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
) {
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 if (Handles
!= NULL
) {
480 // Get L"ConOut", L"ConIn" and L"ErrOut" from the Var
482 OutDevicePath
= EfiLibGetVariable (L
"ConOut", &gEfiGlobalVariableGuid
);
483 InpDevicePath
= EfiLibGetVariable (L
"ConIn", &gEfiGlobalVariableGuid
);
484 ErrDevicePath
= EfiLibGetVariable (L
"ErrOut", &gEfiGlobalVariableGuid
);
485 if (OutDevicePath
!= NULL
) {
486 UpdateComAttributeFromVariable (OutDevicePath
);
489 if (InpDevicePath
!= NULL
) {
490 UpdateComAttributeFromVariable (InpDevicePath
);
493 if (ErrDevicePath
!= NULL
) {
494 UpdateComAttributeFromVariable (ErrDevicePath
);
497 for (Index
= 0; Index
< TerminalMenu
.MenuNumber
; Index
++) {
498 NewMenuEntry
= BOpt_GetMenuEntry (&TerminalMenu
, Index
);
499 if (NULL
== NewMenuEntry
) {
500 return EFI_NOT_FOUND
;
503 NewTerminalContext
= (BM_TERMINAL_CONTEXT
*) NewMenuEntry
->VariableContext
;
505 NewTerminalContext
->TerminalType
= 0;
506 NewTerminalContext
->IsConIn
= FALSE
;
507 NewTerminalContext
->IsConOut
= FALSE
;
508 NewTerminalContext
->IsStdErr
= FALSE
;
510 Vendor
.Header
.Type
= MESSAGING_DEVICE_PATH
;
511 Vendor
.Header
.SubType
= MSG_VENDOR_DP
;
513 for (Index2
= 0; Index2
< 4; Index2
++) {
514 CopyMem (&Vendor
.Guid
, &TerminalTypeGuid
[Index2
], sizeof (EFI_GUID
));
515 SetDevicePathNodeLength (&Vendor
.Header
, sizeof (VENDOR_DEVICE_PATH
));
516 NewDevicePath
= AppendDevicePathNode (
517 NewTerminalContext
->DevicePath
,
518 (EFI_DEVICE_PATH_PROTOCOL
*) &Vendor
520 if (NewMenuEntry
->HelpString
!= NULL
) {
521 FreePool (NewMenuEntry
->HelpString
);
524 // NewMenuEntry->HelpString = DevicePathToStr (NewDevicePath);
525 // NewMenuEntry->DisplayString = NewMenuEntry->HelpString;
527 NewMenuEntry
->HelpString
= NULL
;
529 if (BdsLibMatchDevicePaths (OutDevicePath
, NewDevicePath
)) {
530 NewTerminalContext
->IsConOut
= TRUE
;
531 NewTerminalContext
->TerminalType
= (UINT8
) Index2
;
534 if (BdsLibMatchDevicePaths (InpDevicePath
, NewDevicePath
)) {
535 NewTerminalContext
->IsConIn
= TRUE
;
536 NewTerminalContext
->TerminalType
= (UINT8
) Index2
;
539 if (BdsLibMatchDevicePaths (ErrDevicePath
, NewDevicePath
)) {
540 NewTerminalContext
->IsStdErr
= TRUE
;
541 NewTerminalContext
->TerminalType
= (UINT8
) Index2
;
550 Update Com Ports attributes from DevicePath
553 @param DevicePath DevicePath that contains Com ports
555 @retval EFI_SUCCESS The update is successful.
556 @retval EFI_NOT_FOUND Can not find specific menu entry
559 UpdateComAttributeFromVariable (
560 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
563 EFI_DEVICE_PATH_PROTOCOL
*Node
;
564 EFI_DEVICE_PATH_PROTOCOL
*SerialNode
;
565 ACPI_HID_DEVICE_PATH
*Acpi
;
566 UART_DEVICE_PATH
*Uart
;
567 UART_DEVICE_PATH
*Uart1
;
569 UINTN TerminalNumber
;
570 BM_MENU_ENTRY
*NewMenuEntry
;
571 BM_TERMINAL_CONTEXT
*NewTerminalContext
;
574 Match
= EISA_PNP_ID (0x0501);
576 Node
= NextDevicePathNode (Node
);
578 for (Index
= 0; Index
< TerminalMenu
.MenuNumber
; Index
++) {
579 while (!IsDevicePathEnd (Node
)) {
580 if ((DevicePathType (Node
) == ACPI_DEVICE_PATH
) && (DevicePathSubType (Node
) == ACPI_DP
)) {
581 Acpi
= (ACPI_HID_DEVICE_PATH
*) Node
;
582 if (CompareMem (&Acpi
->HID
, &Match
, sizeof (UINT32
)) == 0) {
583 CopyMem (&TerminalNumber
, &Acpi
->UID
, sizeof (UINT32
));
587 if ((DevicePathType (Node
) == MESSAGING_DEVICE_PATH
) && (DevicePathSubType (Node
) == MSG_UART_DP
)) {
588 Uart
= (UART_DEVICE_PATH
*) Node
;
589 NewMenuEntry
= BOpt_GetMenuEntry (&TerminalMenu
, TerminalNumber
);
590 if (NULL
== NewMenuEntry
) {
591 return EFI_NOT_FOUND
;
594 NewTerminalContext
= (BM_TERMINAL_CONTEXT
*) NewMenuEntry
->VariableContext
;
596 &NewTerminalContext
->BaudRate
,
602 &NewTerminalContext
->DataBits
,
608 &NewTerminalContext
->Parity
,
614 &NewTerminalContext
->StopBits
,
619 SerialNode
= NewTerminalContext
->DevicePath
;
620 SerialNode
= NextDevicePathNode (SerialNode
);
621 while (!IsDevicePathEnd (SerialNode
)) {
622 if ((DevicePathType (SerialNode
) == MESSAGING_DEVICE_PATH
) && (DevicePathSubType (SerialNode
) == MSG_UART_DP
)) {
624 // Update following device paths according to
625 // previous acquired uart attributes
627 Uart1
= (UART_DEVICE_PATH
*) SerialNode
;
630 &NewTerminalContext
->BaudRate
,
636 &NewTerminalContext
->DataBits
,
641 &NewTerminalContext
->Parity
,
646 &NewTerminalContext
->StopBits
,
653 SerialNode
= NextDevicePathNode (SerialNode
);
660 Node
= NextDevicePathNode (Node
);
671 Function creates a device path data structure that identically matches the
672 device path passed in.
675 @param DevPath A pointer to a device path data structure.
677 @return The new copy of DevPath is created to identically match the input.
678 @retval NULL Otherwise, NULL is returned.
681 EFI_DEVICE_PATH_PROTOCOL
*
682 DevicePathInstanceDup (
683 IN EFI_DEVICE_PATH_PROTOCOL
*DevPath
686 EFI_DEVICE_PATH_PROTOCOL
*NewDevPath
;
687 EFI_DEVICE_PATH_PROTOCOL
*DevicePathInst
;
688 EFI_DEVICE_PATH_PROTOCOL
*Temp
;
693 // get the size of an instance from the input
696 DevicePathInst
= GetNextDevicePathInstance (&Temp
, &Size
);
699 // Make a copy and set proper end type
703 NewDevPath
= AllocateZeroPool (Size
);
704 ASSERT (NewDevPath
!= NULL
);
707 if (NewDevPath
!= NULL
) {
708 CopyMem (NewDevPath
, DevicePathInst
, Size
);
709 Ptr
= (UINT8
*) NewDevPath
;
710 Ptr
+= Size
- sizeof (EFI_DEVICE_PATH_PROTOCOL
);
711 Temp
= (EFI_DEVICE_PATH_PROTOCOL
*) Ptr
;
712 SetDevicePathEndNode (Temp
);
719 Build up Console Menu based on types passed in. The type can
720 be BM_CONSOLE_IN_CONTEXT_SELECT, BM_CONSOLE_OUT_CONTEXT_SELECT
721 and BM_CONSOLE_ERR_CONTEXT_SELECT.
723 @param ConsoleMenuType Can be BM_CONSOLE_IN_CONTEXT_SELECT, BM_CONSOLE_OUT_CONTEXT_SELECT
724 and BM_CONSOLE_ERR_CONTEXT_SELECT.
726 @retval EFI_UNSUPPORTED The type passed in is not in the 3 types defined.
727 @retval EFI_NOT_FOUND If the EFI Variable defined in UEFI spec with name "ConOutDev",
728 "ConInDev" or "ConErrDev" doesn't exists.
729 @retval EFI_OUT_OF_RESOURCES Not enough resource to complete the operations.
730 @retval EFI_SUCCESS Function completes successfully.
735 IN UINTN ConsoleMenuType
738 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
739 EFI_DEVICE_PATH_PROTOCOL
*AllDevicePath
;
740 EFI_DEVICE_PATH_PROTOCOL
*MultiDevicePath
;
741 EFI_DEVICE_PATH_PROTOCOL
*DevicePathInst
;
746 BM_MENU_ENTRY
*NewMenuEntry
;
747 BM_CONSOLE_CONTEXT
*NewConsoleContext
;
748 TYPE_OF_TERMINAL Terminal
;
750 BM_MENU_OPTION
*ConsoleMenu
;
753 AllDevicePath
= NULL
;
755 switch (ConsoleMenuType
) {
756 case BM_CONSOLE_IN_CONTEXT_SELECT
:
757 ConsoleMenu
= &ConsoleInpMenu
;
758 DevicePath
= EfiLibGetVariable (
760 &gEfiGlobalVariableGuid
763 AllDevicePath
= EfiLibGetVariable (
765 &gEfiGlobalVariableGuid
769 case BM_CONSOLE_OUT_CONTEXT_SELECT
:
770 ConsoleMenu
= &ConsoleOutMenu
;
771 DevicePath
= EfiLibGetVariable (
773 &gEfiGlobalVariableGuid
776 AllDevicePath
= EfiLibGetVariable (
778 &gEfiGlobalVariableGuid
782 case BM_CONSOLE_ERR_CONTEXT_SELECT
:
783 ConsoleMenu
= &ConsoleErrMenu
;
784 DevicePath
= EfiLibGetVariable (
786 &gEfiGlobalVariableGuid
789 AllDevicePath
= EfiLibGetVariable (
791 &gEfiGlobalVariableGuid
796 return EFI_UNSUPPORTED
;
799 if (NULL
== AllDevicePath
) {
800 return EFI_NOT_FOUND
;
803 InitializeListHead (&ConsoleMenu
->Head
);
805 AllCount
= EfiDevicePathInstanceCount (AllDevicePath
);
806 ConsoleMenu
->MenuNumber
= 0;
808 // Following is menu building up for Console Devices selected.
810 MultiDevicePath
= AllDevicePath
;
812 for (Index
= 0; Index
< AllCount
; Index
++) {
813 DevicePathInst
= GetNextDevicePathInstance (&MultiDevicePath
, &Size
);
815 NewMenuEntry
= BOpt_CreateMenuEntry (BM_CONSOLE_CONTEXT_SELECT
);
816 if (NULL
== NewMenuEntry
) {
817 return EFI_OUT_OF_RESOURCES
;
820 NewConsoleContext
= (BM_CONSOLE_CONTEXT
*) NewMenuEntry
->VariableContext
;
821 NewMenuEntry
->OptionNumber
= Index2
;
823 NewConsoleContext
->DevicePath
= DevicePathInstanceDup (DevicePathInst
);
824 NewMenuEntry
->DisplayString
= EfiLibStrFromDatahub (NewConsoleContext
->DevicePath
);
825 if (NULL
== NewMenuEntry
->DisplayString
) {
826 NewMenuEntry
->DisplayString
= DevicePathToStr (NewConsoleContext
->DevicePath
);
829 NewConsoleContext
->IsTerminal
= IsTerminalDevicePath (
830 NewConsoleContext
->DevicePath
,
835 NewConsoleContext
->IsActive
= BdsLibMatchDevicePaths (
837 NewConsoleContext
->DevicePath
840 if (NewConsoleContext
->IsTerminal
) {
841 BOpt_DestroyMenuEntry (NewMenuEntry
);
844 ConsoleMenu
->MenuNumber
++;
845 InsertTailList (&ConsoleMenu
->Head
, &NewMenuEntry
->Link
);
853 Build up ConsoleOutMenu, ConsoleInpMenu and ConsoleErrMenu
855 @retval EFI_SUCCESS The function always complete successfully.
863 GetConsoleMenu (BM_CONSOLE_IN_CONTEXT_SELECT
);
864 GetConsoleMenu (BM_CONSOLE_OUT_CONTEXT_SELECT
);
865 GetConsoleMenu (BM_CONSOLE_ERR_CONTEXT_SELECT
);
870 Free ConsoleOutMenu, ConsoleInpMenu and ConsoleErrMenu
872 @retval EFI_SUCCESS The function always complete successfully.
879 BOpt_FreeMenu (&ConsoleOutMenu
);
880 BOpt_FreeMenu (&ConsoleInpMenu
);
881 BOpt_FreeMenu (&ConsoleErrMenu
);
882 BOpt_FreeMenu (&TerminalMenu
);
887 Test whether DevicePath is a valid Terminal
890 @param DevicePath DevicePath to be checked
891 @param Termi If DevicePath is valid Terminal, terminal type is returned.
892 @param Com If DevicePath is valid Terminal, Com Port type is returned.
894 @retval TRUE If DevicePath point to a Terminal.
895 @retval FALSE If DevicePath does not point to a Terminal.
899 IsTerminalDevicePath (
900 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
901 OUT TYPE_OF_TERMINAL
*Termi
,
907 VENDOR_DEVICE_PATH
*Vendor
;
908 ACPI_HID_DEVICE_PATH
*Acpi
;
915 // Parse the Device Path, should be change later!!!
917 Ptr
= (UINT8
*) DevicePath
;
918 while (*Ptr
!= END_DEVICE_PATH_TYPE
) {
922 Ptr
= Ptr
- sizeof (VENDOR_DEVICE_PATH
);
923 Vendor
= (VENDOR_DEVICE_PATH
*) Ptr
;
926 // There are four kinds of Terminal types
927 // check to see whether this devicepath
928 // is one of that type
930 CopyMem (&TempGuid
, &Vendor
->Guid
, sizeof (EFI_GUID
));
932 if (CompareGuid (&TempGuid
, &TerminalTypeGuid
[0])) {
936 if (CompareGuid (&TempGuid
, &TerminalTypeGuid
[1])) {
940 if (CompareGuid (&TempGuid
, &TerminalTypeGuid
[2])) {
941 *Termi
= VT_100_PLUS
;
944 if (CompareGuid (&TempGuid
, &TerminalTypeGuid
[3])) {
958 Ptr
= Ptr
- sizeof (UART_DEVICE_PATH
) - sizeof (ACPI_HID_DEVICE_PATH
);
959 Acpi
= (ACPI_HID_DEVICE_PATH
*) Ptr
;
960 Match
= EISA_PNP_ID (0x0501);
961 if (CompareMem (&Acpi
->HID
, &Match
, sizeof (UINT32
)) == 0) {
962 CopyMem (Com
, &Acpi
->UID
, sizeof (UINT32
));
971 Get mode number according to column and row
973 @param CallbackData The BMM context data.
977 IN BMM_CALLBACK_DATA
*CallbackData
987 CONSOLE_OUT_MODE
*ModeInfo
;
988 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*ConOut
;
990 ConOut
= gST
->ConOut
;
991 MaxMode
= (UINTN
) (ConOut
->Mode
->MaxMode
);
992 ModeInfo
= EfiLibGetVariable (VAR_CON_OUT_MODE
, &gEfiGenericPlatformVariableGuid
);
994 if (ModeInfo
!= NULL
) {
995 CurrentCol
= ModeInfo
->Column
;
996 CurrentRow
= ModeInfo
->Row
;
997 for (Mode
= 0; Mode
< MaxMode
; Mode
++) {
998 Status
= ConOut
->QueryMode (ConOut
, Mode
, &Col
, &Row
);
999 if (!EFI_ERROR(Status
)) {
1000 if (CurrentCol
== Col
&& CurrentRow
== Row
) {
1001 CallbackData
->BmmFakeNvData
.ConsoleOutMode
= (UINT16
) Mode
;
1006 FreePool (ModeInfo
);