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