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 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "FrontPage.h"
17 #include "FrontPageCustomizedUi.h"
19 #define MAX_STRING_LEN 200
21 EFI_GUID mFrontPageGuid
= FRONT_PAGE_FORMSET_GUID
;
23 BOOLEAN mFeaturerSwitch
= TRUE
;
24 BOOLEAN mResetRequired
= 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 UpdateFrontPageBannerStrings (
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
;
158 return EFI_NOT_FOUND
;
162 This function processes the results of changes in configuration.
165 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
166 @param Action Specifies the type of action taken by the browser.
167 @param QuestionId A unique value which is sent to the original exporting driver
168 so that it can identify the type of data to expect.
169 @param Type The type of value for the question.
170 @param Value A pointer to the data being sent to the original exporting driver.
171 @param ActionRequest On return, points to the action requested by the callback function.
173 @retval EFI_SUCCESS The callback successfully handled the action.
174 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
175 @retval EFI_DEVICE_ERROR The variable could not be saved.
176 @retval EFI_UNSUPPORTED The specified Action is not supported by the callback.
182 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
183 IN EFI_BROWSER_ACTION Action
,
184 IN EFI_QUESTION_ID QuestionId
,
186 IN EFI_IFR_TYPE_VALUE
*Value
,
187 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
190 return UiFrontPageCallbackHandler (gFrontPagePrivate
.HiiHandle
, Action
, QuestionId
, Type
, Value
, ActionRequest
);
195 Update the menus in the front page.
199 UpdateFrontPageForm (
203 VOID
*StartOpCodeHandle
;
204 VOID
*EndOpCodeHandle
;
205 EFI_IFR_GUID_LABEL
*StartGuidLabel
;
206 EFI_IFR_GUID_LABEL
*EndGuidLabel
;
209 // Allocate space for creation of UpdateData Buffer
211 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
212 ASSERT (StartOpCodeHandle
!= NULL
);
214 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
215 ASSERT (EndOpCodeHandle
!= NULL
);
217 // Create Hii Extend Label OpCode as the start opcode
219 StartGuidLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
220 StartGuidLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
221 StartGuidLabel
->Number
= LABEL_FRANTPAGE_INFORMATION
;
223 // Create Hii Extend Label OpCode as the end opcode
225 EndGuidLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
226 EndGuidLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
227 EndGuidLabel
->Number
= LABEL_END
;
230 //Updata Front Page form
232 UiCustomizeFrontPage (
233 gFrontPagePrivate
.HiiHandle
,
238 gFrontPagePrivate
.HiiHandle
,
245 HiiFreeOpCodeHandle (StartOpCodeHandle
);
246 HiiFreeOpCodeHandle (EndOpCodeHandle
);
250 Initialize HII information for the FrontPage
253 @retval EFI_SUCCESS The operation is successful.
254 @retval EFI_DEVICE_ERROR If the dynamic opcode creation failed.
258 InitializeFrontPage (
264 // Locate Hii relative protocols
266 Status
= gBS
->LocateProtocol (&gEfiFormBrowser2ProtocolGuid
, NULL
, (VOID
**) &gFormBrowser2
);
267 if (EFI_ERROR (Status
)) {
272 // Install Device Path Protocol and Config Access protocol to driver handle
274 gFrontPagePrivate
.DriverHandle
= NULL
;
275 Status
= gBS
->InstallMultipleProtocolInterfaces (
276 &gFrontPagePrivate
.DriverHandle
,
277 &gEfiDevicePathProtocolGuid
,
278 &mFrontPageHiiVendorDevicePath
,
279 &gEfiHiiConfigAccessProtocolGuid
,
280 &gFrontPagePrivate
.ConfigAccess
,
283 ASSERT_EFI_ERROR (Status
);
286 // Publish our HII data
288 gFrontPagePrivate
.HiiHandle
= HiiAddPackages (
290 gFrontPagePrivate
.DriverHandle
,
295 ASSERT (gFrontPagePrivate
.HiiHandle
!= NULL
);
298 //Updata Front Page banner strings
300 UpdateFrontPageBannerStrings ();
303 // Update front page menus.
305 UpdateFrontPageForm();
311 Call the browser and display the front page
313 @return Status code that will be returned by
314 EFI_FORM_BROWSER2_PROTOCOL.SendForm ().
323 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
326 // Begin waiting for USER INPUT
330 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_PC_INPUT_WAIT
)
333 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
334 Status
= gFormBrowser2
->SendForm (
336 &gFrontPagePrivate
.HiiHandle
,
344 // Check whether user change any option setting which needs a reset to be effective
346 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
347 EnableResetRequired ();
354 Remove the installed packages from the HiiDatabase.
363 Status
= gBS
->UninstallMultipleProtocolInterfaces (
364 gFrontPagePrivate
.DriverHandle
,
365 &gEfiDevicePathProtocolGuid
,
366 &mFrontPageHiiVendorDevicePath
,
367 &gEfiHiiConfigAccessProtocolGuid
,
368 &gFrontPagePrivate
.ConfigAccess
,
371 ASSERT_EFI_ERROR (Status
);
374 // Publish our HII data
376 HiiRemovePackages (gFrontPagePrivate
.HiiHandle
);
377 if (gFrontPagePrivate
.LanguageToken
!= NULL
) {
378 FreePool (gFrontPagePrivate
.LanguageToken
);
379 gFrontPagePrivate
.LanguageToken
= NULL
;
384 Convert Processor Frequency Data to a string.
386 @param ProcessorFrequency The frequency data to process
387 @param Base10Exponent The exponent based on 10
388 @param String The string that is created
392 ConvertProcessorToString (
393 IN UINT16 ProcessorFrequency
,
394 IN UINT16 Base10Exponent
,
398 CHAR16
*StringBuffer
;
403 if (Base10Exponent
>= 6) {
404 FreqMhz
= ProcessorFrequency
;
405 for (Index
= 0; Index
< (UINT32
) Base10Exponent
- 6; Index
++) {
411 DestMax
= 0x20 / sizeof (CHAR16
);
412 StringBuffer
= AllocateZeroPool (0x20);
413 ASSERT (StringBuffer
!= NULL
);
414 UnicodeValueToStringS (StringBuffer
, sizeof (CHAR16
) * DestMax
, LEFT_JUSTIFY
, FreqMhz
/ 1000, 3);
415 Index
= StrnLenS (StringBuffer
, DestMax
);
416 StrCatS (StringBuffer
, DestMax
, L
".");
417 UnicodeValueToStringS (
418 StringBuffer
+ Index
+ 1,
419 sizeof (CHAR16
) * (DestMax
- (Index
+ 1)),
421 (FreqMhz
% 1000) / 10,
424 StrCatS (StringBuffer
, DestMax
, L
" GHz");
425 *String
= (CHAR16
*) StringBuffer
;
431 Convert Memory Size to a string.
433 @param MemorySize The size of the memory to process
434 @param String The string that is created
438 ConvertMemorySizeToString (
439 IN UINT32 MemorySize
,
443 CHAR16
*StringBuffer
;
445 StringBuffer
= AllocateZeroPool (0x24);
446 ASSERT (StringBuffer
!= NULL
);
447 UnicodeValueToStringS (StringBuffer
, 0x24, LEFT_JUSTIFY
, MemorySize
, 10);
448 StrCatS (StringBuffer
, 0x24 / sizeof (CHAR16
), L
" MB RAM");
450 *String
= (CHAR16
*) StringBuffer
;
457 Acquire the string associated with the Index from smbios structure and return it.
458 The caller is responsible for free the string buffer.
460 @param OptionalStrStart The start position to search the string
461 @param Index The index of the string to extract
462 @param String The string that is extracted
464 @retval EFI_SUCCESS The function returns EFI_SUCCESS always.
468 GetOptionalStringByIndex (
469 IN CHAR8
*OptionalStrStart
,
477 *String
= AllocateZeroPool (sizeof (CHAR16
));
484 OptionalStrStart
+= StrSize
;
485 StrSize
= AsciiStrSize (OptionalStrStart
);
486 } while (OptionalStrStart
[StrSize
] != 0 && Index
!= 0);
488 if ((Index
!= 0) || (StrSize
== 1)) {
490 // Meet the end of strings set but Index is non-zero, or
491 // Find an empty string
493 *String
= GetStringById (STRING_TOKEN (STR_MISSING_STRING
));
495 *String
= AllocatePool (StrSize
* sizeof (CHAR16
));
496 AsciiStrToUnicodeStrS (OptionalStrStart
, *String
, StrSize
);
505 Update the banner information for the Front Page based on Smbios information.
509 UpdateFrontPageBannerStrings (
515 CHAR16
*FirmwareVersionString
;
517 EFI_SMBIOS_HANDLE SmbiosHandle
;
518 EFI_SMBIOS_PROTOCOL
*Smbios
;
519 SMBIOS_TABLE_TYPE0
*Type0Record
;
520 SMBIOS_TABLE_TYPE1
*Type1Record
;
521 SMBIOS_TABLE_TYPE4
*Type4Record
;
522 SMBIOS_TABLE_TYPE19
*Type19Record
;
523 EFI_SMBIOS_TABLE_HEADER
*Record
;
524 UINT64 InstalledMemory
;
531 // Update default banner string.
533 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE4_LEFT
), NULL
);
534 UiCustomizeFrontPageBanner (4, TRUE
, &NewString
);
535 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE4_LEFT
), NewString
, NULL
);
536 FreePool (NewString
);
538 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE4_RIGHT
), NULL
);
539 UiCustomizeFrontPageBanner (4, FALSE
, &NewString
);
540 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE4_RIGHT
), NewString
, NULL
);
541 FreePool (NewString
);
543 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE5_LEFT
), NULL
);
544 UiCustomizeFrontPageBanner (5, TRUE
, &NewString
);
545 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE5_LEFT
), NewString
, NULL
);
546 FreePool (NewString
);
548 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE5_RIGHT
), NULL
);
549 UiCustomizeFrontPageBanner (5, FALSE
, &NewString
);
550 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE5_RIGHT
), NewString
, NULL
);
551 FreePool (NewString
);
554 // Update Front Page banner strings base on SmBios Table.
556 Status
= gBS
->LocateProtocol (&gEfiSmbiosProtocolGuid
, NULL
, (VOID
**) &Smbios
);
557 if (EFI_ERROR (Status
)) {
559 // Smbios protocol not found, get the default value.
561 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_COMPUTER_MODEL
), NULL
);
562 UiCustomizeFrontPageBanner (1, TRUE
, &NewString
);
563 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_COMPUTER_MODEL
), NewString
, NULL
);
564 FreePool (NewString
);
566 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_CPU_MODEL
), NULL
);
567 UiCustomizeFrontPageBanner (2, TRUE
, &NewString
);
568 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_CPU_MODEL
), NewString
, NULL
);
569 FreePool (NewString
);
571 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_CPU_SPEED
), NULL
);
572 UiCustomizeFrontPageBanner (2, FALSE
, &NewString
);
573 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_CPU_SPEED
), NewString
, NULL
);
574 FreePool (NewString
);
576 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION
), NULL
);
577 UiCustomizeFrontPageBanner (3, TRUE
, &NewString
);
578 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION
), NewString
, NULL
);
579 FreePool (NewString
);
581 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_MEMORY_SIZE
), NULL
);
582 UiCustomizeFrontPageBanner (3, FALSE
, &NewString
);
583 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_MEMORY_SIZE
), NewString
, NULL
);
584 FreePool (NewString
);
589 SmbiosHandle
= SMBIOS_HANDLE_PI_RESERVED
;
590 Status
= Smbios
->GetNext (Smbios
, &SmbiosHandle
, NULL
, &Record
, NULL
);
591 while (!EFI_ERROR(Status
)) {
592 if (Record
->Type
== SMBIOS_TYPE_BIOS_INFORMATION
) {
593 Type0Record
= (SMBIOS_TABLE_TYPE0
*) Record
;
594 StrIndex
= Type0Record
->BiosVersion
;
595 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type0Record
+ Type0Record
->Hdr
.Length
), StrIndex
, &NewString
);
597 FirmwareVersionString
= (CHAR16
*) PcdGetPtr (PcdFirmwareVersionString
);
598 if (*FirmwareVersionString
!= 0x0000 ) {
599 FreePool (NewString
);
600 NewString
= (CHAR16
*) PcdGetPtr (PcdFirmwareVersionString
);
601 UiCustomizeFrontPageBanner (3, TRUE
, &NewString
);
602 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION
), NewString
, NULL
);
604 UiCustomizeFrontPageBanner (3, TRUE
, &NewString
);
605 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION
), NewString
, NULL
);
606 FreePool (NewString
);
610 if (Record
->Type
== SMBIOS_TYPE_SYSTEM_INFORMATION
) {
611 Type1Record
= (SMBIOS_TABLE_TYPE1
*) Record
;
612 StrIndex
= Type1Record
->ProductName
;
613 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type1Record
+ Type1Record
->Hdr
.Length
), StrIndex
, &NewString
);
614 UiCustomizeFrontPageBanner (1, TRUE
, &NewString
);
615 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_COMPUTER_MODEL
), NewString
, NULL
);
616 FreePool (NewString
);
619 if ((Record
->Type
== SMBIOS_TYPE_PROCESSOR_INFORMATION
) && !FoundCpu
) {
620 Type4Record
= (SMBIOS_TABLE_TYPE4
*) Record
;
622 // The information in the record should be only valid when the CPU Socket is populated.
624 if ((Type4Record
->Status
& SMBIOS_TYPE4_CPU_SOCKET_POPULATED
) == SMBIOS_TYPE4_CPU_SOCKET_POPULATED
) {
625 StrIndex
= Type4Record
->ProcessorVersion
;
626 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type4Record
+ Type4Record
->Hdr
.Length
), StrIndex
, &NewString
);
627 UiCustomizeFrontPageBanner (2, TRUE
, &NewString
);
628 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_CPU_MODEL
), NewString
, NULL
);
629 FreePool (NewString
);
631 ConvertProcessorToString(Type4Record
->CurrentSpeed
, 6, &NewString
);
632 UiCustomizeFrontPageBanner (2, FALSE
, &NewString
);
633 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_CPU_SPEED
), NewString
, NULL
);
634 FreePool (NewString
);
640 if ( Record
->Type
== SMBIOS_TYPE_MEMORY_ARRAY_MAPPED_ADDRESS
) {
641 Type19Record
= (SMBIOS_TABLE_TYPE19
*) Record
;
642 if (Type19Record
->StartingAddress
!= 0xFFFFFFFF ) {
643 InstalledMemory
+= RShiftU64(Type19Record
->EndingAddress
-
644 Type19Record
->StartingAddress
+ 1, 10);
646 InstalledMemory
+= RShiftU64(Type19Record
->ExtendedEndingAddress
-
647 Type19Record
->ExtendedStartingAddress
+ 1, 20);
651 Status
= Smbios
->GetNext (Smbios
, &SmbiosHandle
, NULL
, &Record
, NULL
);
655 // Now update the total installed RAM size
657 ConvertMemorySizeToString ((UINT32
)InstalledMemory
, &NewString
);
658 UiCustomizeFrontPageBanner (3, FALSE
, &NewString
);
659 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_MEMORY_SIZE
), NewString
, NULL
);
660 FreePool (NewString
);
664 This function will change video resolution and text mode
665 according to defined setup mode or defined boot mode
667 @param IsSetupMode Indicate mode is changed to setup mode or boot mode.
669 @retval EFI_SUCCESS Mode is changed successfully.
670 @retval Others Mode failed to be changed.
678 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
679 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
681 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
685 UINT32 NewHorizontalResolution
;
686 UINT32 NewVerticalResolution
;
690 EFI_HANDLE
*HandleBuffer
;
700 // Get current video resolution and text mode
702 Status
= gBS
->HandleProtocol (
703 gST
->ConsoleOutHandle
,
704 &gEfiGraphicsOutputProtocolGuid
,
705 (VOID
**)&GraphicsOutput
707 if (EFI_ERROR (Status
)) {
708 GraphicsOutput
= NULL
;
711 Status
= gBS
->HandleProtocol (
712 gST
->ConsoleOutHandle
,
713 &gEfiSimpleTextOutProtocolGuid
,
714 (VOID
**)&SimpleTextOut
716 if (EFI_ERROR (Status
)) {
717 SimpleTextOut
= NULL
;
720 if ((GraphicsOutput
== NULL
) || (SimpleTextOut
== NULL
)) {
721 return EFI_UNSUPPORTED
;
726 // The required resolution and text mode is setup mode.
728 NewHorizontalResolution
= mSetupHorizontalResolution
;
729 NewVerticalResolution
= mSetupVerticalResolution
;
730 NewColumns
= mSetupTextModeColumn
;
731 NewRows
= mSetupTextModeRow
;
734 // The required resolution and text mode is boot mode.
736 NewHorizontalResolution
= mBootHorizontalResolution
;
737 NewVerticalResolution
= mBootVerticalResolution
;
738 NewColumns
= mBootTextModeColumn
;
739 NewRows
= mBootTextModeRow
;
742 if (GraphicsOutput
!= NULL
) {
743 MaxGopMode
= GraphicsOutput
->Mode
->MaxMode
;
746 if (SimpleTextOut
!= NULL
) {
747 MaxTextMode
= SimpleTextOut
->Mode
->MaxMode
;
751 // 1. If current video resolution is same with required video resolution,
752 // video resolution need not be changed.
753 // 1.1. If current text mode is same with required text mode, text mode need not be changed.
754 // 1.2. If current text mode is different from required text mode, text mode need be changed.
755 // 2. If current video resolution is different from required video resolution, we need restart whole console drivers.
757 for (ModeNumber
= 0; ModeNumber
< MaxGopMode
; ModeNumber
++) {
758 Status
= GraphicsOutput
->QueryMode (
764 if (!EFI_ERROR (Status
)) {
765 if ((Info
->HorizontalResolution
== NewHorizontalResolution
) &&
766 (Info
->VerticalResolution
== NewVerticalResolution
)) {
767 if ((GraphicsOutput
->Mode
->Info
->HorizontalResolution
== NewHorizontalResolution
) &&
768 (GraphicsOutput
->Mode
->Info
->VerticalResolution
== NewVerticalResolution
)) {
770 // Current resolution is same with required resolution, check if text mode need be set
772 Status
= SimpleTextOut
->QueryMode (SimpleTextOut
, SimpleTextOut
->Mode
->Mode
, &CurrentColumn
, &CurrentRow
);
773 ASSERT_EFI_ERROR (Status
);
774 if (CurrentColumn
== NewColumns
&& CurrentRow
== NewRows
) {
776 // If current text mode is same with required text mode. Do nothing
782 // If current text mode is different from required text mode. Set new video mode
784 for (Index
= 0; Index
< MaxTextMode
; Index
++) {
785 Status
= SimpleTextOut
->QueryMode (SimpleTextOut
, Index
, &CurrentColumn
, &CurrentRow
);
786 if (!EFI_ERROR(Status
)) {
787 if ((CurrentColumn
== NewColumns
) && (CurrentRow
== NewRows
)) {
789 // Required text mode is supported, set it.
791 Status
= SimpleTextOut
->SetMode (SimpleTextOut
, Index
);
792 ASSERT_EFI_ERROR (Status
);
794 // Update text mode PCD.
796 Status
= PcdSet32S (PcdConOutColumn
, mSetupTextModeColumn
);
797 ASSERT_EFI_ERROR (Status
);
798 Status
= PcdSet32S (PcdConOutRow
, mSetupTextModeRow
);
799 ASSERT_EFI_ERROR (Status
);
805 if (Index
== MaxTextMode
) {
807 // If required text mode is not supported, return error.
810 return EFI_UNSUPPORTED
;
815 // If current video resolution is not same with the new one, set new video resolution.
816 // In this case, the driver which produces simple text out need be restarted.
818 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, ModeNumber
);
819 if (!EFI_ERROR (Status
)) {
829 if (ModeNumber
== MaxGopMode
) {
831 // If the resolution is not supported, return error.
833 return EFI_UNSUPPORTED
;
837 // Set PCD to Inform GraphicsConsole to change video resolution.
838 // Set PCD to Inform Consplitter to change text mode.
840 Status
= PcdSet32S (PcdVideoHorizontalResolution
, NewHorizontalResolution
);
841 ASSERT_EFI_ERROR (Status
);
842 Status
= PcdSet32S (PcdVideoVerticalResolution
, NewVerticalResolution
);
843 ASSERT_EFI_ERROR (Status
);
844 Status
= PcdSet32S (PcdConOutColumn
, NewColumns
);
845 ASSERT_EFI_ERROR (Status
);
846 Status
= PcdSet32S (PcdConOutRow
, NewRows
);
847 ASSERT_EFI_ERROR (Status
);
850 // Video mode is changed, so restart graphics console driver and higher level driver.
851 // Reconnect graphics console driver and higher level driver.
852 // Locate all the handles with GOP protocol and reconnect it.
854 Status
= gBS
->LocateHandleBuffer (
856 &gEfiSimpleTextOutProtocolGuid
,
861 if (!EFI_ERROR (Status
)) {
862 for (Index
= 0; Index
< HandleCount
; Index
++) {
863 gBS
->DisconnectController (HandleBuffer
[Index
], NULL
, NULL
);
865 for (Index
= 0; Index
< HandleCount
; Index
++) {
866 gBS
->ConnectController (HandleBuffer
[Index
], NULL
, NULL
, TRUE
);
868 if (HandleBuffer
!= NULL
) {
869 FreePool (HandleBuffer
);
877 The user Entry Point for Application. The user code starts with this function
878 as the real entry point for the image goes into a library that calls this
881 @param[in] ImageHandle The firmware allocated handle for the EFI image.
882 @param[in] SystemTable A pointer to the EFI System Table.
884 @retval EFI_SUCCESS The entry point is executed successfully.
885 @retval other Some error occurs when executing this entry point.
890 InitializeUserInterface (
891 IN EFI_HANDLE ImageHandle
,
892 IN EFI_SYSTEM_TABLE
*SystemTable
895 EFI_HII_HANDLE HiiHandle
;
897 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
898 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
899 UINTN BootTextColumn
;
902 if (!mModeInitialized
) {
904 // After the console is ready, get current video resolution
905 // and text mode before launching setup at first time.
907 Status
= gBS
->HandleProtocol (
908 gST
->ConsoleOutHandle
,
909 &gEfiGraphicsOutputProtocolGuid
,
910 (VOID
**)&GraphicsOutput
912 if (EFI_ERROR (Status
)) {
913 GraphicsOutput
= NULL
;
916 Status
= gBS
->HandleProtocol (
917 gST
->ConsoleOutHandle
,
918 &gEfiSimpleTextOutProtocolGuid
,
919 (VOID
**)&SimpleTextOut
921 if (EFI_ERROR (Status
)) {
922 SimpleTextOut
= NULL
;
925 if (GraphicsOutput
!= NULL
) {
927 // Get current video resolution and text mode.
929 mBootHorizontalResolution
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
930 mBootVerticalResolution
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
933 if (SimpleTextOut
!= NULL
) {
934 Status
= SimpleTextOut
->QueryMode (
936 SimpleTextOut
->Mode
->Mode
,
940 mBootTextModeColumn
= (UINT32
)BootTextColumn
;
941 mBootTextModeRow
= (UINT32
)BootTextRow
;
945 // Get user defined text mode for setup.
947 mSetupHorizontalResolution
= PcdGet32 (PcdSetupVideoHorizontalResolution
);
948 mSetupVerticalResolution
= PcdGet32 (PcdSetupVideoVerticalResolution
);
949 mSetupTextModeColumn
= PcdGet32 (PcdSetupConOutColumn
);
950 mSetupTextModeRow
= PcdGet32 (PcdSetupConOutRow
);
952 mModeInitialized
= TRUE
;
955 gBS
->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL
);
956 gST
->ConOut
->ClearScreen (gST
->ConOut
);
959 // Install customized fonts needed by Front Page
961 HiiHandle
= ExportFonts ();
962 ASSERT (HiiHandle
!= NULL
);
964 InitializeStringSupport ();
966 UiSetConsoleMode (TRUE
);
968 UiSetConsoleMode (FALSE
);
970 UninitializeStringSupport ();
971 HiiRemovePackages (HiiHandle
);
977 This function is the main entry of the UI entry.
978 The function will present the main menu of the system UI.
980 @param ConnectAllHappened Caller passes the value to UI to avoid unnecessary connect-all.
986 IN BOOLEAN ConnectAllHappened
990 EFI_BOOT_LOGO_PROTOCOL
*BootLogo
;
997 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_PC_USER_SETUP
)
1001 // Indicate if the connect all has been performed before.
1002 // If has not been performed before, do here.
1004 if (!ConnectAllHappened
) {
1005 EfiBootManagerConnectAll ();
1009 // The boot option enumeration time is acceptable in Ui driver
1011 EfiBootManagerRefreshAllBootOption ();
1014 // Boot Logo is corrupted, report it using Boot Logo protocol.
1016 Status
= gBS
->LocateProtocol (&gEfiBootLogoProtocolGuid
, NULL
, (VOID
**) &BootLogo
);
1017 if (!EFI_ERROR (Status
) && (BootLogo
!= NULL
)) {
1018 BootLogo
->SetBootLogo (BootLogo
, NULL
, 0, 0, 0, 0);
1021 InitializeFrontPage ();
1027 if (mLanguageString
!= NULL
) {
1028 FreePool (mLanguageString
);
1029 mLanguageString
= NULL
;
1033 //Will leave browser, check any reset required change is applied? if yes, reset system
1035 SetupResetReminder ();
1039 // Following are BDS Lib functions which contain all the code about setup browser reset reminder feature.
1040 // Setup Browser reset reminder feature is that an reset reminder will be given before user leaves the setup browser if
1041 // user change any option setting which needs a reset to be effective, and the reset will be applied according to the user selection.
1049 Record the info that a reset is required.
1050 A module boolean variable is used to record whether a reset is required.
1055 EnableResetRequired (
1059 mResetRequired
= TRUE
;
1066 Check whether platform policy enable the reset reminder feature. The default is enabled.
1071 IsResetReminderFeatureEnable (
1075 return mFeaturerSwitch
;
1080 Check if user changed any option setting which needs a system reset to be effective.
1089 return mResetRequired
;
1094 Check whether a reset is needed, and finish the reset reminder feature.
1095 If a reset is needed, Popup a menu to notice user, and finish the feature
1096 according to the user selection.
1101 SetupResetReminder (
1106 CHAR16
*StringBuffer1
;
1107 CHAR16
*StringBuffer2
;
1111 //check any reset required change is applied? if yes, reset system
1113 if (IsResetReminderFeatureEnable ()) {
1114 if (IsResetRequired ()) {
1116 StringBuffer1
= AllocateZeroPool (MAX_STRING_LEN
* sizeof (CHAR16
));
1117 ASSERT (StringBuffer1
!= NULL
);
1118 StringBuffer2
= AllocateZeroPool (MAX_STRING_LEN
* sizeof (CHAR16
));
1119 ASSERT (StringBuffer2
!= NULL
);
1120 StrCpyS (StringBuffer1
, MAX_STRING_LEN
, L
"Configuration changed. Reset to apply it Now.");
1121 StrCpyS (StringBuffer2
, MAX_STRING_LEN
, L
"Press ENTER to reset");
1123 // Popup a menu to notice user
1126 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, StringBuffer1
, StringBuffer2
, NULL
);
1127 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1129 FreePool (StringBuffer1
);
1130 FreePool (StringBuffer2
);
1132 gRT
->ResetSystem (EfiResetCold
, EFI_SUCCESS
, 0, NULL
);