2 Header file for Terminal driver.
4 Copyright (c) 2006 - 2014, 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];
67 } TERMINAL_CONSOLE_MODE_DATA
;
69 #define KEYBOARD_TIMER_INTERVAL 200000 // 0.02s
71 #define TERMINAL_DEV_SIGNATURE SIGNATURE_32 ('t', 'm', 'n', 'l')
73 #define TERMINAL_CONSOLE_IN_EX_NOTIFY_SIGNATURE SIGNATURE_32 ('t', 'm', 'e', 'n')
75 typedef struct _TERMINAL_CONSOLE_IN_EX_NOTIFY
{
78 EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn
;
79 LIST_ENTRY NotifyEntry
;
80 } TERMINAL_CONSOLE_IN_EX_NOTIFY
;
85 EFI_SERIAL_IO_PROTOCOL
*SerialIo
;
86 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
87 EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleInput
;
88 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL SimpleTextOutput
;
89 EFI_SIMPLE_TEXT_OUTPUT_MODE SimpleTextOutputMode
;
90 TERMINAL_CONSOLE_MODE_DATA
*TerminalConsoleModeData
;
91 UINTN SerialInTimeOut
;
92 RAW_DATA_FIFO
*RawFiFo
;
93 UNICODE_FIFO
*UnicodeFiFo
;
94 EFI_KEY_FIFO
*EfiKeyFiFo
;
95 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
97 EFI_EVENT TwoSecondTimeOut
;
102 // Esc could not be output to the screen by user,
103 // but the terminal driver need to output it to
104 // the terminal emulation software to send control sequence.
105 // This boolean is used by the terminal driver only
106 // to indicate whether the Esc could be sent or not.
108 BOOLEAN OutputEscChar
;
109 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL SimpleInputEx
;
110 LIST_ENTRY NotifyList
;
113 #define INPUT_STATE_DEFAULT 0x00
114 #define INPUT_STATE_ESC 0x01
115 #define INPUT_STATE_CSI 0x02
116 #define INPUT_STATE_LEFTOPENBRACKET 0x04
117 #define INPUT_STATE_O 0x08
118 #define INPUT_STATE_2 0x10
120 #define RESET_STATE_DEFAULT 0x00
121 #define RESET_STATE_ESC_R 0x01
122 #define RESET_STATE_ESC_R_ESC_R 0x02
124 #define TERMINAL_CON_IN_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleInput, TERMINAL_DEV_SIGNATURE)
125 #define TERMINAL_CON_OUT_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleTextOutput, TERMINAL_DEV_SIGNATURE)
126 #define TERMINAL_CON_IN_EX_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleInputEx, TERMINAL_DEV_SIGNATURE)
136 #define VT100PLUSTYPE 2
139 #define LEFTOPENBRACKET 0x5b // '['
149 #define BRIGHT_CONTROL_OFFSET 2
150 #define FOREGROUND_CONTROL_OFFSET 6
151 #define BACKGROUND_CONTROL_OFFSET 11
153 #define COLUMN_OFFSET 5
164 extern EFI_DRIVER_BINDING_PROTOCOL gTerminalDriverBinding
;
165 extern EFI_COMPONENT_NAME_PROTOCOL gTerminalComponentName
;
166 extern EFI_COMPONENT_NAME2_PROTOCOL gTerminalComponentName2
;
169 The user Entry Point for module Terminal. The user code starts with this function.
171 @param[in] ImageHandle The firmware allocated handle for the EFI image.
172 @param[in] SystemTable A pointer to the EFI System Table.
174 @retval EFI_SUCCESS The entry point is executed successfully.
175 @retval other Some error occurs when executing this entry point.
181 IN EFI_HANDLE ImageHandle
,
182 IN EFI_SYSTEM_TABLE
*SystemTable
186 Implements EFI_SIMPLE_TEXT_INPUT_PROTOCOL.Reset().
187 This driver only perform dependent serial device reset regardless of
188 the value of ExtendeVerification
190 @param This Indicates the calling context.
191 @param ExtendedVerification Skip by this driver.
193 @retval EFI_SUCCESS The reset operation succeeds.
194 @retval EFI_DEVICE_ERROR The dependent serial port reset fails.
200 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
201 IN BOOLEAN ExtendedVerification
206 Implements EFI_SIMPLE_TEXT_INPUT_PROTOCOL.ReadKeyStroke().
208 @param This Indicates the calling context.
209 @param Key A pointer to a buffer that is filled in with the
210 keystroke information for the key that was sent
213 @retval EFI_SUCCESS The keystroke information is returned successfully.
214 @retval EFI_NOT_READY There is no keystroke data available.
215 @retval EFI_DEVICE_ERROR The dependent serial device encounters error.
220 TerminalConInReadKeyStroke (
221 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
222 OUT EFI_INPUT_KEY
*Key
226 Check if the key already has been registered.
228 @param RegsiteredData A pointer to a buffer that is filled in with the
229 keystroke state data for the key that was
231 @param InputData A pointer to a buffer that is filled in with the
232 keystroke state data for the key that was
235 @retval TRUE Key be pressed matches a registered key.
236 @retval FALSE Match failed.
241 IN EFI_KEY_DATA
*RegsiteredData
,
242 IN EFI_KEY_DATA
*InputData
246 Event notification function for EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx event
247 Signal the event if there is key available
249 @param Event Indicates the event that invoke this function.
250 @param Context Indicates the calling context.
255 TerminalConInWaitForKeyEx (
261 // Simple Text Input Ex protocol prototypes
265 Reset the input device and optionally run diagnostics
267 @param This Protocol instance pointer.
268 @param ExtendedVerification Driver may perform diagnostics on reset.
270 @retval EFI_SUCCESS The device was reset.
271 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
277 TerminalConInResetEx (
278 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
279 IN BOOLEAN ExtendedVerification
283 Reads the next keystroke from the input device. The WaitForKey Event can
284 be used to test for existence of a keystroke via WaitForEvent () call.
286 @param This Protocol instance pointer.
287 @param KeyData A pointer to a buffer that is filled in with the
288 keystroke state data for the key that was
291 @retval EFI_SUCCESS The keystroke information was returned.
292 @retval EFI_NOT_READY There was no keystroke data available.
293 @retval EFI_DEVICE_ERROR The keystroke information was not returned due
295 @retval EFI_INVALID_PARAMETER KeyData is NULL.
300 TerminalConInReadKeyStrokeEx (
301 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
302 OUT EFI_KEY_DATA
*KeyData
306 Set certain state for the input device.
308 @param This Protocol instance pointer.
309 @param KeyToggleState A pointer to the EFI_KEY_TOGGLE_STATE to set the
310 state for the input device.
312 @retval EFI_SUCCESS The device state was set successfully.
313 @retval EFI_DEVICE_ERROR The device is not functioning correctly and
314 could not have the setting adjusted.
315 @retval EFI_UNSUPPORTED The device does not have the ability to set its
317 @retval EFI_INVALID_PARAMETER KeyToggleState is NULL.
322 TerminalConInSetState (
323 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
324 IN EFI_KEY_TOGGLE_STATE
*KeyToggleState
328 Register a notification function for a particular keystroke for the input device.
330 @param This Protocol instance pointer.
331 @param KeyData A pointer to a buffer that is filled in with the
332 keystroke information data for the key that was
334 @param KeyNotificationFunction Points to the function to be called when the key
335 sequence is typed specified by KeyData.
336 @param NotifyHandle Points to the unique handle assigned to the
337 registered notification.
339 @retval EFI_SUCCESS The notification function was registered
341 @retval EFI_OUT_OF_RESOURCES Unable to allocate resources for necesssary data
343 @retval EFI_INVALID_PARAMETER KeyData or NotifyHandle is NULL.
348 TerminalConInRegisterKeyNotify (
349 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
350 IN EFI_KEY_DATA
*KeyData
,
351 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction
,
352 OUT VOID
**NotifyHandle
356 Remove a registered notification function from a particular keystroke.
358 @param This Protocol instance pointer.
359 @param NotificationHandle The handle of the notification function being
362 @retval EFI_SUCCESS The notification function was unregistered
364 @retval EFI_INVALID_PARAMETER The NotificationHandle is invalid.
365 @retval EFI_NOT_FOUND Can not find the matching entry in database.
370 TerminalConInUnregisterKeyNotify (
371 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
372 IN VOID
*NotificationHandle
376 Event notification function for EFI_SIMPLE_TEXT_INPUT_PROTOCOL.WaitForKey event
377 Signal the event if there is key available
379 @param Event Indicates the event that invoke this function.
380 @param Context Indicates the calling context.
385 TerminalConInWaitForKey (
391 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset().
392 If ExtendeVerification is TRUE, then perform dependent serial device reset,
393 and set display mode to mode 0.
394 If ExtendedVerification is FALSE, only set display mode to mode 0.
396 @param This Indicates the calling context.
397 @param ExtendedVerification Indicates that the driver may perform a more
398 exhaustive verification operation of the device
401 @retval EFI_SUCCESS The reset operation succeeds.
402 @retval EFI_DEVICE_ERROR The terminal is not functioning correctly or the serial port reset fails.
407 TerminalConOutReset (
408 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
409 IN BOOLEAN ExtendedVerification
413 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString().
414 The Unicode string will be converted to terminal expressible data stream
415 and send to terminal via serial port.
417 @param This Indicates the calling context.
418 @param WString The Null-terminated Unicode string to be displayed
419 on the terminal screen.
421 @retval EFI_SUCCESS The string is output successfully.
422 @retval EFI_DEVICE_ERROR The serial port fails to send the string out.
423 @retval EFI_WARN_UNKNOWN_GLYPH Indicates that some of the characters in the Unicode string could not
424 be rendered and are skipped.
425 @retval EFI_UNSUPPORTED If current display mode is out of range.
430 TerminalConOutOutputString (
431 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
436 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.TestString().
437 If one of the characters in the *Wstring is
438 neither valid Unicode drawing characters,
439 not ASCII code, then this function will return
442 @param This Indicates the calling context.
443 @param WString The Null-terminated Unicode string to be tested.
445 @retval EFI_SUCCESS The terminal is capable of rendering the output string.
446 @retval EFI_UNSUPPORTED Some of the characters in the Unicode string cannot be rendered.
451 TerminalConOutTestString (
452 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
457 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.QueryMode().
458 It returns information for an available text mode
459 that the terminal supports.
460 In this driver, we support text mode 80x25 (mode 0),
461 80x50 (mode 1), 100x31 (mode 2).
463 @param This Indicates the calling context.
464 @param ModeNumber The mode number to return information on.
465 @param Columns The returned columns of the requested mode.
466 @param Rows The returned rows of the requested mode.
468 @retval EFI_SUCCESS The requested mode information is returned.
469 @retval EFI_UNSUPPORTED The mode number is not valid.
470 @retval EFI_DEVICE_ERROR
475 TerminalConOutQueryMode (
476 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
483 Implements EFI_SIMPLE_TEXT_OUT.SetMode().
484 Set the terminal to a specified display mode.
485 In this driver, we only support mode 0.
487 @param This Indicates the calling context.
488 @param ModeNumber The text mode to set.
490 @retval EFI_SUCCESS The requested text mode is set.
491 @retval EFI_DEVICE_ERROR The requested text mode cannot be set
492 because of serial device error.
493 @retval EFI_UNSUPPORTED The text mode number is not valid.
498 TerminalConOutSetMode (
499 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
504 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetAttribute().
506 @param This Indicates the calling context.
507 @param Attribute The attribute to set. Only bit0..6 are valid, all other bits
508 are undefined and must be zero.
510 @retval EFI_SUCCESS The requested attribute is set.
511 @retval EFI_DEVICE_ERROR The requested attribute cannot be set due to serial port error.
512 @retval EFI_UNSUPPORTED The attribute requested is not defined by EFI spec.
517 TerminalConOutSetAttribute (
518 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
523 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.ClearScreen().
524 It clears the ANSI terminal's display to the
525 currently selected background color.
527 @param This Indicates the calling context.
529 @retval EFI_SUCCESS The operation completed successfully.
530 @retval EFI_DEVICE_ERROR The terminal screen cannot be cleared due to serial port error.
531 @retval EFI_UNSUPPORTED The terminal is not in a valid display mode.
536 TerminalConOutClearScreen (
537 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
541 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetCursorPosition().
543 @param This Indicates the calling context.
544 @param Column The row to set cursor to.
545 @param Row The column to set cursor to.
547 @retval EFI_SUCCESS The operation completed successfully.
548 @retval EFI_DEVICE_ERROR The request fails due to serial port error.
549 @retval EFI_UNSUPPORTED The terminal is not in a valid text mode, or the cursor position
550 is invalid for current mode.
555 TerminalConOutSetCursorPosition (
556 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
562 Implements SIMPLE_TEXT_OUTPUT.EnableCursor().
563 In this driver, the cursor cannot be hidden.
565 @param This Indicates the calling context.
566 @param Visible If TRUE, the cursor is set to be visible,
567 If FALSE, the cursor is set to be invisible.
569 @retval EFI_SUCCESS The request is valid.
570 @retval EFI_UNSUPPORTED The terminal does not support cursor hidden.
575 TerminalConOutEnableCursor (
576 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
581 Test to see if this driver supports Controller.
583 @param This Protocol instance pointer.
584 @param ControllerHandle Handle of device to test
585 @param RemainingDevicePath Optional parameter use to pick a specific child
588 @retval EFI_SUCCESS This driver supports this device.
589 @retval EFI_ALREADY_STARTED This driver is already running on this device.
590 @retval other This driver does not support this device.
595 TerminalDriverBindingSupported (
596 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
597 IN EFI_HANDLE ControllerHandle
,
598 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
602 Start this driver on Controller by opening a Serial IO protocol,
603 reading Device Path, and creating a child handle with a Simple Text In,
604 Simple Text In Ex and Simple Text Out protocol, and device path protocol.
605 And store Console Device Environment Variables.
607 @param This Protocol instance pointer.
608 @param Controller Handle of device to bind driver to
609 @param RemainingDevicePath Optional parameter use to pick a specific child
612 @retval EFI_SUCCESS This driver is added to Controller.
613 @retval EFI_ALREADY_STARTED This driver is already running on Controller.
614 @retval other This driver does not support this device.
619 TerminalDriverBindingStart (
620 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
621 IN EFI_HANDLE Controller
,
622 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
627 Stop this driver on Controller by closing Simple Text In, Simple Text
628 In Ex, Simple Text Out protocol, and removing parent device path from
629 Console Device Environment Variables.
631 @param This Protocol instance pointer.
632 @param Controller Handle of device to stop driver on
633 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
634 children is zero stop the entire bus driver.
635 @param ChildHandleBuffer List of Child Handles to Stop.
637 @retval EFI_SUCCESS This driver is removed Controller.
638 @retval other This driver could not be removed from this device.
643 TerminalDriverBindingStop (
644 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
645 IN EFI_HANDLE Controller
,
646 IN UINTN NumberOfChildren
,
647 IN EFI_HANDLE
*ChildHandleBuffer
651 Free notify functions list.
653 @param ListHead The list head
655 @retval EFI_SUCCESS Free the notify list successfully.
656 @retval EFI_INVALID_PARAMETER ListHead is NULL.
660 TerminalFreeNotifyList (
661 IN OUT LIST_ENTRY
*ListHead
665 Retrieves a Unicode string that is the user readable name of the driver.
667 This function retrieves the user readable name of a driver in the form of a
668 Unicode string. If the driver specified by This has a user readable name in
669 the language specified by Language, then a pointer to the driver name is
670 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
671 by This does not support the language specified by Language,
672 then EFI_UNSUPPORTED is returned.
674 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
675 EFI_COMPONENT_NAME_PROTOCOL instance.
677 @param Language[in] A pointer to a Null-terminated ASCII string
678 array indicating the language. This is the
679 language of the driver name that the caller is
680 requesting, and it must match one of the
681 languages specified in SupportedLanguages. The
682 number of languages supported by a driver is up
683 to the driver writer. Language is specified
684 in RFC 4646 or ISO 639-2 language code format.
686 @param DriverName[out] A pointer to the Unicode string to return.
687 This Unicode string is the name of the
688 driver specified by This in the language
689 specified by Language.
691 @retval EFI_SUCCESS The Unicode string for the Driver specified by
692 This and the language specified by Language was
693 returned in DriverName.
695 @retval EFI_INVALID_PARAMETER Language is NULL.
697 @retval EFI_INVALID_PARAMETER DriverName is NULL.
699 @retval EFI_UNSUPPORTED The driver specified by This does not support
700 the language specified by Language.
705 TerminalComponentNameGetDriverName (
706 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
708 OUT CHAR16
**DriverName
713 Retrieves a Unicode string that is the user readable name of the controller
714 that is being managed by a driver.
716 This function retrieves the user readable name of the controller specified by
717 ControllerHandle and ChildHandle in the form of a Unicode string. If the
718 driver specified by This has a user readable name in the language specified by
719 Language, then a pointer to the controller name is returned in ControllerName,
720 and EFI_SUCCESS is returned. If the driver specified by This is not currently
721 managing the controller specified by ControllerHandle and ChildHandle,
722 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
723 support the language specified by Language, then EFI_UNSUPPORTED is returned.
725 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
726 EFI_COMPONENT_NAME_PROTOCOL instance.
728 @param ControllerHandle[in] The handle of a controller that the driver
729 specified by This is managing. This handle
730 specifies the controller whose name is to be
733 @param ChildHandle[in] The handle of the child controller to retrieve
734 the name of. This is an optional parameter that
735 may be NULL. It will be NULL for device
736 drivers. It will also be NULL for a bus drivers
737 that wish to retrieve the name of the bus
738 controller. It will not be NULL for a bus
739 driver that wishes to retrieve the name of a
742 @param Language[in] A pointer to a Null-terminated ASCII string
743 array indicating the language. This is the
744 language of the driver name that the caller is
745 requesting, and it must match one of the
746 languages specified in SupportedLanguages. The
747 number of languages supported by a driver is up
748 to the driver writer. Language is specified in
749 RFC 4646 or ISO 639-2 language code format.
751 @param ControllerName[out] A pointer to the Unicode string to return.
752 This Unicode string is the name of the
753 controller specified by ControllerHandle and
754 ChildHandle in the language specified by
755 Language from the point of view of the driver
758 @retval EFI_SUCCESS The Unicode string for the user readable name in
759 the language specified by Language for the
760 driver specified by This was returned in
763 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
765 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
768 @retval EFI_INVALID_PARAMETER Language is NULL.
770 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
772 @retval EFI_UNSUPPORTED The driver specified by This is not currently
773 managing the controller specified by
774 ControllerHandle and ChildHandle.
776 @retval EFI_UNSUPPORTED The driver specified by This does not support
777 the language specified by Language.
782 TerminalComponentNameGetControllerName (
783 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
784 IN EFI_HANDLE ControllerHandle
,
785 IN EFI_HANDLE ChildHandle OPTIONAL
,
787 OUT CHAR16
**ControllerName
792 // internal functions
796 Check for a pending key in the Efi Key FIFO or Serial device buffer.
798 @param This Indicates the calling context.
800 @retval EFI_SUCCESS There is key pending.
801 @retval EFI_NOT_READY There is no key pending.
802 @retval EFI_DEVICE_ERROR If Serial IO is not attached to serial device.
806 TerminalConInCheckForKey (
807 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
811 Update terminal device path in Console Device Environment Variables.
813 @param VariableName The Console Device Environment Variable.
814 @param ParentDevicePath The terminal device path to be updated.
820 TerminalUpdateConsoleDevVariable (
821 IN CHAR16
*VariableName
,
822 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
826 Remove console device variable.
828 @param VariableName A pointer to the variable name.
829 @param ParentDevicePath A pointer to the parent device path.
833 TerminalRemoveConsoleDevVariable (
834 IN CHAR16
*VariableName
,
835 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
839 Build termial device path according to terminal type.
841 @param TerminalType The terminal type is PC ANSI, VT100, VT100+ or VT-UTF8.
842 @param ParentDevicePath Parent device path.
843 @param TerminalDevicePath Returned terminal device path, if building successfully.
845 @retval EFI_UNSUPPORTED Terminal does not belong to the supported type.
846 @retval EFI_OUT_OF_RESOURCES Generate terminal device path failed.
847 @retval EFI_SUCCESS Build terminal device path successfully.
851 SetTerminalDevicePath (
852 IN UINT8 TerminalType
,
853 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
854 OUT EFI_DEVICE_PATH_PROTOCOL
**TerminalDevicePath
858 Get one key out of serial buffer.
860 @param SerialIo Serial I/O protocl attached to the serial device.
861 @param Input The fetched key.
863 @retval EFI_NOT_READY If serial buffer is empty.
864 @retval EFI_DEVICE_ERROR If reading serial buffer encounter error.
865 @retval EFI_SUCCESS If reading serial buffer successfully, put
866 the fetched key to the parameter output.
870 GetOneKeyFromSerial (
871 EFI_SERIAL_IO_PROTOCOL
*SerialIo
,
876 Insert one byte raw data into the Raw Data FIFO.
878 @param TerminalDevice Terminal driver private structure.
879 @param Input The key will be input.
881 @retval TRUE If insert successfully.
882 @retval FALSE If Raw Data buffer is full before key insertion,
887 RawFiFoInsertOneKey (
888 TERMINAL_DEV
*TerminalDevice
,
893 Remove one pre-fetched key out of the Raw Data FIFO.
895 @param TerminalDevice Terminal driver private structure.
896 @param Output The key will be removed.
898 @retval TRUE If insert successfully.
899 @retval FALSE If Raw Data FIFO buffer is empty before remove operation.
903 RawFiFoRemoveOneKey (
904 TERMINAL_DEV
*TerminalDevice
,
909 Clarify whether Raw Data FIFO buffer is empty.
911 @param TerminalDevice Terminal driver private structure
913 @retval TRUE If Raw Data FIFO buffer is empty.
914 @retval FALSE If Raw Data FIFO buffer is not empty.
919 TERMINAL_DEV
*TerminalDevice
923 Clarify whether Raw Data FIFO buffer is full.
925 @param TerminalDevice Terminal driver private structure
927 @retval TRUE If Raw Data FIFO buffer is full.
928 @retval FALSE If Raw Data FIFO buffer is not full.
933 TERMINAL_DEV
*TerminalDevice
937 Insert one pre-fetched key into the FIFO buffer.
939 @param TerminalDevice Terminal driver private structure.
940 @param Key The key will be input.
942 @retval TRUE If insert successfully.
943 @retval FALSE If FIFO buffer is full before key insertion,
948 EfiKeyFiFoInsertOneKey (
949 TERMINAL_DEV
*TerminalDevice
,
954 Remove one pre-fetched key out of the FIFO buffer.
956 @param TerminalDevice Terminal driver private structure.
957 @param Output The key will be removed.
959 @retval TRUE If insert successfully.
960 @retval FALSE If FIFO buffer is empty before remove operation.
964 EfiKeyFiFoRemoveOneKey (
965 TERMINAL_DEV
*TerminalDevice
,
966 EFI_INPUT_KEY
*Output
970 Clarify whether FIFO buffer is empty.
972 @param TerminalDevice Terminal driver private structure
974 @retval TRUE If FIFO buffer is empty.
975 @retval FALSE If FIFO buffer is not empty.
980 TERMINAL_DEV
*TerminalDevice
984 Clarify whether FIFO buffer is full.
986 @param TerminalDevice Terminal driver private structure
988 @retval TRUE If FIFO buffer is full.
989 @retval FALSE If FIFO buffer is not full.
994 TERMINAL_DEV
*TerminalDevice
998 Insert one pre-fetched key into the Unicode FIFO buffer.
1000 @param TerminalDevice Terminal driver private structure.
1001 @param Input The key will be input.
1003 @retval TRUE If insert successfully.
1004 @retval FALSE If Unicode FIFO buffer is full before key insertion,
1005 and the key is lost.
1009 UnicodeFiFoInsertOneKey (
1010 TERMINAL_DEV
*TerminalDevice
,
1015 Remove one pre-fetched key out of the Unicode FIFO buffer.
1016 The caller should guarantee that Unicode FIFO buffer is not empty
1017 by IsUnicodeFiFoEmpty ().
1019 @param TerminalDevice Terminal driver private structure.
1020 @param Output The key will be removed.
1024 UnicodeFiFoRemoveOneKey (
1025 TERMINAL_DEV
*TerminalDevice
,
1030 Clarify whether Unicode FIFO buffer is empty.
1032 @param TerminalDevice Terminal driver private structure
1034 @retval TRUE If Unicode FIFO buffer is empty.
1035 @retval FALSE If Unicode FIFO buffer is not empty.
1039 IsUnicodeFiFoEmpty (
1040 TERMINAL_DEV
*TerminalDevice
1044 Clarify whether Unicode FIFO buffer is full.
1046 @param TerminalDevice Terminal driver private structure
1048 @retval TRUE If Unicode FIFO buffer is full.
1049 @retval FALSE If Unicode FIFO buffer is not full.
1054 TERMINAL_DEV
*TerminalDevice
1058 Count Unicode FIFO buffer.
1060 @param TerminalDevice Terminal driver private structure
1062 @return The count in bytes of Unicode FIFO.
1066 UnicodeFiFoGetKeyCount (
1067 TERMINAL_DEV
*TerminalDevice
1071 Translate raw data into Unicode (according to different encode), and
1072 translate Unicode into key information. (according to different standard).
1074 @param TerminalDevice Terminal driver private structure.
1078 TranslateRawDataToEfiKey (
1079 IN TERMINAL_DEV
*TerminalDevice
1083 // internal functions for PC ANSI
1087 Translate all raw data in the Raw FIFI into unicode, and insert
1088 them into Unicode FIFO.
1090 @param TerminalDevice The terminal device.
1094 AnsiRawDataToUnicode (
1095 IN TERMINAL_DEV
*TerminalDevice
1099 Converts a stream of Unicode characters from a terminal input device into EFI Keys that
1100 can be read through the Simple Input Protocol.
1102 The table below shows the keyboard input mappings that this function supports.
1103 If the ESC sequence listed in one of the columns is presented, then it is translated
1104 into the coorespoding EFI Scan Code. If a matching sequence is not found, then the raw
1105 key strokes are converted into EFI Keys.
1107 2 seconds are allowed for an ESC sequence to be completed. If the ESC sequence is not
1108 completed in 2 seconds, then the raw key strokes of the partial ESC sequence are
1109 converted into EFI Keys.
1110 There is one special input sequence that will force the system to reset.
1111 This is ESC R ESC r ESC R.
1113 Symbols used in table below
1114 ===========================
1119 +=========+======+===========+==========+==========+
1120 | | EFI | UEFI 2.0 | | |
1121 | | Scan | | VT100+ | |
1122 | KEY | Code | PC ANSI | VTUTF8 | VT100 |
1123 +=========+======+===========+==========+==========+
1124 | NULL | 0x00 | | | |
1125 | UP | 0x01 | ESC [ A | ESC [ A | ESC [ A |
1126 | DOWN | 0x02 | ESC [ B | ESC [ B | ESC [ B |
1127 | RIGHT | 0x03 | ESC [ C | ESC [ C | ESC [ C |
1128 | LEFT | 0x04 | ESC [ D | ESC [ D | ESC [ D |
1129 | HOME | 0x05 | ESC [ H | ESC h | ESC [ H |
1130 | END | 0x06 | ESC [ F | ESC k | ESC [ K |
1131 | INSERT | 0x07 | ESC [ @ | ESC + | ESC [ @ |
1132 | | | ESC [ L | | ESC [ L |
1133 | DELETE | 0x08 | ESC [ X | ESC - | ESC [ P |
1134 | PG UP | 0x09 | ESC [ I | ESC ? | ESC [ V |
1136 | PG DOWN | 0x0A | ESC [ G | ESC / | ESC [ U |
1138 | F1 | 0x0B | ESC [ M | ESC 1 | ESC O P |
1139 | F2 | 0x0C | ESC [ N | ESC 2 | ESC O Q |
1140 | F3 | 0x0D | ESC [ O | ESC 3 | ESC O w |
1141 | F4 | 0x0E | ESC [ P | ESC 4 | ESC O x |
1142 | F5 | 0x0F | ESC [ Q | ESC 5 | ESC O t |
1143 | F6 | 0x10 | ESC [ R | ESC 6 | ESC O u |
1144 | F7 | 0x11 | ESC [ S | ESC 7 | ESC O q |
1145 | F8 | 0x12 | ESC [ T | ESC 8 | ESC O r |
1146 | F9 | 0x13 | ESC [ U | ESC 9 | ESC O p |
1147 | F10 | 0x14 | ESC [ V | ESC 0 | ESC O M |
1148 | Escape | 0x17 | ESC | ESC | ESC |
1149 | F11 | 0x15 | | ESC ! | |
1150 | F12 | 0x16 | | ESC @ | |
1151 +=========+======+===========+==========+==========+
1155 ESC R ESC r ESC R = Reset System
1158 @param TerminalDevice The terminal device to use to translate raw input into EFI Keys
1163 IN TERMINAL_DEV
*TerminalDevice
1167 Check if input string is valid Ascii string, valid EFI control characters
1168 or valid text graphics.
1170 @param TerminalDevice The terminal device.
1171 @param WString The input string.
1173 @retval EFI_UNSUPPORTED If not all input characters are valid.
1174 @retval EFI_SUCCESS If all input characters are valid.
1179 IN TERMINAL_DEV
*TerminalDevice
,
1184 // internal functions for VTUTF8
1188 Translate all VT-UTF8 characters in the Raw FIFI into unicode characters,
1189 and insert them into Unicode FIFO.
1191 @param VtUtf8Device The terminal device.
1195 VTUTF8RawDataToUnicode (
1196 IN TERMINAL_DEV
*VtUtf8Device
1200 Check if input string is valid VT-UTF8 string.
1202 @param TerminalDevice The terminal device.
1203 @param WString The input string.
1205 @retval EFI_SUCCESS If all input characters are valid.
1210 IN TERMINAL_DEV
*TerminalDevice
,
1215 Translate one Unicode character into VT-UTF8 characters.
1218 Bits per Character | Unicode Character Range | Unicode Binary Encoding | UTF8 Binary Encoding
1219 0-7 | 0x0000 - 0x007F | 00000000 0xxxxxxx | 0xxxxxxx
1220 8-11 | 0x0080 - 0x07FF | 00000xxx xxxxxxxx | 110xxxxx 10xxxxxx
1221 12-16 | 0x0800 - 0xFFFF | xxxxxxxx xxxxxxxx | 1110xxxx 10xxxxxx 10xxxxxx
1224 @param Unicode Unicode character need translating.
1225 @param Utf8Char Return VT-UTF8 character set.
1226 @param ValidBytes The count of valid VT-UTF8 characters. If
1227 ValidBytes is zero, no valid VT-UTF8 returned.
1233 OUT UTF8_CHAR
*Utf8Char
,
1234 OUT UINT8
*ValidBytes
1238 Get one valid VT-UTF8 characters set from Raw Data FIFO.
1240 @param Utf8Device The terminal device.
1241 @param Utf8Char Returned valid VT-UTF8 characters set.
1242 @param ValidBytes The count of returned VT-VTF8 characters.
1243 If ValidBytes is zero, no valid VT-UTF8 returned.
1247 GetOneValidUtf8Char (
1248 IN TERMINAL_DEV
*Utf8Device
,
1249 OUT UTF8_CHAR
*Utf8Char
,
1250 OUT UINT8
*ValidBytes
1254 Translate VT-UTF8 characters into one Unicode character.
1257 Bits per Character | Unicode Character Range | Unicode Binary Encoding | UTF8 Binary Encoding
1258 0-7 | 0x0000 - 0x007F | 00000000 0xxxxxxx | 0xxxxxxx
1259 8-11 | 0x0080 - 0x07FF | 00000xxx xxxxxxxx | 110xxxxx 10xxxxxx
1260 12-16 | 0x0800 - 0xFFFF | xxxxxxxx xxxxxxxx | 1110xxxx 10xxxxxx 10xxxxxx
1263 @param Utf8Char VT-UTF8 character set needs translating.
1264 @param ValidBytes The count of valid VT-UTF8 characters.
1265 @param UnicodeChar Returned unicode character.
1270 IN UTF8_CHAR Utf8Char
,
1271 IN UINT8 ValidBytes
,
1272 OUT CHAR16
*UnicodeChar
1276 // functions for boxdraw unicode
1280 Detects if a Unicode char is for Box Drawing text graphics.
1282 @param Graphic Unicode char to test.
1283 @param PcAnsi Optional pointer to return PCANSI equivalent of
1285 @param Ascii Optional pointer to return ASCII equivalent of
1288 @retval TRUE If Graphic is a supported Unicode Box Drawing character.
1292 TerminalIsValidTextGraphics (
1294 OUT CHAR8
*PcAnsi
, OPTIONAL
1295 OUT CHAR8
*Ascii OPTIONAL
1299 Detects if a valid ASCII char.
1301 @param Ascii An ASCII character.
1303 @retval TRUE If it is a valid ASCII character.
1304 @retval FALSE If it is not a valid ASCII character.
1308 TerminalIsValidAscii (
1313 Detects if a valid EFI control character.
1315 @param CharC An input EFI Control character.
1317 @retval TRUE If it is a valid EFI control character.
1318 @retval FALSE If it is not a valid EFI control character.
1322 TerminalIsValidEfiCntlChar (
1327 Check if the device supports hot-plug through its device path.
1329 This function could be updated to check more types of Hot Plug devices.
1330 Currently, it checks USB and PCCard device.
1332 @param DevicePath Pointer to device's device path.
1334 @retval TRUE The devcie is a hot-plug device
1335 @retval FALSE The devcie is not a hot-plug device.
1340 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1344 Timer handler to poll the key from serial.
1346 @param Event Indicates the event that invoke this function.
1347 @param Context Indicates the calling context.
1351 TerminalConInTimerHandler (