2 FrontPage routines to handle the callbacks and browser calls
4 Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "FrontPage.h"
16 #include "FrontPageCustomizedUi.h"
18 #define MAX_STRING_LEN 200
20 EFI_GUID mFrontPageGuid
= FRONT_PAGE_FORMSET_GUID
;
22 BOOLEAN mFeaturerSwitch
= TRUE
;
23 BOOLEAN mResetRequired
= FALSE
;
25 EFI_FORM_BROWSER2_PROTOCOL
*gFormBrowser2
;
26 CHAR8
*mLanguageString
;
27 BOOLEAN mModeInitialized
= FALSE
;
29 // Boot video resolution and text mode.
31 UINT32 mBootHorizontalResolution
= 0;
32 UINT32 mBootVerticalResolution
= 0;
33 UINT32 mBootTextModeColumn
= 0;
34 UINT32 mBootTextModeRow
= 0;
36 // BIOS setup video resolution and text mode.
38 UINT32 mSetupTextModeColumn
= 0;
39 UINT32 mSetupTextModeRow
= 0;
40 UINT32 mSetupHorizontalResolution
= 0;
41 UINT32 mSetupVerticalResolution
= 0;
43 FRONT_PAGE_CALLBACK_DATA gFrontPagePrivate
= {
44 FRONT_PAGE_CALLBACK_DATA_SIGNATURE
,
55 HII_VENDOR_DEVICE_PATH mFrontPageHiiVendorDevicePath
= {
61 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
62 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
66 // {8E6D99EE-7531-48f8-8745-7F6144468FF2}
68 { 0x8e6d99ee, 0x7531, 0x48f8, { 0x87, 0x45, 0x7f, 0x61, 0x44, 0x46, 0x8f, 0xf2 } }
72 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
74 (UINT8
) (END_DEVICE_PATH_LENGTH
),
75 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
81 Update the banner information for the Front Page based on Smbios information.
85 UpdateFrontPageBannerStrings (
90 This function allows a caller to extract the current configuration for one
91 or more named elements from the target driver.
94 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
95 @param Request A null-terminated Unicode string in <ConfigRequest> format.
96 @param Progress On return, points to a character in the Request string.
97 Points to the string's null terminator if request was successful.
98 Points to the most recent '&' before the first failing name/value
99 pair (or the beginning of the string if the failure is in the
100 first name/value pair) if the request was not successful.
101 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
102 has all values filled in for the names in the Request string.
103 String to be allocated by the called function.
105 @retval EFI_SUCCESS The Results is filled with the requested values.
106 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
107 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
108 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
114 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
115 IN CONST EFI_STRING Request
,
116 OUT EFI_STRING
*Progress
,
117 OUT EFI_STRING
*Results
120 if (Progress
== NULL
|| Results
== NULL
) {
121 return EFI_INVALID_PARAMETER
;
124 return EFI_NOT_FOUND
;
128 This function processes the results of changes in configuration.
131 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
132 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
133 @param Progress A pointer to a string filled in with the offset of the most
134 recent '&' before the first failing name/value pair (or the
135 beginning of the string if the failure is in the first
136 name/value pair) or the terminating NULL if all was successful.
138 @retval EFI_SUCCESS The Results is processed successfully.
139 @retval EFI_INVALID_PARAMETER Configuration is NULL.
140 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
146 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
147 IN CONST EFI_STRING Configuration
,
148 OUT EFI_STRING
*Progress
151 if (Configuration
== NULL
|| Progress
== NULL
) {
152 return EFI_INVALID_PARAMETER
;
155 return EFI_NOT_FOUND
;
159 This function processes the results of changes in configuration.
162 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
163 @param Action Specifies the type of action taken by the browser.
164 @param QuestionId A unique value which is sent to the original exporting driver
165 so that it can identify the type of data to expect.
166 @param Type The type of value for the question.
167 @param Value A pointer to the data being sent to the original exporting driver.
168 @param ActionRequest On return, points to the action requested by the callback function.
170 @retval EFI_SUCCESS The callback successfully handled the action.
171 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
172 @retval EFI_DEVICE_ERROR The variable could not be saved.
173 @retval EFI_UNSUPPORTED The specified Action is not supported by the callback.
179 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
180 IN EFI_BROWSER_ACTION Action
,
181 IN EFI_QUESTION_ID QuestionId
,
183 IN EFI_IFR_TYPE_VALUE
*Value
,
184 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
187 return UiFrontPageCallbackHandler (gFrontPagePrivate
.HiiHandle
, Action
, QuestionId
, Type
, Value
, ActionRequest
);
192 Update the menus in the front page.
196 UpdateFrontPageForm (
200 VOID
*StartOpCodeHandle
;
201 VOID
*EndOpCodeHandle
;
202 EFI_IFR_GUID_LABEL
*StartGuidLabel
;
203 EFI_IFR_GUID_LABEL
*EndGuidLabel
;
206 // Allocate space for creation of UpdateData Buffer
208 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
209 ASSERT (StartOpCodeHandle
!= NULL
);
211 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
212 ASSERT (EndOpCodeHandle
!= NULL
);
214 // Create Hii Extend Label OpCode as the start opcode
216 StartGuidLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
217 StartGuidLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
218 StartGuidLabel
->Number
= LABEL_FRANTPAGE_INFORMATION
;
220 // Create Hii Extend Label OpCode as the end opcode
222 EndGuidLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
223 EndGuidLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
224 EndGuidLabel
->Number
= LABEL_END
;
227 //Updata Front Page form
229 UiCustomizeFrontPage (
230 gFrontPagePrivate
.HiiHandle
,
235 gFrontPagePrivate
.HiiHandle
,
242 HiiFreeOpCodeHandle (StartOpCodeHandle
);
243 HiiFreeOpCodeHandle (EndOpCodeHandle
);
247 Initialize HII information for the FrontPage
250 @retval EFI_SUCCESS The operation is successful.
251 @retval EFI_DEVICE_ERROR If the dynamic opcode creation failed.
255 InitializeFrontPage (
261 // Locate Hii relative protocols
263 Status
= gBS
->LocateProtocol (&gEfiFormBrowser2ProtocolGuid
, NULL
, (VOID
**) &gFormBrowser2
);
264 if (EFI_ERROR (Status
)) {
269 // Install Device Path Protocol and Config Access protocol to driver handle
271 gFrontPagePrivate
.DriverHandle
= NULL
;
272 Status
= gBS
->InstallMultipleProtocolInterfaces (
273 &gFrontPagePrivate
.DriverHandle
,
274 &gEfiDevicePathProtocolGuid
,
275 &mFrontPageHiiVendorDevicePath
,
276 &gEfiHiiConfigAccessProtocolGuid
,
277 &gFrontPagePrivate
.ConfigAccess
,
280 ASSERT_EFI_ERROR (Status
);
283 // Publish our HII data
285 gFrontPagePrivate
.HiiHandle
= HiiAddPackages (
287 gFrontPagePrivate
.DriverHandle
,
292 ASSERT (gFrontPagePrivate
.HiiHandle
!= NULL
);
295 //Updata Front Page banner strings
297 UpdateFrontPageBannerStrings ();
300 // Update front page menus.
302 UpdateFrontPageForm();
308 Call the browser and display the front page
310 @return Status code that will be returned by
311 EFI_FORM_BROWSER2_PROTOCOL.SendForm ().
320 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
323 // Begin waiting for USER INPUT
327 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_PC_INPUT_WAIT
)
330 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
331 Status
= gFormBrowser2
->SendForm (
333 &gFrontPagePrivate
.HiiHandle
,
341 // Check whether user change any option setting which needs a reset to be effective
343 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
344 EnableResetRequired ();
351 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
++) {
408 DestMax
= 0x20 / sizeof (CHAR16
);
409 StringBuffer
= AllocateZeroPool (0x20);
410 ASSERT (StringBuffer
!= NULL
);
411 UnicodeValueToStringS (StringBuffer
, sizeof (CHAR16
) * DestMax
, LEFT_JUSTIFY
, FreqMhz
/ 1000, 3);
412 Index
= StrnLenS (StringBuffer
, DestMax
);
413 StrCatS (StringBuffer
, DestMax
, L
".");
414 UnicodeValueToStringS (
415 StringBuffer
+ Index
+ 1,
416 sizeof (CHAR16
) * (DestMax
- (Index
+ 1)),
418 (FreqMhz
% 1000) / 10,
421 StrCatS (StringBuffer
, DestMax
, L
" GHz");
422 *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
);
502 Update the banner information for the Front Page based on Smbios information.
506 UpdateFrontPageBannerStrings (
512 CHAR16
*FirmwareVersionString
;
514 EFI_SMBIOS_HANDLE SmbiosHandle
;
515 EFI_SMBIOS_PROTOCOL
*Smbios
;
516 SMBIOS_TABLE_TYPE0
*Type0Record
;
517 SMBIOS_TABLE_TYPE1
*Type1Record
;
518 SMBIOS_TABLE_TYPE4
*Type4Record
;
519 SMBIOS_TABLE_TYPE19
*Type19Record
;
520 EFI_SMBIOS_TABLE_HEADER
*Record
;
521 UINT64 InstalledMemory
;
528 // Update default banner string.
530 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE4_LEFT
), NULL
);
531 UiCustomizeFrontPageBanner (4, TRUE
, &NewString
);
532 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE4_LEFT
), NewString
, NULL
);
533 FreePool (NewString
);
535 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE4_RIGHT
), NULL
);
536 UiCustomizeFrontPageBanner (4, FALSE
, &NewString
);
537 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE4_RIGHT
), NewString
, NULL
);
538 FreePool (NewString
);
540 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE5_LEFT
), NULL
);
541 UiCustomizeFrontPageBanner (5, TRUE
, &NewString
);
542 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE5_LEFT
), NewString
, NULL
);
543 FreePool (NewString
);
545 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE5_RIGHT
), NULL
);
546 UiCustomizeFrontPageBanner (5, FALSE
, &NewString
);
547 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE5_RIGHT
), NewString
, NULL
);
548 FreePool (NewString
);
551 // Update Front Page banner strings base on SmBios Table.
553 Status
= gBS
->LocateProtocol (&gEfiSmbiosProtocolGuid
, NULL
, (VOID
**) &Smbios
);
554 if (EFI_ERROR (Status
)) {
556 // Smbios protocol not found, get the default value.
558 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_COMPUTER_MODEL
), NULL
);
559 UiCustomizeFrontPageBanner (1, TRUE
, &NewString
);
560 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_COMPUTER_MODEL
), NewString
, NULL
);
561 FreePool (NewString
);
563 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_CPU_MODEL
), NULL
);
564 UiCustomizeFrontPageBanner (2, TRUE
, &NewString
);
565 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_CPU_MODEL
), NewString
, NULL
);
566 FreePool (NewString
);
568 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_CPU_SPEED
), NULL
);
569 UiCustomizeFrontPageBanner (2, FALSE
, &NewString
);
570 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_CPU_SPEED
), NewString
, NULL
);
571 FreePool (NewString
);
573 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION
), NULL
);
574 UiCustomizeFrontPageBanner (3, TRUE
, &NewString
);
575 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION
), NewString
, NULL
);
576 FreePool (NewString
);
578 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_MEMORY_SIZE
), NULL
);
579 UiCustomizeFrontPageBanner (3, FALSE
, &NewString
);
580 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_MEMORY_SIZE
), NewString
, NULL
);
581 FreePool (NewString
);
586 SmbiosHandle
= SMBIOS_HANDLE_PI_RESERVED
;
587 Status
= Smbios
->GetNext (Smbios
, &SmbiosHandle
, NULL
, &Record
, NULL
);
588 while (!EFI_ERROR(Status
)) {
589 if (Record
->Type
== SMBIOS_TYPE_BIOS_INFORMATION
) {
590 Type0Record
= (SMBIOS_TABLE_TYPE0
*) Record
;
591 StrIndex
= Type0Record
->BiosVersion
;
592 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type0Record
+ Type0Record
->Hdr
.Length
), StrIndex
, &NewString
);
594 FirmwareVersionString
= (CHAR16
*) PcdGetPtr (PcdFirmwareVersionString
);
595 if (*FirmwareVersionString
!= 0x0000 ) {
596 FreePool (NewString
);
597 NewString
= (CHAR16
*) PcdGetPtr (PcdFirmwareVersionString
);
598 UiCustomizeFrontPageBanner (3, TRUE
, &NewString
);
599 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION
), NewString
, NULL
);
601 UiCustomizeFrontPageBanner (3, TRUE
, &NewString
);
602 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION
), NewString
, NULL
);
603 FreePool (NewString
);
607 if (Record
->Type
== SMBIOS_TYPE_SYSTEM_INFORMATION
) {
608 Type1Record
= (SMBIOS_TABLE_TYPE1
*) Record
;
609 StrIndex
= Type1Record
->ProductName
;
610 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type1Record
+ Type1Record
->Hdr
.Length
), StrIndex
, &NewString
);
611 UiCustomizeFrontPageBanner (1, TRUE
, &NewString
);
612 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_COMPUTER_MODEL
), NewString
, NULL
);
613 FreePool (NewString
);
616 if ((Record
->Type
== SMBIOS_TYPE_PROCESSOR_INFORMATION
) && !FoundCpu
) {
617 Type4Record
= (SMBIOS_TABLE_TYPE4
*) Record
;
619 // The information in the record should be only valid when the CPU Socket is populated.
621 if ((Type4Record
->Status
& SMBIOS_TYPE4_CPU_SOCKET_POPULATED
) == SMBIOS_TYPE4_CPU_SOCKET_POPULATED
) {
622 StrIndex
= Type4Record
->ProcessorVersion
;
623 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type4Record
+ Type4Record
->Hdr
.Length
), StrIndex
, &NewString
);
624 UiCustomizeFrontPageBanner (2, TRUE
, &NewString
);
625 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_CPU_MODEL
), NewString
, NULL
);
626 FreePool (NewString
);
628 ConvertProcessorToString(Type4Record
->CurrentSpeed
, 6, &NewString
);
629 UiCustomizeFrontPageBanner (2, FALSE
, &NewString
);
630 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_CPU_SPEED
), NewString
, NULL
);
631 FreePool (NewString
);
637 if ( Record
->Type
== SMBIOS_TYPE_MEMORY_ARRAY_MAPPED_ADDRESS
) {
638 Type19Record
= (SMBIOS_TABLE_TYPE19
*) Record
;
639 if (Type19Record
->StartingAddress
!= 0xFFFFFFFF ) {
640 InstalledMemory
+= RShiftU64(Type19Record
->EndingAddress
-
641 Type19Record
->StartingAddress
+ 1, 10);
643 InstalledMemory
+= RShiftU64(Type19Record
->ExtendedEndingAddress
-
644 Type19Record
->ExtendedStartingAddress
+ 1, 20);
648 Status
= Smbios
->GetNext (Smbios
, &SmbiosHandle
, NULL
, &Record
, NULL
);
652 // Now update the total installed RAM size
654 ConvertMemorySizeToString ((UINT32
)InstalledMemory
, &NewString
);
655 UiCustomizeFrontPageBanner (3, FALSE
, &NewString
);
656 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_MEMORY_SIZE
), NewString
, NULL
);
657 FreePool (NewString
);
661 This function will change video resolution and text mode
662 according to defined setup mode or defined boot mode
664 @param IsSetupMode Indicate mode is changed to setup mode or boot mode.
666 @retval EFI_SUCCESS Mode is changed successfully.
667 @retval Others Mode failed to be changed.
675 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
676 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
678 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
682 UINT32 NewHorizontalResolution
;
683 UINT32 NewVerticalResolution
;
687 EFI_HANDLE
*HandleBuffer
;
697 // Get current video resolution and text mode
699 Status
= gBS
->HandleProtocol (
700 gST
->ConsoleOutHandle
,
701 &gEfiGraphicsOutputProtocolGuid
,
702 (VOID
**)&GraphicsOutput
704 if (EFI_ERROR (Status
)) {
705 GraphicsOutput
= NULL
;
708 Status
= gBS
->HandleProtocol (
709 gST
->ConsoleOutHandle
,
710 &gEfiSimpleTextOutProtocolGuid
,
711 (VOID
**)&SimpleTextOut
713 if (EFI_ERROR (Status
)) {
714 SimpleTextOut
= NULL
;
717 if ((GraphicsOutput
== NULL
) || (SimpleTextOut
== NULL
)) {
718 return EFI_UNSUPPORTED
;
723 // The required resolution and text mode is setup mode.
725 NewHorizontalResolution
= mSetupHorizontalResolution
;
726 NewVerticalResolution
= mSetupVerticalResolution
;
727 NewColumns
= mSetupTextModeColumn
;
728 NewRows
= mSetupTextModeRow
;
731 // The required resolution and text mode is boot mode.
733 NewHorizontalResolution
= mBootHorizontalResolution
;
734 NewVerticalResolution
= mBootVerticalResolution
;
735 NewColumns
= mBootTextModeColumn
;
736 NewRows
= mBootTextModeRow
;
739 if (GraphicsOutput
!= NULL
) {
740 MaxGopMode
= GraphicsOutput
->Mode
->MaxMode
;
743 if (SimpleTextOut
!= NULL
) {
744 MaxTextMode
= SimpleTextOut
->Mode
->MaxMode
;
748 // 1. If current video resolution is same with required video resolution,
749 // video resolution need not be changed.
750 // 1.1. If current text mode is same with required text mode, text mode need not be changed.
751 // 1.2. If current text mode is different from required text mode, text mode need be changed.
752 // 2. If current video resolution is different from required video resolution, we need restart whole console drivers.
754 for (ModeNumber
= 0; ModeNumber
< MaxGopMode
; ModeNumber
++) {
755 Status
= GraphicsOutput
->QueryMode (
761 if (!EFI_ERROR (Status
)) {
762 if ((Info
->HorizontalResolution
== NewHorizontalResolution
) &&
763 (Info
->VerticalResolution
== NewVerticalResolution
)) {
764 if ((GraphicsOutput
->Mode
->Info
->HorizontalResolution
== NewHorizontalResolution
) &&
765 (GraphicsOutput
->Mode
->Info
->VerticalResolution
== NewVerticalResolution
)) {
767 // Current resolution is same with required resolution, check if text mode need be set
769 Status
= SimpleTextOut
->QueryMode (SimpleTextOut
, SimpleTextOut
->Mode
->Mode
, &CurrentColumn
, &CurrentRow
);
770 ASSERT_EFI_ERROR (Status
);
771 if (CurrentColumn
== NewColumns
&& CurrentRow
== NewRows
) {
773 // If current text mode is same with required text mode. Do nothing
779 // If current text mode is different from required text mode. Set new video mode
781 for (Index
= 0; Index
< MaxTextMode
; Index
++) {
782 Status
= SimpleTextOut
->QueryMode (SimpleTextOut
, Index
, &CurrentColumn
, &CurrentRow
);
783 if (!EFI_ERROR(Status
)) {
784 if ((CurrentColumn
== NewColumns
) && (CurrentRow
== NewRows
)) {
786 // Required text mode is supported, set it.
788 Status
= SimpleTextOut
->SetMode (SimpleTextOut
, Index
);
789 ASSERT_EFI_ERROR (Status
);
791 // Update text mode PCD.
793 Status
= PcdSet32S (PcdConOutColumn
, mSetupTextModeColumn
);
794 ASSERT_EFI_ERROR (Status
);
795 Status
= PcdSet32S (PcdConOutRow
, mSetupTextModeRow
);
796 ASSERT_EFI_ERROR (Status
);
802 if (Index
== MaxTextMode
) {
804 // If required text mode is not supported, return error.
807 return EFI_UNSUPPORTED
;
812 // If current video resolution is not same with the new one, set new video resolution.
813 // In this case, the driver which produces simple text out need be restarted.
815 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, ModeNumber
);
816 if (!EFI_ERROR (Status
)) {
826 if (ModeNumber
== MaxGopMode
) {
828 // If the resolution is not supported, return error.
830 return EFI_UNSUPPORTED
;
834 // Set PCD to Inform GraphicsConsole to change video resolution.
835 // Set PCD to Inform Consplitter to change text mode.
837 Status
= PcdSet32S (PcdVideoHorizontalResolution
, NewHorizontalResolution
);
838 ASSERT_EFI_ERROR (Status
);
839 Status
= PcdSet32S (PcdVideoVerticalResolution
, NewVerticalResolution
);
840 ASSERT_EFI_ERROR (Status
);
841 Status
= PcdSet32S (PcdConOutColumn
, NewColumns
);
842 ASSERT_EFI_ERROR (Status
);
843 Status
= PcdSet32S (PcdConOutRow
, NewRows
);
844 ASSERT_EFI_ERROR (Status
);
847 // Video mode is changed, so restart graphics console driver and higher level driver.
848 // Reconnect graphics console driver and higher level driver.
849 // Locate all the handles with GOP protocol and reconnect it.
851 Status
= gBS
->LocateHandleBuffer (
853 &gEfiSimpleTextOutProtocolGuid
,
858 if (!EFI_ERROR (Status
)) {
859 for (Index
= 0; Index
< HandleCount
; Index
++) {
860 gBS
->DisconnectController (HandleBuffer
[Index
], NULL
, NULL
);
862 for (Index
= 0; Index
< HandleCount
; Index
++) {
863 gBS
->ConnectController (HandleBuffer
[Index
], NULL
, NULL
, TRUE
);
865 if (HandleBuffer
!= NULL
) {
866 FreePool (HandleBuffer
);
874 The user Entry Point for Application. The user code starts with this function
875 as the real entry point for the image goes into a library that calls this
878 @param[in] ImageHandle The firmware allocated handle for the EFI image.
879 @param[in] SystemTable A pointer to the EFI System Table.
881 @retval EFI_SUCCESS The entry point is executed successfully.
882 @retval other Some error occurs when executing this entry point.
887 InitializeUserInterface (
888 IN EFI_HANDLE ImageHandle
,
889 IN EFI_SYSTEM_TABLE
*SystemTable
892 EFI_HII_HANDLE HiiHandle
;
894 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
895 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
896 UINTN BootTextColumn
;
899 if (!mModeInitialized
) {
901 // After the console is ready, get current video resolution
902 // and text mode before launching setup at first time.
904 Status
= gBS
->HandleProtocol (
905 gST
->ConsoleOutHandle
,
906 &gEfiGraphicsOutputProtocolGuid
,
907 (VOID
**)&GraphicsOutput
909 if (EFI_ERROR (Status
)) {
910 GraphicsOutput
= NULL
;
913 Status
= gBS
->HandleProtocol (
914 gST
->ConsoleOutHandle
,
915 &gEfiSimpleTextOutProtocolGuid
,
916 (VOID
**)&SimpleTextOut
918 if (EFI_ERROR (Status
)) {
919 SimpleTextOut
= NULL
;
922 if (GraphicsOutput
!= NULL
) {
924 // Get current video resolution and text mode.
926 mBootHorizontalResolution
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
927 mBootVerticalResolution
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
930 if (SimpleTextOut
!= NULL
) {
931 Status
= SimpleTextOut
->QueryMode (
933 SimpleTextOut
->Mode
->Mode
,
937 mBootTextModeColumn
= (UINT32
)BootTextColumn
;
938 mBootTextModeRow
= (UINT32
)BootTextRow
;
942 // Get user defined text mode for setup.
944 mSetupHorizontalResolution
= PcdGet32 (PcdSetupVideoHorizontalResolution
);
945 mSetupVerticalResolution
= PcdGet32 (PcdSetupVideoVerticalResolution
);
946 mSetupTextModeColumn
= PcdGet32 (PcdSetupConOutColumn
);
947 mSetupTextModeRow
= PcdGet32 (PcdSetupConOutRow
);
949 mModeInitialized
= TRUE
;
952 gBS
->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL
);
953 gST
->ConOut
->ClearScreen (gST
->ConOut
);
956 // Install customized fonts needed by Front Page
958 HiiHandle
= ExportFonts ();
959 ASSERT (HiiHandle
!= NULL
);
961 InitializeStringSupport ();
963 UiSetConsoleMode (TRUE
);
965 UiSetConsoleMode (FALSE
);
967 UninitializeStringSupport ();
968 HiiRemovePackages (HiiHandle
);
974 This function is the main entry of the UI entry.
975 The function will present the main menu of the system UI.
977 @param ConnectAllHappened Caller passes the value to UI to avoid unnecessary connect-all.
983 IN BOOLEAN ConnectAllHappened
987 EFI_BOOT_LOGO_PROTOCOL
*BootLogo
;
994 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_PC_USER_SETUP
)
998 // Indicate if the connect all has been performed before.
999 // If has not been performed before, do here.
1001 if (!ConnectAllHappened
) {
1002 EfiBootManagerConnectAll ();
1006 // The boot option enumeration time is acceptable in Ui driver
1008 EfiBootManagerRefreshAllBootOption ();
1011 // Boot Logo is corrupted, report it using Boot Logo protocol.
1013 Status
= gBS
->LocateProtocol (&gEfiBootLogoProtocolGuid
, NULL
, (VOID
**) &BootLogo
);
1014 if (!EFI_ERROR (Status
) && (BootLogo
!= NULL
)) {
1015 BootLogo
->SetBootLogo (BootLogo
, NULL
, 0, 0, 0, 0);
1018 InitializeFrontPage ();
1024 if (mLanguageString
!= NULL
) {
1025 FreePool (mLanguageString
);
1026 mLanguageString
= NULL
;
1030 //Will leave browser, check any reset required change is applied? if yes, reset system
1032 SetupResetReminder ();
1036 // Following are BDS Lib functions which contain all the code about setup browser reset reminder feature.
1037 // Setup Browser reset reminder feature is that an reset reminder will be given before user leaves the setup browser if
1038 // user change any option setting which needs a reset to be effective, and the reset will be applied according to the user selection.
1043 Enable the setup browser reset reminder feature.
1044 This routine is used in platform tip. If the platform policy need the feature, use the routine to enable it.
1049 EnableResetReminderFeature (
1053 mFeaturerSwitch
= TRUE
;
1058 Disable the setup browser reset reminder feature.
1059 This routine is used in platform tip. If the platform policy do not want the feature, use the routine to disable it.
1064 DisableResetReminderFeature (
1068 mFeaturerSwitch
= FALSE
;
1073 Record the info that a reset is required.
1074 A module boolean variable is used to record whether a reset is required.
1079 EnableResetRequired (
1083 mResetRequired
= TRUE
;
1088 Record the info that no reset is required.
1089 A module boolean variable is used to record whether a reset is required.
1094 DisableResetRequired (
1098 mResetRequired
= FALSE
;
1103 Check whether platform policy enable the reset reminder feature. The default is enabled.
1108 IsResetReminderFeatureEnable (
1112 return mFeaturerSwitch
;
1117 Check if user changed any option setting which needs a system reset to be effective.
1126 return mResetRequired
;
1131 Check whether a reset is needed, and finish the reset reminder feature.
1132 If a reset is needed, Popup a menu to notice user, and finish the feature
1133 according to the user selection.
1138 SetupResetReminder (
1143 CHAR16
*StringBuffer1
;
1144 CHAR16
*StringBuffer2
;
1148 //check any reset required change is applied? if yes, reset system
1150 if (IsResetReminderFeatureEnable ()) {
1151 if (IsResetRequired ()) {
1153 StringBuffer1
= AllocateZeroPool (MAX_STRING_LEN
* sizeof (CHAR16
));
1154 ASSERT (StringBuffer1
!= NULL
);
1155 StringBuffer2
= AllocateZeroPool (MAX_STRING_LEN
* sizeof (CHAR16
));
1156 ASSERT (StringBuffer2
!= NULL
);
1157 StrCpyS (StringBuffer1
, MAX_STRING_LEN
, L
"Configuration changed. Reset to apply it Now.");
1158 StrCpyS (StringBuffer2
, MAX_STRING_LEN
, L
"Press ENTER to reset");
1160 // Popup a menu to notice user
1163 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, StringBuffer1
, StringBuffer2
, NULL
);
1164 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1166 FreePool (StringBuffer1
);
1167 FreePool (StringBuffer2
);
1169 gRT
->ResetSystem (EfiResetCold
, EFI_SUCCESS
, 0, NULL
);