From cb7d01c0c9fd199742d0fed6aa69dab0c79c3338 Mon Sep 17 00:00:00 2001 From: rsun3 Date: Tue, 14 Apr 2009 10:47:19 +0000 Subject: [PATCH] HII Library Class interface refine. The "HiiLib" prefix for all HII Library API function names changed to "Hii". Remove: HiiLibPreparePackageList(), replaced by HiiAddPackages() HiiLibNewString(), replaced by HiiSetString() HiiLibGetStringFromHandle(), replaced by HiiGetString() HiiLibGetStringFromToken(), replaced by HiiGetPackageString() HiiLibExtractGuidFromHiiHandle() HiiLibDevicePathToHiiHandle() HiiLibGetSupportedSecondaryLanguages() HiiLibGetSupportedLanguageNumber() HiiLibExportPackageLists() HiiLibListPackageLists() Interface change: HiiAddPackages() HiiSetString() HiiGetString() HiiGetHiiHandles() git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8083 6f19259b-4bc3-4df7-8a09-765794883524 --- DuetPkg/DataHubGenDxe/DataHubGen.c | 23 +- .../FrameworkHiiOnUefiHiiThunk/ConfigAccess.c | 12 +- .../FrameworkHiiOnUefiHiiThunk/HiiDatabase.c | 61 +- .../FrameworkHiiOnUefiHiiThunk/Package.c | 4 +- .../FrameworkHiiOnUefiHiiThunk/SetupBrowser.c | 20 +- .../FrameworkHiiOnUefiHiiThunk/Strings.c | 121 ++- .../FrameworkHiiOnUefiHiiThunk/Utility.c | 216 ++++- .../FrameworkHiiOnUefiHiiThunk/Utility.h | 94 +++ .../Universal/BdsDxe/BootMaint/BootMaint.c | 65 +- .../Universal/BdsDxe/BootMaint/UpdatePage.c | 8 +- .../Universal/BdsDxe/BootMaint/Variable.c | 8 +- .../Universal/BdsDxe/BootMngr/BootManager.c | 31 +- .../Universal/BdsDxe/BootMngr/BootManager.h | 4 +- .../BdsDxe/DeviceMngr/DeviceManager.c | 89 +-- .../BdsDxe/DeviceMngr/DeviceManager.h | 4 +- .../Universal/BdsDxe/FrontPage.c | 47 +- .../Universal/BdsDxe/Language.c | 15 +- .../Universal/BdsDxe/String.c | 38 +- .../Universal/BdsDxe/String.h | 4 +- .../Application/PlatOverMngr/PlatOverMngr.c | 105 +-- MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c | 16 +- MdeModulePkg/Include/Library/HiiLib.h | 496 ++++-------- MdeModulePkg/Library/UefiHiiLib/HiiLanguage.c | 178 ++--- MdeModulePkg/Library/UefiHiiLib/HiiLib.c | 735 +++++------------- MdeModulePkg/Library/UefiHiiLib/HiiString.c | 535 ++++++------- .../Library/UefiHiiLib/InternalHiiLib.h | 24 +- .../GraphicsConsoleDxe/GraphicsConsole.c | 14 +- .../Universal/DriverSampleDxe/DriverSample.c | 89 +-- .../Universal/DriverSampleDxe/DriverSample.h | 5 +- .../DriverSampleDxe/DriverSampleDxe.inf | 1 + .../Universal/Network/IScsiDxe/IScsiConfig.c | 28 +- .../Universal/SetupBrowserDxe/IfrParse.c | 8 +- .../Universal/SetupBrowserDxe/Setup.c | 50 +- .../Universal/SetupBrowserDxe/Setup.h | 1 + .../SetupBrowserDxe/SetupBrowserDxe.inf | 3 +- MdeModulePkg/Universal/SetupBrowserDxe/Ui.c | 98 ++- Nt32Pkg/CpuRuntimeDxe/Cpu.c | 9 +- .../MiscSubclassDriverEntryPoint.c | 12 +- UnixPkg/CpuRuntimeDxe/Cpu.c | 9 +- .../MiscSubclassDriverEntryPoint.c | 13 +- 40 files changed, 1547 insertions(+), 1746 deletions(-) diff --git a/DuetPkg/DataHubGenDxe/DataHubGen.c b/DuetPkg/DataHubGenDxe/DataHubGen.c index 6d6770444d..937425fb8f 100644 --- a/DuetPkg/DataHubGenDxe/DataHubGen.c +++ b/DuetPkg/DataHubGenDxe/DataHubGen.c @@ -104,9 +104,8 @@ InstallProcessorDataHub ( ASSERT (UString != NULL); AsciiStrToUnicodeStr (AString, UString); - Status = HiiLibNewString (gStringHandle, &Token, UString); - - if (EFI_ERROR (Status)) { + Token = HiiSetString (gStringHandle, 0, UString, NULL); + if (Token == 0) { gBS->FreePool (UString); return ; } @@ -232,9 +231,8 @@ InstallMiscDataHub ( CopyMem (UString, FIRMWARE_BIOS_VERSIONE, sizeof(FIRMWARE_BIOS_VERSIONE)); AsciiStrToUnicodeStr (AString, UString + sizeof(FIRMWARE_BIOS_VERSIONE) / sizeof(CHAR16) - 1); - Status = HiiLibNewString (gStringHandle, &Token, UString); - - if (EFI_ERROR (Status)) { + Token = HiiSetString (gStringHandle, 0, UString, NULL); + if (Token == 0) { gBS->FreePool (UString); return ; } @@ -281,9 +279,8 @@ InstallMiscDataHub ( CopyMem (UString, FIRMWARE_PRODUCT_NAME, sizeof(FIRMWARE_PRODUCT_NAME)); AsciiStrToUnicodeStr (AString, UString + sizeof(FIRMWARE_PRODUCT_NAME) / sizeof(CHAR16) - 1); - Status = HiiLibNewString (gStringHandle, &Token, UString); - - if (EFI_ERROR (Status)) { + Token = HiiSetString (gStringHandle, 0, UString, NULL); + if (Token == 0) { gBS->FreePool (UString); return ; } @@ -345,7 +342,13 @@ DataHubGenEntrypoint ( return Status; } - HiiLibAddPackages (1, &gEfiMiscProducerGuid, NULL, &gStringHandle, DataHubGenDxeStrings); + gStringHandle = HiiAddPackages ( + &gEfiMiscProducerGuid, + NULL, + DataHubGenDxeStrings, + NULL + ); + ASSERT (gStringHandle != NULL); InstallProcessorDataHub (Smbios); InstallCacheDataHub (Smbios); diff --git a/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/ConfigAccess.c b/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/ConfigAccess.c index 117d6ea636..ac6f2ac244 100644 --- a/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/ConfigAccess.c +++ b/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/ConfigAccess.c @@ -674,7 +674,6 @@ CreateIfrDataArray ( FORMSET_STORAGE *BufferStorage; EFI_STATUS Status; UINTN Size; - UINTN StringSize; EFI_STRING String; *NvMapAllocated = FALSE; @@ -691,17 +690,10 @@ CreateIfrDataArray ( break; case EFI_IFR_TYPE_STRING: - StringSize = 0; - Status = HiiLibGetString (ConfigAccess->ThunkContext->UefiHiiHandle, Value->string, String, &StringSize); - ASSERT (Status == EFI_BUFFER_TOO_SMALL); - - String = AllocateZeroPool (StringSize); + String = HiiGetString (ConfigAccess->ThunkContext->UefiHiiHandle, Value->string, NULL); ASSERT (String != NULL); - Status = HiiLibGetString (ConfigAccess->ThunkContext->UefiHiiHandle, Value->string, String, &StringSize); - ASSERT_EFI_ERROR (Status); - - Size = StringSize; + Size = StrSize (String); break; default: diff --git a/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/HiiDatabase.c b/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/HiiDatabase.c index 7882227faf..5a3df71aab 100644 --- a/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/HiiDatabase.c +++ b/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/HiiDatabase.c @@ -156,7 +156,7 @@ InitializeHiiDatabase ( ); ASSERT_EFI_ERROR (Status); - Status = HiiLibListPackageLists (EFI_HII_PACKAGE_STRINGS, NULL, &BufferLength, &Buffer); + Status = ListPackageLists (EFI_HII_PACKAGE_STRINGS, NULL, &BufferLength, &Buffer); if (Status == EFI_SUCCESS) { for (Index = 0; Index < BufferLength / sizeof (EFI_HII_HANDLE); Index++) { ThunkContext = CreateThunkContextForUefiHiiHandle (Buffer[Index]); @@ -403,7 +403,7 @@ HiiGetPrimaryLanguages ( return EFI_INVALID_PARAMETER; } - LangCodes3066 = HiiLibGetSupportedLanguages (UefiHiiHandle); + LangCodes3066 = HiiGetSupportedLanguages (UefiHiiHandle); if (LangCodes3066 == NULL) { return EFI_INVALID_PARAMETER; @@ -437,6 +437,61 @@ Done: return Status; } +/** + This function returns the list of supported 2nd languages, in the format specified + in UEFI specification Appendix M. + + If HiiHandle is not a valid Handle in the HII database, then ASSERT. + If not enough resource to complete the operation, then ASSERT. + + @param HiiHandle The HII package list handle. + @param FirstLanguage Pointer to language name buffer. + + @return The supported languages. + +**/ +CHAR8 * +EFIAPI +HiiGetSupportedSecondaryLanguages ( + IN EFI_HII_HANDLE HiiHandle, + IN CONST CHAR8 *FirstLanguage + ) +{ + EFI_STATUS Status; + UINTN BufferSize; + CHAR8 *LanguageString; + + ASSERT (HiiHandle != NULL); + + // + // Collect current supported 2nd Languages for given HII handle + // First try allocate 4K buffer to store the current supported 2nd languages. + // + BufferSize = 0x1000; + LanguageString = AllocateZeroPool (BufferSize); + if (LanguageString == NULL) { + return NULL; + } + + Status = mHiiStringProtocol->GetSecondaryLanguages (mHiiStringProtocol, HiiHandle, FirstLanguage, LanguageString, &BufferSize); + ASSERT (Status != EFI_NOT_FOUND); + + if (Status == EFI_BUFFER_TOO_SMALL) { + FreePool (LanguageString); + LanguageString = AllocateZeroPool (BufferSize); + if (LanguageString == NULL) { + return NULL; + } + + Status = mHiiStringProtocol->GetSecondaryLanguages (mHiiStringProtocol, HiiHandle, FirstLanguage, LanguageString, &BufferSize); + } + + if (EFI_ERROR (Status)) { + LanguageString = NULL; + } + + return LanguageString; +} /** Allows a program to determine which secondary languages are supported on a given handle for a given primary language @@ -499,7 +554,7 @@ HiiGetSecondaryLanguages ( PrimaryLang3066 = ConvertIso639LanguageToRfc3066Language (PrimaryLang639); ASSERT_EFI_ERROR (PrimaryLang3066 != NULL); - SecLangCodes3066 = HiiLibGetSupportedSecondaryLanguages (UefiHiiHandle, PrimaryLang3066); + SecLangCodes3066 = HiiGetSupportedSecondaryLanguages (UefiHiiHandle, PrimaryLang3066); if (SecLangCodes3066 == NULL) { Status = EFI_INVALID_PARAMETER; diff --git a/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Package.c b/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Package.c index 3187a94160..5b326721ba 100644 --- a/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Package.c +++ b/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Package.c @@ -401,7 +401,7 @@ FindStringPackAndUpdatePackListWithOnlyIfrPack ( if (ThunkContext != IfrThunkContext) { if (CompareGuid (&IfrThunkContext->TagGuid, &ThunkContext->TagGuid) && (ThunkContext->IfrPackageCount == 0)) { - Status = HiiLibExportPackageLists (ThunkContext->UefiHiiHandle, &StringPackageListHeader, &Size); + Status = ExportPackageLists (ThunkContext->UefiHiiHandle, &StringPackageListHeader, &Size); ASSERT_EFI_ERROR (Status); IfrThunkContext->StringPackageCount = GetPackageCountByType (StringPackageListHeader, EFI_HII_PACKAGE_STRINGS); @@ -861,7 +861,7 @@ RemovePackNotify ( // if (ThunkContext != NULL) { if (!ThunkContext->ByFrameworkHiiNewPack) { - Status = HiiLibExportPackageLists (Handle, &HiiPackageList, &BufferSize); + Status = ExportPackageLists (Handle, &HiiPackageList, &BufferSize); ASSERT_EFI_ERROR (Status); if (GetPackageCountByType (HiiPackageList, EFI_HII_PACKAGE_STRINGS) == 1) { diff --git a/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/SetupBrowser.c b/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/SetupBrowser.c index 7c4b27f077..807e8396d0 100644 --- a/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/SetupBrowser.c +++ b/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/SetupBrowser.c @@ -40,13 +40,9 @@ GetStringById ( IN EFI_STRING_ID Id ) { - CHAR16 *String; - - String = NULL; - HiiLibGetStringFromHandle (gStringPackHandle, Id, &String); - - return String; + return HiiGetString (gStringPackHandle, Id, NULL); } + /** Show progress bar with title above it. It only works in Graphics mode. @@ -544,12 +540,14 @@ InitSetBrowserStrings ( VOID ) { - EFI_STATUS Status; - // // Initialize strings to HII database // - Status = HiiLibAddPackages (1, &gEfiHiiThunkProducerGuid, NULL, &gStringPackHandle, STRING_ARRAY_NAME); - ASSERT_EFI_ERROR (Status); - + gStringPackHandle = HiiAddPackages ( + &gEfiHiiThunkProducerGuid, + NULL, + STRING_ARRAY_NAME, + NULL + ); + ASSERT (gStringPackHandle != NULL); } diff --git a/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Strings.c b/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Strings.c index d9cc39eb8d..05a885cc8f 100644 --- a/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Strings.c +++ b/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Strings.c @@ -65,7 +65,7 @@ ConvertIso639ToRfc3066 ( If all glyphs in the string are available, the index is the index of the terminator of the string. @param GlyphBufferSize A pointer to a value. On output, if the function returns EFI_SUCCESS, - it contains the amount of memory that is required to store the string¡¯s glyph equivalent. + it contains the amount of memory that is required to store the string? glyph equivalent. @retval EFI_UNSUPPORTED The function performs nothing and return EFI_UNSUPPORTED. **/ @@ -148,73 +148,17 @@ UpdateString ( ) { EFI_STRING_ID NewStringId; - EFI_STATUS Status; - - NewStringId = 0; - - if (*StringId == 0) { - // - // Create a new string token. - // - if (Rfc3066AsciiLanguage == NULL) { - // - // For all languages in the package list. - // - Status = HiiLibNewString (ThunkContext->UefiHiiHandle, &NewStringId, NewString); - } else { - // - // For specified language. - // - Status = mHiiStringProtocol->NewString ( - mHiiStringProtocol, - ThunkContext->UefiHiiHandle, - &NewStringId, - Rfc3066AsciiLanguage, - NULL, - NewString, - NULL - ); - } - } else { - // - // Update the existing string token. - // - if (Rfc3066AsciiLanguage == NULL) { - // - // For all languages in the package list. - // - Status = HiiLibSetString (ThunkContext->UefiHiiHandle, *StringId, NewString); - } else { - // - // For specified language. - // - Status = mHiiStringProtocol->SetString ( - mHiiStringProtocol, - ThunkContext->UefiHiiHandle, - *StringId, - Rfc3066AsciiLanguage, - NewString, - NULL - ); - } - } - - if (!EFI_ERROR (Status)) { - if (*StringId == 0) { - // - // When creating new string, return the newly created String Token. - // - *StringId = NewStringId; - } - } else { + NewStringId = HiiSetString (ThunkContext->UefiHiiHandle, *StringId, NewString, Rfc3066AsciiLanguage); + *StringId = NewStringId; + if (NewStringId == 0) { // // Only EFI_INVALID_PARAMETER is defined in HII 0.92 specification. // - *StringId = 0; + return EFI_INVALID_PARAMETER; + } else { + return EFI_SUCCESS; } - - return Status; } /** @@ -388,9 +332,12 @@ HiiThunkGetString ( OUT EFI_STRING StringBuffer ) { - CHAR8 *Iso639AsciiLanguage; HII_THUNK_PRIVATE_DATA *Private; + CHAR8 *Iso639AsciiLanguage; CHAR8 *Rfc3066AsciiLanguage; + CHAR8 *SupportedLanguages; + CHAR8 *PlatformLanguage; + CHAR8 *BestLanguage; EFI_HII_HANDLE UefiHiiHandle; EFI_STATUS Status; @@ -427,7 +374,51 @@ HiiThunkGetString ( } if (Rfc3066AsciiLanguage == NULL) { - Status = HiiLibGetString (UefiHiiHandle, Token, StringBuffer, BufferLengthTemp); + // + // Get the languages that the package specified by HiiHandle supports + // + SupportedLanguages = HiiGetSupportedLanguages (UefiHiiHandle); + if (SupportedLanguages == NULL) { + goto Error2; + } + + // + // Get the current platform language setting + // + PlatformLanguage = GetEfiGlobalVariable (L"PlatformLang"); + if (PlatformLanguage == NULL) { + goto Error1; + } + + // + // Get the best matching language from SupportedLanguages + // + BestLanguage = GetBestLanguage ( + SupportedLanguages, + FALSE, // RFC 4646 mode + PlatformLanguage, // Next highest priority + SupportedLanguages, // Lowest priority + NULL + ); + if (BestLanguage == NULL) { + FreePool (PlatformLanguage); +Error1: + FreePool (SupportedLanguages); +Error2: + Status = EFI_INVALID_PARAMETER; + goto Done; + } + + Status = mHiiStringProtocol->GetString ( + mHiiStringProtocol, + BestLanguage, + UefiHiiHandle, + Token, + StringBuffer, + BufferLengthTemp, + NULL + ); + FreePool (BestLanguage); } else { Status = mHiiStringProtocol->GetString ( mHiiStringProtocol, diff --git a/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Utility.c b/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Utility.c index 0ad0668f72..e74830de56 100644 --- a/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Utility.c +++ b/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Utility.c @@ -21,6 +21,220 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. CONST EFI_GUID gZeroGuid = {0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}}; CONST CHAR16 FrameworkReservedVarstoreName[] = FRAMEWORK_RESERVED_VARSTORE_NAME; +/** + + This function returns a list of the package handles of the + specified type that are currently active in the HII database. The + pseudo-type EFI_HII_PACKAGE_TYPE_ALL will cause all package + handles to be listed. + + If HandleBufferLength is NULL, then ASSERT. + If HandleBuffer is NULL, the ASSERT. + If PackageType is EFI_HII_PACKAGE_TYPE_GUID and PackageGuid is + NULL, then ASSERT. + If PackageType is not EFI_HII_PACKAGE_TYPE_GUID and PackageGuid is not + NULL, then ASSERT. + + + @param PackageType Specifies the package type of the packages + to list or EFI_HII_PACKAGE_TYPE_ALL for + all packages to be listed. + + @param PackageGuid If PackageType is + EFI_HII_PACKAGE_TYPE_GUID, then this is + the pointer to the GUID which must match + the Guid field of + EFI_HII_PACKAGE_GUID_HEADER. Otherwise, it + must be NULL. + + @param HandleBufferLength On output, the length of the handle buffer + that is required for the handles found. + + @param HandleBuffer On output, an array of EFI_HII_HANDLE instances returned. + The caller is responcible to free this pointer allocated. + + @retval EFI_SUCCESS The matching handles are outputed successfully. + HandleBufferLength is updated with the actual length. + @retval EFI_OUT_OF_RESOURCES Not enough resource to complete the operation. + @retval EFI_NOT_FOUND No matching handle could not be found in database. +**/ +EFI_STATUS +EFIAPI +ListPackageLists ( + IN UINT8 PackageType, + IN CONST EFI_GUID *PackageGuid, + IN OUT UINTN *HandleBufferLength, + OUT EFI_HII_HANDLE **HandleBuffer + ) +{ + EFI_STATUS Status; + + ASSERT (HandleBufferLength != NULL); + ASSERT (HandleBuffer != NULL); + + *HandleBufferLength = 0; + *HandleBuffer = NULL; + + if (PackageType == EFI_HII_PACKAGE_TYPE_GUID) { + ASSERT (PackageGuid != NULL); + } else { + ASSERT (PackageGuid == NULL); + } + + Status = mHiiDatabase->ListPackageLists ( + mHiiDatabase, + PackageType, + PackageGuid, + HandleBufferLength, + *HandleBuffer + ); + if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) { + // + // No packages is registered to UEFI HII Database, just return. + // + // + return Status; + } + + *HandleBuffer = AllocateZeroPool (*HandleBufferLength); + + if (*HandleBuffer == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + return mHiiDatabase->ListPackageLists ( + mHiiDatabase, + PackageType, + PackageGuid, + HandleBufferLength, + *HandleBuffer + ); + +} + +/** + Exports the contents of one or all package lists in the HII database into a buffer. + + If Handle is not NULL and not a valid EFI_HII_HANDLE registered in the database, + then ASSERT. + If PackageListHeader is NULL, then ASSERT. + If PackageListSize is NULL, then ASSERT. + + @param Handle The HII Handle. + @param PackageListHeader A pointer to a buffer that will contain the results of + the export function. + @param PackageListSize On output, the length of the buffer that is required for the exported data. + + @retval EFI_SUCCESS Package exported. + + @retval EFI_OUT_OF_RESOURCES Not enought memory to complete the operations. + +**/ +EFI_STATUS +EFIAPI +ExportPackageLists ( + IN EFI_HII_HANDLE Handle, + OUT EFI_HII_PACKAGE_LIST_HEADER **PackageListHeader, + OUT UINTN *PackageListSize + ) +{ + EFI_STATUS Status; + UINTN Size; + EFI_HII_PACKAGE_LIST_HEADER *PackageListHdr; + + ASSERT (PackageListSize != NULL); + ASSERT (PackageListHeader != NULL); + + Size = 0; + PackageListHdr = NULL; + Status = mHiiDatabase->ExportPackageLists ( + mHiiDatabase, + Handle, + &Size, + PackageListHdr + ); + ASSERT_EFI_ERROR (Status != EFI_BUFFER_TOO_SMALL); + + if (Status == EFI_BUFFER_TOO_SMALL) { + PackageListHdr = AllocateZeroPool (Size); + + if (PackageListHeader == NULL) { + return EFI_OUT_OF_RESOURCES; + } else { + Status = mHiiDatabase->ExportPackageLists ( + mHiiDatabase, + Handle, + &Size, + PackageListHdr + ); + } + } + + if (!EFI_ERROR (Status)) { + *PackageListHeader = PackageListHdr; + *PackageListSize = Size; + } else { + FreePool (PackageListHdr); + } + + return Status; +} + +/** + Extract Hii package list GUID for given HII handle. + + If HiiHandle could not be found in the HII database, then ASSERT. + If Guid is NULL, then ASSERT. + + @param Handle Hii handle + @param Guid Package list GUID + + @retval EFI_SUCCESS Successfully extract GUID from Hii database. + +**/ +EFI_STATUS +EFIAPI +ExtractGuidFromHiiHandle ( + IN EFI_HII_HANDLE Handle, + OUT EFI_GUID *Guid + ) +{ + EFI_STATUS Status; + UINTN BufferSize; + EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList; + + ASSERT (Guid != NULL); + ASSERT (Handle != NULL); + + // + // Get HII PackageList + // + BufferSize = 0; + HiiPackageList = NULL; + + Status = mHiiDatabase->ExportPackageLists (mHiiDatabase, Handle, &BufferSize, HiiPackageList); + ASSERT (Status != EFI_NOT_FOUND); + + if (Status == EFI_BUFFER_TOO_SMALL) { + HiiPackageList = AllocatePool (BufferSize); + ASSERT (HiiPackageList != NULL); + + Status = mHiiDatabase->ExportPackageLists (mHiiDatabase, Handle, &BufferSize, HiiPackageList); + } + if (EFI_ERROR (Status)) { + FreePool (HiiPackageList); + return Status; + } + + // + // Extract GUID + // + CopyGuid (Guid, &HiiPackageList->PackageListGuid); + + FreePool (HiiPackageList); + + return EFI_SUCCESS; +} /** Find the corressponding UEFI HII Handle from a Framework HII Handle given. @@ -202,7 +416,7 @@ CreateThunkContextForUefiHiiHandle ( ThunkContext->UefiHiiHandle = UefiHiiHandle; - Status = HiiLibExtractGuidFromHiiHandle (UefiHiiHandle, &PackageGuid); + Status = ExtractGuidFromHiiHandle (UefiHiiHandle, &PackageGuid); ASSERT_EFI_ERROR (Status); CopyGuid(&ThunkContext->TagGuid, &PackageGuid); diff --git a/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Utility.h b/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Utility.h index 99642fd5b9..087eafaaa8 100644 --- a/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Utility.h +++ b/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Utility.h @@ -16,6 +16,100 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #ifndef _HII_THUNK_UTILITY_H #define _HII_THUNK_UTILITY_H +/** + + This function returns a list of the package handles of the + specified type that are currently active in the HII database. The + pseudo-type EFI_HII_PACKAGE_TYPE_ALL will cause all package + handles to be listed. + + If HandleBufferLength is NULL, then ASSERT. + If HandleBuffer is NULL, the ASSERT. + If PackageType is EFI_HII_PACKAGE_TYPE_GUID and PackageGuid is + NULL, then ASSERT. + If PackageType is not EFI_HII_PACKAGE_TYPE_GUID and PackageGuid is not + NULL, then ASSERT. + + + @param PackageType Specifies the package type of the packages + to list or EFI_HII_PACKAGE_TYPE_ALL for + all packages to be listed. + + @param PackageGuid If PackageType is + EFI_HII_PACKAGE_TYPE_GUID, then this is + the pointer to the GUID which must match + the Guid field of + EFI_HII_PACKAGE_GUID_HEADER. Otherwise, it + must be NULL. + + @param HandleBufferLength On output, the length of the handle buffer + that is required for the handles found. + + @param HandleBuffer On output, an array of EFI_HII_HANDLE instances returned. + The caller is responcible to free this pointer allocated. + + @retval EFI_SUCCESS The matching handles are outputed successfully. + HandleBufferLength is updated with the actual length. + @retval EFI_OUT_OF_RESOURCES Not enough resource to complete the operation. + @retval EFI_NOT_FOUND No matching handle could not be found in database. +**/ +EFI_STATUS +EFIAPI +ListPackageLists ( + IN UINT8 PackageType, + IN CONST EFI_GUID *PackageGuid, + IN OUT UINTN *HandleBufferLength, + OUT EFI_HII_HANDLE **HandleBuffer + ) +; + +/** + Exports the contents of one or all package lists in the HII database into a buffer. + + If Handle is not NULL and not a valid EFI_HII_HANDLE registered in the database, + then ASSERT. + If PackageListHeader is NULL, then ASSERT. + If PackageListSize is NULL, then ASSERT. + + @param Handle The HII Handle. + @param PackageListHeader A pointer to a buffer that will contain the results of + the export function. + @param PackageListSize On output, the length of the buffer that is required for the exported data. + + @retval EFI_SUCCESS Package exported. + + @retval EFI_OUT_OF_RESOURCES Not enought memory to complete the operations. + +**/ +EFI_STATUS +EFIAPI +ExportPackageLists ( + IN EFI_HII_HANDLE Handle, + OUT EFI_HII_PACKAGE_LIST_HEADER **PackageListHeader, + OUT UINTN *PackageListSize + ) +; + +/** + Extract Hii package list GUID for given HII handle. + + If HiiHandle could not be found in the HII database, then ASSERT. + If Guid is NULL, then ASSERT. + + @param Handle Hii handle + @param Guid Package list GUID + + @retval EFI_SUCCESS Successfully extract GUID from Hii database. + +**/ +EFI_STATUS +EFIAPI +ExtractGuidFromHiiHandle ( + IN EFI_HII_HANDLE Handle, + OUT EFI_GUID *Guid + ) +; + /** Find the UefiHiiHandle based on a Framework HII Handle returned by the HII Thunk to Framework HII code. diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BootMaint.c b/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BootMaint.c index 3f5bbc40c2..57dd2db9c5 100644 --- a/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BootMaint.c +++ b/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BootMaint.c @@ -128,20 +128,22 @@ CreateMenuStringToken ( for (Index = 0; Index < MenuOption->MenuNumber; Index++) { NewMenuEntry = BOpt_GetMenuEntry (MenuOption, Index); - HiiLibNewString ( - HiiHandle, - &NewMenuEntry->DisplayStringToken, - NewMenuEntry->DisplayString - ); + NewMenuEntry->DisplayStringToken = HiiSetString ( + HiiHandle, + 0, + NewMenuEntry->DisplayString, + NULL + ); if (NULL == NewMenuEntry->HelpString) { NewMenuEntry->HelpStringToken = NewMenuEntry->DisplayStringToken; } else { - HiiLibNewString ( - HiiHandle, - &NewMenuEntry->HelpStringToken, - NewMenuEntry->HelpString - ); + NewMenuEntry->HelpStringToken = HiiSetString ( + HiiHandle, + 0, + NewMenuEntry->HelpString, + NULL + ); } } @@ -848,7 +850,6 @@ InitializeBM ( ) { EFI_LEGACY_BIOS_PROTOCOL *LegacyBios; - EFI_HII_PACKAGE_LIST_HEADER *PackageList; BMM_CALLBACK_DATA *BmmCallbackInfo; EFI_STATUS Status; UINT8 *Ptr; @@ -931,30 +932,26 @@ InitializeBM ( // // Post our Boot Maint VFR binnary to the HII database. // - PackageList = HiiLibPreparePackageList (2, &mBootMaintGuid, BmBin, BdsDxeStrings); - ASSERT (PackageList != NULL); - - Status = gHiiDatabase->NewPackageList ( - gHiiDatabase, - PackageList, - BmmCallbackInfo->BmmDriverHandle, - &BmmCallbackInfo->BmmHiiHandle - ); - FreePool (PackageList); + BmmCallbackInfo->BmmHiiHandle = HiiAddPackages ( + &mBootMaintGuid, + BmmCallbackInfo->BmmDriverHandle, + BmBin, + BdsDxeStrings, + NULL + ); + ASSERT (BmmCallbackInfo->BmmHiiHandle != NULL); // // Post our File Explorer VFR binary to the HII database. // - PackageList = HiiLibPreparePackageList (2, &mFileExplorerGuid, FEBin, BdsDxeStrings); - ASSERT (PackageList != NULL); - - Status = gHiiDatabase->NewPackageList ( - gHiiDatabase, - PackageList, - BmmCallbackInfo->FeDriverHandle, - &BmmCallbackInfo->FeHiiHandle - ); - FreePool (PackageList); + BmmCallbackInfo->FeHiiHandle = HiiAddPackages ( + &mFileExplorerGuid, + BmmCallbackInfo->FeDriverHandle, + FEBin, + BdsDxeStrings, + NULL + ); + ASSERT (BmmCallbackInfo->FeHiiHandle != NULL); // // Allocate space for creation of Buffer @@ -1057,8 +1054,8 @@ InitializeBM ( // // Remove our IFR data from HII database // - gHiiDatabase->RemovePackageList (gHiiDatabase, BmmCallbackInfo->BmmHiiHandle); - gHiiDatabase->RemovePackageList (gHiiDatabase, BmmCallbackInfo->FeHiiHandle); + HiiRemovePackages (BmmCallbackInfo->BmmHiiHandle); + HiiRemovePackages (BmmCallbackInfo->FeHiiHandle); CleanUpStringDepository (); @@ -1192,7 +1189,7 @@ GetStringTokenFromDepository ( // NextListNode = AllocateZeroPool (sizeof (STRING_LIST_NODE)); ASSERT (NextListNode != NULL); - HiiLibNewString (CallbackData->BmmHiiHandle, &(NextListNode->StringToken), L" "); + NextListNode->StringToken = HiiSetString (CallbackData->BmmHiiHandle, 0, L" ", NULL); ASSERT (NextListNode->StringToken != 0); StringDepository->TotalNodeNumber++; diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/UpdatePage.c b/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/UpdatePage.c index 6831289add..3d23da1ac3 100644 --- a/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/UpdatePage.c +++ b/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/UpdatePage.c @@ -752,7 +752,7 @@ UpdateConModePage ( ASSERT ((StrLen (ModeString) + TempStringLen) < (sizeof (ModeString) / sizeof (ModeString[0]))); StrCat (ModeString, RowString); - HiiLibNewString (CallbackData->BmmHiiHandle, &ModeToken[Index], ModeString); + ModeToken[Index] = HiiSetString (CallbackData->BmmHiiHandle, 0, ModeString, NULL); IfrOptionList[Index].StringToken = ModeToken[Index]; IfrOptionList[Index].Value.u16 = (UINT16) Mode; @@ -1246,12 +1246,10 @@ UpdateSetLegacyDeviceOrderPage ( // Create the string for oneof tag // UnicodeSPrint (String, sizeof (String), TypeStr, Index); - StrRef = 0; - HiiLibNewString (CallbackData->BmmHiiHandle, &StrRef, String); + StrRef = HiiSetString (CallbackData->BmmHiiHandle, 0, String, NULL); UnicodeSPrint (String, sizeof (String), TypeStrHelp, Index); - StrRefHelp = 0; - HiiLibNewString (CallbackData->BmmHiiHandle, &StrRefHelp, String); + StrRefHelp = HiiSetString (CallbackData->BmmHiiHandle, 0, String, NULL); CreateOneOfOpCode ( (EFI_QUESTION_ID) (Key + Index), diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/Variable.c b/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/Variable.c index 489827f9de..6bdcee41d5 100644 --- a/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/Variable.c +++ b/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/Variable.c @@ -642,13 +642,13 @@ Var_UpdateDriverOption ( CallbackData, DriverOptionStrDepository ); - HiiLibNewString (HiiHandle, &NewMenuEntry->DisplayStringToken, NewMenuEntry->DisplayString); + NewMenuEntry->DisplayStringToken = HiiSetString (HiiHandle, 0, NewMenuEntry->DisplayString, NULL); NewMenuEntry->HelpStringToken = GetStringTokenFromDepository ( CallbackData, DriverOptionHelpStrDepository ); - HiiLibNewString (HiiHandle, &NewMenuEntry->HelpStringToken, NewMenuEntry->HelpString); + NewMenuEntry->HelpStringToken = HiiSetString (HiiHandle, 0, NewMenuEntry->HelpString, NULL); if (OptionalDataExist) { Ptr += (UINT8) GetDevicePathSize (CallbackData->LoadContext->FilePathList); @@ -814,13 +814,13 @@ Var_UpdateBootOption ( CallbackData, BootOptionStrDepository ); - HiiLibNewString (CallbackData->FeHiiHandle, &NewMenuEntry->DisplayStringToken, NewMenuEntry->DisplayString); + NewMenuEntry->DisplayStringToken = HiiSetString (CallbackData->FeHiiHandle, 0, NewMenuEntry->DisplayString, NULL); NewMenuEntry->HelpStringToken = GetStringTokenFromDepository ( CallbackData, BootOptionHelpStrDepository ); - HiiLibNewString (CallbackData->FeHiiHandle, &NewMenuEntry->HelpStringToken, NewMenuEntry->HelpString); + NewMenuEntry->HelpStringToken = HiiSetString (CallbackData->FeHiiHandle, 0, NewMenuEntry->HelpString, NULL); if (OptionalDataExist) { Ptr += (UINT8) GetDevicePathSize (CallbackData->LoadContext->FilePathList); diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/BootMngr/BootManager.c b/IntelFrameworkModulePkg/Universal/BdsDxe/BootMngr/BootManager.c index 615c189d8d..4918b25b13 100644 --- a/IntelFrameworkModulePkg/Universal/BdsDxe/BootMngr/BootManager.c +++ b/IntelFrameworkModulePkg/Universal/BdsDxe/BootMngr/BootManager.c @@ -129,7 +129,8 @@ BootManagerCallback ( Registers HII packages for the Boot Manger to HII Database. It also registers the browser call back function. - @return Status of gBS->InstallMultipleProtocolInterfaces() and gHiiDatabase->NewPackageList() + @retval EFI_SUCCESS HII packages for the Boot Manager were registered successfully. + @retval EFI_OUT_OF_RESOURCES HII packages for the Boot Manager failed to be registered. **/ EFI_STATUS @@ -138,7 +139,6 @@ InitializeBootManager ( ) { EFI_STATUS Status; - EFI_HII_PACKAGE_LIST_HEADER *PackageList; // // Install Device Path Protocol and Config Access protocol to driver handle @@ -156,17 +156,18 @@ InitializeBootManager ( // // Publish our HII data // - PackageList = HiiLibPreparePackageList (2, &mBootManagerGuid, BootManagerVfrBin, BdsDxeStrings); - ASSERT (PackageList != NULL); - - Status = gHiiDatabase->NewPackageList ( - gHiiDatabase, - PackageList, - gBootManagerPrivate.DriverHandle, - &gBootManagerPrivate.HiiHandle - ); - FreePool (PackageList); - + gBootManagerPrivate.HiiHandle = HiiAddPackages ( + &mBootManagerGuid, + gBootManagerPrivate.DriverHandle, + BootManagerVfrBin, + BdsDxeStrings, + NULL + ); + if (gBootManagerPrivate.HiiHandle == NULL) { + Status = EFI_OUT_OF_RESOURCES; + } else { + Status = EFI_SUCCESS; + } return Status; } @@ -244,7 +245,7 @@ CallBootManager ( continue; } - HiiLibNewString (HiiHandle, &Token, Option->Description); + Token = HiiSetString (HiiHandle, 0, Option->Description, NULL); TempStr = DevicePathToStr (Option->DevicePath); TempSize = StrSize (TempStr); @@ -253,7 +254,7 @@ CallBootManager ( StrCat (HelpString, L"Device Path : "); StrCat (HelpString, TempStr); - HiiLibNewString (HiiHandle, &HelpToken, HelpString); + HelpToken = HiiSetString (HiiHandle, 0, HelpString, NULL); CreateActionOpCode ( mKeyInput, diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/BootMngr/BootManager.h b/IntelFrameworkModulePkg/Universal/BdsDxe/BootMngr/BootManager.h index d7566f4ccf..90b7b2850d 100644 --- a/IntelFrameworkModulePkg/Universal/BdsDxe/BootMngr/BootManager.h +++ b/IntelFrameworkModulePkg/Universal/BdsDxe/BootMngr/BootManager.h @@ -86,7 +86,9 @@ BootManagerCallback ( Registers HII packages for the Boot Manger to HII Database. It also registers the browser call back function. - @return Status of gBS->InstallMultipleProtocolInterfaces() and gHiiDatabase->NewPackageList() + @retval EFI_SUCCESS HII packages for the Boot Manager were registered successfully. + @retval EFI_OUT_OF_RESOURCES HII packages for the Boot Manager failed to be registered. + **/ EFI_STATUS InitializeBootManager ( diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c b/IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c index 9264734ddc..920a050630 100644 --- a/IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c +++ b/IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.c @@ -112,8 +112,8 @@ DeviceManagerCallback ( This function registers HII packages to HII database. - @retval EFI_SUCCESS This function complete successfully. - @return Other value if failed to register HII packages. + @retval EFI_SUCCESS HII packages for the Device Manager were registered successfully. + @retval EFI_OUT_OF_RESOURCES HII packages for the Device Manager failed to be registered. **/ EFI_STATUS @@ -122,7 +122,6 @@ InitializeDeviceManager ( ) { EFI_STATUS Status; - EFI_HII_PACKAGE_LIST_HEADER *PackageList; // // Install Device Path Protocol and Config Access protocol to driver handle @@ -140,17 +139,18 @@ InitializeDeviceManager ( // // Publish our HII data // - PackageList = HiiLibPreparePackageList (2, &mDeviceManagerGuid, DeviceManagerVfrBin, BdsDxeStrings); - ASSERT (PackageList != NULL); - - Status = gHiiDatabase->NewPackageList ( - gHiiDatabase, - PackageList, - gDeviceManagerPrivate.DriverHandle, - &gDeviceManagerPrivate.HiiHandle - ); - FreePool (PackageList); - + gDeviceManagerPrivate.HiiHandle = HiiAddPackages ( + &mDeviceManagerGuid, + gDeviceManagerPrivate.DriverHandle, + DeviceManagerVfrBin, + BdsDxeStrings, + NULL + ); + if (gDeviceManagerPrivate.HiiHandle == NULL) { + Status = EFI_OUT_OF_RESOURCES; + } else { + Status = EFI_SUCCESS; + } return Status; } @@ -174,23 +174,18 @@ CallDeviceManager ( EFI_STATUS Status; UINTN Count; UINTN Index; - CHAR16 *String; - UINTN StringLength; + EFI_STRING String; EFI_HII_UPDATE_DATA UpdateData[MENU_ITEM_NUM]; EFI_STRING_ID Token; EFI_STRING_ID TokenHelp; EFI_HII_HANDLE *HiiHandles; - UINTN HandleBufferLength; - UINTN NumberOfHiiHandles; EFI_HII_HANDLE HiiHandle; UINT16 FormSetClass; EFI_STRING_ID FormSetTitle; EFI_STRING_ID FormSetHelp; EFI_BROWSER_ACTION_REQUEST ActionRequest; - EFI_HII_PACKAGE_LIST_HEADER *PackageList; HiiHandles = NULL; - HandleBufferLength = 0; Status = EFI_SUCCESS; gCallbackKey = 0; @@ -221,37 +216,30 @@ CallDeviceManager ( // // Get all the Hii handles // - Status = HiiLibGetHiiHandles (&HandleBufferLength, &HiiHandles); - ASSERT_EFI_ERROR (Status && (HiiHandles != NULL)); + HiiHandles = HiiGetHiiHandles (NULL); + ASSERT (HiiHandles != NULL); HiiHandle = gDeviceManagerPrivate.HiiHandle; - StringLength = 0x1000; - String = AllocateZeroPool (StringLength); - ASSERT (String != NULL); - // // Search for formset of each class type // - NumberOfHiiHandles = HandleBufferLength / sizeof (EFI_HII_HANDLE); - for (Index = 0; Index < NumberOfHiiHandles; Index++) { + for (Index = 0; HiiHandles[Index] != NULL; Index++) { IfrLibExtractClassFromHiiHandle (HiiHandles[Index], &FormSetClass, &FormSetTitle, &FormSetHelp); if (FormSetClass == EFI_NON_DEVICE_CLASS) { continue; } - Token = 0; - *String = 0; - StringLength = 0x1000; - HiiLibGetString (HiiHandles[Index], FormSetTitle, String, &StringLength); - HiiLibNewString (HiiHandle, &Token, String); + String = HiiGetString (HiiHandles[Index], FormSetTitle, NULL); + ASSERT (String != NULL); + Token = HiiSetString (HiiHandle, 0, String, NULL); + FreePool (String); - TokenHelp = 0; - *String = 0; - StringLength = 0x1000; - HiiLibGetString (HiiHandles[Index], FormSetHelp, String, &StringLength); - HiiLibNewString (HiiHandle, &TokenHelp, String); + String = HiiGetString (HiiHandles[Index], FormSetHelp, NULL); + ASSERT (String != NULL); + TokenHelp = HiiSetString (HiiHandle, 0, String, NULL); + FreePool (String); for (Count = 0; Count < MENU_ITEM_NUM; Count++) { if (FormSetClass & mDeviceManagerMenuItemTable[Count].Class) { @@ -266,7 +254,6 @@ CallDeviceManager ( } } } - FreePool (String); for (Index = 0; Index < MENU_ITEM_NUM; Index++) { // @@ -327,16 +314,20 @@ CallDeviceManager ( // // Cleanup dynamic created strings in HII database by reinstall the packagelist // - gHiiDatabase->RemovePackageList (gHiiDatabase, HiiHandle); - PackageList = HiiLibPreparePackageList (2, &mDeviceManagerGuid, DeviceManagerVfrBin, BdsDxeStrings); - ASSERT (PackageList != NULL); - Status = gHiiDatabase->NewPackageList ( - gHiiDatabase, - PackageList, - gDeviceManagerPrivate.DriverHandle, - &gDeviceManagerPrivate.HiiHandle - ); - FreePool (PackageList); + HiiRemovePackages (HiiHandle); + + gDeviceManagerPrivate.HiiHandle = HiiAddPackages ( + &mDeviceManagerGuid, + gDeviceManagerPrivate.DriverHandle, + DeviceManagerVfrBin, + BdsDxeStrings, + NULL + ); + if (gDeviceManagerPrivate.HiiHandle == NULL) { + Status = EFI_OUT_OF_RESOURCES; + } else { + Status = EFI_SUCCESS; + } for (Index = 0; Index < MENU_ITEM_NUM; Index++) { FreePool (UpdateData[Index].Data); diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.h b/IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.h index 23809dd924..ef39ca142e 100644 --- a/IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.h +++ b/IntelFrameworkModulePkg/Universal/BdsDxe/DeviceMngr/DeviceManager.h @@ -104,8 +104,8 @@ DeviceManagerCallback ( This function registers HII packages to HII database. - @retval EFI_SUCCESS This function complete successfully. - @return Other value if failed to register HII packages. + @retval EFI_SUCCESS HII packages for the Device Manager were registered successfully. + @retval EFI_OUT_OF_RESOURCES HII packages for the Device Manager failed to be registered. **/ EFI_STATUS diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c b/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c index fbfac08178..bda75e15ca 100644 --- a/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c +++ b/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c @@ -183,7 +183,7 @@ FrontPageCallback ( // // Collect the languages from what our current Language support is based on our VFR // - LanguageString = HiiLibGetSupportedLanguages (gFrontPagePrivate.HiiHandle); + LanguageString = HiiGetSupportedLanguages (gFrontPagePrivate.HiiHandle); ASSERT (LanguageString != NULL); // // Allocate working buffer for RFC 4646 language in supported LanguageString. @@ -297,7 +297,6 @@ InitializeFrontPage ( ) { EFI_STATUS Status; - EFI_HII_PACKAGE_LIST_HEADER *PackageList; EFI_HII_UPDATE_DATA UpdateData; IFR_OPTION *OptionList; CHAR8 *LanguageString; @@ -364,18 +363,15 @@ InitializeFrontPage ( // // Publish our HII data // - PackageList = HiiLibPreparePackageList (2, &mFrontPageGuid, FrontPageVfrBin, BdsDxeStrings); - ASSERT (PackageList != NULL); - - Status = gHiiDatabase->NewPackageList ( - gHiiDatabase, - PackageList, - gFrontPagePrivate.DriverHandle, - &gFrontPagePrivate.HiiHandle - ); - FreePool (PackageList); - if (EFI_ERROR (Status)) { - return Status; + gFrontPagePrivate.HiiHandle = HiiAddPackages ( + &mFrontPageGuid, + gFrontPagePrivate.DriverHandle, + FrontPageVfrBin, + BdsDxeStrings, + NULL + ); + if (gFrontPagePrivate.HiiHandle == NULL) { + return EFI_OUT_OF_RESOURCES; } } @@ -394,7 +390,7 @@ InitializeFrontPage ( // Collect the languages from what our current Language support is based on our VFR // HiiHandle = gFrontPagePrivate.HiiHandle; - LanguageString = HiiLibGetSupportedLanguages (HiiHandle); + LanguageString = HiiGetSupportedLanguages (HiiHandle); ASSERT (LanguageString != NULL); // // Allocate working buffer for RFC 4646 language in supported LanguageString. @@ -455,8 +451,7 @@ InitializeFrontPage ( } ASSERT_EFI_ERROR (Status); - Token = 0; - Status = HiiLibNewString (HiiHandle, &Token, StringBuffer); + Token = HiiSetString (HiiHandle, 0, StringBuffer, NULL); FreePool (StringBuffer); } else { Token = gFrontPagePrivate.LanguageToken[OptionCount]; @@ -578,11 +573,13 @@ GetProducerString ( OUT CHAR16 **String ) { - EFI_STATUS Status; + EFI_STRING TmpString; - Status = HiiLibGetStringFromToken (ProducerGuid, Token, String); - if (EFI_ERROR (Status)) { + TmpString = HiiGetPackageString (ProducerGuid, Token, NULL); + if (TmpString == NULL) { *String = GetStringById (STRING_TOKEN (STR_MISSING_STRING)); + } else { + *String = TmpString; } return EFI_SUCCESS; @@ -698,7 +695,7 @@ UpdateFrontPageStrings ( BiosVendor = (EFI_MISC_BIOS_VENDOR_DATA *) (DataHeader + 1); GetProducerString (&Record->ProducerName, BiosVendor->BiosVersion, &NewString); TokenToUpdate = STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION); - HiiLibSetString (gFrontPagePrivate.HiiHandle, TokenToUpdate, NewString); + HiiSetString (gFrontPagePrivate.HiiHandle, TokenToUpdate, NewString, NULL); FreePool (NewString); Find[0] = TRUE; } @@ -709,7 +706,7 @@ UpdateFrontPageStrings ( SystemManufacturer = (EFI_MISC_SYSTEM_MANUFACTURER_DATA *) (DataHeader + 1); GetProducerString (&Record->ProducerName, SystemManufacturer->SystemProductName, &NewString); TokenToUpdate = STRING_TOKEN (STR_FRONT_PAGE_COMPUTER_MODEL); - HiiLibSetString (gFrontPagePrivate.HiiHandle, TokenToUpdate, NewString); + HiiSetString (gFrontPagePrivate.HiiHandle, TokenToUpdate, NewString, NULL); FreePool (NewString); Find[1] = TRUE; } @@ -720,7 +717,7 @@ UpdateFrontPageStrings ( ProcessorVersion = (EFI_PROCESSOR_VERSION_DATA *) (DataHeader + 1); GetProducerString (&Record->ProducerName, *ProcessorVersion, &NewString); TokenToUpdate = STRING_TOKEN (STR_FRONT_PAGE_CPU_MODEL); - HiiLibSetString (gFrontPagePrivate.HiiHandle, TokenToUpdate, NewString); + HiiSetString (gFrontPagePrivate.HiiHandle, TokenToUpdate, NewString, NULL); FreePool (NewString); Find[2] = TRUE; } @@ -731,7 +728,7 @@ UpdateFrontPageStrings ( ProcessorFrequency = (EFI_PROCESSOR_CORE_FREQUENCY_DATA *) (DataHeader + 1); ConvertProcessorToString (ProcessorFrequency, &NewString); TokenToUpdate = STRING_TOKEN (STR_FRONT_PAGE_CPU_SPEED); - HiiLibSetString (gFrontPagePrivate.HiiHandle, TokenToUpdate, NewString); + HiiSetString (gFrontPagePrivate.HiiHandle, TokenToUpdate, NewString, NULL); FreePool (NewString); Find[3] = TRUE; } @@ -745,7 +742,7 @@ UpdateFrontPageStrings ( &NewString ); TokenToUpdate = STRING_TOKEN (STR_FRONT_PAGE_MEMORY_SIZE); - HiiLibSetString (gFrontPagePrivate.HiiHandle, TokenToUpdate, NewString); + HiiSetString (gFrontPagePrivate.HiiHandle, TokenToUpdate, NewString, NULL); FreePool (NewString); Find[4] = TRUE; } diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/Language.c b/IntelFrameworkModulePkg/Universal/BdsDxe/Language.c index c9e19c5ff0..fe3f0e0064 100644 --- a/IntelFrameworkModulePkg/Universal/BdsDxe/Language.c +++ b/IntelFrameworkModulePkg/Universal/BdsDxe/Language.c @@ -24,7 +24,7 @@ EFI_GUID mFontPackageGuid = { typedef struct { /// - /// This 4-bytes total array length is required by HiiLibPreparePackageList() + /// This 4-bytes total array length is required by HiiAddPackages() /// UINT32 Length; @@ -260,13 +260,14 @@ ExportFonts ( ) { EFI_HII_HANDLE HiiHandle; - EFI_HII_PACKAGE_LIST_HEADER *PackageList; - PackageList = HiiLibPreparePackageList (1, &mFontPackageGuid, &mFontBin); - ASSERT (PackageList != NULL); - - gHiiDatabase->NewPackageList (gHiiDatabase, PackageList, mBdsImageHandle, &HiiHandle); - FreePool (PackageList); + HiiHandle = HiiAddPackages ( + &mFontPackageGuid, + mBdsImageHandle, + &mFontBin, + NULL + ); + ASSERT (HiiHandle != NULL); } /** diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/String.c b/IntelFrameworkModulePkg/Universal/BdsDxe/String.c index a509a85df1..ccabd3239d 100644 --- a/IntelFrameworkModulePkg/Universal/BdsDxe/String.c +++ b/IntelFrameworkModulePkg/Universal/BdsDxe/String.c @@ -25,34 +25,19 @@ EFI_GUID mBdsStringPackGuid = { /** Initialize HII global accessor for string support - @retval EFI_SUCCESS String support initialize success. - **/ -EFI_STATUS +VOID InitializeStringSupport ( VOID ) { - EFI_STATUS Status; - EFI_HII_PACKAGE_LIST_HEADER *PackageList; - - Status = gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **) &gHiiDatabase); - if (EFI_ERROR (Status)) { - return Status; - } - - PackageList = HiiLibPreparePackageList (1, &mBdsStringPackGuid, &BdsDxeStrings); - ASSERT (PackageList != NULL); - - Status = gHiiDatabase->NewPackageList ( - gHiiDatabase, - PackageList, - mBdsImageHandle, - &gStringPackHandle - ); - - FreePool (PackageList); - return Status; + gStringPackHandle = HiiAddPackages ( + &mBdsStringPackGuid, + mBdsImageHandle, + BdsDxeStrings, + NULL + ); + ASSERT (gStringPackHandle != NULL); } /** @@ -70,10 +55,5 @@ GetStringById ( IN EFI_STRING_ID Id ) { - CHAR16 *String; - - String = NULL; - HiiLibGetStringFromHandle (gStringPackHandle, Id, &String); - - return String; + return HiiGetString (gStringPackHandle, Id, NULL); } diff --git a/IntelFrameworkModulePkg/Universal/BdsDxe/String.h b/IntelFrameworkModulePkg/Universal/BdsDxe/String.h index 81a7a6035a..4b8efa4345 100644 --- a/IntelFrameworkModulePkg/Universal/BdsDxe/String.h +++ b/IntelFrameworkModulePkg/Universal/BdsDxe/String.h @@ -52,10 +52,8 @@ GetStringById ( /** Initialize HII global accessor for string support - @retval EFI_SUCCESS String support initialize success. - **/ -EFI_STATUS +VOID InitializeStringSupport ( VOID ); diff --git a/MdeModulePkg/Application/PlatOverMngr/PlatOverMngr.c b/MdeModulePkg/Application/PlatOverMngr/PlatOverMngr.c index 64a26c6665..018917fd0a 100644 --- a/MdeModulePkg/Application/PlatOverMngr/PlatOverMngr.c +++ b/MdeModulePkg/Application/PlatOverMngr/PlatOverMngr.c @@ -409,17 +409,19 @@ UpdateDeviceSelectPage ( // then the 'first refresh' string will be replaced by the 'refresh' string, and the two strings content are same after the replacement // NewStringToken = STRING_TOKEN (STR_FIRST_REFRESH); - HiiLibGetStringFromHandle (Private->RegisteredHandle, STRING_TOKEN (STR_REFRESH), &NewString); + NewString = HiiGetString (Private->RegisteredHandle, STRING_TOKEN (STR_REFRESH), NULL); ASSERT (NewString != NULL); - Status = HiiLibSetString (Private->RegisteredHandle, NewStringToken, NewString); - ASSERT_EFI_ERROR (Status); + if (HiiSetString (Private->RegisteredHandle, NewStringToken, NewString, NULL) == 0) { + ASSERT (FALSE); + } FreePool (NewString); NewStringToken = STRING_TOKEN (STR_FIRST_REFRESH_HELP); - HiiLibGetStringFromHandle (Private->RegisteredHandle, STRING_TOKEN (STR_REFRESH_HELP), &NewString); + NewString = HiiGetString (Private->RegisteredHandle, STRING_TOKEN (STR_REFRESH_HELP), NULL); ASSERT (NewString != NULL); - Status = HiiLibSetString (Private->RegisteredHandle, NewStringToken, NewString); - ASSERT_EFI_ERROR (Status); + if (HiiSetString (Private->RegisteredHandle, NewStringToken, NewString, NULL) == 0) { + ASSERT (FALSE); + } FreePool (NewString); // @@ -504,13 +506,8 @@ UpdateDeviceSelectPage ( } StrCat (NewString, ControllerName); - NewStringToken = mControllerToken[Index]; - if (NewStringToken == 0) { - Status = HiiLibNewString (Private->RegisteredHandle, &NewStringToken, NewString); - } else { - Status = HiiLibSetString (Private->RegisteredHandle, NewStringToken, NewString); - } - ASSERT_EFI_ERROR (Status); + NewStringToken = HiiSetString (Private->RegisteredHandle, mControllerToken[Index], NewString, NULL); + ASSERT (NewStringToken != 0); FreePool (NewString); // // Save the device path string toke for next access use @@ -799,7 +796,7 @@ UpdateBindingDriverSelectPage ( // // give a default name // - HiiLibGetStringFromHandle (Private->RegisteredHandle, STRING_TOKEN (STR_DRIVER_DEFAULT_NAME), &DriverName); + DriverName = HiiGetString (Private->RegisteredHandle, STRING_TOKEN (STR_DRIVER_DEFAULT_NAME), NULL); ASSERT (DriverName != NULL); FreeDriverName = TRUE; // the DriverName string need to free pool } @@ -821,14 +818,9 @@ UpdateBindingDriverSelectPage ( mLastSavedDriverImageNum++; } StrCat (NewString, DriverName); - NewStringToken = mDriverImageToken[Index]; - if (NewStringToken == 0) { - Status = HiiLibNewString (Private->RegisteredHandle, &NewStringToken, NewString); - } else { - Status = HiiLibSetString (Private->RegisteredHandle, NewStringToken, NewString); - } + NewStringToken = HiiSetString (Private->RegisteredHandle, mDriverImageToken[Index], NewString, NULL); + ASSERT (NewStringToken != 0); mDriverImageToken[Index] = NewStringToken; - ASSERT_EFI_ERROR (Status); FreePool (NewString); if (FreeDriverName) { FreePool (DriverName); @@ -842,14 +834,9 @@ UpdateBindingDriverSelectPage ( NewString = AllocateZeroPool (StrSize (DriverName)); ASSERT (NewString != NULL); StrCat (NewString, DriverName); - NewStringHelpToken = mDriverImageFilePathToken[Index]; - if (NewStringHelpToken == 0) { - Status = HiiLibNewString (Private->RegisteredHandle, &NewStringHelpToken, NewString); - } else { - Status = HiiLibSetString (Private->RegisteredHandle, NewStringHelpToken, NewString); - } + NewStringHelpToken = HiiSetString (Private->RegisteredHandle, mDriverImageFilePathToken[Index], NewString, NULL); + ASSERT (NewStringHelpToken != 0); mDriverImageFilePathToken[Index] = NewStringHelpToken; - ASSERT_EFI_ERROR (Status); FreePool (NewString); FreePool (DriverName); @@ -1304,8 +1291,9 @@ PlatOverMngrCallback ( // Update page title string // NewStringToken = STRING_TOKEN (STR_TITLE); - Status = HiiLibSetString (Private->RegisteredHandle, NewStringToken, L"First, Select the controller by device path"); - ASSERT_EFI_ERROR (Status); + if (HiiSetString (Private->RegisteredHandle, NewStringToken, L"First, Select the controller by device path", NULL) == 0) { + ASSERT (FALSE); + } } if (((KeyValue >= KEY_VALUE_DEVICE_OFFSET) && (KeyValue < KEY_VALUE_DEVICE_MAX)) || (KeyValue == KEY_VALUE_ORDER_GOTO_PREVIOUS)) { @@ -1317,8 +1305,9 @@ PlatOverMngrCallback ( // Update page title string // NewStringToken = STRING_TOKEN (STR_TITLE); - Status = HiiLibSetString (Private->RegisteredHandle, NewStringToken, L"Second, Select drivers for the previous selected controller"); - ASSERT_EFI_ERROR (Status); + if (HiiSetString (Private->RegisteredHandle, NewStringToken, L"Second, Select drivers for the previous selected controller", NULL) == 0) { + ASSERT (FALSE); + } } if (KeyValue == KEY_VALUE_DRIVER_GOTO_ORDER) { @@ -1327,8 +1316,9 @@ PlatOverMngrCallback ( // Update page title string // NewStringToken = STRING_TOKEN (STR_TITLE); - Status = HiiLibSetString (Private->RegisteredHandle, NewStringToken, L"Finally, Set the priority order for the drivers and save them"); - ASSERT_EFI_ERROR (Status); + if (HiiSetString (Private->RegisteredHandle, NewStringToken, L"Finally, Set the priority order for the drivers and save them", NULL) == 0) { + ASSERT (FALSE); + } } if (KeyValue == KEY_VALUE_ORDER_SAVE_AND_EXIT) { @@ -1383,22 +1373,8 @@ PlatOverMngrInit ( ) { EFI_STATUS Status; - EFI_HII_DATABASE_PROTOCOL *HiiDatabase; - EFI_HII_PACKAGE_LIST_HEADER *PackageList; EFI_FORM_BROWSER2_PROTOCOL *FormBrowser2; - // - // There should only be one HII protocol - // - Status = gBS->LocateProtocol ( - &gEfiHiiDatabaseProtocolGuid, - NULL, - (VOID **) &HiiDatabase - ); - if (EFI_ERROR (Status)) { - return Status; - } - // // There should only be one Form Configuration protocol // @@ -1439,23 +1415,15 @@ PlatOverMngrInit ( // // Publish our HII data // - PackageList = HiiLibPreparePackageList ( - 2, - &mPlatformOverridesManagerGuid, - VfrBin, - PlatOverMngrStrings - ); - ASSERT (PackageList != NULL); - - Status = HiiDatabase->NewPackageList ( - HiiDatabase, - PackageList, - mCallbackInfo->DriverHandle, - &mCallbackInfo->RegisteredHandle - ); - FreePool (PackageList); - - if (EFI_ERROR (Status)) { + mCallbackInfo->RegisteredHandle = HiiAddPackages ( + &mPlatformOverridesManagerGuid, + mCallbackInfo->DriverHandle, + VfrBin, + PlatOverMngrStrings, + NULL + ); + if (mCallbackInfo->RegisteredHandle == NULL) { + Status = EFI_OUT_OF_RESOURCES; goto Finish; } @@ -1494,11 +1462,8 @@ PlatOverMngrInit ( NULL ); - HiiDatabase->RemovePackageList (HiiDatabase, mCallbackInfo->RegisteredHandle); - - if (EFI_ERROR (Status)) { - goto Finish; - } + HiiRemovePackages (mCallbackInfo->RegisteredHandle); + Status = EFI_SUCCESS; Finish: if (mCallbackInfo->DriverHandle != NULL) { diff --git a/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c b/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c index 7a8ee00d3c..32ea3cfb8a 100644 --- a/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c +++ b/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c @@ -318,7 +318,6 @@ InstallDefaultKeyboardLayout ( EFI_STATUS Status; EFI_HII_DATABASE_PROTOCOL *HiiDatabase; EFI_HII_HANDLE HiiHandle; - EFI_HII_PACKAGE_LIST_HEADER *PackageList; // // Locate Hii database protocol @@ -335,13 +334,14 @@ InstallDefaultKeyboardLayout ( // // Install Keyboard Layout package to HII database // - PackageList = HiiLibPreparePackageList (1, &mUsbKeyboardLayoutPackageGuid, &mUsbKeyboardLayoutBin); - ASSERT (PackageList != NULL); - - Status = HiiDatabase->NewPackageList (HiiDatabase, PackageList, UsbKeyboardDevice->ControllerHandle, &HiiHandle); - FreePool (PackageList); - if (EFI_ERROR (Status)) { - return Status; + HiiHandle = HiiAddPackages ( + &mUsbKeyboardLayoutPackageGuid, + UsbKeyboardDevice->ControllerHandle, + &mUsbKeyboardLayoutBin, + NULL + ); + if (HiiHandle == NULL) { + return EFI_OUT_OF_RESOURCES; } // diff --git a/MdeModulePkg/Include/Library/HiiLib.h b/MdeModulePkg/Include/Library/HiiLib.h index 37b59bf376..730f450fc5 100644 --- a/MdeModulePkg/Include/Library/HiiLib.h +++ b/MdeModulePkg/Include/Library/HiiLib.h @@ -17,281 +17,207 @@ /** - Assemble EFI_HII_PACKAGE_LIST according to the passed in packages. - - If GuidId is NULL, then ASSERT. - If not enough resource to complete the operation, then ASSERT. - - @param NumberOfPackages Number of packages. - @param GuidId Package GUID. - @param ... Variable argument list for packages to be assembled. - - @return Pointer of EFI_HII_PACKAGE_LIST_HEADER. - -**/ -EFI_HII_PACKAGE_LIST_HEADER * -EFIAPI -HiiLibPreparePackageList ( - IN UINTN NumberOfPackages, - IN CONST EFI_GUID *GuidId, - ... - ) -; - -/** - This function allocates pool for an EFI_HII_PACKAGE_LIST structure - with additional space that is big enough to host all packages described by the variable - argument list of package pointers. The allocated structure is initialized using NumberOfPackages, - GuidId, and the variable length argument list of package pointers. - - Then, EFI_HII_PACKAGE_LIST will be register to the default System HII Database. The - Handle to the newly registered Package List is returned throught HiiHandle. + Registers a list of packages in the HII Database and returns the HII Handle + associated with that registration. If an HII Handle has already been registered + with the same PackageListGuid, then NULL is returned. If there are not enough + resources to perform the registration, then NULL is returned. If an empty list + of packages is passed in, then NULL is returned. If the size of the list of + package is 0, then NULL is returned. - If HiiHandle is NULL, then ASSERT. + The variable arguments are pointers which point to package header that defined + by UEFI VFR compiler and StringGather tool. - @param NumberOfPackages The number of HII packages to register. - @param GuidId Package List GUID ID. - @param DriverHandle Optional. If not NULL, the DriverHandle on which an instance of DEVICE_PATH_PROTOCOL is installed. - This DriverHandle uniquely defines the device that the added packages are associated with. - @param HiiHandle On output, the HiiHandle is update with the handle which can be used to retrieve the Package - List later. If the functions failed to add the package to the default HII database, this value will - be set to NULL. - @param ... The variable argument list describing all HII Package. + #pragma pack (push, 1) + typedef struct { + UINT32 BinaryLength; + EFI_HII_PACKAGE_HEADER PackageHeader; + } EDKII_AUTOGEN_PACKAGES_HEADER; + #pragma pack (pop) + + @param[in] PackageListGuid The GUID of the package list. + @param[in] DeviceHandle If not NULL, the Device Handle on which + an instance of DEVICE_PATH_PROTOCOL is installed. + This Device Handle uniquely defines the device that + the added packages are associated with. + @param[in] ... The variable argument list that contains pointers + to packages terminated by a NULL. - @return EFI_SUCCESS If the packages are successfully added to the default HII database. - @return EFI_OUT_OF_RESOURCE Not enough resource to complete the operation. + @retval NULL A HII Handle has already been registered in the HII Database with + the same PackageListGuid. + @retval NULL The HII Handle could not be created. + @retval NULL An empty list of packages was passed in. + @retval NULL All packages are empty. + @retval Other The HII Handle associated with the newly registered package list. **/ -EFI_STATUS +EFI_HII_HANDLE EFIAPI -HiiLibAddPackages ( - IN UINTN NumberOfPackages, - IN CONST EFI_GUID *GuidId, - IN EFI_HANDLE DriverHandle, OPTIONAL - OUT EFI_HII_HANDLE *HiiHandle, +HiiAddPackages ( + IN CONST EFI_GUID *PackageListGuid, + IN EFI_HANDLE DeviceHandle OPTIONAL, ... ) ; /** - Removes a package list from the default HII database. + Removes a package list from the HII database. If HiiHandle is NULL, then ASSERT. - If HiiHandle is not a valid EFI_HII_HANDLE in the default HII database, then ASSERT. + If HiiHandle is not a valid EFI_HII_HANDLE in the HII database, then ASSERT. - @param HiiHandle The handle that was previously registered to the data base that is requested for removal. - List later. + @param[in] HiiHandle The handle that was previously registered in the HII database **/ VOID EFIAPI -HiiLibRemovePackages ( +HiiRemovePackages ( IN EFI_HII_HANDLE HiiHandle ) ; /** - This function adds the string into String Package of each language - supported by the package list. - - If String is NULL, then ASSERT. - If StringId is NULL, the ASSERT. - If PackageList could not be found in the default HII database, then ASSERT. - - @param PackageList Handle of the package list where this string will - be added. - @param StringId On return, contains the new strings id, which is - unique within PackageList. - @param String Points to the new null-terminated string. - - @retval EFI_SUCCESS The new string was added successfully. - @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources. - -**/ -EFI_STATUS -EFIAPI -HiiLibNewString ( - IN EFI_HII_HANDLE PackageList, - OUT EFI_STRING_ID *StringId, - IN CONST EFI_STRING String - ) -; - -/** - This function update the specified string in String Package of each language - supported by the package list. - - If String is NULL, then ASSERT. - If PackageList could not be found in the default HII database, then ASSERT. - If StringId is not found in PackageList, then ASSERT. - - @param PackageList Handle of the package list where this string will - be added. - @param StringId Ths String Id to be updated. - @param String Points to the new null-terminated string. - - @retval EFI_SUCCESS The new string was added successfully. - @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources. - -**/ -EFI_STATUS -EFIAPI -HiiLibSetString ( - IN EFI_HII_HANDLE PackageList, - IN EFI_STRING_ID StringId, - IN CONST EFI_STRING String - ) -; - -/** - This function try to retrieve string from String package of current language. - If fails, it try to retrieve string from String package of first language it support. - - If StringSize is NULL, then ASSERT. - If String is NULL and *StringSize is not 0, then ASSERT. - If PackageList could not be found in the default HII database, then ASSERT. - If StringId is not found in PackageList, then ASSERT. - - @param PackageList The package list in the HII database to search for - the specified string. - @param StringId The string's id, which is unique within - PackageList. - @param String Points to the new null-terminated string. - @param StringSize On entry, points to the size of the buffer pointed - to by String, in bytes. On return, points to the - length of the string, in bytes. - - @retval EFI_SUCCESS The string was returned successfully. - @retval EFI_NOT_FOUND The string specified by StringId is not available. - @retval EFI_BUFFER_TOO_SMALL The buffer specified by StringLength is too small - to hold the string. - -**/ -EFI_STATUS -EFIAPI -HiiLibGetString ( - IN EFI_HII_HANDLE PackageList, - IN EFI_STRING_ID StringId, - OUT EFI_STRING String, - IN OUT UINTN *StringSize - ) -; - -/** - Get string specified by StringId form the HiiHandle. The caller - is responsible to free the *String. - - If String is NULL, then ASSERT. - If HiiHandle could not be found in the default HII database, then ASSERT. - If StringId is not found in PackageList, then ASSERT. - - @param HiiHandle The HII handle of package list. - @param StringId The String ID. - @param String The output string. - - @retval EFI_NOT_FOUND String is not found. - @retval EFI_SUCCESS Operation is successful. - @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system. - -**/ -EFI_STATUS -EFIAPI -HiiLibGetStringFromHandle ( - IN EFI_HII_HANDLE HiiHandle, - IN EFI_STRING_ID StringId, - OUT EFI_STRING *String - ) -; - -/** - Get the string given the StringId and String package Producer's Guid. The caller - is responsible to free the *String. - - If PackageList with the matching ProducerGuid is not found, then ASSERT. - If PackageList with the matching ProducerGuid is found but no String is - specified by StringId is found, then ASSERT. + This function create a new string in String Package or updates an existing + string in a String Package. If StringId is 0, then a new string is added to + a String Package. If StringId is not zero, then a string in String Package is + updated. If SupportedLanguages is NULL, then the string is added or updated + for all the languages that the String Package supports. If SupportedLanguages + is not NULL, then the string is added or updated for the set of languages + specified by SupportedLanguages. + + If HiiHandle is NULL, then ASSERT(). + If String is NULL, then ASSERT(). - @param ProducerGuid The Guid of String package list. - @param StringId The String ID. - @param String The output string. + @param[in] HiiHandle A handle that was previously registered in the + HII Database. + @param[in] StringId If zero, then a new string is created in the + String Package associated with HiiHandle. If + non-zero, then the string specified by StringId + is updated in the String Package associated + with HiiHandle. + @param[in] String A pointer to the Null-terminated Unicode string + to add or update in the String Package associated + with HiiHandle. + @param[in] SupportedLanguages A pointer to a Null-terminated ASCII string of + language codes. If this parameter is NULL, then + String is added or updated in the String Package + associated with HiiHandle for all the languages + that the String Package supports. If this + parameter is not NULL, then then String is added + or updated in the String Package associated with + HiiHandle for the set oflanguages specified by + SupportedLanguages. The format of + SupportedLanguages must follow the language + format assumed the HII Database. - @retval EFI_SUCCESS Operation is successful. - @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system. + @retval 0 The string could not be added or updated in the String Package. + @retval Other The EFI_STRING_ID of the newly added or updated string. **/ -EFI_STATUS +EFI_STRING_ID EFIAPI -HiiLibGetStringFromToken ( - IN EFI_GUID *ProducerGuid, - IN EFI_STRING_ID StringId, - OUT EFI_STRING *String +HiiSetString ( + IN EFI_HII_HANDLE HiiHandle, + IN EFI_STRING_ID StringId, OPTIONAL + IN CONST EFI_STRING String, + IN CONST CHAR8 *SupportedLanguages OPTIONAL ) ; /** - Determines the handles that are currently active in the database. - It's the caller's responsibility to free handle buffer. - - If HandleBufferLength is NULL, then ASSERT. - If HiiHandleBuffer is NULL, then ASSERT. + Retrieves a string from a string package in a specific language. If the language + is not specified, then a string from a string package in the current platform + language is retrieved. If the string can not be retrieved using the specified + language or the current platform language, then the string is retrieved from + the string package in the first language the string package supports. The + returned string is allocated using AllocatePool(). The caller is responsible + for freeing the allocated buffer using FreePool(). + + If HiiHandle is NULL, then ASSERT(). + If StringId is 0, then ASSET. - @param HandleBufferLength On input, a pointer to the length of the handle - buffer. On output, the length of the handle buffer - that is required for the handles found. - @param HiiHandleBuffer Pointer to an array of Hii Handles returned. + @param[in] HiiHandle A handle that was previously registered in the HII Database. + @param[in] StringId The identifier of the string to retrieved from the string + package associated with HiiHandle. + @param[in] Language The language of the string to retrieve. If this parameter + is NULL, then the current platform language is used. The + format of Language must follow the language format assumed + the HII Database. - @retval EFI_SUCCESS Get an array of Hii Handles successfully. + @retval NULL The string specified by StringId is not present in the string package. + @retval Other The string was returned. **/ -EFI_STATUS +EFI_STRING EFIAPI -HiiLibGetHiiHandles ( - IN OUT UINTN *HandleBufferLength, - OUT EFI_HII_HANDLE **HiiHandleBuffer +HiiGetString ( + IN EFI_HII_HANDLE HiiHandle, + IN EFI_STRING_ID StringId, + IN CONST CHAR8 *Language OPTIONAL ) ; /** - Extract Hii package list GUID for given HII handle. - - If HiiHandle could not be found in the default HII database, then ASSERT. - If Guid is NULL, then ASSERT. + Retrieves a string from a string package names by GUID in a specific language. + If the language is not specified, then a string from a string package in the + current platform language is retrieved. If the string can not be retrieved + using the specified language or the current platform language, then the string + is retrieved from the string package in the first language the string package + supports. The returned string is allocated using AllocatePool(). The caller + is responsible for freeing the allocated buffer using FreePool(). + + If PackageListGuid is NULL, then ASSERT(). + If StringId is 0, then ASSERT. - @param Handle Hii handle - @param Guid Package list GUID + @param[in] PackageListGuid The GUID of a package list that was previously + registered in the HII Database. + @param[in] StringId The identifier of the string to retrieved from the + string package associated with PackageListGuid. + @param[in] Language The language of the string to retrieve. If this + parameter is NULL, then the current platform + language is used. The format of Language must + follow the language format assumed the HII Database. - @retval EFI_SUCCESS Successfully extract GUID from Hii database. + @retval NULL The package list specified by PackageListGuid is not present in the + HII Database. + @retval NULL The string specified by StringId is not present in the string package. + @retval Other The string was returned. **/ -EFI_STATUS +EFI_STRING EFIAPI -HiiLibExtractGuidFromHiiHandle ( - IN EFI_HII_HANDLE Handle, - OUT EFI_GUID *Guid +HiiGetPackageString ( + IN CONST EFI_GUID *PackageListGuid, + IN EFI_STRING_ID StringId, + IN CONST CHAR8 *Language OPTIONAL ) ; /** - Find HII Handle in the default HII database associated with given Device Path. - - If DevicePath is NULL, then ASSERT. + Retrieves the array of all the HII Handles or the HII handle of a specific + package list in the HII Database. + This array is terminated with a NULL HII Handle. + This function allocates the returned array using AllocatePool(). + The caller is responsible for freeing the array with FreePool(). - @param DevicePath Device Path associated with the HII package list - handle. + @param[in] PackageListGuid An optional parameter that is used to request + an HII Handle that is associatd with a specific + Package List GUID. If this parameter is NULL + then all the HII Handles in the HII Database + are returned. If this parameter is not NULL + then at most 1 HII Handle is returned. - @retval Handle HII package list Handle associated with the Device - Path. - @retval NULL Hii Package list handle is not found. + @retval NULL No HII handles were found in the HII database + @retval NULL The array of HII Handles could not be retrieved + @retval Other A pointer to the NULL terminated array of HII Handles **/ -EFI_HII_HANDLE +EFI_HII_HANDLE * EFIAPI -HiiLibDevicePathToHiiHandle ( - IN EFI_DEVICE_PATH_PROTOCOL *DevicePath +HiiGetHiiHandles ( + IN CONST EFI_GUID *PackageListGuid OPTIONAL ) ; - /** Get next language from language code list (with separator ';'). @@ -313,138 +239,30 @@ HiiLibGetNextLanguage ( ; /** - This function returns the list of supported languages, in the format specified - in UEFI specification Appendix M. - - If HiiHandle is not a valid Handle in the default HII database, then ASSERT. - - @param HiiHandle The HII package list handle. - - @retval !NULL The supported languages. - @retval NULL If Supported Languages can not be retrived. - -**/ -CHAR8 * -EFIAPI -HiiLibGetSupportedLanguages ( - IN EFI_HII_HANDLE HiiHandle - ) -; - -/** - This function returns the list of supported 2nd languages, in the format specified - in UEFI specification Appendix M. - - If HiiHandle is not a valid Handle in the default HII database, then ASSERT. - If not enough resource to complete the operation, then ASSERT. - - @param HiiHandle The HII package list handle. - @param FirstLanguage Pointer to language name buffer. + Retrieves a pointer to the a Null-terminated ASCII string containing the list + of languages that an HII handle in the HII Database supports. The returned + string is allocated using AllocatePool(). The caller is responsible for freeing + the returned string using FreePool(). The format of the returned string follows + the language format assumed the HII Database. - @return The supported languages. - -**/ -CHAR8 * -EFIAPI -HiiLibGetSupportedSecondaryLanguages ( - IN EFI_HII_HANDLE HiiHandle, - IN CONST CHAR8 *FirstLanguage - ) -; - - -/** - This function returns the number of supported languages on HiiHandle. - - If HiiHandle is not a valid Handle in the default HII database, then ASSERT. - If not enough resource to complete the operation, then ASSERT. + If HiiHandle is NULL, then ASSERT(). - @param HiiHandle The HII package list handle. + @param[in] HiiHandle A handle that was previously registered in the HII Database. - @return The number of supported languages. + @retval NULL HiiHandle is not registered in the HII database + @retval NULL There are not enough resources available to retrieve the suported + languages. + @retval NULL The list of suported languages could not be retrieved. + @retval Other A pointer to the Null-terminated ASCII string of supported languages. **/ -UINT16 +CHAR8 * EFIAPI -HiiLibGetSupportedLanguageNumber ( +HiiGetSupportedLanguages ( IN EFI_HII_HANDLE HiiHandle ) ; -/** - Exports the contents of one or all package lists in the HII database into a buffer. - - If Handle is not NULL and not a valid EFI_HII_HANDLE registered in the database, - then ASSERT. - If PackageListHeader is NULL, then ASSERT. - If PackageListSize is NULL, then ASSERT. - - @param Handle The HII Handle. - @param PackageListHeader A pointer to a buffer that will contain the results of - the export function. - @param PackageListSize On output, the length of the buffer that is required for the exported data. - - @retval EFI_SUCCESS Package exported. - - @retval EFI_OUT_OF_RESOURCES Not enought memory to complete the operations. - -**/ -EFI_STATUS -EFIAPI -HiiLibExportPackageLists ( - IN EFI_HII_HANDLE Handle, - OUT EFI_HII_PACKAGE_LIST_HEADER **PackageListHeader, - OUT UINTN *PackageListSize - ) -; - -/** - - This function returns a list of the package handles of the - specified type that are currently active in the HII database. The - pseudo-type EFI_HII_PACKAGE_TYPE_ALL will cause all package - handles to be listed. - - If HandleBufferLength is NULL, then ASSERT. - If HandleBuffer is NULL, the ASSERT. - If PackageType is EFI_HII_PACKAGE_TYPE_GUID and PackageGuid is - NULL, then ASSERT. - If PackageType is not EFI_HII_PACKAGE_TYPE_GUID and PackageGuid is not - NULL, then ASSERT. - - - @param PackageType Specifies the package type of the packages - to list or EFI_HII_PACKAGE_TYPE_ALL for - all packages to be listed. - - @param PackageGuid If PackageType is - EFI_HII_PACKAGE_TYPE_GUID, then this is - the pointer to the GUID which must match - the Guid field of - EFI_HII_PACKAGE_GUID_HEADER. Otherwise, it - must be NULL. - - @param HandleBufferLength On output, the length of the handle buffer - that is required for the handles found. - - @param HandleBuffer On output, an array of EFI_HII_HANDLE instances returned. - The caller is responcible to free this pointer allocated. - - @retval EFI_SUCCESS The matching handles are outputed successfully. - HandleBufferLength is updated with the actual length. - @retval EFI_OUT_OF_RESOURCES Not enough resource to complete the operation. - @retval EFI_NOT_FOUND No matching handle could not be found in database. -**/ -EFI_STATUS -EFIAPI -HiiLibListPackageLists ( - IN UINT8 PackageType, - IN CONST EFI_GUID *PackageGuid, - IN OUT UINTN *HandleBufferLength, - OUT EFI_HII_HANDLE **Handle - ) -; - /** Convert language code from RFC3066 to ISO639-2. diff --git a/MdeModulePkg/Library/UefiHiiLib/HiiLanguage.c b/MdeModulePkg/Library/UefiHiiLib/HiiLanguage.c index 21173296ba..45e178c446 100644 --- a/MdeModulePkg/Library/UefiHiiLib/HiiLanguage.c +++ b/MdeModulePkg/Library/UefiHiiLib/HiiLanguage.c @@ -58,155 +58,81 @@ HiiLibGetNextLanguage ( /** - This function returns the list of supported languages, in the format specified - in UEFI specification Appendix M. - - If HiiHandle is not a valid Handle in the default HII database, then ASSERT. + Retrieves a pointer to the a Null-terminated ASCII string containing the list + of languages that an HII handle in the HII Database supports. The returned + string is allocated using AllocatePool(). The caller is responsible for freeing + the returned string using FreePool(). The format of the returned string follows + the language format assumed the HII Database. + + If HiiHandle is NULL, then ASSERT(). - @param HiiHandle The HII package list handle. + @param[in] HiiHandle A handle that was previously registered in the HII Database. - @retval !NULL The supported languages. - @retval NULL If Supported Languages can not be retrived. + @retval NULL HiiHandle is not registered in the HII database + @retval NULL There are not enough resources available to retrieve the suported + languages. + @retval NULL The list of suported languages could not be retrieved. + @retval Other A pointer to the Null-terminated ASCII string of supported languages. **/ CHAR8 * EFIAPI -HiiLibGetSupportedLanguages ( +HiiGetSupportedLanguages ( IN EFI_HII_HANDLE HiiHandle ) { EFI_STATUS Status; - UINTN BufferSize; - CHAR8 *LanguageString; + UINTN LanguageSize; + CHAR8 TempSupportedLanguages; + CHAR8 *SupportedLanguages; + + ASSERT (HiiHandle != NULL); - ASSERT (IsHiiHandleRegistered (HiiHandle)); // - // Collect current supported Languages for given HII handle - // First try allocate 4K buffer to store the current supported languages. + // Retrieve the size required for the supported languages buffer. // - BufferSize = 0x1000; - LanguageString = AllocateZeroPool (BufferSize); - if (LanguageString == NULL) { - return NULL; - } - - Status = gHiiString->GetLanguages (gHiiString, HiiHandle, LanguageString, &BufferSize); - - if (Status == EFI_BUFFER_TOO_SMALL) { - FreePool (LanguageString); - LanguageString = AllocateZeroPool (BufferSize); - if (LanguageString == NULL) { - return NULL; - } - - Status = gHiiString->GetLanguages (gHiiString, HiiHandle, LanguageString, &BufferSize); - } - - if (EFI_ERROR (Status)) { - LanguageString = NULL; - } - - return LanguageString; -} - - -/** - This function returns the number of supported languages on HiiHandle. - - If HiiHandle is not a valid Handle in the default HII database, then ASSERT. - If not enough resource to complete the operation, then ASSERT. - - @param HiiHandle The HII package list handle. - - @return The number of supported languages. - -**/ -UINT16 -EFIAPI -HiiLibGetSupportedLanguageNumber ( - IN EFI_HII_HANDLE HiiHandle - ) -{ - CHAR8 *Languages; - CHAR8 *LanguageString; - UINT16 LangNumber; - CHAR8 *Lang; - - Languages = HiiLibGetSupportedLanguages (HiiHandle); - if (Languages == NULL) { - return 0; - } - - LangNumber = 0; - Lang = AllocatePool (AsciiStrSize (Languages)); - if (Lang != NULL) { - LanguageString = Languages; - while (*LanguageString != 0) { - HiiLibGetNextLanguage (&LanguageString, Lang); - LangNumber++; - } + LanguageSize = 0; + Status = gHiiString->GetLanguages (gHiiString, HiiHandle, &TempSupportedLanguages, &LanguageSize); - FreePool (Lang); - } - FreePool (Languages); - - return LangNumber; -} - -/** - This function returns the list of supported 2nd languages, in the format specified - in UEFI specification Appendix M. - - If HiiHandle is not a valid Handle in the default HII database, then ASSERT. - If not enough resource to complete the operation, then ASSERT. - - @param HiiHandle The HII package list handle. - @param FirstLanguage Pointer to language name buffer. - - @return The supported languages. - -**/ -CHAR8 * -EFIAPI -HiiLibGetSupportedSecondaryLanguages ( - IN EFI_HII_HANDLE HiiHandle, - IN CONST CHAR8 *FirstLanguage - ) -{ - EFI_STATUS Status; - UINTN BufferSize; - CHAR8 *LanguageString; - - ASSERT (HiiHandle != NULL); - ASSERT (IsHiiHandleRegistered (HiiHandle)); // - // Collect current supported 2nd Languages for given HII handle - // First try allocate 4K buffer to store the current supported 2nd languages. + // If GetLanguages() returns EFI_SUCCESS for a zero size, + // then there are no supported languages registered for HiiHandle. If GetLanguages() + // returns an error other than EFI_BUFFER_TOO_SMALL, then HiiHandle is not present + // in the HII Database // - BufferSize = 0x1000; - LanguageString = AllocateZeroPool (BufferSize); - if (LanguageString == NULL) { + if (Status != EFI_BUFFER_TOO_SMALL) { + // + // Return NULL if the size can not be retrieved, or if HiiHandle is not in the HII Database + // return NULL; } - Status = gHiiString->GetSecondaryLanguages (gHiiString, HiiHandle, FirstLanguage, LanguageString, &BufferSize); - - if (Status == EFI_BUFFER_TOO_SMALL) { - FreePool (LanguageString); - LanguageString = AllocateZeroPool (BufferSize); - if (LanguageString == NULL) { - return NULL; - } - - Status = gHiiString->GetSecondaryLanguages (gHiiString, HiiHandle, FirstLanguage, LanguageString, &BufferSize); + // + // Allocate the supported languages buffer. + // + SupportedLanguages = AllocateZeroPool (LanguageSize); + if (SupportedLanguages == NULL) { + // + // Return NULL if allocation fails. + // + return NULL; } + // + // Retrieve the supported languages string + // + Status = gHiiString->GetLanguages (gHiiString, HiiHandle, SupportedLanguages, &LanguageSize); if (EFI_ERROR (Status)) { - LanguageString = NULL; + // + // Free the buffer and return NULL if the supported languages can not be retrieved. + // + FreePool (SupportedLanguages); + return NULL; } - return LanguageString; + // + // Return the Null-terminated ASCII string of supported languages + // + return SupportedLanguages; } - - diff --git a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c index 384bab4ed6..e337b23475 100644 --- a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c +++ b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c @@ -19,16 +19,26 @@ // GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR16 mConfigHdrTemplate[] = L"GUID=00000000000000000000000000000000&NAME=0000&PATH=00"; +EFI_FORM_BROWSER2_PROTOCOL *mUefiFormBrowser2 = NULL; + // -// Form Browser2 Protocol +// Template used to mark the end of a list of packages // -EFI_FORM_BROWSER2_PROTOCOL *mUefiFormBrowser2 = NULL; +GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_HII_PACKAGE_HEADER mEndOfPakageList = { + sizeof (EFI_HII_PACKAGE_HEADER), + EFI_HII_PACKAGE_END +}; /** - This funciton build the package list based on the package number, - the GUID of the package list and the list of pointer which point to - package header that defined by UEFI VFR compiler and StringGather - tool. + Registers a list of packages in the HII Database and returns the HII Handle + associated with that registration. If an HII Handle has already been registered + with the same PackageListGuid, then NULL is returned. If there are not enough + resources to perform the registration, then NULL is returned. If an empty list + of packages is passed in, then NULL is returned. If the size of the list of + package is 0, then NULL is returned. + + The variable arguments are pointers which point to package header that defined + by UEFI VFR compiler and StringGather tool. #pragma pack (push, 1) typedef struct { @@ -36,267 +46,269 @@ EFI_FORM_BROWSER2_PROTOCOL *mUefiFormBrowser2 = NULL; EFI_HII_PACKAGE_HEADER PackageHeader; } EDKII_AUTOGEN_PACKAGES_HEADER; #pragma pack (pop) - - If there is not enough resource for the new package list, - the function will ASSERT. - - @param NumberOfPackages The number of packages be - @param GuidId The GUID for the package list to be generated. - @param Marker The variable argument list. Each entry represent a specific package header that is - generated by VFR compiler and StrGather tool. The first 4 bytes is a UINT32 value - that indicate the overall length of the package. - - @return The pointer to the package list header. + + @param[in] PackageListGuid The GUID of the package list. + @param[in] DeviceHandle If not NULL, the Device Handle on which + an instance of DEVICE_PATH_PROTOCOL is installed. + This Device Handle uniquely defines the device that + the added packages are associated with. + @param[in] ... The variable argument list that contains pointers + to packages terminated by a NULL. + + @retval NULL A HII Handle has already been registered in the HII Database with + the same PackageListGuid. + @retval NULL The HII Handle could not be created. + @retval NULL An empty list of packages was passed in. + @retval NULL All packages are empty. + @retval Other The HII Handle associated with the newly registered package list. **/ -EFI_HII_PACKAGE_LIST_HEADER * -InternalHiiLibPreparePackages ( - IN UINTN NumberOfPackages, - IN CONST EFI_GUID *GuidId, - IN VA_LIST Marker +EFI_HII_HANDLE +EFIAPI +HiiAddPackages ( + IN CONST EFI_GUID *PackageListGuid, + IN EFI_HANDLE DeviceHandle OPTIONAL, + ... ) { - EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader; - UINT8 *PackageListData; - UINT32 PackageListLength; - UINT32 PackageLength; - EFI_HII_PACKAGE_HEADER PackageHeader; - UINT8 *PackageArray; - UINTN Index; - VA_LIST MarkerBackup; - - PackageListLength = sizeof (EFI_HII_PACKAGE_LIST_HEADER); + EFI_STATUS Status; + EFI_HII_HANDLE *HiiHandleBuffer; + VA_LIST Args; + UINT32 *Package; + EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader; + EFI_HII_HANDLE HiiHandle; + UINT32 Length; + UINT8 *Data; - MarkerBackup = Marker; + ASSERT (PackageListGuid != NULL); // - // Count the length of the final package list. + // Check to see if an HII Handle has already been registered with the same + // PackageListGuid // - for (Index = 0; Index < NumberOfPackages; Index++) { - CopyMem (&PackageLength, VA_ARG (Marker, VOID *), sizeof (UINT32)); - // - // Do not count the BinaryLength field. - // - PackageListLength += (PackageLength - sizeof (UINT32)); + HiiHandleBuffer = HiiGetHiiHandles (PackageListGuid); + if (HiiHandleBuffer != NULL) { + FreePool (HiiHandleBuffer); + return NULL; } // - // Include the length of EFI_HII_PACKAGE_END + // Calculate the length of all the packages in the variable argument list // - PackageListLength += sizeof (EFI_HII_PACKAGE_HEADER); - PackageListHeader = AllocateZeroPool (PackageListLength); - ASSERT (PackageListHeader != NULL); - - CopyGuid (&PackageListHeader->PackageListGuid, GuidId); - PackageListHeader->PackageLength = PackageListLength; - - PackageListData = ((UINT8 *) PackageListHeader) + sizeof (EFI_HII_PACKAGE_LIST_HEADER); + for (Length = 0, VA_START (Args, DeviceHandle); (Package = VA_ARG (Args, UINT32 *)) != NULL; ) { + Length += (ReadUnaligned32 (Package) - sizeof (UINT32)); + } + VA_END (Args); - Marker = MarkerBackup; // - // Prepare the final package list. + // If there are no packages in the variable argument list or all the packages + // are empty, then return a NULL HII Handle // - for (Index = 0; Index < NumberOfPackages; Index++) { - PackageArray = (UINT8 *) VA_ARG (Marker, VOID *); - // - // CopyMem is used for UINT32 to cover the unaligned address access. - // - CopyMem (&PackageLength, PackageArray, sizeof (UINT32)); - PackageLength -= sizeof (UINT32); - PackageArray += sizeof (UINT32); - CopyMem (PackageListData, PackageArray, PackageLength); - PackageListData += PackageLength; + if (Length == 0) { + return NULL; } // - // Append EFI_HII_PACKAGE_END + // Add the length of the Package List Header and the terminating Package Header // - PackageHeader.Type = EFI_HII_PACKAGE_END; - PackageHeader.Length = sizeof (EFI_HII_PACKAGE_HEADER); - CopyMem (PackageListData, &PackageHeader, PackageHeader.Length); - - return PackageListHeader; -} - -/** - Assemble EFI_HII_PACKAGE_LIST according to the passed in packages. - - If GuidId is NULL, then ASSERT. - If not enough resource to complete the operation, then ASSERT. - - @param NumberOfPackages Number of packages. - @param GuidId Package GUID. - @param ... Variable argument list for packages to be assembled. + Length += sizeof (EFI_HII_PACKAGE_LIST_HEADER) + sizeof (EFI_HII_PACKAGE_HEADER); - @return Pointer of EFI_HII_PACKAGE_LIST_HEADER. - -**/ -EFI_HII_PACKAGE_LIST_HEADER * -EFIAPI -HiiLibPreparePackageList ( - IN UINTN NumberOfPackages, - IN CONST EFI_GUID *GuidId, - ... - ) -{ - EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader; - VA_LIST Marker; - - ASSERT (GuidId != NULL); - - VA_START (Marker, GuidId); - PackageListHeader = InternalHiiLibPreparePackages (NumberOfPackages, GuidId, Marker); - VA_END (Marker); - - return PackageListHeader; -} - - -/** - This function allocates pool for an EFI_HII_PACKAGE_LIST structure - with additional space that is big enough to host all packages described by the variable - argument list of package pointers. The allocated structure is initialized using NumberOfPackages, - GuidId, and the variable length argument list of package pointers. - - Then, EFI_HII_PACKAGE_LIST will be register to the default System HII Database. The - Handle to the newly registered Package List is returned through HiiHandle. - - If HiiHandle is NULL, then ASSERT. + // + // Allocate the storage for the entire Package List + // + PackageListHeader = AllocateZeroPool (Length); - @param NumberOfPackages The number of HII packages to register. - @param GuidId Package List GUID ID. - @param DriverHandle Optional. If not NULL, the DriverHandle on which an instance of DEVICE_PATH_PROTOCOL is installed. - This DriverHandle uniquely defines the device that the added packages are associated with. - @param HiiHandle On output, the HiiHandle is update with the handle which can be used to retrieve the Package - List later. If the functions failed to add the package to the default HII database, this value will - be set to NULL. - @param ... The variable argument list describing all HII Package. + // + // If the Packahge List can not be allocated, then return a NULL HII Handle + // + if (PackageListHeader == NULL) { + return NULL; + } - @return EFI_SUCCESS If the packages are successfully added to the default HII database. - @return EFI_OUT_OF_RESOURCE Not enough resource to complete the operation. + // + // Fill in the GUID and Length of the Package List Header + // + CopyGuid (&PackageListHeader->PackageListGuid, PackageListGuid); + PackageListHeader->PackageLength = Length; -**/ -EFI_STATUS -EFIAPI -HiiLibAddPackages ( - IN UINTN NumberOfPackages, - IN CONST EFI_GUID *GuidId, - IN EFI_HANDLE DriverHandle, OPTIONAL - OUT EFI_HII_HANDLE *HiiHandle, - ... - ) -{ - VA_LIST Args; - EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader; - EFI_STATUS Status; + // + // Initialize a pointer to the beginning if the Package List data + // + Data = (UINT8 *)(PackageListHeader + 1); - ASSERT (HiiHandle != NULL); + // + // Copy the data from each package in the variable argument list + // + for (VA_START (Args, DeviceHandle); (Package = VA_ARG (Args, UINT32 *)) != NULL; ) { + Length = ReadUnaligned32 (Package) - sizeof (UINT32); + CopyMem (Data, Package + 1, Length); + Data += Length; + } + VA_END (Args); - VA_START (Args, HiiHandle); - PackageListHeader = InternalHiiLibPreparePackages (NumberOfPackages, GuidId, Args); + // + // Append a package of type EFI_HII_PACKAGE_END to mark the end of the package list + // + CopyMem (Data, &mEndOfPakageList, sizeof (mEndOfPakageList)); - Status = gHiiDatabase->NewPackageList (gHiiDatabase, PackageListHeader, DriverHandle, HiiHandle); - if (HiiHandle != NULL) { - if (EFI_ERROR (Status)) { - *HiiHandle = NULL; - } + // + // Register the package list with the HII Database + // + Status = gHiiDatabase->NewPackageList ( + gHiiDatabase, + PackageListHeader, + DeviceHandle, + &HiiHandle + ); + if (EFI_ERROR (Status)) { + HiiHandle = NULL; } + // + // Free the allocated package list + // FreePool (PackageListHeader); - VA_END (Args); - - return Status; + + // + // Return the new HII Handle + // + return HiiHandle; } /** - Removes a package list from the default HII database. + Removes a package list from the HII database. If HiiHandle is NULL, then ASSERT. - If HiiHandle is not a valid EFI_HII_HANDLE in the default HII database, then ASSERT. + If HiiHandle is not a valid EFI_HII_HANDLE in the HII database, then ASSERT. - @param HiiHandle The handle that was previously registered to the data base that is requested for removal. - List later. + @param[in] HiiHandle The handle that was previously registered in the HII database **/ VOID EFIAPI -HiiLibRemovePackages ( +HiiRemovePackages ( IN EFI_HII_HANDLE HiiHandle ) { EFI_STATUS Status; - ASSERT (IsHiiHandleRegistered (HiiHandle)); + ASSERT (HiiHandle != NULL); Status = gHiiDatabase->RemovePackageList (gHiiDatabase, HiiHandle); ASSERT_EFI_ERROR (Status); } /** - Determines the handles that are currently active in the database. - It's the caller's responsibility to free handle buffer. - - If HandleBufferLength is NULL, then ASSERT. - If HiiHandleBuffer is NULL, then ASSERT. - - @param HandleBufferLength On input, a pointer to the length of the handle - buffer. On output, the length of the handle buffer - that is required for the handles found. - @param HiiHandleBuffer Pointer to an array of Hii Handles returned. - - @retval EFI_SUCCESS Get an array of Hii Handles successfully. + Retrieves the array of all the HII Handles or the HII handle of a specific + package list in the HII Database. + This array is terminated with a NULL HII Handle. + This function allocates the returned array using AllocatePool(). + The caller is responsible for freeing the array with FreePool(). + + @param[in] PackageListGuid An optional parameter that is used to request + an HII Handle that is associatd with a specific + Package List GUID. If this parameter is NULL + then all the HII Handles in the HII Database + are returned. If this parameter is not NULL + then at most 1 HII Handle is returned. + + @retval NULL No HII handles were found in the HII database + @retval NULL The array of HII Handles could not be retrieved + @retval Other A pointer to the NULL terminated array of HII Handles **/ -EFI_STATUS +EFI_HII_HANDLE * EFIAPI -HiiLibGetHiiHandles ( - IN OUT UINTN *HandleBufferLength, - OUT EFI_HII_HANDLE **HiiHandleBuffer +HiiGetHiiHandles ( + IN CONST EFI_GUID *PackageListGuid OPTIONAL ) { - EFI_STATUS Status; + EFI_STATUS Status; + UINTN HandleBufferLength; + EFI_HII_HANDLE TempHiiHandleBuffer; + EFI_HII_HANDLE *HiiHandleBuffer; + EFI_GUID Guid; + UINTN Index; + + // + // Retrieve the size required for the buffer of all HII handles. + // + HandleBufferLength = 0; + Status = gHiiDatabase->ListPackageLists ( + gHiiDatabase, + EFI_HII_PACKAGE_TYPE_ALL, + NULL, + &HandleBufferLength, + &TempHiiHandleBuffer + ); - ASSERT (HandleBufferLength != NULL); - ASSERT (HiiHandleBuffer != NULL); + // + // If ListPackageLists() returns EFI_SUCCESS for a zero size, + // then there are no HII handles in the HII database. If ListPackageLists() + // returns an error other than EFI_BUFFER_TOO_SMALL, then there are no HII + // handles in the HII database. + // + if (Status != EFI_BUFFER_TOO_SMALL) { + // + // Return NULL if the size can not be retrieved, or if there are no HII + // handles in the HII Database + // + return NULL; + } - *HandleBufferLength = 0; - *HiiHandleBuffer = NULL; + // + // Allocate the array of HII handles to hold all the HII Handles and a NULL terminator + // + HiiHandleBuffer = AllocateZeroPool (HandleBufferLength + sizeof (EFI_HII_HANDLE)); + if (HiiHandleBuffer == NULL) { + // + // Return NULL if allocation fails. + // + return NULL; + } // - // Try to find the actual buffer size for HiiHandle Buffer. + // Retrieve the array of HII Handles in the HII Database // Status = gHiiDatabase->ListPackageLists ( - gHiiDatabase, - EFI_HII_PACKAGE_TYPE_ALL, - NULL, - HandleBufferLength, - *HiiHandleBuffer - ); - - if (Status == EFI_BUFFER_TOO_SMALL) { - *HiiHandleBuffer = AllocateZeroPool (*HandleBufferLength); - ASSERT (*HiiHandleBuffer != NULL); - Status = gHiiDatabase->ListPackageLists ( - gHiiDatabase, - EFI_HII_PACKAGE_TYPE_ALL, - NULL, - HandleBufferLength, - *HiiHandleBuffer - ); - - if (EFI_ERROR (Status)) { - FreePool (*HiiHandleBuffer); - *HiiHandleBuffer = NULL; - } + gHiiDatabase, + EFI_HII_PACKAGE_TYPE_ALL, + NULL, + &HandleBufferLength, + HiiHandleBuffer + ); + if (EFI_ERROR (Status)) { + // + // Free the buffer and return NULL if the HII handles can not be retrieved. + // + FreePool (HiiHandleBuffer); + return NULL; } - return Status; + if (PackageListGuid == NULL) { + // + // Return the NULL terminated array of HII handles in the HII Database + // + return HiiHandleBuffer; + } else { + for (Index = 0; HiiHandleBuffer[Index] != NULL; Index++) { + Status = InternalHiiExtractGuidFromHiiHandle (HiiHandleBuffer[Index], &Guid); + ASSERT_EFI_ERROR (Status); + if (CompareGuid (&Guid, PackageListGuid)) { + HiiHandleBuffer[0] = HiiHandleBuffer[Index]; + HiiHandleBuffer[1] = NULL; + return HiiHandleBuffer; + } + } + FreePool (HiiHandleBuffer); + return NULL; + } } /** Extract Hii package list GUID for given HII handle. - If HiiHandle could not be found in the default HII database, then ASSERT. + If HiiHandle could not be found in the HII database, then ASSERT. If Guid is NULL, then ASSERT. @param Handle Hii handle @@ -307,7 +319,7 @@ HiiLibGetHiiHandles ( **/ EFI_STATUS EFIAPI -HiiLibExtractGuidFromHiiHandle ( +InternalHiiExtractGuidFromHiiHandle ( IN EFI_HII_HANDLE Handle, OUT EFI_GUID *Guid ) @@ -317,7 +329,7 @@ HiiLibExtractGuidFromHiiHandle ( EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList; ASSERT (Guid != NULL); - ASSERT (IsHiiHandleRegistered (Handle)); + ASSERT (Handle != NULL); // // Get HII PackageList @@ -349,326 +361,6 @@ HiiLibExtractGuidFromHiiHandle ( return EFI_SUCCESS; } -/** - Find HII Handle in the default HII database associated with given Device Path. - - If DevicePath is NULL, then ASSERT. - - @param DevicePath Device Path associated with the HII package list - handle. - - @retval Handle HII package list Handle associated with the Device - Path. - @retval NULL Hii Package list handle is not found. - -**/ -EFI_HII_HANDLE -EFIAPI -HiiLibDevicePathToHiiHandle ( - IN EFI_DEVICE_PATH_PROTOCOL *DevicePath - ) -{ - EFI_STATUS Status; - EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath; - UINTN BufferSize; - UINTN HandleCount; - UINTN Index; - EFI_HANDLE *Handles; - EFI_HANDLE Handle; - UINTN Size; - EFI_HANDLE DriverHandle; - EFI_HII_HANDLE *HiiHandles; - EFI_HII_HANDLE HiiHandle; - - ASSERT (DevicePath != NULL); - - // - // Locate Device Path Protocol handle buffer - // - Status = gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiDevicePathProtocolGuid, - NULL, - &HandleCount, - &Handles - ); - if (EFI_ERROR (Status)) { - return NULL; - } - - // - // Search Driver Handle by Device Path - // - DriverHandle = NULL; - BufferSize = GetDevicePathSize (DevicePath); - for(Index = 0; Index < HandleCount; Index++) { - Handle = Handles[Index]; - gBS->HandleProtocol (Handle, &gEfiDevicePathProtocolGuid, (VOID **) &TmpDevicePath); - - // - // Check whether DevicePath match - // - Size = GetDevicePathSize (TmpDevicePath); - if ((Size == BufferSize) && CompareMem (DevicePath, TmpDevicePath, Size) == 0) { - DriverHandle = Handle; - break; - } - } - FreePool (Handles); - - if (DriverHandle == NULL) { - return NULL; - } - - // - // Retrieve all Hii Handles from HII database - // - BufferSize = 0x1000; - HiiHandles = AllocatePool (BufferSize); - ASSERT (HiiHandles != NULL); - Status = gHiiDatabase->ListPackageLists ( - gHiiDatabase, - EFI_HII_PACKAGE_TYPE_ALL, - NULL, - &BufferSize, - HiiHandles - ); - if (Status == EFI_BUFFER_TOO_SMALL) { - FreePool (HiiHandles); - HiiHandles = AllocatePool (BufferSize); - ASSERT (HiiHandles != NULL); - - Status = gHiiDatabase->ListPackageLists ( - gHiiDatabase, - EFI_HII_PACKAGE_TYPE_ALL, - NULL, - &BufferSize, - HiiHandles - ); - } - - if (EFI_ERROR (Status)) { - FreePool (HiiHandles); - return NULL; - } - - // - // Search Hii Handle by Driver Handle - // - HiiHandle = NULL; - HandleCount = BufferSize / sizeof (EFI_HII_HANDLE); - for (Index = 0; Index < HandleCount; Index++) { - Status = gHiiDatabase->GetPackageListHandle ( - gHiiDatabase, - HiiHandles[Index], - &Handle - ); - if (!EFI_ERROR (Status) && (Handle == DriverHandle)) { - HiiHandle = HiiHandles[Index]; - break; - } - } - - FreePool (HiiHandles); - return HiiHandle; -} - -/** - Exports the contents of one or all package lists in the HII database into a buffer. - - If Handle is not NULL and not a valid EFI_HII_HANDLE registered in the database, - then ASSERT. - If PackageListHeader is NULL, then ASSERT. - If PackageListSize is NULL, then ASSERT. - - @param Handle The HII Handle. - @param PackageListHeader A pointer to a buffer that will contain the results of - the export function. - @param PackageListSize On output, the length of the buffer that is required for the exported data. - - @retval EFI_SUCCESS Package exported. - - @retval EFI_OUT_OF_RESOURCES Not enought memory to complete the operations. - -**/ -EFI_STATUS -EFIAPI -HiiLibExportPackageLists ( - IN EFI_HII_HANDLE Handle, - OUT EFI_HII_PACKAGE_LIST_HEADER **PackageListHeader, - OUT UINTN *PackageListSize - ) -{ - EFI_STATUS Status; - UINTN Size; - EFI_HII_PACKAGE_LIST_HEADER *PackageListHdr; - - ASSERT (PackageListSize != NULL); - ASSERT (PackageListHeader != NULL); - - if (Handle != NULL) { - ASSERT (IsHiiHandleRegistered (Handle)); - } - - Size = 0; - PackageListHdr = NULL; - Status = gHiiDatabase->ExportPackageLists ( - gHiiDatabase, - Handle, - &Size, - PackageListHdr - ); - ASSERT_EFI_ERROR (Status != EFI_BUFFER_TOO_SMALL); - - if (Status == EFI_BUFFER_TOO_SMALL) { - PackageListHdr = AllocateZeroPool (Size); - - if (PackageListHeader == NULL) { - return EFI_OUT_OF_RESOURCES; - } else { - Status = gHiiDatabase->ExportPackageLists ( - gHiiDatabase, - Handle, - &Size, - PackageListHdr - ); - } - } - - if (!EFI_ERROR (Status)) { - *PackageListHeader = PackageListHdr; - *PackageListSize = Size; - } else { - FreePool (PackageListHdr); - } - - return Status; -} - -/** - - This function returns a list of the package handles of the - specified type that are currently active in the HII database. The - pseudo-type EFI_HII_PACKAGE_TYPE_ALL will cause all package - handles to be listed. - - If HandleBufferLength is NULL, then ASSERT. - If HandleBuffer is NULL, the ASSERT. - If PackageType is EFI_HII_PACKAGE_TYPE_GUID and PackageGuid is - NULL, then ASSERT. - If PackageType is not EFI_HII_PACKAGE_TYPE_GUID and PackageGuid is not - NULL, then ASSERT. - - - @param PackageType Specifies the package type of the packages - to list or EFI_HII_PACKAGE_TYPE_ALL for - all packages to be listed. - - @param PackageGuid If PackageType is - EFI_HII_PACKAGE_TYPE_GUID, then this is - the pointer to the GUID which must match - the Guid field of - EFI_HII_PACKAGE_GUID_HEADER. Otherwise, it - must be NULL. - - @param HandleBufferLength On output, the length of the handle buffer - that is required for the handles found. - - @param HandleBuffer On output, an array of EFI_HII_HANDLE instances returned. - The caller is responcible to free this pointer allocated. - - @retval EFI_SUCCESS The matching handles are outputed successfully. - HandleBufferLength is updated with the actual length. - @retval EFI_OUT_OF_RESOURCES Not enough resource to complete the operation. - @retval EFI_NOT_FOUND No matching handle could not be found in database. -**/ -EFI_STATUS -EFIAPI -HiiLibListPackageLists ( - IN UINT8 PackageType, - IN CONST EFI_GUID *PackageGuid, - IN OUT UINTN *HandleBufferLength, - OUT EFI_HII_HANDLE **HandleBuffer - ) -{ - EFI_STATUS Status; - - ASSERT (HandleBufferLength != NULL); - ASSERT (HandleBuffer != NULL); - - *HandleBufferLength = 0; - *HandleBuffer = NULL; - - if (PackageType == EFI_HII_PACKAGE_TYPE_GUID) { - ASSERT (PackageGuid != NULL); - } else { - ASSERT (PackageGuid == NULL); - } - - Status = gHiiDatabase->ListPackageLists ( - gHiiDatabase, - PackageType, - PackageGuid, - HandleBufferLength, - *HandleBuffer - ); - if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) { - // - // No packages is registered to UEFI HII Database, just return. - // - // - return Status; - } - - *HandleBuffer = AllocateZeroPool (*HandleBufferLength); - - if (*HandleBuffer == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - return gHiiDatabase->ListPackageLists ( - gHiiDatabase, - PackageType, - PackageGuid, - HandleBufferLength, - *HandleBuffer - ); - -} -/** - This function check if the Hii Handle is a valid handle registered - in the HII database. - - @param HiiHandle The HII Handle. - - @retval TRUE If it is a valid HII handle. - @retval FALSE If it is a invalid HII handle. -**/ -BOOLEAN -IsHiiHandleRegistered ( - EFI_HII_HANDLE HiiHandle - ) -{ - EFI_STATUS Status; - UINTN BufferSize; - EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList; - - ASSERT (HiiHandle != NULL); - - HiiPackageList = NULL; - BufferSize = 0; - - Status = gHiiDatabase->ExportPackageLists ( - gHiiDatabase, - HiiHandle, - &BufferSize, - HiiPackageList - ); - - return (BOOLEAN) (Status == EFI_BUFFER_TOO_SMALL); -} - - /** Converts all hex dtring characters in range ['A'..'F'] to ['a'..'f'] for hex digits that appear between a '=' and a '&' in a config string. @@ -2916,3 +2608,4 @@ HiiIfrLibExtractDefault( return EFI_SUCCESS; } + diff --git a/MdeModulePkg/Library/UefiHiiLib/HiiString.c b/MdeModulePkg/Library/UefiHiiLib/HiiString.c index 7d8ca5e117..2c317e5de3 100644 --- a/MdeModulePkg/Library/UefiHiiLib/HiiString.c +++ b/MdeModulePkg/Library/UefiHiiLib/HiiString.c @@ -163,339 +163,340 @@ zulzu\ /** - This function adds the string into String Package of each language - supported by the package list. - - If String is NULL, then ASSERT. - If StringId is NULL, the ASSERT. - If PackageList could not be found in the default HII database, then ASSERT. - - @param PackageList Handle of the package list where this string will - be added. - @param StringId On return, contains the new strings id, which is - unique within PackageList. - @param String Points to the new null-terminated string. - - @retval EFI_SUCCESS The new string was added successfully. - @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources. + This function create a new string in String Package or updates an existing + string in a String Package. If StringId is 0, then a new string is added to + a String Package. If StringId is not zero, then a string in String Package is + updated. If SupportedLanguages is NULL, then the string is added or updated + for all the languages that the String Package supports. If SupportedLanguages + is not NULL, then the string is added or updated for the set of languages + specified by SupportedLanguages. + + If HiiHandle is NULL, then ASSERT(). + If String is NULL, then ASSERT(). + + @param[in] HiiHandle A handle that was previously registered in the + HII Database. + @param[in] StringId If zero, then a new string is created in the + String Package associated with HiiHandle. If + non-zero, then the string specified by StringId + is updated in the String Package associated + with HiiHandle. + @param[in] String A pointer to the Null-terminated Unicode string + to add or update in the String Package associated + with HiiHandle. + @param[in] SupportedLanguages A pointer to a Null-terminated ASCII string of + language codes. If this parameter is NULL, then + String is added or updated in the String Package + associated with HiiHandle for all the languages + that the String Package supports. If this + parameter is not NULL, then then String is added + or updated in the String Package associated with + HiiHandle for the set oflanguages specified by + SupportedLanguages. The format of + SupportedLanguages must follow the language + format assumed the HII Database. + + @retval 0 The string could not be added or updated in the String Package. + @retval Other The EFI_STRING_ID of the newly added or updated string. **/ -EFI_STATUS +EFI_STRING_ID EFIAPI -HiiLibNewString ( - IN EFI_HII_HANDLE PackageList, - OUT EFI_STRING_ID *StringId, - IN CONST EFI_STRING String +HiiSetString ( + IN EFI_HII_HANDLE HiiHandle, + IN EFI_STRING_ID StringId, OPTIONAL + IN CONST EFI_STRING String, + IN CONST CHAR8 *SupportedLanguages OPTIONAL ) { - EFI_STATUS Status; - CHAR8 *Languages; - CHAR8 *LangStrings; - CHAR8 *Lang; + EFI_STATUS Status; + CHAR8 *AllocatedLanguages; + CHAR8 *Supported; + CHAR8 *Language; + EFI_STRING_ID NewStringId; + ASSERT (HiiHandle != NULL); ASSERT (String != NULL); - ASSERT (StringId != NULL); - Status = EFI_SUCCESS; + if (SupportedLanguages == NULL) { + // + // Retrieve the languages that the package specified by HiiHandle supports + // + AllocatedLanguages = HiiGetSupportedLanguages (HiiHandle); + } else { + // + // Allocate a copy of the SupportLanguages string that passed in + // + AllocatedLanguages = AllocateCopyPool (AsciiStrLen (SupportedLanguages), SupportedLanguages); + } - Languages = HiiLibGetSupportedLanguages (PackageList); - ASSERT (Languages != NULL); // - // Allocate working buffer to contain substring of Languages. + // If there are not enough resources for the supported languages string, then return a StringId of 0 // - Lang = AllocatePool (AsciiStrSize (Languages)); - ASSERT (Lang != NULL); + if (AllocatedLanguages == NULL) { + return (EFI_STRING_ID)(0); + } - LangStrings = Languages; - while (*LangStrings != 0) { - HiiLibGetNextLanguage (&LangStrings, Lang); + NewStringId = 0; + Status = EFI_INVALID_PARAMETER; + // + // Loop through each language that the string supports + // + for (Supported = AllocatedLanguages; *Supported != '\0'; ) { + // + // Cache a pointer to the beginning of the current language in the list of languages + // + Language = Supported; // - // For each language supported by the package, - // a string token is created. + // Search for the next language seperator and replace it with a Null-terminator // - Status = gHiiString->NewString ( - gHiiString, - PackageList, - StringId, - Lang, - NULL, - String, - NULL - ); - if (EFI_ERROR (Status)) { - break; + for (; *Supported != 0 && *Supported != ';'; Supported++); + if (*Supported != 0) { + *(Supported++) = '\0'; } - } - - FreePool (Lang); - FreePool (Languages); - - return Status; - -} - -/** - This function update the specified string in String Package of each language - supported by the package list. - - If String is NULL, then ASSERT. - If PackageList could not be found in the default HII database, then ASSERT. - If StringId is not found in PackageList, then ASSERT. - - @param PackageList Handle of the package list where this string will - be added. - @param StringId Ths String Id to be updated. - @param String Points to the new null-terminated string. - - @retval EFI_SUCCESS The new string was added successfully. - @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources. - -**/ -EFI_STATUS -EFIAPI -HiiLibSetString ( - IN EFI_HII_HANDLE PackageList, - IN EFI_STRING_ID StringId, - IN CONST EFI_STRING String - ) -{ - EFI_STATUS Status; - CHAR8 *Languages; - CHAR8 *LangStrings; - CHAR8 *Lang; - - ASSERT (IsHiiHandleRegistered (PackageList)); - - Status = EFI_SUCCESS; - - Languages = HiiLibGetSupportedLanguages (PackageList); - ASSERT (Languages != NULL); - - // - // Allocate working buffer to contain substring of Languages. - // - Lang = AllocatePool (AsciiStrSize (Languages)); - ASSERT (Lang != NULL); - - LangStrings = Languages; - while (*LangStrings != 0) { - HiiLibGetNextLanguage (&LangStrings, Lang); + // + // If StringId is 0, then call NewString(). Otherwise, call SetString() + // + if (StringId == (EFI_STRING_ID)(0)) { + Status = gHiiString->NewString (gHiiString, HiiHandle, &NewStringId, Language, NULL, String, NULL); + } else { + Status = gHiiString->SetString (gHiiString, HiiHandle, StringId, Language, String, NULL); + } // - // For each language supported by the package, - // the string is updated. + // If there was an error, then break out of the loop and return a StringId of 0 // - Status = gHiiString->SetString ( - gHiiString, - PackageList, - StringId, - Lang, - String, - NULL - ); if (EFI_ERROR (Status)) { break; } } - FreePool (Lang); - FreePool (Languages); - - return Status; + // + // Free the buffer of supported languages + // + FreePool (AllocatedLanguages); + + if (EFI_ERROR (Status)) { + return (EFI_STRING_ID)(0); + } else if (StringId == (EFI_STRING_ID)(0)) { + return NewStringId; + } else { + return StringId; + } } /** - Get the string given the StringId and String package Producer's Guid. The caller - is responsible to free the *String. - - If PackageList with the matching ProducerGuid is not found, then ASSERT. - If PackageList with the matching ProducerGuid is found but no String is - specified by StringId is found, then ASSERT. - - @param ProducerGuid The Guid of String package list. - @param StringId The String ID. - @param String The output string. - - @retval EFI_SUCCESS Operation is successful. - @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system. + Retrieves a string from a string package names by GUID in a specific language. + If the language is not specified, then a string from a string package in the + current platform language is retrieved. If the string can not be retrieved + using the specified language or the current platform language, then the string + is retrieved from the string package in the first language the string package + supports. The returned string is allocated using AllocatePool(). The caller + is responsible for freeing the allocated buffer using FreePool(). + + If PackageListGuid is NULL, then ASSERT(). + If StringId is 0, then ASSERT. + + @param[in] PackageListGuid The GUID of a package list that was previously + registered in the HII Database. + @param[in] StringId The identifier of the string to retrieved from the + string package associated with PackageListGuid. + @param[in] Language The language of the string to retrieve. If this + parameter is NULL, then the current platform + language is used. The format of Language must + follow the language format assumed the HII Database. + + @retval NULL The package list specified by PackageListGuid is not present in the + HII Database. + @retval NULL The string specified by StringId is not present in the string package. + @retval Other The string was returned. **/ -EFI_STATUS +EFI_STRING EFIAPI -HiiLibGetStringFromToken ( - IN EFI_GUID *ProducerGuid, - IN EFI_STRING_ID StringId, - OUT EFI_STRING *String +HiiGetPackageString ( + IN CONST EFI_GUID *PackageListGuid, + IN EFI_STRING_ID StringId, + IN CONST CHAR8 *Language OPTIONAL ) { - EFI_STATUS Status; - UINTN Index; - UINTN HandleBufferLen; - EFI_HII_HANDLE *HiiHandleBuffer; - EFI_GUID Guid; + EFI_HANDLE *HiiHandleBuffer; + EFI_HANDLE HiiHandle; - Status = HiiLibGetHiiHandles (&HandleBufferLen, &HiiHandleBuffer); - if (HiiHandleBuffer == NULL) { - return EFI_NOT_FOUND; - } - for (Index = 0; Index < (HandleBufferLen / sizeof (EFI_HII_HANDLE)); Index++) { - Status = HiiLibExtractGuidFromHiiHandle (HiiHandleBuffer[Index], &Guid); - if (EFI_ERROR(Status)) { - return Status; - } - if (CompareGuid (&Guid, ProducerGuid)) { - break; - } - } + ASSERT (PackageListGuid != NULL); - if (Index >= (HandleBufferLen / sizeof (EFI_HII_HANDLE))) { - // - // If PackageList with the matching ProducerGuid is not found, then ASSERT. - // - ASSERT (FALSE); - Status = EFI_NOT_FOUND; - goto Out; + HiiHandleBuffer = HiiGetHiiHandles (PackageListGuid); + if (HiiHandleBuffer == NULL) { + return NULL; } - Status = HiiLibGetStringFromHandle (HiiHandleBuffer[Index], StringId, String); - -Out: + HiiHandle = HiiHandleBuffer[0]; FreePool (HiiHandleBuffer); - return Status; + return HiiGetString (HiiHandle, StringId, Language); } /** - This function try to retrieve string from String package of current language. - If fails, it try to retrieve string from String package of first language it support. - - If StringSize is NULL, then ASSERT. - If String is NULL and *StringSize is not 0, then ASSERT. - If PackageList could not be found in the default HII database, then ASSERT. - If StringId is not found in PackageList, then ASSERT. - - @param PackageList The package list in the HII database to search for - the specified string. - @param StringId The string's id, which is unique within - PackageList. - @param String Points to the new null-terminated string. - @param StringSize On entry, points to the size of the buffer pointed - to by String, in bytes. On return, points to the - length of the string, in bytes. - - @retval EFI_SUCCESS The string was returned successfully. - @retval EFI_NOT_FOUND The string specified by StringId is not available. - @retval EFI_BUFFER_TOO_SMALL The buffer specified by StringLength is too small - to hold the string. + Retrieves a string from a string package in a specific language. If the language + is not specified, then a string from a string package in the current platform + language is retrieved. If the string can not be retrieved using the specified + language or the current platform language, then the string is retrieved from + the string package in the first language the string package supports. The + returned string is allocated using AllocatePool(). The caller is responsible + for freeing the allocated buffer using FreePool(). + + If HiiHandle is NULL, then ASSERT(). + If StringId is 0, then ASSET. + + @param[in] HiiHandle A handle that was previously registered in the HII Database. + @param[in] StringId The identifier of the string to retrieved from the string + package associated with HiiHandle. + @param[in] Language The language of the string to retrieve. If this parameter + is NULL, then the current platform language is used. The + format of Language must follow the language format assumed + the HII Database. + + @retval NULL The string specified by StringId is not present in the string package. + @retval Other The string was returned. **/ -EFI_STATUS +EFI_STRING EFIAPI -HiiLibGetString ( - IN EFI_HII_HANDLE PackageList, - IN EFI_STRING_ID StringId, - OUT EFI_STRING String, - IN OUT UINTN *StringSize +HiiGetString ( + IN EFI_HII_HANDLE HiiHandle, + IN EFI_STRING_ID StringId, + IN CONST CHAR8 *Language OPTIONAL ) { EFI_STATUS Status; - CHAR8 *Languages; - CHAR8 *CurrentLang; + UINTN StringSize; + CHAR16 TempString; + EFI_STRING String; + CHAR8 *SupportedLanguages; + CHAR8 *PlatformLanguage; CHAR8 *BestLanguage; - ASSERT (StringSize != NULL); - ASSERT (!(*StringSize != 0 && String == NULL)); - ASSERT (IsHiiHandleRegistered (PackageList)); + ASSERT (HiiHandle != NULL); + ASSERT (StringId != 0); - Languages = HiiLibGetSupportedLanguages (PackageList); - ASSERT (Languages != NULL); + // + // Initialize all allocated buffers to NULL + // + SupportedLanguages = NULL; + PlatformLanguage = NULL; + BestLanguage = NULL; + String = NULL; - CurrentLang = GetEfiGlobalVariable (L"PlatformLang"); - - Status = EFI_NOT_FOUND; - BestLanguage = GetBestLanguage ( - Languages, - FALSE, - (CurrentLang != NULL) ? CurrentLang : "", - (CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLang), - Languages, - NULL - ); - if (BestLanguage != NULL ) { - Status = gHiiString->GetString ( - gHiiString, - BestLanguage, - PackageList, - StringId, - String, - StringSize, - NULL - ); - FreePool (BestLanguage); - } - if (CurrentLang != NULL) { - FreePool (CurrentLang); + // + // Get the languages that the package specified by HiiHandle supports + // + SupportedLanguages = HiiGetSupportedLanguages (HiiHandle); + if (SupportedLanguages == NULL) { + goto Error; } - FreePool (Languages); - - return Status; -} + // + // Get the current platform language setting + // + PlatformLanguage = GetEfiGlobalVariable (L"PlatformLang"); -/** - Get string specified by StringId form the HiiHandle. The caller - is responsible to free the *String. - - If String is NULL, then ASSERT. - If HiiHandle could not be found in the default HII database, then ASSERT. - If StringId is not found in PackageList, then ASSERT. - - @param HiiHandle The HII handle of package list. - @param StringId The String ID. - @param String The output string. + // + // If Languag is NULL, then set it to an empty string, so it will be + // skipped by GetBestLanguage() + // + if (Language == NULL) { + Language = ""; + } - @retval EFI_NOT_FOUND String is not found. - @retval EFI_SUCCESS Operation is successful. - @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system. + // + // Get the best matching language from SupportedLanguages + // + BestLanguage = GetBestLanguage ( + SupportedLanguages, + FALSE, // RFC 4646 mode + Language, // Highest priority + PlatformLanguage != NULL ? PlatformLanguage : "", // Next highest priority + SupportedLanguages, // Lowest priority + NULL + ); + if (BestLanguage == NULL) { + goto Error; + } -**/ -EFI_STATUS -EFIAPI -HiiLibGetStringFromHandle ( - IN EFI_HII_HANDLE HiiHandle, - IN EFI_STRING_ID StringId, - OUT EFI_STRING *String - ) -{ - EFI_STATUS Status; - UINTN StringSize; + // + // Retrieve the size of the string in the string package for the BestLanguage + // + StringSize = 0; + Status = gHiiString->GetString ( + gHiiString, + BestLanguage, + HiiHandle, + StringId, + &TempString, + &StringSize, + NULL + ); + // + // If GetString() returns EFI_SUCCESS for a zero size, + // then there are no supported languages registered for HiiHandle. If GetString() + // returns an error other than EFI_BUFFER_TOO_SMALL, then HiiHandle is not present + // in the HII Database + // + if (Status != EFI_BUFFER_TOO_SMALL) { + goto Error; + } - ASSERT (String != NULL); + // + // Allocate a buffer for the return string + // + String = AllocateZeroPool (StringSize); + if (String == NULL) { + goto Error; + } - StringSize = HII_LIB_DEFAULT_STRING_SIZE; - *String = AllocateZeroPool (StringSize); - if (*String == NULL) { - return EFI_OUT_OF_RESOURCES; + // + // Retrieve the string from the string package + // + Status = gHiiString->GetString ( + gHiiString, + BestLanguage, + HiiHandle, + StringId, + String, + &StringSize, + NULL + ); + if (EFI_ERROR (Status)) { + // + // Free the buffer and return NULL if the supported languages can not be retrieved. + // + FreePool (String); + String = NULL; } - Status = HiiLibGetString (HiiHandle, StringId, *String, &StringSize); - if (Status == EFI_BUFFER_TOO_SMALL) { - FreePool (*String); - *String = AllocateZeroPool (StringSize); - if (*String == NULL) { - return EFI_OUT_OF_RESOURCES; - } - Status = HiiLibGetString (HiiHandle, StringId, *String, &StringSize); +Error: + // + // Free allocated buffers + // + if (SupportedLanguages != NULL) { + FreePool (SupportedLanguages); + } + if (PlatformLanguage != NULL) { + FreePool (PlatformLanguage); + } + if (BestLanguage != NULL) { + FreePool (BestLanguage); } - return Status; + // + // Return the Null-terminated Unicode string + // + return String; } - - /** Convert language code from RFC3066 to ISO639-2. diff --git a/MdeModulePkg/Library/UefiHiiLib/InternalHiiLib.h b/MdeModulePkg/Library/UefiHiiLib/InternalHiiLib.h index e1446351d7..c3fd834ec5 100644 --- a/MdeModulePkg/Library/UefiHiiLib/InternalHiiLib.h +++ b/MdeModulePkg/Library/UefiHiiLib/InternalHiiLib.h @@ -48,17 +48,23 @@ extern CONST EFI_HII_DATABASE_PROTOCOL *mHiiDatabaseProt; extern CONST EFI_HII_STRING_PROTOCOL *mHiiStringProt; /** - This function check if the Hii Handle is a valid handle registered - in the HII database. + Extract Hii package list GUID for given HII handle. - @param HiiHandle The HII Handle. + If HiiHandle could not be found in the HII database, then ASSERT. + If Guid is NULL, then ASSERT. + + @param Handle Hii handle + @param Guid Package list GUID + + @retval EFI_SUCCESS Successfully extract GUID from Hii database. - @retval TRUE If it is a valid HII handle. - @retval FALSE If it is a invalid HII handle. **/ -BOOLEAN -IsHiiHandleRegistered ( - EFI_HII_HANDLE HiiHandle - ); +EFI_STATUS +EFIAPI +InternalHiiExtractGuidFromHiiHandle ( + IN EFI_HII_HANDLE Handle, + OUT EFI_GUID *Guid + ) +; #endif diff --git a/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c b/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c index 4de8009bdf..3d2e3f3f2a 100644 --- a/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c +++ b/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c @@ -1857,7 +1857,6 @@ RegisterFontPackage ( EFI_STATUS Status; EFI_HII_SIMPLE_FONT_PACKAGE_HDR *SimplifiedFont; UINT32 PackageLength; - EFI_HII_PACKAGE_LIST_HEADER *PackageList; UINT8 *Package; UINT8 *Location; EFI_HII_DATABASE_PROTOCOL *HiiDatabase; @@ -1873,7 +1872,7 @@ RegisterFontPackage ( ASSERT_EFI_ERROR (Status); // - // Add 4 bytes to the header for entire length for HiiLibPreparePackageList use only. + // Add 4 bytes to the header for entire length for HiiAddPackages use only. // // +--------------------------------+ <-- Package // | | @@ -1905,10 +1904,13 @@ RegisterFontPackage ( // // Add this simplified font package to a package list then install it. // - PackageList = HiiLibPreparePackageList (1, &mFontPackageListGuid, Package); - Status = HiiDatabase->NewPackageList (HiiDatabase, PackageList, NULL, &mHiiHandle); - ASSERT_EFI_ERROR (Status); - FreePool (PackageList); + mHiiHandle = HiiAddPackages ( + &mFontPackageListGuid, + NULL, + Package, + NULL + ); + ASSERT (mHiiHandle != NULL); FreePool (Package); } diff --git a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c index 409c8e4740..573374f59b 100644 --- a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c +++ b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c @@ -170,21 +170,21 @@ ValidatePassword ( // // Get user input password // - BufferSize = 21 * sizeof (CHAR16); - Password = AllocateZeroPool (BufferSize); - ASSERT (Password != NULL); - - Status = HiiLibGetString (PrivateData->HiiHandle[0], StringId, Password, &BufferSize); - if (EFI_ERROR (Status)) { + Password = HiiGetString (PrivateData->HiiHandle[0], StringId, NULL); + if (Password == NULL) { + return EFI_NOT_READY; + } + if (StrLen (Password) > 20) { FreePool (Password); - return Status; + return EFI_NOT_READY; } // // Validate old password // - EncodedPassword = AllocateCopyPool (21 * sizeof (CHAR16), Password); + EncodedPassword = AllocateZeroPool (21 * sizeof (CHAR16)); ASSERT (EncodedPassword != NULL); + StrnCpy (EncodedPassword, Password, 21); EncodePassword (EncodedPassword, 20 * sizeof (CHAR16)); if (CompareMem (EncodedPassword, PrivateData->Configuration.WhatIsThePassword2, 20 * sizeof (CHAR16)) != 0) { // @@ -219,6 +219,7 @@ SetPassword ( { EFI_STATUS Status; CHAR16 *Password; + CHAR16 *TempPassword; UINTN PasswordSize; DRIVER_SAMPLE_CONFIGURATION *Configuration; UINTN BufferSize; @@ -242,13 +243,19 @@ SetPassword ( // Get user input password // Password = &PrivateData->Configuration.WhatIsThePassword2[0]; - PasswordSize = sizeof (PrivateData->Configuration.WhatIsThePassword2); - + PasswordSize = sizeof (PrivateData->Configuration.WhatIsThePassword2); ZeroMem (Password, PasswordSize); - Status = HiiLibGetString (PrivateData->HiiHandle[0], StringId, Password, &BufferSize); - if (EFI_ERROR (Status)) { - return Status; + + TempPassword = HiiGetString (PrivateData->HiiHandle[0], StringId, NULL); + if (TempPassword == NULL) { + return EFI_NOT_READY; + } + if (StrLen (TempPassword) > PasswordSize / sizeof (CHAR16)) { + FreePool (TempPassword); + return EFI_NOT_READY; } + StrnCpy (Password, TempPassword, PasswordSize / sizeof (CHAR16)); + FreePool (TempPassword); // // Retrive uncommitted data from Browser @@ -786,7 +793,6 @@ DriverSampleInit ( { EFI_STATUS Status; EFI_STATUS SavedStatus; - EFI_HII_PACKAGE_LIST_HEADER *PackageList; EFI_HII_HANDLE HiiHandle[2]; EFI_SCREEN_DESCRIPTOR Screen; EFI_HII_DATABASE_PROTOCOL *HiiDatabase; @@ -878,26 +884,17 @@ DriverSampleInit ( // // Publish our HII data // - PackageList = HiiLibPreparePackageList ( - 2, - &mFormSetGuid, - DriverSampleStrings, - VfrBin - ); - if (PackageList == NULL) { + HiiHandle[0] = HiiAddPackages ( + &mFormSetGuid, + DriverHandle[0], + DriverSampleStrings, + VfrBin, + NULL + ); + if (HiiHandle[0] == NULL) { return EFI_OUT_OF_RESOURCES; } - Status = HiiDatabase->NewPackageList ( - HiiDatabase, - PackageList, - DriverHandle[0], - &HiiHandle[0] - ); - FreePool (PackageList); - if (EFI_ERROR (Status)) { - return Status; - } PrivateData->HiiHandle[0] = HiiHandle[0]; // @@ -913,26 +910,17 @@ DriverSampleInit ( PrivateData->DriverHandle[1] = DriverHandle[1]; - PackageList = HiiLibPreparePackageList ( - 2, - &mInventoryGuid, - DriverSampleStrings, - InventoryBin - ); - if (PackageList == NULL) { + HiiHandle[1] = HiiAddPackages ( + &mInventoryGuid, + DriverHandle[1], + DriverSampleStrings, + InventoryBin, + NULL + ); + if (HiiHandle[1] == NULL) { return EFI_OUT_OF_RESOURCES; } - Status = HiiDatabase->NewPackageList ( - HiiDatabase, - PackageList, - DriverHandle[1], - &HiiHandle[1] - ); - FreePool (PackageList); - if (EFI_ERROR (Status)) { - return Status; - } PrivateData->HiiHandle[1] = HiiHandle[1]; // @@ -941,9 +929,8 @@ DriverSampleInit ( // NewString = L"700 Mhz"; - Status = HiiLibSetString (HiiHandle[0], STRING_TOKEN (STR_CPU_STRING2), NewString); - if (EFI_ERROR (Status)) { - return Status; + if (HiiSetString (HiiHandle[0], STRING_TOKEN (STR_CPU_STRING2), NewString, NULL) == 0) { + return EFI_OUT_OF_RESOURCES; } // diff --git a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h index 3317e4fdc2..ded33121ec 100644 --- a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h +++ b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h @@ -34,6 +34,7 @@ Revision History #include #include +#include #include #include #include @@ -53,7 +54,7 @@ extern UINT8 VfrMyIfrNVDataBlockName[]; // // This is the generated IFR binary data for each formset defined in VFR. -// This data array is ready to be used as input of HiiLibPreparePackageList() to +// This data array is ready to be used as input of HiiAddPackages() to // create a packagelist (which contains Form packages, String packages, etc). // extern UINT8 VfrBin[]; @@ -61,7 +62,7 @@ extern UINT8 InventoryBin[]; // // This is the generated String package data for all .UNI files. -// This data array is ready to be used as input of HiiLibPreparePackageList() to +// This data array is ready to be used as input of HiiAddPackages() to // create a packagelist (which contains Form packages, String packages, etc). // extern UINT8 DriverSampleStrings[]; diff --git a/MdeModulePkg/Universal/DriverSampleDxe/DriverSampleDxe.inf b/MdeModulePkg/Universal/DriverSampleDxe/DriverSampleDxe.inf index 3ed56e934e..657d0ca78e 100644 --- a/MdeModulePkg/Universal/DriverSampleDxe/DriverSampleDxe.inf +++ b/MdeModulePkg/Universal/DriverSampleDxe/DriverSampleDxe.inf @@ -46,6 +46,7 @@ [LibraryClasses] + BaseLib MemoryAllocationLib UefiBootServicesTableLib UefiDriverEntryPoint diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.c b/MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.c index 76068e573e..0025f24bc1 100644 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.c +++ b/MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.c @@ -715,7 +715,7 @@ IScsiFormCallback ( UnicodeSPrint (PortString, (UINTN) 128, L"Port %s", ConfigFormEntry->MacString); DeviceFormTitleToken = (EFI_STRING_ID) STR_ISCSI_DEVICE_FORM_TITLE; - HiiLibSetString (Private->RegisteredHandle, DeviceFormTitleToken, PortString); + HiiSetString (Private->RegisteredHandle, DeviceFormTitleToken, PortString, NULL); IScsiConvertDeviceConfigDataToIfrNvData (ConfigFormEntry, IfrNvData); @@ -840,13 +840,13 @@ IScsiConfigUpdateForm ( // Compose the Port string and create a new EFI_STRING_ID. // UnicodeSPrint (PortString, 128, L"Port %s", ConfigFormEntry->MacString); - HiiLibNewString (mCallbackInfo->RegisteredHandle, &ConfigFormEntry->PortTitleToken, PortString); + ConfigFormEntry->PortTitleToken = HiiSetString (mCallbackInfo->RegisteredHandle, 0, PortString, NULL); // // Compose the help string of this port and create a new EFI_STRING_ID. // UnicodeSPrint (PortString, 128, L"Set the iSCSI parameters on port %s", ConfigFormEntry->MacString); - HiiLibNewString (mCallbackInfo->RegisteredHandle, &ConfigFormEntry->PortTitleHelpToken, PortString); + ConfigFormEntry->PortTitleHelpToken = HiiSetString (mCallbackInfo->RegisteredHandle, 0, PortString, NULL); InsertTailList (&mIScsiConfigFormList, &ConfigFormEntry->Link); mNumberOfIScsiDevices++; @@ -931,7 +931,6 @@ IScsiConfigFormInit ( { EFI_STATUS Status; EFI_HII_DATABASE_PROTOCOL *HiiDatabase; - EFI_HII_PACKAGE_LIST_HEADER *PackageList; ISCSI_FORM_CALLBACK_INFO *CallbackInfo; Status = gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **)&HiiDatabase); @@ -974,19 +973,16 @@ IScsiConfigFormInit ( // // Publish our HII data // - PackageList = HiiLibPreparePackageList (2, &mVendorGuid, IScsiDxeStrings, IScsiConfigDxeBin); - ASSERT (PackageList != NULL); - - Status = HiiDatabase->NewPackageList ( - HiiDatabase, - PackageList, - CallbackInfo->DriverHandle, - &CallbackInfo->RegisteredHandle - ); - FreePool (PackageList); - if (EFI_ERROR (Status)) { + CallbackInfo->RegisteredHandle = HiiAddPackages ( + &mVendorGuid, + CallbackInfo->DriverHandle, + IScsiDxeStrings, + IScsiConfigDxeBin, + NULL + ); + if (CallbackInfo->RegisteredHandle == NULL) { FreePool(CallbackInfo); - return Status; + return EFI_OUT_OF_RESOURCES; } mCallbackInfo = CallbackInfo; diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/IfrParse.c b/MdeModulePkg/Universal/SetupBrowserDxe/IfrParse.c index e612d4f855..02f5556255 100644 --- a/MdeModulePkg/Universal/SetupBrowserDxe/IfrParse.c +++ b/MdeModulePkg/Universal/SetupBrowserDxe/IfrParse.c @@ -108,17 +108,15 @@ UpdateCheckBoxStringToken ( { CHAR16 Str[MAXIMUM_VALUE_CHARACTERS]; EFI_STRING_ID Id; - EFI_STATUS Status; ASSERT (Statement != NULL); ASSERT (Statement->Operand == EFI_IFR_NUMERIC_OP); UnicodeValueToString (Str, 0, Statement->VarStoreInfo.VarName, MAXIMUM_VALUE_CHARACTERS - 1); - - Status = HiiLibNewString (FormSet->HiiHandle, &Id, Str); - if (EFI_ERROR (Status)) { - return Status; + Id = HiiSetString (FormSet->HiiHandle, 0, Str, NULL); + if (Id == 0) { + return EFI_OUT_OF_RESOURCES; } Statement->VarStoreInfo.VarName = Id; diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c b/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c index 26acccd153..f5963ce2fe 100644 --- a/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c +++ b/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c @@ -525,7 +525,6 @@ InitializeSetup ( ) { EFI_STATUS Status; - EFI_HII_PACKAGE_LIST_HEADER *PackageList; // // Locate required Hii relative protocols @@ -554,15 +553,13 @@ InitializeSetup ( // // Publish our HII data // - PackageList = HiiLibPreparePackageList (1, &gSetupBrowserGuid, SetupBrowserStrings); - ASSERT (PackageList != NULL); - Status = mHiiDatabase->NewPackageList ( - mHiiDatabase, - PackageList, - ImageHandle, - &gHiiHandle - ); - ASSERT_EFI_ERROR (Status); + gHiiHandle = HiiAddPackages ( + &gSetupBrowserGuid, + ImageHandle, + SetupBrowserStrings, + NULL + ); + ASSERT (gHiiHandle != NULL); // // Initialize Driver private data @@ -603,11 +600,9 @@ NewString ( ) { EFI_STRING_ID StringId; - EFI_STATUS Status; - StringId = 0; - Status = HiiLibNewString (HiiHandle, &StringId, String); - ASSERT_EFI_ERROR (Status); + StringId = HiiSetString (HiiHandle, 0, String, NULL); + ASSERT (StringId != 0); return StringId; } @@ -631,7 +626,8 @@ DeleteString ( CHAR16 NullChar; NullChar = CHAR_NULL; - return HiiLibSetString (HiiHandle, StringId, &NullChar); + HiiSetString (HiiHandle, StringId, &NullChar, NULL); + return EFI_SUCCESS; } @@ -651,29 +647,11 @@ GetToken ( IN EFI_HII_HANDLE HiiHandle ) { - EFI_STATUS Status; - CHAR16 *String; - UINTN BufferLength; + EFI_STRING String; - // - // Set default string size assumption at no more than 256 bytes - // - BufferLength = 0x100; - String = AllocateZeroPool (BufferLength); + String = HiiGetString (HiiHandle, Token, NULL); ASSERT (String != NULL); - - Status = HiiLibGetString (HiiHandle, Token, String, &BufferLength); - - if (Status == EFI_BUFFER_TOO_SMALL) { - FreePool (String); - String = AllocateZeroPool (BufferLength); - ASSERT (String != NULL); - - Status = HiiLibGetString (HiiHandle, Token, String, &BufferLength); - } - ASSERT_EFI_ERROR (Status); - - return String; + return (CHAR16 *) String; } diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/Setup.h b/MdeModulePkg/Universal/SetupBrowserDxe/Setup.h index b19d1ba5b9..b352482f46 100644 --- a/MdeModulePkg/Universal/SetupBrowserDxe/Setup.h +++ b/MdeModulePkg/Universal/SetupBrowserDxe/Setup.h @@ -41,6 +41,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include #include "Colors.h" diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf b/MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf index bd4ba108be..77951ee79f 100644 --- a/MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf +++ b/MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf @@ -59,7 +59,8 @@ DebugLib PrintLib HiiLib - + DevicePathLib + [Guids] gEfiIfrTianoGuid ## CONSUMES ## GUID gEfiIfrFrameworkGuid ## CONSUMES ## GUID diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/Ui.c b/MdeModulePkg/Universal/SetupBrowserDxe/Ui.c index 42074ca32b..4d2fc8871a 100644 --- a/MdeModulePkg/Universal/SetupBrowserDxe/Ui.c +++ b/MdeModulePkg/Universal/SetupBrowserDxe/Ui.c @@ -1448,6 +1448,102 @@ AdjustDateAndTimePosition ( return PadLineNumber; } +/** + Find HII Handle in the HII database associated with given Device Path. + + If DevicePath is NULL, then ASSERT. + + @param DevicePath Device Path associated with the HII package list + handle. + + @retval Handle HII package list Handle associated with the Device + Path. + @retval NULL Hii Package list handle is not found. + +**/ +EFI_HII_HANDLE +EFIAPI +DevicePathToHiiHandle ( + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath + ) +{ + EFI_STATUS Status; + EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath; + UINTN BufferSize; + UINTN HandleCount; + UINTN Index; + EFI_HANDLE Handle; + EFI_HANDLE DriverHandle; + EFI_HII_HANDLE *HiiHandles; + EFI_HII_HANDLE HiiHandle; + + ASSERT (DevicePath != NULL); + + TmpDevicePath = DevicePath; + // + // Locate Device Path Protocol handle buffer + // + Status = gBS->LocateDevicePath ( + &gEfiDevicePathProtocolGuid, + &TmpDevicePath, + &DriverHandle + ); + if (EFI_ERROR (Status) || !IsDevicePathEnd (TmpDevicePath)) { + return NULL; + } + + // + // Retrieve all HII Handles from HII database + // + BufferSize = 0x1000; + HiiHandles = AllocatePool (BufferSize); + ASSERT (HiiHandles != NULL); + Status = mHiiDatabase->ListPackageLists ( + mHiiDatabase, + EFI_HII_PACKAGE_TYPE_ALL, + NULL, + &BufferSize, + HiiHandles + ); + if (Status == EFI_BUFFER_TOO_SMALL) { + FreePool (HiiHandles); + HiiHandles = AllocatePool (BufferSize); + ASSERT (HiiHandles != NULL); + + Status = mHiiDatabase->ListPackageLists ( + mHiiDatabase, + EFI_HII_PACKAGE_TYPE_ALL, + NULL, + &BufferSize, + HiiHandles + ); + } + + if (EFI_ERROR (Status)) { + FreePool (HiiHandles); + return NULL; + } + + // + // Search Hii Handle by Driver Handle + // + HiiHandle = NULL; + HandleCount = BufferSize / sizeof (EFI_HII_HANDLE); + for (Index = 0; Index < HandleCount; Index++) { + Status = mHiiDatabase->GetPackageListHandle ( + mHiiDatabase, + HiiHandles[Index], + &Handle + ); + if (!EFI_ERROR (Status) && (Handle == DriverHandle)) { + HiiHandle = HiiHandles[Index]; + break; + } + } + + FreePool (HiiHandles); + return HiiHandle; +} /** Display menu and wait for user to select one menu option, then return it. @@ -2382,7 +2478,7 @@ UiDisplayMenu ( } } - Selection->Handle = HiiLibDevicePathToHiiHandle (DevicePath); + Selection->Handle = DevicePathToHiiHandle (DevicePath); if (Selection->Handle == NULL) { // // If target Hii Handle not found, exit diff --git a/Nt32Pkg/CpuRuntimeDxe/Cpu.c b/Nt32Pkg/CpuRuntimeDxe/Cpu.c index 9cc2aea86b..d8d63d3da9 100644 --- a/Nt32Pkg/CpuRuntimeDxe/Cpu.c +++ b/Nt32Pkg/CpuRuntimeDxe/Cpu.c @@ -437,8 +437,13 @@ Returns: // // Initialize strings to HII database // - HiiLibAddPackages (1, &gEfiProcessorProducerGuid, NULL, &HiiHandle, CpuStrings); - + HiiHandle = HiiAddPackages ( + &gEfiProcessorProducerGuid, + NULL, + CpuStrings, + NULL + ); + ASSERT (HiiHandle != NULL); CopyMem (RecordBuffer.Raw, &mCpuDataRecordHeader, HeaderSize); diff --git a/Nt32Pkg/MiscSubClassPlatformDxe/MiscSubclassDriverEntryPoint.c b/Nt32Pkg/MiscSubClassPlatformDxe/MiscSubclassDriverEntryPoint.c index 4384697757..8c2bcc19ea 100644 --- a/Nt32Pkg/MiscSubClassPlatformDxe/MiscSubclassDriverEntryPoint.c +++ b/Nt32Pkg/MiscSubClassPlatformDxe/MiscSubclassDriverEntryPoint.c @@ -180,11 +180,15 @@ Returns: // // Add our default strings to the HII database. They will be modified later. // - HiiLibAddPackages (1, &gEfiMiscSubClassGuid, NULL, &HiiHandle, MiscSubclassStrings); - - if (EFI_ERROR (Status)) { + HiiHandle = HiiAddPackages ( + &gEfiMiscSubClassGuid, + NULL, + MiscSubclassStrings, + NULL + ); + if (HiiHandle == NULL) { DEBUG ((EFI_D_ERROR, "Could not log default strings to Hii. %r\n", Status)); - return Status; + return EFI_OUT_OF_RESOURCES; } // // diff --git a/UnixPkg/CpuRuntimeDxe/Cpu.c b/UnixPkg/CpuRuntimeDxe/Cpu.c index aef2c30ccd..f2541ee994 100644 --- a/UnixPkg/CpuRuntimeDxe/Cpu.c +++ b/UnixPkg/CpuRuntimeDxe/Cpu.c @@ -451,8 +451,13 @@ Returns: // // Initialize strings to HII database // - HiiLibAddPackages (1, &gEfiProcessorProducerGuid, NULL, &HiiHandle, CpuStrings); - + HiiHandle = HiiAddPackages ( + &gEfiProcessorProducerGuid, + NULL, + CpuStrings, + NULL + ); + ASSERT (HiiHandle != NULL); CopyMem (RecordBuffer.Raw, &mCpuDataRecordHeader, HeaderSize); diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscSubclassDriverEntryPoint.c b/UnixPkg/MiscSubClassPlatformDxe/MiscSubclassDriverEntryPoint.c index de8d8ef6f0..553289668f 100644 --- a/UnixPkg/MiscSubClassPlatformDxe/MiscSubclassDriverEntryPoint.c +++ b/UnixPkg/MiscSubClassPlatformDxe/MiscSubclassDriverEntryPoint.c @@ -181,12 +181,17 @@ Returns: // // Add our default strings to the HII database. They will be modified later. // - HiiLibAddPackages (1, &gEfiMiscSubClassGuid, NULL, &HiiHandle, MiscSubclassStrings); - - if (EFI_ERROR (EfiStatus)) { + HiiHandle = HiiAddPackages ( + &gEfiMiscSubClassGuid, + NULL, + MiscSubclassStrings, + NULL + ); + if (HiiHandle == NULL) { DEBUG ((EFI_D_ERROR, "Could not log default strings to Hii. %r\n", EfiStatus)); - return EfiStatus; + return EFI_OUT_OF_RESOURCES; } + // // // -- 2.39.2