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