53dcf82ea91999bdd94a84ec4deec0ae94df0152
[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 PlatformSupportedLanguages = GetEfiGlobalVariable (L"PlatformLangCodes");
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 CurrentLang = GetEfiGlobalVariable (L"PlatformLang");
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 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
966 if (EFI_ERROR (Status)) {
967 return Status;
968 }
969
970 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
971 //
972 // User pressed enter, equivalent to select "continue"
973 //
974 return EFI_TIMEOUT;
975 }
976
977 return EFI_SUCCESS;
978 }
979
980 /**
981 This function is the main entry of the platform setup entry.
982 The function will present the main menu of the system setup,
983 this is the platform reference part and can be customize.
984
985
986 @param TimeoutDefault The fault time out value before the system
987 continue to boot.
988 @param ConnectAllHappened The indicater to check if the connect all have
989 already happened.
990
991 **/
992 VOID
993 PlatformBdsEnterFrontPage (
994 IN UINT16 TimeoutDefault,
995 IN BOOLEAN ConnectAllHappened
996 )
997 {
998 EFI_STATUS Status;
999 EFI_STATUS StatusHotkey;
1000 EFI_BOOT_LOGO_PROTOCOL *BootLogo;
1001 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
1002 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut;
1003 UINTN BootTextColumn;
1004 UINTN BootTextRow;
1005
1006 GraphicsOutput = NULL;
1007 SimpleTextOut = NULL;
1008
1009 PERF_START (NULL, "BdsTimeOut", "BDS", 0);
1010 //
1011 // Indicate if we need connect all in the platform setup
1012 //
1013 if (ConnectAllHappened) {
1014 gConnectAllHappened = TRUE;
1015 }
1016
1017 if (!mModeInitialized) {
1018 //
1019 // After the console is ready, get current video resolution
1020 // and text mode before launching setup at first time.
1021 //
1022 Status = gBS->HandleProtocol (
1023 gST->ConsoleOutHandle,
1024 &gEfiGraphicsOutputProtocolGuid,
1025 (VOID**)&GraphicsOutput
1026 );
1027 if (EFI_ERROR (Status)) {
1028 GraphicsOutput = NULL;
1029 }
1030
1031 Status = gBS->HandleProtocol (
1032 gST->ConsoleOutHandle,
1033 &gEfiSimpleTextOutProtocolGuid,
1034 (VOID**)&SimpleTextOut
1035 );
1036 if (EFI_ERROR (Status)) {
1037 SimpleTextOut = NULL;
1038 }
1039
1040 if (GraphicsOutput != NULL) {
1041 //
1042 // Get current video resolution and text mode.
1043 //
1044 mBootHorizontalResolution = GraphicsOutput->Mode->Info->HorizontalResolution;
1045 mBootVerticalResolution = GraphicsOutput->Mode->Info->VerticalResolution;
1046 }
1047
1048 if (SimpleTextOut != NULL) {
1049 Status = SimpleTextOut->QueryMode (
1050 SimpleTextOut,
1051 SimpleTextOut->Mode->Mode,
1052 &BootTextColumn,
1053 &BootTextRow
1054 );
1055 mBootTextModeColumn = (UINT32)BootTextColumn;
1056 mBootTextModeRow = (UINT32)BootTextRow;
1057 }
1058
1059 //
1060 // Get user defined text mode for setup.
1061 //
1062 mSetupHorizontalResolution = PcdGet32 (PcdSetupVideoHorizontalResolution);
1063 mSetupVerticalResolution = PcdGet32 (PcdSetupVideoVerticalResolution);
1064 mSetupTextModeColumn = PcdGet32 (PcdSetupConOutColumn);
1065 mSetupTextModeRow = PcdGet32 (PcdSetupConOutRow);
1066
1067 mModeInitialized = TRUE;
1068 }
1069
1070
1071
1072 HotkeyBoot ();
1073 if (TimeoutDefault != 0xffff) {
1074 Status = ShowProgress (TimeoutDefault);
1075 StatusHotkey = HotkeyBoot ();
1076
1077 if (!FeaturePcdGet(PcdBootlogoOnlyEnable) || !EFI_ERROR(StatusHotkey)){
1078 //
1079 // Ensure screen is clear when switch Console from Graphics mode to Text mode
1080 // Skip it in normal boot
1081 //
1082 gST->ConOut->EnableCursor (gST->ConOut, TRUE);
1083 gST->ConOut->ClearScreen (gST->ConOut);
1084 }
1085
1086 if (EFI_ERROR (Status)) {
1087 //
1088 // Timeout or user press enter to continue
1089 //
1090 goto Exit;
1091 }
1092 }
1093
1094 //
1095 // Boot Logo is corrupted, report it using Boot Logo protocol.
1096 //
1097 Status = gBS->LocateProtocol (&gEfiBootLogoProtocolGuid, NULL, (VOID **) &BootLogo);
1098 if (!EFI_ERROR (Status) && (BootLogo != NULL)) {
1099 BootLogo->SetBootLogo (BootLogo, NULL, 0, 0, 0, 0);
1100 }
1101
1102 Status = EFI_SUCCESS;
1103 do {
1104 //
1105 // Set proper video resolution and text mode for setup
1106 //
1107 BdsSetConsoleMode (TRUE);
1108
1109 InitializeFrontPage (FALSE);
1110
1111 //
1112 // Update Front Page strings
1113 //
1114 UpdateFrontPageStrings ();
1115
1116 gCallbackKey = 0;
1117 CallFrontPage ();
1118
1119 //
1120 // If gCallbackKey is greater than 1 and less or equal to 5,
1121 // it will launch configuration utilities.
1122 // 2 = set language
1123 // 3 = boot manager
1124 // 4 = device manager
1125 // 5 = boot maintenance manager
1126 //
1127 if (gCallbackKey != 0) {
1128 REPORT_STATUS_CODE (
1129 EFI_PROGRESS_CODE,
1130 (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_PC_USER_SETUP)
1131 );
1132 }
1133 //
1134 // Based on the key that was set, we can determine what to do
1135 //
1136 switch (gCallbackKey) {
1137 //
1138 // The first 4 entries in the Front Page are to be GUARANTEED to remain constant so IHV's can
1139 // describe to their customers in documentation how to find their setup information (namely
1140 // under the device manager and specific buckets)
1141 //
1142 // These entries consist of the Continue, Select language, Boot Manager, and Device Manager
1143 //
1144 case FRONT_PAGE_KEY_CONTINUE:
1145 //
1146 // User hit continue
1147 //
1148 break;
1149
1150 case FRONT_PAGE_KEY_LANGUAGE:
1151 //
1152 // User made a language setting change - display front page again
1153 //
1154 break;
1155
1156 case FRONT_PAGE_KEY_BOOT_MANAGER:
1157 //
1158 // User chose to run the Boot Manager
1159 //
1160 CallBootManager ();
1161 break;
1162
1163 case FRONT_PAGE_KEY_DEVICE_MANAGER:
1164 //
1165 // Display the Device Manager
1166 //
1167 do {
1168 CallDeviceManager ();
1169 } while (gCallbackKey == FRONT_PAGE_KEY_DEVICE_MANAGER);
1170 break;
1171
1172 case FRONT_PAGE_KEY_BOOT_MAINTAIN:
1173 //
1174 // Display the Boot Maintenance Manager
1175 //
1176 BdsStartBootMaint ();
1177 break;
1178 }
1179
1180 } while ((Status == EFI_SUCCESS) && (gCallbackKey != FRONT_PAGE_KEY_CONTINUE));
1181
1182 //
1183 //Will leave browser, check any reset required change is applied? if yes, reset system
1184 //
1185 SetupResetReminder ();
1186
1187 Exit:
1188 //
1189 // Automatically load current entry
1190 // Note: The following lines of code only execute when Auto boot
1191 // takes affect
1192 //
1193 PERF_END (NULL, "BdsTimeOut", "BDS", 0);
1194 }
1195
1196 /**
1197 This function will change video resolution and text mode
1198 according to defined setup mode or defined boot mode
1199
1200 @param IsSetupMode Indicate mode is changed to setup mode or boot mode.
1201
1202 @retval EFI_SUCCESS Mode is changed successfully.
1203 @retval Others Mode failed to be changed.
1204
1205 **/
1206 EFI_STATUS
1207 EFIAPI
1208 BdsSetConsoleMode (
1209 BOOLEAN IsSetupMode
1210 )
1211 {
1212 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
1213 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut;
1214 UINTN SizeOfInfo;
1215 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
1216 UINT32 MaxGopMode;
1217 UINT32 MaxTextMode;
1218 UINT32 ModeNumber;
1219 UINT32 NewHorizontalResolution;
1220 UINT32 NewVerticalResolution;
1221 UINT32 NewColumns;
1222 UINT32 NewRows;
1223 UINTN HandleCount;
1224 EFI_HANDLE *HandleBuffer;
1225 EFI_STATUS Status;
1226 UINTN Index;
1227 UINTN CurrentColumn;
1228 UINTN CurrentRow;
1229
1230 MaxGopMode = 0;
1231 MaxTextMode = 0;
1232
1233 //
1234 // Get current video resolution and text mode
1235 //
1236 Status = gBS->HandleProtocol (
1237 gST->ConsoleOutHandle,
1238 &gEfiGraphicsOutputProtocolGuid,
1239 (VOID**)&GraphicsOutput
1240 );
1241 if (EFI_ERROR (Status)) {
1242 GraphicsOutput = NULL;
1243 }
1244
1245 Status = gBS->HandleProtocol (
1246 gST->ConsoleOutHandle,
1247 &gEfiSimpleTextOutProtocolGuid,
1248 (VOID**)&SimpleTextOut
1249 );
1250 if (EFI_ERROR (Status)) {
1251 SimpleTextOut = NULL;
1252 }
1253
1254 if ((GraphicsOutput == NULL) || (SimpleTextOut == NULL)) {
1255 return EFI_UNSUPPORTED;
1256 }
1257
1258 if (IsSetupMode) {
1259 //
1260 // The requried resolution and text mode is setup mode.
1261 //
1262 NewHorizontalResolution = mSetupHorizontalResolution;
1263 NewVerticalResolution = mSetupVerticalResolution;
1264 NewColumns = mSetupTextModeColumn;
1265 NewRows = mSetupTextModeRow;
1266 } else {
1267 //
1268 // The required resolution and text mode is boot mode.
1269 //
1270 NewHorizontalResolution = mBootHorizontalResolution;
1271 NewVerticalResolution = mBootVerticalResolution;
1272 NewColumns = mBootTextModeColumn;
1273 NewRows = mBootTextModeRow;
1274 }
1275
1276 if (GraphicsOutput != NULL) {
1277 MaxGopMode = GraphicsOutput->Mode->MaxMode;
1278 }
1279
1280 if (SimpleTextOut != NULL) {
1281 MaxTextMode = SimpleTextOut->Mode->MaxMode;
1282 }
1283
1284 //
1285 // 1. If current video resolution is same with required video resolution,
1286 // video resolution need not be changed.
1287 // 1.1. If current text mode is same with required text mode, text mode need not be changed.
1288 // 1.2. If current text mode is different from required text mode, text mode need be changed.
1289 // 2. If current video resolution is different from required video resolution, we need restart whole console drivers.
1290 //
1291 for (ModeNumber = 0; ModeNumber < MaxGopMode; ModeNumber++) {
1292 Status = GraphicsOutput->QueryMode (
1293 GraphicsOutput,
1294 ModeNumber,
1295 &SizeOfInfo,
1296 &Info
1297 );
1298 if (!EFI_ERROR (Status)) {
1299 if ((Info->HorizontalResolution == NewHorizontalResolution) &&
1300 (Info->VerticalResolution == NewVerticalResolution)) {
1301 if ((GraphicsOutput->Mode->Info->HorizontalResolution == NewHorizontalResolution) &&
1302 (GraphicsOutput->Mode->Info->VerticalResolution == NewVerticalResolution)) {
1303 //
1304 // Current resolution is same with required resolution, check if text mode need be set
1305 //
1306 Status = SimpleTextOut->QueryMode (SimpleTextOut, SimpleTextOut->Mode->Mode, &CurrentColumn, &CurrentRow);
1307 ASSERT_EFI_ERROR (Status);
1308 if (CurrentColumn == NewColumns && CurrentRow == NewRows) {
1309 //
1310 // If current text mode is same with required text mode. Do nothing
1311 //
1312 FreePool (Info);
1313 return EFI_SUCCESS;
1314 } else {
1315 //
1316 // If current text mode is different from requried text mode. Set new video mode
1317 //
1318 for (Index = 0; Index < MaxTextMode; Index++) {
1319 Status = SimpleTextOut->QueryMode (SimpleTextOut, Index, &CurrentColumn, &CurrentRow);
1320 if (!EFI_ERROR(Status)) {
1321 if ((CurrentColumn == NewColumns) && (CurrentRow == NewRows)) {
1322 //
1323 // Required text mode is supported, set it.
1324 //
1325 Status = SimpleTextOut->SetMode (SimpleTextOut, Index);
1326 ASSERT_EFI_ERROR (Status);
1327 //
1328 // Update text mode PCD.
1329 //
1330 PcdSet32 (PcdConOutColumn, mSetupTextModeColumn);
1331 PcdSet32 (PcdConOutRow, mSetupTextModeRow);
1332 FreePool (Info);
1333 return EFI_SUCCESS;
1334 }
1335 }
1336 }
1337 if (Index == MaxTextMode) {
1338 //
1339 // If requried text mode is not supported, return error.
1340 //
1341 FreePool (Info);
1342 return EFI_UNSUPPORTED;
1343 }
1344 }
1345 } else {
1346 //
1347 // If current video resolution is not same with the new one, set new video resolution.
1348 // In this case, the driver which produces simple text out need be restarted.
1349 //
1350 Status = GraphicsOutput->SetMode (GraphicsOutput, ModeNumber);
1351 if (!EFI_ERROR (Status)) {
1352 FreePool (Info);
1353 break;
1354 }
1355 }
1356 }
1357 FreePool (Info);
1358 }
1359 }
1360
1361 if (ModeNumber == MaxGopMode) {
1362 //
1363 // If the resolution is not supported, return error.
1364 //
1365 return EFI_UNSUPPORTED;
1366 }
1367
1368 //
1369 // Set PCD to Inform GraphicsConsole to change video resolution.
1370 // Set PCD to Inform Consplitter to change text mode.
1371 //
1372 PcdSet32 (PcdVideoHorizontalResolution, NewHorizontalResolution);
1373 PcdSet32 (PcdVideoVerticalResolution, NewVerticalResolution);
1374 PcdSet32 (PcdConOutColumn, NewColumns);
1375 PcdSet32 (PcdConOutRow, NewRows);
1376
1377
1378 //
1379 // Video mode is changed, so restart graphics console driver and higher level driver.
1380 // Reconnect graphics console driver and higher level driver.
1381 // Locate all the handles with GOP protocol and reconnect it.
1382 //
1383 Status = gBS->LocateHandleBuffer (
1384 ByProtocol,
1385 &gEfiSimpleTextOutProtocolGuid,
1386 NULL,
1387 &HandleCount,
1388 &HandleBuffer
1389 );
1390 if (!EFI_ERROR (Status)) {
1391 for (Index = 0; Index < HandleCount; Index++) {
1392 gBS->DisconnectController (HandleBuffer[Index], NULL, NULL);
1393 }
1394 for (Index = 0; Index < HandleCount; Index++) {
1395 gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE);
1396 }
1397 if (HandleBuffer != NULL) {
1398 FreePool (HandleBuffer);
1399 }
1400 }
1401
1402 return EFI_SUCCESS;
1403 }
1404