]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Universal/Console/ConSplitter/Dxe/ConSplitter.c
7d1a3fea1d21f7c9d593a829f3d56ea15173ab12
[mirror_edk2.git] / EdkModulePkg / Universal / Console / ConSplitter / Dxe / 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 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_IN_PROTOCOL **) NULL,
45 0,
46
47 {
48 ConSplitterSimplePointerReset,
49 ConSplitterSimplePointerGetState,
50 (EFI_EVENT) NULL,
51 (EFI_SIMPLE_POINTER_MODE *) NULL
52 },
53 {
54 0x10000,
55 0x10000,
56 0x10000,
57 TRUE,
58 TRUE
59 },
60 0,
61 (EFI_SIMPLE_POINTER_PROTOCOL **) NULL,
62 0,
63
64 FALSE,
65 {
66 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
67 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
68 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
69 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
70 },
71 0,
72 {
73 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
74 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
75 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
76 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
77 },
78 (EFI_EVENT) NULL,
79
80 FALSE,
81 FALSE
82 };
83
84 STATIC TEXT_OUT_SPLITTER_PRIVATE_DATA mConOut = {
85 TEXT_OUT_SPLITTER_PRIVATE_DATA_SIGNATURE,
86 (EFI_HANDLE) NULL,
87 {
88 ConSplitterTextOutReset,
89 ConSplitterTextOutOutputString,
90 ConSplitterTextOutTestString,
91 ConSplitterTextOutQueryMode,
92 ConSplitterTextOutSetMode,
93 ConSplitterTextOutSetAttribute,
94 ConSplitterTextOutClearScreen,
95 ConSplitterTextOutSetCursorPosition,
96 ConSplitterTextOutEnableCursor,
97 (EFI_SIMPLE_TEXT_OUTPUT_MODE *) NULL
98 },
99 {
100 1,
101 0,
102 0,
103 0,
104 0,
105 FALSE,
106 },
107 #if (EFI_SPECIFICATION_VERSION < 0x00020000)
108 {
109 ConSpliterUgaDrawGetMode,
110 ConSpliterUgaDrawSetMode,
111 ConSpliterUgaDrawBlt
112 },
113 0,
114 0,
115 0,
116 0,
117 (EFI_UGA_PIXEL *) NULL,
118 #else
119 {
120 ConSpliterGraphicsOutputQueryMode,
121 ConSpliterGraphicsOutputSetMode,
122 ConSpliterGraphicsOutputBlt,
123 NULL
124 },
125 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) NULL,
126 (TEXT_OUT_GOP_MODE *) NULL,
127 0,
128 TRUE,
129 #endif
130 {
131 ConSpliterConsoleControlGetMode,
132 ConSpliterConsoleControlSetMode,
133 ConSpliterConsoleControlLockStdIn
134 },
135
136 0,
137 (TEXT_OUT_AND_GOP_DATA *) NULL,
138 0,
139 (TEXT_OUT_SPLITTER_QUERY_DATA *) NULL,
140 0,
141 (INT32 *) NULL,
142
143 EfiConsoleControlScreenText,
144 0,
145 0,
146 (CHAR16 *) NULL,
147 (INT32 *) NULL
148 };
149
150 STATIC TEXT_OUT_SPLITTER_PRIVATE_DATA mStdErr = {
151 TEXT_OUT_SPLITTER_PRIVATE_DATA_SIGNATURE,
152 (EFI_HANDLE) NULL,
153 {
154 ConSplitterTextOutReset,
155 ConSplitterTextOutOutputString,
156 ConSplitterTextOutTestString,
157 ConSplitterTextOutQueryMode,
158 ConSplitterTextOutSetMode,
159 ConSplitterTextOutSetAttribute,
160 ConSplitterTextOutClearScreen,
161 ConSplitterTextOutSetCursorPosition,
162 ConSplitterTextOutEnableCursor,
163 (EFI_SIMPLE_TEXT_OUTPUT_MODE *) NULL
164 },
165 {
166 1,
167 0,
168 0,
169 0,
170 0,
171 FALSE,
172 },
173 #if (EFI_SPECIFICATION_VERSION < 0x00020000)
174 {
175 ConSpliterUgaDrawGetMode,
176 ConSpliterUgaDrawSetMode,
177 ConSpliterUgaDrawBlt
178 },
179 0,
180 0,
181 0,
182 0,
183 (EFI_UGA_PIXEL *) NULL,
184 #else
185 {
186 ConSpliterGraphicsOutputQueryMode,
187 ConSpliterGraphicsOutputSetMode,
188 ConSpliterGraphicsOutputBlt,
189 NULL
190 },
191 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) NULL,
192 (TEXT_OUT_GOP_MODE *) NULL,
193 0,
194 TRUE,
195 #endif
196 {
197 ConSpliterConsoleControlGetMode,
198 ConSpliterConsoleControlSetMode,
199 ConSpliterConsoleControlLockStdIn
200 },
201
202 0,
203 (TEXT_OUT_AND_GOP_DATA *) NULL,
204 0,
205 (TEXT_OUT_SPLITTER_QUERY_DATA *) NULL,
206 0,
207 (INT32 *) NULL,
208
209 EfiConsoleControlScreenText,
210 0,
211 0,
212 (CHAR16 *) NULL,
213 (INT32 *) NULL
214 };
215
216 EFI_DRIVER_BINDING_PROTOCOL gConSplitterConInDriverBinding = {
217 ConSplitterConInDriverBindingSupported,
218 ConSplitterConInDriverBindingStart,
219 ConSplitterConInDriverBindingStop,
220 0xa,
221 NULL,
222 NULL
223 };
224
225 EFI_DRIVER_BINDING_PROTOCOL gConSplitterSimplePointerDriverBinding = {
226 ConSplitterSimplePointerDriverBindingSupported,
227 ConSplitterSimplePointerDriverBindingStart,
228 ConSplitterSimplePointerDriverBindingStop,
229 0xa,
230 NULL,
231 NULL
232 };
233
234 EFI_DRIVER_BINDING_PROTOCOL gConSplitterConOutDriverBinding = {
235 ConSplitterConOutDriverBindingSupported,
236 ConSplitterConOutDriverBindingStart,
237 ConSplitterConOutDriverBindingStop,
238 0xa,
239 NULL,
240 NULL
241 };
242
243 EFI_DRIVER_BINDING_PROTOCOL gConSplitterStdErrDriverBinding = {
244 ConSplitterStdErrDriverBindingSupported,
245 ConSplitterStdErrDriverBindingStart,
246 ConSplitterStdErrDriverBindingStop,
247 0xa,
248 NULL,
249 NULL
250 };
251
252 EFI_STATUS
253 EFIAPI
254 ConSplitterDriverEntry (
255 IN EFI_HANDLE ImageHandle,
256 IN EFI_SYSTEM_TABLE *SystemTable
257 )
258 /*++
259
260 Routine Description:
261 Intialize a virtual console device to act as an agrigator of physical console
262 devices.
263
264 Arguments:
265 ImageHandle - (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
266 SystemTable - (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
267 Returns:
268 EFI_SUCCESS
269
270 --*/
271 {
272 EFI_STATUS Status;
273
274 //
275 // The driver creates virtual handles for ConIn, ConOut, and StdErr.
276 // The virtual handles will always exist even if no console exist in the
277 // system. This is need to support hotplug devices like USB.
278 //
279 //
280 // Create virtual device handle for StdErr Splitter
281 //
282 Status = ConSplitterTextOutConstructor (&mStdErr);
283 if (!EFI_ERROR (Status)) {
284 Status = gBS->InstallMultipleProtocolInterfaces (
285 &mStdErr.VirtualHandle,
286 &gEfiSimpleTextOutProtocolGuid,
287 &mStdErr.TextOut,
288 &gEfiPrimaryStandardErrorDeviceGuid,
289 NULL,
290 NULL
291 );
292 }
293 //
294 // Create virtual device handle for ConIn Splitter
295 //
296 Status = ConSplitterTextInConstructor (&mConIn);
297 if (!EFI_ERROR (Status)) {
298 Status = gBS->InstallMultipleProtocolInterfaces (
299 &mConIn.VirtualHandle,
300 &gEfiSimpleTextInProtocolGuid,
301 &mConIn.TextIn,
302 &gEfiSimplePointerProtocolGuid,
303 &mConIn.SimplePointer,
304 &gEfiPrimaryConsoleInDeviceGuid,
305 NULL,
306 NULL
307 );
308 if (!EFI_ERROR (Status)) {
309 //
310 // Update the EFI System Table with new virtual console
311 //
312 gST->ConsoleInHandle = mConIn.VirtualHandle;
313 gST->ConIn = &mConIn.TextIn;
314 }
315 }
316 //
317 // Create virtual device handle for ConOut Splitter
318 //
319 Status = ConSplitterTextOutConstructor (&mConOut);
320 if (!EFI_ERROR (Status)) {
321 #if (EFI_SPECIFICATION_VERSION < 0x00020000)
322 //
323 // In EFI mode, UGA Draw protocol is installed
324 //
325 Status = gBS->InstallMultipleProtocolInterfaces (
326 &mConOut.VirtualHandle,
327 &gEfiSimpleTextOutProtocolGuid,
328 &mConOut.TextOut,
329 &gEfiUgaDrawProtocolGuid,
330 &mConOut.UgaDraw,
331 &gEfiConsoleControlProtocolGuid,
332 &mConOut.ConsoleControl,
333 &gEfiPrimaryConsoleOutDeviceGuid,
334 NULL,
335 NULL
336 );
337 #else
338 //
339 // In UEFI mode, Graphics Output Protocol is installed on virtual handle.
340 //
341 Status = gBS->InstallMultipleProtocolInterfaces (
342 &mConOut.VirtualHandle,
343 &gEfiSimpleTextOutProtocolGuid,
344 &mConOut.TextOut,
345 &gEfiGraphicsOutputProtocolGuid,
346 &mConOut.GraphicsOutput,
347 &gEfiConsoleControlProtocolGuid,
348 &mConOut.ConsoleControl,
349 &gEfiPrimaryConsoleOutDeviceGuid,
350 NULL,
351 NULL
352 );
353 #endif
354
355 if (!EFI_ERROR (Status)) {
356 //
357 // Update the EFI System Table with new virtual console
358 //
359 gST->ConsoleOutHandle = mConOut.VirtualHandle;
360 gST->ConOut = &mConOut.TextOut;
361 }
362
363 }
364 //
365 // Update the CRC32 in the EFI System Table header
366 //
367 gST->Hdr.CRC32 = 0;
368 gBS->CalculateCrc32 (
369 (UINT8 *) &gST->Hdr,
370 gST->Hdr.HeaderSize,
371 &gST->Hdr.CRC32
372 );
373
374 return EFI_SUCCESS;
375 }
376
377 EFI_STATUS
378 ConSplitterTextInConstructor (
379 TEXT_IN_SPLITTER_PRIVATE_DATA *ConInPrivate
380 )
381 /*++
382
383 Routine Description:
384
385 Construct the ConSplitter.
386
387 Arguments:
388
389 ConInPrivate - A pointer to the TEXT_IN_SPLITTER_PRIVATE_DATA structure.
390
391 Returns:
392 EFI_OUT_OF_RESOURCES - Out of resources.
393
394 --*/
395 {
396 EFI_STATUS Status;
397
398 //
399 // Initilize console input splitter's private data.
400 //
401 Status = ConSplitterGrowBuffer (
402 sizeof (EFI_SIMPLE_TEXT_IN_PROTOCOL *),
403 &ConInPrivate->TextInListCount,
404 (VOID **) &ConInPrivate->TextInList
405 );
406 if (EFI_ERROR (Status)) {
407 return EFI_OUT_OF_RESOURCES;
408 }
409 //
410 // Create Event to support locking StdIn Device
411 //
412 Status = gBS->CreateEvent (
413 EFI_EVENT_TIMER | EFI_EVENT_NOTIFY_SIGNAL,
414 EFI_TPL_CALLBACK,
415 ConSpliterConsoleControlLockStdInEvent,
416 NULL,
417 &ConInPrivate->LockEvent
418 );
419 ASSERT_EFI_ERROR (Status);
420
421 Status = gBS->CreateEvent (
422 EFI_EVENT_NOTIFY_WAIT,
423 EFI_TPL_NOTIFY,
424 ConSplitterTextInWaitForKey,
425 ConInPrivate,
426 &ConInPrivate->TextIn.WaitForKey
427 );
428 ASSERT_EFI_ERROR (Status);
429
430 ConInPrivate->SimplePointer.Mode = &ConInPrivate->SimplePointerMode;
431
432 Status = ConSplitterGrowBuffer (
433 sizeof (EFI_SIMPLE_POINTER_PROTOCOL *),
434 &ConInPrivate->PointerListCount,
435 (VOID **) &ConInPrivate->PointerList
436 );
437 if (EFI_ERROR (Status)) {
438 return EFI_OUT_OF_RESOURCES;
439 }
440
441 Status = gBS->CreateEvent (
442 EFI_EVENT_NOTIFY_WAIT,
443 EFI_TPL_NOTIFY,
444 ConSplitterSimplePointerWaitForInput,
445 ConInPrivate,
446 &ConInPrivate->SimplePointer.WaitForInput
447 );
448
449 return Status;
450 }
451
452 EFI_STATUS
453 ConSplitterTextOutConstructor (
454 TEXT_OUT_SPLITTER_PRIVATE_DATA *ConOutPrivate
455 )
456 {
457 EFI_STATUS Status;
458
459 //
460 // Initilize console output splitter's private data.
461 //
462 ConOutPrivate->TextOut.Mode = &ConOutPrivate->TextOutMode;
463
464 Status = ConSplitterGrowBuffer (
465 sizeof (TEXT_OUT_AND_GOP_DATA),
466 &ConOutPrivate->TextOutListCount,
467 (VOID **) &ConOutPrivate->TextOutList
468 );
469 if (EFI_ERROR (Status)) {
470 return EFI_OUT_OF_RESOURCES;
471 }
472
473 Status = ConSplitterGrowBuffer (
474 sizeof (TEXT_OUT_SPLITTER_QUERY_DATA),
475 &ConOutPrivate->TextOutQueryDataCount,
476 (VOID **) &ConOutPrivate->TextOutQueryData
477 );
478 if (EFI_ERROR (Status)) {
479 return EFI_OUT_OF_RESOURCES;
480 }
481 //
482 // Setup the DevNullTextOut console to 80 x 25
483 //
484 ConOutPrivate->TextOutQueryData[0].Columns = 80;
485 ConOutPrivate->TextOutQueryData[0].Rows = 25;
486 DevNullTextOutSetMode (ConOutPrivate, 0);
487
488 #if (EFI_SPECIFICATION_VERSION < 0x00020000)
489 //
490 // Setup the DevNullUgaDraw to 800 x 600 x 32 bits per pixel
491 //
492 ConSpliterUgaDrawSetMode (&ConOutPrivate->UgaDraw, 800, 600, 32, 60);
493 #else
494 //
495 // Setup resource for mode information in Graphics Output Protocol interface
496 //
497 if ((ConOutPrivate->GraphicsOutput.Mode = AllocateZeroPool (sizeof (EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE))) == NULL) {
498 return EFI_OUT_OF_RESOURCES;
499 }
500 if ((ConOutPrivate->GraphicsOutput.Mode->Info = AllocateZeroPool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION))) == NULL) {
501 return EFI_OUT_OF_RESOURCES;
502 }
503 //
504 // Setup the DevNullGraphicsOutput to 800 x 600 x 32 bits per pixel
505 //
506 if ((ConOutPrivate->GraphicsOutputModeBuffer = AllocateZeroPool (sizeof (TEXT_OUT_GOP_MODE))) == NULL) {
507 return EFI_OUT_OF_RESOURCES;
508 }
509 ConOutPrivate->GraphicsOutputModeBuffer[0].HorizontalResolution = 800;
510 ConOutPrivate->GraphicsOutputModeBuffer[0].VerticalResolution = 600;
511
512 //
513 // Initialize the following items, theset items remain unchanged in GraphicsOutput->SetMode()
514 // GraphicsOutputMode->Info->Version, GraphicsOutputMode->Info->PixelFormat
515 // GraphicsOutputMode->SizeOfInfo, GraphicsOutputMode->FrameBufferBase, GraphicsOutputMode->FrameBufferSize
516 //
517 ConOutPrivate->GraphicsOutput.Mode->Info->Version = 0;
518 ConOutPrivate->GraphicsOutput.Mode->Info->PixelFormat = PixelBltOnly;
519 ConOutPrivate->GraphicsOutput.Mode->SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
520 ConOutPrivate->GraphicsOutput.Mode->FrameBufferBase = (EFI_PHYSICAL_ADDRESS) NULL;
521 ConOutPrivate->GraphicsOutput.Mode->FrameBufferSize = 0;
522
523 ConOutPrivate->GraphicsOutput.Mode->MaxMode = 1;
524 //
525 // Initial current mode to unknow state, and then set to mode 0
526 //
527 ConOutPrivate->GraphicsOutput.Mode->Mode = 0xffff;
528 ConOutPrivate->GraphicsOutput.SetMode (&ConOutPrivate->GraphicsOutput, 0);
529 #endif
530
531 return Status;
532 }
533
534 STATIC
535 EFI_STATUS
536 ConSplitterSupported (
537 IN EFI_DRIVER_BINDING_PROTOCOL *This,
538 IN EFI_HANDLE ControllerHandle,
539 IN EFI_GUID *Guid
540 )
541 /*++
542
543 Routine Description:
544 Generic Supported Check
545
546 Arguments:
547 This - Pointer to protocol.
548 ControllerHandle - Controller Handle.
549 Guid - Guid.
550
551 Returns:
552
553 EFI_UNSUPPORTED - unsupported.
554 EFI_SUCCESS - operation is OK.
555
556 --*/
557 {
558 EFI_STATUS Status;
559 VOID *Instance;
560
561 //
562 // Make sure the Console Splitter does not attempt to attach to itself
563 //
564 if (ControllerHandle == mConIn.VirtualHandle) {
565 return EFI_UNSUPPORTED;
566 }
567
568 if (ControllerHandle == mConOut.VirtualHandle) {
569 return EFI_UNSUPPORTED;
570 }
571
572 if (ControllerHandle == mStdErr.VirtualHandle) {
573 return EFI_UNSUPPORTED;
574 }
575 //
576 // Check to see whether the handle has the ConsoleInDevice GUID on it
577 //
578 Status = gBS->OpenProtocol (
579 ControllerHandle,
580 Guid,
581 &Instance,
582 This->DriverBindingHandle,
583 ControllerHandle,
584 EFI_OPEN_PROTOCOL_BY_DRIVER
585 );
586
587 if (EFI_ERROR (Status)) {
588 return Status;
589 }
590
591 gBS->CloseProtocol (
592 ControllerHandle,
593 Guid,
594 This->DriverBindingHandle,
595 ControllerHandle
596 );
597
598 return EFI_SUCCESS;
599 }
600
601 EFI_STATUS
602 EFIAPI
603 ConSplitterConInDriverBindingSupported (
604 IN EFI_DRIVER_BINDING_PROTOCOL *This,
605 IN EFI_HANDLE ControllerHandle,
606 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
607 )
608 /*++
609
610 Routine Description:
611 Console In Supported Check
612
613 Arguments:
614 This - Pointer to protocol.
615 ControllerHandle - Controller handle.
616 RemainingDevicePath - Remaining device path.
617
618 Returns:
619
620 EFI_STATUS
621
622 --*/
623 {
624 return ConSplitterSupported (
625 This,
626 ControllerHandle,
627 &gEfiConsoleInDeviceGuid
628 );
629 }
630
631 EFI_STATUS
632 EFIAPI
633 ConSplitterSimplePointerDriverBindingSupported (
634 IN EFI_DRIVER_BINDING_PROTOCOL *This,
635 IN EFI_HANDLE ControllerHandle,
636 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
637 )
638 /*++
639
640 Routine Description:
641 Standard Error Supported Check
642
643 Arguments:
644 This - Pointer to protocol.
645 ControllerHandle - Controller handle.
646 RemainingDevicePath - Remaining device path.
647
648 Returns:
649
650 EFI_STATUS
651
652 --*/
653 {
654 return ConSplitterSupported (
655 This,
656 ControllerHandle,
657 &gEfiSimplePointerProtocolGuid
658 );
659 }
660
661 EFI_STATUS
662 EFIAPI
663 ConSplitterConOutDriverBindingSupported (
664 IN EFI_DRIVER_BINDING_PROTOCOL *This,
665 IN EFI_HANDLE ControllerHandle,
666 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
667 )
668 /*++
669
670 Routine Description:
671 Console Out Supported Check
672
673 Arguments:
674 This - Pointer to protocol.
675 ControllerHandle - Controller handle.
676 RemainingDevicePath - Remaining device path.
677
678 Returns:
679
680 EFI_STATUS
681
682 --*/
683 {
684 return ConSplitterSupported (
685 This,
686 ControllerHandle,
687 &gEfiConsoleOutDeviceGuid
688 );
689 }
690
691 EFI_STATUS
692 EFIAPI
693 ConSplitterStdErrDriverBindingSupported (
694 IN EFI_DRIVER_BINDING_PROTOCOL *This,
695 IN EFI_HANDLE ControllerHandle,
696 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
697 )
698 /*++
699
700 Routine Description:
701 Standard Error Supported Check
702
703 Arguments:
704 This - Pointer to protocol.
705 ControllerHandle - Controller handle.
706 RemainingDevicePath - Remaining device path.
707
708 Returns:
709
710 EFI_STATUS
711
712 --*/
713 {
714 return ConSplitterSupported (
715 This,
716 ControllerHandle,
717 &gEfiStandardErrorDeviceGuid
718 );
719 }
720
721 STATIC
722 EFI_STATUS
723 EFIAPI
724 ConSplitterStart (
725 IN EFI_DRIVER_BINDING_PROTOCOL *This,
726 IN EFI_HANDLE ControllerHandle,
727 IN EFI_HANDLE ConSplitterVirtualHandle,
728 IN EFI_GUID *DeviceGuid,
729 IN EFI_GUID *InterfaceGuid,
730 IN VOID **Interface
731 )
732 /*++
733
734 Routine Description:
735 Start ConSplitter on ControllerHandle, and create the virtual
736 agrogated console device on first call Start for a SimpleTextIn handle.
737
738 Arguments:
739 (Standard DriverBinding Protocol Start() function)
740
741 Returns:
742 EFI_ERROR if a SimpleTextIn protocol is not started.
743
744 --*/
745 {
746 EFI_STATUS Status;
747 VOID *Instance;
748
749 //
750 // Check to see whether the handle has the ConsoleInDevice GUID on it
751 //
752 Status = gBS->OpenProtocol (
753 ControllerHandle,
754 DeviceGuid,
755 &Instance,
756 This->DriverBindingHandle,
757 ControllerHandle,
758 EFI_OPEN_PROTOCOL_BY_DRIVER
759 );
760 if (EFI_ERROR (Status)) {
761 return Status;
762 }
763
764 Status = gBS->OpenProtocol (
765 ControllerHandle,
766 DeviceGuid,
767 &Instance,
768 This->DriverBindingHandle,
769 ConSplitterVirtualHandle,
770 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
771 );
772 if (EFI_ERROR (Status)) {
773 return Status;
774 }
775
776 return gBS->OpenProtocol (
777 ControllerHandle,
778 InterfaceGuid,
779 Interface,
780 This->DriverBindingHandle,
781 ConSplitterVirtualHandle,
782 EFI_OPEN_PROTOCOL_GET_PROTOCOL
783 );
784 }
785
786 EFI_STATUS
787 EFIAPI
788 ConSplitterConInDriverBindingStart (
789 IN EFI_DRIVER_BINDING_PROTOCOL *This,
790 IN EFI_HANDLE ControllerHandle,
791 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
792 )
793 /*++
794
795 Routine Description:
796 Start ConSplitter on ControllerHandle, and create the virtual
797 agrogated console device on first call Start for a SimpleTextIn handle.
798
799 Arguments:
800 This - Pointer to protocol.
801 ControllerHandle - Controller handle.
802 RemainingDevicePath - Remaining device path.
803
804 Returns:
805
806 EFI_STATUS
807 EFI_ERROR if a SimpleTextIn protocol is not started.
808
809 --*/
810 {
811 EFI_STATUS Status;
812 EFI_SIMPLE_TEXT_IN_PROTOCOL *TextIn;
813
814 //
815 // Start ConSplitter on ControllerHandle, and create the virtual
816 // agrogated console device on first call Start for a SimpleTextIn handle.
817 //
818 Status = ConSplitterStart (
819 This,
820 ControllerHandle,
821 mConIn.VirtualHandle,
822 &gEfiConsoleInDeviceGuid,
823 &gEfiSimpleTextInProtocolGuid,
824 (VOID **) &TextIn
825 );
826 if (EFI_ERROR (Status)) {
827 return Status;
828 }
829
830 return ConSplitterTextInAddDevice (&mConIn, TextIn);
831 }
832
833 EFI_STATUS
834 EFIAPI
835 ConSplitterSimplePointerDriverBindingStart (
836 IN EFI_DRIVER_BINDING_PROTOCOL *This,
837 IN EFI_HANDLE ControllerHandle,
838 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
839 )
840 /*++
841
842 Routine Description:
843 Start ConSplitter on ControllerHandle, and create the virtual
844 agrogated console device on first call Start for a SimpleTextIn handle.
845
846 Arguments:
847 This - Pointer to protocol.
848 ControllerHandle - Controller handle.
849 RemainingDevicePath - Remaining device path.
850
851 Returns:
852
853 EFI_ERROR if a SimpleTextIn protocol is not started.
854
855 --*/
856 {
857 EFI_STATUS Status;
858 EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer;
859
860 Status = ConSplitterStart (
861 This,
862 ControllerHandle,
863 mConIn.VirtualHandle,
864 &gEfiSimplePointerProtocolGuid,
865 &gEfiSimplePointerProtocolGuid,
866 (VOID **) &SimplePointer
867 );
868 if (EFI_ERROR (Status)) {
869 return Status;
870 }
871
872 return ConSplitterSimplePointerAddDevice (&mConIn, SimplePointer);
873 }
874
875 EFI_STATUS
876 EFIAPI
877 ConSplitterConOutDriverBindingStart (
878 IN EFI_DRIVER_BINDING_PROTOCOL *This,
879 IN EFI_HANDLE ControllerHandle,
880 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
881 )
882 /*++
883
884 Routine Description:
885 Start ConSplitter on ControllerHandle, and create the virtual
886 agrogated console device on first call Start for a SimpleTextIn handle.
887
888 Arguments:
889 This - Pointer to protocol.
890 ControllerHandle - Controller handle.
891 RemainingDevicePath - Remaining device path.
892
893 Returns:
894 EFI_ERROR if a SimpleTextIn protocol is not started.
895
896 --*/
897 {
898 EFI_STATUS Status;
899 EFI_SIMPLE_TEXT_OUT_PROTOCOL *TextOut;
900 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
901 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
902
903 Status = ConSplitterStart (
904 This,
905 ControllerHandle,
906 mConOut.VirtualHandle,
907 &gEfiConsoleOutDeviceGuid,
908 &gEfiSimpleTextOutProtocolGuid,
909 (VOID **) &TextOut
910 );
911 if (EFI_ERROR (Status)) {
912 return Status;
913 }
914 //
915 // Try to Open Graphics Output protocol
916 //
917 Status = gBS->OpenProtocol (
918 ControllerHandle,
919 &gEfiGraphicsOutputProtocolGuid,
920 (VOID **) &GraphicsOutput,
921 This->DriverBindingHandle,
922 mConOut.VirtualHandle,
923 EFI_OPEN_PROTOCOL_GET_PROTOCOL
924 );
925 if (EFI_ERROR (Status)) {
926 GraphicsOutput = NULL;
927 }
928 //
929 // Open UGA_DRAW protocol
930 //
931 Status = gBS->OpenProtocol (
932 ControllerHandle,
933 &gEfiUgaDrawProtocolGuid,
934 (VOID **) &UgaDraw,
935 This->DriverBindingHandle,
936 mConOut.VirtualHandle,
937 EFI_OPEN_PROTOCOL_GET_PROTOCOL
938 );
939 if (EFI_ERROR (Status)) {
940 UgaDraw = NULL;
941 }
942 //
943 // If both ConOut and StdErr incorporate the same Text Out device,
944 // their MaxMode and QueryData should be the intersection of both.
945 //
946 Status = ConSplitterTextOutAddDevice (&mConOut, TextOut, GraphicsOutput, UgaDraw);
947 ConSplitterTextOutSetAttribute (&mConOut.TextOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
948
949 #if (EFI_SPECIFICATION_VERSION < 0x00020000)
950 //
951 // Match the UGA mode data of ConOut with the current mode
952 //
953 if (UgaDraw != NULL) {
954 UgaDraw->GetMode (
955 UgaDraw,
956 &mConOut.UgaHorizontalResolution,
957 &mConOut.UgaVerticalResolution,
958 &mConOut.UgaColorDepth,
959 &mConOut.UgaRefreshRate
960 );
961 }
962 #endif
963
964 return Status;
965 }
966
967 EFI_STATUS
968 EFIAPI
969 ConSplitterStdErrDriverBindingStart (
970 IN EFI_DRIVER_BINDING_PROTOCOL *This,
971 IN EFI_HANDLE ControllerHandle,
972 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
973 )
974 /*++
975
976 Routine Description:
977 Start ConSplitter on ControllerHandle, and create the virtual
978 agrogated console device on first call Start for a SimpleTextIn handle.
979
980 Arguments:
981 This - Pointer to protocol.
982 ControllerHandle - Controller handle.
983 RemainingDevicePath - Remaining device path.
984
985 Returns:
986 EFI_ERROR if a SimpleTextIn protocol is not started.
987
988 --*/
989 {
990 EFI_STATUS Status;
991 EFI_SIMPLE_TEXT_OUT_PROTOCOL *TextOut;
992
993 Status = ConSplitterStart (
994 This,
995 ControllerHandle,
996 mStdErr.VirtualHandle,
997 &gEfiStandardErrorDeviceGuid,
998 &gEfiSimpleTextOutProtocolGuid,
999 (VOID **) &TextOut
1000 );
1001 if (EFI_ERROR (Status)) {
1002 return Status;
1003 }
1004 //
1005 // If both ConOut and StdErr incorporate the same Text Out device,
1006 // their MaxMode and QueryData should be the intersection of both.
1007 //
1008 Status = ConSplitterTextOutAddDevice (&mStdErr, TextOut, NULL, NULL);
1009 ConSplitterTextOutSetAttribute (&mStdErr.TextOut, EFI_TEXT_ATTR (EFI_MAGENTA, EFI_BLACK));
1010 if (EFI_ERROR (Status)) {
1011 return Status;
1012 }
1013
1014 if (mStdErr.CurrentNumberOfConsoles == 1) {
1015 gST->StandardErrorHandle = mStdErr.VirtualHandle;
1016 gST->StdErr = &mStdErr.TextOut;
1017 //
1018 // Update the CRC32 in the EFI System Table header
1019 //
1020 gST->Hdr.CRC32 = 0;
1021 gBS->CalculateCrc32 (
1022 (UINT8 *) &gST->Hdr,
1023 gST->Hdr.HeaderSize,
1024 &gST->Hdr.CRC32
1025 );
1026 }
1027
1028 return Status;
1029 }
1030
1031 STATIC
1032 EFI_STATUS
1033 EFIAPI
1034 ConSplitterStop (
1035 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1036 IN EFI_HANDLE ControllerHandle,
1037 IN EFI_HANDLE ConSplitterVirtualHandle,
1038 IN EFI_GUID *DeviceGuid,
1039 IN EFI_GUID *InterfaceGuid,
1040 IN VOID **Interface
1041 )
1042 /*++
1043
1044 Routine Description:
1045
1046 Arguments:
1047 (Standard DriverBinding Protocol Stop() function)
1048
1049 Returns:
1050
1051 None
1052
1053 --*/
1054 {
1055 EFI_STATUS Status;
1056
1057 Status = gBS->OpenProtocol (
1058 ControllerHandle,
1059 InterfaceGuid,
1060 Interface,
1061 This->DriverBindingHandle,
1062 ControllerHandle,
1063 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1064 );
1065 if (EFI_ERROR (Status)) {
1066 return Status;
1067 }
1068 //
1069 // close the protocol refered.
1070 //
1071 gBS->CloseProtocol (
1072 ControllerHandle,
1073 DeviceGuid,
1074 This->DriverBindingHandle,
1075 ConSplitterVirtualHandle
1076 );
1077 gBS->CloseProtocol (
1078 ControllerHandle,
1079 DeviceGuid,
1080 This->DriverBindingHandle,
1081 ControllerHandle
1082 );
1083
1084 return EFI_SUCCESS;
1085 }
1086
1087 EFI_STATUS
1088 EFIAPI
1089 ConSplitterConInDriverBindingStop (
1090 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1091 IN EFI_HANDLE ControllerHandle,
1092 IN UINTN NumberOfChildren,
1093 IN EFI_HANDLE *ChildHandleBuffer
1094 )
1095 /*++
1096
1097 Routine Description:
1098
1099 Arguments:
1100 (Standard DriverBinding Protocol Stop() function)
1101
1102 Returns:
1103
1104 None
1105
1106 --*/
1107 {
1108 EFI_STATUS Status;
1109 EFI_SIMPLE_TEXT_IN_PROTOCOL *TextIn;
1110
1111 if (NumberOfChildren == 0) {
1112 return EFI_SUCCESS;
1113 }
1114
1115 Status = ConSplitterStop (
1116 This,
1117 ControllerHandle,
1118 mConIn.VirtualHandle,
1119 &gEfiConsoleInDeviceGuid,
1120 &gEfiSimpleTextInProtocolGuid,
1121 (VOID **) &TextIn
1122 );
1123 if (EFI_ERROR (Status)) {
1124 return Status;
1125 }
1126 //
1127 // Delete this console input device's data structures.
1128 //
1129 return ConSplitterTextInDeleteDevice (&mConIn, TextIn);
1130 }
1131
1132 EFI_STATUS
1133 EFIAPI
1134 ConSplitterSimplePointerDriverBindingStop (
1135 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1136 IN EFI_HANDLE ControllerHandle,
1137 IN UINTN NumberOfChildren,
1138 IN EFI_HANDLE *ChildHandleBuffer
1139 )
1140 /*++
1141
1142 Routine Description:
1143
1144 Arguments:
1145 (Standard DriverBinding Protocol Stop() function)
1146
1147 Returns:
1148
1149 None
1150
1151 --*/
1152 {
1153 EFI_STATUS Status;
1154 EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer;
1155
1156 if (NumberOfChildren == 0) {
1157 return EFI_SUCCESS;
1158 }
1159
1160 Status = ConSplitterStop (
1161 This,
1162 ControllerHandle,
1163 mConIn.VirtualHandle,
1164 &gEfiSimplePointerProtocolGuid,
1165 &gEfiSimplePointerProtocolGuid,
1166 (VOID **) &SimplePointer
1167 );
1168 if (EFI_ERROR (Status)) {
1169 return Status;
1170 }
1171 //
1172 // Delete this console input device's data structures.
1173 //
1174 return ConSplitterSimplePointerDeleteDevice (&mConIn, SimplePointer);
1175 }
1176
1177 EFI_STATUS
1178 EFIAPI
1179 ConSplitterConOutDriverBindingStop (
1180 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1181 IN EFI_HANDLE ControllerHandle,
1182 IN UINTN NumberOfChildren,
1183 IN EFI_HANDLE *ChildHandleBuffer
1184 )
1185 /*++
1186
1187 Routine Description:
1188
1189 Arguments:
1190 (Standard DriverBinding Protocol Stop() function)
1191
1192 Returns:
1193
1194 None
1195
1196 --*/
1197 {
1198 EFI_STATUS Status;
1199 EFI_SIMPLE_TEXT_OUT_PROTOCOL *TextOut;
1200
1201 if (NumberOfChildren == 0) {
1202 return EFI_SUCCESS;
1203 }
1204
1205 Status = ConSplitterStop (
1206 This,
1207 ControllerHandle,
1208 mConOut.VirtualHandle,
1209 &gEfiConsoleOutDeviceGuid,
1210 &gEfiSimpleTextOutProtocolGuid,
1211 (VOID **) &TextOut
1212 );
1213 if (EFI_ERROR (Status)) {
1214 return Status;
1215 }
1216
1217 //
1218 // Delete this console output device's data structures.
1219 //
1220 return ConSplitterTextOutDeleteDevice (&mConOut, TextOut);
1221 }
1222
1223 EFI_STATUS
1224 EFIAPI
1225 ConSplitterStdErrDriverBindingStop (
1226 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1227 IN EFI_HANDLE ControllerHandle,
1228 IN UINTN NumberOfChildren,
1229 IN EFI_HANDLE *ChildHandleBuffer
1230 )
1231 /*++
1232
1233 Routine Description:
1234
1235 Arguments:
1236 (Standard DriverBinding Protocol Stop() function)
1237
1238 Returns:
1239
1240 EFI_SUCCESS - Complete successfully.
1241
1242 --*/
1243 {
1244 EFI_STATUS Status;
1245 EFI_SIMPLE_TEXT_OUT_PROTOCOL *TextOut;
1246
1247 if (NumberOfChildren == 0) {
1248 return EFI_SUCCESS;
1249 }
1250
1251 Status = ConSplitterStop (
1252 This,
1253 ControllerHandle,
1254 mStdErr.VirtualHandle,
1255 &gEfiStandardErrorDeviceGuid,
1256 &gEfiSimpleTextOutProtocolGuid,
1257 (VOID **) &TextOut
1258 );
1259 if (EFI_ERROR (Status)) {
1260 return Status;
1261 }
1262 //
1263 // Delete this console error out device's data structures.
1264 //
1265 Status = ConSplitterTextOutDeleteDevice (&mStdErr, TextOut);
1266 if (EFI_ERROR (Status)) {
1267 return Status;
1268 }
1269
1270 if (mStdErr.CurrentNumberOfConsoles == 0) {
1271 gST->StandardErrorHandle = NULL;
1272 gST->StdErr = NULL;
1273 //
1274 // Update the CRC32 in the EFI System Table header
1275 //
1276 gST->Hdr.CRC32 = 0;
1277 gBS->CalculateCrc32 (
1278 (UINT8 *) &gST->Hdr,
1279 gST->Hdr.HeaderSize,
1280 &gST->Hdr.CRC32
1281 );
1282 }
1283
1284 return Status;
1285 }
1286
1287 EFI_STATUS
1288 ConSplitterGrowBuffer (
1289 IN UINTN SizeOfCount,
1290 IN UINTN *Count,
1291 IN OUT VOID **Buffer
1292 )
1293 /*++
1294
1295 Routine Description:
1296 Take the passed in Buffer of size SizeOfCount and grow the buffer
1297 by MAX (CONSOLE_SPLITTER_CONSOLES_ALLOC_UNIT, MaxGrow) * SizeOfCount
1298 bytes. Copy the current data in Buffer to the new version of Buffer
1299 and free the old version of buffer.
1300
1301
1302 Arguments:
1303 SizeOfCount - Size of element in array
1304 Count - Current number of elements in array
1305 Buffer - Bigger version of passed in Buffer with all the data
1306
1307 Returns:
1308 EFI_SUCCESS - Buffer size has grown
1309 EFI_OUT_OF_RESOURCES - Could not grow the buffer size
1310
1311 None
1312
1313 --*/
1314 {
1315 UINTN NewSize;
1316 UINTN OldSize;
1317 VOID *Ptr;
1318
1319 //
1320 // grow the buffer to new buffer size,
1321 // copy the old buffer's content to the new-size buffer,
1322 // then free the old buffer.
1323 //
1324 OldSize = *Count * SizeOfCount;
1325 *Count += CONSOLE_SPLITTER_CONSOLES_ALLOC_UNIT;
1326 NewSize = *Count * SizeOfCount;
1327
1328 Ptr = AllocateZeroPool (NewSize);
1329 if (Ptr == NULL) {
1330 return EFI_OUT_OF_RESOURCES;
1331 }
1332
1333 CopyMem (Ptr, *Buffer, OldSize);
1334
1335 if (*Buffer != NULL) {
1336 FreePool (*Buffer);
1337 }
1338
1339 *Buffer = Ptr;
1340
1341 return EFI_SUCCESS;
1342 }
1343
1344 EFI_STATUS
1345 ConSplitterTextInAddDevice (
1346 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
1347 IN EFI_SIMPLE_TEXT_IN_PROTOCOL *TextIn
1348 )
1349 /*++
1350
1351 Routine Description:
1352
1353 Arguments:
1354
1355 Returns:
1356
1357 EFI_SUCCESS
1358 EFI_OUT_OF_RESOURCES
1359
1360 --*/
1361 {
1362 EFI_STATUS Status;
1363
1364 //
1365 // If the Text In List is full, enlarge it by calling growbuffer().
1366 //
1367 if (Private->CurrentNumberOfConsoles >= Private->TextInListCount) {
1368 Status = ConSplitterGrowBuffer (
1369 sizeof (EFI_SIMPLE_TEXT_IN_PROTOCOL *),
1370 &Private->TextInListCount,
1371 (VOID **) &Private->TextInList
1372 );
1373 if (EFI_ERROR (Status)) {
1374 return EFI_OUT_OF_RESOURCES;
1375 }
1376 }
1377 //
1378 // Add the new text-in device data structure into the Text In List.
1379 //
1380 Private->TextInList[Private->CurrentNumberOfConsoles] = TextIn;
1381 Private->CurrentNumberOfConsoles++;
1382
1383 //
1384 // Extra CheckEvent added to reduce the double CheckEvent() in UI.c
1385 //
1386 gBS->CheckEvent (TextIn->WaitForKey);
1387
1388 return EFI_SUCCESS;
1389 }
1390
1391 EFI_STATUS
1392 ConSplitterTextInDeleteDevice (
1393 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
1394 IN EFI_SIMPLE_TEXT_IN_PROTOCOL *TextIn
1395 )
1396 /*++
1397
1398 Routine Description:
1399
1400 Arguments:
1401
1402 Returns:
1403
1404 EFI_SUCCESS
1405 EFI_NOT_FOUND
1406
1407 --*/
1408 {
1409 UINTN Index;
1410 //
1411 // Remove the specified text-in device data structure from the Text In List,
1412 // and rearrange the remaining data structures in the Text In List.
1413 //
1414 for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {
1415 if (Private->TextInList[Index] == TextIn) {
1416 for (Index = Index; Index < Private->CurrentNumberOfConsoles - 1; Index++) {
1417 Private->TextInList[Index] = Private->TextInList[Index + 1];
1418 }
1419
1420 Private->CurrentNumberOfConsoles--;
1421 return EFI_SUCCESS;
1422 }
1423 }
1424
1425 return EFI_NOT_FOUND;
1426 }
1427
1428 EFI_STATUS
1429 ConSplitterSimplePointerAddDevice (
1430 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
1431 IN EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer
1432 )
1433 /*++
1434
1435 Routine Description:
1436
1437 Arguments:
1438
1439 Returns:
1440
1441 EFI_OUT_OF_RESOURCES
1442 EFI_SUCCESS
1443
1444 --*/
1445 {
1446 EFI_STATUS Status;
1447
1448 //
1449 // If the Text In List is full, enlarge it by calling growbuffer().
1450 //
1451 if (Private->CurrentNumberOfPointers >= Private->PointerListCount) {
1452 Status = ConSplitterGrowBuffer (
1453 sizeof (EFI_SIMPLE_POINTER_PROTOCOL *),
1454 &Private->PointerListCount,
1455 (VOID **) &Private->PointerList
1456 );
1457 if (EFI_ERROR (Status)) {
1458 return EFI_OUT_OF_RESOURCES;
1459 }
1460 }
1461 //
1462 // Add the new text-in device data structure into the Text In List.
1463 //
1464 Private->PointerList[Private->CurrentNumberOfPointers] = SimplePointer;
1465 Private->CurrentNumberOfPointers++;
1466 return EFI_SUCCESS;
1467 }
1468
1469 EFI_STATUS
1470 ConSplitterSimplePointerDeleteDevice (
1471 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
1472 IN EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer
1473 )
1474 /*++
1475
1476 Routine Description:
1477
1478 Arguments:
1479
1480 Returns:
1481
1482 None
1483
1484 --*/
1485 {
1486 UINTN Index;
1487 //
1488 // Remove the specified text-in device data structure from the Text In List,
1489 // and rearrange the remaining data structures in the Text In List.
1490 //
1491 for (Index = 0; Index < Private->CurrentNumberOfPointers; Index++) {
1492 if (Private->PointerList[Index] == SimplePointer) {
1493 for (Index = Index; Index < Private->CurrentNumberOfPointers - 1; Index++) {
1494 Private->PointerList[Index] = Private->PointerList[Index + 1];
1495 }
1496
1497 Private->CurrentNumberOfPointers--;
1498 return EFI_SUCCESS;
1499 }
1500 }
1501
1502 return EFI_NOT_FOUND;
1503 }
1504
1505 STATIC
1506 EFI_STATUS
1507 ConSplitterGrowMapTable (
1508 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private
1509 )
1510 /*++
1511
1512 Routine Description:
1513
1514 Arguments:
1515
1516 Returns:
1517
1518 None
1519
1520 --*/
1521 {
1522 UINTN Size;
1523 UINTN NewSize;
1524 UINTN TotalSize;
1525 INT32 *TextOutModeMap;
1526 INT32 *OldTextOutModeMap;
1527 INT32 *SrcAddress;
1528 INT32 Index;
1529
1530 NewSize = Private->TextOutListCount * sizeof (INT32);
1531 OldTextOutModeMap = Private->TextOutModeMap;
1532 TotalSize = NewSize * Private->TextOutQueryDataCount;
1533
1534 TextOutModeMap = AllocateZeroPool (TotalSize);
1535 if (TextOutModeMap == NULL) {
1536 return EFI_OUT_OF_RESOURCES;
1537 }
1538
1539 SetMem (TextOutModeMap, TotalSize, 0xFF);
1540 Private->TextOutModeMap = TextOutModeMap;
1541
1542 //
1543 // If TextOutList has been enlarged, need to realloc the mode map table
1544 // The mode map table is regarded as a two dimension array.
1545 //
1546 // Old New
1547 // 0 ---------> TextOutListCount ----> TextOutListCount
1548 // | -------------------------------------------
1549 // | | | |
1550 // | | | |
1551 // | | | |
1552 // | | | |
1553 // | | | |
1554 // \/ | | |
1555 // -------------------------------------------
1556 // QueryDataCount
1557 //
1558 if (OldTextOutModeMap != NULL) {
1559
1560 Size = Private->CurrentNumberOfConsoles * sizeof (INT32);
1561 Index = 0;
1562 SrcAddress = OldTextOutModeMap;
1563
1564 //
1565 // Copy the old data to the new one
1566 //
1567 while (Index < Private->TextOutMode.MaxMode) {
1568 CopyMem (TextOutModeMap, SrcAddress, Size);
1569 TextOutModeMap += NewSize;
1570 SrcAddress += Size;
1571 Index++;
1572 }
1573 //
1574 // Free the old buffer
1575 //
1576 FreePool (OldTextOutModeMap);
1577 }
1578
1579 return EFI_SUCCESS;
1580 }
1581
1582 STATIC
1583 EFI_STATUS
1584 ConSplitterAddOutputMode (
1585 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
1586 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *TextOut
1587 )
1588 /*++
1589
1590 Routine Description:
1591
1592 Arguments:
1593
1594 Returns:
1595
1596 None
1597
1598 --*/
1599 {
1600 EFI_STATUS Status;
1601 INT32 MaxMode;
1602 INT32 Mode;
1603 UINTN Index;
1604
1605 MaxMode = TextOut->Mode->MaxMode;
1606 Private->TextOutMode.MaxMode = MaxMode;
1607
1608 //
1609 // Grow the buffer if query data buffer is not large enough to
1610 // hold all the mode supported by the first console.
1611 //
1612 while (MaxMode > (INT32) Private->TextOutQueryDataCount) {
1613 Status = ConSplitterGrowBuffer (
1614 sizeof (TEXT_OUT_SPLITTER_QUERY_DATA),
1615 &Private->TextOutQueryDataCount,
1616 (VOID **) &Private->TextOutQueryData
1617 );
1618 if (EFI_ERROR (Status)) {
1619 return EFI_OUT_OF_RESOURCES;
1620 }
1621 }
1622 //
1623 // Allocate buffer for the output mode map
1624 //
1625 Status = ConSplitterGrowMapTable (Private);
1626 if (EFI_ERROR (Status)) {
1627 return EFI_OUT_OF_RESOURCES;
1628 }
1629 //
1630 // As the first textout device, directly add the mode in to QueryData
1631 // and at the same time record the mapping between QueryData and TextOut.
1632 //
1633 Mode = 0;
1634 Index = 0;
1635 while (Mode < MaxMode) {
1636 TextOut->QueryMode (
1637 TextOut,
1638 Mode,
1639 &Private->TextOutQueryData[Mode].Columns,
1640 &Private->TextOutQueryData[Mode].Rows
1641 );
1642 Private->TextOutModeMap[Index] = Mode;
1643 Mode++;
1644 Index += Private->TextOutListCount;
1645 }
1646
1647 return EFI_SUCCESS;
1648 }
1649
1650 STATIC
1651 VOID
1652 ConSplitterGetIntersection (
1653 IN INT32 *TextOutModeMap,
1654 IN INT32 *NewlyAddedMap,
1655 IN UINTN MapStepSize,
1656 IN UINTN NewMapStepSize,
1657 OUT INT32 *MaxMode,
1658 OUT INT32 *CurrentMode
1659 )
1660 {
1661 INT32 Index;
1662 INT32 *CurrentMapEntry;
1663 INT32 *NextMapEntry;
1664 INT32 CurrentMaxMode;
1665 INT32 Mode;
1666
1667 Index = 0;
1668 CurrentMapEntry = TextOutModeMap;
1669 NextMapEntry = TextOutModeMap;
1670 CurrentMaxMode = *MaxMode;
1671 Mode = *CurrentMode;
1672
1673 while (Index < CurrentMaxMode) {
1674 if (*NewlyAddedMap == -1) {
1675 //
1676 // This mode is not supported any more. Remove it. Special care
1677 // must be taken as this remove will also affect current mode;
1678 //
1679 if (Index == *CurrentMode) {
1680 Mode = -1;
1681 } else if (Index < *CurrentMode) {
1682 Mode--;
1683 }
1684 (*MaxMode)--;
1685 } else {
1686 if (CurrentMapEntry != NextMapEntry) {
1687 CopyMem (NextMapEntry, CurrentMapEntry, MapStepSize * sizeof (INT32));
1688 }
1689
1690 NextMapEntry += MapStepSize;
1691 }
1692
1693 CurrentMapEntry += MapStepSize;
1694 NewlyAddedMap += NewMapStepSize;
1695 Index++;
1696 }
1697
1698 *CurrentMode = Mode;
1699
1700 return ;
1701 }
1702
1703 STATIC
1704 VOID
1705 ConSplitterSyncOutputMode (
1706 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
1707 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *TextOut
1708 )
1709 /*++
1710
1711 Routine Description:
1712
1713 Arguments:
1714 Private - Private data structure.
1715 TextOut - Text Out Protocol.
1716 Returns:
1717
1718 None
1719
1720 --*/
1721 {
1722 INT32 CurrentMaxMode;
1723 INT32 Mode;
1724 INT32 Index;
1725 INT32 *TextOutModeMap;
1726 INT32 *MapTable;
1727 TEXT_OUT_SPLITTER_QUERY_DATA *TextOutQueryData;
1728 UINTN Rows;
1729 UINTN Columns;
1730 UINTN StepSize;
1731
1732 //
1733 // Must make sure that current mode won't change even if mode number changes
1734 //
1735 CurrentMaxMode = Private->TextOutMode.MaxMode;
1736 TextOutModeMap = Private->TextOutModeMap;
1737 StepSize = Private->TextOutListCount;
1738 TextOutQueryData = Private->TextOutQueryData;
1739
1740 //
1741 // Query all the mode that the newly added TextOut supports
1742 //
1743 Mode = 0;
1744 MapTable = TextOutModeMap + Private->CurrentNumberOfConsoles;
1745 while (Mode < TextOut->Mode->MaxMode) {
1746 TextOut->QueryMode (TextOut, Mode, &Columns, &Rows);
1747
1748 //
1749 // Search the QueryData database to see if they intersects
1750 //
1751 Index = 0;
1752 while (Index < CurrentMaxMode) {
1753 if ((TextOutQueryData[Index].Rows == Rows) && (TextOutQueryData[Index].Columns == Columns)) {
1754 MapTable[Index * StepSize] = Mode;
1755 break;
1756 }
1757
1758 Index++;
1759 }
1760
1761 Mode++;
1762 }
1763 //
1764 // Now search the TextOutModeMap table to find the intersection of supported
1765 // mode between ConSplitter and the newly added device.
1766 //
1767 ConSplitterGetIntersection (
1768 TextOutModeMap,
1769 MapTable,
1770 StepSize,
1771 StepSize,
1772 &Private->TextOutMode.MaxMode,
1773 &Private->TextOutMode.Mode
1774 );
1775
1776 return ;
1777 }
1778
1779 STATIC
1780 EFI_STATUS
1781 ConSplitterGetIntersectionBetweenConOutAndStrErr (
1782 VOID
1783 )
1784 /*++
1785
1786 Routine Description:
1787
1788 Arguments:
1789
1790 Returns:
1791
1792 None
1793 EFI_OUT_OF_RESOURCES
1794
1795 --*/
1796 {
1797 UINTN ConOutNumOfConsoles;
1798 UINTN StdErrNumOfConsoles;
1799 TEXT_OUT_AND_GOP_DATA *ConOutTextOutList;
1800 TEXT_OUT_AND_GOP_DATA *StdErrTextOutList;
1801 UINTN Indexi;
1802 UINTN Indexj;
1803 UINTN Rows;
1804 UINTN Columns;
1805 INT32 ConOutMaxMode;
1806 INT32 StdErrMaxMode;
1807 INT32 Mode;
1808 INT32 Index;
1809 INT32 *ConOutModeMap;
1810 INT32 *StdErrModeMap;
1811 INT32 *ConOutMapTable;
1812 INT32 *StdErrMapTable;
1813 TEXT_OUT_SPLITTER_QUERY_DATA *ConOutQueryData;
1814 TEXT_OUT_SPLITTER_QUERY_DATA *StdErrQueryData;
1815 BOOLEAN FoundTheSameTextOut;
1816 UINTN ConOutMapTableSize;
1817 UINTN StdErrMapTableSize;
1818
1819 ConOutNumOfConsoles = mConOut.CurrentNumberOfConsoles;
1820 StdErrNumOfConsoles = mStdErr.CurrentNumberOfConsoles;
1821 ConOutTextOutList = mConOut.TextOutList;
1822 StdErrTextOutList = mStdErr.TextOutList;
1823
1824 Indexi = 0;
1825 FoundTheSameTextOut = FALSE;
1826 while ((Indexi < ConOutNumOfConsoles) && (!FoundTheSameTextOut)) {
1827 Indexj = 0;
1828 while (Indexj < StdErrNumOfConsoles) {
1829 if (ConOutTextOutList->TextOut == StdErrTextOutList->TextOut) {
1830 FoundTheSameTextOut = TRUE;
1831 break;
1832 }
1833
1834 Indexj++;
1835 StdErrTextOutList++;
1836 }
1837
1838 Indexi++;
1839 ConOutTextOutList++;
1840 }
1841
1842 if (!FoundTheSameTextOut) {
1843 return EFI_SUCCESS;
1844 }
1845 //
1846 // Must make sure that current mode won't change even if mode number changes
1847 //
1848 ConOutMaxMode = mConOut.TextOutMode.MaxMode;
1849 ConOutModeMap = mConOut.TextOutModeMap;
1850 ConOutQueryData = mConOut.TextOutQueryData;
1851
1852 StdErrMaxMode = mStdErr.TextOutMode.MaxMode;
1853 StdErrModeMap = mStdErr.TextOutModeMap;
1854 StdErrQueryData = mStdErr.TextOutQueryData;
1855
1856 //
1857 // Allocate the map table and set the map table's index to -1.
1858 //
1859 ConOutMapTableSize = ConOutMaxMode * sizeof (INT32);
1860 ConOutMapTable = AllocateZeroPool (ConOutMapTableSize);
1861 if (ConOutMapTable == NULL) {
1862 return EFI_OUT_OF_RESOURCES;
1863 }
1864
1865 SetMem (ConOutMapTable, ConOutMapTableSize, 0xFF);
1866
1867 StdErrMapTableSize = StdErrMaxMode * sizeof (INT32);
1868 StdErrMapTable = AllocateZeroPool (StdErrMapTableSize);
1869 if (StdErrMapTable == NULL) {
1870 return EFI_OUT_OF_RESOURCES;
1871 }
1872
1873 SetMem (StdErrMapTable, StdErrMapTableSize, 0xFF);
1874
1875 //
1876 // Find the intersection of the two set of modes. If they actually intersect, the
1877 // correponding entry in the map table is set to 1.
1878 //
1879 Mode = 0;
1880 while (Mode < ConOutMaxMode) {
1881 //
1882 // Search the other's QueryData database to see if they intersect
1883 //
1884 Index = 0;
1885 Rows = ConOutQueryData[Mode].Rows;
1886 Columns = ConOutQueryData[Mode].Columns;
1887 while (Index < StdErrMaxMode) {
1888 if ((StdErrQueryData[Index].Rows == Rows) && (StdErrQueryData[Index].Columns == Columns)) {
1889 ConOutMapTable[Mode] = 1;
1890 StdErrMapTable[Index] = 1;
1891 break;
1892 }
1893
1894 Index++;
1895 }
1896
1897 Mode++;
1898 }
1899 //
1900 // Now search the TextOutModeMap table to find the intersection of supported
1901 // mode between ConSplitter and the newly added device.
1902 //
1903 ConSplitterGetIntersection (
1904 ConOutModeMap,
1905 ConOutMapTable,
1906 mConOut.TextOutListCount,
1907 1,
1908 &(mConOut.TextOutMode.MaxMode),
1909 &(mConOut.TextOutMode.Mode)
1910 );
1911 if (mConOut.TextOutMode.Mode < 0) {
1912 mConOut.TextOut.SetMode (&(mConOut.TextOut), 0);
1913 }
1914
1915 ConSplitterGetIntersection (
1916 StdErrModeMap,
1917 StdErrMapTable,
1918 mStdErr.TextOutListCount,
1919 1,
1920 &(mStdErr.TextOutMode.MaxMode),
1921 &(mStdErr.TextOutMode.Mode)
1922 );
1923 if (mStdErr.TextOutMode.Mode < 0) {
1924 mStdErr.TextOut.SetMode (&(mStdErr.TextOut), 0);
1925 }
1926
1927 FreePool (ConOutMapTable);
1928 FreePool (StdErrMapTable);
1929
1930 return EFI_SUCCESS;
1931 }
1932
1933 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
1934 STATIC
1935 EFI_STATUS
1936 ConSplitterAddGraphicsOutputMode (
1937 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
1938 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput,
1939 IN EFI_UGA_DRAW_PROTOCOL *UgaDraw
1940 )
1941 /*++
1942
1943 Routine Description:
1944
1945 Arguments:
1946
1947 Returns:
1948
1949 None
1950
1951 --*/
1952 {
1953 EFI_STATUS Status;
1954 UINTN Index;
1955 TEXT_OUT_GOP_MODE *Mode;
1956 UINTN SizeOfInfo;
1957 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
1958 EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *CurrentGraphicsOutputMode;
1959 TEXT_OUT_GOP_MODE *ModeBuffer;
1960 TEXT_OUT_GOP_MODE *MatchedMode;
1961 UINTN NumberIndex;
1962 BOOLEAN Match;
1963
1964 if ((GraphicsOutput == NULL) && (UgaDraw == NULL)) {
1965 return EFI_UNSUPPORTED;
1966 }
1967
1968 CurrentGraphicsOutputMode = Private->GraphicsOutput.Mode;
1969
1970 if (GraphicsOutput != NULL) {
1971 if (Private->CurrentNumberOfGraphicsOutput == 0) {
1972 //
1973 // This is the first Graphics Output device added
1974 //
1975 CurrentGraphicsOutputMode->MaxMode = GraphicsOutput->Mode->MaxMode;
1976 CurrentGraphicsOutputMode->Mode = GraphicsOutput->Mode->Mode;
1977 CopyMem (CurrentGraphicsOutputMode->Info, GraphicsOutput->Mode->Info, GraphicsOutput->Mode->SizeOfInfo);
1978 CurrentGraphicsOutputMode->SizeOfInfo = GraphicsOutput->Mode->SizeOfInfo;
1979 CurrentGraphicsOutputMode->FrameBufferBase = GraphicsOutput->Mode->FrameBufferBase;
1980 CurrentGraphicsOutputMode->FrameBufferSize = GraphicsOutput->Mode->FrameBufferSize;
1981
1982 //
1983 // Allocate resource for the private mode buffer
1984 //
1985 ModeBuffer = AllocatePool (sizeof (TEXT_OUT_GOP_MODE) * GraphicsOutput->Mode->MaxMode);
1986 if (ModeBuffer == NULL) {
1987 return EFI_OUT_OF_RESOURCES;
1988 }
1989 FreePool (Private->GraphicsOutputModeBuffer);
1990 Private->GraphicsOutputModeBuffer = ModeBuffer;
1991
1992 //
1993 // Store all supported display modes to the private mode buffer
1994 //
1995 Mode = ModeBuffer;
1996 for (Index = 0; Index < GraphicsOutput->Mode->MaxMode; Index++) {
1997 Status = GraphicsOutput->QueryMode (GraphicsOutput, (UINT32) Index, &SizeOfInfo, &Info);
1998 if (EFI_ERROR (Status)) {
1999 return Status;
2000 }
2001 Mode->HorizontalResolution = Info->HorizontalResolution;
2002 Mode->VerticalResolution = Info->VerticalResolution;
2003 Mode++;
2004 FreePool (Info);
2005 }
2006 } else {
2007 //
2008 // Check intersection of display mode
2009 //
2010 ModeBuffer = AllocatePool (sizeof (TEXT_OUT_GOP_MODE) * CurrentGraphicsOutputMode->MaxMode);
2011 if (ModeBuffer == NULL) {
2012 return EFI_OUT_OF_RESOURCES;
2013 }
2014
2015 MatchedMode = ModeBuffer;
2016 Mode = &Private->GraphicsOutputModeBuffer[0];
2017 for (Index = 0; Index < CurrentGraphicsOutputMode->MaxMode; Index++) {
2018 Match = FALSE;
2019
2020 for (NumberIndex = 0; NumberIndex < GraphicsOutput->Mode->MaxMode; NumberIndex++) {
2021 Status = GraphicsOutput->QueryMode (GraphicsOutput, (UINT32) NumberIndex, &SizeOfInfo, &Info);
2022 if (EFI_ERROR (Status)) {
2023 return Status;
2024 }
2025 if ((Info->HorizontalResolution == Mode->HorizontalResolution) &&
2026 (Info->VerticalResolution == Mode->VerticalResolution)){
2027 Match = TRUE;
2028 FreePool (Info);
2029 break;
2030 }
2031 FreePool (Info);
2032 }
2033
2034 if (Match) {
2035 CopyMem (MatchedMode, Mode, sizeof (TEXT_OUT_GOP_MODE));
2036 MatchedMode++;
2037 }
2038
2039 Mode++;
2040 }
2041
2042 //
2043 // Drop the old mode buffer, assign it to a new one
2044 //
2045 FreePool (Private->GraphicsOutputModeBuffer);
2046 Private->GraphicsOutputModeBuffer = ModeBuffer;
2047
2048 //
2049 // Physical frame buffer is no longer available when there are more than one physical GOP devices
2050 //
2051 CurrentGraphicsOutputMode->MaxMode = (UINT32) (((UINTN) MatchedMode - (UINTN) ModeBuffer) / sizeof (TEXT_OUT_GOP_MODE));
2052 CurrentGraphicsOutputMode->Info->PixelFormat = PixelBltOnly;
2053 ZeroMem (&CurrentGraphicsOutputMode->Info->PixelInformation, sizeof (EFI_PIXEL_BITMASK));
2054 CurrentGraphicsOutputMode->SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
2055 CurrentGraphicsOutputMode->FrameBufferBase = (EFI_PHYSICAL_ADDRESS) NULL;
2056 CurrentGraphicsOutputMode->FrameBufferSize = 0;
2057 }
2058
2059 //
2060 // Select a prefered Display mode 800x600
2061 //
2062 for (Index = 0; Index < CurrentGraphicsOutputMode->MaxMode; Index++) {
2063 Mode = &Private->GraphicsOutputModeBuffer[Index];
2064 if ((Mode->HorizontalResolution == 800) && (Mode->VerticalResolution == 600)) {
2065 break;
2066 }
2067 }
2068 //
2069 // Prefered mode is not found, set to mode 0
2070 //
2071 if (Index >= CurrentGraphicsOutputMode->MaxMode) {
2072 Index = 0;
2073 }
2074
2075 //
2076 // Current mode number may need update now, so set it to an invalide mode number
2077 //
2078 CurrentGraphicsOutputMode->Mode = 0xffff;
2079 } else {
2080 //
2081 // For UGA device, it's inconvenient to retrieve all the supported display modes.
2082 // To simplify the implementation, only add one resolution(800x600, 32bit color depth) as defined in UEFI spec
2083 //
2084 CurrentGraphicsOutputMode->MaxMode = 1;
2085 CurrentGraphicsOutputMode->Info->Version = 0;
2086 CurrentGraphicsOutputMode->Info->HorizontalResolution = 800;
2087 CurrentGraphicsOutputMode->Info->VerticalResolution = 600;
2088 CurrentGraphicsOutputMode->Info->PixelFormat = PixelBltOnly;
2089 CurrentGraphicsOutputMode->Info->PixelsPerScanLine = 800;
2090 CurrentGraphicsOutputMode->SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
2091 CurrentGraphicsOutputMode->FrameBufferBase = (EFI_PHYSICAL_ADDRESS) NULL;
2092 CurrentGraphicsOutputMode->FrameBufferSize = 0;
2093
2094 //
2095 // Update the private mode buffer
2096 //
2097 ModeBuffer = &Private->GraphicsOutputModeBuffer[0];
2098 ModeBuffer->HorizontalResolution = 800;
2099 ModeBuffer->VerticalResolution = 600;
2100
2101 //
2102 // Current mode is unknow now, set it to an invalid mode number 0xffff
2103 //
2104 CurrentGraphicsOutputMode->Mode = 0xffff;
2105 Index = 0;
2106 }
2107
2108 //
2109 // Force GraphicsOutput mode to be set,
2110 // regardless whether the console is in EfiConsoleControlScreenGraphics or EfiConsoleControlScreenText mode
2111 //
2112 Private->HardwareNeedsStarting = TRUE;
2113 Status = Private->GraphicsOutput.SetMode (&Private->GraphicsOutput, (UINT32) Index);
2114
2115 Private->CurrentNumberOfGraphicsOutput++;
2116
2117 return Status;
2118 }
2119 #endif
2120
2121 EFI_STATUS
2122 ConSplitterTextOutAddDevice (
2123 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
2124 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *TextOut,
2125 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput,
2126 IN EFI_UGA_DRAW_PROTOCOL *UgaDraw
2127 )
2128 /*++
2129
2130 Routine Description:
2131
2132 Arguments:
2133
2134 Returns:
2135
2136 None
2137
2138 --*/
2139 {
2140 EFI_STATUS Status;
2141 UINTN CurrentNumOfConsoles;
2142 INT32 CurrentMode;
2143 INT32 MaxMode;
2144 TEXT_OUT_AND_GOP_DATA *TextAndGop;
2145
2146 Status = EFI_SUCCESS;
2147 CurrentNumOfConsoles = Private->CurrentNumberOfConsoles;
2148
2149 //
2150 // If the Text Out List is full, enlarge it by calling growbuffer().
2151 //
2152 while (CurrentNumOfConsoles >= Private->TextOutListCount) {
2153 Status = ConSplitterGrowBuffer (
2154 sizeof (TEXT_OUT_AND_GOP_DATA),
2155 &Private->TextOutListCount,
2156 (VOID **) &Private->TextOutList
2157 );
2158 if (EFI_ERROR (Status)) {
2159 return EFI_OUT_OF_RESOURCES;
2160 }
2161 //
2162 // Also need to reallocate the TextOutModeMap table
2163 //
2164 Status = ConSplitterGrowMapTable (Private);
2165 if (EFI_ERROR (Status)) {
2166 return EFI_OUT_OF_RESOURCES;
2167 }
2168 }
2169
2170 TextAndGop = &Private->TextOutList[CurrentNumOfConsoles];
2171
2172 TextAndGop->TextOut = TextOut;
2173 TextAndGop->GraphicsOutput = GraphicsOutput;
2174 TextAndGop->UgaDraw = UgaDraw;
2175
2176 if ((GraphicsOutput == NULL) && (UgaDraw == NULL)) {
2177 //
2178 // If No UGA device then use the ConOut device
2179 //
2180 TextAndGop->TextOutEnabled = TRUE;
2181 } else {
2182 //
2183 // If UGA device use ConOut device only used if UGA screen is in Text mode
2184 //
2185 TextAndGop->TextOutEnabled = (BOOLEAN) (Private->ConsoleOutputMode == EfiConsoleControlScreenText);
2186 }
2187
2188 if (CurrentNumOfConsoles == 0) {
2189 //
2190 // Add the first device's output mode to console splitter's mode list
2191 //
2192 Status = ConSplitterAddOutputMode (Private, TextOut);
2193 } else {
2194 ConSplitterSyncOutputMode (Private, TextOut);
2195 }
2196
2197 Private->CurrentNumberOfConsoles++;
2198
2199 //
2200 // Scan both TextOutList, for the intersection TextOut device
2201 // maybe both ConOut and StdErr incorporate the same Text Out
2202 // device in them, thus the output of both should be synced.
2203 //
2204 ConSplitterGetIntersectionBetweenConOutAndStrErr ();
2205
2206 CurrentMode = Private->TextOutMode.Mode;
2207 MaxMode = Private->TextOutMode.MaxMode;
2208 ASSERT (MaxMode >= 1);
2209
2210 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
2211 if ((GraphicsOutput != NULL) || (UgaDraw != NULL)) {
2212 ConSplitterAddGraphicsOutputMode (Private, GraphicsOutput, UgaDraw);
2213 }
2214 #endif
2215
2216 if (Private->ConsoleOutputMode == EfiConsoleControlScreenGraphics && GraphicsOutput != NULL) {
2217 //
2218 // We just added a new UGA device in graphics mode
2219 //
2220 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
2221 DevNullGopSync (Private, GraphicsOutput, UgaDraw);
2222 #else
2223 DevNullUgaSync (Private, UgaDraw);
2224 #endif
2225 } else if ((CurrentMode >= 0) && ((GraphicsOutput != NULL) || (UgaDraw != NULL)) && (CurrentMode < Private->TextOutMode.MaxMode)) {
2226 //
2227 // The new console supports the same mode of the current console so sync up
2228 //
2229 DevNullSyncGopStdOut (Private);
2230 } else {
2231 //
2232 // If ConOut, then set the mode to Mode #0 which us 80 x 25
2233 //
2234 Private->TextOut.SetMode (&Private->TextOut, 0);
2235 }
2236
2237 return Status;
2238 }
2239
2240 EFI_STATUS
2241 ConSplitterTextOutDeleteDevice (
2242 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
2243 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *TextOut
2244 )
2245 /*++
2246
2247 Routine Description:
2248
2249 Arguments:
2250
2251 Returns:
2252
2253 None
2254
2255 --*/
2256 {
2257 INT32 Index;
2258 UINTN CurrentNumOfConsoles;
2259 TEXT_OUT_AND_GOP_DATA *TextOutList;
2260 EFI_STATUS Status;
2261
2262 //
2263 // Remove the specified text-out device data structure from the Text out List,
2264 // and rearrange the remaining data structures in the Text out List.
2265 //
2266 CurrentNumOfConsoles = Private->CurrentNumberOfConsoles;
2267 Index = (INT32) CurrentNumOfConsoles - 1;
2268 TextOutList = Private->TextOutList;
2269 while (Index >= 0) {
2270 if (TextOutList->TextOut == TextOut) {
2271 CopyMem (TextOutList, TextOutList + 1, sizeof (TEXT_OUT_AND_GOP_DATA) * Index);
2272 CurrentNumOfConsoles--;
2273 break;
2274 }
2275
2276 Index--;
2277 TextOutList++;
2278 }
2279 //
2280 // The specified TextOut is not managed by the ConSplitter driver
2281 //
2282 if (Index < 0) {
2283 return EFI_NOT_FOUND;
2284 }
2285
2286 if (CurrentNumOfConsoles == 0) {
2287 //
2288 // If the number of consoles is zero clear the Dev NULL device
2289 //
2290 Private->CurrentNumberOfConsoles = 0;
2291 Private->TextOutMode.MaxMode = 1;
2292 Private->TextOutQueryData[0].Columns = 80;
2293 Private->TextOutQueryData[0].Rows = 25;
2294 DevNullTextOutSetMode (Private, 0);
2295
2296 return EFI_SUCCESS;
2297 }
2298 //
2299 // Max Mode is realy an intersection of the QueryMode command to all
2300 // devices. So we must copy the QueryMode of the first device to
2301 // QueryData.
2302 //
2303 ZeroMem (
2304 Private->TextOutQueryData,
2305 Private->TextOutQueryDataCount * sizeof (TEXT_OUT_SPLITTER_QUERY_DATA)
2306 );
2307
2308 FreePool (Private->TextOutModeMap);
2309 Private->TextOutModeMap = NULL;
2310 TextOutList = Private->TextOutList;
2311
2312 //
2313 // Add the first TextOut to the QueryData array and ModeMap table
2314 //
2315 Status = ConSplitterAddOutputMode (Private, TextOutList->TextOut);
2316
2317 //
2318 // Now add one by one
2319 //
2320 Index = 1;
2321 Private->CurrentNumberOfConsoles = 1;
2322 TextOutList++;
2323 while ((UINTN) Index < CurrentNumOfConsoles) {
2324 ConSplitterSyncOutputMode (Private, TextOutList->TextOut);
2325 Index++;
2326 Private->CurrentNumberOfConsoles++;
2327 TextOutList++;
2328 }
2329
2330 ConSplitterGetIntersectionBetweenConOutAndStrErr ();
2331
2332 return Status;
2333 }
2334 //
2335 // ConSplitter TextIn member functions
2336 //
2337 EFI_STATUS
2338 EFIAPI
2339 ConSplitterTextInReset (
2340 IN EFI_SIMPLE_TEXT_IN_PROTOCOL *This,
2341 IN BOOLEAN ExtendedVerification
2342 )
2343 /*++
2344
2345 Routine Description:
2346 Reset the input device and optionaly run diagnostics
2347
2348 Arguments:
2349 This - Protocol instance pointer.
2350 ExtendedVerification - Driver may perform diagnostics on reset.
2351
2352 Returns:
2353 EFI_SUCCESS - The device was reset.
2354 EFI_DEVICE_ERROR - The device is not functioning properly and could
2355 not be reset.
2356
2357 --*/
2358 {
2359 EFI_STATUS Status;
2360 EFI_STATUS ReturnStatus;
2361 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
2362 UINTN Index;
2363
2364 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
2365
2366 Private->KeyEventSignalState = FALSE;
2367
2368 //
2369 // return the worst status met
2370 //
2371 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
2372 Status = Private->TextInList[Index]->Reset (
2373 Private->TextInList[Index],
2374 ExtendedVerification
2375 );
2376 if (EFI_ERROR (Status)) {
2377 ReturnStatus = Status;
2378 }
2379 }
2380
2381 return ReturnStatus;
2382 }
2383
2384 EFI_STATUS
2385 EFIAPI
2386 ConSplitterTextInPrivateReadKeyStroke (
2387 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
2388 OUT EFI_INPUT_KEY *Key
2389 )
2390 /*++
2391
2392 Routine Description:
2393 Reads the next keystroke from the input device. The WaitForKey Event can
2394 be used to test for existance of a keystroke via WaitForEvent () call.
2395
2396 Arguments:
2397 This - Protocol instance pointer.
2398 Key - Driver may perform diagnostics on reset.
2399
2400 Returns:
2401 EFI_SUCCESS - The keystroke information was returned.
2402 EFI_NOT_READY - There was no keystroke data availiable.
2403 EFI_DEVICE_ERROR - The keydtroke information was not returned due to
2404 hardware errors.
2405
2406 --*/
2407 {
2408 EFI_STATUS Status;
2409 UINTN Index;
2410 EFI_INPUT_KEY CurrentKey;
2411
2412 Key->UnicodeChar = 0;
2413 Key->ScanCode = SCAN_NULL;
2414
2415 //
2416 // if no physical console input device exists, return EFI_NOT_READY;
2417 // if any physical console input device has key input,
2418 // return the key and EFI_SUCCESS.
2419 //
2420 for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {
2421 Status = Private->TextInList[Index]->ReadKeyStroke (
2422 Private->TextInList[Index],
2423 &CurrentKey
2424 );
2425 if (!EFI_ERROR (Status)) {
2426 *Key = CurrentKey;
2427 return Status;
2428 }
2429 }
2430
2431 return EFI_NOT_READY;
2432 }
2433
2434 BOOLEAN
2435 ConSpliterConssoleControlStdInLocked (
2436 VOID
2437 )
2438 /*++
2439
2440 Routine Description:
2441 Return TRUE if StdIn is locked. The ConIn device on the virtual handle is
2442 the only device locked.
2443
2444 Arguments:
2445 NONE
2446
2447 Returns:
2448 TRUE - StdIn locked
2449 FALSE - StdIn working normally
2450
2451 --*/
2452 {
2453 return mConIn.PasswordEnabled;
2454 }
2455
2456 VOID
2457 EFIAPI
2458 ConSpliterConsoleControlLockStdInEvent (
2459 IN EFI_EVENT Event,
2460 IN VOID *Context
2461 )
2462 /*++
2463
2464 Routine Description:
2465 This timer event will fire when StdIn is locked. It will check the key
2466 sequence on StdIn to see if it matches the password. Any error in the
2467 password will cause the check to reset. As long a mConIn.PasswordEnabled is
2468 TRUE the StdIn splitter will not report any input.
2469
2470 Arguments:
2471 (Standard EFI_EVENT_NOTIFY)
2472
2473 Returns:
2474 None
2475
2476 --*/
2477 {
2478 EFI_STATUS Status;
2479 EFI_INPUT_KEY Key;
2480 CHAR16 BackSpaceString[2];
2481 CHAR16 SpaceString[2];
2482
2483 do {
2484 Status = ConSplitterTextInPrivateReadKeyStroke (&mConIn, &Key);
2485 if (!EFI_ERROR (Status)) {
2486 //
2487 // if it's an ENTER, match password
2488 //
2489 if ((Key.UnicodeChar == CHAR_CARRIAGE_RETURN) && (Key.ScanCode == SCAN_NULL)) {
2490 mConIn.PwdAttempt[mConIn.PwdIndex] = CHAR_NULL;
2491 if (StrCmp (mConIn.Password, mConIn.PwdAttempt)) {
2492 //
2493 // Password not match
2494 //
2495 ConSplitterTextOutOutputString (&mConOut.TextOut, (CHAR16 *) L"\n\rPassword not correct\n\r");
2496 mConIn.PwdIndex = 0;
2497 } else {
2498 //
2499 // Key matches password sequence
2500 //
2501 gBS->SetTimer (mConIn.LockEvent, TimerPeriodic, 0);
2502 mConIn.PasswordEnabled = FALSE;
2503 Status = EFI_NOT_READY;
2504 }
2505 } else if ((Key.UnicodeChar == CHAR_BACKSPACE) && (Key.ScanCode == SCAN_NULL)) {
2506 //
2507 // BackSpace met
2508 //
2509 if (mConIn.PwdIndex > 0) {
2510 BackSpaceString[0] = CHAR_BACKSPACE;
2511 BackSpaceString[1] = 0;
2512
2513 SpaceString[0] = ' ';
2514 SpaceString[1] = 0;
2515
2516 ConSplitterTextOutOutputString (&mConOut.TextOut, BackSpaceString);
2517 ConSplitterTextOutOutputString (&mConOut.TextOut, SpaceString);
2518 ConSplitterTextOutOutputString (&mConOut.TextOut, BackSpaceString);
2519
2520 mConIn.PwdIndex--;
2521 }
2522 } else if ((Key.ScanCode == SCAN_NULL) && (Key.UnicodeChar >= 32)) {
2523 //
2524 // If it's not an ENTER, neigher a function key, nor a CTRL-X or ALT-X, record the input
2525 //
2526 if (mConIn.PwdIndex < (MAX_STD_IN_PASSWORD - 1)) {
2527 if (mConIn.PwdIndex == 0) {
2528 ConSplitterTextOutOutputString (&mConOut.TextOut, (CHAR16 *) L"\n\r");
2529 }
2530
2531 ConSplitterTextOutOutputString (&mConOut.TextOut, (CHAR16 *) L"*");
2532 mConIn.PwdAttempt[mConIn.PwdIndex] = Key.UnicodeChar;
2533 mConIn.PwdIndex++;
2534 }
2535 }
2536 }
2537 } while (!EFI_ERROR (Status));
2538 }
2539
2540 EFI_STATUS
2541 EFIAPI
2542 ConSpliterConsoleControlLockStdIn (
2543 IN EFI_CONSOLE_CONTROL_PROTOCOL *This,
2544 IN CHAR16 *Password
2545 )
2546 /*++
2547
2548 Routine Description:
2549 If Password is NULL unlock the password state variable and set the event
2550 timer. If the Password is too big return an error. If the Password is valid
2551 Copy the Password and enable state variable and then arm the periodic timer
2552
2553 Arguments:
2554
2555 Returns:
2556 EFI_SUCCESS - Lock the StdIn device
2557 EFI_INVALID_PARAMETER - Password is NULL
2558 EFI_OUT_OF_RESOURCES - Buffer allocation to store the password fails
2559
2560 --*/
2561 {
2562 if (Password == NULL) {
2563 return EFI_INVALID_PARAMETER;
2564 }
2565
2566 if (StrLen (Password) >= MAX_STD_IN_PASSWORD) {
2567 //
2568 // Currently have a max password size
2569 //
2570 return EFI_OUT_OF_RESOURCES;
2571 }
2572 //
2573 // Save the password, initialize state variables and arm event timer
2574 //
2575 StrCpy (mConIn.Password, Password);
2576 mConIn.PasswordEnabled = TRUE;
2577 mConIn.PwdIndex = 0;
2578 gBS->SetTimer (mConIn.LockEvent, TimerPeriodic, (10000 * 25));
2579
2580 return EFI_SUCCESS;
2581 }
2582
2583 EFI_STATUS
2584 EFIAPI
2585 ConSplitterTextInReadKeyStroke (
2586 IN EFI_SIMPLE_TEXT_IN_PROTOCOL *This,
2587 OUT EFI_INPUT_KEY *Key
2588 )
2589 /*++
2590
2591 Routine Description:
2592 Reads the next keystroke from the input device. The WaitForKey Event can
2593 be used to test for existance of a keystroke via WaitForEvent () call.
2594 If the ConIn is password locked make it look like no keystroke is availible
2595
2596 Arguments:
2597 This - Protocol instance pointer.
2598 Key - Driver may perform diagnostics on reset.
2599
2600 Returns:
2601 EFI_SUCCESS - The keystroke information was returned.
2602 EFI_NOT_READY - There was no keystroke data availiable.
2603 EFI_DEVICE_ERROR - The keydtroke information was not returned due to
2604 hardware errors.
2605
2606 --*/
2607 {
2608 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
2609
2610 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
2611 if (Private->PasswordEnabled) {
2612 //
2613 // If StdIn Locked return not ready
2614 //
2615 return EFI_NOT_READY;
2616 }
2617
2618 Private->KeyEventSignalState = FALSE;
2619
2620 return ConSplitterTextInPrivateReadKeyStroke (Private, Key);
2621 }
2622
2623 VOID
2624 EFIAPI
2625 ConSplitterTextInWaitForKey (
2626 IN EFI_EVENT Event,
2627 IN VOID *Context
2628 )
2629 /*++
2630
2631 Routine Description:
2632 This event agregates all the events of the ConIn devices in the spliter.
2633 If the ConIn is password locked then return.
2634 If any events of physical ConIn devices are signaled, signal the ConIn
2635 spliter event. This will cause the calling code to call
2636 ConSplitterTextInReadKeyStroke ().
2637
2638 Arguments:
2639 Event - The Event assoicated with callback.
2640 Context - Context registered when Event was created.
2641
2642 Returns:
2643 None
2644
2645 --*/
2646 {
2647 EFI_STATUS Status;
2648 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
2649 UINTN Index;
2650
2651 Private = (TEXT_IN_SPLITTER_PRIVATE_DATA *) Context;
2652 if (Private->PasswordEnabled) {
2653 //
2654 // If StdIn Locked return not ready
2655 //
2656 return ;
2657 }
2658
2659 //
2660 // if KeyEventSignalState is flagged before, and not cleared by Reset() or ReadKeyStroke()
2661 //
2662 if (Private->KeyEventSignalState) {
2663 gBS->SignalEvent (Event);
2664 return ;
2665 }
2666 //
2667 // if any physical console input device has key input, signal the event.
2668 //
2669 for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {
2670 Status = gBS->CheckEvent (Private->TextInList[Index]->WaitForKey);
2671 if (!EFI_ERROR (Status)) {
2672 gBS->SignalEvent (Event);
2673 Private->KeyEventSignalState = TRUE;
2674 }
2675 }
2676 }
2677
2678 EFI_STATUS
2679 EFIAPI
2680 ConSplitterSimplePointerReset (
2681 IN EFI_SIMPLE_POINTER_PROTOCOL *This,
2682 IN BOOLEAN ExtendedVerification
2683 )
2684 /*++
2685
2686 Routine Description:
2687 Reset the input device and optionaly run diagnostics
2688
2689 Arguments:
2690 This - Protocol instance pointer.
2691 ExtendedVerification - Driver may perform diagnostics on reset.
2692
2693 Returns:
2694 EFI_SUCCESS - The device was reset.
2695 EFI_DEVICE_ERROR - The device is not functioning properly and could
2696 not be reset.
2697
2698 --*/
2699 {
2700 EFI_STATUS Status;
2701 EFI_STATUS ReturnStatus;
2702 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
2703 UINTN Index;
2704
2705 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_SIMPLE_POINTER_THIS (This);
2706
2707 Private->InputEventSignalState = FALSE;
2708
2709 if (Private->CurrentNumberOfPointers == 0) {
2710 return EFI_SUCCESS;
2711 }
2712 //
2713 // return the worst status met
2714 //
2715 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfPointers; Index++) {
2716 Status = Private->PointerList[Index]->Reset (
2717 Private->PointerList[Index],
2718 ExtendedVerification
2719 );
2720 if (EFI_ERROR (Status)) {
2721 ReturnStatus = Status;
2722 }
2723 }
2724
2725 return ReturnStatus;
2726 }
2727
2728 STATIC
2729 EFI_STATUS
2730 EFIAPI
2731 ConSplitterSimplePointerPrivateGetState (
2732 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
2733 IN OUT EFI_SIMPLE_POINTER_STATE *State
2734 )
2735 /*++
2736
2737 Routine Description:
2738 Reads the next keystroke from the input device. The WaitForKey Event can
2739 be used to test for existance of a keystroke via WaitForEvent () call.
2740
2741 Arguments:
2742 This - Protocol instance pointer.
2743 State -
2744
2745 Returns:
2746 EFI_SUCCESS - The keystroke information was returned.
2747 EFI_NOT_READY - There was no keystroke data availiable.
2748 EFI_DEVICE_ERROR - The keydtroke information was not returned due to
2749 hardware errors.
2750
2751 --*/
2752 {
2753 EFI_STATUS Status;
2754 EFI_STATUS ReturnStatus;
2755 UINTN Index;
2756 EFI_SIMPLE_POINTER_STATE CurrentState;
2757
2758 State->RelativeMovementX = 0;
2759 State->RelativeMovementY = 0;
2760 State->RelativeMovementZ = 0;
2761 State->LeftButton = FALSE;
2762 State->RightButton = FALSE;
2763
2764 //
2765 // if no physical console input device exists, return EFI_NOT_READY;
2766 // if any physical console input device has key input,
2767 // return the key and EFI_SUCCESS.
2768 //
2769 ReturnStatus = EFI_NOT_READY;
2770 for (Index = 0; Index < Private->CurrentNumberOfPointers; Index++) {
2771
2772 Status = Private->PointerList[Index]->GetState (
2773 Private->PointerList[Index],
2774 &CurrentState
2775 );
2776 if (!EFI_ERROR (Status)) {
2777 if (ReturnStatus == EFI_NOT_READY) {
2778 ReturnStatus = EFI_SUCCESS;
2779 }
2780
2781 if (CurrentState.LeftButton) {
2782 State->LeftButton = TRUE;
2783 }
2784
2785 if (CurrentState.RightButton) {
2786 State->RightButton = TRUE;
2787 }
2788
2789 if (CurrentState.RelativeMovementX != 0 && Private->PointerList[Index]->Mode->ResolutionX != 0) {
2790 State->RelativeMovementX += (CurrentState.RelativeMovementX * (INT32) Private->SimplePointerMode.ResolutionX) / (INT32) Private->PointerList[Index]->Mode->ResolutionX;
2791 }
2792
2793 if (CurrentState.RelativeMovementY != 0 && Private->PointerList[Index]->Mode->ResolutionY != 0) {
2794 State->RelativeMovementY += (CurrentState.RelativeMovementY * (INT32) Private->SimplePointerMode.ResolutionY) / (INT32) Private->PointerList[Index]->Mode->ResolutionY;
2795 }
2796
2797 if (CurrentState.RelativeMovementZ != 0 && Private->PointerList[Index]->Mode->ResolutionZ != 0) {
2798 State->RelativeMovementZ += (CurrentState.RelativeMovementZ * (INT32) Private->SimplePointerMode.ResolutionZ) / (INT32) Private->PointerList[Index]->Mode->ResolutionZ;
2799 }
2800 } else if (Status == EFI_DEVICE_ERROR) {
2801 ReturnStatus = EFI_DEVICE_ERROR;
2802 }
2803 }
2804
2805 return ReturnStatus;
2806 }
2807
2808 EFI_STATUS
2809 EFIAPI
2810 ConSplitterSimplePointerGetState (
2811 IN EFI_SIMPLE_POINTER_PROTOCOL *This,
2812 IN OUT EFI_SIMPLE_POINTER_STATE *State
2813 )
2814 /*++
2815
2816 Routine Description:
2817 Reads the next keystroke from the input device. The WaitForKey Event can
2818 be used to test for existance of a keystroke via WaitForEvent () call.
2819 If the ConIn is password locked make it look like no keystroke is availible
2820
2821 Arguments:
2822 This - Protocol instance pointer.
2823 State -
2824
2825 Returns:
2826 EFI_SUCCESS - The keystroke information was returned.
2827 EFI_NOT_READY - There was no keystroke data availiable.
2828 EFI_DEVICE_ERROR - The keydtroke information was not returned due to
2829 hardware errors.
2830
2831 --*/
2832 {
2833 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
2834
2835 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_SIMPLE_POINTER_THIS (This);
2836 if (Private->PasswordEnabled) {
2837 //
2838 // If StdIn Locked return not ready
2839 //
2840 return EFI_NOT_READY;
2841 }
2842
2843 Private->InputEventSignalState = FALSE;
2844
2845 return ConSplitterSimplePointerPrivateGetState (Private, State);
2846 }
2847
2848 VOID
2849 EFIAPI
2850 ConSplitterSimplePointerWaitForInput (
2851 IN EFI_EVENT Event,
2852 IN VOID *Context
2853 )
2854 /*++
2855
2856 Routine Description:
2857 This event agregates all the events of the ConIn devices in the spliter.
2858 If the ConIn is password locked then return.
2859 If any events of physical ConIn devices are signaled, signal the ConIn
2860 spliter event. This will cause the calling code to call
2861 ConSplitterTextInReadKeyStroke ().
2862
2863 Arguments:
2864 Event - The Event assoicated with callback.
2865 Context - Context registered when Event was created.
2866
2867 Returns:
2868 None
2869
2870 --*/
2871 {
2872 EFI_STATUS Status;
2873 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
2874 UINTN Index;
2875
2876 Private = (TEXT_IN_SPLITTER_PRIVATE_DATA *) Context;
2877 if (Private->PasswordEnabled) {
2878 //
2879 // If StdIn Locked return not ready
2880 //
2881 return ;
2882 }
2883
2884 //
2885 // if InputEventSignalState is flagged before, and not cleared by Reset() or ReadKeyStroke()
2886 //
2887 if (Private->InputEventSignalState) {
2888 gBS->SignalEvent (Event);
2889 return ;
2890 }
2891 //
2892 // if any physical console input device has key input, signal the event.
2893 //
2894 for (Index = 0; Index < Private->CurrentNumberOfPointers; Index++) {
2895 Status = gBS->CheckEvent (Private->PointerList[Index]->WaitForInput);
2896 if (!EFI_ERROR (Status)) {
2897 gBS->SignalEvent (Event);
2898 Private->InputEventSignalState = TRUE;
2899 }
2900 }
2901 }
2902
2903 EFI_STATUS
2904 EFIAPI
2905 ConSplitterTextOutReset (
2906 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
2907 IN BOOLEAN ExtendedVerification
2908 )
2909 /*++
2910
2911 Routine Description:
2912 Reset the text output device hardware and optionaly run diagnostics
2913
2914 Arguments:
2915 This - Protocol instance pointer.
2916 ExtendedVerification - Driver may perform more exhaustive verfication
2917 operation of the device during reset.
2918
2919 Returns:
2920 EFI_SUCCESS - The text output device was reset.
2921 EFI_DEVICE_ERROR - The text output device is not functioning correctly and
2922 could not be reset.
2923
2924 --*/
2925 {
2926 EFI_STATUS Status;
2927 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
2928 UINTN Index;
2929 EFI_STATUS ReturnStatus;
2930
2931 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
2932
2933 //
2934 // return the worst status met
2935 //
2936 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
2937
2938 if (Private->TextOutList[Index].TextOutEnabled) {
2939
2940 Status = Private->TextOutList[Index].TextOut->Reset (
2941 Private->TextOutList[Index].TextOut,
2942 ExtendedVerification
2943 );
2944 if (EFI_ERROR (Status)) {
2945 ReturnStatus = Status;
2946 }
2947 }
2948 }
2949
2950 This->SetAttribute (This, EFI_TEXT_ATTR (This->Mode->Attribute & 0x0F, EFI_BACKGROUND_BLACK));
2951
2952 Status = DevNullTextOutSetMode (Private, 0);
2953 if (EFI_ERROR (Status)) {
2954 ReturnStatus = Status;
2955 }
2956
2957 return ReturnStatus;
2958 }
2959
2960 EFI_STATUS
2961 EFIAPI
2962 ConSplitterTextOutOutputString (
2963 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
2964 IN CHAR16 *WString
2965 )
2966 /*++
2967
2968 Routine Description:
2969 Write a Unicode string to the output device.
2970
2971 Arguments:
2972 This - Protocol instance pointer.
2973 String - The NULL-terminated Unicode string to be displayed on the output
2974 device(s). All output devices must also support the Unicode
2975 drawing defined in this file.
2976
2977 Returns:
2978 EFI_SUCCESS - The string was output to the device.
2979 EFI_DEVICE_ERROR - The device reported an error while attempting to output
2980 the text.
2981 EFI_UNSUPPORTED - The output device's mode is not currently in a
2982 defined text mode.
2983 EFI_WARN_UNKNOWN_GLYPH - This warning code indicates that some of the
2984 characters in the Unicode string could not be
2985 rendered and were skipped.
2986
2987 --*/
2988 {
2989 EFI_STATUS Status;
2990 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
2991 UINTN Index;
2992 UINTN BackSpaceCount;
2993 EFI_STATUS ReturnStatus;
2994 CHAR16 *TargetString;
2995
2996 This->SetAttribute (This, This->Mode->Attribute);
2997
2998 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
2999
3000 BackSpaceCount = 0;
3001 for (TargetString = WString; *TargetString; TargetString++) {
3002 if (*TargetString == CHAR_BACKSPACE) {
3003 BackSpaceCount++;
3004 }
3005
3006 }
3007
3008 if (BackSpaceCount == 0) {
3009 TargetString = WString;
3010 } else {
3011 TargetString = AllocatePool (sizeof (CHAR16) * (StrLen (WString) + BackSpaceCount + 1));
3012 StrCpy (TargetString, WString);
3013 }
3014 //
3015 // return the worst status met
3016 //
3017 Status = DevNullTextOutOutputString (Private, TargetString);
3018 if (EFI_ERROR (Status)) {
3019 ReturnStatus = Status;
3020 }
3021
3022 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
3023
3024 if (Private->TextOutList[Index].TextOutEnabled) {
3025 Status = Private->TextOutList[Index].TextOut->OutputString (
3026 Private->TextOutList[Index].TextOut,
3027 TargetString
3028 );
3029 if (EFI_ERROR (Status)) {
3030 ReturnStatus = Status;
3031 }
3032 }
3033 }
3034
3035 if (BackSpaceCount) {
3036 FreePool (TargetString);
3037 }
3038
3039 return ReturnStatus;
3040 }
3041
3042 EFI_STATUS
3043 EFIAPI
3044 ConSplitterTextOutTestString (
3045 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
3046 IN CHAR16 *WString
3047 )
3048 /*++
3049
3050 Routine Description:
3051 Verifies that all characters in a Unicode string can be output to the
3052 target device.
3053
3054 Arguments:
3055 This - Protocol instance pointer.
3056 String - The NULL-terminated Unicode string to be examined for the output
3057 device(s).
3058
3059 Returns:
3060 EFI_SUCCESS - The device(s) are capable of rendering the output string.
3061 EFI_UNSUPPORTED - Some of the characters in the Unicode string cannot be
3062 rendered by one or more of the output devices mapped
3063 by the EFI handle.
3064
3065 --*/
3066 {
3067 EFI_STATUS Status;
3068 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
3069 UINTN Index;
3070 EFI_STATUS ReturnStatus;
3071
3072 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3073
3074 //
3075 // return the worst status met
3076 //
3077 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
3078 if (Private->TextOutList[Index].TextOutEnabled) {
3079 Status = Private->TextOutList[Index].TextOut->TestString (
3080 Private->TextOutList[Index].TextOut,
3081 WString
3082 );
3083 if (EFI_ERROR (Status)) {
3084 ReturnStatus = Status;
3085 }
3086 }
3087 }
3088 //
3089 // There is no DevNullTextOutTestString () since a Unicode buffer would
3090 // always return EFI_SUCCESS.
3091 // ReturnStatus will be EFI_SUCCESS if no consoles are present
3092 //
3093 return ReturnStatus;
3094 }
3095
3096 EFI_STATUS
3097 EFIAPI
3098 ConSplitterTextOutQueryMode (
3099 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
3100 IN UINTN ModeNumber,
3101 OUT UINTN *Columns,
3102 OUT UINTN *Rows
3103 )
3104 /*++
3105
3106 Routine Description:
3107 Returns information for an available text mode that the output device(s)
3108 supports.
3109
3110 Arguments:
3111 This - Protocol instance pointer.
3112 ModeNumber - The mode number to return information on.
3113 Columns, Rows - Returns the geometry of the text output device for the
3114 requested ModeNumber.
3115
3116 Returns:
3117 EFI_SUCCESS - The requested mode information was returned.
3118 EFI_DEVICE_ERROR - The device had an error and could not
3119 complete the request.
3120 EFI_UNSUPPORTED - The mode number was not valid.
3121
3122 --*/
3123 {
3124 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
3125
3126 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3127
3128 //
3129 // Check whether param ModeNumber is valid.
3130 // ModeNumber should be within range 0 ~ MaxMode - 1.
3131 //
3132 if ( (ModeNumber > (UINTN)(((UINT32)-1)>>1)) ) {
3133 return EFI_UNSUPPORTED;
3134 }
3135
3136 if ((INT32) ModeNumber >= This->Mode->MaxMode) {
3137 return EFI_UNSUPPORTED;
3138 }
3139
3140 *Columns = Private->TextOutQueryData[ModeNumber].Columns;
3141 *Rows = Private->TextOutQueryData[ModeNumber].Rows;
3142
3143 if (*Columns <= 0 && *Rows <= 0) {
3144 return EFI_UNSUPPORTED;
3145
3146 }
3147
3148 return EFI_SUCCESS;
3149 }
3150
3151 EFI_STATUS
3152 EFIAPI
3153 ConSplitterTextOutSetMode (
3154 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
3155 IN UINTN ModeNumber
3156 )
3157 /*++
3158
3159 Routine Description:
3160 Sets the output device(s) to a specified mode.
3161
3162 Arguments:
3163 This - Protocol instance pointer.
3164 ModeNumber - The mode number to set.
3165
3166 Returns:
3167 EFI_SUCCESS - The requested text mode was set.
3168 EFI_DEVICE_ERROR - The device had an error and
3169 could not complete the request.
3170 EFI_UNSUPPORTED - The mode number was not valid.
3171
3172 --*/
3173 {
3174 EFI_STATUS Status;
3175 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
3176 UINTN Index;
3177 INT32 *TextOutModeMap;
3178 EFI_STATUS ReturnStatus;
3179
3180 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3181
3182 //
3183 // Check whether param ModeNumber is valid.
3184 // ModeNumber should be within range 0 ~ MaxMode - 1.
3185 //
3186 if ( (ModeNumber > (UINTN)(((UINT32)-1)>>1)) ) {
3187 return EFI_UNSUPPORTED;
3188 }
3189
3190 if ((INT32) ModeNumber >= This->Mode->MaxMode) {
3191 return EFI_UNSUPPORTED;
3192 }
3193 //
3194 // If the mode is being set to the curent mode, then just clear the screen and return.
3195 //
3196 if (Private->TextOutMode.Mode == (INT32) ModeNumber) {
3197 return ConSplitterTextOutClearScreen (This);
3198 }
3199 //
3200 // return the worst status met
3201 //
3202 TextOutModeMap = Private->TextOutModeMap + Private->TextOutListCount * ModeNumber;
3203 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
3204
3205 if (Private->TextOutList[Index].TextOutEnabled) {
3206 Status = Private->TextOutList[Index].TextOut->SetMode (
3207 Private->TextOutList[Index].TextOut,
3208 TextOutModeMap[Index]
3209 );
3210 //
3211 // If this console device is based on a UGA device, then sync up the bitmap from
3212 // the UGA splitter and reclear the text portion of the display in the new mode.
3213 //
3214 if ((Private->TextOutList[Index].GraphicsOutput != NULL) || (Private->TextOutList[Index].UgaDraw != NULL)) {
3215 Private->TextOutList[Index].TextOut->ClearScreen (Private->TextOutList[Index].TextOut);
3216 }
3217
3218 if (EFI_ERROR (Status)) {
3219 ReturnStatus = Status;
3220 }
3221 }
3222 }
3223 //
3224 // The DevNull Console will support any possible mode as it allocates memory
3225 //
3226 Status = DevNullTextOutSetMode (Private, ModeNumber);
3227 if (EFI_ERROR (Status)) {
3228 ReturnStatus = Status;
3229 }
3230
3231 return ReturnStatus;
3232 }
3233
3234 EFI_STATUS
3235 EFIAPI
3236 ConSplitterTextOutSetAttribute (
3237 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
3238 IN UINTN Attribute
3239 )
3240 /*++
3241
3242 Routine Description:
3243 Sets the background and foreground colors for the OutputString () and
3244 ClearScreen () functions.
3245
3246 Arguments:
3247 This - Protocol instance pointer.
3248 Attribute - The attribute to set. Bits 0..3 are the foreground color, and
3249 bits 4..6 are the background color. All other bits are undefined
3250 and must be zero. The valid Attributes are defined in this file.
3251
3252 Returns:
3253 EFI_SUCCESS - The attribute was set.
3254 EFI_DEVICE_ERROR - The device had an error and
3255 could not complete the request.
3256 EFI_UNSUPPORTED - The attribute requested is not defined.
3257
3258 --*/
3259 {
3260 EFI_STATUS Status;
3261 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
3262 UINTN Index;
3263 EFI_STATUS ReturnStatus;
3264
3265 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3266
3267 //
3268 // Check whether param Attribute is valid.
3269 //
3270 if ( (Attribute > (UINTN)(((UINT32)-1)>>1)) ) {
3271 return EFI_UNSUPPORTED;
3272 }
3273
3274 //
3275 // return the worst status met
3276 //
3277 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
3278
3279 if (Private->TextOutList[Index].TextOutEnabled) {
3280 Status = Private->TextOutList[Index].TextOut->SetAttribute (
3281 Private->TextOutList[Index].TextOut,
3282 Attribute
3283 );
3284 if (EFI_ERROR (Status)) {
3285 ReturnStatus = Status;
3286 }
3287 }
3288 }
3289
3290 Private->TextOutMode.Attribute = (INT32) Attribute;
3291
3292 return ReturnStatus;
3293 }
3294
3295 EFI_STATUS
3296 EFIAPI
3297 ConSplitterTextOutClearScreen (
3298 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This
3299 )
3300 /*++
3301
3302 Routine Description:
3303 Clears the output device(s) display to the currently selected background
3304 color.
3305
3306 Arguments:
3307 This - Protocol instance pointer.
3308
3309 Returns:
3310 EFI_SUCCESS - The operation completed successfully.
3311 EFI_DEVICE_ERROR - The device had an error and
3312 could not complete the request.
3313 EFI_UNSUPPORTED - The output device is not in a valid text mode.
3314
3315 --*/
3316 {
3317 EFI_STATUS Status;
3318 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
3319 UINTN Index;
3320 EFI_STATUS ReturnStatus;
3321
3322 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3323
3324 //
3325 // return the worst status met
3326 //
3327 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
3328
3329 if (Private->TextOutList[Index].TextOutEnabled) {
3330 Status = Private->TextOutList[Index].TextOut->ClearScreen (Private->TextOutList[Index].TextOut);
3331 if (EFI_ERROR (Status)) {
3332 ReturnStatus = Status;
3333 }
3334 }
3335 }
3336
3337 Status = DevNullTextOutClearScreen (Private);
3338 if (EFI_ERROR (Status)) {
3339 ReturnStatus = Status;
3340 }
3341
3342 return ReturnStatus;
3343 }
3344
3345 EFI_STATUS
3346 EFIAPI
3347 ConSplitterTextOutSetCursorPosition (
3348 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
3349 IN UINTN Column,
3350 IN UINTN Row
3351 )
3352 /*++
3353
3354 Routine Description:
3355 Sets the current coordinates of the cursor position
3356
3357 Arguments:
3358 This - Protocol instance pointer.
3359 Column, Row - the position to set the cursor to. Must be greater than or
3360 equal to zero and less than the number of columns and rows
3361 by QueryMode ().
3362
3363 Returns:
3364 EFI_SUCCESS - The operation completed successfully.
3365 EFI_DEVICE_ERROR - The device had an error and
3366 could not complete the request.
3367 EFI_UNSUPPORTED - The output device is not in a valid text mode, or the
3368 cursor position is invalid for the current mode.
3369
3370 --*/
3371 {
3372 EFI_STATUS Status;
3373 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
3374 UINTN Index;
3375 EFI_STATUS ReturnStatus;
3376 UINTN MaxColumn;
3377 UINTN MaxRow;
3378
3379 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3380
3381 MaxColumn = Private->TextOutQueryData[Private->TextOutMode.Mode].Columns;
3382 MaxRow = Private->TextOutQueryData[Private->TextOutMode.Mode].Rows;
3383
3384 if (Column >= MaxColumn || Row >= MaxRow) {
3385 return EFI_UNSUPPORTED;
3386 }
3387 //
3388 // return the worst status met
3389 //
3390 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
3391
3392 if (Private->TextOutList[Index].TextOutEnabled) {
3393 Status = Private->TextOutList[Index].TextOut->SetCursorPosition (
3394 Private->TextOutList[Index].TextOut,
3395 Column,
3396 Row
3397 );
3398 if (EFI_ERROR (Status)) {
3399 ReturnStatus = Status;
3400 }
3401 }
3402 }
3403
3404 DevNullTextOutSetCursorPosition (Private, Column, Row);
3405
3406 return ReturnStatus;
3407 }
3408
3409 EFI_STATUS
3410 EFIAPI
3411 ConSplitterTextOutEnableCursor (
3412 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *This,
3413 IN BOOLEAN Visible
3414 )
3415 /*++
3416
3417 Routine Description:
3418 Makes the cursor visible or invisible
3419
3420 Arguments:
3421 This - Protocol instance pointer.
3422 Visible - If TRUE, the cursor is set to be visible. If FALSE, the cursor is
3423 set to be invisible.
3424
3425 Returns:
3426 EFI_SUCCESS - The operation completed successfully.
3427 EFI_DEVICE_ERROR - The device had an error and could not complete the
3428 request, or the device does not support changing
3429 the cursor mode.
3430 EFI_UNSUPPORTED - The output device is not in a valid text mode.
3431
3432 --*/
3433 {
3434 EFI_STATUS Status;
3435 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
3436 UINTN Index;
3437 EFI_STATUS ReturnStatus;
3438
3439 Private = TEXT_OUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
3440
3441 //
3442 // return the worst status met
3443 //
3444 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
3445
3446 if (Private->TextOutList[Index].TextOutEnabled) {
3447 Status = Private->TextOutList[Index].TextOut->EnableCursor (
3448 Private->TextOutList[Index].TextOut,
3449 Visible
3450 );
3451 if (EFI_ERROR (Status)) {
3452 ReturnStatus = Status;
3453 }
3454 }
3455 }
3456
3457 DevNullTextOutEnableCursor (Private, Visible);
3458
3459 return ReturnStatus;
3460 }