]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkPkg/Library/FrameworkUefiLib/UefiLib.c
Sync UefiLib instance in IntelFrameworkPkg with the one in MdePkg.
[mirror_edk2.git] / IntelFrameworkPkg / Library / FrameworkUefiLib / UefiLib.c
index 91b37d2ab3b38a1d0d293659ee3bd43b523f602b..e263a06f89b223095c13da3ec4ee2af536251161 100644 (file)
@@ -1,5 +1,9 @@
 /** @file\r
-  Implementation of UefiLib \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 - 2007, Intel Corporation<BR>\r
   All rights reserved. This program and the accompanying materials\r
@@ -12,7 +16,8 @@
 \r
 **/\r
 \r
-#include "FrameworkUefiLib.h"\r
+\r
+#include "UefiLibInternal.h"\r
 \r
 /**\r
   Compare whether two names of languages are identical.\r
@@ -40,10 +45,15 @@ CompareIso639LanguageCode (
 }\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
-  is returned.  If a matching GUID is not found, then EFI_NOT_FOUND is returned.\r
+  Retrieves a pointer to the system configuration table from the EFI System Table\r
+  based on a specified GUID.\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
+  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
@@ -78,16 +88,26 @@ 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
-  installed or reinstalled, the notification function is also executed.\r
+  Creates and returns a notification event and registers that event with all the protocol\r
+  instances specified by ProtocolGuid.\r
+\r
+  This function causes the notification function to be executed for every protocol of type\r
+  ProtocolGuid instance that exists in the system when this function is invoked.\r
+  In addition, every time a protocol of type ProtocolGuid instance is installed or reinstalled,\r
+  the notification function is also executed.  This function returns the notification event\r
+  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
+  If Registration is NULL, then ASSERT().\r
 \r
   @param  ProtocolGuid    Supplies GUID of the protocol upon whose installation the event is fired.\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  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
 \r
   @return The notification event that was created.\r
 \r
@@ -105,6 +125,10 @@ EfiCreateProtocolNotifyEvent(
   EFI_STATUS  Status;\r
   EFI_EVENT   Event;\r
 \r
+  ASSERT (ProtocolGuid != NULL);\r
+  ASSERT (NotifyFunction != NULL);\r
+  ASSERT (Registration != NULL);\r
+\r
   //\r
   // Create the event\r
   //\r
@@ -140,14 +164,19 @@ EfiCreateProtocolNotifyEvent(
 }\r
 \r
 /**\r
+  Creates a named event that can be signaled with EfiNamedEventSignal().\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
-  one or more listeners on the same event named by the GUID specified by Name.\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
+  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
@@ -168,6 +197,10 @@ EfiNamedEventListen (
   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
@@ -201,12 +234,15 @@ 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
-  have been created with EfiNamedEventListen().\r
+  Signals a named event created with EfiNamedEventListen().\r
+\r
+  This function signals the named event specified by Name. The named event must have been\r
+  created with EfiNamedEventListen().\r
+  If Name is NULL, then ASSERT().\r
 \r
   @param  Name                  Supplies GUID name of the event.\r
 \r
@@ -223,6 +259,8 @@ EfiNamedEventSignal (
   EFI_STATUS  Status;\r
   EFI_HANDLE  Handle;\r
 \r
+  ASSERT(Name != NULL);\r
+\r
   Handle = NULL;\r
   Status = gBS->InstallProtocolInterface (\r
                   &Handle,\r
@@ -239,16 +277,16 @@ EfiNamedEventSignal (
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  return EFI_SUCCESS;\r
+  return Status;\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
@@ -270,10 +308,14 @@ EfiGetCurrentTpl (
 \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
+  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
   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
@@ -298,11 +340,16 @@ EfiInitializeLock (
 }\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
+  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
   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  Lock  Point to EFI_LOCK instance\r
+  @param  Lock              A pointer to the lock to acquire.\r
 \r
 **/\r
 VOID\r
