Update for IntelFrameworkModulePkg.
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / BdsDxe / BootMaint / UpdatePage.c
CommitLineData
5c08e117 1/** @file\r
2Dynamically update the pages.\r
3\r
b1620d0b 4Copyright (c) 2004 - 2011, 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 "BootMaint.h"\r
16\r
17/**\r
18 Refresh the global UpdateData structure.\r
19\r
20**/\r
21VOID\r
22RefreshUpdateData (\r
23 VOID\r
24 )\r
25{\r
75bf9d0e
LG
26 //\r
27 // Free current updated date\r
28 // \r
29 if (mStartOpCodeHandle != NULL) {\r
30 HiiFreeOpCodeHandle (mStartOpCodeHandle);\r
31 }\r
32\r
33 //\r
34 // Create new OpCode Handle\r
35 //\r
36 mStartOpCodeHandle = HiiAllocateOpCodeHandle ();\r
37\r
38 //\r
39 // Create Hii Extend Label OpCode as the start opcode\r
40 //\r
41 mStartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (mStartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
42 mStartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
43\r
5c08e117 44}\r
45\r
46/**\r
47 Add a "Go back to main page" tag in front of the form when there are no\r
48 "Apply changes" and "Discard changes" tags in the end of the form.\r
49 \r
50 @param CallbackData The BMM context data.\r
51\r
52**/\r
53VOID\r
54UpdatePageStart (\r
55 IN BMM_CALLBACK_DATA *CallbackData\r
56 )\r
57{\r
58 RefreshUpdateData ();\r
75bf9d0e 59 mStartLabel->Number = CallbackData->BmmCurrentPageId;\r
5c08e117 60\r
61 if (!(CallbackData->BmmAskSaveOrNot)) {\r
62 //\r
63 // Add a "Go back to main page" tag in front of the form when there are no\r
64 // "Apply changes" and "Discard changes" tags in the end of the form.\r
65 //\r
75bf9d0e
LG
66 HiiCreateGotoOpCode (\r
67 mStartOpCodeHandle,\r
5c08e117 68 FORM_MAIN_ID,\r
69 STRING_TOKEN (STR_FORM_GOTO_MAIN),\r
70 STRING_TOKEN (STR_FORM_GOTO_MAIN),\r
71 0,\r
75bf9d0e 72 FORM_MAIN_ID\r
5c08e117 73 );\r
74 }\r
75\r
76}\r
77\r
78/**\r
79 Create the "Apply changes" and "Discard changes" tags. And\r
80 ensure user can return to the main page.\r
81\r
82 @param CallbackData The BMM context data.\r
83\r
84**/\r
85VOID\r
86UpdatePageEnd (\r
87 IN BMM_CALLBACK_DATA *CallbackData\r
88 )\r
89{\r
90 //\r
91 // Create the "Apply changes" and "Discard changes" tags.\r
92 //\r
93 if (CallbackData->BmmAskSaveOrNot) {\r
75bf9d0e
LG
94 HiiCreateSubTitleOpCode (\r
95 mStartOpCodeHandle,\r
5c08e117 96 STRING_TOKEN (STR_NULL_STRING),\r
97 0,\r
98 0,\r
75bf9d0e 99 0\r
5c08e117 100 );\r
101\r
84724077 102 HiiCreateActionOpCode (\r
75bf9d0e 103 mStartOpCodeHandle,\r
84724077 104 KEY_VALUE_SAVE_AND_EXIT,\r
5c08e117 105 STRING_TOKEN (STR_SAVE_AND_EXIT),\r
106 STRING_TOKEN (STR_NULL_STRING),\r
107 EFI_IFR_FLAG_CALLBACK,\r
84724077 108 0\r
5c08e117 109 );\r
110 }\r
111\r
112 //\r
113 // Ensure user can return to the main page.\r
114 //\r
84724077 115 HiiCreateActionOpCode (\r
75bf9d0e 116 mStartOpCodeHandle,\r
84724077 117 KEY_VALUE_NO_SAVE_AND_EXIT,\r
5c08e117 118 STRING_TOKEN (STR_NO_SAVE_AND_EXIT),\r
119 STRING_TOKEN (STR_NULL_STRING),\r
120 EFI_IFR_FLAG_CALLBACK,\r
84724077 121 0\r
5c08e117 122 );\r
123\r
75bf9d0e 124 HiiUpdateForm (\r
5c08e117 125 CallbackData->BmmHiiHandle,\r
e24fc103 126 &gBootMaintFormSetGuid,\r
5c08e117 127 CallbackData->BmmCurrentPageId,\r
75bf9d0e
LG
128 mStartOpCodeHandle, // Label CallbackData->BmmCurrentPageId\r
129 mEndOpCodeHandle // LABEL_END\r
5c08e117 130 );\r
131}\r
132\r
133/**\r
134 Clean up the dynamic opcode at label and form specified by both LabelId. \r
135\r
136 @param LabelId It is both the Form ID and Label ID for opcode deletion.\r
137 @param CallbackData The BMM context data.\r
138\r
139**/\r
140VOID\r
141CleanUpPage (\r
142 IN UINT16 LabelId,\r
143 IN BMM_CALLBACK_DATA *CallbackData\r
144 )\r
145{\r
146 RefreshUpdateData ();\r
147\r
148 //\r
149 // Remove all op-codes from dynamic page\r
150 //\r
75bf9d0e
LG
151 mStartLabel->Number = LabelId;\r
152 HiiUpdateForm (\r
5c08e117 153 CallbackData->BmmHiiHandle,\r
e24fc103 154 &gBootMaintFormSetGuid,\r
5c08e117 155 LabelId,\r
75bf9d0e
LG
156 mStartOpCodeHandle, // Label LabelId\r
157 mEndOpCodeHandle // LABEL_END\r
5c08e117 158 );\r
159}\r
160\r
161/**\r
162 Boot a file selected by user at File Expoloer of BMM.\r
163\r
164 @param FileContext The file context data, which contains the device path\r
165 of the file to be boot from.\r
166\r
167 @retval EFI_SUCCESS The function completed successfull.\r
168 @return Other value if the boot from the file fails.\r
169\r
170**/\r
171EFI_STATUS\r
172BootThisFile (\r
173 IN BM_FILE_CONTEXT *FileContext\r
174 )\r
175{\r
176 EFI_STATUS Status;\r
177 UINTN ExitDataSize;\r
178 CHAR16 *ExitData;\r
179 BDS_COMMON_OPTION *Option;\r
180\r
181 Option = (BDS_COMMON_OPTION *) AllocatePool (sizeof (BDS_COMMON_OPTION));\r
182 ASSERT (Option != NULL);\r
326f0711 183 Option->Description = (CHAR16 *) AllocateCopyPool (StrSize (FileContext->FileName), FileContext->FileName);\r
5c08e117 184 Option->DevicePath = FileContext->DevicePath;\r
185 Option->LoadOptionsSize = 0;\r
186 Option->LoadOptions = NULL;\r
187\r
188 //\r
189 // Since current no boot from removable media directly is allowed */\r
190 //\r
191 gST->ConOut->ClearScreen (gST->ConOut);\r
192\r
193 ExitDataSize = 0;\r
194\r
195 Status = BdsLibBootViaBootOption (Option, Option->DevicePath, &ExitDataSize, &ExitData);\r
196\r
197 return Status;\r
198\r
199}\r
200\r
201/**\r
202 Create a list of Goto Opcode for all terminal devices logged\r
203 by TerminaMenu. This list will be inserted to form FORM_CON_COM_SETUP_ID.\r
204\r
205 @param CallbackData The BMM context data.\r
206**/\r
207VOID\r
208UpdateConCOMPage (\r
209 IN BMM_CALLBACK_DATA *CallbackData\r
210 )\r
211{\r
212 BM_MENU_ENTRY *NewMenuEntry;\r
213 UINT16 Index;\r
214\r
215 CallbackData->BmmAskSaveOrNot = FALSE;\r
216\r
217 UpdatePageStart (CallbackData);\r
218\r
219\r
220 for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) {\r
221 NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index);\r
222\r
75bf9d0e
LG
223 HiiCreateGotoOpCode (\r
224 mStartOpCodeHandle,\r
5c08e117 225 FORM_CON_COM_SETUP_ID,\r
226 NewMenuEntry->DisplayStringToken,\r
227 STRING_TOKEN (STR_NULL_STRING),\r
228 EFI_IFR_FLAG_CALLBACK,\r
75bf9d0e 229 (UINT16) (TERMINAL_OPTION_OFFSET + Index)\r
5c08e117 230 );\r
231 }\r
232\r
233 UpdatePageEnd (CallbackData);\r
234}\r
235\r
236/**\r
237 Create a lit of boot option from global BootOptionMenu. It\r
238 allow user to delete the boot option.\r
239\r
240 @param CallbackData The BMM context data.\r
241\r
242**/\r
243VOID\r
244UpdateBootDelPage (\r
245 IN BMM_CALLBACK_DATA *CallbackData\r
246 )\r
247{\r
248 BM_MENU_ENTRY *NewMenuEntry;\r
249 BM_LOAD_CONTEXT *NewLoadContext;\r
250 UINT16 Index;\r
251\r
252 CallbackData->BmmAskSaveOrNot = TRUE;\r
253\r
254 UpdatePageStart (CallbackData);\r
255 CreateMenuStringToken (CallbackData, CallbackData->BmmHiiHandle, &BootOptionMenu);\r
256\r
b452ca89 257 ASSERT (BootOptionMenu.MenuNumber <= (sizeof (CallbackData->BmmFakeNvData.OptionDel) / sizeof (CallbackData->BmmFakeNvData.OptionDel[0])));\r
5c08e117 258 for (Index = 0; Index < BootOptionMenu.MenuNumber; Index++) {\r
259 NewMenuEntry = BOpt_GetMenuEntry (&BootOptionMenu, Index);\r
260 NewLoadContext = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext;\r
261 if (NewLoadContext->IsLegacy) {\r
262 continue;\r
263 }\r
264\r
265 NewLoadContext->Deleted = FALSE;\r
b452ca89 266 CallbackData->BmmFakeNvData.OptionDel[Index] = FALSE;\r
5c08e117 267\r
75bf9d0e
LG
268 HiiCreateCheckBoxOpCode (\r
269 mStartOpCodeHandle,\r
b452ca89 270 (EFI_QUESTION_ID) (OPTION_DEL_QUESTION_ID + Index),\r
5c08e117 271 VARSTORE_ID_BOOT_MAINT,\r
b452ca89 272 (UINT16) (OPTION_DEL_VAR_OFFSET + Index),\r
5c08e117 273 NewMenuEntry->DisplayStringToken,\r
274 NewMenuEntry->HelpStringToken,\r
275 0,\r
276 0,\r
75bf9d0e 277 NULL\r
5c08e117 278 );\r
279 }\r
280\r
281 UpdatePageEnd (CallbackData);\r
282}\r
283\r
284/**\r
285 Create a lit of driver option from global DriverMenu.\r
286\r
287 @param CallbackData The BMM context data.\r
288\r
289**/\r
290VOID\r
291UpdateDrvAddHandlePage (\r
292 IN BMM_CALLBACK_DATA *CallbackData\r
293 )\r
294{\r
295 BM_MENU_ENTRY *NewMenuEntry;\r
296 UINT16 Index;\r
297\r
298 CallbackData->BmmAskSaveOrNot = FALSE;\r
299\r
300 UpdatePageStart (CallbackData);\r
301\r
302 for (Index = 0; Index < DriverMenu.MenuNumber; Index++) {\r
303 NewMenuEntry = BOpt_GetMenuEntry (&DriverMenu, Index);\r
304\r
75bf9d0e
LG
305 HiiCreateGotoOpCode (\r
306 mStartOpCodeHandle,\r
5c08e117 307 FORM_DRV_ADD_HANDLE_DESC_ID,\r
308 NewMenuEntry->DisplayStringToken,\r
309 STRING_TOKEN (STR_NULL_STRING),\r
310 EFI_IFR_FLAG_CALLBACK,\r
75bf9d0e 311 (UINT16) (HANDLE_OPTION_OFFSET + Index)\r
5c08e117 312 );\r
313 }\r
314\r
315 UpdatePageEnd (CallbackData);\r
316}\r
317\r
318/**\r
319 Create a lit of driver option from global DriverOptionMenu. It\r
320 allow user to delete the driver option.\r
321\r
322 @param CallbackData The BMM context data.\r
323\r
324**/\r
325VOID\r
326UpdateDrvDelPage (\r
327 IN BMM_CALLBACK_DATA *CallbackData\r
328 )\r
329{\r
330 BM_MENU_ENTRY *NewMenuEntry;\r
331 BM_LOAD_CONTEXT *NewLoadContext;\r
332 UINT16 Index;\r
333\r
334 CallbackData->BmmAskSaveOrNot = TRUE;\r
335\r
336 UpdatePageStart (CallbackData);\r
337\r
338 CreateMenuStringToken (CallbackData, CallbackData->BmmHiiHandle, &DriverOptionMenu);\r
339 \r
b452ca89 340 ASSERT (DriverOptionMenu.MenuNumber <= (sizeof (CallbackData->BmmFakeNvData.OptionDel) / sizeof (CallbackData->BmmFakeNvData.OptionDel[0])));\r
5c08e117 341 for (Index = 0; Index < DriverOptionMenu.MenuNumber; Index++) {\r
342 NewMenuEntry = BOpt_GetMenuEntry (&DriverOptionMenu, Index);\r
343\r
344 NewLoadContext = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext;\r
345 NewLoadContext->Deleted = FALSE;\r
b452ca89 346 CallbackData->BmmFakeNvData.OptionDel[Index] = FALSE;\r
5c08e117 347\r
75bf9d0e
LG
348 HiiCreateCheckBoxOpCode (\r
349 mStartOpCodeHandle,\r
b452ca89 350 (EFI_QUESTION_ID) (OPTION_DEL_QUESTION_ID + Index),\r
5c08e117 351 VARSTORE_ID_BOOT_MAINT,\r
b452ca89 352 (UINT16) (OPTION_DEL_VAR_OFFSET + Index),\r
5c08e117 353 NewMenuEntry->DisplayStringToken,\r
354 NewMenuEntry->HelpStringToken,\r
355 0,\r
356 0,\r
75bf9d0e 357 NULL\r
5c08e117 358 );\r
359 }\r
360\r
361 UpdatePageEnd (CallbackData);\r
362}\r
363\r
364/**\r
365 Prepare the page to allow user to add description for \r
366 a Driver Option.\r
367\r
368 @param CallbackData The BMM context data.\r
369\r
370**/\r
371VOID\r
372UpdateDriverAddHandleDescPage (\r
373 IN BMM_CALLBACK_DATA *CallbackData\r
374 )\r
375{\r
376 BM_MENU_ENTRY *NewMenuEntry;\r
377\r
378 CallbackData->BmmFakeNvData.DriverAddActive = 0x01;\r
379 CallbackData->BmmFakeNvData.DriverAddForceReconnect = 0x00;\r
380 CallbackData->BmmAskSaveOrNot = TRUE;\r
381 NewMenuEntry = CallbackData->MenuEntry;\r
382\r
383 UpdatePageStart (CallbackData);\r
384\r
75bf9d0e
LG
385 HiiCreateSubTitleOpCode (\r
386 mStartOpCodeHandle,\r
5c08e117 387 NewMenuEntry->DisplayStringToken,\r
388 0,\r
389 0,\r
75bf9d0e 390 0\r
5c08e117 391 );\r
392\r
75bf9d0e
LG
393 HiiCreateStringOpCode (\r
394 mStartOpCodeHandle,\r
5c08e117 395 (EFI_QUESTION_ID) DRV_ADD_HANDLE_DESC_QUESTION_ID,\r
396 VARSTORE_ID_BOOT_MAINT,\r
397 DRV_ADD_HANDLE_DESC_VAR_OFFSET,\r
398 STRING_TOKEN (STR_LOAD_OPTION_DESC),\r
399 STRING_TOKEN (STR_NULL_STRING),\r
400 0,\r
401 0,\r
402 6,\r
403 75,\r
75bf9d0e 404 NULL\r
5c08e117 405 );\r
406\r
75bf9d0e
LG
407 HiiCreateCheckBoxOpCode (\r
408 mStartOpCodeHandle,\r
5c08e117 409 (EFI_QUESTION_ID) DRV_ADD_RECON_QUESTION_ID,\r
410 VARSTORE_ID_BOOT_MAINT,\r
411 DRV_ADD_RECON_VAR_OFFSET,\r
412 STRING_TOKEN (STR_LOAD_OPTION_FORCE_RECON),\r
413 STRING_TOKEN (STR_LOAD_OPTION_FORCE_RECON),\r
414 0,\r
415 0,\r
75bf9d0e 416 NULL\r
5c08e117 417 );\r
418\r
75bf9d0e
LG
419 HiiCreateStringOpCode (\r
420 mStartOpCodeHandle,\r
5c08e117 421 (EFI_QUESTION_ID) DRIVER_ADD_OPTION_QUESTION_ID,\r
422 VARSTORE_ID_BOOT_MAINT,\r
423 DRIVER_ADD_OPTION_VAR_OFFSET,\r
424 STRING_TOKEN (STR_OPTIONAL_DATA),\r
425 STRING_TOKEN (STR_NULL_STRING),\r
426 0,\r
427 0,\r
428 6,\r
429 75,\r
75bf9d0e 430 NULL\r
5c08e117 431 );\r
432\r
433 UpdatePageEnd (CallbackData);\r
434}\r
435\r
436/**\r
437 Update console page.\r
438\r
439 @param UpdatePageId The form ID to be updated.\r
440 @param ConsoleMenu The console menu list.\r
441 @param CallbackData The BMM context data.\r
442\r
443**/\r
444VOID\r
445UpdateConsolePage (\r
446 IN UINT16 UpdatePageId,\r
447 IN BM_MENU_OPTION *ConsoleMenu,\r
448 IN BMM_CALLBACK_DATA *CallbackData\r
449 )\r
450{\r
451 BM_MENU_ENTRY *NewMenuEntry;\r
452 BM_CONSOLE_CONTEXT *NewConsoleContext;\r
453 BM_TERMINAL_CONTEXT *NewTerminalContext;\r
454 UINT16 Index;\r
455 UINT16 Index2;\r
456 UINT8 CheckFlags;\r
457 \r
458 CallbackData->BmmAskSaveOrNot = TRUE;\r
459\r
460 UpdatePageStart (CallbackData);\r
461\r
582c2368 462 for (Index = 0; ((Index < ConsoleMenu->MenuNumber) && \\r
463 (Index < (sizeof (CallbackData->BmmFakeNvData.ConsoleCheck) / sizeof (UINT8)))) ; Index++) {\r
5c08e117 464 NewMenuEntry = BOpt_GetMenuEntry (ConsoleMenu, Index);\r
465 NewConsoleContext = (BM_CONSOLE_CONTEXT *) NewMenuEntry->VariableContext;\r
466 CheckFlags = 0;\r
467 if (NewConsoleContext->IsActive) {\r
468 CheckFlags |= EFI_IFR_CHECKBOX_DEFAULT;\r
469 CallbackData->BmmFakeNvData.ConsoleCheck[Index] = TRUE;\r
470 } else {\r
471 CallbackData->BmmFakeNvData.ConsoleCheck[Index] = FALSE;\r
472 }\r
473\r
75bf9d0e
LG
474 HiiCreateCheckBoxOpCode (\r
475 mStartOpCodeHandle,\r
5c08e117 476 (EFI_QUESTION_ID) (CON_DEVICE_QUESTION_ID + Index),\r
477 VARSTORE_ID_BOOT_MAINT,\r
478 (UINT16) (CON_DEVICE_VAR_OFFSET + Index),\r
479 NewMenuEntry->DisplayStringToken,\r
480 NewMenuEntry->HelpStringToken,\r
481 0,\r
482 CheckFlags,\r
75bf9d0e 483 NULL\r
5c08e117 484 );\r
485 }\r
486\r
582c2368 487 for (Index2 = 0; ((Index2 < TerminalMenu.MenuNumber) && \\r
488 (Index2 < (sizeof (CallbackData->BmmFakeNvData.ConsoleCheck) / sizeof (UINT8)))); Index2++) {\r
5c08e117 489 CheckFlags = 0;\r
490 NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index2);\r
491 NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;\r
492\r
b7b0dca2 493 ASSERT (Index < MAX_MENU_NUMBER);\r
5c08e117 494 if (((NewTerminalContext->IsConIn != 0) && (UpdatePageId == FORM_CON_IN_ID)) ||\r
495 ((NewTerminalContext->IsConOut != 0) && (UpdatePageId == FORM_CON_OUT_ID)) ||\r
496 ((NewTerminalContext->IsStdErr != 0) && (UpdatePageId == FORM_CON_ERR_ID))\r
497 ) {\r
498 CheckFlags |= EFI_IFR_CHECKBOX_DEFAULT;\r
499 CallbackData->BmmFakeNvData.ConsoleCheck[Index] = TRUE;\r
500 } else {\r
501 CallbackData->BmmFakeNvData.ConsoleCheck[Index] = FALSE;\r
502 }\r
503\r
75bf9d0e
LG
504 HiiCreateCheckBoxOpCode (\r
505 mStartOpCodeHandle,\r
5c08e117 506 (EFI_QUESTION_ID) (CON_DEVICE_QUESTION_ID + Index),\r
507 VARSTORE_ID_BOOT_MAINT,\r
508 (UINT16) (CON_DEVICE_VAR_OFFSET + Index),\r
509 NewMenuEntry->DisplayStringToken,\r
510 NewMenuEntry->HelpStringToken,\r
511 0,\r
512 CheckFlags,\r
75bf9d0e 513 NULL\r
5c08e117 514 );\r
515\r
516 Index++;\r
517 }\r
518\r
519 UpdatePageEnd (CallbackData);\r
520}\r
521\r
522/**\r
523 Update the page's NV Map if user has changed the order\r
524 a list. This list can be Boot Order or Driver Order.\r
525\r
526 @param UpdatePageId The form ID to be updated.\r
527 @param OptionMenu The new list.\r
528 @param CallbackData The BMM context data.\r
529\r
530**/\r
531VOID\r
532UpdateOrderPage (\r
533 IN UINT16 UpdatePageId,\r
534 IN BM_MENU_OPTION *OptionMenu,\r
535 IN BMM_CALLBACK_DATA *CallbackData\r
536 )\r
537{\r
22d1f978
RN
538 BM_MENU_ENTRY *NewMenuEntry;\r
539 UINT16 Index;\r
540 UINT16 OptionOrderIndex;\r
541 VOID *OptionsOpCodeHandle;\r
542 UINTN DeviceType;\r
543 BM_LOAD_CONTEXT *NewLoadContext;\r
5c08e117 544\r
22d1f978 545 DeviceType = (UINTN) -1;\r
5c08e117 546 CallbackData->BmmAskSaveOrNot = TRUE;\r
547\r
548 UpdatePageStart (CallbackData);\r
549\r
550 CreateMenuStringToken (CallbackData, CallbackData->BmmHiiHandle, OptionMenu);\r
551\r
b452ca89 552 ZeroMem (CallbackData->BmmFakeNvData.OptionOrder, sizeof (CallbackData->BmmFakeNvData.OptionOrder));\r
5c08e117 553\r
75bf9d0e
LG
554 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();\r
555 ASSERT (OptionsOpCodeHandle != NULL);\r
5c08e117 556 \r
8bb37919 557 for (\r
22d1f978 558 Index = 0, OptionOrderIndex = 0;\r
8bb37919 559 (\r
560 (Index < OptionMenu->MenuNumber) &&\r
22d1f978 561 (OptionOrderIndex <\r
8bb37919 562 (\r
563 sizeof (CallbackData->BmmFakeNvData.OptionOrder) /\r
b452ca89 564 sizeof (CallbackData->BmmFakeNvData.OptionOrder[0])\r
8bb37919 565 )\r
566 )\r
567 );\r
568 Index++\r
569 ) {\r
22d1f978
RN
570 NewMenuEntry = BOpt_GetMenuEntry (OptionMenu, Index);\r
571 NewLoadContext = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext;\r
572\r
573 if (NewLoadContext->IsLegacy) {\r
574 if (((BBS_BBS_DEVICE_PATH *) NewLoadContext->FilePathList)->DeviceType != DeviceType) {\r
575 DeviceType = ((BBS_BBS_DEVICE_PATH *) NewLoadContext->FilePathList)->DeviceType;\r
576 } else {\r
577 //\r
578 // Only show one legacy boot option for the same device type\r
579 // assuming the boot options are grouped by the device type\r
580 //\r
581 continue;\r
582 }\r
583 }\r
75bf9d0e
LG
584 HiiCreateOneOfOptionOpCode (\r
585 OptionsOpCodeHandle,\r
586 NewMenuEntry->DisplayStringToken,\r
587 0,\r
b452ca89
RN
588 EFI_IFR_TYPE_NUM_SIZE_32,\r
589 (UINT32) (NewMenuEntry->OptionNumber + 1)\r
75bf9d0e 590 );\r
22d1f978 591 CallbackData->BmmFakeNvData.OptionOrder[OptionOrderIndex++] = (UINT32) (NewMenuEntry->OptionNumber + 1);\r
5c08e117 592 }\r
593\r
594 if (OptionMenu->MenuNumber > 0) {\r
75bf9d0e
LG
595 HiiCreateOrderedListOpCode ( \r
596 mStartOpCodeHandle, // Container for dynamic created opcodes \r
597 (EFI_QUESTION_ID) OPTION_ORDER_QUESTION_ID, // Question ID \r
598 VARSTORE_ID_BOOT_MAINT, // VarStore ID \r
599 OPTION_ORDER_VAR_OFFSET, // Offset in Buffer Storage \r
600 STRING_TOKEN (STR_CHANGE_ORDER), // Question prompt text \r
601 STRING_TOKEN (STR_CHANGE_ORDER), // Question help text \r
602 0, // Question flag \r
603 0, // Ordered list flag, e.g. EFI_IFR_UNIQUE_SET\r
b452ca89 604 EFI_IFR_TYPE_NUM_SIZE_32, // Data type of Question value \r
75bf9d0e
LG
605 100, // Maximum container \r
606 OptionsOpCodeHandle, // Option Opcode list \r
607 NULL // Default Opcode is NULL \r
5c08e117 608 );\r
609 }\r
610\r
75bf9d0e 611 HiiFreeOpCodeHandle (OptionsOpCodeHandle);\r
5c08e117 612\r
613 UpdatePageEnd (CallbackData);\r
614\r
615 CopyMem (\r
616 CallbackData->BmmOldFakeNVData.OptionOrder,\r
617 CallbackData->BmmFakeNvData.OptionOrder,\r
b452ca89 618 sizeof (CallbackData->BmmOldFakeNVData.OptionOrder)\r
5c08e117 619 );\r
620}\r
621\r
622/**\r
623 Create the dynamic page to allow user to set\r
624 the "BootNext" value.\r
625\r
626 @param CallbackData The BMM context data.\r
627\r
628**/\r
629VOID\r
630UpdateBootNextPage (\r
631 IN BMM_CALLBACK_DATA *CallbackData\r
632 )\r
633{\r
634 BM_MENU_ENTRY *NewMenuEntry;\r
635 BM_LOAD_CONTEXT *NewLoadContext;\r
5c08e117 636 UINTN NumberOfOptions;\r
637 UINT16 Index;\r
75bf9d0e 638 VOID *OptionsOpCodeHandle;\r
5c08e117 639\r
5c08e117 640 NumberOfOptions = BootOptionMenu.MenuNumber;\r
641 CallbackData->BmmAskSaveOrNot = TRUE;\r
642\r
643 UpdatePageStart (CallbackData);\r
644 CreateMenuStringToken (CallbackData, CallbackData->BmmHiiHandle, &BootOptionMenu);\r
645\r
646 if (NumberOfOptions > 0) {\r
75bf9d0e
LG
647 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();\r
648 ASSERT (OptionsOpCodeHandle != NULL);\r
5c08e117 649\r
650 CallbackData->BmmFakeNvData.BootNext = (UINT16) (BootOptionMenu.MenuNumber);\r
651\r
652 for (Index = 0; Index < BootOptionMenu.MenuNumber; Index++) {\r
653 NewMenuEntry = BOpt_GetMenuEntry (&BootOptionMenu, Index);\r
654 NewLoadContext = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext;\r
75bf9d0e 655\r
5c08e117 656 if (NewLoadContext->IsBootNext) {\r
75bf9d0e
LG
657 HiiCreateOneOfOptionOpCode (\r
658 OptionsOpCodeHandle,\r
659 NewMenuEntry->DisplayStringToken,\r
660 EFI_IFR_OPTION_DEFAULT,\r
b452ca89 661 EFI_IFR_TYPE_NUM_SIZE_16,\r
75bf9d0e
LG
662 Index\r
663 );\r
5c08e117 664 CallbackData->BmmFakeNvData.BootNext = Index;\r
665 } else {\r
75bf9d0e
LG
666 HiiCreateOneOfOptionOpCode (\r
667 OptionsOpCodeHandle,\r
668 NewMenuEntry->DisplayStringToken,\r
669 0,\r
b452ca89 670 EFI_IFR_TYPE_NUM_SIZE_16,\r
75bf9d0e
LG
671 Index\r
672 );\r
5c08e117 673 }\r
5c08e117 674 }\r
675\r
5c08e117 676 if (CallbackData->BmmFakeNvData.BootNext == Index) {\r
75bf9d0e
LG
677 HiiCreateOneOfOptionOpCode (\r
678 OptionsOpCodeHandle,\r
679 STRING_TOKEN (STR_NONE),\r
680 EFI_IFR_OPTION_DEFAULT,\r
b452ca89 681 EFI_IFR_TYPE_NUM_SIZE_16,\r
75bf9d0e
LG
682 Index\r
683 );\r
684 } else {\r
685 HiiCreateOneOfOptionOpCode (\r
686 OptionsOpCodeHandle,\r
687 STRING_TOKEN (STR_NONE),\r
688 0,\r
b452ca89 689 EFI_IFR_TYPE_NUM_SIZE_16,\r
75bf9d0e
LG
690 Index\r
691 );\r
692 } \r
5c08e117 693\r
75bf9d0e
LG
694 HiiCreateOneOfOpCode (\r
695 mStartOpCodeHandle,\r
5c08e117 696 (EFI_QUESTION_ID) BOOT_NEXT_QUESTION_ID,\r
697 VARSTORE_ID_BOOT_MAINT,\r
698 BOOT_NEXT_VAR_OFFSET,\r
699 STRING_TOKEN (STR_BOOT_NEXT),\r
700 STRING_TOKEN (STR_BOOT_NEXT_HELP),\r
701 0,\r
702 EFI_IFR_NUMERIC_SIZE_2,\r
75bf9d0e
LG
703 OptionsOpCodeHandle,\r
704 NULL\r
5c08e117 705 );\r
706\r
75bf9d0e 707 HiiFreeOpCodeHandle (OptionsOpCodeHandle);\r
5c08e117 708 }\r
709\r
710 UpdatePageEnd (CallbackData);\r
711}\r
712\r
713/**\r
714 Create the dynamic page to allow user to set the "TimeOut" value.\r
715\r
716 @param CallbackData The BMM context data.\r
717\r
718**/\r
719VOID\r
720UpdateTimeOutPage (\r
721 IN BMM_CALLBACK_DATA *CallbackData\r
722 )\r
723{\r
724 UINT16 BootTimeOut;\r
75bf9d0e 725 VOID *DefaultOpCodeHandle;\r
5c08e117 726\r
727 CallbackData->BmmAskSaveOrNot = TRUE;\r
728\r
729 UpdatePageStart (CallbackData);\r
730\r
8c81cb83 731 BootTimeOut = PcdGet16 (PcdPlatformBootTimeOut);\r
5c08e117 732\r
75bf9d0e
LG
733 DefaultOpCodeHandle = HiiAllocateOpCodeHandle ();\r
734 ASSERT (DefaultOpCodeHandle != NULL);\r
b452ca89 735 HiiCreateDefaultOpCode (DefaultOpCodeHandle, EFI_HII_DEFAULT_CLASS_STANDARD, EFI_IFR_TYPE_NUM_SIZE_16, BootTimeOut);\r
75bf9d0e
LG
736\r
737 HiiCreateNumericOpCode (\r
738 mStartOpCodeHandle,\r
5c08e117 739 (EFI_QUESTION_ID) BOOT_TIME_OUT_QUESTION_ID,\r
740 VARSTORE_ID_BOOT_MAINT,\r
741 BOOT_TIME_OUT_VAR_OFFSET,\r
742 STRING_TOKEN (STR_NUM_AUTO_BOOT),\r
743 STRING_TOKEN (STR_HLP_AUTO_BOOT),\r
744 0,\r
745 EFI_IFR_NUMERIC_SIZE_2 | EFI_IFR_DISPLAY_UINT_DEC,\r
746 0,\r
747 65535,\r
748 0,\r
75bf9d0e 749 DefaultOpCodeHandle\r
5c08e117 750 );\r
75bf9d0e
LG
751 \r
752 HiiFreeOpCodeHandle (DefaultOpCodeHandle);\r
5c08e117 753\r
754 CallbackData->BmmFakeNvData.BootTimeOut = BootTimeOut;\r
755\r
756 UpdatePageEnd (CallbackData);\r
757}\r
758\r
759/**\r
760 Refresh the text mode page.\r
761\r
762 @param CallbackData The BMM context data.\r
763\r
764**/\r
765VOID\r
766UpdateConModePage (\r
767 IN BMM_CALLBACK_DATA *CallbackData\r
768 )\r
769{\r
770 UINTN Mode;\r
771 UINTN Index;\r
772 UINTN Col;\r
773 UINTN Row;\r
5c08e117 774 CHAR16 ModeString[50];\r
19bf20e1 775 CHAR16 *PStr;\r
5c08e117 776 UINTN MaxMode;\r
777 UINTN ValidMode;\r
778 EFI_STRING_ID *ModeToken;\r
5c08e117 779 EFI_STATUS Status;\r
75bf9d0e 780 VOID *OptionsOpCodeHandle;\r
5c08e117 781 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut;\r
782\r
783 ConOut = gST->ConOut;\r
784 Index = 0;\r
785 ValidMode = 0;\r
786 MaxMode = (UINTN) (ConOut->Mode->MaxMode);\r
787\r
788 CallbackData->BmmAskSaveOrNot = TRUE;\r
789\r
790 UpdatePageStart (CallbackData);\r
791\r
792 //\r
793 // Check valid mode\r
794 //\r
795 for (Mode = 0; Mode < MaxMode; Mode++) {\r
796 Status = ConOut->QueryMode (ConOut, Mode, &Col, &Row);\r
797 if (EFI_ERROR (Status)) {\r
798 continue;\r
799 }\r
800 ValidMode++;\r
801 }\r
802\r
803 if (ValidMode == 0) {\r
804 return;\r
805 }\r
806\r
75bf9d0e
LG
807 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();\r
808 ASSERT (OptionsOpCodeHandle != NULL);\r
5c08e117 809\r
810 ModeToken = AllocateZeroPool (sizeof (EFI_STRING_ID) * ValidMode);\r
811 ASSERT(ModeToken != NULL);\r
812\r
813 //\r
814 // Determin which mode should be the first entry in menu\r
815 //\r
816 GetConsoleOutMode (CallbackData);\r
817\r
818 //\r
819 // Build text mode options\r
820 //\r
821 for (Mode = 0; Mode < MaxMode; Mode++) {\r
822 Status = ConOut->QueryMode (ConOut, Mode, &Col, &Row);\r
823 if (EFI_ERROR (Status)) {\r
824 continue;\r
825 }\r
826 \r
827 //\r
828 // Build mode string Column x Row\r
829 //\r
7a45e5aa 830 UnicodeValueToString (ModeString, 0, Col, 0);\r
19bf20e1 831 PStr = &ModeString[0];\r
b55f8b01
LG
832 StrnCat (PStr, L" x ", StrLen(L" x ") + 1);\r
833 PStr = PStr + StrLen (PStr);\r
834 UnicodeValueToString (PStr , 0, Row, 0);\r
5c08e117 835\r
cb7d01c0 836 ModeToken[Index] = HiiSetString (CallbackData->BmmHiiHandle, 0, ModeString, NULL);\r
5c08e117 837\r
5c08e117 838 if (Mode == CallbackData->BmmFakeNvData.ConsoleOutMode) {\r
75bf9d0e
LG
839 HiiCreateOneOfOptionOpCode (\r
840 OptionsOpCodeHandle,\r
841 ModeToken[Index],\r
842 EFI_IFR_OPTION_DEFAULT,\r
b452ca89 843 EFI_IFR_TYPE_NUM_SIZE_16,\r
75bf9d0e
LG
844 (UINT16) Mode\r
845 );\r
5c08e117 846 } else {\r
75bf9d0e
LG
847 HiiCreateOneOfOptionOpCode (\r
848 OptionsOpCodeHandle,\r
849 ModeToken[Index],\r
850 0,\r
b452ca89 851 EFI_IFR_TYPE_NUM_SIZE_16,\r
75bf9d0e
LG
852 (UINT16) Mode\r
853 );\r
5c08e117 854 }\r
855 Index++;\r
856 }\r
857\r
75bf9d0e
LG
858 HiiCreateOneOfOpCode (\r
859 mStartOpCodeHandle,\r
5c08e117 860 (EFI_QUESTION_ID) CON_MODE_QUESTION_ID,\r
861 VARSTORE_ID_BOOT_MAINT,\r
862 CON_MODE_VAR_OFFSET,\r
863 STRING_TOKEN (STR_CON_MODE_SETUP),\r
864 STRING_TOKEN (STR_CON_MODE_SETUP),\r
865 EFI_IFR_FLAG_RESET_REQUIRED,\r
866 EFI_IFR_NUMERIC_SIZE_2,\r
75bf9d0e
LG
867 OptionsOpCodeHandle,\r
868 NULL\r
5c08e117 869 );\r
75bf9d0e
LG
870\r
871 HiiFreeOpCodeHandle (OptionsOpCodeHandle);\r
5c08e117 872 FreePool (ModeToken);\r
873\r
874 UpdatePageEnd (CallbackData);\r
875}\r
876\r
877/**\r
878 Create the dynamic page which allows user to set the property such as Baud Rate, Data Bits,\r
879 Parity, Stop Bits, Terminal Type.\r
880\r
881 @param CallbackData The BMM context data.\r
882\r
883**/\r
884VOID\r
885UpdateTerminalPage (\r
886 IN BMM_CALLBACK_DATA *CallbackData\r
887 )\r
888{\r
889 UINT8 Index;\r
890 UINT8 CheckFlags;\r
5c08e117 891 BM_MENU_ENTRY *NewMenuEntry;\r
892 BM_TERMINAL_CONTEXT *NewTerminalContext;\r
75bf9d0e 893 VOID *OptionsOpCodeHandle;\r
5c08e117 894\r
895 CallbackData->BmmAskSaveOrNot = TRUE;\r
896\r
897 UpdatePageStart (CallbackData);\r
898\r
899 NewMenuEntry = BOpt_GetMenuEntry (\r
900 &TerminalMenu,\r
901 CallbackData->CurrentTerminal\r
902 );\r
903\r
904 if (NewMenuEntry == NULL) {\r
905 return ;\r
906 }\r
907\r
908 NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;\r
909\r
75bf9d0e
LG
910 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();\r
911 ASSERT (OptionsOpCodeHandle != NULL);\r
5c08e117 912\r
913 for (Index = 0; Index < sizeof (BaudRateList) / sizeof (BaudRateList [0]); Index++) {\r
914 CheckFlags = 0;\r
915 if (NewTerminalContext->BaudRate == (UINT64) (BaudRateList[Index].Value)) {\r
916 CheckFlags |= EFI_IFR_OPTION_DEFAULT;\r
917 NewTerminalContext->BaudRateIndex = Index;\r
918 CallbackData->BmmFakeNvData.COMBaudRate = NewTerminalContext->BaudRateIndex;\r
919 }\r
920\r
75bf9d0e
LG
921 HiiCreateOneOfOptionOpCode (\r
922 OptionsOpCodeHandle,\r
923 BaudRateList[Index].StringToken,\r
924 CheckFlags,\r
b452ca89 925 EFI_IFR_TYPE_NUM_SIZE_8,\r
75bf9d0e
LG
926 Index\r
927 );\r
5c08e117 928 }\r
929\r
75bf9d0e
LG
930 HiiCreateOneOfOpCode (\r
931 mStartOpCodeHandle,\r
5c08e117 932 (EFI_QUESTION_ID) COM_BAUD_RATE_QUESTION_ID,\r
933 VARSTORE_ID_BOOT_MAINT,\r
934 COM_BAUD_RATE_VAR_OFFSET,\r
935 STRING_TOKEN (STR_COM_BAUD_RATE),\r
936 STRING_TOKEN (STR_COM_BAUD_RATE),\r
937 0,\r
938 EFI_IFR_NUMERIC_SIZE_1,\r
75bf9d0e
LG
939 OptionsOpCodeHandle,\r
940 NULL\r
5c08e117 941 );\r
75bf9d0e
LG
942 \r
943 HiiFreeOpCodeHandle (OptionsOpCodeHandle);\r
944 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();\r
945 ASSERT (OptionsOpCodeHandle != NULL);\r
5c08e117 946\r
947 for (Index = 0; Index < sizeof (DataBitsList) / sizeof (DataBitsList[0]); Index++) {\r
948 CheckFlags = 0;\r
949\r
950 if (NewTerminalContext->DataBits == DataBitsList[Index].Value) {\r
951 NewTerminalContext->DataBitsIndex = Index;\r
952 CallbackData->BmmFakeNvData.COMDataRate = NewTerminalContext->DataBitsIndex;\r
953 CheckFlags |= EFI_IFR_OPTION_DEFAULT;\r
954 }\r
955\r
75bf9d0e
LG
956 HiiCreateOneOfOptionOpCode (\r
957 OptionsOpCodeHandle,\r
958 DataBitsList[Index].StringToken,\r
959 CheckFlags,\r
b452ca89 960 EFI_IFR_TYPE_NUM_SIZE_8,\r
75bf9d0e
LG
961 Index\r
962 );\r
5c08e117 963 }\r
964\r
75bf9d0e
LG
965 HiiCreateOneOfOpCode (\r
966 mStartOpCodeHandle,\r
5c08e117 967 (EFI_QUESTION_ID) COM_DATA_RATE_QUESTION_ID,\r
968 VARSTORE_ID_BOOT_MAINT,\r
969 COM_DATA_RATE_VAR_OFFSET,\r
970 STRING_TOKEN (STR_COM_DATA_BITS),\r
971 STRING_TOKEN (STR_COM_DATA_BITS),\r
972 0,\r
973 EFI_IFR_NUMERIC_SIZE_1,\r
75bf9d0e
LG
974 OptionsOpCodeHandle,\r
975 NULL\r
5c08e117 976 );\r
977\r
75bf9d0e
LG
978 HiiFreeOpCodeHandle (OptionsOpCodeHandle);\r
979 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();\r
980 ASSERT (OptionsOpCodeHandle != NULL);\r
981\r
5c08e117 982 for (Index = 0; Index < sizeof (ParityList) / sizeof (ParityList[0]); Index++) {\r
983 CheckFlags = 0;\r
984 if (NewTerminalContext->Parity == ParityList[Index].Value) {\r
985 CheckFlags |= EFI_IFR_OPTION_DEFAULT;\r
986 NewTerminalContext->ParityIndex = (UINT8) Index;\r
987 CallbackData->BmmFakeNvData.COMParity = NewTerminalContext->ParityIndex;\r
988 }\r
989\r
75bf9d0e
LG
990 HiiCreateOneOfOptionOpCode (\r
991 OptionsOpCodeHandle,\r
992 ParityList[Index].StringToken,\r
993 CheckFlags,\r
b452ca89 994 EFI_IFR_TYPE_NUM_SIZE_8,\r
75bf9d0e
LG
995 Index\r
996 );\r
5c08e117 997 }\r
998\r
75bf9d0e
LG
999 HiiCreateOneOfOpCode (\r
1000 mStartOpCodeHandle,\r
5c08e117 1001 (EFI_QUESTION_ID) COM_PARITY_QUESTION_ID,\r
1002 VARSTORE_ID_BOOT_MAINT,\r
1003 COM_PARITY_VAR_OFFSET,\r
1004 STRING_TOKEN (STR_COM_PARITY),\r
1005 STRING_TOKEN (STR_COM_PARITY),\r
1006 0,\r
1007 EFI_IFR_NUMERIC_SIZE_1,\r
75bf9d0e
LG
1008 OptionsOpCodeHandle,\r
1009 NULL\r
5c08e117 1010 );\r
1011\r
75bf9d0e
LG
1012 HiiFreeOpCodeHandle (OptionsOpCodeHandle);\r
1013 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();\r
1014 ASSERT (OptionsOpCodeHandle != NULL);\r
1015\r
5c08e117 1016 for (Index = 0; Index < sizeof (StopBitsList) / sizeof (StopBitsList[0]); Index++) {\r
1017 CheckFlags = 0;\r
1018 if (NewTerminalContext->StopBits == StopBitsList[Index].Value) {\r
1019 CheckFlags |= EFI_IFR_OPTION_DEFAULT;\r
1020 NewTerminalContext->StopBitsIndex = (UINT8) Index;\r
1021 CallbackData->BmmFakeNvData.COMStopBits = NewTerminalContext->StopBitsIndex;\r
1022 }\r
1023\r
75bf9d0e
LG
1024 HiiCreateOneOfOptionOpCode (\r
1025 OptionsOpCodeHandle,\r
1026 StopBitsList[Index].StringToken,\r
1027 CheckFlags,\r
b452ca89 1028 EFI_IFR_TYPE_NUM_SIZE_8,\r
75bf9d0e
LG
1029 Index\r
1030 );\r
5c08e117 1031 }\r
1032\r
75bf9d0e
LG
1033 HiiCreateOneOfOpCode (\r
1034 mStartOpCodeHandle,\r
5c08e117 1035 (EFI_QUESTION_ID) COM_STOP_BITS_QUESTION_ID,\r
1036 VARSTORE_ID_BOOT_MAINT,\r
1037 COM_STOP_BITS_VAR_OFFSET,\r
1038 STRING_TOKEN (STR_COM_STOP_BITS),\r
1039 STRING_TOKEN (STR_COM_STOP_BITS),\r
1040 0,\r
1041 EFI_IFR_NUMERIC_SIZE_1,\r
75bf9d0e
LG
1042 OptionsOpCodeHandle,\r
1043 NULL\r
5c08e117 1044 );\r
1045\r
75bf9d0e
LG
1046 HiiFreeOpCodeHandle (OptionsOpCodeHandle);\r
1047 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();\r
1048 ASSERT (OptionsOpCodeHandle != NULL);\r
1049\r
5c08e117 1050 for (Index = 0; Index < 4; Index++) {\r
1051 CheckFlags = 0;\r
1052 if (NewTerminalContext->TerminalType == Index) {\r
1053 CheckFlags |= EFI_IFR_OPTION_DEFAULT;\r
1054 CallbackData->BmmFakeNvData.COMTerminalType = NewTerminalContext->TerminalType;\r
1055 }\r
1056\r
75bf9d0e
LG
1057 HiiCreateOneOfOptionOpCode (\r
1058 OptionsOpCodeHandle,\r
1059 (EFI_STRING_ID) TerminalType[Index],\r
1060 CheckFlags,\r
b452ca89 1061 EFI_IFR_TYPE_NUM_SIZE_8,\r
75bf9d0e
LG
1062 Index\r
1063 );\r
5c08e117 1064 }\r
1065\r
75bf9d0e
LG
1066 HiiCreateOneOfOpCode (\r
1067 mStartOpCodeHandle,\r
5c08e117 1068 (EFI_QUESTION_ID) COM_TERMINAL_QUESTION_ID,\r
1069 VARSTORE_ID_BOOT_MAINT,\r
1070 COM_TERMINAL_VAR_OFFSET,\r
1071 STRING_TOKEN (STR_COM_TERMI_TYPE),\r
1072 STRING_TOKEN (STR_COM_TERMI_TYPE),\r
1073 0,\r
1074 EFI_IFR_NUMERIC_SIZE_1,\r
75bf9d0e
LG
1075 OptionsOpCodeHandle,\r
1076 NULL\r
5c08e117 1077 );\r
1078\r
8e491a81
ED
1079 HiiFreeOpCodeHandle (OptionsOpCodeHandle);\r
1080 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();\r
1081 ASSERT (OptionsOpCodeHandle != NULL);\r
1082\r
1083 CallbackData->BmmFakeNvData.COMFlowControl = NewTerminalContext->FlowControl;\r
1084 for (Index = 0; Index < sizeof (mFlowControlType) / sizeof (mFlowControlType[0]); Index++) {\r
1085 HiiCreateOneOfOptionOpCode (\r
1086 OptionsOpCodeHandle,\r
1087 (EFI_STRING_ID) mFlowControlType[Index],\r
1088 0,\r
1089 EFI_IFR_TYPE_NUM_SIZE_8,\r
1090 mFlowControlValue[Index]\r
1091 );\r
1092 }\r
1093\r
1094 HiiCreateOneOfOpCode (\r
1095 mStartOpCodeHandle,\r
1096 (EFI_QUESTION_ID) COM_FLOWCONTROL_QUESTION_ID,\r
1097 VARSTORE_ID_BOOT_MAINT,\r
1098 COM_FLOWCONTROL_VAR_OFFSET,\r
1099 STRING_TOKEN (STR_COM_FLOW_CONTROL),\r
1100 STRING_TOKEN (STR_COM_FLOW_CONTROL),\r
1101 0,\r
1102 EFI_IFR_NUMERIC_SIZE_1,\r
1103 OptionsOpCodeHandle,\r
1104 NULL\r
1105 );\r
1106\r
75bf9d0e 1107 HiiFreeOpCodeHandle (OptionsOpCodeHandle);\r
5c08e117 1108\r
1109 UpdatePageEnd (CallbackData);\r
1110}\r
1111\r
1112/**\r
1113 Dispatch the correct update page function to call based on\r
1114 the UpdatePageId.\r
1115\r
1116 @param UpdatePageId The form ID.\r
1117 @param CallbackData The BMM context data.\r
1118\r
1119**/\r
1120VOID\r
1121UpdatePageBody (\r
1122 IN UINT16 UpdatePageId,\r
1123 IN BMM_CALLBACK_DATA *CallbackData\r
1124 )\r
1125{\r
1126 CleanUpPage (UpdatePageId, CallbackData);\r
1127 switch (UpdatePageId) {\r
1128 case FORM_CON_IN_ID:\r
1129 UpdateConsolePage (UpdatePageId, &ConsoleInpMenu, CallbackData);\r
1130 break;\r
1131\r
1132 case FORM_CON_OUT_ID:\r
1133 UpdateConsolePage (UpdatePageId, &ConsoleOutMenu, CallbackData);\r
1134 break;\r
1135\r
1136 case FORM_CON_ERR_ID:\r
1137 UpdateConsolePage (UpdatePageId, &ConsoleErrMenu, CallbackData);\r
1138 break;\r
1139\r
1140 case FORM_BOOT_CHG_ID:\r
1141 UpdateOrderPage (UpdatePageId, &BootOptionMenu, CallbackData);\r
1142 break;\r
1143\r
1144 case FORM_DRV_CHG_ID:\r
1145 UpdateOrderPage (UpdatePageId, &DriverOptionMenu, CallbackData);\r
1146 break;\r
1147\r
1148 default:\r
1149 break;\r
1150 }\r
1151}\r
1152\r
1153/**\r
1154 Get the index number (#### in Boot####) for the boot option pointed to a BBS legacy device type\r
1155 specified by DeviceType.\r
1156\r
1157 @param DeviceType The legacy device type. It can be floppy, network, harddisk, cdrom,\r
1158 etc.\r
1159 @param OptionIndex Returns the index number (#### in Boot####).\r
1160 @param OptionSize Return the size of the Boot### variable.\r
1161\r
1162**/\r
1163VOID *\r
1164GetLegacyBootOptionVar (\r
1165 IN UINTN DeviceType,\r
1166 OUT UINTN *OptionIndex,\r
1167 OUT UINTN *OptionSize\r
1168 )\r
1169{\r
1170 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
1171 VOID *OptionBuffer;\r
1172 UINTN OrderSize;\r
1173 UINTN Index;\r
1174 UINT16 *OrderBuffer;\r
1175 CHAR16 StrTemp[100];\r
1176 UINT16 FilePathSize;\r
1177 UINT8 *Ptr;\r
1178 UINT8 *OptionalData;\r
1179\r
1180 //\r
1181 // Get Boot Option number from the size of BootOrder\r
1182 //\r
1183 OrderBuffer = BdsLibGetVariableAndSize (\r
1184 L"BootOrder",\r
1185 &gEfiGlobalVariableGuid,\r
1186 &OrderSize\r
1187 );\r
1188 \r
1189 if (OrderBuffer == NULL) {\r
1190 return NULL;\r
1191 }\r
1192 \r
1193 for (Index = 0; Index < OrderSize / sizeof (UINT16); Index++) {\r
1194 UnicodeSPrint (StrTemp, 100, L"Boot%04x", OrderBuffer[Index]);\r
1195 OptionBuffer = BdsLibGetVariableAndSize (\r
1196 StrTemp,\r
1197 &gEfiGlobalVariableGuid,\r
1198 OptionSize\r
1199 );\r
1200 if (NULL == OptionBuffer) {\r
1201 continue;\r
1202 }\r
1203\r
1204 Ptr = (UINT8 *) OptionBuffer;\r
1205 Ptr += sizeof (UINT32);\r
1206\r
1207 FilePathSize = *(UINT16 *) Ptr;\r
1208 Ptr += sizeof (UINT16);\r
1209\r
1210 Ptr += StrSize ((CHAR16 *) Ptr);\r
1211\r
1212 //\r
1213 // Now Ptr point to Device Path\r
1214 //\r
1215 DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) Ptr;\r
1216 Ptr += FilePathSize;\r
1217\r
1218 //\r
1219 // Now Ptr point to Optional Data\r
1220 //\r
1221 OptionalData = Ptr;\r
1222\r
1223 if ((DeviceType == ((BBS_TABLE *) OptionalData)->DeviceType) &&\r
1224 (BBS_DEVICE_PATH == DevicePath->Type) &&\r
1225 (BBS_BBS_DP == DevicePath->SubType)\r
1226 ) {\r
1227 *OptionIndex = OrderBuffer[Index];\r
1228 FreePool (OrderBuffer);\r
1229 return OptionBuffer;\r
1230 } else {\r
1231 FreePool (OptionBuffer);\r
1232 }\r
1233 }\r
1234\r
1235 FreePool (OrderBuffer);\r
1236 return NULL;\r
1237}\r
1238\r
1239/**\r
1240 Create a dynamic page so that Legacy Device boot order\r
1241 can be set for specified device type.\r
1242\r
1243 @param UpdatePageId The form ID. It also spefies the legacy device type.\r
1244 @param CallbackData The BMM context data.\r
1245\r
1246\r
1247**/\r
1248VOID\r
1249UpdateSetLegacyDeviceOrderPage (\r
1250 IN UINT16 UpdatePageId,\r
1251 IN BMM_CALLBACK_DATA *CallbackData\r
1252 )\r
1253{\r
e24fc103 1254 LEGACY_DEV_ORDER_ENTRY *DevOrder;\r
5c08e117 1255 BM_MENU_OPTION *OptionMenu;\r
1256 BM_MENU_ENTRY *NewMenuEntry;\r
5c08e117 1257 EFI_STRING_ID StrRef;\r
1258 EFI_STRING_ID StrRefHelp;\r
1259 BBS_TYPE BbsType;\r
1260 UINTN VarSize;\r
1261 UINTN Pos;\r
1262 UINTN Bit;\r
1263 UINT16 Index;\r
1264 UINT16 Key;\r
1265 CHAR16 String[100];\r
1266 CHAR16 *TypeStr;\r
1267 CHAR16 *TypeStrHelp;\r
1268 UINT16 VarDevOrder;\r
1269 UINT8 *VarData;\r
1270 UINT8 *LegacyOrder;\r
1271 UINT8 *OldData;\r
1272 UINT8 *DisMap;\r
75bf9d0e 1273 VOID *OptionsOpCodeHandle;\r
5c08e117 1274\r
1275 OptionMenu = NULL;\r
1276 Key = 0;\r
1277 StrRef = 0;\r
1278 StrRefHelp = 0;\r
1279 TypeStr = NULL;\r
1280 TypeStrHelp = NULL;\r
1281 BbsType = BBS_FLOPPY;\r
1282 LegacyOrder = NULL;\r
1283 OldData = NULL;\r
1284 DisMap = NULL;\r
1285\r
1286 CallbackData->BmmAskSaveOrNot = TRUE;\r
1287 UpdatePageStart (CallbackData);\r
1288\r
22d1f978 1289 DisMap = ZeroMem (CallbackData->BmmOldFakeNVData.DisableMap, sizeof (CallbackData->BmmOldFakeNVData.DisableMap));\r
5c08e117 1290\r
5c08e117 1291 //\r
1292 // Create oneof option list\r
1293 //\r
1294 switch (UpdatePageId) {\r
1295 case FORM_SET_FD_ORDER_ID:\r
1296 OptionMenu = (BM_MENU_OPTION *) &LegacyFDMenu;\r
1297 Key = (UINT16) LEGACY_FD_QUESTION_ID;\r
1298 TypeStr = STR_FLOPPY;\r
1299 TypeStrHelp = STR_FLOPPY_HELP;\r
1300 BbsType = BBS_FLOPPY;\r
1301 LegacyOrder = CallbackData->BmmFakeNvData.LegacyFD;\r
1302 OldData = CallbackData->BmmOldFakeNVData.LegacyFD;\r
1303 break;\r
1304\r
1305 case FORM_SET_HD_ORDER_ID:\r
1306 OptionMenu = (BM_MENU_OPTION *) &LegacyHDMenu;\r
1307 Key = (UINT16) LEGACY_HD_QUESTION_ID;\r
1308 TypeStr = STR_HARDDISK;\r
1309 TypeStrHelp = STR_HARDDISK_HELP;\r
1310 BbsType = BBS_HARDDISK;\r
1311 LegacyOrder = CallbackData->BmmFakeNvData.LegacyHD;\r
1312 OldData = CallbackData->BmmOldFakeNVData.LegacyHD;\r
1313 break;\r
1314\r
1315 case FORM_SET_CD_ORDER_ID:\r
1316 OptionMenu = (BM_MENU_OPTION *) &LegacyCDMenu;\r
1317 Key = (UINT16) LEGACY_CD_QUESTION_ID;\r
1318 TypeStr = STR_CDROM;\r
1319 TypeStrHelp = STR_CDROM_HELP;\r
1320 BbsType = BBS_CDROM;\r
1321 LegacyOrder = CallbackData->BmmFakeNvData.LegacyCD;\r
1322 OldData = CallbackData->BmmOldFakeNVData.LegacyCD;\r
1323 break;\r
1324\r
1325 case FORM_SET_NET_ORDER_ID:\r
1326 OptionMenu = (BM_MENU_OPTION *) &LegacyNETMenu;\r
1327 Key = (UINT16) LEGACY_NET_QUESTION_ID;\r
1328 TypeStr = STR_NET;\r
1329 TypeStrHelp = STR_NET_HELP;\r
1330 BbsType = BBS_EMBED_NETWORK;\r
1331 LegacyOrder = CallbackData->BmmFakeNvData.LegacyNET;\r
1332 OldData = CallbackData->BmmOldFakeNVData.LegacyNET;\r
1333 break;\r
1334\r
1335 case FORM_SET_BEV_ORDER_ID:\r
1336 OptionMenu = (BM_MENU_OPTION *) &LegacyBEVMenu;\r
1337 Key = (UINT16) LEGACY_BEV_QUESTION_ID;\r
1338 TypeStr = STR_BEV;\r
1339 TypeStrHelp = STR_BEV_HELP;\r
1340 BbsType = BBS_BEV_DEVICE;\r
1341 LegacyOrder = CallbackData->BmmFakeNvData.LegacyBEV;\r
1342 OldData = CallbackData->BmmOldFakeNVData.LegacyBEV;\r
1343 break;\r
1344\r
1345 default:\r
1346 DEBUG ((EFI_D_ERROR, "Invalid command ID for updating page!\n"));\r
1347 return;\r
1348 }\r
1349\r
1350 CreateMenuStringToken (CallbackData, CallbackData->BmmHiiHandle, OptionMenu);\r
1351\r
75bf9d0e
LG
1352 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();\r
1353 ASSERT (OptionsOpCodeHandle != NULL);\r
5c08e117 1354\r
1355 for (Index = 0; Index < OptionMenu->MenuNumber; Index++) {\r
1356 NewMenuEntry = BOpt_GetMenuEntry (OptionMenu, Index);\r
b1620d0b 1357 //\r
22d1f978 1358 // Create OneOf for each legacy device\r
b1620d0b 1359 //\r
75bf9d0e
LG
1360 HiiCreateOneOfOptionOpCode (\r
1361 OptionsOpCodeHandle,\r
1362 NewMenuEntry->DisplayStringToken,\r
22d1f978 1363 0,\r
b452ca89 1364 EFI_IFR_TYPE_NUM_SIZE_8,\r
22d1f978 1365 (UINT8) ((BM_LEGACY_DEVICE_CONTEXT *) NewMenuEntry->VariableContext)->BbsIndex\r
75bf9d0e 1366 );\r
5c08e117 1367 }\r
75bf9d0e 1368\r
5c08e117 1369 //\r
22d1f978 1370 // Create OneOf for item "Disabled"\r
5c08e117 1371 //\r
75bf9d0e
LG
1372 HiiCreateOneOfOptionOpCode (\r
1373 OptionsOpCodeHandle,\r
1374 STRING_TOKEN (STR_DISABLE_LEGACY_DEVICE),\r
1375 0,\r
b452ca89 1376 EFI_IFR_TYPE_NUM_SIZE_8,\r
75bf9d0e
LG
1377 0xFF\r
1378 );\r
5c08e117 1379\r
1380 //\r
1381 // Get Device Order from variable\r
1382 //\r
1383 VarData = BdsLibGetVariableAndSize (\r
1384 VAR_LEGACY_DEV_ORDER,\r
e24fc103 1385 &gEfiLegacyDevOrderVariableGuid,\r
5c08e117 1386 &VarSize\r
1387 );\r
1388\r
1389 if (NULL != VarData) {\r
e24fc103 1390 DevOrder = (LEGACY_DEV_ORDER_ENTRY *) VarData;\r
5c08e117 1391 while (VarData < VarData + VarSize) {\r
1392 if (DevOrder->BbsType == BbsType) {\r
1393 break;\r
1394 }\r
1395\r
1396 VarData += sizeof (BBS_TYPE);\r
1397 VarData += *(UINT16 *) VarData;\r
e24fc103 1398 DevOrder = (LEGACY_DEV_ORDER_ENTRY *) VarData;\r
5c08e117 1399 }\r
1400 //\r
1401 // Create oneof tag here for FD/HD/CD #1 #2\r
1402 //\r
1403 for (Index = 0; Index < OptionMenu->MenuNumber; Index++) {\r
1404 //\r
1405 // Create the string for oneof tag\r
1406 //\r
1407 UnicodeSPrint (String, sizeof (String), TypeStr, Index);\r
cb7d01c0 1408 StrRef = HiiSetString (CallbackData->BmmHiiHandle, 0, String, NULL);\r
5c08e117 1409\r
1410 UnicodeSPrint (String, sizeof (String), TypeStrHelp, Index);\r
cb7d01c0 1411 StrRefHelp = HiiSetString (CallbackData->BmmHiiHandle, 0, String, NULL);\r
5c08e117 1412\r
75bf9d0e
LG
1413 HiiCreateOneOfOpCode (\r
1414 mStartOpCodeHandle,\r
5c08e117 1415 (EFI_QUESTION_ID) (Key + Index),\r
1416 VARSTORE_ID_BOOT_MAINT,\r
1417 (UINT16) (Key + Index - CONFIG_OPTION_OFFSET),\r
1418 StrRef,\r
1419 StrRefHelp,\r
1420 EFI_IFR_FLAG_CALLBACK,\r
1421 EFI_IFR_NUMERIC_SIZE_1,\r
75bf9d0e
LG
1422 OptionsOpCodeHandle,\r
1423 NULL\r
5c08e117 1424 );\r
1425\r
1426 VarDevOrder = *(UINT16 *) ((UINT8 *) DevOrder + sizeof (BBS_TYPE) + sizeof (UINT16) + Index * sizeof (UINT16));\r
1427\r
1428 if (0xFF00 == (VarDevOrder & 0xFF00)) {\r
1429 LegacyOrder[Index] = 0xFF;\r
1430 Pos = (VarDevOrder & 0xFF) / 8;\r
1431 Bit = 7 - ((VarDevOrder & 0xFF) % 8);\r
1432 DisMap[Pos] = (UINT8) (DisMap[Pos] | (UINT8) (1 << Bit));\r
1433 } else {\r
1434 LegacyOrder[Index] = (UINT8) (VarDevOrder & 0xFF);\r
1435 }\r
1436 }\r
1437 }\r
1438\r
1439 CopyMem (OldData, LegacyOrder, 100);\r
1440\r
75bf9d0e 1441 HiiFreeOpCodeHandle (OptionsOpCodeHandle);\r
5c08e117 1442\r
1443 UpdatePageEnd (CallbackData);\r
1444}\r
1445\r
1446/**\r
1447 Dispatch the display to the next page based on NewPageId.\r
1448\r
1449 @param Private The BMM context data.\r
1450 @param NewPageId The original page ID.\r
1451\r
1452**/\r
1453VOID\r
1454UpdatePageId (\r
1455 BMM_CALLBACK_DATA *Private,\r
1456 UINT16 NewPageId\r
1457 )\r
1458{\r
1459 if ((NewPageId < FILE_OPTION_OFFSET) && (NewPageId >= HANDLE_OPTION_OFFSET)) {\r
1460 //\r
1461 // If we select a handle to add driver option, advance to the add handle description page.\r
1462 //\r
1463 NewPageId = FORM_DRV_ADD_HANDLE_DESC_ID;\r
1464 } else if ((NewPageId == KEY_VALUE_SAVE_AND_EXIT) || (NewPageId == KEY_VALUE_NO_SAVE_AND_EXIT)) {\r
1465 //\r
1466 // Return to main page after "Save Changes" or "Discard Changes".\r
1467 //\r
1468 NewPageId = FORM_MAIN_ID;\r
1469 } else if ((NewPageId >= TERMINAL_OPTION_OFFSET) && (NewPageId < CONSOLE_OPTION_OFFSET)) {\r
1470 NewPageId = FORM_CON_COM_SETUP_ID;\r
1471 }\r
1472\r
1473 if ((NewPageId > 0) && (NewPageId < MAXIMUM_FORM_ID)) {\r
1474 Private->BmmPreviousPageId = Private->BmmCurrentPageId;\r
1475 Private->BmmCurrentPageId = NewPageId;\r
1476 }\r
1477}\r