]> git.proxmox.com Git - mirror_edk2.git/blob - EdkNt32Pkg/Library/EdkGenericBdsLib/BdsMisc.c
1. Removed #ifdef EDK_RELEASE_VERSION from all c files for all modules
[mirror_edk2.git] / EdkNt32Pkg / Library / EdkGenericBdsLib / BdsMisc.c
1 /*++
2
3 Copyright (c) 2006 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 BdsMisc.c
15
16 Abstract:
17
18 Misc BDS library function
19
20 --*/
21
22 #define MAX_STRING_LEN 200
23 static BOOLEAN mFeaturerSwitch = TRUE;
24 static BOOLEAN mResetRequired = FALSE;
25 extern UINT16 gPlatformBootTimeOutDefault;
26
27 UINT16
28 BdsLibGetTimeout (
29 VOID
30 )
31 /*++
32
33 Routine Description:
34
35 Return the default value for system Timeout variable.
36
37 Arguments:
38
39 None
40
41 Returns:
42
43 Timeout value.
44
45 --*/
46 {
47 UINT16 Timeout;
48 UINTN Size;
49 EFI_STATUS Status;
50
51 //
52 // Return Timeout variable or 0xffff if no valid
53 // Timeout variable exists.
54 //
55 Size = sizeof (UINT16);
56 Status = gRT->GetVariable (L"Timeout", &gEfiGlobalVariableGuid, NULL, &Size, &Timeout);
57 if (!EFI_ERROR (Status)) {
58 return Timeout;
59 }
60 //
61 // To make the current EFI Automatic-Test activity possible, just add
62 // following code to make AutoBoot enabled when this variable is not
63 // present.
64 // This code should be removed later.
65 //
66 Timeout = gPlatformBootTimeOutDefault;
67
68 //
69 // Notes: Platform should set default variable if non exists on all error cases!!!
70 //
71 Status = gRT->SetVariable (
72 L"Timeout",
73 &gEfiGlobalVariableGuid,
74 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
75 sizeof (UINT16),
76 &Timeout
77 );
78 return Timeout;
79 }
80
81 VOID
82 BdsLibLoadDrivers (
83 IN LIST_ENTRY *BdsDriverLists
84 )
85 /*++
86
87 Routine Description:
88
89 The function will go through the driver optoin link list, load and start
90 every driver the driver optoin device path point to.
91
92 Arguments:
93
94 BdsDriverLists - The header of the current driver option link list
95
96 Returns:
97
98 None
99
100 --*/
101 {
102 EFI_STATUS Status;
103 LIST_ENTRY *Link;
104 BDS_COMMON_OPTION *Option;
105 EFI_HANDLE ImageHandle;
106 EFI_LOADED_IMAGE_PROTOCOL *ImageInfo;
107 UINTN ExitDataSize;
108 CHAR16 *ExitData;
109 BOOLEAN ReconnectAll;
110
111 ReconnectAll = FALSE;
112
113 //
114 // Process the driver option
115 //
116 for (Link = BdsDriverLists->ForwardLink; Link != BdsDriverLists; Link = Link->ForwardLink) {
117 Option = CR (Link, BDS_COMMON_OPTION, Link, BDS_LOAD_OPTION_SIGNATURE);
118 //
119 // If a load option is not marked as LOAD_OPTION_ACTIVE,
120 // the boot manager will not automatically load the option.
121 //
122 if (!IS_LOAD_OPTION_TYPE (Option->Attribute, LOAD_OPTION_ACTIVE)) {
123 continue;
124 }
125 //
126 // If a driver load option is marked as LOAD_OPTION_FORCE_RECONNECT,
127 // then all of the EFI drivers in the system will be disconnected and
128 // reconnected after the last driver load option is processed.
129 //
130 if (IS_LOAD_OPTION_TYPE (Option->Attribute, LOAD_OPTION_FORCE_RECONNECT)) {
131 ReconnectAll = TRUE;
132 }
133 //
134 // Make sure the driver path is connected.
135 //
136 BdsLibConnectDevicePath (Option->DevicePath);
137
138 //
139 // Load and start the image that Driver#### describes
140 //
141 Status = gBS->LoadImage (
142 FALSE,
143 mBdsImageHandle,
144 Option->DevicePath,
145 NULL,
146 0,
147 &ImageHandle
148 );
149
150 if (!EFI_ERROR (Status)) {
151 gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, &ImageInfo);
152
153 //
154 // Verify whether this image is a driver, if not,
155 // exit it and continue to parse next load option
156 //
157 if (ImageInfo->ImageCodeType != EfiBootServicesCode && ImageInfo->ImageCodeType != EfiRuntimeServicesCode) {
158 gBS->Exit (ImageHandle, EFI_INVALID_PARAMETER, 0, NULL);
159 continue;
160 }
161
162 if (Option->LoadOptionsSize != 0) {
163 ImageInfo->LoadOptionsSize = Option->LoadOptionsSize;
164 ImageInfo->LoadOptions = Option->LoadOptions;
165 }
166 //
167 // Before calling the image, enable the Watchdog Timer for
168 // the 5 Minute period
169 //
170 gBS->SetWatchdogTimer (5 * 60, 0x0000, 0x00, NULL);
171
172 Status = gBS->StartImage (ImageHandle, &ExitDataSize, &ExitData);
173 DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Driver Return Status = %r\n", Status));
174
175 //
176 // Clear the Watchdog Timer after the image returns
177 //
178 gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL);
179 }
180 }
181 //
182 // Process the LOAD_OPTION_FORCE_RECONNECT driver option
183 //
184 if (ReconnectAll) {
185 BdsLibDisconnectAllEfi ();
186 BdsLibConnectAll ();
187 }
188
189 }
190
191 EFI_STATUS
192 BdsLibRegisterNewOption (
193 IN LIST_ENTRY *BdsOptionList,
194 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
195 IN CHAR16 *String,
196 IN CHAR16 *VariableName
197 )
198 /*++
199
200 Routine Description:
201
202 This function will register the new boot#### or driver#### option base on
203 the VariableName. The new registered boot#### or driver#### will be linked
204 to BdsOptionList and also update to the VariableName. After the boot#### or
205 driver#### updated, the BootOrder or DriverOrder will also be updated.
206
207 Arguments:
208
209 BdsOptionList - The header of the boot#### or driver#### link list
210
211 DevicePath - The device path which the boot####
212 or driver#### option present
213
214 String - The description of the boot#### or driver####
215
216 VariableName - Indicate if the boot#### or driver#### option
217
218 Returns:
219
220 EFI_SUCCESS - The boot#### or driver#### have been success registered
221
222 EFI_STATUS - Return the status of gRT->SetVariable ().
223
224 --*/
225 {
226 EFI_STATUS Status;
227 UINTN Index;
228 UINT16 MaxOptionNumber;
229 UINT16 RegisterOptionNumber;
230 UINT16 *TempOptionPtr;
231 UINTN TempOptionSize;
232 UINT16 *OptionOrderPtr;
233 VOID *OptionPtr;
234 UINTN OptionSize;
235 UINT8 *TempPtr;
236 EFI_DEVICE_PATH_PROTOCOL *OptionDevicePath;
237 CHAR16 *Description;
238 CHAR16 OptionName[10];
239 BOOLEAN UpdateBootDevicePath;
240
241 OptionPtr = NULL;
242 OptionSize = 0;
243 TempPtr = NULL;
244 OptionDevicePath = NULL;
245 Description = NULL;
246 MaxOptionNumber = 0;
247 OptionOrderPtr = NULL;
248 UpdateBootDevicePath = FALSE;
249 ZeroMem (OptionName, sizeof (OptionName));
250
251 TempOptionSize = 0;
252 TempOptionPtr = BdsLibGetVariableAndSize (
253 VariableName,
254 &gEfiGlobalVariableGuid,
255 &TempOptionSize
256 );
257 //
258 // Compare with current option variable
259 //
260 for (Index = 0; Index < TempOptionSize / sizeof (UINT16); Index++) {
261 //
262 // Got the max option#### number
263 //
264 if (MaxOptionNumber < TempOptionPtr[Index]) {
265 MaxOptionNumber = TempOptionPtr[Index];
266 }
267
268 if (*VariableName == 'B') {
269 UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", TempOptionPtr[Index]);
270 } else {
271 UnicodeSPrint (OptionName, sizeof (OptionName), L"Driver%04x", TempOptionPtr[Index]);
272 }
273
274 OptionPtr = BdsLibGetVariableAndSize (
275 OptionName,
276 &gEfiGlobalVariableGuid,
277 &OptionSize
278 );
279 TempPtr = OptionPtr;
280 TempPtr += sizeof (UINT32) + sizeof (UINT16);
281 Description = (CHAR16 *) TempPtr;
282 TempPtr += StrSize ((CHAR16 *) TempPtr);
283 OptionDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;
284
285 //
286 // Notes: the description may will change base on the GetStringToken
287 //
288 if (CompareMem (Description, String, StrSize (Description)) == 0) {
289 if (CompareMem (OptionDevicePath, DevicePath, GetDevicePathSize (OptionDevicePath)) == 0) {
290 //
291 // Got the option, so just return
292 //
293 gBS->FreePool (OptionPtr);
294 gBS->FreePool (TempOptionPtr);
295 return EFI_SUCCESS;
296 } else {
297 //
298 // Boot device path changed, need update.
299 //
300 UpdateBootDevicePath = TRUE;
301 break;
302 }
303 }
304
305 gBS->FreePool (OptionPtr);
306 }
307
308 OptionSize = sizeof (UINT32) + sizeof (UINT16) + StrSize (String) + GetDevicePathSize (DevicePath);
309 OptionPtr = AllocateZeroPool (OptionSize);
310 TempPtr = OptionPtr;
311 *(UINT32 *) TempPtr = LOAD_OPTION_ACTIVE;
312 TempPtr += sizeof (UINT32);
313 *(UINT16 *) TempPtr = (UINT16) GetDevicePathSize (DevicePath);
314 TempPtr += sizeof (UINT16);
315 CopyMem (TempPtr, String, StrSize (String));
316 TempPtr += StrSize (String);
317 CopyMem (TempPtr, DevicePath, GetDevicePathSize (DevicePath));
318
319 if (UpdateBootDevicePath) {
320 //
321 // The number in option#### to be updated
322 //
323 RegisterOptionNumber = TempOptionPtr[Index];
324 } else {
325 //
326 // The new option#### number
327 //
328 RegisterOptionNumber = MaxOptionNumber + 1;
329 }
330
331 if (*VariableName == 'B') {
332 UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", RegisterOptionNumber);
333 } else {
334 UnicodeSPrint (OptionName, sizeof (OptionName), L"Driver%04x", RegisterOptionNumber);
335 }
336
337 Status = gRT->SetVariable (
338 OptionName,
339 &gEfiGlobalVariableGuid,
340 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
341 OptionSize,
342 OptionPtr
343 );
344 if (EFI_ERROR (Status) || UpdateBootDevicePath) {
345 gBS->FreePool (OptionPtr);
346 gBS->FreePool (TempOptionPtr);
347 return Status;
348 }
349
350 gBS->FreePool (OptionPtr);
351
352 //
353 // Update the option order variable
354 //
355 OptionOrderPtr = AllocateZeroPool ((Index + 1) * sizeof (UINT16));
356 CopyMem (OptionOrderPtr, TempOptionPtr, Index * sizeof (UINT16));
357 OptionOrderPtr[Index] = RegisterOptionNumber;
358 Status = gRT->SetVariable (
359 VariableName,
360 &gEfiGlobalVariableGuid,
361 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
362 (Index + 1) * sizeof (UINT16),
363 OptionOrderPtr
364 );
365 if (EFI_ERROR (Status)) {
366 gBS->FreePool (TempOptionPtr);
367 gBS->FreePool (OptionOrderPtr);
368 return Status;
369 }
370
371 gBS->FreePool (TempOptionPtr);
372 gBS->FreePool (OptionOrderPtr);
373
374 return EFI_SUCCESS;
375 }
376
377 BDS_COMMON_OPTION *
378 BdsLibVariableToOption (
379 IN OUT LIST_ENTRY *BdsCommonOptionList,
380 IN CHAR16 *VariableName
381 )
382 /*++
383
384 Routine Description:
385
386 Build the boot#### or driver#### option from the VariableName, the
387 build boot#### or driver#### will also be linked to BdsCommonOptionList
388
389 Arguments:
390
391 BdsCommonOptionList - The header of the boot#### or driver#### option link list
392
393 VariableName - EFI Variable name indicate if it is boot#### or driver####
394
395 Returns:
396
397 BDS_COMMON_OPTION - Get the option just been created
398
399 NULL - Failed to get the new option
400
401 --*/
402 {
403 UINT32 Attribute;
404 UINT16 FilePathSize;
405 UINT8 *Variable;
406 UINT8 *TempPtr;
407 UINTN VariableSize;
408 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
409 BDS_COMMON_OPTION *Option;
410 VOID *LoadOptions;
411 UINT32 LoadOptionsSize;
412 CHAR16 *Description;
413
414 //
415 // Read the variable. We will never free this data.
416 //
417 Variable = BdsLibGetVariableAndSize (
418 VariableName,
419 &gEfiGlobalVariableGuid,
420 &VariableSize
421 );
422 if (Variable == NULL) {
423 return NULL;
424 }
425 //
426 // Notes: careful defined the variable of Boot#### or
427 // Driver####, consider use some macro to abstract the code
428 //
429 //
430 // Get the option attribute
431 //
432 TempPtr = Variable;
433 Attribute = *(UINT32 *) Variable;
434 TempPtr += sizeof (UINT32);
435
436 //
437 // Get the option's device path size
438 //
439 FilePathSize = *(UINT16 *) TempPtr;
440 TempPtr += sizeof (UINT16);
441
442 //
443 // Get the option's description string
444 //
445 Description = (CHAR16 *) TempPtr;
446
447 //
448 // Get the option's description string size
449 //
450 TempPtr += StrSize ((CHAR16 *) TempPtr);
451
452 //
453 // Get the option's device path
454 //
455 DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;
456 TempPtr += FilePathSize;
457
458 LoadOptions = TempPtr;
459 LoadOptionsSize = (UINT32) (VariableSize - (UINTN) (TempPtr - Variable));
460
461 //
462 // The Console variables may have multiple device paths, so make
463 // an Entry for each one.
464 //
465 Option = AllocateZeroPool (sizeof (BDS_COMMON_OPTION));
466 if (Option == NULL) {
467 return NULL;
468 }
469
470 Option->Signature = BDS_LOAD_OPTION_SIGNATURE;
471 Option->DevicePath = AllocateZeroPool (GetDevicePathSize (DevicePath));
472 CopyMem (Option->DevicePath, DevicePath, GetDevicePathSize (DevicePath));
473 Option->Attribute = Attribute;
474 Option->Description = AllocateZeroPool (StrSize (Description));
475 CopyMem (Option->Description, Description, StrSize (Description));
476 Option->LoadOptions = AllocateZeroPool (LoadOptionsSize);
477 CopyMem (Option->LoadOptions, LoadOptions, LoadOptionsSize);
478 Option->LoadOptionsSize = LoadOptionsSize;
479
480 //
481 // Insert active entry to BdsDeviceList
482 //
483 if ((Option->Attribute & LOAD_OPTION_ACTIVE) == LOAD_OPTION_ACTIVE) {
484 InsertTailList (BdsCommonOptionList, &Option->Link);
485 gBS->FreePool (Variable);
486 return Option;
487 }
488
489 gBS->FreePool (Variable);
490 gBS->FreePool (Option);
491 return NULL;
492
493 }
494
495 EFI_STATUS
496 BdsLibBuildOptionFromVar (
497 IN LIST_ENTRY *BdsCommonOptionList,
498 IN CHAR16 *VariableName
499 )
500 /*++
501
502 Routine Description:
503
504 Process BootOrder, or DriverOrder variables, by calling
505 BdsLibVariableToOption () for each UINT16 in the variables.
506
507 Arguments:
508
509 BdsCommonOptionList - The header of the option list base on variable
510 VariableName
511
512 VariableName - EFI Variable name indicate the BootOrder or DriverOrder
513
514 Returns:
515
516 EFI_SUCCESS - Success create the boot option or driver option list
517
518 EFI_OUT_OF_RESOURCES - Failed to get the boot option or driver option list
519
520 --*/
521 {
522 UINT16 *OptionOrder;
523 UINTN OptionOrderSize;
524 UINTN Index;
525 BDS_COMMON_OPTION *Option;
526 CHAR16 OptionName[20];
527
528 //
529 // Zero Buffer in order to get all BOOT#### variables
530 //
531 ZeroMem (OptionName, sizeof (OptionName));
532
533 //
534 // Read the BootOrder, or DriverOrder variable.
535 //
536 OptionOrder = BdsLibGetVariableAndSize (
537 VariableName,
538 &gEfiGlobalVariableGuid,
539 &OptionOrderSize
540 );
541 if (OptionOrder == NULL) {
542 return EFI_OUT_OF_RESOURCES;
543 }
544
545 for (Index = 0; Index < OptionOrderSize / sizeof (UINT16); Index++) {
546 if (*VariableName == 'B') {
547 UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", OptionOrder[Index]);
548 } else {
549 UnicodeSPrint (OptionName, sizeof (OptionName), L"Driver%04x", OptionOrder[Index]);
550 }
551 Option = BdsLibVariableToOption (BdsCommonOptionList, OptionName);
552 Option->BootCurrent = OptionOrder[Index];
553
554 }
555
556 gBS->FreePool (OptionOrder);
557
558 return EFI_SUCCESS;
559 }
560
561 VOID *
562 BdsLibGetVariableAndSize (
563 IN CHAR16 *Name,
564 IN EFI_GUID *VendorGuid,
565 OUT UINTN *VariableSize
566 )
567 /*++
568
569 Routine Description:
570
571 Read the EFI variable (VendorGuid/Name) and return a dynamically allocated
572 buffer, and the size of the buffer. If failure return NULL.
573
574 Arguments:
575
576 Name - String part of EFI variable name
577
578 VendorGuid - GUID part of EFI variable name
579
580 VariableSize - Returns the size of the EFI variable that was read
581
582 Returns:
583
584 Dynamically allocated memory that contains a copy of the EFI variable.
585 Caller is responsible freeing the buffer.
586
587 NULL - Variable was not read
588
589 --*/
590 {
591 EFI_STATUS Status;
592 UINTN BufferSize;
593 VOID *Buffer;
594
595 Buffer = NULL;
596
597 //
598 // Pass in a zero size buffer to find the required buffer size.
599 //
600 BufferSize = 0;
601 Status = gRT->GetVariable (Name, VendorGuid, NULL, &BufferSize, Buffer);
602 if (Status == EFI_BUFFER_TOO_SMALL) {
603 //
604 // Allocate the buffer to return
605 //
606 Buffer = AllocateZeroPool (BufferSize);
607 if (Buffer == NULL) {
608 return NULL;
609 }
610 //
611 // Read variable into the allocated buffer.
612 //
613 Status = gRT->GetVariable (Name, VendorGuid, NULL, &BufferSize, Buffer);
614 if (EFI_ERROR (Status)) {
615 BufferSize = 0;
616 }
617 }
618
619 *VariableSize = BufferSize;
620 return Buffer;
621 }
622
623 VOID
624 BdsLibSafeFreePool (
625 IN VOID *Buffer
626 )
627 /*++
628
629 Routine Description:
630
631 Free pool safely.
632
633 Arguments:
634
635 Buffer - The allocated pool entry to free
636
637 Returns:
638
639 Pointer of the buffer allocated.
640
641 --*/
642 {
643 if (Buffer != NULL) {
644 gBS->FreePool (Buffer);
645 Buffer = NULL;
646 }
647 }
648
649 EFI_DEVICE_PATH_PROTOCOL *
650 BdsLibDelPartMatchInstance (
651 IN EFI_DEVICE_PATH_PROTOCOL *Multi,
652 IN EFI_DEVICE_PATH_PROTOCOL *Single
653 )
654 /*++
655
656 Routine Description:
657
658 Delete the instance in Multi which matches partly with Single instance
659
660 Arguments:
661
662 Multi - A pointer to a multi-instance device path data structure.
663
664 Single - A pointer to a single-instance device path data structure.
665
666 Returns:
667
668 This function will remove the device path instances in Multi which partly
669 match with the Single, and return the result device path. If there is no
670 remaining device path as a result, this function will return NULL.
671
672 --*/
673 {
674 EFI_DEVICE_PATH_PROTOCOL *Instance;
675 EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
676 EFI_DEVICE_PATH_PROTOCOL *TempNewDevicePath;
677 UINTN InstanceSize;
678 UINTN SingleDpSize;
679 UINTN Size;
680
681 NewDevicePath = NULL;
682 TempNewDevicePath = NULL;
683
684 if (Multi == NULL || Single == NULL) {
685 return Multi;
686 }
687
688 Instance = GetNextDevicePathInstance (&Multi, &InstanceSize);
689 SingleDpSize = GetDevicePathSize (Single) - END_DEVICE_PATH_LENGTH;
690 InstanceSize -= END_DEVICE_PATH_LENGTH;
691
692 while (Instance != NULL) {
693
694 Size = (SingleDpSize < InstanceSize) ? SingleDpSize : InstanceSize;
695
696 if ((CompareMem (Instance, Single, Size) != 0)) {
697 //
698 // Append the device path instance which does not match with Single
699 //
700 TempNewDevicePath = NewDevicePath;
701 NewDevicePath = AppendDevicePathInstance (NewDevicePath, Instance);
702 BdsLibSafeFreePool(TempNewDevicePath);
703 }
704 BdsLibSafeFreePool(Instance);
705 Instance = GetNextDevicePathInstance (&Multi, &InstanceSize);
706 InstanceSize -= END_DEVICE_PATH_LENGTH;
707 }
708
709 return NewDevicePath;
710 }
711
712 BOOLEAN
713 BdsLibMatchDevicePaths (
714 IN EFI_DEVICE_PATH_PROTOCOL *Multi,
715 IN EFI_DEVICE_PATH_PROTOCOL *Single
716 )
717 /*++
718
719 Routine Description:
720
721 Function compares a device path data structure to that of all the nodes of a
722 second device path instance.
723
724 Arguments:
725
726 Multi - A pointer to a multi-instance device path data structure.
727
728 Single - A pointer to a single-instance device path data structure.
729
730 Returns:
731
732 TRUE - If the Single is contained within Multi
733
734 FALSE - The Single is not match within Multi
735
736
737 --*/
738 {
739 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
740 EFI_DEVICE_PATH_PROTOCOL *DevicePathInst;
741 UINTN Size;
742
743 if (!Multi || !Single) {
744 return FALSE;
745 }
746
747 DevicePath = Multi;
748 DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);
749
750 //
751 // Search for the match of 'Single' in 'Multi'
752 //
753 while (DevicePathInst != NULL) {
754 //
755 // If the single device path is found in multiple device paths,
756 // return success
757 //
758 if (CompareMem (Single, DevicePathInst, Size) == 0) {
759 gBS->FreePool (DevicePathInst);
760 return TRUE;
761 }
762
763 gBS->FreePool (DevicePathInst);
764 DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);
765 }
766
767 return FALSE;
768 }
769
770 EFI_STATUS
771 BdsLibOutputStrings (
772 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *ConOut,
773 ...
774 )
775 /*++
776
777 Routine Description:
778
779 This function prints a series of strings.
780
781 Arguments:
782
783 ConOut - Pointer to EFI_SIMPLE_TEXT_OUT_PROTOCOL
784
785 ... - A variable argument list containing series of strings,
786 the last string must be NULL.
787
788 Returns:
789
790 EFI_SUCCESS - Success print out the string using ConOut.
791
792 EFI_STATUS - Return the status of the ConOut->OutputString ().
793
794 --*/
795 {
796 VA_LIST args;
797 EFI_STATUS Status;
798 CHAR16 *String;
799
800 Status = EFI_SUCCESS;
801 VA_START (args, ConOut);
802
803 while (!EFI_ERROR (Status)) {
804 //
805 // If String is NULL, then it's the end of the list
806 //
807 String = VA_ARG (args, CHAR16 *);
808 if (!String) {
809 break;
810 }
811
812 Status = ConOut->OutputString (ConOut, String);
813
814 if (EFI_ERROR (Status)) {
815 break;
816 }
817 }
818
819 return Status;
820 }
821
822 //
823 // Following are BDS Lib functions which contain all the code about setup browser reset reminder feature.
824 // Setup Browser reset reminder feature is that an reset reminder will be given before user leaves the setup browser if
825 // user change any option setting which needs a reset to be effective, and the reset will be applied according to the user selection.
826 //
827
828 VOID
829 EnableResetReminderFeature (
830 VOID
831 )
832 /*++
833
834 Routine Description:
835
836 Enable the setup browser reset reminder feature.
837 This routine is used in platform tip. If the platform policy need the feature, use the routine to enable it.
838
839 Arguments:
840
841 VOID
842
843 Returns:
844
845 VOID
846
847 --*/
848 {
849 mFeaturerSwitch = TRUE;
850 }
851
852 VOID
853 DisableResetReminderFeature (
854 VOID
855 )
856 /*++
857
858 Routine Description:
859
860 Disable the setup browser reset reminder feature.
861 This routine is used in platform tip. If the platform policy do not want the feature, use the routine to disable it.
862
863 Arguments:
864
865 VOID
866
867 Returns:
868
869 VOID
870
871 --*/
872 {
873 mFeaturerSwitch = FALSE;
874 }
875
876 VOID
877 EnableResetRequired (
878 VOID
879 )
880 /*++
881
882 Routine Description:
883
884 Record the info that a reset is required.
885 A module boolean variable is used to record whether a reset is required.
886
887 Arguments:
888
889 VOID
890
891 Returns:
892
893 VOID
894
895 --*/
896 {
897 mResetRequired = TRUE;
898 }
899
900 VOID
901 DisableResetRequired (
902 VOID
903 )
904 /*++
905
906 Routine Description:
907
908 Record the info that no reset is required.
909 A module boolean variable is used to record whether a reset is required.
910
911 Arguments:
912
913 VOID
914
915 Returns:
916
917 VOID
918
919 --*/
920 {
921 mResetRequired = FALSE;
922 }
923
924 BOOLEAN
925 IsResetReminderFeatureEnable (
926 VOID
927 )
928 /*++
929
930 Routine Description:
931
932 Check whether platform policy enable the reset reminder feature. The default is enabled.
933
934 Arguments:
935
936 VOID
937
938 Returns:
939
940 VOID
941
942 --*/
943 {
944 return mFeaturerSwitch;
945 }
946
947 BOOLEAN
948 IsResetRequired (
949 VOID
950 )
951 /*++
952
953 Routine Description:
954
955 Check if user changed any option setting which needs a system reset to be effective.
956
957 Arguments:
958
959 VOID
960
961 Returns:
962
963 VOID
964
965 --*/
966 {
967 return mResetRequired;
968 }
969
970 VOID
971 SetupResetReminder (
972 VOID
973 )
974 /*++
975
976 Routine Description:
977
978 Check whether a reset is needed, and finish the reset reminder feature.
979 If a reset is needed, Popup a menu to notice user, and finish the feature
980 according to the user selection.
981
982 Arguments:
983
984 VOID
985
986 Returns:
987
988 VOID
989
990 --*/
991 {
992 EFI_STATUS Status;
993 EFI_FORM_BROWSER_PROTOCOL *Browser;
994 EFI_INPUT_KEY Key;
995 CHAR16 *StringBuffer1;
996 CHAR16 *StringBuffer2;
997
998
999 //
1000 //check any reset required change is applied? if yes, reset system
1001 //
1002 if (IsResetReminderFeatureEnable ()) {
1003 if (IsResetRequired ()) {
1004
1005 Status = gBS->LocateProtocol (
1006 &gEfiFormBrowserProtocolGuid,
1007 NULL,
1008 &Browser
1009 );
1010
1011 StringBuffer1 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16));
1012 ASSERT (StringBuffer1 != NULL);
1013 StringBuffer2 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16));
1014 ASSERT (StringBuffer2 != NULL);
1015 StrCpy (StringBuffer1, L"Configuration changed. Reset to apply it Now ? ");
1016 StrCpy (StringBuffer2, L"Enter (YES) / Esc (NO)");
1017 //
1018 // Popup a menu to notice user
1019 //
1020 do {
1021 Browser->CreatePopUp (2, TRUE, 0, NULL, &Key, StringBuffer1, StringBuffer2);
1022 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
1023
1024 gBS->FreePool (StringBuffer1);
1025 gBS->FreePool (StringBuffer2);
1026 //
1027 // If the user hits the YES Response key, reset
1028 //
1029 if ((Key.UnicodeChar == CHAR_CARRIAGE_RETURN)) {
1030 gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);
1031 }
1032 gST->ConOut->ClearScreen (gST->ConOut);
1033 }
1034 }
1035 }
1036
1037 EFI_STATUS
1038 BdsLibGetHiiHandles (
1039 IN EFI_HII_PROTOCOL *Hii,
1040 IN OUT UINT16 *HandleBufferLength,
1041 OUT EFI_HII_HANDLE **HiiHandleBuffer
1042 )
1043 /*++
1044
1045 Routine Description:
1046
1047 Determines the handles that are currently active in the database.
1048 It's the caller's responsibility to free handle buffer.
1049
1050 Arguments:
1051
1052 This - A pointer to the EFI_HII_PROTOCOL instance.
1053 HandleBufferLength - On input, a pointer to the length of the handle buffer. On output,
1054 the length of the handle buffer that is required for the handles found.
1055 HiiHandleBuffer - Pointer to an array of EFI_HII_PROTOCOL instances returned.
1056
1057 Returns:
1058
1059 EFI_SUCCESS - Get an array of EFI_HII_PROTOCOL instances successfully.
1060 EFI_INVALID_PARAMETER - Hii is NULL.
1061 EFI_NOT_FOUND - Database not found.
1062
1063 --*/
1064 {
1065 UINT16 TempBufferLength;
1066 EFI_STATUS Status;
1067
1068 TempBufferLength = 0;
1069
1070 //
1071 // Try to find the actual buffer size for HiiHandle Buffer.
1072 //
1073 Status = Hii->FindHandles (Hii, &TempBufferLength, *HiiHandleBuffer);
1074
1075 if (Status == EFI_BUFFER_TOO_SMALL) {
1076 *HiiHandleBuffer = AllocateZeroPool (TempBufferLength);
1077 Status = Hii->FindHandles (Hii, &TempBufferLength, *HiiHandleBuffer);
1078 //
1079 // we should not fail here.
1080 //
1081 ASSERT_EFI_ERROR (Status);
1082 }
1083
1084 *HandleBufferLength = TempBufferLength;
1085
1086 return Status;
1087
1088 }