2 FrontPage routines to handle the callbacks and browser calls
4 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "FrontPage.h"
14 BOOLEAN mModeInitialized
= FALSE
;
16 BOOLEAN gConnectAllHappened
= FALSE
;
18 CHAR8
*mLanguageString
;
21 // Boot video resolution and text mode.
23 UINT32 mBootHorizontalResolution
= 0;
24 UINT32 mBootVerticalResolution
= 0;
25 UINT32 mBootTextModeColumn
= 0;
26 UINT32 mBootTextModeRow
= 0;
28 // BIOS setup video resolution and text mode.
30 UINT32 mSetupTextModeColumn
= 0;
31 UINT32 mSetupTextModeRow
= 0;
32 UINT32 mSetupHorizontalResolution
= 0;
33 UINT32 mSetupVerticalResolution
= 0;
35 EFI_FORM_BROWSER2_PROTOCOL
*gFormBrowser2
;
37 FRONT_PAGE_CALLBACK_DATA gFrontPagePrivate
= {
38 FRONT_PAGE_CALLBACK_DATA_SIGNATURE
,
49 HII_VENDOR_DEVICE_PATH mFrontPageHiiVendorDevicePath
= {
55 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
56 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
59 FRONT_PAGE_FORMSET_GUID
63 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
65 (UINT8
) (END_DEVICE_PATH_LENGTH
),
66 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
72 This function allows a caller to extract the current configuration for one
73 or more named elements from the target driver.
76 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
77 @param Request A null-terminated Unicode string in <ConfigRequest> format.
78 @param Progress On return, points to a character in the Request string.
79 Points to the string's null terminator if request was successful.
80 Points to the most recent '&' before the first failing name/value
81 pair (or the beginning of the string if the failure is in the
82 first name/value pair) if the request was not successful.
83 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
84 has all values filled in for the names in the Request string.
85 String to be allocated by the called function.
87 @retval EFI_SUCCESS The Results is filled with the requested values.
88 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
89 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
90 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
96 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
97 IN CONST EFI_STRING Request
,
98 OUT EFI_STRING
*Progress
,
99 OUT EFI_STRING
*Results
102 if (Progress
== NULL
|| Results
== NULL
) {
103 return EFI_INVALID_PARAMETER
;
106 return EFI_NOT_FOUND
;
110 This function processes the results of changes in configuration.
113 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
114 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
115 @param Progress A pointer to a string filled in with the offset of the most
116 recent '&' before the first failing name/value pair (or the
117 beginning of the string if the failure is in the first
118 name/value pair) or the terminating NULL if all was successful.
120 @retval EFI_SUCCESS The Results is processed successfully.
121 @retval EFI_INVALID_PARAMETER Configuration is NULL.
122 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
128 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
129 IN CONST EFI_STRING Configuration
,
130 OUT EFI_STRING
*Progress
133 if (Configuration
== NULL
|| Progress
== NULL
) {
134 return EFI_INVALID_PARAMETER
;
137 *Progress
= Configuration
;
138 if (!HiiIsConfigHdrMatch (Configuration
, &gBootMaintFormSetGuid
, mBootMaintStorageName
)
139 && !HiiIsConfigHdrMatch (Configuration
, &gFileExploreFormSetGuid
, mFileExplorerStorageName
)) {
140 return EFI_NOT_FOUND
;
143 *Progress
= Configuration
+ StrLen (Configuration
);
148 This function processes the results of changes in configuration.
151 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
152 @param Action Specifies the type of action taken by the browser.
153 @param QuestionId A unique value which is sent to the original exporting driver
154 so that it can identify the type of data to expect.
155 @param Type The type of value for the question.
156 @param Value A pointer to the data being sent to the original exporting driver.
157 @param ActionRequest On return, points to the action requested by the callback function.
159 @retval EFI_SUCCESS The callback successfully handled the action.
160 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
161 @retval EFI_DEVICE_ERROR The variable could not be saved.
162 @retval EFI_UNSUPPORTED The specified Action is not supported by the callback.
168 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
169 IN EFI_BROWSER_ACTION Action
,
170 IN EFI_QUESTION_ID QuestionId
,
172 IN EFI_IFR_TYPE_VALUE
*Value
,
173 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
180 if (Action
!= EFI_BROWSER_ACTION_CHANGING
&& Action
!= EFI_BROWSER_ACTION_CHANGED
) {
182 // All other action return unsupported.
184 return EFI_UNSUPPORTED
;
187 gCallbackKey
= QuestionId
;
189 if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
190 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
191 return EFI_INVALID_PARAMETER
;
194 switch (QuestionId
) {
195 case FRONT_PAGE_KEY_CONTINUE
:
197 // This is the continue - clear the screen and return an error to get out of FrontPage loop
199 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
202 case FRONT_PAGE_KEY_LANGUAGE
:
204 // Allocate working buffer for RFC 4646 language in supported LanguageString.
206 Lang
= AllocatePool (AsciiStrSize (mLanguageString
));
207 ASSERT (Lang
!= NULL
);
210 LangCode
= mLanguageString
;
211 while (*LangCode
!= 0) {
212 GetNextLanguage (&LangCode
, Lang
);
214 if (Index
== Value
->u8
) {
221 if (Index
== Value
->u8
) {
222 BdsDxeSetVariableAndReportStatusCodeOnError (
224 &gEfiGlobalVariableGuid
,
225 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
233 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
241 } else if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
243 return EFI_INVALID_PARAMETER
;
247 // The first 4 entries in the Front Page are to be GUARANTEED to remain constant so IHV's can
248 // describe to their customers in documentation how to find their setup information (namely
249 // under the device manager and specific buckets)
251 switch (QuestionId
) {
252 case FRONT_PAGE_KEY_BOOT_MANAGER
:
258 case FRONT_PAGE_KEY_DEVICE_MANAGER
:
264 case FRONT_PAGE_KEY_BOOT_MAINTAIN
:
266 // Boot Maintenance Manager
280 Initialize HII information for the FrontPage
283 @param InitializeHiiData TRUE if HII elements need to be initialized.
285 @retval EFI_SUCCESS The operation is successful.
286 @retval EFI_DEVICE_ERROR If the dynamic opcode creation failed.
290 InitializeFrontPage (
291 IN BOOLEAN InitializeHiiData
300 CHAR16
*StringBuffer
;
301 EFI_HII_HANDLE HiiHandle
;
302 VOID
*OptionsOpCodeHandle
;
303 VOID
*StartOpCodeHandle
;
304 VOID
*EndOpCodeHandle
;
305 EFI_IFR_GUID_LABEL
*StartLabel
;
306 EFI_IFR_GUID_LABEL
*EndLabel
;
307 EFI_HII_STRING_PROTOCOL
*HiiString
;
313 if (InitializeHiiData
) {
315 // Initialize the Device Manager
317 InitializeDeviceManager ();
320 // Initialize the Device Manager
322 InitializeBootManager ();
327 // Locate Hii relative protocols
329 Status
= gBS
->LocateProtocol (&gEfiFormBrowser2ProtocolGuid
, NULL
, (VOID
**) &gFormBrowser2
);
330 if (EFI_ERROR (Status
)) {
335 // Install Device Path Protocol and Config Access protocol to driver handle
337 Status
= gBS
->InstallMultipleProtocolInterfaces (
338 &gFrontPagePrivate
.DriverHandle
,
339 &gEfiDevicePathProtocolGuid
,
340 &mFrontPageHiiVendorDevicePath
,
341 &gEfiHiiConfigAccessProtocolGuid
,
342 &gFrontPagePrivate
.ConfigAccess
,
345 ASSERT_EFI_ERROR (Status
);
348 // Publish our HII data
350 gFrontPagePrivate
.HiiHandle
= HiiAddPackages (
351 &gFrontPageFormSetGuid
,
352 gFrontPagePrivate
.DriverHandle
,
357 if (gFrontPagePrivate
.HiiHandle
== NULL
) {
358 return EFI_OUT_OF_RESOURCES
;
364 // Init OpCode Handle and Allocate space for creation of UpdateData Buffer
366 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
367 ASSERT (StartOpCodeHandle
!= NULL
);
369 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
370 ASSERT (EndOpCodeHandle
!= NULL
);
372 OptionsOpCodeHandle
= HiiAllocateOpCodeHandle ();
373 ASSERT (OptionsOpCodeHandle
!= NULL
);
375 // Create Hii Extend Label OpCode as the start opcode
377 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
378 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
379 StartLabel
->Number
= LABEL_SELECT_LANGUAGE
;
382 // Create Hii Extend Label OpCode as the end opcode
384 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
385 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
386 EndLabel
->Number
= LABEL_END
;
389 // Collect the languages from what our current Language support is based on our VFR
391 HiiHandle
= gFrontPagePrivate
.HiiHandle
;
393 GetEfiGlobalVariable2 (L
"PlatformLang", (VOID
**)&CurrentLang
, NULL
);
396 // Get Support language list from variable.
398 if (mLanguageString
== NULL
){
399 GetEfiGlobalVariable2 (L
"PlatformLangCodes", (VOID
**)&mLanguageString
, NULL
);
400 if (mLanguageString
== NULL
) {
401 mLanguageString
= AllocateCopyPool (
402 AsciiStrSize ((CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLangCodes
)),
403 (CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLangCodes
)
405 ASSERT (mLanguageString
!= NULL
);
409 if (gFrontPagePrivate
.LanguageToken
== NULL
) {
411 // Count the language list number.
413 LangCode
= mLanguageString
;
414 Lang
= AllocatePool (AsciiStrSize (mLanguageString
));
415 ASSERT (Lang
!= NULL
);
417 while (*LangCode
!= 0) {
418 GetNextLanguage (&LangCode
, Lang
);
423 // Allocate extra 1 as the end tag.
425 gFrontPagePrivate
.LanguageToken
= AllocateZeroPool ((OptionCount
+ 1) * sizeof (EFI_STRING_ID
));
426 ASSERT (gFrontPagePrivate
.LanguageToken
!= NULL
);
428 Status
= gBS
->LocateProtocol (&gEfiHiiStringProtocolGuid
, NULL
, (VOID
**) &HiiString
);
429 ASSERT_EFI_ERROR (Status
);
431 LangCode
= mLanguageString
;
433 while (*LangCode
!= 0) {
434 GetNextLanguage (&LangCode
, Lang
);
437 Status
= HiiString
->GetString (HiiString
, Lang
, HiiHandle
, PRINTABLE_LANGUAGE_NAME_STRING_ID
, StringBuffer
, &StringSize
, NULL
);
438 if (Status
== EFI_BUFFER_TOO_SMALL
) {
439 StringBuffer
= AllocateZeroPool (StringSize
);
440 ASSERT (StringBuffer
!= NULL
);
441 Status
= HiiString
->GetString (HiiString
, Lang
, HiiHandle
, PRINTABLE_LANGUAGE_NAME_STRING_ID
, StringBuffer
, &StringSize
, NULL
);
442 ASSERT_EFI_ERROR (Status
);
445 if (EFI_ERROR (Status
)) {
446 LangSize
= AsciiStrSize (Lang
);
447 StringBuffer
= AllocatePool (LangSize
* sizeof (CHAR16
));
448 ASSERT (StringBuffer
!= NULL
);
449 AsciiStrToUnicodeStrS (Lang
, StringBuffer
, LangSize
);
452 ASSERT (StringBuffer
!= NULL
);
453 gFrontPagePrivate
.LanguageToken
[OptionCount
] = HiiSetString (HiiHandle
, 0, StringBuffer
, NULL
);
454 FreePool (StringBuffer
);
460 ASSERT (gFrontPagePrivate
.LanguageToken
!= NULL
);
461 LangCode
= mLanguageString
;
464 Lang
= AllocatePool (AsciiStrSize (mLanguageString
));
465 ASSERT (Lang
!= NULL
);
467 while (*LangCode
!= 0) {
468 GetNextLanguage (&LangCode
, Lang
);
470 if (CurrentLang
!= NULL
&& AsciiStrCmp (Lang
, CurrentLang
) == 0) {
471 HiiCreateOneOfOptionOpCode (
473 gFrontPagePrivate
.LanguageToken
[OptionCount
],
474 EFI_IFR_OPTION_DEFAULT
,
475 EFI_IFR_NUMERIC_SIZE_1
,
479 HiiCreateOneOfOptionOpCode (
481 gFrontPagePrivate
.LanguageToken
[OptionCount
],
483 EFI_IFR_NUMERIC_SIZE_1
,
491 if (CurrentLang
!= NULL
) {
492 FreePool (CurrentLang
);
496 HiiCreateOneOfOpCode (
498 FRONT_PAGE_KEY_LANGUAGE
,
501 STRING_TOKEN (STR_LANGUAGE_SELECT
),
502 STRING_TOKEN (STR_LANGUAGE_SELECT_HELP
),
503 EFI_IFR_FLAG_CALLBACK
,
504 EFI_IFR_NUMERIC_SIZE_1
,
509 Status
= HiiUpdateForm (
511 &gFrontPageFormSetGuid
,
513 StartOpCodeHandle
, // LABEL_SELECT_LANGUAGE
514 EndOpCodeHandle
// LABEL_END
517 HiiFreeOpCodeHandle (StartOpCodeHandle
);
518 HiiFreeOpCodeHandle (EndOpCodeHandle
);
519 HiiFreeOpCodeHandle (OptionsOpCodeHandle
);
524 Call the browser and display the front page
526 @return Status code that will be returned by
527 EFI_FORM_BROWSER2_PROTOCOL.SendForm ().
536 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
539 // Begin waiting for USER INPUT
543 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_PC_INPUT_WAIT
)
546 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
547 Status
= gFormBrowser2
->SendForm (
549 &gFrontPagePrivate
.HiiHandle
,
551 &gFrontPageFormSetGuid
,
557 // Check whether user change any option setting which needs a reset to be effective
559 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
560 EnableResetRequired ();
568 Convert Processor Frequency Data to a string.
570 @param ProcessorFrequency The frequency data to process
571 @param Base10Exponent The exponent based on 10
572 @param String The string that is created
576 ConvertProcessorToString (
577 IN UINT16 ProcessorFrequency
,
578 IN UINT16 Base10Exponent
,
582 CHAR16
*StringBuffer
;
586 if (Base10Exponent
>= 6) {
587 FreqMhz
= ProcessorFrequency
;
588 for (Index
= 0; Index
< ((UINT32
)Base10Exponent
- 6); Index
++) {
595 StringBuffer
= AllocateZeroPool (0x20);
596 ASSERT (StringBuffer
!= NULL
);
597 UnicodeValueToStringS (StringBuffer
, 0x20, LEFT_JUSTIFY
, FreqMhz
/ 1000, 3);
598 Index
= StrnLenS (StringBuffer
, 0x20 / sizeof (CHAR16
));
599 StrCatS (StringBuffer
, 0x20 / sizeof (CHAR16
), L
".");
600 UnicodeValueToStringS (
601 StringBuffer
+ Index
+ 1,
602 0x20 - sizeof (CHAR16
) * (Index
+ 1),
604 (FreqMhz
% 1000) / 10,
607 StrCatS (StringBuffer
, 0x20 / sizeof (CHAR16
), L
" GHz");
608 *String
= (CHAR16
*) StringBuffer
;
614 Convert Memory Size to a string.
616 @param MemorySize The size of the memory to process
617 @param String The string that is created
621 ConvertMemorySizeToString (
622 IN UINT32 MemorySize
,
626 CHAR16
*StringBuffer
;
628 StringBuffer
= AllocateZeroPool (0x20);
629 ASSERT (StringBuffer
!= NULL
);
630 UnicodeValueToStringS (StringBuffer
, 0x20, LEFT_JUSTIFY
, MemorySize
, 6);
631 StrCatS (StringBuffer
, 0x20 / sizeof (CHAR16
), L
" MB RAM");
633 *String
= (CHAR16
*) StringBuffer
;
640 Acquire the string associated with the Index from smbios structure and return it.
641 The caller is responsible for free the string buffer.
643 @param OptionalStrStart The start position to search the string
644 @param Index The index of the string to extract
645 @param String The string that is extracted
647 @retval EFI_SUCCESS The function returns EFI_SUCCESS always.
651 GetOptionalStringByIndex (
652 IN CHAR8
*OptionalStrStart
,
660 *String
= AllocateZeroPool (sizeof (CHAR16
));
667 OptionalStrStart
+= StrSize
;
668 StrSize
= AsciiStrSize (OptionalStrStart
);
669 } while (OptionalStrStart
[StrSize
] != 0 && Index
!= 0);
671 if ((Index
!= 0) || (StrSize
== 1)) {
673 // Meet the end of strings set but Index is non-zero, or
674 // Find an empty string
676 *String
= GetStringById (STRING_TOKEN (STR_MISSING_STRING
));
678 *String
= AllocatePool (StrSize
* sizeof (CHAR16
));
679 AsciiStrToUnicodeStrS (OptionalStrStart
, *String
, StrSize
);
687 Update the banner information for the Front Page based on DataHub information.
691 UpdateFrontPageStrings (
698 EFI_STRING_ID TokenToUpdate
;
699 EFI_SMBIOS_HANDLE SmbiosHandle
;
700 EFI_SMBIOS_PROTOCOL
*Smbios
;
701 SMBIOS_TABLE_TYPE0
*Type0Record
;
702 SMBIOS_TABLE_TYPE1
*Type1Record
;
703 SMBIOS_TABLE_TYPE4
*Type4Record
;
704 SMBIOS_TABLE_TYPE19
*Type19Record
;
705 EFI_SMBIOS_TABLE_HEADER
*Record
;
706 UINT64 InstalledMemory
;
711 // Update Front Page strings
713 Status
= gBS
->LocateProtocol (
714 &gEfiSmbiosProtocolGuid
,
718 if (!EFI_ERROR (Status
)) {
719 SmbiosHandle
= SMBIOS_HANDLE_PI_RESERVED
;
720 Status
= Smbios
->GetNext (Smbios
, &SmbiosHandle
, NULL
, &Record
, NULL
);
721 while (!EFI_ERROR(Status
)) {
722 if (Record
->Type
== SMBIOS_TYPE_BIOS_INFORMATION
) {
723 Type0Record
= (SMBIOS_TABLE_TYPE0
*) Record
;
724 StrIndex
= Type0Record
->BiosVersion
;
725 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type0Record
+ Type0Record
->Hdr
.Length
), StrIndex
, &NewString
);
726 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION
);
727 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
728 FreePool (NewString
);
731 if (Record
->Type
== SMBIOS_TYPE_SYSTEM_INFORMATION
) {
732 Type1Record
= (SMBIOS_TABLE_TYPE1
*) Record
;
733 StrIndex
= Type1Record
->ProductName
;
734 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type1Record
+ Type1Record
->Hdr
.Length
), StrIndex
, &NewString
);
735 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_COMPUTER_MODEL
);
736 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
737 FreePool (NewString
);
740 if (Record
->Type
== SMBIOS_TYPE_PROCESSOR_INFORMATION
) {
741 Type4Record
= (SMBIOS_TABLE_TYPE4
*) Record
;
742 StrIndex
= Type4Record
->ProcessorVersion
;
743 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type4Record
+ Type4Record
->Hdr
.Length
), StrIndex
, &NewString
);
744 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_CPU_MODEL
);
745 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
746 FreePool (NewString
);
749 if (Record
->Type
== SMBIOS_TYPE_PROCESSOR_INFORMATION
) {
750 Type4Record
= (SMBIOS_TABLE_TYPE4
*) Record
;
751 ConvertProcessorToString(Type4Record
->CurrentSpeed
, 6, &NewString
);
752 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_CPU_SPEED
);
753 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
754 FreePool (NewString
);
757 if ( Record
->Type
== SMBIOS_TYPE_MEMORY_ARRAY_MAPPED_ADDRESS
) {
758 Type19Record
= (SMBIOS_TABLE_TYPE19
*) Record
;
759 if (Type19Record
->StartingAddress
!= 0xFFFFFFFF ) {
760 InstalledMemory
+= RShiftU64(Type19Record
->EndingAddress
-
761 Type19Record
->StartingAddress
+ 1, 10);
763 InstalledMemory
+= RShiftU64(Type19Record
->ExtendedEndingAddress
-
764 Type19Record
->ExtendedStartingAddress
+ 1, 20);
768 Status
= Smbios
->GetNext (Smbios
, &SmbiosHandle
, NULL
, &Record
, NULL
);
771 // now update the total installed RAM size
772 ConvertMemorySizeToString ((UINT32
)InstalledMemory
, &NewString
);
773 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_MEMORY_SIZE
);
774 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
775 FreePool (NewString
);
783 Function waits for a given event to fire, or for an optional timeout to expire.
785 @param Event The event to wait for
786 @param Timeout An optional timeout value in 100 ns units.
788 @retval EFI_SUCCESS Event fired before Timeout expired.
789 @retval EFI_TIME_OUT Timout expired before Event fired..
795 IN UINT64 Timeout OPTIONAL
800 EFI_EVENT TimerEvent
;
801 EFI_EVENT WaitList
[2];
805 // Create a timer event
807 Status
= gBS
->CreateEvent (EVT_TIMER
, 0, NULL
, NULL
, &TimerEvent
);
808 if (!EFI_ERROR (Status
)) {
810 // Set the timer event
819 // Wait for the original event or the timer
822 WaitList
[1] = TimerEvent
;
823 Status
= gBS
->WaitForEvent (2, WaitList
, &Index
);
824 gBS
->CloseEvent (TimerEvent
);
827 // If the timer expired, change the return to timed out
829 if (!EFI_ERROR (Status
) && Index
== 1) {
830 Status
= EFI_TIMEOUT
;
835 // No timeout... just wait on the event
837 Status
= gBS
->WaitForEvent (1, &Event
, &Index
);
838 ASSERT (!EFI_ERROR (Status
));
846 Function show progress bar to wait for user input.
849 @param TimeoutDefault The fault time out value before the system continue to boot.
851 @retval EFI_SUCCESS User pressed some key except "Enter"
852 @retval EFI_TIME_OUT Timeout expired or user press "Enter"
857 IN UINT16 TimeoutDefault
861 UINT16 TimeoutRemain
;
864 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
865 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
866 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
868 if (TimeoutDefault
!= 0) {
869 DEBUG ((EFI_D_INFO
, "\n\nStart showing progress bar... Press any key to stop it! ...Zzz....\n"));
871 SetMem (&Foreground
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
872 SetMem (&Background
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0x0);
873 SetMem (&Color
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
875 TmpStr
= GetStringById (STRING_TOKEN (STR_START_BOOT_OPTION
));
877 if (!FeaturePcdGet(PcdBootlogoOnlyEnable
)) {
879 // Clear the progress status bar first
881 if (TmpStr
!= NULL
) {
882 PlatformBdsShowProgress (Foreground
, Background
, TmpStr
, Color
, 0, 0);
887 TimeoutRemain
= TimeoutDefault
;
888 while (TimeoutRemain
!= 0) {
889 DEBUG ((EFI_D_INFO
, "Showing progress bar...Remaining %d second!\n", TimeoutRemain
));
891 Status
= WaitForSingleEvent (gST
->ConIn
->WaitForKey
, ONE_SECOND
);
892 if (Status
!= EFI_TIMEOUT
) {
897 if (!FeaturePcdGet(PcdBootlogoOnlyEnable
)) {
901 if (TmpStr
!= NULL
) {
902 PlatformBdsShowProgress (
907 ((TimeoutDefault
- TimeoutRemain
) * 100 / TimeoutDefault
),
914 if (TmpStr
!= NULL
) {
915 gBS
->FreePool (TmpStr
);
921 if (TimeoutRemain
== 0) {
927 // User pressed some key
929 if (!PcdGetBool (PcdConInConnectOnDemand
)) {
930 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
931 if (EFI_ERROR (Status
)) {
935 if (Key
.UnicodeChar
== CHAR_CARRIAGE_RETURN
) {
937 // User pressed enter, equivalent to select "continue"
947 This function is the main entry of the platform setup entry.
948 The function will present the main menu of the system setup,
949 this is the platform reference part and can be customize.
952 @param TimeoutDefault The fault time out value before the system
954 @param ConnectAllHappened The indicater to check if the connect all have
959 PlatformBdsEnterFrontPage (
960 IN UINT16 TimeoutDefault
,
961 IN BOOLEAN ConnectAllHappened
965 EFI_STATUS StatusHotkey
;
966 EFI_BOOT_LOGO_PROTOCOL
*BootLogo
;
967 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
968 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
969 UINTN BootTextColumn
;
975 GraphicsOutput
= NULL
;
976 SimpleTextOut
= NULL
;
978 PERF_START (NULL
, "BdsTimeOut", "BDS", 0);
980 // Indicate if we need connect all in the platform setup
982 if (ConnectAllHappened
) {
983 gConnectAllHappened
= TRUE
;
986 if (!mModeInitialized
) {
988 // After the console is ready, get current video resolution
989 // and text mode before launching setup at first time.
991 Status
= gBS
->HandleProtocol (
992 gST
->ConsoleOutHandle
,
993 &gEfiGraphicsOutputProtocolGuid
,
994 (VOID
**)&GraphicsOutput
996 if (EFI_ERROR (Status
)) {
997 GraphicsOutput
= NULL
;
1000 Status
= gBS
->HandleProtocol (
1001 gST
->ConsoleOutHandle
,
1002 &gEfiSimpleTextOutProtocolGuid
,
1003 (VOID
**)&SimpleTextOut
1005 if (EFI_ERROR (Status
)) {
1006 SimpleTextOut
= NULL
;
1009 if (GraphicsOutput
!= NULL
) {
1011 // Get current video resolution and text mode.
1013 mBootHorizontalResolution
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
1014 mBootVerticalResolution
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
1017 if (SimpleTextOut
!= NULL
) {
1018 Status
= SimpleTextOut
->QueryMode (
1020 SimpleTextOut
->Mode
->Mode
,
1024 mBootTextModeColumn
= (UINT32
)BootTextColumn
;
1025 mBootTextModeRow
= (UINT32
)BootTextRow
;
1029 // Get user defined text mode for setup.
1031 mSetupHorizontalResolution
= PcdGet32 (PcdSetupVideoHorizontalResolution
);
1032 mSetupVerticalResolution
= PcdGet32 (PcdSetupVideoVerticalResolution
);
1033 mSetupTextModeColumn
= PcdGet32 (PcdSetupConOutColumn
);
1034 mSetupTextModeRow
= PcdGet32 (PcdSetupConOutRow
);
1036 mModeInitialized
= TRUE
;
1041 // goto FrontPage directly when EFI_OS_INDICATIONS_BOOT_TO_FW_UI is set
1044 DataSize
= sizeof(UINT64
);
1045 Status
= gRT
->GetVariable (
1047 &gEfiGlobalVariableGuid
,
1054 // goto FrontPage directly when EFI_OS_INDICATIONS_BOOT_TO_FW_UI is set. Skip HotkeyBoot
1056 if (!EFI_ERROR(Status
) && ((OsIndication
& EFI_OS_INDICATIONS_BOOT_TO_FW_UI
) != 0)) {
1058 // Clear EFI_OS_INDICATIONS_BOOT_TO_FW_UI to acknowledge OS
1060 OsIndication
&= ~((UINT64
)EFI_OS_INDICATIONS_BOOT_TO_FW_UI
);
1061 Status
= gRT
->SetVariable (
1063 &gEfiGlobalVariableGuid
,
1064 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
1069 // Changing the content without increasing its size with current variable implementation shouldn't fail.
1071 ASSERT_EFI_ERROR (Status
);
1074 // Follow generic rule, Call ReadKeyStroke to connect ConIn before enter UI
1076 if (PcdGetBool (PcdConInConnectOnDemand
)) {
1077 gST
->ConIn
->ReadKeyStroke(gST
->ConIn
, &Key
);
1081 // Ensure screen is clear when switch Console from Graphics mode to Text mode
1083 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
1084 gST
->ConOut
->ClearScreen (gST
->ConOut
);
1089 if (TimeoutDefault
!= 0xffff) {
1090 Status
= ShowProgress (TimeoutDefault
);
1091 StatusHotkey
= HotkeyBoot ();
1093 if (!FeaturePcdGet(PcdBootlogoOnlyEnable
) || !EFI_ERROR(Status
) || !EFI_ERROR(StatusHotkey
)){
1095 // Ensure screen is clear when switch Console from Graphics mode to Text mode
1096 // Skip it in normal boot
1098 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
1099 gST
->ConOut
->ClearScreen (gST
->ConOut
);
1102 if (EFI_ERROR (Status
)) {
1104 // Timeout or user press enter to continue
1112 // Boot Logo is corrupted, report it using Boot Logo protocol.
1114 Status
= gBS
->LocateProtocol (&gEfiBootLogoProtocolGuid
, NULL
, (VOID
**) &BootLogo
);
1115 if (!EFI_ERROR (Status
) && (BootLogo
!= NULL
)) {
1116 BootLogo
->SetBootLogo (BootLogo
, NULL
, 0, 0, 0, 0);
1120 // Install BM HiiPackages.
1121 // Keep BootMaint HiiPackage, so that it can be covered by global setting.
1125 Status
= EFI_SUCCESS
;
1128 // Set proper video resolution and text mode for setup
1130 BdsSetConsoleMode (TRUE
);
1132 InitializeFrontPage (FALSE
);
1135 // Update Front Page strings
1137 UpdateFrontPageStrings ();
1143 // If gCallbackKey is greater than 1 and less or equal to 5,
1144 // it will launch configuration utilities.
1147 // 4 = device manager
1148 // 5 = boot maintenance manager
1150 if (gCallbackKey
!= 0) {
1151 REPORT_STATUS_CODE (
1153 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_PC_USER_SETUP
)
1157 // Based on the key that was set, we can determine what to do
1159 switch (gCallbackKey
) {
1161 // The first 4 entries in the Front Page are to be GUARANTEED to remain constant so IHV's can
1162 // describe to their customers in documentation how to find their setup information (namely
1163 // under the device manager and specific buckets)
1165 // These entries consist of the Continue, Select language, Boot Manager, and Device Manager
1167 case FRONT_PAGE_KEY_CONTINUE
:
1169 // User hit continue
1173 case FRONT_PAGE_KEY_LANGUAGE
:
1175 // User made a language setting change - display front page again
1179 case FRONT_PAGE_KEY_BOOT_MANAGER
:
1181 // Remove the installed BootMaint HiiPackages when exit.
1186 // User chose to run the Boot Manager
1191 // Reinstall BootMaint HiiPackages after exiting from Boot Manager.
1196 case FRONT_PAGE_KEY_DEVICE_MANAGER
:
1198 // Display the Device Manager
1201 CallDeviceManager ();
1202 } while (gCallbackKey
== FRONT_PAGE_KEY_DEVICE_MANAGER
);
1205 case FRONT_PAGE_KEY_BOOT_MAINTAIN
:
1207 // Display the Boot Maintenance Manager
1209 BdsStartBootMaint ();
1213 } while ((Status
== EFI_SUCCESS
) && (gCallbackKey
!= FRONT_PAGE_KEY_CONTINUE
));
1215 if (mLanguageString
!= NULL
) {
1216 FreePool (mLanguageString
);
1217 mLanguageString
= NULL
;
1220 //Will leave browser, check any reset required change is applied? if yes, reset system
1222 SetupResetReminder ();
1225 // Remove the installed BootMaint HiiPackages when exit.
1231 // Automatically load current entry
1232 // Note: The following lines of code only execute when Auto boot
1235 PERF_END (NULL
, "BdsTimeOut", "BDS", 0);
1239 This function will change video resolution and text mode
1240 according to defined setup mode or defined boot mode
1242 @param IsSetupMode Indicate mode is changed to setup mode or boot mode.
1244 @retval EFI_SUCCESS Mode is changed successfully.
1245 @retval Others Mode failed to be changed.
1254 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1255 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
1257 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
1261 UINT32 NewHorizontalResolution
;
1262 UINT32 NewVerticalResolution
;
1266 EFI_HANDLE
*HandleBuffer
;
1269 UINTN CurrentColumn
;
1276 // Get current video resolution and text mode
1278 Status
= gBS
->HandleProtocol (
1279 gST
->ConsoleOutHandle
,
1280 &gEfiGraphicsOutputProtocolGuid
,
1281 (VOID
**)&GraphicsOutput
1283 if (EFI_ERROR (Status
)) {
1284 GraphicsOutput
= NULL
;
1287 Status
= gBS
->HandleProtocol (
1288 gST
->ConsoleOutHandle
,
1289 &gEfiSimpleTextOutProtocolGuid
,
1290 (VOID
**)&SimpleTextOut
1292 if (EFI_ERROR (Status
)) {
1293 SimpleTextOut
= NULL
;
1296 if ((GraphicsOutput
== NULL
) || (SimpleTextOut
== NULL
)) {
1297 return EFI_UNSUPPORTED
;
1302 // The required resolution and text mode is setup mode.
1304 NewHorizontalResolution
= mSetupHorizontalResolution
;
1305 NewVerticalResolution
= mSetupVerticalResolution
;
1306 NewColumns
= mSetupTextModeColumn
;
1307 NewRows
= mSetupTextModeRow
;
1310 // The required resolution and text mode is boot mode.
1312 NewHorizontalResolution
= mBootHorizontalResolution
;
1313 NewVerticalResolution
= mBootVerticalResolution
;
1314 NewColumns
= mBootTextModeColumn
;
1315 NewRows
= mBootTextModeRow
;
1318 if (GraphicsOutput
!= NULL
) {
1319 MaxGopMode
= GraphicsOutput
->Mode
->MaxMode
;
1322 if (SimpleTextOut
!= NULL
) {
1323 MaxTextMode
= SimpleTextOut
->Mode
->MaxMode
;
1327 // 1. If current video resolution is same with required video resolution,
1328 // video resolution need not be changed.
1329 // 1.1. If current text mode is same with required text mode, text mode need not be changed.
1330 // 1.2. If current text mode is different from required text mode, text mode need be changed.
1331 // 2. If current video resolution is different from required video resolution, we need restart whole console drivers.
1333 for (ModeNumber
= 0; ModeNumber
< MaxGopMode
; ModeNumber
++) {
1334 Status
= GraphicsOutput
->QueryMode (
1340 if (!EFI_ERROR (Status
)) {
1341 if ((Info
->HorizontalResolution
== NewHorizontalResolution
) &&
1342 (Info
->VerticalResolution
== NewVerticalResolution
)) {
1343 if ((GraphicsOutput
->Mode
->Info
->HorizontalResolution
== NewHorizontalResolution
) &&
1344 (GraphicsOutput
->Mode
->Info
->VerticalResolution
== NewVerticalResolution
)) {
1346 // Current resolution is same with required resolution, check if text mode need be set
1348 Status
= SimpleTextOut
->QueryMode (SimpleTextOut
, SimpleTextOut
->Mode
->Mode
, &CurrentColumn
, &CurrentRow
);
1349 ASSERT_EFI_ERROR (Status
);
1350 if (CurrentColumn
== NewColumns
&& CurrentRow
== NewRows
) {
1352 // If current text mode is same with required text mode. Do nothing
1358 // If current text mode is different from required text mode. Set new video mode
1360 for (Index
= 0; Index
< MaxTextMode
; Index
++) {
1361 Status
= SimpleTextOut
->QueryMode (SimpleTextOut
, Index
, &CurrentColumn
, &CurrentRow
);
1362 if (!EFI_ERROR(Status
)) {
1363 if ((CurrentColumn
== NewColumns
) && (CurrentRow
== NewRows
)) {
1365 // Required text mode is supported, set it.
1367 Status
= SimpleTextOut
->SetMode (SimpleTextOut
, Index
);
1368 ASSERT_EFI_ERROR (Status
);
1370 // Update text mode PCD.
1372 Status
= PcdSet32S (PcdConOutColumn
, mSetupTextModeColumn
);
1373 ASSERT_EFI_ERROR (Status
);
1374 Status
= PcdSet32S (PcdConOutRow
, mSetupTextModeRow
);
1375 ASSERT_EFI_ERROR (Status
);
1381 if (Index
== MaxTextMode
) {
1383 // If required text mode is not supported, return error.
1386 return EFI_UNSUPPORTED
;
1391 // If current video resolution is not same with the new one, set new video resolution.
1392 // In this case, the driver which produces simple text out need be restarted.
1394 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, ModeNumber
);
1395 if (!EFI_ERROR (Status
)) {
1405 if (ModeNumber
== MaxGopMode
) {
1407 // If the resolution is not supported, return error.
1409 return EFI_UNSUPPORTED
;
1413 // Set PCD to Inform GraphicsConsole to change video resolution.
1414 // Set PCD to Inform Consplitter to change text mode.
1416 Status
= PcdSet32S (PcdVideoHorizontalResolution
, NewHorizontalResolution
);
1417 ASSERT_EFI_ERROR (Status
);
1418 Status
= PcdSet32S (PcdVideoVerticalResolution
, NewVerticalResolution
);
1419 ASSERT_EFI_ERROR (Status
);
1420 Status
= PcdSet32S (PcdConOutColumn
, NewColumns
);
1421 ASSERT_EFI_ERROR (Status
);
1422 Status
= PcdSet32S (PcdConOutRow
, NewRows
);
1423 ASSERT_EFI_ERROR (Status
);
1427 // Video mode is changed, so restart graphics console driver and higher level driver.
1428 // Reconnect graphics console driver and higher level driver.
1429 // Locate all the handles with GOP protocol and reconnect it.
1431 Status
= gBS
->LocateHandleBuffer (
1433 &gEfiSimpleTextOutProtocolGuid
,
1438 if (!EFI_ERROR (Status
)) {
1439 for (Index
= 0; Index
< HandleCount
; Index
++) {
1440 gBS
->DisconnectController (HandleBuffer
[Index
], NULL
, NULL
);
1442 for (Index
= 0; Index
< HandleCount
; Index
++) {
1443 gBS
->ConnectController (HandleBuffer
[Index
], NULL
, NULL
, TRUE
);
1445 if (HandleBuffer
!= NULL
) {
1446 FreePool (HandleBuffer
);