Add BlockIO2 Protocol.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11606 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
@@ -44,6 +44,13 @@ ATA_DEVICE gAtaDeviceTemplate = {
|
||||
AtaBlockIoWriteBlocks,
|
||||
AtaBlockIoFlushBlocks
|
||||
},
|
||||
{ // BlockIo2
|
||||
NULL,
|
||||
AtaBlockIoResetEx,
|
||||
AtaBlockIoReadBlocksEx,
|
||||
AtaBlockIoWriteBlocksEx,
|
||||
AtaBlockIoFlushBlocksEx
|
||||
},
|
||||
{ // BlockMedia
|
||||
0, // MediaId
|
||||
FALSE, // RemovableMedia
|
||||
@@ -75,7 +82,8 @@ ATA_DEVICE gAtaDeviceTemplate = {
|
||||
FALSE, // Lba48Bit
|
||||
NULL, // IdentifyData
|
||||
NULL, // ControllerNameTable
|
||||
{L'\0', } // ModelName
|
||||
{L'\0', }, // ModelName
|
||||
{NULL, NULL} // AtaTaskList
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -135,12 +143,34 @@ ReleaseAtaResources (
|
||||
IN ATA_DEVICE *AtaDevice
|
||||
)
|
||||
{
|
||||
ATA_BUS_ASYN_TASK *Task;
|
||||
LIST_ENTRY *Entry;
|
||||
LIST_ENTRY *DelEntry;
|
||||
EFI_TPL OldTpl;
|
||||
|
||||
FreeUnicodeStringTable (AtaDevice->ControllerNameTable);
|
||||
FreeAlignedBuffer (AtaDevice->Asb, sizeof (*AtaDevice->Asb));
|
||||
FreeAlignedBuffer (AtaDevice->IdentifyData, sizeof (*AtaDevice->IdentifyData));
|
||||
if (AtaDevice->DevicePath != NULL) {
|
||||
FreePool (AtaDevice->DevicePath);
|
||||
}
|
||||
OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
|
||||
if (!IsListEmpty (&AtaDevice->AtaTaskList)) {
|
||||
//
|
||||
// Free the Subtask list.
|
||||
//
|
||||
for(Entry = (&AtaDevice->AtaTaskList)->ForwardLink;
|
||||
Entry != (&AtaDevice->AtaTaskList);
|
||||
) {
|
||||
DelEntry = Entry;
|
||||
Entry = Entry->ForwardLink;
|
||||
Task = ATA_AYNS_TASK_FROM_ENTRY (DelEntry);
|
||||
|
||||
RemoveEntryList (DelEntry);
|
||||
FreeAtaSubTask (Task);
|
||||
}
|
||||
}
|
||||
gBS->RestoreTPL (OldTpl);
|
||||
FreePool (AtaDevice);
|
||||
}
|
||||
|
||||
@@ -218,10 +248,11 @@ RegisterAtaDevice (
|
||||
//
|
||||
// Initializes ATA device structures and allocates the required buffer.
|
||||
//
|
||||
AtaDevice->BlockIo.Media = &AtaDevice->BlockMedia;
|
||||
AtaDevice->AtaBusDriverData = AtaBusDriverData;
|
||||
AtaDevice->DevicePath = DevicePath;
|
||||
AtaDevice->Port = Port;
|
||||
AtaDevice->BlockIo.Media = &AtaDevice->BlockMedia;
|
||||
AtaDevice->BlockIo2.Media = &AtaDevice->BlockMedia;
|
||||
AtaDevice->AtaBusDriverData = AtaBusDriverData;
|
||||
AtaDevice->DevicePath = DevicePath;
|
||||
AtaDevice->Port = Port;
|
||||
AtaDevice->PortMultiplierPort = PortMultiplierPort;
|
||||
AtaDevice->Asb = AllocateAlignedBuffer (AtaDevice, sizeof (*AtaDevice->Asb));
|
||||
if (AtaDevice->Asb == NULL) {
|
||||
@@ -234,6 +265,11 @@ RegisterAtaDevice (
|
||||
goto Done;
|
||||
}
|
||||
|
||||
//
|
||||
// Initial Ata Task List
|
||||
//
|
||||
InitializeListHead (&AtaDevice->AtaTaskList);
|
||||
|
||||
//
|
||||
// Try to identify the ATA device via the ATA pass through command.
|
||||
//
|
||||
@@ -241,7 +277,7 @@ RegisterAtaDevice (
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto Done;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Build controller name for Component Name (2) protocol.
|
||||
//
|
||||
@@ -281,6 +317,8 @@ RegisterAtaDevice (
|
||||
AtaDevice->DevicePath,
|
||||
&gEfiBlockIoProtocolGuid,
|
||||
&AtaDevice->BlockIo,
|
||||
&gEfiBlockIo2ProtocolGuid,
|
||||
&AtaDevice->BlockIo2,
|
||||
&gEfiDiskInfoProtocolGuid,
|
||||
&AtaDevice->DiskInfo,
|
||||
NULL
|
||||
@@ -334,8 +372,11 @@ UnregisterAtaDevice (
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_BLOCK_IO_PROTOCOL *BlockIo;
|
||||
EFI_BLOCK_IO2_PROTOCOL *BlockIo2;
|
||||
ATA_DEVICE *AtaDevice;
|
||||
EFI_ATA_PASS_THRU_PROTOCOL *AtaPassThru;
|
||||
BlockIo2 = NULL;
|
||||
BlockIo = NULL;
|
||||
|
||||
Status = gBS->OpenProtocol (
|
||||
Handle,
|
||||
@@ -346,10 +387,30 @@ UnregisterAtaDevice (
|
||||
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
//
|
||||
// Locate BlockIo2 protocol
|
||||
//
|
||||
Status = gBS->OpenProtocol (
|
||||
Handle,
|
||||
&gEfiBlockIo2ProtocolGuid,
|
||||
(VOID **) &BlockIo2,
|
||||
This->DriverBindingHandle,
|
||||
Controller,
|
||||
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
}
|
||||
|
||||
AtaDevice = ATA_DEVICE_FROM_BLOCK_IO (BlockIo);
|
||||
//
|
||||
// Get AtaDevice data.
|
||||
//
|
||||
if (BlockIo != NULL) {
|
||||
AtaDevice = ATA_DEVICE_FROM_BLOCK_IO (BlockIo);
|
||||
} else {
|
||||
AtaDevice = ATA_DEVICE_FROM_BLOCK_IO2 (BlockIo2);
|
||||
}
|
||||
|
||||
//
|
||||
// Close the child handle
|
||||
@@ -361,12 +422,18 @@ UnregisterAtaDevice (
|
||||
Handle
|
||||
);
|
||||
|
||||
//
|
||||
// The Ata Bus driver installs the BlockIo and BlockIo2 in the DriverBindingStart().
|
||||
// Here should uninstall both of them.
|
||||
//
|
||||
Status = gBS->UninstallMultipleProtocolInterfaces (
|
||||
Handle,
|
||||
&gEfiDevicePathProtocolGuid,
|
||||
AtaDevice->DevicePath,
|
||||
&gEfiBlockIoProtocolGuid,
|
||||
&AtaDevice->BlockIo,
|
||||
&gEfiBlockIo2ProtocolGuid,
|
||||
&AtaDevice->BlockIo2,
|
||||
&gEfiDiskInfoProtocolGuid,
|
||||
&AtaDevice->DiskInfo,
|
||||
NULL
|
||||
@@ -385,7 +452,6 @@ UnregisterAtaDevice (
|
||||
}
|
||||
|
||||
ReleaseAtaResources (AtaDevice);
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
@@ -446,7 +512,7 @@ AtaBusDriverBindingSupported (
|
||||
EFI_ATA_PASS_THRU_PROTOCOL *AtaPassThru;
|
||||
UINT16 Port;
|
||||
UINT16 PortMultiplierPort;
|
||||
|
||||
|
||||
//
|
||||
// Test EFI_ATA_PASS_THRU_PROTOCOL on controller handle.
|
||||
//
|
||||
@@ -522,7 +588,7 @@ AtaBusDriverBindingSupported (
|
||||
@param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
|
||||
parameter is ignored by device drivers, and is optional for bus
|
||||
drivers. For a bus driver, if this parameter is NULL, then handles
|
||||
for all the children of Controller are created by this driver.
|
||||
for all the children of Controller are created by this driver.
|
||||
If this parameter is not NULL and the first Device Path Node is
|
||||
not the End of Device Path Node, then only the handle for the
|
||||
child device specified by the first Device Path Node of
|
||||
@@ -589,7 +655,7 @@ AtaBusDriverBindingStart (
|
||||
}
|
||||
|
||||
AtaBusDriverData->AtaPassThru = AtaPassThru;
|
||||
AtaBusDriverData->Controller = Controller;
|
||||
AtaBusDriverData->Controller = Controller;
|
||||
AtaBusDriverData->ParentDevicePath = ParentDevicePath;
|
||||
AtaBusDriverData->DriverBindingHandle = This->DriverBindingHandle;
|
||||
|
||||
@@ -628,7 +694,7 @@ AtaBusDriverBindingStart (
|
||||
//
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
PortMultiplierPort = 0xFFFF;
|
||||
while (TRUE) {
|
||||
Status = AtaPassThru->GetNextDevice (AtaPassThru, Port, &PortMultiplierPort);
|
||||
@@ -649,7 +715,7 @@ AtaBusDriverBindingStart (
|
||||
Status = RegisterAtaDevice (AtaBusDriverData,Port, PortMultiplierPort);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return Status;
|
||||
|
||||
ErrorExit:
|
||||
@@ -789,7 +855,7 @@ AtaBlockIoReset (
|
||||
|
||||
AtaDevice = ATA_DEVICE_FROM_BLOCK_IO (This);
|
||||
|
||||
Status = ResetAtaDevice (AtaDevice);
|
||||
Status = ResetAtaDevice (AtaDevice);
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
Status = EFI_DEVICE_ERROR;
|
||||
@@ -803,13 +869,18 @@ AtaBlockIoReset (
|
||||
/**
|
||||
Read/Write BufferSize bytes from Lba from/into Buffer.
|
||||
|
||||
@param This Indicates a pointer to the calling context.
|
||||
@param MediaId The media ID that the read/write request is for.
|
||||
@param Lba The starting logical block address to be read/written. The caller is
|
||||
responsible for reading/writing to only legitimate locations.
|
||||
@param BufferSize Size of Buffer, must be a multiple of device block size.
|
||||
@param Buffer A pointer to the destination/source buffer for the data.
|
||||
@param IsWrite Indicates whether it is a write operation.
|
||||
@param[in] This Indicates a pointer to the calling context. Either be
|
||||
block I/O or block I/O2.
|
||||
@param[in] MediaId The media ID that the read/write request is for.
|
||||
@param[in] Lba The starting logical block address to be read/written.
|
||||
The caller is responsible for reading/writing to only
|
||||
legitimate locations.
|
||||
@param[in, out] Token A pointer to the token associated with the transaction.
|
||||
@param[in] BufferSize Size of Buffer, must be a multiple of device block size.
|
||||
@param[out] Buffer A pointer to the destination/source buffer for the data.
|
||||
@param[in] IsBlockIo2 Indicate the calling is from BlockIO or BlockIO2. TURE is
|
||||
from BlockIO2, FALSE is for BlockIO.
|
||||
@param[in] IsWrite Indicates whether it is a write operation.
|
||||
|
||||
@retval EFI_SUCCESS The data was read/written correctly to the device.
|
||||
@retval EFI_WRITE_PROTECTED The device can not be read/written to.
|
||||
@@ -823,12 +894,14 @@ AtaBlockIoReset (
|
||||
**/
|
||||
EFI_STATUS
|
||||
BlockIoReadWrite (
|
||||
IN EFI_BLOCK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN BufferSize,
|
||||
OUT VOID *Buffer,
|
||||
IN BOOLEAN IsWrite
|
||||
IN VOID *This,
|
||||
IN UINT32 MediaId,
|
||||
IN EFI_LBA Lba,
|
||||
IN OUT EFI_BLOCK_IO2_TOKEN *Token,
|
||||
IN UINTN BufferSize,
|
||||
OUT VOID *Buffer,
|
||||
IN BOOLEAN IsBlockIo2,
|
||||
IN BOOLEAN IsWrite
|
||||
)
|
||||
{
|
||||
ATA_DEVICE *AtaDevice;
|
||||
@@ -839,21 +912,28 @@ BlockIoReadWrite (
|
||||
UINTN NumberOfBlocks;
|
||||
UINTN IoAlign;
|
||||
|
||||
//
|
||||
// Check parameters.
|
||||
//
|
||||
Media = This->Media;
|
||||
if (IsBlockIo2) {
|
||||
Media = ((EFI_BLOCK_IO2_PROTOCOL *) This)->Media;
|
||||
AtaDevice = ATA_DEVICE_FROM_BLOCK_IO2 (This);
|
||||
} else {
|
||||
Media = ((EFI_BLOCK_IO_PROTOCOL *) This)->Media;
|
||||
AtaDevice = ATA_DEVICE_FROM_BLOCK_IO (This);
|
||||
}
|
||||
|
||||
if (MediaId != Media->MediaId) {
|
||||
return EFI_MEDIA_CHANGED;
|
||||
}
|
||||
|
||||
//
|
||||
// Check parameters.
|
||||
//
|
||||
if (Buffer == NULL) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (BufferSize == 0) {
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
BlockSize = Media->BlockSize;
|
||||
if ((BufferSize % BlockSize) != 0) {
|
||||
@@ -871,13 +951,11 @@ BlockIoReadWrite (
|
||||
}
|
||||
|
||||
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
|
||||
|
||||
AtaDevice = ATA_DEVICE_FROM_BLOCK_IO (This);
|
||||
|
||||
//
|
||||
// Invoke low level AtaDevice Access Routine.
|
||||
//
|
||||
Status = AccessAtaDevice (AtaDevice, Buffer, Lba, NumberOfBlocks, IsWrite);
|
||||
Status = AccessAtaDevice (AtaDevice, Buffer, Lba, NumberOfBlocks, IsWrite, Token);
|
||||
|
||||
gBS->RestoreTPL (OldTpl);
|
||||
|
||||
@@ -914,7 +992,7 @@ AtaBlockIoReadBlocks (
|
||||
OUT VOID *Buffer
|
||||
)
|
||||
{
|
||||
return BlockIoReadWrite (This, MediaId, Lba, BufferSize, Buffer, FALSE);
|
||||
return BlockIoReadWrite ((VOID *) This, MediaId, Lba, NULL, BufferSize, Buffer, FALSE, FALSE);
|
||||
}
|
||||
|
||||
|
||||
@@ -948,7 +1026,7 @@ AtaBlockIoWriteBlocks (
|
||||
IN VOID *Buffer
|
||||
)
|
||||
{
|
||||
return BlockIoReadWrite (This, MediaId, Lba, BufferSize, Buffer, TRUE);
|
||||
return BlockIoReadWrite ((VOID *) This, MediaId, Lba, NULL, BufferSize, Buffer, FALSE, TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -974,7 +1052,147 @@ AtaBlockIoFlushBlocks (
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
Reset the Block Device.
|
||||
|
||||
@param[in] This Indicates a pointer to the calling context.
|
||||
@param[in] ExtendedVerification Driver may perform diagnostics on reset.
|
||||
|
||||
@retval EFI_SUCCESS The device was reset.
|
||||
@retval EFI_DEVICE_ERROR The device is not functioning properly and could
|
||||
not be reset.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
AtaBlockIoResetEx (
|
||||
IN EFI_BLOCK_IO2_PROTOCOL *This,
|
||||
IN BOOLEAN ExtendedVerification
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
ATA_DEVICE *AtaDevice;
|
||||
EFI_TPL OldTpl;
|
||||
|
||||
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
|
||||
|
||||
AtaDevice = ATA_DEVICE_FROM_BLOCK_IO2 (This);
|
||||
|
||||
Status = ResetAtaDevice (AtaDevice);
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
Status = EFI_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
gBS->RestoreTPL (OldTpl);
|
||||
return Status;
|
||||
}
|
||||
|
||||
/**
|
||||
Read BufferSize bytes from Lba into Buffer.
|
||||
|
||||
@param[in] This Indicates a pointer to the calling context.
|
||||
@param[in] MediaId Id of the media, changes every time the media is replaced.
|
||||
@param[in] Lba The starting Logical Block Address to read from.
|
||||
@param[in, out] Token A pointer to the token associated with the transaction.
|
||||
@param[in] BufferSize Size of Buffer, must be a multiple of device block size.
|
||||
@param[out] Buffer A pointer to the destination buffer for the data. The caller is
|
||||
responsible for either having implicit or explicit ownership of the buffer.
|
||||
|
||||
@retval EFI_SUCCESS The read request was queued if Event is not NULL.
|
||||
The data was read correctly from the device if
|
||||
the Event is NULL.
|
||||
@retval EFI_DEVICE_ERROR The device reported an error while performing
|
||||
the read.
|
||||
@retval EFI_NO_MEDIA There is no media in the device.
|
||||
@retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
|
||||
@retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the
|
||||
intrinsic block size of the device.
|
||||
@retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
|
||||
or the buffer is not on proper alignment.
|
||||
@retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
|
||||
of resources.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
AtaBlockIoReadBlocksEx (
|
||||
IN EFI_BLOCK_IO2_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN EFI_LBA Lba,
|
||||
IN OUT EFI_BLOCK_IO2_TOKEN *Token,
|
||||
IN UINTN BufferSize,
|
||||
OUT VOID *Buffer
|
||||
)
|
||||
{
|
||||
return BlockIoReadWrite ((VOID *) This, MediaId, Lba, Token, BufferSize, Buffer, TRUE, FALSE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Write BufferSize bytes from Lba into Buffer.
|
||||
|
||||
@param[in] This Indicates a pointer to the calling context.
|
||||
@param[in] MediaId The media ID that the write request is for.
|
||||
@param[in] Lba The starting logical block address to be written. The
|
||||
caller is responsible for writing to only legitimate
|
||||
locations.
|
||||
@param[in, out] Token A pointer to the token associated with the transaction.
|
||||
@param[in] BufferSize Size of Buffer, must be a multiple of device block size.
|
||||
@param[in] Buffer A pointer to the source buffer for the data.
|
||||
|
||||
@retval EFI_SUCCESS The data was written correctly to the device.
|
||||
@retval EFI_WRITE_PROTECTED The device can not be written to.
|
||||
@retval EFI_DEVICE_ERROR The device reported an error while performing the write.
|
||||
@retval EFI_NO_MEDIA There is no media in the device.
|
||||
@retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
|
||||
@retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
|
||||
@retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
|
||||
or the buffer is not on proper alignment.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
AtaBlockIoWriteBlocksEx (
|
||||
IN EFI_BLOCK_IO2_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN EFI_LBA Lba,
|
||||
IN OUT EFI_BLOCK_IO2_TOKEN *Token,
|
||||
IN UINTN BufferSize,
|
||||
IN VOID *Buffer
|
||||
)
|
||||
{
|
||||
return BlockIoReadWrite ((VOID *) This, MediaId, Lba, Token, BufferSize, Buffer, TRUE, TRUE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Flush the Block Device.
|
||||
|
||||
@param[in] This Indicates a pointer to the calling context.
|
||||
@param[in, out] Token A pointer to the token associated with the transaction.
|
||||
|
||||
@retval EFI_SUCCESS All outstanding data was written to the device
|
||||
@retval EFI_DEVICE_ERROR The device reported an error while writing back the data
|
||||
@retval EFI_NO_MEDIA There is no media in the device.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
AtaBlockIoFlushBlocksEx (
|
||||
IN EFI_BLOCK_IO2_PROTOCOL *This,
|
||||
IN OUT EFI_BLOCK_IO2_TOKEN *Token
|
||||
)
|
||||
{
|
||||
//
|
||||
// Signla event and return directly.
|
||||
//
|
||||
if (Token != NULL && Token->Event != NULL) {
|
||||
Token->TransactionStatus = EFI_SUCCESS;
|
||||
gBS->SignalEvent (Token->Event);
|
||||
}
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
/**
|
||||
Provides inquiry information for the controller type.
|
||||
|
||||
|
@@ -22,6 +22,7 @@
|
||||
|
||||
#include <Protocol/AtaPassThru.h>
|
||||
#include <Protocol/BlockIo.h>
|
||||
#include <Protocol/BlockIo2.h>
|
||||
#include <Protocol/DiskInfo.h>
|
||||
#include <Protocol/DevicePath.h>
|
||||
|
||||
@@ -59,13 +60,37 @@
|
||||
//
|
||||
// The maximum ATA transaction sector count in 48 bit addressing mode.
|
||||
//
|
||||
#define MAX_48BIT_TRANSFER_BLOCK_NUM 0x10000
|
||||
//#define MAX_48BIT_TRANSFER_BLOCK_NUM 0x10000
|
||||
|
||||
//
|
||||
// BugBug: if the TransferLength is equal with 0x10000 (the 48bit max length),
|
||||
// there is a bug that even the register interrupt bit has been sit, the buffer
|
||||
// seems not ready. Change the Maximum Sector Numbers to 0xFFFF to work round
|
||||
// this issue.
|
||||
//
|
||||
#define MAX_48BIT_TRANSFER_BLOCK_NUM 0xFFFF
|
||||
|
||||
//
|
||||
// The maximum model name in ATA identify data
|
||||
//
|
||||
#define MAX_MODEL_NAME_LEN 40
|
||||
|
||||
#define ATA_TASK_SIGNATURE SIGNATURE_32 ('A', 'T', 'S', 'K')
|
||||
#define ATA_DEVICE_SIGNATURE SIGNATURE_32 ('A', 'B', 'I', 'D')
|
||||
|
||||
#define IS_ALIGNED(addr, size) (((UINTN) (addr) & (size - 1)) == 0)
|
||||
|
||||
//
|
||||
// Task for the non blocking I/O
|
||||
//
|
||||
typedef struct {
|
||||
UINT32 Signature;
|
||||
EFI_BLOCK_IO2_TOKEN *Token;
|
||||
UINTN *UnsignalledEventCount;
|
||||
EFI_ATA_PASS_THRU_COMMAND_PACKET Packet;
|
||||
BOOLEAN *IsError;// Indicate whether meeting error during source allocation for new task.
|
||||
LIST_ENTRY TaskEntry;
|
||||
} ATA_BUS_ASYN_TASK;
|
||||
|
||||
//
|
||||
// ATA bus data structure for ATA controller
|
||||
@@ -77,46 +102,48 @@ typedef struct {
|
||||
EFI_HANDLE DriverBindingHandle;
|
||||
} ATA_BUS_DRIVER_DATA;
|
||||
|
||||
#define ATA_DEVICE_SIGNATURE SIGNATURE_32 ('A', 'B', 'I', 'D')
|
||||
|
||||
//
|
||||
// ATA device data structure for each child device
|
||||
//
|
||||
typedef struct {
|
||||
UINT32 Signature;
|
||||
UINT32 Signature;
|
||||
|
||||
EFI_HANDLE Handle;
|
||||
EFI_BLOCK_IO_PROTOCOL BlockIo;
|
||||
EFI_BLOCK_IO_MEDIA BlockMedia;
|
||||
EFI_DISK_INFO_PROTOCOL DiskInfo;
|
||||
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
|
||||
EFI_HANDLE Handle;
|
||||
EFI_BLOCK_IO_PROTOCOL BlockIo;
|
||||
EFI_BLOCK_IO2_PROTOCOL BlockIo2;
|
||||
EFI_BLOCK_IO_MEDIA BlockMedia;
|
||||
EFI_DISK_INFO_PROTOCOL DiskInfo;
|
||||
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
|
||||
|
||||
ATA_BUS_DRIVER_DATA *AtaBusDriverData;
|
||||
UINT16 Port;
|
||||
UINT16 PortMultiplierPort;
|
||||
ATA_BUS_DRIVER_DATA *AtaBusDriverData;
|
||||
UINT16 Port;
|
||||
UINT16 PortMultiplierPort;
|
||||
|
||||
//
|
||||
// Buffer for the execution of ATA pass through protocol
|
||||
//
|
||||
EFI_ATA_PASS_THRU_COMMAND_PACKET Packet;
|
||||
EFI_ATA_COMMAND_BLOCK Acb;
|
||||
EFI_ATA_STATUS_BLOCK *Asb;
|
||||
EFI_ATA_PASS_THRU_COMMAND_PACKET Packet;
|
||||
EFI_ATA_COMMAND_BLOCK Acb;
|
||||
EFI_ATA_STATUS_BLOCK *Asb;
|
||||
|
||||
BOOLEAN UdmaValid;
|
||||
BOOLEAN Lba48Bit;
|
||||
BOOLEAN UdmaValid;
|
||||
BOOLEAN Lba48Bit;
|
||||
|
||||
//
|
||||
// Cached data for ATA identify data
|
||||
//
|
||||
ATA_IDENTIFY_DATA *IdentifyData;
|
||||
ATA_IDENTIFY_DATA *IdentifyData;
|
||||
|
||||
EFI_UNICODE_STRING_TABLE *ControllerNameTable;
|
||||
CHAR16 ModelName[MAX_MODEL_NAME_LEN + 1];
|
||||
EFI_UNICODE_STRING_TABLE *ControllerNameTable;
|
||||
CHAR16 ModelName[MAX_MODEL_NAME_LEN + 1];
|
||||
|
||||
LIST_ENTRY AtaTaskList;
|
||||
} ATA_DEVICE;
|
||||
|
||||
#define ATA_DEVICE_FROM_BLOCK_IO(a) CR (a, ATA_DEVICE, BlockIo, ATA_DEVICE_SIGNATURE)
|
||||
#define ATA_DEVICE_FROM_DISK_INFO(a) CR (a, ATA_DEVICE, DiskInfo, ATA_DEVICE_SIGNATURE)
|
||||
#define ATA_DEVICE_FROM_BLOCK_IO(a) CR (a, ATA_DEVICE, BlockIo, ATA_DEVICE_SIGNATURE)
|
||||
#define ATA_DEVICE_FROM_BLOCK_IO2(a) CR (a, ATA_DEVICE, BlockIo2, ATA_DEVICE_SIGNATURE)
|
||||
#define ATA_DEVICE_FROM_DISK_INFO(a) CR (a, ATA_DEVICE, DiskInfo, ATA_DEVICE_SIGNATURE)
|
||||
#define ATA_AYNS_TASK_FROM_ENTRY(a) CR (a, ATA_BUS_ASYN_TASK, TaskEntry, ATA_TASK_SIGNATURE)
|
||||
|
||||
//
|
||||
// Global Variables
|
||||
@@ -125,6 +152,52 @@ extern EFI_DRIVER_BINDING_PROTOCOL gAtaBusDriverBinding;
|
||||
extern EFI_COMPONENT_NAME_PROTOCOL gAtaBusComponentName;
|
||||
extern EFI_COMPONENT_NAME2_PROTOCOL gAtaBusComponentName2;
|
||||
|
||||
/**
|
||||
Allocates an aligned buffer for ATA device.
|
||||
|
||||
This function allocates an aligned buffer for the ATA device to perform
|
||||
ATA pass through operations. The alignment requirement is from ATA pass
|
||||
through interface.
|
||||
|
||||
@param AtaDevice The ATA child device involved for the operation.
|
||||
@param BufferSize The request buffer size.
|
||||
|
||||
@return A pointer to the aligned buffer or NULL if the allocation fails.
|
||||
|
||||
**/
|
||||
VOID *
|
||||
AllocateAlignedBuffer (
|
||||
IN ATA_DEVICE *AtaDevice,
|
||||
IN UINTN BufferSize
|
||||
);
|
||||
|
||||
/**
|
||||
Frees an aligned buffer for ATA device.
|
||||
|
||||
This function frees an aligned buffer for the ATA device to perform
|
||||
ATA pass through operations.
|
||||
|
||||
@param Buffer The aligned buffer to be freed.
|
||||
@param BufferSize The request buffer size.
|
||||
|
||||
**/
|
||||
VOID
|
||||
FreeAlignedBuffer (
|
||||
IN VOID *Buffer,
|
||||
IN UINTN BufferSize
|
||||
);
|
||||
|
||||
/**
|
||||
Free SubTask.
|
||||
|
||||
@param[in, out] Task Pointer to task to be freed.
|
||||
|
||||
**/
|
||||
VOID
|
||||
EFIAPI
|
||||
FreeAtaSubTask (
|
||||
IN ATA_BUS_ASYN_TASK *Task
|
||||
);
|
||||
|
||||
/**
|
||||
Wrapper for EFI_ATA_PASS_THRU_PROTOCOL.ResetDevice().
|
||||
@@ -162,7 +235,6 @@ DiscoverAtaDevice (
|
||||
IN OUT ATA_DEVICE *AtaDevice
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
Read or write a number of blocks from ATA device.
|
||||
|
||||
@@ -170,11 +242,12 @@ DiscoverAtaDevice (
|
||||
ATA device. It may separate the read/write request into several ATA pass through
|
||||
transactions.
|
||||
|
||||
@param AtaDevice The ATA child device involved for the operation.
|
||||
@param Buffer The pointer to the current transaction buffer.
|
||||
@param StartLba The starting logical block address to be accessed.
|
||||
@param NumberOfBlocks The block number or sector count of the transfer.
|
||||
@param IsWrite Indicates whether it is a write operation.
|
||||
@param[in, out] AtaDevice The ATA child device involved for the operation.
|
||||
@param[in, out] Buffer The pointer to the current transaction buffer.
|
||||
@param[in] StartLba The starting logical block address to be accessed.
|
||||
@param[in] NumberOfBlocks The block number or sector count of the transfer.
|
||||
@param[in] IsWrite Indicates whether it is a write operation.
|
||||
@param[in, out] Token A pointer to the token associated with the transaction.
|
||||
|
||||
@retval EFI_SUCCESS The data transfer is complete successfully.
|
||||
@return others Some error occurs when transferring data.
|
||||
@@ -186,7 +259,8 @@ AccessAtaDevice(
|
||||
IN OUT UINT8 *Buffer,
|
||||
IN EFI_LBA StartLba,
|
||||
IN UINTN NumberOfBlocks,
|
||||
IN BOOLEAN IsWrite
|
||||
IN BOOLEAN IsWrite,
|
||||
IN OUT EFI_BLOCK_IO2_TOKEN *Token
|
||||
);
|
||||
|
||||
//
|
||||
@@ -544,6 +618,111 @@ AtaBlockIoFlushBlocks (
|
||||
IN EFI_BLOCK_IO_PROTOCOL *This
|
||||
);
|
||||
|
||||
/**
|
||||
Reset the Block Device throught Block I/O2 protocol.
|
||||
|
||||
@param[in] This Indicates a pointer to the calling context.
|
||||
@param[in] ExtendedVerification Driver may perform diagnostics on reset.
|
||||
|
||||
@retval EFI_SUCCESS The device was reset.
|
||||
@retval EFI_DEVICE_ERROR The device is not functioning properly and could
|
||||
not be reset.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
AtaBlockIoResetEx (
|
||||
IN EFI_BLOCK_IO2_PROTOCOL *This,
|
||||
IN BOOLEAN ExtendedVerification
|
||||
);
|
||||
|
||||
/**
|
||||
Read BufferSize bytes from Lba into Buffer.
|
||||
|
||||
@param[in] This Indicates a pointer to the calling context.
|
||||
@param[in] MediaId Id of the media, changes every time the media is replaced.
|
||||
@param[in] Lba The starting Logical Block Address to read from.
|
||||
@param[in, out] Token A pointer to the token associated with the transaction.
|
||||
@param[in] BufferSize Size of Buffer, must be a multiple of device block size.
|
||||
@param[out] Buffer A pointer to the destination buffer for the data. The caller is
|
||||
responsible for either having implicit or explicit ownership of the buffer.
|
||||
|
||||
@retval EFI_SUCCESS The read request was queued if Event is not NULL.
|
||||
The data was read correctly from the device if
|
||||
the Event is NULL.
|
||||
@retval EFI_DEVICE_ERROR The device reported an error while performing
|
||||
the read.
|
||||
@retval EFI_NO_MEDIA There is no media in the device.
|
||||
@retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
|
||||
@retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the
|
||||
intrinsic block size of the device.
|
||||
@retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
|
||||
or the buffer is not on proper alignment.
|
||||
@retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
|
||||
of resources.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
AtaBlockIoReadBlocksEx (
|
||||
IN EFI_BLOCK_IO2_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN EFI_LBA Lba,
|
||||
IN OUT EFI_BLOCK_IO2_TOKEN *Token,
|
||||
IN UINTN BufferSize,
|
||||
OUT VOID *Buffer
|
||||
);
|
||||
|
||||
/**
|
||||
Write BufferSize bytes from Lba into Buffer.
|
||||
|
||||
@param[in] This Indicates a pointer to the calling context.
|
||||
@param[in] MediaId The media ID that the write request is for.
|
||||
@param[in] Lba The starting logical block address to be written. The
|
||||
caller is responsible for writing to only legitimate
|
||||
locations.
|
||||
@param[in, out] Token A pointer to the token associated with the transaction.
|
||||
@param[in] BufferSize Size of Buffer, must be a multiple of device block size.
|
||||
@param[in] Buffer A pointer to the source buffer for the data.
|
||||
|
||||
@retval EFI_SUCCESS The data was written correctly to the device.
|
||||
@retval EFI_WRITE_PROTECTED The device can not be written to.
|
||||
@retval EFI_DEVICE_ERROR The device reported an error while performing the write.
|
||||
@retval EFI_NO_MEDIA There is no media in the device.
|
||||
@retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
|
||||
@retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
|
||||
@retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
|
||||
or the buffer is not on proper alignment.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
AtaBlockIoWriteBlocksEx (
|
||||
IN EFI_BLOCK_IO2_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN EFI_LBA Lba,
|
||||
IN OUT EFI_BLOCK_IO2_TOKEN *Token,
|
||||
IN UINTN BufferSize,
|
||||
IN VOID *Buffer
|
||||
);
|
||||
|
||||
/**
|
||||
Flush the Block Device.
|
||||
|
||||
@param[in] This Indicates a pointer to the calling context.
|
||||
@param[in, out] Token A pointer to the token associated with the transaction.
|
||||
|
||||
@retval EFI_SUCCESS All outstanding data was written to the device
|
||||
@retval EFI_DEVICE_ERROR The device reported an error while writing back the data
|
||||
@retval EFI_NO_MEDIA There is no media in the device.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
AtaBlockIoFlushBlocksEx (
|
||||
IN EFI_BLOCK_IO2_PROTOCOL *This,
|
||||
IN OUT EFI_BLOCK_IO2_TOKEN *Token
|
||||
);
|
||||
|
||||
/**
|
||||
Provides inquiry information for the controller type.
|
||||
|
@@ -5,7 +5,7 @@
|
||||
# in UEFI spec 2.2. It installs Block IO and Disk Info protocol for each ATA device
|
||||
# it enumerates and identifies successfully.
|
||||
#
|
||||
# Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
# Copyright (c) 2009 - 2011, 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
|
||||
@@ -63,6 +63,7 @@
|
||||
[Protocols]
|
||||
gEfiDiskInfoProtocolGuid # BY_START
|
||||
gEfiBlockIoProtocolGuid # BY_START
|
||||
gEfiBlockIo2ProtocolGuid # BY_START
|
||||
gEfiAtaPassThruProtocolGuid # TO_START
|
||||
gEfiDevicePathProtocolGuid # TO_START
|
||||
|
||||
|
@@ -5,7 +5,7 @@
|
||||
It transforms the high level identity, read/write, reset command to ATA pass
|
||||
through command and protocol.
|
||||
|
||||
Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2009 - 2011, 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
|
||||
@@ -75,14 +75,25 @@ UINTN mMaxTransferBlockNumber[] = {
|
||||
for an ATA device. It assembles the ATA pass through command packet for ATA
|
||||
transaction.
|
||||
|
||||
@param AtaDevice The ATA child device involved for the operation.
|
||||
@param[in, out] AtaDevice The ATA child device involved for the operation.
|
||||
@param[in, out] TaskPacket Pointer to a Pass Thru Command Packet. Optional,
|
||||
if it is NULL, blocking mode, and use the packet
|
||||
in AtaDevice. If it is not NULL, non blocking mode,
|
||||
and pass down this Packet.
|
||||
@param[in] Event If Event is NULL, then blocking I/O is performed.
|
||||
If Event is not NULL and non-blocking I/O is
|
||||
supported,then non-blocking I/O is performed,
|
||||
and Event will be signaled when the write
|
||||
request is completed.
|
||||
|
||||
@return The return status from EFI_ATA_PASS_THRU_PROTOCOL.PassThru().
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
AtaDevicePassThru (
|
||||
IN OUT ATA_DEVICE *AtaDevice
|
||||
IN OUT ATA_DEVICE *AtaDevice,
|
||||
IN OUT EFI_ATA_PASS_THRU_COMMAND_PACKET *TaskPacket, OPTIONAL
|
||||
IN OUT EFI_EVENT Event OPTIONAL
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
@@ -90,12 +101,19 @@ AtaDevicePassThru (
|
||||
EFI_ATA_PASS_THRU_COMMAND_PACKET *Packet;
|
||||
|
||||
//
|
||||
// Assemble packet
|
||||
// Assemble packet. If it is non blocking mode, the Ata driver should keep each
|
||||
// subtask and clean them when the event is signaled.
|
||||
//
|
||||
Packet = &AtaDevice->Packet;
|
||||
Packet->Asb = AtaDevice->Asb;
|
||||
Packet->Acb = &AtaDevice->Acb;
|
||||
Packet->Timeout = ATA_TIMEOUT;
|
||||
if (TaskPacket != NULL) {
|
||||
Packet = TaskPacket;
|
||||
Packet->Asb = AllocateAlignedBuffer (AtaDevice, sizeof (*AtaDevice->Asb));
|
||||
CopyMem (Packet->Asb, AtaDevice->Asb, sizeof (*AtaDevice->Asb));
|
||||
Packet->Acb = AllocateCopyPool(sizeof (EFI_ATA_COMMAND_BLOCK), &AtaDevice->Acb);
|
||||
} else {
|
||||
Packet = &AtaDevice->Packet;
|
||||
Packet->Asb = AtaDevice->Asb;
|
||||
Packet->Acb = &AtaDevice->Acb;
|
||||
}
|
||||
|
||||
AtaPassThru = AtaDevice->AtaBusDriverData->AtaPassThru;
|
||||
|
||||
@@ -104,7 +122,7 @@ AtaDevicePassThru (
|
||||
AtaDevice->Port,
|
||||
AtaDevice->PortMultiplierPort,
|
||||
Packet,
|
||||
NULL
|
||||
Event
|
||||
);
|
||||
//
|
||||
// Ensure ATA pass through caller and callee have the same
|
||||
@@ -257,6 +275,8 @@ IdentifyAtaDevice (
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
DEBUG ((EFI_D_INFO, "AtaBus - Identify Device (%x %x)\n", (UINTN)AtaDevice->Port, (UINTN)AtaDevice->PortMultiplierPort));
|
||||
|
||||
//
|
||||
// Check whether the WORD 88 (supported UltraDMA by drive) is valid
|
||||
//
|
||||
@@ -319,7 +339,7 @@ IdentifyAtaDevice (
|
||||
//
|
||||
// Get ATA model name from identify data structure.
|
||||
//
|
||||
PrintAtaModelName (AtaDevice);
|
||||
PrintAtaModelName (AtaDevice);
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
@@ -354,7 +374,7 @@ DiscoverAtaDevice (
|
||||
//
|
||||
Acb = ZeroMem (&AtaDevice->Acb, sizeof (*Acb));
|
||||
Acb->AtaCommand = ATA_CMD_IDENTIFY_DRIVE;
|
||||
Acb->AtaDeviceHead = (UINT8) (BIT7 | BIT6 | BIT5 | (AtaDevice->PortMultiplierPort << 4));
|
||||
Acb->AtaDeviceHead = (UINT8) (BIT7 | BIT6 | BIT5 | (AtaDevice->PortMultiplierPort << 4));
|
||||
|
||||
//
|
||||
// Prepare for ATA pass through packet.
|
||||
@@ -363,11 +383,12 @@ DiscoverAtaDevice (
|
||||
Packet->InDataBuffer = AtaDevice->IdentifyData;
|
||||
Packet->InTransferLength = sizeof (*AtaDevice->IdentifyData);
|
||||
Packet->Protocol = EFI_ATA_PASS_THRU_PROTOCOL_PIO_DATA_IN;
|
||||
Packet->Length = EFI_ATA_PASS_THRU_LENGTH_BYTES | EFI_ATA_PASS_THRU_LENGTH_SECTOR_COUNT;
|
||||
Packet->Length = EFI_ATA_PASS_THRU_LENGTH_BYTES | EFI_ATA_PASS_THRU_LENGTH_SECTOR_COUNT;
|
||||
Packet->Timeout = ATA_TIMEOUT;
|
||||
|
||||
Retry = MAX_RETRY_TIMES;
|
||||
do {
|
||||
Status = AtaDevicePassThru (AtaDevice);
|
||||
Status = AtaDevicePassThru (AtaDevice, NULL, NULL);
|
||||
if (!EFI_ERROR (Status)) {
|
||||
//
|
||||
// The command is issued successfully
|
||||
@@ -389,11 +410,20 @@ DiscoverAtaDevice (
|
||||
ATA device. It chooses the appropriate ATA command and protocol to invoke PassThru
|
||||
interface of ATA pass through.
|
||||
|
||||
@param AtaDevice The ATA child device involved for the operation.
|
||||
@param Buffer The pointer to the current transaction buffer.
|
||||
@param StartLba The starting logical block address to be accessed.
|
||||
@param TransferLength The block number or sector count of the transfer.
|
||||
@param IsWrite Indicates whether it is a write operation.
|
||||
@param[in, out] AtaDevice The ATA child device involved for the operation.
|
||||
@param[in, out] TaskPacket Pointer to a Pass Thru Command Packet. Optional,
|
||||
if it is NULL, blocking mode, and use the packet
|
||||
in AtaDevice. If it is not NULL, non blocking mode,
|
||||
and pass down this Packet.
|
||||
@param[in, out] Buffer The pointer to the current transaction buffer.
|
||||
@param[in] StartLba The starting logical block address to be accessed.
|
||||
@param[in] TransferLength The block number or sector count of the transfer.
|
||||
@param[in] IsWrite Indicates whether it is a write operation.
|
||||
@param[in] Event If Event is NULL, then blocking I/O is performed.
|
||||
If Event is not NULL and non-blocking I/O is
|
||||
supported,then non-blocking I/O is performed,
|
||||
and Event will be signaled when the write
|
||||
request is completed.
|
||||
|
||||
@retval EFI_SUCCESS The data transfer is complete successfully.
|
||||
@return others Some error occurs when transferring data.
|
||||
@@ -401,11 +431,13 @@ DiscoverAtaDevice (
|
||||
**/
|
||||
EFI_STATUS
|
||||
TransferAtaDevice (
|
||||
IN OUT ATA_DEVICE *AtaDevice,
|
||||
IN OUT VOID *Buffer,
|
||||
IN EFI_LBA StartLba,
|
||||
IN UINT32 TransferLength,
|
||||
IN BOOLEAN IsWrite
|
||||
IN OUT ATA_DEVICE *AtaDevice,
|
||||
IN OUT EFI_ATA_PASS_THRU_COMMAND_PACKET *TaskPacket, OPTIONAL
|
||||
IN OUT VOID *Buffer,
|
||||
IN EFI_LBA StartLba,
|
||||
IN UINT32 TransferLength,
|
||||
IN BOOLEAN IsWrite,
|
||||
IN EFI_EVENT Event OPTIONAL
|
||||
)
|
||||
{
|
||||
EFI_ATA_COMMAND_BLOCK *Acb;
|
||||
@@ -425,7 +457,7 @@ TransferAtaDevice (
|
||||
Acb->AtaSectorNumber = (UINT8) StartLba;
|
||||
Acb->AtaCylinderLow = (UINT8) RShiftU64 (StartLba, 8);
|
||||
Acb->AtaCylinderHigh = (UINT8) RShiftU64 (StartLba, 16);
|
||||
Acb->AtaDeviceHead = (UINT8) (BIT7 | BIT6 | BIT5 | (AtaDevice->PortMultiplierPort << 4));
|
||||
Acb->AtaDeviceHead = (UINT8) (BIT7 | BIT6 | BIT5 | (AtaDevice->PortMultiplierPort << 4));
|
||||
Acb->AtaSectorCount = (UINT8) TransferLength;
|
||||
if (AtaDevice->Lba48Bit) {
|
||||
Acb->AtaSectorNumberExp = (UINT8) RShiftU64 (StartLba, 24);
|
||||
@@ -439,7 +471,12 @@ TransferAtaDevice (
|
||||
//
|
||||
// Prepare for ATA pass through packet.
|
||||
//
|
||||
Packet = ZeroMem (&AtaDevice->Packet, sizeof (*Packet));
|
||||
if (TaskPacket != NULL) {
|
||||
Packet = ZeroMem (TaskPacket, sizeof (*Packet));
|
||||
} else {
|
||||
Packet = ZeroMem (&AtaDevice->Packet, sizeof (*Packet));
|
||||
}
|
||||
|
||||
if (IsWrite) {
|
||||
Packet->OutDataBuffer = Buffer;
|
||||
Packet->OutTransferLength = TransferLength;
|
||||
@@ -447,10 +484,109 @@ TransferAtaDevice (
|
||||
Packet->InDataBuffer = Buffer;
|
||||
Packet->InTransferLength = TransferLength;
|
||||
}
|
||||
|
||||
Packet->Protocol = mAtaPassThruCmdProtocols[AtaDevice->UdmaValid][IsWrite];
|
||||
Packet->Length = EFI_ATA_PASS_THRU_LENGTH_SECTOR_COUNT;
|
||||
Packet->Timeout = ATA_TIMEOUT;
|
||||
|
||||
return AtaDevicePassThru (AtaDevice);
|
||||
return AtaDevicePassThru (AtaDevice, TaskPacket, Event);
|
||||
}
|
||||
|
||||
/**
|
||||
Free SubTask.
|
||||
|
||||
@param[in, out] Task Pointer to task to be freed.
|
||||
|
||||
**/
|
||||
VOID
|
||||
EFIAPI
|
||||
FreeAtaSubTask (
|
||||
IN ATA_BUS_ASYN_TASK *Task
|
||||
)
|
||||
{
|
||||
if (Task->Packet.Asb != NULL) {
|
||||
FreeAlignedBuffer (Task->Packet.Asb, sizeof (Task->Packet.Asb));
|
||||
}
|
||||
if (Task->Packet.Acb != NULL) {
|
||||
FreePool (Task->Packet.Acb);
|
||||
}
|
||||
|
||||
FreePool (Task);
|
||||
}
|
||||
|
||||
/**
|
||||
Call back funtion when the event is signaled.
|
||||
|
||||
@param[in] Event The Event this notify function registered to.
|
||||
@param[in] Context Pointer to the context data registerd to the
|
||||
Event.
|
||||
|
||||
**/
|
||||
VOID
|
||||
EFIAPI
|
||||
AtaNonBlockingCallBack (
|
||||
IN EFI_EVENT Event,
|
||||
IN VOID *Context
|
||||
)
|
||||
{
|
||||
ATA_BUS_ASYN_TASK *Task;
|
||||
|
||||
Task = (ATA_BUS_ASYN_TASK *) Context;
|
||||
gBS->CloseEvent (Event);
|
||||
|
||||
//
|
||||
// Check the command status.
|
||||
// If there is error during the sub task source allocation, the error status
|
||||
// should be returned to the caller directly, so here the Task->Token may already
|
||||
// be deleted by the caller and no need to update the status.
|
||||
//
|
||||
if ((!(*Task->IsError)) && (Task->Packet.Asb->AtaStatus & 0x01) == 0x01) {
|
||||
Task->Token->TransactionStatus = EFI_DEVICE_ERROR;
|
||||
}
|
||||
DEBUG ((
|
||||
DEBUG_INFO,
|
||||
"NON-BLOCKING EVENT FINISHED!- STATUS = %r\n",
|
||||
Task->Token->TransactionStatus
|
||||
));
|
||||
|
||||
//
|
||||
// Reduce the SubEventCount, till it comes to zero.
|
||||
//
|
||||
(*Task->UnsignalledEventCount) --;
|
||||
DEBUG ((DEBUG_INFO, "UnsignalledEventCount = %x\n", *Task->UnsignalledEventCount));
|
||||
|
||||
//
|
||||
// Remove the SubTask from the Task list.
|
||||
//
|
||||
RemoveEntryList (&Task->TaskEntry);
|
||||
if ((*Task->UnsignalledEventCount) == 0) {
|
||||
//
|
||||
// All Sub tasks are done, then signal the upper layyer event.
|
||||
// Except there is error during the sub task source allocation.
|
||||
//
|
||||
if (!(*Task->IsError)) {
|
||||
gBS->SignalEvent (Task->Token->Event);
|
||||
DEBUG ((DEBUG_INFO, "Signal Up Level Event UnsignalledEventCount = %x!\n", *Task->UnsignalledEventCount));
|
||||
}
|
||||
|
||||
FreePool (Task->UnsignalledEventCount);
|
||||
FreePool (Task->IsError);
|
||||
}
|
||||
|
||||
DEBUG ((
|
||||
DEBUG_INFO,
|
||||
"PACKET INFO: Write=%s, Lenght=%x, LowCylinder=%x, HighCylinder=%x,SectionNumber=%x",
|
||||
Task->Packet.OutDataBuffer != NULL ? L"YES" : L"NO",
|
||||
Task->Packet.OutDataBuffer != NULL ? Task->Packet.OutTransferLength : Task->Packet.InTransferLength,
|
||||
Task->Packet.Acb->AtaCylinderLow,
|
||||
Task->Packet.Acb->AtaCylinderHigh,
|
||||
Task->Packet.Acb->AtaSectorCount
|
||||
));
|
||||
|
||||
//
|
||||
// Free the buffer of SubTask.
|
||||
//
|
||||
FreeAtaSubTask (Task);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -460,11 +596,12 @@ TransferAtaDevice (
|
||||
ATA device. It may separate the read/write request into several ATA pass through
|
||||
transactions.
|
||||
|
||||
@param AtaDevice The ATA child device involved for the operation.
|
||||
@param Buffer The pointer to the current transaction buffer.
|
||||
@param StartLba The starting logical block address to be accessed.
|
||||
@param NumberOfBlocks The block number or sector count of the transfer.
|
||||
@param IsWrite Indicates whether it is a write operation.
|
||||
@param[in, out] AtaDevice The ATA child device involved for the operation.
|
||||
@param[in, out] Buffer The pointer to the current transaction buffer.
|
||||
@param[in] StartLba The starting logical block address to be accessed.
|
||||
@param[in] NumberOfBlocks The block number or sector count of the transfer.
|
||||
@param[in] IsWrite Indicates whether it is a write operation.
|
||||
@param[in, out] Token A pointer to the token associated with the transaction.
|
||||
|
||||
@retval EFI_SUCCESS The data transfer is complete successfully.
|
||||
@return others Some error occurs when transferring data.
|
||||
@@ -476,36 +613,146 @@ AccessAtaDevice(
|
||||
IN OUT UINT8 *Buffer,
|
||||
IN EFI_LBA StartLba,
|
||||
IN UINTN NumberOfBlocks,
|
||||
IN BOOLEAN IsWrite
|
||||
IN BOOLEAN IsWrite,
|
||||
IN OUT EFI_BLOCK_IO2_TOKEN *Token
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINTN MaxTransferBlockNumber;
|
||||
UINTN TransferBlockNumber;
|
||||
UINTN BlockSize;
|
||||
|
||||
UINTN *EventCount;
|
||||
UINTN TempCount;
|
||||
ATA_BUS_ASYN_TASK *Task;
|
||||
EFI_EVENT SubEvent;
|
||||
UINTN Index;
|
||||
BOOLEAN *IsError;
|
||||
EFI_TPL OldTpl;
|
||||
|
||||
SubEvent = NULL;
|
||||
TempCount = 0;
|
||||
Status = EFI_SUCCESS;
|
||||
|
||||
EventCount = AllocateZeroPool (sizeof (UINTN));
|
||||
if (EventCount == NULL) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
IsError = AllocateZeroPool (sizeof (BOOLEAN));
|
||||
if (IsError == NULL) {
|
||||
goto EXIT;
|
||||
}
|
||||
*IsError = FALSE;
|
||||
|
||||
//
|
||||
// Initial the return status for Non Blocking.
|
||||
//
|
||||
if (Token != NULL && Token->Event != NULL) {
|
||||
Token->TransactionStatus = EFI_SUCCESS;
|
||||
}
|
||||
//
|
||||
// Ensure AtaDevice->Lba48Bit is a valid boolean value
|
||||
//
|
||||
ASSERT ((UINTN) AtaDevice->Lba48Bit < 2);
|
||||
MaxTransferBlockNumber = mMaxTransferBlockNumber[AtaDevice->Lba48Bit];
|
||||
BlockSize = AtaDevice->BlockMedia.BlockSize;
|
||||
BlockSize = AtaDevice->BlockMedia.BlockSize;
|
||||
|
||||
TempCount = (NumberOfBlocks + MaxTransferBlockNumber - 1) / MaxTransferBlockNumber;
|
||||
*EventCount = TempCount;
|
||||
Index = 0;
|
||||
|
||||
do {
|
||||
if (NumberOfBlocks > MaxTransferBlockNumber) {
|
||||
TransferBlockNumber = MaxTransferBlockNumber;
|
||||
NumberOfBlocks -= MaxTransferBlockNumber;
|
||||
NumberOfBlocks -= MaxTransferBlockNumber;
|
||||
} else {
|
||||
TransferBlockNumber = NumberOfBlocks;
|
||||
NumberOfBlocks = 0;
|
||||
}
|
||||
|
||||
Status = TransferAtaDevice (AtaDevice, Buffer, StartLba, (UINT32) TransferBlockNumber, IsWrite);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
//
|
||||
// Create sub event for the sub Ata task. Non-Blocking Mode.
|
||||
//
|
||||
if (Token != NULL && Token->Event != NULL) {
|
||||
OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
|
||||
Task = AllocateZeroPool (sizeof (ATA_BUS_ASYN_TASK));
|
||||
if (Task == NULL) {
|
||||
//
|
||||
// If resource allocation fail, reduce the total sub event counts.
|
||||
//
|
||||
*EventCount = (*EventCount) - (TempCount - Index);
|
||||
*IsError = TRUE;
|
||||
Token->TransactionStatus = EFI_OUT_OF_RESOURCES;
|
||||
Status = EFI_OUT_OF_RESOURCES;
|
||||
|
||||
gBS->RestoreTPL (OldTpl);
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
Task->UnsignalledEventCount = EventCount;
|
||||
Task->Token = Token;
|
||||
Task->IsError = IsError;
|
||||
|
||||
InsertTailList (&AtaDevice->AtaTaskList, &Task->TaskEntry);
|
||||
|
||||
Status = gBS->CreateEvent (
|
||||
EVT_NOTIFY_SIGNAL,
|
||||
TPL_NOTIFY,
|
||||
AtaNonBlockingCallBack,
|
||||
Task,
|
||||
&SubEvent
|
||||
);
|
||||
//
|
||||
// If resource allocation fail, the un-signalled event count should equal to
|
||||
// the original one minus the unassigned subtasks number.
|
||||
//
|
||||
if (EFI_ERROR (Status)) {
|
||||
*EventCount = (*EventCount) - (TempCount - Index);
|
||||
*IsError = TRUE;
|
||||
gBS->RestoreTPL (OldTpl);
|
||||
goto EXIT;
|
||||
}
|
||||
Index++;
|
||||
gBS->RestoreTPL (OldTpl);
|
||||
|
||||
DEBUG ((EFI_D_INFO, "NON-BLOCKING SET EVENT START: WRITE = %d\n", IsWrite));
|
||||
Status = TransferAtaDevice (AtaDevice, &Task->Packet, Buffer, StartLba, (UINT32) TransferBlockNumber, IsWrite, SubEvent);
|
||||
DEBUG ((
|
||||
EFI_D_INFO,
|
||||
"NON-BLOCKING SET EVENT END:StartLba=%x, TransferBlockNumbers=%x, Status=%r\n",
|
||||
StartLba,
|
||||
TransferBlockNumber,
|
||||
Status
|
||||
));
|
||||
}else {
|
||||
//
|
||||
// Blocking Mode.
|
||||
//
|
||||
DEBUG ((EFI_D_INFO, "BLOCKING BLOCK I/O START: WRITE = %d\n", IsWrite));
|
||||
Status = TransferAtaDevice (AtaDevice, NULL, Buffer, StartLba, (UINT32) TransferBlockNumber, IsWrite, NULL);
|
||||
DEBUG ((
|
||||
EFI_D_INFO,
|
||||
"BLOCKING BLOCK I/O FINISHE - StartLba = %x; TransferBlockNumbers = %x, status = %r\n",
|
||||
StartLba,
|
||||
TransferBlockNumber,
|
||||
Status
|
||||
));
|
||||
}
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
StartLba += TransferBlockNumber;
|
||||
Buffer += TransferBlockNumber * BlockSize;
|
||||
} while (NumberOfBlocks > 0);
|
||||
|
||||
EXIT:
|
||||
|
||||
if (*EventCount == 0) {
|
||||
FreePool (EventCount);
|
||||
FreePool (IsError);
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
Reference in New Issue
Block a user