]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.c
refine comments for EFI_CONSOLE_CONTROL_PROTOCOL
[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 // One of Either Graphics Output protocol and 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
1277 //
1278 // Start ConSplitter on ControllerHandle, and create the virtual
1279 // agrogated console device on first call Start for a ConsoleOut handle.
1280 //
1281 Status = ConSplitterStart (
1282 This,
1283 ControllerHandle,
1284 mConOut.VirtualHandle,
1285 &gEfiConsoleOutDeviceGuid,
1286 &gEfiSimpleTextOutProtocolGuid,
1287 (VOID **) &TextOut
1288 );
1289 if (EFI_ERROR (Status)) {
1290 return Status;
1291 }
1292
1293 GraphicsOutput = NULL;
1294 UgaDraw = NULL;
1295 //
1296 // Try to Open Graphics Output protocol
1297 //
1298 Status = gBS->OpenProtocol (
1299 ControllerHandle,
1300 &gEfiGraphicsOutputProtocolGuid,
1301 (VOID **) &GraphicsOutput,
1302 This->DriverBindingHandle,
1303 mConOut.VirtualHandle,
1304 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1305 );
1306
1307 if (EFI_ERROR (Status) && FeaturePcdGet (PcdUgaConsumeSupport)) {
1308 //
1309 // Open UGA DRAW protocol
1310 //
1311 Status = gBS->OpenProtocol (
1312 ControllerHandle,
1313 &gEfiUgaDrawProtocolGuid,
1314 (VOID **) &UgaDraw,
1315 This->DriverBindingHandle,
1316 mConOut.VirtualHandle,
1317 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1318 );
1319 }
1320
1321 //
1322 // When new console device is added, the new mode will be set later,
1323 // so put current mode back to init state.
1324 //
1325 mConOut.TextOutMode.Mode = 0xFF;
1326
1327 //
1328 // If both ConOut and StdErr incorporate the same Text Out device,
1329 // their MaxMode and QueryData should be the intersection of both.
1330 //
1331 Status = ConSplitterTextOutAddDevice (&mConOut, TextOut, GraphicsOutput, UgaDraw);
1332 ConSplitterTextOutSetAttribute (&mConOut.TextOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
1333
1334 if (FeaturePcdGet (PcdConOutUgaSupport) && FeaturePcdGet (PcdUgaConsumeSupport)) {
1335 //
1336 // Match the UGA mode data of ConOut with the current mode
1337 //
1338 if (UgaDraw != NULL) {
1339 UgaDraw->GetMode (
1340 UgaDraw,
1341 &mConOut.UgaHorizontalResolution,
1342 &mConOut.UgaVerticalResolution,
1343 &mConOut.UgaColorDepth,
1344 &mConOut.UgaRefreshRate
1345 );
1346 }
1347 }
1348 return Status;
1349 }
1350
1351
1352 /**
1353 Start Standard Error Consplitter on device handle.
1354
1355 @param This Driver Binding protocol instance pointer.
1356 @param ControllerHandle Handle of device to bind driver to.
1357 @param RemainingDevicePath Optional parameter use to pick a specific child
1358 device to start.
1359
1360 @retval EFI_SUCCESS Standard Error Consplitter is added to ControllerHandle.
1361 @retval other Standard Error Consplitter does not support this device.
1362
1363 **/
1364 EFI_STATUS
1365 EFIAPI
1366 ConSplitterStdErrDriverBindingStart (
1367 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1368 IN EFI_HANDLE ControllerHandle,
1369 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
1370 )
1371 {
1372 EFI_STATUS Status;
1373 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut;
1374
1375 //
1376 // Start ConSplitter on ControllerHandle, and create the virtual
1377 // agrogated console device on first call Start for a StandardError handle.
1378 //
1379 Status = ConSplitterStart (
1380 This,
1381 ControllerHandle,
1382 mStdErr.VirtualHandle,
1383 &gEfiStandardErrorDeviceGuid,
1384 &gEfiSimpleTextOutProtocolGuid,
1385 (VOID **) &TextOut
1386 );
1387 if (EFI_ERROR (Status)) {
1388 return Status;
1389 }
1390
1391 //
1392 // When new console device is added, the new mode will be set later,
1393 // so put current mode back to init state.
1394 //
1395 mStdErr.TextOutMode.Mode = 0xFF;
1396
1397 //
1398 // If both ConOut and StdErr incorporate the same Text Out device,
1399 // their MaxMode and QueryData should be the intersection of both.
1400 //
1401 Status = ConSplitterTextOutAddDevice (&mStdErr, TextOut, NULL, NULL);
1402 ConSplitterTextOutSetAttribute (&mStdErr.TextOut, EFI_TEXT_ATTR (EFI_MAGENTA, EFI_BLACK));
1403 if (EFI_ERROR (Status)) {
1404 return Status;
1405 }
1406
1407 if (mStdErr.CurrentNumberOfConsoles == 1) {
1408 gST->StandardErrorHandle = mStdErr.VirtualHandle;
1409 gST->StdErr = &mStdErr.TextOut;
1410 //
1411 // Update the CRC32 in the EFI System Table header
1412 //
1413 gST->Hdr.CRC32 = 0;
1414 gBS->CalculateCrc32 (
1415 (UINT8 *) &gST->Hdr,
1416 gST->Hdr.HeaderSize,
1417 &gST->Hdr.CRC32
1418 );
1419 }
1420
1421 return Status;
1422 }
1423
1424
1425 /**
1426 Stop ConSplitter on device handle by closing Console Device Guid on device handle
1427 and the console virtual handle.
1428
1429 @param This Protocol instance pointer.
1430 @param ControllerHandle Handle of device.
1431 @param ConSplitterVirtualHandle Console virtual Handle.
1432 @param DeviceGuid The specified Console Device, such as ConInDev,
1433 ConOutDev.
1434 @param InterfaceGuid The specified protocol to be opened.
1435 @param Interface Protocol interface returned.
1436
1437 @retval EFI_SUCCESS Stop ConSplitter on ControllerHandle successfully.
1438 @retval other Failed to Stop ConSplitter on ControllerHandle.
1439
1440 **/
1441 EFI_STATUS
1442 ConSplitterStop (
1443 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1444 IN EFI_HANDLE ControllerHandle,
1445 IN EFI_HANDLE ConSplitterVirtualHandle,
1446 IN EFI_GUID *DeviceGuid,
1447 IN EFI_GUID *InterfaceGuid,
1448 IN VOID **Interface
1449 )
1450 {
1451 EFI_STATUS Status;
1452
1453 Status = gBS->OpenProtocol (
1454 ControllerHandle,
1455 InterfaceGuid,
1456 Interface,
1457 This->DriverBindingHandle,
1458 ControllerHandle,
1459 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1460 );
1461 if (EFI_ERROR (Status)) {
1462 return Status;
1463 }
1464 //
1465 // close the protocol refered.
1466 //
1467 gBS->CloseProtocol (
1468 ControllerHandle,
1469 DeviceGuid,
1470 This->DriverBindingHandle,
1471 ConSplitterVirtualHandle
1472 );
1473
1474 gBS->CloseProtocol (
1475 ControllerHandle,
1476 DeviceGuid,
1477 This->DriverBindingHandle,
1478 ControllerHandle
1479 );
1480
1481 return EFI_SUCCESS;
1482 }
1483
1484
1485 /**
1486 Stop Console In ConSplitter on ControllerHandle by closing Console In Devcice GUID.
1487
1488 @param This Driver Binding protocol instance pointer.
1489 @param ControllerHandle Handle of device to stop driver on
1490 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
1491 children is zero stop the entire bus driver.
1492 @param ChildHandleBuffer List of Child Handles to Stop.
1493
1494 @retval EFI_SUCCESS This driver is removed ControllerHandle
1495 @retval other This driver was not removed from this device
1496
1497 **/
1498 EFI_STATUS
1499 EFIAPI
1500 ConSplitterConInDriverBindingStop (
1501 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1502 IN EFI_HANDLE ControllerHandle,
1503 IN UINTN NumberOfChildren,
1504 IN EFI_HANDLE *ChildHandleBuffer
1505 )
1506 {
1507 EFI_STATUS Status;
1508 EFI_SIMPLE_TEXT_INPUT_PROTOCOL *TextIn;
1509 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TextInEx;
1510
1511 if (NumberOfChildren == 0) {
1512 return EFI_SUCCESS;
1513 }
1514
1515 Status = gBS->OpenProtocol (
1516 ControllerHandle,
1517 &gEfiSimpleTextInputExProtocolGuid,
1518 (VOID **) &TextInEx,
1519 This->DriverBindingHandle,
1520 ControllerHandle,
1521 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1522 );
1523 if (!EFI_ERROR (Status)) {
1524 //
1525 // If Simple Text Input Ex protocol exists,
1526 // remove device from Text Input Ex devices list.
1527 //
1528 Status = ConSplitterTextInExDeleteDevice (&mConIn, TextInEx);
1529 if (EFI_ERROR (Status)) {
1530 return Status;
1531 }
1532 }
1533
1534 //
1535 // Close Simple Text In protocol on controller handle and virtual handle.
1536 //
1537 Status = ConSplitterStop (
1538 This,
1539 ControllerHandle,
1540 mConIn.VirtualHandle,
1541 &gEfiConsoleInDeviceGuid,
1542 &gEfiSimpleTextInProtocolGuid,
1543 (VOID **) &TextIn
1544 );
1545 if (EFI_ERROR (Status)) {
1546 return Status;
1547 }
1548
1549 //
1550 // Remove device from Text Input devices list.
1551 //
1552 return ConSplitterTextInDeleteDevice (&mConIn, TextIn);
1553 }
1554
1555
1556 /**
1557 Stop Simple Pointer protocol ConSplitter on ControllerHandle by closing
1558 Simple Pointer protocol.
1559
1560 @param This Driver Binding protocol instance pointer.
1561 @param ControllerHandle Handle of device to stop driver on
1562 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
1563 children is zero stop the entire bus driver.
1564 @param ChildHandleBuffer List of Child Handles to Stop.
1565
1566 @retval EFI_SUCCESS This driver is removed ControllerHandle
1567 @retval other This driver was not removed from this device
1568
1569 **/
1570 EFI_STATUS
1571 EFIAPI
1572 ConSplitterSimplePointerDriverBindingStop (
1573 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1574 IN EFI_HANDLE ControllerHandle,
1575 IN UINTN NumberOfChildren,
1576 IN EFI_HANDLE *ChildHandleBuffer
1577 )
1578 {
1579 EFI_STATUS Status;
1580 EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer;
1581
1582 if (NumberOfChildren == 0) {
1583 return EFI_SUCCESS;
1584 }
1585
1586 //
1587 // Close Simple Pointer protocol on controller handle and virtual handle.
1588 //
1589 Status = ConSplitterStop (
1590 This,
1591 ControllerHandle,
1592 mConIn.VirtualHandle,
1593 &gEfiSimplePointerProtocolGuid,
1594 &gEfiSimplePointerProtocolGuid,
1595 (VOID **) &SimplePointer
1596 );
1597 if (EFI_ERROR (Status)) {
1598 return Status;
1599 }
1600
1601 //
1602 // Remove this device from Simple Pointer device list.
1603 //
1604 return ConSplitterSimplePointerDeleteDevice (&mConIn, SimplePointer);
1605 }
1606
1607
1608 /**
1609 Stop Absolute Pointer protocol ConSplitter on ControllerHandle by closing
1610 Absolute Pointer protocol.
1611
1612 @param This Driver Binding protocol instance pointer.
1613 @param ControllerHandle Handle of device to stop driver on
1614 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
1615 children is zero stop the entire bus driver.
1616 @param ChildHandleBuffer List of Child Handles to Stop.
1617
1618 @retval EFI_SUCCESS This driver is removed ControllerHandle
1619 @retval other This driver was not removed from this device
1620
1621 **/
1622 EFI_STATUS
1623 EFIAPI
1624 ConSplitterAbsolutePointerDriverBindingStop (
1625 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1626 IN EFI_HANDLE ControllerHandle,
1627 IN UINTN NumberOfChildren,
1628 IN EFI_HANDLE *ChildHandleBuffer
1629 )
1630 {
1631 EFI_STATUS Status;
1632 EFI_ABSOLUTE_POINTER_PROTOCOL *AbsolutePointer;
1633
1634 if (NumberOfChildren == 0) {
1635 return EFI_SUCCESS;
1636 }
1637
1638 //
1639 // Close Absolute Pointer protocol on controller handle and virtual handle.
1640 //
1641 Status = ConSplitterStop (
1642 This,
1643 ControllerHandle,
1644 mConIn.VirtualHandle,
1645 &gEfiAbsolutePointerProtocolGuid,
1646 &gEfiAbsolutePointerProtocolGuid,
1647 (VOID **) &AbsolutePointer
1648 );
1649 if (EFI_ERROR (Status)) {
1650 return Status;
1651 }
1652
1653 //
1654 // Remove this device from Absolute Pointer device list.
1655 //
1656 return ConSplitterAbsolutePointerDeleteDevice (&mConIn, AbsolutePointer);
1657 }
1658
1659
1660 /**
1661 Stop Console Out ConSplitter on device handle by closing Console Out Devcice GUID.
1662
1663 @param This Driver Binding protocol instance pointer.
1664 @param ControllerHandle Handle of device to stop driver on
1665 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
1666 children is zero stop the entire bus driver.
1667 @param ChildHandleBuffer List of Child Handles to Stop.
1668
1669 @retval EFI_SUCCESS This driver is removed ControllerHandle
1670 @retval other This driver was not removed from this device
1671
1672 **/
1673 EFI_STATUS
1674 EFIAPI
1675 ConSplitterConOutDriverBindingStop (
1676 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1677 IN EFI_HANDLE ControllerHandle,
1678 IN UINTN NumberOfChildren,
1679 IN EFI_HANDLE *ChildHandleBuffer
1680 )
1681 {
1682 EFI_STATUS Status;
1683 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut;
1684
1685 if (NumberOfChildren == 0) {
1686 return EFI_SUCCESS;
1687 }
1688
1689 //
1690 // Close Absolute Pointer protocol on controller handle and virtual handle.
1691 //
1692 Status = ConSplitterStop (
1693 This,
1694 ControllerHandle,
1695 mConOut.VirtualHandle,
1696 &gEfiConsoleOutDeviceGuid,
1697 &gEfiSimpleTextOutProtocolGuid,
1698 (VOID **) &TextOut
1699 );
1700 if (EFI_ERROR (Status)) {
1701 return Status;
1702 }
1703
1704 //
1705 // Remove this device from Text Out device list.
1706 //
1707 return ConSplitterTextOutDeleteDevice (&mConOut, TextOut);
1708 }
1709
1710
1711 /**
1712 Stop Standard Error ConSplitter on ControllerHandle by closing Standard Error GUID.
1713
1714 @param This Driver Binding protocol instance pointer.
1715 @param ControllerHandle Handle of device to stop driver on
1716 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
1717 children is zero stop the entire bus driver.
1718 @param ChildHandleBuffer List of Child Handles to Stop.
1719
1720 @retval EFI_SUCCESS This driver is removed ControllerHandle
1721 @retval other This driver was not removed from this device
1722
1723 **/
1724 EFI_STATUS
1725 EFIAPI
1726 ConSplitterStdErrDriverBindingStop (
1727 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1728 IN EFI_HANDLE ControllerHandle,
1729 IN UINTN NumberOfChildren,
1730 IN EFI_HANDLE *ChildHandleBuffer
1731 )
1732 {
1733 EFI_STATUS Status;
1734 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut;
1735
1736 if (NumberOfChildren == 0) {
1737 return EFI_SUCCESS;
1738 }
1739
1740 //
1741 // Close Standard Error Device on controller handle and virtual handle.
1742 //
1743 Status = ConSplitterStop (
1744 This,
1745 ControllerHandle,
1746 mStdErr.VirtualHandle,
1747 &gEfiStandardErrorDeviceGuid,
1748 &gEfiSimpleTextOutProtocolGuid,
1749 (VOID **) &TextOut
1750 );
1751 if (EFI_ERROR (Status)) {
1752 return Status;
1753 }
1754 //
1755 // Delete this console error out device's data structures.
1756 //
1757 Status = ConSplitterTextOutDeleteDevice (&mStdErr, TextOut);
1758 if (EFI_ERROR (Status)) {
1759 return Status;
1760 }
1761
1762 if (mStdErr.CurrentNumberOfConsoles == 0) {
1763 gST->StandardErrorHandle = NULL;
1764 gST->StdErr = NULL;
1765 //
1766 // Update the CRC32 in the EFI System Table header
1767 //
1768 gST->Hdr.CRC32 = 0;
1769 gBS->CalculateCrc32 (
1770 (UINT8 *) &gST->Hdr,
1771 gST->Hdr.HeaderSize,
1772 &gST->Hdr.CRC32
1773 );
1774 }
1775
1776 return Status;
1777 }
1778
1779
1780 /**
1781 Take the passed in Buffer of size SizeOfCount and grow the buffer
1782 by MAX (CONSOLE_SPLITTER_CONSOLES_ALLOC_UNIT, MaxGrow) * SizeOfCount
1783 bytes. Copy the current data in Buffer to the new version of Buffer
1784 and free the old version of buffer.
1785
1786 @param SizeOfCount Size of element in array.
1787 @param Count Current number of elements in array.
1788 @param Buffer Bigger version of passed in Buffer with all the
1789 data.
1790
1791 @retval EFI_SUCCESS Buffer size has grown.
1792 @retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
1793
1794 **/
1795 EFI_STATUS
1796 ConSplitterGrowBuffer (
1797 IN UINTN SizeOfCount,
1798 IN UINTN *Count,
1799 IN OUT VOID **Buffer
1800 )
1801 {
1802 VOID *Ptr;
1803
1804 //
1805 // grow the buffer to new buffer size,
1806 // copy the old buffer's content to the new-size buffer,
1807 // then free the old buffer.
1808 //
1809 *Count += CONSOLE_SPLITTER_CONSOLES_ALLOC_UNIT;
1810 Ptr = ReallocatePool (
1811 SizeOfCount * ((*Count) - CONSOLE_SPLITTER_CONSOLES_ALLOC_UNIT),
1812 SizeOfCount * (*Count),
1813 *Buffer
1814 );
1815 if (Ptr == NULL) {
1816 return EFI_OUT_OF_RESOURCES;
1817 }
1818 *Buffer = Ptr;
1819 return EFI_SUCCESS;
1820 }
1821
1822
1823 /**
1824 Add Text Input Device in Consplitter Text Input list.
1825
1826 @param Private Text In Splitter pointer.
1827 @param TextIn Simple Text Input protocol pointer.
1828
1829 @retval EFI_SUCCESS Text Input Device added successfully.
1830 @retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
1831
1832 **/
1833 EFI_STATUS
1834 ConSplitterTextInAddDevice (
1835 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
1836 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *TextIn
1837 )
1838 {
1839 EFI_STATUS Status;
1840
1841 //
1842 // If the Text In List is full, enlarge it by calling ConSplitterGrowBuffer().
1843 //
1844 if (Private->CurrentNumberOfConsoles >= Private->TextInListCount) {
1845 Status = ConSplitterGrowBuffer (
1846 sizeof (EFI_SIMPLE_TEXT_INPUT_PROTOCOL *),
1847 &Private->TextInListCount,
1848 (VOID **) &Private->TextInList
1849 );
1850 if (EFI_ERROR (Status)) {
1851 return EFI_OUT_OF_RESOURCES;
1852 }
1853 }
1854 //
1855 // Add the new text-in device data structure into the Text In List.
1856 //
1857 Private->TextInList[Private->CurrentNumberOfConsoles] = TextIn;
1858 Private->CurrentNumberOfConsoles++;
1859
1860 //
1861 // Extra CheckEvent added to reduce the double CheckEvent().
1862 //
1863 gBS->CheckEvent (TextIn->WaitForKey);
1864
1865 return EFI_SUCCESS;
1866 }
1867
1868
1869 /**
1870 Remove Text Input Device from Consplitter Text Input list.
1871
1872 @param Private Text In Splitter pointer.
1873 @param TextIn Simple Text protocol pointer.
1874
1875 @retval EFI_SUCCESS Simple Text Device removed successfully.
1876 @retval EFI_NOT_FOUND No Simple Text Device found.
1877
1878 **/
1879 EFI_STATUS
1880 ConSplitterTextInDeleteDevice (
1881 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
1882 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *TextIn
1883 )
1884 {
1885 UINTN Index;
1886 //
1887 // Remove the specified text-in device data structure from the Text In List,
1888 // and rearrange the remaining data structures in the Text In List.
1889 //
1890 for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {
1891 if (Private->TextInList[Index] == TextIn) {
1892 for (Index = Index; Index < Private->CurrentNumberOfConsoles - 1; Index++) {
1893 Private->TextInList[Index] = Private->TextInList[Index + 1];
1894 }
1895
1896 Private->CurrentNumberOfConsoles--;
1897 return EFI_SUCCESS;
1898 }
1899 }
1900
1901 return EFI_NOT_FOUND;
1902 }
1903
1904 /**
1905 Add Text Input Ex Device in Consplitter Text Input Ex list.
1906
1907 @param Private Text In Splitter pointer.
1908 @param TextInEx Simple Text Input Ex Input protocol pointer.
1909
1910 @retval EFI_SUCCESS Text Input Ex Device added successfully.
1911 @retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
1912
1913 **/
1914 EFI_STATUS
1915 ConSplitterTextInExAddDevice (
1916 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
1917 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TextInEx
1918 )
1919 {
1920 EFI_STATUS Status;
1921
1922 //
1923 // If the Text Input Ex List is full, enlarge it by calling ConSplitterGrowBuffer().
1924 //
1925 if (Private->CurrentNumberOfExConsoles >= Private->TextInExListCount) {
1926 Status = ConSplitterGrowBuffer (
1927 sizeof (EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *),
1928 &Private->TextInExListCount,
1929 (VOID **) &Private->TextInExList
1930 );
1931 if (EFI_ERROR (Status)) {
1932 return EFI_OUT_OF_RESOURCES;
1933 }
1934 }
1935 //
1936 // Add the new text-in device data structure into the Text Input Ex List.
1937 //
1938 Private->TextInExList[Private->CurrentNumberOfExConsoles] = TextInEx;
1939 Private->CurrentNumberOfExConsoles++;
1940
1941 //
1942 // Extra CheckEvent added to reduce the double CheckEvent().
1943 //
1944 gBS->CheckEvent (TextInEx->WaitForKeyEx);
1945
1946 return EFI_SUCCESS;
1947 }
1948
1949 /**
1950 Remove Text Ex Device from Consplitter Text Input Ex list.
1951
1952 @param Private Text In Splitter pointer.
1953 @param TextInEx Simple Text Ex protocol pointer.
1954
1955 @retval EFI_SUCCESS Simple Text Input Ex Device removed successfully.
1956 @retval EFI_NOT_FOUND No Simple Text Input Ex Device found.
1957
1958 **/
1959 EFI_STATUS
1960 ConSplitterTextInExDeleteDevice (
1961 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
1962 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *TextInEx
1963 )
1964 {
1965 UINTN Index;
1966 //
1967 // Remove the specified text-in device data structure from the Text Input Ex List,
1968 // and rearrange the remaining data structures in the Text In List.
1969 //
1970 for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {
1971 if (Private->TextInExList[Index] == TextInEx) {
1972 for (Index = Index; Index < Private->CurrentNumberOfExConsoles - 1; Index++) {
1973 Private->TextInExList[Index] = Private->TextInExList[Index + 1];
1974 }
1975
1976 Private->CurrentNumberOfExConsoles--;
1977 return EFI_SUCCESS;
1978 }
1979 }
1980
1981 return EFI_NOT_FOUND;
1982 }
1983
1984
1985 /**
1986 Add Simple Pointer Device in Consplitter Simple Pointer list.
1987
1988 @param Private Text In Splitter pointer.
1989 @param SimplePointer Simple Pointer protocol pointer.
1990
1991 @retval EFI_SUCCESS Simple Pointer Device added successfully.
1992 @retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
1993
1994 **/
1995 EFI_STATUS
1996 ConSplitterSimplePointerAddDevice (
1997 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
1998 IN EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer
1999 )
2000 {
2001 EFI_STATUS Status;
2002
2003 //
2004 // If the Simple Pointer List is full, enlarge it by calling ConSplitterGrowBuffer().
2005 //
2006 if (Private->CurrentNumberOfPointers >= Private->PointerListCount) {
2007 Status = ConSplitterGrowBuffer (
2008 sizeof (EFI_SIMPLE_POINTER_PROTOCOL *),
2009 &Private->PointerListCount,
2010 (VOID **) &Private->PointerList
2011 );
2012 if (EFI_ERROR (Status)) {
2013 return EFI_OUT_OF_RESOURCES;
2014 }
2015 }
2016 //
2017 // Add the new text-in device data structure into the Simple Pointer List.
2018 //
2019 Private->PointerList[Private->CurrentNumberOfPointers] = SimplePointer;
2020 Private->CurrentNumberOfPointers++;
2021
2022 return EFI_SUCCESS;
2023 }
2024
2025
2026 /**
2027 Remove Simple Pointer Device from Consplitter Simple Pointer list.
2028
2029 @param Private Text In Splitter pointer.
2030 @param SimplePointer Simple Pointer protocol pointer.
2031
2032 @retval EFI_SUCCESS Simple Pointer Device removed successfully.
2033 @retval EFI_NOT_FOUND No Simple Pointer Device found.
2034
2035 **/
2036 EFI_STATUS
2037 ConSplitterSimplePointerDeleteDevice (
2038 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
2039 IN EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer
2040 )
2041 {
2042 UINTN Index;
2043 //
2044 // Remove the specified text-in device data structure from the Simple Pointer List,
2045 // and rearrange the remaining data structures in the Text In List.
2046 //
2047 for (Index = 0; Index < Private->CurrentNumberOfPointers; Index++) {
2048 if (Private->PointerList[Index] == SimplePointer) {
2049 for (Index = Index; Index < Private->CurrentNumberOfPointers - 1; Index++) {
2050 Private->PointerList[Index] = Private->PointerList[Index + 1];
2051 }
2052
2053 Private->CurrentNumberOfPointers--;
2054 return EFI_SUCCESS;
2055 }
2056 }
2057
2058 return EFI_NOT_FOUND;
2059 }
2060
2061
2062 /**
2063 Add Absolute Pointer Device in Consplitter Absolute Pointer list.
2064
2065 @param Private Text In Splitter pointer.
2066 @param AbsolutePointer Absolute Pointer protocol pointer.
2067
2068 @retval EFI_SUCCESS Absolute Pointer Device added successfully.
2069 @retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
2070
2071 **/
2072 EFI_STATUS
2073 ConSplitterAbsolutePointerAddDevice (
2074 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
2075 IN EFI_ABSOLUTE_POINTER_PROTOCOL *AbsolutePointer
2076 )
2077 {
2078 EFI_STATUS Status;
2079
2080 //
2081 // If the Absolute Pointer List is full, enlarge it by calling ConSplitterGrowBuffer().
2082 //
2083 if (Private->CurrentNumberOfAbsolutePointers >= Private->AbsolutePointerListCount) {
2084 Status = ConSplitterGrowBuffer (
2085 sizeof (EFI_ABSOLUTE_POINTER_PROTOCOL *),
2086 &Private->AbsolutePointerListCount,
2087 (VOID **) &Private->AbsolutePointerList
2088 );
2089 if (EFI_ERROR (Status)) {
2090 return EFI_OUT_OF_RESOURCES;
2091 }
2092 }
2093 //
2094 // Add the new text-in device data structure into the Absolute Pointer List.
2095 //
2096 Private->AbsolutePointerList[Private->CurrentNumberOfAbsolutePointers] = AbsolutePointer;
2097 Private->CurrentNumberOfAbsolutePointers++;
2098
2099 return EFI_SUCCESS;
2100 }
2101
2102
2103 /**
2104 Remove Absolute Pointer Device from Consplitter Absolute Pointer list.
2105
2106 @param Private Text In Splitter pointer.
2107 @param AbsolutePointer Absolute Pointer protocol pointer.
2108
2109 @retval EFI_SUCCESS Absolute Pointer Device removed successfully.
2110 @retval EFI_NOT_FOUND No Absolute Pointer Device found.
2111
2112 **/
2113 EFI_STATUS
2114 ConSplitterAbsolutePointerDeleteDevice (
2115 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
2116 IN EFI_ABSOLUTE_POINTER_PROTOCOL *AbsolutePointer
2117 )
2118 {
2119 UINTN Index;
2120 //
2121 // Remove the specified text-in device data structure from the Absolute Pointer List,
2122 // and rearrange the remaining data structures from the Absolute Pointer List.
2123 //
2124 for (Index = 0; Index < Private->CurrentNumberOfAbsolutePointers; Index++) {
2125 if (Private->AbsolutePointerList[Index] == AbsolutePointer) {
2126 for (Index = Index; Index < Private->CurrentNumberOfAbsolutePointers - 1; Index++) {
2127 Private->AbsolutePointerList[Index] = Private->AbsolutePointerList[Index + 1];
2128 }
2129
2130 Private->CurrentNumberOfAbsolutePointers--;
2131 return EFI_SUCCESS;
2132 }
2133 }
2134
2135 return EFI_NOT_FOUND;
2136 }
2137
2138 /**
2139 Reallocate Text Out mode map.
2140
2141 Allocate new buffer and copy original buffer into the new buffer.
2142
2143 @param Private Consplitter Text Out pointer.
2144
2145 @retval EFI_SUCCESS Buffer size has grown
2146 @retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
2147
2148 **/
2149 EFI_STATUS
2150 ConSplitterGrowMapTable (
2151 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private
2152 )
2153 {
2154 UINTN Size;
2155 UINTN NewSize;
2156 UINTN TotalSize;
2157 INT32 *TextOutModeMap;
2158 INT32 *OldTextOutModeMap;
2159 INT32 *SrcAddress;
2160 INT32 Index;
2161
2162 NewSize = Private->TextOutListCount * sizeof (INT32);
2163 OldTextOutModeMap = Private->TextOutModeMap;
2164 TotalSize = NewSize * (Private->TextOutQueryDataCount);
2165
2166 //
2167 // Allocate new buffer for Text Out List.
2168 //
2169 TextOutModeMap = AllocatePool (TotalSize);
2170 if (TextOutModeMap == NULL) {
2171 return EFI_OUT_OF_RESOURCES;
2172 }
2173
2174 SetMem (TextOutModeMap, TotalSize, 0xFF);
2175 Private->TextOutModeMap = TextOutModeMap;
2176
2177 //
2178 // If TextOutList has been enlarged, need to realloc the mode map table
2179 // The mode map table is regarded as a two dimension array.
2180 //
2181 // Old New
2182 // 0 ---------> TextOutListCount ----> TextOutListCount
2183 // | -------------------------------------------
2184 // | | | |
2185 // | | | |
2186 // | | | |
2187 // | | | |
2188 // | | | |
2189 // \/ | | |
2190 // -------------------------------------------
2191 // QueryDataCount
2192 //
2193 if (OldTextOutModeMap != NULL) {
2194
2195 Size = Private->CurrentNumberOfConsoles * sizeof (INT32);
2196 Index = 0;
2197 SrcAddress = OldTextOutModeMap;
2198
2199 //
2200 // Copy the old data to the new one
2201 //
2202 while (Index < Private->TextOutMode.MaxMode) {
2203 CopyMem (TextOutModeMap, SrcAddress, Size);
2204 TextOutModeMap += NewSize;
2205 SrcAddress += Size;
2206 Index++;
2207 }
2208 //
2209 // Free the old buffer
2210 //
2211 FreePool (OldTextOutModeMap);
2212 }
2213
2214 return EFI_SUCCESS;
2215 }
2216
2217
2218 /**
2219 Add new device's output mode to console splitter's mode list.
2220
2221 @param Private Text Out Splitter pointer
2222 @param TextOut Simple Text Output protocol pointer.
2223
2224 @retval EFI_SUCCESS Device added successfully.
2225 @retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
2226
2227 **/
2228 EFI_STATUS
2229 ConSplitterAddOutputMode (
2230 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
2231 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut
2232 )
2233 {
2234 EFI_STATUS Status;
2235 INT32 MaxMode;
2236 INT32 Mode;
2237 UINTN Index;
2238
2239 MaxMode = TextOut->Mode->MaxMode;
2240 Private->TextOutMode.MaxMode = MaxMode;
2241
2242 //
2243 // Grow the buffer if query data buffer is not large enough to
2244 // hold all the mode supported by the first console.
2245 //
2246 while (MaxMode > (INT32) Private->TextOutQueryDataCount) {
2247 Status = ConSplitterGrowBuffer (
2248 sizeof (TEXT_OUT_SPLITTER_QUERY_DATA),
2249 &Private->TextOutQueryDataCount,
2250 (VOID **) &Private->TextOutQueryData
2251 );
2252 if (EFI_ERROR (Status)) {
2253 return EFI_OUT_OF_RESOURCES;
2254 }
2255 }
2256 //
2257 // Allocate buffer for the output mode map
2258 //
2259 Status = ConSplitterGrowMapTable (Private);
2260 if (EFI_ERROR (Status)) {
2261 return EFI_OUT_OF_RESOURCES;
2262 }
2263 //
2264 // As the first textout device, directly add the mode in to QueryData
2265 // and at the same time record the mapping between QueryData and TextOut.
2266 //
2267 Mode = 0;
2268 Index = 0;
2269 while (Mode < MaxMode) {
2270 Status = TextOut->QueryMode (
2271 TextOut,
2272 Mode,
2273 &Private->TextOutQueryData[Mode].Columns,
2274 &Private->TextOutQueryData[Mode].Rows
2275 );
2276 //
2277 // If mode 1 (80x50) is not supported, make sure mode 1 in TextOutQueryData
2278 // is clear to 0x0.
2279 //
2280 if ((EFI_ERROR(Status)) && (Mode == 1)) {
2281 Private->TextOutQueryData[Mode].Columns = 0;
2282 Private->TextOutQueryData[Mode].Rows = 0;
2283 }
2284 Private->TextOutModeMap[Index] = Mode;
2285 Mode++;
2286 Index += Private->TextOutListCount;
2287 }
2288
2289 return EFI_SUCCESS;
2290 }
2291
2292 /**
2293 Reconstruct TextOutModeMap to get intersection of modes.
2294
2295 This routine reconstruct TextOutModeMap to get the intersection
2296 of modes for all console out devices. Because EFI/UEFI spec require
2297 mode 0 is 80x25, mode 1 is 80x50, this routine will not check the
2298 intersection for mode 0 and mode 1.
2299
2300 @param TextOutModeMap Current text out mode map, begin with the mode 80x25
2301 @param NewlyAddedMap New text out mode map, begin with the mode 80x25
2302 @param MapStepSize Mode step size for one console device
2303 @param NewMapStepSize New Mode step size for one console device
2304 @param MaxMode IN: Current max text mode, OUT: Updated max text mode.
2305 @param CurrentMode IN: Current text mode, OUT: Updated current text mode.
2306
2307 **/
2308 VOID
2309 ConSplitterGetIntersection (
2310 IN INT32 *TextOutModeMap,
2311 IN INT32 *NewlyAddedMap,
2312 IN UINTN MapStepSize,
2313 IN UINTN NewMapStepSize,
2314 IN OUT INT32 *MaxMode,
2315 IN OUT INT32 *CurrentMode
2316 )
2317 {
2318 INT32 Index;
2319 INT32 *CurrentMapEntry;
2320 INT32 *NextMapEntry;
2321 INT32 *NewMapEntry;
2322 INT32 CurrentMaxMode;
2323 INT32 Mode;
2324
2325 //
2326 // According to EFI/UEFI spec, mode 0 and mode 1 have been reserved
2327 // for 80x25 and 80x50 in Simple Text Out protocol, so don't make intersection
2328 // for mode 0 and mode 1, mode number starts from 2.
2329 //
2330 Index = 2;
2331 CurrentMapEntry = &TextOutModeMap[MapStepSize * 2];
2332 NextMapEntry = CurrentMapEntry;
2333 NewMapEntry = &NewlyAddedMap[NewMapStepSize * 2];
2334
2335 CurrentMaxMode = *MaxMode;
2336 Mode = *CurrentMode;
2337
2338 while (Index < CurrentMaxMode) {
2339 if (*NewMapEntry == -1) {
2340 //
2341 // This mode is not supported any more. Remove it. Special care
2342 // must be taken as this remove will also affect current mode;
2343 //
2344 if (Index == *CurrentMode) {
2345 Mode = -1;
2346 } else if (Index < *CurrentMode) {
2347 Mode--;
2348 }
2349 (*MaxMode)--;
2350 } else {
2351 if (CurrentMapEntry != NextMapEntry) {
2352 CopyMem (NextMapEntry, CurrentMapEntry, MapStepSize * sizeof (INT32));
2353 }
2354
2355 NextMapEntry += MapStepSize;
2356 }
2357
2358 CurrentMapEntry += MapStepSize;
2359 NewMapEntry += NewMapStepSize;
2360 Index++;
2361 }
2362
2363 *CurrentMode = Mode;
2364
2365 return ;
2366 }
2367
2368 /**
2369 Add the device's output mode to console splitter's mode list.
2370
2371 @param Private Text Out Splitter pointer.
2372 @param TextOut Simple Text Output protocol pointer.
2373
2374 **/
2375 VOID
2376 ConSplitterSyncOutputMode (
2377 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
2378 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut
2379 )
2380 {
2381 INT32 CurrentMaxMode;
2382 INT32 Mode;
2383 INT32 Index;
2384 INT32 *TextOutModeMap;
2385 INT32 *MapTable;
2386 INT32 QueryMode;
2387 TEXT_OUT_SPLITTER_QUERY_DATA *TextOutQueryData;
2388 UINTN Rows;
2389 UINTN Columns;
2390 UINTN StepSize;
2391 EFI_STATUS Status;
2392
2393 //
2394 // Must make sure that current mode won't change even if mode number changes
2395 //
2396 CurrentMaxMode = Private->TextOutMode.MaxMode;
2397 TextOutModeMap = Private->TextOutModeMap;
2398 StepSize = Private->TextOutListCount;
2399 TextOutQueryData = Private->TextOutQueryData;
2400
2401 //
2402 // Query all the mode that the newly added TextOut supports
2403 //
2404 Mode = 0;
2405 MapTable = TextOutModeMap + Private->CurrentNumberOfConsoles;
2406 while (Mode < TextOut->Mode->MaxMode) {
2407 Status = TextOut->QueryMode (TextOut, Mode, &Columns, &Rows);
2408
2409 if (EFI_ERROR(Status)) {
2410 if (Mode == 1) {
2411 //
2412 // If mode 1 (80x50) is not supported, make sure mode 1 in TextOutQueryData
2413 // is clear to 0x0.
2414 //
2415 MapTable[StepSize] = Mode;
2416 TextOutQueryData[Mode].Columns = 0;
2417 TextOutQueryData[Mode].Rows = 0;
2418 }
2419 Mode++;
2420 continue;
2421 }
2422 //
2423 // Search the intersection map and QueryData database to see if they intersects
2424 //
2425 Index = 0;
2426 while (Index < CurrentMaxMode) {
2427 QueryMode = *(TextOutModeMap + Index * StepSize);
2428 if ((TextOutQueryData[QueryMode].Rows == Rows) && (TextOutQueryData[QueryMode].Columns == Columns)) {
2429 MapTable[Index * StepSize] = Mode;
2430 break;
2431 }
2432 Index++;
2433 }
2434 Mode++;
2435 }
2436 //
2437 // Now search the TextOutModeMap table to find the intersection of supported
2438 // mode between ConSplitter and the newly added device.
2439 //
2440 ConSplitterGetIntersection (
2441 TextOutModeMap,
2442 MapTable,
2443 StepSize,
2444 StepSize,
2445 &Private->TextOutMode.MaxMode,
2446 &Private->TextOutMode.Mode
2447 );
2448
2449 return ;
2450 }
2451
2452
2453 /**
2454 Sync output device between ConOut and StdErr output.
2455
2456 @retval EFI_SUCCESS Sync implemented successfully.
2457 @retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
2458
2459 **/
2460 EFI_STATUS
2461 ConSplitterGetIntersectionBetweenConOutAndStrErr (
2462 VOID
2463 )
2464 {
2465 UINTN ConOutNumOfConsoles;
2466 UINTN StdErrNumOfConsoles;
2467 TEXT_OUT_AND_GOP_DATA *ConOutTextOutList;
2468 TEXT_OUT_AND_GOP_DATA *StdErrTextOutList;
2469 UINTN Indexi;
2470 UINTN Indexj;
2471 UINTN ConOutRows;
2472 UINTN ConOutColumns;
2473 UINTN StdErrRows;
2474 UINTN StdErrColumns;
2475 INT32 ConOutMaxMode;
2476 INT32 StdErrMaxMode;
2477 INT32 ConOutMode;
2478 INT32 StdErrMode;
2479 INT32 Mode;
2480 INT32 Index;
2481 INT32 *ConOutModeMap;
2482 INT32 *StdErrModeMap;
2483 INT32 *ConOutMapTable;
2484 INT32 *StdErrMapTable;
2485 TEXT_OUT_SPLITTER_QUERY_DATA *ConOutQueryData;
2486 TEXT_OUT_SPLITTER_QUERY_DATA *StdErrQueryData;
2487 UINTN ConOutStepSize;
2488 UINTN StdErrStepSize;
2489 BOOLEAN FoundTheSameTextOut;
2490 UINTN ConOutMapTableSize;
2491 UINTN StdErrMapTableSize;
2492
2493 ConOutNumOfConsoles = mConOut.CurrentNumberOfConsoles;
2494 StdErrNumOfConsoles = mStdErr.CurrentNumberOfConsoles;
2495 ConOutTextOutList = mConOut.TextOutList;
2496 StdErrTextOutList = mStdErr.TextOutList;
2497
2498 Indexi = 0;
2499 FoundTheSameTextOut = FALSE;
2500 while ((Indexi < ConOutNumOfConsoles) && (!FoundTheSameTextOut)) {
2501 Indexj = 0;
2502 while (Indexj < StdErrNumOfConsoles) {
2503 if (ConOutTextOutList->TextOut == StdErrTextOutList->TextOut) {
2504 FoundTheSameTextOut = TRUE;
2505 break;
2506 }
2507
2508 Indexj++;
2509 StdErrTextOutList++;
2510 }
2511
2512 Indexi++;
2513 ConOutTextOutList++;
2514 }
2515
2516 if (!FoundTheSameTextOut) {
2517 return EFI_SUCCESS;
2518 }
2519 //
2520 // Must make sure that current mode won't change even if mode number changes
2521 //
2522 ConOutMaxMode = mConOut.TextOutMode.MaxMode;
2523 ConOutModeMap = mConOut.TextOutModeMap;
2524 ConOutStepSize = mConOut.TextOutListCount;
2525 ConOutQueryData = mConOut.TextOutQueryData;
2526
2527 StdErrMaxMode = mStdErr.TextOutMode.MaxMode;
2528 StdErrModeMap = mStdErr.TextOutModeMap;
2529 StdErrStepSize = mStdErr.TextOutListCount;
2530 StdErrQueryData = mStdErr.TextOutQueryData;
2531
2532 //
2533 // Allocate the map table and set the map table's index to -1.
2534 //
2535 ConOutMapTableSize = ConOutMaxMode * sizeof (INT32);
2536 ConOutMapTable = AllocateZeroPool (ConOutMapTableSize);
2537 if (ConOutMapTable == NULL) {
2538 return EFI_OUT_OF_RESOURCES;
2539 }
2540
2541 SetMem (ConOutMapTable, ConOutMapTableSize, 0xFF);
2542
2543 StdErrMapTableSize = StdErrMaxMode * sizeof (INT32);
2544 StdErrMapTable = AllocateZeroPool (StdErrMapTableSize);
2545 if (StdErrMapTable == NULL) {
2546 return EFI_OUT_OF_RESOURCES;
2547 }
2548
2549 SetMem (StdErrMapTable, StdErrMapTableSize, 0xFF);
2550
2551 //
2552 // Find the intersection of the two set of modes. If they actually intersect, the
2553 // correponding entry in the map table is set to 1.
2554 //
2555 Mode = 0;
2556 while (Mode < ConOutMaxMode) {
2557 //
2558 // Search the intersection map and QueryData database to see if they intersect
2559 //
2560 Index = 0;
2561 ConOutMode = *(ConOutModeMap + Mode * ConOutStepSize);
2562 ConOutRows = ConOutQueryData[ConOutMode].Rows;
2563 ConOutColumns = ConOutQueryData[ConOutMode].Columns;
2564 while (Index < StdErrMaxMode) {
2565 StdErrMode = *(StdErrModeMap + Index * StdErrStepSize);
2566 StdErrRows = StdErrQueryData[StdErrMode].Rows;
2567 StdErrColumns = StdErrQueryData[StdErrMode].Columns;
2568 if ((StdErrRows == ConOutRows) && (StdErrColumns == ConOutColumns)) {
2569 ConOutMapTable[Mode] = 1;
2570 StdErrMapTable[Index] = 1;
2571 break;
2572 }
2573
2574 Index++;
2575 }
2576
2577 Mode++;
2578 }
2579 //
2580 // Now search the TextOutModeMap table to find the intersection of supported
2581 // mode between ConSplitter and the newly added device.
2582 //
2583 ConSplitterGetIntersection (
2584 ConOutModeMap,
2585 ConOutMapTable,
2586 mConOut.TextOutListCount,
2587 1,
2588 &(mConOut.TextOutMode.MaxMode),
2589 &(mConOut.TextOutMode.Mode)
2590 );
2591
2592 if (mConOut.TextOutMode.Mode < 0) {
2593 mConOut.TextOut.SetMode (&(mConOut.TextOut), 0);
2594 }
2595
2596 ConSplitterGetIntersection (
2597 StdErrModeMap,
2598 StdErrMapTable,
2599 mStdErr.TextOutListCount,
2600 1,
2601 &(mStdErr.TextOutMode.MaxMode),
2602 &(mStdErr.TextOutMode.Mode)
2603 );
2604
2605 if (mStdErr.TextOutMode.Mode < 0) {
2606 mStdErr.TextOut.SetMode (&(mStdErr.TextOut), 0);
2607 }
2608
2609 FreePool (ConOutMapTable);
2610 FreePool (StdErrMapTable);
2611
2612 return EFI_SUCCESS;
2613 }
2614
2615
2616 /**
2617 Add display (GOP or UGA) output modes into Consplitter Text Out list.
2618
2619 @param Private Text Out Splitter pointer.
2620 @param GraphicsOutput Graphics Output protocol pointer.
2621 @param UgaDraw UGA Draw protocol pointer.
2622
2623 @retval EFI_SUCCESS Output mode added successfully.
2624 @retval other Failed to add output mode.
2625
2626 **/
2627 EFI_STATUS
2628 ConSplitterAddDisplayOutputMode (
2629 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
2630 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput,
2631 IN EFI_UGA_DRAW_PROTOCOL *UgaDraw
2632 )
2633 {
2634 EFI_STATUS Status;
2635 UINTN Index;
2636 UINTN CurrentIndex;
2637 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Mode;
2638 UINTN SizeOfInfo;
2639 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
2640 EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *CurrentGraphicsOutputMode;
2641 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *ModeBuffer;
2642 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *MatchedMode;
2643 UINTN NumberIndex;
2644 BOOLEAN Match;
2645 BOOLEAN AlreadyExist;
2646 UINT32 UgaHorizontalResolution;
2647 UINT32 UgaVerticalResolution;
2648 UINT32 UgaColorDepth;
2649 UINT32 UgaRefreshRate;
2650
2651 if ((GraphicsOutput == NULL) && (UgaDraw == NULL)) {
2652 return EFI_UNSUPPORTED;
2653 }
2654
2655 CurrentGraphicsOutputMode = Private->GraphicsOutput.Mode;
2656
2657 Index = 0;
2658 CurrentIndex = 0;
2659
2660 if (Private->CurrentNumberOfUgaDraw != 0) {
2661 //
2662 // If any UGA device has already been added, then there is no need to
2663 // calculate intersection of display mode of different GOP/UGA device,
2664 // since only one display mode will be exported (i.e. user-defined mode)
2665 //
2666 goto Done;
2667 }
2668
2669 if (GraphicsOutput != NULL) {
2670 if (Private->CurrentNumberOfGraphicsOutput == 0) {
2671 //
2672 // This is the first Graphics Output device added
2673 //
2674 CurrentGraphicsOutputMode->MaxMode = GraphicsOutput->Mode->MaxMode;
2675 CurrentGraphicsOutputMode->Mode = GraphicsOutput->Mode->Mode;
2676 CopyMem (CurrentGraphicsOutputMode->Info, GraphicsOutput->Mode->Info, GraphicsOutput->Mode->SizeOfInfo);
2677 CurrentGraphicsOutputMode->SizeOfInfo = GraphicsOutput->Mode->SizeOfInfo;
2678 CurrentGraphicsOutputMode->FrameBufferBase = GraphicsOutput->Mode->FrameBufferBase;
2679 CurrentGraphicsOutputMode->FrameBufferSize = GraphicsOutput->Mode->FrameBufferSize;
2680
2681 //
2682 // Allocate resource for the private mode buffer
2683 //
2684 ModeBuffer = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION) * GraphicsOutput->Mode->MaxMode);
2685 if (ModeBuffer == NULL) {
2686 return EFI_OUT_OF_RESOURCES;
2687 }
2688 FreePool (Private->GraphicsOutputModeBuffer);
2689 Private->GraphicsOutputModeBuffer = ModeBuffer;
2690
2691 //
2692 // Store all supported display modes to the private mode buffer
2693 //
2694 Mode = ModeBuffer;
2695 for (Index = 0; Index < GraphicsOutput->Mode->MaxMode; Index++) {
2696 //
2697 // The Info buffer would be allocated by callee
2698 //
2699 Status = GraphicsOutput->QueryMode (GraphicsOutput, (UINT32) Index, &SizeOfInfo, &Info);
2700 if (EFI_ERROR (Status)) {
2701 return Status;
2702 }
2703 ASSERT ( SizeOfInfo <= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
2704 CopyMem (Mode, Info, SizeOfInfo);
2705 Mode++;
2706 FreePool (Info);
2707 }
2708 } else {
2709 //
2710 // Check intersection of display mode
2711 //
2712 ModeBuffer = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION) * CurrentGraphicsOutputMode->MaxMode);
2713 if (ModeBuffer == NULL) {
2714 return EFI_OUT_OF_RESOURCES;
2715 }
2716
2717 MatchedMode = ModeBuffer;
2718 Mode = &Private->GraphicsOutputModeBuffer[0];
2719 for (Index = 0; Index < CurrentGraphicsOutputMode->MaxMode; Index++) {
2720 Match = FALSE;
2721
2722 for (NumberIndex = 0; NumberIndex < GraphicsOutput->Mode->MaxMode; NumberIndex++) {
2723 //
2724 // The Info buffer would be allocated by callee
2725 //
2726 Status = GraphicsOutput->QueryMode (GraphicsOutput, (UINT32) NumberIndex, &SizeOfInfo, &Info);
2727 if (EFI_ERROR (Status)) {
2728 return Status;
2729 }
2730 if ((Info->HorizontalResolution == Mode->HorizontalResolution) &&
2731 (Info->VerticalResolution == Mode->VerticalResolution)) {
2732 //
2733 // If GOP device supports one mode in current mode buffer,
2734 // it will be added into matched mode buffer
2735 //
2736 Match = TRUE;
2737 FreePool (Info);
2738 break;
2739 }
2740 FreePool (Info);
2741 }
2742
2743 if (Match) {
2744 AlreadyExist = FALSE;
2745
2746 //
2747 // Check if GOP mode has been in the mode buffer, ModeBuffer = MatchedMode at begin.
2748 //
2749 for (Info = ModeBuffer; Info < MatchedMode; Info++) {
2750 if ((Info->HorizontalResolution == Mode->HorizontalResolution) &&
2751 (Info->VerticalResolution == Mode->VerticalResolution)) {
2752 AlreadyExist = TRUE;
2753 break;
2754 }
2755 }
2756
2757 if (!AlreadyExist) {
2758 CopyMem (MatchedMode, Mode, sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
2759
2760 //
2761 // Physical frame buffer is no longer available, change PixelFormat to PixelBltOnly
2762 //
2763 MatchedMode->Version = 0;
2764 MatchedMode->PixelFormat = PixelBltOnly;
2765 ZeroMem (&MatchedMode->PixelInformation, sizeof (EFI_PIXEL_BITMASK));
2766
2767 MatchedMode++;
2768 }
2769 }
2770
2771 Mode++;
2772 }
2773
2774 //
2775 // Drop the old mode buffer, assign it to a new one
2776 //
2777 FreePool (Private->GraphicsOutputModeBuffer);
2778 Private->GraphicsOutputModeBuffer = ModeBuffer;
2779
2780 //
2781 // Physical frame buffer is no longer available when there are more than one physical GOP devices
2782 //
2783 CurrentGraphicsOutputMode->MaxMode = (UINT32) (((UINTN) MatchedMode - (UINTN) ModeBuffer) / sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
2784 CurrentGraphicsOutputMode->Info->PixelFormat = PixelBltOnly;
2785 ZeroMem (&CurrentGraphicsOutputMode->Info->PixelInformation, sizeof (EFI_PIXEL_BITMASK));
2786 CurrentGraphicsOutputMode->SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
2787 CurrentGraphicsOutputMode->FrameBufferBase = (EFI_PHYSICAL_ADDRESS) (UINTN) NULL;
2788 CurrentGraphicsOutputMode->FrameBufferSize = 0;
2789 }
2790
2791 //
2792 // Graphics console driver can ensure the same mode for all GOP devices
2793 //
2794 for (Index = 0; Index < CurrentGraphicsOutputMode->MaxMode; Index++) {
2795 Mode = &Private->GraphicsOutputModeBuffer[Index];
2796 if ((Mode->HorizontalResolution == GraphicsOutput->Mode->Info->HorizontalResolution) &&
2797 (Mode->VerticalResolution == GraphicsOutput->Mode->Info->VerticalResolution)) {
2798 CurrentIndex = Index;
2799 break;
2800 }
2801 }
2802 if (Index >= CurrentGraphicsOutputMode->MaxMode) {
2803 //
2804 // if user defined mode is not found, set to default mode 800x600
2805 //
2806 for (Index = 0; Index < CurrentGraphicsOutputMode->MaxMode; Index++) {
2807 Mode = &Private->GraphicsOutputModeBuffer[Index];
2808 if ((Mode->HorizontalResolution == 800) && (Mode->VerticalResolution == 600)) {
2809 CurrentIndex = Index;
2810 break;
2811 }
2812 }
2813 }
2814 }
2815 if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {
2816 //
2817 // Graphics console driver can ensure the same mode for all GOP devices
2818 // so we can get the current mode from this video device
2819 //
2820 UgaDraw->GetMode (
2821 UgaDraw,
2822 &UgaHorizontalResolution,
2823 &UgaVerticalResolution,
2824 &UgaColorDepth,
2825 &UgaRefreshRate
2826 );
2827
2828 CurrentGraphicsOutputMode->MaxMode = 1;
2829 Info = CurrentGraphicsOutputMode->Info;
2830 Info->Version = 0;
2831 Info->HorizontalResolution = UgaHorizontalResolution;
2832 Info->VerticalResolution = UgaVerticalResolution;
2833 Info->PixelFormat = PixelBltOnly;
2834 Info->PixelsPerScanLine = UgaHorizontalResolution;
2835 CurrentGraphicsOutputMode->SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
2836 CurrentGraphicsOutputMode->FrameBufferBase = (EFI_PHYSICAL_ADDRESS) (UINTN) NULL;
2837 CurrentGraphicsOutputMode->FrameBufferSize = 0;
2838
2839 //
2840 // Update the private mode buffer
2841 //
2842 CopyMem (&Private->GraphicsOutputModeBuffer[0], Info, sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
2843
2844 //
2845 // Only mode 0 is available to be set
2846 //
2847 CurrentIndex = 0;
2848 }
2849
2850 Done:
2851
2852 if (GraphicsOutput != NULL) {
2853 Private->CurrentNumberOfGraphicsOutput++;
2854 }
2855 if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {
2856 Private->CurrentNumberOfUgaDraw++;
2857 }
2858
2859 //
2860 // Force GraphicsOutput mode to be set,
2861 // regardless whether the console is in EfiConsoleControlScreenGraphics or EfiConsoleControlScreenText mode
2862 //
2863 Private->HardwareNeedsStarting = TRUE;
2864 //
2865 // Current mode number may need update now, so set it to an invalid mode number
2866 //
2867 CurrentGraphicsOutputMode->Mode = 0xffff;
2868 //
2869 // Graphics console can ensure all GOP devices have the same mode which can be taken as current mode.
2870 //
2871 Status = Private->GraphicsOutput.SetMode (&Private->GraphicsOutput, (UINT32) CurrentIndex);
2872 if (EFI_ERROR(Status)) {
2873 //
2874 // If user defined mode is not valid for display device, set to the default mode 800x600.
2875 //
2876 (Private->GraphicsOutputModeBuffer[0]).HorizontalResolution = 800;
2877 (Private->GraphicsOutputModeBuffer[0]).VerticalResolution = 600;
2878 Status = Private->GraphicsOutput.SetMode (&Private->GraphicsOutput, 0);
2879 }
2880
2881 return Status;
2882 }
2883
2884
2885 /**
2886 This routine will get the current console mode information (column, row)
2887 from ConsoleOutMode variable and set it; if the variable does not exist,
2888 set to user defined console mode.
2889
2890 @param Private Consplitter Text Out pointer.
2891
2892 **/
2893 VOID
2894 ConsplitterSetConsoleOutMode (
2895 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private
2896 )
2897 {
2898 UINTN Col;
2899 UINTN Row;
2900 UINTN Mode;
2901 UINTN PreferMode;
2902 UINTN BaseMode;
2903 UINTN ModeInfoSize;
2904 UINTN MaxMode;
2905 EFI_STATUS Status;
2906 CONSOLE_OUT_MODE *ModeInfo;
2907 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut;
2908
2909 PreferMode = 0xFF;
2910 BaseMode = 0xFF;
2911 TextOut = &Private->TextOut;
2912 MaxMode = (UINTN) (TextOut->Mode->MaxMode);
2913 ModeInfoSize = sizeof (CONSOLE_OUT_MODE);
2914
2915 ModeInfo = AllocateZeroPool (sizeof(CONSOLE_OUT_MODE));
2916 ASSERT(ModeInfo != NULL);
2917
2918 Status = gRT->GetVariable (
2919 VARCONOUTMODE,
2920 &gEfiGenericPlatformVariableGuid,
2921 NULL,
2922 &ModeInfoSize,
2923 ModeInfo
2924 );
2925
2926 //
2927 // Set to the default mode 80 x 25 required by EFI/UEFI spec;
2928 // user can also define other valid default console mode here.
2929 //
2930 if (EFI_ERROR(Status)) {
2931 ModeInfo->Column = 80;
2932 ModeInfo->Row = 25;
2933 Status = gRT->SetVariable (
2934 VARCONOUTMODE,
2935 &gEfiGenericPlatformVariableGuid,
2936 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
2937 sizeof (CONSOLE_OUT_MODE),
2938 ModeInfo
2939 );
2940 }
2941
2942 for (Mode = 0; Mode < MaxMode; Mode++) {
2943 Status = TextOut->QueryMode (TextOut, Mode, &Col, &Row);
2944 if (!EFI_ERROR(Status)) {
2945 if (Col == ModeInfo->Column && Row == ModeInfo->Row) {
2946 PreferMode = Mode;
2947 }
2948 if (Col == 80 && Row == 25) {
2949 BaseMode = Mode;
2950 }
2951 }
2952 }
2953
2954 Status = TextOut->SetMode (TextOut, PreferMode);
2955
2956 //
2957 // if current mode setting is failed, default 80x25 mode will be set.
2958 //
2959 if (EFI_ERROR(Status)) {
2960 Status = TextOut->SetMode (TextOut, BaseMode);
2961 ASSERT(!EFI_ERROR(Status));
2962
2963 ModeInfo->Column = 80;
2964 ModeInfo->Row = 25;
2965
2966 //
2967 // Update ConOutMode variable
2968 //
2969 Status = gRT->SetVariable (
2970 VARCONOUTMODE,
2971 &gEfiGenericPlatformVariableGuid,
2972 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
2973 sizeof (CONSOLE_OUT_MODE),
2974 ModeInfo
2975 );
2976 }
2977
2978 gBS->FreePool (ModeInfo);
2979 }
2980
2981
2982 /**
2983 Add Text Output Device in Consplitter Text Output list.
2984
2985 @param Private Text Out Splitter pointer.
2986 @param TextOut Simple Text Output protocol pointer.
2987 @param GraphicsOutput Graphics Output protocol pointer.
2988 @param UgaDraw UGA Draw protocol pointer.
2989
2990 @retval EFI_SUCCESS Text Output Device added successfully.
2991 @retval EFI_OUT_OF_RESOURCES Could not grow the buffer size.
2992
2993 **/
2994 EFI_STATUS
2995 ConSplitterTextOutAddDevice (
2996 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
2997 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut,
2998 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput,
2999 IN EFI_UGA_DRAW_PROTOCOL *UgaDraw
3000 )
3001 {
3002 EFI_STATUS Status;
3003 UINTN CurrentNumOfConsoles;
3004 INT32 CurrentMode;
3005 INT32 MaxMode;
3006 UINT32 UgaHorizontalResolution;
3007 UINT32 UgaVerticalResolution;
3008 UINT32 UgaColorDepth;
3009 UINT32 UgaRefreshRate;
3010 TEXT_OUT_AND_GOP_DATA *TextAndGop;
3011
3012 Status = EFI_SUCCESS;
3013 CurrentNumOfConsoles = Private->CurrentNumberOfConsoles;
3014
3015 //
3016 // If the Text Out List is full, enlarge it by calling ConSplitterGrowBuffer().
3017 //
3018 while (CurrentNumOfConsoles >= Private->TextOutListCount) {
3019 Status = ConSplitterGrowBuffer (
3020 sizeof (TEXT_OUT_AND_GOP_DATA),
3021 &Private->TextOutListCount,
3022 (VOID **) &Private->TextOutList
3023 );
3024 if (EFI_ERROR (Status)) {
3025 return EFI_OUT_OF_RESOURCES;
3026 }
3027 //
3028 // Also need to reallocate the TextOutModeMap table
3029 //
3030 Status = ConSplitterGrowMapTable (Private);
3031 if (EFI_ERROR (Status)) {
3032 return EFI_OUT_OF_RESOURCES;
3033 }
3034 }
3035
3036 TextAndGop = &Private->TextOutList[CurrentNumOfConsoles];
3037
3038 TextAndGop->TextOut = TextOut;
3039 TextAndGop->GraphicsOutput = GraphicsOutput;
3040 TextAndGop->UgaDraw = UgaDraw;
3041
3042 if ((GraphicsOutput == NULL) && (UgaDraw == NULL)) {
3043 //
3044 // If No GOP/UGA device then use the ConOut device
3045 //
3046 TextAndGop->TextOutEnabled = TRUE;
3047 } else {
3048 //
3049 // If GOP/UGA device use ConOut device only used if screen is in Text mode
3050 //
3051 TextAndGop->TextOutEnabled = (BOOLEAN) (Private->ConsoleOutputMode == EfiConsoleControlScreenText);
3052 }
3053
3054 if (CurrentNumOfConsoles == 0) {
3055 //
3056 // Add the first device's output mode to console splitter's mode list
3057 //
3058 Status = ConSplitterAddOutputMode (Private, TextOut);
3059 } else {
3060 ConSplitterSyncOutputMode (Private, TextOut);
3061 }
3062
3063 Private->CurrentNumberOfConsoles++;
3064
3065 //
3066 // Scan both TextOutList, for the intersection TextOut device
3067 // maybe both ConOut and StdErr incorporate the same Text Out
3068 // device in them, thus the output of both should be synced.
3069 //
3070 ConSplitterGetIntersectionBetweenConOutAndStrErr ();
3071
3072 CurrentMode = Private->TextOutMode.Mode;
3073 MaxMode = Private->TextOutMode.MaxMode;
3074 ASSERT (MaxMode >= 1);
3075
3076 //
3077 // Update DevNull mode according to current video device
3078 //
3079 if (FeaturePcdGet (PcdConOutGopSupport)) {
3080 if ((GraphicsOutput != NULL) || (UgaDraw != NULL)) {
3081 ConSplitterAddDisplayOutputMode (Private, GraphicsOutput, UgaDraw);
3082 }
3083 }
3084 if (FeaturePcdGet (PcdConOutUgaSupport)) {
3085 if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {
3086 Status = UgaDraw->GetMode (
3087 UgaDraw,
3088 &UgaHorizontalResolution,
3089 &UgaVerticalResolution,
3090 &UgaColorDepth,
3091 &UgaRefreshRate
3092 );
3093 if (!EFI_ERROR (Status)) {
3094 Status = ConSpliterUgaDrawSetMode (
3095 &Private->UgaDraw,
3096 UgaHorizontalResolution,
3097 UgaVerticalResolution,
3098 UgaColorDepth,
3099 UgaRefreshRate
3100 );
3101 }
3102 //
3103 // If GetMode/SetMode is failed, set to 800x600 mode
3104 //
3105 if(EFI_ERROR (Status)) {
3106 Status = ConSpliterUgaDrawSetMode (
3107 &Private->UgaDraw,
3108 800,
3109 600,
3110 32,
3111 60
3112 );
3113 }
3114 }
3115 }
3116
3117 if (Private->ConsoleOutputMode == EfiConsoleControlScreenGraphics && GraphicsOutput != NULL) {
3118 //
3119 // We just added a new GOP or UGA device in graphics mode
3120 //
3121 if (FeaturePcdGet (PcdConOutGopSupport)) {
3122 DevNullGopSync (Private, TextAndGop->GraphicsOutput, TextAndGop->UgaDraw);
3123 } else if (FeaturePcdGet (PcdConOutUgaSupport)) {
3124 DevNullUgaSync (Private, TextAndGop->GraphicsOutput, TextAndGop->UgaDraw);
3125 }
3126 } else if ((CurrentMode >= 0) && ((GraphicsOutput != NULL) || (UgaDraw != NULL)) && (CurrentMode < Private->TextOutMode.MaxMode)) {
3127 //
3128 // The new console supports the same mode of the current console so sync up
3129 //
3130 DevNullSyncStdOut (Private);
3131 } else {
3132 //
3133 // If ConOut, then set the mode to Mode #0 which us 80 x 25
3134 //
3135 Private->TextOut.SetMode (&Private->TextOut, 0);
3136 }
3137
3138 //
3139 // After adding new console device, all existing console devices should be
3140 // synced to the current shared mode.
3141 //
3142 ConsplitterSetConsoleOutMode (Private);
3143
3144 return Status;
3145 }
3146
3147
3148 /**
3149 Remove Text Out Device in Consplitter Text Out list.
3150
3151 @param Private Text Out Splitter pointer.
3152 @param TextOut Simple Text Output Pointer protocol pointer.
3153
3154 @retval EFI_SUCCESS Text Out Device removed successfully.
3155 @retval EFI_NOT_FOUND No Text Out Device found.
3156
3157 **/
3158 EFI_STATUS
3159 ConSplitterTextOutDeleteDevice (
3160 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
3161 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut
3162 )
3163 {
3164 INT32 Index;
3165 UINTN CurrentNumOfConsoles;
3166 TEXT_OUT_AND_GOP_DATA *TextOutList;
3167 EFI_STATUS Status;
3168
3169 //
3170 // Remove the specified text-out device data structure from the Text out List,
3171 // and rearrange the remaining data structures in the Text out List.
3172 //
3173 CurrentNumOfConsoles = Private->CurrentNumberOfConsoles;
3174 Index = (INT32) CurrentNumOfConsoles - 1;
3175 TextOutList = Private->TextOutList;
3176 while (Index >= 0) {
3177 if (TextOutList->TextOut == TextOut) {
3178 CopyMem (TextOutList, TextOutList + 1, sizeof (TEXT_OUT_AND_GOP_DATA) * Index);
3179 CurrentNumOfConsoles--;
3180 if (TextOutList->UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {
3181 Private->CurrentNumberOfUgaDraw--;
3182 }
3183 if (TextOutList->GraphicsOutput != NULL) {
3184 Private->CurrentNumberOfGraphicsOutput--;
3185 }
3186 break;
3187 }
3188
3189 Index--;
3190 TextOutList++;
3191 }
3192 //
3193 // The specified TextOut is not managed by the ConSplitter driver
3194 //
3195 if (Index < 0) {
3196 return EFI_NOT_FOUND;
3197 }
3198
3199 if (CurrentNumOfConsoles == 0) {
3200 //
3201 // If the number of consoles is zero clear the Dev NULL device
3202 //
3203 Private->CurrentNumberOfConsoles = 0;
3204 Private->TextOutMode.MaxMode = 1;
3205 Private->TextOutQueryData[0].Columns = 80;
3206 Private->TextOutQueryData[0].Rows = 25;
3207 DevNullTextOutSetMode (Private, 0);
3208
3209 return EFI_SUCCESS;
3210 }
3211 //
3212 // Max Mode is realy an intersection of the QueryMode command to all
3213 // devices. So we must copy the QueryMode of the first device to
3214 // QueryData.
3215 //
3216 ZeroMem (
3217 Private->TextOutQueryData,
3218 Private->TextOutQueryDataCount * sizeof (TEXT_OUT_SPLITTER_QUERY_DATA)
3219 );
3220
3221 FreePool (Private->TextOutModeMap);
3222 Private->TextOutModeMap = NULL;
3223 TextOutList = Private->TextOutList;
3224
3225 //
3226 // Add the first TextOut to the QueryData array and ModeMap table
3227 //
3228 Status = ConSplitterAddOutputMode (Private, TextOutList->TextOut);
3229
3230 //
3231 // Now add one by one
3232 //
3233 Index = 1;
3234 Private->CurrentNumberOfConsoles = 1;
3235 TextOutList++;
3236 while ((UINTN) Index < CurrentNumOfConsoles) {
3237 ConSplitterSyncOutputMode (Private, TextOutList->TextOut);
3238 Index++;
3239 Private->CurrentNumberOfConsoles++;
3240 TextOutList++;
3241 }
3242
3243 ConSplitterGetIntersectionBetweenConOutAndStrErr ();
3244
3245 return Status;
3246 }
3247
3248
3249 /**
3250 Reset the input device and optionaly run diagnostics
3251
3252 @param This Protocol instance pointer.
3253 @param ExtendedVerification Driver may perform diagnostics on reset.
3254
3255 @retval EFI_SUCCESS The device was reset.
3256 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
3257 not be reset.
3258
3259 **/
3260 EFI_STATUS
3261 EFIAPI
3262 ConSplitterTextInReset (
3263 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
3264 IN BOOLEAN ExtendedVerification
3265 )
3266 {
3267 EFI_STATUS Status;
3268 EFI_STATUS ReturnStatus;
3269 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3270 UINTN Index;
3271
3272 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3273
3274 Private->KeyEventSignalState = FALSE;
3275
3276 //
3277 // return the worst status met
3278 //
3279 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
3280 Status = Private->TextInList[Index]->Reset (
3281 Private->TextInList[Index],
3282 ExtendedVerification
3283 );
3284 if (EFI_ERROR (Status)) {
3285 ReturnStatus = Status;
3286 }
3287 }
3288
3289 return ReturnStatus;
3290 }
3291
3292
3293 /**
3294 Reads the next keystroke from the input device. The WaitForKey Event can
3295 be used to test for existance of a keystroke via WaitForEvent () call.
3296
3297 @param Private Protocol instance pointer.
3298 @param Key Driver may perform diagnostics on reset.
3299
3300 @retval EFI_SUCCESS The keystroke information was returned.
3301 @retval EFI_NOT_READY There was no keystroke data availiable.
3302 @retval EFI_DEVICE_ERROR The keydtroke information was not returned due
3303 to hardware errors.
3304
3305 **/
3306 EFI_STATUS
3307 EFIAPI
3308 ConSplitterTextInPrivateReadKeyStroke (
3309 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
3310 OUT EFI_INPUT_KEY *Key
3311 )
3312 {
3313 EFI_STATUS Status;
3314 UINTN Index;
3315 EFI_INPUT_KEY CurrentKey;
3316
3317 Key->UnicodeChar = 0;
3318 Key->ScanCode = SCAN_NULL;
3319
3320 //
3321 // if no physical console input device exists, return EFI_NOT_READY;
3322 // if any physical console input device has key input,
3323 // return the key and EFI_SUCCESS.
3324 //
3325 for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {
3326 Status = Private->TextInList[Index]->ReadKeyStroke (
3327 Private->TextInList[Index],
3328 &CurrentKey
3329 );
3330 if (!EFI_ERROR (Status)) {
3331 *Key = CurrentKey;
3332 return Status;
3333 }
3334 }
3335
3336 return EFI_NOT_READY;
3337 }
3338
3339 /**
3340 Return TRUE if StdIn is locked. The ConIn device on the virtual handle is
3341 the only device locked.
3342
3343 @retval TRUE StdIn locked
3344 @retval FALSE StdIn working normally
3345
3346 **/
3347 BOOLEAN
3348 ConSpliterConssoleControlStdInLocked (
3349 VOID
3350 )
3351 {
3352 return mConIn.PasswordEnabled;
3353 }
3354
3355
3356 /**
3357 This timer event will fire when StdIn is locked. It will check the key
3358 sequence on StdIn to see if it matches the password. Any error in the
3359 password will cause the check to reset. As long a mConIn.PasswordEnabled is
3360 TRUE the StdIn splitter will not report any input.
3361
3362 @param Event The Event this notify function registered to.
3363 @param Context Pointer to the context data registerd to the
3364 Event.
3365 **/
3366 VOID
3367 EFIAPI
3368 ConSpliterConsoleControlLockStdInEvent (
3369 IN EFI_EVENT Event,
3370 IN VOID *Context
3371 )
3372 {
3373 EFI_STATUS Status;
3374 EFI_INPUT_KEY Key;
3375 CHAR16 BackSpaceString[2];
3376 CHAR16 SpaceString[2];
3377
3378 do {
3379 Status = ConSplitterTextInPrivateReadKeyStroke (&mConIn, &Key);
3380 if (!EFI_ERROR (Status)) {
3381 //
3382 // if it's an ENTER, match password
3383 //
3384 if ((Key.UnicodeChar == CHAR_CARRIAGE_RETURN) && (Key.ScanCode == SCAN_NULL)) {
3385 mConIn.PwdAttempt[mConIn.PwdIndex] = CHAR_NULL;
3386 if (StrCmp (mConIn.Password, mConIn.PwdAttempt)) {
3387 //
3388 // Password not match
3389 //
3390 ConSplitterTextOutOutputString (&mConOut.TextOut, (CHAR16 *) L"\n\rPassword not correct\n\r");
3391 mConIn.PwdIndex = 0;
3392 } else {
3393 //
3394 // Key matches password sequence
3395 //
3396 gBS->SetTimer (mConIn.LockEvent, TimerPeriodic, 0);
3397 mConIn.PasswordEnabled = FALSE;
3398 Status = EFI_NOT_READY;
3399 }
3400 } else if ((Key.UnicodeChar == CHAR_BACKSPACE) && (Key.ScanCode == SCAN_NULL)) {
3401 //
3402 // BackSpace met
3403 //
3404 if (mConIn.PwdIndex > 0) {
3405 BackSpaceString[0] = CHAR_BACKSPACE;
3406 BackSpaceString[1] = 0;
3407
3408 SpaceString[0] = L' ';
3409 SpaceString[1] = 0;
3410
3411 ConSplitterTextOutOutputString (&mConOut.TextOut, BackSpaceString);
3412 ConSplitterTextOutOutputString (&mConOut.TextOut, SpaceString);
3413 ConSplitterTextOutOutputString (&mConOut.TextOut, BackSpaceString);
3414
3415 mConIn.PwdIndex--;
3416 }
3417 } else if ((Key.ScanCode == SCAN_NULL) && (Key.UnicodeChar >= 32)) {
3418 //
3419 // If it's not an ENTER, neigher a function key, nor a CTRL-X or ALT-X, record the input
3420 //
3421 if (mConIn.PwdIndex < (MAX_STD_IN_PASSWORD - 1)) {
3422 if (mConIn.PwdIndex == 0) {
3423 ConSplitterTextOutOutputString (&mConOut.TextOut, (CHAR16 *) L"\n\r");
3424 }
3425
3426 ConSplitterTextOutOutputString (&mConOut.TextOut, (CHAR16 *) L"*");
3427 mConIn.PwdAttempt[mConIn.PwdIndex] = Key.UnicodeChar;
3428 mConIn.PwdIndex++;
3429 }
3430 }
3431 }
3432 } while (!EFI_ERROR (Status));
3433 }
3434
3435
3436 /**
3437 If Password is NULL or the Password is too big, then return an error. If the
3438 Password is valid, then store the password, lock StdIn and arm the periodic timer.
3439
3440 @param This Console Control protocol pointer.
3441 @param Password The password input.
3442
3443 @retval EFI_SUCCESS Lock the StdIn device
3444 @retval EFI_INVALID_PARAMETER Password is NULL
3445 @retval EFI_OUT_OF_RESOURCES Buffer allocation to store the password fails
3446
3447 **/
3448 EFI_STATUS
3449 EFIAPI
3450 ConSpliterConsoleControlLockStdIn (
3451 IN EFI_CONSOLE_CONTROL_PROTOCOL *This,
3452 IN CHAR16 *Password
3453 )
3454 {
3455 if (Password == NULL) {
3456 return EFI_INVALID_PARAMETER;
3457 }
3458
3459 if (StrLen (Password) >= MAX_STD_IN_PASSWORD) {
3460 //
3461 // Currently have a max password size
3462 //
3463 return EFI_OUT_OF_RESOURCES;
3464 }
3465 //
3466 // Save the password, initialize state variables and arm event timer
3467 //
3468 StrCpy (mConIn.Password, Password);
3469 mConIn.PasswordEnabled = TRUE;
3470 mConIn.PwdIndex = 0;
3471 gBS->SetTimer (mConIn.LockEvent, TimerPeriodic, (10000 * 25));
3472
3473 return EFI_SUCCESS;
3474 }
3475
3476
3477 /**
3478 Reads the next keystroke from the input device. The WaitForKey Event can
3479 be used to test for existance of a keystroke via WaitForEvent () call.
3480 If the ConIn is password locked make it look like no keystroke is availible
3481
3482 @param This Protocol instance pointer.
3483 @param Key Driver may perform diagnostics on reset.
3484
3485 @retval EFI_SUCCESS The keystroke information was returned.
3486 @retval EFI_NOT_READY There was no keystroke data availiable.
3487 @retval EFI_DEVICE_ERROR The keydtroke information was not returned due
3488 to hardware errors.
3489
3490 **/
3491 EFI_STATUS
3492 EFIAPI
3493 ConSplitterTextInReadKeyStroke (
3494 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
3495 OUT EFI_INPUT_KEY *Key
3496 )
3497 {
3498 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3499
3500 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3501 if (Private->PasswordEnabled) {
3502 //
3503 // If StdIn Locked return not ready
3504 //
3505 return EFI_NOT_READY;
3506 }
3507
3508 Private->KeyEventSignalState = FALSE;
3509
3510 return ConSplitterTextInPrivateReadKeyStroke (Private, Key);
3511 }
3512
3513
3514 /**
3515 This event agregates all the events of the ConIn devices in the spliter.
3516 If the ConIn is password locked then return.
3517 If any events of physical ConIn devices are signaled, signal the ConIn
3518 spliter event. This will cause the calling code to call
3519 ConSplitterTextInReadKeyStroke ().
3520
3521 @param Event The Event assoicated with callback.
3522 @param Context Context registered when Event was created.
3523
3524 **/
3525 VOID
3526 EFIAPI
3527 ConSplitterTextInWaitForKey (
3528 IN EFI_EVENT Event,
3529 IN VOID *Context
3530 )
3531 {
3532 EFI_STATUS Status;
3533 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3534 UINTN Index;
3535
3536 Private = (TEXT_IN_SPLITTER_PRIVATE_DATA *) Context;
3537 if (Private->PasswordEnabled) {
3538 //
3539 // If StdIn Locked return not ready
3540 //
3541 return ;
3542 }
3543
3544 //
3545 // if KeyEventSignalState is flagged before, and not cleared by Reset() or ReadKeyStroke()
3546 //
3547 if (Private->KeyEventSignalState) {
3548 gBS->SignalEvent (Event);
3549 return ;
3550 }
3551 //
3552 // if any physical console input device has key input, signal the event.
3553 //
3554 for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {
3555 Status = gBS->CheckEvent (Private->TextInList[Index]->WaitForKey);
3556 if (!EFI_ERROR (Status)) {
3557 gBS->SignalEvent (Event);
3558 Private->KeyEventSignalState = TRUE;
3559 }
3560 }
3561 }
3562
3563
3564
3565 /**
3566 Test if the key has been registered on input device.
3567
3568 @param RegsiteredData A pointer to a buffer that is filled in with the
3569 keystroke state data for the key that was
3570 registered.
3571 @param InputData A pointer to a buffer that is filled in with the
3572 keystroke state data for the key that was
3573 pressed.
3574
3575 @retval TRUE Key be pressed matches a registered key.
3576 @retval FLASE Match failed.
3577
3578 **/
3579 BOOLEAN
3580 IsKeyRegistered (
3581 IN EFI_KEY_DATA *RegsiteredData,
3582 IN EFI_KEY_DATA *InputData
3583 )
3584 {
3585 ASSERT (RegsiteredData != NULL && InputData != NULL);
3586
3587 if ((RegsiteredData->Key.ScanCode != InputData->Key.ScanCode) ||
3588 (RegsiteredData->Key.UnicodeChar != InputData->Key.UnicodeChar)) {
3589 return FALSE;
3590 }
3591
3592 //
3593 // Assume KeyShiftState/KeyToggleState = 0 in Registered key data means these state could be ignored.
3594 //
3595 if (RegsiteredData->KeyState.KeyShiftState != 0 &&
3596 RegsiteredData->KeyState.KeyShiftState != InputData->KeyState.KeyShiftState) {
3597 return FALSE;
3598 }
3599 if (RegsiteredData->KeyState.KeyToggleState != 0 &&
3600 RegsiteredData->KeyState.KeyToggleState != InputData->KeyState.KeyToggleState) {
3601 return FALSE;
3602 }
3603
3604 return TRUE;
3605
3606 }
3607
3608
3609 /**
3610 Reset the input device and optionaly run diagnostics
3611
3612 @param This Protocol instance pointer.
3613 @param ExtendedVerification Driver may perform diagnostics on reset.
3614
3615 @retval EFI_SUCCESS The device was reset.
3616 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
3617 not be reset.
3618
3619 **/
3620 EFI_STATUS
3621 EFIAPI
3622 ConSplitterTextInResetEx (
3623 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
3624 IN BOOLEAN ExtendedVerification
3625 )
3626 {
3627 EFI_STATUS Status;
3628 EFI_STATUS ReturnStatus;
3629 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3630 UINTN Index;
3631
3632 Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3633
3634 Private->KeyEventSignalState = FALSE;
3635
3636 //
3637 // return the worst status met
3638 //
3639 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfExConsoles; Index++) {
3640 Status = Private->TextInExList[Index]->Reset (
3641 Private->TextInExList[Index],
3642 ExtendedVerification
3643 );
3644 if (EFI_ERROR (Status)) {
3645 ReturnStatus = Status;
3646 }
3647 }
3648
3649 return ReturnStatus;
3650
3651 }
3652
3653
3654 /**
3655 Reads the next keystroke from the input device. The WaitForKey Event can
3656 be used to test for existance of a keystroke via WaitForEvent () call.
3657
3658 @param This Protocol instance pointer.
3659 @param KeyData A pointer to a buffer that is filled in with the
3660 keystroke state data for the key that was
3661 pressed.
3662
3663 @retval EFI_SUCCESS The keystroke information was returned.
3664 @retval EFI_NOT_READY There was no keystroke data availiable.
3665 @retval EFI_DEVICE_ERROR The keystroke information was not returned due
3666 to hardware errors.
3667 @retval EFI_INVALID_PARAMETER KeyData is NULL.
3668
3669 **/
3670 EFI_STATUS
3671 EFIAPI
3672 ConSplitterTextInReadKeyStrokeEx (
3673 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
3674 OUT EFI_KEY_DATA *KeyData
3675 )
3676 {
3677 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3678 EFI_STATUS Status;
3679 UINTN Index;
3680 EFI_KEY_DATA CurrentKeyData;
3681
3682
3683 if (KeyData == NULL) {
3684 return EFI_INVALID_PARAMETER;
3685 }
3686
3687 Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3688 if (Private->PasswordEnabled) {
3689 //
3690 // If StdIn Locked return not ready
3691 //
3692 return EFI_NOT_READY;
3693 }
3694
3695 Private->KeyEventSignalState = FALSE;
3696
3697 KeyData->Key.UnicodeChar = 0;
3698 KeyData->Key.ScanCode = SCAN_NULL;
3699
3700 //
3701 // if no physical console input device exists, return EFI_NOT_READY;
3702 // if any physical console input device has key input,
3703 // return the key and EFI_SUCCESS.
3704 //
3705 for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {
3706 Status = Private->TextInExList[Index]->ReadKeyStrokeEx (
3707 Private->TextInExList[Index],
3708 &CurrentKeyData
3709 );
3710 if (!EFI_ERROR (Status)) {
3711 CopyMem (KeyData, &CurrentKeyData, sizeof (CurrentKeyData));
3712 return Status;
3713 }
3714 }
3715
3716 return EFI_NOT_READY;
3717 }
3718
3719
3720 /**
3721 Set certain state for the input device.
3722
3723 @param This Protocol instance pointer.
3724 @param KeyToggleState A pointer to the EFI_KEY_TOGGLE_STATE to set the
3725 state for the input device.
3726
3727 @retval EFI_SUCCESS The device state was set successfully.
3728 @retval EFI_DEVICE_ERROR The device is not functioning correctly and
3729 could not have the setting adjusted.
3730 @retval EFI_UNSUPPORTED The device does not have the ability to set its
3731 state.
3732 @retval EFI_INVALID_PARAMETER KeyToggleState is NULL.
3733
3734 **/
3735 EFI_STATUS
3736 EFIAPI
3737 ConSplitterTextInSetState (
3738 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
3739 IN EFI_KEY_TOGGLE_STATE *KeyToggleState
3740 )
3741 {
3742 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3743 EFI_STATUS Status;
3744 UINTN Index;
3745
3746 if (KeyToggleState == NULL) {
3747 return EFI_INVALID_PARAMETER;
3748 }
3749
3750 Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3751
3752 //
3753 // if no physical console input device exists, return EFI_SUCCESS;
3754 // otherwise return the status of setting state of physical console input device
3755 //
3756 for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {
3757 Status = Private->TextInExList[Index]->SetState (
3758 Private->TextInExList[Index],
3759 KeyToggleState
3760 );
3761 if (EFI_ERROR (Status)) {
3762 return Status;
3763 }
3764 }
3765
3766 return EFI_SUCCESS;
3767
3768 }
3769
3770
3771 /**
3772 Register a notification function for a particular keystroke for the input device.
3773
3774 @param This Protocol instance pointer.
3775 @param KeyData A pointer to a buffer that is filled in with the
3776 keystroke information data for the key that was
3777 pressed.
3778 @param KeyNotificationFunction Points to the function to be called when the key
3779 sequence is typed specified by KeyData.
3780 @param NotifyHandle Points to the unique handle assigned to the
3781 registered notification.
3782
3783 @retval EFI_SUCCESS The notification function was registered
3784 successfully.
3785 @retval EFI_OUT_OF_RESOURCES Unable to allocate resources for necesssary data
3786 structures.
3787 @retval EFI_INVALID_PARAMETER KeyData or NotifyHandle is NULL.
3788
3789 **/
3790 EFI_STATUS
3791 EFIAPI
3792 ConSplitterTextInRegisterKeyNotify (
3793 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
3794 IN EFI_KEY_DATA *KeyData,
3795 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction,
3796 OUT EFI_HANDLE *NotifyHandle
3797 )
3798 {
3799 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3800 EFI_STATUS Status;
3801 UINTN Index;
3802 TEXT_IN_EX_SPLITTER_NOTIFY *NewNotify;
3803 LIST_ENTRY *Link;
3804 TEXT_IN_EX_SPLITTER_NOTIFY *CurrentNotify;
3805
3806
3807 if (KeyData == NULL || NotifyHandle == NULL || KeyNotificationFunction == NULL) {
3808 return EFI_INVALID_PARAMETER;
3809 }
3810
3811 Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3812
3813 //
3814 // if no physical console input device exists,
3815 // return EFI_SUCCESS directly.
3816 //
3817 if (Private->CurrentNumberOfExConsoles <= 0) {
3818 return EFI_SUCCESS;
3819 }
3820
3821 //
3822 // Return EFI_SUCCESS if the (KeyData, NotificationFunction) is already registered.
3823 //
3824 for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {
3825 CurrentNotify = TEXT_IN_EX_SPLITTER_NOTIFY_FROM_THIS (Link);
3826 if (IsKeyRegistered (&CurrentNotify->KeyData, KeyData)) {
3827 if (CurrentNotify->KeyNotificationFn == KeyNotificationFunction) {
3828 *NotifyHandle = CurrentNotify->NotifyHandle;
3829 return EFI_SUCCESS;
3830 }
3831 }
3832 }
3833
3834 //
3835 // Allocate resource to save the notification function
3836 //
3837 NewNotify = (TEXT_IN_EX_SPLITTER_NOTIFY *) AllocateZeroPool (sizeof (TEXT_IN_EX_SPLITTER_NOTIFY));
3838 if (NewNotify == NULL) {
3839 return EFI_OUT_OF_RESOURCES;
3840 }
3841 NewNotify->NotifyHandleList = (EFI_HANDLE *) AllocateZeroPool (sizeof (EFI_HANDLE) * Private->CurrentNumberOfExConsoles);
3842 if (NewNotify->NotifyHandleList == NULL) {
3843 gBS->FreePool (NewNotify);
3844 return EFI_OUT_OF_RESOURCES;
3845 }
3846 NewNotify->Signature = TEXT_IN_EX_SPLITTER_NOTIFY_SIGNATURE;
3847 NewNotify->KeyNotificationFn = KeyNotificationFunction;
3848 CopyMem (&NewNotify->KeyData, KeyData, sizeof (KeyData));
3849
3850 //
3851 // Return the wrong status of registering key notify of
3852 // physical console input device if meet problems
3853 //
3854 for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {
3855 Status = Private->TextInExList[Index]->RegisterKeyNotify (
3856 Private->TextInExList[Index],
3857 KeyData,
3858 KeyNotificationFunction,
3859 &NewNotify->NotifyHandleList[Index]
3860 );
3861 if (EFI_ERROR (Status)) {
3862 gBS->FreePool (NewNotify->NotifyHandleList);
3863 gBS->FreePool (NewNotify);
3864 return Status;
3865 }
3866 }
3867
3868 //
3869 // Use gSimpleTextInExNotifyGuid to get a valid EFI_HANDLE
3870 //
3871 Status = gBS->InstallMultipleProtocolInterfaces (
3872 &NewNotify->NotifyHandle,
3873 &gSimpleTextInExNotifyGuid,
3874 NULL,
3875 NULL
3876 );
3877 ASSERT_EFI_ERROR (Status);
3878
3879 InsertTailList (&mConIn.NotifyList, &NewNotify->NotifyEntry);
3880
3881 *NotifyHandle = NewNotify->NotifyHandle;
3882
3883 return EFI_SUCCESS;
3884
3885 }
3886
3887
3888 /**
3889 Remove a registered notification function from a particular keystroke.
3890
3891 @param This Protocol instance pointer.
3892 @param NotificationHandle The handle of the notification function being
3893 unregistered.
3894
3895 @retval EFI_SUCCESS The notification function was unregistered
3896 successfully.
3897 @retval EFI_INVALID_PARAMETER The NotificationHandle is invalid.
3898 @retval EFI_NOT_FOUND Can not find the matching entry in database.
3899
3900 **/
3901 EFI_STATUS
3902 EFIAPI
3903 ConSplitterTextInUnregisterKeyNotify (
3904 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
3905 IN EFI_HANDLE NotificationHandle
3906 )
3907 {
3908 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3909 EFI_STATUS Status;
3910 UINTN Index;
3911 TEXT_IN_EX_SPLITTER_NOTIFY *CurrentNotify;
3912 LIST_ENTRY *Link;
3913
3914 if (NotificationHandle == NULL) {
3915 return EFI_INVALID_PARAMETER;
3916 }
3917
3918 Status = gBS->OpenProtocol (
3919 NotificationHandle,
3920 &gSimpleTextInExNotifyGuid,
3921 NULL,
3922 NULL,
3923 NULL,
3924 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
3925 );
3926 if (EFI_ERROR (Status)) {
3927 return EFI_INVALID_PARAMETER;
3928 }
3929
3930 Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3931
3932 //
3933 // if no physical console input device exists,
3934 // return EFI_SUCCESS directly.
3935 //
3936 if (Private->CurrentNumberOfExConsoles <= 0) {
3937 return EFI_SUCCESS;
3938 }
3939
3940 for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {
3941 CurrentNotify = TEXT_IN_EX_SPLITTER_NOTIFY_FROM_THIS (Link);
3942 if (CurrentNotify->NotifyHandle == NotificationHandle) {
3943 for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {
3944 Status = Private->TextInExList[Index]->UnregisterKeyNotify (
3945 Private->TextInExList[Index],
3946 CurrentNotify->NotifyHandleList[Index]
3947 );
3948 if (EFI_ERROR (Status)) {
3949 return Status;
3950 }
3951 }
3952 RemoveEntryList (&CurrentNotify->NotifyEntry);
3953 Status = gBS->UninstallMultipleProtocolInterfaces (
3954 CurrentNotify->NotifyHandle,
3955 &gSimpleTextInExNotifyGuid,
3956 NULL,
3957 NULL
3958 );
3959 ASSERT_EFI_ERROR (Status);
3960 gBS->FreePool (CurrentNotify->NotifyHandleList);
3961 gBS->FreePool (CurrentNotify);
3962 return EFI_SUCCESS;
3963 }
3964 }
3965
3966 return EFI_NOT_FOUND;
3967
3968 }
3969
3970
3971 /**
3972 Reset the input device and optionaly run diagnostics
3973
3974 @param This Protocol instance pointer.
3975 @param ExtendedVerification Driver may perform diagnostics on reset.
3976
3977 @retval EFI_SUCCESS The device was reset.
3978 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
3979 not be reset.
3980
3981 **/
3982 EFI_STATUS
3983 EFIAPI
3984 ConSplitterSimplePointerReset (
3985 IN EFI_SIMPLE_POINTER_PROTOCOL *This,
3986 IN BOOLEAN ExtendedVerification
3987 )
3988 {
3989 EFI_STATUS Status;
3990 EFI_STATUS ReturnStatus;
3991 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3992 UINTN Index;
3993
3994 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_SIMPLE_POINTER_THIS (This);
3995
3996 Private->InputEventSignalState = FALSE;
3997
3998 if (Private->CurrentNumberOfPointers == 0) {
3999 return EFI_SUCCESS;
4000 }
4001 //
4002 // return the worst status met
4003 //
4004 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfPointers; Index++) {
4005 Status = Private->PointerList[Index]->Reset (
4006 Private->PointerList[Index],
4007 ExtendedVerification
4008 );
4009 if (EFI_ERROR (Status)) {
4010 ReturnStatus = Status;
4011 }
4012 }
4013
4014 return ReturnStatus;
4015 }
4016
4017
4018 /**
4019 Reads the next keystroke from the input device. The WaitForKey Event can
4020 be used to test for existance of a keystroke via WaitForEvent () call.
4021
4022 @param Private Protocol instance pointer.
4023 @param State The state information of simple pointer device.
4024
4025 @retval EFI_SUCCESS The keystroke information was returned.
4026 @retval EFI_NOT_READY There was no keystroke data availiable.
4027 @retval EFI_DEVICE_ERROR The keydtroke information was not returned due
4028 to hardware errors.
4029
4030 **/
4031 EFI_STATUS
4032 EFIAPI
4033 ConSplitterSimplePointerPrivateGetState (
4034 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
4035 IN OUT EFI_SIMPLE_POINTER_STATE *State
4036 )
4037 {
4038 EFI_STATUS Status;
4039 EFI_STATUS ReturnStatus;
4040 UINTN Index;
4041 EFI_SIMPLE_POINTER_STATE CurrentState;
4042
4043 State->RelativeMovementX = 0;
4044 State->RelativeMovementY = 0;
4045 State->RelativeMovementZ = 0;
4046 State->LeftButton = FALSE;
4047 State->RightButton = FALSE;
4048
4049 //
4050 // if no physical console input device exists, return EFI_NOT_READY;
4051 // if any physical console input device has key input,
4052 // return the key and EFI_SUCCESS.
4053 //
4054 ReturnStatus = EFI_NOT_READY;
4055 for (Index = 0; Index < Private->CurrentNumberOfPointers; Index++) {
4056
4057 Status = Private->PointerList[Index]->GetState (
4058 Private->PointerList[Index],
4059 &CurrentState
4060 );
4061 if (!EFI_ERROR (Status)) {
4062 if (ReturnStatus == EFI_NOT_READY) {
4063 ReturnStatus = EFI_SUCCESS;
4064 }
4065
4066 if (CurrentState.LeftButton) {
4067 State->LeftButton = TRUE;
4068 }
4069
4070 if (CurrentState.RightButton) {
4071 State->RightButton = TRUE;
4072 }
4073
4074 if (CurrentState.RelativeMovementX != 0 && Private->PointerList[Index]->Mode->ResolutionX != 0) {
4075 State->RelativeMovementX += (CurrentState.RelativeMovementX * (INT32) Private->SimplePointerMode.ResolutionX) / (INT32) Private->PointerList[Index]->Mode->ResolutionX;
4076 }
4077
4078 if (CurrentState.RelativeMovementY != 0 && Private->PointerList[Index]->Mode->ResolutionY != 0) {
4079 State->RelativeMovementY += (CurrentState.RelativeMovementY * (INT32) Private->SimplePointerMode.ResolutionY) / (INT32) Private->PointerList[Index]->Mode->ResolutionY;
4080 }
4081
4082 if (CurrentState.RelativeMovementZ != 0 && Private->PointerList[Index]->Mode->ResolutionZ != 0) {
4083 State->RelativeMovementZ += (CurrentState.RelativeMovementZ * (INT32) Private->SimplePointerMode.ResolutionZ) / (INT32) Private->PointerList[Index]->Mode->ResolutionZ;
4084 }
4085 } else if (Status == EFI_DEVICE_ERROR) {
4086 ReturnStatus = EFI_DEVICE_ERROR;
4087 }
4088 }
4089
4090 return ReturnStatus;
4091 }
4092
4093
4094 /**
4095 Reads the next keystroke from the input device. The WaitForKey Event can
4096 be used to test for existance of a keystroke via WaitForEvent () call.
4097 If the ConIn is password locked make it look like no keystroke is availible
4098
4099 @param This A pointer to protocol instance.
4100 @param State A pointer to state information on the pointer device
4101
4102 @retval EFI_SUCCESS The keystroke information was returned in State.
4103 @retval EFI_NOT_READY There was no keystroke data availiable.
4104 @retval EFI_DEVICE_ERROR The keydtroke information was not returned due
4105 to hardware errors.
4106
4107 **/
4108 EFI_STATUS
4109 EFIAPI
4110 ConSplitterSimplePointerGetState (
4111 IN EFI_SIMPLE_POINTER_PROTOCOL *This,
4112 IN OUT EFI_SIMPLE_POINTER_STATE *State
4113 )
4114 {
4115 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
4116
4117 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_SIMPLE_POINTER_THIS (This);
4118 if (Private->PasswordEnabled) {
4119 //
4120 // If StdIn Locked return not ready
4121 //
4122 return EFI_NOT_READY;
4123 }
4124
4125 Private->InputEventSignalState = FALSE;
4126
4127 return ConSplitterSimplePointerPrivateGetState (Private, State);
4128 }
4129
4130
4131 /**
4132 This event agregates all the events of the ConIn devices in the spliter.
4133 If the ConIn is password locked then return.
4134 If any events of physical ConIn devices are signaled, signal the ConIn
4135 spliter event. This will cause the calling code to call
4136 ConSplitterTextInReadKeyStroke ().
4137
4138 @param Event The Event assoicated with callback.
4139 @param Context Context registered when Event was created.
4140
4141 **/
4142 VOID
4143 EFIAPI
4144 ConSplitterSimplePointerWaitForInput (
4145 IN EFI_EVENT Event,
4146 IN VOID *Context
4147 )
4148 {
4149 EFI_STATUS Status;
4150 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
4151 UINTN Index;
4152
4153 Private = (TEXT_IN_SPLITTER_PRIVATE_DATA *) Context;
4154 if (Private->PasswordEnabled) {
4155 //
4156 // If StdIn Locked return not ready
4157 //
4158 return ;
4159 }
4160
4161 //
4162 // if InputEventSignalState is flagged before, and not cleared by Reset() or ReadKeyStroke()
4163 //
4164 if (Private->InputEventSignalState) {
4165 gBS->SignalEvent (Event);
4166 return ;
4167 }
4168 //
4169 // if any physical console input device has key input, signal the event.
4170 //
4171 for (Index = 0; Index < Private->CurrentNumberOfPointers; Index++) {
4172 Status = gBS->CheckEvent (Private->PointerList[Index]->WaitForInput);
4173 if (!EFI_ERROR (Status)) {
4174 gBS->SignalEvent (Event);
4175 Private->InputEventSignalState = TRUE;
4176 }
4177 }
4178 }
4179
4180 /**
4181 Resets the pointer device hardware.
4182
4183 @param This Protocol instance pointer.
4184 @param ExtendedVerification Driver may perform diagnostics on reset.
4185
4186 @retval EFI_SUCCESS The device was reset.
4187 @retval EFI_DEVICE_ERROR The device is not functioning correctly and
4188 could not be reset.
4189
4190 **/
4191 EFI_STATUS
4192 EFIAPI
4193 ConSplitterAbsolutePointerReset (
4194 IN EFI_ABSOLUTE_POINTER_PROTOCOL *This,
4195 IN BOOLEAN ExtendedVerification
4196 )
4197 {
4198 EFI_STATUS Status;
4199 EFI_STATUS ReturnStatus;
4200 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
4201 UINTN Index;
4202
4203 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_ABSOLUTE_POINTER_THIS (This);
4204
4205 Private->AbsoluteInputEventSignalState = FALSE;
4206
4207 if (Private->CurrentNumberOfAbsolutePointers == 0) {
4208 return EFI_SUCCESS;
4209 }
4210 //
4211 // return the worst status met
4212 //
4213 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfAbsolutePointers; Index++) {
4214 Status = Private->AbsolutePointerList[Index]->Reset (
4215 Private->AbsolutePointerList[Index],
4216 ExtendedVerification
4217 );
4218 if (EFI_ERROR (Status)) {
4219 ReturnStatus = Status;
4220 }
4221 }
4222
4223 return ReturnStatus;
4224 }
4225
4226
4227 /**
4228 Retrieves the current state of a pointer device.
4229
4230 @param This Protocol instance pointer.
4231 @param State A pointer to the state information on the
4232 pointer device.
4233
4234 @retval EFI_SUCCESS The state of the pointer device was returned in
4235 State..
4236 @retval EFI_NOT_READY The state of the pointer device has not changed
4237 since the last call to GetState().
4238 @retval EFI_DEVICE_ERROR A device error occurred while attempting to
4239 retrieve the pointer device's current state.
4240
4241 **/
4242 EFI_STATUS
4243 EFIAPI
4244 ConSplitterAbsolutePointerGetState (
4245 IN EFI_ABSOLUTE_POINTER_PROTOCOL *This,
4246 IN OUT EFI_ABSOLUTE_POINTER_STATE *State
4247 )
4248 {
4249 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
4250 EFI_STATUS Status;
4251 EFI_STATUS ReturnStatus;
4252 UINTN Index;
4253 EFI_ABSOLUTE_POINTER_STATE CurrentState;
4254
4255
4256 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_ABSOLUTE_POINTER_THIS (This);
4257 if (Private->PasswordEnabled) {
4258 //
4259 // If StdIn Locked return not ready
4260 //
4261 return EFI_NOT_READY;
4262 }
4263
4264 Private->AbsoluteInputEventSignalState = FALSE;
4265
4266 State->CurrentX = 0;
4267 State->CurrentY = 0;
4268 State->CurrentZ = 0;
4269 State->ActiveButtons = 0;
4270
4271 //
4272 // if no physical pointer device exists, return EFI_NOT_READY;
4273 // if any physical pointer device has changed state,
4274 // return the state and EFI_SUCCESS.
4275 //
4276 ReturnStatus = EFI_NOT_READY;
4277 for (Index = 0; Index < Private->CurrentNumberOfAbsolutePointers; Index++) {
4278
4279 Status = Private->AbsolutePointerList[Index]->GetState (
4280 Private->AbsolutePointerList[Index],
4281 &CurrentState
4282 );
4283 if (!EFI_ERROR (Status)) {
4284 if (ReturnStatus == EFI_NOT_READY) {
4285 ReturnStatus = EFI_SUCCESS;
4286 }
4287
4288 State->ActiveButtons = CurrentState.ActiveButtons;
4289
4290 if (!(Private->AbsolutePointerMode.AbsoluteMinX == 0 && Private->AbsolutePointerMode.AbsoluteMaxX == 0)) {
4291 State->CurrentX = CurrentState.CurrentX;
4292 }
4293 if (!(Private->AbsolutePointerMode.AbsoluteMinY == 0 && Private->AbsolutePointerMode.AbsoluteMaxY == 0)) {
4294 State->CurrentY = CurrentState.CurrentY;
4295 }
4296 if (!(Private->AbsolutePointerMode.AbsoluteMinZ == 0 && Private->AbsolutePointerMode.AbsoluteMaxZ == 0)) {
4297 State->CurrentZ = CurrentState.CurrentZ;
4298 }
4299
4300 } else if (Status == EFI_DEVICE_ERROR) {
4301 ReturnStatus = EFI_DEVICE_ERROR;
4302 }
4303 }
4304
4305 return ReturnStatus;
4306 }
4307
4308
4309 /**
4310 This event agregates all the events of the pointer devices in the splitter.
4311 If the ConIn is password locked then return.
4312 If any events of physical pointer devices are signaled, signal the pointer
4313 splitter event. This will cause the calling code to call
4314 ConSplitterAbsolutePointerGetState ().
4315
4316 @param Event The Event assoicated with callback.
4317 @param Context Context registered when Event was created.
4318
4319 **/
4320 VOID
4321 EFIAPI
4322 ConSplitterAbsolutePointerWaitForInput (
4323 IN EFI_EVENT Event,
4324 IN VOID *Context
4325 )
4326 {
4327 EFI_STATUS Status;
4328 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
4329 UINTN Index;
4330
4331 Private = (TEXT_IN_SPLITTER_PRIVATE_DATA *) Context;
4332 if (Private->PasswordEnabled) {
4333 //
4334 // If StdIn Locked return not ready
4335 //
4336 return ;
4337 }
4338
4339 //
4340 // if AbsoluteInputEventSignalState is flagged before,
4341 // and not cleared by Reset() or GetState(), signal it
4342 //
4343 if (Private->AbsoluteInputEventSignalState) {
4344 gBS->SignalEvent (Event);
4345 return ;
4346 }
4347 //
4348 // if any physical console input device has key input, signal the event.
4349 //
4350 for (Index = 0; Index < Private->CurrentNumberOfAbsolutePointers; Index++) {
4351 Status = gBS->CheckEvent (Private->AbsolutePointerList[Index]->WaitForInput);
4352 if (!EFI_ERROR (Status)) {
4353 gBS->SignalEvent (Event);
4354 Private->AbsoluteInputEventSignalState = TRUE;
4355 }
4356 }
4357 }
4358
4359
4360 /**
4361 Reset the text output device hardware and optionaly run diagnostics
4362
4363 @param This Protocol instance pointer.
4364 @param ExtendedVerification Driver may perform more exhaustive verfication
4365 operation of the device during reset.
4366
4367 @retval EFI_SUCCESS The text output device was reset.
4368 @retval EFI_DEVICE_ERROR The text output device is not functioning
4369 correctly and could not be reset.
4370
4371 **/
4372 EFI_STATUS
4373 EFIAPI
4374 ConSplitterTextOutReset (
4375 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4376 IN BOOLEAN ExtendedVerification
4377 )
4378 {
4379 EFI_STATUS Status;
4380 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4381 UINTN Index;
4382 EFI_STATUS ReturnStatus;
4383
4384 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4385
4386 //
4387 // return the worst status met
4388 //
4389 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4390
4391 if (Private->TextOutList[Index].TextOutEnabled) {
4392
4393 Status = Private->TextOutList[Index].TextOut->Reset (
4394 Private->TextOutList[Index].TextOut,
4395 ExtendedVerification
4396 );
4397 if (EFI_ERROR (Status)) {
4398 ReturnStatus = Status;
4399 }
4400 }
4401 }
4402
4403 This->SetAttribute (This, EFI_TEXT_ATTR (This->Mode->Attribute & 0x0F, EFI_BLACK));
4404
4405 Status = DevNullTextOutSetMode (Private, 0);
4406 if (EFI_ERROR (Status)) {
4407 ReturnStatus = Status;
4408 }
4409
4410 return ReturnStatus;
4411 }
4412
4413
4414 /**
4415 Write a Unicode string to the output device.
4416
4417 @param This Protocol instance pointer.
4418 @param WString The NULL-terminated Unicode string to be
4419 displayed on the output device(s). All output
4420 devices must also support the Unicode drawing
4421 defined in this file.
4422
4423 @retval EFI_SUCCESS The string was output to the device.
4424 @retval EFI_DEVICE_ERROR The device reported an error while attempting to
4425 output the text.
4426 @retval EFI_UNSUPPORTED The output device's mode is not currently in a
4427 defined text mode.
4428 @retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the
4429 characters in the Unicode string could not be
4430 rendered and were skipped.
4431
4432 **/
4433 EFI_STATUS
4434 EFIAPI
4435 ConSplitterTextOutOutputString (
4436 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4437 IN CHAR16 *WString
4438 )
4439 {
4440 EFI_STATUS Status;
4441 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4442 UINTN Index;
4443 UINTN BackSpaceCount;
4444 EFI_STATUS ReturnStatus;
4445 CHAR16 *TargetString;
4446
4447 This->SetAttribute (This, This->Mode->Attribute);
4448
4449 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4450
4451 BackSpaceCount = 0;
4452 for (TargetString = WString; *TargetString != L'\0'; TargetString++) {
4453 if (*TargetString == CHAR_BACKSPACE) {
4454 BackSpaceCount++;
4455 }
4456
4457 }
4458
4459 if (BackSpaceCount == 0) {
4460 TargetString = WString;
4461 } else {
4462 TargetString = AllocatePool (sizeof (CHAR16) * (StrLen (WString) + BackSpaceCount + 1));
4463 StrCpy (TargetString, WString);
4464 }
4465 //
4466 // return the worst status met
4467 //
4468 Status = DevNullTextOutOutputString (Private, TargetString);
4469 if (EFI_ERROR (Status)) {
4470 ReturnStatus = Status;
4471 }
4472
4473 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4474
4475 if (Private->TextOutList[Index].TextOutEnabled) {
4476 Status = Private->TextOutList[Index].TextOut->OutputString (
4477 Private->TextOutList[Index].TextOut,
4478 TargetString
4479 );
4480 if (EFI_ERROR (Status)) {
4481 ReturnStatus = Status;
4482 }
4483 }
4484 }
4485
4486 if (BackSpaceCount > 0) {
4487 FreePool (TargetString);
4488 }
4489
4490 return ReturnStatus;
4491 }
4492
4493
4494 /**
4495 Verifies that all characters in a Unicode string can be output to the
4496 target device.
4497
4498 @param This Protocol instance pointer.
4499 @param WString The NULL-terminated Unicode string to be
4500 examined for the output device(s).
4501
4502 @retval EFI_SUCCESS The device(s) are capable of rendering the
4503 output string.
4504 @retval EFI_UNSUPPORTED Some of the characters in the Unicode string
4505 cannot be rendered by one or more of the output
4506 devices mapped by the EFI handle.
4507
4508 **/
4509 EFI_STATUS
4510 EFIAPI
4511 ConSplitterTextOutTestString (
4512 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4513 IN CHAR16 *WString
4514 )
4515 {
4516 EFI_STATUS Status;
4517 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4518 UINTN Index;
4519 EFI_STATUS ReturnStatus;
4520
4521 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4522
4523 //
4524 // return the worst status met
4525 //
4526 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4527 if (Private->TextOutList[Index].TextOutEnabled) {
4528 Status = Private->TextOutList[Index].TextOut->TestString (
4529 Private->TextOutList[Index].TextOut,
4530 WString
4531 );
4532 if (EFI_ERROR (Status)) {
4533 ReturnStatus = Status;
4534 }
4535 }
4536 }
4537 //
4538 // There is no DevNullTextOutTestString () since a Unicode buffer would
4539 // always return EFI_SUCCESS.
4540 // ReturnStatus will be EFI_SUCCESS if no consoles are present
4541 //
4542 return ReturnStatus;
4543 }
4544
4545
4546 /**
4547 Returns information for an available text mode that the output device(s)
4548 supports.
4549
4550 @param This Protocol instance pointer.
4551 @param ModeNumber The mode number to return information on.
4552 @param Columns Returns the columns of the text output device
4553 for the requested ModeNumber.
4554 @param Rows Returns the rows of the text output device
4555 for the requested ModeNumber.
4556
4557 @retval EFI_SUCCESS The requested mode information was returned.
4558 @retval EFI_DEVICE_ERROR The device had an error and could not complete
4559 the request.
4560 @retval EFI_UNSUPPORTED The mode number was not valid.
4561
4562 **/
4563 EFI_STATUS
4564 EFIAPI
4565 ConSplitterTextOutQueryMode (
4566 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4567 IN UINTN ModeNumber,
4568 OUT UINTN *Columns,
4569 OUT UINTN *Rows
4570 )
4571 {
4572 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4573 UINTN CurrentMode;
4574 INT32 *TextOutModeMap;
4575
4576 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4577
4578 //
4579 // Check whether param ModeNumber is valid.
4580 // ModeNumber should be within range 0 ~ MaxMode - 1.
4581 //
4582 if ( (ModeNumber > (UINTN)(((UINT32)-1)>>1)) ) {
4583 return EFI_UNSUPPORTED;
4584 }
4585
4586 if ((INT32) ModeNumber >= This->Mode->MaxMode) {
4587 return EFI_UNSUPPORTED;
4588 }
4589
4590 //
4591 // We get the available mode from mode intersection map if it's available
4592 //
4593 if (Private->TextOutModeMap != NULL) {
4594 TextOutModeMap = Private->TextOutModeMap + Private->TextOutListCount * ModeNumber;
4595 CurrentMode = (UINTN)(*TextOutModeMap);
4596 *Columns = Private->TextOutQueryData[CurrentMode].Columns;
4597 *Rows = Private->TextOutQueryData[CurrentMode].Rows;
4598 } else {
4599 *Columns = Private->TextOutQueryData[ModeNumber].Columns;
4600 *Rows = Private->TextOutQueryData[ModeNumber].Rows;
4601 }
4602
4603 if (*Columns <= 0 && *Rows <= 0) {
4604 return EFI_UNSUPPORTED;
4605
4606 }
4607
4608 return EFI_SUCCESS;
4609 }
4610
4611
4612 /**
4613 Sets the output device(s) to a specified mode.
4614
4615 @param This Protocol instance pointer.
4616 @param ModeNumber The mode number to set.
4617
4618 @retval EFI_SUCCESS The requested text mode was set.
4619 @retval EFI_DEVICE_ERROR The device had an error and could not complete
4620 the request.
4621 @retval EFI_UNSUPPORTED The mode number was not valid.
4622
4623 **/
4624 EFI_STATUS
4625 EFIAPI
4626 ConSplitterTextOutSetMode (
4627 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4628 IN UINTN ModeNumber
4629 )
4630 {
4631 EFI_STATUS Status;
4632 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4633 UINTN Index;
4634 INT32 *TextOutModeMap;
4635 EFI_STATUS ReturnStatus;
4636
4637 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4638
4639 //
4640 // Check whether param ModeNumber is valid.
4641 // ModeNumber should be within range 0 ~ MaxMode - 1.
4642 //
4643 if ( (ModeNumber > (UINTN)(((UINT32)-1)>>1)) ) {
4644 return EFI_UNSUPPORTED;
4645 }
4646
4647 if ((INT32) ModeNumber >= This->Mode->MaxMode) {
4648 return EFI_UNSUPPORTED;
4649 }
4650 //
4651 // If the mode is being set to the curent mode, then just clear the screen and return.
4652 //
4653 if (Private->TextOutMode.Mode == (INT32) ModeNumber) {
4654 return ConSplitterTextOutClearScreen (This);
4655 }
4656 //
4657 // return the worst status met
4658 //
4659 TextOutModeMap = Private->TextOutModeMap + Private->TextOutListCount * ModeNumber;
4660 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4661
4662 if (Private->TextOutList[Index].TextOutEnabled) {
4663 Status = Private->TextOutList[Index].TextOut->SetMode (
4664 Private->TextOutList[Index].TextOut,
4665 TextOutModeMap[Index]
4666 );
4667 //
4668 // If this console device is based on a GOP or UGA device, then sync up the bitmap from
4669 // the GOP/UGA splitter and reclear the text portion of the display in the new mode.
4670 //
4671 if ((Private->TextOutList[Index].GraphicsOutput != NULL) || (Private->TextOutList[Index].UgaDraw != NULL)) {
4672 Private->TextOutList[Index].TextOut->ClearScreen (Private->TextOutList[Index].TextOut);
4673 }
4674
4675 if (EFI_ERROR (Status)) {
4676 ReturnStatus = Status;
4677 }
4678 }
4679 }
4680 //
4681 // The DevNull Console will support any possible mode as it allocates memory
4682 //
4683 Status = DevNullTextOutSetMode (Private, ModeNumber);
4684 if (EFI_ERROR (Status)) {
4685 ReturnStatus = Status;
4686 }
4687
4688 return ReturnStatus;
4689 }
4690
4691
4692 /**
4693 Sets the background and foreground colors for the OutputString () and
4694 ClearScreen () functions.
4695
4696 @param This Protocol instance pointer.
4697 @param Attribute The attribute to set. Bits 0..3 are the
4698 foreground color, and bits 4..6 are the
4699 background color. All other bits are undefined
4700 and must be zero. The valid Attributes are
4701 defined in this file.
4702
4703 @retval EFI_SUCCESS The attribute was set.
4704 @retval EFI_DEVICE_ERROR The device had an error and could not complete
4705 the request.
4706 @retval EFI_UNSUPPORTED The attribute requested is not defined.
4707
4708 **/
4709 EFI_STATUS
4710 EFIAPI
4711 ConSplitterTextOutSetAttribute (
4712 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4713 IN UINTN Attribute
4714 )
4715 {
4716 EFI_STATUS Status;
4717 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4718 UINTN Index;
4719 EFI_STATUS ReturnStatus;
4720
4721 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4722
4723 //
4724 // Check whether param Attribute is valid.
4725 //
4726 if ( (Attribute > (UINTN)(((UINT32)-1)>>1)) ) {
4727 return EFI_UNSUPPORTED;
4728 }
4729
4730 //
4731 // return the worst status met
4732 //
4733 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4734
4735 if (Private->TextOutList[Index].TextOutEnabled) {
4736 Status = Private->TextOutList[Index].TextOut->SetAttribute (
4737 Private->TextOutList[Index].TextOut,
4738 Attribute
4739 );
4740 if (EFI_ERROR (Status)) {
4741 ReturnStatus = Status;
4742 }
4743 }
4744 }
4745
4746 Private->TextOutMode.Attribute = (INT32) Attribute;
4747
4748 return ReturnStatus;
4749 }
4750
4751
4752 /**
4753 Clears the output device(s) display to the currently selected background
4754 color.
4755
4756 @param This Protocol instance pointer.
4757
4758 @retval EFI_SUCCESS The operation completed successfully.
4759 @retval EFI_DEVICE_ERROR The device had an error and could not complete
4760 the request.
4761 @retval EFI_UNSUPPORTED The output device is not in a valid text mode.
4762
4763 **/
4764 EFI_STATUS
4765 EFIAPI
4766 ConSplitterTextOutClearScreen (
4767 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This
4768 )
4769 {
4770 EFI_STATUS Status;
4771 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4772 UINTN Index;
4773 EFI_STATUS ReturnStatus;
4774
4775 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4776
4777 //
4778 // return the worst status met
4779 //
4780 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4781
4782 if (Private->TextOutList[Index].TextOutEnabled) {
4783 Status = Private->TextOutList[Index].TextOut->ClearScreen (Private->TextOutList[Index].TextOut);
4784 if (EFI_ERROR (Status)) {
4785 ReturnStatus = Status;
4786 }
4787 }
4788 }
4789
4790 Status = DevNullTextOutClearScreen (Private);
4791 if (EFI_ERROR (Status)) {
4792 ReturnStatus = Status;
4793 }
4794
4795 return ReturnStatus;
4796 }
4797
4798
4799 /**
4800 Sets the current coordinates of the cursor position
4801
4802 @param This Protocol instance pointer.
4803 @param Column The column position to set the cursor to. Must be
4804 greater than or equal to zero and less than the
4805 number of columns by QueryMode ().
4806 @param Row The row position to set the cursor to. Must be
4807 greater than or equal to zero and less than the
4808 number of rows by QueryMode ().
4809
4810 @retval EFI_SUCCESS The operation completed successfully.
4811 @retval EFI_DEVICE_ERROR The device had an error and could not complete
4812 the request.
4813 @retval EFI_UNSUPPORTED The output device is not in a valid text mode,
4814 or the cursor position is invalid for the
4815 current mode.
4816
4817 **/
4818 EFI_STATUS
4819 EFIAPI
4820 ConSplitterTextOutSetCursorPosition (
4821 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4822 IN UINTN Column,
4823 IN UINTN Row
4824 )
4825 {
4826 EFI_STATUS Status;
4827 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4828 UINTN Index;
4829 EFI_STATUS ReturnStatus;
4830 UINTN MaxColumn;
4831 UINTN MaxRow;
4832 INT32 *TextOutModeMap;
4833 INT32 ModeNumber;
4834 INT32 CurrentMode;
4835
4836 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4837 TextOutModeMap = NULL;
4838 ModeNumber = Private->TextOutMode.Mode;
4839
4840 //
4841 // Get current MaxColumn and MaxRow from intersection map
4842 //
4843 if (Private->TextOutModeMap != NULL) {
4844 TextOutModeMap = Private->TextOutModeMap + Private->TextOutListCount * ModeNumber;
4845 CurrentMode = *TextOutModeMap;
4846 } else {
4847 CurrentMode = ModeNumber;
4848 }
4849
4850 MaxColumn = Private->TextOutQueryData[CurrentMode].Columns;
4851 MaxRow = Private->TextOutQueryData[CurrentMode].Rows;
4852
4853 if (Column >= MaxColumn || Row >= MaxRow) {
4854 return EFI_UNSUPPORTED;
4855 }
4856 //
4857 // return the worst status met
4858 //
4859 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4860
4861 if (Private->TextOutList[Index].TextOutEnabled) {
4862 Status = Private->TextOutList[Index].TextOut->SetCursorPosition (
4863 Private->TextOutList[Index].TextOut,
4864 Column,
4865 Row
4866 );
4867 if (EFI_ERROR (Status)) {
4868 ReturnStatus = Status;
4869 }
4870 }
4871 }
4872
4873 DevNullTextOutSetCursorPosition (Private, Column, Row);
4874
4875 return ReturnStatus;
4876 }
4877
4878
4879 /**
4880 Makes the cursor visible or invisible
4881
4882 @param This Protocol instance pointer.
4883 @param Visible If TRUE, the cursor is set to be visible. If
4884 FALSE, the cursor is set to be invisible.
4885
4886 @retval EFI_SUCCESS The operation completed successfully.
4887 @retval EFI_DEVICE_ERROR The device had an error and could not complete
4888 the request, or the device does not support
4889 changing the cursor mode.
4890 @retval EFI_UNSUPPORTED The output device is not in a valid text mode.
4891
4892 **/
4893 EFI_STATUS
4894 EFIAPI
4895 ConSplitterTextOutEnableCursor (
4896 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4897 IN BOOLEAN Visible
4898 )
4899 {
4900 EFI_STATUS Status;
4901 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4902 UINTN Index;
4903 EFI_STATUS ReturnStatus;
4904
4905 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4906
4907 //
4908 // return the worst status met
4909 //
4910 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4911
4912 if (Private->TextOutList[Index].TextOutEnabled) {
4913 Status = Private->TextOutList[Index].TextOut->EnableCursor (
4914 Private->TextOutList[Index].TextOut,
4915 Visible
4916 );
4917 if (EFI_ERROR (Status)) {
4918 ReturnStatus = Status;
4919 }
4920 }
4921 }
4922
4923 DevNullTextOutEnableCursor (Private, Visible);
4924
4925 return ReturnStatus;
4926 }
4927