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