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.

Export the configuration data and contents of HiiDatabase when
driver add package, update package and remove package.
For string and image may also need to update the contents of 
HiiDatabase when NewString/SetString, NewImage/SetImage.

Cc: Liming Gao <[email protected]>
Cc: Eric Dong <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Dandan Bi <[email protected]>
---
 MdeModulePkg/Universal/HiiDatabaseDxe/Database.c   | 135 ++++++++++++++++++++-
 .../Universal/HiiDatabaseDxe/HiiDatabase.h         |  16 ++-
 MdeModulePkg/Universal/HiiDatabaseDxe/Image.c      |  10 ++
 MdeModulePkg/Universal/HiiDatabaseDxe/String.c     |  12 +-
 4 files changed, 169 insertions(+), 4 deletions(-)

diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c 
b/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
index ec56795..c70a5be 100644
--- a/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
+++ b/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c
@@ -1,9 +1,9 @@
 /** @file
 Implementation for EFI_HII_DATABASE_PROTOCOL.
 
-Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD 
License
 which accompanies this distribution.  The full text of the license may be 
found at
 http://opensource.org/licenses/bsd-license.php
 
@@ -13,10 +13,15 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER 
EXPRESS OR IMPLIED.
 **/
 
 
 #include "HiiDatabase.h"
 
