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