]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Application/UiApp/FrontPage.c
EmulatorPkg: don't display the cpu current speed
[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 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include "FrontPage.h"
11 #include "FrontPageCustomizedUi.h"
12
13 #define MAX_STRING_LEN 200
14
15 EFI_GUID mFrontPageGuid = FRONT_PAGE_FORMSET_GUID;
16
17 BOOLEAN mResetRequired = FALSE;
18
19 EFI_FORM_BROWSER2_PROTOCOL *gFormBrowser2;
20 CHAR8 *mLanguageString;
21 BOOLEAN mModeInitialized = FALSE;
22 //
23 // Boot video resolution and text mode.
24 //
25 UINT32 mBootHorizontalResolution = 0;
26 UINT32 mBootVerticalResolution = 0;
27 UINT32 mBootTextModeColumn = 0;
28 UINT32 mBootTextModeRow = 0;
29 //
30 // BIOS setup video resolution and text mode.
31 //
32 UINT32 mSetupTextModeColumn = 0;
33 UINT32 mSetupTextModeRow = 0;
34 UINT32 mSetupHorizontalResolution = 0;
35 UINT32 mSetupVerticalResolution = 0;
36
37 FRONT_PAGE_CALLBACK_DATA gFrontPagePrivate = {
38 FRONT_PAGE_CALLBACK_DATA_SIGNATURE,
39 NULL,
40 NULL,
41 NULL,
42 {
43 FakeExtractConfig,
44 FakeRouteConfig,
45 FrontPageCallback
46 }
47 };
48
49 HII_VENDOR_DEVICE_PATH mFrontPageHiiVendorDevicePath = {
50 {
51 {
52 HARDWARE_DEVICE_PATH,
53 HW_VENDOR_DP,
54 {
55 (UINT8) (sizeof (VENDOR_DEVICE_PATH)),
56 (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)
57 }
58 },
59 //
60 // {8E6D99EE-7531-48f8-8745-7F6144468FF2}
61 //
62 { 0x8e6d99ee, 0x7531, 0x48f8, { 0x87, 0x45, 0x7f, 0x61, 0x44, 0x46, 0x8f, 0xf2 } }
63 },
64 {
65 END_DEVICE_PATH_TYPE,
66 END_ENTIRE_DEVICE_PATH_SUBTYPE,
67 {
68 (UINT8) (END_DEVICE_PATH_LENGTH),
69 (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)
70 }
71 }
72 };
73
74 /**
75 Update the banner information for the Front Page based on Smbios information.
76
77 **/
78 VOID
79 UpdateFrontPageBannerStrings (
80 VOID
81 );
82
83 /**
84 This function allows a caller to extract the current configuration for one
85 or more named elements from the target driver.
86
87
88 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
89 @param Request A null-terminated Unicode string in <ConfigRequest> format.
90 @param Progress On return, points to a character in the Request string.
91 Points to the string's null terminator if request was successful.
92 Points to the most recent '&' before the first failing name/value
93 pair (or the beginning of the string if the failure is in the
94 first name/value pair) if the request was not successful.
95 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
96 has all values filled in for the names in the Request string.
97 String to be allocated by the called function.
98
99 @retval EFI_SUCCESS The Results is filled with the requested values.
100 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
101 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
102 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
103
104 **/
105 EFI_STATUS
106 EFIAPI
107 FakeExtractConfig (
108 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
109 IN CONST EFI_STRING Request,
110 OUT EFI_STRING *Progress,
111 OUT EFI_STRING *Results
112 )
113 {
114 if (Progress == NULL || Results == NULL) {
115 return EFI_INVALID_PARAMETER;
116 }
117 *Progress = Request;
118 return EFI_NOT_FOUND;
119 }
120
121 /**
122 This function processes the results of changes in configuration.
123
124
125 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
126 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
127 @param Progress A pointer to a string filled in with the offset of the most
128 recent '&' before the first failing name/value pair (or the
129 beginning of the string if the failure is in the first
130 name/value pair) or the terminating NULL if all was successful.
131
132 @retval EFI_SUCCESS The Results is processed successfully.
133 @retval EFI_INVALID_PARAMETER Configuration is NULL.
134 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
135
136 **/
137 EFI_STATUS
138 EFIAPI
139 FakeRouteConfig (
140 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
141 IN CONST EFI_STRING Configuration,
142 OUT EFI_STRING *Progress
143 )
144 {
145 if (Configuration == NULL || Progress == NULL) {
146 return EFI_INVALID_PARAMETER;
147 }
148
149 *Progress = Configuration;
150
151 return EFI_NOT_FOUND;
152 }
153
154 /**
155 This function processes the results of changes in configuration.
156
157
158 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
159 @param Action Specifies the type of action taken by the browser.
160 @param QuestionId A unique value which is sent to the original exporting driver
161 so that it can identify the type of data to expect.
162 @param Type The type of value for the question.
163 @param Value A pointer to the data being sent to the original exporting driver.
164 @param ActionRequest On return, points to the action requested by the callback function.
165
166 @retval EFI_SUCCESS The callback successfully handled the action.
167 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
168 @retval EFI_DEVICE_ERROR The variable could not be saved.
169 @retval EFI_UNSUPPORTED The specified Action is not supported by the callback.
170
171 **/
172 EFI_STATUS
173 EFIAPI
174 FrontPageCallback (
175 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
176 IN EFI_BROWSER_ACTION Action,
177 IN EFI_QUESTION_ID QuestionId,
178 IN UINT8 Type,
179 IN EFI_IFR_TYPE_VALUE *Value,
180 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
181 )
182 {
183 return UiFrontPageCallbackHandler (gFrontPagePrivate.HiiHandle, Action, QuestionId, Type, Value, ActionRequest);
184 }
185
186 /**
187
188 Update the menus in the front page.
189
190 **/
191 VOID
192 UpdateFrontPageForm (
193 VOID
194 )
195 {
196 VOID *StartOpCodeHandle;
197 VOID *EndOpCodeHandle;
198 EFI_IFR_GUID_LABEL *StartGuidLabel;
199 EFI_IFR_GUID_LABEL *EndGuidLabel;
200
201 //
202 // Allocate space for creation of UpdateData Buffer
203 //
204 StartOpCodeHandle = HiiAllocateOpCodeHandle ();
205 ASSERT (StartOpCodeHandle != NULL);
206
207 EndOpCodeHandle = HiiAllocateOpCodeHandle ();
208 ASSERT (EndOpCodeHandle != NULL);
209 //
210 // Create Hii Extend Label OpCode as the start opcode
211 //
212 StartGuidLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
213 StartGuidLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
214 StartGuidLabel->Number = LABEL_FRANTPAGE_INFORMATION;
215 //
216 // Create Hii Extend Label OpCode as the end opcode
217 //
218 EndGuidLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
219 EndGuidLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
220 EndGuidLabel->Number = LABEL_END;
221
222 //
223 //Updata Front Page form
224 //
225 UiCustomizeFrontPage (
226 gFrontPagePrivate.HiiHandle,
227 StartOpCodeHandle
228 );
229
230 HiiUpdateForm (
231 gFrontPagePrivate.HiiHandle,
232 &mFrontPageGuid,
233 FRONT_PAGE_FORM_ID,
234 StartOpCodeHandle,
235 EndOpCodeHandle
236 );
237
238 HiiFreeOpCodeHandle (StartOpCodeHandle);
239 HiiFreeOpCodeHandle (EndOpCodeHandle);
240 }
241
242 /**
243 Initialize HII information for the FrontPage
244
245
246 @retval EFI_SUCCESS The operation is successful.
247 @retval EFI_DEVICE_ERROR If the dynamic opcode creation failed.
248
249 **/
250 EFI_STATUS
251 InitializeFrontPage (
252 VOID
253 )
254 {
255 EFI_STATUS Status;
256 //
257 // Locate Hii relative protocols
258 //
259 Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **) &gFormBrowser2);
260 if (EFI_ERROR (Status)) {
261 return Status;
262 }
263
264 //
265 // Install Device Path Protocol and Config Access protocol to driver handle
266 //
267 gFrontPagePrivate.DriverHandle = NULL;
268 Status = gBS->InstallMultipleProtocolInterfaces (
269 &gFrontPagePrivate.DriverHandle,
270 &gEfiDevicePathProtocolGuid,
271 &mFrontPageHiiVendorDevicePath,
272 &gEfiHiiConfigAccessProtocolGuid,
273 &gFrontPagePrivate.ConfigAccess,
274 NULL
275 );
276 ASSERT_EFI_ERROR (Status);
277
278 //
279 // Publish our HII data
280 //
281 gFrontPagePrivate.HiiHandle = HiiAddPackages (
282 &mFrontPageGuid,
283 gFrontPagePrivate.DriverHandle,
284 FrontPageVfrBin,
285 UiAppStrings,
286 NULL
287 );
288 ASSERT (gFrontPagePrivate.HiiHandle != NULL);
289
290 //
291 //Updata Front Page banner strings
292 //
293 UpdateFrontPageBannerStrings ();
294
295 //
296 // Update front page menus.
297 //
298 UpdateFrontPageForm();
299
300 return Status;
301 }
302
303 /**
304 Call the browser and display the front page
305
306 @return Status code that will be returned by
307 EFI_FORM_BROWSER2_PROTOCOL.SendForm ().
308
309 **/
310 EFI_STATUS
311 CallFrontPage (
312 VOID
313 )
314 {
315 EFI_STATUS Status;
316 EFI_BROWSER_ACTION_REQUEST ActionRequest;
317
318 //
319 // Begin waiting for USER INPUT
320 //
321 REPORT_STATUS_CODE (
322 EFI_PROGRESS_CODE,
323 (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_PC_INPUT_WAIT)
324 );
325
326 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
327 Status = gFormBrowser2->SendForm (
328 gFormBrowser2,
329 &gFrontPagePrivate.HiiHandle,
330 1,
331 &mFrontPageGuid,
332 0,
333 NULL,
334 &ActionRequest
335 );
336 //
337 // Check whether user change any option setting which needs a reset to be effective
338 //
339 if (ActionRequest == EFI_BROWSER_ACTION_REQUEST_RESET) {
340 EnableResetRequired ();
341 }
342
343 return Status;
344 }
345
346 /**
347 Remove the installed packages from the HiiDatabase.
348
349 **/
350 VOID
351 FreeFrontPage(
352 VOID
353 )
354 {
355 EFI_STATUS Status;
356 Status = gBS->UninstallMultipleProtocolInterfaces (
357 gFrontPagePrivate.DriverHandle,
358 &gEfiDevicePathProtocolGuid,
359 &mFrontPageHiiVendorDevicePath,
360 &gEfiHiiConfigAccessProtocolGuid,
361 &gFrontPagePrivate.ConfigAccess,
362 NULL
363 );
364 ASSERT_EFI_ERROR (Status);
365
366 //
367 // Publish our HII data
368 //
369 HiiRemovePackages (gFrontPagePrivate.HiiHandle);
370 if (gFrontPagePrivate.LanguageToken != NULL) {
371 FreePool (gFrontPagePrivate.LanguageToken);
372 gFrontPagePrivate.LanguageToken = NULL;
373 }
374 }
375
376 /**
377 Convert Processor Frequency Data to a string.
378
379 @param ProcessorFrequency The frequency data to process
380 @param Base10Exponent The exponent based on 10
381 @param String The string that is created
382
383 **/
384 VOID
385 ConvertProcessorToString (
386 IN UINT16 ProcessorFrequency,
387 IN UINT16 Base10Exponent,
388 OUT CHAR16 **String
389 )
390 {
391 CHAR16 *StringBuffer;
392 UINTN Index;
393 UINTN DestMax;
394 UINT32 FreqMhz;
395
396 if (Base10Exponent >= 6) {
397 FreqMhz = ProcessorFrequency;
398 for (Index = 0; Index < (UINT32) Base10Exponent - 6; Index++) {
399 FreqMhz *= 10;
400 }
401 } else {
402 FreqMhz = 0;
403 }
404 DestMax = 0x20 / sizeof (CHAR16);
405 StringBuffer = AllocateZeroPool (0x20);
406 ASSERT (StringBuffer != NULL);
407 UnicodeValueToStringS (StringBuffer, sizeof (CHAR16) * DestMax, LEFT_JUSTIFY, FreqMhz / 1000, 3);
408 Index = StrnLenS (StringBuffer, DestMax);
409 StrCatS (StringBuffer, DestMax, L".");
410 UnicodeValueToStringS (
411 StringBuffer + Index + 1,
412 sizeof (CHAR16) * (DestMax - (Index + 1)),
413 PREFIX_ZERO,
414 (FreqMhz % 1000) / 10,
415 2
416 );
417 StrCatS (StringBuffer, DestMax, L" GHz");
418 *String = (CHAR16 *) StringBuffer;
419 return ;
420 }
421
422
423 /**
424 Convert Memory Size to a string.
425
426 @param MemorySize The size of the memory to process
427 @param String The string that is created
428
429 **/
430 VOID
431 ConvertMemorySizeToString (
432 IN UINT32 MemorySize,
433 OUT CHAR16 **String
434 )
435 {
436 CHAR16 *StringBuffer;
437
438 StringBuffer = AllocateZeroPool (0x24);
439 ASSERT (StringBuffer != NULL);
440 UnicodeValueToStringS (StringBuffer, 0x24, LEFT_JUSTIFY, MemorySize, 10);
441 StrCatS (StringBuffer, 0x24 / sizeof (CHAR16), L" MB RAM");
442
443 *String = (CHAR16 *) StringBuffer;
444
445 return ;
446 }
447
448 /**
449
450 Acquire the string associated with the Index from smbios structure and return it.
451 The caller is responsible for free the string buffer.
452
453 @param OptionalStrStart The start position to search the string
454 @param Index The index of the string to extract
455 @param String The string that is extracted
456
457 @retval EFI_SUCCESS The function returns EFI_SUCCESS always.
458
459 **/
460 EFI_STATUS
461 GetOptionalStringByIndex (
462 IN CHAR8 *OptionalStrStart,
463 IN UINT8 Index,
464 OUT CHAR16 **String
465 )
466 {
467 UINTN StrSize;
468
469 if (Index == 0) {
470 *String = AllocateZeroPool (sizeof (CHAR16));
471 return EFI_SUCCESS;
472 }
473
474 StrSize = 0;
475 do {
476 Index--;
477 OptionalStrStart += StrSize;
478 StrSize = AsciiStrSize (OptionalStrStart);
479 } while (OptionalStrStart[StrSize] != 0 && Index != 0);
480
481 if ((Index != 0) || (StrSize == 1)) {
482 //
483 // Meet the end of strings set but Index is non-zero, or
484 // Find an empty string
485 //
486 *String = GetStringById (STRING_TOKEN (STR_MISSING_STRING));
487 } else {
488 *String = AllocatePool (StrSize * sizeof (CHAR16));
489 AsciiStrToUnicodeStrS (OptionalStrStart, *String, StrSize);
490 }
491
492 return EFI_SUCCESS;
493 }
494
495
496 /**
497
498 Update the banner information for the Front Page based on Smbios information.
499
500 **/
501 VOID
502 UpdateFrontPageBannerStrings (
503 VOID
504 )
505 {
506 UINT8 StrIndex;
507 CHAR16 *NewString;
508 CHAR16 *FirmwareVersionString;
509 EFI_STATUS Status;
510 EFI_SMBIOS_HANDLE SmbiosHandle;
511 EFI_SMBIOS_PROTOCOL *Smbios;
512 SMBIOS_TABLE_TYPE0 *Type0Record;
513 SMBIOS_TABLE_TYPE1 *Type1Record;
514 SMBIOS_TABLE_TYPE4 *Type4Record;
515 SMBIOS_TABLE_TYPE19 *Type19Record;
516 EFI_SMBIOS_TABLE_HEADER *Record;
517 UINT64 InstalledMemory;
518 BOOLEAN FoundCpu;
519
520 InstalledMemory = 0;
521 FoundCpu = 0;
522
523 //
524 // Update default banner string.
525 //
526 NewString = HiiGetString (gFrontPagePrivate.HiiHandle, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE4_LEFT), NULL);
527 UiCustomizeFrontPageBanner (4, TRUE, &NewString);
528 HiiSetString (gFrontPagePrivate.HiiHandle, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE4_LEFT), NewString, NULL);
529 FreePool (NewString);
530
531 NewString = HiiGetString (gFrontPagePrivate.HiiHandle, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE4_RIGHT), NULL);
532 UiCustomizeFrontPageBanner (4, FALSE, &NewString);
533 HiiSetString (gFrontPagePrivate.HiiHandle, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE4_RIGHT), NewString, NULL);
534 FreePool (NewString);
535
536 NewString = HiiGetString (gFrontPagePrivate.HiiHandle, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE5_LEFT), NULL);
537 UiCustomizeFrontPageBanner (5, TRUE, &NewString);
538 HiiSetString (gFrontPagePrivate.HiiHandle, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE5_LEFT), NewString, NULL);
539 FreePool (NewString);
540
541 NewString = HiiGetString (gFrontPagePrivate.HiiHandle, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE5_RIGHT), NULL);
542 UiCustomizeFrontPageBanner (5, FALSE, &NewString);
543 HiiSetString (gFrontPagePrivate.HiiHandle, STRING_TOKEN (STR_CUSTOMIZE_BANNER_LINE5_RIGHT), NewString, NULL);
544 FreePool (NewString);
545
546 //
547 // Update Front Page banner strings base on SmBios Table.
548 //
549 Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **) &Smbios);
550 if (EFI_ERROR (Status)) {
551 //
552 // Smbios protocol not found, get the default value.
553 //
554 NewString = HiiGetString (gFrontPagePrivate.HiiHandle, STRING_TOKEN (STR_FRONT_PAGE_COMPUTER_MODEL), NULL);
555 UiCustomizeFrontPageBanner (1, TRUE, &NewString);
556 HiiSetString (gFrontPagePrivate.HiiHandle, STRING_TOKEN (STR_FRONT_PAGE_COMPUTER_MODEL), NewString, NULL);
557 FreePool (NewString);
558
559 NewString = HiiGetString (gFrontPagePrivate.HiiHandle, STRING_TOKEN (STR_FRONT_PAGE_CPU_MODEL), NULL);
560 UiCustomizeFrontPageBanner (2, TRUE, &NewString);
561 HiiSetString (gFrontPagePrivate.HiiHandle, STRING_TOKEN (STR_FRONT_PAGE_CPU_MODEL), NewString, NULL);
562 FreePool (NewString);
563
564 NewString = HiiGetString (gFrontPagePrivate.HiiHandle, STRING_TOKEN (STR_FRONT_PAGE_CPU_SPEED), NULL);
565 UiCustomizeFrontPageBanner (2, FALSE, &NewString);
566 HiiSetString (gFrontPagePrivate.HiiHandle, STRING_TOKEN (STR_FRONT_PAGE_CPU_SPEED), NewString, NULL);
567 FreePool (NewString);
568
569 NewString = HiiGetString (gFrontPagePrivate.HiiHandle, STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION), NULL);
570 UiCustomizeFrontPageBanner (3, TRUE, &NewString);
571 HiiSetString (gFrontPagePrivate.HiiHandle, STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION), NewString, NULL);
572 FreePool (NewString);
573
574 NewString = HiiGetString (gFrontPagePrivate.HiiHandle, STRING_TOKEN (STR_FRONT_PAGE_MEMORY_SIZE), NULL);
575 UiCustomizeFrontPageBanner (3, FALSE, &NewString);
576 HiiSetString (gFrontPagePrivate.HiiHandle, STRING_TOKEN (STR_FRONT_PAGE_MEMORY_SIZE), NewString, NULL);
577 FreePool (NewString);
578
579 return;
580 }
581
582 SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
583 Status = Smbios->GetNext (Smbios, &SmbiosHandle, NULL, &Record, NULL);
584 while (!EFI_ERROR(Status)) {
585 if (Record->Type == SMBIOS_TYPE_BIOS_INFORMATION) {
586 Type0Record = (SMBIOS_TABLE_TYPE0 *) Record;
587 StrIndex = Type0Record->BiosVersion;
588 GetOptionalStringByIndex ((CHAR8*)((UINT8*)Type0Record + Type0Record->Hdr.Length), StrIndex, &NewString);
589
590 FirmwareVersionString = (CHAR16 *) PcdGetPtr (PcdFirmwareVersionString);
591 if (*FirmwareVersionString != 0x0000 ) {
592 FreePool (NewString);
593 NewString = (CHAR16 *) PcdGetPtr (PcdFirmwareVersionString);
594 UiCustomizeFrontPageBanner (3, TRUE, &NewString);
595 HiiSetString (gFrontPagePrivate.HiiHandle, STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION), NewString, NULL);
596 } else {
597 UiCustomizeFrontPageBanner (3, TRUE, &NewString);
598 HiiSetString (gFrontPagePrivate.HiiHandle, STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION), NewString, NULL);
599 FreePool (NewString);
600 }
601 }
602
603 if (Record->Type == SMBIOS_TYPE_SYSTEM_INFORMATION) {
604 Type1Record = (SMBIOS_TABLE_TYPE1 *) Record;
605 StrIndex = Type1Record->ProductName;
606 GetOptionalStringByIndex ((CHAR8*)((UINT8*)Type1Record + Type1Record->Hdr.Length), StrIndex, &NewString);
607 UiCustomizeFrontPageBanner (1, TRUE, &NewString);
608 HiiSetString (gFrontPagePrivate.HiiHandle, STRING_TOKEN (STR_FRONT_PAGE_COMPUTER_MODEL), NewString, NULL);
609 FreePool (NewString);
610 }
611
612 if ((Record->Type == SMBIOS_TYPE_PROCESSOR_INFORMATION) && !FoundCpu) {
613 Type4Record = (SMBIOS_TABLE_TYPE4 *) Record;
614 //
615 // The information in the record should be only valid when the CPU Socket is populated.
616 //
617 if ((Type4Record->Status & SMBIOS_TYPE4_CPU_SOCKET_POPULATED) == SMBIOS_TYPE4_CPU_SOCKET_POPULATED) {
618 StrIndex = Type4Record->ProcessorVersion;
619 GetOptionalStringByIndex ((CHAR8*)((UINT8*)Type4Record + Type4Record->Hdr.Length), StrIndex, &NewString);
620 UiCustomizeFrontPageBanner (2, TRUE, &NewString);
621 HiiSetString (gFrontPagePrivate.HiiHandle, STRING_TOKEN (STR_FRONT_PAGE_CPU_MODEL), NewString, NULL);
622 FreePool (NewString);
623
624 FoundCpu = TRUE;
625 }
626 }
627
628 if ( Record->Type == SMBIOS_TYPE_MEMORY_ARRAY_MAPPED_ADDRESS ) {
629 Type19Record = (SMBIOS_TABLE_TYPE19 *) Record;
630 if (Type19Record->StartingAddress != 0xFFFFFFFF ) {
631 InstalledMemory += RShiftU64(Type19Record->EndingAddress -
632 Type19Record->StartingAddress + 1, 10);
633 } else {
634 InstalledMemory += RShiftU64(Type19Record->ExtendedEndingAddress -
635 Type19Record->ExtendedStartingAddress + 1, 20);
636 }
637 }
638
639 Status = Smbios->GetNext (Smbios, &SmbiosHandle, NULL, &Record, NULL);
640 }
641
642 //
643 // Now update the total installed RAM size
644 //
645 ConvertMemorySizeToString ((UINT32)InstalledMemory, &NewString );
646 UiCustomizeFrontPageBanner (3, FALSE, &NewString);
647 HiiSetString (gFrontPagePrivate.HiiHandle, STRING_TOKEN (STR_FRONT_PAGE_MEMORY_SIZE), NewString, NULL);
648 FreePool (NewString);
649 }
650
651 /**
652 This function will change video resolution and text mode
653 according to defined setup mode or defined boot mode
654
655 @param IsSetupMode Indicate mode is changed to setup mode or boot mode.
656
657 @retval EFI_SUCCESS Mode is changed successfully.
658 @retval Others Mode failed to be changed.
659
660 **/
661 EFI_STATUS
662 UiSetConsoleMode (
663 BOOLEAN IsSetupMode
664 )
665 {
666 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
667 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut;
668 UINTN SizeOfInfo;
669 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
670 UINT32 MaxGopMode;
671 UINT32 MaxTextMode;
672 UINT32 ModeNumber;
673 UINT32 NewHorizontalResolution;
674 UINT32 NewVerticalResolution;
675 UINT32 NewColumns;
676 UINT32 NewRows;
677 UINTN HandleCount;
678 EFI_HANDLE *HandleBuffer;
679 EFI_STATUS Status;
680 UINTN Index;
681 UINTN CurrentColumn;
682 UINTN CurrentRow;
683
684 MaxGopMode = 0;
685 MaxTextMode = 0;
686
687 //
688 // Get current video resolution and text mode
689 //
690 Status = gBS->HandleProtocol (
691 gST->ConsoleOutHandle,
692 &gEfiGraphicsOutputProtocolGuid,
693 (VOID**)&GraphicsOutput
694 );
695 if (EFI_ERROR (Status)) {
696 GraphicsOutput = NULL;
697 }
698
699 Status = gBS->HandleProtocol (
700 gST->ConsoleOutHandle,
701 &gEfiSimpleTextOutProtocolGuid,
702 (VOID**)&SimpleTextOut
703 );
704 if (EFI_ERROR (Status)) {
705 SimpleTextOut = NULL;
706 }
707
708 if ((GraphicsOutput == NULL) || (SimpleTextOut == NULL)) {
709 return EFI_UNSUPPORTED;
710 }
711
712 if (IsSetupMode) {
713 //
714 // The required resolution and text mode is setup mode.
715 //
716 NewHorizontalResolution = mSetupHorizontalResolution;
717 NewVerticalResolution = mSetupVerticalResolution;
718 NewColumns = mSetupTextModeColumn;
719 NewRows = mSetupTextModeRow;
720 } else {
721 //
722 // The required resolution and text mode is boot mode.
723 //
724 NewHorizontalResolution = mBootHorizontalResolution;
725 NewVerticalResolution = mBootVerticalResolution;
726 NewColumns = mBootTextModeColumn;
727 NewRows = mBootTextModeRow;
728 }
729
730 if (GraphicsOutput != NULL) {
731 MaxGopMode = GraphicsOutput->Mode->MaxMode;
732 }
733
734 if (SimpleTextOut != NULL) {
735 MaxTextMode = SimpleTextOut->Mode->MaxMode;
736 }
737
738 //
739 // 1. If current video resolution is same with required video resolution,
740 // video resolution need not be changed.
741 // 1.1. If current text mode is same with required text mode, text mode need not be changed.
742 // 1.2. If current text mode is different from required text mode, text mode need be changed.
743 // 2. If current video resolution is different from required video resolution, we need restart whole console drivers.
744 //
745 for (ModeNumber = 0; ModeNumber < MaxGopMode; ModeNumber++) {
746 Status = GraphicsOutput->QueryMode (
747 GraphicsOutput,
748 ModeNumber,
749 &SizeOfInfo,
750 &Info
751 );
752 if (!EFI_ERROR (Status)) {
753 if ((Info->HorizontalResolution == NewHorizontalResolution) &&
754 (Info->VerticalResolution == NewVerticalResolution)) {
755 if ((GraphicsOutput->Mode->Info->HorizontalResolution == NewHorizontalResolution) &&
756 (GraphicsOutput->Mode->Info->VerticalResolution == NewVerticalResolution)) {
757 //
758 // Current resolution is same with required resolution, check if text mode need be set
759 //
760 Status = SimpleTextOut->QueryMode (SimpleTextOut, SimpleTextOut->Mode->Mode, &CurrentColumn, &CurrentRow);
761 ASSERT_EFI_ERROR (Status);
762 if (CurrentColumn == NewColumns && CurrentRow == NewRows) {
763 //
764 // If current text mode is same with required text mode. Do nothing
765 //
766 FreePool (Info);
767 return EFI_SUCCESS;
768 } else {
769 //
770 // If current text mode is different from required text mode. Set new video mode
771 //
772 for (Index = 0; Index < MaxTextMode; Index++) {
773 Status = SimpleTextOut->QueryMode (SimpleTextOut, Index, &CurrentColumn, &CurrentRow);
774 if (!EFI_ERROR(Status)) {
775 if ((CurrentColumn == NewColumns) && (CurrentRow == NewRows)) {
776 //
777 // Required text mode is supported, set it.
778 //
779 Status = SimpleTextOut->SetMode (SimpleTextOut, Index);
780 ASSERT_EFI_ERROR (Status);
781 //
782 // Update text mode PCD.
783 //
784 Status = PcdSet32S (PcdConOutColumn, mSetupTextModeColumn);
785 ASSERT_EFI_ERROR (Status);
786 Status = PcdSet32S (PcdConOutRow, mSetupTextModeRow);
787 ASSERT_EFI_ERROR (Status);
788 FreePool (Info);
789 return EFI_SUCCESS;
790 }
791 }
792 }
793 if (Index == MaxTextMode) {
794 //
795 // If required text mode is not supported, return error.
796 //
797 FreePool (Info);
798 return EFI_UNSUPPORTED;
799 }
800 }
801 } else {
802 //
803 // If current video resolution is not same with the new one, set new video resolution.
804 // In this case, the driver which produces simple text out need be restarted.
805 //
806 Status = GraphicsOutput->SetMode (GraphicsOutput, ModeNumber);
807 if (!EFI_ERROR (Status)) {
808 FreePool (Info);
809 break;
810 }
811 }
812 }
813 FreePool (Info);
814 }
815 }
816
817 if (ModeNumber == MaxGopMode) {
818 //
819 // If the resolution is not supported, return error.
820 //
821 return EFI_UNSUPPORTED;
822 }
823
824 //
825 // Set PCD to Inform GraphicsConsole to change video resolution.
826 // Set PCD to Inform Consplitter to change text mode.
827 //
828 Status = PcdSet32S (PcdVideoHorizontalResolution, NewHorizontalResolution);
829 ASSERT_EFI_ERROR (Status);
830 Status = PcdSet32S (PcdVideoVerticalResolution, NewVerticalResolution);
831 ASSERT_EFI_ERROR (Status);
832 Status = PcdSet32S (PcdConOutColumn, NewColumns);
833 ASSERT_EFI_ERROR (Status);
834 Status = PcdSet32S (PcdConOutRow, NewRows);
835 ASSERT_EFI_ERROR (Status);
836
837 //
838 // Video mode is changed, so restart graphics console driver and higher level driver.
839 // Reconnect graphics console driver and higher level driver.
840 // Locate all the handles with GOP protocol and reconnect it.
841 //
842 Status = gBS->LocateHandleBuffer (
843 ByProtocol,
844 &gEfiSimpleTextOutProtocolGuid,
845 NULL,
846 &HandleCount,
847 &HandleBuffer
848 );
849 if (!EFI_ERROR (Status)) {
850 for (Index = 0; Index < HandleCount; Index++) {
851 gBS->DisconnectController (HandleBuffer[Index], NULL, NULL);
852 }
853 for (Index = 0; Index < HandleCount; Index++) {
854 gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE);
855 }
856 if (HandleBuffer != NULL) {
857 FreePool (HandleBuffer);
858 }
859 }
860
861 return EFI_SUCCESS;
862 }
863
864 /**
865 The user Entry Point for Application. The user code starts with this function
866 as the real entry point for the image goes into a library that calls this
867 function.
868
869 @param[in] ImageHandle The firmware allocated handle for the EFI image.
870 @param[in] SystemTable A pointer to the EFI System Table.
871
872 @retval EFI_SUCCESS The entry point is executed successfully.
873 @retval other Some error occurs when executing this entry point.
874
875 **/
876 EFI_STATUS
877 EFIAPI
878 InitializeUserInterface (
879 IN EFI_HANDLE ImageHandle,
880 IN EFI_SYSTEM_TABLE *SystemTable
881 )
882 {
883 EFI_HII_HANDLE HiiHandle;
884 EFI_STATUS Status;
885 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
886 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut;
887 UINTN BootTextColumn;
888 UINTN BootTextRow;
889
890 if (!mModeInitialized) {
891 //
892 // After the console is ready, get current video resolution
893 // and text mode before launching setup at first time.
894 //
895 Status = gBS->HandleProtocol (
896 gST->ConsoleOutHandle,
897 &gEfiGraphicsOutputProtocolGuid,
898 (VOID**)&GraphicsOutput
899 );
900 if (EFI_ERROR (Status)) {
901 GraphicsOutput = NULL;
902 }
903
904 Status = gBS->HandleProtocol (
905 gST->ConsoleOutHandle,
906 &gEfiSimpleTextOutProtocolGuid,
907 (VOID**)&SimpleTextOut
908 );
909 if (EFI_ERROR (Status)) {
910 SimpleTextOut = NULL;
911 }
912
913 if (GraphicsOutput != NULL) {
914 //
915 // Get current video resolution and text mode.
916 //
917 mBootHorizontalResolution = GraphicsOutput->Mode->Info->HorizontalResolution;
918 mBootVerticalResolution = GraphicsOutput->Mode->Info->VerticalResolution;
919 }
920
921 if (SimpleTextOut != NULL) {
922 Status = SimpleTextOut->QueryMode (
923 SimpleTextOut,
924 SimpleTextOut->Mode->Mode,
925 &BootTextColumn,
926 &BootTextRow
927 );
928 mBootTextModeColumn = (UINT32)BootTextColumn;
929 mBootTextModeRow = (UINT32)BootTextRow;
930 }
931
932 //
933 // Get user defined text mode for setup.
934 //
935 mSetupHorizontalResolution = PcdGet32 (PcdSetupVideoHorizontalResolution);
936 mSetupVerticalResolution = PcdGet32 (PcdSetupVideoVerticalResolution);
937 mSetupTextModeColumn = PcdGet32 (PcdSetupConOutColumn);
938 mSetupTextModeRow = PcdGet32 (PcdSetupConOutRow);
939
940 mModeInitialized = TRUE;
941 }
942
943 gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL);
944 gST->ConOut->ClearScreen (gST->ConOut);
945
946 //
947 // Install customized fonts needed by Front Page
948 //
949 HiiHandle = ExportFonts ();
950 ASSERT (HiiHandle != NULL);
951
952 InitializeStringSupport ();
953
954 UiSetConsoleMode (TRUE);
955 UiEntry (FALSE);
956 UiSetConsoleMode (FALSE);
957
958 UninitializeStringSupport ();
959 HiiRemovePackages (HiiHandle);
960
961 return EFI_SUCCESS;
962 }
963
964 /**
965 This function is the main entry of the UI entry.
966 The function will present the main menu of the system UI.
967
968 @param ConnectAllHappened Caller passes the value to UI to avoid unnecessary connect-all.
969
970 **/
971 VOID
972 EFIAPI
973 UiEntry (
974 IN BOOLEAN ConnectAllHappened
975 )
976 {
977 EFI_STATUS Status;
978 EFI_BOOT_LOGO_PROTOCOL *BootLogo;
979
980 //
981 // Enter Setup page.
982 //
983 REPORT_STATUS_CODE (
984 EFI_PROGRESS_CODE,
985 (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_PC_USER_SETUP)
986 );
987
988 //
989 // Indicate if the connect all has been performed before.
990 // If has not been performed before, do here.
991 //
992 if (!ConnectAllHappened) {
993 EfiBootManagerConnectAll ();
994 }
995
996 //
997 // The boot option enumeration time is acceptable in Ui driver
998 //
999 EfiBootManagerRefreshAllBootOption ();
1000
1001 //
1002 // Boot Logo is corrupted, report it using Boot Logo protocol.
1003 //
1004 Status = gBS->LocateProtocol (&gEfiBootLogoProtocolGuid, NULL, (VOID **) &BootLogo);
1005 if (!EFI_ERROR (Status) && (BootLogo != NULL)) {
1006 BootLogo->SetBootLogo (BootLogo, NULL, 0, 0, 0, 0);
1007 }
1008
1009 InitializeFrontPage ();
1010
1011 CallFrontPage ();
1012
1013 FreeFrontPage ();
1014
1015 if (mLanguageString != NULL) {
1016 FreePool (mLanguageString);
1017 mLanguageString = NULL;
1018 }
1019
1020 //
1021 //Will leave browser, check any reset required change is applied? if yes, reset system
1022 //
1023 SetupResetReminder ();
1024 }
1025
1026 //
1027 // Following are BDS Lib functions which contain all the code about setup browser reset reminder feature.
1028 // Setup Browser reset reminder feature is that an reset reminder will be given before user leaves the setup browser if
1029 // user change any option setting which needs a reset to be effective, and the reset will be applied according to the user selection.
1030 //
1031
1032
1033
1034
1035
1036 /**
1037 Record the info that a reset is required.
1038 A module boolean variable is used to record whether a reset is required.
1039
1040 **/
1041 VOID
1042 EFIAPI
1043 EnableResetRequired (
1044 VOID
1045 )
1046 {
1047 mResetRequired = TRUE;
1048 }
1049
1050
1051
1052
1053
1054 /**
1055 Check if user changed any option setting which needs a system reset to be effective.
1056
1057 **/
1058 BOOLEAN
1059 EFIAPI
1060 IsResetRequired (
1061 VOID
1062 )
1063 {
1064 return mResetRequired;
1065 }
1066
1067
1068 /**
1069 Check whether a reset is needed, and finish the reset reminder feature.
1070 If a reset is needed, Popup a menu to notice user, and finish the feature
1071 according to the user selection.
1072
1073 **/
1074 VOID
1075 EFIAPI
1076 SetupResetReminder (
1077 VOID
1078 )
1079 {
1080 EFI_INPUT_KEY Key;
1081 CHAR16 *StringBuffer1;
1082 CHAR16 *StringBuffer2;
1083
1084 //
1085 //check any reset required change is applied? if yes, reset system
1086 //
1087 if (IsResetRequired ()) {
1088
1089 StringBuffer1 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16));
1090 ASSERT (StringBuffer1 != NULL);
1091 StringBuffer2 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16));
1092 ASSERT (StringBuffer2 != NULL);
1093 StrCpyS (StringBuffer1, MAX_STRING_LEN, L"Configuration changed. Reset to apply it Now.");
1094 StrCpyS (StringBuffer2, MAX_STRING_LEN, L"Press ENTER to reset");
1095 //
1096 // Popup a menu to notice user
1097 //
1098 do {
1099 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, StringBuffer1, StringBuffer2, NULL);
1100 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
1101
1102 FreePool (StringBuffer1);
1103 FreePool (StringBuffer2);
1104
1105 gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);
1106 }
1107 }
1108