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