1. updated return value to EFI_SUCCESS by default.
[edk2.git] / MdeModulePkg / Universal / Console / ConSplitterDxe / ConSplitter.c
blob9b0fe2fed4ce2c42e177b32911f60f926a6d58a4
1 /** @file
2 Console Splitter Driver. Any Handle that attatched console I/O protocols
3 (Console In device, Console Out device, Console Error device, Simple Pointer
4 protocol, Absolute Pointer protocol) can be bound by this driver.
6 So far it works like any other driver by opening a SimpleTextIn and/or
7 SimpleTextOut protocol with EFI_OPEN_PROTOCOL_BY_DRIVER attributes. The big
8 difference is this driver does not layer a protocol on the passed in
9 handle, or construct a child handle like a standard device or bus driver.
10 This driver produces three virtual handles as children, one for console input
11 splitter, one for console output splitter and one for error output splitter.
12 These 3 virtual handles would be installed on gST.
14 Each virtual handle, that supports the Console I/O protocol, will be produced
15 in the driver entry point. The virtual handle are added on driver entry and
16 never removed. Such design ensures sytem function well during none console
17 device situation.
19 Copyright (c) 2006 - 2009, 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.
28 **/
30 #include "ConSplitter.h"
33 // Text In Splitter Private Data template
35 GLOBAL_REMOVE_IF_UNREFERENCED TEXT_IN_SPLITTER_PRIVATE_DATA mConIn = {
36 TEXT_IN_SPLITTER_PRIVATE_DATA_SIGNATURE,
37 (EFI_HANDLE) NULL,
40 ConSplitterTextInReset,
41 ConSplitterTextInReadKeyStroke,
42 (EFI_EVENT) NULL
45 (EFI_SIMPLE_TEXT_INPUT_PROTOCOL **) NULL,
49 ConSplitterTextInResetEx,
50 ConSplitterTextInReadKeyStrokeEx,
51 (EFI_EVENT) NULL,
52 ConSplitterTextInSetState,
53 ConSplitterTextInRegisterKeyNotify,
54 ConSplitterTextInUnregisterKeyNotify
57 (EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL **) NULL,
60 (LIST_ENTRY *) NULL,
61 (LIST_ENTRY *) NULL
65 ConSplitterSimplePointerReset,
66 ConSplitterSimplePointerGetState,
67 (EFI_EVENT) NULL,
68 (EFI_SIMPLE_POINTER_MODE *) NULL
71 0x10000,
72 0x10000,
73 0x10000,
74 TRUE,
75 TRUE
78 (EFI_SIMPLE_POINTER_PROTOCOL **) NULL,
82 ConSplitterAbsolutePointerReset,
83 ConSplitterAbsolutePointerGetState,
84 (EFI_EVENT) NULL,
85 (EFI_ABSOLUTE_POINTER_MODE *) NULL
88 0, // AbsoluteMinX
89 0, // AbsoluteMinY
90 0, // AbsoluteMinZ
91 0x10000, // AbsoluteMaxX
92 0x10000, // AbsoluteMaxY
93 0x10000, // AbsoluteMaxZ
94 0 // Attributes
97 (EFI_ABSOLUTE_POINTER_PROTOCOL **) NULL,
99 FALSE,
101 FALSE,
102 FALSE
107 // Uga Draw Protocol Private Data template
109 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UGA_DRAW_PROTOCOL mUgaDrawProtocolTemplate = {
110 ConSpliterUgaDrawGetMode,
111 ConSpliterUgaDrawSetMode,
112 ConSpliterUgaDrawBlt
116 // Graphics Output Protocol Private Data template
118 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GRAPHICS_OUTPUT_PROTOCOL mGraphicsOutputProtocolTemplate = {
119 ConSpliterGraphicsOutputQueryMode,
120 ConSpliterGraphicsOutputSetMode,
121 ConSpliterGraphicsOutputBlt,
122 NULL
127 // Text Out Splitter Private Data template
129 GLOBAL_REMOVE_IF_UNREFERENCED TEXT_OUT_SPLITTER_PRIVATE_DATA mConOut = {
130 TEXT_OUT_SPLITTER_PRIVATE_DATA_SIGNATURE,
131 (EFI_HANDLE) NULL,
133 ConSplitterTextOutReset,
134 ConSplitterTextOutOutputString,
135 ConSplitterTextOutTestString,
136 ConSplitterTextOutQueryMode,
137 ConSplitterTextOutSetMode,
138 ConSplitterTextOutSetAttribute,
139 ConSplitterTextOutClearScreen,
140 ConSplitterTextOutSetCursorPosition,
141 ConSplitterTextOutEnableCursor,
142 (EFI_SIMPLE_TEXT_OUTPUT_MODE *) NULL
150 FALSE,
154 NULL,
155 NULL,
156 NULL
164 NULL,
165 NULL,
166 NULL,
167 NULL
169 (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *) NULL,
172 TRUE,
175 (TEXT_OUT_AND_GOP_DATA *) NULL,
177 (TEXT_OUT_SPLITTER_QUERY_DATA *) NULL,
179 (INT32 *) NULL
183 // Standard Error Text Out Splitter Data Template
185 GLOBAL_REMOVE_IF_UNREFERENCED TEXT_OUT_SPLITTER_PRIVATE_DATA mStdErr = {
186 TEXT_OUT_SPLITTER_PRIVATE_DATA_SIGNATURE,
187 (EFI_HANDLE) NULL,
189 ConSplitterTextOutReset,
190 ConSplitterTextOutOutputString,
191 ConSplitterTextOutTestString,
192 ConSplitterTextOutQueryMode,
193 ConSplitterTextOutSetMode,
194 ConSplitterTextOutSetAttribute,
195 ConSplitterTextOutClearScreen,
196 ConSplitterTextOutSetCursorPosition,
197 ConSplitterTextOutEnableCursor,
198 (EFI_SIMPLE_TEXT_OUTPUT_MODE *) NULL
206 FALSE,
210 NULL,
211 NULL,
212 NULL
220 NULL,
221 NULL,
222 NULL,
223 NULL
225 (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *) NULL,
228 TRUE,
231 (TEXT_OUT_AND_GOP_DATA *) NULL,
233 (TEXT_OUT_SPLITTER_QUERY_DATA *) NULL,
235 (INT32 *) NULL
239 // Driver binding instance for Console Input Device
241 EFI_DRIVER_BINDING_PROTOCOL gConSplitterConInDriverBinding = {
242 ConSplitterConInDriverBindingSupported,
243 ConSplitterConInDriverBindingStart,
244 ConSplitterConInDriverBindingStop,
245 0xa,
246 NULL,
247 NULL
251 // Driver binding instance for Console Out device
253 EFI_DRIVER_BINDING_PROTOCOL gConSplitterConOutDriverBinding = {
254 ConSplitterConOutDriverBindingSupported,
255 ConSplitterConOutDriverBindingStart,
256 ConSplitterConOutDriverBindingStop,
257 0xa,
258 NULL,
259 NULL
263 // Driver binding instance for Standard Error device
265 EFI_DRIVER_BINDING_PROTOCOL gConSplitterStdErrDriverBinding = {
266 ConSplitterStdErrDriverBindingSupported,
267 ConSplitterStdErrDriverBindingStart,
268 ConSplitterStdErrDriverBindingStop,
269 0xa,
270 NULL,
271 NULL
275 // Driver binding instance for Simple Pointer protocol
277 EFI_DRIVER_BINDING_PROTOCOL gConSplitterSimplePointerDriverBinding = {
278 ConSplitterSimplePointerDriverBindingSupported,
279 ConSplitterSimplePointerDriverBindingStart,
280 ConSplitterSimplePointerDriverBindingStop,
281 0xa,
282 NULL,
283 NULL
287 // Driver binding instance for Absolute Pointer protocol
289 EFI_DRIVER_BINDING_PROTOCOL gConSplitterAbsolutePointerDriverBinding = {
290 ConSplitterAbsolutePointerDriverBindingSupported,
291 ConSplitterAbsolutePointerDriverBindingStart,
292 ConSplitterAbsolutePointerDriverBindingStop,
293 0xa,
294 NULL,
295 NULL
299 The Entry Point for module ConSplitter. The user code starts with this function.
301 Installs driver module protocols and. Creates virtual device handles for ConIn,
302 ConOut, and StdErr. Installs Simple Text In protocol, Simple Text In Ex protocol,
303 Simple Pointer protocol, Absolute Pointer protocol on those virtual handlers.
304 Installs Graphics Output protocol and/or UGA Draw protocol if needed.
306 @param[in] ImageHandle The firmware allocated handle for the EFI image.
307 @param[in] SystemTable A pointer to the EFI System Table.
309 @retval EFI_SUCCESS The entry point is executed successfully.
310 @retval other Some error occurs when executing this entry point.
313 EFI_STATUS
314 EFIAPI
315 ConSplitterDriverEntry(
316 IN EFI_HANDLE ImageHandle,
317 IN EFI_SYSTEM_TABLE *SystemTable
320 EFI_STATUS Status;
323 // Install driver model protocol(s).
325 Status = EfiLibInstallDriverBindingComponentName2 (
326 ImageHandle,
327 SystemTable,
328 &gConSplitterConInDriverBinding,
329 ImageHandle,
330 &gConSplitterConInComponentName,
331 &gConSplitterConInComponentName2
333 ASSERT_EFI_ERROR (Status);
335 Status = EfiLibInstallDriverBindingComponentName2 (
336 ImageHandle,
337 SystemTable,
338 &gConSplitterSimplePointerDriverBinding,
339 NULL,
340 &gConSplitterSimplePointerComponentName,
341 &gConSplitterSimplePointerComponentName2
343 ASSERT_EFI_ERROR (Status);
345 Status = EfiLibInstallDriverBindingComponentName2 (
346 ImageHandle,
347 SystemTable,
348 &gConSplitterAbsolutePointerDriverBinding,
349 NULL,
350 &gConSplitterAbsolutePointerComponentName,
351 &gConSplitterAbsolutePointerComponentName2
353 ASSERT_EFI_ERROR (Status);
355 Status = EfiLibInstallDriverBindingComponentName2 (
356 ImageHandle,
357 SystemTable,
358 &gConSplitterConOutDriverBinding,
359 NULL,
360 &gConSplitterConOutComponentName,
361 &gConSplitterConOutComponentName2
363 ASSERT_EFI_ERROR (Status);
365 Status = EfiLibInstallDriverBindingComponentName2 (
366 ImageHandle,
367 SystemTable,
368 &gConSplitterStdErrDriverBinding,
369 NULL,
370 &gConSplitterStdErrComponentName,
371 &gConSplitterStdErrComponentName2
373 ASSERT_EFI_ERROR (Status);
376 // Either Graphics Output protocol or UGA Draw protocol must be supported.
378 ASSERT (FeaturePcdGet (PcdConOutGopSupport) ||
379 FeaturePcdGet (PcdConOutUgaSupport));
382 // The driver creates virtual handles for ConIn, ConOut, and StdErr.
383 // The virtual handles will always exist even if no console exist in the
384 // system. This is need to support hotplug devices like USB.
387 // Create virtual device handle for StdErr Splitter
389 Status = ConSplitterTextOutConstructor (&mStdErr);
390 if (!EFI_ERROR (Status)) {
391 Status = gBS->InstallMultipleProtocolInterfaces (
392 &mStdErr.VirtualHandle,
393 &gEfiSimpleTextOutProtocolGuid,
394 &mStdErr.TextOut,
395 NULL
399 // Create virtual device handle for ConIn Splitter
401 Status = ConSplitterTextInConstructor (&mConIn);
402 if (!EFI_ERROR (Status)) {
403 Status = gBS->InstallMultipleProtocolInterfaces (
404 &mConIn.VirtualHandle,
405 &gEfiSimpleTextInProtocolGuid,
406 &mConIn.TextIn,
407 &gEfiSimpleTextInputExProtocolGuid,
408 &mConIn.TextInEx,
409 &gEfiSimplePointerProtocolGuid,
410 &mConIn.SimplePointer,
411 &gEfiAbsolutePointerProtocolGuid,
412 &mConIn.AbsolutePointer,
413 NULL
415 if (!EFI_ERROR (Status)) {
417 // Update the EFI System Table with new virtual console
418 // and update the pointer to Simple Text Input protocol.
420 gST->ConsoleInHandle = mConIn.VirtualHandle;
421 gST->ConIn = &mConIn.TextIn;
425 // Create virtual device handle for ConOut Splitter
427 Status = ConSplitterTextOutConstructor (&mConOut);
428 if (!EFI_ERROR (Status)) {
429 if (!FeaturePcdGet (PcdConOutGopSupport)) {
431 // If Graphics Outpurt protocol not supported, UGA Draw protocol is installed
432 // on the virtual handle.
434 Status = gBS->InstallMultipleProtocolInterfaces (
435 &mConOut.VirtualHandle,
436 &gEfiSimpleTextOutProtocolGuid,
437 &mConOut.TextOut,
438 &gEfiUgaDrawProtocolGuid,
439 &mConOut.UgaDraw,
440 NULL
442 } else if (!FeaturePcdGet (PcdConOutUgaSupport)) {
444 // If UGA Draw protocol not supported, Graphics Output Protocol is installed
445 // on virtual handle.
447 Status = gBS->InstallMultipleProtocolInterfaces (
448 &mConOut.VirtualHandle,
449 &gEfiSimpleTextOutProtocolGuid,
450 &mConOut.TextOut,
451 &gEfiGraphicsOutputProtocolGuid,
452 &mConOut.GraphicsOutput,
453 NULL
455 } else {
457 // Boot Graphics Output protocol and UGA Draw protocol are supported,
458 // both they will be installed on virtual handle.
460 Status = gBS->InstallMultipleProtocolInterfaces (
461 &mConOut.VirtualHandle,
462 &gEfiSimpleTextOutProtocolGuid,
463 &mConOut.TextOut,
464 &gEfiGraphicsOutputProtocolGuid,
465 &mConOut.GraphicsOutput,
466 &gEfiUgaDrawProtocolGuid,
467 &mConOut.UgaDraw,
468 NULL
472 if (!EFI_ERROR (Status)) {
474 // Update the EFI System Table with new virtual console
475 // and Update the pointer to Text Output protocol.
477 gST->ConsoleOutHandle = mConOut.VirtualHandle;
478 gST->ConOut = &mConOut.TextOut;
483 // Update the CRC32 in the EFI System Table header
485 gST->Hdr.CRC32 = 0;
486 gBS->CalculateCrc32 (
487 (UINT8 *) &gST->Hdr,
488 gST->Hdr.HeaderSize,
489 &gST->Hdr.CRC32
492 return EFI_SUCCESS;
497 Construct console input devices' private data.
499 @param ConInPrivate A pointer to the TEXT_IN_SPLITTER_PRIVATE_DATA
500 structure.
502 @retval EFI_OUT_OF_RESOURCES Out of resources.
503 @retval EFI_SUCCESS Text Input Devcie's private data has been constructed.
504 @retval other Failed to construct private data.
507 EFI_STATUS
508 ConSplitterTextInConstructor (
509 TEXT_IN_SPLITTER_PRIVATE_DATA *ConInPrivate
512 EFI_STATUS Status;
515 // Allocate buffer for Simple Text Input device
517 Status = ConSplitterGrowBuffer (
518 sizeof (EFI_SIMPLE_TEXT_INPUT_PROTOCOL *),
519 &ConInPrivate->TextInListCount,
520 (VOID **) &ConInPrivate->TextInList
522 if (EFI_ERROR (Status)) {
523 return EFI_OUT_OF_RESOURCES;
527 // Create Event to wait for a key
529 Status = gBS->CreateEvent (
530 EVT_NOTIFY_WAIT,
531 TPL_NOTIFY,
532 ConSplitterTextInWaitForKey,
533 ConInPrivate,
534 &ConInPrivate->TextIn.WaitForKey
536 ASSERT_EFI_ERROR (Status);
539 // Allocate buffer for Simple Text Input Ex device
541 Status = ConSplitterGrowBuffer (
542 sizeof (EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *),
543 &ConInPrivate->TextInExListCount,
544 (VOID **) &ConInPrivate->TextInExList
546 if (EFI_ERROR (Status)) {
547 return EFI_OUT_OF_RESOURCES;
550 // Create Event to wait for a key Ex
552 Status = gBS->CreateEvent (
553 EVT_NOTIFY_WAIT,
554 TPL_NOTIFY,
555 ConSplitterTextInWaitForKey,
556 ConInPrivate,
557 &ConInPrivate->TextInEx.WaitForKeyEx
559 ASSERT_EFI_ERROR (Status);
561 InitializeListHead (&ConInPrivate->NotifyList);
563 ConInPrivate->AbsolutePointer.Mode = &ConInPrivate->AbsolutePointerMode;
565 // Allocate buffer for Absolute Pointer device
567 Status = ConSplitterGrowBuffer (
568 sizeof (EFI_ABSOLUTE_POINTER_PROTOCOL *),
569 &ConInPrivate->AbsolutePointerListCount,
570 (VOID **) &ConInPrivate->AbsolutePointerList
572 if (EFI_ERROR (Status)) {
573 return EFI_OUT_OF_RESOURCES;
576 // Create Event to wait for device input for Absolute pointer device
578 Status = gBS->CreateEvent (
579 EVT_NOTIFY_WAIT,
580 TPL_NOTIFY,
581 ConSplitterAbsolutePointerWaitForInput,
582 ConInPrivate,
583 &ConInPrivate->AbsolutePointer.WaitForInput
585 ASSERT_EFI_ERROR (Status);
587 ConInPrivate->SimplePointer.Mode = &ConInPrivate->SimplePointerMode;
589 // Allocate buffer for Simple Pointer device
591 Status = ConSplitterGrowBuffer (
592 sizeof (EFI_SIMPLE_POINTER_PROTOCOL *),
593 &ConInPrivate->PointerListCount,
594 (VOID **) &ConInPrivate->PointerList
596 if (EFI_ERROR (Status)) {
597 return EFI_OUT_OF_RESOURCES;
600 // Create Event to wait for device input for Simple pointer device
602 Status = gBS->CreateEvent (
603 EVT_NOTIFY_WAIT,
604 TPL_NOTIFY,
605 ConSplitterSimplePointerWaitForInput,
606 ConInPrivate,
607 &ConInPrivate->SimplePointer.WaitForInput
610 return Status;
614 Construct console output devices' private data.
616 @param ConOutPrivate A pointer to the TEXT_OUT_SPLITTER_PRIVATE_DATA
617 structure.
619 @retval EFI_OUT_OF_RESOURCES Out of resources.
620 @retval EFI_SUCCESS Text Input Devcie's private data has been constructed.
623 EFI_STATUS
624 ConSplitterTextOutConstructor (
625 TEXT_OUT_SPLITTER_PRIVATE_DATA *ConOutPrivate
628 EFI_STATUS Status;
629 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
632 // Copy protocols template
634 if (FeaturePcdGet (PcdConOutUgaSupport)) {
635 CopyMem (&ConOutPrivate->UgaDraw, &mUgaDrawProtocolTemplate, sizeof (EFI_UGA_DRAW_PROTOCOL));
637 if (FeaturePcdGet (PcdConOutGopSupport)) {
638 CopyMem (&ConOutPrivate->GraphicsOutput, &mGraphicsOutputProtocolTemplate, sizeof (EFI_GRAPHICS_OUTPUT_PROTOCOL));
642 // Initilize console output splitter's private data.
644 ConOutPrivate->TextOut.Mode = &ConOutPrivate->TextOutMode;
647 // When new console device is added, the new mode will be set later,
648 // so put current mode back to init state.
650 ConOutPrivate->TextOutMode.Mode = 0xFF;
652 // Allocate buffer for Console Out device
654 Status = ConSplitterGrowBuffer (
655 sizeof (TEXT_OUT_AND_GOP_DATA),
656 &ConOutPrivate->TextOutListCount,
657 (VOID **) &ConOutPrivate->TextOutList
659 if (EFI_ERROR (Status)) {
660 return EFI_OUT_OF_RESOURCES;
663 // Allocate buffer for Text Out query data
665 Status = ConSplitterGrowBuffer (
666 sizeof (TEXT_OUT_SPLITTER_QUERY_DATA),
667 &ConOutPrivate->TextOutQueryDataCount,
668 (VOID **) &ConOutPrivate->TextOutQueryData
670 if (EFI_ERROR (Status)) {
671 return EFI_OUT_OF_RESOURCES;
675 // Setup the default console to 80 x 25 and mode to 0
677 ConOutPrivate->TextOutQueryData[0].Columns = 80;
678 ConOutPrivate->TextOutQueryData[0].Rows = 25;
679 TextOutSetMode (ConOutPrivate, 0);
682 if (FeaturePcdGet (PcdConOutUgaSupport)) {
684 // Setup the UgaDraw to 800 x 600 x 32 bits per pixel, 60Hz.
686 ConSpliterUgaDrawSetMode (&ConOutPrivate->UgaDraw, 800, 600, 32, 60);
688 if (FeaturePcdGet (PcdConOutGopSupport)) {
690 // Setup resource for mode information in Graphics Output Protocol interface
692 if ((ConOutPrivate->GraphicsOutput.Mode = AllocateZeroPool (sizeof (EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE))) == NULL) {
693 return EFI_OUT_OF_RESOURCES;
695 if ((ConOutPrivate->GraphicsOutput.Mode->Info = AllocateZeroPool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION))) == NULL) {
696 return EFI_OUT_OF_RESOURCES;
699 // Setup the DevNullGraphicsOutput to 800 x 600 x 32 bits per pixel
700 // DevNull will be updated to user-defined mode after driver has started.
702 if ((ConOutPrivate->GraphicsOutputModeBuffer = AllocateZeroPool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION))) == NULL) {
703 return EFI_OUT_OF_RESOURCES;
705 Info = &ConOutPrivate->GraphicsOutputModeBuffer[0];
706 Info->Version = 0;
707 Info->HorizontalResolution = 800;
708 Info->VerticalResolution = 600;
709 Info->PixelFormat = PixelBltOnly;
710 Info->PixelsPerScanLine = 800;
711 CopyMem (ConOutPrivate->GraphicsOutput.Mode->Info, Info, sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
712 ConOutPrivate->GraphicsOutput.Mode->SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
715 // Initialize the following items, theset items remain unchanged in GraphicsOutput->SetMode()
716 // GraphicsOutputMode->FrameBufferBase, GraphicsOutputMode->FrameBufferSize
718 ConOutPrivate->GraphicsOutput.Mode->FrameBufferBase = (EFI_PHYSICAL_ADDRESS) (UINTN) NULL;
719 ConOutPrivate->GraphicsOutput.Mode->FrameBufferSize = 0;
721 ConOutPrivate->GraphicsOutput.Mode->MaxMode = 1;
723 // Initial current mode to unknown state, and then set to mode 0
725 ConOutPrivate->GraphicsOutput.Mode->Mode = 0xffff;
726 ConOutPrivate->GraphicsOutput.SetMode (&ConOutPrivate->GraphicsOutput, 0);
729 return EFI_SUCCESS;
734 Test to see if the specified protocol could be supported on the specified device.
736 @param This Driver Binding protocol pointer.
737 @param ControllerHandle Handle of device to test.
738 @param Guid The specified protocol.
740 @retval EFI_SUCCESS The specified protocol is supported on this device.
741 @retval EFI_UNSUPPORTED The specified protocol attempts to be installed on virtul handle.
742 @retval other Failed to open specified protocol on this device.
745 EFI_STATUS
746 ConSplitterSupported (
747 IN EFI_DRIVER_BINDING_PROTOCOL *This,
748 IN EFI_HANDLE ControllerHandle,
749 IN EFI_GUID *Guid
752 EFI_STATUS Status;
753 VOID *Instance;
756 // Make sure the Console Splitter does not attempt to attach to itself
758 if (ControllerHandle == mConIn.VirtualHandle ||
759 ControllerHandle == mConOut.VirtualHandle ||
760 ControllerHandle == mStdErr.VirtualHandle
762 return EFI_UNSUPPORTED;
766 // Check to see whether the specific protocol could be opened BY_DRIVER
768 Status = gBS->OpenProtocol (
769 ControllerHandle,
770 Guid,
771 &Instance,
772 This->DriverBindingHandle,
773 ControllerHandle,
774 EFI_OPEN_PROTOCOL_BY_DRIVER
777 if (EFI_ERROR (Status)) {
778 return Status;
781 gBS->CloseProtocol (
782 ControllerHandle,
783 Guid,
784 This->DriverBindingHandle,
785 ControllerHandle
788 return EFI_SUCCESS;
792 Test to see if Console In Device could be supported on the Controller.
794 @param This Driver Binding protocol instance pointer.
795 @param ControllerHandle Handle of device to test.
796 @param RemainingDevicePath Optional parameter use to pick a specific child
797 device to start.
799 @retval EFI_SUCCESS This driver supports this device.
800 @retval other This driver does not support this device.
803 EFI_STATUS
804 EFIAPI
805 ConSplitterConInDriverBindingSupported (
806 IN EFI_DRIVER_BINDING_PROTOCOL *This,
807 IN EFI_HANDLE ControllerHandle,
808 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
811 return ConSplitterSupported (
812 This,
813 ControllerHandle,
814 &gEfiConsoleInDeviceGuid
819 Test to see if Simple Pointer protocol could be supported on the Controller.
821 @param This Driver Binding protocol instance pointer.
822 @param ControllerHandle Handle of device to test.
823 @param RemainingDevicePath Optional parameter use to pick a specific child
824 device to start.
826 @retval EFI_SUCCESS This driver supports this device.
827 @retval other This driver does not support this device.
830 EFI_STATUS
831 EFIAPI
832 ConSplitterSimplePointerDriverBindingSupported (
833 IN EFI_DRIVER_BINDING_PROTOCOL *This,
834 IN EFI_HANDLE ControllerHandle,
835 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
838 return ConSplitterSupported (
839 This,
840 ControllerHandle,
841 &gEfiSimplePointerProtocolGuid
846 Test to see if Absolute Pointer protocol could be supported on the Controller.
848 @param This Driver Binding protocol instance pointer.
849 @param ControllerHandle Handle of device to test.
850 @param RemainingDevicePath Optional parameter use to pick a specific child
851 device to start.
853 @retval EFI_SUCCESS This driver supports this device.
854 @retval other This driver does not support this device.
857 EFI_STATUS
858 EFIAPI
859 ConSplitterAbsolutePointerDriverBindingSupported (
860 IN EFI_DRIVER_BINDING_PROTOCOL *This,
861 IN EFI_HANDLE ControllerHandle,
862 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
865 return ConSplitterSupported (
866 This,
867 ControllerHandle,
868 &gEfiAbsolutePointerProtocolGuid
874 Test to see if Console Out Device could be supported on the Controller.
876 @param This Driver Binding protocol instance pointer.
877 @param ControllerHandle Handle of device to test.
878 @param RemainingDevicePath Optional parameter use to pick a specific child
879 device to start.
881 @retval EFI_SUCCESS This driver supports this device.
882 @retval other This driver does not support this device.
885 EFI_STATUS
886 EFIAPI
887 ConSplitterConOutDriverBindingSupported (
888 IN EFI_DRIVER_BINDING_PROTOCOL *This,
889 IN EFI_HANDLE ControllerHandle,
890 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
893 return ConSplitterSupported (
894 This,
895 ControllerHandle,
896 &gEfiConsoleOutDeviceGuid
901 Test to see if Standard Error Device could be supported on the Controller.
903 @param This Driver Binding protocol instance pointer.
904 @param ControllerHandle Handle of device to test.
905 @param RemainingDevicePath Optional parameter use to pick a specific child
906 device to start.
908 @retval EFI_SUCCESS This driver supports this device.
909 @retval other This driver does not support this device.
912 EFI_STATUS
913 EFIAPI
914 ConSplitterStdErrDriverBindingSupported (
915 IN EFI_DRIVER_BINDING_PROTOCOL *This,
916 IN EFI_HANDLE ControllerHandle,
917 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
920 return ConSplitterSupported (
921 This,
922 ControllerHandle,
923 &gEfiStandardErrorDeviceGuid
929 Start ConSplitter on devcie handle by opening Console Device Guid on device handle
930 and the console virtual handle. And Get the console interface on controller handle.
932 @param This Driver Binding protocol instance pointer.
933 @param ControllerHandle Handle of device.
934 @param ConSplitterVirtualHandle Console virtual Handle.
935 @param DeviceGuid The specified Console Device, such as ConInDev,
936 ConOutDev.
937 @param InterfaceGuid The specified protocol to be opened.
938 @param Interface Protocol interface returned.
940 @retval EFI_SUCCESS This driver supports this device.
941 @retval other Failed to open the specified Console Device Guid
942 or specified protocol.
945 EFI_STATUS
946 ConSplitterStart (
947 IN EFI_DRIVER_BINDING_PROTOCOL *This,
948 IN EFI_HANDLE ControllerHandle,
949 IN EFI_HANDLE ConSplitterVirtualHandle,
950 IN EFI_GUID *DeviceGuid,
951 IN EFI_GUID *InterfaceGuid,
952 OUT VOID **Interface
955 EFI_STATUS Status;
956 VOID *Instance;
959 // Check to see whether the ControllerHandle has the DeviceGuid on it.
961 Status = gBS->OpenProtocol (
962 ControllerHandle,
963 DeviceGuid,
964 &Instance,
965 This->DriverBindingHandle,
966 ControllerHandle,
967 EFI_OPEN_PROTOCOL_BY_DRIVER
969 if (EFI_ERROR (Status)) {
970 return Status;
974 // Create virtual handle and open DeviceGuid on the virtul handle.
976 Status = gBS->OpenProtocol (
977 ControllerHandle,
978 DeviceGuid,
979 &Instance,
980 This->DriverBindingHandle,
981 ConSplitterVirtualHandle,
982 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
984 if (EFI_ERROR (Status)) {
985 goto Err;
989 // Open InterfaceGuid on the virtul handle.
991 Status = gBS->OpenProtocol (
992 ControllerHandle,
993 InterfaceGuid,
994 Interface,
995 This->DriverBindingHandle,
996 ConSplitterVirtualHandle,
997 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1000 if (!EFI_ERROR (Status)) {
1001 return EFI_SUCCESS;
1005 // close the DeviceGuid on ConSplitter VirtualHandle.
1007 gBS->CloseProtocol (
1008 ControllerHandle,
1009 DeviceGuid,
1010 This->DriverBindingHandle,
1011 ConSplitterVirtualHandle
1014 Err:
1016 // close the DeviceGuid on ControllerHandle.
1018 gBS->CloseProtocol (
1019 ControllerHandle,
1020 DeviceGuid,
1021 This->DriverBindingHandle,
1022 ControllerHandle
1025 return Status;
1030 Start Console In Consplitter on device handle.
1032 @param This Driver Binding protocol instance pointer.
1033 @param ControllerHandle Handle of device to bind driver to.
1034 @param RemainingDevicePath Optional parameter use to pick a specific child
1035 device to start.
1037 @retval EFI_SUCCESS Console In Consplitter is added to ControllerHandle.
1038 @retval other Console In Consplitter does not support this device.
1041 EFI_STATUS
1042 EFIAPI
1043 ConSplitterConInDriverBindingStart (
1044 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1045 IN EFI_HANDLE ControllerHandle,
1046 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
1049 EFI_STATUS Status;
1050 EFI_SIMPLE_TEXT_INPUT_PROTOCOL *TextIn;
1051 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TextInEx;
1054 // Start ConSplitter on ControllerHandle, and create the virtual
1055 // agrogated console device on first call Start for a SimpleTextIn handle.
1057 Status = ConSplitterStart (
1058 This,
1059 ControllerHandle,
1060 mConIn.VirtualHandle,
1061 &gEfiConsoleInDeviceGuid,
1062 &gEfiSimpleTextInProtocolGuid,
1063 (VOID **) &TextIn
1065 if (EFI_ERROR (Status)) {
1066 return Status;
1070 // Add this device into Text In devices list.
1072 Status = ConSplitterTextInAddDevice (&mConIn, TextIn);
1073 if (EFI_ERROR (Status)) {
1074 return Status;
1077 Status = gBS->OpenProtocol (
1078 ControllerHandle,
1079 &gEfiSimpleTextInputExProtocolGuid,
1080 (VOID **) &TextInEx,
1081 This->DriverBindingHandle,
1082 mConIn.VirtualHandle,
1083 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1085 if (!EFI_ERROR (Status)) {
1087 // If Simple Text Input Ex protocol exists,
1088 // add this device into Text In Ex devices list.
1090 Status = ConSplitterTextInExAddDevice (&mConIn, TextInEx);
1093 return Status;
1098 Start Simple Pointer Consplitter on device handle.
1100 @param This Driver Binding protocol instance pointer.
1101 @param ControllerHandle Handle of device to bind driver to.
1102 @param RemainingDevicePath Optional parameter use to pick a specific child
1103 device to start.
1105 @retval EFI_SUCCESS Simple Pointer Consplitter is added to ControllerHandle.
1106 @retval other Simple Pointer Consplitter does not support this device.
1109 EFI_STATUS
1110 EFIAPI
1111 ConSplitterSimplePointerDriverBindingStart (
1112 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1113 IN EFI_HANDLE ControllerHandle,
1114 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
1117 EFI_STATUS Status;
1118 EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer;
1121 // Start ConSplitter on ControllerHandle, and create the virtual
1122 // agrogated console device on first call Start for a SimplePointer handle.
1124 Status = ConSplitterStart (
1125 This,
1126 ControllerHandle,
1127 mConIn.VirtualHandle,
1128 &gEfiSimplePointerProtocolGuid,
1129 &gEfiSimplePointerProtocolGuid,
1130 (VOID **) &SimplePointer
1132 if (EFI_ERROR (Status)) {
1133 return Status;
1137 // Add this devcie into Simple Pointer devices list.
1139 return ConSplitterSimplePointerAddDevice (&mConIn, SimplePointer);
1144 Start Absolute Pointer Consplitter on device handle.
1146 @param This Driver Binding protocol instance pointer.
1147 @param ControllerHandle Handle of device to bind driver to.
1148 @param RemainingDevicePath Optional parameter use to pick a specific child
1149 device to start.
1151 @retval EFI_SUCCESS Absolute Pointer Consplitter is added to ControllerHandle.
1152 @retval other Absolute Pointer Consplitter does not support this device.
1155 EFI_STATUS
1156 EFIAPI
1157 ConSplitterAbsolutePointerDriverBindingStart (
1158 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1159 IN EFI_HANDLE ControllerHandle,
1160 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
1163 EFI_STATUS Status;
1164 EFI_ABSOLUTE_POINTER_PROTOCOL *AbsolutePointer;
1167 // Start ConSplitter on ControllerHandle, and create the virtual
1168 // agrogated console device on first call Start for a AbsolutePointer handle.
1170 Status = ConSplitterStart (
1171 This,
1172 ControllerHandle,
1173 mConIn.VirtualHandle,
1174 &gEfiAbsolutePointerProtocolGuid,
1175 &gEfiAbsolutePointerProtocolGuid,
1176 (VOID **) &AbsolutePointer
1179 if (EFI_ERROR (Status)) {
1180 return Status;
1184 // Add this devcie into Absolute Pointer devices list.
1186 return ConSplitterAbsolutePointerAddDevice (&mConIn, AbsolutePointer);
1191 Start Console Out Consplitter on device handle.
1193 @param This Driver Binding protocol instance pointer.
1194 @param ControllerHandle Handle of device to bind driver to.
1195 @param RemainingDevicePath Optional parameter use to pick a specific child
1196 device to start.
1198 @retval EFI_SUCCESS Console Out Consplitter is added to ControllerHandle.
1199 @retval other Console Out Consplitter does not support this device.
1202 EFI_STATUS
1203 EFIAPI
1204 ConSplitterConOutDriverBindingStart (
1205 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1206 IN EFI_HANDLE ControllerHandle,
1207 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
1210 EFI_STATUS Status;
1211 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut;
1212 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
1213 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
1214 UINTN SizeOfInfo;
1215 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
1218 // Start ConSplitter on ControllerHandle, and create the virtual
1219 // agrogated console device on first call Start for a ConsoleOut handle.
1221 Status = ConSplitterStart (
1222 This,
1223 ControllerHandle,
1224 mConOut.VirtualHandle,
1225 &gEfiConsoleOutDeviceGuid,
1226 &gEfiSimpleTextOutProtocolGuid,
1227 (VOID **) &TextOut
1229 if (EFI_ERROR (Status)) {
1230 return Status;
1233 GraphicsOutput = NULL;
1234 UgaDraw = NULL;
1236 // Try to Open Graphics Output protocol
1238 Status = gBS->OpenProtocol (
1239 ControllerHandle,
1240 &gEfiGraphicsOutputProtocolGuid,
1241 (VOID **) &GraphicsOutput,
1242 This->DriverBindingHandle,
1243 mConOut.VirtualHandle,
1244 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1247 if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {
1249 // Open UGA DRAW protocol
1251 gBS->OpenProtocol (
1252 ControllerHandle,
1253 &gEfiUgaDrawProtocolGuid,
1254 (VOID **) &UgaDraw,
1255 This->DriverBindingHandle,
1256 mConOut.VirtualHandle,
1257 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1262 // When new console device is added, the new mode will be set later,
1263 // so put current mode back to init state.
1265 mConOut.TextOutMode.Mode = 0xFF;
1268 // If both ConOut and StdErr incorporate the same Text Out device,
1269 // their MaxMode and QueryData should be the intersection of both.
1271 Status = ConSplitterTextOutAddDevice (&mConOut, TextOut, GraphicsOutput, UgaDraw);
1272 ConSplitterTextOutSetAttribute (&mConOut.TextOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
1274 if (FeaturePcdGet (PcdConOutUgaSupport)) {
1276 // Get the UGA mode data of ConOut from the current mode
1278 if (GraphicsOutput != NULL) {
1279 Status = GraphicsOutput->QueryMode (GraphicsOutput, GraphicsOutput->Mode->Mode, &SizeOfInfo, &Info);
1280 if (EFI_ERROR (Status)) {
1281 return Status;
1283 ASSERT ( SizeOfInfo <= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
1285 mConOut.UgaHorizontalResolution = Info->HorizontalResolution;
1286 mConOut.UgaVerticalResolution = Info->VerticalResolution;
1287 mConOut.UgaColorDepth = 32;
1288 mConOut.UgaRefreshRate = 60;
1290 FreePool (Info);
1292 } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {
1293 Status = UgaDraw->GetMode (
1294 UgaDraw,
1295 &mConOut.UgaHorizontalResolution,
1296 &mConOut.UgaVerticalResolution,
1297 &mConOut.UgaColorDepth,
1298 &mConOut.UgaRefreshRate
1303 return Status;
1308 Start Standard Error Consplitter on device handle.
1310 @param This Driver Binding protocol instance pointer.
1311 @param ControllerHandle Handle of device to bind driver to.
1312 @param RemainingDevicePath Optional parameter use to pick a specific child
1313 device to start.
1315 @retval EFI_SUCCESS Standard Error Consplitter is added to ControllerHandle.
1316 @retval other Standard Error Consplitter does not support this device.
1319 EFI_STATUS
1320 EFIAPI
1321 ConSplitterStdErrDriverBindingStart (
1322 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1323 IN EFI_HANDLE ControllerHandle,
1324 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
1327 EFI_STATUS Status;
1328 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut;
1331 // Start ConSplitter on ControllerHandle, and create the virtual
1332 // agrogated console device on first call Start for a StandardError handle.
1334 Status = ConSplitterStart (
1335 This,
1336 ControllerHandle,
1337 mStdErr.VirtualHandle,
1338 &gEfiStandardErrorDeviceGuid,
1339 &gEfiSimpleTextOutProtocolGuid,
1340 (VOID **) &TextOut
1342 if (EFI_ERROR (Status)) {
1343 return Status;
1347 // When new console device is added, the new mode will be set later,
1348 // so put current mode back to init state.
1350 mStdErr.TextOutMode.Mode = 0xFF;
1353 // If both ConOut and StdErr incorporate the same Text Out device,
1354 // their MaxMode and QueryData should be the intersection of both.
1356 Status = ConSplitterTextOutAddDevice (&mStdErr, TextOut, NULL, NULL);
1357 ConSplitterTextOutSetAttribute (&mStdErr.TextOut, EFI_TEXT_ATTR (EFI_MAGENTA, EFI_BLACK));
1358 if (EFI_ERROR (Status)) {
1359 return Status;
1362 if (mStdErr.CurrentNumberOfConsoles == 1) {
1363 gST->StandardErrorHandle = mStdErr.VirtualHandle;
1364 gST->StdErr = &mStdErr.TextOut;
1366 // Update the CRC32 in the EFI System Table header
1368 gST->Hdr.CRC32 = 0;
1369 gBS->CalculateCrc32 (
1370 (UINT8 *) &gST->Hdr,
1371 gST->Hdr.HeaderSize,
1372 &gST->Hdr.CRC32
1376 return Status;
1381 Stop ConSplitter on device handle by closing Console Device Guid on device handle
1382 and the console virtual handle.
1384 @param This Protocol instance pointer.
1385 @param ControllerHandle Handle of device.
1386 @param ConSplitterVirtualHandle Console virtual Handle.
1387 @param DeviceGuid The specified Console Device, such as ConInDev,
1388 ConOutDev.
1389 @param InterfaceGuid The specified protocol to be opened.
1390 @param Interface Protocol interface returned.
1392 @retval EFI_SUCCESS Stop ConSplitter on ControllerHandle successfully.
1393 @retval other Failed to Stop ConSplitter on ControllerHandle.
1396 EFI_STATUS
1397 ConSplitterStop (
1398 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1399 IN EFI_HANDLE ControllerHandle,
1400 IN EFI_HANDLE ConSplitterVirtualHandle,
1401 IN EFI_GUID *DeviceGuid,
1402 IN EFI_GUID *InterfaceGuid,
1403 IN VOID **Interface
1406 EFI_STATUS Status;
1408 Status = gBS->OpenProtocol (
1409 ControllerHandle,
1410 InterfaceGuid,
1411 Interface,
1412 This->DriverBindingHandle,
1413 ControllerHandle,
1414 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1416 if (EFI_ERROR (Status)) {
1417 return Status;
1420 // close the protocol refered.
1422 gBS->CloseProtocol (
1423 ControllerHandle,
1424 DeviceGuid,
1425 This->DriverBindingHandle,
1426 ConSplitterVirtualHandle
1429 gBS->CloseProtocol (
1430 ControllerHandle,
1431 DeviceGuid,
1432 This->DriverBindingHandle,
1433 ControllerHandle
1436 return EFI_SUCCESS;
1441 Stop Console In ConSplitter on ControllerHandle by closing Console In Devcice GUID.
1443 @param This Driver Binding protocol instance pointer.
1444 @param ControllerHandle Handle of device to stop driver on
1445 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
1446 children is zero stop the entire bus driver.
1447 @param ChildHandleBuffer List of Child Handles to Stop.
1449 @retval EFI_SUCCESS This driver is removed ControllerHandle
1450 @retval other This driver was not removed from this device
1453 EFI_STATUS
1454 EFIAPI
1455 ConSplitterConInDriverBindingStop (
1456 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1457 IN EFI_HANDLE ControllerHandle,
1458 IN UINTN NumberOfChildren,
1459 IN EFI_HANDLE *ChildHandleBuffer
1462 EFI_STATUS Status;
1463 EFI_SIMPLE_TEXT_INPUT_PROTOCOL *TextIn;
1464 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TextInEx;
1466 if (NumberOfChildren == 0) {
1467 return EFI_SUCCESS;
1470 Status = gBS->OpenProtocol (
1471 ControllerHandle,
1472 &gEfiSimpleTextInputExProtocolGuid,
1473 (VOID **) &TextInEx,
1474 This->DriverBindingHandle,
1475 ControllerHandle,
1476 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1478 if (!EFI_ERROR (Status)) {
1480 // If Simple Text Input Ex protocol exists,
1481 // remove device from Text Input Ex devices list.
1483 Status = ConSplitterTextInExDeleteDevice (&mConIn, TextInEx);
1484 if (EFI_ERROR (Status)) {
1485 return Status;
1490 // Close Simple Text In protocol on controller handle and virtual handle.
1492 Status = ConSplitterStop (
1493 This,
1494 ControllerHandle,
1495 mConIn.VirtualHandle,
1496 &gEfiConsoleInDeviceGuid,
1497 &gEfiSimpleTextInProtocolGuid,
1498 (VOID **) &TextIn
1500 if (EFI_ERROR (Status)) {
1501 return Status;
1505 // Remove device from Text Input devices list.
1507 return ConSplitterTextInDeleteDevice (&mConIn, TextIn);
1512 Stop Simple Pointer protocol ConSplitter on ControllerHandle by closing
1513 Simple Pointer protocol.
1515 @param This Driver Binding protocol instance pointer.
1516 @param ControllerHandle Handle of device to stop driver on
1517 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
1518 children is zero stop the entire bus driver.
1519 @param ChildHandleBuffer List of Child Handles to Stop.
1521 @retval EFI_SUCCESS This driver is removed ControllerHandle
1522 @retval other This driver was not removed from this device
1525 EFI_STATUS
1526 EFIAPI
1527 ConSplitterSimplePointerDriverBindingStop (
1528 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1529 IN EFI_HANDLE ControllerHandle,
1530 IN UINTN NumberOfChildren,
1531 IN EFI_HANDLE *ChildHandleBuffer
1534 EFI_STATUS Status;
1535 EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer;
1537 if (NumberOfChildren == 0) {
1538 return EFI_SUCCESS;
1542 // Close Simple Pointer protocol on controller handle and virtual handle.
1544 Status = ConSplitterStop (
1545 This,
1546 ControllerHandle,
1547 mConIn.VirtualHandle,
1548 &gEfiSimplePointerProtocolGuid,
1549 &gEfiSimplePointerProtocolGuid,
1550 (VOID **) &SimplePointer
1552 if (EFI_ERROR (Status)) {
1553 return Status;
1557 // Remove this device from Simple Pointer device list.
1559 return ConSplitterSimplePointerDeleteDevice (&mConIn, SimplePointer);
1564 Stop Absolute Pointer protocol ConSplitter on ControllerHandle by closing
1565 Absolute Pointer protocol.
1567 @param This Driver Binding protocol instance pointer.
1568 @param ControllerHandle Handle of device to stop driver on
1569 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
1570 children is zero stop the entire bus driver.
1571 @param ChildHandleBuffer List of Child Handles to Stop.
1573 @retval EFI_SUCCESS This driver is removed ControllerHandle
1574 @retval other This driver was not removed from this device
1577 EFI_STATUS
1578 EFIAPI
1579 ConSplitterAbsolutePointerDriverBindingStop (
1580 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1581 IN EFI_HANDLE ControllerHandle,
1582 IN UINTN NumberOfChildren,
1583 IN EFI_HANDLE *ChildHandleBuffer
1586 EFI_STATUS Status;
1587 EFI_ABSOLUTE_POINTER_PROTOCOL *AbsolutePointer;
1589 if (NumberOfChildren == 0) {
1590 return EFI_SUCCESS;
1594 // Close Absolute Pointer protocol on controller handle and virtual handle.
1596 Status = ConSplitterStop (
1597 This,
1598 ControllerHandle,
1599 mConIn.VirtualHandle,
1600 &gEfiAbsolutePointerProtocolGuid,
1601 &gEfiAbsolutePointerProtocolGuid,
1602 (VOID **) &AbsolutePointer
1604 if (EFI_ERROR (Status)) {
1605 return Status;
1609 // Remove this device from Absolute Pointer device list.
1611 return ConSplitterAbsolutePointerDeleteDevice (&mConIn, AbsolutePointer);
1616 Stop Console Out ConSplitter on device handle by closing Console Out Devcice GUID.
1618 @param This Driver Binding protocol instance pointer.
1619 @param ControllerHandle Handle of device to stop driver on
1620 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
1621 children is zero stop the entire bus driver.
1622 @param ChildHandleBuffer List of Child Handles to Stop.
1624 @retval EFI_SUCCESS This driver is removed ControllerHandle
1625 @retval other This driver was not removed from this device
1628 EFI_STATUS
1629 EFIAPI
1630 ConSplitterConOutDriverBindingStop (
1631 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1632 IN EFI_HANDLE ControllerHandle,
1633 IN UINTN NumberOfChildren,
1634 IN EFI_HANDLE *ChildHandleBuffer
1637 EFI_STATUS Status;
1638 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut;
1640 if (NumberOfChildren == 0) {
1641 return EFI_SUCCESS;
1645 // Close Absolute Pointer protocol on controller handle and virtual handle.
1647 Status = ConSplitterStop (
1648 This,
1649 ControllerHandle,
1650 mConOut.VirtualHandle,
1651 &gEfiConsoleOutDeviceGuid,
1652 &gEfiSimpleTextOutProtocolGuid,
1653 (VOID **) &TextOut
1655 if (EFI_ERROR (Status)) {
1656 return Status;
1660 // Remove this device from Text Out device list.
1662 return ConSplitterTextOutDeleteDevice (&mConOut, TextOut);
1667 Stop Standard Error ConSplitter on ControllerHandle by closing Standard Error GUID.
1669 @param This Driver Binding protocol instance pointer.
1670 @param ControllerHandle Handle of device to stop driver on
1671 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
1672 children is zero stop the entire bus driver.
1673 @param ChildHandleBuffer List of Child Handles to Stop.
1675 @retval EFI_SUCCESS This driver is removed ControllerHandle
1676 @retval other This driver was not removed from this device
1679 EFI_STATUS
1680 EFIAPI
1681 ConSplitterStdErrDriverBindingStop (
1682 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1683 IN EFI_HANDLE ControllerHandle,
1684 IN UINTN NumberOfChildren,
1685 IN EFI_HANDLE *ChildHandleBuffer
1688 EFI_STATUS Status;
1689 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut;
1691 if (NumberOfChildren == 0) {
1692 return EFI_SUCCESS;
1696 // Close Standard Error Device on controller handle and virtual handle.
1698 Status = ConSplitterStop (
1699 This,
1700 ControllerHandle,
1701 mStdErr.VirtualHandle,
1702 &gEfiStandardErrorDeviceGuid,
1703 &gEfiSimpleTextOutProtocolGuid,
1704 (VOID **) &TextOut
1706 if (EFI_ERROR (Status)) {
1707 return Status;
1710 // Delete this console error out device's data structures.
1712 Status = ConSplitterTextOutDeleteDevice (&mStdErr, TextOut);
1713 if (EFI_ERROR (Status)) {
1714 return Status;
1717 if (mStdErr.CurrentNumberOfConsoles == 0) {
1718 gST->StandardErrorHandle = NULL;
1719 gST->StdErr = NULL;
1721 // Update the CRC32 in the EFI System Table header
1723 gST->Hdr.CRC32 = 0;
1724 gBS->CalculateCrc32 (
1725 (UINT8 *) &gST->Hdr,
1726 gST->Hdr.HeaderSize,
1727 &gST->Hdr.CRC32
1731 return Status;
1736 Take the passed in Buffer of size SizeOfCount and grow the buffer
1737 by MAX (CONSOLE_SPLITTER_CONSOLES_ALLOC_UNIT, MaxGrow) * SizeOfCount
1738 bytes. Copy the current data in Buffer to the new version of Buffer
1739 and free the old version of buffer.
1741 @param SizeOfCount Size of element in array.
1742 @param Count Current number of elements in array.
1743 @param Buffer Bigger version of passed in Buffer with all the
1744 data.
1746 @retval EFI_SUCCESS Buffer size has grown.
1747 @retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
1750 EFI_STATUS
1751 ConSplitterGrowBuffer (
1752 IN UINTN SizeOfCount,
1753 IN UINTN *Count,
1754 IN OUT VOID **Buffer
1757 VOID *Ptr;
1760 // grow the buffer to new buffer size,
1761 // copy the old buffer's content to the new-size buffer,
1762 // then free the old buffer.
1764 *Count += CONSOLE_SPLITTER_CONSOLES_ALLOC_UNIT;
1765 Ptr = ReallocatePool (
1766 SizeOfCount * ((*Count) - CONSOLE_SPLITTER_CONSOLES_ALLOC_UNIT),
1767 SizeOfCount * (*Count),
1768 *Buffer
1770 if (Ptr == NULL) {
1771 return EFI_OUT_OF_RESOURCES;
1773 *Buffer = Ptr;
1774 return EFI_SUCCESS;
1779 Add Text Input Device in Consplitter Text Input list.
1781 @param Private Text In Splitter pointer.
1782 @param TextIn Simple Text Input protocol pointer.
1784 @retval EFI_SUCCESS Text Input Device added successfully.
1785 @retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
1788 EFI_STATUS
1789 ConSplitterTextInAddDevice (
1790 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
1791 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *TextIn
1794 EFI_STATUS Status;
1797 // If the Text In List is full, enlarge it by calling ConSplitterGrowBuffer().
1799 if (Private->CurrentNumberOfConsoles >= Private->TextInListCount) {
1800 Status = ConSplitterGrowBuffer (
1801 sizeof (EFI_SIMPLE_TEXT_INPUT_PROTOCOL *),
1802 &Private->TextInListCount,
1803 (VOID **) &Private->TextInList
1805 if (EFI_ERROR (Status)) {
1806 return EFI_OUT_OF_RESOURCES;
1810 // Add the new text-in device data structure into the Text In List.
1812 Private->TextInList[Private->CurrentNumberOfConsoles] = TextIn;
1813 Private->CurrentNumberOfConsoles++;
1816 // Extra CheckEvent added to reduce the double CheckEvent().
1818 gBS->CheckEvent (TextIn->WaitForKey);
1820 return EFI_SUCCESS;
1825 Remove Text Input Device from Consplitter Text Input list.
1827 @param Private Text In Splitter pointer.
1828 @param TextIn Simple Text protocol pointer.
1830 @retval EFI_SUCCESS Simple Text Device removed successfully.
1831 @retval EFI_NOT_FOUND No Simple Text Device found.
1834 EFI_STATUS
1835 ConSplitterTextInDeleteDevice (
1836 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
1837 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *TextIn
1840 UINTN Index;
1842 // Remove the specified text-in device data structure from the Text In List,
1843 // and rearrange the remaining data structures in the Text In List.
1845 for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {
1846 if (Private->TextInList[Index] == TextIn) {
1847 for (Index = Index; Index < Private->CurrentNumberOfConsoles - 1; Index++) {
1848 Private->TextInList[Index] = Private->TextInList[Index + 1];
1851 Private->CurrentNumberOfConsoles--;
1852 return EFI_SUCCESS;
1856 return EFI_NOT_FOUND;
1860 Add Text Input Ex Device in Consplitter Text Input Ex list.
1862 @param Private Text In Splitter pointer.
1863 @param TextInEx Simple Text Input Ex Input protocol pointer.
1865 @retval EFI_SUCCESS Text Input Ex Device added successfully.
1866 @retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
1869 EFI_STATUS
1870 ConSplitterTextInExAddDevice (
1871 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
1872 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TextInEx
1875 EFI_STATUS Status;
1878 // If the Text Input Ex List is full, enlarge it by calling ConSplitterGrowBuffer().
1880 if (Private->CurrentNumberOfExConsoles >= Private->TextInExListCount) {
1881 Status = ConSplitterGrowBuffer (
1882 sizeof (EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *),
1883 &Private->TextInExListCount,
1884 (VOID **) &Private->TextInExList
1886 if (EFI_ERROR (Status)) {
1887 return EFI_OUT_OF_RESOURCES;
1891 // Add the new text-in device data structure into the Text Input Ex List.
1893 Private->TextInExList[Private->CurrentNumberOfExConsoles] = TextInEx;
1894 Private->CurrentNumberOfExConsoles++;
1897 // Extra CheckEvent added to reduce the double CheckEvent().
1899 gBS->CheckEvent (TextInEx->WaitForKeyEx);
1901 return EFI_SUCCESS;
1905 Remove Text Ex Device from Consplitter Text Input Ex list.
1907 @param Private Text In Splitter pointer.
1908 @param TextInEx Simple Text Ex protocol pointer.
1910 @retval EFI_SUCCESS Simple Text Input Ex Device removed successfully.
1911 @retval EFI_NOT_FOUND No Simple Text Input Ex Device found.
1914 EFI_STATUS
1915 ConSplitterTextInExDeleteDevice (
1916 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
1917 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TextInEx
1920 UINTN Index;
1922 // Remove the specified text-in device data structure from the Text Input Ex List,
1923 // and rearrange the remaining data structures in the Text In List.
1925 for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {
1926 if (Private->TextInExList[Index] == TextInEx) {
1927 for (Index = Index; Index < Private->CurrentNumberOfExConsoles - 1; Index++) {
1928 Private->TextInExList[Index] = Private->TextInExList[Index + 1];
1931 Private->CurrentNumberOfExConsoles--;
1932 return EFI_SUCCESS;
1936 return EFI_NOT_FOUND;
1941 Add Simple Pointer Device in Consplitter Simple Pointer list.
1943 @param Private Text In Splitter pointer.
1944 @param SimplePointer Simple Pointer protocol pointer.
1946 @retval EFI_SUCCESS Simple Pointer Device added successfully.
1947 @retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
1950 EFI_STATUS
1951 ConSplitterSimplePointerAddDevice (
1952 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
1953 IN EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer
1956 EFI_STATUS Status;
1959 // If the Simple Pointer List is full, enlarge it by calling ConSplitterGrowBuffer().
1961 if (Private->CurrentNumberOfPointers >= Private->PointerListCount) {
1962 Status = ConSplitterGrowBuffer (
1963 sizeof (EFI_SIMPLE_POINTER_PROTOCOL *),
1964 &Private->PointerListCount,
1965 (VOID **) &Private->PointerList
1967 if (EFI_ERROR (Status)) {
1968 return EFI_OUT_OF_RESOURCES;
1972 // Add the new text-in device data structure into the Simple Pointer List.
1974 Private->PointerList[Private->CurrentNumberOfPointers] = SimplePointer;
1975 Private->CurrentNumberOfPointers++;
1977 return EFI_SUCCESS;
1982 Remove Simple Pointer Device from Consplitter Simple Pointer list.
1984 @param Private Text In Splitter pointer.
1985 @param SimplePointer Simple Pointer protocol pointer.
1987 @retval EFI_SUCCESS Simple Pointer Device removed successfully.
1988 @retval EFI_NOT_FOUND No Simple Pointer Device found.
1991 EFI_STATUS
1992 ConSplitterSimplePointerDeleteDevice (
1993 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
1994 IN EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer
1997 UINTN Index;
1999 // Remove the specified text-in device data structure from the Simple Pointer List,
2000 // and rearrange the remaining data structures in the Text In List.
2002 for (Index = 0; Index < Private->CurrentNumberOfPointers; Index++) {
2003 if (Private->PointerList[Index] == SimplePointer) {
2004 for (Index = Index; Index < Private->CurrentNumberOfPointers - 1; Index++) {
2005 Private->PointerList[Index] = Private->PointerList[Index + 1];
2008 Private->CurrentNumberOfPointers--;
2009 return EFI_SUCCESS;
2013 return EFI_NOT_FOUND;
2018 Add Absolute Pointer Device in Consplitter Absolute Pointer list.
2020 @param Private Text In Splitter pointer.
2021 @param AbsolutePointer Absolute Pointer protocol pointer.
2023 @retval EFI_SUCCESS Absolute Pointer Device added successfully.
2024 @retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
2027 EFI_STATUS
2028 ConSplitterAbsolutePointerAddDevice (
2029 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
2030 IN EFI_ABSOLUTE_POINTER_PROTOCOL *AbsolutePointer
2033 EFI_STATUS Status;
2036 // If the Absolute Pointer List is full, enlarge it by calling ConSplitterGrowBuffer().
2038 if (Private->CurrentNumberOfAbsolutePointers >= Private->AbsolutePointerListCount) {
2039 Status = ConSplitterGrowBuffer (
2040 sizeof (EFI_ABSOLUTE_POINTER_PROTOCOL *),
2041 &Private->AbsolutePointerListCount,
2042 (VOID **) &Private->AbsolutePointerList
2044 if (EFI_ERROR (Status)) {
2045 return EFI_OUT_OF_RESOURCES;
2049 // Add the new text-in device data structure into the Absolute Pointer List.
2051 Private->AbsolutePointerList[Private->CurrentNumberOfAbsolutePointers] = AbsolutePointer;
2052 Private->CurrentNumberOfAbsolutePointers++;
2054 return EFI_SUCCESS;
2059 Remove Absolute Pointer Device from Consplitter Absolute Pointer list.
2061 @param Private Text In Splitter pointer.
2062 @param AbsolutePointer Absolute Pointer protocol pointer.
2064 @retval EFI_SUCCESS Absolute Pointer Device removed successfully.
2065 @retval EFI_NOT_FOUND No Absolute Pointer Device found.
2068 EFI_STATUS
2069 ConSplitterAbsolutePointerDeleteDevice (
2070 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
2071 IN EFI_ABSOLUTE_POINTER_PROTOCOL *AbsolutePointer
2074 UINTN Index;
2076 // Remove the specified text-in device data structure from the Absolute Pointer List,
2077 // and rearrange the remaining data structures from the Absolute Pointer List.
2079 for (Index = 0; Index < Private->CurrentNumberOfAbsolutePointers; Index++) {
2080 if (Private->AbsolutePointerList[Index] == AbsolutePointer) {
2081 for (Index = Index; Index < Private->CurrentNumberOfAbsolutePointers - 1; Index++) {
2082 Private->AbsolutePointerList[Index] = Private->AbsolutePointerList[Index + 1];
2085 Private->CurrentNumberOfAbsolutePointers--;
2086 return EFI_SUCCESS;
2090 return EFI_NOT_FOUND;
2094 Reallocate Text Out mode map.
2096 Allocate new buffer and copy original buffer into the new buffer.
2098 @param Private Consplitter Text Out pointer.
2100 @retval EFI_SUCCESS Buffer size has grown
2101 @retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
2104 EFI_STATUS
2105 ConSplitterGrowMapTable (
2106 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private
2109 UINTN Size;
2110 UINTN NewSize;
2111 UINTN TotalSize;
2112 INT32 *TextOutModeMap;
2113 INT32 *OldTextOutModeMap;
2114 INT32 *SrcAddress;
2115 INT32 Index;
2117 NewSize = Private->TextOutListCount * sizeof (INT32);
2118 OldTextOutModeMap = Private->TextOutModeMap;
2119 TotalSize = NewSize * (Private->TextOutQueryDataCount);
2122 // Allocate new buffer for Text Out List.
2124 TextOutModeMap = AllocatePool (TotalSize);
2125 if (TextOutModeMap == NULL) {
2126 return EFI_OUT_OF_RESOURCES;
2129 SetMem (TextOutModeMap, TotalSize, 0xFF);
2130 Private->TextOutModeMap = TextOutModeMap;
2133 // If TextOutList has been enlarged, need to realloc the mode map table
2134 // The mode map table is regarded as a two dimension array.
2136 // Old New
2137 // 0 ---------> TextOutListCount ----> TextOutListCount
2138 // | -------------------------------------------
2139 // | | | |
2140 // | | | |
2141 // | | | |
2142 // | | | |
2143 // | | | |
2144 // \/ | | |
2145 // -------------------------------------------
2146 // QueryDataCount
2148 if (OldTextOutModeMap != NULL) {
2150 Size = Private->CurrentNumberOfConsoles * sizeof (INT32);
2151 Index = 0;
2152 SrcAddress = OldTextOutModeMap;
2155 // Copy the old data to the new one
2157 while (Index < Private->TextOutMode.MaxMode) {
2158 CopyMem (TextOutModeMap, SrcAddress, Size);
2159 TextOutModeMap += NewSize;
2160 SrcAddress += Size;
2161 Index++;
2164 // Free the old buffer
2166 FreePool (OldTextOutModeMap);
2169 return EFI_SUCCESS;
2174 Add new device's output mode to console splitter's mode list.
2176 @param Private Text Out Splitter pointer
2177 @param TextOut Simple Text Output protocol pointer.
2179 @retval EFI_SUCCESS Device added successfully.
2180 @retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
2183 EFI_STATUS
2184 ConSplitterAddOutputMode (
2185 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
2186 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut
2189 EFI_STATUS Status;
2190 INT32 MaxMode;
2191 INT32 Mode;
2192 UINTN Index;
2194 MaxMode = TextOut->Mode->MaxMode;
2195 Private->TextOutMode.MaxMode = MaxMode;
2198 // Grow the buffer if query data buffer is not large enough to
2199 // hold all the mode supported by the first console.
2201 while (MaxMode > (INT32) Private->TextOutQueryDataCount) {
2202 Status = ConSplitterGrowBuffer (
2203 sizeof (TEXT_OUT_SPLITTER_QUERY_DATA),
2204 &Private->TextOutQueryDataCount,
2205 (VOID **) &Private->TextOutQueryData
2207 if (EFI_ERROR (Status)) {
2208 return EFI_OUT_OF_RESOURCES;
2212 // Allocate buffer for the output mode map
2214 Status = ConSplitterGrowMapTable (Private);
2215 if (EFI_ERROR (Status)) {
2216 return EFI_OUT_OF_RESOURCES;
2219 // As the first textout device, directly add the mode in to QueryData
2220 // and at the same time record the mapping between QueryData and TextOut.
2222 Mode = 0;
2223 Index = 0;
2224 while (Mode < MaxMode) {
2225 Status = TextOut->QueryMode (
2226 TextOut,
2227 Mode,
2228 &Private->TextOutQueryData[Mode].Columns,
2229 &Private->TextOutQueryData[Mode].Rows
2232 // If mode 1 (80x50) is not supported, make sure mode 1 in TextOutQueryData
2233 // is clear to 0x0.
2235 if ((EFI_ERROR(Status)) && (Mode == 1)) {
2236 Private->TextOutQueryData[Mode].Columns = 0;
2237 Private->TextOutQueryData[Mode].Rows = 0;
2239 Private->TextOutModeMap[Index] = Mode;
2240 Mode++;
2241 Index += Private->TextOutListCount;
2244 return EFI_SUCCESS;
2248 Reconstruct TextOutModeMap to get intersection of modes.
2250 This routine reconstruct TextOutModeMap to get the intersection
2251 of modes for all console out devices. Because EFI/UEFI spec require
2252 mode 0 is 80x25, mode 1 is 80x50, this routine will not check the
2253 intersection for mode 0 and mode 1.
2255 @param TextOutModeMap Current text out mode map, begin with the mode 80x25
2256 @param NewlyAddedMap New text out mode map, begin with the mode 80x25
2257 @param MapStepSize Mode step size for one console device
2258 @param NewMapStepSize New Mode step size for one console device
2259 @param MaxMode IN: Current max text mode, OUT: Updated max text mode.
2260 @param CurrentMode IN: Current text mode, OUT: Updated current text mode.
2263 VOID
2264 ConSplitterGetIntersection (
2265 IN INT32 *TextOutModeMap,
2266 IN INT32 *NewlyAddedMap,
2267 IN UINTN MapStepSize,
2268 IN UINTN NewMapStepSize,
2269 IN OUT INT32 *MaxMode,
2270 IN OUT INT32 *CurrentMode
2273 INT32 Index;
2274 INT32 *CurrentMapEntry;
2275 INT32 *NextMapEntry;
2276 INT32 *NewMapEntry;
2277 INT32 CurrentMaxMode;
2278 INT32 Mode;
2281 // According to EFI/UEFI spec, mode 0 and mode 1 have been reserved
2282 // for 80x25 and 80x50 in Simple Text Out protocol, so don't make intersection
2283 // for mode 0 and mode 1, mode number starts from 2.
2285 Index = 2;
2286 CurrentMapEntry = &TextOutModeMap[MapStepSize * 2];
2287 NextMapEntry = CurrentMapEntry;
2288 NewMapEntry = &NewlyAddedMap[NewMapStepSize * 2];
2290 CurrentMaxMode = *MaxMode;
2291 Mode = *CurrentMode;
2293 while (Index < CurrentMaxMode) {
2294 if (*NewMapEntry == -1) {
2296 // This mode is not supported any more. Remove it. Special care
2297 // must be taken as this remove will also affect current mode;
2299 if (Index == *CurrentMode) {
2300 Mode = -1;
2301 } else if (Index < *CurrentMode) {
2302 Mode--;
2304 (*MaxMode)--;
2305 } else {
2306 if (CurrentMapEntry != NextMapEntry) {
2307 CopyMem (NextMapEntry, CurrentMapEntry, MapStepSize * sizeof (INT32));
2310 NextMapEntry += MapStepSize;
2313 CurrentMapEntry += MapStepSize;
2314 NewMapEntry += NewMapStepSize;
2315 Index++;
2318 *CurrentMode = Mode;
2320 return ;
2324 Sync the device's output mode to console splitter's mode list.
2326 @param Private Text Out Splitter pointer.
2327 @param TextOut Simple Text Output protocol pointer.
2330 VOID
2331 ConSplitterSyncOutputMode (
2332 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
2333 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut
2336 INT32 CurrentMaxMode;
2337 INT32 Mode;
2338 INT32 Index;
2339 INT32 *TextOutModeMap;
2340 INT32 *MapTable;
2341 INT32 QueryMode;
2342 TEXT_OUT_SPLITTER_QUERY_DATA *TextOutQueryData;
2343 UINTN Rows;
2344 UINTN Columns;
2345 UINTN StepSize;
2346 EFI_STATUS Status;
2349 // Must make sure that current mode won't change even if mode number changes
2351 CurrentMaxMode = Private->TextOutMode.MaxMode;
2352 TextOutModeMap = Private->TextOutModeMap;
2353 StepSize = Private->TextOutListCount;
2354 TextOutQueryData = Private->TextOutQueryData;
2357 // Query all the mode that the newly added TextOut supports
2359 Mode = 0;
2360 MapTable = TextOutModeMap + Private->CurrentNumberOfConsoles;
2361 while (Mode < TextOut->Mode->MaxMode) {
2362 Status = TextOut->QueryMode (TextOut, Mode, &Columns, &Rows);
2364 if (EFI_ERROR(Status)) {
2365 if (Mode == 1) {
2367 // If mode 1 (80x50) is not supported, make sure mode 1 in TextOutQueryData
2368 // is clear to 0x0.
2370 MapTable[StepSize] = Mode;
2371 TextOutQueryData[Mode].Columns = 0;
2372 TextOutQueryData[Mode].Rows = 0;
2374 Mode++;
2375 continue;
2378 // Search the intersection map and QueryData database to see if they intersects
2380 Index = 0;
2381 while (Index < CurrentMaxMode) {
2382 QueryMode = *(TextOutModeMap + Index * StepSize);
2383 if ((TextOutQueryData[QueryMode].Rows == Rows) && (TextOutQueryData[QueryMode].Columns == Columns)) {
2384 MapTable[Index * StepSize] = Mode;
2385 break;
2387 Index++;
2389 Mode++;
2392 // Now search the TextOutModeMap table to find the intersection of supported
2393 // mode between ConSplitter and the newly added device.
2395 ConSplitterGetIntersection (
2396 TextOutModeMap,
2397 MapTable,
2398 StepSize,
2399 StepSize,
2400 &Private->TextOutMode.MaxMode,
2401 &Private->TextOutMode.Mode
2404 return ;
2409 Sync output device between ConOut and StdErr output.
2411 @retval EFI_SUCCESS Sync implemented successfully.
2412 @retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
2415 EFI_STATUS
2416 ConSplitterGetIntersectionBetweenConOutAndStrErr (
2417 VOID
2420 UINTN ConOutNumOfConsoles;
2421 UINTN StdErrNumOfConsoles;
2422 TEXT_OUT_AND_GOP_DATA *ConOutTextOutList;
2423 TEXT_OUT_AND_GOP_DATA *StdErrTextOutList;
2424 UINTN Indexi;
2425 UINTN Indexj;
2426 UINTN ConOutRows;
2427 UINTN ConOutColumns;
2428 UINTN StdErrRows;
2429 UINTN StdErrColumns;
2430 INT32 ConOutMaxMode;
2431 INT32 StdErrMaxMode;
2432 INT32 ConOutMode;
2433 INT32 StdErrMode;
2434 INT32 Mode;
2435 INT32 Index;
2436 INT32 *ConOutModeMap;
2437 INT32 *StdErrModeMap;
2438 INT32 *ConOutMapTable;
2439 INT32 *StdErrMapTable;
2440 TEXT_OUT_SPLITTER_QUERY_DATA *ConOutQueryData;
2441 TEXT_OUT_SPLITTER_QUERY_DATA *StdErrQueryData;
2442 UINTN ConOutStepSize;
2443 UINTN StdErrStepSize;
2444 BOOLEAN FoundTheSameTextOut;
2445 UINTN ConOutMapTableSize;
2446 UINTN StdErrMapTableSize;
2448 ConOutNumOfConsoles = mConOut.CurrentNumberOfConsoles;
2449 StdErrNumOfConsoles = mStdErr.CurrentNumberOfConsoles;
2450 ConOutTextOutList = mConOut.TextOutList;
2451 StdErrTextOutList = mStdErr.TextOutList;
2453 Indexi = 0;
2454 FoundTheSameTextOut = FALSE;
2455 while ((Indexi < ConOutNumOfConsoles) && (!FoundTheSameTextOut)) {
2456 Indexj = 0;
2457 while (Indexj < StdErrNumOfConsoles) {
2458 if (ConOutTextOutList->TextOut == StdErrTextOutList->TextOut) {
2459 FoundTheSameTextOut = TRUE;
2460 break;
2463 Indexj++;
2464 StdErrTextOutList++;
2467 Indexi++;
2468 ConOutTextOutList++;
2471 if (!FoundTheSameTextOut) {
2472 return EFI_SUCCESS;
2475 // Must make sure that current mode won't change even if mode number changes
2477 ConOutMaxMode = mConOut.TextOutMode.MaxMode;
2478 ConOutModeMap = mConOut.TextOutModeMap;
2479 ConOutStepSize = mConOut.TextOutListCount;
2480 ConOutQueryData = mConOut.TextOutQueryData;
2482 StdErrMaxMode = mStdErr.TextOutMode.MaxMode;
2483 StdErrModeMap = mStdErr.TextOutModeMap;
2484 StdErrStepSize = mStdErr.TextOutListCount;
2485 StdErrQueryData = mStdErr.TextOutQueryData;
2488 // Allocate the map table and set the map table's index to -1.
2490 ConOutMapTableSize = ConOutMaxMode * sizeof (INT32);
2491 ConOutMapTable = AllocateZeroPool (ConOutMapTableSize);
2492 if (ConOutMapTable == NULL) {
2493 return EFI_OUT_OF_RESOURCES;
2496 SetMem (ConOutMapTable, ConOutMapTableSize, 0xFF);
2498 StdErrMapTableSize = StdErrMaxMode * sizeof (INT32);
2499 StdErrMapTable = AllocateZeroPool (StdErrMapTableSize);
2500 if (StdErrMapTable == NULL) {
2501 return EFI_OUT_OF_RESOURCES;
2504 SetMem (StdErrMapTable, StdErrMapTableSize, 0xFF);
2507 // Find the intersection of the two set of modes. If they actually intersect, the
2508 // correponding entry in the map table is set to 1.
2510 Mode = 0;
2511 while (Mode < ConOutMaxMode) {
2513 // Search the intersection map and QueryData database to see if they intersect
2515 Index = 0;
2516 ConOutMode = *(ConOutModeMap + Mode * ConOutStepSize);
2517 ConOutRows = ConOutQueryData[ConOutMode].Rows;
2518 ConOutColumns = ConOutQueryData[ConOutMode].Columns;
2519 while (Index < StdErrMaxMode) {
2520 StdErrMode = *(StdErrModeMap + Index * StdErrStepSize);
2521 StdErrRows = StdErrQueryData[StdErrMode].Rows;
2522 StdErrColumns = StdErrQueryData[StdErrMode].Columns;
2523 if ((StdErrRows == ConOutRows) && (StdErrColumns == ConOutColumns)) {
2524 ConOutMapTable[Mode] = 1;
2525 StdErrMapTable[Index] = 1;
2526 break;
2529 Index++;
2532 Mode++;
2535 // Now search the TextOutModeMap table to find the intersection of supported
2536 // mode between ConSplitter and the newly added device.
2538 ConSplitterGetIntersection (
2539 ConOutModeMap,
2540 ConOutMapTable,
2541 mConOut.TextOutListCount,
2543 &(mConOut.TextOutMode.MaxMode),
2544 &(mConOut.TextOutMode.Mode)
2547 if (mConOut.TextOutMode.Mode < 0) {
2548 mConOut.TextOut.SetMode (&(mConOut.TextOut), 0);
2551 ConSplitterGetIntersection (
2552 StdErrModeMap,
2553 StdErrMapTable,
2554 mStdErr.TextOutListCount,
2556 &(mStdErr.TextOutMode.MaxMode),
2557 &(mStdErr.TextOutMode.Mode)
2560 if (mStdErr.TextOutMode.Mode < 0) {
2561 mStdErr.TextOut.SetMode (&(mStdErr.TextOut), 0);
2564 FreePool (ConOutMapTable);
2565 FreePool (StdErrMapTable);
2567 return EFI_SUCCESS;
2572 Add Grahpics Output modes into Consplitter Text Out list.
2574 @param Private Text Out Splitter pointer.
2575 @param GraphicsOutput Graphics Output protocol pointer.
2576 @param UgaDraw UGA Draw protocol pointer.
2578 @retval EFI_SUCCESS Output mode added successfully.
2579 @retval other Failed to add output mode.
2582 EFI_STATUS
2583 ConSplitterAddGraphicsOutputMode (
2584 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
2585 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput,
2586 IN EFI_UGA_DRAW_PROTOCOL *UgaDraw
2589 EFI_STATUS Status;
2590 UINTN Index;
2591 UINTN CurrentIndex;
2592 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Mode;
2593 UINTN SizeOfInfo;
2594 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
2595 EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *CurrentGraphicsOutputMode;
2596 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *ModeBuffer;
2597 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *MatchedMode;
2598 UINTN NumberIndex;
2599 BOOLEAN Match;
2600 BOOLEAN AlreadyExist;
2601 UINT32 UgaHorizontalResolution;
2602 UINT32 UgaVerticalResolution;
2603 UINT32 UgaColorDepth;
2604 UINT32 UgaRefreshRate;
2606 ASSERT (GraphicsOutput != NULL || UgaDraw != NULL);
2608 CurrentGraphicsOutputMode = Private->GraphicsOutput.Mode;
2610 Index = 0;
2611 CurrentIndex = 0;
2613 if (Private->CurrentNumberOfUgaDraw != 0) {
2615 // If any UGA device has already been added, then there is no need to
2616 // calculate intersection of display mode of different GOP/UGA device,
2617 // since only one display mode will be exported (i.e. user-defined mode)
2619 goto Done;
2622 if (GraphicsOutput != NULL) {
2623 if (Private->CurrentNumberOfGraphicsOutput == 0) {
2625 // This is the first Graphics Output device added
2627 CurrentGraphicsOutputMode->MaxMode = GraphicsOutput->Mode->MaxMode;
2628 CurrentGraphicsOutputMode->Mode = GraphicsOutput->Mode->Mode;
2629 CopyMem (CurrentGraphicsOutputMode->Info, GraphicsOutput->Mode->Info, GraphicsOutput->Mode->SizeOfInfo);
2630 CurrentGraphicsOutputMode->SizeOfInfo = GraphicsOutput->Mode->SizeOfInfo;
2631 CurrentGraphicsOutputMode->FrameBufferBase = GraphicsOutput->Mode->FrameBufferBase;
2632 CurrentGraphicsOutputMode->FrameBufferSize = GraphicsOutput->Mode->FrameBufferSize;
2635 // Allocate resource for the private mode buffer
2637 ModeBuffer = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION) * GraphicsOutput->Mode->MaxMode);
2638 if (ModeBuffer == NULL) {
2639 return EFI_OUT_OF_RESOURCES;
2641 FreePool (Private->GraphicsOutputModeBuffer);
2642 Private->GraphicsOutputModeBuffer = ModeBuffer;
2645 // Store all supported display modes to the private mode buffer
2647 Mode = ModeBuffer;
2648 for (Index = 0; Index < GraphicsOutput->Mode->MaxMode; Index++) {
2650 // The Info buffer would be allocated by callee
2652 Status = GraphicsOutput->QueryMode (GraphicsOutput, (UINT32) Index, &SizeOfInfo, &Info);
2653 if (EFI_ERROR (Status)) {
2654 return Status;
2656 ASSERT ( SizeOfInfo <= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
2657 CopyMem (Mode, Info, SizeOfInfo);
2658 Mode++;
2659 FreePool (Info);
2661 } else {
2663 // Check intersection of display mode
2665 ModeBuffer = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION) * CurrentGraphicsOutputMode->MaxMode);
2666 if (ModeBuffer == NULL) {
2667 return EFI_OUT_OF_RESOURCES;
2670 MatchedMode = ModeBuffer;
2671 Mode = &Private->GraphicsOutputModeBuffer[0];
2672 for (Index = 0; Index < CurrentGraphicsOutputMode->MaxMode; Index++) {
2673 Match = FALSE;
2675 for (NumberIndex = 0; NumberIndex < GraphicsOutput->Mode->MaxMode; NumberIndex++) {
2677 // The Info buffer would be allocated by callee
2679 Status = GraphicsOutput->QueryMode (GraphicsOutput, (UINT32) NumberIndex, &SizeOfInfo, &Info);
2680 if (EFI_ERROR (Status)) {
2681 return Status;
2683 if ((Info->HorizontalResolution == Mode->HorizontalResolution) &&
2684 (Info->VerticalResolution == Mode->VerticalResolution)) {
2686 // If GOP device supports one mode in current mode buffer,
2687 // it will be added into matched mode buffer
2689 Match = TRUE;
2690 FreePool (Info);
2691 break;
2693 FreePool (Info);
2696 if (Match) {
2697 AlreadyExist = FALSE;
2700 // Check if GOP mode has been in the mode buffer, ModeBuffer = MatchedMode at begin.
2702 for (Info = ModeBuffer; Info < MatchedMode; Info++) {
2703 if ((Info->HorizontalResolution == Mode->HorizontalResolution) &&
2704 (Info->VerticalResolution == Mode->VerticalResolution)) {
2705 AlreadyExist = TRUE;
2706 break;
2710 if (!AlreadyExist) {
2711 CopyMem (MatchedMode, Mode, sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
2714 // Physical frame buffer is no longer available, change PixelFormat to PixelBltOnly
2716 MatchedMode->Version = 0;
2717 MatchedMode->PixelFormat = PixelBltOnly;
2718 ZeroMem (&MatchedMode->PixelInformation, sizeof (EFI_PIXEL_BITMASK));
2720 MatchedMode++;
2724 Mode++;
2728 // Drop the old mode buffer, assign it to a new one
2730 FreePool (Private->GraphicsOutputModeBuffer);
2731 Private->GraphicsOutputModeBuffer = ModeBuffer;
2734 // Physical frame buffer is no longer available when there are more than one physical GOP devices
2736 CurrentGraphicsOutputMode->MaxMode = (UINT32) (((UINTN) MatchedMode - (UINTN) ModeBuffer) / sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
2737 CurrentGraphicsOutputMode->Info->PixelFormat = PixelBltOnly;
2738 ZeroMem (&CurrentGraphicsOutputMode->Info->PixelInformation, sizeof (EFI_PIXEL_BITMASK));
2739 CurrentGraphicsOutputMode->SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
2740 CurrentGraphicsOutputMode->FrameBufferBase = (EFI_PHYSICAL_ADDRESS) (UINTN) NULL;
2741 CurrentGraphicsOutputMode->FrameBufferSize = 0;
2745 // Graphics console driver can ensure the same mode for all GOP devices
2747 for (Index = 0; Index < CurrentGraphicsOutputMode->MaxMode; Index++) {
2748 Mode = &Private->GraphicsOutputModeBuffer[Index];
2749 if ((Mode->HorizontalResolution == GraphicsOutput->Mode->Info->HorizontalResolution) &&
2750 (Mode->VerticalResolution == GraphicsOutput->Mode->Info->VerticalResolution)) {
2751 CurrentIndex = Index;
2752 break;
2755 if (Index >= CurrentGraphicsOutputMode->MaxMode) {
2757 // if user defined mode is not found, set to default mode 800x600
2759 for (Index = 0; Index < CurrentGraphicsOutputMode->MaxMode; Index++) {
2760 Mode = &Private->GraphicsOutputModeBuffer[Index];
2761 if ((Mode->HorizontalResolution == 800) && (Mode->VerticalResolution == 600)) {
2762 CurrentIndex = Index;
2763 break;
2767 } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {
2769 // Graphics console driver can ensure the same mode for all GOP devices
2770 // so we can get the current mode from this video device
2772 UgaDraw->GetMode (
2773 UgaDraw,
2774 &UgaHorizontalResolution,
2775 &UgaVerticalResolution,
2776 &UgaColorDepth,
2777 &UgaRefreshRate
2780 CurrentGraphicsOutputMode->MaxMode = 1;
2781 Info = CurrentGraphicsOutputMode->Info;
2782 Info->Version = 0;
2783 Info->HorizontalResolution = UgaHorizontalResolution;
2784 Info->VerticalResolution = UgaVerticalResolution;
2785 Info->PixelFormat = PixelBltOnly;
2786 Info->PixelsPerScanLine = UgaHorizontalResolution;
2787 CurrentGraphicsOutputMode->SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
2788 CurrentGraphicsOutputMode->FrameBufferBase = (EFI_PHYSICAL_ADDRESS) (UINTN) NULL;
2789 CurrentGraphicsOutputMode->FrameBufferSize = 0;
2792 // Update the private mode buffer
2794 CopyMem (&Private->GraphicsOutputModeBuffer[0], Info, sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
2797 // Only mode 0 is available to be set
2799 CurrentIndex = 0;
2802 Done:
2804 if (GraphicsOutput != NULL) {
2805 Private->CurrentNumberOfGraphicsOutput++;
2807 if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {
2808 Private->CurrentNumberOfUgaDraw++;
2812 // Force GraphicsOutput mode to be set,
2813 // regardless whether the console is in EfiConsoleControlScreenGraphics or EfiConsoleControlScreenText mode
2815 Private->HardwareNeedsStarting = TRUE;
2817 // Current mode number may need update now, so set it to an invalid mode number
2819 CurrentGraphicsOutputMode->Mode = 0xffff;
2821 // Graphics console can ensure all GOP devices have the same mode which can be taken as current mode.
2823 Status = Private->GraphicsOutput.SetMode (&Private->GraphicsOutput, (UINT32) CurrentIndex);
2824 if (EFI_ERROR(Status)) {
2826 // If user defined mode is not valid for display device, set to the default mode 800x600.
2828 (Private->GraphicsOutputModeBuffer[0]).HorizontalResolution = 800;
2829 (Private->GraphicsOutputModeBuffer[0]).VerticalResolution = 600;
2830 Status = Private->GraphicsOutput.SetMode (&Private->GraphicsOutput, 0);
2833 return Status;
2837 Set the current console out mode.
2839 This routine will get the current console mode information (column, row)
2840 from ConsoleOutMode variable and set it; if the variable does not exist,
2841 set to user defined console mode.
2843 @param Private Consplitter Text Out pointer.
2846 VOID
2847 ConsplitterSetConsoleOutMode (
2848 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private
2851 UINTN Col;
2852 UINTN Row;
2853 UINTN Mode;
2854 UINTN PreferMode;
2855 UINTN BaseMode;
2856 UINTN MaxMode;
2857 EFI_STATUS Status;
2858 CONSOLE_OUT_MODE ModeInfo;
2859 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut;
2861 PreferMode = 0xFF;
2862 BaseMode = 0xFF;
2863 TextOut = &Private->TextOut;
2864 MaxMode = (UINTN) (TextOut->Mode->MaxMode);
2866 ModeInfo.Column = PcdGet32 (PcdConOutColumn);
2867 ModeInfo.Row = PcdGet32 (PcdConOutRow);
2870 // To find the prefer mode and basic mode from Text Out mode list
2872 for (Mode = 0; Mode < MaxMode; Mode++) {
2873 Status = TextOut->QueryMode (TextOut, Mode, &Col, &Row);
2874 if (!EFI_ERROR(Status)) {
2875 if (Col == ModeInfo.Column && Row == ModeInfo.Row) {
2876 PreferMode = Mode;
2878 if (Col == 80 && Row == 25) {
2879 BaseMode = Mode;
2885 // Set prefer mode to Text Out devices.
2887 Status = TextOut->SetMode (TextOut, PreferMode);
2888 if (EFI_ERROR(Status)) {
2890 // if current mode setting is failed, default 80x25 mode will be set.
2892 Status = TextOut->SetMode (TextOut, BaseMode);
2893 ASSERT(!EFI_ERROR(Status));
2895 PcdSet32 (PcdConOutColumn, 80);
2896 PcdSet32 (PcdConOutRow, 25);
2899 return ;
2904 Add Text Output Device in Consplitter Text Output list.
2906 @param Private Text Out Splitter pointer.
2907 @param TextOut Simple Text Output protocol pointer.
2908 @param GraphicsOutput Graphics Output protocol pointer.
2909 @param UgaDraw UGA Draw protocol pointer.
2911 @retval EFI_SUCCESS Text Output Device added successfully.
2912 @retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
2915 EFI_STATUS
2916 ConSplitterTextOutAddDevice (
2917 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
2918 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut,
2919 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput,
2920 IN EFI_UGA_DRAW_PROTOCOL *UgaDraw
2923 EFI_STATUS Status;
2924 UINTN CurrentNumOfConsoles;
2925 INT32 MaxMode;
2926 UINT32 UgaHorizontalResolution;
2927 UINT32 UgaVerticalResolution;
2928 UINT32 UgaColorDepth;
2929 UINT32 UgaRefreshRate;
2930 TEXT_OUT_AND_GOP_DATA *TextAndGop;
2931 UINTN SizeOfInfo;
2932 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
2934 Status = EFI_SUCCESS;
2935 CurrentNumOfConsoles = Private->CurrentNumberOfConsoles;
2938 // If the Text Out List is full, enlarge it by calling ConSplitterGrowBuffer().
2940 while (CurrentNumOfConsoles >= Private->TextOutListCount) {
2941 Status = ConSplitterGrowBuffer (
2942 sizeof (TEXT_OUT_AND_GOP_DATA),
2943 &Private->TextOutListCount,
2944 (VOID **) &Private->TextOutList
2946 if (EFI_ERROR (Status)) {
2947 return EFI_OUT_OF_RESOURCES;
2950 // Also need to reallocate the TextOutModeMap table
2952 Status = ConSplitterGrowMapTable (Private);
2953 if (EFI_ERROR (Status)) {
2954 return EFI_OUT_OF_RESOURCES;
2958 TextAndGop = &Private->TextOutList[CurrentNumOfConsoles];
2960 TextAndGop->TextOut = TextOut;
2961 TextAndGop->GraphicsOutput = GraphicsOutput;
2962 TextAndGop->UgaDraw = UgaDraw;
2964 if (CurrentNumOfConsoles == 0) {
2966 // Add the first device's output mode to console splitter's mode list
2968 Status = ConSplitterAddOutputMode (Private, TextOut);
2969 } else {
2970 ConSplitterSyncOutputMode (Private, TextOut);
2973 Private->CurrentNumberOfConsoles++;
2976 // Scan both TextOutList, for the intersection TextOut device
2977 // maybe both ConOut and StdErr incorporate the same Text Out
2978 // device in them, thus the output of both should be synced.
2980 ConSplitterGetIntersectionBetweenConOutAndStrErr ();
2982 MaxMode = Private->TextOutMode.MaxMode;
2983 ASSERT (MaxMode >= 1);
2985 if (FeaturePcdGet (PcdConOutGopSupport)) {
2987 // If GOP is produced by Consplitter, this device display mode will be added into Graphics Ouput modes.
2989 if ((GraphicsOutput != NULL) || (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport))) {
2990 ConSplitterAddGraphicsOutputMode (Private, GraphicsOutput, UgaDraw);
2994 if (FeaturePcdGet (PcdConOutUgaSupport)) {
2995 UgaHorizontalResolution = 800;
2996 UgaVerticalResolution = 600;
2997 UgaColorDepth = 32;
2998 UgaRefreshRate = 60;
3000 Status = EFI_DEVICE_ERROR;
3002 // If UGA is produced by Consplitter
3004 if (GraphicsOutput != NULL) {
3005 Status = GraphicsOutput->QueryMode (GraphicsOutput, GraphicsOutput->Mode->Mode, &SizeOfInfo, &Info);
3006 if (EFI_ERROR (Status)) {
3007 return Status;
3009 ASSERT ( SizeOfInfo <= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
3011 UgaHorizontalResolution = Info->HorizontalResolution;
3012 UgaVerticalResolution = Info->VerticalResolution;
3014 FreePool (Info);
3016 } else if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {
3017 Status = UgaDraw->GetMode (
3018 UgaDraw,
3019 &UgaHorizontalResolution,
3020 &UgaVerticalResolution,
3021 &UgaColorDepth,
3022 &UgaRefreshRate
3027 // Set UGA Draw mode,
3028 // if GetMode is failed, set to 800x600 mode
3030 Status = ConSpliterUgaDrawSetMode (
3031 &Private->UgaDraw,
3032 UgaHorizontalResolution,
3033 UgaVerticalResolution,
3034 UgaColorDepth,
3035 UgaRefreshRate
3040 // If ConOut, then set the mode to Mode #0 which us 80 x 25
3042 Private->TextOut.SetMode (&Private->TextOut, 0);
3045 // After adding new console device, all existing console devices should be
3046 // synced to the current shared mode.
3048 ConsplitterSetConsoleOutMode (Private);
3050 return Status;
3055 Remove Text Out Device in Consplitter Text Out list.
3057 @param Private Text Out Splitter pointer.
3058 @param TextOut Simple Text Output Pointer protocol pointer.
3060 @retval EFI_SUCCESS Text Out Device removed successfully.
3061 @retval EFI_NOT_FOUND No Text Out Device found.
3064 EFI_STATUS
3065 ConSplitterTextOutDeleteDevice (
3066 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
3067 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut
3070 INT32 Index;
3071 UINTN CurrentNumOfConsoles;
3072 TEXT_OUT_AND_GOP_DATA *TextOutList;
3073 EFI_STATUS Status;
3076 // Remove the specified text-out device data structure from the Text out List,
3077 // and rearrange the remaining data structures in the Text out List.
3079 CurrentNumOfConsoles = Private->CurrentNumberOfConsoles;
3080 Index = (INT32) CurrentNumOfConsoles - 1;
3081 TextOutList = Private->TextOutList;
3082 while (Index >= 0) {
3083 if (TextOutList->TextOut == TextOut) {
3084 CopyMem (TextOutList, TextOutList + 1, sizeof (TEXT_OUT_AND_GOP_DATA) * Index);
3085 CurrentNumOfConsoles--;
3086 if (TextOutList->UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {
3087 Private->CurrentNumberOfUgaDraw--;
3089 if (TextOutList->GraphicsOutput != NULL) {
3090 Private->CurrentNumberOfGraphicsOutput--;
3092 break;
3095 Index--;
3096 TextOutList++;
3099 // The specified TextOut is not managed by the ConSplitter driver
3101 if (Index < 0) {
3102 return EFI_NOT_FOUND;
3105 if (CurrentNumOfConsoles == 0) {
3107 // If the number of consoles is zero, reset all parameters
3109 Private->CurrentNumberOfConsoles = 0;
3110 Private->TextOutMode.MaxMode = 1;
3111 Private->TextOutQueryData[0].Columns = 80;
3112 Private->TextOutQueryData[0].Rows = 25;
3113 TextOutSetMode (Private, 0);
3115 return EFI_SUCCESS;
3118 // Max Mode is realy an intersection of the QueryMode command to all
3119 // devices. So we must copy the QueryMode of the first device to
3120 // QueryData.
3122 ZeroMem (
3123 Private->TextOutQueryData,
3124 Private->TextOutQueryDataCount * sizeof (TEXT_OUT_SPLITTER_QUERY_DATA)
3127 FreePool (Private->TextOutModeMap);
3128 Private->TextOutModeMap = NULL;
3129 TextOutList = Private->TextOutList;
3132 // Add the first TextOut to the QueryData array and ModeMap table
3134 Status = ConSplitterAddOutputMode (Private, TextOutList->TextOut);
3137 // Now add one by one
3139 Index = 1;
3140 Private->CurrentNumberOfConsoles = 1;
3141 TextOutList++;
3142 while ((UINTN) Index < CurrentNumOfConsoles) {
3143 ConSplitterSyncOutputMode (Private, TextOutList->TextOut);
3144 Index++;
3145 Private->CurrentNumberOfConsoles++;
3146 TextOutList++;
3149 ConSplitterGetIntersectionBetweenConOutAndStrErr ();
3151 return Status;
3156 Reset the input device and optionaly run diagnostics
3158 @param This Protocol instance pointer.
3159 @param ExtendedVerification Driver may perform diagnostics on reset.
3161 @retval EFI_SUCCESS The device was reset.
3162 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
3163 not be reset.
3166 EFI_STATUS
3167 EFIAPI
3168 ConSplitterTextInReset (
3169 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
3170 IN BOOLEAN ExtendedVerification
3173 EFI_STATUS Status;
3174 EFI_STATUS ReturnStatus;
3175 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3176 UINTN Index;
3178 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3180 Private->KeyEventSignalState = FALSE;
3183 // return the worst status met
3185 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
3186 Status = Private->TextInList[Index]->Reset (
3187 Private->TextInList[Index],
3188 ExtendedVerification
3190 if (EFI_ERROR (Status)) {
3191 ReturnStatus = Status;
3195 return ReturnStatus;
3200 Reads the next keystroke from the input device. The WaitForKey Event can
3201 be used to test for existance of a keystroke via WaitForEvent () call.
3203 @param Private Protocol instance pointer.
3204 @param Key Driver may perform diagnostics on reset.
3206 @retval EFI_SUCCESS The keystroke information was returned.
3207 @retval EFI_NOT_READY There was no keystroke data availiable.
3208 @retval EFI_DEVICE_ERROR The keydtroke information was not returned due
3209 to hardware errors.
3212 EFI_STATUS
3213 EFIAPI
3214 ConSplitterTextInPrivateReadKeyStroke (
3215 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
3216 OUT EFI_INPUT_KEY *Key
3219 EFI_STATUS Status;
3220 UINTN Index;
3221 EFI_INPUT_KEY CurrentKey;
3223 Key->UnicodeChar = 0;
3224 Key->ScanCode = SCAN_NULL;
3227 // if no physical console input device exists, return EFI_NOT_READY;
3228 // if any physical console input device has key input,
3229 // return the key and EFI_SUCCESS.
3231 for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {
3232 Status = Private->TextInList[Index]->ReadKeyStroke (
3233 Private->TextInList[Index],
3234 &CurrentKey
3236 if (!EFI_ERROR (Status)) {
3237 *Key = CurrentKey;
3238 return Status;
3242 return EFI_NOT_READY;
3247 Reads the next keystroke from the input device. The WaitForKey Event can
3248 be used to test for existance of a keystroke via WaitForEvent () call.
3250 @param This Protocol instance pointer.
3251 @param Key Driver may perform diagnostics on reset.
3253 @retval EFI_SUCCESS The keystroke information was returned.
3254 @retval EFI_NOT_READY There was no keystroke data availiable.
3255 @retval EFI_DEVICE_ERROR The keydtroke information was not returned due
3256 to hardware errors.
3259 EFI_STATUS
3260 EFIAPI
3261 ConSplitterTextInReadKeyStroke (
3262 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
3263 OUT EFI_INPUT_KEY *Key
3266 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3268 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3270 Private->KeyEventSignalState = FALSE;
3272 return ConSplitterTextInPrivateReadKeyStroke (Private, Key);
3277 This event aggregates all the events of the ConIn devices in the spliter.
3279 If any events of physical ConIn devices are signaled, signal the ConIn
3280 spliter event. This will cause the calling code to call
3281 ConSplitterTextInReadKeyStroke ().
3283 @param Event The Event assoicated with callback.
3284 @param Context Context registered when Event was created.
3287 VOID
3288 EFIAPI
3289 ConSplitterTextInWaitForKey (
3290 IN EFI_EVENT Event,
3291 IN VOID *Context
3294 EFI_STATUS Status;
3295 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3296 UINTN Index;
3298 Private = (TEXT_IN_SPLITTER_PRIVATE_DATA *) Context;
3300 if (Private->KeyEventSignalState) {
3302 // If KeyEventSignalState is flagged before, and not cleared by Reset() or ReadKeyStroke()
3304 gBS->SignalEvent (Event);
3305 return ;
3309 // If any physical console input device has key input, signal the event.
3311 for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {
3312 Status = gBS->CheckEvent (Private->TextInList[Index]->WaitForKey);
3313 if (!EFI_ERROR (Status)) {
3314 gBS->SignalEvent (Event);
3315 Private->KeyEventSignalState = TRUE;
3323 Test if the key has been registered on input device.
3325 @param RegsiteredData A pointer to a buffer that is filled in with the
3326 keystroke state data for the key that was
3327 registered.
3328 @param InputData A pointer to a buffer that is filled in with the
3329 keystroke state data for the key that was
3330 pressed.
3332 @retval TRUE Key be pressed matches a registered key.
3333 @retval FLASE Match failed.
3336 BOOLEAN
3337 IsKeyRegistered (
3338 IN EFI_KEY_DATA *RegsiteredData,
3339 IN EFI_KEY_DATA *InputData
3342 ASSERT (RegsiteredData != NULL && InputData != NULL);
3344 if ((RegsiteredData->Key.ScanCode != InputData->Key.ScanCode) ||
3345 (RegsiteredData->Key.UnicodeChar != InputData->Key.UnicodeChar)) {
3346 return FALSE;
3350 // Assume KeyShiftState/KeyToggleState = 0 in Registered key data means these state could be ignored.
3352 if (RegsiteredData->KeyState.KeyShiftState != 0 &&
3353 RegsiteredData->KeyState.KeyShiftState != InputData->KeyState.KeyShiftState) {
3354 return FALSE;
3356 if (RegsiteredData->KeyState.KeyToggleState != 0 &&
3357 RegsiteredData->KeyState.KeyToggleState != InputData->KeyState.KeyToggleState) {
3358 return FALSE;
3361 return TRUE;
3367 Reset the input device and optionaly run diagnostics
3369 @param This Protocol instance pointer.
3370 @param ExtendedVerification Driver may perform diagnostics on reset.
3372 @retval EFI_SUCCESS The device was reset.
3373 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
3374 not be reset.
3377 EFI_STATUS
3378 EFIAPI
3379 ConSplitterTextInResetEx (
3380 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
3381 IN BOOLEAN ExtendedVerification
3384 EFI_STATUS Status;
3385 EFI_STATUS ReturnStatus;
3386 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3387 UINTN Index;
3389 Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3391 Private->KeyEventSignalState = FALSE;
3394 // return the worst status met
3396 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfExConsoles; Index++) {
3397 Status = Private->TextInExList[Index]->Reset (
3398 Private->TextInExList[Index],
3399 ExtendedVerification
3401 if (EFI_ERROR (Status)) {
3402 ReturnStatus = Status;
3406 return ReturnStatus;
3412 Reads the next keystroke from the input device. The WaitForKey Event can
3413 be used to test for existance of a keystroke via WaitForEvent () call.
3415 @param This Protocol instance pointer.
3416 @param KeyData A pointer to a buffer that is filled in with the
3417 keystroke state data for the key that was
3418 pressed.
3420 @retval EFI_SUCCESS The keystroke information was returned.
3421 @retval EFI_NOT_READY There was no keystroke data availiable.
3422 @retval EFI_DEVICE_ERROR The keystroke information was not returned due
3423 to hardware errors.
3424 @retval EFI_INVALID_PARAMETER KeyData is NULL.
3427 EFI_STATUS
3428 EFIAPI
3429 ConSplitterTextInReadKeyStrokeEx (
3430 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
3431 OUT EFI_KEY_DATA *KeyData
3434 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3435 EFI_STATUS Status;
3436 UINTN Index;
3437 EFI_KEY_DATA CurrentKeyData;
3440 if (KeyData == NULL) {
3441 return EFI_INVALID_PARAMETER;
3444 Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3446 Private->KeyEventSignalState = FALSE;
3448 KeyData->Key.UnicodeChar = 0;
3449 KeyData->Key.ScanCode = SCAN_NULL;
3452 // if no physical console input device exists, return EFI_NOT_READY;
3453 // if any physical console input device has key input,
3454 // return the key and EFI_SUCCESS.
3456 for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {
3457 Status = Private->TextInExList[Index]->ReadKeyStrokeEx (
3458 Private->TextInExList[Index],
3459 &CurrentKeyData
3461 if (!EFI_ERROR (Status)) {
3462 CopyMem (KeyData, &CurrentKeyData, sizeof (CurrentKeyData));
3463 return Status;
3467 return EFI_NOT_READY;
3472 Set certain state for the input device.
3474 @param This Protocol instance pointer.
3475 @param KeyToggleState A pointer to the EFI_KEY_TOGGLE_STATE to set the
3476 state for the input device.
3478 @retval EFI_SUCCESS The device state was set successfully.
3479 @retval EFI_DEVICE_ERROR The device is not functioning correctly and
3480 could not have the setting adjusted.
3481 @retval EFI_UNSUPPORTED The device does not have the ability to set its
3482 state.
3483 @retval EFI_INVALID_PARAMETER KeyToggleState is NULL.
3486 EFI_STATUS
3487 EFIAPI
3488 ConSplitterTextInSetState (
3489 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
3490 IN EFI_KEY_TOGGLE_STATE *KeyToggleState
3493 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3494 EFI_STATUS Status;
3495 UINTN Index;
3497 if (KeyToggleState == NULL) {
3498 return EFI_INVALID_PARAMETER;
3501 Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3504 // if no physical console input device exists, return EFI_SUCCESS;
3505 // otherwise return the status of setting state of physical console input device
3507 for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {
3508 Status = Private->TextInExList[Index]->SetState (
3509 Private->TextInExList[Index],
3510 KeyToggleState
3512 if (EFI_ERROR (Status)) {
3513 return Status;
3517 return EFI_SUCCESS;
3523 Register a notification function for a particular keystroke for the input device.
3525 @param This Protocol instance pointer.
3526 @param KeyData A pointer to a buffer that is filled in with the
3527 keystroke information data for the key that was
3528 pressed.
3529 @param KeyNotificationFunction Points to the function to be called when the key
3530 sequence is typed specified by KeyData.
3531 @param NotifyHandle Points to the unique handle assigned to the
3532 registered notification.
3534 @retval EFI_SUCCESS The notification function was registered
3535 successfully.
3536 @retval EFI_OUT_OF_RESOURCES Unable to allocate resources for necesssary data
3537 structures.
3538 @retval EFI_INVALID_PARAMETER KeyData or KeyNotificationFunction or NotifyHandle is NULL.
3541 EFI_STATUS
3542 EFIAPI
3543 ConSplitterTextInRegisterKeyNotify (
3544 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
3545 IN EFI_KEY_DATA *KeyData,
3546 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction,
3547 OUT EFI_HANDLE *NotifyHandle
3550 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3551 EFI_STATUS Status;
3552 UINTN Index;
3553 TEXT_IN_EX_SPLITTER_NOTIFY *NewNotify;
3554 LIST_ENTRY *Link;
3555 TEXT_IN_EX_SPLITTER_NOTIFY *CurrentNotify;
3558 if (KeyData == NULL || NotifyHandle == NULL || KeyNotificationFunction == NULL) {
3559 return EFI_INVALID_PARAMETER;
3562 Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3565 // If no physical console input device exists,
3566 // return EFI_SUCCESS directly.
3568 if (Private->CurrentNumberOfExConsoles <= 0) {
3569 return EFI_SUCCESS;
3573 // Return EFI_SUCCESS if the (KeyData, NotificationFunction) is already registered.
3575 for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {
3576 CurrentNotify = TEXT_IN_EX_SPLITTER_NOTIFY_FROM_THIS (Link);
3577 if (IsKeyRegistered (&CurrentNotify->KeyData, KeyData)) {
3578 if (CurrentNotify->KeyNotificationFn == KeyNotificationFunction) {
3579 *NotifyHandle = CurrentNotify->NotifyHandle;
3580 return EFI_SUCCESS;
3586 // Allocate resource to save the notification function
3588 NewNotify = (TEXT_IN_EX_SPLITTER_NOTIFY *) AllocateZeroPool (sizeof (TEXT_IN_EX_SPLITTER_NOTIFY));
3589 if (NewNotify == NULL) {
3590 return EFI_OUT_OF_RESOURCES;
3592 NewNotify->NotifyHandleList = (EFI_HANDLE *) AllocateZeroPool (sizeof (EFI_HANDLE) * Private->CurrentNumberOfExConsoles);
3593 if (NewNotify->NotifyHandleList == NULL) {
3594 gBS->FreePool (NewNotify);
3595 return EFI_OUT_OF_RESOURCES;
3597 NewNotify->Signature = TEXT_IN_EX_SPLITTER_NOTIFY_SIGNATURE;
3598 NewNotify->KeyNotificationFn = KeyNotificationFunction;
3599 NewNotify->NotifyHandle = (EFI_HANDLE) NewNotify;
3600 CopyMem (&NewNotify->KeyData, KeyData, sizeof (KeyData));
3603 // Return the wrong status of registering key notify of
3604 // physical console input device if meet problems
3606 for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {
3607 Status = Private->TextInExList[Index]->RegisterKeyNotify (
3608 Private->TextInExList[Index],
3609 KeyData,
3610 KeyNotificationFunction,
3611 &NewNotify->NotifyHandleList[Index]
3613 if (EFI_ERROR (Status)) {
3614 gBS->FreePool (NewNotify->NotifyHandleList);
3615 gBS->FreePool (NewNotify);
3616 return Status;
3620 InsertTailList (&mConIn.NotifyList, &NewNotify->NotifyEntry);
3622 *NotifyHandle = NewNotify->NotifyHandle;
3624 return EFI_SUCCESS;
3630 Remove a registered notification function from a particular keystroke.
3632 @param This Protocol instance pointer.
3633 @param NotificationHandle The handle of the notification function being
3634 unregistered.
3636 @retval EFI_SUCCESS The notification function was unregistered
3637 successfully.
3638 @retval EFI_INVALID_PARAMETER The NotificationHandle is invalid.
3639 @retval EFI_NOT_FOUND Can not find the matching entry in database.
3642 EFI_STATUS
3643 EFIAPI
3644 ConSplitterTextInUnregisterKeyNotify (
3645 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
3646 IN EFI_HANDLE NotificationHandle
3649 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3650 EFI_STATUS Status;
3651 UINTN Index;
3652 TEXT_IN_EX_SPLITTER_NOTIFY *CurrentNotify;
3653 LIST_ENTRY *Link;
3655 if (NotificationHandle == NULL) {
3656 return EFI_INVALID_PARAMETER;
3659 if (((TEXT_IN_EX_SPLITTER_NOTIFY *) NotificationHandle)->Signature != TEXT_IN_EX_SPLITTER_NOTIFY_SIGNATURE) {
3660 return EFI_INVALID_PARAMETER;
3663 Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3666 // if no physical console input device exists,
3667 // return EFI_SUCCESS directly.
3669 if (Private->CurrentNumberOfExConsoles <= 0) {
3670 return EFI_SUCCESS;
3673 for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {
3674 CurrentNotify = TEXT_IN_EX_SPLITTER_NOTIFY_FROM_THIS (Link);
3675 if (CurrentNotify->NotifyHandle == NotificationHandle) {
3676 for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {
3677 Status = Private->TextInExList[Index]->UnregisterKeyNotify (
3678 Private->TextInExList[Index],
3679 CurrentNotify->NotifyHandleList[Index]
3681 if (EFI_ERROR (Status)) {
3682 return Status;
3685 RemoveEntryList (&CurrentNotify->NotifyEntry);
3687 gBS->FreePool (CurrentNotify->NotifyHandleList);
3688 gBS->FreePool (CurrentNotify);
3689 return EFI_SUCCESS;
3693 return EFI_NOT_FOUND;
3699 Reset the input device and optionaly run diagnostics
3701 @param This Protocol instance pointer.
3702 @param ExtendedVerification Driver may perform diagnostics on reset.
3704 @retval EFI_SUCCESS The device was reset.
3705 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
3706 not be reset.
3709 EFI_STATUS
3710 EFIAPI
3711 ConSplitterSimplePointerReset (
3712 IN EFI_SIMPLE_POINTER_PROTOCOL *This,
3713 IN BOOLEAN ExtendedVerification
3716 EFI_STATUS Status;
3717 EFI_STATUS ReturnStatus;
3718 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3719 UINTN Index;
3721 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_SIMPLE_POINTER_THIS (This);
3723 Private->InputEventSignalState = FALSE;
3725 if (Private->CurrentNumberOfPointers == 0) {
3726 return EFI_SUCCESS;
3729 // return the worst status met
3731 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfPointers; Index++) {
3732 Status = Private->PointerList[Index]->Reset (
3733 Private->PointerList[Index],
3734 ExtendedVerification
3736 if (EFI_ERROR (Status)) {
3737 ReturnStatus = Status;
3741 return ReturnStatus;
3746 Reads the next keystroke from the input device. The WaitForKey Event can
3747 be used to test for existance of a keystroke via WaitForEvent () call.
3749 @param Private Protocol instance pointer.
3750 @param State The state information of simple pointer device.
3752 @retval EFI_SUCCESS The keystroke information was returned.
3753 @retval EFI_NOT_READY There was no keystroke data availiable.
3754 @retval EFI_DEVICE_ERROR The keydtroke information was not returned due
3755 to hardware errors.
3758 EFI_STATUS
3759 EFIAPI
3760 ConSplitterSimplePointerPrivateGetState (
3761 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
3762 IN OUT EFI_SIMPLE_POINTER_STATE *State
3765 EFI_STATUS Status;
3766 EFI_STATUS ReturnStatus;
3767 UINTN Index;
3768 EFI_SIMPLE_POINTER_STATE CurrentState;
3770 State->RelativeMovementX = 0;
3771 State->RelativeMovementY = 0;
3772 State->RelativeMovementZ = 0;
3773 State->LeftButton = FALSE;
3774 State->RightButton = FALSE;
3777 // if no physical console input device exists, return EFI_NOT_READY;
3778 // if any physical console input device has key input,
3779 // return the key and EFI_SUCCESS.
3781 ReturnStatus = EFI_NOT_READY;
3782 for (Index = 0; Index < Private->CurrentNumberOfPointers; Index++) {
3784 Status = Private->PointerList[Index]->GetState (
3785 Private->PointerList[Index],
3786 &CurrentState
3788 if (!EFI_ERROR (Status)) {
3789 if (ReturnStatus == EFI_NOT_READY) {
3790 ReturnStatus = EFI_SUCCESS;
3793 if (CurrentState.LeftButton) {
3794 State->LeftButton = TRUE;
3797 if (CurrentState.RightButton) {
3798 State->RightButton = TRUE;
3801 if (CurrentState.RelativeMovementX != 0 && Private->PointerList[Index]->Mode->ResolutionX != 0) {
3802 State->RelativeMovementX += (CurrentState.RelativeMovementX * (INT32) Private->SimplePointerMode.ResolutionX) / (INT32) Private->PointerList[Index]->Mode->ResolutionX;
3805 if (CurrentState.RelativeMovementY != 0 && Private->PointerList[Index]->Mode->ResolutionY != 0) {
3806 State->RelativeMovementY += (CurrentState.RelativeMovementY * (INT32) Private->SimplePointerMode.ResolutionY) / (INT32) Private->PointerList[Index]->Mode->ResolutionY;
3809 if (CurrentState.RelativeMovementZ != 0 && Private->PointerList[Index]->Mode->ResolutionZ != 0) {
3810 State->RelativeMovementZ += (CurrentState.RelativeMovementZ * (INT32) Private->SimplePointerMode.ResolutionZ) / (INT32) Private->PointerList[Index]->Mode->ResolutionZ;
3812 } else if (Status == EFI_DEVICE_ERROR) {
3813 ReturnStatus = EFI_DEVICE_ERROR;
3817 return ReturnStatus;
3822 Reads the next keystroke from the input device. The WaitForKey Event can
3823 be used to test for existance of a keystroke via WaitForEvent () call.
3825 @param This A pointer to protocol instance.
3826 @param State A pointer to state information on the pointer device
3828 @retval EFI_SUCCESS The keystroke information was returned in State.
3829 @retval EFI_NOT_READY There was no keystroke data availiable.
3830 @retval EFI_DEVICE_ERROR The keydtroke information was not returned due
3831 to hardware errors.
3834 EFI_STATUS
3835 EFIAPI
3836 ConSplitterSimplePointerGetState (
3837 IN EFI_SIMPLE_POINTER_PROTOCOL *This,
3838 IN OUT EFI_SIMPLE_POINTER_STATE *State
3841 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3843 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_SIMPLE_POINTER_THIS (This);
3845 Private->InputEventSignalState = FALSE;
3847 return ConSplitterSimplePointerPrivateGetState (Private, State);
3852 This event agregates all the events of the ConIn devices in the spliter.
3853 If any events of physical ConIn devices are signaled, signal the ConIn
3854 spliter event. This will cause the calling code to call
3855 ConSplitterTextInReadKeyStroke ().
3857 @param Event The Event assoicated with callback.
3858 @param Context Context registered when Event was created.
3861 VOID
3862 EFIAPI
3863 ConSplitterSimplePointerWaitForInput (
3864 IN EFI_EVENT Event,
3865 IN VOID *Context
3868 EFI_STATUS Status;
3869 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3870 UINTN Index;
3872 Private = (TEXT_IN_SPLITTER_PRIVATE_DATA *) Context;
3875 // if InputEventSignalState is flagged before, and not cleared by Reset() or ReadKeyStroke()
3877 if (Private->InputEventSignalState) {
3878 gBS->SignalEvent (Event);
3879 return ;
3882 // if any physical console input device has key input, signal the event.
3884 for (Index = 0; Index < Private->CurrentNumberOfPointers; Index++) {
3885 Status = gBS->CheckEvent (Private->PointerList[Index]->WaitForInput);
3886 if (!EFI_ERROR (Status)) {
3887 gBS->SignalEvent (Event);
3888 Private->InputEventSignalState = TRUE;
3894 Resets the pointer device hardware.
3896 @param This Protocol instance pointer.
3897 @param ExtendedVerification Driver may perform diagnostics on reset.
3899 @retval EFI_SUCCESS The device was reset.
3900 @retval EFI_DEVICE_ERROR The device is not functioning correctly and
3901 could not be reset.
3904 EFI_STATUS
3905 EFIAPI
3906 ConSplitterAbsolutePointerReset (
3907 IN EFI_ABSOLUTE_POINTER_PROTOCOL *This,
3908 IN BOOLEAN ExtendedVerification
3911 EFI_STATUS Status;
3912 EFI_STATUS ReturnStatus;
3913 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3914 UINTN Index;
3916 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_ABSOLUTE_POINTER_THIS (This);
3918 Private->AbsoluteInputEventSignalState = FALSE;
3920 if (Private->CurrentNumberOfAbsolutePointers == 0) {
3921 return EFI_SUCCESS;
3924 // return the worst status met
3926 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfAbsolutePointers; Index++) {
3927 Status = Private->AbsolutePointerList[Index]->Reset (
3928 Private->AbsolutePointerList[Index],
3929 ExtendedVerification
3931 if (EFI_ERROR (Status)) {
3932 ReturnStatus = Status;
3936 return ReturnStatus;
3941 Retrieves the current state of a pointer device.
3943 @param This Protocol instance pointer.
3944 @param State A pointer to the state information on the
3945 pointer device.
3947 @retval EFI_SUCCESS The state of the pointer device was returned in
3948 State..
3949 @retval EFI_NOT_READY The state of the pointer device has not changed
3950 since the last call to GetState().
3951 @retval EFI_DEVICE_ERROR A device error occurred while attempting to
3952 retrieve the pointer device's current state.
3955 EFI_STATUS
3956 EFIAPI
3957 ConSplitterAbsolutePointerGetState (
3958 IN EFI_ABSOLUTE_POINTER_PROTOCOL *This,
3959 IN OUT EFI_ABSOLUTE_POINTER_STATE *State
3962 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3963 EFI_STATUS Status;
3964 EFI_STATUS ReturnStatus;
3965 UINTN Index;
3966 EFI_ABSOLUTE_POINTER_STATE CurrentState;
3969 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_ABSOLUTE_POINTER_THIS (This);
3971 Private->AbsoluteInputEventSignalState = FALSE;
3973 State->CurrentX = 0;
3974 State->CurrentY = 0;
3975 State->CurrentZ = 0;
3976 State->ActiveButtons = 0;
3979 // if no physical pointer device exists, return EFI_NOT_READY;
3980 // if any physical pointer device has changed state,
3981 // return the state and EFI_SUCCESS.
3983 ReturnStatus = EFI_NOT_READY;
3984 for (Index = 0; Index < Private->CurrentNumberOfAbsolutePointers; Index++) {
3986 Status = Private->AbsolutePointerList[Index]->GetState (
3987 Private->AbsolutePointerList[Index],
3988 &CurrentState
3990 if (!EFI_ERROR (Status)) {
3991 if (ReturnStatus == EFI_NOT_READY) {
3992 ReturnStatus = EFI_SUCCESS;
3995 State->ActiveButtons = CurrentState.ActiveButtons;
3997 if (!(Private->AbsolutePointerMode.AbsoluteMinX == 0 && Private->AbsolutePointerMode.AbsoluteMaxX == 0)) {
3998 State->CurrentX = CurrentState.CurrentX;
4000 if (!(Private->AbsolutePointerMode.AbsoluteMinY == 0 && Private->AbsolutePointerMode.AbsoluteMaxY == 0)) {
4001 State->CurrentY = CurrentState.CurrentY;
4003 if (!(Private->AbsolutePointerMode.AbsoluteMinZ == 0 && Private->AbsolutePointerMode.AbsoluteMaxZ == 0)) {
4004 State->CurrentZ = CurrentState.CurrentZ;
4007 } else if (Status == EFI_DEVICE_ERROR) {
4008 ReturnStatus = EFI_DEVICE_ERROR;
4012 return ReturnStatus;
4017 This event agregates all the events of the pointer devices in the splitter.
4018 If any events of physical pointer devices are signaled, signal the pointer
4019 splitter event. This will cause the calling code to call
4020 ConSplitterAbsolutePointerGetState ().
4022 @param Event The Event assoicated with callback.
4023 @param Context Context registered when Event was created.
4026 VOID
4027 EFIAPI
4028 ConSplitterAbsolutePointerWaitForInput (
4029 IN EFI_EVENT Event,
4030 IN VOID *Context
4033 EFI_STATUS Status;
4034 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
4035 UINTN Index;
4037 Private = (TEXT_IN_SPLITTER_PRIVATE_DATA *) Context;
4040 // if AbsoluteInputEventSignalState is flagged before,
4041 // and not cleared by Reset() or GetState(), signal it
4043 if (Private->AbsoluteInputEventSignalState) {
4044 gBS->SignalEvent (Event);
4045 return ;
4048 // if any physical console input device has key input, signal the event.
4050 for (Index = 0; Index < Private->CurrentNumberOfAbsolutePointers; Index++) {
4051 Status = gBS->CheckEvent (Private->AbsolutePointerList[Index]->WaitForInput);
4052 if (!EFI_ERROR (Status)) {
4053 gBS->SignalEvent (Event);
4054 Private->AbsoluteInputEventSignalState = TRUE;
4061 Reset the text output device hardware and optionaly run diagnostics
4063 @param This Protocol instance pointer.
4064 @param ExtendedVerification Driver may perform more exhaustive verfication
4065 operation of the device during reset.
4067 @retval EFI_SUCCESS The text output device was reset.
4068 @retval EFI_DEVICE_ERROR The text output device is not functioning
4069 correctly and could not be reset.
4072 EFI_STATUS
4073 EFIAPI
4074 ConSplitterTextOutReset (
4075 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4076 IN BOOLEAN ExtendedVerification
4079 EFI_STATUS Status;
4080 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4081 UINTN Index;
4082 EFI_STATUS ReturnStatus;
4084 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4087 // return the worst status met
4089 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4090 Status = Private->TextOutList[Index].TextOut->Reset (
4091 Private->TextOutList[Index].TextOut,
4092 ExtendedVerification
4094 if (EFI_ERROR (Status)) {
4095 ReturnStatus = Status;
4099 This->SetAttribute (This, EFI_TEXT_ATTR (This->Mode->Attribute & 0x0F, EFI_BLACK));
4102 // reset all mode parameters
4104 TextOutSetMode (Private, 0);
4106 return ReturnStatus;
4111 Write a Unicode string to the output device.
4113 @param This Protocol instance pointer.
4114 @param WString The NULL-terminated Unicode string to be
4115 displayed on the output device(s). All output
4116 devices must also support the Unicode drawing
4117 defined in this file.
4119 @retval EFI_SUCCESS The string was output to the device.
4120 @retval EFI_DEVICE_ERROR The device reported an error while attempting to
4121 output the text.
4122 @retval EFI_UNSUPPORTED The output device's mode is not currently in a
4123 defined text mode.
4124 @retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the
4125 characters in the Unicode string could not be
4126 rendered and were skipped.
4129 EFI_STATUS
4130 EFIAPI
4131 ConSplitterTextOutOutputString (
4132 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4133 IN CHAR16 *WString
4136 EFI_STATUS Status;
4137 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4138 UINTN Index;
4139 UINTN BackSpaceCount;
4140 EFI_STATUS ReturnStatus;
4141 CHAR16 *TargetString;
4143 This->SetAttribute (This, This->Mode->Attribute);
4145 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4147 BackSpaceCount = 0;
4148 for (TargetString = WString; *TargetString != L'\0'; TargetString++) {
4149 if (*TargetString == L'a' && *(TargetString + 1) == L'b' && *(TargetString + 2) == L'c') {
4150 ;// CpuBreakpoint ();
4153 if (*TargetString == CHAR_BACKSPACE) {
4154 BackSpaceCount++;
4159 if (BackSpaceCount == 0) {
4160 TargetString = WString;
4161 } else {
4162 TargetString = AllocatePool (sizeof (CHAR16) * (StrLen (WString) + BackSpaceCount + 1));
4163 ASSERT (TargetString != NULL);
4165 StrCpy (TargetString, WString);
4168 // return the worst status met
4170 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4171 Status = Private->TextOutList[Index].TextOut->OutputString (
4172 Private->TextOutList[Index].TextOut,
4173 TargetString
4175 if (EFI_ERROR (Status)) {
4176 ReturnStatus = Status;
4180 if (Private->CurrentNumberOfConsoles > 0) {
4181 Private->TextOutMode.CursorColumn = Private->TextOutList[0].TextOut->Mode->CursorColumn;
4182 Private->TextOutMode.CursorRow = Private->TextOutList[0].TextOut->Mode->CursorRow;
4185 if (BackSpaceCount > 0) {
4186 FreePool (TargetString);
4189 return ReturnStatus;
4194 Verifies that all characters in a Unicode string can be output to the
4195 target device.
4197 @param This Protocol instance pointer.
4198 @param WString The NULL-terminated Unicode string to be
4199 examined for the output device(s).
4201 @retval EFI_SUCCESS The device(s) are capable of rendering the
4202 output string.
4203 @retval EFI_UNSUPPORTED Some of the characters in the Unicode string
4204 cannot be rendered by one or more of the output
4205 devices mapped by the EFI handle.
4208 EFI_STATUS
4209 EFIAPI
4210 ConSplitterTextOutTestString (
4211 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4212 IN CHAR16 *WString
4215 EFI_STATUS Status;
4216 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4217 UINTN Index;
4218 EFI_STATUS ReturnStatus;
4220 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4223 // return the worst status met
4225 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4226 Status = Private->TextOutList[Index].TextOut->TestString (
4227 Private->TextOutList[Index].TextOut,
4228 WString
4230 if (EFI_ERROR (Status)) {
4231 ReturnStatus = Status;
4235 // There is no DevNullTextOutTestString () since a Unicode buffer would
4236 // always return EFI_SUCCESS.
4237 // ReturnStatus will be EFI_SUCCESS if no consoles are present
4239 return ReturnStatus;
4244 Returns information for an available text mode that the output device(s)
4245 supports.
4247 @param This Protocol instance pointer.
4248 @param ModeNumber The mode number to return information on.
4249 @param Columns Returns the columns of the text output device
4250 for the requested ModeNumber.
4251 @param Rows Returns the rows of the text output device
4252 for the requested ModeNumber.
4254 @retval EFI_SUCCESS The requested mode information was returned.
4255 @retval EFI_DEVICE_ERROR The device had an error and could not complete
4256 the request.
4257 @retval EFI_UNSUPPORTED The mode number was not valid.
4260 EFI_STATUS
4261 EFIAPI
4262 ConSplitterTextOutQueryMode (
4263 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4264 IN UINTN ModeNumber,
4265 OUT UINTN *Columns,
4266 OUT UINTN *Rows
4269 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4270 UINTN CurrentMode;
4271 INT32 *TextOutModeMap;
4273 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4276 // Check whether param ModeNumber is valid.
4277 // ModeNumber should be within range 0 ~ MaxMode - 1.
4279 if ( (ModeNumber > (UINTN)(((UINT32)-1)>>1)) ) {
4280 return EFI_UNSUPPORTED;
4283 if ((INT32) ModeNumber >= This->Mode->MaxMode) {
4284 return EFI_UNSUPPORTED;
4288 // We get the available mode from mode intersection map if it's available
4290 if (Private->TextOutModeMap != NULL) {
4291 TextOutModeMap = Private->TextOutModeMap + Private->TextOutListCount * ModeNumber;
4292 CurrentMode = (UINTN)(*TextOutModeMap);
4293 *Columns = Private->TextOutQueryData[CurrentMode].Columns;
4294 *Rows = Private->TextOutQueryData[CurrentMode].Rows;
4295 } else {
4296 *Columns = Private->TextOutQueryData[ModeNumber].Columns;
4297 *Rows = Private->TextOutQueryData[ModeNumber].Rows;
4300 if (*Columns <= 0 && *Rows <= 0) {
4301 return EFI_UNSUPPORTED;
4305 return EFI_SUCCESS;
4310 Sets the output device(s) to a specified mode.
4312 @param This Protocol instance pointer.
4313 @param ModeNumber The mode number to set.
4315 @retval EFI_SUCCESS The requested text mode was set.
4316 @retval EFI_DEVICE_ERROR The device had an error and could not complete
4317 the request.
4318 @retval EFI_UNSUPPORTED The mode number was not valid.
4321 EFI_STATUS
4322 EFIAPI
4323 ConSplitterTextOutSetMode (
4324 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4325 IN UINTN ModeNumber
4328 EFI_STATUS Status;
4329 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4330 UINTN Index;
4331 INT32 *TextOutModeMap;
4332 EFI_STATUS ReturnStatus;
4334 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4337 // Check whether param ModeNumber is valid.
4338 // ModeNumber should be within range 0 ~ MaxMode - 1.
4340 if ( (ModeNumber > (UINTN)(((UINT32)-1)>>1)) ) {
4341 return EFI_UNSUPPORTED;
4344 if ((INT32) ModeNumber >= This->Mode->MaxMode) {
4345 return EFI_UNSUPPORTED;
4348 // If the mode is being set to the curent mode, then just clear the screen and return.
4350 if (Private->TextOutMode.Mode == (INT32) ModeNumber) {
4351 return ConSplitterTextOutClearScreen (This);
4354 // return the worst status met
4356 TextOutModeMap = Private->TextOutModeMap + Private->TextOutListCount * ModeNumber;
4357 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4358 Status = Private->TextOutList[Index].TextOut->SetMode (
4359 Private->TextOutList[Index].TextOut,
4360 TextOutModeMap[Index]
4363 // If this console device is based on a GOP or UGA device, then sync up the bitmap from
4364 // the GOP/UGA splitter and reclear the text portion of the display in the new mode.
4366 if ((Private->TextOutList[Index].GraphicsOutput != NULL) || (Private->TextOutList[Index].UgaDraw != NULL)) {
4367 Private->TextOutList[Index].TextOut->ClearScreen (Private->TextOutList[Index].TextOut);
4370 if (EFI_ERROR (Status)) {
4371 ReturnStatus = Status;
4376 // Set mode parameter to specified mode number
4378 TextOutSetMode (Private, ModeNumber);
4380 return ReturnStatus;
4385 Sets the background and foreground colors for the OutputString () and
4386 ClearScreen () functions.
4388 @param This Protocol instance pointer.
4389 @param Attribute The attribute to set. Bits 0..3 are the
4390 foreground color, and bits 4..6 are the
4391 background color. All other bits are undefined
4392 and must be zero. The valid Attributes are
4393 defined in this file.
4395 @retval EFI_SUCCESS The attribute was set.
4396 @retval EFI_DEVICE_ERROR The device had an error and could not complete
4397 the request.
4398 @retval EFI_UNSUPPORTED The attribute requested is not defined.
4401 EFI_STATUS
4402 EFIAPI
4403 ConSplitterTextOutSetAttribute (
4404 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4405 IN UINTN Attribute
4408 EFI_STATUS Status;
4409 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4410 UINTN Index;
4411 EFI_STATUS ReturnStatus;
4413 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4416 // Check whether param Attribute is valid.
4418 if ( (Attribute > (UINTN)(((UINT32)-1)>>1)) ) {
4419 return EFI_UNSUPPORTED;
4423 // return the worst status met
4425 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4426 Status = Private->TextOutList[Index].TextOut->SetAttribute (
4427 Private->TextOutList[Index].TextOut,
4428 Attribute
4430 if (EFI_ERROR (Status)) {
4431 ReturnStatus = Status;
4435 Private->TextOutMode.Attribute = (INT32) Attribute;
4437 return ReturnStatus;
4442 Clears the output device(s) display to the currently selected background
4443 color.
4445 @param This Protocol instance pointer.
4447 @retval EFI_SUCCESS The operation completed successfully.
4448 @retval EFI_DEVICE_ERROR The device had an error and could not complete
4449 the request.
4450 @retval EFI_UNSUPPORTED The output device is not in a valid text mode.
4453 EFI_STATUS
4454 EFIAPI
4455 ConSplitterTextOutClearScreen (
4456 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This
4459 EFI_STATUS Status;
4460 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4461 UINTN Index;
4462 EFI_STATUS ReturnStatus;
4464 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4467 // return the worst status met
4469 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4470 Status = Private->TextOutList[Index].TextOut->ClearScreen (Private->TextOutList[Index].TextOut);
4471 if (EFI_ERROR (Status)) {
4472 ReturnStatus = Status;
4477 // No need to do extra check here as whether (Column, Row) is valid has
4478 // been checked in ConSplitterTextOutSetCursorPosition. And (0, 0) should
4479 // always be supported.
4481 Private->TextOutMode.CursorColumn = 0;
4482 Private->TextOutMode.CursorRow = 0;
4483 Private->TextOutMode.CursorVisible = TRUE;
4485 return ReturnStatus;
4490 Sets the current coordinates of the cursor position
4492 @param This Protocol instance pointer.
4493 @param Column The column position to set the cursor to. Must be
4494 greater than or equal to zero and less than the
4495 number of columns by QueryMode ().
4496 @param Row The row position to set the cursor to. Must be
4497 greater than or equal to zero and less than the
4498 number of rows by QueryMode ().
4500 @retval EFI_SUCCESS The operation completed successfully.
4501 @retval EFI_DEVICE_ERROR The device had an error and could not complete
4502 the request.
4503 @retval EFI_UNSUPPORTED The output device is not in a valid text mode,
4504 or the cursor position is invalid for the
4505 current mode.
4508 EFI_STATUS
4509 EFIAPI
4510 ConSplitterTextOutSetCursorPosition (
4511 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4512 IN UINTN Column,
4513 IN UINTN Row
4516 EFI_STATUS Status;
4517 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4518 UINTN Index;
4519 EFI_STATUS ReturnStatus;
4520 UINTN MaxColumn;
4521 UINTN MaxRow;
4522 INT32 *TextOutModeMap;
4523 INT32 ModeNumber;
4524 INT32 CurrentMode;
4526 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4527 TextOutModeMap = NULL;
4528 ModeNumber = Private->TextOutMode.Mode;
4531 // Get current MaxColumn and MaxRow from intersection map
4533 if (Private->TextOutModeMap != NULL) {
4534 TextOutModeMap = Private->TextOutModeMap + Private->TextOutListCount * ModeNumber;
4535 CurrentMode = *TextOutModeMap;
4536 } else {
4537 CurrentMode = ModeNumber;
4540 MaxColumn = Private->TextOutQueryData[CurrentMode].Columns;
4541 MaxRow = Private->TextOutQueryData[CurrentMode].Rows;
4543 if (Column >= MaxColumn || Row >= MaxRow) {
4544 return EFI_UNSUPPORTED;
4547 // return the worst status met
4549 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4550 Status = Private->TextOutList[Index].TextOut->SetCursorPosition (
4551 Private->TextOutList[Index].TextOut,
4552 Column,
4555 if (EFI_ERROR (Status)) {
4556 ReturnStatus = Status;
4561 // No need to do extra check here as whether (Column, Row) is valid has
4562 // been checked in ConSplitterTextOutSetCursorPosition. And (0, 0) should
4563 // always be supported.
4565 Private->TextOutMode.CursorColumn = (INT32) Column;
4566 Private->TextOutMode.CursorRow = (INT32) Row;
4568 return ReturnStatus;
4573 Makes the cursor visible or invisible
4575 @param This Protocol instance pointer.
4576 @param Visible If TRUE, the cursor is set to be visible. If
4577 FALSE, the cursor is set to be invisible.
4579 @retval EFI_SUCCESS The operation completed successfully.
4580 @retval EFI_DEVICE_ERROR The device had an error and could not complete
4581 the request, or the device does not support
4582 changing the cursor mode.
4583 @retval EFI_UNSUPPORTED The output device is not in a valid text mode.
4586 EFI_STATUS
4587 EFIAPI
4588 ConSplitterTextOutEnableCursor (
4589 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4590 IN BOOLEAN Visible
4593 EFI_STATUS Status;
4594 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4595 UINTN Index;
4596 EFI_STATUS ReturnStatus;
4598 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4601 // return the worst status met
4603 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4604 Status = Private->TextOutList[Index].TextOut->EnableCursor (
4605 Private->TextOutList[Index].TextOut,
4606 Visible
4608 if (EFI_ERROR (Status)) {
4609 ReturnStatus = Status;
4613 Private->TextOutMode.CursorVisible = Visible;
4615 return ReturnStatus;