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