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