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