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