]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/UefiHiiLib/HiiLib.c
HII Library Class interface refine.
[mirror_edk2.git] / MdeModulePkg / Library / UefiHiiLib / HiiLib.c
index 384bab4ed6f3d80bb83b9e683c62c1200d008e6b..e337b234754434a7eb5c73ed3dcbff1b403c12ab 100644 (file)
 //\r
 GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR16 mConfigHdrTemplate[] = L"GUID=00000000000000000000000000000000&NAME=0000&PATH=00";\r
 \r
+EFI_FORM_BROWSER2_PROTOCOL  *mUefiFormBrowser2 = NULL;\r
+\r
 //\r
-// Form Browser2 Protocol\r
+// Template used to mark the end of a list of packages \r
 //\r
-EFI_FORM_BROWSER2_PROTOCOL  *mUefiFormBrowser2 = NULL;\r
+GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_HII_PACKAGE_HEADER  mEndOfPakageList = {\r
+  sizeof (EFI_HII_PACKAGE_HEADER),\r
+  EFI_HII_PACKAGE_END\r
+};\r
 \r
 /**\r
-  This funciton build the package list based on the package number,\r
-  the GUID of the package list and the list of pointer which point to\r
-  package header that defined by UEFI VFR compiler and StringGather\r
-  tool.\r
+  Registers a list of packages in the HII Database and returns the HII Handle\r
+  associated with that registration.  If an HII Handle has already been registered\r
+  with the same PackageListGuid, then NULL is returned.  If there are not enough \r
+  resources to perform the registration, then NULL is returned.  If an empty list \r
+  of packages is passed in, then NULL is returned.  If the size of the list of \r
+  package is 0, then NULL is returned.\r
+\r
+  The variable arguments are pointers which point to package header that defined \r
+  by UEFI VFR compiler and StringGather tool.\r
 \r
   #pragma pack (push, 1)\r
   typedef struct {\r
@@ -36,267 +46,269 @@ EFI_FORM_BROWSER2_PROTOCOL  *mUefiFormBrowser2 = NULL;
     EFI_HII_PACKAGE_HEADER  PackageHeader;\r
   } EDKII_AUTOGEN_PACKAGES_HEADER;\r
   #pragma pack (pop)\r
-\r
-  If there is not enough resource for the new package list,\r
-  the function will ASSERT.\r
-\r
-  @param NumberOfPackages The number of packages be \r
-  @param GuidId          The GUID for the package list to be generated.\r
-  @param Marker          The variable argument list. Each entry represent a specific package header that is\r
-                         generated by VFR compiler and StrGather tool. The first 4 bytes is a UINT32 value\r
-                         that indicate the overall length of the package.\r
-\r
-  @return The pointer to the package list header.\r
+  \r
+  @param[in]  PackageListGuid  The GUID of the package list.\r
+  @param[in]  DeviceHandle     If not NULL, the Device Handle on which \r
+                               an instance of DEVICE_PATH_PROTOCOL is installed.\r
+                               This Device Handle uniquely defines the device that \r
+                               the added packages are associated with.\r
+  @param[in]  ...              The variable argument list that contains pointers \r
+                               to packages terminated by a NULL.\r
+\r
+  @retval NULL   A HII Handle has already been registered in the HII Database with\r
+                 the same PackageListGuid.\r
+  @retval NULL   The HII Handle could not be created.\r
+  @retval NULL   An empty list of packages was passed in.\r
+  @retval NULL   All packages are empty.\r
+  @retval Other  The HII Handle associated with the newly registered package list.\r
 \r
 **/\r
