2 Header file for Terminal driver.
4 Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 #include <Guid/GlobalVariable.h>
22 #include <Guid/PcAnsi.h>
23 #include <Guid/TtyTerm.h>
24 #include <Guid/StatusCodeDataTypeVariable.h>
26 #include <Protocol/SimpleTextOut.h>
27 #include <Protocol/SerialIo.h>
28 #include <Protocol/DevicePath.h>
29 #include <Protocol/SimpleTextIn.h>
30 #include <Protocol/SimpleTextInEx.h>
32 #include <Library/DebugLib.h>
33 #include <Library/UefiDriverEntryPoint.h>
34 #include <Library/UefiLib.h>
35 #include <Library/ReportStatusCodeLib.h>
36 #include <Library/BaseMemoryLib.h>
37 #include <Library/MemoryAllocationLib.h>
38 #include <Library/UefiBootServicesTableLib.h>
39 #include <Library/UefiRuntimeServicesTableLib.h>
40 #include <Library/DevicePathLib.h>
41 #include <Library/PcdLib.h>
42 #include <Library/BaseLib.h>
45 #define RAW_FIFO_MAX_NUMBER 256
46 #define FIFO_MAX_NUMBER 128
51 UINT8 Data
[RAW_FIFO_MAX_NUMBER
+ 1];
57 UINT16 Data
[FIFO_MAX_NUMBER
+ 1];
63 EFI_INPUT_KEY Data
[FIFO_MAX_NUMBER
+ 1];
69 } TERMINAL_CONSOLE_MODE_DATA
;
71 #define KEYBOARD_TIMER_INTERVAL 200000 // 0.02s
73 #define TERMINAL_DEV_SIGNATURE SIGNATURE_32 ('t', 'm', 'n', 'l')
75 #define TERMINAL_CONSOLE_IN_EX_NOTIFY_SIGNATURE SIGNATURE_32 ('t', 'm', 'e', 'n')
77 typedef struct _TERMINAL_CONSOLE_IN_EX_NOTIFY
{
80 EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn
;
81 LIST_ENTRY NotifyEntry
;
82 } TERMINAL_CONSOLE_IN_EX_NOTIFY
;
87 EFI_SERIAL_IO_PROTOCOL
*SerialIo
;
88 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
89 EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleInput
;
90 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL SimpleTextOutput
;
91 EFI_SIMPLE_TEXT_OUTPUT_MODE SimpleTextOutputMode
;
92 TERMINAL_CONSOLE_MODE_DATA
*TerminalConsoleModeData
;
93 UINTN SerialInTimeOut
;
94 RAW_DATA_FIFO
*RawFiFo
;
95 UNICODE_FIFO
*UnicodeFiFo
;
96 EFI_KEY_FIFO
*EfiKeyFiFo
;
97 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
99 EFI_EVENT TwoSecondTimeOut
;
102 UINT16 TtyEscapeStr
[3];
106 // Esc could not be output to the screen by user,
107 // but the terminal driver need to output it to
108 // the terminal emulation software to send control sequence.
109 // This boolean is used by the terminal driver only
110 // to indicate whether the Esc could be sent or not.
112 BOOLEAN OutputEscChar
;
113 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL SimpleInputEx
;
114 LIST_ENTRY NotifyList
;
117 #define INPUT_STATE_DEFAULT 0x00
118 #define INPUT_STATE_ESC 0x01
119 #define INPUT_STATE_CSI 0x02
120 #define INPUT_STATE_LEFTOPENBRACKET 0x04
121 #define INPUT_STATE_O 0x08
122 #define INPUT_STATE_2 0x10
123 #define INPUT_STATE_LEFTOPENBRACKET_2 0x20
125 #define RESET_STATE_DEFAULT 0x00
126 #define RESET_STATE_ESC_R 0x01
127 #define RESET_STATE_ESC_R_ESC_R 0x02
129 #define TERMINAL_CON_IN_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleInput, TERMINAL_DEV_SIGNATURE)
130 #define TERMINAL_CON_OUT_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleTextOutput, TERMINAL_DEV_SIGNATURE)
131 #define TERMINAL_CON_IN_EX_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleInputEx, TERMINAL_DEV_SIGNATURE)
141 #define VT100PLUSTYPE 2
143 #define TTYTERMTYPE 4
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
170 extern EFI_DRIVER_BINDING_PROTOCOL gTerminalDriverBinding
;
171 extern EFI_COMPONENT_NAME_PROTOCOL gTerminalComponentName
;
172 extern EFI_COMPONENT_NAME2_PROTOCOL gTerminalComponentName2
;
175 The user Entry Point for module Terminal. The user code starts with this function.
177 @param[in] ImageHandle The firmware allocated handle for the EFI image.
178 @param[in] SystemTable A pointer to the EFI System Table.
180 @retval EFI_SUCCESS The entry point is executed successfully.
181 @retval other Some error occurs when executing this entry point.
187 IN EFI_HANDLE ImageHandle
,
188 IN EFI_SYSTEM_TABLE
*SystemTable
192 Implements EFI_SIMPLE_TEXT_INPUT_PROTOCOL.Reset().
193 This driver only perform dependent serial device reset regardless of
194 the value of ExtendeVerification
196 @param This Indicates the calling context.
197 @param ExtendedVerification Skip by this driver.
199 @retval EFI_SUCCESS The reset operation succeeds.
200 @retval EFI_DEVICE_ERROR The dependent serial port reset fails.
206 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
207 IN BOOLEAN ExtendedVerification
212 Implements EFI_SIMPLE_TEXT_INPUT_PROTOCOL.ReadKeyStroke().
214 @param This Indicates the calling context.
215 @param Key A pointer to a buffer that is filled in with the
216 keystroke information for the key that was sent
219 @retval EFI_SUCCESS The keystroke information is returned successfully.
220 @retval EFI_NOT_READY There is no keystroke data available.
221 @retval EFI_DEVICE_ERROR The dependent serial device encounters error.
226 TerminalConInReadKeyStroke (
227 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
228 OUT EFI_INPUT_KEY
*Key
232 Check if the key already has been registered.
234 @param RegsiteredData A pointer to a buffer that is filled in with the
235 keystroke state data for the key that was
237 @param InputData A pointer to a buffer that is filled in with the
238 keystroke state data for the key that was
241 @retval TRUE Key be pressed matches a registered key.
242 @retval FALSE Match failed.
247 IN EFI_KEY_DATA
*RegsiteredData
,
248 IN EFI_KEY_DATA
*InputData
252 Event notification function for EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx event
253 Signal the event if there is key available
255 @param Event Indicates the event that invoke this function.
256 @param Context Indicates the calling context.
261 TerminalConInWaitForKeyEx (
267 // Simple Text Input Ex protocol prototypes
271 Reset the input device and optionally run diagnostics
273 @param This Protocol instance pointer.
274 @param ExtendedVerification Driver may perform diagnostics on reset.
276 @retval EFI_SUCCESS The device was reset.
277 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
283 TerminalConInResetEx (
284 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
285 IN BOOLEAN ExtendedVerification
289 Reads the next keystroke from the input device. The WaitForKey Event can
290 be used to test for existence of a keystroke via WaitForEvent () call.
292 @param This Protocol instance pointer.
293 @param KeyData A pointer to a buffer that is filled in with the
294 keystroke state data for the key that was
297 @retval EFI_SUCCESS The keystroke information was returned.
298 @retval EFI_NOT_READY There was no keystroke data available.
299 @retval EFI_DEVICE_ERROR The keystroke information was not returned due
301 @retval EFI_INVALID_PARAMETER KeyData is NULL.
306 TerminalConInReadKeyStrokeEx (
307 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
308 OUT EFI_KEY_DATA
*KeyData
312 Set certain state for the input device.
314 @param This Protocol instance pointer.
315 @param KeyToggleState A pointer to the EFI_KEY_TOGGLE_STATE to set the
316 state for the input device.
318 @retval EFI_SUCCESS The device state was set successfully.
319 @retval EFI_DEVICE_ERROR The device is not functioning correctly and
320 could not have the setting adjusted.
321 @retval EFI_UNSUPPORTED The device does not have the ability to set its
323 @retval EFI_INVALID_PARAMETER KeyToggleState is NULL.
328 TerminalConInSetState (
329 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
330 IN EFI_KEY_TOGGLE_STATE
*KeyToggleState
334 Register a notification function for a particular keystroke for the input device.
336 @param This Protocol instance pointer.
337 @param KeyData A pointer to a buffer that is filled in with the
338 keystroke information data for the key that was
340 @param KeyNotificationFunction Points to the function to be called when the key
341 sequence is typed specified by KeyData.
342 @param NotifyHandle Points to the unique handle assigned to the
343 registered notification.
345 @retval EFI_SUCCESS The notification function was registered
347 @retval EFI_OUT_OF_RESOURCES Unable to allocate resources for necesssary data
349 @retval EFI_INVALID_PARAMETER KeyData or NotifyHandle is NULL.
354 TerminalConInRegisterKeyNotify (
355 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
356 IN EFI_KEY_DATA
*KeyData
,
357 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction
,
358 OUT VOID
**NotifyHandle
362 Remove a registered notification function from a particular keystroke.
364 @param This Protocol instance pointer.
365 @param NotificationHandle The handle of the notification function being
368 @retval EFI_SUCCESS The notification function was unregistered
370 @retval EFI_INVALID_PARAMETER The NotificationHandle is invalid.
371 @retval EFI_NOT_FOUND Can not find the matching entry in database.
376 TerminalConInUnregisterKeyNotify (
377 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
378 IN VOID
*NotificationHandle
382 Event notification function for EFI_SIMPLE_TEXT_INPUT_PROTOCOL.WaitForKey event
383 Signal the event if there is key available
385 @param Event Indicates the event that invoke this function.
386 @param Context Indicates the calling context.
391 TerminalConInWaitForKey (
397 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset().
398 If ExtendeVerification is TRUE, then perform dependent serial device reset,
399 and set display mode to mode 0.
400 If ExtendedVerification is FALSE, only set display mode to mode 0.
402 @param This Indicates the calling context.
403 @param ExtendedVerification Indicates that the driver may perform a more
404 exhaustive verification operation of the device
407 @retval EFI_SUCCESS The reset operation succeeds.
408 @retval EFI_DEVICE_ERROR The terminal is not functioning correctly or the serial port reset fails.
413 TerminalConOutReset (
414 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
415 IN BOOLEAN ExtendedVerification
419 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString().
420 The Unicode string will be converted to terminal expressible data stream
421 and send to terminal via serial port.
423 @param This Indicates the calling context.
424 @param WString The Null-terminated Unicode string to be displayed
425 on the terminal screen.
427 @retval EFI_SUCCESS The string is output successfully.
428 @retval EFI_DEVICE_ERROR The serial port fails to send the string out.
429 @retval EFI_WARN_UNKNOWN_GLYPH Indicates that some of the characters in the Unicode string could not
430 be rendered and are skipped.
431 @retval EFI_UNSUPPORTED If current display mode is out of range.
436 TerminalConOutOutputString (
437 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
442 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.TestString().
443 If one of the characters in the *Wstring is
444 neither valid Unicode drawing characters,
445 not ASCII code, then this function will return
448 @param This Indicates the calling context.
449 @param WString The Null-terminated Unicode string to be tested.
451 @retval EFI_SUCCESS The terminal is capable of rendering the output string.
452 @retval EFI_UNSUPPORTED Some of the characters in the Unicode string cannot be rendered.
457 TerminalConOutTestString (
458 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
463 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.QueryMode().
464 It returns information for an available text mode
465 that the terminal supports.
466 In this driver, we support text mode 80x25 (mode 0),
467 80x50 (mode 1), 100x31 (mode 2).
469 @param This Indicates the calling context.
470 @param ModeNumber The mode number to return information on.
471 @param Columns The returned columns of the requested mode.
472 @param Rows The returned rows of the requested mode.
474 @retval EFI_SUCCESS The requested mode information is returned.
475 @retval EFI_UNSUPPORTED The mode number is not valid.
476 @retval EFI_DEVICE_ERROR
481 TerminalConOutQueryMode (
482 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
489 Implements EFI_SIMPLE_TEXT_OUT.SetMode().
490 Set the terminal to a specified display mode.
491 In this driver, we only support mode 0.
493 @param This Indicates the calling context.
494 @param ModeNumber The text mode to set.
496 @retval EFI_SUCCESS The requested text mode is set.
497 @retval EFI_DEVICE_ERROR The requested text mode cannot be set
498 because of serial device error.
499 @retval EFI_UNSUPPORTED The text mode number is not valid.
504 TerminalConOutSetMode (
505 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
510 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetAttribute().
512 @param This Indicates the calling context.
513 @param Attribute The attribute to set. Only bit0..6 are valid, all other bits
514 are undefined and must be zero.
516 @retval EFI_SUCCESS The requested attribute is set.
517 @retval EFI_DEVICE_ERROR The requested attribute cannot be set due to serial port error.
518 @retval EFI_UNSUPPORTED The attribute requested is not defined by EFI spec.
523 TerminalConOutSetAttribute (
524 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
529 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.ClearScreen().
530 It clears the ANSI terminal's display to the
531 currently selected background color.
533 @param This Indicates the calling context.
535 @retval EFI_SUCCESS The operation completed successfully.
536 @retval EFI_DEVICE_ERROR The terminal screen cannot be cleared due to serial port error.
537 @retval EFI_UNSUPPORTED The terminal is not in a valid display mode.
542 TerminalConOutClearScreen (
543 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
547 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetCursorPosition().
549 @param This Indicates the calling context.
550 @param Column The row to set cursor to.
551 @param Row The column to set cursor to.
553 @retval EFI_SUCCESS The operation completed successfully.
554 @retval EFI_DEVICE_ERROR The request fails due to serial port error.
555 @retval EFI_UNSUPPORTED The terminal is not in a valid text mode, or the cursor position
556 is invalid for current mode.
561 TerminalConOutSetCursorPosition (
562 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
568 Implements SIMPLE_TEXT_OUTPUT.EnableCursor().
569 In this driver, the cursor cannot be hidden.
571 @param This Indicates the calling context.
572 @param Visible If TRUE, the cursor is set to be visible,
573 If FALSE, the cursor is set to be invisible.
575 @retval EFI_SUCCESS The request is valid.
576 @retval EFI_UNSUPPORTED The terminal does not support cursor hidden.
581 TerminalConOutEnableCursor (
582 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
587 Test to see if this driver supports Controller.
589 @param This Protocol instance pointer.
590 @param ControllerHandle Handle of device to test
591 @param RemainingDevicePath Optional parameter use to pick a specific child
594 @retval EFI_SUCCESS This driver supports this device.
595 @retval EFI_ALREADY_STARTED This driver is already running on this device.
596 @retval other This driver does not support this device.
601 TerminalDriverBindingSupported (
602 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
603 IN EFI_HANDLE ControllerHandle
,
604 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
608 Start this driver on Controller by opening a Serial IO protocol,
609 reading Device Path, and creating a child handle with a Simple Text In,
610 Simple Text In Ex and Simple Text Out protocol, and device path protocol.
611 And store Console Device Environment Variables.
613 @param This Protocol instance pointer.
614 @param Controller Handle of device to bind driver to
615 @param RemainingDevicePath Optional parameter use to pick a specific child
618 @retval EFI_SUCCESS This driver is added to Controller.
619 @retval EFI_ALREADY_STARTED This driver is already running on Controller.
620 @retval other This driver does not support this device.
625 TerminalDriverBindingStart (
626 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
627 IN EFI_HANDLE Controller
,
628 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
633 Stop this driver on Controller by closing Simple Text In, Simple Text
634 In Ex, Simple Text Out protocol, and removing parent device path from
635 Console Device Environment Variables.
637 @param This Protocol instance pointer.
638 @param Controller Handle of device to stop driver on
639 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
640 children is zero stop the entire bus driver.
641 @param ChildHandleBuffer List of Child Handles to Stop.
643 @retval EFI_SUCCESS This driver is removed Controller.
644 @retval other This driver could not be removed from this device.
649 TerminalDriverBindingStop (
650 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
651 IN EFI_HANDLE Controller
,
652 IN UINTN NumberOfChildren
,
653 IN EFI_HANDLE
*ChildHandleBuffer
657 Free notify functions list.
659 @param ListHead The list head
661 @retval EFI_SUCCESS Free the notify list successfully.
662 @retval EFI_INVALID_PARAMETER ListHead is NULL.
666 TerminalFreeNotifyList (
667 IN OUT LIST_ENTRY
*ListHead
671 Retrieves a Unicode string that is the user readable name of the driver.
673 This function retrieves the user readable name of a driver in the form of a
674 Unicode string. If the driver specified by This has a user readable name in
675 the language specified by Language, then a pointer to the driver name is
676 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
677 by This does not support the language specified by Language,
678 then EFI_UNSUPPORTED is returned.
680 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
681 EFI_COMPONENT_NAME_PROTOCOL instance.
683 @param Language[in] A pointer to a Null-terminated ASCII string
684 array indicating the language. This is the
685 language of the driver name that the caller is
686 requesting, and it must match one of the
687 languages specified in SupportedLanguages. The
688 number of languages supported by a driver is up
689 to the driver writer. Language is specified
690 in RFC 4646 or ISO 639-2 language code format.
692 @param DriverName[out] A pointer to the Unicode string to return.
693 This Unicode string is the name of the
694 driver specified by This in the language
695 specified by Language.
697 @retval EFI_SUCCESS The Unicode string for the Driver specified by
698 This and the language specified by Language was
699 returned in DriverName.
701 @retval EFI_INVALID_PARAMETER Language is NULL.
703 @retval EFI_INVALID_PARAMETER DriverName is NULL.
705 @retval EFI_UNSUPPORTED The driver specified by This does not support
706 the language specified by Language.
711 TerminalComponentNameGetDriverName (
712 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
714 OUT CHAR16
**DriverName
719 Retrieves a Unicode string that is the user readable name of the controller
720 that is being managed by a driver.
722 This function retrieves the user readable name of the controller specified by
723 ControllerHandle and ChildHandle in the form of a Unicode string. If the
724 driver specified by This has a user readable name in the language specified by
725 Language, then a pointer to the controller name is returned in ControllerName,
726 and EFI_SUCCESS is returned. If the driver specified by This is not currently
727 managing the controller specified by ControllerHandle and ChildHandle,
728 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
729 support the language specified by Language, then EFI_UNSUPPORTED is returned.
731 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
732 EFI_COMPONENT_NAME_PROTOCOL instance.
734 @param ControllerHandle[in] The handle of a controller that the driver
735 specified by This is managing. This handle
736 specifies the controller whose name is to be
739 @param ChildHandle[in] The handle of the child controller to retrieve
740 the name of. This is an optional parameter that
741 may be NULL. It will be NULL for device
742 drivers. It will also be NULL for a bus drivers
743 that wish to retrieve the name of the bus
744 controller. It will not be NULL for a bus
745 driver that wishes to retrieve the name of a
748 @param Language[in] A pointer to a Null-terminated ASCII string
749 array indicating the language. This is the
750 language of the driver name that the caller is
751 requesting, and it must match one of the
752 languages specified in SupportedLanguages. The
753 number of languages supported by a driver is up
754 to the driver writer. Language is specified in
755 RFC 4646 or ISO 639-2 language code format.
757 @param ControllerName[out] A pointer to the Unicode string to return.
758 This Unicode string is the name of the
759 controller specified by ControllerHandle and
760 ChildHandle in the language specified by
761 Language from the point of view of the driver
764 @retval EFI_SUCCESS The Unicode string for the user readable name in
765 the language specified by Language for the
766 driver specified by This was returned in
769 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
771 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
774 @retval EFI_INVALID_PARAMETER Language is NULL.
776 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
778 @retval EFI_UNSUPPORTED The driver specified by This is not currently
779 managing the controller specified by
780 ControllerHandle and ChildHandle.
782 @retval EFI_UNSUPPORTED The driver specified by This does not support
783 the language specified by Language.
788 TerminalComponentNameGetControllerName (
789 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
790 IN EFI_HANDLE ControllerHandle
,
791 IN EFI_HANDLE ChildHandle OPTIONAL
,
793 OUT CHAR16
**ControllerName
798 // internal functions
802 Check for a pending key in the Efi Key FIFO or Serial device buffer.
804 @param This Indicates the calling context.
806 @retval EFI_SUCCESS There is key pending.
807 @retval EFI_NOT_READY There is no key pending.
808 @retval EFI_DEVICE_ERROR If Serial IO is not attached to serial device.
812 TerminalConInCheckForKey (
813 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
817 Update terminal device path in Console Device Environment Variables.
819 @param VariableName The Console Device Environment Variable.
820 @param ParentDevicePath The terminal device path to be updated.
826 TerminalUpdateConsoleDevVariable (
827 IN CHAR16
*VariableName
,
828 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
832 Remove console device variable.
834 @param VariableName A pointer to the variable name.
835 @param ParentDevicePath A pointer to the parent device path.
839 TerminalRemoveConsoleDevVariable (
840 IN CHAR16
*VariableName
,
841 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
845 Build termial device path according to terminal type.
847 @param TerminalType The terminal type is PC ANSI, VT100, VT100+ or VT-UTF8.
848 @param ParentDevicePath Parent device path.
849 @param TerminalDevicePath Returned terminal device path, if building successfully.
851 @retval EFI_UNSUPPORTED Terminal does not belong to the supported type.
852 @retval EFI_OUT_OF_RESOURCES Generate terminal device path failed.
853 @retval EFI_SUCCESS Build terminal device path successfully.
857 SetTerminalDevicePath (
858 IN UINT8 TerminalType
,
859 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
860 OUT EFI_DEVICE_PATH_PROTOCOL
**TerminalDevicePath
864 Get one key out of serial buffer.
866 @param SerialIo Serial I/O protocl attached to the serial device.
867 @param Input The fetched key.
869 @retval EFI_NOT_READY If serial buffer is empty.
870 @retval EFI_DEVICE_ERROR If reading serial buffer encounter error.
871 @retval EFI_SUCCESS If reading serial buffer successfully, put
872 the fetched key to the parameter output.
876 GetOneKeyFromSerial (
877 EFI_SERIAL_IO_PROTOCOL
*SerialIo
,
882 Insert one byte raw data into the Raw Data FIFO.
884 @param TerminalDevice Terminal driver private structure.
885 @param Input The key will be input.
887 @retval TRUE If insert successfully.
888 @retval FALSE If Raw Data buffer is full before key insertion,
893 RawFiFoInsertOneKey (
894 TERMINAL_DEV
*TerminalDevice
,
899 Remove one pre-fetched key out of the Raw Data FIFO.
901 @param TerminalDevice Terminal driver private structure.
902 @param Output The key will be removed.
904 @retval TRUE If insert successfully.
905 @retval FALSE If Raw Data FIFO buffer is empty before remove operation.
909 RawFiFoRemoveOneKey (
910 TERMINAL_DEV
*TerminalDevice
,
915 Clarify whether Raw Data FIFO buffer is empty.
917 @param TerminalDevice Terminal driver private structure
919 @retval TRUE If Raw Data FIFO buffer is empty.
920 @retval FALSE If Raw Data FIFO buffer is not empty.
925 TERMINAL_DEV
*TerminalDevice
929 Clarify whether Raw Data FIFO buffer is full.
931 @param TerminalDevice Terminal driver private structure
933 @retval TRUE If Raw Data FIFO buffer is full.
934 @retval FALSE If Raw Data FIFO buffer is not full.
939 TERMINAL_DEV
*TerminalDevice
943 Insert one pre-fetched key into the FIFO buffer.
945 @param TerminalDevice Terminal driver private structure.
946 @param Key The key will be input.
948 @retval TRUE If insert successfully.
949 @retval FALSE If FIFO buffer is full before key insertion,
954 EfiKeyFiFoInsertOneKey (
955 TERMINAL_DEV
*TerminalDevice
,
960 Remove one pre-fetched key out of the FIFO buffer.
962 @param TerminalDevice Terminal driver private structure.
963 @param Output The key will be removed.
965 @retval TRUE If insert successfully.
966 @retval FALSE If FIFO buffer is empty before remove operation.
970 EfiKeyFiFoRemoveOneKey (
971 TERMINAL_DEV
*TerminalDevice
,
972 EFI_INPUT_KEY
*Output
976 Clarify whether FIFO buffer is empty.
978 @param TerminalDevice Terminal driver private structure
980 @retval TRUE If FIFO buffer is empty.
981 @retval FALSE If FIFO buffer is not empty.
986 TERMINAL_DEV
*TerminalDevice
990 Clarify whether FIFO buffer is full.
992 @param TerminalDevice Terminal driver private structure
994 @retval TRUE If FIFO buffer is full.
995 @retval FALSE If FIFO buffer is not full.
1000 TERMINAL_DEV
*TerminalDevice
1004 Insert one pre-fetched key into the Unicode FIFO buffer.
1006 @param TerminalDevice Terminal driver private structure.
1007 @param Input The key will be input.
1009 @retval TRUE If insert successfully.
1010 @retval FALSE If Unicode FIFO buffer is full before key insertion,
1011 and the key is lost.
1015 UnicodeFiFoInsertOneKey (
1016 TERMINAL_DEV
*TerminalDevice
,
1021 Remove one pre-fetched key out of the Unicode FIFO buffer.
1022 The caller should guarantee that Unicode FIFO buffer is not empty
1023 by IsUnicodeFiFoEmpty ().
1025 @param TerminalDevice Terminal driver private structure.
1026 @param Output The key will be removed.
1030 UnicodeFiFoRemoveOneKey (
1031 TERMINAL_DEV
*TerminalDevice
,
1036 Clarify whether Unicode FIFO buffer is empty.
1038 @param TerminalDevice Terminal driver private structure
1040 @retval TRUE If Unicode FIFO buffer is empty.
1041 @retval FALSE If Unicode FIFO buffer is not empty.
1045 IsUnicodeFiFoEmpty (
1046 TERMINAL_DEV
*TerminalDevice
1050 Clarify whether Unicode FIFO buffer is full.
1052 @param TerminalDevice Terminal driver private structure
1054 @retval TRUE If Unicode FIFO buffer is full.
1055 @retval FALSE If Unicode FIFO buffer is not full.
1060 TERMINAL_DEV
*TerminalDevice
1064 Count Unicode FIFO buffer.
1066 @param TerminalDevice Terminal driver private structure
1068 @return The count in bytes of Unicode FIFO.
1072 UnicodeFiFoGetKeyCount (
1073 TERMINAL_DEV
*TerminalDevice
1077 Translate raw data into Unicode (according to different encode), and
1078 translate Unicode into key information. (according to different standard).
1080 @param TerminalDevice Terminal driver private structure.
1084 TranslateRawDataToEfiKey (
1085 IN TERMINAL_DEV
*TerminalDevice
1089 // internal functions for PC ANSI
1093 Translate all raw data in the Raw FIFI into unicode, and insert
1094 them into Unicode FIFO.
1096 @param TerminalDevice The terminal device.
1100 AnsiRawDataToUnicode (
1101 IN TERMINAL_DEV
*TerminalDevice
1105 Converts a stream of Unicode characters from a terminal input device into EFI Keys that
1106 can be read through the Simple Input Protocol.
1108 The table below shows the keyboard input mappings that this function supports.
1109 If the ESC sequence listed in one of the columns is presented, then it is translated
1110 into the coorespoding EFI Scan Code. If a matching sequence is not found, then the raw
1111 key strokes are converted into EFI Keys.
1113 2 seconds are allowed for an ESC sequence to be completed. If the ESC sequence is not
1114 completed in 2 seconds, then the raw key strokes of the partial ESC sequence are
1115 converted into EFI Keys.
1116 There is one special input sequence that will force the system to reset.
1117 This is ESC R ESC r ESC R.
1119 Symbols used in table below
1120 ===========================
1125 +=========+======+===========+==========+==========+
1126 | | EFI | UEFI 2.0 | | |
1127 | | Scan | | VT100+ | |
1128 | KEY | Code | PC ANSI | VTUTF8 | VT100 |
1129 +=========+======+===========+==========+==========+
1130 | NULL | 0x00 | | | |
1131 | UP | 0x01 | ESC [ A | ESC [ A | ESC [ A |
1132 | DOWN | 0x02 | ESC [ B | ESC [ B | ESC [ B |
1133 | RIGHT | 0x03 | ESC [ C | ESC [ C | ESC [ C |
1134 | LEFT | 0x04 | ESC [ D | ESC [ D | ESC [ D |
1135 | HOME | 0x05 | ESC [ H | ESC h | ESC [ H |
1136 | END | 0x06 | ESC [ F | ESC k | ESC [ K |
1137 | INSERT | 0x07 | ESC [ @ | ESC + | ESC [ @ |
1138 | | | ESC [ L | | ESC [ L |
1139 | DELETE | 0x08 | ESC [ X | ESC - | ESC [ P |
1140 | PG UP | 0x09 | ESC [ I | ESC ? | ESC [ V |
1142 | PG DOWN | 0x0A | ESC [ G | ESC / | ESC [ U |
1144 | F1 | 0x0B | ESC [ M | ESC 1 | ESC O P |
1145 | F2 | 0x0C | ESC [ N | ESC 2 | ESC O Q |
1146 | F3 | 0x0D | ESC [ O | ESC 3 | ESC O w |
1147 | F4 | 0x0E | ESC [ P | ESC 4 | ESC O x |
1148 | F5 | 0x0F | ESC [ Q | ESC 5 | ESC O t |
1149 | F6 | 0x10 | ESC [ R | ESC 6 | ESC O u |
1150 | F7 | 0x11 | ESC [ S | ESC 7 | ESC O q |
1151 | F8 | 0x12 | ESC [ T | ESC 8 | ESC O r |
1152 | F9 | 0x13 | ESC [ U | ESC 9 | ESC O p |
1153 | F10 | 0x14 | ESC [ V | ESC 0 | ESC O M |
1154 | Escape | 0x17 | ESC | ESC | ESC |
1155 | F11 | 0x15 | | ESC ! | |
1156 | F12 | 0x16 | | ESC @ | |
1157 +=========+======+===========+==========+==========+
1161 ESC R ESC r ESC R = Reset System
1164 @param TerminalDevice The terminal device to use to translate raw input into EFI Keys
1169 IN TERMINAL_DEV
*TerminalDevice
1173 Check if input string is valid Ascii string, valid EFI control characters
1174 or valid text graphics.
1176 @param TerminalDevice The terminal device.
1177 @param WString The input string.
1179 @retval EFI_UNSUPPORTED If not all input characters are valid.
1180 @retval EFI_SUCCESS If all input characters are valid.
1185 IN TERMINAL_DEV
*TerminalDevice
,
1190 // internal functions for VTUTF8
1194 Translate all VT-UTF8 characters in the Raw FIFI into unicode characters,
1195 and insert them into Unicode FIFO.
1197 @param VtUtf8Device The terminal device.
1201 VTUTF8RawDataToUnicode (
1202 IN TERMINAL_DEV
*VtUtf8Device
1206 Check if input string is valid VT-UTF8 string.
1208 @param TerminalDevice The terminal device.
1209 @param WString The input string.
1211 @retval EFI_SUCCESS If all input characters are valid.
1216 IN TERMINAL_DEV
*TerminalDevice
,
1221 Translate one Unicode character into VT-UTF8 characters.
1224 Bits per Character | Unicode Character Range | Unicode Binary Encoding | UTF8 Binary Encoding
1225 0-7 | 0x0000 - 0x007F | 00000000 0xxxxxxx | 0xxxxxxx
1226 8-11 | 0x0080 - 0x07FF | 00000xxx xxxxxxxx | 110xxxxx 10xxxxxx
1227 12-16 | 0x0800 - 0xFFFF | xxxxxxxx xxxxxxxx | 1110xxxx 10xxxxxx 10xxxxxx
1230 @param Unicode Unicode character need translating.
1231 @param Utf8Char Return VT-UTF8 character set.
1232 @param ValidBytes The count of valid VT-UTF8 characters. If
1233 ValidBytes is zero, no valid VT-UTF8 returned.
1239 OUT UTF8_CHAR
*Utf8Char
,
1240 OUT UINT8
*ValidBytes
1244 Get one valid VT-UTF8 characters set from Raw Data FIFO.
1246 @param Utf8Device The terminal device.
1247 @param Utf8Char Returned valid VT-UTF8 characters set.
1248 @param ValidBytes The count of returned VT-VTF8 characters.
1249 If ValidBytes is zero, no valid VT-UTF8 returned.
1253 GetOneValidUtf8Char (
1254 IN TERMINAL_DEV
*Utf8Device
,
1255 OUT UTF8_CHAR
*Utf8Char
,
1256 OUT UINT8
*ValidBytes
1260 Translate VT-UTF8 characters into one Unicode character.
1263 Bits per Character | Unicode Character Range | Unicode Binary Encoding | UTF8 Binary Encoding
1264 0-7 | 0x0000 - 0x007F | 00000000 0xxxxxxx | 0xxxxxxx
1265 8-11 | 0x0080 - 0x07FF | 00000xxx xxxxxxxx | 110xxxxx 10xxxxxx
1266 12-16 | 0x0800 - 0xFFFF | xxxxxxxx xxxxxxxx | 1110xxxx 10xxxxxx 10xxxxxx
1269 @param Utf8Char VT-UTF8 character set needs translating.
1270 @param ValidBytes The count of valid VT-UTF8 characters.
1271 @param UnicodeChar Returned unicode character.
1276 IN UTF8_CHAR Utf8Char
,
1277 IN UINT8 ValidBytes
,
1278 OUT CHAR16
*UnicodeChar
1282 // functions for boxdraw unicode
1286 Detects if a Unicode char is for Box Drawing text graphics.
1288 @param Graphic Unicode char to test.
1289 @param PcAnsi Optional pointer to return PCANSI equivalent of
1291 @param Ascii Optional pointer to return ASCII equivalent of
1294 @retval TRUE If Graphic is a supported Unicode Box Drawing character.
1298 TerminalIsValidTextGraphics (
1300 OUT CHAR8
*PcAnsi
, OPTIONAL
1301 OUT CHAR8
*Ascii OPTIONAL
1305 Detects if a valid ASCII char.
1307 @param Ascii An ASCII character.
1309 @retval TRUE If it is a valid ASCII character.
1310 @retval FALSE If it is not a valid ASCII character.
1314 TerminalIsValidAscii (
1319 Detects if a valid EFI control character.
1321 @param CharC An input EFI Control character.
1323 @retval TRUE If it is a valid EFI control character.
1324 @retval FALSE If it is not a valid EFI control character.
1328 TerminalIsValidEfiCntlChar (
1333 Check if the device supports hot-plug through its device path.
1335 This function could be updated to check more types of Hot Plug devices.
1336 Currently, it checks USB and PCCard device.
1338 @param DevicePath Pointer to device's device path.
1340 @retval TRUE The devcie is a hot-plug device
1341 @retval FALSE The devcie is not a hot-plug device.
1346 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1350 Timer handler to poll the key from serial.
1352 @param Event Indicates the event that invoke this function.
1353 @param Context Indicates the calling context.
1357 TerminalConInTimerHandler (