]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Utility.c
Merge branch 'master' of https://github.com/tianocore/edk2
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / FrameworkHiiOnUefiHiiThunk / Utility.c
index 0ad0668f728e6d1cb1f725b61cf67b505663a951..d269b8e4d6bab6c3482043122a5f5f8262c49a5c 100644 (file)
@@ -1,9 +1,9 @@
-/**@file\r
+/** @file\r
 \r
   This file contains the keyboard processing code to the HII database.\r
 \r
-Copyright (c) 2006 - 2008, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 http://opensource.org/licenses/bsd-license.php\r
@@ -17,10 +17,224 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include "HiiDatabase.h"\r
 #include "HiiHandle.h"\r
 #include <Library/DebugLib.h>\r
+#include <Guid/ZeroGuid.h>\r
 \r
-CONST EFI_GUID  gZeroGuid = {0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}};\r
 CONST CHAR16 FrameworkReservedVarstoreName[] = FRAMEWORK_RESERVED_VARSTORE_NAME;\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
+ListPackageLists (\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 = mHiiDatabase->ListPackageLists (\r
+                           mHiiDatabase,\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 mHiiDatabase->ListPackageLists (\r
+                         mHiiDatabase,\r
+                         PackageType,\r
+                         PackageGuid,\r
+                         HandleBufferLength,\r
+                         *HandleBuffer\r
+                         );\r
+  \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
+ExportPackageLists (\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
+  Size = 0;\r
+  PackageListHdr = NULL;\r
+  Status = mHiiDatabase->ExportPackageLists (\r
+                           mHiiDatabase,\r
+                           Handle,\r
+                           &Size,\r
+                           PackageListHdr\r
+                           );\r
+  ASSERT (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 = mHiiDatabase->ExportPackageLists (\r
+                               mHiiDatabase,\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
+  Extract Hii package list GUID for given HII handle.\r
+\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
+  @param  Guid                Package list GUID\r
+\r
+  @retval EFI_SUCCESS            Successfully extract GUID from Hii database.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ExtractGuidFromHiiHandle (\r
+  IN      EFI_HII_HANDLE      Handle,\r
+  OUT     EFI_GUID            *Guid\r
+  )\r
+{\r
+  EFI_STATUS                   Status;\r
+  UINTN                        BufferSize;\r
+  EFI_HII_PACKAGE_LIST_HEADER  *HiiPackageList;\r
+\r
+  ASSERT (Guid != NULL);\r
+  ASSERT (Handle != NULL);\r
+\r
+  //\r
+  // Get HII PackageList\r
+  //\r
+  BufferSize = 0;\r
+  HiiPackageList = NULL;\r
+\r
+  Status = mHiiDatabase->ExportPackageLists (mHiiDatabase, Handle, &BufferSize, HiiPackageList);\r
+  ASSERT (Status != EFI_NOT_FOUND);\r
+  \r
+  if (Status == EFI_BUFFER_TOO_SMALL) {\r
+    HiiPackageList = AllocatePool (BufferSize);\r
+    ASSERT (HiiPackageList != NULL);\r
+\r
+    Status = mHiiDatabase->ExportPackageLists (mHiiDatabase, Handle, &BufferSize, HiiPackageList);\r
+  }\r
+  if (EFI_ERROR (Status)) {\r
+    FreePool (HiiPackageList);\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Extract GUID\r
+  //\r
+  CopyGuid (Guid, &HiiPackageList->PackageListGuid);\r
+\r
+  FreePool (HiiPackageList);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
 \r
 /**\r
   Find the corressponding UEFI HII Handle from a Framework HII Handle given.\r
@@ -89,8 +303,8 @@ FwHiiHandleToThunkContext (
 /**\r
   Find the corressponding HII Thunk Context from a UEFI HII Handle given.\r
 \r
-  @param Private      The HII Thunk Module Private context.\r
-  @param UEFIHiiHandle  The UEFI HII Handle.\r
+  @param Private        The HII Thunk Module Private context.\r
+  @param UefiHiiHandle  The UEFI HII Handle.\r
 \r
   @return NULL        If UEFI HII Handle is invalid.\r
   @return The corresponding HII Thunk Context.\r
@@ -155,15 +369,15 @@ TagGuidToIfrPackThunkContext (
 /**\r
   Clean up the HII Thunk Context for a UEFI HII Handle.\r
 \r
-  @param Private      The HII Thunk Module Private context.\r
-  @param UEFIHiiHandle  The UEFI HII Handle.\r
+  @param Private        The HII Thunk Module Private context.\r
+  @param UefiHiiHandle  The UEFI HII Handle.\r
 \r
 **/\r
 VOID\r
 DestroyThunkContextForUefiHiiHandle (\r
   IN HII_THUNK_PRIVATE_DATA     *Private,\r
   IN EFI_HII_HANDLE             UefiHiiHandle\r
- )\r
 )\r
 {\r
   HII_THUNK_CONTEXT     *ThunkContext;\r
 \r
@@ -175,16 +389,21 @@ DestroyThunkContextForUefiHiiHandle (
 \r
 \r
 /**\r
-  This function create a HII_THUNK_CONTEXT for a package list registered\r
-  by a module calling EFI_HII_DATABASE_PROTOCOL.NewPackageList. It records\r
-  the PackageListGuid in EFI_HII_PACKAGE_LIST_HEADER in the TagGuid in \r
-  HII_THUNK_CONTEXT created. This TagGuid will be used as a key to s\r
+  This function create a HII_THUNK_CONTEXT for the input UEFI HiiHandle\r
+  that is created when a package list registered by a module calling \r
+  EFI_HII_DATABASE_PROTOCOL.NewPackageList. \r
+  This function records the PackageListGuid of EFI_HII_PACKAGE_LIST_HEADER \r
+  into the TagGuid of the created HII_THUNK_CONTEXT.\r
+\r
+  @param UefiHiiHandle  The UEFI HII Handle.\r
+  \r
+  @return the new created Hii thunk context.\r
 \r
 **/\r
 HII_THUNK_CONTEXT *\r
 CreateThunkContextForUefiHiiHandle (\r
   IN  EFI_HII_HANDLE             UefiHiiHandle\r
- )\r
 )\r
 {\r
   EFI_STATUS            Status;\r
   EFI_GUID              PackageGuid;\r
@@ -202,7 +421,7 @@ CreateThunkContextForUefiHiiHandle (
   \r
   ThunkContext->UefiHiiHandle = UefiHiiHandle;\r
   \r
-  Status = HiiLibExtractGuidFromHiiHandle (UefiHiiHandle, &PackageGuid);\r
+  Status = ExtractGuidFromHiiHandle (UefiHiiHandle, &PackageGuid);\r
   ASSERT_EFI_ERROR (Status);\r
   \r
   CopyGuid(&ThunkContext->TagGuid, &PackageGuid);\r
@@ -337,7 +556,7 @@ GetFormSetGuid (
 \r
   @param Private             The HII Thunk Private Context.\r
   @param StringPackageCount  The String package count.\r
-  @param FormSetGuid         The IFR Package count.\r
+  @param IfrPackageCount     The IFR Package count.\r
 \r
   @return  A newly created Thunk Context.\r
   @retval  NULL  No resource to create a new Thunk Context.\r
@@ -408,12 +627,10 @@ GetFormsetDefaultVarstoreId (
 {\r
   LIST_ENTRY             *StorageList;\r
   FORMSET_STORAGE        *Storage;\r
-  FORMSET_STORAGE        *DefaultStorage;\r
 \r
   //\r
   // VarStoreId 0 is invalid in UEFI IFR.\r
   //\r
-  DefaultStorage= NULL;\r
   FormSet->DefaultVarStoreId = 0;\r
   StorageList = GetFirstNode (&FormSet->StorageListHead);\r
 \r
@@ -427,7 +644,6 @@ GetFormsetDefaultVarstoreId (
       // 1) If VarStore ID of FRAMEWORK_RESERVED_VARSTORE_ID (0x01) is found, Var Store ID is used.\r
       //\r
       FormSet->DefaultVarStoreId = FRAMEWORK_RESERVED_VARSTORE_ID;\r
-      DefaultStorage = Storage;\r
       break;\r
     }\r
 \r
@@ -444,28 +660,13 @@ GetFormsetDefaultVarstoreId (
     if (!IsNull (&FormSet->StorageListHead, StorageList)) {\r
       Storage = FORMSET_STORAGE_FROM_LINK (StorageList);\r
       FormSet->DefaultVarStoreId = Storage->VarStoreId;\r
-      DefaultStorage = Storage;\r
     }\r
     \r
   }\r
 \r
-  DEBUG_CODE_BEGIN ();\r
   if (FormSet->DefaultVarStoreId == 0) {\r
     DEBUG ((EFI_D_INFO, "FormSet %g: No Varstore Found\n", &FormSet->Guid));\r
-  } else {\r
-    //    The name of default VARSTORE with a Explicit declaration statement will be updated to L"Setup" to make sure\r
-    //    the Framework HII Setup module will run correctly. Framework HII Setup module always assumed that default\r
-    //    VARSTORE to have L"Setup" as name, Formset GUID as GUID. \r
-\r
-    DEBUG ((EFI_D_INFO, "FormSet %g: Default Varstore ID (0x%x) N(%s) G(%g)\n", &FormSet->Guid, FormSet->DefaultVarStoreId, DefaultStorage->Name, &DefaultStorage->Guid));\r
-\r
-    if (StrCmp (DefaultStorage->Name, FrameworkReservedVarstoreName) != 0) {\r
-      DEBUG ((EFI_D_INFO, "          : Name is updated from %s to %s.\n", DefaultStorage->Name, FrameworkReservedVarstoreName));\r
-      FormSet->OriginalDefaultVarStoreName = DefaultStorage->Name;\r
-      DefaultStorage->Name = AllocateCopyPool (StrSize (FrameworkReservedVarstoreName), FrameworkReservedVarstoreName);\r
-    }\r
-  }\r
-  DEBUG_CODE_END ();\r
+  } \r
   \r
   return;\r
 }\r
@@ -531,8 +732,8 @@ GetIfrBinaryData (
 \r
     Status = mHiiDatabase->ExportPackageLists (mHiiDatabase, Handle, &BufferSize, HiiPackageList);\r
   }\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
+  if (EFI_ERROR (Status) || HiiPackageList == NULL) {\r
+    return EFI_NOT_FOUND;\r
   }\r
 \r
   //\r
@@ -680,7 +881,10 @@ ParseFormSet (
 \r
   CopyGuid (&FormSetGuid, &gZeroGuid);\r
   Status = InitializeFormSet (UefiHiiHandle, &FormSetGuid, FormSet);\r
-  ASSERT_EFI_ERROR (Status);\r
+  if (EFI_ERROR (Status)) {\r
+    FreePool (FormSet);\r
+    return NULL;\r
+  }\r
 \r
   return FormSet;\r
 }\r