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