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