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.
21 #include <Guid/GlobalVariable.h>
22 #include <Guid/PcAnsi.h>
24 #include <Protocol/SimpleTextInExNotify.h>
25 #include <Protocol/HotPlugDevice.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];
66 #define TERMINAL_DEV_SIGNATURE SIGNATURE_32 ('t', 'm', 'n', 'l')
68 #define TERMINAL_CONSOLE_IN_EX_NOTIFY_SIGNATURE SIGNATURE_32 ('t', 'm', 'e', 'n')
70 typedef struct _TERMINAL_CONSOLE_IN_EX_NOTIFY
{
72 EFI_HANDLE NotifyHandle
;
74 EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn
;
75 LIST_ENTRY NotifyEntry
;
76 } TERMINAL_CONSOLE_IN_EX_NOTIFY
;
81 EFI_SERIAL_IO_PROTOCOL
*SerialIo
;
82 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
83 EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleInput
;
84 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL SimpleTextOutput
;
85 EFI_SIMPLE_TEXT_OUTPUT_MODE SimpleTextOutputMode
;
86 UINTN SerialInTimeOut
;
87 RAW_DATA_FIFO
*RawFiFo
;
88 UNICODE_FIFO
*UnicodeFiFo
;
89 EFI_KEY_FIFO
*EfiKeyFiFo
;
90 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
91 EFI_EVENT TwoSecondTimeOut
;
96 // Esc could not be output to the screen by user,
97 // but the terminal driver need to output it to
98 // the terminal emulation software to send control sequence.
99 // This boolean is used by the terminal driver only
100 // to indicate whether the Esc could be sent or not.
102 BOOLEAN OutputEscChar
;
103 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL SimpleInputEx
;
104 LIST_ENTRY NotifyList
;
107 #define INPUT_STATE_DEFAULT 0x00
108 #define INPUT_STATE_ESC 0x01
109 #define INPUT_STATE_CSI 0x02
110 #define INPUT_STATE_LEFTOPENBRACKET 0x04
111 #define INPUT_STATE_O 0x08
112 #define INPUT_STATE_2 0x10
114 #define RESET_STATE_DEFAULT 0x00
115 #define RESET_STATE_ESC_R 0x01
116 #define RESET_STATE_ESC_R_ESC_r 0x02
118 #define TERMINAL_CON_IN_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleInput, TERMINAL_DEV_SIGNATURE)
119 #define TERMINAL_CON_OUT_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleTextOutput, TERMINAL_DEV_SIGNATURE)
120 #define TERMINAL_CON_IN_EX_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleInputEx, TERMINAL_DEV_SIGNATURE)
130 #define VT100PLUSTYPE 2
133 #define LEFTOPENBRACKET 0x5b // '['
139 #define MODE0_COLUMN_COUNT 80
140 #define MODE0_ROW_COUNT 25
142 #define MODE1_COLUMN_COUNT 80
143 #define MODE1_ROW_COUNT 50
145 #define MODE2_COLUMN_COUNT 100
146 #define MODE2_ROW_COUNT 31
152 #define BRIGHT_CONTROL_OFFSET 2
153 #define FOREGROUND_CONTROL_OFFSET 6
154 #define BACKGROUND_CONTROL_OFFSET 11
156 #define COLUMN_OFFSET 5
167 extern EFI_DRIVER_BINDING_PROTOCOL gTerminalDriverBinding
;
168 extern EFI_COMPONENT_NAME_PROTOCOL gTerminalComponentName
;
169 extern EFI_COMPONENT_NAME2_PROTOCOL gTerminalComponentName2
;
172 The user Entry Point for module Terminal. The user code starts with this function.
174 @param[in] ImageHandle The firmware allocated handle for the EFI image.
175 @param[in] SystemTable A pointer to the EFI System Table.
177 @retval EFI_SUCCESS The entry point is executed successfully.
178 @retval other Some error occurs when executing this entry point.
184 IN EFI_HANDLE ImageHandle
,
185 IN EFI_SYSTEM_TABLE
*SystemTable
189 Implements EFI_SIMPLE_TEXT_INPUT_PROTOCOL.Reset().
190 This driver only perform dependent serial device reset regardless of
191 the value of ExtendeVerification
193 @param This Indicates the calling context.
194 @param ExtendedVerification Skip by this driver.
196 @retval EFI_SUCCESS The reset operation succeeds.
197 @retval EFI_DEVICE_ERROR The dependent serial port reset fails.
203 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
204 IN BOOLEAN ExtendedVerification
209 Implements EFI_SIMPLE_TEXT_INPUT_PROTOCOL.ReadKeyStroke().
211 @param This Indicates the calling context.
212 @param Key A pointer to a buffer that is filled in with the
213 keystroke information for the key that was sent
216 @retval EFI_SUCCESS The keystroke information is returned successfully.
217 @retval EFI_NOT_READY There is no keystroke data available.
218 @retval EFI_DEVICE_ERROR The dependent serial device encounters error.
223 TerminalConInReadKeyStroke (
224 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
225 OUT EFI_INPUT_KEY
*Key
229 Check if the key already has been registered.
231 @param RegsiteredData A pointer to a buffer that is filled in with the
232 keystroke state data for the key that was
234 @param InputData A pointer to a buffer that is filled in with the
235 keystroke state data for the key that was
238 @retval TRUE Key be pressed matches a registered key.
239 @retval FLASE Match failed.
244 IN EFI_KEY_DATA
*RegsiteredData
,
245 IN EFI_KEY_DATA
*InputData
249 Event notification function for EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx event
250 Signal the event if there is key available
252 @param Event Indicates the event that invoke this function.
253 @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.
388 TerminalConInWaitForKey (
394 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset().
395 If ExtendeVerification is TRUE, then perform dependent serial device reset,
396 and set display mode to mode 0.
397 If ExtendedVerification is FALSE, only set display mode to mode 0.
399 @param This Indicates the calling context.
400 @param ExtendedVerification Indicates that the driver may perform a more
401 exhaustive verification operation of the device
404 @retval EFI_SUCCESS The reset operation succeeds.
405 @retval EFI_DEVICE_ERROR The terminal is not functioning correctly or the serial port reset fails.
410 TerminalConOutReset (
411 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
412 IN BOOLEAN ExtendedVerification
416 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString().
417 The Unicode string will be converted to terminal expressible data stream
418 and send to terminal via serial port.
420 @param This Indicates the calling context.
421 @param WString The Null-terminated Unicode string to be displayed
422 on the terminal screen.
424 @retval EFI_SUCCESS The string is output successfully.
425 @retval EFI_DEVICE_ERROR The serial port fails to send the string out.
426 @retval EFI_WARN_UNKNOWN_GLYPH Indicates that some of the characters in the Unicode string could not
427 be rendered and are skipped.
428 @retval EFI_UNSUPPORTED If current display mode is out of range.
433 TerminalConOutOutputString (
434 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
439 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.TestString().
440 If one of the characters in the *Wstring is
441 neither valid Unicode drawing characters,
442 not ASCII code, then this function will return
445 @param This Indicates the calling context.
446 @param WString The Null-terminated Unicode string to be tested.
448 @retval EFI_SUCCESS The terminal is capable of rendering the output string.
449 @retval EFI_UNSUPPORTED Some of the characters in the Unicode string cannot be rendered.
454 TerminalConOutTestString (
455 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
460 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.QueryMode().
461 It returns information for an available text mode
462 that the terminal supports.
463 In this driver, we support text mode 80x25 (mode 0),
464 80x50 (mode 1), 100x31 (mode 2).
466 @param This Indicates the calling context.
467 @param ModeNumber The mode number to return information on.
468 @param Columns The returned columns of the requested mode.
469 @param Rows The returned rows of the requested mode.
471 @retval EFI_SUCCESS The requested mode information is returned.
472 @retval EFI_UNSUPPORTED The mode number is not valid.
473 @retval EFI_DEVICE_ERROR
478 TerminalConOutQueryMode (
479 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
486 Implements EFI_SIMPLE_TEXT_OUT.SetMode().
487 Set the terminal to a specified display mode.
488 In this driver, we only support mode 0.
490 @param This Indicates the calling context.
491 @param ModeNumber The text mode to set.
493 @retval EFI_SUCCESS The requested text mode is set.
494 @retval EFI_DEVICE_ERROR The requested text mode cannot be set
495 because of serial device error.
496 @retval EFI_UNSUPPORTED The text mode number is not valid.
501 TerminalConOutSetMode (
502 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
507 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetAttribute().
509 @param This Indicates the calling context.
510 @param Attribute The attribute to set. Only bit0..6 are valid, all other bits
511 are undefined and must be zero.
513 @retval EFI_SUCCESS The requested attribute is set.
514 @retval EFI_DEVICE_ERROR The requested attribute cannot be set due to serial port error.
515 @retval EFI_UNSUPPORTED The attribute requested is not defined by EFI spec.
520 TerminalConOutSetAttribute (
521 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
526 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.ClearScreen().
527 It clears the ANSI terminal's display to the
528 currently selected background color.
530 @param This Indicates the calling context.
532 @retval EFI_SUCCESS The operation completed successfully.
533 @retval EFI_DEVICE_ERROR The terminal screen cannot be cleared due to serial port error.
534 @retval EFI_UNSUPPORTED The terminal is not in a valid display mode.
539 TerminalConOutClearScreen (
540 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
544 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetCursorPosition().
546 @param This Indicates the calling context.
547 @param Column The row to set cursor to.
548 @param Row The column to set cursor to.
550 @retval EFI_SUCCESS The operation completed successfully.
551 @retval EFI_DEVICE_ERROR The request fails due to serial port error.
552 @retval EFI_UNSUPPORTED The terminal is not in a valid text mode, or the cursor position
553 is invalid for current mode.
558 TerminalConOutSetCursorPosition (
559 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
565 Implements SIMPLE_TEXT_OUTPUT.EnableCursor().
566 In this driver, the cursor cannot be hidden.
568 @param This Indicates the calling context.
569 @param Visible If TRUE, the cursor is set to be visible,
570 If FALSE, the cursor is set to be invisible.
572 @retval EFI_SUCCESS The request is valid.
573 @retval EFI_UNSUPPORTED The terminal does not support cursor hidden.
578 TerminalConOutEnableCursor (
579 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
584 Test to see if this driver supports Controller.
586 @param This Protocol instance pointer.
587 @param ControllerHandle Handle of device to test
588 @param RemainingDevicePath Optional parameter use to pick a specific child
591 @retval EFI_SUCCESS This driver supports this device.
592 @retval EFI_ALREADY_STARTED This driver is already running on this device.
593 @retval other This driver does not support this device.
598 TerminalDriverBindingSupported (
599 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
600 IN EFI_HANDLE ControllerHandle
,
601 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
605 Start this driver on Controller by opening a Serial IO protocol,
606 reading Device Path, and creating a child handle with a Simple Text In,
607 Simple Text In Ex and Simple Text Out protocol, and device path protocol.
608 And store Console Device Environment Variables.
610 @param This Protocol instance pointer.
611 @param Controller Handle of device to bind driver to
612 @param RemainingDevicePath Optional parameter use to pick a specific child
615 @retval EFI_SUCCESS This driver is added to Controller.
616 @retval EFI_ALREADY_STARTED This driver is already running on Controller.
617 @retval other This driver does not support this device.
622 TerminalDriverBindingStart (
623 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
624 IN EFI_HANDLE Controller
,
625 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
630 Stop this driver on Controller by closing Simple Text In, Simple Text
631 In Ex, Simple Text Out protocol, and removing parent device path from
632 Console Device Environment Variables.
634 @param This Protocol instance pointer.
635 @param Controller Handle of device to stop driver on
636 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
637 children is zero stop the entire bus driver.
638 @param ChildHandleBuffer List of Child Handles to Stop.
640 @retval EFI_SUCCESS This driver is removed Controller.
641 @retval other This driver could not be removed from this device.
646 TerminalDriverBindingStop (
647 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
648 IN EFI_HANDLE Controller
,
649 IN UINTN NumberOfChildren
,
650 IN EFI_HANDLE
*ChildHandleBuffer
654 Free notify functions list.
656 @param ListHead The list head
658 @retval EFI_SUCCESS Free the notify list successfully.
659 @retval EFI_INVALID_PARAMETER ListHead is NULL.
663 TerminalFreeNotifyList (
664 IN OUT LIST_ENTRY
*ListHead
668 Retrieves a Unicode string that is the user readable name of the driver.
670 This function retrieves the user readable name of a driver in the form of a
671 Unicode string. If the driver specified by This has a user readable name in
672 the language specified by Language, then a pointer to the driver name is
673 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
674 by This does not support the language specified by Language,
675 then EFI_UNSUPPORTED is returned.
677 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
678 EFI_COMPONENT_NAME_PROTOCOL instance.
680 @param Language[in] A pointer to a Null-terminated ASCII string
681 array indicating the language. This is the
682 language of the driver name that the caller is
683 requesting, and it must match one of the
684 languages specified in SupportedLanguages. The
685 number of languages supported by a driver is up
686 to the driver writer. Language is specified
687 in RFC 3066 or ISO 639-2 language code format.
689 @param DriverName[out] A pointer to the Unicode string to return.
690 This Unicode string is the name of the
691 driver specified by This in the language
692 specified by Language.
694 @retval EFI_SUCCESS The Unicode string for the Driver specified by
695 This and the language specified by Language was
696 returned in DriverName.
698 @retval EFI_INVALID_PARAMETER Language is NULL.
700 @retval EFI_INVALID_PARAMETER DriverName is NULL.
702 @retval EFI_UNSUPPORTED The driver specified by This does not support
703 the language specified by Language.
708 TerminalComponentNameGetDriverName (
709 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
711 OUT CHAR16
**DriverName
716 Retrieves a Unicode string that is the user readable name of the controller
717 that is being managed by a driver.
719 This function retrieves the user readable name of the controller specified by
720 ControllerHandle and ChildHandle in the form of a Unicode string. If the
721 driver specified by This has a user readable name in the language specified by
722 Language, then a pointer to the controller name is returned in ControllerName,
723 and EFI_SUCCESS is returned. If the driver specified by This is not currently
724 managing the controller specified by ControllerHandle and ChildHandle,
725 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
726 support the language specified by Language, then EFI_UNSUPPORTED is returned.
728 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
729 EFI_COMPONENT_NAME_PROTOCOL instance.
731 @param ControllerHandle[in] The handle of a controller that the driver
732 specified by This is managing. This handle
733 specifies the controller whose name is to be
736 @param ChildHandle[in] The handle of the child controller to retrieve
737 the name of. This is an optional parameter that
738 may be NULL. It will be NULL for device
739 drivers. It will also be NULL for a bus drivers
740 that wish to retrieve the name of the bus
741 controller. It will not be NULL for a bus
742 driver that wishes to retrieve the name of a
745 @param Language[in] A pointer to a Null-terminated ASCII string
746 array indicating the language. This is the
747 language of the driver name that the caller is
748 requesting, and it must match one of the
749 languages specified in SupportedLanguages. The
750 number of languages supported by a driver is up
751 to the driver writer. Language is specified in
752 RFC 3066 or ISO 639-2 language code format.
754 @param ControllerName[out] A pointer to the Unicode string to return.
755 This Unicode string is the name of the
756 controller specified by ControllerHandle and
757 ChildHandle in the language specified by
758 Language from the point of view of the driver
761 @retval EFI_SUCCESS The Unicode string for the user readable name in
762 the language specified by Language for the
763 driver specified by This was returned in
766 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
768 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
771 @retval EFI_INVALID_PARAMETER Language is NULL.
773 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
775 @retval EFI_UNSUPPORTED The driver specified by This is not currently
776 managing the controller specified by
777 ControllerHandle and ChildHandle.
779 @retval EFI_UNSUPPORTED The driver specified by This does not support
780 the language specified by Language.
785 TerminalComponentNameGetControllerName (
786 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
787 IN EFI_HANDLE ControllerHandle
,
788 IN EFI_HANDLE ChildHandle OPTIONAL
,
790 OUT CHAR16
**ControllerName
795 // internal functions
799 Check for a pending key in the Efi Key FIFO or Serial device buffer.
801 @param This Indicates the calling context.
803 @retval EFI_SUCCESS There is key pending.
804 @retval EFI_NOT_READY There is no key pending.
805 @retval EFI_DEVICE_ERROR If Serial IO is not attached to serial device.
809 TerminalConInCheckForKey (
810 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
814 Update terminal device path in Console Device Environment Variables.
816 @param VariableName The Console Device Environment Variable.
817 @param ParentDevicePath The terminal device path to be updated.
823 TerminalUpdateConsoleDevVariable (
824 IN CHAR16
*VariableName
,
825 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
829 Remove console device variable.
831 @param VariableName A pointer to the variable name.
832 @param ParentDevicePath A pointer to the parent device path.
836 TerminalRemoveConsoleDevVariable (
837 IN CHAR16
*VariableName
,
838 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
842 Read the EFI variable (VendorGuid/Name) and return a dynamically allocated
843 buffer, and the size of the buffer. On failure return NULL.
845 @param Name String part of EFI variable name
846 @param VendorGuid GUID part of EFI variable name
847 @param VariableSize Returns the size of the EFI variable that was read
849 @return Dynamically allocated memory that contains a copy of the EFI variable.
850 Caller is repsoncible freeing the buffer. If variable was not read,
855 TerminalGetVariableAndSize (
857 IN EFI_GUID
*VendorGuid
,
858 OUT UINTN
*VariableSize
862 Build termial device path according to terminal type.
864 @param TerminalType The terminal type is PC ANSI, VT100, VT100+ or VT-UTF8.
865 @param ParentDevicePath Parent device path.
866 @param TerminalDevicePath Returned terminal device path, if building successfully.
868 @retval EFI_UNSUPPORTED Terminal does not belong to the supported type.
869 @retval EFI_OUT_OF_RESOURCES Generate terminal device path failed.
870 @retval EFI_SUCCESS Build terminal device path successfully.
874 SetTerminalDevicePath (
875 IN UINT8 TerminalType
,
876 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
877 OUT EFI_DEVICE_PATH_PROTOCOL
**TerminalDevicePath
881 Get one key out of serial buffer.
883 @param SerialIo Serial I/O protocl attached to the serial device.
884 @param Input The fetched key.
886 @retval EFI_NOT_READY If serial buffer is empty.
887 @retval EFI_DEVICE_ERROR If reading serial buffer encounter error.
888 @retval EFI_SUCCESS If reading serial buffer successfully, put
889 the fetched key to the parameter output.
893 GetOneKeyFromSerial (
894 EFI_SERIAL_IO_PROTOCOL
*SerialIo
,
899 Insert one byte raw data into the Raw Data FIFO.
901 @param TerminalDevice Terminal driver private structure.
902 @param Input The key will be input.
904 @retval TRUE If insert successfully.
905 @retval FLASE If Raw Data buffer is full before key insertion,
910 RawFiFoInsertOneKey (
911 TERMINAL_DEV
*TerminalDevice
,
916 Remove one pre-fetched key out of the Raw Data FIFO.
918 @param TerminalDevice Terminal driver private structure.
919 @param Output The key will be removed.
921 @retval TRUE If insert successfully.
922 @retval FLASE If Raw Data FIFO buffer is empty before remove operation.
926 RawFiFoRemoveOneKey (
927 TERMINAL_DEV
*TerminalDevice
,
932 Clarify whether Raw Data FIFO buffer is empty.
934 @param TerminalDevice Terminal driver private structure
936 @retval TRUE If Raw Data FIFO buffer is empty.
937 @retval FLASE If Raw Data FIFO buffer is not empty.
942 TERMINAL_DEV
*TerminalDevice
946 Clarify whether Raw Data FIFO buffer is full.
948 @param TerminalDevice Terminal driver private structure
950 @retval TRUE If Raw Data FIFO buffer is full.
951 @retval FLASE If Raw Data FIFO buffer is not full.
956 TERMINAL_DEV
*TerminalDevice
960 Insert one pre-fetched key into the FIFO buffer.
962 @param TerminalDevice Terminal driver private structure.
963 @param Key The key will be input.
965 @retval TRUE If insert successfully.
966 @retval FLASE If FIFO buffer is full before key insertion,
971 EfiKeyFiFoInsertOneKey (
972 TERMINAL_DEV
*TerminalDevice
,
977 Remove one pre-fetched key out of the FIFO buffer.
979 @param TerminalDevice Terminal driver private structure.
980 @param Output The key will be removed.
982 @retval TRUE If insert successfully.
983 @retval FLASE If FIFO buffer is empty before remove operation.
987 EfiKeyFiFoRemoveOneKey (
988 TERMINAL_DEV
*TerminalDevice
,
989 EFI_INPUT_KEY
*Output
993 Clarify whether FIFO buffer is empty.
995 @param TerminalDevice Terminal driver private structure
997 @retval TRUE If FIFO buffer is empty.
998 @retval FLASE If FIFO buffer is not empty.
1003 TERMINAL_DEV
*TerminalDevice
1007 Clarify whether FIFO buffer is full.
1009 @param TerminalDevice Terminal driver private structure
1011 @retval TRUE If FIFO buffer is full.
1012 @retval FLASE If FIFO buffer is not full.
1017 TERMINAL_DEV
*TerminalDevice
1021 Insert one pre-fetched key into the Unicode FIFO buffer.
1023 @param TerminalDevice Terminal driver private structure.
1024 @param Input The key will be input.
1026 @retval TRUE If insert successfully.
1027 @retval FLASE If Unicode FIFO buffer is full before key insertion,
1028 and the key is lost.
1032 UnicodeFiFoInsertOneKey (
1033 TERMINAL_DEV
*TerminalDevice
,
1038 Remove one pre-fetched key out of the Unicode FIFO buffer.
1040 @param TerminalDevice Terminal driver private structure.
1041 @param Output The key will be removed.
1043 @retval TRUE If insert successfully.
1044 @retval FLASE If Unicode FIFO buffer is empty before remove operation.
1048 UnicodeFiFoRemoveOneKey (
1049 TERMINAL_DEV
*TerminalDevice
,
1054 Clarify whether Unicode FIFO buffer is empty.
1056 @param TerminalDevice Terminal driver private structure
1058 @retval TRUE If Unicode FIFO buffer is empty.
1059 @retval FLASE If Unicode FIFO buffer is not empty.
1063 IsUnicodeFiFoEmpty (
1064 TERMINAL_DEV
*TerminalDevice
1068 Clarify whether Unicode FIFO buffer is full.
1070 @param TerminalDevice Terminal driver private structure
1072 @retval TRUE If Unicode FIFO buffer is full.
1073 @retval FLASE If Unicode FIFO buffer is not full.
1078 TERMINAL_DEV
*TerminalDevice
1082 Count Unicode FIFO buffer.
1084 @param TerminalDevice Terminal driver private structure
1086 @return The count in bytes of Unicode FIFO.
1090 UnicodeFiFoGetKeyCount (
1091 TERMINAL_DEV
*TerminalDevice
1095 Translate raw data into Unicode (according to different encode), and
1096 translate Unicode into key information. (according to different standard).
1098 @param TerminalDevice Terminal driver private structure.
1102 TranslateRawDataToEfiKey (
1103 IN TERMINAL_DEV
*TerminalDevice
1107 // internal functions for PC ANSI
1111 Translate all raw data in the Raw FIFI into unicode, and insert
1112 them into Unicode FIFO.
1114 @param TerminalDevice The terminal device.
1118 AnsiRawDataToUnicode (
1119 IN TERMINAL_DEV
*TerminalDevice
1123 Converts a stream of Unicode characters from a terminal input device into EFI Keys that
1124 can be read through the Simple Input Protocol.
1126 The table below shows the keyboard input mappings that this function supports.
1127 If the ESC sequence listed in one of the columns is presented, then it is translated
1128 into the coorespoding EFI Scan Code. If a matching sequence is not found, then the raw
1129 key strokes are converted into EFI Keys.
1131 2 seconds are allowed for an ESC sequence to be completed. If the ESC sequence is not
1132 completed in 2 seconds, then the raw key strokes of the partial ESC sequence are
1133 converted into EFI Keys.
1134 There is one special input sequence that will force the system to reset.
1135 This is ESC R ESC r ESC R.
1137 Symbols used in table below
1138 ===========================
1143 +=========+======+===========+==========+==========+
1144 | | EFI | UEFI 2.0 | | |
1145 | | Scan | | VT100+ | |
1146 | KEY | Code | PC ANSI | VTUTF8 | VT100 |
1147 +=========+======+===========+==========+==========+
1148 | NULL | 0x00 | | | |
1149 | UP | 0x01 | ESC [ A | ESC [ A | ESC [ A |
1150 | DOWN | 0x02 | ESC [ B | ESC [ B | ESC [ B |
1151 | RIGHT | 0x03 | ESC [ C | ESC [ C | ESC [ C |
1152 | LEFT | 0x04 | ESC [ D | ESC [ D | ESC [ D |
1153 | HOME | 0x05 | ESC [ H | ESC h | ESC [ H |
1154 | END | 0x06 | ESC [ F | ESC k | ESC [ K |
1155 | INSERT | 0x07 | ESC [ @ | ESC + | ESC [ @ |
1156 | | | ESC [ L | | ESC [ L |
1157 | DELETE | 0x08 | ESC [ X | ESC - | ESC [ P |
1158 | PG UP | 0x09 | ESC [ I | ESC ? | ESC [ V |
1160 | PG DOWN | 0x0A | ESC [ G | ESC / | ESC [ U |
1162 | F1 | 0x0B | ESC [ M | ESC 1 | ESC O P |
1163 | F2 | 0x0C | ESC [ N | ESC 2 | ESC O Q |
1164 | F3 | 0x0D | ESC [ O | ESC 3 | ESC O w |
1165 | F4 | 0x0E | ESC [ P | ESC 4 | ESC O x |
1166 | F5 | 0x0F | ESC [ Q | ESC 5 | ESC O t |
1167 | F6 | 0x10 | ESC [ R | ESC 6 | ESC O u |
1168 | F7 | 0x11 | ESC [ S | ESC 7 | ESC O q |
1169 | F8 | 0x12 | ESC [ T | ESC 8 | ESC O r |
1170 | F9 | 0x13 | ESC [ U | ESC 9 | ESC O p |
1171 | F10 | 0x14 | ESC [ V | ESC 0 | ESC O M |
1172 | Escape | 0x17 | ESC | ESC | ESC |
1173 | F11 | 0x15 | | ESC ! | |
1174 | F12 | 0x16 | | ESC @ | |
1175 +=========+======+===========+==========+==========+
1179 ESC R ESC r ESC R = Reset System
1182 @param TerminalDevice The terminal device to use to translate raw input into EFI Keys
1187 IN TERMINAL_DEV
*TerminalDevice
1191 Check if input string is valid Ascii string, valid EFI control characters
1192 or valid text graphics.
1194 @param TerminalDevice The terminal device.
1195 @param WString The input string.
1197 @retval EFI_UNSUPPORTED If not all input characters are valid.
1198 @retval EFI_SUCCESS If all input characters are valid.
1203 IN TERMINAL_DEV
*TerminalDevice
,
1208 // internal functions for VTUTF8
1212 Translate all VT-UTF8 characters in the Raw FIFI into unicode characters,
1213 and insert them into Unicode FIFO.
1215 @param VtUtf8Device The terminal device.
1219 VTUTF8RawDataToUnicode (
1220 IN TERMINAL_DEV
*VtUtf8Device
1224 Check if input string is valid VT-UTF8 string.
1226 @param TerminalDevice The terminal device.
1227 @param WString The input string.
1229 @retval EFI_SUCCESS If all input characters are valid.
1234 IN TERMINAL_DEV
*TerminalDevice
,
1239 Translate one Unicode character into VT-UTF8 characters.
1242 Bits per Character | Unicode Character Range | Unicode Binary Encoding | UTF8 Binary Encoding
1243 0-7 | 0x0000 - 0x007F | 00000000 0xxxxxxx | 0xxxxxxx
1244 8-11 | 0x0080 - 0x07FF | 00000xxx xxxxxxxx | 110xxxxx 10xxxxxx
1245 12-16 | 0x0800 - 0xFFFF | xxxxxxxx xxxxxxxx | 1110xxxx 10xxxxxx 10xxxxxx
1248 @param Unicode Unicode character need translating.
1249 @param Utf8Char Return VT-UTF8 character set.
1250 @param ValidBytes The count of valid VT-UTF8 characters. If
1251 ValidBytes is zero, no valid VT-UTF8 returned.
1257 OUT UTF8_CHAR
*Utf8Char
,
1258 OUT UINT8
*ValidBytes
1262 Get one valid VT-UTF8 characters set from Raw Data FIFO.
1264 @param Utf8Device The terminal device.
1265 @param Utf8Char Returned valid VT-UTF8 characters set.
1266 @param ValidBytes The count of returned VT-VTF8 characters.
1267 If ValidBytes is zero, no valid VT-UTF8 returned.
1271 GetOneValidUtf8Char (
1272 IN TERMINAL_DEV
*Utf8Device
,
1273 OUT UTF8_CHAR
*Utf8Char
,
1274 OUT UINT8
*ValidBytes
1278 Translate VT-UTF8 characters into one Unicode character.
1281 Bits per Character | Unicode Character Range | Unicode Binary Encoding | UTF8 Binary Encoding
1282 0-7 | 0x0000 - 0x007F | 00000000 0xxxxxxx | 0xxxxxxx
1283 8-11 | 0x0080 - 0x07FF | 00000xxx xxxxxxxx | 110xxxxx 10xxxxxx
1284 12-16 | 0x0800 - 0xFFFF | xxxxxxxx xxxxxxxx | 1110xxxx 10xxxxxx 10xxxxxx
1287 @param Utf8Char VT-UTF8 character set needs translating.
1288 @param ValidBytes The count of valid VT-UTF8 characters.
1289 @param UnicodeChar Returned unicode character.
1294 IN UTF8_CHAR Utf8Char
,
1295 IN UINT8 ValidBytes
,
1296 OUT CHAR16
*UnicodeChar
1300 // functions for boxdraw unicode
1304 Detects if a Unicode char is for Box Drawing text graphics.
1306 @param Graphic Unicode char to test.
1307 @param PcAnsi Optional pointer to return PCANSI equivalent of
1309 @param Ascii Optional pointer to return ASCII equivalent of
1312 @retval TRUE If Graphic is a supported Unicode Box Drawing character.
1316 TerminalIsValidTextGraphics (
1318 OUT CHAR8
*PcAnsi
, OPTIONAL
1319 OUT CHAR8
*Ascii OPTIONAL
1323 Detects if a valid ASCII char.
1325 @param Ascii An ASCII character.
1327 @retval TRUE If it is a valid ASCII character.
1328 @retval FALSE If it is not a valid ASCII character.
1332 TerminalIsValidAscii (
1337 Detects if a valid EFI control character.
1339 @param CharC An input EFI Control character.
1341 @retval TRUE If it is a valid EFI control character.
1342 @retval FALSE If it is not a valid EFI control character.
1346 TerminalIsValidEfiCntlChar (