1. Correct Col * Row string
[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
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
75bf9d0e
LG
102 HiiCreateGotoOpCode (\r
103 mStartOpCodeHandle,\r
5c08e117 104 FORM_MAIN_ID,\r
105 STRING_TOKEN (STR_SAVE_AND_EXIT),\r
106 STRING_TOKEN (STR_NULL_STRING),\r
107 EFI_IFR_FLAG_CALLBACK,\r
75bf9d0e 108 KEY_VALUE_SAVE_AND_EXIT\r
5c08e117 109 );\r
110 }\r
111\r
112 //\r
113 // Ensure user can return to the main page.\r
114 //\r
75bf9d0e
LG
115 HiiCreateGotoOpCode (\r
116 mStartOpCodeHandle,\r
5c08e117 117 FORM_MAIN_ID,\r
118 STRING_TOKEN (STR_NO_SAVE_AND_EXIT),\r
119 STRING_TOKEN (STR_NULL_STRING),\r
120 EFI_IFR_FLAG_CALLBACK,\r
75bf9d0e 121 KEY_VALUE_NO_SAVE_AND_EXIT\r
5c08e117 122 );\r
123\r
75bf9d0e 124 HiiUpdateForm (\r
5c08e117 125 CallbackData->BmmHiiHandle,\r
126 &mBootMaintGuid,\r
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
154 &mBootMaintGuid,\r
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
183 Option->Description = FileContext->FileName;\r
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
257 ASSERT (BootOptionMenu.MenuNumber <= (sizeof (CallbackData->BmmFakeNvData.BootOptionDel) / sizeof (CallbackData->BmmFakeNvData.BootOptionDel[0])));\r
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
266 CallbackData->BmmFakeNvData.BootOptionDel[Index] = 0x00;\r
267\r
75bf9d0e
LG
268 HiiCreateCheckBoxOpCode (\r
269 mStartOpCodeHandle,\r
5c08e117 270 (EFI_QUESTION_ID) (BOOT_OPTION_DEL_QUESTION_ID + Index),\r
271 VARSTORE_ID_BOOT_MAINT,\r
272 (UINT16) (BOOT_OPTION_DEL_VAR_OFFSET + Index),\r
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
340 ASSERT (DriverOptionMenu.MenuNumber <= (sizeof (CallbackData->BmmFakeNvData.DriverOptionDel) / sizeof (CallbackData->BmmFakeNvData.DriverOptionDel[0])));\r
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
346 CallbackData->BmmFakeNvData.DriverOptionDel[Index] = 0x00;\r
347\r
75bf9d0e
LG
348 HiiCreateCheckBoxOpCode (\r
349 mStartOpCodeHandle,\r
5c08e117 350 (EFI_QUESTION_ID) (DRIVER_OPTION_DEL_QUESTION_ID + Index),\r
351 VARSTORE_ID_BOOT_MAINT,\r
352 (UINT16) (DRIVER_OPTION_DEL_VAR_OFFSET + Index),\r
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
538 BM_MENU_ENTRY *NewMenuEntry;\r
539 UINT16 Index;\r
75bf9d0e 540 VOID *OptionsOpCodeHandle;\r
5c08e117 541\r
542 CallbackData->BmmAskSaveOrNot = TRUE;\r
543\r
544 UpdatePageStart (CallbackData);\r
545\r
546 CreateMenuStringToken (CallbackData, CallbackData->BmmHiiHandle, OptionMenu);\r
547\r
548 ZeroMem (CallbackData->BmmFakeNvData.OptionOrder, 100);\r
549\r
75bf9d0e
LG
550 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();\r
551 ASSERT (OptionsOpCodeHandle != NULL);\r
5c08e117 552 \r
8bb37919 553 for (\r
554 Index = 0;\r
555 (\r
556 (Index < OptionMenu->MenuNumber) &&\r
557 (Index <\r
558 (\r
559 sizeof (CallbackData->BmmFakeNvData.OptionOrder) /\r
560 sizeof (UINT8)\r
561 )\r
562 )\r
563 );\r
564 Index++\r
565 ) {\r
5c08e117 566 NewMenuEntry = BOpt_GetMenuEntry (OptionMenu, Index);\r
75bf9d0e
LG
567 HiiCreateOneOfOptionOpCode (\r
568 OptionsOpCodeHandle,\r
569 NewMenuEntry->DisplayStringToken,\r
570 0,\r
571 EFI_IFR_NUMERIC_SIZE_1,\r
572 (UINT8) (NewMenuEntry->OptionNumber + 1)\r
573 );\r
574 CallbackData->BmmFakeNvData.OptionOrder[Index] = (UINT8) (NewMenuEntry->OptionNumber + 1);\r
5c08e117 575 }\r
576\r
577 if (OptionMenu->MenuNumber > 0) {\r
75bf9d0e
LG
578 HiiCreateOrderedListOpCode ( \r
579 mStartOpCodeHandle, // Container for dynamic created opcodes \r
580 (EFI_QUESTION_ID) OPTION_ORDER_QUESTION_ID, // Question ID \r
581 VARSTORE_ID_BOOT_MAINT, // VarStore ID \r
582 OPTION_ORDER_VAR_OFFSET, // Offset in Buffer Storage \r
583 STRING_TOKEN (STR_CHANGE_ORDER), // Question prompt text \r
584 STRING_TOKEN (STR_CHANGE_ORDER), // Question help text \r
585 0, // Question flag \r
586 0, // Ordered list flag, e.g. EFI_IFR_UNIQUE_SET\r
587 EFI_IFR_NUMERIC_SIZE_1, // Data type of Question value \r
588 100, // Maximum container \r
589 OptionsOpCodeHandle, // Option Opcode list \r
590 NULL // Default Opcode is NULL \r
5c08e117 591 );\r
592 }\r
593\r
75bf9d0e 594 HiiFreeOpCodeHandle (OptionsOpCodeHandle);\r
5c08e117 595\r
596 UpdatePageEnd (CallbackData);\r
597\r
598 CopyMem (\r
599 CallbackData->BmmOldFakeNVData.OptionOrder,\r
600 CallbackData->BmmFakeNvData.OptionOrder,\r
601 100\r
602 );\r
603}\r
604\r
605/**\r
606 Create the dynamic page to allow user to set\r
607 the "BootNext" value.\r
608\r
609 @param CallbackData The BMM context data.\r
610\r
611**/\r
612VOID\r
613UpdateBootNextPage (\r
614 IN BMM_CALLBACK_DATA *CallbackData\r
615 )\r
616{\r
617 BM_MENU_ENTRY *NewMenuEntry;\r
618 BM_LOAD_CONTEXT *NewLoadContext;\r
5c08e117 619 UINTN NumberOfOptions;\r
620 UINT16 Index;\r
75bf9d0e 621 VOID *OptionsOpCodeHandle;\r
5c08e117 622\r
5c08e117 623 NumberOfOptions = BootOptionMenu.MenuNumber;\r
624 CallbackData->BmmAskSaveOrNot = TRUE;\r
625\r
626 UpdatePageStart (CallbackData);\r
627 CreateMenuStringToken (CallbackData, CallbackData->BmmHiiHandle, &BootOptionMenu);\r
628\r
629 if (NumberOfOptions > 0) {\r
75bf9d0e
LG
630 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();\r
631 ASSERT (OptionsOpCodeHandle != NULL);\r
5c08e117 632\r
633 CallbackData->BmmFakeNvData.BootNext = (UINT16) (BootOptionMenu.MenuNumber);\r
634\r
635 for (Index = 0; Index < BootOptionMenu.MenuNumber; Index++) {\r
636 NewMenuEntry = BOpt_GetMenuEntry (&BootOptionMenu, Index);\r
637 NewLoadContext = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext;\r
75bf9d0e 638\r
5c08e117 639 if (NewLoadContext->IsBootNext) {\r
75bf9d0e
LG
640 HiiCreateOneOfOptionOpCode (\r
641 OptionsOpCodeHandle,\r
642 NewMenuEntry->DisplayStringToken,\r
643 EFI_IFR_OPTION_DEFAULT,\r
644 EFI_IFR_NUMERIC_SIZE_2,\r
645 Index\r
646 );\r
5c08e117 647 CallbackData->BmmFakeNvData.BootNext = Index;\r
648 } else {\r
75bf9d0e
LG
649 HiiCreateOneOfOptionOpCode (\r
650 OptionsOpCodeHandle,\r
651 NewMenuEntry->DisplayStringToken,\r
652 0,\r
653 EFI_IFR_NUMERIC_SIZE_2,\r
654 Index\r
655 );\r
5c08e117 656 }\r
5c08e117 657 }\r
658\r
5c08e117 659 if (CallbackData->BmmFakeNvData.BootNext == Index) {\r
75bf9d0e
LG
660 HiiCreateOneOfOptionOpCode (\r
661 OptionsOpCodeHandle,\r
662 STRING_TOKEN (STR_NONE),\r
663 EFI_IFR_OPTION_DEFAULT,\r
664 EFI_IFR_NUMERIC_SIZE_2,\r
665 Index\r
666 );\r
667 } else {\r
668 HiiCreateOneOfOptionOpCode (\r
669 OptionsOpCodeHandle,\r
670 STRING_TOKEN (STR_NONE),\r
671 0,\r
672 EFI_IFR_NUMERIC_SIZE_2,\r
673 Index\r
674 );\r
675 } \r
5c08e117 676\r
75bf9d0e
LG
677 HiiCreateOneOfOpCode (\r
678 mStartOpCodeHandle,\r
5c08e117 679 (EFI_QUESTION_ID) BOOT_NEXT_QUESTION_ID,\r
680 VARSTORE_ID_BOOT_MAINT,\r
681 BOOT_NEXT_VAR_OFFSET,\r
682 STRING_TOKEN (STR_BOOT_NEXT),\r
683 STRING_TOKEN (STR_BOOT_NEXT_HELP),\r
684 0,\r
685 EFI_IFR_NUMERIC_SIZE_2,\r
75bf9d0e
LG
686 OptionsOpCodeHandle,\r
687 NULL\r
5c08e117 688 );\r
689\r
75bf9d0e 690 HiiFreeOpCodeHandle (OptionsOpCodeHandle);\r
5c08e117 691 }\r
692\r
693 UpdatePageEnd (CallbackData);\r
694}\r
695\r
696/**\r
697 Create the dynamic page to allow user to set the "TimeOut" value.\r
698\r
699 @param CallbackData The BMM context data.\r
700\r
701**/\r
702VOID\r
703UpdateTimeOutPage (\r
704 IN BMM_CALLBACK_DATA *CallbackData\r
705 )\r
706{\r
707 UINT16 BootTimeOut;\r
75bf9d0e 708 VOID *DefaultOpCodeHandle;\r
5c08e117 709\r
710 CallbackData->BmmAskSaveOrNot = TRUE;\r
711\r
712 UpdatePageStart (CallbackData);\r
713\r
8c81cb83 714 BootTimeOut = PcdGet16 (PcdPlatformBootTimeOut);\r
5c08e117 715\r
75bf9d0e
LG
716 DefaultOpCodeHandle = HiiAllocateOpCodeHandle ();\r
717 ASSERT (DefaultOpCodeHandle != NULL);\r
718 HiiCreateDefaultOpCode (DefaultOpCodeHandle, EFI_HII_DEFAULT_CLASS_STANDARD, EFI_IFR_NUMERIC_SIZE_2, BootTimeOut);\r
719\r
720 HiiCreateNumericOpCode (\r
721 mStartOpCodeHandle,\r
5c08e117 722 (EFI_QUESTION_ID) BOOT_TIME_OUT_QUESTION_ID,\r
723 VARSTORE_ID_BOOT_MAINT,\r
724 BOOT_TIME_OUT_VAR_OFFSET,\r
725 STRING_TOKEN (STR_NUM_AUTO_BOOT),\r
726 STRING_TOKEN (STR_HLP_AUTO_BOOT),\r
727 0,\r
728 EFI_IFR_NUMERIC_SIZE_2 | EFI_IFR_DISPLAY_UINT_DEC,\r
729 0,\r
730 65535,\r
731 0,\r
75bf9d0e 732 DefaultOpCodeHandle\r
5c08e117 733 );\r
75bf9d0e
LG
734 \r
735 HiiFreeOpCodeHandle (DefaultOpCodeHandle);\r
5c08e117 736\r
737 CallbackData->BmmFakeNvData.BootTimeOut = BootTimeOut;\r
738\r
739 UpdatePageEnd (CallbackData);\r
740}\r
741\r
742/**\r
743 Refresh the text mode page.\r
744\r
745 @param CallbackData The BMM context data.\r
746\r
747**/\r
748VOID\r
749UpdateConModePage (\r
750 IN BMM_CALLBACK_DATA *CallbackData\r
751 )\r
752{\r
753 UINTN Mode;\r
754 UINTN Index;\r
755 UINTN Col;\r
756 UINTN Row;\r
5c08e117 757 CHAR16 ModeString[50];\r
19bf20e1 758 CHAR16 *PStr;\r
5c08e117 759 UINTN MaxMode;\r
760 UINTN ValidMode;\r
761 EFI_STRING_ID *ModeToken;\r
5c08e117 762 EFI_STATUS Status;\r
75bf9d0e 763 VOID *OptionsOpCodeHandle;\r
5c08e117 764 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut;\r
765\r
766 ConOut = gST->ConOut;\r
767 Index = 0;\r
768 ValidMode = 0;\r
769 MaxMode = (UINTN) (ConOut->Mode->MaxMode);\r
770\r
771 CallbackData->BmmAskSaveOrNot = TRUE;\r
772\r
773 UpdatePageStart (CallbackData);\r
774\r
775 //\r
776 // Check valid mode\r
777 //\r
778 for (Mode = 0; Mode < MaxMode; Mode++) {\r
779 Status = ConOut->QueryMode (ConOut, Mode, &Col, &Row);\r
780 if (EFI_ERROR (Status)) {\r
781 continue;\r
782 }\r
783 ValidMode++;\r
784 }\r
785\r
786 if (ValidMode == 0) {\r
787 return;\r
788 }\r
789\r
75bf9d0e
LG
790 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();\r
791 ASSERT (OptionsOpCodeHandle != NULL);\r
5c08e117 792\r
793 ModeToken = AllocateZeroPool (sizeof (EFI_STRING_ID) * ValidMode);\r
794 ASSERT(ModeToken != NULL);\r
795\r
796 //\r
797 // Determin which mode should be the first entry in menu\r
798 //\r
799 GetConsoleOutMode (CallbackData);\r
800\r
801 //\r
802 // Build text mode options\r
803 //\r
804 for (Mode = 0; Mode < MaxMode; Mode++) {\r
805 Status = ConOut->QueryMode (ConOut, Mode, &Col, &Row);\r
806 if (EFI_ERROR (Status)) {\r
807 continue;\r
808 }\r
809 \r
810 //\r
811 // Build mode string Column x Row\r
812 //\r
7a45e5aa 813 UnicodeValueToString (ModeString, 0, Col, 0);\r
19bf20e1 814 PStr = &ModeString[0];\r
b55f8b01
LG
815 StrnCat (PStr, L" x ", StrLen(L" x ") + 1);\r
816 PStr = PStr + StrLen (PStr);\r
817 UnicodeValueToString (PStr , 0, Row, 0);\r
5c08e117 818\r
cb7d01c0 819 ModeToken[Index] = HiiSetString (CallbackData->BmmHiiHandle, 0, ModeString, NULL);\r
5c08e117 820\r
5c08e117 821 if (Mode == CallbackData->BmmFakeNvData.ConsoleOutMode) {\r
75bf9d0e
LG
822 HiiCreateOneOfOptionOpCode (\r
823 OptionsOpCodeHandle,\r
824 ModeToken[Index],\r
825 EFI_IFR_OPTION_DEFAULT,\r
826 EFI_IFR_NUMERIC_SIZE_2,\r
827 (UINT16) Mode\r
828 );\r
5c08e117 829 } else {\r
75bf9d0e
LG
830 HiiCreateOneOfOptionOpCode (\r
831 OptionsOpCodeHandle,\r
832 ModeToken[Index],\r
833 0,\r
834 EFI_IFR_NUMERIC_SIZE_2,\r
835 (UINT16) Mode\r
836 );\r
5c08e117 837 }\r
838 Index++;\r
839 }\r
840\r
75bf9d0e
LG
841 HiiCreateOneOfOpCode (\r
842 mStartOpCodeHandle,\r
5c08e117 843 (EFI_QUESTION_ID) CON_MODE_QUESTION_ID,\r
844 VARSTORE_ID_BOOT_MAINT,\r
845 CON_MODE_VAR_OFFSET,\r
846 STRING_TOKEN (STR_CON_MODE_SETUP),\r
847 STRING_TOKEN (STR_CON_MODE_SETUP),\r
848 EFI_IFR_FLAG_RESET_REQUIRED,\r
849 EFI_IFR_NUMERIC_SIZE_2,\r
75bf9d0e
LG
850 OptionsOpCodeHandle,\r
851 NULL\r
5c08e117 852 );\r
75bf9d0e
LG
853\r
854 HiiFreeOpCodeHandle (OptionsOpCodeHandle);\r
5c08e117 855 FreePool (ModeToken);\r
856\r
857 UpdatePageEnd (CallbackData);\r
858}\r
859\r
860/**\r
861 Create the dynamic page which allows user to set the property such as Baud Rate, Data Bits,\r
862 Parity, Stop Bits, Terminal Type.\r
863\r
864 @param CallbackData The BMM context data.\r
865\r
866**/\r
867VOID\r
868UpdateTerminalPage (\r
869 IN BMM_CALLBACK_DATA *CallbackData\r
870 )\r
871{\r
872 UINT8 Index;\r
873 UINT8 CheckFlags;\r
5c08e117 874 BM_MENU_ENTRY *NewMenuEntry;\r
875 BM_TERMINAL_CONTEXT *NewTerminalContext;\r
75bf9d0e 876 VOID *OptionsOpCodeHandle;\r
5c08e117 877\r
878 CallbackData->BmmAskSaveOrNot = TRUE;\r
879\r
880 UpdatePageStart (CallbackData);\r
881\r
882 NewMenuEntry = BOpt_GetMenuEntry (\r
883 &TerminalMenu,\r
884 CallbackData->CurrentTerminal\r
885 );\r
886\r
887 if (NewMenuEntry == NULL) {\r
888 return ;\r
889 }\r
890\r
891 NewTerminalContext = (BM_TERMINAL_CONTEXT *) NewMenuEntry->VariableContext;\r
892\r
75bf9d0e
LG
893 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();\r
894 ASSERT (OptionsOpCodeHandle != NULL);\r
5c08e117 895\r
896 for (Index = 0; Index < sizeof (BaudRateList) / sizeof (BaudRateList [0]); Index++) {\r
897 CheckFlags = 0;\r
898 if (NewTerminalContext->BaudRate == (UINT64) (BaudRateList[Index].Value)) {\r
899 CheckFlags |= EFI_IFR_OPTION_DEFAULT;\r
900 NewTerminalContext->BaudRateIndex = Index;\r
901 CallbackData->BmmFakeNvData.COMBaudRate = NewTerminalContext->BaudRateIndex;\r
902 }\r
903\r
75bf9d0e
LG
904 HiiCreateOneOfOptionOpCode (\r
905 OptionsOpCodeHandle,\r
906 BaudRateList[Index].StringToken,\r
907 CheckFlags,\r
908 EFI_IFR_NUMERIC_SIZE_1,\r
909 Index\r
910 );\r
5c08e117 911 }\r
912\r
75bf9d0e
LG
913 HiiCreateOneOfOpCode (\r
914 mStartOpCodeHandle,\r
5c08e117 915 (EFI_QUESTION_ID) COM_BAUD_RATE_QUESTION_ID,\r
916 VARSTORE_ID_BOOT_MAINT,\r
917 COM_BAUD_RATE_VAR_OFFSET,\r
918 STRING_TOKEN (STR_COM_BAUD_RATE),\r
919 STRING_TOKEN (STR_COM_BAUD_RATE),\r
920 0,\r
921 EFI_IFR_NUMERIC_SIZE_1,\r
75bf9d0e
LG
922 OptionsOpCodeHandle,\r
923 NULL\r
5c08e117 924 );\r
75bf9d0e
LG
925 \r
926 HiiFreeOpCodeHandle (OptionsOpCodeHandle);\r
927 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();\r
928 ASSERT (OptionsOpCodeHandle != NULL);\r
5c08e117 929\r
930 for (Index = 0; Index < sizeof (DataBitsList) / sizeof (DataBitsList[0]); Index++) {\r
931 CheckFlags = 0;\r
932\r
933 if (NewTerminalContext->DataBits == DataBitsList[Index].Value) {\r
934 NewTerminalContext->DataBitsIndex = Index;\r
935 CallbackData->BmmFakeNvData.COMDataRate = NewTerminalContext->DataBitsIndex;\r
936 CheckFlags |= EFI_IFR_OPTION_DEFAULT;\r
937 }\r
938\r
75bf9d0e
LG
939 HiiCreateOneOfOptionOpCode (\r
940 OptionsOpCodeHandle,\r
941 DataBitsList[Index].StringToken,\r
942 CheckFlags,\r
943 EFI_IFR_NUMERIC_SIZE_1,\r
944 Index\r
945 );\r
5c08e117 946 }\r
947\r
75bf9d0e
LG
948 HiiCreateOneOfOpCode (\r
949 mStartOpCodeHandle,\r
5c08e117 950 (EFI_QUESTION_ID) COM_DATA_RATE_QUESTION_ID,\r
951 VARSTORE_ID_BOOT_MAINT,\r
952 COM_DATA_RATE_VAR_OFFSET,\r
953 STRING_TOKEN (STR_COM_DATA_BITS),\r
954 STRING_TOKEN (STR_COM_DATA_BITS),\r
955 0,\r
956 EFI_IFR_NUMERIC_SIZE_1,\r
75bf9d0e
LG
957 OptionsOpCodeHandle,\r
958 NULL\r
5c08e117 959 );\r
960\r
75bf9d0e
LG
961 HiiFreeOpCodeHandle (OptionsOpCodeHandle);\r
962 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();\r
963 ASSERT (OptionsOpCodeHandle != NULL);\r
964\r
5c08e117 965 for (Index = 0; Index < sizeof (ParityList) / sizeof (ParityList[0]); Index++) {\r
966 CheckFlags = 0;\r
967 if (NewTerminalContext->Parity == ParityList[Index].Value) {\r
968 CheckFlags |= EFI_IFR_OPTION_DEFAULT;\r
969 NewTerminalContext->ParityIndex = (UINT8) Index;\r
970 CallbackData->BmmFakeNvData.COMParity = NewTerminalContext->ParityIndex;\r
971 }\r
972\r
75bf9d0e
LG
973 HiiCreateOneOfOptionOpCode (\r
974 OptionsOpCodeHandle,\r
975 ParityList[Index].StringToken,\r
976 CheckFlags,\r
977 EFI_IFR_NUMERIC_SIZE_1,\r
978 Index\r
979 );\r
5c08e117 980 }\r
981\r
75bf9d0e
LG
982 HiiCreateOneOfOpCode (\r
983 mStartOpCodeHandle,\r
5c08e117 984 (EFI_QUESTION_ID) COM_PARITY_QUESTION_ID,\r
985 VARSTORE_ID_BOOT_MAINT,\r
986 COM_PARITY_VAR_OFFSET,\r
987 STRING_TOKEN (STR_COM_PARITY),\r
988 STRING_TOKEN (STR_COM_PARITY),\r
989 0,\r
990 EFI_IFR_NUMERIC_SIZE_1,\r
75bf9d0e
LG
991 OptionsOpCodeHandle,\r
992 NULL\r
5c08e117 993 );\r
994\r
75bf9d0e
LG
995 HiiFreeOpCodeHandle (OptionsOpCodeHandle);\r
996 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();\r
997 ASSERT (OptionsOpCodeHandle != NULL);\r
998\r
5c08e117 999 for (Index = 0; Index < sizeof (StopBitsList) / sizeof (StopBitsList[0]); Index++) {\r
1000 CheckFlags = 0;\r
1001 if (NewTerminalContext->StopBits == StopBitsList[Index].Value) {\r
1002 CheckFlags |= EFI_IFR_OPTION_DEFAULT;\r
1003 NewTerminalContext->StopBitsIndex = (UINT8) Index;\r
1004 CallbackData->BmmFakeNvData.COMStopBits = NewTerminalContext->StopBitsIndex;\r
1005 }\r
1006\r
75bf9d0e
LG
1007 HiiCreateOneOfOptionOpCode (\r
1008 OptionsOpCodeHandle,\r
1009 StopBitsList[Index].StringToken,\r
1010 CheckFlags,\r
1011 EFI_IFR_NUMERIC_SIZE_1,\r
1012 Index\r
1013 );\r
5c08e117 1014 }\r
1015\r
75bf9d0e
LG
1016 HiiCreateOneOfOpCode (\r
1017 mStartOpCodeHandle,\r
5c08e117 1018 (EFI_QUESTION_ID) COM_STOP_BITS_QUESTION_ID,\r
1019 VARSTORE_ID_BOOT_MAINT,\r
1020 COM_STOP_BITS_VAR_OFFSET,\r
1021 STRING_TOKEN (STR_COM_STOP_BITS),\r
1022 STRING_TOKEN (STR_COM_STOP_BITS),\r
1023 0,\r
1024 EFI_IFR_NUMERIC_SIZE_1,\r
75bf9d0e
LG
1025 OptionsOpCodeHandle,\r
1026 NULL\r
5c08e117 1027 );\r
1028\r
75bf9d0e
LG
1029 HiiFreeOpCodeHandle (OptionsOpCodeHandle);\r
1030 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();\r
1031 ASSERT (OptionsOpCodeHandle != NULL);\r
1032\r
5c08e117 1033 for (Index = 0; Index < 4; Index++) {\r
1034 CheckFlags = 0;\r
1035 if (NewTerminalContext->TerminalType == Index) {\r
1036 CheckFlags |= EFI_IFR_OPTION_DEFAULT;\r
1037 CallbackData->BmmFakeNvData.COMTerminalType = NewTerminalContext->TerminalType;\r
1038 }\r
1039\r
75bf9d0e
LG
1040 HiiCreateOneOfOptionOpCode (\r
1041 OptionsOpCodeHandle,\r
1042 (EFI_STRING_ID) TerminalType[Index],\r
1043 CheckFlags,\r
1044 EFI_IFR_NUMERIC_SIZE_1,\r
1045 Index\r
1046 );\r
5c08e117 1047 }\r
1048\r
75bf9d0e
LG
1049 HiiCreateOneOfOpCode (\r
1050 mStartOpCodeHandle,\r
5c08e117 1051 (EFI_QUESTION_ID) COM_TERMINAL_QUESTION_ID,\r
1052 VARSTORE_ID_BOOT_MAINT,\r
1053 COM_TERMINAL_VAR_OFFSET,\r
1054 STRING_TOKEN (STR_COM_TERMI_TYPE),\r
1055 STRING_TOKEN (STR_COM_TERMI_TYPE),\r
1056 0,\r
1057 EFI_IFR_NUMERIC_SIZE_1,\r
75bf9d0e
LG
1058 OptionsOpCodeHandle,\r
1059 NULL\r
5c08e117 1060 );\r
1061\r
75bf9d0e 1062 HiiFreeOpCodeHandle (OptionsOpCodeHandle);\r
5c08e117 1063\r
1064 UpdatePageEnd (CallbackData);\r
1065}\r
1066\r
1067/**\r
1068 Dispatch the correct update page function to call based on\r
1069 the UpdatePageId.\r
1070\r
1071 @param UpdatePageId The form ID.\r
1072 @param CallbackData The BMM context data.\r
1073\r
1074**/\r
1075VOID\r
1076UpdatePageBody (\r
1077 IN UINT16 UpdatePageId,\r
1078 IN BMM_CALLBACK_DATA *CallbackData\r
1079 )\r
1080{\r
1081 CleanUpPage (UpdatePageId, CallbackData);\r
1082 switch (UpdatePageId) {\r
1083 case FORM_CON_IN_ID:\r
1084 UpdateConsolePage (UpdatePageId, &ConsoleInpMenu, CallbackData);\r
1085 break;\r
1086\r
1087 case FORM_CON_OUT_ID:\r
1088 UpdateConsolePage (UpdatePageId, &ConsoleOutMenu, CallbackData);\r
1089 break;\r
1090\r
1091 case FORM_CON_ERR_ID:\r
1092 UpdateConsolePage (UpdatePageId, &ConsoleErrMenu, CallbackData);\r
1093 break;\r
1094\r
1095 case FORM_BOOT_CHG_ID:\r
1096 UpdateOrderPage (UpdatePageId, &BootOptionMenu, CallbackData);\r
1097 break;\r
1098\r
1099 case FORM_DRV_CHG_ID:\r
1100 UpdateOrderPage (UpdatePageId, &DriverOptionMenu, CallbackData);\r
1101 break;\r
1102\r
1103 default:\r
1104 break;\r
1105 }\r
1106}\r
1107\r
1108/**\r
1109 Get the index number (#### in Boot####) for the boot option pointed to a BBS legacy device type\r
1110 specified by DeviceType.\r
1111\r
1112 @param DeviceType The legacy device type. It can be floppy, network, harddisk, cdrom,\r
1113 etc.\r
1114 @param OptionIndex Returns the index number (#### in Boot####).\r
1115 @param OptionSize Return the size of the Boot### variable.\r
1116\r
1117**/\r
1118VOID *\r
1119GetLegacyBootOptionVar (\r
1120 IN UINTN DeviceType,\r
1121 OUT UINTN *OptionIndex,\r
1122 OUT UINTN *OptionSize\r
1123 )\r
1124{\r
1125 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
1126 VOID *OptionBuffer;\r
1127 UINTN OrderSize;\r
1128 UINTN Index;\r
1129 UINT16 *OrderBuffer;\r
1130 CHAR16 StrTemp[100];\r
1131 UINT16 FilePathSize;\r
1132 UINT8 *Ptr;\r
1133 UINT8 *OptionalData;\r
1134\r
1135 //\r
1136 // Get Boot Option number from the size of BootOrder\r
1137 //\r
1138 OrderBuffer = BdsLibGetVariableAndSize (\r
1139 L"BootOrder",\r
1140 &gEfiGlobalVariableGuid,\r
1141 &OrderSize\r
1142 );\r
1143 \r
1144 if (OrderBuffer == NULL) {\r
1145 return NULL;\r
1146 }\r
1147 \r
1148 for (Index = 0; Index < OrderSize / sizeof (UINT16); Index++) {\r
1149 UnicodeSPrint (StrTemp, 100, L"Boot%04x", OrderBuffer[Index]);\r
1150 OptionBuffer = BdsLibGetVariableAndSize (\r
1151 StrTemp,\r
1152 &gEfiGlobalVariableGuid,\r
1153 OptionSize\r
1154 );\r
1155 if (NULL == OptionBuffer) {\r
1156 continue;\r
1157 }\r
1158\r
1159 Ptr = (UINT8 *) OptionBuffer;\r
1160 Ptr += sizeof (UINT32);\r
1161\r
1162 FilePathSize = *(UINT16 *) Ptr;\r
1163 Ptr += sizeof (UINT16);\r
1164\r
1165 Ptr += StrSize ((CHAR16 *) Ptr);\r
1166\r
1167 //\r
1168 // Now Ptr point to Device Path\r
1169 //\r
1170 DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) Ptr;\r
1171 Ptr += FilePathSize;\r
1172\r
1173 //\r
1174 // Now Ptr point to Optional Data\r
1175 //\r
1176 OptionalData = Ptr;\r
1177\r
1178 if ((DeviceType == ((BBS_TABLE *) OptionalData)->DeviceType) &&\r
1179 (BBS_DEVICE_PATH == DevicePath->Type) &&\r
1180 (BBS_BBS_DP == DevicePath->SubType)\r
1181 ) {\r
1182 *OptionIndex = OrderBuffer[Index];\r
1183 FreePool (OrderBuffer);\r
1184 return OptionBuffer;\r
1185 } else {\r
1186 FreePool (OptionBuffer);\r
1187 }\r
1188 }\r
1189\r
1190 FreePool (OrderBuffer);\r
1191 return NULL;\r
1192}\r
1193\r
1194/**\r
1195 Create a dynamic page so that Legacy Device boot order\r
1196 can be set for specified device type.\r
1197\r
1198 @param UpdatePageId The form ID. It also spefies the legacy device type.\r
1199 @param CallbackData The BMM context data.\r
1200\r
1201\r
1202**/\r
1203VOID\r
1204UpdateSetLegacyDeviceOrderPage (\r
1205 IN UINT16 UpdatePageId,\r
1206 IN BMM_CALLBACK_DATA *CallbackData\r
1207 )\r
1208{\r
1209 BM_LEGACY_DEV_ORDER_CONTEXT *DevOrder;\r
1210 BM_MENU_OPTION *OptionMenu;\r
1211 BM_MENU_ENTRY *NewMenuEntry;\r
5c08e117 1212 EFI_STRING_ID StrRef;\r
1213 EFI_STRING_ID StrRefHelp;\r
1214 BBS_TYPE BbsType;\r
1215 UINTN VarSize;\r
1216 UINTN Pos;\r
1217 UINTN Bit;\r
1218 UINT16 Index;\r
1219 UINT16 Key;\r
1220 CHAR16 String[100];\r
1221 CHAR16 *TypeStr;\r
1222 CHAR16 *TypeStrHelp;\r
1223 UINT16 VarDevOrder;\r
1224 UINT8 *VarData;\r
1225 UINT8 *LegacyOrder;\r
1226 UINT8 *OldData;\r
1227 UINT8 *DisMap;\r
75bf9d0e 1228 VOID *OptionsOpCodeHandle;\r
5c08e117 1229\r
1230 OptionMenu = NULL;\r
1231 Key = 0;\r
1232 StrRef = 0;\r
1233 StrRefHelp = 0;\r
1234 TypeStr = NULL;\r
1235 TypeStrHelp = NULL;\r
1236 BbsType = BBS_FLOPPY;\r
1237 LegacyOrder = NULL;\r
1238 OldData = NULL;\r
1239 DisMap = NULL;\r
1240\r
1241 CallbackData->BmmAskSaveOrNot = TRUE;\r
1242 UpdatePageStart (CallbackData);\r
1243\r
1244 DisMap = CallbackData->BmmOldFakeNVData.DisableMap;\r
1245\r
1246 SetMem (DisMap, 32, 0);\r
1247 //\r
1248 // Create oneof option list\r
1249 //\r
1250 switch (UpdatePageId) {\r
1251 case FORM_SET_FD_ORDER_ID:\r
1252 OptionMenu = (BM_MENU_OPTION *) &LegacyFDMenu;\r
1253 Key = (UINT16) LEGACY_FD_QUESTION_ID;\r
1254 TypeStr = STR_FLOPPY;\r
1255 TypeStrHelp = STR_FLOPPY_HELP;\r
1256 BbsType = BBS_FLOPPY;\r
1257 LegacyOrder = CallbackData->BmmFakeNvData.LegacyFD;\r
1258 OldData = CallbackData->BmmOldFakeNVData.LegacyFD;\r
1259 break;\r
1260\r
1261 case FORM_SET_HD_ORDER_ID:\r
1262 OptionMenu = (BM_MENU_OPTION *) &LegacyHDMenu;\r
1263 Key = (UINT16) LEGACY_HD_QUESTION_ID;\r
1264 TypeStr = STR_HARDDISK;\r
1265 TypeStrHelp = STR_HARDDISK_HELP;\r
1266 BbsType = BBS_HARDDISK;\r
1267 LegacyOrder = CallbackData->BmmFakeNvData.LegacyHD;\r
1268 OldData = CallbackData->BmmOldFakeNVData.LegacyHD;\r
1269 break;\r
1270\r
1271 case FORM_SET_CD_ORDER_ID:\r
1272 OptionMenu = (BM_MENU_OPTION *) &LegacyCDMenu;\r
1273 Key = (UINT16) LEGACY_CD_QUESTION_ID;\r
1274 TypeStr = STR_CDROM;\r
1275 TypeStrHelp = STR_CDROM_HELP;\r
1276 BbsType = BBS_CDROM;\r
1277 LegacyOrder = CallbackData->BmmFakeNvData.LegacyCD;\r
1278 OldData = CallbackData->BmmOldFakeNVData.LegacyCD;\r
1279 break;\r
1280\r
1281 case FORM_SET_NET_ORDER_ID:\r
1282 OptionMenu = (BM_MENU_OPTION *) &LegacyNETMenu;\r
1283 Key = (UINT16) LEGACY_NET_QUESTION_ID;\r
1284 TypeStr = STR_NET;\r
1285 TypeStrHelp = STR_NET_HELP;\r
1286 BbsType = BBS_EMBED_NETWORK;\r
1287 LegacyOrder = CallbackData->BmmFakeNvData.LegacyNET;\r
1288 OldData = CallbackData->BmmOldFakeNVData.LegacyNET;\r
1289 break;\r
1290\r
1291 case FORM_SET_BEV_ORDER_ID:\r
1292 OptionMenu = (BM_MENU_OPTION *) &LegacyBEVMenu;\r
1293 Key = (UINT16) LEGACY_BEV_QUESTION_ID;\r
1294 TypeStr = STR_BEV;\r
1295 TypeStrHelp = STR_BEV_HELP;\r
1296 BbsType = BBS_BEV_DEVICE;\r
1297 LegacyOrder = CallbackData->BmmFakeNvData.LegacyBEV;\r
1298 OldData = CallbackData->BmmOldFakeNVData.LegacyBEV;\r
1299 break;\r
1300\r
1301 default:\r
1302 DEBUG ((EFI_D_ERROR, "Invalid command ID for updating page!\n"));\r
1303 return;\r
1304 }\r
1305\r
1306 CreateMenuStringToken (CallbackData, CallbackData->BmmHiiHandle, OptionMenu);\r
1307\r
75bf9d0e
LG
1308 OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();\r
1309 ASSERT (OptionsOpCodeHandle != NULL);\r
5c08e117 1310\r
1311 for (Index = 0; Index < OptionMenu->MenuNumber; Index++) {\r
1312 NewMenuEntry = BOpt_GetMenuEntry (OptionMenu, Index);\r
75bf9d0e
LG
1313\r
1314 if (Index == 0) {\r
1315 HiiCreateOneOfOptionOpCode (\r
1316 OptionsOpCodeHandle,\r
1317 NewMenuEntry->DisplayStringToken,\r
1318 EFI_IFR_OPTION_DEFAULT,\r
1319 EFI_IFR_NUMERIC_SIZE_1,\r
1320 (UINT8) ((BM_LEGACY_DEVICE_CONTEXT *) NewMenuEntry->VariableContext)->Index\r
1321 );\r
5c08e117 1322 }\r
1323\r
75bf9d0e
LG
1324 HiiCreateOneOfOptionOpCode (\r
1325 OptionsOpCodeHandle,\r
1326 NewMenuEntry->DisplayStringToken,\r
1327 0,\r
1328 EFI_IFR_NUMERIC_SIZE_1,\r
1329 (UINT8) ((BM_LEGACY_DEVICE_CONTEXT *) NewMenuEntry->VariableContext)->Index\r
1330 );\r
5c08e117 1331 }\r
75bf9d0e 1332\r
5c08e117 1333 //\r
1334 // for item "Disabled"\r
1335 //\r
75bf9d0e
LG
1336 HiiCreateOneOfOptionOpCode (\r
1337 OptionsOpCodeHandle,\r
1338 STRING_TOKEN (STR_DISABLE_LEGACY_DEVICE),\r
1339 0,\r
1340 EFI_IFR_NUMERIC_SIZE_1,\r
1341 0xFF\r
1342 );\r
5c08e117 1343\r
1344 //\r
1345 // Get Device Order from variable\r
1346 //\r
1347 VarData = BdsLibGetVariableAndSize (\r
1348 VAR_LEGACY_DEV_ORDER,\r
1349 &EfiLegacyDevOrderGuid,\r
1350 &VarSize\r
1351 );\r
1352\r
1353 if (NULL != VarData) {\r
1354 DevOrder = (BM_LEGACY_DEV_ORDER_CONTEXT *) VarData;\r
1355 while (VarData < VarData + VarSize) {\r
1356 if (DevOrder->BbsType == BbsType) {\r
1357 break;\r
1358 }\r
1359\r
1360 VarData += sizeof (BBS_TYPE);\r
1361 VarData += *(UINT16 *) VarData;\r
1362 DevOrder = (BM_LEGACY_DEV_ORDER_CONTEXT *) VarData;\r
1363 }\r
1364 //\r
1365 // Create oneof tag here for FD/HD/CD #1 #2\r
1366 //\r
1367 for (Index = 0; Index < OptionMenu->MenuNumber; Index++) {\r
1368 //\r
1369 // Create the string for oneof tag\r
1370 //\r
1371 UnicodeSPrint (String, sizeof (String), TypeStr, Index);\r
cb7d01c0 1372 StrRef = HiiSetString (CallbackData->BmmHiiHandle, 0, String, NULL);\r
5c08e117 1373\r
1374 UnicodeSPrint (String, sizeof (String), TypeStrHelp, Index);\r
cb7d01c0 1375 StrRefHelp = HiiSetString (CallbackData->BmmHiiHandle, 0, String, NULL);\r
5c08e117 1376\r
75bf9d0e
LG
1377 HiiCreateOneOfOpCode (\r
1378 mStartOpCodeHandle,\r
5c08e117 1379 (EFI_QUESTION_ID) (Key + Index),\r
1380 VARSTORE_ID_BOOT_MAINT,\r
1381 (UINT16) (Key + Index - CONFIG_OPTION_OFFSET),\r
1382 StrRef,\r
1383 StrRefHelp,\r
1384 EFI_IFR_FLAG_CALLBACK,\r
1385 EFI_IFR_NUMERIC_SIZE_1,\r
75bf9d0e
LG
1386 OptionsOpCodeHandle,\r
1387 NULL\r
5c08e117 1388 );\r
1389\r
1390 VarDevOrder = *(UINT16 *) ((UINT8 *) DevOrder + sizeof (BBS_TYPE) + sizeof (UINT16) + Index * sizeof (UINT16));\r
1391\r
1392 if (0xFF00 == (VarDevOrder & 0xFF00)) {\r
1393 LegacyOrder[Index] = 0xFF;\r
1394 Pos = (VarDevOrder & 0xFF) / 8;\r
1395 Bit = 7 - ((VarDevOrder & 0xFF) % 8);\r
1396 DisMap[Pos] = (UINT8) (DisMap[Pos] | (UINT8) (1 << Bit));\r
1397 } else {\r
1398 LegacyOrder[Index] = (UINT8) (VarDevOrder & 0xFF);\r
1399 }\r
1400 }\r
1401 }\r
1402\r
1403 CopyMem (OldData, LegacyOrder, 100);\r
1404\r
75bf9d0e 1405 HiiFreeOpCodeHandle (OptionsOpCodeHandle);\r
5c08e117 1406\r
1407 UpdatePageEnd (CallbackData);\r
1408}\r
1409\r
1410/**\r
1411 Dispatch the display to the next page based on NewPageId.\r
1412\r
1413 @param Private The BMM context data.\r
1414 @param NewPageId The original page ID.\r
1415\r
1416**/\r
1417VOID\r
1418UpdatePageId (\r
1419 BMM_CALLBACK_DATA *Private,\r
1420 UINT16 NewPageId\r
1421 )\r
1422{\r
1423 if ((NewPageId < FILE_OPTION_OFFSET) && (NewPageId >= HANDLE_OPTION_OFFSET)) {\r
1424 //\r
1425 // If we select a handle to add driver option, advance to the add handle description page.\r
1426 //\r
1427 NewPageId = FORM_DRV_ADD_HANDLE_DESC_ID;\r
1428 } else if ((NewPageId == KEY_VALUE_SAVE_AND_EXIT) || (NewPageId == KEY_VALUE_NO_SAVE_AND_EXIT)) {\r
1429 //\r
1430 // Return to main page after "Save Changes" or "Discard Changes".\r
1431 //\r
1432 NewPageId = FORM_MAIN_ID;\r
1433 } else if ((NewPageId >= TERMINAL_OPTION_OFFSET) && (NewPageId < CONSOLE_OPTION_OFFSET)) {\r
1434 NewPageId = FORM_CON_COM_SETUP_ID;\r
1435 }\r
1436\r
1437 if ((NewPageId > 0) && (NewPageId < MAXIMUM_FORM_ID)) {\r
1438 Private->BmmPreviousPageId = Private->BmmCurrentPageId;\r
1439 Private->BmmCurrentPageId = NewPageId;\r
1440 }\r
1441}\r