+EFI_HII_PACKAGE_LIST_HEADER    *gRTDatabaseInfoBuffer = NULL;
+EFI_STRING                     gRTConfigRespBuffer    = NULL;
+UINTN                          gDatabaseInfoSize = 0;
+UINTN                          gConfigRespSize = 0;
+
 /**
   This function generates a HII_DATABASE_RECORD node and adds into hii 
database.
   This is a internal function.
 
   @param  Private                hii database private structure
@@ -2773,10 +2778,117 @@ 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.
+
+@retval EFI_SUCCESS            Get the information successfully.
+@retval EFI_OUT_OF_RESOURCES   Not enough memory to store the Configuration 
Setting data.
+
+**/
+EFI_STATUS
+HiiGetConfigurationSetting(
+  IN CONST EFI_HII_DATABASE_PROTOCOL        *This
+  )
+{
+  EFI_STATUS                          Status;
+  HII_DATABASE_PRIVATE_DATA           *Private;
+  EFI_STRING                          ConfigAltResp;
+  UINTN                               ConfigSize;
+
+  ConfigAltResp        = NULL;
+  ConfigSize           = 0;
+
+  Private = HII_DATABASE_DATABASE_PRIVATE_DATA_FROM_THIS (This);
+
+  //
+  // Get the HiiDatabase info.
+  //
+  HiiGetDatabaseInfo(This);
+
+  //
+  // Get ConfigResp string
+  //
+  Status = 
HiiConfigRoutingExportConfig(&Private->ConfigRouting,&ConfigAltResp);
+
+  if (!EFI_ERROR (Status)){
+    ConfigSize = StrSize(ConfigAltResp);
+    if (ConfigSize > gConfigRespSize){
+      gConfigRespSize = ConfigSize;
+      if (gRTConfigRespBuffer != NULL){
+        FreePool(gRTConfigRespBuffer);
+      }
+      gRTConfigRespBuffer = (EFI_STRING)AllocateRuntimeZeroPool(ConfigSize);
+      if (gRTConfigRespBuffer == NULL){
+        FreePool(ConfigAltResp);
+        DEBUG ((DEBUG_ERROR, "Not enough memory resource to get the ConfigResp 
string.\n"));
+        return EFI_OUT_OF_RESOURCES;
+      }
+    } else {
+      ZeroMem(gRTConfigRespBuffer,gConfigRespSize);
+    }
+    CopyMem(gRTConfigRespBuffer,ConfigAltResp,ConfigSize);
+    gBS->InstallConfigurationTable (&gEfiHiiConfigRoutingProtocolGuid, 
gRTConfigRespBuffer);
+    FreePool(ConfigAltResp);
+  }
+
+  return EFI_SUCCESS;
+
+}
+
+/**
+This is an internal function,mainly use to get HiiDatabase information.
+
+@param  This                   A pointer to the EFI_HII_DATABASE_PROTOCOL 
instance.
+
+@retval EFI_SUCCESS            Get the information successfully.
+@retval EFI_OUT_OF_RESOURCES   Not enough memory to store the Hiidatabase data.
+
+**/
+EFI_STATUS
+HiiGetDatabaseInfo(
+  IN CONST EFI_HII_DATABASE_PROTOCOL        *This
+  )
+{
+  EFI_STATUS                          Status;
+  EFI_HII_PACKAGE_LIST_HEADER         *DatabaseInfo;
+  UINTN                               DatabaseInfoSize;
+
+  DatabaseInfo         = NULL;
+  DatabaseInfoSize     = 0;
+
+  //
+  // Get HiiDatabase information.
+  //
+  Status = HiiExportPackageLists(This, NULL, &DatabaseInfoSize, DatabaseInfo);
+
+  ASSERT(Status == EFI_BUFFER_TOO_SMALL);
+
+  if(DatabaseInfoSize > gDatabaseInfoSize ) {
+    gDatabaseInfoSize = DatabaseInfoSize;
+    if (gRTDatabaseInfoBuffer != NULL){
+      FreePool(gRTDatabaseInfoBuffer);
+    }
+    gRTDatabaseInfoBuffer = AllocateRuntimeZeroPool(DatabaseInfoSize);
+    if (gRTDatabaseInfoBuffer == NULL){
+      DEBUG ((DEBUG_ERROR, "Not enough memory resource to get the HiiDatabase 
info.\n"));
+      return EFI_OUT_OF_RESOURCES;
+    }
+  } else {
+    ZeroMem(gRTDatabaseInfoBuffer,gDatabaseInfoSize);
+  }
+  Status = HiiExportPackageLists(This, NULL, &DatabaseInfoSize, 
gRTDatabaseInfoBuffer);
+  ASSERT_EFI_ERROR (Status);
+  gBS->InstallConfigurationTable (&gEfiHiiDatabaseProtocolGuid, 
gRTDatabaseInfoBuffer);
+
+  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 +2977,16 @@ HiiNewPackageList (
     Status = AddDevicePathPackage (Private, EFI_HII_DATABASE_NOTIFY_NEW_PACK, 
DevicePath, DatabaseRecord);
     ASSERT_EFI_ERROR (Status);
   }
 
   *Handle = DatabaseRecord->Handle;
+
+  //
+  // Get the Database and configuration setting info.
+  //
+  HiiGetConfigurationSetting(This);
+
   return EFI_SUCCESS;
 }
 
 
 /**
@@ -2970,10 +3088,14 @@ HiiRemovePackageList (
       HiiHandle->Signature = 0;
       FreePool (HiiHandle);
       FreePool (Node->PackageList);
       FreePool (Node);
 
+      //
+      // Update  the Database and configuration setting info.
+      //
+      HiiGetConfigurationSetting(This);
       return EFI_SUCCESS;
     }
   }
 
   return EFI_NOT_FOUND;
@@ -3077,11 +3199,20 @@ 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 Database and configuration setting info.
+      //
+      if (Status == EFI_SUCCESS){
+        HiiGetConfigurationSetting(This);
+      }
+
+      return Status;
     }
   }
 
   return EFI_NOT_FOUND;
 }
diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabase.h 
b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabase.h
index bb0090a..bb13818 100644
--- a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabase.h
+++ b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabase.h
@@ -1,9 +1,9 @@
 /** @file
 Private structures definitions in HiiDatabase.
 
-Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD 
License
 which accompanies this distribution.  The full text of the license may be 
found at
 http://opensource.org/licenses/bsd-license.php
 
@@ -2013,10 +2013,24 @@ HiiCompareLanguage (
 CHAR8 *
 GetSupportedLanguages (
   IN EFI_HII_HANDLE           HiiHandle
   );
 
+/**
+This function mainly use to get HiiDatabase information.
+
+@param  This                   A pointer to the EFI_HII_DATABASE_PROTOCOL 
instance.
+
+@retval EFI_SUCCESS            Get the information successfully.
+@retval EFI_OUT_OF_RESOURCES   Not enough memory to store the Hiidatabase data.
+
+**/
+EFI_STATUS
+HiiGetDatabaseInfo(
+  IN CONST EFI_HII_DATABASE_PROTOCOL        *This
+  );
+
 //
 // Global variables
 //
 extern EFI_EVENT gHiiKeyboardLayoutChanged;
 #endif
diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c 
b/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c
index c46c965..ce89bfe 100644
--- a/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c
+++ b/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c
@@ -788,10 +788,15 @@ HiiNewImage (
   // Append the block end
   //
   ImageBlock += NewBlockSize;
   ((EFI_HII_IIBT_END_BLOCK *) (ImageBlock))->Header.BlockType = 
EFI_HII_IIBT_END;
 
+  //
+  // The contents of HiiDataBase may updated,need to check.
+  //
+  HiiGetDatabaseInfo(&Private->HiiDatabase);
+
   return EFI_SUCCESS;
 }
 
 
 /**
@@ -1176,10 +1181,15 @@ HiiSetImage (
   ImagePackage->ImageBlock     = Block;
   ImagePackage->ImageBlockSize = BlockSize;
   ImagePackage->ImagePkgHdr.Header.Length += NewBlockSize - OldBlockSize;
   PackageListNode->PackageListHdr.PackageLength += NewBlockSize - OldBlockSize;
 
+  //
+  // The contents of HiiDataBase may updated,need to check.
+  //
+  HiiGetDatabaseInfo(&Private->HiiDatabase);
+
   return EFI_SUCCESS;
 
 }
 
 
diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/String.c 
b/MdeModulePkg/Universal/HiiDatabaseDxe/String.c
index 2d04be4..9eea615 100644
--- a/MdeModulePkg/Universal/HiiDatabaseDxe/String.c
+++ b/MdeModulePkg/Universal/HiiDatabaseDxe/String.c
@@ -1,10 +1,10 @@
 /** @file
 Implementation for EFI_HII_STRING_PROTOCOL.
 
 
-Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD 
License
 which accompanies this distribution.  The full text of the license may be 
found at
 http://opensource.org/licenses/bsd-license.php
 
@@ -1556,10 +1556,16 @@ Done:
     RemoveEntryList (&StringPackage->StringEntry);
     FreePool (StringPackage->StringBlock);
     FreePool (StringPackage->StringPkgHdr);
     FreePool (StringPackage);
   }
+  //
+  // The contents of HiiDataBase may updated,need to check.
+  //
+  if (!EFI_ERROR (Status)){
+    HiiGetDatabaseInfo(&Private->HiiDatabase);
+  }
 
   return Status;
 }
 
 
@@ -1751,10 +1757,14 @@ HiiSetString (
                    );
         if (EFI_ERROR (Status)) {
           return Status;
         }
         PackageListNode->PackageListHdr.PackageLength += 
StringPackage->StringPkgHdr->Header.Length - OldPackageLen;
+        //
+        // The contents of HiiDataBase may updated,need to check.
+        //
+        HiiGetDatabaseInfo(&Private->HiiDatabase);
         return EFI_SUCCESS;
       }
     }
   }
 
-- 
1.9.5.msysgit.1

_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to