]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Application/UiApp/FrontPage.c
MdeModulePkg UiApp: Remove redundant functions
[mirror_edk2.git] / MdeModulePkg / Application / UiApp / FrontPage.c
1 /** @file
2 FrontPage routines to handle the callbacks and browser calls
3
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
10
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.
13
14 **/
15
16 #include "FrontPage.h"
17 #include "FrontPageCustomizedUi.h"
18
19 #define MAX_STRING_LEN 200
20
21 EFI_GUID mFrontPageGuid = FRONT_PAGE_FORMSET_GUID;
22
23 BOOLEAN mFeaturerSwitch = TRUE;
24 BOOLEAN mResetRequired = FALSE;
25
26 EFI_FORM_BROWSER2_PROTOCOL *gFormBrowser2;
27 CHAR8 *mLanguageString;
28 BOOLEAN mModeInitialized = FALSE;
29 //
30 // Boot video resolution and text mode.
31 //
32 UINT32 mBootHorizontalResolution = 0;
33 UINT32 mBootVerticalResolution = 0;
34 UINT32 mBootTextModeColumn = 0;
35 UINT32 mBootTextModeRow = 0;
36 //
37 // BIOS setup video resolution and text mode.
38 //
39 UINT32 mSetupTextModeColumn = 0;
40 UINT32 mSetupTextModeRow = 0;
41 UINT32 mSetupHorizontalResolution = 0;
42 UINT32 mSetupVerticalResolution = 0;
43
44 FRONT_PAGE_CALLBACK_DATA gFrontPagePrivate = {
45 FRONT_PAGE_CALLBACK_DATA_SIGNATURE,
46 NULL,
47 NULL,
48 NULL,
49 {
50 FakeExtractConfig,
51 FakeRouteConfig,
52 FrontPageCallback
53 }
54 };
55
56 HII_VENDOR_DEVICE_PATH mFrontPageHiiVendorDevicePath = {
57 {
58 {
59 HARDWARE_DEVICE_PATH,
60 HW_VENDOR_DP,
61 {
62 (UINT8) (sizeof (VENDOR_DEVICE_PATH)),
63 (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)
64 }
65 },
66 //
67 // {8E6D99EE-7531-48f8-8745-7F6144468FF2}
68 //
69 { 0x8e6d99ee, 0x7531, 0x48f8, { 0x87, 0x45, 0x7f, 0x61, 0x44, 0x46, 0x8f, 0xf2 } }
70 },
71 {
72 END_DEVICE_PATH_TYPE,
73 END_ENTIRE_DEVICE_PATH_SUBTYPE,
74 {
75 (UINT8) (END_DEVICE_PATH_LENGTH),
76 (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)
77 }
78 }
79 };
80
81 /**
82 Update the banner information for the Front Page based on Smbios information.
83
84 **/
85 VOID
86 UpdateFrontPageBannerStrings (
87 VOID
88 );
89
90 /**
91 This function allows a caller to extract the current configuration for one
92 or more named elements from the target driver.
93
94
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.
105
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.
110
111 **/
112 EFI_STATUS
113 EFIAPI
114 FakeExtractConfig (
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
119 )
120 {
121 if (Progress == NULL || Results == NULL) {
122 return EFI_INVALID_PARAMETER;
123 }
124 *Progress = Request;
125 return EFI_NOT_FOUND;
126 }
127
128 /**
129 This function processes the results of changes in configuration.
130
131
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.
138
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.
142
143 **/
144 EFI_STATUS
145 EFIAPI
146 FakeRouteConfig (
147 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
148 IN CONST EFI_STRING Configuration,
149 OUT EFI_STRING *Progress
150 )
151 {
152 if (Configuration == NULL || Progress == NULL) {
153 return EFI_INVALID_PARAMETER;
154 }
155
156 *Progress = Configuration;
157
158 return EFI_NOT_FOUND;
159 }
160
161 /**
162 This function processes the results of changes in configuration.
163
164
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.
172
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.
177
178 **/
179 EFI_STATUS
180 EFIAPI
181 FrontPageCallback (
182 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
183 IN EFI_BROWSER_ACTION Action,
184 IN EFI_QUESTION_ID QuestionId,
185 IN UINT8 Type,
186 IN EFI_IFR_TYPE_VALUE *Value,
187 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
188 )
189 {
190 return UiFrontPageCallbackHandler (gFrontPagePrivate.HiiHandle, Action, QuestionId, Type, Value, ActionRequest);
191 }
192
193 /**
194
195 Update the menus in the front page.
196
197 **/
198 VOID
199 UpdateFrontPageForm (
200 VOID
201 )
202 {
203 VOID *StartOpCodeHandle;
204 VOID *EndOpCodeHandle;
205 EFI_IFR_GUID_LABEL *StartGuidLabel;
206 EFI_IFR_GUID_LABEL *EndGuidLabel;
207
208 //
209 // Allocate space for creation of UpdateData Buffer
210 //
211 StartOpCodeHandle = HiiAllocateOpCodeHandle ();
212 ASSERT (StartOpCodeHandle != NULL);
213
214 EndOpCodeHandle = HiiAllocateOpCodeHandle ();
215 ASSERT (EndOpCodeHandle != NULL);
216 //
217 // Create Hii Extend Label OpCode as the start opcode
218 //
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;
222 //
223 // Create Hii Extend Label OpCode as the end opcode
224 //
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;
228
229 //
230 //Updata Front Page form
231 //
232 UiCustomizeFrontPage (
233 gFrontPagePrivate.HiiHandle,
234 StartOpCodeHandle
235 );
236
237 HiiUpdateForm (
238 gFrontPagePrivate.HiiHandle,
239 &mFrontPageGuid,
240 FRONT_PAGE_FORM_ID,
241 StartOpCodeHandle,
242 EndOpCodeHandle
243 );
244
245 HiiFreeOpCodeHandle (StartOpCodeHandle);
246 HiiFreeOpCodeHandle (EndOpCodeHandle);
247 }
248
249 /**
250 Initialize HII information for the FrontPage
251
252
253 @retval EFI_SUCCESS The operation is successful.
254 @retval EFI_DEVICE_ERROR If the dynamic opcode creation failed.
255
256 **/
257 EFI_STATUS
258 InitializeFrontPage (
259 VOID
260 )
261 {
262 EFI_STATUS Status;
263 //
264 // Locate Hii relative protocols
265 //
266 Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **) &gFormBrowser2);
267 if (EFI_ERROR (Status)) {
268 return Status;
269 }
270
271 //
272 // Install Device Path Protocol and Config Access protocol to driver handle
273 //
274 gFrontPagePrivate.DriverHandle = NULL;
275 Status = gBS->InstallMultipleProtocolInterfaces (
276 &gFrontPagePrivate.DriverHandle,
277 &gEfiDevicePathProtocolGuid,
278 &mFrontPageHiiVendorDevicePath,
279 &gEfiHiiConfigAccessProtocolGuid,
280 &gFrontPagePrivate.ConfigAccess,
281 NULL
282 );
283 ASSERT_EFI_ERROR (Status);
284
285 //
286 // Publish our HII data
287 //
288 gFrontPagePrivate.HiiHandle = HiiAddPackages (
289 &mFrontPageGuid,
290 gFrontPagePrivate.DriverHandle,
291 FrontPageVfrBin,
292 UiAppStrings,
293 NULL
294 );
295 ASSERT (gFrontPagePrivate.HiiHandle != NULL);
296
297 //
298 //Updata Front Page banner strings
299 //
300 UpdateFrontPageBannerStrings ();
301
302 //
303 // Update front page menus.
304 //
305 UpdateFrontPageForm();
306
307 return Status;
308 }
309
310 /**
311 Call the browser and display the front page
312
313 @return Status code that will be returned by
314 EFI_FORM_BROWSER2_PROTOCOL.SendForm ().
315
316 **/
317 EFI_STATUS
318 CallFrontPage (
319 VOID
320 )
321 {
322 EFI_STATUS Status;
323 EFI_BROWSER_ACTION_REQUEST ActionRequest;
324
325 //
326 // Begin waiting for USER INPUT
327 //
328 REPORT_STATUS_CODE (
329 EFI_PROGRESS_CODE,
330 (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_PC_INPUT_WAIT)
331 );
332
333 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
334 Status = gFormBrowser2->SendForm (
335 gFormBrowser2,
336 &gFrontPagePrivate.HiiHandle,
337 1,
338 &mFrontPageGuid,
339 0,
340 NULL,
341 &ActionRequest
342 );
343 //
344 // Check whether user change any option setting which needs a reset to be effective
345 //
346 if (ActionRequest == EFI_BROWSER_ACTION_REQUEST_RESET) {
347 EnableResetRequired ();
348 }
349
350 return Status;
351 }
352
353 /**
354 Remove the installed packages from the HiiDatabase.
355
356 **/
357 VOID
358 FreeFrontPage(
359 VOID
360 )
361 {
362 EFI_STATUS Status;
363 Status = gBS->UninstallMultipleProtocolInterfaces (
364 gFrontPagePrivate.DriverHandle,
365 &gEfiDevicePathProtocolGuid,
366 &mFrontPageHiiVendorDevicePath,
367 &gEfiHiiConfigAccessProtocolGuid,
368 &gFrontPagePrivate.ConfigAccess,
369 NULL
370 );
371 ASSERT_EFI_ERROR (Status);
372
373 //
374 // Publish our HII data
375 //
376 HiiRemovePackages (gFrontPagePrivate.HiiHandle);
377 if (gFrontPagePrivate.LanguageToken != NULL) {
378 FreePool (gFrontPagePrivate.LanguageToken);
379 gFrontPagePrivate.LanguageToken = NULL;
380 }
381 }
382
383 /**
384 Convert Processor Frequency Data to a string.
385
386 @param ProcessorFrequency The frequency data to process
387 @param Base10Exponent The exponent based on 10
388 @param String The string that is created
389
390 **/
391 VOID
392 ConvertProcessorToString (
393 IN UINT16 ProcessorFrequency,
394 IN UINT16 Base10Exponent,
395 OUT CHAR16 **String
396 )
397 {
398 CHAR16 *StringBuffer;
399 UINTN Index;
400 UINTN DestMax;
401 UINT32 FreqMhz;
402
403 if (Base10Exponent >= 6) {
404 FreqMhz = ProcessorFrequency;
405 for (Index = 0; Index < (UINT32) Base10Exponent - 6; Index++) {
406 FreqMhz *= 10;
407 }
408 } else {
409 FreqMhz = 0;
410 }
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)),
420 PREFIX_ZERO,
421 (FreqMhz % 1000) / 10,
422 2
423 );
424 StrCatS (StringBuffer, DestMax, L" GHz");
425 *String = (CHAR16 *) StringBuffer;
426 return ;
427 }
428
429
430 /**
431 Convert Memory Size to a string.
432
433 @param MemorySize The size of the memory to process
434 @param String The string that is created
435
436 **/
437 VOID
438 ConvertMemorySizeToString (
439 IN UINT32 MemorySize,
440 OUT CHAR16 **String
441 )
442 {
443 CHAR16 *StringBuffer;
444
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");
449
450 *String = (CHAR16 *) StringBuffer;
451
452 return ;
453 }
454
455 /**
456
457 Acquire the string associated with the Index from smbios structure and return it.
458 The caller is responsible for free the string buffer.
459
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
463
464 @retval EFI_SUCCESS The function returns EFI_SUCCESS always.
465
466 **/
467 EFI_STATUS
468 GetOptionalStringByIndex (
469 IN CHAR8 *OptionalStrStart,
470 IN UINT8 Index,
471 OUT CHAR16 **String
472 )
473 {
474 UINTN StrSize;
475
476 if (Index == 0) {
477 *String = AllocateZeroPool (sizeof (CHAR16));
478 return EFI_SUCCESS;
479 }
480
481 StrSize = 0;
482 do {
483 Index--;
484 OptionalStrStart += StrSize;
485 StrSize = AsciiStrSize (OptionalStrStart);
486 } while (OptionalStrStart[StrSize] != 0 && Index != 0);
487
488 if ((Index != 0) || (StrSize == 1)) {
489 //
490 // Meet the end of strings set but Index is non-zero, or
491 // Find an empty string
492 //
493 *String = GetStringById (STRING_TOKEN (STR_MISSING_STRING));
494 } else {
495 *String = AllocatePool (StrSize * sizeof (CHAR16));
496 AsciiStrToUnicodeStrS (OptionalStrStart, *String, StrSize);
497 }
498
499 return EFI_SUCCESS;
500 }
501
502
503 /**
504
505 Update the banner information for the Front Page based on Smbios information.
506
507 **/
508 VOID
509 UpdateFrontPageBannerStrings (
510 VOID
511 )
512 {
513 UINT8 StrIndex;
514 CHAR16 *NewString;
515 CHAR16 *FirmwareVersionString;
516 EFI_STATUS Status;
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;
525 BOOLEAN FoundCpu;
526
527 InstalledMemory = 0;
528 FoundCpu = 0;
529
530 //
531 // Update default banner string.
532 //
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);
537
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);
542
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);
547
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);
552
553 //
554 // Update Front Page banner strings base on SmBios Table.
555 //
556 Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **) &Smbios);
557 if (EFI_ERROR (Status)) {
558 //
559 // Smbios protocol not found, get the default value.
560 //
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);
565
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);
570
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);
575
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);
580
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);
585
586 return;
587 }
588
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);
596
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);
603 } else {
604 UiCustomizeFrontPageBanner (3, TRUE, &NewString);
605 HiiSetString (gFrontPagePrivate.HiiHandle, STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION), NewString, NULL);
606 FreePool (NewString);
607 }
608 }
609
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);
617 }
618
619 if ((Record->Type == SMBIOS_TYPE_PROCESSOR_INFORMATION) && !FoundCpu) {
620 Type4Record = (SMBIOS_TABLE_TYPE4 *) Record;
621 //
622 // The information in the record should be only valid when the CPU Socket is populated.
623 //
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);
630
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);
635
636 FoundCpu = TRUE;
637 }
638 }
639
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);
645 } else {
646 InstalledMemory += RShiftU64(Type19Record->ExtendedEndingAddress -
647 Type19Record->ExtendedStartingAddress + 1, 20);
648 }
649 }
650
651 Status = Smbios->GetNext (Smbios, &SmbiosHandle, NULL, &Record, NULL);
652 }
653
654 //
655 // Now update the total installed RAM size
656 //
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);
661 }
662
663 /**
664 This function will change video resolution and text mode
665 according to defined setup mode or defined boot mode
666
667 @param IsSetupMode Indicate mode is changed to setup mode or boot mode.
668
669 @retval EFI_SUCCESS Mode is changed successfully.
670 @retval Others Mode failed to be changed.
671
672 **/
673 EFI_STATUS
674 UiSetConsoleMode (
675 BOOLEAN IsSetupMode
676 )
677 {
678 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
679 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut;
680 UINTN SizeOfInfo;
681 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
682 UINT32 MaxGopMode;
683 UINT32 MaxTextMode;
684 UINT32 ModeNumber;
685 UINT32 NewHorizontalResolution;
686 UINT32 NewVerticalResolution;
687 UINT32 NewColumns;
688 UINT32 NewRows;
689 UINTN HandleCount;
690 EFI_HANDLE *HandleBuffer;
691 EFI_STATUS Status;
692 UINTN Index;
693 UINTN CurrentColumn;
694 UINTN CurrentRow;
695
696 MaxGopMode = 0;
697 MaxTextMode = 0;
698
699 //
700 // Get current video resolution and text mode
701 //
702 Status = gBS->HandleProtocol (
703 gST->ConsoleOutHandle,
704 &gEfiGraphicsOutputProtocolGuid,
705 (VOID**)&GraphicsOutput
706 );
707 if (EFI_ERROR (Status)) {
708 GraphicsOutput = NULL;
709 }
710
711 Status = gBS->HandleProtocol (
712 gST->ConsoleOutHandle,
713 &gEfiSimpleTextOutProtocolGuid,
714 (VOID**)&SimpleTextOut
715 );
716 if (EFI_ERROR (Status)) {
717 SimpleTextOut = NULL;
718 }
719
720 if ((GraphicsOutput == NULL) || (SimpleTextOut == NULL)) {
721 return EFI_UNSUPPORTED;
722 }
723
724 if (IsSetupMode) {
725 //
726 // The required resolution and text mode is setup mode.
727 //
728 NewHorizontalResolution = mSetupHorizontalResolution;
729 NewVerticalResolution = mSetupVerticalResolution;
730 NewColumns = mSetupTextModeColumn;
731 NewRows = mSetupTextModeRow;
732 } else {
733 //
734 // The required resolution and text mode is boot mode.
735 //
736 NewHorizontalResolution = mBootHorizontalResolution;
737 NewVerticalResolution = mBootVerticalResolution;
738 NewColumns = mBootTextModeColumn;
739 NewRows = mBootTextModeRow;
740 }
741
742 if (GraphicsOutput != NULL) {
743 MaxGopMode = GraphicsOutput->Mode->MaxMode;
744 }
745
746 if (SimpleTextOut != NULL) {
747 MaxTextMode = SimpleTextOut->Mode->MaxMode;
748 }
749
750 //
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.
756 //
757 for (ModeNumber = 0; ModeNumber < MaxGopMode; ModeNumber++) {
758 Status = GraphicsOutput->QueryMode (
759 GraphicsOutput,
760 ModeNumber,
761 &SizeOfInfo,
762 &Info
763 );
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)) {
769 //
770 // Current resolution is same with required resolution, check if text mode need be set
771 //
772 Status = SimpleTextOut->QueryMode (SimpleTextOut, SimpleTextOut->Mode->Mode, &CurrentColumn, &CurrentRow);
773 ASSERT_EFI_ERROR (Status);
774 if (CurrentColumn == NewColumns && CurrentRow == NewRows) {
775 //
776 // If current text mode is same with required text mode. Do nothing
777 //
778 FreePool (Info);
779 return EFI_SUCCESS;
780 } else {
781 //
782 // If current text mode is different from required text mode. Set new video mode
783 //
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)) {
788 //
789 // Required text mode is supported, set it.
790 //
791 Status = SimpleTextOut->SetMode (SimpleTextOut, Index);
792 ASSERT_EFI_ERROR (Status);
793 //
794 // Update text mode PCD.
795 //
796 Status = PcdSet32S (PcdConOutColumn, mSetupTextModeColumn);
797 ASSERT_EFI_ERROR (Status);
798 Status = PcdSet32S (PcdConOutRow, mSetupTextModeRow);
799 ASSERT_EFI_ERROR (Status);
800 FreePool (Info);
801 return EFI_SUCCESS;
802 }
803 }
804 }
805 if (Index == MaxTextMode) {
806 //
807 // If required text mode is not supported, return error.
808 //
809 FreePool (Info);
810 return EFI_UNSUPPORTED;
811 }
812 }
813 } else {
814 //
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.
817 //
818 Status = GraphicsOutput->SetMode (GraphicsOutput, ModeNumber);
819 if (!EFI_ERROR (Status)) {
820 FreePool (Info);
821 break;
822 }
823 }
824 }
825 FreePool (Info);
826 }
827 }
828
829 if (ModeNumber == MaxGopMode) {
830 //
831 // If the resolution is not supported, return error.
832 //
833 return EFI_UNSUPPORTED;
834 }
835
836 //
837 // Set PCD to Inform GraphicsConsole to change video resolution.
838 // Set PCD to Inform Consplitter to change text mode.
839 //
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);
848
849 //
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.
853 //
854 Status = gBS->LocateHandleBuffer (
855 ByProtocol,
856 &gEfiSimpleTextOutProtocolGuid,
857 NULL,
858 &HandleCount,
859 &HandleBuffer
860 );
861 if (!EFI_ERROR (Status)) {
862 for (Index = 0; Index < HandleCount; Index++) {
863 gBS->DisconnectController (HandleBuffer[Index], NULL, NULL);
864 }
865 for (Index = 0; Index < HandleCount; Index++) {
866 gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE);
867 }
868 if (HandleBuffer != NULL) {
869 FreePool (HandleBuffer);
870 }
871 }
872
873 return EFI_SUCCESS;
874 }
875
876 /**
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
879 function.
880
881 @param[in] ImageHandle The firmware allocated handle for the EFI image.
882 @param[in] SystemTable A pointer to the EFI System Table.
883
884 @retval EFI_SUCCESS The entry point is executed successfully.
885 @retval other Some error occurs when executing this entry point.
886
887 **/
888 EFI_STATUS
889 EFIAPI
890 InitializeUserInterface (
891 IN EFI_HANDLE ImageHandle,
892 IN EFI_SYSTEM_TABLE *SystemTable
893 )
894 {
895 EFI_HII_HANDLE HiiHandle;
896 EFI_STATUS Status;
897 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
898 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut;
899 UINTN BootTextColumn;
900 UINTN BootTextRow;
901
902 if (!mModeInitialized) {
903 //
904 // After the console is ready, get current video resolution
905 // and text mode before launching setup at first time.
906 //
907 Status = gBS->HandleProtocol (
908 gST->ConsoleOutHandle,
909 &gEfiGraphicsOutputProtocolGuid,
910 (VOID**)&GraphicsOutput
911 );
912 if (EFI_ERROR (Status)) {
913 GraphicsOutput = NULL;
914 }
915
916 Status = gBS->HandleProtocol (
917 gST->ConsoleOutHandle,
918 &gEfiSimpleTextOutProtocolGuid,
919 (VOID**)&SimpleTextOut
920 );
921 if (EFI_ERROR (Status)) {
922 SimpleTextOut = NULL;
923 }
924
925 if (GraphicsOutput != NULL) {
926 //
927 // Get current video resolution and text mode.
928 //
929 mBootHorizontalResolution = GraphicsOutput->Mode->Info->HorizontalResolution;
930 mBootVerticalResolution = GraphicsOutput->Mode->Info->VerticalResolution;
931 }
932
933 if (SimpleTextOut != NULL) {
934 Status = SimpleTextOut->QueryMode (
935 SimpleTextOut,
936 SimpleTextOut->Mode->Mode,
937 &BootTextColumn,
938 &BootTextRow
939 );
940 mBootTextModeColumn = (UINT32)BootTextColumn;
941 mBootTextModeRow = (UINT32)BootTextRow;
942 }
943
944 //
945 // Get user defined text mode for setup.
946 //
947 mSetupHorizontalResolution = PcdGet32 (PcdSetupVideoHorizontalResolution);
948 mSetupVerticalResolution = PcdGet32 (PcdSetupVideoVerticalResolution);
949 mSetupTextModeColumn = PcdGet32 (PcdSetupConOutColumn);
950 mSetupTextModeRow = PcdGet32 (PcdSetupConOutRow);
951
952 mModeInitialized = TRUE;
953 }
954
955 gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL);
956 gST->ConOut->ClearScreen (gST->ConOut);
957
958 //
959 // Install customized fonts needed by Front Page
960 //
961 HiiHandle = ExportFonts ();
962 ASSERT (HiiHandle != NULL);
963
964 InitializeStringSupport ();
965
966 UiSetConsoleMode (TRUE);
967 UiEntry (FALSE);
968 UiSetConsoleMode (FALSE);
969
970 UninitializeStringSupport ();
971 HiiRemovePackages (HiiHandle);
972
973 return EFI_SUCCESS;
974 }
975
976 /**
977 This function is the main entry of the UI entry.
978 The function will present the main menu of the system UI.
979
980 @param ConnectAllHappened Caller passes the value to UI to avoid unnecessary connect-all.
981
982 **/
983 VOID
984 EFIAPI
985 UiEntry (
986 IN BOOLEAN ConnectAllHappened
987 )
988 {
989 EFI_STATUS Status;
990 EFI_BOOT_LOGO_PROTOCOL *BootLogo;
991
992 //
993 // Enter Setup page.
994 //
995 REPORT_STATUS_CODE (
996 EFI_PROGRESS_CODE,
997 (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_PC_USER_SETUP)
998 );
999
1000 //
1001 // Indicate if the connect all has been performed before.
1002 // If has not been performed before, do here.
1003 //
1004 if (!ConnectAllHappened) {
1005 EfiBootManagerConnectAll ();
1006 }
1007
1008 //
1009 // The boot option enumeration time is acceptable in Ui driver
1010 //
1011 EfiBootManagerRefreshAllBootOption ();
1012
1013 //
1014 // Boot Logo is corrupted, report it using Boot Logo protocol.
1015 //
1016 Status = gBS->LocateProtocol (&gEfiBootLogoProtocolGuid, NULL, (VOID **) &BootLogo);
1017 if (!EFI_ERROR (Status) && (BootLogo != NULL)) {
1018 BootLogo->SetBootLogo (BootLogo, NULL, 0, 0, 0, 0);
1019 }
1020
1021 InitializeFrontPage ();
1022
1023 CallFrontPage ();
1024
1025 FreeFrontPage ();
1026
1027 if (mLanguageString != NULL) {
1028 FreePool (mLanguageString);
1029 mLanguageString = NULL;
1030 }
1031
1032 //
1033 //Will leave browser, check any reset required change is applied? if yes, reset system
1034 //
1035 SetupResetReminder ();
1036 }
1037
1038 //
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.
1042 //
1043
1044
1045
1046
1047
1048 /**
1049 Record the info that a reset is required.
1050 A module boolean variable is used to record whether a reset is required.
1051
1052 **/
1053 VOID
1054 EFIAPI
1055 EnableResetRequired (
1056 VOID
1057 )
1058 {
1059 mResetRequired = TRUE;
1060 }
1061
1062
1063
1064
1065 /**
1066 Check whether platform policy enable the reset reminder feature. The default is enabled.
1067
1068 **/
1069 BOOLEAN
1070 EFIAPI
1071 IsResetReminderFeatureEnable (
1072 VOID
1073 )
1074 {
1075 return mFeaturerSwitch;
1076 }
1077
1078
1079 /**
1080 Check if user changed any option setting which needs a system reset to be effective.
1081
1082 **/
1083 BOOLEAN
1084 EFIAPI
1085 IsResetRequired (
1086 VOID
1087 )
1088 {
1089 return mResetRequired;
1090 }
1091
1092
1093 /**
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.
1097
1098 **/
1099 VOID
1100 EFIAPI
1101 SetupResetReminder (
1102 VOID
1103 )
1104 {
1105 EFI_INPUT_KEY Key;
1106 CHAR16 *StringBuffer1;
1107 CHAR16 *StringBuffer2;
1108
1109
1110 //
1111 //check any reset required change is applied? if yes, reset system
1112 //
1113 if (IsResetReminderFeatureEnable ()) {
1114 if (IsResetRequired ()) {
1115
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");
1122 //
1123 // Popup a menu to notice user
1124 //
1125 do {
1126 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, StringBuffer1, StringBuffer2, NULL);
1127 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
1128
1129 FreePool (StringBuffer1);
1130 FreePool (StringBuffer2);
1131
1132 gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);
1133 }
1134 }
1135 }
1136