]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.c
sync tracker to remove duplicate display mode in ConOut virtual handle GOP instance.
[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 TEXT_OUT_SPLITTER_QUERY_DATA *TextOutQueryData;
2247 UINTN Rows;
2248 UINTN Columns;
2249 UINTN StepSize;
2250
2251 //
2252 // Must make sure that current mode won't change even if mode number changes
2253 //
2254 CurrentMaxMode = Private->TextOutMode.MaxMode;
2255 TextOutModeMap = Private->TextOutModeMap;
2256 StepSize = Private->TextOutListCount;
2257 TextOutQueryData = Private->TextOutQueryData;
2258
2259 //
2260 // Query all the mode that the newly added TextOut supports
2261 //
2262 Mode = 0;
2263 MapTable = TextOutModeMap + Private->CurrentNumberOfConsoles;
2264 while (Mode < TextOut->Mode->MaxMode) {
2265 TextOut->QueryMode (TextOut, Mode, &Columns, &Rows);
2266
2267 //
2268 // Search the QueryData database to see if they intersects
2269 //
2270 Index = 0;
2271 while (Index < CurrentMaxMode) {
2272 if ((TextOutQueryData[Index].Rows == Rows) && (TextOutQueryData[Index].Columns == Columns)) {
2273 MapTable[Index * StepSize] = Mode;
2274 break;
2275 }
2276
2277 Index++;
2278 }
2279
2280 Mode++;
2281 }
2282 //
2283 // Now search the TextOutModeMap table to find the intersection of supported
2284 // mode between ConSplitter and the newly added device.
2285 //
2286 ConSplitterGetIntersection (
2287 TextOutModeMap,
2288 MapTable,
2289 StepSize,
2290 StepSize,
2291 &Private->TextOutMode.MaxMode,
2292 &Private->TextOutMode.Mode
2293 );
2294
2295 return ;
2296 }
2297
2298 STATIC
2299 EFI_STATUS
2300 ConSplitterGetIntersectionBetweenConOutAndStrErr (
2301 VOID
2302 )
2303 /*++
2304
2305 Routine Description:
2306
2307 Arguments:
2308
2309 Returns:
2310
2311 None
2312 EFI_OUT_OF_RESOURCES
2313
2314 --*/
2315 {
2316 UINTN ConOutNumOfConsoles;
2317 UINTN StdErrNumOfConsoles;
2318 TEXT_OUT_AND_GOP_DATA *ConOutTextOutList;
2319 TEXT_OUT_AND_GOP_DATA *StdErrTextOutList;
2320 UINTN Indexi;
2321 UINTN Indexj;
2322 UINTN Rows;
2323 UINTN Columns;
2324 INT32 ConOutMaxMode;
2325 INT32 StdErrMaxMode;
2326 INT32 Mode;
2327 INT32 Index;
2328 INT32 *ConOutModeMap;
2329 INT32 *StdErrModeMap;
2330 INT32 *ConOutMapTable;
2331 INT32 *StdErrMapTable;
2332 TEXT_OUT_SPLITTER_QUERY_DATA *ConOutQueryData;
2333 TEXT_OUT_SPLITTER_QUERY_DATA *StdErrQueryData;
2334 BOOLEAN FoundTheSameTextOut;
2335 UINTN ConOutMapTableSize;
2336 UINTN StdErrMapTableSize;
2337
2338 ConOutNumOfConsoles = mConOut.CurrentNumberOfConsoles;
2339 StdErrNumOfConsoles = mStdErr.CurrentNumberOfConsoles;
2340 ConOutTextOutList = mConOut.TextOutList;
2341 StdErrTextOutList = mStdErr.TextOutList;
2342
2343 Indexi = 0;
2344 FoundTheSameTextOut = FALSE;
2345 while ((Indexi < ConOutNumOfConsoles) && (!FoundTheSameTextOut)) {
2346 Indexj = 0;
2347 while (Indexj < StdErrNumOfConsoles) {
2348 if (ConOutTextOutList->TextOut == StdErrTextOutList->TextOut) {
2349 FoundTheSameTextOut = TRUE;
2350 break;
2351 }
2352
2353 Indexj++;
2354 StdErrTextOutList++;
2355 }
2356
2357 Indexi++;
2358 ConOutTextOutList++;
2359 }
2360
2361 if (!FoundTheSameTextOut) {
2362 return EFI_SUCCESS;
2363 }
2364 //
2365 // Must make sure that current mode won't change even if mode number changes
2366 //
2367 ConOutMaxMode = mConOut.TextOutMode.MaxMode;
2368 ConOutModeMap = mConOut.TextOutModeMap;
2369 ConOutQueryData = mConOut.TextOutQueryData;
2370
2371 StdErrMaxMode = mStdErr.TextOutMode.MaxMode;
2372 StdErrModeMap = mStdErr.TextOutModeMap;
2373 StdErrQueryData = mStdErr.TextOutQueryData;
2374
2375 //
2376 // Allocate the map table and set the map table's index to -1.
2377 //
2378 ConOutMapTableSize = ConOutMaxMode * sizeof (INT32);
2379 ConOutMapTable = AllocateZeroPool (ConOutMapTableSize);
2380 if (ConOutMapTable == NULL) {
2381 return EFI_OUT_OF_RESOURCES;
2382 }
2383
2384 SetMem (ConOutMapTable, ConOutMapTableSize, 0xFF);
2385
2386 StdErrMapTableSize = StdErrMaxMode * sizeof (INT32);
2387 StdErrMapTable = AllocateZeroPool (StdErrMapTableSize);
2388 if (StdErrMapTable == NULL) {
2389 return EFI_OUT_OF_RESOURCES;
2390 }
2391
2392 SetMem (StdErrMapTable, StdErrMapTableSize, 0xFF);
2393
2394 //
2395 // Find the intersection of the two set of modes. If they actually intersect, the
2396 // correponding entry in the map table is set to 1.
2397 //
2398 Mode = 0;
2399 while (Mode < ConOutMaxMode) {
2400 //
2401 // Search the other's QueryData database to see if they intersect
2402 //
2403 Index = 0;
2404 Rows = ConOutQueryData[Mode].Rows;
2405 Columns = ConOutQueryData[Mode].Columns;
2406 while (Index < StdErrMaxMode) {
2407 if ((StdErrQueryData[Index].Rows == Rows) && (StdErrQueryData[Index].Columns == Columns)) {
2408 ConOutMapTable[Mode] = 1;
2409 StdErrMapTable[Index] = 1;
2410 break;
2411 }
2412
2413 Index++;
2414 }
2415
2416 Mode++;
2417 }
2418 //
2419 // Now search the TextOutModeMap table to find the intersection of supported
2420 // mode between ConSplitter and the newly added device.
2421 //
2422 ConSplitterGetIntersection (
2423 ConOutModeMap,
2424 ConOutMapTable,
2425 mConOut.TextOutListCount,
2426 1,
2427 &(mConOut.TextOutMode.MaxMode),
2428 &(mConOut.TextOutMode.Mode)
2429 );
2430 if (mConOut.TextOutMode.Mode < 0) {
2431 mConOut.TextOut.SetMode (&(mConOut.TextOut), 0);
2432 }
2433
2434 ConSplitterGetIntersection (
2435 StdErrModeMap,
2436 StdErrMapTable,
2437 mStdErr.TextOutListCount,
2438 1,
2439 &(mStdErr.TextOutMode.MaxMode),
2440 &(mStdErr.TextOutMode.Mode)
2441 );
2442 if (mStdErr.TextOutMode.Mode < 0) {
2443 mStdErr.TextOut.SetMode (&(mStdErr.TextOut), 0);
2444 }
2445
2446 FreePool (ConOutMapTable);
2447 FreePool (StdErrMapTable);
2448
2449 return EFI_SUCCESS;
2450 }
2451
2452 STATIC
2453 EFI_STATUS
2454 ConSplitterAddGraphicsOutputMode (
2455 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
2456 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput,
2457 IN EFI_UGA_DRAW_PROTOCOL *UgaDraw
2458 )
2459 /*++
2460
2461 Routine Description:
2462
2463 Arguments:
2464
2465 Returns:
2466
2467 None
2468
2469 --*/
2470 {
2471 EFI_STATUS Status;
2472 UINTN Index;
2473 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Mode;
2474 UINTN SizeOfInfo;
2475 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
2476 EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *CurrentGraphicsOutputMode;
2477 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *ModeBuffer;
2478 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *MatchedMode;
2479 UINTN NumberIndex;
2480 BOOLEAN Match;
2481 BOOLEAN AlreadyExist;
2482
2483 if ((GraphicsOutput == NULL) && (UgaDraw == NULL)) {
2484 return EFI_UNSUPPORTED;
2485 }
2486
2487 CurrentGraphicsOutputMode = Private->GraphicsOutput.Mode;
2488
2489 Index = 0;
2490
2491 if (Private->CurrentNumberOfUgaDraw != 0) {
2492 //
2493 // If any UGA device has already been added, then there is no need to
2494 // calculate intersection of display mode of different GOP/UGA device,
2495 // since only one display mode will be exported (i.e. user-defined mode)
2496 //
2497 goto Done;
2498 }
2499
2500 if (GraphicsOutput != NULL) {
2501 if (Private->CurrentNumberOfGraphicsOutput == 0) {
2502 //
2503 // This is the first Graphics Output device added
2504 //
2505 CurrentGraphicsOutputMode->MaxMode = GraphicsOutput->Mode->MaxMode;
2506 CurrentGraphicsOutputMode->Mode = GraphicsOutput->Mode->Mode;
2507 CopyMem (CurrentGraphicsOutputMode->Info, GraphicsOutput->Mode->Info, GraphicsOutput->Mode->SizeOfInfo);
2508 CurrentGraphicsOutputMode->SizeOfInfo = GraphicsOutput->Mode->SizeOfInfo;
2509 CurrentGraphicsOutputMode->FrameBufferBase = GraphicsOutput->Mode->FrameBufferBase;
2510 CurrentGraphicsOutputMode->FrameBufferSize = GraphicsOutput->Mode->FrameBufferSize;
2511
2512 //
2513 // Allocate resource for the private mode buffer
2514 //
2515 ModeBuffer = AllocatePool (GraphicsOutput->Mode->SizeOfInfo * GraphicsOutput->Mode->MaxMode);
2516 if (ModeBuffer == NULL) {
2517 return EFI_OUT_OF_RESOURCES;
2518 }
2519 FreePool (Private->GraphicsOutputModeBuffer);
2520 Private->GraphicsOutputModeBuffer = ModeBuffer;
2521
2522 //
2523 // Store all supported display modes to the private mode buffer
2524 //
2525 Mode = ModeBuffer;
2526 for (Index = 0; Index < GraphicsOutput->Mode->MaxMode; Index++) {
2527 Status = GraphicsOutput->QueryMode (GraphicsOutput, (UINT32) Index, &SizeOfInfo, &Info);
2528 if (EFI_ERROR (Status)) {
2529 return Status;
2530 }
2531 CopyMem (Mode, Info, SizeOfInfo);
2532 Mode++;
2533 FreePool (Info);
2534 }
2535 } else {
2536 //
2537 // Check intersection of display mode
2538 //
2539 ModeBuffer = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION) * CurrentGraphicsOutputMode->MaxMode);
2540 if (ModeBuffer == NULL) {
2541 return EFI_OUT_OF_RESOURCES;
2542 }
2543
2544 MatchedMode = ModeBuffer;
2545 Mode = &Private->GraphicsOutputModeBuffer[0];
2546 for (Index = 0; Index < CurrentGraphicsOutputMode->MaxMode; Index++) {
2547 Match = FALSE;
2548
2549 for (NumberIndex = 0; NumberIndex < GraphicsOutput->Mode->MaxMode; NumberIndex++) {
2550 Status = GraphicsOutput->QueryMode (GraphicsOutput, (UINT32) NumberIndex, &SizeOfInfo, &Info);
2551 if (EFI_ERROR (Status)) {
2552 return Status;
2553 }
2554 if ((Info->HorizontalResolution == Mode->HorizontalResolution) &&
2555 (Info->VerticalResolution == Mode->VerticalResolution)) {
2556 Match = TRUE;
2557 FreePool (Info);
2558 break;
2559 }
2560 FreePool (Info);
2561 }
2562
2563 if (Match) {
2564 AlreadyExist = FALSE;
2565
2566 for (Info = ModeBuffer; Info < MatchedMode; Info++) {
2567 if ((Info->HorizontalResolution == Mode->HorizontalResolution) &&
2568 (Info->VerticalResolution == Mode->VerticalResolution)) {
2569 AlreadyExist = TRUE;
2570 break;
2571 }
2572 }
2573
2574 if (!AlreadyExist) {
2575 CopyMem (MatchedMode, Mode, sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
2576
2577 //
2578 // Physical frame buffer is no longer available, change PixelFormat to PixelBltOnly
2579 //
2580 MatchedMode->Version = 0;
2581 MatchedMode->PixelFormat = PixelBltOnly;
2582 ZeroMem (&MatchedMode->PixelInformation, sizeof (EFI_PIXEL_BITMASK));
2583
2584 MatchedMode++;
2585 }
2586 }
2587
2588 Mode++;
2589 }
2590
2591 //
2592 // Drop the old mode buffer, assign it to a new one
2593 //
2594 FreePool (Private->GraphicsOutputModeBuffer);
2595 Private->GraphicsOutputModeBuffer = ModeBuffer;
2596
2597 //
2598 // Physical frame buffer is no longer available when there are more than one physical GOP devices
2599 //
2600 CurrentGraphicsOutputMode->MaxMode = (UINT32) (((UINTN) MatchedMode - (UINTN) ModeBuffer) / sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
2601 CurrentGraphicsOutputMode->Info->PixelFormat = PixelBltOnly;
2602 ZeroMem (&CurrentGraphicsOutputMode->Info->PixelInformation, sizeof (EFI_PIXEL_BITMASK));
2603 CurrentGraphicsOutputMode->SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
2604 CurrentGraphicsOutputMode->FrameBufferBase = (EFI_PHYSICAL_ADDRESS) NULL;
2605 CurrentGraphicsOutputMode->FrameBufferSize = 0;
2606 }
2607
2608 //
2609 // Select a prefered Display mode 800x600
2610 //
2611 for (Index = 0; Index < CurrentGraphicsOutputMode->MaxMode; Index++) {
2612 Mode = &Private->GraphicsOutputModeBuffer[Index];
2613 if ((Mode->HorizontalResolution == 800) && (Mode->VerticalResolution == 600)) {
2614 break;
2615 }
2616 }
2617 //
2618 // Prefered mode is not found, set to mode 0
2619 //
2620 if (Index >= CurrentGraphicsOutputMode->MaxMode) {
2621 Index = 0;
2622 }
2623
2624 }
2625 if (UgaDraw != NULL) {
2626 //
2627 // For UGA device, it's inconvenient to retrieve all the supported display modes.
2628 // To simplify the implementation, only add one resolution(800x600, 32bit color depth) as defined in UEFI spec
2629 //
2630 CurrentGraphicsOutputMode->MaxMode = 1;
2631 Info = CurrentGraphicsOutputMode->Info;
2632 Info->Version = 0;
2633 Info->HorizontalResolution = 800;
2634 Info->VerticalResolution = 600;
2635 Info->PixelFormat = PixelBltOnly;
2636 Info->PixelsPerScanLine = 800;
2637 CurrentGraphicsOutputMode->SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
2638 CurrentGraphicsOutputMode->FrameBufferBase = (EFI_PHYSICAL_ADDRESS) NULL;
2639 CurrentGraphicsOutputMode->FrameBufferSize = 0;
2640
2641 //
2642 // Update the private mode buffer
2643 //
2644 CopyMem (&Private->GraphicsOutputModeBuffer[0], Info, sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
2645
2646 //
2647 // Only mode 0 is available to be set
2648 //
2649 Index = 0;
2650 }
2651
2652 Done:
2653
2654 if (GraphicsOutput != NULL) {
2655 Private->CurrentNumberOfGraphicsOutput++;
2656 }
2657 if (UgaDraw != NULL) {
2658 Private->CurrentNumberOfUgaDraw++;
2659 }
2660
2661 //
2662 // Force GraphicsOutput mode to be set,
2663 // regardless whether the console is in EfiConsoleControlScreenGraphics or EfiConsoleControlScreenText mode
2664 //
2665 Private->HardwareNeedsStarting = TRUE;
2666 //
2667 // Current mode number may need update now, so set it to an invalid mode number
2668 //
2669 Status = Private->GraphicsOutput.SetMode (&Private->GraphicsOutput, (UINT32) Index);
2670
2671 return Status;
2672 }
2673
2674 EFI_STATUS
2675 ConSplitterTextOutAddDevice (
2676 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
2677 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut,
2678 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput,
2679 IN EFI_UGA_DRAW_PROTOCOL *UgaDraw
2680 )
2681 /*++
2682
2683 Routine Description:
2684
2685 Arguments:
2686
2687 Returns:
2688
2689 None
2690
2691 --*/
2692 {
2693 EFI_STATUS Status;
2694 UINTN CurrentNumOfConsoles;
2695 INT32 CurrentMode;
2696 INT32 MaxMode;
2697 TEXT_OUT_AND_GOP_DATA *TextAndGop;
2698
2699 Status = EFI_SUCCESS;
2700 CurrentNumOfConsoles = Private->CurrentNumberOfConsoles;
2701
2702 //
2703 // If the Text Out List is full, enlarge it by calling growbuffer().
2704 //
2705 while (CurrentNumOfConsoles >= Private->TextOutListCount) {
2706 Status = ConSplitterGrowBuffer (
2707 sizeof (TEXT_OUT_AND_GOP_DATA),
2708 &Private->TextOutListCount,
2709 (VOID **) &Private->TextOutList
2710 );
2711 if (EFI_ERROR (Status)) {
2712 return EFI_OUT_OF_RESOURCES;
2713 }
2714 //
2715 // Also need to reallocate the TextOutModeMap table
2716 //
2717 Status = ConSplitterGrowMapTable (Private);
2718 if (EFI_ERROR (Status)) {
2719 return EFI_OUT_OF_RESOURCES;
2720 }
2721 }
2722
2723 TextAndGop = &Private->TextOutList[CurrentNumOfConsoles];
2724
2725 TextAndGop->TextOut = TextOut;
2726 TextAndGop->GraphicsOutput = GraphicsOutput;
2727 TextAndGop->UgaDraw = UgaDraw;
2728
2729 if ((GraphicsOutput == NULL) && (UgaDraw == NULL)) {
2730 //
2731 // If No UGA device then use the ConOut device
2732 //
2733 TextAndGop->TextOutEnabled = TRUE;
2734 } else {
2735 //
2736 // If UGA device use ConOut device only used if UGA screen is in Text mode
2737 //
2738 TextAndGop->TextOutEnabled = (BOOLEAN) (Private->ConsoleOutputMode == EfiConsoleControlScreenText);
2739 }
2740
2741 if (CurrentNumOfConsoles == 0) {
2742 //
2743 // Add the first device's output mode to console splitter's mode list
2744 //
2745 Status = ConSplitterAddOutputMode (Private, TextOut);
2746 } else {
2747 ConSplitterSyncOutputMode (Private, TextOut);
2748 }
2749
2750 Private->CurrentNumberOfConsoles++;
2751
2752 //
2753 // Scan both TextOutList, for the intersection TextOut device
2754 // maybe both ConOut and StdErr incorporate the same Text Out
2755 // device in them, thus the output of both should be synced.
2756 //
2757 ConSplitterGetIntersectionBetweenConOutAndStrErr ();
2758
2759 CurrentMode = Private->TextOutMode.Mode;
2760 MaxMode = Private->TextOutMode.MaxMode;
2761 ASSERT (MaxMode >= 1);
2762
2763 if (FeaturePcdGet (PcdConOutGopSupport)) {
2764 if ((GraphicsOutput != NULL) || (UgaDraw != NULL)) {
2765 ConSplitterAddGraphicsOutputMode (Private, GraphicsOutput, UgaDraw);
2766 }
2767 }
2768
2769 if (Private->ConsoleOutputMode == EfiConsoleControlScreenGraphics && GraphicsOutput != NULL) {
2770 //
2771 // We just added a new UGA device in graphics mode
2772 //
2773 if (FeaturePcdGet (PcdConOutGopSupport)) {
2774 DevNullGopSync (Private, TextAndGop->GraphicsOutput, TextAndGop->UgaDraw);
2775 } else if (FeaturePcdGet (PcdConOutUgaSupport)) {
2776 DevNullUgaSync (Private, TextAndGop->GraphicsOutput, TextAndGop->UgaDraw);
2777 }
2778 } else if ((CurrentMode >= 0) && ((GraphicsOutput != NULL) || (UgaDraw != NULL)) && (CurrentMode < Private->TextOutMode.MaxMode)) {
2779 //
2780 // The new console supports the same mode of the current console so sync up
2781 //
2782 DevNullSyncStdOut (Private);
2783 } else {
2784 //
2785 // If ConOut, then set the mode to Mode #0 which us 80 x 25
2786 //
2787 Private->TextOut.SetMode (&Private->TextOut, 0);
2788 }
2789
2790 return Status;
2791 }
2792
2793 EFI_STATUS
2794 ConSplitterTextOutDeleteDevice (
2795 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
2796 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut
2797 )
2798 /*++
2799
2800 Routine Description:
2801
2802 Arguments:
2803
2804 Returns:
2805
2806 None
2807
2808 --*/
2809 {
2810 INT32 Index;
2811 UINTN CurrentNumOfConsoles;
2812 TEXT_OUT_AND_GOP_DATA *TextOutList;
2813 EFI_STATUS Status;
2814
2815 //
2816 // Remove the specified text-out device data structure from the Text out List,
2817 // and rearrange the remaining data structures in the Text out List.
2818 //
2819 CurrentNumOfConsoles = Private->CurrentNumberOfConsoles;
2820 Index = (INT32) CurrentNumOfConsoles - 1;
2821 TextOutList = Private->TextOutList;
2822 while (Index >= 0) {
2823 if (TextOutList->TextOut == TextOut) {
2824 CopyMem (TextOutList, TextOutList + 1, sizeof (TEXT_OUT_AND_GOP_DATA) * Index);
2825 CurrentNumOfConsoles--;
2826 if (FeaturePcdGet (PcdConOutGopSupport)) {
2827 if (TextOutList->UgaDraw != NULL) {
2828 Private->CurrentNumberOfUgaDraw--;
2829 }
2830 if (TextOutList->GraphicsOutput != NULL) {
2831 Private->CurrentNumberOfGraphicsOutput--;
2832 }
2833 }
2834 break;
2835 }
2836
2837 Index--;
2838 TextOutList++;
2839 }
2840 //
2841 // The specified TextOut is not managed by the ConSplitter driver
2842 //
2843 if (Index < 0) {
2844 return EFI_NOT_FOUND;
2845 }
2846
2847 if (CurrentNumOfConsoles == 0) {
2848 //
2849 // If the number of consoles is zero clear the Dev NULL device
2850 //
2851 Private->CurrentNumberOfConsoles = 0;
2852 Private->TextOutMode.MaxMode = 1;
2853 Private->TextOutQueryData[0].Columns = 80;
2854 Private->TextOutQueryData[0].Rows = 25;
2855 DevNullTextOutSetMode (Private, 0);
2856
2857 return EFI_SUCCESS;
2858 }
2859 //
2860 // Max Mode is realy an intersection of the QueryMode command to all
2861 // devices. So we must copy the QueryMode of the first device to
2862 // QueryData.
2863 //
2864 ZeroMem (
2865 Private->TextOutQueryData,
2866 Private->TextOutQueryDataCount * sizeof (TEXT_OUT_SPLITTER_QUERY_DATA)
2867 );
2868
2869 FreePool (Private->TextOutModeMap);
2870 Private->TextOutModeMap = NULL;
2871 TextOutList = Private->TextOutList;
2872
2873 //
2874 // Add the first TextOut to the QueryData array and ModeMap table
2875 //
2876 Status = ConSplitterAddOutputMode (Private, TextOutList->TextOut);
2877
2878 //
2879 // Now add one by one
2880 //
2881 Index = 1;
2882 Private->CurrentNumberOfConsoles = 1;
2883 TextOutList++;
2884 while ((UINTN) Index < CurrentNumOfConsoles) {
2885 ConSplitterSyncOutputMode (Private, TextOutList->TextOut);
2886 Index++;
2887 Private->CurrentNumberOfConsoles++;
2888 TextOutList++;
2889 }
2890
2891 ConSplitterGetIntersectionBetweenConOutAndStrErr ();
2892
2893 return Status;
2894 }
2895 //
2896 // ConSplitter TextIn member functions
2897 //
2898 EFI_STATUS
2899 EFIAPI
2900 ConSplitterTextInReset (
2901 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
2902 IN BOOLEAN ExtendedVerification
2903 )
2904 /*++
2905
2906 Routine Description:
2907 Reset the input device and optionaly run diagnostics
2908
2909 Arguments:
2910 This - Protocol instance pointer.
2911 ExtendedVerification - Driver may perform diagnostics on reset.
2912
2913 Returns:
2914 EFI_SUCCESS - The device was reset.
2915 EFI_DEVICE_ERROR - The device is not functioning properly and could
2916 not be reset.
2917
2918 --*/
2919 {
2920 EFI_STATUS Status;
2921 EFI_STATUS ReturnStatus;
2922 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
2923 UINTN Index;
2924
2925 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
2926
2927 Private->KeyEventSignalState = FALSE;
2928
2929 //
2930 // return the worst status met
2931 //
2932 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
2933 Status = Private->TextInList[Index]->Reset (
2934 Private->TextInList[Index],
2935 ExtendedVerification
2936 );
2937 if (EFI_ERROR (Status)) {
2938 ReturnStatus = Status;
2939 }
2940 }
2941
2942 return ReturnStatus;
2943 }
2944
2945 EFI_STATUS
2946 EFIAPI
2947 ConSplitterTextInPrivateReadKeyStroke (
2948 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
2949 OUT EFI_INPUT_KEY *Key
2950 )
2951 /*++
2952
2953 Routine Description:
2954 Reads the next keystroke from the input device. The WaitForKey Event can
2955 be used to test for existance of a keystroke via WaitForEvent () call.
2956
2957 Arguments:
2958 This - Protocol instance pointer.
2959 Key - Driver may perform diagnostics on reset.
2960
2961 Returns:
2962 EFI_SUCCESS - The keystroke information was returned.
2963 EFI_NOT_READY - There was no keystroke data availiable.
2964 EFI_DEVICE_ERROR - The keydtroke information was not returned due to
2965 hardware errors.
2966
2967 --*/
2968 {
2969 EFI_STATUS Status;
2970 UINTN Index;
2971 EFI_INPUT_KEY CurrentKey;
2972
2973 Key->UnicodeChar = 0;
2974 Key->ScanCode = SCAN_NULL;
2975
2976 //
2977 // if no physical console input device exists, return EFI_NOT_READY;
2978 // if any physical console input device has key input,
2979 // return the key and EFI_SUCCESS.
2980 //
2981 for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {
2982 Status = Private->TextInList[Index]->ReadKeyStroke (
2983 Private->TextInList[Index],
2984 &CurrentKey
2985 );
2986 if (!EFI_ERROR (Status)) {
2987 *Key = CurrentKey;
2988 return Status;
2989 }
2990 }
2991
2992 return EFI_NOT_READY;
2993 }
2994
2995 BOOLEAN
2996 ConSpliterConssoleControlStdInLocked (
2997 VOID
2998 )
2999 /*++
3000
3001 Routine Description:
3002 Return TRUE if StdIn is locked. The ConIn device on the virtual handle is
3003 the only device locked.
3004
3005 Arguments:
3006 NONE
3007
3008 Returns:
3009 TRUE - StdIn locked
3010 FALSE - StdIn working normally
3011
3012 --*/
3013 {
3014 return mConIn.PasswordEnabled;
3015 }
3016
3017 VOID
3018 EFIAPI
3019 ConSpliterConsoleControlLockStdInEvent (
3020 IN EFI_EVENT Event,
3021 IN VOID *Context
3022 )
3023 /*++
3024
3025 Routine Description:
3026 This timer event will fire when StdIn is locked. It will check the key
3027 sequence on StdIn to see if it matches the password. Any error in the
3028 password will cause the check to reset. As long a mConIn.PasswordEnabled is
3029 TRUE the StdIn splitter will not report any input.
3030
3031 Arguments:
3032 (Standard EFI_EVENT_NOTIFY)
3033
3034 Returns:
3035 None
3036
3037 --*/
3038 {
3039 EFI_STATUS Status;
3040 EFI_INPUT_KEY Key;
3041 CHAR16 BackSpaceString[2];
3042 CHAR16 SpaceString[2];
3043
3044 do {
3045 Status = ConSplitterTextInPrivateReadKeyStroke (&mConIn, &Key);
3046 if (!EFI_ERROR (Status)) {
3047 //
3048 // if it's an ENTER, match password
3049 //
3050 if ((Key.UnicodeChar == CHAR_CARRIAGE_RETURN) && (Key.ScanCode == SCAN_NULL)) {
3051 mConIn.PwdAttempt[mConIn.PwdIndex] = CHAR_NULL;
3052 if (StrCmp (mConIn.Password, mConIn.PwdAttempt)) {
3053 //
3054 // Password not match
3055 //
3056 ConSplitterTextOutOutputString (&mConOut.TextOut, (CHAR16 *) L"\n\rPassword not correct\n\r");
3057 mConIn.PwdIndex = 0;
3058 } else {
3059 //
3060 // Key matches password sequence
3061 //
3062 gBS->SetTimer (mConIn.LockEvent, TimerPeriodic, 0);
3063 mConIn.PasswordEnabled = FALSE;
3064 Status = EFI_NOT_READY;
3065 }
3066 } else if ((Key.UnicodeChar == CHAR_BACKSPACE) && (Key.ScanCode == SCAN_NULL)) {
3067 //
3068 // BackSpace met
3069 //
3070 if (mConIn.PwdIndex > 0) {
3071 BackSpaceString[0] = CHAR_BACKSPACE;
3072 BackSpaceString[1] = 0;
3073
3074 SpaceString[0] = ' ';
3075 SpaceString[1] = 0;
3076
3077 ConSplitterTextOutOutputString (&mConOut.TextOut, BackSpaceString);
3078 ConSplitterTextOutOutputString (&mConOut.TextOut, SpaceString);
3079 ConSplitterTextOutOutputString (&mConOut.TextOut, BackSpaceString);
3080
3081 mConIn.PwdIndex--;
3082 }
3083 } else if ((Key.ScanCode == SCAN_NULL) && (Key.UnicodeChar >= 32)) {
3084 //
3085 // If it's not an ENTER, neigher a function key, nor a CTRL-X or ALT-X, record the input
3086 //
3087 if (mConIn.PwdIndex < (MAX_STD_IN_PASSWORD - 1)) {
3088 if (mConIn.PwdIndex == 0) {
3089 ConSplitterTextOutOutputString (&mConOut.TextOut, (CHAR16 *) L"\n\r");
3090 }
3091
3092 ConSplitterTextOutOutputString (&mConOut.TextOut, (CHAR16 *) L"*");
3093 mConIn.PwdAttempt[mConIn.PwdIndex] = Key.UnicodeChar;
3094 mConIn.PwdIndex++;
3095 }
3096 }
3097 }
3098 } while (!EFI_ERROR (Status));
3099 }
3100
3101 EFI_STATUS
3102 EFIAPI
3103 ConSpliterConsoleControlLockStdIn (
3104 IN EFI_CONSOLE_CONTROL_PROTOCOL *This,
3105 IN CHAR16 *Password
3106 )
3107 /*++
3108
3109 Routine Description:
3110 If Password is NULL unlock the password state variable and set the event
3111 timer. If the Password is too big return an error. If the Password is valid
3112 Copy the Password and enable state variable and then arm the periodic timer
3113
3114 Arguments:
3115
3116 Returns:
3117 EFI_SUCCESS - Lock the StdIn device
3118 EFI_INVALID_PARAMETER - Password is NULL
3119 EFI_OUT_OF_RESOURCES - Buffer allocation to store the password fails
3120
3121 --*/
3122 {
3123 if (Password == NULL) {
3124 return EFI_INVALID_PARAMETER;
3125 }
3126
3127 if (StrLen (Password) >= MAX_STD_IN_PASSWORD) {
3128 //
3129 // Currently have a max password size
3130 //
3131 return EFI_OUT_OF_RESOURCES;
3132 }
3133 //
3134 // Save the password, initialize state variables and arm event timer
3135 //
3136 StrCpy (mConIn.Password, Password);
3137 mConIn.PasswordEnabled = TRUE;
3138 mConIn.PwdIndex = 0;
3139 gBS->SetTimer (mConIn.LockEvent, TimerPeriodic, (10000 * 25));
3140
3141 return EFI_SUCCESS;
3142 }
3143
3144 EFI_STATUS
3145 EFIAPI
3146 ConSplitterTextInReadKeyStroke (
3147 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
3148 OUT EFI_INPUT_KEY *Key
3149 )
3150 /*++
3151
3152 Routine Description:
3153 Reads the next keystroke from the input device. The WaitForKey Event can
3154 be used to test for existance of a keystroke via WaitForEvent () call.
3155 If the ConIn is password locked make it look like no keystroke is availible
3156
3157 Arguments:
3158 This - Protocol instance pointer.
3159 Key - Driver may perform diagnostics on reset.
3160
3161 Returns:
3162 EFI_SUCCESS - The keystroke information was returned.
3163 EFI_NOT_READY - There was no keystroke data availiable.
3164 EFI_DEVICE_ERROR - The keydtroke information was not returned due to
3165 hardware errors.
3166
3167 --*/
3168 {
3169 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3170
3171 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3172 if (Private->PasswordEnabled) {
3173 //
3174 // If StdIn Locked return not ready
3175 //
3176 return EFI_NOT_READY;
3177 }
3178
3179 Private->KeyEventSignalState = FALSE;
3180
3181 return ConSplitterTextInPrivateReadKeyStroke (Private, Key);
3182 }
3183
3184 VOID
3185 EFIAPI
3186 ConSplitterTextInWaitForKey (
3187 IN EFI_EVENT Event,
3188 IN VOID *Context
3189 )
3190 /*++
3191
3192 Routine Description:
3193 This event agregates all the events of the ConIn devices in the spliter.
3194 If the ConIn is password locked then return.
3195 If any events of physical ConIn devices are signaled, signal the ConIn
3196 spliter event. This will cause the calling code to call
3197 ConSplitterTextInReadKeyStroke ().
3198
3199 Arguments:
3200 Event - The Event assoicated with callback.
3201 Context - Context registered when Event was created.
3202
3203 Returns:
3204 None
3205
3206 --*/
3207 {
3208 EFI_STATUS Status;
3209 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3210 UINTN Index;
3211
3212 Private = (TEXT_IN_SPLITTER_PRIVATE_DATA *) Context;
3213 if (Private->PasswordEnabled) {
3214 //
3215 // If StdIn Locked return not ready
3216 //
3217 return ;
3218 }
3219
3220 //
3221 // if KeyEventSignalState is flagged before, and not cleared by Reset() or ReadKeyStroke()
3222 //
3223 if (Private->KeyEventSignalState) {
3224 gBS->SignalEvent (Event);
3225 return ;
3226 }
3227 //
3228 // if any physical console input device has key input, signal the event.
3229 //
3230 for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {
3231 Status = gBS->CheckEvent (Private->TextInList[Index]->WaitForKey);
3232 if (!EFI_ERROR (Status)) {
3233 gBS->SignalEvent (Event);
3234 Private->KeyEventSignalState = TRUE;
3235 }
3236 }
3237 }
3238
3239
3240 STATIC
3241 BOOLEAN
3242 IsKeyRegistered (
3243 IN EFI_KEY_DATA *RegsiteredData,
3244 IN EFI_KEY_DATA *InputData
3245 )
3246 /*++
3247
3248 Routine Description:
3249
3250 Arguments:
3251
3252 RegsiteredData - A pointer to a buffer that is filled in with the keystroke
3253 state data for the key that was registered.
3254 InputData - A pointer to a buffer that is filled in with the keystroke
3255 state data for the key that was pressed.
3256
3257 Returns:
3258 TRUE - Key be pressed matches a registered key.
3259 FLASE - Match failed.
3260
3261 --*/
3262 {
3263 ASSERT (RegsiteredData != NULL && InputData != NULL);
3264
3265 if ((RegsiteredData->Key.ScanCode != InputData->Key.ScanCode) ||
3266 (RegsiteredData->Key.UnicodeChar != InputData->Key.UnicodeChar)) {
3267 return FALSE;
3268 }
3269
3270 //
3271 // Assume KeyShiftState/KeyToggleState = 0 in Registered key data means these state could be ignored.
3272 //
3273 if (RegsiteredData->KeyState.KeyShiftState != 0 &&
3274 RegsiteredData->KeyState.KeyShiftState != InputData->KeyState.KeyShiftState) {
3275 return FALSE;
3276 }
3277 if (RegsiteredData->KeyState.KeyToggleState != 0 &&
3278 RegsiteredData->KeyState.KeyToggleState != InputData->KeyState.KeyToggleState) {
3279 return FALSE;
3280 }
3281
3282 return TRUE;
3283
3284 }
3285
3286 //
3287 // Simple Text Input Ex protocol functions
3288 //
3289
3290 EFI_STATUS
3291 EFIAPI
3292 ConSplitterTextInResetEx (
3293 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
3294 IN BOOLEAN ExtendedVerification
3295 )
3296 /*++
3297
3298 Routine Description:
3299 Reset the input device and optionaly run diagnostics
3300
3301 Arguments:
3302 This - Protocol instance pointer.
3303 ExtendedVerification - Driver may perform diagnostics on reset.
3304
3305 Returns:
3306 EFI_SUCCESS - The device was reset.
3307 EFI_DEVICE_ERROR - The device is not functioning properly and could
3308 not be reset.
3309
3310 --*/
3311 {
3312 EFI_STATUS Status;
3313 EFI_STATUS ReturnStatus;
3314 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3315 UINTN Index;
3316
3317 Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3318
3319 Private->KeyEventSignalState = FALSE;
3320
3321 //
3322 // return the worst status met
3323 //
3324 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfExConsoles; Index++) {
3325 Status = Private->TextInExList[Index]->Reset (
3326 Private->TextInExList[Index],
3327 ExtendedVerification
3328 );
3329 if (EFI_ERROR (Status)) {
3330 ReturnStatus = Status;
3331 }
3332 }
3333
3334 return ReturnStatus;
3335
3336 }
3337
3338 EFI_STATUS
3339 EFIAPI
3340 ConSplitterTextInReadKeyStrokeEx (
3341 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
3342 OUT EFI_KEY_DATA *KeyData
3343 )
3344 /*++
3345
3346 Routine Description:
3347 Reads the next keystroke from the input device. The WaitForKey Event can
3348 be used to test for existance of a keystroke via WaitForEvent () call.
3349
3350 Arguments:
3351 This - Protocol instance pointer.
3352 KeyData - A pointer to a buffer that is filled in with the keystroke
3353 state data for the key that was pressed.
3354
3355 Returns:
3356 EFI_SUCCESS - The keystroke information was returned.
3357 EFI_NOT_READY - There was no keystroke data availiable.
3358 EFI_DEVICE_ERROR - The keystroke information was not returned due to
3359 hardware errors.
3360 EFI_INVALID_PARAMETER - KeyData is NULL.
3361
3362 --*/
3363 {
3364 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3365 EFI_STATUS Status;
3366 UINTN Index;
3367 EFI_KEY_DATA CurrentKeyData;
3368
3369
3370 if (KeyData == NULL) {
3371 return EFI_INVALID_PARAMETER;
3372 }
3373
3374 Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3375 if (Private->PasswordEnabled) {
3376 //
3377 // If StdIn Locked return not ready
3378 //
3379 return EFI_NOT_READY;
3380 }
3381
3382 Private->KeyEventSignalState = FALSE;
3383
3384 KeyData->Key.UnicodeChar = 0;
3385 KeyData->Key.ScanCode = SCAN_NULL;
3386
3387 //
3388 // if no physical console input device exists, return EFI_NOT_READY;
3389 // if any physical console input device has key input,
3390 // return the key and EFI_SUCCESS.
3391 //
3392 for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {
3393 Status = Private->TextInExList[Index]->ReadKeyStrokeEx (
3394 Private->TextInExList[Index],
3395 &CurrentKeyData
3396 );
3397 if (!EFI_ERROR (Status)) {
3398 CopyMem (KeyData, &CurrentKeyData, sizeof (CurrentKeyData));
3399 return Status;
3400 }
3401 }
3402
3403 return EFI_NOT_READY;
3404 }
3405
3406 EFI_STATUS
3407 EFIAPI
3408 ConSplitterTextInSetState (
3409 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
3410 IN EFI_KEY_TOGGLE_STATE *KeyToggleState
3411 )
3412 /*++
3413
3414 Routine Description:
3415 Set certain state for the input device.
3416
3417 Arguments:
3418 This - Protocol instance pointer.
3419 KeyToggleState - A pointer to the EFI_KEY_TOGGLE_STATE to set the
3420 state for the input device.
3421
3422 Returns:
3423 EFI_SUCCESS - The device state was set successfully.
3424 EFI_DEVICE_ERROR - The device is not functioning correctly and could
3425 not have the setting adjusted.
3426 EFI_UNSUPPORTED - The device does not have the ability to set its state.
3427 EFI_INVALID_PARAMETER - KeyToggleState is NULL.
3428
3429 --*/
3430 {
3431 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3432 EFI_STATUS Status;
3433 UINTN Index;
3434
3435 if (KeyToggleState == NULL) {
3436 return EFI_INVALID_PARAMETER;
3437 }
3438
3439 Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3440
3441 //
3442 // if no physical console input device exists, return EFI_SUCCESS;
3443 // otherwise return the status of setting state of physical console input device
3444 //
3445 for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {
3446 Status = Private->TextInExList[Index]->SetState (
3447 Private->TextInExList[Index],
3448 KeyToggleState
3449 );
3450 if (EFI_ERROR (Status)) {
3451 return Status;
3452 }
3453 }
3454
3455 return EFI_SUCCESS;
3456
3457 }
3458
3459 EFI_STATUS
3460 EFIAPI
3461 ConSplitterTextInRegisterKeyNotify (
3462 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
3463 IN EFI_KEY_DATA *KeyData,
3464 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction,
3465 OUT EFI_HANDLE *NotifyHandle
3466 )
3467 /*++
3468
3469 Routine Description:
3470 Register a notification function for a particular keystroke for the input device.
3471
3472 Arguments:
3473 This - Protocol instance pointer.
3474 KeyData - A pointer to a buffer that is filled in with the keystroke
3475 information data for the key that was pressed.
3476 KeyNotificationFunction - Points to the function to be called when the key
3477 sequence is typed specified by KeyData.
3478 NotifyHandle - Points to the unique handle assigned to the registered notification.
3479
3480 Returns:
3481 EFI_SUCCESS - The notification function was registered successfully.
3482 EFI_OUT_OF_RESOURCES - Unable to allocate resources for necesssary data structures.
3483 EFI_INVALID_PARAMETER - KeyData or NotifyHandle is NULL.
3484
3485 --*/
3486 {
3487 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3488 EFI_STATUS Status;
3489 UINTN Index;
3490 TEXT_IN_EX_SPLITTER_NOTIFY *NewNotify;
3491 LIST_ENTRY *Link;
3492 TEXT_IN_EX_SPLITTER_NOTIFY *CurrentNotify;
3493
3494
3495 if (KeyData == NULL || NotifyHandle == NULL || KeyNotificationFunction == NULL) {
3496 return EFI_INVALID_PARAMETER;
3497 }
3498
3499 Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3500
3501 //
3502 // if no physical console input device exists,
3503 // return EFI_SUCCESS directly.
3504 //
3505 if (Private->CurrentNumberOfExConsoles <= 0) {
3506 return EFI_SUCCESS;
3507 }
3508
3509 //
3510 // Return EFI_SUCCESS if the (KeyData, NotificationFunction) is already registered.
3511 //
3512 for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {
3513 CurrentNotify = CR (
3514 Link,
3515 TEXT_IN_EX_SPLITTER_NOTIFY,
3516 NotifyEntry,
3517 TEXT_IN_EX_SPLITTER_NOTIFY_SIGNATURE
3518 );
3519 if (IsKeyRegistered (&CurrentNotify->KeyData, KeyData)) {
3520 if (CurrentNotify->KeyNotificationFn == KeyNotificationFunction) {
3521 *NotifyHandle = CurrentNotify->NotifyHandle;
3522 return EFI_SUCCESS;
3523 }
3524 }
3525 }
3526
3527 //
3528 // Allocate resource to save the notification function
3529 //
3530 NewNotify = (TEXT_IN_EX_SPLITTER_NOTIFY *) AllocateZeroPool (sizeof (TEXT_IN_EX_SPLITTER_NOTIFY));
3531 if (NewNotify == NULL) {
3532 return EFI_OUT_OF_RESOURCES;
3533 }
3534 NewNotify->NotifyHandleList = (EFI_HANDLE *) AllocateZeroPool (sizeof (EFI_HANDLE) * Private->CurrentNumberOfExConsoles);
3535 if (NewNotify->NotifyHandleList == NULL) {
3536 gBS->FreePool (NewNotify);
3537 return EFI_OUT_OF_RESOURCES;
3538 }
3539 NewNotify->Signature = TEXT_IN_EX_SPLITTER_NOTIFY_SIGNATURE;
3540 NewNotify->KeyNotificationFn = KeyNotificationFunction;
3541 CopyMem (&NewNotify->KeyData, KeyData, sizeof (KeyData));
3542
3543 //
3544 // Return the wrong status of registering key notify of
3545 // physical console input device if meet problems
3546 //
3547 for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {
3548 Status = Private->TextInExList[Index]->RegisterKeyNotify (
3549 Private->TextInExList[Index],
3550 KeyData,
3551 KeyNotificationFunction,
3552 &NewNotify->NotifyHandleList[Index]
3553 );
3554 if (EFI_ERROR (Status)) {
3555 gBS->FreePool (NewNotify->NotifyHandleList);
3556 gBS->FreePool (NewNotify);
3557 return Status;
3558 }
3559 }
3560
3561 //
3562 // Use gSimpleTextInExNotifyGuid to get a valid EFI_HANDLE
3563 //
3564 Status = gBS->InstallMultipleProtocolInterfaces (
3565 &NewNotify->NotifyHandle,
3566 &gSimpleTextInExNotifyGuid,
3567 NULL,
3568 NULL
3569 );
3570 ASSERT_EFI_ERROR (Status);
3571
3572 InsertTailList (&mConIn.NotifyList, &NewNotify->NotifyEntry);
3573
3574 *NotifyHandle = NewNotify->NotifyHandle;
3575
3576 return EFI_SUCCESS;
3577
3578 }
3579
3580 EFI_STATUS
3581 EFIAPI
3582 ConSplitterTextInUnregisterKeyNotify (
3583 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
3584 IN EFI_HANDLE NotificationHandle
3585 )
3586 /*++
3587
3588 Routine Description:
3589 Remove a registered notification function from a particular keystroke.
3590
3591 Arguments:
3592 This - Protocol instance pointer.
3593 NotificationHandle - The handle of the notification function being unregistered.
3594
3595 Returns:
3596 EFI_SUCCESS - The notification function was unregistered successfully.
3597 EFI_INVALID_PARAMETER - The NotificationHandle is invalid.
3598 EFI_NOT_FOUND - Can not find the matching entry in database.
3599
3600 --*/
3601 {
3602 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3603 EFI_STATUS Status;
3604 UINTN Index;
3605 TEXT_IN_EX_SPLITTER_NOTIFY *CurrentNotify;
3606 LIST_ENTRY *Link;
3607
3608 if (NotificationHandle == NULL) {
3609 return EFI_INVALID_PARAMETER;
3610 }
3611
3612 Status = gBS->OpenProtocol (
3613 NotificationHandle,
3614 &gSimpleTextInExNotifyGuid,
3615 NULL,
3616 NULL,
3617 NULL,
3618 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
3619 );
3620 if (EFI_ERROR (Status)) {
3621 return EFI_INVALID_PARAMETER;
3622 }
3623
3624 Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3625
3626 //
3627 // if no physical console input device exists,
3628 // return EFI_SUCCESS directly.
3629 //
3630 if (Private->CurrentNumberOfExConsoles <= 0) {
3631 return EFI_SUCCESS;
3632 }
3633
3634 for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {
3635 CurrentNotify = CR (Link, TEXT_IN_EX_SPLITTER_NOTIFY, NotifyEntry, TEXT_IN_EX_SPLITTER_NOTIFY_SIGNATURE);
3636 if (CurrentNotify->NotifyHandle == NotificationHandle) {
3637 for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {
3638 Status = Private->TextInExList[Index]->UnregisterKeyNotify (
3639 Private->TextInExList[Index],
3640 CurrentNotify->NotifyHandleList[Index]
3641 );
3642 if (EFI_ERROR (Status)) {
3643 return Status;
3644 }
3645 }
3646 RemoveEntryList (&CurrentNotify->NotifyEntry);
3647 Status = gBS->UninstallMultipleProtocolInterfaces (
3648 CurrentNotify->NotifyHandle,
3649 &gSimpleTextInExNotifyGuid,
3650 NULL,
3651 NULL
3652 );
3653 ASSERT_EFI_ERROR (Status);
3654 gBS->FreePool (CurrentNotify->NotifyHandleList);
3655 gBS->FreePool (CurrentNotify);
3656 return EFI_SUCCESS;
3657 }
3658 }
3659
3660 return EFI_NOT_FOUND;
3661
3662 }
3663
3664 EFI_STATUS
3665 EFIAPI
3666 ConSplitterSimplePointerReset (
3667 IN EFI_SIMPLE_POINTER_PROTOCOL *This,
3668 IN BOOLEAN ExtendedVerification
3669 )
3670 /*++
3671
3672 Routine Description:
3673 Reset the input device and optionaly run diagnostics
3674
3675 Arguments:
3676 This - Protocol instance pointer.
3677 ExtendedVerification - Driver may perform diagnostics on reset.
3678
3679 Returns:
3680 EFI_SUCCESS - The device was reset.
3681 EFI_DEVICE_ERROR - The device is not functioning properly and could
3682 not be reset.
3683
3684 --*/
3685 {
3686 EFI_STATUS Status;
3687 EFI_STATUS ReturnStatus;
3688 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3689 UINTN Index;
3690
3691 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_SIMPLE_POINTER_THIS (This);
3692
3693 Private->InputEventSignalState = FALSE;
3694
3695 if (Private->CurrentNumberOfPointers == 0) {
3696 return EFI_SUCCESS;
3697 }
3698 //
3699 // return the worst status met
3700 //
3701 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfPointers; Index++) {
3702 Status = Private->PointerList[Index]->Reset (
3703 Private->PointerList[Index],
3704 ExtendedVerification
3705 );
3706 if (EFI_ERROR (Status)) {
3707 ReturnStatus = Status;
3708 }
3709 }
3710
3711 return ReturnStatus;
3712 }
3713
3714 STATIC
3715 EFI_STATUS
3716 EFIAPI
3717 ConSplitterSimplePointerPrivateGetState (
3718 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
3719 IN OUT EFI_SIMPLE_POINTER_STATE *State
3720 )
3721 /*++
3722
3723 Routine Description:
3724 Reads the next keystroke from the input device. The WaitForKey Event can
3725 be used to test for existance of a keystroke via WaitForEvent () call.
3726
3727 Arguments:
3728 This - Protocol instance pointer.
3729 State -
3730
3731 Returns:
3732 EFI_SUCCESS - The keystroke information was returned.
3733 EFI_NOT_READY - There was no keystroke data availiable.
3734 EFI_DEVICE_ERROR - The keydtroke information was not returned due to
3735 hardware errors.
3736
3737 --*/
3738 {
3739 EFI_STATUS Status;
3740 EFI_STATUS ReturnStatus;
3741 UINTN Index;
3742 EFI_SIMPLE_POINTER_STATE CurrentState;
3743
3744 State->RelativeMovementX = 0;
3745 State->RelativeMovementY = 0;
3746 State->RelativeMovementZ = 0;
3747 State->LeftButton = FALSE;
3748 State->RightButton = FALSE;
3749
3750 //
3751 // if no physical console input device exists, return EFI_NOT_READY;
3752 // if any physical console input device has key input,
3753 // return the key and EFI_SUCCESS.
3754 //
3755 ReturnStatus = EFI_NOT_READY;
3756 for (Index = 0; Index < Private->CurrentNumberOfPointers; Index++) {
3757
3758 Status = Private->PointerList[Index]->GetState (
3759 Private->PointerList[Index],
3760 &CurrentState
3761 );
3762 if (!EFI_ERROR (Status)) {
3763 if (ReturnStatus == EFI_NOT_READY) {
3764 ReturnStatus = EFI_SUCCESS;
3765 }
3766
3767 if (CurrentState.LeftButton) {
3768 State->LeftButton = TRUE;
3769 }
3770
3771 if (CurrentState.RightButton) {
3772 State->RightButton = TRUE;
3773 }
3774
3775 if (CurrentState.RelativeMovementX != 0 && Private->PointerList[Index]->Mode->ResolutionX != 0) {
3776 State->RelativeMovementX += (CurrentState.RelativeMovementX * (INT32) Private->SimplePointerMode.ResolutionX) / (INT32) Private->PointerList[Index]->Mode->ResolutionX;
3777 }
3778
3779 if (CurrentState.RelativeMovementY != 0 && Private->PointerList[Index]->Mode->ResolutionY != 0) {
3780 State->RelativeMovementY += (CurrentState.RelativeMovementY * (INT32) Private->SimplePointerMode.ResolutionY) / (INT32) Private->PointerList[Index]->Mode->ResolutionY;
3781 }
3782
3783 if (CurrentState.RelativeMovementZ != 0 && Private->PointerList[Index]->Mode->ResolutionZ != 0) {
3784 State->RelativeMovementZ += (CurrentState.RelativeMovementZ * (INT32) Private->SimplePointerMode.ResolutionZ) / (INT32) Private->PointerList[Index]->Mode->ResolutionZ;
3785 }
3786 } else if (Status == EFI_DEVICE_ERROR) {
3787 ReturnStatus = EFI_DEVICE_ERROR;
3788 }
3789 }
3790
3791 return ReturnStatus;
3792 }
3793
3794 EFI_STATUS
3795 EFIAPI
3796 ConSplitterSimplePointerGetState (
3797 IN EFI_SIMPLE_POINTER_PROTOCOL *This,
3798 IN OUT EFI_SIMPLE_POINTER_STATE *State
3799 )
3800 /*++
3801
3802 Routine Description:
3803 Reads the next keystroke from the input device. The WaitForKey Event can
3804 be used to test for existance of a keystroke via WaitForEvent () call.
3805 If the ConIn is password locked make it look like no keystroke is availible
3806
3807 Arguments:
3808 This - Protocol instance pointer.
3809 State -
3810
3811 Returns:
3812 EFI_SUCCESS - The keystroke information was returned.
3813 EFI_NOT_READY - There was no keystroke data availiable.
3814 EFI_DEVICE_ERROR - The keydtroke information was not returned due to
3815 hardware errors.
3816
3817 --*/
3818 {
3819 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3820
3821 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_SIMPLE_POINTER_THIS (This);
3822 if (Private->PasswordEnabled) {
3823 //
3824 // If StdIn Locked return not ready
3825 //
3826 return EFI_NOT_READY;
3827 }
3828
3829 Private->InputEventSignalState = FALSE;
3830
3831 return ConSplitterSimplePointerPrivateGetState (Private, State);
3832 }
3833
3834 VOID
3835 EFIAPI
3836 ConSplitterSimplePointerWaitForInput (
3837 IN EFI_EVENT Event,
3838 IN VOID *Context
3839 )
3840 /*++
3841
3842 Routine Description:
3843 This event agregates all the events of the ConIn devices in the spliter.
3844 If the ConIn is password locked then return.
3845 If any events of physical ConIn devices are signaled, signal the ConIn
3846 spliter event. This will cause the calling code to call
3847 ConSplitterTextInReadKeyStroke ().
3848
3849 Arguments:
3850 Event - The Event assoicated with callback.
3851 Context - Context registered when Event was created.
3852
3853 Returns:
3854 None
3855
3856 --*/
3857 {
3858 EFI_STATUS Status;
3859 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3860 UINTN Index;
3861
3862 Private = (TEXT_IN_SPLITTER_PRIVATE_DATA *) Context;
3863 if (Private->PasswordEnabled) {
3864 //
3865 // If StdIn Locked return not ready
3866 //
3867 return ;
3868 }
3869
3870 //
3871 // if InputEventSignalState is flagged before, and not cleared by Reset() or ReadKeyStroke()
3872 //
3873 if (Private->InputEventSignalState) {
3874 gBS->SignalEvent (Event);
3875 return ;
3876 }
3877 //
3878 // if any physical console input device has key input, signal the event.
3879 //
3880 for (Index = 0; Index < Private->CurrentNumberOfPointers; Index++) {
3881 Status = gBS->CheckEvent (Private->PointerList[Index]->WaitForInput);
3882 if (!EFI_ERROR (Status)) {
3883 gBS->SignalEvent (Event);
3884 Private->InputEventSignalState = TRUE;
3885 }
3886 }
3887 }
3888
3889 //
3890 // Absolute Pointer Protocol functions
3891 //
3892
3893 EFI_STATUS
3894 EFIAPI
3895 ConSplitterAbsolutePointerReset (
3896 IN EFI_ABSOLUTE_POINTER_PROTOCOL *This,
3897 IN BOOLEAN ExtendedVerification
3898 )
3899 /*++
3900
3901 Routine Description:
3902 Resets the pointer device hardware.
3903
3904 Arguments:
3905 This - Protocol instance pointer.
3906 ExtendedVerification - Driver may perform diagnostics on reset.
3907
3908 Returns:
3909 EFI_SUCCESS - The device was reset.
3910 EFI_DEVICE_ERROR - The device is not functioning correctly and could
3911 not be reset.
3912
3913 --*/
3914 {
3915 EFI_STATUS Status;
3916 EFI_STATUS ReturnStatus;
3917 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3918 UINTN Index;
3919
3920 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_ABSOLUTE_POINTER_THIS (This);
3921
3922 Private->AbsoluteInputEventSignalState = FALSE;
3923
3924 if (Private->CurrentNumberOfAbsolutePointers == 0) {
3925 return EFI_SUCCESS;
3926 }
3927 //
3928 // return the worst status met
3929 //
3930 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfAbsolutePointers; Index++) {
3931 Status = Private->AbsolutePointerList[Index]->Reset (
3932 Private->AbsolutePointerList[Index],
3933 ExtendedVerification
3934 );
3935 if (EFI_ERROR (Status)) {
3936 ReturnStatus = Status;
3937 }
3938 }
3939
3940 return ReturnStatus;
3941 }
3942
3943 EFI_STATUS
3944 EFIAPI
3945 ConSplitterAbsolutePointerGetState (
3946 IN EFI_ABSOLUTE_POINTER_PROTOCOL *This,
3947 IN OUT EFI_ABSOLUTE_POINTER_STATE *State
3948 )
3949 /*++
3950
3951 Routine Description:
3952 Retrieves the current state of a pointer device.
3953
3954 Arguments:
3955 This - Protocol instance pointer.
3956 State - A pointer to the state information on the pointer device.
3957
3958 Returns:
3959 EFI_SUCCESS - The state of the pointer device was returned in State..
3960 EFI_NOT_READY - The state of the pointer device has not changed since the last call to
3961 GetState().
3962 EFI_DEVICE_ERROR - A device error occurred while attempting to retrieve the pointer
3963 device's current state.
3964 --*/
3965 {
3966 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3967 EFI_STATUS Status;
3968 EFI_STATUS ReturnStatus;
3969 UINTN Index;
3970 EFI_ABSOLUTE_POINTER_STATE CurrentState;
3971
3972
3973 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_ABSOLUTE_POINTER_THIS (This);
3974 if (Private->PasswordEnabled) {
3975 //
3976 // If StdIn Locked return not ready
3977 //
3978 return EFI_NOT_READY;
3979 }
3980
3981 Private->AbsoluteInputEventSignalState = FALSE;
3982
3983 State->CurrentX = 0;
3984 State->CurrentY = 0;
3985 State->CurrentZ = 0;
3986 State->ActiveButtons = 0;
3987
3988 //
3989 // if no physical pointer device exists, return EFI_NOT_READY;
3990 // if any physical pointer device has changed state,
3991 // return the state and EFI_SUCCESS.
3992 //
3993 ReturnStatus = EFI_NOT_READY;
3994 for (Index = 0; Index < Private->CurrentNumberOfAbsolutePointers; Index++) {
3995
3996 Status = Private->AbsolutePointerList[Index]->GetState (
3997 Private->AbsolutePointerList[Index],
3998 &CurrentState
3999 );
4000 if (!EFI_ERROR (Status)) {
4001 if (ReturnStatus == EFI_NOT_READY) {
4002 ReturnStatus = EFI_SUCCESS;
4003 }
4004
4005 State->ActiveButtons = CurrentState.ActiveButtons;
4006
4007 if (!(Private->AbsolutePointerMode.AbsoluteMinX == 0 && Private->AbsolutePointerMode.AbsoluteMaxX == 0)) {
4008 State->CurrentX = CurrentState.CurrentX;
4009 }
4010 if (!(Private->AbsolutePointerMode.AbsoluteMinY == 0 && Private->AbsolutePointerMode.AbsoluteMaxY == 0)) {
4011 State->CurrentY = CurrentState.CurrentY;
4012 }
4013 if (!(Private->AbsolutePointerMode.AbsoluteMinZ == 0 && Private->AbsolutePointerMode.AbsoluteMaxZ == 0)) {
4014 State->CurrentZ = CurrentState.CurrentZ;
4015 }
4016
4017 } else if (Status == EFI_DEVICE_ERROR) {
4018 ReturnStatus = EFI_DEVICE_ERROR;
4019 }
4020 }
4021
4022 return ReturnStatus;
4023 }
4024
4025 VOID
4026 EFIAPI
4027 ConSplitterAbsolutePointerWaitForInput (
4028 IN EFI_EVENT Event,
4029 IN VOID *Context
4030 )
4031 /*++
4032
4033 Routine Description:
4034 This event agregates all the events of the pointer devices in the splitter.
4035 If the ConIn is password locked then return.
4036 If any events of physical pointer devices are signaled, signal the pointer
4037 splitter event. This will cause the calling code to call
4038 ConSplitterAbsolutePointerGetState ().
4039
4040 Arguments:
4041 Event - The Event assoicated with callback.
4042 Context - Context registered when Event was created.
4043
4044 Returns:
4045 None
4046
4047 --*/
4048 {
4049 EFI_STATUS Status;
4050 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
4051 UINTN Index;
4052
4053 Private = (TEXT_IN_SPLITTER_PRIVATE_DATA *) Context;
4054 if (Private->PasswordEnabled) {
4055 //
4056 // If StdIn Locked return not ready
4057 //
4058 return ;
4059 }
4060
4061 //
4062 // if AbsoluteInputEventSignalState is flagged before,
4063 // and not cleared by Reset() or GetState(), signal it
4064 //
4065 if (Private->AbsoluteInputEventSignalState) {
4066 gBS->SignalEvent (Event);
4067 return ;
4068 }
4069 //
4070 // if any physical console input device has key input, signal the event.
4071 //
4072 for (Index = 0; Index < Private->CurrentNumberOfAbsolutePointers; Index++) {
4073 Status = gBS->CheckEvent (Private->AbsolutePointerList[Index]->WaitForInput);
4074 if (!EFI_ERROR (Status)) {
4075 gBS->SignalEvent (Event);
4076 Private->AbsoluteInputEventSignalState = TRUE;
4077 }
4078 }
4079 }
4080
4081 EFI_STATUS
4082 EFIAPI
4083 ConSplitterTextOutReset (
4084 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4085 IN BOOLEAN ExtendedVerification
4086 )
4087 /*++
4088
4089 Routine Description:
4090 Reset the text output device hardware and optionaly run diagnostics
4091
4092 Arguments:
4093 This - Protocol instance pointer.
4094 ExtendedVerification - Driver may perform more exhaustive verfication
4095 operation of the device during reset.
4096
4097 Returns:
4098 EFI_SUCCESS - The text output device was reset.
4099 EFI_DEVICE_ERROR - The text output device is not functioning correctly and
4100 could not be reset.
4101
4102 --*/
4103 {
4104 EFI_STATUS Status;
4105 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4106 UINTN Index;
4107 EFI_STATUS ReturnStatus;
4108
4109 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4110
4111 //
4112 // return the worst status met
4113 //
4114 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4115
4116 if (Private->TextOutList[Index].TextOutEnabled) {
4117
4118 Status = Private->TextOutList[Index].TextOut->Reset (
4119 Private->TextOutList[Index].TextOut,
4120 ExtendedVerification
4121 );
4122 if (EFI_ERROR (Status)) {
4123 ReturnStatus = Status;
4124 }
4125 }
4126 }
4127
4128 This->SetAttribute (This, EFI_TEXT_ATTR (This->Mode->Attribute & 0x0F, EFI_BACKGROUND_BLACK));
4129
4130 Status = DevNullTextOutSetMode (Private, 0);
4131 if (EFI_ERROR (Status)) {
4132 ReturnStatus = Status;
4133 }
4134
4135 return ReturnStatus;
4136 }
4137
4138 EFI_STATUS
4139 EFIAPI
4140 ConSplitterTextOutOutputString (
4141 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4142 IN CHAR16 *WString
4143 )
4144 /*++
4145
4146 Routine Description:
4147 Write a Unicode string to the output device.
4148
4149 Arguments:
4150 This - Protocol instance pointer.
4151 String - The NULL-terminated Unicode string to be displayed on the output
4152 device(s). All output devices must also support the Unicode
4153 drawing defined in this file.
4154
4155 Returns:
4156 EFI_SUCCESS - The string was output to the device.
4157 EFI_DEVICE_ERROR - The device reported an error while attempting to output
4158 the text.
4159 EFI_UNSUPPORTED - The output device's mode is not currently in a
4160 defined text mode.
4161 EFI_WARN_UNKNOWN_GLYPH - This warning code indicates that some of the
4162 characters in the Unicode string could not be
4163 rendered and were skipped.
4164
4165 --*/
4166 {
4167 EFI_STATUS Status;
4168 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4169 UINTN Index;
4170 UINTN BackSpaceCount;
4171 EFI_STATUS ReturnStatus;
4172 CHAR16 *TargetString;
4173
4174 This->SetAttribute (This, This->Mode->Attribute);
4175
4176 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4177
4178 BackSpaceCount = 0;
4179 for (TargetString = WString; *TargetString; TargetString++) {
4180 if (*TargetString == CHAR_BACKSPACE) {
4181 BackSpaceCount++;
4182 }
4183
4184 }
4185
4186 if (BackSpaceCount == 0) {
4187 TargetString = WString;
4188 } else {
4189 TargetString = AllocatePool (sizeof (CHAR16) * (StrLen (WString) + BackSpaceCount + 1));
4190 StrCpy (TargetString, WString);
4191 }
4192 //
4193 // return the worst status met
4194 //
4195 Status = DevNullTextOutOutputString (Private, TargetString);
4196 if (EFI_ERROR (Status)) {
4197 ReturnStatus = Status;
4198 }
4199
4200 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4201
4202 if (Private->TextOutList[Index].TextOutEnabled) {
4203 Status = Private->TextOutList[Index].TextOut->OutputString (
4204 Private->TextOutList[Index].TextOut,
4205 TargetString
4206 );
4207 if (EFI_ERROR (Status)) {
4208 ReturnStatus = Status;
4209 }
4210 }
4211 }
4212
4213 if (BackSpaceCount) {
4214 FreePool (TargetString);
4215 }
4216
4217 return ReturnStatus;
4218 }
4219
4220 EFI_STATUS
4221 EFIAPI
4222 ConSplitterTextOutTestString (
4223 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4224 IN CHAR16 *WString
4225 )
4226 /*++
4227
4228 Routine Description:
4229 Verifies that all characters in a Unicode string can be output to the
4230 target device.
4231
4232 Arguments:
4233 This - Protocol instance pointer.
4234 String - The NULL-terminated Unicode string to be examined for the output
4235 device(s).
4236
4237 Returns:
4238 EFI_SUCCESS - The device(s) are capable of rendering the output string.
4239 EFI_UNSUPPORTED - Some of the characters in the Unicode string cannot be
4240 rendered by one or more of the output devices mapped
4241 by the EFI handle.
4242
4243 --*/
4244 {
4245 EFI_STATUS Status;
4246 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4247 UINTN Index;
4248 EFI_STATUS ReturnStatus;
4249
4250 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4251
4252 //
4253 // return the worst status met
4254 //
4255 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4256 if (Private->TextOutList[Index].TextOutEnabled) {
4257 Status = Private->TextOutList[Index].TextOut->TestString (
4258 Private->TextOutList[Index].TextOut,
4259 WString
4260 );
4261 if (EFI_ERROR (Status)) {
4262 ReturnStatus = Status;
4263 }
4264 }
4265 }
4266 //
4267 // There is no DevNullTextOutTestString () since a Unicode buffer would
4268 // always return EFI_SUCCESS.
4269 // ReturnStatus will be EFI_SUCCESS if no consoles are present
4270 //
4271 return ReturnStatus;
4272 }
4273
4274 EFI_STATUS
4275 EFIAPI
4276 ConSplitterTextOutQueryMode (
4277 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4278 IN UINTN ModeNumber,
4279 OUT UINTN *Columns,
4280 OUT UINTN *Rows
4281 )
4282 /*++
4283
4284 Routine Description:
4285 Returns information for an available text mode that the output device(s)
4286 supports.
4287
4288 Arguments:
4289 This - Protocol instance pointer.
4290 ModeNumber - The mode number to return information on.
4291 Columns, Rows - Returns the geometry of the text output device for the
4292 requested ModeNumber.
4293
4294 Returns:
4295 EFI_SUCCESS - The requested mode information was returned.
4296 EFI_DEVICE_ERROR - The device had an error and could not
4297 complete the request.
4298 EFI_UNSUPPORTED - The mode number was not valid.
4299
4300 --*/
4301 {
4302 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4303
4304 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4305
4306 //
4307 // Check whether param ModeNumber is valid.
4308 // ModeNumber should be within range 0 ~ MaxMode - 1.
4309 //
4310 if ( (ModeNumber > (UINTN)(((UINT32)-1)>>1)) ) {
4311 return EFI_UNSUPPORTED;
4312 }
4313
4314 if ((INT32) ModeNumber >= This->Mode->MaxMode) {
4315 return EFI_UNSUPPORTED;
4316 }
4317
4318 *Columns = Private->TextOutQueryData[ModeNumber].Columns;
4319 *Rows = Private->TextOutQueryData[ModeNumber].Rows;
4320
4321 if (*Columns <= 0 && *Rows <= 0) {
4322 return EFI_UNSUPPORTED;
4323
4324 }
4325
4326 return EFI_SUCCESS;
4327 }
4328
4329 EFI_STATUS
4330 EFIAPI
4331 ConSplitterTextOutSetMode (
4332 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4333 IN UINTN ModeNumber
4334 )
4335 /*++
4336
4337 Routine Description:
4338 Sets the output device(s) to a specified mode.
4339
4340 Arguments:
4341 This - Protocol instance pointer.
4342 ModeNumber - The mode number to set.
4343
4344 Returns:
4345 EFI_SUCCESS - The requested text mode was set.
4346 EFI_DEVICE_ERROR - The device had an error and
4347 could not complete the request.
4348 EFI_UNSUPPORTED - The mode number was not valid.
4349
4350 --*/
4351 {
4352 EFI_STATUS Status;
4353 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4354 UINTN Index;
4355 INT32 *TextOutModeMap;
4356 EFI_STATUS ReturnStatus;
4357
4358 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4359
4360 //
4361 // Check whether param ModeNumber is valid.
4362 // ModeNumber should be within range 0 ~ MaxMode - 1.
4363 //
4364 if ( (ModeNumber > (UINTN)(((UINT32)-1)>>1)) ) {
4365 return EFI_UNSUPPORTED;
4366 }
4367
4368 if ((INT32) ModeNumber >= This->Mode->MaxMode) {
4369 return EFI_UNSUPPORTED;
4370 }
4371 //
4372 // If the mode is being set to the curent mode, then just clear the screen and return.
4373 //
4374 if (Private->TextOutMode.Mode == (INT32) ModeNumber) {
4375 return ConSplitterTextOutClearScreen (This);
4376 }
4377 //
4378 // return the worst status met
4379 //
4380 TextOutModeMap = Private->TextOutModeMap + Private->TextOutListCount * ModeNumber;
4381 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4382
4383 if (Private->TextOutList[Index].TextOutEnabled) {
4384 Status = Private->TextOutList[Index].TextOut->SetMode (
4385 Private->TextOutList[Index].TextOut,
4386 TextOutModeMap[Index]
4387 );
4388 //
4389 // If this console device is based on a UGA device, then sync up the bitmap from
4390 // the UGA splitter and reclear the text portion of the display in the new mode.
4391 //
4392 if ((Private->TextOutList[Index].GraphicsOutput != NULL) || (Private->TextOutList[Index].UgaDraw != NULL)) {
4393 Private->TextOutList[Index].TextOut->ClearScreen (Private->TextOutList[Index].TextOut);
4394 }
4395
4396 if (EFI_ERROR (Status)) {
4397 ReturnStatus = Status;
4398 }
4399 }
4400 }
4401 //
4402 // The DevNull Console will support any possible mode as it allocates memory
4403 //
4404 Status = DevNullTextOutSetMode (Private, ModeNumber);
4405 if (EFI_ERROR (Status)) {
4406 ReturnStatus = Status;
4407 }
4408
4409 return ReturnStatus;
4410 }
4411
4412 EFI_STATUS
4413 EFIAPI
4414 ConSplitterTextOutSetAttribute (
4415 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4416 IN UINTN Attribute
4417 )
4418 /*++
4419
4420 Routine Description:
4421 Sets the background and foreground colors for the OutputString () and
4422 ClearScreen () functions.
4423
4424 Arguments:
4425 This - Protocol instance pointer.
4426 Attribute - The attribute to set. Bits 0..3 are the foreground color, and
4427 bits 4..6 are the background color. All other bits are undefined
4428 and must be zero. The valid Attributes are defined in this file.
4429
4430 Returns:
4431 EFI_SUCCESS - The attribute was set.
4432 EFI_DEVICE_ERROR - The device had an error and
4433 could not complete the request.
4434 EFI_UNSUPPORTED - The attribute requested is not defined.
4435
4436 --*/
4437 {
4438 EFI_STATUS Status;
4439 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4440 UINTN Index;
4441 EFI_STATUS ReturnStatus;
4442
4443 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4444
4445 //
4446 // Check whether param Attribute is valid.
4447 //
4448 if ( (Attribute > (UINTN)(((UINT32)-1)>>1)) ) {
4449 return EFI_UNSUPPORTED;
4450 }
4451
4452 //
4453 // return the worst status met
4454 //
4455 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4456
4457 if (Private->TextOutList[Index].TextOutEnabled) {
4458 Status = Private->TextOutList[Index].TextOut->SetAttribute (
4459 Private->TextOutList[Index].TextOut,
4460 Attribute
4461 );
4462 if (EFI_ERROR (Status)) {
4463 ReturnStatus = Status;
4464 }
4465 }
4466 }
4467
4468 Private->TextOutMode.Attribute = (INT32) Attribute;
4469
4470 return ReturnStatus;
4471 }
4472
4473 EFI_STATUS
4474 EFIAPI
4475 ConSplitterTextOutClearScreen (
4476 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This
4477 )
4478 /*++
4479
4480 Routine Description:
4481 Clears the output device(s) display to the currently selected background
4482 color.
4483
4484 Arguments:
4485 This - Protocol instance pointer.
4486
4487 Returns:
4488 EFI_SUCCESS - The operation completed successfully.
4489 EFI_DEVICE_ERROR - The device had an error and
4490 could not complete the request.
4491 EFI_UNSUPPORTED - The output device is not in a valid text mode.
4492
4493 --*/
4494 {
4495 EFI_STATUS Status;
4496 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4497 UINTN Index;
4498 EFI_STATUS ReturnStatus;
4499
4500 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4501
4502 //
4503 // return the worst status met
4504 //
4505 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4506
4507 if (Private->TextOutList[Index].TextOutEnabled) {
4508 Status = Private->TextOutList[Index].TextOut->ClearScreen (Private->TextOutList[Index].TextOut);
4509 if (EFI_ERROR (Status)) {
4510 ReturnStatus = Status;
4511 }
4512 }
4513 }
4514
4515 Status = DevNullTextOutClearScreen (Private);
4516 if (EFI_ERROR (Status)) {
4517 ReturnStatus = Status;
4518 }
4519
4520 return ReturnStatus;
4521 }
4522
4523 EFI_STATUS
4524 EFIAPI
4525 ConSplitterTextOutSetCursorPosition (
4526 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4527 IN UINTN Column,
4528 IN UINTN Row
4529 )
4530 /*++
4531
4532 Routine Description:
4533 Sets the current coordinates of the cursor position
4534
4535 Arguments:
4536 This - Protocol instance pointer.
4537 Column, Row - the position to set the cursor to. Must be greater than or
4538 equal to zero and less than the number of columns and rows
4539 by QueryMode ().
4540
4541 Returns:
4542 EFI_SUCCESS - The operation completed successfully.
4543 EFI_DEVICE_ERROR - The device had an error and
4544 could not complete the request.
4545 EFI_UNSUPPORTED - The output device is not in a valid text mode, or the
4546 cursor position is invalid for the current mode.
4547
4548 --*/
4549 {
4550 EFI_STATUS Status;
4551 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4552 UINTN Index;
4553 EFI_STATUS ReturnStatus;
4554 UINTN MaxColumn;
4555 UINTN MaxRow;
4556 INT32 *TextOutModeMap;
4557 INT32 ModeNumber;
4558 INT32 CurrentMode;
4559
4560 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4561 TextOutModeMap = NULL;
4562 ModeNumber = Private->TextOutMode.Mode;
4563
4564 //
4565 // Get current MaxColumn and MaxRow from intersection map
4566 //
4567 if (Private->TextOutModeMap != NULL) {
4568 TextOutModeMap = Private->TextOutModeMap + Private->TextOutListCount * ModeNumber;
4569 CurrentMode = *TextOutModeMap;
4570 } else {
4571 CurrentMode = ModeNumber;
4572 }
4573
4574 MaxColumn = Private->TextOutQueryData[CurrentMode].Columns;
4575 MaxRow = Private->TextOutQueryData[CurrentMode].Rows;
4576
4577 if (Column >= MaxColumn || Row >= MaxRow) {
4578 return EFI_UNSUPPORTED;
4579 }
4580 //
4581 // return the worst status met
4582 //
4583 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4584
4585 if (Private->TextOutList[Index].TextOutEnabled) {
4586 Status = Private->TextOutList[Index].TextOut->SetCursorPosition (
4587 Private->TextOutList[Index].TextOut,
4588 Column,
4589 Row
4590 );
4591 if (EFI_ERROR (Status)) {
4592 ReturnStatus = Status;
4593 }
4594 }
4595 }
4596
4597 DevNullTextOutSetCursorPosition (Private, Column, Row);
4598
4599 return ReturnStatus;
4600 }
4601
4602 EFI_STATUS
4603 EFIAPI
4604 ConSplitterTextOutEnableCursor (
4605 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4606 IN BOOLEAN Visible
4607 )
4608 /*++
4609
4610 Routine Description:
4611 Makes the cursor visible or invisible
4612
4613 Arguments:
4614 This - Protocol instance pointer.
4615 Visible - If TRUE, the cursor is set to be visible. If FALSE, the cursor is
4616 set to be invisible.
4617
4618 Returns:
4619 EFI_SUCCESS - The operation completed successfully.
4620 EFI_DEVICE_ERROR - The device had an error and could not complete the
4621 request, or the device does not support changing
4622 the cursor mode.
4623 EFI_UNSUPPORTED - The output device is not in a valid text mode.
4624
4625 --*/
4626 {
4627 EFI_STATUS Status;
4628 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4629 UINTN Index;
4630 EFI_STATUS ReturnStatus;
4631
4632 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4633
4634 //
4635 // return the worst status met
4636 //
4637 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4638
4639 if (Private->TextOutList[Index].TextOutEnabled) {
4640 Status = Private->TextOutList[Index].TextOut->EnableCursor (
4641 Private->TextOutList[Index].TextOut,
4642 Visible
4643 );
4644 if (EFI_ERROR (Status)) {
4645 ReturnStatus = Status;
4646 }
4647 }
4648 }
4649
4650 DevNullTextOutEnableCursor (Private, Visible);
4651
4652 return ReturnStatus;
4653 }