2 Header file for Terminal driver.
4 Copyright (c) 2006 - 2008, Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 #include <Guid/GlobalVariable.h>
22 #include <Guid/PcAnsi.h>
24 #include <Protocol/SimpleTextInExNotify.h>
25 #include <Protocol/SimpleTextOut.h>
26 #include <Protocol/SerialIo.h>
27 #include <Protocol/DevicePath.h>
28 #include <Protocol/SimpleTextIn.h>
29 #include <Protocol/SimpleTextInEx.h>
31 #include <Library/DebugLib.h>
32 #include <Library/UefiDriverEntryPoint.h>
33 #include <Library/UefiLib.h>
34 #include <Library/ReportStatusCodeLib.h>
35 #include <Library/BaseMemoryLib.h>
36 #include <Library/MemoryAllocationLib.h>
37 #include <Library/UefiBootServicesTableLib.h>
38 #include <Library/UefiRuntimeServicesTableLib.h>
39 #include <Library/DevicePathLib.h>
40 #include <Library/PcdLib.h>
41 #include <Library/BaseLib.h>
44 #define RAW_FIFO_MAX_NUMBER 256
45 #define FIFO_MAX_NUMBER 128
50 UINT8 Data
[RAW_FIFO_MAX_NUMBER
+ 1];
56 UINT16 Data
[FIFO_MAX_NUMBER
+ 1];
62 EFI_INPUT_KEY Data
[FIFO_MAX_NUMBER
+ 1];
65 #define TERMINAL_DEV_SIGNATURE SIGNATURE_32 ('t', 'm', 'n', 'l')
67 #define TERMINAL_CONSOLE_IN_EX_NOTIFY_SIGNATURE SIGNATURE_32 ('t', 'm', 'e', 'n')
69 typedef struct _TERMINAL_CONSOLE_IN_EX_NOTIFY
{
71 EFI_HANDLE NotifyHandle
;
73 EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn
;
74 LIST_ENTRY NotifyEntry
;
75 } TERMINAL_CONSOLE_IN_EX_NOTIFY
;
80 EFI_SERIAL_IO_PROTOCOL
*SerialIo
;
81 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
82 EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleInput
;
83 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL SimpleTextOutput
;
84 EFI_SIMPLE_TEXT_OUTPUT_MODE SimpleTextOutputMode
;
85 UINTN SerialInTimeOut
;
86 RAW_DATA_FIFO
*RawFiFo
;
87 UNICODE_FIFO
*UnicodeFiFo
;
88 EFI_KEY_FIFO
*EfiKeyFiFo
;
89 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
90 EFI_EVENT TwoSecondTimeOut
;
95 // Esc could not be output to the screen by user,
96 // but the terminal driver need to output it to
97 // the terminal emulation software to send control sequence.
98 // This boolean is used by the terminal driver only
99 // to indicate whether the Esc could be sent or not.
101 BOOLEAN OutputEscChar
;
102 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL SimpleInputEx
;
103 LIST_ENTRY NotifyList
;
106 #define INPUT_STATE_DEFAULT 0x00
107 #define INPUT_STATE_ESC 0x01
108 #define INPUT_STATE_CSI 0x02
109 #define INPUT_STATE_LEFTOPENBRACKET 0x04
110 #define INPUT_STATE_O 0x08
111 #define INPUT_STATE_2 0x10
113 #define RESET_STATE_DEFAULT 0x00
114 #define RESET_STATE_ESC_R 0x01
115 #define RESET_STATE_ESC_R_ESC_r 0x02
117 #define TERMINAL_CON_IN_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleInput, TERMINAL_DEV_SIGNATURE)
118 #define TERMINAL_CON_OUT_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleTextOutput, TERMINAL_DEV_SIGNATURE)
119 #define TERMINAL_CON_IN_EX_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleInputEx, TERMINAL_DEV_SIGNATURE)
129 #define VT100PLUSTYPE 2
132 #define LEFTOPENBRACKET 0x5b // '['
138 #define MODE0_COLUMN_COUNT 80
139 #define MODE0_ROW_COUNT 25
141 #define MODE1_COLUMN_COUNT 80
142 #define MODE1_ROW_COUNT 50
144 #define MODE2_COLUMN_COUNT 100
145 #define MODE2_ROW_COUNT 31
151 #define BRIGHT_CONTROL_OFFSET 2
152 #define FOREGROUND_CONTROL_OFFSET 6
153 #define BACKGROUND_CONTROL_OFFSET 11
155 #define COLUMN_OFFSET 5
166 extern EFI_DRIVER_BINDING_PROTOCOL gTerminalDriverBinding
;
167 extern EFI_COMPONENT_NAME_PROTOCOL gTerminalComponentName
;
168 extern EFI_COMPONENT_NAME2_PROTOCOL gTerminalComponentName2
;
171 The user Entry Point for module Terminal. The user code starts with this function.
173 @param[in] ImageHandle The firmware allocated handle for the EFI image.
174 @param[in] SystemTable A pointer to the EFI System Table.
176 @retval EFI_SUCCESS The entry point is executed successfully.
177 @retval other Some error occurs when executing this entry point.
183 IN EFI_HANDLE ImageHandle
,
184 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 @retval EFI_SUCCESS The reset operation succeeds.
196 @retval EFI_DEVICE_ERROR The dependent serial port reset fails.
202 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
203 IN BOOLEAN ExtendedVerification
208 Implements EFI_SIMPLE_TEXT_INPUT_PROTOCOL.ReadKeyStroke().
210 @param This Indicates the calling context.
211 @param Key A pointer to a buffer that is filled in with the
212 keystroke information for the key that was sent
215 @retval EFI_SUCCESS The keystroke information is returned successfully.
216 @retval EFI_NOT_READY There is no keystroke data available.
217 @retval EFI_DEVICE_ERROR The dependent serial device encounters error.
222 TerminalConInReadKeyStroke (
223 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
224 OUT EFI_INPUT_KEY
*Key
228 Check if the key already has been registered.
230 @param RegsiteredData A pointer to a buffer that is filled in with the
231 keystroke state data for the key that was
233 @param InputData A pointer to a buffer that is filled in with the
234 keystroke state data for the key that was
237 @retval TRUE Key be pressed matches a registered key.
238 @retval FLASE Match failed.
243 IN EFI_KEY_DATA
*RegsiteredData
,
244 IN EFI_KEY_DATA
*InputData
248 Event notification function for EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx event
249 Signal the event if there is key available
251 @param Event Indicates the event that invoke this function.
252 @param Context Indicates the calling context.
257 TerminalConInWaitForKeyEx (
263 // Simple Text Input Ex protocol prototypes
267 Reset the input device and optionally run diagnostics
269 @param This Protocol instance pointer.
270 @param ExtendedVerification Driver may perform diagnostics on reset.
272 @retval EFI_SUCCESS The device was reset.
273 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
279 TerminalConInResetEx (
280 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
281 IN BOOLEAN ExtendedVerification
285 Reads the next keystroke from the input device. The WaitForKey Event can
286 be used to test for existence of a keystroke via WaitForEvent () call.
288 @param This Protocol instance pointer.
289 @param KeyData A pointer to a buffer that is filled in with the
290 keystroke state data for the key that was
293 @retval EFI_SUCCESS The keystroke information was returned.
294 @retval EFI_NOT_READY There was no keystroke data available.
295 @retval EFI_DEVICE_ERROR The keystroke information was not returned due
297 @retval EFI_INVALID_PARAMETER KeyData is NULL.
302 TerminalConInReadKeyStrokeEx (
303 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
304 OUT EFI_KEY_DATA
*KeyData
308 Set certain state for the input device.
310 @param This Protocol instance pointer.
311 @param KeyToggleState A pointer to the EFI_KEY_TOGGLE_STATE to set the
312 state for the input device.
314 @retval EFI_SUCCESS The device state was set successfully.
315 @retval EFI_DEVICE_ERROR The device is not functioning correctly and
316 could not have the setting adjusted.
317 @retval EFI_UNSUPPORTED The device does not have the ability to set its
319 @retval EFI_INVALID_PARAMETER KeyToggleState is NULL.
324 TerminalConInSetState (
325 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
326 IN EFI_KEY_TOGGLE_STATE
*KeyToggleState
330 Register a notification function for a particular keystroke for the input device.
332 @param This Protocol instance pointer.
333 @param KeyData A pointer to a buffer that is filled in with the
334 keystroke information data for the key that was
336 @param KeyNotificationFunction Points to the function to be called when the key
337 sequence is typed specified by KeyData.
338 @param NotifyHandle Points to the unique handle assigned to the
339 registered notification.
341 @retval EFI_SUCCESS The notification function was registered
343 @retval EFI_OUT_OF_RESOURCES Unable to allocate resources for necesssary data
345 @retval EFI_INVALID_PARAMETER KeyData or NotifyHandle is NULL.
350 TerminalConInRegisterKeyNotify (
351 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
352 IN EFI_KEY_DATA
*KeyData
,
353 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction
,
354 OUT EFI_HANDLE
*NotifyHandle
358 Remove a registered notification function from a particular keystroke.
360 @param This Protocol instance pointer.
361 @param NotificationHandle The handle of the notification function being
364 @retval EFI_SUCCESS The notification function was unregistered
366 @retval EFI_INVALID_PARAMETER The NotificationHandle is invalid.
367 @retval EFI_NOT_FOUND Can not find the matching entry in database.
372 TerminalConInUnregisterKeyNotify (
373 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
374 IN EFI_HANDLE NotificationHandle
378 Event notification function for EFI_SIMPLE_TEXT_INPUT_PROTOCOL.WaitForKey event
379 Signal the event if there is key available
381 @param Event Indicates the event that invoke this function.
382 @param Context Indicates the calling context.
387 TerminalConInWaitForKey (
393 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset().
394 If ExtendeVerification is TRUE, then perform dependent serial device reset,
395 and set display mode to mode 0.
396 If ExtendedVerification is FALSE, only set display mode to mode 0.
398 @param This Indicates the calling context.
399 @param ExtendedVerification Indicates that the driver may perform a more
400 exhaustive verification operation of the device
403 @retval EFI_SUCCESS The reset operation succeeds.
404 @retval EFI_DEVICE_ERROR The terminal is not functioning correctly or the serial port reset fails.
409 TerminalConOutReset (
410 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
411 IN BOOLEAN ExtendedVerification
415 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString().
416 The Unicode string will be converted to terminal expressible data stream
417 and send to terminal via serial port.
419 @param This Indicates the calling context.
420 @param WString The Null-terminated Unicode string to be displayed
421 on the terminal screen.
423 @retval EFI_SUCCESS The string is output successfully.
424 @retval EFI_DEVICE_ERROR The serial port fails to send the string out.
425 @retval EFI_WARN_UNKNOWN_GLYPH Indicates that some of the characters in the Unicode string could not
426 be rendered and are skipped.
427 @retval EFI_UNSUPPORTED If current display mode is out of range.
432 TerminalConOutOutputString (
433 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
438 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.TestString().
439 If one of the characters in the *Wstring is
440 neither valid Unicode drawing characters,
441 not ASCII code, then this function will return
444 @param This Indicates the calling context.
445 @param WString The Null-terminated Unicode string to be tested.
447 @retval EFI_SUCCESS The terminal is capable of rendering the output string.
448 @retval EFI_UNSUPPORTED Some of the characters in the Unicode string cannot be rendered.
453 TerminalConOutTestString (
454 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
459 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.QueryMode().
460 It returns information for an available text mode
461 that the terminal supports.
462 In this driver, we support text mode 80x25 (mode 0),
463 80x50 (mode 1), 100x31 (mode 2).
465 @param This Indicates the calling context.
466 @param ModeNumber The mode number to return information on.
467 @param Columns The returned columns of the requested mode.
468 @param Rows The returned rows of the requested mode.
470 @retval EFI_SUCCESS The requested mode information is returned.
471 @retval EFI_UNSUPPORTED The mode number is not valid.
472 @retval EFI_DEVICE_ERROR
477 TerminalConOutQueryMode (
478 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
485 Implements EFI_SIMPLE_TEXT_OUT.SetMode().
486 Set the terminal to a specified display mode.
487 In this driver, we only support mode 0.
489 @param This Indicates the calling context.
490 @param ModeNumber The text mode to set.
492 @retval EFI_SUCCESS The requested text mode is set.
493 @retval EFI_DEVICE_ERROR The requested text mode cannot be set
494 because of serial device error.
495 @retval EFI_UNSUPPORTED The text mode number is not valid.
500 TerminalConOutSetMode (
501 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
506 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetAttribute().
508 @param This Indicates the calling context.
509 @param Attribute The attribute to set. Only bit0..6 are valid, all other bits
510 are undefined and must be zero.
512 @retval EFI_SUCCESS The requested attribute is set.
513 @retval EFI_DEVICE_ERROR The requested attribute cannot be set due to serial port error.
514 @retval EFI_UNSUPPORTED The attribute requested is not defined by EFI spec.
519 TerminalConOutSetAttribute (
520 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
525 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.ClearScreen().
526 It clears the ANSI terminal's display to the
527 currently selected background color.
529 @param This Indicates the calling context.
531 @retval EFI_SUCCESS The operation completed successfully.
532 @retval EFI_DEVICE_ERROR The terminal screen cannot be cleared due to serial port error.
533 @retval EFI_UNSUPPORTED The terminal is not in a valid display mode.
538 TerminalConOutClearScreen (
539 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
543 Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetCursorPosition().
545 @param This Indicates the calling context.
546 @param Column The row to set cursor to.
547 @param Row The column to set cursor to.
549 @retval EFI_SUCCESS The operation completed successfully.
550 @retval EFI_DEVICE_ERROR The request fails due to serial port error.
551 @retval EFI_UNSUPPORTED The terminal is not in a valid text mode, or the cursor position
552 is invalid for current mode.
557 TerminalConOutSetCursorPosition (
558 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
564 Implements SIMPLE_TEXT_OUTPUT.EnableCursor().
565 In this driver, the cursor cannot be hidden.
567 @param This Indicates the calling context.
568 @param Visible If TRUE, the cursor is set to be visible,
569 If FALSE, the cursor is set to be invisible.
571 @retval EFI_SUCCESS The request is valid.
572 @retval EFI_UNSUPPORTED The terminal does not support cursor hidden.
577 TerminalConOutEnableCursor (
578 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
583 Test to see if this driver supports Controller.
585 @param This Protocol instance pointer.
586 @param ControllerHandle Handle of device to test
587 @param RemainingDevicePath Optional parameter use to pick a specific child
590 @retval EFI_SUCCESS This driver supports this device.
591 @retval EFI_ALREADY_STARTED This driver is already running on this device.
592 @retval other This driver does not support this device.
597 TerminalDriverBindingSupported (
598 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
599 IN EFI_HANDLE ControllerHandle
,
600 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
604 Start this driver on Controller by opening a Serial IO protocol,
605 reading Device Path, and creating a child handle with a Simple Text In,
606 Simple Text In Ex and Simple Text Out protocol, and device path protocol.
607 And store Console Device Environment Variables.
609 @param This Protocol instance pointer.
610 @param Controller Handle of device to bind driver to
611 @param RemainingDevicePath Optional parameter use to pick a specific child
614 @retval EFI_SUCCESS This driver is added to Controller.
615 @retval EFI_ALREADY_STARTED This driver is already running on Controller.
616 @retval other This driver does not support this device.
621 TerminalDriverBindingStart (
622 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
623 IN EFI_HANDLE Controller
,
624 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
629 Stop this driver on Controller by closing Simple Text In, Simple Text
630 In Ex, Simple Text Out protocol, and removing parent device path from
631 Console Device Environment Variables.
633 @param This Protocol instance pointer.
634 @param Controller Handle of device to stop driver on
635 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
636 children is zero stop the entire bus driver.
637 @param ChildHandleBuffer List of Child Handles to Stop.
639 @retval EFI_SUCCESS This driver is removed Controller.
640 @retval other This driver could not be removed from this device.
645 TerminalDriverBindingStop (
646 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
647 IN EFI_HANDLE Controller
,
648 IN UINTN NumberOfChildren
,
649 IN EFI_HANDLE
*ChildHandleBuffer
653 Free notify functions list.
655 @param ListHead The list head
657 @retval EFI_SUCCESS Free the notify list successfully.
658 @retval EFI_INVALID_PARAMETER ListHead is NULL.
662 TerminalFreeNotifyList (
663 IN OUT LIST_ENTRY
*ListHead
667 Retrieves a Unicode string that is the user readable name of the driver.
669 This function retrieves the user readable name of a driver in the form of a
670 Unicode string. If the driver specified by This has a user readable name in
671 the language specified by Language, then a pointer to the driver name is
672 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
673 by This does not support the language specified by Language,
674 then EFI_UNSUPPORTED is returned.
676 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
677 EFI_COMPONENT_NAME_PROTOCOL instance.
679 @param Language[in] A pointer to a Null-terminated ASCII string
680 array indicating the language. This is the
681 language of the driver name that the caller is
682 requesting, and it must match one of the
683 languages specified in SupportedLanguages. The
684 number of languages supported by a driver is up
685 to the driver writer. Language is specified
686 in RFC 3066 or ISO 639-2 language code format.
688 @param DriverName[out] A pointer to the Unicode string to return.
689 This Unicode string is the name of the
690 driver specified by This in the language
691 specified by Language.
693 @retval EFI_SUCCESS The Unicode string for the Driver specified by
694 This and the language specified by Language was
695 returned in DriverName.
697 @retval EFI_INVALID_PARAMETER Language is NULL.
699 @retval EFI_INVALID_PARAMETER DriverName is NULL.
701 @retval EFI_UNSUPPORTED The driver specified by This does not support
702 the language specified by Language.
707 TerminalComponentNameGetDriverName (
708 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
710 OUT CHAR16
**DriverName
715 Retrieves a Unicode string that is the user readable name of the controller
716 that is being managed by a driver.
718 This function retrieves the user readable name of the controller specified by
719 ControllerHandle and ChildHandle in the form of a Unicode string. If the
720 driver specified by This has a user readable name in the language specified by
721 Language, then a pointer to the controller name is returned in ControllerName,
722 and EFI_SUCCESS is returned. If the driver specified by This is not currently
723 managing the controller specified by ControllerHandle and ChildHandle,
724 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
725 support the language specified by Language, then EFI_UNSUPPORTED is returned.
727 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
728 EFI_COMPONENT_NAME_PROTOCOL instance.
730 @param ControllerHandle[in] The handle of a controller that the driver
731 specified by This is managing. This handle
732 specifies the controller whose name is to be
735 @param ChildHandle[in] The handle of the child controller to retrieve
736 the name of. This is an optional parameter that
737 may be NULL. It will be NULL for device
738 drivers. It will also be NULL for a bus drivers
739 that wish to retrieve the name of the bus
740 controller. It will not be NULL for a bus
741 driver that wishes to retrieve the name of a
744 @param Language[in] A pointer to a Null-terminated ASCII string
745 array indicating the language. This is the
746 language of the driver name that the caller is
747 requesting, and it must match one of the
748 languages specified in SupportedLanguages. The
749 number of languages supported by a driver is up
750 to the driver writer. Language is specified in
751 RFC 3066 or ISO 639-2 language code format.
753 @param ControllerName[out] A pointer to the Unicode string to return.
754 This Unicode string is the name of the
755 controller specified by ControllerHandle and
756 ChildHandle in the language specified by
757 Language from the point of view of the driver
760 @retval EFI_SUCCESS The Unicode string for the user readable name in
761 the language specified by Language for the
762 driver specified by This was returned in
765 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
767 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
770 @retval EFI_INVALID_PARAMETER Language is NULL.
772 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
774 @retval EFI_UNSUPPORTED The driver specified by This is not currently
775 managing the controller specified by
776 ControllerHandle and ChildHandle.
778 @retval EFI_UNSUPPORTED The driver specified by This does not support
779 the language specified by Language.
784 TerminalComponentNameGetControllerName (
785 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
786 IN EFI_HANDLE ControllerHandle
,
787 IN EFI_HANDLE ChildHandle OPTIONAL
,
789 OUT CHAR16
**ControllerName
794 // internal functions
798 Check for a pending key in the Efi Key FIFO or Serial device buffer.
800 @param This Indicates the calling context.
802 @retval EFI_SUCCESS There is key pending.
803 @retval EFI_NOT_READY There is no key pending.
804 @retval EFI_DEVICE_ERROR If Serial IO is not attached to serial device.
808 TerminalConInCheckForKey (
809 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
813 Update terminal device path in Console Device Environment Variables.
815 @param VariableName The Console Device Environment Variable.
816 @param ParentDevicePath The terminal device path to be updated.
822 TerminalUpdateConsoleDevVariable (
823 IN CHAR16
*VariableName
,
824 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
828 Remove console device variable.
830 @param VariableName A pointer to the variable name.
831 @param ParentDevicePath A pointer to the parent device path.
835 TerminalRemoveConsoleDevVariable (
836 IN CHAR16
*VariableName
,
837 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
841 Read the EFI variable (VendorGuid/Name) and return a dynamically allocated
842 buffer, and the size of the buffer. On failure return NULL.
844 @param Name String part of EFI variable name
845 @param VendorGuid GUID part of EFI variable name
846 @param VariableSize Returns the size of the EFI variable that was read
848 @return Dynamically allocated memory that contains a copy of the EFI variable.
849 Caller is repsoncible freeing the buffer. If variable was not read,
854 TerminalGetVariableAndSize (
856 IN EFI_GUID
*VendorGuid
,
857 OUT UINTN
*VariableSize
861 Build termial device path according to terminal type.
863 @param TerminalType The terminal type is PC ANSI, VT100, VT100+ or VT-UTF8.
864 @param ParentDevicePath Parent device path.
865 @param TerminalDevicePath Returned terminal device path, if building successfully.
867 @retval EFI_UNSUPPORTED Terminal does not belong to the supported type.
868 @retval EFI_OUT_OF_RESOURCES Generate terminal device path failed.
869 @retval EFI_SUCCESS Build terminal device path successfully.
873 SetTerminalDevicePath (
874 IN UINT8 TerminalType
,
875 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
876 OUT EFI_DEVICE_PATH_PROTOCOL
**TerminalDevicePath
880 Get one key out of serial buffer.
882 @param SerialIo Serial I/O protocl attached to the serial device.
883 @param Input The fetched key.
885 @retval EFI_NOT_READY If serial buffer is empty.
886 @retval EFI_DEVICE_ERROR If reading serial buffer encounter error.
887 @retval EFI_SUCCESS If reading serial buffer successfully, put
888 the fetched key to the parameter output.
892 GetOneKeyFromSerial (
893 EFI_SERIAL_IO_PROTOCOL
*SerialIo
,
898 Insert one byte raw data into the Raw Data FIFO.
900 @param TerminalDevice Terminal driver private structure.
901 @param Input The key will be input.
903 @retval TRUE If insert successfully.
904 @retval FLASE If Raw Data buffer is full before key insertion,
909 RawFiFoInsertOneKey (
910 TERMINAL_DEV
*TerminalDevice
,
915 Remove one pre-fetched key out of the Raw Data FIFO.
917 @param TerminalDevice Terminal driver private structure.
918 @param Output The key will be removed.
920 @retval TRUE If insert successfully.
921 @retval FLASE If Raw Data FIFO buffer is empty before remove operation.
925 RawFiFoRemoveOneKey (
926 TERMINAL_DEV
*TerminalDevice
,
931 Clarify whether Raw Data FIFO buffer is empty.
933 @param TerminalDevice Terminal driver private structure
935 @retval TRUE If Raw Data FIFO buffer is empty.
936 @retval FLASE If Raw Data FIFO buffer is not empty.
941 TERMINAL_DEV
*TerminalDevice
945 Clarify whether Raw Data FIFO buffer is full.
947 @param TerminalDevice Terminal driver private structure
949 @retval TRUE If Raw Data FIFO buffer is full.
950 @retval FLASE If Raw Data FIFO buffer is not full.
955 TERMINAL_DEV
*TerminalDevice
959 Insert one pre-fetched key into the FIFO buffer.
961 @param TerminalDevice Terminal driver private structure.
962 @param Key The key will be input.
964 @retval TRUE If insert successfully.
965 @retval FLASE If FIFO buffer is full before key insertion,
970 EfiKeyFiFoInsertOneKey (
971 TERMINAL_DEV
*TerminalDevice
,
976 Remove one pre-fetched key out of the FIFO buffer.
978 @param TerminalDevice Terminal driver private structure.
979 @param Output The key will be removed.
981 @retval TRUE If insert successfully.
982 @retval FLASE If FIFO buffer is empty before remove operation.
986 EfiKeyFiFoRemoveOneKey (
987 TERMINAL_DEV
*TerminalDevice
,
988 EFI_INPUT_KEY
*Output
992 Clarify whether FIFO buffer is empty.
994 @param TerminalDevice Terminal driver private structure
996 @retval TRUE If FIFO buffer is empty.
997 @retval FLASE If FIFO buffer is not empty.
1002 TERMINAL_DEV
*TerminalDevice
1006 Clarify whether FIFO buffer is full.
1008 @param TerminalDevice Terminal driver private structure
1010 @retval TRUE If FIFO buffer is full.
1011 @retval FLASE If FIFO buffer is not full.
1016 TERMINAL_DEV
*TerminalDevice
1020 Insert one pre-fetched key into the Unicode FIFO buffer.
1022 @param TerminalDevice Terminal driver private structure.
1023 @param Input The key will be input.
1025 @retval TRUE If insert successfully.
1026 @retval FLASE If Unicode FIFO buffer is full before key insertion,
1027 and the key is lost.
1031 UnicodeFiFoInsertOneKey (
1032 TERMINAL_DEV
*TerminalDevice
,
1037 Remove one pre-fetched key out of the Unicode FIFO buffer.
1039 @param TerminalDevice Terminal driver private structure.
1040 @param Output The key will be removed.
1042 @retval TRUE If insert successfully.
1043 @retval FLASE If Unicode FIFO buffer is empty before remove operation.
1047 UnicodeFiFoRemoveOneKey (
1048 TERMINAL_DEV
*TerminalDevice
,
1053 Clarify whether Unicode FIFO buffer is empty.
1055 @param TerminalDevice Terminal driver private structure
1057 @retval TRUE If Unicode FIFO buffer is empty.
1058 @retval FLASE If Unicode FIFO buffer is not empty.
1062 IsUnicodeFiFoEmpty (
1063 TERMINAL_DEV
*TerminalDevice
1067 Clarify whether Unicode FIFO buffer is full.
1069 @param TerminalDevice Terminal driver private structure
1071 @retval TRUE If Unicode FIFO buffer is full.
1072 @retval FLASE If Unicode FIFO buffer is not full.
1077 TERMINAL_DEV
*TerminalDevice
1081 Count Unicode FIFO buffer.
1083 @param TerminalDevice Terminal driver private structure
1085 @return The count in bytes of Unicode FIFO.
1089 UnicodeFiFoGetKeyCount (
1090 TERMINAL_DEV
*TerminalDevice
1094 Translate raw data into Unicode (according to different encode), and
1095 translate Unicode into key information. (according to different standard).
1097 @param TerminalDevice Terminal driver private structure.
1101 TranslateRawDataToEfiKey (
1102 IN TERMINAL_DEV
*TerminalDevice
1106 // internal functions for PC ANSI
1110 Translate all raw data in the Raw FIFI into unicode, and insert
1111 them into Unicode FIFO.
1113 @param TerminalDevice The terminal device.
1117 AnsiRawDataToUnicode (
1118 IN TERMINAL_DEV
*TerminalDevice
1122 Converts a stream of Unicode characters from a terminal input device into EFI Keys that
1123 can be read through the Simple Input Protocol.
1125 The table below shows the keyboard input mappings that this function supports.
1126 If the ESC sequence listed in one of the columns is presented, then it is translated
1127 into the coorespoding EFI Scan Code. If a matching sequence is not found, then the raw
1128 key strokes are converted into EFI Keys.
1130 2 seconds are allowed for an ESC sequence to be completed. If the ESC sequence is not
1131 completed in 2 seconds, then the raw key strokes of the partial ESC sequence are
1132 converted into EFI Keys.
1133 There is one special input sequence that will force the system to reset.
1134 This is ESC R ESC r ESC R.
1136 Symbols used in table below
1137 ===========================
1142 +=========+======+===========+==========+==========+
1143 | | EFI | UEFI 2.0 | | |
1144 | | Scan | | VT100+ | |
1145 | KEY | Code | PC ANSI | VTUTF8 | VT100 |
1146 +=========+======+===========+==========+==========+
1147 | NULL | 0x00 | | | |
1148 | UP | 0x01 | ESC [ A | ESC [ A | ESC [ A |
1149 | DOWN | 0x02 | ESC [ B | ESC [ B | ESC [ B |
1150 | RIGHT | 0x03 | ESC [ C | ESC [ C | ESC [ C |
1151 | LEFT | 0x04 | ESC [ D | ESC [ D | ESC [ D |
1152 | HOME | 0x05 | ESC [ H | ESC h | ESC [ H |
1153 | END | 0x06 | ESC [ F | ESC k | ESC [ K |
1154 | INSERT | 0x07 | ESC [ @ | ESC + | ESC [ @ |
1155 | | | ESC [ L | | ESC [ L |
1156 | DELETE | 0x08 | ESC [ X | ESC - | ESC [ P |
1157 | PG UP | 0x09 | ESC [ I | ESC ? | ESC [ V |
1159 | PG DOWN | 0x0A | ESC [ G | ESC / | ESC [ U |
1161 | F1 | 0x0B | ESC [ M | ESC 1 | ESC O P |
1162 | F2 | 0x0C | ESC [ N | ESC 2 | ESC O Q |
1163 | F3 | 0x0D | ESC [ O | ESC 3 | ESC O w |
1164 | F4 | 0x0E | ESC [ P | ESC 4 | ESC O x |
1165 | F5 | 0x0F | ESC [ Q | ESC 5 | ESC O t |
1166 | F6 | 0x10 | ESC [ R | ESC 6 | ESC O u |
1167 | F7 | 0x11 | ESC [ S | ESC 7 | ESC O q |
1168 | F8 | 0x12 | ESC [ T | ESC 8 | ESC O r |
1169 | F9 | 0x13 | ESC [ U | ESC 9 | ESC O p |
1170 | F10 | 0x14 | ESC [ V | ESC 0 | ESC O M |
1171 | Escape | 0x17 | ESC | ESC | ESC |
1172 | F11 | 0x15 | | ESC ! | |
1173 | F12 | 0x16 | | ESC @ | |
1174 +=========+======+===========+==========+==========+
1178 ESC R ESC r ESC R = Reset System
1181 @param TerminalDevice The terminal device to use to translate raw input into EFI Keys
1186 IN TERMINAL_DEV
*TerminalDevice
1190 Check if input string is valid Ascii string, valid EFI control characters
1191 or valid text graphics.
1193 @param TerminalDevice The terminal device.
1194 @param WString The input string.
1196 @retval EFI_UNSUPPORTED If not all input characters are valid.
1197 @retval EFI_SUCCESS If all input characters are valid.
1202 IN TERMINAL_DEV
*TerminalDevice
,
1207 // internal functions for VTUTF8
1211 Translate all VT-UTF8 characters in the Raw FIFI into unicode characters,
1212 and insert them into Unicode FIFO.
1214 @param VtUtf8Device The terminal device.
1218 VTUTF8RawDataToUnicode (
1219 IN TERMINAL_DEV
*VtUtf8Device
1223 Check if input string is valid VT-UTF8 string.
1225 @param TerminalDevice The terminal device.
1226 @param WString The input string.
1228 @retval EFI_SUCCESS If all input characters are valid.
1233 IN TERMINAL_DEV
*TerminalDevice
,
1238 Translate one Unicode character into VT-UTF8 characters.
1241 Bits per Character | Unicode Character Range | Unicode Binary Encoding | UTF8 Binary Encoding
1242 0-7 | 0x0000 - 0x007F | 00000000 0xxxxxxx | 0xxxxxxx
1243 8-11 | 0x0080 - 0x07FF | 00000xxx xxxxxxxx | 110xxxxx 10xxxxxx
1244 12-16 | 0x0800 - 0xFFFF | xxxxxxxx xxxxxxxx | 1110xxxx 10xxxxxx 10xxxxxx
1247 @param Unicode Unicode character need translating.
1248 @param Utf8Char Return VT-UTF8 character set.
1249 @param ValidBytes The count of valid VT-UTF8 characters. If
1250 ValidBytes is zero, no valid VT-UTF8 returned.
1256 OUT UTF8_CHAR
*Utf8Char
,
1257 OUT UINT8
*ValidBytes
1261 Get one valid VT-UTF8 characters set from Raw Data FIFO.
1263 @param Utf8Device The terminal device.
1264 @param Utf8Char Returned valid VT-UTF8 characters set.
1265 @param ValidBytes The count of returned VT-VTF8 characters.
1266 If ValidBytes is zero, no valid VT-UTF8 returned.
1270 GetOneValidUtf8Char (
1271 IN TERMINAL_DEV
*Utf8Device
,
1272 OUT UTF8_CHAR
*Utf8Char
,
1273 OUT UINT8
*ValidBytes
1277 Translate VT-UTF8 characters into one Unicode character.
1280 Bits per Character | Unicode Character Range | Unicode Binary Encoding | UTF8 Binary Encoding
1281 0-7 | 0x0000 - 0x007F | 00000000 0xxxxxxx | 0xxxxxxx
1282 8-11 | 0x0080 - 0x07FF | 00000xxx xxxxxxxx | 110xxxxx 10xxxxxx
1283 12-16 | 0x0800 - 0xFFFF | xxxxxxxx xxxxxxxx | 1110xxxx 10xxxxxx 10xxxxxx
1286 @param Utf8Char VT-UTF8 character set needs translating.
1287 @param ValidBytes The count of valid VT-UTF8 characters.
1288 @param UnicodeChar Returned unicode character.
1293 IN UTF8_CHAR Utf8Char
,
1294 IN UINT8 ValidBytes
,
1295 OUT CHAR16
*UnicodeChar
1299 // functions for boxdraw unicode
1303 Detects if a Unicode char is for Box Drawing text graphics.
1305 @param Graphic Unicode char to test.
1306 @param PcAnsi Optional pointer to return PCANSI equivalent of
1308 @param Ascii Optional pointer to return ASCII equivalent of
1311 @retval TRUE If Graphic is a supported Unicode Box Drawing character.
1315 TerminalIsValidTextGraphics (
1317 OUT CHAR8
*PcAnsi
, OPTIONAL
1318 OUT CHAR8
*Ascii OPTIONAL
1322 Detects if a valid ASCII char.
1324 @param Ascii An ASCII character.
1326 @retval TRUE If it is a valid ASCII character.
1327 @retval FALSE If it is not a valid ASCII character.
1331 TerminalIsValidAscii (
1336 Detects if a valid EFI control character.
1338 @param CharC An input EFI Control character.
1340 @retval TRUE If it is a valid EFI control character.
1341 @retval FALSE If it is not a valid EFI control character.
1345 TerminalIsValidEfiCntlChar (
1350 Check if the device supports hot-plug through its device path.
1352 This function could be updated to check more types of Hot Plug devices.
1353 Currently, it checks USB and PCCard device.
1355 @param DevicePath Pointer to device's device path.
1357 @retval TRUE The devcie is a hot-plug device
1358 @retval FALSE The devcie is not a hot-plug device.
1363 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath