]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/UefiLib/UefiLib.c
remove unnecessary comments introduced by tools from MdePkg. The regular express...
[mirror_edk2.git] / MdePkg / Library / UefiLib / UefiLib.c
index 0ce36fce7ba8cb3608df963a54fb24a2cd523c00..a58878e5d348c0c83233f5ebdcd9bf3f6fb6967f 100644 (file)
@@ -1,19 +1,20 @@
 /** @file\r
   Mde UEFI library functions.\r
 \r
-  Copyright (c) 2006, Intel Corporation<BR>\r
-  All rights reserved. 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
+  Copyright (c) 2006 - 2007, Intel Corporation<BR>\r
+  All rights reserved. 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
-\r
-  Module Name:  UefiLib.c\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
 \r
 **/\r
 \r
+\r
+#include "UefiLibInternal.h"\r
+\r
 /**\r
   Compare whether two names of languages are identical.\r
 \r
@@ -30,14 +31,22 @@ CompareIso639LanguageCode (
   IN CONST CHAR8  *Language2\r
   )\r
 {\r
-  return (BOOLEAN) (ReadUnaligned24 ((CONST UINT32 *) Language1) == ReadUnaligned24 ((CONST UINT32 *) Language2));\r
+  UINT32  Name1;\r
+  UINT32  Name2;\r
+\r
+  Name1 = ReadUnaligned24 ((CONST UINT32 *) Language1);\r
+  Name2 = ReadUnaligned24 ((CONST UINT32 *) Language2);\r
+\r
+  return (BOOLEAN) (Name1 == Name2);\r
 }\r
 \r
 /**\r
-  This function searches the list of configuration tables stored in the EFI System \r
-  Table for a table with a GUID that matches TableGuid.  If a match is found, \r
-  then a pointer to the configuration table is returned in Table, and EFI_SUCCESS \r
+  This function searches the list of configuration tables stored in the EFI System\r
+  Table for a table with a GUID that matches TableGuid.  If a match is found,\r
+  then a pointer to the configuration table is returned in Table, and EFI_SUCCESS\r
   is returned.  If a matching GUID is not found, then EFI_NOT_FOUND is returned.\r
+  If TableGuid is NULL, then ASSERT().\r
+  If Table is NULL, then ASSERT().\r
 \r
   @param  TableGuid       Pointer to table's GUID type..\r
   @param  Table           Pointer to the table associated with TableGuid in the EFI System Table.\r
@@ -48,7 +57,7 @@ CompareIso639LanguageCode (
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-EfiGetSystemConfigurationTable (  \r
+EfiGetSystemConfigurationTable (\r
   IN  EFI_GUID  *TableGuid,\r
   OUT VOID      **Table\r
   )\r
@@ -72,9 +81,9 @@ EfiGetSystemConfigurationTable (
 }\r
 \r
 /**\r
-  This function causes the notification function to be executed for every protocol \r
-  of type ProtocolGuid instance that exists in the system when this function is \r
-  invoked.  In addition, every time a protocol of type ProtocolGuid instance is \r
+  This function causes the notification function to be executed for every protocol\r
+  of type ProtocolGuid instance that exists in the system when this function is\r
+  invoked.  In addition, every time a protocol of type ProtocolGuid instance is\r
   installed or reinstalled, the notification function is also executed.\r
 \r
   @param  ProtocolGuid    Supplies GUID of the protocol upon whose installation the event is fired.\r
@@ -83,7 +92,7 @@ EfiGetSystemConfigurationTable (
   @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
-  @return The notification event that was created. \r
+  @return The notification event that was created.\r
 \r
 **/\r
 EFI_EVENT\r
