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 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
346 pressed. If KeyData.Key, KeyData.KeyState.KeyToggleState
347 and KeyData.KeyState.KeyShiftState are 0, then any incomplete
348 keystroke will trigger a notification of the KeyNotificationFunction.
349 @param KeyNotificationFunction Points to the function to be called when the key
350 sequence is typed specified by KeyData. This notification function
351 should be called at <=TPL_CALLBACK.
352 @param NotifyHandle Points to the unique handle assigned to the
353 registered notification.
355 @retval EFI_SUCCESS The notification function was registered
357 @retval EFI_OUT_OF_RESOURCES Unable to allocate resources for necesssary data
359 @retval EFI_INVALID_PARAMETER KeyData or NotifyHandle is NULL.
364 TerminalConInRegisterKeyNotify (
365 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
366 IN EFI_KEY_DATA
*KeyData
,
367 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction
,
368 OUT VOID
**NotifyHandle
372 Remove a registered notification function from a particular keystroke.
374 @param This Protocol instance pointer.
375 @param NotificationHandle The handle of the notification function being
378 @retval EFI_SUCCESS The notification function was unregistered
380 @retval EFI_INVALID_PARAMETER The NotificationHandle is invalid.
381 @retval EFI_NOT_FOUND Can not find the matching entry in database.
386 TerminalConInUnregisterKeyNotify (
387 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
388 IN VOID
*NotificationHandle
392 Event notification function for EFI_SIMPLE_TEXT_INPUT_PROTOCOL.WaitForKey event
393 Signal the event if there is key available
395 @param Event Indicates the event that invoke this function.
396 @param Context Indicates the calling context.
401 TerminalConInWaitForKey (
407 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset().
408 If ExtendeVerification is TRUE, then perform dependent serial device reset,
409 and set display mode to mode 0.
410 If ExtendedVerification is FALSE, only set display mode to mode 0.
412 @param This Indicates the calling context.
413 @param ExtendedVerification Indicates that the driver may perform a more
414 exhaustive verification operation of the device
417 @retval EFI_SUCCESS The reset operation succeeds.
418 @retval EFI_DEVICE_ERROR The terminal is not functioning correctly or the serial port reset fails.
423 TerminalConOutReset (
424 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
425 IN BOOLEAN ExtendedVerification
429 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString().
430 The Unicode string will be converted to terminal expressible data stream
431 and send to terminal via serial port.
433 @param This Indicates the calling context.
434 @param WString The Null-terminated Unicode string to be displayed
435 on the terminal screen.
437 @retval EFI_SUCCESS The string is output successfully.
438 @retval EFI_DEVICE_ERROR The serial port fails to send the string out.
439 @retval EFI_WARN_UNKNOWN_GLYPH Indicates that some of the characters in the Unicode string could not
440 be rendered and are skipped.
441 @retval EFI_UNSUPPORTED If current display mode is out of range.
446 TerminalConOutOutputString (
447 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
452 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.TestString().
453 If one of the characters in the *Wstring is
454 neither valid Unicode drawing characters,
455 not ASCII code, then this function will return
458 @param This Indicates the calling context.
459 @param WString The Null-terminated Unicode string to be tested.
461 @retval EFI_SUCCESS The terminal is capable of rendering the output string.
462 @retval EFI_UNSUPPORTED Some of the characters in the Unicode string cannot be rendered.
467 TerminalConOutTestString (
468 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
473 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.QueryMode().
474 It returns information for an available text mode
475 that the terminal supports.
476 In this driver, we support text mode 80x25 (mode 0),
477 80x50 (mode 1), 100x31 (mode 2).
479 @param This Indicates the calling context.
480 @param ModeNumber The mode number to return information on.
481 @param Columns The returned columns of the requested mode.
482 @param Rows The returned rows of the requested mode.
484 @retval EFI_SUCCESS The requested mode information is returned.
485 @retval EFI_UNSUPPORTED The mode number is not valid.
486 @retval EFI_DEVICE_ERROR
491 TerminalConOutQueryMode (
492 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
499 Implements EFI_SIMPLE_TEXT_OUT.SetMode().
500 Set the terminal to a specified display mode.
501 In this driver, we only support mode 0.
503 @param This Indicates the calling context.
504 @param ModeNumber The text mode to set.
506 @retval EFI_SUCCESS The requested text mode is set.
507 @retval EFI_DEVICE_ERROR The requested text mode cannot be set
508 because of serial device error.
509 @retval EFI_UNSUPPORTED The text mode number is not valid.
514 TerminalConOutSetMode (
515 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
520 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetAttribute().
522 @param This Indicates the calling context.
523 @param Attribute The attribute to set. Only bit0..6 are valid, all other bits
524 are undefined and must be zero.
526 @retval EFI_SUCCESS The requested attribute is set.
527 @retval EFI_DEVICE_ERROR The requested attribute cannot be set due to serial port error.
528 @retval EFI_UNSUPPORTED The attribute requested is not defined by EFI spec.
533 TerminalConOutSetAttribute (
534 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
539 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.ClearScreen().
540 It clears the ANSI terminal's display to the
541 currently selected background color.
543 @param This Indicates the calling context.
545 @retval EFI_SUCCESS The operation completed successfully.
546 @retval EFI_DEVICE_ERROR The terminal screen cannot be cleared due to serial port error.
547 @retval EFI_UNSUPPORTED The terminal is not in a valid display mode.
552 TerminalConOutClearScreen (
553 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
557 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetCursorPosition().
559 @param This Indicates the calling context.
560 @param Column The row to set cursor to.
561 @param Row The column to set cursor to.
563 @retval EFI_SUCCESS The operation completed successfully.
564 @retval EFI_DEVICE_ERROR The request fails due to serial port error.
565 @retval EFI_UNSUPPORTED The terminal is not in a valid text mode, or the cursor position
566 is invalid for current mode.
571 TerminalConOutSetCursorPosition (
572 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
578 Implements SIMPLE_TEXT_OUTPUT.EnableCursor().
579 In this driver, the cursor cannot be hidden.
581 @param This Indicates the calling context.
582 @param Visible If TRUE, the cursor is set to be visible,
583 If FALSE, the cursor is set to be invisible.
585 @retval EFI_SUCCESS The request is valid.
586 @retval EFI_UNSUPPORTED The terminal does not support cursor hidden.
591 TerminalConOutEnableCursor (
592 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
597 Test to see if this driver supports Controller.
599 @param This Protocol instance pointer.
600 @param ControllerHandle Handle of device to test
601 @param RemainingDevicePath Optional parameter use to pick a specific child
604 @retval EFI_SUCCESS This driver supports this device.
605 @retval EFI_ALREADY_STARTED This driver is already running on this device.
606 @retval other This driver does not support this device.
611 TerminalDriverBindingSupported (
612 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
613 IN EFI_HANDLE ControllerHandle
,
614 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
618 Start this driver on Controller by opening a Serial IO protocol,
619 reading Device Path, and creating a child handle with a Simple Text In,
620 Simple Text In Ex and Simple Text Out protocol, and device path protocol.
621 And store Console Device Environment Variables.
623 @param This Protocol instance pointer.
624 @param Controller Handle of device to bind driver to
625 @param RemainingDevicePath Optional parameter use to pick a specific child
628 @retval EFI_SUCCESS This driver is added to Controller.
629 @retval EFI_ALREADY_STARTED This driver is already running on Controller.
630 @retval other This driver does not support this device.
635 TerminalDriverBindingStart (
636 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
637 IN EFI_HANDLE Controller
,
638 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
643 Stop this driver on Controller by closing Simple Text In, Simple Text
644 In Ex, Simple Text Out protocol, and removing parent device path from
645 Console Device Environment Variables.
647 @param This Protocol instance pointer.
648 @param Controller Handle of device to stop driver on
649 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
650 children is zero stop the entire bus driver.
651 @param ChildHandleBuffer List of Child Handles to Stop.
653 @retval EFI_SUCCESS This driver is removed Controller.
654 @retval other This driver could not be removed from this device.
659 TerminalDriverBindingStop (
660 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
661 IN EFI_HANDLE Controller
,
662 IN UINTN NumberOfChildren
,
663 IN EFI_HANDLE
*ChildHandleBuffer
667 Free notify functions list.
669 @param ListHead The list head
671 @retval EFI_SUCCESS Free the notify list successfully.
672 @retval EFI_INVALID_PARAMETER ListHead is NULL.
676 TerminalFreeNotifyList (
677 IN OUT LIST_ENTRY
*ListHead
681 Retrieves a Unicode string that is the user readable name of the driver.
683 This function retrieves the user readable name of a driver in the form of a
684 Unicode string. If the driver specified by This has a user readable name in
685 the language specified by Language, then a pointer to the driver name is
686 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
687 by This does not support the language specified by Language,
688 then EFI_UNSUPPORTED is returned.
690 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
691 EFI_COMPONENT_NAME_PROTOCOL instance.
693 @param Language[in] A pointer to a Null-terminated ASCII string
694 array indicating the language. This is the
695 language of the driver name that the caller is
696 requesting, and it must match one of the
697 languages specified in SupportedLanguages. The
698 number of languages supported by a driver is up
699 to the driver writer. Language is specified
700 in RFC 4646 or ISO 639-2 language code format.
702 @param DriverName[out] A pointer to the Unicode string to return.
703 This Unicode string is the name of the
704 driver specified by This in the language
705 specified by Language.
707 @retval EFI_SUCCESS The Unicode string for the Driver specified by
708 This and the language specified by Language was
709 returned in DriverName.
711 @retval EFI_INVALID_PARAMETER Language is NULL.
713 @retval EFI_INVALID_PARAMETER DriverName is NULL.
715 @retval EFI_UNSUPPORTED The driver specified by This does not support
716 the language specified by Language.
721 TerminalComponentNameGetDriverName (
722 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
724 OUT CHAR16
**DriverName
729 Retrieves a Unicode string that is the user readable name of the controller
730 that is being managed by a driver.
732 This function retrieves the user readable name of the controller specified by
733 ControllerHandle and ChildHandle in the form of a Unicode string. If the
734 driver specified by This has a user readable name in the language specified by
735 Language, then a pointer to the controller name is returned in ControllerName,
736 and EFI_SUCCESS is returned. If the driver specified by This is not currently
737 managing the controller specified by ControllerHandle and ChildHandle,
738 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
739 support the language specified by Language, then EFI_UNSUPPORTED is returned.
741 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
742 EFI_COMPONENT_NAME_PROTOCOL instance.
744 @param ControllerHandle[in] The handle of a controller that the driver
745 specified by This is managing. This handle
746 specifies the controller whose name is to be
749 @param ChildHandle[in] The handle of the child controller to retrieve
750 the name of. This is an optional parameter that
751 may be NULL. It will be NULL for device
752 drivers. It will also be NULL for a bus drivers
753 that wish to retrieve the name of the bus
754 controller. It will not be NULL for a bus
755 driver that wishes to retrieve the name of a
758 @param Language[in] A pointer to a Null-terminated ASCII string
759 array indicating the language. This is the
760 language of the driver name that the caller is
761 requesting, and it must match one of the
762 languages specified in SupportedLanguages. The
763 number of languages supported by a driver is up
764 to the driver writer. Language is specified in
765 RFC 4646 or ISO 639-2 language code format.
767 @param ControllerName[out] A pointer to the Unicode string to return.
768 This Unicode string is the name of the
769 controller specified by ControllerHandle and
770 ChildHandle in the language specified by
771 Language from the point of view of the driver
774 @retval EFI_SUCCESS The Unicode string for the user readable name in
775 the language specified by Language for the
776 driver specified by This was returned in
779 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
781 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
784 @retval EFI_INVALID_PARAMETER Language is NULL.
786 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
788 @retval EFI_UNSUPPORTED The driver specified by This is not currently
789 managing the controller specified by
790 ControllerHandle and ChildHandle.
792 @retval EFI_UNSUPPORTED The driver specified by This does not support
793 the language specified by Language.
798 TerminalComponentNameGetControllerName (
799 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
800 IN EFI_HANDLE ControllerHandle
,
801 IN EFI_HANDLE ChildHandle OPTIONAL
,
803 OUT CHAR16
**ControllerName
808 // internal functions
812 Check for a pending key in the Efi Key FIFO or Serial device buffer.
814 @param This Indicates the calling context.
816 @retval EFI_SUCCESS There is key pending.
817 @retval EFI_NOT_READY There is no key pending.
818 @retval EFI_DEVICE_ERROR If Serial IO is not attached to serial device.
822 TerminalConInCheckForKey (
823 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
827 Update terminal device path in Console Device Environment Variables.
829 @param VariableName The Console Device Environment Variable.
830 @param ParentDevicePath The terminal device path to be updated.
836 TerminalUpdateConsoleDevVariable (
837 IN CHAR16
*VariableName
,
838 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
842 Remove console device variable.
844 @param VariableName A pointer to the variable name.
845 @param ParentDevicePath A pointer to the parent device path.
849 TerminalRemoveConsoleDevVariable (
850 IN CHAR16
*VariableName
,
851 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
855 Build termial device path according to terminal type.
857 @param TerminalType The terminal type is PC ANSI, VT100, VT100+ or VT-UTF8.
858 @param ParentDevicePath Parent device path.
859 @param TerminalDevicePath Returned terminal device path, if building successfully.
861 @retval EFI_UNSUPPORTED Terminal does not belong to the supported type.
862 @retval EFI_OUT_OF_RESOURCES Generate terminal device path failed.
863 @retval EFI_SUCCESS Build terminal device path successfully.
867 SetTerminalDevicePath (
868 IN TERMINAL_TYPE TerminalType
,
869 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
870 OUT EFI_DEVICE_PATH_PROTOCOL
**TerminalDevicePath
874 Get one key out of serial buffer.
876 @param SerialIo Serial I/O protocl attached to the serial device.
877 @param Input The fetched key.
879 @retval EFI_NOT_READY If serial buffer is empty.
880 @retval EFI_DEVICE_ERROR If reading serial buffer encounter error.
881 @retval EFI_SUCCESS If reading serial buffer successfully, put
882 the fetched key to the parameter output.
886 GetOneKeyFromSerial (
887 EFI_SERIAL_IO_PROTOCOL
*SerialIo
,
892 Insert one byte raw data into the Raw Data FIFO.
894 @param TerminalDevice Terminal driver private structure.
895 @param Input The key will be input.
897 @retval TRUE If insert successfully.
898 @retval FALSE If Raw Data buffer is full before key insertion,
903 RawFiFoInsertOneKey (
904 TERMINAL_DEV
*TerminalDevice
,
909 Remove one pre-fetched key out of the Raw Data FIFO.
911 @param TerminalDevice Terminal driver private structure.
912 @param Output The key will be removed.
914 @retval TRUE If insert successfully.
915 @retval FALSE If Raw Data FIFO buffer is empty before remove operation.
919 RawFiFoRemoveOneKey (
920 TERMINAL_DEV
*TerminalDevice
,
925 Clarify whether Raw Data FIFO buffer is empty.
927 @param TerminalDevice Terminal driver private structure
929 @retval TRUE If Raw Data FIFO buffer is empty.
930 @retval FALSE If Raw Data FIFO buffer is not empty.
935 TERMINAL_DEV
*TerminalDevice
939 Clarify whether Raw Data FIFO buffer is full.
941 @param TerminalDevice Terminal driver private structure
943 @retval TRUE If Raw Data FIFO buffer is full.
944 @retval FALSE If Raw Data FIFO buffer is not full.
949 TERMINAL_DEV
*TerminalDevice
953 Insert one pre-fetched key into the FIFO buffer.
955 @param EfiKeyFiFo Pointer to instance of EFI_KEY_FIFO.
956 @param Input The key will be input.
958 @retval TRUE If insert successfully.
959 @retval FALSE If FIFO buffer is full before key insertion,
964 EfiKeyFiFoForNotifyInsertOneKey (
965 EFI_KEY_FIFO
*EfiKeyFiFo
,
970 Remove one pre-fetched key out of the FIFO buffer.
972 @param EfiKeyFiFo Pointer to instance of EFI_KEY_FIFO.
973 @param Output The key will be removed.
975 @retval TRUE If insert successfully.
976 @retval FALSE If FIFO buffer is empty before remove operation.
980 EfiKeyFiFoForNotifyRemoveOneKey (
981 EFI_KEY_FIFO
*EfiKeyFiFo
,
982 EFI_INPUT_KEY
*Output
986 Clarify whether FIFO buffer is empty.
988 @param EfiKeyFiFo Pointer to instance of EFI_KEY_FIFO.
990 @retval TRUE If FIFO buffer is empty.
991 @retval FALSE If FIFO buffer is not empty.
995 IsEfiKeyFiFoForNotifyEmpty (
996 IN EFI_KEY_FIFO
*EfiKeyFiFo
1000 Clarify whether FIFO buffer is full.
1002 @param EfiKeyFiFo Pointer to instance of EFI_KEY_FIFO.
1004 @retval TRUE If FIFO buffer is full.
1005 @retval FALSE If FIFO buffer is not full.
1009 IsEfiKeyFiFoForNotifyFull (
1010 EFI_KEY_FIFO
*EfiKeyFiFo
1014 Insert one pre-fetched key into the FIFO buffer.
1016 @param TerminalDevice Terminal driver private structure.
1017 @param Key The key will be input.
1019 @retval TRUE If insert successfully.
1020 @retval FALSE If FIFO buffer is full before key insertion,
1021 and the key is lost.
1025 EfiKeyFiFoInsertOneKey (
1026 TERMINAL_DEV
*TerminalDevice
,
1031 Remove one pre-fetched key out of the FIFO buffer.
1033 @param TerminalDevice Terminal driver private structure.
1034 @param Output The key will be removed.
1036 @retval TRUE If insert successfully.
1037 @retval FALSE If FIFO buffer is empty before remove operation.
1041 EfiKeyFiFoRemoveOneKey (
1042 TERMINAL_DEV
*TerminalDevice
,
1043 EFI_INPUT_KEY
*Output
1047 Clarify whether FIFO buffer is empty.
1049 @param TerminalDevice Terminal driver private structure
1051 @retval TRUE If FIFO buffer is empty.
1052 @retval FALSE If FIFO buffer is not empty.
1057 TERMINAL_DEV
*TerminalDevice
1061 Clarify whether FIFO buffer is full.
1063 @param TerminalDevice Terminal driver private structure
1065 @retval TRUE If FIFO buffer is full.
1066 @retval FALSE If FIFO buffer is not full.
1071 TERMINAL_DEV
*TerminalDevice
1075 Insert one pre-fetched key into the Unicode FIFO buffer.
1077 @param TerminalDevice Terminal driver private structure.
1078 @param Input The key will be input.
1080 @retval TRUE If insert successfully.
1081 @retval FALSE If Unicode FIFO buffer is full before key insertion,
1082 and the key is lost.
1086 UnicodeFiFoInsertOneKey (
1087 TERMINAL_DEV
*TerminalDevice
,
1092 Remove one pre-fetched key out of the Unicode FIFO buffer.
1093 The caller should guarantee that Unicode FIFO buffer is not empty
1094 by IsUnicodeFiFoEmpty ().
1096 @param TerminalDevice Terminal driver private structure.
1097 @param Output The key will be removed.
1101 UnicodeFiFoRemoveOneKey (
1102 TERMINAL_DEV
*TerminalDevice
,
1107 Clarify whether Unicode FIFO buffer is empty.
1109 @param TerminalDevice Terminal driver private structure
1111 @retval TRUE If Unicode FIFO buffer is empty.
1112 @retval FALSE If Unicode FIFO buffer is not empty.
1116 IsUnicodeFiFoEmpty (
1117 TERMINAL_DEV
*TerminalDevice
1121 Clarify whether Unicode FIFO buffer is full.
1123 @param TerminalDevice Terminal driver private structure
1125 @retval TRUE If Unicode FIFO buffer is full.
1126 @retval FALSE If Unicode FIFO buffer is not full.
1131 TERMINAL_DEV
*TerminalDevice
1135 Count Unicode FIFO buffer.
1137 @param TerminalDevice Terminal driver private structure
1139 @return The count in bytes of Unicode FIFO.
1143 UnicodeFiFoGetKeyCount (
1144 TERMINAL_DEV
*TerminalDevice
1148 Translate raw data into Unicode (according to different encode), and
1149 translate Unicode into key information. (according to different standard).
1151 @param TerminalDevice Terminal driver private structure.
1155 TranslateRawDataToEfiKey (
1156 IN TERMINAL_DEV
*TerminalDevice
1160 // internal functions for PC ANSI
1164 Translate all raw data in the Raw FIFI into unicode, and insert
1165 them into Unicode FIFO.
1167 @param TerminalDevice The terminal device.
1171 AnsiRawDataToUnicode (
1172 IN TERMINAL_DEV
*TerminalDevice
1176 Converts a stream of Unicode characters from a terminal input device into EFI Keys that
1177 can be read through the Simple Input Protocol.
1179 The table below shows the keyboard input mappings that this function supports.
1180 If the ESC sequence listed in one of the columns is presented, then it is translated
1181 into the coorespoding EFI Scan Code. If a matching sequence is not found, then the raw
1182 key strokes are converted into EFI Keys.
1184 2 seconds are allowed for an ESC sequence to be completed. If the ESC sequence is not
1185 completed in 2 seconds, then the raw key strokes of the partial ESC sequence are
1186 converted into EFI Keys.
1187 There is one special input sequence that will force the system to reset.
1188 This is ESC R ESC r ESC R.
1190 Symbols used in table below
1191 ===========================
1196 +=========+======+===========+==========+==========+
1197 | | EFI | UEFI 2.0 | | |
1198 | | Scan | | VT100+ | |
1199 | KEY | Code | PC ANSI | VTUTF8 | VT100 |
1200 +=========+======+===========+==========+==========+
1201 | NULL | 0x00 | | | |
1202 | UP | 0x01 | ESC [ A | ESC [ A | ESC [ A |
1203 | DOWN | 0x02 | ESC [ B | ESC [ B | ESC [ B |
1204 | RIGHT | 0x03 | ESC [ C | ESC [ C | ESC [ C |
1205 | LEFT | 0x04 | ESC [ D | ESC [ D | ESC [ D |
1206 | HOME | 0x05 | ESC [ H | ESC h | ESC [ H |
1207 | END | 0x06 | ESC [ F | ESC k | ESC [ K |
1208 | INSERT | 0x07 | ESC [ @ | ESC + | ESC [ @ |
1209 | | | ESC [ L | | ESC [ L |
1210 | DELETE | 0x08 | ESC [ X | ESC - | ESC [ P |
1211 | PG UP | 0x09 | ESC [ I | ESC ? | ESC [ V |
1213 | PG DOWN | 0x0A | ESC [ G | ESC / | ESC [ U |
1215 | F1 | 0x0B | ESC [ M | ESC 1 | ESC O P |
1216 | F2 | 0x0C | ESC [ N | ESC 2 | ESC O Q |
1217 | F3 | 0x0D | ESC [ O | ESC 3 | ESC O w |
1218 | F4 | 0x0E | ESC [ P | ESC 4 | ESC O x |
1219 | F5 | 0x0F | ESC [ Q | ESC 5 | ESC O t |
1220 | F6 | 0x10 | ESC [ R | ESC 6 | ESC O u |
1221 | F7 | 0x11 | ESC [ S | ESC 7 | ESC O q |
1222 | F8 | 0x12 | ESC [ T | ESC 8 | ESC O r |
1223 | F9 | 0x13 | ESC [ U | ESC 9 | ESC O p |
1224 | F10 | 0x14 | ESC [ V | ESC 0 | ESC O M |
1225 | Escape | 0x17 | ESC | ESC | ESC |
1226 | F11 | 0x15 | | ESC ! | |
1227 | F12 | 0x16 | | ESC @ | |
1228 +=========+======+===========+==========+==========+
1232 ESC R ESC r ESC R = Reset System
1235 @param TerminalDevice The terminal device to use to translate raw input into EFI Keys
1240 IN TERMINAL_DEV
*TerminalDevice
1244 Check if input string is valid Ascii string, valid EFI control characters
1245 or valid text graphics.
1247 @param TerminalDevice The terminal device.
1248 @param WString The input string.
1250 @retval EFI_UNSUPPORTED If not all input characters are valid.
1251 @retval EFI_SUCCESS If all input characters are valid.
1256 IN TERMINAL_DEV
*TerminalDevice
,
1261 // internal functions for VTUTF8
1265 Translate all VT-UTF8 characters in the Raw FIFI into unicode characters,
1266 and insert them into Unicode FIFO.
1268 @param VtUtf8Device The terminal device.
1272 VTUTF8RawDataToUnicode (
1273 IN TERMINAL_DEV
*VtUtf8Device
1277 Check if input string is valid VT-UTF8 string.
1279 @param TerminalDevice The terminal device.
1280 @param WString The input string.
1282 @retval EFI_SUCCESS If all input characters are valid.
1287 IN TERMINAL_DEV
*TerminalDevice
,
1292 Translate one Unicode character into VT-UTF8 characters.
1295 Bits per Character | Unicode Character Range | Unicode Binary Encoding | UTF8 Binary Encoding
1296 0-7 | 0x0000 - 0x007F | 00000000 0xxxxxxx | 0xxxxxxx
1297 8-11 | 0x0080 - 0x07FF | 00000xxx xxxxxxxx | 110xxxxx 10xxxxxx
1298 12-16 | 0x0800 - 0xFFFF | xxxxxxxx xxxxxxxx | 1110xxxx 10xxxxxx 10xxxxxx
1301 @param Unicode Unicode character need translating.
1302 @param Utf8Char Return VT-UTF8 character set.
1303 @param ValidBytes The count of valid VT-UTF8 characters. If
1304 ValidBytes is zero, no valid VT-UTF8 returned.
1310 OUT UTF8_CHAR
*Utf8Char
,
1311 OUT UINT8
*ValidBytes
1315 Get one valid VT-UTF8 characters set from Raw Data FIFO.
1317 @param Utf8Device The terminal device.
1318 @param Utf8Char Returned valid VT-UTF8 characters set.
1319 @param ValidBytes The count of returned VT-VTF8 characters.
1320 If ValidBytes is zero, no valid VT-UTF8 returned.
1324 GetOneValidUtf8Char (
1325 IN TERMINAL_DEV
*Utf8Device
,
1326 OUT UTF8_CHAR
*Utf8Char
,
1327 OUT UINT8
*ValidBytes
1331 Translate VT-UTF8 characters into one Unicode character.
1334 Bits per Character | Unicode Character Range | Unicode Binary Encoding | UTF8 Binary Encoding
1335 0-7 | 0x0000 - 0x007F | 00000000 0xxxxxxx | 0xxxxxxx
1336 8-11 | 0x0080 - 0x07FF | 00000xxx xxxxxxxx | 110xxxxx 10xxxxxx
1337 12-16 | 0x0800 - 0xFFFF | xxxxxxxx xxxxxxxx | 1110xxxx 10xxxxxx 10xxxxxx
1340 @param Utf8Char VT-UTF8 character set needs translating.
1341 @param ValidBytes The count of valid VT-UTF8 characters.
1342 @param UnicodeChar Returned unicode character.
1347 IN UTF8_CHAR Utf8Char
,
1348 IN UINT8 ValidBytes
,
1349 OUT CHAR16
*UnicodeChar
1353 // functions for boxdraw unicode
1357 Detects if a Unicode char is for Box Drawing text graphics.
1359 @param Graphic Unicode char to test.
1360 @param PcAnsi Optional pointer to return PCANSI equivalent of
1362 @param Ascii Optional pointer to return ASCII equivalent of
1365 @retval TRUE If Graphic is a supported Unicode Box Drawing character.
1369 TerminalIsValidTextGraphics (
1371 OUT CHAR8
*PcAnsi
, OPTIONAL
1372 OUT CHAR8
*Ascii OPTIONAL
1376 Detects if a valid ASCII char.
1378 @param Ascii An ASCII character.
1380 @retval TRUE If it is a valid ASCII character.
1381 @retval FALSE If it is not a valid ASCII character.
1385 TerminalIsValidAscii (
1390 Detects if a valid EFI control character.
1392 @param CharC An input EFI Control character.
1394 @retval TRUE If it is a valid EFI control character.
1395 @retval FALSE If it is not a valid EFI control character.
1399 TerminalIsValidEfiCntlChar (
1404 Check if the device supports hot-plug through its device path.
1406 This function could be updated to check more types of Hot Plug devices.
1407 Currently, it checks USB and PCCard device.
1409 @param DevicePath Pointer to device's device path.
1411 @retval TRUE The devcie is a hot-plug device
1412 @retval FALSE The devcie is not a hot-plug device.
1417 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1421 Timer handler to poll the key from serial.
1423 @param Event Indicates the event that invoke this function.
1424 @param Context Indicates the calling context.
1428 TerminalConInTimerHandler (
1437 @param Event Indicates the event that invoke this function.
1438 @param Context Indicates the calling context.
1442 KeyNotifyProcessHandler (