/** @file\r
- The UEFI Library provides functions and macros that simplify the development of \r
- UEFI Drivers and UEFI Applications. These functions and macros help manage EFI \r
- events, build simple locks utilizing EFI Task Priority Levels (TPLs), install \r
- EFI Driver Model related protocols, manage Unicode string tables for UEFI Drivers, \r
+ The UEFI Library provides functions and macros that simplify the development of\r
+ UEFI Drivers and UEFI Applications. These functions and macros help manage EFI\r
+ events, build simple locks utilizing EFI Task Priority Levels (TPLs), install\r
+ EFI Driver Model related protocols, manage Unicode string tables for UEFI Drivers,\r
and print messages on the console output and standard error devices.\r
\r
- Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
- This program and the accompanying materials\r
- are licensed and made available under the terms and conditions of the BSD License\r
- which accompanies this distribution. The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php.\r
-\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+ Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
-\r
#include "UefiLibInternal.h"\r
\r
/**\r
- Empty constructor function that is required to resolve dependencies between \r
+ Empty constructor function that is required to resolve dependencies between\r
libraries.\r
- \r
+\r
** DO NOT REMOVE **\r
- \r
+\r
@param ImageHandle The firmware allocated handle for the EFI image.\r
@param SystemTable A pointer to the EFI System Table.\r
- \r
+\r
@retval EFI_SUCCESS The constructor executed correctly.\r
\r
**/\r
UINT32 Name1;\r
UINT32 Name2;\r
\r
- Name1 = ReadUnaligned24 ((CONST UINT32 *) Language1);\r
- Name2 = ReadUnaligned24 ((CONST UINT32 *) Language2);\r
+ Name1 = ReadUnaligned24 ((CONST UINT32 *)Language1);\r
+ Name2 = ReadUnaligned24 ((CONST UINT32 *)Language2);\r
\r
- return (BOOLEAN) (Name1 == Name2);\r
+ return (BOOLEAN)(Name1 == Name2);\r
}\r
\r
/**\r
Retrieves a pointer to the system configuration table from the EFI System Table\r
based on a specified GUID.\r
- \r
+\r
This function searches the list of configuration tables stored in the EFI System Table\r
for a table with a GUID that matches TableGuid. If a match is found, then a pointer to\r
the configuration table is returned in Table., and EFI_SUCCESS is returned. If a matching GUID\r
ASSERT (Table != NULL);\r
\r
SystemTable = gST;\r
- *Table = NULL;\r
+ *Table = NULL;\r
for (Index = 0; Index < SystemTable->NumberOfTableEntries; Index++) {\r
if (CompareGuid (TableGuid, &(SystemTable->ConfigurationTable[Index].VendorGuid))) {\r
*Table = SystemTable->ConfigurationTable[Index].VendorTable;\r
no instances of ProtocolGuid in the handle database at the time this function is invoked,\r
then the notification function is still executed one time. In addition, every time a protocol\r
of type ProtocolGuid instance is installed or reinstalled, the notification function is also\r
- executed. This function returns the notification event that was created. \r
+ executed. This function returns the notification event that was created.\r
If ProtocolGuid is NULL, then ASSERT().\r
If NotifyTpl is not a legal TPL value, then ASSERT().\r
If NotifyFunction is NULL, then ASSERT().\r
@param NotifyContext The context parameter to pass to NotifyFunction.\r
@param Registration A pointer to a memory location to receive the registration value.\r
This value is passed to LocateHandle() to obtain new handles that\r
- have been added that support the ProtocolGuid-specified protocol. \r
+ have been added that support the ProtocolGuid-specified protocol.\r
\r
@return The notification event that was created.\r
\r
**/\r
EFI_EVENT\r
EFIAPI\r
-EfiCreateProtocolNotifyEvent(\r
+EfiCreateProtocolNotifyEvent (\r
IN EFI_GUID *ProtocolGuid,\r
IN EFI_TPL NotifyTpl,\r
IN EFI_EVENT_NOTIFY NotifyFunction,\r
- IN VOID *NotifyContext, OPTIONAL\r
+ IN VOID *NotifyContext OPTIONAL,\r
OUT VOID **Registration\r
)\r
{\r
\r
This function creates an event using NotifyTpl, NoifyFunction, and NotifyContext.\r
This event is signaled with EfiNamedEventSignal(). This provides the ability for one or more\r
- listeners on the same event named by the GUID specified by Name. \r
+ listeners on the same event named by the GUID specified by Name.\r
If Name is NULL, then ASSERT().\r
If NotifyTpl is not a legal TPL value, then ASSERT().\r
If NotifyFunction is NULL, then ASSERT().\r
@param Name Supplies the GUID name of the event.\r
@param NotifyTpl Supplies the task priority level of the event notifications.\r
@param NotifyFunction Supplies the function to notify when the event is signaled.\r
- @param NotifyContext The context parameter to pass to NotifyFunction. \r
+ @param NotifyContext The context parameter to pass to NotifyFunction.\r
@param Registration A pointer to a memory location to receive the registration value.\r
\r
@retval EFI_SUCCESS A named event was created.\r
IN CONST EFI_GUID *Name,\r
IN EFI_TPL NotifyTpl,\r
IN EFI_EVENT_NOTIFY NotifyFunction,\r
- IN CONST VOID *NotifyContext, OPTIONAL\r
+ IN CONST VOID *NotifyContext OPTIONAL,\r
OUT VOID *Registration OPTIONAL\r
)\r
{\r
ASSERT (Name != NULL);\r
ASSERT (NotifyFunction != NULL);\r
ASSERT (NotifyTpl <= TPL_HIGH_LEVEL);\r
- \r
+\r
//\r
// Create event\r
//\r
EVT_NOTIFY_SIGNAL,\r
NotifyTpl,\r
NotifyFunction,\r
- (VOID *) NotifyContext,\r
+ (VOID *)NotifyContext,\r
&Event\r
);\r
ASSERT_EFI_ERROR (Status);\r
//\r
\r
Status = gBS->RegisterProtocolNotify (\r
- (EFI_GUID *) Name,\r
+ (EFI_GUID *)Name,\r
Event,\r
RegistrationLocal\r
);\r
EFI_STATUS Status;\r
EFI_HANDLE Handle;\r
\r
- ASSERT(Name != NULL);\r
+ ASSERT (Name != NULL);\r
\r
Handle = NULL;\r
Status = gBS->InstallProtocolInterface (\r
&Handle,\r
- (EFI_GUID *) Name,\r
+ (EFI_GUID *)Name,\r
EFI_NATIVE_INTERFACE,\r
NULL\r
);\r
\r
Status = gBS->UninstallProtocolInterface (\r
Handle,\r
- (EFI_GUID *) Name,\r
+ (EFI_GUID *)Name,\r
NULL\r
);\r
ASSERT_EFI_ERROR (Status);\r
return Status;\r
}\r
\r
-/** \r
+/**\r
+ Signals an event group by placing a new event in the group temporarily and\r
+ signaling it.\r
+\r
+ @param[in] EventGroup Supplies the unique identifier of the event\r
+ group to signal.\r
+\r
+ @retval EFI_SUCCESS The event group was signaled successfully.\r
+ @retval EFI_INVALID_PARAMETER EventGroup is NULL.\r
+ @return Error codes that report problems about event\r
+ creation or signaling.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EfiEventGroupSignal (\r
+ IN CONST EFI_GUID *EventGroup\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_EVENT Event;\r
+\r
+ if (EventGroup == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ Status = gBS->CreateEventEx (\r
+ EVT_NOTIFY_SIGNAL,\r
+ TPL_CALLBACK,\r
+ EfiEventEmptyFunction,\r
+ NULL,\r
+ EventGroup,\r
+ &Event\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ Status = gBS->SignalEvent (Event);\r
+ gBS->CloseEvent (Event);\r
+\r
+ return Status;\r
+}\r
+\r
+/**\r
+ An empty function that can be used as NotifyFunction parameter of\r
+ CreateEvent() or CreateEventEx().\r
+\r
+ @param Event Event whose notification function is being invoked.\r
+ @param Context The pointer to the notification function's context,\r
+ which is implementation-dependent.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+EfiEventEmptyFunction (\r
+ IN EFI_EVENT Event,\r
+ IN VOID *Context\r
+ )\r
+{\r
+}\r
+\r
+/**\r
Returns the current TPL.\r
\r
- This function returns the current TPL. There is no EFI service to directly \r
- retrieve the current TPL. Instead, the RaiseTPL() function is used to raise \r
- the TPL to TPL_HIGH_LEVEL. This will return the current TPL. The TPL level \r
- can then immediately be restored back to the current TPL level with a call \r
+ This function returns the current TPL. There is no EFI service to directly\r
+ retrieve the current TPL. Instead, the RaiseTPL() function is used to raise\r
+ the TPL to TPL_HIGH_LEVEL. This will return the current TPL. The TPL level\r
+ can then immediately be restored back to the current TPL level with a call\r
to RestoreTPL().\r
\r
@return The current TPL.\r
VOID\r
)\r
{\r
- EFI_TPL Tpl;\r
+ EFI_TPL Tpl;\r
\r
Tpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r
gBS->RestoreTPL (Tpl);\r
return Tpl;\r
}\r
\r
-\r
/**\r
Initializes a basic mutual exclusion lock.\r
\r
- This function initializes a basic mutual exclusion lock to the released state \r
- and returns the lock. Each lock provides mutual exclusion access at its task \r
+ This function initializes a basic mutual exclusion lock to the released state\r
+ and returns the lock. Each lock provides mutual exclusion access at its task\r
priority level. Since there is no preemption or multiprocessor support in EFI,\r
acquiring the lock only consists of raising to the locks TPL.\r
If Lock is NULL, then ASSERT().\r
EFIAPI\r
EfiInitializeLock (\r
IN OUT EFI_LOCK *Lock,\r
- IN EFI_TPL Priority\r
+ IN EFI_TPL Priority\r
)\r
{\r
ASSERT (Lock != NULL);\r
ASSERT (Priority <= TPL_HIGH_LEVEL);\r
\r
- Lock->Tpl = Priority;\r
- Lock->OwnerTpl = TPL_APPLICATION;\r
- Lock->Lock = EfiLockReleased ;\r
+ Lock->Tpl = Priority;\r
+ Lock->OwnerTpl = TPL_APPLICATION;\r
+ Lock->Lock = EfiLockReleased;\r
return Lock;\r
}\r
\r
/**\r
Acquires ownership of a lock.\r
\r
- This function raises the system's current task priority level to the task \r
- priority level of the mutual exclusion lock. Then, it places the lock in the \r
+ This function raises the system's current task priority level to the task\r
+ priority level of the mutual exclusion lock. Then, it places the lock in the\r
acquired state.\r
If Lock is NULL, then ASSERT().\r
If Lock is not initialized, then ASSERT().\r
IN EFI_LOCK *Lock\r
)\r
{\r
-\r
ASSERT (Lock != NULL);\r
ASSERT (Lock->Lock != EfiLockUninitialized);\r
\r
/**\r
Releases ownership of a lock.\r
\r
- This function transitions a mutual exclusion lock from the acquired state to \r
- the released state, and restores the system's task priority level to its \r
+ This function transitions a mutual exclusion lock from the acquired state to\r
+ the released state, and restores the system's task priority level to its\r
previous level.\r
If Lock is NULL, then ASSERT().\r
If Lock is not initialized, then ASSERT().\r
IN EFI_LOCK *Lock\r
)\r
{\r
- EFI_TPL Tpl;\r
+ EFI_TPL Tpl;\r
\r
ASSERT (Lock != NULL);\r
ASSERT (Lock->Lock == EfiLockAcquired);\r
currently managing the controller specified by ControllerHandle. This test\r
is performed by evaluating if the the protocol specified by ProtocolGuid is\r
present on ControllerHandle and is was opened by DriverBindingHandle with an\r
- attribute of EFI_OPEN_PROTOCOL_BY_DRIVER. \r
+ attribute of EFI_OPEN_PROTOCOL_BY_DRIVER.\r
If ProtocolGuid is NULL, then ASSERT().\r
\r
@param ControllerHandle A handle for a controller to test.\r
EFI_STATUS\r
EFIAPI\r
EfiTestManagedDevice (\r
- IN CONST EFI_HANDLE ControllerHandle,\r
- IN CONST EFI_HANDLE DriverBindingHandle,\r
- IN CONST EFI_GUID *ProtocolGuid\r
+ IN CONST EFI_HANDLE ControllerHandle,\r
+ IN CONST EFI_HANDLE DriverBindingHandle,\r
+ IN CONST EFI_GUID *ProtocolGuid\r
)\r
{\r
- EFI_STATUS Status;\r
- VOID *ManagedInterface;\r
+ EFI_STATUS Status;\r
+ VOID *ManagedInterface;\r
\r
ASSERT (ProtocolGuid != NULL);\r
\r
Status = gBS->OpenProtocol (\r
ControllerHandle,\r
- (EFI_GUID *) ProtocolGuid,\r
+ (EFI_GUID *)ProtocolGuid,\r
&ManagedInterface,\r
DriverBindingHandle,\r
ControllerHandle,\r
if (!EFI_ERROR (Status)) {\r
gBS->CloseProtocol (\r
ControllerHandle,\r
- (EFI_GUID *) ProtocolGuid,\r
+ (EFI_GUID *)ProtocolGuid,\r
DriverBindingHandle,\r
ControllerHandle\r
);\r
ChildHandle with an attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
If ProtocolGuid is NULL, then ASSERT().\r
\r
- @param ControllerHandle A handle for a (parent) controller to test. \r
+ @param ControllerHandle A handle for a (parent) controller to test.\r
@param ChildHandle A child handle to test.\r
@param ProtocolGuid Supplies the protocol that the child controller\r
- opens on its parent controller. \r
+ opens on its parent controller.\r
\r
@retval EFI_SUCCESS ChildHandle is a child of the ControllerHandle.\r
@retval EFI_UNSUPPORTED ChildHandle is not a child of the\r
EFI_STATUS\r
EFIAPI\r
EfiTestChildHandle (\r
- IN CONST EFI_HANDLE ControllerHandle,\r
- IN CONST EFI_HANDLE ChildHandle,\r
- IN CONST EFI_GUID *ProtocolGuid\r
+ IN CONST EFI_HANDLE ControllerHandle,\r
+ IN CONST EFI_HANDLE ChildHandle,\r
+ IN CONST EFI_GUID *ProtocolGuid\r
)\r
{\r
- EFI_STATUS Status;\r
- EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;\r
- UINTN EntryCount;\r
- UINTN Index;\r
+ EFI_STATUS Status;\r
+ EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;\r
+ UINTN EntryCount;\r
+ UINTN Index;\r
\r
ASSERT (ProtocolGuid != NULL);\r
\r
//\r
Status = gBS->OpenProtocolInformation (\r
ControllerHandle,\r
- (EFI_GUID *) ProtocolGuid,\r
+ (EFI_GUID *)ProtocolGuid,\r
&OpenInfoBuffer,\r
&EntryCount\r
);\r
Status = EFI_UNSUPPORTED;\r
for (Index = 0; Index < EntryCount; Index++) {\r
if ((OpenInfoBuffer[Index].ControllerHandle == ChildHandle) &&\r
- (OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {\r
+ ((OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0))\r
+ {\r
Status = EFI_SUCCESS;\r
break;\r
}\r
return Status;\r
}\r
\r
+/**\r
+ This function checks the supported languages list for a target language,\r
+ This only supports RFC 4646 Languages.\r
+\r
+ @param SupportedLanguages The supported languages\r
+ @param TargetLanguage The target language\r
+\r
+ @retval Returns EFI_SUCCESS if the language is supported,\r
+ EFI_UNSUPPORTED otherwise\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+IsLanguageSupported (\r
+ IN CONST CHAR8 *SupportedLanguages,\r
+ IN CONST CHAR8 *TargetLanguage\r
+ )\r
+{\r
+ UINTN Index;\r
+\r
+ while (*SupportedLanguages != 0) {\r
+ for (Index = 0; SupportedLanguages[Index] != 0 && SupportedLanguages[Index] != ';'; Index++) {\r
+ }\r
+\r
+ if ((AsciiStrnCmp (SupportedLanguages, TargetLanguage, Index) == 0) && (TargetLanguage[Index] == 0)) {\r
+ return EFI_SUCCESS;\r
+ }\r
+\r
+ SupportedLanguages += Index;\r
+ for ( ; *SupportedLanguages != 0 && *SupportedLanguages == ';'; SupportedLanguages++) {\r
+ }\r
+ }\r
+\r
+ return EFI_UNSUPPORTED;\r
+}\r
+\r
/**\r
This function looks up a Unicode string in UnicodeStringTable.\r
\r
UnicodeStringTable that matches the language code specified by Language, then it\r
is returned in UnicodeString.\r
\r
- @param Language A pointer to the ISO 639-2 language code for the \r
+ @param Language A pointer to the ISO 639-2 language code for the\r
Unicode string to look up and return.\r
- @param SupportedLanguages A pointer to the set of ISO 639-2 language codes \r
- that the Unicode string table supports. Language \r
+ @param SupportedLanguages A pointer to the set of ISO 639-2 language codes\r
+ that the Unicode string table supports. Language\r
must be a member of this set.\r
@param UnicodeStringTable A pointer to the table of Unicode strings.\r
@param UnicodeString A pointer to the Unicode string from UnicodeStringTable\r
that matches the language specified by Language.\r
\r
- @retval EFI_SUCCESS The Unicode string that matches the language \r
+ @retval EFI_SUCCESS The Unicode string that matches the language\r
specified by Language was found\r
- in the table of Unicode strings UnicodeStringTable, \r
+ in the table of Unicode strings UnicodeStringTable,\r
and it was returned in UnicodeString.\r
@retval EFI_INVALID_PARAMETER Language is NULL.\r
@retval EFI_INVALID_PARAMETER UnicodeString is NULL.\r
@retval EFI_UNSUPPORTED SupportedLanguages is NULL.\r
@retval EFI_UNSUPPORTED UnicodeStringTable is NULL.\r
- @retval EFI_UNSUPPORTED The language specified by Language is not a \r
+ @retval EFI_UNSUPPORTED The language specified by Language is not a\r
member of SupportedLanguages.\r
- @retval EFI_UNSUPPORTED The language specified by Language is not \r
+ @retval EFI_UNSUPPORTED The language specified by Language is not\r
supported by UnicodeStringTable.\r
\r
**/\r
//\r
// Make sure the parameters are valid\r
//\r
- if (Language == NULL || UnicodeString == NULL) {\r
+ if ((Language == NULL) || (UnicodeString == NULL)) {\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
// If there are no supported languages, or the Unicode String Table is empty, then the\r
// Unicode String specified by Language is not supported by this Unicode String Table\r
//\r
- if (SupportedLanguages == NULL || UnicodeStringTable == NULL) {\r
+ if ((SupportedLanguages == NULL) || (UnicodeStringTable == NULL)) {\r
return EFI_UNSUPPORTED;\r
}\r
\r
//\r
while (*SupportedLanguages != 0) {\r
if (CompareIso639LanguageCode (Language, SupportedLanguages)) {\r
-\r
//\r
// Search the Unicode String Table for the matching Language specifier\r
//\r
while (UnicodeStringTable->Language != NULL) {\r
if (CompareIso639LanguageCode (Language, UnicodeStringTable->Language)) {\r
-\r
//\r
// A matching string was found, so return it\r
//\r
return EFI_UNSUPPORTED;\r
}\r
\r
-\r
-\r
/**\r
This function looks up a Unicode string in UnicodeStringTable.\r
\r
return. If Iso639Language is TRUE, then this ASCII string is\r
not assumed to be Null-terminated, and only the first three\r
characters are used. If Iso639Language is FALSE, then this ASCII\r
- string must be Null-terminated. \r
+ string must be Null-terminated.\r
@param SupportedLanguages A pointer to a Null-terminated ASCII string that contains a\r
set of ISO 639-2 or RFC 4646 language codes that the Unicode\r
string table supports. Language must be a member of this set.\r
@retval EFI_SUCCESS The Unicode string that matches the language specified by Language\r
was found in the table of Unicode strings UnicodeStringTable, and\r
it was returned in UnicodeString.\r
- @retval EFI_INVALID_PARAMETER Language is NULL. \r
- @retval EFI_INVALID_PARAMETER UnicodeString is NULL. \r
- @retval EFI_UNSUPPORTED SupportedLanguages is NULL. \r
- @retval EFI_UNSUPPORTED UnicodeStringTable is NULL. \r
- @retval EFI_UNSUPPORTED The language specified by Language is not a member of SupportedLanguages. \r
+ @retval EFI_INVALID_PARAMETER Language is NULL.\r
+ @retval EFI_INVALID_PARAMETER UnicodeString is NULL.\r
+ @retval EFI_UNSUPPORTED SupportedLanguages is NULL.\r
+ @retval EFI_UNSUPPORTED UnicodeStringTable is NULL.\r
+ @retval EFI_UNSUPPORTED The language specified by Language is not a member of SupportedLanguages.\r
@retval EFI_UNSUPPORTED The language specified by Language is not supported by UnicodeStringTable.\r
\r
**/\r
IN BOOLEAN Iso639Language\r
)\r
{\r
- BOOLEAN Found;\r
- UINTN Index;\r
- CHAR8 *LanguageString;\r
+ BOOLEAN Found;\r
+ UINTN Index;\r
+ CHAR8 *LanguageString;\r
\r
//\r
// Make sure the parameters are valid\r
//\r
- if (Language == NULL || UnicodeString == NULL) {\r
+ if ((Language == NULL) || (UnicodeString == NULL)) {\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
// If there are no supported languages, or the Unicode String Table is empty, then the\r
// Unicode String specified by Language is not supported by this Unicode String Table\r
//\r
- if (SupportedLanguages == NULL || UnicodeStringTable == NULL) {\r
+ if ((SupportedLanguages == NULL) || (UnicodeStringTable == NULL)) {\r
return EFI_UNSUPPORTED;\r
}\r
\r
// Make sure Language is in the set of Supported Languages\r
//\r
Found = FALSE;\r
- while (*SupportedLanguages != 0) {\r
- if (Iso639Language) {\r
+ if (Iso639Language) {\r
+ while (*SupportedLanguages != 0) {\r
if (CompareIso639LanguageCode (Language, SupportedLanguages)) {\r
Found = TRUE;\r
break;\r
}\r
+\r
SupportedLanguages += 3;\r
- } else {\r
- for (Index = 0; SupportedLanguages[Index] != 0 && SupportedLanguages[Index] != ';'; Index++);\r
- if ((AsciiStrnCmp(SupportedLanguages, Language, Index) == 0) && (Language[Index] == 0)) {\r
- Found = TRUE;\r
- break;\r
- }\r
- SupportedLanguages += Index;\r
- for (; *SupportedLanguages != 0 && *SupportedLanguages == ';'; SupportedLanguages++);\r
}\r
+ } else {\r
+ Found = !IsLanguageSupported (SupportedLanguages, Language);\r
}\r
\r
//\r
while (UnicodeStringTable->Language != NULL) {\r
LanguageString = UnicodeStringTable->Language;\r
while (0 != *LanguageString) {\r
- for (Index = 0 ;LanguageString[Index] != 0 && LanguageString[Index] != ';'; Index++);\r
- if (AsciiStrnCmp(LanguageString, Language, Index) == 0) {\r
+ for (Index = 0; LanguageString[Index] != 0 && LanguageString[Index] != ';'; Index++) {\r
+ }\r
+\r
+ if (AsciiStrnCmp (LanguageString, Language, Index) == 0) {\r
*UnicodeString = UnicodeStringTable->UnicodeString;\r
return EFI_SUCCESS;\r
}\r
+\r
LanguageString += Index;\r
- for (Index = 0 ;LanguageString[Index] != 0 && LanguageString[Index] == ';'; Index++);\r
+ for (Index = 0; LanguageString[Index] != 0 && LanguageString[Index] == ';'; Index++) {\r
+ }\r
}\r
+\r
UnicodeStringTable++;\r
}\r
\r
return EFI_UNSUPPORTED;\r
}\r
\r
-\r
/**\r
This function adds a Unicode string to UnicodeStringTable.\r
\r
- If Language is a member of SupportedLanguages then UnicodeString is added to \r
- UnicodeStringTable. New buffers are allocated for both Language and \r
- UnicodeString. The contents of Language and UnicodeString are copied into \r
- these new buffers. These buffers are automatically freed when \r
+ If Language is a member of SupportedLanguages then UnicodeString is added to\r
+ UnicodeStringTable. New buffers are allocated for both Language and\r
+ UnicodeString. The contents of Language and UnicodeString are copied into\r
+ these new buffers. These buffers are automatically freed when\r
FreeUnicodeStringTable() is called.\r
\r
- @param Language A pointer to the ISO 639-2 language code for the Unicode \r
+ @param Language A pointer to the ISO 639-2 language code for the Unicode\r
string to add.\r
@param SupportedLanguages A pointer to the set of ISO 639-2 language codes\r
that the Unicode string table supports.\r
@param UnicodeStringTable A pointer to the table of Unicode strings.\r
@param UnicodeString A pointer to the Unicode string to add.\r
\r
- @retval EFI_SUCCESS The Unicode string that matches the language \r
- specified by Language was found in the table of \r
- Unicode strings UnicodeStringTable, and it was \r
+ @retval EFI_SUCCESS The Unicode string that matches the language\r
+ specified by Language was found in the table of\r
+ Unicode strings UnicodeStringTable, and it was\r
returned in UnicodeString.\r
@retval EFI_INVALID_PARAMETER Language is NULL.\r
@retval EFI_INVALID_PARAMETER UnicodeString is NULL.\r
@retval EFI_INVALID_PARAMETER UnicodeString is an empty string.\r
@retval EFI_UNSUPPORTED SupportedLanguages is NULL.\r
- @retval EFI_ALREADY_STARTED A Unicode string with language Language is \r
+ @retval EFI_ALREADY_STARTED A Unicode string with language Language is\r
already present in UnicodeStringTable.\r
- @retval EFI_OUT_OF_RESOURCES There is not enough memory to add another \r
+ @retval EFI_OUT_OF_RESOURCES There is not enough memory to add another\r
Unicode string to UnicodeStringTable.\r
- @retval EFI_UNSUPPORTED The language specified by Language is not a \r
+ @retval EFI_UNSUPPORTED The language specified by Language is not a\r
member of SupportedLanguages.\r
\r
**/\r
EFI_STATUS\r
EFIAPI\r
AddUnicodeString (\r
- IN CONST CHAR8 *Language,\r
- IN CONST CHAR8 *SupportedLanguages,\r
- IN EFI_UNICODE_STRING_TABLE **UnicodeStringTable,\r
- IN CONST CHAR16 *UnicodeString\r
+ IN CONST CHAR8 *Language,\r
+ IN CONST CHAR8 *SupportedLanguages,\r
+ IN OUT EFI_UNICODE_STRING_TABLE **UnicodeStringTable,\r
+ IN CONST CHAR16 *UnicodeString\r
)\r
{\r
UINTN NumberOfEntries;\r
//\r
// Make sure the parameter are valid\r
//\r
- if (Language == NULL || UnicodeString == NULL || UnicodeStringTable == NULL) {\r
+ if ((Language == NULL) || (UnicodeString == NULL) || (UnicodeStringTable == NULL)) {\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
//\r
while (*SupportedLanguages != 0) {\r
if (CompareIso639LanguageCode (Language, SupportedLanguages)) {\r
-\r
//\r
// Determine the size of the Unicode String Table by looking for a NULL Language entry\r
//\r
//\r
if (*UnicodeStringTable != NULL) {\r
CopyMem (\r
- NewUnicodeStringTable,\r
- *UnicodeStringTable,\r
- NumberOfEntries * sizeof (EFI_UNICODE_STRING_TABLE)\r
- );\r
+ NewUnicodeStringTable,\r
+ *UnicodeStringTable,\r
+ NumberOfEntries * sizeof (EFI_UNICODE_STRING_TABLE)\r
+ );\r
}\r
\r
//\r
//\r
// Compute the length of the Unicode String\r
//\r
- for (UnicodeStringLength = 0; UnicodeString[UnicodeStringLength] != 0; UnicodeStringLength++)\r
- ;\r
+ for (UnicodeStringLength = 0; UnicodeString[UnicodeStringLength] != 0; UnicodeStringLength++) {\r
+ }\r
\r
//\r
// Allocate space for a copy of the Unicode String\r
//\r
NewUnicodeStringTable[NumberOfEntries].UnicodeString = AllocateCopyPool (\r
- (UnicodeStringLength + 1) * sizeof (CHAR16),\r
- UnicodeString\r
- );\r
+ (UnicodeStringLength + 1) * sizeof (CHAR16),\r
+ UnicodeString\r
+ );\r
if (NewUnicodeStringTable[NumberOfEntries].UnicodeString == NULL) {\r
FreePool (NewUnicodeStringTable[NumberOfEntries].Language);\r
FreePool (NewUnicodeStringTable);\r
//\r
// Mark the end of the Unicode String Table\r
//\r
- NewUnicodeStringTable[NumberOfEntries + 1].Language = NULL;\r
- NewUnicodeStringTable[NumberOfEntries + 1].UnicodeString = NULL;\r
+ NewUnicodeStringTable[NumberOfEntries + 1].Language = NULL;\r
+ NewUnicodeStringTable[NumberOfEntries + 1].UnicodeString = NULL;\r
\r
//\r
// Free the old Unicode String Table\r
return EFI_UNSUPPORTED;\r
}\r
\r
-\r
/**\r
This function adds the Null-terminated Unicode string specified by UnicodeString\r
to UnicodeStringTable.\r
RFC 4646 language codes separated by ';'.\r
@param UnicodeStringTable A pointer to the table of Unicode strings. Type EFI_UNICODE_STRING_TABLE\r
is defined in "Related Definitions".\r
- @param UnicodeString A pointer to the Unicode string to add. \r
+ @param UnicodeString A pointer to the Unicode string to add.\r
@param Iso639Language Specifies the supported language code format. If it is TRUE,\r
then Language and SupportedLanguages follow ISO 639-2 language code format.\r
Otherwise, they follow RFC 4646 language code format.\r
\r
@retval EFI_SUCCESS The Unicode string that matches the language specified by\r
Language was found in the table of Unicode strings UnicodeStringTable,\r
- and it was returned in UnicodeString. \r
- @retval EFI_INVALID_PARAMETER Language is NULL. \r
- @retval EFI_INVALID_PARAMETER UnicodeString is NULL. \r
- @retval EFI_INVALID_PARAMETER UnicodeString is an empty string. \r
- @retval EFI_UNSUPPORTED SupportedLanguages is NULL. \r
+ and it was returned in UnicodeString.\r
+ @retval EFI_INVALID_PARAMETER Language is NULL.\r
+ @retval EFI_INVALID_PARAMETER UnicodeString is NULL.\r
+ @retval EFI_INVALID_PARAMETER UnicodeString is an empty string.\r
+ @retval EFI_UNSUPPORTED SupportedLanguages is NULL.\r
@retval EFI_ALREADY_STARTED A Unicode string with language Language is already present in\r
- UnicodeStringTable. \r
- @retval EFI_OUT_OF_RESOURCES There is not enough memory to add another Unicode string UnicodeStringTable. \r
+ UnicodeStringTable.\r
+ @retval EFI_OUT_OF_RESOURCES There is not enough memory to add another Unicode string UnicodeStringTable.\r
@retval EFI_UNSUPPORTED The language specified by Language is not a member of SupportedLanguages.\r
\r
**/\r
EFI_STATUS\r
EFIAPI\r
AddUnicodeString2 (\r
- IN CONST CHAR8 *Language,\r
- IN CONST CHAR8 *SupportedLanguages,\r
- IN EFI_UNICODE_STRING_TABLE **UnicodeStringTable,\r
- IN CONST CHAR16 *UnicodeString,\r
- IN BOOLEAN Iso639Language\r
+ IN CONST CHAR8 *Language,\r
+ IN CONST CHAR8 *SupportedLanguages,\r
+ IN OUT EFI_UNICODE_STRING_TABLE **UnicodeStringTable,\r
+ IN CONST CHAR16 *UnicodeString,\r
+ IN BOOLEAN Iso639Language\r
)\r
{\r
UINTN NumberOfEntries;\r
//\r
// Make sure the parameter are valid\r
//\r
- if (Language == NULL || UnicodeString == NULL || UnicodeStringTable == NULL) {\r
+ if ((Language == NULL) || (UnicodeString == NULL) || (UnicodeStringTable == NULL)) {\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
// Make sure Language is a member of SupportedLanguages\r
//\r
Found = FALSE;\r
- while (*SupportedLanguages != 0) {\r
- if (Iso639Language) {\r
+ if (Iso639Language) {\r
+ while (*SupportedLanguages != 0) {\r
if (CompareIso639LanguageCode (Language, SupportedLanguages)) {\r
Found = TRUE;\r
break;\r
}\r
+\r
SupportedLanguages += 3;\r
- } else {\r
- for (Index = 0; SupportedLanguages[Index] != 0 && SupportedLanguages[Index] != ';'; Index++);\r
- if (AsciiStrnCmp(SupportedLanguages, Language, Index) == 0) {\r
- Found = TRUE;\r
- break;\r
- }\r
- SupportedLanguages += Index;\r
- for (; *SupportedLanguages != 0 && *SupportedLanguages == ';'; SupportedLanguages++);\r
}\r
+ } else {\r
+ Found = !IsLanguageSupported (SupportedLanguages, Language);\r
}\r
\r
//\r
LanguageString = OldUnicodeStringTable->Language;\r
\r
while (*LanguageString != 0) {\r
- for (Index = 0; LanguageString[Index] != 0 && LanguageString[Index] != ';'; Index++);\r
+ for (Index = 0; LanguageString[Index] != 0 && LanguageString[Index] != ';'; Index++) {\r
+ }\r
\r
- if (AsciiStrnCmp (Language, LanguageString, Index) == 0) { \r
+ if (AsciiStrnCmp (Language, LanguageString, Index) == 0) {\r
return EFI_ALREADY_STARTED;\r
}\r
+\r
LanguageString += Index;\r
- for (; *LanguageString != 0 && *LanguageString == ';'; LanguageString++);\r
+ for ( ; *LanguageString != 0 && *LanguageString == ';'; LanguageString++) {\r
+ }\r
}\r
+\r
OldUnicodeStringTable++;\r
NumberOfEntries++;\r
}\r
//\r
// Allocate space for a copy of the Language specifier\r
//\r
- NewUnicodeStringTable[NumberOfEntries].Language = AllocateCopyPool (AsciiStrSize(Language), Language);\r
+ NewUnicodeStringTable[NumberOfEntries].Language = AllocateCopyPool (AsciiStrSize (Language), Language);\r
if (NewUnicodeStringTable[NumberOfEntries].Language == NULL) {\r
FreePool (NewUnicodeStringTable);\r
return EFI_OUT_OF_RESOURCES;\r
//\r
// Compute the length of the Unicode String\r
//\r
- for (UnicodeStringLength = 0; UnicodeString[UnicodeStringLength] != 0; UnicodeStringLength++);\r
+ for (UnicodeStringLength = 0; UnicodeString[UnicodeStringLength] != 0; UnicodeStringLength++) {\r
+ }\r
\r
//\r
// Allocate space for a copy of the Unicode String\r
//\r
// Mark the end of the Unicode String Table\r
//\r
- NewUnicodeStringTable[NumberOfEntries + 1].Language = NULL;\r
- NewUnicodeStringTable[NumberOfEntries + 1].UnicodeString = NULL;\r
+ NewUnicodeStringTable[NumberOfEntries + 1].Language = NULL;\r
+ NewUnicodeStringTable[NumberOfEntries + 1].UnicodeString = NULL;\r
\r
//\r
// Free the old Unicode String Table\r
This function frees the table of Unicode strings in UnicodeStringTable.\r
\r
If UnicodeStringTable is NULL, then EFI_SUCCESS is returned.\r
- Otherwise, each language code, and each Unicode string in the Unicode string \r
+ Otherwise, each language code, and each Unicode string in the Unicode string\r
table are freed, and EFI_SUCCESS is returned.\r
\r
@param UnicodeStringTable A pointer to the table of Unicode strings.\r
IN EFI_UNICODE_STRING_TABLE *UnicodeStringTable\r
)\r
{\r
- UINTN Index;\r
+ UINTN Index;\r
\r
//\r
// If the Unicode String Table is NULL, then it is already freed\r
// Loop through the Unicode String Table until we reach the end of table marker\r
//\r
for (Index = 0; UnicodeStringTable[Index].Language != NULL; Index++) {\r
-\r
//\r
// Free the Language string from the Unicode String Table\r
//\r
}\r
\r
/**\r
- Returns a pointer to an allocated buffer that contains the contents of a \r
- variable retrieved through the UEFI Runtime Service GetVariable(). The \r
+ Returns the status whether get the variable success. The function retrieves\r
+ variable through the UEFI Runtime Service GetVariable(). The\r
returned buffer is allocated using AllocatePool(). The caller is responsible\r
for freeing this buffer with FreePool().\r
\r
- If Name is NULL, then ASSERT().\r
- If Guid is NULL, then ASSERT().\r
+ If Name is NULL, then ASSERT().\r
+ If Guid is NULL, then ASSERT().\r
+ If Value is NULL, then ASSERT().\r
\r
@param[in] Name The pointer to a Null-terminated Unicode string.\r
@param[in] Guid The pointer to an EFI_GUID structure\r
+ @param[out] Value The buffer point saved the variable info.\r
+ @param[out] Size The buffer size of the variable.\r
\r
- @retval NULL The variable could not be retrieved.\r
- @retval NULL There are not enough resources available for the variable contents.\r
- @retval Other A pointer to allocated buffer containing the variable contents.\r
+ @return EFI_OUT_OF_RESOURCES Allocate buffer failed.\r
+ @return EFI_SUCCESS Find the specified variable.\r
+ @return Others Errors Return errors from call to gRT->GetVariable.\r
\r
**/\r
-VOID *\r
+EFI_STATUS\r
EFIAPI\r
-GetVariable (\r
+GetVariable2 (\r
IN CONST CHAR16 *Name,\r
- IN CONST EFI_GUID *Guid\r
+ IN CONST EFI_GUID *Guid,\r
+ OUT VOID **Value,\r
+ OUT UINTN *Size OPTIONAL\r
)\r
{\r
EFI_STATUS Status;\r
- UINTN Size;\r
- VOID *Value;\r
+ UINTN BufferSize;\r
\r
- ASSERT (Name != NULL);\r
- ASSERT (Guid != NULL);\r
+ ASSERT (Name != NULL && Guid != NULL && Value != NULL);\r
\r
//\r
// Try to get the variable size.\r
//\r
- Value = NULL;\r
- Size = 0;\r
- Status = gRT->GetVariable ((CHAR16 *) Name, (EFI_GUID *) Guid, NULL, &Size, Value);\r
+ BufferSize = 0;\r
+ *Value = NULL;\r
+ if (Size != NULL) {\r
+ *Size = 0;\r
+ }\r
+\r
+ Status = gRT->GetVariable ((CHAR16 *)Name, (EFI_GUID *)Guid, NULL, &BufferSize, *Value);\r
if (Status != EFI_BUFFER_TOO_SMALL) {\r
- return NULL;\r
+ return Status;\r
}\r
\r
//\r
// Allocate buffer to get the variable.\r
//\r
- Value = AllocatePool (Size);\r
- if (Value == NULL) {\r
- return NULL;\r
+ *Value = AllocatePool (BufferSize);\r
+ ASSERT (*Value != NULL);\r
+ if (*Value == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
}\r
\r
//\r
// Get the variable data.\r
//\r
- Status = gRT->GetVariable ((CHAR16 *) Name, (EFI_GUID *) Guid, NULL, &Size, Value);\r
+ Status = gRT->GetVariable ((CHAR16 *)Name, (EFI_GUID *)Guid, NULL, &BufferSize, *Value);\r
if (EFI_ERROR (Status)) {\r
- FreePool(Value);\r
- return NULL;\r
+ FreePool (*Value);\r
+ *Value = NULL;\r
}\r
\r
- return Value;\r
+ if (Size != NULL) {\r
+ *Size = BufferSize;\r
+ }\r
+\r
+ return Status;\r
}\r
\r
+/** Return the attributes of the variable.\r
+\r
+ Returns the status whether get the variable success. The function retrieves\r
+ variable through the UEFI Runtime Service GetVariable(). The\r
+ returned buffer is allocated using AllocatePool(). The caller is responsible\r
+ for freeing this buffer with FreePool(). The attributes are returned if\r
+ the caller provides a valid Attribute parameter.\r
+\r
+ If Name is NULL, then ASSERT().\r
+ If Guid is NULL, then ASSERT().\r
+ If Value is NULL, then ASSERT().\r
+\r
+ @param[in] Name The pointer to a Null-terminated Unicode string.\r
+ @param[in] Guid The pointer to an EFI_GUID structure\r
+ @param[out] Value The buffer point saved the variable info.\r
+ @param[out] Size The buffer size of the variable.\r
+ @param[out] Attr The pointer to the variable attributes as found in var store\r
+\r
+ @retval EFI_OUT_OF_RESOURCES Allocate buffer failed.\r
+ @retval EFI_SUCCESS Find the specified variable.\r
+ @retval Others Errors Return errors from call to gRT->GetVariable.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GetVariable3 (\r
+ IN CONST CHAR16 *Name,\r
+ IN CONST EFI_GUID *Guid,\r
+ OUT VOID **Value,\r
+ OUT UINTN *Size OPTIONAL,\r
+ OUT UINT32 *Attr OPTIONAL\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ UINTN BufferSize;\r
+\r
+ ASSERT (Name != NULL && Guid != NULL && Value != NULL);\r
+\r
+ //\r
+ // Try to get the variable size.\r
+ //\r
+ BufferSize = 0;\r
+ *Value = NULL;\r
+ if (Size != NULL) {\r
+ *Size = 0;\r
+ }\r
+\r
+ if (Attr != NULL) {\r
+ *Attr = 0;\r
+ }\r
+\r
+ Status = gRT->GetVariable ((CHAR16 *)Name, (EFI_GUID *)Guid, Attr, &BufferSize, *Value);\r
+ if (Status != EFI_BUFFER_TOO_SMALL) {\r
+ return Status;\r
+ }\r
+\r
+ //\r
+ // Allocate buffer to get the variable.\r
+ //\r
+ *Value = AllocatePool (BufferSize);\r
+ ASSERT (*Value != NULL);\r
+ if (*Value == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+\r
+ //\r
+ // Get the variable data.\r
+ //\r
+ Status = gRT->GetVariable ((CHAR16 *)Name, (EFI_GUID *)Guid, Attr, &BufferSize, *Value);\r
+ if (EFI_ERROR (Status)) {\r
+ FreePool (*Value);\r
+ *Value = NULL;\r
+ }\r
+\r
+ if (Size != NULL) {\r
+ *Size = BufferSize;\r
+ }\r
+\r
+ return Status;\r
+}\r
\r
/**\r
- Returns a pointer to an allocated buffer that contains the contents of a \r
- variable retrieved through the UEFI Runtime Service GetVariable(). This \r
+ Returns a pointer to an allocated buffer that contains the contents of a\r
+ variable retrieved through the UEFI Runtime Service GetVariable(). This\r
function always uses the EFI_GLOBAL_VARIABLE GUID to retrieve variables.\r
- The returned buffer is allocated using AllocatePool(). The caller is \r
+ The returned buffer is allocated using AllocatePool(). The caller is\r
responsible for freeing this buffer with FreePool().\r
\r
If Name is NULL, then ASSERT().\r
+ If Value is NULL, then ASSERT().\r
\r
@param[in] Name The pointer to a Null-terminated Unicode string.\r
+ @param[out] Value The buffer point saved the variable info.\r
+ @param[out] Size The buffer size of the variable.\r
\r
- @retval NULL The variable could not be retrieved.\r
- @retval NULL There are not enough resources available for the variable contents.\r
- @retval Other A pointer to allocated buffer containing the variable contents.\r
+ @return EFI_OUT_OF_RESOURCES Allocate buffer failed.\r
+ @return EFI_SUCCESS Find the specified variable.\r
+ @return Others Errors Return errors from call to gRT->GetVariable.\r
\r
**/\r
-VOID *\r
+EFI_STATUS\r
EFIAPI\r
-GetEfiGlobalVariable (\r
- IN CONST CHAR16 *Name\r
+GetEfiGlobalVariable2 (\r
+ IN CONST CHAR16 *Name,\r
+ OUT VOID **Value,\r
+ OUT UINTN *Size OPTIONAL\r
)\r
{\r
- return GetVariable (Name, &gEfiGlobalVariableGuid);\r
+ return GetVariable2 (Name, &gEfiGlobalVariableGuid, Value, Size);\r
}\r
\r
-\r
/**\r
- Returns a pointer to an allocated buffer that contains the best matching language \r
- from a set of supported languages. \r
- \r
- This function supports both ISO 639-2 and RFC 4646 language codes, but language \r
- code types may not be mixed in a single call to this function. The language \r
- code returned is allocated using AllocatePool(). The caller is responsible for \r
+ Returns a pointer to an allocated buffer that contains the best matching language\r
+ from a set of supported languages.\r
+\r
+ This function supports both ISO 639-2 and RFC 4646 language codes, but language\r
+ code types may not be mixed in a single call to this function. The language\r
+ code returned is allocated using AllocatePool(). The caller is responsible for\r
freeing the allocated buffer using FreePool(). This function supports a variable\r
- argument list that allows the caller to pass in a prioritized list of language \r
- codes to test against all the language codes in SupportedLanguages. \r
+ argument list that allows the caller to pass in a prioritized list of language\r
+ codes to test against all the language codes in SupportedLanguages.\r
\r
If SupportedLanguages is NULL, then ASSERT().\r
\r
@param[in] SupportedLanguages A pointer to a Null-terminated ASCII string that\r
- contains a set of language codes in the format \r
+ contains a set of language codes in the format\r
specified by Iso639Language.\r
- @param[in] Iso639Language If TRUE, then all language codes are assumed to be\r
- in ISO 639-2 format. If FALSE, then all language\r
+ @param[in] Iso639Language If not zero, then all language codes are assumed to be\r
+ in ISO 639-2 format. If zero, then all language\r
codes are assumed to be in RFC 4646 language format\r
- @param[in] ... A variable argument list that contains pointers to \r
+ @param[in] ... A variable argument list that contains pointers to\r
Null-terminated ASCII strings that contain one or more\r
language codes in the format specified by Iso639Language.\r
The first language code from each of these language\r
code lists is used to determine if it is an exact or\r
- close match to any of the language codes in \r
+ close match to any of the language codes in\r
SupportedLanguages. Close matches only apply to RFC 4646\r
language codes, and the matching algorithm from RFC 4647\r
- is used to determine if a close match is present. If \r
+ is used to determine if a close match is present. If\r
an exact or close match is found, then the matching\r
language code from SupportedLanguages is returned. If\r
no matches are found, then the next variable argument\r
- parameter is evaluated. The variable argument list \r
+ parameter is evaluated. The variable argument list\r
is terminated by a NULL.\r
\r
@retval NULL The best matching language could not be found in SupportedLanguages.\r
- @retval NULL There are not enough resources available to return the best matching \r
+ @retval NULL There are not enough resources available to return the best matching\r
language.\r
- @retval Other A pointer to a Null-terminated ASCII string that is the best matching \r
+ @retval Other A pointer to a Null-terminated ASCII string that is the best matching\r
language in SupportedLanguages.\r
\r
**/\r
CHAR8 *\r
EFIAPI\r
GetBestLanguage (\r
- IN CONST CHAR8 *SupportedLanguages, \r
- IN BOOLEAN Iso639Language,\r
+ IN CONST CHAR8 *SupportedLanguages,\r
+ IN UINTN Iso639Language,\r
...\r
)\r
{\r
//\r
// If in RFC 4646 mode, then determine the length of the first RFC 4646 language code in Language\r
//\r
- if (!Iso639Language) {\r
- for (LanguageLength = 0; Language[LanguageLength] != 0 && Language[LanguageLength] != ';'; LanguageLength++);\r
+ if (Iso639Language == 0) {\r
+ for (LanguageLength = 0; Language[LanguageLength] != 0 && Language[LanguageLength] != ';'; LanguageLength++) {\r
+ }\r
}\r
\r
//\r
//\r
// In RFC 4646 mode, then Loop through all language codes in SupportedLanguages\r
//\r
- if (!Iso639Language) {\r
+ if (Iso639Language == 0) {\r
//\r
// Skip ';' characters in Supported\r
//\r
- for (; *Supported != '\0' && *Supported == ';'; Supported++);\r
+ for ( ; *Supported != '\0' && *Supported == ';'; Supported++) {\r
+ }\r
+\r
//\r
// Determine the length of the next language code in Supported\r
//\r
- for (CompareLength = 0; Supported[CompareLength] != 0 && Supported[CompareLength] != ';'; CompareLength++);\r
+ for (CompareLength = 0; Supported[CompareLength] != 0 && Supported[CompareLength] != ';'; CompareLength++) {\r
+ }\r
+\r
//\r
// If Language is longer than the Supported, then skip to the next language\r
//\r
continue;\r
}\r
}\r
+\r
//\r
// See if the first LanguageLength characters in Supported match Language\r
//\r
if (BestLanguage == NULL) {\r
return NULL;\r
}\r
+\r
return CopyMem (BestLanguage, Supported, CompareLength);\r
}\r
}\r
\r
- if (Iso639Language) {\r
+ if (Iso639Language != 0) {\r
//\r
// If ISO 639 mode, then each language can only be tested once\r
//\r
LanguageLength = 0;\r
} else {\r
//\r
- // If RFC 4646 mode, then trim Language from the right to the next '-' character \r
+ // If RFC 4646 mode, then trim Language from the right to the next '-' character\r
//\r
- for (LanguageLength--; LanguageLength > 0 && Language[LanguageLength] != '-'; LanguageLength--);\r
+ for (LanguageLength--; LanguageLength > 0 && Language[LanguageLength] != '-'; LanguageLength--) {\r
+ }\r
}\r
}\r
}\r
+\r
VA_END (Args);\r
\r
//\r
- // No matches were found \r
+ // No matches were found\r
//\r
return NULL;\r
}\r
\r
+/**\r
+ Returns an array of protocol instance that matches the given protocol.\r
+\r
+ @param[in] Protocol Provides the protocol to search for.\r
+ @param[out] NoProtocols The number of protocols returned in Buffer.\r
+ @param[out] Buffer A pointer to the buffer to return the requested\r
+ array of protocol instances that match Protocol.\r
+ The returned buffer is allocated using\r
+ EFI_BOOT_SERVICES.AllocatePool(). The caller is\r
+ responsible for freeing this buffer with\r
+ EFI_BOOT_SERVICES.FreePool().\r
+\r
+ @retval EFI_SUCCESS The array of protocols was returned in Buffer,\r
+ and the number of protocols in Buffer was\r
+ returned in NoProtocols.\r
+ @retval EFI_NOT_FOUND No protocols found.\r
+ @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the\r
+ matching results.\r
+ @retval EFI_INVALID_PARAMETER Protocol is NULL.\r
+ @retval EFI_INVALID_PARAMETER NoProtocols is NULL.\r
+ @retval EFI_INVALID_PARAMETER Buffer is NULL.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EfiLocateProtocolBuffer (\r
+ IN EFI_GUID *Protocol,\r
+ OUT UINTN *NoProtocols,\r
+ OUT VOID ***Buffer\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ UINTN NoHandles;\r
+ EFI_HANDLE *HandleBuffer;\r
+ UINTN Index;\r
+\r
+ //\r
+ // Check input parameters\r
+ //\r
+ if ((Protocol == NULL) || (NoProtocols == NULL) || (Buffer == NULL)) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ //\r
+ // Initialze output parameters\r
+ //\r
+ *NoProtocols = 0;\r
+ *Buffer = NULL;\r
+\r
+ //\r
+ // Retrieve the array of handles that support Protocol\r
+ //\r
+ Status = gBS->LocateHandleBuffer (\r
+ ByProtocol,\r
+ Protocol,\r
+ NULL,\r
+ &NoHandles,\r
+ &HandleBuffer\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ //\r
+ // Allocate array of protocol instances\r
+ //\r
+ Status = gBS->AllocatePool (\r
+ EfiBootServicesData,\r
+ NoHandles * sizeof (VOID *),\r
+ (VOID **)Buffer\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ //\r
+ // Free the handle buffer\r
+ //\r
+ gBS->FreePool (HandleBuffer);\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+\r
+ ZeroMem (*Buffer, NoHandles * sizeof (VOID *));\r
+\r
+ //\r
+ // Lookup Protocol on each handle in HandleBuffer to fill in the array of\r
+ // protocol instances. Handle case where protocol instance was present when\r
+ // LocateHandleBuffer() was called, but is not present when HandleProtocol()\r
+ // is called.\r
+ //\r
+ for (Index = 0, *NoProtocols = 0; Index < NoHandles; Index++) {\r
+ Status = gBS->HandleProtocol (\r
+ HandleBuffer[Index],\r
+ Protocol,\r
+ &((*Buffer)[*NoProtocols])\r
+ );\r
+ if (!EFI_ERROR (Status)) {\r
+ (*NoProtocols)++;\r
+ }\r
+ }\r
+\r
+ //\r
+ // Free the handle buffer\r
+ //\r
+ gBS->FreePool (HandleBuffer);\r
+\r
+ //\r
+ // Make sure at least one protocol instance was found\r
+ //\r
+ if (*NoProtocols == 0) {\r
+ gBS->FreePool (*Buffer);\r
+ *Buffer = NULL;\r
+ return EFI_NOT_FOUND;\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ Open or create a file or directory, possibly creating the chain of\r
+ directories leading up to the directory.\r
+\r
+ EfiOpenFileByDevicePath() first locates EFI_SIMPLE_FILE_SYSTEM_PROTOCOL on\r
+ FilePath, and opens the root directory of that filesystem with\r
+ EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume().\r
+\r
+ On the remaining device path, the longest initial sequence of\r
+ FILEPATH_DEVICE_PATH nodes is node-wise traversed with\r
+ EFI_FILE_PROTOCOL.Open().\r
+\r
+ (As a consequence, if OpenMode includes EFI_FILE_MODE_CREATE, and Attributes\r
+ includes EFI_FILE_DIRECTORY, and each FILEPATH_DEVICE_PATH specifies a single\r
+ pathname component, then EfiOpenFileByDevicePath() ensures that the specified\r
+ series of subdirectories exist on return.)\r
+\r
+ The EFI_FILE_PROTOCOL identified by the last FILEPATH_DEVICE_PATH node is\r
+ output to the caller; intermediate EFI_FILE_PROTOCOL instances are closed. If\r
+ there are no FILEPATH_DEVICE_PATH nodes past the node that identifies the\r
+ filesystem, then the EFI_FILE_PROTOCOL of the root directory of the\r
+ filesystem is output to the caller. If a device path node that is different\r
+ from FILEPATH_DEVICE_PATH is encountered relative to the filesystem, the\r
+ traversal is stopped with an error, and a NULL EFI_FILE_PROTOCOL is output.\r
+\r
+ @param[in,out] FilePath On input, the device path to the file or directory\r
+ to open or create. The caller is responsible for\r
+ ensuring that the device path pointed-to by FilePath\r
+ is well-formed. On output, FilePath points one past\r
+ the last node in the original device path that has\r
+ been successfully processed. FilePath is set on\r
+ output even if EfiOpenFileByDevicePath() returns an\r
+ error.\r
+\r
+ @param[out] File On error, File is set to NULL. On success, File is\r
+ set to the EFI_FILE_PROTOCOL of the root directory\r
+ of the filesystem, if there are no\r
+ FILEPATH_DEVICE_PATH nodes in FilePath; otherwise,\r
+ File is set to the EFI_FILE_PROTOCOL identified by\r
+ the last node in FilePath.\r
+\r
+ @param[in] OpenMode The OpenMode parameter to pass to\r
+ EFI_FILE_PROTOCOL.Open().\r
+\r
+ @param[in] Attributes The Attributes parameter to pass to\r
+ EFI_FILE_PROTOCOL.Open().\r
+\r
+ @retval EFI_SUCCESS The file or directory has been opened or\r
+ created.\r
+\r
+ @retval EFI_INVALID_PARAMETER FilePath is NULL; or File is NULL; or FilePath\r
+ contains a device path node, past the node\r
+ that identifies\r
+ EFI_SIMPLE_FILE_SYSTEM_PROTOCOL, that is not a\r
+ FILEPATH_DEVICE_PATH node.\r
+\r
+ @retval EFI_OUT_OF_RESOURCES Memory allocation failed.\r
+\r
+ @return Error codes propagated from the\r
+ LocateDevicePath() and OpenProtocol() boot\r
+ services, and from the\r
+ EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume()\r
+ and EFI_FILE_PROTOCOL.Open() member functions.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+EfiOpenFileByDevicePath (\r
+ IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath,\r
+ OUT EFI_FILE_PROTOCOL **File,\r
+ IN UINT64 OpenMode,\r
+ IN UINT64 Attributes\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_HANDLE FileSystemHandle;\r
+ EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem;\r
+ EFI_FILE_PROTOCOL *LastFile;\r
+ FILEPATH_DEVICE_PATH *FilePathNode;\r
+ CHAR16 *AlignedPathName;\r
+ CHAR16 *PathName;\r
+ EFI_FILE_PROTOCOL *NextFile;\r
+\r
+ if (File == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ *File = NULL;\r
+\r
+ if (FilePath == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ //\r
+ // Look up the filesystem.\r
+ //\r
+ Status = gBS->LocateDevicePath (\r
+ &gEfiSimpleFileSystemProtocolGuid,\r
+ FilePath,\r
+ &FileSystemHandle\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ Status = gBS->OpenProtocol (\r
+ FileSystemHandle,\r
+ &gEfiSimpleFileSystemProtocolGuid,\r
+ (VOID **)&FileSystem,\r
+ gImageHandle,\r
+ NULL,\r
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ //\r
+ // Open the root directory of the filesystem. After this operation succeeds,\r
+ // we have to release LastFile on error.\r
+ //\r
+ Status = FileSystem->OpenVolume (FileSystem, &LastFile);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ //\r
+ // Traverse the device path nodes relative to the filesystem.\r
+ //\r
+ while (!IsDevicePathEnd (*FilePath)) {\r
+ if ((DevicePathType (*FilePath) != MEDIA_DEVICE_PATH) ||\r
+ (DevicePathSubType (*FilePath) != MEDIA_FILEPATH_DP))\r
+ {\r
+ Status = EFI_INVALID_PARAMETER;\r
+ goto CloseLastFile;\r
+ }\r
+\r
+ FilePathNode = (FILEPATH_DEVICE_PATH *)*FilePath;\r
+\r
+ //\r
+ // FilePathNode->PathName may be unaligned, and the UEFI specification\r
+ // requires pointers that are passed to protocol member functions to be\r
+ // aligned. Create an aligned copy of the pathname if necessary.\r
+ //\r
+ if ((UINTN)FilePathNode->PathName % sizeof *FilePathNode->PathName == 0) {\r
+ AlignedPathName = NULL;\r
+ PathName = FilePathNode->PathName;\r
+ } else {\r
+ AlignedPathName = AllocateCopyPool (\r
+ (DevicePathNodeLength (FilePathNode) -\r
+ SIZE_OF_FILEPATH_DEVICE_PATH),\r
+ FilePathNode->PathName\r
+ );\r
+ if (AlignedPathName == NULL) {\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ goto CloseLastFile;\r
+ }\r
+\r
+ PathName = AlignedPathName;\r
+ }\r
+\r
+ //\r
+ // Open or create the file corresponding to the next pathname fragment.\r
+ //\r
+ Status = LastFile->Open (\r
+ LastFile,\r
+ &NextFile,\r
+ PathName,\r
+ OpenMode,\r
+ Attributes\r
+ );\r
+\r
+ //\r
+ // Release any AlignedPathName on both error and success paths; PathName is\r
+ // no longer needed.\r
+ //\r
+ if (AlignedPathName != NULL) {\r
+ FreePool (AlignedPathName);\r
+ }\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ goto CloseLastFile;\r
+ }\r
+\r
+ //\r
+ // Advance to the next device path node.\r
+ //\r
+ LastFile->Close (LastFile);\r
+ LastFile = NextFile;\r
+ *FilePath = NextDevicePathNode (FilePathNode);\r
+ }\r
+\r
+ *File = LastFile;\r
+ return EFI_SUCCESS;\r
+\r
+CloseLastFile:\r
+ LastFile->Close (LastFile);\r
+\r
+ //\r
+ // We are on the error path; we must have set an error Status for returning\r
+ // to the caller.\r
+ //\r
+ ASSERT (EFI_ERROR (Status));\r
+ return Status;\r
+}\r