2 FrontPage routines to handle the callbacks and browser calls
4 Copyright (c) 2004 - 2015, 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.
15 #include "FrontPage.h"
17 #define MAX_STRING_LEN 200
19 EFI_GUID mFrontPageGuid
= FRONT_PAGE_FORMSET_GUID
;
21 BOOLEAN gConnectAllHappened
= FALSE
;
22 BOOLEAN mFeaturerSwitch
= TRUE
;
23 BOOLEAN mResetRequired
= FALSE
;
24 BOOLEAN mEnterBmm
= FALSE
;
26 EFI_FORM_BROWSER2_PROTOCOL
*gFormBrowser2
;
27 CHAR8
*mLanguageString
;
28 BOOLEAN mModeInitialized
= FALSE
;
30 // Boot video resolution and text mode.
32 UINT32 mBootHorizontalResolution
= 0;
33 UINT32 mBootVerticalResolution
= 0;
34 UINT32 mBootTextModeColumn
= 0;
35 UINT32 mBootTextModeRow
= 0;
37 // BIOS setup video resolution and text mode.
39 UINT32 mSetupTextModeColumn
= 0;
40 UINT32 mSetupTextModeRow
= 0;
41 UINT32 mSetupHorizontalResolution
= 0;
42 UINT32 mSetupVerticalResolution
= 0;
44 FRONT_PAGE_CALLBACK_DATA gFrontPagePrivate
= {
45 FRONT_PAGE_CALLBACK_DATA_SIGNATURE
,
56 HII_VENDOR_DEVICE_PATH mFrontPageHiiVendorDevicePath
= {
62 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
63 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
67 // {8E6D99EE-7531-48f8-8745-7F6144468FF2}
69 { 0x8e6d99ee, 0x7531, 0x48f8, { 0x87, 0x45, 0x7f, 0x61, 0x44, 0x46, 0x8f, 0xf2 } }
73 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
75 (UINT8
) (END_DEVICE_PATH_LENGTH
),
76 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
82 Update the banner information for the Front Page based on Smbios information.
86 UpdateFrontPageStrings (
91 This function allows a caller to extract the current configuration for one
92 or more named elements from the target driver.
95 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
96 @param Request A null-terminated Unicode string in <ConfigRequest> format.
97 @param Progress On return, points to a character in the Request string.
98 Points to the string's null terminator if request was successful.
99 Points to the most recent '&' before the first failing name/value
100 pair (or the beginning of the string if the failure is in the
101 first name/value pair) if the request was not successful.
102 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
103 has all values filled in for the names in the Request string.
104 String to be allocated by the called function.
106 @retval EFI_SUCCESS The Results is filled with the requested values.
107 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
108 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
109 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
115 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
116 IN CONST EFI_STRING Request
,
117 OUT EFI_STRING
*Progress
,
118 OUT EFI_STRING
*Results
121 if (Progress
== NULL
|| Results
== NULL
) {
122 return EFI_INVALID_PARAMETER
;
125 return EFI_NOT_FOUND
;
129 This function processes the results of changes in configuration.
132 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
133 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
134 @param Progress A pointer to a string filled in with the offset of the most
135 recent '&' before the first failing name/value pair (or the
136 beginning of the string if the failure is in the first
137 name/value pair) or the terminating NULL if all was successful.
139 @retval EFI_SUCCESS The Results is processed successfully.
140 @retval EFI_INVALID_PARAMETER Configuration is NULL.
141 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
147 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
148 IN CONST EFI_STRING Configuration
,
149 OUT EFI_STRING
*Progress
152 if (Configuration
== NULL
|| Progress
== NULL
) {
153 return EFI_INVALID_PARAMETER
;
156 *Progress
= Configuration
;
157 if (!HiiIsConfigHdrMatch (Configuration
, &mBootMaintGuid
, mBootMaintStorageName
)
158 && !HiiIsConfigHdrMatch (Configuration
, &mFileExplorerGuid
, mFileExplorerStorageName
)) {
159 return EFI_NOT_FOUND
;
162 *Progress
= Configuration
+ StrLen (Configuration
);
167 Create oneof options for language.
180 CHAR16
*StringBuffer
;
181 EFI_HII_HANDLE HiiHandle
;
182 VOID
*OptionsOpCodeHandle
;
183 VOID
*StartOpCodeHandle
;
184 VOID
*EndOpCodeHandle
;
185 EFI_IFR_GUID_LABEL
*StartLabel
;
186 EFI_IFR_GUID_LABEL
*EndLabel
;
187 EFI_HII_STRING_PROTOCOL
*HiiString
;
194 // Init OpCode Handle and Allocate space for creation of UpdateData Buffer
196 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
197 ASSERT (StartOpCodeHandle
!= NULL
);
199 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
200 ASSERT (EndOpCodeHandle
!= NULL
);
202 OptionsOpCodeHandle
= HiiAllocateOpCodeHandle ();
203 ASSERT (OptionsOpCodeHandle
!= NULL
);
205 // Create Hii Extend Label OpCode as the start opcode
207 StartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
208 StartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
209 StartLabel
->Number
= LABEL_SELECT_LANGUAGE
;
212 // Create Hii Extend Label OpCode as the end opcode
214 EndLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
215 EndLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
216 EndLabel
->Number
= LABEL_END
;
218 // Collect the languages from what our current Language support is based on our VFR
220 HiiHandle
= gFrontPagePrivate
.HiiHandle
;
222 CurrentLang
= GetEfiGlobalVariable (L
"PlatformLang");
224 if (mLanguageString
== NULL
) {
226 // Get Support language list from variable.
228 mLanguageString
= GetEfiGlobalVariable (L
"PlatformLangCodes");
229 if (mLanguageString
== NULL
) {
230 mLanguageString
= AllocateCopyPool (
231 AsciiStrSize ((CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLangCodes
)),
232 (CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLangCodes
)
234 ASSERT (mLanguageString
!= NULL
);
238 if (gFrontPagePrivate
.LanguageToken
== NULL
) {
240 // Count the language list number.
242 LangCode
= mLanguageString
;
243 Lang
= AllocatePool (AsciiStrSize (mLanguageString
));
244 ASSERT (Lang
!= NULL
);
246 while (*LangCode
!= 0) {
247 GetNextLanguage (&LangCode
, Lang
);
252 // Allocate extra 1 as the end tag.
254 gFrontPagePrivate
.LanguageToken
= AllocateZeroPool ((OptionCount
+ 1) * sizeof (EFI_STRING_ID
));
255 ASSERT (gFrontPagePrivate
.LanguageToken
!= NULL
);
257 Status
= gBS
->LocateProtocol (&gEfiHiiStringProtocolGuid
, NULL
, (VOID
**) &HiiString
);
258 ASSERT_EFI_ERROR (Status
);
260 LangCode
= mLanguageString
;
262 while (*LangCode
!= 0) {
263 GetNextLanguage (&LangCode
, Lang
);
266 Status
= HiiString
->GetString (HiiString
, Lang
, HiiHandle
, PRINTABLE_LANGUAGE_NAME_STRING_ID
, StringBuffer
, &StringSize
, NULL
);
267 if (Status
== EFI_BUFFER_TOO_SMALL
) {
268 StringBuffer
= AllocateZeroPool (StringSize
);
269 ASSERT (StringBuffer
!= NULL
);
270 Status
= HiiString
->GetString (HiiString
, Lang
, HiiHandle
, PRINTABLE_LANGUAGE_NAME_STRING_ID
, StringBuffer
, &StringSize
, NULL
);
271 ASSERT_EFI_ERROR (Status
);
274 if (EFI_ERROR (Status
)) {
275 StringBuffer
= AllocatePool (AsciiStrSize (Lang
) * sizeof (CHAR16
));
276 ASSERT (StringBuffer
!= NULL
);
277 AsciiStrToUnicodeStr (Lang
, StringBuffer
);
280 ASSERT (StringBuffer
!= NULL
);
281 gFrontPagePrivate
.LanguageToken
[OptionCount
] = HiiSetString (HiiHandle
, 0, StringBuffer
, NULL
);
282 FreePool (StringBuffer
);
288 ASSERT (gFrontPagePrivate
.LanguageToken
!= NULL
);
289 LangCode
= mLanguageString
;
292 Lang
= AllocatePool (AsciiStrSize (mLanguageString
));
293 ASSERT (Lang
!= NULL
);
295 while (*LangCode
!= 0) {
296 GetNextLanguage (&LangCode
, Lang
);
298 if (CurrentLang
!= NULL
&& AsciiStrCmp (Lang
, CurrentLang
) == 0) {
299 HiiCreateOneOfOptionOpCode (
301 gFrontPagePrivate
.LanguageToken
[OptionCount
],
302 EFI_IFR_OPTION_DEFAULT
,
303 EFI_IFR_NUMERIC_SIZE_1
,
307 HiiCreateOneOfOptionOpCode (
309 gFrontPagePrivate
.LanguageToken
[OptionCount
],
311 EFI_IFR_NUMERIC_SIZE_1
,
319 if (CurrentLang
!= NULL
) {
320 FreePool (CurrentLang
);
324 HiiCreateOneOfOpCode (
326 FRONT_PAGE_KEY_LANGUAGE
,
329 STRING_TOKEN (STR_LANGUAGE_SELECT
),
330 STRING_TOKEN (STR_LANGUAGE_SELECT_HELP
),
331 EFI_IFR_FLAG_CALLBACK
,
332 EFI_IFR_NUMERIC_SIZE_1
,
337 Status
= HiiUpdateForm (
341 StartOpCodeHandle
, // LABEL_SELECT_LANGUAGE
342 EndOpCodeHandle
// LABEL_END
345 HiiFreeOpCodeHandle (StartOpCodeHandle
);
346 HiiFreeOpCodeHandle (EndOpCodeHandle
);
347 HiiFreeOpCodeHandle (OptionsOpCodeHandle
);
351 This function processes the results of changes in configuration.
354 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
355 @param Action Specifies the type of action taken by the browser.
356 @param QuestionId A unique value which is sent to the original exporting driver
357 so that it can identify the type of data to expect.
358 @param Type The type of value for the question.
359 @param Value A pointer to the data being sent to the original exporting driver.
360 @param ActionRequest On return, points to the action requested by the callback function.
362 @retval EFI_SUCCESS The callback successfully handled the action.
363 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
364 @retval EFI_DEVICE_ERROR The variable could not be saved.
365 @retval EFI_UNSUPPORTED The specified Action is not supported by the callback.
371 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
372 IN EFI_BROWSER_ACTION Action
,
373 IN EFI_QUESTION_ID QuestionId
,
375 IN EFI_IFR_TYPE_VALUE
*Value
,
376 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
385 //Chech whether exit from BMM and reenter frontpage,if yes,reclaim string depositories
387 if (Action
== EFI_BROWSER_ACTION_FORM_OPEN
){
389 ReclaimStringDepository();
394 if (Action
!= EFI_BROWSER_ACTION_CHANGING
&& Action
!= EFI_BROWSER_ACTION_CHANGED
) {
396 // Do nothing for other UEFI Action. Only do call back when data is changed.
398 return EFI_UNSUPPORTED
;
401 if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
402 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
403 return EFI_INVALID_PARAMETER
;
406 switch (QuestionId
) {
407 case FRONT_PAGE_KEY_CONTINUE
:
409 // This is the continue - clear the screen and return an error to get out of FrontPage loop
411 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
414 case FRONT_PAGE_KEY_LANGUAGE
:
416 // Allocate working buffer for RFC 4646 language in supported LanguageString.
418 Lang
= AllocatePool (AsciiStrSize (mLanguageString
));
419 ASSERT (Lang
!= NULL
);
422 LangCode
= mLanguageString
;
423 while (*LangCode
!= 0) {
424 GetNextLanguage (&LangCode
, Lang
);
426 if (Index
== Value
->u8
) {
433 if (Index
== Value
->u8
) {
434 Status
= gRT
->SetVariable (
436 &gEfiGlobalVariableGuid
,
437 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
441 ASSERT_EFI_ERROR(Status
);
447 //Current language of platform is changed,recreate oneof options for language.
449 InitializeLanguage();
455 } else if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
457 return EFI_INVALID_PARAMETER
;
461 // The first 4 entries in the Front Page are to be GUARANTEED to remain constant so IHV's can
462 // describe to their customers in documentation how to find their setup information (namely
463 // under the device manager and specific buckets)
465 switch (QuestionId
) {
466 case FRONT_PAGE_KEY_BOOT_MANAGER
:
470 EnumerateBootOptions ();
473 case FRONT_PAGE_KEY_DEVICE_MANAGER
:
477 CreateDeviceManagerForm(DEVICE_MANAGER_FORM_ID
);
480 case FRONT_PAGE_KEY_BOOT_MAINTAIN
:
482 // Boot Maintenance Manager
497 Initialize HII information for the FrontPage
500 @retval EFI_SUCCESS The operation is successful.
501 @retval EFI_DEVICE_ERROR If the dynamic opcode creation failed.
505 InitializeFrontPage (
512 // Locate Hii relative protocols
514 Status
= gBS
->LocateProtocol (&gEfiFormBrowser2ProtocolGuid
, NULL
, (VOID
**) &gFormBrowser2
);
515 if (EFI_ERROR (Status
)) {
520 // Install Device Path Protocol and Config Access protocol to driver handle
522 gFrontPagePrivate
.DriverHandle
= NULL
;
523 Status
= gBS
->InstallMultipleProtocolInterfaces (
524 &gFrontPagePrivate
.DriverHandle
,
525 &gEfiDevicePathProtocolGuid
,
526 &mFrontPageHiiVendorDevicePath
,
527 &gEfiHiiConfigAccessProtocolGuid
,
528 &gFrontPagePrivate
.ConfigAccess
,
531 ASSERT_EFI_ERROR (Status
);
534 // Publish our HII data
536 gFrontPagePrivate
.HiiHandle
= HiiAddPackages (
538 gFrontPagePrivate
.DriverHandle
,
543 ASSERT (gFrontPagePrivate
.HiiHandle
!= NULL
);
546 //Updata Front Page strings
548 UpdateFrontPageStrings ();
551 // Initialize laguage options
553 InitializeLanguage ();
559 Call the browser and display the front page
561 @return Status code that will be returned by
562 EFI_FORM_BROWSER2_PROTOCOL.SendForm ().
571 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
574 // Begin waiting for USER INPUT
578 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_PC_INPUT_WAIT
)
581 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
582 Status
= gFormBrowser2
->SendForm (
584 &gFrontPagePrivate
.HiiHandle
,
592 // Check whether user change any option setting which needs a reset to be effective
594 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
595 EnableResetRequired ();
602 Remove the installed packages from the HiiDatabase.
611 Status
= gBS
->UninstallMultipleProtocolInterfaces (
612 gFrontPagePrivate
.DriverHandle
,
613 &gEfiDevicePathProtocolGuid
,
614 &mFrontPageHiiVendorDevicePath
,
615 &gEfiHiiConfigAccessProtocolGuid
,
616 &gFrontPagePrivate
.ConfigAccess
,
619 ASSERT_EFI_ERROR (Status
);
622 // Publish our HII data
624 HiiRemovePackages (gFrontPagePrivate
.HiiHandle
);
625 if (gFrontPagePrivate
.LanguageToken
!= NULL
) {
626 FreePool (gFrontPagePrivate
.LanguageToken
);
627 gFrontPagePrivate
.LanguageToken
= NULL
;
632 Convert Processor Frequency Data to a string.
634 @param ProcessorFrequency The frequency data to process
635 @param Base10Exponent The exponent based on 10
636 @param String The string that is created
640 ConvertProcessorToString (
641 IN UINT16 ProcessorFrequency
,
642 IN UINT16 Base10Exponent
,
646 CHAR16
*StringBuffer
;
651 if (Base10Exponent
>= 6) {
652 FreqMhz
= ProcessorFrequency
;
653 for (Index
= 0; Index
< (UINTN
) (Base10Exponent
- 6); Index
++) {
659 DestMax
= 0x20 / sizeof (CHAR16
);
660 StringBuffer
= AllocateZeroPool (0x20);
661 ASSERT (StringBuffer
!= NULL
);
662 Index
= UnicodeValueToString (StringBuffer
, LEFT_JUSTIFY
, FreqMhz
/ 1000, 3);
663 StrCatS (StringBuffer
, DestMax
, L
".");
664 UnicodeValueToString (StringBuffer
+ Index
+ 1, PREFIX_ZERO
, (FreqMhz
% 1000) / 10, 2);
665 StrCatS (StringBuffer
, DestMax
, L
" GHz");
666 *String
= (CHAR16
*) StringBuffer
;
672 Convert Memory Size to a string.
674 @param MemorySize The size of the memory to process
675 @param String The string that is created
679 ConvertMemorySizeToString (
680 IN UINT32 MemorySize
,
684 CHAR16
*StringBuffer
;
686 StringBuffer
= AllocateZeroPool (0x24);
687 ASSERT (StringBuffer
!= NULL
);
688 UnicodeValueToString (StringBuffer
, LEFT_JUSTIFY
, MemorySize
, 10);
689 StrCatS (StringBuffer
, 0x24 / sizeof (CHAR16
), L
" MB RAM");
691 *String
= (CHAR16
*) StringBuffer
;
698 Acquire the string associated with the Index from smbios structure and return it.
699 The caller is responsible for free the string buffer.
701 @param OptionalStrStart The start position to search the string
702 @param Index The index of the string to extract
703 @param String The string that is extracted
705 @retval EFI_SUCCESS The function returns EFI_SUCCESS always.
709 GetOptionalStringByIndex (
710 IN CHAR8
*OptionalStrStart
,
718 *String
= AllocateZeroPool (sizeof (CHAR16
));
725 OptionalStrStart
+= StrSize
;
726 StrSize
= AsciiStrSize (OptionalStrStart
);
727 } while (OptionalStrStart
[StrSize
] != 0 && Index
!= 0);
729 if ((Index
!= 0) || (StrSize
== 1)) {
731 // Meet the end of strings set but Index is non-zero, or
732 // Find an empty string
734 *String
= GetStringById (STRING_TOKEN (STR_MISSING_STRING
));
736 *String
= AllocatePool (StrSize
* sizeof (CHAR16
));
737 AsciiStrToUnicodeStr (OptionalStrStart
, *String
);
745 Update the banner information for the Front Page based on Smbios information.
748 UpdateFrontPageStrings (
754 CHAR16
*FirmwareVersionString
;
757 EFI_STRING_ID TokenToUpdate
;
758 EFI_SMBIOS_HANDLE SmbiosHandle
;
759 EFI_SMBIOS_PROTOCOL
*Smbios
;
760 SMBIOS_TABLE_TYPE0
*Type0Record
;
761 SMBIOS_TABLE_TYPE1
*Type1Record
;
762 SMBIOS_TABLE_TYPE4
*Type4Record
;
763 SMBIOS_TABLE_TYPE19
*Type19Record
;
764 EFI_SMBIOS_TABLE_HEADER
*Record
;
766 ZeroMem (Find
, sizeof (Find
));
769 // Update Front Page strings
771 Status
= gBS
->LocateProtocol (
772 &gEfiSmbiosProtocolGuid
,
776 if (EFI_ERROR (Status
)) {
780 SmbiosHandle
= SMBIOS_HANDLE_PI_RESERVED
;
782 Status
= Smbios
->GetNext (Smbios
, &SmbiosHandle
, NULL
, &Record
, NULL
);
783 if (EFI_ERROR(Status
)) {
787 if (Record
->Type
== EFI_SMBIOS_TYPE_BIOS_INFORMATION
) {
788 Type0Record
= (SMBIOS_TABLE_TYPE0
*) Record
;
789 StrIndex
= Type0Record
->BiosVersion
;
790 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type0Record
+ Type0Record
->Hdr
.Length
), StrIndex
, &NewString
);
791 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION
);
792 FirmwareVersionString
= (CHAR16
*) PcdGetPtr (PcdFirmwareVersionString
);
793 if (*FirmwareVersionString
!= 0x0000 ) {
794 FreePool (NewString
);
795 NewString
= (CHAR16
*) PcdGetPtr (PcdFirmwareVersionString
);
796 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
798 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
799 FreePool (NewString
);
804 if (Record
->Type
== EFI_SMBIOS_TYPE_SYSTEM_INFORMATION
) {
805 Type1Record
= (SMBIOS_TABLE_TYPE1
*) Record
;
806 StrIndex
= Type1Record
->ProductName
;
807 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type1Record
+ Type1Record
->Hdr
.Length
), StrIndex
, &NewString
);
808 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_COMPUTER_MODEL
);
809 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
810 FreePool (NewString
);
814 if ((Record
->Type
== EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION
) && !Find
[2]) {
815 Type4Record
= (SMBIOS_TABLE_TYPE4
*) Record
;
817 // The information in the record should be only valid when the CPU Socket is populated.
819 if ((Type4Record
->Status
& SMBIOS_TYPE4_CPU_SOCKET_POPULATED
) == SMBIOS_TYPE4_CPU_SOCKET_POPULATED
) {
820 StrIndex
= Type4Record
->ProcessorVersion
;
821 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type4Record
+ Type4Record
->Hdr
.Length
), StrIndex
, &NewString
);
822 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_CPU_MODEL
);
823 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
824 FreePool (NewString
);
829 if ((Record
->Type
== EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION
) && !Find
[3]) {
830 Type4Record
= (SMBIOS_TABLE_TYPE4
*) Record
;
832 // The information in the record should be only valid when the CPU Socket is populated.
834 if ((Type4Record
->Status
& SMBIOS_TYPE4_CPU_SOCKET_POPULATED
) == SMBIOS_TYPE4_CPU_SOCKET_POPULATED
) {
835 ConvertProcessorToString(Type4Record
->CurrentSpeed
, 6, &NewString
);
836 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_CPU_SPEED
);
837 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
838 FreePool (NewString
);
843 if ( Record
->Type
== EFI_SMBIOS_TYPE_MEMORY_ARRAY_MAPPED_ADDRESS
) {
844 Type19Record
= (SMBIOS_TABLE_TYPE19
*) Record
;
845 ConvertMemorySizeToString (
846 (UINT32
)(RShiftU64((Type19Record
->EndingAddress
- Type19Record
->StartingAddress
+ 1), 10)),
849 TokenToUpdate
= STRING_TOKEN (STR_FRONT_PAGE_MEMORY_SIZE
);
850 HiiSetString (gFrontPagePrivate
.HiiHandle
, TokenToUpdate
, NewString
, NULL
);
851 FreePool (NewString
);
854 } while ( !(Find
[0] && Find
[1] && Find
[2] && Find
[3] && Find
[4]));
859 This function will change video resolution and text mode
860 according to defined setup mode or defined boot mode
862 @param IsSetupMode Indicate mode is changed to setup mode or boot mode.
864 @retval EFI_SUCCESS Mode is changed successfully.
865 @retval Others Mode failed to be changed.
874 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
875 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
877 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
881 UINT32 NewHorizontalResolution
;
882 UINT32 NewVerticalResolution
;
886 EFI_HANDLE
*HandleBuffer
;
896 // Get current video resolution and text mode
898 Status
= gBS
->HandleProtocol (
899 gST
->ConsoleOutHandle
,
900 &gEfiGraphicsOutputProtocolGuid
,
901 (VOID
**)&GraphicsOutput
903 if (EFI_ERROR (Status
)) {
904 GraphicsOutput
= NULL
;
907 Status
= gBS
->HandleProtocol (
908 gST
->ConsoleOutHandle
,
909 &gEfiSimpleTextOutProtocolGuid
,
910 (VOID
**)&SimpleTextOut
912 if (EFI_ERROR (Status
)) {
913 SimpleTextOut
= NULL
;
916 if ((GraphicsOutput
== NULL
) || (SimpleTextOut
== NULL
)) {
917 return EFI_UNSUPPORTED
;
922 // The requried resolution and text mode is setup mode.
924 NewHorizontalResolution
= mSetupHorizontalResolution
;
925 NewVerticalResolution
= mSetupVerticalResolution
;
926 NewColumns
= mSetupTextModeColumn
;
927 NewRows
= mSetupTextModeRow
;
930 // The required resolution and text mode is boot mode.
932 NewHorizontalResolution
= mBootHorizontalResolution
;
933 NewVerticalResolution
= mBootVerticalResolution
;
934 NewColumns
= mBootTextModeColumn
;
935 NewRows
= mBootTextModeRow
;
938 if (GraphicsOutput
!= NULL
) {
939 MaxGopMode
= GraphicsOutput
->Mode
->MaxMode
;
942 if (SimpleTextOut
!= NULL
) {
943 MaxTextMode
= SimpleTextOut
->Mode
->MaxMode
;
947 // 1. If current video resolution is same with required video resolution,
948 // video resolution need not be changed.
949 // 1.1. If current text mode is same with required text mode, text mode need not be changed.
950 // 1.2. If current text mode is different from required text mode, text mode need be changed.
951 // 2. If current video resolution is different from required video resolution, we need restart whole console drivers.
953 for (ModeNumber
= 0; ModeNumber
< MaxGopMode
; ModeNumber
++) {
954 Status
= GraphicsOutput
->QueryMode (
960 if (!EFI_ERROR (Status
)) {
961 if ((Info
->HorizontalResolution
== NewHorizontalResolution
) &&
962 (Info
->VerticalResolution
== NewVerticalResolution
)) {
963 if ((GraphicsOutput
->Mode
->Info
->HorizontalResolution
== NewHorizontalResolution
) &&
964 (GraphicsOutput
->Mode
->Info
->VerticalResolution
== NewVerticalResolution
)) {
966 // Current resolution is same with required resolution, check if text mode need be set
968 Status
= SimpleTextOut
->QueryMode (SimpleTextOut
, SimpleTextOut
->Mode
->Mode
, &CurrentColumn
, &CurrentRow
);
969 ASSERT_EFI_ERROR (Status
);
970 if (CurrentColumn
== NewColumns
&& CurrentRow
== NewRows
) {
972 // If current text mode is same with required text mode. Do nothing
978 // If current text mode is different from requried text mode. Set new video mode
980 for (Index
= 0; Index
< MaxTextMode
; Index
++) {
981 Status
= SimpleTextOut
->QueryMode (SimpleTextOut
, Index
, &CurrentColumn
, &CurrentRow
);
982 if (!EFI_ERROR(Status
)) {
983 if ((CurrentColumn
== NewColumns
) && (CurrentRow
== NewRows
)) {
985 // Required text mode is supported, set it.
987 Status
= SimpleTextOut
->SetMode (SimpleTextOut
, Index
);
988 ASSERT_EFI_ERROR (Status
);
990 // Update text mode PCD.
992 PcdSet32 (PcdConOutColumn
, mSetupTextModeColumn
);
993 PcdSet32 (PcdConOutRow
, mSetupTextModeRow
);
999 if (Index
== MaxTextMode
) {
1001 // If requried text mode is not supported, return error.
1004 return EFI_UNSUPPORTED
;
1009 // If current video resolution is not same with the new one, set new video resolution.
1010 // In this case, the driver which produces simple text out need be restarted.
1012 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, ModeNumber
);
1013 if (!EFI_ERROR (Status
)) {
1023 if (ModeNumber
== MaxGopMode
) {
1025 // If the resolution is not supported, return error.
1027 return EFI_UNSUPPORTED
;
1031 // Set PCD to Inform GraphicsConsole to change video resolution.
1032 // Set PCD to Inform Consplitter to change text mode.
1034 PcdSet32 (PcdVideoHorizontalResolution
, NewHorizontalResolution
);
1035 PcdSet32 (PcdVideoVerticalResolution
, NewVerticalResolution
);
1036 PcdSet32 (PcdConOutColumn
, NewColumns
);
1037 PcdSet32 (PcdConOutRow
, NewRows
);
1041 // Video mode is changed, so restart graphics console driver and higher level driver.
1042 // Reconnect graphics console driver and higher level driver.
1043 // Locate all the handles with GOP protocol and reconnect it.
1045 Status
= gBS
->LocateHandleBuffer (
1047 &gEfiSimpleTextOutProtocolGuid
,
1052 if (!EFI_ERROR (Status
)) {
1053 for (Index
= 0; Index
< HandleCount
; Index
++) {
1054 gBS
->DisconnectController (HandleBuffer
[Index
], NULL
, NULL
);
1056 for (Index
= 0; Index
< HandleCount
; Index
++) {
1057 gBS
->ConnectController (HandleBuffer
[Index
], NULL
, NULL
, TRUE
);
1059 if (HandleBuffer
!= NULL
) {
1060 FreePool (HandleBuffer
);
1068 The user Entry Point for Application. The user code starts with this function
1069 as the real entry point for the image goes into a library that calls this
1072 @param[in] ImageHandle The firmware allocated handle for the EFI image.
1073 @param[in] SystemTable A pointer to the EFI System Table.
1075 @retval EFI_SUCCESS The entry point is executed successfully.
1076 @retval other Some error occurs when executing this entry point.
1081 InitializeUserInterface (
1082 IN EFI_HANDLE ImageHandle
,
1083 IN EFI_SYSTEM_TABLE
*SystemTable
1086 EFI_HII_HANDLE HiiHandle
;
1088 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
1089 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
1090 UINTN BootTextColumn
;
1093 if (!mModeInitialized
) {
1095 // After the console is ready, get current video resolution
1096 // and text mode before launching setup at first time.
1098 Status
= gBS
->HandleProtocol (
1099 gST
->ConsoleOutHandle
,
1100 &gEfiGraphicsOutputProtocolGuid
,
1101 (VOID
**)&GraphicsOutput
1103 if (EFI_ERROR (Status
)) {
1104 GraphicsOutput
= NULL
;
1107 Status
= gBS
->HandleProtocol (
1108 gST
->ConsoleOutHandle
,
1109 &gEfiSimpleTextOutProtocolGuid
,
1110 (VOID
**)&SimpleTextOut
1112 if (EFI_ERROR (Status
)) {
1113 SimpleTextOut
= NULL
;
1116 if (GraphicsOutput
!= NULL
) {
1118 // Get current video resolution and text mode.
1120 mBootHorizontalResolution
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
1121 mBootVerticalResolution
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
1124 if (SimpleTextOut
!= NULL
) {
1125 Status
= SimpleTextOut
->QueryMode (
1127 SimpleTextOut
->Mode
->Mode
,
1131 mBootTextModeColumn
= (UINT32
)BootTextColumn
;
1132 mBootTextModeRow
= (UINT32
)BootTextRow
;
1136 // Get user defined text mode for setup.
1138 mSetupHorizontalResolution
= PcdGet32 (PcdSetupVideoHorizontalResolution
);
1139 mSetupVerticalResolution
= PcdGet32 (PcdSetupVideoVerticalResolution
);
1140 mSetupTextModeColumn
= PcdGet32 (PcdSetupConOutColumn
);
1141 mSetupTextModeRow
= PcdGet32 (PcdSetupConOutRow
);
1143 mModeInitialized
= TRUE
;
1146 gBS
->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL
);
1147 gST
->ConOut
->ClearScreen (gST
->ConOut
);
1150 // Install customized fonts needed by Front Page
1153 HiiHandle
= ExportFonts ();
1154 ASSERT (HiiHandle
!= NULL
);
1156 InitializeStringSupport ();
1158 BdsSetConsoleMode (TRUE
);
1160 BdsSetConsoleMode (FALSE
);
1162 UninitializeStringSupport ();
1163 HiiRemovePackages (HiiHandle
);
1169 This function is the main entry of the UI entry.
1170 The function will present the main menu of the system UI.
1172 @param ConnectAllHappened Caller passes the value to UI to avoid unnecessary connect-all.
1178 IN BOOLEAN ConnectAllHappened
1182 EFI_BOOT_LOGO_PROTOCOL
*BootLogo
;
1185 // Indicate if the connect all has been performed before.
1187 if (ConnectAllHappened
) {
1188 gConnectAllHappened
= TRUE
;
1192 // The boot option enumeration time is acceptable in Ui driver
1194 EfiBootManagerRefreshAllBootOption ();
1197 // Boot Logo is corrupted, report it using Boot Logo protocol.
1199 Status
= gBS
->LocateProtocol (&gEfiBootLogoProtocolGuid
, NULL
, (VOID
**) &BootLogo
);
1200 if (!EFI_ERROR (Status
) && (BootLogo
!= NULL
)) {
1201 BootLogo
->SetBootLogo (BootLogo
, NULL
, 0, 0, 0, 0);
1204 InitializeFrontPage ();
1205 InitializeDeviceManager ();
1206 InitializeBootManager ();
1207 InitBootMaintenance();
1213 FreeDeviceManager ();
1216 if (mLanguageString
!= NULL
) {
1217 FreePool (mLanguageString
);
1218 mLanguageString
= NULL
;
1222 //Will leave browser, check any reset required change is applied? if yes, reset system
1224 SetupResetReminder ();
1228 Extract device path for given HII handle and class guid.
1230 @param Handle The HII handle.
1232 @retval NULL Fail to get the device path string.
1233 @return PathString Get the device path string.
1237 ExtractDevicePathFromHiiHandle (
1238 IN EFI_HII_HANDLE Handle
1242 EFI_HANDLE DriverHandle
;
1243 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1244 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL
*PathToText
;
1247 ASSERT (Handle
!= NULL
);
1249 if (Handle
== NULL
) {
1253 Status
= gHiiDatabase
->GetPackageListHandle (gHiiDatabase
, Handle
, &DriverHandle
);
1254 if (EFI_ERROR (Status
)) {
1259 // Get the device path by the got Driver handle .
1261 Status
= gBS
->HandleProtocol (DriverHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**) &DevicePath
);
1262 if (EFI_ERROR (Status
)) {
1266 Status
= gBS
->LocateProtocol (
1267 &gEfiDevicePathToTextProtocolGuid
,
1269 (VOID
**) &PathToText
1271 if (EFI_ERROR (Status
)) {
1276 // Get device path string.
1278 NewString
= PathToText
->ConvertDevicePathToText(DevicePath
, FALSE
, FALSE
);
1284 Extract the displayed formset for given HII handle and class guid.
1286 @param Handle The HII handle.
1287 @param SetupClassGuid The class guid specifies which form set will be displayed.
1288 @param SkipCount Skip some formsets which has processed before.
1289 @param FormSetTitle Formset title string.
1290 @param FormSetHelp Formset help string.
1291 @param FormSetGuid Formset Guid.
1293 @retval TRUE The formset for given HII handle will be displayed.
1294 @return FALSE The formset for given HII handle will not be displayed.
1298 ExtractDisplayedHiiFormFromHiiHandle (
1299 IN EFI_HII_HANDLE Handle
,
1300 IN EFI_GUID
*SetupClassGuid
,
1302 OUT EFI_STRING_ID
*FormSetTitle
,
1303 OUT EFI_STRING_ID
*FormSetHelp
,
1304 OUT EFI_GUID
*FormSetGuid
1309 EFI_HII_PACKAGE_LIST_HEADER
*HiiPackageList
;
1314 UINT32 PackageListLength
;
1315 EFI_HII_PACKAGE_HEADER PackageHeader
;
1316 EFI_GUID
*ClassGuid
;
1318 BOOLEAN FoundAndSkip
;
1320 ASSERT (Handle
!= NULL
);
1321 ASSERT (SetupClassGuid
!= NULL
&& FormSetTitle
!= NULL
&& FormSetHelp
!= NULL
&& FormSetGuid
!= NULL
);
1327 FoundAndSkip
= FALSE
;
1330 // Get HII PackageList
1333 HiiPackageList
= NULL
;
1334 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
1336 // Handle is a invalid handle. Check if Handle is corrupted.
1338 ASSERT (Status
!= EFI_NOT_FOUND
);
1340 // The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0.
1342 ASSERT (Status
== EFI_BUFFER_TOO_SMALL
);
1344 HiiPackageList
= AllocatePool (BufferSize
);
1345 ASSERT (HiiPackageList
!= NULL
);
1347 Status
= gHiiDatabase
->ExportPackageLists (gHiiDatabase
, Handle
, &BufferSize
, HiiPackageList
);
1348 if (EFI_ERROR (Status
)) {
1353 // Get Form package from this HII package List
1355 Offset
= sizeof (EFI_HII_PACKAGE_LIST_HEADER
);
1356 PackageListLength
= ReadUnaligned32 (&HiiPackageList
->PackageLength
);
1358 while (Offset
< PackageListLength
) {
1359 Package
= ((UINT8
*) HiiPackageList
) + Offset
;
1360 CopyMem (&PackageHeader
, Package
, sizeof (EFI_HII_PACKAGE_HEADER
));
1361 Offset
+= PackageHeader
.Length
;
1363 if (PackageHeader
.Type
== EFI_HII_PACKAGE_FORMS
) {
1365 // Search FormSet Opcode in this Form Package
1367 Offset2
= sizeof (EFI_HII_PACKAGE_HEADER
);
1368 while (Offset2
< PackageHeader
.Length
) {
1369 OpCodeData
= Package
+ Offset2
;
1370 Offset2
+= ((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
;
1372 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->OpCode
== EFI_IFR_FORM_SET_OP
) {
1373 if (((EFI_IFR_OP_HEADER
*) OpCodeData
)->Length
> OFFSET_OF (EFI_IFR_FORM_SET
, Flags
)) {
1375 // Find FormSet OpCode
1377 ClassGuidNum
= (UINT8
) (((EFI_IFR_FORM_SET
*) OpCodeData
)->Flags
& 0x3);
1378 ClassGuid
= (EFI_GUID
*) (VOID
*)(OpCodeData
+ sizeof (EFI_IFR_FORM_SET
));
1379 while (ClassGuidNum
-- > 0) {
1380 if (CompareGuid (SetupClassGuid
, ClassGuid
)) {
1382 // Check whether need to skip the formset.
1384 if (SkipCount
!= 0) {
1386 FoundAndSkip
= TRUE
;
1389 CopyMem (FormSetTitle
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->FormSetTitle
, sizeof (EFI_STRING_ID
));
1390 CopyMem (FormSetHelp
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Help
, sizeof (EFI_STRING_ID
));
1391 CopyGuid (FormSetGuid
, (CONST EFI_GUID
*)(&((EFI_IFR_FORM_SET
*) OpCodeData
)->Guid
));
1392 FreePool (HiiPackageList
);
1400 } else if (CompareGuid (SetupClassGuid
, &gEfiHiiPlatformSetupFormsetGuid
)) {
1402 // Check whether need to skip the formset.
1404 if (SkipCount
!= 0) {
1408 CopyMem (FormSetTitle
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->FormSetTitle
, sizeof (EFI_STRING_ID
));
1409 CopyMem (FormSetHelp
, &((EFI_IFR_FORM_SET
*) OpCodeData
)->Help
, sizeof (EFI_STRING_ID
));
1410 CopyGuid (FormSetGuid
, (CONST EFI_GUID
*)(&((EFI_IFR_FORM_SET
*) OpCodeData
)->Guid
));
1411 FreePool (HiiPackageList
);
1419 FreePool (HiiPackageList
);
1425 // Following are BDS Lib functions which contain all the code about setup browser reset reminder feature.
1426 // Setup Browser reset reminder feature is that an reset reminder will be given before user leaves the setup browser if
1427 // user change any option setting which needs a reset to be effective, and the reset will be applied according to the user selection.
1432 Enable the setup browser reset reminder feature.
1433 This routine is used in platform tip. If the platform policy need the feature, use the routine to enable it.
1438 EnableResetReminderFeature (
1442 mFeaturerSwitch
= TRUE
;
1447 Disable the setup browser reset reminder feature.
1448 This routine is used in platform tip. If the platform policy do not want the feature, use the routine to disable it.
1453 DisableResetReminderFeature (
1457 mFeaturerSwitch
= FALSE
;
1462 Record the info that a reset is required.
1463 A module boolean variable is used to record whether a reset is required.
1468 EnableResetRequired (
1472 mResetRequired
= TRUE
;
1477 Record the info that no reset is required.
1478 A module boolean variable is used to record whether a reset is required.
1483 DisableResetRequired (
1487 mResetRequired
= FALSE
;
1492 Check whether platform policy enable the reset reminder feature. The default is enabled.
1497 IsResetReminderFeatureEnable (
1501 return mFeaturerSwitch
;
1506 Check if user changed any option setting which needs a system reset to be effective.
1515 return mResetRequired
;
1520 Check whether a reset is needed, and finish the reset reminder feature.
1521 If a reset is needed, Popup a menu to notice user, and finish the feature
1522 according to the user selection.
1527 SetupResetReminder (
1532 CHAR16
*StringBuffer1
;
1533 CHAR16
*StringBuffer2
;
1537 //check any reset required change is applied? if yes, reset system
1539 if (IsResetReminderFeatureEnable ()) {
1540 if (IsResetRequired ()) {
1542 StringBuffer1
= AllocateZeroPool (MAX_STRING_LEN
* sizeof (CHAR16
));
1543 ASSERT (StringBuffer1
!= NULL
);
1544 StringBuffer2
= AllocateZeroPool (MAX_STRING_LEN
* sizeof (CHAR16
));
1545 ASSERT (StringBuffer2
!= NULL
);
1546 StrCpyS (StringBuffer1
, MAX_STRING_LEN
, L
"Configuration changed. Reset to apply it Now.");
1547 StrCpyS (StringBuffer2
, MAX_STRING_LEN
, L
"Press ENTER to reset");
1549 // Popup a menu to notice user
1552 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, StringBuffer1
, StringBuffer2
, NULL
);
1553 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1555 FreePool (StringBuffer1
);
1556 FreePool (StringBuffer2
);
1558 gRT
->ResetSystem (EfiResetCold
, EFI_SUCCESS
, 0, NULL
);
1565 This function converts an input device structure to a Unicode string.
1567 @param DevPath A pointer to the device path structure.
1569 @return A new allocated Unicode string that represents the device path.
1574 IN EFI_DEVICE_PATH_PROTOCOL
*DevPath
1579 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL
*DevPathToText
;
1581 if (DevPath
== NULL
) {
1585 Status
= gBS
->LocateProtocol (
1586 &gEfiDevicePathToTextProtocolGuid
,
1588 (VOID
**) &DevPathToText
1590 ASSERT_EFI_ERROR (Status
);
1591 ToText
= DevPathToText
->ConvertDevicePathToText (
1596 ASSERT (ToText
!= NULL
);