2 Header file for Terminal driver.
4 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 #include <Guid/GlobalVariable.h>
22 #include <Guid/PcAnsi.h>
24 #include <Protocol/SimpleTextOut.h>
25 #include <Protocol/SerialIo.h>
26 #include <Protocol/DevicePath.h>
27 #include <Protocol/SimpleTextIn.h>
28 #include <Protocol/SimpleTextInEx.h>
30 #include <Library/DebugLib.h>
31 #include <Library/UefiDriverEntryPoint.h>
32 #include <Library/UefiLib.h>
33 #include <Library/ReportStatusCodeLib.h>
34 #include <Library/BaseMemoryLib.h>
35 #include <Library/MemoryAllocationLib.h>
36 #include <Library/UefiBootServicesTableLib.h>
37 #include <Library/UefiRuntimeServicesTableLib.h>
38 #include <Library/DevicePathLib.h>
39 #include <Library/PcdLib.h>
40 #include <Library/BaseLib.h>
43 #define RAW_FIFO_MAX_NUMBER 256
44 #define FIFO_MAX_NUMBER 128
49 UINT8 Data
[RAW_FIFO_MAX_NUMBER
+ 1];
55 UINT16 Data
[FIFO_MAX_NUMBER
+ 1];
61 EFI_INPUT_KEY Data
[FIFO_MAX_NUMBER
+ 1];
64 #define KEYBOARD_TIMER_INTERVAL 200000 // 0.02s
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
;
92 EFI_EVENT TwoSecondTimeOut
;
97 // Esc could not be output to the screen by user,
98 // but the terminal driver need to output it to
99 // the terminal emulation software to send control sequence.
100 // This boolean is used by the terminal driver only
101 // to indicate whether the Esc could be sent or not.
103 BOOLEAN OutputEscChar
;
104 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL SimpleInputEx
;
105 LIST_ENTRY NotifyList
;
108 #define INPUT_STATE_DEFAULT 0x00
109 #define INPUT_STATE_ESC 0x01
110 #define INPUT_STATE_CSI 0x02
111 #define INPUT_STATE_LEFTOPENBRACKET 0x04
112 #define INPUT_STATE_O 0x08
113 #define INPUT_STATE_2 0x10
115 #define RESET_STATE_DEFAULT 0x00
116 #define RESET_STATE_ESC_R 0x01
117 #define RESET_STATE_ESC_R_ESC_R 0x02
119 #define TERMINAL_CON_IN_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleInput, TERMINAL_DEV_SIGNATURE)
120 #define TERMINAL_CON_OUT_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleTextOutput, TERMINAL_DEV_SIGNATURE)
121 #define TERMINAL_CON_IN_EX_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleInputEx, TERMINAL_DEV_SIGNATURE)
131 #define VT100PLUSTYPE 2
134 #define LEFTOPENBRACKET 0x5b // '['
140 #define MODE0_COLUMN_COUNT 80
141 #define MODE0_ROW_COUNT 25
143 #define MODE1_COLUMN_COUNT 80
144 #define MODE1_ROW_COUNT 50
146 #define MODE2_COLUMN_COUNT 100
147 #define MODE2_ROW_COUNT 31
150 // MODE3 is defined by PcdConOutColumn & PcdConOutRow
153 #define TERMINAL_MAX_MODE 4
159 #define BRIGHT_CONTROL_OFFSET 2
160 #define FOREGROUND_CONTROL_OFFSET 6
161 #define BACKGROUND_CONTROL_OFFSET 11
163 #define COLUMN_OFFSET 5
174 extern EFI_DRIVER_BINDING_PROTOCOL gTerminalDriverBinding
;
175 extern EFI_COMPONENT_NAME_PROTOCOL gTerminalComponentName
;
176 extern EFI_COMPONENT_NAME2_PROTOCOL gTerminalComponentName2
;
179 The user Entry Point for module Terminal. The user code starts with this function.
181 @param[in] ImageHandle The firmware allocated handle for the EFI image.
182 @param[in] SystemTable A pointer to the EFI System Table.
184 @retval EFI_SUCCESS The entry point is executed successfully.
185 @retval other Some error occurs when executing this entry point.
191 IN EFI_HANDLE ImageHandle
,
192 IN EFI_SYSTEM_TABLE
*SystemTable
196 Implements EFI_SIMPLE_TEXT_INPUT_PROTOCOL.Reset().
197 This driver only perform dependent serial device reset regardless of
198 the value of ExtendeVerification
200 @param This Indicates the calling context.
201 @param ExtendedVerification Skip by this driver.
203 @retval EFI_SUCCESS The reset operation succeeds.
204 @retval EFI_DEVICE_ERROR The dependent serial port reset fails.
210 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
211 IN BOOLEAN ExtendedVerification
216 Implements EFI_SIMPLE_TEXT_INPUT_PROTOCOL.ReadKeyStroke().
218 @param This Indicates the calling context.
219 @param Key A pointer to a buffer that is filled in with the
220 keystroke information for the key that was sent
223 @retval EFI_SUCCESS The keystroke information is returned successfully.
224 @retval EFI_NOT_READY There is no keystroke data available.
225 @retval EFI_DEVICE_ERROR The dependent serial device encounters error.
230 TerminalConInReadKeyStroke (
231 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
232 OUT EFI_INPUT_KEY
*Key
236 Check if the key already has been registered.
238 @param RegsiteredData A pointer to a buffer that is filled in with the
239 keystroke state data for the key that was
241 @param InputData A pointer to a buffer that is filled in with the
242 keystroke state data for the key that was
245 @retval TRUE Key be pressed matches a registered key.
246 @retval FLASE Match failed.
251 IN EFI_KEY_DATA
*RegsiteredData
,
252 IN EFI_KEY_DATA
*InputData
256 Event notification function for EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx event
257 Signal the event if there is key available
259 @param Event Indicates the event that invoke this function.
260 @param Context Indicates the calling context.
265 TerminalConInWaitForKeyEx (
271 // Simple Text Input Ex protocol prototypes
275 Reset the input device and optionally run diagnostics
277 @param This Protocol instance pointer.
278 @param ExtendedVerification Driver may perform diagnostics on reset.
280 @retval EFI_SUCCESS The device was reset.
281 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
287 TerminalConInResetEx (
288 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
289 IN BOOLEAN ExtendedVerification
293 Reads the next keystroke from the input device. The WaitForKey Event can
294 be used to test for existence of a keystroke via WaitForEvent () call.
296 @param This Protocol instance pointer.
297 @param KeyData A pointer to a buffer that is filled in with the
298 keystroke state data for the key that was
301 @retval EFI_SUCCESS The keystroke information was returned.
302 @retval EFI_NOT_READY There was no keystroke data available.
303 @retval EFI_DEVICE_ERROR The keystroke information was not returned due
305 @retval EFI_INVALID_PARAMETER KeyData is NULL.
310 TerminalConInReadKeyStrokeEx (
311 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
312 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
338 Register a notification function for a particular keystroke for the input device.
340 @param This Protocol instance pointer.
341 @param KeyData A pointer to a buffer that is filled in with the
342 keystroke information data for the key that was
344 @param KeyNotificationFunction Points to the function to be called when the key
345 sequence is typed specified by KeyData.
346 @param NotifyHandle Points to the unique handle assigned to the
347 registered notification.
349 @retval EFI_SUCCESS The notification function was registered
351 @retval EFI_OUT_OF_RESOURCES Unable to allocate resources for necesssary data
353 @retval EFI_INVALID_PARAMETER KeyData or NotifyHandle is NULL.
358 TerminalConInRegisterKeyNotify (
359 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
360 IN EFI_KEY_DATA
*KeyData
,
361 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction
,
362 OUT EFI_HANDLE
*NotifyHandle
366 Remove a registered notification function from a particular keystroke.
368 @param This Protocol instance pointer.
369 @param NotificationHandle The handle of the notification function being
372 @retval EFI_SUCCESS The notification function was unregistered
374 @retval EFI_INVALID_PARAMETER The NotificationHandle is invalid.
375 @retval EFI_NOT_FOUND Can not find the matching entry in database.
380 TerminalConInUnregisterKeyNotify (
381 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
382 IN EFI_HANDLE NotificationHandle
386 Event notification function for EFI_SIMPLE_TEXT_INPUT_PROTOCOL.WaitForKey event
387 Signal the event if there is key available
389 @param Event Indicates the event that invoke this function.
390 @param Context Indicates the calling context.
395 TerminalConInWaitForKey (
401 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset().
402 If ExtendeVerification is TRUE, then perform dependent serial device reset,
403 and set display mode to mode 0.
404 If ExtendedVerification is FALSE, only set display mode to mode 0.
406 @param This Indicates the calling context.
407 @param ExtendedVerification Indicates that the driver may perform a more
408 exhaustive verification operation of the device
411 @retval EFI_SUCCESS The reset operation succeeds.
412 @retval EFI_DEVICE_ERROR The terminal is not functioning correctly or the serial port reset fails.
417 TerminalConOutReset (
418 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
419 IN BOOLEAN ExtendedVerification
423 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString().
424 The Unicode string will be converted to terminal expressible data stream
425 and send to terminal via serial port.
427 @param This Indicates the calling context.
428 @param WString The Null-terminated Unicode string to be displayed
429 on the terminal screen.
431 @retval EFI_SUCCESS The string is output successfully.
432 @retval EFI_DEVICE_ERROR The serial port fails to send the string out.
433 @retval EFI_WARN_UNKNOWN_GLYPH Indicates that some of the characters in the Unicode string could not
434 be rendered and are skipped.
435 @retval EFI_UNSUPPORTED If current display mode is out of range.
440 TerminalConOutOutputString (
441 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
446 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.TestString().
447 If one of the characters in the *Wstring is
448 neither valid Unicode drawing characters,
449 not ASCII code, then this function will return
452 @param This Indicates the calling context.
453 @param WString The Null-terminated Unicode string to be tested.
455 @retval EFI_SUCCESS The terminal is capable of rendering the output string.
456 @retval EFI_UNSUPPORTED Some of the characters in the Unicode string cannot be rendered.
461 TerminalConOutTestString (
462 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
467 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.QueryMode().
468 It returns information for an available text mode
469 that the terminal supports.
470 In this driver, we support text mode 80x25 (mode 0),
471 80x50 (mode 1), 100x31 (mode 2).
473 @param This Indicates the calling context.
474 @param ModeNumber The mode number to return information on.
475 @param Columns The returned columns of the requested mode.
476 @param Rows The returned rows of the requested mode.
478 @retval EFI_SUCCESS The requested mode information is returned.
479 @retval EFI_UNSUPPORTED The mode number is not valid.
480 @retval EFI_DEVICE_ERROR
485 TerminalConOutQueryMode (
486 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
493 Implements EFI_SIMPLE_TEXT_OUT.SetMode().
494 Set the terminal to a specified display mode.
495 In this driver, we only support mode 0.
497 @param This Indicates the calling context.
498 @param ModeNumber The text mode to set.
500 @retval EFI_SUCCESS The requested text mode is set.
501 @retval EFI_DEVICE_ERROR The requested text mode cannot be set
502 because of serial device error.
503 @retval EFI_UNSUPPORTED The text mode number is not valid.
508 TerminalConOutSetMode (
509 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
514 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetAttribute().
516 @param This Indicates the calling context.
517 @param Attribute The attribute to set. Only bit0..6 are valid, all other bits
518 are undefined and must be zero.
520 @retval EFI_SUCCESS The requested attribute is set.
521 @retval EFI_DEVICE_ERROR The requested attribute cannot be set due to serial port error.
522 @retval EFI_UNSUPPORTED The attribute requested is not defined by EFI spec.
527 TerminalConOutSetAttribute (
528 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
533 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.ClearScreen().
534 It clears the ANSI terminal's display to the
535 currently selected background color.
537 @param This Indicates the calling context.
539 @retval EFI_SUCCESS The operation completed successfully.
540 @retval EFI_DEVICE_ERROR The terminal screen cannot be cleared due to serial port error.
541 @retval EFI_UNSUPPORTED The terminal is not in a valid display mode.
546 TerminalConOutClearScreen (
547 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
551 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetCursorPosition().
553 @param This Indicates the calling context.
554 @param Column The row to set cursor to.
555 @param Row The column to set cursor to.
557 @retval EFI_SUCCESS The operation completed successfully.
558 @retval EFI_DEVICE_ERROR The request fails due to serial port error.
559 @retval EFI_UNSUPPORTED The terminal is not in a valid text mode, or the cursor position
560 is invalid for current mode.
565 TerminalConOutSetCursorPosition (
566 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
572 Implements SIMPLE_TEXT_OUTPUT.EnableCursor().
573 In this driver, the cursor cannot be hidden.
575 @param This Indicates the calling context.
576 @param Visible If TRUE, the cursor is set to be visible,
577 If FALSE, the cursor is set to be invisible.
579 @retval EFI_SUCCESS The request is valid.
580 @retval EFI_UNSUPPORTED The terminal does not support cursor hidden.
585 TerminalConOutEnableCursor (
586 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
591 Test to see if this driver supports Controller.
593 @param This Protocol instance pointer.
594 @param ControllerHandle Handle of device to test
595 @param RemainingDevicePath Optional parameter use to pick a specific child
598 @retval EFI_SUCCESS This driver supports this device.
599 @retval EFI_ALREADY_STARTED This driver is already running on this device.
600 @retval other This driver does not support this device.
605 TerminalDriverBindingSupported (
606 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
607 IN EFI_HANDLE ControllerHandle
,
608 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
612 Start this driver on Controller by opening a Serial IO protocol,
613 reading Device Path, and creating a child handle with a Simple Text In,
614 Simple Text In Ex and Simple Text Out protocol, and device path protocol.
615 And store Console Device Environment Variables.
617 @param This Protocol instance pointer.
618 @param Controller Handle of device to bind driver to
619 @param RemainingDevicePath Optional parameter use to pick a specific child
622 @retval EFI_SUCCESS This driver is added to Controller.
623 @retval EFI_ALREADY_STARTED This driver is already running on Controller.
624 @retval other This driver does not support this device.
629 TerminalDriverBindingStart (
630 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
631 IN EFI_HANDLE Controller
,
632 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
637 Stop this driver on Controller by closing Simple Text In, Simple Text
638 In Ex, Simple Text Out protocol, and removing parent device path from
639 Console Device Environment Variables.
641 @param This Protocol instance pointer.
642 @param Controller Handle of device to stop driver on
643 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
644 children is zero stop the entire bus driver.
645 @param ChildHandleBuffer List of Child Handles to Stop.
647 @retval EFI_SUCCESS This driver is removed Controller.
648 @retval other This driver could not be removed from this device.
653 TerminalDriverBindingStop (
654 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
655 IN EFI_HANDLE Controller
,
656 IN UINTN NumberOfChildren
,
657 IN EFI_HANDLE
*ChildHandleBuffer
661 Free notify functions list.
663 @param ListHead The list head
665 @retval EFI_SUCCESS Free the notify list successfully.
666 @retval EFI_INVALID_PARAMETER ListHead is NULL.
670 TerminalFreeNotifyList (
671 IN OUT LIST_ENTRY
*ListHead
675 Retrieves a Unicode string that is the user readable name of the driver.
677 This function retrieves the user readable name of a driver in the form of a
678 Unicode string. If the driver specified by This has a user readable name in
679 the language specified by Language, then a pointer to the driver name is
680 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
681 by This does not support the language specified by Language,
682 then EFI_UNSUPPORTED is returned.
684 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
685 EFI_COMPONENT_NAME_PROTOCOL instance.
687 @param Language[in] A pointer to a Null-terminated ASCII string
688 array indicating the language. This is the
689 language of the driver name that the caller is
690 requesting, and it must match one of the
691 languages specified in SupportedLanguages. The
692 number of languages supported by a driver is up
693 to the driver writer. Language is specified
694 in RFC 4646 or ISO 639-2 language code format.
696 @param DriverName[out] A pointer to the Unicode string to return.
697 This Unicode string is the name of the
698 driver specified by This in the language
699 specified by Language.
701 @retval EFI_SUCCESS The Unicode string for the Driver specified by
702 This and the language specified by Language was
703 returned in DriverName.
705 @retval EFI_INVALID_PARAMETER Language is NULL.
707 @retval EFI_INVALID_PARAMETER DriverName is NULL.
709 @retval EFI_UNSUPPORTED The driver specified by This does not support
710 the language specified by Language.
715 TerminalComponentNameGetDriverName (
716 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
718 OUT CHAR16
**DriverName
723 Retrieves a Unicode string that is the user readable name of the controller
724 that is being managed by a driver.
726 This function retrieves the user readable name of the controller specified by
727 ControllerHandle and ChildHandle in the form of a Unicode string. If the
728 driver specified by This has a user readable name in the language specified by
729 Language, then a pointer to the controller name is returned in ControllerName,
730 and EFI_SUCCESS is returned. If the driver specified by This is not currently
731 managing the controller specified by ControllerHandle and ChildHandle,
732 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
733 support the language specified by Language, then EFI_UNSUPPORTED is returned.
735 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
736 EFI_COMPONENT_NAME_PROTOCOL instance.
738 @param ControllerHandle[in] The handle of a controller that the driver
739 specified by This is managing. This handle
740 specifies the controller whose name is to be
743 @param ChildHandle[in] The handle of the child controller to retrieve
744 the name of. This is an optional parameter that
745 may be NULL. It will be NULL for device
746 drivers. It will also be NULL for a bus drivers
747 that wish to retrieve the name of the bus
748 controller. It will not be NULL for a bus
749 driver that wishes to retrieve the name of a
752 @param Language[in] A pointer to a Null-terminated ASCII string
753 array indicating the language. This is the
754 language of the driver name that the caller is
755 requesting, and it must match one of the
756 languages specified in SupportedLanguages. The
757 number of languages supported by a driver is up
758 to the driver writer. Language is specified in
759 RFC 4646 or ISO 639-2 language code format.
761 @param ControllerName[out] A pointer to the Unicode string to return.
762 This Unicode string is the name of the
763 controller specified by ControllerHandle and
764 ChildHandle in the language specified by
765 Language from the point of view of the driver
768 @retval EFI_SUCCESS The Unicode string for the user readable name in
769 the language specified by Language for the
770 driver specified by This was returned in
773 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
775 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
778 @retval EFI_INVALID_PARAMETER Language is NULL.
780 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
782 @retval EFI_UNSUPPORTED The driver specified by This is not currently
783 managing the controller specified by
784 ControllerHandle and ChildHandle.
786 @retval EFI_UNSUPPORTED The driver specified by This does not support
787 the language specified by Language.
792 TerminalComponentNameGetControllerName (
793 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
794 IN EFI_HANDLE ControllerHandle
,
795 IN EFI_HANDLE ChildHandle OPTIONAL
,
797 OUT CHAR16
**ControllerName
802 // internal functions
806 Check for a pending key in the Efi Key FIFO or Serial device buffer.
808 @param This Indicates the calling context.
810 @retval EFI_SUCCESS There is key pending.
811 @retval EFI_NOT_READY There is no key pending.
812 @retval EFI_DEVICE_ERROR If Serial IO is not attached to serial device.
816 TerminalConInCheckForKey (
817 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
821 Update terminal device path in Console Device Environment Variables.
823 @param VariableName The Console Device Environment Variable.
824 @param ParentDevicePath The terminal device path to be updated.
830 TerminalUpdateConsoleDevVariable (
831 IN CHAR16
*VariableName
,
832 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
836 Remove console device variable.
838 @param VariableName A pointer to the variable name.
839 @param ParentDevicePath A pointer to the parent device path.
843 TerminalRemoveConsoleDevVariable (
844 IN CHAR16
*VariableName
,
845 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
849 Build termial device path according to terminal type.
851 @param TerminalType The terminal type is PC ANSI, VT100, VT100+ or VT-UTF8.
852 @param ParentDevicePath Parent device path.
853 @param TerminalDevicePath Returned terminal device path, if building successfully.
855 @retval EFI_UNSUPPORTED Terminal does not belong to the supported type.
856 @retval EFI_OUT_OF_RESOURCES Generate terminal device path failed.
857 @retval EFI_SUCCESS Build terminal device path successfully.
861 SetTerminalDevicePath (
862 IN UINT8 TerminalType
,
863 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
864 OUT EFI_DEVICE_PATH_PROTOCOL
**TerminalDevicePath
868 Get one key out of serial buffer.
870 @param SerialIo Serial I/O protocl attached to the serial device.
871 @param Input The fetched key.
873 @retval EFI_NOT_READY If serial buffer is empty.
874 @retval EFI_DEVICE_ERROR If reading serial buffer encounter error.
875 @retval EFI_SUCCESS If reading serial buffer successfully, put
876 the fetched key to the parameter output.
880 GetOneKeyFromSerial (
881 EFI_SERIAL_IO_PROTOCOL
*SerialIo
,
886 Insert one byte raw data into the Raw Data FIFO.
888 @param TerminalDevice Terminal driver private structure.
889 @param Input The key will be input.
891 @retval TRUE If insert successfully.
892 @retval FLASE If Raw Data buffer is full before key insertion,
897 RawFiFoInsertOneKey (
898 TERMINAL_DEV
*TerminalDevice
,
903 Remove one pre-fetched key out of the Raw Data FIFO.
905 @param TerminalDevice Terminal driver private structure.
906 @param Output The key will be removed.
908 @retval TRUE If insert successfully.
909 @retval FLASE If Raw Data FIFO buffer is empty before remove operation.
913 RawFiFoRemoveOneKey (
914 TERMINAL_DEV
*TerminalDevice
,
919 Clarify whether Raw Data FIFO buffer is empty.
921 @param TerminalDevice Terminal driver private structure
923 @retval TRUE If Raw Data FIFO buffer is empty.
924 @retval FLASE If Raw Data FIFO buffer is not empty.
929 TERMINAL_DEV
*TerminalDevice
933 Clarify whether Raw Data FIFO buffer is full.
935 @param TerminalDevice Terminal driver private structure
937 @retval TRUE If Raw Data FIFO buffer is full.
938 @retval FLASE If Raw Data FIFO buffer is not full.
943 TERMINAL_DEV
*TerminalDevice
947 Insert one pre-fetched key into the FIFO buffer.
949 @param TerminalDevice Terminal driver private structure.
950 @param Key The key will be input.
952 @retval TRUE If insert successfully.
953 @retval FLASE If FIFO buffer is full before key insertion,
958 EfiKeyFiFoInsertOneKey (
959 TERMINAL_DEV
*TerminalDevice
,
964 Remove one pre-fetched key out of the FIFO buffer.
966 @param TerminalDevice Terminal driver private structure.
967 @param Output The key will be removed.
969 @retval TRUE If insert successfully.
970 @retval FLASE If FIFO buffer is empty before remove operation.
974 EfiKeyFiFoRemoveOneKey (
975 TERMINAL_DEV
*TerminalDevice
,
976 EFI_INPUT_KEY
*Output
980 Clarify whether FIFO buffer is empty.
982 @param TerminalDevice Terminal driver private structure
984 @retval TRUE If FIFO buffer is empty.
985 @retval FLASE If FIFO buffer is not empty.
990 TERMINAL_DEV
*TerminalDevice
994 Clarify whether FIFO buffer is full.
996 @param TerminalDevice Terminal driver private structure
998 @retval TRUE If FIFO buffer is full.
999 @retval FLASE If FIFO buffer is not full.
1004 TERMINAL_DEV
*TerminalDevice
1008 Insert one pre-fetched key into the Unicode FIFO buffer.
1010 @param TerminalDevice Terminal driver private structure.
1011 @param Input The key will be input.
1013 @retval TRUE If insert successfully.
1014 @retval FLASE If Unicode FIFO buffer is full before key insertion,
1015 and the key is lost.
1019 UnicodeFiFoInsertOneKey (
1020 TERMINAL_DEV
*TerminalDevice
,
1025 Remove one pre-fetched key out of the Unicode FIFO buffer.
1027 @param TerminalDevice Terminal driver private structure.
1028 @param Output The key will be removed.
1030 @retval TRUE If insert successfully.
1031 @retval FLASE If Unicode FIFO buffer is empty before remove operation.
1035 UnicodeFiFoRemoveOneKey (
1036 TERMINAL_DEV
*TerminalDevice
,
1041 Clarify whether Unicode FIFO buffer is empty.
1043 @param TerminalDevice Terminal driver private structure
1045 @retval TRUE If Unicode FIFO buffer is empty.
1046 @retval FLASE If Unicode FIFO buffer is not empty.
1050 IsUnicodeFiFoEmpty (
1051 TERMINAL_DEV
*TerminalDevice
1055 Clarify whether Unicode FIFO buffer is full.
1057 @param TerminalDevice Terminal driver private structure
1059 @retval TRUE If Unicode FIFO buffer is full.
1060 @retval FLASE If Unicode FIFO buffer is not full.
1065 TERMINAL_DEV
*TerminalDevice
1069 Count Unicode FIFO buffer.
1071 @param TerminalDevice Terminal driver private structure
1073 @return The count in bytes of Unicode FIFO.
1077 UnicodeFiFoGetKeyCount (
1078 TERMINAL_DEV
*TerminalDevice
1082 Translate raw data into Unicode (according to different encode), and
1083 translate Unicode into key information. (according to different standard).
1085 @param TerminalDevice Terminal driver private structure.
1089 TranslateRawDataToEfiKey (
1090 IN TERMINAL_DEV
*TerminalDevice
1094 // internal functions for PC ANSI
1098 Translate all raw data in the Raw FIFI into unicode, and insert
1099 them into Unicode FIFO.
1101 @param TerminalDevice The terminal device.
1105 AnsiRawDataToUnicode (
1106 IN TERMINAL_DEV
*TerminalDevice
1110 Converts a stream of Unicode characters from a terminal input device into EFI Keys that
1111 can be read through the Simple Input Protocol.
1113 The table below shows the keyboard input mappings that this function supports.
1114 If the ESC sequence listed in one of the columns is presented, then it is translated
1115 into the coorespoding EFI Scan Code. If a matching sequence is not found, then the raw
1116 key strokes are converted into EFI Keys.
1118 2 seconds are allowed for an ESC sequence to be completed. If the ESC sequence is not
1119 completed in 2 seconds, then the raw key strokes of the partial ESC sequence are
1120 converted into EFI Keys.
1121 There is one special input sequence that will force the system to reset.
1122 This is ESC R ESC r ESC R.
1124 Symbols used in table below
1125 ===========================
1130 +=========+======+===========+==========+==========+
1131 | | EFI | UEFI 2.0 | | |
1132 | | Scan | | VT100+ | |
1133 | KEY | Code | PC ANSI | VTUTF8 | VT100 |
1134 +=========+======+===========+==========+==========+
1135 | NULL | 0x00 | | | |
1136 | UP | 0x01 | ESC [ A | ESC [ A | ESC [ A |
1137 | DOWN | 0x02 | ESC [ B | ESC [ B | ESC [ B |
1138 | RIGHT | 0x03 | ESC [ C | ESC [ C | ESC [ C |
1139 | LEFT | 0x04 | ESC [ D | ESC [ D | ESC [ D |
1140 | HOME | 0x05 | ESC [ H | ESC h | ESC [ H |
1141 | END | 0x06 | ESC [ F | ESC k | ESC [ K |
1142 | INSERT | 0x07 | ESC [ @ | ESC + | ESC [ @ |
1143 | | | ESC [ L | | ESC [ L |
1144 | DELETE | 0x08 | ESC [ X | ESC - | ESC [ P |
1145 | PG UP | 0x09 | ESC [ I | ESC ? | ESC [ V |
1147 | PG DOWN | 0x0A | ESC [ G | ESC / | ESC [ U |
1149 | F1 | 0x0B | ESC [ M | ESC 1 | ESC O P |
1150 | F2 | 0x0C | ESC [ N | ESC 2 | ESC O Q |
1151 | F3 | 0x0D | ESC [ O | ESC 3 | ESC O w |
1152 | F4 | 0x0E | ESC [ P | ESC 4 | ESC O x |
1153 | F5 | 0x0F | ESC [ Q | ESC 5 | ESC O t |
1154 | F6 | 0x10 | ESC [ R | ESC 6 | ESC O u |
1155 | F7 | 0x11 | ESC [ S | ESC 7 | ESC O q |
1156 | F8 | 0x12 | ESC [ T | ESC 8 | ESC O r |
1157 | F9 | 0x13 | ESC [ U | ESC 9 | ESC O p |
1158 | F10 | 0x14 | ESC [ V | ESC 0 | ESC O M |
1159 | Escape | 0x17 | ESC | ESC | ESC |
1160 | F11 | 0x15 | | ESC ! | |
1161 | F12 | 0x16 | | ESC @ | |
1162 +=========+======+===========+==========+==========+
1166 ESC R ESC r ESC R = Reset System
1169 @param TerminalDevice The terminal device to use to translate raw input into EFI Keys
1174 IN TERMINAL_DEV
*TerminalDevice
1178 Check if input string is valid Ascii string, valid EFI control characters
1179 or valid text graphics.
1181 @param TerminalDevice The terminal device.
1182 @param WString The input string.
1184 @retval EFI_UNSUPPORTED If not all input characters are valid.
1185 @retval EFI_SUCCESS If all input characters are valid.
1190 IN TERMINAL_DEV
*TerminalDevice
,
1195 // internal functions for VTUTF8
1199 Translate all VT-UTF8 characters in the Raw FIFI into unicode characters,
1200 and insert them into Unicode FIFO.
1202 @param VtUtf8Device The terminal device.
1206 VTUTF8RawDataToUnicode (
1207 IN TERMINAL_DEV
*VtUtf8Device
1211 Check if input string is valid VT-UTF8 string.
1213 @param TerminalDevice The terminal device.
1214 @param WString The input string.
1216 @retval EFI_SUCCESS If all input characters are valid.
1221 IN TERMINAL_DEV
*TerminalDevice
,
1226 Translate one Unicode character into VT-UTF8 characters.
1229 Bits per Character | Unicode Character Range | Unicode Binary Encoding | UTF8 Binary Encoding
1230 0-7 | 0x0000 - 0x007F | 00000000 0xxxxxxx | 0xxxxxxx
1231 8-11 | 0x0080 - 0x07FF | 00000xxx xxxxxxxx | 110xxxxx 10xxxxxx
1232 12-16 | 0x0800 - 0xFFFF | xxxxxxxx xxxxxxxx | 1110xxxx 10xxxxxx 10xxxxxx
1235 @param Unicode Unicode character need translating.
1236 @param Utf8Char Return VT-UTF8 character set.
1237 @param ValidBytes The count of valid VT-UTF8 characters. If
1238 ValidBytes is zero, no valid VT-UTF8 returned.
1244 OUT UTF8_CHAR
*Utf8Char
,
1245 OUT UINT8
*ValidBytes
1249 Get one valid VT-UTF8 characters set from Raw Data FIFO.
1251 @param Utf8Device The terminal device.
1252 @param Utf8Char Returned valid VT-UTF8 characters set.
1253 @param ValidBytes The count of returned VT-VTF8 characters.
1254 If ValidBytes is zero, no valid VT-UTF8 returned.
1258 GetOneValidUtf8Char (
1259 IN TERMINAL_DEV
*Utf8Device
,
1260 OUT UTF8_CHAR
*Utf8Char
,
1261 OUT UINT8
*ValidBytes
1265 Translate VT-UTF8 characters into one Unicode character.
1268 Bits per Character | Unicode Character Range | Unicode Binary Encoding | UTF8 Binary Encoding
1269 0-7 | 0x0000 - 0x007F | 00000000 0xxxxxxx | 0xxxxxxx
1270 8-11 | 0x0080 - 0x07FF | 00000xxx xxxxxxxx | 110xxxxx 10xxxxxx
1271 12-16 | 0x0800 - 0xFFFF | xxxxxxxx xxxxxxxx | 1110xxxx 10xxxxxx 10xxxxxx
1274 @param Utf8Char VT-UTF8 character set needs translating.
1275 @param ValidBytes The count of valid VT-UTF8 characters.
1276 @param UnicodeChar Returned unicode character.
1281 IN UTF8_CHAR Utf8Char
,
1282 IN UINT8 ValidBytes
,
1283 OUT CHAR16
*UnicodeChar
1287 // functions for boxdraw unicode
1291 Detects if a Unicode char is for Box Drawing text graphics.
1293 @param Graphic Unicode char to test.
1294 @param PcAnsi Optional pointer to return PCANSI equivalent of
1296 @param Ascii Optional pointer to return ASCII equivalent of
1299 @retval TRUE If Graphic is a supported Unicode Box Drawing character.
1303 TerminalIsValidTextGraphics (
1305 OUT CHAR8
*PcAnsi
, OPTIONAL
1306 OUT CHAR8
*Ascii OPTIONAL
1310 Detects if a valid ASCII char.
1312 @param Ascii An ASCII character.
1314 @retval TRUE If it is a valid ASCII character.
1315 @retval FALSE If it is not a valid ASCII character.
1319 TerminalIsValidAscii (
1324 Detects if a valid EFI control character.
1326 @param CharC An input EFI Control character.
1328 @retval TRUE If it is a valid EFI control character.
1329 @retval FALSE If it is not a valid EFI control character.
1333 TerminalIsValidEfiCntlChar (
1338 Check if the device supports hot-plug through its device path.
1340 This function could be updated to check more types of Hot Plug devices.
1341 Currently, it checks USB and PCCard device.
1343 @param DevicePath Pointer to device's device path.
1345 @retval TRUE The devcie is a hot-plug device
1346 @retval FALSE The devcie is not a hot-plug device.
1351 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1355 Timer handler to poll the key from serial.
1357 @param Event Indicates the event that invoke this function.
1358 @param Context Indicates the calling context.
1362 TerminalConInTimerHandler (