3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
28 #include <Protocol/SimpleTextOut.h>
29 #include <Protocol/SerialIo.h>
30 #include <Guid/GlobalVariable.h>
31 #include <Protocol/DevicePath.h>
32 #include <Protocol/SimpleTextIn.h>
33 #include <Guid/HotPlugDevice.h>
34 #include <Guid/PcAnsi.h>
35 #include <Library/DebugLib.h>
36 #include <Library/UefiDriverEntryPoint.h>
37 #include <Library/UefiLib.h>
38 #include <Library/ReportStatusCodeLib.h>
39 #include <Library/BaseMemoryLib.h>
40 #include <Library/MemoryAllocationLib.h>
41 #include <Library/UefiBootServicesTableLib.h>
42 #include <Library/UefiRuntimeServicesTableLib.h>
43 #include <Library/DevicePathLib.h>
44 #include <Library/PcdLib.h>
48 #define RAW_FIFO_MAX_NUMBER 256
49 #define FIFO_MAX_NUMBER 128
54 UINT8 Data
[RAW_FIFO_MAX_NUMBER
+ 1];
60 UINT16 Data
[FIFO_MAX_NUMBER
+ 1];
66 EFI_INPUT_KEY Data
[FIFO_MAX_NUMBER
+ 1];
69 #define TERMINAL_DEV_SIGNATURE EFI_SIGNATURE_32 ('t', 'm', 'n', 'l')
75 EFI_SERIAL_IO_PROTOCOL
*SerialIo
;
76 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
77 EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleInput
;
78 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL SimpleTextOutput
;
79 EFI_SIMPLE_TEXT_OUTPUT_MODE SimpleTextOutputMode
;
80 UINTN SerialInTimeOut
;
81 RAW_DATA_FIFO RawFiFo
;
82 UNICODE_FIFO UnicodeFiFo
;
83 EFI_KEY_FIFO EfiKeyFiFo
;
84 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
85 EFI_EVENT TwoSecondTimeOut
;
90 // Esc could not be output to the screen by user,
91 // but the terminal driver need to output it to
92 // the terminal emulation software to send control sequence.
93 // This boolean is used by the terminal driver only
94 // to indicate whether the Esc could be sent or not.
96 BOOLEAN OutputEscChar
;
99 #define INPUT_STATE_DEFAULT 0x00
100 #define INPUT_STATE_ESC 0x01
101 #define INPUT_STATE_CSI 0x02
102 #define INPUT_STATE_LEFTOPENBRACKET 0x04
103 #define INPUT_STATE_O 0x08
104 #define INPUT_STATE_2 0x10
106 #define RESET_STATE_DEFAULT 0x00
107 #define RESET_STATE_ESC_R 0x01
108 #define RESET_STATE_ESC_R_ESC_r 0x02
110 #define TERMINAL_CON_IN_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleInput, TERMINAL_DEV_SIGNATURE)
111 #define TERMINAL_CON_OUT_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleTextOutput, TERMINAL_DEV_SIGNATURE)
121 #define VT100PlusType 2
124 #define LEFTOPENBRACKET 0x5b // '['
130 #define MODE0_COLUMN_COUNT 80
131 #define MODE0_ROW_COUNT 25
137 #define BRIGHT_CONTROL_OFFSET 2
138 #define FOREGROUND_CONTROL_OFFSET 6
139 #define BACKGROUND_CONTROL_OFFSET 11
141 #define COLUMN_OFFSET 5
152 extern EFI_DRIVER_BINDING_PROTOCOL gTerminalDriverBinding
;
153 extern EFI_COMPONENT_NAME_PROTOCOL gTerminalComponentName
;
154 extern EFI_COMPONENT_NAME2_PROTOCOL gTerminalComponentName2
;
162 IN EFI_HANDLE ImageHandle
,
163 IN EFI_SYSTEM_TABLE
*SystemTable
170 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
171 IN BOOLEAN ExtendedVerification
177 TerminalConInReadKeyStroke (
178 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
179 OUT EFI_INPUT_KEY
*Key
185 TerminalConInWaitForKey (
193 TerminalConOutReset (
194 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
195 IN BOOLEAN ExtendedVerification
201 TerminalConOutOutputString (
202 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
209 TerminalConOutTestString (
210 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
217 TerminalConOutQueryMode (
218 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
227 TerminalConOutSetMode (
228 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
235 TerminalConOutSetAttribute (
236 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
243 TerminalConOutClearScreen (
244 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
250 TerminalConOutSetCursorPosition (
251 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
259 TerminalConOutEnableCursor (
260 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
*This
,
267 TerminalDriverBindingSupported (
268 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
269 IN EFI_HANDLE Controller
,
270 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
275 TerminalDriverBindingStart (
276 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
277 IN EFI_HANDLE Controller
,
278 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
283 TerminalDriverBindingStop (
284 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
285 IN EFI_HANDLE Controller
,
286 IN UINTN NumberOfChildren
,
287 IN EFI_HANDLE
*ChildHandleBuffer
291 Retrieves a Unicode string that is the user readable name of the driver.
293 This function retrieves the user readable name of a driver in the form of a
294 Unicode string. If the driver specified by This has a user readable name in
295 the language specified by Language, then a pointer to the driver name is
296 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
297 by This does not support the language specified by Language,
298 then EFI_UNSUPPORTED is returned.
300 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
301 EFI_COMPONENT_NAME_PROTOCOL instance.
303 @param Language[in] A pointer to a Null-terminated ASCII string
304 array indicating the language. This is the
305 language of the driver name that the caller is
306 requesting, and it must match one of the
307 languages specified in SupportedLanguages. The
308 number of languages supported by a driver is up
309 to the driver writer. Language is specified
310 in RFC 3066 or ISO 639-2 language code format.
312 @param DriverName[out] A pointer to the Unicode string to return.
313 This Unicode string is the name of the
314 driver specified by This in the language
315 specified by Language.
317 @retval EFI_SUCCESS The Unicode string for the Driver specified by
318 This and the language specified by Language was
319 returned in DriverName.
321 @retval EFI_INVALID_PARAMETER Language is NULL.
323 @retval EFI_INVALID_PARAMETER DriverName is NULL.
325 @retval EFI_UNSUPPORTED The driver specified by This does not support
326 the language specified by Language.
331 TerminalComponentNameGetDriverName (
332 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
334 OUT CHAR16
**DriverName
339 Retrieves a Unicode string that is the user readable name of the controller
340 that is being managed by a driver.
342 This function retrieves the user readable name of the controller specified by
343 ControllerHandle and ChildHandle in the form of a Unicode string. If the
344 driver specified by This has a user readable name in the language specified by
345 Language, then a pointer to the controller name is returned in ControllerName,
346 and EFI_SUCCESS is returned. If the driver specified by This is not currently
347 managing the controller specified by ControllerHandle and ChildHandle,
348 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
349 support the language specified by Language, then EFI_UNSUPPORTED is returned.
351 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
352 EFI_COMPONENT_NAME_PROTOCOL instance.
354 @param ControllerHandle[in] The handle of a controller that the driver
355 specified by This is managing. This handle
356 specifies the controller whose name is to be
359 @param ChildHandle[in] The handle of the child controller to retrieve
360 the name of. This is an optional parameter that
361 may be NULL. It will be NULL for device
362 drivers. It will also be NULL for a bus drivers
363 that wish to retrieve the name of the bus
364 controller. It will not be NULL for a bus
365 driver that wishes to retrieve the name of a
368 @param Language[in] A pointer to a Null-terminated ASCII string
369 array indicating the language. This is the
370 language of the driver name that the caller is
371 requesting, and it must match one of the
372 languages specified in SupportedLanguages. The
373 number of languages supported by a driver is up
374 to the driver writer. Language is specified in
375 RFC 3066 or ISO 639-2 language code format.
377 @param ControllerName[out] A pointer to the Unicode string to return.
378 This Unicode string is the name of the
379 controller specified by ControllerHandle and
380 ChildHandle in the language specified by
381 Language from the point of view of the driver
384 @retval EFI_SUCCESS The Unicode string for the user readable name in
385 the language specified by Language for the
386 driver specified by This was returned in
389 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
391 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
394 @retval EFI_INVALID_PARAMETER Language is NULL.
396 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
398 @retval EFI_UNSUPPORTED The driver specified by This is not currently
399 managing the controller specified by
400 ControllerHandle and ChildHandle.
402 @retval EFI_UNSUPPORTED The driver specified by This does not support
403 the language specified by Language.
408 TerminalComponentNameGetControllerName (
409 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
410 IN EFI_HANDLE ControllerHandle
,
411 IN EFI_HANDLE ChildHandle OPTIONAL
,
413 OUT CHAR16
**ControllerName
418 // internal functions
421 TerminalConInCheckForKey (
422 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
427 TerminalUpdateConsoleDevVariable (
428 IN CHAR16
*VariableName
,
429 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
434 TerminalRemoveConsoleDevVariable (
435 IN CHAR16
*VariableName
,
436 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
441 TerminalGetVariableAndSize (
443 IN EFI_GUID
*VendorGuid
,
444 OUT UINTN
*VariableSize
449 SetTerminalDevicePath (
450 IN UINT8 TerminalType
,
451 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
452 OUT EFI_DEVICE_PATH_PROTOCOL
**TerminalDevicePath
458 IN TERMINAL_DEV
*TerminalDevice
463 InitializeUnicodeFiFo (
464 IN TERMINAL_DEV
*TerminalDevice
469 InitializeEfiKeyFiFo (
470 IN TERMINAL_DEV
*TerminalDevice
475 GetOneKeyFromSerial (
476 EFI_SERIAL_IO_PROTOCOL
*SerialIo
,
482 RawFiFoInsertOneKey (
483 TERMINAL_DEV
*TerminalDevice
,
489 RawFiFoRemoveOneKey (
490 TERMINAL_DEV
*TerminalDevice
,
497 TERMINAL_DEV
*TerminalDevice
503 TERMINAL_DEV
*TerminalDevice
508 EfiKeyFiFoInsertOneKey (
509 TERMINAL_DEV
*TerminalDevice
,
515 EfiKeyFiFoRemoveOneKey (
516 TERMINAL_DEV
*TerminalDevice
,
517 EFI_INPUT_KEY
*Output
523 TERMINAL_DEV
*TerminalDevice
529 TERMINAL_DEV
*TerminalDevice
534 UnicodeFiFoInsertOneKey (
535 TERMINAL_DEV
*TerminalDevice
,
541 UnicodeFiFoRemoveOneKey (
542 TERMINAL_DEV
*TerminalDevice
,
549 TERMINAL_DEV
*TerminalDevice
555 TERMINAL_DEV
*TerminalDevice
560 UnicodeFiFoGetKeyCount (
561 TERMINAL_DEV
*TerminalDevice
566 TranslateRawDataToEfiKey (
567 IN TERMINAL_DEV
*TerminalDevice
572 // internal functions for PC ANSI
575 AnsiRawDataToUnicode (
576 IN TERMINAL_DEV
*PcAnsiDevice
582 IN TERMINAL_DEV
*PcAnsiDevice
588 IN TERMINAL_DEV
*TerminalDevice
,
594 // internal functions for VT100
598 IN TERMINAL_DEV
*VT100Device
,
604 // internal functions for VT100Plus
607 VT100PlusTestString (
608 IN TERMINAL_DEV
*TerminalDevice
,
614 // internal functions for VTUTF8
617 VTUTF8RawDataToUnicode (
618 IN TERMINAL_DEV
*VtUtf8Device
624 IN TERMINAL_DEV
*TerminalDevice
,
632 OUT UTF8_CHAR
*Utf8Char
,
633 OUT UINT8
*ValidBytes
638 GetOneValidUtf8Char (
639 IN TERMINAL_DEV
*Utf8Device
,
640 OUT UTF8_CHAR
*Utf8Char
,
641 OUT UINT8
*ValidBytes
647 IN UTF8_CHAR Utf8Char
,
649 OUT CHAR16
*UnicodeChar
654 // functions for boxdraw unicode
657 TerminalIsValidTextGraphics (
659 OUT CHAR8
*PcAnsi
, OPTIONAL
660 OUT CHAR8
*Ascii OPTIONAL
665 TerminalIsValidAscii (
671 TerminalIsValidEfiCntlChar (