]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Universal/Console/ConSplitter/Dxe/ConSplitter.c
8f52c341dcf5ad331c789b4880427965cdda002c
[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 0x10,
221 NULL,
222 NULL
223 };
224
225 EFI_DRIVER_BINDING_PROTOCOL gConSplitterSimplePointerDriverBinding = {
226 ConSplitterSimplePointerDriverBindingSupported,
227 ConSplitterSimplePointerDriverBindingStart,
228 ConSplitterSimplePointerDriverBindingStop,
229 0x10,
230 NULL,
231 NULL
232 };
233
234 EFI_DRIVER_BINDING_PROTOCOL gConSplitterConOutDriverBinding = {
235 ConSplitterConOutDriverBindingSupported,
236 ConSplitterConOutDriverBindingStart,
237 ConSplitterConOutDriverBindingStop,
238 0x10,
239 NULL,
240 NULL
241 };
242
243 EFI_DRIVER_BINDING_PROTOCOL gConSplitterStdErrDriverBinding = {
244 ConSplitterStdErrDriverBindingSupported,
245 ConSplitterStdErrDriverBindingStart,
246 ConSplitterStdErrDriverBindingStop,
247 0x10,
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 EFI_STATUS
535 ConSplitterSupported (
536 IN EFI_DRIVER_BINDING_PROTOCOL *This,
537 IN EFI_HANDLE ControllerHandle,
538 IN EFI_GUID *Guid
539 )
540 /*++
541
542 Routine Description:
543 Generic Supported Check
544
545 Arguments:
546 This - Pointer to protocol.
547 ControllerHandle - Controller Handle.
548 Guid - Guid.
549
550 Returns:
551
552 EFI_UNSUPPORTED - unsupported.
553 EFI_SUCCESS - operation is OK.
554
555 --*/
556 {
557 EFI_STATUS Status;
558 VOID *Instance;
559
560 //
561 // Make sure the Console Splitter does not attempt to attach to itself
562 //
563 if (ControllerHandle == mConIn.VirtualHandle) {
564 return EFI_UNSUPPORTED;
565 }
566
567 if (ControllerHandle == mConOut.VirtualHandle) {
568 return EFI_UNSUPPORTED;
569 }
570
571 if (ControllerHandle == mStdErr.VirtualHandle) {
572 return EFI_UNSUPPORTED;
573 }
574 //
575 // Check to see whether the handle has the ConsoleInDevice GUID on it
576 //
577 Status = gBS->OpenProtocol (
578 ControllerHandle,
579 Guid,
580 &Instance,
581 This->DriverBindingHandle,
582 ControllerHandle,
583 EFI_OPEN_PROTOCOL_BY_DRIVER
584 );
585
586 if (EFI_ERROR (Status)) {
587 return Status;
588 }
589
590 gBS->CloseProtocol (
591 ControllerHandle,
592 Guid,
593 This->DriverBindingHandle,
594 ControllerHandle
595 );
596
597 return EFI_SUCCESS;
598 }
599
600 EFI_STATUS
601 EFIAPI
602 ConSplitterConInDriverBindingSupported (
603 IN EFI_DRIVER_BINDING_PROTOCOL *This,
604 IN EFI_HANDLE ControllerHandle,
605 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
606 )
607 /*++
608
609 Routine Description:
610 Console In Supported Check
611
612 Arguments:
613 This - Pointer to protocol.
614 ControllerHandle - Controller handle.
615 RemainingDevicePath - Remaining device path.
616
617 Returns:
618
619 EFI_STATUS
620
621 --*/
622 {
623 return ConSplitterSupported (
624 This,
625 ControllerHandle,
626 &gEfiConsoleInDeviceGuid
627 );
628 }
629
630 EFI_STATUS
631 EFIAPI
632 ConSplitterSimplePointerDriverBindingSupported (
633 IN EFI_DRIVER_BINDING_PROTOCOL *This,
634 IN EFI_HANDLE ControllerHandle,
635 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
636 )
637 /*++
638
639 Routine Description:
640 Standard Error Supported Check
641
642 Arguments:
643 This - Pointer to protocol.
644 ControllerHandle - Controller handle.
645 RemainingDevicePath - Remaining device path.
646
647 Returns:
648
649 EFI_STATUS
650
651 --*/
652 {
653 return ConSplitterSupported (
654 This,
655 ControllerHandle,
656 &gEfiSimplePointerProtocolGuid
657 );
658 }
659
660 EFI_STATUS
661 EFIAPI
662 ConSplitterConOutDriverBindingSupported (
663 IN EFI_DRIVER_BINDING_PROTOCOL *This,
664 IN EFI_HANDLE ControllerHandle,
665 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
666 )
667 /*++
668
669 Routine Description:
670 Console Out Supported Check
671
672 Arguments:
673 This - Pointer to protocol.
674 ControllerHandle - Controller handle.
675 RemainingDevicePath - Remaining device path.
676
677 Returns:
678
679 EFI_STATUS
680
681 --*/
682 {
683 return ConSplitterSupported (
684 This,
685 ControllerHandle,
686 &gEfiConsoleOutDeviceGuid
687 );
688 }
689
690 EFI_STATUS
691 EFIAPI
692 ConSplitterStdErrDriverBindingSupported (
693 IN EFI_DRIVER_BINDING_PROTOCOL *This,
694 IN EFI_HANDLE ControllerHandle,
695 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
696 )
697 /*++
698
699 Routine Description:
700 Standard Error Supported Check
701
702 Arguments:
703 This - Pointer to protocol.
704 ControllerHandle - Controller handle.
705 RemainingDevicePath - Remaining device path.
706
707 Returns:
708
709 EFI_STATUS
710
711 --*/
712 {
713 return ConSplitterSupported (
714 This,
715 ControllerHandle,
716 &gEfiStandardErrorDeviceGuid
717 );
718 }
719
720 EFI_STATUS
721 EFIAPI
722 ConSplitterStart (
723 IN EFI_DRIVER_BINDING_PROTOCOL *This,
724 IN EFI_HANDLE ControllerHandle,
725 IN EFI_HANDLE ConSplitterVirtualHandle,
726 IN EFI_GUID *DeviceGuid,
727 IN EFI_GUID *InterfaceGuid,
728 IN VOID **Interface
729 )
730 /*++
731
732 Routine Description:
733 Start ConSplitter on ControllerHandle, and create the virtual
734 agrogated console device on first call Start for a SimpleTextIn handle.
735
736 Arguments:
737 (Standard DriverBinding Protocol Start() function)
738
739 Returns:
740 EFI_ERROR if a SimpleTextIn protocol is not started.
741
742 --*/
743 {
744 EFI_STATUS Status;
745 VOID *Instance;
746
747 //
748 // Check to see whether the handle has the ConsoleInDevice GUID on it
749 //
750 Status = gBS->OpenProtocol (
751 ControllerHandle,
752 DeviceGuid,
753 &Instance,
754 This->DriverBindingHandle,
755 ControllerHandle,
756 EFI_OPEN_PROTOCOL_BY_DRIVER
757 );
758 if (EFI_ERROR (Status)) {
759 return Status;
760 }
761
762 Status = gBS->OpenProtocol (
763 ControllerHandle,
764 DeviceGuid,
765 &Instance,
766 This->DriverBindingHandle,
767 ConSplitterVirtualHandle,
768 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
769 );
770 if (EFI_ERROR (Status)) {
771 return Status;
772 }
773
774 return gBS->OpenProtocol (
775 ControllerHandle,
776 InterfaceGuid,
777 Interface,
778 This->DriverBindingHandle,
779 ConSplitterVirtualHandle,
780 EFI_OPEN_PROTOCOL_GET_PROTOCOL
781 );
782 }
783
784 EFI_STATUS
785 EFIAPI
786 ConSplitterConInDriverBindingStart (
787 IN EFI_DRIVER_BINDING_PROTOCOL *This,
788 IN EFI_HANDLE ControllerHandle,
789 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
790 )
791 /*++
792
793 Routine Description:
794 Start ConSplitter on ControllerHandle, and create the virtual
795 agrogated console device on first call Start for a SimpleTextIn handle.
796
797 Arguments:
798 This - Pointer to protocol.
799 ControllerHandle - Controller handle.
800 RemainingDevicePath - Remaining device path.
801
802 Returns:
803
804 EFI_STATUS
805 EFI_ERROR if a SimpleTextIn protocol is not started.
806
807 --*/
808 {
809 EFI_STATUS Status;
810 EFI_SIMPLE_TEXT_IN_PROTOCOL *TextIn;
811
812 //
813 // Start ConSplitter on ControllerHandle, and create the virtual
814 // agrogated console device on first call Start for a SimpleTextIn handle.
815 //
816 Status = ConSplitterStart (
817 This,
818 ControllerHandle,
819 mConIn.VirtualHandle,
820 &gEfiConsoleInDeviceGuid,
821 &gEfiSimpleTextInProtocolGuid,
822 (VOID **) &TextIn
823 );
824 if (EFI_ERROR (Status)) {
825 return Status;
826 }
827
828 return ConSplitterTextInAddDevice (&mConIn, TextIn);
829 }
830
831 EFI_STATUS
832 EFIAPI
833 ConSplitterSimplePointerDriverBindingStart (
834 IN EFI_DRIVER_BINDING_PROTOCOL *This,
835 IN EFI_HANDLE ControllerHandle,
836 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
837 )
838 /*++
839
840 Routine Description:
841 Start ConSplitter on ControllerHandle, and create the virtual
842 agrogated console device on first call Start for a SimpleTextIn handle.
843
844 Arguments:
845 This - Pointer to protocol.
846 ControllerHandle - Controller handle.
847 RemainingDevicePath - Remaining device path.
848
849 Returns:
850
851 EFI_ERROR if a SimpleTextIn protocol is not started.
852
853 --*/
854 {
855 EFI_STATUS Status;
856 EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer;
857
858 Status = ConSplitterStart (
859 This,
860 ControllerHandle,
861 mConIn.VirtualHandle,
862 &gEfiSimplePointerProtocolGuid,
863 &gEfiSimplePointerProtocolGuid,
864 (VOID **) &SimplePointer
865 );
866 if (EFI_ERROR (Status)) {
867 return Status;
868 }
869
870 return ConSplitterSimplePointerAddDevice (&mConIn, SimplePointer);
871 }
872
873 EFI_STATUS
874 EFIAPI
875 ConSplitterConOutDriverBindingStart (
876 IN EFI_DRIVER_BINDING_PROTOCOL *This,
877 IN EFI_HANDLE ControllerHandle,
878 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
879 )
880 /*++
881
882 Routine Description:
883 Start ConSplitter on ControllerHandle, and create the virtual
884 agrogated console device on first call Start for a SimpleTextIn handle.
885
886 Arguments:
887 This - Pointer to protocol.
888 ControllerHandle - Controller handle.
889 RemainingDevicePath - Remaining device path.
890
891 Returns:
892 EFI_ERROR if a SimpleTextIn protocol is not started.
893
894 --*/
895 {
896 EFI_STATUS Status;
897 EFI_SIMPLE_TEXT_OUT_PROTOCOL *TextOut;
898 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
899 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
900
901 Status = ConSplitterStart (
902 This,
903 ControllerHandle,
904 mConOut.VirtualHandle,
905 &gEfiConsoleOutDeviceGuid,
906 &gEfiSimpleTextOutProtocolGuid,
907 (VOID **) &TextOut
908 );
909 if (EFI_ERROR (Status)) {
910 return Status;
911 }
912 //
913 // Try to Open Graphics Output protocol
914 //
915 Status = gBS->OpenProtocol (
916 ControllerHandle,
917 &gEfiGraphicsOutputProtocolGuid,
918 (VOID **) &GraphicsOutput,
919 This->DriverBindingHandle,
920 mConOut.VirtualHandle,
921 EFI_OPEN_PROTOCOL_GET_PROTOCOL
922 );
923 if (EFI_ERROR (Status)) {
924 GraphicsOutput = NULL;
925 }
926 //
927 // Open UGA_DRAW protocol
928 //
929 Status = gBS->OpenProtocol (
930 ControllerHandle,
931 &gEfiUgaDrawProtocolGuid,
932 (VOID **) &UgaDraw,
933 This->DriverBindingHandle,
934 mConOut.VirtualHandle,
935 EFI_OPEN_PROTOCOL_GET_PROTOCOL
936 );
937 if (EFI_ERROR (Status)) {
938 UgaDraw = NULL;
939 }
940 //
941 // If both ConOut and StdErr incorporate the same Text Out device,
942 // their MaxMode and QueryData should be the intersection of both.
943 //
944 Status = ConSplitterTextOutAddDevice (&mConOut, TextOut, GraphicsOutput, UgaDraw);
945 ConSplitterTextOutSetAttribute (&mConOut.TextOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
946
947 #if (EFI_SPECIFICATION_VERSION < 0x00020000)
948 //
949 // Match the UGA mode data of ConOut with the current mode
950 //
951 if (UgaDraw != NULL) {
952 UgaDraw->GetMode (
953 UgaDraw,
954 &mConOut.UgaHorizontalResolution,
955 &mConOut.UgaVerticalResolution,
956 &mConOut.UgaColorDepth,
957 &mConOut.UgaRefreshRate
958 );
959 }
960 #endif
961
962 return Status;
963 }
964
965 EFI_STATUS
966 EFIAPI
967 ConSplitterStdErrDriverBindingStart (
968 IN EFI_DRIVER_BINDING_PROTOCOL *This,
969 IN EFI_HANDLE ControllerHandle,
970 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
971 )
972 /*++
973
974 Routine Description:
975 Start ConSplitter on ControllerHandle, and create the virtual
976 agrogated console device on first call Start for a SimpleTextIn handle.
977
978 Arguments:
979 This - Pointer to protocol.
980 ControllerHandle - Controller handle.
981 RemainingDevicePath - Remaining device path.
982
983 Returns:
984 EFI_ERROR if a SimpleTextIn protocol is not started.
985
986 --*/
987 {
988 EFI_STATUS Status;
989 EFI_SIMPLE_TEXT_OUT_PROTOCOL *TextOut;
990
991 Status = ConSplitterStart (
992 This,
993 ControllerHandle,
994 mStdErr.VirtualHandle,
995 &gEfiStandardErrorDeviceGuid,
996 &gEfiSimpleTextOutProtocolGuid,
997 (VOID **) &TextOut
998 );
999 if (EFI_ERROR (Status)) {
1000 return Status;
1001 }
1002 //
1003 // If both ConOut and StdErr incorporate the same Text Out device,
1004 // their MaxMode and QueryData should be the intersection of both.
1005 //
1006 Status = ConSplitterTextOutAddDevice (&mStdErr, TextOut, NULL, NULL);
1007 ConSplitterTextOutSetAttribute (&mStdErr.TextOut, EFI_TEXT_ATTR (EFI_MAGENTA, EFI_BLACK));
1008 if (EFI_ERROR (Status)) {
1009 return Status;
1010 }
1011
1012 if (mStdErr.CurrentNumberOfConsoles == 1) {
1013 gST->StandardErrorHandle = mStdErr.VirtualHandle;
1014 gST->StdErr = &mStdErr.TextOut;
1015 //
1016 // Update the CRC32 in the EFI System Table header
1017 //
1018 gST->Hdr.CRC32 = 0;
1019 gBS->CalculateCrc32 (
1020 (UINT8 *) &gST->Hdr,
1021 gST->Hdr.HeaderSize,
1022 &gST->Hdr.CRC32
1023 );
1024 }
1025
1026 return Status;
1027 }
1028
1029 EFI_STATUS
1030 EFIAPI
1031 ConSplitterStop (
1032 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1033 IN EFI_HANDLE ControllerHandle,
1034 IN EFI_HANDLE ConSplitterVirtualHandle,
1035 IN EFI_GUID *DeviceGuid,
1036 IN EFI_GUID *InterfaceGuid,
1037 IN VOID **Interface
1038 )
1039 /*++
1040
1041 Routine Description:
1042
1043 Arguments:
1044 (Standard DriverBinding Protocol Stop() function)
1045
1046 Returns:
1047
1048 None
1049
1050 --*/
1051 {
1052 EFI_STATUS Status;
1053
1054 Status = gBS->OpenProtocol (
1055 ControllerHandle,
1056 InterfaceGuid,
1057 Interface,
1058 This->DriverBindingHandle,
1059 ControllerHandle,
1060 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1061 );
1062 if (EFI_ERROR (Status)) {
1063 return Status;
1064 }
1065 //
1066 // close the protocol refered.
1067 //
1068 gBS->CloseProtocol (
1069 ControllerHandle,
1070 DeviceGuid,
1071 This->DriverBindingHandle,
1072 ConSplitterVirtualHandle
1073 );
1074 gBS->CloseProtocol (
1075 ControllerHandle,
1076 DeviceGuid,
1077 This->DriverBindingHandle,
1078 ControllerHandle
1079 );
1080
1081 return EFI_SUCCESS;
1082 }
1083
1084 EFI_STATUS
1085 EFIAPI
1086 ConSplitterConInDriverBindingStop (
1087 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1088 IN EFI_HANDLE ControllerHandle,
1089 IN UINTN NumberOfChildren,
1090 IN EFI_HANDLE *ChildHandleBuffer
1091 )
1092 /*++
1093
1094 Routine Description:
1095
1096 Arguments:
1097 (Standard DriverBinding Protocol Stop() function)
1098
1099 Returns:
1100
1101 None
1102
1103 --*/
1104 {
1105 EFI_STATUS Status;
1106 EFI_SIMPLE_TEXT_IN_PROTOCOL *TextIn;
1107
1108 if (NumberOfChildren == 0) {
1109 return EFI_SUCCESS;
1110 }
1111
1112 Status = ConSplitterStop (
1113 This,
1114 ControllerHandle,
1115 mConIn.VirtualHandle,
1116 &gEfiConsoleInDeviceGuid,
1117 &gEfiSimpleTextInProtocolGuid,
1118 (VOID **) &TextIn
1119 );
1120 if (EFI_ERROR (Status)) {
1121 return Status;
1122 }
1123 //
1124 // Delete this console input device's data structures.
1125 //
1126 return ConSplitterTextInDeleteDevice (&mConIn, TextIn);
1127 }
1128
1129 EFI_STATUS
1130 EFIAPI
1131 ConSplitterSimplePointerDriverBindingStop (
1132 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1133 IN EFI_HANDLE ControllerHandle,
1134 IN UINTN NumberOfChildren,
1135 IN EFI_HANDLE *ChildHandleBuffer
1136 )
1137 /*++
1138
1139 Routine Description:
1140
1141 Arguments:
1142 (Standard DriverBinding Protocol Stop() function)
1143
1144 Returns:
1145
1146 None
1147
1148 --*/
1149 {
1150 EFI_STATUS Status;
1151 EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer;
1152
1153 if (NumberOfChildren == 0) {
1154 return EFI_SUCCESS;
1155 }
1156
1157 Status = ConSplitterStop (
1158 This,
1159 ControllerHandle,
1160 mConIn.VirtualHandle,
1161 &gEfiSimplePointerProtocolGuid,
1162 &gEfiSimplePointerProtocolGuid,
1163 (VOID **) &SimplePointer
1164 );
1165 if (EFI_ERROR (Status)) {
1166 return Status;
1167 }
1168 //
1169 // Delete this console input device's data structures.
1170 //
1171 return ConSplitterSimplePointerDeleteDevice (&mConIn, SimplePointer);
1172 }
1173
1174 EFI_STATUS
1175 EFIAPI
1176 ConSplitterConOutDriverBindingStop (
1177 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1178 IN EFI_HANDLE ControllerHandle,
1179 IN UINTN NumberOfChildren,
1180 IN EFI_HANDLE *ChildHandleBuffer
1181 )
1182 /*++
1183
1184 Routine Description:
1185
1186 Arguments:
1187 (Standard DriverBinding Protocol Stop() function)
1188
1189 Returns:
1190
1191 None
1192
1193 --*/
1194 {
1195 EFI_STATUS Status;
1196 EFI_SIMPLE_TEXT_OUT_PROTOCOL *TextOut;
1197
1198 if (NumberOfChildren == 0) {
1199 return EFI_SUCCESS;
1200 }
1201
1202 Status = ConSplitterStop (
1203 This,
1204 ControllerHandle,
1205 mConOut.VirtualHandle,
1206 &gEfiConsoleOutDeviceGuid,
1207 &gEfiSimpleTextOutProtocolGuid,
1208 (VOID **) &TextOut
1209 );
1210 if (EFI_ERROR (Status)) {
1211 return Status;
1212 }
1213
1214 //
1215 // Delete this console output device's data structures.
1216 //
1217 return ConSplitterTextOutDeleteDevice (&mConOut, TextOut);
1218 }
1219
1220 EFI_STATUS
1221 EFIAPI
1222 ConSplitterStdErrDriverBindingStop (
1223 IN EFI_DRIVER_BINDING_PROTOCOL *This,
1224 IN EFI_HANDLE ControllerHandle,
1225 IN UINTN NumberOfChildren,
1226 IN EFI_HANDLE *ChildHandleBuffer
1227 )
1228 /*++
1229
1230 Routine Description:
1231
1232 Arguments:
1233 (Standard DriverBinding Protocol Stop() function)
1234
1235 Returns:
1236
1237 EFI_SUCCESS - Complete successfully.
1238
1239 --*/
1240 {
1241 EFI_STATUS Status;
1242 EFI_SIMPLE_TEXT_OUT_PROTOCOL *TextOut;
1243
1244 if (NumberOfChildren == 0) {
1245 return EFI_SUCCESS;
1246 }
1247
1248 Status = ConSplitterStop (
1249 This,
1250 ControllerHandle,
1251 mStdErr.VirtualHandle,
1252 &gEfiStandardErrorDeviceGuid,
1253 &gEfiSimpleTextOutProtocolGuid,
1254 (VOID **) &TextOut
1255 );
1256 if (EFI_ERROR (Status)) {
1257 return Status;
1258 }
1259 //
1260 // Delete this console error out device's data structures.
1261 //
1262 Status = ConSplitterTextOutDeleteDevice (&mStdErr, TextOut);
1263 if (EFI_ERROR (Status)) {
1264 return Status;
1265 }
1266
1267 if (mStdErr.CurrentNumberOfConsoles == 0) {
1268 gST->StandardErrorHandle = NULL;
1269 gST->StdErr = NULL;
1270 //
1271 // Update the CRC32 in the EFI System Table header
1272 //
1273 gST->Hdr.CRC32 = 0;
1274 gBS->CalculateCrc32 (
1275 (UINT8 *) &gST->Hdr,
1276 gST->Hdr.HeaderSize,
1277 &gST->Hdr.CRC32
1278 );
1279 }
1280
1281 return Status;
1282 }
1283
1284 EFI_STATUS
1285 ConSplitterGrowBuffer (
1286 IN UINTN SizeOfCount,
1287 IN UINTN *Count,
1288 IN OUT VOID **Buffer
1289 )
1290 /*++
1291
1292 Routine Description:
1293 Take the passed in Buffer of size SizeOfCount and grow the buffer
1294 by MAX (CONSOLE_SPLITTER_CONSOLES_ALLOC_UNIT, MaxGrow) * SizeOfCount
1295 bytes. Copy the current data in Buffer to the new version of Buffer
1296 and free the old version of buffer.
1297
1298
1299 Arguments:
1300 SizeOfCount - Size of element in array
1301 Count - Current number of elements in array
1302 Buffer - Bigger version of passed in Buffer with all the data
1303
1304 Returns:
1305 EFI_SUCCESS - Buffer size has grown
1306 EFI_OUT_OF_RESOURCES - Could not grow the buffer size
1307
1308 None
1309
1310 --*/
1311 {
1312 UINTN NewSize;
1313 UINTN OldSize;
1314 VOID *Ptr;
1315
1316 //
1317 // grow the buffer to new buffer size,
1318 // copy the old buffer's content to the new-size buffer,
1319 // then free the old buffer.
1320 //
1321 OldSize = *Count * SizeOfCount;
1322 *Count += CONSOLE_SPLITTER_CONSOLES_ALLOC_UNIT;
1323 NewSize = *Count * SizeOfCount;
1324
1325 Ptr = AllocateZeroPool (NewSize);
1326 if (Ptr == NULL) {
1327 return EFI_OUT_OF_RESOURCES;
1328 }
1329
1330 CopyMem (Ptr, *Buffer, OldSize);
1331
1332 if (*Buffer != NULL) {
1333 gBS->FreePool (*Buffer);
1334 }
1335
1336 *Buffer = Ptr;
1337
1338 return EFI_SUCCESS;
1339 }
1340
1341 EFI_STATUS
1342 ConSplitterTextInAddDevice (
1343 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
1344 IN EFI_SIMPLE_TEXT_IN_PROTOCOL *TextIn
1345 )
1346 /*++
1347
1348 Routine Description:
1349
1350 Arguments:
1351
1352 Returns:
1353
1354 EFI_SUCCESS
1355 EFI_OUT_OF_RESOURCES
1356
1357 --*/
1358 {
1359 EFI_STATUS Status;
1360
1361 //
1362 // If the Text In List is full, enlarge it by calling growbuffer().
1363 //
1364 if (Private->CurrentNumberOfConsoles >= Private->TextInListCount) {
1365 Status = ConSplitterGrowBuffer (
1366 sizeof (EFI_SIMPLE_TEXT_IN_PROTOCOL *),
1367 &Private->TextInListCount,
1368 (VOID **) &Private->TextInList
1369 );
1370 if (EFI_ERROR (Status)) {
1371 return EFI_OUT_OF_RESOURCES;
1372 }
1373 }
1374 //
1375 // Add the new text-in device data structure into the Text In List.
1376 //
1377 Private->TextInList[Private->CurrentNumberOfConsoles] = TextIn;
1378 Private->CurrentNumberOfConsoles++;
1379
1380 //
1381 // Extra CheckEvent added to reduce the double CheckEvent() in UI.c
1382 //
1383 gBS->CheckEvent (TextIn->WaitForKey);
1384
1385 return EFI_SUCCESS;
1386 }
1387
1388 EFI_STATUS
1389 ConSplitterTextInDeleteDevice (
1390 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
1391 IN EFI_SIMPLE_TEXT_IN_PROTOCOL *TextIn
1392 )
1393 /*++
1394
1395 Routine Description:
1396
1397 Arguments:
1398
1399 Returns:
1400
1401 EFI_SUCCESS
1402 EFI_NOT_FOUND
1403
1404 --*/
1405 {
1406 UINTN Index;
1407 //
1408 // Remove the specified text-in device data structure from the Text In List,
1409 // and rearrange the remaining data structures in the Text In List.
1410 //
1411 for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {
1412 if (Private->TextInList[Index] == TextIn) {
1413 for (Index = Index; Index < Private->CurrentNumberOfConsoles - 1; Index++) {
1414 Private->TextInList[Index] = Private->TextInList[Index + 1];
1415 }
1416
1417 Private->CurrentNumberOfConsoles--;
1418 return EFI_SUCCESS;
1419 }
1420 }
1421
1422 return EFI_NOT_FOUND;
1423 }
1424
1425 EFI_STATUS
1426 ConSplitterSimplePointerAddDevice (
1427 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
1428 IN EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer
1429 )
1430 /*++
1431
1432 Routine Description:
1433
1434 Arguments:
1435
1436 Returns:
1437
1438 EFI_OUT_OF_RESOURCES
1439 EFI_SUCCESS
1440
1441 --*/
1442 {
1443 EFI_STATUS Status;
1444
1445 //
1446 // If the Text In List is full, enlarge it by calling growbuffer().
1447 //
1448 if (Private->CurrentNumberOfPointers >= Private->PointerListCount) {
1449 Status = ConSplitterGrowBuffer (
1450 sizeof (EFI_SIMPLE_POINTER_PROTOCOL *),
1451 &Private->PointerListCount,
1452 (VOID **) &Private->PointerList
1453 );
1454 if (EFI_ERROR (Status)) {
1455 return EFI_OUT_OF_RESOURCES;
1456 }
1457 }
1458 //
1459 // Add the new text-in device data structure into the Text In List.
1460 //
1461 Private->PointerList[Private->CurrentNumberOfPointers] = SimplePointer;
1462 Private->CurrentNumberOfPointers++;
1463 return EFI_SUCCESS;
1464 }
1465
1466 EFI_STATUS
1467 ConSplitterSimplePointerDeleteDevice (
1468 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
1469 IN EFI_SIMPLE_POINTER_PROTOCOL *SimplePointer
1470 )
1471 /*++
1472
1473 Routine Description:
1474
1475 Arguments:
1476
1477 Returns:
1478
1479 None
1480
1481 --*/
1482 {
1483 UINTN Index;
1484 //
1485 // Remove the specified text-in device data structure from the Text In List,
1486 // and rearrange the remaining data structures in the Text In List.
1487 //
1488 for (Index = 0; Index < Private->CurrentNumberOfPointers; Index++) {
1489 if (Private->PointerList[Index] == SimplePointer) {
1490 for (Index = Index; Index < Private->CurrentNumberOfPointers - 1; Index++) {
1491 Private->PointerList[Index] = Private->PointerList[Index + 1];
1492 }
1493
1494 Private->CurrentNumberOfPointers--;
1495 return EFI_SUCCESS;
1496 }
1497 }
1498
1499 return EFI_NOT_FOUND;
1500 }
1501
1502 EFI_STATUS
1503 ConSplitterGrowMapTable (
1504 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private
1505 )
1506 /*++
1507
1508 Routine Description:
1509
1510 Arguments:
1511
1512 Returns:
1513
1514 None
1515
1516 --*/
1517 {
1518 UINTN Size;
1519 UINTN NewSize;
1520 UINTN TotalSize;
1521 INT32 *TextOutModeMap;
1522 INT32 *OldTextOutModeMap;
1523 INT32 *SrcAddress;
1524 INT32 Index;
1525
1526 NewSize = Private->TextOutListCount * sizeof (INT32);
1527 OldTextOutModeMap = Private->TextOutModeMap;
1528 TotalSize = NewSize * Private->TextOutQueryDataCount;
1529
1530 TextOutModeMap = AllocateZeroPool (TotalSize);
1531 if (TextOutModeMap == NULL) {
1532 return EFI_OUT_OF_RESOURCES;
1533 }
1534
1535 SetMem (TextOutModeMap, TotalSize, 0xFF);
1536 Private->TextOutModeMap = TextOutModeMap;
1537
1538 //
1539 // If TextOutList has been enlarged, need to realloc the mode map table
1540 // The mode map table is regarded as a two dimension array.
1541 //
1542 // Old New
1543 // 0 ---------> TextOutListCount ----> TextOutListCount
1544 // | -------------------------------------------
1545 // | | | |
1546 // | | | |
1547 // | | | |
1548 // | | | |
1549 // | | | |
1550 // \/ | | |
1551 // -------------------------------------------
1552 // QueryDataCount
1553 //
1554 if (OldTextOutModeMap != NULL) {
1555
1556 Size = Private->CurrentNumberOfConsoles * sizeof (INT32);
1557 Index = 0;
1558 SrcAddress = OldTextOutModeMap;
1559
1560 //
1561 // Copy the old data to the new one
1562 //
1563 while (Index < Private->TextOutMode.MaxMode) {
1564 CopyMem (TextOutModeMap, SrcAddress, Size);
1565 TextOutModeMap += NewSize;
1566 SrcAddress += Size;
1567 Index++;
1568 }
1569 //
1570 // Free the old buffer
1571 //
1572 gBS->FreePool (OldTextOutModeMap);
1573 }
1574
1575 return EFI_SUCCESS;
1576 }
1577
1578 EFI_STATUS
1579 ConSplitterAddOutputMode (
1580 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
1581 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *TextOut
1582 )
1583 /*++
1584
1585 Routine Description:
1586
1587 Arguments:
1588
1589 Returns:
1590
1591 None
1592
1593 --*/
1594 {
1595 EFI_STATUS Status;
1596 INT32 MaxMode;
1597 INT32 Mode;
1598 UINTN Index;
1599
1600 MaxMode = TextOut->Mode->MaxMode;
1601 Private->TextOutMode.MaxMode = MaxMode;
1602
1603 //
1604 // Grow the buffer if query data buffer is not large enough to
1605 // hold all the mode supported by the first console.
1606 //
1607 while (MaxMode > (INT32) Private->TextOutQueryDataCount) {
1608 Status = ConSplitterGrowBuffer (
1609 sizeof (TEXT_OUT_SPLITTER_QUERY_DATA),
1610 &Private->TextOutQueryDataCount,
1611 (VOID **) &Private->TextOutQueryData
1612 );
1613 if (EFI_ERROR (Status)) {
1614 return EFI_OUT_OF_RESOURCES;
1615 }
1616 }
1617 //
1618 // Allocate buffer for the output mode map
1619 //
1620 Status = ConSplitterGrowMapTable (Private);
1621 if (EFI_ERROR (Status)) {
1622 return EFI_OUT_OF_RESOURCES;
1623 }
1624 //
1625 // As the first textout device, directly add the mode in to QueryData
1626 // and at the same time record the mapping between QueryData and TextOut.
1627 //
1628 Mode = 0;
1629 Index = 0;
1630 while (Mode < MaxMode) {
1631 TextOut->QueryMode (
1632 TextOut,
1633 Mode,
1634 &Private->TextOutQueryData[Mode].Columns,
1635 &Private->TextOutQueryData[Mode].Rows
1636 );
1637 Private->TextOutModeMap[Index] = Mode;
1638 Mode++;
1639 Index += Private->TextOutListCount;
1640 }
1641
1642 return EFI_SUCCESS;
1643 }
1644
1645 VOID
1646 ConSplitterGetIntersection (
1647 IN INT32 *TextOutModeMap,
1648 IN INT32 *NewlyAddedMap,
1649 IN UINTN MapStepSize,
1650 IN UINTN NewMapStepSize,
1651 OUT INT32 *MaxMode,
1652 OUT INT32 *CurrentMode
1653 )
1654 {
1655 INT32 Index;
1656 INT32 *CurrentMapEntry;
1657 INT32 *NextMapEntry;
1658 INT32 CurrentMaxMode;
1659 INT32 Mode;
1660
1661 Index = 0;
1662 CurrentMapEntry = TextOutModeMap;
1663 NextMapEntry = TextOutModeMap;
1664 CurrentMaxMode = *MaxMode;
1665 Mode = *CurrentMode;
1666
1667 while (Index < CurrentMaxMode) {
1668 if (*NewlyAddedMap == -1) {
1669 //
1670 // This mode is not supported any more. Remove it. Special care
1671 // must be taken as this remove will also affect current mode;
1672 //
1673 if (Index == *CurrentMode) {
1674 Mode = -1;
1675 } else if (Index < *CurrentMode) {
1676 Mode--;
1677 }
1678 (*MaxMode)--;
1679 } else {
1680 if (CurrentMapEntry != NextMapEntry) {
1681 CopyMem (NextMapEntry, CurrentMapEntry, MapStepSize * sizeof (INT32));
1682 }
1683
1684 NextMapEntry += MapStepSize;
1685 }
1686
1687 CurrentMapEntry += MapStepSize;
1688 NewlyAddedMap += NewMapStepSize;
1689 Index++;
1690 }
1691
1692 *CurrentMode = Mode;
1693
1694 return ;
1695 }
1696
1697 VOID
1698 ConSplitterSyncOutputMode (
1699 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
1700 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *TextOut
1701 )
1702 /*++
1703
1704 Routine Description:
1705
1706 Arguments:
1707 Private - Private data structure.
1708 TextOut - Text Out Protocol.
1709 Returns:
1710
1711 None
1712
1713 --*/
1714 {
1715 INT32 CurrentMode;
1716 INT32 CurrentMaxMode;
1717 INT32 Mode;
1718 INT32 Index;
1719 INT32 *TextOutModeMap;
1720 INT32 *MapTable;
1721 TEXT_OUT_SPLITTER_QUERY_DATA *TextOutQueryData;
1722 UINTN Rows;
1723 UINTN Columns;
1724 UINTN StepSize;
1725
1726 //
1727 // Must make sure that current mode won't change even if mode number changes
1728 //
1729 CurrentMode = Private->TextOutMode.Mode;
1730 CurrentMaxMode = Private->TextOutMode.MaxMode;
1731 TextOutModeMap = Private->TextOutModeMap;
1732 StepSize = Private->TextOutListCount;
1733 TextOutQueryData = Private->TextOutQueryData;
1734
1735 //
1736 // Query all the mode that the newly added TextOut supports
1737 //
1738 Mode = 0;
1739 MapTable = TextOutModeMap + Private->CurrentNumberOfConsoles;
1740 while (Mode < TextOut->Mode->MaxMode) {
1741 TextOut->QueryMode (TextOut, Mode, &Columns, &Rows);
1742
1743 //
1744 // Search the QueryData database to see if they intersects
1745 //
1746 Index = 0;
1747 while (Index < CurrentMaxMode) {
1748 if ((TextOutQueryData[Index].Rows == Rows) && (TextOutQueryData[Index].Columns == Columns)) {
1749 MapTable[Index * StepSize] = Mode;
1750 break;
1751 }
1752
1753 Index++;
1754 }
1755
1756 Mode++;
1757 }
1758 //
1759 // Now search the TextOutModeMap table to find the intersection of supported
1760 // mode between ConSplitter and the newly added device.
1761 //
1762 ConSplitterGetIntersection (
1763 TextOutModeMap,
1764 MapTable,
1765 StepSize,
1766 StepSize,
1767 &Private->TextOutMode.MaxMode,
1768 &Private->TextOutMode.Mode
1769 );
1770
1771 return ;
1772 }
1773
1774 EFI_STATUS
1775 ConSplitterGetIntersectionBetweenConOutAndStrErr (
1776 VOID
1777 )
1778 /*++
1779
1780 Routine Description:
1781
1782 Arguments:
1783
1784 Returns:
1785
1786 None
1787 EFI_OUT_OF_RESOURCES
1788
1789 --*/
1790 {
1791 UINTN ConOutNumOfConsoles;
1792 UINTN StdErrNumOfConsoles;
1793 TEXT_OUT_AND_GOP_DATA *ConOutTextOutList;
1794 TEXT_OUT_AND_GOP_DATA *StdErrTextOutList;
1795 UINTN Indexi;
1796 UINTN Indexj;
1797 UINTN Rows;
1798 UINTN Columns;
1799 INT32 ConOutCurrentMode;
1800 INT32 StdErrCurrentMode;
1801 INT32 ConOutMaxMode;
1802 INT32 StdErrMaxMode;
1803 INT32 Mode;
1804 INT32 Index;
1805 INT32 *ConOutModeMap;
1806 INT32 *StdErrModeMap;
1807 INT32 *ConOutMapTable;
1808 INT32 *StdErrMapTable;
1809 TEXT_OUT_SPLITTER_QUERY_DATA *ConOutQueryData;
1810 TEXT_OUT_SPLITTER_QUERY_DATA *StdErrQueryData;
1811 UINTN ConOutStepSize;
1812 UINTN StdErrStepSize;
1813 BOOLEAN FoundTheSameTextOut;
1814 UINTN ConOutMapTableSize;
1815 UINTN StdErrMapTableSize;
1816
1817 ConOutNumOfConsoles = mConOut.CurrentNumberOfConsoles;
1818 StdErrNumOfConsoles = mStdErr.CurrentNumberOfConsoles;
1819 ConOutTextOutList = mConOut.TextOutList;
1820 StdErrTextOutList = mStdErr.TextOutList;
1821
1822 Indexi = 0;
1823 FoundTheSameTextOut = FALSE;
1824 while ((Indexi < ConOutNumOfConsoles) && (!FoundTheSameTextOut)) {
1825 Indexj = 0;
1826 while (Indexj < StdErrNumOfConsoles) {
1827 if (ConOutTextOutList->TextOut == StdErrTextOutList->TextOut) {
1828 FoundTheSameTextOut = TRUE;
1829 break;
1830 }
1831
1832 Indexj++;
1833 StdErrTextOutList++;
1834 }
1835
1836 Indexi++;
1837 ConOutTextOutList++;
1838 }
1839
1840 if (!FoundTheSameTextOut) {
1841 return EFI_SUCCESS;
1842 }
1843 //
1844 // Must make sure that current mode won't change even if mode number changes
1845 //
1846 ConOutCurrentMode = mConOut.TextOutMode.Mode;
1847 ConOutMaxMode = mConOut.TextOutMode.MaxMode;
1848 ConOutModeMap = mConOut.TextOutModeMap;
1849 ConOutStepSize = mConOut.TextOutListCount;
1850 ConOutQueryData = mConOut.TextOutQueryData;
1851
1852 StdErrCurrentMode = mStdErr.TextOutMode.Mode;
1853 StdErrMaxMode = mStdErr.TextOutMode.MaxMode;
1854 StdErrModeMap = mStdErr.TextOutModeMap;
1855 StdErrStepSize = mStdErr.TextOutListCount;
1856 StdErrQueryData = mStdErr.TextOutQueryData;
1857
1858 //
1859 // Allocate the map table and set the map table's index to -1.
1860 //
1861 ConOutMapTableSize = ConOutMaxMode * sizeof (INT32);
1862 ConOutMapTable = AllocateZeroPool (ConOutMapTableSize);
1863 if (ConOutMapTable == NULL) {
1864 return EFI_OUT_OF_RESOURCES;
1865 }
1866
1867 SetMem (ConOutMapTable, ConOutMapTableSize, 0xFF);
1868
1869 StdErrMapTableSize = StdErrMaxMode * sizeof (INT32);
1870 StdErrMapTable = AllocateZeroPool (StdErrMapTableSize);
1871 if (StdErrMapTable == NULL) {
1872 return EFI_OUT_OF_RESOURCES;
1873 }
1874
1875 SetMem (StdErrMapTable, StdErrMapTableSize, 0xFF);
1876
1877 //
1878 // Find the intersection of the two set of modes. If they actually intersect, the
1879 // correponding entry in the map table is set to 1.
1880 //
1881 Mode = 0;
1882 while (Mode < ConOutMaxMode) {
1883 //
1884 // Search the other's QueryData database to see if they intersect
1885 //
1886 Index = 0;
1887 Rows = ConOutQueryData[Mode].Rows;
1888 Columns = ConOutQueryData[Mode].Columns;
1889 while (Index < StdErrMaxMode) {
1890 if ((StdErrQueryData[Index].Rows == Rows) && (StdErrQueryData[Index].Columns == Columns)) {
1891 ConOutMapTable[Mode] = 1;
1892 StdErrMapTable[Index] = 1;
1893 break;
1894 }
1895
1896 Index++;
1897 }
1898
1899 Mode++;
1900 }
1901 //
1902 // Now search the TextOutModeMap table to find the intersection of supported
1903 // mode between ConSplitter and the newly added device.
1904 //
1905 ConSplitterGetIntersection (
1906 ConOutModeMap,
1907 ConOutMapTable,
1908 mConOut.TextOutListCount,
1909 1,
1910 &(mConOut.TextOutMode.MaxMode),
1911 &(mConOut.TextOutMode.Mode)
1912 );
1913 if (mConOut.TextOutMode.Mode < 0) {
1914 mConOut.TextOut.SetMode (&(mConOut.TextOut), 0);
1915 }
1916
1917 ConSplitterGetIntersection (
1918 StdErrModeMap,
1919 StdErrMapTable,
1920 mStdErr.TextOutListCount,
1921 1,
1922 &(mStdErr.TextOutMode.MaxMode),
1923 &(mStdErr.TextOutMode.Mode)
1924 );
1925 if (mStdErr.TextOutMode.Mode < 0) {
1926 mStdErr.TextOut.SetMode (&(mStdErr.TextOut), 0);
1927 }
1928
1929 gBS->FreePool (ConOutMapTable);
1930 gBS->FreePool (StdErrMapTable);
1931
1932 return EFI_SUCCESS;
1933 }
1934
1935 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
1936 EFI_STATUS
1937 ConSplitterAddGraphicsOutputMode (
1938 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
1939 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput,
1940 IN EFI_UGA_DRAW_PROTOCOL *UgaDraw
1941 )
1942 /*++
1943
1944 Routine Description:
1945
1946 Arguments:
1947
1948 Returns:
1949
1950 None
1951
1952 --*/
1953 {
1954 EFI_STATUS Status;
1955 UINTN Index;
1956 TEXT_OUT_GOP_MODE *Mode;
1957 UINTN SizeOfInfo;
1958 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
1959 EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *CurrentGraphicsOutputMode;
1960 TEXT_OUT_GOP_MODE *ModeBuffer;
1961 TEXT_OUT_GOP_MODE *MatchedMode;
1962 UINTN NumberIndex;
1963 BOOLEAN Match;
1964
1965 if ((GraphicsOutput == NULL) && (UgaDraw == NULL)) {
1966 return EFI_UNSUPPORTED;
1967 }
1968
1969 CurrentGraphicsOutputMode = Private->GraphicsOutput.Mode;
1970
1971 if (GraphicsOutput != NULL) {
1972 if (Private->CurrentNumberOfGraphicsOutput == 0) {
1973 //
1974 // This is the first Graphics Output device added
1975 //
1976 CurrentGraphicsOutputMode->MaxMode = GraphicsOutput->Mode->MaxMode;
1977 CurrentGraphicsOutputMode->Mode = GraphicsOutput->Mode->Mode;
1978 CopyMem (CurrentGraphicsOutputMode->Info, GraphicsOutput->Mode->Info, GraphicsOutput->Mode->SizeOfInfo);
1979 CurrentGraphicsOutputMode->SizeOfInfo = GraphicsOutput->Mode->SizeOfInfo;
1980 CurrentGraphicsOutputMode->FrameBufferBase = GraphicsOutput->Mode->FrameBufferBase;
1981 CurrentGraphicsOutputMode->FrameBufferSize = GraphicsOutput->Mode->FrameBufferSize;
1982
1983 //
1984 // Allocate resource for the private mode buffer
1985 //
1986 ModeBuffer = AllocatePool (sizeof (TEXT_OUT_GOP_MODE) * GraphicsOutput->Mode->MaxMode);
1987 if (ModeBuffer == NULL) {
1988 return EFI_OUT_OF_RESOURCES;
1989 }
1990 gBS->FreePool (Private->GraphicsOutputModeBuffer);
1991 Private->GraphicsOutputModeBuffer = ModeBuffer;
1992
1993 //
1994 // Store all supported display modes to the private mode buffer
1995 //
1996 Mode = ModeBuffer;
1997 for (Index = 0; Index < GraphicsOutput->Mode->MaxMode; Index++) {
1998 Status = GraphicsOutput->QueryMode (GraphicsOutput, (UINT32) Index, &SizeOfInfo, &Info);
1999 if (EFI_ERROR (Status)) {
2000 return Status;
2001 }
2002 Mode->HorizontalResolution = Info->HorizontalResolution;
2003 Mode->VerticalResolution = Info->VerticalResolution;
2004 Mode++;
2005 gBS->FreePool (Info);
2006 }
2007 } else {
2008 //
2009 // Check intersection of display mode
2010 //
2011 ModeBuffer = AllocatePool (sizeof (TEXT_OUT_GOP_MODE) * CurrentGraphicsOutputMode->MaxMode);
2012 if (ModeBuffer == NULL) {
2013 return EFI_OUT_OF_RESOURCES;
2014 }
2015
2016 MatchedMode = ModeBuffer;
2017 Mode = &Private->GraphicsOutputModeBuffer[0];
2018 for (Index = 0; Index < CurrentGraphicsOutputMode->MaxMode; Index++) {
2019 Match = FALSE;
2020
2021 for (NumberIndex = 0; NumberIndex < GraphicsOutput->Mode->MaxMode; NumberIndex++) {
2022 Status = GraphicsOutput->QueryMode (GraphicsOutput, (UINT32) NumberIndex, &SizeOfInfo, &Info);
2023 if (EFI_ERROR (Status)) {
2024 return Status;
2025 }
2026 if ((Info->HorizontalResolution == Mode->HorizontalResolution) &&
2027 (Info->VerticalResolution == Mode->VerticalResolution)){
2028 Match = TRUE;
2029 gBS->FreePool (Info);
2030 break;
2031 }
2032 gBS->FreePool (Info);
2033 }
2034
2035 if (Match) {
2036 CopyMem (MatchedMode, Mode, sizeof (TEXT_OUT_GOP_MODE));
2037 MatchedMode++;
2038 }
2039
2040 Mode++;
2041 }
2042
2043 //
2044 // Drop the old mode buffer, assign it to a new one
2045 //
2046 gBS->FreePool (Private->GraphicsOutputModeBuffer);
2047 Private->GraphicsOutputModeBuffer = ModeBuffer;
2048
2049 //
2050 // Physical frame buffer is no longer available when there are more than one physical GOP devices
2051 //
2052 CurrentGraphicsOutputMode->MaxMode = (UINT32) (((UINTN) MatchedMode - (UINTN) ModeBuffer) / sizeof (TEXT_OUT_GOP_MODE));
2053 CurrentGraphicsOutputMode->Info->PixelFormat = PixelBltOnly;
2054 ZeroMem (&CurrentGraphicsOutputMode->Info->PixelInformation, sizeof (EFI_PIXEL_BITMASK));
2055 CurrentGraphicsOutputMode->SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
2056 CurrentGraphicsOutputMode->FrameBufferBase = (EFI_PHYSICAL_ADDRESS) NULL;
2057 CurrentGraphicsOutputMode->FrameBufferSize = 0;
2058 }
2059
2060 //
2061 // Select a prefered Display mode 800x600
2062 //
2063 for (Index = 0; Index < CurrentGraphicsOutputMode->MaxMode; Index++) {
2064 Mode = &Private->GraphicsOutputModeBuffer[Index];
2065 if ((Mode->HorizontalResolution == 800) && (Mode->VerticalResolution == 600)) {
2066 break;
2067 }
2068 }
2069 //
2070 // Prefered mode is not found, set to mode 0
2071 //
2072 if (Index >= CurrentGraphicsOutputMode->MaxMode) {
2073 Index = 0;
2074 }
2075
2076 //
2077 // Current mode number may need update now, so set it to an invalide mode number
2078 //
2079 CurrentGraphicsOutputMode->Mode = 0xffff;
2080 } else {
2081 //
2082 // For UGA device, it's inconvenient to retrieve all the supported display modes.
2083 // To simplify the implementation, only add one resolution(800x600, 32bit color depth) as defined in UEFI spec
2084 //
2085 CurrentGraphicsOutputMode->MaxMode = 1;
2086 CurrentGraphicsOutputMode->Info->Version = 0;
2087 CurrentGraphicsOutputMode->Info->HorizontalResolution = 800;
2088 CurrentGraphicsOutputMode->Info->VerticalResolution = 600;
2089 CurrentGraphicsOutputMode->Info->PixelFormat = PixelBltOnly;
2090 CurrentGraphicsOutputMode->Info->PixelsPerScanLine = 800;
2091 CurrentGraphicsOutputMode->SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
2092 CurrentGraphicsOutputMode->FrameBufferBase = (EFI_PHYSICAL_ADDRESS) NULL;
2093 CurrentGraphicsOutputMode->FrameBufferSize = 0;
2094
2095 //
2096 // Update the private mode buffer
2097 //
2098 ModeBuffer = &Private->GraphicsOutputModeBuffer[0];
2099 ModeBuffer->HorizontalResolution = 800;
2100 ModeBuffer->VerticalResolution = 600;
2101
2102 //
2103 // Current mode is unknow now, set it to an invalid mode number 0xffff
2104 //
2105 CurrentGraphicsOutputMode->Mode = 0xffff;
2106 Index = 0;
2107 }
2108
2109 //
2110 // Force GraphicsOutput mode to be set,
2111 // regardless whether the console is in EfiConsoleControlScreenGraphics or EfiConsoleControlScreenText mode
2112 //
2113 Private->HardwareNeedsStarting = TRUE;
2114 Status = Private->GraphicsOutput.SetMode (&Private->GraphicsOutput, (UINT32) Index);
2115
2116 Private->CurrentNumberOfGraphicsOutput++;
2117
2118 return Status;
2119 }
2120 #endif
2121
2122 EFI_STATUS
2123 ConSplitterTextOutAddDevice (
2124 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
2125 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *TextOut,
2126 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput,
2127 IN EFI_UGA_DRAW_PROTOCOL *UgaDraw
2128 )
2129 /*++
2130
2131 Routine Description:
2132
2133 Arguments:
2134
2135 Returns:
2136
2137 None
2138
2139 --*/
2140 {
2141 EFI_STATUS Status;
2142 UINTN CurrentNumOfConsoles;
2143 INT32 CurrentMode;
2144 INT32 MaxMode;
2145 TEXT_OUT_AND_GOP_DATA *TextAndGop;
2146
2147 Status = EFI_SUCCESS;
2148 CurrentNumOfConsoles = Private->CurrentNumberOfConsoles;
2149
2150 //
2151 // If the Text Out List is full, enlarge it by calling growbuffer().
2152 //
2153 while (CurrentNumOfConsoles >= Private->TextOutListCount) {
2154 Status = ConSplitterGrowBuffer (
2155 sizeof (TEXT_OUT_AND_GOP_DATA),
2156 &Private->TextOutListCount,
2157 (VOID **) &Private->TextOutList
2158 );
2159 if (EFI_ERROR (Status)) {
2160 return EFI_OUT_OF_RESOURCES;
2161 }
2162 //
2163 // Also need to reallocate the TextOutModeMap table
2164 //
2165 Status = ConSplitterGrowMapTable (Private);
2166 if (EFI_ERROR (Status)) {
2167 return EFI_OUT_OF_RESOURCES;
2168 }
2169 }
2170
2171 TextAndGop = &Private->TextOutList[CurrentNumOfConsoles];
2172
2173 TextAndGop->TextOut = TextOut;
2174 TextAndGop->GraphicsOutput = GraphicsOutput;
2175 TextAndGop->UgaDraw = UgaDraw;
2176
2177 if ((GraphicsOutput == NULL) && (UgaDraw == NULL)) {
2178 //
2179 // If No UGA device then use the ConOut device
2180 //
2181 TextAndGop->TextOutEnabled = TRUE;
2182 } else {
2183 //
2184 // If UGA device use ConOut device only used if UGA screen is in Text mode
2185 //
2186 TextAndGop->TextOutEnabled = (BOOLEAN) (Private->ConsoleOutputMode == EfiConsoleControlScreenText);
2187 }
2188
2189 if (CurrentNumOfConsoles == 0) {
2190 //
2191 // Add the first device's output mode to console splitter's mode list
2192 //
2193 Status = ConSplitterAddOutputMode (Private, TextOut);
2194 } else {
2195 ConSplitterSyncOutputMode (Private, TextOut);
2196 }
2197
2198 Private->CurrentNumberOfConsoles++;
2199
2200 //
2201 // Scan both TextOutList, for the intersection TextOut device
2202 // maybe both ConOut and StdErr incorporate the same Text Out
2203 // device in them, thus the output of both should be synced.
2204 //
2205 ConSplitterGetIntersectionBetweenConOutAndStrErr ();
2206
2207 CurrentMode = Private->TextOutMode.Mode;
2208 MaxMode = Private->TextOutMode.MaxMode;
2209 ASSERT (MaxMode >= 1);
2210
2211 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
2212 if ((GraphicsOutput != NULL) || (UgaDraw != NULL)) {
2213 ConSplitterAddGraphicsOutputMode (Private, GraphicsOutput, UgaDraw);
2214 }
2215 #endif
2216
2217 if (Private->ConsoleOutputMode == EfiConsoleControlScreenGraphics && GraphicsOutput != NULL) {
2218 //
2219 // We just added a new UGA device in graphics mode
2220 //
2221 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
2222 DevNullGopSync (Private, GraphicsOutput, UgaDraw);
2223 #else
2224 DevNullUgaSync (Private, UgaDraw);
2225 #endif
2226 } else if ((CurrentMode >= 0) && ((GraphicsOutput != NULL) || (UgaDraw != NULL)) && (CurrentMode < Private->TextOutMode.MaxMode)) {
2227 //
2228 // The new console supports the same mode of the current console so sync up
2229 //
2230 DevNullSyncGopStdOut (Private);
2231 } else {
2232 //
2233 // If ConOut, then set the mode to Mode #0 which us 80 x 25
2234 //
2235 Private->TextOut.SetMode (&Private->TextOut, 0);
2236 }
2237
2238 return Status;
2239 }
2240
2241 EFI_STATUS
2242 ConSplitterTextOutDeleteDevice (
2243 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
2244 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *TextOut
2245 )
2246 /*++
2247
2248 Routine Description:
2249
2250 Arguments:
2251
2252 Returns:
2253
2254 None
2255
2256 --*/
2257 {
2258 INT32 Index;
2259 UINTN CurrentNumOfConsoles;
2260 TEXT_OUT_AND_GOP_DATA *TextOutList;
2261 EFI_STATUS Status;
2262
2263 //
2264 // Remove the specified text-out device data structure from the Text out List,
2265 // and rearrange the remaining data structures in the Text out List.
2266 //
2267 CurrentNumOfConsoles = Private->CurrentNumberOfConsoles;
2268 Index = (INT32) CurrentNumOfConsoles - 1;
2269 TextOutList = Private->TextOutList;
2270 while (Index >= 0) {
2271 if (TextOutList->TextOut == TextOut) {
2272 CopyMem (TextOutList, TextOutList + 1, sizeof (TEXT_OUT_AND_GOP_DATA) * Index);
2273 CurrentNumOfConsoles--;
2274 break;
2275 }
2276
2277 Index--;
2278 TextOutList++;
2279 }
2280 //
2281 // The specified TextOut is not managed by the ConSplitter driver
2282 //
2283 if (Index < 0) {
2284 return EFI_NOT_FOUND;
2285 }
2286
2287 if (CurrentNumOfConsoles == 0) {
2288 //
2289 // If the number of consoles is zero clear the Dev NULL device
2290 //
2291 Private->CurrentNumberOfConsoles = 0;
2292 Private->TextOutMode.MaxMode = 1;
2293 Private->TextOutQueryData[0].Columns = 80;
2294 Private->TextOutQueryData[0].Rows = 25;
2295 DevNullTextOutSetMode (Private, 0);
2296
2297 return EFI_SUCCESS;
2298 }
2299 //
2300 // Max Mode is realy an intersection of the QueryMode command to all
2301 // devices. So we must copy the QueryMode of the first device to
2302 // QueryData.
2303 //
2304 ZeroMem (
2305 Private->TextOutQueryData,
2306 Private->TextOutQueryDataCount * sizeof (TEXT_OUT_SPLITTER_QUERY_DATA)
2307 );
2308
2309 gBS->FreePool (Private->TextOutModeMap);
2310 Private->TextOutModeMap = NULL;
2311 TextOutList = Private->TextOutList;
2312
2313 //
2314 // Add the first TextOut to the QueryData array and ModeMap table
2315 //
2316 Status = ConSplitterAddOutputMode (Private, TextOutList->TextOut);
2317
2318 //
2319 // Now add one by one
2320 //
2321 Index = 1;
2322 Private->CurrentNumberOfConsoles = 1;
2323 TextOutList++;
2324 while ((UINTN) Index < CurrentNumOfConsoles) {
2325 ConSplitterSyncOutputMode (Private, TextOutList->TextOut);
2326 Index++;
2327 Private->CurrentNumberOfConsoles++;
2328 TextOutList++;
2329 }
2330
2331 ConSplitterGetIntersectionBetweenConOutAndStrErr ();
2332
2333 return Status;
2334 }
2335 //
2336 // ConSplitter TextIn member functions
2337 //
2338 EFI_STATUS
2339 EFIAPI
2340 ConSplitterTextInReset (
2341 IN EFI_SIMPLE_TEXT_IN_PROTOCOL *This,
2342 IN BOOLEAN ExtendedVerification
2343 )
2344 /*++
2345
2346 Routine Description:
2347 Reset the input device and optionaly run diagnostics
2348
2349 Arguments:
2350 This - Protocol instance pointer.
2351 ExtendedVerification - Driver may perform diagnostics on reset.
2352
2353 Returns:
2354 EFI_SUCCESS - The device was reset.
2355 EFI_DEVICE_ERROR - The device is not functioning properly and could
2356 not be reset.
2357
2358 --*/
2359 {
2360 EFI_STATUS Status;
2361 EFI_STATUS ReturnStatus;
2362 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
2363 UINTN Index;
2364
2365 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
2366
2367 Private->KeyEventSignalState = FALSE;
2368
2369 //
2370 // return the worst status met
2371 //
2372 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfConsoles; Index++) {
2373 Status = Private->TextInList[Index]->Reset (
2374 Private->TextInList[Index],
2375 ExtendedVerification
2376 );
2377 if (EFI_ERROR (Status)) {
2378 ReturnStatus = Status;
2379 }
2380 }
2381
2382 return ReturnStatus;
2383 }
2384
2385 EFI_STATUS
2386 EFIAPI
2387 ConSplitterTextInPrivateReadKeyStroke (
2388 IN TEXT_IN_SPLITTER_PRIVATE_DATA *Private,
2389 OUT EFI_INPUT_KEY *Key
2390 )
2391 /*++
2392
2393 Routine Description:
2394 Reads the next keystroke from the input device. The WaitForKey Event can
2395 be used to test for existance of a keystroke via WaitForEvent () call.
2396
2397 Arguments:
2398 This - Protocol instance pointer.
2399 Key - Driver may perform diagnostics on reset.
2400
2401 Returns:
2402 EFI_SUCCESS - The keystroke information was returned.
2403 EFI_NOT_READY - There was no keystroke data availiable.
2404 EFI_DEVICE_ERROR - The keydtroke information was not returned due to
2405 hardware errors.
2406
2407 --*/
2408 {
2409 EFI_STATUS Status;
2410 UINTN Index;
2411 EFI_INPUT_KEY CurrentKey;
2412
2413 Key->UnicodeChar = 0;
2414 Key->ScanCode = SCAN_NULL;
2415
2416 //
2417 // if no physical console input device exists, return EFI_NOT_READY;
2418 // if any physical console input device has key input,
2419 // return the key and EFI_SUCCESS.
2420 //
2421 for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {
2422 Status = Private->TextInList[Index]->ReadKeyStroke (
2423 Private->TextInList[Index],
2424 &CurrentKey
2425 );
2426 if (!EFI_ERROR (Status)) {
2427 *Key = CurrentKey;
2428 return Status;
2429 }
2430 }
2431
2432 return EFI_NOT_READY;
2433 }
2434
2435 BOOLEAN
2436 ConSpliterConssoleControlStdInLocked (
2437 VOID
2438 )
2439 /*++
2440
2441 Routine Description:
2442 Return TRUE if StdIn is locked. The ConIn device on the virtual handle is
2443 the only device locked.
2444
2445 Arguments:
2446 NONE
2447
2448 Returns:
2449 TRUE - StdIn locked
2450 FALSE - StdIn working normally
2451
2452 --*/
2453 {
2454 return mConIn.PasswordEnabled;
2455 }
2456
2457 VOID
2458 EFIAPI
2459 ConSpliterConsoleControlLockStdInEvent (
2460 IN EFI_EVENT Event,
2461 IN VOID *Context
2462 )
2463 /*++
2464
2465 Routine Description:
2466 This timer event will fire when StdIn is locked. It will check the key
2467 sequence on StdIn to see if it matches the password. Any error in the
2468 password will cause the check to reset. As long a mConIn.PasswordEnabled is
2469 TRUE the StdIn splitter will not report any input.
2470
2471 Arguments:
2472 (Standard EFI_EVENT_NOTIFY)
2473
2474 Returns:
2475 None
2476
2477 --*/
2478 {
2479 EFI_STATUS Status;
2480 EFI_INPUT_KEY Key;
2481 CHAR16 BackSpaceString[2];
2482 CHAR16 SpaceString[2];
2483
2484 do {
2485 Status = ConSplitterTextInPrivateReadKeyStroke (&mConIn, &Key);
2486 if (!EFI_ERROR (Status)) {
2487 //
2488 // if it's an ENTER, match password
2489 //
2490 if ((Key.UnicodeChar == CHAR_CARRIAGE_RETURN) && (Key.ScanCode == SCAN_NULL)) {
2491 mConIn.PwdAttempt[mConIn.PwdIndex] = CHAR_NULL;
2492 if (StrCmp (mConIn.Password, mConIn.PwdAttempt)) {
2493 //
2494 // Password not match
2495 //
2496 ConSplitterTextOutOutputString (&mConOut.TextOut, (CHAR16 *) L"\n\rPassword not correct\n\r");
2497 mConIn.PwdIndex = 0;
2498 } else {
2499 //
2500 // Key matches password sequence
2501 //
2502 gBS->SetTimer (mConIn.LockEvent, TimerPeriodic, 0);
2503 mConIn.PasswordEnabled = FALSE;
2504 Status = EFI_NOT_READY;
2505 }
2506 } else if ((Key.UnicodeChar == CHAR_BACKSPACE) && (Key.ScanCode == SCAN_NULL)) {
2507 //
2508 // BackSpace met
2509 //
2510 if (mConIn.PwdIndex > 0) {
2511 BackSpaceString[0] = CHAR_BACKSPACE;
2512 BackSpaceString[1] = 0;
2513
2514 SpaceString[0] = ' ';
2515 SpaceString[1] = 0;
2516
2517 ConSplitterTextOutOutputString (&mConOut.TextOut, BackSpaceString);
2518 ConSplitterTextOutOutputString (&mConOut.TextOut, SpaceString);
2519 ConSplitterTextOutOutputString (&mConOut.TextOut, BackSpaceString);
2520
2521 mConIn.PwdIndex--;
2522 }
2523 } else if ((Key.ScanCode == SCAN_NULL) && (Key.UnicodeChar >= 32)) {
2524 //
2525 // If it's not an ENTER, neigher a function key, nor a CTRL-X or ALT-X, record the input
2526 //
2527 if (mConIn.PwdIndex < (MAX_STD_IN_PASSWORD - 1)) {
2528 if (mConIn.PwdIndex == 0) {
2529 ConSplitterTextOutOutputString (&mConOut.TextOut, (CHAR16 *) L"\n\r");
2530 }
2531
2532 ConSplitterTextOutOutputString (&mConOut.TextOut, (CHAR16 *) L"*");
2533 mConIn.PwdAttempt[mConIn.PwdIndex] = Key.UnicodeChar;
2534 mConIn.PwdIndex++;
2535 }
2536 }
2537 }
2538 } while (!EFI_ERROR (Status));
2539 }
2540
2541 EFI_STATUS
2542 EFIAPI
2543 ConSpliterConsoleControlLockStdIn (
2544 IN EFI_CONSOLE_CONTROL_PROTOCOL *This,
2545 IN CHAR16 *Password
2546 )
2547 /*++
2548
2549 Routine Description:
2550 If Password is NULL unlock the password state variable and set the event
2551 timer. If the Password is too big return an error. If the Password is valid
2552 Copy the Password and enable state variable and then arm the periodic timer
2553
2554 Arguments:
2555
2556 Returns:
2557 EFI_SUCCESS - Lock the StdIn device
2558 EFI_INVALID_PARAMETER - Password is NULL
2559 EFI_OUT_OF_RESOURCES - Buffer allocation to store the password fails
2560
2561 --*/
2562 {
2563 if (Password == NULL) {
2564 return EFI_INVALID_PARAMETER;
2565 }
2566
2567 if (StrLen (Password) >= MAX_STD_IN_PASSWORD) {
2568 //
2569 // Currently have a max password size
2570 //
2571 return EFI_OUT_OF_RESOURCES;
2572 }
2573 //
2574 // Save the password, initialize state variables and arm event timer
2575 //
2576 StrCpy (mConIn.Password, Password);
2577 mConIn.PasswordEnabled = TRUE;
2578 mConIn.PwdIndex = 0;
2579 gBS->SetTimer (mConIn.LockEvent, TimerPeriodic, (10000 * 25));
2580
2581 return EFI_SUCCESS;
2582 }
2583
2584 EFI_STATUS
2585 EFIAPI
2586 ConSplitterTextInReadKeyStroke (
2587 IN EFI_SIMPLE_TEXT_IN_PROTOCOL *This,
2588 OUT EFI_INPUT_KEY *Key
2589 )
2590 /*++
2591
2592 Routine Description:
2593 Reads the next keystroke from the input device. The WaitForKey Event can
2594 be used to test for existance of a keystroke via WaitForEvent () call.
2595 If the ConIn is password locked make it look like no keystroke is availible
2596
2597 Arguments:
2598 This - Protocol instance pointer.
2599 Key - Driver may perform diagnostics on reset.
2600
2601 Returns:
2602 EFI_SUCCESS - The keystroke information was returned.
2603 EFI_NOT_READY - There was no keystroke data availiable.
2604 EFI_DEVICE_ERROR - The keydtroke information was not returned due to
2605 hardware errors.
2606
2607 --*/
2608 {
2609 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
2610
2611 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
2612 if (Private->PasswordEnabled) {
2613 //
2614 // If StdIn Locked return not ready
2615 //
2616 return EFI_NOT_READY;
2617 }
2618
2619 Private->KeyEventSignalState = FALSE;
2620
2621 return ConSplitterTextInPrivateReadKeyStroke (Private, Key);
2622 }
2623
2624 VOID
2625 EFIAPI
2626 ConSplitterTextInWaitForKey (
2627 IN EFI_EVENT Event,
2628 IN VOID *Context
2629 )
2630 /*++
2631
2632 Routine Description:
2633 This event agregates all the events of the ConIn devices in the spliter.
2634 If the ConIn is password locked then return.
2635 If any events of physical ConIn devices are signaled, signal the ConIn
2636 spliter event. This will cause the calling code to call
2637 ConSplitterTextInReadKeyStroke ().
2638
2639 Arguments:
2640 Event - The Event assoicated with callback.
2641 Context - Context registered when Event was created.
2642
2643 Returns:
2644 None
2645
2646 --*/
2647 {
2648 EFI_STATUS Status;
2649 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
2650 UINTN Index;
2651
2652 Private = (TEXT_IN_SPLITTER_PRIVATE_DATA *) Context;
2653 if (Private->PasswordEnabled) {
2654 //
2655 // If StdIn Locked return not ready
2656 //
2657 return ;
2658 }
2659
2660 //
2661 // if KeyEventSignalState is flagged before, and not cleared by Reset() or ReadKeyStroke()
2662 //
2663 if (Private->KeyEventSignalState) {
2664 gBS->SignalEvent (Event);
2665 return ;
2666 }
2667 //
2668 // if any physical console input device has key input, signal the event.
2669 //
2670 for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {
2671 Status = gBS->CheckEvent (Private->TextInList[Index]->WaitForKey);
2672 if (!EFI_ERROR (Status)) {
2673 gBS->SignalEvent (Event);
2674 Private->KeyEventSignalState = TRUE;
2675 }
2676 }
2677 }
2678
2679 EFI_STATUS
2680 EFIAPI
2681 ConSplitterSimplePointerReset (
2682 IN EFI_SIMPLE_POINTER_PROTOCOL *This,
2683 IN BOOLEAN ExtendedVerification
2684 )
2685 /*++
2686
2687 Routine Description:
2688 Reset the input device and optionaly run diagnostics
2689
2690 Arguments:
2691 This - Protocol instance pointer.
2692 ExtendedVerification - Driver may perform diagnostics on reset.
2693
2694 Returns:
2695 EFI_SUCCESS - The device was reset.
2696 EFI_DEVICE_ERROR - The device is not functioning properly and could
2697 not be reset.
2698
2699 --*/
2700 {
2701 EFI_STATUS Status;
2702 EFI_STATUS ReturnStatus;
2703 TEXT_IN_SPLITTER_PRIVATE_DATA *Private;
2704 UINTN Index;
2705
2706 Private = TEXT_IN_SPLITTER_PRIVATE_DATA_FROM_SIMPLE_POINTER_THIS (This);
2707
2708 Private->InputEventSignalState = FALSE;
2709
2710 if (Private->CurrentNumberOfPointers == 0) {
2711 return EFI_SUCCESS;
2712 }
2713 //
2714 // return the worst status met
2715 //
2716 for (Index = 0, ReturnStatus = EFI_SUCCESS; Index < Private->CurrentNumberOfPointers; Index++) {
2717 Status = Private->PointerList[Index]->Reset (
2718 Private->PointerList[Index],
2719 ExtendedVerification
2720 );
2721 if (EFI_ERROR (Status)) {
2722 ReturnStatus = Status;
2723 }
2724 }
2725
2726 return ReturnStatus;
2727 }
2728
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 gBS->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 }