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