@@ -104,7 +113,7 @@ EfiCreateProtocolNotifyEvent(
   //\r
 \r
   Status = gBS->CreateEvent (\r
-                  EFI_EVENT_NOTIFY_SIGNAL,\r
+                  EVT_NOTIFY_SIGNAL,\r
                   NotifyTpl,\r
                   NotifyFunction,\r
                   NotifyContext,\r
@@ -135,13 +144,16 @@ EfiCreateProtocolNotifyEvent(
 \r
 /**\r
   This function creates an event using NotifyTpl, NoifyFunction, and NotifyContext.\r
-  This event is signaled with EfiNamedEventSignal().  This provide the ability for \r
+  This event is signaled with EfiNamedEventSignal().  This provide the ability for\r
   one or more 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
 \r
   @param  Name                  Supplies 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
@@ -155,18 +167,22 @@ EfiNamedEventListen (
   IN EFI_TPL           NotifyTpl,\r
   IN EFI_EVENT_NOTIFY  NotifyFunction,\r
   IN CONST VOID        *NotifyContext,  OPTIONAL\r
-  OUT VOID             *Registration    OPTIONAL\r
+  OUT VOID             *Registration OPTIONAL\r
   )\r
 {\r
   EFI_STATUS  Status;\r
   EFI_EVENT   Event;\r
   VOID        *RegistrationLocal;\r
 \r
+  ASSERT (Name != NULL);\r
+  ASSERT (NotifyFunction != NULL);\r
+  ASSERT (NotifyTpl <= TPL_HIGH_LEVEL);\r
+  \r
   //\r
   // Create event\r
   //\r
   Status = gBS->CreateEvent (\r
-                  EFI_EVENT_NOTIFY_SIGNAL,\r
+                  EVT_NOTIFY_SIGNAL,\r
                   NotifyTpl,\r
                   NotifyFunction,\r
                   (VOID *) NotifyContext,\r
@@ -195,11 +211,11 @@ EfiNamedEventListen (
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  return EFI_SUCCESS;\r
+  return Status;\r
 }\r
 \r
 /**\r
-  This function signals the named event specified by Name.  The named event must \r
+  This function signals the named event specified by Name.  The named event must\r
   have been created with EfiNamedEventListen().\r
 \r
   @param  Name                  Supplies GUID name of the event.\r
@@ -233,15 +249,45 @@ EfiNamedEventSignal (
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  return EFI_SUCCESS;\r
+  return Status;\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
+  to RestoreTPL().\r
+\r
+  @param  VOID\r
+\r
+  @retval EFI_TPL              The current TPL.\r
+\r
+**/\r
+EFI_TPL\r
+EFIAPI\r
+EfiGetCurrentTpl (\r
+  VOID\r
+  )\r
+{\r
+  EFI_TPL Tpl;\r
+\r
+  Tpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r
+  gBS->RestoreTPL (Tpl);\r
+\r
+  return Tpl;\r
 }\r
 \r
 \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
+  If Priority is not a valid TPL value, then ASSERT().\r
 \r
   @param  Lock       A pointer to the lock data structure to initialize.\r
   @param  Priority   EFI TPL associated with the lock.\r
@@ -257,20 +303,23 @@ EfiInitializeLock (
   )\r
 {\r
   ASSERT (Lock != NULL);\r
-  ASSERT (Priority <= EFI_TPL_HIGH_LEVEL);\r
+  ASSERT (Priority <= TPL_HIGH_LEVEL);\r
 \r
   Lock->Tpl       = Priority;\r
-  Lock->OwnerTpl  = EFI_TPL_APPLICATION;\r
+  Lock->OwnerTpl  = TPL_APPLICATION;\r
   Lock->Lock      = EfiLockReleased ;\r
   return Lock;\r
 }\r
 \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
+  If Lock is already in the acquired state, then ASSERT().\r
 \r
-  @param  Priority  The task priority level of the lock.\r
+  @param  Lock   The task lock with priority level.\r
 \r
 **/\r
 VOID\r
@@ -287,8 +336,8 @@ EfiAcquireLock (
 }\r
 \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 attempts to place 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 attempts to place the\r
   lock in the acquired state.\r
 \r
   @param  Lock              A pointer to the lock to acquire.\r
@@ -322,8 +371,8 @@ EfiAcquireLockOrFail (
 }\r
 \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
 \r
   @param  Lock  A pointer to the lock to release.\r
@@ -341,39 +390,183 @@ EfiReleaseLock (
   ASSERT (Lock->Lock == EfiLockAcquired);\r
 \r
   Tpl = Lock->OwnerTpl;\r
-  \r
+\r
   Lock->Lock = EfiLockReleased;\r
 \r
   gBS->RestoreTPL (Tpl);\r
 }\r
 \r
 /**\r
-  This function looks up a Unicode string in UnicodeStringTable.  If Language is \r
-  a member of SupportedLanguages and a Unicode string is found in UnicodeStringTable\r
-  that matches the language code specified by Language, then it is returned in \r
+  Tests whether a controller handle is being managed by a specific driver.\r
+\r
+  This function tests whether the driver specified by DriverBindingHandle is\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
+  If ProtocolGuid is NULL, then ASSERT().\r
+\r
+  @param  ControllerHandle     A handle for a controller to test.\r
+  @param  DriverBindingHandle  Specifies the driver binding handle for the\r
+                               driver.\r
+  @param  ProtocolGuid         Specifies the protocol that the driver specified\r
+                               by DriverBindingHandle opens in its Start()\r
+                               function.\r
+\r
+  @retval EFI_SUCCESS          ControllerHandle is managed by the driver\r
+                               specifed by DriverBindingHandle.\r
+  @retval EFI_UNSUPPORTED      ControllerHandle is not managed by the driver\r
+                               specifed by DriverBindingHandle.\r
+\r
+**/\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
+  )\r
+{\r
+  EFI_STATUS     Status;\r
+  VOID           *ManagedInterface;\r
+\r
+  ASSERT (ProtocolGuid != NULL);\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  (EFI_GUID *) ProtocolGuid,\r
+                  &ManagedInterface,\r
+                  DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+           ControllerHandle,\r
+           (EFI_GUID *) ProtocolGuid,\r
+           DriverBindingHandle,\r
+           ControllerHandle\r
+           );\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (Status != EFI_ALREADY_STARTED) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Tests whether a child handle is a child device of the controller.\r
+\r
+  This function tests whether ChildHandle is one of the children of\r
+  ControllerHandle.  This test is performed by checking to see if the protocol\r
+  specified by ProtocolGuid is present on ControllerHandle and opened by\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  ChildHandle          A child handle to test.\r
+  @param  ProtocolGuid         Supplies the protocol that the child 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
+                               ControllerHandle.\r
+\r
+**/\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
+  )\r
+{\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
+  // Retrieve the list of agents that are consuming the specific protocol\r
+  // on ControllerHandle.\r
+  //\r
+  Status = gBS->OpenProtocolInformation (\r
+                  ControllerHandle,\r
+                  (EFI_GUID *) ProtocolGuid,\r
+                  &OpenInfoBuffer,\r
+                  &EntryCount\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Inspect if ChildHandle is one of the agents.\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
+      Status = EFI_SUCCESS;\r
+      break;\r
+    }\r
+  }\r
+\r
+  FreePool (OpenInfoBuffer);\r
+  return Status;\r
+}\r
+\r
+/**\r
+  This function looks up a Unicode string in UnicodeStringTable.\r
+  If Language is a member of SupportedLanguages and a Unicode\r
+  string is found in UnicodeStringTable that matches the\r
+  language code specified by Language, then it is returned in\r
   UnicodeString.\r
 \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
-                                  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
-                                  specified by Language was found\r
-                                  in the table of Unicoide strings UnicodeStringTable, \r
-                                  and it was returned in UnicodeString.\r
+  @param  Language                A pointer to the ISO 639-2\r
+                                  language code for the Unicode\r
+                                  string to look up and return.\r
+  \r
+  @param  SupportedLanguages      A pointer to the set of ISO\r
+                                  639-2language\r
+                                  codes that the Unicode string\r
+                                  table supports. Language must\r
+                                  be a member of this set.\r
+  \r
+  @param  UnicodeStringTable      A pointer to the table of\r
+                                  Unicode strings.\r
+  \r
+  @param  UnicodeString           A pointer to the Unicode\r
+                                  string from UnicodeStringTable\r
+                                  that matches the language\r
+                                  specified by Language.\r
+\r
+  @retval  EFI_SUCCESS            The Unicode string that\r
+                                  matches the language specified\r
+                                  by Language was found in the\r
+                                  table of Unicoide strings\r
+                                  UnicodeStringTable, and it was\r
+                                  returned in UnicodeString.\r
+  \r
   @retval  EFI_INVALID_PARAMETER  Language is NULL.\r
+  \r
   @retval  EFI_INVALID_PARAMETER  UnicodeString is NULL.\r
   @retval  EFI_UNSUPPORTED        SupportedLanguages is NULL.\r
+  \r
   @retval  EFI_UNSUPPORTED        UnicodeStringTable is NULL.\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
-                                  supported by UnicodeStringTable.\r
+  \r
+  @retval  EFI_UNSUPPORTED        The language specified by\r
+                                  Language is not a member\r
+                                  ofSupportedLanguages.\r
+  \r
+  @retval EFI_UNSUPPORTED         The language specified by\r
+                                  Language is not supported by\r
+                                  UnicodeStringTable.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -431,36 +624,196 @@ LookupUnicodeString (
   return EFI_UNSUPPORTED;\r
 }\r
 \r
+\r
+\r
+/**\r
+  This function looks up a Unicode string in UnicodeStringTable.\r
+  If Language is a member of SupportedLanguages and a Unicode\r
+  string is found in UnicodeStringTable that matches the\r
+  language code specified by Language, then it is returned in\r
+  UnicodeString.\r
+\r
+  @param  Language                A pointer to the ISO 639-2 or\r
+                                  RFC 3066 language code for the\r
+                                  Unicode string to look up and\r
+                                  return.\r
+  \r
+  @param  SupportedLanguages      A pointer to the set of ISO\r
+                                  639-2 or RFC 3066 language\r
+                                  codes that the Unicode string\r
+                                  table supports. Language must\r
+                                  be a member of this set.\r
+  \r
+  @param  UnicodeStringTable      A pointer to the table of\r
+                                  Unicode strings.\r
+  \r
+  @param  UnicodeString           A pointer to the Unicode\r
+                                  string from UnicodeStringTable\r
+                                  that matches the language\r
+                                  specified by Language.\r
+\r
+  @param  Iso639Language          Specify the language code\r
+                                  format supported. If true,\r
+                                  then the format follow ISO\r
+                                  639-2. If false, then it\r
+                                  follows RFC3066.\r
+\r
+  @retval  EFI_SUCCESS            The Unicode string that\r
+                                  matches the language specified\r
+                                  by Language was found in the\r
+                                  table of Unicoide strings\r
+                                  UnicodeStringTable, and it was\r
+                                  returned in UnicodeString.\r
+  \r
+  @retval  EFI_INVALID_PARAMETER  Language is NULL.\r
+  \r
+  @retval  EFI_INVALID_PARAMETER  UnicodeString is NULL.\r
+  \r
+  @retval  EFI_UNSUPPORTED        SupportedLanguages is NULL.\r
+  \r
+  @retval  EFI_UNSUPPORTED        UnicodeStringTable is NULL.\r
+  \r
+  @retval  EFI_UNSUPPORTED        The language specified by\r
+                                  Language is not a member\r
+                                  ofSupportedLanguages.\r
+  \r
+  @retval EFI_UNSUPPORTED         The language specified by\r
+                                  Language is not supported by\r
+                                  UnicodeStringTable.\r
+\r
+**/\r
+EFI_STATUS\r
+\r
+EFIAPI\r
+LookupUnicodeString2 (\r
+  IN CONST CHAR8                     *Language,\r
+  IN CONST CHAR8                     *SupportedLanguages,\r
+  IN CONST EFI_UNICODE_STRING_TABLE  *UnicodeStringTable,\r
+  OUT CHAR16                         **UnicodeString,\r
+  IN BOOLEAN                         Iso639Language\r
+  )\r
+{\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
+    return EFI_INVALID_PARAMETER;\r
+  }\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
+    return EFI_UNSUPPORTED;\r
+  }\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 (CompareIso639LanguageCode (Language, SupportedLanguages)) {\r
+        Found = TRUE;\r
+        break;\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
+  }\r
+\r
+  //\r
+  // If Language is not a member of SupportedLanguages, then return EFI_UNSUPPORTED\r
+  //\r
+  if (!Found) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Search the Unicode String Table for the matching Language specifier\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
+        *UnicodeString = UnicodeStringTable->UnicodeString;\r
+        return EFI_SUCCESS;\r
+      }\r
+      LanguageString += Index;\r
+      for (Index = 0 ;LanguageString[Index] != 0 && LanguageString[Index] == ';'; Index++);\r
+    }\r
+    UnicodeStringTable++;\r
+  }\r
+\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+\r
 /**\r
+  \r
   This function adds a Unicode string to UnicodeStringTable.\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\r
+  UnicodeString is added to UnicodeStringTable.  New buffers are\r
+  allocated for both Language and UnicodeString.  The contents\r
+  of Language and UnicodeString are copied into these new\r
+  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\r
+                                  language code for the Unicode\r
+                                  string to add.\r
+  \r
+  @param  SupportedLanguages      A pointer to the set of ISO\r
+                                  639-2 language codes that the\r
+                                  Unicode string table supports.\r
+                                  Language must be a member of\r
+                                  this set.\r
+  \r
+  @param  UnicodeStringTable      A pointer to the table of\r
+                                  Unicode strings.\r
+  \r
+  @param  UnicodeString           A pointer to 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
-                                  Language 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 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
+\r
+  @retval EFI_SUCCESS             The Unicode string that\r
+                                  matches the language specified\r
+                                  by Language was found in the\r
+                                  table of Unicode strings\r
+                                  UnicodeStringTable, and it was\r
                                   returned in UnicodeString.\r
+  \r
   @retval EFI_INVALID_PARAMETER   Language is NULL.\r
+  \r
   @retval EFI_INVALID_PARAMETER   UnicodeString is NULL.\r
+  \r
   @retval EFI_INVALID_PARAMETER   UnicodeString is an empty string.\r
+  \r
   @retval EFI_UNSUPPORTED         SupportedLanguages is NULL.\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
-                                  Unicode string to UnicodeStringTable.\r
-  @retval EFI_UNSUPPORTED         The language specified by Language is not a \r
-                                  member of SupportedLanguages.\r
+  \r
+  @retval EFI_ALREADY_STARTED     A Unicode string with language\r
+                                  Language is already present in\r
+                                  UnicodeStringTable.\r
+  \r
+  @retval EFI_OUT_OF_RESOURCES    There is not enough memory to\r
+                                  add another Unicode string to\r
+                                  UnicodeStringTable.\r
+  \r
+  @retval EFI_UNSUPPORTED         The language specified by\r
+                                  Language is not a member of\r
+                                  SupportedLanguages.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -597,6 +950,225 @@ AddUnicodeString (
   return EFI_UNSUPPORTED;\r
 }\r
 \r
+\r
+/**\r
+  \r
+  This function adds a Unicode string to UnicodeStringTable.\r
+  If Language is a member of SupportedLanguages then\r
+  UnicodeString is added to UnicodeStringTable.  New buffers are\r
+  allocated for both Language and UnicodeString.  The contents\r
+  of Language and UnicodeString are copied into these new\r
+  buffers.  These buffers are automatically freed when\r
+  FreeUnicodeStringTable() is called.\r
+\r
+  @param  Language                A pointer to the ISO 639-2 or\r
+                                  RFC 3066 language code for the\r
+                                  Unicode string to add.\r
+  \r
+  @param  SupportedLanguages      A pointer to the set of ISO\r
+                                  639-2 or RFC 3.66 language\r
+                                  codes that the Unicode string\r
+                                  table supports. Language must\r
+                                  be a member of this set.\r
+  \r
+  @param  UnicodeStringTable      A pointer to the table of\r
+                                  Unicode strings.\r
+  \r
+  @param  UnicodeString           A pointer to the Unicode\r
+                                  string to add.\r
+  \r
+  @param  Iso639Language          Specify the language code\r
+                                  format supported. If true,\r
+                                  then the format follow ISO\r
+                                  639-2. If false, then it\r
+                                  follows RFC3066.\r
+\r
+  @retval EFI_SUCCESS             The Unicode string that\r
+                                  matches the language specified\r
+                                  by Language was found in the\r
+                                  table of Unicode strings\r
+                                  UnicodeStringTable, and it was\r
+                                  returned in UnicodeString.\r
+  \r
+  @retval EFI_INVALID_PARAMETER   Language is NULL.\r
+  \r
+  @retval EFI_INVALID_PARAMETER   UnicodeString is NULL.\r
+  \r
+  @retval EFI_INVALID_PARAMETER   UnicodeString is an empty string.\r
+  \r
+  @retval EFI_UNSUPPORTED         SupportedLanguages is NULL.\r
+  \r
+  @retval EFI_ALREADY_STARTED     A Unicode string with language\r
+                                  Language is already present in\r
+                                  UnicodeStringTable.\r
+  \r
+  @retval EFI_OUT_OF_RESOURCES    There is not enough memory to\r
+                                  add another Unicode string to\r
+                                  UnicodeStringTable.\r
+  \r
+  @retval EFI_UNSUPPORTED         The language specified by\r
+                                  Language is not a member of\r
+                                  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
+  )\r
+{\r
+  UINTN                     NumberOfEntries;\r
+  EFI_UNICODE_STRING_TABLE  *OldUnicodeStringTable;\r
+  EFI_UNICODE_STRING_TABLE  *NewUnicodeStringTable;\r
+  UINTN                     UnicodeStringLength;\r
+  BOOLEAN                   Found;\r
+  UINTN                     Index;\r
+  CHAR8                     *LanguageString;\r
+\r
+  //\r
+  // Make sure the parameter are valid\r
+  //\r
+  if (Language == NULL || UnicodeString == NULL || UnicodeStringTable == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // If there are no supported languages, then a Unicode String can not be added\r
+  //\r
+  if (SupportedLanguages == NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // If the Unicode String is empty, then a Unicode String can not be added\r
+  //\r
+  if (UnicodeString[0] == 0) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Make sure Language is a member of SupportedLanguages\r
+  //\r
+  Found = FALSE;\r
+  while (*SupportedLanguages != 0) {\r
+    if (Iso639Language) {\r
+      if (CompareIso639LanguageCode (Language, SupportedLanguages)) {\r
+        Found = TRUE;\r
+        break;\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
+  }\r
+\r
+  //\r
+  // If Language is not a member of SupportedLanguages, then return EFI_UNSUPPORTED\r
+  //\r
+  if (!Found) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Determine the size of the Unicode String Table by looking for a NULL Language entry\r
+  //\r
+  NumberOfEntries = 0;\r
+  if (*UnicodeStringTable != NULL) {\r
+    OldUnicodeStringTable = *UnicodeStringTable;\r
+    while (OldUnicodeStringTable->Language != NULL) {\r
+      LanguageString = OldUnicodeStringTable->Language;\r
+\r
+      while (*LanguageString != 0) {\r
+        for (Index = 0; LanguageString[Index] != 0 && LanguageString[Index] != ';'; Index++);\r
+\r
+        if (AsciiStrnCmp (Language, LanguageString, Index) == 0) { \r
+          return EFI_ALREADY_STARTED;\r
+        }\r
+        LanguageString += Index;\r
+        for (; *LanguageString != 0 && *LanguageString == ';'; LanguageString++);\r
+      }\r
+      OldUnicodeStringTable++;\r
+      NumberOfEntries++;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Allocate space for a new Unicode String Table.  It must hold the current number of\r
+  // entries, plus 1 entry for the new Unicode String, plus 1 entry for the end of table\r
+  // marker\r
+  //\r
+  NewUnicodeStringTable = AllocatePool ((NumberOfEntries + 2) * sizeof (EFI_UNICODE_STRING_TABLE));\r
+  if (NewUnicodeStringTable == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  //\r
+  // If the current Unicode String Table contains any entries, then copy them to the\r
+  // newly allocated Unicode String Table.\r
+  //\r
+  if (*UnicodeStringTable != NULL) {\r
+    CopyMem (\r
+      NewUnicodeStringTable,\r
+      *UnicodeStringTable,\r
+      NumberOfEntries * sizeof (EFI_UNICODE_STRING_TABLE)\r
+      );\r
+  }\r
+\r
+  //\r
+  // Allocate space for a copy of the Language specifier\r
+  //\r
+  NewUnicodeStringTable[NumberOfEntries].Language = AllocateCopyPool (AsciiStrSize(Language), Language);\r
+  if (NewUnicodeStringTable[NumberOfEntries].Language == NULL) {\r
+    gBS->FreePool (NewUnicodeStringTable);\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  //\r
+  // Compute the length of the Unicode String\r
+  //\r
+  for (UnicodeStringLength = 0; UnicodeString[UnicodeStringLength] != 0; UnicodeStringLength++);\r
+\r
+  //\r
+  // Allocate space for a copy of the Unicode String\r
+  //\r
+  NewUnicodeStringTable[NumberOfEntries].UnicodeString = AllocateCopyPool (StrSize (UnicodeString), UnicodeString);\r
+  if (NewUnicodeStringTable[NumberOfEntries].UnicodeString == NULL) {\r
+    gBS->FreePool (NewUnicodeStringTable[NumberOfEntries].Language);\r
+    gBS->FreePool (NewUnicodeStringTable);\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  //\r
+  // Mark the end of the Unicode String Table\r
+  //\r
+  NewUnicodeStringTable[NumberOfEntries + 1].Language       = NULL;\r
+  NewUnicodeStringTable[NumberOfEntries + 1].UnicodeString  = NULL;\r
+\r
+  //\r
+  // Free the old Unicode String Table\r
+  //\r
+  if (*UnicodeStringTable != NULL) {\r
+    gBS->FreePool (*UnicodeStringTable);\r
+  }\r
+\r
+  //\r
+  // Point UnicodeStringTable at the newly allocated Unicode String Table\r
+  //\r
+  *UnicodeStringTable = NewUnicodeStringTable;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
 /**\r
   This function frees the table of Unicode strings in UnicodeStringTable.\r
   If UnicodeStringTable is NULL, then EFI_SUCCESS is returned.\r
@@ -648,3 +1220,5 @@ FreeUnicodeStringTable (
 \r
   return EFI_SUCCESS;\r
 }\r
+\r
+\r