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