2 Header file for Terminal driver.
4 Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
5 Copyright (C) 2016 Silicon Graphics, Inc. All rights reserved.<BR>
6 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 #include <Guid/GlobalVariable.h>
23 #include <Guid/PcAnsi.h>
24 #include <Guid/TtyTerm.h>
25 #include <Guid/StatusCodeDataTypeVariable.h>
27 #include <Protocol/SimpleTextOut.h>
28 #include <Protocol/SerialIo.h>
29 #include <Protocol/DevicePath.h>
30 #include <Protocol/SimpleTextIn.h>
31 #include <Protocol/SimpleTextInEx.h>
33 #include <Library/DebugLib.h>
34 #include <Library/UefiDriverEntryPoint.h>
35 #include <Library/UefiLib.h>
36 #include <Library/ReportStatusCodeLib.h>
37 #include <Library/BaseMemoryLib.h>
38 #include <Library/MemoryAllocationLib.h>
39 #include <Library/UefiBootServicesTableLib.h>
40 #include <Library/UefiRuntimeServicesTableLib.h>
41 #include <Library/DevicePathLib.h>
42 #include <Library/PcdLib.h>
43 #include <Library/BaseLib.h>
46 #define RAW_FIFO_MAX_NUMBER 256
47 #define FIFO_MAX_NUMBER 128
52 UINT8 Data
[RAW_FIFO_MAX_NUMBER
+ 1];
58 UINT16 Data
[FIFO_MAX_NUMBER
+ 1];
64 EFI_INPUT_KEY Data
[FIFO_MAX_NUMBER
+ 1];
70 } TERMINAL_CONSOLE_MODE_DATA
;
72 #define KEYBOARD_TIMER_INTERVAL 200000 // 0.02s
74 #define TERMINAL_DEV_SIGNATURE SIGNATURE_32 ('t', 'm', 'n', 'l')
76 #define TERMINAL_CONSOLE_IN_EX_NOTIFY_SIGNATURE SIGNATURE_32 ('t', 'm', 'e', 'n')
78 typedef struct _TERMINAL_CONSOLE_IN_EX_NOTIFY
{
81 EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn
;
82 LIST_ENTRY NotifyEntry
;
83 } TERMINAL_CONSOLE_IN_EX_NOTIFY
;
88 TerminalTypeVt100Plus
,
96 TERMINAL_TYPE TerminalType
;
97 EFI_SERIAL_IO_PROTOCOL
*SerialIo
;
98 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
99 EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleInput
;
100 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL SimpleTextOutput
;
101 EFI_SIMPLE_TEXT_OUTPUT_MODE SimpleTextOutputMode
;
102 TERMINAL_CONSOLE_MODE_DATA
*TerminalConsoleModeData
;
103 UINTN SerialInTimeOut
;
104 RAW_DATA_FIFO
*RawFiFo
;
105 UNICODE_FIFO
*UnicodeFiFo
;
106 EFI_KEY_FIFO
*EfiKeyFiFo
;
107 EFI_KEY_FIFO
*EfiKeyFiFoForNotify
;
108 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
109 EFI_EVENT TimerEvent
;
110 EFI_EVENT TwoSecondTimeOut
;
113 UINT16 TtyEscapeStr
[3];
117 // Esc could not be output to the screen by user,
118 // but the terminal driver need to output it to
119 // the terminal emulation software to send control sequence.
120 // This boolean is used by the terminal driver only
121 // to indicate whether the Esc could be sent or not.
123 BOOLEAN OutputEscChar
;
124 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL SimpleInputEx
;
125 LIST_ENTRY NotifyList
;
126 EFI_EVENT KeyNotifyProcessEvent
;
129 #define INPUT_STATE_DEFAULT 0x00
130 #define INPUT_STATE_ESC 0x01
131 #define INPUT_STATE_CSI 0x02
132 #define INPUT_STATE_LEFTOPENBRACKET 0x04
133 #define INPUT_STATE_O 0x08
134 #define INPUT_STATE_2 0x10
135 #define INPUT_STATE_LEFTOPENBRACKET_2 0x20
137 #define RESET_STATE_DEFAULT 0x00
138 #define RESET_STATE_ESC_R 0x01
139 #define RESET_STATE_ESC_R_ESC_R 0x02
141 #define TERMINAL_CON_IN_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleInput, TERMINAL_DEV_SIGNATURE)
142 #define TERMINAL_CON_OUT_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleTextOutput, TERMINAL_DEV_SIGNATURE)
143 #define TERMINAL_CON_IN_EX_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleInputEx, TERMINAL_DEV_SIGNATURE)
151 #define LEFTOPENBRACKET 0x5b // '['
161 #define BRIGHT_CONTROL_OFFSET 2
162 #define FOREGROUND_CONTROL_OFFSET 6
163 #define BACKGROUND_CONTROL_OFFSET 11
165 #define COLUMN_OFFSET 5
166 #define FW_BACK_OFFSET 2
177 extern EFI_DRIVER_BINDING_PROTOCOL gTerminalDriverBinding
;
178 extern EFI_COMPONENT_NAME_PROTOCOL gTerminalComponentName
;
179 extern EFI_COMPONENT_NAME2_PROTOCOL gTerminalComponentName2
;
182 The user Entry Point for module Terminal. The user code starts with this function.
184 @param[in] ImageHandle The firmware allocated handle for the EFI image.
185 @param[in] SystemTable A pointer to the EFI System Table.
187 @retval EFI_SUCCESS The entry point is executed successfully.
188 @retval other Some error occurs when executing this entry point.
194 IN EFI_HANDLE ImageHandle
,
195 IN EFI_SYSTEM_TABLE
*SystemTable
199 Implements EFI_SIMPLE_TEXT_INPUT_PROTOCOL.Reset().
200 This driver only perform dependent serial device reset regardless of
201 the value of ExtendeVerification
203 @param This Indicates the calling context.
204 @param ExtendedVerification Skip by this driver.
206 @retval EFI_SUCCESS The reset operation succeeds.
207 @retval EFI_DEVICE_ERROR The dependent serial port reset fails.
213 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
214 IN BOOLEAN ExtendedVerification
219 Implements EFI_SIMPLE_TEXT_INPUT_PROTOCOL.ReadKeyStroke().
221 @param This Indicates the calling context.
222 @param Key A pointer to a buffer that is filled in with the
223 keystroke information for the key that was sent
226 @retval EFI_SUCCESS The keystroke information is returned successfully.
227 @retval EFI_NOT_READY There is no keystroke data available.
228 @retval EFI_DEVICE_ERROR The dependent serial device encounters error.
233 TerminalConInReadKeyStroke (
234 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
235 OUT EFI_INPUT_KEY
*Key
239 Check if the key already has been registered.
241 @param RegsiteredData A pointer to a buffer that is filled in with the
242 keystroke state data for the key that was
244 @param InputData A pointer to a buffer that is filled in with the
245 keystroke state data for the key that was
248 @retval TRUE Key be pressed matches a registered key.
249 @retval FALSE Match failed.
254 IN EFI_KEY_DATA
*RegsiteredData
,
255 IN EFI_KEY_DATA
*InputData
259 Event notification function for EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx event
260 Signal the event if there is key available
262 @param Event Indicates the event that invoke this function.
263 @param Context Indicates the calling context.
268 TerminalConInWaitForKeyEx (
274 // Simple Text Input Ex protocol prototypes
278 Reset the input device and optionally run diagnostics
280 @param This Protocol instance pointer.
281 @param ExtendedVerification Driver may perform diagnostics on reset.
283 @retval EFI_SUCCESS The device was reset.
284 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
290 TerminalConInResetEx (
291 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
292 IN BOOLEAN ExtendedVerification
296 Reads the next keystroke from the input device. The WaitForKey Event can
297 be used to test for existence of a keystroke via WaitForEvent () call.
299 @param This Protocol instance pointer.
300 @param KeyData A pointer to a buffer that is filled in with the
301 keystroke state data for the key that was
304 @retval EFI_SUCCESS The keystroke information was returned.
305 @retval EFI_NOT_READY There was no keystroke data available.
306 @retval EFI_DEVICE_ERROR The keystroke information was not returned due
308 @retval EFI_INVALID_PARAMETER KeyData is NULL.
313 TerminalConInReadKeyStrokeEx (
314 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
315 OUT EFI_KEY_DATA
*KeyData
319 Set certain state for the input device.
321 @param This Protocol instance pointer.
322 @param KeyToggleState A pointer to the EFI_KEY_TOGGLE_STATE to set the
323 state for the input device.
325 @retval EFI_SUCCESS The device state was set successfully.
326 @retval EFI_DEVICE_ERROR The device is not functioning correctly and
327 could not have the setting adjusted.
328 @retval EFI_UNSUPPORTED The device does not have the ability to set its
330 @retval EFI_INVALID_PARAMETER KeyToggleState is NULL.
335 TerminalConInSetState (
336 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
337 IN EFI_KEY_TOGGLE_STATE
*KeyToggleState
341 Register a notification function for a particular keystroke for the input device.
343 @param This Protocol instance pointer.
344 @param KeyData A pointer to a buffer that is filled in with the
345 keystroke information data for the key that was
347 @param KeyNotificationFunction Points to the function to be called when the key
348 sequence is typed specified by KeyData.
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
640 Stop this driver on Controller by closing Simple Text In, Simple Text
641 In Ex, Simple Text Out protocol, and removing parent device path from
642 Console Device Environment Variables.
644 @param This Protocol instance pointer.
645 @param Controller Handle of device to stop driver on
646 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
647 children is zero stop the entire bus driver.
648 @param ChildHandleBuffer List of Child Handles to Stop.
650 @retval EFI_SUCCESS This driver is removed Controller.
651 @retval other This driver could not be removed from this device.
656 TerminalDriverBindingStop (
657 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
658 IN EFI_HANDLE Controller
,
659 IN UINTN NumberOfChildren
,
660 IN EFI_HANDLE
*ChildHandleBuffer
664 Free notify functions list.
666 @param ListHead The list head
668 @retval EFI_SUCCESS Free the notify list successfully.
669 @retval EFI_INVALID_PARAMETER ListHead is NULL.
673 TerminalFreeNotifyList (
674 IN OUT LIST_ENTRY
*ListHead
678 Retrieves a Unicode string that is the user readable name of the driver.
680 This function retrieves the user readable name of a driver in the form of a
681 Unicode string. If the driver specified by This has a user readable name in
682 the language specified by Language, then a pointer to the driver name is
683 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
684 by This does not support the language specified by Language,
685 then EFI_UNSUPPORTED is returned.
687 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
688 EFI_COMPONENT_NAME_PROTOCOL instance.
690 @param Language[in] A pointer to a Null-terminated ASCII string
691 array indicating the language. This is the
692 language of the driver name that the caller is
693 requesting, and it must match one of the
694 languages specified in SupportedLanguages. The
695 number of languages supported by a driver is up
696 to the driver writer. Language is specified
697 in RFC 4646 or ISO 639-2 language code format.
699 @param DriverName[out] A pointer to the Unicode string to return.
700 This Unicode string is the name of the
701 driver specified by This in the language
702 specified by Language.
704 @retval EFI_SUCCESS The Unicode string for the Driver specified by
705 This and the language specified by Language was
706 returned in DriverName.
708 @retval EFI_INVALID_PARAMETER Language is NULL.
710 @retval EFI_INVALID_PARAMETER DriverName is NULL.
712 @retval EFI_UNSUPPORTED The driver specified by This does not support
713 the language specified by Language.
718 TerminalComponentNameGetDriverName (
719 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
721 OUT CHAR16
**DriverName
726 Retrieves a Unicode string that is the user readable name of the controller
727 that is being managed by a driver.
729 This function retrieves the user readable name of the controller specified by
730 ControllerHandle and ChildHandle in the form of a Unicode string. If the
731 driver specified by This has a user readable name in the language specified by
732 Language, then a pointer to the controller name is returned in ControllerName,
733 and EFI_SUCCESS is returned. If the driver specified by This is not currently
734 managing the controller specified by ControllerHandle and ChildHandle,
735 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
736 support the language specified by Language, then EFI_UNSUPPORTED is returned.
738 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
739 EFI_COMPONENT_NAME_PROTOCOL instance.
741 @param ControllerHandle[in] The handle of a controller that the driver
742 specified by This is managing. This handle
743 specifies the controller whose name is to be
746 @param ChildHandle[in] The handle of the child controller to retrieve
747 the name of. This is an optional parameter that
748 may be NULL. It will be NULL for device
749 drivers. It will also be NULL for a bus drivers
750 that wish to retrieve the name of the bus
751 controller. It will not be NULL for a bus
752 driver that wishes to retrieve the name of a
755 @param Language[in] A pointer to a Null-terminated ASCII string
756 array indicating the language. This is the
757 language of the driver name that the caller is
758 requesting, and it must match one of the
759 languages specified in SupportedLanguages. The
760 number of languages supported by a driver is up
761 to the driver writer. Language is specified in
762 RFC 4646 or ISO 639-2 language code format.
764 @param ControllerName[out] A pointer to the Unicode string to return.
765 This Unicode string is the name of the
766 controller specified by ControllerHandle and
767 ChildHandle in the language specified by
768 Language from the point of view of the driver
771 @retval EFI_SUCCESS The Unicode string for the user readable name in
772 the language specified by Language for the
773 driver specified by This was returned in
776 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
778 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
781 @retval EFI_INVALID_PARAMETER Language is NULL.
783 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
785 @retval EFI_UNSUPPORTED The driver specified by This is not currently
786 managing the controller specified by
787 ControllerHandle and ChildHandle.
789 @retval EFI_UNSUPPORTED The driver specified by This does not support
790 the language specified by Language.
795 TerminalComponentNameGetControllerName (
796 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
797 IN EFI_HANDLE ControllerHandle
,
798 IN EFI_HANDLE ChildHandle OPTIONAL
,
800 OUT CHAR16
**ControllerName
805 // internal functions
809 Check for a pending key in the Efi Key FIFO or Serial device buffer.
811 @param This Indicates the calling context.
813 @retval EFI_SUCCESS There is key pending.
814 @retval EFI_NOT_READY There is no key pending.
815 @retval EFI_DEVICE_ERROR If Serial IO is not attached to serial device.
819 TerminalConInCheckForKey (
820 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
824 Update terminal device path in Console Device Environment Variables.
826 @param VariableName The Console Device Environment Variable.
827 @param ParentDevicePath The terminal device path to be updated.
833 TerminalUpdateConsoleDevVariable (
834 IN CHAR16
*VariableName
,
835 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
839 Remove console device variable.
841 @param VariableName A pointer to the variable name.
842 @param ParentDevicePath A pointer to the parent device path.
846 TerminalRemoveConsoleDevVariable (
847 IN CHAR16
*VariableName
,
848 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
852 Build termial device path according to terminal type.
854 @param TerminalType The terminal type is PC ANSI, VT100, VT100+ or VT-UTF8.
855 @param ParentDevicePath Parent device path.
856 @param TerminalDevicePath Returned terminal device path, if building successfully.
858 @retval EFI_UNSUPPORTED Terminal does not belong to the supported type.
859 @retval EFI_OUT_OF_RESOURCES Generate terminal device path failed.
860 @retval EFI_SUCCESS Build terminal device path successfully.
864 SetTerminalDevicePath (
865 IN TERMINAL_TYPE TerminalType
,
866 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
867 OUT EFI_DEVICE_PATH_PROTOCOL
**TerminalDevicePath
871 Get one key out of serial buffer.
873 @param SerialIo Serial I/O protocl attached to the serial device.
874 @param Input The fetched key.
876 @retval EFI_NOT_READY If serial buffer is empty.
877 @retval EFI_DEVICE_ERROR If reading serial buffer encounter error.
878 @retval EFI_SUCCESS If reading serial buffer successfully, put
879 the fetched key to the parameter output.
883 GetOneKeyFromSerial (
884 EFI_SERIAL_IO_PROTOCOL
*SerialIo
,
889 Insert one byte raw data into the Raw Data FIFO.
891 @param TerminalDevice Terminal driver private structure.
892 @param Input The key will be input.
894 @retval TRUE If insert successfully.
895 @retval FALSE If Raw Data buffer is full before key insertion,
900 RawFiFoInsertOneKey (
901 TERMINAL_DEV
*TerminalDevice
,
906 Remove one pre-fetched key out of the Raw Data FIFO.
908 @param TerminalDevice Terminal driver private structure.
909 @param Output The key will be removed.
911 @retval TRUE If insert successfully.
912 @retval FALSE If Raw Data FIFO buffer is empty before remove operation.
916 RawFiFoRemoveOneKey (
917 TERMINAL_DEV
*TerminalDevice
,
922 Clarify whether Raw Data FIFO buffer is empty.
924 @param TerminalDevice Terminal driver private structure
926 @retval TRUE If Raw Data FIFO buffer is empty.
927 @retval FALSE If Raw Data FIFO buffer is not empty.
932 TERMINAL_DEV
*TerminalDevice
936 Clarify whether Raw Data FIFO buffer is full.
938 @param TerminalDevice Terminal driver private structure
940 @retval TRUE If Raw Data FIFO buffer is full.
941 @retval FALSE If Raw Data FIFO buffer is not full.
946 TERMINAL_DEV
*TerminalDevice
950 Insert one pre-fetched key into the FIFO buffer.
952 @param EfiKeyFiFo Pointer to instance of EFI_KEY_FIFO.
953 @param Input The key will be input.
955 @retval TRUE If insert successfully.
956 @retval FALSE If FIFO buffer is full before key insertion,
961 EfiKeyFiFoForNotifyInsertOneKey (
962 EFI_KEY_FIFO
*EfiKeyFiFo
,
967 Remove one pre-fetched key out of the FIFO buffer.
969 @param EfiKeyFiFo Pointer to instance of EFI_KEY_FIFO.
970 @param Output The key will be removed.
972 @retval TRUE If insert successfully.
973 @retval FALSE If FIFO buffer is empty before remove operation.
977 EfiKeyFiFoForNotifyRemoveOneKey (
978 EFI_KEY_FIFO
*EfiKeyFiFo
,
979 EFI_INPUT_KEY
*Output
983 Clarify whether FIFO buffer is empty.
985 @param EfiKeyFiFo Pointer to instance of EFI_KEY_FIFO.
987 @retval TRUE If FIFO buffer is empty.
988 @retval FALSE If FIFO buffer is not empty.
992 IsEfiKeyFiFoForNotifyEmpty (
993 IN EFI_KEY_FIFO
*EfiKeyFiFo
997 Clarify whether FIFO buffer is full.
999 @param EfiKeyFiFo Pointer to instance of EFI_KEY_FIFO.
1001 @retval TRUE If FIFO buffer is full.
1002 @retval FALSE If FIFO buffer is not full.
1006 IsEfiKeyFiFoForNotifyFull (
1007 EFI_KEY_FIFO
*EfiKeyFiFo
1011 Insert one pre-fetched key into the FIFO buffer.
1013 @param TerminalDevice Terminal driver private structure.
1014 @param Key The key will be input.
1016 @retval TRUE If insert successfully.
1017 @retval FALSE If FIFO buffer is full before key insertion,
1018 and the key is lost.
1022 EfiKeyFiFoInsertOneKey (
1023 TERMINAL_DEV
*TerminalDevice
,
1028 Remove one pre-fetched key out of the FIFO buffer.
1030 @param TerminalDevice Terminal driver private structure.
1031 @param Output The key will be removed.
1033 @retval TRUE If insert successfully.
1034 @retval FALSE If FIFO buffer is empty before remove operation.
1038 EfiKeyFiFoRemoveOneKey (
1039 TERMINAL_DEV
*TerminalDevice
,
1040 EFI_INPUT_KEY
*Output
1044 Clarify whether FIFO buffer is empty.
1046 @param TerminalDevice Terminal driver private structure
1048 @retval TRUE If FIFO buffer is empty.
1049 @retval FALSE If FIFO buffer is not empty.
1054 TERMINAL_DEV
*TerminalDevice
1058 Clarify whether FIFO buffer is full.
1060 @param TerminalDevice Terminal driver private structure
1062 @retval TRUE If FIFO buffer is full.
1063 @retval FALSE If FIFO buffer is not full.
1068 TERMINAL_DEV
*TerminalDevice
1072 Insert one pre-fetched key into the Unicode FIFO buffer.
1074 @param TerminalDevice Terminal driver private structure.
1075 @param Input The key will be input.
1077 @retval TRUE If insert successfully.
1078 @retval FALSE If Unicode FIFO buffer is full before key insertion,
1079 and the key is lost.
1083 UnicodeFiFoInsertOneKey (
1084 TERMINAL_DEV
*TerminalDevice
,
1089 Remove one pre-fetched key out of the Unicode FIFO buffer.
1090 The caller should guarantee that Unicode FIFO buffer is not empty
1091 by IsUnicodeFiFoEmpty ().
1093 @param TerminalDevice Terminal driver private structure.
1094 @param Output The key will be removed.
1098 UnicodeFiFoRemoveOneKey (
1099 TERMINAL_DEV
*TerminalDevice
,
1104 Clarify whether Unicode FIFO buffer is empty.
1106 @param TerminalDevice Terminal driver private structure
1108 @retval TRUE If Unicode FIFO buffer is empty.
1109 @retval FALSE If Unicode FIFO buffer is not empty.
1113 IsUnicodeFiFoEmpty (
1114 TERMINAL_DEV
*TerminalDevice
1118 Clarify whether Unicode FIFO buffer is full.
1120 @param TerminalDevice Terminal driver private structure
1122 @retval TRUE If Unicode FIFO buffer is full.
1123 @retval FALSE If Unicode FIFO buffer is not full.
1128 TERMINAL_DEV
*TerminalDevice
1132 Count Unicode FIFO buffer.
1134 @param TerminalDevice Terminal driver private structure
1136 @return The count in bytes of Unicode FIFO.
1140 UnicodeFiFoGetKeyCount (
1141 TERMINAL_DEV
*TerminalDevice
1145 Translate raw data into Unicode (according to different encode), and
1146 translate Unicode into key information. (according to different standard).
1148 @param TerminalDevice Terminal driver private structure.
1152 TranslateRawDataToEfiKey (
1153 IN TERMINAL_DEV
*TerminalDevice
1157 // internal functions for PC ANSI
1161 Translate all raw data in the Raw FIFI into unicode, and insert
1162 them into Unicode FIFO.
1164 @param TerminalDevice The terminal device.
1168 AnsiRawDataToUnicode (
1169 IN TERMINAL_DEV
*TerminalDevice
1173 Converts a stream of Unicode characters from a terminal input device into EFI Keys that
1174 can be read through the Simple Input Protocol.
1176 The table below shows the keyboard input mappings that this function supports.
1177 If the ESC sequence listed in one of the columns is presented, then it is translated
1178 into the coorespoding EFI Scan Code. If a matching sequence is not found, then the raw
1179 key strokes are converted into EFI Keys.
1181 2 seconds are allowed for an ESC sequence to be completed. If the ESC sequence is not
1182 completed in 2 seconds, then the raw key strokes of the partial ESC sequence are
1183 converted into EFI Keys.
1184 There is one special input sequence that will force the system to reset.
1185 This is ESC R ESC r ESC R.
1187 Symbols used in table below
1188 ===========================
1193 +=========+======+===========+==========+==========+
1194 | | EFI | UEFI 2.0 | | |
1195 | | Scan | | VT100+ | |
1196 | KEY | Code | PC ANSI | VTUTF8 | VT100 |
1197 +=========+======+===========+==========+==========+
1198 | NULL | 0x00 | | | |
1199 | UP | 0x01 | ESC [ A | ESC [ A | ESC [ A |
1200 | DOWN | 0x02 | ESC [ B | ESC [ B | ESC [ B |
1201 | RIGHT | 0x03 | ESC [ C | ESC [ C | ESC [ C |
1202 | LEFT | 0x04 | ESC [ D | ESC [ D | ESC [ D |
1203 | HOME | 0x05 | ESC [ H | ESC h | ESC [ H |
1204 | END | 0x06 | ESC [ F | ESC k | ESC [ K |
1205 | INSERT | 0x07 | ESC [ @ | ESC + | ESC [ @ |
1206 | | | ESC [ L | | ESC [ L |
1207 | DELETE | 0x08 | ESC [ X | ESC - | ESC [ P |
1208 | PG UP | 0x09 | ESC [ I | ESC ? | ESC [ V |
1210 | PG DOWN | 0x0A | ESC [ G | ESC / | ESC [ U |
1212 | F1 | 0x0B | ESC [ M | ESC 1 | ESC O P |
1213 | F2 | 0x0C | ESC [ N | ESC 2 | ESC O Q |
1214 | F3 | 0x0D | ESC [ O | ESC 3 | ESC O w |
1215 | F4 | 0x0E | ESC [ P | ESC 4 | ESC O x |
1216 | F5 | 0x0F | ESC [ Q | ESC 5 | ESC O t |
1217 | F6 | 0x10 | ESC [ R | ESC 6 | ESC O u |
1218 | F7 | 0x11 | ESC [ S | ESC 7 | ESC O q |
1219 | F8 | 0x12 | ESC [ T | ESC 8 | ESC O r |
1220 | F9 | 0x13 | ESC [ U | ESC 9 | ESC O p |
1221 | F10 | 0x14 | ESC [ V | ESC 0 | ESC O M |
1222 | Escape | 0x17 | ESC | ESC | ESC |
1223 | F11 | 0x15 | | ESC ! | |
1224 | F12 | 0x16 | | ESC @ | |
1225 +=========+======+===========+==========+==========+
1229 ESC R ESC r ESC R = Reset System
1232 @param TerminalDevice The terminal device to use to translate raw input into EFI Keys
1237 IN TERMINAL_DEV
*TerminalDevice
1241 Check if input string is valid Ascii string, valid EFI control characters
1242 or valid text graphics.
1244 @param TerminalDevice The terminal device.
1245 @param WString The input string.
1247 @retval EFI_UNSUPPORTED If not all input characters are valid.
1248 @retval EFI_SUCCESS If all input characters are valid.
1253 IN TERMINAL_DEV
*TerminalDevice
,
1258 // internal functions for VTUTF8
1262 Translate all VT-UTF8 characters in the Raw FIFI into unicode characters,
1263 and insert them into Unicode FIFO.
1265 @param VtUtf8Device The terminal device.
1269 VTUTF8RawDataToUnicode (
1270 IN TERMINAL_DEV
*VtUtf8Device
1274 Check if input string is valid VT-UTF8 string.
1276 @param TerminalDevice The terminal device.
1277 @param WString The input string.
1279 @retval EFI_SUCCESS If all input characters are valid.
1284 IN TERMINAL_DEV
*TerminalDevice
,
1289 Translate one Unicode character into VT-UTF8 characters.
1292 Bits per Character | Unicode Character Range | Unicode Binary Encoding | UTF8 Binary Encoding
1293 0-7 | 0x0000 - 0x007F | 00000000 0xxxxxxx | 0xxxxxxx
1294 8-11 | 0x0080 - 0x07FF | 00000xxx xxxxxxxx | 110xxxxx 10xxxxxx
1295 12-16 | 0x0800 - 0xFFFF | xxxxxxxx xxxxxxxx | 1110xxxx 10xxxxxx 10xxxxxx
1298 @param Unicode Unicode character need translating.
1299 @param Utf8Char Return VT-UTF8 character set.
1300 @param ValidBytes The count of valid VT-UTF8 characters. If
1301 ValidBytes is zero, no valid VT-UTF8 returned.
1307 OUT UTF8_CHAR
*Utf8Char
,
1308 OUT UINT8
*ValidBytes
1312 Get one valid VT-UTF8 characters set from Raw Data FIFO.
1314 @param Utf8Device The terminal device.
1315 @param Utf8Char Returned valid VT-UTF8 characters set.
1316 @param ValidBytes The count of returned VT-VTF8 characters.
1317 If ValidBytes is zero, no valid VT-UTF8 returned.
1321 GetOneValidUtf8Char (
1322 IN TERMINAL_DEV
*Utf8Device
,
1323 OUT UTF8_CHAR
*Utf8Char
,
1324 OUT UINT8
*ValidBytes
1328 Translate VT-UTF8 characters into one Unicode character.
1331 Bits per Character | Unicode Character Range | Unicode Binary Encoding | UTF8 Binary Encoding
1332 0-7 | 0x0000 - 0x007F | 00000000 0xxxxxxx | 0xxxxxxx
1333 8-11 | 0x0080 - 0x07FF | 00000xxx xxxxxxxx | 110xxxxx 10xxxxxx
1334 12-16 | 0x0800 - 0xFFFF | xxxxxxxx xxxxxxxx | 1110xxxx 10xxxxxx 10xxxxxx
1337 @param Utf8Char VT-UTF8 character set needs translating.
1338 @param ValidBytes The count of valid VT-UTF8 characters.
1339 @param UnicodeChar Returned unicode character.
1344 IN UTF8_CHAR Utf8Char
,
1345 IN UINT8 ValidBytes
,
1346 OUT CHAR16
*UnicodeChar
1350 // functions for boxdraw unicode
1354 Detects if a Unicode char is for Box Drawing text graphics.
1356 @param Graphic Unicode char to test.
1357 @param PcAnsi Optional pointer to return PCANSI equivalent of
1359 @param Ascii Optional pointer to return ASCII equivalent of
1362 @retval TRUE If Graphic is a supported Unicode Box Drawing character.
1366 TerminalIsValidTextGraphics (
1368 OUT CHAR8
*PcAnsi
, OPTIONAL
1369 OUT CHAR8
*Ascii OPTIONAL
1373 Detects if a valid ASCII char.
1375 @param Ascii An ASCII character.
1377 @retval TRUE If it is a valid ASCII character.
1378 @retval FALSE If it is not a valid ASCII character.
1382 TerminalIsValidAscii (
1387 Detects if a valid EFI control character.
1389 @param CharC An input EFI Control character.
1391 @retval TRUE If it is a valid EFI control character.
1392 @retval FALSE If it is not a valid EFI control character.
1396 TerminalIsValidEfiCntlChar (
1401 Check if the device supports hot-plug through its device path.
1403 This function could be updated to check more types of Hot Plug devices.
1404 Currently, it checks USB and PCCard device.
1406 @param DevicePath Pointer to device's device path.
1408 @retval TRUE The devcie is a hot-plug device
1409 @retval FALSE The devcie is not a hot-plug device.
1414 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1418 Timer handler to poll the key from serial.
1420 @param Event Indicates the event that invoke this function.
1421 @param Context Indicates the calling context.
1425 TerminalConInTimerHandler (
1434 @param Event Indicates the event that invoke this function.
1435 @param Context Indicates the calling context.
1439 KeyNotifyProcessHandler (