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