This feature is aimed to allow OS make use of the HII database during runtime.
In this case, the contents of the HII Database is exported to a buffer.
The pointer to the buffer is placed in the EFI System Configuration Table,
where it can be retrieved by an OS application.

Cc: Liming Gao <liming....@intel.com>
Cc: Eric Dong <eric.d...@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Dandan Bi <dandan...@intel.com>
---
 MdeModulePkg/Universal/HiiDatabaseDxe/Database.c   | 102 ++++++++++++++++++++-
 .../Universal/HiiDatabaseDxe/HiiDatabase.h         |   5 +
 .../Universal/HiiDatabaseDxe/HiiDatabaseEntry.c    |  51 +++++++++++
 3 files changed, 157 insertions(+), 1 deletion(-)

diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c 
b/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
index ec56795..011e712 100644
--- a/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
+++ b/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
@@ -2773,10 +2773,96 @@ ExportPackageList (
   *UsedSize += ResultSize + sizeof (EFI_HII_PACKAGE_HEADER);
 
   return EFI_SUCCESS;
 }
 
+/**
+This is an internal function,mainly use to get and update configuration 
settings information.
+
+@param  This            A pointer to the EFI_HII_DATABASE_PROTOCOL instance.
+@param  NewPackage      Indaicate whether add the packages in the package list 
to the database.
+
+@retval EFI_SUCCESS     Get the information successfully.
+
+**/
+EFI_STATUS
+HiiGetConfigurationSetting(
+  IN CONST EFI_HII_DATABASE_PROTOCOL        *This,
+  IN BOOLEAN                                NewPackage
+  )
+{
+  EFI_STATUS                          Status;
+  HII_DATABASE_PRIVATE_DATA           *Private;
+  EFI_HII_PACKAGE_LIST_HEADER         *DatabaseInfo;
+  EFI_STRING                          ConfigAltResp;
+  UINTN                               DatabaseInfoSize;
+  UINTN                               ConfigLen;
+  
+  DatabaseInfo         = NULL;
+  ConfigAltResp        = NULL;
+  DatabaseInfoSize     = 0;
+  ConfigLen            = 0;
+
+  Private = HII_DATABASE_DATABASE_PRIVATE_DATA_FROM_THIS (This);
+
+  //
+  // Get the length of the buffer that is required for the exported data.
+  //
+
+  Status = HiiExportPackageLists(This, NULL, &DatabaseInfoSize, DatabaseInfo);
+  if (Status == EFI_BUFFER_TOO_SMALL) {
+    if (gRTDatabaseInfoBuffer == NULL){
+      gRTDatabaseInfoBuffer = AllocateRuntimePool (DatabaseInfoSize);
+    } else if (DatabaseInfoSize != gDatabaseInfoSize ) {
+      if (NewPackage){
+        gBS->InstallConfigurationTable (&gEfiHiiDatabaseProtocolGuid, NULL);
+      }
+      gRTDatabaseInfoBuffer = 
ReallocateRuntimePool(gDatabaseInfoSize,DatabaseInfoSize,gRTDatabaseInfoBuffer);
+    }
+    ASSERT (gRTDatabaseInfoBuffer != NULL);
+
+    gDatabaseInfoSize = DatabaseInfoSize;
+
+    //
+    //install it to configuration table.
+    //
+    if (NewPackage){
+      gBS->InstallConfigurationTable (&gEfiHiiDatabaseProtocolGuid, 
gRTDatabaseInfoBuffer);
+    }
+  }
+
+  //
+  // Get ConfigResp string 
+  //
+  Status = 
HiiConfigRoutingExportConfig(&Private->ConfigRouting,&ConfigAltResp);
+  if (!EFI_ERROR (Status)){
+    ConfigLen = StrLen(ConfigAltResp);
+    if (gRTConfigRespBuffer == NULL){
+      gRTConfigRespBuffer = AllocateRuntimePool ((ConfigLen + 1) * sizeof 
(CHAR16));
+    } else if (ConfigLen != gConfigLen ){
+      if (NewPackage){
+        gBS->InstallConfigurationTable (&gEfiHiiConfigRoutingProtocolGuid, 
NULL);
+      }
+      gRTConfigRespBuffer = ReallocateRuntimePool((gConfigLen + 1) * sizeof 
(CHAR16),(ConfigLen + 1) * sizeof (CHAR16),gRTConfigRespBuffer);
+    }
+    ASSERT (gRTConfigRespBuffer != NULL);
+
+    gConfigLen = ConfigLen;
+    
+    //
+    //install it to configuration table.
+    //
+    if (NewPackage){
+      gBS->InstallConfigurationTable (&gEfiHiiConfigRoutingProtocolGuid, 
gRTConfigRespBuffer);
+    }
+
+    FreePool(ConfigAltResp);
+  }
+
+  return EFI_SUCCESS;
+
+}
 
 /**
   This function adds the packages in the package list to the database and 
returns a handle. If there is a
   EFI_DEVICE_PATH_PROTOCOL associated with the DriverHandle, then this 
function will
   create a package of type EFI_PACKAGE_TYPE_DEVICE_PATH and add it to the 
package list.
@@ -2865,10 +2951,18 @@ HiiNewPackageList (
     Status = AddDevicePathPackage (Private, EFI_HII_DATABASE_NOTIFY_NEW_PACK, 
DevicePath, DatabaseRecord);
     ASSERT_EFI_ERROR (Status);
   }
 
   *Handle = DatabaseRecord->Handle;
+
+  //
+  // Get the configuration setting info.
+  // And install it to configuration table.
+  //
+
+  HiiGetConfigurationSetting(This,TRUE);
+
   return EFI_SUCCESS;
 }
 
 
 /**
@@ -3077,11 +3171,17 @@ HiiUpdatePackageList (
       }
 
       //
       // Add all of the packages within the new package list
       //
-      return AddPackages (Private, EFI_HII_DATABASE_NOTIFY_ADD_PACK, 
PackageList, Node);
+      Status = AddPackages (Private, EFI_HII_DATABASE_NOTIFY_ADD_PACK, 
PackageList, Node);
+      //
+      // Update the the configuration setting info
+      //
+      HiiGetConfigurationSetting(This,FALSE);
+
+      return Status; 
     }
   }
 
   return EFI_NOT_FOUND;
 }
diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabase.h 
b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabase.h
index bb0090a..1be508b 100644
--- a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabase.h
+++ b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabase.h
@@ -2017,6 +2017,11 @@ GetSupportedLanguages (
 
 //
 // Global variables
 //
 extern EFI_EVENT gHiiKeyboardLayoutChanged;
+extern EFI_HII_PACKAGE_LIST_HEADER *gRTDatabaseInfoBuffer;
+extern EFI_STRING gRTConfigRespBuffer;
+extern UINTN gDatabaseInfoSize;
+extern UINTN gConfigLen;
+
 #endif
diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseEntry.c 
b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseEntry.c
index 6448c97..c35655c 100644
--- a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseEntry.c
+++ b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseEntry.c
@@ -18,10 +18,16 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER 
EXPRESS OR IMPLIED.
 
 //
 // Global variables
 //
 EFI_EVENT gHiiKeyboardLayoutChanged;
+EFI_EVENT mExitBootServicesEvent = (EFI_EVENT)NULL;
+
+EFI_HII_PACKAGE_LIST_HEADER    *gRTDatabaseInfoBuffer = NULL;
+EFI_STRING                     gRTConfigRespBuffer    = NULL;
+UINTN                          gDatabaseInfoSize = 0;
+UINTN                          gConfigLen = 0;
 
 HII_DATABASE_PRIVATE_DATA mPrivate = {
   HII_DATABASE_PRIVATE_DATA_SIGNATURE,
   {
     (LIST_ENTRY *) NULL,
@@ -122,10 +128,43 @@ KeyboardLayoutChangeNullEvent (
 {
   return;
 }
 
 /**
+  Callback function for ExitBootServices.
+
+  @param  Event                 Event whose notification function is being 
invoked.
+  @param  Context               The pointer to the notification function's 
context,
+                                which is implementation-dependent.
+
+**/
+VOID
+EFIAPI
+ExitBootServicesCallback (
+  IN EFI_EVENT                Event,
+  IN VOID                     *Context
+  )
+{
+  EFI_STATUS                          Status;
+
+  //
+  //export the contents of the HII Database and the current configuration into 
 runtime buffer
+  //
+  Status = HiiExportPackageLists(&mPrivate.HiiDatabase, NULL, 
&gDatabaseInfoSize, gRTDatabaseInfoBuffer);
+  ASSERT_EFI_ERROR (Status);
+
+  Status = 
HiiConfigRoutingExportConfig(&mPrivate.ConfigRouting,&gRTConfigRespBuffer);
+  ASSERT_EFI_ERROR (Status);
+
+  //
+  // Install the package list and configuration date to configuration table.
+  //
+  gBS->InstallConfigurationTable (&gEfiHiiDatabaseProtocolGuid, 
gRTDatabaseInfoBuffer);
+  gBS->InstallConfigurationTable (&gEfiHiiConfigRoutingProtocolGuid, 
gRTConfigRespBuffer);
+}
+
+/**
   Initialize HII Database.
 
 
   @param ImageHandle     The image handle.
   @param SystemTable     The system table.
@@ -177,10 +216,22 @@ InitializeHiiDatabase (
                   );
   if (EFI_ERROR (Status)) {
     return Status;
   }
 
+  //
+  // Create a event with EVT_SIGNAL_EXIT_BOOT_SERVICES type.
+  //
+  Status = gBS->CreateEvent (
+                  EVT_SIGNAL_EXIT_BOOT_SERVICES,
+                  TPL_CALLBACK,
+                  ExitBootServicesCallback,
+                  NULL,
+                  &mExitBootServicesEvent
+                  );
+  ASSERT_EFI_ERROR (Status);
+
   Handle = NULL;
   Status = gBS->InstallMultipleProtocolInterfaces (
                   &Handle,
                   &gEfiHiiFontProtocolGuid,
                   &mPrivate.HiiFont,
-- 
1.9.5.msysgit.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to