2 FrontPage routines to handle the callbacks and browser calls
4 Copyright (c) 2004 - 2014, 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
;
24 CHAR8
*mLanguageString
;
27 // Boot video resolution and text mode.
29 UINT32 mBootHorizontalResolution
= 0;
30 UINT32 mBootVerticalResolution
= 0;
31 UINT32 mBootTextModeColumn
= 0;
32 UINT32 mBootTextModeRow
= 0;
34 // BIOS setup video resolution and text mode.
36 UINT32 mSetupTextModeColumn
= 0;
37 UINT32 mSetupTextModeRow
= 0;
38 UINT32 mSetupHorizontalResolution
= 0;
39 UINT32 mSetupVerticalResolution
= 0;
41 EFI_FORM_BROWSER2_PROTOCOL
*gFormBrowser2
;
43 FRONT_PAGE_CALLBACK_DATA gFrontPagePrivate
= {
44 FRONT_PAGE_CALLBACK_DATA_SIGNATURE
,
55 HII_VENDOR_DEVICE_PATH mFrontPageHiiVendorDevicePath
= {
61 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
62 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
65 FRONT_PAGE_FORMSET_GUID
69 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
71 (UINT8
) (END_DEVICE_PATH_LENGTH
),
72 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
78 This function allows a caller to extract the current configuration for one
79 or more named elements from the target driver.
82 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
83 @param Request A null-terminated Unicode string in <ConfigRequest> format.
84 @param Progress On return, points to a character in the Request string.
85 Points to the string's null terminator if request was successful.
86 Points to the most recent '&' before the first failing name/value
87 pair (or the beginning of the string if the failure is in the
88 first name/value pair) if the request was not successful.
89 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
90 has all values filled in for the names in the Request string.
91 String to be allocated by the called function.
93 @retval EFI_SUCCESS The Results is filled with the requested values.
94 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
95 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
96 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
102 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
103 IN CONST EFI_STRING Request
,
104 OUT EFI_STRING
*Progress
,
105 OUT EFI_STRING
*Results
108 if (Progress
== NULL
|| Results
== NULL
) {
109 return EFI_INVALID_PARAMETER
;
112 return EFI_NOT_FOUND
;
116 This function processes the results of changes in configuration.
119 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
120 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
121 @param Progress A pointer to a string filled in with the offset of the most
122 recent '&' before the first failing name/value pair (or the
123 beginning of the string if the failure is in the first
124 name/value pair) or the terminating NULL if all was successful.
126 @retval EFI_SUCCESS The Results is processed successfully.
127 @retval EFI_INVALID_PARAMETER Configuration is NULL.
128 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
134 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
135 IN CONST EFI_STRING Configuration
,
136 OUT EFI_STRING
*Progress
139 if (Configuration
== NULL
|| Progress
== NULL
) {
140 return EFI_INVALID_PARAMETER
;
143 *Progress
= Configuration
;
144 if (!HiiIsConfigHdrMatch (Configuration
, &gBootMaintFormSetGuid
, mBootMaintStorageName
)
145 && !HiiIsConfigHdrMatch (Configuration
, &gFileExploreFormSetGuid
, mFileExplorerStorageName
)) {
146 return EFI_NOT_FOUND
;
149 *Progress
= Configuration
+ StrLen (Configuration
);
154 This function processes the results of changes in configuration.
157 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
158 @param Action Specifies the type of action taken by the browser.
159 @param QuestionId A unique value which is sent to the original exporting driver
160 so that it can identify the type of data to expect.
161 @param Type The type of value for the question.
162 @param Value A pointer to the data being sent to the original exporting driver.
163 @param ActionRequest On return, points to the action requested by the callback function.
165 @retval EFI_SUCCESS The callback successfully handled the action.
166 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
167 @retval EFI_DEVICE_ERROR The variable could not be saved.
168 @retval EFI_UNSUPPORTED The specified Action is not supported by the callback.
174 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
175 IN EFI_BROWSER_ACTION Action
,
176 IN EFI_QUESTION_ID QuestionId
,
178 IN EFI_IFR_TYPE_VALUE
*Value
,
179 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
186 if (Action
!= EFI_BROWSER_ACTION_CHANGING
&& Action
!= EFI_BROWSER_ACTION_CHANGED
) {
188 // All other action return unsupported.
190 return EFI_UNSUPPORTED
;
193 gCallbackKey
= QuestionId
;
195 if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
196 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
197 return EFI_INVALID_PARAMETER
;
200 switch (QuestionId
) {
201 case FRONT_PAGE_KEY_CONTINUE
:
203 // This is the continue - clear the screen and return an error to get out of FrontPage loop
205 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
208 case FRONT_PAGE_KEY_LANGUAGE
:
210 // Allocate working buffer for RFC 4646 language in supported LanguageString.
212 Lang
= AllocatePool (AsciiStrSize (mLanguageString
));
213 ASSERT (Lang
!= NULL
);
216 LangCode
= mLanguageString
;
217 while (*LangCode
!= 0) {
218 GetNextLanguage (&LangCode
, Lang
);
220 if (Index
== Value
->u8
) {
227 if (Index
== Value
->u8
) {
228 BdsDxeSetVariableAndReportStatusCodeOnError (
230 &gEfiGlobalVariableGuid
,
231 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
239 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
247 } else if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
249 return EFI_INVALID_PARAMETER
;
253 // The first 4 entries in the Front Page are to be GUARANTEED to remain constant so IHV's can
254 // describe to their customers in documentation how to find their setup information (namely
255 // under the device manager and specific buckets)
257 switch (QuestionId
) {
258 case FRONT_PAGE_KEY_BOOT_MANAGER
:
264 case FRONT_PAGE_KEY_DEVICE_MANAGER
:
270 case FRONT_PAGE_KEY_BOOT_MAINTAIN
:
272 // Boot Maintenance Manager
286 Initialize HII information for the FrontPage
289 @param InitializeHiiData TRUE if HII elements need to be initialized.
291 @retval EFI_SUCCESS The operation is successful.
292 @retval EFI_DEVICE_ERROR If the dynamic opcode creation failed.
296 InitializeFrontPage (
297 IN BOOLEAN InitializeHiiData
305 CHAR16
*StringBuffer
;
306 EFI_HII_HANDLE HiiHandle
;
307 VOID
*OptionsOpCodeHandle
;
308 VOID
*StartOpCodeHandle
;
309 VOID
*EndOpCodeHandle
;
310 EFI_IFR_GUID_LABEL
*StartLabel
;
311 EFI_IFR_GUID_LABEL
*EndLabel
;
312 EFI_HII_STRING_PROTOCOL
*HiiString
;
318 if (InitializeHiiData
) {
320 // Initialize the Device Manager
322 InitializeDeviceManager ();
325 // Initialize the Device Manager
327 InitializeBootManager ();
332 // Locate Hii relative protocols
334 Status
= gBS
->LocateProtocol (&gEfiFormBrowser2ProtocolGuid
, NULL
, (VOID
**) &gFormBrowser2
);
335 if (EFI_ERROR (Status
)) {
340 // Install Device Path Protocol and Config Access protocol to driver handle
342 Status
= gBS
->InstallMultipleProtocolInterfaces (
343 &gFrontPagePrivate
.DriverHandle
,
344 &gEfiDevicePathProtocolGuid
,
345 &mFrontPageHiiVendorDevicePath
,
346 &gEfiHiiConfigAccessProtocolGuid
,
347 &gFrontPagePrivate
.ConfigAccess
,
350 ASSERT_EFI_ERROR (Status
);
353 // Publish our HII data
355 gFrontPagePrivate
.HiiHandle
= HiiAddPackages (
356 &gFrontPageFormSetGuid
,
357 gFrontPagePrivate
.DriverHandle
,
362 if (gFrontPagePrivate
.HiiHandle
== NULL
) {
363 return EFI_OUT_OF_RESOURCES
;
369 // Init OpCode Handle and Allocate space for creation of UpdateData Buffer
371 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
372 ASSERT (StartOpCodeHandle
!= NULL
);
374 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
375 ASSERT (EndOpCodeHandle
!= NULL
);
377 OptionsOpCodeHandle
= HiiAllocateOpCodeHandle ();
378 ASSERT (OptionsOpCodeHandle
!= NULL
);
380 // Create Hii Extend Label OpCode as the start opcode
382 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
383 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
384 StartLabel
->Number
= LABEL_SELECT_LANGUAGE
;
387 // Create Hii Extend Label OpCode as the end opcode
389 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
390 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
391 EndLabel
->Number
= LABEL_END
;
394 // Collect the languages from what our current Language support is based on our VFR
396 HiiHandle
= gFrontPagePrivate
.HiiHandle
;
398 CurrentLang
= GetEfiGlobalVariable (L
"PlatformLang");
401 // Get Support language list from variable.
403 if (mLanguageString
== NULL
){
404 mLanguageString
= GetEfiGlobalVariable (L
"PlatformLangCodes");
405 if (mLanguageString
== NULL
) {
406 mLanguageString
= AllocateCopyPool (
407 AsciiStrSize ((CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLangCodes
)),
408 (CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLangCodes
)
410 ASSERT (mLanguageString
!= NULL
);
414 if (gFrontPagePrivate
.LanguageToken
== NULL
) {
416 // Count the language list number.
418 LangCode
= mLanguageString
;
419 Lang
= AllocatePool (AsciiStrSize (mLanguageString
));
420 ASSERT (Lang
!= NULL
);
422 while (*LangCode
!= 0) {
423 GetNextLanguage (&LangCode
, Lang
);
428 // Allocate extra 1 as the end tag.
430 gFrontPagePrivate
.LanguageToken
= AllocateZeroPool ((OptionCount
+ 1) * sizeof (EFI_STRING_ID
));
431 ASSERT (gFrontPagePrivate
.LanguageToken
!= NULL
);
433 Status
= gBS
->LocateProtocol (&gEfiHiiStringProtocolGuid
, NULL
, (VOID
**) &HiiString
);
434 ASSERT_EFI_ERROR (Status
);
436 LangCode
= mLanguageString
;
438 while (*LangCode
!= 0) {
439 GetNextLanguage (&LangCode
, Lang
);
442 Status
= HiiString
->GetString (HiiString
, Lang
, HiiHandle
, PRINTABLE_LANGUAGE_NAME_STRING_ID
, StringBuffer
, &StringSize
, NULL
);
443 if (Status
== EFI_BUFFER_TOO_SMALL
) {
444 StringBuffer
= AllocateZeroPool (StringSize
);
445 ASSERT (StringBuffer
!= NULL
);
446 Status
= HiiString
->GetString (HiiString
, Lang
, HiiHandle
, PRINTABLE_LANGUAGE_NAME_STRING_ID
, StringBuffer
, &StringSize
, NULL
);
447 ASSERT_EFI_ERROR (Status
);
450 if (EFI_ERROR (Status
)) {
451 StringBuffer
= AllocatePool (AsciiStrSize (Lang
) * sizeof (CHAR16
));
452 ASSERT (StringBuffer
!= NULL
);
453 AsciiStrToUnicodeStr (Lang
, StringBuffer
);
456 ASSERT (StringBuffer
!= NULL
);
457 gFrontPagePrivate
.LanguageToken
[OptionCount
] = HiiSetString (HiiHandle
, 0, StringBuffer
, NULL
);
458 FreePool (StringBuffer
);
464 ASSERT (gFrontPagePrivate
.LanguageToken
!= NULL
);
465 LangCode
= mLanguageString
;
468 Lang
= AllocatePool (AsciiStrSize (mLanguageString
));
469 ASSERT (Lang
!= NULL
);
471 while (*LangCode
!= 0) {
472 GetNextLanguage (&LangCode
, Lang
);
474 if (CurrentLang
!= NULL
&& AsciiStrCmp (Lang
, CurrentLang
) == 0) {
475 HiiCreateOneOfOptionOpCode (
477 gFrontPagePrivate
.LanguageToken
[OptionCount
],
478 EFI_IFR_OPTION_DEFAULT
,
479 EFI_IFR_NUMERIC_SIZE_1
,
483 HiiCreateOneOfOptionOpCode (
485 gFrontPagePrivate
.LanguageToken
[OptionCount
],
487 EFI_IFR_NUMERIC_SIZE_1
,
495 if (CurrentLang
!= NULL
) {
496 FreePool (CurrentLang
);
500 HiiCreateOneOfOpCode (
502 FRONT_PAGE_KEY_LANGUAGE
,
505 STRING_TOKEN (STR_LANGUAGE_SELECT
),
506 STRING_TOKEN (STR_LANGUAGE_SELECT_HELP
),
507 EFI_IFR_FLAG_CALLBACK
,
508 EFI_IFR_NUMERIC_SIZE_1
,
513 Status
= HiiUpdateForm (
515 &gFrontPageFormSetGuid
,
517 StartOpCodeHandle
, // LABEL_SELECT_LANGUAGE
518 EndOpCodeHandle
// LABEL_END
521 HiiFreeOpCodeHandle (StartOpCodeHandle
);
522 HiiFreeOpCodeHandle (EndOpCodeHandle
);
523 HiiFreeOpCodeHandle (OptionsOpCodeHandle
);
528 Call the browser and display the front page
530 @return Status code that will be returned by
531 EFI_FORM_BROWSER2_PROTOCOL.SendForm ().
540 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
543 // Begin waiting for USER INPUT
547 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_PC_INPUT_WAIT
)
550 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
551 Status
= gFormBrowser2
->SendForm (
553 &gFrontPagePrivate
.HiiHandle
,
555 &gFrontPageFormSetGuid
,
561 // Check whether user change any option setting which needs a reset to be effective
563 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
564 EnableResetRequired ();
571 Acquire the string associated with the ProducerGuid and return it.
574 @param ProducerGuid The Guid to search the HII database for
575 @param Token The token value of the string to extract
576 @param String The string that is extracted
578 @retval EFI_SUCCESS The function returns EFI_SUCCESS always.
583 IN EFI_GUID
*ProducerGuid
,
584 IN EFI_STRING_ID Token
,
588 EFI_STRING TmpString
;
590 TmpString
= HiiGetPackageString (ProducerGuid
, Token
, NULL
);
591 if (TmpString
== NULL
) {
592 *String
= GetStringById (STRING_TOKEN (STR_MISSING_STRING
));
601 Convert Processor Frequency Data to a string.
603 @param ProcessorFrequency The frequency data to process
604 @param Base10Exponent The exponent based on 10
605 @param String The string that is created
609 ConvertProcessorToString (
610 IN UINT16 ProcessorFrequency
,
611 IN UINT16 Base10Exponent
,
615 CHAR16
*StringBuffer
;
619 if (Base10Exponent
>= 6) {
620 FreqMhz
= ProcessorFrequency
;
621 for (Index
= 0; Index
< (UINTN
) (Base10Exponent
- 6); Index
++) {
628 StringBuffer
= AllocateZeroPool (0x20);
629 ASSERT (StringBuffer
!= NULL
);
630 Index
= UnicodeValueToString (StringBuffer
, LEFT_JUSTIFY
, FreqMhz
/ 1000, 3);
631 StrCat (StringBuffer
, L
".");
632 UnicodeValueToString (StringBuffer
+ Index
+ 1, PREFIX_ZERO
, (FreqMhz
% 1000) / 10, 2);
633 StrCat (StringBuffer
, L
" GHz");
634 *String
= (CHAR16
*) StringBuffer
;
640 Convert Memory Size to a string.
642 @param MemorySize The size of the memory to process
643 @param String The string that is created
647 ConvertMemorySizeToString (
648 IN UINT32 MemorySize
,
652 CHAR16
*StringBuffer
;
654 StringBuffer
= AllocateZeroPool (0x20);
655 ASSERT (StringBuffer
!= NULL
);
656 UnicodeValueToString (StringBuffer
, LEFT_JUSTIFY
, MemorySize
, 6);
657 StrCat (StringBuffer
, L
" MB RAM");
659 *String
= (CHAR16
*) StringBuffer
;
666 Acquire the string associated with the Index from smbios structure and return it.
667 The caller is responsible for free the string buffer.
669 @param OptionalStrStart The start position to search the string
670 @param Index The index of the string to extract
671 @param String The string that is extracted
673 @retval EFI_SUCCESS The function returns EFI_SUCCESS always.
677 GetOptionalStringByIndex (
678 IN CHAR8
*OptionalStrStart
,
686 *String
= AllocateZeroPool (sizeof (CHAR16
));
693 OptionalStrStart
+= StrSize
;
694 StrSize
= AsciiStrSize (OptionalStrStart
);
695 } while (OptionalStrStart
[StrSize
] != 0 && Index
!= 0);
697 if ((Index
!= 0) || (StrSize
== 1)) {
699 // Meet the end of strings set but Index is non-zero, or
700 // Find an empty string
702 *String
= GetStringById (STRING_TOKEN (STR_MISSING_STRING
));
704 *String
= AllocatePool (StrSize
* sizeof (CHAR16
));
705 AsciiStrToUnicodeStr (OptionalStrStart
, *String
);
713 Update the banner information for the Front Page based on DataHub information.
717 UpdateFrontPageStrings (
725 EFI_STRING_ID TokenToUpdate
;
726 EFI_SMBIOS_HANDLE SmbiosHandle
;
727 EFI_SMBIOS_PROTOCOL
*Smbios
;
728 SMBIOS_TABLE_TYPE0
*Type0Record
;
729 SMBIOS_TABLE_TYPE1
*Type1Record
;
730 SMBIOS_TABLE_TYPE4
*Type4Record
;
731 SMBIOS_TABLE_TYPE19
*Type19Record
;
732 EFI_SMBIOS_TABLE_HEADER
*Record
;
734 ZeroMem (Find
, sizeof (Find
));
737 // Update Front Page strings
739 Status
= gBS
->LocateProtocol (
740 &gEfiSmbiosProtocolGuid
,
744 ASSERT_EFI_ERROR (Status
);
746 SmbiosHandle
= SMBIOS_HANDLE_PI_RESERVED
;
748 Status
= Smbios
->GetNext (Smbios
, &SmbiosHandle
, NULL
, &Record
, NULL
);
749 if (EFI_ERROR(Status
)) {
753 if (Record
->Type
== EFI_SMBIOS_TYPE_BIOS_INFORMATION
) {
754 Type0Record
= (SMBIOS_TABLE_TYPE0
*) Record
;
755 StrIndex
= Type0Record
->BiosVersion
;
756 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type0Record
+ Type0Record
->Hdr
.Length
), StrIndex
, &NewString
);
757 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION
);
758 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
759 FreePool (NewString
);
763 if (Record
->Type
== EFI_SMBIOS_TYPE_SYSTEM_INFORMATION
) {
764 Type1Record
= (SMBIOS_TABLE_TYPE1
*) Record
;
765 StrIndex
= Type1Record
->ProductName
;
766 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type1Record
+ Type1Record
->Hdr
.Length
), StrIndex
, &NewString
);
767 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_COMPUTER_MODEL
);
768 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
769 FreePool (NewString
);
773 if (Record
->Type
== EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION
) {
774 Type4Record
= (SMBIOS_TABLE_TYPE4
*) Record
;
775 StrIndex
= Type4Record
->ProcessorVersion
;
776 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type4Record
+ Type4Record
->Hdr
.Length
), StrIndex
, &NewString
);
777 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_CPU_MODEL
);
778 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
779 FreePool (NewString
);
783 if (Record
->Type
== EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION
) {
784 Type4Record
= (SMBIOS_TABLE_TYPE4
*) Record
;
785 ConvertProcessorToString(Type4Record
->CurrentSpeed
, 6, &NewString
);
786 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_CPU_SPEED
);
787 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
788 FreePool (NewString
);
792 if ( Record
->Type
== EFI_SMBIOS_TYPE_MEMORY_ARRAY_MAPPED_ADDRESS
) {
793 Type19Record
= (SMBIOS_TABLE_TYPE19
*) Record
;
794 ConvertMemorySizeToString (
795 (UINT32
)(RShiftU64((Type19Record
->EndingAddress
- Type19Record
->StartingAddress
+ 1), 10)),
798 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_MEMORY_SIZE
);
799 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
800 FreePool (NewString
);
803 } while ( !(Find
[0] && Find
[1] && Find
[2] && Find
[3] && Find
[4]));
809 Function waits for a given event to fire, or for an optional timeout to expire.
811 @param Event The event to wait for
812 @param Timeout An optional timeout value in 100 ns units.
814 @retval EFI_SUCCESS Event fired before Timeout expired.
815 @retval EFI_TIME_OUT Timout expired before Event fired..
821 IN UINT64 Timeout OPTIONAL
826 EFI_EVENT TimerEvent
;
827 EFI_EVENT WaitList
[2];
831 // Create a timer event
833 Status
= gBS
->CreateEvent (EVT_TIMER
, 0, NULL
, NULL
, &TimerEvent
);
834 if (!EFI_ERROR (Status
)) {
836 // Set the timer event
845 // Wait for the original event or the timer
848 WaitList
[1] = TimerEvent
;
849 Status
= gBS
->WaitForEvent (2, WaitList
, &Index
);
850 gBS
->CloseEvent (TimerEvent
);
853 // If the timer expired, change the return to timed out
855 if (!EFI_ERROR (Status
) && Index
== 1) {
856 Status
= EFI_TIMEOUT
;
861 // No timeout... just wait on the event
863 Status
= gBS
->WaitForEvent (1, &Event
, &Index
);
864 ASSERT (!EFI_ERROR (Status
));
872 Function show progress bar to wait for user input.
875 @param TimeoutDefault The fault time out value before the system continue to boot.
877 @retval EFI_SUCCESS User pressed some key except "Enter"
878 @retval EFI_TIME_OUT Timeout expired or user press "Enter"
883 IN UINT16 TimeoutDefault
887 UINT16 TimeoutRemain
;
890 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
891 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
892 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
894 if (TimeoutDefault
== 0) {
898 DEBUG ((EFI_D_INFO
, "\n\nStart showing progress bar... Press any key to stop it! ...Zzz....\n"));
900 SetMem (&Foreground
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
901 SetMem (&Background
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0x0);
902 SetMem (&Color
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
904 TmpStr
= GetStringById (STRING_TOKEN (STR_START_BOOT_OPTION
));
906 if (!FeaturePcdGet(PcdBootlogoOnlyEnable
)) {
908 // Clear the progress status bar first
910 if (TmpStr
!= NULL
) {
911 PlatformBdsShowProgress (Foreground
, Background
, TmpStr
, Color
, 0, 0);
916 TimeoutRemain
= TimeoutDefault
;
917 while (TimeoutRemain
!= 0) {
918 DEBUG ((EFI_D_INFO
, "Showing progress bar...Remaining %d second!\n", TimeoutRemain
));
920 Status
= WaitForSingleEvent (gST
->ConIn
->WaitForKey
, ONE_SECOND
);
921 if (Status
!= EFI_TIMEOUT
) {
926 if (!FeaturePcdGet(PcdBootlogoOnlyEnable
)) {
930 if (TmpStr
!= NULL
) {
931 PlatformBdsShowProgress (
936 ((TimeoutDefault
- TimeoutRemain
) * 100 / TimeoutDefault
),
943 if (TmpStr
!= NULL
) {
944 gBS
->FreePool (TmpStr
);
950 if (TimeoutRemain
== 0) {
955 // User pressed some key
957 if (!PcdGetBool (PcdConInConnectOnDemand
)) {
958 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
959 if (EFI_ERROR (Status
)) {
963 if (Key
.UnicodeChar
== CHAR_CARRIAGE_RETURN
) {
965 // User pressed enter, equivalent to select "continue"
975 This function is the main entry of the platform setup entry.
976 The function will present the main menu of the system setup,
977 this is the platform reference part and can be customize.
980 @param TimeoutDefault The fault time out value before the system
982 @param ConnectAllHappened The indicater to check if the connect all have
987 PlatformBdsEnterFrontPage (
988 IN UINT16 TimeoutDefault
,
989 IN BOOLEAN ConnectAllHappened
993 EFI_STATUS StatusHotkey
;
994 EFI_BOOT_LOGO_PROTOCOL
*BootLogo
;
995 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
996 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
997 UINTN BootTextColumn
;
1003 GraphicsOutput
= NULL
;
1004 SimpleTextOut
= NULL
;
1006 PERF_START (NULL
, "BdsTimeOut", "BDS", 0);
1008 // Indicate if we need connect all in the platform setup
1010 if (ConnectAllHappened
) {
1011 gConnectAllHappened
= TRUE
;
1014 if (!mModeInitialized
) {
1016 // After the console is ready, get current video resolution
1017 // and text mode before launching setup at first time.
1019 Status
= gBS
->HandleProtocol (
1020 gST
->ConsoleOutHandle
,
1021 &gEfiGraphicsOutputProtocolGuid
,
1022 (VOID
**)&GraphicsOutput
1024 if (EFI_ERROR (Status
)) {
1025 GraphicsOutput
= NULL
;
1028 Status
= gBS
->HandleProtocol (
1029 gST
->ConsoleOutHandle
,
1030 &gEfiSimpleTextOutProtocolGuid
,
1031 (VOID
**)&SimpleTextOut
1033 if (EFI_ERROR (Status
)) {
1034 SimpleTextOut
= NULL
;
1037 if (GraphicsOutput
!= NULL
) {
1039 // Get current video resolution and text mode.
1041 mBootHorizontalResolution
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
1042 mBootVerticalResolution
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
1045 if (SimpleTextOut
!= NULL
) {
1046 Status
= SimpleTextOut
->QueryMode (
1048 SimpleTextOut
->Mode
->Mode
,
1052 mBootTextModeColumn
= (UINT32
)BootTextColumn
;
1053 mBootTextModeRow
= (UINT32
)BootTextRow
;
1057 // Get user defined text mode for setup.
1059 mSetupHorizontalResolution
= PcdGet32 (PcdSetupVideoHorizontalResolution
);
1060 mSetupVerticalResolution
= PcdGet32 (PcdSetupVideoVerticalResolution
);
1061 mSetupTextModeColumn
= PcdGet32 (PcdSetupConOutColumn
);
1062 mSetupTextModeRow
= PcdGet32 (PcdSetupConOutRow
);
1064 mModeInitialized
= TRUE
;
1069 // goto FrontPage directly when EFI_OS_INDICATIONS_BOOT_TO_FW_UI is set
1072 DataSize
= sizeof(UINT64
);
1073 Status
= gRT
->GetVariable (
1075 &gEfiGlobalVariableGuid
,
1082 // goto FrontPage directly when EFI_OS_INDICATIONS_BOOT_TO_FW_UI is set. Skip HotkeyBoot
1084 if (!EFI_ERROR(Status
) && ((OsIndication
& EFI_OS_INDICATIONS_BOOT_TO_FW_UI
) != 0)) {
1086 // Clear EFI_OS_INDICATIONS_BOOT_TO_FW_UI to acknowledge OS
1088 OsIndication
&= ~((UINT64
)EFI_OS_INDICATIONS_BOOT_TO_FW_UI
);
1089 Status
= gRT
->SetVariable (
1091 &gEfiGlobalVariableGuid
,
1092 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
1097 // Changing the content without increasing its size with current variable implementation shouldn't fail.
1099 ASSERT_EFI_ERROR (Status
);
1102 // Follow generic rule, Call ReadKeyStroke to connect ConIn before enter UI
1104 if (PcdGetBool (PcdConInConnectOnDemand
)) {
1105 gST
->ConIn
->ReadKeyStroke(gST
->ConIn
, &Key
);
1109 // Ensure screen is clear when switch Console from Graphics mode to Text mode
1111 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
1112 gST
->ConOut
->ClearScreen (gST
->ConOut
);
1117 if (TimeoutDefault
!= 0xffff) {
1118 Status
= ShowProgress (TimeoutDefault
);
1119 StatusHotkey
= HotkeyBoot ();
1121 if (!FeaturePcdGet(PcdBootlogoOnlyEnable
) || !EFI_ERROR(Status
) || !EFI_ERROR(StatusHotkey
)){
1123 // Ensure screen is clear when switch Console from Graphics mode to Text mode
1124 // Skip it in normal boot
1126 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
1127 gST
->ConOut
->ClearScreen (gST
->ConOut
);
1130 if (EFI_ERROR (Status
)) {
1132 // Timeout or user press enter to continue
1140 // Boot Logo is corrupted, report it using Boot Logo protocol.
1142 Status
= gBS
->LocateProtocol (&gEfiBootLogoProtocolGuid
, NULL
, (VOID
**) &BootLogo
);
1143 if (!EFI_ERROR (Status
) && (BootLogo
!= NULL
)) {
1144 BootLogo
->SetBootLogo (BootLogo
, NULL
, 0, 0, 0, 0);
1148 // Install BM HiiPackages.
1149 // Keep BootMaint HiiPackage, so that it can be covered by global setting.
1153 Status
= EFI_SUCCESS
;
1156 // Set proper video resolution and text mode for setup
1158 BdsSetConsoleMode (TRUE
);
1160 InitializeFrontPage (FALSE
);
1163 // Update Front Page strings
1165 UpdateFrontPageStrings ();
1171 // If gCallbackKey is greater than 1 and less or equal to 5,
1172 // it will launch configuration utilities.
1175 // 4 = device manager
1176 // 5 = boot maintenance manager
1178 if (gCallbackKey
!= 0) {
1179 REPORT_STATUS_CODE (
1181 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_PC_USER_SETUP
)
1185 // Based on the key that was set, we can determine what to do
1187 switch (gCallbackKey
) {
1189 // The first 4 entries in the Front Page are to be GUARANTEED to remain constant so IHV's can
1190 // describe to their customers in documentation how to find their setup information (namely
1191 // under the device manager and specific buckets)
1193 // These entries consist of the Continue, Select language, Boot Manager, and Device Manager
1195 case FRONT_PAGE_KEY_CONTINUE
:
1197 // User hit continue
1201 case FRONT_PAGE_KEY_LANGUAGE
:
1203 // User made a language setting change - display front page again
1207 case FRONT_PAGE_KEY_BOOT_MANAGER
:
1209 // Remove the installed BootMaint HiiPackages when exit.
1214 // User chose to run the Boot Manager
1219 // Reinstall BootMaint HiiPackages after exiting from Boot Manager.
1224 case FRONT_PAGE_KEY_DEVICE_MANAGER
:
1226 // Display the Device Manager
1229 CallDeviceManager ();
1230 } while (gCallbackKey
== FRONT_PAGE_KEY_DEVICE_MANAGER
);
1233 case FRONT_PAGE_KEY_BOOT_MAINTAIN
:
1235 // Display the Boot Maintenance Manager
1237 BdsStartBootMaint ();
1241 } while ((Status
== EFI_SUCCESS
) && (gCallbackKey
!= FRONT_PAGE_KEY_CONTINUE
));
1243 if (mLanguageString
!= NULL
) {
1244 FreePool (mLanguageString
);
1245 mLanguageString
= NULL
;
1248 //Will leave browser, check any reset required change is applied? if yes, reset system
1250 SetupResetReminder ();
1253 // Remove the installed BootMaint HiiPackages when exit.
1259 // Automatically load current entry
1260 // Note: The following lines of code only execute when Auto boot
1263 PERF_END (NULL
, "BdsTimeOut", "BDS", 0);
1267 This function will change video resolution and text mode
1268 according to defined setup mode or defined boot mode
1270 @param IsSetupMode Indicate mode is changed to setup mode or boot mode.
1272 @retval EFI_SUCCESS Mode is changed successfully.
1273 @retval Others Mode failed to be changed.
1282 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1283 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
1285 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
1289 UINT32 NewHorizontalResolution
;
1290 UINT32 NewVerticalResolution
;
1294 EFI_HANDLE
*HandleBuffer
;
1297 UINTN CurrentColumn
;
1304 // Get current video resolution and text mode
1306 Status
= gBS
->HandleProtocol (
1307 gST
->ConsoleOutHandle
,
1308 &gEfiGraphicsOutputProtocolGuid
,
1309 (VOID
**)&GraphicsOutput
1311 if (EFI_ERROR (Status
)) {
1312 GraphicsOutput
= NULL
;
1315 Status
= gBS
->HandleProtocol (
1316 gST
->ConsoleOutHandle
,
1317 &gEfiSimpleTextOutProtocolGuid
,
1318 (VOID
**)&SimpleTextOut
1320 if (EFI_ERROR (Status
)) {
1321 SimpleTextOut
= NULL
;
1324 if ((GraphicsOutput
== NULL
) || (SimpleTextOut
== NULL
)) {
1325 return EFI_UNSUPPORTED
;
1330 // The requried resolution and text mode is setup mode.
1332 NewHorizontalResolution
= mSetupHorizontalResolution
;
1333 NewVerticalResolution
= mSetupVerticalResolution
;
1334 NewColumns
= mSetupTextModeColumn
;
1335 NewRows
= mSetupTextModeRow
;
1338 // The required resolution and text mode is boot mode.
1340 NewHorizontalResolution
= mBootHorizontalResolution
;
1341 NewVerticalResolution
= mBootVerticalResolution
;
1342 NewColumns
= mBootTextModeColumn
;
1343 NewRows
= mBootTextModeRow
;
1346 if (GraphicsOutput
!= NULL
) {
1347 MaxGopMode
= GraphicsOutput
->Mode
->MaxMode
;
1350 if (SimpleTextOut
!= NULL
) {
1351 MaxTextMode
= SimpleTextOut
->Mode
->MaxMode
;
1355 // 1. If current video resolution is same with required video resolution,
1356 // video resolution need not be changed.
1357 // 1.1. If current text mode is same with required text mode, text mode need not be changed.
1358 // 1.2. If current text mode is different from required text mode, text mode need be changed.
1359 // 2. If current video resolution is different from required video resolution, we need restart whole console drivers.
1361 for (ModeNumber
= 0; ModeNumber
< MaxGopMode
; ModeNumber
++) {
1362 Status
= GraphicsOutput
->QueryMode (
1368 if (!EFI_ERROR (Status
)) {
1369 if ((Info
->HorizontalResolution
== NewHorizontalResolution
) &&
1370 (Info
->VerticalResolution
== NewVerticalResolution
)) {
1371 if ((GraphicsOutput
->Mode
->Info
->HorizontalResolution
== NewHorizontalResolution
) &&
1372 (GraphicsOutput
->Mode
->Info
->VerticalResolution
== NewVerticalResolution
)) {
1374 // Current resolution is same with required resolution, check if text mode need be set
1376 Status
= SimpleTextOut
->QueryMode (SimpleTextOut
, SimpleTextOut
->Mode
->Mode
, &CurrentColumn
, &CurrentRow
);
1377 ASSERT_EFI_ERROR (Status
);
1378 if (CurrentColumn
== NewColumns
&& CurrentRow
== NewRows
) {
1380 // If current text mode is same with required text mode. Do nothing
1386 // If current text mode is different from requried text mode. Set new video mode
1388 for (Index
= 0; Index
< MaxTextMode
; Index
++) {
1389 Status
= SimpleTextOut
->QueryMode (SimpleTextOut
, Index
, &CurrentColumn
, &CurrentRow
);
1390 if (!EFI_ERROR(Status
)) {
1391 if ((CurrentColumn
== NewColumns
) && (CurrentRow
== NewRows
)) {
1393 // Required text mode is supported, set it.
1395 Status
= SimpleTextOut
->SetMode (SimpleTextOut
, Index
);
1396 ASSERT_EFI_ERROR (Status
);
1398 // Update text mode PCD.
1400 PcdSet32 (PcdConOutColumn
, mSetupTextModeColumn
);
1401 PcdSet32 (PcdConOutRow
, mSetupTextModeRow
);
1407 if (Index
== MaxTextMode
) {
1409 // If requried text mode is not supported, return error.
1412 return EFI_UNSUPPORTED
;
1417 // If current video resolution is not same with the new one, set new video resolution.
1418 // In this case, the driver which produces simple text out need be restarted.
1420 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, ModeNumber
);
1421 if (!EFI_ERROR (Status
)) {
1431 if (ModeNumber
== MaxGopMode
) {
1433 // If the resolution is not supported, return error.
1435 return EFI_UNSUPPORTED
;
1439 // Set PCD to Inform GraphicsConsole to change video resolution.
1440 // Set PCD to Inform Consplitter to change text mode.
1442 PcdSet32 (PcdVideoHorizontalResolution
, NewHorizontalResolution
);
1443 PcdSet32 (PcdVideoVerticalResolution
, NewVerticalResolution
);
1444 PcdSet32 (PcdConOutColumn
, NewColumns
);
1445 PcdSet32 (PcdConOutRow
, NewRows
);
1449 // Video mode is changed, so restart graphics console driver and higher level driver.
1450 // Reconnect graphics console driver and higher level driver.
1451 // Locate all the handles with GOP protocol and reconnect it.
1453 Status
= gBS
->LocateHandleBuffer (
1455 &gEfiSimpleTextOutProtocolGuid
,
1460 if (!EFI_ERROR (Status
)) {
1461 for (Index
= 0; Index
< HandleCount
; Index
++) {
1462 gBS
->DisconnectController (HandleBuffer
[Index
], NULL
, NULL
);
1464 for (Index
= 0; Index
< HandleCount
; Index
++) {
1465 gBS
->ConnectController (HandleBuffer
[Index
], NULL
, NULL
, TRUE
);
1467 if (HandleBuffer
!= NULL
) {
1468 FreePool (HandleBuffer
);