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 EFI_SIGNATURE_32 ('t', 'm', 'n', 'l')
64 #define TERMINAL_CONSOLE_IN_EX_NOTIFY_SIGNATURE EFI_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
188 Implements EFI_SIMPLE_TEXT_INPUT_PROTOCOL.Reset().
189 This driver only perform dependent serial device reset regardless of
190 the value of ExtendeVerification
192 @param This Indicates the calling context.
193 @param ExtendedVerification Skip by this driver.
195 @return EFI_SUCCESS The reset operation succeeds.
196 @return EFI_DEVICE_ERROR The dependent serial port reset fails.
202 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
203 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 @return EFI_SUCCESS The keystroke information is returned successfully.
217 @return EFI_NOT_READY There is no keystroke data available.
218 @return 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
230 Check if the key already has been registered.
232 @param RegsiteredData A pointer to a buffer that is filled in with the
233 keystroke state data for the key that was
235 @param InputData A pointer to a buffer that is filled in with the
236 keystroke state data for the key that was
239 @retval TRUE Key be pressed matches a registered key.
240 @retval FLASE Match failed.
245 IN EFI_KEY_DATA
*RegsiteredData
,
246 IN EFI_KEY_DATA
*InputData
251 Event notification function for EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx event
252 Signal the event if there is key available
254 @param Event Indicates the event that invoke this function.
255 @param Context Indicates the calling context.
262 TerminalConInWaitForKeyEx (
269 // Simple Text Input Ex protocol prototypes
273 Reset the input device and optionaly run diagnostics
275 @param This Protocol instance pointer.
276 @param ExtendedVerification Driver may perform diagnostics on reset.
278 @retval EFI_SUCCESS The device was reset.
279 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
285 TerminalConInResetEx (
286 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
287 IN BOOLEAN ExtendedVerification
292 Reads the next keystroke from the input device. The WaitForKey Event can
293 be used to test for existance of a keystroke via WaitForEvent () call.
295 @param This Protocol instance pointer.
296 @param KeyData A pointer to a buffer that is filled in with the
297 keystroke state data for the key that was
300 @retval EFI_SUCCESS The keystroke information was returned.
301 @retval EFI_NOT_READY There was no keystroke data availiable.
302 @retval EFI_DEVICE_ERROR The keystroke information was not returned due
304 @retval EFI_INVALID_PARAMETER KeyData is NULL.
309 TerminalConInReadKeyStrokeEx (
310 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
311 OUT EFI_KEY_DATA
*KeyData
316 Set certain state for the input device.
318 @param This Protocol instance pointer.
319 @param KeyToggleState A pointer to the EFI_KEY_TOGGLE_STATE to set the
320 state for the input device.
322 @retval EFI_SUCCESS The device state was set successfully.
323 @retval EFI_DEVICE_ERROR The device is not functioning correctly and
324 could not have the setting adjusted.
325 @retval EFI_UNSUPPORTED The device does not have the ability to set its
327 @retval EFI_INVALID_PARAMETER KeyToggleState is NULL.
332 TerminalConInSetState (
333 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
334 IN EFI_KEY_TOGGLE_STATE
*KeyToggleState
339 Register a notification function for a particular keystroke for the input device.
341 @param This Protocol instance pointer.
342 @param KeyData A pointer to a buffer that is filled in with the
343 keystroke information data for the key that was
345 @param KeyNotificationFunction Points to the function to be called when the key
346 sequence is typed specified by KeyData.
347 @param NotifyHandle Points to the unique handle assigned to the
348 registered notification.
350 @retval EFI_SUCCESS The notification function was registered
352 @retval EFI_OUT_OF_RESOURCES Unable to allocate resources for necesssary data
354 @retval EFI_INVALID_PARAMETER KeyData or NotifyHandle is NULL.
359 TerminalConInRegisterKeyNotify (
360 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
361 IN EFI_KEY_DATA
*KeyData
,
362 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction
,
363 OUT EFI_HANDLE
*NotifyHandle
368 Remove a registered notification function from a particular keystroke.
370 @param This Protocol instance pointer.
371 @param NotificationHandle The handle of the notification function being
374 @retval EFI_SUCCESS The notification function was unregistered
376 @retval EFI_INVALID_PARAMETER The NotificationHandle is invalid.
377 @retval EFI_NOT_FOUND Can not find the matching entry in database.
382 TerminalConInUnregisterKeyNotify (
383 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
384 IN EFI_HANDLE NotificationHandle
389 Event notification function for EFI_SIMPLE_TEXT_INPUT_PROTOCOL.WaitForKey event
390 Signal the event if there is key available
392 @param Event Indicates the event that invoke this function.
393 @param Context Indicates the calling context.
400 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 @return EFI_SUCCESS The reset operation succeeds.
418 @return 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
430 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString().
431 The Unicode string will be converted to terminal expressible data stream
432 and send to terminal via serial port.
434 @param This Indicates the calling context.
435 @param WString The Null-terminated Unicode string to be displayed
436 on the terminal screen.
438 @retval EFI_SUCCESS The string is output successfully.
439 @retval EFI_DEVICE_ERROR The serial port fails to send the string out.
440 @retval EFI_WARN_UNKNOWN_GLYPH Indicates that some of the characters in the Unicode string could not
441 be rendered and are skipped.
442 @retval EFI_UNSUPPORTED If current display mode is out of range.
447 TerminalConOutOutputString (
448 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
454 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.TestString().
455 If one of the characters in the *Wstring is
456 neither valid Unicode drawing characters,
457 not ASCII code, then this function will return
460 @param This Indicates the calling context.
461 @param WString The Null-terminated Unicode string to be tested.
463 @return EFI_SUCCESS The terminal is capable of rendering the output string.
464 @return EFI_UNSUPPORTED Some of the characters in the Unicode string cannot be rendered.
469 TerminalConOutTestString (
470 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
476 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.QueryMode().
477 It returns information for an available text mode
478 that the terminal supports.
479 In this driver, we support text mode 80x25 (mode 0),
480 80x50 (mode 1), 100x31 (mode 2).
482 @param This Indicates the calling context.
483 @param ModeNumber The mode number to return information on.
484 @param Columns The returned columns of the requested mode.
485 @param Rows The returned rows of the requested mode.
487 @return EFI_SUCCESS The requested mode information is returned.
488 @return EFI_UNSUPPORTED The mode number is not valid.
489 @return EFI_DEVICE_ERROR
494 TerminalConOutQueryMode (
495 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
503 Implements EFI_SIMPLE_TEXT_OUT.SetMode().
504 Set the terminal to a specified display mode.
505 In this driver, we only support mode 0.
507 @param This Indicates the calling context.
508 @param ModeNumber The text mode to set.
510 @return EFI_SUCCESS The requested text mode is set.
511 @return EFI_DEVICE_ERROR The requested text mode cannot be set
512 because of serial device error.
513 @return EFI_UNSUPPORTED The text mode number is not valid.
518 TerminalConOutSetMode (
519 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
525 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetAttribute().
527 @param This Indicates the calling context.
528 @param Attribute The attribute to set. Only bit0..6 are valid, all other bits
529 are undefined and must be zero.
531 @return EFI_SUCCESS The requested attribute is set.
532 @return EFI_DEVICE_ERROR The requested attribute cannot be set due to serial port error.
533 @return EFI_UNSUPPORTED The attribute requested is not defined by EFI spec.
538 TerminalConOutSetAttribute (
539 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
545 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.ClearScreen().
546 It clears the ANSI terminal's display to the
547 currently selected background color.
549 @param This Indicates the calling context.
551 @return EFI_SUCCESS The operation completed successfully.
552 @return EFI_DEVICE_ERROR The terminal screen cannot be cleared due to serial port error.
553 @return EFI_UNSUPPORTED The terminal is not in a valid display mode.
558 TerminalConOutClearScreen (
559 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
564 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetCursorPosition().
566 @param This Indicates the calling context.
567 @param Column The row to set cursor to.
568 @param Row The column to set cursor to.
570 @return EFI_SUCCESS The operation completed successfully.
571 @return EFI_DEVICE_ERROR The request fails due to serial port error.
572 @return EFI_UNSUPPORTED The terminal is not in a valid text mode, or the cursor position
573 is invalid for current mode.
578 TerminalConOutSetCursorPosition (
579 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
586 Implements SIMPLE_TEXT_OUTPUT.EnableCursor().
587 In this driver, the cursor cannot be hidden.
589 @param This Indicates the calling context.
590 @param Visible If TRUE, the cursor is set to be visible,
591 If FALSE, the cursor is set to be invisible.
593 @return EFI_SUCCESS The request is valid.
594 @return EFI_UNSUPPORTED The terminal does not support cursor hidden.
599 TerminalConOutEnableCursor (
600 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
606 Test to see if this driver supports Controller.
608 @param This Protocol instance pointer.
609 @param Controller Handle of device to test
610 @param RemainingDevicePath Optional parameter use to pick a specific child
613 @retval EFI_SUCCESS This driver supports this device.
614 @retval EFI_ALREADY_STARTED This driver is already running on this device.
615 @retval other This driver does not support this device.
620 TerminalDriverBindingSupported (
621 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
622 IN EFI_HANDLE ControllerHandle
,
623 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
627 Start this driver on Controller by opening a Serial IO protocol,
628 reading Device Path, and creating a child handle with a Simple Text In,
629 Simple Text In Ex and Simple Text Out protocol, and device path protocol.
630 And store Console Device Environment Variables.
632 @param This Protocol instance pointer.
633 @param Controller Handle of device to bind driver to
634 @param RemainingDevicePath Optional parameter use to pick a specific child
637 @retval EFI_SUCCESS This driver is added to Controller.
638 @retval EFI_ALREADY_STARTED This driver is already running on Controller.
639 @retval other This driver does not support this device.
644 TerminalDriverBindingStart (
645 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
646 IN EFI_HANDLE Controller
,
647 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
652 Stop this driver on Controller by closing Simple Text In, Simple Text
653 In Ex, Simple Text Out protocol, and removing parent device path from
654 Console Device Environment Variables.
656 @param This Protocol instance pointer.
657 @param Controller Handle of device to stop driver on
658 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
659 children is zero stop the entire bus driver.
660 @param ChildHandleBuffer List of Child Handles to Stop.
662 @retval EFI_SUCCESS This driver is removed Controller.
663 @retval other This driver could not be removed from this device.
668 TerminalDriverBindingStop (
669 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
670 IN EFI_HANDLE Controller
,
671 IN UINTN NumberOfChildren
,
672 IN EFI_HANDLE
*ChildHandleBuffer
676 Retrieves a Unicode string that is the user readable name of the driver.
678 This function retrieves the user readable name of a driver in the form of a
679 Unicode string. If the driver specified by This has a user readable name in
680 the language specified by Language, then a pointer to the driver name is
681 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
682 by This does not support the language specified by Language,
683 then EFI_UNSUPPORTED is returned.
685 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
686 EFI_COMPONENT_NAME_PROTOCOL instance.
688 @param Language[in] A pointer to a Null-terminated ASCII string
689 array indicating the language. This is the
690 language of the driver name that the caller is
691 requesting, and it must match one of the
692 languages specified in SupportedLanguages. The
693 number of languages supported by a driver is up
694 to the driver writer. Language is specified
695 in RFC 3066 or ISO 639-2 language code format.
697 @param DriverName[out] A pointer to the Unicode string to return.
698 This Unicode string is the name of the
699 driver specified by This in the language
700 specified by Language.
702 @retval EFI_SUCCESS The Unicode string for the Driver specified by
703 This and the language specified by Language was
704 returned in DriverName.
706 @retval EFI_INVALID_PARAMETER Language is NULL.
708 @retval EFI_INVALID_PARAMETER DriverName is NULL.
710 @retval EFI_UNSUPPORTED The driver specified by This does not support
711 the language specified by Language.
716 TerminalComponentNameGetDriverName (
717 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
719 OUT CHAR16
**DriverName
724 Retrieves a Unicode string that is the user readable name of the controller
725 that is being managed by a driver.
727 This function retrieves the user readable name of the controller specified by
728 ControllerHandle and ChildHandle in the form of a Unicode string. If the
729 driver specified by This has a user readable name in the language specified by
730 Language, then a pointer to the controller name is returned in ControllerName,
731 and EFI_SUCCESS is returned. If the driver specified by This is not currently
732 managing the controller specified by ControllerHandle and ChildHandle,
733 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
734 support the language specified by Language, then EFI_UNSUPPORTED is returned.
736 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
737 EFI_COMPONENT_NAME_PROTOCOL instance.
739 @param ControllerHandle[in] The handle of a controller that the driver
740 specified by This is managing. This handle
741 specifies the controller whose name is to be
744 @param ChildHandle[in] The handle of the child controller to retrieve
745 the name of. This is an optional parameter that
746 may be NULL. It will be NULL for device
747 drivers. It will also be NULL for a bus drivers
748 that wish to retrieve the name of the bus
749 controller. It will not be NULL for a bus
750 driver that wishes to retrieve the name of a
753 @param Language[in] A pointer to a Null-terminated ASCII string
754 array indicating the language. This is the
755 language of the driver name that the caller is
756 requesting, and it must match one of the
757 languages specified in SupportedLanguages. The
758 number of languages supported by a driver is up
759 to the driver writer. Language is specified in
760 RFC 3066 or ISO 639-2 language code format.
762 @param ControllerName[out] A pointer to the Unicode string to return.
763 This Unicode string is the name of the
764 controller specified by ControllerHandle and
765 ChildHandle in the language specified by
766 Language from the point of view of the driver
769 @retval EFI_SUCCESS The Unicode string for the user readable name in
770 the language specified by Language for the
771 driver specified by This was returned in
774 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
776 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
779 @retval EFI_INVALID_PARAMETER Language is NULL.
781 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
783 @retval EFI_UNSUPPORTED The driver specified by This is not currently
784 managing the controller specified by
785 ControllerHandle and ChildHandle.
787 @retval EFI_UNSUPPORTED The driver specified by This does not support
788 the language specified by Language.
793 TerminalComponentNameGetControllerName (
794 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
795 IN EFI_HANDLE ControllerHandle
,
796 IN EFI_HANDLE ChildHandle OPTIONAL
,
798 OUT CHAR16
**ControllerName
803 // internal functions
807 Check for a pending key in the Efi Key FIFO or Serial device buffer.
809 @param This Indicates the calling context.
811 @retval EFI_SUCCESS There is key pending.
812 @retval EFI_NOT_READY There is no key pending.
813 @retval EFI_DEVICE_ERROR If Serial IO is not attched to serial device.
817 TerminalConInCheckForKey (
818 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
823 Update terminal device path in Console Device Environment Variables.
825 @param VariableName The Console Device Environment Variable.
826 @param ParentDevicePath The terminal devcie path to be updated.
832 TerminalUpdateConsoleDevVariable (
833 IN CHAR16
*VariableName
,
834 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
839 Remove console device variable.
841 @param VariableName A pointer to the variable name.
842 @param ParentDevicePath A pointer to the parent device path.
848 TerminalRemoveConsoleDevVariable (
849 IN CHAR16
*VariableName
,
850 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
855 Read the EFI variable (VendorGuid/Name) and return a dynamically allocated
856 buffer, and the size of the buffer. On failure return NULL.
858 @param Name String part of EFI variable name
859 @param VendorGuid GUID part of EFI variable name
860 @param VariableSize Returns the size of the EFI variable that was read
862 @return Dynamically allocated memory that contains a copy of the EFI variable.
863 Caller is repsoncible freeing the buffer. If variable was not read,
868 TerminalGetVariableAndSize (
870 IN EFI_GUID
*VendorGuid
,
871 OUT UINTN
*VariableSize
876 Build termial device path according to terminal type.
878 @param TerminalType The terminal type is PC ANSI, VT100, VT100+ or VT-UTF8.
879 @param ParentDevicePath Parent devcie path.
880 @param TerminalDevicePath Returned terminal device path, if building successfully.
882 @retval EFI_UNSUPPORTED Terminal does not belong to the supported type.
883 @retval EFI_OUT_OF_RESOURCES Generate terminal device path failed.
884 @retval EFI_SUCCESS Build terminal device path successfully.
888 SetTerminalDevicePath (
889 IN UINT8 TerminalType
,
890 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
891 OUT EFI_DEVICE_PATH_PROTOCOL
**TerminalDevicePath
896 Initialize the Raw Data FIFO.
898 @param TerminalDevice The terminal device.
905 IN TERMINAL_DEV
*TerminalDevice
910 Initialize the Unicode FIFO.
912 @param TerminalDevice The terminal device.
918 InitializeUnicodeFiFo (
919 IN TERMINAL_DEV
*TerminalDevice
924 Initialize the EFI Key FIFO.
926 @param TerminalDevice The terminal device.
932 InitializeEfiKeyFiFo (
933 IN TERMINAL_DEV
*TerminalDevice
938 Get one key out of serial buffer.
940 @param SerialIo Serial I/O protocl attached to the serial device.
941 @param Input The fetched key.
943 @return EFI_NOT_READY If serial buffer is empty.
944 @return EFI_DEVICE_ERROR If reading serial buffer encounter error.
945 @return EFI_SUCCESS If reading serial buffer successfully, put
946 the fetched key to the parameter output.
950 GetOneKeyFromSerial (
951 EFI_SERIAL_IO_PROTOCOL
*SerialIo
,
957 Insert one byte raw data into the Raw Data FIFO.
959 @param TerminalDevice Terminal driver private structure.
960 @param Input The key will be input.
962 @return TRUE If insert successfully.
963 @return FLASE If Raw Data buffer is full before key insertion,
968 RawFiFoInsertOneKey (
969 TERMINAL_DEV
*TerminalDevice
,
975 Remove one pre-fetched key out of the Raw Data FIFO.
977 @param TerminalDevice Terminal driver private structure.
978 @param Output The key will be removed.
980 @return TRUE If insert successfully.
981 @return FLASE If Raw Data FIFO buffer is empty before remove operation.
985 RawFiFoRemoveOneKey (
986 TERMINAL_DEV
*TerminalDevice
,
992 Clarify whether Raw Data FIFO buffer is empty.
994 @param TerminalDevice Terminal driver private structure
996 @return TRUE If Raw Data FIFO buffer is empty.
997 @return FLASE If Raw Data FIFO buffer is not empty.
1002 TERMINAL_DEV
*TerminalDevice
1007 Clarify whether Raw Data FIFO buffer is full.
1009 @param TerminalDevice Terminal driver private structure
1011 @return TRUE If Raw Data FIFO buffer is full.
1012 @return FLASE If Raw Data FIFO buffer is not full.
1017 TERMINAL_DEV
*TerminalDevice
1022 Insert one pre-fetched key into the FIFO buffer.
1024 @param TerminalDevice Terminal driver private structure.
1025 @param Key The key will be input.
1027 @return TRUE If insert successfully.
1028 @return FLASE If FIFO buffer is full before key insertion,
1029 and the key is lost.
1033 EfiKeyFiFoInsertOneKey (
1034 TERMINAL_DEV
*TerminalDevice
,
1040 Remove one pre-fetched key out of the FIFO buffer.
1042 @param TerminalDevice Terminal driver private structure.
1043 @param Output The key will be removed.
1045 @return TRUE If insert successfully.
1046 @return FLASE If FIFO buffer is empty before remove operation.
1050 EfiKeyFiFoRemoveOneKey (
1051 TERMINAL_DEV
*TerminalDevice
,
1052 EFI_INPUT_KEY
*Output
1057 Clarify whether FIFO buffer is empty.
1059 @param TerminalDevice Terminal driver private structure
1061 @return TRUE If FIFO buffer is empty.
1062 @return FLASE If FIFO buffer is not empty.
1067 TERMINAL_DEV
*TerminalDevice
1072 Clarify whether FIFO buffer is full.
1074 @param TerminalDevice Terminal driver private structure
1076 @return TRUE If FIFO buffer is full.
1077 @return FLASE If FIFO buffer is not full.
1082 TERMINAL_DEV
*TerminalDevice
1087 Insert one pre-fetched key into the Unicode FIFO buffer.
1089 @param TerminalDevice Terminal driver private structure.
1090 @param Input The key will be input.
1092 @return TRUE If insert successfully.
1093 @return FLASE If Unicode FIFO buffer is full before key insertion,
1094 and the key is lost.
1098 UnicodeFiFoInsertOneKey (
1099 TERMINAL_DEV
*TerminalDevice
,
1105 Remove one pre-fetched key out of the Unicode FIFO buffer.
1107 @param TerminalDevice Terminal driver private structure.
1108 @param Output The key will be removed.
1110 @return TRUE If insert successfully.
1111 @return FLASE If Unicode FIFO buffer is empty before remove operation.
1115 UnicodeFiFoRemoveOneKey (
1116 TERMINAL_DEV
*TerminalDevice
,
1122 Clarify whether Unicode FIFO buffer is empty.
1124 @param TerminalDevice Terminal driver private structure
1126 @return TRUE If Unicode FIFO buffer is empty.
1127 @return FLASE If Unicode FIFO buffer is not empty.
1131 IsUnicodeFiFoEmpty (
1132 TERMINAL_DEV
*TerminalDevice
1137 Clarify whether Unicode FIFO buffer is full.
1139 @param TerminalDevice Terminal driver private structure
1141 @return TRUE If Unicode FIFO buffer is full.
1142 @return FLASE If Unicode FIFO buffer is not full.
1147 TERMINAL_DEV
*TerminalDevice
1152 Count Unicode FIFO buffer.
1154 @param TerminalDevice Terminal driver private structure
1156 @return The count in bytes of Unicode FIFO.
1160 UnicodeFiFoGetKeyCount (
1161 TERMINAL_DEV
*TerminalDevice
1166 Translate raw data into Unicode (according to different encode), and
1167 translate Unicode into key information. (according to different standard).
1169 @param TerminalDevice Terminal driver private structure.
1175 TranslateRawDataToEfiKey (
1176 IN TERMINAL_DEV
*TerminalDevice
1181 // internal functions for PC ANSI
1185 Translate all raw data in the Raw FIFI into unicode, and insert
1186 them into Unicode FIFO.
1188 @param TerminalDevice The terminal device.
1194 AnsiRawDataToUnicode (
1195 IN TERMINAL_DEV
*TerminalDevice
1200 Converts a stream of Unicode characters from a terminal input device into EFI Keys that
1201 can be read through the Simple Input Protocol.
1203 The table below shows the keyboard input mappings that this function supports.
1204 If the ESC sequence listed in one of the columns is presented, then it is translated
1205 into the coorespoding EFI Scan Code. If a matching sequence is not found, then the raw
1206 key strokes are converted into EFI Keys.
1208 2 seconds are allowed for an ESC sequence to be completed. If the ESC sequence is not
1209 completed in 2 seconds, then the raw key strokes of the partial ESC sequence are
1210 converted into EFI Keys.
1211 There is one special input sequence that will force the system to reset.
1212 This is ESC R ESC r ESC R.
1214 Symbols used in table below
1215 ===========================
1220 +=========+======+===========+==========+==========+
1221 | | EFI | UEFI 2.0 | | |
1222 | | Scan | | VT100+ | |
1223 | KEY | Code | PC ANSI | VTUTF8 | VT100 |
1224 +=========+======+===========+==========+==========+
1225 | NULL | 0x00 | | | |
1226 | UP | 0x01 | ESC [ A | ESC [ A | ESC [ A |
1227 | DOWN | 0x02 | ESC [ B | ESC [ B | ESC [ B |
1228 | RIGHT | 0x03 | ESC [ C | ESC [ C | ESC [ C |
1229 | LEFT | 0x04 | ESC [ D | ESC [ D | ESC [ D |
1230 | HOME | 0x05 | ESC [ H | ESC h | ESC [ H |
1231 | END | 0x06 | ESC [ F | ESC k | ESC [ K |
1232 | INSERT | 0x07 | ESC [ @ | ESC + | ESC [ @ |
1233 | | | ESC [ L | | ESC [ L |
1234 | DELETE | 0x08 | ESC [ X | ESC - | ESC [ P |
1235 | PG UP | 0x09 | ESC [ I | ESC ? | ESC [ V |
1237 | PG DOWN | 0x0A | ESC [ G | ESC / | ESC [ U |
1239 | F1 | 0x0B | ESC [ M | ESC 1 | ESC O P |
1240 | F2 | 0x0C | ESC [ N | ESC 2 | ESC O Q |
1241 | F3 | 0x0D | ESC [ O | ESC 3 | ESC O w |
1242 | F4 | 0x0E | ESC [ P | ESC 4 | ESC O x |
1243 | F5 | 0x0F | ESC [ Q | ESC 5 | ESC O t |
1244 | F6 | 0x10 | ESC [ R | ESC 6 | ESC O u |
1245 | F7 | 0x11 | ESC [ S | ESC 7 | ESC O q |
1246 | F8 | 0x12 | ESC [ T | ESC 8 | ESC O r |
1247 | F9 | 0x13 | ESC [ U | ESC 9 | ESC O p |
1248 | F10 | 0x14 | ESC [ V | ESC 0 | ESC O M |
1249 | Escape | 0x17 | ESC | ESC | ESC |
1250 | F11 | 0x15 | | ESC ! | |
1251 | F12 | 0x16 | | ESC @ | |
1252 +=========+======+===========+==========+==========+
1256 ESC R ESC r ESC R = Reset System
1259 @param TerminalDevice The terminal device to use to translate raw input into EFI Keys
1266 IN TERMINAL_DEV
*TerminalDevice
1271 Check if input string is valid Ascii string, valid EFI control characters
1272 or valid text graphics.
1274 @param TerminalDevice The terminal device.
1275 @param WString The input string.
1277 @retval EFI_UNSUPPORTED If not all input characters are valid.
1278 @retval EFI_SUCCESS If all input characters are valid.
1283 IN TERMINAL_DEV
*TerminalDevice
,
1289 // internal functions for VTUTF8
1293 Translate all VT-UTF8 characters in the Raw FIFI into unicode characters,
1294 and insert them into Unicode FIFO.
1296 @param VtUtf8Device The terminal device.
1302 VTUTF8RawDataToUnicode (
1303 IN TERMINAL_DEV
*VtUtf8Device
1308 Check if input string is valid VT-UTF8 string.
1310 @param TerminalDevice The terminal device.
1311 @param WString The input string.
1313 @retval EFI_SUCCESS If all input characters are valid.
1318 IN TERMINAL_DEV
*TerminalDevice
,
1324 Translate one Unicode character into VT-UTF8 characters.
1327 Bits per Character | Unicode Character Range | Unicode Binary Encoding | UTF8 Binary Encoding
1328 0-7 | 0x0000 - 0x007F | 00000000 0xxxxxxx | 0xxxxxxx
1329 8-11 | 0x0080 - 0x07FF | 00000xxx xxxxxxxx | 110xxxxx 10xxxxxx
1330 12-16 | 0x0800 - 0xFFFF | xxxxxxxx xxxxxxxx | 1110xxxx 10xxxxxx 10xxxxxx
1333 @param Unicode Unicode character need translating.
1334 @param Utf8Char Return VT-UTF8 character set.
1335 @param ValidBytes The count of valid VT-UTF8 characters. If
1336 ValidBytes is zero, no valid VT-UTF8 returned.
1344 OUT UTF8_CHAR
*Utf8Char
,
1345 OUT UINT8
*ValidBytes
1350 Get one valid VT-UTF8 characters set from Raw Data FIFO.
1352 @param Utf8Device The terminal device.
1353 @param Utf8Char Returned valid VT-UTF8 characters set.
1354 @param ValidBytes The count of returned VT-VTF8 characters.
1355 If ValidBytes is zero, no valid VT-UTF8 returned.
1361 GetOneValidUtf8Char (
1362 IN TERMINAL_DEV
*Utf8Device
,
1363 OUT UTF8_CHAR
*Utf8Char
,
1364 OUT UINT8
*ValidBytes
1369 Translate VT-UTF8 characters into one Unicode character.
1372 Bits per Character | Unicode Character Range | Unicode Binary Encoding | UTF8 Binary Encoding
1373 0-7 | 0x0000 - 0x007F | 00000000 0xxxxxxx | 0xxxxxxx
1374 8-11 | 0x0080 - 0x07FF | 00000xxx xxxxxxxx | 110xxxxx 10xxxxxx
1375 12-16 | 0x0800 - 0xFFFF | xxxxxxxx xxxxxxxx | 1110xxxx 10xxxxxx 10xxxxxx
1378 @param Utf8Char VT-UTF8 character set needs translating.
1379 @param ValidBytes The count of valid VT-UTF8 characters.
1380 @param UnicodeChar Returned unicode character.
1387 IN UTF8_CHAR Utf8Char
,
1388 IN UINT8 ValidBytes
,
1389 OUT CHAR16
*UnicodeChar
1394 // functions for boxdraw unicode
1398 Detects if a Unicode char is for Box Drawing text graphics.
1400 @param Graphic Unicode char to test.
1401 @param PcAnsi Optional pointer to return PCANSI equivalent of
1403 @param Ascii Optional pointer to return ASCII equivalent of
1406 @return TRUE If Graphic is a supported Unicode Box Drawing character.
1410 TerminalIsValidTextGraphics (
1412 OUT CHAR8
*PcAnsi
, OPTIONAL
1413 OUT CHAR8
*Ascii OPTIONAL
1418 Detects if a valid ASCII char.
1420 @param Ascii An ASCII character.
1422 @retval TRUE If it is a valid ASCII character.
1423 @retval FALSE If it is not a valid ASCII character.
1427 TerminalIsValidAscii (
1433 Detects if a valid EFI control character.
1435 @param CharC An input EFI Control character.
1437 @retval TRUE If it is a valid EFI control character.
1438 @retval FALSE If it is not a valid EFI control character.
1442 TerminalIsValidEfiCntlChar (