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