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