@@ -319,9 +366,14 @@ 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
-  lock in the acquired state.\r
+  Acquires ownership of a lock.\r
+\r
+  This function raises the system's current task priority level to the task priority\r
+  level of the mutual exclusion lock.  Then, it attempts to place the lock in the acquired state.\r
+  If the lock is already in the acquired state, then EFI_ACCESS_DENIED is returned.\r
+  Otherwise, EFI_SUCCESS is returned.\r
+  If Lock is NULL, then ASSERT().\r
+  If Lock is not initialized, then ASSERT().\r
 \r
   @param  Lock              A pointer to the lock to acquire.\r
 \r
@@ -354,9 +406,14 @@ 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
+  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
   previous level.\r
+  If Lock is NULL, then ASSERT().\r
+  If Lock is not initialized, then ASSERT().\r
+  If Lock is already in the released state, then ASSERT().\r
 \r
   @param  Lock  A pointer to the lock to release.\r
 \r
@@ -386,7 +443,7 @@ EfiReleaseLock (
   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
@@ -449,10 +506,10 @@ EfiTestManagedDevice (
   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
@@ -505,31 +562,32 @@ EfiTestChildHandle (
 }\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
-  UnicodeString.\r
+  This function looks up a Unicode string in UnicodeStringTable.\r
 \r
-  @param  Language                A pointer to the ISO 639-2 language code for the\r
+  If Language is a member of SupportedLanguages and a Unicode string is found in\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
                                   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 Unicoide strings UnicodeStringTable,\r
+                                  in the table of Unicoide 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_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
                                   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
@@ -588,15 +646,138 @@ LookupUnicodeString (
   return EFI_UNSUPPORTED;\r
 }\r
 \r
+\r
+\r
+/**\r
+  This function looks up a Unicode string in UnicodeStringTable.\r
+\r
+  If Language is a member of SupportedLanguages and a Unicode string is found in\r
+  UnicodeStringTable that matches the language code specified by Language, then\r
+  it is returned in UnicodeString.\r
+\r
+  @param  Language             A pointer to an ASCII string containing the ISO 639-2 or the\r
+                               RFC 4646 language code for the Unicode string to look up and\r
+                               return. If Iso639Language is TRUE, then this ASCII string is\r
+                               not assumed to be Null-terminated, and only the first three\r
+                               chacters are used. If Iso639Language is FALSE, then this ASCII\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
+                               If Iso639Language is TRUE, then this string contains one or more\r
+                               ISO 639-2 language codes with no separator characters. If Iso639Language\r
+                               is FALSE, then is string contains one or more RFC 4646 language\r
+                               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 Null-terminated Unicode string from UnicodeStringTable\r
+                               that matches the language specified by Language.\r
+  @param  Iso639Language       Specifies the supported language code format. If it is TRUE, then\r
+                               Language and SupportedLanguages follow ISO 639-2 language code format.\r
+                               Otherwise, they follow RFC 4646 language code format.\r
+\r
+\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_UNSUPPORTED        The language specified by Language is not supported by 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
   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
+\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
@@ -604,19 +785,19 @@ LookupUnicodeString (
   @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
@@ -754,10 +935,212 @@ AddUnicodeString (
   return EFI_UNSUPPORTED;\r
 }\r
 \r
+\r
+/**\r
+  This function adds the Null-terminated Unicode string specified by UnicodeString\r
+  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 UnicodeString.\r
+  The contents of Language and UnicodeString are copied into these new buffers.\r
+  These buffers are automatically freed when EfiLibFreeUnicodeStringTable() is called.\r
+\r
+  @param  Language            A pointer to an ASCII string containing the ISO 639-2 or\r
+                              the RFC 4646 language code for the Unicode string to add.\r
+                              If Iso639Language is TRUE, then this ASCII string is not\r
+                              assumed to be Null-terminated, and only the first three\r
+                              chacters are used. If Iso639Language is FALSE, then this\r
+                              ASCII string must be Null-terminated.\r
+  @param  SupportedLanguages  A pointer to a Null-terminated ASCII string that contains\r
+                              a 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
+                              If Iso639Language is TRUE, then this string contains one or more\r
+                              ISO 639-2 language codes with no separator characters.\r
+                              If Iso639Language is FALSE, then is string contains one or more\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  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
+  @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
+  @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
+  )\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
+\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
@@ -805,4 +1188,3 @@ FreeUnicodeStringTable (
 \r
   return EFI_SUCCESS;\r
 }\r
-\r