]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Modules cleanup.
authorvanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 16 Jul 2007 05:48:11 +0000 (05:48 +0000)
committervanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 16 Jul 2007 05:48:11 +0000 (05:48 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@3244 6f19259b-4bc3-4df7-8a09-765794883524

30 files changed:
MdeModulePkg/Application/HelloWorld/HelloWorld.inf
MdeModulePkg/Bus/Pci/EhciDxe/EhciDxe.inf
MdeModulePkg/Bus/Pci/UhciDxe/UhciDxe.inf
MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBusDxe.inf
MdeModulePkg/Bus/Usb/UsbKbDxe/UsbKbDxe.inf
MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassStorageDxe.inf
MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouseDxe.inf
MdeModulePkg/MdeModulePkg.dsc
MdeModulePkg/Universal/Disk/DiskIoDxe/ComponentName.c [new file with mode: 0644]
MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIo.c [new file with mode: 0644]
MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIo.h [new file with mode: 0644]
MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf [new file with mode: 0644]
MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.msa [new file with mode: 0644]
MdeModulePkg/Universal/Disk/PartitionDxe/ComponentName.c [new file with mode: 0644]
MdeModulePkg/Universal/Disk/PartitionDxe/ElTorito.c [new file with mode: 0644]
MdeModulePkg/Universal/Disk/PartitionDxe/Gpt.c [new file with mode: 0644]
MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c [new file with mode: 0644]
MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c [new file with mode: 0644]
MdeModulePkg/Universal/Disk/PartitionDxe/Partition.h [new file with mode: 0644]
MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf [new file with mode: 0644]
MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.msa [new file with mode: 0644]
MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf [new file with mode: 0644]
MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.msa [new file with mode: 0644]
MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/UnicodeCollationEng.c [new file with mode: 0644]
MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/UnicodeCollationEng.h [new file with mode: 0644]
MdeModulePkg/Universal/PCD/Dxe/Pcd.dxs [deleted file]
MdeModulePkg/Universal/PCD/Pei/Pcd.dxs [deleted file]
MdeModulePkg/Universal/PCD/Pei/Pcd.inf
MdeModulePkg/Universal/VariableRuntimeDxe/Variable.dxs [deleted file]
MdeModulePkg/Universal/WatchDogTimerDxe/WatchDogTimer.dxs [deleted file]

index 69b5000599ee78371252cc535e715e2f2b30a95e..e20a01ed224a16cc4796d893a7921c5f3314527a 100644 (file)
@@ -55,7 +55,6 @@
 \r
 [Packages]\r
   MdePkg/MdePkg.dec\r
-  MdeModulePkg/MdeModulePkg.dec\r
 \r
 \r
 ################################################################################\r
index 80e243eecb2f6788b06945a054e0ce9d03e1d49e..0a8331ca16c70019320be73799b73b1525464b55 100644 (file)
@@ -67,7 +67,6 @@
 \r
 [Packages]\r
   MdePkg/MdePkg.dec\r
-  MdeModulePkg/MdeModulePkg.dec\r
 \r
 \r
 ################################################################################\r
index 1ccae15f33f19ae643b505b3542e17094358e213..a756cccddae97c4b5031a56c6c7c8b05915f56ae 100644 (file)
@@ -67,7 +67,6 @@
 \r
 [Packages]\r
   MdePkg/MdePkg.dec\r
-  MdeModulePkg/MdeModulePkg.dec\r
 \r
 \r
 ################################################################################\r
index 423d9fb307e6798e5f96d4ad61e5a13eb76b8b02..3ae011c5b54e2fb8cb111f975fc45b382fe80b69 100644 (file)
@@ -64,7 +64,6 @@
 \r
 [Packages]\r
   MdePkg/MdePkg.dec\r
-  MdeModulePkg/MdeModulePkg.dec\r
 \r
 \r
 ################################################################################\r
index dfe7a2cabf92e639241e34ca1cd70715e14d015c..bf21e918582705a6516a63d32fc3ca27672281f7 100644 (file)
@@ -59,7 +59,6 @@
 \r
 [Packages]\r
   MdePkg/MdePkg.dec\r
-  MdeModulePkg/MdeModulePkg.dec\r
 \r
 \r
 ################################################################################\r
index 7636db70288cfb3ec9a6fa9d4f3289863d6a2bd0..611c5f346753ad8a36875ccd6bd846c085c7780d 100644 (file)
@@ -63,8 +63,6 @@
 \r
 [Packages]\r
   MdePkg/MdePkg.dec\r
-  MdeModulePkg/MdeModulePkg.dec\r
-\r
 \r
 ################################################################################\r
 #\r
index 01af215fabd8e3b9f43d3cb3b5227ee4fd27ee75..39692c9a105c3a4b1705c3f0567dddafe8825e92 100644 (file)
@@ -49,8 +49,6 @@
   usbmouse.c\r
   mousehid.c\r
   usbmouse.h\r
-  CommonHeader.h\r
-\r
 \r
 ################################################################################\r
 #\r
@@ -61,8 +59,6 @@
 \r
 [Packages]\r
   MdePkg/MdePkg.dec\r
-  MdeModulePkg/MdeModulePkg.dec\r
-\r
 \r
 ################################################################################\r
 #\r
index e8ec07c8fe0e11a7d8a0b335cff2f351edeeb620..aa3121a8b0c59d65cb93a234ea1dc408f533f910 100644 (file)
   $(WORKSPACE)/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.inf\r
 \r
   $(WORKSPACE)/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf\r
-  $(WORKSPACE)/MdeModulePkg/Universal/Disk/DiskIo/Dxe/DiskIo.inf\r
-  $(WORKSPACE)/MdeModulePkg/Universal/Disk/Partition/Dxe/Partition.inf\r
-  $(WORKSPACE)/MdeModulePkg/Universal/Disk/UnicodeCollation/English/Dxe/English.inf\r
+  $(WORKSPACE)/MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf\r
+  $(WORKSPACE)/MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf\r
+  $(WORKSPACE)/MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf\r
   $(WORKSPACE)/MdeModulePkg/Universal/SecurityStubDxe/SecurityStub.inf\r
 \r
   $(WORKSPACE)/MdeModulePkg/Universal/Ebc/Dxe/Ebc.inf\r
diff --git a/MdeModulePkg/Universal/Disk/DiskIoDxe/ComponentName.c b/MdeModulePkg/Universal/Disk/DiskIoDxe/ComponentName.c
new file mode 100644 (file)
index 0000000..bf95be1
--- /dev/null
@@ -0,0 +1,174 @@
+/** @file\r
+  UEFI Component Name protocol for DiskIo driver.\r
+  \r
+  Copyright (c) 2006 - 2007, Intel Corporation                                              \r
+  All rights reserved. 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
+#include "DiskIo.h"\r
+\r
+//\r
+// EFI Component Name Protocol\r
+//\r
+EFI_COMPONENT_NAME_PROTOCOL     gDiskIoComponentName = {\r
+  DiskIoComponentNameGetDriverName,\r
+  DiskIoComponentNameGetControllerName,\r
+  "eng"\r
+};\r
+\r
+static EFI_UNICODE_STRING_TABLE mDiskIoDriverNameTable[] = {\r
+  {\r
+    "eng",\r
+    (CHAR16 *)L"Generic Disk I/O Driver"\r
+  },\r
+  {\r
+    NULL,\r
+    NULL\r
+  }\r
+};\r
+\r
+\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of\r
+  the EFI Driver.\r
+\r
+  @param  This       A pointer to the\r
+                     EFI_COMPONENT_NAME_PROTOCOL instance.\r
+  \r
+  @param  Language   A pointer to a Null-terminated ASCII string\r
+                     array indicating the language. This is the\r
+                     language of the driver name that the caller\r
+                     is requesting, and it must match one of the\r
+                     languages specified in SupportedLanguages.\r
+                     The number of languages supported by a\r
+                     driver is up to the driver writer. Language\r
+                     is specified in RFC 3066 language code\r
+                     format.\r
+  \r
+  @param  DriverName A pointer to the Unicode string to return.\r
+                     This Unicode string is the name of the\r
+                     driver specified by This in the language\r
+                     specified by Language.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the\r
+                                Driver specified by This and the\r
+                                language specified by Language\r
+                                was returned in DriverName.\r
+  \r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+  \r
+  @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
+  \r
+  @retval EFI_UNSUPPORTED       The driver specified by This\r
+                                does not support the language\r
+                                specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DiskIoComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  )\r
+{\r
+  return LookupUnicodeString (\r
+           Language,\r
+           gDiskIoComponentName.SupportedLanguages,\r
+           mDiskIoDriverNameTable,\r
+           DriverName\r
+           );\r
+}\r
+\r
+\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of\r
+  the controller that is being managed by an EFI Driver.\r
+\r
+  @param  This             A pointer to the\r
+                           EFI_COMPONENT_NAME_PROTOCOL instance.\r
+\r
+  @param  ControllerHandle The handle of a controller that the\r
+                           driver specified by This is managing.\r
+                           This handle specifies the controller\r
+                           whose name is to be returned.\r
+\r
+  @param ChildHandle      The handle of the child controller to\r
+                           retrieve the name of.  This is an\r
+                           optional parameter that may be NULL.\r
+                           It will be NULL for device drivers.\r
+                           It will also be NULL for a bus\r
+                           drivers that wish to retrieve the\r
+                           name of the bus controller.  It will\r
+                           not be NULL for a bus driver that\r
+                           wishes to retrieve the name of a\r
+                           child controller.\r
+\r
+  @param  Language         A pointer to a Null-terminated ASCII\r
+                           string array indicating the language.\r
+                           This is the language of the driver\r
+                           name that the caller is requesting,\r
+                           and it must match one of the\r
+                           languages specified in\r
+                           SupportedLanguages. The number of\r
+                           languages supported by a driver is up\r
+                           to the driver writer. Language is\r
+                           specified in RFC 3066 language code\r
+                           format.\r
+\r
+  @param  ControllerName   A pointer to the Unicode string to\r
+                           return.  This Unicode string is the\r
+                           name of the controller specified by\r
+                           ControllerHandle and ChildHandle in\r
+                           the language specified by Language\r
+                           from the point of view of the driver\r
+                           specified by This.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the user\r
+                                readable name in the language\r
+                                specified by Language for the\r
+                                driver specified by This was\r
+                                returned in DriverName.\r
+\r
+  @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid\r
+                                EFI_HANDLE.\r
+\r
+  @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it\r
+                                is not a valid EFI_HANDLE.\r
+\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This is\r
+                                not currently managing the\r
+                                controller specified by\r
+                                ControllerHandle and\r
+                                ChildHandle.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This\r
+                                does not support the language\r
+                                specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DiskIoComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
diff --git a/MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIo.c b/MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIo.c
new file mode 100644 (file)
index 0000000..0cb4922
--- /dev/null
@@ -0,0 +1,737 @@
+/** @file\r
+  DiskIo driver that layers it's self on every Block IO protocol in the system.\r
+  DiskIo converts a block oriented device to a byte oriented device.\r
+\r
+  ReadDisk may have to do reads that are not aligned on sector boundaries.\r
+  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
+  Copyright (c) 2006 - 2007, Intel Corporation                                              \r
+  All rights reserved. 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
+#include "DiskIo.h"\r
+\r
+EFI_DRIVER_BINDING_PROTOCOL gDiskIoDriverBinding = {\r
+  DiskIoDriverBindingSupported,\r
+  DiskIoDriverBindingStart,\r
+  DiskIoDriverBindingStop,\r
+  0xa,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+DISK_IO_PRIVATE_DATA        gDiskIoPrivateDataTemplate = {\r
+  DISK_IO_PRIVATE_DATA_SIGNATURE,\r
+  {\r
+    EFI_DISK_IO_PROTOCOL_REVISION,\r
+    DiskIoReadDisk,\r
+    DiskIoWriteDisk\r
+  },\r
+  NULL\r
+};\r
+\r
+\r
+/**\r
+  Test to see if this driver supports ControllerHandle. \r
+\r
+  @param  This                Protocol instance pointer.\r
+  @param  ControllerHandle    Handle of device to test\r
+  @param  RemainingDevicePath Optional parameter use to pick a specific child\r
+                              device to start.\r
+\r
+  @retval EFI_SUCCESS         This driver supports this device\r
+  @retval EFI_ALREADY_STARTED This driver is already running on this device\r
+  @retval other               This driver does not support this device\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DiskIoDriverBindingSupported (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN EFI_HANDLE                   ControllerHandle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
+\r
+  //\r
+  // Open the IO Abstraction(s) needed to perform the supported test.\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiBlockIoProtocolGuid,\r
+                  (VOID **) &BlockIo,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // 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
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Start this driver on ControllerHandle by opening a Block IO protocol and\r
+  installing a Disk IO protocol on ControllerHandle.\r
+\r
+  @param  This                 Protocol instance pointer.\r
+  @param  ControllerHandle     Handle of device to bind driver to\r
+  @param  RemainingDevicePath  Optional parameter use to pick a specific child\r
+                               device to start.\r
+\r
+  @retval EFI_SUCCESS          This driver is added to ControllerHandle\r
+  @retval EFI_ALREADY_STARTED  This driver is already running on ControllerHandle\r
+  @retval other                This driver does not support this device\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DiskIoDriverBindingStart (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN EFI_HANDLE                   ControllerHandle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  DISK_IO_PRIVATE_DATA  *Private;\r
+\r
+  Private = NULL;\r
+\r
+  //\r
+  // Connect to the Block IO interface on ControllerHandle.\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiBlockIoProtocolGuid,\r
+                  (VOID **) &gDiskIoPrivateDataTemplate.BlockIo,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\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
+    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
+\r
+ErrorExit:\r
+  if (EFI_ERROR (Status)) {\r
+\r
+    if (Private != NULL) {\r
+      FreePool (Private);\r
+    }\r
+\r
+    gBS->CloseProtocol (\r
+          ControllerHandle,\r
+          &gEfiBlockIoProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          ControllerHandle\r
+          );\r
+  }\r
+\r
+  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
+\r
+  @param  This              Protocol instance pointer.\r
+  @param  ControllerHandle  Handle of device to stop driver on\r
+  @param  NumberOfChildren  Number of Handles in ChildHandleBuffer. If number of\r
+                            children is zero stop the entire bus driver.\r
+  @param  ChildHandleBuffer List of Child Handles to Stop.\r
+\r
+  @retval EFI_SUCCESS       This driver is removed ControllerHandle\r
+  @retval other             This driver was not removed from this device\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DiskIoDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL    *This,\r
+  IN  EFI_HANDLE                     ControllerHandle,\r
+  IN  UINTN                          NumberOfChildren,\r
+  IN  EFI_HANDLE                     *ChildHandleBuffer\r
+  )\r
+{\r
+  EFI_STATUS            Status;\r
+  EFI_DISK_IO_PROTOCOL  *DiskIo;\r
+  DISK_IO_PRIVATE_DATA  *Private;\r
+\r
+  //\r
+  // Get our context back.\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiDiskIoProtocolGuid,\r
+                  (VOID **) &DiskIo,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Private = DISK_IO_PRIVATE_DATA_FROM_THIS (DiskIo);\r
+\r
+  Status = gBS->UninstallProtocolInterface (\r
+                  ControllerHandle,\r
+                  &gEfiDiskIoProtocolGuid,\r
+                  &Private->DiskIo\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+\r
+    Status = gBS->CloseProtocol (\r
+                    ControllerHandle,\r
+                    &gEfiBlockIoProtocolGuid,\r
+                    This->DriverBindingHandle,\r
+                    ControllerHandle\r
+                    );\r
+  }\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    FreePool (Private);\r
+  }\r
+\r
+  return Status;\r
+}\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
+\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
+  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               LastRead;\r
+\r
+  Private   = DISK_IO_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  BlockIo   = Private->BlockIo;\r
+  Media     = BlockIo->Media;\r
+  BlockSize = Media->BlockSize;\r
+\r
+  if (Media->MediaId != MediaId) {\r
+    return EFI_MEDIA_CHANGED;\r
+  }\r
+\r
+  WorkingBuffer     = Buffer;\r
+  WorkingBufferSize = BufferSize;\r
+\r
+  //\r
+  // Allocate a temporary buffer for operation\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
+  }\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
+    }\r
+\r
+    if (Length > BufferSize) {\r
+      Length              = BufferSize;\r
+      TransactionComplete = TRUE;\r
+    }\r
+\r
+    CopyMem (WorkingBuffer, Data + UnderRun, Length);\r
+\r
+    WorkingBuffer += Length;\r
+\r
+    WorkingBufferSize -= Length;\r
+    if (WorkingBufferSize == 0) {\r
+      goto Done;\r
+    }\r
+\r
+    Lba += 1;\r
+  }\r
+\r
+  OverRunLba = Lba + DivU64x32Remainder (WorkingBufferSize, BlockSize, &OverRun);\r
+\r
+  if (!TransactionComplete && WorkingBufferSize >= BlockSize) {\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
+        goto Done;\r
+      }\r
+\r
+      WorkingBuffer += WorkingBufferSize;\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
+          //\r
+          // It is the last calling to readblocks in this loop\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
+        }\r
+\r
+        CopyMem (WorkingBuffer, Data, DataBufferSize);\r
+        WorkingBufferSize -= DataBufferSize;\r
+        WorkingBuffer += DataBufferSize;\r
+        Lba += DATA_BUFFER_BLOCK_NUM;\r
+      } while (!LastRead);\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
+\r
+    if (EFI_ERROR (Status)) {\r
+      goto Done;\r
+    }\r
+\r
+    CopyMem (WorkingBuffer, Data, OverRun);\r
+  }\r
+\r
+Done:\r
+  if (PreData != NULL) {\r
+    FreePool (PreData);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Read BufferSize bytes from Offset into Buffer.\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
+  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
+\r
+  Private   = DISK_IO_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  BlockIo   = Private->BlockIo;\r
+  Media     = BlockIo->Media;\r
+  BlockSize = Media->BlockSize;\r
+\r
+  if (Media->ReadOnly) {\r
+    return EFI_WRITE_PROTECTED;\r
+  }\r
+\r
+  if (Media->MediaId != MediaId) {\r
+    return EFI_MEDIA_CHANGED;\r
+  }\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
+  }\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
+    // Offset starts in the middle of an Lba, so do read modify write.\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
+    }\r
+\r
+    if (Length > BufferSize) {\r
+      Length              = BufferSize;\r
+      TransactionComplete = TRUE;\r
+    }\r
+\r
+    CopyMem (Data + UnderRun, WorkingBuffer, Length);\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
+\r
+    WorkingBuffer += Length;\r
+    WorkingBufferSize -= Length;\r
+    if (WorkingBufferSize == 0) {\r
+      goto Done;\r
+    }\r
+\r
+    Lba += 1;\r
+  }\r
+\r
+  OverRunLba = Lba + DivU64x32Remainder (WorkingBufferSize, BlockSize, &OverRun);\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
+    }\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 write them together\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
+      }\r
+\r
+      WorkingBuffer += WorkingBufferSize;\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
+      //\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
+                            BlockIo,\r
+                            MediaId,\r
+                            Lba,\r
+                            DataBufferSize,\r
+                            Data\r
+                            );\r
+        if (EFI_ERROR (Status)) {\r
+          goto Done;\r
+        }\r
+\r
+        WorkingBufferSize -= DataBufferSize;\r
+        WorkingBuffer += DataBufferSize;\r
+        Lba += DATA_BUFFER_BLOCK_NUM;\r
+      } while (!LastWrite);\r
+    }\r
+  }\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
+    if (EFI_ERROR (Status)) {\r
+      goto Done;\r
+    }\r
+\r
+    CopyMem (Data, WorkingBuffer, OverRun);\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
+    }\r
+  }\r
+\r
+Done:\r
+  if (PreData != NULL) {\r
+    FreePool (PreData);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  The user Entry Point for module DiskIo. The user code starts with this function.\r
+\r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.  \r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
+  \r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeDiskIo (\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+\r
+  //\r
+  // Install driver model protocol(s).\r
+  //\r
+  Status = EfiLibInstallAllDriverProtocols (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gDiskIoDriverBinding,\r
+             ImageHandle,\r
+             &gDiskIoComponentName,\r
+             NULL,\r
+             NULL\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+\r
+  return Status;\r
+}\r
+\r
diff --git a/MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIo.h b/MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIo.h
new file mode 100644 (file)
index 0000000..c1a572f
--- /dev/null
@@ -0,0 +1,124 @@
+/** @file\r
+  DiskIo driver that layers it's self on every Block IO protocol in the system.\r
+  DiskIo converts a block oriented device to a byte oriented device.\r
+\r
+  Copyright (c) 2006 - 2007, Intel Corporation                                              \r
+  All rights reserved. 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_IO_H\r
+#define _DISK_IO_H\r
+\r
+#include <Uefi.h>\r
+#include <Protocol/BlockIo.h>\r
+#include <Protocol/ComponentName.h>\r
+#include <Protocol/DriverBinding.h>\r
+#include <Protocol/DiskIo.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+\r
+#define DISK_IO_PRIVATE_DATA_SIGNATURE  EFI_SIGNATURE_32 ('d', 's', 'k', 'I')\r
+\r
+#define DATA_BUFFER_BLOCK_NUM           (64)\r
+\r
+typedef struct {\r
+  UINTN                 Signature;\r
+  EFI_DISK_IO_PROTOCOL  DiskIo;\r
+  EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
+} DISK_IO_PRIVATE_DATA;\r
+\r
+#define DISK_IO_PRIVATE_DATA_FROM_THIS(a) CR (a, DISK_IO_PRIVATE_DATA, DiskIo, DISK_IO_PRIVATE_DATA_SIGNATURE)\r
+\r
+//\r
+// Global Variables\r
+//\r
+extern EFI_DRIVER_BINDING_PROTOCOL  gDiskIoDriverBinding;\r
+extern EFI_COMPONENT_NAME_PROTOCOL  gDiskIoComponentName;\r
+\r
+//\r
+// Prototypes\r
+// Driver model protocol interface\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+DiskIoDriverBindingSupported (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL    *This,\r
+  IN EFI_HANDLE                     ControllerHandle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+DiskIoDriverBindingStart (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL    *This,\r
+  IN EFI_HANDLE                     ControllerHandle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+DiskIoDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL    *This,\r
+  IN  EFI_HANDLE                     ControllerHandle,\r
+  IN  UINTN                          NumberOfChildren,\r
+  IN  EFI_HANDLE                     *ChildHandleBuffer\r
+  );\r
+\r
+//\r
+// Disk I/O Protocol Interface\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
+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
+//\r
+// EFI Component Name Functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+DiskIoComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+DiskIoComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  );\r
+\r
+#endif\r
diff --git a/MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf b/MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf
new file mode 100644 (file)
index 0000000..27e7e50
--- /dev/null
@@ -0,0 +1,91 @@
+#/** @file\r
+#  Component description file for DiskIo module.\r
+#\r
+#  Copyright (c) 2006 - 2007, Intel Corporation\r
+#  All rights reserved. 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
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = DiskIoDxe\r
+  FILE_GUID                      = 6B38F7B4-AD98-40e9-9093-ACA2B5A253C4\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = InitializeDiskIo\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+#  DRIVER_BINDING                =  gDiskIoDriverBinding\r
+#  COMPONENT_NAME                =  gDiskIoComponentName\r
+#\r
+\r
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+  ComponentName.c\r
+  DiskIo.h\r
+  DiskIo.c\r
+\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+#                         this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  BaseMemoryLib\r
+  BaseLib\r
+  UefiLib\r
+  UefiDriverEntryPoint\r
+  DebugLib\r
+\r
+\r
+################################################################################\r
+#\r
+# Protocol C Name Section - list of Protocol and Protocol Notify C Names\r
+#                           that this module uses or produces.\r
+#\r
+################################################################################\r
+\r
+[Protocols]\r
+  gEfiDiskIoProtocolGuid                        # PROTOCOL BY_START\r
+  gEfiBlockIoProtocolGuid                       # PROTOCOL TO_START\r
+\r
diff --git a/MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.msa b/MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.msa
new file mode 100644 (file)
index 0000000..b6b0960
--- /dev/null
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+  <MsaHeader>\r
+    <ModuleName>DiskIoDxe</ModuleName>\r
+    <ModuleType>UEFI_DRIVER</ModuleType>\r
+    <GuidValue>6B38F7B4-AD98-40e9-9093-ACA2B5A253C4</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Component description file for DiskIo module.</Abstract>\r
+    <Description>DiskIo driver that layers it's self on every Block IO protocol in the system.</Description>\r
+    <Copyright>Copyright (c) 2006 - 2007, Intel Corporation</Copyright>\r
+    <License>All rights reserved. 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
+      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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>DiskIoDxe</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED" RecommendedInstanceGuid="bda39d3a-451b-4350-8266-81ab10fa0523">\r
+      <Keyword>DebugLib</Keyword>\r
+      <HelpText>Recommended libary Instance is PeiDxeDebugLibReportStatusCode instance in MdePkg.</HelpText>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverModelLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <FilenameDiskIo.c</Filename>\r
+    <Filename>DiskIo.h</Filename>\r
+    <Filename>ComponentName.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="TO_START">\r
+      <ProtocolCName>gEfiBlockIoProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="BY_START">\r
+      <ProtocolCName>gEfiDiskIoProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <DriverBinding>gDiskIoDriverBinding</DriverBinding>\r
+      <ComponentName>gDiskIoComponentName</ComponentName>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>\r
diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/ComponentName.c b/MdeModulePkg/Universal/Disk/PartitionDxe/ComponentName.c
new file mode 100644 (file)
index 0000000..e922cb0
--- /dev/null
@@ -0,0 +1,173 @@
+/** @file\r
+  UEFI Component Name protocol for Partition driver.\r
+  \r
+  Copyright (c) 2006 - 2007, Intel Corporation                                              \r
+  All rights reserved. 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
+#include "Partition.h"\r
+\r
+//\r
+// EFI Component Name Protocol\r
+//\r
+EFI_COMPONENT_NAME_PROTOCOL     gPartitionComponentName = {\r
+  PartitionComponentNameGetDriverName,\r
+  PartitionComponentNameGetControllerName,\r
+  "eng"\r
+};\r
+\r
+static EFI_UNICODE_STRING_TABLE mPartitionDriverNameTable[] = {\r
+  {\r
+    "eng",\r
+    (CHAR16 *)L"Partition Driver(MBR/GPT/El Torito)"\r
+  },\r
+  {\r
+    NULL,\r
+    NULL\r
+  }\r
+};\r
+\r
+\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of\r
+  the EFI Driver.\r
+\r
+  @param  This       A pointer to the\r
+                     EFI_COMPONENT_NAME_PROTOCOL instance.\r
+  \r
+  @param  Language   A pointer to a Null-terminated ASCII string\r
+                     array indicating the language. This is the\r
+                     language of the driver name that the caller\r
+                     is requesting, and it must match one of the\r
+                     languages specified in SupportedLanguages.\r
+                     The number of languages supported by a\r
+                     driver is up to the driver writer. Language\r
+                     is specified in RFC 3066 language code\r
+                     format.\r
+  \r
+  @param  DriverName A pointer to the Unicode string to return.\r
+                     This Unicode string is the name of the\r
+                     driver specified by This in the language\r
+                     specified by Language.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the\r
+                                Driver specified by This and the\r
+                                language specified by Language\r
+                                was returned in DriverName.\r
+  \r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+  \r
+  @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
+  \r
+  @retval EFI_UNSUPPORTED       The driver specified by This\r
+                                does not support the language\r
+                                specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PartitionComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  )\r
+{\r
+  return LookupUnicodeString (\r
+          Language,\r
+          gPartitionComponentName.SupportedLanguages,\r
+          mPartitionDriverNameTable,\r
+          DriverName\r
+          );\r
+}\r
+\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of\r
+  the controller that is being managed by an EFI Driver.\r
+\r
+  @param  This             A pointer to the\r
+                           EFI_COMPONENT_NAME_PROTOCOL instance.\r
+\r
+  @param  ControllerHandle The handle of a controller that the\r
+                           driver specified by This is managing.\r
+                           This handle specifies the controller\r
+                           whose name is to be returned.\r
+\r
+  @param ChildHandle      The handle of the child controller to\r
+                           retrieve the name of.  This is an\r
+                           optional parameter that may be NULL.\r
+                           It will be NULL for device drivers.\r
+                           It will also be NULL for a bus\r
+                           drivers that wish to retrieve the\r
+                           name of the bus controller.  It will\r
+                           not be NULL for a bus driver that\r
+                           wishes to retrieve the name of a\r
+                           child controller.\r
+\r
+  @param  Language         A pointer to a Null-terminated ASCII\r
+                           string array indicating the language.\r
+                           This is the language of the driver\r
+                           name that the caller is requesting,\r
+                           and it must match one of the\r
+                           languages specified in\r
+                           SupportedLanguages. The number of\r
+                           languages supported by a driver is up\r
+                           to the driver writer. Language is\r
+                           specified in RFC 3066 language code\r
+                           format.\r
+\r
+  @param  ControllerName   A pointer to the Unicode string to\r
+                           return.  This Unicode string is the\r
+                           name of the controller specified by\r
+                           ControllerHandle and ChildHandle in\r
+                           the language specified by Language\r
+                           from the point of view of the driver\r
+                           specified by This.\r
+\r
+  @retval EFI_SUCCESS           The Unicode string for the user\r
+                                readable name in the language\r
+                                specified by Language for the\r
+                                driver specified by This was\r
+                                returned in DriverName.\r
+\r
+  @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid\r
+                                EFI_HANDLE.\r
+\r
+  @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it\r
+                                is not a valid EFI_HANDLE.\r
+\r
+  @retval EFI_INVALID_PARAMETER Language is NULL.\r
+\r
+  @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This is\r
+                                not currently managing the\r
+                                controller specified by\r
+                                ControllerHandle and\r
+                                ChildHandle.\r
+\r
+  @retval EFI_UNSUPPORTED       The driver specified by This\r
+                                does not support the language\r
+                                specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PartitionComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/ElTorito.c b/MdeModulePkg/Universal/Disk/PartitionDxe/ElTorito.c
new file mode 100644 (file)
index 0000000..37ac710
--- /dev/null
@@ -0,0 +1,275 @@
+/** @file\r
+  Decode an El Torito formatted CD-ROM\r
+\r
+  Copyright (c) 2006 - 2007, Intel Corporation                                              \r
+  All rights reserved. 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
+\r
+#include "Partition.h"\r
+\r
+\r
+/**\r
+  Install child handles if the Handle supports El Torito format.\r
+\r
+  @param[in]  This        Calling context.\r
+  @param[in]  Handle      Parent Handle\r
+  @param[in]  DiskIo      Parent DiskIo interface\r
+  @param[in]  BlockIo     Parent BlockIo interface\r
+  @param[in]  DevicePath  Parent Device Path\r
+\r
+\r
+  @retval EFI_SUCCESS         Child handle(s) was added\r
+  @retval EFI_MEDIA_CHANGED   Media changed Detected\r
+  @retval other               no child handle was added\r
+\r
+**/\r
+EFI_STATUS\r
+PartitionInstallElToritoChildHandles (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Handle,\r
+  IN  EFI_DISK_IO_PROTOCOL         *DiskIo,\r
+  IN  EFI_BLOCK_IO_PROTOCOL        *BlockIo,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *DevicePath\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  UINT32                  VolDescriptorLba;\r
+  UINT32                  Lba;\r
+  EFI_BLOCK_IO_MEDIA      *Media;\r
+  CDROM_VOLUME_DESCRIPTOR *VolDescriptor;\r
+  ELTORITO_CATALOG        *Catalog;\r
+  UINTN                   Check;\r
+  UINTN                   Index;\r
+  UINTN                   BootEntry;\r
+  UINTN                   MaxIndex;\r
+  UINT16                  *CheckBuffer;\r
+  CDROM_DEVICE_PATH       CdDev;\r
+  UINT32                  SubBlockSize;\r
+  UINT32                  SectorCount;\r
+  EFI_STATUS              Found;\r
+  UINT32                  VolSpaceSize;\r
+\r
+  Found         = EFI_NOT_FOUND;\r
+  Media         = BlockIo->Media;\r
+  VolSpaceSize  = 0;\r
+\r
+  //\r
+  // CD_ROM has the fixed block size as 2048 bytes\r
+  //\r
+  if (Media->BlockSize != 2048) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  VolDescriptor = AllocatePool ((UINTN) Media->BlockSize);\r
+\r
+  if (VolDescriptor == NULL) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  Catalog = (ELTORITO_CATALOG *) VolDescriptor;\r
+\r
+  //\r
+  // the ISO-9660 volume descriptor starts at 32k on the media\r
+  // and CD_ROM has the fixed block size as 2048 bytes, so...\r
+  //\r
+  //\r
+  // ((16*2048) / Media->BlockSize) - 1;\r
+  //\r
+  VolDescriptorLba = 15;\r
+  //\r
+  // Loop: handle one volume descriptor per time\r
+  //\r
+  while (TRUE) {\r
+\r
+    VolDescriptorLba += 1;\r
+    if (VolDescriptorLba > Media->LastBlock) {\r
+      //\r
+      // We are pointing past the end of the device so exit\r
+      //\r
+      break;\r
+    }\r
+\r
+    Status = BlockIo->ReadBlocks (\r
+                        BlockIo,\r
+                        Media->MediaId,\r
+                        VolDescriptorLba,\r
+                        Media->BlockSize,\r
+                        VolDescriptor\r
+                        );\r
+    if (EFI_ERROR (Status)) {\r
+      Found = Status;\r
+      break;\r
+    }\r
+    //\r
+    // Check for valid volume descriptor signature\r
+    //\r
+    if (VolDescriptor->Type == CDVOL_TYPE_END ||\r
+        CompareMem (VolDescriptor->Id, CDVOL_ID, sizeof (VolDescriptor->Id)) != 0\r
+        ) {\r
+      //\r
+      // end of Volume descriptor list\r
+      //\r
+      break;\r
+    }\r
+    //\r
+    // Read the Volume Space Size from Primary Volume Descriptor 81-88 byte,\r
+    // the 32-bit numerical values is stored in Both-byte orders\r
+    //\r
+    if (VolDescriptor->Type == CDVOL_TYPE_CODED) {\r
+      VolSpaceSize = VolDescriptor->VolSpaceSize[0];\r
+    }\r
+    //\r
+    // Is it an El Torito volume descriptor?\r
+    //\r
+    if (CompareMem (VolDescriptor->SystemId, CDVOL_ELTORITO_ID, sizeof (CDVOL_ELTORITO_ID) - 1) != 0) {\r
+      continue;\r
+    }\r
+    //\r
+    // Read in the boot El Torito boot catalog\r
+    //\r
+    Lba = UNPACK_INT32 (VolDescriptor->EltCatalog);\r
+    if (Lba > Media->LastBlock) {\r
+      continue;\r
+    }\r
+\r
+    Status = BlockIo->ReadBlocks (\r
+                        BlockIo,\r
+                        Media->MediaId,\r
+                        Lba,\r
+                        Media->BlockSize,\r
+                        Catalog\r
+                        );\r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG ((EFI_D_ERROR, "EltCheckDevice: error reading catalog %r\n", Status));\r
+      continue;\r
+    }\r
+    //\r
+    // We don't care too much about the Catalog header's contents, but we do want\r
+    // to make sure it looks like a Catalog header\r
+    //\r
+    if (Catalog->Catalog.Indicator != ELTORITO_ID_CATALOG || Catalog->Catalog.Id55AA != 0xAA55) {\r
+      DEBUG ((EFI_D_ERROR, "EltCheckBootCatalog: El Torito boot catalog header IDs not correct\n"));\r
+      continue;\r
+    }\r
+\r
+    Check       = 0;\r
+    CheckBuffer = (UINT16 *) Catalog;\r
+    for (Index = 0; Index < sizeof (ELTORITO_CATALOG) / sizeof (UINT16); Index += 1) {\r
+      Check += CheckBuffer[Index];\r
+    }\r
+\r
+    if (Check & 0xFFFF) {\r
+      DEBUG ((EFI_D_ERROR, "EltCheckBootCatalog: El Torito boot catalog header checksum failed\n"));\r
+      continue;\r
+    }\r
+\r
+    MaxIndex = Media->BlockSize / sizeof (ELTORITO_CATALOG);\r
+    for (Index = 1, BootEntry = 1; Index < MaxIndex; Index += 1) {\r
+      //\r
+      // Next entry\r
+      //\r
+      Catalog += 1;\r
+\r
+      //\r
+      // Check this entry\r
+      //\r
+      if (Catalog->Boot.Indicator != ELTORITO_ID_SECTION_BOOTABLE || Catalog->Boot.Lba == 0) {\r
+        continue;\r
+      }\r
+\r
+      SubBlockSize  = 512;\r
+      SectorCount   = Catalog->Boot.SectorCount;\r
+\r
+      switch (Catalog->Boot.MediaType) {\r
+\r
+      case ELTORITO_NO_EMULATION:\r
+        SubBlockSize = Media->BlockSize;\r
+        break;\r
+\r
+      case ELTORITO_HARD_DISK:\r
+        break;\r
+\r
+      case ELTORITO_12_DISKETTE:\r
+        SectorCount = 0x50 * 0x02 * 0x0F;\r
+        break;\r
+\r
+      case ELTORITO_14_DISKETTE:\r
+        SectorCount = 0x50 * 0x02 * 0x12;\r
+        break;\r
+\r
+      case ELTORITO_28_DISKETTE:\r
+        SectorCount = 0x50 * 0x02 * 0x24;\r
+        break;\r
+\r
+      default:\r
+        DEBUG ((EFI_D_INIT, "EltCheckDevice: unsupported El Torito boot media type %x\n", Catalog->Boot.MediaType));\r
+        SectorCount   = 0;\r
+        SubBlockSize  = Media->BlockSize;\r
+        break;\r
+      }\r
+      //\r
+      // Create child device handle\r
+      //\r
+      CdDev.Header.Type     = MEDIA_DEVICE_PATH;\r
+      CdDev.Header.SubType  = MEDIA_CDROM_DP;\r
+      SetDevicePathNodeLength (&CdDev.Header, sizeof (CdDev));\r
+\r
+      if (Index == 1) {\r
+        //\r
+        // This is the initial/default entry\r
+        //\r
+        BootEntry = 0;\r
+      }\r
+\r
+      CdDev.BootEntry = (UINT32) BootEntry;\r
+      BootEntry++;\r
+      CdDev.PartitionStart = Catalog->Boot.Lba;\r
+      if (SectorCount < 2) {\r
+        //\r
+        // When the SectorCount < 2, set the Partition as the whole CD.\r
+        //\r
+        if (VolSpaceSize > (Media->LastBlock + 1)) {\r
+          CdDev.PartitionSize = (UINT32)(Media->LastBlock - Catalog->Boot.Lba + 1);\r
+        } else {\r
+          CdDev.PartitionSize = (UINT32)(VolSpaceSize - Catalog->Boot.Lba);\r
+        }\r
+      } else {\r
+        CdDev.PartitionSize = DivU64x32 (\r
+                                MultU64x32 (\r
+                                  SectorCount,\r
+                                  SubBlockSize\r
+                                  ) + Media->BlockSize - 1,\r
+                                Media->BlockSize\r
+                                );\r
+      }\r
+\r
+      Status = PartitionInstallChildHandle (\r
+                This,\r
+                Handle,\r
+                DiskIo,\r
+                BlockIo,\r
+                DevicePath,\r
+                (EFI_DEVICE_PATH_PROTOCOL *) &CdDev,\r
+                Catalog->Boot.Lba,\r
+                Catalog->Boot.Lba + CdDev.PartitionSize - 1,\r
+                SubBlockSize,\r
+                FALSE\r
+                );\r
+      if (!EFI_ERROR (Status)) {\r
+        Found = EFI_SUCCESS;\r
+      }\r
+    }\r
+  }\r
+\r
+  FreePool (VolDescriptor);\r
+\r
+  return Found;\r
+}\r
diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Gpt.c b/MdeModulePkg/Universal/Disk/PartitionDxe/Gpt.c
new file mode 100644 (file)
index 0000000..581007e
--- /dev/null
@@ -0,0 +1,720 @@
+/** @file\r
+  Decode a hard disk partitioned with the GPT scheme in the EFI 1.0\r
+  specification.\r
+\r
+  Copyright (c) 2006 - 2007, Intel Corporation                                              \r
+  All rights reserved. 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
+\r
+#include "Partition.h"\r
+\r
+\r
+BOOLEAN\r
+PartitionValidGptTable (\r
+  IN  EFI_BLOCK_IO_PROTOCOL       *BlockIo,\r
+  IN  EFI_DISK_IO_PROTOCOL        *DiskIo,\r
+  IN  EFI_LBA                     Lba,\r
+  OUT EFI_PARTITION_TABLE_HEADER  *PartHeader\r
+  );\r
+\r
+\r
+BOOLEAN\r
+PartitionCheckGptEntryArrayCRC (\r
+  IN  EFI_BLOCK_IO_PROTOCOL       *BlockIo,\r
+  IN  EFI_DISK_IO_PROTOCOL        *DiskIo,\r
+  IN  EFI_PARTITION_TABLE_HEADER  *PartHeader\r
+  );\r
+\r
+\r
+BOOLEAN\r
+PartitionRestoreGptTable (\r
+  IN  EFI_BLOCK_IO_PROTOCOL       *BlockIo,\r
+  IN  EFI_DISK_IO_PROTOCOL        *DiskIo,\r
+  IN  EFI_PARTITION_TABLE_HEADER  *PartHeader\r
+  );\r
+\r
+\r
+VOID\r
+PartitionCheckGptEntry (\r
+  IN  EFI_PARTITION_TABLE_HEADER  *PartHeader,\r
+  IN  EFI_PARTITION_ENTRY         *PartEntry,\r
+  OUT EFI_PARTITION_ENTRY_STATUS  *PEntryStatus\r
+  );\r
+\r
+\r
+BOOLEAN\r
+PartitionCheckCrcAltSize (\r
+  IN UINTN                 MaxSize,\r
+  IN UINTN                 Size,\r
+  IN OUT EFI_TABLE_HEADER  *Hdr\r
+  );\r
+\r
+\r
+BOOLEAN\r
+PartitionCheckCrc (\r
+  IN UINTN                 MaxSize,\r
+  IN OUT EFI_TABLE_HEADER  *Hdr\r
+  );\r
+\r
+\r
+VOID\r
+PartitionSetCrcAltSize (\r
+  IN UINTN                 Size,\r
+  IN OUT EFI_TABLE_HEADER  *Hdr\r
+  );\r
+\r
+\r
+VOID\r
+PartitionSetCrc (\r
+  IN OUT EFI_TABLE_HEADER *Hdr\r
+  );\r
+\r
+/**\r
+  Install child handles if the Handle supports GPT partition structure.\r
+\r
+  @param[in]  This       - Calling context.\r
+  @param[in]  Handle     - Parent Handle\r
+  @param[in]  DiskIo     - Parent DiskIo interface\r
+  @param[in]  BlockIo    - Parent BlockIo interface\r
+  @param[in]  DevicePath - Parent Device Path\r
+\r
+  @retval EFI_SUCCESS         Valid GPT disk\r
+  @retval EFI_MEDIA_CHANGED   Media changed Detected\r
+  @retval other               Not a valid GPT disk\r
+\r
+**/\r
+EFI_STATUS\r
+PartitionInstallGptChildHandles (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Handle,\r
+  IN  EFI_DISK_IO_PROTOCOL         *DiskIo,\r
+  IN  EFI_BLOCK_IO_PROTOCOL        *BlockIo,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *DevicePath\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+  UINT32                      BlockSize;\r
+  EFI_LBA                     LastBlock;\r
+  MASTER_BOOT_RECORD          *ProtectiveMbr;\r
+  EFI_PARTITION_TABLE_HEADER  *PrimaryHeader;\r
+  EFI_PARTITION_TABLE_HEADER  *BackupHeader;\r
+  EFI_PARTITION_ENTRY         *PartEntry;\r
+  EFI_PARTITION_ENTRY_STATUS  *PEntryStatus;\r
+  UINTN                       Index;\r
+  EFI_STATUS                  GptValid;\r
+  HARDDRIVE_DEVICE_PATH       HdDev;\r
+\r
+  ProtectiveMbr = NULL;\r
+  PrimaryHeader = NULL;\r
+  BackupHeader  = NULL;\r
+  PartEntry     = NULL;\r
+  PEntryStatus  = NULL;\r
+\r
+  BlockSize     = BlockIo->Media->BlockSize;\r
+  LastBlock     = BlockIo->Media->LastBlock;\r
+\r
+  DEBUG ((EFI_D_INFO, " BlockSize : %d \n", BlockSize));\r
+  DEBUG ((EFI_D_INFO, " LastBlock : %x \n", LastBlock));\r
+\r
+  GptValid = EFI_NOT_FOUND;\r
+\r
+  //\r
+  // Allocate a buffer for the Protective MBR\r
+  //\r
+  ProtectiveMbr = AllocatePool (BlockSize);\r
+  if (ProtectiveMbr == NULL) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  //\r
+  // Read the Protective MBR from LBA #0\r
+  //\r
+  Status = BlockIo->ReadBlocks (\r
+                      BlockIo,\r
+                      BlockIo->Media->MediaId,\r
+                      0,\r
+                      BlockIo->Media->BlockSize,\r
+                      ProtectiveMbr\r
+                      );\r
+  if (EFI_ERROR (Status)) {\r
+    GptValid = Status;\r
+    goto Done;\r
+  }\r
+  //\r
+  // Verify that the Protective MBR is valid\r
+  //\r
+  if (ProtectiveMbr->Partition[0].BootIndicator != 0x00 ||\r
+      ProtectiveMbr->Partition[0].OSIndicator != PMBR_GPT_PARTITION ||\r
+      UNPACK_UINT32 (ProtectiveMbr->Partition[0].StartingLBA) != 1\r
+      ) {\r
+    goto Done;\r
+  }\r
+\r
+  //\r
+  // Allocate the GPT structures\r
+  //\r
+  PrimaryHeader = AllocateZeroPool (sizeof (EFI_PARTITION_TABLE_HEADER));\r
+  if (PrimaryHeader == NULL) {\r
+    goto Done;\r
+  }\r
+\r
+  BackupHeader = AllocateZeroPool (sizeof (EFI_PARTITION_TABLE_HEADER));\r
+\r
+  if (BackupHeader == NULL) {\r
+    goto Done;\r
+  }\r
+\r
+  //\r
+  // Check primary and backup partition tables\r
+  //\r
+  if (!PartitionValidGptTable (BlockIo, DiskIo, PRIMARY_PART_HEADER_LBA, PrimaryHeader)) {\r
+    DEBUG ((EFI_D_INFO, " Not Valid primary partition table\n"));\r
+\r
+    if (!PartitionValidGptTable (BlockIo, DiskIo, LastBlock, BackupHeader)) {\r
+      DEBUG ((EFI_D_INFO, " Not Valid backup partition table\n"));\r
+      goto Done;\r
+    } else {\r
+      DEBUG ((EFI_D_INFO, " Valid backup partition table\n"));\r
+      DEBUG ((EFI_D_INFO, " Restore primary partition table by the backup\n"));\r
+      if (!PartitionRestoreGptTable (BlockIo, DiskIo, BackupHeader)) {\r
+        DEBUG ((EFI_D_INFO, " Restore primary partition table error\n"));\r
+      }\r
+\r
+      if (PartitionValidGptTable (BlockIo, DiskIo, BackupHeader->AlternateLBA, PrimaryHeader)) {\r
+        DEBUG ((EFI_D_INFO, " Restore backup partition table success\n"));\r
+      }\r
+    }\r
+  } else if (!PartitionValidGptTable (BlockIo, DiskIo, PrimaryHeader->AlternateLBA, BackupHeader)) {\r
+    DEBUG ((EFI_D_INFO, " Valid primary and !Valid backup partition table\n"));\r
+    DEBUG ((EFI_D_INFO, " Restore backup partition table by the primary\n"));\r
+    if (!PartitionRestoreGptTable (BlockIo, DiskIo, PrimaryHeader)) {\r
+      DEBUG ((EFI_D_INFO, " Restore  backup partition table error\n"));\r
+    }\r
+\r
+    if (PartitionValidGptTable (BlockIo, DiskIo, PrimaryHeader->AlternateLBA, BackupHeader)) {\r
+      DEBUG ((EFI_D_INFO, " Restore backup partition table success\n"));\r
+    }\r
+\r
+  }\r
+\r
+  DEBUG ((EFI_D_INFO, " Valid primary and Valid backup partition table\n"));\r
+\r
+  //\r
+  // Read the EFI Partition Entries\r
+  //\r
+  PartEntry = AllocatePool (PrimaryHeader->NumberOfPartitionEntries * sizeof (EFI_PARTITION_ENTRY));\r
+  if (PartEntry == NULL) {\r
+    DEBUG ((EFI_D_ERROR, "Allocate pool error\n"));\r
+    goto Done;\r
+  }\r
+\r
+  Status = DiskIo->ReadDisk (\r
+                    DiskIo,\r
+                    BlockIo->Media->MediaId,\r
+                    MultU64x32(PrimaryHeader->PartitionEntryLBA, BlockSize),\r
+                    PrimaryHeader->NumberOfPartitionEntries * (PrimaryHeader->SizeOfPartitionEntry),\r
+                    PartEntry\r
+                    );\r
+  if (EFI_ERROR (Status)) {\r
+    GptValid = Status;\r
+    DEBUG ((EFI_D_INFO, " Partition Entry ReadBlocks error\n"));\r
+    goto Done;\r
+  }\r
+\r
+  DEBUG ((EFI_D_INFO, " Partition entries read block success\n"));\r
+\r
+  DEBUG ((EFI_D_INFO, " Number of partition entries: %d\n", PrimaryHeader->NumberOfPartitionEntries));\r
+\r
+  PEntryStatus = AllocateZeroPool (PrimaryHeader->NumberOfPartitionEntries * sizeof (EFI_PARTITION_ENTRY_STATUS));\r
+  if (PEntryStatus == NULL) {\r
+    DEBUG ((EFI_D_ERROR, "Allocate pool error\n"));\r
+    goto Done;\r
+  }\r
+\r
+  //\r
+  // Check the integrity of partition entries\r
+  //\r
+  PartitionCheckGptEntry (PrimaryHeader, PartEntry, PEntryStatus);\r
+\r
+  //\r
+  // If we got this far the GPT layout of the disk is valid and we should return true\r
+  //\r
+  GptValid = EFI_SUCCESS;\r
+\r
+  //\r
+  // Create child device handles\r
+  //\r
+  for (Index = 0; Index < PrimaryHeader->NumberOfPartitionEntries; Index++) {\r
+    if (CompareGuid (&PartEntry[Index].PartitionTypeGUID, &gEfiPartTypeUnusedGuid) ||\r
+        PEntryStatus[Index].OutOfRange ||\r
+        PEntryStatus[Index].Overlap\r
+        ) {\r
+      //\r
+      // Don't use null EFI Partition Entries or Invalid Partition Entries\r
+      //\r
+      continue;\r
+    }\r
+\r
+    ZeroMem (&HdDev, sizeof (HdDev));\r
+    HdDev.Header.Type     = MEDIA_DEVICE_PATH;\r
+    HdDev.Header.SubType  = MEDIA_HARDDRIVE_DP;\r
+    SetDevicePathNodeLength (&HdDev.Header, sizeof (HdDev));\r
+\r
+    HdDev.PartitionNumber = (UINT32) Index + 1;\r
+    HdDev.MBRType         = MBR_TYPE_EFI_PARTITION_TABLE_HEADER;\r
+    HdDev.SignatureType   = SIGNATURE_TYPE_GUID;\r
+    HdDev.PartitionStart  = PartEntry[Index].StartingLBA;\r
+    HdDev.PartitionSize   = PartEntry[Index].EndingLBA - PartEntry[Index].StartingLBA + 1;\r
+    CopyMem (HdDev.Signature, &PartEntry[Index].UniquePartitionGUID, sizeof (EFI_GUID));\r
+\r
+    DEBUG ((EFI_D_INFO, " Index : %d\n", Index));\r
+    DEBUG ((EFI_D_INFO, " Start LBA : %x\n", HdDev.PartitionStart));\r
+    DEBUG ((EFI_D_INFO, " End LBA : %x\n", PartEntry[Index].EndingLBA));\r
+    DEBUG ((EFI_D_INFO, " Partition size: %x\n", HdDev.PartitionSize));\r
+    DEBUG ((EFI_D_INFO, " Start : %x", MultU64x32 (PartEntry[Index].StartingLBA, BlockSize)));\r
+    DEBUG ((EFI_D_INFO, " End : %x\n", MultU64x32 (PartEntry[Index].EndingLBA, BlockSize)));\r
+\r
+    Status = PartitionInstallChildHandle (\r
+              This,\r
+              Handle,\r
+              DiskIo,\r
+              BlockIo,\r
+              DevicePath,\r
+              (EFI_DEVICE_PATH_PROTOCOL *) &HdDev,\r
+              PartEntry[Index].StartingLBA,\r
+              PartEntry[Index].EndingLBA,\r
+              BlockSize,\r
+              CompareGuid(&PartEntry[Index].PartitionTypeGUID, &gEfiPartTypeSystemPartGuid)\r
+              );\r
+  }\r
+\r
+  DEBUG ((EFI_D_INFO, "Prepare to Free Pool\n"));\r
+\r
+Done:\r
+  if (ProtectiveMbr != NULL) {\r
+    FreePool (ProtectiveMbr);\r
+  }\r
+  if (PrimaryHeader != NULL) {\r
+    FreePool (PrimaryHeader);\r
+  }\r
+  if (BackupHeader != NULL) {\r
+    FreePool (BackupHeader);\r
+  }\r
+  if (PartEntry != NULL) {\r
+    FreePool (PartEntry);\r
+  }\r
+  if (PEntryStatus != NULL) {\r
+    FreePool (PEntryStatus);\r
+  }\r
+\r
+  return GptValid;\r
+}\r
+\r
+\r
+/**\r
+  Install child handles if the Handle supports GPT partition structure.\r
+\r
+  @param[in]  BlockIo     Parent BlockIo interface\r
+  @param[in]  DiskIo      Disk Io protocol.\r
+  @param[in]  Lba         The starting Lba of the Partition Table\r
+  @param[in]  PartHeader  Stores the partition table that is read\r
+\r
+  @retval TRUE      The partition table is valid\r
+  @retval FALSE     The partition table is not valid\r
+\r
+**/\r
+BOOLEAN\r
+PartitionValidGptTable (\r
+  IN  EFI_BLOCK_IO_PROTOCOL       *BlockIo,\r
+  IN  EFI_DISK_IO_PROTOCOL        *DiskIo,\r
+  IN  EFI_LBA                     Lba,\r
+  OUT EFI_PARTITION_TABLE_HEADER  *PartHeader\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+  UINT32                      BlockSize;\r
+  EFI_PARTITION_TABLE_HEADER  *PartHdr;\r
+\r
+  BlockSize = BlockIo->Media->BlockSize;\r
+\r
+  PartHdr   = AllocateZeroPool (BlockSize);\r
+\r
+  if (PartHdr == NULL) {\r
+    DEBUG ((EFI_D_ERROR, "Allocate pool error\n"));\r
+    return FALSE;\r
+  }\r
+  //\r
+  // Read the EFI Partition Table Header\r
+  //\r
+  Status = BlockIo->ReadBlocks (\r
+                      BlockIo,\r
+                      BlockIo->Media->MediaId,\r
+                      Lba,\r
+                      BlockSize,\r
+                      PartHdr\r
+                      );\r
+  if (EFI_ERROR (Status)) {\r
+    FreePool (PartHdr);\r
+    return FALSE;\r
+  }\r
+\r
+  if ((PartHdr->Header.Signature == EFI_PTAB_HEADER_ID) ||\r
+      !PartitionCheckCrc (BlockSize, &PartHdr->Header) ||\r
+      PartHdr->MyLBA != Lba\r
+      ) {\r
+    DEBUG ((EFI_D_INFO, " !Valid efi partition table header\n"));\r
+    FreePool (PartHdr);\r
+    return FALSE;\r
+  }\r
+\r
+  CopyMem (PartHeader, PartHdr, sizeof (EFI_PARTITION_TABLE_HEADER));\r
+  if (!PartitionCheckGptEntryArrayCRC (BlockIo, DiskIo, PartHeader)) {\r
+    FreePool (PartHdr);\r
+    return FALSE;\r
+  }\r
+\r
+  DEBUG ((EFI_D_INFO, " Valid efi partition table header\n"));\r
+  FreePool (PartHdr);\r
+  return TRUE;\r
+}\r
+\r
+\r
+/**\r
+  Check if the CRC field in the Partition table header is valid\r
+  for Partition entry array.\r
+\r
+  @param[in]  BlockIo     Parent BlockIo interface\r
+  @param[in]  DiskIo      Disk Io Protocol.\r
+  @param[in]  PartHeader  Partition table header structure\r
+\r
+  @retval TRUE      the CRC is valid\r
+  @retval FALSE     the CRC is invalid\r
+\r
+**/\r
+BOOLEAN\r
+PartitionCheckGptEntryArrayCRC (\r
+  IN  EFI_BLOCK_IO_PROTOCOL       *BlockIo,\r
+  IN  EFI_DISK_IO_PROTOCOL        *DiskIo,\r
+  IN  EFI_PARTITION_TABLE_HEADER  *PartHeader\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  UINT8       *Ptr;\r
+  UINT32      Crc;\r
+  UINTN       Size;\r
+\r
+  //\r
+  // Read the EFI Partition Entries\r
+  //\r
+  Ptr = AllocatePool (PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry);\r
+  if (Ptr == NULL) {\r
+    DEBUG ((EFI_D_ERROR, " Allocate pool error\n"));\r
+    return FALSE;\r
+  }\r
+\r
+  Status = DiskIo->ReadDisk (\r
+                    DiskIo,\r
+                    BlockIo->Media->MediaId,\r
+                    MultU64x32(PartHeader->PartitionEntryLBA, BlockIo->Media->BlockSize),\r
+                    PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry,\r
+                    Ptr\r
+                    );\r
+  if (EFI_ERROR (Status)) {\r
+    FreePool (Ptr);\r
+    return FALSE;\r
+  }\r
+\r
+  Size    = PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry;\r
+\r
+  Status  = gBS->CalculateCrc32 (Ptr, Size, &Crc);\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_ERROR, "CheckPEntryArrayCRC: Crc calculation failed\n"));\r
+    FreePool (Ptr);\r
+    return FALSE;\r
+  }\r
+\r
+  FreePool (Ptr);\r
+\r
+  return (BOOLEAN) (PartHeader->PartitionEntryArrayCRC32 == Crc);\r
+}\r
+\r
+\r
+/**\r
+  Restore Partition Table to its alternate place\r
+  (Primary -> Backup or Backup -> Primary)\r
+\r
+  @param[in]  BlockIo     Parent BlockIo interface\r
+  @param[in]  DiskIo      Disk Io Protocol.\r
+  @param[in]  PartHeader  Partition table header structure\r
+\r
+  @retval TRUE      Restoring succeeds\r
+  @retval FALSE     Restoring failed\r
+\r
+**/\r
+BOOLEAN\r
+PartitionRestoreGptTable (\r
+  IN  EFI_BLOCK_IO_PROTOCOL       *BlockIo,\r
+  IN  EFI_DISK_IO_PROTOCOL        *DiskIo,\r
+  IN  EFI_PARTITION_TABLE_HEADER  *PartHeader\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+  UINTN                       BlockSize;\r
+  EFI_PARTITION_TABLE_HEADER  *PartHdr;\r
+  EFI_LBA                     PEntryLBA;\r
+  UINT8                       *Ptr;\r
+\r
+  PartHdr   = NULL;\r
+  Ptr       = NULL;\r
+\r
+  BlockSize = BlockIo->Media->BlockSize;\r
+\r
+  PartHdr   = AllocateZeroPool (BlockSize);\r
+\r
+  if (PartHdr == NULL) {\r
+    DEBUG ((EFI_D_ERROR, "Allocate pool error\n"));\r
+    return FALSE;\r
+  }\r
+\r
+  PEntryLBA = (PartHeader->MyLBA == PRIMARY_PART_HEADER_LBA) ? \\r
+                             (PartHeader->LastUsableLBA + 1) : \\r
+                             (PRIMARY_PART_HEADER_LBA + 1);\r
+\r
+  CopyMem (PartHdr, PartHeader, sizeof (EFI_PARTITION_TABLE_HEADER));\r
+\r
+  PartHdr->MyLBA              = PartHeader->AlternateLBA;\r
+  PartHdr->AlternateLBA       = PartHeader->MyLBA;\r
+  PartHdr->PartitionEntryLBA  = PEntryLBA;\r
+  PartitionSetCrc ((EFI_TABLE_HEADER *) PartHdr);\r
+\r
+  Status = BlockIo->WriteBlocks (BlockIo, BlockIo->Media->MediaId, PartHdr->MyLBA, BlockSize, PartHdr);\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
+  Ptr = AllocatePool (PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry);\r
+  if (Ptr == NULL) {\r
+    DEBUG ((EFI_D_ERROR, " Allocate pool effor\n"));\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto Done;\r
+  }\r
+\r
+  Status = DiskIo->ReadDisk (\r
+                    DiskIo,\r
+                    BlockIo->Media->MediaId,\r
+                    MultU64x32(PartHeader->PartitionEntryLBA, BlockIo->Media->BlockSize),\r
+                    PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry,\r
+                    Ptr\r
+                    );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
+  Status = DiskIo->WriteDisk (\r
+                    DiskIo,\r
+                    BlockIo->Media->MediaId,\r
+                    MultU64x32(PEntryLBA, BlockIo->Media->BlockSize),\r
+                    PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry,\r
+                    Ptr\r
+                    );\r
+\r
+Done:\r
+  FreePool (PartHdr);\r
+  FreePool (Ptr);\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return FALSE;\r
+  }\r
+\r
+  return TRUE;\r
+}\r
+\r
+\r
+/**\r
+  Restore Partition Table to its alternate place\r
+  (Primary -> Backup or Backup -> Primary)\r
+\r
+  @param[in]    PartHeader    Partition table header structure\r
+  @param[in]    PartEntry     The partition entry array\r
+  @param[out]   PEntryStatus  the partition entry status array \r
+                              recording the status of each partition\r
+**/\r
+VOID\r
+PartitionCheckGptEntry (\r
+  IN  EFI_PARTITION_TABLE_HEADER  *PartHeader,\r
+  IN  EFI_PARTITION_ENTRY         *PartEntry,\r
+  OUT EFI_PARTITION_ENTRY_STATUS  *PEntryStatus\r
+  )\r
+{\r
+  EFI_LBA StartingLBA;\r
+  EFI_LBA EndingLBA;\r
+  UINTN   Index1;\r
+  UINTN   Index2;\r
+\r
+  DEBUG ((EFI_D_INFO, " start check partition entries\n"));\r
+  for (Index1 = 0; Index1 < PartHeader->NumberOfPartitionEntries; Index1++) {\r
+    if (CompareGuid (&PartEntry[Index1].PartitionTypeGUID, &gEfiPartTypeUnusedGuid)) {\r
+      continue;\r
+    }\r
+\r
+    StartingLBA = PartEntry[Index1].StartingLBA;\r
+    EndingLBA   = PartEntry[Index1].EndingLBA;\r
+    if (StartingLBA > EndingLBA ||\r
+        StartingLBA < PartHeader->FirstUsableLBA ||\r
+        StartingLBA > PartHeader->LastUsableLBA ||\r
+        EndingLBA < PartHeader->FirstUsableLBA ||\r
+        EndingLBA > PartHeader->LastUsableLBA\r
+        ) {\r
+      PEntryStatus[Index1].OutOfRange = TRUE;\r
+      continue;\r
+    }\r
+\r
+    for (Index2 = Index1 + 1; Index2 < PartHeader->NumberOfPartitionEntries; Index2++) {\r
+\r
+      if (CompareGuid (&PartEntry[Index2].PartitionTypeGUID, &gEfiPartTypeUnusedGuid)) {\r
+        continue;\r
+      }\r
+\r
+      if (PartEntry[Index2].EndingLBA >= StartingLBA && PartEntry[Index2].StartingLBA <= EndingLBA) {\r
+        //\r
+        // This region overlaps with the Index1'th region\r
+        //\r
+        PEntryStatus[Index1].Overlap  = TRUE;\r
+        PEntryStatus[Index2].Overlap  = TRUE;\r
+        continue;\r
+\r
+      }\r
+    }\r
+  }\r
+\r
+  DEBUG ((EFI_D_INFO, " End check partition entries\n"));\r
+}\r
+\r
+\r
+/**\r
+  Updates the CRC32 value in the table header\r
+\r
+  @param[in,out]  Hdr    Table to update\r
+\r
+**/\r
+VOID\r
+PartitionSetCrc (\r
+  IN OUT EFI_TABLE_HEADER *Hdr\r
+  )\r
+{\r
+  PartitionSetCrcAltSize (Hdr->HeaderSize, Hdr);\r
+}\r
+\r
+\r
+/**\r
+  Updates the CRC32 value in the table header\r
+\r
+  @param[in]      Size   The size of the table\r
+  @param[in,out]  Hdr    Table to update\r
+\r
+**/\r
+VOID\r
+PartitionSetCrcAltSize (\r
+  IN UINTN                 Size,\r
+  IN OUT EFI_TABLE_HEADER  *Hdr\r
+  )\r
+\r
+{\r
+  UINT32  Crc;\r
+\r
+  Hdr->CRC32 = 0;\r
+  gBS->CalculateCrc32 ((UINT8 *) Hdr, Size, &Crc);\r
+  Hdr->CRC32 = Crc;\r
+}\r
+\r
+\r
+/**\r
+  Checks the CRC32 value in the table header\r
+\r
+  @param[in]      MaxSize   Max Size limit\r
+  @param[in,out]  Hdr       Table to check\r
+\r
+  @return TRUE    CRC Valid\r
+  @return FALSE   CRC Invalid\r
+\r
+**/\r
+BOOLEAN\r
+PartitionCheckCrc (\r
+  IN UINTN                 MaxSize,\r
+  IN OUT EFI_TABLE_HEADER  *Hdr\r
+  )\r
+{\r
+  return PartitionCheckCrcAltSize (MaxSize, Hdr->HeaderSize, Hdr);\r
+}\r
+\r
+\r
+/**\r
+  Checks the CRC32 value in the table header\r
+\r
+  @param[in]      MaxSize   Max Size limit\r
+  @param[in]      Size      The size of the table\r
+  @param[in,out]  Hdr       Table to check\r
+\r
+  @return TRUE    CRC Valid\r
+  @return FALSE   CRC Invalid\r
+\r
+**/\r
+BOOLEAN\r
+PartitionCheckCrcAltSize (\r
+  IN UINTN                 MaxSize,\r
+  IN UINTN                 Size,\r
+  IN OUT EFI_TABLE_HEADER  *Hdr\r
+  )\r
+{\r
+  UINT32      Crc;\r
+  UINT32      OrgCrc;\r
+  EFI_STATUS  Status;\r
+\r
+  Crc = 0;\r
+\r
+  if (Size == 0) {\r
+    //\r
+    // If header size is 0 CRC will pass so return FALSE here\r
+    //\r
+    return FALSE;\r
+  }\r
+\r
+  if (MaxSize && Size > MaxSize) {\r
+    DEBUG ((EFI_D_ERROR, "CheckCrc32: Size > MaxSize\n"));\r
+    return FALSE;\r
+  }\r
+  //\r
+  // clear old crc from header\r
+  //\r
+  OrgCrc      = Hdr->CRC32;\r
+  Hdr->CRC32  = 0;\r
+\r
+  Status      = gBS->CalculateCrc32 ((UINT8 *) Hdr, Size, &Crc);\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_ERROR, "CheckCrc32: Crc calculation failed\n"));\r
+    return FALSE;\r
+  }\r
+  //\r
+  // set results\r
+  //\r
+  Hdr->CRC32 = Crc;\r
+\r
+  //\r
+  // return status\r
+  //\r
+  DEBUG_CODE_BEGIN ();\r
+    if (OrgCrc != Crc) {\r
+      DEBUG ((EFI_D_ERROR, "CheckCrc32: Crc check failed\n"));\r
+    }\r
+  DEBUG_CODE_END ();\r
+\r
+  return (BOOLEAN) (OrgCrc == Crc);\r
+}\r
diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c b/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c
new file mode 100644 (file)
index 0000000..d71698c
--- /dev/null
@@ -0,0 +1,328 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2007, Intel Corporation                                                         \r
+All rights reserved. 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
+Module Name:\r
+\r
+  Mbr.c\r
+  \r
+Abstract:\r
+\r
+  Decode a hard disk partitioned with the legacy MBR found on most PC's\r
+\r
+  MBR - Master Boot Record is in the first sector of a partitioned hard disk.\r
+        The MBR supports four partitions per disk. The MBR also contains legacy\r
+        code that is not run on an EFI system. The legacy code reads the \r
+        first sector of the active partition into memory and \r
+\r
+  BPB - Boot(?) Parameter Block is in the first sector of a FAT file system. \r
+        The BPB contains information about the FAT file system. The BPB is \r
+        always on the first sector of a media. The first sector also contains\r
+        the legacy boot strap code.\r
+\r
+--*/\r
+\r
+#include "Partition.h"\r
+\r
+STATIC\r
+BOOLEAN\r
+PartitionValidMbr (\r
+  IN  MASTER_BOOT_RECORD      *Mbr,\r
+  IN  EFI_LBA                 LastLba\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Test to see if the Mbr buffer is a valid MBR\r
+\r
+Arguments:       \r
+  Mbr     - Parent Handle \r
+  LastLba - Last Lba address on the device.\r
+\r
+Returns:\r
+  TRUE  - Mbr is a Valid MBR\r
+  FALSE - Mbr is not a Valid MBR\r
+\r
+--*/\r
+{\r
+  UINT32  StartingLBA;\r
+  UINT32  EndingLBA;\r
+  UINT32  NewEndingLBA;\r
+  INTN    Index1;\r
+  INTN    Index2;\r
+  BOOLEAN MbrValid;\r
+\r
+  if (Mbr->Signature != MBR_SIGNATURE) {\r
+    return FALSE;\r
+  }\r
+  //\r
+  // The BPB also has this signature, so it can not be used alone.\r
+  //\r
+  MbrValid = FALSE;\r
+  for (Index1 = 0; Index1 < MAX_MBR_PARTITIONS; Index1++) {\r
+    if (Mbr->Partition[Index1].OSIndicator == 0x00 || UNPACK_UINT32 (Mbr->Partition[Index1].SizeInLBA) == 0) {\r
+      continue;\r
+    }\r
+\r
+    MbrValid    = TRUE;\r
+    StartingLBA = UNPACK_UINT32 (Mbr->Partition[Index1].StartingLBA);\r
+    EndingLBA   = StartingLBA + UNPACK_UINT32 (Mbr->Partition[Index1].SizeInLBA) - 1;\r
+    if (EndingLBA > LastLba) {\r
+      //\r
+      // Compatibility Errata:\r
+      //  Some systems try to hide drive space with their INT 13h driver\r
+      //  This does not hide space from the OS driver. This means the MBR\r
+      //  that gets created from DOS is smaller than the MBR created from\r
+      //  a real OS (NT & Win98). This leads to BlockIo->LastBlock being\r
+      //  wrong on some systems FDISKed by the OS.\r
+      //\r
+      // return FALSE since no block devices on a system are implemented\r
+      // with INT 13h\r
+      //\r
+      return FALSE;\r
+    }\r
+\r
+    for (Index2 = Index1 + 1; Index2 < MAX_MBR_PARTITIONS; Index2++) {\r
+      if (Mbr->Partition[Index2].OSIndicator == 0x00 || UNPACK_UINT32 (Mbr->Partition[Index2].SizeInLBA) == 0) {\r
+        continue;\r
+      }\r
+\r
+      NewEndingLBA = UNPACK_UINT32 (Mbr->Partition[Index2].StartingLBA) + UNPACK_UINT32 (Mbr->Partition[Index2].SizeInLBA) - 1;\r
+      if (NewEndingLBA >= StartingLBA && UNPACK_UINT32 (Mbr->Partition[Index2].StartingLBA) <= EndingLBA) {\r
+        //\r
+        // This region overlaps with the Index1'th region\r
+        //\r
+        return FALSE;\r
+      }\r
+    }\r
+  }\r
+  //\r
+  // Non of the regions overlapped so MBR is O.K.\r
+  //\r
+  return MbrValid;\r
+}\r
+\r
+EFI_STATUS\r
+PartitionInstallMbrChildHandles (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Handle,\r
+  IN  EFI_DISK_IO_PROTOCOL         *DiskIo,\r
+  IN  EFI_BLOCK_IO_PROTOCOL        *BlockIo,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *DevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Install child handles if the Handle supports MBR format.\r
+\r
+Arguments:       \r
+  This       - Calling context.\r
+  Handle     - Parent Handle \r
+  DiskIo     - Parent DiskIo interface\r
+  BlockIo    - Parent BlockIo interface\r
+  DevicePath - Parent Device Path\r
+\r
+Returns:\r
+  EFI_SUCCESS       - If a child handle was added\r
+  EFI_MEDIA_CHANGED - Media changed Detected\r
+       !EFI_SUCCESS      - Not found MBR partition.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                Status;\r
+  MASTER_BOOT_RECORD        *Mbr;\r
+  UINT32                    ExtMbrStartingLba;\r
+  UINTN                     Index;\r
+  HARDDRIVE_DEVICE_PATH     HdDev;\r
+  HARDDRIVE_DEVICE_PATH     ParentHdDev;\r
+  EFI_STATUS                Found;\r
+  UINT32                    PartitionNumber;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePathNode;\r
+  EFI_DEVICE_PATH_PROTOCOL  *LastDevicePathNode;\r
+\r
+  Mbr             = NULL;\r
+  Found           = EFI_NOT_FOUND;\r
+\r
+  Mbr             = AllocatePool (BlockIo->Media->BlockSize);\r
+  if (Mbr == NULL) {\r
+    goto Done;\r
+  }\r
+\r
+  Status = BlockIo->ReadBlocks (\r
+                      BlockIo,\r
+                      BlockIo->Media->MediaId,\r
+                      0,\r
+                      BlockIo->Media->BlockSize,\r
+                      Mbr\r
+                      );\r
+  if (EFI_ERROR (Status)) {\r
+    Found = Status;\r
+    goto Done;\r
+  }\r
+  if (!PartitionValidMbr (Mbr, BlockIo->Media->LastBlock)) {\r
+    goto Done;\r
+  }\r
+  //\r
+  // We have a valid mbr - add each partition\r
+  //\r
+  //\r
+  // Get starting and ending LBA of the parent block device.\r
+  //\r
+  LastDevicePathNode = NULL;\r
+  ZeroMem (&ParentHdDev, sizeof (ParentHdDev));\r
+  DevicePathNode = DevicePath;\r
+  while (!EfiIsDevicePathEnd (DevicePathNode)) {\r
+    LastDevicePathNode  = DevicePathNode;\r
+    DevicePathNode      = EfiNextDevicePathNode (DevicePathNode);\r
+  }\r
+\r
+  if (LastDevicePathNode != NULL) {\r
+    if (DevicePathType (LastDevicePathNode) == MEDIA_DEVICE_PATH &&\r
+        DevicePathSubType (LastDevicePathNode) == MEDIA_HARDDRIVE_DP\r
+        ) {\r
+      CopyMem (&ParentHdDev, LastDevicePathNode, sizeof (ParentHdDev));\r
+    } else {\r
+      LastDevicePathNode = NULL;\r
+    }\r
+  }\r
+\r
+  PartitionNumber = 1;\r
+\r
+  ZeroMem (&HdDev, sizeof (HdDev));\r
+  HdDev.Header.Type     = MEDIA_DEVICE_PATH;\r
+  HdDev.Header.SubType  = MEDIA_HARDDRIVE_DP;\r
+  SetDevicePathNodeLength (&HdDev.Header, sizeof (HdDev));\r
+  HdDev.MBRType         = MBR_TYPE_PCAT;\r
+  HdDev.SignatureType   = SIGNATURE_TYPE_MBR;\r
+\r
+  if (LastDevicePathNode == NULL) {\r
+    //\r
+    // This is a MBR, add each partition\r
+    //\r
+    for (Index = 0; Index < MAX_MBR_PARTITIONS; Index++) {\r
+      if (Mbr->Partition[Index].OSIndicator == 0x00 || UNPACK_UINT32 (Mbr->Partition[Index].SizeInLBA) == 0) {\r
+        //\r
+        // Don't use null MBR entries\r
+        //\r
+        continue;\r
+      }\r
+\r
+      if (Mbr->Partition[Index].OSIndicator == PMBR_GPT_PARTITION) {\r
+        //\r
+        // This is the guard MBR for the GPT. If you ever see a GPT disk with zero partitions you can get here.\r
+        //  We can not produce an MBR BlockIo for this device as the MBR spans the GPT headers. So formating \r
+        //  this BlockIo would corrupt the GPT structures and require a recovery that would corrupt the format\r
+        //  that corrupted the GPT partition. \r
+        //\r
+        continue;\r
+      }\r
+\r
+      HdDev.PartitionNumber = PartitionNumber ++;\r
+      HdDev.PartitionStart  = UNPACK_UINT32 (Mbr->Partition[Index].StartingLBA);\r
+      HdDev.PartitionSize   = UNPACK_UINT32 (Mbr->Partition[Index].SizeInLBA);\r
+      CopyMem (HdDev.Signature, &(Mbr->UniqueMbrSignature[0]), sizeof (UINT32));\r
+\r
+      Status = PartitionInstallChildHandle (\r
+                This,\r
+                Handle,\r
+                DiskIo,\r
+                BlockIo,\r
+                DevicePath,\r
+                (EFI_DEVICE_PATH_PROTOCOL *) &HdDev,\r
+                HdDev.PartitionStart,\r
+                HdDev.PartitionStart + HdDev.PartitionSize - 1,\r
+                MBR_SIZE,\r
+                (BOOLEAN) (Mbr->Partition[Index].OSIndicator == EFI_PARTITION)\r
+                );\r
+\r
+      if (!EFI_ERROR (Status)) {\r
+        Found = EFI_SUCCESS;\r
+      }\r
+    }\r
+  } else {\r
+    //\r
+    // It's an extended partition. Follow the extended partition\r
+    // chain to get all the logical drives\r
+    //\r
+    ExtMbrStartingLba = 0;\r
+\r
+    do {\r
+\r
+      Status = BlockIo->ReadBlocks (\r
+                          BlockIo,\r
+                          BlockIo->Media->MediaId,\r
+                          ExtMbrStartingLba,\r
+                          BlockIo->Media->BlockSize,\r
+                          Mbr\r
+                          );\r
+      if (EFI_ERROR (Status)) {\r
+        Found = Status;\r
+        goto Done;\r
+      }\r
+\r
+      if (Mbr->Partition[0].OSIndicator == 0) {\r
+        break;\r
+      }\r
+\r
+      if ((Mbr->Partition[0].OSIndicator == EXTENDED_DOS_PARTITION) ||\r
+          (Mbr->Partition[0].OSIndicator == EXTENDED_WINDOWS_PARTITION)) {\r
+        ExtMbrStartingLba = UNPACK_UINT32 (Mbr->Partition[0].StartingLBA);\r
+        continue;\r
+      }\r
+      HdDev.PartitionNumber = PartitionNumber ++;\r
+      HdDev.PartitionStart  = UNPACK_UINT32 (Mbr->Partition[0].StartingLBA) + ExtMbrStartingLba + ParentHdDev.PartitionStart;\r
+      HdDev.PartitionSize   = UNPACK_UINT32 (Mbr->Partition[0].SizeInLBA);\r
+      if ((HdDev.PartitionStart + HdDev.PartitionSize - 1 >= ParentHdDev.PartitionStart + ParentHdDev.PartitionSize) ||\r
+          (HdDev.PartitionStart <= ParentHdDev.PartitionStart)) {\r
+        break;\r
+      }\r
+\r
+      //\r
+      // The signature in EBR(Extended Boot Record) should always be 0.\r
+      //\r
+      *((UINT32 *) &HdDev.Signature[0]) = 0;\r
+\r
+      Status = PartitionInstallChildHandle (\r
+                This,\r
+                Handle,\r
+                DiskIo,\r
+                BlockIo,\r
+                DevicePath,\r
+                (EFI_DEVICE_PATH_PROTOCOL *) &HdDev,\r
+                HdDev.PartitionStart - ParentHdDev.PartitionStart,\r
+                HdDev.PartitionStart - ParentHdDev.PartitionStart + HdDev.PartitionSize - 1,\r
+                MBR_SIZE,\r
+                (BOOLEAN) (Mbr->Partition[0].OSIndicator == EFI_PARTITION)\r
+                );\r
+      if (!EFI_ERROR (Status)) {\r
+        Found = EFI_SUCCESS;\r
+      }\r
+\r
+      if ((Mbr->Partition[1].OSIndicator != EXTENDED_DOS_PARTITION) &&\r
+          (Mbr->Partition[1].OSIndicator != EXTENDED_WINDOWS_PARTITION)\r
+          ) {\r
+        break;\r
+      }\r
+\r
+      ExtMbrStartingLba = UNPACK_UINT32 (Mbr->Partition[1].StartingLBA);\r
+      //\r
+      // Don't allow partition to be self referencing\r
+      //\r
+      if (ExtMbrStartingLba == 0) {\r
+        break;\r
+      }\r
+    } while (ExtMbrStartingLba  < ParentHdDev.PartitionSize);\r
+  }\r
+\r
+Done:\r
+  FreePool (Mbr);\r
+\r
+  return Found;\r
+}\r
diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c b/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c
new file mode 100644 (file)
index 0000000..4d0c76f
--- /dev/null
@@ -0,0 +1,712 @@
+/** @file\r
+  Partition driver that produces logical BlockIo devices from a physical\r
+  BlockIo device. The logical BlockIo devices are based on the format\r
+  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 - 2007, Intel Corporation                                              \r
+  All rights reserved. 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
+\r
+#include "Partition.h"\r
+\r
+//\r
+// Partition Driver Global Variables\r
+//\r
+EFI_DRIVER_BINDING_PROTOCOL gPartitionDriverBinding = {\r
+  PartitionDriverBindingSupported,\r
+  PartitionDriverBindingStart,\r
+  PartitionDriverBindingStop,\r
+  0xa,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+STATIC \r
+PARTITION_DETECT_ROUTINE mPartitionDetectRoutineTable[] = {\r
+  PartitionInstallGptChildHandles,\r
+  PartitionInstallElToritoChildHandles,\r
+  PartitionInstallMbrChildHandles,\r
+  NULL\r
+};\r
+\r
+\r
+\r
+/**\r
+  Test to see if this driver supports ControllerHandle. Any ControllerHandle\r
+  than contains a BlockIo and DiskIo protocol can be supported.\r
+\r
+  @param  This                Protocol instance pointer.\r
+  @param  ControllerHandle    Handle of device to test\r
+  @param  RemainingDevicePath Optional parameter use to pick a specific child\r
+                              device to start.\r
+\r
+  @retval EFI_SUCCESS         This driver supports this device\r
+  @retval EFI_ALREADY_STARTED This driver is already running on this device\r
+  @retval other               This driver does not support this device\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PartitionDriverBindingSupported (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN EFI_HANDLE                   ControllerHandle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  )\r
+{\r
+  EFI_STATUS                Status;\r
+  EFI_DEVICE_PATH_PROTOCOL  *ParentDevicePath;\r
+  EFI_DISK_IO_PROTOCOL      *DiskIo;\r
+  EFI_DEV_PATH              *Node;\r
+\r
+  if (RemainingDevicePath != NULL) {\r
+    Node = (EFI_DEV_PATH *) RemainingDevicePath;\r
+    if (Node->DevPath.Type != MEDIA_DEVICE_PATH ||\r
+        Node->DevPath.SubType != MEDIA_HARDDRIVE_DP ||\r
+        DevicePathNodeLength (&Node->DevPath) != sizeof (HARDDRIVE_DEVICE_PATH)\r
+        ) {\r
+      return EFI_UNSUPPORTED;\r
+    }\r
+  }\r
+  //\r
+  // Open the IO Abstraction(s) needed to perform the supported test\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID **) &ParentDevicePath,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (Status == EFI_ALREADY_STARTED) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Close the I/O Abstraction(s) used to perform the supported test\r
+  //\r
+  gBS->CloseProtocol (\r
+        ControllerHandle,\r
+        &gEfiDevicePathProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        ControllerHandle\r
+        );\r
+\r
+  //\r
+  // Open the IO Abstraction(s) needed to perform the supported test\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiDiskIoProtocolGuid,\r
+                  (VOID **) &DiskIo,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (Status == EFI_ALREADY_STARTED) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Close the I/O Abstraction(s) used to perform the supported test\r
+  //\r
+  gBS->CloseProtocol (\r
+        ControllerHandle,\r
+        &gEfiDiskIoProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        ControllerHandle\r
+        );\r
+\r
+  //\r
+  // Open the IO Abstraction(s) needed to perform the supported test\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiBlockIoProtocolGuid,\r
+                  NULL,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
+                  );\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Start this driver on ControllerHandle by opening a Block IO and Disk IO\r
+  protocol, reading Device Path, and creating a child handle with a\r
+  Disk IO and device path protocol.\r
+\r
+  @param  This                 Protocol instance pointer.\r
+  @param  ControllerHandle     Handle of device to bind driver to\r
+  @param  RemainingDevicePath  Optional parameter use to pick a specific child\r
+                               device to start.\r
+\r
+  @retval EFI_SUCCESS          This driver is added to ControllerHandle\r
+  @retval EFI_ALREADY_STARTED  This driver is already running on ControllerHandle\r
+  @retval other                This driver does not support this device\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PartitionDriverBindingStart (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN EFI_HANDLE                   ControllerHandle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  )\r
+{\r
+  EFI_STATUS                Status;\r
+  EFI_STATUS                OpenStatus;\r
+  EFI_BLOCK_IO_PROTOCOL     *BlockIo;\r
+  EFI_DISK_IO_PROTOCOL      *DiskIo;\r
+  EFI_DEVICE_PATH_PROTOCOL  *ParentDevicePath;\r
+  PARTITION_DETECT_ROUTINE  *Routine;\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiBlockIoProtocolGuid,\r
+                  (VOID **) &BlockIo,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Get the Device Path Protocol on ControllerHandle's handle\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID **) &ParentDevicePath,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r
+    return Status;\r
+  }\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiDiskIoProtocolGuid,\r
+                  (VOID **) &DiskIo,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r
+    gBS->CloseProtocol (\r
+          ControllerHandle,\r
+          &gEfiDevicePathProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          ControllerHandle\r
+          );\r
+    return Status;\r
+  }\r
+\r
+  OpenStatus = Status;\r
+\r
+  //\r
+  // If no media is present, do nothing here.\r
+  //\r
+  Status = EFI_UNSUPPORTED;\r
+  if (BlockIo->Media->MediaPresent) {\r
+    //\r
+    // Try for GPT, then El Torito, and then legacy MBR partition types. If the\r
+    // media supports a given partition type install child handles to represent\r
+    // the partitions described by the media.\r
+    //\r
+    Routine = &mPartitionDetectRoutineTable[0];\r
+    while (*Routine != NULL) {\r
+      Status = (*Routine) (\r
+                   This,\r
+                   ControllerHandle,\r
+                   DiskIo,\r
+                   BlockIo,\r
+                   ParentDevicePath\r
+                   );\r
+      if (!EFI_ERROR (Status) || Status == EFI_MEDIA_CHANGED) {\r
+        break;\r
+      }\r
+      Routine++;\r
+    }\r
+  }\r
+  //\r
+  // In the case that the driver is already started (OpenStatus == EFI_ALREADY_STARTED),\r
+  // the DevicePathProtocol and the DiskIoProtocol are not actually opened by the\r
+  // driver. So don't try to close them. Otherwise, we will break the dependency\r
+  // between the controller and the driver set up before.\r
+  //\r
+  if (EFI_ERROR (Status) && !EFI_ERROR (OpenStatus) && Status != EFI_MEDIA_CHANGED) {\r
+    gBS->CloseProtocol (\r
+          ControllerHandle,\r
+          &gEfiDiskIoProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          ControllerHandle\r
+          );\r
+\r
+    gBS->CloseProtocol (\r
+          ControllerHandle,\r
+          &gEfiDevicePathProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          ControllerHandle\r
+          );\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Stop this driver on ControllerHandle. Support stoping any child handles\r
+  created by this driver.\r
+\r
+  @param  This              Protocol instance pointer.\r
+  @param  ControllerHandle  Handle of device to stop driver on\r
+  @param  NumberOfChildren  Number of Handles in ChildHandleBuffer. If number of\r
+                            children is zero stop the entire bus driver.\r
+  @param  ChildHandleBuffer List of Child Handles to Stop.\r
+\r
+  @retval EFI_SUCCESS       This driver is removed ControllerHandle\r
+  @retval other             This driver was not removed from this device\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PartitionDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL   *This,\r
+  IN  EFI_HANDLE                    ControllerHandle,\r
+  IN  UINTN                         NumberOfChildren,\r
+  IN  EFI_HANDLE                    *ChildHandleBuffer\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  UINTN                   Index;\r
+  EFI_BLOCK_IO_PROTOCOL   *BlockIo;\r
+  BOOLEAN                 AllChildrenStopped;\r
+  PARTITION_PRIVATE_DATA  *Private;\r
+  EFI_DISK_IO_PROTOCOL    *DiskIo;\r
+\r
+  if (NumberOfChildren == 0) {\r
+    //\r
+    // Close the bus driver\r
+    //\r
+    gBS->CloseProtocol (\r
+          ControllerHandle,\r
+          &gEfiDiskIoProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          ControllerHandle\r
+          );\r
+\r
+    gBS->CloseProtocol (\r
+          ControllerHandle,\r
+          &gEfiDevicePathProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          ControllerHandle\r
+          );\r
+\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  AllChildrenStopped = TRUE;\r
+  for (Index = 0; Index < NumberOfChildren; Index++) {\r
+    Status = gBS->OpenProtocol (\r
+                    ChildHandleBuffer[Index],\r
+                    &gEfiBlockIoProtocolGuid,\r
+                    (VOID **) &BlockIo,\r
+                    This->DriverBindingHandle,\r
+                    ControllerHandle,\r
+                    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                    );\r
+    if (!EFI_ERROR (Status)) {\r
+\r
+      Private = PARTITION_DEVICE_FROM_BLOCK_IO_THIS (BlockIo);\r
+\r
+      //\r
+      // All Software protocols have be freed from the handle so remove it.\r
+      //\r
+      BlockIo->FlushBlocks (BlockIo);\r
+\r
+      Status = gBS->CloseProtocol (\r
+                      ControllerHandle,\r
+                      &gEfiDiskIoProtocolGuid,\r
+                      This->DriverBindingHandle,\r
+                      ChildHandleBuffer[Index]\r
+                      );\r
+\r
+      Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                      ChildHandleBuffer[Index],\r
+                      &gEfiDevicePathProtocolGuid,\r
+                      Private->DevicePath,\r
+                      &gEfiBlockIoProtocolGuid,\r
+                      &Private->BlockIo,\r
+                      Private->EspGuid,\r
+                      NULL,\r
+                      NULL\r
+                      );\r
+      if (EFI_ERROR (Status)) {\r
+        gBS->OpenProtocol (\r
+              ControllerHandle,\r
+              &gEfiDiskIoProtocolGuid,\r
+              (VOID **) &DiskIo,\r
+              This->DriverBindingHandle,\r
+              ChildHandleBuffer[Index],\r
+              EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+              );\r
+      } else {\r
+        FreePool (Private->DevicePath);\r
+        FreePool (Private);\r
+      }\r
+\r
+    }\r
+\r
+    if (EFI_ERROR (Status)) {\r
+      AllChildrenStopped = FALSE;\r
+    }\r
+  }\r
+\r
+  if (!AllChildrenStopped) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+/**\r
+  Reset the Block Device.\r
+\r
+  @param  This                 Protocol instance pointer.\r
+  @param  ExtendedVerification Driver may perform diagnostics on reset.\r
+\r
+  @retval EFI_SUCCESS          The device was reset.\r
+  @retval EFI_DEVICE_ERROR     The device is not functioning properly and could\r
+                               not be reset.\r
+\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+PartitionReset (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This,\r
+  IN BOOLEAN                ExtendedVerification\r
+  )\r
+{\r
+  PARTITION_PRIVATE_DATA  *Private;\r
+\r
+  Private = PARTITION_DEVICE_FROM_BLOCK_IO_THIS (This);\r
+\r
+  return Private->ParentBlockIo->Reset (\r
+                                  Private->ParentBlockIo,\r
+                                  ExtendedVerification\r
+                                  );\r
+}\r
+\r
+\r
+/**\r
+  Read by using the Disk IO protocol on the parent device. Lba addresses\r
+  must be converted to byte offsets.\r
+\r
+  @param  This       Protocol instance pointer.\r
+  @param  MediaId    Id of the media, changes every time the media is replaced.\r
+  @param  Lba        The starting Logical Block Address to read from\r
+  @param  BufferSize Size of Buffer, must be a multiple of device block size.\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_CHANGED     The MediaId does not matched the current device.\r
+  @retval EFI_BAD_BUFFER_SIZE   The Buffer was not a multiple of the block size of the device.\r
+  @retval EFI_INVALID_PARAMETER The read request contains device addresses that are not\r
+                                valid for the device.\r
+\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+PartitionReadBlocks (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This,\r
+  IN UINT32                 MediaId,\r
+  IN EFI_LBA                Lba,\r
+  IN UINTN                  BufferSize,\r
+  OUT VOID                  *Buffer\r
+  )\r
+{\r
+  PARTITION_PRIVATE_DATA  *Private;\r
+  UINT64                  Offset;\r
+\r
+  Private = PARTITION_DEVICE_FROM_BLOCK_IO_THIS (This);\r
+\r
+  if (BufferSize % Private->BlockSize != 0) {\r
+    return EFI_BAD_BUFFER_SIZE;\r
+  }\r
+\r
+  Offset = MultU64x32 (Lba, Private->BlockSize) + Private->Start;\r
+  if (Offset + BufferSize > Private->End) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  //\r
+  // Because some kinds of partition have different block size from their parent\r
+  // device, we call the Disk IO protocol on the parent device, not the Block IO\r
+  // protocol\r
+  //\r
+  return Private->DiskIo->ReadDisk (Private->DiskIo, MediaId, Offset, BufferSize, Buffer);\r
+}\r
+\r
+/**\r
+  Write by using the Disk IO protocol on the parent device. Lba addresses\r
+  must be converted to byte offsets.\r
+\r
+  @param  This       Protocol instance pointer.\r
+  @param  MediaId    Id of the media, changes every time the media is replaced.\r
+  @param  Lba        The starting Logical Block Address to read from\r
+  @param  BufferSize Size of Buffer, must be a multiple of device block size.\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_BAD_BUFFER_SIZE   The Buffer was not a multiple of the block size of the device.\r
+  @retval EFI_INVALID_PARAMETER The write request contains a LBA that is not\r
+                                valid for the device.\r
+\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+PartitionWriteBlocks (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This,\r
+  IN UINT32                 MediaId,\r
+  IN EFI_LBA                Lba,\r
+  IN UINTN                  BufferSize,\r
+  OUT VOID                  *Buffer\r
+  )\r
+{\r
+  PARTITION_PRIVATE_DATA  *Private;\r
+  UINT64                  Offset;\r
+\r
+  Private = PARTITION_DEVICE_FROM_BLOCK_IO_THIS (This);\r
+\r
+  if (BufferSize % Private->BlockSize != 0) {\r
+    return EFI_BAD_BUFFER_SIZE;\r
+  }\r
+\r
+  Offset = MultU64x32 (Lba, Private->BlockSize) + Private->Start;\r
+  if (Offset + BufferSize > Private->End) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  //\r
+  // Because some kinds of partition have different block size from their parent\r
+  // device, we call the Disk IO protocol on the parent device, not the Block IO\r
+  // protocol\r
+  //\r
+  return Private->DiskIo->WriteDisk (Private->DiskIo, MediaId, Offset, BufferSize, Buffer);\r
+}\r
+\r
+\r
+/**\r
+  Flush the parent Block Device.\r
+\r
+  @param  This              Protocol instance pointer.\r
+\r
+  @retval EFI_SUCCESS       All outstanding data was written to the device\r
+  @retval EFI_DEVICE_ERROR  The device reported an error while writting back the data\r
+  @retval EFI_NO_MEDIA      There is no media in the device.\r
+\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+PartitionFlushBlocks (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This\r
+  )\r
+{\r
+  PARTITION_PRIVATE_DATA  *Private;\r
+\r
+  Private = PARTITION_DEVICE_FROM_BLOCK_IO_THIS (This);\r
+\r
+  return Private->ParentBlockIo->FlushBlocks (Private->ParentBlockIo);\r
+}\r
+\r
+\r
+\r
+/**\r
+  Create a child handle for a logical block device that represents the\r
+  bytes Start to End of the Parent Block IO device.\r
+\r
+  @param[in]  This              Protocol instance pointer.\r
+  @param[in]  This              Calling context.\r
+  @param[in]  ParentHandle      Parent Handle for new child\r
+  @param[in]  ParentDiskIo      Parent DiskIo interface\r
+  @param[in]  ParentBlockIo     Parent BlockIo interface\r
+  @param[in]  ParentDevicePath  Parent Device Path\r
+  @param[in]  DevicePathNode    Child Device Path node\r
+  @param[in]  Start             Start Block\r
+  @param[in]  End               End Block\r
+  @param[in]  BlockSize         Child block size\r
+  @param[in]  InstallEspGuid    Flag to install EFI System Partition GUID on handle\r
+\r
+  @retval EFI_SUCCESS       A child handle was added\r
+  @retval other             A child handle was not added\r
+\r
+**/\r
+EFI_STATUS\r
+PartitionInstallChildHandle (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   ParentHandle,\r
+  IN  EFI_DISK_IO_PROTOCOL         *ParentDiskIo,\r
+  IN  EFI_BLOCK_IO_PROTOCOL        *ParentBlockIo,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *ParentDevicePath,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *DevicePathNode,\r
+  IN  EFI_LBA                      Start,\r
+  IN  EFI_LBA                      End,\r
+  IN  UINT32                       BlockSize,\r
+  IN  BOOLEAN                      InstallEspGuid\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  PARTITION_PRIVATE_DATA  *Private;\r
+\r
+  Private = AllocateZeroPool (sizeof (PARTITION_PRIVATE_DATA));\r
+  if (Private == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  Private->Signature        = PARTITION_PRIVATE_DATA_SIGNATURE;\r
+\r
+  Private->Start            = MultU64x32 (Start, ParentBlockIo->Media->BlockSize);\r
+  Private->End              = MultU64x32 (End + 1, ParentBlockIo->Media->BlockSize);\r
+\r
+  Private->BlockSize        = BlockSize;\r
+  Private->ParentBlockIo    = ParentBlockIo;\r
+  Private->DiskIo           = ParentDiskIo;\r
+\r
+  Private->BlockIo.Revision = EFI_BLOCK_IO_PROTOCOL_REVISION;\r
+\r
+  Private->BlockIo.Media    = &Private->Media;\r
+  CopyMem (Private->BlockIo.Media, ParentBlockIo->Media, sizeof (EFI_BLOCK_IO_MEDIA));\r
+  Private->Media.LogicalPartition = TRUE;\r
+  Private->Media.LastBlock = DivU64x32 (\r
+                               MultU64x32 (\r
+                                 End - Start + 1,\r
+                                 ParentBlockIo->Media->BlockSize\r
+                                 ),\r
+                               BlockSize\r
+                               ) - 1;\r
+\r
+  Private->Media.BlockSize      = (UINT32) BlockSize;\r
+\r
+  Private->BlockIo.Reset        = PartitionReset;\r
+  Private->BlockIo.ReadBlocks   = PartitionReadBlocks;\r
+  Private->BlockIo.WriteBlocks  = PartitionWriteBlocks;\r
+  Private->BlockIo.FlushBlocks  = PartitionFlushBlocks;\r
+\r
+  Private->DevicePath           = AppendDevicePathNode (ParentDevicePath, DevicePathNode);\r
+\r
+  if (Private->DevicePath == NULL) {\r
+    FreePool (Private);\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  if (InstallEspGuid) {\r
+    Private->EspGuid = &gEfiPartTypeSystemPartGuid;\r
+  } else {\r
+    //\r
+    // If NULL InstallMultipleProtocolInterfaces will ignore it.\r
+    //\r
+    Private->EspGuid = NULL;\r
+  }\r
+  //\r
+  // Create the new handle\r
+  //\r
+  Private->Handle = NULL;\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &Private->Handle,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  Private->DevicePath,\r
+                  &gEfiBlockIoProtocolGuid,\r
+                  &Private->BlockIo,\r
+                  Private->EspGuid,\r
+                  NULL,\r
+                  NULL\r
+                  );\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // Open the Parent Handle for the child\r
+    //\r
+    Status = gBS->OpenProtocol (\r
+                    ParentHandle,\r
+                    &gEfiDiskIoProtocolGuid,\r
+                    (VOID **) &ParentDiskIo,\r
+                    This->DriverBindingHandle,\r
+                    Private->Handle,\r
+                    EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+                    );\r
+  } else {\r
+    FreePool (Private->DevicePath);\r
+    FreePool (Private);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  The user Entry Point for module Partition. The user code starts with this function.\r
+\r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.  \r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
+  \r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializePartition (\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+\r
+  //\r
+  // Install driver model protocol(s).\r
+  //\r
+  Status = EfiLibInstallAllDriverProtocols (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gPartitionDriverBinding,\r
+             ImageHandle,\r
+             &gPartitionComponentName,\r
+             NULL,\r
+             NULL\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+\r
+  return Status;\r
+}\r
+\r
diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.h b/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.h
new file mode 100644 (file)
index 0000000..570d019
--- /dev/null
@@ -0,0 +1,191 @@
+/** @file\r
+  Partition driver that produces logical BlockIo devices from a physical \r
+  BlockIo device. The logical BlockIo devices are based on the format\r
+  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 - 2007, Intel Corporation                                              \r
+  All rights reserved. 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 _PARTITION_H \r
+#define _PARTITION_H \r
+\r
+#include <Uefi.h>\r
+#include <Protocol/BlockIo.h>\r
+#include <Guid/Gpt.h>\r
+#include <Protocol/ComponentName.h>\r
+#include <Protocol/DevicePath.h>\r
+#include <Protocol/DriverBinding.h>\r
+#include <Protocol/DiskIo.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/DevicePathLib.h>\r
+\r
+#include <IndustryStandard/Mbr.h>\r
+#include <IndustryStandard/ElTorito.h>\r
+\r
+\r
+//\r
+// Partition private data\r
+//\r
+#define PARTITION_PRIVATE_DATA_SIGNATURE  EFI_SIGNATURE_32 ('P', 'a', 'r', 't')\r
+typedef struct {\r
+  UINT64                    Signature;\r
+\r
+  EFI_HANDLE                Handle;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
+  EFI_BLOCK_IO_PROTOCOL     BlockIo;\r
+  EFI_BLOCK_IO_MEDIA        Media;\r
+\r
+  EFI_DISK_IO_PROTOCOL      *DiskIo;\r
+  EFI_BLOCK_IO_PROTOCOL     *ParentBlockIo;\r
+  UINT64                    Start;\r
+  UINT64                    End;\r
+  UINT32                    BlockSize;\r
+\r
+  EFI_GUID                  *EspGuid;\r
+\r
+} PARTITION_PRIVATE_DATA;\r
+\r
+#define PARTITION_DEVICE_FROM_BLOCK_IO_THIS(a)  CR (a, PARTITION_PRIVATE_DATA, BlockIo, PARTITION_PRIVATE_DATA_SIGNATURE)\r
+\r
+//\r
+// Global Variables\r
+//\r
+extern EFI_DRIVER_BINDING_PROTOCOL  gPartitionDriverBinding;\r
+extern EFI_COMPONENT_NAME_PROTOCOL  gPartitionComponentName;\r
+\r
+//\r
+// Extract INT32 from char array\r
+//\r
+#define UNPACK_INT32(a) (INT32)( (((UINT8 *) a)[0] <<  0) |    \\r
+                                 (((UINT8 *) a)[1] <<  8) |    \\r
+                                 (((UINT8 *) a)[2] << 16) |    \\r
+                                 (((UINT8 *) a)[3] << 24) )\r
+\r
+//\r
+// Extract UINT32 from char array\r
+//\r
+#define UNPACK_UINT32(a) (UINT32)( (((UINT8 *) a)[0] <<  0) |    \\r
+                                   (((UINT8 *) a)[1] <<  8) |    \\r
+                                   (((UINT8 *) a)[2] << 16) |    \\r
+                                   (((UINT8 *) a)[3] << 24) )\r
+\r
+//\r
+// Function Prototypes\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+PartitionDriverBindingSupported (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN EFI_HANDLE                   ControllerHandle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+PartitionDriverBindingStart (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN EFI_HANDLE                   ControllerHandle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+PartitionDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   ControllerHandle,\r
+  IN  UINTN                        NumberOfChildren,\r
+  IN  EFI_HANDLE                   *ChildHandleBuffer\r
+  );\r
+\r
+//\r
+// EFI Component Name Functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+PartitionComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+PartitionComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  );\r
+\r
+EFI_STATUS\r
+PartitionInstallChildHandle (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   ParentHandle,\r
+  IN  EFI_DISK_IO_PROTOCOL         *ParentDiskIo,\r
+  IN  EFI_BLOCK_IO_PROTOCOL        *ParentBlockIo,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *ParentDevicePath,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *DevicePathNode,\r
+  IN  UINT64                       Start,\r
+  IN  UINT64                       End,\r
+  IN  UINT32                       BlockSize,\r
+  IN  BOOLEAN                      InstallEspGuid\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+PartitionInstallGptChildHandles (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Handle,\r
+  IN  EFI_DISK_IO_PROTOCOL         *DiskIo,\r
+  IN  EFI_BLOCK_IO_PROTOCOL        *BlockIo,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *DevicePath\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+PartitionInstallElToritoChildHandles (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Handle,\r
+  IN  EFI_DISK_IO_PROTOCOL         *DiskIo,\r
+  IN  EFI_BLOCK_IO_PROTOCOL        *BlockIo,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *DevicePath\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+PartitionInstallMbrChildHandles (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Handle,\r
+  IN  EFI_DISK_IO_PROTOCOL         *DiskIo,\r
+  IN  EFI_BLOCK_IO_PROTOCOL        *BlockIo,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *DevicePath\r
+  )\r
+;\r
+\r
+typedef\r
+EFI_STATUS\r
+(*PARTITION_DETECT_ROUTINE) (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Handle,\r
+  IN  EFI_DISK_IO_PROTOCOL         *DiskIo,\r
+  IN  EFI_BLOCK_IO_PROTOCOL        *BlockIo,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *DevicePath\r
+  );\r
+\r
+#endif\r
diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf b/MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf
new file mode 100644 (file)
index 0000000..18a95a9
--- /dev/null
@@ -0,0 +1,114 @@
+#/** @file\r
+# Component description file for Partition module.\r
+#\r
+# Partition driver produces the logical BlockIo device\r
+#  that represents the bytes Start to End of the Parent Block IO\r
+#  device (one partition of physical BlockIo device,\r
+#  which can be one of GPT, MBR, ElTorito partition).\r
+#\r
+#  Copyright (c) 2006 - 2007, Intel Corporation\r
+#  All rights reserved. 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
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = PartitionDxe\r
+  FILE_GUID                      = 1FA1F39E-FEFF-4aae-BD7B-38A070A3B609\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = InitializePartition\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+#  DRIVER_BINDING                =  gPartitionDriverBinding\r
+#  COMPONENT_NAME                =  gPartitionComponentName\r
+#\r
+\r
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+  ComponentName.c\r
+  Mbr.c\r
+  Gpt.c\r
+  ElTorito.c\r
+  Partition.c\r
+  Partition.h\r
+\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+#                         this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+  DevicePathLib\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  BaseMemoryLib\r
+  UefiLib\r
+  BaseLib\r
+  UefiDriverEntryPoint\r
+  DebugLib\r
+\r
+\r
+################################################################################\r
+#\r
+# Guid C Name Section - list of Guids that this module uses or produces.\r
+#\r
+################################################################################\r
+\r
+[Guids]\r
+  gEfiPartTypeUnusedGuid                        # SOMETIMES_CONSUMED\r
+  gEfiPartTypeSystemPartGuid                    # SOMETIMES_CONSUMED\r
+\r
+\r
+################################################################################\r
+#\r
+# Protocol C Name Section - list of Protocol and Protocol Notify C Names\r
+#                           that this module uses or produces.\r
+#\r
+################################################################################\r
+\r
+[Protocols]\r
+  gEfiBlockIoProtocolGuid                       # PROTOCOL BY_START\r
+  gEfiDevicePathProtocolGuid                    # PROTOCOL BY_START\r
+  gEfiDevicePathProtocolGuid                    # PROTOCOL TO_START\r
+  gEfiDiskIoProtocolGuid                        # PROTOCOL TO_START\r
+  gEfiBlockIoProtocolGuid                       # PROTOCOL TO_START\r
+\r
diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.msa b/MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.msa
new file mode 100644 (file)
index 0000000..35274f0
--- /dev/null
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+  <MsaHeader>\r
+    <ModuleName>PartitionDxe</ModuleName>\r
+    <ModuleType>UEFI_DRIVER</ModuleType>\r
+    <GuidValue>1FA1F39E-FEFF-4aae-BD7B-38A070A3B609</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Component description file for Partition module.</Abstract>\r
+    <Description>Partition driver produces the logical BlockIo device\r
+      that represents the bytes Start to End of the Parent Block IO\r
+      device (one partition of physical BlockIo device,\r
+      which can be one of GPT, MBR, ElTorito partition).</Description>\r
+    <Copyright>Copyright (c) 2006 - 2007, Intel Corporation</Copyright>\r
+    <License>All rights reserved. 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
+      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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>PartitionDxe</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED" RecommendedInstanceGuid="bda39d3a-451b-4350-8266-81ab10fa0523">\r
+      <Keyword>DebugLib</Keyword>\r
+      <HelpText>Recommended libary Instance is PeiDxeDebugLibReportStatusCode instance in MdePkg.</HelpText>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverModelLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DevicePathLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>Partition.h</Filename>\r
+    <Filename>Partition.c</Filename>\r
+    <Filename>ElTorito.c</Filename>\r
+    <Filename>Gpt.c</Filename>\r
+    <Filename>Mbr.c</Filename>\r
+    <Filename>ComponentName.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="TO_START">\r
+      <ProtocolCName>gEfiBlockIoProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="TO_START">\r
+      <ProtocolCName>gEfiDiskIoProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="TO_START">\r
+      <ProtocolCName>gEfiDevicePathProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="BY_START">\r
+      <ProtocolCName>gEfiDevicePathProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="BY_START">\r
+      <ProtocolCName>gEfiBlockIoProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Guids>\r
+    <GuidCNames Usage="SOMETIMES_CONSUMED">\r
+      <GuidCName>gEfiPartTypeSystemPartGuid</GuidCName>\r
+    </GuidCNames>\r
+    <GuidCNames Usage="SOMETIMES_CONSUMED">\r
+      <GuidCName>gEfiPartTypeUnusedGuid</GuidCName>\r
+    </GuidCNames>\r
+  </Guids>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <DriverBinding>gPartitionDriverBinding</DriverBinding>\r
+      <ComponentName>gPartitionComponentName</ComponentName>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf b/MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf
new file mode 100644 (file)
index 0000000..1a67da7
--- /dev/null
@@ -0,0 +1,82 @@
+#/** @file\r
+# Component description file for English module for unicode collation.\r
+#\r
+# This driver installs UEFI EFI_UNICODE_COLLATION_PROTOCOL protocol to provide Unicode strings function.\r
+# Copyright (c) 2006 - 2007, Intel Corporation\r
+#\r
+#  All rights reserved. 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
+#  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
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = EnglishDxe\r
+  FILE_GUID                      = CD3BAFB6-50FB-4fe8-8E4E-AB74D2C1A600\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = InitializeUnicodeCollationEng\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+  UnicodeCollationEng.c\r
+  UnicodeCollationEng.h\r
+\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+#                         this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  UefiDriverEntryPoint\r
+  DebugLib\r
+\r
+\r
+################################################################################\r
+#\r
+# Protocol C Name Section - list of Protocol and Protocol Notify C Names\r
+#                           that this module uses or produces.\r
+#\r
+################################################################################\r
+\r
+[Protocols]\r
+  gEfiUnicodeCollationProtocolGuid              # PROTOCOL ALWAYS_PRODUCED\r
+\r
diff --git a/MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.msa b/MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.msa
new file mode 100644 (file)
index 0000000..d8ebf6d
--- /dev/null
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+  <MsaHeader>\r
+    <ModuleName>EnglishDxe</ModuleName>\r
+    <ModuleType>UEFI_DRIVER</ModuleType>\r
+    <GuidValue>CD3BAFB6-50FB-4fe8-8E4E-AB74D2C1A600</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Component description file for English module for unicode collation.</Abstract>\r
+    <Description>This driver installs UEFI EFI_UNICODE_COLLATION_PROTOCOL protocol to provide Unicode strings function.</Description>\r
+    <Copyright>Copyright (c) 2006 - 2007, Intel Corporation</Copyright>\r
+    <License>All rights reserved. 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
+      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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>EnglishDxe</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED" RecommendedInstanceGuid="bda39d3a-451b-4350-8266-81ab10fa0523">\r
+      <Keyword>DebugLib</Keyword>\r
+      <HelpText>Recommended libary Instance is PeiDxeDebugLibReportStatusCode instance in MdePkg.</HelpText>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>UnicodeCollationEng.h</Filename>\r
+    <Filename>UnicodeCollationEng.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="ALWAYS_PRODUCED">\r
+      <ProtocolCName>gEfiUnicodeCollationProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <ModuleEntryPoint>InitializeUnicodeCollationEng</ModuleEntryPoint>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/UnicodeCollationEng.c b/MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/UnicodeCollationEng.c
new file mode 100644 (file)
index 0000000..5b543e9
--- /dev/null
@@ -0,0 +1,479 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. 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
+Module Name:\r
+\r
+  UnicodeCollationEng.c\r
+\r
+Abstract:\r
+\r
+  Unicode Collation Protocol (English)\r
+\r
+Revision History\r
+\r
+--*/\r
+\r
+\r
+#include "UnicodeCollationEng.h"\r
+\r
+CHAR8 mEngUpperMap[0x100];\r
+CHAR8 mEngLowerMap[0x100];\r
+CHAR8 mEngInfoMap[0x100];\r
+\r
+CHAR8 mOtherChars[] = {\r
+  '0',\r
+  '1',\r
+  '2',\r
+  '3',\r
+  '4',\r
+  '5',\r
+  '6',\r
+  '7',\r
+  '8',\r
+  '9',\r
+  '\\',\r
+  '.',\r
+  '_',\r
+  '^',\r
+  '$',\r
+  '~',\r
+  '!',\r
+  '#',\r
+  '%',\r
+  '&',\r
+  '-',\r
+  '{',\r
+  '}',\r
+  '(',\r
+  ')',\r
+  '@',\r
+  '`',\r
+  '\'',\r
+  '\0'\r
+};\r
+\r
+EFI_HANDLE  mHandle = NULL;\r
+\r
+EFI_UNICODE_COLLATION_PROTOCOL  UnicodeEng = {\r
+  EngStriColl,\r
+  EngMetaiMatch,\r
+  EngStrLwr,\r
+  EngStrUpr,\r
+  EngFatToStr,\r
+  EngStrToFat,\r
+  "eng"\r
+};\r
+\r
+//\r
+//\r
+//\r
+EFI_STATUS\r
+InitializeUnicodeCollationEng (\r
+  IN EFI_HANDLE       ImageHandle,\r
+  IN EFI_SYSTEM_TABLE *SystemTable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Initializes the Unicode Collation Driver\r
+\r
+Arguments:\r
+\r
+  ImageHandle -\r
+\r
+  SystemTable -\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS\r
+  EFI_OUT_OF_RESOURCES\r
+\r
+--*/\r
+{\r
+  UINTN       Index;\r
+  UINTN       Index2;\r
+\r
+  //\r
+  // Initialize mapping tables for the supported languages\r
+  //\r
+  for (Index = 0; Index < 0x100; Index++) {\r
+    mEngUpperMap[Index] = (CHAR8) Index;\r
+    mEngLowerMap[Index] = (CHAR8) Index;\r
+    mEngInfoMap[Index]  = 0;\r
+\r
+    if ((Index >= 'a' && Index <= 'z') || (Index >= 0xe0 && Index <= 0xf6) || (Index >= 0xf8 && Index <= 0xfe)) {\r
+\r
+      Index2                = Index - 0x20;\r
+      mEngUpperMap[Index]   = (CHAR8) Index2;\r
+      mEngLowerMap[Index2]  = (CHAR8) Index;\r
+\r
+      mEngInfoMap[Index] |= CHAR_FAT_VALID;\r
+      mEngInfoMap[Index2] |= CHAR_FAT_VALID;\r
+    }\r
+  }\r
+\r
+  for (Index = 0; mOtherChars[Index]; Index++) {\r
+    Index2 = mOtherChars[Index];\r
+    mEngInfoMap[Index2] |= CHAR_FAT_VALID;\r
+  }\r
+  //\r
+  // Create a handle for the device\r
+  //\r
+  return gBS->InstallProtocolInterface (\r
+                &mHandle,\r
+                &gEfiUnicodeCollationProtocolGuid,\r
+                EFI_NATIVE_INTERFACE,\r
+                &UnicodeEng\r
+                );\r
+}\r
+\r
+INTN\r
+EFIAPI\r
+EngStriColl (\r
+  IN EFI_UNICODE_COLLATION_PROTOCOL   *This,\r
+  IN CHAR16                           *s1,\r
+  IN CHAR16                           *s2\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Performs a case-insensitive comparison of two Null-terminated Unicode strings.\r
+\r
+Arguments:\r
+\r
+  This\r
+  s1\r
+  s2\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  while (*s1) {\r
+    if (ToUpper (*s1) != ToUpper (*s2)) {\r
+      break;\r
+    }\r
+\r
+    s1 += 1;\r
+    s2 += 1;\r
+  }\r
+\r
+  return ToUpper (*s1) - ToUpper (*s2);\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+EngStrLwr (\r
+  IN EFI_UNICODE_COLLATION_PROTOCOL   *This,\r
+  IN OUT CHAR16                       *Str\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Converts all the Unicode characters in a Null-terminated Unicode string\r
+  to lower case Unicode characters.\r
+\r
+Arguments:\r
+\r
+  This - A pointer to the EFI_UNICODE_COLLATION_PROTOCOL instance.\r
+  Str1  - A pointer to a Null-terminated Unicode string.\r
+  Str2  - A pointer to a Null-terminated Unicode string.\r
+\r
+Returns:\r
+\r
+  0   - s1 is equivalent to s2.\r
+  > 0 - s1 is lexically greater than s2.\r
+  < 0 - s1 is lexically less than s2.\r
+\r
+--*/\r
+{\r
+  while (*Str) {\r
+    *Str = ToLower (*Str);\r
+    Str += 1;\r
+  }\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+EngStrUpr (\r
+  IN EFI_UNICODE_COLLATION_PROTOCOL   *This,\r
+  IN OUT CHAR16                       *Str\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Converts all the Unicode characters in a Null-terminated\r
+  Unicode string to upper case Unicode characters.\r
+\r
+Arguments:\r
+  This\r
+  Str\r
+\r
+Returns:\r
+  None\r
+\r
+--*/\r
+{\r
+  while (*Str) {\r
+    *Str = ToUpper (*Str);\r
+    Str += 1;\r
+  }\r
+}\r
+\r
+BOOLEAN\r
+EFIAPI\r
+EngMetaiMatch (\r
+  IN EFI_UNICODE_COLLATION_PROTOCOL   *This,\r
+  IN CHAR16                           *String,\r
+  IN CHAR16                           *Pattern\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Performs a case-insensitive comparison between a Null-terminated\r
+  Unicode pattern string and a Null-terminated Unicode string.\r
+\r
+  The pattern string can use the '?' wildcard to match any character,\r
+  and the '*' wildcard to match any sub-string.\r
+\r
+Arguments:\r
+\r
+  This     - A pointer to the EFI_UNICODE_COLLATION_PROTOCOL instance.\r
+  String   - A pointer to a Null-terminated Unicode string.\r
+  Pattern  - A pointer to a Null-terminated Unicode pattern string.\r
+\r
+Returns:\r
+\r
+  TRUE  - Pattern was found in String.\r
+  FALSE - Pattern was not found in String.\r
+\r
+--*/\r
+{\r
+  CHAR16  CharC;\r
+  CHAR16  CharP;\r
+  CHAR16  Index3;\r
+\r
+  for (;;) {\r
+    CharP = *Pattern;\r
+    Pattern += 1;\r
+\r
+    switch (CharP) {\r
+    case 0:\r
+      //\r
+      // End of pattern.  If end of string, TRUE match\r
+      //\r
+      if (*String) {\r
+        return FALSE;\r
+      } else {\r
+        return TRUE;\r
+      }\r
+\r
+    case '*':\r
+      //\r
+      // Match zero or more chars\r
+      //\r
+      while (*String) {\r
+        if (EngMetaiMatch (This, String, Pattern)) {\r
+          return TRUE;\r
+        }\r
+\r
+        String += 1;\r
+      }\r
+\r
+      return EngMetaiMatch (This, String, Pattern);\r
+\r
+    case '?':\r
+      //\r
+      // Match any one char\r
+      //\r
+      if (!*String) {\r
+        return FALSE;\r
+      }\r
+\r
+      String += 1;\r
+      break;\r
+\r
+    case '[':\r
+      //\r
+      // Match char set\r
+      //\r
+      CharC = *String;\r
+      if (!CharC) {\r
+        //\r
+        // syntax problem\r
+        //\r
+        return FALSE;\r
+      }\r
+\r
+      Index3  = 0;\r
+      CharP   = *Pattern++;\r
+      while (CharP) {\r
+        if (CharP == ']') {\r
+          return FALSE;\r
+        }\r
+\r
+        if (CharP == '-') {\r
+          //\r
+          // if range of chars, get high range\r
+          //\r
+          CharP = *Pattern;\r
+          if (CharP == 0 || CharP == ']') {\r
+            //\r
+            // syntax problem\r
+            //\r
+            return FALSE;\r
+          }\r
+\r
+          if (ToUpper (CharC) >= ToUpper (Index3) && ToUpper (CharC) <= ToUpper (CharP)) {\r
+            //\r
+            // if in range, it's a match\r
+            //\r
+            break;\r
+          }\r
+        }\r
+\r
+        Index3 = CharP;\r
+        if (ToUpper (CharC) == ToUpper (CharP)) {\r
+          //\r
+          // if char matches\r
+          //\r
+          break;\r
+        }\r
+\r
+        CharP = *Pattern++;\r
+      }\r
+      //\r
+      // skip to end of match char set\r
+      //\r
+      while (CharP && CharP != ']') {\r
+        CharP = *Pattern;\r
+        Pattern += 1;\r
+      }\r
+\r
+      String += 1;\r
+      break;\r
+\r
+    default:\r
+      CharC = *String;\r
+      if (ToUpper (CharC) != ToUpper (CharP)) {\r
+        return FALSE;\r
+      }\r
+\r
+      String += 1;\r
+      break;\r
+    }\r
+  }\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+EngFatToStr (\r
+  IN EFI_UNICODE_COLLATION_PROTOCOL   *This,\r
+  IN UINTN                            FatSize,\r
+  IN CHAR8                            *Fat,\r
+  OUT CHAR16                          *String\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Converts an 8.3 FAT file name using an OEM character set\r
+  to a Null-terminated Unicode string.\r
+\r
+  BUGBUG: Function has to expand DBCS FAT chars, currently not.\r
+\r
+Arguments:\r
+  This\r
+  FatSize\r
+  Fat\r
+  String\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  //\r
+  // No DBCS issues, just expand and add null terminate to end of string\r
+  //\r
+  while (*Fat && FatSize) {\r
+    *String = *Fat;\r
+    String += 1;\r
+    Fat += 1;\r
+    FatSize -= 1;\r
+  }\r
+\r
+  *String = 0;\r
+}\r
+\r
+BOOLEAN\r
+EFIAPI\r
+EngStrToFat (\r
+  IN EFI_UNICODE_COLLATION_PROTOCOL   *This,\r
+  IN CHAR16                           *String,\r
+  IN UINTN                            FatSize,\r
+  OUT CHAR8                           *Fat\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Converts a Null-terminated Unicode string to legal characters\r
+  in a FAT filename using an OEM character set.\r
+\r
+  Functions has to crunch string to a fat string. Replacing\r
+  any chars that can't be represented in the fat name.\r
+\r
+Arguments:\r
+  This\r
+  String\r
+  FatSize\r
+  Fat\r
+\r
+Returns:\r
+  TRUE\r
+  FALSE\r
+--*/\r
+{\r
+  BOOLEAN SpecialCharExist;\r
+\r
+  SpecialCharExist = FALSE;\r
+  while (*String && FatSize) {\r
+    //\r
+    // Skip '.' or ' ' when making a fat name\r
+    //\r
+    if (*String != '.' && *String != ' ') {\r
+      //\r
+      // If this is a valid fat char, move it.\r
+      // Otherwise, move a '_' and flag the fact that the name needs an Lfn\r
+      //\r
+      if (*String < 0x100 && (mEngInfoMap[*String] & CHAR_FAT_VALID)) {\r
+        *Fat = mEngUpperMap[*String];\r
+      } else {\r
+        *Fat              = '_';\r
+        SpecialCharExist  = TRUE;\r
+      }\r
+\r
+      Fat += 1;\r
+      FatSize -= 1;\r
+    }\r
+\r
+    String += 1;\r
+  }\r
+  //\r
+  // Do not terminate that fat string\r
+  //\r
+  return SpecialCharExist;\r
+}\r
diff --git a/MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/UnicodeCollationEng.h b/MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/UnicodeCollationEng.h
new file mode 100644 (file)
index 0000000..1163d7a
--- /dev/null
@@ -0,0 +1,117 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. 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
+Module Name:\r
+\r
+  UnicodeCollationEng.h\r
+\r
+Abstract:\r
+\r
+  Head file for Unicode Collation Protocol (English)\r
+\r
+Revision History\r
+\r
+--*/\r
+\r
+#ifndef _UNICODE_COLLATION_ENG_H\r
+#define _UNICODE_COLLATION_ENG_H\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <Uefi.h>\r
+\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Protocol/UnicodeCollation.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+//\r
+// Defines\r
+//\r
+#define CHAR_FAT_VALID  0x01\r
+\r
+#define ToUpper(a)      (CHAR16) (a <= 0xFF ? mEngUpperMap[a] : a)\r
+#define ToLower(a)      (CHAR16) (a <= 0xFF ? mEngLowerMap[a] : a)\r
+\r
+//\r
+// Prototypes\r
+//\r
+INTN\r
+EFIAPI\r
+EngStriColl (\r
+  IN EFI_UNICODE_COLLATION_PROTOCOL           *This,\r
+  IN CHAR16                                   *s1,\r
+  IN CHAR16                                   *s2\r
+  )\r
+;\r
+\r
+BOOLEAN\r
+EFIAPI\r
+EngMetaiMatch (\r
+  IN EFI_UNICODE_COLLATION_PROTOCOL          *This,\r
+  IN CHAR16                                  *String,\r
+  IN CHAR16                                  *Pattern\r
+  )\r
+;\r
+\r
+VOID\r
+EFIAPI\r
+EngStrLwr (\r
+  IN EFI_UNICODE_COLLATION_PROTOCOL          *This,\r
+  IN OUT CHAR16                              *Str\r
+  )\r
+;\r
+\r
+VOID\r
+EFIAPI\r
+EngStrUpr (\r
+  IN EFI_UNICODE_COLLATION_PROTOCOL          *This,\r
+  IN OUT CHAR16                              *Str\r
+  )\r
+;\r
+\r
+VOID\r
+EFIAPI\r
+EngFatToStr (\r
+  IN EFI_UNICODE_COLLATION_PROTOCOL          *This,\r
+  IN UINTN                                   FatSize,\r
+  IN CHAR8                                   *Fat,\r
+  OUT CHAR16                                 *String\r
+  )\r
+;\r
+\r
+BOOLEAN\r
+EFIAPI\r
+EngStrToFat (\r
+  IN EFI_UNICODE_COLLATION_PROTOCOL          *This,\r
+  IN CHAR16                                  *String,\r
+  IN UINTN                                   FatSize,\r
+  OUT CHAR8                                  *Fat\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeUnicodeCollationEng (\r
+  IN EFI_HANDLE       ImageHandle,\r
+  IN EFI_SYSTEM_TABLE *SystemTable\r
+  )\r
+;\r
+\r
+#endif\r
diff --git a/MdeModulePkg/Universal/PCD/Dxe/Pcd.dxs b/MdeModulePkg/Universal/PCD/Dxe/Pcd.dxs
deleted file mode 100644 (file)
index 8601537..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*++\r
-\r
-Copyright (c) 2006 - 2007, Intel Corporation                                                         \r
-All rights reserved. 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
-Module Name:\r
-\r
-  Pcd.dxs\r
-\r
-Abstract:\r
-\r
-  Dependency expression source file.\r
-  \r
---*/  \r
-\r
-#include <DxeDepex.h>\r
-\r
-DEPENDENCY_START\r
-  TRUE\r
-DEPENDENCY_END\r
diff --git a/MdeModulePkg/Universal/PCD/Pei/Pcd.dxs b/MdeModulePkg/Universal/PCD/Pei/Pcd.dxs
deleted file mode 100644 (file)
index 3bad561..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/*++\r
-\r
-Copyright (c) 2006, Intel Corporation                                                         \r
-All rights reserved. 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
-Module Name:\r
-\r
-  Pcd.dxs\r
-\r
-Abstract:\r
-\r
-  Dependency expression source file.\r
-  \r
---*/  \r
-#include <DxeDepex.h>\r
-\r
-DEPENDENCY_START\r
-  TRUE\r
-DEPENDENCY_END\r
index a9022b951baaccf856f92af505756040eff0df74..fd2d2bc80fb01880d42cbc27f5eef109d42c7fd9 100644 (file)
@@ -39,7 +39,6 @@
 \r
 [Packages]\r
   MdePkg/MdePkg.dec\r
-  MdeModulePkg/MdeModulePkg.dec\r
 \r
 [LibraryClasses]\r
   BaseMemoryLib\r
diff --git a/MdeModulePkg/Universal/VariableRuntimeDxe/Variable.dxs b/MdeModulePkg/Universal/VariableRuntimeDxe/Variable.dxs
deleted file mode 100644 (file)
index f4aa840..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*++\r
-\r
-Copyright (c) 2006, Intel Corporation                                                         \r
-All rights reserved. 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
-Module Name:\r
-\r
-  Ia32Variable.dxs\r
-\r
-Abstract:\r
-\r
-  Dependency expression source file.\r
-  \r
---*/  \r
-//\r
-// Include common header file for this module.\r
-//\r
-#include "CommonHeader.h"\r
-\r
-#include <DxeDepex.h>\r
-\r
-DEPENDENCY_START\r
-  EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL_GUID AND\r
-  EFI_ALTERNATE_FV_BLOCK_GUID             AND\r
-  EFI_FTW_LITE_PROTOCOL_GUID\r
-DEPENDENCY_END\r
diff --git a/MdeModulePkg/Universal/WatchDogTimerDxe/WatchDogTimer.dxs b/MdeModulePkg/Universal/WatchDogTimerDxe/WatchDogTimer.dxs
deleted file mode 100644 (file)
index 27e7bf1..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*++\r
-\r
-Copyright (c) 2006, Intel Corporation                                                         \r
-All rights reserved. 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
-Module Name:\r
-\r
-  WatchDogTimer.dxs\r
-\r
-Abstract:\r
-\r
-  Dependency expression source file.\r
-  \r
---*/  \r
-//\r
-// Include common header file for this module.\r
-//\r
-#include "CommonHeader.h"\r
-\r
-#include <DxeDepex.h>\r
-\r
-DEPENDENCY_START\r
-  EFI_TIMER_ARCH_PROTOCOL_GUID\r
-DEPENDENCY_END\r
-\r