]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBus.c
Introduce tow non-blocking task lists to AtaBus. One maintains the sub-task which...
[mirror_edk2.git] / MdeModulePkg / Bus / Ata / AtaBusDxe / AtaBus.c
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