1. Correct Col * Row string
[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
5d7c1609 4Copyright (c) 2004 - 2009, Intel Corporation. <BR>\r
5c08e117 5All rights reserved. This 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
ad5a96ab 17#include "Language.h"\r
5c08e117 18\r
19EFI_GUID mFrontPageGuid = FRONT_PAGE_FORMSET_GUID;\r
20\r
21BOOLEAN gConnectAllHappened = FALSE;\r
22UINTN gCallbackKey;\r
23\r
24EFI_HII_DATABASE_PROTOCOL *gHiiDatabase;\r
25EFI_HII_STRING_PROTOCOL *gHiiString;\r
26EFI_FORM_BROWSER2_PROTOCOL *gFormBrowser2;\r
27EFI_HII_CONFIG_ROUTING_PROTOCOL *gHiiConfigRouting;\r
28\r
29FRONT_PAGE_CALLBACK_DATA gFrontPagePrivate = {\r
30 FRONT_PAGE_CALLBACK_DATA_SIGNATURE,\r
31 NULL,\r
32 NULL,\r
33 NULL,\r
34 {\r
35 FakeExtractConfig,\r
36 FakeRouteConfig,\r
37 FrontPageCallback\r
38 }\r
39};\r
40\r
f6f910dd 41HII_VENDOR_DEVICE_PATH mFrontPageHiiVendorDevicePath = {\r
42 {\r
43 {\r
44 HARDWARE_DEVICE_PATH,\r
45 HW_VENDOR_DP,\r
46 {\r
47 (UINT8) (sizeof (VENDOR_DEVICE_PATH)),\r
48 (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
49 }\r
50 },\r
51 //\r
52 // {8E6D99EE-7531-48f8-8745-7F6144468FF2}\r
53 //\r
54 { 0x8e6d99ee, 0x7531, 0x48f8, { 0x87, 0x45, 0x7f, 0x61, 0x44, 0x46, 0x8f, 0xf2 } }\r
55 },\r
56 {\r
57 END_DEVICE_PATH_TYPE,\r
58 END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
128efbbc 59 {\r
f6f910dd 60 (UINT8) (END_DEVICE_PATH_LENGTH),\r
61 (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)\r
62 }\r
63 }\r
64};\r
65\r
5c08e117 66/**\r
67 This function allows a caller to extract the current configuration for one\r
68 or more named elements from the target driver.\r
69\r
70\r
71 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
72 @param Request A null-terminated Unicode string in <ConfigRequest> format.\r
73 @param Progress On return, points to a character in the Request string.\r
74 Points to the string's null terminator if request was successful.\r
75 Points to the most recent '&' before the first failing name/value\r
76 pair (or the beginning of the string if the failure is in the\r
77 first name/value pair) if the request was not successful.\r
78 @param Results A null-terminated Unicode string in <ConfigAltResp> format which\r
79 has all values filled in for the names in the Request string.\r
80 String to be allocated by the called function.\r
81\r
82 @retval EFI_SUCCESS The Results is filled with the requested values.\r
83 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.\r
84 @retval EFI_INVALID_PARAMETER Request is NULL, illegal syntax, or unknown name.\r
85 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.\r
86\r
87**/\r
88EFI_STATUS\r
89EFIAPI\r
90FakeExtractConfig (\r
91 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
92 IN CONST EFI_STRING Request,\r
93 OUT EFI_STRING *Progress,\r
94 OUT EFI_STRING *Results\r
95 )\r
96{\r
dedfc3bb
LG
97 if (Request == NULL || Progress == NULL || Results == NULL) {\r
98 return EFI_INVALID_PARAMETER;\r
99 }\r
cdcc36ae 100 *Progress = Request;\r
5c08e117 101 return EFI_NOT_FOUND;\r
102}\r
103\r
104/**\r
105 This function processes the results of changes in configuration.\r
106\r
107\r
108 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
109 @param Configuration A null-terminated Unicode string in <ConfigResp> format.\r
110 @param Progress A pointer to a string filled in with the offset of the most\r
111 recent '&' before the first failing name/value pair (or the\r
112 beginning of the string if the failure is in the first\r
113 name/value pair) or the terminating NULL if all was successful.\r
114\r
115 @retval EFI_SUCCESS The Results is processed successfully.\r
116 @retval EFI_INVALID_PARAMETER Configuration is NULL.\r
117 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.\r
118\r
119**/\r
120EFI_STATUS\r
121EFIAPI\r
122FakeRouteConfig (\r
123 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
124 IN CONST EFI_STRING Configuration,\r
125 OUT EFI_STRING *Progress\r
126 )\r
127{\r
dedfc3bb 128 if (Configuration == NULL || Progress == NULL) {\r
cdcc36ae
LG
129 return EFI_INVALID_PARAMETER;\r
130 }\r
131\r
dedfc3bb
LG
132 *Progress = Configuration;\r
133 if (!HiiIsConfigHdrMatch (Configuration, &mBootMaintGuid, mBootMaintStorageName)\r
134 && !HiiIsConfigHdrMatch (Configuration, &mFileExplorerGuid, mFileExplorerStorageName)) {\r
135 return EFI_NOT_FOUND;\r
cdcc36ae
LG
136 }\r
137\r
dedfc3bb
LG
138 *Progress = Configuration + StrLen (Configuration);\r
139 return EFI_SUCCESS;\r
5c08e117 140}\r
141\r
142/**\r
143 This function processes the results of changes in configuration.\r
144\r
145\r
146 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
147 @param Action Specifies the type of action taken by the browser.\r
148 @param QuestionId A unique value which is sent to the original exporting driver\r
149 so that it can identify the type of data to expect.\r
150 @param Type The type of value for the question.\r
151 @param Value A pointer to the data being sent to the original exporting driver.\r
152 @param ActionRequest On return, points to the action requested by the callback function.\r
153\r
154 @retval EFI_SUCCESS The callback successfully handled the action.\r
155 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.\r
156 @retval EFI_DEVICE_ERROR The variable could not be saved.\r
157 @retval EFI_UNSUPPORTED The specified Action is not supported by the callback.\r
158\r
159**/\r
160EFI_STATUS\r
161EFIAPI\r
162FrontPageCallback (\r
163 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
164 IN EFI_BROWSER_ACTION Action,\r
165 IN EFI_QUESTION_ID QuestionId,\r
166 IN UINT8 Type,\r
167 IN EFI_IFR_TYPE_VALUE *Value,\r
168 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r
169 )\r
170{\r
171 CHAR8 *LanguageString;\r
172 CHAR8 *LangCode;\r
a3a795af 173 CHAR8 *Lang;\r
5c08e117 174 UINTN Index;\r
175 EFI_STATUS Status;\r
a3a795af 176 CHAR8 *PlatformSupportedLanguages;\r
177 CHAR8 *BestLanguage;\r
5c08e117 178\r
179 if ((Value == NULL) || (ActionRequest == NULL)) {\r
180 return EFI_INVALID_PARAMETER;\r
181 }\r
182\r
183 gCallbackKey = QuestionId;\r
184\r
185 //\r
186 // The first 4 entries in the Front Page are to be GUARANTEED to remain constant so IHV's can\r
187 // describe to their customers in documentation how to find their setup information (namely\r
188 // under the device manager and specific buckets)\r
189 //\r
190 switch (QuestionId) {\r
191 case FRONT_PAGE_KEY_CONTINUE:\r
192 //\r
193 // This is the continue - clear the screen and return an error to get out of FrontPage loop\r
194 //\r
195 break;\r
196\r
197 case FRONT_PAGE_KEY_LANGUAGE:\r
198 //\r
199 // Collect the languages from what our current Language support is based on our VFR\r
200 //\r
cb7d01c0 201 LanguageString = HiiGetSupportedLanguages (gFrontPagePrivate.HiiHandle);\r
5c08e117 202 ASSERT (LanguageString != NULL);\r
a3a795af 203 //\r
204 // Allocate working buffer for RFC 4646 language in supported LanguageString.\r
205 //\r
206 Lang = AllocatePool (AsciiStrSize (LanguageString));\r
207 ASSERT (Lang != NULL);\r
128efbbc 208\r
5c08e117 209 Index = 0;\r
210 LangCode = LanguageString;\r
211 while (*LangCode != 0) {\r
0f268521 212 GetNextLanguage (&LangCode, Lang);\r
5c08e117 213\r
214 if (Index == Value->u8) {\r
215 break;\r
216 }\r
217\r
218 Index++;\r
219 }\r
220\r
a3a795af 221 PlatformSupportedLanguages = GetEfiGlobalVariable (L"PlatformLangCodes");\r
222 if (PlatformSupportedLanguages == NULL) {\r
223 PlatformSupportedLanguages = AllocateCopyPool (\r
224 AsciiStrSize ((CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLangCodes)),\r
225 (CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLangCodes)\r
226 );\r
227 ASSERT (PlatformSupportedLanguages != NULL);\r
228 }\r
128efbbc 229\r
a3a795af 230 //\r
231 // Select the best language in platform supported Language.\r
232 //\r
233 BestLanguage = GetBestLanguage (\r
234 PlatformSupportedLanguages,\r
235 FALSE,\r
236 Lang,\r
237 NULL\r
238 );\r
239 if (BestLanguage != NULL) {\r
240 Status = gRT->SetVariable (\r
241 L"PlatformLang",\r
242 &gEfiGlobalVariableGuid,\r
243 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
244 AsciiStrSize (BestLanguage),\r
245 Lang\r
246 );\r
b96c2106 247 ASSERT_EFI_ERROR(Status);\r
a3a795af 248 FreePool (BestLanguage);\r
d357145f 249 } else {\r
250 ASSERT (FALSE);\r
5c08e117 251 }\r
d357145f 252\r
a3a795af 253 FreePool (PlatformSupportedLanguages);\r
254 FreePool (Lang);\r
5c08e117 255 FreePool (LanguageString);\r
256 break;\r
257\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 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;\r
282\r
283 return EFI_SUCCESS;\r
284}\r
285\r
286/**\r
287 Initialize HII information for the FrontPage\r
288\r
289\r
290 @param InitializeHiiData TRUE if HII elements need to be initialized.\r
291\r
292 @retval EFI_SUCCESS The operation is successful.\r
293 @retval EFI_DEVICE_ERROR If the dynamic opcode creation failed.\r
294\r
295**/\r
296EFI_STATUS\r
297InitializeFrontPage (\r
298 IN BOOLEAN InitializeHiiData\r
299 )\r
300{\r
301 EFI_STATUS Status;\r
5c08e117 302 CHAR8 *LanguageString;\r
303 CHAR8 *LangCode;\r
a3a795af 304 CHAR8 *Lang;\r
305 CHAR8 *CurrentLang;\r
306 CHAR8 *BestLanguage;\r
5c08e117 307 UINTN OptionCount;\r
5c08e117 308 CHAR16 *StringBuffer;\r
309 UINTN BufferSize;\r
5c08e117 310 EFI_HII_HANDLE HiiHandle;\r
75bf9d0e
LG
311 VOID *OptionsOpCodeHandle;\r
312 VOID *StartOpCodeHandle;\r
313 VOID *EndOpCodeHandle;\r
314 EFI_IFR_GUID_LABEL *StartLabel;\r
315 EFI_IFR_GUID_LABEL *EndLabel;\r
316 BOOLEAN FirstFlag;\r
5c08e117 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 (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **) &gHiiDatabase);\r
335 if (EFI_ERROR (Status)) {\r
336 return Status;\r
337 }\r
338\r
339 Status = gBS->LocateProtocol (&gEfiHiiStringProtocolGuid, NULL, (VOID **) &gHiiString);\r
340 if (EFI_ERROR (Status)) {\r
341 return Status;\r
342 }\r
343\r
344 Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **) &gFormBrowser2);\r
345 if (EFI_ERROR (Status)) {\r
346 return Status;\r
347 }\r
348\r
349 Status = gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **) &gHiiConfigRouting);\r
350 if (EFI_ERROR (Status)) {\r
351 return Status;\r
352 }\r
353\r
354 //\r
f6f910dd 355 // Install Device Path Protocol and Config Access protocol to driver handle\r
5c08e117 356 //\r
f6f910dd 357 Status = gBS->InstallMultipleProtocolInterfaces (\r
5c08e117 358 &gFrontPagePrivate.DriverHandle,\r
f6f910dd 359 &gEfiDevicePathProtocolGuid,\r
360 &mFrontPageHiiVendorDevicePath,\r
5c08e117 361 &gEfiHiiConfigAccessProtocolGuid,\r
f6f910dd 362 &gFrontPagePrivate.ConfigAccess,\r
363 NULL\r
5c08e117 364 );\r
365 ASSERT_EFI_ERROR (Status);\r
366\r
367 //\r
368 // Publish our HII data\r
369 //\r
cb7d01c0 370 gFrontPagePrivate.HiiHandle = HiiAddPackages (\r
371 &mFrontPageGuid,\r
372 gFrontPagePrivate.DriverHandle,\r
373 FrontPageVfrBin,\r
374 BdsDxeStrings,\r
375 NULL\r
376 );\r
377 if (gFrontPagePrivate.HiiHandle == NULL) {\r
378 return EFI_OUT_OF_RESOURCES;\r
5c08e117 379 }\r
380 }\r
381\r
5c08e117 382\r
383 //\r
75bf9d0e 384 // Init OpCode Handle and Allocate space for creation of UpdateData Buffer\r
5c08e117 385 //\r
75bf9d0e
LG
386 StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r
387 ASSERT (StartOpCodeHandle != NULL);\r
5c08e117 388\r
75bf9d0e
LG
389 EndOpCodeHandle = HiiAllocateOpCodeHandle ();\r
390 ASSERT (EndOpCodeHandle != NULL);\r
391\r
392 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();\r
393 ASSERT (OptionsOpCodeHandle != NULL);\r
394 //\r
395 // Create Hii Extend Label OpCode as the start opcode\r
396 //\r
397 StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
398 StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
399 StartLabel->Number = LABEL_SELECT_LANGUAGE;\r
400\r
401 //\r
402 // Create Hii Extend Label OpCode as the end opcode\r
403 //\r
404 EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
405 EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
406 EndLabel->Number = LABEL_END;\r
5c08e117 407\r
408 //\r
409 // Collect the languages from what our current Language support is based on our VFR\r
410 //\r
411 HiiHandle = gFrontPagePrivate.HiiHandle;\r
cb7d01c0 412 LanguageString = HiiGetSupportedLanguages (HiiHandle);\r
5c08e117 413 ASSERT (LanguageString != NULL);\r
a3a795af 414 //\r
415 // Allocate working buffer for RFC 4646 language in supported LanguageString.\r
416 //\r
417 Lang = AllocatePool (AsciiStrSize (LanguageString));\r
418 ASSERT (Lang != NULL);\r
419\r
420 CurrentLang = GetEfiGlobalVariable (L"PlatformLang");\r
421 //\r
422 // Select the best language in LanguageString as the default one.\r
423 //\r
424 BestLanguage = GetBestLanguage (\r
425 LanguageString,\r
426 FALSE,\r
427 (CurrentLang != NULL) ? CurrentLang : "",\r
428 (CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLang),\r
429 LanguageString,\r
430 NULL\r
431 );\r
432 //\r
433 // BestLanguage must be selected as it is the first language in LanguageString by default\r
434 //\r
435 ASSERT (BestLanguage != NULL);\r
5c08e117 436\r
75bf9d0e
LG
437 OptionCount = 0;\r
438 LangCode = LanguageString;\r
439 FirstFlag = FALSE;\r
128efbbc 440\r
75bf9d0e
LG
441 if (gFrontPagePrivate.LanguageToken == NULL) {\r
442 while (*LangCode != 0) {\r
0b3f5a4d 443 GetNextLanguage (&LangCode, Lang);\r
75bf9d0e
LG
444 OptionCount ++;\r
445 }\r
446 gFrontPagePrivate.LanguageToken = AllocatePool (OptionCount * sizeof (EFI_STRING_ID));\r
447 ASSERT (gFrontPagePrivate.LanguageToken != NULL);\r
448 FirstFlag = TRUE;\r
449 }\r
450\r
5c08e117 451 OptionCount = 0;\r
452 LangCode = LanguageString;\r
453 while (*LangCode != 0) {\r
0f268521 454 GetNextLanguage (&LangCode, Lang);\r
5c08e117 455\r
75bf9d0e 456 if (FirstFlag) {\r
5c08e117 457 //\r
458 // Get Language Name from String Package. The StringId of Printable Language\r
459 // Name is always 1 which is generated by StringGather Tool.\r
460 //\r
461 BufferSize = 0x100;\r
462 StringBuffer = AllocatePool (BufferSize);\r
463 Status = gHiiString->GetString (\r
464 gHiiString,\r
465 Lang,\r
466 HiiHandle,\r
467 PRINTABLE_LANGUAGE_NAME_STRING_ID,\r
468 StringBuffer,\r
469 &BufferSize,\r
470 NULL\r
471 );\r
472 if (Status == EFI_BUFFER_TOO_SMALL) {\r
473 FreePool (StringBuffer);\r
474 StringBuffer = AllocatePool (BufferSize);\r
475 Status = gHiiString->GetString (\r
476 gHiiString,\r
477 Lang,\r
478 HiiHandle,\r
479 PRINTABLE_LANGUAGE_NAME_STRING_ID,\r
480 StringBuffer,\r
481 &BufferSize,\r
482 NULL\r
483 );\r
484 }\r
485 ASSERT_EFI_ERROR (Status);\r
486\r
75bf9d0e
LG
487 //\r
488 // Save the string Id for each language\r
489 //\r
490 gFrontPagePrivate.LanguageToken[OptionCount] = HiiSetString (HiiHandle, 0, StringBuffer, NULL);\r
5c08e117 491 FreePool (StringBuffer);\r
5c08e117 492 }\r
493\r
a3a795af 494 if (AsciiStrCmp (Lang, BestLanguage) == 0) {\r
75bf9d0e
LG
495 HiiCreateOneOfOptionOpCode (\r
496 OptionsOpCodeHandle,\r
497 gFrontPagePrivate.LanguageToken[OptionCount],\r
498 EFI_IFR_OPTION_DEFAULT,\r
499 EFI_IFR_NUMERIC_SIZE_1,\r
500 (UINT8) OptionCount\r
501 );\r
5c08e117 502 } else {\r
75bf9d0e
LG
503 HiiCreateOneOfOptionOpCode (\r
504 OptionsOpCodeHandle,\r
505 gFrontPagePrivate.LanguageToken[OptionCount],\r
506 0,\r
507 EFI_IFR_NUMERIC_SIZE_1,\r
508 (UINT8) OptionCount\r
509 );\r
5c08e117 510 }\r
5c08e117 511\r
512 OptionCount++;\r
513 }\r
514\r
a3a795af 515 if (CurrentLang != NULL) {\r
516 FreePool (CurrentLang);\r
517 }\r
518 FreePool (BestLanguage);\r
519 FreePool (Lang);\r
5c08e117 520 FreePool (LanguageString);\r
521\r
75bf9d0e
LG
522 HiiCreateOneOfOpCode (\r
523 StartOpCodeHandle,\r
5c08e117 524 FRONT_PAGE_KEY_LANGUAGE,\r
525 0,\r
526 0,\r
527 STRING_TOKEN (STR_LANGUAGE_SELECT),\r
528 STRING_TOKEN (STR_LANGUAGE_SELECT_HELP),\r
529 EFI_IFR_FLAG_CALLBACK,\r
530 EFI_IFR_NUMERIC_SIZE_1,\r
75bf9d0e
LG
531 OptionsOpCodeHandle,\r
532 NULL\r
5c08e117 533 );\r
534\r
75bf9d0e 535 Status = HiiUpdateForm (\r
5c08e117 536 HiiHandle,\r
537 &mFrontPageGuid,\r
538 FRONT_PAGE_FORM_ID,\r
75bf9d0e
LG
539 StartOpCodeHandle, // LABEL_SELECT_LANGUAGE\r
540 EndOpCodeHandle // LABEL_END\r
5c08e117 541 );\r
542\r
75bf9d0e
LG
543 HiiFreeOpCodeHandle (StartOpCodeHandle);\r
544 HiiFreeOpCodeHandle (EndOpCodeHandle);\r
545 HiiFreeOpCodeHandle (OptionsOpCodeHandle);\r
5c08e117 546 return Status;\r
547}\r
548\r
549/**\r
550 Call the browser and display the front page\r
551\r
552 @return Status code that will be returned by\r
553 EFI_FORM_BROWSER2_PROTOCOL.SendForm ().\r
554\r
555**/\r
556EFI_STATUS\r
557CallFrontPage (\r
558 VOID\r
559 )\r
560{\r
561 EFI_STATUS Status;\r
562 EFI_BROWSER_ACTION_REQUEST ActionRequest;\r
563\r
564 //\r
565 // Begin waiting for USER INPUT\r
566 //\r
567 REPORT_STATUS_CODE (\r
568 EFI_PROGRESS_CODE,\r
569 (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_PC_INPUT_WAIT)\r
570 );\r
571\r
572 ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;\r
573 Status = gFormBrowser2->SendForm (\r
574 gFormBrowser2,\r
575 &gFrontPagePrivate.HiiHandle,\r
576 1,\r
f0da9ffb 577 &mFrontPageGuid,\r
5c08e117 578 0,\r
579 NULL,\r
580 &ActionRequest\r
581 );\r
582 //\r
583 // Check whether user change any option setting which needs a reset to be effective\r
584 //\r
585 if (ActionRequest == EFI_BROWSER_ACTION_REQUEST_RESET) {\r
586 EnableResetRequired ();\r
587 }\r
588\r
589 return Status;\r
590}\r
591\r
592/**\r
593 Acquire the string associated with the ProducerGuid and return it.\r
594\r
595\r
596 @param ProducerGuid The Guid to search the HII database for\r
597 @param Token The token value of the string to extract\r
598 @param String The string that is extracted\r
599\r
600 @retval EFI_SUCCESS The function returns EFI_SUCCESS always.\r
601\r
602**/\r
603EFI_STATUS\r
604GetProducerString (\r
605 IN EFI_GUID *ProducerGuid,\r
606 IN EFI_STRING_ID Token,\r
607 OUT CHAR16 **String\r
608 )\r
609{\r
cb7d01c0 610 EFI_STRING TmpString;\r
5c08e117 611\r
cb7d01c0 612 TmpString = HiiGetPackageString (ProducerGuid, Token, NULL);\r
613 if (TmpString == NULL) {\r
5c08e117 614 *String = GetStringById (STRING_TOKEN (STR_MISSING_STRING));\r
cb7d01c0 615 } else {\r
616 *String = TmpString;\r
5c08e117 617 }\r
618\r
619 return EFI_SUCCESS;\r
620}\r
621\r
622/**\r
13078b3f 623 Convert Processor Frequency Data to a string.\r
5c08e117 624\r
625 @param ProcessorFrequency The frequency data to process\r
626 @param String The string that is created\r
627\r
628**/\r
629VOID\r
630ConvertProcessorToString (\r
631 IN EFI_PROCESSOR_CORE_FREQUENCY_DATA *ProcessorFrequency,\r
632 OUT CHAR16 **String\r
633 )\r
634{\r
635 CHAR16 *StringBuffer;\r
636 UINTN Index;\r
637 UINT32 FreqMhz;\r
638\r
639 if (ProcessorFrequency->Exponent >= 6) {\r
640 FreqMhz = ProcessorFrequency->Value;\r
641 for (Index = 0; Index < (UINTN) (ProcessorFrequency->Exponent - 6); Index++) {\r
642 FreqMhz *= 10;\r
643 }\r
644 } else {\r
645 FreqMhz = 0;\r
646 }\r
647\r
648 StringBuffer = AllocateZeroPool (0x20);\r
649 ASSERT (StringBuffer != NULL);\r
650 Index = UnicodeValueToString (StringBuffer, LEFT_JUSTIFY, FreqMhz / 1000, 3);\r
651 StrCat (StringBuffer, L".");\r
652 UnicodeValueToString (StringBuffer + Index + 1, PREFIX_ZERO, (FreqMhz % 1000) / 10, 2);\r
653 StrCat (StringBuffer, L" GHz");\r
654\r
655 *String = (CHAR16 *) StringBuffer;\r
656\r
657 return ;\r
658}\r
659\r
660/**\r
661 Convert Memory Size to a string.\r
662\r
663 @param MemorySize The size of the memory to process\r
664 @param String The string that is created\r
665\r
666**/\r
667VOID\r
668ConvertMemorySizeToString (\r
669 IN UINT32 MemorySize,\r
670 OUT CHAR16 **String\r
671 )\r
672{\r
673 CHAR16 *StringBuffer;\r
674\r
675 StringBuffer = AllocateZeroPool (0x20);\r
676 ASSERT (StringBuffer != NULL);\r
677 UnicodeValueToString (StringBuffer, LEFT_JUSTIFY, MemorySize, 6);\r
678 StrCat (StringBuffer, L" MB RAM");\r
679\r
680 *String = (CHAR16 *) StringBuffer;\r
681\r
682 return ;\r
683}\r
684\r
685/**\r
686 Update the banner information for the Front Page based on DataHub information.\r
687\r
688**/\r
689VOID\r
690UpdateFrontPageStrings (\r
691 VOID\r
692 )\r
693{\r
694 EFI_STATUS Status;\r
695 EFI_STRING_ID TokenToUpdate;\r
696 CHAR16 *NewString;\r
697 UINT64 MonotonicCount;\r
698 EFI_DATA_HUB_PROTOCOL *DataHub;\r
699 EFI_DATA_RECORD_HEADER *Record;\r
700 EFI_SUBCLASS_TYPE1_HEADER *DataHeader;\r
701 EFI_MISC_BIOS_VENDOR_DATA *BiosVendor;\r
702 EFI_MISC_SYSTEM_MANUFACTURER_DATA *SystemManufacturer;\r
703 EFI_PROCESSOR_VERSION_DATA *ProcessorVersion;\r
704 EFI_PROCESSOR_CORE_FREQUENCY_DATA *ProcessorFrequency;\r
705 EFI_MEMORY_ARRAY_START_ADDRESS_DATA *MemoryArray;\r
706 BOOLEAN Find[5];\r
707\r
708 ZeroMem (Find, sizeof (Find));\r
709\r
710 //\r
711 // Update Front Page strings\r
712 //\r
713 Status = gBS->LocateProtocol (\r
714 &gEfiDataHubProtocolGuid,\r
715 NULL,\r
716 (VOID **) &DataHub\r
717 );\r
718 ASSERT_EFI_ERROR (Status);\r
719\r
720 MonotonicCount = 0;\r
721 Record = NULL;\r
722 do {\r
723 Status = DataHub->GetNextRecord (DataHub, &MonotonicCount, NULL, &Record);\r
b55f8b01
LG
724 if (EFI_ERROR (Status) || Record == NULL) {\r
725 break;\r
726 }\r
5c08e117 727 if (Record->DataRecordClass == EFI_DATA_RECORD_CLASS_DATA) {\r
728 DataHeader = (EFI_SUBCLASS_TYPE1_HEADER *) (Record + 1);\r
729 if (CompareGuid (&Record->DataRecordGuid, &gEfiMiscSubClassGuid) &&\r
730 (DataHeader->RecordType == EFI_MISC_BIOS_VENDOR_RECORD_NUMBER)\r
731 ) {\r
732 BiosVendor = (EFI_MISC_BIOS_VENDOR_DATA *) (DataHeader + 1);\r
733 GetProducerString (&Record->ProducerName, BiosVendor->BiosVersion, &NewString);\r
734 TokenToUpdate = STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION);\r
cb7d01c0 735 HiiSetString (gFrontPagePrivate.HiiHandle, TokenToUpdate, NewString, NULL);\r
5c08e117 736 FreePool (NewString);\r
737 Find[0] = TRUE;\r
738 }\r
739\r
740 if (CompareGuid (&Record->DataRecordGuid, &gEfiMiscSubClassGuid) &&\r
741 (DataHeader->RecordType == EFI_MISC_SYSTEM_MANUFACTURER_RECORD_NUMBER)\r
742 ) {\r
743 SystemManufacturer = (EFI_MISC_SYSTEM_MANUFACTURER_DATA *) (DataHeader + 1);\r
744 GetProducerString (&Record->ProducerName, SystemManufacturer->SystemProductName, &NewString);\r
745 TokenToUpdate = STRING_TOKEN (STR_FRONT_PAGE_COMPUTER_MODEL);\r
cb7d01c0 746 HiiSetString (gFrontPagePrivate.HiiHandle, TokenToUpdate, NewString, NULL);\r
5c08e117 747 FreePool (NewString);\r
748 Find[1] = TRUE;\r
749 }\r
750\r
751 if (CompareGuid (&Record->DataRecordGuid, &gEfiProcessorSubClassGuid) &&\r
0995a974 752 (DataHeader->RecordType == ProcessorVersionRecordType)\r
5c08e117 753 ) {\r
754 ProcessorVersion = (EFI_PROCESSOR_VERSION_DATA *) (DataHeader + 1);\r
755 GetProducerString (&Record->ProducerName, *ProcessorVersion, &NewString);\r
756 TokenToUpdate = STRING_TOKEN (STR_FRONT_PAGE_CPU_MODEL);\r
cb7d01c0 757 HiiSetString (gFrontPagePrivate.HiiHandle, TokenToUpdate, NewString, NULL);\r
5c08e117 758 FreePool (NewString);\r
759 Find[2] = TRUE;\r
760 }\r
761\r
762 if (CompareGuid (&Record->DataRecordGuid, &gEfiProcessorSubClassGuid) &&\r
0995a974 763 (DataHeader->RecordType == ProcessorCoreFrequencyRecordType)\r
5c08e117 764 ) {\r
765 ProcessorFrequency = (EFI_PROCESSOR_CORE_FREQUENCY_DATA *) (DataHeader + 1);\r
766 ConvertProcessorToString (ProcessorFrequency, &NewString);\r
767 TokenToUpdate = STRING_TOKEN (STR_FRONT_PAGE_CPU_SPEED);\r
cb7d01c0 768 HiiSetString (gFrontPagePrivate.HiiHandle, TokenToUpdate, NewString, NULL);\r
5c08e117 769 FreePool (NewString);\r
770 Find[3] = TRUE;\r
771 }\r
772\r
773 if (CompareGuid (&Record->DataRecordGuid, &gEfiMemorySubClassGuid) &&\r
774 (DataHeader->RecordType == EFI_MEMORY_ARRAY_START_ADDRESS_RECORD_NUMBER)\r
775 ) {\r
776 MemoryArray = (EFI_MEMORY_ARRAY_START_ADDRESS_DATA *) (DataHeader + 1);\r
777 ConvertMemorySizeToString (\r
778 (UINT32)(RShiftU64((MemoryArray->MemoryArrayEndAddress - MemoryArray->MemoryArrayStartAddress + 1), 20)),\r
779 &NewString\r
780 );\r
781 TokenToUpdate = STRING_TOKEN (STR_FRONT_PAGE_MEMORY_SIZE);\r
cb7d01c0 782 HiiSetString (gFrontPagePrivate.HiiHandle, TokenToUpdate, NewString, NULL);\r
5c08e117 783 FreePool (NewString);\r
784 Find[4] = TRUE;\r
785 }\r
786 }\r
787 } while (!EFI_ERROR (Status) && (MonotonicCount != 0) && !(Find[0] && Find[1] && Find[2] && Find[3] && Find[4]));\r
788\r
789 return ;\r
790}\r
791\r
792/**\r
793 Function waits for a given event to fire, or for an optional timeout to expire.\r
794\r
795 @param Event The event to wait for\r
796 @param Timeout An optional timeout value in 100 ns units.\r
797\r
798 @retval EFI_SUCCESS Event fired before Timeout expired.\r
799 @retval EFI_TIME_OUT Timout expired before Event fired..\r
800\r
801**/\r
802EFI_STATUS\r
803WaitForSingleEvent (\r
804 IN EFI_EVENT Event,\r
805 IN UINT64 Timeout OPTIONAL\r
806 )\r
807{\r
808 EFI_STATUS Status;\r
809 UINTN Index;\r
810 EFI_EVENT TimerEvent;\r
811 EFI_EVENT WaitList[2];\r
812\r
813 if (Timeout != 0) {\r
814 //\r
815 // Create a timer event\r
816 //\r
817 Status = gBS->CreateEvent (EVT_TIMER, 0, NULL, NULL, &TimerEvent);\r
818 if (!EFI_ERROR (Status)) {\r
819 //\r
820 // Set the timer event\r
821 //\r
822 gBS->SetTimer (\r
823 TimerEvent,\r
824 TimerRelative,\r
825 Timeout\r
826 );\r
827\r
828 //\r
829 // Wait for the original event or the timer\r
830 //\r
831 WaitList[0] = Event;\r
832 WaitList[1] = TimerEvent;\r
833 Status = gBS->WaitForEvent (2, WaitList, &Index);\r
834 gBS->CloseEvent (TimerEvent);\r
835\r
836 //\r
837 // If the timer expired, change the return to timed out\r
838 //\r
839 if (!EFI_ERROR (Status) && Index == 1) {\r
840 Status = EFI_TIMEOUT;\r
841 }\r
842 }\r
843 } else {\r
844 //\r
845 // No timeout... just wait on the event\r
846 //\r
847 Status = gBS->WaitForEvent (1, &Event, &Index);\r
848 ASSERT (!EFI_ERROR (Status));\r
849 ASSERT (Index == 0);\r
850 }\r
851\r
852 return Status;\r
853}\r
854\r
855/**\r
856 Function show progress bar to wait for user input.\r
857\r
858\r
859 @param TimeoutDefault The fault time out value before the system continue to boot.\r
860\r
861 @retval EFI_SUCCESS User pressed some key except "Enter"\r
862 @retval EFI_TIME_OUT Timout expired or user press "Enter"\r
863\r
864**/\r
865EFI_STATUS\r
866ShowProgress (\r
867 IN UINT16 TimeoutDefault\r
868 )\r
869{\r
870 EFI_STATUS Status;\r
871 CHAR16 *TmpStr;\r
872 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground;\r
873 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;\r
874 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Color;\r
875 EFI_INPUT_KEY Key;\r
876 UINT16 TimeoutRemain;\r
877\r
878 if (TimeoutDefault == 0) {\r
879 return EFI_TIMEOUT;\r
880 }\r
881\r
882 DEBUG ((EFI_D_INFO, "\n\nStart showing progress bar... Press any key to stop it! ...Zzz....\n"));\r
128efbbc 883\r
5c08e117 884 SetMem (&Foreground, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0xff);\r
885 SetMem (&Background, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0x0);\r
886 SetMem (&Color, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL), 0xff);\r
887\r
888 //\r
889 // Clear the progress status bar first\r
890 //\r
891 TmpStr = GetStringById (STRING_TOKEN (STR_START_BOOT_OPTION));\r
892 if (TmpStr != NULL) {\r
893 PlatformBdsShowProgress (Foreground, Background, TmpStr, Color, 0, 0);\r
894 }\r
895\r
896 TimeoutRemain = TimeoutDefault;\r
897 while (TimeoutRemain != 0) {\r
898 DEBUG ((EFI_D_INFO, "Showing progress bar...Remaining %d second!\n", TimeoutRemain));\r
128efbbc 899\r
5c08e117 900 Status = WaitForSingleEvent (gST->ConIn->WaitForKey, ONE_SECOND);\r
901 if (Status != EFI_TIMEOUT) {\r
902 break;\r
903 }\r
904 TimeoutRemain--;\r
905\r
906 //\r
907 // Show progress\r
908 //\r
909 if (TmpStr != NULL) {\r
910 PlatformBdsShowProgress (\r
911 Foreground,\r
912 Background,\r
913 TmpStr,\r
914 Color,\r
915 ((TimeoutDefault - TimeoutRemain) * 100 / TimeoutDefault),\r
916 0\r
917 );\r
918 }\r
919 }\r
920 gBS->FreePool (TmpStr);\r
921\r
922 //\r
923 // Timeout expired\r
924 //\r
925 if (TimeoutRemain == 0) {\r
926 return EFI_TIMEOUT;\r
927 }\r
928\r
929 //\r
930 // User pressed some key\r
931 //\r
932 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
933 if (EFI_ERROR (Status)) {\r
934 return Status;\r
935 }\r
936\r
937 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r
938 //\r
939 // User pressed enter, equivalent to select "continue"\r
940 //\r
941 return EFI_TIMEOUT;\r
942 }\r
943\r
944 return EFI_SUCCESS;\r
945}\r
946\r
947/**\r
948 This function is the main entry of the platform setup entry.\r
949 The function will present the main menu of the system setup,\r
950 this is the platform reference part and can be customize.\r
951\r
952\r
953 @param TimeoutDefault The fault time out value before the system\r
954 continue to boot.\r
955 @param ConnectAllHappened The indicater to check if the connect all have\r
956 already happended.\r
957\r
958**/\r
959VOID\r
960PlatformBdsEnterFrontPage (\r
961 IN UINT16 TimeoutDefault,\r
962 IN BOOLEAN ConnectAllHappened\r
963 )\r
964{\r
965 EFI_STATUS Status;\r
5c08e117 966\r
128efbbc 967 PERF_START (NULL, "BdsTimeOut", "BDS", 0);\r
5c08e117 968 //\r
969 // Indicate if we need connect all in the platform setup\r
970 //\r
971 if (ConnectAllHappened) {\r
972 gConnectAllHappened = TRUE;\r
973 }\r
974\r
975 if (TimeoutDefault != 0xffff) {\r
976 Status = ShowProgress (TimeoutDefault);\r
977\r
978 //\r
979 // Ensure screen is clear when switch Console from Graphics mode to Text mode\r
980 //\r
981 gST->ConOut->EnableCursor (gST->ConOut, TRUE);\r
982 gST->ConOut->ClearScreen (gST->ConOut);\r
983\r
984 if (EFI_ERROR (Status)) {\r
985 //\r
986 // Timeout or user press enter to continue\r
987 //\r
988 goto Exit;\r
989 }\r
990 }\r
991\r
992 do {\r
993\r
994 InitializeFrontPage (FALSE);\r
995\r
996 //\r
997 // Update Front Page strings\r
998 //\r
999 UpdateFrontPageStrings ();\r
1000\r
1001 gCallbackKey = 0;\r
1002 Status = CallFrontPage ();\r
1003\r
1004 //\r
1005 // If gCallbackKey is greater than 1 and less or equal to 5,\r
1006 // it will lauch configuration utilities.\r
1007 // 2 = set language\r
1008 // 3 = boot manager\r
1009 // 4 = device manager\r
1010 // 5 = boot maintainenance manager\r
1011 //\r
1012 if (gCallbackKey != 0) {\r
1013 REPORT_STATUS_CODE (\r
1014 EFI_PROGRESS_CODE,\r
1015 (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_PC_USER_SETUP)\r
1016 );\r
1017 }\r
1018 //\r
1019 // Based on the key that was set, we can determine what to do\r
1020 //\r
1021 switch (gCallbackKey) {\r
1022 //\r
1023 // The first 4 entries in the Front Page are to be GUARANTEED to remain constant so IHV's can\r
1024 // describe to their customers in documentation how to find their setup information (namely\r
1025 // under the device manager and specific buckets)\r
1026 //\r
1027 // These entries consist of the Continue, Select language, Boot Manager, and Device Manager\r
1028 //\r
1029 case FRONT_PAGE_KEY_CONTINUE:\r
1030 //\r
1031 // User hit continue\r
1032 //\r
1033 break;\r
1034\r
1035 case FRONT_PAGE_KEY_LANGUAGE:\r
1036 //\r
1037 // User made a language setting change - display front page again\r
1038 //\r
1039 break;\r
1040\r
1041 case FRONT_PAGE_KEY_BOOT_MANAGER:\r
1042 //\r
1043 // User chose to run the Boot Manager\r
1044 //\r
1045 CallBootManager ();\r
1046 break;\r
1047\r
1048 case FRONT_PAGE_KEY_DEVICE_MANAGER:\r
1049 //\r
1050 // Display the Device Manager\r
1051 //\r
1052 do {\r
1053 CallDeviceManager();\r
1054 } while (gCallbackKey == FRONT_PAGE_KEY_DEVICE_MANAGER);\r
1055 break;\r
1056\r
1057 case FRONT_PAGE_KEY_BOOT_MAINTAIN:\r
1058 //\r
1059 // Display the Boot Maintenance Manager\r
1060 //\r
1061 BdsStartBootMaint ();\r
1062 break;\r
1063 }\r
1064\r
1065 } while ((Status == EFI_SUCCESS) && (gCallbackKey != FRONT_PAGE_KEY_CONTINUE));\r
1066\r
1067 //\r
1068 //Will leave browser, check any reset required change is applied? if yes, reset system\r
1069 //\r
1070 SetupResetReminder ();\r
1071\r
1072Exit:\r
1073 //\r
1074 // Automatically load current entry\r
1075 // Note: The following lines of code only execute when Auto boot\r
1076 // takes affect\r
1077 //\r
128efbbc 1078 PERF_END (NULL, "BdsTimeOut", "BDS", 0);\r
5c08e117 1079}\r