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