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