2 FrontPage routines to handle the callbacks and browser calls
4 Copyright (c) 2004 - 2017, 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
306 CHAR16
*StringBuffer
;
307 EFI_HII_HANDLE HiiHandle
;
308 VOID
*OptionsOpCodeHandle
;
309 VOID
*StartOpCodeHandle
;
310 VOID
*EndOpCodeHandle
;
311 EFI_IFR_GUID_LABEL
*StartLabel
;
312 EFI_IFR_GUID_LABEL
*EndLabel
;
313 EFI_HII_STRING_PROTOCOL
*HiiString
;
319 if (InitializeHiiData
) {
321 // Initialize the Device Manager
323 InitializeDeviceManager ();
326 // Initialize the Device Manager
328 InitializeBootManager ();
333 // Locate Hii relative protocols
335 Status
= gBS
->LocateProtocol (&gEfiFormBrowser2ProtocolGuid
, NULL
, (VOID
**) &gFormBrowser2
);
336 if (EFI_ERROR (Status
)) {
341 // Install Device Path Protocol and Config Access protocol to driver handle
343 Status
= gBS
->InstallMultipleProtocolInterfaces (
344 &gFrontPagePrivate
.DriverHandle
,
345 &gEfiDevicePathProtocolGuid
,
346 &mFrontPageHiiVendorDevicePath
,
347 &gEfiHiiConfigAccessProtocolGuid
,
348 &gFrontPagePrivate
.ConfigAccess
,
351 ASSERT_EFI_ERROR (Status
);
354 // Publish our HII data
356 gFrontPagePrivate
.HiiHandle
= HiiAddPackages (
357 &gFrontPageFormSetGuid
,
358 gFrontPagePrivate
.DriverHandle
,
363 if (gFrontPagePrivate
.HiiHandle
== NULL
) {
364 return EFI_OUT_OF_RESOURCES
;
370 // Init OpCode Handle and Allocate space for creation of UpdateData Buffer
372 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
373 ASSERT (StartOpCodeHandle
!= NULL
);
375 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
376 ASSERT (EndOpCodeHandle
!= NULL
);
378 OptionsOpCodeHandle
= HiiAllocateOpCodeHandle ();
379 ASSERT (OptionsOpCodeHandle
!= NULL
);
381 // Create Hii Extend Label OpCode as the start opcode
383 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
384 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
385 StartLabel
->Number
= LABEL_SELECT_LANGUAGE
;
388 // Create Hii Extend Label OpCode as the end opcode
390 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
391 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
392 EndLabel
->Number
= LABEL_END
;
395 // Collect the languages from what our current Language support is based on our VFR
397 HiiHandle
= gFrontPagePrivate
.HiiHandle
;
399 GetEfiGlobalVariable2 (L
"PlatformLang", (VOID
**)&CurrentLang
, NULL
);
402 // Get Support language list from variable.
404 if (mLanguageString
== NULL
){
405 GetEfiGlobalVariable2 (L
"PlatformLangCodes", (VOID
**)&mLanguageString
, NULL
);
406 if (mLanguageString
== NULL
) {
407 mLanguageString
= AllocateCopyPool (
408 AsciiStrSize ((CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLangCodes
)),
409 (CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLangCodes
)
411 ASSERT (mLanguageString
!= NULL
);
415 if (gFrontPagePrivate
.LanguageToken
== NULL
) {
417 // Count the language list number.
419 LangCode
= mLanguageString
;
420 Lang
= AllocatePool (AsciiStrSize (mLanguageString
));
421 ASSERT (Lang
!= NULL
);
423 while (*LangCode
!= 0) {
424 GetNextLanguage (&LangCode
, Lang
);
429 // Allocate extra 1 as the end tag.
431 gFrontPagePrivate
.LanguageToken
= AllocateZeroPool ((OptionCount
+ 1) * sizeof (EFI_STRING_ID
));
432 ASSERT (gFrontPagePrivate
.LanguageToken
!= NULL
);
434 Status
= gBS
->LocateProtocol (&gEfiHiiStringProtocolGuid
, NULL
, (VOID
**) &HiiString
);
435 ASSERT_EFI_ERROR (Status
);
437 LangCode
= mLanguageString
;
439 while (*LangCode
!= 0) {
440 GetNextLanguage (&LangCode
, Lang
);
443 Status
= HiiString
->GetString (HiiString
, Lang
, HiiHandle
, PRINTABLE_LANGUAGE_NAME_STRING_ID
, StringBuffer
, &StringSize
, NULL
);
444 if (Status
== EFI_BUFFER_TOO_SMALL
) {
445 StringBuffer
= AllocateZeroPool (StringSize
);
446 ASSERT (StringBuffer
!= NULL
);
447 Status
= HiiString
->GetString (HiiString
, Lang
, HiiHandle
, PRINTABLE_LANGUAGE_NAME_STRING_ID
, StringBuffer
, &StringSize
, NULL
);
448 ASSERT_EFI_ERROR (Status
);
451 if (EFI_ERROR (Status
)) {
452 LangSize
= AsciiStrSize (Lang
);
453 StringBuffer
= AllocatePool (LangSize
* sizeof (CHAR16
));
454 ASSERT (StringBuffer
!= NULL
);
455 AsciiStrToUnicodeStrS (Lang
, StringBuffer
, LangSize
);
458 ASSERT (StringBuffer
!= NULL
);
459 gFrontPagePrivate
.LanguageToken
[OptionCount
] = HiiSetString (HiiHandle
, 0, StringBuffer
, NULL
);
460 FreePool (StringBuffer
);
466 ASSERT (gFrontPagePrivate
.LanguageToken
!= NULL
);
467 LangCode
= mLanguageString
;
470 Lang
= AllocatePool (AsciiStrSize (mLanguageString
));
471 ASSERT (Lang
!= NULL
);
473 while (*LangCode
!= 0) {
474 GetNextLanguage (&LangCode
, Lang
);
476 if (CurrentLang
!= NULL
&& AsciiStrCmp (Lang
, CurrentLang
) == 0) {
477 HiiCreateOneOfOptionOpCode (
479 gFrontPagePrivate
.LanguageToken
[OptionCount
],
480 EFI_IFR_OPTION_DEFAULT
,
481 EFI_IFR_NUMERIC_SIZE_1
,
485 HiiCreateOneOfOptionOpCode (
487 gFrontPagePrivate
.LanguageToken
[OptionCount
],
489 EFI_IFR_NUMERIC_SIZE_1
,
497 if (CurrentLang
!= NULL
) {
498 FreePool (CurrentLang
);
502 HiiCreateOneOfOpCode (
504 FRONT_PAGE_KEY_LANGUAGE
,
507 STRING_TOKEN (STR_LANGUAGE_SELECT
),
508 STRING_TOKEN (STR_LANGUAGE_SELECT_HELP
),
509 EFI_IFR_FLAG_CALLBACK
,
510 EFI_IFR_NUMERIC_SIZE_1
,
515 Status
= HiiUpdateForm (
517 &gFrontPageFormSetGuid
,
519 StartOpCodeHandle
, // LABEL_SELECT_LANGUAGE
520 EndOpCodeHandle
// LABEL_END
523 HiiFreeOpCodeHandle (StartOpCodeHandle
);
524 HiiFreeOpCodeHandle (EndOpCodeHandle
);
525 HiiFreeOpCodeHandle (OptionsOpCodeHandle
);
530 Call the browser and display the front page
532 @return Status code that will be returned by
533 EFI_FORM_BROWSER2_PROTOCOL.SendForm ().
542 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
545 // Begin waiting for USER INPUT
549 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_PC_INPUT_WAIT
)
552 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
553 Status
= gFormBrowser2
->SendForm (
555 &gFrontPagePrivate
.HiiHandle
,
557 &gFrontPageFormSetGuid
,
563 // Check whether user change any option setting which needs a reset to be effective
565 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
566 EnableResetRequired ();
573 Acquire the string associated with the ProducerGuid and return it.
576 @param ProducerGuid The Guid to search the HII database for
577 @param Token The token value of the string to extract
578 @param String The string that is extracted
580 @retval EFI_SUCCESS The function returns EFI_SUCCESS always.
585 IN EFI_GUID
*ProducerGuid
,
586 IN EFI_STRING_ID Token
,
590 EFI_STRING TmpString
;
592 TmpString
= HiiGetPackageString (ProducerGuid
, Token
, NULL
);
593 if (TmpString
== NULL
) {
594 *String
= GetStringById (STRING_TOKEN (STR_MISSING_STRING
));
603 Convert Processor Frequency Data to a string.
605 @param ProcessorFrequency The frequency data to process
606 @param Base10Exponent The exponent based on 10
607 @param String The string that is created
611 ConvertProcessorToString (
612 IN UINT16 ProcessorFrequency
,
613 IN UINT16 Base10Exponent
,
617 CHAR16
*StringBuffer
;
621 if (Base10Exponent
>= 6) {
622 FreqMhz
= ProcessorFrequency
;
623 for (Index
= 0; Index
< (UINTN
) (Base10Exponent
- 6); Index
++) {
630 StringBuffer
= AllocateZeroPool (0x20);
631 ASSERT (StringBuffer
!= NULL
);
632 UnicodeValueToStringS (StringBuffer
, 0x20, LEFT_JUSTIFY
, FreqMhz
/ 1000, 3);
633 Index
= StrnLenS (StringBuffer
, 0x20 / sizeof (CHAR16
));
634 StrCatS (StringBuffer
, 0x20 / sizeof (CHAR16
), L
".");
635 UnicodeValueToStringS (
636 StringBuffer
+ Index
+ 1,
637 0x20 - sizeof (CHAR16
) * (Index
+ 1),
639 (FreqMhz
% 1000) / 10,
642 StrCatS (StringBuffer
, 0x20 / sizeof (CHAR16
), L
" GHz");
643 *String
= (CHAR16
*) StringBuffer
;
649 Convert Memory Size to a string.
651 @param MemorySize The size of the memory to process
652 @param String The string that is created
656 ConvertMemorySizeToString (
657 IN UINT32 MemorySize
,
661 CHAR16
*StringBuffer
;
663 StringBuffer
= AllocateZeroPool (0x20);
664 ASSERT (StringBuffer
!= NULL
);
665 UnicodeValueToStringS (StringBuffer
, 0x20, LEFT_JUSTIFY
, MemorySize
, 6);
666 StrCatS (StringBuffer
, 0x20 / sizeof (CHAR16
), L
" MB RAM");
668 *String
= (CHAR16
*) StringBuffer
;
675 Acquire the string associated with the Index from smbios structure and return it.
676 The caller is responsible for free the string buffer.
678 @param OptionalStrStart The start position to search the string
679 @param Index The index of the string to extract
680 @param String The string that is extracted
682 @retval EFI_SUCCESS The function returns EFI_SUCCESS always.
686 GetOptionalStringByIndex (
687 IN CHAR8
*OptionalStrStart
,
695 *String
= AllocateZeroPool (sizeof (CHAR16
));
702 OptionalStrStart
+= StrSize
;
703 StrSize
= AsciiStrSize (OptionalStrStart
);
704 } while (OptionalStrStart
[StrSize
] != 0 && Index
!= 0);
706 if ((Index
!= 0) || (StrSize
== 1)) {
708 // Meet the end of strings set but Index is non-zero, or
709 // Find an empty string
711 *String
= GetStringById (STRING_TOKEN (STR_MISSING_STRING
));
713 *String
= AllocatePool (StrSize
* sizeof (CHAR16
));
714 AsciiStrToUnicodeStrS (OptionalStrStart
, *String
, StrSize
);
722 Update the banner information for the Front Page based on DataHub information.
726 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
;
741 UINT64 InstalledMemory
;
746 // Update Front Page strings
748 Status
= gBS
->LocateProtocol (
749 &gEfiSmbiosProtocolGuid
,
753 if (!EFI_ERROR (Status
)) {
754 SmbiosHandle
= SMBIOS_HANDLE_PI_RESERVED
;
755 Status
= Smbios
->GetNext (Smbios
, &SmbiosHandle
, NULL
, &Record
, NULL
);
756 while (!EFI_ERROR(Status
)) {
757 if (Record
->Type
== SMBIOS_TYPE_BIOS_INFORMATION
) {
758 Type0Record
= (SMBIOS_TABLE_TYPE0
*) Record
;
759 StrIndex
= Type0Record
->BiosVersion
;
760 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type0Record
+ Type0Record
->Hdr
.Length
), StrIndex
, &NewString
);
761 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION
);
762 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
763 FreePool (NewString
);
766 if (Record
->Type
== SMBIOS_TYPE_SYSTEM_INFORMATION
) {
767 Type1Record
= (SMBIOS_TABLE_TYPE1
*) Record
;
768 StrIndex
= Type1Record
->ProductName
;
769 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type1Record
+ Type1Record
->Hdr
.Length
), StrIndex
, &NewString
);
770 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_COMPUTER_MODEL
);
771 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
772 FreePool (NewString
);
775 if (Record
->Type
== SMBIOS_TYPE_PROCESSOR_INFORMATION
) {
776 Type4Record
= (SMBIOS_TABLE_TYPE4
*) Record
;
777 StrIndex
= Type4Record
->ProcessorVersion
;
778 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type4Record
+ Type4Record
->Hdr
.Length
), StrIndex
, &NewString
);
779 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_CPU_MODEL
);
780 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
781 FreePool (NewString
);
784 if (Record
->Type
== SMBIOS_TYPE_PROCESSOR_INFORMATION
) {
785 Type4Record
= (SMBIOS_TABLE_TYPE4
*) Record
;
786 ConvertProcessorToString(Type4Record
->CurrentSpeed
, 6, &NewString
);
787 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_CPU_SPEED
);
788 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
789 FreePool (NewString
);
792 if ( Record
->Type
== SMBIOS_TYPE_MEMORY_ARRAY_MAPPED_ADDRESS
) {
793 Type19Record
= (SMBIOS_TABLE_TYPE19
*) Record
;
794 if (Type19Record
->StartingAddress
!= 0xFFFFFFFF ) {
795 InstalledMemory
+= RShiftU64(Type19Record
->EndingAddress
-
796 Type19Record
->StartingAddress
+ 1, 10);
798 InstalledMemory
+= RShiftU64(Type19Record
->ExtendedEndingAddress
-
799 Type19Record
->ExtendedStartingAddress
+ 1, 20);
803 Status
= Smbios
->GetNext (Smbios
, &SmbiosHandle
, NULL
, &Record
, NULL
);
806 // now update the total installed RAM size
807 ConvertMemorySizeToString ((UINT32
)InstalledMemory
, &NewString
);
808 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_MEMORY_SIZE
);
809 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
810 FreePool (NewString
);
818 Function waits for a given event to fire, or for an optional timeout to expire.
820 @param Event The event to wait for
821 @param Timeout An optional timeout value in 100 ns units.
823 @retval EFI_SUCCESS Event fired before Timeout expired.
824 @retval EFI_TIME_OUT Timout expired before Event fired..
830 IN UINT64 Timeout OPTIONAL
835 EFI_EVENT TimerEvent
;
836 EFI_EVENT WaitList
[2];
840 // Create a timer event
842 Status
= gBS
->CreateEvent (EVT_TIMER
, 0, NULL
, NULL
, &TimerEvent
);
843 if (!EFI_ERROR (Status
)) {
845 // Set the timer event
854 // Wait for the original event or the timer
857 WaitList
[1] = TimerEvent
;
858 Status
= gBS
->WaitForEvent (2, WaitList
, &Index
);
859 gBS
->CloseEvent (TimerEvent
);
862 // If the timer expired, change the return to timed out
864 if (!EFI_ERROR (Status
) && Index
== 1) {
865 Status
= EFI_TIMEOUT
;
870 // No timeout... just wait on the event
872 Status
= gBS
->WaitForEvent (1, &Event
, &Index
);
873 ASSERT (!EFI_ERROR (Status
));
881 Function show progress bar to wait for user input.
884 @param TimeoutDefault The fault time out value before the system continue to boot.
886 @retval EFI_SUCCESS User pressed some key except "Enter"
887 @retval EFI_TIME_OUT Timeout expired or user press "Enter"
892 IN UINT16 TimeoutDefault
896 UINT16 TimeoutRemain
;
899 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
900 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
901 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color
;
903 if (TimeoutDefault
!= 0) {
904 DEBUG ((EFI_D_INFO
, "\n\nStart showing progress bar... Press any key to stop it! ...Zzz....\n"));
906 SetMem (&Foreground
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
907 SetMem (&Background
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0x0);
908 SetMem (&Color
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
), 0xff);
910 TmpStr
= GetStringById (STRING_TOKEN (STR_START_BOOT_OPTION
));
912 if (!FeaturePcdGet(PcdBootlogoOnlyEnable
)) {
914 // Clear the progress status bar first
916 if (TmpStr
!= NULL
) {
917 PlatformBdsShowProgress (Foreground
, Background
, TmpStr
, Color
, 0, 0);
922 TimeoutRemain
= TimeoutDefault
;
923 while (TimeoutRemain
!= 0) {
924 DEBUG ((EFI_D_INFO
, "Showing progress bar...Remaining %d second!\n", TimeoutRemain
));
926 Status
= WaitForSingleEvent (gST
->ConIn
->WaitForKey
, ONE_SECOND
);
927 if (Status
!= EFI_TIMEOUT
) {
932 if (!FeaturePcdGet(PcdBootlogoOnlyEnable
)) {
936 if (TmpStr
!= NULL
) {
937 PlatformBdsShowProgress (
942 ((TimeoutDefault
- TimeoutRemain
) * 100 / TimeoutDefault
),
949 if (TmpStr
!= NULL
) {
950 gBS
->FreePool (TmpStr
);
956 if (TimeoutRemain
== 0) {
962 // User pressed some key
964 if (!PcdGetBool (PcdConInConnectOnDemand
)) {
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"
982 This function is the main entry of the platform setup entry.
983 The function will present the main menu of the system setup,
984 this is the platform reference part and can be customize.
987 @param TimeoutDefault The fault time out value before the system
989 @param ConnectAllHappened The indicater to check if the connect all have
994 PlatformBdsEnterFrontPage (
995 IN UINT16 TimeoutDefault
,
996 IN BOOLEAN ConnectAllHappened
1000 EFI_STATUS StatusHotkey
;
1001 EFI_BOOT_LOGO_PROTOCOL
*BootLogo
;
1002 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1003 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
1004 UINTN BootTextColumn
;
1006 UINT64 OsIndication
;
1010 GraphicsOutput
= NULL
;
1011 SimpleTextOut
= NULL
;
1013 PERF_START (NULL
, "BdsTimeOut", "BDS", 0);
1015 // Indicate if we need connect all in the platform setup
1017 if (ConnectAllHappened
) {
1018 gConnectAllHappened
= TRUE
;
1021 if (!mModeInitialized
) {
1023 // After the console is ready, get current video resolution
1024 // and text mode before launching setup at first time.
1026 Status
= gBS
->HandleProtocol (
1027 gST
->ConsoleOutHandle
,
1028 &gEfiGraphicsOutputProtocolGuid
,
1029 (VOID
**)&GraphicsOutput
1031 if (EFI_ERROR (Status
)) {
1032 GraphicsOutput
= NULL
;
1035 Status
= gBS
->HandleProtocol (
1036 gST
->ConsoleOutHandle
,
1037 &gEfiSimpleTextOutProtocolGuid
,
1038 (VOID
**)&SimpleTextOut
1040 if (EFI_ERROR (Status
)) {
1041 SimpleTextOut
= NULL
;
1044 if (GraphicsOutput
!= NULL
) {
1046 // Get current video resolution and text mode.
1048 mBootHorizontalResolution
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
1049 mBootVerticalResolution
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
1052 if (SimpleTextOut
!= NULL
) {
1053 Status
= SimpleTextOut
->QueryMode (
1055 SimpleTextOut
->Mode
->Mode
,
1059 mBootTextModeColumn
= (UINT32
)BootTextColumn
;
1060 mBootTextModeRow
= (UINT32
)BootTextRow
;
1064 // Get user defined text mode for setup.
1066 mSetupHorizontalResolution
= PcdGet32 (PcdSetupVideoHorizontalResolution
);
1067 mSetupVerticalResolution
= PcdGet32 (PcdSetupVideoVerticalResolution
);
1068 mSetupTextModeColumn
= PcdGet32 (PcdSetupConOutColumn
);
1069 mSetupTextModeRow
= PcdGet32 (PcdSetupConOutRow
);
1071 mModeInitialized
= TRUE
;
1076 // goto FrontPage directly when EFI_OS_INDICATIONS_BOOT_TO_FW_UI is set
1079 DataSize
= sizeof(UINT64
);
1080 Status
= gRT
->GetVariable (
1082 &gEfiGlobalVariableGuid
,
1089 // goto FrontPage directly when EFI_OS_INDICATIONS_BOOT_TO_FW_UI is set. Skip HotkeyBoot
1091 if (!EFI_ERROR(Status
) && ((OsIndication
& EFI_OS_INDICATIONS_BOOT_TO_FW_UI
) != 0)) {
1093 // Clear EFI_OS_INDICATIONS_BOOT_TO_FW_UI to acknowledge OS
1095 OsIndication
&= ~((UINT64
)EFI_OS_INDICATIONS_BOOT_TO_FW_UI
);
1096 Status
= gRT
->SetVariable (
1098 &gEfiGlobalVariableGuid
,
1099 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
1104 // Changing the content without increasing its size with current variable implementation shouldn't fail.
1106 ASSERT_EFI_ERROR (Status
);
1109 // Follow generic rule, Call ReadKeyStroke to connect ConIn before enter UI
1111 if (PcdGetBool (PcdConInConnectOnDemand
)) {
1112 gST
->ConIn
->ReadKeyStroke(gST
->ConIn
, &Key
);
1116 // Ensure screen is clear when switch Console from Graphics mode to Text mode
1118 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
1119 gST
->ConOut
->ClearScreen (gST
->ConOut
);
1124 if (TimeoutDefault
!= 0xffff) {
1125 Status
= ShowProgress (TimeoutDefault
);
1126 StatusHotkey
= HotkeyBoot ();
1128 if (!FeaturePcdGet(PcdBootlogoOnlyEnable
) || !EFI_ERROR(Status
) || !EFI_ERROR(StatusHotkey
)){
1130 // Ensure screen is clear when switch Console from Graphics mode to Text mode
1131 // Skip it in normal boot
1133 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
1134 gST
->ConOut
->ClearScreen (gST
->ConOut
);
1137 if (EFI_ERROR (Status
)) {
1139 // Timeout or user press enter to continue
1147 // Boot Logo is corrupted, report it using Boot Logo protocol.
1149 Status
= gBS
->LocateProtocol (&gEfiBootLogoProtocolGuid
, NULL
, (VOID
**) &BootLogo
);
1150 if (!EFI_ERROR (Status
) && (BootLogo
!= NULL
)) {
1151 BootLogo
->SetBootLogo (BootLogo
, NULL
, 0, 0, 0, 0);
1155 // Install BM HiiPackages.
1156 // Keep BootMaint HiiPackage, so that it can be covered by global setting.
1160 Status
= EFI_SUCCESS
;
1163 // Set proper video resolution and text mode for setup
1165 BdsSetConsoleMode (TRUE
);
1167 InitializeFrontPage (FALSE
);
1170 // Update Front Page strings
1172 UpdateFrontPageStrings ();
1178 // If gCallbackKey is greater than 1 and less or equal to 5,
1179 // it will launch configuration utilities.
1182 // 4 = device manager
1183 // 5 = boot maintenance manager
1185 if (gCallbackKey
!= 0) {
1186 REPORT_STATUS_CODE (
1188 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_PC_USER_SETUP
)
1192 // Based on the key that was set, we can determine what to do
1194 switch (gCallbackKey
) {
1196 // The first 4 entries in the Front Page are to be GUARANTEED to remain constant so IHV's can
1197 // describe to their customers in documentation how to find their setup information (namely
1198 // under the device manager and specific buckets)
1200 // These entries consist of the Continue, Select language, Boot Manager, and Device Manager
1202 case FRONT_PAGE_KEY_CONTINUE
:
1204 // User hit continue
1208 case FRONT_PAGE_KEY_LANGUAGE
:
1210 // User made a language setting change - display front page again
1214 case FRONT_PAGE_KEY_BOOT_MANAGER
:
1216 // Remove the installed BootMaint HiiPackages when exit.
1221 // User chose to run the Boot Manager
1226 // Reinstall BootMaint HiiPackages after exiting from Boot Manager.
1231 case FRONT_PAGE_KEY_DEVICE_MANAGER
:
1233 // Display the Device Manager
1236 CallDeviceManager ();
1237 } while (gCallbackKey
== FRONT_PAGE_KEY_DEVICE_MANAGER
);
1240 case FRONT_PAGE_KEY_BOOT_MAINTAIN
:
1242 // Display the Boot Maintenance Manager
1244 BdsStartBootMaint ();
1248 } while ((Status
== EFI_SUCCESS
) && (gCallbackKey
!= FRONT_PAGE_KEY_CONTINUE
));
1250 if (mLanguageString
!= NULL
) {
1251 FreePool (mLanguageString
);
1252 mLanguageString
= NULL
;
1255 //Will leave browser, check any reset required change is applied? if yes, reset system
1257 SetupResetReminder ();
1260 // Remove the installed BootMaint HiiPackages when exit.
1266 // Automatically load current entry
1267 // Note: The following lines of code only execute when Auto boot
1270 PERF_END (NULL
, "BdsTimeOut", "BDS", 0);
1274 This function will change video resolution and text mode
1275 according to defined setup mode or defined boot mode
1277 @param IsSetupMode Indicate mode is changed to setup mode or boot mode.
1279 @retval EFI_SUCCESS Mode is changed successfully.
1280 @retval Others Mode failed to be changed.
1289 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1290 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
1292 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
1296 UINT32 NewHorizontalResolution
;
1297 UINT32 NewVerticalResolution
;
1301 EFI_HANDLE
*HandleBuffer
;
1304 UINTN CurrentColumn
;
1311 // Get current video resolution and text mode
1313 Status
= gBS
->HandleProtocol (
1314 gST
->ConsoleOutHandle
,
1315 &gEfiGraphicsOutputProtocolGuid
,
1316 (VOID
**)&GraphicsOutput
1318 if (EFI_ERROR (Status
)) {
1319 GraphicsOutput
= NULL
;
1322 Status
= gBS
->HandleProtocol (
1323 gST
->ConsoleOutHandle
,
1324 &gEfiSimpleTextOutProtocolGuid
,
1325 (VOID
**)&SimpleTextOut
1327 if (EFI_ERROR (Status
)) {
1328 SimpleTextOut
= NULL
;
1331 if ((GraphicsOutput
== NULL
) || (SimpleTextOut
== NULL
)) {
1332 return EFI_UNSUPPORTED
;
1337 // The required resolution and text mode is setup mode.
1339 NewHorizontalResolution
= mSetupHorizontalResolution
;
1340 NewVerticalResolution
= mSetupVerticalResolution
;
1341 NewColumns
= mSetupTextModeColumn
;
1342 NewRows
= mSetupTextModeRow
;
1345 // The required resolution and text mode is boot mode.
1347 NewHorizontalResolution
= mBootHorizontalResolution
;
1348 NewVerticalResolution
= mBootVerticalResolution
;
1349 NewColumns
= mBootTextModeColumn
;
1350 NewRows
= mBootTextModeRow
;
1353 if (GraphicsOutput
!= NULL
) {
1354 MaxGopMode
= GraphicsOutput
->Mode
->MaxMode
;
1357 if (SimpleTextOut
!= NULL
) {
1358 MaxTextMode
= SimpleTextOut
->Mode
->MaxMode
;
1362 // 1. If current video resolution is same with required video resolution,
1363 // video resolution need not be changed.
1364 // 1.1. If current text mode is same with required text mode, text mode need not be changed.
1365 // 1.2. If current text mode is different from required text mode, text mode need be changed.
1366 // 2. If current video resolution is different from required video resolution, we need restart whole console drivers.
1368 for (ModeNumber
= 0; ModeNumber
< MaxGopMode
; ModeNumber
++) {
1369 Status
= GraphicsOutput
->QueryMode (
1375 if (!EFI_ERROR (Status
)) {
1376 if ((Info
->HorizontalResolution
== NewHorizontalResolution
) &&
1377 (Info
->VerticalResolution
== NewVerticalResolution
)) {
1378 if ((GraphicsOutput
->Mode
->Info
->HorizontalResolution
== NewHorizontalResolution
) &&
1379 (GraphicsOutput
->Mode
->Info
->VerticalResolution
== NewVerticalResolution
)) {
1381 // Current resolution is same with required resolution, check if text mode need be set
1383 Status
= SimpleTextOut
->QueryMode (SimpleTextOut
, SimpleTextOut
->Mode
->Mode
, &CurrentColumn
, &CurrentRow
);
1384 ASSERT_EFI_ERROR (Status
);
1385 if (CurrentColumn
== NewColumns
&& CurrentRow
== NewRows
) {
1387 // If current text mode is same with required text mode. Do nothing
1393 // If current text mode is different from required text mode. Set new video mode
1395 for (Index
= 0; Index
< MaxTextMode
; Index
++) {
1396 Status
= SimpleTextOut
->QueryMode (SimpleTextOut
, Index
, &CurrentColumn
, &CurrentRow
);
1397 if (!EFI_ERROR(Status
)) {
1398 if ((CurrentColumn
== NewColumns
) && (CurrentRow
== NewRows
)) {
1400 // Required text mode is supported, set it.
1402 Status
= SimpleTextOut
->SetMode (SimpleTextOut
, Index
);
1403 ASSERT_EFI_ERROR (Status
);
1405 // Update text mode PCD.
1407 Status
= PcdSet32S (PcdConOutColumn
, mSetupTextModeColumn
);
1408 ASSERT_EFI_ERROR (Status
);
1409 Status
= PcdSet32S (PcdConOutRow
, mSetupTextModeRow
);
1410 ASSERT_EFI_ERROR (Status
);
1416 if (Index
== MaxTextMode
) {
1418 // If required text mode is not supported, return error.
1421 return EFI_UNSUPPORTED
;
1426 // If current video resolution is not same with the new one, set new video resolution.
1427 // In this case, the driver which produces simple text out need be restarted.
1429 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, ModeNumber
);
1430 if (!EFI_ERROR (Status
)) {
1440 if (ModeNumber
== MaxGopMode
) {
1442 // If the resolution is not supported, return error.
1444 return EFI_UNSUPPORTED
;
1448 // Set PCD to Inform GraphicsConsole to change video resolution.
1449 // Set PCD to Inform Consplitter to change text mode.
1451 Status
= PcdSet32S (PcdVideoHorizontalResolution
, NewHorizontalResolution
);
1452 ASSERT_EFI_ERROR (Status
);
1453 Status
= PcdSet32S (PcdVideoVerticalResolution
, NewVerticalResolution
);
1454 ASSERT_EFI_ERROR (Status
);
1455 Status
= PcdSet32S (PcdConOutColumn
, NewColumns
);
1456 ASSERT_EFI_ERROR (Status
);
1457 Status
= PcdSet32S (PcdConOutRow
, NewRows
);
1458 ASSERT_EFI_ERROR (Status
);
1462 // Video mode is changed, so restart graphics console driver and higher level driver.
1463 // Reconnect graphics console driver and higher level driver.
1464 // Locate all the handles with GOP protocol and reconnect it.
1466 Status
= gBS
->LocateHandleBuffer (
1468 &gEfiSimpleTextOutProtocolGuid
,
1473 if (!EFI_ERROR (Status
)) {
1474 for (Index
= 0; Index
< HandleCount
; Index
++) {
1475 gBS
->DisconnectController (HandleBuffer
[Index
], NULL
, NULL
);
1477 for (Index
= 0; Index
< HandleCount
; Index
++) {
1478 gBS
->ConnectController (HandleBuffer
[Index
], NULL
, NULL
, TRUE
);
1480 if (HandleBuffer
!= NULL
) {
1481 FreePool (HandleBuffer
);