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