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