-EFI_HII_PACKAGE_LIST_HEADER *\r
-InternalHiiLibPreparePackages (\r
-  IN UINTN           NumberOfPackages,\r
-  IN CONST EFI_GUID  *GuidId,\r
-  IN VA_LIST         Marker\r
+EFI_HII_HANDLE\r
+EFIAPI\r
+HiiAddPackages (\r
+  IN CONST EFI_GUID    *PackageListGuid,\r
+  IN       EFI_HANDLE  DeviceHandle  OPTIONAL,\r
+  ...\r
   )\r
 {\r
-  EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader;\r
-  UINT8                       *PackageListData;\r
-  UINT32                      PackageListLength;\r
-  UINT32                      PackageLength;\r
-  EFI_HII_PACKAGE_HEADER      PackageHeader;\r
-  UINT8                       *PackageArray;\r
-  UINTN                       Index;\r
-  VA_LIST                     MarkerBackup;\r
-\r
-  PackageListLength = sizeof (EFI_HII_PACKAGE_LIST_HEADER);\r
+  EFI_STATUS                   Status;\r
+  EFI_HII_HANDLE               *HiiHandleBuffer;\r
+  VA_LIST                      Args;\r
+  UINT32                       *Package;\r
+  EFI_HII_PACKAGE_LIST_HEADER  *PackageListHeader;\r
+  EFI_HII_HANDLE               HiiHandle;\r
+  UINT32                       Length;\r
+  UINT8                        *Data;\r
 \r
-  MarkerBackup = Marker;\r
+  ASSERT (PackageListGuid != NULL);\r
 \r
   //\r
-  // Count the length of the final package list.\r
+  // Check to see if an HII Handle has already been registered with the same \r
+  // PackageListGuid\r
   //\r
-  for (Index = 0; Index < NumberOfPackages; Index++) {\r
-    CopyMem (&PackageLength, VA_ARG (Marker, VOID *), sizeof (UINT32));\r
-    //\r
-    // Do not count the BinaryLength field.\r
-    //\r
-    PackageListLength += (PackageLength - sizeof (UINT32));\r
+  HiiHandleBuffer = HiiGetHiiHandles (PackageListGuid);\r
+  if (HiiHandleBuffer != NULL) {\r
+    FreePool (HiiHandleBuffer);\r
+    return NULL;\r
   }\r
 \r
   //\r
-  // Include the length of EFI_HII_PACKAGE_END\r
+  // Calculate the length of all the packages in the variable argument list\r
   //\r
-  PackageListLength += sizeof (EFI_HII_PACKAGE_HEADER);\r
-  PackageListHeader = AllocateZeroPool (PackageListLength);\r
-  ASSERT (PackageListHeader != NULL);\r
-  \r
-  CopyGuid (&PackageListHeader->PackageListGuid, GuidId);\r
-  PackageListHeader->PackageLength = PackageListLength;\r
-\r
-  PackageListData = ((UINT8 *) PackageListHeader) + sizeof (EFI_HII_PACKAGE_LIST_HEADER);\r
+  for (Length = 0, VA_START (Args, DeviceHandle); (Package = VA_ARG (Args, UINT32 *)) != NULL; ) {\r
+    Length += (ReadUnaligned32 (Package) - sizeof (UINT32));\r
+  }\r
+  VA_END (Args);\r
 \r
-  Marker = MarkerBackup;\r
   //\r
-  // Prepare the final package list.\r
+  // If there are no packages in the variable argument list or all the packages \r
+  // are empty, then return a NULL HII Handle\r
   //\r
-  for (Index = 0; Index < NumberOfPackages; Index++) {\r
-    PackageArray = (UINT8 *) VA_ARG (Marker, VOID *);\r
-    //\r
-    // CopyMem is used for UINT32 to cover the unaligned address access.\r
-    //\r
-    CopyMem (&PackageLength, PackageArray, sizeof (UINT32));\r
-    PackageLength  -= sizeof (UINT32);\r
-    PackageArray += sizeof (UINT32);\r
-    CopyMem (PackageListData, PackageArray, PackageLength);\r
-    PackageListData += PackageLength;\r
+  if (Length == 0) {\r
+    return NULL;\r
   }\r
 \r
   //\r
-  // Append EFI_HII_PACKAGE_END\r
+  // Add the length of the Package List Header and the terminating Package Header \r
   //\r
-  PackageHeader.Type = EFI_HII_PACKAGE_END;\r
-  PackageHeader.Length = sizeof (EFI_HII_PACKAGE_HEADER);\r
-  CopyMem (PackageListData, &PackageHeader, PackageHeader.Length);\r
-\r
-  return PackageListHeader;\r
-}\r
-\r
-/**\r
-  Assemble EFI_HII_PACKAGE_LIST according to the passed in packages.\r
-\r
-  If GuidId is NULL, then ASSERT.\r
-  If not enough resource to complete the operation, then ASSERT.\r
-\r
-  @param  NumberOfPackages       Number of packages.\r
-  @param  GuidId                 Package GUID.\r
-  @param  ...                    Variable argument list for packages to be assembled.\r
+  Length += sizeof (EFI_HII_PACKAGE_LIST_HEADER) + sizeof (EFI_HII_PACKAGE_HEADER);\r
 \r
-  @return Pointer of EFI_HII_PACKAGE_LIST_HEADER.\r
-\r
-**/\r
-EFI_HII_PACKAGE_LIST_HEADER *\r
-EFIAPI\r
-HiiLibPreparePackageList (\r
-  IN UINTN                    NumberOfPackages,\r
-  IN CONST EFI_GUID           *GuidId,\r
-  ...\r
-  )\r
-{\r
-  EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader;\r
-  VA_LIST                     Marker;\r
-\r
-  ASSERT (GuidId != NULL);\r
-\r
-  VA_START (Marker, GuidId);\r
-  PackageListHeader = InternalHiiLibPreparePackages (NumberOfPackages, GuidId, Marker);\r
-  VA_END (Marker);\r
-\r
-  return PackageListHeader;\r
-}\r
-\r
-\r
-/**\r
-  This function allocates pool for an EFI_HII_PACKAGE_LIST structure\r
-  with additional space that is big enough to host all packages described by the variable \r
-  argument list of package pointers.  The allocated structure is initialized using NumberOfPackages, \r
-  GuidId,  and the variable length argument list of package pointers.\r
-\r
-  Then, EFI_HII_PACKAGE_LIST will be register to the default System HII Database. The\r
-  Handle to the newly registered Package List is returned through HiiHandle.\r
-\r
-  If HiiHandle is NULL, then ASSERT.\r
+  //\r
+  // Allocate the storage for the entire Package List\r
+  //\r
+  PackageListHeader = AllocateZeroPool (Length);\r
 \r
-  @param  NumberOfPackages    The number of HII packages to register.\r
-  @param  GuidId              Package List GUID ID.\r
-  @param  DriverHandle        Optional. If not NULL, the DriverHandle on which an instance of DEVICE_PATH_PROTOCOL is installed.\r
-                              This DriverHandle uniquely defines the device that the added packages are associated with.\r
-  @param  HiiHandle           On output, the HiiHandle is update with the handle which can be used to retrieve the Package \r
-                              List later. If the functions failed to add the package to the default HII database, this value will\r
-                              be set to NULL.\r
-  @param  ...                 The variable argument list describing all HII Package.\r
+  //\r
+  // If the Packahge List can not be allocated, then return a NULL HII Handle\r
+  //\r
+  if (PackageListHeader == NULL) {\r
+    return NULL;\r
+  }\r
 \r
-  @return  EFI_SUCCESS         If the packages are successfully added to the default HII database.\r
-  @return  EFI_OUT_OF_RESOURCE Not enough resource to complete the operation.\r
+  //\r
+  // Fill in the GUID and Length of the Package List Header\r
+  //\r
+  CopyGuid (&PackageListHeader->PackageListGuid, PackageListGuid);\r
+  PackageListHeader->PackageLength = Length;\r
 \r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-HiiLibAddPackages (\r
-  IN       UINTN               NumberOfPackages,\r
-  IN CONST EFI_GUID            *GuidId,\r
-  IN       EFI_HANDLE          DriverHandle, OPTIONAL\r
-  OUT      EFI_HII_HANDLE      *HiiHandle,\r
-  ...\r
-  )\r
-{\r
-  VA_LIST                   Args;\r
-  EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader;\r
-  EFI_STATUS                Status;\r
+  //\r
+  // Initialize a pointer to the beginning if the Package List data\r
+  //\r
+  Data = (UINT8 *)(PackageListHeader + 1);\r
 \r
-  ASSERT (HiiHandle != NULL);\r
+  //\r
+  // Copy the data from each package in the variable argument list\r
+  //\r
+  for (VA_START (Args, DeviceHandle); (Package = VA_ARG (Args, UINT32 *)) != NULL; ) {\r
+    Length = ReadUnaligned32 (Package) - sizeof (UINT32);\r
+    CopyMem (Data, Package + 1, Length);\r
+    Data += Length;\r
+  }\r
+  VA_END (Args);\r
 \r
-  VA_START (Args, HiiHandle);\r
-  PackageListHeader = InternalHiiLibPreparePackages (NumberOfPackages, GuidId, Args);\r
+  //\r
+  // Append a package of type EFI_HII_PACKAGE_END to mark the end of the package list\r
+  //\r
+  CopyMem (Data, &mEndOfPakageList, sizeof (mEndOfPakageList));\r
 \r
-  Status      = gHiiDatabase->NewPackageList (gHiiDatabase, PackageListHeader, DriverHandle, HiiHandle);\r
-  if (HiiHandle != NULL) {\r
-    if (EFI_ERROR (Status)) {\r
-      *HiiHandle = NULL;\r
-    }\r
+  //\r
+  // Register the package list with the HII Database\r
+  //\r
+  Status = gHiiDatabase->NewPackageList (\r
+                           gHiiDatabase, \r
+                           PackageListHeader, \r
+                           DeviceHandle, \r
+                           &HiiHandle\r
+                           );\r
+  if (EFI_ERROR (Status)) {\r
+    HiiHandle = NULL;\r
   }\r
 \r
+  //\r
+  // Free the allocated package list\r
+  //\r
   FreePool (PackageListHeader);\r
-  VA_END (Args);\r
-  \r
-  return Status;\r
+\r
+  //\r
+  // Return the new HII Handle\r
+  //\r
+  return HiiHandle;\r
 }\r
 \r
 /**\r
-  Removes a package list from the default HII database.\r
+  Removes a package list from the HII database.\r
 \r
   If HiiHandle is NULL, then ASSERT.\r
-  If HiiHandle is not a valid EFI_HII_HANDLE in the default HII database, then ASSERT.\r
+  If HiiHandle is not a valid EFI_HII_HANDLE in the HII database, then ASSERT.\r
 \r
-  @param  HiiHandle                The handle that was previously registered to the data base that is requested for removal.\r
-                                             List later.\r
+  @param[in]  HiiHandle   The handle that was previously registered in the HII database\r
 \r
 **/\r
 VOID\r
 EFIAPI\r
-HiiLibRemovePackages (\r
+HiiRemovePackages (\r
   IN      EFI_HII_HANDLE      HiiHandle\r
   )\r
 {\r
   EFI_STATUS Status;\r
-  ASSERT (IsHiiHandleRegistered (HiiHandle));\r
 \r
+  ASSERT (HiiHandle != NULL);\r
   Status = gHiiDatabase->RemovePackageList (gHiiDatabase, HiiHandle);\r
   ASSERT_EFI_ERROR (Status);\r
 }\r
 \r
 \r
 /**\r
-  Determines the handles that are currently active in the database.\r
-  It's the caller's responsibility to free handle buffer.\r
-\r
-  If HandleBufferLength is NULL, then ASSERT.\r
-  If HiiHandleBuffer is NULL, then ASSERT.\r
-\r
-  @param  HandleBufferLength     On input, a pointer to the length of the handle\r
-                                 buffer. On output, the length of the handle buffer\r
-                                 that is required for the handles found.\r
-  @param  HiiHandleBuffer        Pointer to an array of Hii Handles returned.\r
-\r
-  @retval EFI_SUCCESS            Get an array of Hii Handles successfully.\r
+  Retrieves the array of all the HII Handles or the HII handle of a specific\r
+  package list in the HII Database.\r
+  This array is terminated with a NULL HII Handle.\r
+  This function allocates the returned array using AllocatePool().\r
+  The caller is responsible for freeing the array with FreePool().\r
+\r
+  @param[in]  PackageListGuid  An optional parameter that is used to request \r
+                               an HII Handle that is associatd with a specific\r
+                               Package List GUID.  If this parameter is NULL\r
+                               then all the HII Handles in the HII Database\r
+                               are returned.  If this parameter is not NULL\r
+                               then at most 1 HII Handle is returned.\r
+\r
+  @retval NULL   No HII handles were found in the HII database\r
+  @retval NULL   The array of HII Handles could not be retrieved\r
+  @retval Other  A pointer to the NULL terminated array of HII Handles\r
 \r
 **/\r
-EFI_STATUS\r
+EFI_HII_HANDLE *\r
 EFIAPI\r
-HiiLibGetHiiHandles (\r
-  IN OUT UINTN                     *HandleBufferLength,\r
-  OUT    EFI_HII_HANDLE            **HiiHandleBuffer\r
+HiiGetHiiHandles (\r
+  IN CONST EFI_GUID  *PackageListGuid  OPTIONAL\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
+  EFI_STATUS      Status;\r
+  UINTN           HandleBufferLength;\r
+  EFI_HII_HANDLE  TempHiiHandleBuffer;\r
+  EFI_HII_HANDLE  *HiiHandleBuffer;\r
+  EFI_GUID        Guid;\r
+  UINTN           Index;\r
+\r
+  //\r
+  // Retrieve the size required for the buffer of all HII handles.\r
+  //\r
+  HandleBufferLength = 0;\r
+  Status = gHiiDatabase->ListPackageLists (\r
+                           gHiiDatabase,\r
+                           EFI_HII_PACKAGE_TYPE_ALL,\r
+                           NULL,\r
+                           &HandleBufferLength,\r
+                           &TempHiiHandleBuffer\r
+                           );\r
 \r
-  ASSERT (HandleBufferLength != NULL);\r
-  ASSERT (HiiHandleBuffer != NULL);\r
+  //\r
+  // If ListPackageLists() returns EFI_SUCCESS for a zero size, \r
+  // then there are no HII handles in the HII database.  If ListPackageLists() \r
+  // returns an error other than EFI_BUFFER_TOO_SMALL, then there are no HII \r
+  // handles in the HII database.\r
+  //\r
+  if (Status != EFI_BUFFER_TOO_SMALL) {\r
+    //\r
+    // Return NULL if the size can not be retrieved, or if there are no HII \r
+    // handles in the HII Database\r
+    //\r
+    return NULL;\r
+  }\r
 \r
-  *HandleBufferLength = 0;\r
-  *HiiHandleBuffer = NULL;\r
+  //\r
+  // Allocate the array of HII handles to hold all the HII Handles and a NULL terminator\r
+  //\r
+  HiiHandleBuffer = AllocateZeroPool (HandleBufferLength + sizeof (EFI_HII_HANDLE));\r
+  if (HiiHandleBuffer == NULL) {\r
+    //\r
+    // Return NULL if allocation fails.\r
+    //\r
+    return NULL;\r
+  }\r
 \r
   //\r
-  // Try to find the actual buffer size for HiiHandle Buffer.\r
+  // Retrieve the array of HII Handles in the HII Database\r
   //\r
   Status = gHiiDatabase->ListPackageLists (\r
-                                 gHiiDatabase,\r
-                                 EFI_HII_PACKAGE_TYPE_ALL,\r
-                                 NULL,\r
-                                 HandleBufferLength,\r
-                                 *HiiHandleBuffer\r
-                                 );\r
-  \r
-  if (Status == EFI_BUFFER_TOO_SMALL) {\r
-      *HiiHandleBuffer = AllocateZeroPool (*HandleBufferLength);\r
-      ASSERT (*HiiHandleBuffer != NULL);\r
-      Status = gHiiDatabase->ListPackageLists (\r
-                                     gHiiDatabase,\r
-                                     EFI_HII_PACKAGE_TYPE_ALL,\r
-                                     NULL,\r
-                                     HandleBufferLength,\r
-                                     *HiiHandleBuffer\r
-                                     );\r
-\r
-      if (EFI_ERROR (Status)) {\r
-        FreePool (*HiiHandleBuffer);\r
-        *HiiHandleBuffer = NULL;\r
-      }\r
+                           gHiiDatabase,\r
+                           EFI_HII_PACKAGE_TYPE_ALL,\r
+                           NULL,\r
+                           &HandleBufferLength,\r
+                           HiiHandleBuffer\r
+                           );\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // Free the buffer and return NULL if the HII handles can not be retrieved.\r
+    //\r
+    FreePool (HiiHandleBuffer);\r
+    return NULL;\r
   }\r
 \r
-  return Status;\r
+  if (PackageListGuid == NULL) {\r
+    //\r
+    // Return the NULL terminated array of HII handles in the HII Database\r
+    //\r
+    return HiiHandleBuffer;\r
+  } else {\r
+    for (Index = 0; HiiHandleBuffer[Index] != NULL; Index++) {\r
+      Status = InternalHiiExtractGuidFromHiiHandle (HiiHandleBuffer[Index], &Guid);\r
+      ASSERT_EFI_ERROR (Status);\r
+      if (CompareGuid (&Guid, PackageListGuid)) {\r
+        HiiHandleBuffer[0] = HiiHandleBuffer[Index];\r
+        HiiHandleBuffer[1] = NULL;\r
+        return HiiHandleBuffer;\r
+      }\r
+    }\r
+    FreePool (HiiHandleBuffer);\r
+    return NULL;\r
+  }\r
 }\r
 \r
 /**\r
   Extract Hii package list GUID for given HII handle.\r
 \r
-  If HiiHandle could not be found in the default HII database, then ASSERT.\r
+  If HiiHandle could not be found in the HII database, then ASSERT.\r
   If Guid is NULL, then ASSERT.\r
 \r
   @param  Handle              Hii handle\r
@@ -307,7 +319,7 @@ HiiLibGetHiiHandles (
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-HiiLibExtractGuidFromHiiHandle (\r
+InternalHiiExtractGuidFromHiiHandle (\r
   IN      EFI_HII_HANDLE      Handle,\r
   OUT     EFI_GUID            *Guid\r
   )\r
@@ -317,7 +329,7 @@ HiiLibExtractGuidFromHiiHandle (
   EFI_HII_PACKAGE_LIST_HEADER  *HiiPackageList;\r
 \r
   ASSERT (Guid != NULL);\r
-  ASSERT (IsHiiHandleRegistered (Handle));\r
+  ASSERT (Handle != NULL);\r
 \r
   //\r
   // Get HII PackageList\r
@@ -349,326 +361,6 @@ HiiLibExtractGuidFromHiiHandle (
   return EFI_SUCCESS;\r
 }\r
 \r
-/**\r
-  Find HII Handle in the default HII database associated with given Device Path.\r
-\r
-  If DevicePath is NULL, then ASSERT.\r
-\r
-  @param  DevicePath             Device Path associated with the HII package list\r
-                                 handle.\r
-\r
-  @retval Handle                 HII package list Handle associated with the Device\r
-                                        Path.\r
-  @retval NULL                   Hii Package list handle is not found.\r
-\r
-**/\r
-EFI_HII_HANDLE\r
-EFIAPI\r
-HiiLibDevicePathToHiiHandle (\r
-  IN EFI_DEVICE_PATH_PROTOCOL   *DevicePath\r
-  )\r
-{\r
-  EFI_STATUS                  Status;\r
-  EFI_DEVICE_PATH_PROTOCOL    *TmpDevicePath;\r
-  UINTN                       BufferSize;\r
-  UINTN                       HandleCount;\r
-  UINTN                       Index;\r
-  EFI_HANDLE                  *Handles;\r
-  EFI_HANDLE                  Handle;\r
-  UINTN                       Size;\r
-  EFI_HANDLE                  DriverHandle;\r
-  EFI_HII_HANDLE              *HiiHandles;\r
-  EFI_HII_HANDLE              HiiHandle;\r
-\r
-  ASSERT (DevicePath != NULL);\r
-\r
-  //\r
-  // Locate Device Path Protocol handle buffer\r
-  //\r
-  Status = gBS->LocateHandleBuffer (\r
-                  ByProtocol,\r
-                  &gEfiDevicePathProtocolGuid,\r
-                  NULL,\r
-                  &HandleCount,\r
-                  &Handles\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    return NULL;\r
-  }\r
-\r
-  //\r
-  // Search Driver Handle by Device Path\r
-  //\r
-  DriverHandle = NULL;\r
-  BufferSize = GetDevicePathSize (DevicePath);\r
-  for(Index = 0; Index < HandleCount; Index++) {\r
-    Handle = Handles[Index];\r
-    gBS->HandleProtocol (Handle, &gEfiDevicePathProtocolGuid, (VOID **) &TmpDevicePath);\r
-\r
-    //\r
-    // Check whether DevicePath match\r
-    //\r
-    Size = GetDevicePathSize (TmpDevicePath);\r
-    if ((Size == BufferSize) && CompareMem (DevicePath, TmpDevicePath, Size) == 0) {\r
-      DriverHandle = Handle;\r
-      break;\r
-    }\r
-  }\r
-  FreePool (Handles);\r
-\r
-  if (DriverHandle == NULL) {\r
-    return NULL;\r
-  }\r
-\r
-  //\r
-  // Retrieve all Hii Handles from HII database\r
-  //\r
-  BufferSize = 0x1000;\r
-  HiiHandles = AllocatePool (BufferSize);\r
-  ASSERT (HiiHandles != NULL);\r
-  Status = gHiiDatabase->ListPackageLists (\r
-                          gHiiDatabase,\r
-                          EFI_HII_PACKAGE_TYPE_ALL,\r
-                          NULL,\r
-                          &BufferSize,\r
-                          HiiHandles\r
-                          );\r
-  if (Status == EFI_BUFFER_TOO_SMALL) {\r
-    FreePool (HiiHandles);\r
-    HiiHandles = AllocatePool (BufferSize);\r
-    ASSERT (HiiHandles != NULL);\r
-\r
-    Status = gHiiDatabase->ListPackageLists (\r
-                            gHiiDatabase,\r
-                            EFI_HII_PACKAGE_TYPE_ALL,\r
-                            NULL,\r
-                            &BufferSize,\r
-                            HiiHandles\r
-                            );\r
-  }\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    FreePool (HiiHandles);\r
-    return NULL;\r
-  }\r
-\r
-  //\r
-  // Search Hii Handle by Driver Handle\r
-  //\r
-  HiiHandle = NULL;\r
-  HandleCount = BufferSize / sizeof (EFI_HII_HANDLE);\r
-  for (Index = 0; Index < HandleCount; Index++) {\r
-    Status = gHiiDatabase->GetPackageListHandle (\r
-                            gHiiDatabase,\r
-                            HiiHandles[Index],\r
-                            &Handle\r
-                            );\r
-    if (!EFI_ERROR (Status) && (Handle == DriverHandle)) {\r
-      HiiHandle = HiiHandles[Index];\r
-      break;\r
-    }\r
-  }\r
-\r
-  FreePool (HiiHandles);\r
-  return HiiHandle;\r
-}\r
-\r
-/**\r
-  Exports the contents of one or all package lists in the HII database into a buffer.\r
-\r
-  If Handle is not NULL and not a valid EFI_HII_HANDLE registered in the database, \r
-  then ASSERT.\r
-  If PackageListHeader is NULL, then ASSERT.\r
-  If PackageListSize is NULL, then ASSERT.\r
-\r
-  @param  Handle                 The HII Handle.\r
-  @param  PackageListHeader      A pointer to a buffer that will contain the results of \r
-                                 the export function.\r
-  @param  PackageListSize        On output, the length of the buffer that is required for the exported data.\r
-\r
-  @retval EFI_SUCCESS            Package exported.\r
-\r
-  @retval EFI_OUT_OF_RESOURCES   Not enought memory to complete the operations.\r
-\r
-**/\r
-EFI_STATUS \r
-EFIAPI\r
-HiiLibExportPackageLists (\r
-  IN EFI_HII_HANDLE                    Handle,\r
-  OUT EFI_HII_PACKAGE_LIST_HEADER      **PackageListHeader,\r
-  OUT UINTN                            *PackageListSize\r
-  )\r
-{\r
-  EFI_STATUS                       Status;\r
-  UINTN                            Size;\r
-  EFI_HII_PACKAGE_LIST_HEADER      *PackageListHdr;\r
-\r
-  ASSERT (PackageListSize != NULL);\r
-  ASSERT (PackageListHeader != NULL);\r
-\r
-  if (Handle != NULL) {\r
-    ASSERT (IsHiiHandleRegistered (Handle));\r
-  }\r
-\r
-  Size = 0;\r
-  PackageListHdr = NULL;\r
-  Status = gHiiDatabase->ExportPackageLists (\r
-                                      gHiiDatabase,\r
-                                      Handle,\r
-                                      &Size,\r
-                                      PackageListHdr\r
-                                      );\r
-  ASSERT_EFI_ERROR (Status != EFI_BUFFER_TOO_SMALL);\r
-  \r
-  if (Status == EFI_BUFFER_TOO_SMALL) {\r
-    PackageListHdr = AllocateZeroPool (Size);\r
-    \r
-    if (PackageListHeader == NULL) {\r
-      return EFI_OUT_OF_RESOURCES;\r
-    } else {\r
-      Status = gHiiDatabase->ExportPackageLists (\r
-                                          gHiiDatabase,\r
-                                          Handle,\r
-                                          &Size,\r
-                                          PackageListHdr\r
-                                           );\r
-    }\r
-  }\r
-\r
-  if (!EFI_ERROR (Status)) {\r
-    *PackageListHeader = PackageListHdr;\r
-    *PackageListSize   = Size;\r
-  } else {\r
-    FreePool (PackageListHdr);\r
-  }\r
-\r
-  return Status;\r
-}\r
-\r
-/**\r
-  \r
-  This function returns a list of the package handles of the   \r
-  specified type that are currently active in the HII database. The   \r
-  pseudo-type EFI_HII_PACKAGE_TYPE_ALL will cause all package   \r
-  handles to be listed.\r
-\r
-  If HandleBufferLength is NULL, then ASSERT.\r
-  If HandleBuffer is NULL, the ASSERT.\r
-  If PackageType is EFI_HII_PACKAGE_TYPE_GUID and PackageGuid is\r
-  NULL, then ASSERT.\r
-  If PackageType is not EFI_HII_PACKAGE_TYPE_GUID and PackageGuid is not\r
-  NULL, then ASSERT.\r
-  \r
-  \r
-  @param PackageType          Specifies the package type of the packages\r
-                              to list or EFI_HII_PACKAGE_TYPE_ALL for\r
-                              all packages to be listed.\r
-  \r
-  @param PackageGuid          If PackageType is\r
-                              EFI_HII_PACKAGE_TYPE_GUID, then this is\r
-                              the pointer to the GUID which must match\r
-                              the Guid field of\r
-                              EFI_HII_PACKAGE_GUID_HEADER. Otherwise, it\r
-                              must be NULL.\r
-  \r
-  @param HandleBufferLength   On output, the length of the handle buffer\r
-                              that is required for the handles found.\r
-\r
-  @param HandleBuffer         On output, an array of EFI_HII_HANDLE  instances returned.\r
-                              The caller is responcible to free this pointer allocated.\r
-\r
-  @retval EFI_SUCCESS           The matching handles are outputed successfully.\r
-                                HandleBufferLength is updated with the actual length.\r
-  @retval EFI_OUT_OF_RESOURCES  Not enough resource to complete the operation.\r
-  @retval EFI_NOT_FOUND         No matching handle could not be found in database.\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-HiiLibListPackageLists (\r
-  IN        UINT8                     PackageType,\r
-  IN CONST  EFI_GUID                  *PackageGuid,\r
-  IN OUT    UINTN                     *HandleBufferLength,\r
-  OUT       EFI_HII_HANDLE            **HandleBuffer\r
-  )\r
-{\r
-  EFI_STATUS          Status;\r
-  \r
-  ASSERT (HandleBufferLength != NULL);\r
-  ASSERT (HandleBuffer != NULL);\r
-  \r
-  *HandleBufferLength = 0;\r
-  *HandleBuffer       = NULL;\r
-\r
-  if (PackageType == EFI_HII_PACKAGE_TYPE_GUID) {\r
-    ASSERT (PackageGuid != NULL);\r
-  } else {\r
-    ASSERT (PackageGuid == NULL);\r
-  }\r
-\r
-  Status = gHiiDatabase->ListPackageLists (\r
-                            gHiiDatabase,\r
-                            PackageType,\r
-                            PackageGuid,\r
-                            HandleBufferLength,\r
-                            *HandleBuffer\r
-                            );\r
-  if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) {\r
-    //\r
-    // No packages is registered to UEFI HII Database, just return.\r
-    // \r
-    //\r
-    return Status;\r
-  }\r
-\r
-  *HandleBuffer = AllocateZeroPool (*HandleBufferLength);\r
-  \r
-  if (*HandleBuffer == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-  \r
-  return gHiiDatabase->ListPackageLists (\r
-                            gHiiDatabase,\r
-                            PackageType,\r
-                            PackageGuid,\r
-                            HandleBufferLength,\r
-                            *HandleBuffer\r
-                            );\r
-  \r
-}\r
-/**\r
-  This function check if the Hii Handle is a valid handle registered\r
-  in the HII database.\r
-\r
-  @param HiiHandle The HII Handle.\r
-\r
-  @retval TRUE If it is a valid HII handle.\r
-  @retval FALSE If it is a invalid HII handle.\r
-**/\r
-BOOLEAN\r
-IsHiiHandleRegistered (\r
-  EFI_HII_HANDLE    HiiHandle\r
-  )\r
-{\r
-  EFI_STATUS                   Status;\r
-  UINTN                        BufferSize;\r
-  EFI_HII_PACKAGE_LIST_HEADER  *HiiPackageList;\r
-\r
-  ASSERT (HiiHandle != NULL);\r
-\r
-  HiiPackageList = NULL;\r
-  BufferSize = 0;\r
-\r
-  Status = gHiiDatabase->ExportPackageLists (\r
-             gHiiDatabase,\r
-             HiiHandle,\r
-             &BufferSize,\r
-             HiiPackageList\r
-             );\r
-\r
-  return (BOOLEAN) (Status == EFI_BUFFER_TOO_SMALL);\r
-}\r
-\r
-\r
 /**\r
   Converts all hex dtring characters in range ['A'..'F'] to ['a'..'f'] for \r
   hex digits that appear between a '=' and a '&' in a config string.\r
@@ -2916,3 +2608,4 @@ HiiIfrLibExtractDefault(
 \r
   return EFI_SUCCESS;\r
 }\r
+\r