]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c
Update BdsDxe to use HiiLib and UefiHiiServicesLib APIs to eliminate the symbol colli...
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / BdsDxe / FrontPage.c
1 /** @file
2 FrontPage routines to handle the callbacks and browser calls
3
4 Copyright (c) 2004 - 2009, Intel Corporation. <BR>
5 All rights reserved. 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 "Bds.h"
16 #include "FrontPage.h"
17 #include "Language.h"
18
19 EFI_GUID mFrontPageGuid = FRONT_PAGE_FORMSET_GUID;
20
21 BOOLEAN gConnectAllHappened = FALSE;
22 UINTN gCallbackKey;
23
24 EFI_FORM_BROWSER2_PROTOCOL *gFormBrowser2;
25
26 FRONT_PAGE_CALLBACK_DATA gFrontPagePrivate = {
27 FRONT_PAGE_CALLBACK_DATA_SIGNATURE,
28 NULL,
29 NULL,
30 NULL,
31 {
32 FakeExtractConfig,
33 FakeRouteConfig,
34 FrontPageCallback
35 }
36 };
37
38 HII_VENDOR_DEVICE_PATH mFrontPageHiiVendorDevicePath = {
39 {
40 {
41 HARDWARE_DEVICE_PATH,
42 HW_VENDOR_DP,
43 {
44 (UINT8) (sizeof (VENDOR_DEVICE_PATH)),
45 (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)
46 }
47 },
48 //
49 // {8E6D99EE-7531-48f8-8745-7F6144468FF2}
50 //
51 { 0x8e6d99ee, 0x7531, 0x48f8, { 0x87, 0x45, 0x7f, 0x61, 0x44, 0x46, 0x8f, 0xf2 } }
52 },
53 {
54 END_DEVICE_PATH_TYPE,
55 END_ENTIRE_DEVICE_PATH_SUBTYPE,
56 {
57 (UINT8) (END_DEVICE_PATH_LENGTH),
58 (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)
59 }
60 }
61 };
62
63 /**
64 This function allows a caller to extract the current configuration for one
65 or more named elements from the target driver.
66
67
68 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
69 @param Request A null-terminated Unicode string in <ConfigRequest> format.
70 @param Progress On return, points to a character in the Request string.
71 Points to the string's null terminator if request was successful.
72 Points to the most recent '&' before the first failing name/value
73 pair (or the beginning of the string if the failure is in the
74 first name/value pair) if the request was not successful.
75 @param Results A null-terminated Unicode string in <ConfigAltResp> format which
76 has all values filled in for the names in the Request string.
77 String to be allocated by the called function.
78
79 @retval EFI_SUCCESS The Results is filled with the requested values.
80 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
81 @retval EFI_INVALID_PARAMETER Request is NULL, illegal syntax, or unknown name.
82 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
83
84 **/
85 EFI_STATUS
86 EFIAPI
87 FakeExtractConfig (
88 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
89 IN CONST EFI_STRING Request,
90 OUT EFI_STRING *Progress,
91 OUT EFI_STRING *Results
92 )
93 {
94 if (Request == NULL || Progress == NULL || Results == NULL) {
95 return EFI_INVALID_PARAMETER;
96 }
97 *Progress = Request;
98 return EFI_NOT_FOUND;
99 }
100
101 /**
102 This function processes the results of changes in configuration.
103
104
105 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
106 @param Configuration A null-terminated Unicode string in <ConfigResp> format.
107 @param Progress A pointer to a string filled in with the offset of the most
108 recent '&' before the first failing name/value pair (or the
109 beginning of the string if the failure is in the first
110 name/value pair) or the terminating NULL if all was successful.
111
112 @retval EFI_SUCCESS The Results is processed successfully.
113 @retval EFI_INVALID_PARAMETER Configuration is NULL.
114 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.
115
116 **/
117 EFI_STATUS
118 EFIAPI
119 FakeRouteConfig (
120 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
121 IN CONST EFI_STRING Configuration,
122 OUT EFI_STRING *Progress
123 )
124 {
125 if (Configuration == NULL || Progress == NULL) {
126 return EFI_INVALID_PARAMETER;
127 }
128
129 *Progress = Configuration;
130 if (!HiiIsConfigHdrMatch (Configuration, &mBootMaintGuid, mBootMaintStorageName)
131 && !HiiIsConfigHdrMatch (Configuration, &mFileExplorerGuid, mFileExplorerStorageName)) {
132 return EFI_NOT_FOUND;
133 }
134
135 *Progress = Configuration + StrLen (Configuration);
136 return EFI_SUCCESS;
137 }
138
139 /**
140 This function processes the results of changes in configuration.
141
142
143 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
144 @param Action Specifies the type of action taken by the browser.
145 @param QuestionId A unique value which is sent to the original exporting driver
146 so that it can identify the type of data to expect.
147 @param Type The type of value for the question.
148 @param Value A pointer to the data being sent to the original exporting driver.
149 @param ActionRequest On return, points to the action requested by the callback function.
150
151 @retval EFI_SUCCESS The callback successfully handled the action.
152 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
153 @retval EFI_DEVICE_ERROR The variable could not be saved.
154 @retval EFI_UNSUPPORTED The specified Action is not supported by the callback.
155
156 **/
157 EFI_STATUS
158 EFIAPI
159 FrontPageCallback (
160 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
161 IN EFI_BROWSER_ACTION Action,
162 IN EFI_QUESTION_ID QuestionId,
163 IN UINT8 Type,
164 IN EFI_IFR_TYPE_VALUE *Value,
165 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
166 )
167 {
168 CHAR8 *LanguageString;
169 CHAR8 *LangCode;
170 CHAR8 *Lang;
171 UINTN Index;
172 EFI_STATUS Status;
173 CHAR8 *PlatformSupportedLanguages;
174 CHAR8 *BestLanguage;
175
176 if ((Value == NULL) || (ActionRequest == NULL)) {
177 return EFI_INVALID_PARAMETER;
178 }
179
180 gCallbackKey = QuestionId;
181
182 //
183 // The first 4 entries in the Front Page are to be GUARANTEED to remain constant so IHV's can
184 // describe to their customers in documentation how to find their setup information (namely
185 // under the device manager and specific buckets)
186 //
187 switch (QuestionId) {
188 case FRONT_PAGE_KEY_CONTINUE:
189 //
190 // This is the continue - clear the screen and return an error to get out of FrontPage loop
191 //
192 break;
193
194 case FRONT_PAGE_KEY_LANGUAGE:
195 //
196 // Collect the languages from what our current Language support is based on our VFR
197 //
198 LanguageString = HiiGetSupportedLanguages (gFrontPagePrivate.HiiHandle);
199 ASSERT (LanguageString != NULL);
200 //
201 // Allocate working buffer for RFC 4646 language in supported LanguageString.
202 //
203 Lang = AllocatePool (AsciiStrSize (LanguageString));
204 ASSERT (Lang != NULL);
205
206 Index = 0;
207 LangCode = LanguageString;
208 while (*LangCode != 0) {
209 GetNextLanguage (&LangCode, Lang);
210
211 if (Index == Value->u8) {
212 break;
213 }
214
215 Index++;
216 }
217
218 PlatformSupportedLanguages = GetEfiGlobalVariable (L"PlatformLangCodes");
219 if (PlatformSupportedLanguages == NULL) {
220 PlatformSupportedLanguages = AllocateCopyPool (
221 AsciiStrSize ((CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLangCodes)),
222 (CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLangCodes)
223 );
224 ASSERT (PlatformSupportedLanguages != NULL);
225 }
226
227 //
228 // Select the best language in platform supported Language.
229 //
230 BestLanguage = GetBestLanguage (
231 PlatformSupportedLanguages,
232 FALSE,
233 Lang,
234 NULL
235 );
236 if (BestLanguage != NULL) {
237 Status = gRT->SetVariable (
238 L"PlatformLang",
239 &gEfiGlobalVariableGuid,
240 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
241 AsciiStrSize (BestLanguage),
242 Lang
243 );
244 ASSERT_EFI_ERROR(Status);
245 FreePool (BestLanguage);
246 } else {
247 ASSERT (FALSE);
248 }
249
250 FreePool (PlatformSupportedLanguages);
251 FreePool (Lang);
252 FreePool (LanguageString);
253 break;
254
255 case FRONT_PAGE_KEY_BOOT_MANAGER:
256 //
257 // Boot Manager
258 //
259 break;
260
261 case FRONT_PAGE_KEY_DEVICE_MANAGER:
262 //
263 // Device Manager
264 //
265 break;
266
267 case FRONT_PAGE_KEY_BOOT_MAINTAIN:
268 //
269 // Boot Maintenance Manager
270 //
271 break;
272
273 default:
274 gCallbackKey = 0;
275 break;
276 }
277
278 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;
279
280 return EFI_SUCCESS;
281 }
282
283 /**
284 Initialize HII information for the FrontPage
285
286
287 @param InitializeHiiData TRUE if HII elements need to be initialized.
288
289 @retval EFI_SUCCESS The operation is successful.
290 @retval EFI_DEVICE_ERROR If the dynamic opcode creation failed.
291
292 **/
293 EFI_STATUS
294 InitializeFrontPage (
295 IN BOOLEAN InitializeHiiData
296 )
297 {
298 EFI_STATUS Status;
299 CHAR8 *LanguageString;
300 CHAR8 *LangCode;
301 CHAR8 *Lang;
302 CHAR8 *CurrentLang;
303 CHAR8 *BestLanguage;
304 UINTN OptionCount;
305 CHAR16 *StringBuffer;
306 EFI_HII_HANDLE HiiHandle;
307 VOID *OptionsOpCodeHandle;
308 VOID *StartOpCodeHandle;
309 VOID *EndOpCodeHandle;
310 EFI_IFR_GUID_LABEL *StartLabel;
311 EFI_IFR_GUID_LABEL *EndLabel;
312 BOOLEAN FirstFlag;
313
314 if (InitializeHiiData) {
315 //
316 // Initialize the Device Manager
317 //
318 InitializeDeviceManager ();
319
320 //
321 // Initialize the Device Manager
322 //
323 InitializeBootManager ();
324
325 gCallbackKey = 0;
326
327 //
328 // Locate Hii relative protocols
329 //
330 Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **) &gFormBrowser2);
331 if (EFI_ERROR (Status)) {
332 return Status;
333 }
334
335 //
336 // Install Device Path Protocol and Config Access protocol to driver handle
337 //
338 Status = gBS->InstallMultipleProtocolInterfaces (
339 &gFrontPagePrivate.DriverHandle,
340 &gEfiDevicePathProtocolGuid,
341 &mFrontPageHiiVendorDevicePath,
342 &gEfiHiiConfigAccessProtocolGuid,
343 &gFrontPagePrivate.ConfigAccess,
344 NULL
345 );
346 ASSERT_EFI_ERROR (Status);
347
348 //
349 // Publish our HII data
350 //
351 gFrontPagePrivate.HiiHandle = HiiAddPackages (
352 &mFrontPageGuid,
353 gFrontPagePrivate.DriverHandle,
354 FrontPageVfrBin,
355 BdsDxeStrings,
356 NULL
357 );
358 if (gFrontPagePrivate.HiiHandle == NULL) {
359 return EFI_OUT_OF_RESOURCES;
360 }
361 }
362
363
364 //
365 // Init OpCode Handle and Allocate space for creation of UpdateData Buffer
366 //
367 StartOpCodeHandle = HiiAllocateOpCodeHandle ();
368 ASSERT (StartOpCodeHandle != NULL);
369
370 EndOpCodeHandle = HiiAllocateOpCodeHandle ();
371 ASSERT (EndOpCodeHandle != NULL);
372
373 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();
374 ASSERT (OptionsOpCodeHandle != NULL);
375 //
376 // Create Hii Extend Label OpCode as the start opcode
377 //
378 StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
379 StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
380 StartLabel->Number = LABEL_SELECT_LANGUAGE;
381
382 //
383 // Create Hii Extend Label OpCode as the end opcode
384 //
385 EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));
386 EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
387 EndLabel->Number = LABEL_END;
388
389 //
390 // Collect the languages from what our current Language support is based on our VFR
391 //
392 HiiHandle = gFrontPagePrivate.HiiHandle;
393 LanguageString = HiiGetSupportedLanguages (HiiHandle);
394 ASSERT (LanguageString != NULL);
395 //
396 // Allocate working buffer for RFC 4646 language in supported LanguageString.
397 //
398 Lang = AllocatePool (AsciiStrSize (LanguageString));
399 ASSERT (Lang != NULL);
400
401 CurrentLang = GetEfiGlobalVariable (L"PlatformLang");
402 //
403 // Select the best language in LanguageString as the default one.
404 //
405 BestLanguage = GetBestLanguage (
406 LanguageString,
407 FALSE,
408 (CurrentLang != NULL) ? CurrentLang : "",
409 (CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLang),
410 LanguageString,
411 NULL
412 );
413 //
414 // BestLanguage must be selected as it is the first language in LanguageString by default
415 //
416 ASSERT (BestLanguage != NULL);
417
418 OptionCount = 0;
419 LangCode = LanguageString;
420 FirstFlag = FALSE;
421
422 if (gFrontPagePrivate.LanguageToken == NULL) {
423 while (*LangCode != 0) {
424 GetNextLanguage (&LangCode, Lang);
425 OptionCount ++;
426 }
427 gFrontPagePrivate.LanguageToken = AllocatePool (OptionCount * sizeof (EFI_STRING_ID));
428 ASSERT (gFrontPagePrivate.LanguageToken != NULL);
429 FirstFlag = TRUE;
430 }
431
432 OptionCount = 0;
433 LangCode = LanguageString;
434 while (*LangCode != 0) {
435 GetNextLanguage (&LangCode, Lang);
436
437 if (FirstFlag) {
438 StringBuffer = HiiGetString (HiiHandle, PRINTABLE_LANGUAGE_NAME_STRING_ID, Lang);
439 ASSERT_EFI_ERROR (StringBuffer != NULL);
440
441 //
442 // Save the string Id for each language
443 //
444 gFrontPagePrivate.LanguageToken[OptionCount] = HiiSetString (HiiHandle, 0, StringBuffer, NULL);
445 FreePool (StringBuffer);
446 }
447
448 if (AsciiStrCmp (Lang, BestLanguage) == 0) {
449 HiiCreateOneOfOptionOpCode (
450 OptionsOpCodeHandle,
451 gFrontPagePrivate.LanguageToken[OptionCount],
452 EFI_IFR_OPTION_DEFAULT,
453 EFI_IFR_NUMERIC_SIZE_1,
454 (UINT8) OptionCount
455 );
456 } else {
457 HiiCreateOneOfOptionOpCode (
458 OptionsOpCodeHandle,
459 gFrontPagePrivate.LanguageToken[OptionCount],
460 0,
461 EFI_IFR_NUMERIC_SIZE_1,
462 (UINT8) OptionCount
463 );
464 }
465
466 OptionCount++;
467 }
468
469 if (CurrentLang != NULL) {
470 FreePool (CurrentLang);
471 }
472 FreePool (BestLanguage);
473 FreePool (Lang);
474 FreePool (LanguageString);
475
476 HiiCreateOneOfOpCode (
477 StartOpCodeHandle,
478 FRONT_PAGE_KEY_LANGUAGE,
479 0,
480 0,
481 STRING_TOKEN (STR_LANGUAGE_SELECT),
482 STRING_TOKEN (STR_LANGUAGE_SELECT_HELP),
483 EFI_IFR_FLAG_CALLBACK,
484 EFI_IFR_NUMERIC_SIZE_1,
485 OptionsOpCodeHandle,
486 NULL
487 );
488
489 Status = HiiUpdateForm (
490 HiiHandle,
491 &mFrontPageGuid,
492 FRONT_PAGE_FORM_ID,
493 StartOpCodeHandle, // LABEL_SELECT_LANGUAGE
494 EndOpCodeHandle // LABEL_END
495 );
496
497 HiiFreeOpCodeHandle (StartOpCodeHandle);
498 HiiFreeOpCodeHandle (EndOpCodeHandle);
499 HiiFreeOpCodeHandle (OptionsOpCodeHandle);
500 return Status;
501 }
502
503 /**
504 Call the browser and display the front page
505
506 @return Status code that will be returned by
507 EFI_FORM_BROWSER2_PROTOCOL.SendForm ().
508
509 **/
510 EFI_STATUS
511 CallFrontPage (
512 VOID
513 )
514 {
515 EFI_STATUS Status;
516 EFI_BROWSER_ACTION_REQUEST ActionRequest;
517
518 //
519 // Begin waiting for USER INPUT
520 //
521 REPORT_STATUS_CODE (
522 EFI_PROGRESS_CODE,
523 (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_PC_INPUT_WAIT)
524 );
525
526 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
527 Status = gFormBrowser2->SendForm (
528 gFormBrowser2,
529 &gFrontPagePrivate.HiiHandle,
530 1,
531 &mFrontPageGuid,
532 0,
533 NULL,
534 &ActionRequest
535 );
536 //
537 // Check whether user change any option setting which needs a reset to be effective
538 //
539 if (ActionRequest == EFI_BROWSER_ACTION_REQUEST_RESET) {
540 EnableResetRequired ();
541 }
542
543 return Status;
544 }
545
546 /**
547 Acquire the string associated with the ProducerGuid and return it.
548
549
550 @param ProducerGuid The Guid to search the HII database for
551 @param Token The token value of the string to extract
552 @param String The string that is extracted
553
554 @retval EFI_SUCCESS The function returns EFI_SUCCESS always.
555
556 **/
557 EFI_STATUS
558 GetProducerString (
559 IN EFI_GUID *ProducerGuid,
560 IN EFI_STRING_ID Token,
561 OUT CHAR16 **String
562 )
563 {
564 EFI_STRING TmpString;
565
566 TmpString = HiiGetPackageString (ProducerGuid, Token, NULL);
567 if (TmpString == NULL) {
568 *String = GetStringById (STRING_TOKEN (STR_MISSING_STRING));
569 } else {
570 *String = TmpString;
571 }
572
573 return EFI_SUCCESS;
574 }
575
576 /**
577 Convert Processor Frequency Data to a string.
578
579 @param ProcessorFrequency The frequency data to process
580 @param String The string that is created
581
582 **/
583 VOID
584 ConvertProcessorToString (
585 IN EFI_PROCESSOR_CORE_FREQUENCY_DATA *ProcessorFrequency,
586 OUT CHAR16 **String
587 )
588 {
589 CHAR16 *StringBuffer;
590 UINTN Index;
591 UINT32 FreqMhz;
592
593 if (ProcessorFrequency->Exponent >= 6) {
594 FreqMhz = ProcessorFrequency->Value;
595 for (Index = 0; Index < (UINTN) (ProcessorFrequency->Exponent - 6); Index++) {
596 FreqMhz *= 10;
597 }
598 } else {
599 FreqMhz = 0;
600 }
601
602 StringBuffer = AllocateZeroPool (0x20);
603 ASSERT (StringBuffer != NULL);
604 Index = UnicodeValueToString (StringBuffer, LEFT_JUSTIFY, FreqMhz / 1000, 3);
605 StrCat (StringBuffer, L".");
606 UnicodeValueToString (StringBuffer + Index + 1, PREFIX_ZERO, (FreqMhz % 1000) / 10, 2);
607 StrCat (StringBuffer, L" GHz");
608
609 *String = (CHAR16 *) StringBuffer;
610
611 return ;
612 }
613
614 /**
615 Convert Memory Size to a string.
616
617 @param MemorySize The size of the memory to process
618 @param String The string that is created
619
620 **/
621 VOID
622 ConvertMemorySizeToString (
623 IN UINT32 MemorySize,
624 OUT CHAR16 **String
625 )
626 {
627 CHAR16 *StringBuffer;
628
629 StringBuffer = AllocateZeroPool (0x20);
630 ASSERT (StringBuffer != NULL);
631 UnicodeValueToString (StringBuffer, LEFT_JUSTIFY, MemorySize, 6);
632 StrCat (StringBuffer, L" MB RAM");
633
634 *String = (CHAR16 *) StringBuffer;
635
636 return ;
637 }
638
639 /**
640 Update the banner information for the Front Page based on DataHub information.
641
642 **/
643 VOID
644 UpdateFrontPageStrings (
645 VOID
646 )
647 {
648 EFI_STATUS Status;
649 EFI_STRING_ID TokenToUpdate;
650 CHAR16 *NewString;
651 UINT64 MonotonicCount;
652 EFI_DATA_HUB_PROTOCOL *DataHub;
653 EFI_DATA_RECORD_HEADER *Record;
654 EFI_SUBCLASS_TYPE1_HEADER *DataHeader;
655 EFI_MISC_BIOS_VENDOR_DATA *BiosVendor;
656 EFI_MISC_SYSTEM_MANUFACTURER_DATA *SystemManufacturer;
657 EFI_PROCESSOR_VERSION_DATA *ProcessorVersion;
658 EFI_PROCESSOR_CORE_FREQUENCY_DATA *ProcessorFrequency;
659 EFI_MEMORY_ARRAY_START_ADDRESS_DATA *MemoryArray;
660 BOOLEAN Find[5];
661
662 ZeroMem (Find, sizeof (Find));
663
664 //
665 // Update Front Page strings
666 //
667 Status = gBS->LocateProtocol (
668 &gEfiDataHubProtocolGuid,
669 NULL,
670 (VOID **) &DataHub
671 );
672 ASSERT_EFI_ERROR (Status);
673
674 MonotonicCount = 0;
675 Record = NULL;
676 do {
677 Status = DataHub->GetNextRecord (DataHub, &MonotonicCount, NULL, &Record);
678 if (EFI_ERROR (Status) || Record == NULL) {
679 break;
680 }
681 if (Record->DataRecordClass == EFI_DATA_RECORD_CLASS_DATA) {
682 DataHeader = (EFI_SUBCLASS_TYPE1_HEADER *) (Record + 1);
683 if (CompareGuid (&Record->DataRecordGuid, &gEfiMiscSubClassGuid) &&
684 (DataHeader->RecordType == EFI_MISC_BIOS_VENDOR_RECORD_NUMBER)
685 ) {
686 BiosVendor = (EFI_MISC_BIOS_VENDOR_DATA *) (DataHeader + 1);
687 GetProducerString (&Record->ProducerName, BiosVendor->BiosVersion, &NewString);
688 TokenToUpdate = STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION);
689 HiiSetString (gFrontPagePrivate.HiiHandle, TokenToUpdate, NewString, NULL);
690 FreePool (NewString);
691 Find[0] = TRUE;
692 }
693
694 if (CompareGuid (&Record->DataRecordGuid, &gEfiMiscSubClassGuid) &&
695 (DataHeader->RecordType == EFI_MISC_SYSTEM_MANUFACTURER_RECORD_NUMBER)
696 ) {
697 SystemManufacturer = (EFI_MISC_SYSTEM_MANUFACTURER_DATA *) (DataHeader + 1);
698 GetProducerString (&Record->ProducerName, SystemManufacturer->SystemProductName, &NewString);
699 TokenToUpdate = STRING_TOKEN (STR_FRONT_PAGE_COMPUTER_MODEL);
700 HiiSetString (gFrontPagePrivate.HiiHandle, TokenToUpdate, NewString, NULL);
701 FreePool (NewString);
702 Find[1] = TRUE;
703 }
704
705 if (CompareGuid (&Record->DataRecordGuid, &gEfiProcessorSubClassGuid) &&
706 (DataHeader->RecordType == ProcessorVersionRecordType)
707 ) {
708 ProcessorVersion = (EFI_PROCESSOR_VERSION_DATA *) (DataHeader + 1);
709 GetProducerString (&Record->ProducerName, *ProcessorVersion, &NewString);
710 TokenToUpdate = STRING_TOKEN (STR_FRONT_PAGE_CPU_MODEL);
711 HiiSetString (gFrontPagePrivate.HiiHandle, TokenToUpdate, NewString, NULL);
712 FreePool (NewString);
713 Find[2] = TRUE;
714 }
715
716 if (CompareGuid (&Record->DataRecordGuid, &gEfiProcessorSubClassGuid) &&
717 (DataHeader->RecordType == ProcessorCoreFrequencyRecordType)
718 ) {
719 ProcessorFrequency = (EFI_PROCESSOR_CORE_FREQUENCY_DATA *) (DataHeader + 1);
720 ConvertProcessorToString (ProcessorFrequency, &NewString);
721 TokenToUpdate = STRING_TOKEN (STR_FRONT_PAGE_CPU_SPEED);
722 HiiSetString (gFrontPagePrivate.HiiHandle, TokenToUpdate, NewString, NULL);
723 FreePool (NewString);
724 Find[3] = TRUE;
725 }
726
727 if (CompareGuid (&Record->DataRecordGuid, &gEfiMemorySubClassGuid) &&
728 (DataHeader->RecordType == EFI_MEMORY_ARRAY_START_ADDRESS_RECORD_NUMBER)
729 ) {
730 MemoryArray = (EFI_MEMORY_ARRAY_START_ADDRESS_DATA *) (DataHeader + 1);
731 ConvertMemorySizeToString (
732 (UINT32)(RShiftU64((MemoryArray->MemoryArrayEndAddress - MemoryArray->MemoryArrayStartAddress + 1), 20)),
733 &NewString
734 );
735 TokenToUpdate = STRING_TOKEN (STR_FRONT_PAGE_MEMORY_SIZE);
736 HiiSetString (gFrontPagePrivate.HiiHandle, TokenToUpdate, NewString, NULL);
737 FreePool (NewString);
738 Find[4] = TRUE;
739 }
740 }
741 } while (!EFI_ERROR (Status) && (MonotonicCount != 0) && !(Find[0] && Find[1] && Find[2] && Find[3] && Find[4]));
742
743 return ;
744 }
745
746 /**
747 Function waits for a given event to fire, or for an optional timeout to expire.
748
749 @param Event The event to wait for
750 @param Timeout An optional timeout value in 100 ns units.
751
752 @retval EFI_SUCCESS Event fired before Timeout expired.
753 @retval EFI_TIME_OUT Timout expired before Event fired..
754
755 **/
756 EFI_STATUS
757 WaitForSingleEvent (
758 IN EFI_EVENT Event,
759 IN UINT64 Timeout OPTIONAL
760 )
761 {
762 EFI_STATUS Status;
763 UINTN Index;
764 EFI_EVENT TimerEvent;
765 EFI_EVENT WaitList[2];
766
767 if (Timeout != 0) {
768 //
769 // Create a timer event
770 //
771 Status = gBS->CreateEvent (EVT_TIMER, 0, NULL, NULL, &TimerEvent);
772 if (!EFI_ERROR (Status)) {
773 //
774 // Set the timer event
775 //
776 gBS->SetTimer (
777 TimerEvent,
778 TimerRelative,
779 Timeout
780 );
781
782 //
783 // Wait for the original event or the timer
784 //
785 WaitList[0] = Event;
786 WaitList[1] = TimerEvent;
787 Status = gBS->WaitForEvent (2, WaitList, &Index);
788 gBS->CloseEvent (TimerEvent);
789
790 //
791 // If the timer expired, change the return to timed out
792 //
793 if (!EFI_ERROR (Status) && Index == 1) {
794 Status = EFI_TIMEOUT;
795 }
796 }
797 } else {
798 //
799 // No timeout... just wait on the event
800 //
801 Status = gBS->WaitForEvent (1, &Event, &Index);
802 ASSERT (!EFI_ERROR (Status));
803 ASSERT (Index == 0);
804 }
805
806 return Status;
807 }
808
809 /**
810 Function show progress bar to wait for user input.
811
812
813 @param TimeoutDefault The fault time out value before the system continue to boot.
814
815 @retval EFI_SUCCESS User pressed some key except "Enter"
816 @retval EFI_TIME_OUT Timout expired or user press "Enter"
817
818 **/
819 EFI_STATUS
820 ShowProgress (
821 IN UINT16 TimeoutDefault
822 )
823 {
824 EFI_STATUS Status;
825 CHAR16 *TmpStr;
826 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground;
827 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;
828 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color;
829 EFI_INPUT_KEY Key;
830 UINT16 TimeoutRemain;
831
832 if (TimeoutDefault == 0) {
833 return EFI_TIMEOUT;
834 }
835
836 DEBUG ((EFI_D_INFO, "\n\nStart showing progress bar... Press any key to stop it! ...Zzz....\n"));
837
838 SetMem (&Foreground, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0xff);
839 SetMem (&Background, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0x0);
840 SetMem (&Color, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0xff);
841
842 //
843 // Clear the progress status bar first
844 //
845 TmpStr = GetStringById (STRING_TOKEN (STR_START_BOOT_OPTION));
846 if (TmpStr != NULL) {
847 PlatformBdsShowProgress (Foreground, Background, TmpStr, Color, 0, 0);
848 }
849
850 TimeoutRemain = TimeoutDefault;
851 while (TimeoutRemain != 0) {
852 DEBUG ((EFI_D_INFO, "Showing progress bar...Remaining %d second!\n", TimeoutRemain));
853
854 Status = WaitForSingleEvent (gST->ConIn->WaitForKey, ONE_SECOND);
855 if (Status != EFI_TIMEOUT) {
856 break;
857 }
858 TimeoutRemain--;
859
860 //
861 // Show progress
862 //
863 if (TmpStr != NULL) {
864 PlatformBdsShowProgress (
865 Foreground,
866 Background,
867 TmpStr,
868 Color,
869 ((TimeoutDefault - TimeoutRemain) * 100 / TimeoutDefault),
870 0
871 );
872 }
873 }
874 gBS->FreePool (TmpStr);
875
876 //
877 // Timeout expired
878 //
879 if (TimeoutRemain == 0) {
880 return EFI_TIMEOUT;
881 }
882
883 //
884 // User pressed some key
885 //
886 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
887 if (EFI_ERROR (Status)) {
888 return Status;
889 }
890
891 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
892 //
893 // User pressed enter, equivalent to select "continue"
894 //
895 return EFI_TIMEOUT;
896 }
897
898 return EFI_SUCCESS;
899 }
900
901 /**
902 This function is the main entry of the platform setup entry.
903 The function will present the main menu of the system setup,
904 this is the platform reference part and can be customize.
905
906
907 @param TimeoutDefault The fault time out value before the system
908 continue to boot.
909 @param ConnectAllHappened The indicater to check if the connect all have
910 already happended.
911
912 **/
913 VOID
914 PlatformBdsEnterFrontPage (
915 IN UINT16 TimeoutDefault,
916 IN BOOLEAN ConnectAllHappened
917 )
918 {
919 EFI_STATUS Status;
920
921 PERF_START (NULL, "BdsTimeOut", "BDS", 0);
922 //
923 // Indicate if we need connect all in the platform setup
924 //
925 if (ConnectAllHappened) {
926 gConnectAllHappened = TRUE;
927 }
928
929 if (TimeoutDefault != 0xffff) {
930 Status = ShowProgress (TimeoutDefault);
931
932 //
933 // Ensure screen is clear when switch Console from Graphics mode to Text mode
934 //
935 gST->ConOut->EnableCursor (gST->ConOut, TRUE);
936 gST->ConOut->ClearScreen (gST->ConOut);
937
938 if (EFI_ERROR (Status)) {
939 //
940 // Timeout or user press enter to continue
941 //
942 goto Exit;
943 }
944 }
945
946 do {
947
948 InitializeFrontPage (FALSE);
949
950 //
951 // Update Front Page strings
952 //
953 UpdateFrontPageStrings ();
954
955 gCallbackKey = 0;
956 Status = CallFrontPage ();
957
958 //
959 // If gCallbackKey is greater than 1 and less or equal to 5,
960 // it will lauch configuration utilities.
961 // 2 = set language
962 // 3 = boot manager
963 // 4 = device manager
964 // 5 = boot maintainenance manager
965 //
966 if (gCallbackKey != 0) {
967 REPORT_STATUS_CODE (
968 EFI_PROGRESS_CODE,
969 (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_PC_USER_SETUP)
970 );
971 }
972 //
973 // Based on the key that was set, we can determine what to do
974 //
975 switch (gCallbackKey) {
976 //
977 // The first 4 entries in the Front Page are to be GUARANTEED to remain constant so IHV's can
978 // describe to their customers in documentation how to find their setup information (namely
979 // under the device manager and specific buckets)
980 //
981 // These entries consist of the Continue, Select language, Boot Manager, and Device Manager
982 //
983 case FRONT_PAGE_KEY_CONTINUE:
984 //
985 // User hit continue
986 //
987 break;
988
989 case FRONT_PAGE_KEY_LANGUAGE:
990 //
991 // User made a language setting change - display front page again
992 //
993 break;
994
995 case FRONT_PAGE_KEY_BOOT_MANAGER:
996 //
997 // User chose to run the Boot Manager
998 //
999 CallBootManager ();
1000 break;
1001
1002 case FRONT_PAGE_KEY_DEVICE_MANAGER:
1003 //
1004 // Display the Device Manager
1005 //
1006 do {
1007 CallDeviceManager();
1008 } while (gCallbackKey == FRONT_PAGE_KEY_DEVICE_MANAGER);
1009 break;
1010
1011 case FRONT_PAGE_KEY_BOOT_MAINTAIN:
1012 //
1013 // Display the Boot Maintenance Manager
1014 //
1015 BdsStartBootMaint ();
1016 break;
1017 }
1018
1019 } while ((Status == EFI_SUCCESS) && (gCallbackKey != FRONT_PAGE_KEY_CONTINUE));
1020
1021 //
1022 //Will leave browser, check any reset required change is applied? if yes, reset system
1023 //
1024 SetupResetReminder ();
1025
1026 Exit:
1027 //
1028 // Automatically load current entry
1029 // Note: The following lines of code only execute when Auto boot
1030 // takes affect
1031 //
1032 PERF_END (NULL, "BdsTimeOut", "BDS", 0);
1033 }