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