]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkPkg/Library/FrameworkUefiLib/UefiLib.c
Update the copyright notice format
[mirror_edk2.git] / IntelFrameworkPkg / Library / FrameworkUefiLib / UefiLib.c
CommitLineData
79964ac8 1/** @file\r
bf428cb3 2 The UEFI Library provides functions and macros that simplify the development of \r
3 UEFI Drivers and UEFI Applications. These functions and macros help manage EFI \r
4 events, build simple locks utilizing EFI Task Priority Levels (TPLs), install \r
5 EFI Driver Model related protocols, manage Unicode string tables for UEFI Drivers, \r
6 and print messages on the console output and standard error devices.\r
79964ac8 7\r
2b3687db
HT
8 Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>\r
9 This program and the accompanying materials\r
79964ac8 10 are licensed and made available under the terms and conditions of the BSD License\r
11 which accompanies this distribution. The full text of the license may be found at\r
12 http://opensource.org/licenses/bsd-license.php\r
13\r
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
16\r
79964ac8 17**/\r
18\r
bf428cb3 19\r
20#include "UefiLibInternal.h"\r
79964ac8 21\r
22/**\r
23 Compare whether two names of languages are identical.\r
24\r
25 @param Language1 Name of language 1.\r
26 @param Language2 Name of language 2.\r
27\r
28 @retval TRUE Language 1 and language 2 are the same.\r
29 @retval FALSE Language 1 and language 2 are not the same.\r
30\r
31**/\r
79964ac8 32BOOLEAN\r
33CompareIso639LanguageCode (\r
34 IN CONST CHAR8 *Language1,\r
35 IN CONST CHAR8 *Language2\r
36 )\r
37{\r
38 UINT32 Name1;\r
39 UINT32 Name2;\r
40\r
41 Name1 = ReadUnaligned24 ((CONST UINT32 *) Language1);\r
42 Name2 = ReadUnaligned24 ((CONST UINT32 *) Language2);\r
43\r
44 return (BOOLEAN) (Name1 == Name2);\r
45}\r
46\r
47/**\r
bf428cb3 48 Retrieves a pointer to the system configuration table from the EFI System Table\r
49 based on a specified GUID.\r
50 \r
51 This function searches the list of configuration tables stored in the EFI System Table\r
52 for a table with a GUID that matches TableGuid. If a match is found, then a pointer to\r
53 the configuration table is returned in Table., and EFI_SUCCESS is returned. If a matching GUID\r
54 is not found, then EFI_NOT_FOUND is returned.\r
55 If TableGuid is NULL, then ASSERT().\r
56 If Table is NULL, then ASSERT().\r
79964ac8 57\r
58 @param TableGuid Pointer to table's GUID type..\r
59 @param Table Pointer to the table associated with TableGuid in the EFI System Table.\r
60\r
61 @retval EFI_SUCCESS A configuration table matching TableGuid was found.\r
62 @retval EFI_NOT_FOUND A configuration table matching TableGuid could not be found.\r
63\r
64**/\r
65EFI_STATUS\r
66EFIAPI\r
67EfiGetSystemConfigurationTable (\r
68 IN EFI_GUID *TableGuid,\r
69 OUT VOID **Table\r
70 )\r
71{\r
72 EFI_SYSTEM_TABLE *SystemTable;\r
73 UINTN Index;\r
74\r
75 ASSERT (TableGuid != NULL);\r
76 ASSERT (Table != NULL);\r
77\r
78 SystemTable = gST;\r
79 *Table = NULL;\r
80 for (Index = 0; Index < SystemTable->NumberOfTableEntries; Index++) {\r
81 if (CompareGuid (TableGuid, &(SystemTable->ConfigurationTable[Index].VendorGuid))) {\r
82 *Table = SystemTable->ConfigurationTable[Index].VendorTable;\r
83 return EFI_SUCCESS;\r
84 }\r
85 }\r
86\r
87 return EFI_NOT_FOUND;\r
88}\r
89\r
90/**\r
bf428cb3 91 Creates and returns a notification event and registers that event with all the protocol\r
92 instances specified by ProtocolGuid.\r
93\r
94 This function causes the notification function to be executed for every protocol of type\r
95 ProtocolGuid instance that exists in the system when this function is invoked.\r
96 In addition, every time a protocol of type ProtocolGuid instance is installed or reinstalled,\r
97 the notification function is also executed. This function returns the notification event\r
98 that was created. \r
99 If ProtocolGuid is NULL, then ASSERT().\r
100 If NotifyTpl is not a legal TPL value, then ASSERT().\r
101 If NotifyFunction is NULL, then ASSERT().\r
102 If Registration is NULL, then ASSERT().\r
79964ac8 103\r
104 @param ProtocolGuid Supplies GUID of the protocol upon whose installation the event is fired.\r
105 @param NotifyTpl Supplies the task priority level of the event notifications.\r
106 @param NotifyFunction Supplies the function to notify when the event is signaled.\r
107 @param NotifyContext The context parameter to pass to NotifyFunction.\r
108 @param Registration A pointer to a memory location to receive the registration value.\r
bf428cb3 109 This value is passed to LocateHandle() to obtain new handles that\r
110 have been added that support the ProtocolGuid-specified protocol. \r
79964ac8 111\r
112 @return The notification event that was created.\r
113\r
114**/\r
115EFI_EVENT\r
116EFIAPI\r
117EfiCreateProtocolNotifyEvent(\r
118 IN EFI_GUID *ProtocolGuid,\r
119 IN EFI_TPL NotifyTpl,\r
120 IN EFI_EVENT_NOTIFY NotifyFunction,\r
121 IN VOID *NotifyContext, OPTIONAL\r
122 OUT VOID **Registration\r
123 )\r
124{\r
125 EFI_STATUS Status;\r
126 EFI_EVENT Event;\r
127\r
bf428cb3 128 ASSERT (ProtocolGuid != NULL);\r
129 ASSERT (NotifyFunction != NULL);\r
130 ASSERT (Registration != NULL);\r
131\r
79964ac8 132 //\r
133 // Create the event\r
134 //\r
135\r
136 Status = gBS->CreateEvent (\r
93b0fbc8 137 EVT_NOTIFY_SIGNAL,\r
79964ac8 138 NotifyTpl,\r
139 NotifyFunction,\r
140 NotifyContext,\r
141 &Event\r
142 );\r
143 ASSERT_EFI_ERROR (Status);\r
144\r
145 //\r
146 // Register for protocol notifactions on this event\r
147 //\r
148\r
149 Status = gBS->RegisterProtocolNotify (\r
150 ProtocolGuid,\r
151 Event,\r
152 Registration\r
153 );\r
154\r
155 ASSERT_EFI_ERROR (Status);\r
156\r
157 //\r
158 // Kick the event so we will perform an initial pass of\r
159 // current installed drivers\r
160 //\r
161\r
162 gBS->SignalEvent (Event);\r
163 return Event;\r
164}\r
165\r
166/**\r
bf428cb3 167 Creates a named event that can be signaled with EfiNamedEventSignal().\r
168\r
79964ac8 169 This function creates an event using NotifyTpl, NoifyFunction, and NotifyContext.\r
bf428cb3 170 This event is signaled with EfiNamedEventSignal(). This provides the ability for one or more\r
171 listeners on the same event named by the GUID specified by Name. \r
172 If Name is NULL, then ASSERT().\r
173 If NotifyTpl is not a legal TPL value, then ASSERT().\r
174 If NotifyFunction is NULL, then ASSERT().\r
79964ac8 175\r
176 @param Name Supplies GUID name of the event.\r
177 @param NotifyTpl Supplies the task priority level of the event notifications.\r
178 @param NotifyFunction Supplies the function to notify when the event is signaled.\r
bf428cb3 179 @param NotifyContext The context parameter to pass to NotifyFunction. \r
79964ac8 180 @param Registration A pointer to a memory location to receive the registration value.\r
181\r
182 @retval EFI_SUCCESS A named event was created.\r
183 @retval EFI_OUT_OF_RESOURCES There are not enough resource to create the named event.\r
184\r
185**/\r
186EFI_STATUS\r
187EFIAPI\r
188EfiNamedEventListen (\r
189 IN CONST EFI_GUID *Name,\r
190 IN EFI_TPL NotifyTpl,\r
191 IN EFI_EVENT_NOTIFY NotifyFunction,\r
192 IN CONST VOID *NotifyContext, OPTIONAL\r
193 OUT VOID *Registration OPTIONAL\r
194 )\r
195{\r
196 EFI_STATUS Status;\r
197 EFI_EVENT Event;\r
198 VOID *RegistrationLocal;\r
199\r
bf428cb3 200 ASSERT (Name != NULL);\r
201 ASSERT (NotifyFunction != NULL);\r
202 ASSERT (NotifyTpl <= TPL_HIGH_LEVEL);\r
203 \r
79964ac8 204 //\r
205 // Create event\r
206 //\r
207 Status = gBS->CreateEvent (\r
93b0fbc8 208 EVT_NOTIFY_SIGNAL,\r
79964ac8 209 NotifyTpl,\r
210 NotifyFunction,\r
211 (VOID *) NotifyContext,\r
212 &Event\r
213 );\r
214 ASSERT_EFI_ERROR (Status);\r
215\r
216 //\r
217 // The Registration is not optional to RegisterProtocolNotify().\r
218 // To make it optional to EfiNamedEventListen(), may need to substitute with a local.\r
219 //\r
220 if (Registration != NULL) {\r
221 RegistrationLocal = Registration;\r
222 } else {\r
223 RegistrationLocal = &RegistrationLocal;\r
224 }\r
225\r
226 //\r
227 // Register for an installation of protocol interface\r
228 //\r
229\r
230 Status = gBS->RegisterProtocolNotify (\r
231 (EFI_GUID *) Name,\r
232 Event,\r
233 RegistrationLocal\r
234 );\r
235 ASSERT_EFI_ERROR (Status);\r
236\r
bf428cb3 237 return Status;\r
79964ac8 238}\r
239\r
240/**\r
bf428cb3 241 Signals a named event created with EfiNamedEventListen().\r
242\r
243 This function signals the named event specified by Name. The named event must have been\r
244 created with EfiNamedEventListen().\r
245 If Name is NULL, then ASSERT().\r
79964ac8 246\r
247 @param Name Supplies GUID name of the event.\r
248\r
249 @retval EFI_SUCCESS A named event was signaled.\r
250 @retval EFI_OUT_OF_RESOURCES There are not enough resource to signal the named event.\r
251\r
252**/\r
253EFI_STATUS\r
254EFIAPI\r
255EfiNamedEventSignal (\r
256 IN CONST EFI_GUID *Name\r
257 )\r
258{\r
259 EFI_STATUS Status;\r
260 EFI_HANDLE Handle;\r
261\r
bf428cb3 262 ASSERT(Name != NULL);\r
263\r
79964ac8 264 Handle = NULL;\r
265 Status = gBS->InstallProtocolInterface (\r
266 &Handle,\r
267 (EFI_GUID *) Name,\r
268 EFI_NATIVE_INTERFACE,\r
269 NULL\r
270 );\r
271 ASSERT_EFI_ERROR (Status);\r
272\r
273 Status = gBS->UninstallProtocolInterface (\r
274 Handle,\r
275 (EFI_GUID *) Name,\r
276 NULL\r
277 );\r
278 ASSERT_EFI_ERROR (Status);\r
279\r
bf428cb3 280 return Status;\r
79964ac8 281}\r
282\r
bf428cb3 283/** \r
79964ac8 284 Returns the current TPL.\r
285\r
bf428cb3 286 This function returns the current TPL. There is no EFI service to directly \r
287 retrieve the current TPL. Instead, the RaiseTPL() function is used to raise \r
288 the TPL to TPL_HIGH_LEVEL. This will return the current TPL. The TPL level \r
289 can then immediately be restored back to the current TPL level with a call \r
79964ac8 290 to RestoreTPL().\r
291\r
7459094d 292 @return The current TPL.\r
79964ac8 293\r
294**/\r
295EFI_TPL\r
296EFIAPI\r
297EfiGetCurrentTpl (\r
298 VOID\r
299 )\r
300{\r
301 EFI_TPL Tpl;\r
302\r
93b0fbc8 303 Tpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r
79964ac8 304 gBS->RestoreTPL (Tpl);\r
305\r
306 return Tpl;\r
307}\r
308\r
309\r
310/**\r
bf428cb3 311 Initializes a basic mutual exclusion lock.\r
312\r
313 This function initializes a basic mutual exclusion lock to the released state \r
314 and returns the lock. Each lock provides mutual exclusion access at its task \r
79964ac8 315 priority level. Since there is no preemption or multiprocessor support in EFI,\r
316 acquiring the lock only consists of raising to the locks TPL.\r
bf428cb3 317 If Lock is NULL, then ASSERT().\r
318 If Priority is not a valid TPL value, then ASSERT().\r
79964ac8 319\r
320 @param Lock A pointer to the lock data structure to initialize.\r
321 @param Priority EFI TPL associated with the lock.\r
322\r
323 @return The lock.\r
324\r
325**/\r
326EFI_LOCK *\r
327EFIAPI\r
328EfiInitializeLock (\r
329 IN OUT EFI_LOCK *Lock,\r
330 IN EFI_TPL Priority\r
331 )\r
332{\r
333 ASSERT (Lock != NULL);\r
93b0fbc8 334 ASSERT (Priority <= TPL_HIGH_LEVEL);\r
79964ac8 335\r
336 Lock->Tpl = Priority;\r
93b0fbc8 337 Lock->OwnerTpl = TPL_APPLICATION;\r
79964ac8 338 Lock->Lock = EfiLockReleased ;\r
339 return Lock;\r
340}\r
341\r
342/**\r
bf428cb3 343 Acquires ownership of a lock.\r
344\r
345 This function raises the system's current task priority level to the task \r
346 priority level of the mutual exclusion lock. Then, it places the lock in the \r
79964ac8 347 acquired state.\r
bf428cb3 348 If Lock is NULL, then ASSERT().\r
349 If Lock is not initialized, then ASSERT().\r
350 If Lock is already in the acquired state, then ASSERT().\r
79964ac8 351\r
bf428cb3 352 @param Lock A pointer to the lock to acquire.\r
79964ac8 353\r
354**/\r
355VOID\r
356EFIAPI\r
357EfiAcquireLock (\r
358 IN EFI_LOCK *Lock\r
359 )\r
360{\r
361 ASSERT (Lock != NULL);\r
362 ASSERT (Lock->Lock == EfiLockReleased);\r
363\r
364 Lock->OwnerTpl = gBS->RaiseTPL (Lock->Tpl);\r
365 Lock->Lock = EfiLockAcquired;\r
366}\r
367\r
368/**\r
bf428cb3 369 Acquires ownership of a lock.\r
370\r
371 This function raises the system's current task priority level to the task priority\r
372 level of the mutual exclusion lock. Then, it attempts to place the lock in the acquired state.\r
373 If the lock is already in the acquired state, then EFI_ACCESS_DENIED is returned.\r
374 Otherwise, EFI_SUCCESS is returned.\r
375 If Lock is NULL, then ASSERT().\r
376 If Lock is not initialized, then ASSERT().\r
79964ac8 377\r
378 @param Lock A pointer to the lock to acquire.\r
379\r
380 @retval EFI_SUCCESS The lock was acquired.\r
381 @retval EFI_ACCESS_DENIED The lock could not be acquired because it is already owned.\r
382\r
383**/\r
384EFI_STATUS\r
385EFIAPI\r
386EfiAcquireLockOrFail (\r
387 IN EFI_LOCK *Lock\r
388 )\r
389{\r
390\r
391 ASSERT (Lock != NULL);\r
392 ASSERT (Lock->Lock != EfiLockUninitialized);\r
393\r
394 if (Lock->Lock == EfiLockAcquired) {\r
395 //\r
396 // Lock is already owned, so bail out\r
397 //\r
398 return EFI_ACCESS_DENIED;\r
399 }\r
400\r
401 Lock->OwnerTpl = gBS->RaiseTPL (Lock->Tpl);\r
402\r
403 Lock->Lock = EfiLockAcquired;\r
404\r
405 return EFI_SUCCESS;\r
406}\r
407\r
408/**\r
bf428cb3 409 Releases ownership of a lock.\r
410\r
411 This function transitions a mutual exclusion lock from the acquired state to \r
412 the released state, and restores the system's task priority level to its \r
79964ac8 413 previous level.\r
bf428cb3 414 If Lock is NULL, then ASSERT().\r
415 If Lock is not initialized, then ASSERT().\r
416 If Lock is already in the released state, then ASSERT().\r
79964ac8 417\r
418 @param Lock A pointer to the lock to release.\r
419\r
420**/\r
421VOID\r
422EFIAPI\r
423EfiReleaseLock (\r
424 IN EFI_LOCK *Lock\r
425 )\r
426{\r
427 EFI_TPL Tpl;\r
428\r
429 ASSERT (Lock != NULL);\r
430 ASSERT (Lock->Lock == EfiLockAcquired);\r
431\r
432 Tpl = Lock->OwnerTpl;\r
433\r
434 Lock->Lock = EfiLockReleased;\r
435\r
436 gBS->RestoreTPL (Tpl);\r
437}\r
438\r
b51e6bc4 439/**\r
440 Tests whether a controller handle is being managed by a specific driver.\r
441\r
79964ac8 442 This function tests whether the driver specified by DriverBindingHandle is\r
443 currently managing the controller specified by ControllerHandle. This test\r
444 is performed by evaluating if the the protocol specified by ProtocolGuid is\r
445 present on ControllerHandle and is was opened by DriverBindingHandle with an\r
bf428cb3 446 attribute of EFI_OPEN_PROTOCOL_BY_DRIVER. \r
79964ac8 447 If ProtocolGuid is NULL, then ASSERT().\r
b51e6bc4 448\r
449 @param ControllerHandle A handle for a controller to test.\r
450 @param DriverBindingHandle Specifies the driver binding handle for the\r
451 driver.\r
452 @param ProtocolGuid Specifies the protocol that the driver specified\r
453 by DriverBindingHandle opens in its Start()\r
454 function.\r
455\r
456 @retval EFI_SUCCESS ControllerHandle is managed by the driver\r
457 specifed by DriverBindingHandle.\r
458 @retval EFI_UNSUPPORTED ControllerHandle is not managed by the driver\r
459 specifed by DriverBindingHandle.\r
460\r
79964ac8 461**/\r
462EFI_STATUS\r
463EFIAPI\r
464EfiTestManagedDevice (\r
465 IN CONST EFI_HANDLE ControllerHandle,\r
466 IN CONST EFI_HANDLE DriverBindingHandle,\r
467 IN CONST EFI_GUID *ProtocolGuid\r
468 )\r
469{\r
470 EFI_STATUS Status;\r
471 VOID *ManagedInterface;\r
472\r
473 ASSERT (ProtocolGuid != NULL);\r
474\r
475 Status = gBS->OpenProtocol (\r
476 ControllerHandle,\r
477 (EFI_GUID *) ProtocolGuid,\r
478 &ManagedInterface,\r
479 DriverBindingHandle,\r
480 ControllerHandle,\r
481 EFI_OPEN_PROTOCOL_BY_DRIVER\r
482 );\r
483 if (!EFI_ERROR (Status)) {\r
484 gBS->CloseProtocol (\r
485 ControllerHandle,\r
486 (EFI_GUID *) ProtocolGuid,\r
487 DriverBindingHandle,\r
488 ControllerHandle\r
489 );\r
490 return EFI_UNSUPPORTED;\r
491 }\r
492\r
493 if (Status != EFI_ALREADY_STARTED) {\r
494 return EFI_UNSUPPORTED;\r
495 }\r
496\r
497 return EFI_SUCCESS;\r
498}\r
499\r
b51e6bc4 500/**\r
501 Tests whether a child handle is a child device of the controller.\r
502\r
79964ac8 503 This function tests whether ChildHandle is one of the children of\r
504 ControllerHandle. This test is performed by checking to see if the protocol\r
505 specified by ProtocolGuid is present on ControllerHandle and opened by\r
506 ChildHandle with an attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
507 If ProtocolGuid is NULL, then ASSERT().\r
b51e6bc4 508\r
bf428cb3 509 @param ControllerHandle A handle for a (parent) controller to test. \r
b51e6bc4 510 @param ChildHandle A child handle to test.\r
7459094d 511 @param ProtocolGuid Supplies the protocol that the child controller\r
bf428cb3 512 opens on its parent controller. \r
b51e6bc4 513\r
514 @retval EFI_SUCCESS ChildHandle is a child of the ControllerHandle.\r
515 @retval EFI_UNSUPPORTED ChildHandle is not a child of the\r
516 ControllerHandle.\r
517\r
79964ac8 518**/\r
519EFI_STATUS\r
520EFIAPI\r
521EfiTestChildHandle (\r
522 IN CONST EFI_HANDLE ControllerHandle,\r
523 IN CONST EFI_HANDLE ChildHandle,\r
524 IN CONST EFI_GUID *ProtocolGuid\r
525 )\r
526{\r
527 EFI_STATUS Status;\r
528 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;\r
529 UINTN EntryCount;\r
530 UINTN Index;\r
531\r
532 ASSERT (ProtocolGuid != NULL);\r
533\r
534 //\r
535 // Retrieve the list of agents that are consuming the specific protocol\r
536 // on ControllerHandle.\r
537 //\r
538 Status = gBS->OpenProtocolInformation (\r
539 ControllerHandle,\r
540 (EFI_GUID *) ProtocolGuid,\r
541 &OpenInfoBuffer,\r
542 &EntryCount\r
543 );\r
544 if (EFI_ERROR (Status)) {\r
545 return EFI_UNSUPPORTED;\r
546 }\r
547\r
548 //\r
549 // Inspect if ChildHandle is one of the agents.\r
550 //\r
551 Status = EFI_UNSUPPORTED;\r
552 for (Index = 0; Index < EntryCount; Index++) {\r
553 if ((OpenInfoBuffer[Index].ControllerHandle == ChildHandle) &&\r
554 (OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {\r
555 Status = EFI_SUCCESS;\r
556 break;\r
557 }\r
558 }\r
559\r
560 FreePool (OpenInfoBuffer);\r
561 return Status;\r
562}\r
563\r
564/**\r
bf428cb3 565 This function looks up a Unicode string in UnicodeStringTable.\r
79964ac8 566\r
bf428cb3 567 If Language is a member of SupportedLanguages and a Unicode string is found in\r
568 UnicodeStringTable that matches the language code specified by Language, then it\r
569 is returned in UnicodeString.\r
570\r
571 @param Language A pointer to the ISO 639-2 language code for the \r
79964ac8 572 Unicode string to look up and return.\r
bf428cb3 573 @param SupportedLanguages A pointer to the set of ISO 639-2 language codes \r
574 that the Unicode string table supports. Language \r
79964ac8 575 must be a member of this set.\r
576 @param UnicodeStringTable A pointer to the table of Unicode strings.\r
577 @param UnicodeString A pointer to the Unicode string from UnicodeStringTable\r
578 that matches the language specified by Language.\r
579\r
bf428cb3 580 @retval EFI_SUCCESS The Unicode string that matches the language \r
79964ac8 581 specified by Language was found\r
bf428cb3 582 in the table of Unicoide strings UnicodeStringTable, \r
79964ac8 583 and it was returned in UnicodeString.\r
bf428cb3 584 @retval EFI_INVALID_PARAMETER Language is NULL.\r
585 @retval EFI_INVALID_PARAMETER UnicodeString is NULL.\r
586 @retval EFI_UNSUPPORTED SupportedLanguages is NULL.\r
587 @retval EFI_UNSUPPORTED UnicodeStringTable is NULL.\r
588 @retval EFI_UNSUPPORTED The language specified by Language is not a \r
79964ac8 589 member of SupportedLanguages.\r
bf428cb3 590 @retval EFI_UNSUPPORTED The language specified by Language is not \r
79964ac8 591 supported by UnicodeStringTable.\r
592\r
593**/\r
594EFI_STATUS\r
595EFIAPI\r
596LookupUnicodeString (\r
597 IN CONST CHAR8 *Language,\r
598 IN CONST CHAR8 *SupportedLanguages,\r
599 IN CONST EFI_UNICODE_STRING_TABLE *UnicodeStringTable,\r
600 OUT CHAR16 **UnicodeString\r
601 )\r
602{\r
603 //\r
604 // Make sure the parameters are valid\r
605 //\r
606 if (Language == NULL || UnicodeString == NULL) {\r
607 return EFI_INVALID_PARAMETER;\r
608 }\r
609\r
610 //\r
611 // If there are no supported languages, or the Unicode String Table is empty, then the\r
612 // Unicode String specified by Language is not supported by this Unicode String Table\r
613 //\r
614 if (SupportedLanguages == NULL || UnicodeStringTable == NULL) {\r
615 return EFI_UNSUPPORTED;\r
616 }\r
617\r
618 //\r
619 // Make sure Language is in the set of Supported Languages\r
620 //\r
621 while (*SupportedLanguages != 0) {\r
622 if (CompareIso639LanguageCode (Language, SupportedLanguages)) {\r
623\r
624 //\r
625 // Search the Unicode String Table for the matching Language specifier\r
626 //\r
627 while (UnicodeStringTable->Language != NULL) {\r
628 if (CompareIso639LanguageCode (Language, UnicodeStringTable->Language)) {\r
629\r
630 //\r
631 // A matching string was found, so return it\r
632 //\r
633 *UnicodeString = UnicodeStringTable->UnicodeString;\r
634 return EFI_SUCCESS;\r
635 }\r
636\r
637 UnicodeStringTable++;\r
638 }\r
639\r
640 return EFI_UNSUPPORTED;\r
641 }\r
642\r
643 SupportedLanguages += 3;\r
644 }\r
645\r
646 return EFI_UNSUPPORTED;\r
647}\r
648\r
bf428cb3 649\r
650\r
651/**\r
652 This function looks up a Unicode string in UnicodeStringTable.\r
653\r
654 If Language is a member of SupportedLanguages and a Unicode string is found in\r
655 UnicodeStringTable that matches the language code specified by Language, then\r
656 it is returned in UnicodeString.\r
657\r
658 @param Language A pointer to an ASCII string containing the ISO 639-2 or the\r
659 RFC 4646 language code for the Unicode string to look up and\r
660 return. If Iso639Language is TRUE, then this ASCII string is\r
661 not assumed to be Null-terminated, and only the first three\r
662 chacters are used. If Iso639Language is FALSE, then this ASCII\r
663 string must be Null-terminated. \r
664 @param SupportedLanguages A pointer to a Null-terminated ASCII string that contains a\r
665 set of ISO 639-2 or RFC 4646 language codes that the Unicode\r
666 string table supports. Language must be a member of this set.\r
667 If Iso639Language is TRUE, then this string contains one or more\r
668 ISO 639-2 language codes with no separator characters. If Iso639Language\r
669 is FALSE, then is string contains one or more RFC 4646 language\r
670 codes separated by ';'.\r
671 @param UnicodeStringTable A pointer to the table of Unicode strings. Type EFI_UNICODE_STRING_TABLE\r
672 is defined in "Related Definitions".\r
673 @param UnicodeString A pointer to the Null-terminated Unicode string from UnicodeStringTable\r
674 that matches the language specified by Language.\r
675 @param Iso639Language Specifies the supported language code format. If it is TRUE, then\r
676 Language and SupportedLanguages follow ISO 639-2 language code format.\r
677 Otherwise, they follow RFC 4646 language code format.\r
678\r
679\r
680 @retval EFI_SUCCESS The Unicode string that matches the language specified by Language\r
681 was found in the table of Unicode strings UnicodeStringTable, and\r
682 it was returned in UnicodeString.\r
683 @retval EFI_INVALID_PARAMETER Language is NULL. \r
684 @retval EFI_INVALID_PARAMETER UnicodeString is NULL. \r
685 @retval EFI_UNSUPPORTED SupportedLanguages is NULL. \r
686 @retval EFI_UNSUPPORTED UnicodeStringTable is NULL. \r
687 @retval EFI_UNSUPPORTED The language specified by Language is not a member of SupportedLanguages. \r
688 @retval EFI_UNSUPPORTED The language specified by Language is not supported by UnicodeStringTable.\r
689\r
690**/\r
691EFI_STATUS\r
692\r
693EFIAPI\r
694LookupUnicodeString2 (\r
695 IN CONST CHAR8 *Language,\r
696 IN CONST CHAR8 *SupportedLanguages,\r
697 IN CONST EFI_UNICODE_STRING_TABLE *UnicodeStringTable,\r
698 OUT CHAR16 **UnicodeString,\r
699 IN BOOLEAN Iso639Language\r
700 )\r
701{\r
702 BOOLEAN Found;\r
703 UINTN Index;\r
704 CHAR8 *LanguageString;\r
705\r
706 //\r
707 // Make sure the parameters are valid\r
708 //\r
709 if (Language == NULL || UnicodeString == NULL) {\r
710 return EFI_INVALID_PARAMETER;\r
711 }\r
712\r
713 //\r
714 // If there are no supported languages, or the Unicode String Table is empty, then the\r
715 // Unicode String specified by Language is not supported by this Unicode String Table\r
716 //\r
717 if (SupportedLanguages == NULL || UnicodeStringTable == NULL) {\r
718 return EFI_UNSUPPORTED;\r
719 }\r
720\r
721 //\r
722 // Make sure Language is in the set of Supported Languages\r
723 //\r
724 Found = FALSE;\r
725 while (*SupportedLanguages != 0) {\r
726 if (Iso639Language) {\r
727 if (CompareIso639LanguageCode (Language, SupportedLanguages)) {\r
728 Found = TRUE;\r
729 break;\r
730 }\r
731 SupportedLanguages += 3;\r
732 } else {\r
733 for (Index = 0; SupportedLanguages[Index] != 0 && SupportedLanguages[Index] != ';'; Index++);\r
734 if ((AsciiStrnCmp(SupportedLanguages, Language, Index) == 0) && (Language[Index] == 0)) {\r
735 Found = TRUE;\r
736 break;\r
737 }\r
738 SupportedLanguages += Index;\r
739 for (; *SupportedLanguages != 0 && *SupportedLanguages == ';'; SupportedLanguages++);\r
740 }\r
741 }\r
742\r
743 //\r
744 // If Language is not a member of SupportedLanguages, then return EFI_UNSUPPORTED\r
745 //\r
746 if (!Found) {\r
747 return EFI_UNSUPPORTED;\r
748 }\r
749\r
750 //\r
751 // Search the Unicode String Table for the matching Language specifier\r
752 //\r
753 while (UnicodeStringTable->Language != NULL) {\r
754 LanguageString = UnicodeStringTable->Language;\r
755 while (0 != *LanguageString) {\r
756 for (Index = 0 ;LanguageString[Index] != 0 && LanguageString[Index] != ';'; Index++);\r
757 if (AsciiStrnCmp(LanguageString, Language, Index) == 0) {\r
758 *UnicodeString = UnicodeStringTable->UnicodeString;\r
759 return EFI_SUCCESS;\r
760 }\r
761 LanguageString += Index;\r
762 for (Index = 0 ;LanguageString[Index] != 0 && LanguageString[Index] == ';'; Index++);\r
763 }\r
764 UnicodeStringTable++;\r
765 }\r
766\r
767 return EFI_UNSUPPORTED;\r
768}\r
769\r
770\r
79964ac8 771/**\r
772 This function adds a Unicode string to UnicodeStringTable.\r
bf428cb3 773\r
774 If Language is a member of SupportedLanguages then UnicodeString is added to \r
775 UnicodeStringTable. New buffers are allocated for both Language and \r
776 UnicodeString. The contents of Language and UnicodeString are copied into \r
777 these new buffers. These buffers are automatically freed when \r
79964ac8 778 FreeUnicodeStringTable() is called.\r
779\r
bf428cb3 780 @param Language A pointer to the ISO 639-2 language code for the Unicode \r
79964ac8 781 string to add.\r
782 @param SupportedLanguages A pointer to the set of ISO 639-2 language codes\r
783 that the Unicode string table supports.\r
784 Language must be a member of this set.\r
785 @param UnicodeStringTable A pointer to the table of Unicode strings.\r
786 @param UnicodeString A pointer to the Unicode string to add.\r
787\r
bf428cb3 788 @retval EFI_SUCCESS The Unicode string that matches the language \r
789 specified by Language was found in the table of \r
790 Unicode strings UnicodeStringTable, and it was \r
79964ac8 791 returned in UnicodeString.\r
792 @retval EFI_INVALID_PARAMETER Language is NULL.\r
793 @retval EFI_INVALID_PARAMETER UnicodeString is NULL.\r
794 @retval EFI_INVALID_PARAMETER UnicodeString is an empty string.\r
795 @retval EFI_UNSUPPORTED SupportedLanguages is NULL.\r
bf428cb3 796 @retval EFI_ALREADY_STARTED A Unicode string with language Language is \r
79964ac8 797 already present in UnicodeStringTable.\r
bf428cb3 798 @retval EFI_OUT_OF_RESOURCES There is not enough memory to add another \r
79964ac8 799 Unicode string to UnicodeStringTable.\r
bf428cb3 800 @retval EFI_UNSUPPORTED The language specified by Language is not a \r
79964ac8 801 member of SupportedLanguages.\r
802\r
803**/\r
804EFI_STATUS\r
805EFIAPI\r
806AddUnicodeString (\r
807 IN CONST CHAR8 *Language,\r
808 IN CONST CHAR8 *SupportedLanguages,\r
809 IN EFI_UNICODE_STRING_TABLE **UnicodeStringTable,\r
810 IN CONST CHAR16 *UnicodeString\r
811 )\r
812{\r
813 UINTN NumberOfEntries;\r
814 EFI_UNICODE_STRING_TABLE *OldUnicodeStringTable;\r
815 EFI_UNICODE_STRING_TABLE *NewUnicodeStringTable;\r
816 UINTN UnicodeStringLength;\r
817\r
818 //\r
819 // Make sure the parameter are valid\r
820 //\r
821 if (Language == NULL || UnicodeString == NULL || UnicodeStringTable == NULL) {\r
822 return EFI_INVALID_PARAMETER;\r
823 }\r
824\r
825 //\r
826 // If there are no supported languages, then a Unicode String can not be added\r
827 //\r
828 if (SupportedLanguages == NULL) {\r
829 return EFI_UNSUPPORTED;\r
830 }\r
831\r
832 //\r
833 // If the Unicode String is empty, then a Unicode String can not be added\r
834 //\r
835 if (UnicodeString[0] == 0) {\r
836 return EFI_INVALID_PARAMETER;\r
837 }\r
838\r
839 //\r
840 // Make sure Language is a member of SupportedLanguages\r
841 //\r
842 while (*SupportedLanguages != 0) {\r
843 if (CompareIso639LanguageCode (Language, SupportedLanguages)) {\r
844\r
845 //\r
846 // Determine the size of the Unicode String Table by looking for a NULL Language entry\r
847 //\r
848 NumberOfEntries = 0;\r
849 if (*UnicodeStringTable != NULL) {\r
850 OldUnicodeStringTable = *UnicodeStringTable;\r
851 while (OldUnicodeStringTable->Language != NULL) {\r
852 if (CompareIso639LanguageCode (Language, OldUnicodeStringTable->Language)) {\r
853 return EFI_ALREADY_STARTED;\r
854 }\r
855\r
856 OldUnicodeStringTable++;\r
857 NumberOfEntries++;\r
858 }\r
859 }\r
860\r
861 //\r
862 // Allocate space for a new Unicode String Table. It must hold the current number of\r
863 // entries, plus 1 entry for the new Unicode String, plus 1 entry for the end of table\r
864 // marker\r
865 //\r
866 NewUnicodeStringTable = AllocatePool ((NumberOfEntries + 2) * sizeof (EFI_UNICODE_STRING_TABLE));\r
867 if (NewUnicodeStringTable == NULL) {\r
868 return EFI_OUT_OF_RESOURCES;\r
869 }\r
870\r
871 //\r
872 // If the current Unicode String Table contains any entries, then copy them to the\r
873 // newly allocated Unicode String Table.\r
874 //\r
875 if (*UnicodeStringTable != NULL) {\r
876 CopyMem (\r
877 NewUnicodeStringTable,\r
878 *UnicodeStringTable,\r
879 NumberOfEntries * sizeof (EFI_UNICODE_STRING_TABLE)\r
880 );\r
881 }\r
882\r
883 //\r
884 // Allocate space for a copy of the Language specifier\r
885 //\r
886 NewUnicodeStringTable[NumberOfEntries].Language = AllocateCopyPool (3, Language);\r
887 if (NewUnicodeStringTable[NumberOfEntries].Language == NULL) {\r
888 gBS->FreePool (NewUnicodeStringTable);\r
889 return EFI_OUT_OF_RESOURCES;\r
890 }\r
891\r
892 //\r
893 // Compute the length of the Unicode String\r
894 //\r
895 for (UnicodeStringLength = 0; UnicodeString[UnicodeStringLength] != 0; UnicodeStringLength++)\r
896 ;\r
897\r
898 //\r
899 // Allocate space for a copy of the Unicode String\r
900 //\r
901 NewUnicodeStringTable[NumberOfEntries].UnicodeString = AllocateCopyPool (\r
902 (UnicodeStringLength + 1) * sizeof (CHAR16),\r
903 UnicodeString\r
904 );\r
905 if (NewUnicodeStringTable[NumberOfEntries].UnicodeString == NULL) {\r
906 gBS->FreePool (NewUnicodeStringTable[NumberOfEntries].Language);\r
907 gBS->FreePool (NewUnicodeStringTable);\r
908 return EFI_OUT_OF_RESOURCES;\r
909 }\r
910\r
911 //\r
912 // Mark the end of the Unicode String Table\r
913 //\r
914 NewUnicodeStringTable[NumberOfEntries + 1].Language = NULL;\r
915 NewUnicodeStringTable[NumberOfEntries + 1].UnicodeString = NULL;\r
916\r
917 //\r
918 // Free the old Unicode String Table\r
919 //\r
920 if (*UnicodeStringTable != NULL) {\r
921 gBS->FreePool (*UnicodeStringTable);\r
922 }\r
923\r
924 //\r
925 // Point UnicodeStringTable at the newly allocated Unicode String Table\r
926 //\r
927 *UnicodeStringTable = NewUnicodeStringTable;\r
928\r
929 return EFI_SUCCESS;\r
930 }\r
931\r
932 SupportedLanguages += 3;\r
933 }\r
934\r
935 return EFI_UNSUPPORTED;\r
936}\r
937\r
bf428cb3 938\r
939/**\r
940 This function adds the Null-terminated Unicode string specified by UnicodeString\r
941 to UnicodeStringTable.\r
942\r
943 If Language is a member of SupportedLanguages then UnicodeString is added to\r
944 UnicodeStringTable. New buffers are allocated for both Language and UnicodeString.\r
945 The contents of Language and UnicodeString are copied into these new buffers.\r
946 These buffers are automatically freed when EfiLibFreeUnicodeStringTable() is called.\r
947\r
948 @param Language A pointer to an ASCII string containing the ISO 639-2 or\r
949 the RFC 4646 language code for the Unicode string to add.\r
950 If Iso639Language is TRUE, then this ASCII string is not\r
951 assumed to be Null-terminated, and only the first three\r
952 chacters are used. If Iso639Language is FALSE, then this\r
953 ASCII string must be Null-terminated.\r
954 @param SupportedLanguages A pointer to a Null-terminated ASCII string that contains\r
955 a set of ISO 639-2 or RFC 4646 language codes that the Unicode\r
956 string table supports. Language must be a member of this set.\r
957 If Iso639Language is TRUE, then this string contains one or more\r
958 ISO 639-2 language codes with no separator characters.\r
959 If Iso639Language is FALSE, then is string contains one or more\r
960 RFC 4646 language codes separated by ';'.\r
961 @param UnicodeStringTable A pointer to the table of Unicode strings. Type EFI_UNICODE_STRING_TABLE\r
962 is defined in "Related Definitions".\r
963 @param UnicodeString A pointer to the Unicode string to add. \r
964 @param Iso639Language Specifies the supported language code format. If it is TRUE,\r
965 then Language and SupportedLanguages follow ISO 639-2 language code format.\r
966 Otherwise, they follow RFC 4646 language code format.\r
967\r
968 @retval EFI_SUCCESS The Unicode string that matches the language specified by\r
969 Language was found in the table of Unicode strings UnicodeStringTable,\r
970 and it was returned in UnicodeString. \r
971 @retval EFI_INVALID_PARAMETER Language is NULL. \r
972 @retval EFI_INVALID_PARAMETER UnicodeString is NULL. \r
973 @retval EFI_INVALID_PARAMETER UnicodeString is an empty string. \r
974 @retval EFI_UNSUPPORTED SupportedLanguages is NULL. \r
975 @retval EFI_ALREADY_STARTED A Unicode string with language Language is already present in\r
976 UnicodeStringTable. \r
977 @retval EFI_OUT_OF_RESOURCES There is not enough memory to add another Unicode string UnicodeStringTable. \r
978 @retval EFI_UNSUPPORTED The language specified by Language is not a member of SupportedLanguages.\r
979\r
980**/\r
981EFI_STATUS\r
982EFIAPI\r
983AddUnicodeString2 (\r
984 IN CONST CHAR8 *Language,\r
985 IN CONST CHAR8 *SupportedLanguages,\r
986 IN EFI_UNICODE_STRING_TABLE **UnicodeStringTable,\r
987 IN CONST CHAR16 *UnicodeString,\r
988 IN BOOLEAN Iso639Language\r
989 )\r
990{\r
991 UINTN NumberOfEntries;\r
992 EFI_UNICODE_STRING_TABLE *OldUnicodeStringTable;\r
993 EFI_UNICODE_STRING_TABLE *NewUnicodeStringTable;\r
994 UINTN UnicodeStringLength;\r
995 BOOLEAN Found;\r
996 UINTN Index;\r
997 CHAR8 *LanguageString;\r
998\r
999 //\r
1000 // Make sure the parameter are valid\r
1001 //\r
1002 if (Language == NULL || UnicodeString == NULL || UnicodeStringTable == NULL) {\r
1003 return EFI_INVALID_PARAMETER;\r
1004 }\r
1005\r
1006 //\r
1007 // If there are no supported languages, then a Unicode String can not be added\r
1008 //\r
1009 if (SupportedLanguages == NULL) {\r
1010 return EFI_UNSUPPORTED;\r
1011 }\r
1012\r
1013 //\r
1014 // If the Unicode String is empty, then a Unicode String can not be added\r
1015 //\r
1016 if (UnicodeString[0] == 0) {\r
1017 return EFI_INVALID_PARAMETER;\r
1018 }\r
1019\r
1020 //\r
1021 // Make sure Language is a member of SupportedLanguages\r
1022 //\r
1023 Found = FALSE;\r
1024 while (*SupportedLanguages != 0) {\r
1025 if (Iso639Language) {\r
1026 if (CompareIso639LanguageCode (Language, SupportedLanguages)) {\r
1027 Found = TRUE;\r
1028 break;\r
1029 }\r
1030 SupportedLanguages += 3;\r
1031 } else {\r
1032 for (Index = 0; SupportedLanguages[Index] != 0 && SupportedLanguages[Index] != ';'; Index++);\r
1033 if (AsciiStrnCmp(SupportedLanguages, Language, Index) == 0) {\r
1034 Found = TRUE;\r
1035 break;\r
1036 }\r
1037 SupportedLanguages += Index;\r
1038 for (; *SupportedLanguages != 0 && *SupportedLanguages == ';'; SupportedLanguages++);\r
1039 }\r
1040 }\r
1041\r
1042 //\r
1043 // If Language is not a member of SupportedLanguages, then return EFI_UNSUPPORTED\r
1044 //\r
1045 if (!Found) {\r
1046 return EFI_UNSUPPORTED;\r
1047 }\r
1048\r
1049 //\r
1050 // Determine the size of the Unicode String Table by looking for a NULL Language entry\r
1051 //\r
1052 NumberOfEntries = 0;\r
1053 if (*UnicodeStringTable != NULL) {\r
1054 OldUnicodeStringTable = *UnicodeStringTable;\r
1055 while (OldUnicodeStringTable->Language != NULL) {\r
1056 LanguageString = OldUnicodeStringTable->Language;\r
1057\r
1058 while (*LanguageString != 0) {\r
1059 for (Index = 0; LanguageString[Index] != 0 && LanguageString[Index] != ';'; Index++);\r
1060\r
1061 if (AsciiStrnCmp (Language, LanguageString, Index) == 0) { \r
1062 return EFI_ALREADY_STARTED;\r
1063 }\r
1064 LanguageString += Index;\r
1065 for (; *LanguageString != 0 && *LanguageString == ';'; LanguageString++);\r
1066 }\r
1067 OldUnicodeStringTable++;\r
1068 NumberOfEntries++;\r
1069 }\r
1070 }\r
1071\r
1072 //\r
1073 // Allocate space for a new Unicode String Table. It must hold the current number of\r
1074 // entries, plus 1 entry for the new Unicode String, plus 1 entry for the end of table\r
1075 // marker\r
1076 //\r
1077 NewUnicodeStringTable = AllocatePool ((NumberOfEntries + 2) * sizeof (EFI_UNICODE_STRING_TABLE));\r
1078 if (NewUnicodeStringTable == NULL) {\r
1079 return EFI_OUT_OF_RESOURCES;\r
1080 }\r
1081\r
1082 //\r
1083 // If the current Unicode String Table contains any entries, then copy them to the\r
1084 // newly allocated Unicode String Table.\r
1085 //\r
1086 if (*UnicodeStringTable != NULL) {\r
1087 CopyMem (\r
1088 NewUnicodeStringTable,\r
1089 *UnicodeStringTable,\r
1090 NumberOfEntries * sizeof (EFI_UNICODE_STRING_TABLE)\r
1091 );\r
1092 }\r
1093\r
1094 //\r
1095 // Allocate space for a copy of the Language specifier\r
1096 //\r
1097 NewUnicodeStringTable[NumberOfEntries].Language = AllocateCopyPool (AsciiStrSize(Language), Language);\r
1098 if (NewUnicodeStringTable[NumberOfEntries].Language == NULL) {\r
1099 gBS->FreePool (NewUnicodeStringTable);\r
1100 return EFI_OUT_OF_RESOURCES;\r
1101 }\r
1102\r
1103 //\r
1104 // Compute the length of the Unicode String\r
1105 //\r
1106 for (UnicodeStringLength = 0; UnicodeString[UnicodeStringLength] != 0; UnicodeStringLength++);\r
1107\r
1108 //\r
1109 // Allocate space for a copy of the Unicode String\r
1110 //\r
1111 NewUnicodeStringTable[NumberOfEntries].UnicodeString = AllocateCopyPool (StrSize (UnicodeString), UnicodeString);\r
1112 if (NewUnicodeStringTable[NumberOfEntries].UnicodeString == NULL) {\r
1113 gBS->FreePool (NewUnicodeStringTable[NumberOfEntries].Language);\r
1114 gBS->FreePool (NewUnicodeStringTable);\r
1115 return EFI_OUT_OF_RESOURCES;\r
1116 }\r
1117\r
1118 //\r
1119 // Mark the end of the Unicode String Table\r
1120 //\r
1121 NewUnicodeStringTable[NumberOfEntries + 1].Language = NULL;\r
1122 NewUnicodeStringTable[NumberOfEntries + 1].UnicodeString = NULL;\r
1123\r
1124 //\r
1125 // Free the old Unicode String Table\r
1126 //\r
1127 if (*UnicodeStringTable != NULL) {\r
1128 gBS->FreePool (*UnicodeStringTable);\r
1129 }\r
1130\r
1131 //\r
1132 // Point UnicodeStringTable at the newly allocated Unicode String Table\r
1133 //\r
1134 *UnicodeStringTable = NewUnicodeStringTable;\r
1135\r
1136 return EFI_SUCCESS;\r
1137}\r
1138\r
79964ac8 1139/**\r
1140 This function frees the table of Unicode strings in UnicodeStringTable.\r
bf428cb3 1141\r
79964ac8 1142 If UnicodeStringTable is NULL, then EFI_SUCCESS is returned.\r
bf428cb3 1143 Otherwise, each language code, and each Unicode string in the Unicode string \r
79964ac8 1144 table are freed, and EFI_SUCCESS is returned.\r
1145\r
1146 @param UnicodeStringTable A pointer to the table of Unicode strings.\r
1147\r
1148 @retval EFI_SUCCESS The Unicode string table was freed.\r
1149\r
1150**/\r
1151EFI_STATUS\r
1152EFIAPI\r
1153FreeUnicodeStringTable (\r
1154 IN EFI_UNICODE_STRING_TABLE *UnicodeStringTable\r
1155 )\r
1156{\r
1157 UINTN Index;\r
1158\r
1159 //\r
1160 // If the Unicode String Table is NULL, then it is already freed\r
1161 //\r
1162 if (UnicodeStringTable == NULL) {\r
1163 return EFI_SUCCESS;\r
1164 }\r
1165\r
1166 //\r
1167 // Loop through the Unicode String Table until we reach the end of table marker\r
1168 //\r
1169 for (Index = 0; UnicodeStringTable[Index].Language != NULL; Index++) {\r
1170\r
1171 //\r
1172 // Free the Language string from the Unicode String Table\r
1173 //\r
1174 gBS->FreePool (UnicodeStringTable[Index].Language);\r
1175\r
1176 //\r
1177 // Free the Unicode String from the Unicode String Table\r
1178 //\r
1179 if (UnicodeStringTable[Index].UnicodeString != NULL) {\r
1180 gBS->FreePool (UnicodeStringTable[Index].UnicodeString);\r
1181 }\r
1182 }\r
1183\r
1184 //\r
1185 // Free the Unicode String Table itself\r
1186 //\r
1187 gBS->FreePool (UnicodeStringTable);\r
1188\r
1189 return EFI_SUCCESS;\r
1190}\r