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