2 Produces Simple Text Input Protocol, Simple Text Input Extended Protocol and
3 Simple Text Output Protocol upon Serial IO Protocol.
5 Copyright (c) 2006 - 2008, Intel Corporation. <BR>
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22 EFI_DRIVER_BINDING_PROTOCOL gTerminalDriverBinding
= {
23 TerminalDriverBindingSupported
,
24 TerminalDriverBindingStart
,
25 TerminalDriverBindingStop
,
32 EFI_GUID
*gTerminalType
[] = {
40 TERMINAL_DEV mTerminalDevTemplate
= {
41 TERMINAL_DEV_SIGNATURE
,
48 TerminalConInReadKeyStroke
,
53 TerminalConOutOutputString
,
54 TerminalConOutTestString
,
55 TerminalConOutQueryMode
,
56 TerminalConOutSetMode
,
57 TerminalConOutSetAttribute
,
58 TerminalConOutClearScreen
,
59 TerminalConOutSetCursorPosition
,
60 TerminalConOutEnableCursor
,
63 { // SimpleTextOutputMode
66 EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
), // Attribute
87 NULL
, // ControllerNameTable
88 NULL
, // TwoSecondTimeOut
92 { // SimpleTextInputEx
94 TerminalConInReadKeyStrokeEx
,
96 TerminalConInSetState
,
97 TerminalConInRegisterKeyNotify
,
98 TerminalConInUnregisterKeyNotify
,
107 Test to see if this driver supports Controller.
109 @param This Protocol instance pointer.
110 @param Controller Handle of device to test
111 @param RemainingDevicePath Optional parameter use to pick a specific child
114 @retval EFI_SUCCESS This driver supports this device.
115 @retval EFI_ALREADY_STARTED This driver is already running on this device.
116 @retval other This driver does not support this device.
121 TerminalDriverBindingSupported (
122 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
123 IN EFI_HANDLE Controller
,
124 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
128 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
129 EFI_SERIAL_IO_PROTOCOL
*SerialIo
;
130 VENDOR_DEVICE_PATH
*Node
;
133 // If remaining device path is not NULL, then make sure it is a
134 // device path that describes a terminal communications protocol.
136 if (RemainingDevicePath
!= NULL
) {
138 Node
= (VENDOR_DEVICE_PATH
*) RemainingDevicePath
;
140 if (Node
->Header
.Type
!= MESSAGING_DEVICE_PATH
||
141 Node
->Header
.SubType
!= MSG_VENDOR_DP
||
142 DevicePathNodeLength(&Node
->Header
) != sizeof(VENDOR_DEVICE_PATH
)) {
144 return EFI_UNSUPPORTED
;
148 // only supports PC ANSI, VT100, VT100+ and VT-UTF8 terminal types
150 if (!CompareGuid (&Node
->Guid
, &gEfiPcAnsiGuid
) &&
151 !CompareGuid (&Node
->Guid
, &gEfiVT100Guid
) &&
152 !CompareGuid (&Node
->Guid
, &gEfiVT100PlusGuid
) &&
153 !CompareGuid (&Node
->Guid
, &gEfiVTUTF8Guid
)) {
155 return EFI_UNSUPPORTED
;
159 // Open the IO Abstraction(s) needed to perform the supported test
161 Status
= gBS
->OpenProtocol (
163 &gEfiDevicePathProtocolGuid
,
164 (VOID
**) &ParentDevicePath
,
165 This
->DriverBindingHandle
,
167 EFI_OPEN_PROTOCOL_BY_DRIVER
169 if (Status
== EFI_ALREADY_STARTED
) {
173 if (EFI_ERROR (Status
)) {
179 &gEfiDevicePathProtocolGuid
,
180 This
->DriverBindingHandle
,
185 // The Controller must support the Serial I/O Protocol.
186 // This driver is a bus driver with at most 1 child device, so it is
187 // ok for it to be already started.
189 Status
= gBS
->OpenProtocol (
191 &gEfiSerialIoProtocolGuid
,
193 This
->DriverBindingHandle
,
195 EFI_OPEN_PROTOCOL_BY_DRIVER
197 if (Status
== EFI_ALREADY_STARTED
) {
201 if (EFI_ERROR (Status
)) {
205 // Close the I/O Abstraction(s) used to perform the supported test
209 &gEfiSerialIoProtocolGuid
,
210 This
->DriverBindingHandle
,
218 Start this driver on Controller by opening a Serial IO protocol,
219 reading Device Path, and creating a child handle with a Simple Text In,
220 Simple Text In Ex and Simple Text Out protocol, and device path protocol.
221 And store Console Device Environment Variables.
223 @param This Protocol instance pointer.
224 @param Controller Handle of device to bind driver to
225 @param RemainingDevicePath Optional parameter use to pick a specific child
228 @retval EFI_SUCCESS This driver is added to Controller.
229 @retval EFI_ALREADY_STARTED This driver is already running on Controller.
230 @retval other This driver does not support this device.
235 TerminalDriverBindingStart (
236 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
237 IN EFI_HANDLE Controller
,
238 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
242 EFI_SERIAL_IO_PROTOCOL
*SerialIo
;
243 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
244 VENDOR_DEVICE_PATH
*Node
;
245 VENDOR_DEVICE_PATH
*DefaultNode
;
246 EFI_SERIAL_IO_MODE
*Mode
;
247 UINTN SerialInTimeOut
;
248 TERMINAL_DEV
*TerminalDevice
;
250 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY
*OpenInfoBuffer
;
253 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
254 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOutput
;
256 TerminalDevice
= NULL
;
259 // Get the Device Path Protocol to build the device path of the child device
261 Status
= gBS
->OpenProtocol (
263 &gEfiDevicePathProtocolGuid
,
264 (VOID
**) &ParentDevicePath
,
265 This
->DriverBindingHandle
,
267 EFI_OPEN_PROTOCOL_BY_DRIVER
269 if (EFI_ERROR (Status
) && Status
!= EFI_ALREADY_STARTED
) {
274 // Open the Serial I/O Protocol BY_DRIVER. It might already be started.
276 Status
= gBS
->OpenProtocol (
278 &gEfiSerialIoProtocolGuid
,
280 This
->DriverBindingHandle
,
282 EFI_OPEN_PROTOCOL_BY_DRIVER
284 if (EFI_ERROR (Status
) && Status
!= EFI_ALREADY_STARTED
) {
288 if (Status
!= EFI_ALREADY_STARTED
) {
290 // If Serial I/O is not already open by this driver, then tag the handle
291 // with the Terminal Driver GUID and update the ConInDev, ConOutDev, and
292 // StdErrDev variables with the list of possible terminal types on this
295 Status
= gBS
->OpenProtocol (
299 This
->DriverBindingHandle
,
301 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
303 if (EFI_ERROR (Status
)) {
304 Status
= gBS
->InstallMultipleProtocolInterfaces (
307 DuplicateDevicePath (ParentDevicePath
),
310 if (EFI_ERROR (Status
)) {
314 // if the serial device is a hot plug device, do not update the
315 // ConInDev, ConOutDev, and StdErrDev variables.
317 Status
= gBS
->OpenProtocol (
319 &gEfiHotPlugDeviceGuid
,
321 This
->DriverBindingHandle
,
323 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
325 if (EFI_ERROR (Status
)) {
326 TerminalUpdateConsoleDevVariable (L
"ConInDev", ParentDevicePath
);
327 TerminalUpdateConsoleDevVariable (L
"ConOutDev", ParentDevicePath
);
328 TerminalUpdateConsoleDevVariable (L
"ErrOutDev", ParentDevicePath
);
333 // Make sure a child handle does not already exist. This driver can only
334 // produce one child per serial port.
336 Status
= gBS
->OpenProtocolInformation (
338 &gEfiSerialIoProtocolGuid
,
342 if (!EFI_ERROR (Status
)) {
343 Status
= EFI_SUCCESS
;
344 for (Index
= 0; Index
< EntryCount
; Index
++) {
345 if (OpenInfoBuffer
[Index
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) {
346 Status
= EFI_ALREADY_STARTED
;
350 FreePool (OpenInfoBuffer
);
351 if (EFI_ERROR (Status
)) {
356 // If RemainingDevicePath is NULL, then create default device path node
358 if (RemainingDevicePath
== NULL
) {
359 DefaultNode
= AllocateZeroPool (sizeof (VENDOR_DEVICE_PATH
));
360 if (DefaultNode
== NULL
) {
361 Status
= EFI_OUT_OF_RESOURCES
;
365 TerminalType
= FixedPcdGet8 (PcdDefaultTerminalType
);
367 // Must be between PCANSITYPE (0) and VTUTF8TYPE (3)
369 ASSERT (TerminalType
<= VTUTF8TYPE
);
371 CopyMem (&DefaultNode
->Guid
, gTerminalType
[TerminalType
], sizeof (EFI_GUID
));
372 RemainingDevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) DefaultNode
;
375 // Use the RemainingDevicePath to determine the terminal type
377 Node
= (VENDOR_DEVICE_PATH
*)RemainingDevicePath
;
378 if (CompareGuid (&Node
->Guid
, &gEfiPcAnsiGuid
)) {
379 TerminalType
= PCANSITYPE
;
380 } else if (CompareGuid (&Node
->Guid
, &gEfiVT100Guid
)) {
381 TerminalType
= VT100TYPE
;
382 } else if (CompareGuid (&Node
->Guid
, &gEfiVT100PlusGuid
)) {
383 TerminalType
= VT100PLUSTYPE
;
384 } else if (CompareGuid (&Node
->Guid
, &gEfiVTUTF8Guid
)) {
385 TerminalType
= VTUTF8TYPE
;
392 // Initialize the Terminal Dev
394 TerminalDevice
= AllocateCopyPool (sizeof (TERMINAL_DEV
), &mTerminalDevTemplate
);
395 if (TerminalDevice
== NULL
) {
396 Status
= EFI_OUT_OF_RESOURCES
;
400 TerminalDevice
->TerminalType
= TerminalType
;
401 TerminalDevice
->SerialIo
= SerialIo
;
403 InitializeListHead (&TerminalDevice
->NotifyList
);
404 Status
= gBS
->CreateEvent (
407 TerminalConInWaitForKeyEx
,
408 &TerminalDevice
->SimpleInputEx
,
409 &TerminalDevice
->SimpleInputEx
.WaitForKeyEx
411 if (EFI_ERROR (Status
)) {
416 Status
= gBS
->CreateEvent (
419 TerminalConInWaitForKey
,
420 &TerminalDevice
->SimpleInput
,
421 &TerminalDevice
->SimpleInput
.WaitForKey
423 if (EFI_ERROR (Status
)) {
427 // initialize the FIFO buffer used for accommodating
428 // the pre-read pending characters
430 InitializeRawFiFo (TerminalDevice
);
431 InitializeUnicodeFiFo (TerminalDevice
);
432 InitializeEfiKeyFiFo (TerminalDevice
);
435 // Set the timeout value of serial buffer for
436 // keystroke response performance issue
438 Mode
= TerminalDevice
->SerialIo
->Mode
;
441 if (Mode
->BaudRate
!= 0) {
442 SerialInTimeOut
= (1 + Mode
->DataBits
+ Mode
->StopBits
) * 2 * 1000000 / (UINTN
) Mode
->BaudRate
;
445 Status
= TerminalDevice
->SerialIo
->SetAttributes (
446 TerminalDevice
->SerialIo
,
448 Mode
->ReceiveFifoDepth
,
449 (UINT32
) SerialInTimeOut
,
450 (EFI_PARITY_TYPE
) (Mode
->Parity
),
451 (UINT8
) Mode
->DataBits
,
452 (EFI_STOP_BITS_TYPE
) (Mode
->StopBits
)
454 if (EFI_ERROR (Status
)) {
456 // if set attributes operation fails, invalidate
457 // the value of SerialInTimeOut,thus make it
458 // inconsistent with the default timeout value
459 // of serial buffer. This will invoke the recalculation
460 // in the readkeystroke routine.
462 TerminalDevice
->SerialInTimeOut
= 0;
464 TerminalDevice
->SerialInTimeOut
= SerialInTimeOut
;
467 // Build the device path for the child device
469 Status
= SetTerminalDevicePath (
470 TerminalDevice
->TerminalType
,
472 &TerminalDevice
->DevicePath
474 if (EFI_ERROR (Status
)) {
478 DevicePath
= TerminalDevice
->DevicePath
;
480 Status
= TerminalDevice
->SimpleInput
.Reset (
481 &TerminalDevice
->SimpleInput
,
484 if (EFI_ERROR (Status
)) {
486 // Need to report Error Code first
491 // Set Simple Text Output Protocol from template.
493 SimpleTextOutput
= CopyMem (
494 &TerminalDevice
->SimpleTextOutput
,
495 &mTerminalDevTemplate
.SimpleTextOutput
,
496 sizeof (mTerminalDevTemplate
.SimpleTextOutput
)
498 SimpleTextOutput
->Mode
= &TerminalDevice
->SimpleTextOutputMode
;
500 TerminalDevice
->SimpleTextOutputMode
.MaxMode
= 3;
502 // For terminal devices, cursor is always visible
504 TerminalDevice
->SimpleTextOutputMode
.CursorVisible
= TRUE
;
505 Status
= TerminalConOutSetAttribute (
507 EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
)
509 if (EFI_ERROR (Status
)) {
513 Status
= TerminalConOutReset (SimpleTextOutput
, FALSE
);
514 if (EFI_ERROR (Status
)) {
518 Status
= TerminalConOutSetMode (SimpleTextOutput
, 0);
519 if (EFI_ERROR (Status
)) {
523 Status
= TerminalConOutEnableCursor (SimpleTextOutput
, TRUE
);
524 if (EFI_ERROR (Status
)) {
528 Status
= gBS
->CreateEvent (
533 &TerminalDevice
->TwoSecondTimeOut
537 // Build the component name for the child device
539 TerminalDevice
->ControllerNameTable
= NULL
;
540 switch (TerminalDevice
->TerminalType
) {
544 gTerminalComponentName
.SupportedLanguages
,
545 &TerminalDevice
->ControllerNameTable
,
546 (CHAR16
*)L
"PC-ANSI Serial Console",
551 gTerminalComponentName2
.SupportedLanguages
,
552 &TerminalDevice
->ControllerNameTable
,
553 (CHAR16
*)L
"PC-ANSI Serial Console",
562 gTerminalComponentName
.SupportedLanguages
,
563 &TerminalDevice
->ControllerNameTable
,
564 (CHAR16
*)L
"VT-100 Serial Console",
569 gTerminalComponentName2
.SupportedLanguages
,
570 &TerminalDevice
->ControllerNameTable
,
571 (CHAR16
*)L
"VT-100 Serial Console",
580 gTerminalComponentName
.SupportedLanguages
,
581 &TerminalDevice
->ControllerNameTable
,
582 (CHAR16
*)L
"VT-100+ Serial Console",
587 gTerminalComponentName2
.SupportedLanguages
,
588 &TerminalDevice
->ControllerNameTable
,
589 (CHAR16
*)L
"VT-100+ Serial Console",
598 gTerminalComponentName
.SupportedLanguages
,
599 &TerminalDevice
->ControllerNameTable
,
600 (CHAR16
*)L
"VT-UTF8 Serial Console",
605 gTerminalComponentName2
.SupportedLanguages
,
606 &TerminalDevice
->ControllerNameTable
,
607 (CHAR16
*)L
"VT-UTF8 Serial Console",
614 // Install protocol interfaces for the serial device.
616 Status
= gBS
->InstallMultipleProtocolInterfaces (
617 &TerminalDevice
->Handle
,
618 &gEfiDevicePathProtocolGuid
,
619 TerminalDevice
->DevicePath
,
620 &gEfiSimpleTextInProtocolGuid
,
621 &TerminalDevice
->SimpleInput
,
622 &gEfiSimpleTextInputExProtocolGuid
,
623 &TerminalDevice
->SimpleInputEx
,
624 &gEfiSimpleTextOutProtocolGuid
,
625 &TerminalDevice
->SimpleTextOutput
,
628 if (EFI_ERROR (Status
)) {
632 // if the serial device is a hot plug device, attaches the HotPlugGuid
633 // onto the terminal device handle.
635 Status
= gBS
->OpenProtocol (
637 &gEfiHotPlugDeviceGuid
,
639 This
->DriverBindingHandle
,
641 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
643 if (!EFI_ERROR (Status
)) {
644 Status
= gBS
->InstallMultipleProtocolInterfaces (
645 &TerminalDevice
->Handle
,
646 &gEfiHotPlugDeviceGuid
,
652 // Register the Parent-Child relationship via
653 // EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
655 Status
= gBS
->OpenProtocol (
657 &gEfiSerialIoProtocolGuid
,
658 (VOID
**) &TerminalDevice
->SerialIo
,
659 This
->DriverBindingHandle
,
660 TerminalDevice
->Handle
,
661 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
663 if (EFI_ERROR (Status
)) {
667 if (DefaultNode
!= NULL
) {
668 FreePool (DefaultNode
);
675 // Report error code before exiting
677 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
678 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
679 PcdGet32 (PcdStatusCodeValueRemoteConsoleError
),
685 // Use the Stop() function to free all resources allocated in Start()
687 if (TerminalDevice
!= NULL
) {
689 if (TerminalDevice
->Handle
!= NULL
) {
690 This
->Stop (This
, Controller
, 1, &TerminalDevice
->Handle
);
693 if (TerminalDevice
->TwoSecondTimeOut
!= NULL
) {
694 gBS
->CloseEvent (TerminalDevice
->TwoSecondTimeOut
);
697 if (TerminalDevice
->SimpleInput
.WaitForKey
!= NULL
) {
698 gBS
->CloseEvent (TerminalDevice
->SimpleInput
.WaitForKey
);
701 if (TerminalDevice
->SimpleInputEx
.WaitForKeyEx
!= NULL
) {
702 gBS
->CloseEvent (TerminalDevice
->SimpleInputEx
.WaitForKeyEx
);
705 TerminalFreeNotifyList (&TerminalDevice
->NotifyList
);
707 if (TerminalDevice
->ControllerNameTable
!= NULL
) {
708 FreeUnicodeStringTable (TerminalDevice
->ControllerNameTable
);
711 if (TerminalDevice
->DevicePath
!= NULL
) {
712 FreePool (TerminalDevice
->DevicePath
);
715 FreePool (TerminalDevice
);
719 if (DefaultNode
!= NULL
) {
720 FreePool (DefaultNode
);
723 This
->Stop (This
, Controller
, 0, NULL
);
729 Stop this driver on Controller by closing Simple Text In, Simple Text
730 In Ex, Simple Text Out protocol, and removing parent device path from
731 Console Device Environment Variables.
733 @param This Protocol instance pointer.
734 @param Controller Handle of device to stop driver on
735 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
736 children is zero stop the entire bus driver.
737 @param ChildHandleBuffer List of Child Handles to Stop.
739 @retval EFI_SUCCESS This driver is removed Controller.
740 @retval other This driver could not be removed from this device.
745 TerminalDriverBindingStop (
746 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
747 IN EFI_HANDLE Controller
,
748 IN UINTN NumberOfChildren
,
749 IN EFI_HANDLE
*ChildHandleBuffer
754 BOOLEAN AllChildrenStopped
;
755 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*SimpleTextOutput
;
756 TERMINAL_DEV
*TerminalDevice
;
757 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
758 EFI_SERIAL_IO_PROTOCOL
*SerialIo
;
759 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
761 Status
= gBS
->HandleProtocol (
763 &gEfiDevicePathProtocolGuid
,
764 (VOID
**) &DevicePath
766 if (EFI_ERROR (Status
)) {
771 // Complete all outstanding transactions to Controller.
772 // Don't allow any new transaction to Controller to be started.
774 if (NumberOfChildren
== 0) {
776 // Close the bus driver
778 Status
= gBS
->OpenProtocol (
781 (VOID
**) &ParentDevicePath
,
782 This
->DriverBindingHandle
,
784 EFI_OPEN_PROTOCOL_GET_PROTOCOL
786 if (!EFI_ERROR (Status
)) {
788 // Remove Parent Device Path from
789 // the Console Device Environment Variables
791 TerminalRemoveConsoleDevVariable (L
"ConInDev", ParentDevicePath
);
792 TerminalRemoveConsoleDevVariable (L
"ConOutDev", ParentDevicePath
);
793 TerminalRemoveConsoleDevVariable (L
"ErrOutDev", ParentDevicePath
);
796 // Uninstall the Terminal Driver's GUID Tag from the Serial controller
798 Status
= gBS
->UninstallMultipleProtocolInterfaces (
806 // Free the ParentDevicePath that was duplicated in Start()
808 if (!EFI_ERROR (Status
)) {
809 FreePool (ParentDevicePath
);
815 &gEfiSerialIoProtocolGuid
,
816 This
->DriverBindingHandle
,
822 &gEfiDevicePathProtocolGuid
,
823 This
->DriverBindingHandle
,
830 AllChildrenStopped
= TRUE
;
832 for (Index
= 0; Index
< NumberOfChildren
; Index
++) {
834 Status
= gBS
->OpenProtocol (
835 ChildHandleBuffer
[Index
],
836 &gEfiSimpleTextOutProtocolGuid
,
837 (VOID
**) &SimpleTextOutput
,
838 This
->DriverBindingHandle
,
839 ChildHandleBuffer
[Index
],
840 EFI_OPEN_PROTOCOL_GET_PROTOCOL
842 if (!EFI_ERROR (Status
)) {
844 TerminalDevice
= TERMINAL_CON_OUT_DEV_FROM_THIS (SimpleTextOutput
);
848 &gEfiSerialIoProtocolGuid
,
849 This
->DriverBindingHandle
,
850 ChildHandleBuffer
[Index
]
853 Status
= gBS
->UninstallMultipleProtocolInterfaces (
854 ChildHandleBuffer
[Index
],
855 &gEfiSimpleTextInProtocolGuid
,
856 &TerminalDevice
->SimpleInput
,
857 &gEfiSimpleTextInputExProtocolGuid
,
858 &TerminalDevice
->SimpleInputEx
,
859 &gEfiSimpleTextOutProtocolGuid
,
860 &TerminalDevice
->SimpleTextOutput
,
861 &gEfiDevicePathProtocolGuid
,
862 TerminalDevice
->DevicePath
,
865 if (EFI_ERROR (Status
)) {
868 &gEfiSerialIoProtocolGuid
,
870 This
->DriverBindingHandle
,
871 ChildHandleBuffer
[Index
],
872 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
876 if (TerminalDevice
->ControllerNameTable
!= NULL
) {
877 FreeUnicodeStringTable (TerminalDevice
->ControllerNameTable
);
880 Status
= gBS
->OpenProtocol (
881 ChildHandleBuffer
[Index
],
882 &gEfiHotPlugDeviceGuid
,
884 This
->DriverBindingHandle
,
886 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
888 if (!EFI_ERROR (Status
)) {
889 Status
= gBS
->UninstallMultipleProtocolInterfaces (
890 ChildHandleBuffer
[Index
],
891 &gEfiHotPlugDeviceGuid
,
896 Status
= EFI_SUCCESS
;
899 gBS
->CloseEvent (TerminalDevice
->TwoSecondTimeOut
);
900 gBS
->CloseEvent (TerminalDevice
->SimpleInput
.WaitForKey
);
901 gBS
->CloseEvent (TerminalDevice
->SimpleInputEx
.WaitForKeyEx
);
902 TerminalFreeNotifyList (&TerminalDevice
->NotifyList
);
903 FreePool (TerminalDevice
->DevicePath
);
904 FreePool (TerminalDevice
);
908 if (EFI_ERROR (Status
)) {
909 AllChildrenStopped
= FALSE
;
913 if (!AllChildrenStopped
) {
914 return EFI_DEVICE_ERROR
;
922 Free notify functions list.
924 @param ListHead The list head
926 @retval EFI_SUCCESS Free the notify list successfully.
927 @retval EFI_INVALID_PARAMETER ListHead is NULL.
931 TerminalFreeNotifyList (
932 IN OUT LIST_ENTRY
*ListHead
935 TERMINAL_CONSOLE_IN_EX_NOTIFY
*NotifyNode
;
937 if (ListHead
== NULL
) {
938 return EFI_INVALID_PARAMETER
;
940 while (!IsListEmpty (ListHead
)) {
942 ListHead
->ForwardLink
,
943 TERMINAL_CONSOLE_IN_EX_NOTIFY
,
945 TERMINAL_CONSOLE_IN_EX_NOTIFY_SIGNATURE
947 RemoveEntryList (ListHead
->ForwardLink
);
948 FreePool (NotifyNode
);
956 Update terminal device path in Console Device Environment Variables.
958 @param VariableName The Console Device Environment Variable.
959 @param ParentDevicePath The terminal device path to be updated.
965 TerminalUpdateConsoleDevVariable (
966 IN CHAR16
*VariableName
,
967 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
973 EFI_DEVICE_PATH_PROTOCOL
*Variable
;
974 EFI_DEVICE_PATH_PROTOCOL
*NewVariable
;
975 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
980 // Get global variable and its size according to the name given.
982 Variable
= TerminalGetVariableAndSize (
984 &gEfiGlobalVariableGuid
,
988 // Append terminal device path onto the variable.
990 for (TerminalType
= PCANSITYPE
; TerminalType
<= VTUTF8TYPE
; TerminalType
++) {
991 SetTerminalDevicePath (TerminalType
, ParentDevicePath
, &TempDevicePath
);
992 NewVariable
= AppendDevicePathInstance (Variable
, TempDevicePath
);
993 if (Variable
!= NULL
) {
997 if (TempDevicePath
!= NULL
) {
998 FreePool (TempDevicePath
);
1001 Variable
= NewVariable
;
1004 VariableSize
= GetDevicePathSize (Variable
);
1006 Status
= gRT
->SetVariable (
1008 &gEfiGlobalVariableGuid
,
1009 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
1013 ASSERT_EFI_ERROR (Status
);
1014 FreePool (Variable
);
1021 Remove terminal device path from Console Device Environment Variables.
1023 @param VariableName Console Device Environment Variables.
1024 @param ParentDevicePath The terminal device path to be updated.
1030 TerminalRemoveConsoleDevVariable (
1031 IN CHAR16
*VariableName
,
1032 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
1041 EFI_DEVICE_PATH_PROTOCOL
*Instance
;
1042 EFI_DEVICE_PATH_PROTOCOL
*Variable
;
1043 EFI_DEVICE_PATH_PROTOCOL
*OriginalVariable
;
1044 EFI_DEVICE_PATH_PROTOCOL
*NewVariable
;
1045 EFI_DEVICE_PATH_PROTOCOL
*SavedNewVariable
;
1046 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
1052 // Get global variable and its size according to the name given.
1054 Variable
= TerminalGetVariableAndSize (
1056 &gEfiGlobalVariableGuid
,
1059 if (Variable
== NULL
) {
1064 OriginalVariable
= Variable
;
1068 // Get first device path instance from Variable
1070 Instance
= GetNextDevicePathInstance (&Variable
, &InstanceSize
);
1071 if (Instance
== NULL
) {
1072 FreePool (OriginalVariable
);
1076 // Loop through all the device path instances of Variable
1080 // Loop through all the terminal types that this driver supports
1083 for (TerminalType
= PCANSITYPE
; TerminalType
<= VTUTF8TYPE
; TerminalType
++) {
1085 SetTerminalDevicePath (TerminalType
, ParentDevicePath
, &TempDevicePath
);
1088 // Compare the generated device path to the current device path instance
1090 if (TempDevicePath
!= NULL
) {
1091 if (CompareMem (Instance
, TempDevicePath
, InstanceSize
) == 0) {
1096 FreePool (TempDevicePath
);
1100 // If a match was not found, then keep the current device path instance
1103 SavedNewVariable
= NewVariable
;
1104 NewVariable
= AppendDevicePathInstance (NewVariable
, Instance
);
1105 if (SavedNewVariable
!= NULL
) {
1106 FreePool (SavedNewVariable
);
1110 // Get next device path instance from Variable
1112 FreePool (Instance
);
1113 Instance
= GetNextDevicePathInstance (&Variable
, &InstanceSize
);
1114 } while (Instance
!= NULL
);
1116 FreePool (OriginalVariable
);
1119 VariableSize
= GetDevicePathSize (NewVariable
);
1121 Status
= gRT
->SetVariable (
1123 &gEfiGlobalVariableGuid
,
1124 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
1128 ASSERT_EFI_ERROR (Status
);
1131 if (NewVariable
!= NULL
) {
1132 FreePool (NewVariable
);
1140 Read the EFI variable (VendorGuid/Name) and return a dynamically allocated
1141 buffer, and the size of the buffer. On failure return NULL.
1143 @param Name String part of EFI variable name
1144 @param VendorGuid GUID part of EFI variable name
1145 @param VariableSize Returns the size of the EFI variable that was read
1147 @return Dynamically allocated memory that contains a copy of the EFI variable.
1148 Caller is responsible freeing the buffer. If variable was not read,
1153 TerminalGetVariableAndSize (
1155 IN EFI_GUID
*VendorGuid
,
1156 OUT UINTN
*VariableSize
1166 // Pass in a small size buffer to find the actual variable size.
1169 Buffer
= AllocatePool (BufferSize
);
1170 if (Buffer
== NULL
) {
1175 Status
= gRT
->GetVariable (Name
, VendorGuid
, NULL
, &BufferSize
, Buffer
);
1177 if (Status
== EFI_SUCCESS
) {
1178 *VariableSize
= BufferSize
;
1181 } else if (Status
== EFI_BUFFER_TOO_SMALL
) {
1183 // Allocate the buffer to return
1186 Buffer
= AllocatePool (BufferSize
);
1187 if (Buffer
== NULL
) {
1192 // Read variable into the allocated buffer.
1194 Status
= gRT
->GetVariable (Name
, VendorGuid
, NULL
, &BufferSize
, Buffer
);
1195 if (EFI_ERROR (Status
)) {
1202 // Variable not found or other errors met.
1209 *VariableSize
= BufferSize
;
1214 Build terminal device path according to terminal type.
1216 @param TerminalType The terminal type is PC ANSI, VT100, VT100+ or VT-UTF8.
1217 @param ParentDevicePath Parent device path.
1218 @param TerminalDevicePath Returned terminal device path, if building successfully.
1220 @retval EFI_UNSUPPORTED Terminal does not belong to the supported type.
1221 @retval EFI_OUT_OF_RESOURCES Generate terminal device path failed.
1222 @retval EFI_SUCCESS Build terminal device path successfully.
1226 SetTerminalDevicePath (
1227 IN UINT8 TerminalType
,
1228 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
1229 OUT EFI_DEVICE_PATH_PROTOCOL
**TerminalDevicePath
1232 VENDOR_DEVICE_PATH Node
;
1234 *TerminalDevicePath
= NULL
;
1235 Node
.Header
.Type
= MESSAGING_DEVICE_PATH
;
1236 Node
.Header
.SubType
= MSG_VENDOR_DP
;
1239 // Generate terminal device path node according to terminal type.
1241 switch (TerminalType
) {
1244 CopyGuid (&Node
.Guid
, &gEfiPcAnsiGuid
);
1248 CopyGuid (&Node
.Guid
, &gEfiVT100Guid
);
1252 CopyGuid (&Node
.Guid
, &gEfiVT100PlusGuid
);
1256 CopyGuid (&Node
.Guid
, &gEfiVTUTF8Guid
);
1260 return EFI_UNSUPPORTED
;
1264 // Get VENDOR_DEVCIE_PATH size and put into Node.Header
1266 SetDevicePathNodeLength (
1268 sizeof (VENDOR_DEVICE_PATH
)
1272 // Append the terminal node onto parent device path
1273 // to generate a complete terminal device path.
1275 *TerminalDevicePath
= AppendDevicePathNode (
1277 (EFI_DEVICE_PATH_PROTOCOL
*) &Node
1279 if (*TerminalDevicePath
== NULL
) {
1280 return EFI_OUT_OF_RESOURCES
;
1287 Initialize the Raw Data FIFO.
1289 @param TerminalDevice The terminal device.
1296 IN TERMINAL_DEV
*TerminalDevice
1300 // Make the raw FIFO empty.
1302 TerminalDevice
->RawFiFo
.Head
= TerminalDevice
->RawFiFo
.Tail
;
1306 Initialize the Unicode FIFO.
1308 @param TerminalDevice The terminal device.
1314 InitializeUnicodeFiFo (
1315 IN TERMINAL_DEV
*TerminalDevice
1319 // Make the unicode FIFO empty
1321 TerminalDevice
->UnicodeFiFo
.Head
= TerminalDevice
->UnicodeFiFo
.Tail
;
1325 Initialize the EFI Key FIFO.
1327 @param TerminalDevice The terminal device.
1333 InitializeEfiKeyFiFo (
1334 IN TERMINAL_DEV
*TerminalDevice
1338 // Make the efi key FIFO empty
1340 TerminalDevice
->EfiKeyFiFo
.Head
= TerminalDevice
->EfiKeyFiFo
.Tail
;
1345 The user Entry Point for module Terminal. The user code starts with this function.
1347 @param ImageHandle The firmware allocated handle for the EFI image.
1348 @param SystemTable A pointer to the EFI System Table.
1350 @retval EFI_SUCCESS The entry point is executed successfully.
1351 @retval other Some error occurs when executing this entry point.
1357 IN EFI_HANDLE ImageHandle
,
1358 IN EFI_SYSTEM_TABLE
*SystemTable
1364 // Install driver model protocol(s).
1366 Status
= EfiLibInstallDriverBindingComponentName2 (
1369 &gTerminalDriverBinding
,
1371 &gTerminalComponentName
,
1372 &gTerminalComponentName2
1374 ASSERT_EFI_ERROR (Status
);