]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkPkg/Library/FrameworkUefiLib/UefiLib.c
Patch to remove STATIC modifier. This is on longer recommended by EFI Framework codin...
[mirror_edk2.git] / IntelFrameworkPkg / Library / FrameworkUefiLib / UefiLib.c
1 /** @file
2 Implementation of UefiLib
3
4 Copyright (c) 2006 - 2007, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "FrameworkUefiLib.h"
16
17 /**
18 Compare whether two names of languages are identical.
19
20 @param Language1 Name of language 1.
21 @param Language2 Name of language 2.
22
23 @retval TRUE Language 1 and language 2 are the same.
24 @retval FALSE Language 1 and language 2 are not the same.
25
26 **/
27 BOOLEAN
28 CompareIso639LanguageCode (
29 IN CONST CHAR8 *Language1,
30 IN CONST CHAR8 *Language2
31 )
32 {
33 UINT32 Name1;
34 UINT32 Name2;
35
36 Name1 = ReadUnaligned24 ((CONST UINT32 *) Language1);
37 Name2 = ReadUnaligned24 ((CONST UINT32 *) Language2);
38
39 return (BOOLEAN) (Name1 == Name2);
40 }
41
42 /**
43 This function searches the list of configuration tables stored in the EFI System
44 Table for a table with a GUID that matches TableGuid. If a match is found,
45 then a pointer to the configuration table is returned in Table, and EFI_SUCCESS
46 is returned. If a matching GUID is not found, then EFI_NOT_FOUND is returned.
47
48 @param TableGuid Pointer to table's GUID type..
49 @param Table Pointer to the table associated with TableGuid in the EFI System Table.
50
51 @retval EFI_SUCCESS A configuration table matching TableGuid was found.
52 @retval EFI_NOT_FOUND A configuration table matching TableGuid could not be found.
53
54 **/
55 EFI_STATUS
56 EFIAPI
57 EfiGetSystemConfigurationTable (
58 IN EFI_GUID *TableGuid,
59 OUT VOID **Table
60 )
61 {
62 EFI_SYSTEM_TABLE *SystemTable;
63 UINTN Index;
64
65 ASSERT (TableGuid != NULL);
66 ASSERT (Table != NULL);
67
68 SystemTable = gST;
69 *Table = NULL;
70 for (Index = 0; Index < SystemTable->NumberOfTableEntries; Index++) {
71 if (CompareGuid (TableGuid, &(SystemTable->ConfigurationTable[Index].VendorGuid))) {
72 *Table = SystemTable->ConfigurationTable[Index].VendorTable;
73 return EFI_SUCCESS;
74 }
75 }
76
77 return EFI_NOT_FOUND;
78 }
79
80 /**
81 This function causes the notification function to be executed for every protocol
82 of type ProtocolGuid instance that exists in the system when this function is
83 invoked. In addition, every time a protocol of type ProtocolGuid instance is
84 installed or reinstalled, the notification function is also executed.
85
86 @param ProtocolGuid Supplies GUID of the protocol upon whose installation the event is fired.
87 @param NotifyTpl Supplies the task priority level of the event notifications.
88 @param NotifyFunction Supplies the function to notify when the event is signaled.
89 @param NotifyContext The context parameter to pass to NotifyFunction.
90 @param Registration A pointer to a memory location to receive the registration value.
91
92 @return The notification event that was created.
93
94 **/
95 EFI_EVENT
96 EFIAPI
97 EfiCreateProtocolNotifyEvent(
98 IN EFI_GUID *ProtocolGuid,
99 IN EFI_TPL NotifyTpl,
100 IN EFI_EVENT_NOTIFY NotifyFunction,
101 IN VOID *NotifyContext, OPTIONAL
102 OUT VOID **Registration
103 )
104 {
105 EFI_STATUS Status;
106 EFI_EVENT Event;
107
108 //
109 // Create the event
110 //
111
112 Status = gBS->CreateEvent (
113 EVT_NOTIFY_SIGNAL,
114 NotifyTpl,
115 NotifyFunction,
116 NotifyContext,
117 &Event
118 );
119 ASSERT_EFI_ERROR (Status);
120
121 //
122 // Register for protocol notifactions on this event
123 //
124
125 Status = gBS->RegisterProtocolNotify (
126 ProtocolGuid,
127 Event,
128 Registration
129 );
130
131 ASSERT_EFI_ERROR (Status);
132
133 //
134 // Kick the event so we will perform an initial pass of
135 // current installed drivers
136 //
137
138 gBS->SignalEvent (Event);
139 return Event;
140 }
141
142 /**
143 This function creates an event using NotifyTpl, NoifyFunction, and NotifyContext.
144 This event is signaled with EfiNamedEventSignal(). This provide the ability for
145 one or more listeners on the same event named by the GUID specified by Name.
146
147 @param Name Supplies GUID name of the event.
148 @param NotifyTpl Supplies the task priority level of the event notifications.
149 @param NotifyFunction Supplies the function to notify when the event is signaled.
150 @param NotifyContext The context parameter to pass to NotifyFunction.
151 @param Registration A pointer to a memory location to receive the registration value.
152
153 @retval EFI_SUCCESS A named event was created.
154 @retval EFI_OUT_OF_RESOURCES There are not enough resource to create the named event.
155
156 **/
157 EFI_STATUS
158 EFIAPI
159 EfiNamedEventListen (
160 IN CONST EFI_GUID *Name,
161 IN EFI_TPL NotifyTpl,
162 IN EFI_EVENT_NOTIFY NotifyFunction,
163 IN CONST VOID *NotifyContext, OPTIONAL
164 OUT VOID *Registration OPTIONAL
165 )
166 {
167 EFI_STATUS Status;
168 EFI_EVENT Event;
169 VOID *RegistrationLocal;
170
171 //
172 // Create event
173 //
174 Status = gBS->CreateEvent (
175 EVT_NOTIFY_SIGNAL,
176 NotifyTpl,
177 NotifyFunction,
178 (VOID *) NotifyContext,
179 &Event
180 );
181 ASSERT_EFI_ERROR (Status);
182
183 //
184 // The Registration is not optional to RegisterProtocolNotify().
185 // To make it optional to EfiNamedEventListen(), may need to substitute with a local.
186 //
187 if (Registration != NULL) {
188 RegistrationLocal = Registration;
189 } else {
190 RegistrationLocal = &RegistrationLocal;
191 }
192
193 //
194 // Register for an installation of protocol interface
195 //
196
197 Status = gBS->RegisterProtocolNotify (
198 (EFI_GUID *) Name,
199 Event,
200 RegistrationLocal
201 );
202 ASSERT_EFI_ERROR (Status);
203
204 return EFI_SUCCESS;
205 }
206
207 /**
208 This function signals the named event specified by Name. The named event must
209 have been created with EfiNamedEventListen().
210
211 @param Name Supplies GUID name of the event.
212
213 @retval EFI_SUCCESS A named event was signaled.
214 @retval EFI_OUT_OF_RESOURCES There are not enough resource to signal the named event.
215
216 **/
217 EFI_STATUS
218 EFIAPI
219 EfiNamedEventSignal (
220 IN CONST EFI_GUID *Name
221 )
222 {
223 EFI_STATUS Status;
224 EFI_HANDLE Handle;
225
226 Handle = NULL;
227 Status = gBS->InstallProtocolInterface (
228 &Handle,
229 (EFI_GUID *) Name,
230 EFI_NATIVE_INTERFACE,
231 NULL
232 );
233 ASSERT_EFI_ERROR (Status);
234
235 Status = gBS->UninstallProtocolInterface (
236 Handle,
237 (EFI_GUID *) Name,
238 NULL
239 );
240 ASSERT_EFI_ERROR (Status);
241
242 return EFI_SUCCESS;
243 }
244
245 /**
246 Returns the current TPL.
247
248 This function returns the current TPL. There is no EFI service to directly
249 retrieve the current TPL. Instead, the RaiseTPL() function is used to raise
250 the TPL to TPL_HIGH_LEVEL. This will return the current TPL. The TPL level
251 can then immediately be restored back to the current TPL level with a call
252 to RestoreTPL().
253
254 @return The current TPL.
255
256 **/
257 EFI_TPL
258 EFIAPI
259 EfiGetCurrentTpl (
260 VOID
261 )
262 {
263 EFI_TPL Tpl;
264
265 Tpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);
266 gBS->RestoreTPL (Tpl);
267
268 return Tpl;
269 }
270
271
272 /**
273 This function initializes a basic mutual exclusion lock to the released state
274 and returns the lock. Each lock provides mutual exclusion access at its task
275 priority level. Since there is no preemption or multiprocessor support in EFI,
276 acquiring the lock only consists of raising to the locks TPL.
277
278 @param Lock A pointer to the lock data structure to initialize.
279 @param Priority EFI TPL associated with the lock.
280
281 @return The lock.
282
283 **/
284 EFI_LOCK *
285 EFIAPI
286 EfiInitializeLock (
287 IN OUT EFI_LOCK *Lock,
288 IN EFI_TPL Priority
289 )
290 {
291 ASSERT (Lock != NULL);
292 ASSERT (Priority <= TPL_HIGH_LEVEL);
293
294 Lock->Tpl = Priority;
295 Lock->OwnerTpl = TPL_APPLICATION;
296 Lock->Lock = EfiLockReleased ;
297 return Lock;
298 }
299
300 /**
301 This function raises the system's current task priority level to the task
302 priority level of the mutual exclusion lock. Then, it places the lock in the
303 acquired state.
304
305 @param Lock Point to EFI_LOCK instance
306
307 **/
308 VOID
309 EFIAPI
310 EfiAcquireLock (
311 IN EFI_LOCK *Lock
312 )
313 {
314 ASSERT (Lock != NULL);
315 ASSERT (Lock->Lock == EfiLockReleased);
316
317 Lock->OwnerTpl = gBS->RaiseTPL (Lock->Tpl);
318 Lock->Lock = EfiLockAcquired;
319 }
320
321 /**
322 This function raises the system's current task priority level to the task
323 priority level of the mutual exclusion lock. Then, it attempts to place the
324 lock in the acquired state.
325
326 @param Lock A pointer to the lock to acquire.
327
328 @retval EFI_SUCCESS The lock was acquired.
329 @retval EFI_ACCESS_DENIED The lock could not be acquired because it is already owned.
330
331 **/
332 EFI_STATUS
333 EFIAPI
334 EfiAcquireLockOrFail (
335 IN EFI_LOCK *Lock
336 )
337 {
338
339 ASSERT (Lock != NULL);
340 ASSERT (Lock->Lock != EfiLockUninitialized);
341
342 if (Lock->Lock == EfiLockAcquired) {
343 //
344 // Lock is already owned, so bail out
345 //
346 return EFI_ACCESS_DENIED;
347 }
348
349 Lock->OwnerTpl = gBS->RaiseTPL (Lock->Tpl);
350
351 Lock->Lock = EfiLockAcquired;
352
353 return EFI_SUCCESS;
354 }
355
356 /**
357 This function transitions a mutual exclusion lock from the acquired state to
358 the released state, and restores the system's task priority level to its
359 previous level.
360
361 @param Lock A pointer to the lock to release.
362
363 **/
364 VOID
365 EFIAPI
366 EfiReleaseLock (
367 IN EFI_LOCK *Lock
368 )
369 {
370 EFI_TPL Tpl;
371
372 ASSERT (Lock != NULL);
373 ASSERT (Lock->Lock == EfiLockAcquired);
374
375 Tpl = Lock->OwnerTpl;
376
377 Lock->Lock = EfiLockReleased;
378
379 gBS->RestoreTPL (Tpl);
380 }
381
382 /**
383 Tests whether a controller handle is being managed by a specific driver.
384
385 This function tests whether the driver specified by DriverBindingHandle is
386 currently managing the controller specified by ControllerHandle. This test
387 is performed by evaluating if the the protocol specified by ProtocolGuid is
388 present on ControllerHandle and is was opened by DriverBindingHandle with an
389 attribute of EFI_OPEN_PROTOCOL_BY_DRIVER.
390 If ProtocolGuid is NULL, then ASSERT().
391
392 @param ControllerHandle A handle for a controller to test.
393 @param DriverBindingHandle Specifies the driver binding handle for the
394 driver.
395 @param ProtocolGuid Specifies the protocol that the driver specified
396 by DriverBindingHandle opens in its Start()
397 function.
398
399 @retval EFI_SUCCESS ControllerHandle is managed by the driver
400 specifed by DriverBindingHandle.
401 @retval EFI_UNSUPPORTED ControllerHandle is not managed by the driver
402 specifed by DriverBindingHandle.
403
404 **/
405 EFI_STATUS
406 EFIAPI
407 EfiTestManagedDevice (
408 IN CONST EFI_HANDLE ControllerHandle,
409 IN CONST EFI_HANDLE DriverBindingHandle,
410 IN CONST EFI_GUID *ProtocolGuid
411 )
412 {
413 EFI_STATUS Status;
414 VOID *ManagedInterface;
415
416 ASSERT (ProtocolGuid != NULL);
417
418 Status = gBS->OpenProtocol (
419 ControllerHandle,
420 (EFI_GUID *) ProtocolGuid,
421 &ManagedInterface,
422 DriverBindingHandle,
423 ControllerHandle,
424 EFI_OPEN_PROTOCOL_BY_DRIVER
425 );
426 if (!EFI_ERROR (Status)) {
427 gBS->CloseProtocol (
428 ControllerHandle,
429 (EFI_GUID *) ProtocolGuid,
430 DriverBindingHandle,
431 ControllerHandle
432 );
433 return EFI_UNSUPPORTED;
434 }
435
436 if (Status != EFI_ALREADY_STARTED) {
437 return EFI_UNSUPPORTED;
438 }
439
440 return EFI_SUCCESS;
441 }
442
443 /**
444 Tests whether a child handle is a child device of the controller.
445
446 This function tests whether ChildHandle is one of the children of
447 ControllerHandle. This test is performed by checking to see if the protocol
448 specified by ProtocolGuid is present on ControllerHandle and opened by
449 ChildHandle with an attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
450 If ProtocolGuid is NULL, then ASSERT().
451
452 @param ControllerHandle A handle for a (parent) controller to test.
453 @param ChildHandle A child handle to test.
454 @param ProtocolGuid Supplies the protocol that the child controller
455 opens on its parent controller.
456
457 @retval EFI_SUCCESS ChildHandle is a child of the ControllerHandle.
458 @retval EFI_UNSUPPORTED ChildHandle is not a child of the
459 ControllerHandle.
460
461 **/
462 EFI_STATUS
463 EFIAPI
464 EfiTestChildHandle (
465 IN CONST EFI_HANDLE ControllerHandle,
466 IN CONST EFI_HANDLE ChildHandle,
467 IN CONST EFI_GUID *ProtocolGuid
468 )
469 {
470 EFI_STATUS Status;
471 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;
472 UINTN EntryCount;
473 UINTN Index;
474
475 ASSERT (ProtocolGuid != NULL);
476
477 //
478 // Retrieve the list of agents that are consuming the specific protocol
479 // on ControllerHandle.
480 //
481 Status = gBS->OpenProtocolInformation (
482 ControllerHandle,
483 (EFI_GUID *) ProtocolGuid,
484 &OpenInfoBuffer,
485 &EntryCount
486 );
487 if (EFI_ERROR (Status)) {
488 return EFI_UNSUPPORTED;
489 }
490
491 //
492 // Inspect if ChildHandle is one of the agents.
493 //
494 Status = EFI_UNSUPPORTED;
495 for (Index = 0; Index < EntryCount; Index++) {
496 if ((OpenInfoBuffer[Index].ControllerHandle == ChildHandle) &&
497 (OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) != 0) {
498 Status = EFI_SUCCESS;
499 break;
500 }
501 }
502
503 FreePool (OpenInfoBuffer);
504 return Status;
505 }
506
507 /**
508 This function looks up a Unicode string in UnicodeStringTable. If Language is
509 a member of SupportedLanguages and a Unicode string is found in UnicodeStringTable
510 that matches the language code specified by Language, then it is returned in
511 UnicodeString.
512
513 @param Language A pointer to the ISO 639-2 language code for the
514 Unicode string to look up and return.
515 @param SupportedLanguages A pointer to the set of ISO 639-2 language codes
516 that the Unicode string table supports. Language
517 must be a member of this set.
518 @param UnicodeStringTable A pointer to the table of Unicode strings.
519 @param UnicodeString A pointer to the Unicode string from UnicodeStringTable
520 that matches the language specified by Language.
521
522 @retval EFI_SUCCESS The Unicode string that matches the language
523 specified by Language was found
524 in the table of Unicoide strings UnicodeStringTable,
525 and it was returned in UnicodeString.
526 @retval EFI_INVALID_PARAMETER Language is NULL.
527 @retval EFI_INVALID_PARAMETER UnicodeString is NULL.
528 @retval EFI_UNSUPPORTED SupportedLanguages is NULL.
529 @retval EFI_UNSUPPORTED UnicodeStringTable is NULL.
530 @retval EFI_UNSUPPORTED The language specified by Language is not a
531 member of SupportedLanguages.
532 @retval EFI_UNSUPPORTED The language specified by Language is not
533 supported by UnicodeStringTable.
534
535 **/
536 EFI_STATUS
537 EFIAPI
538 LookupUnicodeString (
539 IN CONST CHAR8 *Language,
540 IN CONST CHAR8 *SupportedLanguages,
541 IN CONST EFI_UNICODE_STRING_TABLE *UnicodeStringTable,
542 OUT CHAR16 **UnicodeString
543 )
544 {
545 //
546 // Make sure the parameters are valid
547 //
548 if (Language == NULL || UnicodeString == NULL) {
549 return EFI_INVALID_PARAMETER;
550 }
551
552 //
553 // If there are no supported languages, or the Unicode String Table is empty, then the
554 // Unicode String specified by Language is not supported by this Unicode String Table
555 //
556 if (SupportedLanguages == NULL || UnicodeStringTable == NULL) {
557 return EFI_UNSUPPORTED;
558 }
559
560 //
561 // Make sure Language is in the set of Supported Languages
562 //
563 while (*SupportedLanguages != 0) {
564 if (CompareIso639LanguageCode (Language, SupportedLanguages)) {
565
566 //
567 // Search the Unicode String Table for the matching Language specifier
568 //
569 while (UnicodeStringTable->Language != NULL) {
570 if (CompareIso639LanguageCode (Language, UnicodeStringTable->Language)) {
571
572 //
573 // A matching string was found, so return it
574 //
575 *UnicodeString = UnicodeStringTable->UnicodeString;
576 return EFI_SUCCESS;
577 }
578
579 UnicodeStringTable++;
580 }
581
582 return EFI_UNSUPPORTED;
583 }
584
585 SupportedLanguages += 3;
586 }
587
588 return EFI_UNSUPPORTED;
589 }
590
591 /**
592 This function adds a Unicode string to UnicodeStringTable.
593 If Language is a member of SupportedLanguages then UnicodeString is added to
594 UnicodeStringTable. New buffers are allocated for both Language and
595 UnicodeString. The contents of Language and UnicodeString are copied into
596 these new buffers. These buffers are automatically freed when
597 FreeUnicodeStringTable() is called.
598
599 @param Language A pointer to the ISO 639-2 language code for the Unicode
600 string to add.
601 @param SupportedLanguages A pointer to the set of ISO 639-2 language codes
602 that the Unicode string table supports.
603 Language must be a member of this set.
604 @param UnicodeStringTable A pointer to the table of Unicode strings.
605 @param UnicodeString A pointer to the Unicode string to add.
606
607 @retval EFI_SUCCESS The Unicode string that matches the language
608 specified by Language was found in the table of
609 Unicode strings UnicodeStringTable, and it was
610 returned in UnicodeString.
611 @retval EFI_INVALID_PARAMETER Language is NULL.
612 @retval EFI_INVALID_PARAMETER UnicodeString is NULL.
613 @retval EFI_INVALID_PARAMETER UnicodeString is an empty string.
614 @retval EFI_UNSUPPORTED SupportedLanguages is NULL.
615 @retval EFI_ALREADY_STARTED A Unicode string with language Language is
616 already present in UnicodeStringTable.
617 @retval EFI_OUT_OF_RESOURCES There is not enough memory to add another
618 Unicode string to UnicodeStringTable.
619 @retval EFI_UNSUPPORTED The language specified by Language is not a
620 member of SupportedLanguages.
621
622 **/
623 EFI_STATUS
624 EFIAPI
625 AddUnicodeString (
626 IN CONST CHAR8 *Language,
627 IN CONST CHAR8 *SupportedLanguages,
628 IN EFI_UNICODE_STRING_TABLE **UnicodeStringTable,
629 IN CONST CHAR16 *UnicodeString
630 )
631 {
632 UINTN NumberOfEntries;
633 EFI_UNICODE_STRING_TABLE *OldUnicodeStringTable;
634 EFI_UNICODE_STRING_TABLE *NewUnicodeStringTable;
635 UINTN UnicodeStringLength;
636
637 //
638 // Make sure the parameter are valid
639 //
640 if (Language == NULL || UnicodeString == NULL || UnicodeStringTable == NULL) {
641 return EFI_INVALID_PARAMETER;
642 }
643
644 //
645 // If there are no supported languages, then a Unicode String can not be added
646 //
647 if (SupportedLanguages == NULL) {
648 return EFI_UNSUPPORTED;
649 }
650
651 //
652 // If the Unicode String is empty, then a Unicode String can not be added
653 //
654 if (UnicodeString[0] == 0) {
655 return EFI_INVALID_PARAMETER;
656 }
657
658 //
659 // Make sure Language is a member of SupportedLanguages
660 //
661 while (*SupportedLanguages != 0) {
662 if (CompareIso639LanguageCode (Language, SupportedLanguages)) {
663
664 //
665 // Determine the size of the Unicode String Table by looking for a NULL Language entry
666 //
667 NumberOfEntries = 0;
668 if (*UnicodeStringTable != NULL) {
669 OldUnicodeStringTable = *UnicodeStringTable;
670 while (OldUnicodeStringTable->Language != NULL) {
671 if (CompareIso639LanguageCode (Language, OldUnicodeStringTable->Language)) {
672 return EFI_ALREADY_STARTED;
673 }
674
675 OldUnicodeStringTable++;
676 NumberOfEntries++;
677 }
678 }
679
680 //
681 // Allocate space for a new Unicode String Table. It must hold the current number of
682 // entries, plus 1 entry for the new Unicode String, plus 1 entry for the end of table
683 // marker
684 //
685 NewUnicodeStringTable = AllocatePool ((NumberOfEntries + 2) * sizeof (EFI_UNICODE_STRING_TABLE));
686 if (NewUnicodeStringTable == NULL) {
687 return EFI_OUT_OF_RESOURCES;
688 }
689
690 //
691 // If the current Unicode String Table contains any entries, then copy them to the
692 // newly allocated Unicode String Table.
693 //
694 if (*UnicodeStringTable != NULL) {
695 CopyMem (
696 NewUnicodeStringTable,
697 *UnicodeStringTable,
698 NumberOfEntries * sizeof (EFI_UNICODE_STRING_TABLE)
699 );
700 }
701
702 //
703 // Allocate space for a copy of the Language specifier
704 //
705 NewUnicodeStringTable[NumberOfEntries].Language = AllocateCopyPool (3, Language);
706 if (NewUnicodeStringTable[NumberOfEntries].Language == NULL) {
707 gBS->FreePool (NewUnicodeStringTable);
708 return EFI_OUT_OF_RESOURCES;
709 }
710
711 //
712 // Compute the length of the Unicode String
713 //
714 for (UnicodeStringLength = 0; UnicodeString[UnicodeStringLength] != 0; UnicodeStringLength++)
715 ;
716
717 //
718 // Allocate space for a copy of the Unicode String
719 //
720 NewUnicodeStringTable[NumberOfEntries].UnicodeString = AllocateCopyPool (
721 (UnicodeStringLength + 1) * sizeof (CHAR16),
722 UnicodeString
723 );
724 if (NewUnicodeStringTable[NumberOfEntries].UnicodeString == NULL) {
725 gBS->FreePool (NewUnicodeStringTable[NumberOfEntries].Language);
726 gBS->FreePool (NewUnicodeStringTable);
727 return EFI_OUT_OF_RESOURCES;
728 }
729
730 //
731 // Mark the end of the Unicode String Table
732 //
733 NewUnicodeStringTable[NumberOfEntries + 1].Language = NULL;
734 NewUnicodeStringTable[NumberOfEntries + 1].UnicodeString = NULL;
735
736 //
737 // Free the old Unicode String Table
738 //
739 if (*UnicodeStringTable != NULL) {
740 gBS->FreePool (*UnicodeStringTable);
741 }
742
743 //
744 // Point UnicodeStringTable at the newly allocated Unicode String Table
745 //
746 *UnicodeStringTable = NewUnicodeStringTable;
747
748 return EFI_SUCCESS;
749 }
750
751 SupportedLanguages += 3;
752 }
753
754 return EFI_UNSUPPORTED;
755 }
756
757 /**
758 This function frees the table of Unicode strings in UnicodeStringTable.
759 If UnicodeStringTable is NULL, then EFI_SUCCESS is returned.
760 Otherwise, each language code, and each Unicode string in the Unicode string
761 table are freed, and EFI_SUCCESS is returned.
762
763 @param UnicodeStringTable A pointer to the table of Unicode strings.
764
765 @retval EFI_SUCCESS The Unicode string table was freed.
766
767 **/
768 EFI_STATUS
769 EFIAPI
770 FreeUnicodeStringTable (
771 IN EFI_UNICODE_STRING_TABLE *UnicodeStringTable
772 )
773 {
774 UINTN Index;
775
776 //
777 // If the Unicode String Table is NULL, then it is already freed
778 //
779 if (UnicodeStringTable == NULL) {
780 return EFI_SUCCESS;
781 }
782
783 //
784 // Loop through the Unicode String Table until we reach the end of table marker
785 //
786 for (Index = 0; UnicodeStringTable[Index].Language != NULL; Index++) {
787
788 //
789 // Free the Language string from the Unicode String Table
790 //
791 gBS->FreePool (UnicodeStringTable[Index].Language);
792
793 //
794 // Free the Unicode String from the Unicode String Table
795 //
796 if (UnicodeStringTable[Index].UnicodeString != NULL) {
797 gBS->FreePool (UnicodeStringTable[Index].UnicodeString);
798 }
799 }
800
801 //
802 // Free the Unicode String Table itself
803 //
804 gBS->FreePool (UnicodeStringTable);
805
806 return EFI_SUCCESS;
807 }
808