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