2 Header file for Terminal driver.
4 Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
5 Copyright (C) 2016 Silicon Graphics, Inc. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
15 #include <Guid/GlobalVariable.h>
16 #include <Guid/PcAnsi.h>
17 #include <Guid/TtyTerm.h>
18 #include <Guid/StatusCodeDataTypeVariable.h>
20 #include <Protocol/SimpleTextOut.h>
21 #include <Protocol/SerialIo.h>
22 #include <Protocol/DevicePath.h>
23 #include <Protocol/SimpleTextIn.h>
24 #include <Protocol/SimpleTextInEx.h>
26 #include <Library/DebugLib.h>
27 #include <Library/UefiDriverEntryPoint.h>
28 #include <Library/UefiLib.h>
29 #include <Library/ReportStatusCodeLib.h>
30 #include <Library/BaseMemoryLib.h>
31 #include <Library/MemoryAllocationLib.h>
32 #include <Library/UefiBootServicesTableLib.h>
33 #include <Library/UefiRuntimeServicesTableLib.h>
34 #include <Library/DevicePathLib.h>
35 #include <Library/PcdLib.h>
36 #include <Library/BaseLib.h>
38 #define RAW_FIFO_MAX_NUMBER 255
39 #define FIFO_MAX_NUMBER 128
44 UINT8 Data
[RAW_FIFO_MAX_NUMBER
+ 1];
50 UINT16 Data
[FIFO_MAX_NUMBER
+ 1];
56 EFI_INPUT_KEY Data
[FIFO_MAX_NUMBER
+ 1];
62 } TERMINAL_CONSOLE_MODE_DATA
;
64 #define KEYBOARD_TIMER_INTERVAL 200000 // 0.02s
66 #define TERMINAL_DEV_SIGNATURE SIGNATURE_32 ('t', 'm', 'n', 'l')
68 #define TERMINAL_CONSOLE_IN_EX_NOTIFY_SIGNATURE SIGNATURE_32 ('t', 'm', 'e', 'n')
70 typedef struct _TERMINAL_CONSOLE_IN_EX_NOTIFY
{
73 EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn
;
74 LIST_ENTRY NotifyEntry
;
75 } TERMINAL_CONSOLE_IN_EX_NOTIFY
;
80 TerminalTypeVt100Plus
,
92 TERMINAL_TYPE TerminalType
;
93 EFI_SERIAL_IO_PROTOCOL
*SerialIo
;
94 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
95 EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleInput
;
96 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL SimpleTextOutput
;
97 EFI_SIMPLE_TEXT_OUTPUT_MODE SimpleTextOutputMode
;
98 TERMINAL_CONSOLE_MODE_DATA
*TerminalConsoleModeData
;
99 UINTN SerialInTimeOut
;
100 RAW_DATA_FIFO
*RawFiFo
;
101 UNICODE_FIFO
*UnicodeFiFo
;
102 EFI_KEY_FIFO
*EfiKeyFiFo
;
103 EFI_KEY_FIFO
*EfiKeyFiFoForNotify
;
104 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
105 EFI_EVENT TimerEvent
;
106 EFI_EVENT TwoSecondTimeOut
;
109 UINT16 TtyEscapeStr
[3];
113 // Esc could not be output to the screen by user,
114 // but the terminal driver need to output it to
115 // the terminal emulation software to send control sequence.
116 // This boolean is used by the terminal driver only
117 // to indicate whether the Esc could be sent or not.
119 BOOLEAN OutputEscChar
;
120 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL SimpleInputEx
;
121 LIST_ENTRY NotifyList
;
122 EFI_EVENT KeyNotifyProcessEvent
;
125 #define INPUT_STATE_DEFAULT 0x00
126 #define INPUT_STATE_ESC 0x01
127 #define INPUT_STATE_CSI 0x02
128 #define INPUT_STATE_LEFTOPENBRACKET 0x04
129 #define INPUT_STATE_O 0x08
130 #define INPUT_STATE_2 0x10
131 #define INPUT_STATE_LEFTOPENBRACKET_TTY 0x20
132 #define INPUT_STATE_1 0x40
133 #define INPUT_STATE_LEFTOPENBRACKET_2ND 0x80
135 #define RESET_STATE_DEFAULT 0x00
136 #define RESET_STATE_ESC_R 0x01
137 #define RESET_STATE_ESC_R_ESC_R 0x02
139 #define TERMINAL_CON_IN_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleInput, TERMINAL_DEV_SIGNATURE)
140 #define TERMINAL_CON_OUT_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleTextOutput, TERMINAL_DEV_SIGNATURE)
141 #define TERMINAL_CON_IN_EX_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleInputEx, TERMINAL_DEV_SIGNATURE)
149 #define LEFTOPENBRACKET 0x5b // '['
159 #define BRIGHT_CONTROL_OFFSET 2
160 #define FOREGROUND_CONTROL_OFFSET 6
161 #define BACKGROUND_CONTROL_OFFSET 11
163 #define COLUMN_OFFSET 5
164 #define FW_BACK_OFFSET 2
175 extern EFI_DRIVER_BINDING_PROTOCOL gTerminalDriverBinding
;
176 extern EFI_COMPONENT_NAME_PROTOCOL gTerminalComponentName
;
177 extern EFI_COMPONENT_NAME2_PROTOCOL gTerminalComponentName2
;
180 The user Entry Point for module Terminal. The user code starts with this function.
182 @param[in] ImageHandle The firmware allocated handle for the EFI image.
183 @param[in] SystemTable A pointer to the EFI System Table.
185 @retval EFI_SUCCESS The entry point is executed successfully.
186 @retval other Some error occurs when executing this entry point.
192 IN EFI_HANDLE ImageHandle
,
193 IN EFI_SYSTEM_TABLE
*SystemTable
197 Implements EFI_SIMPLE_TEXT_INPUT_PROTOCOL.Reset().
198 This driver only perform dependent serial device reset regardless of
199 the value of ExtendeVerification
201 @param This Indicates the calling context.
202 @param ExtendedVerification Skip by this driver.
204 @retval EFI_SUCCESS The reset operation succeeds.
205 @retval EFI_DEVICE_ERROR The dependent serial port reset fails.
211 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
212 IN BOOLEAN ExtendedVerification
216 Implements EFI_SIMPLE_TEXT_INPUT_PROTOCOL.ReadKeyStroke().
218 @param This Indicates the calling context.
219 @param Key A pointer to a buffer that is filled in with the
220 keystroke information for the key that was sent
223 @retval EFI_SUCCESS The keystroke information is returned successfully.
224 @retval EFI_NOT_READY There is no keystroke data available.
225 @retval EFI_DEVICE_ERROR The dependent serial device encounters error.
230 TerminalConInReadKeyStroke (
231 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
232 OUT EFI_INPUT_KEY
*Key
236 Check if the key already has been registered.
238 @param RegsiteredData A pointer to a buffer that is filled in with the
239 keystroke state data for the key that was
241 @param InputData A pointer to a buffer that is filled in with the
242 keystroke state data for the key that was
245 @retval TRUE Key be pressed matches a registered key.
246 @retval FALSE Match failed.
251 IN EFI_KEY_DATA
*RegsiteredData
,
252 IN EFI_KEY_DATA
*InputData
256 Event notification function for EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx event
257 Signal the event if there is key available
259 @param Event Indicates the event that invoke this function.
260 @param Context Indicates the calling context.
265 TerminalConInWaitForKeyEx (
271 // Simple Text Input Ex protocol prototypes
275 Reset the input device and optionally run diagnostics
277 @param This Protocol instance pointer.
278 @param ExtendedVerification Driver may perform diagnostics on reset.
280 @retval EFI_SUCCESS The device was reset.
281 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
287 TerminalConInResetEx (
288 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
289 IN BOOLEAN ExtendedVerification
293 Reads the next keystroke from the input device. The WaitForKey Event can
294 be used to test for existence of a keystroke via WaitForEvent () call.
296 @param This Protocol instance pointer.
297 @param KeyData A pointer to a buffer that is filled in with the
298 keystroke state data for the key that was
301 @retval EFI_SUCCESS The keystroke information was returned.
302 @retval EFI_NOT_READY There was no keystroke data available.
303 @retval EFI_DEVICE_ERROR The keystroke information was not returned due
305 @retval EFI_INVALID_PARAMETER KeyData is NULL.
310 TerminalConInReadKeyStrokeEx (
311 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
312 OUT EFI_KEY_DATA
*KeyData
316 Set certain state for the input device.
318 @param This Protocol instance pointer.
319 @param KeyToggleState A pointer to the EFI_KEY_TOGGLE_STATE to set the
320 state for the input device.
322 @retval EFI_SUCCESS The device state was set successfully.
323 @retval EFI_DEVICE_ERROR The device is not functioning correctly and
324 could not have the setting adjusted.
325 @retval EFI_UNSUPPORTED The device does not have the ability to set its
327 @retval EFI_INVALID_PARAMETER KeyToggleState is NULL.
332 TerminalConInSetState (
333 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
334 IN EFI_KEY_TOGGLE_STATE
*KeyToggleState
338 Register a notification function for a particular keystroke for the input device.
340 @param This Protocol instance pointer.
341 @param KeyData A pointer to a buffer that is filled in with the
342 keystroke information data for the key that was
343 pressed. If KeyData.Key, KeyData.KeyState.KeyToggleState
344 and KeyData.KeyState.KeyShiftState are 0, then any incomplete
345 keystroke will trigger a notification of the KeyNotificationFunction.
346 @param KeyNotificationFunction Points to the function to be called when the key
347 sequence is typed specified by KeyData. This notification function
348 should be called at <=TPL_CALLBACK.
349 @param NotifyHandle Points to the unique handle assigned to the
350 registered notification.
352 @retval EFI_SUCCESS The notification function was registered
354 @retval EFI_OUT_OF_RESOURCES Unable to allocate resources for necesssary data
356 @retval EFI_INVALID_PARAMETER KeyData or NotifyHandle is NULL.
361 TerminalConInRegisterKeyNotify (
362 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
363 IN EFI_KEY_DATA
*KeyData
,
364 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction
,
365 OUT VOID
**NotifyHandle
369 Remove a registered notification function from a particular keystroke.
371 @param This Protocol instance pointer.
372 @param NotificationHandle The handle of the notification function being
375 @retval EFI_SUCCESS The notification function was unregistered
377 @retval EFI_INVALID_PARAMETER The NotificationHandle is invalid.
378 @retval EFI_NOT_FOUND Can not find the matching entry in database.
383 TerminalConInUnregisterKeyNotify (
384 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
385 IN VOID
*NotificationHandle
389 Event notification function for EFI_SIMPLE_TEXT_INPUT_PROTOCOL.WaitForKey event
390 Signal the event if there is key available
392 @param Event Indicates the event that invoke this function.
393 @param Context Indicates the calling context.
398 TerminalConInWaitForKey (
404 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset().
405 If ExtendeVerification is TRUE, then perform dependent serial device reset,
406 and set display mode to mode 0.
407 If ExtendedVerification is FALSE, only set display mode to mode 0.
409 @param This Indicates the calling context.
410 @param ExtendedVerification Indicates that the driver may perform a more
411 exhaustive verification operation of the device
414 @retval EFI_SUCCESS The reset operation succeeds.
415 @retval EFI_DEVICE_ERROR The terminal is not functioning correctly or the serial port reset fails.
420 TerminalConOutReset (
421 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
422 IN BOOLEAN ExtendedVerification
426 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString().
427 The Unicode string will be converted to terminal expressible data stream
428 and send to terminal via serial port.
430 @param This Indicates the calling context.
431 @param WString The Null-terminated Unicode string to be displayed
432 on the terminal screen.
434 @retval EFI_SUCCESS The string is output successfully.
435 @retval EFI_DEVICE_ERROR The serial port fails to send the string out.
436 @retval EFI_WARN_UNKNOWN_GLYPH Indicates that some of the characters in the Unicode string could not
437 be rendered and are skipped.
438 @retval EFI_UNSUPPORTED If current display mode is out of range.
443 TerminalConOutOutputString (
444 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
449 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.TestString().
450 If one of the characters in the *Wstring is
451 neither valid Unicode drawing characters,
452 not ASCII code, then this function will return
455 @param This Indicates the calling context.
456 @param WString The Null-terminated Unicode string to be tested.
458 @retval EFI_SUCCESS The terminal is capable of rendering the output string.
459 @retval EFI_UNSUPPORTED Some of the characters in the Unicode string cannot be rendered.
464 TerminalConOutTestString (
465 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
470 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.QueryMode().
471 It returns information for an available text mode
472 that the terminal supports.
473 In this driver, we support text mode 80x25 (mode 0),
474 80x50 (mode 1), 100x31 (mode 2).
476 @param This Indicates the calling context.
477 @param ModeNumber The mode number to return information on.
478 @param Columns The returned columns of the requested mode.
479 @param Rows The returned rows of the requested mode.
481 @retval EFI_SUCCESS The requested mode information is returned.
482 @retval EFI_UNSUPPORTED The mode number is not valid.
483 @retval EFI_DEVICE_ERROR
488 TerminalConOutQueryMode (
489 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
496 Implements EFI_SIMPLE_TEXT_OUT.SetMode().
497 Set the terminal to a specified display mode.
498 In this driver, we only support mode 0.
500 @param This Indicates the calling context.
501 @param ModeNumber The text mode to set.
503 @retval EFI_SUCCESS The requested text mode is set.
504 @retval EFI_DEVICE_ERROR The requested text mode cannot be set
505 because of serial device error.
506 @retval EFI_UNSUPPORTED The text mode number is not valid.
511 TerminalConOutSetMode (
512 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
517 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetAttribute().
519 @param This Indicates the calling context.
520 @param Attribute The attribute to set. Only bit0..6 are valid, all other bits
521 are undefined and must be zero.
523 @retval EFI_SUCCESS The requested attribute is set.
524 @retval EFI_DEVICE_ERROR The requested attribute cannot be set due to serial port error.
525 @retval EFI_UNSUPPORTED The attribute requested is not defined by EFI spec.
530 TerminalConOutSetAttribute (
531 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
536 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.ClearScreen().
537 It clears the ANSI terminal's display to the
538 currently selected background color.
540 @param This Indicates the calling context.
542 @retval EFI_SUCCESS The operation completed successfully.
543 @retval EFI_DEVICE_ERROR The terminal screen cannot be cleared due to serial port error.
544 @retval EFI_UNSUPPORTED The terminal is not in a valid display mode.
549 TerminalConOutClearScreen (
550 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
554 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetCursorPosition().
556 @param This Indicates the calling context.
557 @param Column The row to set cursor to.
558 @param Row The column to set cursor to.
560 @retval EFI_SUCCESS The operation completed successfully.
561 @retval EFI_DEVICE_ERROR The request fails due to serial port error.
562 @retval EFI_UNSUPPORTED The terminal is not in a valid text mode, or the cursor position
563 is invalid for current mode.
568 TerminalConOutSetCursorPosition (
569 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
575 Implements SIMPLE_TEXT_OUTPUT.EnableCursor().
576 In this driver, the cursor cannot be hidden.
578 @param This Indicates the calling context.
579 @param Visible If TRUE, the cursor is set to be visible,
580 If FALSE, the cursor is set to be invisible.
582 @retval EFI_SUCCESS The request is valid.
583 @retval EFI_UNSUPPORTED The terminal does not support cursor hidden.
588 TerminalConOutEnableCursor (
589 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
594 Test to see if this driver supports Controller.
596 @param This Protocol instance pointer.
597 @param ControllerHandle Handle of device to test
598 @param RemainingDevicePath Optional parameter use to pick a specific child
601 @retval EFI_SUCCESS This driver supports this device.
602 @retval EFI_ALREADY_STARTED This driver is already running on this device.
603 @retval other This driver does not support this device.
608 TerminalDriverBindingSupported (
609 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
610 IN EFI_HANDLE ControllerHandle
,
611 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
615 Start this driver on Controller by opening a Serial IO protocol,
616 reading Device Path, and creating a child handle with a Simple Text In,
617 Simple Text In Ex and Simple Text Out protocol, and device path protocol.
618 And store Console Device Environment Variables.
620 @param This Protocol instance pointer.
621 @param Controller Handle of device to bind driver to
622 @param RemainingDevicePath Optional parameter use to pick a specific child
625 @retval EFI_SUCCESS This driver is added to Controller.
626 @retval EFI_ALREADY_STARTED This driver is already running on Controller.
627 @retval other This driver does not support this device.
632 TerminalDriverBindingStart (
633 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
634 IN EFI_HANDLE Controller
,
635 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
639 Stop this driver on Controller by closing Simple Text In, Simple Text
640 In Ex, Simple Text Out protocol, and removing parent device path from
641 Console Device Environment Variables.
643 @param This Protocol instance pointer.
644 @param Controller Handle of device to stop driver on
645 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
646 children is zero stop the entire bus driver.
647 @param ChildHandleBuffer List of Child Handles to Stop.
649 @retval EFI_SUCCESS This driver is removed Controller.
650 @retval other This driver could not be removed from this device.
655 TerminalDriverBindingStop (
656 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
657 IN EFI_HANDLE Controller
,
658 IN UINTN NumberOfChildren
,
659 IN EFI_HANDLE
*ChildHandleBuffer
663 Free notify functions list.
665 @param ListHead The list head
667 @retval EFI_SUCCESS Free the notify list successfully.
668 @retval EFI_INVALID_PARAMETER ListHead is NULL.
672 TerminalFreeNotifyList (
673 IN OUT LIST_ENTRY
*ListHead
677 Retrieves a Unicode string that is the user readable name of the driver.
679 This function retrieves the user readable name of a driver in the form of a
680 Unicode string. If the driver specified by This has a user readable name in
681 the language specified by Language, then a pointer to the driver name is
682 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
683 by This does not support the language specified by Language,
684 then EFI_UNSUPPORTED is returned.
686 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
687 EFI_COMPONENT_NAME_PROTOCOL instance.
689 @param Language[in] A pointer to a Null-terminated ASCII string
690 array indicating the language. This is the
691 language of the driver name that the caller is
692 requesting, and it must match one of the
693 languages specified in SupportedLanguages. The
694 number of languages supported by a driver is up
695 to the driver writer. Language is specified
696 in RFC 4646 or ISO 639-2 language code format.
698 @param DriverName[out] A pointer to the Unicode string to return.
699 This Unicode string is the name of the
700 driver specified by This in the language
701 specified by Language.
703 @retval EFI_SUCCESS The Unicode string for the Driver specified by
704 This and the language specified by Language was
705 returned in DriverName.
707 @retval EFI_INVALID_PARAMETER Language is NULL.
709 @retval EFI_INVALID_PARAMETER DriverName is NULL.
711 @retval EFI_UNSUPPORTED The driver specified by This does not support
712 the language specified by Language.
717 TerminalComponentNameGetDriverName (
718 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
720 OUT CHAR16
**DriverName
724 Retrieves a Unicode string that is the user readable name of the controller
725 that is being managed by a driver.
727 This function retrieves the user readable name of the controller specified by
728 ControllerHandle and ChildHandle in the form of a Unicode string. If the
729 driver specified by This has a user readable name in the language specified by
730 Language, then a pointer to the controller name is returned in ControllerName,
731 and EFI_SUCCESS is returned. If the driver specified by This is not currently
732 managing the controller specified by ControllerHandle and ChildHandle,
733 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
734 support the language specified by Language, then EFI_UNSUPPORTED is returned.
736 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
737 EFI_COMPONENT_NAME_PROTOCOL instance.
739 @param ControllerHandle[in] The handle of a controller that the driver
740 specified by This is managing. This handle
741 specifies the controller whose name is to be
744 @param ChildHandle[in] The handle of the child controller to retrieve
745 the name of. This is an optional parameter that
746 may be NULL. It will be NULL for device
747 drivers. It will also be NULL for a bus drivers
748 that wish to retrieve the name of the bus
749 controller. It will not be NULL for a bus
750 driver that wishes to retrieve the name of a
753 @param Language[in] A pointer to a Null-terminated ASCII string
754 array indicating the language. This is the
755 language of the driver name that the caller is
756 requesting, and it must match one of the
757 languages specified in SupportedLanguages. The
758 number of languages supported by a driver is up
759 to the driver writer. Language is specified in
760 RFC 4646 or ISO 639-2 language code format.
762 @param ControllerName[out] A pointer to the Unicode string to return.
763 This Unicode string is the name of the
764 controller specified by ControllerHandle and
765 ChildHandle in the language specified by
766 Language from the point of view of the driver
769 @retval EFI_SUCCESS The Unicode string for the user readable name in
770 the language specified by Language for the
771 driver specified by This was returned in
774 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
776 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
779 @retval EFI_INVALID_PARAMETER Language is NULL.
781 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
783 @retval EFI_UNSUPPORTED The driver specified by This is not currently
784 managing the controller specified by
785 ControllerHandle and ChildHandle.
787 @retval EFI_UNSUPPORTED The driver specified by This does not support
788 the language specified by Language.
793 TerminalComponentNameGetControllerName (
794 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
795 IN EFI_HANDLE ControllerHandle
,
796 IN EFI_HANDLE ChildHandle OPTIONAL
,
798 OUT CHAR16
**ControllerName
802 // internal functions
806 Check for a pending key in the Efi Key FIFO or Serial device buffer.
808 @param This Indicates the calling context.
810 @retval EFI_SUCCESS There is key pending.
811 @retval EFI_NOT_READY There is no key pending.
812 @retval EFI_DEVICE_ERROR If Serial IO is not attached to serial device.
816 TerminalConInCheckForKey (
817 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
821 Update terminal device path in Console Device Environment Variables.
823 @param VariableName The Console Device Environment Variable.
824 @param ParentDevicePath The terminal device path to be updated.
830 TerminalUpdateConsoleDevVariable (
831 IN CHAR16
*VariableName
,
832 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
836 Remove console device variable.
838 @param VariableName A pointer to the variable name.
839 @param ParentDevicePath A pointer to the parent device path.
843 TerminalRemoveConsoleDevVariable (
844 IN CHAR16
*VariableName
,
845 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
849 Build termial device path according to terminal type.
851 @param TerminalType The terminal type is PC ANSI, VT100, VT100+, VT-UTF8, TTY-Term,
852 Linux, XtermR6, VT400 and SCO.
853 @param ParentDevicePath Parent device path.
854 @param TerminalDevicePath Returned terminal device path, if building successfully.
856 @retval EFI_UNSUPPORTED Terminal does not belong to the supported type.
857 @retval EFI_OUT_OF_RESOURCES Generate terminal device path failed.
858 @retval EFI_SUCCESS Build terminal device path successfully.
862 SetTerminalDevicePath (
863 IN TERMINAL_TYPE TerminalType
,
864 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
865 OUT EFI_DEVICE_PATH_PROTOCOL
**TerminalDevicePath
869 Get one key out of serial buffer.
871 @param SerialIo Serial I/O protocl attached to the serial device.
872 @param Input The fetched key.
874 @retval EFI_NOT_READY If serial buffer is empty.
875 @retval EFI_DEVICE_ERROR If reading serial buffer encounter error.
876 @retval EFI_SUCCESS If reading serial buffer successfully, put
877 the fetched key to the parameter output.
881 GetOneKeyFromSerial (
882 EFI_SERIAL_IO_PROTOCOL
*SerialIo
,
887 Insert one byte raw data into the Raw Data FIFO.
889 @param TerminalDevice Terminal driver private structure.
890 @param Input The key will be input.
892 @retval TRUE If insert successfully.
893 @retval FALSE If Raw Data buffer is full before key insertion,
898 RawFiFoInsertOneKey (
899 TERMINAL_DEV
*TerminalDevice
,
904 Remove one pre-fetched key out of the Raw Data FIFO.
906 @param TerminalDevice Terminal driver private structure.
907 @param Output The key will be removed.
909 @retval TRUE If insert successfully.
910 @retval FALSE If Raw Data FIFO buffer is empty before remove operation.
914 RawFiFoRemoveOneKey (
915 TERMINAL_DEV
*TerminalDevice
,
920 Clarify whether Raw Data FIFO buffer is empty.
922 @param TerminalDevice Terminal driver private structure
924 @retval TRUE If Raw Data FIFO buffer is empty.
925 @retval FALSE If Raw Data FIFO buffer is not empty.
930 TERMINAL_DEV
*TerminalDevice
934 Clarify whether Raw Data FIFO buffer is full.
936 @param TerminalDevice Terminal driver private structure
938 @retval TRUE If Raw Data FIFO buffer is full.
939 @retval FALSE If Raw Data FIFO buffer is not full.
944 TERMINAL_DEV
*TerminalDevice
948 Insert one pre-fetched key into the FIFO buffer.
950 @param EfiKeyFiFo Pointer to instance of EFI_KEY_FIFO.
951 @param Input The key will be input.
953 @retval TRUE If insert successfully.
954 @retval FALSE If FIFO buffer is full before key insertion,
959 EfiKeyFiFoForNotifyInsertOneKey (
960 EFI_KEY_FIFO
*EfiKeyFiFo
,
965 Remove one pre-fetched key out of the FIFO buffer.
967 @param EfiKeyFiFo Pointer to instance of EFI_KEY_FIFO.
968 @param Output The key will be removed.
970 @retval TRUE If insert successfully.
971 @retval FALSE If FIFO buffer is empty before remove operation.
975 EfiKeyFiFoForNotifyRemoveOneKey (
976 EFI_KEY_FIFO
*EfiKeyFiFo
,
977 EFI_INPUT_KEY
*Output
981 Clarify whether FIFO buffer is empty.
983 @param EfiKeyFiFo Pointer to instance of EFI_KEY_FIFO.
985 @retval TRUE If FIFO buffer is empty.
986 @retval FALSE If FIFO buffer is not empty.
990 IsEfiKeyFiFoForNotifyEmpty (
991 IN EFI_KEY_FIFO
*EfiKeyFiFo
995 Clarify whether FIFO buffer is full.
997 @param EfiKeyFiFo Pointer to instance of EFI_KEY_FIFO.
999 @retval TRUE If FIFO buffer is full.
1000 @retval FALSE If FIFO buffer is not full.
1004 IsEfiKeyFiFoForNotifyFull (
1005 EFI_KEY_FIFO
*EfiKeyFiFo
1009 Insert one pre-fetched key into the FIFO buffer.
1011 @param TerminalDevice Terminal driver private structure.
1012 @param Key The key will be input.
1014 @retval TRUE If insert successfully.
1015 @retval FALSE If FIFO buffer is full before key insertion,
1016 and the key is lost.
1020 EfiKeyFiFoInsertOneKey (
1021 TERMINAL_DEV
*TerminalDevice
,
1026 Remove one pre-fetched key out of the FIFO buffer.
1028 @param TerminalDevice Terminal driver private structure.
1029 @param Output The key will be removed.
1031 @retval TRUE If insert successfully.
1032 @retval FALSE If FIFO buffer is empty before remove operation.
1036 EfiKeyFiFoRemoveOneKey (
1037 TERMINAL_DEV
*TerminalDevice
,
1038 EFI_INPUT_KEY
*Output
1042 Clarify whether FIFO buffer is empty.
1044 @param TerminalDevice Terminal driver private structure
1046 @retval TRUE If FIFO buffer is empty.
1047 @retval FALSE If FIFO buffer is not empty.
1052 TERMINAL_DEV
*TerminalDevice
1056 Clarify whether FIFO buffer is full.
1058 @param TerminalDevice Terminal driver private structure
1060 @retval TRUE If FIFO buffer is full.
1061 @retval FALSE If FIFO buffer is not full.
1066 TERMINAL_DEV
*TerminalDevice
1070 Insert one pre-fetched key into the Unicode FIFO buffer.
1072 @param TerminalDevice Terminal driver private structure.
1073 @param Input The key will be input.
1075 @retval TRUE If insert successfully.
1076 @retval FALSE If Unicode FIFO buffer is full before key insertion,
1077 and the key is lost.
1081 UnicodeFiFoInsertOneKey (
1082 TERMINAL_DEV
*TerminalDevice
,
1087 Remove one pre-fetched key out of the Unicode FIFO buffer.
1088 The caller should guarantee that Unicode FIFO buffer is not empty
1089 by IsUnicodeFiFoEmpty ().
1091 @param TerminalDevice Terminal driver private structure.
1092 @param Output The key will be removed.
1096 UnicodeFiFoRemoveOneKey (
1097 TERMINAL_DEV
*TerminalDevice
,
1102 Clarify whether Unicode FIFO buffer is empty.
1104 @param TerminalDevice Terminal driver private structure
1106 @retval TRUE If Unicode FIFO buffer is empty.
1107 @retval FALSE If Unicode FIFO buffer is not empty.
1111 IsUnicodeFiFoEmpty (
1112 TERMINAL_DEV
*TerminalDevice
1116 Clarify whether Unicode FIFO buffer is full.
1118 @param TerminalDevice Terminal driver private structure
1120 @retval TRUE If Unicode FIFO buffer is full.
1121 @retval FALSE If Unicode FIFO buffer is not full.
1126 TERMINAL_DEV
*TerminalDevice
1130 Translate raw data into Unicode (according to different encode), and
1131 translate Unicode into key information. (according to different standard).
1133 @param TerminalDevice Terminal driver private structure.
1137 TranslateRawDataToEfiKey (
1138 IN TERMINAL_DEV
*TerminalDevice
1142 // internal functions for PC ANSI
1146 Translate all raw data in the Raw FIFI into unicode, and insert
1147 them into Unicode FIFO.
1149 @param TerminalDevice The terminal device.
1153 AnsiRawDataToUnicode (
1154 IN TERMINAL_DEV
*TerminalDevice
1158 Converts a stream of Unicode characters from a terminal input device into EFI Keys that
1159 can be read through the Simple Input Protocol.
1161 The table below shows the keyboard input mappings that this function supports.
1162 If the ESC sequence listed in one of the columns is presented, then it is translated
1163 into the coorespoding EFI Scan Code. If a matching sequence is not found, then the raw
1164 key strokes are converted into EFI Keys.
1166 2 seconds are allowed for an ESC sequence to be completed. If the ESC sequence is not
1167 completed in 2 seconds, then the raw key strokes of the partial ESC sequence are
1168 converted into EFI Keys.
1169 There is one special input sequence that will force the system to reset.
1170 This is ESC R ESC r ESC R.
1172 Symbols used in table below
1173 ===========================
1178 +=========+======+===========+==========+==========+
1179 | | EFI | UEFI 2.0 | | |
1180 | | Scan | | VT100+ | |
1181 | KEY | Code | PC ANSI | VTUTF8 | VT100 |
1182 +=========+======+===========+==========+==========+
1183 | NULL | 0x00 | | | |
1184 | UP | 0x01 | ESC [ A | ESC [ A | ESC [ A |
1185 | DOWN | 0x02 | ESC [ B | ESC [ B | ESC [ B |
1186 | RIGHT | 0x03 | ESC [ C | ESC [ C | ESC [ C |
1187 | LEFT | 0x04 | ESC [ D | ESC [ D | ESC [ D |
1188 | HOME | 0x05 | ESC [ H | ESC h | ESC [ H |
1189 | END | 0x06 | ESC [ F | ESC k | ESC [ K |
1190 | INSERT | 0x07 | ESC [ @ | ESC + | ESC [ @ |
1191 | | | ESC [ L | | ESC [ L |
1192 | DELETE | 0x08 | ESC [ X | ESC - | ESC [ P |
1193 | PG UP | 0x09 | ESC [ I | ESC ? | ESC [ V |
1195 | PG DOWN | 0x0A | ESC [ G | ESC / | ESC [ U |
1197 | F1 | 0x0B | ESC [ M | ESC 1 | ESC O P |
1198 | F2 | 0x0C | ESC [ N | ESC 2 | ESC O Q |
1199 | F3 | 0x0D | ESC [ O | ESC 3 | ESC O w |
1200 | F4 | 0x0E | ESC [ P | ESC 4 | ESC O x |
1201 | F5 | 0x0F | ESC [ Q | ESC 5 | ESC O t |
1202 | F6 | 0x10 | ESC [ R | ESC 6 | ESC O u |
1203 | F7 | 0x11 | ESC [ S | ESC 7 | ESC O q |
1204 | F8 | 0x12 | ESC [ T | ESC 8 | ESC O r |
1205 | F9 | 0x13 | ESC [ U | ESC 9 | ESC O p |
1206 | F10 | 0x14 | ESC [ V | ESC 0 | ESC O M |
1207 | Escape | 0x17 | ESC | ESC | ESC |
1208 | F11 | 0x15 | | ESC ! | |
1209 | F12 | 0x16 | | ESC @ | |
1210 +=========+======+===========+==========+==========+
1212 Putty function key map:
1213 +=========+======+===========+=============+=============+=============+=========+
1215 | | Scan | | | Normal | | |
1216 | KEY | Code | VT100+ | Xterm R6 | VT400 | Linux | SCO |
1217 +=========+======+===========+=============+=============+=============+=========+
1218 | F1 | 0x0B | ESC O P | ESC O P | ESC [ 1 1 ~ | ESC [ [ A | ESC [ M |
1219 | F2 | 0x0C | ESC O Q | ESC O Q | ESC [ 1 2 ~ | ESC [ [ B | ESC [ N |
1220 | F3 | 0x0D | ESC O R | ESC O R | ESC [ 1 3 ~ | ESC [ [ C | ESC [ O |
1221 | F4 | 0x0E | ESC O S | ESC O S | ESC [ 1 4 ~ | ESC [ [ D | ESC [ P |
1222 | F5 | 0x0F | ESC O T | ESC [ 1 5 ~ | ESC [ 1 5 ~ | ESC [ [ E | ESC [ Q |
1223 | F6 | 0x10 | ESC O U | ESC [ 1 7 ~ | ESC [ 1 7 ~ | ESC [ 1 7 ~ | ESC [ R |
1224 | F7 | 0x11 | ESC O V | ESC [ 1 8 ~ | ESC [ 1 8 ~ | ESC [ 1 8 ~ | ESC [ S |
1225 | F8 | 0x12 | ESC O W | ESC [ 1 9 ~ | ESC [ 1 9 ~ | ESC [ 1 9 ~ | ESC [ T |
1226 | F9 | 0x13 | ESC O X | ESC [ 2 0 ~ | ESC [ 2 0 ~ | ESC [ 2 0 ~ | ESC [ U |
1227 | F10 | 0x14 | ESC O Y | ESC [ 2 1 ~ | ESC [ 2 1 ~ | ESC [ 2 1 ~ | ESC [ V |
1228 | Escape | 0x17 | ESC | ESC | ESC | ESC | ESC |
1229 | F11 | 0x15 | ESC O Z | ESC [ 2 3 ~ | ESC [ 2 3 ~ | ESC [ 2 3 ~ | ESC [ W |
1230 | F12 | 0x16 | ESC O [ | ESC [ 2 4 ~ | ESC [ 2 4 ~ | ESC [ 2 4 ~ | ESC [ X |
1231 +=========+======+===========+=============+=============+=============+=========+
1236 ESC R ESC r ESC R = Reset System
1239 @param TerminalDevice The terminal device to use to translate raw input into EFI Keys
1244 IN TERMINAL_DEV
*TerminalDevice
1248 Check if input string is valid Ascii string, valid EFI control characters
1249 or valid text graphics.
1251 @param TerminalDevice The terminal device.
1252 @param WString The input string.
1254 @retval EFI_UNSUPPORTED If not all input characters are valid.
1255 @retval EFI_SUCCESS If all input characters are valid.
1260 IN TERMINAL_DEV
*TerminalDevice
,
1265 // internal functions for VTUTF8
1269 Translate all VT-UTF8 characters in the Raw FIFI into unicode characters,
1270 and insert them into Unicode FIFO.
1272 @param VtUtf8Device The terminal device.
1276 VTUTF8RawDataToUnicode (
1277 IN TERMINAL_DEV
*VtUtf8Device
1281 Check if input string is valid VT-UTF8 string.
1283 @param TerminalDevice The terminal device.
1284 @param WString The input string.
1286 @retval EFI_SUCCESS If all input characters are valid.
1291 IN TERMINAL_DEV
*TerminalDevice
,
1296 Translate one Unicode character into VT-UTF8 characters.
1299 Bits per Character | Unicode Character Range | Unicode Binary Encoding | UTF8 Binary Encoding
1300 0-7 | 0x0000 - 0x007F | 00000000 0xxxxxxx | 0xxxxxxx
1301 8-11 | 0x0080 - 0x07FF | 00000xxx xxxxxxxx | 110xxxxx 10xxxxxx
1302 12-16 | 0x0800 - 0xFFFF | xxxxxxxx xxxxxxxx | 1110xxxx 10xxxxxx 10xxxxxx
1305 @param Unicode Unicode character need translating.
1306 @param Utf8Char Return VT-UTF8 character set.
1307 @param ValidBytes The count of valid VT-UTF8 characters. If
1308 ValidBytes is zero, no valid VT-UTF8 returned.
1314 OUT UTF8_CHAR
*Utf8Char
,
1315 OUT UINT8
*ValidBytes
1319 Get one valid VT-UTF8 characters set from Raw Data FIFO.
1321 @param Utf8Device The terminal device.
1322 @param Utf8Char Returned valid VT-UTF8 characters set.
1323 @param ValidBytes The count of returned VT-VTF8 characters.
1324 If ValidBytes is zero, no valid VT-UTF8 returned.
1328 GetOneValidUtf8Char (
1329 IN TERMINAL_DEV
*Utf8Device
,
1330 OUT UTF8_CHAR
*Utf8Char
,
1331 OUT UINT8
*ValidBytes
1335 Translate VT-UTF8 characters into one Unicode character.
1338 Bits per Character | Unicode Character Range | Unicode Binary Encoding | UTF8 Binary Encoding
1339 0-7 | 0x0000 - 0x007F | 00000000 0xxxxxxx | 0xxxxxxx
1340 8-11 | 0x0080 - 0x07FF | 00000xxx xxxxxxxx | 110xxxxx 10xxxxxx
1341 12-16 | 0x0800 - 0xFFFF | xxxxxxxx xxxxxxxx | 1110xxxx 10xxxxxx 10xxxxxx
1344 @param Utf8Char VT-UTF8 character set needs translating.
1345 @param ValidBytes The count of valid VT-UTF8 characters.
1346 @param UnicodeChar Returned unicode character.
1351 IN UTF8_CHAR Utf8Char
,
1352 IN UINT8 ValidBytes
,
1353 OUT CHAR16
*UnicodeChar
1357 // functions for boxdraw unicode
1361 Detects if a Unicode char is for Box Drawing text graphics.
1363 @param Graphic Unicode char to test.
1364 @param PcAnsi Optional pointer to return PCANSI equivalent of
1366 @param Ascii Optional pointer to return ASCII equivalent of
1369 @retval TRUE If Graphic is a supported Unicode Box Drawing character.
1373 TerminalIsValidTextGraphics (
1375 OUT CHAR8
*PcAnsi OPTIONAL
,
1376 OUT CHAR8
*Ascii OPTIONAL
1380 Detects if a valid ASCII char.
1382 @param Ascii An ASCII character.
1384 @retval TRUE If it is a valid ASCII character.
1385 @retval FALSE If it is not a valid ASCII character.
1389 TerminalIsValidAscii (
1394 Detects if a valid EFI control character.
1396 @param CharC An input EFI Control character.
1398 @retval TRUE If it is a valid EFI control character.
1399 @retval FALSE If it is not a valid EFI control character.
1403 TerminalIsValidEfiCntlChar (
1408 Check if the device supports hot-plug through its device path.
1410 This function could be updated to check more types of Hot Plug devices.
1411 Currently, it checks USB and PCCard device.
1413 @param DevicePath Pointer to device's device path.
1415 @retval TRUE The devcie is a hot-plug device
1416 @retval FALSE The devcie is not a hot-plug device.
1421 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1425 Timer handler to poll the key from serial.
1427 @param Event Indicates the event that invoke this function.
1428 @param Context Indicates the calling context.
1432 TerminalConInTimerHandler (
1440 @param Event Indicates the event that invoke this function.
1441 @param Context Indicates the calling context.
1445 KeyNotifyProcessHandler (