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