]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/HiiLib/HiiLib.c
Clean up IfrSupportLib.
[mirror_edk2.git] / MdePkg / Library / HiiLib / HiiLib.c
index b0c28e2a805daf7ff77cdd88e8cd8ddddca3cb2d..be3a31704d2f61799a16444bb0818d00c48fe2fd 100644 (file)
@@ -23,10 +23,6 @@ BOOLEAN mHiiProtocolsInitialized = FALSE;
 \r
   This function locate Hii relative protocols for later usage.\r
 \r
-  @param VOID\r
-\r
-  @retval  VOID\r
-\r
 **/\r
 VOID\r
 LocateHiiProtocols (\r
@@ -36,6 +32,9 @@ LocateHiiProtocols (
   EFI_STATUS  Status;\r
 \r
   if (mHiiProtocolsInitialized) {\r
+    //\r
+    // Only need to initialize the protocol instance once.\r
+    //\r
     return;\r
   }\r
 \r
@@ -50,11 +49,36 @@ LocateHiiProtocols (
 \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
+\r
+  #pragma pack (push, 1)\r
+  typedef struct {\r
+    UINT32                  BinaryLength;\r
+    EFI_HII_PACKAGE_HEADER  PackageHeader;\r
+  } TIANO_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
+**/\r
 EFI_HII_PACKAGE_LIST_HEADER *\r
 InternalHiiLibPreparePackages (\r
   IN UINTN           NumberOfPackages,\r
-  IN CONST EFI_GUID  *GuidId, OPTIONAL\r
-  VA_LIST            Marker\r
+  IN CONST EFI_GUID  *GuidId,\r
+  IN VA_LIST         Marker\r
   )\r
 {\r
   EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader;\r
@@ -72,6 +96,9 @@ InternalHiiLibPreparePackages (
   \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
   }\r
 \r
@@ -81,6 +108,7 @@ InternalHiiLibPreparePackages (
   PackageListLength += sizeof (EFI_HII_PACKAGE_HEADER);\r
   PackageListHeader = AllocateZeroPool (PackageListLength);\r
   ASSERT (PackageListHeader != NULL);\r
+  \r
   CopyMem (&PackageListHeader->PackageListGuid, GuidId, sizeof (EFI_GUID));\r
   PackageListHeader->PackageLength = PackageListLength;\r
 \r
@@ -106,6 +134,20 @@ InternalHiiLibPreparePackages (
   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
+\r
+  @return EFI_HII_PACKAGE_LIST_HEADER Pointer of EFI_HII_PACKAGE_LIST_HEADER. The function will ASSERT if system has\r
+                                      not enough resource to complete the operation.\r
+\r
+**/\r
 EFI_HII_PACKAGE_LIST_HEADER *\r
 EFIAPI\r
 HiiLibPreparePackageList (\r
@@ -127,6 +169,30 @@ HiiLibPreparePackageList (
 }\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 throught HiiHandle.\r
+\r
+  If HiiHandle is NULL, then ASSERT.\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
+  @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
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 HiiLibAddPackages (\r
@@ -161,6 +227,16 @@ HiiLibAddPackages (
   return Status;\r
 }\r
 \r
+/**\r
+  Removes a package list from the default 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
+\r
+  @param  HiiHandle                The handle that was previously registered to the data base that is requested for removal.\r
+                                             List later.\r
+\r
+**/\r
 VOID\r
 EFIAPI\r
 HiiLibRemovePackages (\r
@@ -168,7 +244,7 @@ HiiLibRemovePackages (
   )\r
 {\r
   EFI_STATUS Status;\r
-  ASSERT (HiiHandle != NULL);\r
+  ASSERT (IsHiiHandleRegistered (HiiHandle));\r
 \r
   LocateHiiProtocols ();\r
 \r
@@ -177,6 +253,21 @@ HiiLibRemovePackages (
 }\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
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 HiiLibGetHiiHandles (\r
@@ -225,6 +316,18 @@ HiiLibGetHiiHandles (
   return Status;\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 Guid is NULL, then ASSERT.\r
+\r
+  @param  Handle              Hii handle\r
+  @param  Guid                Package list GUID\r
+\r
+  @retval EFI_SUCCESS            Successfully extract GUID from Hii database.\r
+\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 HiiLibExtractGuidFromHiiHandle (\r
@@ -237,6 +340,7 @@ HiiLibExtractGuidFromHiiHandle (
   EFI_HII_PACKAGE_LIST_HEADER  *HiiPackageList;\r
 \r
   ASSERT (Guid != NULL);\r
+  ASSERT (IsHiiHandleRegistered (Handle));\r
 \r
   //\r
   // Get HII PackageList\r
@@ -264,11 +368,24 @@ HiiLibExtractGuidFromHiiHandle (
   //\r
   CopyMem (Guid, &HiiPackageList->PackageListGuid, sizeof (EFI_GUID));\r
 \r
-  gBS->FreePool (HiiPackageList);\r
+  FreePool (HiiPackageList);\r
 \r
   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
@@ -321,7 +438,7 @@ HiiLibDevicePathToHiiHandle (
       break;\r
     }\r
   }\r
-  gBS->FreePool (Handles);\r
+  FreePool (Handles);\r
 \r
   if (DriverHandle == NULL) {\r
     return NULL;\r
@@ -343,7 +460,7 @@ HiiLibDevicePathToHiiHandle (
                           HiiHandles\r
                           );\r
   if (Status == EFI_BUFFER_TOO_SMALL) {\r
-    gBS->FreePool (HiiHandles);\r
+    FreePool (HiiHandles);\r
     HiiHandles = AllocatePool (BufferSize);\r
     ASSERT (HiiHandles != NULL);\r
 \r
@@ -357,7 +474,7 @@ HiiLibDevicePathToHiiHandle (
   }\r
 \r
   if (EFI_ERROR (Status)) {\r
-    gBS->FreePool (HiiHandles);\r
+    FreePool (HiiHandles);\r
     return NULL;\r
   }\r
 \r
@@ -378,10 +495,19 @@ HiiLibDevicePathToHiiHandle (
     }\r
   }\r
 \r
-  gBS->FreePool (HiiHandles);\r
+  FreePool (HiiHandles);\r
   return HiiHandle;\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