]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.c
6fc0e4796f9c2fa02615e0645af0d69a0a049418
[mirror_edk2.git] / MdeModulePkg / Universal / Console / ConSplitterDxe / ConSplitter.c
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.
5
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.
13
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.
18
19 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
20 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
21 SPDX-License-Identifier: BSD-2-Clause-Patent
22
23 **/
24
25 #include "ConSplitter.h"
26
27 //
28 // Identify if ConIn is connected in PcdConInConnectOnDemand enabled mode.
29 // default not connect
30 //
31 BOOLEAN mConInIsConnect = FALSE;
32
33 //
34 // Text In Splitter Private Data template
35 //
36 GLOBAL_REMOVE_IF_UNREFERENCED TEXT_IN_SPLITTER_PRIVATE_DATA mConIn = {
37 TEXT_IN_SPLITTER_PRIVATE_DATA_SIGNATURE,
38 (EFI_HANDLE) NULL,
39
40 {
41 ConSplitterTextInReset,
42 ConSplitterTextInReadKeyStroke,
43 (EFI_EVENT) NULL
44 },
45 0,
46 (EFI_SIMPLE_TEXT_INPUT_PROTOCOL **) NULL,
47 0,
48
49 {
50 ConSplitterTextInResetEx,
51 ConSplitterTextInReadKeyStrokeEx,
52 (EFI_EVENT) NULL,
53 ConSplitterTextInSetState,
54 ConSplitterTextInRegisterKeyNotify,
55 ConSplitterTextInUnregisterKeyNotify
56 },
57 0,
58 (EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL **) NULL,
59 0,
60 {
61 (LIST_ENTRY *) NULL,
62 (LIST_ENTRY *) NULL
63 },
64 (EFI_KEY_DATA *) NULL,
65 0,
66 0,
67 FALSE,
68
69 {
70 ConSplitterSimplePointerReset,
71 ConSplitterSimplePointerGetState,
72 (EFI_EVENT) NULL,
73 (EFI_SIMPLE_POINTER_MODE *) NULL
74 },
75 {
76 0x10000,
77 0x10000,
78 0x10000,
79 TRUE,
80 TRUE
81 },
82 0,
83 (EFI_SIMPLE_POINTER_PROTOCOL **) NULL,
84 0,
85
86 {
87 ConSplitterAbsolutePointerReset,
88 ConSplitterAbsolutePointerGetState,
89 (EFI_EVENT) NULL,
90 (EFI_ABSOLUTE_POINTER_MODE *) NULL
91 },
92 {
93 0, // AbsoluteMinX
94 0, // AbsoluteMinY
95 0, // AbsoluteMinZ
96 0x10000, // AbsoluteMaxX
97 0x10000, // AbsoluteMaxY
98 0x10000, // AbsoluteMaxZ
99 0 // Attributes
100 },
101 0,
102 (EFI_ABSOLUTE_POINTER_PROTOCOL **) NULL,
103 0,
104 FALSE,
105
106 FALSE,
107 FALSE
108 };
109
110
111 //
112 // Uga Draw Protocol Private Data template
113 //
114 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UGA_DRAW_PROTOCOL mUgaDrawProtocolTemplate = {
115 ConSplitterUgaDrawGetMode,
116 ConSplitterUgaDrawSetMode,
117 ConSplitterUgaDrawBlt
118 };
119
120 //
121 // Graphics Output Protocol Private Data template
122 //
123 GLOBAL_REMOVE_IF_UNREFERENCED EFI_GRAPHICS_OUTPUT_PROTOCOL mGraphicsOutputProtocolTemplate = {
124 ConSplitterGraphicsOutputQueryMode,
125 ConSplitterGraphicsOutputSetMode,
126 ConSplitterGraphicsOutputBlt,
127 NULL
128 };
129
130
131 //
132 // Text Out Splitter Private Data template
133 //
134 GLOBAL_REMOVE_IF_UNREFERENCED TEXT_OUT_SPLITTER_PRIVATE_DATA mConOut = {
135 TEXT_OUT_SPLITTER_PRIVATE_DATA_SIGNATURE,
136 (EFI_HANDLE) NULL,
137 {
138 ConSplitterTextOutReset,
139 ConSplitterTextOutOutputString,
140 ConSplitterTextOutTestString,
141 ConSplitterTextOutQueryMode,
142 ConSplitterTextOutSetMode,
143 ConSplitterTextOutSetAttribute,
144 ConSplitterTextOutClearScreen,
145 ConSplitterTextOutSetCursorPosition,
146 ConSplitterTextOutEnableCursor,
147 (EFI_SIMPLE_TEXT_OUTPUT_MODE *) NULL
148 },
149 {
150 1,
151 0,
152 0,
153 0,
154 0,
155 FALSE,
156 },
157
158 {
159 NULL,
160 NULL,
161 NULL
162 },
163 0,
164 0,
165 0,
166 0,
167
168 {
169 NULL,
170 NULL,
171 NULL,
172 NULL
173 },
174 (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *) NULL,
175 0,
176 0,
177
178 0,
179 (TEXT_OUT_AND_GOP_DATA *) NULL,
180 0,
181 (TEXT_OUT_SPLITTER_QUERY_DATA *) NULL,
182 0,
183 (INT32 *) NULL
184 };
185
186 //
187 // Standard Error Text Out Splitter Data Template
188 //
189 GLOBAL_REMOVE_IF_UNREFERENCED TEXT_OUT_SPLITTER_PRIVATE_DATA mStdErr = {
190 TEXT_OUT_SPLITTER_PRIVATE_DATA_SIGNATURE,
191 (EFI_HANDLE) NULL,
192 {
193 ConSplitterTextOutReset,
194 ConSplitterTextOutOutputString,
195 ConSplitterTextOutTestString,
196 ConSplitterTextOutQueryMode,
197 ConSplitterTextOutSetMode,
198 ConSplitterTextOutSetAttribute,
199 ConSplitterTextOutClearScreen,
200 ConSplitterTextOutSetCursorPosition,
201 ConSplitterTextOutEnableCursor,
202 (EFI_SIMPLE_TEXT_OUTPUT_MODE *) NULL
203 },
204 {
205 1,
206 0,
207 0,
208 0,
209 0,
210 FALSE,
211 },
212
213 {
214 NULL,
215 NULL,
216 NULL
217 },
218 0,
219 0,
220 0,
221 0,
222
223 {
224 NULL,
225 NULL,
226 NULL,
227 NULL
228 },
229 (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *) NULL,
230 0,
231 0,
232
233 0,
234 (TEXT_OUT_AND_GOP_DATA *) NULL,
235 0,
236 (TEXT_OUT_SPLITTER_QUERY_DATA *) NULL,
237 0,
238 (INT32 *) NULL
239 };
240
241 //
242 // Driver binding instance for Console Input Device
243 //
244 EFI_DRIVER_BINDING_PROTOCOL gConSplitterConInDriverBinding = {
245 ConSplitterConInDriverBindingSupported,
246 ConSplitterConInDriverBindingStart,
247 ConSplitterConInDriverBindingStop,
248 0xa,
249 NULL,
250 NULL
251 };
252
253 //
254 // Driver binding instance for Console Out device
255 //
256 EFI_DRIVER_BINDING_PROTOCOL gConSplitterConOutDriverBinding = {
257 ConSplitterConOutDriverBindingSupported,
258 ConSplitterConOutDriverBindingStart,
259 ConSplitterConOutDriverBindingStop,
260 0xa,
261 NULL,
262 NULL
263 };
264
265 //
266 // Driver binding instance for Standard Error device
267 //
268 EFI_DRIVER_BINDING_PROTOCOL gConSplitterStdErrDriverBinding = {
269 ConSplitterStdErrDriverBindingSupported,
270 ConSplitterStdErrDriverBindingStart,
271 ConSplitterStdErrDriverBindingStop,
272 0xa,
273 NULL,
274 NULL
275 };
276
277 //
278 // Driver binding instance for Simple Pointer protocol
279 //
280 EFI_DRIVER_BINDING_PROTOCOL gConSplitterSimplePointerDriverBinding = {
281 ConSplitterSimplePointerDriverBindingSupported,
282 ConSplitterSimplePointerDriverBindingStart,
283 ConSplitterSimplePointerDriverBindingStop,
284 0xa,
285 NULL,
286 NULL
287 };
288
289 //
290 // Driver binding instance for Absolute Pointer protocol
291 //
292 EFI_DRIVER_BINDING_PROTOCOL gConSplitterAbsolutePointerDriverBinding = {
293 ConSplitterAbsolutePointerDriverBindingSupported,
294 ConSplitterAbsolutePointerDriverBindingStart,
295 ConSplitterAbsolutePointerDriverBindingStop,
296 0xa,
297 NULL,
298 NULL
299 };
300
301 /**
302 Key notify for toggle state sync.
303
304 @param KeyData A pointer to a buffer that is filled in with
305 the keystroke information for the key that was
306 pressed.
307
308 @retval EFI_SUCCESS Toggle state sync successfully.
309
310 **/
311 EFI_STATUS
312 EFIAPI
313 ToggleStateSyncKeyNotify (
314 IN EFI_KEY_DATA *KeyData
315 )
316 {
317 UINTN Index;
318
319 if (((KeyData->KeyState.KeyToggleState & KEY_STATE_VALID_EXPOSED) == KEY_STATE_VALID_EXPOSED) &&
320 (KeyData->KeyState.KeyToggleState != mConIn.PhysicalKeyToggleState)) {
321 //
322 // There is toggle state change, sync to other console input devices.
323 //
324 for (Index = 0; Index < mConIn.CurrentNumberOfExConsoles; Index++) {
325 mConIn.TextInExList[Index]->SetState (
326 mConIn.TextInExList[Index],
327 &KeyData->KeyState.KeyToggleState
328 );
329 }
330 mConIn.PhysicalKeyToggleState = KeyData->KeyState.KeyToggleState;
331 DEBUG ((EFI_D_INFO, "Current toggle state is 0x%02x\n", mConIn.PhysicalKeyToggleState));
332 }
333
334 return EFI_SUCCESS;
335 }
336
337 /**
338 Initialization for toggle state sync.
339
340 @param Private Text In Splitter pointer.
341
342 **/
343 VOID
344 ToggleStateSyncInitialization (
345 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private
346 )
347 {
348 EFI_KEY_DATA KeyData;
349 VOID *NotifyHandle;
350
351 //
352 // Initialize PhysicalKeyToggleState that will be synced to new console
353 // input device to turn on physical TextInEx partial key report for
354 // toggle state sync.
355 //
356 Private->PhysicalKeyToggleState = KEY_STATE_VALID_EXPOSED;
357
358 //
359 // Initialize VirtualKeyStateExported to let the virtual TextInEx not report
360 // the partial key even though the physical TextInEx turns on the partial
361 // key report. The virtual TextInEx will report the partial key after it is
362 // required by calling SetState(X | KEY_STATE_VALID_EXPOSED) explicitly.
363 //
364 Private->VirtualKeyStateExported = FALSE;
365
366 //
367 // Register key notify for toggle state sync.
368 //
369 KeyData.Key.ScanCode = SCAN_NULL;
370 KeyData.Key.UnicodeChar = CHAR_NULL;
371 KeyData.KeyState.KeyShiftState = 0;
372 KeyData.KeyState.KeyToggleState = 0;
373 Private->TextInEx.RegisterKeyNotify (
374 &Private->TextInEx,
375 &KeyData,
376 ToggleStateSyncKeyNotify,
377 &NotifyHandle
378 );
379 }
380
381 /**
382 Reinitialization for toggle state sync.
383
384 @param Private Text In Splitter pointer.
385
386 **/
387 VOID
388 ToggleStateSyncReInitialization (
389 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private
390 )
391 {
392 UINTN Index;
393
394 //
395 // Reinitialize PhysicalKeyToggleState that will be synced to new console
396 // input device to turn on physical TextInEx partial key report for
397 // toggle state sync.
398 //
399 Private->PhysicalKeyToggleState = KEY_STATE_VALID_EXPOSED;
400
401 //
402 // Reinitialize VirtualKeyStateExported to let the virtual TextInEx not report
403 // the partial key even though the physical TextInEx turns on the partial
404 // key report. The virtual TextInEx will report the partial key after it is
405 // required by calling SetState(X | KEY_STATE_VALID_EXPOSED) explicitly.
406 //
407 Private->VirtualKeyStateExported = FALSE;
408
409 for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {
410 Private->TextInExList[Index]->SetState (
411 Private->TextInExList[Index],
412 &Private->PhysicalKeyToggleState
413 );
414 }
415 }
416
417 /**
418 The Entry Point for module ConSplitter. The user code starts with this function.
419
420 Installs driver module protocols and. Creates virtual device handles for ConIn,
421 ConOut, and StdErr. Installs Simple Text In protocol, Simple Text In Ex protocol,
422 Simple Pointer protocol, Absolute Pointer protocol on those virtual handlers.
423 Installs Graphics Output protocol and/or UGA Draw protocol if needed.
424
425 @param[in] ImageHandle The firmware allocated handle for the EFI image.
426 @param[in] SystemTable A pointer to the EFI System Table.
427
428 @retval EFI_SUCCESS The entry point is executed successfully.
429 @retval other Some error occurs when executing this entry point.
430
431 **/
432 EFI_STATUS
433 EFIAPI
434 ConSplitterDriverEntry(
435 IN EFI_HANDLE ImageHandle,
436 IN EFI_SYSTEM_TABLE *SystemTable
437 )
438 {
439 EFI_STATUS Status;
440
441 //
442 // Install driver model protocol(s).
443 //
444 Status = EfiLibInstallDriverBindingComponentName2 (
445 ImageHandle,
446 SystemTable,
447 &gConSplitterConInDriverBinding,
448 ImageHandle,
449 &gConSplitterConInComponentName,
450 &gConSplitterConInComponentName2
451 );
452 ASSERT_EFI_ERROR (Status);
453
454 Status = EfiLibInstallDriverBindingComponentName2 (
455 ImageHandle,
456 SystemTable,
457 &gConSplitterSimplePointerDriverBinding,
458 NULL,
459 &gConSplitterSimplePointerComponentName,
460 &gConSplitterSimplePointerComponentName2
461 );
462 ASSERT_EFI_ERROR (Status);
463
464 Status = EfiLibInstallDriverBindingComponentName2 (
465 ImageHandle,
466 SystemTable,
467 &gConSplitterAbsolutePointerDriverBinding,
468 NULL,
469 &gConSplitterAbsolutePointerComponentName,
470 &gConSplitterAbsolutePointerComponentName2
471 );
472 ASSERT_EFI_ERROR (Status);
473
474 Status = EfiLibInstallDriverBindingComponentName2 (
475 ImageHandle,
476 SystemTable,
477 &gConSplitterConOutDriverBinding,
478 NULL,
479 &gConSplitterConOutComponentName,
480 &gConSplitterConOutComponentName2
481 );
482 ASSERT_EFI_ERROR (Status);
483
484 Status = EfiLibInstallDriverBindingComponentName2 (
485 ImageHandle,
486 SystemTable,
487 &gConSplitterStdErrDriverBinding,
488 NULL,
489 &gConSplitterStdErrComponentName,
490 &gConSplitterStdErrComponentName2
491 );
492 ASSERT_EFI_ERROR (Status);
493
494 //
495 // Either Graphics Output protocol or UGA Draw protocol must be supported.
496 //
497 ASSERT (FeaturePcdGet (PcdConOutGopSupport) ||
498 FeaturePcdGet (PcdConOutUgaSupport));
499
500 //
501 // The driver creates virtual handles for ConIn, ConOut, StdErr.
502 // The virtual handles will always exist even if no console exist in the
503 // system. This is need to support hotplug devices like USB.
504 //
505 //
506 // Create virtual device handle for ConIn Splitter
507 //
508 Status = ConSplitterTextInConstructor (&mConIn);
509 if (!EFI_ERROR (Status)) {
510 Status = gBS->InstallMultipleProtocolInterfaces (
511 &mConIn.VirtualHandle,
512 &gEfiSimpleTextInProtocolGuid,
513 &mConIn.TextIn,
514 &gEfiSimpleTextInputExProtocolGuid,
515 &mConIn.TextInEx,
516 &gEfiSimplePointerProtocolGuid,
517 &mConIn.SimplePointer,
518 &gEfiAbsolutePointerProtocolGuid,
519 &mConIn.AbsolutePointer,
520 NULL
521 );
522 if (!EFI_ERROR (Status)) {
523 //
524 // Update the EFI System Table with new virtual console
525 // and update the pointer to Simple Text Input protocol.
526 //
527 gST->ConsoleInHandle = mConIn.VirtualHandle;
528 gST->ConIn = &mConIn.TextIn;
529 }
530 }
531 //
532 // Create virtual device handle for ConOut Splitter
533 //
534 Status = ConSplitterTextOutConstructor (&mConOut);
535 if (!EFI_ERROR (Status)) {
536 Status = gBS->InstallMultipleProtocolInterfaces (
537 &mConOut.VirtualHandle,
538 &gEfiSimpleTextOutProtocolGuid,
539 &mConOut.TextOut,
540 NULL
541 );
542 if (!EFI_ERROR (Status)) {
543 //
544 // Update the EFI System Table with new virtual console
545 // and Update the pointer to Text Output protocol.
546 //
547 gST->ConsoleOutHandle = mConOut.VirtualHandle;
548 gST->ConOut = &mConOut.TextOut;
549 }
550
551 }
552
553 //
554 // Create virtual device handle for StdErr Splitter
555 //
556 Status = ConSplitterTextOutConstructor (&mStdErr);
557 if (!EFI_ERROR (Status)) {
558 Status = gBS->InstallMultipleProtocolInterfaces (
559 &mStdErr.VirtualHandle,
560 &gEfiSimpleTextOutProtocolGuid,
561 &mStdErr.TextOut,
562 NULL
563 );
564 if (!EFI_ERROR (Status)) {
565 //
566 // Update the EFI System Table with new virtual console
567 // and update the pointer to Text Output protocol.
568 //
569 gST->StandardErrorHandle = mStdErr.VirtualHandle;
570 gST->StdErr = &mStdErr.TextOut;
571 }
572 }
573
574 //
575 // Update the CRC32 in the EFI System Table header
576 //
577 gST->Hdr.CRC32 = 0;
578 gBS->CalculateCrc32 (
579 (UINT8 *) &gST->Hdr,
580 gST->Hdr.HeaderSize,
581 &gST->Hdr.CRC32
582 );
583
584 return EFI_SUCCESS;
585
586 }
587
588 /**
589 Construct console input devices' private data.
590
591 @param ConInPrivate A pointer to the TEXT_IN_SPLITTER_PRIVATE_DATA
592 structure.
593
594 @retval EFI_OUT_OF_RESOURCES Out of resources.
595 @retval EFI_SUCCESS Text Input Devcie's private data has been constructed.
596 @retval other Failed to construct private data.
597
598 **/
599 EFI_STATUS
600 ConSplitterTextInConstructor (
601 TEXT_IN_SPLITTER_PRIVATE_DATA *ConInPrivate
602 )
603 {
604 EFI_STATUS Status;
605 UINTN TextInExListCount;
606
607 //
608 // Allocate buffer for Simple Text Input device
609 //
610 Status = ConSplitterGrowBuffer (
611 sizeof (EFI_SIMPLE_TEXT_INPUT_PROTOCOL *),
612 &ConInPrivate->TextInListCount,
613 (VOID **) &ConInPrivate->TextInList
614 );
615 if (EFI_ERROR (Status)) {
616 return EFI_OUT_OF_RESOURCES;
617 }
618
619 //
620 // Create Event to wait for a key
621 //
622 Status = gBS->CreateEvent (
623 EVT_NOTIFY_WAIT,
624 TPL_NOTIFY,
625 ConSplitterTextInWaitForKey,
626 ConInPrivate,
627 &ConInPrivate->TextIn.WaitForKey
628 );
629 ASSERT_EFI_ERROR (Status);
630
631 //
632 // Allocate buffer for KeyQueue
633 //
634 TextInExListCount = ConInPrivate->TextInExListCount;
635 Status = ConSplitterGrowBuffer (
636 sizeof (EFI_KEY_DATA),
637 &TextInExListCount,
638 (VOID **) &ConInPrivate->KeyQueue
639 );
640 if (EFI_ERROR (Status)) {
641 return EFI_OUT_OF_RESOURCES;
642 }
643
644 //
645 // Allocate buffer for Simple Text Input Ex device
646 //
647 Status = ConSplitterGrowBuffer (
648 sizeof (EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *),
649 &ConInPrivate->TextInExListCount,
650 (VOID **) &ConInPrivate->TextInExList
651 );
652 if (EFI_ERROR (Status)) {
653 return EFI_OUT_OF_RESOURCES;
654 }
655 //
656 // Create Event to wait for a key Ex
657 //
658 Status = gBS->CreateEvent (
659 EVT_NOTIFY_WAIT,
660 TPL_NOTIFY,
661 ConSplitterTextInWaitForKey,
662 ConInPrivate,
663 &ConInPrivate->TextInEx.WaitForKeyEx
664 );
665 ASSERT_EFI_ERROR (Status);
666
667 InitializeListHead (&ConInPrivate->NotifyList);
668
669 ToggleStateSyncInitialization (ConInPrivate);
670
671 ConInPrivate->AbsolutePointer.Mode = &ConInPrivate->AbsolutePointerMode;
672 //
673 // Allocate buffer for Absolute Pointer device
674 //
675 Status = ConSplitterGrowBuffer (
676 sizeof (EFI_ABSOLUTE_POINTER_PROTOCOL *),
677 &ConInPrivate->AbsolutePointerListCount,
678 (VOID **) &ConInPrivate->AbsolutePointerList
679 );
680 if (EFI_ERROR (Status)) {
681 return EFI_OUT_OF_RESOURCES;
682 }
683 //
684 // Create Event to wait for device input for Absolute pointer device
685 //
686 Status = gBS->CreateEvent (
687 EVT_NOTIFY_WAIT,
688 TPL_NOTIFY,
689 ConSplitterAbsolutePointerWaitForInput,
690 ConInPrivate,
691 &ConInPrivate->AbsolutePointer.WaitForInput
692 );
693 ASSERT_EFI_ERROR (Status);
694
695 ConInPrivate->SimplePointer.Mode = &ConInPrivate->SimplePointerMode;
696 //
697 // Allocate buffer for Simple Pointer device
698 //
699 Status = ConSplitterGrowBuffer (
700 sizeof (EFI_SIMPLE_POINTER_PROTOCOL *),
701 &ConInPrivate->PointerListCount,
702 (VOID **) &ConInPrivate->PointerList
703 );
704 if (EFI_ERROR (Status)) {
705 return EFI_OUT_OF_RESOURCES;
706 }
707 //
708 // Create Event to wait for device input for Simple pointer device
709 //
710 Status = gBS->CreateEvent (
711 EVT_NOTIFY_WAIT,
712 TPL_NOTIFY,
713 ConSplitterSimplePointerWaitForInput,
714 ConInPrivate,
715 &ConInPrivate->SimplePointer.WaitForInput
716 );
717 ASSERT_EFI_ERROR (Status);
718 //
719 // Create Event to signal ConIn connection request
720 //
721 Status = gBS->CreateEventEx (
722 EVT_NOTIFY_SIGNAL,
723 TPL_CALLBACK,
724 EfiEventEmptyFunction,
725 NULL,
726 &gConnectConInEventGuid,
727 &ConInPrivate->ConnectConInEvent
728 );
729
730 return Status;
731 }
732
733 /**
734 Construct console output devices' private data.
735
736 @param ConOutPrivate A pointer to the TEXT_OUT_SPLITTER_PRIVATE_DATA
737 structure.
738
739 @retval EFI_OUT_OF_RESOURCES Out of resources.
740 @retval EFI_SUCCESS Text Input Devcie's private data has been constructed.
741
742 **/
743 EFI_STATUS
744 ConSplitterTextOutConstructor (
745 TEXT_OUT_SPLITTER_PRIVATE_DATA *ConOutPrivate
746 )
747 {
748 EFI_STATUS Status;
749 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
750
751 //
752 // Copy protocols template
753 //
754 if (FeaturePcdGet (PcdConOutUgaSupport)) {
755 CopyMem (&ConOutPrivate->UgaDraw, &mUgaDrawProtocolTemplate, sizeof (EFI_UGA_DRAW_PROTOCOL));
756 }
757 if (FeaturePcdGet (PcdConOutGopSupport)) {
758 CopyMem (&ConOutPrivate->GraphicsOutput, &mGraphicsOutputProtocolTemplate, sizeof (EFI_GRAPHICS_OUTPUT_PROTOCOL));
759 }
760
761 //
762 // Initilize console output splitter's private data.
763 //
764 ConOutPrivate->TextOut.Mode = &ConOutPrivate->TextOutMode;
765
766 //
767 // When new console device is added, the new mode will be set later,
768 // so put current mode back to init state.
769 //
770 ConOutPrivate->TextOutMode.Mode = 0xFF;
771 //
772 // Allocate buffer for Console Out device
773 //
774 Status = ConSplitterGrowBuffer (
775 sizeof (TEXT_OUT_AND_GOP_DATA),
776 &ConOutPrivate->TextOutListCount,
777 (VOID **) &ConOutPrivate->TextOutList
778 );
779 if (EFI_ERROR (Status)) {
780 return EFI_OUT_OF_RESOURCES;
781 }
782 //
783 // Allocate buffer for Text Out query data
784 //
785 Status = ConSplitterGrowBuffer (
786 sizeof (TEXT_OUT_SPLITTER_QUERY_DATA),
787 &ConOutPrivate->TextOutQueryDataCount,
788 (VOID **) &ConOutPrivate->TextOutQueryData
789 );
790 if (EFI_ERROR (Status)) {
791 return EFI_OUT_OF_RESOURCES;
792 }
793
794 //
795 // Setup the default console to 80 x 25 and mode to 0
796 //
797 ConOutPrivate->TextOutQueryData[0].Columns = 80;
798 ConOutPrivate->TextOutQueryData[0].Rows = 25;
799 TextOutSetMode (ConOutPrivate, 0);
800
801
802 if (FeaturePcdGet (PcdConOutUgaSupport)) {
803 //
804 // Setup the UgaDraw to 800 x 600 x 32 bits per pixel, 60Hz.
805 //
806 ConSplitterUgaDrawSetMode (&ConOutPrivate->UgaDraw, 800, 600, 32, 60);
807 }
808 if (FeaturePcdGet (PcdConOutGopSupport)) {
809 //
810 // Setup resource for mode information in Graphics Output Protocol interface
811 //
812 if ((ConOutPrivate->GraphicsOutput.Mode = AllocateZeroPool (sizeof (EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE))) == NULL) {
813 return EFI_OUT_OF_RESOURCES;
814 }
815 if ((ConOutPrivate->GraphicsOutput.Mode->Info = AllocateZeroPool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION))) == NULL) {
816 return EFI_OUT_OF_RESOURCES;
817 }
818 //
819 // Setup the DevNullGraphicsOutput to 800 x 600 x 32 bits per pixel
820 // DevNull will be updated to user-defined mode after driver has started.
821 //
822 if ((ConOutPrivate->GraphicsOutputModeBuffer = AllocateZeroPool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION))) == NULL) {
823 return EFI_OUT_OF_RESOURCES;
824 }
825 Info = &ConOutPrivate->GraphicsOutputModeBuffer[0];
826 Info->Version = 0;
827 Info->HorizontalResolution = 800;
828 Info->VerticalResolution = 600;
829 Info->PixelFormat = PixelBltOnly;
830 Info->PixelsPerScanLine = 800;
831 CopyMem (ConOutPrivate->GraphicsOutput.Mode->Info, Info, sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
832 ConOutPrivate->GraphicsOutput.Mode->SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
833
834 //
835 // Initialize the following items, theset items remain unchanged in GraphicsOutput->SetMode()
836 // GraphicsOutputMode->FrameBufferBase, GraphicsOutputMode->FrameBufferSize
837 //
838 ConOutPrivate->GraphicsOutput.Mode->FrameBufferBase = (EFI_PHYSICAL_ADDRESS) (UINTN) NULL;
839 ConOutPrivate->GraphicsOutput.Mode->FrameBufferSize = 0;
840
841 ConOutPrivate->GraphicsOutput.Mode->MaxMode = 1;
842 //
843 // Initial current mode to unknown state, and then set to mode 0
844 //
845 ConOutPrivate->GraphicsOutput.Mode->Mode = 0xffff;
846 ConOutPrivate->GraphicsOutput.SetMode (&ConOutPrivate->GraphicsOutput, 0);
847 }
848
849 return EFI_SUCCESS;
850 }
851
852
853 /**
854 Test to see if the specified protocol could be supported on the specified device.
855
856 @param This Driver Binding protocol pointer.
857 @param ControllerHandle Handle of device to test.
858 @param Guid The specified protocol.
859
860 @retval EFI_SUCCESS The specified protocol is supported on this device.
861 @retval EFI_UNSUPPORTED The specified protocol attempts to be installed on virtul handle.
862 @retval other Failed to open specified protocol on this device.
863
864 **/
865 EFI_STATUS
866 ConSplitterSupported (
867 IN EFI_DRIVER_BINDING_PROTOCOL *This,
868 IN EFI_HANDLE ControllerHandle,
869 IN EFI_GUID *Guid
870 )
871 {
872 EFI_STATUS Status;
873 VOID *Instance;
874
875 //
876 // Make sure the Console Splitter does not attempt to attach to itself
877 //
878 if (ControllerHandle == mConIn.VirtualHandle ||
879 ControllerHandle == mConOut.VirtualHandle ||
880 ControllerHandle == mStdErr.VirtualHandle
881 ) {
882 return EFI_UNSUPPORTED;
883 }
884
885 //
886 // Check to see whether the specific protocol could be opened BY_DRIVER
887 //
888 Status = gBS->OpenProtocol (
889 ControllerHandle,
890 Guid,
891 &Instance,
892 This->DriverBindingHandle,
893 ControllerHandle,
894 EFI_OPEN_PROTOCOL_BY_DRIVER
895 );
896
897 if (EFI_ERROR (Status)) {
898 return Status;
899 }
900
901 gBS->CloseProtocol (
902 ControllerHandle,
903 Guid,
904 This->DriverBindingHandle,
905 ControllerHandle
906 );
907
908 return EFI_SUCCESS;
909 }
910
911 /**
912 Test to see if Console In Device could be supported on the Controller.
913
914 @param This Driver Binding protocol instance pointer.
915 @param ControllerHandle Handle of device to test.
916 @param RemainingDevicePath Optional parameter use to pick a specific child
917 device to start.
918
919 @retval EFI_SUCCESS This driver supports this device.
920 @retval other This driver does not support this device.
921
922 **/
923 EFI_STATUS
924 EFIAPI
925 ConSplitterConInDriverBindingSupported (
926 IN EFI_DRIVER_BINDING_PROTOCOL *This,
927 IN EFI_HANDLE ControllerHandle,
928 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
929 )
930 {
931 return ConSplitterSupported (
932 This,
933 ControllerHandle,
934 &gEfiConsoleInDeviceGuid
935 );
936 }
937
938 /**
939 Test to see if Simple Pointer protocol could be supported on the Controller.
940
941 @param This Driver Binding protocol instance pointer.
942 @param ControllerHandle Handle of device to test.
943 @param RemainingDevicePath Optional parameter use to pick a specific child
944 device to start.
945
946 @retval EFI_SUCCESS This driver supports this device.
947 @retval other This driver does not support this device.
948
949 **/
950 EFI_STATUS
951 EFIAPI
952 ConSplitterSimplePointerDriverBindingSupported (
953 IN EFI_DRIVER_BINDING_PROTOCOL *This,
954 IN EFI_HANDLE ControllerHandle,
955 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
956 )
957 {
958 return ConSplitterSupported (
959 This,
960 ControllerHandle,
961 &gEfiSimplePointerProtocolGuid
962 );
963 }
964
965 /**
966 Test to see if Absolute Pointer protocol could be supported on the Controller.
967
968 @param This Driver Binding protocol instance pointer.
969 @param ControllerHandle Handle of device to test.
970 @param RemainingDevicePath Optional parameter use to pick a specific child
971 device to start.
972
973 @retval EFI_SUCCESS This driver supports this device.
974 @retval other This driver does not support this device.
975
976 **/
977 EFI_STATUS
978 EFIAPI
979 ConSplitterAbsolutePointerDriverBindingSupported (
980 IN EFI_DRIVER_BINDING_PROTOCOL *This,
981 IN EFI_HANDLE ControllerHandle,
982 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
983 )
984 {
985 return ConSplitterSupported (
986 This,
987 ControllerHandle,
988 &gEfiAbsolutePointerProtocolGuid
989 );
990 }
991
992
993 /**
994 Test to see if Console Out Device could be supported on the Controller.
995
996 @param This Driver Binding protocol instance pointer.
997 @param ControllerHandle Handle of device to test.
998 @param RemainingDevicePath Optional parameter use to pick a specific child
999 device to start.
1000
1001 @retval EFI_SUCCESS This driver supports this device.
1002 @retval other This driver does not support this device.
1003
1004 **/
1005 EFI_STATUS
1006 EFIAPI
1007 ConSplitterConOutDriverBindingSupported (
1008 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1009 IN EFI_HANDLE ControllerHandle,
1010 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
1011 )
1012 {
1013 return ConSplitterSupported (
1014 This,
1015 ControllerHandle,
1016 &gEfiConsoleOutDeviceGuid
1017 );
1018 }
1019
1020 /**
1021 Test to see if Standard Error Device could be supported on the Controller.
1022
1023 @param This Driver Binding protocol instance pointer.
1024 @param ControllerHandle Handle of device to test.
1025 @param RemainingDevicePath Optional parameter use to pick a specific child
1026 device to start.
1027
1028 @retval EFI_SUCCESS This driver supports this device.
1029 @retval other This driver does not support this device.
1030
1031 **/
1032 EFI_STATUS
1033 EFIAPI
1034 ConSplitterStdErrDriverBindingSupported (
1035 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1036 IN EFI_HANDLE ControllerHandle,
1037 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
1038 )
1039 {
1040 return ConSplitterSupported (
1041 This,
1042 ControllerHandle,
1043 &gEfiStandardErrorDeviceGuid
1044 );
1045 }
1046
1047
1048 /**
1049 Start ConSplitter on devcie handle by opening Console Device Guid on device handle
1050 and the console virtual handle. And Get the console interface on controller handle.
1051
1052 @param This Driver Binding protocol instance pointer.
1053 @param ControllerHandle Handle of device.
1054 @param ConSplitterVirtualHandle Console virtual Handle.
1055 @param DeviceGuid The specified Console Device, such as ConInDev,
1056 ConOutDev.
1057 @param InterfaceGuid The specified protocol to be opened.
1058 @param Interface Protocol interface returned.
1059
1060 @retval EFI_SUCCESS This driver supports this device.
1061 @retval other Failed to open the specified Console Device Guid
1062 or specified protocol.
1063
1064 **/
1065 EFI_STATUS
1066 ConSplitterStart (
1067 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1068 IN EFI_HANDLE ControllerHandle,
1069 IN EFI_HANDLE ConSplitterVirtualHandle,
1070 IN EFI_GUID *DeviceGuid,
1071 IN EFI_GUID *InterfaceGuid,
1072 OUT VOID **Interface
1073 )
1074 {
1075 EFI_STATUS Status;
1076 VOID *Instance;
1077
1078 //
1079 // Check to see whether the ControllerHandle has the DeviceGuid on it.
1080 //
1081 Status = gBS->OpenProtocol (
1082 ControllerHandle,
1083 DeviceGuid,
1084 &Instance,
1085 This->DriverBindingHandle,
1086 ControllerHandle,
1087 EFI_OPEN_PROTOCOL_BY_DRIVER
1088 );
1089 if (EFI_ERROR (Status)) {
1090 return Status;
1091 }
1092
1093 //
1094 // Open the Parent Handle for the child.
1095 //
1096 Status = gBS->OpenProtocol (
1097 ControllerHandle,
1098 DeviceGuid,
1099 &Instance,
1100 This->DriverBindingHandle,
1101 ConSplitterVirtualHandle,
1102 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
1103 );
1104 if (EFI_ERROR (Status)) {
1105 goto Err;
1106 }
1107
1108 //
1109 // Open InterfaceGuid on the virtul handle.
1110 //
1111 Status = gBS->OpenProtocol (
1112 ControllerHandle,
1113 InterfaceGuid,
1114 Interface,
1115 This->DriverBindingHandle,
1116 ConSplitterVirtualHandle,
1117 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1118 );
1119
1120 if (!EFI_ERROR (Status)) {
1121 return EFI_SUCCESS;
1122 }
1123
1124 //
1125 // close the DeviceGuid on ConSplitter VirtualHandle.
1126 //
1127 gBS->CloseProtocol (
1128 ControllerHandle,
1129 DeviceGuid,
1130 This->DriverBindingHandle,
1131 ConSplitterVirtualHandle
1132 );
1133
1134 Err:
1135 //
1136 // close the DeviceGuid on ControllerHandle.
1137 //
1138 gBS->CloseProtocol (
1139 ControllerHandle,
1140 DeviceGuid,
1141 This->DriverBindingHandle,
1142 ControllerHandle
1143 );
1144
1145 return Status;
1146 }
1147
1148
1149 /**
1150 Start Console In Consplitter on device handle.
1151
1152 @param This Driver Binding protocol instance pointer.
1153 @param ControllerHandle Handle of device to bind driver to.
1154 @param RemainingDevicePath Optional parameter use to pick a specific child
1155 device to start.
1156
1157 @retval EFI_SUCCESS Console In Consplitter is added to ControllerHandle.
1158 @retval other Console In Consplitter does not support this device.
1159
1160 **/
1161 EFI_STATUS
1162 EFIAPI
1163 ConSplitterConInDriverBindingStart (
1164 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1165 IN EFI_HANDLE ControllerHandle,
1166 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
1167 )
1168 {
1169 EFI_STATUS Status;
1170 EFI_SIMPLE_TEXT_INPUT_PROTOCOL *TextIn;
1171 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TextInEx;
1172
1173 //
1174 // Start ConSplitter on ControllerHandle, and create the virtual
1175 // agrogated console device on first call Start for a SimpleTextIn handle.
1176 //
1177 Status = ConSplitterStart (
1178 This,
1179 ControllerHandle,
1180 mConIn.VirtualHandle,
1181 &gEfiConsoleInDeviceGuid,
1182 &gEfiSimpleTextInProtocolGuid,
1183 (VOID **) &TextIn
1184 );
1185 if (EFI_ERROR (Status)) {
1186 return Status;
1187 }
1188
1189 //
1190 // Add this device into Text In devices list.
1191 //
1192 Status = ConSplitterTextInAddDevice (&mConIn, TextIn);
1193 if (EFI_ERROR (Status)) {
1194 return Status;
1195 }
1196
1197 Status = gBS->OpenProtocol (
1198 ControllerHandle,
1199 &gEfiSimpleTextInputExProtocolGuid,
1200 (VOID **) &TextInEx,
1201 This->DriverBindingHandle,
1202 mConIn.VirtualHandle,
1203 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1204 );
1205 if (!EFI_ERROR (Status)) {
1206 //
1207 // If Simple Text Input Ex protocol exists,
1208 // add this device into Text In Ex devices list.
1209 //
1210 Status = ConSplitterTextInExAddDevice (&mConIn, TextInEx);
1211 }
1212
1213 return Status;
1214 }
1215
1216
1217 /**
1218 Start Simple Pointer Consplitter on device handle.
1219
1220 @param This Driver Binding protocol instance pointer.
1221 @param ControllerHandle Handle of device to bind driver to.
1222 @param RemainingDevicePath Optional parameter use to pick a specific child
1223 device to start.
1224
1225 @retval EFI_SUCCESS Simple Pointer Consplitter is added to ControllerHandle.
1226 @retval other Simple Pointer Consplitter does not support this device.
1227
1228 **/
1229 EFI_STATUS
1230 EFIAPI
1231 ConSplitterSimplePointerDriverBindingStart (
1232 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1233 IN EFI_HANDLE ControllerHandle,
1234 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
1235 )
1236 {
1237 EFI_STATUS Status;
1238 EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer;
1239
1240 //
1241 // Start ConSplitter on ControllerHandle, and create the virtual
1242 // agrogated console device on first call Start for a SimplePointer handle.
1243 //
1244 Status = ConSplitterStart (
1245 This,
1246 ControllerHandle,
1247 mConIn.VirtualHandle,
1248 &gEfiSimplePointerProtocolGuid,
1249 &gEfiSimplePointerProtocolGuid,
1250 (VOID **) &SimplePointer
1251 );
1252 if (EFI_ERROR (Status)) {
1253 return Status;
1254 }
1255
1256 //
1257 // Add this devcie into Simple Pointer devices list.
1258 //
1259 return ConSplitterSimplePointerAddDevice (&mConIn, SimplePointer);
1260 }
1261
1262
1263 /**
1264 Start Absolute Pointer Consplitter on device handle.
1265
1266 @param This Driver Binding protocol instance pointer.
1267 @param ControllerHandle Handle of device to bind driver to.
1268 @param RemainingDevicePath Optional parameter use to pick a specific child
1269 device to start.
1270
1271 @retval EFI_SUCCESS Absolute Pointer Consplitter is added to ControllerHandle.
1272 @retval other Absolute Pointer Consplitter does not support this device.
1273
1274 **/
1275 EFI_STATUS
1276 EFIAPI
1277 ConSplitterAbsolutePointerDriverBindingStart (
1278 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1279 IN EFI_HANDLE ControllerHandle,
1280 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
1281 )
1282 {
1283 EFI_STATUS Status;
1284 EFI_ABSOLUTE_POINTER_PROTOCOL *AbsolutePointer;
1285
1286 //
1287 // Start ConSplitter on ControllerHandle, and create the virtual
1288 // agrogated console device on first call Start for a AbsolutePointer handle.
1289 //
1290 Status = ConSplitterStart (
1291 This,
1292 ControllerHandle,
1293 mConIn.VirtualHandle,
1294 &gEfiAbsolutePointerProtocolGuid,
1295 &gEfiAbsolutePointerProtocolGuid,
1296 (VOID **) &AbsolutePointer
1297 );
1298
1299 if (EFI_ERROR (Status)) {
1300 return Status;
1301 }
1302
1303 //
1304 // Add this devcie into Absolute Pointer devices list.
1305 //
1306 return ConSplitterAbsolutePointerAddDevice (&mConIn, AbsolutePointer);
1307 }
1308
1309
1310 /**
1311 Start Console Out Consplitter on device handle.
1312
1313 @param This Driver Binding protocol instance pointer.
1314 @param ControllerHandle Handle of device to bind driver to.
1315 @param RemainingDevicePath Optional parameter use to pick a specific child
1316 device to start.
1317
1318 @retval EFI_SUCCESS Console Out Consplitter is added to ControllerHandle.
1319 @retval other Console Out Consplitter does not support this device.
1320
1321 **/
1322 EFI_STATUS
1323 EFIAPI
1324 ConSplitterConOutDriverBindingStart (
1325 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1326 IN EFI_HANDLE ControllerHandle,
1327 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
1328 )
1329 {
1330 EFI_STATUS Status;
1331 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut;
1332 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
1333 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
1334 UINTN SizeOfInfo;
1335 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
1336
1337 //
1338 // Start ConSplitter on ControllerHandle, and create the virtual
1339 // agrogated console device on first call Start for a ConsoleOut handle.
1340 //
1341 Status = ConSplitterStart (
1342 This,
1343 ControllerHandle,
1344 mConOut.VirtualHandle,
1345 &gEfiConsoleOutDeviceGuid,
1346 &gEfiSimpleTextOutProtocolGuid,
1347 (VOID **) &TextOut
1348 );
1349 if (EFI_ERROR (Status)) {
1350 return Status;
1351 }
1352
1353 GraphicsOutput = NULL;
1354 UgaDraw = NULL;
1355 //
1356 // Try to Open Graphics Output protocol
1357 //
1358 Status = gBS->OpenProtocol (
1359 ControllerHandle,
1360 &gEfiGraphicsOutputProtocolGuid,
1361 (VOID **) &GraphicsOutput,
1362 This->DriverBindingHandle,
1363 mConOut.VirtualHandle,
1364 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1365 );
1366
1367 if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {
1368 //
1369 // Open UGA DRAW protocol
1370 //
1371 gBS->OpenProtocol (
1372 ControllerHandle,
1373 &gEfiUgaDrawProtocolGuid,
1374 (VOID **) &UgaDraw,
1375 This->DriverBindingHandle,
1376 mConOut.VirtualHandle,
1377 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1378 );
1379 }
1380
1381 //
1382 // When new console device is added, the new mode will be set later,
1383 // so put current mode back to init state.
1384 //
1385 mConOut.TextOutMode.Mode = 0xFF;
1386
1387 //
1388 // If both ConOut and StdErr incorporate the same Text Out device,
1389 // their MaxMode and QueryData should be the intersection of both.
1390 //
1391 Status = ConSplitterTextOutAddDevice (&mConOut, TextOut, GraphicsOutput, UgaDraw);
1392 ConSplitterTextOutSetAttribute (&mConOut.TextOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
1393
1394 if (FeaturePcdGet (PcdConOutUgaSupport)) {
1395 //
1396 // Get the UGA mode data of ConOut from the current mode
1397 //
1398 if (GraphicsOutput != NULL) {
1399 Status = GraphicsOutput->QueryMode (GraphicsOutput, GraphicsOutput->Mode->Mode, &SizeOfInfo, &Info);
1400 if (EFI_ERROR (Status)) {
1401 return Status;
1402 }
1403 ASSERT ( SizeOfInfo <= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
1404
1405 mConOut.UgaHorizontalResolution = Info->HorizontalResolution;
1406 mConOut.UgaVerticalResolution = Info->VerticalResolution;
1407 mConOut.UgaColorDepth = 32;
1408 mConOut.UgaRefreshRate = 60;
1409
1410 FreePool (Info);
1411
1412 } else if (UgaDraw != NULL) {
1413 Status = UgaDraw->GetMode (
1414 UgaDraw,
1415 &mConOut.UgaHorizontalResolution,
1416 &mConOut.UgaVerticalResolution,
1417 &mConOut.UgaColorDepth,
1418 &mConOut.UgaRefreshRate
1419 );
1420 }
1421 }
1422
1423 return Status;
1424 }
1425
1426
1427 /**
1428 Start Standard Error Consplitter on device handle.
1429
1430 @param This Driver Binding protocol instance pointer.
1431 @param ControllerHandle Handle of device to bind driver to.
1432 @param RemainingDevicePath Optional parameter use to pick a specific child
1433 device to start.
1434
1435 @retval EFI_SUCCESS Standard Error Consplitter is added to ControllerHandle.
1436 @retval other Standard Error Consplitter does not support this device.
1437
1438 **/
1439 EFI_STATUS
1440 EFIAPI
1441 ConSplitterStdErrDriverBindingStart (
1442 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1443 IN EFI_HANDLE ControllerHandle,
1444 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
1445 )
1446 {
1447 EFI_STATUS Status;
1448 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut;
1449
1450 //
1451 // Start ConSplitter on ControllerHandle, and create the virtual
1452 // agrogated console device on first call Start for a StandardError handle.
1453 //
1454 Status = ConSplitterStart (
1455 This,
1456 ControllerHandle,
1457 mStdErr.VirtualHandle,
1458 &gEfiStandardErrorDeviceGuid,
1459 &gEfiSimpleTextOutProtocolGuid,
1460 (VOID **) &TextOut
1461 );
1462 if (EFI_ERROR (Status)) {
1463 return Status;
1464 }
1465
1466 //
1467 // When new console device is added, the new mode will be set later,
1468 // so put current mode back to init state.
1469 //
1470 mStdErr.TextOutMode.Mode = 0xFF;
1471
1472 //
1473 // If both ConOut and StdErr incorporate the same Text Out device,
1474 // their MaxMode and QueryData should be the intersection of both.
1475 //
1476 Status = ConSplitterTextOutAddDevice (&mStdErr, TextOut, NULL, NULL);
1477 ConSplitterTextOutSetAttribute (&mStdErr.TextOut, EFI_TEXT_ATTR (EFI_MAGENTA, EFI_BLACK));
1478
1479 return Status;
1480 }
1481
1482
1483 /**
1484 Stop ConSplitter on device handle by closing Console Device Guid on device handle
1485 and the console virtual handle.
1486
1487 @param This Protocol instance pointer.
1488 @param ControllerHandle Handle of device.
1489 @param ConSplitterVirtualHandle Console virtual Handle.
1490 @param DeviceGuid The specified Console Device, such as ConInDev,
1491 ConOutDev.
1492 @param InterfaceGuid The specified protocol to be opened.
1493 @param Interface Protocol interface returned.
1494
1495 @retval EFI_SUCCESS Stop ConSplitter on ControllerHandle successfully.
1496 @retval other Failed to Stop ConSplitter on ControllerHandle.
1497
1498 **/
1499 EFI_STATUS
1500 ConSplitterStop (
1501 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1502 IN EFI_HANDLE ControllerHandle,
1503 IN EFI_HANDLE ConSplitterVirtualHandle,
1504 IN EFI_GUID *DeviceGuid,
1505 IN EFI_GUID *InterfaceGuid,
1506 IN VOID **Interface
1507 )
1508 {
1509 EFI_STATUS Status;
1510
1511 Status = gBS->OpenProtocol (
1512 ControllerHandle,
1513 InterfaceGuid,
1514 Interface,
1515 This->DriverBindingHandle,
1516 ControllerHandle,
1517 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1518 );
1519 if (EFI_ERROR (Status)) {
1520 return Status;
1521 }
1522 //
1523 // close the protocol refered.
1524 //
1525 gBS->CloseProtocol (
1526 ControllerHandle,
1527 DeviceGuid,
1528 This->DriverBindingHandle,
1529 ConSplitterVirtualHandle
1530 );
1531
1532 gBS->CloseProtocol (
1533 ControllerHandle,
1534 DeviceGuid,
1535 This->DriverBindingHandle,
1536 ControllerHandle
1537 );
1538
1539 return EFI_SUCCESS;
1540 }
1541
1542
1543 /**
1544 Stop Console In ConSplitter on ControllerHandle by closing Console In Devcice GUID.
1545
1546 @param This Driver Binding protocol instance pointer.
1547 @param ControllerHandle Handle of device to stop driver on
1548 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
1549 children is zero stop the entire bus driver.
1550 @param ChildHandleBuffer List of Child Handles to Stop.
1551
1552 @retval EFI_SUCCESS This driver is removed ControllerHandle
1553 @retval other This driver was not removed from this device
1554
1555 **/
1556 EFI_STATUS
1557 EFIAPI
1558 ConSplitterConInDriverBindingStop (
1559 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1560 IN EFI_HANDLE ControllerHandle,
1561 IN UINTN NumberOfChildren,
1562 IN EFI_HANDLE *ChildHandleBuffer
1563 )
1564 {
1565 EFI_STATUS Status;
1566 EFI_SIMPLE_TEXT_INPUT_PROTOCOL *TextIn;
1567 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TextInEx;
1568
1569 if (NumberOfChildren == 0) {
1570 return EFI_SUCCESS;
1571 }
1572
1573 Status = gBS->OpenProtocol (
1574 ControllerHandle,
1575 &gEfiSimpleTextInputExProtocolGuid,
1576 (VOID **) &TextInEx,
1577 This->DriverBindingHandle,
1578 ControllerHandle,
1579 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1580 );
1581 if (!EFI_ERROR (Status)) {
1582 //
1583 // If Simple Text Input Ex protocol exists,
1584 // remove device from Text Input Ex devices list.
1585 //
1586 Status = ConSplitterTextInExDeleteDevice (&mConIn, TextInEx);
1587 if (EFI_ERROR (Status)) {
1588 return Status;
1589 }
1590 }
1591
1592 //
1593 // Close Simple Text In protocol on controller handle and virtual handle.
1594 //
1595 Status = ConSplitterStop (
1596 This,
1597 ControllerHandle,
1598 mConIn.VirtualHandle,
1599 &gEfiConsoleInDeviceGuid,
1600 &gEfiSimpleTextInProtocolGuid,
1601 (VOID **) &TextIn
1602 );
1603 if (EFI_ERROR (Status)) {
1604 return Status;
1605 }
1606
1607 //
1608 // Remove device from Text Input devices list.
1609 //
1610 return ConSplitterTextInDeleteDevice (&mConIn, TextIn);
1611 }
1612
1613
1614 /**
1615 Stop Simple Pointer protocol ConSplitter on ControllerHandle by closing
1616 Simple Pointer protocol.
1617
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.
1623
1624 @retval EFI_SUCCESS This driver is removed ControllerHandle
1625 @retval other This driver was not removed from this device
1626
1627 **/
1628 EFI_STATUS
1629 EFIAPI
1630 ConSplitterSimplePointerDriverBindingStop (
1631 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1632 IN EFI_HANDLE ControllerHandle,
1633 IN UINTN NumberOfChildren,
1634 IN EFI_HANDLE *ChildHandleBuffer
1635 )
1636 {
1637 EFI_STATUS Status;
1638 EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer;
1639
1640 if (NumberOfChildren == 0) {
1641 return EFI_SUCCESS;
1642 }
1643
1644 //
1645 // Close Simple Pointer protocol on controller handle and virtual handle.
1646 //
1647 Status = ConSplitterStop (
1648 This,
1649 ControllerHandle,
1650 mConIn.VirtualHandle,
1651 &gEfiSimplePointerProtocolGuid,
1652 &gEfiSimplePointerProtocolGuid,
1653 (VOID **) &SimplePointer
1654 );
1655 if (EFI_ERROR (Status)) {
1656 return Status;
1657 }
1658
1659 //
1660 // Remove this device from Simple Pointer device list.
1661 //
1662 return ConSplitterSimplePointerDeleteDevice (&mConIn, SimplePointer);
1663 }
1664
1665
1666 /**
1667 Stop Absolute Pointer protocol ConSplitter on ControllerHandle by closing
1668 Absolute Pointer protocol.
1669
1670 @param This Driver Binding protocol instance pointer.
1671 @param ControllerHandle Handle of device to stop driver on
1672 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
1673 children is zero stop the entire bus driver.
1674 @param ChildHandleBuffer List of Child Handles to Stop.
1675
1676 @retval EFI_SUCCESS This driver is removed ControllerHandle
1677 @retval other This driver was not removed from this device
1678
1679 **/
1680 EFI_STATUS
1681 EFIAPI
1682 ConSplitterAbsolutePointerDriverBindingStop (
1683 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1684 IN EFI_HANDLE ControllerHandle,
1685 IN UINTN NumberOfChildren,
1686 IN EFI_HANDLE *ChildHandleBuffer
1687 )
1688 {
1689 EFI_STATUS Status;
1690 EFI_ABSOLUTE_POINTER_PROTOCOL *AbsolutePointer;
1691
1692 if (NumberOfChildren == 0) {
1693 return EFI_SUCCESS;
1694 }
1695
1696 //
1697 // Close Absolute Pointer protocol on controller handle and virtual handle.
1698 //
1699 Status = ConSplitterStop (
1700 This,
1701 ControllerHandle,
1702 mConIn.VirtualHandle,
1703 &gEfiAbsolutePointerProtocolGuid,
1704 &gEfiAbsolutePointerProtocolGuid,
1705 (VOID **) &AbsolutePointer
1706 );
1707 if (EFI_ERROR (Status)) {
1708 return Status;
1709 }
1710
1711 //
1712 // Remove this device from Absolute Pointer device list.
1713 //
1714 return ConSplitterAbsolutePointerDeleteDevice (&mConIn, AbsolutePointer);
1715 }
1716
1717
1718 /**
1719 Stop Console Out ConSplitter on device handle by closing Console Out Devcice GUID.
1720
1721 @param This Driver Binding protocol instance pointer.
1722 @param ControllerHandle Handle of device to stop driver on
1723 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
1724 children is zero stop the entire bus driver.
1725 @param ChildHandleBuffer List of Child Handles to Stop.
1726
1727 @retval EFI_SUCCESS This driver is removed ControllerHandle
1728 @retval other This driver was not removed from this device
1729
1730 **/
1731 EFI_STATUS
1732 EFIAPI
1733 ConSplitterConOutDriverBindingStop (
1734 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1735 IN EFI_HANDLE ControllerHandle,
1736 IN UINTN NumberOfChildren,
1737 IN EFI_HANDLE *ChildHandleBuffer
1738 )
1739 {
1740 EFI_STATUS Status;
1741 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut;
1742
1743 if (NumberOfChildren == 0) {
1744 return EFI_SUCCESS;
1745 }
1746
1747 //
1748 // Close Absolute Pointer protocol on controller handle and virtual handle.
1749 //
1750 Status = ConSplitterStop (
1751 This,
1752 ControllerHandle,
1753 mConOut.VirtualHandle,
1754 &gEfiConsoleOutDeviceGuid,
1755 &gEfiSimpleTextOutProtocolGuid,
1756 (VOID **) &TextOut
1757 );
1758 if (EFI_ERROR (Status)) {
1759 return Status;
1760 }
1761
1762 //
1763 // Remove this device from Text Out device list.
1764 //
1765 return ConSplitterTextOutDeleteDevice (&mConOut, TextOut);
1766 }
1767
1768
1769 /**
1770 Stop Standard Error ConSplitter on ControllerHandle by closing Standard Error GUID.
1771
1772 @param This Driver Binding protocol instance pointer.
1773 @param ControllerHandle Handle of device to stop driver on
1774 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
1775 children is zero stop the entire bus driver.
1776 @param ChildHandleBuffer List of Child Handles to Stop.
1777
1778 @retval EFI_SUCCESS This driver is removed ControllerHandle
1779 @retval other This driver was not removed from this device
1780
1781 **/
1782 EFI_STATUS
1783 EFIAPI
1784 ConSplitterStdErrDriverBindingStop (
1785 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1786 IN EFI_HANDLE ControllerHandle,
1787 IN UINTN NumberOfChildren,
1788 IN EFI_HANDLE *ChildHandleBuffer
1789 )
1790 {
1791 EFI_STATUS Status;
1792 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut;
1793
1794 if (NumberOfChildren == 0) {
1795 return EFI_SUCCESS;
1796 }
1797
1798 //
1799 // Close Standard Error Device on controller handle and virtual handle.
1800 //
1801 Status = ConSplitterStop (
1802 This,
1803 ControllerHandle,
1804 mStdErr.VirtualHandle,
1805 &gEfiStandardErrorDeviceGuid,
1806 &gEfiSimpleTextOutProtocolGuid,
1807 (VOID **) &TextOut
1808 );
1809 if (EFI_ERROR (Status)) {
1810 return Status;
1811 }
1812 //
1813 // Delete this console error out device's data structures.
1814 //
1815 return ConSplitterTextOutDeleteDevice (&mStdErr, TextOut);
1816 }
1817
1818
1819 /**
1820 Take the passed in Buffer of size ElementSize and grow the buffer
1821 by CONSOLE_SPLITTER_ALLOC_UNIT * ElementSize bytes.
1822 Copy the current data in Buffer to the new version of Buffer and
1823 free the old version of buffer.
1824
1825 @param ElementSize Size of element in array.
1826 @param Count Current number of elements in array.
1827 @param Buffer Bigger version of passed in Buffer with all the
1828 data.
1829
1830 @retval EFI_SUCCESS Buffer size has grown.
1831 @retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
1832
1833 **/
1834 EFI_STATUS
1835 ConSplitterGrowBuffer (
1836 IN UINTN ElementSize,
1837 IN OUT UINTN *Count,
1838 IN OUT VOID **Buffer
1839 )
1840 {
1841 VOID *Ptr;
1842
1843 //
1844 // grow the buffer to new buffer size,
1845 // copy the old buffer's content to the new-size buffer,
1846 // then free the old buffer.
1847 //
1848 Ptr = ReallocatePool (
1849 ElementSize * (*Count),
1850 ElementSize * ((*Count) + CONSOLE_SPLITTER_ALLOC_UNIT),
1851 *Buffer
1852 );
1853 if (Ptr == NULL) {
1854 return EFI_OUT_OF_RESOURCES;
1855 }
1856 *Count += CONSOLE_SPLITTER_ALLOC_UNIT;
1857 *Buffer = Ptr;
1858 return EFI_SUCCESS;
1859 }
1860
1861
1862 /**
1863 Add Text Input Device in Consplitter Text Input list.
1864
1865 @param Private Text In Splitter pointer.
1866 @param TextIn Simple Text Input protocol pointer.
1867
1868 @retval EFI_SUCCESS Text Input Device added successfully.
1869 @retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
1870
1871 **/
1872 EFI_STATUS
1873 ConSplitterTextInAddDevice (
1874 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
1875 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *TextIn
1876 )
1877 {
1878 EFI_STATUS Status;
1879
1880 //
1881 // If the Text In List is full, enlarge it by calling ConSplitterGrowBuffer().
1882 //
1883 if (Private->CurrentNumberOfConsoles >= Private->TextInListCount) {
1884 Status = ConSplitterGrowBuffer (
1885 sizeof (EFI_SIMPLE_TEXT_INPUT_PROTOCOL *),
1886 &Private->TextInListCount,
1887 (VOID **) &Private->TextInList
1888 );
1889 if (EFI_ERROR (Status)) {
1890 return EFI_OUT_OF_RESOURCES;
1891 }
1892 }
1893 //
1894 // Add the new text-in device data structure into the Text In List.
1895 //
1896 Private->TextInList[Private->CurrentNumberOfConsoles] = TextIn;
1897 Private->CurrentNumberOfConsoles++;
1898
1899 //
1900 // Extra CheckEvent added to reduce the double CheckEvent().
1901 //
1902 gBS->CheckEvent (TextIn->WaitForKey);
1903
1904 return EFI_SUCCESS;
1905 }
1906
1907
1908 /**
1909 Remove Text Input Device from Consplitter Text Input list.
1910
1911 @param Private Text In Splitter pointer.
1912 @param TextIn Simple Text protocol pointer.
1913
1914 @retval EFI_SUCCESS Simple Text Device removed successfully.
1915 @retval EFI_NOT_FOUND No Simple Text Device found.
1916
1917 **/
1918 EFI_STATUS
1919 ConSplitterTextInDeleteDevice (
1920 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
1921 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *TextIn
1922 )
1923 {
1924 UINTN Index;
1925 //
1926 // Remove the specified text-in device data structure from the Text In List,
1927 // and rearrange the remaining data structures in the Text In List.
1928 //
1929 for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {
1930 if (Private->TextInList[Index] == TextIn) {
1931 for (; Index < Private->CurrentNumberOfConsoles - 1; Index++) {
1932 Private->TextInList[Index] = Private->TextInList[Index + 1];
1933 }
1934
1935 Private->CurrentNumberOfConsoles--;
1936 return EFI_SUCCESS;
1937 }
1938 }
1939
1940 return EFI_NOT_FOUND;
1941 }
1942
1943 /**
1944 Add Text Input Ex Device in Consplitter Text Input Ex list.
1945
1946 @param Private Text In Splitter pointer.
1947 @param TextInEx Simple Text Input Ex Input protocol pointer.
1948
1949 @retval EFI_SUCCESS Text Input Ex Device added successfully.
1950 @retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
1951
1952 **/
1953 EFI_STATUS
1954 ConSplitterTextInExAddDevice (
1955 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
1956 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TextInEx
1957 )
1958 {
1959 EFI_STATUS Status;
1960 LIST_ENTRY *Link;
1961 TEXT_IN_EX_SPLITTER_NOTIFY *CurrentNotify;
1962 UINTN TextInExListCount;
1963
1964 //
1965 // Enlarge the NotifyHandleList and the TextInExList
1966 //
1967 if (Private->CurrentNumberOfExConsoles >= Private->TextInExListCount) {
1968 for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {
1969 CurrentNotify = TEXT_IN_EX_SPLITTER_NOTIFY_FROM_THIS (Link);
1970 TextInExListCount = Private->TextInExListCount;
1971
1972 Status = ConSplitterGrowBuffer (
1973 sizeof (EFI_HANDLE),
1974 &TextInExListCount,
1975 (VOID **) &CurrentNotify->NotifyHandleList
1976 );
1977 if (EFI_ERROR (Status)) {
1978 return EFI_OUT_OF_RESOURCES;
1979 }
1980 }
1981
1982 TextInExListCount = Private->TextInExListCount;
1983 Status = ConSplitterGrowBuffer (
1984 sizeof (EFI_KEY_DATA),
1985 &TextInExListCount,
1986 (VOID **) &Private->KeyQueue
1987 );
1988 if (EFI_ERROR (Status)) {
1989 return EFI_OUT_OF_RESOURCES;
1990 }
1991
1992 Status = ConSplitterGrowBuffer (
1993 sizeof (EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *),
1994 &Private->TextInExListCount,
1995 (VOID **) &Private->TextInExList
1996 );
1997 if (EFI_ERROR (Status)) {
1998 return EFI_OUT_OF_RESOURCES;
1999 }
2000 }
2001
2002 //
2003 // Register the key notify in the new text-in device
2004 //
2005 for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {
2006 CurrentNotify = TEXT_IN_EX_SPLITTER_NOTIFY_FROM_THIS (Link);
2007 Status = TextInEx->RegisterKeyNotify (
2008 TextInEx,
2009 &CurrentNotify->KeyData,
2010 CurrentNotify->KeyNotificationFn,
2011 &CurrentNotify->NotifyHandleList[Private->CurrentNumberOfExConsoles]
2012 );
2013 if (EFI_ERROR (Status)) {
2014 for (Link = Link->BackLink; Link != &Private->NotifyList; Link = Link->BackLink) {
2015 CurrentNotify = TEXT_IN_EX_SPLITTER_NOTIFY_FROM_THIS (Link);
2016 TextInEx->UnregisterKeyNotify (
2017 TextInEx,
2018 CurrentNotify->NotifyHandleList[Private->CurrentNumberOfExConsoles]
2019 );
2020 }
2021 return Status;
2022 }
2023 }
2024
2025 //
2026 // Add the new text-in device data structure into the Text Input Ex List.
2027 //
2028 Private->TextInExList[Private->CurrentNumberOfExConsoles] = TextInEx;
2029 Private->CurrentNumberOfExConsoles++;
2030
2031 //
2032 // Sync current toggle state to this new console input device.
2033 //
2034 TextInEx->SetState (TextInEx, &Private->PhysicalKeyToggleState);
2035
2036 //
2037 // Extra CheckEvent added to reduce the double CheckEvent().
2038 //
2039 gBS->CheckEvent (TextInEx->WaitForKeyEx);
2040
2041 return EFI_SUCCESS;
2042 }
2043
2044 /**
2045 Remove Text Ex Device from Consplitter Text Input Ex list.
2046
2047 @param Private Text In Splitter pointer.
2048 @param TextInEx Simple Text Ex protocol pointer.
2049
2050 @retval EFI_SUCCESS Simple Text Input Ex Device removed successfully.
2051 @retval EFI_NOT_FOUND No Simple Text Input Ex Device found.
2052
2053 **/
2054 EFI_STATUS
2055 ConSplitterTextInExDeleteDevice (
2056 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
2057 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TextInEx
2058 )
2059 {
2060 UINTN Index;
2061 //
2062 // Remove the specified text-in device data structure from the Text Input Ex List,
2063 // and rearrange the remaining data structures in the Text In List.
2064 //
2065 for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {
2066 if (Private->TextInExList[Index] == TextInEx) {
2067 for (; Index < Private->CurrentNumberOfExConsoles - 1; Index++) {
2068 Private->TextInExList[Index] = Private->TextInExList[Index + 1];
2069 }
2070
2071 Private->CurrentNumberOfExConsoles--;
2072 return EFI_SUCCESS;
2073 }
2074 }
2075
2076 return EFI_NOT_FOUND;
2077 }
2078
2079
2080 /**
2081 Add Simple Pointer Device in Consplitter Simple Pointer list.
2082
2083 @param Private Text In Splitter pointer.
2084 @param SimplePointer Simple Pointer protocol pointer.
2085
2086 @retval EFI_SUCCESS Simple Pointer Device added successfully.
2087 @retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
2088
2089 **/
2090 EFI_STATUS
2091 ConSplitterSimplePointerAddDevice (
2092 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
2093 IN EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer
2094 )
2095 {
2096 EFI_STATUS Status;
2097
2098 //
2099 // If the Simple Pointer List is full, enlarge it by calling ConSplitterGrowBuffer().
2100 //
2101 if (Private->CurrentNumberOfPointers >= Private->PointerListCount) {
2102 Status = ConSplitterGrowBuffer (
2103 sizeof (EFI_SIMPLE_POINTER_PROTOCOL *),
2104 &Private->PointerListCount,
2105 (VOID **) &Private->PointerList
2106 );
2107 if (EFI_ERROR (Status)) {
2108 return EFI_OUT_OF_RESOURCES;
2109 }
2110 }
2111 //
2112 // Add the new text-in device data structure into the Simple Pointer List.
2113 //
2114 Private->PointerList[Private->CurrentNumberOfPointers] = SimplePointer;
2115 Private->CurrentNumberOfPointers++;
2116
2117 return EFI_SUCCESS;
2118 }
2119
2120
2121 /**
2122 Remove Simple Pointer Device from Consplitter Simple Pointer list.
2123
2124 @param Private Text In Splitter pointer.
2125 @param SimplePointer Simple Pointer protocol pointer.
2126
2127 @retval EFI_SUCCESS Simple Pointer Device removed successfully.
2128 @retval EFI_NOT_FOUND No Simple Pointer Device found.
2129
2130 **/
2131 EFI_STATUS
2132 ConSplitterSimplePointerDeleteDevice (
2133 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
2134 IN EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer
2135 )
2136 {
2137 UINTN Index;
2138 //
2139 // Remove the specified text-in device data structure from the Simple Pointer List,
2140 // and rearrange the remaining data structures in the Text In List.
2141 //
2142 for (Index = 0; Index < Private->CurrentNumberOfPointers; Index++) {
2143 if (Private->PointerList[Index] == SimplePointer) {
2144 for (; Index < Private->CurrentNumberOfPointers - 1; Index++) {
2145 Private->PointerList[Index] = Private->PointerList[Index + 1];
2146 }
2147
2148 Private->CurrentNumberOfPointers--;
2149 return EFI_SUCCESS;
2150 }
2151 }
2152
2153 return EFI_NOT_FOUND;
2154 }
2155
2156
2157 /**
2158 Add Absolute Pointer Device in Consplitter Absolute Pointer list.
2159
2160 @param Private Text In Splitter pointer.
2161 @param AbsolutePointer Absolute Pointer protocol pointer.
2162
2163 @retval EFI_SUCCESS Absolute Pointer Device added successfully.
2164 @retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
2165
2166 **/
2167 EFI_STATUS
2168 ConSplitterAbsolutePointerAddDevice (
2169 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
2170 IN EFI_ABSOLUTE_POINTER_PROTOCOL *AbsolutePointer
2171 )
2172 {
2173 EFI_STATUS Status;
2174
2175 //
2176 // If the Absolute Pointer List is full, enlarge it by calling ConSplitterGrowBuffer().
2177 //
2178 if (Private->CurrentNumberOfAbsolutePointers >= Private->AbsolutePointerListCount) {
2179 Status = ConSplitterGrowBuffer (
2180 sizeof (EFI_ABSOLUTE_POINTER_PROTOCOL *),
2181 &Private->AbsolutePointerListCount,
2182 (VOID **) &Private->AbsolutePointerList
2183 );
2184 if (EFI_ERROR (Status)) {
2185 return EFI_OUT_OF_RESOURCES;
2186 }
2187 }
2188 //
2189 // Add the new text-in device data structure into the Absolute Pointer List.
2190 //
2191 Private->AbsolutePointerList[Private->CurrentNumberOfAbsolutePointers] = AbsolutePointer;
2192 Private->CurrentNumberOfAbsolutePointers++;
2193
2194 return EFI_SUCCESS;
2195 }
2196
2197
2198 /**
2199 Remove Absolute Pointer Device from Consplitter Absolute Pointer list.
2200
2201 @param Private Text In Splitter pointer.
2202 @param AbsolutePointer Absolute Pointer protocol pointer.
2203
2204 @retval EFI_SUCCESS Absolute Pointer Device removed successfully.
2205 @retval EFI_NOT_FOUND No Absolute Pointer Device found.
2206
2207 **/
2208 EFI_STATUS
2209 ConSplitterAbsolutePointerDeleteDevice (
2210 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
2211 IN EFI_ABSOLUTE_POINTER_PROTOCOL *AbsolutePointer
2212 )
2213 {
2214 UINTN Index;
2215 //
2216 // Remove the specified text-in device data structure from the Absolute Pointer List,
2217 // and rearrange the remaining data structures from the Absolute Pointer List.
2218 //
2219 for (Index = 0; Index < Private->CurrentNumberOfAbsolutePointers; Index++) {
2220 if (Private->AbsolutePointerList[Index] == AbsolutePointer) {
2221 for (; Index < Private->CurrentNumberOfAbsolutePointers - 1; Index++) {
2222 Private->AbsolutePointerList[Index] = Private->AbsolutePointerList[Index + 1];
2223 }
2224
2225 Private->CurrentNumberOfAbsolutePointers--;
2226 return EFI_SUCCESS;
2227 }
2228 }
2229
2230 return EFI_NOT_FOUND;
2231 }
2232
2233 /**
2234 Reallocate Text Out mode map.
2235
2236 Allocate new buffer and copy original buffer into the new buffer.
2237
2238 @param Private Consplitter Text Out pointer.
2239
2240 @retval EFI_SUCCESS Buffer size has grown
2241 @retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
2242
2243 **/
2244 EFI_STATUS
2245 ConSplitterGrowMapTable (
2246 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private
2247 )
2248 {
2249 UINTN Size;
2250 UINTN NewSize;
2251 UINTN TotalSize;
2252 INT32 *TextOutModeMap;
2253 INT32 *OldTextOutModeMap;
2254 INT32 *SrcAddress;
2255 INT32 Index;
2256 UINTN OldStepSize;
2257 UINTN NewStepSize;
2258
2259 NewSize = Private->TextOutListCount * sizeof (INT32);
2260 OldTextOutModeMap = Private->TextOutModeMap;
2261 TotalSize = NewSize * (Private->TextOutQueryDataCount);
2262
2263 //
2264 // Allocate new buffer for Text Out List.
2265 //
2266 TextOutModeMap = AllocatePool (TotalSize);
2267 if (TextOutModeMap == NULL) {
2268 return EFI_OUT_OF_RESOURCES;
2269 }
2270
2271 SetMem (TextOutModeMap, TotalSize, 0xFF);
2272 Private->TextOutModeMap = TextOutModeMap;
2273
2274 //
2275 // If TextOutList has been enlarged, need to realloc the mode map table
2276 // The mode map table is regarded as a two dimension array.
2277 //
2278 // Old New
2279 // 0 ---------> TextOutListCount ----> TextOutListCount
2280 // | -------------------------------------------
2281 // | | | |
2282 // | | | |
2283 // | | | |
2284 // | | | |
2285 // | | | |
2286 // \/ | | |
2287 // -------------------------------------------
2288 // QueryDataCount
2289 //
2290 if (OldTextOutModeMap != NULL) {
2291
2292 Size = Private->CurrentNumberOfConsoles * sizeof (INT32);
2293 Index = 0;
2294 SrcAddress = OldTextOutModeMap;
2295 NewStepSize = NewSize / sizeof(INT32);
2296 // If Private->CurrentNumberOfConsoles is not zero and OldTextOutModeMap
2297 // is not NULL, it indicates that the original TextOutModeMap is not enough
2298 // for the new console devices and has been enlarged by CONSOLE_SPLITTER_ALLOC_UNIT columns.
2299 //
2300 OldStepSize = NewStepSize - CONSOLE_SPLITTER_ALLOC_UNIT;
2301
2302 //
2303 // Copy the old data to the new one
2304 //
2305 while (Index < Private->TextOutMode.MaxMode) {
2306 CopyMem (TextOutModeMap, SrcAddress, Size);
2307 //
2308 // Go to next row of new TextOutModeMap.
2309 //
2310 TextOutModeMap += NewStepSize;
2311 //
2312 // Go to next row of old TextOutModeMap.
2313 //
2314 SrcAddress += OldStepSize;
2315 Index++;
2316 }
2317 //
2318 // Free the old buffer
2319 //
2320 FreePool (OldTextOutModeMap);
2321 }
2322
2323 return EFI_SUCCESS;
2324 }
2325
2326
2327 /**
2328 Add new device's output mode to console splitter's mode list.
2329
2330 @param Private Text Out Splitter pointer
2331 @param TextOut Simple Text Output protocol pointer.
2332
2333 @retval EFI_SUCCESS Device added successfully.
2334 @retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
2335
2336 **/
2337 EFI_STATUS
2338 ConSplitterAddOutputMode (
2339 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
2340 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut
2341 )
2342 {
2343 EFI_STATUS Status;
2344 INT32 MaxMode;
2345 INT32 Mode;
2346 UINTN Index;
2347
2348 MaxMode = TextOut->Mode->MaxMode;
2349 Private->TextOutMode.MaxMode = MaxMode;
2350
2351 //
2352 // Grow the buffer if query data buffer is not large enough to
2353 // hold all the mode supported by the first console.
2354 //
2355 while (MaxMode > (INT32) Private->TextOutQueryDataCount) {
2356 Status = ConSplitterGrowBuffer (
2357 sizeof (TEXT_OUT_SPLITTER_QUERY_DATA),
2358 &Private->TextOutQueryDataCount,
2359 (VOID **) &Private->TextOutQueryData
2360 );
2361 if (EFI_ERROR (Status)) {
2362 return EFI_OUT_OF_RESOURCES;
2363 }
2364 }
2365 //
2366 // Allocate buffer for the output mode map
2367 //
2368 Status = ConSplitterGrowMapTable (Private);
2369 if (EFI_ERROR (Status)) {
2370 return EFI_OUT_OF_RESOURCES;
2371 }
2372 //
2373 // As the first textout device, directly add the mode in to QueryData
2374 // and at the same time record the mapping between QueryData and TextOut.
2375 //
2376 Mode = 0;
2377 Index = 0;
2378 while (Mode < MaxMode) {
2379 Status = TextOut->QueryMode (
2380 TextOut,
2381 Mode,
2382 &Private->TextOutQueryData[Mode].Columns,
2383 &Private->TextOutQueryData[Mode].Rows
2384 );
2385 //
2386 // If mode 1 (80x50) is not supported, make sure mode 1 in TextOutQueryData
2387 // is clear to 0x0.
2388 //
2389 if ((EFI_ERROR(Status)) && (Mode == 1)) {
2390 Private->TextOutQueryData[Mode].Columns = 0;
2391 Private->TextOutQueryData[Mode].Rows = 0;
2392 }
2393 Private->TextOutModeMap[Index] = Mode;
2394 Mode++;
2395 Index += Private->TextOutListCount;
2396 }
2397
2398 return EFI_SUCCESS;
2399 }
2400
2401 /**
2402 Reconstruct TextOutModeMap to get intersection of modes.
2403
2404 This routine reconstruct TextOutModeMap to get the intersection
2405 of modes for all console out devices. Because EFI/UEFI spec require
2406 mode 0 is 80x25, mode 1 is 80x50, this routine will not check the
2407 intersection for mode 0 and mode 1.
2408
2409 @param TextOutModeMap Current text out mode map, begin with the mode 80x25
2410 @param NewlyAddedMap New text out mode map, begin with the mode 80x25
2411 @param MapStepSize Mode step size for one console device
2412 @param NewMapStepSize New Mode step size for one console device
2413 @param MaxMode IN: Current max text mode, OUT: Updated max text mode.
2414 @param CurrentMode IN: Current text mode, OUT: Updated current text mode.
2415
2416 **/
2417 VOID
2418 ConSplitterGetIntersection (
2419 IN INT32 *TextOutModeMap,
2420 IN INT32 *NewlyAddedMap,
2421 IN UINTN MapStepSize,
2422 IN UINTN NewMapStepSize,
2423 IN OUT INT32 *MaxMode,
2424 IN OUT INT32 *CurrentMode
2425 )
2426 {
2427 INT32 Index;
2428 INT32 *CurrentMapEntry;
2429 INT32 *NextMapEntry;
2430 INT32 *NewMapEntry;
2431 INT32 CurrentMaxMode;
2432 INT32 Mode;
2433
2434 //
2435 // According to EFI/UEFI spec, mode 0 and mode 1 have been reserved
2436 // for 80x25 and 80x50 in Simple Text Out protocol, so don't make intersection
2437 // for mode 0 and mode 1, mode number starts from 2.
2438 //
2439 Index = 2;
2440 CurrentMapEntry = &TextOutModeMap[MapStepSize * 2];
2441 NextMapEntry = CurrentMapEntry;
2442 NewMapEntry = &NewlyAddedMap[NewMapStepSize * 2];
2443
2444 CurrentMaxMode = *MaxMode;
2445 Mode = *CurrentMode;
2446
2447 while (Index < CurrentMaxMode) {
2448 if (*NewMapEntry == -1) {
2449 //
2450 // This mode is not supported any more. Remove it. Special care
2451 // must be taken as this remove will also affect current mode;
2452 //
2453 if (Index == *CurrentMode) {
2454 Mode = -1;
2455 } else if (Index < *CurrentMode) {
2456 Mode--;
2457 }
2458 (*MaxMode)--;
2459 } else {
2460 if (CurrentMapEntry != NextMapEntry) {
2461 CopyMem (NextMapEntry, CurrentMapEntry, MapStepSize * sizeof (INT32));
2462 }
2463
2464 NextMapEntry += MapStepSize;
2465 }
2466
2467 CurrentMapEntry += MapStepSize;
2468 NewMapEntry += NewMapStepSize;
2469 Index++;
2470 }
2471
2472 *CurrentMode = Mode;
2473
2474 return ;
2475 }
2476
2477 /**
2478 Sync the device's output mode to console splitter's mode list.
2479
2480 @param Private Text Out Splitter pointer.
2481 @param TextOut Simple Text Output protocol pointer.
2482
2483 **/
2484 VOID
2485 ConSplitterSyncOutputMode (
2486 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
2487 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut
2488 )
2489 {
2490 INT32 CurrentMaxMode;
2491 INT32 Mode;
2492 INT32 Index;
2493 INT32 *TextOutModeMap;
2494 INT32 *MapTable;
2495 INT32 QueryMode;
2496 TEXT_OUT_SPLITTER_QUERY_DATA *TextOutQueryData;
2497 UINTN Rows;
2498 UINTN Columns;
2499 UINTN StepSize;
2500 EFI_STATUS Status;
2501
2502 //
2503 // Must make sure that current mode won't change even if mode number changes
2504 //
2505 CurrentMaxMode = Private->TextOutMode.MaxMode;
2506 TextOutModeMap = Private->TextOutModeMap;
2507 StepSize = Private->TextOutListCount;
2508 TextOutQueryData = Private->TextOutQueryData;
2509
2510 //
2511 // Query all the mode that the newly added TextOut supports
2512 //
2513 Mode = 0;
2514 MapTable = TextOutModeMap + Private->CurrentNumberOfConsoles;
2515 while (Mode < TextOut->Mode->MaxMode) {
2516 Status = TextOut->QueryMode (TextOut, Mode, &Columns, &Rows);
2517
2518 if (EFI_ERROR(Status)) {
2519 if (Mode == 1) {
2520 //
2521 // If mode 1 (80x50) is not supported, make sure mode 1 in TextOutQueryData
2522 // is clear to 0x0.
2523 //
2524 MapTable[StepSize] = Mode;
2525 TextOutQueryData[Mode].Columns = 0;
2526 TextOutQueryData[Mode].Rows = 0;
2527 }
2528 Mode++;
2529 continue;
2530 }
2531 //
2532 // Search the intersection map and QueryData database to see if they intersects
2533 //
2534 Index = 0;
2535 while (Index < CurrentMaxMode) {
2536 QueryMode = *(TextOutModeMap + Index * StepSize);
2537 if ((TextOutQueryData[QueryMode].Rows == Rows) && (TextOutQueryData[QueryMode].Columns == Columns)) {
2538 MapTable[Index * StepSize] = Mode;
2539 break;
2540 }
2541 Index++;
2542 }
2543 Mode++;
2544 }
2545 //
2546 // Now search the TextOutModeMap table to find the intersection of supported
2547 // mode between ConSplitter and the newly added device.
2548 //
2549 ConSplitterGetIntersection (
2550 TextOutModeMap,
2551 MapTable,
2552 StepSize,
2553 StepSize,
2554 &Private->TextOutMode.MaxMode,
2555 &Private->TextOutMode.Mode
2556 );
2557
2558 return ;
2559 }
2560
2561
2562 /**
2563 Sync output device between ConOut and StdErr output.
2564
2565 @retval EFI_SUCCESS Sync implemented successfully.
2566 @retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
2567
2568 **/
2569 EFI_STATUS
2570 ConSplitterGetIntersectionBetweenConOutAndStrErr (
2571 VOID
2572 )
2573 {
2574 UINTN ConOutNumOfConsoles;
2575 UINTN StdErrNumOfConsoles;
2576 TEXT_OUT_AND_GOP_DATA *ConOutTextOutList;
2577 TEXT_OUT_AND_GOP_DATA *StdErrTextOutList;
2578 UINTN Indexi;
2579 UINTN Indexj;
2580 UINTN ConOutRows;
2581 UINTN ConOutColumns;
2582 UINTN StdErrRows;
2583 UINTN StdErrColumns;
2584 INT32 ConOutMaxMode;
2585 INT32 StdErrMaxMode;
2586 INT32 ConOutMode;
2587 INT32 StdErrMode;
2588 INT32 Mode;
2589 INT32 Index;
2590 INT32 *ConOutModeMap;
2591 INT32 *StdErrModeMap;
2592 INT32 *ConOutMapTable;
2593 INT32 *StdErrMapTable;
2594 TEXT_OUT_SPLITTER_QUERY_DATA *ConOutQueryData;
2595 TEXT_OUT_SPLITTER_QUERY_DATA *StdErrQueryData;
2596 UINTN ConOutStepSize;
2597 UINTN StdErrStepSize;
2598 BOOLEAN FoundTheSameTextOut;
2599 UINTN ConOutMapTableSize;
2600 UINTN StdErrMapTableSize;
2601
2602 ConOutNumOfConsoles = mConOut.CurrentNumberOfConsoles;
2603 StdErrNumOfConsoles = mStdErr.CurrentNumberOfConsoles;
2604 ConOutTextOutList = mConOut.TextOutList;
2605 StdErrTextOutList = mStdErr.TextOutList;
2606
2607 Indexi = 0;
2608 FoundTheSameTextOut = FALSE;
2609 while ((Indexi < ConOutNumOfConsoles) && (!FoundTheSameTextOut)) {
2610 Indexj = 0;
2611 while (Indexj < StdErrNumOfConsoles) {
2612 if (ConOutTextOutList->TextOut == StdErrTextOutList->TextOut) {
2613 FoundTheSameTextOut = TRUE;
2614 break;
2615 }
2616
2617 Indexj++;
2618 StdErrTextOutList++;
2619 }
2620
2621 Indexi++;
2622 ConOutTextOutList++;
2623 }
2624
2625 if (!FoundTheSameTextOut) {
2626 return EFI_SUCCESS;
2627 }
2628 //
2629 // Must make sure that current mode won't change even if mode number changes
2630 //
2631 ConOutMaxMode = mConOut.TextOutMode.MaxMode;
2632 ConOutModeMap = mConOut.TextOutModeMap;
2633 ConOutStepSize = mConOut.TextOutListCount;
2634 ConOutQueryData = mConOut.TextOutQueryData;
2635
2636 StdErrMaxMode = mStdErr.TextOutMode.MaxMode;
2637 StdErrModeMap = mStdErr.TextOutModeMap;
2638 StdErrStepSize = mStdErr.TextOutListCount;
2639 StdErrQueryData = mStdErr.TextOutQueryData;
2640
2641 //
2642 // Allocate the map table and set the map table's index to -1.
2643 //
2644 ConOutMapTableSize = ConOutMaxMode * sizeof (INT32);
2645 ConOutMapTable = AllocateZeroPool (ConOutMapTableSize);
2646 if (ConOutMapTable == NULL) {
2647 return EFI_OUT_OF_RESOURCES;
2648 }
2649
2650 SetMem (ConOutMapTable, ConOutMapTableSize, 0xFF);
2651
2652 StdErrMapTableSize = StdErrMaxMode * sizeof (INT32);
2653 StdErrMapTable = AllocateZeroPool (StdErrMapTableSize);
2654 if (StdErrMapTable == NULL) {
2655 return EFI_OUT_OF_RESOURCES;
2656 }
2657
2658 SetMem (StdErrMapTable, StdErrMapTableSize, 0xFF);
2659
2660 //
2661 // Find the intersection of the two set of modes. If they actually intersect, the
2662 // corresponding entry in the map table is set to 1.
2663 //
2664 Mode = 0;
2665 while (Mode < ConOutMaxMode) {
2666 //
2667 // Search the intersection map and QueryData database to see if they intersect
2668 //
2669 Index = 0;
2670 ConOutMode = *(ConOutModeMap + Mode * ConOutStepSize);
2671 ConOutRows = ConOutQueryData[ConOutMode].Rows;
2672 ConOutColumns = ConOutQueryData[ConOutMode].Columns;
2673 while (Index < StdErrMaxMode) {
2674 StdErrMode = *(StdErrModeMap + Index * StdErrStepSize);
2675 StdErrRows = StdErrQueryData[StdErrMode].Rows;
2676 StdErrColumns = StdErrQueryData[StdErrMode].Columns;
2677 if ((StdErrRows == ConOutRows) && (StdErrColumns == ConOutColumns)) {
2678 ConOutMapTable[Mode] = 1;
2679 StdErrMapTable[Index] = 1;
2680 break;
2681 }
2682
2683 Index++;
2684 }
2685
2686 Mode++;
2687 }
2688 //
2689 // Now search the TextOutModeMap table to find the intersection of supported
2690 // mode between ConSplitter and the newly added device.
2691 //
2692 ConSplitterGetIntersection (
2693 ConOutModeMap,
2694 ConOutMapTable,
2695 mConOut.TextOutListCount,
2696 1,
2697 &(mConOut.TextOutMode.MaxMode),
2698 &(mConOut.TextOutMode.Mode)
2699 );
2700
2701 if (mConOut.TextOutMode.Mode < 0) {
2702 mConOut.TextOut.SetMode (&(mConOut.TextOut), 0);
2703 }
2704
2705 ConSplitterGetIntersection (
2706 StdErrModeMap,
2707 StdErrMapTable,
2708 mStdErr.TextOutListCount,
2709 1,
2710 &(mStdErr.TextOutMode.MaxMode),
2711 &(mStdErr.TextOutMode.Mode)
2712 );
2713
2714 if (mStdErr.TextOutMode.Mode < 0) {
2715 mStdErr.TextOut.SetMode (&(mStdErr.TextOut), 0);
2716 }
2717
2718 FreePool (ConOutMapTable);
2719 FreePool (StdErrMapTable);
2720
2721 return EFI_SUCCESS;
2722 }
2723
2724
2725 /**
2726 Add Grahpics Output modes into Consplitter Text Out list.
2727
2728 @param Private Text Out Splitter pointer.
2729 @param GraphicsOutput Graphics Output protocol pointer.
2730 @param UgaDraw UGA Draw protocol pointer.
2731
2732 @retval EFI_SUCCESS Output mode added successfully.
2733 @retval other Failed to add output mode.
2734
2735 **/
2736 EFI_STATUS
2737 ConSplitterAddGraphicsOutputMode (
2738 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
2739 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput,
2740 IN EFI_UGA_DRAW_PROTOCOL *UgaDraw
2741 )
2742 {
2743 EFI_STATUS Status;
2744 UINTN Index;
2745 UINTN CurrentIndex;
2746 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Mode;
2747 UINTN SizeOfInfo;
2748 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
2749 EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *CurrentGraphicsOutputMode;
2750 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *ModeBuffer;
2751 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *MatchedMode;
2752 UINTN NumberIndex;
2753 BOOLEAN Match;
2754 BOOLEAN AlreadyExist;
2755 UINT32 UgaHorizontalResolution;
2756 UINT32 UgaVerticalResolution;
2757 UINT32 UgaColorDepth;
2758 UINT32 UgaRefreshRate;
2759
2760 ASSERT (GraphicsOutput != NULL || UgaDraw != NULL);
2761
2762 CurrentGraphicsOutputMode = Private->GraphicsOutput.Mode;
2763
2764 Index = 0;
2765 CurrentIndex = 0;
2766 Status = EFI_SUCCESS;
2767
2768 if (Private->CurrentNumberOfUgaDraw != 0) {
2769 //
2770 // If any UGA device has already been added, then there is no need to
2771 // calculate intersection of display mode of different GOP/UGA device,
2772 // since only one display mode will be exported (i.e. user-defined mode)
2773 //
2774 goto Done;
2775 }
2776
2777 if (GraphicsOutput != NULL) {
2778 if (Private->CurrentNumberOfGraphicsOutput == 0) {
2779 //
2780 // This is the first Graphics Output device added
2781 //
2782 CurrentGraphicsOutputMode->MaxMode = GraphicsOutput->Mode->MaxMode;
2783 CurrentGraphicsOutputMode->Mode = GraphicsOutput->Mode->Mode;
2784 CopyMem (CurrentGraphicsOutputMode->Info, GraphicsOutput->Mode->Info, GraphicsOutput->Mode->SizeOfInfo);
2785 CurrentGraphicsOutputMode->SizeOfInfo = GraphicsOutput->Mode->SizeOfInfo;
2786 CurrentGraphicsOutputMode->FrameBufferBase = GraphicsOutput->Mode->FrameBufferBase;
2787 CurrentGraphicsOutputMode->FrameBufferSize = GraphicsOutput->Mode->FrameBufferSize;
2788
2789 //
2790 // Allocate resource for the private mode buffer
2791 //
2792 ModeBuffer = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION) * GraphicsOutput->Mode->MaxMode);
2793 if (ModeBuffer == NULL) {
2794 return EFI_OUT_OF_RESOURCES;
2795 }
2796 FreePool (Private->GraphicsOutputModeBuffer);
2797 Private->GraphicsOutputModeBuffer = ModeBuffer;
2798
2799 //
2800 // Store all supported display modes to the private mode buffer
2801 //
2802 Mode = ModeBuffer;
2803 for (Index = 0; Index < GraphicsOutput->Mode->MaxMode; Index++) {
2804 //
2805 // The Info buffer would be allocated by callee
2806 //
2807 Status = GraphicsOutput->QueryMode (GraphicsOutput, (UINT32) Index, &SizeOfInfo, &Info);
2808 if (EFI_ERROR (Status)) {
2809 return Status;
2810 }
2811 ASSERT ( SizeOfInfo <= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
2812 CopyMem (Mode, Info, SizeOfInfo);
2813 Mode++;
2814 FreePool (Info);
2815 }
2816 } else {
2817 //
2818 // Check intersection of display mode
2819 //
2820 ModeBuffer = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION) * CurrentGraphicsOutputMode->MaxMode);
2821 if (ModeBuffer == NULL) {
2822 return EFI_OUT_OF_RESOURCES;
2823 }
2824
2825 MatchedMode = ModeBuffer;
2826 Mode = &Private->GraphicsOutputModeBuffer[0];
2827 for (Index = 0; Index < CurrentGraphicsOutputMode->MaxMode; Index++) {
2828 Match = FALSE;
2829
2830 for (NumberIndex = 0; NumberIndex < GraphicsOutput->Mode->MaxMode; NumberIndex++) {
2831 //
2832 // The Info buffer would be allocated by callee
2833 //
2834 Status = GraphicsOutput->QueryMode (GraphicsOutput, (UINT32) NumberIndex, &SizeOfInfo, &Info);
2835 if (EFI_ERROR (Status)) {
2836 return Status;
2837 }
2838 if ((Info->HorizontalResolution == Mode->HorizontalResolution) &&
2839 (Info->VerticalResolution == Mode->VerticalResolution)) {
2840 //
2841 // If GOP device supports one mode in current mode buffer,
2842 // it will be added into matched mode buffer
2843 //
2844 Match = TRUE;
2845 FreePool (Info);
2846 break;
2847 }
2848 FreePool (Info);
2849 }
2850
2851 if (Match) {
2852 AlreadyExist = FALSE;
2853
2854 //
2855 // Check if GOP mode has been in the mode buffer, ModeBuffer = MatchedMode at begin.
2856 //
2857 for (Info = ModeBuffer; Info < MatchedMode; Info++) {
2858 if ((Info->HorizontalResolution == Mode->HorizontalResolution) &&
2859 (Info->VerticalResolution == Mode->VerticalResolution)) {
2860 AlreadyExist = TRUE;
2861 break;
2862 }
2863 }
2864
2865 if (!AlreadyExist) {
2866 CopyMem (MatchedMode, Mode, sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
2867
2868 //
2869 // Physical frame buffer is no longer available, change PixelFormat to PixelBltOnly
2870 //
2871 MatchedMode->Version = 0;
2872 MatchedMode->PixelFormat = PixelBltOnly;
2873 ZeroMem (&MatchedMode->PixelInformation, sizeof (EFI_PIXEL_BITMASK));
2874
2875 MatchedMode++;
2876 }
2877 }
2878
2879 Mode++;
2880 }
2881
2882 //
2883 // Drop the old mode buffer, assign it to a new one
2884 //
2885 FreePool (Private->GraphicsOutputModeBuffer);
2886 Private->GraphicsOutputModeBuffer = ModeBuffer;
2887
2888 //
2889 // Physical frame buffer is no longer available when there are more than one physical GOP devices
2890 //
2891 CurrentGraphicsOutputMode->MaxMode = (UINT32) (((UINTN) MatchedMode - (UINTN) ModeBuffer) / sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
2892 CurrentGraphicsOutputMode->Info->PixelFormat = PixelBltOnly;
2893 ZeroMem (&CurrentGraphicsOutputMode->Info->PixelInformation, sizeof (EFI_PIXEL_BITMASK));
2894 CurrentGraphicsOutputMode->SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
2895 CurrentGraphicsOutputMode->FrameBufferBase = (EFI_PHYSICAL_ADDRESS) (UINTN) NULL;
2896 CurrentGraphicsOutputMode->FrameBufferSize = 0;
2897 }
2898
2899 //
2900 // Graphics console driver can ensure the same mode for all GOP devices
2901 //
2902 for (Index = 0; Index < CurrentGraphicsOutputMode->MaxMode; Index++) {
2903 Mode = &Private->GraphicsOutputModeBuffer[Index];
2904 if ((Mode->HorizontalResolution == GraphicsOutput->Mode->Info->HorizontalResolution) &&
2905 (Mode->VerticalResolution == GraphicsOutput->Mode->Info->VerticalResolution)) {
2906 CurrentIndex = Index;
2907 break;
2908 }
2909 }
2910 if (Index >= CurrentGraphicsOutputMode->MaxMode) {
2911 //
2912 // if user defined mode is not found, set to default mode 800x600
2913 //
2914 for (Index = 0; Index < CurrentGraphicsOutputMode->MaxMode; Index++) {
2915 Mode = &Private->GraphicsOutputModeBuffer[Index];
2916 if ((Mode->HorizontalResolution == 800) && (Mode->VerticalResolution == 600)) {
2917 CurrentIndex = Index;
2918 break;
2919 }
2920 }
2921 }
2922 } else if (UgaDraw != NULL) {
2923 //
2924 // Graphics console driver can ensure the same mode for all GOP devices
2925 // so we can get the current mode from this video device
2926 //
2927 UgaDraw->GetMode (
2928 UgaDraw,
2929 &UgaHorizontalResolution,
2930 &UgaVerticalResolution,
2931 &UgaColorDepth,
2932 &UgaRefreshRate
2933 );
2934
2935 CurrentGraphicsOutputMode->MaxMode = 1;
2936 Info = CurrentGraphicsOutputMode->Info;
2937 Info->Version = 0;
2938 Info->HorizontalResolution = UgaHorizontalResolution;
2939 Info->VerticalResolution = UgaVerticalResolution;
2940 Info->PixelFormat = PixelBltOnly;
2941 Info->PixelsPerScanLine = UgaHorizontalResolution;
2942 CurrentGraphicsOutputMode->SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
2943 CurrentGraphicsOutputMode->FrameBufferBase = (EFI_PHYSICAL_ADDRESS) (UINTN) NULL;
2944 CurrentGraphicsOutputMode->FrameBufferSize = 0;
2945
2946 //
2947 // Update the private mode buffer
2948 //
2949 CopyMem (&Private->GraphicsOutputModeBuffer[0], Info, sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
2950
2951 //
2952 // Only mode 0 is available to be set
2953 //
2954 CurrentIndex = 0;
2955 }
2956
2957 Done:
2958
2959 if (GraphicsOutput != NULL) {
2960 Private->CurrentNumberOfGraphicsOutput++;
2961 }
2962 if (UgaDraw != NULL) {
2963 Private->CurrentNumberOfUgaDraw++;
2964 }
2965
2966 //
2967 // Force GraphicsOutput mode to be set,
2968 //
2969
2970 Mode = &Private->GraphicsOutputModeBuffer[CurrentIndex];
2971 if ((GraphicsOutput != NULL) &&
2972 (Mode->HorizontalResolution == CurrentGraphicsOutputMode->Info->HorizontalResolution) &&
2973 (Mode->VerticalResolution == CurrentGraphicsOutputMode->Info->VerticalResolution)) {
2974 CurrentGraphicsOutputMode->Mode = (UINT32) CurrentIndex;
2975 if ((Mode->HorizontalResolution != GraphicsOutput->Mode->Info->HorizontalResolution) ||
2976 (Mode->VerticalResolution != GraphicsOutput->Mode->Info->VerticalResolution)) {
2977 //
2978 // If all existing video device has been set to common mode, only set new GOP device to
2979 // the common mode
2980 //
2981 for (NumberIndex = 0; NumberIndex < GraphicsOutput->Mode->MaxMode; NumberIndex ++) {
2982 Status = GraphicsOutput->QueryMode (GraphicsOutput, (UINT32) NumberIndex, &SizeOfInfo, &Info);
2983 if (EFI_ERROR (Status)) {
2984 return Status;
2985 }
2986 if ((Info->HorizontalResolution == Mode->HorizontalResolution) && (Info->VerticalResolution == Mode->VerticalResolution)) {
2987 FreePool (Info);
2988 break;
2989 }
2990 FreePool (Info);
2991 }
2992 Status = GraphicsOutput->SetMode (GraphicsOutput, (UINT32) NumberIndex);
2993 }
2994 } else {
2995 //
2996 // Current mode number may need update now, so set it to an invalid mode number
2997 //
2998 CurrentGraphicsOutputMode->Mode = 0xffff;
2999 //
3000 // Graphics console can ensure all GOP devices have the same mode which can be taken as current mode.
3001 //
3002 Status = Private->GraphicsOutput.SetMode (&Private->GraphicsOutput, (UINT32) CurrentIndex);
3003 if (EFI_ERROR(Status)) {
3004 //
3005 // If user defined mode is not valid for display device, set to the default mode 800x600.
3006 //
3007 (Private->GraphicsOutputModeBuffer[0]).HorizontalResolution = 800;
3008 (Private->GraphicsOutputModeBuffer[0]).VerticalResolution = 600;
3009 Status = Private->GraphicsOutput.SetMode (&Private->GraphicsOutput, 0);
3010 }
3011 }
3012
3013 return Status;
3014 }
3015
3016 /**
3017 Set the current console out mode.
3018
3019 This routine will get the current console mode information (column, row)
3020 from ConsoleOutMode variable and set it; if the variable does not exist,
3021 set to user defined console mode.
3022
3023 @param Private Consplitter Text Out pointer.
3024
3025 **/
3026 VOID
3027 ConsplitterSetConsoleOutMode (
3028 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private
3029 )
3030 {
3031 UINTN Col;
3032 UINTN Row;
3033 UINTN Mode;
3034 UINTN PreferMode;
3035 UINTN BaseMode;
3036 UINTN MaxMode;
3037 EFI_STATUS Status;
3038 CONSOLE_OUT_MODE ModeInfo;
3039 CONSOLE_OUT_MODE MaxModeInfo;
3040 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut;
3041
3042 PreferMode = 0xFF;
3043 BaseMode = 0xFF;
3044 TextOut = &Private->TextOut;
3045 MaxMode = (UINTN) (TextOut->Mode->MaxMode);
3046
3047 MaxModeInfo.Column = 0;
3048 MaxModeInfo.Row = 0;
3049 ModeInfo.Column = PcdGet32 (PcdConOutColumn);
3050 ModeInfo.Row = PcdGet32 (PcdConOutRow);
3051
3052 //
3053 // To find the prefer mode and basic mode from Text Out mode list
3054 //
3055 for (Mode = 0; Mode < MaxMode; Mode++) {
3056 Status = TextOut->QueryMode (TextOut, Mode, &Col, &Row);
3057 if (!EFI_ERROR(Status)) {
3058 if ((ModeInfo.Column != 0) && (ModeInfo.Row != 0)) {
3059 //
3060 // Use user defined column and row
3061 //
3062 if (Col == ModeInfo.Column && Row == ModeInfo.Row) {
3063 PreferMode = Mode;
3064 }
3065 } else {
3066 //
3067 // If user sets PcdConOutColumn or PcdConOutRow to 0,
3068 // find and set the highest text mode.
3069 //
3070 if ((Col >= MaxModeInfo.Column) && (Row >= MaxModeInfo.Row)) {
3071 MaxModeInfo.Column = Col;
3072 MaxModeInfo.Row = Row;
3073 PreferMode = Mode;
3074 }
3075 }
3076 if (Col == 80 && Row == 25) {
3077 BaseMode = Mode;
3078 }
3079 }
3080 }
3081
3082 //
3083 // Set prefer mode to Text Out devices.
3084 //
3085 Status = TextOut->SetMode (TextOut, PreferMode);
3086 if (EFI_ERROR(Status)) {
3087 //
3088 // if current mode setting is failed, default 80x25 mode will be set.
3089 //
3090 Status = TextOut->SetMode (TextOut, BaseMode);
3091 ASSERT(!EFI_ERROR(Status));
3092
3093 Status = PcdSet32S (PcdConOutColumn, 80);
3094 ASSERT(!EFI_ERROR(Status));
3095 Status = PcdSet32S (PcdConOutRow, 25);
3096 ASSERT(!EFI_ERROR(Status));
3097 }
3098
3099 return ;
3100 }
3101
3102
3103 /**
3104 Add Text Output Device in Consplitter Text Output list.
3105
3106 @param Private Text Out Splitter pointer.
3107 @param TextOut Simple Text Output protocol pointer.
3108 @param GraphicsOutput Graphics Output protocol pointer.
3109 @param UgaDraw UGA Draw protocol pointer.
3110
3111 @retval EFI_SUCCESS Text Output Device added successfully.
3112 @retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
3113
3114 **/
3115 EFI_STATUS
3116 ConSplitterTextOutAddDevice (
3117 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
3118 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut,
3119 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput,
3120 IN EFI_UGA_DRAW_PROTOCOL *UgaDraw
3121 )
3122 {
3123 EFI_STATUS Status;
3124 UINTN CurrentNumOfConsoles;
3125 INT32 MaxMode;
3126 UINT32 UgaHorizontalResolution;
3127 UINT32 UgaVerticalResolution;
3128 UINT32 UgaColorDepth;
3129 UINT32 UgaRefreshRate;
3130 TEXT_OUT_AND_GOP_DATA *TextAndGop;
3131 UINTN SizeOfInfo;
3132 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
3133 EFI_STATUS DeviceStatus;
3134
3135 Status = EFI_SUCCESS;
3136 CurrentNumOfConsoles = Private->CurrentNumberOfConsoles;
3137
3138 //
3139 // If the Text Out List is full, enlarge it by calling ConSplitterGrowBuffer().
3140 //
3141 while (CurrentNumOfConsoles >= Private->TextOutListCount) {
3142 Status = ConSplitterGrowBuffer (
3143 sizeof (TEXT_OUT_AND_GOP_DATA),
3144 &Private->TextOutListCount,
3145 (VOID **) &Private->TextOutList
3146 );
3147 if (EFI_ERROR (Status)) {
3148 return EFI_OUT_OF_RESOURCES;
3149 }
3150 //
3151 // Also need to reallocate the TextOutModeMap table
3152 //
3153 Status = ConSplitterGrowMapTable (Private);
3154 if (EFI_ERROR (Status)) {
3155 return EFI_OUT_OF_RESOURCES;
3156 }
3157 }
3158
3159 TextAndGop = &Private->TextOutList[CurrentNumOfConsoles];
3160
3161 TextAndGop->TextOut = TextOut;
3162 TextAndGop->GraphicsOutput = GraphicsOutput;
3163 TextAndGop->UgaDraw = UgaDraw;
3164
3165 if (CurrentNumOfConsoles == 0) {
3166 //
3167 // Add the first device's output mode to console splitter's mode list
3168 //
3169 Status = ConSplitterAddOutputMode (Private, TextOut);
3170 } else {
3171 ConSplitterSyncOutputMode (Private, TextOut);
3172 }
3173
3174 Private->CurrentNumberOfConsoles++;
3175
3176 //
3177 // Scan both TextOutList, for the intersection TextOut device
3178 // maybe both ConOut and StdErr incorporate the same Text Out
3179 // device in them, thus the output of both should be synced.
3180 //
3181 ConSplitterGetIntersectionBetweenConOutAndStrErr ();
3182
3183 MaxMode = Private->TextOutMode.MaxMode;
3184 ASSERT (MaxMode >= 1);
3185
3186 DeviceStatus = EFI_DEVICE_ERROR;
3187 Status = EFI_DEVICE_ERROR;
3188
3189 //
3190 // This device display mode will be added into Graphics Ouput modes.
3191 //
3192 if ((GraphicsOutput != NULL) || (UgaDraw != NULL)) {
3193 DeviceStatus = ConSplitterAddGraphicsOutputMode (Private, GraphicsOutput, UgaDraw);
3194 }
3195
3196 if (FeaturePcdGet (PcdConOutUgaSupport)) {
3197 //
3198 // If UGA is produced by Consplitter
3199 //
3200 if (GraphicsOutput != NULL) {
3201 Status = GraphicsOutput->QueryMode (GraphicsOutput, GraphicsOutput->Mode->Mode, &SizeOfInfo, &Info);
3202 if (EFI_ERROR (Status)) {
3203 return Status;
3204 }
3205 ASSERT ( SizeOfInfo <= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
3206
3207 UgaHorizontalResolution = Info->HorizontalResolution;
3208 UgaVerticalResolution = Info->VerticalResolution;
3209
3210 FreePool (Info);
3211
3212 } else if (UgaDraw != NULL) {
3213 Status = UgaDraw->GetMode (
3214 UgaDraw,
3215 &UgaHorizontalResolution,
3216 &UgaVerticalResolution,
3217 &UgaColorDepth,
3218 &UgaRefreshRate
3219 );
3220 if (!EFI_ERROR (Status) && EFI_ERROR (DeviceStatus)) {
3221 //
3222 // if GetMode is successfully and UGA device hasn't been set, set it
3223 //
3224 Status = ConSplitterUgaDrawSetMode (
3225 &Private->UgaDraw,
3226 UgaHorizontalResolution,
3227 UgaVerticalResolution,
3228 UgaColorDepth,
3229 UgaRefreshRate
3230 );
3231 }
3232 //
3233 // If GetMode/SetMode is failed, set to 800x600 mode
3234 //
3235 if(EFI_ERROR (Status)) {
3236 Status = ConSplitterUgaDrawSetMode (
3237 &Private->UgaDraw,
3238 800,
3239 600,
3240 32,
3241 60
3242 );
3243 }
3244 }
3245 }
3246
3247 if (((!EFI_ERROR (DeviceStatus)) || (!EFI_ERROR (Status))) &&
3248 ((Private->CurrentNumberOfGraphicsOutput + Private->CurrentNumberOfUgaDraw) == 1)) {
3249 if (!FeaturePcdGet (PcdConOutGopSupport)) {
3250 //
3251 // If Graphics Outpurt protocol not supported, UGA Draw protocol is installed
3252 // on the virtual handle.
3253 //
3254 Status = gBS->InstallMultipleProtocolInterfaces (
3255 &mConOut.VirtualHandle,
3256 &gEfiUgaDrawProtocolGuid,
3257 &mConOut.UgaDraw,
3258 NULL
3259 );
3260 } else if (!FeaturePcdGet (PcdConOutUgaSupport)) {
3261 //
3262 // If UGA Draw protocol not supported, Graphics Output Protocol is installed
3263 // on virtual handle.
3264 //
3265 Status = gBS->InstallMultipleProtocolInterfaces (
3266 &mConOut.VirtualHandle,
3267 &gEfiGraphicsOutputProtocolGuid,
3268 &mConOut.GraphicsOutput,
3269 NULL
3270 );
3271 } else {
3272 //
3273 // Boot Graphics Output protocol and UGA Draw protocol are supported,
3274 // both they will be installed on virtual handle.
3275 //
3276 Status = gBS->InstallMultipleProtocolInterfaces (
3277 &mConOut.VirtualHandle,
3278 &gEfiGraphicsOutputProtocolGuid,
3279 &mConOut.GraphicsOutput,
3280 &gEfiUgaDrawProtocolGuid,
3281 &mConOut.UgaDraw,
3282 NULL
3283 );
3284 }
3285 }
3286
3287 //
3288 // After adding new console device, all existing console devices should be
3289 // synced to the current shared mode.
3290 //
3291 ConsplitterSetConsoleOutMode (Private);
3292
3293 return Status;
3294 }
3295
3296
3297 /**
3298 Remove Text Out Device in Consplitter Text Out list.
3299
3300 @param Private Text Out Splitter pointer.
3301 @param TextOut Simple Text Output Pointer protocol pointer.
3302
3303 @retval EFI_SUCCESS Text Out Device removed successfully.
3304 @retval EFI_NOT_FOUND No Text Out Device found.
3305
3306 **/
3307 EFI_STATUS
3308 ConSplitterTextOutDeleteDevice (
3309 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
3310 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut
3311 )
3312 {
3313 INT32 Index;
3314 UINTN CurrentNumOfConsoles;
3315 TEXT_OUT_AND_GOP_DATA *TextOutList;
3316 EFI_STATUS Status;
3317
3318 //
3319 // Remove the specified text-out device data structure from the Text out List,
3320 // and rearrange the remaining data structures in the Text out List.
3321 //
3322 CurrentNumOfConsoles = Private->CurrentNumberOfConsoles;
3323 Index = (INT32) CurrentNumOfConsoles - 1;
3324 TextOutList = Private->TextOutList;
3325 while (Index >= 0) {
3326 if (TextOutList->TextOut == TextOut) {
3327 if (TextOutList->UgaDraw != NULL) {
3328 Private->CurrentNumberOfUgaDraw--;
3329 }
3330 if (TextOutList->GraphicsOutput != NULL) {
3331 Private->CurrentNumberOfGraphicsOutput--;
3332 }
3333 CopyMem (TextOutList, TextOutList + 1, sizeof (TEXT_OUT_AND_GOP_DATA) * Index);
3334 CurrentNumOfConsoles--;
3335 break;
3336 }
3337
3338 Index--;
3339 TextOutList++;
3340 }
3341 //
3342 // The specified TextOut is not managed by the ConSplitter driver
3343 //
3344 if (Index < 0) {
3345 return EFI_NOT_FOUND;
3346 }
3347
3348 if ((Private->CurrentNumberOfGraphicsOutput == 0) && (Private->CurrentNumberOfUgaDraw == 0)) {
3349 //
3350 // If there is not any physical GOP and UGA device in system,
3351 // Consplitter GOP or UGA protocol will be uninstalled
3352 //
3353 if (!FeaturePcdGet (PcdConOutGopSupport)) {
3354 Status = gBS->UninstallProtocolInterface (
3355 Private->VirtualHandle,
3356 &gEfiUgaDrawProtocolGuid,
3357 &Private->UgaDraw
3358 );
3359 } else if (!FeaturePcdGet (PcdConOutUgaSupport)) {
3360 Status = gBS->UninstallProtocolInterface (
3361 Private->VirtualHandle,
3362 &gEfiGraphicsOutputProtocolGuid,
3363 &Private->GraphicsOutput
3364 );
3365 } else {
3366 Status = gBS->UninstallMultipleProtocolInterfaces (
3367 Private->VirtualHandle,
3368 &gEfiUgaDrawProtocolGuid,
3369 &Private->UgaDraw,
3370 &gEfiGraphicsOutputProtocolGuid,
3371 &Private->GraphicsOutput,
3372 NULL
3373 );
3374 }
3375 }
3376
3377 if (CurrentNumOfConsoles == 0) {
3378 //
3379 // If the number of consoles is zero, reset all parameters
3380 //
3381 Private->CurrentNumberOfConsoles = 0;
3382 Private->TextOutMode.MaxMode = 1;
3383 Private->TextOutQueryData[0].Columns = 80;
3384 Private->TextOutQueryData[0].Rows = 25;
3385 TextOutSetMode (Private, 0);
3386
3387 return EFI_SUCCESS;
3388 }
3389 //
3390 // Max Mode is realy an intersection of the QueryMode command to all
3391 // devices. So we must copy the QueryMode of the first device to
3392 // QueryData.
3393 //
3394 ZeroMem (
3395 Private->TextOutQueryData,
3396 Private->TextOutQueryDataCount * sizeof (TEXT_OUT_SPLITTER_QUERY_DATA)
3397 );
3398
3399 FreePool (Private->TextOutModeMap);
3400 Private->TextOutModeMap = NULL;
3401 TextOutList = Private->TextOutList;
3402
3403 //
3404 // Add the first TextOut to the QueryData array and ModeMap table
3405 //
3406 Status = ConSplitterAddOutputMode (Private, TextOutList->TextOut);
3407
3408 //
3409 // Now add one by one
3410 //
3411 Index = 1;
3412 Private->CurrentNumberOfConsoles = 1;
3413 TextOutList++;
3414 while ((UINTN) Index < CurrentNumOfConsoles) {
3415 ConSplitterSyncOutputMode (Private, TextOutList->TextOut);
3416 Index++;
3417 Private->CurrentNumberOfConsoles++;
3418 TextOutList++;
3419 }
3420
3421 ConSplitterGetIntersectionBetweenConOutAndStrErr ();
3422
3423 return Status;
3424 }
3425
3426
3427 /**
3428 Reset the input device and optionaly run diagnostics
3429
3430 @param This Protocol instance pointer.
3431 @param ExtendedVerification Driver may perform diagnostics on reset.
3432
3433 @retval EFI_SUCCESS The device was reset.
3434 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
3435 not be reset.
3436
3437 **/
3438 EFI_STATUS
3439 EFIAPI
3440 ConSplitterTextInReset (
3441 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
3442 IN BOOLEAN ExtendedVerification
3443 )
3444 {
3445 EFI_STATUS Status;
3446 EFI_STATUS ReturnStatus;
3447 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3448 UINTN Index;
3449
3450 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3451
3452 Private->KeyEventSignalState = FALSE;
3453
3454 //
3455 // return the worst status met
3456 //
3457 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
3458 Status = Private->TextInList[Index]->Reset (
3459 Private->TextInList[Index],
3460 ExtendedVerification
3461 );
3462 if (EFI_ERROR (Status)) {
3463 ReturnStatus = Status;
3464 }
3465 }
3466
3467 if (!EFI_ERROR (ReturnStatus)) {
3468 ToggleStateSyncReInitialization (Private);
3469 //
3470 // Empty the key queue.
3471 //
3472 Private->CurrentNumberOfKeys = 0;
3473 }
3474
3475 return ReturnStatus;
3476 }
3477
3478 /**
3479 Dequeue the saved key from internal key queue.
3480
3481 @param Private Protocol instance pointer.
3482 @param KeyData A pointer to a buffer that is filled in with the
3483 keystroke state data for the key that was
3484 pressed.
3485 @retval EFI_NOT_FOUND Queue is empty.
3486 @retval EFI_SUCCESS First key is dequeued and returned.
3487 **/
3488 EFI_STATUS
3489 ConSplitterTextInExDequeueKey (
3490 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
3491 OUT EFI_KEY_DATA *KeyData
3492 )
3493 {
3494 if (Private->CurrentNumberOfKeys == 0) {
3495 return EFI_NOT_FOUND;
3496 }
3497 //
3498 // Return the first saved key.
3499 //
3500 CopyMem (KeyData, &Private->KeyQueue[0], sizeof (EFI_KEY_DATA));
3501 Private->CurrentNumberOfKeys--;
3502 CopyMem (
3503 &Private->KeyQueue[0],
3504 &Private->KeyQueue[1],
3505 Private->CurrentNumberOfKeys * sizeof (EFI_KEY_DATA)
3506 );
3507 return EFI_SUCCESS;
3508 }
3509
3510 /**
3511 Reads the next keystroke from the input device. The WaitForKey Event can
3512 be used to test for existance of a keystroke via WaitForEvent () call.
3513
3514 @param Private Protocol instance pointer.
3515 @param Key Driver may perform diagnostics on reset.
3516
3517 @retval EFI_SUCCESS The keystroke information was returned.
3518 @retval EFI_NOT_READY There was no keystroke data availiable.
3519 @retval EFI_DEVICE_ERROR The keydtroke information was not returned due
3520 to hardware errors.
3521
3522 **/
3523 EFI_STATUS
3524 EFIAPI
3525 ConSplitterTextInPrivateReadKeyStroke (
3526 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
3527 OUT EFI_INPUT_KEY *Key
3528 )
3529 {
3530 EFI_STATUS Status;
3531 UINTN Index;
3532 EFI_KEY_DATA KeyData;
3533
3534 //
3535 // Return the first saved non-NULL key.
3536 //
3537 while (TRUE) {
3538 Status = ConSplitterTextInExDequeueKey (Private, &KeyData);
3539 if (EFI_ERROR (Status)) {
3540 break;
3541 }
3542 if ((KeyData.Key.ScanCode != CHAR_NULL) || (KeyData.Key.UnicodeChar != SCAN_NULL)) {
3543 CopyMem (Key, &KeyData.Key, sizeof (EFI_INPUT_KEY));
3544 return Status;
3545 }
3546 }
3547
3548 Key->UnicodeChar = 0;
3549 Key->ScanCode = SCAN_NULL;
3550
3551 //
3552 // if no physical console input device exists, return EFI_NOT_READY;
3553 // if any physical console input device has key input,
3554 // return the key and EFI_SUCCESS.
3555 //
3556 for (Index = 0; Index < Private->CurrentNumberOfConsoles;) {
3557 Status = Private->TextInList[Index]->ReadKeyStroke (
3558 Private->TextInList[Index],
3559 &KeyData.Key
3560 );
3561 if (!EFI_ERROR (Status)) {
3562 //
3563 // If it is not partial keystorke, return the key. Otherwise, continue
3564 // to read key from THIS physical console input device.
3565 //
3566 if ((KeyData.Key.ScanCode != CHAR_NULL) || (KeyData.Key.UnicodeChar != SCAN_NULL)) {
3567 CopyMem (Key, &KeyData.Key, sizeof (EFI_INPUT_KEY));
3568 return Status;
3569 }
3570 } else {
3571 //
3572 // Continue to read key from NEXT physical console input device.
3573 //
3574 Index++;
3575 }
3576 }
3577
3578 return EFI_NOT_READY;
3579 }
3580
3581
3582
3583 /**
3584 Reads the next keystroke from the input device. The WaitForKey Event can
3585 be used to test for existance of a keystroke via WaitForEvent () call.
3586
3587 @param This Protocol instance pointer.
3588 @param Key Driver may perform diagnostics on reset.
3589
3590 @retval EFI_SUCCESS The keystroke information was returned.
3591 @retval EFI_NOT_READY There was no keystroke data availiable.
3592 @retval EFI_DEVICE_ERROR The keydtroke information was not returned due
3593 to hardware errors.
3594
3595 **/
3596 EFI_STATUS
3597 EFIAPI
3598 ConSplitterTextInReadKeyStroke (
3599 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
3600 OUT EFI_INPUT_KEY *Key
3601 )
3602 {
3603 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3604
3605 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3606
3607 Private->KeyEventSignalState = FALSE;
3608
3609 //
3610 // Signal ConnectConIn event on first call in Lazy ConIn mode
3611 //
3612 if (!mConInIsConnect && PcdGetBool (PcdConInConnectOnDemand)) {
3613 DEBUG ((EFI_D_INFO, "Connect ConIn in first ReadKeyStoke in Lazy ConIn mode.\n"));
3614 gBS->SignalEvent (Private->ConnectConInEvent);
3615 mConInIsConnect = TRUE;
3616 }
3617
3618 return ConSplitterTextInPrivateReadKeyStroke (Private, Key);
3619 }
3620
3621
3622 /**
3623 This event aggregates all the events of the ConIn devices in the spliter.
3624
3625 If any events of physical ConIn devices are signaled, signal the ConIn
3626 spliter event. This will cause the calling code to call
3627 ConSplitterTextInReadKeyStroke ().
3628
3629 @param Event The Event assoicated with callback.
3630 @param Context Context registered when Event was created.
3631
3632 **/
3633 VOID
3634 EFIAPI
3635 ConSplitterTextInWaitForKey (
3636 IN EFI_EVENT Event,
3637 IN VOID *Context
3638 )
3639 {
3640 EFI_STATUS Status;
3641 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3642 UINTN Index;
3643
3644 Private = (TEXT_IN_SPLITTER_PRIVATE_DATA *) Context;
3645
3646 if (Private->KeyEventSignalState) {
3647 //
3648 // If KeyEventSignalState is flagged before, and not cleared by Reset() or ReadKeyStroke()
3649 //
3650 gBS->SignalEvent (Event);
3651 return ;
3652 }
3653
3654 //
3655 // If any physical console input device has key input, signal the event.
3656 //
3657 for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {
3658 Status = gBS->CheckEvent (Private->TextInList[Index]->WaitForKey);
3659 if (!EFI_ERROR (Status)) {
3660 gBS->SignalEvent (Event);
3661 Private->KeyEventSignalState = TRUE;
3662 }
3663 }
3664 }
3665
3666
3667
3668 /**
3669 Test if the key has been registered on input device.
3670
3671 @param RegsiteredData A pointer to a buffer that is filled in with the
3672 keystroke state data for the key that was
3673 registered.
3674 @param InputData A pointer to a buffer that is filled in with the
3675 keystroke state data for the key that was
3676 pressed.
3677
3678 @retval TRUE Key be pressed matches a registered key.
3679 @retval FLASE Match failed.
3680
3681 **/
3682 BOOLEAN
3683 IsKeyRegistered (
3684 IN EFI_KEY_DATA *RegsiteredData,
3685 IN EFI_KEY_DATA *InputData
3686 )
3687 {
3688 ASSERT (RegsiteredData != NULL && InputData != NULL);
3689
3690 if ((RegsiteredData->Key.ScanCode != InputData->Key.ScanCode) ||
3691 (RegsiteredData->Key.UnicodeChar != InputData->Key.UnicodeChar)) {
3692 return FALSE;
3693 }
3694
3695 //
3696 // Assume KeyShiftState/KeyToggleState = 0 in Registered key data means these state could be ignored.
3697 //
3698 if (RegsiteredData->KeyState.KeyShiftState != 0 &&
3699 RegsiteredData->KeyState.KeyShiftState != InputData->KeyState.KeyShiftState) {
3700 return FALSE;
3701 }
3702 if (RegsiteredData->KeyState.KeyToggleState != 0 &&
3703 RegsiteredData->KeyState.KeyToggleState != InputData->KeyState.KeyToggleState) {
3704 return FALSE;
3705 }
3706
3707 return TRUE;
3708
3709 }
3710
3711
3712 /**
3713 Reset the input device and optionaly run diagnostics
3714
3715 @param This Protocol instance pointer.
3716 @param ExtendedVerification Driver may perform diagnostics on reset.
3717
3718 @retval EFI_SUCCESS The device was reset.
3719 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
3720 not be reset.
3721
3722 **/
3723 EFI_STATUS
3724 EFIAPI
3725 ConSplitterTextInResetEx (
3726 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
3727 IN BOOLEAN ExtendedVerification
3728 )
3729 {
3730 EFI_STATUS Status;
3731 EFI_STATUS ReturnStatus;
3732 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3733 UINTN Index;
3734
3735 Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3736
3737 Private->KeyEventSignalState = FALSE;
3738
3739 //
3740 // return the worst status met
3741 //
3742 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfExConsoles; Index++) {
3743 Status = Private->TextInExList[Index]->Reset (
3744 Private->TextInExList[Index],
3745 ExtendedVerification
3746 );
3747 if (EFI_ERROR (Status)) {
3748 ReturnStatus = Status;
3749 }
3750 }
3751
3752 if (!EFI_ERROR (ReturnStatus)) {
3753 ToggleStateSyncReInitialization (Private);
3754 //
3755 // Empty the key queue.
3756 //
3757 Private->CurrentNumberOfKeys = 0;
3758 }
3759
3760 return ReturnStatus;
3761
3762 }
3763
3764
3765 /**
3766 Reads the next keystroke from the input device. The WaitForKey Event can
3767 be used to test for existance of a keystroke via WaitForEvent () call.
3768
3769 @param This Protocol instance pointer.
3770 @param KeyData A pointer to a buffer that is filled in with the
3771 keystroke state data for the key that was
3772 pressed.
3773
3774 @retval EFI_SUCCESS The keystroke information was returned.
3775 @retval EFI_NOT_READY There was no keystroke data availiable.
3776 @retval EFI_DEVICE_ERROR The keystroke information was not returned due
3777 to hardware errors.
3778 @retval EFI_INVALID_PARAMETER KeyData is NULL.
3779
3780 **/
3781 EFI_STATUS
3782 EFIAPI
3783 ConSplitterTextInReadKeyStrokeEx (
3784 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
3785 OUT EFI_KEY_DATA *KeyData
3786 )
3787 {
3788 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3789 EFI_STATUS Status;
3790 UINTN Index;
3791 EFI_KEY_STATE KeyState;
3792 EFI_KEY_DATA CurrentKeyData;
3793
3794
3795 if (KeyData == NULL) {
3796 return EFI_INVALID_PARAMETER;
3797 }
3798
3799 Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3800
3801 Private->KeyEventSignalState = FALSE;
3802
3803 //
3804 // Signal ConnectConIn event on first call in Lazy ConIn mode
3805 //
3806 if (!mConInIsConnect && PcdGetBool (PcdConInConnectOnDemand)) {
3807 DEBUG ((EFI_D_INFO, "Connect ConIn in first ReadKeyStoke in Lazy ConIn mode.\n"));
3808 gBS->SignalEvent (Private->ConnectConInEvent);
3809 mConInIsConnect = TRUE;
3810 }
3811
3812 //
3813 // Return the first saved key.
3814 //
3815 Status = ConSplitterTextInExDequeueKey (Private, KeyData);
3816 if (!EFI_ERROR (Status)) {
3817 return Status;
3818 }
3819 ASSERT (Private->CurrentNumberOfKeys == 0);
3820
3821 ZeroMem (&KeyState, sizeof (KeyState));
3822
3823 //
3824 // Iterate through all physical consoles to get key state.
3825 // Some physical consoles may return valid key.
3826 // Queue the valid keys.
3827 //
3828 for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {
3829 ZeroMem (&CurrentKeyData, sizeof (EFI_KEY_DATA));
3830 Status = Private->TextInExList[Index]->ReadKeyStrokeEx (
3831 Private->TextInExList[Index],
3832 &CurrentKeyData
3833 );
3834 if (EFI_ERROR (Status) && (Status != EFI_NOT_READY)) {
3835 continue;
3836 }
3837
3838 //
3839 // Consolidate the key state from all physical consoles.
3840 //
3841 if ((CurrentKeyData.KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) != 0) {
3842 KeyState.KeyShiftState |= CurrentKeyData.KeyState.KeyShiftState;
3843 }
3844 if ((CurrentKeyData.KeyState.KeyToggleState & EFI_TOGGLE_STATE_VALID) != 0) {
3845 KeyState.KeyToggleState |= CurrentKeyData.KeyState.KeyToggleState;
3846 }
3847
3848 if (!EFI_ERROR (Status)) {
3849 //
3850 // If virtual KeyState has been required to be exposed, or it is not
3851 // partial keystorke, queue the key.
3852 // It's possible that user presses at multiple keyboards at the same moment,
3853 // Private->KeyQueue[] are the storage to save all the keys.
3854 //
3855 if ((Private->VirtualKeyStateExported) ||
3856 (CurrentKeyData.Key.ScanCode != CHAR_NULL) ||
3857 (CurrentKeyData.Key.UnicodeChar != SCAN_NULL)) {
3858 CopyMem (
3859 &Private->KeyQueue[Private->CurrentNumberOfKeys],
3860 &CurrentKeyData,
3861 sizeof (EFI_KEY_DATA)
3862 );
3863 Private->CurrentNumberOfKeys++;
3864 }
3865 }
3866 }
3867
3868 //
3869 // Consolidate the key state for all keys in Private->KeyQueue[]
3870 //
3871 for (Index = 0; Index < Private->CurrentNumberOfKeys; Index++) {
3872 CopyMem (&Private->KeyQueue[Index].KeyState, &KeyState, sizeof (EFI_KEY_STATE));
3873 }
3874
3875 //
3876 // Return the first saved key.
3877 //
3878 Status = ConSplitterTextInExDequeueKey (Private, KeyData);
3879 if (!EFI_ERROR (Status)) {
3880 return Status;
3881 }
3882
3883 //
3884 // Always return the key state even there is no key pressed.
3885 //
3886 ZeroMem (&KeyData->Key, sizeof (KeyData->Key));
3887 CopyMem (&KeyData->KeyState, &KeyState, sizeof (KeyData->KeyState));
3888 return EFI_NOT_READY;
3889 }
3890
3891
3892 /**
3893 Set certain state for the input device.
3894
3895 @param This Protocol instance pointer.
3896 @param KeyToggleState A pointer to the EFI_KEY_TOGGLE_STATE to set the
3897 state for the input device.
3898
3899 @retval EFI_SUCCESS The device state was set successfully.
3900 @retval EFI_DEVICE_ERROR The device is not functioning correctly and
3901 could not have the setting adjusted.
3902 @retval EFI_UNSUPPORTED The device does not have the ability to set its
3903 state.
3904 @retval EFI_INVALID_PARAMETER KeyToggleState is NULL.
3905
3906 **/
3907 EFI_STATUS
3908 EFIAPI
3909 ConSplitterTextInSetState (
3910 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
3911 IN EFI_KEY_TOGGLE_STATE *KeyToggleState
3912 )
3913 {
3914 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3915 EFI_STATUS Status;
3916 UINTN Index;
3917 EFI_KEY_TOGGLE_STATE PhysicalKeyToggleState;
3918
3919 if (KeyToggleState == NULL) {
3920 return EFI_INVALID_PARAMETER;
3921 }
3922
3923 Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3924
3925 //
3926 // Always turn on physical TextInEx partial key report for
3927 // toggle state sync.
3928 //
3929 PhysicalKeyToggleState = *KeyToggleState | EFI_KEY_STATE_EXPOSED;
3930
3931 //
3932 // if no physical console input device exists, return EFI_SUCCESS;
3933 // otherwise return the status of setting state of physical console input device
3934 //
3935 for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {
3936 Status = Private->TextInExList[Index]->SetState (
3937 Private->TextInExList[Index],
3938 &PhysicalKeyToggleState
3939 );
3940 if (EFI_ERROR (Status)) {
3941 return Status;
3942 }
3943 }
3944
3945 //
3946 // Record the physical KeyToggleState.
3947 //
3948 Private->PhysicalKeyToggleState = PhysicalKeyToggleState;
3949 //
3950 // Get if virtual KeyState has been required to be exposed.
3951 //
3952 Private->VirtualKeyStateExported = (((*KeyToggleState) & EFI_KEY_STATE_EXPOSED) != 0);
3953
3954 return EFI_SUCCESS;
3955
3956 }
3957
3958
3959 /**
3960 Register a notification function for a particular keystroke for the input device.
3961
3962 @param This Protocol instance pointer.
3963 @param KeyData A pointer to a buffer that is filled in with
3964 the keystroke information for the key that was
3965 pressed. If KeyData.Key, KeyData.KeyState.KeyToggleState
3966 and KeyData.KeyState.KeyShiftState are 0, then any incomplete
3967 keystroke will trigger a notification of the KeyNotificationFunction.
3968 @param KeyNotificationFunction Points to the function to be called when the key
3969 sequence is typed specified by KeyData. This notification function
3970 should be called at <=TPL_CALLBACK.
3971 @param NotifyHandle Points to the unique handle assigned to the
3972 registered notification.
3973
3974 @retval EFI_SUCCESS The notification function was registered
3975 successfully.
3976 @retval EFI_OUT_OF_RESOURCES Unable to allocate resources for necesssary data
3977 structures.
3978 @retval EFI_INVALID_PARAMETER KeyData or KeyNotificationFunction or NotifyHandle is NULL.
3979
3980 **/
3981 EFI_STATUS
3982 EFIAPI
3983 ConSplitterTextInRegisterKeyNotify (
3984 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
3985 IN EFI_KEY_DATA *KeyData,
3986 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction,
3987 OUT VOID **NotifyHandle
3988 )
3989 {
3990 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3991 EFI_STATUS Status;
3992 UINTN Index;
3993 TEXT_IN_EX_SPLITTER_NOTIFY *NewNotify;
3994 LIST_ENTRY *Link;
3995 TEXT_IN_EX_SPLITTER_NOTIFY *CurrentNotify;
3996
3997
3998 if (KeyData == NULL || NotifyHandle == NULL || KeyNotificationFunction == NULL) {
3999 return EFI_INVALID_PARAMETER;
4000 }
4001
4002 Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4003
4004 //
4005 // Return EFI_SUCCESS if the (KeyData, NotificationFunction) is already registered.
4006 //
4007 for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {
4008 CurrentNotify = TEXT_IN_EX_SPLITTER_NOTIFY_FROM_THIS (Link);
4009 if (IsKeyRegistered (&CurrentNotify->KeyData, KeyData)) {
4010 if (CurrentNotify->KeyNotificationFn == KeyNotificationFunction) {
4011 *NotifyHandle = CurrentNotify;
4012 return EFI_SUCCESS;
4013 }
4014 }
4015 }
4016
4017 //
4018 // Allocate resource to save the notification function
4019 //
4020 NewNotify = (TEXT_IN_EX_SPLITTER_NOTIFY *) AllocateZeroPool (sizeof (TEXT_IN_EX_SPLITTER_NOTIFY));
4021 if (NewNotify == NULL) {
4022 return EFI_OUT_OF_RESOURCES;
4023 }
4024 NewNotify->NotifyHandleList = (EFI_HANDLE *) AllocateZeroPool (sizeof (EFI_HANDLE) * Private->TextInExListCount);
4025 if (NewNotify->NotifyHandleList == NULL) {
4026 gBS->FreePool (NewNotify);
4027 return EFI_OUT_OF_RESOURCES;
4028 }
4029 NewNotify->Signature = TEXT_IN_EX_SPLITTER_NOTIFY_SIGNATURE;
4030 NewNotify->KeyNotificationFn = KeyNotificationFunction;
4031 CopyMem (&NewNotify->KeyData, KeyData, sizeof (EFI_KEY_DATA));
4032
4033 //
4034 // Return the wrong status of registering key notify of
4035 // physical console input device if meet problems
4036 //
4037 for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {
4038 Status = Private->TextInExList[Index]->RegisterKeyNotify (
4039 Private->TextInExList[Index],
4040 KeyData,
4041 KeyNotificationFunction,
4042 &NewNotify->NotifyHandleList[Index]
4043 );
4044 if (EFI_ERROR (Status)) {
4045 //
4046 // Un-register the key notify on all physical console input devices
4047 //
4048 while (Index-- != 0) {
4049 Private->TextInExList[Index]->UnregisterKeyNotify (
4050 Private->TextInExList[Index],
4051 NewNotify->NotifyHandleList[Index]
4052 );
4053 }
4054 gBS->FreePool (NewNotify->NotifyHandleList);
4055 gBS->FreePool (NewNotify);
4056 return Status;
4057 }
4058 }
4059
4060 InsertTailList (&Private->NotifyList, &NewNotify->NotifyEntry);
4061
4062 *NotifyHandle = NewNotify;
4063
4064 return EFI_SUCCESS;
4065
4066 }
4067
4068
4069 /**
4070 Remove a registered notification function from a particular keystroke.
4071
4072 @param This Protocol instance pointer.
4073 @param NotificationHandle The handle of the notification function being
4074 unregistered.
4075
4076 @retval EFI_SUCCESS The notification function was unregistered
4077 successfully.
4078 @retval EFI_INVALID_PARAMETER The NotificationHandle is invalid.
4079
4080 **/
4081 EFI_STATUS
4082 EFIAPI
4083 ConSplitterTextInUnregisterKeyNotify (
4084 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
4085 IN VOID *NotificationHandle
4086 )
4087 {
4088 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
4089 UINTN Index;
4090 TEXT_IN_EX_SPLITTER_NOTIFY *CurrentNotify;
4091 LIST_ENTRY *Link;
4092
4093 if (NotificationHandle == NULL) {
4094 return EFI_INVALID_PARAMETER;
4095 }
4096
4097 Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4098
4099 for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {
4100 CurrentNotify = TEXT_IN_EX_SPLITTER_NOTIFY_FROM_THIS (Link);
4101 if (CurrentNotify == NotificationHandle) {
4102 for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {
4103 Private->TextInExList[Index]->UnregisterKeyNotify (
4104 Private->TextInExList[Index],
4105 CurrentNotify->NotifyHandleList[Index]
4106 );
4107 }
4108 RemoveEntryList (&CurrentNotify->NotifyEntry);
4109
4110 gBS->FreePool (CurrentNotify->NotifyHandleList);
4111 gBS->FreePool (CurrentNotify);
4112 return EFI_SUCCESS;
4113 }
4114 }
4115
4116 //
4117 // NotificationHandle is not found in database
4118 //
4119 return EFI_INVALID_PARAMETER;
4120 }
4121
4122
4123 /**
4124 Reset the input device and optionaly run diagnostics
4125
4126 @param This Protocol instance pointer.
4127 @param ExtendedVerification Driver may perform diagnostics on reset.
4128
4129 @retval EFI_SUCCESS The device was reset.
4130 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
4131 not be reset.
4132
4133 **/
4134 EFI_STATUS
4135 EFIAPI
4136 ConSplitterSimplePointerReset (
4137 IN EFI_SIMPLE_POINTER_PROTOCOL *This,
4138 IN BOOLEAN ExtendedVerification
4139 )
4140 {
4141 EFI_STATUS Status;
4142 EFI_STATUS ReturnStatus;
4143 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
4144 UINTN Index;
4145
4146 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_SIMPLE_POINTER_THIS (This);
4147
4148 Private->InputEventSignalState = FALSE;
4149
4150 if (Private->CurrentNumberOfPointers == 0) {
4151 return EFI_SUCCESS;
4152 }
4153 //
4154 // return the worst status met
4155 //
4156 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfPointers; Index++) {
4157 Status = Private->PointerList[Index]->Reset (
4158 Private->PointerList[Index],
4159 ExtendedVerification
4160 );
4161 if (EFI_ERROR (Status)) {
4162 ReturnStatus = Status;
4163 }
4164 }
4165
4166 return ReturnStatus;
4167 }
4168
4169
4170 /**
4171 Reads the next keystroke from the input device. The WaitForKey Event can
4172 be used to test for existance of a keystroke via WaitForEvent () call.
4173
4174 @param Private Protocol instance pointer.
4175 @param State The state information of simple pointer device.
4176
4177 @retval EFI_SUCCESS The keystroke information was returned.
4178 @retval EFI_NOT_READY There was no keystroke data availiable.
4179 @retval EFI_DEVICE_ERROR The keydtroke information was not returned due
4180 to hardware errors.
4181
4182 **/
4183 EFI_STATUS
4184 EFIAPI
4185 ConSplitterSimplePointerPrivateGetState (
4186 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
4187 IN OUT EFI_SIMPLE_POINTER_STATE *State
4188 )
4189 {
4190 EFI_STATUS Status;
4191 EFI_STATUS ReturnStatus;
4192 UINTN Index;
4193 EFI_SIMPLE_POINTER_STATE CurrentState;
4194
4195 State->RelativeMovementX = 0;
4196 State->RelativeMovementY = 0;
4197 State->RelativeMovementZ = 0;
4198 State->LeftButton = FALSE;
4199 State->RightButton = FALSE;
4200
4201 //
4202 // if no physical console input device exists, return EFI_NOT_READY;
4203 // if any physical console input device has key input,
4204 // return the key and EFI_SUCCESS.
4205 //
4206 ReturnStatus = EFI_NOT_READY;
4207 for (Index = 0; Index < Private->CurrentNumberOfPointers; Index++) {
4208
4209 Status = Private->PointerList[Index]->GetState (
4210 Private->PointerList[Index],
4211 &CurrentState
4212 );
4213 if (!EFI_ERROR (Status)) {
4214 if (ReturnStatus == EFI_NOT_READY) {
4215 ReturnStatus = EFI_SUCCESS;
4216 }
4217
4218 if (CurrentState.LeftButton) {
4219 State->LeftButton = TRUE;
4220 }
4221
4222 if (CurrentState.RightButton) {
4223 State->RightButton = TRUE;
4224 }
4225
4226 if (CurrentState.RelativeMovementX != 0 && Private->PointerList[Index]->Mode->ResolutionX != 0) {
4227 State->RelativeMovementX += (CurrentState.RelativeMovementX * (INT32) Private->SimplePointerMode.ResolutionX) / (INT32) Private->PointerList[Index]->Mode->ResolutionX;
4228 }
4229
4230 if (CurrentState.RelativeMovementY != 0 && Private->PointerList[Index]->Mode->ResolutionY != 0) {
4231 State->RelativeMovementY += (CurrentState.RelativeMovementY * (INT32) Private->SimplePointerMode.ResolutionY) / (INT32) Private->PointerList[Index]->Mode->ResolutionY;
4232 }
4233
4234 if (CurrentState.RelativeMovementZ != 0 && Private->PointerList[Index]->Mode->ResolutionZ != 0) {
4235 State->RelativeMovementZ += (CurrentState.RelativeMovementZ * (INT32) Private->SimplePointerMode.ResolutionZ) / (INT32) Private->PointerList[Index]->Mode->ResolutionZ;
4236 }
4237 } else if (Status == EFI_DEVICE_ERROR) {
4238 ReturnStatus = EFI_DEVICE_ERROR;
4239 }
4240 }
4241
4242 return ReturnStatus;
4243 }
4244
4245
4246 /**
4247 Reads the next keystroke from the input device. The WaitForKey Event can
4248 be used to test for existance of a keystroke via WaitForEvent () call.
4249
4250 @param This A pointer to protocol instance.
4251 @param State A pointer to state information on the pointer device
4252
4253 @retval EFI_SUCCESS The keystroke information was returned in State.
4254 @retval EFI_NOT_READY There was no keystroke data availiable.
4255 @retval EFI_DEVICE_ERROR The keydtroke information was not returned due
4256 to hardware errors.
4257
4258 **/
4259 EFI_STATUS
4260 EFIAPI
4261 ConSplitterSimplePointerGetState (
4262 IN EFI_SIMPLE_POINTER_PROTOCOL *This,
4263 IN OUT EFI_SIMPLE_POINTER_STATE *State
4264 )
4265 {
4266 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
4267
4268 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_SIMPLE_POINTER_THIS (This);
4269
4270 Private->InputEventSignalState = FALSE;
4271
4272 return ConSplitterSimplePointerPrivateGetState (Private, State);
4273 }
4274
4275
4276 /**
4277 This event agregates all the events of the ConIn devices in the spliter.
4278 If any events of physical ConIn devices are signaled, signal the ConIn
4279 spliter event. This will cause the calling code to call
4280 ConSplitterTextInReadKeyStroke ().
4281
4282 @param Event The Event assoicated with callback.
4283 @param Context Context registered when Event was created.
4284
4285 **/
4286 VOID
4287 EFIAPI
4288 ConSplitterSimplePointerWaitForInput (
4289 IN EFI_EVENT Event,
4290 IN VOID *Context
4291 )
4292 {
4293 EFI_STATUS Status;
4294 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
4295 UINTN Index;
4296
4297 Private = (TEXT_IN_SPLITTER_PRIVATE_DATA *) Context;
4298
4299 //
4300 // if InputEventSignalState is flagged before, and not cleared by Reset() or ReadKeyStroke()
4301 //
4302 if (Private->InputEventSignalState) {
4303 gBS->SignalEvent (Event);
4304 return ;
4305 }
4306 //
4307 // if any physical console input device has key input, signal the event.
4308 //
4309 for (Index = 0; Index < Private->CurrentNumberOfPointers; Index++) {
4310 Status = gBS->CheckEvent (Private->PointerList[Index]->WaitForInput);
4311 if (!EFI_ERROR (Status)) {
4312 gBS->SignalEvent (Event);
4313 Private->InputEventSignalState = TRUE;
4314 }
4315 }
4316 }
4317
4318 /**
4319 Resets the pointer device hardware.
4320
4321 @param This Protocol instance pointer.
4322 @param ExtendedVerification Driver may perform diagnostics on reset.
4323
4324 @retval EFI_SUCCESS The device was reset.
4325 @retval EFI_DEVICE_ERROR The device is not functioning correctly and
4326 could not be reset.
4327
4328 **/
4329 EFI_STATUS
4330 EFIAPI
4331 ConSplitterAbsolutePointerReset (
4332 IN EFI_ABSOLUTE_POINTER_PROTOCOL *This,
4333 IN BOOLEAN ExtendedVerification
4334 )
4335 {
4336 EFI_STATUS Status;
4337 EFI_STATUS ReturnStatus;
4338 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
4339 UINTN Index;
4340
4341 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_ABSOLUTE_POINTER_THIS (This);
4342
4343 Private->AbsoluteInputEventSignalState = FALSE;
4344
4345 if (Private->CurrentNumberOfAbsolutePointers == 0) {
4346 return EFI_SUCCESS;
4347 }
4348 //
4349 // return the worst status met
4350 //
4351 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfAbsolutePointers; Index++) {
4352 Status = Private->AbsolutePointerList[Index]->Reset (
4353 Private->AbsolutePointerList[Index],
4354 ExtendedVerification
4355 );
4356 if (EFI_ERROR (Status)) {
4357 ReturnStatus = Status;
4358 }
4359 }
4360
4361 return ReturnStatus;
4362 }
4363
4364
4365 /**
4366 Retrieves the current state of a pointer device.
4367
4368 @param This Protocol instance pointer.
4369 @param State A pointer to the state information on the
4370 pointer device.
4371
4372 @retval EFI_SUCCESS The state of the pointer device was returned in
4373 State..
4374 @retval EFI_NOT_READY The state of the pointer device has not changed
4375 since the last call to GetState().
4376 @retval EFI_DEVICE_ERROR A device error occurred while attempting to
4377 retrieve the pointer device's current state.
4378
4379 **/
4380 EFI_STATUS
4381 EFIAPI
4382 ConSplitterAbsolutePointerGetState (
4383 IN EFI_ABSOLUTE_POINTER_PROTOCOL *This,
4384 IN OUT EFI_ABSOLUTE_POINTER_STATE *State
4385 )
4386 {
4387 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
4388 EFI_STATUS Status;
4389 EFI_STATUS ReturnStatus;
4390 UINTN Index;
4391 EFI_ABSOLUTE_POINTER_STATE CurrentState;
4392 UINT64 MinX;
4393 UINT64 MinY;
4394 UINT64 MinZ;
4395 UINT64 MaxX;
4396 UINT64 MaxY;
4397 UINT64 MaxZ;
4398 UINT64 VirtualMinX;
4399 UINT64 VirtualMinY;
4400 UINT64 VirtualMinZ;
4401 UINT64 VirtualMaxX;
4402 UINT64 VirtualMaxY;
4403 UINT64 VirtualMaxZ;
4404
4405 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_ABSOLUTE_POINTER_THIS (This);
4406
4407 Private->AbsoluteInputEventSignalState = FALSE;
4408
4409 State->CurrentX = 0;
4410 State->CurrentY = 0;
4411 State->CurrentZ = 0;
4412 State->ActiveButtons = 0;
4413
4414 VirtualMinX = Private->AbsolutePointerMode.AbsoluteMinX;
4415 VirtualMinY = Private->AbsolutePointerMode.AbsoluteMinY;
4416 VirtualMinZ = Private->AbsolutePointerMode.AbsoluteMinZ;
4417 VirtualMaxX = Private->AbsolutePointerMode.AbsoluteMaxX;
4418 VirtualMaxY = Private->AbsolutePointerMode.AbsoluteMaxY;
4419 VirtualMaxZ = Private->AbsolutePointerMode.AbsoluteMaxZ;
4420
4421 //
4422 // if no physical pointer device exists, return EFI_NOT_READY;
4423 // if any physical pointer device has changed state,
4424 // return the state and EFI_SUCCESS.
4425 //
4426 ReturnStatus = EFI_NOT_READY;
4427 for (Index = 0; Index < Private->CurrentNumberOfAbsolutePointers; Index++) {
4428
4429 Status = Private->AbsolutePointerList[Index]->GetState (
4430 Private->AbsolutePointerList[Index],
4431 &CurrentState
4432 );
4433 if (!EFI_ERROR (Status)) {
4434 if (ReturnStatus == EFI_NOT_READY) {
4435 ReturnStatus = EFI_SUCCESS;
4436 }
4437
4438 MinX = Private->AbsolutePointerList[Index]->Mode->AbsoluteMinX;
4439 MinY = Private->AbsolutePointerList[Index]->Mode->AbsoluteMinY;
4440 MinZ = Private->AbsolutePointerList[Index]->Mode->AbsoluteMinZ;
4441 MaxX = Private->AbsolutePointerList[Index]->Mode->AbsoluteMaxX;
4442 MaxY = Private->AbsolutePointerList[Index]->Mode->AbsoluteMaxY;
4443 MaxZ = Private->AbsolutePointerList[Index]->Mode->AbsoluteMaxZ;
4444
4445 State->ActiveButtons = CurrentState.ActiveButtons;
4446
4447 //
4448 // Rescale to Con Splitter virtual Absolute Pointer's resolution.
4449 //
4450 if (!(MinX == 0 && MaxX == 0)) {
4451 State->CurrentX = VirtualMinX + DivU64x64Remainder (
4452 MultU64x64 (
4453 CurrentState.CurrentX,
4454 VirtualMaxX - VirtualMinX
4455 ),
4456 MaxX - MinX,
4457 NULL
4458 );
4459 }
4460 if (!(MinY == 0 && MaxY == 0)) {
4461 State->CurrentY = VirtualMinY + DivU64x64Remainder (
4462 MultU64x64 (
4463 CurrentState.CurrentY,
4464 VirtualMaxY - VirtualMinY
4465 ),
4466 MaxY - MinY,
4467 NULL
4468 );
4469 }
4470 if (!(MinZ == 0 && MaxZ == 0)) {
4471 State->CurrentZ = VirtualMinZ + DivU64x64Remainder (
4472 MultU64x64 (
4473 CurrentState.CurrentZ,
4474 VirtualMaxZ - VirtualMinZ
4475 ),
4476 MaxZ - MinZ,
4477 NULL
4478 );
4479 }
4480
4481 } else if (Status == EFI_DEVICE_ERROR) {
4482 ReturnStatus = EFI_DEVICE_ERROR;
4483 }
4484 }
4485
4486 return ReturnStatus;
4487 }
4488
4489
4490 /**
4491 This event agregates all the events of the pointer devices in the splitter.
4492 If any events of physical pointer devices are signaled, signal the pointer
4493 splitter event. This will cause the calling code to call
4494 ConSplitterAbsolutePointerGetState ().
4495
4496 @param Event The Event assoicated with callback.
4497 @param Context Context registered when Event was created.
4498
4499 **/
4500 VOID
4501 EFIAPI
4502 ConSplitterAbsolutePointerWaitForInput (
4503 IN EFI_EVENT Event,
4504 IN VOID *Context
4505 )
4506 {
4507 EFI_STATUS Status;
4508 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
4509 UINTN Index;
4510
4511 Private = (TEXT_IN_SPLITTER_PRIVATE_DATA *) Context;
4512
4513 //
4514 // if AbsoluteInputEventSignalState is flagged before,
4515 // and not cleared by Reset() or GetState(), signal it
4516 //
4517 if (Private->AbsoluteInputEventSignalState) {
4518 gBS->SignalEvent (Event);
4519 return ;
4520 }
4521 //
4522 // if any physical console input device has key input, signal the event.
4523 //
4524 for (Index = 0; Index < Private->CurrentNumberOfAbsolutePointers; Index++) {
4525 Status = gBS->CheckEvent (Private->AbsolutePointerList[Index]->WaitForInput);
4526 if (!EFI_ERROR (Status)) {
4527 gBS->SignalEvent (Event);
4528 Private->AbsoluteInputEventSignalState = TRUE;
4529 }
4530 }
4531 }
4532
4533
4534 /**
4535 Reset the text output device hardware and optionaly run diagnostics
4536
4537 @param This Protocol instance pointer.
4538 @param ExtendedVerification Driver may perform more exhaustive verfication
4539 operation of the device during reset.
4540
4541 @retval EFI_SUCCESS The text output device was reset.
4542 @retval EFI_DEVICE_ERROR The text output device is not functioning
4543 correctly and could not be reset.
4544
4545 **/
4546 EFI_STATUS
4547 EFIAPI
4548 ConSplitterTextOutReset (
4549 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4550 IN BOOLEAN ExtendedVerification
4551 )
4552 {
4553 EFI_STATUS Status;
4554 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4555 UINTN Index;
4556 EFI_STATUS ReturnStatus;
4557
4558 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4559
4560 //
4561 // return the worst status met
4562 //
4563 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4564 Status = Private->TextOutList[Index].TextOut->Reset (
4565 Private->TextOutList[Index].TextOut,
4566 ExtendedVerification
4567 );
4568 if (EFI_ERROR (Status)) {
4569 ReturnStatus = Status;
4570 }
4571 }
4572
4573 This->SetAttribute (This, EFI_TEXT_ATTR (This->Mode->Attribute & 0x0F, EFI_BLACK));
4574
4575 //
4576 // reset all mode parameters
4577 //
4578 TextOutSetMode (Private, 0);
4579
4580 return ReturnStatus;
4581 }
4582
4583
4584 /**
4585 Write a Unicode string to the output device.
4586
4587 @param This Protocol instance pointer.
4588 @param WString The NULL-terminated Unicode string to be
4589 displayed on the output device(s). All output
4590 devices must also support the Unicode drawing
4591 defined in this file.
4592
4593 @retval EFI_SUCCESS The string was output to the device.
4594 @retval EFI_DEVICE_ERROR The device reported an error while attempting to
4595 output the text.
4596 @retval EFI_UNSUPPORTED The output device's mode is not currently in a
4597 defined text mode.
4598 @retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the
4599 characters in the Unicode string could not be
4600 rendered and were skipped.
4601
4602 **/
4603 EFI_STATUS
4604 EFIAPI
4605 ConSplitterTextOutOutputString (
4606 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4607 IN CHAR16 *WString
4608 )
4609 {
4610 EFI_STATUS Status;
4611 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4612 UINTN Index;
4613 EFI_STATUS ReturnStatus;
4614 UINTN MaxColumn;
4615 UINTN MaxRow;
4616
4617 This->SetAttribute (This, This->Mode->Attribute);
4618
4619 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4620
4621 //
4622 // return the worst status met
4623 //
4624 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4625 Status = Private->TextOutList[Index].TextOut->OutputString (
4626 Private->TextOutList[Index].TextOut,
4627 WString
4628 );
4629 if (EFI_ERROR (Status)) {
4630 ReturnStatus = Status;
4631 }
4632 }
4633
4634 if (Private->CurrentNumberOfConsoles > 0) {
4635 Private->TextOutMode.CursorColumn = Private->TextOutList[0].TextOut->Mode->CursorColumn;
4636 Private->TextOutMode.CursorRow = Private->TextOutList[0].TextOut->Mode->CursorRow;
4637 } else {
4638 //
4639 // When there is no real console devices in system,
4640 // update cursor position for the virtual device in consplitter.
4641 //
4642 Private->TextOut.QueryMode (
4643 &Private->TextOut,
4644 Private->TextOutMode.Mode,
4645 &MaxColumn,
4646 &MaxRow
4647 );
4648 for (; *WString != CHAR_NULL; WString++) {
4649 switch (*WString) {
4650 case CHAR_BACKSPACE:
4651 if (Private->TextOutMode.CursorColumn == 0 && Private->TextOutMode.CursorRow > 0) {
4652 Private->TextOutMode.CursorRow--;
4653 Private->TextOutMode.CursorColumn = (INT32) (MaxColumn - 1);
4654 } else if (Private->TextOutMode.CursorColumn > 0) {
4655 Private->TextOutMode.CursorColumn--;
4656 }
4657 break;
4658
4659 case CHAR_LINEFEED:
4660 if (Private->TextOutMode.CursorRow < (INT32) (MaxRow - 1)) {
4661 Private->TextOutMode.CursorRow++;
4662 }
4663 break;
4664
4665 case CHAR_CARRIAGE_RETURN:
4666 Private->TextOutMode.CursorColumn = 0;
4667 break;
4668
4669 default:
4670 if (Private->TextOutMode.CursorColumn < (INT32) (MaxColumn - 1)) {
4671 Private->TextOutMode.CursorColumn++;
4672 } else {
4673 Private->TextOutMode.CursorColumn = 0;
4674 if (Private->TextOutMode.CursorRow < (INT32) (MaxRow - 1)) {
4675 Private->TextOutMode.CursorRow++;
4676 }
4677 }
4678 break;
4679 }
4680 }
4681 }
4682
4683 return ReturnStatus;
4684 }
4685
4686
4687 /**
4688 Verifies that all characters in a Unicode string can be output to the
4689 target device.
4690
4691 @param This Protocol instance pointer.
4692 @param WString The NULL-terminated Unicode string to be
4693 examined for the output device(s).
4694
4695 @retval EFI_SUCCESS The device(s) are capable of rendering the
4696 output string.
4697 @retval EFI_UNSUPPORTED Some of the characters in the Unicode string
4698 cannot be rendered by one or more of the output
4699 devices mapped by the EFI handle.
4700
4701 **/
4702 EFI_STATUS
4703 EFIAPI
4704 ConSplitterTextOutTestString (
4705 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4706 IN CHAR16 *WString
4707 )
4708 {
4709 EFI_STATUS Status;
4710 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4711 UINTN Index;
4712 EFI_STATUS ReturnStatus;
4713
4714 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4715
4716 //
4717 // return the worst status met
4718 //
4719 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4720 Status = Private->TextOutList[Index].TextOut->TestString (
4721 Private->TextOutList[Index].TextOut,
4722 WString
4723 );
4724 if (EFI_ERROR (Status)) {
4725 ReturnStatus = Status;
4726 }
4727 }
4728 //
4729 // There is no DevNullTextOutTestString () since a Unicode buffer would
4730 // always return EFI_SUCCESS.
4731 // ReturnStatus will be EFI_SUCCESS if no consoles are present
4732 //
4733 return ReturnStatus;
4734 }
4735
4736
4737 /**
4738 Returns information for an available text mode that the output device(s)
4739 supports.
4740
4741 @param This Protocol instance pointer.
4742 @param ModeNumber The mode number to return information on.
4743 @param Columns Returns the columns of the text output device
4744 for the requested ModeNumber.
4745 @param Rows Returns the rows of the text output device
4746 for the requested ModeNumber.
4747
4748 @retval EFI_SUCCESS The requested mode information was returned.
4749 @retval EFI_DEVICE_ERROR The device had an error and could not complete
4750 the request.
4751 @retval EFI_UNSUPPORTED The mode number was not valid.
4752
4753 **/
4754 EFI_STATUS
4755 EFIAPI
4756 ConSplitterTextOutQueryMode (
4757 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4758 IN UINTN ModeNumber,
4759 OUT UINTN *Columns,
4760 OUT UINTN *Rows
4761 )
4762 {
4763 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4764 UINTN CurrentMode;
4765 INT32 *TextOutModeMap;
4766
4767 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4768
4769 //
4770 // Check whether param ModeNumber is valid.
4771 // ModeNumber should be within range 0 ~ MaxMode - 1.
4772 //
4773 if ( (ModeNumber > (UINTN)(((UINT32)-1)>>1)) ) {
4774 return EFI_UNSUPPORTED;
4775 }
4776
4777 if ((INT32) ModeNumber >= This->Mode->MaxMode) {
4778 return EFI_UNSUPPORTED;
4779 }
4780
4781 //
4782 // We get the available mode from mode intersection map if it's available
4783 //
4784 if (Private->TextOutModeMap != NULL) {
4785 TextOutModeMap = Private->TextOutModeMap + Private->TextOutListCount * ModeNumber;
4786 CurrentMode = (UINTN)(*TextOutModeMap);
4787 *Columns = Private->TextOutQueryData[CurrentMode].Columns;
4788 *Rows = Private->TextOutQueryData[CurrentMode].Rows;
4789 } else {
4790 *Columns = Private->TextOutQueryData[ModeNumber].Columns;
4791 *Rows = Private->TextOutQueryData[ModeNumber].Rows;
4792 }
4793
4794 if (*Columns <= 0 && *Rows <= 0) {
4795 return EFI_UNSUPPORTED;
4796
4797 }
4798
4799 return EFI_SUCCESS;
4800 }
4801
4802
4803 /**
4804 Sets the output device(s) to a specified mode.
4805
4806 @param This Protocol instance pointer.
4807 @param ModeNumber The mode number to set.
4808
4809 @retval EFI_SUCCESS The requested text mode was set.
4810 @retval EFI_DEVICE_ERROR The device had an error and could not complete
4811 the request.
4812 @retval EFI_UNSUPPORTED The mode number was not valid.
4813
4814 **/
4815 EFI_STATUS
4816 EFIAPI
4817 ConSplitterTextOutSetMode (
4818 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4819 IN UINTN ModeNumber
4820 )
4821 {
4822 EFI_STATUS Status;
4823 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4824 UINTN Index;
4825 INT32 *TextOutModeMap;
4826 EFI_STATUS ReturnStatus;
4827
4828 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4829
4830 //
4831 // Check whether param ModeNumber is valid.
4832 // ModeNumber should be within range 0 ~ MaxMode - 1.
4833 //
4834 if ( (ModeNumber > (UINTN)(((UINT32)-1)>>1)) ) {
4835 return EFI_UNSUPPORTED;
4836 }
4837
4838 if ((INT32) ModeNumber >= This->Mode->MaxMode) {
4839 return EFI_UNSUPPORTED;
4840 }
4841 //
4842 // If the mode is being set to the curent mode, then just clear the screen and return.
4843 //
4844 if (Private->TextOutMode.Mode == (INT32) ModeNumber) {
4845 return ConSplitterTextOutClearScreen (This);
4846 }
4847 //
4848 // return the worst status met
4849 //
4850 TextOutModeMap = Private->TextOutModeMap + Private->TextOutListCount * ModeNumber;
4851 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4852 Status = Private->TextOutList[Index].TextOut->SetMode (
4853 Private->TextOutList[Index].TextOut,
4854 TextOutModeMap[Index]
4855 );
4856 if (EFI_ERROR (Status)) {
4857 ReturnStatus = Status;
4858 }
4859 }
4860
4861 //
4862 // Set mode parameter to specified mode number
4863 //
4864 TextOutSetMode (Private, ModeNumber);
4865
4866 return ReturnStatus;
4867 }
4868
4869
4870 /**
4871 Sets the background and foreground colors for the OutputString () and
4872 ClearScreen () functions.
4873
4874 @param This Protocol instance pointer.
4875 @param Attribute The attribute to set. Bits 0..3 are the
4876 foreground color, and bits 4..6 are the
4877 background color. All other bits are undefined
4878 and must be zero. The valid Attributes are
4879 defined in this file.
4880
4881 @retval EFI_SUCCESS The attribute was set.
4882 @retval EFI_DEVICE_ERROR The device had an error and could not complete
4883 the request.
4884 @retval EFI_UNSUPPORTED The attribute requested is not defined.
4885
4886 **/
4887 EFI_STATUS
4888 EFIAPI
4889 ConSplitterTextOutSetAttribute (
4890 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4891 IN UINTN Attribute
4892 )
4893 {
4894 EFI_STATUS Status;
4895 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4896 UINTN Index;
4897 EFI_STATUS ReturnStatus;
4898
4899 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4900
4901 //
4902 // Check whether param Attribute is valid.
4903 //
4904 if ((Attribute | 0x7F) != 0x7F) {
4905 return EFI_UNSUPPORTED;
4906 }
4907
4908 //
4909 // return the worst status met
4910 //
4911 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4912 Status = Private->TextOutList[Index].TextOut->SetAttribute (
4913 Private->TextOutList[Index].TextOut,
4914 Attribute
4915 );
4916 if (EFI_ERROR (Status)) {
4917 ReturnStatus = Status;
4918 }
4919 }
4920
4921 Private->TextOutMode.Attribute = (INT32) Attribute;
4922
4923 return ReturnStatus;
4924 }
4925
4926
4927 /**
4928 Clears the output device(s) display to the currently selected background
4929 color.
4930
4931 @param This Protocol instance pointer.
4932
4933 @retval EFI_SUCCESS The operation completed successfully.
4934 @retval EFI_DEVICE_ERROR The device had an error and could not complete
4935 the request.
4936 @retval EFI_UNSUPPORTED The output device is not in a valid text mode.
4937
4938 **/
4939 EFI_STATUS
4940 EFIAPI
4941 ConSplitterTextOutClearScreen (
4942 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This
4943 )
4944 {
4945 EFI_STATUS Status;
4946 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4947 UINTN Index;
4948 EFI_STATUS ReturnStatus;
4949
4950 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4951
4952 //
4953 // return the worst status met
4954 //
4955 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4956 Status = Private->TextOutList[Index].TextOut->ClearScreen (Private->TextOutList[Index].TextOut);
4957 if (EFI_ERROR (Status)) {
4958 ReturnStatus = Status;
4959 }
4960 }
4961
4962 //
4963 // No need to do extra check here as whether (Column, Row) is valid has
4964 // been checked in ConSplitterTextOutSetCursorPosition. And (0, 0) should
4965 // always be supported.
4966 //
4967 Private->TextOutMode.CursorColumn = 0;
4968 Private->TextOutMode.CursorRow = 0;
4969 Private->TextOutMode.CursorVisible = TRUE;
4970
4971 return ReturnStatus;
4972 }
4973
4974
4975 /**
4976 Sets the current coordinates of the cursor position
4977
4978 @param This Protocol instance pointer.
4979 @param Column The column position to set the cursor to. Must be
4980 greater than or equal to zero and less than the
4981 number of columns by QueryMode ().
4982 @param Row The row position to set the cursor to. Must be
4983 greater than or equal to zero and less than the
4984 number of rows by QueryMode ().
4985
4986 @retval EFI_SUCCESS The operation completed successfully.
4987 @retval EFI_DEVICE_ERROR The device had an error and could not complete
4988 the request.
4989 @retval EFI_UNSUPPORTED The output device is not in a valid text mode,
4990 or the cursor position is invalid for the
4991 current mode.
4992
4993 **/
4994 EFI_STATUS
4995 EFIAPI
4996 ConSplitterTextOutSetCursorPosition (
4997 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4998 IN UINTN Column,
4999 IN UINTN Row
5000 )
5001 {
5002 EFI_STATUS Status;
5003 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
5004 UINTN Index;
5005 EFI_STATUS ReturnStatus;
5006 UINTN MaxColumn;
5007 UINTN MaxRow;
5008 INT32 *TextOutModeMap;
5009 INT32 ModeNumber;
5010 INT32 CurrentMode;
5011
5012 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
5013 TextOutModeMap = NULL;
5014 ModeNumber = Private->TextOutMode.Mode;
5015
5016 //
5017 // Get current MaxColumn and MaxRow from intersection map
5018 //
5019 if (Private->TextOutModeMap != NULL) {
5020 TextOutModeMap = Private->TextOutModeMap + Private->TextOutListCount * ModeNumber;
5021 CurrentMode = *TextOutModeMap;
5022 } else {
5023 CurrentMode = ModeNumber;
5024 }
5025
5026 MaxColumn = Private->TextOutQueryData[CurrentMode].Columns;
5027 MaxRow = Private->TextOutQueryData[CurrentMode].Rows;
5028
5029 if (Column >= MaxColumn || Row >= MaxRow) {
5030 return EFI_UNSUPPORTED;
5031 }
5032 //
5033 // return the worst status met
5034 //
5035 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
5036 Status = Private->TextOutList[Index].TextOut->SetCursorPosition (
5037 Private->TextOutList[Index].TextOut,
5038 Column,
5039 Row
5040 );
5041 if (EFI_ERROR (Status)) {
5042 ReturnStatus = Status;
5043 }
5044 }
5045
5046 //
5047 // No need to do extra check here as whether (Column, Row) is valid has
5048 // been checked in ConSplitterTextOutSetCursorPosition. And (0, 0) should
5049 // always be supported.
5050 //
5051 Private->TextOutMode.CursorColumn = (INT32) Column;
5052 Private->TextOutMode.CursorRow = (INT32) Row;
5053
5054 return ReturnStatus;
5055 }
5056
5057
5058 /**
5059 Makes the cursor visible or invisible
5060
5061 @param This Protocol instance pointer.
5062 @param Visible If TRUE, the cursor is set to be visible. If
5063 FALSE, the cursor is set to be invisible.
5064
5065 @retval EFI_SUCCESS The operation completed successfully.
5066 @retval EFI_DEVICE_ERROR The device had an error and could not complete
5067 the request, or the device does not support
5068 changing the cursor mode.
5069 @retval EFI_UNSUPPORTED The output device is not in a valid text mode.
5070
5071 **/
5072 EFI_STATUS
5073 EFIAPI
5074 ConSplitterTextOutEnableCursor (
5075 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
5076 IN BOOLEAN Visible
5077 )
5078 {
5079 EFI_STATUS Status;
5080 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
5081 UINTN Index;
5082 EFI_STATUS ReturnStatus;
5083
5084 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
5085
5086 //
5087 // return the worst status met
5088 //
5089 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
5090 Status = Private->TextOutList[Index].TextOut->EnableCursor (
5091 Private->TextOutList[Index].TextOut,
5092 Visible
5093 );
5094 if (EFI_ERROR (Status)) {
5095 ReturnStatus = Status;
5096 }
5097 }
5098
5099 Private->TextOutMode.CursorVisible = Visible;
5100
5101 return ReturnStatus;
5102 }