]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Application/UiApp/FrontPage.c
MdeModulePkg UiApp: Remove invalid keyword "bds" in UiApp.
[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 UiSetConsoleMode (
666 BOOLEAN IsSetupMode
667 )
668 {
669 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
670 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut;
671 UINTN SizeOfInfo;
672 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
673 UINT32 MaxGopMode;
674 UINT32 MaxTextMode;
675 UINT32 ModeNumber;
676 UINT32 NewHorizontalResolution;
677 UINT32 NewVerticalResolution;
678 UINT32 NewColumns;
679 UINT32 NewRows;
680 UINTN HandleCount;
681 EFI_HANDLE *HandleBuffer;
682 EFI_STATUS Status;
683 UINTN Index;
684 UINTN CurrentColumn;
685 UINTN CurrentRow;
686
687 MaxGopMode = 0;
688 MaxTextMode = 0;
689
690 //
691 // Get current video resolution and text mode
692 //
693 Status = gBS->HandleProtocol (
694 gST->ConsoleOutHandle,
695 &gEfiGraphicsOutputProtocolGuid,
696 (VOID**)&GraphicsOutput
697 );
698 if (EFI_ERROR (Status)) {
699 GraphicsOutput = NULL;
700 }
701
702 Status = gBS->HandleProtocol (
703 gST->ConsoleOutHandle,
704 &gEfiSimpleTextOutProtocolGuid,
705 (VOID**)&SimpleTextOut
706 );
707 if (EFI_ERROR (Status)) {
708 SimpleTextOut = NULL;
709 }
710
711 if ((GraphicsOutput == NULL) || (SimpleTextOut == NULL)) {
712 return EFI_UNSUPPORTED;
713 }
714
715 if (IsSetupMode) {
716 //
717 // The requried resolution and text mode is setup mode.
718 //
719 NewHorizontalResolution = mSetupHorizontalResolution;
720 NewVerticalResolution = mSetupVerticalResolution;
721 NewColumns = mSetupTextModeColumn;
722 NewRows = mSetupTextModeRow;
723 } else {
724 //
725 // The required resolution and text mode is boot mode.
726 //
727 NewHorizontalResolution = mBootHorizontalResolution;
728 NewVerticalResolution = mBootVerticalResolution;
729 NewColumns = mBootTextModeColumn;
730 NewRows = mBootTextModeRow;
731 }
732
733 if (GraphicsOutput != NULL) {
734 MaxGopMode = GraphicsOutput->Mode->MaxMode;
735 }
736
737 if (SimpleTextOut != NULL) {
738 MaxTextMode = SimpleTextOut->Mode->MaxMode;
739 }
740
741 //
742 // 1. If current video resolution is same with required video resolution,
743 // video resolution need not be changed.
744 // 1.1. If current text mode is same with required text mode, text mode need not be changed.
745 // 1.2. If current text mode is different from required text mode, text mode need be changed.
746 // 2. If current video resolution is different from required video resolution, we need restart whole console drivers.
747 //
748 for (ModeNumber = 0; ModeNumber < MaxGopMode; ModeNumber++) {
749 Status = GraphicsOutput->QueryMode (
750 GraphicsOutput,
751 ModeNumber,
752 &SizeOfInfo,
753 &Info
754 );
755 if (!EFI_ERROR (Status)) {
756 if ((Info->HorizontalResolution == NewHorizontalResolution) &&
757 (Info->VerticalResolution == NewVerticalResolution)) {
758 if ((GraphicsOutput->Mode->Info->HorizontalResolution == NewHorizontalResolution) &&
759 (GraphicsOutput->Mode->Info->VerticalResolution == NewVerticalResolution)) {
760 //
761 // Current resolution is same with required resolution, check if text mode need be set
762 //
763 Status = SimpleTextOut->QueryMode (SimpleTextOut, SimpleTextOut->Mode->Mode, &CurrentColumn, &CurrentRow);
764 ASSERT_EFI_ERROR (Status);
765 if (CurrentColumn == NewColumns && CurrentRow == NewRows) {
766 //
767 // If current text mode is same with required text mode. Do nothing
768 //
769 FreePool (Info);
770 return EFI_SUCCESS;
771 } else {
772 //
773 // If current text mode is different from requried text mode. Set new video mode
774 //
775 for (Index = 0; Index < MaxTextMode; Index++) {
776 Status = SimpleTextOut->QueryMode (SimpleTextOut, Index, &CurrentColumn, &CurrentRow);
777 if (!EFI_ERROR(Status)) {
778 if ((CurrentColumn == NewColumns) && (CurrentRow == NewRows)) {
779 //
780 // Required text mode is supported, set it.
781 //
782 Status = SimpleTextOut->SetMode (SimpleTextOut, Index);
783 ASSERT_EFI_ERROR (Status);
784 //
785 // Update text mode PCD.
786 //
787 Status = PcdSet32S (PcdConOutColumn, mSetupTextModeColumn);
788 ASSERT_EFI_ERROR (Status);
789 Status = PcdSet32S (PcdConOutRow, mSetupTextModeRow);
790 ASSERT_EFI_ERROR (Status);
791 FreePool (Info);
792 return EFI_SUCCESS;
793 }
794 }
795 }
796 if (Index == MaxTextMode) {
797 //
798 // If requried text mode is not supported, return error.
799 //
800 FreePool (Info);
801 return EFI_UNSUPPORTED;
802 }
803 }
804 } else {
805 //
806 // If current video resolution is not same with the new one, set new video resolution.
807 // In this case, the driver which produces simple text out need be restarted.
808 //
809 Status = GraphicsOutput->SetMode (GraphicsOutput, ModeNumber);
810 if (!EFI_ERROR (Status)) {
811 FreePool (Info);
812 break;
813 }
814 }
815 }
816 FreePool (Info);
817 }
818 }
819
820 if (ModeNumber == MaxGopMode) {
821 //
822 // If the resolution is not supported, return error.
823 //
824 return EFI_UNSUPPORTED;
825 }
826
827 //
828 // Set PCD to Inform GraphicsConsole to change video resolution.
829 // Set PCD to Inform Consplitter to change text mode.
830 //
831 Status = PcdSet32S (PcdVideoHorizontalResolution, NewHorizontalResolution);
832 ASSERT_EFI_ERROR (Status);
833 Status = PcdSet32S (PcdVideoVerticalResolution, NewVerticalResolution);
834 ASSERT_EFI_ERROR (Status);
835 Status = PcdSet32S (PcdConOutColumn, NewColumns);
836 ASSERT_EFI_ERROR (Status);
837 Status = PcdSet32S (PcdConOutRow, NewRows);
838 ASSERT_EFI_ERROR (Status);
839
840 //
841 // Video mode is changed, so restart graphics console driver and higher level driver.
842 // Reconnect graphics console driver and higher level driver.
843 // Locate all the handles with GOP protocol and reconnect it.
844 //
845 Status = gBS->LocateHandleBuffer (
846 ByProtocol,
847 &gEfiSimpleTextOutProtocolGuid,
848 NULL,
849 &HandleCount,
850 &HandleBuffer
851 );
852 if (!EFI_ERROR (Status)) {
853 for (Index = 0; Index < HandleCount; Index++) {
854 gBS->DisconnectController (HandleBuffer[Index], NULL, NULL);
855 }
856 for (Index = 0; Index < HandleCount; Index++) {
857 gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE);
858 }
859 if (HandleBuffer != NULL) {
860 FreePool (HandleBuffer);
861 }
862 }
863
864 return EFI_SUCCESS;
865 }
866
867 /**
868 The user Entry Point for Application. The user code starts with this function
869 as the real entry point for the image goes into a library that calls this
870 function.
871
872 @param[in] ImageHandle The firmware allocated handle for the EFI image.
873 @param[in] SystemTable A pointer to the EFI System Table.
874
875 @retval EFI_SUCCESS The entry point is executed successfully.
876 @retval other Some error occurs when executing this entry point.
877
878 **/
879 EFI_STATUS
880 EFIAPI
881 InitializeUserInterface (
882 IN EFI_HANDLE ImageHandle,
883 IN EFI_SYSTEM_TABLE *SystemTable
884 )
885 {
886 EFI_HII_HANDLE HiiHandle;
887 EFI_STATUS Status;
888 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
889 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut;
890 UINTN BootTextColumn;
891 UINTN BootTextRow;
892
893 if (!mModeInitialized) {
894 //
895 // After the console is ready, get current video resolution
896 // and text mode before launching setup at first time.
897 //
898 Status = gBS->HandleProtocol (
899 gST->ConsoleOutHandle,
900 &gEfiGraphicsOutputProtocolGuid,
901 (VOID**)&GraphicsOutput
902 );
903 if (EFI_ERROR (Status)) {
904 GraphicsOutput = NULL;
905 }
906
907 Status = gBS->HandleProtocol (
908 gST->ConsoleOutHandle,
909 &gEfiSimpleTextOutProtocolGuid,
910 (VOID**)&SimpleTextOut
911 );
912 if (EFI_ERROR (Status)) {
913 SimpleTextOut = NULL;
914 }
915
916 if (GraphicsOutput != NULL) {
917 //
918 // Get current video resolution and text mode.
919 //
920 mBootHorizontalResolution = GraphicsOutput->Mode->Info->HorizontalResolution;
921 mBootVerticalResolution = GraphicsOutput->Mode->Info->VerticalResolution;
922 }
923
924 if (SimpleTextOut != NULL) {
925 Status = SimpleTextOut->QueryMode (
926 SimpleTextOut,
927 SimpleTextOut->Mode->Mode,
928 &BootTextColumn,
929 &BootTextRow
930 );
931 mBootTextModeColumn = (UINT32)BootTextColumn;
932 mBootTextModeRow = (UINT32)BootTextRow;
933 }
934
935 //
936 // Get user defined text mode for setup.
937 //
938 mSetupHorizontalResolution = PcdGet32 (PcdSetupVideoHorizontalResolution);
939 mSetupVerticalResolution = PcdGet32 (PcdSetupVideoVerticalResolution);
940 mSetupTextModeColumn = PcdGet32 (PcdSetupConOutColumn);
941 mSetupTextModeRow = PcdGet32 (PcdSetupConOutRow);
942
943 mModeInitialized = TRUE;
944 }
945
946 gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL);
947 gST->ConOut->ClearScreen (gST->ConOut);
948
949 //
950 // Install customized fonts needed by Front Page
951 //
952 HiiHandle = ExportFonts ();
953 ASSERT (HiiHandle != NULL);
954
955 InitializeStringSupport ();
956
957 UiSetConsoleMode (TRUE);
958 UiEntry (FALSE);
959 UiSetConsoleMode (FALSE);
960
961 UninitializeStringSupport ();
962 HiiRemovePackages (HiiHandle);
963
964 return EFI_SUCCESS;
965 }
966
967 /**
968 This function is the main entry of the UI entry.
969 The function will present the main menu of the system UI.
970
971 @param ConnectAllHappened Caller passes the value to UI to avoid unnecessary connect-all.
972
973 **/
974 VOID
975 EFIAPI
976 UiEntry (
977 IN BOOLEAN ConnectAllHappened
978 )
979 {
980 EFI_STATUS Status;
981 EFI_BOOT_LOGO_PROTOCOL *BootLogo;
982
983 //
984 // Enter Setup page.
985 //
986 REPORT_STATUS_CODE (
987 EFI_PROGRESS_CODE,
988 (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_PC_USER_SETUP)
989 );
990
991 //
992 // Indicate if the connect all has been performed before.
993 //
994 if (ConnectAllHappened) {
995 gConnectAllHappened = TRUE;
996 }
997
998 //
999 // The boot option enumeration time is acceptable in Ui driver
1000 //
1001 EfiBootManagerRefreshAllBootOption ();
1002
1003 //
1004 // Boot Logo is corrupted, report it using Boot Logo protocol.
1005 //
1006 Status = gBS->LocateProtocol (&gEfiBootLogoProtocolGuid, NULL, (VOID **) &BootLogo);
1007 if (!EFI_ERROR (Status) && (BootLogo != NULL)) {
1008 BootLogo->SetBootLogo (BootLogo, NULL, 0, 0, 0, 0);
1009 }
1010
1011 InitializeFrontPage ();
1012
1013 CallFrontPage ();
1014
1015 FreeFrontPage ();
1016
1017 if (mLanguageString != NULL) {
1018 FreePool (mLanguageString);
1019 mLanguageString = NULL;
1020 }
1021
1022 //
1023 //Will leave browser, check any reset required change is applied? if yes, reset system
1024 //
1025 SetupResetReminder ();
1026 }
1027
1028 //
1029 // Following are BDS Lib functions which contain all the code about setup browser reset reminder feature.
1030 // Setup Browser reset reminder feature is that an reset reminder will be given before user leaves the setup browser if
1031 // user change any option setting which needs a reset to be effective, and the reset will be applied according to the user selection.
1032 //
1033
1034
1035 /**
1036 Enable the setup browser reset reminder feature.
1037 This routine is used in platform tip. If the platform policy need the feature, use the routine to enable it.
1038
1039 **/
1040 VOID
1041 EFIAPI
1042 EnableResetReminderFeature (
1043 VOID
1044 )
1045 {
1046 mFeaturerSwitch = TRUE;
1047 }
1048
1049
1050 /**
1051 Disable the setup browser reset reminder feature.
1052 This routine is used in platform tip. If the platform policy do not want the feature, use the routine to disable it.
1053
1054 **/
1055 VOID
1056 EFIAPI
1057 DisableResetReminderFeature (
1058 VOID
1059 )
1060 {
1061 mFeaturerSwitch = FALSE;
1062 }
1063
1064
1065 /**
1066 Record the info that a reset is required.
1067 A module boolean variable is used to record whether a reset is required.
1068
1069 **/
1070 VOID
1071 EFIAPI
1072 EnableResetRequired (
1073 VOID
1074 )
1075 {
1076 mResetRequired = TRUE;
1077 }
1078
1079
1080 /**
1081 Record the info that no reset is required.
1082 A module boolean variable is used to record whether a reset is required.
1083
1084 **/
1085 VOID
1086 EFIAPI
1087 DisableResetRequired (
1088 VOID
1089 )
1090 {
1091 mResetRequired = FALSE;
1092 }
1093
1094
1095 /**
1096 Check whether platform policy enable the reset reminder feature. The default is enabled.
1097
1098 **/
1099 BOOLEAN
1100 EFIAPI
1101 IsResetReminderFeatureEnable (
1102 VOID
1103 )
1104 {
1105 return mFeaturerSwitch;
1106 }
1107
1108
1109 /**
1110 Check if user changed any option setting which needs a system reset to be effective.
1111
1112 **/
1113 BOOLEAN
1114 EFIAPI
1115 IsResetRequired (
1116 VOID
1117 )
1118 {
1119 return mResetRequired;
1120 }
1121
1122
1123 /**
1124 Check whether a reset is needed, and finish the reset reminder feature.
1125 If a reset is needed, Popup a menu to notice user, and finish the feature
1126 according to the user selection.
1127
1128 **/
1129 VOID
1130 EFIAPI
1131 SetupResetReminder (
1132 VOID
1133 )
1134 {
1135 EFI_INPUT_KEY Key;
1136 CHAR16 *StringBuffer1;
1137 CHAR16 *StringBuffer2;
1138
1139
1140 //
1141 //check any reset required change is applied? if yes, reset system
1142 //
1143 if (IsResetReminderFeatureEnable ()) {
1144 if (IsResetRequired ()) {
1145
1146 StringBuffer1 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16));
1147 ASSERT (StringBuffer1 != NULL);
1148 StringBuffer2 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16));
1149 ASSERT (StringBuffer2 != NULL);
1150 StrCpyS (StringBuffer1, MAX_STRING_LEN, L"Configuration changed. Reset to apply it Now.");
1151 StrCpyS (StringBuffer2, MAX_STRING_LEN, L"Press ENTER to reset");
1152 //
1153 // Popup a menu to notice user
1154 //
1155 do {
1156 CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, StringBuffer1, StringBuffer2, NULL);
1157 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
1158
1159 FreePool (StringBuffer1);
1160 FreePool (StringBuffer2);
1161
1162 gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);
1163 }
1164 }
1165 }
1166