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