/** @file
This file implement UEFI driver for IDE Bus which includes device identification,
Child device(Disk, CDROM, etc) enumeration and child handler installation, and
driver stop.
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@par Revision Reference:
This module is modified from DXE\IDE module for Ide Contriller Init support
**/
#include "IdeBus.h"
//
// IDE Bus Driver Binding Protocol Instance
//
0xa,
NULL,
};
/**
Deregister an IDE device and free resources
@param This Protocol instance pointer.
@param Controller Ide device handle
@param Handle Handle of device to deregister driver on
@retval EFI_SUCCESS Deregiter a specific IDE device successfully
**/
)
{
);
return Status;
}
//
// Report Status code: Device disabled
//
);
//
// Close the child handle
//
);
);
gBS->OpenProtocol (
);
return Status;
}
//
// Release allocated resources
//
if (Index < MAX_IDE_DEVICE) {
}
return EFI_SUCCESS;
}
/**
Supported function of Driver Binding protocol for this driver.
@param This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
@param ControllerHandle The handle of the controller to test.
@param RemainingDevicePath A pointer to the remaining portion of a device path.
@retval EFI_SUCCESS Driver loaded.
@retval other Driver not loaded.
**/
)
{
if (RemainingDevicePath != NULL) {
//
// Check if RemainingDevicePath is the End of Device Path Node,
// if yes, go on checking other conditions
//
if (!IsDevicePathEnd (Node)) {
//
// If RemainingDevicePath isn't the End of Device Path Node,
// check its validation
//
return EFI_UNSUPPORTED;
}
}
}
//
// Verify the Ide Controller Init Protocol, which installed by the
// IdeController module.
//
);
if (Status == EFI_ALREADY_STARTED) {
return EFI_SUCCESS;
}
return Status;
}
//
// Close the I/O Abstraction(s) used to perform the supported test
//
gBS->CloseProtocol (
);
//
// Open the EFI Device Path protocol needed to perform the supported test
//
(VOID **) &ParentDevicePath,
);
if (Status == EFI_ALREADY_STARTED) {
return EFI_SUCCESS;
}
//
// Close protocol, don't use device path protocol in the Support() function
//
gBS->CloseProtocol (
);
//
// Get the EfiPciIoProtocol
//
);
return Status;
}
//
// Now further check the PCI header: Base class (offset 0x0B) and
// Sub Class (offset 0x0A). This controller should be an IDE controller
//
0,
sizeof (PciData),
);
//
// Examine if it is IDE mode by class code
//
if ((PciData.Hdr.ClassCode[2] != PCI_CLASS_MASS_STORAGE) || (PciData.Hdr.ClassCode[1] != PCI_SUB_CLASS_IDE)) {
} else {
}
}
return Status;
}
/**
Start function of Driver binding protocol which start this driver on Controller
by detecting all disks and installing BlockIo protocol on them.
@param This Protocol instance pointer.
@param Controller Handle of device to bind driver to.
@param RemainingDevicePath produce all possible children.
@retval EFI_SUCCESS This driver is added to ControllerHandle.
@retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle.
@retval other This driver does not support this device.
**/
)
{
//
// Local variables declaration for IdeControllerInit support
//
//
// Perform IdeBus initialization
//
(VOID **) &ParentDevicePath,
);
return Status;
}
//
// Now open the IDE_CONTROLLER_INIT protocol. Step7.1
//
);
//
// The following OpenProtocol function with _GET_PROTOCOL attribute and
// will not return EFI_ALREADY_STARTED, so save it for now
//
//
// open protocol is not SUCCESS or not ALREADY_STARTED, error exit
//
goto ErrorExit;
}
//
// Save Enumall. Step7.2
//
//
// Consume PCI I/O protocol. Note that the OpenProtocol with _GET_PROTOCOL
// attribute will not return EFI_ALREADY_STARTED
//
);
goto ErrorExit;
}
//
// We must check EFI_ALREADY_STARTED because many ATAPI devices are removable
//
if (SavedStatus != EFI_ALREADY_STARTED) {
if (IdeBusDriverPrivateData == NULL) {
goto ErrorExit;
}
);
goto ErrorExit;
}
} else {
(VOID **) &IdeBusDriverPrivateData,
);
goto ErrorExit;
}
}
0,
);
);
}
goto ErrorExit;
}
//
// Read the environment variable that contains the IDEBus Driver's
// Config options that were set by the Driver Configuration Protocol
//
DataSize = sizeof (ConfigurationOptions);
(CHAR16 *) L"Configuration",
NULL,
&DataSize,
);
ConfigurationOptions = 0x0f;
}
//
// If IdeInit->EnumAll is TRUE or RemainingDevicePath is NULL,
// must enumerate all IDE devices anyway
//
} else if (!IsDevicePathEnd (RemainingDevicePath)) {
//
// If RemainingDevicePath isn't the End of Device Path Node,
// only scan the specified device by RemainingDevicePath
//
goto ErrorExit;
}
goto ErrorExit;
}
} else {
//
// If RemainingDevicePath is the End of Device Path Node,
// skip enumerate any device and return EFI_SUCESSS
//
}
//
// Obtain IDE IO port registers' base addresses
//
goto ErrorExit;
}
//
// Report status code: begin IdeBus initialization
//
);
//
// Strictly follow the enumeration based on IDE_CONTROLLER_INIT protocol
//
//
// now obtain channel information fron IdeControllerInit protocol. Step9
//
);
continue;
}
if (!ChannelEnabled) {
continue;
}
//
// Now inform the IDE Controller Init Module. Sept10
//
//
// No reset channel function implemented. Sept11
//
//
// Step13
//
);
//
// Prepare to detect IDE device of this channel
//
//
//
//
// Check whether the configuration options allow this device
//
continue;
}
//
// The device has been scanned in another Start(), No need to scan it again
// for perf optimization.
//
continue;
}
//
// create child handle for the detected device.
//
continue;
}
//
// initialize Block IO interface's Media pointer
//
//
// Initialize IDE IO port addresses, including Command Block registers
// and Control Block registers
//
continue;
}
//
// Report Status code: is about to detect IDE drive
//
0,
NULL,
NULL,
0
);
//
// Discover device, now!
//
//
// Set Device Path
//
);
continue;
}
//
// Submit identify data to IDE controller init driver
//
} else {
//
// Device detection failed
//
}
//
// end of 1st inner loop ---
//
}
//
// end of 1st outer loop =========
//
}
//
//
//
//
continue;
}
continue;
}
);
continue;
}
//
// Set best supported PIO mode on this IDE device
//
} else {
}
if (SupportedModes->ExtModeCount == 0){
continue;
}
}
//
// Set supported DMA mode on this IDE device. Note that UDMA & MDMA cann't
// be set together. Only one DMA mode can be set to a device. If setting
// DMA mode operation fails, we can continue moving on because we only use
// PIO mode at boot time. DMA modes are used by certain kind of OS booting
//
continue;
}
//
// Record Udma Mode
//
continue;
}
}
//
// Init driver parameters
//
DriveParameters.Sector = (UINT8) ((ATA5_IDENTIFY_DATA *) IdeBlkIoDevicePtr->IdData)->sectors_per_track;
DriveParameters.MultipleSector = (UINT8) IdeBlkIoDevicePtr->IdData->AtaData.multi_sector_cmd_max_sct_cnt;
//
// Set Parameters for the device:
// 1) Init
//
if ((IdeBlkIoDevicePtr->Type == IdeHardDisk) || (IdeBlkIoDevicePtr->Type == Ide48bitAddressingHardDisk)) {
}
//
// Record PIO mode used in private data
//
//
// Set IDE controller Timing Blocks in the PCI Configuration Space
//
//
//
);
}
gBS->OpenProtocol (
);
//
// Report status code: device eanbled!
//
);
//
// Create event to clear pending IDE interrupt
//
);
//
// end of 2nd inner loop ----
//
}
//
// end of 2nd outer loop ==========
//
}
//
// All configurations done! Notify IdeController to do post initialization
// work such as saving IDE controller PCI settings for S3 resume
//
if (SupportedModes != NULL) {
}
return EFI_SUCCESS;
//
// Report error code: controller error
//
);
gBS->CloseProtocol (
);
);
if (IdeBusDriverPrivateData != NULL) {
}
if (SupportedModes != NULL) {
}
gBS->CloseProtocol (
);
gBS->CloseProtocol (
);
return Status;
}
/**
Stop function of Driver Binding Protocol which is to stop the driver on Controller Handle and all
child handle attached to the controller handle if there are.
@param This Protocol instance pointer.
@param Controller Handle of device to stop driver on
@param NumberOfChildren Not used
@param ChildHandleBuffer Not used
@retval EFI_SUCCESS This driver is removed DeviceHandle
@retval other This driver was not removed from this device
**/
)
{
if (NumberOfChildren == 0) {
);
0,
);
Supports &= EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO | EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO | EFI_PCI_DEVICE_ENABLE;
PciIo->Attributes (
);
}
}
gBS->OpenProtocol (
(VOID **) &IdeBusDriverPrivateData,
);
);
if (IdeBusDriverPrivateData != NULL) {
}
//
// Close the bus driver
//
gBS->CloseProtocol (
);
gBS->CloseProtocol (
);
gBS->CloseProtocol (
);
return EFI_SUCCESS;
}
}
}
if (!AllChildrenStopped) {
return EFI_DEVICE_ERROR;
}
return EFI_SUCCESS;
}
/**
issue ATA or ATAPI command to reset a block IO device.
@param This Block IO protocol instance pointer.
@param ExtendedVerification If FALSE,for ATAPI device, driver will only invoke ATAPI reset method
If TRUE, for ATAPI device, driver need invoke ATA reset method after
invoke ATAPI reset method
@retval EFI_DEVICE_ERROR When the device is neighther ATA device or ATAPI device.
@retval EFI_SUCCESS The device reset successfully
**/
)
{
//
// Requery IDE IO resources in case of the switch of native and legacy modes
//
//
// for ATA device, using ATA reset method
//
goto Done;
}
goto Done;
}
//
// for ATAPI device, using ATAPI reset method
//
if (ExtendedVerification) {
}
Done:
return Status;
}
/**
Read data from a block IO device
@param This Block IO protocol instance pointer.
@param MediaId The media ID of the device
@param Lba Starting LBA address to read data
@param BufferSize The size of data to be read
@param Buffer Caller supplied buffer to save data
@retval EFI_DEVICE_ERROR unknown device type
@retval other read data status.
**/
)
{
//
// Requery IDE IO resources in case of the switch of native and legacy modes
//
//
// For ATA compatible device, use ATA read block's mechanism
//
Lba,
);
goto Done;
}
goto Done;
}
//
// for ATAPI device, using ATAPI read block's mechanism
//
Lba,
);
Done:
return Status;
}
/**
Write data to block io device.
@param This Protocol instance pointer.
@param MediaId The media ID of the device
@param Lba Starting LBA address to write data
@param BufferSize The size of data to be written
@param Buffer Caller supplied buffer to save data
@retval EFI_DEVICE_ERROR unknown device type
@retval other write data status
**/
)
{
//
// Requery IDE IO resources in case of the switch of native and legacy modes
//
//
// for ATA device, using ATA write block's mechanism
//
Lba,
);
goto Done;
}
goto Done;
}
//
// for ATAPI device, using ATAPI write block's mechanism
//
Lba,
);
Done:
return Status;
}
/**
Flushes all modified data to a physical block devices
@param This Indicates a pointer to the calling context which to sepcify a
sepcific block device
@retval EFI_SUCCESS Always return success.
**/
)
{
//
// return directly
//
return EFI_SUCCESS;
}
/**
This function is used by the IDE bus driver to get inquiry data.
Data format of Identify data is defined by the Interface GUID.
@param This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
@param InquiryData Pointer to a buffer for the inquiry data.
@param InquiryDataSize Pointer to the value for the inquiry data size.
@retval EFI_SUCCESS The command was accepted without any errors.
@retval EFI_NOT_FOUND Device does not support this data class
@retval EFI_DEVICE_ERROR Error reading InquiryData from device
@retval EFI_BUFFER_TOO_SMALL IntquiryDataSize not big enough
**/
)
{
if (*InquiryDataSize < sizeof (ATAPI_INQUIRY_DATA)) {
*InquiryDataSize = sizeof (ATAPI_INQUIRY_DATA);
return EFI_BUFFER_TOO_SMALL;
}
return EFI_NOT_FOUND;
}
*InquiryDataSize = sizeof (ATAPI_INQUIRY_DATA);
return EFI_SUCCESS;
}
/**
This function is used by the IDE bus driver to get identify data.
Data format of Identify data is defined by the Interface GUID.
@param This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
@param IdentifyData Pointer to a buffer for the identify data.
@param IdentifyDataSize Pointer to the value for the identify data size.
@retval EFI_SUCCESS The command was accepted without any errors.
@retval EFI_NOT_FOUND Device does not support this data class
@retval EFI_DEVICE_ERROR Error reading IdentifyData from device
@retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough
**/
)
{
if (*IdentifyDataSize < sizeof (EFI_IDENTIFY_DATA)) {
*IdentifyDataSize = sizeof (EFI_IDENTIFY_DATA);
return EFI_BUFFER_TOO_SMALL;
}
return EFI_NOT_FOUND;
}
*IdentifyDataSize = sizeof (EFI_IDENTIFY_DATA);
return EFI_SUCCESS;
}
/**
This function is used by the IDE bus driver to get sense data.
Data format of Sense data is defined by the Interface GUID.
@param This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
@param SenseData Pointer to the SenseData.
@param SenseDataSize Size of SenseData in bytes.
@param SenseDataNumber Pointer to the value for the identify data size.
@retval EFI_SUCCESS The command was accepted without any errors.
@retval EFI_NOT_FOUND Device does not support this data class
@retval EFI_DEVICE_ERROR Error reading InquiryData from device
@retval EFI_BUFFER_TOO_SMALL SenseDataSize not big enough
**/
)
{
return EFI_NOT_FOUND;
}
/**
This function is used by the IDE bus driver to get controller information.
@param This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
@param IdeChannel Pointer to the Ide Channel number. Primary or secondary.
@param IdeDevice Pointer to the Ide Device number. Master or slave.
@retval EFI_SUCCESS IdeChannel and IdeDevice are valid
@retval EFI_UNSUPPORTED This is not an IDE device
**/
)
{
return EFI_SUCCESS;
}
/**
The is an event(generally the event is exitBootService event) call back function.
@param Event Pointer to this event
@param Context Event hanlder private data
**/
)
{
//
// Get our context
//
//
// Obtain IDE IO port registers' base addresses
//
return;
}
//
// Check whether interrupt is pending
//
//
// Reset IDE device to force it de-assert interrupt pin
// Note: this will reset all devices on this IDE channel
//
return;
}
//
// Get base address of IDE Bus Master Status Regsiter
//
} else {
} else {
return;
}
}
//
// Read BMIS register and clear ERROR and INTR bit
//
1,
);
1,
);
//
// Select the other device on this channel to ensure this device to release the interrupt pin
//
} else {
}
);
}
/**
The user Entry Point for module IdeBus. The user code starts with this function.
@param[in] ImageHandle The firmware allocated handle for the EFI image.
@param[in] SystemTable A pointer to the EFI System Table.
@retval EFI_SUCCESS The entry point is executed successfully.
@retval other Some error occurs when executing this entry point.
**/
)
{
//
// Install driver model protocol(s).
//
NULL,
NULL,
);
return Status;
}