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 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
966 if (EFI_ERROR (Status
)) {
970 if (Key
.UnicodeChar
== CHAR_CARRIAGE_RETURN
) {
972 // User pressed enter, equivalent to select "continue"
981 This function is the main entry of the platform setup entry.
982 The function will present the main menu of the system setup,
983 this is the platform reference part and can be customize.
986 @param TimeoutDefault The fault time out value before the system
988 @param ConnectAllHappened The indicater to check if the connect all have
993 PlatformBdsEnterFrontPage (
994 IN UINT16 TimeoutDefault
,
995 IN BOOLEAN ConnectAllHappened
999 EFI_STATUS StatusHotkey
;
1000 EFI_BOOT_LOGO_PROTOCOL
*BootLogo
;
1001 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1002 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
1003 UINTN BootTextColumn
;
1006 GraphicsOutput
= NULL
;
1007 SimpleTextOut
= NULL
;
1009 PERF_START (NULL
, "BdsTimeOut", "BDS", 0);
1011 // Indicate if we need connect all in the platform setup
1013 if (ConnectAllHappened
) {
1014 gConnectAllHappened
= TRUE
;
1017 if (!mModeInitialized
) {
1019 // After the console is ready, get current video resolution
1020 // and text mode before launching setup at first time.
1022 Status
= gBS
->HandleProtocol (
1023 gST
->ConsoleOutHandle
,
1024 &gEfiGraphicsOutputProtocolGuid
,
1025 (VOID
**)&GraphicsOutput
1027 if (EFI_ERROR (Status
)) {
1028 GraphicsOutput
= NULL
;
1031 Status
= gBS
->HandleProtocol (
1032 gST
->ConsoleOutHandle
,
1033 &gEfiSimpleTextOutProtocolGuid
,
1034 (VOID
**)&SimpleTextOut
1036 if (EFI_ERROR (Status
)) {
1037 SimpleTextOut
= NULL
;
1040 if (GraphicsOutput
!= NULL
) {
1042 // Get current video resolution and text mode.
1044 mBootHorizontalResolution
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
1045 mBootVerticalResolution
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
1048 if (SimpleTextOut
!= NULL
) {
1049 Status
= SimpleTextOut
->QueryMode (
1051 SimpleTextOut
->Mode
->Mode
,
1055 mBootTextModeColumn
= (UINT32
)BootTextColumn
;
1056 mBootTextModeRow
= (UINT32
)BootTextRow
;
1060 // Get user defined text mode for setup.
1062 mSetupHorizontalResolution
= PcdGet32 (PcdSetupVideoHorizontalResolution
);
1063 mSetupVerticalResolution
= PcdGet32 (PcdSetupVideoVerticalResolution
);
1064 mSetupTextModeColumn
= PcdGet32 (PcdSetupConOutColumn
);
1065 mSetupTextModeRow
= PcdGet32 (PcdSetupConOutRow
);
1067 mModeInitialized
= TRUE
;
1073 if (TimeoutDefault
!= 0xffff) {
1074 Status
= ShowProgress (TimeoutDefault
);
1075 StatusHotkey
= HotkeyBoot ();
1077 if (!FeaturePcdGet(PcdBootlogoOnlyEnable
) || !EFI_ERROR(StatusHotkey
)){
1079 // Ensure screen is clear when switch Console from Graphics mode to Text mode
1080 // Skip it in normal boot
1082 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
1083 gST
->ConOut
->ClearScreen (gST
->ConOut
);
1086 if (EFI_ERROR (Status
)) {
1088 // Timeout or user press enter to continue
1095 // Boot Logo is corrupted, report it using Boot Logo protocol.
1097 Status
= gBS
->LocateProtocol (&gEfiBootLogoProtocolGuid
, NULL
, (VOID
**) &BootLogo
);
1098 if (!EFI_ERROR (Status
) && (BootLogo
!= NULL
)) {
1099 BootLogo
->SetBootLogo (BootLogo
, NULL
, 0, 0, 0, 0);
1102 Status
= EFI_SUCCESS
;
1105 // Set proper video resolution and text mode for setup
1107 BdsSetConsoleMode (TRUE
);
1109 InitializeFrontPage (FALSE
);
1112 // Update Front Page strings
1114 UpdateFrontPageStrings ();
1120 // If gCallbackKey is greater than 1 and less or equal to 5,
1121 // it will launch configuration utilities.
1124 // 4 = device manager
1125 // 5 = boot maintenance manager
1127 if (gCallbackKey
!= 0) {
1128 REPORT_STATUS_CODE (
1130 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_PC_USER_SETUP
)
1134 // Based on the key that was set, we can determine what to do
1136 switch (gCallbackKey
) {
1138 // The first 4 entries in the Front Page are to be GUARANTEED to remain constant so IHV's can
1139 // describe to their customers in documentation how to find their setup information (namely
1140 // under the device manager and specific buckets)
1142 // These entries consist of the Continue, Select language, Boot Manager, and Device Manager
1144 case FRONT_PAGE_KEY_CONTINUE
:
1146 // User hit continue
1150 case FRONT_PAGE_KEY_LANGUAGE
:
1152 // User made a language setting change - display front page again
1156 case FRONT_PAGE_KEY_BOOT_MANAGER
:
1158 // User chose to run the Boot Manager
1163 case FRONT_PAGE_KEY_DEVICE_MANAGER
:
1165 // Display the Device Manager
1168 CallDeviceManager ();
1169 } while (gCallbackKey
== FRONT_PAGE_KEY_DEVICE_MANAGER
);
1172 case FRONT_PAGE_KEY_BOOT_MAINTAIN
:
1174 // Display the Boot Maintenance Manager
1176 BdsStartBootMaint ();
1180 } while ((Status
== EFI_SUCCESS
) && (gCallbackKey
!= FRONT_PAGE_KEY_CONTINUE
));
1183 //Will leave browser, check any reset required change is applied? if yes, reset system
1185 SetupResetReminder ();
1189 // Automatically load current entry
1190 // Note: The following lines of code only execute when Auto boot
1193 PERF_END (NULL
, "BdsTimeOut", "BDS", 0);
1197 This function will change video resolution and text mode
1198 according to defined setup mode or defined boot mode
1200 @param IsSetupMode Indicate mode is changed to setup mode or boot mode.
1202 @retval EFI_SUCCESS Mode is changed successfully.
1203 @retval Others Mode failed to be changed.
1212 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1213 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
1215 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
1219 UINT32 NewHorizontalResolution
;
1220 UINT32 NewVerticalResolution
;
1224 EFI_HANDLE
*HandleBuffer
;
1227 UINTN CurrentColumn
;
1234 // Get current video resolution and text mode
1236 Status
= gBS
->HandleProtocol (
1237 gST
->ConsoleOutHandle
,
1238 &gEfiGraphicsOutputProtocolGuid
,
1239 (VOID
**)&GraphicsOutput
1241 if (EFI_ERROR (Status
)) {
1242 GraphicsOutput
= NULL
;
1245 Status
= gBS
->HandleProtocol (
1246 gST
->ConsoleOutHandle
,
1247 &gEfiSimpleTextOutProtocolGuid
,
1248 (VOID
**)&SimpleTextOut
1250 if (EFI_ERROR (Status
)) {
1251 SimpleTextOut
= NULL
;
1254 if ((GraphicsOutput
== NULL
) || (SimpleTextOut
== NULL
)) {
1255 return EFI_UNSUPPORTED
;
1260 // The requried resolution and text mode is setup mode.
1262 NewHorizontalResolution
= mSetupHorizontalResolution
;
1263 NewVerticalResolution
= mSetupVerticalResolution
;
1264 NewColumns
= mSetupTextModeColumn
;
1265 NewRows
= mSetupTextModeRow
;
1268 // The required resolution and text mode is boot mode.
1270 NewHorizontalResolution
= mBootHorizontalResolution
;
1271 NewVerticalResolution
= mBootVerticalResolution
;
1272 NewColumns
= mBootTextModeColumn
;
1273 NewRows
= mBootTextModeRow
;
1276 if (GraphicsOutput
!= NULL
) {
1277 MaxGopMode
= GraphicsOutput
->Mode
->MaxMode
;
1280 if (SimpleTextOut
!= NULL
) {
1281 MaxTextMode
= SimpleTextOut
->Mode
->MaxMode
;
1285 // 1. If current video resolution is same with required video resolution,
1286 // video resolution need not be changed.
1287 // 1.1. If current text mode is same with required text mode, text mode need not be changed.
1288 // 1.2. If current text mode is different from required text mode, text mode need be changed.
1289 // 2. If current video resolution is different from required video resolution, we need restart whole console drivers.
1291 for (ModeNumber
= 0; ModeNumber
< MaxGopMode
; ModeNumber
++) {
1292 Status
= GraphicsOutput
->QueryMode (
1298 if (!EFI_ERROR (Status
)) {
1299 if ((Info
->HorizontalResolution
== NewHorizontalResolution
) &&
1300 (Info
->VerticalResolution
== NewVerticalResolution
)) {
1301 if ((GraphicsOutput
->Mode
->Info
->HorizontalResolution
== NewHorizontalResolution
) &&
1302 (GraphicsOutput
->Mode
->Info
->VerticalResolution
== NewVerticalResolution
)) {
1304 // Current resolution is same with required resolution, check if text mode need be set
1306 Status
= SimpleTextOut
->QueryMode (SimpleTextOut
, SimpleTextOut
->Mode
->Mode
, &CurrentColumn
, &CurrentRow
);
1307 ASSERT_EFI_ERROR (Status
);
1308 if (CurrentColumn
== NewColumns
&& CurrentRow
== NewRows
) {
1310 // If current text mode is same with required text mode. Do nothing
1316 // If current text mode is different from requried text mode. Set new video mode
1318 for (Index
= 0; Index
< MaxTextMode
; Index
++) {
1319 Status
= SimpleTextOut
->QueryMode (SimpleTextOut
, Index
, &CurrentColumn
, &CurrentRow
);
1320 if (!EFI_ERROR(Status
)) {
1321 if ((CurrentColumn
== NewColumns
) && (CurrentRow
== NewRows
)) {
1323 // Required text mode is supported, set it.
1325 Status
= SimpleTextOut
->SetMode (SimpleTextOut
, Index
);
1326 ASSERT_EFI_ERROR (Status
);
1328 // Update text mode PCD.
1330 PcdSet32 (PcdConOutColumn
, mSetupTextModeColumn
);
1331 PcdSet32 (PcdConOutRow
, mSetupTextModeRow
);
1337 if (Index
== MaxTextMode
) {
1339 // If requried text mode is not supported, return error.
1342 return EFI_UNSUPPORTED
;
1347 // If current video resolution is not same with the new one, set new video resolution.
1348 // In this case, the driver which produces simple text out need be restarted.
1350 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, ModeNumber
);
1351 if (!EFI_ERROR (Status
)) {
1361 if (ModeNumber
== MaxGopMode
) {
1363 // If the resolution is not supported, return error.
1365 return EFI_UNSUPPORTED
;
1369 // Set PCD to Inform GraphicsConsole to change video resolution.
1370 // Set PCD to Inform Consplitter to change text mode.
1372 PcdSet32 (PcdVideoHorizontalResolution
, NewHorizontalResolution
);
1373 PcdSet32 (PcdVideoVerticalResolution
, NewVerticalResolution
);
1374 PcdSet32 (PcdConOutColumn
, NewColumns
);
1375 PcdSet32 (PcdConOutRow
, NewRows
);
1379 // Video mode is changed, so restart graphics console driver and higher level driver.
1380 // Reconnect graphics console driver and higher level driver.
1381 // Locate all the handles with GOP protocol and reconnect it.
1383 Status
= gBS
->LocateHandleBuffer (
1385 &gEfiSimpleTextOutProtocolGuid
,
1390 if (!EFI_ERROR (Status
)) {
1391 for (Index
= 0; Index
< HandleCount
; Index
++) {
1392 gBS
->DisconnectController (HandleBuffer
[Index
], NULL
, NULL
);
1394 for (Index
= 0; Index
< HandleCount
; Index
++) {
1395 gBS
->ConnectController (HandleBuffer
[Index
], NULL
, NULL
, TRUE
);
1397 if (HandleBuffer
!= NULL
) {
1398 FreePool (HandleBuffer
);