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
;
174 IN EFI_HANDLE ImageHandle
,
175 IN EFI_SYSTEM_TABLE
*SystemTable
182 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
183 IN BOOLEAN ExtendedVerification
189 TerminalConInReadKeyStroke (
190 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
191 OUT EFI_INPUT_KEY
*Key
198 IN EFI_KEY_DATA
*RegsiteredData
,
199 IN EFI_KEY_DATA
*InputData
207 RegsiteredData - A pointer to a buffer that is filled in with the keystroke
208 state data for the key that was registered.
209 InputData - A pointer to a buffer that is filled in with the keystroke
210 state data for the key that was pressed.
213 TRUE - Key be pressed matches a registered key.
214 FLASE - Match failed.
221 TerminalConInWaitForKeyEx (
227 // Simple Text Input Ex protocol prototypes
232 TerminalConInResetEx (
233 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
234 IN BOOLEAN ExtendedVerification
239 Reset the input device and optionaly run diagnostics
242 This - Protocol instance pointer.
243 ExtendedVerification - Driver may perform diagnostics on reset.
246 EFI_SUCCESS - The device was reset.
247 EFI_DEVICE_ERROR - The device is not functioning properly and could
255 TerminalConInReadKeyStrokeEx (
256 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
257 OUT EFI_KEY_DATA
*KeyData
262 Reads the next keystroke from the input device. The WaitForKey Event can
263 be used to test for existance of a keystroke via WaitForEvent () call.
266 This - Protocol instance pointer.
267 KeyData - A pointer to a buffer that is filled in with the keystroke
268 state data for the key that was pressed.
271 EFI_SUCCESS - The keystroke information was returned.
272 EFI_NOT_READY - There was no keystroke data availiable.
273 EFI_DEVICE_ERROR - The keystroke information was not returned due to
275 EFI_INVALID_PARAMETER - KeyData is NULL.
282 TerminalConInSetState (
283 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
284 IN EFI_KEY_TOGGLE_STATE
*KeyToggleState
289 Set certain state for the input device.
292 This - Protocol instance pointer.
293 KeyToggleState - A pointer to the EFI_KEY_TOGGLE_STATE to set the
294 state for the input device.
297 EFI_SUCCESS - The device state was set successfully.
298 EFI_DEVICE_ERROR - The device is not functioning correctly and could
299 not have the setting adjusted.
300 EFI_UNSUPPORTED - The device does not have the ability to set its state.
301 EFI_INVALID_PARAMETER - KeyToggleState is NULL.
308 TerminalConInRegisterKeyNotify (
309 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
310 IN EFI_KEY_DATA
*KeyData
,
311 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction
,
312 OUT EFI_HANDLE
*NotifyHandle
317 Register a notification function for a particular keystroke for the input device.
320 This - Protocol instance pointer.
321 KeyData - A pointer to a buffer that is filled in with the keystroke
322 information data for the key that was pressed.
323 KeyNotificationFunction - Points to the function to be called when the key
324 sequence is typed specified by KeyData.
325 NotifyHandle - Points to the unique handle assigned to the registered notification.
328 EFI_SUCCESS - The notification function was registered successfully.
329 EFI_OUT_OF_RESOURCES - Unable to allocate resources for necesssary data structures.
330 EFI_INVALID_PARAMETER - KeyData or NotifyHandle is NULL.
337 TerminalConInUnregisterKeyNotify (
338 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
339 IN EFI_HANDLE NotificationHandle
344 Remove a registered notification function from a particular keystroke.
347 This - Protocol instance pointer.
348 NotificationHandle - The handle of the notification function being unregistered.
351 EFI_SUCCESS - The notification function was unregistered successfully.
352 EFI_INVALID_PARAMETER - The NotificationHandle is invalid.
353 EFI_NOT_FOUND - Can not find the matching entry in database.
360 TerminalConInWaitForKey (
368 TerminalConOutReset (
369 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
370 IN BOOLEAN ExtendedVerification
376 TerminalConOutOutputString (
377 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
384 TerminalConOutTestString (
385 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
392 TerminalConOutQueryMode (
393 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
402 TerminalConOutSetMode (
403 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
410 TerminalConOutSetAttribute (
411 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
418 TerminalConOutClearScreen (
419 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
425 TerminalConOutSetCursorPosition (
426 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
434 TerminalConOutEnableCursor (
435 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
442 TerminalDriverBindingSupported (
443 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
444 IN EFI_HANDLE Controller
,
445 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
450 TerminalDriverBindingStart (
451 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
452 IN EFI_HANDLE Controller
,
453 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
458 TerminalDriverBindingStop (
459 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
460 IN EFI_HANDLE Controller
,
461 IN UINTN NumberOfChildren
,
462 IN EFI_HANDLE
*ChildHandleBuffer
466 Retrieves a Unicode string that is the user readable name of the driver.
468 This function retrieves the user readable name of a driver in the form of a
469 Unicode string. If the driver specified by This has a user readable name in
470 the language specified by Language, then a pointer to the driver name is
471 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
472 by This does not support the language specified by Language,
473 then EFI_UNSUPPORTED is returned.
475 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
476 EFI_COMPONENT_NAME_PROTOCOL instance.
478 @param Language[in] A pointer to a Null-terminated ASCII string
479 array indicating the language. This is the
480 language of the driver name that the caller is
481 requesting, and it must match one of the
482 languages specified in SupportedLanguages. The
483 number of languages supported by a driver is up
484 to the driver writer. Language is specified
485 in RFC 3066 or ISO 639-2 language code format.
487 @param DriverName[out] A pointer to the Unicode string to return.
488 This Unicode string is the name of the
489 driver specified by This in the language
490 specified by Language.
492 @retval EFI_SUCCESS The Unicode string for the Driver specified by
493 This and the language specified by Language was
494 returned in DriverName.
496 @retval EFI_INVALID_PARAMETER Language is NULL.
498 @retval EFI_INVALID_PARAMETER DriverName is NULL.
500 @retval EFI_UNSUPPORTED The driver specified by This does not support
501 the language specified by Language.
506 TerminalComponentNameGetDriverName (
507 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
509 OUT CHAR16
**DriverName
514 Retrieves a Unicode string that is the user readable name of the controller
515 that is being managed by a driver.
517 This function retrieves the user readable name of the controller specified by
518 ControllerHandle and ChildHandle in the form of a Unicode string. If the
519 driver specified by This has a user readable name in the language specified by
520 Language, then a pointer to the controller name is returned in ControllerName,
521 and EFI_SUCCESS is returned. If the driver specified by This is not currently
522 managing the controller specified by ControllerHandle and ChildHandle,
523 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
524 support the language specified by Language, then EFI_UNSUPPORTED is returned.
526 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
527 EFI_COMPONENT_NAME_PROTOCOL instance.
529 @param ControllerHandle[in] The handle of a controller that the driver
530 specified by This is managing. This handle
531 specifies the controller whose name is to be
534 @param ChildHandle[in] The handle of the child controller to retrieve
535 the name of. This is an optional parameter that
536 may be NULL. It will be NULL for device
537 drivers. It will also be NULL for a bus drivers
538 that wish to retrieve the name of the bus
539 controller. It will not be NULL for a bus
540 driver that wishes to retrieve the name of a
543 @param Language[in] A pointer to a Null-terminated ASCII string
544 array indicating the language. This is the
545 language of the driver name that the caller is
546 requesting, and it must match one of the
547 languages specified in SupportedLanguages. The
548 number of languages supported by a driver is up
549 to the driver writer. Language is specified in
550 RFC 3066 or ISO 639-2 language code format.
552 @param ControllerName[out] A pointer to the Unicode string to return.
553 This Unicode string is the name of the
554 controller specified by ControllerHandle and
555 ChildHandle in the language specified by
556 Language from the point of view of the driver
559 @retval EFI_SUCCESS The Unicode string for the user readable name in
560 the language specified by Language for the
561 driver specified by This was returned in
564 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
566 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
569 @retval EFI_INVALID_PARAMETER Language is NULL.
571 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
573 @retval EFI_UNSUPPORTED The driver specified by This is not currently
574 managing the controller specified by
575 ControllerHandle and ChildHandle.
577 @retval EFI_UNSUPPORTED The driver specified by This does not support
578 the language specified by Language.
583 TerminalComponentNameGetControllerName (
584 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
585 IN EFI_HANDLE ControllerHandle
,
586 IN EFI_HANDLE ChildHandle OPTIONAL
,
588 OUT CHAR16
**ControllerName
593 // internal functions
596 TerminalConInCheckForKey (
597 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
602 TerminalUpdateConsoleDevVariable (
603 IN CHAR16
*VariableName
,
604 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
609 TerminalRemoveConsoleDevVariable (
610 IN CHAR16
*VariableName
,
611 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
616 TerminalGetVariableAndSize (
618 IN EFI_GUID
*VendorGuid
,
619 OUT UINTN
*VariableSize
624 SetTerminalDevicePath (
625 IN UINT8 TerminalType
,
626 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
627 OUT EFI_DEVICE_PATH_PROTOCOL
**TerminalDevicePath
633 IN TERMINAL_DEV
*TerminalDevice
638 InitializeUnicodeFiFo (
639 IN TERMINAL_DEV
*TerminalDevice
644 InitializeEfiKeyFiFo (
645 IN TERMINAL_DEV
*TerminalDevice
650 GetOneKeyFromSerial (
651 EFI_SERIAL_IO_PROTOCOL
*SerialIo
,
657 RawFiFoInsertOneKey (
658 TERMINAL_DEV
*TerminalDevice
,
664 RawFiFoRemoveOneKey (
665 TERMINAL_DEV
*TerminalDevice
,
672 TERMINAL_DEV
*TerminalDevice
678 TERMINAL_DEV
*TerminalDevice
683 EfiKeyFiFoInsertOneKey (
684 TERMINAL_DEV
*TerminalDevice
,
690 EfiKeyFiFoRemoveOneKey (
691 TERMINAL_DEV
*TerminalDevice
,
692 EFI_INPUT_KEY
*Output
698 TERMINAL_DEV
*TerminalDevice
704 TERMINAL_DEV
*TerminalDevice
709 UnicodeFiFoInsertOneKey (
710 TERMINAL_DEV
*TerminalDevice
,
716 UnicodeFiFoRemoveOneKey (
717 TERMINAL_DEV
*TerminalDevice
,
724 TERMINAL_DEV
*TerminalDevice
730 TERMINAL_DEV
*TerminalDevice
735 UnicodeFiFoGetKeyCount (
736 TERMINAL_DEV
*TerminalDevice
741 TranslateRawDataToEfiKey (
742 IN TERMINAL_DEV
*TerminalDevice
747 // internal functions for PC ANSI
750 AnsiRawDataToUnicode (
751 IN TERMINAL_DEV
*PcAnsiDevice
757 IN TERMINAL_DEV
*PcAnsiDevice
763 IN TERMINAL_DEV
*TerminalDevice
,
769 // internal functions for VT100
773 IN TERMINAL_DEV
*VT100Device
,
779 // internal functions for VT100Plus
782 VT100PlusTestString (
783 IN TERMINAL_DEV
*TerminalDevice
,
789 // internal functions for VTUTF8
792 VTUTF8RawDataToUnicode (
793 IN TERMINAL_DEV
*VtUtf8Device
799 IN TERMINAL_DEV
*TerminalDevice
,
807 OUT UTF8_CHAR
*Utf8Char
,
808 OUT UINT8
*ValidBytes
813 GetOneValidUtf8Char (
814 IN TERMINAL_DEV
*Utf8Device
,
815 OUT UTF8_CHAR
*Utf8Char
,
816 OUT UINT8
*ValidBytes
822 IN UTF8_CHAR Utf8Char
,
824 OUT CHAR16
*UnicodeChar
829 // functions for boxdraw unicode
832 TerminalIsValidTextGraphics (
834 OUT CHAR8
*PcAnsi
, OPTIONAL
835 OUT CHAR8
*Ascii OPTIONAL
840 TerminalIsValidAscii (
846 TerminalIsValidEfiCntlChar (