]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c
Fix memory leak issues.
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / GenericBdsLib / BdsMisc.c
1 /** @file
2 Misc BDS library function
3
4 Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
5 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 "InternalBdsLib.h"
16
17
18 #define MAX_STRING_LEN 200
19
20 BOOLEAN mFeaturerSwitch = TRUE;
21 BOOLEAN mResetRequired = FALSE;
22
23 extern UINT16 gPlatformBootTimeOutDefault;
24
25 /**
26 The function will go through the driver option link list, load and start
27 every driver the driver option device path point to.
28
29 @param BdsDriverLists The header of the current driver option link list
30
31 **/
32 VOID
33 EFIAPI
34 BdsLibLoadDrivers (
35 IN LIST_ENTRY *BdsDriverLists
36 )
37 {
38 EFI_STATUS Status;
39 LIST_ENTRY *Link;
40 BDS_COMMON_OPTION *Option;
41 EFI_HANDLE ImageHandle;
42 EFI_LOADED_IMAGE_PROTOCOL *ImageInfo;
43 UINTN ExitDataSize;
44 CHAR16 *ExitData;
45 BOOLEAN ReconnectAll;
46
47 ReconnectAll = FALSE;
48
49 //
50 // Process the driver option
51 //
52 for (Link = BdsDriverLists->ForwardLink; Link != BdsDriverLists; Link = Link->ForwardLink) {
53 Option = CR (Link, BDS_COMMON_OPTION, Link, BDS_LOAD_OPTION_SIGNATURE);
54
55 //
56 // If a load option is not marked as LOAD_OPTION_ACTIVE,
57 // the boot manager will not automatically load the option.
58 //
59 if (!IS_LOAD_OPTION_TYPE (Option->Attribute, LOAD_OPTION_ACTIVE)) {
60 continue;
61 }
62
63 //
64 // If a driver load option is marked as LOAD_OPTION_FORCE_RECONNECT,
65 // then all of the EFI drivers in the system will be disconnected and
66 // reconnected after the last driver load option is processed.
67 //
68 if (IS_LOAD_OPTION_TYPE (Option->Attribute, LOAD_OPTION_FORCE_RECONNECT)) {
69 ReconnectAll = TRUE;
70 }
71
72 //
73 // Make sure the driver path is connected.
74 //
75 BdsLibConnectDevicePath (Option->DevicePath);
76
77 //
78 // Load and start the image that Driver#### describes
79 //
80 Status = gBS->LoadImage (
81 FALSE,
82 gImageHandle,
83 Option->DevicePath,
84 NULL,
85 0,
86 &ImageHandle
87 );
88
89 if (!EFI_ERROR (Status)) {
90 gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &ImageInfo);
91
92 //
93 // Verify whether this image is a driver, if not,
94 // exit it and continue to parse next load option
95 //
96 if (ImageInfo->ImageCodeType != EfiBootServicesCode && ImageInfo->ImageCodeType != EfiRuntimeServicesCode) {
97 gBS->Exit (ImageHandle, EFI_INVALID_PARAMETER, 0, NULL);
98 continue;
99 }
100
101 if (Option->LoadOptionsSize != 0) {
102 ImageInfo->LoadOptionsSize = Option->LoadOptionsSize;
103 ImageInfo->LoadOptions = Option->LoadOptions;
104 }
105 //
106 // Before calling the image, enable the Watchdog Timer for
107 // the 5 Minute period
108 //
109 gBS->SetWatchdogTimer (5 * 60, 0x0000, 0x00, NULL);
110
111 Status = gBS->StartImage (ImageHandle, &ExitDataSize, &ExitData);
112 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Driver Return Status = %r\n", Status));
113
114 //
115 // Clear the Watchdog Timer after the image returns
116 //
117 gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL);
118 }
119 }
120
121 //
122 // Process the LOAD_OPTION_FORCE_RECONNECT driver option
123 //
124 if (ReconnectAll) {
125 BdsLibDisconnectAllEfi ();
126 BdsLibConnectAll ();
127 }
128
129 }
130
131 /**
132 Get the Option Number that does not used.
133 Try to locate the specific option variable one by one utile find a free number.
134
135 @param VariableName Indicate if the boot#### or driver#### option
136
137 @return The Minimal Free Option Number
138
139 **/
140 UINT16
141 BdsLibGetFreeOptionNumber (
142 IN CHAR16 *VariableName
143 )
144 {
145 UINTN Index;
146 CHAR16 StrTemp[10];
147 UINT16 *OptionBuffer;
148 UINTN OptionSize;
149
150 //
151 // Try to find the minimum free number from 0, 1, 2, 3....
152 //
153 Index = 0;
154 do {
155 if (*VariableName == 'B') {
156 UnicodeSPrint (StrTemp, sizeof (StrTemp), L"Boot%04x", Index);
157 } else {
158 UnicodeSPrint (StrTemp, sizeof (StrTemp), L"Driver%04x", Index);
159 }
160 //
161 // try if the option number is used
162 //
163 OptionBuffer = BdsLibGetVariableAndSize (
164 StrTemp,
165 &gEfiGlobalVariableGuid,
166 &OptionSize
167 );
168 if (OptionBuffer == NULL) {
169 break;
170 }
171 Index++;
172 } while (TRUE);
173
174 return ((UINT16) Index);
175 }
176
177
178 /**
179 This function will register the new boot#### or driver#### option base on
180 the VariableName. The new registered boot#### or driver#### will be linked
181 to BdsOptionList and also update to the VariableName. After the boot#### or
182 driver#### updated, the BootOrder or DriverOrder will also be updated.
183
184 @param BdsOptionList The header of the boot#### or driver#### link list
185 @param DevicePath The device path which the boot#### or driver####
186 option present
187 @param String The description of the boot#### or driver####
188 @param VariableName Indicate if the boot#### or driver#### option
189
190 @retval EFI_SUCCESS The boot#### or driver#### have been success
191 registered
192 @retval EFI_STATUS Return the status of gRT->SetVariable ().
193
194 **/
195 EFI_STATUS
196 EFIAPI
197 BdsLibRegisterNewOption (
198 IN LIST_ENTRY *BdsOptionList,
199 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
200 IN CHAR16 *String,
201 IN CHAR16 *VariableName
202 )
203 {
204 EFI_STATUS Status;
205 UINTN Index;
206 UINT16 RegisterOptionNumber;
207 UINT16 *TempOptionPtr;
208 UINTN TempOptionSize;
209 UINT16 *OptionOrderPtr;
210 VOID *OptionPtr;
211 UINTN OptionSize;
212 UINT8 *TempPtr;
213 EFI_DEVICE_PATH_PROTOCOL *OptionDevicePath;
214 CHAR16 *Description;
215 CHAR16 OptionName[10];
216 BOOLEAN UpdateDescription;
217 UINT16 BootOrderEntry;
218 UINTN OrderItemNum;
219
220
221 OptionPtr = NULL;
222 OptionSize = 0;
223 TempPtr = NULL;
224 OptionDevicePath = NULL;
225 Description = NULL;
226 OptionOrderPtr = NULL;
227 UpdateDescription = FALSE;
228 Status = EFI_SUCCESS;
229 ZeroMem (OptionName, sizeof (OptionName));
230
231 TempOptionSize = 0;
232 TempOptionPtr = BdsLibGetVariableAndSize (
233 VariableName,
234 &gEfiGlobalVariableGuid,
235 &TempOptionSize
236 );
237 //
238 // Compare with current option variable if the previous option is set in global variable.
239 //
240 for (Index = 0; Index < TempOptionSize / sizeof (UINT16); Index++) {
241 //
242 // TempOptionPtr must not be NULL if we have non-zero TempOptionSize.
243 //
244 ASSERT (TempOptionPtr != NULL);
245
246 if (*VariableName == 'B') {
247 UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", TempOptionPtr[Index]);
248 } else {
249 UnicodeSPrint (OptionName, sizeof (OptionName), L"Driver%04x", TempOptionPtr[Index]);
250 }
251
252 OptionPtr = BdsLibGetVariableAndSize (
253 OptionName,
254 &gEfiGlobalVariableGuid,
255 &OptionSize
256 );
257 if (OptionPtr == NULL) {
258 continue;
259 }
260
261 //
262 // Validate the variable.
263 //
264 if (!ValidateOption(OptionPtr, OptionSize)) {
265 continue;
266 }
267
268 TempPtr = OptionPtr;
269 TempPtr += sizeof (UINT32) + sizeof (UINT16);
270 Description = (CHAR16 *) TempPtr;
271 TempPtr += StrSize ((CHAR16 *) TempPtr);
272 OptionDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;
273
274 //
275 // Notes: the description may will change base on the GetStringToken
276 //
277 if (CompareMem (OptionDevicePath, DevicePath, GetDevicePathSize (OptionDevicePath)) == 0) {
278 if (CompareMem (Description, String, StrSize (Description)) == 0) {
279 //
280 // Got the option, so just return
281 //
282 FreePool (OptionPtr);
283 FreePool (TempOptionPtr);
284 return EFI_SUCCESS;
285 } else {
286 //
287 // Option description changed, need update.
288 //
289 UpdateDescription = TRUE;
290 FreePool (OptionPtr);
291 break;
292 }
293 }
294
295 FreePool (OptionPtr);
296 }
297
298 OptionSize = sizeof (UINT32) + sizeof (UINT16) + StrSize (String);
299 OptionSize += GetDevicePathSize (DevicePath);
300 OptionPtr = AllocateZeroPool (OptionSize);
301 ASSERT (OptionPtr != NULL);
302
303 TempPtr = OptionPtr;
304 *(UINT32 *) TempPtr = LOAD_OPTION_ACTIVE;
305 TempPtr += sizeof (UINT32);
306 *(UINT16 *) TempPtr = (UINT16) GetDevicePathSize (DevicePath);
307 TempPtr += sizeof (UINT16);
308 CopyMem (TempPtr, String, StrSize (String));
309 TempPtr += StrSize (String);
310 CopyMem (TempPtr, DevicePath, GetDevicePathSize (DevicePath));
311
312 if (UpdateDescription) {
313 //
314 // The number in option#### to be updated.
315 // In this case, we must have non-NULL TempOptionPtr.
316 //
317 ASSERT (TempOptionPtr != NULL);
318 RegisterOptionNumber = TempOptionPtr[Index];
319 } else {
320 //
321 // The new option#### number
322 //
323 RegisterOptionNumber = BdsLibGetFreeOptionNumber(VariableName);
324 }
325
326 if (*VariableName == 'B') {
327 UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", RegisterOptionNumber);
328 } else {
329 UnicodeSPrint (OptionName, sizeof (OptionName), L"Driver%04x", RegisterOptionNumber);
330 }
331
332 Status = gRT->SetVariable (
333 OptionName,
334 &gEfiGlobalVariableGuid,
335 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
336 OptionSize,
337 OptionPtr
338 );
339 //
340 // Return if only need to update a changed description or fail to set option.
341 //
342 if (EFI_ERROR (Status) || UpdateDescription) {
343 FreePool (OptionPtr);
344 if (TempOptionPtr != NULL) {
345 FreePool (TempOptionPtr);
346 }
347 return Status;
348 }
349
350 FreePool (OptionPtr);
351
352 //
353 // Update the option order variable
354 //
355
356 //
357 // If no option order
358 //
359 if (TempOptionSize == 0) {
360 BootOrderEntry = 0;
361 Status = gRT->SetVariable (
362 VariableName,
363 &gEfiGlobalVariableGuid,
364 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
365 sizeof (UINT16),
366 &BootOrderEntry
367 );
368 if (TempOptionPtr != NULL) {
369 FreePool (TempOptionPtr);
370 }
371 return Status;
372 }
373
374 //
375 // TempOptionPtr must not be NULL if TempOptionSize is not zero.
376 //
377 ASSERT (TempOptionPtr != NULL);
378 //
379 // Append the new option number to the original option order
380 //
381 OrderItemNum = (TempOptionSize / sizeof (UINT16)) + 1 ;
382 OptionOrderPtr = AllocateZeroPool ( OrderItemNum * sizeof (UINT16));
383 ASSERT (OptionOrderPtr!= NULL);
384 CopyMem (OptionOrderPtr, TempOptionPtr, (OrderItemNum - 1) * sizeof (UINT16));
385
386 OptionOrderPtr[Index] = RegisterOptionNumber;
387
388 Status = gRT->SetVariable (
389 VariableName,
390 &gEfiGlobalVariableGuid,
391 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
392 OrderItemNum * sizeof (UINT16),
393 OptionOrderPtr
394 );
395 FreePool (TempOptionPtr);
396 FreePool (OptionOrderPtr);
397
398 return Status;
399 }
400
401 /**
402 Returns the size of a device path in bytes.
403
404 This function returns the size, in bytes, of the device path data structure
405 specified by DevicePath including the end of device path node. If DevicePath
406 is NULL, then 0 is returned. If the length of the device path is bigger than
407 MaxSize, also return 0 to indicate this is an invalidate device path.
408
409 @param DevicePath A pointer to a device path data structure.
410 @param MaxSize Max valid device path size. If big than this size,
411 return error.
412
413 @retval 0 An invalid device path.
414 @retval Others The size of a device path in bytes.
415
416 **/
417 UINTN
418 GetDevicePathSizeEx (
419 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
420 IN UINTN MaxSize
421 )
422 {
423 UINTN Size;
424 UINTN NodeSize;
425
426 if (DevicePath == NULL) {
427 return 0;
428 }
429
430 //
431 // Search for the end of the device path structure
432 //
433 Size = 0;
434 while (!IsDevicePathEnd (DevicePath)) {
435 NodeSize = DevicePathNodeLength (DevicePath);
436 if (NodeSize < END_DEVICE_PATH_LENGTH) {
437 return 0;
438 }
439 Size += NodeSize;
440 if (Size > MaxSize) {
441 return 0;
442 }
443 DevicePath = NextDevicePathNode (DevicePath);
444 }
445 Size += DevicePathNodeLength (DevicePath);
446 if (Size > MaxSize) {
447 return 0;
448 }
449
450 return Size;
451 }
452
453 /**
454 Returns the length of a Null-terminated Unicode string. If the length is
455 bigger than MaxStringLen, return length 0 to indicate that this is an
456 invalidate string.
457
458 This function returns the byte length of Unicode characters in the Null-terminated
459 Unicode string specified by String.
460
461 If String is NULL, then ASSERT().
462 If String is not aligned on a 16-bit boundary, then ASSERT().
463
464 @param String A pointer to a Null-terminated Unicode string.
465 @param MaxStringLen Max string len in this string.
466
467 @retval 0 An invalid string.
468 @retval Others The length of String.
469
470 **/
471 UINTN
472 StrSizeEx (
473 IN CONST CHAR16 *String,
474 IN UINTN MaxStringLen
475 )
476 {
477 UINTN Length;
478
479 ASSERT (String != NULL && MaxStringLen != 0);
480 ASSERT (((UINTN) String & BIT0) == 0);
481
482 for (Length = 0; *String != L'\0' && MaxStringLen != Length; String++, Length+=2);
483
484 if (*String != L'\0' && MaxStringLen == Length) {
485 return 0;
486 }
487
488 return Length + 2;
489 }
490
491 /**
492 Validate the EFI Boot#### variable (VendorGuid/Name)
493
494 @param Variable Boot#### variable data.
495 @param VariableSize Returns the size of the EFI variable that was read
496
497 @retval TRUE The variable data is correct.
498 @retval FALSE The variable data is corrupted.
499
500 **/
501 BOOLEAN
502 ValidateOption (
503 UINT8 *Variable,
504 UINTN VariableSize
505 )
506 {
507 UINT16 FilePathSize;
508 UINT8 *TempPtr;
509 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
510 UINTN TempSize;
511
512 if (VariableSize <= sizeof (UINT16) + sizeof (UINT32)) {
513 return FALSE;
514 }
515
516 //
517 // Skip the option attribute
518 //
519 TempPtr = Variable;
520 TempPtr += sizeof (UINT32);
521
522 //
523 // Get the option's device path size
524 //
525 FilePathSize = *(UINT16 *) TempPtr;
526 TempPtr += sizeof (UINT16);
527
528 //
529 // Get the option's description string size
530 //
531 TempSize = StrSizeEx ((CHAR16 *) TempPtr, VariableSize - sizeof (UINT16) - sizeof (UINT32));
532 TempPtr += TempSize;
533
534 //
535 // Get the option's device path
536 //
537 DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;
538 TempPtr += FilePathSize;
539
540 //
541 // Validation boot option variable.
542 //
543 if ((FilePathSize == 0) || (TempSize == 0)) {
544 return FALSE;
545 }
546
547 if (TempSize + FilePathSize + sizeof (UINT16) + sizeof (UINT32) > VariableSize) {
548 return FALSE;
549 }
550
551 return (BOOLEAN) (GetDevicePathSizeEx (DevicePath, FilePathSize) != 0);
552 }
553
554 /**
555 Convert a single character to number.
556 It assumes the input Char is in the scope of L'0' ~ L'9' and L'A' ~ L'F'
557
558 @param Char The input char which need to change to a hex number.
559
560 **/
561 UINTN
562 CharToUint (
563 IN CHAR16 Char
564 )
565 {
566 if ((Char >= L'0') && (Char <= L'9')) {
567 return (UINTN) (Char - L'0');
568 }
569
570 if ((Char >= L'A') && (Char <= L'F')) {
571 return (UINTN) (Char - L'A' + 0xA);
572 }
573
574 ASSERT (FALSE);
575 return 0;
576 }
577
578 /**
579 Build the boot#### or driver#### option from the VariableName, the
580 build boot#### or driver#### will also be linked to BdsCommonOptionList.
581
582 @param BdsCommonOptionList The header of the boot#### or driver#### option
583 link list
584 @param VariableName EFI Variable name indicate if it is boot#### or
585 driver####
586
587 @retval BDS_COMMON_OPTION Get the option just been created
588 @retval NULL Failed to get the new option
589
590 **/
591 BDS_COMMON_OPTION *
592 EFIAPI
593 BdsLibVariableToOption (
594 IN OUT LIST_ENTRY *BdsCommonOptionList,
595 IN CHAR16 *VariableName
596 )
597 {
598 UINT32 Attribute;
599 UINT16 FilePathSize;
600 UINT8 *Variable;
601 UINT8 *TempPtr;
602 UINTN VariableSize;
603 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
604 BDS_COMMON_OPTION *Option;
605 VOID *LoadOptions;
606 UINT32 LoadOptionsSize;
607 CHAR16 *Description;
608 UINT8 NumOff;
609
610 //
611 // Read the variable. We will never free this data.
612 //
613 Variable = BdsLibGetVariableAndSize (
614 VariableName,
615 &gEfiGlobalVariableGuid,
616 &VariableSize
617 );
618 if (Variable == NULL) {
619 return NULL;
620 }
621
622 //
623 // Validate Boot#### variable data.
624 //
625 if (!ValidateOption(Variable, VariableSize)) {
626 return NULL;
627 }
628
629 //
630 // Notes: careful defined the variable of Boot#### or
631 // Driver####, consider use some macro to abstract the code
632 //
633 //
634 // Get the option attribute
635 //
636 TempPtr = Variable;
637 Attribute = *(UINT32 *) Variable;
638 TempPtr += sizeof (UINT32);
639
640 //
641 // Get the option's device path size
642 //
643 FilePathSize = *(UINT16 *) TempPtr;
644 TempPtr += sizeof (UINT16);
645
646 //
647 // Get the option's description string
648 //
649 Description = (CHAR16 *) TempPtr;
650
651 //
652 // Get the option's description string size
653 //
654 TempPtr += StrSize((CHAR16 *) TempPtr);
655
656 //
657 // Get the option's device path
658 //
659 DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;
660 TempPtr += FilePathSize;
661
662 //
663 // Get load opion data.
664 //
665 LoadOptions = TempPtr;
666 LoadOptionsSize = (UINT32) (VariableSize - (UINTN) (TempPtr - Variable));
667
668 //
669 // The Console variables may have multiple device paths, so make
670 // an Entry for each one.
671 //
672 Option = AllocateZeroPool (sizeof (BDS_COMMON_OPTION));
673 if (Option == NULL) {
674 return NULL;
675 }
676
677 Option->Signature = BDS_LOAD_OPTION_SIGNATURE;
678 Option->DevicePath = AllocateZeroPool (GetDevicePathSize (DevicePath));
679 ASSERT(Option->DevicePath != NULL);
680 CopyMem (Option->DevicePath, DevicePath, GetDevicePathSize (DevicePath));
681
682 Option->Attribute = Attribute;
683 Option->Description = AllocateZeroPool (StrSize (Description));
684 ASSERT(Option->Description != NULL);
685 CopyMem (Option->Description, Description, StrSize (Description));
686
687 Option->LoadOptions = AllocateZeroPool (LoadOptionsSize);
688 ASSERT(Option->LoadOptions != NULL);
689 CopyMem (Option->LoadOptions, LoadOptions, LoadOptionsSize);
690 Option->LoadOptionsSize = LoadOptionsSize;
691
692 //
693 // Get the value from VariableName Unicode string
694 // since the ISO standard assumes ASCII equivalent abbreviations, we can be safe in converting this
695 // Unicode stream to ASCII without any loss in meaning.
696 //
697 if (*VariableName == 'B') {
698 NumOff = (UINT8) (sizeof (L"Boot") / sizeof (CHAR16) - 1);
699 Option->BootCurrent = (UINT16) (CharToUint (VariableName[NumOff+0]) * 0x1000)
700 + (UINT16) (CharToUint (VariableName[NumOff+1]) * 0x100)
701 + (UINT16) (CharToUint (VariableName[NumOff+2]) * 0x10)
702 + (UINT16) (CharToUint (VariableName[NumOff+3]) * 0x1);
703 }
704 InsertTailList (BdsCommonOptionList, &Option->Link);
705 FreePool (Variable);
706 return Option;
707 }
708
709 /**
710 Process BootOrder, or DriverOrder variables, by calling
711 BdsLibVariableToOption () for each UINT16 in the variables.
712
713 @param BdsCommonOptionList The header of the option list base on variable
714 VariableName
715 @param VariableName EFI Variable name indicate the BootOrder or
716 DriverOrder
717
718 @retval EFI_SUCCESS Success create the boot option or driver option
719 list
720 @retval EFI_OUT_OF_RESOURCES Failed to get the boot option or driver option list
721
722 **/
723 EFI_STATUS
724 EFIAPI
725 BdsLibBuildOptionFromVar (
726 IN LIST_ENTRY *BdsCommonOptionList,
727 IN CHAR16 *VariableName
728 )
729 {
730 UINT16 *OptionOrder;
731 UINTN OptionOrderSize;
732 UINTN Index;
733 BDS_COMMON_OPTION *Option;
734 CHAR16 OptionName[20];
735
736 //
737 // Zero Buffer in order to get all BOOT#### variables
738 //
739 ZeroMem (OptionName, sizeof (OptionName));
740
741 //
742 // Read the BootOrder, or DriverOrder variable.
743 //
744 OptionOrder = BdsLibGetVariableAndSize (
745 VariableName,
746 &gEfiGlobalVariableGuid,
747 &OptionOrderSize
748 );
749 if (OptionOrder == NULL) {
750 return EFI_OUT_OF_RESOURCES;
751 }
752
753 for (Index = 0; Index < OptionOrderSize / sizeof (UINT16); Index++) {
754 if (*VariableName == 'B') {
755 UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", OptionOrder[Index]);
756 } else {
757 UnicodeSPrint (OptionName, sizeof (OptionName), L"Driver%04x", OptionOrder[Index]);
758 }
759
760 Option = BdsLibVariableToOption (BdsCommonOptionList, OptionName);
761 if (Option != NULL) {
762 Option->BootCurrent = OptionOrder[Index];
763 }
764 }
765
766 FreePool (OptionOrder);
767
768 return EFI_SUCCESS;
769 }
770
771 /**
772 Get boot mode by looking up configuration table and parsing HOB list
773
774 @param BootMode Boot mode from PEI handoff HOB.
775
776 @retval EFI_SUCCESS Successfully get boot mode
777
778 **/
779 EFI_STATUS
780 EFIAPI
781 BdsLibGetBootMode (
782 OUT EFI_BOOT_MODE *BootMode
783 )
784 {
785 *BootMode = GetBootModeHob ();
786
787 return EFI_SUCCESS;
788 }
789
790 /**
791 Read the EFI variable (VendorGuid/Name) and return a dynamically allocated
792 buffer, and the size of the buffer. If failure return NULL.
793
794 @param Name String part of EFI variable name
795 @param VendorGuid GUID part of EFI variable name
796 @param VariableSize Returns the size of the EFI variable that was read
797
798 @return Dynamically allocated memory that contains a copy of the EFI variable
799 Caller is responsible freeing the buffer.
800 @retval NULL Variable was not read
801
802 **/
803 VOID *
804 EFIAPI
805 BdsLibGetVariableAndSize (
806 IN CHAR16 *Name,
807 IN EFI_GUID *VendorGuid,
808 OUT UINTN *VariableSize
809 )
810 {
811 EFI_STATUS Status;
812 UINTN BufferSize;
813 VOID *Buffer;
814
815 Buffer = NULL;
816
817 //
818 // Pass in a zero size buffer to find the required buffer size.
819 //
820 BufferSize = 0;
821 Status = gRT->GetVariable (Name, VendorGuid, NULL, &BufferSize, Buffer);
822 if (Status == EFI_BUFFER_TOO_SMALL) {
823 //
824 // Allocate the buffer to return
825 //
826 Buffer = AllocateZeroPool (BufferSize);
827 if (Buffer == NULL) {
828 *VariableSize = 0;
829 return NULL;
830 }
831 //
832 // Read variable into the allocated buffer.
833 //
834 Status = gRT->GetVariable (Name, VendorGuid, NULL, &BufferSize, Buffer);
835 if (EFI_ERROR (Status)) {
836 FreePool (Buffer);
837 BufferSize = 0;
838 Buffer = NULL;
839 }
840 }
841
842 ASSERT (((Buffer == NULL) && (BufferSize == 0)) ||
843 ((Buffer != NULL) && (BufferSize != 0))
844 );
845 *VariableSize = BufferSize;
846 return Buffer;
847 }
848
849 /**
850 Delete the instance in Multi which matches partly with Single instance
851
852 @param Multi A pointer to a multi-instance device path data
853 structure.
854 @param Single A pointer to a single-instance device path data
855 structure.
856
857 @return This function will remove the device path instances in Multi which partly
858 match with the Single, and return the result device path. If there is no
859 remaining device path as a result, this function will return NULL.
860
861 **/
862 EFI_DEVICE_PATH_PROTOCOL *
863 EFIAPI
864 BdsLibDelPartMatchInstance (
865 IN EFI_DEVICE_PATH_PROTOCOL *Multi,
866 IN EFI_DEVICE_PATH_PROTOCOL *Single
867 )
868 {
869 EFI_DEVICE_PATH_PROTOCOL *Instance;
870 EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
871 EFI_DEVICE_PATH_PROTOCOL *TempNewDevicePath;
872 UINTN InstanceSize;
873 UINTN SingleDpSize;
874 UINTN Size;
875
876 NewDevicePath = NULL;
877 TempNewDevicePath = NULL;
878
879 if (Multi == NULL || Single == NULL) {
880 return Multi;
881 }
882
883 Instance = GetNextDevicePathInstance (&Multi, &InstanceSize);
884 SingleDpSize = GetDevicePathSize (Single) - END_DEVICE_PATH_LENGTH;
885 InstanceSize -= END_DEVICE_PATH_LENGTH;
886
887 while (Instance != NULL) {
888
889 Size = (SingleDpSize < InstanceSize) ? SingleDpSize : InstanceSize;
890
891 if ((CompareMem (Instance, Single, Size) != 0)) {
892 //
893 // Append the device path instance which does not match with Single
894 //
895 TempNewDevicePath = NewDevicePath;
896 NewDevicePath = AppendDevicePathInstance (NewDevicePath, Instance);
897 if (TempNewDevicePath != NULL) {
898 FreePool(TempNewDevicePath);
899 }
900 }
901 FreePool(Instance);
902 Instance = GetNextDevicePathInstance (&Multi, &InstanceSize);
903 InstanceSize -= END_DEVICE_PATH_LENGTH;
904 }
905
906 return NewDevicePath;
907 }
908
909 /**
910 Function compares a device path data structure to that of all the nodes of a
911 second device path instance.
912
913 @param Multi A pointer to a multi-instance device path data
914 structure.
915 @param Single A pointer to a single-instance device path data
916 structure.
917
918 @retval TRUE If the Single device path is contained within Multi device path.
919 @retval FALSE The Single device path is not match within Multi device path.
920
921 **/
922 BOOLEAN
923 EFIAPI
924 BdsLibMatchDevicePaths (
925 IN EFI_DEVICE_PATH_PROTOCOL *Multi,
926 IN EFI_DEVICE_PATH_PROTOCOL *Single
927 )
928 {
929 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
930 EFI_DEVICE_PATH_PROTOCOL *DevicePathInst;
931 UINTN Size;
932
933 if (Multi == NULL || Single == NULL) {
934 return FALSE;
935 }
936
937 DevicePath = Multi;
938 DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);
939
940 //
941 // Search for the match of 'Single' in 'Multi'
942 //
943 while (DevicePathInst != NULL) {
944 //
945 // If the single device path is found in multiple device paths,
946 // return success
947 //
948 if (CompareMem (Single, DevicePathInst, Size) == 0) {
949 FreePool (DevicePathInst);
950 return TRUE;
951 }
952
953 FreePool (DevicePathInst);
954 DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);
955 }
956
957 return FALSE;
958 }
959
960 /**
961 This function prints a series of strings.
962
963 @param ConOut Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
964 @param ... A variable argument list containing series of
965 strings, the last string must be NULL.
966
967 @retval EFI_SUCCESS Success print out the string using ConOut.
968 @retval EFI_STATUS Return the status of the ConOut->OutputString ().
969
970 **/
971 EFI_STATUS
972 EFIAPI
973 BdsLibOutputStrings (
974 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut,
975 ...
976 )
977 {
978 VA_LIST Args;
979 EFI_STATUS Status;
980 CHAR16 *String;
981
982 Status = EFI_SUCCESS;
983 VA_START (Args, ConOut);
984
985 while (!EFI_ERROR (Status)) {
986 //
987 // If String is NULL, then it's the end of the list
988 //
989 String = VA_ARG (Args, CHAR16 *);
990 if (String == NULL) {
991 break;
992 }
993
994 Status = ConOut->OutputString (ConOut, String);
995
996 if (EFI_ERROR (Status)) {
997 break;
998 }
999 }
1000
1001 VA_END(Args);
1002 return Status;
1003 }
1004
1005 //
1006 // Following are BDS Lib functions which contain all the code about setup browser reset reminder feature.
1007 // Setup Browser reset reminder feature is that an reset reminder will be given before user leaves the setup browser if
1008 // user change any option setting which needs a reset to be effective, and the reset will be applied according to the user selection.
1009 //
1010
1011
1012 /**
1013 Enable the setup browser reset reminder feature.
1014 This routine is used in platform tip. If the platform policy need the feature, use the routine to enable it.
1015
1016 **/
1017 VOID
1018 EFIAPI
1019 EnableResetReminderFeature (
1020 VOID
1021 )
1022 {
1023 mFeaturerSwitch = TRUE;
1024 }
1025
1026
1027 /**
1028 Disable the setup browser reset reminder feature.
1029 This routine is used in platform tip. If the platform policy do not want the feature, use the routine to disable it.
1030
1031 **/
1032 VOID
1033 EFIAPI
1034 DisableResetReminderFeature (
1035 VOID
1036 )
1037 {
1038 mFeaturerSwitch = FALSE;
1039 }
1040
1041
1042 /**
1043 Record the info that a reset is required.
1044 A module boolean variable is used to record whether a reset is required.
1045
1046 **/
1047 VOID
1048 EFIAPI
1049 EnableResetRequired (
1050 VOID
1051 )
1052 {
1053 mResetRequired = TRUE;
1054 }
1055
1056
1057 /**
1058 Record the info that no reset is required.
1059 A module boolean variable is used to record whether a reset is required.
1060
1061 **/
1062 VOID
1063 EFIAPI
1064 DisableResetRequired (
1065 VOID
1066 )
1067 {
1068 mResetRequired = FALSE;
1069 }
1070
1071
1072 /**
1073 Check whether platform policy enable the reset reminder feature. The default is enabled.
1074
1075 **/
1076 BOOLEAN
1077 EFIAPI
1078 IsResetReminderFeatureEnable (
1079 VOID
1080 )
1081 {
1082 return mFeaturerSwitch;
1083 }
1084
1085
1086 /**
1087 Check if user changed any option setting which needs a system reset to be effective.
1088
1089 **/
1090 BOOLEAN
1091 EFIAPI
1092 IsResetRequired (
1093 VOID
1094 )
1095 {
1096 return mResetRequired;
1097 }
1098
1099
1100 /**
1101 Check whether a reset is needed, and finish the reset reminder feature.
1102 If a reset is needed, Popup a menu to notice user, and finish the feature
1103 according to the user selection.
1104
1105 **/
1106 VOID
1107 EFIAPI
1108 SetupResetReminder (
1109 VOID
1110 )
1111 {
1112 EFI_INPUT_KEY Key;
1113 CHAR16 *StringBuffer1;
1114 CHAR16 *StringBuffer2;
1115
1116
1117 //
1118 //check any reset required change is applied? if yes, reset system
1119 //
1120 if (IsResetReminderFeatureEnable ()) {
1121 if (IsResetRequired ()) {
1122
1123 StringBuffer1 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16));
1124 ASSERT (StringBuffer1 != NULL);
1125 StringBuffer2 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16));
1126 ASSERT (StringBuffer2 != NULL);
1127 StrCpy (StringBuffer1, L"Configuration changed. Reset to apply it Now ? ");
1128 StrCpy (StringBuffer2, L"Enter (YES) / Esc (NO)");
1129 //
1130 // Popup a menu to notice user
1131 //
1132 do {
1133 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, StringBuffer1, StringBuffer2, NULL);
1134 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
1135
1136 FreePool (StringBuffer1);
1137 FreePool (StringBuffer2);
1138 //
1139 // If the user hits the YES Response key, reset
1140 //
1141 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
1142 gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);
1143 }
1144 gST->ConOut->ClearScreen (gST->ConOut);
1145 }
1146 }
1147 }
1148
1149 /**
1150 Get the headers (dos, image, optional header) from an image
1151
1152 @param Device SimpleFileSystem device handle
1153 @param FileName File name for the image
1154 @param DosHeader Pointer to dos header
1155 @param Hdr The buffer in which to return the PE32, PE32+, or TE header.
1156
1157 @retval EFI_SUCCESS Successfully get the machine type.
1158 @retval EFI_NOT_FOUND The file is not found.
1159 @retval EFI_LOAD_ERROR File is not a valid image file.
1160
1161 **/
1162 EFI_STATUS
1163 EFIAPI
1164 BdsLibGetImageHeader (
1165 IN EFI_HANDLE Device,
1166 IN CHAR16 *FileName,
1167 OUT EFI_IMAGE_DOS_HEADER *DosHeader,
1168 OUT EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr
1169 )
1170 {
1171 EFI_STATUS Status;
1172 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Volume;
1173 EFI_FILE_HANDLE Root;
1174 EFI_FILE_HANDLE ThisFile;
1175 UINTN BufferSize;
1176 UINT64 FileSize;
1177 EFI_FILE_INFO *Info;
1178
1179 Root = NULL;
1180 ThisFile = NULL;
1181 //
1182 // Handle the file system interface to the device
1183 //
1184 Status = gBS->HandleProtocol (
1185 Device,
1186 &gEfiSimpleFileSystemProtocolGuid,
1187 (VOID *) &Volume
1188 );
1189 if (EFI_ERROR (Status)) {
1190 goto Done;
1191 }
1192
1193 Status = Volume->OpenVolume (
1194 Volume,
1195 &Root
1196 );
1197 if (EFI_ERROR (Status)) {
1198 Root = NULL;
1199 goto Done;
1200 }
1201 ASSERT (Root != NULL);
1202 Status = Root->Open (Root, &ThisFile, FileName, EFI_FILE_MODE_READ, 0);
1203 if (EFI_ERROR (Status)) {
1204 goto Done;
1205 }
1206 ASSERT (ThisFile != NULL);
1207
1208 //
1209 // Get file size
1210 //
1211 BufferSize = SIZE_OF_EFI_FILE_INFO + 200;
1212 do {
1213 Info = NULL;
1214 Status = gBS->AllocatePool (EfiBootServicesData, BufferSize, (VOID **) &Info);
1215 if (EFI_ERROR (Status)) {
1216 goto Done;
1217 }
1218 Status = ThisFile->GetInfo (
1219 ThisFile,
1220 &gEfiFileInfoGuid,
1221 &BufferSize,
1222 Info
1223 );
1224 if (!EFI_ERROR (Status)) {
1225 break;
1226 }
1227 if (Status != EFI_BUFFER_TOO_SMALL) {
1228 FreePool (Info);
1229 goto Done;
1230 }
1231 FreePool (Info);
1232 } while (TRUE);
1233
1234 FileSize = Info->FileSize;
1235 FreePool (Info);
1236
1237 //
1238 // Read dos header
1239 //
1240 BufferSize = sizeof (EFI_IMAGE_DOS_HEADER);
1241 Status = ThisFile->Read (ThisFile, &BufferSize, DosHeader);
1242 if (EFI_ERROR (Status) ||
1243 BufferSize < sizeof (EFI_IMAGE_DOS_HEADER) ||
1244 FileSize <= DosHeader->e_lfanew ||
1245 DosHeader->e_magic != EFI_IMAGE_DOS_SIGNATURE) {
1246 Status = EFI_LOAD_ERROR;
1247 goto Done;
1248 }
1249
1250 //
1251 // Move to PE signature
1252 //
1253 Status = ThisFile->SetPosition (ThisFile, DosHeader->e_lfanew);
1254 if (EFI_ERROR (Status)) {
1255 Status = EFI_LOAD_ERROR;
1256 goto Done;
1257 }
1258
1259 //
1260 // Read and check PE signature
1261 //
1262 BufferSize = sizeof (EFI_IMAGE_OPTIONAL_HEADER_UNION);
1263 Status = ThisFile->Read (ThisFile, &BufferSize, Hdr.Pe32);
1264 if (EFI_ERROR (Status) ||
1265 BufferSize < sizeof (EFI_IMAGE_OPTIONAL_HEADER_UNION) ||
1266 Hdr.Pe32->Signature != EFI_IMAGE_NT_SIGNATURE) {
1267 Status = EFI_LOAD_ERROR;
1268 goto Done;
1269 }
1270
1271 //
1272 // Check PE32 or PE32+ magic
1273 //
1274 if (Hdr.Pe32->OptionalHeader.Magic != EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC &&
1275 Hdr.Pe32->OptionalHeader.Magic != EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
1276 Status = EFI_LOAD_ERROR;
1277 goto Done;
1278 }
1279
1280 Done:
1281 if (ThisFile != NULL) {
1282 ThisFile->Close (ThisFile);
1283 }
1284 if (Root != NULL) {
1285 Root->Close (Root);
1286 }
1287 return Status;
1288 }
1289
1290 /**
1291 This routine adjusts the memory information for different memory type and
1292 saves them into the variables for next boot. It conditionally resets the
1293 system when the memory information changes. Platform can reserve memory
1294 large enough (125% of actual requirement) to avoid the reset in the first boot.
1295 **/
1296 VOID
1297 BdsSetMemoryTypeInformationVariable (
1298 VOID
1299 )
1300 {
1301 EFI_STATUS Status;
1302 EFI_MEMORY_TYPE_INFORMATION *PreviousMemoryTypeInformation;
1303 EFI_MEMORY_TYPE_INFORMATION *CurrentMemoryTypeInformation;
1304 UINTN VariableSize;
1305 UINTN Index;
1306 UINTN Index1;
1307 UINT32 Previous;
1308 UINT32 Current;
1309 UINT32 Next;
1310 EFI_HOB_GUID_TYPE *GuidHob;
1311 BOOLEAN MemoryTypeInformationModified;
1312 BOOLEAN MemoryTypeInformationVariableExists;
1313 EFI_BOOT_MODE BootMode;
1314
1315 MemoryTypeInformationModified = FALSE;
1316 MemoryTypeInformationVariableExists = FALSE;
1317
1318
1319 BootMode = GetBootModeHob ();
1320 //
1321 // In BOOT_IN_RECOVERY_MODE, Variable region is not reliable.
1322 //
1323 if (BootMode == BOOT_IN_RECOVERY_MODE) {
1324 return;
1325 }
1326
1327 //
1328 // Only check the the Memory Type Information variable in the boot mode
1329 // other than BOOT_WITH_DEFAULT_SETTINGS because the Memory Type
1330 // Information is not valid in this boot mode.
1331 //
1332 if (BootMode != BOOT_WITH_DEFAULT_SETTINGS) {
1333 VariableSize = 0;
1334 Status = gRT->GetVariable (
1335 EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,
1336 &gEfiMemoryTypeInformationGuid,
1337 NULL,
1338 &VariableSize,
1339 NULL
1340 );
1341 if (Status == EFI_BUFFER_TOO_SMALL) {
1342 MemoryTypeInformationVariableExists = TRUE;
1343 }
1344 }
1345
1346 //
1347 // Retrieve the current memory usage statistics. If they are not found, then
1348 // no adjustments can be made to the Memory Type Information variable.
1349 //
1350 Status = EfiGetSystemConfigurationTable (
1351 &gEfiMemoryTypeInformationGuid,
1352 (VOID **) &CurrentMemoryTypeInformation
1353 );
1354 if (EFI_ERROR (Status) || CurrentMemoryTypeInformation == NULL) {
1355 return;
1356 }
1357
1358 //
1359 // Get the Memory Type Information settings from Hob if they exist,
1360 // PEI is responsible for getting them from variable and build a Hob to save them.
1361 // If the previous Memory Type Information is not available, then set defaults
1362 //
1363 GuidHob = GetFirstGuidHob (&gEfiMemoryTypeInformationGuid);
1364 if (GuidHob == NULL) {
1365 //
1366 // If Platform has not built Memory Type Info into the Hob, just return.
1367 //
1368 return;
1369 }
1370 PreviousMemoryTypeInformation = GET_GUID_HOB_DATA (GuidHob);
1371 VariableSize = GET_GUID_HOB_DATA_SIZE (GuidHob);
1372
1373 //
1374 // Use a heuristic to adjust the Memory Type Information for the next boot
1375 //
1376 DEBUG ((EFI_D_INFO, "Memory Previous Current Next \n"));
1377 DEBUG ((EFI_D_INFO, " Type Pages Pages Pages \n"));
1378 DEBUG ((EFI_D_INFO, "====== ======== ======== ========\n"));
1379
1380 for (Index = 0; PreviousMemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) {
1381
1382 for (Index1 = 0; CurrentMemoryTypeInformation[Index1].Type != EfiMaxMemoryType; Index1++) {
1383 if (PreviousMemoryTypeInformation[Index].Type == CurrentMemoryTypeInformation[Index1].Type) {
1384 break;
1385 }
1386 }
1387 if (CurrentMemoryTypeInformation[Index1].Type == EfiMaxMemoryType) {
1388 continue;
1389 }
1390
1391 //
1392 // Previous is the number of pages pre-allocated
1393 // Current is the number of pages actually needed
1394 //
1395 Previous = PreviousMemoryTypeInformation[Index].NumberOfPages;
1396 Current = CurrentMemoryTypeInformation[Index1].NumberOfPages;
1397 Next = Previous;
1398
1399 //
1400 // Write next varible to 125% * current and Inconsistent Memory Reserved across bootings may lead to S4 fail
1401 //
1402 if (Current < Previous) {
1403 if (BootMode == BOOT_WITH_DEFAULT_SETTINGS) {
1404 Next = Current + (Current >> 2);
1405 } else if (!MemoryTypeInformationVariableExists) {
1406 Next = MAX (Current + (Current >> 2), Previous);
1407 }
1408 } else if (Current > Previous) {
1409 Next = Current + (Current >> 2);
1410 }
1411 if (Next > 0 && Next < 4) {
1412 Next = 4;
1413 }
1414
1415 if (Next != Previous) {
1416 PreviousMemoryTypeInformation[Index].NumberOfPages = Next;
1417 MemoryTypeInformationModified = TRUE;
1418 }
1419
1420 DEBUG ((EFI_D_INFO, " %02x %08x %08x %08x\n", PreviousMemoryTypeInformation[Index].Type, Previous, Current, Next));
1421 }
1422
1423 //
1424 // If any changes were made to the Memory Type Information settings, then set the new variable value;
1425 // Or create the variable in first boot.
1426 //
1427 if (MemoryTypeInformationModified || !MemoryTypeInformationVariableExists) {
1428 Status = gRT->SetVariable (
1429 EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,
1430 &gEfiMemoryTypeInformationGuid,
1431 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
1432 VariableSize,
1433 PreviousMemoryTypeInformation
1434 );
1435
1436 //
1437 // If the Memory Type Information settings have been modified, then reset the platform
1438 // so the new Memory Type Information setting will be used to guarantee that an S4
1439 // entry/resume cycle will not fail.
1440 //
1441 if (MemoryTypeInformationModified && PcdGetBool (PcdResetOnMemoryTypeInformationChange)) {
1442 DEBUG ((EFI_D_INFO, "Memory Type Information settings change. Warm Reset!!!\n"));
1443 gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);
1444 }
1445 }
1446 }
1447
1448 /**
1449 This routine is kept for backward compatibility.
1450 **/
1451 VOID
1452 EFIAPI
1453 BdsLibSaveMemoryTypeInformation (
1454 VOID
1455 )
1456 {
1457 }
1458
1459
1460 /**
1461 Identify a user and, if authenticated, returns the current user profile handle.
1462
1463 @param[out] User Point to user profile handle.
1464
1465 @retval EFI_SUCCESS User is successfully identified, or user identification
1466 is not supported.
1467 @retval EFI_ACCESS_DENIED User is not successfully identified
1468
1469 **/
1470 EFI_STATUS
1471 EFIAPI
1472 BdsLibUserIdentify (
1473 OUT EFI_USER_PROFILE_HANDLE *User
1474 )
1475 {
1476 EFI_STATUS Status;
1477 EFI_USER_MANAGER_PROTOCOL *Manager;
1478
1479 Status = gBS->LocateProtocol (
1480 &gEfiUserManagerProtocolGuid,
1481 NULL,
1482 (VOID **) &Manager
1483 );
1484 if (EFI_ERROR (Status)) {
1485 return EFI_SUCCESS;
1486 }
1487
1488 return Manager->Identify (Manager, User);
1489 }
1490