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
&& Action
!= EFI_BROWSER_ACTION_CHANGED
) {
180 // All other action return unsupported.
182 return EFI_UNSUPPORTED
;
185 gCallbackKey
= QuestionId
;
187 if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
188 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
189 return EFI_INVALID_PARAMETER
;
192 switch (QuestionId
) {
193 case FRONT_PAGE_KEY_CONTINUE
:
195 // This is the continue - clear the screen and return an error to get out of FrontPage loop
197 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
200 case FRONT_PAGE_KEY_LANGUAGE
:
202 // Collect the languages from what our current Language support is based on our VFR
204 LanguageString
= HiiGetSupportedLanguages (gFrontPagePrivate
.HiiHandle
);
205 ASSERT (LanguageString
!= NULL
);
207 // Allocate working buffer for RFC 4646 language in supported LanguageString.
209 Lang
= AllocatePool (AsciiStrSize (LanguageString
));
210 ASSERT (Lang
!= NULL
);
213 LangCode
= LanguageString
;
214 while (*LangCode
!= 0) {
215 GetNextLanguage (&LangCode
, Lang
);
217 if (Index
== Value
->u8
) {
224 PlatformSupportedLanguages
= GetEfiGlobalVariable (L
"PlatformLangCodes");
225 if (PlatformSupportedLanguages
== NULL
) {
226 PlatformSupportedLanguages
= AllocateCopyPool (
227 AsciiStrSize ((CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLangCodes
)),
228 (CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLangCodes
)
230 ASSERT (PlatformSupportedLanguages
!= NULL
);
234 // Select the best language in platform supported Language.
236 BestLanguage
= GetBestLanguage (
237 PlatformSupportedLanguages
,
242 if (BestLanguage
!= NULL
) {
243 Status
= gRT
->SetVariable (
245 &gEfiGlobalVariableGuid
,
246 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
247 AsciiStrSize (BestLanguage
),
250 ASSERT_EFI_ERROR(Status
);
251 FreePool (BestLanguage
);
256 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
258 FreePool (PlatformSupportedLanguages
);
260 FreePool (LanguageString
);
266 } else if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
268 return EFI_INVALID_PARAMETER
;
272 // The first 4 entries in the Front Page are to be GUARANTEED to remain constant so IHV's can
273 // describe to their customers in documentation how to find their setup information (namely
274 // under the device manager and specific buckets)
276 switch (QuestionId
) {
277 case FRONT_PAGE_KEY_BOOT_MANAGER
:
283 case FRONT_PAGE_KEY_DEVICE_MANAGER
:
289 case FRONT_PAGE_KEY_BOOT_MAINTAIN
:
291 // Boot Maintenance Manager
305 Initialize HII information for the FrontPage
308 @param InitializeHiiData TRUE if HII elements need to be initialized.
310 @retval EFI_SUCCESS The operation is successful.
311 @retval EFI_DEVICE_ERROR If the dynamic opcode creation failed.
315 InitializeFrontPage (
316 IN BOOLEAN InitializeHiiData
320 CHAR8
*LanguageString
;
326 CHAR16
*StringBuffer
;
327 EFI_HII_HANDLE HiiHandle
;
328 VOID
*OptionsOpCodeHandle
;
329 VOID
*StartOpCodeHandle
;
330 VOID
*EndOpCodeHandle
;
331 EFI_IFR_GUID_LABEL
*StartLabel
;
332 EFI_IFR_GUID_LABEL
*EndLabel
;
335 if (InitializeHiiData
) {
337 // Initialize the Device Manager
339 InitializeDeviceManager ();
342 // Initialize the Device Manager
344 InitializeBootManager ();
349 // Locate Hii relative protocols
351 Status
= gBS
->LocateProtocol (&gEfiFormBrowser2ProtocolGuid
, NULL
, (VOID
**) &gFormBrowser2
);
352 if (EFI_ERROR (Status
)) {
357 // Install Device Path Protocol and Config Access protocol to driver handle
359 Status
= gBS
->InstallMultipleProtocolInterfaces (
360 &gFrontPagePrivate
.DriverHandle
,
361 &gEfiDevicePathProtocolGuid
,
362 &mFrontPageHiiVendorDevicePath
,
363 &gEfiHiiConfigAccessProtocolGuid
,
364 &gFrontPagePrivate
.ConfigAccess
,
367 ASSERT_EFI_ERROR (Status
);
370 // Publish our HII data
372 gFrontPagePrivate
.HiiHandle
= HiiAddPackages (
373 &gFrontPageFormSetGuid
,
374 gFrontPagePrivate
.DriverHandle
,
379 if (gFrontPagePrivate
.HiiHandle
== NULL
) {
380 return EFI_OUT_OF_RESOURCES
;
386 // Init OpCode Handle and Allocate space for creation of UpdateData Buffer
388 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
389 ASSERT (StartOpCodeHandle
!= NULL
);
391 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
392 ASSERT (EndOpCodeHandle
!= NULL
);
394 OptionsOpCodeHandle
= HiiAllocateOpCodeHandle ();
395 ASSERT (OptionsOpCodeHandle
!= NULL
);
397 // Create Hii Extend Label OpCode as the start opcode
399 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
400 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
401 StartLabel
->Number
= LABEL_SELECT_LANGUAGE
;
404 // Create Hii Extend Label OpCode as the end opcode
406 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
407 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
408 EndLabel
->Number
= LABEL_END
;
411 // Collect the languages from what our current Language support is based on our VFR
413 HiiHandle
= gFrontPagePrivate
.HiiHandle
;
414 LanguageString
= HiiGetSupportedLanguages (HiiHandle
);
415 ASSERT (LanguageString
!= NULL
);
417 // Allocate working buffer for RFC 4646 language in supported LanguageString.
419 Lang
= AllocatePool (AsciiStrSize (LanguageString
));
420 ASSERT (Lang
!= NULL
);
422 CurrentLang
= GetEfiGlobalVariable (L
"PlatformLang");
424 // Select the best language in LanguageString as the default one.
426 BestLanguage
= GetBestLanguage (
429 (CurrentLang
!= NULL
) ? CurrentLang
: "",
430 (CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLang
),
435 // BestLanguage must be selected as it is the first language in LanguageString by default
437 ASSERT (BestLanguage
!= NULL
);
440 LangCode
= LanguageString
;
443 if (gFrontPagePrivate
.LanguageToken
== NULL
) {
444 while (*LangCode
!= 0) {
445 GetNextLanguage (&LangCode
, Lang
);
448 gFrontPagePrivate
.LanguageToken
= AllocatePool (OptionCount
* sizeof (EFI_STRING_ID
));
449 ASSERT (gFrontPagePrivate
.LanguageToken
!= NULL
);
454 LangCode
= LanguageString
;
455 while (*LangCode
!= 0) {
456 GetNextLanguage (&LangCode
, Lang
);
459 StringBuffer
= HiiGetString (HiiHandle
, PRINTABLE_LANGUAGE_NAME_STRING_ID
, Lang
);
460 ASSERT (StringBuffer
!= NULL
);
463 // Save the string Id for each language
465 gFrontPagePrivate
.LanguageToken
[OptionCount
] = HiiSetString (HiiHandle
, 0, StringBuffer
, NULL
);
466 FreePool (StringBuffer
);
469 if (AsciiStrCmp (Lang
, BestLanguage
) == 0) {
470 HiiCreateOneOfOptionOpCode (
472 gFrontPagePrivate
.LanguageToken
[OptionCount
],
473 EFI_IFR_OPTION_DEFAULT
,
474 EFI_IFR_NUMERIC_SIZE_1
,
478 HiiCreateOneOfOptionOpCode (
480 gFrontPagePrivate
.LanguageToken
[OptionCount
],
482 EFI_IFR_NUMERIC_SIZE_1
,
490 if (CurrentLang
!= NULL
) {
491 FreePool (CurrentLang
);
493 FreePool (BestLanguage
);
495 FreePool (LanguageString
);
497 HiiCreateOneOfOpCode (
499 FRONT_PAGE_KEY_LANGUAGE
,
502 STRING_TOKEN (STR_LANGUAGE_SELECT
),
503 STRING_TOKEN (STR_LANGUAGE_SELECT_HELP
),
504 EFI_IFR_FLAG_CALLBACK
,
505 EFI_IFR_NUMERIC_SIZE_1
,
510 Status
= HiiUpdateForm (
512 &gFrontPageFormSetGuid
,
514 StartOpCodeHandle
, // LABEL_SELECT_LANGUAGE
515 EndOpCodeHandle
// LABEL_END
518 HiiFreeOpCodeHandle (StartOpCodeHandle
);
519 HiiFreeOpCodeHandle (EndOpCodeHandle
);
520 HiiFreeOpCodeHandle (OptionsOpCodeHandle
);
525 Call the browser and display the front page
527 @return Status code that will be returned by
528 EFI_FORM_BROWSER2_PROTOCOL.SendForm ().
537 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
540 // Begin waiting for USER INPUT
544 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_PC_INPUT_WAIT
)
547 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
548 Status
= gFormBrowser2
->SendForm (
550 &gFrontPagePrivate
.HiiHandle
,
552 &gFrontPageFormSetGuid
,
558 // Check whether user change any option setting which needs a reset to be effective
560 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
561 EnableResetRequired ();
568 Acquire the string associated with the ProducerGuid and return it.
571 @param ProducerGuid The Guid to search the HII database for
572 @param Token The token value of the string to extract
573 @param String The string that is extracted
575 @retval EFI_SUCCESS The function returns EFI_SUCCESS always.
580 IN EFI_GUID
*ProducerGuid
,
581 IN EFI_STRING_ID Token
,
585 EFI_STRING TmpString
;
587 TmpString
= HiiGetPackageString (ProducerGuid
, Token
, NULL
);
588 if (TmpString
== NULL
) {
589 *String
= GetStringById (STRING_TOKEN (STR_MISSING_STRING
));
598 Convert Processor Frequency Data to a string.
600 @param ProcessorFrequency The frequency data to process
601 @param Base10Exponent The exponent based on 10
602 @param String The string that is created
606 ConvertProcessorToString (
607 IN UINT16 ProcessorFrequency
,
608 IN UINT16 Base10Exponent
,
612 CHAR16
*StringBuffer
;
616 if (Base10Exponent
>= 6) {
617 FreqMhz
= ProcessorFrequency
;
618 for (Index
= 0; Index
< (UINTN
) (Base10Exponent
- 6); Index
++) {
625 StringBuffer
= AllocateZeroPool (0x20);
626 ASSERT (StringBuffer
!= NULL
);
627 Index
= UnicodeValueToString (StringBuffer
, LEFT_JUSTIFY
, FreqMhz
/ 1000, 3);
628 StrCat (StringBuffer
, L
".");
629 UnicodeValueToString (StringBuffer
+ Index
+ 1, PREFIX_ZERO
, (FreqMhz
% 1000) / 10, 2);
630 StrCat (StringBuffer
, L
" GHz");
631 *String
= (CHAR16
*) StringBuffer
;
637 Convert Memory Size to a string.
639 @param MemorySize The size of the memory to process
640 @param String The string that is created
644 ConvertMemorySizeToString (
645 IN UINT32 MemorySize
,
649 CHAR16
*StringBuffer
;
651 StringBuffer
= AllocateZeroPool (0x20);
652 ASSERT (StringBuffer
!= NULL
);
653 UnicodeValueToString (StringBuffer
, LEFT_JUSTIFY
, MemorySize
, 6);
654 StrCat (StringBuffer
, L
" MB RAM");
656 *String
= (CHAR16
*) StringBuffer
;
663 Acquire the string associated with the Index from smbios structure and return it.
664 The caller is responsible for free the string buffer.
666 @param OptionalStrStart The start position to search the string
667 @param Index The index of the string to extract
668 @param String The string that is extracted
670 @retval EFI_SUCCESS The function returns EFI_SUCCESS always.
674 GetOptionalStringByIndex (
675 IN CHAR8
*OptionalStrStart
,
683 *String
= AllocateZeroPool (sizeof (CHAR16
));
690 OptionalStrStart
+= StrSize
;
691 StrSize
= AsciiStrSize (OptionalStrStart
);
692 } while (OptionalStrStart
[StrSize
] != 0 && Index
!= 0);
694 if ((Index
!= 0) || (StrSize
== 1)) {
696 // Meet the end of strings set but Index is non-zero, or
697 // Find an empty string
699 *String
= GetStringById (STRING_TOKEN (STR_MISSING_STRING
));
701 *String
= AllocatePool (StrSize
* sizeof (CHAR16
));
702 AsciiStrToUnicodeStr (OptionalStrStart
, *String
);
710 Update the banner information for the Front Page based on DataHub information.
714 UpdateFrontPageStrings (
722 EFI_STRING_ID TokenToUpdate
;
723 EFI_SMBIOS_HANDLE SmbiosHandle
;
724 EFI_SMBIOS_PROTOCOL
*Smbios
;
725 SMBIOS_TABLE_TYPE0
*Type0Record
;
726 SMBIOS_TABLE_TYPE1
*Type1Record
;
727 SMBIOS_TABLE_TYPE4
*Type4Record
;
728 SMBIOS_TABLE_TYPE19
*Type19Record
;
729 EFI_SMBIOS_TABLE_HEADER
*Record
;
731 ZeroMem (Find
, sizeof (Find
));
734 // Update Front Page strings
736 Status
= gBS
->LocateProtocol (
737 &gEfiSmbiosProtocolGuid
,
741 ASSERT_EFI_ERROR (Status
);
743 SmbiosHandle
= SMBIOS_HANDLE_PI_RESERVED
;
745 Status
= Smbios
->GetNext (Smbios
, &SmbiosHandle
, NULL
, &Record
, NULL
);
746 if (EFI_ERROR(Status
)) {
750 if (Record
->Type
== EFI_SMBIOS_TYPE_BIOS_INFORMATION
) {
751 Type0Record
= (SMBIOS_TABLE_TYPE0
*) Record
;
752 StrIndex
= Type0Record
->BiosVersion
;
753 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type0Record
+ Type0Record
->Hdr
.Length
), StrIndex
, &NewString
);
754 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION
);
755 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
756 FreePool (NewString
);
760 if (Record
->Type
== EFI_SMBIOS_TYPE_SYSTEM_INFORMATION
) {
761 Type1Record
= (SMBIOS_TABLE_TYPE1
*) Record
;
762 StrIndex
= Type1Record
->ProductName
;
763 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type1Record
+ Type1Record
->Hdr
.Length
), StrIndex
, &NewString
);
764 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_COMPUTER_MODEL
);
765 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
766 FreePool (NewString
);
770 if (Record
->Type
== EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION
) {
771 Type4Record
= (SMBIOS_TABLE_TYPE4
*) Record
;
772 StrIndex
= Type4Record
->ProcessorVersion
;
773 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type4Record
+ Type4Record
->Hdr
.Length
), StrIndex
, &NewString
);
774 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_CPU_MODEL
);
775 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
776 FreePool (NewString
);
780 if (Record
->Type
== EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION
) {
781 Type4Record
= (SMBIOS_TABLE_TYPE4
*) Record
;
782 ConvertProcessorToString(Type4Record
->CurrentSpeed
, 6, &NewString
);
783 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_CPU_SPEED
);
784 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
785 FreePool (NewString
);
789 if ( Record
->Type
== EFI_SMBIOS_TYPE_MEMORY_ARRAY_MAPPED_ADDRESS
) {
790 Type19Record
= (SMBIOS_TABLE_TYPE19
*) Record
;
791 ConvertMemorySizeToString (
792 (UINT32
)(RShiftU64((Type19Record
->EndingAddress
- Type19Record
->StartingAddress
+ 1), 10)),
795 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_MEMORY_SIZE
);
796 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
797 FreePool (NewString
);
800 } while ( !(Find
[0] && Find
[1] && Find
[2] && Find
[3] && Find
[4]));
806 Function waits for a given event to fire, or for an optional timeout to expire.
808 @param Event The event to wait for
809 @param Timeout An optional timeout value in 100 ns units.
811 @retval EFI_SUCCESS Event fired before Timeout expired.
812 @retval EFI_TIME_OUT Timout expired before Event fired..
818 IN UINT64 Timeout OPTIONAL
823 EFI_EVENT TimerEvent
;
824 EFI_EVENT WaitList
[2];
828 // Create a timer event
830 Status
= gBS
->CreateEvent (EVT_TIMER
, 0, NULL
, NULL
, &TimerEvent
);
831 if (!EFI_ERROR (Status
)) {
833 // Set the timer event
842 // Wait for the original event or the timer
845 WaitList
[1] = TimerEvent
;
846 Status
= gBS
->WaitForEvent (2, WaitList
, &Index
);
847 gBS
->CloseEvent (TimerEvent
);
850 // If the timer expired, change the return to timed out
852 if (!EFI_ERROR (Status
) && Index
== 1) {
853 Status
= EFI_TIMEOUT
;
858 // No timeout... just wait on the event
860 Status
= gBS
->WaitForEvent (1, &Event
, &Index
);
861 ASSERT (!EFI_ERROR (Status
));
869 Function show progress bar to wait for user input.
872 @param TimeoutDefault The fault time out value before the system continue to boot.
874 @retval EFI_SUCCESS User pressed some key except "Enter"
875 @retval EFI_TIME_OUT Timeout expired or user press "Enter"
880 IN UINT16 TimeoutDefault
884 UINT16 TimeoutRemain
;
887 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
888 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
889 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
891 if (TimeoutDefault
== 0) {
895 DEBUG ((EFI_D_INFO
, "\n\nStart showing progress bar... Press any key to stop it! ...Zzz....\n"));
897 SetMem (&Foreground
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
898 SetMem (&Background
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0x0);
899 SetMem (&Color
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
902 // Clear the progress status bar first
904 TmpStr
= GetStringById (STRING_TOKEN (STR_START_BOOT_OPTION
));
905 if (TmpStr
!= NULL
) {
906 PlatformBdsShowProgress (Foreground
, Background
, TmpStr
, Color
, 0, 0);
909 TimeoutRemain
= TimeoutDefault
;
910 while (TimeoutRemain
!= 0) {
911 DEBUG ((EFI_D_INFO
, "Showing progress bar...Remaining %d second!\n", TimeoutRemain
));
913 Status
= WaitForSingleEvent (gST
->ConIn
->WaitForKey
, ONE_SECOND
);
914 if (Status
!= EFI_TIMEOUT
) {
922 if (TmpStr
!= NULL
) {
923 PlatformBdsShowProgress (
928 ((TimeoutDefault
- TimeoutRemain
) * 100 / TimeoutDefault
),
933 gBS
->FreePool (TmpStr
);
938 if (TimeoutRemain
== 0) {
943 // User pressed some key
945 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
946 if (EFI_ERROR (Status
)) {
950 if (Key
.UnicodeChar
== CHAR_CARRIAGE_RETURN
) {
952 // User pressed enter, equivalent to select "continue"
961 This function will change video resolution and text mode for setup when setup is launched.
965 @retval EFI_SUCCESS Mode is changed successfully.
966 @retval Others Mode failed to changed.
975 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
976 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
978 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
983 EFI_HANDLE
*HandleBuffer
;
989 Status
= gBS
->HandleProtocol (
990 gST
->ConsoleOutHandle
,
991 &gEfiGraphicsOutputProtocolGuid
,
992 (VOID
**)&GraphicsOutput
994 if (EFI_ERROR (Status
)) {
995 GraphicsOutput
= NULL
;
998 Status
= gBS
->HandleProtocol (
999 gST
->ConsoleOutHandle
,
1000 &gEfiSimpleTextOutProtocolGuid
,
1001 (VOID
**)&SimpleTextOut
1003 if (EFI_ERROR (Status
)) {
1004 SimpleTextOut
= NULL
;
1007 if ((GraphicsOutput
== NULL
) || (SimpleTextOut
== NULL
)) {
1008 return EFI_UNSUPPORTED
;
1012 // Get user defined text mode for setup only once.
1014 if (!mSetupModeInitialized
) {
1015 mSetupHorizontalResolution
= PcdGet32 (PcdSetupVideoHorizontalResolution
);
1016 mSetupVerticalResolution
= PcdGet32 (PcdSetupVideoVerticalResolution
);
1017 mSetupTextModeColumn
= PcdGet32 (PcdSetupConOutColumn
);
1018 mSetupTextModeRow
= PcdGet32 (PcdSetupConOutRow
);
1019 mSetupModeInitialized
= TRUE
;
1022 MaxGopMode
= GraphicsOutput
->Mode
->MaxMode
;
1023 MaxTextMode
= SimpleTextOut
->Mode
->MaxMode
;
1026 // 1. If current video resolution is same with setup video resolution,
1027 // video resolution need not be changed.
1028 // 1.1. If current text mode is same with setup text mode, text mode need not be changed.
1029 // 1.2. If current text mode is different with setup text mode, text mode need be changed to setup text mode.
1030 // 2. If current video resolution is different with setup video resolution, we need restart whole console drivers.
1032 for (ModeNumber
= 0; ModeNumber
< MaxGopMode
; ModeNumber
++) {
1033 Status
= GraphicsOutput
->QueryMode (
1039 if (!EFI_ERROR (Status
)) {
1040 if ((Info
->HorizontalResolution
== mSetupHorizontalResolution
) &&
1041 (Info
->VerticalResolution
== mSetupVerticalResolution
)) {
1042 if ((GraphicsOutput
->Mode
->Info
->HorizontalResolution
== mSetupHorizontalResolution
) &&
1043 (GraphicsOutput
->Mode
->Info
->VerticalResolution
== mSetupVerticalResolution
)) {
1045 // If current video resolution is same with setup video resolution,
1046 // then check if current text mode is same with setup text mode.
1048 Status
= SimpleTextOut
->QueryMode (SimpleTextOut
, SimpleTextOut
->Mode
->Mode
, &CurrentColumn
, &CurrentRow
);
1049 ASSERT_EFI_ERROR (Status
);
1050 if (CurrentColumn
== mSetupTextModeColumn
&& CurrentRow
== mSetupTextModeRow
) {
1052 // Current text mode is same with setup text mode, text mode need not be change.
1058 // Current text mode is different with setup text mode, text mode need be change to new text mode.
1060 for (Index
= 0; Index
< MaxTextMode
; Index
++) {
1061 Status
= SimpleTextOut
->QueryMode (SimpleTextOut
, Index
, &CurrentColumn
, &CurrentRow
);
1062 if (!EFI_ERROR(Status
)) {
1063 if ((CurrentColumn
== mSetupTextModeColumn
) && (CurrentRow
== mSetupTextModeRow
)) {
1065 // setup text mode is supported, set it.
1067 Status
= SimpleTextOut
->SetMode (SimpleTextOut
, Index
);
1068 ASSERT_EFI_ERROR (Status
);
1070 // Update text mode PCD.
1072 PcdSet32 (PcdConOutColumn
, mSetupTextModeColumn
);
1073 PcdSet32 (PcdConOutRow
, mSetupTextModeRow
);
1079 if (Index
== MaxTextMode
) {
1081 // If setup text mode is not supported, return error.
1084 return EFI_UNSUPPORTED
;
1090 // If current video resolution is not same with the setup video resolution, set new video resolution.
1091 // In this case, the drivers which produce simple text out need be restarted.
1093 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, ModeNumber
);
1094 if (!EFI_ERROR (Status
)) {
1096 // Set PCD to restart GraphicsConsole and Consplitter to change video resolution
1097 // and produce new text mode based on new resolution.
1099 PcdSet32 (PcdVideoHorizontalResolution
, mSetupHorizontalResolution
);
1100 PcdSet32 (PcdVideoVerticalResolution
, mSetupVerticalResolution
);
1101 PcdSet32 (PcdConOutColumn
, mSetupTextModeColumn
);
1102 PcdSet32 (PcdConOutRow
, mSetupTextModeRow
);
1104 Status
= gBS
->LocateHandleBuffer (
1106 &gEfiSimpleTextOutProtocolGuid
,
1111 if (!EFI_ERROR (Status
)) {
1112 for (Index
= 0; Index
< HandleCount
; Index
++) {
1113 gBS
->DisconnectController (HandleBuffer
[Index
], NULL
, NULL
);
1115 for (Index
= 0; Index
< HandleCount
; Index
++) {
1116 gBS
->ConnectController (HandleBuffer
[Index
], NULL
, NULL
, TRUE
);
1118 if (HandleBuffer
!= NULL
) {
1119 FreePool (HandleBuffer
);
1130 if (ModeNumber
== MaxGopMode
) {
1132 // If the new resolution is not supported, return error.
1134 return EFI_UNSUPPORTED
;
1141 This function is the main entry of the platform setup entry.
1142 The function will present the main menu of the system setup,
1143 this is the platform reference part and can be customize.
1146 @param TimeoutDefault The fault time out value before the system
1148 @param ConnectAllHappened The indicater to check if the connect all have
1153 PlatformBdsEnterFrontPage (
1154 IN UINT16 TimeoutDefault
,
1155 IN BOOLEAN ConnectAllHappened
1159 EFI_BOOT_LOGO_PROTOCOL
*BootLogo
;
1161 PERF_START (NULL
, "BdsTimeOut", "BDS", 0);
1163 // Indicate if we need connect all in the platform setup
1165 if (ConnectAllHappened
) {
1166 gConnectAllHappened
= TRUE
;
1170 if (TimeoutDefault
!= 0xffff) {
1171 Status
= ShowProgress (TimeoutDefault
);
1175 // Ensure screen is clear when switch Console from Graphics mode to Text mode
1177 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
1178 gST
->ConOut
->ClearScreen (gST
->ConOut
);
1180 if (EFI_ERROR (Status
)) {
1182 // Timeout or user press enter to continue
1189 // Boot Logo is corrupted, report it using Boot Logo protocol.
1191 Status
= gBS
->LocateProtocol (&gEfiBootLogoProtocolGuid
, NULL
, (VOID
**) &BootLogo
);
1192 if (!EFI_ERROR (Status
) && (BootLogo
!= NULL
)) {
1193 BootLogo
->SetBootLogo (BootLogo
, NULL
, 0, 0, 0, 0);
1196 Status
= EFI_SUCCESS
;
1199 // Set proper video resolution and text mode for setup
1201 ChangeModeForSetup ();
1203 InitializeFrontPage (FALSE
);
1206 // Update Front Page strings
1208 UpdateFrontPageStrings ();
1214 // If gCallbackKey is greater than 1 and less or equal to 5,
1215 // it will launch configuration utilities.
1218 // 4 = device manager
1219 // 5 = boot maintenance manager
1221 if (gCallbackKey
!= 0) {
1222 REPORT_STATUS_CODE (
1224 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_PC_USER_SETUP
)
1228 // Based on the key that was set, we can determine what to do
1230 switch (gCallbackKey
) {
1232 // The first 4 entries in the Front Page are to be GUARANTEED to remain constant so IHV's can
1233 // describe to their customers in documentation how to find their setup information (namely
1234 // under the device manager and specific buckets)
1236 // These entries consist of the Continue, Select language, Boot Manager, and Device Manager
1238 case FRONT_PAGE_KEY_CONTINUE
:
1240 // User hit continue
1244 case FRONT_PAGE_KEY_LANGUAGE
:
1246 // User made a language setting change - display front page again
1250 case FRONT_PAGE_KEY_BOOT_MANAGER
:
1252 // User chose to run the Boot Manager
1257 case FRONT_PAGE_KEY_DEVICE_MANAGER
:
1259 // Display the Device Manager
1262 CallDeviceManager ();
1263 } while (gCallbackKey
== FRONT_PAGE_KEY_DEVICE_MANAGER
);
1266 case FRONT_PAGE_KEY_BOOT_MAINTAIN
:
1268 // Display the Boot Maintenance Manager
1270 BdsStartBootMaint ();
1274 } while ((Status
== EFI_SUCCESS
) && (gCallbackKey
!= FRONT_PAGE_KEY_CONTINUE
));
1277 //Will leave browser, check any reset required change is applied? if yes, reset system
1279 SetupResetReminder ();
1283 // Automatically load current entry
1284 // Note: The following lines of code only execute when Auto boot
1287 PERF_END (NULL
, "BdsTimeOut", "BDS", 0);