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