2 FrontPage routines to handle the callbacks and browser calls
4 Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2018 Hewlett Packard Enterprise Development LP<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "FrontPage.h"
11 #include "FrontPageCustomizedUi.h"
13 #define MAX_STRING_LEN 200
15 EFI_GUID mFrontPageGuid
= FRONT_PAGE_FORMSET_GUID
;
17 BOOLEAN mResetRequired
= FALSE
;
19 EFI_FORM_BROWSER2_PROTOCOL
*gFormBrowser2
;
20 CHAR8
*mLanguageString
;
21 BOOLEAN mModeInitialized
= FALSE
;
23 // Boot video resolution and text mode.
25 UINT32 mBootHorizontalResolution
= 0;
26 UINT32 mBootVerticalResolution
= 0;
27 UINT32 mBootTextModeColumn
= 0;
28 UINT32 mBootTextModeRow
= 0;
30 // BIOS setup video resolution and text mode.
32 UINT32 mSetupTextModeColumn
= 0;
33 UINT32 mSetupTextModeRow
= 0;
34 UINT32 mSetupHorizontalResolution
= 0;
35 UINT32 mSetupVerticalResolution
= 0;
37 FRONT_PAGE_CALLBACK_DATA gFrontPagePrivate
= {
38 FRONT_PAGE_CALLBACK_DATA_SIGNATURE
,
49 HII_VENDOR_DEVICE_PATH mFrontPageHiiVendorDevicePath
= {
55 (UINT8
)(sizeof (VENDOR_DEVICE_PATH
)),
56 (UINT8
)((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
60 // {8E6D99EE-7531-48f8-8745-7F6144468FF2}
62 { 0x8e6d99ee, 0x7531, 0x48f8, { 0x87, 0x45, 0x7f, 0x61, 0x44, 0x46, 0x8f, 0xf2 }
67 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
69 (UINT8
)(END_DEVICE_PATH_LENGTH
),
70 (UINT8
)((END_DEVICE_PATH_LENGTH
) >> 8)
76 Update the banner information for the Front Page based on Smbios information.
80 UpdateFrontPageBannerStrings (
85 This function allows a caller to extract the current configuration for one
86 or more named elements from the target driver.
89 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
90 @param Request A null-terminated Unicode string in <ConfigRequest> format.
91 @param Progress On return, points to a character in the Request string.
92 Points to the string's null terminator if request was successful.
93 Points to the most recent '&' before the first failing name/value
94 pair (or the beginning of the string if the failure is in the
95 first name/value pair) if the request was not successful.
96 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
97 has all values filled in for the names in the Request string.
98 String to be allocated by the called function.
100 @retval EFI_SUCCESS The Results is filled with the requested values.
101 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
102 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
103 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
109 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
110 IN CONST EFI_STRING Request
,
111 OUT EFI_STRING
*Progress
,
112 OUT EFI_STRING
*Results
115 if ((Progress
== NULL
) || (Results
== NULL
)) {
116 return EFI_INVALID_PARAMETER
;
120 return EFI_NOT_FOUND
;
124 This function processes the results of changes in configuration.
127 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
128 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
129 @param Progress A pointer to a string filled in with the offset of the most
130 recent '&' before the first failing name/value pair (or the
131 beginning of the string if the failure is in the first
132 name/value pair) or the terminating NULL if all was successful.
134 @retval EFI_SUCCESS The Results is processed successfully.
135 @retval EFI_INVALID_PARAMETER Configuration is NULL.
136 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
142 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
143 IN CONST EFI_STRING Configuration
,
144 OUT EFI_STRING
*Progress
147 if ((Configuration
== NULL
) || (Progress
== NULL
)) {
148 return EFI_INVALID_PARAMETER
;
151 *Progress
= Configuration
;
153 return EFI_NOT_FOUND
;
157 This function processes the results of changes in configuration.
160 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
161 @param Action Specifies the type of action taken by the browser.
162 @param QuestionId A unique value which is sent to the original exporting driver
163 so that it can identify the type of data to expect.
164 @param Type The type of value for the question.
165 @param Value A pointer to the data being sent to the original exporting driver.
166 @param ActionRequest On return, points to the action requested by the callback function.
168 @retval EFI_SUCCESS The callback successfully handled the action.
169 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
170 @retval EFI_DEVICE_ERROR The variable could not be saved.
171 @retval EFI_UNSUPPORTED The specified Action is not supported by the callback.
177 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
178 IN EFI_BROWSER_ACTION Action
,
179 IN EFI_QUESTION_ID QuestionId
,
181 IN EFI_IFR_TYPE_VALUE
*Value
,
182 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
185 return UiFrontPageCallbackHandler (gFrontPagePrivate
.HiiHandle
, Action
, QuestionId
, Type
, Value
, ActionRequest
);
190 Update the menus in the front page.
194 UpdateFrontPageForm (
198 VOID
*StartOpCodeHandle
;
199 VOID
*EndOpCodeHandle
;
200 EFI_IFR_GUID_LABEL
*StartGuidLabel
;
201 EFI_IFR_GUID_LABEL
*EndGuidLabel
;
204 // Allocate space for creation of UpdateData Buffer
206 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
207 ASSERT (StartOpCodeHandle
!= NULL
);
209 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
210 ASSERT (EndOpCodeHandle
!= NULL
);
212 // Create Hii Extend Label OpCode as the start opcode
214 StartGuidLabel
= (EFI_IFR_GUID_LABEL
*)HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
215 StartGuidLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
216 StartGuidLabel
->Number
= LABEL_FRONTPAGE_INFORMATION
;
218 // Create Hii Extend Label OpCode as the end opcode
220 EndGuidLabel
= (EFI_IFR_GUID_LABEL
*)HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
221 EndGuidLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
222 EndGuidLabel
->Number
= LABEL_END
;
225 // Updata Front Page form
227 UiCustomizeFrontPage (
228 gFrontPagePrivate
.HiiHandle
,
233 gFrontPagePrivate
.HiiHandle
,
240 HiiFreeOpCodeHandle (StartOpCodeHandle
);
241 HiiFreeOpCodeHandle (EndOpCodeHandle
);
245 Initialize HII information for the FrontPage
248 @retval EFI_SUCCESS The operation is successful.
249 @retval EFI_DEVICE_ERROR If the dynamic opcode creation failed.
253 InitializeFrontPage (
260 // Locate Hii relative protocols
262 Status
= gBS
->LocateProtocol (&gEfiFormBrowser2ProtocolGuid
, NULL
, (VOID
**)&gFormBrowser2
);
263 if (EFI_ERROR (Status
)) {
268 // Install Device Path Protocol and Config Access protocol to driver handle
270 gFrontPagePrivate
.DriverHandle
= NULL
;
271 Status
= gBS
->InstallMultipleProtocolInterfaces (
272 &gFrontPagePrivate
.DriverHandle
,
273 &gEfiDevicePathProtocolGuid
,
274 &mFrontPageHiiVendorDevicePath
,
275 &gEfiHiiConfigAccessProtocolGuid
,
276 &gFrontPagePrivate
.ConfigAccess
,
279 ASSERT_EFI_ERROR (Status
);
282 // Publish our HII data
284 gFrontPagePrivate
.HiiHandle
= HiiAddPackages (
286 gFrontPagePrivate
.DriverHandle
,
291 ASSERT (gFrontPagePrivate
.HiiHandle
!= NULL
);
294 // Updata Front Page banner strings
296 UpdateFrontPageBannerStrings ();
299 // Update front page menus.
301 UpdateFrontPageForm ();
307 Call the browser and display the front page
309 @return Status code that will be returned by
310 EFI_FORM_BROWSER2_PROTOCOL.SendForm ().
319 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
322 // Begin waiting for USER INPUT
326 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_PC_INPUT_WAIT
)
329 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
330 Status
= gFormBrowser2
->SendForm (
332 &gFrontPagePrivate
.HiiHandle
,
340 // Check whether user change any option setting which needs a reset to be effective
342 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
343 EnableResetRequired ();
350 Remove the installed packages from the HiiDatabase.
360 Status
= gBS
->UninstallMultipleProtocolInterfaces (
361 gFrontPagePrivate
.DriverHandle
,
362 &gEfiDevicePathProtocolGuid
,
363 &mFrontPageHiiVendorDevicePath
,
364 &gEfiHiiConfigAccessProtocolGuid
,
365 &gFrontPagePrivate
.ConfigAccess
,
368 ASSERT_EFI_ERROR (Status
);
371 // Publish our HII data
373 HiiRemovePackages (gFrontPagePrivate
.HiiHandle
);
374 if (gFrontPagePrivate
.LanguageToken
!= NULL
) {
375 FreePool (gFrontPagePrivate
.LanguageToken
);
376 gFrontPagePrivate
.LanguageToken
= NULL
;
381 Convert Processor Frequency Data to a string.
383 @param ProcessorFrequency The frequency data to process
384 @param Base10Exponent The exponent based on 10
385 @param String The string that is created
389 ConvertProcessorToString (
390 IN UINT16 ProcessorFrequency
,
391 IN UINT16 Base10Exponent
,
395 CHAR16
*StringBuffer
;
400 if (Base10Exponent
>= 6) {
401 FreqMhz
= ProcessorFrequency
;
402 for (Index
= 0; Index
< (UINT32
)Base10Exponent
- 6; Index
++) {
409 DestMax
= 0x20 / sizeof (CHAR16
);
410 StringBuffer
= AllocateZeroPool (0x20);
411 ASSERT (StringBuffer
!= NULL
);
412 UnicodeValueToStringS (StringBuffer
, sizeof (CHAR16
) * DestMax
, LEFT_JUSTIFY
, FreqMhz
/ 1000, 3);
413 Index
= StrnLenS (StringBuffer
, DestMax
);
414 StrCatS (StringBuffer
, DestMax
, L
".");
415 UnicodeValueToStringS (
416 StringBuffer
+ Index
+ 1,
417 sizeof (CHAR16
) * (DestMax
- (Index
+ 1)),
419 (FreqMhz
% 1000) / 10,
422 StrCatS (StringBuffer
, DestMax
, L
" GHz");
423 *String
= (CHAR16
*)StringBuffer
;
428 Convert Memory Size to a string.
430 @param MemorySize The size of the memory to process
431 @param String The string that is created
435 ConvertMemorySizeToString (
436 IN UINT32 MemorySize
,
440 CHAR16
*StringBuffer
;
442 StringBuffer
= AllocateZeroPool (0x24);
443 ASSERT (StringBuffer
!= NULL
);
444 UnicodeValueToStringS (StringBuffer
, 0x24, LEFT_JUSTIFY
, MemorySize
, 10);
445 StrCatS (StringBuffer
, 0x24 / sizeof (CHAR16
), L
" MB RAM");
447 *String
= (CHAR16
*)StringBuffer
;
454 Acquire the string associated with the Index from smbios structure and return it.
455 The caller is responsible for free the string buffer.
457 @param OptionalStrStart The start position to search the string
458 @param Index The index of the string to extract
459 @param String The string that is extracted
461 @retval EFI_SUCCESS The function returns EFI_SUCCESS always.
465 GetOptionalStringByIndex (
466 IN CHAR8
*OptionalStrStart
,
474 *String
= AllocateZeroPool (sizeof (CHAR16
));
481 OptionalStrStart
+= StrSize
;
482 StrSize
= AsciiStrSize (OptionalStrStart
);
483 } while (OptionalStrStart
[StrSize
] != 0 && Index
!= 0);
485 if ((Index
!= 0) || (StrSize
== 1)) {
487 // Meet the end of strings set but Index is non-zero, or
488 // Find an empty string
490 *String
= GetStringById (STRING_TOKEN (STR_MISSING_STRING
));
492 *String
= AllocatePool (StrSize
* sizeof (CHAR16
));
493 AsciiStrToUnicodeStrS (OptionalStrStart
, *String
, StrSize
);
501 Update the banner information for the Front Page based on Smbios information.
505 UpdateFrontPageBannerStrings (
511 CHAR16
*FirmwareVersionString
;
513 EFI_SMBIOS_HANDLE SmbiosHandle
;
514 EFI_SMBIOS_PROTOCOL
*Smbios
;
515 SMBIOS_TABLE_TYPE0
*Type0Record
;
516 SMBIOS_TABLE_TYPE1
*Type1Record
;
517 SMBIOS_TABLE_TYPE4
*Type4Record
;
518 SMBIOS_TABLE_TYPE19
*Type19Record
;
519 EFI_SMBIOS_TABLE_HEADER
*Record
;
520 UINT64 InstalledMemory
;
527 // Update default banner string.
529 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE4_LEFT
), NULL
);
530 UiCustomizeFrontPageBanner (4, TRUE
, &NewString
);
531 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE4_LEFT
), NewString
, NULL
);
532 FreePool (NewString
);
534 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE4_RIGHT
), NULL
);
535 UiCustomizeFrontPageBanner (4, FALSE
, &NewString
);
536 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE4_RIGHT
), NewString
, NULL
);
537 FreePool (NewString
);
539 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE5_LEFT
), NULL
);
540 UiCustomizeFrontPageBanner (5, TRUE
, &NewString
);
541 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE5_LEFT
), NewString
, NULL
);
542 FreePool (NewString
);
544 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE5_RIGHT
), NULL
);
545 UiCustomizeFrontPageBanner (5, FALSE
, &NewString
);
546 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE5_RIGHT
), NewString
, NULL
);
547 FreePool (NewString
);
550 // Update Front Page banner strings base on SmBios Table.
552 Status
= gBS
->LocateProtocol (&gEfiSmbiosProtocolGuid
, NULL
, (VOID
**)&Smbios
);
553 if (EFI_ERROR (Status
)) {
555 // Smbios protocol not found, get the default value.
557 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_COMPUTER_MODEL
), NULL
);
558 UiCustomizeFrontPageBanner (1, TRUE
, &NewString
);
559 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_COMPUTER_MODEL
), NewString
, NULL
);
560 FreePool (NewString
);
562 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_CPU_MODEL
), NULL
);
563 UiCustomizeFrontPageBanner (2, TRUE
, &NewString
);
564 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_CPU_MODEL
), NewString
, NULL
);
565 FreePool (NewString
);
567 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_CPU_SPEED
), NULL
);
568 UiCustomizeFrontPageBanner (2, FALSE
, &NewString
);
569 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_CPU_SPEED
), NewString
, NULL
);
570 FreePool (NewString
);
572 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION
), NULL
);
573 UiCustomizeFrontPageBanner (3, TRUE
, &NewString
);
574 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION
), NewString
, NULL
);
575 FreePool (NewString
);
577 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_MEMORY_SIZE
), NULL
);
578 UiCustomizeFrontPageBanner (3, FALSE
, &NewString
);
579 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_MEMORY_SIZE
), NewString
, NULL
);
580 FreePool (NewString
);
585 SmbiosHandle
= SMBIOS_HANDLE_PI_RESERVED
;
586 Status
= Smbios
->GetNext (Smbios
, &SmbiosHandle
, NULL
, &Record
, NULL
);
587 while (!EFI_ERROR (Status
)) {
588 if (Record
->Type
== SMBIOS_TYPE_BIOS_INFORMATION
) {
589 Type0Record
= (SMBIOS_TABLE_TYPE0
*)Record
;
590 StrIndex
= Type0Record
->BiosVersion
;
591 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type0Record
+ Type0Record
->Hdr
.Length
), StrIndex
, &NewString
);
593 FirmwareVersionString
= (CHAR16
*)PcdGetPtr (PcdFirmwareVersionString
);
594 if (*FirmwareVersionString
!= 0x0000 ) {
595 FreePool (NewString
);
596 NewString
= (CHAR16
*)PcdGetPtr (PcdFirmwareVersionString
);
597 UiCustomizeFrontPageBanner (3, TRUE
, &NewString
);
598 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION
), NewString
, NULL
);
600 UiCustomizeFrontPageBanner (3, TRUE
, &NewString
);
601 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION
), NewString
, NULL
);
602 FreePool (NewString
);
606 if (Record
->Type
== SMBIOS_TYPE_SYSTEM_INFORMATION
) {
607 Type1Record
= (SMBIOS_TABLE_TYPE1
*)Record
;
608 StrIndex
= Type1Record
->ProductName
;
609 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type1Record
+ Type1Record
->Hdr
.Length
), StrIndex
, &NewString
);
610 UiCustomizeFrontPageBanner (1, TRUE
, &NewString
);
611 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_COMPUTER_MODEL
), NewString
, NULL
);
612 FreePool (NewString
);
615 if ((Record
->Type
== SMBIOS_TYPE_PROCESSOR_INFORMATION
) && !FoundCpu
) {
616 Type4Record
= (SMBIOS_TABLE_TYPE4
*)Record
;
618 // The information in the record should be only valid when the CPU Socket is populated.
620 if ((Type4Record
->Status
& SMBIOS_TYPE4_CPU_SOCKET_POPULATED
) == SMBIOS_TYPE4_CPU_SOCKET_POPULATED
) {
621 StrIndex
= Type4Record
->ProcessorVersion
;
622 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type4Record
+ Type4Record
->Hdr
.Length
), StrIndex
, &NewString
);
623 UiCustomizeFrontPageBanner (2, TRUE
, &NewString
);
624 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_CPU_MODEL
), NewString
, NULL
);
625 FreePool (NewString
);
627 ConvertProcessorToString (Type4Record
->CurrentSpeed
, 6, &NewString
);
628 UiCustomizeFrontPageBanner (2, FALSE
, &NewString
);
629 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_CPU_SPEED
), NewString
, NULL
);
630 FreePool (NewString
);
636 if ( Record
->Type
== SMBIOS_TYPE_MEMORY_ARRAY_MAPPED_ADDRESS
) {
637 Type19Record
= (SMBIOS_TABLE_TYPE19
*)Record
;
638 if (Type19Record
->StartingAddress
!= 0xFFFFFFFF ) {
639 InstalledMemory
+= RShiftU64 (
640 Type19Record
->EndingAddress
-
641 Type19Record
->StartingAddress
+ 1,
645 InstalledMemory
+= RShiftU64 (
646 Type19Record
->ExtendedEndingAddress
-
647 Type19Record
->ExtendedStartingAddress
+ 1,
653 Status
= Smbios
->GetNext (Smbios
, &SmbiosHandle
, NULL
, &Record
, NULL
);
657 // Now update the total installed RAM size
659 ConvertMemorySizeToString ((UINT32
)InstalledMemory
, &NewString
);
660 UiCustomizeFrontPageBanner (3, FALSE
, &NewString
);
661 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_MEMORY_SIZE
), NewString
, NULL
);
662 FreePool (NewString
);
666 This function will change video resolution and text mode
667 according to defined setup mode or defined boot mode
669 @param IsSetupMode Indicate mode is changed to setup mode or boot mode.
671 @retval EFI_SUCCESS Mode is changed successfully.
672 @retval Others Mode failed to be changed.
680 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
681 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
683 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
687 UINT32 NewHorizontalResolution
;
688 UINT32 NewVerticalResolution
;
692 EFI_HANDLE
*HandleBuffer
;
702 // Get current video resolution and text mode
704 Status
= gBS
->HandleProtocol (
705 gST
->ConsoleOutHandle
,
706 &gEfiGraphicsOutputProtocolGuid
,
707 (VOID
**)&GraphicsOutput
709 if (EFI_ERROR (Status
)) {
710 GraphicsOutput
= NULL
;
713 Status
= gBS
->HandleProtocol (
714 gST
->ConsoleOutHandle
,
715 &gEfiSimpleTextOutProtocolGuid
,
716 (VOID
**)&SimpleTextOut
718 if (EFI_ERROR (Status
)) {
719 SimpleTextOut
= NULL
;
722 if ((GraphicsOutput
== NULL
) || (SimpleTextOut
== NULL
)) {
723 return EFI_UNSUPPORTED
;
728 // The required resolution and text mode is setup mode.
730 NewHorizontalResolution
= mSetupHorizontalResolution
;
731 NewVerticalResolution
= mSetupVerticalResolution
;
732 NewColumns
= mSetupTextModeColumn
;
733 NewRows
= mSetupTextModeRow
;
736 // The required resolution and text mode is boot mode.
738 NewHorizontalResolution
= mBootHorizontalResolution
;
739 NewVerticalResolution
= mBootVerticalResolution
;
740 NewColumns
= mBootTextModeColumn
;
741 NewRows
= mBootTextModeRow
;
744 if (GraphicsOutput
!= NULL
) {
745 MaxGopMode
= GraphicsOutput
->Mode
->MaxMode
;
748 if (SimpleTextOut
!= NULL
) {
749 MaxTextMode
= SimpleTextOut
->Mode
->MaxMode
;
753 // 1. If current video resolution is same with required video resolution,
754 // video resolution need not be changed.
755 // 1.1. If current text mode is same with required text mode, text mode need not be changed.
756 // 1.2. If current text mode is different from required text mode, text mode need be changed.
757 // 2. If current video resolution is different from required video resolution, we need restart whole console drivers.
759 for (ModeNumber
= 0; ModeNumber
< MaxGopMode
; ModeNumber
++) {
760 Status
= GraphicsOutput
->QueryMode (
766 if (!EFI_ERROR (Status
)) {
767 if ((Info
->HorizontalResolution
== NewHorizontalResolution
) &&
768 (Info
->VerticalResolution
== NewVerticalResolution
))
770 if ((GraphicsOutput
->Mode
->Info
->HorizontalResolution
== NewHorizontalResolution
) &&
771 (GraphicsOutput
->Mode
->Info
->VerticalResolution
== NewVerticalResolution
))
774 // Current resolution is same with required resolution, check if text mode need be set
776 Status
= SimpleTextOut
->QueryMode (SimpleTextOut
, SimpleTextOut
->Mode
->Mode
, &CurrentColumn
, &CurrentRow
);
777 ASSERT_EFI_ERROR (Status
);
778 if ((CurrentColumn
== NewColumns
) && (CurrentRow
== NewRows
)) {
780 // If current text mode is same with required text mode. Do nothing
786 // If current text mode is different from required text mode. Set new video mode
788 for (Index
= 0; Index
< MaxTextMode
; Index
++) {
789 Status
= SimpleTextOut
->QueryMode (SimpleTextOut
, Index
, &CurrentColumn
, &CurrentRow
);
790 if (!EFI_ERROR (Status
)) {
791 if ((CurrentColumn
== NewColumns
) && (CurrentRow
== NewRows
)) {
793 // Required text mode is supported, set it.
795 Status
= SimpleTextOut
->SetMode (SimpleTextOut
, Index
);
796 ASSERT_EFI_ERROR (Status
);
798 // Update text mode PCD.
800 Status
= PcdSet32S (PcdConOutColumn
, mSetupTextModeColumn
);
801 ASSERT_EFI_ERROR (Status
);
802 Status
= PcdSet32S (PcdConOutRow
, mSetupTextModeRow
);
803 ASSERT_EFI_ERROR (Status
);
810 if (Index
== MaxTextMode
) {
812 // If required text mode is not supported, return error.
815 return EFI_UNSUPPORTED
;
820 // If current video resolution is not same with the new one, set new video resolution.
821 // In this case, the driver which produces simple text out need be restarted.
823 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, ModeNumber
);
824 if (!EFI_ERROR (Status
)) {
835 if (ModeNumber
== MaxGopMode
) {
837 // If the resolution is not supported, return error.
839 return EFI_UNSUPPORTED
;
843 // Set PCD to Inform GraphicsConsole to change video resolution.
844 // Set PCD to Inform Consplitter to change text mode.
846 Status
= PcdSet32S (PcdVideoHorizontalResolution
, NewHorizontalResolution
);
847 ASSERT_EFI_ERROR (Status
);
848 Status
= PcdSet32S (PcdVideoVerticalResolution
, NewVerticalResolution
);
849 ASSERT_EFI_ERROR (Status
);
850 Status
= PcdSet32S (PcdConOutColumn
, NewColumns
);
851 ASSERT_EFI_ERROR (Status
);
852 Status
= PcdSet32S (PcdConOutRow
, NewRows
);
853 ASSERT_EFI_ERROR (Status
);
856 // Video mode is changed, so restart graphics console driver and higher level driver.
857 // Reconnect graphics console driver and higher level driver.
858 // Locate all the handles with GOP protocol and reconnect it.
860 Status
= gBS
->LocateHandleBuffer (
862 &gEfiSimpleTextOutProtocolGuid
,
867 if (!EFI_ERROR (Status
)) {
868 for (Index
= 0; Index
< HandleCount
; Index
++) {
869 gBS
->DisconnectController (HandleBuffer
[Index
], NULL
, NULL
);
872 for (Index
= 0; Index
< HandleCount
; Index
++) {
873 gBS
->ConnectController (HandleBuffer
[Index
], NULL
, NULL
, TRUE
);
876 if (HandleBuffer
!= NULL
) {
877 FreePool (HandleBuffer
);
885 The user Entry Point for Application. The user code starts with this function
886 as the real entry point for the image goes into a library that calls this
889 @param[in] ImageHandle The firmware allocated handle for the EFI image.
890 @param[in] SystemTable A pointer to the EFI System Table.
892 @retval EFI_SUCCESS The entry point is executed successfully.
893 @retval other Some error occurs when executing this entry point.
898 InitializeUserInterface (
899 IN EFI_HANDLE ImageHandle
,
900 IN EFI_SYSTEM_TABLE
*SystemTable
903 EFI_HII_HANDLE HiiHandle
;
905 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
906 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
907 UINTN BootTextColumn
;
910 if (!mModeInitialized
) {
912 // After the console is ready, get current video resolution
913 // and text mode before launching setup at first time.
915 Status
= gBS
->HandleProtocol (
916 gST
->ConsoleOutHandle
,
917 &gEfiGraphicsOutputProtocolGuid
,
918 (VOID
**)&GraphicsOutput
920 if (EFI_ERROR (Status
)) {
921 GraphicsOutput
= NULL
;
924 Status
= gBS
->HandleProtocol (
925 gST
->ConsoleOutHandle
,
926 &gEfiSimpleTextOutProtocolGuid
,
927 (VOID
**)&SimpleTextOut
929 if (EFI_ERROR (Status
)) {
930 SimpleTextOut
= NULL
;
933 if (GraphicsOutput
!= NULL
) {
935 // Get current video resolution and text mode.
937 mBootHorizontalResolution
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
938 mBootVerticalResolution
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
941 if (SimpleTextOut
!= NULL
) {
942 Status
= SimpleTextOut
->QueryMode (
944 SimpleTextOut
->Mode
->Mode
,
948 mBootTextModeColumn
= (UINT32
)BootTextColumn
;
949 mBootTextModeRow
= (UINT32
)BootTextRow
;
953 // Get user defined text mode for setup.
955 mSetupHorizontalResolution
= PcdGet32 (PcdSetupVideoHorizontalResolution
);
956 mSetupVerticalResolution
= PcdGet32 (PcdSetupVideoVerticalResolution
);
957 mSetupTextModeColumn
= PcdGet32 (PcdSetupConOutColumn
);
958 mSetupTextModeRow
= PcdGet32 (PcdSetupConOutRow
);
960 mModeInitialized
= TRUE
;
963 gBS
->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL
);
964 gST
->ConOut
->ClearScreen (gST
->ConOut
);
967 // Install customized fonts needed by Front Page
969 HiiHandle
= ExportFonts ();
970 ASSERT (HiiHandle
!= NULL
);
972 InitializeStringSupport ();
974 UiSetConsoleMode (TRUE
);
976 UiSetConsoleMode (FALSE
);
978 UninitializeStringSupport ();
979 HiiRemovePackages (HiiHandle
);
985 This function is the main entry of the UI entry.
986 The function will present the main menu of the system UI.
988 @param ConnectAllHappened Caller passes the value to UI to avoid unnecessary connect-all.
994 IN BOOLEAN ConnectAllHappened
998 EFI_BOOT_LOGO_PROTOCOL
*BootLogo
;
1001 // Enter Setup page.
1003 REPORT_STATUS_CODE (
1005 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_PC_USER_SETUP
)
1009 // Indicate if the connect all has been performed before.
1010 // If has not been performed before, do here.
1012 if (!ConnectAllHappened
) {
1013 EfiBootManagerConnectAll ();
1017 // The boot option enumeration time is acceptable in Ui driver
1019 EfiBootManagerRefreshAllBootOption ();
1022 // Boot Logo is corrupted, report it using Boot Logo protocol.
1024 Status
= gBS
->LocateProtocol (&gEfiBootLogoProtocolGuid
, NULL
, (VOID
**)&BootLogo
);
1025 if (!EFI_ERROR (Status
) && (BootLogo
!= NULL
)) {
1026 BootLogo
->SetBootLogo (BootLogo
, NULL
, 0, 0, 0, 0);
1029 InitializeFrontPage ();
1035 if (mLanguageString
!= NULL
) {
1036 FreePool (mLanguageString
);
1037 mLanguageString
= NULL
;
1041 // Will leave browser, check any reset required change is applied? if yes, reset system
1043 SetupResetReminder ();
1047 // Following are BDS Lib functions which contain all the code about setup browser reset reminder feature.
1048 // Setup Browser reset reminder feature is that an reset reminder will be given before user leaves the setup browser if
1049 // user change any option setting which needs a reset to be effective, and the reset will be applied according to the user selection.
1053 Record the info that a reset is required.
1054 A module boolean variable is used to record whether a reset is required.
1059 EnableResetRequired (
1063 mResetRequired
= TRUE
;
1067 Check if user changed any option setting which needs a system reset to be effective.
1076 return mResetRequired
;
1080 Check whether a reset is needed, and finish the reset reminder feature.
1081 If a reset is needed, Popup a menu to notice user, and finish the feature
1082 according to the user selection.
1087 SetupResetReminder (
1092 CHAR16
*StringBuffer1
;
1093 CHAR16
*StringBuffer2
;
1096 // check any reset required change is applied? if yes, reset system
1098 if (IsResetRequired ()) {
1099 StringBuffer1
= AllocateZeroPool (MAX_STRING_LEN
* sizeof (CHAR16
));
1100 ASSERT (StringBuffer1
!= NULL
);
1101 StringBuffer2
= AllocateZeroPool (MAX_STRING_LEN
* sizeof (CHAR16
));
1102 ASSERT (StringBuffer2
!= NULL
);
1103 StrCpyS (StringBuffer1
, MAX_STRING_LEN
, L
"Configuration changed. Reset to apply it Now.");
1104 StrCpyS (StringBuffer2
, MAX_STRING_LEN
, L
"Press ENTER to reset");
1106 // Popup a menu to notice user
1109 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, StringBuffer1
, StringBuffer2
, NULL
);
1110 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1112 FreePool (StringBuffer1
);
1113 FreePool (StringBuffer2
);
1115 gRT
->ResetSystem (EfiResetCold
, EFI_SUCCESS
, 0, NULL
);