TianoCore EDK2 master
Loading...
Searching...
No Matches
ConsoleOption.c
Go to the documentation of this file.
1
10
24BOOLEAN
28 )
29{
30 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
31 EFI_DEVICE_PATH_PROTOCOL *DevicePathInst;
32 UINTN Size;
33
34 if ((Multi == NULL) || (Single == NULL)) {
35 return FALSE;
36 }
37
38 DevicePath = Multi;
39 DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);
40
41 //
42 // Search for the match of 'Single' in 'Multi'
43 //
44 while (DevicePathInst != NULL) {
45 //
46 // If the single device path is found in multiple device paths,
47 // return success
48 //
49 if (CompareMem (Single, DevicePathInst, Size) == 0) {
50 FreePool (DevicePathInst);
51 return TRUE;
52 }
53
54 FreePool (DevicePathInst);
55 DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);
56 }
57
58 return FALSE;
59}
60
70BOOLEAN
73 )
74{
75 return (BOOLEAN)(
76 (DevicePathType (Acpi) == ACPI_DEVICE_PATH) &&
77 (DevicePathSubType (Acpi) == ACPI_DP) &&
78 (ReadUnaligned32 (&Acpi->HID) == EISA_PNP_ID (0x0501))
79 );
80}
81
92 EFI_DEVICE_PATH_PROTOCOL *DevicePath
93 );
94
109 IN OUT EFI_DEVICE_PATH_PROTOCOL *DevicePath,
110 IN BOOLEAN ChangeTerminal
111 )
112{
116 UART_DEVICE_PATH *Uart;
117 UART_DEVICE_PATH *Uart1;
118 UINTN Com;
119 BM_TERMINAL_CONTEXT *NewTerminalContext;
120 BM_MENU_ENTRY *NewMenuEntry;
121
122 Node = DevicePath;
123 Node = NextDevicePathNode (Node);
124 Com = 0;
125 while (!IsDevicePathEnd (Node)) {
126 Acpi = (ACPI_HID_DEVICE_PATH *)Node;
127 if (IsIsaSerialNode (Acpi)) {
128 CopyMem (&Com, &Acpi->UID, sizeof (UINT32));
129 }
130
131 NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Com);
132
133 NewTerminalContext = (BM_TERMINAL_CONTEXT *)NewMenuEntry->VariableContext;
134 if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node) == MSG_UART_DP)) {
135 Uart = (UART_DEVICE_PATH *)Node;
136 CopyMem (
137 &Uart->BaudRate,
138 &NewTerminalContext->BaudRate,
139 sizeof (UINT64)
140 );
141
142 CopyMem (
143 &Uart->DataBits,
144 &NewTerminalContext->DataBits,
145 sizeof (UINT8)
146 );
147
148 CopyMem (
149 &Uart->Parity,
150 &NewTerminalContext->Parity,
151 sizeof (UINT8)
152 );
153
154 CopyMem (
155 &Uart->StopBits,
156 &NewTerminalContext->StopBits,
157 sizeof (UINT8)
158 );
159 //
160 // Change the device path in the ComPort
161 //
162 if (ChangeTerminal) {
163 Node1 = NewTerminalContext->DevicePath;
164 Node1 = NextDevicePathNode (Node1);
165 while (!IsDevicePathEnd (Node1)) {
166 if ((DevicePathType (Node1) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node1) == MSG_UART_DP)) {
167 Uart1 = (UART_DEVICE_PATH *)Node1;
168 CopyMem (
169 &Uart1->BaudRate,
170 &NewTerminalContext->BaudRate,
171 sizeof (UINT64)
172 );
173
174 CopyMem (
175 &Uart1->DataBits,
176 &NewTerminalContext->DataBits,
177 sizeof (UINT8)
178 );
179
180 CopyMem (
181 &Uart1->Parity,
182 &NewTerminalContext->Parity,
183 sizeof (UINT8)
184 );
185
186 CopyMem (
187 &Uart1->StopBits,
188 &NewTerminalContext->StopBits,
189 sizeof (UINT8)
190 );
191 break;
192 }
193
194 //
195 // end if
196 //
197 Node1 = NextDevicePathNode (Node1);
198 }
199
200 //
201 // end while
202 //
203 break;
204 }
205 }
206
207 Node = NextDevicePathNode (Node);
208 }
209
210 return EFI_SUCCESS;
211}
212
221VOID
224 )
225{
228 UART_DEVICE_PATH *Uart;
229 UINTN Com;
230 BM_TERMINAL_CONTEXT *NewTerminalContext;
231 BM_MENU_ENTRY *NewMenuEntry;
232
233 Node = DevicePath;
234 Node = NextDevicePathNode (Node);
235 Com = 0;
236 while (!IsDevicePathEnd (Node)) {
237 Acpi = (ACPI_HID_DEVICE_PATH *)Node;
238 if (IsIsaSerialNode (Acpi)) {
239 CopyMem (&Com, &Acpi->UID, sizeof (UINT32));
240 }
241
242 if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node) == MSG_UART_DP)) {
243 NewMenuEntry = BOpt_GetMenuEntry (
244 &TerminalMenu,
245 Com
246 );
247 ASSERT (NewMenuEntry != NULL);
248 NewTerminalContext = (BM_TERMINAL_CONTEXT *)NewMenuEntry->VariableContext;
249 Uart = (UART_DEVICE_PATH *)Node;
250 CopyMem (
251 &Uart->BaudRate,
252 &NewTerminalContext->BaudRate,
253 sizeof (UINT64)
254 );
255
256 CopyMem (
257 &Uart->DataBits,
258 &NewTerminalContext->DataBits,
259 sizeof (UINT8)
260 );
261
262 CopyMem (
263 &Uart->Parity,
264 &NewTerminalContext->Parity,
265 sizeof (UINT8)
266 );
267
268 CopyMem (
269 &Uart->StopBits,
270 &NewTerminalContext->StopBits,
271 sizeof (UINT8)
272 );
273 }
274
275 Node = NextDevicePathNode (Node);
276 }
277}
278
289BOOLEAN
291 IN EFI_HANDLE Handle,
292 IN OUT UINT32 *AcpiUid
293 )
294{
295 EFI_STATUS Status;
297 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
298
299 Status = gBS->HandleProtocol (
300 Handle,
301 &gEfiDevicePathProtocolGuid,
302 (VOID **)&DevicePath
303 );
304 if (EFI_ERROR (Status)) {
305 return FALSE;
306 }
307
308 Acpi = NULL;
309 for ( ; !IsDevicePathEnd (DevicePath); DevicePath = NextDevicePathNode (DevicePath)) {
310 if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (DevicePath) == MSG_UART_DP)) {
311 break;
312 }
313
314 //
315 // Acpi points to the node before the Uart node
316 //
317 Acpi = (ACPI_HID_DEVICE_PATH *)DevicePath;
318 }
319
320 if ((Acpi != NULL) && IsIsaSerialNode (Acpi)) {
321 if (AcpiUid != NULL) {
322 CopyMem (AcpiUid, &Acpi->UID, sizeof (UINT32));
323 }
324
325 return TRUE;
326 } else {
327 return FALSE;
328 }
329}
330
337VOID
339 IN EFI_HANDLE *Handles,
340 IN UINTN NoHandles
341 )
342{
343 UINTN Index1;
344 UINTN Index2;
345 UINTN Position;
346 UINT32 AcpiUid1;
347 UINT32 AcpiUid2;
348 UINT32 TempAcpiUid;
349 EFI_HANDLE TempHandle;
350
351 for (Index1 = 0; Index1 < NoHandles-1; Index1++) {
352 if (!RetrieveUartUid (Handles[Index1], &AcpiUid1)) {
353 continue;
354 }
355
356 TempHandle = Handles[Index1];
357 Position = Index1;
358 TempAcpiUid = AcpiUid1;
359
360 for (Index2 = Index1+1; Index2 < NoHandles; Index2++) {
361 if (!RetrieveUartUid (Handles[Index2], &AcpiUid2)) {
362 continue;
363 }
364
365 if (AcpiUid2 < TempAcpiUid) {
366 TempAcpiUid = AcpiUid2;
367 TempHandle = Handles[Index2];
368 Position = Index2;
369 }
370 }
371
372 Handles[Position] = Handles[Index1];
373 Handles[Index1] = TempHandle;
374 }
375}
376
389BOOLEAN
391 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
392 OUT TYPE_OF_TERMINAL *Termi,
393 OUT UINTN *Com
394 );
395
406 VOID
407 )
408{
409 UINTN Index;
410 UINTN Index2;
411 UINTN NoHandles;
412 EFI_HANDLE *Handles;
413 EFI_STATUS Status;
415 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
416 EFI_SERIAL_IO_PROTOCOL *SerialIo;
418 EFI_DEVICE_PATH_PROTOCOL *OutDevicePath;
419 EFI_DEVICE_PATH_PROTOCOL *InpDevicePath;
420 EFI_DEVICE_PATH_PROTOCOL *ErrDevicePath;
421 BM_MENU_ENTRY *NewMenuEntry;
422 BM_TERMINAL_CONTEXT *NewTerminalContext;
423 EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
424 VENDOR_DEVICE_PATH Vendor;
425
426 //
427 // Get all handles that have SerialIo protocol installed
428 //
429 InitializeListHead (&TerminalMenu.Head);
430 TerminalMenu.MenuNumber = 0;
431 Status = gBS->LocateHandleBuffer (
433 &gEfiSerialIoProtocolGuid,
434 NULL,
435 &NoHandles,
436 &Handles
437 );
438 if (EFI_ERROR (Status)) {
439 //
440 // No serial ports present
441 //
442 return EFI_UNSUPPORTED;
443 }
444
445 //
446 // Sort Uart handles array with Acpi->UID from low to high
447 // then Terminal menu can be built from low Acpi->UID to high Acpi->UID
448 //
449 SortedUartHandle (Handles, NoHandles);
450
451 for (Index = 0; Index < NoHandles; Index++) {
452 //
453 // Check to see whether the handle has DevicePath Protocol installed
454 //
455 gBS->HandleProtocol (
456 Handles[Index],
457 &gEfiDevicePathProtocolGuid,
458 (VOID **)&DevicePath
459 );
460
461 Acpi = NULL;
462 for (Node = DevicePath; !IsDevicePathEnd (Node); Node = NextDevicePathNode (Node)) {
463 if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node) == MSG_UART_DP)) {
464 break;
465 }
466
467 //
468 // Acpi points to the node before Uart node
469 //
470 Acpi = (ACPI_HID_DEVICE_PATH *)Node;
471 }
472
473 if ((Acpi != NULL) && IsIsaSerialNode (Acpi)) {
474 NewMenuEntry = BOpt_CreateMenuEntry (BM_TERMINAL_CONTEXT_SELECT);
475 if (NewMenuEntry == NULL) {
476 FreePool (Handles);
477 return EFI_OUT_OF_RESOURCES;
478 }
479
480 NewTerminalContext = (BM_TERMINAL_CONTEXT *)NewMenuEntry->VariableContext;
481 CopyMem (&NewMenuEntry->OptionNumber, &Acpi->UID, sizeof (UINT32));
482 NewTerminalContext->DevicePath = DuplicateDevicePath (DevicePath);
483 //
484 // BugBug: I have no choice, calling EfiLibStrFromDatahub will hang the system!
485 // coz' the misc data for each platform is not correct, actually it's the device path stored in
486 // datahub which is not completed, so a searching for end of device path will enter a
487 // dead-loop.
488 //
489 NewMenuEntry->DisplayString = EfiLibStrFromDatahub (DevicePath);
490 if (NULL == NewMenuEntry->DisplayString) {
491 NewMenuEntry->DisplayString = UiDevicePathToStr (DevicePath);
492 }
493
494 NewMenuEntry->HelpString = NULL;
495
496 NewMenuEntry->DisplayStringToken = HiiSetString (mBmmCallbackInfo->BmmHiiHandle, 0, NewMenuEntry->DisplayString, NULL);
497
498 NewMenuEntry->HelpStringToken = NewMenuEntry->DisplayStringToken;
499
500 gBS->HandleProtocol (
501 Handles[Index],
502 &gEfiSerialIoProtocolGuid,
503 (VOID **)&SerialIo
504 );
505
506 CopyMem (
507 &NewTerminalContext->BaudRate,
508 &SerialIo->Mode->BaudRate,
509 sizeof (UINT64)
510 );
511
512 CopyMem (
513 &NewTerminalContext->DataBits,
514 &SerialIo->Mode->DataBits,
515 sizeof (UINT8)
516 );
517
518 CopyMem (
519 &NewTerminalContext->Parity,
520 &SerialIo->Mode->Parity,
521 sizeof (UINT8)
522 );
523
524 CopyMem (
525 &NewTerminalContext->StopBits,
526 &SerialIo->Mode->StopBits,
527 sizeof (UINT8)
528 );
529 InsertTailList (&TerminalMenu.Head, &NewMenuEntry->Link);
530 TerminalMenu.MenuNumber++;
531 }
532 }
533
534 if (Handles != NULL) {
535 FreePool (Handles);
536 }
537
538 //
539 // Get L"ConOut", L"ConIn" and L"ErrOut" from the Var
540 //
541 GetEfiGlobalVariable2 (L"ConOut", (VOID **)&OutDevicePath, NULL);
542 GetEfiGlobalVariable2 (L"ConIn", (VOID **)&InpDevicePath, NULL);
543 GetEfiGlobalVariable2 (L"ErrOut", (VOID **)&ErrDevicePath, NULL);
544 if (OutDevicePath != NULL) {
545 UpdateComAttributeFromVariable (OutDevicePath);
546 }
547
548 if (InpDevicePath != NULL) {
549 UpdateComAttributeFromVariable (InpDevicePath);
550 }
551
552 if (ErrDevicePath != NULL) {
553 UpdateComAttributeFromVariable (ErrDevicePath);
554 }
555
556 for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) {
557 NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index);
558 if (NULL == NewMenuEntry) {
559 return EFI_NOT_FOUND;
560 }
561
562 NewTerminalContext = (BM_TERMINAL_CONTEXT *)NewMenuEntry->VariableContext;
563
564 NewTerminalContext->TerminalType = 0;
565 NewTerminalContext->IsConIn = FALSE;
566 NewTerminalContext->IsConOut = FALSE;
567 NewTerminalContext->IsStdErr = FALSE;
568
569 Vendor.Header.Type = MESSAGING_DEVICE_PATH;
570 Vendor.Header.SubType = MSG_VENDOR_DP;
571
572 for (Index2 = 0; Index2 < (ARRAY_SIZE (TerminalTypeGuid)); Index2++) {
573 CopyMem (&Vendor.Guid, &TerminalTypeGuid[Index2], sizeof (EFI_GUID));
574 SetDevicePathNodeLength (&Vendor.Header, sizeof (VENDOR_DEVICE_PATH));
575 NewDevicePath = AppendDevicePathNode (
576 NewTerminalContext->DevicePath,
577 (EFI_DEVICE_PATH_PROTOCOL *)&Vendor
578 );
579 if (NewMenuEntry->HelpString != NULL) {
580 FreePool (NewMenuEntry->HelpString);
581 }
582
583 //
584 // NewMenuEntry->HelpString = UiDevicePathToStr (NewDevicePath);
585 // NewMenuEntry->DisplayString = NewMenuEntry->HelpString;
586 //
587 NewMenuEntry->HelpString = NULL;
588
589 NewMenuEntry->DisplayStringToken = HiiSetString (mBmmCallbackInfo->BmmHiiHandle, 0, NewMenuEntry->DisplayString, NULL);
590
591 NewMenuEntry->HelpStringToken = NewMenuEntry->DisplayStringToken;
592
593 if (MatchDevicePaths (OutDevicePath, NewDevicePath)) {
594 NewTerminalContext->IsConOut = TRUE;
595 NewTerminalContext->TerminalType = (UINT8)Index2;
596 }
597
598 if (MatchDevicePaths (InpDevicePath, NewDevicePath)) {
599 NewTerminalContext->IsConIn = TRUE;
600 NewTerminalContext->TerminalType = (UINT8)Index2;
601 }
602
603 if (MatchDevicePaths (ErrDevicePath, NewDevicePath)) {
604 NewTerminalContext->IsStdErr = TRUE;
605 NewTerminalContext->TerminalType = (UINT8)Index2;
606 }
607 }
608 }
609
610 return EFI_SUCCESS;
611}
612
623 EFI_DEVICE_PATH_PROTOCOL *DevicePath
624 )
625{
627 EFI_DEVICE_PATH_PROTOCOL *SerialNode;
629 UART_DEVICE_PATH *Uart;
630 UART_DEVICE_PATH *Uart1;
631 UINTN TerminalNumber;
632 BM_MENU_ENTRY *NewMenuEntry;
633 BM_TERMINAL_CONTEXT *NewTerminalContext;
634 UINTN Index;
635
636 Node = DevicePath;
637 Node = NextDevicePathNode (Node);
638 TerminalNumber = 0;
639 for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) {
640 while (!IsDevicePathEnd (Node)) {
641 Acpi = (ACPI_HID_DEVICE_PATH *)Node;
642 if (IsIsaSerialNode (Acpi)) {
643 CopyMem (&TerminalNumber, &Acpi->UID, sizeof (UINT32));
644 }
645
646 if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node) == MSG_UART_DP)) {
647 Uart = (UART_DEVICE_PATH *)Node;
648 NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, TerminalNumber);
649 if (NULL == NewMenuEntry) {
650 return EFI_NOT_FOUND;
651 }
652
653 NewTerminalContext = (BM_TERMINAL_CONTEXT *)NewMenuEntry->VariableContext;
654 CopyMem (
655 &NewTerminalContext->BaudRate,
656 &Uart->BaudRate,
657 sizeof (UINT64)
658 );
659
660 CopyMem (
661 &NewTerminalContext->DataBits,
662 &Uart->DataBits,
663 sizeof (UINT8)
664 );
665
666 CopyMem (
667 &NewTerminalContext->Parity,
668 &Uart->Parity,
669 sizeof (UINT8)
670 );
671
672 CopyMem (
673 &NewTerminalContext->StopBits,
674 &Uart->StopBits,
675 sizeof (UINT8)
676 );
677
678 SerialNode = NewTerminalContext->DevicePath;
679 SerialNode = NextDevicePathNode (SerialNode);
680 while (!IsDevicePathEnd (SerialNode)) {
681 if ((DevicePathType (SerialNode) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (SerialNode) == MSG_UART_DP)) {
682 //
683 // Update following device paths according to
684 // previous acquired uart attributes
685 //
686 Uart1 = (UART_DEVICE_PATH *)SerialNode;
687 CopyMem (
688 &Uart1->BaudRate,
689 &NewTerminalContext->BaudRate,
690 sizeof (UINT64)
691 );
692
693 CopyMem (
694 &Uart1->DataBits,
695 &NewTerminalContext->DataBits,
696 sizeof (UINT8)
697 );
698 CopyMem (
699 &Uart1->Parity,
700 &NewTerminalContext->Parity,
701 sizeof (UINT8)
702 );
703 CopyMem (
704 &Uart1->StopBits,
705 &NewTerminalContext->StopBits,
706 sizeof (UINT8)
707 );
708
709 break;
710 }
711
712 SerialNode = NextDevicePathNode (SerialNode);
713 }
714
715 //
716 // end while
717 //
718 }
719
720 Node = NextDevicePathNode (Node);
721 }
722
723 //
724 // end while
725 //
726 }
727
728 return EFI_SUCCESS;
729}
730
748 IN UINTN ConsoleMenuType
749 )
750{
751 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
752 EFI_DEVICE_PATH_PROTOCOL *AllDevicePath;
753 EFI_DEVICE_PATH_PROTOCOL *MultiDevicePath;
754 EFI_DEVICE_PATH_PROTOCOL *DevicePathInst;
755 UINTN Size;
756 UINTN AllCount;
757 UINTN Index;
758 UINTN Index2;
759 BM_MENU_ENTRY *NewMenuEntry;
760 BM_CONSOLE_CONTEXT *NewConsoleContext;
761 TYPE_OF_TERMINAL Terminal;
762 UINTN Com;
763 BM_MENU_OPTION *ConsoleMenu;
764
765 DevicePath = NULL;
766 AllDevicePath = NULL;
767 AllCount = 0;
768 switch (ConsoleMenuType) {
769 case BM_CONSOLE_IN_CONTEXT_SELECT:
770 ConsoleMenu = &ConsoleInpMenu;
771 GetEfiGlobalVariable2 (L"ConIn", (VOID **)&DevicePath, NULL);
772 GetEfiGlobalVariable2 (L"ConInDev", (VOID **)&AllDevicePath, NULL);
773 break;
774
775 case BM_CONSOLE_OUT_CONTEXT_SELECT:
776 ConsoleMenu = &ConsoleOutMenu;
777 GetEfiGlobalVariable2 (L"ConOut", (VOID **)&DevicePath, NULL);
778 GetEfiGlobalVariable2 (L"ConOutDev", (VOID **)&AllDevicePath, NULL);
779 break;
780
781 case BM_CONSOLE_ERR_CONTEXT_SELECT:
782 ConsoleMenu = &ConsoleErrMenu;
783 GetEfiGlobalVariable2 (L"ErrOut", (VOID **)&DevicePath, NULL);
784 GetEfiGlobalVariable2 (L"ErrOutDev", (VOID **)&AllDevicePath, NULL);
785 break;
786
787 default:
788 return EFI_UNSUPPORTED;
789 }
790
791 if (NULL == AllDevicePath) {
792 return EFI_NOT_FOUND;
793 }
794
795 InitializeListHead (&ConsoleMenu->Head);
796
797 AllCount = EfiDevicePathInstanceCount (AllDevicePath);
798 ConsoleMenu->MenuNumber = 0;
799 //
800 // Following is menu building up for Console Devices selected.
801 //
802 MultiDevicePath = AllDevicePath;
803 Index2 = 0;
804 for (Index = 0; Index < AllCount; Index++) {
805 DevicePathInst = GetNextDevicePathInstance (&MultiDevicePath, &Size);
806
807 NewMenuEntry = BOpt_CreateMenuEntry (BM_CONSOLE_CONTEXT_SELECT);
808 if (NULL == NewMenuEntry) {
809 return EFI_OUT_OF_RESOURCES;
810 }
811
812 NewConsoleContext = (BM_CONSOLE_CONTEXT *)NewMenuEntry->VariableContext;
813 NewMenuEntry->OptionNumber = Index2;
814
815 NewConsoleContext->DevicePath = DuplicateDevicePath (DevicePathInst);
816 ASSERT (NewConsoleContext->DevicePath != NULL);
817 NewMenuEntry->DisplayString = EfiLibStrFromDatahub (NewConsoleContext->DevicePath);
818 if (NULL == NewMenuEntry->DisplayString) {
819 NewMenuEntry->DisplayString = UiDevicePathToStr (NewConsoleContext->DevicePath);
820 }
821
822 NewMenuEntry->DisplayStringToken = HiiSetString (mBmmCallbackInfo->BmmHiiHandle, 0, NewMenuEntry->DisplayString, NULL);
823
824 if (NULL == NewMenuEntry->HelpString) {
825 NewMenuEntry->HelpStringToken = NewMenuEntry->DisplayStringToken;
826 } else {
827 NewMenuEntry->HelpStringToken = HiiSetString (mBmmCallbackInfo->BmmHiiHandle, 0, NewMenuEntry->HelpString, NULL);
828 }
829
830 NewConsoleContext->IsTerminal = IsTerminalDevicePath (
831 NewConsoleContext->DevicePath,
832 &Terminal,
833 &Com
834 );
835
836 NewConsoleContext->IsActive = MatchDevicePaths (
837 DevicePath,
838 NewConsoleContext->DevicePath
839 );
840
841 if (NewConsoleContext->IsTerminal) {
842 BOpt_DestroyMenuEntry (NewMenuEntry);
843 } else {
844 Index2++;
845 ConsoleMenu->MenuNumber++;
846 InsertTailList (&ConsoleMenu->Head, &NewMenuEntry->Link);
847 }
848 }
849
850 return EFI_SUCCESS;
851}
852
861 VOID
862 )
863{
864 GetConsoleMenu (BM_CONSOLE_IN_CONTEXT_SELECT);
865 GetConsoleMenu (BM_CONSOLE_OUT_CONTEXT_SELECT);
866 GetConsoleMenu (BM_CONSOLE_ERR_CONTEXT_SELECT);
867 return EFI_SUCCESS;
868}
869
877 VOID
878 )
879{
883 BOpt_FreeMenu (&TerminalMenu);
884 return EFI_SUCCESS;
885}
886
899BOOLEAN
901 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
902 OUT TYPE_OF_TERMINAL *Termi,
903 OUT UINTN *Com
904 )
905{
906 BOOLEAN IsTerminal;
908 VENDOR_DEVICE_PATH *Vendor;
909 UART_DEVICE_PATH *Uart;
911 UINTN Index;
912
913 IsTerminal = FALSE;
914
915 Uart = NULL;
916 Vendor = NULL;
917 Acpi = NULL;
918 for (Node = DevicePath; !IsDevicePathEnd (Node); Node = NextDevicePathNode (Node)) {
919 //
920 // Vendor points to the node before the End node
921 //
922 Vendor = (VENDOR_DEVICE_PATH *)Node;
923
924 if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) && (DevicePathSubType (Node) == MSG_UART_DP)) {
925 Uart = (UART_DEVICE_PATH *)Node;
926 }
927
928 if (Uart == NULL) {
929 //
930 // Acpi points to the node before the UART node
931 //
932 Acpi = (ACPI_HID_DEVICE_PATH *)Node;
933 }
934 }
935
936 if ((Vendor == NULL) ||
938 (DevicePathSubType (Vendor) != MSG_VENDOR_DP) ||
939 (Uart == NULL))
940 {
941 return FALSE;
942 }
943
944 //
945 // There are 9 kinds of Terminal types
946 // check to see whether this devicepath
947 // is one of that type
948 //
949 for (Index = 0; Index < ARRAY_SIZE (TerminalTypeGuid); Index++) {
950 if (CompareGuid (&Vendor->Guid, &TerminalTypeGuid[Index])) {
951 *Termi = Index;
952 IsTerminal = TRUE;
953 break;
954 }
955 }
956
957 if (Index == ARRAY_SIZE (TerminalTypeGuid)) {
958 IsTerminal = FALSE;
959 }
960
961 if (!IsTerminal) {
962 return FALSE;
963 }
964
965 if ((Acpi != NULL) && IsIsaSerialNode (Acpi)) {
966 CopyMem (Com, &Acpi->UID, sizeof (UINT32));
967 } else {
968 return FALSE;
969 }
970
971 return TRUE;
972}
973
979VOID
981 IN BMM_CALLBACK_DATA *CallbackData
982 )
983{
984 UINTN Col;
985 UINTN Row;
986 UINTN CurrentCol;
987 UINTN CurrentRow;
988 UINTN Mode;
989 UINTN MaxMode;
990 EFI_STATUS Status;
992
993 ConOut = gST->ConOut;
994 MaxMode = (UINTN)(ConOut->Mode->MaxMode);
995
996 CurrentCol = PcdGet32 (PcdSetupConOutColumn);
997 CurrentRow = PcdGet32 (PcdSetupConOutRow);
998 for (Mode = 0; Mode < MaxMode; Mode++) {
999 Status = ConOut->QueryMode (ConOut, Mode, &Col, &Row);
1000 if (!EFI_ERROR (Status)) {
1001 if ((CurrentCol == Col) && (CurrentRow == Row)) {
1002 CallbackData->BmmFakeNvData.ConsoleOutMode = (UINT16)Mode;
1003 break;
1004 }
1005 }
1006 }
1007}
1008
1017VOID
1019 IN BMM_CALLBACK_DATA *CallbackData
1020 )
1021{
1022 UINT16 Index;
1023 BM_MENU_ENTRY *NewMenuEntry;
1024 UINT8 *ConInCheck;
1025 BM_CONSOLE_CONTEXT *NewConsoleContext;
1026 BM_TERMINAL_CONTEXT *NewTerminalContext;
1027
1028 ASSERT (CallbackData != NULL);
1029
1030 ConInCheck = &CallbackData->BmmFakeNvData.ConsoleInCheck[0];
1031 for (Index = 0; ((Index < ConsoleInpMenu.MenuNumber) && \
1032 (Index < MAX_MENU_NUMBER)); Index++)
1033 {
1034 NewMenuEntry = BOpt_GetMenuEntry (&ConsoleInpMenu, Index);
1035 NewConsoleContext = (BM_CONSOLE_CONTEXT *)NewMenuEntry->VariableContext;
1036 ConInCheck[Index] = NewConsoleContext->IsActive;
1037 }
1038
1039 for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) {
1040 NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index);
1041 NewTerminalContext = (BM_TERMINAL_CONTEXT *)NewMenuEntry->VariableContext;
1042 ASSERT (Index + ConsoleInpMenu.MenuNumber < MAX_MENU_NUMBER);
1043 ConInCheck[Index + ConsoleInpMenu.MenuNumber] = NewTerminalContext->IsConIn;
1044 }
1045}
1046
1055VOID
1057 IN BMM_CALLBACK_DATA *CallbackData
1058 )
1059{
1060 UINT16 Index;
1061 BM_MENU_ENTRY *NewMenuEntry;
1062 UINT8 *ConOutCheck;
1063 BM_CONSOLE_CONTEXT *NewConsoleContext;
1064 BM_TERMINAL_CONTEXT *NewTerminalContext;
1065
1066 ASSERT (CallbackData != NULL);
1067 ConOutCheck = &CallbackData->BmmFakeNvData.ConsoleOutCheck[0];
1068 for (Index = 0; ((Index < ConsoleOutMenu.MenuNumber) && \
1069 (Index < MAX_MENU_NUMBER)); Index++)
1070 {
1071 NewMenuEntry = BOpt_GetMenuEntry (&ConsoleOutMenu, Index);
1072 NewConsoleContext = (BM_CONSOLE_CONTEXT *)NewMenuEntry->VariableContext;
1073 ConOutCheck[Index] = NewConsoleContext->IsActive;
1074 }
1075
1076 for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) {
1077 NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index);
1078 NewTerminalContext = (BM_TERMINAL_CONTEXT *)NewMenuEntry->VariableContext;
1079 ASSERT (Index + ConsoleOutMenu.MenuNumber < MAX_MENU_NUMBER);
1080 ConOutCheck[Index + ConsoleOutMenu.MenuNumber] = NewTerminalContext->IsConOut;
1081 }
1082}
1083
1092VOID
1094 IN BMM_CALLBACK_DATA *CallbackData
1095 )
1096{
1097 UINT16 Index;
1098 BM_MENU_ENTRY *NewMenuEntry;
1099 UINT8 *ConErrCheck;
1100 BM_CONSOLE_CONTEXT *NewConsoleContext;
1101 BM_TERMINAL_CONTEXT *NewTerminalContext;
1102
1103 ASSERT (CallbackData != NULL);
1104 ConErrCheck = &CallbackData->BmmFakeNvData.ConsoleErrCheck[0];
1105 for (Index = 0; ((Index < ConsoleErrMenu.MenuNumber) && \
1106 (Index < MAX_MENU_NUMBER)); Index++)
1107 {
1108 NewMenuEntry = BOpt_GetMenuEntry (&ConsoleErrMenu, Index);
1109 NewConsoleContext = (BM_CONSOLE_CONTEXT *)NewMenuEntry->VariableContext;
1110 ConErrCheck[Index] = NewConsoleContext->IsActive;
1111 }
1112
1113 for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) {
1114 NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index);
1115 NewTerminalContext = (BM_TERMINAL_CONTEXT *)NewMenuEntry->VariableContext;
1116 ASSERT (Index + ConsoleErrMenu.MenuNumber < MAX_MENU_NUMBER);
1117 ConErrCheck[Index + ConsoleErrMenu.MenuNumber] = NewTerminalContext->IsStdErr;
1118 }
1119}
1120
1129VOID
1131 IN BMM_CALLBACK_DATA *CallbackData
1132 )
1133{
1134 BMM_FAKE_NV_DATA *CurrentFakeNVMap;
1135 BM_MENU_ENTRY *NewMenuEntry;
1136 BM_TERMINAL_CONTEXT *NewTerminalContext;
1137 UINT16 TerminalIndex;
1138 UINT8 AttributeIndex;
1139
1140 ASSERT (CallbackData != NULL);
1141
1142 CurrentFakeNVMap = &CallbackData->BmmFakeNvData;
1143 for (TerminalIndex = 0; ((TerminalIndex < TerminalMenu.MenuNumber) && \
1144 (TerminalIndex < MAX_MENU_NUMBER)); TerminalIndex++)
1145 {
1146 NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, TerminalIndex);
1147 NewTerminalContext = (BM_TERMINAL_CONTEXT *)NewMenuEntry->VariableContext;
1148 for (AttributeIndex = 0; AttributeIndex < sizeof (BaudRateList) / sizeof (BaudRateList[0]); AttributeIndex++) {
1149 if (NewTerminalContext->BaudRate == (UINT64)(BaudRateList[AttributeIndex].Value)) {
1150 NewTerminalContext->BaudRateIndex = AttributeIndex;
1151 break;
1152 }
1153 }
1154
1155 for (AttributeIndex = 0; AttributeIndex < ARRAY_SIZE (DataBitsList); AttributeIndex++) {
1156 if (NewTerminalContext->DataBits == (UINT64)(DataBitsList[AttributeIndex].Value)) {
1157 NewTerminalContext->DataBitsIndex = AttributeIndex;
1158 break;
1159 }
1160 }
1161
1162 for (AttributeIndex = 0; AttributeIndex < ARRAY_SIZE (ParityList); AttributeIndex++) {
1163 if (NewTerminalContext->Parity == (UINT64)(ParityList[AttributeIndex].Value)) {
1164 NewTerminalContext->ParityIndex = AttributeIndex;
1165 break;
1166 }
1167 }
1168
1169 for (AttributeIndex = 0; AttributeIndex < ARRAY_SIZE (StopBitsList); AttributeIndex++) {
1170 if (NewTerminalContext->StopBits == (UINT64)(StopBitsList[AttributeIndex].Value)) {
1171 NewTerminalContext->StopBitsIndex = AttributeIndex;
1172 break;
1173 }
1174 }
1175
1176 CurrentFakeNVMap->COMBaudRate[TerminalIndex] = NewTerminalContext->BaudRateIndex;
1177 CurrentFakeNVMap->COMDataRate[TerminalIndex] = NewTerminalContext->DataBitsIndex;
1178 CurrentFakeNVMap->COMStopBits[TerminalIndex] = NewTerminalContext->StopBitsIndex;
1179 CurrentFakeNVMap->COMParity[TerminalIndex] = NewTerminalContext->ParityIndex;
1180 CurrentFakeNVMap->COMTerminalType[TerminalIndex] = NewTerminalContext->TerminalType;
1181 CurrentFakeNVMap->COMFlowControl[TerminalIndex] = NewTerminalContext->FlowControl;
1182 }
1183}
UINT64 UINTN
LIST_ENTRY *EFIAPI InitializeListHead(IN OUT LIST_ENTRY *ListHead)
Definition: LinkedList.c:182
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
Definition: LinkedList.c:259
UINT32 EFIAPI ReadUnaligned32(IN CONST UINT32 *Buffer)
Definition: Unaligned.c:145
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
Definition: MemLibGuid.c:73
UINTN EfiDevicePathInstanceCount(IN EFI_DEVICE_PATH_PROTOCOL *DevicePath)
Definition: BmLib.c:51
UINT16 * EfiLibStrFromDatahub(IN EFI_DEVICE_PATH_PROTOCOL *DevPath)
Definition: BmLib.c:78
CHAR16 * UiDevicePathToStr(IN EFI_DEVICE_PATH_PROTOCOL *DevPath)
VOID BOpt_FreeMenu(BM_MENU_OPTION *FreeMenu)
Definition: BootOption.c:256
BM_MENU_ENTRY * BOpt_GetMenuEntry(BM_MENU_OPTION *MenuOption, UINTN MenuNumber)
Definition: BootOption.c:229
VOID BOpt_DestroyMenuEntry(BM_MENU_ENTRY *MenuEntry)
Definition: BootOption.c:141
COM_ATTR DataBitsList[4]
Definition: Data.c:189
BM_MENU_ENTRY * BOpt_CreateMenuEntry(UINTN MenuType)
Definition: BootOption.c:75
COM_ATTR BaudRateList[19]
Definition: Data.c:107
COM_ATTR ParityList[5]
Definition: Data.c:211
BM_MENU_OPTION ConsoleErrMenu
Definition: Data.c:65
BM_MENU_OPTION ConsoleOutMenu
Definition: Data.c:56
BM_MENU_OPTION ConsoleInpMenu
Definition: Data.c:47
COM_ATTR StopBitsList[3]
Definition: Data.c:237
EFI_GUID TerminalTypeGuid[9]
Definition: Data.c:255
VOID ChangeVariableDevicePath(IN OUT EFI_DEVICE_PATH_PROTOCOL *DevicePath)
BOOLEAN MatchDevicePaths(IN EFI_DEVICE_PATH_PROTOCOL *Multi, IN EFI_DEVICE_PATH_PROTOCOL *Single)
Definition: ConsoleOption.c:25
EFI_STATUS GetAllConsoles(VOID)
VOID GetTerminalAttribute(IN BMM_CALLBACK_DATA *CallbackData)
VOID GetConsoleOutCheck(IN BMM_CALLBACK_DATA *CallbackData)
VOID GetConsoleOutMode(IN BMM_CALLBACK_DATA *CallbackData)
EFI_STATUS LocateSerialIo(VOID)
VOID GetConsoleErrCheck(IN BMM_CALLBACK_DATA *CallbackData)
VOID SortedUartHandle(IN EFI_HANDLE *Handles, IN UINTN NoHandles)
EFI_STATUS GetConsoleMenu(IN UINTN ConsoleMenuType)
EFI_STATUS UpdateComAttributeFromVariable(EFI_DEVICE_PATH_PROTOCOL *DevicePath)
EFI_STATUS FreeAllConsoles(VOID)
VOID GetConsoleInCheck(IN BMM_CALLBACK_DATA *CallbackData)
BOOLEAN RetrieveUartUid(IN EFI_HANDLE Handle, IN OUT UINT32 *AcpiUid)
EFI_STATUS ChangeTerminalDevicePath(IN OUT EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN BOOLEAN ChangeTerminal)
BOOLEAN IsTerminalDevicePath(IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, OUT TYPE_OF_TERMINAL *Termi, OUT UINTN *Com)
BOOLEAN IsIsaSerialNode(IN ACPI_HID_DEVICE_PATH *Acpi)
Definition: ConsoleOption.c:71
#define ACPI_DEVICE_PATH
Definition: DevicePath.h:190
#define ACPI_DP
Definition: DevicePath.h:195
#define MSG_UART_DP
Definition: DevicePath.h:692
#define MESSAGING_DEVICE_PATH
Definition: DevicePath.h:321
UINT8 EFIAPI DevicePathType(IN CONST VOID *Node)
UINT16 EFIAPI SetDevicePathNodeLength(IN OUT VOID *Node, IN UINTN Length)
UINT8 EFIAPI DevicePathSubType(IN CONST VOID *Node)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI AppendDevicePathNode(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL, IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL)
BOOLEAN EFIAPI IsDevicePathEnd(IN CONST VOID *Node)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI NextDevicePathNode(IN CONST VOID *Node)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI GetNextDevicePathInstance(IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath, OUT UINTN *Size)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI DuplicateDevicePath(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STRING_ID EFIAPI HiiSetString(IN EFI_HII_HANDLE HiiHandle, IN EFI_STRING_ID StringId OPTIONAL, IN CONST EFI_STRING String, IN CONST CHAR8 *SupportedLanguages OPTIONAL)
Definition: HiiString.c:52
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define ARRAY_SIZE(Array)
Definition: Base.h:1393
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define PcdGet32(TokenName)
Definition: PcdLib.h:362
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_SYSTEM_TABLE * gST
EFI_BOOT_SERVICES * gBS
EFI_STATUS EFIAPI GetEfiGlobalVariable2(IN CONST CHAR16 *Name, OUT VOID **Value, OUT UINTN *Size OPTIONAL)
Definition: UefiLib.c:1470
@ ByProtocol
Definition: UefiSpec.h:1518
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL * ConOut
Definition: UefiSpec.h:2064
Definition: Base.h:213