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