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