2 Header file for Terminal driver.
4 Copyright (c) 2006 - 2018, 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
16 #include <Guid/GlobalVariable.h>
17 #include <Guid/PcAnsi.h>
18 #include <Guid/TtyTerm.h>
19 #include <Guid/StatusCodeDataTypeVariable.h>
21 #include <Protocol/SimpleTextOut.h>
22 #include <Protocol/SerialIo.h>
23 #include <Protocol/DevicePath.h>
24 #include <Protocol/SimpleTextIn.h>
25 #include <Protocol/SimpleTextInEx.h>
27 #include <Library/DebugLib.h>
28 #include <Library/UefiDriverEntryPoint.h>
29 #include <Library/UefiLib.h>
30 #include <Library/ReportStatusCodeLib.h>
31 #include <Library/BaseMemoryLib.h>
32 #include <Library/MemoryAllocationLib.h>
33 #include <Library/UefiBootServicesTableLib.h>
34 #include <Library/UefiRuntimeServicesTableLib.h>
35 #include <Library/DevicePathLib.h>
36 #include <Library/PcdLib.h>
37 #include <Library/BaseLib.h>
40 #define RAW_FIFO_MAX_NUMBER 256
41 #define FIFO_MAX_NUMBER 128
46 UINT8 Data
[RAW_FIFO_MAX_NUMBER
+ 1];
52 UINT16 Data
[FIFO_MAX_NUMBER
+ 1];
58 EFI_INPUT_KEY Data
[FIFO_MAX_NUMBER
+ 1];
64 } TERMINAL_CONSOLE_MODE_DATA
;
66 #define KEYBOARD_TIMER_INTERVAL 200000 // 0.02s
68 #define TERMINAL_DEV_SIGNATURE SIGNATURE_32 ('t', 'm', 'n', 'l')
70 #define TERMINAL_CONSOLE_IN_EX_NOTIFY_SIGNATURE SIGNATURE_32 ('t', 'm', 'e', 'n')
72 typedef struct _TERMINAL_CONSOLE_IN_EX_NOTIFY
{
75 EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn
;
76 LIST_ENTRY NotifyEntry
;
77 } TERMINAL_CONSOLE_IN_EX_NOTIFY
;
82 TerminalTypeVt100Plus
,
90 TERMINAL_TYPE TerminalType
;
91 EFI_SERIAL_IO_PROTOCOL
*SerialIo
;
92 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
93 EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleInput
;
94 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL SimpleTextOutput
;
95 EFI_SIMPLE_TEXT_OUTPUT_MODE SimpleTextOutputMode
;
96 TERMINAL_CONSOLE_MODE_DATA
*TerminalConsoleModeData
;
97 UINTN SerialInTimeOut
;
98 RAW_DATA_FIFO
*RawFiFo
;
99 UNICODE_FIFO
*UnicodeFiFo
;
100 EFI_KEY_FIFO
*EfiKeyFiFo
;
101 EFI_KEY_FIFO
*EfiKeyFiFoForNotify
;
102 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
103 EFI_EVENT TimerEvent
;
104 EFI_EVENT TwoSecondTimeOut
;
107 UINT16 TtyEscapeStr
[3];
111 // Esc could not be output to the screen by user,
112 // but the terminal driver need to output it to
113 // the terminal emulation software to send control sequence.
114 // This boolean is used by the terminal driver only
115 // to indicate whether the Esc could be sent or not.
117 BOOLEAN OutputEscChar
;
118 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL SimpleInputEx
;
119 LIST_ENTRY NotifyList
;
120 EFI_EVENT KeyNotifyProcessEvent
;
123 #define INPUT_STATE_DEFAULT 0x00
124 #define INPUT_STATE_ESC 0x01
125 #define INPUT_STATE_CSI 0x02
126 #define INPUT_STATE_LEFTOPENBRACKET 0x04
127 #define INPUT_STATE_O 0x08
128 #define INPUT_STATE_2 0x10
129 #define INPUT_STATE_LEFTOPENBRACKET_2 0x20
131 #define RESET_STATE_DEFAULT 0x00
132 #define RESET_STATE_ESC_R 0x01
133 #define RESET_STATE_ESC_R_ESC_R 0x02
135 #define TERMINAL_CON_IN_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleInput, TERMINAL_DEV_SIGNATURE)
136 #define TERMINAL_CON_OUT_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleTextOutput, TERMINAL_DEV_SIGNATURE)
137 #define TERMINAL_CON_IN_EX_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleInputEx, TERMINAL_DEV_SIGNATURE)
145 #define LEFTOPENBRACKET 0x5b // '['
155 #define BRIGHT_CONTROL_OFFSET 2
156 #define FOREGROUND_CONTROL_OFFSET 6
157 #define BACKGROUND_CONTROL_OFFSET 11
159 #define COLUMN_OFFSET 5
160 #define FW_BACK_OFFSET 2
171 extern EFI_DRIVER_BINDING_PROTOCOL gTerminalDriverBinding
;
172 extern EFI_COMPONENT_NAME_PROTOCOL gTerminalComponentName
;
173 extern EFI_COMPONENT_NAME2_PROTOCOL gTerminalComponentName2
;
176 The user Entry Point for module Terminal. The user code starts with this function.
178 @param[in] ImageHandle The firmware allocated handle for the EFI image.
179 @param[in] SystemTable A pointer to the EFI System Table.
181 @retval EFI_SUCCESS The entry point is executed successfully.
182 @retval other Some error occurs when executing this entry point.
188 IN EFI_HANDLE ImageHandle
,
189 IN EFI_SYSTEM_TABLE
*SystemTable
193 Implements EFI_SIMPLE_TEXT_INPUT_PROTOCOL.Reset().
194 This driver only perform dependent serial device reset regardless of
195 the value of ExtendeVerification
197 @param This Indicates the calling context.
198 @param ExtendedVerification Skip by this driver.
200 @retval EFI_SUCCESS The reset operation succeeds.
201 @retval EFI_DEVICE_ERROR The dependent serial port reset fails.
207 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
208 IN BOOLEAN ExtendedVerification
213 Implements EFI_SIMPLE_TEXT_INPUT_PROTOCOL.ReadKeyStroke().
215 @param This Indicates the calling context.
216 @param Key A pointer to a buffer that is filled in with the
217 keystroke information for the key that was sent
220 @retval EFI_SUCCESS The keystroke information is returned successfully.
221 @retval EFI_NOT_READY There is no keystroke data available.
222 @retval EFI_DEVICE_ERROR The dependent serial device encounters error.
227 TerminalConInReadKeyStroke (
228 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
229 OUT EFI_INPUT_KEY
*Key
233 Check if the key already has been registered.
235 @param RegsiteredData A pointer to a buffer that is filled in with the
236 keystroke state data for the key that was
238 @param InputData A pointer to a buffer that is filled in with the
239 keystroke state data for the key that was
242 @retval TRUE Key be pressed matches a registered key.
243 @retval FALSE Match failed.
248 IN EFI_KEY_DATA
*RegsiteredData
,
249 IN EFI_KEY_DATA
*InputData
253 Event notification function for EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx event
254 Signal the event if there is key available
256 @param Event Indicates the event that invoke this function.
257 @param Context Indicates the calling context.
262 TerminalConInWaitForKeyEx (
268 // Simple Text Input Ex protocol prototypes
272 Reset the input device and optionally run diagnostics
274 @param This Protocol instance pointer.
275 @param ExtendedVerification Driver may perform diagnostics on reset.
277 @retval EFI_SUCCESS The device was reset.
278 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
284 TerminalConInResetEx (
285 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
286 IN BOOLEAN ExtendedVerification
290 Reads the next keystroke from the input device. The WaitForKey Event can
291 be used to test for existence of a keystroke via WaitForEvent () call.
293 @param This Protocol instance pointer.
294 @param KeyData A pointer to a buffer that is filled in with the
295 keystroke state data for the key that was
298 @retval EFI_SUCCESS The keystroke information was returned.
299 @retval EFI_NOT_READY There was no keystroke data available.
300 @retval EFI_DEVICE_ERROR The keystroke information was not returned due
302 @retval EFI_INVALID_PARAMETER KeyData is NULL.
307 TerminalConInReadKeyStrokeEx (
308 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
309 OUT EFI_KEY_DATA
*KeyData
313 Set certain state for the input device.
315 @param This Protocol instance pointer.
316 @param KeyToggleState A pointer to the EFI_KEY_TOGGLE_STATE to set the
317 state for the input device.
319 @retval EFI_SUCCESS The device state was set successfully.
320 @retval EFI_DEVICE_ERROR The device is not functioning correctly and
321 could not have the setting adjusted.
322 @retval EFI_UNSUPPORTED The device does not have the ability to set its
324 @retval EFI_INVALID_PARAMETER KeyToggleState is NULL.
329 TerminalConInSetState (
330 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
331 IN EFI_KEY_TOGGLE_STATE
*KeyToggleState
335 Register a notification function for a particular keystroke for the input device.
337 @param This Protocol instance pointer.
338 @param KeyData A pointer to a buffer that is filled in with the
339 keystroke information data for the key that was
340 pressed. If KeyData.Key, KeyData.KeyState.KeyToggleState
341 and KeyData.KeyState.KeyShiftState are 0, then any incomplete
342 keystroke will trigger a notification of the KeyNotificationFunction.
343 @param KeyNotificationFunction Points to the function to be called when the key
344 sequence is typed specified by KeyData. This notification function
345 should be called at <=TPL_CALLBACK.
346 @param NotifyHandle Points to the unique handle assigned to the
347 registered notification.
349 @retval EFI_SUCCESS The notification function was registered
351 @retval EFI_OUT_OF_RESOURCES Unable to allocate resources for necesssary data
353 @retval EFI_INVALID_PARAMETER KeyData or NotifyHandle is NULL.
358 TerminalConInRegisterKeyNotify (
359 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
360 IN EFI_KEY_DATA
*KeyData
,
361 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction
,
362 OUT VOID
**NotifyHandle
366 Remove a registered notification function from a particular keystroke.
368 @param This Protocol instance pointer.
369 @param NotificationHandle The handle of the notification function being
372 @retval EFI_SUCCESS The notification function was unregistered
374 @retval EFI_INVALID_PARAMETER The NotificationHandle is invalid.
375 @retval EFI_NOT_FOUND Can not find the matching entry in database.
380 TerminalConInUnregisterKeyNotify (
381 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
382 IN VOID
*NotificationHandle
386 Event notification function for EFI_SIMPLE_TEXT_INPUT_PROTOCOL.WaitForKey event
387 Signal the event if there is key available
389 @param Event Indicates the event that invoke this function.
390 @param Context Indicates the calling context.
395 TerminalConInWaitForKey (
401 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset().
402 If ExtendeVerification is TRUE, then perform dependent serial device reset,
403 and set display mode to mode 0.
404 If ExtendedVerification is FALSE, only set display mode to mode 0.
406 @param This Indicates the calling context.
407 @param ExtendedVerification Indicates that the driver may perform a more
408 exhaustive verification operation of the device
411 @retval EFI_SUCCESS The reset operation succeeds.
412 @retval EFI_DEVICE_ERROR The terminal is not functioning correctly or the serial port reset fails.
417 TerminalConOutReset (
418 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
419 IN BOOLEAN ExtendedVerification
423 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString().
424 The Unicode string will be converted to terminal expressible data stream
425 and send to terminal via serial port.
427 @param This Indicates the calling context.
428 @param WString The Null-terminated Unicode string to be displayed
429 on the terminal screen.
431 @retval EFI_SUCCESS The string is output successfully.
432 @retval EFI_DEVICE_ERROR The serial port fails to send the string out.
433 @retval EFI_WARN_UNKNOWN_GLYPH Indicates that some of the characters in the Unicode string could not
434 be rendered and are skipped.
435 @retval EFI_UNSUPPORTED If current display mode is out of range.
440 TerminalConOutOutputString (
441 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
446 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.TestString().
447 If one of the characters in the *Wstring is
448 neither valid Unicode drawing characters,
449 not ASCII code, then this function will return
452 @param This Indicates the calling context.
453 @param WString The Null-terminated Unicode string to be tested.
455 @retval EFI_SUCCESS The terminal is capable of rendering the output string.
456 @retval EFI_UNSUPPORTED Some of the characters in the Unicode string cannot be rendered.
461 TerminalConOutTestString (
462 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
467 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.QueryMode().
468 It returns information for an available text mode
469 that the terminal supports.
470 In this driver, we support text mode 80x25 (mode 0),
471 80x50 (mode 1), 100x31 (mode 2).
473 @param This Indicates the calling context.
474 @param ModeNumber The mode number to return information on.
475 @param Columns The returned columns of the requested mode.
476 @param Rows The returned rows of the requested mode.
478 @retval EFI_SUCCESS The requested mode information is returned.
479 @retval EFI_UNSUPPORTED The mode number is not valid.
480 @retval EFI_DEVICE_ERROR
485 TerminalConOutQueryMode (
486 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
493 Implements EFI_SIMPLE_TEXT_OUT.SetMode().
494 Set the terminal to a specified display mode.
495 In this driver, we only support mode 0.
497 @param This Indicates the calling context.
498 @param ModeNumber The text mode to set.
500 @retval EFI_SUCCESS The requested text mode is set.
501 @retval EFI_DEVICE_ERROR The requested text mode cannot be set
502 because of serial device error.
503 @retval EFI_UNSUPPORTED The text mode number is not valid.
508 TerminalConOutSetMode (
509 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
514 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetAttribute().
516 @param This Indicates the calling context.
517 @param Attribute The attribute to set. Only bit0..6 are valid, all other bits
518 are undefined and must be zero.
520 @retval EFI_SUCCESS The requested attribute is set.
521 @retval EFI_DEVICE_ERROR The requested attribute cannot be set due to serial port error.
522 @retval EFI_UNSUPPORTED The attribute requested is not defined by EFI spec.
527 TerminalConOutSetAttribute (
528 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
533 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.ClearScreen().
534 It clears the ANSI terminal's display to the
535 currently selected background color.
537 @param This Indicates the calling context.
539 @retval EFI_SUCCESS The operation completed successfully.
540 @retval EFI_DEVICE_ERROR The terminal screen cannot be cleared due to serial port error.
541 @retval EFI_UNSUPPORTED The terminal is not in a valid display mode.
546 TerminalConOutClearScreen (
547 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
551 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetCursorPosition().
553 @param This Indicates the calling context.
554 @param Column The row to set cursor to.
555 @param Row The column to set cursor to.
557 @retval EFI_SUCCESS The operation completed successfully.
558 @retval EFI_DEVICE_ERROR The request fails due to serial port error.
559 @retval EFI_UNSUPPORTED The terminal is not in a valid text mode, or the cursor position
560 is invalid for current mode.
565 TerminalConOutSetCursorPosition (
566 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
572 Implements SIMPLE_TEXT_OUTPUT.EnableCursor().
573 In this driver, the cursor cannot be hidden.
575 @param This Indicates the calling context.
576 @param Visible If TRUE, the cursor is set to be visible,
577 If FALSE, the cursor is set to be invisible.
579 @retval EFI_SUCCESS The request is valid.
580 @retval EFI_UNSUPPORTED The terminal does not support cursor hidden.
585 TerminalConOutEnableCursor (
586 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
591 Test to see if this driver supports Controller.
593 @param This Protocol instance pointer.
594 @param ControllerHandle Handle of device to test
595 @param RemainingDevicePath Optional parameter use to pick a specific child
598 @retval EFI_SUCCESS This driver supports this device.
599 @retval EFI_ALREADY_STARTED This driver is already running on this device.
600 @retval other This driver does not support this device.
605 TerminalDriverBindingSupported (
606 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
607 IN EFI_HANDLE ControllerHandle
,
608 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
612 Start this driver on Controller by opening a Serial IO protocol,
613 reading Device Path, and creating a child handle with a Simple Text In,
614 Simple Text In Ex and Simple Text Out protocol, and device path protocol.
615 And store Console Device Environment Variables.
617 @param This Protocol instance pointer.
618 @param Controller Handle of device to bind driver to
619 @param RemainingDevicePath Optional parameter use to pick a specific child
622 @retval EFI_SUCCESS This driver is added to Controller.
623 @retval EFI_ALREADY_STARTED This driver is already running on Controller.
624 @retval other This driver does not support this device.
629 TerminalDriverBindingStart (
630 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
631 IN EFI_HANDLE Controller
,
632 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
637 Stop this driver on Controller by closing Simple Text In, Simple Text
638 In Ex, Simple Text Out protocol, and removing parent device path from
639 Console Device Environment Variables.
641 @param This Protocol instance pointer.
642 @param Controller Handle of device to stop driver on
643 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
644 children is zero stop the entire bus driver.
645 @param ChildHandleBuffer List of Child Handles to Stop.
647 @retval EFI_SUCCESS This driver is removed Controller.
648 @retval other This driver could not be removed from this device.
653 TerminalDriverBindingStop (
654 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
655 IN EFI_HANDLE Controller
,
656 IN UINTN NumberOfChildren
,
657 IN EFI_HANDLE
*ChildHandleBuffer
661 Free notify functions list.
663 @param ListHead The list head
665 @retval EFI_SUCCESS Free the notify list successfully.
666 @retval EFI_INVALID_PARAMETER ListHead is NULL.
670 TerminalFreeNotifyList (
671 IN OUT LIST_ENTRY
*ListHead
675 Retrieves a Unicode string that is the user readable name of the driver.
677 This function retrieves the user readable name of a driver in the form of a
678 Unicode string. If the driver specified by This has a user readable name in
679 the language specified by Language, then a pointer to the driver name is
680 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
681 by This does not support the language specified by Language,
682 then EFI_UNSUPPORTED is returned.
684 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
685 EFI_COMPONENT_NAME_PROTOCOL instance.
687 @param Language[in] A pointer to a Null-terminated ASCII string
688 array indicating the language. This is the
689 language of the driver name that the caller is
690 requesting, and it must match one of the
691 languages specified in SupportedLanguages. The
692 number of languages supported by a driver is up
693 to the driver writer. Language is specified
694 in RFC 4646 or ISO 639-2 language code format.
696 @param DriverName[out] A pointer to the Unicode string to return.
697 This Unicode string is the name of the
698 driver specified by This in the language
699 specified by Language.
701 @retval EFI_SUCCESS The Unicode string for the Driver specified by
702 This and the language specified by Language was
703 returned in DriverName.
705 @retval EFI_INVALID_PARAMETER Language is NULL.
707 @retval EFI_INVALID_PARAMETER DriverName is NULL.
709 @retval EFI_UNSUPPORTED The driver specified by This does not support
710 the language specified by Language.
715 TerminalComponentNameGetDriverName (
716 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
718 OUT CHAR16
**DriverName
723 Retrieves a Unicode string that is the user readable name of the controller
724 that is being managed by a driver.
726 This function retrieves the user readable name of the controller specified by
727 ControllerHandle and ChildHandle in the form of a Unicode string. If the
728 driver specified by This has a user readable name in the language specified by
729 Language, then a pointer to the controller name is returned in ControllerName,
730 and EFI_SUCCESS is returned. If the driver specified by This is not currently
731 managing the controller specified by ControllerHandle and ChildHandle,
732 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
733 support the language specified by Language, then EFI_UNSUPPORTED is returned.
735 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
736 EFI_COMPONENT_NAME_PROTOCOL instance.
738 @param ControllerHandle[in] The handle of a controller that the driver
739 specified by This is managing. This handle
740 specifies the controller whose name is to be
743 @param ChildHandle[in] The handle of the child controller to retrieve
744 the name of. This is an optional parameter that
745 may be NULL. It will be NULL for device
746 drivers. It will also be NULL for a bus drivers
747 that wish to retrieve the name of the bus
748 controller. It will not be NULL for a bus
749 driver that wishes to retrieve the name of a
752 @param Language[in] A pointer to a Null-terminated ASCII string
753 array indicating the language. This is the
754 language of the driver name that the caller is
755 requesting, and it must match one of the
756 languages specified in SupportedLanguages. The
757 number of languages supported by a driver is up
758 to the driver writer. Language is specified in
759 RFC 4646 or ISO 639-2 language code format.
761 @param ControllerName[out] A pointer to the Unicode string to return.
762 This Unicode string is the name of the
763 controller specified by ControllerHandle and
764 ChildHandle in the language specified by
765 Language from the point of view of the driver
768 @retval EFI_SUCCESS The Unicode string for the user readable name in
769 the language specified by Language for the
770 driver specified by This was returned in
773 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
775 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
778 @retval EFI_INVALID_PARAMETER Language is NULL.
780 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
782 @retval EFI_UNSUPPORTED The driver specified by This is not currently
783 managing the controller specified by
784 ControllerHandle and ChildHandle.
786 @retval EFI_UNSUPPORTED The driver specified by This does not support
787 the language specified by Language.
792 TerminalComponentNameGetControllerName (
793 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
794 IN EFI_HANDLE ControllerHandle
,
795 IN EFI_HANDLE ChildHandle OPTIONAL
,
797 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+ or VT-UTF8.
852 @param ParentDevicePath Parent device path.
853 @param TerminalDevicePath Returned terminal device path, if building successfully.
855 @retval EFI_UNSUPPORTED Terminal does not belong to the supported type.
856 @retval EFI_OUT_OF_RESOURCES Generate terminal device path failed.
857 @retval EFI_SUCCESS Build terminal device path successfully.
861 SetTerminalDevicePath (
862 IN TERMINAL_TYPE TerminalType
,
863 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
864 OUT EFI_DEVICE_PATH_PROTOCOL
**TerminalDevicePath
868 Get one key out of serial buffer.
870 @param SerialIo Serial I/O protocl attached to the serial device.
871 @param Input The fetched key.
873 @retval EFI_NOT_READY If serial buffer is empty.
874 @retval EFI_DEVICE_ERROR If reading serial buffer encounter error.
875 @retval EFI_SUCCESS If reading serial buffer successfully, put
876 the fetched key to the parameter output.
880 GetOneKeyFromSerial (
881 EFI_SERIAL_IO_PROTOCOL
*SerialIo
,
886 Insert one byte raw data into the Raw Data FIFO.
888 @param TerminalDevice Terminal driver private structure.
889 @param Input The key will be input.
891 @retval TRUE If insert successfully.
892 @retval FALSE If Raw Data buffer is full before key insertion,
897 RawFiFoInsertOneKey (
898 TERMINAL_DEV
*TerminalDevice
,
903 Remove one pre-fetched key out of the Raw Data FIFO.
905 @param TerminalDevice Terminal driver private structure.
906 @param Output The key will be removed.
908 @retval TRUE If insert successfully.
909 @retval FALSE If Raw Data FIFO buffer is empty before remove operation.
913 RawFiFoRemoveOneKey (
914 TERMINAL_DEV
*TerminalDevice
,
919 Clarify whether Raw Data FIFO buffer is empty.
921 @param TerminalDevice Terminal driver private structure
923 @retval TRUE If Raw Data FIFO buffer is empty.
924 @retval FALSE If Raw Data FIFO buffer is not empty.
929 TERMINAL_DEV
*TerminalDevice
933 Clarify whether Raw Data FIFO buffer is full.
935 @param TerminalDevice Terminal driver private structure
937 @retval TRUE If Raw Data FIFO buffer is full.
938 @retval FALSE If Raw Data FIFO buffer is not full.
943 TERMINAL_DEV
*TerminalDevice
947 Insert one pre-fetched key into the FIFO buffer.
949 @param EfiKeyFiFo Pointer to instance of EFI_KEY_FIFO.
950 @param Input The key will be input.
952 @retval TRUE If insert successfully.
953 @retval FALSE If FIFO buffer is full before key insertion,
958 EfiKeyFiFoForNotifyInsertOneKey (
959 EFI_KEY_FIFO
*EfiKeyFiFo
,
964 Remove one pre-fetched key out of the FIFO buffer.
966 @param EfiKeyFiFo Pointer to instance of EFI_KEY_FIFO.
967 @param Output The key will be removed.
969 @retval TRUE If insert successfully.
970 @retval FALSE If FIFO buffer is empty before remove operation.
974 EfiKeyFiFoForNotifyRemoveOneKey (
975 EFI_KEY_FIFO
*EfiKeyFiFo
,
976 EFI_INPUT_KEY
*Output
980 Clarify whether FIFO buffer is empty.
982 @param EfiKeyFiFo Pointer to instance of EFI_KEY_FIFO.
984 @retval TRUE If FIFO buffer is empty.
985 @retval FALSE If FIFO buffer is not empty.
989 IsEfiKeyFiFoForNotifyEmpty (
990 IN EFI_KEY_FIFO
*EfiKeyFiFo
994 Clarify whether FIFO buffer is full.
996 @param EfiKeyFiFo Pointer to instance of EFI_KEY_FIFO.
998 @retval TRUE If FIFO buffer is full.
999 @retval FALSE If FIFO buffer is not full.
1003 IsEfiKeyFiFoForNotifyFull (
1004 EFI_KEY_FIFO
*EfiKeyFiFo
1008 Insert one pre-fetched key into the FIFO buffer.
1010 @param TerminalDevice Terminal driver private structure.
1011 @param Key The key will be input.
1013 @retval TRUE If insert successfully.
1014 @retval FALSE If FIFO buffer is full before key insertion,
1015 and the key is lost.
1019 EfiKeyFiFoInsertOneKey (
1020 TERMINAL_DEV
*TerminalDevice
,
1025 Remove one pre-fetched key out of the FIFO buffer.
1027 @param TerminalDevice Terminal driver private structure.
1028 @param Output The key will be removed.
1030 @retval TRUE If insert successfully.
1031 @retval FALSE If FIFO buffer is empty before remove operation.
1035 EfiKeyFiFoRemoveOneKey (
1036 TERMINAL_DEV
*TerminalDevice
,
1037 EFI_INPUT_KEY
*Output
1041 Clarify whether FIFO buffer is empty.
1043 @param TerminalDevice Terminal driver private structure
1045 @retval TRUE If FIFO buffer is empty.
1046 @retval FALSE If FIFO buffer is not empty.
1051 TERMINAL_DEV
*TerminalDevice
1055 Clarify whether FIFO buffer is full.
1057 @param TerminalDevice Terminal driver private structure
1059 @retval TRUE If FIFO buffer is full.
1060 @retval FALSE If FIFO buffer is not full.
1065 TERMINAL_DEV
*TerminalDevice
1069 Insert one pre-fetched key into the Unicode FIFO buffer.
1071 @param TerminalDevice Terminal driver private structure.
1072 @param Input The key will be input.
1074 @retval TRUE If insert successfully.
1075 @retval FALSE If Unicode FIFO buffer is full before key insertion,
1076 and the key is lost.
1080 UnicodeFiFoInsertOneKey (
1081 TERMINAL_DEV
*TerminalDevice
,
1086 Remove one pre-fetched key out of the Unicode FIFO buffer.
1087 The caller should guarantee that Unicode FIFO buffer is not empty
1088 by IsUnicodeFiFoEmpty ().
1090 @param TerminalDevice Terminal driver private structure.
1091 @param Output The key will be removed.
1095 UnicodeFiFoRemoveOneKey (
1096 TERMINAL_DEV
*TerminalDevice
,
1101 Clarify whether Unicode FIFO buffer is empty.
1103 @param TerminalDevice Terminal driver private structure
1105 @retval TRUE If Unicode FIFO buffer is empty.
1106 @retval FALSE If Unicode FIFO buffer is not empty.
1110 IsUnicodeFiFoEmpty (
1111 TERMINAL_DEV
*TerminalDevice
1115 Clarify whether Unicode FIFO buffer is full.
1117 @param TerminalDevice Terminal driver private structure
1119 @retval TRUE If Unicode FIFO buffer is full.
1120 @retval FALSE If Unicode FIFO buffer is not full.
1125 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 +=========+======+===========+==========+==========+
1214 ESC R ESC r ESC R = Reset System
1217 @param TerminalDevice The terminal device to use to translate raw input into EFI Keys
1222 IN TERMINAL_DEV
*TerminalDevice
1226 Check if input string is valid Ascii string, valid EFI control characters
1227 or valid text graphics.
1229 @param TerminalDevice The terminal device.
1230 @param WString The input string.
1232 @retval EFI_UNSUPPORTED If not all input characters are valid.
1233 @retval EFI_SUCCESS If all input characters are valid.
1238 IN TERMINAL_DEV
*TerminalDevice
,
1243 // internal functions for VTUTF8
1247 Translate all VT-UTF8 characters in the Raw FIFI into unicode characters,
1248 and insert them into Unicode FIFO.
1250 @param VtUtf8Device The terminal device.
1254 VTUTF8RawDataToUnicode (
1255 IN TERMINAL_DEV
*VtUtf8Device
1259 Check if input string is valid VT-UTF8 string.
1261 @param TerminalDevice The terminal device.
1262 @param WString The input string.
1264 @retval EFI_SUCCESS If all input characters are valid.
1269 IN TERMINAL_DEV
*TerminalDevice
,
1274 Translate one Unicode character into VT-UTF8 characters.
1277 Bits per Character | Unicode Character Range | Unicode Binary Encoding | UTF8 Binary Encoding
1278 0-7 | 0x0000 - 0x007F | 00000000 0xxxxxxx | 0xxxxxxx
1279 8-11 | 0x0080 - 0x07FF | 00000xxx xxxxxxxx | 110xxxxx 10xxxxxx
1280 12-16 | 0x0800 - 0xFFFF | xxxxxxxx xxxxxxxx | 1110xxxx 10xxxxxx 10xxxxxx
1283 @param Unicode Unicode character need translating.
1284 @param Utf8Char Return VT-UTF8 character set.
1285 @param ValidBytes The count of valid VT-UTF8 characters. If
1286 ValidBytes is zero, no valid VT-UTF8 returned.
1292 OUT UTF8_CHAR
*Utf8Char
,
1293 OUT UINT8
*ValidBytes
1297 Get one valid VT-UTF8 characters set from Raw Data FIFO.
1299 @param Utf8Device The terminal device.
1300 @param Utf8Char Returned valid VT-UTF8 characters set.
1301 @param ValidBytes The count of returned VT-VTF8 characters.
1302 If ValidBytes is zero, no valid VT-UTF8 returned.
1306 GetOneValidUtf8Char (
1307 IN TERMINAL_DEV
*Utf8Device
,
1308 OUT UTF8_CHAR
*Utf8Char
,
1309 OUT UINT8
*ValidBytes
1313 Translate VT-UTF8 characters into one Unicode character.
1316 Bits per Character | Unicode Character Range | Unicode Binary Encoding | UTF8 Binary Encoding
1317 0-7 | 0x0000 - 0x007F | 00000000 0xxxxxxx | 0xxxxxxx
1318 8-11 | 0x0080 - 0x07FF | 00000xxx xxxxxxxx | 110xxxxx 10xxxxxx
1319 12-16 | 0x0800 - 0xFFFF | xxxxxxxx xxxxxxxx | 1110xxxx 10xxxxxx 10xxxxxx
1322 @param Utf8Char VT-UTF8 character set needs translating.
1323 @param ValidBytes The count of valid VT-UTF8 characters.
1324 @param UnicodeChar Returned unicode character.
1329 IN UTF8_CHAR Utf8Char
,
1330 IN UINT8 ValidBytes
,
1331 OUT CHAR16
*UnicodeChar
1335 // functions for boxdraw unicode
1339 Detects if a Unicode char is for Box Drawing text graphics.
1341 @param Graphic Unicode char to test.
1342 @param PcAnsi Optional pointer to return PCANSI equivalent of
1344 @param Ascii Optional pointer to return ASCII equivalent of
1347 @retval TRUE If Graphic is a supported Unicode Box Drawing character.
1351 TerminalIsValidTextGraphics (
1353 OUT CHAR8
*PcAnsi
, OPTIONAL
1354 OUT CHAR8
*Ascii OPTIONAL
1358 Detects if a valid ASCII char.
1360 @param Ascii An ASCII character.
1362 @retval TRUE If it is a valid ASCII character.
1363 @retval FALSE If it is not a valid ASCII character.
1367 TerminalIsValidAscii (
1372 Detects if a valid EFI control character.
1374 @param CharC An input EFI Control character.
1376 @retval TRUE If it is a valid EFI control character.
1377 @retval FALSE If it is not a valid EFI control character.
1381 TerminalIsValidEfiCntlChar (
1386 Check if the device supports hot-plug through its device path.
1388 This function could be updated to check more types of Hot Plug devices.
1389 Currently, it checks USB and PCCard device.
1391 @param DevicePath Pointer to device's device path.
1393 @retval TRUE The devcie is a hot-plug device
1394 @retval FALSE The devcie is not a hot-plug device.
1399 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1403 Timer handler to poll the key from serial.
1405 @param Event Indicates the event that invoke this function.
1406 @param Context Indicates the calling context.
1410 TerminalConInTimerHandler (
1419 @param Event Indicates the event that invoke this function.
1420 @param Context Indicates the calling context.
1424 KeyNotifyProcessHandler (