2 FrontPage routines to handle the callbacks and browser calls
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
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.
16 #include "FrontPage.h"
20 BOOLEAN mModeInitialized
= FALSE
;
22 BOOLEAN gConnectAllHappened
= FALSE
;
26 // Boot video resolution and text mode.
28 UINT32 mBootHorizontalResolution
= 0;
29 UINT32 mBootVerticalResolution
= 0;
30 UINT32 mBootTextModeColumn
= 0;
31 UINT32 mBootTextModeRow
= 0;
33 // BIOS setup video resolution and text mode.
35 UINT32 mSetupTextModeColumn
= 0;
36 UINT32 mSetupTextModeRow
= 0;
37 UINT32 mSetupHorizontalResolution
= 0;
38 UINT32 mSetupVerticalResolution
= 0;
40 EFI_FORM_BROWSER2_PROTOCOL
*gFormBrowser2
;
42 FRONT_PAGE_CALLBACK_DATA gFrontPagePrivate
= {
43 FRONT_PAGE_CALLBACK_DATA_SIGNATURE
,
54 HII_VENDOR_DEVICE_PATH mFrontPageHiiVendorDevicePath
= {
60 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
61 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
64 FRONT_PAGE_FORMSET_GUID
68 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
70 (UINT8
) (END_DEVICE_PATH_LENGTH
),
71 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
77 This function allows a caller to extract the current configuration for one
78 or more named elements from the target driver.
81 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
82 @param Request A null-terminated Unicode string in <ConfigRequest> format.
83 @param Progress On return, points to a character in the Request string.
84 Points to the string's null terminator if request was successful.
85 Points to the most recent '&' before the first failing name/value
86 pair (or the beginning of the string if the failure is in the
87 first name/value pair) if the request was not successful.
88 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
89 has all values filled in for the names in the Request string.
90 String to be allocated by the called function.
92 @retval EFI_SUCCESS The Results is filled with the requested values.
93 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
94 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
95 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
101 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
102 IN CONST EFI_STRING Request
,
103 OUT EFI_STRING
*Progress
,
104 OUT EFI_STRING
*Results
107 if (Progress
== NULL
|| Results
== NULL
) {
108 return EFI_INVALID_PARAMETER
;
111 return EFI_NOT_FOUND
;
115 This function processes the results of changes in configuration.
118 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
119 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
120 @param Progress A pointer to a string filled in with the offset of the most
121 recent '&' before the first failing name/value pair (or the
122 beginning of the string if the failure is in the first
123 name/value pair) or the terminating NULL if all was successful.
125 @retval EFI_SUCCESS The Results is processed successfully.
126 @retval EFI_INVALID_PARAMETER Configuration is NULL.
127 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
133 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
134 IN CONST EFI_STRING Configuration
,
135 OUT EFI_STRING
*Progress
138 if (Configuration
== NULL
|| Progress
== NULL
) {
139 return EFI_INVALID_PARAMETER
;
142 *Progress
= Configuration
;
143 if (!HiiIsConfigHdrMatch (Configuration
, &gBootMaintFormSetGuid
, mBootMaintStorageName
)
144 && !HiiIsConfigHdrMatch (Configuration
, &gFileExploreFormSetGuid
, mFileExplorerStorageName
)) {
145 return EFI_NOT_FOUND
;
148 *Progress
= Configuration
+ StrLen (Configuration
);
153 This function processes the results of changes in configuration.
156 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
157 @param Action Specifies the type of action taken by the browser.
158 @param QuestionId A unique value which is sent to the original exporting driver
159 so that it can identify the type of data to expect.
160 @param Type The type of value for the question.
161 @param Value A pointer to the data being sent to the original exporting driver.
162 @param ActionRequest On return, points to the action requested by the callback function.
164 @retval EFI_SUCCESS The callback successfully handled the action.
165 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
166 @retval EFI_DEVICE_ERROR The variable could not be saved.
167 @retval EFI_UNSUPPORTED The specified Action is not supported by the callback.
173 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
174 IN EFI_BROWSER_ACTION Action
,
175 IN EFI_QUESTION_ID QuestionId
,
177 IN EFI_IFR_TYPE_VALUE
*Value
,
178 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
181 CHAR8
*LanguageString
;
186 CHAR8
*PlatformSupportedLanguages
;
189 if (Action
!= EFI_BROWSER_ACTION_CHANGING
&& Action
!= EFI_BROWSER_ACTION_CHANGED
) {
191 // All other action return unsupported.
193 return EFI_UNSUPPORTED
;
196 gCallbackKey
= QuestionId
;
198 if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
199 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
200 return EFI_INVALID_PARAMETER
;
203 switch (QuestionId
) {
204 case FRONT_PAGE_KEY_CONTINUE
:
206 // This is the continue - clear the screen and return an error to get out of FrontPage loop
208 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
211 case FRONT_PAGE_KEY_LANGUAGE
:
213 // Collect the languages from what our current Language support is based on our VFR
215 LanguageString
= HiiGetSupportedLanguages (gFrontPagePrivate
.HiiHandle
);
216 ASSERT (LanguageString
!= NULL
);
218 // Allocate working buffer for RFC 4646 language in supported LanguageString.
220 Lang
= AllocatePool (AsciiStrSize (LanguageString
));
221 ASSERT (Lang
!= NULL
);
224 LangCode
= LanguageString
;
225 while (*LangCode
!= 0) {
226 GetNextLanguage (&LangCode
, Lang
);
228 if (Index
== Value
->u8
) {
235 GetEfiGlobalVariable2 (L
"PlatformLangCodes", (VOID
**)&PlatformSupportedLanguages
, NULL
);
236 if (PlatformSupportedLanguages
== NULL
) {
237 PlatformSupportedLanguages
= AllocateCopyPool (
238 AsciiStrSize ((CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLangCodes
)),
239 (CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLangCodes
)
241 ASSERT (PlatformSupportedLanguages
!= NULL
);
245 // Select the best language in platform supported Language.
247 BestLanguage
= GetBestLanguage (
248 PlatformSupportedLanguages
,
253 if (BestLanguage
!= NULL
) {
254 Status
= gRT
->SetVariable (
256 &gEfiGlobalVariableGuid
,
257 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
258 AsciiStrSize (BestLanguage
),
261 ASSERT_EFI_ERROR(Status
);
262 FreePool (BestLanguage
);
267 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
269 FreePool (PlatformSupportedLanguages
);
271 FreePool (LanguageString
);
277 } else if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
279 return EFI_INVALID_PARAMETER
;
283 // The first 4 entries in the Front Page are to be GUARANTEED to remain constant so IHV's can
284 // describe to their customers in documentation how to find their setup information (namely
285 // under the device manager and specific buckets)
287 switch (QuestionId
) {
288 case FRONT_PAGE_KEY_BOOT_MANAGER
:
294 case FRONT_PAGE_KEY_DEVICE_MANAGER
:
300 case FRONT_PAGE_KEY_BOOT_MAINTAIN
:
302 // Boot Maintenance Manager
316 Initialize HII information for the FrontPage
319 @param InitializeHiiData TRUE if HII elements need to be initialized.
321 @retval EFI_SUCCESS The operation is successful.
322 @retval EFI_DEVICE_ERROR If the dynamic opcode creation failed.
326 InitializeFrontPage (
327 IN BOOLEAN InitializeHiiData
331 CHAR8
*LanguageString
;
337 CHAR16
*StringBuffer
;
338 EFI_HII_HANDLE HiiHandle
;
339 VOID
*OptionsOpCodeHandle
;
340 VOID
*StartOpCodeHandle
;
341 VOID
*EndOpCodeHandle
;
342 EFI_IFR_GUID_LABEL
*StartLabel
;
343 EFI_IFR_GUID_LABEL
*EndLabel
;
346 if (InitializeHiiData
) {
348 // Initialize the Device Manager
350 InitializeDeviceManager ();
353 // Initialize the Device Manager
355 InitializeBootManager ();
360 // Locate Hii relative protocols
362 Status
= gBS
->LocateProtocol (&gEfiFormBrowser2ProtocolGuid
, NULL
, (VOID
**) &gFormBrowser2
);
363 if (EFI_ERROR (Status
)) {
368 // Install Device Path Protocol and Config Access protocol to driver handle
370 Status
= gBS
->InstallMultipleProtocolInterfaces (
371 &gFrontPagePrivate
.DriverHandle
,
372 &gEfiDevicePathProtocolGuid
,
373 &mFrontPageHiiVendorDevicePath
,
374 &gEfiHiiConfigAccessProtocolGuid
,
375 &gFrontPagePrivate
.ConfigAccess
,
378 ASSERT_EFI_ERROR (Status
);
381 // Publish our HII data
383 gFrontPagePrivate
.HiiHandle
= HiiAddPackages (
384 &gFrontPageFormSetGuid
,
385 gFrontPagePrivate
.DriverHandle
,
390 if (gFrontPagePrivate
.HiiHandle
== NULL
) {
391 return EFI_OUT_OF_RESOURCES
;
397 // Init OpCode Handle and Allocate space for creation of UpdateData Buffer
399 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
400 ASSERT (StartOpCodeHandle
!= NULL
);
402 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
403 ASSERT (EndOpCodeHandle
!= NULL
);
405 OptionsOpCodeHandle
= HiiAllocateOpCodeHandle ();
406 ASSERT (OptionsOpCodeHandle
!= NULL
);
408 // Create Hii Extend Label OpCode as the start opcode
410 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
411 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
412 StartLabel
->Number
= LABEL_SELECT_LANGUAGE
;
415 // Create Hii Extend Label OpCode as the end opcode
417 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
418 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
419 EndLabel
->Number
= LABEL_END
;
422 // Collect the languages from what our current Language support is based on our VFR
424 HiiHandle
= gFrontPagePrivate
.HiiHandle
;
425 LanguageString
= HiiGetSupportedLanguages (HiiHandle
);
426 ASSERT (LanguageString
!= NULL
);
428 // Allocate working buffer for RFC 4646 language in supported LanguageString.
430 Lang
= AllocatePool (AsciiStrSize (LanguageString
));
431 ASSERT (Lang
!= NULL
);
433 GetEfiGlobalVariable2 (L
"PlatformLang", (VOID
**)&CurrentLang
, NULL
);
435 // Select the best language in LanguageString as the default one.
437 BestLanguage
= GetBestLanguage (
440 (CurrentLang
!= NULL
) ? CurrentLang
: "",
441 (CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLang
),
446 // BestLanguage must be selected as it is the first language in LanguageString by default
448 ASSERT (BestLanguage
!= NULL
);
451 LangCode
= LanguageString
;
454 if (gFrontPagePrivate
.LanguageToken
== NULL
) {
455 while (*LangCode
!= 0) {
456 GetNextLanguage (&LangCode
, Lang
);
459 gFrontPagePrivate
.LanguageToken
= AllocatePool (OptionCount
* sizeof (EFI_STRING_ID
));
460 ASSERT (gFrontPagePrivate
.LanguageToken
!= NULL
);
465 LangCode
= LanguageString
;
466 while (*LangCode
!= 0) {
467 GetNextLanguage (&LangCode
, Lang
);
470 StringBuffer
= HiiGetString (HiiHandle
, PRINTABLE_LANGUAGE_NAME_STRING_ID
, Lang
);
471 ASSERT (StringBuffer
!= NULL
);
474 // Save the string Id for each language
476 gFrontPagePrivate
.LanguageToken
[OptionCount
] = HiiSetString (HiiHandle
, 0, StringBuffer
, NULL
);
477 FreePool (StringBuffer
);
480 if (AsciiStrCmp (Lang
, BestLanguage
) == 0) {
481 HiiCreateOneOfOptionOpCode (
483 gFrontPagePrivate
.LanguageToken
[OptionCount
],
484 EFI_IFR_OPTION_DEFAULT
,
485 EFI_IFR_NUMERIC_SIZE_1
,
489 HiiCreateOneOfOptionOpCode (
491 gFrontPagePrivate
.LanguageToken
[OptionCount
],
493 EFI_IFR_NUMERIC_SIZE_1
,
501 if (CurrentLang
!= NULL
) {
502 FreePool (CurrentLang
);
504 FreePool (BestLanguage
);
506 FreePool (LanguageString
);
508 HiiCreateOneOfOpCode (
510 FRONT_PAGE_KEY_LANGUAGE
,
513 STRING_TOKEN (STR_LANGUAGE_SELECT
),
514 STRING_TOKEN (STR_LANGUAGE_SELECT_HELP
),
515 EFI_IFR_FLAG_CALLBACK
,
516 EFI_IFR_NUMERIC_SIZE_1
,
521 Status
= HiiUpdateForm (
523 &gFrontPageFormSetGuid
,
525 StartOpCodeHandle
, // LABEL_SELECT_LANGUAGE
526 EndOpCodeHandle
// LABEL_END
529 HiiFreeOpCodeHandle (StartOpCodeHandle
);
530 HiiFreeOpCodeHandle (EndOpCodeHandle
);
531 HiiFreeOpCodeHandle (OptionsOpCodeHandle
);
536 Call the browser and display the front page
538 @return Status code that will be returned by
539 EFI_FORM_BROWSER2_PROTOCOL.SendForm ().
548 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
551 // Begin waiting for USER INPUT
555 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_PC_INPUT_WAIT
)
558 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
559 Status
= gFormBrowser2
->SendForm (
561 &gFrontPagePrivate
.HiiHandle
,
563 &gFrontPageFormSetGuid
,
569 // Check whether user change any option setting which needs a reset to be effective
571 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
572 EnableResetRequired ();
579 Acquire the string associated with the ProducerGuid and return it.
582 @param ProducerGuid The Guid to search the HII database for
583 @param Token The token value of the string to extract
584 @param String The string that is extracted
586 @retval EFI_SUCCESS The function returns EFI_SUCCESS always.
591 IN EFI_GUID
*ProducerGuid
,
592 IN EFI_STRING_ID Token
,
596 EFI_STRING TmpString
;
598 TmpString
= HiiGetPackageString (ProducerGuid
, Token
, NULL
);
599 if (TmpString
== NULL
) {
600 *String
= GetStringById (STRING_TOKEN (STR_MISSING_STRING
));
609 Convert Processor Frequency Data to a string.
611 @param ProcessorFrequency The frequency data to process
612 @param Base10Exponent The exponent based on 10
613 @param String The string that is created
617 ConvertProcessorToString (
618 IN UINT16 ProcessorFrequency
,
619 IN UINT16 Base10Exponent
,
623 CHAR16
*StringBuffer
;
627 if (Base10Exponent
>= 6) {
628 FreqMhz
= ProcessorFrequency
;
629 for (Index
= 0; Index
< (UINTN
) (Base10Exponent
- 6); Index
++) {
636 StringBuffer
= AllocateZeroPool (0x20);
637 ASSERT (StringBuffer
!= NULL
);
638 Index
= UnicodeValueToString (StringBuffer
, LEFT_JUSTIFY
, FreqMhz
/ 1000, 3);
639 StrCat (StringBuffer
, L
".");
640 UnicodeValueToString (StringBuffer
+ Index
+ 1, PREFIX_ZERO
, (FreqMhz
% 1000) / 10, 2);
641 StrCat (StringBuffer
, L
" GHz");
642 *String
= (CHAR16
*) StringBuffer
;
648 Convert Memory Size to a string.
650 @param MemorySize The size of the memory to process
651 @param String The string that is created
655 ConvertMemorySizeToString (
656 IN UINT32 MemorySize
,
660 CHAR16
*StringBuffer
;
662 StringBuffer
= AllocateZeroPool (0x20);
663 ASSERT (StringBuffer
!= NULL
);
664 UnicodeValueToString (StringBuffer
, LEFT_JUSTIFY
, MemorySize
, 6);
665 StrCat (StringBuffer
, L
" MB RAM");
667 *String
= (CHAR16
*) StringBuffer
;
674 Acquire the string associated with the Index from smbios structure and return it.
675 The caller is responsible for free the string buffer.
677 @param OptionalStrStart The start position to search the string
678 @param Index The index of the string to extract
679 @param String The string that is extracted
681 @retval EFI_SUCCESS The function returns EFI_SUCCESS always.
685 GetOptionalStringByIndex (
686 IN CHAR8
*OptionalStrStart
,
694 *String
= AllocateZeroPool (sizeof (CHAR16
));
701 OptionalStrStart
+= StrSize
;
702 StrSize
= AsciiStrSize (OptionalStrStart
);
703 } while (OptionalStrStart
[StrSize
] != 0 && Index
!= 0);
705 if ((Index
!= 0) || (StrSize
== 1)) {
707 // Meet the end of strings set but Index is non-zero, or
708 // Find an empty string
710 *String
= GetStringById (STRING_TOKEN (STR_MISSING_STRING
));
712 *String
= AllocatePool (StrSize
* sizeof (CHAR16
));
713 AsciiStrToUnicodeStr (OptionalStrStart
, *String
);
721 Update the banner information for the Front Page based on DataHub information.
725 UpdateFrontPageStrings (
733 EFI_STRING_ID TokenToUpdate
;
734 EFI_SMBIOS_HANDLE SmbiosHandle
;
735 EFI_SMBIOS_PROTOCOL
*Smbios
;
736 SMBIOS_TABLE_TYPE0
*Type0Record
;
737 SMBIOS_TABLE_TYPE1
*Type1Record
;
738 SMBIOS_TABLE_TYPE4
*Type4Record
;
739 SMBIOS_TABLE_TYPE19
*Type19Record
;
740 EFI_SMBIOS_TABLE_HEADER
*Record
;
742 ZeroMem (Find
, sizeof (Find
));
745 // Update Front Page strings
747 Status
= gBS
->LocateProtocol (
748 &gEfiSmbiosProtocolGuid
,
752 ASSERT_EFI_ERROR (Status
);
754 SmbiosHandle
= SMBIOS_HANDLE_PI_RESERVED
;
756 Status
= Smbios
->GetNext (Smbios
, &SmbiosHandle
, NULL
, &Record
, NULL
);
757 if (EFI_ERROR(Status
)) {
761 if (Record
->Type
== EFI_SMBIOS_TYPE_BIOS_INFORMATION
) {
762 Type0Record
= (SMBIOS_TABLE_TYPE0
*) Record
;
763 StrIndex
= Type0Record
->BiosVersion
;
764 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type0Record
+ Type0Record
->Hdr
.Length
), StrIndex
, &NewString
);
765 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION
);
766 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
767 FreePool (NewString
);
771 if (Record
->Type
== EFI_SMBIOS_TYPE_SYSTEM_INFORMATION
) {
772 Type1Record
= (SMBIOS_TABLE_TYPE1
*) Record
;
773 StrIndex
= Type1Record
->ProductName
;
774 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type1Record
+ Type1Record
->Hdr
.Length
), StrIndex
, &NewString
);
775 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_COMPUTER_MODEL
);
776 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
777 FreePool (NewString
);
781 if (Record
->Type
== EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION
) {
782 Type4Record
= (SMBIOS_TABLE_TYPE4
*) Record
;
783 StrIndex
= Type4Record
->ProcessorVersion
;
784 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type4Record
+ Type4Record
->Hdr
.Length
), StrIndex
, &NewString
);
785 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_CPU_MODEL
);
786 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
787 FreePool (NewString
);
791 if (Record
->Type
== EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION
) {
792 Type4Record
= (SMBIOS_TABLE_TYPE4
*) Record
;
793 ConvertProcessorToString(Type4Record
->CurrentSpeed
, 6, &NewString
);
794 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_CPU_SPEED
);
795 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
796 FreePool (NewString
);
800 if ( Record
->Type
== EFI_SMBIOS_TYPE_MEMORY_ARRAY_MAPPED_ADDRESS
) {
801 Type19Record
= (SMBIOS_TABLE_TYPE19
*) Record
;
802 ConvertMemorySizeToString (
803 (UINT32
)(RShiftU64((Type19Record
->EndingAddress
- Type19Record
->StartingAddress
+ 1), 10)),
806 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_MEMORY_SIZE
);
807 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
808 FreePool (NewString
);
811 } while ( !(Find
[0] && Find
[1] && Find
[2] && Find
[3] && Find
[4]));
817 Function waits for a given event to fire, or for an optional timeout to expire.
819 @param Event The event to wait for
820 @param Timeout An optional timeout value in 100 ns units.
822 @retval EFI_SUCCESS Event fired before Timeout expired.
823 @retval EFI_TIME_OUT Timout expired before Event fired..
829 IN UINT64 Timeout OPTIONAL
834 EFI_EVENT TimerEvent
;
835 EFI_EVENT WaitList
[2];
839 // Create a timer event
841 Status
= gBS
->CreateEvent (EVT_TIMER
, 0, NULL
, NULL
, &TimerEvent
);
842 if (!EFI_ERROR (Status
)) {
844 // Set the timer event
853 // Wait for the original event or the timer
856 WaitList
[1] = TimerEvent
;
857 Status
= gBS
->WaitForEvent (2, WaitList
, &Index
);
858 gBS
->CloseEvent (TimerEvent
);
861 // If the timer expired, change the return to timed out
863 if (!EFI_ERROR (Status
) && Index
== 1) {
864 Status
= EFI_TIMEOUT
;
869 // No timeout... just wait on the event
871 Status
= gBS
->WaitForEvent (1, &Event
, &Index
);
872 ASSERT (!EFI_ERROR (Status
));
880 Function show progress bar to wait for user input.
883 @param TimeoutDefault The fault time out value before the system continue to boot.
885 @retval EFI_SUCCESS User pressed some key except "Enter"
886 @retval EFI_TIME_OUT Timeout expired or user press "Enter"
891 IN UINT16 TimeoutDefault
895 UINT16 TimeoutRemain
;
898 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
899 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
900 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
902 if (TimeoutDefault
== 0) {
906 DEBUG ((EFI_D_INFO
, "\n\nStart showing progress bar... Press any key to stop it! ...Zzz....\n"));
908 SetMem (&Foreground
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
909 SetMem (&Background
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0x0);
910 SetMem (&Color
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
912 TmpStr
= GetStringById (STRING_TOKEN (STR_START_BOOT_OPTION
));
914 if (!FeaturePcdGet(PcdBootlogoOnlyEnable
)) {
916 // Clear the progress status bar first
918 if (TmpStr
!= NULL
) {
919 PlatformBdsShowProgress (Foreground
, Background
, TmpStr
, Color
, 0, 0);
924 TimeoutRemain
= TimeoutDefault
;
925 while (TimeoutRemain
!= 0) {
926 DEBUG ((EFI_D_INFO
, "Showing progress bar...Remaining %d second!\n", TimeoutRemain
));
928 Status
= WaitForSingleEvent (gST
->ConIn
->WaitForKey
, ONE_SECOND
);
929 if (Status
!= EFI_TIMEOUT
) {
934 if (!FeaturePcdGet(PcdBootlogoOnlyEnable
)) {
938 if (TmpStr
!= NULL
) {
939 PlatformBdsShowProgress (
944 ((TimeoutDefault
- TimeoutRemain
) * 100 / TimeoutDefault
),
951 if (TmpStr
!= NULL
) {
952 gBS
->FreePool (TmpStr
);
958 if (TimeoutRemain
== 0) {
963 // User pressed some key
965 if (!PcdGetBool (PcdConInConnectOnDemand
)) {
966 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
967 if (EFI_ERROR (Status
)) {
971 if (Key
.UnicodeChar
== CHAR_CARRIAGE_RETURN
) {
973 // User pressed enter, equivalent to select "continue"
983 This function is the main entry of the platform setup entry.
984 The function will present the main menu of the system setup,
985 this is the platform reference part and can be customize.
988 @param TimeoutDefault The fault time out value before the system
990 @param ConnectAllHappened The indicater to check if the connect all have
995 PlatformBdsEnterFrontPage (
996 IN UINT16 TimeoutDefault
,
997 IN BOOLEAN ConnectAllHappened
1001 EFI_STATUS StatusHotkey
;
1002 EFI_BOOT_LOGO_PROTOCOL
*BootLogo
;
1003 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1004 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
1005 UINTN BootTextColumn
;
1007 UINT64 OsIndication
;
1011 GraphicsOutput
= NULL
;
1012 SimpleTextOut
= NULL
;
1014 PERF_START (NULL
, "BdsTimeOut", "BDS", 0);
1016 // Indicate if we need connect all in the platform setup
1018 if (ConnectAllHappened
) {
1019 gConnectAllHappened
= TRUE
;
1022 if (!mModeInitialized
) {
1024 // After the console is ready, get current video resolution
1025 // and text mode before launching setup at first time.
1027 Status
= gBS
->HandleProtocol (
1028 gST
->ConsoleOutHandle
,
1029 &gEfiGraphicsOutputProtocolGuid
,
1030 (VOID
**)&GraphicsOutput
1032 if (EFI_ERROR (Status
)) {
1033 GraphicsOutput
= NULL
;
1036 Status
= gBS
->HandleProtocol (
1037 gST
->ConsoleOutHandle
,
1038 &gEfiSimpleTextOutProtocolGuid
,
1039 (VOID
**)&SimpleTextOut
1041 if (EFI_ERROR (Status
)) {
1042 SimpleTextOut
= NULL
;
1045 if (GraphicsOutput
!= NULL
) {
1047 // Get current video resolution and text mode.
1049 mBootHorizontalResolution
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
1050 mBootVerticalResolution
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
1053 if (SimpleTextOut
!= NULL
) {
1054 Status
= SimpleTextOut
->QueryMode (
1056 SimpleTextOut
->Mode
->Mode
,
1060 mBootTextModeColumn
= (UINT32
)BootTextColumn
;
1061 mBootTextModeRow
= (UINT32
)BootTextRow
;
1065 // Get user defined text mode for setup.
1067 mSetupHorizontalResolution
= PcdGet32 (PcdSetupVideoHorizontalResolution
);
1068 mSetupVerticalResolution
= PcdGet32 (PcdSetupVideoVerticalResolution
);
1069 mSetupTextModeColumn
= PcdGet32 (PcdSetupConOutColumn
);
1070 mSetupTextModeRow
= PcdGet32 (PcdSetupConOutRow
);
1072 mModeInitialized
= TRUE
;
1077 // goto FrontPage directly when EFI_OS_INDICATIONS_BOOT_TO_FW_UI is set
1080 DataSize
= sizeof(UINT64
);
1081 Status
= gRT
->GetVariable (
1083 &gEfiGlobalVariableGuid
,
1090 // goto FrontPage directly when EFI_OS_INDICATIONS_BOOT_TO_FW_UI is set. Skip HotkeyBoot
1092 if (!EFI_ERROR(Status
) && ((OsIndication
& EFI_OS_INDICATIONS_BOOT_TO_FW_UI
) != 0)) {
1094 // Clear EFI_OS_INDICATIONS_BOOT_TO_FW_UI to acknowledge OS
1096 OsIndication
&= ~EFI_OS_INDICATIONS_BOOT_TO_FW_UI
;
1097 Status
= gRT
->SetVariable (
1099 &gEfiGlobalVariableGuid
,
1100 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
1104 ASSERT_EFI_ERROR (Status
);
1107 // Follow generic rule, Call ReadKeyStroke to connect ConIn before enter UI
1109 if (PcdGetBool (PcdConInConnectOnDemand
)) {
1110 gST
->ConIn
->ReadKeyStroke(gST
->ConIn
, &Key
);
1114 // Ensure screen is clear when switch Console from Graphics mode to Text mode
1116 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
1117 gST
->ConOut
->ClearScreen (gST
->ConOut
);
1122 if (TimeoutDefault
!= 0xffff) {
1123 Status
= ShowProgress (TimeoutDefault
);
1124 StatusHotkey
= HotkeyBoot ();
1126 if (!FeaturePcdGet(PcdBootlogoOnlyEnable
) || !EFI_ERROR(Status
) || !EFI_ERROR(StatusHotkey
)){
1128 // Ensure screen is clear when switch Console from Graphics mode to Text mode
1129 // Skip it in normal boot
1131 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
1132 gST
->ConOut
->ClearScreen (gST
->ConOut
);
1135 if (EFI_ERROR (Status
)) {
1137 // Timeout or user press enter to continue
1145 // Boot Logo is corrupted, report it using Boot Logo protocol.
1147 Status
= gBS
->LocateProtocol (&gEfiBootLogoProtocolGuid
, NULL
, (VOID
**) &BootLogo
);
1148 if (!EFI_ERROR (Status
) && (BootLogo
!= NULL
)) {
1149 BootLogo
->SetBootLogo (BootLogo
, NULL
, 0, 0, 0, 0);
1152 Status
= EFI_SUCCESS
;
1155 // Set proper video resolution and text mode for setup
1157 BdsSetConsoleMode (TRUE
);
1159 InitializeFrontPage (FALSE
);
1162 // Update Front Page strings
1164 UpdateFrontPageStrings ();
1170 // If gCallbackKey is greater than 1 and less or equal to 5,
1171 // it will launch configuration utilities.
1174 // 4 = device manager
1175 // 5 = boot maintenance manager
1177 if (gCallbackKey
!= 0) {
1178 REPORT_STATUS_CODE (
1180 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_PC_USER_SETUP
)
1184 // Based on the key that was set, we can determine what to do
1186 switch (gCallbackKey
) {
1188 // The first 4 entries in the Front Page are to be GUARANTEED to remain constant so IHV's can
1189 // describe to their customers in documentation how to find their setup information (namely
1190 // under the device manager and specific buckets)
1192 // These entries consist of the Continue, Select language, Boot Manager, and Device Manager
1194 case FRONT_PAGE_KEY_CONTINUE
:
1196 // User hit continue
1200 case FRONT_PAGE_KEY_LANGUAGE
:
1202 // User made a language setting change - display front page again
1206 case FRONT_PAGE_KEY_BOOT_MANAGER
:
1208 // User chose to run the Boot Manager
1213 case FRONT_PAGE_KEY_DEVICE_MANAGER
:
1215 // Display the Device Manager
1218 CallDeviceManager ();
1219 } while (gCallbackKey
== FRONT_PAGE_KEY_DEVICE_MANAGER
);
1222 case FRONT_PAGE_KEY_BOOT_MAINTAIN
:
1224 // Display the Boot Maintenance Manager
1226 BdsStartBootMaint ();
1230 } while ((Status
== EFI_SUCCESS
) && (gCallbackKey
!= FRONT_PAGE_KEY_CONTINUE
));
1233 //Will leave browser, check any reset required change is applied? if yes, reset system
1235 SetupResetReminder ();
1239 // Automatically load current entry
1240 // Note: The following lines of code only execute when Auto boot
1243 PERF_END (NULL
, "BdsTimeOut", "BDS", 0);
1247 This function will change video resolution and text mode
1248 according to defined setup mode or defined boot mode
1250 @param IsSetupMode Indicate mode is changed to setup mode or boot mode.
1252 @retval EFI_SUCCESS Mode is changed successfully.
1253 @retval Others Mode failed to be changed.
1262 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1263 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
1265 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
1269 UINT32 NewHorizontalResolution
;
1270 UINT32 NewVerticalResolution
;
1274 EFI_HANDLE
*HandleBuffer
;
1277 UINTN CurrentColumn
;
1284 // Get current video resolution and text mode
1286 Status
= gBS
->HandleProtocol (
1287 gST
->ConsoleOutHandle
,
1288 &gEfiGraphicsOutputProtocolGuid
,
1289 (VOID
**)&GraphicsOutput
1291 if (EFI_ERROR (Status
)) {
1292 GraphicsOutput
= NULL
;
1295 Status
= gBS
->HandleProtocol (
1296 gST
->ConsoleOutHandle
,
1297 &gEfiSimpleTextOutProtocolGuid
,
1298 (VOID
**)&SimpleTextOut
1300 if (EFI_ERROR (Status
)) {
1301 SimpleTextOut
= NULL
;
1304 if ((GraphicsOutput
== NULL
) || (SimpleTextOut
== NULL
)) {
1305 return EFI_UNSUPPORTED
;
1310 // The requried resolution and text mode is setup mode.
1312 NewHorizontalResolution
= mSetupHorizontalResolution
;
1313 NewVerticalResolution
= mSetupVerticalResolution
;
1314 NewColumns
= mSetupTextModeColumn
;
1315 NewRows
= mSetupTextModeRow
;
1318 // The required resolution and text mode is boot mode.
1320 NewHorizontalResolution
= mBootHorizontalResolution
;
1321 NewVerticalResolution
= mBootVerticalResolution
;
1322 NewColumns
= mBootTextModeColumn
;
1323 NewRows
= mBootTextModeRow
;
1326 if (GraphicsOutput
!= NULL
) {
1327 MaxGopMode
= GraphicsOutput
->Mode
->MaxMode
;
1330 if (SimpleTextOut
!= NULL
) {
1331 MaxTextMode
= SimpleTextOut
->Mode
->MaxMode
;
1335 // 1. If current video resolution is same with required video resolution,
1336 // video resolution need not be changed.
1337 // 1.1. If current text mode is same with required text mode, text mode need not be changed.
1338 // 1.2. If current text mode is different from required text mode, text mode need be changed.
1339 // 2. If current video resolution is different from required video resolution, we need restart whole console drivers.
1341 for (ModeNumber
= 0; ModeNumber
< MaxGopMode
; ModeNumber
++) {
1342 Status
= GraphicsOutput
->QueryMode (
1348 if (!EFI_ERROR (Status
)) {
1349 if ((Info
->HorizontalResolution
== NewHorizontalResolution
) &&
1350 (Info
->VerticalResolution
== NewVerticalResolution
)) {
1351 if ((GraphicsOutput
->Mode
->Info
->HorizontalResolution
== NewHorizontalResolution
) &&
1352 (GraphicsOutput
->Mode
->Info
->VerticalResolution
== NewVerticalResolution
)) {
1354 // Current resolution is same with required resolution, check if text mode need be set
1356 Status
= SimpleTextOut
->QueryMode (SimpleTextOut
, SimpleTextOut
->Mode
->Mode
, &CurrentColumn
, &CurrentRow
);
1357 ASSERT_EFI_ERROR (Status
);
1358 if (CurrentColumn
== NewColumns
&& CurrentRow
== NewRows
) {
1360 // If current text mode is same with required text mode. Do nothing
1366 // If current text mode is different from requried text mode. Set new video mode
1368 for (Index
= 0; Index
< MaxTextMode
; Index
++) {
1369 Status
= SimpleTextOut
->QueryMode (SimpleTextOut
, Index
, &CurrentColumn
, &CurrentRow
);
1370 if (!EFI_ERROR(Status
)) {
1371 if ((CurrentColumn
== NewColumns
) && (CurrentRow
== NewRows
)) {
1373 // Required text mode is supported, set it.
1375 Status
= SimpleTextOut
->SetMode (SimpleTextOut
, Index
);
1376 ASSERT_EFI_ERROR (Status
);
1378 // Update text mode PCD.
1380 PcdSet32 (PcdConOutColumn
, mSetupTextModeColumn
);
1381 PcdSet32 (PcdConOutRow
, mSetupTextModeRow
);
1387 if (Index
== MaxTextMode
) {
1389 // If requried text mode is not supported, return error.
1392 return EFI_UNSUPPORTED
;
1397 // If current video resolution is not same with the new one, set new video resolution.
1398 // In this case, the driver which produces simple text out need be restarted.
1400 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, ModeNumber
);
1401 if (!EFI_ERROR (Status
)) {
1411 if (ModeNumber
== MaxGopMode
) {
1413 // If the resolution is not supported, return error.
1415 return EFI_UNSUPPORTED
;
1419 // Set PCD to Inform GraphicsConsole to change video resolution.
1420 // Set PCD to Inform Consplitter to change text mode.
1422 PcdSet32 (PcdVideoHorizontalResolution
, NewHorizontalResolution
);
1423 PcdSet32 (PcdVideoVerticalResolution
, NewVerticalResolution
);
1424 PcdSet32 (PcdConOutColumn
, NewColumns
);
1425 PcdSet32 (PcdConOutRow
, NewRows
);
1429 // Video mode is changed, so restart graphics console driver and higher level driver.
1430 // Reconnect graphics console driver and higher level driver.
1431 // Locate all the handles with GOP protocol and reconnect it.
1433 Status
= gBS
->LocateHandleBuffer (
1435 &gEfiSimpleTextOutProtocolGuid
,
1440 if (!EFI_ERROR (Status
)) {
1441 for (Index
= 0; Index
< HandleCount
; Index
++) {
1442 gBS
->DisconnectController (HandleBuffer
[Index
], NULL
, NULL
);
1444 for (Index
= 0; Index
< HandleCount
; Index
++) {
1445 gBS
->ConnectController (HandleBuffer
[Index
], NULL
, NULL
, TRUE
);
1447 if (HandleBuffer
!= NULL
) {
1448 FreePool (HandleBuffer
);