]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/BdsDxe/FrontPage.c
Remove the non-standard definition: GLYPH_WIDTH and GLYPH_HEIGHT. All reference to...
[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 #ifdef LANG_SUPPORT
143 CHAR8 OldLang[ISO_639_2_ENTRY_SIZE];
144 #endif
145 UINTN Index;
146 EFI_STATUS Status;
147
148 if ((Value == NULL) || (ActionRequest == NULL)) {
149 return EFI_INVALID_PARAMETER;
150 }
151
152 gCallbackKey = QuestionId;
153
154 //
155 // The first 4 entries in the Front Page are to be GUARANTEED to remain constant so IHV's can
156 // describe to their customers in documentation how to find their setup information (namely
157 // under the device manager and specific buckets)
158 //
159 switch (QuestionId) {
160 case FRONT_PAGE_KEY_CONTINUE:
161 //
162 // This is the continue - clear the screen and return an error to get out of FrontPage loop
163 //
164 break;
165
166 case FRONT_PAGE_KEY_LANGUAGE:
167 //
168 // Collect the languages from what our current Language support is based on our VFR
169 //
170 LanguageString = HiiLibGetSupportedLanguages (gFrontPagePrivate.HiiHandle);
171 ASSERT (LanguageString != NULL);
172
173 Index = 0;
174 LangCode = LanguageString;
175 while (*LangCode != 0) {
176 HiiLibGetNextLanguage (&LangCode, Lang);
177
178 if (Index == Value->u8) {
179 break;
180 }
181
182 Index++;
183 }
184
185 Status = gRT->SetVariable (
186 L"PlatformLang",
187 &gEfiGlobalVariableGuid,
188 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
189 AsciiStrSize (Lang),
190 Lang
191 );
192
193 #ifdef LANG_SUPPORT
194 //
195 // Set UEFI deprecated variable "Lang" for backwards compatibility
196 //
197 Status = ConvertRfc3066LanguageToIso639Language (Lang, OldLang);
198 if (!EFI_ERROR (Status)) {
199 Status = gRT->SetVariable (
200 L"Lang",
201 &gEfiGlobalVariableGuid,
202 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
203 ISO_639_2_ENTRY_SIZE,
204 OldLang
205 );
206 }
207 #endif
208
209 FreePool (LanguageString);
210 break;
211
212 case FRONT_PAGE_KEY_BOOT_MANAGER:
213 //
214 // Boot Manager
215 //
216 break;
217
218 case FRONT_PAGE_KEY_DEVICE_MANAGER:
219 //
220 // Device Manager
221 //
222 break;
223
224 case FRONT_PAGE_KEY_BOOT_MAINTAIN:
225 //
226 // Boot Maintenance Manager
227 //
228 break;
229
230 default:
231 gCallbackKey = 0;
232 break;
233 }
234
235 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;
236
237 return EFI_SUCCESS;
238 }
239
240 EFI_STATUS
241 InitializeFrontPage (
242 BOOLEAN ReInitializeStrings
243 )
244 /*++
245
246 Routine Description:
247 Initialize HII information for the FrontPage
248
249 Arguments:
250 None
251
252 Returns:
253 EFI_SUCCESS - The operation is successful.
254 EFI_DEVICE_ERROR - If the dynamic opcode creation failed.
255
256 --*/
257 {
258 EFI_STATUS Status;
259 EFI_HII_PACKAGE_LIST_HEADER *PackageList;
260 EFI_HII_UPDATE_DATA UpdateData;
261 IFR_OPTION *OptionList;
262 CHAR8 *LanguageString;
263 CHAR8 *LangCode;
264 CHAR8 Lang[RFC_3066_ENTRY_SIZE];
265 CHAR8 CurrentLang[RFC_3066_ENTRY_SIZE];
266 UINTN OptionCount;
267 EFI_STRING_ID Token;
268 CHAR16 *StringBuffer;
269 UINTN BufferSize;
270 UINTN Index;
271 EFI_HII_HANDLE HiiHandle;
272
273 if (!ReInitializeStrings) {
274 //
275 // Initialize the Device Manager
276 //
277 InitializeDeviceManager ();
278
279 //
280 // Initialize the Device Manager
281 //
282 InitializeBootManager ();
283
284 gCallbackKey = 0;
285
286 //
287 // Locate Hii relative protocols
288 //
289 Status = gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **) &gHiiDatabase);
290 if (EFI_ERROR (Status)) {
291 return Status;
292 }
293
294 Status = gBS->LocateProtocol (&gEfiHiiStringProtocolGuid, NULL, (VOID **) &gHiiString);
295 if (EFI_ERROR (Status)) {
296 return Status;
297 }
298
299 Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **) &gFormBrowser2);
300 if (EFI_ERROR (Status)) {
301 return Status;
302 }
303
304 Status = gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **) &gHiiConfigRouting);
305 if (EFI_ERROR (Status)) {
306 return Status;
307 }
308
309 //
310 // Create driver handle used by HII database
311 //
312 Status = HiiLibCreateHiiDriverHandle (&gFrontPagePrivate.DriverHandle);
313 if (EFI_ERROR (Status)) {
314 return Status;
315 }
316
317 //
318 // Install Config Access protocol to driver handle
319 //
320 Status = gBS->InstallProtocolInterface (
321 &gFrontPagePrivate.DriverHandle,
322 &gEfiHiiConfigAccessProtocolGuid,
323 EFI_NATIVE_INTERFACE,
324 &gFrontPagePrivate.ConfigAccess
325 );
326 ASSERT_EFI_ERROR (Status);
327
328 //
329 // Publish our HII data
330 //
331 PackageList = HiiLibPreparePackageList (2, &mFrontPageGuid, FrontPageVfrBin, BdsDxeStrings);
332 ASSERT (PackageList != NULL);
333
334 Status = gHiiDatabase->NewPackageList (
335 gHiiDatabase,
336 PackageList,
337 gFrontPagePrivate.DriverHandle,
338 &gFrontPagePrivate.HiiHandle
339 );
340 FreePool (PackageList);
341 if (EFI_ERROR (Status)) {
342 return Status;
343 }
344 }
345
346 //
347 // Get current language setting
348 //
349 HiiLibGetCurrentLanguage (CurrentLang);
350
351 //
352 // Allocate space for creation of UpdateData Buffer
353 //
354 UpdateData.BufferSize = 0x1000;
355 UpdateData.Data = AllocateZeroPool (0x1000);
356 ASSERT (UpdateData.Data != NULL);
357
358 OptionList = AllocateZeroPool (0x1000);
359 ASSERT (OptionList != NULL);
360
361 //
362 // Collect the languages from what our current Language support is based on our VFR
363 //
364 HiiHandle = gFrontPagePrivate.HiiHandle;
365 LanguageString = HiiLibGetSupportedLanguages (HiiHandle);
366 ASSERT (LanguageString != NULL);
367
368 OptionCount = 0;
369 LangCode = LanguageString;
370 while (*LangCode != 0) {
371 HiiLibGetNextLanguage (&LangCode, Lang);
372
373 if (gFrontPagePrivate.LanguageToken == NULL) {
374 //
375 // Get Language Name from String Package. The StringId of Printable Language
376 // Name is always 1 which is generated by StringGather Tool.
377 //
378 BufferSize = 0x100;
379 StringBuffer = AllocatePool (BufferSize);
380 Status = gHiiString->GetString (
381 gHiiString,
382 Lang,
383 HiiHandle,
384 PRINTABLE_LANGUAGE_NAME_STRING_ID,
385 StringBuffer,
386 &BufferSize,
387 NULL
388 );
389 if (Status == EFI_BUFFER_TOO_SMALL) {
390 FreePool (StringBuffer);
391 StringBuffer = AllocatePool (BufferSize);
392 Status = gHiiString->GetString (
393 gHiiString,
394 Lang,
395 HiiHandle,
396 PRINTABLE_LANGUAGE_NAME_STRING_ID,
397 StringBuffer,
398 &BufferSize,
399 NULL
400 );
401 }
402 ASSERT_EFI_ERROR (Status);
403
404 Token = 0;
405 Status = HiiLibNewString (HiiHandle, &Token, StringBuffer);
406 FreePool (StringBuffer);
407 } else {
408 Token = gFrontPagePrivate.LanguageToken[OptionCount];
409 }
410
411 if (AsciiStrCmp (Lang, CurrentLang) == 0) {
412 OptionList[OptionCount].Flags = EFI_IFR_OPTION_DEFAULT;
413 } else {
414 OptionList[OptionCount].Flags = 0;
415 }
416 OptionList[OptionCount].StringToken = Token;
417 OptionList[OptionCount].Value.u8 = (UINT8) OptionCount;
418
419 OptionCount++;
420 }
421
422 FreePool (LanguageString);
423
424 UpdateData.Offset = 0;
425 CreateOneOfOpCode (
426 FRONT_PAGE_KEY_LANGUAGE,
427 0,
428 0,
429 STRING_TOKEN (STR_LANGUAGE_SELECT),
430 STRING_TOKEN (STR_LANGUAGE_SELECT_HELP),
431 EFI_IFR_FLAG_CALLBACK,
432 EFI_IFR_NUMERIC_SIZE_1,
433 OptionList,
434 OptionCount,
435 &UpdateData
436 );
437
438 Status = IfrLibUpdateForm (
439 HiiHandle,
440 &mFrontPageGuid,
441 FRONT_PAGE_FORM_ID,
442 LABEL_SELECT_LANGUAGE,
443 FALSE,
444 &UpdateData
445 );
446
447 //
448 // Save the string Id for each language
449 //
450 gFrontPagePrivate.LanguageToken = AllocatePool (OptionCount * sizeof (EFI_STRING_ID));
451 ASSERT (gFrontPagePrivate.LanguageToken != NULL);
452 for (Index = 0; Index < OptionCount; Index++) {
453 gFrontPagePrivate.LanguageToken[Index] = OptionList[Index].StringToken;
454 }
455
456 FreePool (UpdateData.Data);
457 FreePool (OptionList);
458 return Status;
459 }
460
461 EFI_STATUS
462 CallFrontPage (
463 VOID
464 )
465 /*++
466
467 Routine Description:
468 Call the browser and display the front page
469
470 Arguments:
471 None
472
473 Returns:
474
475 --*/
476 {
477 EFI_STATUS Status;
478 EFI_BROWSER_ACTION_REQUEST ActionRequest;
479
480 //
481 // Begin waiting for USER INPUT
482 //
483 REPORT_STATUS_CODE (
484 EFI_PROGRESS_CODE,
485 (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_PC_INPUT_WAIT)
486 );
487
488
489 //
490 // Drop the TPL level from TPL_APPLICATION to TPL_APPLICATION
491 //
492 gBS->RestoreTPL (TPL_APPLICATION);
493
494 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
495 Status = gFormBrowser2->SendForm (
496 gFormBrowser2,
497 &gFrontPagePrivate.HiiHandle,
498 1,
499 NULL,
500 0,
501 NULL,
502 &ActionRequest
503 );
504 //
505 // Check whether user change any option setting which needs a reset to be effective
506 //
507 if (ActionRequest == EFI_BROWSER_ACTION_REQUEST_RESET) {
508 EnableResetRequired ();
509 }
510
511 gBS->RaiseTPL (TPL_APPLICATION);
512 return Status;
513 }
514
515 EFI_STATUS
516 GetProducerString (
517 IN EFI_GUID *ProducerGuid,
518 IN EFI_STRING_ID Token,
519 OUT CHAR16 **String
520 )
521 /*++
522
523 Routine Description:
524 Acquire the string associated with the ProducerGuid and return it.
525
526 Arguments:
527 ProducerGuid - The Guid to search the HII database for
528 Token - The token value of the string to extract
529 String - The string that is extracted
530
531 Returns:
532 EFI_SUCCESS - The function returns EFI_SUCCESS always.
533
534 --*/
535 {
536 EFI_STATUS Status;
537
538 Status = HiiLibGetStringFromToken (ProducerGuid, Token, String);
539 if (EFI_ERROR (Status)) {
540 *String = GetStringById (STRING_TOKEN (STR_MISSING_STRING));
541 }
542
543 return EFI_SUCCESS;
544 }
545
546 VOID
547 ConvertProcessorToString (
548 IN EFI_PROCESSOR_CORE_FREQUENCY_DATA *ProcessorFrequency,
549 OUT CHAR16 **String
550 )
551 /*++
552
553 Routine Description:
554 Convert Processor Frequency Data to a string
555
556 Arguments:
557 ProcessorFrequency - The frequency data to process
558 String - The string that is created
559
560 Returns:
561
562 --*/
563 {
564 CHAR16 *StringBuffer;
565 UINTN Index;
566 UINT32 FreqMhz;
567
568 if (ProcessorFrequency->Exponent >= 6) {
569 FreqMhz = ProcessorFrequency->Value;
570 for (Index = 0; Index < (UINTN) (ProcessorFrequency->Exponent - 6); Index++) {
571 FreqMhz *= 10;
572 }
573 } else {
574 FreqMhz = 0;
575 }
576
577 StringBuffer = AllocateZeroPool (0x20);
578 ASSERT (StringBuffer != NULL);
579 Index = UnicodeValueToString (StringBuffer, LEFT_JUSTIFY, FreqMhz / 1000, 3);
580 StrCat (StringBuffer, L".");
581 UnicodeValueToString (StringBuffer + Index + 1, PREFIX_ZERO, (FreqMhz % 1000) / 10, 2);
582 StrCat (StringBuffer, L" GHz");
583
584 *String = (CHAR16 *) StringBuffer;
585
586 return ;
587 }
588
589 VOID
590 ConvertMemorySizeToString (
591 IN UINT32 MemorySize,
592 OUT CHAR16 **String
593 )
594 /*++
595
596 Routine Description:
597 Convert Memory Size to a string
598
599 Arguments:
600 MemorySize - The size of the memory to process
601 String - The string that is created
602
603 Returns:
604
605 --*/
606 {
607 CHAR16 *StringBuffer;
608
609 StringBuffer = AllocateZeroPool (0x20);
610 ASSERT (StringBuffer != NULL);
611 UnicodeValueToString (StringBuffer, LEFT_JUSTIFY, MemorySize, 6);
612 StrCat (StringBuffer, L" MB RAM");
613
614 *String = (CHAR16 *) StringBuffer;
615
616 return ;
617 }
618
619 VOID
620 UpdateFrontPageStrings (
621 VOID
622 )
623 /*++
624
625 Routine Description:
626 Update the banner information for the Front Page based on DataHub information
627
628 Arguments:
629 None
630
631 Returns:
632
633 --*/
634 {
635 EFI_STATUS Status;
636 EFI_STRING_ID TokenToUpdate;
637 CHAR16 *NewString;
638 UINT64 MonotonicCount;
639 EFI_DATA_HUB_PROTOCOL *DataHub;
640 EFI_DATA_RECORD_HEADER *Record;
641 EFI_SUBCLASS_TYPE1_HEADER *DataHeader;
642 EFI_MISC_BIOS_VENDOR_DATA *BiosVendor;
643 EFI_MISC_SYSTEM_MANUFACTURER_DATA *SystemManufacturer;
644 EFI_PROCESSOR_VERSION_DATA *ProcessorVersion;
645 EFI_PROCESSOR_CORE_FREQUENCY_DATA *ProcessorFrequency;
646 EFI_MEMORY_ARRAY_START_ADDRESS_DATA *MemoryArray;
647 BOOLEAN Find[5];
648
649 ZeroMem (Find, sizeof (Find));
650
651 //
652 // Update Front Page strings
653 //
654 Status = gBS->LocateProtocol (
655 &gEfiDataHubProtocolGuid,
656 NULL,
657 (VOID **) &DataHub
658 );
659 ASSERT_EFI_ERROR (Status);
660
661 MonotonicCount = 0;
662 Record = NULL;
663 do {
664 Status = DataHub->GetNextRecord (DataHub, &MonotonicCount, NULL, &Record);
665 if (Record->DataRecordClass == EFI_DATA_RECORD_CLASS_DATA) {
666 DataHeader = (EFI_SUBCLASS_TYPE1_HEADER *) (Record + 1);
667 if (CompareGuid (&Record->DataRecordGuid, &gEfiMiscSubClassGuid) &&
668 (DataHeader->RecordType == EFI_MISC_BIOS_VENDOR_RECORD_NUMBER)
669 ) {
670 BiosVendor = (EFI_MISC_BIOS_VENDOR_DATA *) (DataHeader + 1);
671 GetProducerString (&Record->ProducerName, BiosVendor->BiosVersion, &NewString);
672 TokenToUpdate = STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION);
673 HiiLibSetString (gFrontPagePrivate.HiiHandle, TokenToUpdate, NewString);
674 FreePool (NewString);
675 Find[0] = TRUE;
676 }
677
678 if (CompareGuid (&Record->DataRecordGuid, &gEfiMiscSubClassGuid) &&
679 (DataHeader->RecordType == EFI_MISC_SYSTEM_MANUFACTURER_RECORD_NUMBER)
680 ) {
681 SystemManufacturer = (EFI_MISC_SYSTEM_MANUFACTURER_DATA *) (DataHeader + 1);
682 GetProducerString (&Record->ProducerName, SystemManufacturer->SystemProductName, &NewString);
683 TokenToUpdate = STRING_TOKEN (STR_FRONT_PAGE_COMPUTER_MODEL);
684 HiiLibSetString (gFrontPagePrivate.HiiHandle, TokenToUpdate, NewString);
685 FreePool (NewString);
686 Find[1] = TRUE;
687 }
688
689 if (CompareGuid (&Record->DataRecordGuid, &gEfiProcessorSubClassGuid) &&
690 (DataHeader->RecordType == ProcessorVersionRecordType)
691 ) {
692 ProcessorVersion = (EFI_PROCESSOR_VERSION_DATA *) (DataHeader + 1);
693 GetProducerString (&Record->ProducerName, *ProcessorVersion, &NewString);
694 TokenToUpdate = STRING_TOKEN (STR_FRONT_PAGE_CPU_MODEL);
695 HiiLibSetString (gFrontPagePrivate.HiiHandle, TokenToUpdate, NewString);
696 FreePool (NewString);
697 Find[2] = TRUE;
698 }
699
700 if (CompareGuid (&Record->DataRecordGuid, &gEfiProcessorSubClassGuid) &&
701 (DataHeader->RecordType == ProcessorCoreFrequencyRecordType)
702 ) {
703 ProcessorFrequency = (EFI_PROCESSOR_CORE_FREQUENCY_DATA *) (DataHeader + 1);
704 ConvertProcessorToString (ProcessorFrequency, &NewString);
705 TokenToUpdate = STRING_TOKEN (STR_FRONT_PAGE_CPU_SPEED);
706 HiiLibSetString (gFrontPagePrivate.HiiHandle, TokenToUpdate, NewString);
707 FreePool (NewString);
708 Find[3] = TRUE;
709 }
710
711 if (CompareGuid (&Record->DataRecordGuid, &gEfiMemorySubClassGuid) &&
712 (DataHeader->RecordType == EFI_MEMORY_ARRAY_START_ADDRESS_RECORD_NUMBER)
713 ) {
714 MemoryArray = (EFI_MEMORY_ARRAY_START_ADDRESS_DATA *) (DataHeader + 1);
715 ConvertMemorySizeToString (
716 (UINT32)(RShiftU64((MemoryArray->MemoryArrayEndAddress - MemoryArray->MemoryArrayStartAddress + 1), 20)),
717 &NewString
718 );
719 TokenToUpdate = STRING_TOKEN (STR_FRONT_PAGE_MEMORY_SIZE);
720 HiiLibSetString (gFrontPagePrivate.HiiHandle, TokenToUpdate, NewString);
721 FreePool (NewString);
722 Find[4] = TRUE;
723 }
724 }
725 } while (!EFI_ERROR (Status) && (MonotonicCount != 0) && !(Find[0] && Find[1] && Find[2] && Find[3] && Find[4]));
726
727 return ;
728 }
729
730 EFI_STATUS
731 WaitForSingleEvent (
732 IN EFI_EVENT Event,
733 IN UINT64 Timeout OPTIONAL
734 )
735 /*++
736
737 Routine Description:
738 Function waits for a given event to fire, or for an optional timeout to expire.
739
740 Arguments:
741 Event - The event to wait for
742 Timeout - An optional timeout value in 100 ns units.
743
744 Returns:
745 EFI_SUCCESS - Event fired before Timeout expired.
746 EFI_TIME_OUT - Timout expired before Event fired..
747
748 --*/
749 {
750 EFI_STATUS Status;
751 UINTN Index;
752 EFI_EVENT TimerEvent;
753 EFI_EVENT WaitList[2];
754
755 if (Timeout) {
756 //
757 // Create a timer event
758 //
759 Status = gBS->CreateEvent (EVT_TIMER, 0, NULL, NULL, &TimerEvent);
760 if (!EFI_ERROR (Status)) {
761 //
762 // Set the timer event
763 //
764 gBS->SetTimer (
765 TimerEvent,
766 TimerRelative,
767 Timeout
768 );
769
770 //
771 // Wait for the original event or the timer
772 //
773 WaitList[0] = Event;
774 WaitList[1] = TimerEvent;
775 Status = gBS->WaitForEvent (2, WaitList, &Index);
776 gBS->CloseEvent (TimerEvent);
777
778 //
779 // If the timer expired, change the return to timed out
780 //
781 if (!EFI_ERROR (Status) && Index == 1) {
782 Status = EFI_TIMEOUT;
783 }
784 }
785 } else {
786 //
787 // No timeout... just wait on the event
788 //
789 Status = gBS->WaitForEvent (1, &Event, &Index);
790 ASSERT (!EFI_ERROR (Status));
791 ASSERT (Index == 0);
792 }
793
794 return Status;
795 }
796
797 EFI_STATUS
798 ShowProgress (
799 IN UINT16 TimeoutDefault
800 )
801 /*++
802
803 Routine Description:
804 Function show progress bar to wait for user input.
805
806 Arguments:
807 TimeoutDefault - The fault time out value before the system
808 continue to boot.
809
810 Returns:
811 EFI_SUCCESS - User pressed some key except "Enter"
812 EFI_TIME_OUT - Timout expired or user press "Enter"
813
814 --*/
815 {
816 EFI_STATUS Status;
817 CHAR16 *TmpStr;
818 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground;
819 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;
820 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color;
821 EFI_INPUT_KEY Key;
822 UINT16 TimeoutRemain;
823
824 if (TimeoutDefault == 0) {
825 return EFI_TIMEOUT;
826 }
827
828 DEBUG ((EFI_D_INFO, "\n\nStart showing progress bar... Press any key to stop it! ...Zzz....\n"));
829
830 SetMem (&Foreground, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0xff);
831 SetMem (&Background, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0x0);
832 SetMem (&Color, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0xff);
833
834 //
835 // Clear the progress status bar first
836 //
837 TmpStr = GetStringById (STRING_TOKEN (STR_START_BOOT_OPTION));
838 if (TmpStr != NULL) {
839 PlatformBdsShowProgress (Foreground, Background, TmpStr, Color, 0, 0);
840 }
841
842 TimeoutRemain = TimeoutDefault;
843 while (TimeoutRemain != 0) {
844 DEBUG ((EFI_D_INFO, "Showing progress bar...Remaining %d second!\n", TimeoutRemain));
845
846 Status = WaitForSingleEvent (gST->ConIn->WaitForKey, ONE_SECOND);
847 if (Status != EFI_TIMEOUT) {
848 break;
849 }
850 TimeoutRemain--;
851
852 //
853 // Show progress
854 //
855 if (TmpStr != NULL) {
856 PlatformBdsShowProgress (
857 Foreground,
858 Background,
859 TmpStr,
860 Color,
861 ((TimeoutDefault - TimeoutRemain) * 100 / TimeoutDefault),
862 0
863 );
864 }
865 }
866 gBS->FreePool (TmpStr);
867
868 //
869 // Timeout expired
870 //
871 if (TimeoutRemain == 0) {
872 return EFI_TIMEOUT;
873 }
874
875 //
876 // User pressed some key
877 //
878 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
879 if (EFI_ERROR (Status)) {
880 return Status;
881 }
882
883 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
884 //
885 // User pressed enter, equivalent to select "continue"
886 //
887 return EFI_TIMEOUT;
888 }
889
890 return EFI_SUCCESS;
891 }
892
893 VOID
894 PlatformBdsEnterFrontPage (
895 IN UINT16 TimeoutDefault,
896 IN BOOLEAN ConnectAllHappened
897 )
898 /*++
899
900 Routine Description:
901 This function is the main entry of the platform setup entry.
902 The function will present the main menu of the system setup,
903 this is the platform reference part and can be customize.
904
905 Arguments:
906 TimeoutDefault - The fault time out value before the system
907 continue to boot.
908 ConnectAllHappened - The indicater to check if the connect all have
909 already happended.
910
911 Returns:
912 None
913
914 --*/
915 {
916 EFI_STATUS Status;
917 EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl;
918
919 PERF_START (0, "BdsTimeOut", "BDS", 0);
920 //
921 // Indicate if we need connect all in the platform setup
922 //
923 if (ConnectAllHappened) {
924 gConnectAllHappened = TRUE;
925 }
926
927 if (TimeoutDefault != 0xffff) {
928 gBS->RestoreTPL (TPL_APPLICATION);
929 Status = ShowProgress (TimeoutDefault);
930 gBS->RaiseTPL (TPL_APPLICATION);
931
932 if (EFI_ERROR (Status)) {
933 //
934 // Timeout or user press enter to continue
935 //
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 }