]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Introduce tow non-blocking task lists to AtaBus. One maintains the sub-task which...
authorqianouyang <qianouyang@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 16 Mar 2012 03:31:47 +0000 (03:31 +0000)
committerqianouyang <qianouyang@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 16 Mar 2012 03:31:47 +0000 (03:31 +0000)
Signed-off-by: qianouyang
Reviewed-by: czhang46 erictian
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13105 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.c
MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.h
MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBus.c
MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBus.h
MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBusDxe.inf
MdeModulePkg/Bus/Ata/AtaBusDxe/AtaPassThruExecute.c

index 2494c6abf07e73eb020725b214e4e1569504adba..ee49e6eff077bd2a57b598f6a9e1780e460a343d 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   This file implements ATA_PASSTHRU_PROCTOCOL and EXT_SCSI_PASSTHRU_PROTOCOL interfaces\r
   for managed ATA controllers.\r
-    \r
-  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+\r
+  Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -46,14 +46,14 @@ ATA_ATAPI_PASS_THRU_INSTANCE gAtaAtapiPassThruInstanceTemplate = {
     sizeof (UINTN)\r
   },\r
   {                   // AtaPassThru\r
-    NULL,  \r
+    NULL,\r
     AtaPassThruPassThru,\r
     AtaPassThruGetNextPort,\r
     AtaPassThruGetNextDevice,\r
     AtaPassThruBuildDevicePath,\r
     AtaPassThruGetDevice,\r
     AtaPassThruResetPort,\r
-    AtaPassThruResetDevice  \r
+    AtaPassThruResetDevice\r
   },\r
   {                   // ExtScsiPassThruMode\r
     //\r
@@ -65,7 +65,7 @@ ATA_ATAPI_PASS_THRU_INSTANCE gAtaAtapiPassThruInstanceTemplate = {
     // both EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_PHYSICAL and EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_LOGICAL\r
     // bits.\r
     // Note that the driver doesn't support ExtScsiPassThru non blocking I/O.\r
-    // \r
+    //\r
     EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_PHYSICAL | EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_LOGICAL,\r
     //\r
     // IoAlign\r
@@ -101,7 +101,7 @@ ATA_ATAPI_PASS_THRU_INSTANCE gAtaAtapiPassThruInstanceTemplate = {
   0,                  // PreviousLun\r
   NULL,               // Timer event\r
   {                   // NonBlocking TaskList\r
-    NULL,             \r
+    NULL,\r
     NULL\r
   }\r
 };\r
@@ -142,7 +142,7 @@ UINT8 mScsiId[TARGET_MAX_BYTES] = {
   supports both blocking I/O and non-blocking I/O. The blocking I/O functionality is required,\r
   and the non-blocking I/O functionality is optional.\r
 \r
-  @param[in]      Port               The port number of the ATA device to send the command. \r
+  @param[in]      Port               The port number of the ATA device to send the command.\r
   @param[in]      PortMultiplierPort The port multiplier port number of the ATA device to send the command.\r
                                      If there is no port multiplier, then specify 0.\r
   @param[in, out] Packet             A pointer to the ATA command to send to the ATA device specified by Port\r
@@ -178,14 +178,14 @@ AtaPassThruPassThruExecute (
   IN     UINT16                           Port,\r
   IN     UINT16                           PortMultiplierPort,\r
   IN OUT EFI_ATA_PASS_THRU_COMMAND_PACKET *Packet,\r
-  IN     ATA_ATAPI_PASS_THRU_INSTANCE     *Instance, \r
+  IN     ATA_ATAPI_PASS_THRU_INSTANCE     *Instance,\r
   IN     ATA_NONBLOCK_TASK                *Task OPTIONAL\r
   )\r
 {\r
   EFI_ATA_PASS_THRU_CMD_PROTOCOL  Protocol;\r
   EFI_ATA_HC_WORK_MODE            Mode;\r
   EFI_STATUS                      Status;\r
-  \r
+\r
   Protocol = Packet->Protocol;\r
 \r
   Mode = Instance->Mode;\r
@@ -195,11 +195,11 @@ AtaPassThruPassThruExecute (
       // Reassign IDE mode io port registers' base addresses\r
       //\r
       Status = GetIdeRegisterIoAddr (Instance->PciIo, Instance->IdeRegisters);\r
-      \r
+\r
       if (EFI_ERROR (Status)) {\r
         return Status;\r
       }\r
-      \r
+\r
       switch (Protocol) {\r
         case EFI_ATA_PASS_THRU_PROTOCOL_ATA_NON_DATA:\r
           Status = AtaNonDataCommandIn (\r
@@ -207,7 +207,7 @@ AtaPassThruPassThruExecute (
                      &Instance->IdeRegisters[Port],\r
                      Packet->Acb,\r
                      Packet->Asb,\r
-                     Packet->Timeout, \r
+                     Packet->Timeout,\r
                      Task\r
                      );\r
           break;\r
@@ -313,7 +313,7 @@ AtaPassThruPassThruExecute (
                      Packet->Asb,\r
                      Packet->OutDataBuffer,\r
                      Packet->OutTransferLength,\r
-                     Packet->Timeout, \r
+                     Packet->Timeout,\r
                      Task\r
                      );\r
           break;\r
@@ -360,7 +360,7 @@ AtaPassThruPassThruExecute (
       Status = EFI_DEVICE_ERROR;\r
       break;\r
   }\r
-  \r
+\r
   return Status;\r
 }\r
 \r
@@ -369,11 +369,11 @@ AtaPassThruPassThruExecute (
 \r
   @param[in]  Event     The Event this notify function registered to.\r
   @param[in]  Context   Pointer to the context data registered to the\r
-                        Event. \r
\r
+                        Event.\r
+\r
 **/\r
 VOID\r
-EFIAPI \r
+EFIAPI\r
 AsyncNonBlockingTransferRoutine (\r
   EFI_EVENT  Event,\r
   VOID*      Context\r
@@ -388,7 +388,7 @@ AsyncNonBlockingTransferRoutine (
   Instance   = (ATA_ATAPI_PASS_THRU_INSTANCE *) Context;\r
   EntryHeader = &Instance->NonBlockingTaskList;\r
   //\r
-  // Get the Taks from the Taks List and execute it, until there is \r
+  // Get the Taks from the Taks List and execute it, until there is\r
   // no task in the list or the device is busy with task (EFI_NOT_READY).\r
   //\r
   while (TRUE) {\r
@@ -408,23 +408,24 @@ AsyncNonBlockingTransferRoutine (
                );\r
 \r
     //\r
-    // If the data transfer meet a error which is not dumped into the status block\r
-    // set the Status block related bit.\r
+    // If the data transfer meet a error, remove all tasks in the list since these tasks are\r
+    // associated with one task from Ata Bus and signal the event with error status.\r
     //\r
     if ((Status != EFI_NOT_READY) && (Status != EFI_SUCCESS)) {\r
-      Task->Packet->Asb->AtaStatus = 0x01;\r
+      DestroyAsynTaskList (Instance, TRUE);\r
+      break;\r
     }\r
+\r
     //\r
     // For Non blocking mode, the Status of EFI_NOT_READY means the operation\r
-    // is not finished yet. Other Status indicate the operation is either\r
-    // successful or failed. \r
+    // is not finished yet. Otherwise the operation is successful.\r
     //\r
-    if (Status != EFI_NOT_READY) {\r
+    if (Status == EFI_NOT_READY) {\r
+      break;\r
+    } else {\r
       RemoveEntryList (&Task->Link);\r
       gBS->SignalEvent (Task->Event);\r
       FreePool (Task);\r
-    } else {\r
-      break;\r
     }\r
   }\r
 }\r
@@ -465,33 +466,33 @@ InitializeAtaAtapiPassThru (
 }\r
 \r
 /**\r
-  Tests to see if this driver supports a given controller. If a child device is provided, \r
+  Tests to see if this driver supports a given controller. If a child device is provided,\r
   it further tests to see if this driver supports creating a handle for the specified child device.\r
 \r
-  This function checks to see if the driver specified by This supports the device specified by \r
-  ControllerHandle. Drivers will typically use the device path attached to \r
-  ControllerHandle and/or the services from the bus I/O abstraction attached to \r
-  ControllerHandle to determine if the driver supports ControllerHandle. This function \r
-  may be called many times during platform initialization. In order to reduce boot times, the tests \r
-  performed by this function must be very small, and take as little time as possible to execute. This \r
-  function must not change the state of any hardware devices, and this function must be aware that the \r
-  device specified by ControllerHandle may already be managed by the same driver or a \r
-  different driver. This function must match its calls to AllocatePages() with FreePages(), \r
-  AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().  \r
-  Because ControllerHandle may have been previously started by the same driver, if a protocol is \r
-  already in the opened state, then it must not be closed with CloseProtocol(). This is required \r
+  This function checks to see if the driver specified by This supports the device specified by\r
+  ControllerHandle. Drivers will typically use the device path attached to\r
+  ControllerHandle and/or the services from the bus I/O abstraction attached to\r
+  ControllerHandle to determine if the driver supports ControllerHandle. This function\r
+  may be called many times during platform initialization. In order to reduce boot times, the tests\r
+  performed by this function must be very small, and take as little time as possible to execute. This\r
+  function must not change the state of any hardware devices, and this function must be aware that the\r
+  device specified by ControllerHandle may already be managed by the same driver or a\r
+  different driver. This function must match its calls to AllocatePages() with FreePages(),\r
+  AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().\r
+  Because ControllerHandle may have been previously started by the same driver, if a protocol is\r
+  already in the opened state, then it must not be closed with CloseProtocol(). This is required\r
   to guarantee the state of ControllerHandle is not modified by this function.\r
 \r
   @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
-  @param[in]  ControllerHandle     The handle of the controller to test. This handle \r
-                                   must support a protocol interface that supplies \r
+  @param[in]  ControllerHandle     The handle of the controller to test. This handle\r
+                                   must support a protocol interface that supplies\r
                                    an I/O abstraction to the driver.\r
-  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This \r
-                                   parameter is ignored by device drivers, and is optional for bus \r
-                                   drivers. For bus drivers, if this parameter is not NULL, then \r
-                                   the bus driver must determine if the bus controller specified \r
-                                   by ControllerHandle and the child controller specified \r
-                                   by RemainingDevicePath are both supported by this \r
+  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This\r
+                                   parameter is ignored by device drivers, and is optional for bus\r
+                                   drivers. For bus drivers, if this parameter is not NULL, then\r
+                                   the bus driver must determine if the bus controller specified\r
+                                   by ControllerHandle and the child controller specified\r
+                                   by RemainingDevicePath are both supported by this\r
                                    bus driver.\r
 \r
   @retval EFI_SUCCESS              The device specified by ControllerHandle and\r
@@ -614,8 +615,8 @@ AtaAtapiPassThruSupported (
   Starts a device controller or a bus controller.\r
 \r
   The Start() function is designed to be invoked from the EFI boot service ConnectController().\r
-  As a result, much of the error checking on the parameters to Start() has been moved into this \r
-  common boot service. It is legal to call Start() from other locations, \r
+  As a result, much of the error checking on the parameters to Start() has been moved into this\r
+  common boot service. It is legal to call Start() from other locations,\r
   but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
   1. ControllerHandle must be a valid EFI_HANDLE.\r
   2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
@@ -624,18 +625,18 @@ AtaAtapiPassThruSupported (
      have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r
 \r
   @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
-  @param[in]  ControllerHandle     The handle of the controller to start. This handle \r
-                                   must support a protocol interface that supplies \r
+  @param[in]  ControllerHandle     The handle of the controller to start. This handle\r
+                                   must support a protocol interface that supplies\r
                                    an I/O abstraction to the driver.\r
-  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This \r
-                                   parameter is ignored by device drivers, and is optional for bus \r
-                                   drivers. For a bus driver, if this parameter is NULL, then handles \r
+  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This\r
+                                   parameter is ignored by device drivers, and is optional for bus\r
+                                   drivers. For a bus driver, if this parameter is NULL, then handles\r
                                    for all the children of Controller are created by this driver.\r
-                                   If this parameter is not NULL and the first Device Path Node is \r
-                                   not the End of Device Path Node, then only the handle for the \r
-                                   child device specified by the first Device Path Node of \r
+                                   If this parameter is not NULL and the first Device Path Node is\r
+                                   not the End of Device Path Node, then only the handle for the\r
+                                   child device specified by the first Device Path Node of\r
                                    RemainingDevicePath is created by this driver.\r
-                                   If the first Device Path Node of RemainingDevicePath is \r
+                                   If the first Device Path Node of RemainingDevicePath is\r
                                    the End of Device Path Node, no child handle is created by this\r
                                    driver.\r
 \r
@@ -754,7 +755,7 @@ AtaAtapiPassThruStart (
   if (EFI_ERROR (Status)) {\r
     goto ErrorExit;\r
   }\r
-  \r
+\r
   //\r
   // Set 1ms timer.\r
   //\r
@@ -808,10 +809,10 @@ ErrorExit:
 \r
 /**\r
   Stops a device controller or a bus controller.\r
-  \r
-  The Stop() function is designed to be invoked from the EFI boot service DisconnectController(). \r
-  As a result, much of the error checking on the parameters to Stop() has been moved \r
-  into this common boot service. It is legal to call Stop() from other locations, \r
+\r
+  The Stop() function is designed to be invoked from the EFI boot service DisconnectController().\r
+  As a result, much of the error checking on the parameters to Stop() has been moved\r
+  into this common boot service. It is legal to call Stop() from other locations,\r
   but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
   1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
      same driver's Start() function.\r
@@ -819,13 +820,13 @@ ErrorExit:
      EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
      Start() function, and the Start() function must have called OpenProtocol() on\r
      ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
-  \r
+\r
   @param[in]  This              A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
-  @param[in]  ControllerHandle  A handle to the device being stopped. The handle must \r
-                                support a bus specific I/O protocol for the driver \r
+  @param[in]  ControllerHandle  A handle to the device being stopped. The handle must\r
+                                support a bus specific I/O protocol for the driver\r
                                 to use to stop the device.\r
   @param[in]  NumberOfChildren  The number of child device handles in ChildHandleBuffer.\r
-  @param[in]  ChildHandleBuffer An array of child handles to be freed. May be NULL \r
+  @param[in]  ChildHandleBuffer An array of child handles to be freed. May be NULL\r
                                 if NumberOfChildren is 0.\r
 \r
   @retval EFI_SUCCESS           The device was stopped.\r
@@ -872,7 +873,7 @@ AtaAtapiPassThruStop (
     gBS->CloseEvent (Instance->TimerEvent);\r
     Instance->TimerEvent = NULL;\r
   }\r
-  DestroyAsynTaskList (Instance);\r
+  DestroyAsynTaskList (Instance, FALSE);\r
 \r
   //\r
   // Disable this ATA host controller.\r
@@ -968,13 +969,13 @@ AtaAtapiPassThruStop (
 \r
 /**\r
   Traverse the attached ATA devices list to find out the device to access.\r
-  \r
+\r
   @param[in]  Instance            A pointer to the ATA_ATAPI_PASS_THRU_INSTANCE instance.\r
-  @param[in]  Port                The port number of the ATA device to send the command. \r
+  @param[in]  Port                The port number of the ATA device to send the command.\r
   @param[in]  PortMultiplierPort  The port multiplier port number of the ATA device to send the command.\r
                                   If there is no port multiplier, then specify 0.\r
   @param[in]  DeviceType          The device type of the ATA device.\r
-  \r
+\r
   @retval     The pointer to the data structure of the device info to access.\r
 \r
 **/\r
@@ -995,7 +996,7 @@ SearchDeviceInfoList (
     DeviceInfo = ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node);\r
 \r
     if ((DeviceInfo->Type == DeviceType) &&\r
-        (Port == DeviceInfo->Port) && \r
+        (Port == DeviceInfo->Port) &&\r
         (PortMultiplier == DeviceInfo->PortMultiplier)) {\r
       return Node;\r
     }\r
@@ -1009,9 +1010,9 @@ SearchDeviceInfoList (
 /**\r
   Allocate device info data structure to contain device info.\r
   And insert the data structure to the tail of device list for tracing.\r
-    \r
+\r
   @param[in]  Instance            A pointer to the ATA_ATAPI_PASS_THRU_INSTANCE instance.\r
-  @param[in]  Port                The port number of the ATA device to send the command. \r
+  @param[in]  Port                The port number of the ATA device to send the command.\r
   @param[in]  PortMultiplierPort  The port multiplier port number of the ATA device to send the command.\r
                                   If there is no port multiplier, then specify 0.\r
   @param[in]  DeviceType          The device type of the ATA device.\r
@@ -1059,7 +1060,7 @@ CreateNewDeviceInfo (
 \r
 /**\r
   Destroy all attached ATA devices info.\r
-  \r
+\r
   @param[in]  Instance          A pointer to the ATA_ATAPI_PASS_THRU_INSTANCE instance.\r
 \r
 **/\r
@@ -1088,14 +1089,17 @@ DestroyDeviceInfoList (
 \r
 /**\r
   Destroy all pending non blocking tasks.\r
-  \r
-  @param[in]  Instance  A pointer to the ATA_ATAPI_PASS_THRU_INSTANCE instance.\r
+\r
+  @param[in]  Instance    A pointer to the ATA_ATAPI_PASS_THRU_INSTANCE instance.\r
+  @param[in]  IsSigEvent  Indicate whether signal the task event when remove the\r
+                          task.\r
 \r
 **/\r
 VOID\r
 EFIAPI\r
 DestroyAsynTaskList (\r
-  IN ATA_ATAPI_PASS_THRU_INSTANCE *Instance\r
+  IN ATA_ATAPI_PASS_THRU_INSTANCE *Instance,\r
+  IN BOOLEAN                       IsSigEvent\r
   )\r
 {\r
   LIST_ENTRY           *Entry;\r
@@ -1108,7 +1112,7 @@ DestroyAsynTaskList (
     //\r
     // Free the Subtask list.\r
     //\r
-    for (Entry = (&Instance->NonBlockingTaskList)->ForwardLink; \r
+    for (Entry = (&Instance->NonBlockingTaskList)->ForwardLink;\r
         Entry != (&Instance->NonBlockingTaskList);\r
        ) {\r
       DelEntry = Entry;\r
@@ -1116,6 +1120,10 @@ DestroyAsynTaskList (
       Task     = ATA_NON_BLOCK_TASK_FROM_ENTRY (DelEntry);\r
 \r
       RemoveEntryList (DelEntry);\r
+      if (IsSigEvent) {\r
+        Task->Packet->Asb->AtaStatus = 0x01;\r
+        gBS->SignalEvent (Task->Event);\r
+      }\r
       FreePool (Task);\r
     }\r
   }\r
@@ -1124,9 +1132,9 @@ DestroyAsynTaskList (
 \r
 /**\r
   Enumerate all attached ATA devices at IDE mode or AHCI mode separately.\r
-  \r
-  The function is designed to enumerate all attached ATA devices. \r
-  \r
+\r
+  The function is designed to enumerate all attached ATA devices.\r
+\r
   @param[in]  Instance          A pointer to the ATA_ATAPI_PASS_THRU_INSTANCE instance.\r
 \r
   @retval EFI_SUCCESS           Successfully enumerate attached ATA devices.\r
@@ -1196,8 +1204,8 @@ Done:
   supports both blocking I/O and non-blocking I/O. The blocking I/O functionality is required,\r
   and the non-blocking I/O functionality is optional.\r
 \r
-  @param[in]      This               A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance. \r
-  @param[in]      Port               The port number of the ATA device to send the command. \r
+  @param[in]      This               A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.\r
+  @param[in]      Port               The port number of the ATA device to send the command.\r
   @param[in]      PortMultiplierPort The port multiplier port number of the ATA device to send the command.\r
                                      If there is no port multiplier, then specify 0.\r
   @param[in, out] Packet             A pointer to the ATA command to send to the ATA device specified by Port\r
@@ -1207,11 +1215,11 @@ Done:
                                      Event is not NULL and non blocking I/O is supported, then non-blocking\r
                                      I/O is performed, and Event will be signaled when the ATA command completes.\r
 \r
-  @retval EFI_SUCCESS                The ATA command was sent by the host. For bi-directional commands, \r
+  @retval EFI_SUCCESS                The ATA command was sent by the host. For bi-directional commands,\r
                                      InTransferLength bytes were transferred from InDataBuffer. For write and\r
                                      bi-directional commands, OutTransferLength bytes were transferred by OutDataBuffer.\r
   @retval EFI_BAD_BUFFER_SIZE        The ATA command was not executed. The number of bytes that could be transferred\r
-                                     is returned in InTransferLength. For write and bi-directional commands, \r
+                                     is returned in InTransferLength. For write and bi-directional commands,\r
                                      OutTransferLength bytes were transferred by OutDataBuffer.\r
   @retval EFI_NOT_READY              The ATA command could not be sent because there are too many ATA commands\r
                                      already queued. The caller may retry again later.\r
@@ -1256,7 +1264,7 @@ AtaPassThruPassThru (
   //\r
   // convert the transfer length from sector count to byte.\r
   //\r
-  if (((Packet->Length & EFI_ATA_PASS_THRU_LENGTH_BYTES) == 0) && \r
+  if (((Packet->Length & EFI_ATA_PASS_THRU_LENGTH_BYTES) == 0) &&\r
        (Packet->InTransferLength != 0)) {\r
     Packet->InTransferLength = Packet->InTransferLength * 0x200;\r
   }\r
@@ -1278,7 +1286,7 @@ AtaPassThruPassThru (
   //\r
   // Check whether this device needs 48-bit addressing (ATAPI-6 ata device).\r
   // Per ATA-6 spec, word83: bit15 is zero and bit14 is one.\r
-  // If bit10 is one, it means the ata device support 48-bit addressing. \r
+  // If bit10 is one, it means the ata device support 48-bit addressing.\r
   //\r
   DeviceInfo     = ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node);\r
   IdentifyData   = DeviceInfo->IdentifyData;\r
@@ -1297,9 +1305,9 @@ AtaPassThruPassThru (
   //\r
   // If the data buffer described by InDataBuffer/OutDataBuffer and InTransferLength/OutTransferLength\r
   // is too big to be transferred in a single command, then no data is transferred and EFI_BAD_BUFFER_SIZE\r
-  // is returned. \r
+  // is returned.\r
   //\r
-  if (((Packet->InTransferLength != 0) && (Packet->InTransferLength > MaxSectorCount * 0x200)) || \r
+  if (((Packet->InTransferLength != 0) && (Packet->InTransferLength > MaxSectorCount * 0x200)) ||\r
       ((Packet->OutTransferLength != 0) && (Packet->OutTransferLength > MaxSectorCount * 0x200))) {\r
     return EFI_BAD_BUFFER_SIZE;\r
   }\r
@@ -1312,7 +1320,7 @@ AtaPassThruPassThru (
     if (Task == NULL) {\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
-    \r
+\r
     Task->Signature      = ATA_NONBLOCKING_TASK_SIGNATURE;\r
     Task->Port           = Port;\r
     Task->PortMultiplier = PortMultiplierPort;\r
@@ -1356,7 +1364,7 @@ AtaPassThruPassThru (
   If Port is the port number of the last port on the ATA controller, then EFI_NOT_FOUND is\r
   returned.\r
 \r
-  @param[in]      This          A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance. \r
+  @param[in]      This          A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.\r
   @param[in, out] Port          On input, a pointer to the port number on the ATA controller.\r
                                 On output, a pointer to the next port number on the ATA\r
                                 controller. An input value of 0xFFFF retrieves the first port\r
@@ -1436,36 +1444,36 @@ Exit:
 }\r
 \r
 /**\r
-  Used to retrieve the list of legal port multiplier port numbers for ATA devices on a port of an ATA \r
-  controller. These can either be the list of port multiplier ports where ATA devices are actually \r
-  present on port or the list of legal port multiplier ports on that port. Regardless, the caller of this \r
-  function must probe the port number and port multiplier port number returned to see if an ATA \r
+  Used to retrieve the list of legal port multiplier port numbers for ATA devices on a port of an ATA\r
+  controller. These can either be the list of port multiplier ports where ATA devices are actually\r
+  present on port or the list of legal port multiplier ports on that port. Regardless, the caller of this\r
+  function must probe the port number and port multiplier port number returned to see if an ATA\r
   device is actually present.\r
 \r
-  The GetNextDevice() function retrieves the port multiplier port number of an ATA device \r
+  The GetNextDevice() function retrieves the port multiplier port number of an ATA device\r
   present on a port of an ATA controller.\r
 \r
-  If PortMultiplierPort points to a port multiplier port number value that was returned on a \r
+  If PortMultiplierPort points to a port multiplier port number value that was returned on a\r
   previous call to GetNextDevice(), then the port multiplier port number of the next ATA device\r
   on the port of the ATA controller is returned in PortMultiplierPort, and EFI_SUCCESS is\r
   returned.\r
 \r
-  If PortMultiplierPort points to 0xFFFF, then the port multiplier port number of the first \r
-  ATA device on port of the ATA controller is returned in PortMultiplierPort and \r
+  If PortMultiplierPort points to 0xFFFF, then the port multiplier port number of the first\r
+  ATA device on port of the ATA controller is returned in PortMultiplierPort and\r
   EFI_SUCCESS is returned.\r
 \r
   If PortMultiplierPort is not 0xFFFF and the value pointed to by PortMultiplierPort\r
   was not returned on a previous call to GetNextDevice(), then EFI_INVALID_PARAMETER\r
   is returned.\r
 \r
-  If PortMultiplierPort is the port multiplier port number of the last ATA device on the port of \r
+  If PortMultiplierPort is the port multiplier port number of the last ATA device on the port of\r
   the ATA controller, then EFI_NOT_FOUND is returned.\r
 \r
   @param[in]      This               A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.\r
   @param[in]      Port               The port number present on the ATA controller.\r
   @param[in, out] PortMultiplierPort On input, a pointer to the port multiplier port number of an\r
-                                     ATA device present on the ATA controller. \r
-                                     If on input a PortMultiplierPort of 0xFFFF is specified, \r
+                                     ATA device present on the ATA controller.\r
+                                     If on input a PortMultiplierPort of 0xFFFF is specified,\r
                                      then the port multiplier port number of the first ATA device\r
                                      is returned. On output, a pointer to the port multiplier port\r
                                      number of the next ATA device present on an ATA controller.\r
@@ -1635,7 +1643,7 @@ AtaPassThruBuildDevicePath (
 \r
   The GetDevice() function determines the port and port multiplier port number associated with\r
   the ATA device described by DevicePath. If DevicePath is a device path node type that the\r
-  ATA Pass Thru driver supports, then the ATA Pass Thru driver will attempt to translate the contents \r
+  ATA Pass Thru driver supports, then the ATA Pass Thru driver will attempt to translate the contents\r
   DevicePath into a port number and port multiplier port number.\r
 \r
   If this translation is successful, then that port number and port multiplier port number are returned\r
@@ -1643,11 +1651,11 @@ AtaPassThruBuildDevicePath (
 \r
   If DevicePath, Port, or PortMultiplierPort are NULL, then EFI_INVALID_PARAMETER is returned.\r
 \r
-  If DevicePath is not a device path node type that the ATA Pass Thru driver supports, then \r
+  If DevicePath is not a device path node type that the ATA Pass Thru driver supports, then\r
   EFI_UNSUPPORTED is returned.\r
 \r
-  If DevicePath is a device path node type that the ATA Pass Thru driver supports, but there is not \r
-  a valid translation from DevicePath to a port number and port multiplier port number, then \r
+  If DevicePath is a device path node type that the ATA Pass Thru driver supports, but there is not\r
+  a valid translation from DevicePath to a port number and port multiplier port number, then\r
   EFI_NOT_FOUND is returned.\r
 \r
   @param[in]  This                A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.\r
@@ -1759,7 +1767,7 @@ AtaPassThruResetPort (
   If this ATA controller does not support a device reset operation, then EFI_UNSUPPORTED is\r
   returned.\r
 \r
-  If Port or PortMultiplierPort are not in a valid range for this ATA controller, then \r
+  If Port or PortMultiplierPort are not in a valid range for this ATA controller, then\r
   EFI_INVALID_PARAMETER is returned.\r
 \r
   If a device error occurs while executing that device reset operation, then EFI_DEVICE_ERROR\r
@@ -1795,9 +1803,9 @@ AtaPassThruResetDevice (
 }\r
 \r
 /**\r
-  Sends a SCSI Request Packet to a SCSI device that is attached to the SCSI channel. This function   \r
+  Sends a SCSI Request Packet to a SCSI device that is attached to the SCSI channel. This function\r
   supports both blocking I/O and nonblocking I/O. The blocking I/O functionality is required, and the\r
-  nonblocking I/O functionality is optional.                                                             \r
+  nonblocking I/O functionality is optional.\r
 \r
   @param  This    A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
   @param  Target  The Target is an array of size TARGET_MAX_BYTES and it represents\r
@@ -1866,7 +1874,7 @@ ExtScsiPassThruPassThru (
       (Packet->CdbLength != 12) && (Packet->CdbLength != 16)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
   if ((This->Mode->IoAlign > 1) && !IS_ALIGNED(Packet->InDataBuffer, This->Mode->IoAlign)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -1886,7 +1894,7 @@ ExtScsiPassThruPassThru (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  // \r
+  //\r
   // The layout of Target array:\r
   //  ________________________________________________________________________\r
   // |       Byte 0        |       Byte 1        | ... | TARGET_MAX_BYTES - 1 |\r
@@ -1943,10 +1951,10 @@ ExtScsiPassThruPassThru (
 }\r
 \r
 /**\r
-  Used to retrieve the list of legal Target IDs and LUNs for SCSI devices on a SCSI channel. These       \r
+  Used to retrieve the list of legal Target IDs and LUNs for SCSI devices on a SCSI channel. These\r
   can either be the list SCSI devices that are actually present on the SCSI channel, or the list of legal\r
-  Target Ids and LUNs for the SCSI channel. Regardless, the caller of this function must probe the       \r
-  Target ID and LUN returned to see if a SCSI device is actually present at that location on the SCSI    \r
+  Target Ids and LUNs for the SCSI channel. Regardless, the caller of this function must probe the\r
+  Target ID and LUN returned to see if a SCSI device is actually present at that location on the SCSI\r
   channel.\r
 \r
   @param  This   A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
@@ -2027,7 +2035,7 @@ ExtScsiPassThruGetNextTargetLun (
       DeviceInfo = ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node);\r
 \r
       if ((DeviceInfo->Type == EfiIdeCdrom) &&\r
-         ((Target8[0] < DeviceInfo->Port) || \r
+         ((Target8[0] < DeviceInfo->Port) ||\r
           ((Target8[0] == DeviceInfo->Port) &&\r
            (Target8[1] < DeviceInfo->PortMultiplier)))) {\r
         Target8[0] = (UINT8)DeviceInfo->Port;\r
@@ -2067,7 +2075,7 @@ Exit:
   //\r
   Instance->PreviousTargetId = *Target16;\r
   Instance->PreviousLun      = *Lun;\r
-  \r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -2134,7 +2142,7 @@ ExtScsiPassThruBuildDevicePath (
   if (SearchDeviceInfoList(Instance, Port, PortMultiplier, EfiIdeCdrom) == NULL) {\r
     return EFI_NOT_FOUND;\r
   }\r
-  \r
+\r
   if (Instance->Mode == EfiAtaIdeMode) {\r
     DevicePathNode = AllocateCopyPool (sizeof (ATAPI_DEVICE_PATH), &mAtapiDevicePathTemplate);\r
     if (DevicePathNode == NULL) {\r
@@ -2293,10 +2301,10 @@ ExtScsiPassThruResetTargetLun (
 }\r
 \r
 /**\r
-  Used to retrieve the list of legal Target IDs for SCSI devices on a SCSI channel. These can either     \r
+  Used to retrieve the list of legal Target IDs for SCSI devices on a SCSI channel. These can either\r
   be the list SCSI devices that are actually present on the SCSI channel, or the list of legal Target IDs\r
-  for the SCSI channel. Regardless, the caller of this function must probe the Target ID returned to     \r
-  see if a SCSI device is actually present at that location on the SCSI channel.                         \r
+  for the SCSI channel. Regardless, the caller of this function must probe the Target ID returned to\r
+  see if a SCSI device is actually present at that location on the SCSI channel.\r
 \r
   @param  This   A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
   @param  Target (TARGET_MAX_BYTES) of a SCSI device present on the SCSI channel.\r
@@ -2366,7 +2374,7 @@ ExtScsiPassThruGetNextTarget (
       DeviceInfo = ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node);\r
 \r
       if ((DeviceInfo->Type == EfiIdeCdrom) &&\r
-         ((Target8[0] < DeviceInfo->Port) || \r
+         ((Target8[0] < DeviceInfo->Port) ||\r
           ((Target8[0] == DeviceInfo->Port) &&\r
            (Target8[1] < DeviceInfo->PortMultiplier)))) {\r
         Target8[0] = (UINT8)DeviceInfo->Port;\r
index 5be8d24bd73d2d870f5b4d2436b946d9a246ff7a..1d50c30d7be6f22e7aa1f02dc986e03f60e36540 100644 (file)
@@ -1,14 +1,14 @@
 /** @file
   Header file for ATA/ATAPI PASS THRU driver.
-  
-  Copyright (c) 2010 - 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        
-  http://opensource.org/licenses/bsd-license.php                                            
 
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             
+  Copyright (c) 2010 - 2012, 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
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 
 **/
 #ifndef __ATA_ATAPI_PASS_THRU_H__
@@ -95,7 +95,7 @@ typedef struct {
 
   EFI_IDE_REGISTERS                 IdeRegisters[EfiIdeMaxChannel];
   EFI_AHCI_REGISTERS                AhciRegisters;
-  
+
   //
   // The attached device list
   //
@@ -103,18 +103,18 @@ typedef struct {
   UINT64                            OriginalPciAttributes;
 
   //
-  // For AtaPassThru protocol, using the following bytes to record the previous call in 
+  // For AtaPassThru protocol, using the following bytes to record the previous call in
   // GetNextPort()/GetNextDevice().
   //
   UINT16                            PreviousPort;
   UINT16                            PreviousPortMultiplier;
   //
-  // For ExtScsiPassThru protocol, using the following bytes to record the previous call in 
+  // For ExtScsiPassThru protocol, using the following bytes to record the previous call in
   // GetNextTarget()/GetNextTargetLun().
   //
   UINT16                            PreviousTargetId;
   UINT64                            PreviousLun;
+
   //
   // For Non-blocking.
   //
@@ -136,7 +136,7 @@ struct _ATA_NONBLOCK_TASK {
   EFI_EVENT                         Event;
   UINT64                            RetryTimes;
   VOID                              *Map; // Pointer to map.
-  VOID                              *TableMap;// Pointer to PRD table map. 
+  VOID                              *TableMap;// Pointer to PRD table map.
   EFI_ATA_DMA_PRD                   *MapBaseAddress; //  Pointer to range Base address for Map.
   UINTN                             PageCount;      //  The page numbers used by PCIO freebuffer.
 };
@@ -303,33 +303,33 @@ AtaAtapiPassThruComponentNameGetControllerName (
   );
 
 /**
-  Tests to see if this driver supports a given controller. If a child device is provided, 
+  Tests to see if this driver supports a given controller. If a child device is provided,
   it further tests to see if this driver supports creating a handle for the specified child device.
 
-  This function checks to see if the driver specified by This supports the device specified by 
-  ControllerHandle. Drivers will typically use the device path attached to 
-  ControllerHandle and/or the services from the bus I/O abstraction attached to 
-  ControllerHandle to determine if the driver supports ControllerHandle. This function 
-  may be called many times during platform initialization. In order to reduce boot times, the tests 
-  performed by this function must be very small, and take as little time as possible to execute. This 
-  function must not change the state of any hardware devices, and this function must be aware that the 
-  device specified by ControllerHandle may already be managed by the same driver or a 
-  different driver. This function must match its calls to AllocatePages() with FreePages(), 
-  AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().  
-  Because ControllerHandle may have been previously started by the same driver, if a protocol is 
-  already in the opened state, then it must not be closed with CloseProtocol(). This is required 
+  This function checks to see if the driver specified by This supports the device specified by
+  ControllerHandle. Drivers will typically use the device path attached to
+  ControllerHandle and/or the services from the bus I/O abstraction attached to
+  ControllerHandle to determine if the driver supports ControllerHandle. This function
+  may be called many times during platform initialization. In order to reduce boot times, the tests
+  performed by this function must be very small, and take as little time as possible to execute. This
+  function must not change the state of any hardware devices, and this function must be aware that the
+  device specified by ControllerHandle may already be managed by the same driver or a
+  different driver. This function must match its calls to AllocatePages() with FreePages(),
+  AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
+  Because ControllerHandle may have been previously started by the same driver, if a protocol is
+  already in the opened state, then it must not be closed with CloseProtocol(). This is required
   to guarantee the state of ControllerHandle is not modified by this function.
 
   @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
-  @param[in]  ControllerHandle     The handle of the controller to test. This handle 
-                                   must support a protocol interface that supplies 
+  @param[in]  ControllerHandle     The handle of the controller to test. This handle
+                                   must support a protocol interface that supplies
                                    an I/O abstraction to the driver.
-  @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 bus drivers, if this parameter is not NULL, then 
-                                   the bus driver must determine if the bus controller specified 
-                                   by ControllerHandle and the child controller specified 
-                                   by RemainingDevicePath are both supported by this 
+  @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 bus drivers, if this parameter is not NULL, then
+                                   the bus driver must determine if the bus controller specified
+                                   by ControllerHandle and the child controller specified
+                                   by RemainingDevicePath are both supported by this
                                    bus driver.
 
   @retval EFI_SUCCESS              The device specified by ControllerHandle and
@@ -356,28 +356,28 @@ AtaAtapiPassThruSupported (
   Starts a device controller or a bus controller.
 
   The Start() function is designed to be invoked from the EFI boot service ConnectController().
-  As a result, much of the error checking on the parameters to Start() has been moved into this 
-  common boot service. It is legal to call Start() from other locations, 
+  As a result, much of the error checking on the parameters to Start() has been moved into this
+  common boot service. It is legal to call Start() from other locations,
   but the following calling restrictions must be followed, or the system behavior will not be deterministic.
   1. ControllerHandle must be a valid EFI_HANDLE.
   2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
      EFI_DEVICE_PATH_PROTOCOL.
   3. Prior to calling Start(), the Supported() function for the driver specified by This must
-     have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.  
+     have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
 
   @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
-  @param[in]  ControllerHandle     The handle of the controller to start. This handle 
-                                   must support a protocol interface that supplies 
+  @param[in]  ControllerHandle     The handle of the controller to start. This handle
+                                   must support a protocol interface that supplies
                                    an I/O abstraction to the driver.
-  @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.  
-                                   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 
+  @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.
+                                   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
                                    RemainingDevicePath is created by this driver.
-                                   If the first Device Path Node of RemainingDevicePath is 
+                                   If the first Device Path Node of RemainingDevicePath is
                                    the End of Device Path Node, no child handle is created by this
                                    driver.
 
@@ -397,10 +397,10 @@ AtaAtapiPassThruStart (
 
 /**
   Stops a device controller or a bus controller.
-  
-  The Stop() function is designed to be invoked from the EFI boot service DisconnectController(). 
-  As a result, much of the error checking on the parameters to Stop() has been moved 
-  into this common boot service. It is legal to call Stop() from other locations, 
+
+  The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
+  As a result, much of the error checking on the parameters to Stop() has been moved
+  into this common boot service. It is legal to call Stop() from other locations,
   but the following calling restrictions must be followed, or the system behavior will not be deterministic.
   1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
      same driver's Start() function.
@@ -408,13 +408,13 @@ AtaAtapiPassThruStart (
      EFI_HANDLE. In addition, all of these handles must have been created in this driver's
      Start() function, and the Start() function must have called OpenProtocol() on
      ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
-  
+
   @param[in]  This              A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
-  @param[in]  ControllerHandle  A handle to the device being stopped. The handle must 
-                                support a bus specific I/O protocol for the driver 
+  @param[in]  ControllerHandle  A handle to the device being stopped. The handle must
+                                support a bus specific I/O protocol for the driver
                                 to use to stop the device.
   @param[in]  NumberOfChildren  The number of child device handles in ChildHandleBuffer.
-  @param[in]  ChildHandleBuffer An array of child handles to be freed. May be NULL 
+  @param[in]  ChildHandleBuffer An array of child handles to be freed. May be NULL
                                 if NumberOfChildren is 0.
 
   @retval EFI_SUCCESS           The device was stopped.
@@ -432,13 +432,13 @@ AtaAtapiPassThruStop (
 
 /**
   Traverse the attached ATA devices list to find out the device to access.
-  
+
   @param[in]  Instance            A pointer to the ATA_ATAPI_PASS_THRU_INSTANCE instance.
-  @param[in]  Port                The port number of the ATA device to send the command. 
+  @param[in]  Port                The port number of the ATA device to send the command.
   @param[in]  PortMultiplierPort  The port multiplier port number of the ATA device to send the command.
                                   If there is no port multiplier, then specify 0.
   @param[in]  DeviceType          The device type of the ATA device.
-  
+
   @retval     The pointer to the data structure of the device info to access.
 
 **/
@@ -454,9 +454,9 @@ SearchDeviceInfoList (
 /**
   Allocate device info data structure to contain device info.
   And insert the data structure to the tail of device list for tracing.
-    
+
   @param[in]  Instance            A pointer to the ATA_ATAPI_PASS_THRU_INSTANCE instance.
-  @param[in]  Port                The port number of the ATA device to send the command. 
+  @param[in]  Port                The port number of the ATA device to send the command.
   @param[in]  PortMultiplierPort  The port multiplier port number of the ATA device to send the command.
                                   If there is no port multiplier, then specify 0.
   @param[in]  DeviceType          The device type of the ATA device.
@@ -478,7 +478,7 @@ CreateNewDeviceInfo (
 
 /**
   Destroy all attached ATA devices info.
-  
+
   @param[in]  Instance          A pointer to the ATA_ATAPI_PASS_THRU_INSTANCE instance.
 
 **/
@@ -490,21 +490,24 @@ DestroyDeviceInfoList (
 
 /**
   Destroy all pending non blocking tasks.
-  
-  @param[in]  Instance  A pointer to the ATA_ATAPI_PASS_THRU_INSTANCE instance.
+
+  @param[in]  Instance    A pointer to the ATA_ATAPI_PASS_THRU_INSTANCE instance.
+  @param[in]  IsSigEvent  Indicate whether signal the task event when remove the
+                          task.
 
 **/
 VOID
 EFIAPI
 DestroyAsynTaskList (
-  IN ATA_ATAPI_PASS_THRU_INSTANCE *Instance
+  IN ATA_ATAPI_PASS_THRU_INSTANCE *Instance,
+  IN BOOLEAN                       IsSigEvent
   );
 
 /**
   Enumerate all attached ATA devices at IDE mode or AHCI mode separately.
-  
-  The function is designed to enumerate all attached ATA devices. 
-  
+
+  The function is designed to enumerate all attached ATA devices.
+
   @param[in]  Instance          A pointer to the ATA_ATAPI_PASS_THRU_INSTANCE instance.
 
   @retval EFI_SUCCESS           Successfully enumerate attached ATA devices.
@@ -526,9 +529,9 @@ EnumerateAttachedDevice (
 
 **/
 VOID
-EFIAPI 
+EFIAPI
 AsyncNonBlockingTransferRoutine (
-  EFI_EVENT  Event, 
+  EFI_EVENT  Event,
   VOID*      Context
   );
 
@@ -537,8 +540,8 @@ AsyncNonBlockingTransferRoutine (
   supports both blocking I/O and non-blocking I/O. The blocking I/O functionality is required,
   and the non-blocking I/O functionality is optional.
 
-  @param[in]      This               A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance. 
-  @param[in]      Port               The port number of the ATA device to send the command. 
+  @param[in]      This               A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
+  @param[in]      Port               The port number of the ATA device to send the command.
   @param[in]      PortMultiplierPort The port multiplier port number of the ATA device to send the command.
                                      If there is no port multiplier, then specify 0.
   @param[in, out] Packet             A pointer to the ATA command to send to the ATA device specified by Port
@@ -548,11 +551,11 @@ AsyncNonBlockingTransferRoutine (
                                      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 ATA command completes.
 
-  @retval EFI_SUCCESS                The ATA command was sent by the host. For bi-directional commands, 
+  @retval EFI_SUCCESS                The ATA command was sent by the host. For bi-directional commands,
                                      InTransferLength bytes were transferred from InDataBuffer. For write and
                                      bi-directional commands, OutTransferLength bytes were transferred by OutDataBuffer.
   @retval EFI_BAD_BUFFER_SIZE        The ATA command was not executed. The number of bytes that could be transferred
-                                     is returned in InTransferLength. For write and bi-directional commands, 
+                                     is returned in InTransferLength. For write and bi-directional commands,
                                      OutTransferLength bytes were transferred by OutDataBuffer.
   @retval EFI_NOT_READY              The ATA command could not be sent because there are too many ATA commands
                                      already queued. The caller may retry again later.
@@ -590,7 +593,7 @@ AtaPassThruPassThru (
   If Port is the port number of the last port on the ATA controller, then EFI_NOT_FOUND is
   returned.
 
-  @param[in]      This          A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance. 
+  @param[in]      This          A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
   @param[in, out] Port          On input, a pointer to the port number on the ATA controller.
                                 On output, a pointer to the next port number on the ATA
                                 controller. An input value of 0xFFFF retrieves the first port
@@ -610,36 +613,36 @@ AtaPassThruGetNextPort (
   );
 
 /**
-  Used to retrieve the list of legal port multiplier port numbers for ATA devices on a port of an ATA 
-  controller. These can either be the list of port multiplier ports where ATA devices are actually 
-  present on port or the list of legal port multiplier ports on that port. Regardless, the caller of this 
-  function must probe the port number and port multiplier port number returned to see if an ATA 
+  Used to retrieve the list of legal port multiplier port numbers for ATA devices on a port of an ATA
+  controller. These can either be the list of port multiplier ports where ATA devices are actually
+  present on port or the list of legal port multiplier ports on that port. Regardless, the caller of this
+  function must probe the port number and port multiplier port number returned to see if an ATA
   device is actually present.
 
-  The GetNextDevice() function retrieves the port multiplier port number of an ATA device 
+  The GetNextDevice() function retrieves the port multiplier port number of an ATA device
   present on a port of an ATA controller.
 
-  If PortMultiplierPort points to a port multiplier port number value that was returned on a 
+  If PortMultiplierPort points to a port multiplier port number value that was returned on a
   previous call to GetNextDevice(), then the port multiplier port number of the next ATA device
   on the port of the ATA controller is returned in PortMultiplierPort, and EFI_SUCCESS is
   returned.
 
-  If PortMultiplierPort points to 0xFFFF, then the port multiplier port number of the first 
-  ATA device on port of the ATA controller is returned in PortMultiplierPort and 
+  If PortMultiplierPort points to 0xFFFF, then the port multiplier port number of the first
+  ATA device on port of the ATA controller is returned in PortMultiplierPort and
   EFI_SUCCESS is returned.
 
   If PortMultiplierPort is not 0xFFFF and the value pointed to by PortMultiplierPort
   was not returned on a previous call to GetNextDevice(), then EFI_INVALID_PARAMETER
   is returned.
-  
-  If PortMultiplierPort is the port multiplier port number of the last ATA device on the port of 
+
+  If PortMultiplierPort is the port multiplier port number of the last ATA device on the port of
   the ATA controller, then EFI_NOT_FOUND is returned.
 
   @param[in]      This               A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
   @param[in]      Port               The port number present on the ATA controller.
   @param[in, out] PortMultiplierPort On input, a pointer to the port multiplier port number of an
-                                     ATA device present on the ATA controller. 
-                                     If on input a PortMultiplierPort of 0xFFFF is specified, 
+                                     ATA device present on the ATA controller.
+                                     If on input a PortMultiplierPort of 0xFFFF is specified,
                                      then the port multiplier port number of the first ATA device
                                      is returned. On output, a pointer to the port multiplier port
                                      number of the next ATA device present on an ATA controller.
@@ -705,7 +708,7 @@ AtaPassThruBuildDevicePath (
 
   The GetDevice() function determines the port and port multiplier port number associated with
   the ATA device described by DevicePath. If DevicePath is a device path node type that the
-  ATA Pass Thru driver supports, then the ATA Pass Thru driver will attempt to translate the contents 
+  ATA Pass Thru driver supports, then the ATA Pass Thru driver will attempt to translate the contents
   DevicePath into a port number and port multiplier port number.
 
   If this translation is successful, then that port number and port multiplier port number are returned
@@ -713,11 +716,11 @@ AtaPassThruBuildDevicePath (
 
   If DevicePath, Port, or PortMultiplierPort are NULL, then EFI_INVALID_PARAMETER is returned.
 
-  If DevicePath is not a device path node type that the ATA Pass Thru driver supports, then 
+  If DevicePath is not a device path node type that the ATA Pass Thru driver supports, then
   EFI_UNSUPPORTED is returned.
 
-  If DevicePath is a device path node type that the ATA Pass Thru driver supports, but there is not 
-  a valid translation from DevicePath to a port number and port multiplier port number, then 
+  If DevicePath is a device path node type that the ATA Pass Thru driver supports, but there is not
+  a valid translation from DevicePath to a port number and port multiplier port number, then
   EFI_NOT_FOUND is returned.
 
   @param[in]  This                A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
@@ -784,7 +787,7 @@ AtaPassThruResetPort (
   If this ATA controller does not support a device reset operation, then EFI_UNSUPPORTED is
   returned.
 
-  If Port or PortMultiplierPort are not in a valid range for this ATA controller, then 
+  If Port or PortMultiplierPort are not in a valid range for this ATA controller, then
   EFI_INVALID_PARAMETER is returned.
 
   If a device error occurs while executing that device reset operation, then EFI_DEVICE_ERROR
@@ -817,9 +820,9 @@ AtaPassThruResetDevice (
   );
 
 /**
-  Sends a SCSI Request Packet to a SCSI device that is attached to the SCSI channel. This function   
+  Sends a SCSI Request Packet to a SCSI device that is attached to the SCSI channel. This function
   supports both blocking I/O and nonblocking I/O. The blocking I/O functionality is required, and the
-  nonblocking I/O functionality is optional.                                                             
+  nonblocking I/O functionality is optional.
 
   @param  This    A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
   @param  Target  The Target is an array of size TARGET_MAX_BYTES and it represents
@@ -868,10 +871,10 @@ ExtScsiPassThruPassThru (
   );
 
 /**
-  Used to retrieve the list of legal Target IDs and LUNs for SCSI devices on a SCSI channel. These       
+  Used to retrieve the list of legal Target IDs and LUNs for SCSI devices on a SCSI channel. These
   can either be the list SCSI devices that are actually present on the SCSI channel, or the list of legal
-  Target Ids and LUNs for the SCSI channel. Regardless, the caller of this function must probe the       
-  Target ID and LUN returned to see if a SCSI device is actually present at that location on the SCSI    
+  Target Ids and LUNs for the SCSI channel. Regardless, the caller of this function must probe the
+  Target ID and LUN returned to see if a SCSI device is actually present at that location on the SCSI
   channel.
 
   @param  This   A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
@@ -1007,13 +1010,13 @@ ExtScsiPassThruResetTargetLun (
   IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL    *This,
   IN UINT8                              *Target,
   IN UINT64                             Lun
-  );     
+  );
 
 /**
-  Used to retrieve the list of legal Target IDs for SCSI devices on a SCSI channel. These can either     
+  Used to retrieve the list of legal Target IDs for SCSI devices on a SCSI channel. These can either
   be the list SCSI devices that are actually present on the SCSI channel, or the list of legal Target IDs
-  for the SCSI channel. Regardless, the caller of this function must probe the Target ID returned to     
-  see if a SCSI device is actually present at that location on the SCSI channel.                         
+  for the SCSI channel. Regardless, the caller of this function must probe the Target ID returned to
+  see if a SCSI device is actually present at that location on the SCSI channel.
 
   @param  This   A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
   @param  Target (TARGET_MAX_BYTES) of a SCSI device present on the SCSI channel.
@@ -1040,9 +1043,9 @@ ExtScsiPassThruGetNextTarget (
 
 /**
   Initialize ATA host controller at IDE mode.
-  
-  The function is designed to initialize ATA host controller. 
-  
+
+  The function is designed to initialize ATA host controller.
+
   @param[in]  Instance          A pointer to the ATA_ATAPI_PASS_THRU_INSTANCE instance.
 
 **/
@@ -1054,9 +1057,9 @@ IdeModeInitialization (
 
 /**
   Initialize ATA host controller at AHCI mode.
-  
-  The function is designed to initialize ATA host controller. 
-  
+
+  The function is designed to initialize ATA host controller.
+
   @param[in]  Instance          A pointer to the ATA_ATAPI_PASS_THRU_INSTANCE instance.
 
 **/
@@ -1068,7 +1071,7 @@ AhciModeInitialization (
 
 /**
   Start a non data transfer on specific port.
-    
+
   @param[in]       PciIo               The PCI IO protocol instance.
   @param[in]       AhciRegisters       The pointer to the EFI_AHCI_REGISTERS.
   @param[in]       Port                The number of port.
@@ -1099,7 +1102,7 @@ AhciNonDataTransfer (
   IN     UINT8                         AtapiCommandLength,
   IN     EFI_ATA_COMMAND_BLOCK         *AtaCommandBlock,
   IN OUT EFI_ATA_STATUS_BLOCK          *AtaStatusBlock,
-  IN     UINT64                        Timeout, 
+  IN     UINT64                        Timeout,
   IN     ATA_NONBLOCK_TASK             *Task
   );
 
@@ -1131,24 +1134,24 @@ AhciNonDataTransfer (
 EFI_STATUS
 EFIAPI
 AhciDmaTransfer (
-  IN     ATA_ATAPI_PASS_THRU_INSTANCE *Instance, 
+  IN     ATA_ATAPI_PASS_THRU_INSTANCE *Instance,
   IN     EFI_AHCI_REGISTERS           *AhciRegisters,
   IN     UINT8                        Port,
   IN     UINT8                        PortMultiplier,
   IN     EFI_AHCI_ATAPI_COMMAND       *AtapiCommand OPTIONAL,
   IN     UINT8                        AtapiCommandLength,
-  IN     BOOLEAN                      Read,  
+  IN     BOOLEAN                      Read,
   IN     EFI_ATA_COMMAND_BLOCK        *AtaCommandBlock,
   IN OUT EFI_ATA_STATUS_BLOCK         *AtaStatusBlock,
   IN OUT VOID                         *MemoryAddr,
   IN     UINT32                       DataCount,
-  IN     UINT64                       Timeout, 
+  IN     UINT64                       Timeout,
   IN     ATA_NONBLOCK_TASK            *Task
   );
 
 /**
   Start a PIO data transfer on specific port.
-    
+
   @param[in]       PciIo               The PCI IO protocol instance.
   @param[in]       AhciRegisters       The pointer to the EFI_AHCI_REGISTERS.
   @param[in]       Port                The number of port.
@@ -1179,13 +1182,13 @@ AhciPioTransfer (
   IN     UINT8                      Port,
   IN     UINT8                      PortMultiplier,
   IN     EFI_AHCI_ATAPI_COMMAND     *AtapiCommand OPTIONAL,
-  IN     UINT8                      AtapiCommandLength,  
-  IN     BOOLEAN                    Read,  
+  IN     UINT8                      AtapiCommandLength,
+  IN     BOOLEAN                    Read,
   IN     EFI_ATA_COMMAND_BLOCK      *AtaCommandBlock,
   IN OUT EFI_ATA_STATUS_BLOCK       *AtaStatusBlock,
   IN OUT VOID                       *MemoryAddr,
   IN     UINT32                     DataCount,
-  IN     UINT64                     Timeout, 
+  IN     UINT64                     Timeout,
   IN     ATA_NONBLOCK_TASK          *Task
   );
 
@@ -1273,7 +1276,7 @@ AtaUdmaInOut (
   @param[in]      Timeout          The time to complete the command, uses 100ns as a unit.
   @param[in]      Task             Optional. Pointer to the ATA_NONBLOCK_TASK
                                    used by non-blocking mode.
-  
+
   @retval EFI_SUCCESS      send out the ATA command and device send required data successfully.
   @retval EFI_DEVICE_ERROR command sent failed.
 
@@ -1288,7 +1291,7 @@ AtaPioDataInOut (
   IN     BOOLEAN                   Read,
   IN     EFI_ATA_COMMAND_BLOCK     *AtaCommandBlock,
   IN OUT EFI_ATA_STATUS_BLOCK      *AtaStatusBlock,
-  IN     UINT64                    Timeout, 
+  IN     UINT64                    Timeout,
   IN     ATA_NONBLOCK_TASK         *Task
   );
 
index 066ce9e28600e6300b9e07c5f2faf402c5370721..8fa0b3f626cea7b3b7786d45f878743235ba0624 100644 (file)
@@ -1,10 +1,10 @@
 /** @file\r
   This file implements protocol interfaces for ATA bus driver.\r
-  \r
+\r
   This file implements protocol interfaces: Driver Binding protocol,\r
   Block IO protocol and DiskInfo protocol.\r
-    \r
-  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+\r
+  Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -58,7 +58,7 @@ ATA_DEVICE gAtaDeviceTemplate = {
     FALSE,                     // LogicPartition\r
     FALSE,                     // ReadOnly\r
     FALSE,                     // WritingCache\r
-    0x200,                     // BlockSize \r
+    0x200,                     // BlockSize\r
     0,                         // IoAlign\r
     0,                         // LastBlock\r
     0,                         // LowestAlignedLba\r
@@ -87,7 +87,8 @@ ATA_DEVICE gAtaDeviceTemplate = {
   NULL,                        // IdentifyData\r
   NULL,                        // ControllerNameTable\r
   {L'\0', },                   // ModelName\r
-  {NULL, NULL}                 // AtaTaskList\r
+  {NULL, NULL},                // AtaTaskList\r
+  {NULL, NULL}                 // AtaSubTaskList\r
 };\r
 \r
 /**\r
@@ -147,10 +148,11 @@ ReleaseAtaResources (
   IN ATA_DEVICE  *AtaDevice\r
   )\r
 {\r
-  ATA_BUS_ASYN_TASK *Task;\r
-  LIST_ENTRY        *Entry;\r
-  LIST_ENTRY        *DelEntry;\r
-  EFI_TPL           OldTpl;\r
+  ATA_BUS_ASYN_SUB_TASK *SubTask;\r
+  ATA_BUS_ASYN_TASK     *AtaTask;\r
+  LIST_ENTRY            *Entry;\r
+  LIST_ENTRY            *DelEntry;\r
+  EFI_TPL               OldTpl;\r
 \r
   FreeUnicodeStringTable (AtaDevice->ControllerNameTable);\r
   FreeAlignedBuffer (AtaDevice->Asb, sizeof (EFI_ATA_STATUS_BLOCK));\r
@@ -159,19 +161,34 @@ ReleaseAtaResources (
     FreePool (AtaDevice->DevicePath);\r
   }\r
   OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
+  if (!IsListEmpty (&AtaDevice->AtaSubTaskList)) {\r
+    //\r
+    // Free the Subtask list.\r
+    //\r
+    for(Entry = AtaDevice->AtaSubTaskList.ForwardLink;\r
+        Entry != (&AtaDevice->AtaSubTaskList);\r
+       ) {\r
+      DelEntry = Entry;\r
+      Entry    = Entry->ForwardLink;\r
+      SubTask  = ATA_AYNS_SUB_TASK_FROM_ENTRY (DelEntry);\r
+\r
+      RemoveEntryList (DelEntry);\r
+      FreeAtaSubTask (SubTask);\r
+    }\r
+  }\r
   if (!IsListEmpty (&AtaDevice->AtaTaskList)) {\r
     //\r
     // Free the Subtask list.\r
     //\r
-    for(Entry = AtaDevice->AtaTaskList.ForwardLink; \r
+    for(Entry = AtaDevice->AtaTaskList.ForwardLink;\r
         Entry != (&AtaDevice->AtaTaskList);\r
        ) {\r
       DelEntry = Entry;\r
       Entry    = Entry->ForwardLink;\r
-      Task     = ATA_AYNS_TASK_FROM_ENTRY (DelEntry);\r
-      \r
+      AtaTask     = ATA_AYNS_TASK_FROM_ENTRY (DelEntry);\r
+\r
       RemoveEntryList (DelEntry);\r
-      FreeAtaSubTask (Task);\r
+      FreePool (AtaTask);\r
     }\r
   }\r
   gBS->RestoreTPL (OldTpl);\r
@@ -183,7 +200,7 @@ ReleaseAtaResources (
   Registers an ATA device.\r
 \r
   This function allocates an ATA device structure for the ATA device specified by\r
-  Port and PortMultiplierPort if the ATA device is identified as a valid one. \r
+  Port and PortMultiplierPort if the ATA device is identified as a valid one.\r
   Then it will create child handle and install Block IO and Disk Info protocol on\r
   it.\r
 \r
@@ -217,7 +234,7 @@ RegisterAtaDevice (
   RemainingDevicePath = NULL;\r
 \r
   //\r
-  // Build device path \r
+  // Build device path\r
   //\r
   AtaPassThru = AtaBusDriverData->AtaPassThru;\r
   Status = AtaPassThru->BuildDevicePath (AtaPassThru, Port, PortMultiplierPort, &NewDevicePathNode);\r
@@ -273,9 +290,10 @@ RegisterAtaDevice (
   // Initial Ata Task List\r
   //\r
   InitializeListHead (&AtaDevice->AtaTaskList);\r
+  InitializeListHead (&AtaDevice->AtaSubTaskList);\r
 \r
   //\r
-  // Try to identify the ATA device via the ATA pass through command. \r
+  // Try to identify the ATA device via the ATA pass through command.\r
   //\r
   Status = DiscoverAtaDevice (AtaDevice);\r
   if (EFI_ERROR (Status)) {\r
@@ -363,7 +381,7 @@ Done:
   }\r
 \r
   if (EFI_ERROR (Status) && (AtaDevice != NULL)) {\r
-    ReleaseAtaResources (AtaDevice);  \r
+    ReleaseAtaResources (AtaDevice);\r
     DEBUG ((EFI_D_ERROR | EFI_D_INIT, "Failed to initialize Port %x PortMultiplierPort %x, status = %r\n", Port, PortMultiplierPort, Status));\r
   }\r
   return Status;\r
@@ -373,8 +391,8 @@ Done:
 /**\r
   Unregisters an ATA device.\r
 \r
-  This function removes the protocols installed on the controller handle and \r
-  frees the resources allocated for the ATA device. \r
+  This function removes the protocols installed on the controller handle and\r
+  frees the resources allocated for the ATA device.\r
 \r
   @param  This                  The pointer to EFI_DRIVER_BINDING_PROTOCOL instance.\r
   @param  Controller            The controller handle of the ATA device.\r
@@ -433,7 +451,7 @@ UnregisterAtaDevice (
     AtaDevice = ATA_DEVICE_FROM_BLOCK_IO (BlockIo);\r
   } else {\r
     AtaDevice = ATA_DEVICE_FROM_BLOCK_IO2 (BlockIo2);\r
-  } \r
+  }\r
 \r
   //\r
   // Close the child handle\r
@@ -512,33 +530,33 @@ UnregisterAtaDevice (
 \r
 \r
 /**\r
-  Tests to see if this driver supports a given controller. If a child device is provided, \r
+  Tests to see if this driver supports a given controller. If a child device is provided,\r
   it further tests to see if this driver supports creating a handle for the specified child device.\r
 \r
-  This function checks to see if the driver specified by This supports the device specified by \r
-  ControllerHandle. Drivers will typically use the device path attached to \r
-  ControllerHandle and/or the services from the bus I/O abstraction attached to \r
-  ControllerHandle to determine if the driver supports ControllerHandle. This function \r
-  may be called many times during platform initialization. In order to reduce boot times, the tests \r
-  performed by this function must be very small, and take as little time as possible to execute. This \r
-  function must not change the state of any hardware devices, and this function must be aware that the \r
-  device specified by ControllerHandle may already be managed by the same driver or a \r
-  different driver. This function must match its calls to AllocatePages() with FreePages(), \r
-  AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().  \r
-  Since ControllerHandle may have been previously started by the same driver, if a protocol is \r
-  already in the opened state, then it must not be closed with CloseProtocol(). This is required \r
+  This function checks to see if the driver specified by This supports the device specified by\r
+  ControllerHandle. Drivers will typically use the device path attached to\r
+  ControllerHandle and/or the services from the bus I/O abstraction attached to\r
+  ControllerHandle to determine if the driver supports ControllerHandle. This function\r
+  may be called many times during platform initialization. In order to reduce boot times, the tests\r
+  performed by this function must be very small, and take as little time as possible to execute. This\r
+  function must not change the state of any hardware devices, and this function must be aware that the\r
+  device specified by ControllerHandle may already be managed by the same driver or a\r
+  different driver. This function must match its calls to AllocatePages() with FreePages(),\r
+  AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().\r
+  Since ControllerHandle may have been previously started by the same driver, if a protocol is\r
+  already in the opened state, then it must not be closed with CloseProtocol(). This is required\r
   to guarantee the state of ControllerHandle is not modified by this function.\r
 \r
   @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
-  @param[in]  ControllerHandle     The handle of the controller to test. This handle \r
-                                   must support a protocol interface that supplies \r
+  @param[in]  ControllerHandle     The handle of the controller to test. This handle\r
+                                   must support a protocol interface that supplies\r
                                    an I/O abstraction to the driver.\r
-  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This \r
-                                   parameter is ignored by device drivers, and is optional for bus \r
-                                   drivers. For bus drivers, if this parameter is not NULL, then \r
-                                   the bus driver must determine if the bus controller specified \r
-                                   by ControllerHandle and the child controller specified \r
-                                   by RemainingDevicePath are both supported by this \r
+  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This\r
+                                   parameter is ignored by device drivers, and is optional for bus\r
+                                   drivers. For bus drivers, if this parameter is not NULL, then\r
+                                   the bus driver must determine if the bus controller specified\r
+                                   by ControllerHandle and the child controller specified\r
+                                   by RemainingDevicePath are both supported by this\r
                                    bus driver.\r
 \r
   @retval EFI_SUCCESS              The device specified by ControllerHandle and\r
@@ -626,28 +644,28 @@ AtaBusDriverBindingSupported (
   Starts a device controller or a bus controller.\r
 \r
   The Start() function is designed to be invoked from the EFI boot service ConnectController().\r
-  As a result, much of the error checking on the parameters to Start() has been moved into this \r
-  common boot service. It is legal to call Start() from other locations, \r
+  As a result, much of the error checking on the parameters to Start() has been moved into this\r
+  common boot service. It is legal to call Start() from other locations,\r
   but the following calling restrictions must be followed or the system behavior will not be deterministic.\r
   1. ControllerHandle must be a valid EFI_HANDLE.\r
   2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
      EFI_DEVICE_PATH_PROTOCOL.\r
   3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
-     have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.  \r
+     have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r
 \r
   @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
-  @param[in]  ControllerHandle     The handle of the controller to start. This handle \r
-                                   must support a protocol interface that supplies \r
+  @param[in]  ControllerHandle     The handle of the controller to start. This handle\r
+                                   must support a protocol interface that supplies\r
                                    an I/O abstraction to the driver.\r
-  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This \r
-                                   parameter is ignored by device drivers, and is optional for bus \r
-                                   drivers. For a bus driver, if this parameter is NULL, then handles \r
+  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This\r
+                                   parameter is ignored by device drivers, and is optional for bus\r
+                                   drivers. For a bus driver, if this parameter is NULL, then handles\r
                                    for all the children of Controller are created by this driver.\r
-                                   If this parameter is not NULL and the first Device Path Node is \r
-                                   not the End of Device Path Node, then only the handle for the \r
-                                   child device specified by the first Device Path Node of \r
+                                   If this parameter is not NULL and the first Device Path Node is\r
+                                   not the End of Device Path Node, then only the handle for the\r
+                                   child device specified by the first Device Path Node of\r
                                    RemainingDevicePath is created by this driver.\r
-                                   If the first Device Path Node of RemainingDevicePath is \r
+                                   If the first Device Path Node of RemainingDevicePath is\r
                                    the End of Device Path Node, no child handle is created by this\r
                                    driver.\r
 \r
@@ -798,10 +816,10 @@ ErrorExit:
 \r
 /**\r
   Stops a device controller or a bus controller.\r
-  \r
-  The Stop() function is designed to be invoked from the EFI boot service DisconnectController(). \r
-  As a result, much of the error checking on the parameters to Stop() has been moved \r
-  into this common boot service. It is legal to call Stop() from other locations, \r
+\r
+  The Stop() function is designed to be invoked from the EFI boot service DisconnectController().\r
+  As a result, much of the error checking on the parameters to Stop() has been moved\r
+  into this common boot service. It is legal to call Stop() from other locations,\r
   but the following calling restrictions must be followed or the system behavior will not be deterministic.\r
   1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
      same driver's Start() function.\r
@@ -809,13 +827,13 @@ ErrorExit:
      EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
      Start() function, and the Start() function must have called OpenProtocol() on\r
      ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
-  \r
+\r
   @param[in]  This              A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
-  @param[in]  ControllerHandle  A handle to the device being stopped. The handle must \r
-                                support a bus specific I/O protocol for the driver \r
+  @param[in]  ControllerHandle  A handle to the device being stopped. The handle must\r
+                                support a bus specific I/O protocol for the driver\r
                                 to use to stop the device.\r
   @param[in]  NumberOfChildren  The number of child device handles in ChildHandleBuffer.\r
-  @param[in]  ChildHandleBuffer An array of child handles to be freed. May be NULL \r
+  @param[in]  ChildHandleBuffer An array of child handles to be freed. May be NULL\r
                                 if NumberOfChildren is 0.\r
 \r
   @retval EFI_SUCCESS           The device was stopped.\r
@@ -924,7 +942,7 @@ AtaBlockIoReset (
   Read/Write BufferSize bytes from Lba from/into Buffer.\r
 \r
   @param[in]       This       Indicates a pointer to the calling context. Either be\r
-                              block I/O or block I/O2. \r
+                              block I/O or block I/O2.\r
   @param[in]       MediaId    The media ID that the read/write request is for.\r
   @param[in]       Lba        The starting logical block address to be read/written.\r
                               The caller is responsible for reading/writing to only\r
@@ -942,7 +960,7 @@ AtaBlockIoReset (
   @retval EFI_NO_MEDIA          There is no media in the device.\r
   @retval EFI_MEDIA_CHNAGED     The MediaId does not matched the current device.\r
   @retval EFI_BAD_BUFFER_SIZE   The Buffer was not a multiple of the block size of the device.\r
-  @retval EFI_INVALID_PARAMETER The read/write request contains LBAs that are not valid, \r
+  @retval EFI_INVALID_PARAMETER The read/write request contains LBAs that are not valid,\r
                                 or the buffer is not on proper alignment.\r
 \r
 **/\r
@@ -987,13 +1005,13 @@ BlockIoReadWrite (
 \r
   if (BufferSize == 0) {\r
     return EFI_SUCCESS;\r
-  }  \r
+  }\r
 \r
   BlockSize = Media->BlockSize;\r
   if ((BufferSize % BlockSize) != 0) {\r
     return EFI_BAD_BUFFER_SIZE;\r
   }\r
-  \r
+\r
   NumberOfBlocks  = BufferSize / BlockSize;\r
   if ((Lba + NumberOfBlocks - 1) > Media->LastBlock) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -1005,12 +1023,12 @@ BlockIoReadWrite (
   }\r
 \r
   OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
-  \r
+\r
   //\r
   // Invoke low level AtaDevice Access Routine.\r
   //\r
   Status = AccessAtaDevice (AtaDevice, Buffer, Lba, NumberOfBlocks, IsWrite, Token);\r
\r
+\r
   gBS->RestoreTPL (OldTpl);\r
 \r
   return Status;\r
@@ -1032,7 +1050,7 @@ BlockIoReadWrite (
   @retval EFI_NO_MEDIA          There is no media in the device.\r
   @retval EFI_MEDIA_CHANGED     The MediaId does not matched the current device.\r
   @retval EFI_BAD_BUFFER_SIZE   The Buffer was not a multiple of the block size of the device.\r
-  @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid, \r
+  @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,\r
                                 or the buffer is not on proper alignment.\r
 \r
 **/\r
@@ -1066,7 +1084,7 @@ AtaBlockIoReadBlocks (
   @retval EFI_NO_MEDIA          There is no media in the device.\r
   @retval EFI_MEDIA_CHNAGED     The MediaId does not matched the current device.\r
   @retval EFI_BAD_BUFFER_SIZE   The Buffer was not a multiple of the block size of the device.\r
-  @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid, \r
+  @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,\r
                                 or the buffer is not on proper alignment.\r
 \r
 **/\r
@@ -1162,7 +1180,7 @@ AtaBlockIoResetEx (
   @retval EFI_MEDIA_CHANGED     The MediaId is not for the current media.\r
   @retval EFI_BAD_BUFFER_SIZE   The BufferSize parameter is not a multiple of the\r
                                 intrinsic block size of the device.\r
-  @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid, \r
+  @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,\r
                                 or the buffer is not on proper alignment.\r
   @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack\r
                                 of resources.\r
@@ -1201,7 +1219,7 @@ AtaBlockIoReadBlocksEx (
   @retval EFI_NO_MEDIA          There is no media in the device.\r
   @retval EFI_MEDIA_CHNAGED     The MediaId does not matched the current device.\r
   @retval EFI_BAD_BUFFER_SIZE   The Buffer was not a multiple of the block size of the device.\r
-  @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid, \r
+  @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,\r
                                 or the buffer is not on proper alignment.\r
 \r
 **/\r
@@ -1249,7 +1267,7 @@ AtaBlockIoFlushBlocksEx (
 }\r
 /**\r
   Provides inquiry information for the controller type.\r
-  \r
+\r
   This function is used by the IDE bus driver to get inquiry data.  Data format\r
   of Identify data is defined by the Interface GUID.\r
 \r
@@ -1258,9 +1276,9 @@ AtaBlockIoFlushBlocksEx (
   @param[in, out] InquiryDataSize  Pointer to the value for the inquiry data size.\r
 \r
   @retval EFI_SUCCESS            The command was accepted without any errors.\r
-  @retval EFI_NOT_FOUND          Device does not support this data class \r
-  @retval EFI_DEVICE_ERROR       Error reading InquiryData from device \r
-  @retval EFI_BUFFER_TOO_SMALL   InquiryDataSize not big enough \r
+  @retval EFI_NOT_FOUND          Device does not support this data class\r
+  @retval EFI_DEVICE_ERROR       Error reading InquiryData from device\r
+  @retval EFI_BUFFER_TOO_SMALL   InquiryDataSize not big enough\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1281,16 +1299,16 @@ AtaDiskInfoInquiry (
   This function is used by the IDE bus driver to get identify data.  Data format\r
   of Identify data is defined by the Interface GUID.\r
 \r
-  @param[in]      This              Pointer to the EFI_DISK_INFO_PROTOCOL \r
+  @param[in]      This              Pointer to the EFI_DISK_INFO_PROTOCOL\r
                                     instance.\r
   @param[in, out] IdentifyData      Pointer to a buffer for the identify data.\r
   @param[in, out] IdentifyDataSize  Pointer to the value for the identify data\r
                                     size.\r
 \r
   @retval EFI_SUCCESS            The command was accepted without any errors.\r
-  @retval EFI_NOT_FOUND          Device does not support this data class \r
-  @retval EFI_DEVICE_ERROR       Error reading IdentifyData from device \r
-  @retval EFI_BUFFER_TOO_SMALL   IdentifyDataSize not big enough \r
+  @retval EFI_NOT_FOUND          Device does not support this data class\r
+  @retval EFI_DEVICE_ERROR       Error reading IdentifyData from device\r
+  @retval EFI_BUFFER_TOO_SMALL   IdentifyDataSize not big enough\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1319,8 +1337,8 @@ AtaDiskInfoIdentify (
 \r
 /**\r
   Provides sense data information for the controller type.\r
-  \r
-  This function is used by the IDE bus driver to get sense data. \r
+\r
+  This function is used by the IDE bus driver to get sense data.\r
   Data format of Sense data is defined by the Interface GUID.\r
 \r
   @param[in]      This             Pointer to the EFI_DISK_INFO_PROTOCOL instance.\r
@@ -1350,7 +1368,7 @@ AtaDiskInfoSenseData (
 /**\r
   This function is used by the IDE bus driver to get controller information.\r
 \r
-  @param[in]  This         Pointer to the EFI_DISK_INFO_PROTOCOL instance. \r
+  @param[in]  This         Pointer to the EFI_DISK_INFO_PROTOCOL instance.\r
   @param[out] IdeChannel   Pointer to the Ide Channel number.  Primary or secondary.\r
   @param[out] IdeDevice    Pointer to the Ide Device number.  Master or slave.\r
 \r
index 6a4b2576b2d57720550d477644025dc170de77e7..b64a3d39281efa1c2efe76a90a0886c60bd7dbdc 100644 (file)
@@ -4,7 +4,7 @@
   This file defines common data structures, macro definitions and some module\r
   internal function header files.\r
 \r
-  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -35,6 +35,7 @@
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
 #include <Library/DevicePathLib.h>\r
+#include <Library/TimerLib.h>\r
 \r
 #include <IndustryStandard/Atapi.h>\r
 \r
 #define MAX_28BIT_ADDRESSING_CAPACITY     0xfffffff\r
 \r
 //\r
-// The maximum ATA transaction sector count in 28 bit addressing mode. \r
+// The maximum ATA transaction sector count in 28 bit addressing mode.\r
 //\r
 #define MAX_28BIT_TRANSFER_BLOCK_NUM      0x100\r
 \r
 //\r
-// The maximum ATA transaction sector count in 48 bit addressing mode. \r
+// The maximum ATA transaction sector count in 48 bit addressing mode.\r
 //\r
 //#define MAX_48BIT_TRANSFER_BLOCK_NUM      0x10000\r
 \r
 #define MAX_48BIT_TRANSFER_BLOCK_NUM      0xFFFF\r
 \r
 //\r
-// The maximum model name in ATA identify data  \r
+// The maximum model name in ATA identify data\r
 //\r
 #define MAX_MODEL_NAME_LEN                40\r
 \r
 #define ATA_TASK_SIGNATURE                SIGNATURE_32 ('A', 'T', 'S', 'K')\r
 #define ATA_DEVICE_SIGNATURE              SIGNATURE_32 ('A', 'B', 'I', 'D')\r
-\r
+#define ATA_SUB_TASK_SIGNATURE            SIGNATURE_32 ('A', 'S', 'T', 'S')\r
 #define IS_ALIGNED(addr, size)            (((UINTN) (addr) & (size - 1)) == 0)\r
 \r
-//\r
-// Task for the non blocking I/O\r
-//\r
-typedef struct {\r
-  UINT32                            Signature;\r
-  EFI_BLOCK_IO2_TOKEN               *Token;\r
-  UINTN                             *UnsignalledEventCount;\r
-  EFI_ATA_PASS_THRU_COMMAND_PACKET  Packet;\r
-  BOOLEAN                           *IsError;// Indicate whether meeting error during source allocation for new task.\r
-  LIST_ENTRY                        TaskEntry;\r
-} ATA_BUS_ASYN_TASK;\r
-\r
 //\r
 // ATA bus data structure for ATA controller\r
 //\r
@@ -140,12 +129,41 @@ typedef struct {
   CHAR16                                ModelName[MAX_MODEL_NAME_LEN + 1];\r
 \r
   LIST_ENTRY                            AtaTaskList;\r
+  LIST_ENTRY                            AtaSubTaskList;\r
 } ATA_DEVICE;\r
 \r
+//\r
+// Sub-Task for the non blocking I/O\r
+//\r
+typedef struct {\r
+  UINT32                            Signature;\r
+  ATA_DEVICE                        *AtaDevice;\r
+  EFI_BLOCK_IO2_TOKEN               *Token;\r
+  UINTN                             *UnsignalledEventCount;\r
+  EFI_ATA_PASS_THRU_COMMAND_PACKET  Packet;\r
+  BOOLEAN                           *IsError;// Indicate whether meeting error during source allocation for new task.\r
+  LIST_ENTRY                        TaskEntry;\r
+} ATA_BUS_ASYN_SUB_TASK;\r
+\r
+//\r
+// Task for the non blocking I/O\r
+//\r
+typedef struct {\r
+  UINT32                            Signature;\r
+  EFI_BLOCK_IO2_TOKEN               *Token;\r
+  ATA_DEVICE                        *AtaDevice;\r
+  UINT8                             *Buffer;\r
+  EFI_LBA                           StartLba;\r
+  UINTN                             NumberOfBlocks;\r
+  BOOLEAN                           IsWrite;\r
+  LIST_ENTRY                        TaskEntry;\r
+} ATA_BUS_ASYN_TASK;\r
+\r
 #define ATA_DEVICE_FROM_BLOCK_IO(a)         CR (a, ATA_DEVICE, BlockIo, ATA_DEVICE_SIGNATURE)\r
 #define ATA_DEVICE_FROM_BLOCK_IO2(a)        CR (a, ATA_DEVICE, BlockIo2, ATA_DEVICE_SIGNATURE)\r
 #define ATA_DEVICE_FROM_DISK_INFO(a)        CR (a, ATA_DEVICE, DiskInfo, ATA_DEVICE_SIGNATURE)\r
 #define ATA_DEVICE_FROM_STORAGE_SECURITY(a) CR (a, ATA_DEVICE, StorageSecurity, ATA_DEVICE_SIGNATURE)\r
+#define ATA_AYNS_SUB_TASK_FROM_ENTRY(a)     CR (a, ATA_BUS_ASYN_SUB_TASK, TaskEntry, ATA_SUB_TASK_SIGNATURE)\r
 #define ATA_AYNS_TASK_FROM_ENTRY(a)         CR (a, ATA_BUS_ASYN_TASK, TaskEntry, ATA_TASK_SIGNATURE)\r
 \r
 //\r
@@ -191,22 +209,22 @@ FreeAlignedBuffer (
   );\r
 \r
 /**\r
-  Free SubTask. \r
+  Free SubTask.\r
 \r
   @param[in, out]  Task      Pointer to task to be freed.\r
\r
+\r
 **/\r
 VOID\r
-EFIAPI \r
+EFIAPI\r
 FreeAtaSubTask (\r
-  IN OUT ATA_BUS_ASYN_TASK  *Task\r
+  IN OUT ATA_BUS_ASYN_SUB_TASK  *Task\r
   );\r
 \r
 /**\r
   Wrapper for EFI_ATA_PASS_THRU_PROTOCOL.ResetDevice().\r
 \r
   This function wraps the ResetDevice() invocation for ATA pass through function\r
-  for an ATA device. \r
+  for an ATA device.\r
 \r
   @param  AtaDevice         The ATA child device involved for the operation.\r
 \r
@@ -230,7 +248,7 @@ ResetAtaDevice (
 \r
   @retval EFI_SUCCESS       The device is successfully identified and Media information\r
                             is correctly initialized.\r
-  @return others            Some error occurs when discovering the ATA device. \r
+  @return others            Some error occurs when discovering the ATA device.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -253,10 +271,10 @@ DiscoverAtaDevice (
   @param[in, out]  Token           A pointer to the token associated with the transaction.\r
 \r
   @retval EFI_SUCCESS       The data transfer is complete successfully.\r
-  @return others            Some error occurs when transferring data. \r
+  @return others            Some error occurs when transferring data.\r
 \r
 **/\r
-EFI_STATUS \r
+EFI_STATUS\r
 AccessAtaDevice(\r
   IN OUT ATA_DEVICE                 *AtaDevice,\r
   IN OUT UINT8                      *Buffer,\r
@@ -291,7 +309,7 @@ AccessAtaDevice(
                                        written to the buffer. Ignore it when IsTrustSend is TRUE.\r
 \r
   @retval EFI_SUCCESS       The data transfer is complete successfully.\r
-  @return others            Some error occurs when transferring data. \r
+  @return others            Some error occurs when transferring data.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -311,33 +329,33 @@ TrustTransferAtaDevice (
 // Protocol interface prototypes\r
 //\r
 /**\r
-  Tests to see if this driver supports a given controller. If a child device is provided, \r
+  Tests to see if this driver supports a given controller. If a child device is provided,\r
   it further tests to see if this driver supports creating a handle for the specified child device.\r
 \r
-  This function checks to see if the driver specified by This supports the device specified by \r
-  ControllerHandle. Drivers will typically use the device path attached to \r
-  ControllerHandle and/or the services from the bus I/O abstraction attached to \r
-  ControllerHandle to determine if the driver supports ControllerHandle. This function \r
-  may be called many times during platform initialization. In order to reduce boot times, the tests \r
-  performed by this function must be very small, and take as little time as possible to execute. This \r
-  function must not change the state of any hardware devices, and this function must be aware that the \r
-  device specified by ControllerHandle may already be managed by the same driver or a \r
-  different driver. This function must match its calls to AllocatePages() with FreePages(), \r
-  AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().  \r
-  Since ControllerHandle may have been previously started by the same driver, if a protocol is \r
-  already in the opened state, then it must not be closed with CloseProtocol(). This is required \r
+  This function checks to see if the driver specified by This supports the device specified by\r
+  ControllerHandle. Drivers will typically use the device path attached to\r
+  ControllerHandle and/or the services from the bus I/O abstraction attached to\r
+  ControllerHandle to determine if the driver supports ControllerHandle. This function\r
+  may be called many times during platform initialization. In order to reduce boot times, the tests\r
+  performed by this function must be very small, and take as little time as possible to execute. This\r
+  function must not change the state of any hardware devices, and this function must be aware that the\r
+  device specified by ControllerHandle may already be managed by the same driver or a\r
+  different driver. This function must match its calls to AllocatePages() with FreePages(),\r
+  AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().\r
+  Since ControllerHandle may have been previously started by the same driver, if a protocol is\r
+  already in the opened state, then it must not be closed with CloseProtocol(). This is required\r
   to guarantee the state of ControllerHandle is not modified by this function.\r
 \r
   @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
-  @param[in]  ControllerHandle     The handle of the controller to test. This handle \r
-                                   must support a protocol interface that supplies \r
+  @param[in]  ControllerHandle     The handle of the controller to test. This handle\r
+                                   must support a protocol interface that supplies\r
                                    an I/O abstraction to the driver.\r
-  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This \r
-                                   parameter is ignored by device drivers, and is optional for bus \r
-                                   drivers. For bus drivers, if this parameter is not NULL, then \r
-                                   the bus driver must determine if the bus controller specified \r
-                                   by ControllerHandle and the child controller specified \r
-                                   by RemainingDevicePath are both supported by this \r
+  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This\r
+                                   parameter is ignored by device drivers, and is optional for bus\r
+                                   drivers. For bus drivers, if this parameter is not NULL, then\r
+                                   the bus driver must determine if the bus controller specified\r
+                                   by ControllerHandle and the child controller specified\r
+                                   by RemainingDevicePath are both supported by this\r
                                    bus driver.\r
 \r
   @retval EFI_SUCCESS              The device specified by ControllerHandle and\r
@@ -364,28 +382,28 @@ AtaBusDriverBindingSupported (
   Starts a device controller or a bus controller.\r
 \r
   The Start() function is designed to be invoked from the EFI boot service ConnectController().\r
-  As a result, much of the error checking on the parameters to Start() has been moved into this \r
-  common boot service. It is legal to call Start() from other locations, \r
+  As a result, much of the error checking on the parameters to Start() has been moved into this\r
+  common boot service. It is legal to call Start() from other locations,\r
   but the following calling restrictions must be followed or the system behavior will not be deterministic.\r
   1. ControllerHandle must be a valid EFI_HANDLE.\r
   2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
      EFI_DEVICE_PATH_PROTOCOL.\r
   3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
-     have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.  \r
+     have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r
 \r
   @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
-  @param[in]  ControllerHandle     The handle of the controller to start. This handle \r
-                                   must support a protocol interface that supplies \r
+  @param[in]  ControllerHandle     The handle of the controller to start. This handle\r
+                                   must support a protocol interface that supplies\r
                                    an I/O abstraction to the driver.\r
-  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This \r
-                                   parameter is ignored by device drivers, and is optional for bus \r
-                                   drivers. For a bus driver, if this parameter is NULL, then handles \r
-                                   for all the children of Controller are created by this driver.  \r
-                                   If this parameter is not NULL and the first Device Path Node is \r
-                                   not the End of Device Path Node, then only the handle for the \r
-                                   child device specified by the first Device Path Node of \r
+  @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This\r
+                                   parameter is ignored by device drivers, and is optional for bus\r
+                                   drivers. For a bus driver, if this parameter is NULL, then handles\r
+                                   for all the children of Controller are created by this driver.\r
+                                   If this parameter is not NULL and the first Device Path Node is\r
+                                   not the End of Device Path Node, then only the handle for the\r
+                                   child device specified by the first Device Path Node of\r
                                    RemainingDevicePath is created by this driver.\r
-                                   If the first Device Path Node of RemainingDevicePath is \r
+                                   If the first Device Path Node of RemainingDevicePath is\r
                                    the End of Device Path Node, no child handle is created by this\r
                                    driver.\r
 \r
@@ -405,10 +423,10 @@ AtaBusDriverBindingStart (
 \r
 /**\r
   Stops a device controller or a bus controller.\r
-  \r
-  The Stop() function is designed to be invoked from the EFI boot service DisconnectController(). \r
-  As a result, much of the error checking on the parameters to Stop() has been moved \r
-  into this common boot service. It is legal to call Stop() from other locations, \r
+\r
+  The Stop() function is designed to be invoked from the EFI boot service DisconnectController().\r
+  As a result, much of the error checking on the parameters to Stop() has been moved\r
+  into this common boot service. It is legal to call Stop() from other locations,\r
   but the following calling restrictions must be followed or the system behavior will not be deterministic.\r
   1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
      same driver's Start() function.\r
@@ -416,13 +434,13 @@ AtaBusDriverBindingStart (
      EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
      Start() function, and the Start() function must have called OpenProtocol() on\r
      ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
-  \r
+\r
   @param[in]  This              A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
-  @param[in]  ControllerHandle  A handle to the device being stopped. The handle must \r
-                                support a bus specific I/O protocol for the driver \r
+  @param[in]  ControllerHandle  A handle to the device being stopped. The handle must\r
+                                support a bus specific I/O protocol for the driver\r
                                 to use to stop the device.\r
   @param[in]  NumberOfChildren  The number of child device handles in ChildHandleBuffer.\r
-  @param[in]  ChildHandleBuffer An array of child handles to be freed. May be NULL \r
+  @param[in]  ChildHandleBuffer An array of child handles to be freed. May be NULL\r
                                 if NumberOfChildren is 0.\r
 \r
   @retval EFI_SUCCESS           The device was stopped.\r
@@ -600,7 +618,7 @@ AtaBlockIoReset (
   @retval EFI_NO_MEDIA          There is no media in the device.\r
   @retval EFI_MEDIA_CHANGED     The MediaId does not matched the current device.\r
   @retval EFI_BAD_BUFFER_SIZE   The Buffer was not a multiple of the block size of the device.\r
-  @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid, \r
+  @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,\r
                                 or the buffer is not on proper alignment.\r
 \r
 **/\r
@@ -631,7 +649,7 @@ AtaBlockIoReadBlocks (
   @retval EFI_NO_MEDIA          There is no media in the device.\r
   @retval EFI_MEDIA_CHNAGED     The MediaId does not matched the current device.\r
   @retval EFI_BAD_BUFFER_SIZE   The Buffer was not a multiple of the block size of the device.\r
-  @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid, \r
+  @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,\r
                                 or the buffer is not on proper alignment.\r
 \r
 **/\r
@@ -700,7 +718,7 @@ AtaBlockIoResetEx (
   @retval EFI_MEDIA_CHANGED     The MediaId is not for the current media.\r
   @retval EFI_BAD_BUFFER_SIZE   The BufferSize parameter is not a multiple of the\r
                                 intrinsic block size of the device.\r
-  @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid, \r
+  @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,\r
                                 or the buffer is not on proper alignment.\r
   @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack\r
                                 of resources.\r
@@ -735,7 +753,7 @@ AtaBlockIoReadBlocksEx (
   @retval EFI_NO_MEDIA          There is no media in the device.\r
   @retval EFI_MEDIA_CHNAGED     The MediaId does not matched the current device.\r
   @retval EFI_BAD_BUFFER_SIZE   The Buffer was not a multiple of the block size of the device.\r
-  @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid, \r
+  @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,\r
                                 or the buffer is not on proper alignment.\r
 \r
 **/\r
@@ -770,7 +788,7 @@ AtaBlockIoFlushBlocksEx (
 \r
 /**\r
   Provides inquiry information for the controller type.\r
-  \r
+\r
   This function is used by the IDE bus driver to get inquiry data.  Data format\r
   of Identify data is defined by the Interface GUID.\r
 \r
@@ -779,9 +797,9 @@ AtaBlockIoFlushBlocksEx (
   @param[in, out] InquiryDataSize  Pointer to the value for the inquiry data size.\r
 \r
   @retval EFI_SUCCESS            The command was accepted without any errors.\r
-  @retval EFI_NOT_FOUND          Device does not support this data class \r
-  @retval EFI_DEVICE_ERROR       Error reading InquiryData from device \r
-  @retval EFI_BUFFER_TOO_SMALL   InquiryDataSize not big enough \r
+  @retval EFI_NOT_FOUND          Device does not support this data class\r
+  @retval EFI_DEVICE_ERROR       Error reading InquiryData from device\r
+  @retval EFI_BUFFER_TOO_SMALL   InquiryDataSize not big enough\r
 \r
 **/\r
 EFI_STATUS\r
@@ -799,16 +817,16 @@ AtaDiskInfoInquiry (
   This function is used by the IDE bus driver to get identify data.  Data format\r
   of Identify data is defined by the Interface GUID.\r
 \r
-  @param[in]      This              Pointer to the EFI_DISK_INFO_PROTOCOL \r
+  @param[in]      This              Pointer to the EFI_DISK_INFO_PROTOCOL\r
                                     instance.\r
   @param[in, out] IdentifyData      Pointer to a buffer for the identify data.\r
   @param[in, out] IdentifyDataSize  Pointer to the value for the identify data\r
                                     size.\r
 \r
   @retval EFI_SUCCESS            The command was accepted without any errors.\r
-  @retval EFI_NOT_FOUND          Device does not support this data class \r
-  @retval EFI_DEVICE_ERROR       Error reading IdentifyData from device \r
-  @retval EFI_BUFFER_TOO_SMALL   IdentifyDataSize not big enough \r
+  @retval EFI_NOT_FOUND          Device does not support this data class\r
+  @retval EFI_DEVICE_ERROR       Error reading IdentifyData from device\r
+  @retval EFI_BUFFER_TOO_SMALL   IdentifyDataSize not big enough\r
 \r
 **/\r
 EFI_STATUS\r
@@ -822,8 +840,8 @@ AtaDiskInfoIdentify (
 \r
 /**\r
   Provides sense data information for the controller type.\r
-  \r
-  This function is used by the IDE bus driver to get sense data. \r
+\r
+  This function is used by the IDE bus driver to get sense data.\r
   Data format of Sense data is defined by the Interface GUID.\r
 \r
   @param[in]      This             Pointer to the EFI_DISK_INFO_PROTOCOL instance.\r
@@ -850,7 +868,7 @@ AtaDiskInfoSenseData (
 /**\r
   This function is used by the IDE bus driver to get controller information.\r
 \r
-  @param[in]  This         Pointer to the EFI_DISK_INFO_PROTOCOL instance. \r
+  @param[in]  This         Pointer to the EFI_DISK_INFO_PROTOCOL instance.\r
   @param[out] IdeChannel   Pointer to the Ide Channel number.  Primary or secondary.\r
   @param[out] IdeDevice    Pointer to the Ide Device number.  Master or slave.\r
 \r
index 6cc75ec6d07123304caceda7ac82503838d88c38..edc6df9e316d00e8dae537690a55239d2a506a89 100644 (file)
@@ -1,5 +1,5 @@
 ## @file\r
-#  ATA Bus driver to enumerate and identfy ATA devices. \r
+#  ATA Bus driver to enumerate and identfy ATA devices.\r
 #\r
 #  This driver follows UEFI driver model and layers on ATA Pass Thru protocol defined\r
 #  in UEFI spec 2.2. It installs Block IO and Disk Info protocol for each ATA device\r
@@ -30,9 +30,9 @@
 #\r
 #  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
 #\r
-#  DRIVER_BINDING                =  gAtaBusDriverBinding                         \r
+#  DRIVER_BINDING                =  gAtaBusDriverBinding\r
 #  COMPONENT_NAME                =  gAtaBusComponentName\r
-#  COMPONENT_NAME2               =  gAtaBusComponentName2                         \r
+#  COMPONENT_NAME2               =  gAtaBusComponentName2\r
 #\r
 #\r
 \r
@@ -41,7 +41,7 @@
   AtaBus.c\r
   AtaPassThruExecute.c\r
   ComponentName.c\r
-  \r
+\r
 [Packages]\r
   MdePkg/MdePkg.dec\r
 \r
@@ -54,7 +54,7 @@
   BaseLib\r
   UefiDriverEntryPoint\r
   DebugLib\r
-\r
+  TimerLib\r
 \r
 [Guids]\r
   gEfiDiskInfoIdeInterfaceGuid                  # CONSUMES  ## GUID\r
index 2177a45bf7f7c61393445ad73b7fd53b8b343a87..0045cc0d91658f84242a4734ec730e8102a5ed21 100644 (file)
@@ -6,11 +6,11 @@
   through command and protocol.\r
 \r
   NOTE: This file also implements the StorageSecurityCommandProtocol(SSP). For input\r
-  parameter SecurityProtocolSpecificData, ATA spec has no explicitly definition \r
-  for Security Protocol Specific layout. This implementation uses big endian for \r
+  parameter SecurityProtocolSpecificData, ATA spec has no explicitly definition\r
+  for Security Protocol Specific layout. This implementation uses big endian for\r
   Cylinder register.\r
-    \r
-  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+\r
+  Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -73,7 +73,7 @@ UINT8 mAtaCommands[][2][2] = {
 //\r
 // Look up table (UdmaValid, IsTrustSend) for ATA_CMD\r
 //\r
-UINT8 mAtaTrustCommands[2][2] = {      \r
+UINT8 mAtaTrustCommands[2][2] = {\r
   {\r
     ATA_CMD_TRUST_RECEIVE,            // PIO read\r
     ATA_CMD_TRUST_SEND                // PIO write\r
@@ -102,7 +102,7 @@ UINTN mMaxTransferBlockNumber[] = {
   transaction.\r
 \r
   @param[in, out]  AtaDevice   The ATA child device involved for the operation.\r
-  @param[in, out]  TaskPacket  Pointer to a Pass Thru Command Packet. Optional, \r
+  @param[in, out]  TaskPacket  Pointer to a Pass Thru Command Packet. Optional,\r
                                if it is NULL, blocking mode, and use the packet\r
                                in AtaDevice. If it is not NULL, non blocking mode,\r
                                and pass down this Packet.\r
@@ -127,7 +127,7 @@ AtaDevicePassThru (
   EFI_ATA_PASS_THRU_COMMAND_PACKET        *Packet;\r
 \r
   //\r
-  // Assemble packet. If it is non blocking mode, the Ata driver should keep each \r
+  // Assemble packet. If it is non blocking mode, the Ata driver should keep each\r
   // subtask and clean them when the event is signaled.\r
   //\r
   if (TaskPacket != NULL) {\r
@@ -152,7 +152,7 @@ AtaDevicePassThru (
                           );\r
   //\r
   // Ensure ATA pass through caller and callee have the same\r
-  // interpretation of ATA pass through protocol. \r
+  // interpretation of ATA pass through protocol.\r
   //\r
   ASSERT (Status != EFI_INVALID_PARAMETER);\r
   ASSERT (Status != EFI_BAD_BUFFER_SIZE);\r
@@ -165,7 +165,7 @@ AtaDevicePassThru (
   Wrapper for EFI_ATA_PASS_THRU_PROTOCOL.ResetDevice().\r
 \r
   This function wraps the ResetDevice() invocation for ATA pass through function\r
-  for an ATA device. \r
+  for an ATA device.\r
 \r
   @param  AtaDevice         The ATA child device involved for the operation.\r
 \r
@@ -178,9 +178,9 @@ ResetAtaDevice (
   )\r
 {\r
   EFI_ATA_PASS_THRU_PROTOCOL              *AtaPassThru;\r
-  \r
+\r
   AtaPassThru = AtaDevice->AtaBusDriverData->AtaPassThru;\r
-  \r
+\r
   return AtaPassThru->ResetDevice (\r
                         AtaPassThru,\r
                         AtaDevice->Port,\r
@@ -192,7 +192,7 @@ ResetAtaDevice (
 /**\r
   Prints ATA model name to ATA device structure.\r
 \r
-  This function converts ATA device model name from ATA identify data \r
+  This function converts ATA device model name from ATA identify data\r
   to a string in ATA device structure. It needs to change the character\r
   order in the original model name string.\r
 \r
@@ -271,7 +271,7 @@ GetAtapi6Capacity (
 /**\r
   Identifies ATA device via the Identify data.\r
 \r
-  This function identifies the ATA device and initializes the Media information in \r
+  This function identifies the ATA device and initializes the Media information in\r
   Block IO protocol interface.\r
 \r
   @param  AtaDevice         The ATA child device involved for the operation.\r
@@ -363,7 +363,7 @@ IdentifyAtaDevice (
     AtaDevice->BlockIo.Revision = EFI_BLOCK_IO_PROTOCOL_REVISION2;\r
   }\r
   //\r
-  // Get ATA model name from identify data structure. \r
+  // Get ATA model name from identify data structure.\r
   //\r
   PrintAtaModelName (AtaDevice);\r
 \r
@@ -382,7 +382,7 @@ IdentifyAtaDevice (
 \r
   @retval EFI_SUCCESS       The device is successfully identified and Media information\r
                             is correctly initialized.\r
-  @return others            Some error occurs when discovering the ATA device. \r
+  @return others            Some error occurs when discovering the ATA device.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -437,7 +437,7 @@ DiscoverAtaDevice (
   interface of ATA pass through.\r
 \r
   @param[in, out]  AtaDevice       The ATA child device involved for the operation.\r
-  @param[in, out]  TaskPacket      Pointer to a Pass Thru Command Packet. Optional, \r
+  @param[in, out]  TaskPacket      Pointer to a Pass Thru Command Packet. Optional,\r
                                    if it is NULL, blocking mode, and use the packet\r
                                    in AtaDevice. If it is not NULL, non blocking mode,\r
                                    and pass down this Packet.\r
@@ -452,7 +452,7 @@ DiscoverAtaDevice (
                                    request is completed.\r
 \r
   @retval EFI_SUCCESS       The data transfer is complete successfully.\r
-  @return others            Some error occurs when transferring data. \r
+  @return others            Some error occurs when transferring data.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -462,7 +462,7 @@ TransferAtaDevice (
   IN OUT VOID                             *Buffer,\r
   IN EFI_LBA                              StartLba,\r
   IN UINT32                               TransferLength,\r
-  IN BOOLEAN                              IsWrite, \r
+  IN BOOLEAN                              IsWrite,\r
   IN EFI_EVENT                            Event OPTIONAL\r
   )\r
 {\r
@@ -470,7 +470,7 @@ TransferAtaDevice (
   EFI_ATA_PASS_THRU_COMMAND_PACKET  *Packet;\r
 \r
   //\r
-  // Ensure AtaDevice->UdmaValid, AtaDevice->Lba48Bit and IsWrite are valid boolean values \r
+  // Ensure AtaDevice->UdmaValid, AtaDevice->Lba48Bit and IsWrite are valid boolean values\r
   //\r
   ASSERT ((UINTN) AtaDevice->UdmaValid < 2);\r
   ASSERT ((UINTN) AtaDevice->Lba48Bit < 2);\r
@@ -519,15 +519,15 @@ TransferAtaDevice (
 }\r
 \r
 /**\r
-  Free SubTask. \r
+  Free SubTask.\r
 \r
   @param[in, out]  Task      Pointer to task to be freed.\r
 \r
 **/\r
 VOID\r
-EFIAPI \r
+EFIAPI\r
 FreeAtaSubTask (\r
-  IN OUT ATA_BUS_ASYN_TASK  *Task\r
+  IN OUT ATA_BUS_ASYN_SUB_TASK  *Task\r
   )\r
 {\r
   if (Task->Packet.Asb != NULL) {\r
@@ -549,17 +549,23 @@ FreeAtaSubTask (
 \r
 **/\r
 VOID\r
-EFIAPI \r
+EFIAPI\r
 AtaNonBlockingCallBack (\r
   IN EFI_EVENT                Event,\r
   IN VOID                     *Context\r
   )\r
 {\r
-  ATA_BUS_ASYN_TASK *Task;\r
+  ATA_BUS_ASYN_SUB_TASK *Task;\r
+  ATA_BUS_ASYN_TASK     *AtaTask;\r
+  ATA_DEVICE            *AtaDevice;\r
+  LIST_ENTRY            *Entry;\r
+  EFI_STATUS            Status;\r
 \r
-  Task = (ATA_BUS_ASYN_TASK *) Context;\r
+  Task = (ATA_BUS_ASYN_SUB_TASK *) Context;\r
   gBS->CloseEvent (Event);\r
 \r
+  AtaDevice = Task->AtaDevice;\r
+\r
   //\r
   // Check the command status.\r
   // If there is error during the sub task source allocation, the error status\r
@@ -594,9 +600,34 @@ AtaNonBlockingCallBack (
       gBS->SignalEvent (Task->Token->Event);\r
       DEBUG ((EFI_D_BLKIO, "Signal the upper layer event!\n"));\r
     }\r
-    \r
+\r
     FreePool (Task->UnsignalledEventCount);\r
     FreePool (Task->IsError);\r
+\r
+\r
+    //\r
+    // Finish all subtasks and move to the next task in AtaTaskList.\r
+    //\r
+    if (!IsListEmpty (&AtaDevice->AtaTaskList)) {\r
+      Entry   = GetFirstNode (&AtaDevice->AtaTaskList);\r
+      AtaTask = ATA_AYNS_TASK_FROM_ENTRY (Entry);\r
+      DEBUG ((EFI_D_BLKIO, "Start to embark a new Ata Task\n"));\r
+      DEBUG ((EFI_D_BLKIO, "AtaTask->NumberOfBlocks = %x; AtaTask->Token=%x\n", AtaTask->NumberOfBlocks, AtaTask->Token));\r
+      Status = AccessAtaDevice (\r
+                 AtaTask->AtaDevice,\r
+                 AtaTask->Buffer,\r
+                 AtaTask->StartLba,\r
+                 AtaTask->NumberOfBlocks,\r
+                 AtaTask->IsWrite,\r
+                 AtaTask->Token\r
+                 );\r
+      if (EFI_ERROR (Status)) {\r
+        AtaTask->Token->TransactionStatus = Status;\r
+        gBS->SignalEvent (AtaTask->Token->Event);\r
+      }\r
+      RemoveEntryList (Entry);\r
+      FreePool (AtaTask);\r
+    }\r
   }\r
 \r
   DEBUG ((\r
@@ -630,10 +661,10 @@ AtaNonBlockingCallBack (
   @param[in, out]  Token           A pointer to the token associated with the transaction.\r
 \r
   @retval EFI_SUCCESS       The data transfer is complete successfully.\r
-  @return others            Some error occurs when transferring data. \r
+  @return others            Some error occurs when transferring data.\r
 \r
 **/\r
-EFI_STATUS \r
+EFI_STATUS\r
 AccessAtaDevice(\r
   IN OUT ATA_DEVICE                 *AtaDevice,\r
   IN OUT UINT8                      *Buffer,\r
@@ -647,9 +678,10 @@ AccessAtaDevice(
   UINTN                             MaxTransferBlockNumber;\r
   UINTN                             TransferBlockNumber;\r
   UINTN                             BlockSize;\r
+  ATA_BUS_ASYN_SUB_TASK             *SubTask;\r
   UINTN                             *EventCount;\r
   UINTN                             TempCount;\r
-  ATA_BUS_ASYN_TASK                 *Task;\r
+  ATA_BUS_ASYN_TASK                 *AtaTask;\r
   EFI_EVENT                         SubEvent;\r
   UINTN                             Index;\r
   BOOLEAN                           *IsError;\r
@@ -660,11 +692,12 @@ AccessAtaDevice(
   EventCount = NULL;\r
   IsError    = NULL;\r
   Index      = 0;\r
-  Task       = NULL;\r
+  SubTask    = NULL;\r
   SubEvent   = NULL;\r
-\r
+  AtaTask    = NULL;\r
+  \r
   //\r
-  // Ensure AtaDevice->Lba48Bit is a valid boolean value \r
+  // Ensure AtaDevice->Lba48Bit is a valid boolean value\r
   //\r
   ASSERT ((UINTN) AtaDevice->Lba48Bit < 2);\r
   MaxTransferBlockNumber = mMaxTransferBlockNumber[AtaDevice->Lba48Bit];\r
@@ -674,22 +707,52 @@ AccessAtaDevice(
   // Initial the return status and shared account for Non Blocking.\r
   //\r
   if ((Token != NULL) && (Token->Event != NULL)) {\r
-    Token->TransactionStatus = EFI_SUCCESS;\r
+    OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
+    if (!IsListEmpty (&AtaDevice->AtaSubTaskList)) {\r
+      AtaTask = AllocateZeroPool (sizeof (ATA_BUS_ASYN_TASK));\r
+      if (AtaTask == NULL) {\r
+        gBS->RestoreTPL (OldTpl);\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+      AtaTask->AtaDevice      = AtaDevice;\r
+      AtaTask->Buffer         = Buffer;\r
+      AtaTask->IsWrite        = IsWrite;\r
+      AtaTask->NumberOfBlocks = NumberOfBlocks;\r
+      AtaTask->Signature      = ATA_TASK_SIGNATURE;\r
+      AtaTask->StartLba       = StartLba;\r
+      AtaTask->Token          = Token;\r
+\r
+      InsertTailList (&AtaDevice->AtaTaskList, &AtaTask->TaskEntry);\r
+      gBS->RestoreTPL (OldTpl);\r
+      return EFI_SUCCESS;\r
+    }\r
+    gBS->RestoreTPL (OldTpl);\r
 \r
+    Token->TransactionStatus = EFI_SUCCESS;\r
     EventCount = AllocateZeroPool (sizeof (UINTN));\r
     if (EventCount == NULL) {\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
-  \r
+\r
     IsError = AllocateZeroPool (sizeof (BOOLEAN));\r
     if (IsError == NULL) {\r
       FreePool (EventCount);\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
+    DEBUG ((EFI_D_BLKIO, "Allocation IsError Addr=%x\n", IsError));\r
     *IsError = FALSE;\r
-    \r
     TempCount   = (NumberOfBlocks + MaxTransferBlockNumber - 1) / MaxTransferBlockNumber;\r
     *EventCount = TempCount;\r
+    DEBUG ((EFI_D_BLKIO, "AccessAtaDevice, NumberOfBlocks=%x\n", NumberOfBlocks));\r
+    DEBUG ((EFI_D_BLKIO, "AccessAtaDevice, MaxTransferBlockNumber=%x\n", MaxTransferBlockNumber));\r
+    DEBUG ((EFI_D_BLKIO, "AccessAtaDevice, EventCount=%x\n", TempCount));\r
+  }else {\r
+    while (!IsListEmpty (&AtaDevice->AtaTaskList) || !IsListEmpty (&AtaDevice->AtaSubTaskList)) {\r
+      //\r
+      // Stall for 100us.\r
+      //\r
+      MicroSecondDelay (100);\r
+    }\r
   }\r
 \r
   do {\r
@@ -705,27 +768,29 @@ AccessAtaDevice(
     // Create sub event for the sub ata task. Non-blocking mode.\r
     //\r
     if ((Token != NULL) && (Token->Event != NULL)) {\r
-      Task     = NULL;\r
+      SubTask  = NULL;\r
       SubEvent = NULL;\r
 \r
-      Task = AllocateZeroPool (sizeof (ATA_BUS_ASYN_TASK));\r
-      if (Task == NULL) {\r
+      SubTask = AllocateZeroPool (sizeof (ATA_BUS_ASYN_SUB_TASK));\r
+      if (SubTask == NULL) {\r
         Status = EFI_OUT_OF_RESOURCES;\r
         goto EXIT;\r
       }\r
 \r
       OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r
-      Task->UnsignalledEventCount = EventCount;\r
-      Task->Token                 = Token;\r
-      Task->IsError               = IsError;\r
-      InsertTailList (&AtaDevice->AtaTaskList, &Task->TaskEntry);\r
-      gBS->RestoreTPL (OldTpl); \r
+      SubTask->UnsignalledEventCount = EventCount;\r
+      SubTask->Signature             = ATA_SUB_TASK_SIGNATURE;\r
+      SubTask->AtaDevice             = AtaDevice;\r
+      SubTask->Token                 = Token;\r
+      SubTask->IsError               = IsError;\r
+      InsertTailList (&AtaDevice->AtaSubTaskList, &SubTask->TaskEntry);\r
+      gBS->RestoreTPL (OldTpl);\r
 \r
       Status = gBS->CreateEvent (\r
                       EVT_NOTIFY_SIGNAL,\r
                       TPL_NOTIFY,\r
                       AtaNonBlockingCallBack,\r
-                      Task,\r
+                      SubTask,\r
                       &SubEvent\r
                       );\r
       //\r
@@ -737,11 +802,12 @@ AccessAtaDevice(
         goto EXIT;\r
       }\r
 \r
-      Status = TransferAtaDevice (AtaDevice, &Task->Packet, Buffer, StartLba, (UINT32) TransferBlockNumber, IsWrite, SubEvent);\r
+      Status = TransferAtaDevice (AtaDevice, &SubTask->Packet, Buffer, StartLba, (UINT32) TransferBlockNumber, IsWrite, SubEvent);\r
     } else {\r
       //\r
       // Blocking Mode.\r
       //\r
+      DEBUG ((EFI_D_BLKIO, "Blocking AccessAtaDevice, TransferBlockNumber=%x; StartLba = %x\n", TransferBlockNumber, StartLba));\r
       Status = TransferAtaDevice (AtaDevice, NULL, Buffer, StartLba, (UINT32) TransferBlockNumber, IsWrite, NULL);\r
     }\r
 \r
@@ -764,24 +830,23 @@ EXIT:
       Token->TransactionStatus = Status;\r
       *EventCount = (*EventCount) - (TempCount - Index);\r
       *IsError    = TRUE;\r
-      \r
+\r
       if (*EventCount == 0) {\r
         FreePool (EventCount);\r
         FreePool (IsError);\r
       }\r
-      \r
-      if (Task != NULL) {\r
-        RemoveEntryList (&Task->TaskEntry);\r
-        FreeAtaSubTask (Task);  \r
+\r
+      if (SubTask != NULL) {\r
+        RemoveEntryList (&SubTask->TaskEntry);\r
+        FreeAtaSubTask (SubTask);\r
       }\r
 \r
       if (SubEvent != NULL) {\r
-        gBS->CloseEvent (SubEvent);  \r
+        gBS->CloseEvent (SubEvent);\r
       }\r
-      \r
       gBS->RestoreTPL (OldTpl);\r
     }\r
-  } \r
+  }\r
 \r
   return Status;\r
 }\r
@@ -812,7 +877,7 @@ EXIT:
                                        written to the buffer. Ignore it when IsTrustSend is TRUE.\r
 \r
   @retval EFI_SUCCESS       The data transfer is complete successfully.\r
-  @return others            Some error occurs when transferring data. \r
+  @return others            Some error occurs when transferring data.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -835,7 +900,7 @@ TrustTransferAtaDevice (
   EFI_ATA_PASS_THRU_PROTOCOL        *AtaPassThru;\r
 \r
   //\r
-  // Ensure AtaDevice->UdmaValid and IsTrustSend are valid boolean values \r
+  // Ensure AtaDevice->UdmaValid and IsTrustSend are valid boolean values\r
   //\r
   ASSERT ((UINTN) AtaDevice->UdmaValid < 2);\r
   ASSERT ((UINTN) IsTrustSend < 2);\r
@@ -852,12 +917,12 @@ TrustTransferAtaDevice (
   Acb->AtaSectorCount   = (UINT8) (TransferLength / 512);\r
   Acb->AtaSectorNumber  = (UINT8) ((TransferLength / 512) >> 8);\r
   //\r
-  // NOTE: ATA Spec has no explicitly definition for Security Protocol Specific layout. \r
-  // Here use big endian for Cylinder register. \r
+  // NOTE: ATA Spec has no explicitly definition for Security Protocol Specific layout.\r
+  // Here use big endian for Cylinder register.\r
   //\r
   Acb->AtaCylinderHigh  = (UINT8) SecurityProtocolSpecificData;\r
   Acb->AtaCylinderLow   = (UINT8) (SecurityProtocolSpecificData >> 8);\r
-  Acb->AtaDeviceHead    = (UINT8) (BIT7 | BIT6 | BIT5 | (AtaDevice->PortMultiplierPort << 4)); \r
+  Acb->AtaDeviceHead    = (UINT8) (BIT7 | BIT6 | BIT5 | (AtaDevice->PortMultiplierPort << 4));\r
 \r
   //\r
   // Prepare for ATA pass through packet.\r
@@ -877,7 +942,7 @@ TrustTransferAtaDevice (
       CopyMem (NewBuffer, Buffer, TransferLength);\r
       FreePool (Buffer);\r
       Buffer = NewBuffer;\r
-    } \r
+    }\r
     Packet->OutDataBuffer = Buffer;\r
     Packet->OutTransferLength = (UINT32) TransferLength;\r
     Packet->Protocol = mAtaPassThruCmdProtocols[AtaDevice->UdmaValid][IsTrustSend];\r