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 } }
66 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
68 (UINT8
) (END_DEVICE_PATH_LENGTH
),
69 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
75 Update the banner information for the Front Page based on Smbios information.
79 UpdateFrontPageBannerStrings (
84 This function allows a caller to extract the current configuration for one
85 or more named elements from the target driver.
88 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
89 @param Request A null-terminated Unicode string in <ConfigRequest> format.
90 @param Progress On return, points to a character in the Request string.
91 Points to the string's null terminator if request was successful.
92 Points to the most recent '&' before the first failing name/value
93 pair (or the beginning of the string if the failure is in the
94 first name/value pair) if the request was not successful.
95 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
96 has all values filled in for the names in the Request string.
97 String to be allocated by the called function.
99 @retval EFI_SUCCESS The Results is filled with the requested values.
100 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
101 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
102 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
108 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
109 IN CONST EFI_STRING Request
,
110 OUT EFI_STRING
*Progress
,
111 OUT EFI_STRING
*Results
114 if (Progress
== NULL
|| Results
== NULL
) {
115 return EFI_INVALID_PARAMETER
;
118 return EFI_NOT_FOUND
;
122 This function processes the results of changes in configuration.
125 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
126 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
127 @param Progress A pointer to a string filled in with the offset of the most
128 recent '&' before the first failing name/value pair (or the
129 beginning of the string if the failure is in the first
130 name/value pair) or the terminating NULL if all was successful.
132 @retval EFI_SUCCESS The Results is processed successfully.
133 @retval EFI_INVALID_PARAMETER Configuration is NULL.
134 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
140 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
141 IN CONST EFI_STRING Configuration
,
142 OUT EFI_STRING
*Progress
145 if (Configuration
== NULL
|| Progress
== NULL
) {
146 return EFI_INVALID_PARAMETER
;
149 *Progress
= Configuration
;
151 return EFI_NOT_FOUND
;
155 This function processes the results of changes in configuration.
158 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
159 @param Action Specifies the type of action taken by the browser.
160 @param QuestionId A unique value which is sent to the original exporting driver
161 so that it can identify the type of data to expect.
162 @param Type The type of value for the question.
163 @param Value A pointer to the data being sent to the original exporting driver.
164 @param ActionRequest On return, points to the action requested by the callback function.
166 @retval EFI_SUCCESS The callback successfully handled the action.
167 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
168 @retval EFI_DEVICE_ERROR The variable could not be saved.
169 @retval EFI_UNSUPPORTED The specified Action is not supported by the callback.
175 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
176 IN EFI_BROWSER_ACTION Action
,
177 IN EFI_QUESTION_ID QuestionId
,
179 IN EFI_IFR_TYPE_VALUE
*Value
,
180 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
183 return UiFrontPageCallbackHandler (gFrontPagePrivate
.HiiHandle
, Action
, QuestionId
, Type
, Value
, ActionRequest
);
188 Update the menus in the front page.
192 UpdateFrontPageForm (
196 VOID
*StartOpCodeHandle
;
197 VOID
*EndOpCodeHandle
;
198 EFI_IFR_GUID_LABEL
*StartGuidLabel
;
199 EFI_IFR_GUID_LABEL
*EndGuidLabel
;
202 // Allocate space for creation of UpdateData Buffer
204 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
205 ASSERT (StartOpCodeHandle
!= NULL
);
207 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
208 ASSERT (EndOpCodeHandle
!= NULL
);
210 // Create Hii Extend Label OpCode as the start opcode
212 StartGuidLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
213 StartGuidLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
214 StartGuidLabel
->Number
= LABEL_FRANTPAGE_INFORMATION
;
216 // Create Hii Extend Label OpCode as the end opcode
218 EndGuidLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
219 EndGuidLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
220 EndGuidLabel
->Number
= LABEL_END
;
223 //Updata Front Page form
225 UiCustomizeFrontPage (
226 gFrontPagePrivate
.HiiHandle
,
231 gFrontPagePrivate
.HiiHandle
,
238 HiiFreeOpCodeHandle (StartOpCodeHandle
);
239 HiiFreeOpCodeHandle (EndOpCodeHandle
);
243 Initialize HII information for the FrontPage
246 @retval EFI_SUCCESS The operation is successful.
247 @retval EFI_DEVICE_ERROR If the dynamic opcode creation failed.
251 InitializeFrontPage (
257 // Locate Hii relative protocols
259 Status
= gBS
->LocateProtocol (&gEfiFormBrowser2ProtocolGuid
, NULL
, (VOID
**) &gFormBrowser2
);
260 if (EFI_ERROR (Status
)) {
265 // Install Device Path Protocol and Config Access protocol to driver handle
267 gFrontPagePrivate
.DriverHandle
= NULL
;
268 Status
= gBS
->InstallMultipleProtocolInterfaces (
269 &gFrontPagePrivate
.DriverHandle
,
270 &gEfiDevicePathProtocolGuid
,
271 &mFrontPageHiiVendorDevicePath
,
272 &gEfiHiiConfigAccessProtocolGuid
,
273 &gFrontPagePrivate
.ConfigAccess
,
276 ASSERT_EFI_ERROR (Status
);
279 // Publish our HII data
281 gFrontPagePrivate
.HiiHandle
= HiiAddPackages (
283 gFrontPagePrivate
.DriverHandle
,
288 ASSERT (gFrontPagePrivate
.HiiHandle
!= NULL
);
291 //Updata Front Page banner strings
293 UpdateFrontPageBannerStrings ();
296 // Update front page menus.
298 UpdateFrontPageForm();
304 Call the browser and display the front page
306 @return Status code that will be returned by
307 EFI_FORM_BROWSER2_PROTOCOL.SendForm ().
316 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
319 // Begin waiting for USER INPUT
323 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_PC_INPUT_WAIT
)
326 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
327 Status
= gFormBrowser2
->SendForm (
329 &gFrontPagePrivate
.HiiHandle
,
337 // Check whether user change any option setting which needs a reset to be effective
339 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
340 EnableResetRequired ();
347 Remove the installed packages from the HiiDatabase.
356 Status
= gBS
->UninstallMultipleProtocolInterfaces (
357 gFrontPagePrivate
.DriverHandle
,
358 &gEfiDevicePathProtocolGuid
,
359 &mFrontPageHiiVendorDevicePath
,
360 &gEfiHiiConfigAccessProtocolGuid
,
361 &gFrontPagePrivate
.ConfigAccess
,
364 ASSERT_EFI_ERROR (Status
);
367 // Publish our HII data
369 HiiRemovePackages (gFrontPagePrivate
.HiiHandle
);
370 if (gFrontPagePrivate
.LanguageToken
!= NULL
) {
371 FreePool (gFrontPagePrivate
.LanguageToken
);
372 gFrontPagePrivate
.LanguageToken
= NULL
;
377 Convert Processor Frequency Data to a string.
379 @param ProcessorFrequency The frequency data to process
380 @param Base10Exponent The exponent based on 10
381 @param String The string that is created
385 ConvertProcessorToString (
386 IN UINT16 ProcessorFrequency
,
387 IN UINT16 Base10Exponent
,
391 CHAR16
*StringBuffer
;
396 if (Base10Exponent
>= 6) {
397 FreqMhz
= ProcessorFrequency
;
398 for (Index
= 0; Index
< (UINT32
) Base10Exponent
- 6; Index
++) {
404 DestMax
= 0x20 / sizeof (CHAR16
);
405 StringBuffer
= AllocateZeroPool (0x20);
406 ASSERT (StringBuffer
!= NULL
);
407 UnicodeValueToStringS (StringBuffer
, sizeof (CHAR16
) * DestMax
, LEFT_JUSTIFY
, FreqMhz
/ 1000, 3);
408 Index
= StrnLenS (StringBuffer
, DestMax
);
409 StrCatS (StringBuffer
, DestMax
, L
".");
410 UnicodeValueToStringS (
411 StringBuffer
+ Index
+ 1,
412 sizeof (CHAR16
) * (DestMax
- (Index
+ 1)),
414 (FreqMhz
% 1000) / 10,
417 StrCatS (StringBuffer
, DestMax
, L
" GHz");
418 *String
= (CHAR16
*) StringBuffer
;
424 Convert Memory Size to a string.
426 @param MemorySize The size of the memory to process
427 @param String The string that is created
431 ConvertMemorySizeToString (
432 IN UINT32 MemorySize
,
436 CHAR16
*StringBuffer
;
438 StringBuffer
= AllocateZeroPool (0x24);
439 ASSERT (StringBuffer
!= NULL
);
440 UnicodeValueToStringS (StringBuffer
, 0x24, LEFT_JUSTIFY
, MemorySize
, 10);
441 StrCatS (StringBuffer
, 0x24 / sizeof (CHAR16
), L
" MB RAM");
443 *String
= (CHAR16
*) StringBuffer
;
450 Acquire the string associated with the Index from smbios structure and return it.
451 The caller is responsible for free the string buffer.
453 @param OptionalStrStart The start position to search the string
454 @param Index The index of the string to extract
455 @param String The string that is extracted
457 @retval EFI_SUCCESS The function returns EFI_SUCCESS always.
461 GetOptionalStringByIndex (
462 IN CHAR8
*OptionalStrStart
,
470 *String
= AllocateZeroPool (sizeof (CHAR16
));
477 OptionalStrStart
+= StrSize
;
478 StrSize
= AsciiStrSize (OptionalStrStart
);
479 } while (OptionalStrStart
[StrSize
] != 0 && Index
!= 0);
481 if ((Index
!= 0) || (StrSize
== 1)) {
483 // Meet the end of strings set but Index is non-zero, or
484 // Find an empty string
486 *String
= GetStringById (STRING_TOKEN (STR_MISSING_STRING
));
488 *String
= AllocatePool (StrSize
* sizeof (CHAR16
));
489 AsciiStrToUnicodeStrS (OptionalStrStart
, *String
, StrSize
);
498 Update the banner information for the Front Page based on Smbios information.
502 UpdateFrontPageBannerStrings (
508 CHAR16
*FirmwareVersionString
;
510 EFI_SMBIOS_HANDLE SmbiosHandle
;
511 EFI_SMBIOS_PROTOCOL
*Smbios
;
512 SMBIOS_TABLE_TYPE0
*Type0Record
;
513 SMBIOS_TABLE_TYPE1
*Type1Record
;
514 SMBIOS_TABLE_TYPE4
*Type4Record
;
515 SMBIOS_TABLE_TYPE19
*Type19Record
;
516 EFI_SMBIOS_TABLE_HEADER
*Record
;
517 UINT64 InstalledMemory
;
524 // Update default banner string.
526 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE4_LEFT
), NULL
);
527 UiCustomizeFrontPageBanner (4, TRUE
, &NewString
);
528 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE4_LEFT
), NewString
, NULL
);
529 FreePool (NewString
);
531 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE4_RIGHT
), NULL
);
532 UiCustomizeFrontPageBanner (4, FALSE
, &NewString
);
533 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE4_RIGHT
), NewString
, NULL
);
534 FreePool (NewString
);
536 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE5_LEFT
), NULL
);
537 UiCustomizeFrontPageBanner (5, TRUE
, &NewString
);
538 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE5_LEFT
), NewString
, NULL
);
539 FreePool (NewString
);
541 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE5_RIGHT
), NULL
);
542 UiCustomizeFrontPageBanner (5, FALSE
, &NewString
);
543 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE5_RIGHT
), NewString
, NULL
);
544 FreePool (NewString
);
547 // Update Front Page banner strings base on SmBios Table.
549 Status
= gBS
->LocateProtocol (&gEfiSmbiosProtocolGuid
, NULL
, (VOID
**) &Smbios
);
550 if (EFI_ERROR (Status
)) {
552 // Smbios protocol not found, get the default value.
554 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_COMPUTER_MODEL
), NULL
);
555 UiCustomizeFrontPageBanner (1, TRUE
, &NewString
);
556 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_COMPUTER_MODEL
), NewString
, NULL
);
557 FreePool (NewString
);
559 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_CPU_MODEL
), NULL
);
560 UiCustomizeFrontPageBanner (2, TRUE
, &NewString
);
561 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_CPU_MODEL
), NewString
, NULL
);
562 FreePool (NewString
);
564 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_CPU_SPEED
), NULL
);
565 UiCustomizeFrontPageBanner (2, FALSE
, &NewString
);
566 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_CPU_SPEED
), NewString
, NULL
);
567 FreePool (NewString
);
569 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION
), NULL
);
570 UiCustomizeFrontPageBanner (3, TRUE
, &NewString
);
571 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION
), NewString
, NULL
);
572 FreePool (NewString
);
574 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_MEMORY_SIZE
), NULL
);
575 UiCustomizeFrontPageBanner (3, FALSE
, &NewString
);
576 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_MEMORY_SIZE
), NewString
, NULL
);
577 FreePool (NewString
);
582 SmbiosHandle
= SMBIOS_HANDLE_PI_RESERVED
;
583 Status
= Smbios
->GetNext (Smbios
, &SmbiosHandle
, NULL
, &Record
, NULL
);
584 while (!EFI_ERROR(Status
)) {
585 if (Record
->Type
== SMBIOS_TYPE_BIOS_INFORMATION
) {
586 Type0Record
= (SMBIOS_TABLE_TYPE0
*) Record
;
587 StrIndex
= Type0Record
->BiosVersion
;
588 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type0Record
+ Type0Record
->Hdr
.Length
), StrIndex
, &NewString
);
590 FirmwareVersionString
= (CHAR16
*) PcdGetPtr (PcdFirmwareVersionString
);
591 if (*FirmwareVersionString
!= 0x0000 ) {
592 FreePool (NewString
);
593 NewString
= (CHAR16
*) PcdGetPtr (PcdFirmwareVersionString
);
594 UiCustomizeFrontPageBanner (3, TRUE
, &NewString
);
595 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION
), NewString
, NULL
);
597 UiCustomizeFrontPageBanner (3, TRUE
, &NewString
);
598 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION
), NewString
, NULL
);
599 FreePool (NewString
);
603 if (Record
->Type
== SMBIOS_TYPE_SYSTEM_INFORMATION
) {
604 Type1Record
= (SMBIOS_TABLE_TYPE1
*) Record
;
605 StrIndex
= Type1Record
->ProductName
;
606 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type1Record
+ Type1Record
->Hdr
.Length
), StrIndex
, &NewString
);
607 UiCustomizeFrontPageBanner (1, TRUE
, &NewString
);
608 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_COMPUTER_MODEL
), NewString
, NULL
);
609 FreePool (NewString
);
612 if ((Record
->Type
== SMBIOS_TYPE_PROCESSOR_INFORMATION
) && !FoundCpu
) {
613 Type4Record
= (SMBIOS_TABLE_TYPE4
*) Record
;
615 // The information in the record should be only valid when the CPU Socket is populated.
617 if ((Type4Record
->Status
& SMBIOS_TYPE4_CPU_SOCKET_POPULATED
) == SMBIOS_TYPE4_CPU_SOCKET_POPULATED
) {
618 StrIndex
= Type4Record
->ProcessorVersion
;
619 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type4Record
+ Type4Record
->Hdr
.Length
), StrIndex
, &NewString
);
620 UiCustomizeFrontPageBanner (2, TRUE
, &NewString
);
621 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_CPU_MODEL
), NewString
, NULL
);
622 FreePool (NewString
);
624 ConvertProcessorToString(Type4Record
->CurrentSpeed
, 6, &NewString
);
625 UiCustomizeFrontPageBanner (2, FALSE
, &NewString
);
626 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_CPU_SPEED
), NewString
, NULL
);
627 FreePool (NewString
);
633 if ( Record
->Type
== SMBIOS_TYPE_MEMORY_ARRAY_MAPPED_ADDRESS
) {
634 Type19Record
= (SMBIOS_TABLE_TYPE19
*) Record
;
635 if (Type19Record
->StartingAddress
!= 0xFFFFFFFF ) {
636 InstalledMemory
+= RShiftU64(Type19Record
->EndingAddress
-
637 Type19Record
->StartingAddress
+ 1, 10);
639 InstalledMemory
+= RShiftU64(Type19Record
->ExtendedEndingAddress
-
640 Type19Record
->ExtendedStartingAddress
+ 1, 20);
644 Status
= Smbios
->GetNext (Smbios
, &SmbiosHandle
, NULL
, &Record
, NULL
);
648 // Now update the total installed RAM size
650 ConvertMemorySizeToString ((UINT32
)InstalledMemory
, &NewString
);
651 UiCustomizeFrontPageBanner (3, FALSE
, &NewString
);
652 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_MEMORY_SIZE
), NewString
, NULL
);
653 FreePool (NewString
);
657 This function will change video resolution and text mode
658 according to defined setup mode or defined boot mode
660 @param IsSetupMode Indicate mode is changed to setup mode or boot mode.
662 @retval EFI_SUCCESS Mode is changed successfully.
663 @retval Others Mode failed to be changed.
671 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
672 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
674 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
678 UINT32 NewHorizontalResolution
;
679 UINT32 NewVerticalResolution
;
683 EFI_HANDLE
*HandleBuffer
;
693 // Get current video resolution and text mode
695 Status
= gBS
->HandleProtocol (
696 gST
->ConsoleOutHandle
,
697 &gEfiGraphicsOutputProtocolGuid
,
698 (VOID
**)&GraphicsOutput
700 if (EFI_ERROR (Status
)) {
701 GraphicsOutput
= NULL
;
704 Status
= gBS
->HandleProtocol (
705 gST
->ConsoleOutHandle
,
706 &gEfiSimpleTextOutProtocolGuid
,
707 (VOID
**)&SimpleTextOut
709 if (EFI_ERROR (Status
)) {
710 SimpleTextOut
= NULL
;
713 if ((GraphicsOutput
== NULL
) || (SimpleTextOut
== NULL
)) {
714 return EFI_UNSUPPORTED
;
719 // The required resolution and text mode is setup mode.
721 NewHorizontalResolution
= mSetupHorizontalResolution
;
722 NewVerticalResolution
= mSetupVerticalResolution
;
723 NewColumns
= mSetupTextModeColumn
;
724 NewRows
= mSetupTextModeRow
;
727 // The required resolution and text mode is boot mode.
729 NewHorizontalResolution
= mBootHorizontalResolution
;
730 NewVerticalResolution
= mBootVerticalResolution
;
731 NewColumns
= mBootTextModeColumn
;
732 NewRows
= mBootTextModeRow
;
735 if (GraphicsOutput
!= NULL
) {
736 MaxGopMode
= GraphicsOutput
->Mode
->MaxMode
;
739 if (SimpleTextOut
!= NULL
) {
740 MaxTextMode
= SimpleTextOut
->Mode
->MaxMode
;
744 // 1. If current video resolution is same with required video resolution,
745 // video resolution need not be changed.
746 // 1.1. If current text mode is same with required text mode, text mode need not be changed.
747 // 1.2. If current text mode is different from required text mode, text mode need be changed.
748 // 2. If current video resolution is different from required video resolution, we need restart whole console drivers.
750 for (ModeNumber
= 0; ModeNumber
< MaxGopMode
; ModeNumber
++) {
751 Status
= GraphicsOutput
->QueryMode (
757 if (!EFI_ERROR (Status
)) {
758 if ((Info
->HorizontalResolution
== NewHorizontalResolution
) &&
759 (Info
->VerticalResolution
== NewVerticalResolution
)) {
760 if ((GraphicsOutput
->Mode
->Info
->HorizontalResolution
== NewHorizontalResolution
) &&
761 (GraphicsOutput
->Mode
->Info
->VerticalResolution
== NewVerticalResolution
)) {
763 // Current resolution is same with required resolution, check if text mode need be set
765 Status
= SimpleTextOut
->QueryMode (SimpleTextOut
, SimpleTextOut
->Mode
->Mode
, &CurrentColumn
, &CurrentRow
);
766 ASSERT_EFI_ERROR (Status
);
767 if (CurrentColumn
== NewColumns
&& CurrentRow
== NewRows
) {
769 // If current text mode is same with required text mode. Do nothing
775 // If current text mode is different from required text mode. Set new video mode
777 for (Index
= 0; Index
< MaxTextMode
; Index
++) {
778 Status
= SimpleTextOut
->QueryMode (SimpleTextOut
, Index
, &CurrentColumn
, &CurrentRow
);
779 if (!EFI_ERROR(Status
)) {
780 if ((CurrentColumn
== NewColumns
) && (CurrentRow
== NewRows
)) {
782 // Required text mode is supported, set it.
784 Status
= SimpleTextOut
->SetMode (SimpleTextOut
, Index
);
785 ASSERT_EFI_ERROR (Status
);
787 // Update text mode PCD.
789 Status
= PcdSet32S (PcdConOutColumn
, mSetupTextModeColumn
);
790 ASSERT_EFI_ERROR (Status
);
791 Status
= PcdSet32S (PcdConOutRow
, mSetupTextModeRow
);
792 ASSERT_EFI_ERROR (Status
);
798 if (Index
== MaxTextMode
) {
800 // If required text mode is not supported, return error.
803 return EFI_UNSUPPORTED
;
808 // If current video resolution is not same with the new one, set new video resolution.
809 // In this case, the driver which produces simple text out need be restarted.
811 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, ModeNumber
);
812 if (!EFI_ERROR (Status
)) {
822 if (ModeNumber
== MaxGopMode
) {
824 // If the resolution is not supported, return error.
826 return EFI_UNSUPPORTED
;
830 // Set PCD to Inform GraphicsConsole to change video resolution.
831 // Set PCD to Inform Consplitter to change text mode.
833 Status
= PcdSet32S (PcdVideoHorizontalResolution
, NewHorizontalResolution
);
834 ASSERT_EFI_ERROR (Status
);
835 Status
= PcdSet32S (PcdVideoVerticalResolution
, NewVerticalResolution
);
836 ASSERT_EFI_ERROR (Status
);
837 Status
= PcdSet32S (PcdConOutColumn
, NewColumns
);
838 ASSERT_EFI_ERROR (Status
);
839 Status
= PcdSet32S (PcdConOutRow
, NewRows
);
840 ASSERT_EFI_ERROR (Status
);
843 // Video mode is changed, so restart graphics console driver and higher level driver.
844 // Reconnect graphics console driver and higher level driver.
845 // Locate all the handles with GOP protocol and reconnect it.
847 Status
= gBS
->LocateHandleBuffer (
849 &gEfiSimpleTextOutProtocolGuid
,
854 if (!EFI_ERROR (Status
)) {
855 for (Index
= 0; Index
< HandleCount
; Index
++) {
856 gBS
->DisconnectController (HandleBuffer
[Index
], NULL
, NULL
);
858 for (Index
= 0; Index
< HandleCount
; Index
++) {
859 gBS
->ConnectController (HandleBuffer
[Index
], NULL
, NULL
, TRUE
);
861 if (HandleBuffer
!= NULL
) {
862 FreePool (HandleBuffer
);
870 The user Entry Point for Application. The user code starts with this function
871 as the real entry point for the image goes into a library that calls this
874 @param[in] ImageHandle The firmware allocated handle for the EFI image.
875 @param[in] SystemTable A pointer to the EFI System Table.
877 @retval EFI_SUCCESS The entry point is executed successfully.
878 @retval other Some error occurs when executing this entry point.
883 InitializeUserInterface (
884 IN EFI_HANDLE ImageHandle
,
885 IN EFI_SYSTEM_TABLE
*SystemTable
888 EFI_HII_HANDLE HiiHandle
;
890 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
891 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
892 UINTN BootTextColumn
;
895 if (!mModeInitialized
) {
897 // After the console is ready, get current video resolution
898 // and text mode before launching setup at first time.
900 Status
= gBS
->HandleProtocol (
901 gST
->ConsoleOutHandle
,
902 &gEfiGraphicsOutputProtocolGuid
,
903 (VOID
**)&GraphicsOutput
905 if (EFI_ERROR (Status
)) {
906 GraphicsOutput
= NULL
;
909 Status
= gBS
->HandleProtocol (
910 gST
->ConsoleOutHandle
,
911 &gEfiSimpleTextOutProtocolGuid
,
912 (VOID
**)&SimpleTextOut
914 if (EFI_ERROR (Status
)) {
915 SimpleTextOut
= NULL
;
918 if (GraphicsOutput
!= NULL
) {
920 // Get current video resolution and text mode.
922 mBootHorizontalResolution
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
923 mBootVerticalResolution
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
926 if (SimpleTextOut
!= NULL
) {
927 Status
= SimpleTextOut
->QueryMode (
929 SimpleTextOut
->Mode
->Mode
,
933 mBootTextModeColumn
= (UINT32
)BootTextColumn
;
934 mBootTextModeRow
= (UINT32
)BootTextRow
;
938 // Get user defined text mode for setup.
940 mSetupHorizontalResolution
= PcdGet32 (PcdSetupVideoHorizontalResolution
);
941 mSetupVerticalResolution
= PcdGet32 (PcdSetupVideoVerticalResolution
);
942 mSetupTextModeColumn
= PcdGet32 (PcdSetupConOutColumn
);
943 mSetupTextModeRow
= PcdGet32 (PcdSetupConOutRow
);
945 mModeInitialized
= TRUE
;
948 gBS
->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL
);
949 gST
->ConOut
->ClearScreen (gST
->ConOut
);
952 // Install customized fonts needed by Front Page
954 HiiHandle
= ExportFonts ();
955 ASSERT (HiiHandle
!= NULL
);
957 InitializeStringSupport ();
959 UiSetConsoleMode (TRUE
);
961 UiSetConsoleMode (FALSE
);
963 UninitializeStringSupport ();
964 HiiRemovePackages (HiiHandle
);
970 This function is the main entry of the UI entry.
971 The function will present the main menu of the system UI.
973 @param ConnectAllHappened Caller passes the value to UI to avoid unnecessary connect-all.
979 IN BOOLEAN ConnectAllHappened
983 EFI_BOOT_LOGO_PROTOCOL
*BootLogo
;
990 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_PC_USER_SETUP
)
994 // Indicate if the connect all has been performed before.
995 // If has not been performed before, do here.
997 if (!ConnectAllHappened
) {
998 EfiBootManagerConnectAll ();
1002 // The boot option enumeration time is acceptable in Ui driver
1004 EfiBootManagerRefreshAllBootOption ();
1007 // Boot Logo is corrupted, report it using Boot Logo protocol.
1009 Status
= gBS
->LocateProtocol (&gEfiBootLogoProtocolGuid
, NULL
, (VOID
**) &BootLogo
);
1010 if (!EFI_ERROR (Status
) && (BootLogo
!= NULL
)) {
1011 BootLogo
->SetBootLogo (BootLogo
, NULL
, 0, 0, 0, 0);
1014 InitializeFrontPage ();
1020 if (mLanguageString
!= NULL
) {
1021 FreePool (mLanguageString
);
1022 mLanguageString
= NULL
;
1026 //Will leave browser, check any reset required change is applied? if yes, reset system
1028 SetupResetReminder ();
1032 // Following are BDS Lib functions which contain all the code about setup browser reset reminder feature.
1033 // Setup Browser reset reminder feature is that an reset reminder will be given before user leaves the setup browser if
1034 // user change any option setting which needs a reset to be effective, and the reset will be applied according to the user selection.
1042 Record the info that a reset is required.
1043 A module boolean variable is used to record whether a reset is required.
1048 EnableResetRequired (
1052 mResetRequired
= TRUE
;
1060 Check if user changed any option setting which needs a system reset to be effective.
1069 return mResetRequired
;
1074 Check whether a reset is needed, and finish the reset reminder feature.
1075 If a reset is needed, Popup a menu to notice user, and finish the feature
1076 according to the user selection.
1081 SetupResetReminder (
1086 CHAR16
*StringBuffer1
;
1087 CHAR16
*StringBuffer2
;
1090 //check any reset required change is applied? if yes, reset system
1092 if (IsResetRequired ()) {
1094 StringBuffer1
= AllocateZeroPool (MAX_STRING_LEN
* sizeof (CHAR16
));
1095 ASSERT (StringBuffer1
!= NULL
);
1096 StringBuffer2
= AllocateZeroPool (MAX_STRING_LEN
* sizeof (CHAR16
));
1097 ASSERT (StringBuffer2
!= NULL
);
1098 StrCpyS (StringBuffer1
, MAX_STRING_LEN
, L
"Configuration changed. Reset to apply it Now.");
1099 StrCpyS (StringBuffer2
, MAX_STRING_LEN
, L
"Press ENTER to reset");
1101 // Popup a menu to notice user
1104 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, StringBuffer1
, StringBuffer2
, NULL
);
1105 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1107 FreePool (StringBuffer1
);
1108 FreePool (StringBuffer2
);
1110 gRT
->ResetSystem (EfiResetCold
, EFI_SUCCESS
, 0, NULL
);