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