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