]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add DiskIo2 protocol definition to MdePkg.
authorRuiyu Ni <ruiyu.ni@intel.com>
Tue, 20 Aug 2013 03:14:30 +0000 (03:14 +0000)
committerniruiyu <niruiyu@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 20 Aug 2013 03:14:30 +0000 (03:14 +0000)
Change DiskIoDxe to produce DiskIo2 protocol when the BlockIo2 protocol is available.
Change PartitionDxe to produce BlockIo2 protocol based on DiskIo2 protocol instead of BlockIo2 protocol.

Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Kinney Michael <michael.d.kinney@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14570 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIo.c
MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIo.h
MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf
MdeModulePkg/Universal/Disk/PartitionDxe/ElTorito.c
MdeModulePkg/Universal/Disk/PartitionDxe/Gpt.c
MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c
MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c
MdeModulePkg/Universal/Disk/PartitionDxe/Partition.h
MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf
MdePkg/Include/Protocol/DiskIo2.h [new file with mode: 0644]
MdePkg/MdePkg.dec

index 0175465ade735e015cab64b064f1d57c2bf5ca02..4bd6772046310cd2e367e11dfa321012d49ea9fb 100644 (file)
@@ -9,7 +9,7 @@
     Aligned  - A read of N contiguous sectors.\r
     OverRun  - The last byte is not on a sector boundary.\r
 \r
-Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2013, 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
@@ -45,10 +45,15 @@ DISK_IO_PRIVATE_DATA        gDiskIoPrivateDataTemplate = {
     DiskIoReadDisk,\r
     DiskIoWriteDisk\r
   },\r
-  NULL\r
+  {\r
+    EFI_DISK_IO2_PROTOCOL_REVISION,\r
+    DiskIo2Cancel,\r
+    DiskIo2ReadDiskEx,\r
+    DiskIo2WriteDiskEx,\r
+    DiskIo2FlushDiskEx\r
+  }\r
 };\r
 \r
-\r
 /**\r
   Test to see if this driver supports ControllerHandle. \r
 \r
@@ -92,11 +97,11 @@ DiskIoDriverBindingSupported (
   // Close the I/O Abstraction(s) used to perform the supported test.\r
   //\r
   gBS->CloseProtocol (\r
-        ControllerHandle,\r
-        &gEfiBlockIoProtocolGuid,\r
-        This->DriverBindingHandle,\r
-        ControllerHandle\r
-        );\r
+         ControllerHandle,\r
+         &gEfiBlockIoProtocolGuid,\r
+         This->DriverBindingHandle,\r
+         ControllerHandle\r
+         );\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -124,14 +129,16 @@ DiskIoDriverBindingStart (
   )\r
 {\r
   EFI_STATUS            Status;\r
-  DISK_IO_PRIVATE_DATA  *Private;\r
+  DISK_IO_PRIVATE_DATA  *Instance;\r
   EFI_TPL               OldTpl;\r
+  EFI_BLOCK_IO_MEDIA    *Media;\r
+\r
+  Instance = NULL;\r
 \r
   OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
-  Private = NULL;\r
 \r
   //\r
-  // Connect to the Block IO interface on ControllerHandle.\r
+  // Connect to the Block IO and Block IO2 interface on ControllerHandle.\r
   //\r
   Status = gBS->OpenProtocol (\r
                   ControllerHandle,\r
@@ -144,39 +151,86 @@ DiskIoDriverBindingStart (
   if (EFI_ERROR (Status)) {\r
     goto ErrorExit1;\r
   }\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiBlockIo2ProtocolGuid,\r
+                  (VOID **) &gDiskIoPrivateDataTemplate.BlockIo2,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    gDiskIoPrivateDataTemplate.BlockIo2 = NULL;\r
+  }\r
   \r
   //\r
   // Initialize the Disk IO device instance.\r
   //\r
-  Private = AllocateCopyPool (sizeof (DISK_IO_PRIVATE_DATA), &gDiskIoPrivateDataTemplate);\r
-  if (Private == NULL) {\r
+  Instance = AllocateCopyPool (sizeof (DISK_IO_PRIVATE_DATA), &gDiskIoPrivateDataTemplate);\r
+  if (Instance == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
     goto ErrorExit;\r
   }\r
   \r
+  Media = Instance->BlockIo->Media;\r
+\r
+  //\r
+  // The BlockSize and IoAlign of BlockIo and BlockIo2 should equal.\r
+  //\r
+  ASSERT ((Instance->BlockIo2 == NULL) ||\r
+          ((Instance->BlockIo->Media->IoAlign == Instance->BlockIo2->Media->IoAlign) && \r
+           (Instance->BlockIo->Media->BlockSize == Instance->BlockIo2->Media->BlockSize)\r
+          ));\r
+  \r
+  InitializeListHead (&Instance->TaskQueue);\r
+  EfiInitializeLock (&Instance->TaskQueueLock, TPL_NOTIFY);\r
+  Instance->SharedWorkingBuffer = AllocateAlignedPages (\r
+                                    EFI_SIZE_TO_PAGES (DATA_BUFFER_BLOCK_NUM * Instance->BlockIo->Media->BlockSize),\r
+                                    Instance->BlockIo->Media->IoAlign\r
+                                    );\r
+  if (Instance->SharedWorkingBuffer == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto ErrorExit;\r
+  }\r
+\r
   //\r
   // Install protocol interfaces for the Disk IO device.\r
   //\r
-  Status = gBS->InstallProtocolInterface (\r
-                  &ControllerHandle,\r
-                  &gEfiDiskIoProtocolGuid,\r
-                  EFI_NATIVE_INTERFACE,\r
-                  &Private->DiskIo\r
-                  );\r
+  if (Instance->BlockIo2 != NULL) {\r
+    Status = gBS->InstallMultipleProtocolInterfaces (\r
+                    &ControllerHandle,\r
+                    &gEfiDiskIoProtocolGuid,  &Instance->DiskIo,\r
+                    &gEfiDiskIo2ProtocolGuid, &Instance->DiskIo2,\r
+                    NULL\r
+                    );\r
+  } else {\r
+    Status = gBS->InstallMultipleProtocolInterfaces (\r
+                    &ControllerHandle,\r
+                    &gEfiDiskIoProtocolGuid,  &Instance->DiskIo,\r
+                    NULL\r
+                    );\r
+  }\r
 \r
 ErrorExit:\r
   if (EFI_ERROR (Status)) {\r
+    if (Instance != NULL && Instance->SharedWorkingBuffer != NULL) {\r
+      FreeAlignedPages (\r
+        Instance->SharedWorkingBuffer,\r
+        EFI_SIZE_TO_PAGES (DATA_BUFFER_BLOCK_NUM * Instance->BlockIo->Media->BlockSize)\r
+        );\r
+    }\r
 \r
-    if (Private != NULL) {\r
-      FreePool (Private);\r
+    if (Instance != NULL) {\r
+      FreePool (Instance);\r
     }\r
 \r
     gBS->CloseProtocol (\r
-          ControllerHandle,\r
-          &gEfiBlockIoProtocolGuid,\r
-          This->DriverBindingHandle,\r
-          ControllerHandle\r
-          );\r
+           ControllerHandle,\r
+           &gEfiBlockIoProtocolGuid,\r
+           This->DriverBindingHandle,\r
+           ControllerHandle\r
+           );\r
   }\r
 \r
 ErrorExit1:\r
@@ -184,7 +238,6 @@ ErrorExit1:
   return Status;\r
 }\r
 \r
-\r
 /**\r
   Stop this driver on ControllerHandle by removing Disk IO protocol and closing\r
   the Block IO protocol on ControllerHandle.\r
@@ -210,7 +263,9 @@ DiskIoDriverBindingStop (
 {\r
   EFI_STATUS            Status;\r
   EFI_DISK_IO_PROTOCOL  *DiskIo;\r
-  DISK_IO_PRIVATE_DATA  *Private;\r
+  EFI_DISK_IO2_PROTOCOL *DiskIo2;\r
+  DISK_IO_PRIVATE_DATA  *Instance;\r
+  BOOLEAN               AllTaskDone;\r
 \r
   //\r
   // Get our context back.\r
@@ -224,489 +279,947 @@ DiskIoDriverBindingStop (
                   EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    return EFI_UNSUPPORTED;\r
+    return Status;\r
   }\r
-\r
-  Private = DISK_IO_PRIVATE_DATA_FROM_THIS (DiskIo);\r
-\r
-  Status = gBS->UninstallProtocolInterface (\r
+  Status = gBS->OpenProtocol (\r
                   ControllerHandle,\r
-                  &gEfiDiskIoProtocolGuid,\r
-                  &Private->DiskIo\r
+                  &gEfiDiskIo2ProtocolGuid,\r
+                  (VOID **) &DiskIo2,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
                   );\r
+  if (EFI_ERROR (Status)) {\r
+    DiskIo2 = NULL;\r
+  }\r
+  \r
+  Instance = DISK_IO_PRIVATE_DATA_FROM_DISK_IO (DiskIo);\r
+\r
+  if (DiskIo2 != NULL) {\r
+    //\r
+    // Call BlockIo2::Reset() to terminate any in-flight non-blocking I/O requests\r
+    //\r
+    ASSERT (Instance->BlockIo2 != NULL);\r
+    Status = Instance->BlockIo2->Reset (Instance->BlockIo2, FALSE);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+    Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                    ControllerHandle,\r
+                    &gEfiDiskIoProtocolGuid,  &Instance->DiskIo,\r
+                    &gEfiDiskIo2ProtocolGuid, &Instance->DiskIo2,\r
+                    NULL\r
+                    );\r
+  } else {\r
+    Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                    ControllerHandle,\r
+                    &gEfiDiskIoProtocolGuid,  &Instance->DiskIo,\r
+                    NULL\r
+                    );\r
+  }\r
   if (!EFI_ERROR (Status)) {\r
+    \r
+    do {\r
+      EfiAcquireLock (&Instance->TaskQueueLock);\r
+      AllTaskDone = IsListEmpty (&Instance->TaskQueue);\r
+      EfiReleaseLock (&Instance->TaskQueueLock);\r
+    } while (!AllTaskDone);\r
+\r
+    FreeAlignedPages (\r
+      Instance->SharedWorkingBuffer,\r
+      EFI_SIZE_TO_PAGES (DATA_BUFFER_BLOCK_NUM * Instance->BlockIo->Media->BlockSize)\r
+      );\r
+\r
     Status = gBS->CloseProtocol (\r
                     ControllerHandle,\r
                     &gEfiBlockIoProtocolGuid,\r
                     This->DriverBindingHandle,\r
                     ControllerHandle\r
                     );\r
+    ASSERT_EFI_ERROR (Status);\r
+    if (DiskIo2 != NULL) {\r
+      Status = gBS->CloseProtocol (\r
+                      ControllerHandle,\r
+                      &gEfiBlockIo2ProtocolGuid,\r
+                      This->DriverBindingHandle,\r
+                      ControllerHandle\r
+                      );\r
+      ASSERT_EFI_ERROR (Status);\r
+    }\r
+    \r
+    FreePool (Instance);\r
   }\r
 \r
-  if (!EFI_ERROR (Status)) {\r
-    FreePool (Private);\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Destroy the sub task.\r
+\r
+  @param Subtask      Subtask.\r
+\r
+  @return LIST_ENTRY *  Pointer to the next link of subtask.\r
+**/\r
+LIST_ENTRY *\r
+DiskIoDestroySubtask (\r
+  IN DISK_IO_PRIVATE_DATA     *Instance,\r
+  IN DISK_IO_SUBTASK          *Subtask\r
+  )\r
+{\r
+  LIST_ENTRY               *Link;\r
+  Link = RemoveEntryList (&Subtask->Link);\r
+  if (!Subtask->Blocking) {\r
+    if (Subtask->WorkingBuffer != NULL) {\r
+      FreeAlignedPages (\r
+        Subtask->WorkingBuffer, \r
+        Subtask->Length < Instance->BlockIo->Media->BlockSize\r
+        ? EFI_SIZE_TO_PAGES (Instance->BlockIo->Media->BlockSize)\r
+        : EFI_SIZE_TO_PAGES (Subtask->Length)\r
+        );\r
+    }\r
+    if (Subtask->BlockIo2Token.Event != NULL) {\r
+      gBS->CloseEvent (Subtask->BlockIo2Token.Event);\r
+    }\r
   }\r
+  FreePool (Subtask);\r
 \r
-  return Status;\r
+  return Link;\r
 }\r
 \r
