From f8d18bada5af6d1f89cfc3cd50580d590a641e50 Mon Sep 17 00:00:00 2001 From: qwang12 Date: Sun, 21 Sep 2008 08:50:52 +0000 Subject: [PATCH] HiiLibGetCurrentLanguage returns the current UEFI variable "PlatformLang" (if this variable does not exist, a default value is returned). This function is called by HiiDatabase itself. Now, HiiLibGetCurrentLanguage is in HiiLib. Because of this, we can't add location of Hii protoocol in the library constructor of HiiLib. This cause Hii Database driver never get loaded (circular dependency). By moving HiiLibGetCurrentLanguage to UefiLib, library constructor (depex) can be added back to HiiLib to make sure the execution order is correct. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@5938 6f19259b-4bc3-4df7-8a09-765794883524 --- MdePkg/Include/Library/HiiLib.h | 26 ------------ MdePkg/Include/Library/UefiLib.h | 28 +++++++++++++ MdePkg/Library/HiiLib/HiiLanguage.c | 50 ------------------------ MdePkg/Library/HiiLib/HiiLib.c | 44 ++++++++------------- MdePkg/Library/HiiLib/HiiLib.inf | 12 +++--- MdePkg/Library/HiiLib/HiiString.c | 2 +- MdePkg/Library/HiiLib/InternalHiiLib.h | 13 +----- MdePkg/Library/UefiLib/UefiLib.c | 46 ++++++++++++++++++++++ MdePkg/Library/UefiLib/UefiLib.inf | 7 +++- MdePkg/Library/UefiLib/UefiLibInternal.h | 2 + 10 files changed, 108 insertions(+), 122 deletions(-) diff --git a/MdePkg/Include/Library/HiiLib.h b/MdePkg/Include/Library/HiiLib.h index 59e1780a99..36fd8f602c 100644 --- a/MdePkg/Include/Library/HiiLib.h +++ b/MdePkg/Include/Library/HiiLib.h @@ -15,11 +15,6 @@ #ifndef __HII_LIB_H__ #define __HII_LIB_H__ -/// -/// Limited buffer size recommended by RFC3066 -/// (42 characters plus a NULL terminator) -/// -#define RFC_3066_ENTRY_SIZE (42 + 1) #define ISO_639_2_ENTRY_SIZE 3 @@ -288,27 +283,6 @@ HiiLibDevicePathToHiiHandle ( ); -/** - Determine what is the current language setting. The space reserved for Lang - must be at least RFC_3066_ENTRY_SIZE bytes; - - If Lang is NULL, then ASSERT. - - @param Lang Pointer of system language. Lang will always be filled with - a valid RFC 3066 language string. If "PlatformLang" is not - set in the system, the default language specifed by PcdUefiVariableDefaultPlatformLang - is returned. - - @return EFI_SUCCESS If the EFI Variable with "PlatformLang" is set and return in Lang. - @return EFI_NOT_FOUND If the EFI Variable with "PlatformLang" is not set, but a valid default language is return in Lang. - -**/ -EFI_STATUS -EFIAPI -HiiLibGetCurrentLanguage ( - OUT CHAR8 *Lang - ); - /** Get next language from language code list (with separator ';'). diff --git a/MdePkg/Include/Library/UefiLib.h b/MdePkg/Include/Library/UefiLib.h index 13ab258ebe..fa04704c33 100644 --- a/MdePkg/Include/Library/UefiLib.h +++ b/MdePkg/Include/Library/UefiLib.h @@ -22,6 +22,12 @@ #include #include +/// +/// Limited buffer size recommended by RFC3066 +/// (42 characters plus a NULL terminator) +/// +#define RFC_3066_ENTRY_SIZE (42 + 1) + /// /// Unicode String Table /// @@ -986,4 +992,26 @@ EfiLibInstallAllDriverProtocols2 ( IN CONST EFI_DRIVER_DIAGNOSTICS2_PROTOCOL *DriverDiagnostics2 OPTIONAL ); +/** + Determine what is the current language setting. The space reserved for Lang + must be at least RFC_3066_ENTRY_SIZE bytes; + + If Lang is NULL, then ASSERT. + + @param Lang Pointer of system language. Lang will always be filled with + a valid RFC 3066 language string. If "PlatformLang" is not + set in the system, the default language specifed by PcdUefiVariableDefaultPlatformLang + is returned. + + @return EFI_SUCCESS If the EFI Variable with "PlatformLang" is set and return in Lang. + @return EFI_NOT_FOUND If the EFI Variable with "PlatformLang" is not set, but a valid default language is return in Lang. + +**/ +EFI_STATUS +EFIAPI +GetCurrentLanguage ( + OUT CHAR8 *Lang + ); + + #endif diff --git a/MdePkg/Library/HiiLib/HiiLanguage.c b/MdePkg/Library/HiiLib/HiiLanguage.c index 8c03bb993a..147e5a3942 100644 --- a/MdePkg/Library/HiiLib/HiiLanguage.c +++ b/MdePkg/Library/HiiLib/HiiLanguage.c @@ -15,52 +15,6 @@ #include "InternalHiiLib.h" -/** - Determine what is the current language setting. The space reserved for Lang - must be at least RFC_3066_ENTRY_SIZE bytes; - - If Lang is NULL, then ASSERT. - - @param Lang Pointer of system language. Lang will always be filled with - a valid RFC 3066 language string. If "PlatformLang" is not - set in the system, the default language specifed by PcdUefiVariableDefaultPlatformLang - is returned. - - @return EFI_SUCCESS If the EFI Variable with "PlatformLang" is set and return in Lang. - @return EFI_NOT_FOUND If the EFI Variable with "PlatformLang" is not set, but a valid default language is return in Lang. - -**/ -EFI_STATUS -EFIAPI -HiiLibGetCurrentLanguage ( - OUT CHAR8 *Lang - ) -{ - EFI_STATUS Status; - UINTN Size; - - ASSERT (Lang != NULL); - - // - // Get current language setting - // - Size = RFC_3066_ENTRY_SIZE; - Status = gRT->GetVariable ( - L"PlatformLang", - &gEfiGlobalVariableGuid, - NULL, - &Size, - Lang - ); - - if (EFI_ERROR (Status)) { - AsciiStrCpy (Lang, (CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLang)); - } - - return Status; -} - - /** Get next language from language code list (with separator ';'). @@ -136,8 +90,6 @@ HiiLibGetSupportedLanguages ( return NULL; } - LocateHiiProtocols (); - Status = mHiiStringProt->GetLanguages (mHiiStringProt, HiiHandle, LanguageString, &BufferSize); if (Status == EFI_BUFFER_TOO_SMALL) { @@ -232,8 +184,6 @@ HiiLibGetSupportedSecondaryLanguages ( return NULL; } - LocateHiiProtocols (); - Status = mHiiStringProt->GetSecondaryLanguages (mHiiStringProt, HiiHandle, FirstLanguage, LanguageString, &BufferSize); if (Status == EFI_BUFFER_TOO_SMALL) { diff --git a/MdePkg/Library/HiiLib/HiiLib.c b/MdePkg/Library/HiiLib/HiiLib.c index d5d6670405..cee31b20ae 100644 --- a/MdePkg/Library/HiiLib/HiiLib.c +++ b/MdePkg/Library/HiiLib/HiiLib.c @@ -18,29 +18,35 @@ CONST EFI_HII_DATABASE_PROTOCOL *mHiiDatabaseProt = NULL; CONST EFI_HII_STRING_PROTOCOL *mHiiStringProt = NULL; /** - This function locate Hii relative protocols for later usage. + + The constructor function caches the protocol pointer of HII Database Protocol + and Hii String Protocol. + + It will ASSERT() if either of the protocol can't be located. + + @param ImageHandle The firmware allocated handle for the EFI image. + @param SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. **/ -VOID -LocateHiiProtocols ( - VOID +EFI_STATUS +EFIAPI +HiiLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; - if (mHiiStringProt != NULL && mHiiDatabaseProt != NULL) { - // - // Only need to initialize the protocol instance once. - // - return; - } - Status = gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **) &mHiiDatabaseProt); ASSERT_EFI_ERROR (Status); Status = gBS->LocateProtocol (&gEfiHiiStringProtocolGuid, NULL, (VOID **) &mHiiStringProt); ASSERT_EFI_ERROR (Status); + + return EFI_SUCCESS; } @@ -213,8 +219,6 @@ HiiLibAddPackages ( ASSERT (HiiHandle != NULL); - LocateHiiProtocols (); - VA_START (Args, HiiHandle); PackageListHeader = InternalHiiLibPreparePackages (NumberOfPackages, GuidId, Args); @@ -250,8 +254,6 @@ HiiLibRemovePackages ( EFI_STATUS Status; ASSERT (IsHiiHandleRegistered (HiiHandle)); - LocateHiiProtocols (); - Status = mHiiDatabaseProt->RemovePackageList (mHiiDatabaseProt, HiiHandle); ASSERT_EFI_ERROR (Status); } @@ -287,8 +289,6 @@ HiiLibGetHiiHandles ( BufferLength = 0; - LocateHiiProtocols (); - // // Try to find the actual buffer size for HiiHandle Buffer. // @@ -353,8 +353,6 @@ HiiLibExtractGuidFromHiiHandle ( BufferSize = 0; HiiPackageList = NULL; - LocateHiiProtocols (); - Status = mHiiDatabaseProt->ExportPackageLists (mHiiDatabaseProt, Handle, &BufferSize, HiiPackageList); ASSERT (Status != EFI_NOT_FOUND); @@ -450,8 +448,6 @@ HiiLibDevicePathToHiiHandle ( return NULL; } - LocateHiiProtocols (); - // // Retrieve all Hii Handles from HII database // @@ -538,8 +534,6 @@ HiiLibExportPackageLists ( ASSERT (PackageListSize != NULL); ASSERT (PackageListHeader != NULL); - LocateHiiProtocols (); - if (Handle != NULL) { ASSERT (IsHiiHandleRegistered (Handle)); } @@ -597,8 +591,6 @@ HiiLibListPackageLists ( *HandleBufferLength = 0; *HandleBuffer = NULL; - LocateHiiProtocols (); - Status = mHiiDatabaseProt->ListPackageLists ( mHiiDatabaseProt, PackageType, @@ -652,8 +644,6 @@ IsHiiHandleRegistered ( HiiPackageList = NULL; BufferSize = 0; - LocateHiiProtocols (); - Status = mHiiDatabaseProt->ExportPackageLists ( mHiiDatabaseProt, HiiHandle, diff --git a/MdePkg/Library/HiiLib/HiiLib.inf b/MdePkg/Library/HiiLib/HiiLib.inf index 9713f32c7d..db3769a030 100644 --- a/MdePkg/Library/HiiLib/HiiLib.inf +++ b/MdePkg/Library/HiiLib/HiiLib.inf @@ -24,6 +24,8 @@ EDK_RELEASE_VERSION = 0x00020000 EFI_SPECIFICATION_VERSION = 0x00020000 + CONSTRUCTOR = HiiLibConstructor + # # VALID_ARCHITECTURES = IA32 X64 IPF EBC # @@ -46,14 +48,14 @@ UefiRuntimeServicesTableLib UefiBootServicesTableLib DevicePathLib + UefiLib [Protocols] gEfiHiiDatabaseProtocolGuid # ALWAYS_CONSUMED gEfiHiiStringProtocolGuid # ALWAYS_CONSUMED gEfiDevicePathProtocolGuid - -[Guids] - gEfiGlobalVariableGuid -[Pcd] - gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultPlatformLang +[Depex] + gEfiHiiDatabaseProtocolGuid AND + gEfiHiiStringProtocolGuid + diff --git a/MdePkg/Library/HiiLib/HiiString.c b/MdePkg/Library/HiiLib/HiiString.c index ed816c1b3b..fbeb2dbdb6 100644 --- a/MdePkg/Library/HiiLib/HiiString.c +++ b/MdePkg/Library/HiiLib/HiiString.c @@ -251,7 +251,7 @@ HiiLibGetString ( ASSERT (!(*StringSize != 0 && String == NULL)); ASSERT (IsHiiHandleRegistered (PackageList)); - HiiLibGetCurrentLanguage (CurrentLang); + GetCurrentLanguage (CurrentLang); Status = mHiiStringProt->GetString ( mHiiStringProt, diff --git a/MdePkg/Library/HiiLib/InternalHiiLib.h b/MdePkg/Library/HiiLib/InternalHiiLib.h index f9294eb876..255939152a 100644 --- a/MdePkg/Library/HiiLib/InternalHiiLib.h +++ b/MdePkg/Library/HiiLib/InternalHiiLib.h @@ -21,8 +21,6 @@ #include #include -#include - #include #include #include @@ -32,6 +30,7 @@ #include #include #include +#include #define HII_LIB_DEFAULT_STRING_SIZE 0x200 @@ -53,14 +52,4 @@ IsHiiHandleRegistered ( EFI_HII_HANDLE HiiHandle ); -/** - - This function locate Hii relative protocols for later usage. - -**/ -VOID -LocateHiiProtocols ( - VOID - ); - #endif diff --git a/MdePkg/Library/UefiLib/UefiLib.c b/MdePkg/Library/UefiLib/UefiLib.c index a58878e5d3..1acccb0522 100644 --- a/MdePkg/Library/UefiLib/UefiLib.c +++ b/MdePkg/Library/UefiLib/UefiLib.c @@ -1221,4 +1221,50 @@ FreeUnicodeStringTable ( return EFI_SUCCESS; } +/** + Determine what is the current language setting. The space reserved for Lang + must be at least RFC_3066_ENTRY_SIZE bytes; + + If Lang is NULL, then ASSERT. + + @param Lang Pointer of system language. Lang will always be filled with + a valid RFC 3066 language string. If "PlatformLang" is not + set in the system, the default language specifed by PcdUefiVariableDefaultPlatformLang + is returned. + + @return EFI_SUCCESS If the EFI Variable with "PlatformLang" is set and return in Lang. + @return EFI_NOT_FOUND If the EFI Variable with "PlatformLang" is not set, but a valid default language is return in Lang. + +**/ +EFI_STATUS +EFIAPI +GetCurrentLanguage ( + OUT CHAR8 *Lang + ) +{ + EFI_STATUS Status; + UINTN Size; + + ASSERT (Lang != NULL); + + // + // Get current language setting + // + Size = RFC_3066_ENTRY_SIZE; + Status = gRT->GetVariable ( + L"PlatformLang", + &gEfiGlobalVariableGuid, + NULL, + &Size, + Lang + ); + + if (EFI_ERROR (Status)) { + AsciiStrCpy (Lang, (CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLang)); + } + + return Status; +} + + diff --git a/MdePkg/Library/UefiLib/UefiLib.inf b/MdePkg/Library/UefiLib/UefiLib.inf index b3006ab11e..04c61c83f1 100644 --- a/MdePkg/Library/UefiLib/UefiLib.inf +++ b/MdePkg/Library/UefiLib/UefiLib.inf @@ -53,7 +53,7 @@ BaseMemoryLib BaseLib UefiBootServicesTableLib - + UefiRuntimeServicesTableLib [Guids] gEfiEventReadyToBootGuid # ALWAYS_CONSUMED @@ -72,6 +72,7 @@ [Pcd.common] gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize + gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultPlatformLang [FeaturePcd.common] gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnosticsDisable @@ -79,3 +80,7 @@ gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnostics2Disable gEfiMdePkgTokenSpaceGuid.PcdComponentName2Disable +[Guids] + gEfiGlobalVariableGuid + + diff --git a/MdePkg/Library/UefiLib/UefiLibInternal.h b/MdePkg/Library/UefiLib/UefiLibInternal.h index 886287f25d..ff575f69fc 100644 --- a/MdePkg/Library/UefiLib/UefiLibInternal.h +++ b/MdePkg/Library/UefiLib/UefiLibInternal.h @@ -26,8 +26,10 @@ #include #include +#include #include #include +#include #include #include #include