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