]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
MdeModulePkg: Make HII configuration settings available to OS runtime
[mirror_edk2.git] / MdeModulePkg / Universal / HiiDatabaseDxe / Database.c
index ec56795ebb1924942403472a062cc3129aecbc8c..def1eb74a40854c7ce314522b9c1d5bf9e5e292d 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Implementation for EFI_HII_DATABASE_PROTOCOL.\r
 \r
-Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2016, 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
@@ -15,6 +15,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include "HiiDatabase.h"\r
 \r
+EFI_HII_PACKAGE_LIST_HEADER    *gRTDatabaseInfoBuffer = NULL;\r
+EFI_STRING                     gRTConfigRespBuffer    = NULL;\r
+UINTN                          gDatabaseInfoSize = 0;\r
+UINTN                          gConfigRespSize = 0;\r
+\r
 /**\r
   This function generates a HII_DATABASE_RECORD node and adds into hii database.\r
   This is a internal function.\r
@@ -2775,6 +2780,113 @@ ExportPackageList (
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+This is an internal function,mainly use to get and update configuration settings information.\r
+\r
+@param  This                   A pointer to the EFI_HII_DATABASE_PROTOCOL instance.\r
+\r
+@retval EFI_SUCCESS            Get the information successfully.\r
+@retval EFI_OUT_OF_RESOURCES   Not enough memory to store the Configuration Setting data.\r
+\r
+**/\r
+EFI_STATUS\r
+HiiGetConfigurationSetting(\r
+  IN CONST EFI_HII_DATABASE_PROTOCOL        *This\r
+  )\r
+{\r
+  EFI_STATUS                          Status;\r
+  HII_DATABASE_PRIVATE_DATA           *Private;\r
+  EFI_STRING                          ConfigAltResp;\r
+  UINTN                               ConfigSize;\r
+\r
+  ConfigAltResp        = NULL;\r
+  ConfigSize           = 0;\r
+\r
+  Private = HII_DATABASE_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  //\r
+  // Get the HiiDatabase info.\r
+  //\r
+  HiiGetDatabaseInfo(This);\r
+\r
+  //\r
+  // Get ConfigResp string\r
+  //\r
+  Status = HiiConfigRoutingExportConfig(&Private->ConfigRouting,&ConfigAltResp);\r
+\r
+  if (!EFI_ERROR (Status)){\r
+    ConfigSize = StrSize(ConfigAltResp);\r
+    if (ConfigSize > gConfigRespSize){\r
+      gConfigRespSize = ConfigSize;\r
+      if (gRTConfigRespBuffer != NULL){\r
+        FreePool(gRTConfigRespBuffer);\r
+      }\r
+      gRTConfigRespBuffer = (EFI_STRING)AllocateRuntimeZeroPool(ConfigSize);\r
+      if (gRTConfigRespBuffer == NULL){\r
+        FreePool(ConfigAltResp);\r
+        DEBUG ((DEBUG_ERROR, "Not enough memory resource to get the ConfigResp string.\n"));\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+    } else {\r
+      ZeroMem(gRTConfigRespBuffer,gConfigRespSize);\r
+    }\r
+    CopyMem(gRTConfigRespBuffer,ConfigAltResp,ConfigSize);\r
+    gBS->InstallConfigurationTable (&gEfiHiiConfigRoutingProtocolGuid, gRTConfigRespBuffer);\r
+    FreePool(ConfigAltResp);\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+\r
+}\r
+\r
+/**\r
+This is an internal function,mainly use to get HiiDatabase information.\r
+\r
+@param  This                   A pointer to the EFI_HII_DATABASE_PROTOCOL instance.\r
+\r
+@retval EFI_SUCCESS            Get the information successfully.\r
+@retval EFI_OUT_OF_RESOURCES   Not enough memory to store the Hiidatabase data.\r
+\r
+**/\r
+EFI_STATUS\r
+HiiGetDatabaseInfo(\r
+  IN CONST EFI_HII_DATABASE_PROTOCOL        *This\r
+  )\r
+{\r
+  EFI_STATUS                          Status;\r
+  EFI_HII_PACKAGE_LIST_HEADER         *DatabaseInfo;\r
+  UINTN                               DatabaseInfoSize;\r
+\r
+  DatabaseInfo         = NULL;\r
+  DatabaseInfoSize     = 0;\r
+\r
+  //\r
+  // Get HiiDatabase information.\r
+  //\r
+  Status = HiiExportPackageLists(This, NULL, &DatabaseInfoSize, DatabaseInfo);\r
+\r
+  ASSERT(Status == EFI_BUFFER_TOO_SMALL);\r
+\r
+  if(DatabaseInfoSize > gDatabaseInfoSize ) {\r
+    gDatabaseInfoSize = DatabaseInfoSize;\r
+    if (gRTDatabaseInfoBuffer != NULL){\r
+      FreePool(gRTDatabaseInfoBuffer);\r
+    }\r
+    gRTDatabaseInfoBuffer = AllocateRuntimeZeroPool(DatabaseInfoSize);\r
+    if (gRTDatabaseInfoBuffer == NULL){\r
+      DEBUG ((DEBUG_ERROR, "Not enough memory resource to get the HiiDatabase info.\n"));\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+  } else {\r
+    ZeroMem(gRTDatabaseInfoBuffer,gDatabaseInfoSize);\r
+  }\r
+  Status = HiiExportPackageLists(This, NULL, &DatabaseInfoSize, gRTDatabaseInfoBuffer);\r
+  ASSERT_EFI_ERROR (Status);\r
+  gBS->InstallConfigurationTable (&gEfiHiiDatabaseProtocolGuid, gRTDatabaseInfoBuffer);\r
+\r
+  return EFI_SUCCESS;\r
+\r
+}\r
 \r
 /**\r
   This function adds the packages in the package list to the database and returns a handle. If there is a\r
@@ -2867,6 +2979,15 @@ HiiNewPackageList (
   }\r
 \r
   *Handle = DatabaseRecord->Handle;\r
+\r
+  //\r
+  // Check whether need to get the Database and configuration setting info.\r
+  // Only after ReadyToBoot, need to do the export.\r
+  //\r
+  if (gExportAfterReadyToBoot) {\r
+    HiiGetConfigurationSetting(This);\r
+  }\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -2972,6 +3093,13 @@ HiiRemovePackageList (
       FreePool (Node->PackageList);\r
       FreePool (Node);\r
 \r
+      //\r
+      // Check whether need to get the Database and configuration setting info.\r
+      // Only after ReadyToBoot, need to do the export.\r
+      //\r
+      if (gExportAfterReadyToBoot) {\r
+        HiiGetConfigurationSetting(This);\r
+      }\r
       return EFI_SUCCESS;\r
     }\r
   }\r
@@ -3079,7 +3207,19 @@ HiiUpdatePackageList (
       //\r
       // Add all of the packages within the new package list\r
       //\r
-      return AddPackages (Private, EFI_HII_DATABASE_NOTIFY_ADD_PACK, PackageList, Node);\r
+      Status = AddPackages (Private, EFI_HII_DATABASE_NOTIFY_ADD_PACK, PackageList, Node);\r
+\r
+      //\r
+      // Check whether need to get the Database and configuration setting info.\r
+      // Only after ReadyToBoot, need to do the export.\r
+      //\r
+      if (gExportAfterReadyToBoot) {\r
+        if (Status == EFI_SUCCESS){\r
+          HiiGetConfigurationSetting(This);\r
+        }\r
+      }\r
+\r
+      return Status;\r
     }\r
   }\r
 \r