2 Header file for Terminal driver.
4 Copyright (c) 2006 - 2008, Intel Corporation. <BR>
5 All rights reserved. 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.
20 #include <Protocol/SimpleTextOut.h>
21 #include <Protocol/SerialIo.h>
22 #include <Guid/GlobalVariable.h>
23 #include <Protocol/DevicePath.h>
24 #include <Protocol/SimpleTextIn.h>
25 #include <Protocol/SimpleTextInEx.h>
26 #include <Guid/HotPlugDevice.h>
27 #include <Guid/PcAnsi.h>
28 #include <Library/DebugLib.h>
29 #include <Library/UefiDriverEntryPoint.h>
30 #include <Library/UefiLib.h>
31 #include <Library/ReportStatusCodeLib.h>
32 #include <Library/BaseMemoryLib.h>
33 #include <Library/MemoryAllocationLib.h>
34 #include <Library/UefiBootServicesTableLib.h>
35 #include <Library/UefiRuntimeServicesTableLib.h>
36 #include <Library/DevicePathLib.h>
37 #include <Library/PcdLib.h>
38 #include <Library/BaseLib.h>
41 #define RAW_FIFO_MAX_NUMBER 256
42 #define FIFO_MAX_NUMBER 128
47 UINT8 Data
[RAW_FIFO_MAX_NUMBER
+ 1];
53 UINT16 Data
[FIFO_MAX_NUMBER
+ 1];
59 EFI_INPUT_KEY Data
[FIFO_MAX_NUMBER
+ 1];
62 #define TERMINAL_DEV_SIGNATURE SIGNATURE_32 ('t', 'm', 'n', 'l')
64 #define TERMINAL_CONSOLE_IN_EX_NOTIFY_SIGNATURE SIGNATURE_32 ('t', 'm', 'e', 'n')
66 typedef struct _TERMINAL_CONSOLE_IN_EX_NOTIFY
{
68 EFI_HANDLE NotifyHandle
;
70 EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn
;
71 LIST_ENTRY NotifyEntry
;
72 } TERMINAL_CONSOLE_IN_EX_NOTIFY
;
77 EFI_SERIAL_IO_PROTOCOL
*SerialIo
;
78 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
79 EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleInput
;
80 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL SimpleTextOutput
;
81 EFI_SIMPLE_TEXT_OUTPUT_MODE SimpleTextOutputMode
;
82 UINTN SerialInTimeOut
;
83 RAW_DATA_FIFO RawFiFo
;
84 UNICODE_FIFO UnicodeFiFo
;
85 EFI_KEY_FIFO EfiKeyFiFo
;
86 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
87 EFI_EVENT TwoSecondTimeOut
;
92 // Esc could not be output to the screen by user,
93 // but the terminal driver need to output it to
94 // the terminal emulation software to send control sequence.
95 // This boolean is used by the terminal driver only
96 // to indicate whether the Esc could be sent or not.
98 BOOLEAN OutputEscChar
;
99 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL SimpleInputEx
;
100 LIST_ENTRY NotifyList
;
103 #define INPUT_STATE_DEFAULT 0x00
104 #define INPUT_STATE_ESC 0x01
105 #define INPUT_STATE_CSI 0x02
106 #define INPUT_STATE_LEFTOPENBRACKET 0x04
107 #define INPUT_STATE_O 0x08
108 #define INPUT_STATE_2 0x10
110 #define RESET_STATE_DEFAULT 0x00
111 #define RESET_STATE_ESC_R 0x01
112 #define RESET_STATE_ESC_R_ESC_r 0x02
114 #define TERMINAL_CON_IN_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleInput, TERMINAL_DEV_SIGNATURE)
115 #define TERMINAL_CON_OUT_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleTextOutput, TERMINAL_DEV_SIGNATURE)
116 #define TERMINAL_CON_IN_EX_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleInputEx, TERMINAL_DEV_SIGNATURE)
126 #define VT100PLUSTYPE 2
129 #define LEFTOPENBRACKET 0x5b // '['
135 #define MODE0_COLUMN_COUNT 80
136 #define MODE0_ROW_COUNT 25
138 #define MODE1_COLUMN_COUNT 80
139 #define MODE1_ROW_COUNT 50
141 #define MODE2_COLUMN_COUNT 100
142 #define MODE2_ROW_COUNT 31
148 #define BRIGHT_CONTROL_OFFSET 2
149 #define FOREGROUND_CONTROL_OFFSET 6
150 #define BACKGROUND_CONTROL_OFFSET 11
152 #define COLUMN_OFFSET 5
163 extern EFI_DRIVER_BINDING_PROTOCOL gTerminalDriverBinding
;
164 extern EFI_COMPONENT_NAME_PROTOCOL gTerminalComponentName
;
165 extern EFI_COMPONENT_NAME2_PROTOCOL gTerminalComponentName2
;
167 extern EFI_GUID gSimpleTextInExNotifyGuid
;
170 The user Entry Point for module Terminal. The user code starts with this function.
172 @param[in] ImageHandle The firmware allocated handle for the EFI image.
173 @param[in] SystemTable A pointer to the EFI System Table.
175 @retval EFI_SUCCESS The entry point is executed successfully.
176 @retval other Some error occurs when executing this entry point.
182 IN EFI_HANDLE ImageHandle
,
183 IN EFI_SYSTEM_TABLE
*SystemTable
187 Implements EFI_SIMPLE_TEXT_INPUT_PROTOCOL.Reset().
188 This driver only perform dependent serial device reset regardless of
189 the value of ExtendeVerification
191 @param This Indicates the calling context.
192 @param ExtendedVerification Skip by this driver.
194 @return EFI_SUCCESS The reset operation succeeds.
195 @return EFI_DEVICE_ERROR The dependent serial port reset fails.
201 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
202 IN BOOLEAN ExtendedVerification
207 Implements EFI_SIMPLE_TEXT_INPUT_PROTOCOL.ReadKeyStroke().
209 @param This Indicates the calling context.
210 @param Key A pointer to a buffer that is filled in with the
211 keystroke information for the key that was sent
214 @return EFI_SUCCESS The keystroke information is returned successfully.
215 @return EFI_NOT_READY There is no keystroke data available.
216 @return EFI_DEVICE_ERROR The dependent serial device encounters error.
221 TerminalConInReadKeyStroke (
222 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
223 OUT EFI_INPUT_KEY
*Key
227 Check if the key already has been registered.
229 @param RegsiteredData A pointer to a buffer that is filled in with the
230 keystroke state data for the key that was
232 @param InputData A pointer to a buffer that is filled in with the
233 keystroke state data for the key that was
236 @retval TRUE Key be pressed matches a registered key.
237 @retval FLASE Match failed.
242 IN EFI_KEY_DATA
*RegsiteredData
,
243 IN EFI_KEY_DATA
*InputData
247 Event notification function for EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx event
248 Signal the event if there is key available
250 @param Event Indicates the event that invoke this function.
251 @param Context Indicates the calling context.
258 TerminalConInWaitForKeyEx (
264 // Simple Text Input Ex protocol prototypes
268 Reset the input device and optionally run diagnostics
270 @param This Protocol instance pointer.
271 @param ExtendedVerification Driver may perform diagnostics on reset.
273 @retval EFI_SUCCESS The device was reset.
274 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
280 TerminalConInResetEx (
281 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
282 IN BOOLEAN ExtendedVerification
286 Reads the next keystroke from the input device. The WaitForKey Event can
287 be used to test for existence of a keystroke via WaitForEvent () call.
289 @param This Protocol instance pointer.
290 @param KeyData A pointer to a buffer that is filled in with the
291 keystroke state data for the key that was
294 @retval EFI_SUCCESS The keystroke information was returned.
295 @retval EFI_NOT_READY There was no keystroke data available.
296 @retval EFI_DEVICE_ERROR The keystroke information was not returned due
298 @retval EFI_INVALID_PARAMETER KeyData is NULL.
303 TerminalConInReadKeyStrokeEx (
304 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
305 OUT EFI_KEY_DATA
*KeyData
309 Set certain state for the input device.
311 @param This Protocol instance pointer.
312 @param KeyToggleState A pointer to the EFI_KEY_TOGGLE_STATE to set the
313 state for the input device.
315 @retval EFI_SUCCESS The device state was set successfully.
316 @retval EFI_DEVICE_ERROR The device is not functioning correctly and
317 could not have the setting adjusted.
318 @retval EFI_UNSUPPORTED The device does not have the ability to set its
320 @retval EFI_INVALID_PARAMETER KeyToggleState is NULL.
325 TerminalConInSetState (
326 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
327 IN EFI_KEY_TOGGLE_STATE
*KeyToggleState
331 Register a notification function for a particular keystroke for the input device.
333 @param This Protocol instance pointer.
334 @param KeyData A pointer to a buffer that is filled in with the
335 keystroke information data for the key that was
337 @param KeyNotificationFunction Points to the function to be called when the key
338 sequence is typed specified by KeyData.
339 @param NotifyHandle Points to the unique handle assigned to the
340 registered notification.
342 @retval EFI_SUCCESS The notification function was registered
344 @retval EFI_OUT_OF_RESOURCES Unable to allocate resources for necesssary data
346 @retval EFI_INVALID_PARAMETER KeyData or NotifyHandle is NULL.
351 TerminalConInRegisterKeyNotify (
352 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
353 IN EFI_KEY_DATA
*KeyData
,
354 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction
,
355 OUT EFI_HANDLE
*NotifyHandle
359 Remove a registered notification function from a particular keystroke.
361 @param This Protocol instance pointer.
362 @param NotificationHandle The handle of the notification function being
365 @retval EFI_SUCCESS The notification function was unregistered
367 @retval EFI_INVALID_PARAMETER The NotificationHandle is invalid.
368 @retval EFI_NOT_FOUND Can not find the matching entry in database.
373 TerminalConInUnregisterKeyNotify (
374 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
375 IN EFI_HANDLE NotificationHandle
379 Event notification function for EFI_SIMPLE_TEXT_INPUT_PROTOCOL.WaitForKey event
380 Signal the event if there is key available
382 @param Event Indicates the event that invoke this function.
383 @param Context Indicates the calling context.
390 TerminalConInWaitForKey (
396 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset().
397 If ExtendeVerification is TRUE, then perform dependent serial device reset,
398 and set display mode to mode 0.
399 If ExtendedVerification is FALSE, only set display mode to mode 0.
401 @param This Indicates the calling context.
402 @param ExtendedVerification Indicates that the driver may perform a more
403 exhaustive verification operation of the device
406 @return EFI_SUCCESS The reset operation succeeds.
407 @return EFI_DEVICE_ERROR The terminal is not functioning correctly or the serial port reset fails.
412 TerminalConOutReset (
413 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
414 IN BOOLEAN ExtendedVerification
418 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString().
419 The Unicode string will be converted to terminal expressible data stream
420 and send to terminal via serial port.
422 @param This Indicates the calling context.
423 @param WString The Null-terminated Unicode string to be displayed
424 on the terminal screen.
426 @retval EFI_SUCCESS The string is output successfully.
427 @retval EFI_DEVICE_ERROR The serial port fails to send the string out.
428 @retval EFI_WARN_UNKNOWN_GLYPH Indicates that some of the characters in the Unicode string could not
429 be rendered and are skipped.
430 @retval EFI_UNSUPPORTED If current display mode is out of range.
435 TerminalConOutOutputString (
436 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
441 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.TestString().
442 If one of the characters in the *Wstring is
443 neither valid Unicode drawing characters,
444 not ASCII code, then this function will return
447 @param This Indicates the calling context.
448 @param WString The Null-terminated Unicode string to be tested.
450 @return EFI_SUCCESS The terminal is capable of rendering the output string.
451 @return EFI_UNSUPPORTED Some of the characters in the Unicode string cannot be rendered.
456 TerminalConOutTestString (
457 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
462 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.QueryMode().
463 It returns information for an available text mode
464 that the terminal supports.
465 In this driver, we support text mode 80x25 (mode 0),
466 80x50 (mode 1), 100x31 (mode 2).
468 @param This Indicates the calling context.
469 @param ModeNumber The mode number to return information on.
470 @param Columns The returned columns of the requested mode.
471 @param Rows The returned rows of the requested mode.
473 @return EFI_SUCCESS The requested mode information is returned.
474 @return EFI_UNSUPPORTED The mode number is not valid.
475 @return EFI_DEVICE_ERROR
480 TerminalConOutQueryMode (
481 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
488 Implements EFI_SIMPLE_TEXT_OUT.SetMode().
489 Set the terminal to a specified display mode.
490 In this driver, we only support mode 0.
492 @param This Indicates the calling context.
493 @param ModeNumber The text mode to set.
495 @return EFI_SUCCESS The requested text mode is set.
496 @return EFI_DEVICE_ERROR The requested text mode cannot be set
497 because of serial device error.
498 @return EFI_UNSUPPORTED The text mode number is not valid.
503 TerminalConOutSetMode (
504 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
509 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetAttribute().
511 @param This Indicates the calling context.
512 @param Attribute The attribute to set. Only bit0..6 are valid, all other bits
513 are undefined and must be zero.
515 @return EFI_SUCCESS The requested attribute is set.
516 @return EFI_DEVICE_ERROR The requested attribute cannot be set due to serial port error.
517 @return EFI_UNSUPPORTED The attribute requested is not defined by EFI spec.
522 TerminalConOutSetAttribute (
523 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
528 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.ClearScreen().
529 It clears the ANSI terminal's display to the
530 currently selected background color.
532 @param This Indicates the calling context.
534 @return EFI_SUCCESS The operation completed successfully.
535 @return EFI_DEVICE_ERROR The terminal screen cannot be cleared due to serial port error.
536 @return EFI_UNSUPPORTED The terminal is not in a valid display mode.
541 TerminalConOutClearScreen (
542 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
546 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetCursorPosition().
548 @param This Indicates the calling context.
549 @param Column The row to set cursor to.
550 @param Row The column to set cursor to.
552 @return EFI_SUCCESS The operation completed successfully.
553 @return EFI_DEVICE_ERROR The request fails due to serial port error.
554 @return EFI_UNSUPPORTED The terminal is not in a valid text mode, or the cursor position
555 is invalid for current mode.
560 TerminalConOutSetCursorPosition (
561 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
567 Implements SIMPLE_TEXT_OUTPUT.EnableCursor().
568 In this driver, the cursor cannot be hidden.
570 @param This Indicates the calling context.
571 @param Visible If TRUE, the cursor is set to be visible,
572 If FALSE, the cursor is set to be invisible.
574 @return EFI_SUCCESS The request is valid.
575 @return EFI_UNSUPPORTED The terminal does not support cursor hidden.
580 TerminalConOutEnableCursor (
581 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
586 Test to see if this driver supports Controller.
588 @param This Protocol instance pointer.
589 @param ControllerHandle Handle of device to test
590 @param RemainingDevicePath Optional parameter use to pick a specific child
593 @retval EFI_SUCCESS This driver supports this device.
594 @retval EFI_ALREADY_STARTED This driver is already running on this device.
595 @retval other This driver does not support this device.
600 TerminalDriverBindingSupported (
601 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
602 IN EFI_HANDLE ControllerHandle
,
603 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
607 Start this driver on Controller by opening a Serial IO protocol,
608 reading Device Path, and creating a child handle with a Simple Text In,
609 Simple Text In Ex and Simple Text Out protocol, and device path protocol.
610 And store Console Device Environment Variables.
612 @param This Protocol instance pointer.
613 @param Controller Handle of device to bind driver to
614 @param RemainingDevicePath Optional parameter use to pick a specific child
617 @retval EFI_SUCCESS This driver is added to Controller.
618 @retval EFI_ALREADY_STARTED This driver is already running on Controller.
619 @retval other This driver does not support this device.
624 TerminalDriverBindingStart (
625 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
626 IN EFI_HANDLE Controller
,
627 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
632 Stop this driver on Controller by closing Simple Text In, Simple Text
633 In Ex, Simple Text Out protocol, and removing parent device path from
634 Console Device Environment Variables.
636 @param This Protocol instance pointer.
637 @param Controller Handle of device to stop driver on
638 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
639 children is zero stop the entire bus driver.
640 @param ChildHandleBuffer List of Child Handles to Stop.
642 @retval EFI_SUCCESS This driver is removed Controller.
643 @retval other This driver could not be removed from this device.
648 TerminalDriverBindingStop (
649 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
650 IN EFI_HANDLE Controller
,
651 IN UINTN NumberOfChildren
,
652 IN EFI_HANDLE
*ChildHandleBuffer
656 Free notify functions list.
658 @param ListHead The list head
660 @retval EFI_SUCCESS Free the notify list successfully.
661 @retval EFI_INVALID_PARAMETER ListHead is NULL.
665 TerminalFreeNotifyList (
666 IN OUT LIST_ENTRY
*ListHead
670 Retrieves a Unicode string that is the user readable name of the driver.
672 This function retrieves the user readable name of a driver in the form of a
673 Unicode string. If the driver specified by This has a user readable name in
674 the language specified by Language, then a pointer to the driver name is
675 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
676 by This does not support the language specified by Language,
677 then EFI_UNSUPPORTED is returned.
679 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
680 EFI_COMPONENT_NAME_PROTOCOL instance.
682 @param Language[in] A pointer to a Null-terminated ASCII string
683 array indicating the language. This is the
684 language of the driver name that the caller is
685 requesting, and it must match one of the
686 languages specified in SupportedLanguages. The
687 number of languages supported by a driver is up
688 to the driver writer. Language is specified
689 in RFC 3066 or ISO 639-2 language code format.
691 @param DriverName[out] A pointer to the Unicode string to return.
692 This Unicode string is the name of the
693 driver specified by This in the language
694 specified by Language.
696 @retval EFI_SUCCESS The Unicode string for the Driver specified by
697 This and the language specified by Language was
698 returned in DriverName.
700 @retval EFI_INVALID_PARAMETER Language is NULL.
702 @retval EFI_INVALID_PARAMETER DriverName is NULL.
704 @retval EFI_UNSUPPORTED The driver specified by This does not support
705 the language specified by Language.
710 TerminalComponentNameGetDriverName (
711 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
713 OUT CHAR16
**DriverName
718 Retrieves a Unicode string that is the user readable name of the controller
719 that is being managed by a driver.
721 This function retrieves the user readable name of the controller specified by
722 ControllerHandle and ChildHandle in the form of a Unicode string. If the
723 driver specified by This has a user readable name in the language specified by
724 Language, then a pointer to the controller name is returned in ControllerName,
725 and EFI_SUCCESS is returned. If the driver specified by This is not currently
726 managing the controller specified by ControllerHandle and ChildHandle,
727 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
728 support the language specified by Language, then EFI_UNSUPPORTED is returned.
730 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
731 EFI_COMPONENT_NAME_PROTOCOL instance.
733 @param ControllerHandle[in] The handle of a controller that the driver
734 specified by This is managing. This handle
735 specifies the controller whose name is to be
738 @param ChildHandle[in] The handle of the child controller to retrieve
739 the name of. This is an optional parameter that
740 may be NULL. It will be NULL for device
741 drivers. It will also be NULL for a bus drivers
742 that wish to retrieve the name of the bus
743 controller. It will not be NULL for a bus
744 driver that wishes to retrieve the name of a
747 @param Language[in] A pointer to a Null-terminated ASCII string
748 array indicating the language. This is the
749 language of the driver name that the caller is
750 requesting, and it must match one of the
751 languages specified in SupportedLanguages. The
752 number of languages supported by a driver is up
753 to the driver writer. Language is specified in
754 RFC 3066 or ISO 639-2 language code format.
756 @param ControllerName[out] A pointer to the Unicode string to return.
757 This Unicode string is the name of the
758 controller specified by ControllerHandle and
759 ChildHandle in the language specified by
760 Language from the point of view of the driver
763 @retval EFI_SUCCESS The Unicode string for the user readable name in
764 the language specified by Language for the
765 driver specified by This was returned in
768 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
770 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
773 @retval EFI_INVALID_PARAMETER Language is NULL.
775 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
777 @retval EFI_UNSUPPORTED The driver specified by This is not currently
778 managing the controller specified by
779 ControllerHandle and ChildHandle.
781 @retval EFI_UNSUPPORTED The driver specified by This does not support
782 the language specified by Language.
787 TerminalComponentNameGetControllerName (
788 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
789 IN EFI_HANDLE ControllerHandle
,
790 IN EFI_HANDLE ChildHandle OPTIONAL
,
792 OUT CHAR16
**ControllerName
797 // internal functions
801 Check for a pending key in the Efi Key FIFO or Serial device buffer.
803 @param This Indicates the calling context.
805 @retval EFI_SUCCESS There is key pending.
806 @retval EFI_NOT_READY There is no key pending.
807 @retval EFI_DEVICE_ERROR If Serial IO is not attached to serial device.
811 TerminalConInCheckForKey (
812 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
816 Update terminal device path in Console Device Environment Variables.
818 @param VariableName The Console Device Environment Variable.
819 @param ParentDevicePath The terminal device path to be updated.
825 TerminalUpdateConsoleDevVariable (
826 IN CHAR16
*VariableName
,
827 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
831 Remove console device variable.
833 @param VariableName A pointer to the variable name.
834 @param ParentDevicePath A pointer to the parent device path.
840 TerminalRemoveConsoleDevVariable (
841 IN CHAR16
*VariableName
,
842 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
846 Read the EFI variable (VendorGuid/Name) and return a dynamically allocated
847 buffer, and the size of the buffer. On failure return NULL.
849 @param Name String part of EFI variable name
850 @param VendorGuid GUID part of EFI variable name
851 @param VariableSize Returns the size of the EFI variable that was read
853 @return Dynamically allocated memory that contains a copy of the EFI variable.
854 Caller is repsoncible freeing the buffer. If variable was not read,
859 TerminalGetVariableAndSize (
861 IN EFI_GUID
*VendorGuid
,
862 OUT UINTN
*VariableSize
866 Build termial device path according to terminal type.
868 @param TerminalType The terminal type is PC ANSI, VT100, VT100+ or VT-UTF8.
869 @param ParentDevicePath Parent device path.
870 @param TerminalDevicePath Returned terminal device path, if building successfully.
872 @retval EFI_UNSUPPORTED Terminal does not belong to the supported type.
873 @retval EFI_OUT_OF_RESOURCES Generate terminal device path failed.
874 @retval EFI_SUCCESS Build terminal device path successfully.
878 SetTerminalDevicePath (
879 IN UINT8 TerminalType
,
880 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
881 OUT EFI_DEVICE_PATH_PROTOCOL
**TerminalDevicePath
885 Initialize the Raw Data FIFO.
887 @param TerminalDevice The terminal device.
894 IN TERMINAL_DEV
*TerminalDevice
898 Initialize the Unicode FIFO.
900 @param TerminalDevice The terminal device.
906 InitializeUnicodeFiFo (
907 IN TERMINAL_DEV
*TerminalDevice
911 Initialize the EFI Key FIFO.
913 @param TerminalDevice The terminal device.
919 InitializeEfiKeyFiFo (
920 IN TERMINAL_DEV
*TerminalDevice
924 Get one key out of serial buffer.
926 @param SerialIo Serial I/O protocl attached to the serial device.
927 @param Input The fetched key.
929 @return EFI_NOT_READY If serial buffer is empty.
930 @return EFI_DEVICE_ERROR If reading serial buffer encounter error.
931 @return EFI_SUCCESS If reading serial buffer successfully, put
932 the fetched key to the parameter output.
936 GetOneKeyFromSerial (
937 EFI_SERIAL_IO_PROTOCOL
*SerialIo
,
942 Insert one byte raw data into the Raw Data FIFO.
944 @param TerminalDevice Terminal driver private structure.
945 @param Input The key will be input.
947 @return TRUE If insert successfully.
948 @return FLASE If Raw Data buffer is full before key insertion,
953 RawFiFoInsertOneKey (
954 TERMINAL_DEV
*TerminalDevice
,
959 Remove one pre-fetched key out of the Raw Data FIFO.
961 @param TerminalDevice Terminal driver private structure.
962 @param Output The key will be removed.
964 @return TRUE If insert successfully.
965 @return FLASE If Raw Data FIFO buffer is empty before remove operation.
969 RawFiFoRemoveOneKey (
970 TERMINAL_DEV
*TerminalDevice
,
975 Clarify whether Raw Data FIFO buffer is empty.
977 @param TerminalDevice Terminal driver private structure
979 @return TRUE If Raw Data FIFO buffer is empty.
980 @return FLASE If Raw Data FIFO buffer is not empty.
985 TERMINAL_DEV
*TerminalDevice
989 Clarify whether Raw Data FIFO buffer is full.
991 @param TerminalDevice Terminal driver private structure
993 @return TRUE If Raw Data FIFO buffer is full.
994 @return FLASE If Raw Data FIFO buffer is not full.
999 TERMINAL_DEV
*TerminalDevice
1003 Insert one pre-fetched key into the FIFO buffer.
1005 @param TerminalDevice Terminal driver private structure.
1006 @param Key The key will be input.
1008 @return TRUE If insert successfully.
1009 @return FLASE If FIFO buffer is full before key insertion,
1010 and the key is lost.
1014 EfiKeyFiFoInsertOneKey (
1015 TERMINAL_DEV
*TerminalDevice
,
1020 Remove one pre-fetched key out of the FIFO buffer.
1022 @param TerminalDevice Terminal driver private structure.
1023 @param Output The key will be removed.
1025 @return TRUE If insert successfully.
1026 @return FLASE If FIFO buffer is empty before remove operation.
1030 EfiKeyFiFoRemoveOneKey (
1031 TERMINAL_DEV
*TerminalDevice
,
1032 EFI_INPUT_KEY
*Output
1036 Clarify whether FIFO buffer is empty.
1038 @param TerminalDevice Terminal driver private structure
1040 @return TRUE If FIFO buffer is empty.
1041 @return FLASE If FIFO buffer is not empty.
1046 TERMINAL_DEV
*TerminalDevice
1050 Clarify whether FIFO buffer is full.
1052 @param TerminalDevice Terminal driver private structure
1054 @return TRUE If FIFO buffer is full.
1055 @return FLASE If FIFO buffer is not full.
1060 TERMINAL_DEV
*TerminalDevice
1064 Insert one pre-fetched key into the Unicode FIFO buffer.
1066 @param TerminalDevice Terminal driver private structure.
1067 @param Input The key will be input.
1069 @return TRUE If insert successfully.
1070 @return FLASE If Unicode FIFO buffer is full before key insertion,
1071 and the key is lost.
1075 UnicodeFiFoInsertOneKey (
1076 TERMINAL_DEV
*TerminalDevice
,
1081 Remove one pre-fetched key out of the Unicode FIFO buffer.
1083 @param TerminalDevice Terminal driver private structure.
1084 @param Output The key will be removed.
1086 @return TRUE If insert successfully.
1087 @return FLASE If Unicode FIFO buffer is empty before remove operation.
1091 UnicodeFiFoRemoveOneKey (
1092 TERMINAL_DEV
*TerminalDevice
,
1097 Clarify whether Unicode FIFO buffer is empty.
1099 @param TerminalDevice Terminal driver private structure
1101 @return TRUE If Unicode FIFO buffer is empty.
1102 @return FLASE If Unicode FIFO buffer is not empty.
1106 IsUnicodeFiFoEmpty (
1107 TERMINAL_DEV
*TerminalDevice
1111 Clarify whether Unicode FIFO buffer is full.
1113 @param TerminalDevice Terminal driver private structure
1115 @return TRUE If Unicode FIFO buffer is full.
1116 @return FLASE If Unicode FIFO buffer is not full.
1121 TERMINAL_DEV
*TerminalDevice
1125 Count Unicode FIFO buffer.
1127 @param TerminalDevice Terminal driver private structure
1129 @return The count in bytes of Unicode FIFO.
1133 UnicodeFiFoGetKeyCount (
1134 TERMINAL_DEV
*TerminalDevice
1138 Translate raw data into Unicode (according to different encode), and
1139 translate Unicode into key information. (according to different standard).
1141 @param TerminalDevice Terminal driver private structure.
1147 TranslateRawDataToEfiKey (
1148 IN TERMINAL_DEV
*TerminalDevice
1152 // internal functions for PC ANSI
1156 Translate all raw data in the Raw FIFI into unicode, and insert
1157 them into Unicode FIFO.
1159 @param TerminalDevice The terminal device.
1165 AnsiRawDataToUnicode (
1166 IN TERMINAL_DEV
*TerminalDevice
1170 Converts a stream of Unicode characters from a terminal input device into EFI Keys that
1171 can be read through the Simple Input Protocol.
1173 The table below shows the keyboard input mappings that this function supports.
1174 If the ESC sequence listed in one of the columns is presented, then it is translated
1175 into the coorespoding EFI Scan Code. If a matching sequence is not found, then the raw
1176 key strokes are converted into EFI Keys.
1178 2 seconds are allowed for an ESC sequence to be completed. If the ESC sequence is not
1179 completed in 2 seconds, then the raw key strokes of the partial ESC sequence are
1180 converted into EFI Keys.
1181 There is one special input sequence that will force the system to reset.
1182 This is ESC R ESC r ESC R.
1184 Symbols used in table below
1185 ===========================
1190 +=========+======+===========+==========+==========+
1191 | | EFI | UEFI 2.0 | | |
1192 | | Scan | | VT100+ | |
1193 | KEY | Code | PC ANSI | VTUTF8 | VT100 |
1194 +=========+======+===========+==========+==========+
1195 | NULL | 0x00 | | | |
1196 | UP | 0x01 | ESC [ A | ESC [ A | ESC [ A |
1197 | DOWN | 0x02 | ESC [ B | ESC [ B | ESC [ B |
1198 | RIGHT | 0x03 | ESC [ C | ESC [ C | ESC [ C |
1199 | LEFT | 0x04 | ESC [ D | ESC [ D | ESC [ D |
1200 | HOME | 0x05 | ESC [ H | ESC h | ESC [ H |
1201 | END | 0x06 | ESC [ F | ESC k | ESC [ K |
1202 | INSERT | 0x07 | ESC [ @ | ESC + | ESC [ @ |
1203 | | | ESC [ L | | ESC [ L |
1204 | DELETE | 0x08 | ESC [ X | ESC - | ESC [ P |
1205 | PG UP | 0x09 | ESC [ I | ESC ? | ESC [ V |
1207 | PG DOWN | 0x0A | ESC [ G | ESC / | ESC [ U |
1209 | F1 | 0x0B | ESC [ M | ESC 1 | ESC O P |
1210 | F2 | 0x0C | ESC [ N | ESC 2 | ESC O Q |
1211 | F3 | 0x0D | ESC [ O | ESC 3 | ESC O w |
1212 | F4 | 0x0E | ESC [ P | ESC 4 | ESC O x |
1213 | F5 | 0x0F | ESC [ Q | ESC 5 | ESC O t |
1214 | F6 | 0x10 | ESC [ R | ESC 6 | ESC O u |
1215 | F7 | 0x11 | ESC [ S | ESC 7 | ESC O q |
1216 | F8 | 0x12 | ESC [ T | ESC 8 | ESC O r |
1217 | F9 | 0x13 | ESC [ U | ESC 9 | ESC O p |
1218 | F10 | 0x14 | ESC [ V | ESC 0 | ESC O M |
1219 | Escape | 0x17 | ESC | ESC | ESC |
1220 | F11 | 0x15 | | ESC ! | |
1221 | F12 | 0x16 | | ESC @ | |
1222 +=========+======+===========+==========+==========+
1226 ESC R ESC r ESC R = Reset System
1229 @param TerminalDevice The terminal device to use to translate raw input into EFI Keys
1236 IN TERMINAL_DEV
*TerminalDevice
1240 Check if input string is valid Ascii string, valid EFI control characters
1241 or valid text graphics.
1243 @param TerminalDevice The terminal device.
1244 @param WString The input string.
1246 @retval EFI_UNSUPPORTED If not all input characters are valid.
1247 @retval EFI_SUCCESS If all input characters are valid.
1252 IN TERMINAL_DEV
*TerminalDevice
,
1257 // internal functions for VTUTF8
1261 Translate all VT-UTF8 characters in the Raw FIFI into unicode characters,
1262 and insert them into Unicode FIFO.
1264 @param VtUtf8Device The terminal device.
1270 VTUTF8RawDataToUnicode (
1271 IN TERMINAL_DEV
*VtUtf8Device
1275 Check if input string is valid VT-UTF8 string.
1277 @param TerminalDevice The terminal device.
1278 @param WString The input string.
1280 @retval EFI_SUCCESS If all input characters are valid.
1285 IN TERMINAL_DEV
*TerminalDevice
,
1290 Translate one Unicode character into VT-UTF8 characters.
1293 Bits per Character | Unicode Character Range | Unicode Binary Encoding | UTF8 Binary Encoding
1294 0-7 | 0x0000 - 0x007F | 00000000 0xxxxxxx | 0xxxxxxx
1295 8-11 | 0x0080 - 0x07FF | 00000xxx xxxxxxxx | 110xxxxx 10xxxxxx
1296 12-16 | 0x0800 - 0xFFFF | xxxxxxxx xxxxxxxx | 1110xxxx 10xxxxxx 10xxxxxx
1299 @param Unicode Unicode character need translating.
1300 @param Utf8Char Return VT-UTF8 character set.
1301 @param ValidBytes The count of valid VT-UTF8 characters. If
1302 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.
1349 IN UTF8_CHAR Utf8Char
,
1350 IN UINT8 ValidBytes
,
1351 OUT CHAR16
*UnicodeChar
1355 // functions for boxdraw unicode
1359 Detects if a Unicode char is for Box Drawing text graphics.
1361 @param Graphic Unicode char to test.
1362 @param PcAnsi Optional pointer to return PCANSI equivalent of
1364 @param Ascii Optional pointer to return ASCII equivalent of
1367 @return TRUE If Graphic is a supported Unicode Box Drawing character.
1371 TerminalIsValidTextGraphics (
1373 OUT CHAR8
*PcAnsi
, OPTIONAL
1374 OUT CHAR8
*Ascii OPTIONAL
1378 Detects if a valid ASCII char.
1380 @param Ascii An ASCII character.
1382 @retval TRUE If it is a valid ASCII character.
1383 @retval FALSE If it is not a valid ASCII character.
1387 TerminalIsValidAscii (
1392 Detects if a valid EFI control character.
1394 @param CharC An input EFI Control character.
1396 @retval TRUE If it is a valid EFI control character.
1397 @retval FALSE If it is not a valid EFI control character.
1401 TerminalIsValidEfiCntlChar (