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