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