2 FrontPage routines to handle the callbacks and browser calls
4 Copyright (c) 2004 - 2016, 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 gConnectAllHappened
= FALSE
;
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 return EFI_NOT_FOUND
;
160 This function processes the results of changes in configuration.
163 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
164 @param Action Specifies the type of action taken by the browser.
165 @param QuestionId A unique value which is sent to the original exporting driver
166 so that it can identify the type of data to expect.
167 @param Type The type of value for the question.
168 @param Value A pointer to the data being sent to the original exporting driver.
169 @param ActionRequest On return, points to the action requested by the callback function.
171 @retval EFI_SUCCESS The callback successfully handled the action.
172 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
173 @retval EFI_DEVICE_ERROR The variable could not be saved.
174 @retval EFI_UNSUPPORTED The specified Action is not supported by the callback.
180 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
181 IN EFI_BROWSER_ACTION Action
,
182 IN EFI_QUESTION_ID QuestionId
,
184 IN EFI_IFR_TYPE_VALUE
*Value
,
185 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
188 return UiFrontPageCallbackHandler (gFrontPagePrivate
.HiiHandle
, Action
, QuestionId
, Type
, Value
, ActionRequest
);
193 Update the menus in the front page.
197 UpdateFrontPageForm (
201 VOID
*StartOpCodeHandle
;
202 VOID
*EndOpCodeHandle
;
203 EFI_IFR_GUID_LABEL
*StartGuidLabel
;
204 EFI_IFR_GUID_LABEL
*EndGuidLabel
;
207 // Allocate space for creation of UpdateData Buffer
209 StartOpCodeHandle
= HiiAllocateOpCodeHandle ();
210 ASSERT (StartOpCodeHandle
!= NULL
);
212 EndOpCodeHandle
= HiiAllocateOpCodeHandle ();
213 ASSERT (EndOpCodeHandle
!= NULL
);
215 // Create Hii Extend Label OpCode as the start opcode
217 StartGuidLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (StartOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
218 StartGuidLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
219 StartGuidLabel
->Number
= LABEL_FRANTPAGE_INFORMATION
;
221 // Create Hii Extend Label OpCode as the end opcode
223 EndGuidLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (EndOpCodeHandle
, &gEfiIfrTianoGuid
, NULL
, sizeof (EFI_IFR_GUID_LABEL
));
224 EndGuidLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
225 EndGuidLabel
->Number
= LABEL_END
;
228 //Updata Front Page form
230 UiCustomizeFrontPage (
231 gFrontPagePrivate
.HiiHandle
,
236 gFrontPagePrivate
.HiiHandle
,
243 HiiFreeOpCodeHandle (StartOpCodeHandle
);
244 HiiFreeOpCodeHandle (EndOpCodeHandle
);
248 Initialize HII information for the FrontPage
251 @retval EFI_SUCCESS The operation is successful.
252 @retval EFI_DEVICE_ERROR If the dynamic opcode creation failed.
256 InitializeFrontPage (
262 // Locate Hii relative protocols
264 Status
= gBS
->LocateProtocol (&gEfiFormBrowser2ProtocolGuid
, NULL
, (VOID
**) &gFormBrowser2
);
265 if (EFI_ERROR (Status
)) {
270 // Install Device Path Protocol and Config Access protocol to driver handle
272 gFrontPagePrivate
.DriverHandle
= NULL
;
273 Status
= gBS
->InstallMultipleProtocolInterfaces (
274 &gFrontPagePrivate
.DriverHandle
,
275 &gEfiDevicePathProtocolGuid
,
276 &mFrontPageHiiVendorDevicePath
,
277 &gEfiHiiConfigAccessProtocolGuid
,
278 &gFrontPagePrivate
.ConfigAccess
,
281 ASSERT_EFI_ERROR (Status
);
284 // Publish our HII data
286 gFrontPagePrivate
.HiiHandle
= HiiAddPackages (
288 gFrontPagePrivate
.DriverHandle
,
293 ASSERT (gFrontPagePrivate
.HiiHandle
!= NULL
);
296 //Updata Front Page banner strings
298 UpdateFrontPageBannerStrings ();
301 // Update front page menus.
303 UpdateFrontPageForm();
309 Call the browser and display the front page
311 @return Status code that will be returned by
312 EFI_FORM_BROWSER2_PROTOCOL.SendForm ().
321 EFI_BROWSER_ACTION_REQUEST ActionRequest
;
324 // Begin waiting for USER INPUT
328 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_PC_INPUT_WAIT
)
331 ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
332 Status
= gFormBrowser2
->SendForm (
334 &gFrontPagePrivate
.HiiHandle
,
342 // Check whether user change any option setting which needs a reset to be effective
344 if (ActionRequest
== EFI_BROWSER_ACTION_REQUEST_RESET
) {
345 EnableResetRequired ();
352 Remove the installed packages from the HiiDatabase.
361 Status
= gBS
->UninstallMultipleProtocolInterfaces (
362 gFrontPagePrivate
.DriverHandle
,
363 &gEfiDevicePathProtocolGuid
,
364 &mFrontPageHiiVendorDevicePath
,
365 &gEfiHiiConfigAccessProtocolGuid
,
366 &gFrontPagePrivate
.ConfigAccess
,
369 ASSERT_EFI_ERROR (Status
);
372 // Publish our HII data
374 HiiRemovePackages (gFrontPagePrivate
.HiiHandle
);
375 if (gFrontPagePrivate
.LanguageToken
!= NULL
) {
376 FreePool (gFrontPagePrivate
.LanguageToken
);
377 gFrontPagePrivate
.LanguageToken
= NULL
;
382 Convert Processor Frequency Data to a string.
384 @param ProcessorFrequency The frequency data to process
385 @param Base10Exponent The exponent based on 10
386 @param String The string that is created
390 ConvertProcessorToString (
391 IN UINT16 ProcessorFrequency
,
392 IN UINT16 Base10Exponent
,
396 CHAR16
*StringBuffer
;
401 if (Base10Exponent
>= 6) {
402 FreqMhz
= ProcessorFrequency
;
403 for (Index
= 0; Index
< (UINTN
) (Base10Exponent
- 6); Index
++) {
409 DestMax
= 0x20 / sizeof (CHAR16
);
410 StringBuffer
= AllocateZeroPool (0x20);
411 ASSERT (StringBuffer
!= NULL
);
412 Index
= UnicodeValueToString (StringBuffer
, LEFT_JUSTIFY
, FreqMhz
/ 1000, 3);
413 StrCatS (StringBuffer
, DestMax
, L
".");
414 UnicodeValueToString (StringBuffer
+ Index
+ 1, PREFIX_ZERO
, (FreqMhz
% 1000) / 10, 2);
415 StrCatS (StringBuffer
, DestMax
, L
" GHz");
416 *String
= (CHAR16
*) StringBuffer
;
422 Convert Memory Size to a string.
424 @param MemorySize The size of the memory to process
425 @param String The string that is created
429 ConvertMemorySizeToString (
430 IN UINT32 MemorySize
,
434 CHAR16
*StringBuffer
;
436 StringBuffer
= AllocateZeroPool (0x24);
437 ASSERT (StringBuffer
!= NULL
);
438 UnicodeValueToString (StringBuffer
, LEFT_JUSTIFY
, MemorySize
, 10);
439 StrCatS (StringBuffer
, 0x24 / sizeof (CHAR16
), L
" MB RAM");
441 *String
= (CHAR16
*) StringBuffer
;
448 Acquire the string associated with the Index from smbios structure and return it.
449 The caller is responsible for free the string buffer.
451 @param OptionalStrStart The start position to search the string
452 @param Index The index of the string to extract
453 @param String The string that is extracted
455 @retval EFI_SUCCESS The function returns EFI_SUCCESS always.
459 GetOptionalStringByIndex (
460 IN CHAR8
*OptionalStrStart
,
468 *String
= AllocateZeroPool (sizeof (CHAR16
));
475 OptionalStrStart
+= StrSize
;
476 StrSize
= AsciiStrSize (OptionalStrStart
);
477 } while (OptionalStrStart
[StrSize
] != 0 && Index
!= 0);
479 if ((Index
!= 0) || (StrSize
== 1)) {
481 // Meet the end of strings set but Index is non-zero, or
482 // Find an empty string
484 *String
= GetStringById (STRING_TOKEN (STR_MISSING_STRING
));
486 *String
= AllocatePool (StrSize
* sizeof (CHAR16
));
487 AsciiStrToUnicodeStr (OptionalStrStart
, *String
);
496 Update the banner information for the Front Page based on Smbios information.
500 UpdateFrontPageBannerStrings (
506 CHAR16
*FirmwareVersionString
;
508 EFI_SMBIOS_HANDLE SmbiosHandle
;
509 EFI_SMBIOS_PROTOCOL
*Smbios
;
510 SMBIOS_TABLE_TYPE0
*Type0Record
;
511 SMBIOS_TABLE_TYPE1
*Type1Record
;
512 SMBIOS_TABLE_TYPE4
*Type4Record
;
513 SMBIOS_TABLE_TYPE19
*Type19Record
;
514 EFI_SMBIOS_TABLE_HEADER
*Record
;
515 UINT64 InstalledMemory
;
522 // Update default banner string.
524 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE4_LEFT
), NULL
);
525 UiCustomizeFrontPageBanner (4, TRUE
, &NewString
);
526 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE4_LEFT
), NewString
, NULL
);
527 FreePool (NewString
);
529 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE4_RIGHT
), NULL
);
530 UiCustomizeFrontPageBanner (4, FALSE
, &NewString
);
531 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE4_RIGHT
), NewString
, NULL
);
532 FreePool (NewString
);
534 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE5_LEFT
), NULL
);
535 UiCustomizeFrontPageBanner (5, TRUE
, &NewString
);
536 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE5_LEFT
), NewString
, NULL
);
537 FreePool (NewString
);
539 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE5_RIGHT
), NULL
);
540 UiCustomizeFrontPageBanner (5, FALSE
, &NewString
);
541 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE5_RIGHT
), NewString
, NULL
);
542 FreePool (NewString
);
545 // Update Front Page banner strings base on SmBios Table.
547 Status
= gBS
->LocateProtocol (&gEfiSmbiosProtocolGuid
, NULL
, (VOID
**) &Smbios
);
548 if (EFI_ERROR (Status
)) {
550 // Smbios protocol not found, get the default value.
552 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_COMPUTER_MODEL
), NULL
);
553 UiCustomizeFrontPageBanner (1, TRUE
, &NewString
);
554 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_COMPUTER_MODEL
), NewString
, NULL
);
555 FreePool (NewString
);
557 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_CPU_MODEL
), NULL
);
558 UiCustomizeFrontPageBanner (2, TRUE
, &NewString
);
559 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_CPU_MODEL
), NewString
, NULL
);
560 FreePool (NewString
);
562 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_CPU_SPEED
), NULL
);
563 UiCustomizeFrontPageBanner (2, FALSE
, &NewString
);
564 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_CPU_SPEED
), NewString
, NULL
);
565 FreePool (NewString
);
567 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION
), NULL
);
568 UiCustomizeFrontPageBanner (3, TRUE
, &NewString
);
569 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION
), NewString
, NULL
);
570 FreePool (NewString
);
572 NewString
= HiiGetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_MEMORY_SIZE
), NULL
);
573 UiCustomizeFrontPageBanner (3, FALSE
, &NewString
);
574 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_MEMORY_SIZE
), NewString
, NULL
);
575 FreePool (NewString
);
580 SmbiosHandle
= SMBIOS_HANDLE_PI_RESERVED
;
581 Status
= Smbios
->GetNext (Smbios
, &SmbiosHandle
, NULL
, &Record
, NULL
);
582 while (!EFI_ERROR(Status
)) {
583 if (Record
->Type
== EFI_SMBIOS_TYPE_BIOS_INFORMATION
) {
584 Type0Record
= (SMBIOS_TABLE_TYPE0
*) Record
;
585 StrIndex
= Type0Record
->BiosVersion
;
586 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type0Record
+ Type0Record
->Hdr
.Length
), StrIndex
, &NewString
);
588 FirmwareVersionString
= (CHAR16
*) PcdGetPtr (PcdFirmwareVersionString
);
589 if (*FirmwareVersionString
!= 0x0000 ) {
590 FreePool (NewString
);
591 NewString
= (CHAR16
*) PcdGetPtr (PcdFirmwareVersionString
);
592 UiCustomizeFrontPageBanner (3, TRUE
, &NewString
);
593 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION
), NewString
, NULL
);
595 UiCustomizeFrontPageBanner (3, TRUE
, &NewString
);
596 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION
), NewString
, NULL
);
597 FreePool (NewString
);
601 if (Record
->Type
== EFI_SMBIOS_TYPE_SYSTEM_INFORMATION
) {
602 Type1Record
= (SMBIOS_TABLE_TYPE1
*) Record
;
603 StrIndex
= Type1Record
->ProductName
;
604 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type1Record
+ Type1Record
->Hdr
.Length
), StrIndex
, &NewString
);
605 UiCustomizeFrontPageBanner (1, TRUE
, &NewString
);
606 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_COMPUTER_MODEL
), NewString
, NULL
);
607 FreePool (NewString
);
610 if ((Record
->Type
== EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION
) && !FoundCpu
) {
611 Type4Record
= (SMBIOS_TABLE_TYPE4
*) Record
;
613 // The information in the record should be only valid when the CPU Socket is populated.
615 if ((Type4Record
->Status
& SMBIOS_TYPE4_CPU_SOCKET_POPULATED
) == SMBIOS_TYPE4_CPU_SOCKET_POPULATED
) {
616 StrIndex
= Type4Record
->ProcessorVersion
;
617 GetOptionalStringByIndex ((CHAR8
*)((UINT8
*)Type4Record
+ Type4Record
->Hdr
.Length
), StrIndex
, &NewString
);
618 UiCustomizeFrontPageBanner (2, TRUE
, &NewString
);
619 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_CPU_MODEL
), NewString
, NULL
);
620 FreePool (NewString
);
622 ConvertProcessorToString(Type4Record
->CurrentSpeed
, 6, &NewString
);
623 UiCustomizeFrontPageBanner (2, FALSE
, &NewString
);
624 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_CPU_SPEED
), NewString
, NULL
);
625 FreePool (NewString
);
631 if ( Record
->Type
== EFI_SMBIOS_TYPE_MEMORY_ARRAY_MAPPED_ADDRESS
) {
632 Type19Record
= (SMBIOS_TABLE_TYPE19
*) Record
;
633 if (Type19Record
->StartingAddress
!= 0xFFFFFFFF ) {
634 InstalledMemory
+= RShiftU64(Type19Record
->EndingAddress
-
635 Type19Record
->StartingAddress
+ 1, 10);
637 InstalledMemory
+= RShiftU64(Type19Record
->ExtendedEndingAddress
-
638 Type19Record
->ExtendedStartingAddress
+ 1, 20);
642 Status
= Smbios
->GetNext (Smbios
, &SmbiosHandle
, NULL
, &Record
, NULL
);
646 // Now update the total installed RAM size
648 ConvertMemorySizeToString ((UINT32
)InstalledMemory
, &NewString
);
649 UiCustomizeFrontPageBanner (3, FALSE
, &NewString
);
650 HiiSetString (gFrontPagePrivate
.HiiHandle
, STRING_TOKEN (STR_FRONT_PAGE_MEMORY_SIZE
), NewString
, NULL
);
651 FreePool (NewString
);
655 This function will change video resolution and text mode
656 according to defined setup mode or defined boot mode
658 @param IsSetupMode Indicate mode is changed to setup mode or boot mode.
660 @retval EFI_SUCCESS Mode is changed successfully.
661 @retval Others Mode failed to be changed.
670 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
671 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
673 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
677 UINT32 NewHorizontalResolution
;
678 UINT32 NewVerticalResolution
;
682 EFI_HANDLE
*HandleBuffer
;
692 // Get current video resolution and text mode
694 Status
= gBS
->HandleProtocol (
695 gST
->ConsoleOutHandle
,
696 &gEfiGraphicsOutputProtocolGuid
,
697 (VOID
**)&GraphicsOutput
699 if (EFI_ERROR (Status
)) {
700 GraphicsOutput
= NULL
;
703 Status
= gBS
->HandleProtocol (
704 gST
->ConsoleOutHandle
,
705 &gEfiSimpleTextOutProtocolGuid
,
706 (VOID
**)&SimpleTextOut
708 if (EFI_ERROR (Status
)) {
709 SimpleTextOut
= NULL
;
712 if ((GraphicsOutput
== NULL
) || (SimpleTextOut
== NULL
)) {
713 return EFI_UNSUPPORTED
;
718 // The requried resolution and text mode is setup mode.
720 NewHorizontalResolution
= mSetupHorizontalResolution
;
721 NewVerticalResolution
= mSetupVerticalResolution
;
722 NewColumns
= mSetupTextModeColumn
;
723 NewRows
= mSetupTextModeRow
;
726 // The required resolution and text mode is boot mode.
728 NewHorizontalResolution
= mBootHorizontalResolution
;
729 NewVerticalResolution
= mBootVerticalResolution
;
730 NewColumns
= mBootTextModeColumn
;
731 NewRows
= mBootTextModeRow
;
734 if (GraphicsOutput
!= NULL
) {
735 MaxGopMode
= GraphicsOutput
->Mode
->MaxMode
;
738 if (SimpleTextOut
!= NULL
) {
739 MaxTextMode
= SimpleTextOut
->Mode
->MaxMode
;
743 // 1. If current video resolution is same with required video resolution,
744 // video resolution need not be changed.
745 // 1.1. If current text mode is same with required text mode, text mode need not be changed.
746 // 1.2. If current text mode is different from required text mode, text mode need be changed.
747 // 2. If current video resolution is different from required video resolution, we need restart whole console drivers.
749 for (ModeNumber
= 0; ModeNumber
< MaxGopMode
; ModeNumber
++) {
750 Status
= GraphicsOutput
->QueryMode (
756 if (!EFI_ERROR (Status
)) {
757 if ((Info
->HorizontalResolution
== NewHorizontalResolution
) &&
758 (Info
->VerticalResolution
== NewVerticalResolution
)) {
759 if ((GraphicsOutput
->Mode
->Info
->HorizontalResolution
== NewHorizontalResolution
) &&
760 (GraphicsOutput
->Mode
->Info
->VerticalResolution
== NewVerticalResolution
)) {
762 // Current resolution is same with required resolution, check if text mode need be set
764 Status
= SimpleTextOut
->QueryMode (SimpleTextOut
, SimpleTextOut
->Mode
->Mode
, &CurrentColumn
, &CurrentRow
);
765 ASSERT_EFI_ERROR (Status
);
766 if (CurrentColumn
== NewColumns
&& CurrentRow
== NewRows
) {
768 // If current text mode is same with required text mode. Do nothing
774 // If current text mode is different from requried text mode. Set new video mode
776 for (Index
= 0; Index
< MaxTextMode
; Index
++) {
777 Status
= SimpleTextOut
->QueryMode (SimpleTextOut
, Index
, &CurrentColumn
, &CurrentRow
);
778 if (!EFI_ERROR(Status
)) {
779 if ((CurrentColumn
== NewColumns
) && (CurrentRow
== NewRows
)) {
781 // Required text mode is supported, set it.
783 Status
= SimpleTextOut
->SetMode (SimpleTextOut
, Index
);
784 ASSERT_EFI_ERROR (Status
);
786 // Update text mode PCD.
788 Status
= PcdSet32S (PcdConOutColumn
, mSetupTextModeColumn
);
789 ASSERT_EFI_ERROR (Status
);
790 Status
= PcdSet32S (PcdConOutRow
, mSetupTextModeRow
);
791 ASSERT_EFI_ERROR (Status
);
797 if (Index
== MaxTextMode
) {
799 // If requried text mode is not supported, return error.
802 return EFI_UNSUPPORTED
;
807 // If current video resolution is not same with the new one, set new video resolution.
808 // In this case, the driver which produces simple text out need be restarted.
810 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, ModeNumber
);
811 if (!EFI_ERROR (Status
)) {
821 if (ModeNumber
== MaxGopMode
) {
823 // If the resolution is not supported, return error.
825 return EFI_UNSUPPORTED
;
829 // Set PCD to Inform GraphicsConsole to change video resolution.
830 // Set PCD to Inform Consplitter to change text mode.
832 Status
= PcdSet32S (PcdVideoHorizontalResolution
, NewHorizontalResolution
);
833 ASSERT_EFI_ERROR (Status
);
834 Status
= PcdSet32S (PcdVideoVerticalResolution
, NewVerticalResolution
);
835 ASSERT_EFI_ERROR (Status
);
836 Status
= PcdSet32S (PcdConOutColumn
, NewColumns
);
837 ASSERT_EFI_ERROR (Status
);
838 Status
= PcdSet32S (PcdConOutRow
, NewRows
);
839 ASSERT_EFI_ERROR (Status
);
842 // Video mode is changed, so restart graphics console driver and higher level driver.
843 // Reconnect graphics console driver and higher level driver.
844 // Locate all the handles with GOP protocol and reconnect it.
846 Status
= gBS
->LocateHandleBuffer (
848 &gEfiSimpleTextOutProtocolGuid
,
853 if (!EFI_ERROR (Status
)) {
854 for (Index
= 0; Index
< HandleCount
; Index
++) {
855 gBS
->DisconnectController (HandleBuffer
[Index
], NULL
, NULL
);
857 for (Index
= 0; Index
< HandleCount
; Index
++) {
858 gBS
->ConnectController (HandleBuffer
[Index
], NULL
, NULL
, TRUE
);
860 if (HandleBuffer
!= NULL
) {
861 FreePool (HandleBuffer
);
869 The user Entry Point for Application. The user code starts with this function
870 as the real entry point for the image goes into a library that calls this
873 @param[in] ImageHandle The firmware allocated handle for the EFI image.
874 @param[in] SystemTable A pointer to the EFI System Table.
876 @retval EFI_SUCCESS The entry point is executed successfully.
877 @retval other Some error occurs when executing this entry point.
882 InitializeUserInterface (
883 IN EFI_HANDLE ImageHandle
,
884 IN EFI_SYSTEM_TABLE
*SystemTable
887 EFI_HII_HANDLE HiiHandle
;
889 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
890 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOut
;
891 UINTN BootTextColumn
;
894 if (!mModeInitialized
) {
896 // After the console is ready, get current video resolution
897 // and text mode before launching setup at first time.
899 Status
= gBS
->HandleProtocol (
900 gST
->ConsoleOutHandle
,
901 &gEfiGraphicsOutputProtocolGuid
,
902 (VOID
**)&GraphicsOutput
904 if (EFI_ERROR (Status
)) {
905 GraphicsOutput
= NULL
;
908 Status
= gBS
->HandleProtocol (
909 gST
->ConsoleOutHandle
,
910 &gEfiSimpleTextOutProtocolGuid
,
911 (VOID
**)&SimpleTextOut
913 if (EFI_ERROR (Status
)) {
914 SimpleTextOut
= NULL
;
917 if (GraphicsOutput
!= NULL
) {
919 // Get current video resolution and text mode.
921 mBootHorizontalResolution
= GraphicsOutput
->Mode
->Info
->HorizontalResolution
;
922 mBootVerticalResolution
= GraphicsOutput
->Mode
->Info
->VerticalResolution
;
925 if (SimpleTextOut
!= NULL
) {
926 Status
= SimpleTextOut
->QueryMode (
928 SimpleTextOut
->Mode
->Mode
,
932 mBootTextModeColumn
= (UINT32
)BootTextColumn
;
933 mBootTextModeRow
= (UINT32
)BootTextRow
;
937 // Get user defined text mode for setup.
939 mSetupHorizontalResolution
= PcdGet32 (PcdSetupVideoHorizontalResolution
);
940 mSetupVerticalResolution
= PcdGet32 (PcdSetupVideoVerticalResolution
);
941 mSetupTextModeColumn
= PcdGet32 (PcdSetupConOutColumn
);
942 mSetupTextModeRow
= PcdGet32 (PcdSetupConOutRow
);
944 mModeInitialized
= TRUE
;
947 gBS
->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL
);
948 gST
->ConOut
->ClearScreen (gST
->ConOut
);
951 // Install customized fonts needed by Front Page
953 HiiHandle
= ExportFonts ();
954 ASSERT (HiiHandle
!= NULL
);
956 InitializeStringSupport ();
958 BdsSetConsoleMode (TRUE
);
960 BdsSetConsoleMode (FALSE
);
962 UninitializeStringSupport ();
963 HiiRemovePackages (HiiHandle
);
969 This function is the main entry of the UI entry.
970 The function will present the main menu of the system UI.
972 @param ConnectAllHappened Caller passes the value to UI to avoid unnecessary connect-all.
978 IN BOOLEAN ConnectAllHappened
982 EFI_BOOT_LOGO_PROTOCOL
*BootLogo
;
989 (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_PC_USER_SETUP
)
993 // Indicate if the connect all has been performed before.
995 if (ConnectAllHappened
) {
996 gConnectAllHappened
= TRUE
;
1000 // The boot option enumeration time is acceptable in Ui driver
1002 EfiBootManagerRefreshAllBootOption ();
1005 // Boot Logo is corrupted, report it using Boot Logo protocol.
1007 Status
= gBS
->LocateProtocol (&gEfiBootLogoProtocolGuid
, NULL
, (VOID
**) &BootLogo
);
1008 if (!EFI_ERROR (Status
) && (BootLogo
!= NULL
)) {
1009 BootLogo
->SetBootLogo (BootLogo
, NULL
, 0, 0, 0, 0);
1012 InitializeFrontPage ();
1018 if (mLanguageString
!= NULL
) {
1019 FreePool (mLanguageString
);
1020 mLanguageString
= NULL
;
1024 //Will leave browser, check any reset required change is applied? if yes, reset system
1026 SetupResetReminder ();
1030 // Following are BDS Lib functions which contain all the code about setup browser reset reminder feature.
1031 // Setup Browser reset reminder feature is that an reset reminder will be given before user leaves the setup browser if
1032 // user change any option setting which needs a reset to be effective, and the reset will be applied according to the user selection.
1037 Enable the setup browser reset reminder feature.
1038 This routine is used in platform tip. If the platform policy need the feature, use the routine to enable it.
1043 EnableResetReminderFeature (
1047 mFeaturerSwitch
= TRUE
;
1052 Disable the setup browser reset reminder feature.
1053 This routine is used in platform tip. If the platform policy do not want the feature, use the routine to disable it.
1058 DisableResetReminderFeature (
1062 mFeaturerSwitch
= FALSE
;
1067 Record the info that a reset is required.
1068 A module boolean variable is used to record whether a reset is required.
1073 EnableResetRequired (
1077 mResetRequired
= TRUE
;
1082 Record the info that no reset is required.
1083 A module boolean variable is used to record whether a reset is required.
1088 DisableResetRequired (
1092 mResetRequired
= FALSE
;
1097 Check whether platform policy enable the reset reminder feature. The default is enabled.
1102 IsResetReminderFeatureEnable (
1106 return mFeaturerSwitch
;
1111 Check if user changed any option setting which needs a system reset to be effective.
1120 return mResetRequired
;
1125 Check whether a reset is needed, and finish the reset reminder feature.
1126 If a reset is needed, Popup a menu to notice user, and finish the feature
1127 according to the user selection.
1132 SetupResetReminder (
1137 CHAR16
*StringBuffer1
;
1138 CHAR16
*StringBuffer2
;
1142 //check any reset required change is applied? if yes, reset system
1144 if (IsResetReminderFeatureEnable ()) {
1145 if (IsResetRequired ()) {
1147 StringBuffer1
= AllocateZeroPool (MAX_STRING_LEN
* sizeof (CHAR16
));
1148 ASSERT (StringBuffer1
!= NULL
);
1149 StringBuffer2
= AllocateZeroPool (MAX_STRING_LEN
* sizeof (CHAR16
));
1150 ASSERT (StringBuffer2
!= NULL
);
1151 StrCpyS (StringBuffer1
, MAX_STRING_LEN
, L
"Configuration changed. Reset to apply it Now.");
1152 StrCpyS (StringBuffer2
, MAX_STRING_LEN
, L
"Press ENTER to reset");
1154 // Popup a menu to notice user
1157 CreatePopUp (EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
, &Key
, StringBuffer1
, StringBuffer2
, NULL
);
1158 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1160 FreePool (StringBuffer1
);
1161 FreePool (StringBuffer2
);
1163 gRT
->ResetSystem (EfiResetCold
, EFI_SUCCESS
, 0, NULL
);