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