]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitter.c
code scrub for consplitter module.
[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 unlock the password state variable and set the event
3438 timer. If the Password is too big return an error. If the Password is valid
3439 Copy the Password and enable state variable and then arm the periodic timer
3440
3441 @param This Console Control protocol pointer.
3442 @param Password The password input.
3443
3444 @retval EFI_SUCCESS Lock the StdIn device
3445 @retval EFI_INVALID_PARAMETER Password is NULL
3446 @retval EFI_OUT_OF_RESOURCES Buffer allocation to store the password fails
3447
3448 **/
3449 EFI_STATUS
3450 EFIAPI
3451 ConSpliterConsoleControlLockStdIn (
3452 IN EFI_CONSOLE_CONTROL_PROTOCOL *This,
3453 IN CHAR16 *Password
3454 )
3455 {
3456 if (Password == NULL) {
3457 return EFI_INVALID_PARAMETER;
3458 }
3459
3460 if (StrLen (Password) >= MAX_STD_IN_PASSWORD) {
3461 //
3462 // Currently have a max password size
3463 //
3464 return EFI_OUT_OF_RESOURCES;
3465 }
3466 //
3467 // Save the password, initialize state variables and arm event timer
3468 //
3469 StrCpy (mConIn.Password, Password);
3470 mConIn.PasswordEnabled = TRUE;
3471 mConIn.PwdIndex = 0;
3472 gBS->SetTimer (mConIn.LockEvent, TimerPeriodic, (10000 * 25));
3473
3474 return EFI_SUCCESS;
3475 }
3476
3477
3478 /**
3479 Reads the next keystroke from the input device. The WaitForKey Event can
3480 be used to test for existance of a keystroke via WaitForEvent () call.
3481 If the ConIn is password locked make it look like no keystroke is availible
3482
3483 @param This Protocol instance pointer.
3484 @param Key Driver may perform diagnostics on reset.
3485
3486 @retval EFI_SUCCESS The keystroke information was returned.
3487 @retval EFI_NOT_READY There was no keystroke data availiable.
3488 @retval EFI_DEVICE_ERROR The keydtroke information was not returned due
3489 to hardware errors.
3490
3491 **/
3492 EFI_STATUS
3493 EFIAPI
3494 ConSplitterTextInReadKeyStroke (
3495 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
3496 OUT EFI_INPUT_KEY *Key
3497 )
3498 {
3499 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3500
3501 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3502 if (Private->PasswordEnabled) {
3503 //
3504 // If StdIn Locked return not ready
3505 //
3506 return EFI_NOT_READY;
3507 }
3508
3509 Private->KeyEventSignalState = FALSE;
3510
3511 return ConSplitterTextInPrivateReadKeyStroke (Private, Key);
3512 }
3513
3514
3515 /**
3516 This event agregates all the events of the ConIn devices in the spliter.
3517 If the ConIn is password locked then return.
3518 If any events of physical ConIn devices are signaled, signal the ConIn
3519 spliter event. This will cause the calling code to call
3520 ConSplitterTextInReadKeyStroke ().
3521
3522 @param Event The Event assoicated with callback.
3523 @param Context Context registered when Event was created.
3524
3525 **/
3526 VOID
3527 EFIAPI
3528 ConSplitterTextInWaitForKey (
3529 IN EFI_EVENT Event,
3530 IN VOID *Context
3531 )
3532 {
3533 EFI_STATUS Status;
3534 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3535 UINTN Index;
3536
3537 Private = (TEXT_IN_SPLITTER_PRIVATE_DATA *) Context;
3538 if (Private->PasswordEnabled) {
3539 //
3540 // If StdIn Locked return not ready
3541 //
3542 return ;
3543 }
3544
3545 //
3546 // if KeyEventSignalState is flagged before, and not cleared by Reset() or ReadKeyStroke()
3547 //
3548 if (Private->KeyEventSignalState) {
3549 gBS->SignalEvent (Event);
3550 return ;
3551 }
3552 //
3553 // if any physical console input device has key input, signal the event.
3554 //
3555 for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {
3556 Status = gBS->CheckEvent (Private->TextInList[Index]->WaitForKey);
3557 if (!EFI_ERROR (Status)) {
3558 gBS->SignalEvent (Event);
3559 Private->KeyEventSignalState = TRUE;
3560 }
3561 }
3562 }
3563
3564
3565
3566 /**
3567 Test if the key has been registered on input device.
3568
3569 @param RegsiteredData A pointer to a buffer that is filled in with the
3570 keystroke state data for the key that was
3571 registered.
3572 @param InputData A pointer to a buffer that is filled in with the
3573 keystroke state data for the key that was
3574 pressed.
3575
3576 @retval TRUE Key be pressed matches a registered key.
3577 @retval FLASE Match failed.
3578
3579 **/
3580 BOOLEAN
3581 IsKeyRegistered (
3582 IN EFI_KEY_DATA *RegsiteredData,
3583 IN EFI_KEY_DATA *InputData
3584 )
3585 {
3586 ASSERT (RegsiteredData != NULL && InputData != NULL);
3587
3588 if ((RegsiteredData->Key.ScanCode != InputData->Key.ScanCode) ||
3589 (RegsiteredData->Key.UnicodeChar != InputData->Key.UnicodeChar)) {
3590 return FALSE;
3591 }
3592
3593 //
3594 // Assume KeyShiftState/KeyToggleState = 0 in Registered key data means these state could be ignored.
3595 //
3596 if (RegsiteredData->KeyState.KeyShiftState != 0 &&
3597 RegsiteredData->KeyState.KeyShiftState != InputData->KeyState.KeyShiftState) {
3598 return FALSE;
3599 }
3600 if (RegsiteredData->KeyState.KeyToggleState != 0 &&
3601 RegsiteredData->KeyState.KeyToggleState != InputData->KeyState.KeyToggleState) {
3602 return FALSE;
3603 }
3604
3605 return TRUE;
3606
3607 }
3608
3609
3610 /**
3611 Reset the input device and optionaly run diagnostics
3612
3613 @param This Protocol instance pointer.
3614 @param ExtendedVerification Driver may perform diagnostics on reset.
3615
3616 @retval EFI_SUCCESS The device was reset.
3617 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
3618 not be reset.
3619
3620 **/
3621 EFI_STATUS
3622 EFIAPI
3623 ConSplitterTextInResetEx (
3624 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
3625 IN BOOLEAN ExtendedVerification
3626 )
3627 {
3628 EFI_STATUS Status;
3629 EFI_STATUS ReturnStatus;
3630 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3631 UINTN Index;
3632
3633 Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3634
3635 Private->KeyEventSignalState = FALSE;
3636
3637 //
3638 // return the worst status met
3639 //
3640 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfExConsoles; Index++) {
3641 Status = Private->TextInExList[Index]->Reset (
3642 Private->TextInExList[Index],
3643 ExtendedVerification
3644 );
3645 if (EFI_ERROR (Status)) {
3646 ReturnStatus = Status;
3647 }
3648 }
3649
3650 return ReturnStatus;
3651
3652 }
3653
3654
3655 /**
3656 Reads the next keystroke from the input device. The WaitForKey Event can
3657 be used to test for existance of a keystroke via WaitForEvent () call.
3658
3659 @param This Protocol instance pointer.
3660 @param KeyData A pointer to a buffer that is filled in with the
3661 keystroke state data for the key that was
3662 pressed.
3663
3664 @retval EFI_SUCCESS The keystroke information was returned.
3665 @retval EFI_NOT_READY There was no keystroke data availiable.
3666 @retval EFI_DEVICE_ERROR The keystroke information was not returned due
3667 to hardware errors.
3668 @retval EFI_INVALID_PARAMETER KeyData is NULL.
3669
3670 **/
3671 EFI_STATUS
3672 EFIAPI
3673 ConSplitterTextInReadKeyStrokeEx (
3674 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
3675 OUT EFI_KEY_DATA *KeyData
3676 )
3677 {
3678 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3679 EFI_STATUS Status;
3680 UINTN Index;
3681 EFI_KEY_DATA CurrentKeyData;
3682
3683
3684 if (KeyData == NULL) {
3685 return EFI_INVALID_PARAMETER;
3686 }
3687
3688 Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3689 if (Private->PasswordEnabled) {
3690 //
3691 // If StdIn Locked return not ready
3692 //
3693 return EFI_NOT_READY;
3694 }
3695
3696 Private->KeyEventSignalState = FALSE;
3697
3698 KeyData->Key.UnicodeChar = 0;
3699 KeyData->Key.ScanCode = SCAN_NULL;
3700
3701 //
3702 // if no physical console input device exists, return EFI_NOT_READY;
3703 // if any physical console input device has key input,
3704 // return the key and EFI_SUCCESS.
3705 //
3706 for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {
3707 Status = Private->TextInExList[Index]->ReadKeyStrokeEx (
3708 Private->TextInExList[Index],
3709 &CurrentKeyData
3710 );
3711 if (!EFI_ERROR (Status)) {
3712 CopyMem (KeyData, &CurrentKeyData, sizeof (CurrentKeyData));
3713 return Status;
3714 }
3715 }
3716
3717 return EFI_NOT_READY;
3718 }
3719
3720
3721 /**
3722 Set certain state for the input device.
3723
3724 @param This Protocol instance pointer.
3725 @param KeyToggleState A pointer to the EFI_KEY_TOGGLE_STATE to set the
3726 state for the input device.
3727
3728 @retval EFI_SUCCESS The device state was set successfully.
3729 @retval EFI_DEVICE_ERROR The device is not functioning correctly and
3730 could not have the setting adjusted.
3731 @retval EFI_UNSUPPORTED The device does not have the ability to set its
3732 state.
3733 @retval EFI_INVALID_PARAMETER KeyToggleState is NULL.
3734
3735 **/
3736 EFI_STATUS
3737 EFIAPI
3738 ConSplitterTextInSetState (
3739 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
3740 IN EFI_KEY_TOGGLE_STATE *KeyToggleState
3741 )
3742 {
3743 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3744 EFI_STATUS Status;
3745 UINTN Index;
3746
3747 if (KeyToggleState == NULL) {
3748 return EFI_INVALID_PARAMETER;
3749 }
3750
3751 Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3752
3753 //
3754 // if no physical console input device exists, return EFI_SUCCESS;
3755 // otherwise return the status of setting state of physical console input device
3756 //
3757 for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {
3758 Status = Private->TextInExList[Index]->SetState (
3759 Private->TextInExList[Index],
3760 KeyToggleState
3761 );
3762 if (EFI_ERROR (Status)) {
3763 return Status;
3764 }
3765 }
3766
3767 return EFI_SUCCESS;
3768
3769 }
3770
3771
3772 /**
3773 Register a notification function for a particular keystroke for the input device.
3774
3775 @param This Protocol instance pointer.
3776 @param KeyData A pointer to a buffer that is filled in with the
3777 keystroke information data for the key that was
3778 pressed.
3779 @param KeyNotificationFunction Points to the function to be called when the key
3780 sequence is typed specified by KeyData.
3781 @param NotifyHandle Points to the unique handle assigned to the
3782 registered notification.
3783
3784 @retval EFI_SUCCESS The notification function was registered
3785 successfully.
3786 @retval EFI_OUT_OF_RESOURCES Unable to allocate resources for necesssary data
3787 structures.
3788 @retval EFI_INVALID_PARAMETER KeyData or NotifyHandle is NULL.
3789
3790 **/
3791 EFI_STATUS
3792 EFIAPI
3793 ConSplitterTextInRegisterKeyNotify (
3794 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
3795 IN EFI_KEY_DATA *KeyData,
3796 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction,
3797 OUT EFI_HANDLE *NotifyHandle
3798 )
3799 {
3800 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3801 EFI_STATUS Status;
3802 UINTN Index;
3803 TEXT_IN_EX_SPLITTER_NOTIFY *NewNotify;
3804 LIST_ENTRY *Link;
3805 TEXT_IN_EX_SPLITTER_NOTIFY *CurrentNotify;
3806
3807
3808 if (KeyData == NULL || NotifyHandle == NULL || KeyNotificationFunction == NULL) {
3809 return EFI_INVALID_PARAMETER;
3810 }
3811
3812 Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3813
3814 //
3815 // if no physical console input device exists,
3816 // return EFI_SUCCESS directly.
3817 //
3818 if (Private->CurrentNumberOfExConsoles <= 0) {
3819 return EFI_SUCCESS;
3820 }
3821
3822 //
3823 // Return EFI_SUCCESS if the (KeyData, NotificationFunction) is already registered.
3824 //
3825 for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {
3826 CurrentNotify = TEXT_IN_EX_SPLITTER_NOTIFY_FROM_THIS (Link);
3827 if (IsKeyRegistered (&CurrentNotify->KeyData, KeyData)) {
3828 if (CurrentNotify->KeyNotificationFn == KeyNotificationFunction) {
3829 *NotifyHandle = CurrentNotify->NotifyHandle;
3830 return EFI_SUCCESS;
3831 }
3832 }
3833 }
3834
3835 //
3836 // Allocate resource to save the notification function
3837 //
3838 NewNotify = (TEXT_IN_EX_SPLITTER_NOTIFY *) AllocateZeroPool (sizeof (TEXT_IN_EX_SPLITTER_NOTIFY));
3839 if (NewNotify == NULL) {
3840 return EFI_OUT_OF_RESOURCES;
3841 }
3842 NewNotify->NotifyHandleList = (EFI_HANDLE *) AllocateZeroPool (sizeof (EFI_HANDLE) * Private->CurrentNumberOfExConsoles);
3843 if (NewNotify->NotifyHandleList == NULL) {
3844 gBS->FreePool (NewNotify);
3845 return EFI_OUT_OF_RESOURCES;
3846 }
3847 NewNotify->Signature = TEXT_IN_EX_SPLITTER_NOTIFY_SIGNATURE;
3848 NewNotify->KeyNotificationFn = KeyNotificationFunction;
3849 CopyMem (&NewNotify->KeyData, KeyData, sizeof (KeyData));
3850
3851 //
3852 // Return the wrong status of registering key notify of
3853 // physical console input device if meet problems
3854 //
3855 for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {
3856 Status = Private->TextInExList[Index]->RegisterKeyNotify (
3857 Private->TextInExList[Index],
3858 KeyData,
3859 KeyNotificationFunction,
3860 &NewNotify->NotifyHandleList[Index]
3861 );
3862 if (EFI_ERROR (Status)) {
3863 gBS->FreePool (NewNotify->NotifyHandleList);
3864 gBS->FreePool (NewNotify);
3865 return Status;
3866 }
3867 }
3868
3869 //
3870 // Use gSimpleTextInExNotifyGuid to get a valid EFI_HANDLE
3871 //
3872 Status = gBS->InstallMultipleProtocolInterfaces (
3873 &NewNotify->NotifyHandle,
3874 &gSimpleTextInExNotifyGuid,
3875 NULL,
3876 NULL
3877 );
3878 ASSERT_EFI_ERROR (Status);
3879
3880 InsertTailList (&mConIn.NotifyList, &NewNotify->NotifyEntry);
3881
3882 *NotifyHandle = NewNotify->NotifyHandle;
3883
3884 return EFI_SUCCESS;
3885
3886 }
3887
3888
3889 /**
3890 Remove a registered notification function from a particular keystroke.
3891
3892 @param This Protocol instance pointer.
3893 @param NotificationHandle The handle of the notification function being
3894 unregistered.
3895
3896 @retval EFI_SUCCESS The notification function was unregistered
3897 successfully.
3898 @retval EFI_INVALID_PARAMETER The NotificationHandle is invalid.
3899 @retval EFI_NOT_FOUND Can not find the matching entry in database.
3900
3901 **/
3902 EFI_STATUS
3903 EFIAPI
3904 ConSplitterTextInUnregisterKeyNotify (
3905 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
3906 IN EFI_HANDLE NotificationHandle
3907 )
3908 {
3909 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3910 EFI_STATUS Status;
3911 UINTN Index;
3912 TEXT_IN_EX_SPLITTER_NOTIFY *CurrentNotify;
3913 LIST_ENTRY *Link;
3914
3915 if (NotificationHandle == NULL) {
3916 return EFI_INVALID_PARAMETER;
3917 }
3918
3919 Status = gBS->OpenProtocol (
3920 NotificationHandle,
3921 &gSimpleTextInExNotifyGuid,
3922 NULL,
3923 NULL,
3924 NULL,
3925 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
3926 );
3927 if (EFI_ERROR (Status)) {
3928 return EFI_INVALID_PARAMETER;
3929 }
3930
3931 Private = TEXT_IN_EX_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3932
3933 //
3934 // if no physical console input device exists,
3935 // return EFI_SUCCESS directly.
3936 //
3937 if (Private->CurrentNumberOfExConsoles <= 0) {
3938 return EFI_SUCCESS;
3939 }
3940
3941 for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {
3942 CurrentNotify = TEXT_IN_EX_SPLITTER_NOTIFY_FROM_THIS (Link);
3943 if (CurrentNotify->NotifyHandle == NotificationHandle) {
3944 for (Index = 0; Index < Private->CurrentNumberOfExConsoles; Index++) {
3945 Status = Private->TextInExList[Index]->UnregisterKeyNotify (
3946 Private->TextInExList[Index],
3947 CurrentNotify->NotifyHandleList[Index]
3948 );
3949 if (EFI_ERROR (Status)) {
3950 return Status;
3951 }
3952 }
3953 RemoveEntryList (&CurrentNotify->NotifyEntry);
3954 Status = gBS->UninstallMultipleProtocolInterfaces (
3955 CurrentNotify->NotifyHandle,
3956 &gSimpleTextInExNotifyGuid,
3957 NULL,
3958 NULL
3959 );
3960 ASSERT_EFI_ERROR (Status);
3961 gBS->FreePool (CurrentNotify->NotifyHandleList);
3962 gBS->FreePool (CurrentNotify);
3963 return EFI_SUCCESS;
3964 }
3965 }
3966
3967 return EFI_NOT_FOUND;
3968
3969 }
3970
3971
3972 /**
3973 Reset the input device and optionaly run diagnostics
3974
3975 @param This Protocol instance pointer.
3976 @param ExtendedVerification Driver may perform diagnostics on reset.
3977
3978 @retval EFI_SUCCESS The device was reset.
3979 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
3980 not be reset.
3981
3982 **/
3983 EFI_STATUS
3984 EFIAPI
3985 ConSplitterSimplePointerReset (
3986 IN EFI_SIMPLE_POINTER_PROTOCOL *This,
3987 IN BOOLEAN ExtendedVerification
3988 )
3989 {
3990 EFI_STATUS Status;
3991 EFI_STATUS ReturnStatus;
3992 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
3993 UINTN Index;
3994
3995 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_SIMPLE_POINTER_THIS (This);
3996
3997 Private->InputEventSignalState = FALSE;
3998
3999 if (Private->CurrentNumberOfPointers == 0) {
4000 return EFI_SUCCESS;
4001 }
4002 //
4003 // return the worst status met
4004 //
4005 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfPointers; Index++) {
4006 Status = Private->PointerList[Index]->Reset (
4007 Private->PointerList[Index],
4008 ExtendedVerification
4009 );
4010 if (EFI_ERROR (Status)) {
4011 ReturnStatus = Status;
4012 }
4013 }
4014
4015 return ReturnStatus;
4016 }
4017
4018
4019 /**
4020 Reads the next keystroke from the input device. The WaitForKey Event can
4021 be used to test for existance of a keystroke via WaitForEvent () call.
4022
4023 @param Private Protocol instance pointer.
4024 @param State The state information of simple pointer device.
4025
4026 @retval EFI_SUCCESS The keystroke information was returned.
4027 @retval EFI_NOT_READY There was no keystroke data availiable.
4028 @retval EFI_DEVICE_ERROR The keydtroke information was not returned due
4029 to hardware errors.
4030
4031 **/
4032 EFI_STATUS
4033 EFIAPI
4034 ConSplitterSimplePointerPrivateGetState (
4035 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
4036 IN OUT EFI_SIMPLE_POINTER_STATE *State
4037 )
4038 {
4039 EFI_STATUS Status;
4040 EFI_STATUS ReturnStatus;
4041 UINTN Index;
4042 EFI_SIMPLE_POINTER_STATE CurrentState;
4043
4044 State->RelativeMovementX = 0;
4045 State->RelativeMovementY = 0;
4046 State->RelativeMovementZ = 0;
4047 State->LeftButton = FALSE;
4048 State->RightButton = FALSE;
4049
4050 //
4051 // if no physical console input device exists, return EFI_NOT_READY;
4052 // if any physical console input device has key input,
4053 // return the key and EFI_SUCCESS.
4054 //
4055 ReturnStatus = EFI_NOT_READY;
4056 for (Index = 0; Index < Private->CurrentNumberOfPointers; Index++) {
4057
4058 Status = Private->PointerList[Index]->GetState (
4059 Private->PointerList[Index],
4060 &CurrentState
4061 );
4062 if (!EFI_ERROR (Status)) {
4063 if (ReturnStatus == EFI_NOT_READY) {
4064 ReturnStatus = EFI_SUCCESS;
4065 }
4066
4067 if (CurrentState.LeftButton) {
4068 State->LeftButton = TRUE;
4069 }
4070
4071 if (CurrentState.RightButton) {
4072 State->RightButton = TRUE;
4073 }
4074
4075 if (CurrentState.RelativeMovementX != 0 && Private->PointerList[Index]->Mode->ResolutionX != 0) {
4076 State->RelativeMovementX += (CurrentState.RelativeMovementX * (INT32) Private->SimplePointerMode.ResolutionX) / (INT32) Private->PointerList[Index]->Mode->ResolutionX;
4077 }
4078
4079 if (CurrentState.RelativeMovementY != 0 && Private->PointerList[Index]->Mode->ResolutionY != 0) {
4080 State->RelativeMovementY += (CurrentState.RelativeMovementY * (INT32) Private->SimplePointerMode.ResolutionY) / (INT32) Private->PointerList[Index]->Mode->ResolutionY;
4081 }
4082
4083 if (CurrentState.RelativeMovementZ != 0 && Private->PointerList[Index]->Mode->ResolutionZ != 0) {
4084 State->RelativeMovementZ += (CurrentState.RelativeMovementZ * (INT32) Private->SimplePointerMode.ResolutionZ) / (INT32) Private->PointerList[Index]->Mode->ResolutionZ;
4085 }
4086 } else if (Status == EFI_DEVICE_ERROR) {
4087 ReturnStatus = EFI_DEVICE_ERROR;
4088 }
4089 }
4090
4091 return ReturnStatus;
4092 }
4093
4094
4095 /**
4096 Reads the next keystroke from the input device. The WaitForKey Event can
4097 be used to test for existance of a keystroke via WaitForEvent () call.
4098 If the ConIn is password locked make it look like no keystroke is availible
4099
4100 @param This A pointer to protocol instance.
4101 @param State A pointer to state information on the pointer device
4102
4103 @retval EFI_SUCCESS The keystroke information was returned in State.
4104 @retval EFI_NOT_READY There was no keystroke data availiable.
4105 @retval EFI_DEVICE_ERROR The keydtroke information was not returned due
4106 to hardware errors.
4107
4108 **/
4109 EFI_STATUS
4110 EFIAPI
4111 ConSplitterSimplePointerGetState (
4112 IN EFI_SIMPLE_POINTER_PROTOCOL *This,
4113 IN OUT EFI_SIMPLE_POINTER_STATE *State
4114 )
4115 {
4116 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
4117
4118 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_SIMPLE_POINTER_THIS (This);
4119 if (Private->PasswordEnabled) {
4120 //
4121 // If StdIn Locked return not ready
4122 //
4123 return EFI_NOT_READY;
4124 }
4125
4126 Private->InputEventSignalState = FALSE;
4127
4128 return ConSplitterSimplePointerPrivateGetState (Private, State);
4129 }
4130
4131
4132 /**
4133 This event agregates all the events of the ConIn devices in the spliter.
4134 If the ConIn is password locked then return.
4135 If any events of physical ConIn devices are signaled, signal the ConIn
4136 spliter event. This will cause the calling code to call
4137 ConSplitterTextInReadKeyStroke ().
4138
4139 @param Event The Event assoicated with callback.
4140 @param Context Context registered when Event was created.
4141
4142 **/
4143 VOID
4144 EFIAPI
4145 ConSplitterSimplePointerWaitForInput (
4146 IN EFI_EVENT Event,
4147 IN VOID *Context
4148 )
4149 {
4150 EFI_STATUS Status;
4151 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
4152 UINTN Index;
4153
4154 Private = (TEXT_IN_SPLITTER_PRIVATE_DATA *) Context;
4155 if (Private->PasswordEnabled) {
4156 //
4157 // If StdIn Locked return not ready
4158 //
4159 return ;
4160 }
4161
4162 //
4163 // if InputEventSignalState is flagged before, and not cleared by Reset() or ReadKeyStroke()
4164 //
4165 if (Private->InputEventSignalState) {
4166 gBS->SignalEvent (Event);
4167 return ;
4168 }
4169 //
4170 // if any physical console input device has key input, signal the event.
4171 //
4172 for (Index = 0; Index < Private->CurrentNumberOfPointers; Index++) {
4173 Status = gBS->CheckEvent (Private->PointerList[Index]->WaitForInput);
4174 if (!EFI_ERROR (Status)) {
4175 gBS->SignalEvent (Event);
4176 Private->InputEventSignalState = TRUE;
4177 }
4178 }
4179 }
4180
4181 /**
4182 Resets the pointer device hardware.
4183
4184 @param This Protocol instance pointer.
4185 @param ExtendedVerification Driver may perform diagnostics on reset.
4186
4187 @retval EFI_SUCCESS The device was reset.
4188 @retval EFI_DEVICE_ERROR The device is not functioning correctly and
4189 could not be reset.
4190
4191 **/
4192 EFI_STATUS
4193 EFIAPI
4194 ConSplitterAbsolutePointerReset (
4195 IN EFI_ABSOLUTE_POINTER_PROTOCOL *This,
4196 IN BOOLEAN ExtendedVerification
4197 )
4198 {
4199 EFI_STATUS Status;
4200 EFI_STATUS ReturnStatus;
4201 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
4202 UINTN Index;
4203
4204 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_ABSOLUTE_POINTER_THIS (This);
4205
4206 Private->AbsoluteInputEventSignalState = FALSE;
4207
4208 if (Private->CurrentNumberOfAbsolutePointers == 0) {
4209 return EFI_SUCCESS;
4210 }
4211 //
4212 // return the worst status met
4213 //
4214 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfAbsolutePointers; Index++) {
4215 Status = Private->AbsolutePointerList[Index]->Reset (
4216 Private->AbsolutePointerList[Index],
4217 ExtendedVerification
4218 );
4219 if (EFI_ERROR (Status)) {
4220 ReturnStatus = Status;
4221 }
4222 }
4223
4224 return ReturnStatus;
4225 }
4226
4227
4228 /**
4229 Retrieves the current state of a pointer device.
4230
4231 @param This Protocol instance pointer.
4232 @param State A pointer to the state information on the
4233 pointer device.
4234
4235 @retval EFI_SUCCESS The state of the pointer device was returned in
4236 State..
4237 @retval EFI_NOT_READY The state of the pointer device has not changed
4238 since the last call to GetState().
4239 @retval EFI_DEVICE_ERROR A device error occurred while attempting to
4240 retrieve the pointer device's current state.
4241
4242 **/
4243 EFI_STATUS
4244 EFIAPI
4245 ConSplitterAbsolutePointerGetState (
4246 IN EFI_ABSOLUTE_POINTER_PROTOCOL *This,
4247 IN OUT EFI_ABSOLUTE_POINTER_STATE *State
4248 )
4249 {
4250 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
4251 EFI_STATUS Status;
4252 EFI_STATUS ReturnStatus;
4253 UINTN Index;
4254 EFI_ABSOLUTE_POINTER_STATE CurrentState;
4255
4256
4257 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_ABSOLUTE_POINTER_THIS (This);
4258 if (Private->PasswordEnabled) {
4259 //
4260 // If StdIn Locked return not ready
4261 //
4262 return EFI_NOT_READY;
4263 }
4264
4265 Private->AbsoluteInputEventSignalState = FALSE;
4266
4267 State->CurrentX = 0;
4268 State->CurrentY = 0;
4269 State->CurrentZ = 0;
4270 State->ActiveButtons = 0;
4271
4272 //
4273 // if no physical pointer device exists, return EFI_NOT_READY;
4274 // if any physical pointer device has changed state,
4275 // return the state and EFI_SUCCESS.
4276 //
4277 ReturnStatus = EFI_NOT_READY;
4278 for (Index = 0; Index < Private->CurrentNumberOfAbsolutePointers; Index++) {
4279
4280 Status = Private->AbsolutePointerList[Index]->GetState (
4281 Private->AbsolutePointerList[Index],
4282 &CurrentState
4283 );
4284 if (!EFI_ERROR (Status)) {
4285 if (ReturnStatus == EFI_NOT_READY) {
4286 ReturnStatus = EFI_SUCCESS;
4287 }
4288
4289 State->ActiveButtons = CurrentState.ActiveButtons;
4290
4291 if (!(Private->AbsolutePointerMode.AbsoluteMinX == 0 && Private->AbsolutePointerMode.AbsoluteMaxX == 0)) {
4292 State->CurrentX = CurrentState.CurrentX;
4293 }
4294 if (!(Private->AbsolutePointerMode.AbsoluteMinY == 0 && Private->AbsolutePointerMode.AbsoluteMaxY == 0)) {
4295 State->CurrentY = CurrentState.CurrentY;
4296 }
4297 if (!(Private->AbsolutePointerMode.AbsoluteMinZ == 0 && Private->AbsolutePointerMode.AbsoluteMaxZ == 0)) {
4298 State->CurrentZ = CurrentState.CurrentZ;
4299 }
4300
4301 } else if (Status == EFI_DEVICE_ERROR) {
4302 ReturnStatus = EFI_DEVICE_ERROR;
4303 }
4304 }
4305
4306 return ReturnStatus;
4307 }
4308
4309
4310 /**
4311 This event agregates all the events of the pointer devices in the splitter.
4312 If the ConIn is password locked then return.
4313 If any events of physical pointer devices are signaled, signal the pointer
4314 splitter event. This will cause the calling code to call
4315 ConSplitterAbsolutePointerGetState ().
4316
4317 @param Event The Event assoicated with callback.
4318 @param Context Context registered when Event was created.
4319
4320 **/
4321 VOID
4322 EFIAPI
4323 ConSplitterAbsolutePointerWaitForInput (
4324 IN EFI_EVENT Event,
4325 IN VOID *Context
4326 )
4327 {
4328 EFI_STATUS Status;
4329 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
4330 UINTN Index;
4331
4332 Private = (TEXT_IN_SPLITTER_PRIVATE_DATA *) Context;
4333 if (Private->PasswordEnabled) {
4334 //
4335 // If StdIn Locked return not ready
4336 //
4337 return ;
4338 }
4339
4340 //
4341 // if AbsoluteInputEventSignalState is flagged before,
4342 // and not cleared by Reset() or GetState(), signal it
4343 //
4344 if (Private->AbsoluteInputEventSignalState) {
4345 gBS->SignalEvent (Event);
4346 return ;
4347 }
4348 //
4349 // if any physical console input device has key input, signal the event.
4350 //
4351 for (Index = 0; Index < Private->CurrentNumberOfAbsolutePointers; Index++) {
4352 Status = gBS->CheckEvent (Private->AbsolutePointerList[Index]->WaitForInput);
4353 if (!EFI_ERROR (Status)) {
4354 gBS->SignalEvent (Event);
4355 Private->AbsoluteInputEventSignalState = TRUE;
4356 }
4357 }
4358 }
4359
4360
4361 /**
4362 Reset the text output device hardware and optionaly run diagnostics
4363
4364 @param This Protocol instance pointer.
4365 @param ExtendedVerification Driver may perform more exhaustive verfication
4366 operation of the device during reset.
4367
4368 @retval EFI_SUCCESS The text output device was reset.
4369 @retval EFI_DEVICE_ERROR The text output device is not functioning
4370 correctly and could not be reset.
4371
4372 **/
4373 EFI_STATUS
4374 EFIAPI
4375 ConSplitterTextOutReset (
4376 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4377 IN BOOLEAN ExtendedVerification
4378 )
4379 {
4380 EFI_STATUS Status;
4381 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4382 UINTN Index;
4383 EFI_STATUS ReturnStatus;
4384
4385 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4386
4387 //
4388 // return the worst status met
4389 //
4390 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4391
4392 if (Private->TextOutList[Index].TextOutEnabled) {
4393
4394 Status = Private->TextOutList[Index].TextOut->Reset (
4395 Private->TextOutList[Index].TextOut,
4396 ExtendedVerification
4397 );
4398 if (EFI_ERROR (Status)) {
4399 ReturnStatus = Status;
4400 }
4401 }
4402 }
4403
4404 This->SetAttribute (This, EFI_TEXT_ATTR (This->Mode->Attribute & 0x0F, EFI_BLACK));
4405
4406 Status = DevNullTextOutSetMode (Private, 0);
4407 if (EFI_ERROR (Status)) {
4408 ReturnStatus = Status;
4409 }
4410
4411 return ReturnStatus;
4412 }
4413
4414
4415 /**
4416 Write a Unicode string to the output device.
4417
4418 @param This Protocol instance pointer.
4419 @param WString The NULL-terminated Unicode string to be
4420 displayed on the output device(s). All output
4421 devices must also support the Unicode drawing
4422 defined in this file.
4423
4424 @retval EFI_SUCCESS The string was output to the device.
4425 @retval EFI_DEVICE_ERROR The device reported an error while attempting to
4426 output the text.
4427 @retval EFI_UNSUPPORTED The output device's mode is not currently in a
4428 defined text mode.
4429 @retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the
4430 characters in the Unicode string could not be
4431 rendered and were skipped.
4432
4433 **/
4434 EFI_STATUS
4435 EFIAPI
4436 ConSplitterTextOutOutputString (
4437 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4438 IN CHAR16 *WString
4439 )
4440 {
4441 EFI_STATUS Status;
4442 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4443 UINTN Index;
4444 UINTN BackSpaceCount;
4445 EFI_STATUS ReturnStatus;
4446 CHAR16 *TargetString;
4447
4448 This->SetAttribute (This, This->Mode->Attribute);
4449
4450 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4451
4452 BackSpaceCount = 0;
4453 for (TargetString = WString; *TargetString != L'\0'; TargetString++) {
4454 if (*TargetString == CHAR_BACKSPACE) {
4455 BackSpaceCount++;
4456 }
4457
4458 }
4459
4460 if (BackSpaceCount == 0) {
4461 TargetString = WString;
4462 } else {
4463 TargetString = AllocatePool (sizeof (CHAR16) * (StrLen (WString) + BackSpaceCount + 1));
4464 StrCpy (TargetString, WString);
4465 }
4466 //
4467 // return the worst status met
4468 //
4469 Status = DevNullTextOutOutputString (Private, TargetString);
4470 if (EFI_ERROR (Status)) {
4471 ReturnStatus = Status;
4472 }
4473
4474 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4475
4476 if (Private->TextOutList[Index].TextOutEnabled) {
4477 Status = Private->TextOutList[Index].TextOut->OutputString (
4478 Private->TextOutList[Index].TextOut,
4479 TargetString
4480 );
4481 if (EFI_ERROR (Status)) {
4482 ReturnStatus = Status;
4483 }
4484 }
4485 }
4486
4487 if (BackSpaceCount > 0) {
4488 FreePool (TargetString);
4489 }
4490
4491 return ReturnStatus;
4492 }
4493
4494
4495 /**
4496 Verifies that all characters in a Unicode string can be output to the
4497 target device.
4498
4499 @param This Protocol instance pointer.
4500 @param WString The NULL-terminated Unicode string to be
4501 examined for the output device(s).
4502
4503 @retval EFI_SUCCESS The device(s) are capable of rendering the
4504 output string.
4505 @retval EFI_UNSUPPORTED Some of the characters in the Unicode string
4506 cannot be rendered by one or more of the output
4507 devices mapped by the EFI handle.
4508
4509 **/
4510 EFI_STATUS
4511 EFIAPI
4512 ConSplitterTextOutTestString (
4513 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4514 IN CHAR16 *WString
4515 )
4516 {
4517 EFI_STATUS Status;
4518 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4519 UINTN Index;
4520 EFI_STATUS ReturnStatus;
4521
4522 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4523
4524 //
4525 // return the worst status met
4526 //
4527 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4528 if (Private->TextOutList[Index].TextOutEnabled) {
4529 Status = Private->TextOutList[Index].TextOut->TestString (
4530 Private->TextOutList[Index].TextOut,
4531 WString
4532 );
4533 if (EFI_ERROR (Status)) {
4534 ReturnStatus = Status;
4535 }
4536 }
4537 }
4538 //
4539 // There is no DevNullTextOutTestString () since a Unicode buffer would
4540 // always return EFI_SUCCESS.
4541 // ReturnStatus will be EFI_SUCCESS if no consoles are present
4542 //
4543 return ReturnStatus;
4544 }
4545
4546
4547 /**
4548 Returns information for an available text mode that the output device(s)
4549 supports.
4550
4551 @param This Protocol instance pointer.
4552 @param ModeNumber The mode number to return information on.
4553 @param Columns Returns the columns of the text output device
4554 for the requested ModeNumber.
4555 @param Rows Returns the rows of the text output device
4556 for the requested ModeNumber.
4557
4558 @retval EFI_SUCCESS The requested mode information was returned.
4559 @retval EFI_DEVICE_ERROR The device had an error and could not complete
4560 the request.
4561 @retval EFI_UNSUPPORTED The mode number was not valid.
4562
4563 **/
4564 EFI_STATUS
4565 EFIAPI
4566 ConSplitterTextOutQueryMode (
4567 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4568 IN UINTN ModeNumber,
4569 OUT UINTN *Columns,
4570 OUT UINTN *Rows
4571 )
4572 {
4573 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4574 UINTN CurrentMode;
4575 INT32 *TextOutModeMap;
4576
4577 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4578
4579 //
4580 // Check whether param ModeNumber is valid.
4581 // ModeNumber should be within range 0 ~ MaxMode - 1.
4582 //
4583 if ( (ModeNumber > (UINTN)(((UINT32)-1)>>1)) ) {
4584 return EFI_UNSUPPORTED;
4585 }
4586
4587 if ((INT32) ModeNumber >= This->Mode->MaxMode) {
4588 return EFI_UNSUPPORTED;
4589 }
4590
4591 //
4592 // We get the available mode from mode intersection map if it's available
4593 //
4594 if (Private->TextOutModeMap != NULL) {
4595 TextOutModeMap = Private->TextOutModeMap + Private->TextOutListCount * ModeNumber;
4596 CurrentMode = (UINTN)(*TextOutModeMap);
4597 *Columns = Private->TextOutQueryData[CurrentMode].Columns;
4598 *Rows = Private->TextOutQueryData[CurrentMode].Rows;
4599 } else {
4600 *Columns = Private->TextOutQueryData[ModeNumber].Columns;
4601 *Rows = Private->TextOutQueryData[ModeNumber].Rows;
4602 }
4603
4604 if (*Columns <= 0 && *Rows <= 0) {
4605 return EFI_UNSUPPORTED;
4606
4607 }
4608
4609 return EFI_SUCCESS;
4610 }
4611
4612
4613 /**
4614 Sets the output device(s) to a specified mode.
4615
4616 @param This Protocol instance pointer.
4617 @param ModeNumber The mode number to set.
4618
4619 @retval EFI_SUCCESS The requested text mode was set.
4620 @retval EFI_DEVICE_ERROR The device had an error and could not complete
4621 the request.
4622 @retval EFI_UNSUPPORTED The mode number was not valid.
4623
4624 **/
4625 EFI_STATUS
4626 EFIAPI
4627 ConSplitterTextOutSetMode (
4628 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4629 IN UINTN ModeNumber
4630 )
4631 {
4632 EFI_STATUS Status;
4633 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4634 UINTN Index;
4635 INT32 *TextOutModeMap;
4636 EFI_STATUS ReturnStatus;
4637
4638 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4639
4640 //
4641 // Check whether param ModeNumber is valid.
4642 // ModeNumber should be within range 0 ~ MaxMode - 1.
4643 //
4644 if ( (ModeNumber > (UINTN)(((UINT32)-1)>>1)) ) {
4645 return EFI_UNSUPPORTED;
4646 }
4647
4648 if ((INT32) ModeNumber >= This->Mode->MaxMode) {
4649 return EFI_UNSUPPORTED;
4650 }
4651 //
4652 // If the mode is being set to the curent mode, then just clear the screen and return.
4653 //
4654 if (Private->TextOutMode.Mode == (INT32) ModeNumber) {
4655 return ConSplitterTextOutClearScreen (This);
4656 }
4657 //
4658 // return the worst status met
4659 //
4660 TextOutModeMap = Private->TextOutModeMap + Private->TextOutListCount * ModeNumber;
4661 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4662
4663 if (Private->TextOutList[Index].TextOutEnabled) {
4664 Status = Private->TextOutList[Index].TextOut->SetMode (
4665 Private->TextOutList[Index].TextOut,
4666 TextOutModeMap[Index]
4667 );
4668 //
4669 // If this console device is based on a GOP or UGA device, then sync up the bitmap from
4670 // the GOP/UGA splitter and reclear the text portion of the display in the new mode.
4671 //
4672 if ((Private->TextOutList[Index].GraphicsOutput != NULL) || (Private->TextOutList[Index].UgaDraw != NULL)) {
4673 Private->TextOutList[Index].TextOut->ClearScreen (Private->TextOutList[Index].TextOut);
4674 }
4675
4676 if (EFI_ERROR (Status)) {
4677 ReturnStatus = Status;
4678 }
4679 }
4680 }
4681 //
4682 // The DevNull Console will support any possible mode as it allocates memory
4683 //
4684 Status = DevNullTextOutSetMode (Private, ModeNumber);
4685 if (EFI_ERROR (Status)) {
4686 ReturnStatus = Status;
4687 }
4688
4689 return ReturnStatus;
4690 }
4691
4692
4693 /**
4694 Sets the background and foreground colors for the OutputString () and
4695 ClearScreen () functions.
4696
4697 @param This Protocol instance pointer.
4698 @param Attribute The attribute to set. Bits 0..3 are the
4699 foreground color, and bits 4..6 are the
4700 background color. All other bits are undefined
4701 and must be zero. The valid Attributes are
4702 defined in this file.
4703
4704 @retval EFI_SUCCESS The attribute was set.
4705 @retval EFI_DEVICE_ERROR The device had an error and could not complete
4706 the request.
4707 @retval EFI_UNSUPPORTED The attribute requested is not defined.
4708
4709 **/
4710 EFI_STATUS
4711 EFIAPI
4712 ConSplitterTextOutSetAttribute (
4713 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4714 IN UINTN Attribute
4715 )
4716 {
4717 EFI_STATUS Status;
4718 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4719 UINTN Index;
4720 EFI_STATUS ReturnStatus;
4721
4722 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4723
4724 //
4725 // Check whether param Attribute is valid.
4726 //
4727 if ( (Attribute > (UINTN)(((UINT32)-1)>>1)) ) {
4728 return EFI_UNSUPPORTED;
4729 }
4730
4731 //
4732 // return the worst status met
4733 //
4734 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4735
4736 if (Private->TextOutList[Index].TextOutEnabled) {
4737 Status = Private->TextOutList[Index].TextOut->SetAttribute (
4738 Private->TextOutList[Index].TextOut,
4739 Attribute
4740 );
4741 if (EFI_ERROR (Status)) {
4742 ReturnStatus = Status;
4743 }
4744 }
4745 }
4746
4747 Private->TextOutMode.Attribute = (INT32) Attribute;
4748
4749 return ReturnStatus;
4750 }
4751
4752
4753 /**
4754 Clears the output device(s) display to the currently selected background
4755 color.
4756
4757 @param This Protocol instance pointer.
4758
4759 @retval EFI_SUCCESS The operation completed successfully.
4760 @retval EFI_DEVICE_ERROR The device had an error and could not complete
4761 the request.
4762 @retval EFI_UNSUPPORTED The output device is not in a valid text mode.
4763
4764 **/
4765 EFI_STATUS
4766 EFIAPI
4767 ConSplitterTextOutClearScreen (
4768 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This
4769 )
4770 {
4771 EFI_STATUS Status;
4772 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4773 UINTN Index;
4774 EFI_STATUS ReturnStatus;
4775
4776 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4777
4778 //
4779 // return the worst status met
4780 //
4781 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4782
4783 if (Private->TextOutList[Index].TextOutEnabled) {
4784 Status = Private->TextOutList[Index].TextOut->ClearScreen (Private->TextOutList[Index].TextOut);
4785 if (EFI_ERROR (Status)) {
4786 ReturnStatus = Status;
4787 }
4788 }
4789 }
4790
4791 Status = DevNullTextOutClearScreen (Private);
4792 if (EFI_ERROR (Status)) {
4793 ReturnStatus = Status;
4794 }
4795
4796 return ReturnStatus;
4797 }
4798
4799
4800 /**
4801 Sets the current coordinates of the cursor position
4802
4803 @param This Protocol instance pointer.
4804 @param Column The column position to set the cursor to. Must be
4805 greater than or equal to zero and less than the
4806 number of columns by QueryMode ().
4807 @param Row The row position to set the cursor to. Must be
4808 greater than or equal to zero and less than the
4809 number of rows by QueryMode ().
4810
4811 @retval EFI_SUCCESS The operation completed successfully.
4812 @retval EFI_DEVICE_ERROR The device had an error and could not complete
4813 the request.
4814 @retval EFI_UNSUPPORTED The output device is not in a valid text mode,
4815 or the cursor position is invalid for the
4816 current mode.
4817
4818 **/
4819 EFI_STATUS
4820 EFIAPI
4821 ConSplitterTextOutSetCursorPosition (
4822 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4823 IN UINTN Column,
4824 IN UINTN Row
4825 )
4826 {
4827 EFI_STATUS Status;
4828 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4829 UINTN Index;
4830 EFI_STATUS ReturnStatus;
4831 UINTN MaxColumn;
4832 UINTN MaxRow;
4833 INT32 *TextOutModeMap;
4834 INT32 ModeNumber;
4835 INT32 CurrentMode;
4836
4837 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4838 TextOutModeMap = NULL;
4839 ModeNumber = Private->TextOutMode.Mode;
4840
4841 //
4842 // Get current MaxColumn and MaxRow from intersection map
4843 //
4844 if (Private->TextOutModeMap != NULL) {
4845 TextOutModeMap = Private->TextOutModeMap + Private->TextOutListCount * ModeNumber;
4846 CurrentMode = *TextOutModeMap;
4847 } else {
4848 CurrentMode = ModeNumber;
4849 }
4850
4851 MaxColumn = Private->TextOutQueryData[CurrentMode].Columns;
4852 MaxRow = Private->TextOutQueryData[CurrentMode].Rows;
4853
4854 if (Column >= MaxColumn || Row >= MaxRow) {
4855 return EFI_UNSUPPORTED;
4856 }
4857 //
4858 // return the worst status met
4859 //
4860 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4861
4862 if (Private->TextOutList[Index].TextOutEnabled) {
4863 Status = Private->TextOutList[Index].TextOut->SetCursorPosition (
4864 Private->TextOutList[Index].TextOut,
4865 Column,
4866 Row
4867 );
4868 if (EFI_ERROR (Status)) {
4869 ReturnStatus = Status;
4870 }
4871 }
4872 }
4873
4874 DevNullTextOutSetCursorPosition (Private, Column, Row);
4875
4876 return ReturnStatus;
4877 }
4878
4879
4880 /**
4881 Makes the cursor visible or invisible
4882
4883 @param This Protocol instance pointer.
4884 @param Visible If TRUE, the cursor is set to be visible. If
4885 FALSE, the cursor is set to be invisible.
4886
4887 @retval EFI_SUCCESS The operation completed successfully.
4888 @retval EFI_DEVICE_ERROR The device had an error and could not complete
4889 the request, or the device does not support
4890 changing the cursor mode.
4891 @retval EFI_UNSUPPORTED The output device is not in a valid text mode.
4892
4893 **/
4894 EFI_STATUS
4895 EFIAPI
4896 ConSplitterTextOutEnableCursor (
4897 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
4898 IN BOOLEAN Visible
4899 )
4900 {
4901 EFI_STATUS Status;
4902 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
4903 UINTN Index;
4904 EFI_STATUS ReturnStatus;
4905
4906 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
4907
4908 //
4909 // return the worst status met
4910 //
4911 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
4912
4913 if (Private->TextOutList[Index].TextOutEnabled) {
4914 Status = Private->TextOutList[Index].TextOut->EnableCursor (
4915 Private->TextOutList[Index].TextOut,
4916 Visible
4917 );
4918 if (EFI_ERROR (Status)) {
4919 ReturnStatus = Status;
4920 }
4921 }
4922 }
4923
4924 DevNullTextOutEnableCursor (Private, Visible);
4925
4926 return ReturnStatus;
4927 }
4928