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