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.
Notes: Difference with previous version: - Add a Pcd to control this feature, default is enabled. - Export the date after ReadyToBoot. Cc: Liming Gao <liming....@intel.com> Cc: Eric Dong <eric.d...@intel.com> Cc: Brian J. Johnson <bjohn...@sgi.com> Cc: Andrew Fish <af...@apple.com> Cc: El-Haj-Mahmoud, Samer <samer.el-haj-mahm...@hpe.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Dandan Bi <dandan...@intel.com> --- MdeModulePkg/MdeModulePkg.dec | 8 ++ MdeModulePkg/Universal/HiiDatabaseDxe/Database.c | 144 ++++++++++++++++++++- .../Universal/HiiDatabaseDxe/HiiDatabase.h | 30 +++++ .../Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf | 3 +- .../Universal/HiiDatabaseDxe/HiiDatabaseEntry.c | 42 +++++- MdeModulePkg/Universal/HiiDatabaseDxe/Image.c | 16 +++ MdeModulePkg/Universal/HiiDatabaseDxe/String.c | 21 ++- 7 files changed, 259 insertions(+), 5 deletions(-) diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index af7bcab..7e8cca3 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -706,10 +706,18 @@ [PcdsFeatureFlag] # TRUE - Serial device uses half hand shake.<BR> # FALSE - Serial device doesn't use half hand shake.<BR> # @Prompt Enable Serial device Half Hand Shake gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseHalfHandshake|FALSE|BOOLEAN|0x00010073 + ## Indicates if HII data and configuration has been exported.<BR><BR> + # Add this PCD mainly consider the use case of simulator. This PCD maybe set to FALSE for + # simulator platform because the performance cost for this feature. + # TRUE - Export HII data and configuration data.<BR> + # FALSE - Does not export HII data and configuration.<BR> + # @Prompt Enable export HII data and configuration to be used in OS runtime. + gEfiMdeModulePkgTokenSpaceGuid.PcdHiiOsRuntimeSupport|TRUE|BOOLEAN|0x00010074 + [PcdsFeatureFlag.IA32, PcdsFeatureFlag.X64] ## Indicates if DxeIpl should switch to long mode to enter DXE phase. # It is assumed that 64-bit DxeCore is built in firmware if it is true; otherwise 32-bit DxeCore # is built in firmware.<BR><BR> # TRUE - DxeIpl will load a 64-bit DxeCore and switch to long mode to hand over to DxeCore.<BR> diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c b/MdeModulePkg/Universal/HiiDatabaseDxe/Database.c index ec56795..acda061 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,19 @@ HiiNewPackageList ( Status = AddDevicePathPackage (Private, EFI_HII_DATABASE_NOTIFY_NEW_PACK, DevicePath, DatabaseRecord); ASSERT_EFI_ERROR (Status); } *Handle = DatabaseRecord->Handle; + + // + // Check whether need to get the Database and configuration setting info. + // Only after ReadyToBoot, need to do the export. + // + if (ExportAfterReadyToBoot) { + HiiGetConfigurationSetting(This); + } + return EFI_SUCCESS; } /** @@ -2970,10 +3091,17 @@ HiiRemovePackageList ( HiiHandle->Signature = 0; FreePool (HiiHandle); FreePool (Node->PackageList); FreePool (Node); + // + // Check whether need to get the Database and configuration setting info. + // Only after ReadyToBoot, need to do the export. + // + if (ExportAfterReadyToBoot) { + HiiGetConfigurationSetting(This); + } return EFI_SUCCESS; } } return EFI_NOT_FOUND; @@ -3077,11 +3205,23 @@ 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); + + // + // Check whether need to get the Database and configuration setting info. + // Only after ReadyToBoot, need to do the export. + // + if (ExportAfterReadyToBoot) { + 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 6e28df7..409bea6 100644 --- a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabase.h +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabase.h @@ -2015,10 +2015,40 @@ 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 + ); + +/** +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 + ); + // // Global variables // extern EFI_EVENT gHiiKeyboardLayoutChanged; +extern BOOLEAN ExportAfterReadyToBoot; + #endif diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf index 7892503..2fb619e 100644 --- a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf @@ -2,11 +2,11 @@ # The DXE driver produces HII protocols defined in UEFI specification. # # This driver produces all required HII serivces that includes HiiDataBase, HiiString, # HiiFont, HiiConfigRouting. To support UEFI HII, this driver is required. # -# 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 @@ -70,10 +70,11 @@ [Protocols] gEfiHiiConfigAccessProtocolGuid ## SOMETIMES_CONSUMES gEfiConfigKeywordHandlerProtocolGuid ## PRODUCES [FeaturePcd] gEfiMdeModulePkgTokenSpaceGuid.PcdSupportHiiImageProtocol ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdHiiOsRuntimeSupport ## CONSUMES [Pcd] gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultPlatformLang ## CONSUMES [Guids] diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseEntry.c b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseEntry.c index 6448c97..ad402c2 100644 --- a/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseEntry.c +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseEntry.c @@ -1,10 +1,10 @@ /** @file This file contains the entry code to the HII database, which is defined by UEFI 2.1 specification. -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 @@ -18,10 +18,12 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. // // Global variables // EFI_EVENT gHiiKeyboardLayoutChanged; +EFI_EVENT ReadyToBootEvent; +BOOLEAN ExportAfterReadyToBoot = FALSE; HII_DATABASE_PRIVATE_DATA mPrivate = { HII_DATABASE_PRIVATE_DATA_SIGNATURE, { (LIST_ENTRY *) NULL, @@ -122,10 +124,34 @@ KeyboardLayoutChangeNullEvent ( { return; } /** + On Ready To Boot Services Event notification handler. + + To trigger the function that to export the Hii Configuration setting. + + @param[in] Event Event whose notification function is being invoked + @param[in] Context Pointer to the notification function's context + +**/ +VOID +EFIAPI +OnReadyToBoot ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + // + // When ready to boot, we begin to export the HiiDatabase date. + // And hook all the possible HiiDatabase change actions to export data. + // + HiiGetConfigurationSetting(&mPrivate.HiiDatabase); + ExportAfterReadyToBoot = TRUE; +} + +/** Initialize HII Database. @param ImageHandle The image handle. @param SystemTable The system table. @@ -133,10 +159,12 @@ KeyboardLayoutChangeNullEvent ( @retval EFI_SUCCESS The Hii database is setup correctly. @return Other value if failed to create the default event for gHiiKeyboardLayoutChanged. Check gBS->CreateEventEx for details. Or failed to insatll the protocols. Check gBS->InstallMultipleProtocolInterfaces for details. + Or failed to create Ready To Boot Event. + Check EfiCreateEventReadyToBootEx for details. **/ EFI_STATUS EFIAPI InitializeHiiDatabase ( @@ -209,8 +237,20 @@ InitializeHiiDatabase ( NULL ); } + if (FeaturePcdGet(PcdHiiOsRuntimeSupport)) { + Status = EfiCreateEventReadyToBootEx ( + TPL_CALLBACK, + OnReadyToBoot, + NULL, + &ReadyToBootEvent + ); + if (EFI_ERROR (Status)) { + return Status; + } + } + return Status; } diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c b/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c index c46c965..a8d9ccc 100644 --- a/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/Image.c @@ -788,10 +788,18 @@ HiiNewImage ( // Append the block end // ImageBlock += NewBlockSize; ((EFI_HII_IIBT_END_BLOCK *) (ImageBlock))->Header.BlockType = EFI_HII_IIBT_END; + // + // Check whether need to get the contents of HiiDataBase. + // Only after ReadyToBoot to do the export. + // + if (ExportAfterReadyToBoot) { + HiiGetDatabaseInfo(&Private->HiiDatabase); + } + return EFI_SUCCESS; } /** @@ -1176,10 +1184,18 @@ HiiSetImage ( ImagePackage->ImageBlock = Block; ImagePackage->ImageBlockSize = BlockSize; ImagePackage->ImagePkgHdr.Header.Length += NewBlockSize - OldBlockSize; PackageListNode->PackageListHdr.PackageLength += NewBlockSize - OldBlockSize; + // + // Check whether need to get the contents of HiiDataBase. + // Only after ReadyToBoot to do the export. + // + if (ExportAfterReadyToBoot) { + HiiGetDatabaseInfo(&Private->HiiDatabase); + } + return EFI_SUCCESS; } diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/String.c b/MdeModulePkg/Universal/HiiDatabaseDxe/String.c index 2d04be4..a92af2e 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,22 @@ Done: RemoveEntryList (&StringPackage->StringEntry); FreePool (StringPackage->StringBlock); FreePool (StringPackage->StringPkgHdr); FreePool (StringPackage); } + // + // The contents of HiiDataBase may updated,need to check. + // + // + // Check whether need to get the contents of HiiDataBase. + // Only after ReadyToBoot to do the export. + // + if (ExportAfterReadyToBoot) { + if (!EFI_ERROR (Status)) { + HiiGetDatabaseInfo(&Private->HiiDatabase); + } + } return Status; } @@ -1751,10 +1763,17 @@ HiiSetString ( ); if (EFI_ERROR (Status)) { return Status; } PackageListNode->PackageListHdr.PackageLength += StringPackage->StringPkgHdr->Header.Length - OldPackageLen; + // + // Check whether need to get the contents of HiiDataBase. + // Only after ReadyToBoot to do the export. + // + if (ExportAfterReadyToBoot) { + HiiGetDatabaseInfo(&Private->HiiDatabase); + } return EFI_SUCCESS; } } } -- 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel