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