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