2 Console Splitter Driver. Any Handle that attatched
3 EFI_CONSOLE_IDENTIFIER_PROTOCOL can be bound by this driver.
5 So far it works like any other driver by opening a SimpleTextIn and/or
6 SimpleTextOut protocol with EFI_OPEN_PROTOCOL_BY_DRIVER attributes. The big
7 difference is this driver does not layer a protocol on the passed in
8 handle, or construct a child handle like a standard device or bus driver.
9 This driver produces three virtual handles as children, one for console input
10 splitter, one for console output splitter and one for error output splitter.
11 EFI_CONSOLE_SPLIT_PROTOCOL will be attatched onto each virtual handle to
12 identify the splitter type.
14 Each virtual handle, that supports both the EFI_CONSOLE_SPLIT_PROTOCOL
15 and Console I/O protocol, will be produced in the driver entry point.
16 The virtual handle are added on driver entry and never removed.
17 Such design ensures sytem function well during none console device situation.
19 Copyright (c) 2006 Intel Corporation. <BR>
20 All rights reserved. This program and the accompanying materials
21 are licensed and made available under the terms and conditions of the BSD License
22 which accompanies this distribution. The full text of the license may be found at
23 http://opensource.org/licenses/bsd-license.php
25 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
26 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
30 #include "ConSplitter.h"
35 STATIC TEXT_IN_SPLITTER_PRIVATE_DATA mConIn
= {
36 TEXT_IN_SPLITTER_PRIVATE_DATA_SIGNATURE
,
39 ConSplitterTextInReset
,
40 ConSplitterTextInReadKeyStroke
,
44 (EFI_SIMPLE_TEXT_IN_PROTOCOL
**) NULL
,
48 ConSplitterSimplePointerReset
,
49 ConSplitterSimplePointerGetState
,
51 (EFI_SIMPLE_POINTER_MODE
*) NULL
61 (EFI_SIMPLE_POINTER_PROTOCOL
**) NULL
,
66 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
67 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
68 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
69 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
73 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
74 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
75 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
76 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
84 STATIC TEXT_OUT_SPLITTER_PRIVATE_DATA mConOut
= {
85 TEXT_OUT_SPLITTER_PRIVATE_DATA_SIGNATURE
,
88 ConSplitterTextOutReset
,
89 ConSplitterTextOutOutputString
,
90 ConSplitterTextOutTestString
,
91 ConSplitterTextOutQueryMode
,
92 ConSplitterTextOutSetMode
,
93 ConSplitterTextOutSetAttribute
,
94 ConSplitterTextOutClearScreen
,
95 ConSplitterTextOutSetCursorPosition
,
96 ConSplitterTextOutEnableCursor
,
97 (EFI_SIMPLE_TEXT_OUTPUT_MODE
*) NULL
107 #if (EFI_SPECIFICATION_VERSION < 0x00020000)
109 ConSpliterUgaDrawGetMode
,
110 ConSpliterUgaDrawSetMode
,
117 (EFI_UGA_PIXEL
*) NULL
,
120 ConSpliterGraphicsOutputQueryMode
,
121 ConSpliterGraphicsOutputSetMode
,
122 ConSpliterGraphicsOutputBlt
,
125 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) NULL
,
126 (TEXT_OUT_GOP_MODE
*) NULL
,
131 ConSpliterConsoleControlGetMode
,
132 ConSpliterConsoleControlSetMode
,
133 ConSpliterConsoleControlLockStdIn
137 (TEXT_OUT_AND_GOP_DATA
*) NULL
,
139 (TEXT_OUT_SPLITTER_QUERY_DATA
*) NULL
,
143 EfiConsoleControlScreenText
,
150 STATIC TEXT_OUT_SPLITTER_PRIVATE_DATA mStdErr
= {
151 TEXT_OUT_SPLITTER_PRIVATE_DATA_SIGNATURE
,
154 ConSplitterTextOutReset
,
155 ConSplitterTextOutOutputString
,
156 ConSplitterTextOutTestString
,
157 ConSplitterTextOutQueryMode
,
158 ConSplitterTextOutSetMode
,
159 ConSplitterTextOutSetAttribute
,
160 ConSplitterTextOutClearScreen
,
161 ConSplitterTextOutSetCursorPosition
,
162 ConSplitterTextOutEnableCursor
,
163 (EFI_SIMPLE_TEXT_OUTPUT_MODE
*) NULL
173 #if (EFI_SPECIFICATION_VERSION < 0x00020000)
175 ConSpliterUgaDrawGetMode
,
176 ConSpliterUgaDrawSetMode
,
183 (EFI_UGA_PIXEL
*) NULL
,
186 ConSpliterGraphicsOutputQueryMode
,
187 ConSpliterGraphicsOutputSetMode
,
188 ConSpliterGraphicsOutputBlt
,
191 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*) NULL
,
192 (TEXT_OUT_GOP_MODE
*) NULL
,
197 ConSpliterConsoleControlGetMode
,
198 ConSpliterConsoleControlSetMode
,
199 ConSpliterConsoleControlLockStdIn
203 (TEXT_OUT_AND_GOP_DATA
*) NULL
,
205 (TEXT_OUT_SPLITTER_QUERY_DATA
*) NULL
,
209 EfiConsoleControlScreenText
,
216 EFI_DRIVER_BINDING_PROTOCOL gConSplitterConInDriverBinding
= {
217 ConSplitterConInDriverBindingSupported
,
218 ConSplitterConInDriverBindingStart
,
219 ConSplitterConInDriverBindingStop
,
225 EFI_DRIVER_BINDING_PROTOCOL gConSplitterSimplePointerDriverBinding
= {
226 ConSplitterSimplePointerDriverBindingSupported
,
227 ConSplitterSimplePointerDriverBindingStart
,
228 ConSplitterSimplePointerDriverBindingStop
,
234 EFI_DRIVER_BINDING_PROTOCOL gConSplitterConOutDriverBinding
= {
235 ConSplitterConOutDriverBindingSupported
,
236 ConSplitterConOutDriverBindingStart
,
237 ConSplitterConOutDriverBindingStop
,
243 EFI_DRIVER_BINDING_PROTOCOL gConSplitterStdErrDriverBinding
= {
244 ConSplitterStdErrDriverBindingSupported
,
245 ConSplitterStdErrDriverBindingStart
,
246 ConSplitterStdErrDriverBindingStop
,
254 ConSplitterDriverEntry (
255 IN EFI_HANDLE ImageHandle
,
256 IN EFI_SYSTEM_TABLE
*SystemTable
261 Intialize a virtual console device to act as an agrigator of physical console
265 ImageHandle - (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
266 SystemTable - (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
275 // The driver creates virtual handles for ConIn, ConOut, and StdErr.
276 // The virtual handles will always exist even if no console exist in the
277 // system. This is need to support hotplug devices like USB.
280 // Create virtual device handle for StdErr Splitter
282 Status
= ConSplitterTextOutConstructor (&mStdErr
);
283 if (!EFI_ERROR (Status
)) {
284 Status
= gBS
->InstallMultipleProtocolInterfaces (
285 &mStdErr
.VirtualHandle
,
286 &gEfiSimpleTextOutProtocolGuid
,
288 &gEfiPrimaryStandardErrorDeviceGuid
,
294 // Create virtual device handle for ConIn Splitter
296 Status
= ConSplitterTextInConstructor (&mConIn
);
297 if (!EFI_ERROR (Status
)) {
298 Status
= gBS
->InstallMultipleProtocolInterfaces (
299 &mConIn
.VirtualHandle
,
300 &gEfiSimpleTextInProtocolGuid
,
302 &gEfiSimplePointerProtocolGuid
,
303 &mConIn
.SimplePointer
,
304 &gEfiPrimaryConsoleInDeviceGuid
,
308 if (!EFI_ERROR (Status
)) {
310 // Update the EFI System Table with new virtual console
312 gST
->ConsoleInHandle
= mConIn
.VirtualHandle
;
313 gST
->ConIn
= &mConIn
.TextIn
;
317 // Create virtual device handle for ConOut Splitter
319 Status
= ConSplitterTextOutConstructor (&mConOut
);
320 if (!EFI_ERROR (Status
)) {
321 #if (EFI_SPECIFICATION_VERSION < 0x00020000)
323 // In EFI mode, UGA Draw protocol is installed
325 Status
= gBS
->InstallMultipleProtocolInterfaces (
326 &mConOut
.VirtualHandle
,
327 &gEfiSimpleTextOutProtocolGuid
,
329 &gEfiUgaDrawProtocolGuid
,
331 &gEfiConsoleControlProtocolGuid
,
332 &mConOut
.ConsoleControl
,
333 &gEfiPrimaryConsoleOutDeviceGuid
,
339 // In UEFI mode, Graphics Output Protocol is installed on virtual handle.
341 Status
= gBS
->InstallMultipleProtocolInterfaces (
342 &mConOut
.VirtualHandle
,
343 &gEfiSimpleTextOutProtocolGuid
,
345 &gEfiGraphicsOutputProtocolGuid
,
346 &mConOut
.GraphicsOutput
,
347 &gEfiConsoleControlProtocolGuid
,
348 &mConOut
.ConsoleControl
,
349 &gEfiPrimaryConsoleOutDeviceGuid
,
355 if (!EFI_ERROR (Status
)) {
357 // Update the EFI System Table with new virtual console
359 gST
->ConsoleOutHandle
= mConOut
.VirtualHandle
;
360 gST
->ConOut
= &mConOut
.TextOut
;
365 // Update the CRC32 in the EFI System Table header
368 gBS
->CalculateCrc32 (
378 ConSplitterTextInConstructor (
379 TEXT_IN_SPLITTER_PRIVATE_DATA
*ConInPrivate
385 Construct the ConSplitter.
389 ConInPrivate - A pointer to the TEXT_IN_SPLITTER_PRIVATE_DATA structure.
392 EFI_OUT_OF_RESOURCES - Out of resources.
399 // Initilize console input splitter's private data.
401 Status
= ConSplitterGrowBuffer (
402 sizeof (EFI_SIMPLE_TEXT_IN_PROTOCOL
*),
403 &ConInPrivate
->TextInListCount
,
404 (VOID
**) &ConInPrivate
->TextInList
406 if (EFI_ERROR (Status
)) {
407 return EFI_OUT_OF_RESOURCES
;
410 // Create Event to support locking StdIn Device
412 Status
= gBS
->CreateEvent (
413 EFI_EVENT_TIMER
| EFI_EVENT_NOTIFY_SIGNAL
,
415 ConSpliterConsoleControlLockStdInEvent
,
417 &ConInPrivate
->LockEvent
419 ASSERT_EFI_ERROR (Status
);
421 Status
= gBS
->CreateEvent (
422 EFI_EVENT_NOTIFY_WAIT
,
424 ConSplitterTextInWaitForKey
,
426 &ConInPrivate
->TextIn
.WaitForKey
428 ASSERT_EFI_ERROR (Status
);
430 ConInPrivate
->SimplePointer
.Mode
= &ConInPrivate
->SimplePointerMode
;
432 Status
= ConSplitterGrowBuffer (
433 sizeof (EFI_SIMPLE_POINTER_PROTOCOL
*),
434 &ConInPrivate
->PointerListCount
,
435 (VOID
**) &ConInPrivate
->PointerList
437 if (EFI_ERROR (Status
)) {
438 return EFI_OUT_OF_RESOURCES
;
441 Status
= gBS
->CreateEvent (
442 EFI_EVENT_NOTIFY_WAIT
,
444 ConSplitterSimplePointerWaitForInput
,
446 &ConInPrivate
->SimplePointer
.WaitForInput
453 ConSplitterTextOutConstructor (
454 TEXT_OUT_SPLITTER_PRIVATE_DATA
*ConOutPrivate
460 // Initilize console output splitter's private data.
462 ConOutPrivate
->TextOut
.Mode
= &ConOutPrivate
->TextOutMode
;
464 Status
= ConSplitterGrowBuffer (
465 sizeof (TEXT_OUT_AND_GOP_DATA
),
466 &ConOutPrivate
->TextOutListCount
,
467 (VOID
**) &ConOutPrivate
->TextOutList
469 if (EFI_ERROR (Status
)) {
470 return EFI_OUT_OF_RESOURCES
;
473 Status
= ConSplitterGrowBuffer (
474 sizeof (TEXT_OUT_SPLITTER_QUERY_DATA
),
475 &ConOutPrivate
->TextOutQueryDataCount
,
476 (VOID
**) &ConOutPrivate
->TextOutQueryData
478 if (EFI_ERROR (Status
)) {
479 return EFI_OUT_OF_RESOURCES
;
482 // Setup the DevNullTextOut console to 80 x 25
484 ConOutPrivate
->TextOutQueryData
[0].Columns
= 80;
485 ConOutPrivate
->TextOutQueryData
[0].Rows
= 25;
486 DevNullTextOutSetMode (ConOutPrivate
, 0);
488 #if (EFI_SPECIFICATION_VERSION < 0x00020000)
490 // Setup the DevNullUgaDraw to 800 x 600 x 32 bits per pixel
492 ConSpliterUgaDrawSetMode (&ConOutPrivate
->UgaDraw
, 800, 600, 32, 60);
495 // Setup resource for mode information in Graphics Output Protocol interface
497 if ((ConOutPrivate
->GraphicsOutput
.Mode
= AllocateZeroPool (sizeof (EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE
))) == NULL
) {
498 return EFI_OUT_OF_RESOURCES
;
500 if ((ConOutPrivate
->GraphicsOutput
.Mode
->Info
= AllocateZeroPool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
))) == NULL
) {
501 return EFI_OUT_OF_RESOURCES
;
504 // Setup the DevNullGraphicsOutput to 800 x 600 x 32 bits per pixel
506 if ((ConOutPrivate
->GraphicsOutputModeBuffer
= AllocateZeroPool (sizeof (TEXT_OUT_GOP_MODE
))) == NULL
) {
507 return EFI_OUT_OF_RESOURCES
;
509 ConOutPrivate
->GraphicsOutputModeBuffer
[0].HorizontalResolution
= 800;
510 ConOutPrivate
->GraphicsOutputModeBuffer
[0].VerticalResolution
= 600;
513 // Initialize the following items, theset items remain unchanged in GraphicsOutput->SetMode()
514 // GraphicsOutputMode->Info->Version, GraphicsOutputMode->Info->PixelFormat
515 // GraphicsOutputMode->SizeOfInfo, GraphicsOutputMode->FrameBufferBase, GraphicsOutputMode->FrameBufferSize
517 ConOutPrivate
->GraphicsOutput
.Mode
->Info
->Version
= 0;
518 ConOutPrivate
->GraphicsOutput
.Mode
->Info
->PixelFormat
= PixelBltOnly
;
519 ConOutPrivate
->GraphicsOutput
.Mode
->SizeOfInfo
= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
);
520 ConOutPrivate
->GraphicsOutput
.Mode
->FrameBufferBase
= (EFI_PHYSICAL_ADDRESS
) NULL
;
521 ConOutPrivate
->GraphicsOutput
.Mode
->FrameBufferSize
= 0;
523 ConOutPrivate
->GraphicsOutput
.Mode
->MaxMode
= 1;
525 // Initial current mode to unknow state, and then set to mode 0
527 ConOutPrivate
->GraphicsOutput
.Mode
->Mode
= 0xffff;
528 ConOutPrivate
->GraphicsOutput
.SetMode (&ConOutPrivate
->GraphicsOutput
, 0);
535 ConSplitterSupported (
536 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
537 IN EFI_HANDLE ControllerHandle
,
543 Generic Supported Check
546 This - Pointer to protocol.
547 ControllerHandle - Controller Handle.
552 EFI_UNSUPPORTED - unsupported.
553 EFI_SUCCESS - operation is OK.
561 // Make sure the Console Splitter does not attempt to attach to itself
563 if (ControllerHandle
== mConIn
.VirtualHandle
) {
564 return EFI_UNSUPPORTED
;
567 if (ControllerHandle
== mConOut
.VirtualHandle
) {
568 return EFI_UNSUPPORTED
;
571 if (ControllerHandle
== mStdErr
.VirtualHandle
) {
572 return EFI_UNSUPPORTED
;
575 // Check to see whether the handle has the ConsoleInDevice GUID on it
577 Status
= gBS
->OpenProtocol (
581 This
->DriverBindingHandle
,
583 EFI_OPEN_PROTOCOL_BY_DRIVER
586 if (EFI_ERROR (Status
)) {
593 This
->DriverBindingHandle
,
602 ConSplitterConInDriverBindingSupported (
603 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
604 IN EFI_HANDLE ControllerHandle
,
605 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
610 Console In Supported Check
613 This - Pointer to protocol.
614 ControllerHandle - Controller handle.
615 RemainingDevicePath - Remaining device path.
623 return ConSplitterSupported (
626 &gEfiConsoleInDeviceGuid
632 ConSplitterSimplePointerDriverBindingSupported (
633 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
634 IN EFI_HANDLE ControllerHandle
,
635 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
640 Standard Error Supported Check
643 This - Pointer to protocol.
644 ControllerHandle - Controller handle.
645 RemainingDevicePath - Remaining device path.
653 return ConSplitterSupported (
656 &gEfiSimplePointerProtocolGuid
662 ConSplitterConOutDriverBindingSupported (
663 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
664 IN EFI_HANDLE ControllerHandle
,
665 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
670 Console Out Supported Check
673 This - Pointer to protocol.
674 ControllerHandle - Controller handle.
675 RemainingDevicePath - Remaining device path.
683 return ConSplitterSupported (
686 &gEfiConsoleOutDeviceGuid
692 ConSplitterStdErrDriverBindingSupported (
693 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
694 IN EFI_HANDLE ControllerHandle
,
695 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
700 Standard Error Supported Check
703 This - Pointer to protocol.
704 ControllerHandle - Controller handle.
705 RemainingDevicePath - Remaining device path.
713 return ConSplitterSupported (
716 &gEfiStandardErrorDeviceGuid
723 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
724 IN EFI_HANDLE ControllerHandle
,
725 IN EFI_HANDLE ConSplitterVirtualHandle
,
726 IN EFI_GUID
*DeviceGuid
,
727 IN EFI_GUID
*InterfaceGuid
,
733 Start ConSplitter on ControllerHandle, and create the virtual
734 agrogated console device on first call Start for a SimpleTextIn handle.
737 (Standard DriverBinding Protocol Start() function)
740 EFI_ERROR if a SimpleTextIn protocol is not started.
748 // Check to see whether the handle has the ConsoleInDevice GUID on it
750 Status
= gBS
->OpenProtocol (
754 This
->DriverBindingHandle
,
756 EFI_OPEN_PROTOCOL_BY_DRIVER
758 if (EFI_ERROR (Status
)) {
762 Status
= gBS
->OpenProtocol (
766 This
->DriverBindingHandle
,
767 ConSplitterVirtualHandle
,
768 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
770 if (EFI_ERROR (Status
)) {
774 return gBS
->OpenProtocol (
778 This
->DriverBindingHandle
,
779 ConSplitterVirtualHandle
,
780 EFI_OPEN_PROTOCOL_GET_PROTOCOL
786 ConSplitterConInDriverBindingStart (
787 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
788 IN EFI_HANDLE ControllerHandle
,
789 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
794 Start ConSplitter on ControllerHandle, and create the virtual
795 agrogated console device on first call Start for a SimpleTextIn handle.
798 This - Pointer to protocol.
799 ControllerHandle - Controller handle.
800 RemainingDevicePath - Remaining device path.
805 EFI_ERROR if a SimpleTextIn protocol is not started.
810 EFI_SIMPLE_TEXT_IN_PROTOCOL
*TextIn
;
813 // Start ConSplitter on ControllerHandle, and create the virtual
814 // agrogated console device on first call Start for a SimpleTextIn handle.
816 Status
= ConSplitterStart (
819 mConIn
.VirtualHandle
,
820 &gEfiConsoleInDeviceGuid
,
821 &gEfiSimpleTextInProtocolGuid
,
824 if (EFI_ERROR (Status
)) {
828 return ConSplitterTextInAddDevice (&mConIn
, TextIn
);
833 ConSplitterSimplePointerDriverBindingStart (
834 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
835 IN EFI_HANDLE ControllerHandle
,
836 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
841 Start ConSplitter on ControllerHandle, and create the virtual
842 agrogated console device on first call Start for a SimpleTextIn handle.
845 This - Pointer to protocol.
846 ControllerHandle - Controller handle.
847 RemainingDevicePath - Remaining device path.
851 EFI_ERROR if a SimpleTextIn protocol is not started.
856 EFI_SIMPLE_POINTER_PROTOCOL
*SimplePointer
;
858 Status
= ConSplitterStart (
861 mConIn
.VirtualHandle
,
862 &gEfiSimplePointerProtocolGuid
,
863 &gEfiSimplePointerProtocolGuid
,
864 (VOID
**) &SimplePointer
866 if (EFI_ERROR (Status
)) {
870 return ConSplitterSimplePointerAddDevice (&mConIn
, SimplePointer
);
875 ConSplitterConOutDriverBindingStart (
876 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
877 IN EFI_HANDLE ControllerHandle
,
878 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
883 Start ConSplitter on ControllerHandle, and create the virtual
884 agrogated console device on first call Start for a SimpleTextIn handle.
887 This - Pointer to protocol.
888 ControllerHandle - Controller handle.
889 RemainingDevicePath - Remaining device path.
892 EFI_ERROR if a SimpleTextIn protocol is not started.
897 EFI_SIMPLE_TEXT_OUT_PROTOCOL
*TextOut
;
898 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
899 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
901 Status
= ConSplitterStart (
904 mConOut
.VirtualHandle
,
905 &gEfiConsoleOutDeviceGuid
,
906 &gEfiSimpleTextOutProtocolGuid
,
909 if (EFI_ERROR (Status
)) {
913 // Try to Open Graphics Output protocol
915 Status
= gBS
->OpenProtocol (
917 &gEfiGraphicsOutputProtocolGuid
,
918 (VOID
**) &GraphicsOutput
,
919 This
->DriverBindingHandle
,
920 mConOut
.VirtualHandle
,
921 EFI_OPEN_PROTOCOL_GET_PROTOCOL
923 if (EFI_ERROR (Status
)) {
924 GraphicsOutput
= NULL
;
927 // Open UGA_DRAW protocol
929 Status
= gBS
->OpenProtocol (
931 &gEfiUgaDrawProtocolGuid
,
933 This
->DriverBindingHandle
,
934 mConOut
.VirtualHandle
,
935 EFI_OPEN_PROTOCOL_GET_PROTOCOL
937 if (EFI_ERROR (Status
)) {
941 // If both ConOut and StdErr incorporate the same Text Out device,
942 // their MaxMode and QueryData should be the intersection of both.
944 Status
= ConSplitterTextOutAddDevice (&mConOut
, TextOut
, GraphicsOutput
, UgaDraw
);
945 ConSplitterTextOutSetAttribute (&mConOut
.TextOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
947 #if (EFI_SPECIFICATION_VERSION < 0x00020000)
949 // Match the UGA mode data of ConOut with the current mode
951 if (UgaDraw
!= NULL
) {
954 &mConOut
.UgaHorizontalResolution
,
955 &mConOut
.UgaVerticalResolution
,
956 &mConOut
.UgaColorDepth
,
957 &mConOut
.UgaRefreshRate
967 ConSplitterStdErrDriverBindingStart (
968 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
969 IN EFI_HANDLE ControllerHandle
,
970 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
975 Start ConSplitter on ControllerHandle, and create the virtual
976 agrogated console device on first call Start for a SimpleTextIn handle.
979 This - Pointer to protocol.
980 ControllerHandle - Controller handle.
981 RemainingDevicePath - Remaining device path.
984 EFI_ERROR if a SimpleTextIn protocol is not started.
989 EFI_SIMPLE_TEXT_OUT_PROTOCOL
*TextOut
;
991 Status
= ConSplitterStart (
994 mStdErr
.VirtualHandle
,
995 &gEfiStandardErrorDeviceGuid
,
996 &gEfiSimpleTextOutProtocolGuid
,
999 if (EFI_ERROR (Status
)) {
1003 // If both ConOut and StdErr incorporate the same Text Out device,
1004 // their MaxMode and QueryData should be the intersection of both.
1006 Status
= ConSplitterTextOutAddDevice (&mStdErr
, TextOut
, NULL
, NULL
);
1007 ConSplitterTextOutSetAttribute (&mStdErr
.TextOut
, EFI_TEXT_ATTR (EFI_MAGENTA
, EFI_BLACK
));
1008 if (EFI_ERROR (Status
)) {
1012 if (mStdErr
.CurrentNumberOfConsoles
== 1) {
1013 gST
->StandardErrorHandle
= mStdErr
.VirtualHandle
;
1014 gST
->StdErr
= &mStdErr
.TextOut
;
1016 // Update the CRC32 in the EFI System Table header
1019 gBS
->CalculateCrc32 (
1020 (UINT8
*) &gST
->Hdr
,
1021 gST
->Hdr
.HeaderSize
,
1032 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
1033 IN EFI_HANDLE ControllerHandle
,
1034 IN EFI_HANDLE ConSplitterVirtualHandle
,
1035 IN EFI_GUID
*DeviceGuid
,
1036 IN EFI_GUID
*InterfaceGuid
,
1041 Routine Description:
1044 (Standard DriverBinding Protocol Stop() function)
1054 Status
= gBS
->OpenProtocol (
1058 This
->DriverBindingHandle
,
1060 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1062 if (EFI_ERROR (Status
)) {
1066 // close the protocol refered.
1068 gBS
->CloseProtocol (
1071 This
->DriverBindingHandle
,
1072 ConSplitterVirtualHandle
1074 gBS
->CloseProtocol (
1077 This
->DriverBindingHandle
,
1086 ConSplitterConInDriverBindingStop (
1087 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
1088 IN EFI_HANDLE ControllerHandle
,
1089 IN UINTN NumberOfChildren
,
1090 IN EFI_HANDLE
*ChildHandleBuffer
1094 Routine Description:
1097 (Standard DriverBinding Protocol Stop() function)
1106 EFI_SIMPLE_TEXT_IN_PROTOCOL
*TextIn
;
1108 if (NumberOfChildren
== 0) {
1112 Status
= ConSplitterStop (
1115 mConIn
.VirtualHandle
,
1116 &gEfiConsoleInDeviceGuid
,
1117 &gEfiSimpleTextInProtocolGuid
,
1120 if (EFI_ERROR (Status
)) {
1124 // Delete this console input device's data structures.
1126 return ConSplitterTextInDeleteDevice (&mConIn
, TextIn
);
1131 ConSplitterSimplePointerDriverBindingStop (
1132 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
1133 IN EFI_HANDLE ControllerHandle
,
1134 IN UINTN NumberOfChildren
,
1135 IN EFI_HANDLE
*ChildHandleBuffer
1139 Routine Description:
1142 (Standard DriverBinding Protocol Stop() function)
1151 EFI_SIMPLE_POINTER_PROTOCOL
*SimplePointer
;
1153 if (NumberOfChildren
== 0) {
1157 Status
= ConSplitterStop (
1160 mConIn
.VirtualHandle
,
1161 &gEfiSimplePointerProtocolGuid
,
1162 &gEfiSimplePointerProtocolGuid
,
1163 (VOID
**) &SimplePointer
1165 if (EFI_ERROR (Status
)) {
1169 // Delete this console input device's data structures.
1171 return ConSplitterSimplePointerDeleteDevice (&mConIn
, SimplePointer
);
1176 ConSplitterConOutDriverBindingStop (
1177 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
1178 IN EFI_HANDLE ControllerHandle
,
1179 IN UINTN NumberOfChildren
,
1180 IN EFI_HANDLE
*ChildHandleBuffer
1184 Routine Description:
1187 (Standard DriverBinding Protocol Stop() function)
1196 EFI_SIMPLE_TEXT_OUT_PROTOCOL
*TextOut
;
1198 if (NumberOfChildren
== 0) {
1202 Status
= ConSplitterStop (
1205 mConOut
.VirtualHandle
,
1206 &gEfiConsoleOutDeviceGuid
,
1207 &gEfiSimpleTextOutProtocolGuid
,
1210 if (EFI_ERROR (Status
)) {
1215 // Delete this console output device's data structures.
1217 return ConSplitterTextOutDeleteDevice (&mConOut
, TextOut
);
1222 ConSplitterStdErrDriverBindingStop (
1223 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
1224 IN EFI_HANDLE ControllerHandle
,
1225 IN UINTN NumberOfChildren
,
1226 IN EFI_HANDLE
*ChildHandleBuffer
1230 Routine Description:
1233 (Standard DriverBinding Protocol Stop() function)
1237 EFI_SUCCESS - Complete successfully.
1242 EFI_SIMPLE_TEXT_OUT_PROTOCOL
*TextOut
;
1244 if (NumberOfChildren
== 0) {
1248 Status
= ConSplitterStop (
1251 mStdErr
.VirtualHandle
,
1252 &gEfiStandardErrorDeviceGuid
,
1253 &gEfiSimpleTextOutProtocolGuid
,
1256 if (EFI_ERROR (Status
)) {
1260 // Delete this console error out device's data structures.
1262 Status
= ConSplitterTextOutDeleteDevice (&mStdErr
, TextOut
);
1263 if (EFI_ERROR (Status
)) {
1267 if (mStdErr
.CurrentNumberOfConsoles
== 0) {
1268 gST
->StandardErrorHandle
= NULL
;
1271 // Update the CRC32 in the EFI System Table header
1274 gBS
->CalculateCrc32 (
1275 (UINT8
*) &gST
->Hdr
,
1276 gST
->Hdr
.HeaderSize
,
1285 ConSplitterGrowBuffer (
1286 IN UINTN SizeOfCount
,
1288 IN OUT VOID
**Buffer
1292 Routine Description:
1293 Take the passed in Buffer of size SizeOfCount and grow the buffer
1294 by MAX (CONSOLE_SPLITTER_CONSOLES_ALLOC_UNIT, MaxGrow) * SizeOfCount
1295 bytes. Copy the current data in Buffer to the new version of Buffer
1296 and free the old version of buffer.
1300 SizeOfCount - Size of element in array
1301 Count - Current number of elements in array
1302 Buffer - Bigger version of passed in Buffer with all the data
1305 EFI_SUCCESS - Buffer size has grown
1306 EFI_OUT_OF_RESOURCES - Could not grow the buffer size
1317 // grow the buffer to new buffer size,
1318 // copy the old buffer's content to the new-size buffer,
1319 // then free the old buffer.
1321 OldSize
= *Count
* SizeOfCount
;
1322 *Count
+= CONSOLE_SPLITTER_CONSOLES_ALLOC_UNIT
;
1323 NewSize
= *Count
* SizeOfCount
;
1325 Ptr
= AllocateZeroPool (NewSize
);
1327 return EFI_OUT_OF_RESOURCES
;
1330 CopyMem (Ptr
, *Buffer
, OldSize
);
1332 if (*Buffer
!= NULL
) {
1333 gBS
->FreePool (*Buffer
);
1342 ConSplitterTextInAddDevice (
1343 IN TEXT_IN_SPLITTER_PRIVATE_DATA
*Private
,
1344 IN EFI_SIMPLE_TEXT_IN_PROTOCOL
*TextIn
1348 Routine Description:
1355 EFI_OUT_OF_RESOURCES
1362 // If the Text In List is full, enlarge it by calling growbuffer().
1364 if (Private
->CurrentNumberOfConsoles
>= Private
->TextInListCount
) {
1365 Status
= ConSplitterGrowBuffer (
1366 sizeof (EFI_SIMPLE_TEXT_IN_PROTOCOL
*),
1367 &Private
->TextInListCount
,
1368 (VOID
**) &Private
->TextInList
1370 if (EFI_ERROR (Status
)) {
1371 return EFI_OUT_OF_RESOURCES
;
1375 // Add the new text-in device data structure into the Text In List.
1377 Private
->TextInList
[Private
->CurrentNumberOfConsoles
] = TextIn
;
1378 Private
->CurrentNumberOfConsoles
++;
1381 // Extra CheckEvent added to reduce the double CheckEvent() in UI.c
1383 gBS
->CheckEvent (TextIn
->WaitForKey
);
1389 ConSplitterTextInDeleteDevice (
1390 IN TEXT_IN_SPLITTER_PRIVATE_DATA
*Private
,
1391 IN EFI_SIMPLE_TEXT_IN_PROTOCOL
*TextIn
1395 Routine Description:
1408 // Remove the specified text-in device data structure from the Text In List,
1409 // and rearrange the remaining data structures in the Text In List.
1411 for (Index
= 0; Index
< Private
->CurrentNumberOfConsoles
; Index
++) {
1412 if (Private
->TextInList
[Index
] == TextIn
) {
1413 for (Index
= Index
; Index
< Private
->CurrentNumberOfConsoles
- 1; Index
++) {
1414 Private
->TextInList
[Index
] = Private
->TextInList
[Index
+ 1];
1417 Private
->CurrentNumberOfConsoles
--;
1422 return EFI_NOT_FOUND
;
1426 ConSplitterSimplePointerAddDevice (
1427 IN TEXT_IN_SPLITTER_PRIVATE_DATA
*Private
,
1428 IN EFI_SIMPLE_POINTER_PROTOCOL
*SimplePointer
1432 Routine Description:
1438 EFI_OUT_OF_RESOURCES
1446 // If the Text In List is full, enlarge it by calling growbuffer().
1448 if (Private
->CurrentNumberOfPointers
>= Private
->PointerListCount
) {
1449 Status
= ConSplitterGrowBuffer (
1450 sizeof (EFI_SIMPLE_POINTER_PROTOCOL
*),
1451 &Private
->PointerListCount
,
1452 (VOID
**) &Private
->PointerList
1454 if (EFI_ERROR (Status
)) {
1455 return EFI_OUT_OF_RESOURCES
;
1459 // Add the new text-in device data structure into the Text In List.
1461 Private
->PointerList
[Private
->CurrentNumberOfPointers
] = SimplePointer
;
1462 Private
->CurrentNumberOfPointers
++;
1467 ConSplitterSimplePointerDeleteDevice (
1468 IN TEXT_IN_SPLITTER_PRIVATE_DATA
*Private
,
1469 IN EFI_SIMPLE_POINTER_PROTOCOL
*SimplePointer
1473 Routine Description:
1485 // Remove the specified text-in device data structure from the Text In List,
1486 // and rearrange the remaining data structures in the Text In List.
1488 for (Index
= 0; Index
< Private
->CurrentNumberOfPointers
; Index
++) {
1489 if (Private
->PointerList
[Index
] == SimplePointer
) {
1490 for (Index
= Index
; Index
< Private
->CurrentNumberOfPointers
- 1; Index
++) {
1491 Private
->PointerList
[Index
] = Private
->PointerList
[Index
+ 1];
1494 Private
->CurrentNumberOfPointers
--;
1499 return EFI_NOT_FOUND
;
1503 ConSplitterGrowMapTable (
1504 IN TEXT_OUT_SPLITTER_PRIVATE_DATA
*Private
1508 Routine Description:
1521 INT32
*TextOutModeMap
;
1522 INT32
*OldTextOutModeMap
;
1526 NewSize
= Private
->TextOutListCount
* sizeof (INT32
);
1527 OldTextOutModeMap
= Private
->TextOutModeMap
;
1528 TotalSize
= NewSize
* Private
->TextOutQueryDataCount
;
1530 TextOutModeMap
= AllocateZeroPool (TotalSize
);
1531 if (TextOutModeMap
== NULL
) {
1532 return EFI_OUT_OF_RESOURCES
;
1535 SetMem (TextOutModeMap
, TotalSize
, 0xFF);
1536 Private
->TextOutModeMap
= TextOutModeMap
;
1539 // If TextOutList has been enlarged, need to realloc the mode map table
1540 // The mode map table is regarded as a two dimension array.
1543 // 0 ---------> TextOutListCount ----> TextOutListCount
1544 // | -------------------------------------------
1551 // -------------------------------------------
1554 if (OldTextOutModeMap
!= NULL
) {
1556 Size
= Private
->CurrentNumberOfConsoles
* sizeof (INT32
);
1558 SrcAddress
= OldTextOutModeMap
;
1561 // Copy the old data to the new one
1563 while (Index
< Private
->TextOutMode
.MaxMode
) {
1564 CopyMem (TextOutModeMap
, SrcAddress
, Size
);
1565 TextOutModeMap
+= NewSize
;
1570 // Free the old buffer
1572 gBS
->FreePool (OldTextOutModeMap
);
1579 ConSplitterAddOutputMode (
1580 IN TEXT_OUT_SPLITTER_PRIVATE_DATA
*Private
,
1581 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL
*TextOut
1585 Routine Description:
1600 MaxMode
= TextOut
->Mode
->MaxMode
;
1601 Private
->TextOutMode
.MaxMode
= MaxMode
;
1604 // Grow the buffer if query data buffer is not large enough to
1605 // hold all the mode supported by the first console.
1607 while (MaxMode
> (INT32
) Private
->TextOutQueryDataCount
) {
1608 Status
= ConSplitterGrowBuffer (
1609 sizeof (TEXT_OUT_SPLITTER_QUERY_DATA
),
1610 &Private
->TextOutQueryDataCount
,
1611 (VOID
**) &Private
->TextOutQueryData
1613 if (EFI_ERROR (Status
)) {
1614 return EFI_OUT_OF_RESOURCES
;
1618 // Allocate buffer for the output mode map
1620 Status
= ConSplitterGrowMapTable (Private
);
1621 if (EFI_ERROR (Status
)) {
1622 return EFI_OUT_OF_RESOURCES
;
1625 // As the first textout device, directly add the mode in to QueryData
1626 // and at the same time record the mapping between QueryData and TextOut.
1630 while (Mode
< MaxMode
) {
1631 TextOut
->QueryMode (
1634 &Private
->TextOutQueryData
[Mode
].Columns
,
1635 &Private
->TextOutQueryData
[Mode
].Rows
1637 Private
->TextOutModeMap
[Index
] = Mode
;
1639 Index
+= Private
->TextOutListCount
;
1646 ConSplitterGetIntersection (
1647 IN INT32
*TextOutModeMap
,
1648 IN INT32
*NewlyAddedMap
,
1649 IN UINTN MapStepSize
,
1650 IN UINTN NewMapStepSize
,
1652 OUT INT32
*CurrentMode
1656 INT32
*CurrentMapEntry
;
1657 INT32
*NextMapEntry
;
1658 INT32 CurrentMaxMode
;
1662 CurrentMapEntry
= TextOutModeMap
;
1663 NextMapEntry
= TextOutModeMap
;
1664 CurrentMaxMode
= *MaxMode
;
1665 Mode
= *CurrentMode
;
1667 while (Index
< CurrentMaxMode
) {
1668 if (*NewlyAddedMap
== -1) {
1670 // This mode is not supported any more. Remove it. Special care
1671 // must be taken as this remove will also affect current mode;
1673 if (Index
== *CurrentMode
) {
1675 } else if (Index
< *CurrentMode
) {
1680 if (CurrentMapEntry
!= NextMapEntry
) {
1681 CopyMem (NextMapEntry
, CurrentMapEntry
, MapStepSize
* sizeof (INT32
));
1684 NextMapEntry
+= MapStepSize
;
1687 CurrentMapEntry
+= MapStepSize
;
1688 NewlyAddedMap
+= NewMapStepSize
;
1692 *CurrentMode
= Mode
;
1698 ConSplitterSyncOutputMode (
1699 IN TEXT_OUT_SPLITTER_PRIVATE_DATA
*Private
,
1700 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL
*TextOut
1704 Routine Description:
1707 Private - Private data structure.
1708 TextOut - Text Out Protocol.
1716 INT32 CurrentMaxMode
;
1719 INT32
*TextOutModeMap
;
1721 TEXT_OUT_SPLITTER_QUERY_DATA
*TextOutQueryData
;
1727 // Must make sure that current mode won't change even if mode number changes
1729 CurrentMode
= Private
->TextOutMode
.Mode
;
1730 CurrentMaxMode
= Private
->TextOutMode
.MaxMode
;
1731 TextOutModeMap
= Private
->TextOutModeMap
;
1732 StepSize
= Private
->TextOutListCount
;
1733 TextOutQueryData
= Private
->TextOutQueryData
;
1736 // Query all the mode that the newly added TextOut supports
1739 MapTable
= TextOutModeMap
+ Private
->CurrentNumberOfConsoles
;
1740 while (Mode
< TextOut
->Mode
->MaxMode
) {
1741 TextOut
->QueryMode (TextOut
, Mode
, &Columns
, &Rows
);
1744 // Search the QueryData database to see if they intersects
1747 while (Index
< CurrentMaxMode
) {
1748 if ((TextOutQueryData
[Index
].Rows
== Rows
) && (TextOutQueryData
[Index
].Columns
== Columns
)) {
1749 MapTable
[Index
* StepSize
] = Mode
;
1759 // Now search the TextOutModeMap table to find the intersection of supported
1760 // mode between ConSplitter and the newly added device.
1762 ConSplitterGetIntersection (
1767 &Private
->TextOutMode
.MaxMode
,
1768 &Private
->TextOutMode
.Mode
1775 ConSplitterGetIntersectionBetweenConOutAndStrErr (
1780 Routine Description:
1787 EFI_OUT_OF_RESOURCES
1791 UINTN ConOutNumOfConsoles
;
1792 UINTN StdErrNumOfConsoles
;
1793 TEXT_OUT_AND_GOP_DATA
*ConOutTextOutList
;
1794 TEXT_OUT_AND_GOP_DATA
*StdErrTextOutList
;
1799 INT32 ConOutCurrentMode
;
1800 INT32 StdErrCurrentMode
;
1801 INT32 ConOutMaxMode
;
1802 INT32 StdErrMaxMode
;
1805 INT32
*ConOutModeMap
;
1806 INT32
*StdErrModeMap
;
1807 INT32
*ConOutMapTable
;
1808 INT32
*StdErrMapTable
;
1809 TEXT_OUT_SPLITTER_QUERY_DATA
*ConOutQueryData
;
1810 TEXT_OUT_SPLITTER_QUERY_DATA
*StdErrQueryData
;
1811 UINTN ConOutStepSize
;
1812 UINTN StdErrStepSize
;
1813 BOOLEAN FoundTheSameTextOut
;
1814 UINTN ConOutMapTableSize
;
1815 UINTN StdErrMapTableSize
;
1817 ConOutNumOfConsoles
= mConOut
.CurrentNumberOfConsoles
;
1818 StdErrNumOfConsoles
= mStdErr
.CurrentNumberOfConsoles
;
1819 ConOutTextOutList
= mConOut
.TextOutList
;
1820 StdErrTextOutList
= mStdErr
.TextOutList
;
1823 FoundTheSameTextOut
= FALSE
;
1824 while ((Indexi
< ConOutNumOfConsoles
) && (!FoundTheSameTextOut
)) {
1826 while (Indexj
< StdErrNumOfConsoles
) {
1827 if (ConOutTextOutList
->TextOut
== StdErrTextOutList
->TextOut
) {
1828 FoundTheSameTextOut
= TRUE
;
1833 StdErrTextOutList
++;
1837 ConOutTextOutList
++;
1840 if (!FoundTheSameTextOut
) {
1844 // Must make sure that current mode won't change even if mode number changes
1846 ConOutCurrentMode
= mConOut
.TextOutMode
.Mode
;
1847 ConOutMaxMode
= mConOut
.TextOutMode
.MaxMode
;
1848 ConOutModeMap
= mConOut
.TextOutModeMap
;
1849 ConOutStepSize
= mConOut
.TextOutListCount
;
1850 ConOutQueryData
= mConOut
.TextOutQueryData
;
1852 StdErrCurrentMode
= mStdErr
.TextOutMode
.Mode
;
1853 StdErrMaxMode
= mStdErr
.TextOutMode
.MaxMode
;
1854 StdErrModeMap
= mStdErr
.TextOutModeMap
;
1855 StdErrStepSize
= mStdErr
.TextOutListCount
;
1856 StdErrQueryData
= mStdErr
.TextOutQueryData
;
1859 // Allocate the map table and set the map table's index to -1.
1861 ConOutMapTableSize
= ConOutMaxMode
* sizeof (INT32
);
1862 ConOutMapTable
= AllocateZeroPool (ConOutMapTableSize
);
1863 if (ConOutMapTable
== NULL
) {
1864 return EFI_OUT_OF_RESOURCES
;
1867 SetMem (ConOutMapTable
, ConOutMapTableSize
, 0xFF);
1869 StdErrMapTableSize
= StdErrMaxMode
* sizeof (INT32
);
1870 StdErrMapTable
= AllocateZeroPool (StdErrMapTableSize
);
1871 if (StdErrMapTable
== NULL
) {
1872 return EFI_OUT_OF_RESOURCES
;
1875 SetMem (StdErrMapTable
, StdErrMapTableSize
, 0xFF);
1878 // Find the intersection of the two set of modes. If they actually intersect, the
1879 // correponding entry in the map table is set to 1.
1882 while (Mode
< ConOutMaxMode
) {
1884 // Search the other's QueryData database to see if they intersect
1887 Rows
= ConOutQueryData
[Mode
].Rows
;
1888 Columns
= ConOutQueryData
[Mode
].Columns
;
1889 while (Index
< StdErrMaxMode
) {
1890 if ((StdErrQueryData
[Index
].Rows
== Rows
) && (StdErrQueryData
[Index
].Columns
== Columns
)) {
1891 ConOutMapTable
[Mode
] = 1;
1892 StdErrMapTable
[Index
] = 1;
1902 // Now search the TextOutModeMap table to find the intersection of supported
1903 // mode between ConSplitter and the newly added device.
1905 ConSplitterGetIntersection (
1908 mConOut
.TextOutListCount
,
1910 &(mConOut
.TextOutMode
.MaxMode
),
1911 &(mConOut
.TextOutMode
.Mode
)
1913 if (mConOut
.TextOutMode
.Mode
< 0) {
1914 mConOut
.TextOut
.SetMode (&(mConOut
.TextOut
), 0);
1917 ConSplitterGetIntersection (
1920 mStdErr
.TextOutListCount
,
1922 &(mStdErr
.TextOutMode
.MaxMode
),
1923 &(mStdErr
.TextOutMode
.Mode
)
1925 if (mStdErr
.TextOutMode
.Mode
< 0) {
1926 mStdErr
.TextOut
.SetMode (&(mStdErr
.TextOut
), 0);
1929 gBS
->FreePool (ConOutMapTable
);
1930 gBS
->FreePool (StdErrMapTable
);
1935 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
1937 ConSplitterAddGraphicsOutputMode (
1938 IN TEXT_OUT_SPLITTER_PRIVATE_DATA
*Private
,
1939 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
,
1940 IN EFI_UGA_DRAW_PROTOCOL
*UgaDraw
1944 Routine Description:
1956 TEXT_OUT_GOP_MODE
*Mode
;
1958 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
1959 EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE
*CurrentGraphicsOutputMode
;
1960 TEXT_OUT_GOP_MODE
*ModeBuffer
;
1961 TEXT_OUT_GOP_MODE
*MatchedMode
;
1965 if ((GraphicsOutput
== NULL
) && (UgaDraw
== NULL
)) {
1966 return EFI_UNSUPPORTED
;
1969 CurrentGraphicsOutputMode
= Private
->GraphicsOutput
.Mode
;
1971 if (GraphicsOutput
!= NULL
) {
1972 if (Private
->CurrentNumberOfGraphicsOutput
== 0) {
1974 // This is the first Graphics Output device added
1976 CurrentGraphicsOutputMode
->MaxMode
= GraphicsOutput
->Mode
->MaxMode
;
1977 CurrentGraphicsOutputMode
->Mode
= GraphicsOutput
->Mode
->Mode
;
1978 CopyMem (CurrentGraphicsOutputMode
->Info
, GraphicsOutput
->Mode
->Info
, GraphicsOutput
->Mode
->SizeOfInfo
);
1979 CurrentGraphicsOutputMode
->SizeOfInfo
= GraphicsOutput
->Mode
->SizeOfInfo
;
1980 CurrentGraphicsOutputMode
->FrameBufferBase
= GraphicsOutput
->Mode
->FrameBufferBase
;
1981 CurrentGraphicsOutputMode
->FrameBufferSize
= GraphicsOutput
->Mode
->FrameBufferSize
;
1984 // Allocate resource for the private mode buffer
1986 ModeBuffer
= AllocatePool (sizeof (TEXT_OUT_GOP_MODE
) * GraphicsOutput
->Mode
->MaxMode
);
1987 if (ModeBuffer
== NULL
) {
1988 return EFI_OUT_OF_RESOURCES
;
1990 gBS
->FreePool (Private
->GraphicsOutputModeBuffer
);
1991 Private
->GraphicsOutputModeBuffer
= ModeBuffer
;
1994 // Store all supported display modes to the private mode buffer
1997 for (Index
= 0; Index
< GraphicsOutput
->Mode
->MaxMode
; Index
++) {
1998 Status
= GraphicsOutput
->QueryMode (GraphicsOutput
, (UINT32
) Index
, &SizeOfInfo
, &Info
);
1999 if (EFI_ERROR (Status
)) {
2002 Mode
->HorizontalResolution
= Info
->HorizontalResolution
;
2003 Mode
->VerticalResolution
= Info
->VerticalResolution
;
2005 gBS
->FreePool (Info
);
2009 // Check intersection of display mode
2011 ModeBuffer
= AllocatePool (sizeof (TEXT_OUT_GOP_MODE
) * CurrentGraphicsOutputMode
->MaxMode
);
2012 if (ModeBuffer
== NULL
) {
2013 return EFI_OUT_OF_RESOURCES
;
2016 MatchedMode
= ModeBuffer
;
2017 Mode
= &Private
->GraphicsOutputModeBuffer
[0];
2018 for (Index
= 0; Index
< CurrentGraphicsOutputMode
->MaxMode
; Index
++) {
2021 for (NumberIndex
= 0; NumberIndex
< GraphicsOutput
->Mode
->MaxMode
; NumberIndex
++) {
2022 Status
= GraphicsOutput
->QueryMode (GraphicsOutput
, (UINT32
) NumberIndex
, &SizeOfInfo
, &Info
);
2023 if (EFI_ERROR (Status
)) {
2026 if ((Info
->HorizontalResolution
== Mode
->HorizontalResolution
) &&
2027 (Info
->VerticalResolution
== Mode
->VerticalResolution
)){
2029 gBS
->FreePool (Info
);
2032 gBS
->FreePool (Info
);
2036 CopyMem (MatchedMode
, Mode
, sizeof (TEXT_OUT_GOP_MODE
));
2044 // Drop the old mode buffer, assign it to a new one
2046 gBS
->FreePool (Private
->GraphicsOutputModeBuffer
);
2047 Private
->GraphicsOutputModeBuffer
= ModeBuffer
;
2050 // Physical frame buffer is no longer available when there are more than one physical GOP devices
2052 CurrentGraphicsOutputMode
->MaxMode
= (UINT32
) (((UINTN
) MatchedMode
- (UINTN
) ModeBuffer
) / sizeof (TEXT_OUT_GOP_MODE
));
2053 CurrentGraphicsOutputMode
->Info
->PixelFormat
= PixelBltOnly
;
2054 ZeroMem (&CurrentGraphicsOutputMode
->Info
->PixelInformation
, sizeof (EFI_PIXEL_BITMASK
));
2055 CurrentGraphicsOutputMode
->SizeOfInfo
= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
);
2056 CurrentGraphicsOutputMode
->FrameBufferBase
= (EFI_PHYSICAL_ADDRESS
) NULL
;
2057 CurrentGraphicsOutputMode
->FrameBufferSize
= 0;
2061 // Select a prefered Display mode 800x600
2063 for (Index
= 0; Index
< CurrentGraphicsOutputMode
->MaxMode
; Index
++) {
2064 Mode
= &Private
->GraphicsOutputModeBuffer
[Index
];
2065 if ((Mode
->HorizontalResolution
== 800) && (Mode
->VerticalResolution
== 600)) {
2070 // Prefered mode is not found, set to mode 0
2072 if (Index
>= CurrentGraphicsOutputMode
->MaxMode
) {
2077 // Current mode number may need update now, so set it to an invalide mode number
2079 CurrentGraphicsOutputMode
->Mode
= 0xffff;
2082 // For UGA device, it's inconvenient to retrieve all the supported display modes.
2083 // To simplify the implementation, only add one resolution(800x600, 32bit color depth) as defined in UEFI spec
2085 CurrentGraphicsOutputMode
->MaxMode
= 1;
2086 CurrentGraphicsOutputMode
->Info
->Version
= 0;
2087 CurrentGraphicsOutputMode
->Info
->HorizontalResolution
= 800;
2088 CurrentGraphicsOutputMode
->Info
->VerticalResolution
= 600;
2089 CurrentGraphicsOutputMode
->Info
->PixelFormat
= PixelBltOnly
;
2090 CurrentGraphicsOutputMode
->Info
->PixelsPerScanLine
= 800;
2091 CurrentGraphicsOutputMode
->SizeOfInfo
= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
);
2092 CurrentGraphicsOutputMode
->FrameBufferBase
= (EFI_PHYSICAL_ADDRESS
) NULL
;
2093 CurrentGraphicsOutputMode
->FrameBufferSize
= 0;
2096 // Update the private mode buffer
2098 ModeBuffer
= &Private
->GraphicsOutputModeBuffer
[0];
2099 ModeBuffer
->HorizontalResolution
= 800;
2100 ModeBuffer
->VerticalResolution
= 600;
2103 // Current mode is unknow now, set it to an invalid mode number 0xffff
2105 CurrentGraphicsOutputMode
->Mode
= 0xffff;
2110 // Force GraphicsOutput mode to be set,
2111 // regardless whether the console is in EfiConsoleControlScreenGraphics or EfiConsoleControlScreenText mode
2113 Private
->HardwareNeedsStarting
= TRUE
;
2114 Status
= Private
->GraphicsOutput
.SetMode (&Private
->GraphicsOutput
, (UINT32
) Index
);
2116 Private
->CurrentNumberOfGraphicsOutput
++;
2123 ConSplitterTextOutAddDevice (
2124 IN TEXT_OUT_SPLITTER_PRIVATE_DATA
*Private
,
2125 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL
*TextOut
,
2126 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
,
2127 IN EFI_UGA_DRAW_PROTOCOL
*UgaDraw
2131 Routine Description:
2142 UINTN CurrentNumOfConsoles
;
2145 TEXT_OUT_AND_GOP_DATA
*TextAndGop
;
2147 Status
= EFI_SUCCESS
;
2148 CurrentNumOfConsoles
= Private
->CurrentNumberOfConsoles
;
2151 // If the Text Out List is full, enlarge it by calling growbuffer().
2153 while (CurrentNumOfConsoles
>= Private
->TextOutListCount
) {
2154 Status
= ConSplitterGrowBuffer (
2155 sizeof (TEXT_OUT_AND_GOP_DATA
),
2156 &Private
->TextOutListCount
,
2157 (VOID
**) &Private
->TextOutList
2159 if (EFI_ERROR (Status
)) {
2160 return EFI_OUT_OF_RESOURCES
;
2163 // Also need to reallocate the TextOutModeMap table
2165 Status
= ConSplitterGrowMapTable (Private
);
2166 if (EFI_ERROR (Status
)) {
2167 return EFI_OUT_OF_RESOURCES
;
2171 TextAndGop
= &Private
->TextOutList
[CurrentNumOfConsoles
];
2173 TextAndGop
->TextOut
= TextOut
;
2174 TextAndGop
->GraphicsOutput
= GraphicsOutput
;
2175 TextAndGop
->UgaDraw
= UgaDraw
;
2177 if ((GraphicsOutput
== NULL
) && (UgaDraw
== NULL
)) {
2179 // If No UGA device then use the ConOut device
2181 TextAndGop
->TextOutEnabled
= TRUE
;
2184 // If UGA device use ConOut device only used if UGA screen is in Text mode
2186 TextAndGop
->TextOutEnabled
= (BOOLEAN
) (Private
->ConsoleOutputMode
== EfiConsoleControlScreenText
);
2189 if (CurrentNumOfConsoles
== 0) {
2191 // Add the first device's output mode to console splitter's mode list
2193 Status
= ConSplitterAddOutputMode (Private
, TextOut
);
2195 ConSplitterSyncOutputMode (Private
, TextOut
);
2198 Private
->CurrentNumberOfConsoles
++;
2201 // Scan both TextOutList, for the intersection TextOut device
2202 // maybe both ConOut and StdErr incorporate the same Text Out
2203 // device in them, thus the output of both should be synced.
2205 ConSplitterGetIntersectionBetweenConOutAndStrErr ();
2207 CurrentMode
= Private
->TextOutMode
.Mode
;
2208 MaxMode
= Private
->TextOutMode
.MaxMode
;
2209 ASSERT (MaxMode
>= 1);
2211 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
2212 if ((GraphicsOutput
!= NULL
) || (UgaDraw
!= NULL
)) {
2213 ConSplitterAddGraphicsOutputMode (Private
, GraphicsOutput
, UgaDraw
);
2217 if (Private
->ConsoleOutputMode
== EfiConsoleControlScreenGraphics
&& GraphicsOutput
!= NULL
) {
2219 // We just added a new UGA device in graphics mode
2221 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
2222 DevNullGopSync (Private
, GraphicsOutput
, UgaDraw
);
2224 DevNullUgaSync (Private
, UgaDraw
);
2226 } else if ((CurrentMode
>= 0) && ((GraphicsOutput
!= NULL
) || (UgaDraw
!= NULL
)) && (CurrentMode
< Private
->TextOutMode
.MaxMode
)) {
2228 // The new console supports the same mode of the current console so sync up
2230 DevNullSyncGopStdOut (Private
);
2233 // If ConOut, then set the mode to Mode #0 which us 80 x 25
2235 Private
->TextOut
.SetMode (&Private
->TextOut
, 0);
2242 ConSplitterTextOutDeleteDevice (
2243 IN TEXT_OUT_SPLITTER_PRIVATE_DATA
*Private
,
2244 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL
*TextOut
2248 Routine Description:
2259 UINTN CurrentNumOfConsoles
;
2260 TEXT_OUT_AND_GOP_DATA
*TextOutList
;
2264 // Remove the specified text-out device data structure from the Text out List,
2265 // and rearrange the remaining data structures in the Text out List.
2267 CurrentNumOfConsoles
= Private
->CurrentNumberOfConsoles
;
2268 Index
= (INT32
) CurrentNumOfConsoles
- 1;
2269 TextOutList
= Private
->TextOutList
;
2270 while (Index
>= 0) {
2271 if (TextOutList
->TextOut
== TextOut
) {
2272 CopyMem (TextOutList
, TextOutList
+ 1, sizeof (TEXT_OUT_AND_GOP_DATA
) * Index
);
2273 CurrentNumOfConsoles
--;
2281 // The specified TextOut is not managed by the ConSplitter driver
2284 return EFI_NOT_FOUND
;
2287 if (CurrentNumOfConsoles
== 0) {
2289 // If the number of consoles is zero clear the Dev NULL device
2291 Private
->CurrentNumberOfConsoles
= 0;
2292 Private
->TextOutMode
.MaxMode
= 1;
2293 Private
->TextOutQueryData
[0].Columns
= 80;
2294 Private
->TextOutQueryData
[0].Rows
= 25;
2295 DevNullTextOutSetMode (Private
, 0);
2300 // Max Mode is realy an intersection of the QueryMode command to all
2301 // devices. So we must copy the QueryMode of the first device to
2305 Private
->TextOutQueryData
,
2306 Private
->TextOutQueryDataCount
* sizeof (TEXT_OUT_SPLITTER_QUERY_DATA
)
2309 gBS
->FreePool (Private
->TextOutModeMap
);
2310 Private
->TextOutModeMap
= NULL
;
2311 TextOutList
= Private
->TextOutList
;
2314 // Add the first TextOut to the QueryData array and ModeMap table
2316 Status
= ConSplitterAddOutputMode (Private
, TextOutList
->TextOut
);
2319 // Now add one by one
2322 Private
->CurrentNumberOfConsoles
= 1;
2324 while ((UINTN
) Index
< CurrentNumOfConsoles
) {
2325 ConSplitterSyncOutputMode (Private
, TextOutList
->TextOut
);
2327 Private
->CurrentNumberOfConsoles
++;
2331 ConSplitterGetIntersectionBetweenConOutAndStrErr ();
2336 // ConSplitter TextIn member functions
2340 ConSplitterTextInReset (
2341 IN EFI_SIMPLE_TEXT_IN_PROTOCOL
*This
,
2342 IN BOOLEAN ExtendedVerification
2346 Routine Description:
2347 Reset the input device and optionaly run diagnostics
2350 This - Protocol instance pointer.
2351 ExtendedVerification - Driver may perform diagnostics on reset.
2354 EFI_SUCCESS - The device was reset.
2355 EFI_DEVICE_ERROR - The device is not functioning properly and could
2361 EFI_STATUS ReturnStatus
;
2362 TEXT_IN_SPLITTER_PRIVATE_DATA
*Private
;
2365 Private
= TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_THIS (This
);
2367 Private
->KeyEventSignalState
= FALSE
;
2370 // return the worst status met
2372 for (Index
= 0, ReturnStatus
= EFI_SUCCESS
; Index
< Private
->CurrentNumberOfConsoles
; Index
++) {
2373 Status
= Private
->TextInList
[Index
]->Reset (
2374 Private
->TextInList
[Index
],
2375 ExtendedVerification
2377 if (EFI_ERROR (Status
)) {
2378 ReturnStatus
= Status
;
2382 return ReturnStatus
;
2387 ConSplitterTextInPrivateReadKeyStroke (
2388 IN TEXT_IN_SPLITTER_PRIVATE_DATA
*Private
,
2389 OUT EFI_INPUT_KEY
*Key
2393 Routine Description:
2394 Reads the next keystroke from the input device. The WaitForKey Event can
2395 be used to test for existance of a keystroke via WaitForEvent () call.
2398 This - Protocol instance pointer.
2399 Key - Driver may perform diagnostics on reset.
2402 EFI_SUCCESS - The keystroke information was returned.
2403 EFI_NOT_READY - There was no keystroke data availiable.
2404 EFI_DEVICE_ERROR - The keydtroke information was not returned due to
2411 EFI_INPUT_KEY CurrentKey
;
2413 Key
->UnicodeChar
= 0;
2414 Key
->ScanCode
= SCAN_NULL
;
2417 // if no physical console input device exists, return EFI_NOT_READY;
2418 // if any physical console input device has key input,
2419 // return the key and EFI_SUCCESS.
2421 for (Index
= 0; Index
< Private
->CurrentNumberOfConsoles
; Index
++) {
2422 Status
= Private
->TextInList
[Index
]->ReadKeyStroke (
2423 Private
->TextInList
[Index
],
2426 if (!EFI_ERROR (Status
)) {
2432 return EFI_NOT_READY
;
2436 ConSpliterConssoleControlStdInLocked (
2441 Routine Description:
2442 Return TRUE if StdIn is locked. The ConIn device on the virtual handle is
2443 the only device locked.
2450 FALSE - StdIn working normally
2454 return mConIn
.PasswordEnabled
;
2459 ConSpliterConsoleControlLockStdInEvent (
2465 Routine Description:
2466 This timer event will fire when StdIn is locked. It will check the key
2467 sequence on StdIn to see if it matches the password. Any error in the
2468 password will cause the check to reset. As long a mConIn.PasswordEnabled is
2469 TRUE the StdIn splitter will not report any input.
2472 (Standard EFI_EVENT_NOTIFY)
2481 CHAR16 BackSpaceString
[2];
2482 CHAR16 SpaceString
[2];
2485 Status
= ConSplitterTextInPrivateReadKeyStroke (&mConIn
, &Key
);
2486 if (!EFI_ERROR (Status
)) {
2488 // if it's an ENTER, match password
2490 if ((Key
.UnicodeChar
== CHAR_CARRIAGE_RETURN
) && (Key
.ScanCode
== SCAN_NULL
)) {
2491 mConIn
.PwdAttempt
[mConIn
.PwdIndex
] = CHAR_NULL
;
2492 if (StrCmp (mConIn
.Password
, mConIn
.PwdAttempt
)) {
2494 // Password not match
2496 ConSplitterTextOutOutputString (&mConOut
.TextOut
, (CHAR16
*) L
"\n\rPassword not correct\n\r");
2497 mConIn
.PwdIndex
= 0;
2500 // Key matches password sequence
2502 gBS
->SetTimer (mConIn
.LockEvent
, TimerPeriodic
, 0);
2503 mConIn
.PasswordEnabled
= FALSE
;
2504 Status
= EFI_NOT_READY
;
2506 } else if ((Key
.UnicodeChar
== CHAR_BACKSPACE
) && (Key
.ScanCode
== SCAN_NULL
)) {
2510 if (mConIn
.PwdIndex
> 0) {
2511 BackSpaceString
[0] = CHAR_BACKSPACE
;
2512 BackSpaceString
[1] = 0;
2514 SpaceString
[0] = ' ';
2517 ConSplitterTextOutOutputString (&mConOut
.TextOut
, BackSpaceString
);
2518 ConSplitterTextOutOutputString (&mConOut
.TextOut
, SpaceString
);
2519 ConSplitterTextOutOutputString (&mConOut
.TextOut
, BackSpaceString
);
2523 } else if ((Key
.ScanCode
== SCAN_NULL
) && (Key
.UnicodeChar
>= 32)) {
2525 // If it's not an ENTER, neigher a function key, nor a CTRL-X or ALT-X, record the input
2527 if (mConIn
.PwdIndex
< (MAX_STD_IN_PASSWORD
- 1)) {
2528 if (mConIn
.PwdIndex
== 0) {
2529 ConSplitterTextOutOutputString (&mConOut
.TextOut
, (CHAR16
*) L
"\n\r");
2532 ConSplitterTextOutOutputString (&mConOut
.TextOut
, (CHAR16
*) L
"*");
2533 mConIn
.PwdAttempt
[mConIn
.PwdIndex
] = Key
.UnicodeChar
;
2538 } while (!EFI_ERROR (Status
));
2543 ConSpliterConsoleControlLockStdIn (
2544 IN EFI_CONSOLE_CONTROL_PROTOCOL
*This
,
2549 Routine Description:
2550 If Password is NULL unlock the password state variable and set the event
2551 timer. If the Password is too big return an error. If the Password is valid
2552 Copy the Password and enable state variable and then arm the periodic timer
2557 EFI_SUCCESS - Lock the StdIn device
2558 EFI_INVALID_PARAMETER - Password is NULL
2559 EFI_OUT_OF_RESOURCES - Buffer allocation to store the password fails
2563 if (Password
== NULL
) {
2564 return EFI_INVALID_PARAMETER
;
2567 if (StrLen (Password
) >= MAX_STD_IN_PASSWORD
) {
2569 // Currently have a max password size
2571 return EFI_OUT_OF_RESOURCES
;
2574 // Save the password, initialize state variables and arm event timer
2576 StrCpy (mConIn
.Password
, Password
);
2577 mConIn
.PasswordEnabled
= TRUE
;
2578 mConIn
.PwdIndex
= 0;
2579 gBS
->SetTimer (mConIn
.LockEvent
, TimerPeriodic
, (10000 * 25));
2586 ConSplitterTextInReadKeyStroke (
2587 IN EFI_SIMPLE_TEXT_IN_PROTOCOL
*This
,
2588 OUT EFI_INPUT_KEY
*Key
2592 Routine Description:
2593 Reads the next keystroke from the input device. The WaitForKey Event can
2594 be used to test for existance of a keystroke via WaitForEvent () call.
2595 If the ConIn is password locked make it look like no keystroke is availible
2598 This - Protocol instance pointer.
2599 Key - Driver may perform diagnostics on reset.
2602 EFI_SUCCESS - The keystroke information was returned.
2603 EFI_NOT_READY - There was no keystroke data availiable.
2604 EFI_DEVICE_ERROR - The keydtroke information was not returned due to
2609 TEXT_IN_SPLITTER_PRIVATE_DATA
*Private
;
2611 Private
= TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_THIS (This
);
2612 if (Private
->PasswordEnabled
) {
2614 // If StdIn Locked return not ready
2616 return EFI_NOT_READY
;
2619 Private
->KeyEventSignalState
= FALSE
;
2621 return ConSplitterTextInPrivateReadKeyStroke (Private
, Key
);
2626 ConSplitterTextInWaitForKey (
2632 Routine Description:
2633 This event agregates all the events of the ConIn devices in the spliter.
2634 If the ConIn is password locked then return.
2635 If any events of physical ConIn devices are signaled, signal the ConIn
2636 spliter event. This will cause the calling code to call
2637 ConSplitterTextInReadKeyStroke ().
2640 Event - The Event assoicated with callback.
2641 Context - Context registered when Event was created.
2649 TEXT_IN_SPLITTER_PRIVATE_DATA
*Private
;
2652 Private
= (TEXT_IN_SPLITTER_PRIVATE_DATA
*) Context
;
2653 if (Private
->PasswordEnabled
) {
2655 // If StdIn Locked return not ready
2661 // if KeyEventSignalState is flagged before, and not cleared by Reset() or ReadKeyStroke()
2663 if (Private
->KeyEventSignalState
) {
2664 gBS
->SignalEvent (Event
);
2668 // if any physical console input device has key input, signal the event.
2670 for (Index
= 0; Index
< Private
->CurrentNumberOfConsoles
; Index
++) {
2671 Status
= gBS
->CheckEvent (Private
->TextInList
[Index
]->WaitForKey
);
2672 if (!EFI_ERROR (Status
)) {
2673 gBS
->SignalEvent (Event
);
2674 Private
->KeyEventSignalState
= TRUE
;
2681 ConSplitterSimplePointerReset (
2682 IN EFI_SIMPLE_POINTER_PROTOCOL
*This
,
2683 IN BOOLEAN ExtendedVerification
2687 Routine Description:
2688 Reset the input device and optionaly run diagnostics
2691 This - Protocol instance pointer.
2692 ExtendedVerification - Driver may perform diagnostics on reset.
2695 EFI_SUCCESS - The device was reset.
2696 EFI_DEVICE_ERROR - The device is not functioning properly and could
2702 EFI_STATUS ReturnStatus
;
2703 TEXT_IN_SPLITTER_PRIVATE_DATA
*Private
;
2706 Private
= TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_SIMPLE_POINTER_THIS (This
);
2708 Private
->InputEventSignalState
= FALSE
;
2710 if (Private
->CurrentNumberOfPointers
== 0) {
2714 // return the worst status met
2716 for (Index
= 0, ReturnStatus
= EFI_SUCCESS
; Index
< Private
->CurrentNumberOfPointers
; Index
++) {
2717 Status
= Private
->PointerList
[Index
]->Reset (
2718 Private
->PointerList
[Index
],
2719 ExtendedVerification
2721 if (EFI_ERROR (Status
)) {
2722 ReturnStatus
= Status
;
2726 return ReturnStatus
;
2731 ConSplitterSimplePointerPrivateGetState (
2732 IN TEXT_IN_SPLITTER_PRIVATE_DATA
*Private
,
2733 IN OUT EFI_SIMPLE_POINTER_STATE
*State
2737 Routine Description:
2738 Reads the next keystroke from the input device. The WaitForKey Event can
2739 be used to test for existance of a keystroke via WaitForEvent () call.
2742 This - Protocol instance pointer.
2746 EFI_SUCCESS - The keystroke information was returned.
2747 EFI_NOT_READY - There was no keystroke data availiable.
2748 EFI_DEVICE_ERROR - The keydtroke information was not returned due to
2754 EFI_STATUS ReturnStatus
;
2756 EFI_SIMPLE_POINTER_STATE CurrentState
;
2758 State
->RelativeMovementX
= 0;
2759 State
->RelativeMovementY
= 0;
2760 State
->RelativeMovementZ
= 0;
2761 State
->LeftButton
= FALSE
;
2762 State
->RightButton
= FALSE
;
2765 // if no physical console input device exists, return EFI_NOT_READY;
2766 // if any physical console input device has key input,
2767 // return the key and EFI_SUCCESS.
2769 ReturnStatus
= EFI_NOT_READY
;
2770 for (Index
= 0; Index
< Private
->CurrentNumberOfPointers
; Index
++) {
2772 Status
= Private
->PointerList
[Index
]->GetState (
2773 Private
->PointerList
[Index
],
2776 if (!EFI_ERROR (Status
)) {
2777 if (ReturnStatus
== EFI_NOT_READY
) {
2778 ReturnStatus
= EFI_SUCCESS
;
2781 if (CurrentState
.LeftButton
) {
2782 State
->LeftButton
= TRUE
;
2785 if (CurrentState
.RightButton
) {
2786 State
->RightButton
= TRUE
;
2789 if (CurrentState
.RelativeMovementX
!= 0 && Private
->PointerList
[Index
]->Mode
->ResolutionX
!= 0) {
2790 State
->RelativeMovementX
+= (CurrentState
.RelativeMovementX
* (INT32
) Private
->SimplePointerMode
.ResolutionX
) / (INT32
) Private
->PointerList
[Index
]->Mode
->ResolutionX
;
2793 if (CurrentState
.RelativeMovementY
!= 0 && Private
->PointerList
[Index
]->Mode
->ResolutionY
!= 0) {
2794 State
->RelativeMovementY
+= (CurrentState
.RelativeMovementY
* (INT32
) Private
->SimplePointerMode
.ResolutionY
) / (INT32
) Private
->PointerList
[Index
]->Mode
->ResolutionY
;
2797 if (CurrentState
.RelativeMovementZ
!= 0 && Private
->PointerList
[Index
]->Mode
->ResolutionZ
!= 0) {
2798 State
->RelativeMovementZ
+= (CurrentState
.RelativeMovementZ
* (INT32
) Private
->SimplePointerMode
.ResolutionZ
) / (INT32
) Private
->PointerList
[Index
]->Mode
->ResolutionZ
;
2800 } else if (Status
== EFI_DEVICE_ERROR
) {
2801 ReturnStatus
= EFI_DEVICE_ERROR
;
2805 return ReturnStatus
;
2810 ConSplitterSimplePointerGetState (
2811 IN EFI_SIMPLE_POINTER_PROTOCOL
*This
,
2812 IN OUT EFI_SIMPLE_POINTER_STATE
*State
2816 Routine Description:
2817 Reads the next keystroke from the input device. The WaitForKey Event can
2818 be used to test for existance of a keystroke via WaitForEvent () call.
2819 If the ConIn is password locked make it look like no keystroke is availible
2822 This - Protocol instance pointer.
2826 EFI_SUCCESS - The keystroke information was returned.
2827 EFI_NOT_READY - There was no keystroke data availiable.
2828 EFI_DEVICE_ERROR - The keydtroke information was not returned due to
2833 TEXT_IN_SPLITTER_PRIVATE_DATA
*Private
;
2835 Private
= TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_SIMPLE_POINTER_THIS (This
);
2836 if (Private
->PasswordEnabled
) {
2838 // If StdIn Locked return not ready
2840 return EFI_NOT_READY
;
2843 Private
->InputEventSignalState
= FALSE
;
2845 return ConSplitterSimplePointerPrivateGetState (Private
, State
);
2850 ConSplitterSimplePointerWaitForInput (
2856 Routine Description:
2857 This event agregates all the events of the ConIn devices in the spliter.
2858 If the ConIn is password locked then return.
2859 If any events of physical ConIn devices are signaled, signal the ConIn
2860 spliter event. This will cause the calling code to call
2861 ConSplitterTextInReadKeyStroke ().
2864 Event - The Event assoicated with callback.
2865 Context - Context registered when Event was created.
2873 TEXT_IN_SPLITTER_PRIVATE_DATA
*Private
;
2876 Private
= (TEXT_IN_SPLITTER_PRIVATE_DATA
*) Context
;
2877 if (Private
->PasswordEnabled
) {
2879 // If StdIn Locked return not ready
2885 // if InputEventSignalState is flagged before, and not cleared by Reset() or ReadKeyStroke()
2887 if (Private
->InputEventSignalState
) {
2888 gBS
->SignalEvent (Event
);
2892 // if any physical console input device has key input, signal the event.
2894 for (Index
= 0; Index
< Private
->CurrentNumberOfPointers
; Index
++) {
2895 Status
= gBS
->CheckEvent (Private
->PointerList
[Index
]->WaitForInput
);
2896 if (!EFI_ERROR (Status
)) {
2897 gBS
->SignalEvent (Event
);
2898 Private
->InputEventSignalState
= TRUE
;
2905 ConSplitterTextOutReset (
2906 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL
*This
,
2907 IN BOOLEAN ExtendedVerification
2911 Routine Description:
2912 Reset the text output device hardware and optionaly run diagnostics
2915 This - Protocol instance pointer.
2916 ExtendedVerification - Driver may perform more exhaustive verfication
2917 operation of the device during reset.
2920 EFI_SUCCESS - The text output device was reset.
2921 EFI_DEVICE_ERROR - The text output device is not functioning correctly and
2927 TEXT_OUT_SPLITTER_PRIVATE_DATA
*Private
;
2929 EFI_STATUS ReturnStatus
;
2931 Private
= TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This
);
2934 // return the worst status met
2936 for (Index
= 0, ReturnStatus
= EFI_SUCCESS
; Index
< Private
->CurrentNumberOfConsoles
; Index
++) {
2938 if (Private
->TextOutList
[Index
].TextOutEnabled
) {
2940 Status
= Private
->TextOutList
[Index
].TextOut
->Reset (
2941 Private
->TextOutList
[Index
].TextOut
,
2942 ExtendedVerification
2944 if (EFI_ERROR (Status
)) {
2945 ReturnStatus
= Status
;
2950 This
->SetAttribute (This
, EFI_TEXT_ATTR (This
->Mode
->Attribute
& 0x0F, EFI_BACKGROUND_BLACK
));
2952 Status
= DevNullTextOutSetMode (Private
, 0);
2953 if (EFI_ERROR (Status
)) {
2954 ReturnStatus
= Status
;
2957 return ReturnStatus
;
2962 ConSplitterTextOutOutputString (
2963 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL
*This
,
2968 Routine Description:
2969 Write a Unicode string to the output device.
2972 This - Protocol instance pointer.
2973 String - The NULL-terminated Unicode string to be displayed on the output
2974 device(s). All output devices must also support the Unicode
2975 drawing defined in this file.
2978 EFI_SUCCESS - The string was output to the device.
2979 EFI_DEVICE_ERROR - The device reported an error while attempting to output
2981 EFI_UNSUPPORTED - The output device's mode is not currently in a
2983 EFI_WARN_UNKNOWN_GLYPH - This warning code indicates that some of the
2984 characters in the Unicode string could not be
2985 rendered and were skipped.
2990 TEXT_OUT_SPLITTER_PRIVATE_DATA
*Private
;
2992 UINTN BackSpaceCount
;
2993 EFI_STATUS ReturnStatus
;
2994 CHAR16
*TargetString
;
2996 This
->SetAttribute (This
, This
->Mode
->Attribute
);
2998 Private
= TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This
);
3001 for (TargetString
= WString
; *TargetString
; TargetString
++) {
3002 if (*TargetString
== CHAR_BACKSPACE
) {
3008 if (BackSpaceCount
== 0) {
3009 TargetString
= WString
;
3011 TargetString
= AllocatePool (sizeof (CHAR16
) * (StrLen (WString
) + BackSpaceCount
+ 1));
3012 StrCpy (TargetString
, WString
);
3015 // return the worst status met
3017 Status
= DevNullTextOutOutputString (Private
, TargetString
);
3018 if (EFI_ERROR (Status
)) {
3019 ReturnStatus
= Status
;
3022 for (Index
= 0, ReturnStatus
= EFI_SUCCESS
; Index
< Private
->CurrentNumberOfConsoles
; Index
++) {
3024 if (Private
->TextOutList
[Index
].TextOutEnabled
) {
3025 Status
= Private
->TextOutList
[Index
].TextOut
->OutputString (
3026 Private
->TextOutList
[Index
].TextOut
,
3029 if (EFI_ERROR (Status
)) {
3030 ReturnStatus
= Status
;
3035 if (BackSpaceCount
) {
3036 gBS
->FreePool (TargetString
);
3039 return ReturnStatus
;
3044 ConSplitterTextOutTestString (
3045 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL
*This
,
3050 Routine Description:
3051 Verifies that all characters in a Unicode string can be output to the
3055 This - Protocol instance pointer.
3056 String - The NULL-terminated Unicode string to be examined for the output
3060 EFI_SUCCESS - The device(s) are capable of rendering the output string.
3061 EFI_UNSUPPORTED - Some of the characters in the Unicode string cannot be
3062 rendered by one or more of the output devices mapped
3068 TEXT_OUT_SPLITTER_PRIVATE_DATA
*Private
;
3070 EFI_STATUS ReturnStatus
;
3072 Private
= TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This
);
3075 // return the worst status met
3077 for (Index
= 0, ReturnStatus
= EFI_SUCCESS
; Index
< Private
->CurrentNumberOfConsoles
; Index
++) {
3078 if (Private
->TextOutList
[Index
].TextOutEnabled
) {
3079 Status
= Private
->TextOutList
[Index
].TextOut
->TestString (
3080 Private
->TextOutList
[Index
].TextOut
,
3083 if (EFI_ERROR (Status
)) {
3084 ReturnStatus
= Status
;
3089 // There is no DevNullTextOutTestString () since a Unicode buffer would
3090 // always return EFI_SUCCESS.
3091 // ReturnStatus will be EFI_SUCCESS if no consoles are present
3093 return ReturnStatus
;
3098 ConSplitterTextOutQueryMode (
3099 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL
*This
,
3100 IN UINTN ModeNumber
,
3106 Routine Description:
3107 Returns information for an available text mode that the output device(s)
3111 This - Protocol instance pointer.
3112 ModeNumber - The mode number to return information on.
3113 Columns, Rows - Returns the geometry of the text output device for the
3114 requested ModeNumber.
3117 EFI_SUCCESS - The requested mode information was returned.
3118 EFI_DEVICE_ERROR - The device had an error and could not
3119 complete the request.
3120 EFI_UNSUPPORTED - The mode number was not valid.
3124 TEXT_OUT_SPLITTER_PRIVATE_DATA
*Private
;
3126 Private
= TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This
);
3129 // Check whether param ModeNumber is valid.
3130 // ModeNumber should be within range 0 ~ MaxMode - 1.
3132 if ( (ModeNumber
> (UINTN
)(((UINT32
)-1)>>1)) ) {
3133 return EFI_UNSUPPORTED
;
3136 if ((INT32
) ModeNumber
>= This
->Mode
->MaxMode
) {
3137 return EFI_UNSUPPORTED
;
3140 *Columns
= Private
->TextOutQueryData
[ModeNumber
].Columns
;
3141 *Rows
= Private
->TextOutQueryData
[ModeNumber
].Rows
;
3143 if (*Columns
<= 0 && *Rows
<= 0) {
3144 return EFI_UNSUPPORTED
;
3153 ConSplitterTextOutSetMode (
3154 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL
*This
,
3159 Routine Description:
3160 Sets the output device(s) to a specified mode.
3163 This - Protocol instance pointer.
3164 ModeNumber - The mode number to set.
3167 EFI_SUCCESS - The requested text mode was set.
3168 EFI_DEVICE_ERROR - The device had an error and
3169 could not complete the request.
3170 EFI_UNSUPPORTED - The mode number was not valid.
3175 TEXT_OUT_SPLITTER_PRIVATE_DATA
*Private
;
3177 INT32
*TextOutModeMap
;
3178 EFI_STATUS ReturnStatus
;
3180 Private
= TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This
);
3183 // Check whether param ModeNumber is valid.
3184 // ModeNumber should be within range 0 ~ MaxMode - 1.
3186 if ( (ModeNumber
> (UINTN
)(((UINT32
)-1)>>1)) ) {
3187 return EFI_UNSUPPORTED
;
3190 if ((INT32
) ModeNumber
>= This
->Mode
->MaxMode
) {
3191 return EFI_UNSUPPORTED
;
3194 // If the mode is being set to the curent mode, then just clear the screen and return.
3196 if (Private
->TextOutMode
.Mode
== (INT32
) ModeNumber
) {
3197 return ConSplitterTextOutClearScreen (This
);
3200 // return the worst status met
3202 TextOutModeMap
= Private
->TextOutModeMap
+ Private
->TextOutListCount
* ModeNumber
;
3203 for (Index
= 0, ReturnStatus
= EFI_SUCCESS
; Index
< Private
->CurrentNumberOfConsoles
; Index
++) {
3205 if (Private
->TextOutList
[Index
].TextOutEnabled
) {
3206 Status
= Private
->TextOutList
[Index
].TextOut
->SetMode (
3207 Private
->TextOutList
[Index
].TextOut
,
3208 TextOutModeMap
[Index
]
3211 // If this console device is based on a UGA device, then sync up the bitmap from
3212 // the UGA splitter and reclear the text portion of the display in the new mode.
3214 if ((Private
->TextOutList
[Index
].GraphicsOutput
!= NULL
) || (Private
->TextOutList
[Index
].UgaDraw
!= NULL
)) {
3215 Private
->TextOutList
[Index
].TextOut
->ClearScreen (Private
->TextOutList
[Index
].TextOut
);
3218 if (EFI_ERROR (Status
)) {
3219 ReturnStatus
= Status
;
3224 // The DevNull Console will support any possible mode as it allocates memory
3226 Status
= DevNullTextOutSetMode (Private
, ModeNumber
);
3227 if (EFI_ERROR (Status
)) {
3228 ReturnStatus
= Status
;
3231 return ReturnStatus
;
3236 ConSplitterTextOutSetAttribute (
3237 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL
*This
,
3242 Routine Description:
3243 Sets the background and foreground colors for the OutputString () and
3244 ClearScreen () functions.
3247 This - Protocol instance pointer.
3248 Attribute - The attribute to set. Bits 0..3 are the foreground color, and
3249 bits 4..6 are the background color. All other bits are undefined
3250 and must be zero. The valid Attributes are defined in this file.
3253 EFI_SUCCESS - The attribute was set.
3254 EFI_DEVICE_ERROR - The device had an error and
3255 could not complete the request.
3256 EFI_UNSUPPORTED - The attribute requested is not defined.
3261 TEXT_OUT_SPLITTER_PRIVATE_DATA
*Private
;
3263 EFI_STATUS ReturnStatus
;
3265 Private
= TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This
);
3268 // Check whether param Attribute is valid.
3270 if ( (Attribute
> (UINTN
)(((UINT32
)-1)>>1)) ) {
3271 return EFI_UNSUPPORTED
;
3275 // return the worst status met
3277 for (Index
= 0, ReturnStatus
= EFI_SUCCESS
; Index
< Private
->CurrentNumberOfConsoles
; Index
++) {
3279 if (Private
->TextOutList
[Index
].TextOutEnabled
) {
3280 Status
= Private
->TextOutList
[Index
].TextOut
->SetAttribute (
3281 Private
->TextOutList
[Index
].TextOut
,
3284 if (EFI_ERROR (Status
)) {
3285 ReturnStatus
= Status
;
3290 Private
->TextOutMode
.Attribute
= (INT32
) Attribute
;
3292 return ReturnStatus
;
3297 ConSplitterTextOutClearScreen (
3298 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL
*This
3302 Routine Description:
3303 Clears the output device(s) display to the currently selected background
3307 This - Protocol instance pointer.
3310 EFI_SUCCESS - The operation completed successfully.
3311 EFI_DEVICE_ERROR - The device had an error and
3312 could not complete the request.
3313 EFI_UNSUPPORTED - The output device is not in a valid text mode.
3318 TEXT_OUT_SPLITTER_PRIVATE_DATA
*Private
;
3320 EFI_STATUS ReturnStatus
;
3322 Private
= TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This
);
3325 // return the worst status met
3327 for (Index
= 0, ReturnStatus
= EFI_SUCCESS
; Index
< Private
->CurrentNumberOfConsoles
; Index
++) {
3329 if (Private
->TextOutList
[Index
].TextOutEnabled
) {
3330 Status
= Private
->TextOutList
[Index
].TextOut
->ClearScreen (Private
->TextOutList
[Index
].TextOut
);
3331 if (EFI_ERROR (Status
)) {
3332 ReturnStatus
= Status
;
3337 Status
= DevNullTextOutClearScreen (Private
);
3338 if (EFI_ERROR (Status
)) {
3339 ReturnStatus
= Status
;
3342 return ReturnStatus
;
3347 ConSplitterTextOutSetCursorPosition (
3348 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL
*This
,
3354 Routine Description:
3355 Sets the current coordinates of the cursor position
3358 This - Protocol instance pointer.
3359 Column, Row - the position to set the cursor to. Must be greater than or
3360 equal to zero and less than the number of columns and rows
3364 EFI_SUCCESS - The operation completed successfully.
3365 EFI_DEVICE_ERROR - The device had an error and
3366 could not complete the request.
3367 EFI_UNSUPPORTED - The output device is not in a valid text mode, or the
3368 cursor position is invalid for the current mode.
3373 TEXT_OUT_SPLITTER_PRIVATE_DATA
*Private
;
3375 EFI_STATUS ReturnStatus
;
3379 Private
= TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This
);
3381 MaxColumn
= Private
->TextOutQueryData
[Private
->TextOutMode
.Mode
].Columns
;
3382 MaxRow
= Private
->TextOutQueryData
[Private
->TextOutMode
.Mode
].Rows
;
3384 if (Column
>= MaxColumn
|| Row
>= MaxRow
) {
3385 return EFI_UNSUPPORTED
;
3388 // return the worst status met
3390 for (Index
= 0, ReturnStatus
= EFI_SUCCESS
; Index
< Private
->CurrentNumberOfConsoles
; Index
++) {
3392 if (Private
->TextOutList
[Index
].TextOutEnabled
) {
3393 Status
= Private
->TextOutList
[Index
].TextOut
->SetCursorPosition (
3394 Private
->TextOutList
[Index
].TextOut
,
3398 if (EFI_ERROR (Status
)) {
3399 ReturnStatus
= Status
;
3404 DevNullTextOutSetCursorPosition (Private
, Column
, Row
);
3406 return ReturnStatus
;
3411 ConSplitterTextOutEnableCursor (
3412 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL
*This
,
3417 Routine Description:
3418 Makes the cursor visible or invisible
3421 This - Protocol instance pointer.
3422 Visible - If TRUE, the cursor is set to be visible. If FALSE, the cursor is
3423 set to be invisible.
3426 EFI_SUCCESS - The operation completed successfully.
3427 EFI_DEVICE_ERROR - The device had an error and could not complete the
3428 request, or the device does not support changing
3430 EFI_UNSUPPORTED - The output device is not in a valid text mode.
3435 TEXT_OUT_SPLITTER_PRIVATE_DATA
*Private
;
3437 EFI_STATUS ReturnStatus
;
3439 Private
= TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This
);
3442 // return the worst status met
3444 for (Index
= 0, ReturnStatus
= EFI_SUCCESS
; Index
< Private
->CurrentNumberOfConsoles
; Index
++) {
3446 if (Private
->TextOutList
[Index
].TextOutEnabled
) {
3447 Status
= Private
->TextOutList
[Index
].TextOut
->EnableCursor (
3448 Private
->TextOutList
[Index
].TextOut
,
3451 if (EFI_ERROR (Status
)) {
3452 ReturnStatus
= Status
;
3457 DevNullTextOutEnableCursor (Private
, Visible
);
3459 return ReturnStatus
;