+/**\r
+  The callback for the BlockIo2 ReadBlocksEx/WriteBlocksEx.\r
+  @param  Event                 Event whose notification function is being invoked.\r
+  @param  Context               The pointer to the notification function's context,\r
+                                which points to the DISK_IO_SUBTASK instance.\r
+**/\r
+VOID\r
+EFIAPI\r
+DiskIo2OnReadWriteComplete (\r
+  IN EFI_EVENT            Event,\r
+  IN VOID                 *Context\r
+  )\r
+{\r
+  DISK_IO_SUBTASK       *Subtask;\r
+  DISK_IO2_TASK         *Task;\r
+  EFI_STATUS            TransactionStatus;\r
+  DISK_IO_PRIVATE_DATA  *Instance;\r
+\r
+  gBS->CloseEvent (Event);\r
+\r
+  Subtask           = (DISK_IO_SUBTASK *) Context;\r
+  TransactionStatus = Subtask->BlockIo2Token.TransactionStatus;\r
+  Task              = Subtask->Task;\r
+  Instance          = Task->Instance;\r
+\r
+  ASSERT (Subtask->Signature  == DISK_IO_SUBTASK_SIGNATURE);\r
+  ASSERT (Instance->Signature == DISK_IO_PRIVATE_DATA_SIGNATURE);\r
+  ASSERT (Task->Signature     == DISK_IO2_TASK_SIGNATURE);\r
 \r
+  if (Subtask->WorkingBuffer != NULL) {\r
+    if (!EFI_ERROR (TransactionStatus) && (Task->Token != NULL) && !Subtask->Write) {\r
+      CopyMem (Subtask->Buffer, Subtask->WorkingBuffer + Subtask->Offset, Subtask->Length);\r
+    }\r
+\r
+    //\r
+    // The WorkingBuffer of blocking subtask either points to SharedWorkingBuffer\r
+    // or will be used by non-blocking subtask which will be freed below.\r
+    //\r
+    if (!Subtask->Blocking) {\r
+      FreeAlignedPages (\r
+        Subtask->WorkingBuffer, \r
+        Subtask->Length < Instance->BlockIo->Media->BlockSize\r
+        ? EFI_SIZE_TO_PAGES (Instance->BlockIo->Media->BlockSize)\r
+        : EFI_SIZE_TO_PAGES (Subtask->Length)\r
+        );\r
+    }\r
+  }\r
+  RemoveEntryList (&Subtask->Link);\r
+  FreePool (Subtask);\r
+\r
+  if (EFI_ERROR (TransactionStatus) || IsListEmpty (&Task->Subtasks)) {\r
+    if (Task->Token != NULL) {\r
+      //\r
+      // Signal error status once the subtask is failed.\r
+      // Or signal the last status once the last subtask is finished.\r
+      //\r
+      Task->Token->TransactionStatus = TransactionStatus;\r
+      gBS->SignalEvent (Task->Token->Event);\r
+\r
+      //\r
+      // Mark token to NULL\r
+      //\r
+      Task->Token = NULL;\r
+    }\r
+  }\r
+\r
+  if (IsListEmpty (&Task->Subtasks)) {\r
+    EfiAcquireLock (&Instance->TaskQueueLock);\r
+    RemoveEntryList (&Task->Link);\r
+    EfiReleaseLock (&Instance->TaskQueueLock);\r
+\r
+    FreePool (Task);\r
+  }\r
+}\r
 \r
 /**\r
-  Read BufferSize bytes from Offset into Buffer.\r
-  Reads may support reads that are not aligned on\r
-  sector boundaries. There are three cases:\r
-    UnderRun - The first byte is not on a sector boundary or the read request is\r
-               less than a sector in length.\r
-    Aligned  - A read of N contiguous sectors.\r
-    OverRun  - The last byte is not on a sector boundary.\r
+  Create the subtask.\r
 \r
-  @param  This                  Protocol instance pointer.\r
-  @param  MediaId               Id of the media, changes every time the media is replaced.\r
-  @param  Offset                The starting byte offset to read from\r
-  @param  BufferSize            Size of Buffer\r
-  @param  Buffer                Buffer containing read data\r
+  @param Write         TRUE: Write request; FALSE: Read request.\r
+  @param Lba           The starting logical block address to read from on the device.\r
+  @param Offset        The starting byte offset to read from the LBA.\r
+  @param Length        The number of bytes to read from the device.\r
+  @param WorkingBuffer The aligned buffer to hold the data for reading or writing.\r
+  @param Buffer        The buffer to hold the data for reading or writing.\r
+  @param Blocking      TRUE: Blocking request; FALSE: Non-blocking request.\r
 \r
-  @retval EFI_SUCCESS           The data was read correctly from the device.\r
-  @retval EFI_DEVICE_ERROR      The device reported an error while performing the read.\r
-  @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_INVALID_PARAMETER The read request contains device addresses that are not\r
-                                valid for the device.\r
+  @return A pointer to the created subtask.\r
+**/\r
+DISK_IO_SUBTASK *\r
+DiskIoCreateSubtask (\r
+  IN BOOLEAN          Write,\r
+  IN UINT64           Lba,\r
+  IN UINT32           Offset,\r
+  IN UINTN            Length,\r
+  IN VOID             *WorkingBuffer,  OPTIONAL\r
+  IN VOID             *Buffer,\r
+  IN BOOLEAN          Blocking\r
+  )\r
+{\r
+  DISK_IO_SUBTASK       *Subtask;\r
+  EFI_STATUS            Status;\r
 \r
+  Subtask = AllocateZeroPool (sizeof (DISK_IO_SUBTASK));\r
+  if (Subtask == NULL) {\r
+    return NULL;\r
+  }\r
+  Subtask->Signature     = DISK_IO_SUBTASK_SIGNATURE;\r
+  Subtask->Write         = Write;\r
+  Subtask->Lba           = Lba;\r
+  Subtask->Offset        = Offset;\r
+  Subtask->Length        = Length;\r
+  Subtask->WorkingBuffer = WorkingBuffer;\r
+  Subtask->Buffer        = Buffer;\r
+  Subtask->Blocking      = Blocking;\r
+  if (!Blocking) {\r
+    Status = gBS->CreateEvent (\r
+                    EVT_NOTIFY_SIGNAL,\r
+                    TPL_NOTIFY,\r
+                    DiskIo2OnReadWriteComplete,\r
+                    Subtask,\r
+                    &Subtask->BlockIo2Token.Event\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      FreePool (Subtask);\r
+      return NULL;\r
+    }\r
+  }\r
+  DEBUG ((\r
+    EFI_D_BLKIO, \r
+    "  %c:Lba/Offset/Length/WorkingBuffer/Buffer = %016lx/%08x/%08x/%08x/%08x\n",\r
+    Write ? 'W': 'R', Lba, Offset, Length, WorkingBuffer, Buffer\r
+    ));\r
+\r
+  return Subtask;\r
+}\r
+\r
+/**\r
+  Create the subtask list.\r
+\r
+  @param Instance            Pointer to the DISK_IO_PRIVATE_DATA.\r
+  @param Write               TRUE: Write request; FALSE: Read request.\r
+  @param Offset              The starting byte offset to read from the device.\r
+  @param BufferSize          The size in bytes of Buffer. The number of bytes to read from the device.\r
+  @param Buffer              A pointer to the buffer for the data.\r
+  @param Blocking            TRUE: Blocking request; FALSE: Non-blocking request.\r
+  @param SharedWorkingBuffer The aligned buffer to hold the data for reading or writing.\r
+  @param Subtasks            The subtask list header.\r
+\r
+  @retval TRUE  The subtask list is created successfully.\r
+  @retval FALSE The subtask list is not created.\r
 **/\r
