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