2 handles console redirection from boot manager
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
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.
15 #include "BootMaint.h"
18 Function creates a device path data structure that identically matches the
19 device path passed in.
22 @param DevPath A pointer to a device path data structure.
24 @return The new copy of DevPath is created to identically match the input.
25 @retval NULL Otherwise, NULL is returned.
28 EFI_DEVICE_PATH_PROTOCOL
*
29 DevicePathInstanceDup (
30 IN EFI_DEVICE_PATH_PROTOCOL
*DevPath
34 Update Com Ports attributes from DevicePath
37 @param DevicePath DevicePath that contains Com ports
39 @retval EFI_SUCCESS The update is successful.
43 UpdateComAttributeFromVariable (
44 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
48 Update the multi-instance device path of Terminal Device based on
49 the global TerminalMenu. If ChangeTernimal is TRUE, the terminal
50 device path in the Terminal Device in TerminalMenu is also updated.
52 @param DevicePath The multi-instance device path.
53 @param ChangeTerminal TRUE, then device path in the Terminal Device
54 in TerminalMenu is also updated; FALSE, no update.
56 @return EFI_SUCCESS The function completes successfully.
60 ChangeTerminalDevicePath (
61 IN OUT EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
62 IN BOOLEAN ChangeTerminal
65 EFI_DEVICE_PATH_PROTOCOL
*Node
;
66 EFI_DEVICE_PATH_PROTOCOL
*Node1
;
67 ACPI_HID_DEVICE_PATH
*Acpi
;
68 UART_DEVICE_PATH
*Uart
;
69 UART_DEVICE_PATH
*Uart1
;
72 BM_TERMINAL_CONTEXT
*NewTerminalContext
;
73 BM_MENU_ENTRY
*NewMenuEntry
;
75 Match
= EISA_PNP_ID (0x0501);
77 Node
= NextDevicePathNode (Node
);
79 while (!IsDevicePathEnd (Node
)) {
80 if ((DevicePathType (Node
) == ACPI_DEVICE_PATH
) && (DevicePathSubType (Node
) == ACPI_DP
)) {
81 Acpi
= (ACPI_HID_DEVICE_PATH
*) Node
;
82 if (CompareMem (&Acpi
->HID
, &Match
, sizeof (UINT32
)) == 0) {
83 CopyMem (&Com
, &Acpi
->UID
, sizeof (UINT32
));
87 NewMenuEntry
= BOpt_GetMenuEntry (&TerminalMenu
, Com
);
89 NewTerminalContext
= (BM_TERMINAL_CONTEXT
*) NewMenuEntry
->VariableContext
;
90 if ((DevicePathType (Node
) == MESSAGING_DEVICE_PATH
) && (DevicePathSubType (Node
) == MSG_UART_DP
)) {
91 Uart
= (UART_DEVICE_PATH
*) Node
;
94 &NewTerminalContext
->BaudRate
,
100 &NewTerminalContext
->DataBits
,
106 &NewTerminalContext
->Parity
,
112 &NewTerminalContext
->StopBits
,
116 // Change the device path in the ComPort
118 if (ChangeTerminal
) {
119 Node1
= NewTerminalContext
->DevicePath
;
120 Node1
= NextDevicePathNode (Node1
);
121 while (!IsDevicePathEnd (Node1
)) {
122 if ((DevicePathType (Node1
) == MESSAGING_DEVICE_PATH
) && (DevicePathSubType (Node1
) == MSG_UART_DP
)) {
123 Uart1
= (UART_DEVICE_PATH
*) Node1
;
126 &NewTerminalContext
->BaudRate
,
132 &NewTerminalContext
->DataBits
,
138 &NewTerminalContext
->Parity
,
144 &NewTerminalContext
->StopBits
,
152 Node1
= NextDevicePathNode (Node1
);
161 Node
= NextDevicePathNode (Node
);
169 Update the device path that describing a terminal device
170 based on the new BaudRate, Data Bits, parity and Stop Bits
173 @param DevicePath terminal device's path
177 ChangeVariableDevicePath (
178 IN OUT EFI_DEVICE_PATH_PROTOCOL
*DevicePath
181 EFI_DEVICE_PATH_PROTOCOL
*Node
;
182 ACPI_HID_DEVICE_PATH
*Acpi
;
183 UART_DEVICE_PATH
*Uart
;
186 BM_TERMINAL_CONTEXT
*NewTerminalContext
;
187 BM_MENU_ENTRY
*NewMenuEntry
;
189 Match
= EISA_PNP_ID (0x0501);
191 Node
= NextDevicePathNode (Node
);
193 while (!IsDevicePathEnd (Node
)) {
194 if ((DevicePathType (Node
) == ACPI_DEVICE_PATH
) && (DevicePathSubType (Node
) == ACPI_DP
)) {
195 Acpi
= (ACPI_HID_DEVICE_PATH
*) Node
;
196 if (CompareMem (&Acpi
->HID
, &Match
, sizeof (UINT32
)) == 0) {
197 CopyMem (&Com
, &Acpi
->UID
, sizeof (UINT32
));
201 if ((DevicePathType (Node
) == MESSAGING_DEVICE_PATH
) && (DevicePathSubType (Node
) == MSG_UART_DP
)) {
202 NewMenuEntry
= BOpt_GetMenuEntry (
206 ASSERT (NewMenuEntry
!= NULL
);
207 NewTerminalContext
= (BM_TERMINAL_CONTEXT
*) NewMenuEntry
->VariableContext
;
208 Uart
= (UART_DEVICE_PATH
*) Node
;
211 &NewTerminalContext
->BaudRate
,
217 &NewTerminalContext
->DataBits
,
223 &NewTerminalContext
->Parity
,
229 &NewTerminalContext
->StopBits
,
234 Node
= NextDevicePathNode (Node
);
239 Retrieve ACPI UID of UART from device path
241 @param Handle The handle for the UART device.
242 @param AcpiUid The ACPI UID on output.
244 @retval TRUE Find valid UID from device path
245 @retval FALSE Can't find
250 IN EFI_HANDLE Handle
,
251 IN OUT UINT32
*AcpiUid
256 ACPI_HID_DEVICE_PATH
*Acpi
;
257 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
259 gBS
->HandleProtocol (
261 &gEfiDevicePathProtocolGuid
,
262 (VOID
**) &DevicePath
264 Ptr
= (UINT8
*) DevicePath
;
266 while (*Ptr
!= END_DEVICE_PATH_TYPE
) {
270 Ptr
= Ptr
- sizeof (UART_DEVICE_PATH
) - sizeof (ACPI_HID_DEVICE_PATH
);
271 Acpi
= (ACPI_HID_DEVICE_PATH
*) Ptr
;
272 Match
= EISA_PNP_ID (0x0501);
274 if (CompareMem (&Acpi
->HID
, &Match
, sizeof (UINT32
)) == 0) {
275 if (AcpiUid
!= NULL
) {
276 *AcpiUid
= Acpi
->UID
;
285 Sort Uart handles array with Acpi->UID from low to high.
287 @param Handles EFI_SERIAL_IO_PROTOCOL handle buffer
288 @param NoHandles EFI_SERIAL_IO_PROTOCOL handle count
292 IN EFI_HANDLE
*Handles
,
302 EFI_HANDLE TempHandle
;
304 for (Index1
= 0; Index1
< NoHandles
-1; Index1
++) {
305 if (!RetrieveUartUid (Handles
[Index1
], &AcpiUid1
)) {
308 TempHandle
= Handles
[Index1
];
310 TempAcpiUid
= AcpiUid1
;
312 for (Index2
= Index1
+1; Index2
< NoHandles
; Index2
++) {
313 if (!RetrieveUartUid (Handles
[Index2
], &AcpiUid2
)) {
316 if (AcpiUid2
< TempAcpiUid
) {
317 TempAcpiUid
= AcpiUid2
;
318 TempHandle
= Handles
[Index2
];
322 Handles
[Position
] = Handles
[Index1
];
323 Handles
[Index1
] = TempHandle
;
328 Test whether DevicePath is a valid Terminal
331 @param DevicePath DevicePath to be checked
332 @param Termi If DevicePath is valid Terminal, terminal type is returned.
333 @param Com If DevicePath is valid Terminal, Com Port type is returned.
335 @retval TRUE If DevicePath point to a Terminal.
336 @retval FALSE If DevicePath does not point to a Terminal.
340 IsTerminalDevicePath (
341 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
342 OUT TYPE_OF_TERMINAL
*Termi
,
347 Build a list containing all serial devices.
350 @retval EFI_SUCCESS The function complete successfully.
351 @retval EFI_UNSUPPORTED No serial ports present.
365 ACPI_HID_DEVICE_PATH
*Acpi
;
366 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
368 EFI_SERIAL_IO_PROTOCOL
*SerialIo
;
369 EFI_DEVICE_PATH_PROTOCOL
*OutDevicePath
;
370 EFI_DEVICE_PATH_PROTOCOL
*InpDevicePath
;
371 EFI_DEVICE_PATH_PROTOCOL
*ErrDevicePath
;
372 BM_MENU_ENTRY
*NewMenuEntry
;
373 BM_TERMINAL_CONTEXT
*NewTerminalContext
;
374 EFI_DEVICE_PATH_PROTOCOL
*NewDevicePath
;
375 VENDOR_DEVICE_PATH Vendor
;
377 // Get all handles that have SerialIo protocol installed
379 InitializeListHead (&TerminalMenu
.Head
);
380 TerminalMenu
.MenuNumber
= 0;
381 Status
= gBS
->LocateHandleBuffer (
383 &gEfiSerialIoProtocolGuid
,
388 if (EFI_ERROR (Status
)) {
390 // No serial ports present
392 return EFI_UNSUPPORTED
;
396 // Sort Uart handles array with Acpi->UID from low to high
397 // then Terminal menu can be built from low Acpi->UID to high Acpi->UID
399 SortedUartHandle (Handles
, NoHandles
);
401 for (Index
= 0; Index
< NoHandles
; Index
++) {
403 // Check to see whether the handle has DevicePath Protocol installed
405 gBS
->HandleProtocol (
407 &gEfiDevicePathProtocolGuid
,
408 (VOID
**) &DevicePath
410 Ptr
= (UINT8
*) DevicePath
;
411 while (*Ptr
!= END_DEVICE_PATH_TYPE
) {
415 Ptr
= Ptr
- sizeof (UART_DEVICE_PATH
) - sizeof (ACPI_HID_DEVICE_PATH
);
416 Acpi
= (ACPI_HID_DEVICE_PATH
*) Ptr
;
417 Match
= EISA_PNP_ID (0x0501);
419 if (CompareMem (&Acpi
->HID
, &Match
, sizeof (UINT32
)) == 0) {
420 NewMenuEntry
= BOpt_CreateMenuEntry (BM_TERMINAL_CONTEXT_SELECT
);
421 if (NewMenuEntry
== NULL
) {
422 SafeFreePool (Handles
);
423 return EFI_OUT_OF_RESOURCES
;
426 NewTerminalContext
= (BM_TERMINAL_CONTEXT
*) NewMenuEntry
->VariableContext
;
427 CopyMem (&NewMenuEntry
->OptionNumber
, &Acpi
->UID
, sizeof (UINT32
));
428 NewTerminalContext
->DevicePath
= DevicePathInstanceDup (DevicePath
);
430 // BugBug: I have no choice, calling EfiLibStrFromDatahub will hang the system!
431 // coz' the misc data for each platform is not correct, actually it's the device path stored in
432 // datahub which is not completed, so a searching for end of device path will enter a
435 NewMenuEntry
->DisplayString
= EfiLibStrFromDatahub (DevicePath
);
436 if (NULL
== NewMenuEntry
->DisplayString
) {
437 NewMenuEntry
->DisplayString
= DevicePathToStr (DevicePath
);
440 NewMenuEntry
->HelpString
= NULL
;
442 gBS
->HandleProtocol (
444 &gEfiSerialIoProtocolGuid
,
449 &NewTerminalContext
->BaudRate
,
450 &SerialIo
->Mode
->BaudRate
,
455 &NewTerminalContext
->DataBits
,
456 &SerialIo
->Mode
->DataBits
,
461 &NewTerminalContext
->Parity
,
462 &SerialIo
->Mode
->Parity
,
467 &NewTerminalContext
->StopBits
,
468 &SerialIo
->Mode
->StopBits
,
471 InsertTailList (&TerminalMenu
.Head
, &NewMenuEntry
->Link
);
472 TerminalMenu
.MenuNumber
++;
475 SafeFreePool (Handles
);
478 // Get L"ConOut", L"ConIn" and L"ErrOut" from the Var
480 OutDevicePath
= EfiLibGetVariable (L
"ConOut", &gEfiGlobalVariableGuid
);
481 InpDevicePath
= EfiLibGetVariable (L
"ConIn", &gEfiGlobalVariableGuid
);
482 ErrDevicePath
= EfiLibGetVariable (L
"ErrOut", &gEfiGlobalVariableGuid
);
483 if (OutDevicePath
!= NULL
) {
484 UpdateComAttributeFromVariable (OutDevicePath
);
487 if (InpDevicePath
!= NULL
) {
488 UpdateComAttributeFromVariable (InpDevicePath
);
491 if (ErrDevicePath
!= NULL
) {
492 UpdateComAttributeFromVariable (ErrDevicePath
);
495 for (Index
= 0; Index
< TerminalMenu
.MenuNumber
; Index
++) {
496 NewMenuEntry
= BOpt_GetMenuEntry (&TerminalMenu
, Index
);
497 if (NULL
== NewMenuEntry
) {
498 return EFI_NOT_FOUND
;
501 NewTerminalContext
= (BM_TERMINAL_CONTEXT
*) NewMenuEntry
->VariableContext
;
503 NewTerminalContext
->TerminalType
= 0;
504 NewTerminalContext
->IsConIn
= FALSE
;
505 NewTerminalContext
->IsConOut
= FALSE
;
506 NewTerminalContext
->IsStdErr
= FALSE
;
508 Vendor
.Header
.Type
= MESSAGING_DEVICE_PATH
;
509 Vendor
.Header
.SubType
= MSG_VENDOR_DP
;
511 for (Index2
= 0; Index2
< 4; Index2
++) {
512 CopyMem (&Vendor
.Guid
, &TerminalTypeGuid
[Index2
], sizeof (EFI_GUID
));
513 SetDevicePathNodeLength (&Vendor
.Header
, sizeof (VENDOR_DEVICE_PATH
));
514 NewDevicePath
= AppendDevicePathNode (
515 NewTerminalContext
->DevicePath
,
516 (EFI_DEVICE_PATH_PROTOCOL
*) &Vendor
518 SafeFreePool (NewMenuEntry
->HelpString
);
520 // NewMenuEntry->HelpString = DevicePathToStr (NewDevicePath);
521 // NewMenuEntry->DisplayString = NewMenuEntry->HelpString;
523 NewMenuEntry
->HelpString
= NULL
;
525 if (BdsLibMatchDevicePaths (OutDevicePath
, NewDevicePath
)) {
526 NewTerminalContext
->IsConOut
= TRUE
;
527 NewTerminalContext
->TerminalType
= (UINT8
) Index2
;
530 if (BdsLibMatchDevicePaths (InpDevicePath
, NewDevicePath
)) {
531 NewTerminalContext
->IsConIn
= TRUE
;
532 NewTerminalContext
->TerminalType
= (UINT8
) Index2
;
535 if (BdsLibMatchDevicePaths (ErrDevicePath
, NewDevicePath
)) {
536 NewTerminalContext
->IsStdErr
= TRUE
;
537 NewTerminalContext
->TerminalType
= (UINT8
) Index2
;
546 Update Com Ports attributes from DevicePath
549 @param DevicePath DevicePath that contains Com ports
551 @retval EFI_SUCCESS The update is successful.
552 @retval EFI_NOT_FOUND Can not find specific menu entry
555 UpdateComAttributeFromVariable (
556 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
559 EFI_DEVICE_PATH_PROTOCOL
*Node
;
560 EFI_DEVICE_PATH_PROTOCOL
*SerialNode
;
561 ACPI_HID_DEVICE_PATH
*Acpi
;
562 UART_DEVICE_PATH
*Uart
;
563 UART_DEVICE_PATH
*Uart1
;
565 UINTN TerminalNumber
;
566 BM_MENU_ENTRY
*NewMenuEntry
;
567 BM_TERMINAL_CONTEXT
*NewTerminalContext
;
570 Match
= EISA_PNP_ID (0x0501);
572 Node
= NextDevicePathNode (Node
);
574 for (Index
= 0; Index
< TerminalMenu
.MenuNumber
; Index
++) {
575 while (!IsDevicePathEnd (Node
)) {
576 if ((DevicePathType (Node
) == ACPI_DEVICE_PATH
) && (DevicePathSubType (Node
) == ACPI_DP
)) {
577 Acpi
= (ACPI_HID_DEVICE_PATH
*) Node
;
578 if (CompareMem (&Acpi
->HID
, &Match
, sizeof (UINT32
)) == 0) {
579 CopyMem (&TerminalNumber
, &Acpi
->UID
, sizeof (UINT32
));
583 if ((DevicePathType (Node
) == MESSAGING_DEVICE_PATH
) && (DevicePathSubType (Node
) == MSG_UART_DP
)) {
584 Uart
= (UART_DEVICE_PATH
*) Node
;
585 NewMenuEntry
= BOpt_GetMenuEntry (&TerminalMenu
, TerminalNumber
);
586 if (NULL
== NewMenuEntry
) {
587 return EFI_NOT_FOUND
;
590 NewTerminalContext
= (BM_TERMINAL_CONTEXT
*) NewMenuEntry
->VariableContext
;
592 &NewTerminalContext
->BaudRate
,
598 &NewTerminalContext
->DataBits
,
604 &NewTerminalContext
->Parity
,
610 &NewTerminalContext
->StopBits
,
615 SerialNode
= NewTerminalContext
->DevicePath
;
616 SerialNode
= NextDevicePathNode (SerialNode
);
617 while (!IsDevicePathEnd (SerialNode
)) {
618 if ((DevicePathType (SerialNode
) == MESSAGING_DEVICE_PATH
) && (DevicePathSubType (SerialNode
) == MSG_UART_DP
)) {
620 // Update following device paths according to
621 // previous acquired uart attributes
623 Uart1
= (UART_DEVICE_PATH
*) SerialNode
;
626 &NewTerminalContext
->BaudRate
,
632 &NewTerminalContext
->DataBits
,
637 &NewTerminalContext
->Parity
,
642 &NewTerminalContext
->StopBits
,
649 SerialNode
= NextDevicePathNode (SerialNode
);
656 Node
= NextDevicePathNode (Node
);
667 Function creates a device path data structure that identically matches the
668 device path passed in.
671 @param DevPath A pointer to a device path data structure.
673 @return The new copy of DevPath is created to identically match the input.
674 @retval NULL Otherwise, NULL is returned.
677 EFI_DEVICE_PATH_PROTOCOL
*
678 DevicePathInstanceDup (
679 IN EFI_DEVICE_PATH_PROTOCOL
*DevPath
682 EFI_DEVICE_PATH_PROTOCOL
*NewDevPath
;
683 EFI_DEVICE_PATH_PROTOCOL
*DevicePathInst
;
684 EFI_DEVICE_PATH_PROTOCOL
*Temp
;
689 // get the size of an instance from the input
692 DevicePathInst
= GetNextDevicePathInstance (&Temp
, &Size
);
695 // Make a copy and set proper end type
699 NewDevPath
= AllocateZeroPool (Size
);
700 ASSERT (NewDevPath
!= NULL
);
703 if (NewDevPath
!= NULL
) {
704 CopyMem (NewDevPath
, DevicePathInst
, Size
);
705 Ptr
= (UINT8
*) NewDevPath
;
706 Ptr
+= Size
- sizeof (EFI_DEVICE_PATH_PROTOCOL
);
707 Temp
= (EFI_DEVICE_PATH_PROTOCOL
*) Ptr
;
708 SetDevicePathEndNode (Temp
);
715 Build up Console Menu based on types passed in. The type can
716 be BM_CONSOLE_IN_CONTEXT_SELECT, BM_CONSOLE_OUT_CONTEXT_SELECT
717 and BM_CONSOLE_ERR_CONTEXT_SELECT.
719 @param ConsoleMenuType Can be BM_CONSOLE_IN_CONTEXT_SELECT, BM_CONSOLE_OUT_CONTEXT_SELECT
720 and BM_CONSOLE_ERR_CONTEXT_SELECT.
722 @retval EFI_UNSUPPORTED The type passed in is not in the 3 types defined.
723 @retval EFI_NOT_FOUND If the EFI Variable defined in UEFI spec with name "ConOutDev",
724 "ConInDev" or "ConErrDev" doesn't exists.
725 @retval EFI_OUT_OF_RESOURCES Not enough resource to complete the operations.
726 @retval EFI_SUCCESS Function completes successfully.
731 IN UINTN ConsoleMenuType
734 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
735 EFI_DEVICE_PATH_PROTOCOL
*AllDevicePath
;
736 EFI_DEVICE_PATH_PROTOCOL
*MultiDevicePath
;
737 EFI_DEVICE_PATH_PROTOCOL
*DevicePathInst
;
742 BM_MENU_ENTRY
*NewMenuEntry
;
743 BM_CONSOLE_CONTEXT
*NewConsoleContext
;
744 TYPE_OF_TERMINAL Terminal
;
746 BM_MENU_OPTION
*ConsoleMenu
;
749 AllDevicePath
= NULL
;
751 switch (ConsoleMenuType
) {
752 case BM_CONSOLE_IN_CONTEXT_SELECT
:
753 ConsoleMenu
= &ConsoleInpMenu
;
754 DevicePath
= EfiLibGetVariable (
756 &gEfiGlobalVariableGuid
759 AllDevicePath
= EfiLibGetVariable (
761 &gEfiGlobalVariableGuid
765 case BM_CONSOLE_OUT_CONTEXT_SELECT
:
766 ConsoleMenu
= &ConsoleOutMenu
;
767 DevicePath
= EfiLibGetVariable (
769 &gEfiGlobalVariableGuid
772 AllDevicePath
= EfiLibGetVariable (
774 &gEfiGlobalVariableGuid
778 case BM_CONSOLE_ERR_CONTEXT_SELECT
:
779 ConsoleMenu
= &ConsoleErrMenu
;
780 DevicePath
= EfiLibGetVariable (
782 &gEfiGlobalVariableGuid
785 AllDevicePath
= EfiLibGetVariable (
787 &gEfiGlobalVariableGuid
792 return EFI_UNSUPPORTED
;
795 if (NULL
== AllDevicePath
) {
796 return EFI_NOT_FOUND
;
799 InitializeListHead (&ConsoleMenu
->Head
);
801 AllCount
= EfiDevicePathInstanceCount (AllDevicePath
);
802 ConsoleMenu
->MenuNumber
= 0;
804 // Following is menu building up for Console Devices selected.
806 MultiDevicePath
= AllDevicePath
;
808 for (Index
= 0; Index
< AllCount
; Index
++) {
809 DevicePathInst
= GetNextDevicePathInstance (&MultiDevicePath
, &Size
);
811 NewMenuEntry
= BOpt_CreateMenuEntry (BM_CONSOLE_CONTEXT_SELECT
);
812 if (NULL
== NewMenuEntry
) {
813 return EFI_OUT_OF_RESOURCES
;
816 NewConsoleContext
= (BM_CONSOLE_CONTEXT
*) NewMenuEntry
->VariableContext
;
817 NewMenuEntry
->OptionNumber
= Index2
;
819 NewConsoleContext
->DevicePath
= DevicePathInstanceDup (DevicePathInst
);
820 NewMenuEntry
->DisplayString
= EfiLibStrFromDatahub (NewConsoleContext
->DevicePath
);
821 if (NULL
== NewMenuEntry
->DisplayString
) {
822 NewMenuEntry
->DisplayString
= DevicePathToStr (NewConsoleContext
->DevicePath
);
825 NewConsoleContext
->IsTerminal
= IsTerminalDevicePath (
826 NewConsoleContext
->DevicePath
,
831 NewConsoleContext
->IsActive
= BdsLibMatchDevicePaths (
833 NewConsoleContext
->DevicePath
836 if (NewConsoleContext
->IsTerminal
) {
837 BOpt_DestroyMenuEntry (NewMenuEntry
);
840 ConsoleMenu
->MenuNumber
++;
841 InsertTailList (&ConsoleMenu
->Head
, &NewMenuEntry
->Link
);
849 Build up ConsoleOutMenu, ConsoleInpMenu and ConsoleErrMenu
851 @retval EFI_SUCCESS The function always complete successfully.
859 GetConsoleMenu (BM_CONSOLE_IN_CONTEXT_SELECT
);
860 GetConsoleMenu (BM_CONSOLE_OUT_CONTEXT_SELECT
);
861 GetConsoleMenu (BM_CONSOLE_ERR_CONTEXT_SELECT
);
866 Free ConsoleOutMenu, ConsoleInpMenu and ConsoleErrMenu
868 @retval EFI_SUCCESS The function always complete successfully.
875 BOpt_FreeMenu (&ConsoleOutMenu
);
876 BOpt_FreeMenu (&ConsoleInpMenu
);
877 BOpt_FreeMenu (&ConsoleErrMenu
);
878 BOpt_FreeMenu (&TerminalMenu
);
883 Test whether DevicePath is a valid Terminal
886 @param DevicePath DevicePath to be checked
887 @param Termi If DevicePath is valid Terminal, terminal type is returned.
888 @param Com If DevicePath is valid Terminal, Com Port type is returned.
890 @retval TRUE If DevicePath point to a Terminal.
891 @retval FALSE If DevicePath does not point to a Terminal.
895 IsTerminalDevicePath (
896 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
897 OUT TYPE_OF_TERMINAL
*Termi
,
903 VENDOR_DEVICE_PATH
*Vendor
;
904 ACPI_HID_DEVICE_PATH
*Acpi
;
911 // Parse the Device Path, should be change later!!!
913 Ptr
= (UINT8
*) DevicePath
;
914 while (*Ptr
!= END_DEVICE_PATH_TYPE
) {
918 Ptr
= Ptr
- sizeof (VENDOR_DEVICE_PATH
);
919 Vendor
= (VENDOR_DEVICE_PATH
*) Ptr
;
922 // There are four kinds of Terminal types
923 // check to see whether this devicepath
924 // is one of that type
926 CopyMem (&TempGuid
, &Vendor
->Guid
, sizeof (EFI_GUID
));
928 if (CompareGuid (&TempGuid
, &TerminalTypeGuid
[0])) {
932 if (CompareGuid (&TempGuid
, &TerminalTypeGuid
[1])) {
936 if (CompareGuid (&TempGuid
, &TerminalTypeGuid
[2])) {
937 *Termi
= VT_100_PLUS
;
940 if (CompareGuid (&TempGuid
, &TerminalTypeGuid
[3])) {
954 Ptr
= Ptr
- sizeof (UART_DEVICE_PATH
) - sizeof (ACPI_HID_DEVICE_PATH
);
955 Acpi
= (ACPI_HID_DEVICE_PATH
*) Ptr
;
956 Match
= EISA_PNP_ID (0x0501);
957 if (CompareMem (&Acpi
->HID
, &Match
, sizeof (UINT32
)) == 0) {
958 CopyMem (Com
, &Acpi
->UID
, sizeof (UINT32
));
967 Get mode number according to column and row
969 @param CallbackData The BMM context data.
973 IN BMM_CALLBACK_DATA
*CallbackData
983 CONSOLE_OUT_MODE
*ModeInfo
;
984 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*ConOut
;
986 ConOut
= gST
->ConOut
;
987 MaxMode
= (UINTN
) (ConOut
->Mode
->MaxMode
);
988 ModeInfo
= EfiLibGetVariable (VAR_CON_OUT_MODE
, &gEfiGenericPlatformVariableGuid
);
990 if (ModeInfo
!= NULL
) {
991 CurrentCol
= ModeInfo
->Column
;
992 CurrentRow
= ModeInfo
->Row
;
993 for (Mode
= 0; Mode
< MaxMode
; Mode
++) {
994 Status
= ConOut
->QueryMode (ConOut
, Mode
, &Col
, &Row
);
995 if (!EFI_ERROR(Status
)) {
996 if (CurrentCol
== Col
&& CurrentRow
== Row
) {
997 CallbackData
->BmmFakeNvData
.ConsoleOutMode
= (UINT16
) Mode
;
1003 SafeFreePool (ModeInfo
);