2 FrontPage routines to handle the callbacks and browser calls
4 Copyright (c) 2004 - 2011, 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 mSetupModeInitialized
= FALSE
;
21 UINT32 mSetupTextModeColumn
;
22 UINT32 mSetupTextModeRow
;
23 UINT32 mSetupHorizontalResolution
;
24 UINT32 mSetupVerticalResolution
;
26 BOOLEAN gConnectAllHappened
= FALSE
;
29 EFI_FORM_BROWSER2_PROTOCOL
*gFormBrowser2
;
31 FRONT_PAGE_CALLBACK_DATA gFrontPagePrivate
= {
32 FRONT_PAGE_CALLBACK_DATA_SIGNATURE
,
43 HII_VENDOR_DEVICE_PATH mFrontPageHiiVendorDevicePath
= {
49 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
50 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
53 FRONT_PAGE_FORMSET_GUID
57 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
59 (UINT8
) (END_DEVICE_PATH_LENGTH
),
60 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
66 This function allows a caller to extract the current configuration for one
67 or more named elements from the target driver.
70 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
71 @param Request A null-terminated Unicode string in <ConfigRequest> format.
72 @param Progress On return, points to a character in the Request string.
73 Points to the string's null terminator if request was successful.
74 Points to the most recent '&' before the first failing name/value
75 pair (or the beginning of the string if the failure is in the
76 first name/value pair) if the request was not successful.
77 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
78 has all values filled in for the names in the Request string.
79 String to be allocated by the called function.
81 @retval EFI_SUCCESS The Results is filled with the requested values.
82 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
83 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
84 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
90 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
91 IN CONST EFI_STRING Request
,
92 OUT EFI_STRING
*Progress
,
93 OUT EFI_STRING
*Results
96 if (Progress
== NULL
|| Results
== NULL
) {
97 return EFI_INVALID_PARAMETER
;
100 return EFI_NOT_FOUND
;
104 This function processes the results of changes in configuration.
107 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
108 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
109 @param Progress A pointer to a string filled in with the offset of the most
110 recent '&' before the first failing name/value pair (or the
111 beginning of the string if the failure is in the first
112 name/value pair) or the terminating NULL if all was successful.
114 @retval EFI_SUCCESS The Results is processed successfully.
115 @retval EFI_INVALID_PARAMETER Configuration is NULL.
116 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
122 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
123 IN CONST EFI_STRING Configuration
,
124 OUT EFI_STRING
*Progress
127 if (Configuration
== NULL
|| Progress
== NULL
) {
128 return EFI_INVALID_PARAMETER
;
131 *Progress
= Configuration
;
132 if (!HiiIsConfigHdrMatch (Configuration
, &gBootMaintFormSetGuid
, mBootMaintStorageName
)
133 && !HiiIsConfigHdrMatch (Configuration
, &gFileExploreFormSetGuid
, mFileExplorerStorageName
)) {
134 return EFI_NOT_FOUND
;
137 *Progress
= Configuration
+ StrLen (Configuration
);
142 This function processes the results of changes in configuration.
145 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
146 @param Action Specifies the type of action taken by the browser.
147 @param QuestionId A unique value which is sent to the original exporting driver
148 so that it can identify the type of data to expect.
149 @param Type The type of value for the question.
150 @param Value A pointer to the data being sent to the original exporting driver.
151 @param ActionRequest On return, points to the action requested by the callback function.
153 @retval EFI_SUCCESS The callback successfully handled the action.
154 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
155 @retval EFI_DEVICE_ERROR The variable could not be saved.
156 @retval EFI_UNSUPPORTED The specified Action is not supported by the callback.
162 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
163 IN EFI_BROWSER_ACTION Action
,
164 IN EFI_QUESTION_ID QuestionId
,
166 IN EFI_IFR_TYPE_VALUE
*Value
,
167 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
170 CHAR8
*LanguageString
;
175 CHAR8
*PlatformSupportedLanguages
;
178 if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
179 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
180 return EFI_INVALID_PARAMETER
;
183 gCallbackKey
= QuestionId
;
186 // The first 4 entries in the Front Page are to be GUARANTEED to remain constant so IHV's can
187 // describe to their customers in documentation how to find their setup information (namely
188 // under the device manager and specific buckets)
190 switch (QuestionId
) {
191 case FRONT_PAGE_KEY_CONTINUE
:
193 // This is the continue - clear the screen and return an error to get out of FrontPage loop
197 case FRONT_PAGE_KEY_LANGUAGE
:
199 // Collect the languages from what our current Language support is based on our VFR
201 LanguageString
= HiiGetSupportedLanguages (gFrontPagePrivate
.HiiHandle
);
202 ASSERT (LanguageString
!= NULL
);
204 // Allocate working buffer for RFC 4646 language in supported LanguageString.
206 Lang
= AllocatePool (AsciiStrSize (LanguageString
));
207 ASSERT (Lang
!= NULL
);
210 LangCode
= LanguageString
;
211 while (*LangCode
!= 0) {
212 GetNextLanguage (&LangCode
, Lang
);
214 if (Index
== Value
->u8
) {
221 PlatformSupportedLanguages
= GetEfiGlobalVariable (L
"PlatformLangCodes");
222 if (PlatformSupportedLanguages
== NULL
) {
223 PlatformSupportedLanguages
= AllocateCopyPool (
224 AsciiStrSize ((CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLangCodes
)),
225 (CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLangCodes
)
227 ASSERT (PlatformSupportedLanguages
!= NULL
);
231 // Select the best language in platform supported Language.
233 BestLanguage
= GetBestLanguage (
234 PlatformSupportedLanguages
,
239 if (BestLanguage
!= NULL
) {
240 Status
= gRT
->SetVariable (
242 &gEfiGlobalVariableGuid
,
243 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
244 AsciiStrSize (BestLanguage
),
247 ASSERT_EFI_ERROR(Status
);
248 FreePool (BestLanguage
);
253 FreePool (PlatformSupportedLanguages
);
255 FreePool (LanguageString
);
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
281 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
287 // All other action return unsupported.
289 return EFI_UNSUPPORTED
;
293 Initialize HII information for the FrontPage
296 @param InitializeHiiData TRUE if HII elements need to be initialized.
298 @retval EFI_SUCCESS The operation is successful.
299 @retval EFI_DEVICE_ERROR If the dynamic opcode creation failed.
303 InitializeFrontPage (
304 IN BOOLEAN InitializeHiiData
308 CHAR8
*LanguageString
;
314 CHAR16
*StringBuffer
;
315 EFI_HII_HANDLE HiiHandle
;
316 VOID
*OptionsOpCodeHandle
;
317 VOID
*StartOpCodeHandle
;
318 VOID
*EndOpCodeHandle
;
319 EFI_IFR_GUID_LABEL
*StartLabel
;
320 EFI_IFR_GUID_LABEL
*EndLabel
;
323 if (InitializeHiiData
) {
325 // Initialize the Device Manager
327 InitializeDeviceManager ();
330 // Initialize the Device Manager
332 InitializeBootManager ();
337 // Locate Hii relative protocols
339 Status
= gBS
->LocateProtocol (&gEfiFormBrowser2ProtocolGuid
, NULL
, (VOID
**) &gFormBrowser2
);
340 if (EFI_ERROR (Status
)) {
345 // Install Device Path Protocol and Config Access protocol to driver handle
347 Status
= gBS
->InstallMultipleProtocolInterfaces (
348 &gFrontPagePrivate
.DriverHandle
,
349 &gEfiDevicePathProtocolGuid
,
350 &mFrontPageHiiVendorDevicePath
,
351 &gEfiHiiConfigAccessProtocolGuid
,
352 &gFrontPagePrivate
.ConfigAccess
,
355 ASSERT_EFI_ERROR (Status
);
358 // Publish our HII data
360 gFrontPagePrivate
.HiiHandle
= HiiAddPackages (
361 &gFrontPageFormSetGuid
,
362 gFrontPagePrivate
.DriverHandle
,
367 if (gFrontPagePrivate
.HiiHandle
== NULL
) {
368 return EFI_OUT_OF_RESOURCES
;
374 // Init OpCode Handle and Allocate space for creation of UpdateData Buffer
376 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
377 ASSERT (StartOpCodeHandle
!= NULL
);
379 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
380 ASSERT (EndOpCodeHandle
!= NULL
);
382 OptionsOpCodeHandle
= HiiAllocateOpCodeHandle ();
383 ASSERT (OptionsOpCodeHandle
!= NULL
);
385 // Create Hii Extend Label OpCode as the start opcode
387 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
388 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
389 StartLabel
->Number
= LABEL_SELECT_LANGUAGE
;
392 // Create Hii Extend Label OpCode as the end opcode
394 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
395 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
396 EndLabel
->Number
= LABEL_END
;
399 // Collect the languages from what our current Language support is based on our VFR
401 HiiHandle
= gFrontPagePrivate
.HiiHandle
;
402 LanguageString
= HiiGetSupportedLanguages (HiiHandle
);
403 ASSERT (LanguageString
!= NULL
);
405 // Allocate working buffer for RFC 4646 language in supported LanguageString.
407 Lang
= AllocatePool (AsciiStrSize (LanguageString
));
408 ASSERT (Lang
!= NULL
);
410 CurrentLang
= GetEfiGlobalVariable (L
"PlatformLang");
412 // Select the best language in LanguageString as the default one.
414 BestLanguage
= GetBestLanguage (
417 (CurrentLang
!= NULL
) ? CurrentLang
: "",
418 (CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLang
),
423 // BestLanguage must be selected as it is the first language in LanguageString by default
425 ASSERT (BestLanguage
!= NULL
);
428 LangCode
= LanguageString
;
431 if (gFrontPagePrivate
.LanguageToken
== NULL
) {
432 while (*LangCode
!= 0) {
433 GetNextLanguage (&LangCode
, Lang
);
436 gFrontPagePrivate
.LanguageToken
= AllocatePool (OptionCount
* sizeof (EFI_STRING_ID
));
437 ASSERT (gFrontPagePrivate
.LanguageToken
!= NULL
);
442 LangCode
= LanguageString
;
443 while (*LangCode
!= 0) {
444 GetNextLanguage (&LangCode
, Lang
);
447 StringBuffer
= HiiGetString (HiiHandle
, PRINTABLE_LANGUAGE_NAME_STRING_ID
, Lang
);
448 ASSERT (StringBuffer
!= NULL
);
451 // Save the string Id for each language
453 gFrontPagePrivate
.LanguageToken
[OptionCount
] = HiiSetString (HiiHandle
, 0, StringBuffer
, NULL
);
454 FreePool (StringBuffer
);
457 if (AsciiStrCmp (Lang
, BestLanguage
) == 0) {
458 HiiCreateOneOfOptionOpCode (
460 gFrontPagePrivate
.LanguageToken
[OptionCount
],
461 EFI_IFR_OPTION_DEFAULT
,
462 EFI_IFR_NUMERIC_SIZE_1
,
466 HiiCreateOneOfOptionOpCode (
468 gFrontPagePrivate
.LanguageToken
[OptionCount
],
470 EFI_IFR_NUMERIC_SIZE_1
,
478 if (CurrentLang
!= NULL
) {
479 FreePool (CurrentLang
);
481 FreePool (BestLanguage
);
483 FreePool (LanguageString
);
485 HiiCreateOneOfOpCode (
487 FRONT_PAGE_KEY_LANGUAGE
,
490 STRING_TOKEN (STR_LANGUAGE_SELECT
),
491 STRING_TOKEN (STR_LANGUAGE_SELECT_HELP
),
492 EFI_IFR_FLAG_CALLBACK
,
493 EFI_IFR_NUMERIC_SIZE_1
,
498 Status
= HiiUpdateForm (
500 &gFrontPageFormSetGuid
,
502 StartOpCodeHandle
, // LABEL_SELECT_LANGUAGE
503 EndOpCodeHandle
// LABEL_END
506 HiiFreeOpCodeHandle (StartOpCodeHandle
);
507 HiiFreeOpCodeHandle (EndOpCodeHandle
);
508 HiiFreeOpCodeHandle (OptionsOpCodeHandle
);
513 Call the browser and display the front page
515 @return Status code that will be returned by
516 EFI_FORM_BROWSER2_PROTOCOL.SendForm ().
525 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
528 // Begin waiting for USER INPUT
532 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_PC_INPUT_WAIT
)
535 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
536 Status
= gFormBrowser2
->SendForm (
538 &gFrontPagePrivate
.HiiHandle
,
540 &gFrontPageFormSetGuid
,
546 // Check whether user change any option setting which needs a reset to be effective
548 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
549 EnableResetRequired ();
556 Acquire the string associated with the ProducerGuid and return it.
559 @param ProducerGuid The Guid to search the HII database for
560 @param Token The token value of the string to extract
561 @param String The string that is extracted
563 @retval EFI_SUCCESS The function returns EFI_SUCCESS always.
568 IN EFI_GUID
*ProducerGuid
,
569 IN EFI_STRING_ID Token
,
573 EFI_STRING TmpString
;
575 TmpString
= HiiGetPackageString (ProducerGuid
, Token
, NULL
);
576 if (TmpString
== NULL
) {
577 *String
= GetStringById (STRING_TOKEN (STR_MISSING_STRING
));
586 Convert Processor Frequency Data to a string.
588 @param ProcessorFrequency The frequency data to process
589 @param Base10Exponent The exponent based on 10
590 @param String The string that is created
594 ConvertProcessorToString (
595 IN UINT16 ProcessorFrequency
,
596 IN UINT16 Base10Exponent
,
600 CHAR16
*StringBuffer
;
604 if (Base10Exponent
>= 6) {
605 FreqMhz
= ProcessorFrequency
;
606 for (Index
= 0; Index
< (UINTN
) (Base10Exponent
- 6); Index
++) {
613 StringBuffer
= AllocateZeroPool (0x20);
614 ASSERT (StringBuffer
!= NULL
);
615 Index
= UnicodeValueToString (StringBuffer
, LEFT_JUSTIFY
, FreqMhz
/ 1000, 3);
616 StrCat (StringBuffer
, L
".");
617 UnicodeValueToString (StringBuffer
+ Index
+ 1, PREFIX_ZERO
, (FreqMhz
% 1000) / 10, 2);
618 StrCat (StringBuffer
, L
" GHz");
619 *String
= (CHAR16
*) StringBuffer
;
625 Convert Memory Size to a string.
627 @param MemorySize The size of the memory to process
628 @param String The string that is created
632 ConvertMemorySizeToString (
633 IN UINT32 MemorySize
,
637 CHAR16
*StringBuffer
;
639 StringBuffer
= AllocateZeroPool (0x20);
640 ASSERT (StringBuffer
!= NULL
);
641 UnicodeValueToString (StringBuffer
, LEFT_JUSTIFY
, MemorySize
, 6);
642 StrCat (StringBuffer
, L
" MB RAM");
644 *String
= (CHAR16
*) StringBuffer
;
651 Acquire the string associated with the Index from smbios structure and return it.
652 The caller is responsible for free the string buffer.
654 @param OptionalStrStart The start position to search the string
655 @param Index The index of the string to extract
656 @param String The string that is extracted
658 @retval EFI_SUCCESS The function returns EFI_SUCCESS always.
662 GetOptionalStringByIndex (
663 IN CHAR8
*OptionalStrStart
,
671 *String
= AllocateZeroPool (sizeof (CHAR16
));
678 OptionalStrStart
+= StrSize
;
679 StrSize
= AsciiStrSize (OptionalStrStart
);
680 } while (OptionalStrStart
[StrSize
] != 0 && Index
!= 0);
682 if ((Index
!= 0) || (StrSize
== 1)) {
684 // Meet the end of strings set but Index is non-zero, or
685 // Find an empty string
687 *String
= GetStringById (STRING_TOKEN (STR_MISSING_STRING
));
689 *String
= AllocatePool (StrSize
* sizeof (CHAR16
));
690 AsciiStrToUnicodeStr (OptionalStrStart
, *String
);
698 Update the banner information for the Front Page based on DataHub information.
702 UpdateFrontPageStrings (
710 EFI_STRING_ID TokenToUpdate
;
711 EFI_SMBIOS_HANDLE SmbiosHandle
;
712 EFI_SMBIOS_PROTOCOL
*Smbios
;
713 SMBIOS_TABLE_TYPE0
*Type0Record
;
714 SMBIOS_TABLE_TYPE1
*Type1Record
;
715 SMBIOS_TABLE_TYPE4
*Type4Record
;
716 SMBIOS_TABLE_TYPE19
*Type19Record
;
717 EFI_SMBIOS_TABLE_HEADER
*Record
;
719 ZeroMem (Find
, sizeof (Find
));
722 // Update Front Page strings
724 Status
= gBS
->LocateProtocol (
725 &gEfiSmbiosProtocolGuid
,
729 ASSERT_EFI_ERROR (Status
);
731 SmbiosHandle
= SMBIOS_HANDLE_PI_RESERVED
;
733 Status
= Smbios
->GetNext (Smbios
, &SmbiosHandle
, NULL
, &Record
, NULL
);
734 if (EFI_ERROR(Status
)) {
738 if (Record
->Type
== EFI_SMBIOS_TYPE_BIOS_INFORMATION
) {
739 Type0Record
= (SMBIOS_TABLE_TYPE0
*) Record
;
740 StrIndex
= Type0Record
->BiosVersion
;
741 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type0Record
+ Type0Record
->Hdr
.Length
), StrIndex
, &NewString
);
742 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION
);
743 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
744 FreePool (NewString
);
748 if (Record
->Type
== EFI_SMBIOS_TYPE_SYSTEM_INFORMATION
) {
749 Type1Record
= (SMBIOS_TABLE_TYPE1
*) Record
;
750 StrIndex
= Type1Record
->ProductName
;
751 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type1Record
+ Type1Record
->Hdr
.Length
), StrIndex
, &NewString
);
752 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_COMPUTER_MODEL
);
753 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
754 FreePool (NewString
);
758 if (Record
->Type
== EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION
) {
759 Type4Record
= (SMBIOS_TABLE_TYPE4
*) Record
;
760 StrIndex
= Type4Record
->ProcessorVersion
;
761 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type4Record
+ Type4Record
->Hdr
.Length
), StrIndex
, &NewString
);
762 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_CPU_MODEL
);
763 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
764 FreePool (NewString
);
768 if (Record
->Type
== EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION
) {
769 Type4Record
= (SMBIOS_TABLE_TYPE4
*) Record
;
770 ConvertProcessorToString(Type4Record
->CurrentSpeed
, 6, &NewString
);
771 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_CPU_SPEED
);
772 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
773 FreePool (NewString
);
777 if ( Record
->Type
== EFI_SMBIOS_TYPE_MEMORY_ARRAY_MAPPED_ADDRESS
) {
778 Type19Record
= (SMBIOS_TABLE_TYPE19
*) Record
;
779 ConvertMemorySizeToString (
780 (UINT32
)(RShiftU64((Type19Record
->EndingAddress
- Type19Record
->StartingAddress
+ 1), 10)),
783 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_MEMORY_SIZE
);
784 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
785 FreePool (NewString
);
788 } while ( !(Find
[0] && Find
[1] && Find
[2] && Find
[3] && Find
[4]));
794 Function waits for a given event to fire, or for an optional timeout to expire.
796 @param Event The event to wait for
797 @param Timeout An optional timeout value in 100 ns units.
799 @retval EFI_SUCCESS Event fired before Timeout expired.
800 @retval EFI_TIME_OUT Timout expired before Event fired..
806 IN UINT64 Timeout OPTIONAL
811 EFI_EVENT TimerEvent
;
812 EFI_EVENT WaitList
[2];
816 // Create a timer event
818 Status
= gBS
->CreateEvent (EVT_TIMER
, 0, NULL
, NULL
, &TimerEvent
);
819 if (!EFI_ERROR (Status
)) {
821 // Set the timer event
830 // Wait for the original event or the timer
833 WaitList
[1] = TimerEvent
;
834 Status
= gBS
->WaitForEvent (2, WaitList
, &Index
);
835 gBS
->CloseEvent (TimerEvent
);
838 // If the timer expired, change the return to timed out
840 if (!EFI_ERROR (Status
) && Index
== 1) {
841 Status
= EFI_TIMEOUT
;
846 // No timeout... just wait on the event
848 Status
= gBS
->WaitForEvent (1, &Event
, &Index
);
849 ASSERT (!EFI_ERROR (Status
));
857 Function show progress bar to wait for user input.
860 @param TimeoutDefault The fault time out value before the system continue to boot.
862 @retval EFI_SUCCESS User pressed some key except "Enter"
863 @retval EFI_TIME_OUT Timeout expired or user press "Enter"
868 IN UINT16 TimeoutDefault
872 UINT16 TimeoutRemain
;
875 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
876 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
877 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
879 if (TimeoutDefault
== 0) {
883 DEBUG ((EFI_D_INFO
, "\n\nStart showing progress bar... Press any key to stop it! ...Zzz....\n"));
885 SetMem (&Foreground
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
886 SetMem (&Background
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0x0);
887 SetMem (&Color
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
890 // Clear the progress status bar first
892 TmpStr
= GetStringById (STRING_TOKEN (STR_START_BOOT_OPTION
));
893 if (TmpStr
!= NULL
) {
894 PlatformBdsShowProgress (Foreground
, Background
, TmpStr
, Color
, 0, 0);
897 TimeoutRemain
= TimeoutDefault
;
898 while (TimeoutRemain
!= 0) {
899 DEBUG ((EFI_D_INFO
, "Showing progress bar...Remaining %d second!\n", TimeoutRemain
));
901 Status
= WaitForSingleEvent (gST
->ConIn
->WaitForKey
, ONE_SECOND
);
902 if (Status
!= EFI_TIMEOUT
) {
910 if (TmpStr
!= NULL
) {
911 PlatformBdsShowProgress (
916 ((TimeoutDefault
- TimeoutRemain
) * 100 / TimeoutDefault
),
921 gBS
->FreePool (TmpStr
);
926 if (TimeoutRemain
== 0) {
931 // User pressed some key
933 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
934 if (EFI_ERROR (Status
)) {
938 if (Key
.UnicodeChar
== CHAR_CARRIAGE_RETURN
) {
940 // User pressed enter, equivalent to select "continue"
949 This function will change video resolution and text mode for setup when setup is launched.
953 @retval EFI_SUCCESS Mode is changed successfully.
954 @retval Others Mode failed to changed.
963 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
964 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
966 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
971 EFI_HANDLE
*HandleBuffer
;
977 Status
= gBS
->HandleProtocol (
978 gST
->ConsoleOutHandle
,
979 &gEfiGraphicsOutputProtocolGuid
,
980 (VOID
**)&GraphicsOutput
982 if (EFI_ERROR (Status
)) {
983 GraphicsOutput
= NULL
;
986 Status
= gBS
->HandleProtocol (
987 gST
->ConsoleOutHandle
,
988 &gEfiSimpleTextOutProtocolGuid
,
989 (VOID
**)&SimpleTextOut
991 if (EFI_ERROR (Status
)) {
992 SimpleTextOut
= NULL
;
995 if ((GraphicsOutput
== NULL
) || (SimpleTextOut
== NULL
)) {
996 return EFI_UNSUPPORTED
;
1000 // Get user defined text mode for setup only once.
1002 if (!mSetupModeInitialized
) {
1003 mSetupHorizontalResolution
= PcdGet32 (PcdSetupVideoHorizontalResolution
);
1004 mSetupVerticalResolution
= PcdGet32 (PcdSetupVideoVerticalResolution
);
1005 mSetupTextModeColumn
= PcdGet32 (PcdSetupConOutColumn
);
1006 mSetupTextModeRow
= PcdGet32 (PcdSetupConOutRow
);
1007 mSetupModeInitialized
= TRUE
;
1010 MaxGopMode
= GraphicsOutput
->Mode
->MaxMode
;
1011 MaxTextMode
= SimpleTextOut
->Mode
->MaxMode
;
1014 // 1. If current video resolution is same with setup video resolution,
1015 // video resolution need not be changed.
1016 // 1.1. If current text mode is same with setup text mode, text mode need not be changed.
1017 // 1.2. If current text mode is different with setup text mode, text mode need be changed to setup text mode.
1018 // 2. If current video resolution is different with setup video resolution, we need restart whole console drivers.
1020 for (ModeNumber
= 0; ModeNumber
< MaxGopMode
; ModeNumber
++) {
1021 Status
= GraphicsOutput
->QueryMode (
1027 if (!EFI_ERROR (Status
)) {
1028 if ((Info
->HorizontalResolution
== mSetupHorizontalResolution
) &&
1029 (Info
->VerticalResolution
== mSetupVerticalResolution
)) {
1030 if ((GraphicsOutput
->Mode
->Info
->HorizontalResolution
== mSetupHorizontalResolution
) &&
1031 (GraphicsOutput
->Mode
->Info
->VerticalResolution
== mSetupVerticalResolution
)) {
1033 // If current video resolution is same with setup video resolution,
1034 // then check if current text mode is same with setup text mode.
1036 Status
= SimpleTextOut
->QueryMode (SimpleTextOut
, SimpleTextOut
->Mode
->Mode
, &CurrentColumn
, &CurrentRow
);
1037 ASSERT_EFI_ERROR (Status
);
1038 if (CurrentColumn
== mSetupTextModeColumn
&& CurrentRow
== mSetupTextModeRow
) {
1040 // Current text mode is same with setup text mode, text mode need not be change.
1046 // Current text mode is different with setup text mode, text mode need be change to new text mode.
1048 for (Index
= 0; Index
< MaxTextMode
; Index
++) {
1049 Status
= SimpleTextOut
->QueryMode (SimpleTextOut
, Index
, &CurrentColumn
, &CurrentRow
);
1050 if (!EFI_ERROR(Status
)) {
1051 if ((CurrentColumn
== mSetupTextModeColumn
) && (CurrentRow
== mSetupTextModeRow
)) {
1053 // setup text mode is supported, set it.
1055 Status
= SimpleTextOut
->SetMode (SimpleTextOut
, Index
);
1056 ASSERT_EFI_ERROR (Status
);
1058 // Update text mode PCD.
1060 PcdSet32 (PcdConOutColumn
, mSetupTextModeColumn
);
1061 PcdSet32 (PcdConOutRow
, mSetupTextModeRow
);
1067 if (Index
== MaxTextMode
) {
1069 // If setup text mode is not supported, return error.
1072 return EFI_UNSUPPORTED
;
1078 // If current video resolution is not same with the setup video resolution, set new video resolution.
1079 // In this case, the drivers which produce simple text out need be restarted.
1081 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, ModeNumber
);
1082 if (!EFI_ERROR (Status
)) {
1084 // Set PCD to restart GraphicsConsole and Consplitter to change video resolution
1085 // and produce new text mode based on new resolution.
1087 PcdSet32 (PcdVideoHorizontalResolution
, mSetupHorizontalResolution
);
1088 PcdSet32 (PcdVideoVerticalResolution
, mSetupVerticalResolution
);
1089 PcdSet32 (PcdConOutColumn
, mSetupTextModeColumn
);
1090 PcdSet32 (PcdConOutRow
, mSetupTextModeRow
);
1092 Status
= gBS
->LocateHandleBuffer (
1094 &gEfiSimpleTextOutProtocolGuid
,
1099 if (!EFI_ERROR (Status
)) {
1100 for (Index
= 0; Index
< HandleCount
; Index
++) {
1101 gBS
->DisconnectController (HandleBuffer
[Index
], NULL
, NULL
);
1103 for (Index
= 0; Index
< HandleCount
; Index
++) {
1104 gBS
->ConnectController (HandleBuffer
[Index
], NULL
, NULL
, TRUE
);
1106 if (HandleBuffer
!= NULL
) {
1107 FreePool (HandleBuffer
);
1118 if (ModeNumber
== MaxGopMode
) {
1120 // If the new resolution is not supported, return error.
1122 return EFI_UNSUPPORTED
;
1129 This function is the main entry of the platform setup entry.
1130 The function will present the main menu of the system setup,
1131 this is the platform reference part and can be customize.
1134 @param TimeoutDefault The fault time out value before the system
1136 @param ConnectAllHappened The indicater to check if the connect all have
1141 PlatformBdsEnterFrontPage (
1142 IN UINT16 TimeoutDefault
,
1143 IN BOOLEAN ConnectAllHappened
1147 EFI_BOOT_LOGO_PROTOCOL
*BootLogo
;
1149 PERF_START (NULL
, "BdsTimeOut", "BDS", 0);
1151 // Indicate if we need connect all in the platform setup
1153 if (ConnectAllHappened
) {
1154 gConnectAllHappened
= TRUE
;
1158 if (TimeoutDefault
!= 0xffff) {
1159 Status
= ShowProgress (TimeoutDefault
);
1163 // Ensure screen is clear when switch Console from Graphics mode to Text mode
1165 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
1166 gST
->ConOut
->ClearScreen (gST
->ConOut
);
1168 if (EFI_ERROR (Status
)) {
1170 // Timeout or user press enter to continue
1177 // Boot Logo is corrupted, report it using Boot Logo protocol.
1179 Status
= gBS
->LocateProtocol (&gEfiBootLogoProtocolGuid
, NULL
, (VOID
**) &BootLogo
);
1180 if (!EFI_ERROR (Status
) && (BootLogo
!= NULL
)) {
1181 BootLogo
->SetBootLogo (BootLogo
, NULL
, 0, 0, 0, 0);
1186 // Set proper video resolution and text mode for setup
1188 ChangeModeForSetup ();
1190 InitializeFrontPage (FALSE
);
1193 // Update Front Page strings
1195 UpdateFrontPageStrings ();
1198 Status
= CallFrontPage ();
1201 // If gCallbackKey is greater than 1 and less or equal to 5,
1202 // it will launch configuration utilities.
1205 // 4 = device manager
1206 // 5 = boot maintenance manager
1208 if (gCallbackKey
!= 0) {
1209 REPORT_STATUS_CODE (
1211 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_PC_USER_SETUP
)
1215 // Based on the key that was set, we can determine what to do
1217 switch (gCallbackKey
) {
1219 // The first 4 entries in the Front Page are to be GUARANTEED to remain constant so IHV's can
1220 // describe to their customers in documentation how to find their setup information (namely
1221 // under the device manager and specific buckets)
1223 // These entries consist of the Continue, Select language, Boot Manager, and Device Manager
1225 case FRONT_PAGE_KEY_CONTINUE
:
1227 // User hit continue
1231 case FRONT_PAGE_KEY_LANGUAGE
:
1233 // User made a language setting change - display front page again
1237 case FRONT_PAGE_KEY_BOOT_MANAGER
:
1239 // User chose to run the Boot Manager
1244 case FRONT_PAGE_KEY_DEVICE_MANAGER
:
1246 // Display the Device Manager
1249 CallDeviceManager ();
1250 } while (gCallbackKey
== FRONT_PAGE_KEY_DEVICE_MANAGER
);
1253 case FRONT_PAGE_KEY_BOOT_MAINTAIN
:
1255 // Display the Boot Maintenance Manager
1257 BdsStartBootMaint ();
1261 } while ((Status
== EFI_SUCCESS
) && (gCallbackKey
!= FRONT_PAGE_KEY_CONTINUE
));
1264 //Will leave browser, check any reset required change is applied? if yes, reset system
1266 SetupResetReminder ();
1270 // Automatically load current entry
1271 // Note: The following lines of code only execute when Auto boot
1274 PERF_END (NULL
, "BdsTimeOut", "BDS", 0);