-EFI_STATUS\r
-EFIAPI\r
-DiskIoReadDisk (\r
-  IN EFI_DISK_IO_PROTOCOL  *This,\r
-  IN UINT32                MediaId,\r
+BOOLEAN\r
+DiskIoCreateSubtaskList (\r
+  IN DISK_IO_PRIVATE_DATA  *Instance,\r
+  IN BOOLEAN               Write,\r
   IN UINT64                Offset,\r
   IN UINTN                 BufferSize,\r
-  OUT VOID                 *Buffer\r
+  IN VOID                  *Buffer,\r
+  IN BOOLEAN               Blocking,\r
+  IN VOID                  *SharedWorkingBuffer,\r
+  IN OUT LIST_ENTRY        *Subtasks\r
   )\r
 {\r
-  EFI_STATUS            Status;\r
-  DISK_IO_PRIVATE_DATA  *Private;\r
-  EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
-  EFI_BLOCK_IO_MEDIA    *Media;\r
   UINT32                BlockSize;\r
+  UINT32                IoAlign;\r
   UINT64                Lba;\r
   UINT64                OverRunLba;\r
   UINT32                UnderRun;\r
   UINT32                OverRun;\r
-  BOOLEAN               TransactionComplete;\r
-  UINTN                 WorkingBufferSize;\r
-  UINT8                 *WorkingBuffer;\r
+  UINT8                 *BufferPtr;\r
   UINTN                 Length;\r
-  UINT8                 *Data;\r
-  UINT8                 *PreData;\r
-  UINTN                 IsBufferAligned;\r
   UINTN                 DataBufferSize;\r
-  BOOLEAN               LastRead;\r
+  DISK_IO_SUBTASK       *Subtask;\r
+  VOID                  *WorkingBuffer;\r
+  LIST_ENTRY            *Link;\r
 \r
-  Private   = DISK_IO_PRIVATE_DATA_FROM_THIS (This);\r
-\r
-  BlockIo   = Private->BlockIo;\r
-  Media     = BlockIo->Media;\r
-  BlockSize = Media->BlockSize;\r
+  DEBUG ((EFI_D_BLKIO, "DiskIo: Create subtasks for task: Offset/BufferSize/Buffer = %016lx/%08x/%08x\n", Offset, BufferSize, Buffer));\r
 \r
-  if (Media->MediaId != MediaId) {\r
-    return EFI_MEDIA_CHANGED;\r
+  BlockSize = Instance->BlockIo->Media->BlockSize;\r
+  IoAlign   = Instance->BlockIo->Media->IoAlign;\r
+  if (IoAlign == 0) {\r
+    IoAlign = 1;\r
   }\r
-\r
-  WorkingBuffer     = Buffer;\r
-  WorkingBufferSize = BufferSize;\r
+  \r
+  Lba       = DivU64x32Remainder (Offset, BlockSize, &UnderRun);\r
+  BufferPtr = (UINT8 *) Buffer;\r
 \r
   //\r
-  // Allocate a temporary buffer for operation\r
+  // Special handling for zero BufferSize\r
   //\r
-  DataBufferSize = BlockSize * DATA_BUFFER_BLOCK_NUM;\r
-\r
-  if (Media->IoAlign > 1) {\r
-    PreData = AllocatePool (DataBufferSize + Media->IoAlign);\r
-    Data    = PreData - ((UINTN) PreData & (Media->IoAlign - 1)) + Media->IoAlign;\r
-  } else {\r
-    PreData = AllocatePool (DataBufferSize);\r
-    Data    = PreData;\r
-  }\r
-\r
-  if (PreData == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
+  if (BufferSize == 0) {\r
+    Subtask = DiskIoCreateSubtask (Write, Lba, UnderRun, 0, NULL, BufferPtr, Blocking);\r
+    if (Subtask == NULL) {\r
+      goto Done;\r
+    }\r
+    InsertTailList (Subtasks, &Subtask->Link);\r
+    return TRUE;\r
   }\r
 \r
-  Lba                 = DivU64x32Remainder (Offset, BlockSize, &UnderRun);\r
-\r
-  Length              = BlockSize - UnderRun;\r
-  TransactionComplete = FALSE;\r
-\r
-  Status              = EFI_SUCCESS;\r
   if (UnderRun != 0) {\r
-    //\r
-    // Offset starts in the middle of an Lba, so read the entire block.\r
-    //\r
-    Status = BlockIo->ReadBlocks (\r
-                        BlockIo,\r
-                        MediaId,\r
-                        Lba,\r
-                        BlockSize,\r
-                        Data\r
-                        );\r
-\r
-    if (EFI_ERROR (Status)) {\r
-      goto Done;\r
+    Length = MIN (BlockSize - UnderRun, BufferSize);\r
+    if (Blocking) {\r
+      WorkingBuffer = SharedWorkingBuffer;\r
+    } else {\r
+      WorkingBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES (BlockSize), IoAlign);\r
+      if (WorkingBuffer == NULL) {\r
+        goto Done;\r
+      }\r
+    }\r
+    if (Write) {\r
+      //\r
+      // A half write operation can be splitted to a blocking block-read and half write operation\r
+      // This can simplify the sub task processing logic\r
+      //\r
+      Subtask = DiskIoCreateSubtask (FALSE, Lba, 0, BlockSize, NULL, WorkingBuffer, TRUE);\r
+      if (Subtask == NULL) {\r
+        goto Done;\r
+      }\r
+      InsertTailList (Subtasks, &Subtask->Link);\r
     }\r
 \r
-    if (Length > BufferSize) {\r
-      Length              = BufferSize;\r
-      TransactionComplete = TRUE;\r
+    Subtask = DiskIoCreateSubtask (Write, Lba, UnderRun, Length, WorkingBuffer, BufferPtr, Blocking);\r
+    if (Subtask == NULL) {\r
+      goto Done;\r
     }\r
+    InsertTailList (Subtasks, &Subtask->Link);\r
+  \r
+    BufferPtr  += Length;\r
+    Offset     += Length;\r
+    BufferSize -= Length;\r
+    Lba ++;\r
+  }\r
 \r
-    CopyMem (WorkingBuffer, Data + UnderRun, Length);\r
+  OverRunLba  = Lba + DivU64x32Remainder (BufferSize, BlockSize, &OverRun);\r
+  BufferSize -= OverRun;\r
 \r
-    WorkingBuffer += Length;\r
+  if (OverRun != 0) {\r
+    if (Blocking) {\r
+      WorkingBuffer = SharedWorkingBuffer;\r
+    } else {\r
+      WorkingBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES (BlockSize), IoAlign);\r
+      if (WorkingBuffer == NULL) {\r
+        goto Done;\r
+      }\r
+    }\r
+    if (Write) {\r
+      //\r
+      // A half write operation can be splitted to a blocking block-read and half write operation\r
+      // This can simplify the sub task processing logic\r
+      //\r
+      Subtask = DiskIoCreateSubtask (FALSE, OverRunLba, 0, BlockSize, NULL, WorkingBuffer, TRUE);\r
+      if (Subtask == NULL) {\r
+        goto Done;\r
+      }\r
+      InsertTailList (Subtasks, &Subtask->Link);\r
+    }\r
 \r
-    WorkingBufferSize -= Length;\r
-    if (WorkingBufferSize == 0) {\r
+    Subtask = DiskIoCreateSubtask (Write, OverRunLba, 0, OverRun, WorkingBuffer, BufferPtr, Blocking);\r
+    if (Subtask == NULL) {\r
       goto Done;\r
     }\r
-\r
-    Lba += 1;\r
+    InsertTailList (Subtasks, &Subtask->Link);\r
   }\r
-\r
-  OverRunLba = Lba + DivU64x32Remainder (WorkingBufferSize, BlockSize, &OverRun);\r
-\r
-  if (!TransactionComplete && WorkingBufferSize >= BlockSize) {\r
+  \r
+  if (OverRunLba > Lba) {\r
     //\r
     // If the DiskIo maps directly to a BlockIo device do the read.\r
     //\r
-    if (OverRun != 0) {\r
-      WorkingBufferSize -= OverRun;\r
-    }\r
-    //\r
-    // Check buffer alignment\r
-    //\r
-    IsBufferAligned = (UINTN) WorkingBuffer & (UINTN) (Media->IoAlign - 1);\r
-\r
-    if (Media->IoAlign <= 1 || IsBufferAligned == 0) {\r
-      //\r
-      // Alignment is satisfied, so read them together\r
-      //\r
-      Status = BlockIo->ReadBlocks (\r
-                          BlockIo,\r
-                          MediaId,\r
-                          Lba,\r
-                          WorkingBufferSize,\r
-                          WorkingBuffer\r
-                          );\r
-\r
-      if (EFI_ERROR (Status)) {\r
+    if (ALIGN_POINTER (BufferPtr, IoAlign) == BufferPtr) {\r
+      Subtask = DiskIoCreateSubtask (Write, Lba, 0, BufferSize, NULL, BufferPtr, Blocking);\r
+      if (Subtask == NULL) {\r
         goto Done;\r
       }\r
+      InsertTailList (Subtasks, &Subtask->Link);\r
 \r
-      WorkingBuffer += WorkingBufferSize;\r
+      BufferPtr  += BufferSize;\r
+      Offset     += BufferSize;\r
+      BufferSize -= BufferSize;\r
 \r
     } else {\r
-      //\r
-      // Use the allocated buffer instead of the original buffer\r
-      // to avoid alignment issue.\r
-      // Here, the allocated buffer (8-byte align) can satisfy the alignment\r
-      //\r
-      LastRead = FALSE;\r
-      do {\r
-        if (WorkingBufferSize <= DataBufferSize) {\r
+      if (Blocking) {\r
+        //\r
+        // Use the allocated buffer instead of the original buffer\r
+        // to avoid alignment issue.\r
+        //\r
+        for (; Lba < OverRunLba; Lba += DATA_BUFFER_BLOCK_NUM) {\r
+          DataBufferSize = MIN (BufferSize, DATA_BUFFER_BLOCK_NUM * BlockSize);\r
+\r
+          Subtask = DiskIoCreateSubtask (Write, Lba, 0, DataBufferSize, SharedWorkingBuffer, BufferPtr, Blocking);\r
+          if (Subtask == NULL) {\r
+            goto Done;\r
+          }\r
+          InsertTailList (Subtasks, &Subtask->Link);\r
+\r
+          BufferPtr  += DataBufferSize;\r
+          Offset     += DataBufferSize;\r
+          BufferSize -= DataBufferSize;\r
+        }\r
+      } else {\r
+        WorkingBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize), IoAlign);\r
+        if (WorkingBuffer == NULL) {\r
           //\r
-          // It is the last calling to readblocks in this loop\r
+          // If there is not enough memory, downgrade to blocking access\r
           //\r
-          DataBufferSize  = WorkingBufferSize;\r
-          LastRead        = TRUE;\r
-        }\r
-\r
-        Status = BlockIo->ReadBlocks (\r
-                            BlockIo,\r
-                            MediaId,\r
-                            Lba,\r
-                            DataBufferSize,\r
-                            Data\r
-                            );\r
-        if (EFI_ERROR (Status)) {\r
-          goto Done;\r
+          DEBUG ((EFI_D_VERBOSE, "DiskIo: No enough memory so downgrade to blocking access\n"));\r
+          if (!DiskIoCreateSubtaskList (Instance, Write, Offset, BufferSize, BufferPtr, TRUE, SharedWorkingBuffer, Subtasks)) {\r
+            goto Done;\r
+          }\r
+        } else {\r
+          Subtask = DiskIoCreateSubtask (Write, Lba, 0, BufferSize, WorkingBuffer, BufferPtr, Blocking);\r
+          if (Subtask == NULL) {\r
+            goto Done;\r
+          }\r
+          InsertTailList (Subtasks, &Subtask->Link);\r
         }\r
 \r
-        CopyMem (WorkingBuffer, Data, DataBufferSize);\r
-        WorkingBufferSize -= DataBufferSize;\r
-        WorkingBuffer += DataBufferSize;\r
-        Lba += DATA_BUFFER_BLOCK_NUM;\r
-      } while (!LastRead);\r
+        BufferPtr  += BufferSize;\r
+        Offset     += BufferSize;\r
+        BufferSize -= BufferSize;\r
+      }\r
     }\r
   }\r
 \r
-  if (!TransactionComplete && OverRun != 0) {\r
-    //\r
-    // Last read is not a complete block.\r
-    //\r
-    Status = BlockIo->ReadBlocks (\r
-                        BlockIo,\r
-                        MediaId,\r
-                        OverRunLba,\r
-                        BlockSize,\r
-                        Data\r
-                        );\r
+  ASSERT (BufferSize == 0);\r
 \r
-    if (EFI_ERROR (Status)) {\r
-      goto Done;\r
-    }\r
-\r
-    CopyMem (WorkingBuffer, Data, OverRun);\r
-  }\r
+  return TRUE;\r
 \r
 Done:\r
-  if (PreData != NULL) {\r
-    FreePool (PreData);\r
+  //\r
+  // Remove all the subtasks.\r
+  //\r
+  for (Link = GetFirstNode (Subtasks); !IsNull (Subtasks, Link); ) {\r
+    Subtask = CR (Link, DISK_IO_SUBTASK, Link, DISK_IO_SUBTASK_SIGNATURE);\r
+    Link = DiskIoDestroySubtask (Instance, Subtask);\r
   }\r
-\r
-  return Status;\r
+  return FALSE;\r
 }\r
 \r
-\r
 /**\r
-  Writes BufferSize bytes from Buffer into Offset.\r
-  Writes may require a read modify write to support writes that are not\r
-  aligned on sector boundaries. There are three cases:\r
-    UnderRun - The first byte is not on a sector boundary or the write request\r
-               is less than a sector in length. Read modify write is required.\r
-    Aligned  - A write of N contiguous sectors.\r
-    OverRun  - The last byte is not on a sector boundary. Read modified write\r
-               required.\r
+  Terminate outstanding asynchronous requests to a device.\r
 \r
-  @param  This       Protocol instance pointer.\r
-  @param  MediaId    Id of the media, changes every time the media is replaced.\r
-  @param  Offset     The starting byte offset to read from\r
-  @param  BufferSize Size of Buffer\r
-  @param  Buffer     Buffer containing read data\r
-\r
-  @retval EFI_SUCCESS           The data was written correctly to the device.\r
-  @retval EFI_WRITE_PROTECTED   The device can not be written to.\r
-  @retval EFI_DEVICE_ERROR      The device reported an error while performing the write.\r
-  @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_INVALID_PARAMETER The write request contains device addresses that are not\r
-                                 valid for the device.\r
+  @param This                   Indicates a pointer to the calling context.\r
 \r
+  @retval EFI_SUCCESS           All outstanding requests were successfully terminated.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error while performing the cancel\r
+                                operation.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-DiskIoWriteDisk (\r
-  IN EFI_DISK_IO_PROTOCOL  *This,\r
-  IN UINT32                MediaId,\r
-  IN UINT64                Offset,\r
-  IN UINTN                 BufferSize,\r
-  IN VOID                  *Buffer\r
+DiskIo2Cancel (\r
+  IN EFI_DISK_IO2_PROTOCOL *This\r
   )\r
 {\r
-  EFI_STATUS            Status;\r
-  DISK_IO_PRIVATE_DATA  *Private;\r
-  EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
-  EFI_BLOCK_IO_MEDIA    *Media;\r
-  UINT32                BlockSize;\r
-  UINT64                Lba;\r
-  UINT64                OverRunLba;\r
-  UINT32                UnderRun;\r
-  UINT32                OverRun;\r
-  BOOLEAN               TransactionComplete;\r
-  UINTN                 WorkingBufferSize;\r
-  UINT8                 *WorkingBuffer;\r
-  UINTN                 Length;\r
-  UINT8                 *Data;\r
-  UINT8                 *PreData;\r
-  UINTN                 IsBufferAligned;\r
-  UINTN                 DataBufferSize;\r
-  BOOLEAN               LastWrite;\r
+  DISK_IO_PRIVATE_DATA  *Instance;\r
+  DISK_IO2_TASK         *Task;\r
+  LIST_ENTRY            *Link;\r
+  \r
+  Instance = DISK_IO_PRIVATE_DATA_FROM_DISK_IO2 (This);\r
 \r
-  Private   = DISK_IO_PRIVATE_DATA_FROM_THIS (This);\r
+  EfiAcquireLock (&Instance->TaskQueueLock);\r
 \r
-  BlockIo   = Private->BlockIo;\r
-  Media     = BlockIo->Media;\r
-  BlockSize = Media->BlockSize;\r
+  for (Link = GetFirstNode (&Instance->TaskQueue)\r
+    ; !IsNull (&Instance->TaskQueue, Link)\r
+    ; Link = GetNextNode (&Instance->TaskQueue, Link)\r
+    ) {\r
+    Task = CR (Link, DISK_IO2_TASK, Link, DISK_IO2_TASK_SIGNATURE);\r
 \r
-  if (Media->ReadOnly) {\r
-    return EFI_WRITE_PROTECTED;\r
+    if (Task->Token != NULL) {\r
+      Task->Token->TransactionStatus = EFI_ABORTED;\r
+      gBS->SignalEvent (Task->Token->Event);\r
+      //\r
+      // Set Token to NULL so that the further BlockIo2 responses will be ignored\r
+      //\r
+      Task->Token = NULL;\r
+    }\r
   }\r
 \r
-  if (Media->MediaId != MediaId) {\r
-    return EFI_MEDIA_CHANGED;\r
-  }\r
+  EfiReleaseLock (&Instance->TaskQueueLock);\r
 \r
-  DataBufferSize = BlockSize * DATA_BUFFER_BLOCK_NUM;\r
+  return EFI_SUCCESS;\r
+}\r
 \r
-  if (Media->IoAlign > 1) {\r
-    PreData = AllocatePool (DataBufferSize + Media->IoAlign);\r
-    Data    = PreData - ((UINTN) PreData & (Media->IoAlign - 1)) + Media->IoAlign;\r
-  } else {\r
-    PreData = AllocatePool (DataBufferSize);\r
-    Data    = PreData;\r
-  }\r
+/**\r
+  Common routine to access the disk.\r
+\r
+  @param Instance    Pointer to the DISK_IO_PRIVATE_DATA.\r
+  @param Write       TRUE: Write operation; FALSE: Read operation.\r
+  @param MediaId     ID of the medium to access.\r
+  @param Offset      The starting byte offset on the logical block I/O device to access.\r
+  @param Token       A pointer to the token associated with the transaction.\r
+                     If this field is NULL, synchronous/blocking IO is performed.\r
+  @param  BufferSize            The size in bytes of Buffer. The number of bytes to read from the device.\r
+  @param  Buffer                A pointer to the destination buffer for the data.\r
+                                The caller is responsible either having implicit or explicit ownership of the buffer. \r
+**/\r
+EFI_STATUS\r
+DiskIo2ReadWriteDisk (\r
+  IN DISK_IO_PRIVATE_DATA     *Instance,\r
+  IN BOOLEAN                  Write,\r
+  IN UINT32                   MediaId,\r
+  IN UINT64                   Offset,\r
+  IN EFI_DISK_IO2_TOKEN       *Token,\r
+  IN UINTN                    BufferSize,\r
+  IN UINT8                    *Buffer\r
+  )\r
+{\r
+  EFI_STATUS             Status;\r
+  EFI_BLOCK_IO_PROTOCOL  *BlockIo;\r
+  EFI_BLOCK_IO2_PROTOCOL *BlockIo2;\r
+  EFI_BLOCK_IO_MEDIA     *Media;\r
+  LIST_ENTRY             *Link;\r
+  LIST_ENTRY             Subtasks;\r
+  DISK_IO_SUBTASK        *Subtask;\r
+  DISK_IO2_TASK          *Task;\r
+  BOOLEAN                TaskQueueEmpty;\r
+  EFI_TPL                OldTpl;\r
+  BOOLEAN                Blocking;\r
+  LIST_ENTRY             *SubtasksPtr;\r
+\r
+  Task      = NULL;\r
+  BlockIo   = Instance->BlockIo;\r
+  BlockIo2  = Instance->BlockIo2;\r
+  Media     = BlockIo->Media;\r
+  Status    = EFI_SUCCESS;\r
+  Blocking  = ((Token == NULL) || (Token->Event == NULL));\r
 \r
-  if (PreData == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
+  if (Media->MediaId != MediaId) {\r
+    return EFI_MEDIA_CHANGED;\r
   }\r
-\r
-  WorkingBuffer       = Buffer;\r
-  WorkingBufferSize   = BufferSize;\r
-\r
-  Lba                 = DivU64x32Remainder (Offset, BlockSize, &UnderRun);\r
-\r
-  Length              = BlockSize - UnderRun;\r
-  TransactionComplete = FALSE;\r
-\r
-  Status              = EFI_SUCCESS;\r
-  if (UnderRun != 0) {\r
+  \r
+  if (Write && Media->ReadOnly) {\r
+    return EFI_WRITE_PROTECTED;\r
+  }\r
+  \r
+  if (Blocking) {\r
     //\r
-    // Offset starts in the middle of an Lba, so do read modify write.\r
+    // Wait till pending async task is completed.\r
     //\r
-    Status = BlockIo->ReadBlocks (\r
-                        BlockIo,\r
-                        MediaId,\r
-                        Lba,\r
-                        BlockSize,\r
-                        Data\r
-                        );\r
+    do {\r
+      EfiAcquireLock (&Instance->TaskQueueLock);\r
+      TaskQueueEmpty = IsListEmpty (&Instance->TaskQueue);\r
+      EfiReleaseLock (&Instance->TaskQueueLock);\r
+    } while (!TaskQueueEmpty);\r
 \r
-    if (EFI_ERROR (Status)) {\r
-      goto Done;\r
-    }\r
-\r
-    if (Length > BufferSize) {\r
-      Length              = BufferSize;\r
-      TransactionComplete = TRUE;\r
+    SubtasksPtr = &Subtasks;\r
+  } else {\r
+    Task = AllocatePool (sizeof (DISK_IO2_TASK));\r
+    if (Task == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
     }\r
+    \r
+    EfiAcquireLock (&Instance->TaskQueueLock);\r
+    InsertTailList (&Instance->TaskQueue, &Task->Link);\r
+    EfiReleaseLock (&Instance->TaskQueueLock);\r
 \r
-    CopyMem (Data + UnderRun, WorkingBuffer, Length);\r
+    Task->Signature = DISK_IO2_TASK_SIGNATURE;\r
+    Task->Instance  = Instance;\r
+    Task->Token     = Token;\r
 \r
-    Status = BlockIo->WriteBlocks (\r
-                        BlockIo,\r
-                        MediaId,\r
-                        Lba,\r
-                        BlockSize,\r
-                        Data\r
-                        );\r
-    if (EFI_ERROR (Status)) {\r
-      goto Done;\r
-    }\r
+    SubtasksPtr = &Task->Subtasks;\r
+  }\r
 \r
-    WorkingBuffer += Length;\r
-    WorkingBufferSize -= Length;\r
-    if (WorkingBufferSize == 0) {\r
-      goto Done;\r
+  InitializeListHead (SubtasksPtr);\r
+  if (!DiskIoCreateSubtaskList (Instance, Write, Offset, BufferSize, Buffer, Blocking, Instance->SharedWorkingBuffer, SubtasksPtr)) {\r
+    if (Task != NULL) {\r
+      FreePool (Task);\r
     }\r
-\r
-    Lba += 1;\r
+    return EFI_OUT_OF_RESOURCES;\r
   }\r
+  ASSERT (!IsListEmpty (SubtasksPtr));\r
 \r
-  OverRunLba = Lba + DivU64x32Remainder (WorkingBufferSize, BlockSize, &OverRun);\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+  for (Link = GetFirstNode (SubtasksPtr); !IsNull (SubtasksPtr, Link); Link = GetNextNode (SubtasksPtr, Link)) {\r
+    Subtask = CR (Link, DISK_IO_SUBTASK, Link, DISK_IO_SUBTASK_SIGNATURE);\r
 \r
-  if (!TransactionComplete && WorkingBufferSize >= BlockSize) {\r
-    //\r
-    // If the DiskIo maps directly to a BlockIo device do the write.\r
-    //\r
-    if (OverRun != 0) {\r
-      WorkingBufferSize -= OverRun;\r
+    if (!Subtask->Blocking) {\r
+      Subtask->Task = Task;\r
     }\r
-    //\r
-    // Check buffer alignment\r
-    //\r
-    IsBufferAligned = (UINTN) WorkingBuffer & (UINTN) (Media->IoAlign - 1);\r
 \r
-    if (Media->IoAlign <= 1 || IsBufferAligned == 0) {\r
+    if (Subtask->Write) {\r
       //\r
-      // Alignment is satisfied, so write them together\r
+      // Write\r
       //\r
-      Status = BlockIo->WriteBlocks (\r
-                          BlockIo,\r
-                          MediaId,\r
-                          Lba,\r
-                          WorkingBufferSize,\r
-                          WorkingBuffer\r
-                          );\r
-\r
-      if (EFI_ERROR (Status)) {\r
-        goto Done;\r
+      if (Subtask->WorkingBuffer != NULL) {\r
+        //\r
+        // A sub task before this one should be a block read operation, causing the WorkingBuffer filled with the entire one block data.\r
+        //\r
+        CopyMem (Subtask->WorkingBuffer + Subtask->Offset, Subtask->Buffer, Subtask->Length);\r
       }\r
 \r
-      WorkingBuffer += WorkingBufferSize;\r
+      if (Subtask->Blocking) {\r
+        Status = BlockIo->WriteBlocks (\r
+                            BlockIo,\r
+                            MediaId,\r
+                            Subtask->Lba,\r
+                            Subtask->Length < Media->BlockSize ? Media->BlockSize : Subtask->Length,\r
+                            (Subtask->WorkingBuffer != NULL) ? Subtask->WorkingBuffer : Subtask->Buffer\r
+                            );\r
+      } else {\r
+        Status = BlockIo2->WriteBlocksEx (\r
+                             BlockIo2,\r
+                             MediaId,\r
+                             Subtask->Lba,\r
+                             &Subtask->BlockIo2Token,\r
+                             Subtask->Length < Media->BlockSize ? Media->BlockSize : Subtask->Length,\r
+                             (Subtask->WorkingBuffer != NULL) ? Subtask->WorkingBuffer : Subtask->Buffer\r
+                             );\r
+      }\r
 \r
     } else {\r
       //\r
-      // The buffer parameter is not aligned with the request\r
-      // So use the allocated instead.\r
-      // It can fit almost all the cases.\r
+      // Read\r
       //\r
-      LastWrite = FALSE;\r
-      do {\r
-        if (WorkingBufferSize <= DataBufferSize) {\r
-          //\r
-          // It is the last calling to writeblocks in this loop\r
-          //\r
-          DataBufferSize  = WorkingBufferSize;\r
-          LastWrite       = TRUE;\r
-        }\r
-\r
-        CopyMem (Data, WorkingBuffer, DataBufferSize);\r
-        Status = BlockIo->WriteBlocks (\r
+      if (Subtask->Blocking) {\r
+        Status = BlockIo->ReadBlocks (\r
                             BlockIo,\r
                             MediaId,\r
-                            Lba,\r
-                            DataBufferSize,\r
-                            Data\r
+                            Subtask->Lba,\r
+                            Subtask->Length < Media->BlockSize ? Media->BlockSize : Subtask->Length,\r
+                            (Subtask->WorkingBuffer != NULL) ? Subtask->WorkingBuffer : Subtask->Buffer\r
                             );\r
-        if (EFI_ERROR (Status)) {\r
-          goto Done;\r
+        if (!EFI_ERROR (Status) && (Subtask->WorkingBuffer != NULL)) {\r
+          CopyMem (Subtask->Buffer, Subtask->WorkingBuffer + Subtask->Offset, Subtask->Length);\r
         }\r
-\r
-        WorkingBufferSize -= DataBufferSize;\r
-        WorkingBuffer += DataBufferSize;\r
-        Lba += DATA_BUFFER_BLOCK_NUM;\r
-      } while (!LastWrite);\r
+      } else {\r
+        Status = BlockIo2->ReadBlocksEx (\r
+                             BlockIo2,\r
+                             MediaId,\r
+                             Subtask->Lba,\r
+                             &Subtask->BlockIo2Token,\r
+                             Subtask->Length < Media->BlockSize ? Media->BlockSize : Subtask->Length,\r
+                             (Subtask->WorkingBuffer != NULL) ? Subtask->WorkingBuffer : Subtask->Buffer\r
+                             );\r
+      }\r
+    }\r
+    \r
+    if (EFI_ERROR (Status)) {\r
+      break;\r
     }\r
   }\r
+  \r
+  gBS->RaiseTPL (TPL_NOTIFY);\r
 \r
-  if (!TransactionComplete && OverRun != 0) {\r
-    //\r
-    // Last bit is not a complete block, so do a read modify write.\r
-    //\r
-    Status = BlockIo->ReadBlocks (\r
-                        BlockIo,\r
-                        MediaId,\r
-                        OverRunLba,\r
-                        BlockSize,\r
-                        Data\r
-                        );\r
+  //\r
+  // Remove all the remaining subtasks when failure.\r
+  // We shouldn't remove all the tasks because the non-blocking requests have been submitted and cannot be canceled.\r
+  //\r
+  if (EFI_ERROR (Status)) {\r
+    while (!IsNull (SubtasksPtr, Link)) {\r
+      Subtask = CR (Link, DISK_IO_SUBTASK, Link, DISK_IO_SUBTASK_SIGNATURE);\r
+      Link = DiskIoDestroySubtask (Instance, Subtask);\r
+    }\r
+  }\r
 \r
-    if (EFI_ERROR (Status)) {\r
-      goto Done;\r
+  //\r
+  // Remove all the blocking subtasks because the non-blocking callback only removes the non-blocking subtask.\r
+  //\r
+  for (Link = GetFirstNode (SubtasksPtr); !IsNull (SubtasksPtr, Link); ) {\r
+    Subtask = CR (Link, DISK_IO_SUBTASK, Link, DISK_IO_SUBTASK_SIGNATURE);\r
+    if (Subtask->Blocking) {\r
+      Link = DiskIoDestroySubtask (Instance, Subtask);\r
+    } else {\r
+      Link = GetNextNode (SubtasksPtr, Link);\r
     }\r
+  }\r
 \r
-    CopyMem (Data, WorkingBuffer, OverRun);\r
+  //\r
+  // It's possible that the callback runs before raising TPL to NOTIFY,\r
+  // so the subtasks list only contains blocking subtask.\r
+  // Remove the Task after the blocking subtasks are removed in above.\r
+  //\r
+  if (!Blocking && IsListEmpty (SubtasksPtr)) {\r
+    EfiAcquireLock (&Instance->TaskQueueLock);\r
+    RemoveEntryList (&Task->Link);\r
+    EfiReleaseLock (&Instance->TaskQueueLock);\r
 \r
-    Status = BlockIo->WriteBlocks (\r
-                        BlockIo,\r
-                        MediaId,\r
-                        OverRunLba,\r
-                        BlockSize,\r
-                        Data\r
-                        );\r
-    if (EFI_ERROR (Status)) {\r
-      goto Done;\r
+    if (Task->Token != NULL) {\r
+      //\r
+      // Task->Token should be set to NULL by the DiskIo2OnReadWriteComplete\r
+      // It it's not, that means the non-blocking request was downgraded to blocking request.\r
+      //\r
+      DEBUG ((EFI_D_VERBOSE, "DiskIo: Non-blocking request was downgraded to blocking request, signal event directly.\n"));\r
+      Task->Token->TransactionStatus = Status;\r
+      gBS->SignalEvent (Task->Token->Event);\r
     }\r
+\r
+    FreePool (Task);\r
   }\r
 \r
-Done:\r
-  if (PreData != NULL) {\r
-    FreePool (PreData);\r
+  gBS->RestoreTPL (OldTpl);\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Reads a specified number of bytes from a device.\r
+\r
+  @param This                   Indicates a pointer to the calling context.\r
+  @param MediaId                ID of the medium to be read.\r
+  @param Offset                 The starting byte offset on the logical block I/O device to read from.\r
+  @param Token                  A pointer to the token associated with the transaction.\r
+                                If this field is NULL, synchronous/blocking IO is performed.\r
+  @param  BufferSize            The size in bytes of Buffer. The number of bytes to read from the device.\r
+  @param  Buffer                A pointer to the destination buffer for the data.\r
+                                The caller is responsible either having implicit or explicit ownership of the buffer.\r
+\r
+  @retval EFI_SUCCESS           If Event is NULL (blocking I/O): The data was read correctly from the device.\r
+                                If Event is not NULL (asynchronous I/O): The request was successfully queued for processing.\r
+                                                                         Event will be signaled upon completion.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error while performing the write.\r
+  @retval EFI_NO_MEDIA          There is no medium in the device.\r
+  @retval EFI_MEDIA_CHNAGED     The MediaId is not for the current medium.\r
+  @retval EFI_INVALID_PARAMETER The read request contains device addresses that are not valid for the device.\r
+  @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack of resources.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DiskIo2ReadDiskEx (\r
+  IN EFI_DISK_IO2_PROTOCOL        *This,\r
+  IN UINT32                       MediaId,\r
+  IN UINT64                       Offset,\r
+  IN OUT EFI_DISK_IO2_TOKEN       *Token,\r
+  IN UINTN                        BufferSize,\r
+  OUT VOID                        *Buffer\r
+  )\r
+{\r
+  return DiskIo2ReadWriteDisk (\r
+           DISK_IO_PRIVATE_DATA_FROM_DISK_IO2 (This),\r
+           FALSE, MediaId, Offset, Token, BufferSize, (UINT8 *) Buffer\r
+           );\r
+}\r
+\r
+/**\r
+  Writes a specified number of bytes to a device.\r
+\r
+  @param This        Indicates a pointer to the calling context.\r
+  @param MediaId     ID of the medium to be written.\r
+  @param Offset      The starting byte offset on the logical block I/O device to write to.\r
+  @param Token       A pointer to the token associated with the transaction.\r
+                     If this field is NULL, synchronous/blocking IO is performed.\r
+  @param BufferSize  The size in bytes of Buffer. The number of bytes to write to the device.\r
+  @param Buffer      A pointer to the buffer containing the data to be written.\r
+\r
+  @retval EFI_SUCCESS           If Event is NULL (blocking I/O): The data was written correctly to the device.\r
+                                If Event is not NULL (asynchronous I/O): The request was successfully queued for processing.\r
+                                                                         Event will be signaled upon completion.\r
+  @retval EFI_WRITE_PROTECTED   The device cannot be written to.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error while performing the write operation.\r
+  @retval EFI_NO_MEDIA          There is no medium in the device.\r
+  @retval EFI_MEDIA_CHNAGED     The MediaId is not for the current medium.\r
+  @retval EFI_INVALID_PARAMETER The write request contains device addresses that are not valid for the device.\r
+  @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack of resources.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DiskIo2WriteDiskEx (\r
+  IN EFI_DISK_IO2_PROTOCOL        *This,\r
+  IN UINT32                       MediaId,\r
+  IN UINT64                       Offset,\r
+  IN OUT EFI_DISK_IO2_TOKEN       *Token,\r
+  IN UINTN                        BufferSize,\r
+  IN VOID                         *Buffer\r
+  )\r
+{\r
+  return DiskIo2ReadWriteDisk (\r
+           DISK_IO_PRIVATE_DATA_FROM_DISK_IO2 (This),\r
+           TRUE, MediaId, Offset, Token, BufferSize, (UINT8 *) Buffer\r
+           );\r
+}\r
+\r
+/**\r
+  The callback for the BlockIo2 FlushBlocksEx.\r
+  @param  Event                 Event whose notification function is being invoked.\r
+  @param  Context               The pointer to the notification function's context,\r
+                                which points to the DISK_IO2_FLUSH_TASK instance.\r
+**/\r
+VOID\r
+EFIAPI\r
+DiskIo2OnFlushComplete (\r
+  IN EFI_EVENT                 Event,\r
+  IN VOID                      *Context\r
+  )\r
+{\r
+  DISK_IO2_FLUSH_TASK             *Task;\r
+\r
+  gBS->CloseEvent (Event);\r
+\r
+  Task = (DISK_IO2_FLUSH_TASK *) Context;\r
+  ASSERT (Task->Signature == DISK_IO2_FLUSH_TASK_SIGNATURE);\r
+  Task->Token->TransactionStatus = Task->BlockIo2Token.TransactionStatus;\r
+  gBS->SignalEvent (Task->Token->Event);\r
+}\r
+\r
+/**\r
+  Flushes all modified data to the physical device.\r
+\r
+  @param This        Indicates a pointer to the calling context.\r
+  @param Token       A pointer to the token associated with the transaction.\r
+                     If this field is NULL, synchronous/blocking IO is performed.\r
+\r
+  @retval EFI_SUCCESS           If Event is NULL (blocking I/O): The data was flushed successfully to the device.\r
+                                If Event is not NULL (asynchronous I/O): The request was successfully queued for processing.\r
+                                                                         Event will be signaled upon completion.\r
+  @retval EFI_WRITE_PROTECTED   The device cannot be written to.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error while performing the write operation.\r
+  @retval EFI_NO_MEDIA          There is no medium in the device.\r
+  @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack of resources.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DiskIo2FlushDiskEx (\r
+  IN EFI_DISK_IO2_PROTOCOL        *This,\r
+  IN OUT EFI_DISK_IO2_TOKEN       *Token\r
+  )\r
+{\r
+  EFI_STATUS                      Status;\r
+  DISK_IO2_FLUSH_TASK             *Task;\r
+  DISK_IO_PRIVATE_DATA            *Private;\r
+\r
+  Private = DISK_IO_PRIVATE_DATA_FROM_DISK_IO2 (This);\r
+\r
+  if ((Token != NULL) && (Token->Event != NULL)) {\r
+    Task = AllocatePool (sizeof (DISK_IO2_FLUSH_TASK));\r
+    if (Task == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+\r
+    Status = gBS->CreateEvent (\r
+                    EVT_NOTIFY_SIGNAL,\r
+                    TPL_CALLBACK,\r
+                    DiskIo2OnFlushComplete,\r
+                    Task,\r
+                    &Task->BlockIo2Token.Event\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      FreePool (Task);\r
+      return Status;\r
+    }\r
+    Task->Signature = DISK_IO2_FLUSH_TASK_SIGNATURE;\r
+    Status = Private->BlockIo2->FlushBlocksEx (Private->BlockIo2, &Task->BlockIo2Token);\r
+    if (EFI_ERROR (Status)) {\r
+      gBS->CloseEvent (Task->BlockIo2Token.Event);\r
+      FreePool (Task);\r
+    }\r
+  } else {\r
+    Status = Private->BlockIo2->FlushBlocksEx (Private->BlockIo2, NULL);\r
   }\r
 \r
   return Status;\r
 }\r
 \r
+/**\r
+  Read BufferSize bytes from Offset into Buffer.\r
+  Reads may support reads that are not aligned on\r
+  sector boundaries. There are three cases:\r
+    UnderRun - The first byte is not on a sector boundary or the read request is\r
+               less than a sector in length.\r
+    Aligned  - A read of N contiguous sectors.\r
+    OverRun  - The last byte is not on a sector boundary.\r
+\r
+  @param  This                  Protocol instance pointer.\r
+  @param  MediaId               Id of the media, changes every time the media is replaced.\r
+  @param  Offset                The starting byte offset to read from\r
+  @param  BufferSize            Size of Buffer\r
+  @param  Buffer                Buffer containing read data\r
+\r
+  @retval EFI_SUCCESS           The data was read correctly from the device.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error while performing the read.\r
+  @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_INVALID_PARAMETER The read request contains device addresses that are not\r
+                                valid for the device.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DiskIoReadDisk (\r
+  IN EFI_DISK_IO_PROTOCOL  *This,\r
+  IN UINT32                MediaId,\r
+  IN UINT64                Offset,\r
+  IN UINTN                 BufferSize,\r
+  OUT VOID                 *Buffer\r
+  )\r
+{\r
+  return DiskIo2ReadWriteDisk (\r
+           DISK_IO_PRIVATE_DATA_FROM_DISK_IO (This),\r
+           FALSE, MediaId, Offset, NULL, BufferSize, (UINT8 *) Buffer\r
+           );\r
+}\r
+\r
+\r
+/**\r
+  Writes BufferSize bytes from Buffer into Offset.\r
+  Writes may require a read modify write to support writes that are not\r
+  aligned on sector boundaries. There are three cases:\r
+    UnderRun - The first byte is not on a sector boundary or the write request\r
+               is less than a sector in length. Read modify write is required.\r
+    Aligned  - A write of N contiguous sectors.\r
+    OverRun  - The last byte is not on a sector boundary. Read modified write\r
+               required.\r
+\r
+  @param  This       Protocol instance pointer.\r
+  @param  MediaId    Id of the media, changes every time the media is replaced.\r
+  @param  Offset     The starting byte offset to read from\r
+  @param  BufferSize Size of Buffer\r
+  @param  Buffer     Buffer containing read data\r
+\r
+  @retval EFI_SUCCESS           The data was written correctly to the device.\r
+  @retval EFI_WRITE_PROTECTED   The device can not be written to.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error while performing the write.\r
+  @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_INVALID_PARAMETER The write request contains device addresses that are not\r
+                                 valid for the device.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DiskIoWriteDisk (\r
+  IN EFI_DISK_IO_PROTOCOL  *This,\r
+  IN UINT32                MediaId,\r
+  IN UINT64                Offset,\r
+  IN UINTN                 BufferSize,\r
+  IN VOID                  *Buffer\r
+  )\r
+{\r
+  return DiskIo2ReadWriteDisk (\r
+           DISK_IO_PRIVATE_DATA_FROM_DISK_IO (This),\r
+           TRUE, MediaId, Offset, NULL, BufferSize, (UINT8 *) Buffer\r
+           );\r
+}\r
 \r
 /**\r
   The user Entry Point for module DiskIo. The user code starts with this function.\r
@@ -740,7 +1253,5 @@ InitializeDiskIo (
              );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-\r
   return Status;\r
 }\r
-\r
index 77f6dbf89d398600b4a0fbdb5e96d704a6b4efc5..a08d4df799d33f4eae41ddab06d2c758febfe820 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Master header file for DiskIo driver. It includes the module private defininitions.\r
 \r
-Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2013, 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
@@ -17,6 +17,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include <Uefi.h>\r
 #include <Protocol/BlockIo.h>\r
+#include <Protocol/BlockIo2.h>\r
+#include <Protocol/DiskIo2.h>\r
 #include <Protocol/ComponentName.h>\r
 #include <Protocol/DriverBinding.h>\r
 #include <Protocol/DiskIo.h>\r
@@ -28,18 +30,69 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
 \r
-\r
+//\r
+// Pre-allocate an aligned buffer of 64 blocks so very large Disk I/O requests\r
+// will be broken up into 64 * BlockSize chunks to provide better performance\r
+// than allocating an aligned 1 block buffer.\r
+//\r
 #define DATA_BUFFER_BLOCK_NUM             64\r
 \r
 #define DISK_IO_PRIVATE_DATA_SIGNATURE  SIGNATURE_32 ('d', 's', 'k', 'I')\r
-\r
 typedef struct {\r
-  UINTN                 Signature;\r
-  EFI_DISK_IO_PROTOCOL  DiskIo;\r
-  EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
+  UINT32                          Signature;\r
+\r
+  EFI_DISK_IO_PROTOCOL            DiskIo;\r
+  EFI_DISK_IO2_PROTOCOL           DiskIo2;\r
+  EFI_BLOCK_IO_PROTOCOL           *BlockIo;\r
+  EFI_BLOCK_IO2_PROTOCOL          *BlockIo2;\r
+\r
+  UINT8                           *SharedWorkingBuffer;\r
+\r
+  EFI_LOCK                        TaskQueueLock;\r
+  LIST_ENTRY                      TaskQueue;\r
 } DISK_IO_PRIVATE_DATA;\r
+#define DISK_IO_PRIVATE_DATA_FROM_DISK_IO(a)  CR (a, DISK_IO_PRIVATE_DATA, DiskIo,  DISK_IO_PRIVATE_DATA_SIGNATURE)\r
+#define DISK_IO_PRIVATE_DATA_FROM_DISK_IO2(a) CR (a, DISK_IO_PRIVATE_DATA, DiskIo2, DISK_IO_PRIVATE_DATA_SIGNATURE)\r
 \r
-#define DISK_IO_PRIVATE_DATA_FROM_THIS(a) CR (a, DISK_IO_PRIVATE_DATA, DiskIo, DISK_IO_PRIVATE_DATA_SIGNATURE)\r
+#define DISK_IO2_TASK_SIGNATURE   SIGNATURE_32 ('d', 'i', 'a', 't')\r
+typedef struct {\r
+  UINT32                          Signature;\r
+  LIST_ENTRY                      Link;     /// < link to other task\r
+  LIST_ENTRY                      Subtasks; /// < header of subtasks\r
+  EFI_DISK_IO2_TOKEN              *Token;\r
+  DISK_IO_PRIVATE_DATA            *Instance;\r
+} DISK_IO2_TASK;\r
+\r
+#define DISK_IO2_FLUSH_TASK_SIGNATURE SIGNATURE_32 ('d', 'i', 'f', 't')\r
+typedef struct {\r
+  UINT32                          Signature;\r
+  EFI_BLOCK_IO2_TOKEN             BlockIo2Token;\r
+  EFI_DISK_IO2_TOKEN              *Token;\r
+} DISK_IO2_FLUSH_TASK;\r
+\r
+#define DISK_IO_SUBTASK_SIGNATURE SIGNATURE_32 ('d', 'i', 's', 't')\r
+typedef struct {\r
+  //\r
+  // UnderRun:  Offset != 0, Length < BlockSize\r
+  // OverRun:   Offset == 0, Length < BlockSize\r
+  // Middle:    Offset is block aligned, Length is multiple of block size\r
+  //\r
+  UINT32                          Signature;\r
+  LIST_ENTRY                      Link;\r
+  BOOLEAN                         Write;\r
+  UINT64                          Lba;\r
+  UINT32                          Offset;\r
+  UINTN                           Length;\r
+  UINT8                           *WorkingBuffer; /// < NULL indicates using "Buffer" directly\r
+  UINT8                           *Buffer;\r
+  BOOLEAN                         Blocking;\r
+\r
+  //\r
+  // Following fields are for DiskIo2\r
+  //\r
+  DISK_IO2_TASK                   *Task;\r
+  EFI_BLOCK_IO2_TOKEN             BlockIo2Token;\r
+} DISK_IO_SUBTASK;\r
 \r
 //\r
 // Global Variables\r
@@ -189,6 +242,110 @@ DiskIoWriteDisk (
   IN VOID                  *Buffer\r
   );\r
 \r
+\r
+/**\r
+  Terminate outstanding asynchronous requests to a device.\r
+\r
+  @param This                   Indicates a pointer to the calling context.\r
+\r
+  @retval EFI_SUCCESS           All outstanding requests were successfully terminated.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error while performing the cancel\r
+                                operation.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DiskIo2Cancel (\r
+  IN EFI_DISK_IO2_PROTOCOL *This\r
+  );\r
+\r
+/**\r
+  Reads a specified number of bytes from a device.\r
+\r
+  @param This                   Indicates a pointer to the calling context.\r
+  @param MediaId                ID of the medium to be read.\r
+  @param Offset                 The starting byte offset on the logical block I/O device to read from.\r
+  @param Token                  A pointer to the token associated with the transaction.\r
+                                If this field is NULL, synchronous/blocking IO is performed.\r
+  @param  BufferSize            The size in bytes of Buffer. The number of bytes to read from the device.\r
+  @param  Buffer                A pointer to the destination buffer for the data.\r
+                                The caller is responsible either having implicit or explicit ownership of the buffer.\r
+\r
+  @retval EFI_SUCCESS           If Event is NULL (blocking I/O): The data was read correctly from the device.\r
+                                If Event is not NULL (asynchronous I/O): The request was successfully queued for processing.\r
+                                                                         Event will be signaled upon completion.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error while performing the write.\r
+  @retval EFI_NO_MEDIA          There is no medium in the device.\r
+  @retval EFI_MEDIA_CHNAGED     The MediaId is not for the current medium.\r
+  @retval EFI_INVALID_PARAMETER The read request contains device addresses that are not valid for the device.\r
+  @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack of resources.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DiskIo2ReadDiskEx (\r
+  IN EFI_DISK_IO2_PROTOCOL        *This,\r
+  IN UINT32                       MediaId,\r
+  IN UINT64                       Offset,\r
+  IN OUT EFI_DISK_IO2_TOKEN       *Token,\r
+  IN UINTN                        BufferSize,\r
+  OUT VOID                        *Buffer\r
+  );\r
+\r
+/**\r
+  Writes a specified number of bytes to a device.\r
+\r
+  @param This        Indicates a pointer to the calling context.\r
+  @param MediaId     ID of the medium to be written.\r
+  @param Offset      The starting byte offset on the logical block I/O device to write to.\r
+  @param Token       A pointer to the token associated with the transaction.\r
+                     If this field is NULL, synchronous/blocking IO is performed.\r
+  @param BufferSize  The size in bytes of Buffer. The number of bytes to write to the device.\r
+  @param Buffer      A pointer to the buffer containing the data to be written.\r
+\r
+  @retval EFI_SUCCESS           If Event is NULL (blocking I/O): The data was written correctly to the device.\r
+                                If Event is not NULL (asynchronous I/O): The request was successfully queued for processing.\r
+                                                                         Event will be signaled upon completion.\r
+  @retval EFI_WRITE_PROTECTED   The device cannot be written to.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error while performing the write operation.\r
+  @retval EFI_NO_MEDIA          There is no medium in the device.\r
+  @retval EFI_MEDIA_CHNAGED     The MediaId is not for the current medium.\r
+  @retval EFI_INVALID_PARAMETER The write request contains device addresses that are not valid for the device.\r
+  @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack of resources.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DiskIo2WriteDiskEx (\r
+  IN EFI_DISK_IO2_PROTOCOL        *This,\r
+  IN UINT32                       MediaId,\r
+  IN UINT64                       Offset,\r
+  IN EFI_DISK_IO2_TOKEN           *Token,\r
+  IN UINTN                        BufferSize,\r
+  IN VOID                         *Buffer\r
+  );\r
+\r
+/**\r
+  Flushes all modified data to the physical device.\r
+\r
+  @param This        Indicates a pointer to the calling context.\r
+  @param Token       A pointer to the token associated with the transaction.\r
+                     If this field is NULL, synchronous/blocking IO is performed.\r
+\r
+  @retval EFI_SUCCESS           If Event is NULL (blocking I/O): The data was flushed successfully to the device.\r
+                                If Event is not NULL (asynchronous I/O): The request was successfully queued for processing.\r
+                                                                         Event will be signaled upon completion.\r
+  @retval EFI_WRITE_PROTECTED   The device cannot be written to.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error while performing the write operation.\r
+  @retval EFI_NO_MEDIA          There is no medium in the device.\r
+  @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack of resources.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DiskIo2FlushDiskEx (\r
+  IN EFI_DISK_IO2_PROTOCOL        *This,\r
+  IN OUT EFI_DISK_IO2_TOKEN       *Token\r
+  );\r
+\r
 //\r
 // EFI Component Name Functions\r
 //\r
index 1a270e7f982e53a52103b94ae2df99ddab71ef55..8cf2595dfaba19442c11daa0169468c3086dbf94 100644 (file)
@@ -8,7 +8,7 @@
 #  already have a Disk I/O protocol. File systems and other disk access\r
 #  code utilize the Disk I/O protocol.\r
 #  \r
-#  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2006 - 2013, 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
@@ -59,5 +59,7 @@
 \r
 [Protocols]\r
   gEfiDiskIoProtocolGuid                        ## BY_START\r
+  gEfiDiskIo2ProtocolGuid                       ## BY_START\r
   gEfiBlockIoProtocolGuid                       ## TO_START\r
+  gEfiBlockIo2ProtocolGuid                      ## TO_START\r
 \r
index 13b94c307fc0201bc5a4da66e062c1da6e6975ba..3d7cf2dc6cdd8e2fa2c29e4cc21dba80cad2492a 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Decode an El Torito formatted CD-ROM\r
 \r
-Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2013, 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
@@ -22,6 +22,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
   @param[in]  This        Calling context.\r
   @param[in]  Handle      Parent Handle.\r
   @param[in]  DiskIo      Parent DiskIo interface.\r
+  @param[in]  DiskIo2     Parent DiskIo2 interface.\r
   @param[in]  BlockIo     Parent BlockIo interface.\r
   @param[in]  BlockIo2    Parent BlockIo2 interface.\r
   @param[in]  DevicePath  Parent Device Path\r
@@ -37,6 +38,7 @@ PartitionInstallElToritoChildHandles (
   IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
   IN  EFI_HANDLE                   Handle,\r
   IN  EFI_DISK_IO_PROTOCOL         *DiskIo,\r
+  IN  EFI_DISK_IO2_PROTOCOL        *DiskIo2,\r
   IN  EFI_BLOCK_IO_PROTOCOL        *BlockIo,\r
   IN  EFI_BLOCK_IO2_PROTOCOL       *BlockIo2,\r
   IN  EFI_DEVICE_PATH_PROTOCOL     *DevicePath\r
@@ -258,6 +260,7 @@ PartitionInstallElToritoChildHandles (
                 This,\r
                 Handle,\r
                 DiskIo,\r
+                DiskIo2,\r
                 BlockIo,\r
                 BlockIo2,\r
                 DevicePath,\r
index 0778588298e5adbf45e9e36ea6c21df8646a35ba..35860515c13b9da3284b2a5f0d5c57cad2032016 100644 (file)
@@ -184,6 +184,7 @@ PartitionSetCrc (
   @param[in]  This       Calling context.\r
   @param[in]  Handle     Parent Handle.\r
   @param[in]  DiskIo     Parent DiskIo interface.\r
+  @param[in]  DiskIo2    Parent DiskIo2 interface.\r
   @param[in]  BlockIo    Parent BlockIo interface.\r
   @param[in]  BlockIo2   Parent BlockIo2 interface.\r
   @param[in]  DevicePath Parent Device Path.\r
@@ -198,6 +199,7 @@ PartitionInstallGptChildHandles (
   IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
   IN  EFI_HANDLE                   Handle,\r
   IN  EFI_DISK_IO_PROTOCOL         *DiskIo,\r
+  IN  EFI_DISK_IO2_PROTOCOL        *DiskIo2,\r
   IN  EFI_BLOCK_IO_PROTOCOL        *BlockIo,\r
   IN  EFI_BLOCK_IO2_PROTOCOL       *BlockIo2,\r
   IN  EFI_DEVICE_PATH_PROTOCOL     *DevicePath\r
@@ -400,6 +402,7 @@ PartitionInstallGptChildHandles (
                This,\r
                Handle,\r
                DiskIo,\r
+               DiskIo2,\r
                BlockIo,\r
                BlockIo2,\r
                DevicePath,\r
index 4c64663746cc07adc66840c1ab09a4dd779d7d15..a35b4f2d0de86a8ab43971dac032943121704ebf 100644 (file)
@@ -11,7 +11,7 @@
         always on the first sector of a media. The first sector also contains\r
         the legacy boot strap code.\r
 \r
-Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2013, 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
@@ -104,6 +104,7 @@ PartitionValidMbr (
   @param[in]  This              Calling context.\r
   @param[in]  Handle            Parent Handle.\r
   @param[in]  DiskIo            Parent DiskIo interface.\r
+  @param[in]  DiskIo2           Parent DiskIo2 interface.\r
   @param[in]  BlockIo           Parent BlockIo interface.\r
   @param[in]  BlockIo2          Parent BlockIo2 interface.\r
   @param[in]  DevicePath        Parent Device Path.\r
@@ -118,6 +119,7 @@ PartitionInstallMbrChildHandles (
   IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
   IN  EFI_HANDLE                   Handle,\r
   IN  EFI_DISK_IO_PROTOCOL         *DiskIo,\r
+  IN  EFI_DISK_IO2_PROTOCOL        *DiskIo2,\r
   IN  EFI_BLOCK_IO_PROTOCOL        *BlockIo,\r
   IN  EFI_BLOCK_IO2_PROTOCOL       *BlockIo2,\r
   IN  EFI_DEVICE_PATH_PROTOCOL     *DevicePath\r
@@ -226,6 +228,7 @@ PartitionInstallMbrChildHandles (
                 This,\r
                 Handle,\r
                 DiskIo,\r
+                DiskIo2,\r
                 BlockIo,\r
                 BlockIo2,\r
                 DevicePath,\r
@@ -287,6 +290,7 @@ PartitionInstallMbrChildHandles (
                  This,\r
                  Handle,\r
                  DiskIo,\r
+                 DiskIo2,\r
                  BlockIo,\r
                  BlockIo2,\r
                  DevicePath,\r
index 318bfe4326c786869e0ab7ec990fd3771108a802..5cc1397e7c0776e0e03a1c25004a4635cc7d8222 100644 (file)
@@ -4,7 +4,7 @@
   of the raw block devices media. Currently "El Torito CD-ROM", Legacy\r
   MBR, and GPT partition schemes are supported.\r
 \r
-Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2013, 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
@@ -200,6 +200,7 @@ PartitionDriverBindingStart (
   EFI_BLOCK_IO_PROTOCOL     *BlockIo;\r
   EFI_BLOCK_IO2_PROTOCOL    *BlockIo2;\r
   EFI_DISK_IO_PROTOCOL      *DiskIo;\r
+  EFI_DISK_IO2_PROTOCOL     *DiskIo2;\r
   EFI_DEVICE_PATH_PROTOCOL  *ParentDevicePath;\r
   PARTITION_DETECT_ROUTINE  *Routine;\r
   BOOLEAN                   MediaPresent;\r
@@ -243,8 +244,11 @@ PartitionDriverBindingStart (
                   (VOID **) &BlockIo2,\r
                   This->DriverBindingHandle,\r
                   ControllerHandle,\r
-                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
                   );\r
+  if (EFI_ERROR (Status)) {\r
+    BlockIo2 = NULL;\r
+  }\r
 \r
   //\r
   // Get the Device Path Protocol on ControllerHandle's handle.\r
@@ -261,6 +265,9 @@ PartitionDriverBindingStart (
     goto Exit;\r
   }\r
 \r
+  //\r
+  // Get the DiskIo and DiskIo2.\r
+  //\r
   Status = gBS->OpenProtocol (\r
                   ControllerHandle,\r
                   &gEfiDiskIoProtocolGuid,\r
@@ -281,6 +288,18 @@ PartitionDriverBindingStart (
 \r
   OpenStatus = Status;\r
 \r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiDiskIo2ProtocolGuid,\r
+                  (VOID **) &DiskIo2,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r
+    DiskIo2 = NULL;\r
+  }\r
+\r
   //\r
   // Try to read blocks when there's media or it is removable physical partition.\r
   //\r
@@ -299,6 +318,7 @@ PartitionDriverBindingStart (
                    This,\r
                    ControllerHandle,\r
                    DiskIo,\r
+                   DiskIo2,\r
                    BlockIo,\r
                    BlockIo2,\r
                    ParentDevicePath\r
@@ -404,7 +424,7 @@ PartitionDriverBindingStop (
     //    \r
     gBS->CloseProtocol (\r
            ControllerHandle,\r
-           &gEfiBlockIo2ProtocolGuid,\r
+           &gEfiDiskIo2ProtocolGuid,\r
            This->DriverBindingHandle,\r
            ControllerHandle\r
            );\r
@@ -699,7 +719,7 @@ PartitionFlushBlocks (
   Probe the media status and return EFI_NO_MEDIA or EFI_MEDIA_CHANGED\r
   for no media or media change case. Otherwise DefaultStatus is returned.\r
 \r
-  @param BlockIo2           Pointer to the BlockIo2 instance.\r
+  @param DiskIo2            Pointer to the DiskIo2 instance.\r
   @param MediaId            Id of the media, changes every time the media is replaced.\r
   @param DefaultStatus      The default status to return when it's not the no media\r
                             or media change case.\r
@@ -710,7 +730,7 @@ PartitionFlushBlocks (
 **/\r
 EFI_STATUS\r
 ProbeMediaStatusEx (\r
-  IN EFI_BLOCK_IO2_PROTOCOL  *BlockIo2,\r
+  IN EFI_DISK_IO2_PROTOCOL   *DiskIo2,\r
   IN UINT32                  MediaId,\r
   IN EFI_STATUS              DefaultStatus\r
   )\r
@@ -718,16 +738,9 @@ ProbeMediaStatusEx (
   EFI_STATUS                 Status;\r
 \r
   //\r
-  // Read from LBA 0 but passing NULL as buffer pointer to detect the media status.\r
+  // Read 1 byte from offset 0 but passing NULL as buffer pointer\r
   //\r
-  Status = BlockIo2->ReadBlocksEx (\r
-                       BlockIo2,\r
-                       MediaId,\r
-                       0,\r
-                       NULL,\r
-                       0,\r
-                       NULL\r
-                       );\r
+  Status = DiskIo2->ReadDiskEx (DiskIo2, MediaId, 0, NULL, 1, NULL);\r
   if ((Status == EFI_NO_MEDIA) || (Status == EFI_MEDIA_CHANGED)) {\r
     return Status;\r
   }\r
@@ -762,6 +775,68 @@ PartitionResetEx (
                                     );\r
 }\r
 \r
+/**\r
+  The general callback for the DiskIo2 interfaces.\r
+  @param  Event                 Event whose notification function is being invoked.\r
+  @param  Context               The pointer to the notification function's context,\r
+                                which points to the PARTITION_ACCESS_TASK instance.\r
+**/\r
+VOID\r
+EFIAPI\r
+PartitionOnAccessComplete (\r
+  IN EFI_EVENT                 Event,\r
+  IN VOID                      *Context\r
+  )\r
+{\r
+  PARTITION_ACCESS_TASK   *Task;\r
+\r
+  Task = (PARTITION_ACCESS_TASK *) Context;\r
+\r
+  gBS->CloseEvent (Event);\r
+\r
+  Task->BlockIo2Token->TransactionStatus = Task->DiskIo2Token.TransactionStatus;\r
+  gBS->SignalEvent (Task->BlockIo2Token->Event);\r
+\r
+  FreePool (Task);\r
+}\r
+\r
+/**\r
+  Create a new PARTITION_ACCESS_TASK instance.\r
+\r
+  @param  Token  Pointer to the EFI_BLOCK_IO2_TOKEN.\r
+\r
+  @return Pointer to the created PARTITION_ACCESS_TASK instance or NULL upon failure.\r
+**/\r
+PARTITION_ACCESS_TASK *\r
+PartitionCreateAccessTask (\r
+  IN EFI_BLOCK_IO2_TOKEN    *Token\r
+  )\r
+{\r
+  EFI_STATUS                Status;\r
+  PARTITION_ACCESS_TASK     *Task;\r
+\r
+  Task = AllocatePool (sizeof (*Task));\r
+  if (Task == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  Status = gBS->CreateEvent (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_CALLBACK,\r
+                  PartitionOnAccessComplete,\r
+                  Task,\r
+                  &Task->DiskIo2Token.Event\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    FreePool (Task);\r
+    return NULL;\r
+  }\r
+\r
+  Task->BlockIo2Token = Token;\r
+\r
+  return Task;\r
+}\r
+\r
 /**\r
   Read BufferSize bytes from Lba into Buffer.\r
   \r
@@ -806,44 +881,38 @@ PartitionReadBlocksEx (
   OUT    VOID                   *Buffer\r
   )\r
 {\r
+  EFI_STATUS              Status;\r
   PARTITION_PRIVATE_DATA  *Private;\r
   UINT64                  Offset;\r
-  UINT32                  UnderRun;\r
+  PARTITION_ACCESS_TASK   *Task;\r
 \r
   Private = PARTITION_DEVICE_FROM_BLOCK_IO2_THIS (This);\r
 \r
-  if (Token == NULL) {\r
-    return ProbeMediaStatusEx (Private->ParentBlockIo2, MediaId, EFI_INVALID_PARAMETER);\r
-  }\r
-\r
   if (BufferSize % Private->BlockSize != 0) {\r
-    return ProbeMediaStatusEx (Private->ParentBlockIo2, MediaId, EFI_BAD_BUFFER_SIZE);\r
+    return ProbeMediaStatusEx (Private->DiskIo2, MediaId, EFI_BAD_BUFFER_SIZE);\r
   }\r
 \r
   Offset = MultU64x32 (Lba, Private->BlockSize) + Private->Start;\r
   if (Offset + BufferSize > Private->End) {\r
-    return ProbeMediaStatusEx (Private->ParentBlockIo2, MediaId, EFI_INVALID_PARAMETER);\r
+    return ProbeMediaStatusEx (Private->DiskIo2, MediaId, EFI_INVALID_PARAMETER);\r
   }\r
 \r
-  //\r
-  // Since the BlockIO2 call Parent BlockIO2 directly, so here the offset must\r
-  // be multiple of BlockSize. If the Spec will be updated the DiskIO to support\r
-  // BlockIO2, this limitation will be removed and call DiskIO here.\r
-  //\r
-  Lba = DivU64x32Remainder (Offset, Private->BlockSize, &UnderRun);\r
-  if (UnderRun != 0) {\r
-    return ProbeMediaStatusEx (Private->ParentBlockIo2, MediaId, EFI_UNSUPPORTED);\r
-  }\r
+  if ((Token != NULL) && (Token->Event != NULL)) {\r
+    Task = PartitionCreateAccessTask (Token);\r
+    if (Task == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
 \r
-  //\r
-  // Because some partitions have different block size from their parent\r
-  // device, in that case the Block I/O2 couldn't be called.\r
-  //\r
-  if (Private->BlockSize != Private->ParentBlockIo->Media->BlockSize) {\r
-    return ProbeMediaStatusEx (Private->ParentBlockIo2, MediaId, EFI_UNSUPPORTED);\r
+    Status = Private->DiskIo2->ReadDiskEx (Private->DiskIo2, MediaId, Offset, &Task->DiskIo2Token, BufferSize, Buffer);\r
+    if (EFI_ERROR (Status)) {\r
+      gBS->CloseEvent (Task->DiskIo2Token.Event);\r
+      FreePool (Task);\r
+    }\r
+  } else {\r
+    Status = Private->DiskIo2->ReadDiskEx (Private->DiskIo2, MediaId, Offset, NULL, BufferSize, Buffer);\r
   }\r
 \r
-  return Private->ParentBlockIo2->ReadBlocksEx (Private->ParentBlockIo2, MediaId, Lba, Token, BufferSize, Buffer);\r
+  return Status;\r
 }\r
 \r
 /**\r
@@ -888,44 +957,37 @@ PartitionWriteBlocksEx (
   IN     VOID                   *Buffer\r
   )\r
 {\r
+  EFI_STATUS              Status;\r
   PARTITION_PRIVATE_DATA  *Private;\r
   UINT64                  Offset;\r
-  UINT32                  UnderRun;\r
+  PARTITION_ACCESS_TASK   *Task;\r
 \r
   Private = PARTITION_DEVICE_FROM_BLOCK_IO2_THIS (This);\r
 \r
-  if (Token == NULL) {\r
-    return ProbeMediaStatusEx (Private->ParentBlockIo2, MediaId, EFI_INVALID_PARAMETER);\r
-  }\r
-\r
   if (BufferSize % Private->BlockSize != 0) {\r
-    return ProbeMediaStatusEx (Private->ParentBlockIo2, MediaId, EFI_BAD_BUFFER_SIZE);\r
+    return ProbeMediaStatusEx (Private->DiskIo2, MediaId, EFI_BAD_BUFFER_SIZE);\r
   }\r
 \r
   Offset = MultU64x32 (Lba, Private->BlockSize) + Private->Start;\r
   if (Offset + BufferSize > Private->End) {\r
-    return ProbeMediaStatusEx (Private->ParentBlockIo2, MediaId, EFI_INVALID_PARAMETER);\r
-  }\r
-\r
-  //\r
-  // Since the BlockIO2 call Parent BlockIO2 directly, so here the offset must\r
-  // be multiple of BlockSize. If the Spec will be updated the DiskIO to support\r
-  // BlockIO2, this limitation will be removed and call DiskIO here.\r
-  //\r
-  Lba = DivU64x32Remainder (Offset, Private->BlockSize, &UnderRun);\r
-  if (UnderRun != 0) {\r
-    return ProbeMediaStatusEx (Private->ParentBlockIo2, MediaId, EFI_UNSUPPORTED);\r
+    return ProbeMediaStatusEx (Private->DiskIo2, MediaId, EFI_INVALID_PARAMETER);\r
   }\r
+  \r
+  if ((Token != NULL) && (Token->Event != NULL)) {\r
+    Task = PartitionCreateAccessTask (Token);\r
+    if (Task == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
 \r
-  //\r
-  // Because some kinds of partition have different block size from their parent,\r
-  // in that case it couldn't call parent Block I/O2. \r
-  //\r
-  if (Private->BlockSize != Private->ParentBlockIo->Media->BlockSize) {\r
-    return ProbeMediaStatusEx (Private->ParentBlockIo2, MediaId, EFI_UNSUPPORTED);\r
+    Status =  Private->DiskIo2->WriteDiskEx (Private->DiskIo2, MediaId, Offset, &Task->DiskIo2Token, BufferSize, Buffer);\r
+    if (EFI_ERROR (Status)) {\r
+      gBS->CloseEvent (Task->DiskIo2Token.Event);\r
+      FreePool (Task);\r
+    }\r
+  } else {\r
+    Status = Private->DiskIo2->WriteDiskEx (Private->DiskIo2, MediaId, Offset, NULL, BufferSize, Buffer);\r
   }\r
-\r
-  return Private->ParentBlockIo2->WriteBlocksEx (Private->ParentBlockIo2, MediaId, Lba, Token, BufferSize, Buffer);\r
+  return Status;\r
 }\r
 \r
 /**\r
@@ -957,19 +1019,27 @@ PartitionFlushBlocksEx (
   IN OUT EFI_BLOCK_IO2_TOKEN    *Token\r
   )\r
 {\r
+  EFI_STATUS              Status;\r
   PARTITION_PRIVATE_DATA  *Private;\r
+  PARTITION_ACCESS_TASK   *Task;\r
 \r
   Private = PARTITION_DEVICE_FROM_BLOCK_IO2_THIS (This);\r
 \r
-  //\r
-  // Because some kinds of partition have different block size from their parent,\r
-  // in that case it couldn't call parent Block I/O2. \r
-  //\r
-  if (Private->BlockSize != Private->ParentBlockIo->Media->BlockSize) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
+  if ((Token != NULL) && (Token->Event != NULL)) {\r
+    Task = PartitionCreateAccessTask (Token);\r
+    if (Task == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
 \r
-  return Private->ParentBlockIo2->FlushBlocksEx (Private->ParentBlockIo2, Token);\r
+    Status = Private->DiskIo2->FlushDiskEx (Private->DiskIo2, &Task->DiskIo2Token);\r
+    if (EFI_ERROR (Status)) {\r
+      gBS->CloseEvent (Task->DiskIo2Token.Event);\r
+      FreePool (Task);\r
+    }\r
+  } else {\r
+    Status = Private->DiskIo2->FlushDiskEx (Private->DiskIo2, NULL);\r
+  }\r
+  return Status;\r
 }\r
 \r
 \r
@@ -980,6 +1050,7 @@ PartitionFlushBlocksEx (
   @param[in]  This              Protocol instance pointer.\r
   @param[in]  ParentHandle      Parent Handle for new child.\r
   @param[in]  ParentDiskIo      Parent DiskIo interface.\r
+  @param[in]  ParentDiskIo2     Parent DiskIo2 interface.\r
   @param[in]  ParentBlockIo     Parent BlockIo interface.\r
   @param[in]  ParentBlockIo2    Parent BlockIo2 interface.\r
   @param[in]  ParentDevicePath  Parent Device Path.\r
@@ -998,6 +1069,7 @@ PartitionInstallChildHandle (
   IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
   IN  EFI_HANDLE                   ParentHandle,\r
   IN  EFI_DISK_IO_PROTOCOL         *ParentDiskIo,\r
+  IN  EFI_DISK_IO2_PROTOCOL        *ParentDiskIo2,\r
   IN  EFI_BLOCK_IO_PROTOCOL        *ParentBlockIo,\r
   IN  EFI_BLOCK_IO2_PROTOCOL       *ParentBlockIo2,\r
   IN  EFI_DEVICE_PATH_PROTOCOL     *ParentDevicePath,\r
@@ -1026,6 +1098,7 @@ PartitionInstallChildHandle (
   Private->ParentBlockIo    = ParentBlockIo;\r
   Private->ParentBlockIo2   = ParentBlockIo2;\r
   Private->DiskIo           = ParentDiskIo;\r
+  Private->DiskIo2          = ParentDiskIo2;\r
 \r
   //\r
   // Set the BlockIO into Private Data.\r
@@ -1043,7 +1116,8 @@ PartitionInstallChildHandle (
   //\r
   // Set the BlockIO2 into Private Data.\r
   //\r
-  if (Private->ParentBlockIo2 != NULL) {\r
+  if (Private->DiskIo2 != NULL) {\r
+    ASSERT (Private->ParentBlockIo2 != NULL);\r
     Private->BlockIo2.Media    = &Private->Media2;\r
     CopyMem (Private->BlockIo2.Media, ParentBlockIo2->Media, sizeof (EFI_BLOCK_IO_MEDIA));\r
 \r
@@ -1065,9 +1139,7 @@ PartitionInstallChildHandle (
 \r
   Private->Media.BlockSize = (UINT32) BlockSize;\r
 \r
-  //\r
-  // For BlockIO2, it should keep the same alignment with the parent BlockIO2's.\r
-  //\r
+  Private->Media2.IoAlign   = 0;\r
   Private->Media2.LogicalPartition = TRUE;\r
   Private->Media2.LastBlock = Private->Media.LastBlock;\r
   Private->Media2.BlockSize = (UINT32) BlockSize;\r
@@ -1105,17 +1177,9 @@ PartitionInstallChildHandle (
 \r
   //\r
   // Create the new handle. \r
-  // BlockIO2 will be installed on the condition that the blocksize of parent BlockIO \r
-  // is same with the child BlockIO's. Instead of calling the DiskIO, the child BlockIO2 \r
-  // directly call the parent BlockIO and doesn't handle the different block size issue.\r
-  // If SPEC will update the DiskIO to support the Non-Blocking model, the BlockIO2 will call\r
-  // DiskIO to handle the blocksize unequal issue and the limitation will be remove from\r
-  // here.\r
   //\r
   Private->Handle = NULL;\r
-  if ((Private->ParentBlockIo2 != NULL) &&\r
-      (Private->ParentBlockIo2->Media->BlockSize == BlockSize)\r
-     ) {\r
+  if (Private->DiskIo2 != NULL) {\r
     Status = gBS->InstallMultipleProtocolInterfaces (\r
                     &Private->Handle,\r
                     &gEfiDevicePathProtocolGuid,\r
index 7a4ca8a3192f85200040acb89306c9c15a9e24db..06470f689f11f23db894cfd38d8ed5dff0ed9dd8 100644 (file)
@@ -26,6 +26,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Protocol/DevicePath.h>\r
 #include <Protocol/DriverBinding.h>\r
 #include <Protocol/DiskIo.h>\r
+#include <Protocol/DiskIo2.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/UefiDriverEntryPoint.h>\r
 #include <Library/BaseLib.h>\r
@@ -54,6 +55,7 @@ typedef struct {
   EFI_BLOCK_IO_MEDIA        Media2;//For BlockIO2\r
 \r
   EFI_DISK_IO_PROTOCOL      *DiskIo;\r
+  EFI_DISK_IO2_PROTOCOL     *DiskIo2;\r
   EFI_BLOCK_IO_PROTOCOL     *ParentBlockIo;\r
   EFI_BLOCK_IO2_PROTOCOL    *ParentBlockIo2;\r
   UINT64                    Start;\r
@@ -64,6 +66,11 @@ typedef struct {
 \r
 } PARTITION_PRIVATE_DATA;\r
 \r
+typedef struct {\r
+  EFI_DISK_IO2_TOKEN           DiskIo2Token;\r
+  EFI_BLOCK_IO2_TOKEN          *BlockIo2Token;\r
+} PARTITION_ACCESS_TASK;\r
+\r
 #define PARTITION_DEVICE_FROM_BLOCK_IO_THIS(a)  CR (a, PARTITION_PRIVATE_DATA, BlockIo, PARTITION_PRIVATE_DATA_SIGNATURE)\r
 #define PARTITION_DEVICE_FROM_BLOCK_IO2_THIS(a) CR (a, PARTITION_PRIVATE_DATA, BlockIo2, PARTITION_PRIVATE_DATA_SIGNATURE)\r
 \r
@@ -308,6 +315,7 @@ PartitionComponentNameGetControllerName (
   @param[in]  This              Protocol instance pointer.\r
   @param[in]  ParentHandle      Parent Handle for new child.\r
   @param[in]  ParentDiskIo      Parent DiskIo interface.\r
+  @param[in]  ParentDiskIo2     Parent DiskIo2 interface.\r
   @param[in]  ParentBlockIo     Parent BlockIo interface.\r
   @param[in]  ParentBlockIo2    Parent BlockIo2 interface.\r
   @param[in]  ParentDevicePath  Parent Device Path.\r
@@ -326,6 +334,7 @@ PartitionInstallChildHandle (
   IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
   IN  EFI_HANDLE                   ParentHandle,\r
   IN  EFI_DISK_IO_PROTOCOL         *ParentDiskIo,\r
+  IN  EFI_DISK_IO2_PROTOCOL        *ParentDiskIo2,\r
   IN  EFI_BLOCK_IO_PROTOCOL        *ParentBlockIo,\r
   IN  EFI_BLOCK_IO2_PROTOCOL       *ParentBlockIo2,\r
   IN  EFI_DEVICE_PATH_PROTOCOL     *ParentDevicePath,\r
@@ -342,6 +351,7 @@ PartitionInstallChildHandle (
   @param[in]  This       Calling context.\r
   @param[in]  Handle     Parent Handle.\r
   @param[in]  DiskIo     Parent DiskIo interface.\r
+  @param[in]  DiskIo2    Parent DiskIo2 interface.\r
   @param[in]  BlockIo    Parent BlockIo interface.\r
   @param[in]  BlockIo2   Parent BlockIo2 interface.\r
   @param[in]  DevicePath Parent Device Path.\r
@@ -357,6 +367,7 @@ PartitionInstallGptChildHandles (
   IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
   IN  EFI_HANDLE                   Handle,\r
   IN  EFI_DISK_IO_PROTOCOL         *DiskIo,\r
+  IN  EFI_DISK_IO2_PROTOCOL        *DiskIo2,\r
   IN  EFI_BLOCK_IO_PROTOCOL        *BlockIo,\r
   IN  EFI_BLOCK_IO2_PROTOCOL       *BlockIo2,\r
   IN  EFI_DEVICE_PATH_PROTOCOL     *DevicePath\r
@@ -368,6 +379,7 @@ PartitionInstallGptChildHandles (
   @param[in]  This        Calling context.\r
   @param[in]  Handle      Parent Handle.\r
   @param[in]  DiskIo      Parent DiskIo interface.\r
+  @param[in]  DiskIo2     Parent DiskIo2 interface.\r
   @param[in]  BlockIo     Parent BlockIo interface.\r
   @param[in]  BlockIo2    Parent BlockIo2 interface.\r
   @param[in]  DevicePath  Parent Device Path\r
@@ -383,6 +395,7 @@ PartitionInstallElToritoChildHandles (
   IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
   IN  EFI_HANDLE                   Handle,\r
   IN  EFI_DISK_IO_PROTOCOL         *DiskIo,\r
+  IN  EFI_DISK_IO2_PROTOCOL        *DiskIo2,\r
   IN  EFI_BLOCK_IO_PROTOCOL        *BlockIo,\r
   IN  EFI_BLOCK_IO2_PROTOCOL       *BlockIo2,\r
   IN  EFI_DEVICE_PATH_PROTOCOL     *DevicePath\r
@@ -394,6 +407,7 @@ PartitionInstallElToritoChildHandles (
   @param[in]  This              Calling context.\r
   @param[in]  Handle            Parent Handle.\r
   @param[in]  DiskIo            Parent DiskIo interface.\r
+  @param[in]  DiskIo2           Parent DiskIo2 interface.\r
   @param[in]  BlockIo           Parent BlockIo interface.\r
   @param[in]  BlockIo2          Parent BlockIo2 interface.\r
   @param[in]  DevicePath        Parent Device Path.\r
@@ -408,6 +422,7 @@ PartitionInstallMbrChildHandles (
   IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
   IN  EFI_HANDLE                   Handle,\r
   IN  EFI_DISK_IO_PROTOCOL         *DiskIo,\r
+  IN  EFI_DISK_IO2_PROTOCOL        *DiskIo2,\r
   IN  EFI_BLOCK_IO_PROTOCOL        *BlockIo,\r
   IN  EFI_BLOCK_IO2_PROTOCOL       *BlockIo2,\r
   IN  EFI_DEVICE_PATH_PROTOCOL     *DevicePath\r
@@ -419,6 +434,7 @@ EFI_STATUS
   IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
   IN  EFI_HANDLE                   Handle,\r
   IN  EFI_DISK_IO_PROTOCOL         *DiskIo,\r
+  IN  EFI_DISK_IO2_PROTOCOL        *DiskIo2,\r
   IN  EFI_BLOCK_IO_PROTOCOL        *BlockIo,\r
   IN  EFI_BLOCK_IO2_PROTOCOL       *BlockIo2,\r
   IN  EFI_DEVICE_PATH_PROTOCOL     *DevicePath\r
index aac20a13b1bea3478e929dc18b92a30271cbb09d..089918f5a98c4158558c972eb69d517d929a5dd5 100644 (file)
@@ -12,7 +12,7 @@
 #  This external input must be validated carefully to avoid security issue like\r
 #  buffer overflow, integer overflow.\r
 #\r
-#  Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2006 - 2013, 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
@@ -74,7 +74,9 @@
   gEfiBlockIoProtocolGuid                       ## BY_START\r
   gEfiDevicePathProtocolGuid                    ## BY_START\r
   gEfiDiskIoProtocolGuid                        ## BY_START\r
+  gEfiDiskIo2ProtocolGuid                       ## BY_START\r
   gEfiBlockIoProtocolGuid                       ## TO_START\r
   gEfiBlockIo2ProtocolGuid                      ## TO_START\r
   gEfiDevicePathProtocolGuid                    ## TO_START\r
   gEfiDiskIoProtocolGuid                        ## TO_START\r
+  gEfiDiskIo2ProtocolGuid                       ## TO_START\r
diff --git a/MdePkg/Include/Protocol/DiskIo2.h b/MdePkg/Include/Protocol/DiskIo2.h
new file mode 100644 (file)
index 0000000..a6badf2
--- /dev/null
@@ -0,0 +1,173 @@
+/** @file\r
+  Disk IO protocol as defined in the UEFI 2.0 specification.\r
+\r
+  The Disk IO2 protocol is used to convert block oriented devices into byte\r
+  oriented devices. The Disk IO protocol is intended to layer on top of the\r
+  Block IO protocol.\r
+\r
+  Copyright (c) 2013, 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
+  http://opensource.org/licenses/bsd-license.php                                            \r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+**/\r
+\r
+#ifndef __DISK_IO2_H__\r
+#define __DISK_IO2_H__\r
+\r
+#define EFI_DISK_IO2_PROTOCOL_GUID \\r
+  { \\r
+    0x151c8eae, 0x7f2c, 0x472c, 0x9e, 0x54, 0x98, 0x28, 0x19, 0x4f, 0x6a, 0x88 \\r
+  }\r
+\r
+typedef struct _EFI_DISK_IO2_PROTOCOL EFI_DISK_IO2_PROTOCOL;\r
+\r
+/**\r
+  The struct of Disk IO2 Token.\r
+**/\r
+typedef struct {\r
+  //\r
+  // If Event is NULL, then blocking I/O is performed.\r
+  // If Event is not NULL and non-blocking I/O is supported, then non-blocking I/O is performed,\r
+  // and Event will be signaled when the I/O request is completed.\r
+  // The caller must be prepared to handle the case where the callback associated with Event occurs\r
+  // before the original asynchronous I/O request call returns.\r
+  //\r
+  EFI_EVENT  Event;\r
+\r
+  //\r
+  // Defines whether or not the signaled event encountered an error.\r
+  //\r
+  EFI_STATUS TransactionStatus;\r
+} EFI_DISK_IO2_TOKEN;\r
+\r
+/**\r
+  Terminate outstanding asynchronous requests to a device.\r
+\r
+  @param This                   Indicates a pointer to the calling context.\r
+\r
+  @retval EFI_SUCCESS           All outstanding requests were successfully terminated.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error while performing the cancel\r
+                                operation.\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EFI_DISK_CANCEL_EX) (\r
+  IN EFI_DISK_IO2_PROTOCOL *This\r
+  );\r
+\r
+/**\r
+  Reads a specified number of bytes from a device.\r
+\r
+  @param This                   Indicates a pointer to the calling context.\r
+  @param MediaId                ID of the medium to be read.\r
+  @param Offset                 The starting byte offset on the logical block I/O device to read from.\r
+  @param Token                  A pointer to the token associated with the transaction.\r
+                                If this field is NULL, synchronous/blocking IO is performed.\r
+  @param  BufferSize            The size in bytes of Buffer. The number of bytes to read from the device.\r
+  @param  Buffer                A pointer to the destination buffer for the data.\r
+                                The caller is responsible either having implicit or explicit ownership of the buffer.\r
+\r
+  @retval EFI_SUCCESS           If Event is NULL (blocking I/O): The data was read correctly from the device.\r
+                                If Event is not NULL (asynchronous I/O): The request was successfully queued for processing.\r
+                                                                         Event will be signaled upon completion.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error while performing the write.\r
+  @retval EFI_NO_MEDIA          There is no medium in the device.\r
+  @retval EFI_MEDIA_CHNAGED     The MediaId is not for the current medium.\r
+  @retval EFI_INVALID_PARAMETER The read request contains device addresses that are not valid for the device.\r
+  @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack of resources.\r
+\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EFI_DISK_READ_EX) (\r
+  IN EFI_DISK_IO2_PROTOCOL        *This,\r
+  IN UINT32                       MediaId,\r
+  IN UINT64                       Offset,\r
+  IN OUT EFI_DISK_IO2_TOKEN       *Token,\r
+  IN UINTN                        BufferSize,\r
+  OUT VOID                        *Buffer\r
+  );\r
+\r
+/**\r
+  Writes a specified number of bytes to a device.\r
+\r
+  @param This        Indicates a pointer to the calling context.\r
+  @param MediaId     ID of the medium to be written.\r
+  @param Offset      The starting byte offset on the logical block I/O device to write to.\r
+  @param Token       A pointer to the token associated with the transaction.\r
+                     If this field is NULL, synchronous/blocking IO is performed.\r
+  @param BufferSize  The size in bytes of Buffer. The number of bytes to write to the device.\r
+  @param Buffer      A pointer to the buffer containing the data to be written.\r
+\r
+  @retval EFI_SUCCESS           If Event is NULL (blocking I/O): The data was written correctly to the device.\r
+                                If Event is not NULL (asynchronous I/O): The request was successfully queued for processing.\r
+                                                                         Event will be signaled upon completion.\r
+  @retval EFI_WRITE_PROTECTED   The device cannot be written to.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error while performing the write operation.\r
+  @retval EFI_NO_MEDIA          There is no medium in the device.\r
+  @retval EFI_MEDIA_CHNAGED     The MediaId is not for the current medium.\r
+  @retval EFI_INVALID_PARAMETER The write request contains device addresses that are not valid for the device.\r
+  @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack of resources.\r
+\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EFI_DISK_WRITE_EX) (\r
+  IN EFI_DISK_IO2_PROTOCOL        *This,\r
+  IN UINT32                       MediaId,\r
+  IN UINT64                       Offset,\r
+  IN OUT EFI_DISK_IO2_TOKEN       *Token,\r
+  IN UINTN                        BufferSize,\r
+  IN VOID                         *Buffer\r
+  );\r
+\r
+/**\r
+  Flushes all modified data to the physical device.\r
+\r
+  @param This        Indicates a pointer to the calling context.\r
+  @param MediaId     ID of the medium to be written.\r
+  @param Token       A pointer to the token associated with the transaction.\r
+                     If this field is NULL, synchronous/blocking IO is performed.\r
+\r
+  @retval EFI_SUCCESS           If Event is NULL (blocking I/O): The data was flushed successfully to the device.\r
+                                If Event is not NULL (asynchronous I/O): The request was successfully queued for processing.\r
+                                                                         Event will be signaled upon completion.\r
+  @retval EFI_WRITE_PROTECTED   The device cannot be written to.\r
+  @retval EFI_DEVICE_ERROR      The device reported an error while performing the write operation.\r
+  @retval EFI_NO_MEDIA          There is no medium in the device.\r
+  @retval EFI_MEDIA_CHNAGED     The MediaId is not for the current medium.\r
+  @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack of resources.\r
+**/\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *EFI_DISK_FLUSH_EX) (\r
+  IN EFI_DISK_IO2_PROTOCOL        *This,\r
+  IN OUT EFI_DISK_IO2_TOKEN       *Token\r
+  );\r
+\r
+#define EFI_DISK_IO2_PROTOCOL_REVISION 0x00020000\r
+\r
+///\r
+/// This protocol is used to abstract Block I/O interfaces.\r
+///\r
+struct _EFI_DISK_IO2_PROTOCOL {\r
+  ///\r
+  /// The revision to which the disk I/O interface adheres. All future\r
+  /// revisions must be backwards compatible. If a future version is not\r
+  /// backwards compatible, it is not the same GUID.\r
+  ///\r
+  UINT64             Revision;\r
+  EFI_DISK_CANCEL_EX Cancel;\r
+  EFI_DISK_READ_EX   ReadDiskEx;\r
+  EFI_DISK_WRITE_EX  WriteDiskEx;\r
+  EFI_DISK_FLUSH_EX  FlushDiskEx;\r
+};\r
+\r
+extern EFI_GUID gEfiDiskIo2ProtocolGuid;\r
+\r
+#endif\r
index 6ff7ae66f66a74aabf6835f97f711b6a15a8dff4..16c278aec33acbcaa8fbca3dda7afcff017c1e8d 100644 (file)
@@ -5,7 +5,7 @@
 # It also provides the definitions(including PPIs/PROTOCOLs/GUIDs) of\r
 # EFI1.10/UEFI2.3.1/PI1.2 and some Industry Standards.\r
 #\r
-# Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.<BR>\r
 # Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
 #\r
 # This program and the accompanying materials are licensed and made available under\r
   gEfiBlockIo2ProtocolGuid             = { 0xa77b2472, 0xe282, 0x4e9f, {0xa2, 0x45, 0xc2, 0xc0, 0xe2, 0x7b, 0xbc, 0xc1 }}\r
 \r
   ## Include/Protocol/StorageSecurityCommand.h\r
-  gEfiStorageSecurityCommandProtocolGuid    = { 0xc88b0b6d, 0x0dfc, 0x49a7, {0x9c, 0xb4, 0x49, 0x7, 0x4b, 0x4c, 0x3a, 0x78 }}\r
+  gEfiStorageSecurityCommandProtocolGuid = { 0xc88b0b6d, 0x0dfc, 0x49a7, {0x9c, 0xb4, 0x49, 0x7, 0x4b, 0x4c, 0x3a, 0x78 }}\r
 \r
   ## Include/Protocol/UserCredential2.h\r
-  gEfiUserCredential2ProtocolGuid       = { 0xe98adb03, 0xb8b9, 0x4af8, {0xba, 0x20, 0x26, 0xe9, 0x11, 0x4c, 0xbc, 0xe5 }}\r
+  gEfiUserCredential2ProtocolGuid      = { 0xe98adb03, 0xb8b9, 0x4af8, {0xba, 0x20, 0x26, 0xe9, 0x11, 0x4c, 0xbc, 0xe5 }}\r
+\r
+  #\r
+  # Protocols defined in UEFI2.4\r
+  #\r
+  ## Include/Protocol/DiskIo2.h\r
+  gEfiDiskIo2ProtocolGuid              = { 0x151c8eae, 0x7f2c, 0x472c, { 0x9e, 0x54, 0x98, 0x28, 0x19, 0x4f, 0x6a, 0x88 }}\r
 \r
 [PcdsFeatureFlag]\r
   ## If TRUE, the component name protocol will not be installed.\r