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