1 /** @file
2   Header file for Terminal driver.
3 
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
9 
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.
12 
13 **/
14 
15 #ifndef _TERMINAL_H_
16 #define _TERMINAL_H_
17 
18 
19 #include <Uefi.h>
20 
21 #include <Guid/GlobalVariable.h>
22 #include <Guid/PcAnsi.h>
23 #include <Guid/TtyTerm.h>
24 #include <Guid/StatusCodeDataTypeVariable.h>
25 
26 #include <Protocol/SimpleTextOut.h>
27 #include <Protocol/SerialIo.h>
28 #include <Protocol/DevicePath.h>
29 #include <Protocol/SimpleTextIn.h>
30 #include <Protocol/SimpleTextInEx.h>
31 
32 #include <Library/DebugLib.h>
33 #include <Library/UefiDriverEntryPoint.h>
34 #include <Library/UefiLib.h>
35 #include <Library/ReportStatusCodeLib.h>
36 #include <Library/BaseMemoryLib.h>
37 #include <Library/MemoryAllocationLib.h>
38 #include <Library/UefiBootServicesTableLib.h>
39 #include <Library/UefiRuntimeServicesTableLib.h>
40 #include <Library/DevicePathLib.h>
41 #include <Library/PcdLib.h>
42 #include <Library/BaseLib.h>
43 
44 
45 #define RAW_FIFO_MAX_NUMBER 256
46 #define FIFO_MAX_NUMBER     128
47 
48 typedef struct {
49   UINT8 Head;
50   UINT8 Tail;
51   UINT8 Data[RAW_FIFO_MAX_NUMBER + 1];
52 } RAW_DATA_FIFO;
53 
54 typedef struct {
55   UINT8   Head;
56   UINT8   Tail;
57   UINT16  Data[FIFO_MAX_NUMBER + 1];
58 } UNICODE_FIFO;
59 
60 typedef struct {
61   UINT8         Head;
62   UINT8         Tail;
63   EFI_INPUT_KEY Data[FIFO_MAX_NUMBER + 1];
64 } EFI_KEY_FIFO;
65 
66 typedef struct {
67   UINTN   Columns;
68   UINTN   Rows;
69 } TERMINAL_CONSOLE_MODE_DATA;
70 
71 #define KEYBOARD_TIMER_INTERVAL         200000  // 0.02s
72 
73 #define TERMINAL_DEV_SIGNATURE  SIGNATURE_32 ('t', 'm', 'n', 'l')
74 
75 #define TERMINAL_CONSOLE_IN_EX_NOTIFY_SIGNATURE SIGNATURE_32 ('t', 'm', 'e', 'n')
76 
77 typedef struct _TERMINAL_CONSOLE_IN_EX_NOTIFY {
78   UINTN                                 Signature;
79   EFI_KEY_DATA                          KeyData;
80   EFI_KEY_NOTIFY_FUNCTION               KeyNotificationFn;
81   LIST_ENTRY                            NotifyEntry;
82 } TERMINAL_CONSOLE_IN_EX_NOTIFY;
83 typedef struct {
84   UINTN                               Signature;
85   EFI_HANDLE                          Handle;
86   UINT8                               TerminalType;
87   EFI_SERIAL_IO_PROTOCOL              *SerialIo;
88   EFI_DEVICE_PATH_PROTOCOL            *DevicePath;
89   EFI_SIMPLE_TEXT_INPUT_PROTOCOL      SimpleInput;
90   EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL     SimpleTextOutput;
91   EFI_SIMPLE_TEXT_OUTPUT_MODE         SimpleTextOutputMode;
92   TERMINAL_CONSOLE_MODE_DATA          *TerminalConsoleModeData;
93   UINTN                               SerialInTimeOut;
94   RAW_DATA_FIFO                       *RawFiFo;
95   UNICODE_FIFO                        *UnicodeFiFo;
96   EFI_KEY_FIFO                        *EfiKeyFiFo;
97   EFI_UNICODE_STRING_TABLE            *ControllerNameTable;
98   EFI_EVENT                           TimerEvent;
99   EFI_EVENT                           TwoSecondTimeOut;
100   UINT32                              InputState;
101   UINT32                              ResetState;
102   UINT16                              TtyEscapeStr[3];
103   INTN                                TtyEscapeIndex;
104 
105   //
106   // Esc could not be output to the screen by user,
107   // but the terminal driver need to output it to
108   // the terminal emulation software to send control sequence.
109   // This boolean is used by the terminal driver only
110   // to indicate whether the Esc could be sent or not.
111   //
112   BOOLEAN                             OutputEscChar;
113   EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL   SimpleInputEx;
114   LIST_ENTRY                          NotifyList;
115 } TERMINAL_DEV;
116 
117 #define INPUT_STATE_DEFAULT               0x00
118 #define INPUT_STATE_ESC                   0x01
119 #define INPUT_STATE_CSI                   0x02
120 #define INPUT_STATE_LEFTOPENBRACKET       0x04
121 #define INPUT_STATE_O                     0x08
122 #define INPUT_STATE_2                     0x10
123 #define INPUT_STATE_LEFTOPENBRACKET_2     0x20
124 
125 #define RESET_STATE_DEFAULT               0x00
126 #define RESET_STATE_ESC_R                 0x01
127 #define RESET_STATE_ESC_R_ESC_R           0x02
128 
129 #define TERMINAL_CON_IN_DEV_FROM_THIS(a)  CR (a, TERMINAL_DEV, SimpleInput, TERMINAL_DEV_SIGNATURE)
130 #define TERMINAL_CON_OUT_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleTextOutput, TERMINAL_DEV_SIGNATURE)
131 #define TERMINAL_CON_IN_EX_DEV_FROM_THIS(a)  CR (a, TERMINAL_DEV, SimpleInputEx, TERMINAL_DEV_SIGNATURE)
132 
133 typedef union {
134   UINT8 Utf8_1;
135   UINT8 Utf8_2[2];
136   UINT8 Utf8_3[3];
137 } UTF8_CHAR;
138 
139 #define PCANSITYPE                0
140 #define VT100TYPE                 1
141 #define VT100PLUSTYPE             2
142 #define VTUTF8TYPE                3
143 #define TTYTERMTYPE               4
144 
145 #define LEFTOPENBRACKET           0x5b  // '['
146 #define ACAP                      0x41
147 #define BCAP                      0x42
148 #define CCAP                      0x43
149 #define DCAP                      0x44
150 
151 #define BACKSPACE                 8
152 #define ESC                       27
153 #define CSI                       0x9B
154 #define DEL                       127
155 #define BRIGHT_CONTROL_OFFSET     2
156 #define FOREGROUND_CONTROL_OFFSET 6
157 #define BACKGROUND_CONTROL_OFFSET 11
158 #define ROW_OFFSET                2
159 #define COLUMN_OFFSET             5
160 
161 typedef struct {
162   UINT16  Unicode;
163   CHAR8   PcAnsi;
164   CHAR8   Ascii;
165 } UNICODE_TO_CHAR;
166 
167 //
168 // Global Variables
169 //
170 extern EFI_DRIVER_BINDING_PROTOCOL   gTerminalDriverBinding;
171 extern EFI_COMPONENT_NAME_PROTOCOL   gTerminalComponentName;
172 extern EFI_COMPONENT_NAME2_PROTOCOL  gTerminalComponentName2;
173 
174 /**
175   The user Entry Point for module Terminal. The user code starts with this function.
176 
177   @param[in] ImageHandle    The firmware allocated handle for the EFI image.
178   @param[in] SystemTable    A pointer to the EFI System Table.
179 
180   @retval EFI_SUCCESS       The entry point is executed successfully.
181   @retval other             Some error occurs when executing this entry point.
182 
183 **/
184 EFI_STATUS
185 EFIAPI
186 InitializeTerminal (
187   IN EFI_HANDLE         ImageHandle,
188   IN EFI_SYSTEM_TABLE   *SystemTable
189   );
190 
191 /**
192   Implements EFI_SIMPLE_TEXT_INPUT_PROTOCOL.Reset().
193   This driver only perform dependent serial device reset regardless of
194   the value of ExtendeVerification
195 
196   @param  This                     Indicates the calling context.
197   @param  ExtendedVerification     Skip by this driver.
198 
199   @retval EFI_SUCCESS              The reset operation succeeds.
200   @retval EFI_DEVICE_ERROR         The dependent serial port reset fails.
201 
202 **/
203 EFI_STATUS
204 EFIAPI
205 TerminalConInReset (
206   IN  EFI_SIMPLE_TEXT_INPUT_PROTOCOL    *This,
207   IN  BOOLEAN                           ExtendedVerification
208   );
209 
210 
211 /**
212   Implements EFI_SIMPLE_TEXT_INPUT_PROTOCOL.ReadKeyStroke().
213 
214   @param  This                Indicates the calling context.
215   @param  Key                 A pointer to a buffer that is filled in with the
216                               keystroke information for the key that was sent
217                               from terminal.
218 
219   @retval EFI_SUCCESS         The keystroke information is returned successfully.
220   @retval EFI_NOT_READY       There is no keystroke data available.
221   @retval EFI_DEVICE_ERROR    The dependent serial device encounters error.
222 
223 **/
224 EFI_STATUS
225 EFIAPI
226 TerminalConInReadKeyStroke (
227   IN  EFI_SIMPLE_TEXT_INPUT_PROTOCOL  *This,
228   OUT EFI_INPUT_KEY                   *Key
229   );
230 
231 /**
232   Check if the key already has been registered.
233 
234   @param  RegsiteredData           A pointer to a buffer that is filled in with the
235                                    keystroke state data for the key that was
236                                    registered.
237   @param  InputData                A pointer to a buffer that is filled in with the
238                                    keystroke state data for the key that was
239                                    pressed.
240 
241   @retval TRUE                     Key be pressed matches a registered key.
242   @retval FALSE                    Match failed.
243 
244 **/
245 BOOLEAN
246 IsKeyRegistered (
247   IN EFI_KEY_DATA  *RegsiteredData,
248   IN EFI_KEY_DATA  *InputData
249   );
250 
251 /**
252   Event notification function for EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx event
253   Signal the event if there is key available
254 
255   @param  Event                    Indicates the event that invoke this function.
256   @param  Context                  Indicates the calling context.
257 
258 **/
259 VOID
260 EFIAPI
261 TerminalConInWaitForKeyEx (
262   IN  EFI_EVENT       Event,
263   IN  VOID            *Context
264   );
265 
266 //
267 // Simple Text Input Ex protocol prototypes
268 //
269 
270 /**
271   Reset the input device and optionally run diagnostics
272 
273   @param  This                     Protocol instance pointer.
274   @param  ExtendedVerification     Driver may perform diagnostics on reset.
275 
276   @retval EFI_SUCCESS              The device was reset.
277   @retval EFI_DEVICE_ERROR         The device is not functioning properly and could
278                                    not be reset.
279 
280 **/
281 EFI_STATUS
282 EFIAPI
283 TerminalConInResetEx (
284   IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL  *This,
285   IN BOOLEAN                            ExtendedVerification
286   );
287 
288 /**
289   Reads the next keystroke from the input device. The WaitForKey Event can
290   be used to test for existence of a keystroke via WaitForEvent () call.
291 
292   @param  This                     Protocol instance pointer.
293   @param  KeyData                  A pointer to a buffer that is filled in with the
294                                    keystroke state data for the key that was
295                                    pressed.
296 
297   @retval EFI_SUCCESS              The keystroke information was returned.
298   @retval EFI_NOT_READY            There was no keystroke data available.
299   @retval EFI_DEVICE_ERROR         The keystroke information was not returned due
300                                    to hardware errors.
301   @retval EFI_INVALID_PARAMETER    KeyData is NULL.
302 
303 **/
304 EFI_STATUS
305 EFIAPI
306 TerminalConInReadKeyStrokeEx (
307   IN  EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
308   OUT EFI_KEY_DATA                      *KeyData
309   );
310 
311 /**
312   Set certain state for the input device.
313 
314   @param  This                     Protocol instance pointer.
315   @param  KeyToggleState           A pointer to the EFI_KEY_TOGGLE_STATE to set the
316                                    state for the input device.
317 
318   @retval EFI_SUCCESS              The device state was set successfully.
319   @retval EFI_DEVICE_ERROR         The device is not functioning correctly and
320                                    could not have the setting adjusted.
321   @retval EFI_UNSUPPORTED          The device does not have the ability to set its
322                                    state.
323   @retval EFI_INVALID_PARAMETER    KeyToggleState is NULL.
324 
325 **/
326 EFI_STATUS
327 EFIAPI
328 TerminalConInSetState (
329   IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL  *This,
330   IN EFI_KEY_TOGGLE_STATE               *KeyToggleState
331   );
332 
333 /**
334   Register a notification function for a particular keystroke for the input device.
335 
336   @param  This                     Protocol instance pointer.
337   @param  KeyData                  A pointer to a buffer that is filled in with the
338                                    keystroke information data for the key that was
339                                    pressed.
340   @param  KeyNotificationFunction  Points to the function to be called when the key
341                                    sequence is typed specified by KeyData.
342   @param  NotifyHandle             Points to the unique handle assigned to the
343                                    registered notification.
344 
345   @retval EFI_SUCCESS              The notification function was registered
346                                    successfully.
347   @retval EFI_OUT_OF_RESOURCES     Unable to allocate resources for necesssary data
348                                    structures.
349   @retval EFI_INVALID_PARAMETER    KeyData or NotifyHandle is NULL.
350 
351 **/
352 EFI_STATUS
353 EFIAPI
354 TerminalConInRegisterKeyNotify (
355   IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL  *This,
356   IN EFI_KEY_DATA                       *KeyData,
357   IN EFI_KEY_NOTIFY_FUNCTION            KeyNotificationFunction,
358   OUT VOID                              **NotifyHandle
359   );
360 
361 /**
362   Remove a registered notification function from a particular keystroke.
363 
364   @param  This                     Protocol instance pointer.
365   @param  NotificationHandle       The handle of the notification function being
366                                    unregistered.
367 
368   @retval EFI_SUCCESS              The notification function was unregistered
369                                    successfully.
370   @retval EFI_INVALID_PARAMETER    The NotificationHandle is invalid.
371   @retval EFI_NOT_FOUND            Can not find the matching entry in database.
372 
373 **/
374 EFI_STATUS
375 EFIAPI
376 TerminalConInUnregisterKeyNotify (
377   IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL  *This,
378   IN VOID                               *NotificationHandle
379   );
380 
381 /**
382   Event notification function for EFI_SIMPLE_TEXT_INPUT_PROTOCOL.WaitForKey event
383   Signal the event if there is key available
384 
385   @param  Event                    Indicates the event that invoke this function.
386   @param  Context                  Indicates the calling context.
387 
388 **/
389 VOID
390 EFIAPI
391 TerminalConInWaitForKey (
392   IN  EFI_EVENT     Event,
393   IN  VOID          *Context
394   );
395 
396 /**
397   Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.Reset().
398   If ExtendeVerification is TRUE, then perform dependent serial device reset,
399   and set display mode to mode 0.
400   If ExtendedVerification is FALSE, only set display mode to mode 0.
401 
402   @param  This                  Indicates the calling context.
403   @param  ExtendedVerification  Indicates that the driver may perform a more
404                                 exhaustive verification operation of the device
405                                 during reset.
406 
407   @retval EFI_SUCCESS           The reset operation succeeds.
408   @retval EFI_DEVICE_ERROR      The terminal is not functioning correctly or the serial port reset fails.
409 
410 **/
411 EFI_STATUS
412 EFIAPI
413 TerminalConOutReset (
414   IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL    *This,
415   IN  BOOLEAN                            ExtendedVerification
416   );
417 
418 /**
419   Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.OutputString().
420   The Unicode string will be converted to terminal expressible data stream
421   and send to terminal via serial port.
422 
423   @param  This                    Indicates the calling context.
424   @param  WString                 The Null-terminated Unicode string to be displayed
425                                   on the terminal screen.
426 
427   @retval EFI_SUCCESS             The string is output successfully.
428   @retval EFI_DEVICE_ERROR        The serial port fails to send the string out.
429   @retval EFI_WARN_UNKNOWN_GLYPH  Indicates that some of the characters in the Unicode string could not
430                                   be rendered and are skipped.
431   @retval EFI_UNSUPPORTED         If current display mode is out of range.
432 
433 **/
434 EFI_STATUS
435 EFIAPI
436 TerminalConOutOutputString (
437   IN   EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *This,
438   IN  CHAR16                            *WString
439   );
440 
441 /**
442   Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.TestString().
443   If one of the characters in the *Wstring is
444   neither valid Unicode drawing characters,
445   not ASCII code, then this function will return
446   EFI_UNSUPPORTED.
447 
448   @param  This              Indicates the calling context.
449   @param  WString           The Null-terminated Unicode string to be tested.
450 
451   @retval EFI_SUCCESS       The terminal is capable of rendering the output string.
452   @retval EFI_UNSUPPORTED   Some of the characters in the Unicode string cannot be rendered.
453 
454 **/
455 EFI_STATUS
456 EFIAPI
457 TerminalConOutTestString (
458   IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *This,
459   IN  CHAR16                           *WString
460   );
461 
462 /**
463   Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.QueryMode().
464   It returns information for an available text mode
465   that the terminal supports.
466   In this driver, we support text mode 80x25 (mode 0),
467   80x50 (mode 1), 100x31 (mode 2).
468 
469   @param This        Indicates the calling context.
470   @param ModeNumber  The mode number to return information on.
471   @param Columns     The returned columns of the requested mode.
472   @param Rows        The returned rows of the requested mode.
473 
474   @retval EFI_SUCCESS       The requested mode information is returned.
475   @retval EFI_UNSUPPORTED   The mode number is not valid.
476   @retval EFI_DEVICE_ERROR
477 
478 **/
479 EFI_STATUS
480 EFIAPI
481 TerminalConOutQueryMode (
482   IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *This,
483   IN  UINTN                            ModeNumber,
484   OUT UINTN                            *Columns,
485   OUT UINTN                            *Rows
486   );
487 
488 /**
489   Implements EFI_SIMPLE_TEXT_OUT.SetMode().
490   Set the terminal to a specified display mode.
491   In this driver, we only support mode 0.
492 
493   @param This          Indicates the calling context.
494   @param ModeNumber    The text mode to set.
495 
496   @retval EFI_SUCCESS       The requested text mode is set.
497   @retval EFI_DEVICE_ERROR  The requested text mode cannot be set
498                             because of serial device error.
499   @retval EFI_UNSUPPORTED   The text mode number is not valid.
500 
501 **/
502 EFI_STATUS
503 EFIAPI
504 TerminalConOutSetMode (
505   IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *This,
506   IN  UINTN                            ModeNumber
507   );
508 
509 /**
510   Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetAttribute().
511 
512   @param This        Indicates the calling context.
513   @param Attribute   The attribute to set. Only bit0..6 are valid, all other bits
514                      are undefined and must be zero.
515 
516   @retval EFI_SUCCESS        The requested attribute is set.
517   @retval EFI_DEVICE_ERROR   The requested attribute cannot be set due to serial port error.
518   @retval EFI_UNSUPPORTED    The attribute requested is not defined by EFI spec.
519 
520 **/
521 EFI_STATUS
522 EFIAPI
523 TerminalConOutSetAttribute (
524   IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *This,
525   IN  UINTN                            Attribute
526   );
527 
528 /**
529   Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.ClearScreen().
530   It clears the ANSI terminal's display to the
531   currently selected background color.
532 
533   @param This     Indicates the calling context.
534 
535   @retval EFI_SUCCESS       The operation completed successfully.
536   @retval EFI_DEVICE_ERROR  The terminal screen cannot be cleared due to serial port error.
537   @retval EFI_UNSUPPORTED   The terminal is not in a valid display mode.
538 
539 **/
540 EFI_STATUS
541 EFIAPI
542 TerminalConOutClearScreen (
543   IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *This
544   );
545 
546 /**
547   Implements EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.SetCursorPosition().
548 
549   @param This      Indicates the calling context.
550   @param Column    The row to set cursor to.
551   @param Row       The column to set cursor to.
552 
553   @retval EFI_SUCCESS       The operation completed successfully.
554   @retval EFI_DEVICE_ERROR  The request fails due to serial port error.
555   @retval EFI_UNSUPPORTED   The terminal is not in a valid text mode, or the cursor position
556                             is invalid for current mode.
557 
558 **/
559 EFI_STATUS
560 EFIAPI
561 TerminalConOutSetCursorPosition (
562   IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *This,
563   IN  UINTN                            Column,
564   IN  UINTN                            Row
565   );
566 
567 /**
568   Implements SIMPLE_TEXT_OUTPUT.EnableCursor().
569   In this driver, the cursor cannot be hidden.
570 
571   @param This      Indicates the calling context.
572   @param Visible   If TRUE, the cursor is set to be visible,
573                    If FALSE, the cursor is set to be invisible.
574 
575   @retval EFI_SUCCESS      The request is valid.
576   @retval EFI_UNSUPPORTED  The terminal does not support cursor hidden.
577 
578 **/
579 EFI_STATUS
580 EFIAPI
581 TerminalConOutEnableCursor (
582   IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *This,
583   IN  BOOLEAN                          Visible
584   );
585 
586 /**
587   Test to see if this driver supports Controller.
588 
589   @param  This                Protocol instance pointer.
590   @param  ControllerHandle    Handle of device to test
591   @param  RemainingDevicePath Optional parameter use to pick a specific child
592                               device to start.
593 
594   @retval EFI_SUCCESS         This driver supports this device.
595   @retval EFI_ALREADY_STARTED This driver is already running on this device.
596   @retval other               This driver does not support this device.
597 
598 **/
599 EFI_STATUS
600 EFIAPI
601 TerminalDriverBindingSupported (
602   IN EFI_DRIVER_BINDING_PROTOCOL    *This,
603   IN EFI_HANDLE                     ControllerHandle,
604   IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath
605   );
606 
607 /**
608   Start this driver on Controller by opening a Serial IO protocol,
609   reading Device Path, and creating a child handle with a Simple Text In,
610   Simple Text In Ex and Simple Text Out protocol, and device path protocol.
611   And store Console Device Environment Variables.
612 
613   @param  This                 Protocol instance pointer.
614   @param  Controller           Handle of device to bind driver to
615   @param  RemainingDevicePath  Optional parameter use to pick a specific child
616                                device to start.
617 
618   @retval EFI_SUCCESS          This driver is added to Controller.
619   @retval EFI_ALREADY_STARTED  This driver is already running on Controller.
620   @retval other                This driver does not support this device.
621 
622 **/
623 EFI_STATUS
624 EFIAPI
625 TerminalDriverBindingStart (
626   IN EFI_DRIVER_BINDING_PROTOCOL    *This,
627   IN EFI_HANDLE                     Controller,
628   IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath
629   );
630 
631 
632 /**
633   Stop this driver on Controller by closing Simple Text In, Simple Text
634   In Ex, Simple Text Out protocol, and removing parent device path from
635   Console Device Environment Variables.
636 
637   @param  This              Protocol instance pointer.
638   @param  Controller        Handle of device to stop driver on
639   @param  NumberOfChildren  Number of Handles in ChildHandleBuffer. If number of
640                             children is zero stop the entire bus driver.
641   @param  ChildHandleBuffer List of Child Handles to Stop.
642 
643   @retval EFI_SUCCESS       This driver is removed Controller.
644   @retval other             This driver could not be removed from this device.
645 
646 **/
647 EFI_STATUS
648 EFIAPI
649 TerminalDriverBindingStop (
650   IN  EFI_DRIVER_BINDING_PROTOCOL    *This,
651   IN  EFI_HANDLE                     Controller,
652   IN  UINTN                          NumberOfChildren,
653   IN  EFI_HANDLE                     *ChildHandleBuffer
654   );
655 
656 /**
657   Free notify functions list.
658 
659   @param  ListHead               The list head
660 
661   @retval EFI_SUCCESS            Free the notify list successfully.
662   @retval EFI_INVALID_PARAMETER  ListHead is NULL.
663 
664 **/
665 EFI_STATUS
666 TerminalFreeNotifyList (
667   IN OUT LIST_ENTRY           *ListHead
668   );
669 
670 /**
671   Retrieves a Unicode string that is the user readable name of the driver.
672 
673   This function retrieves the user readable name of a driver in the form of a
674   Unicode string. If the driver specified by This has a user readable name in
675   the language specified by Language, then a pointer to the driver name is
676   returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
677   by This does not support the language specified by Language,
678   then EFI_UNSUPPORTED is returned.
679 
680   @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
681                                 EFI_COMPONENT_NAME_PROTOCOL instance.
682 
683   @param  Language[in]          A pointer to a Null-terminated ASCII string
684                                 array indicating the language. This is the
685                                 language of the driver name that the caller is
686                                 requesting, and it must match one of the
687                                 languages specified in SupportedLanguages. The
688                                 number of languages supported by a driver is up
689                                 to the driver writer. Language is specified
690                                 in RFC 4646 or ISO 639-2 language code format.
691 
692   @param  DriverName[out]       A pointer to the Unicode string to return.
693                                 This Unicode string is the name of the
694                                 driver specified by This in the language
695                                 specified by Language.
696 
697   @retval EFI_SUCCESS           The Unicode string for the Driver specified by
698                                 This and the language specified by Language was
699                                 returned in DriverName.
700 
701   @retval EFI_INVALID_PARAMETER Language is NULL.
702 
703   @retval EFI_INVALID_PARAMETER DriverName is NULL.
704 
705   @retval EFI_UNSUPPORTED       The driver specified by This does not support
706                                 the language specified by Language.
707 
708 **/
709 EFI_STATUS
710 EFIAPI
711 TerminalComponentNameGetDriverName (
712   IN  EFI_COMPONENT_NAME_PROTOCOL  *This,
713   IN  CHAR8                        *Language,
714   OUT CHAR16                       **DriverName
715   );
716 
717 
718 /**
719   Retrieves a Unicode string that is the user readable name of the controller
720   that is being managed by a driver.
721 
722   This function retrieves the user readable name of the controller specified by
723   ControllerHandle and ChildHandle in the form of a Unicode string. If the
724   driver specified by This has a user readable name in the language specified by
725   Language, then a pointer to the controller name is returned in ControllerName,
726   and EFI_SUCCESS is returned.  If the driver specified by This is not currently
727   managing the controller specified by ControllerHandle and ChildHandle,
728   then EFI_UNSUPPORTED is returned.  If the driver specified by This does not
729   support the language specified by Language, then EFI_UNSUPPORTED is returned.
730 
731   @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
732                                 EFI_COMPONENT_NAME_PROTOCOL instance.
733 
734   @param  ControllerHandle[in]  The handle of a controller that the driver
735                                 specified by This is managing.  This handle
736                                 specifies the controller whose name is to be
737                                 returned.
738 
739   @param  ChildHandle[in]       The handle of the child controller to retrieve
740                                 the name of.  This is an optional parameter that
741                                 may be NULL.  It will be NULL for device
742                                 drivers.  It will also be NULL for a bus drivers
743                                 that wish to retrieve the name of the bus
744                                 controller.  It will not be NULL for a bus
745                                 driver that wishes to retrieve the name of a
746                                 child controller.
747 
748   @param  Language[in]          A pointer to a Null-terminated ASCII string
749                                 array indicating the language.  This is the
750                                 language of the driver name that the caller is
751                                 requesting, and it must match one of the
752                                 languages specified in SupportedLanguages. The
753                                 number of languages supported by a driver is up
754                                 to the driver writer. Language is specified in
755                                 RFC 4646 or ISO 639-2 language code format.
756 
757   @param  ControllerName[out]   A pointer to the Unicode string to return.
758                                 This Unicode string is the name of the
759                                 controller specified by ControllerHandle and
760                                 ChildHandle in the language specified by
761                                 Language from the point of view of the driver
762                                 specified by This.
763 
764   @retval EFI_SUCCESS           The Unicode string for the user readable name in
765                                 the language specified by Language for the
766                                 driver specified by This was returned in
767                                 DriverName.
768 
769   @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
770 
771   @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
772                                 EFI_HANDLE.
773 
774   @retval EFI_INVALID_PARAMETER Language is NULL.
775 
776   @retval EFI_INVALID_PARAMETER ControllerName is NULL.
777 
778   @retval EFI_UNSUPPORTED       The driver specified by This is not currently
779                                 managing the controller specified by
780                                 ControllerHandle and ChildHandle.
781 
782   @retval EFI_UNSUPPORTED       The driver specified by This does not support
783                                 the language specified by Language.
784 
785 **/
786 EFI_STATUS
787 EFIAPI
788 TerminalComponentNameGetControllerName (
789   IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,
790   IN  EFI_HANDLE                                      ControllerHandle,
791   IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,
792   IN  CHAR8                                           *Language,
793   OUT CHAR16                                          **ControllerName
794   );
795 
796 
797 //
798 // internal functions
799 //
800 
801 /**
802   Check for a pending key in the Efi Key FIFO or Serial device buffer.
803 
804   @param  This                     Indicates the calling context.
805 
806   @retval EFI_SUCCESS              There is key pending.
807   @retval EFI_NOT_READY            There is no key pending.
808   @retval EFI_DEVICE_ERROR         If Serial IO is not attached to serial device.
809 
810 **/
811 EFI_STATUS
812 TerminalConInCheckForKey (
813   IN  EFI_SIMPLE_TEXT_INPUT_PROTOCOL  *This
814   );
815 
816 /**
817   Update terminal device path in Console Device Environment Variables.
818 
819   @param  VariableName           The Console Device Environment Variable.
820   @param  ParentDevicePath       The terminal device path to be updated.
821 
822   @return None.
823 
824 **/
825 VOID
826 TerminalUpdateConsoleDevVariable (
827   IN CHAR16                    *VariableName,
828   IN EFI_DEVICE_PATH_PROTOCOL  *ParentDevicePath
829   );
830 
831 /**
832   Remove console device variable.
833 
834   @param  VariableName           A pointer to the variable name.
835   @param  ParentDevicePath       A pointer to the parent device path.
836 
837 **/
838 VOID
839 TerminalRemoveConsoleDevVariable (
840   IN CHAR16                    *VariableName,
841   IN EFI_DEVICE_PATH_PROTOCOL  *ParentDevicePath
842   );
843 
844 /**
845   Build termial device path according to terminal type.
846 
847   @param  TerminalType           The terminal type is PC ANSI, VT100, VT100+ or VT-UTF8.
848   @param  ParentDevicePath       Parent device path.
849   @param  TerminalDevicePath     Returned terminal device path, if building successfully.
850 
851   @retval EFI_UNSUPPORTED        Terminal does not belong to the supported type.
852   @retval EFI_OUT_OF_RESOURCES   Generate terminal device path failed.
853   @retval EFI_SUCCESS            Build terminal device path successfully.
854 
855 **/
856 EFI_STATUS
857 SetTerminalDevicePath (
858   IN  UINT8                       TerminalType,
859   IN  EFI_DEVICE_PATH_PROTOCOL    *ParentDevicePath,
860   OUT EFI_DEVICE_PATH_PROTOCOL    **TerminalDevicePath
861   );
862 
863 /**
864   Get one key out of serial buffer.
865 
866   @param  SerialIo           Serial I/O protocl attached to the serial device.
867   @param  Input              The fetched key.
868 
869   @retval EFI_NOT_READY      If serial buffer is empty.
870   @retval EFI_DEVICE_ERROR   If reading serial buffer encounter error.
871   @retval EFI_SUCCESS        If reading serial buffer successfully, put
872                              the fetched key to the parameter output.
873 
874 **/
875 EFI_STATUS
876 GetOneKeyFromSerial (
877   EFI_SERIAL_IO_PROTOCOL  *SerialIo,
878   UINT8                   *Input
879   );
880 
881 /**
882   Insert one byte raw data into the Raw Data FIFO.
883 
884   @param  TerminalDevice       Terminal driver private structure.
885   @param  Input                The key will be input.
886 
887   @retval TRUE                 If insert successfully.
888   @retval FALSE                If Raw Data buffer is full before key insertion,
889                                and the key is lost.
890 
891 **/
892 BOOLEAN
893 RawFiFoInsertOneKey (
894   TERMINAL_DEV  *TerminalDevice,
895   UINT8         Input
896   );
897 
898 /**
899   Remove one pre-fetched key out of the Raw Data FIFO.
900 
901   @param  TerminalDevice       Terminal driver private structure.
902   @param  Output               The key will be removed.
903 
904   @retval TRUE                 If insert successfully.
905   @retval FALSE                If Raw Data FIFO buffer is empty before remove operation.
906 
907 **/
908 BOOLEAN
909 RawFiFoRemoveOneKey (
910   TERMINAL_DEV  *TerminalDevice,
911   UINT8         *Output
912   );
913 
914 /**
915   Clarify whether Raw Data FIFO buffer is empty.
916 
917   @param  TerminalDevice       Terminal driver private structure
918 
919   @retval TRUE                 If Raw Data FIFO buffer is empty.
920   @retval FALSE                If Raw Data FIFO buffer is not empty.
921 
922 **/
923 BOOLEAN
924 IsRawFiFoEmpty (
925   TERMINAL_DEV  *TerminalDevice
926   );
927 
928 /**
929   Clarify whether Raw Data FIFO buffer is full.
930 
931   @param  TerminalDevice       Terminal driver private structure
932 
933   @retval TRUE                 If Raw Data FIFO buffer is full.
934   @retval FALSE                If Raw Data FIFO buffer is not full.
935 
936 **/
937 BOOLEAN
938 IsRawFiFoFull (
939   TERMINAL_DEV  *TerminalDevice
940   );
941 
942 /**
943   Insert one pre-fetched key into the FIFO buffer.
944 
945   @param  TerminalDevice       Terminal driver private structure.
946   @param  Key                  The key will be input.
947 
948   @retval TRUE                 If insert successfully.
949   @retval FALSE                If FIFO buffer is full before key insertion,
950                                and the key is lost.
951 
952 **/
953 BOOLEAN
954 EfiKeyFiFoInsertOneKey (
955   TERMINAL_DEV      *TerminalDevice,
956   EFI_INPUT_KEY     *Key
957   );
958 
959 /**
960   Remove one pre-fetched key out of the FIFO buffer.
961 
962   @param  TerminalDevice       Terminal driver private structure.
963   @param  Output               The key will be removed.
964 
965   @retval TRUE                 If insert successfully.
966   @retval FALSE                If FIFO buffer is empty before remove operation.
967 
968 **/
969 BOOLEAN
970 EfiKeyFiFoRemoveOneKey (
971   TERMINAL_DEV  *TerminalDevice,
972   EFI_INPUT_KEY *Output
973   );
974 
975 /**
976   Clarify whether FIFO buffer is empty.
977 
978   @param  TerminalDevice       Terminal driver private structure
979 
980   @retval TRUE                 If FIFO buffer is empty.
981   @retval FALSE                If FIFO buffer is not empty.
982 
983 **/
984 BOOLEAN
985 IsEfiKeyFiFoEmpty (
986   TERMINAL_DEV  *TerminalDevice
987   );
988 
989 /**
990   Clarify whether FIFO buffer is full.
991 
992   @param  TerminalDevice       Terminal driver private structure
993 
994   @retval TRUE                 If FIFO buffer is full.
995   @retval FALSE                If FIFO buffer is not full.
996 
997 **/
998 BOOLEAN
999 IsEfiKeyFiFoFull (
1000   TERMINAL_DEV  *TerminalDevice
1001   );
1002 
1003 /**
1004   Insert one pre-fetched key into the Unicode FIFO buffer.
1005 
1006   @param  TerminalDevice       Terminal driver private structure.
1007   @param  Input                The key will be input.
1008 
1009   @retval TRUE                 If insert successfully.
1010   @retval FALSE                If Unicode FIFO buffer is full before key insertion,
1011                                and the key is lost.
1012 
1013 **/
1014 BOOLEAN
1015 UnicodeFiFoInsertOneKey (
1016   TERMINAL_DEV      *TerminalDevice,
1017   UINT16            Input
1018   );
1019 
1020 /**
1021   Remove one pre-fetched key out of the Unicode FIFO buffer.
1022   The caller should guarantee that Unicode FIFO buffer is not empty
1023   by IsUnicodeFiFoEmpty ().
1024 
1025   @param  TerminalDevice       Terminal driver private structure.
1026   @param  Output               The key will be removed.
1027 
1028 **/
1029 VOID
1030 UnicodeFiFoRemoveOneKey (
1031   TERMINAL_DEV  *TerminalDevice,
1032   UINT16        *Output
1033   );
1034 
1035 /**
1036   Clarify whether Unicode FIFO buffer is empty.
1037 
1038   @param  TerminalDevice       Terminal driver private structure
1039 
1040   @retval TRUE                 If Unicode FIFO buffer is empty.
1041   @retval FALSE                If Unicode FIFO buffer is not empty.
1042 
1043 **/
1044 BOOLEAN
1045 IsUnicodeFiFoEmpty (
1046   TERMINAL_DEV  *TerminalDevice
1047   );
1048 
1049 /**
1050   Clarify whether Unicode FIFO buffer is full.
1051 
1052   @param  TerminalDevice       Terminal driver private structure
1053 
1054   @retval TRUE                 If Unicode FIFO buffer is full.
1055   @retval FALSE                If Unicode FIFO buffer is not full.
1056 
1057 **/
1058 BOOLEAN
1059 IsUnicodeFiFoFull (
1060   TERMINAL_DEV  *TerminalDevice
1061   );
1062 
1063 /**
1064   Count Unicode FIFO buffer.
1065 
1066   @param  TerminalDevice       Terminal driver private structure
1067 
1068   @return The count in bytes of Unicode FIFO.
1069 
1070 **/
1071 UINT8
1072 UnicodeFiFoGetKeyCount (
1073   TERMINAL_DEV    *TerminalDevice
1074   );
1075 
1076 /**
1077   Translate raw data into Unicode (according to different encode), and
1078   translate Unicode into key information. (according to different standard).
1079 
1080   @param  TerminalDevice       Terminal driver private structure.
1081 
1082 **/
1083 VOID
1084 TranslateRawDataToEfiKey (
1085   IN  TERMINAL_DEV      *TerminalDevice
1086   );
1087 
1088 //
1089 // internal functions for PC ANSI
1090 //
1091 
1092 /**
1093   Translate all raw data in the Raw FIFI into unicode, and insert
1094   them into Unicode FIFO.
1095 
1096   @param TerminalDevice          The terminal device.
1097 
1098 **/
1099 VOID
1100 AnsiRawDataToUnicode (
1101   IN  TERMINAL_DEV    *TerminalDevice
1102   );
1103 
1104 /**
1105   Converts a stream of Unicode characters from a terminal input device into EFI Keys that
1106   can be read through the Simple Input Protocol.
1107 
1108   The table below shows the keyboard input mappings that this function supports.
1109   If the ESC sequence listed in one of the columns is presented, then it is translated
1110   into the coorespoding EFI Scan Code.  If a matching sequence is not found, then the raw
1111   key strokes are converted into EFI Keys.
1112 
1113   2 seconds are allowed for an ESC sequence to be completed.  If the ESC sequence is not
1114   completed in 2 seconds, then the raw key strokes of the partial ESC sequence are
1115   converted into EFI Keys.
1116   There is one special input sequence that will force the system to reset.
1117   This is ESC R ESC r ESC R.
1118 
1119   Symbols used in table below
1120   ===========================
1121     ESC = 0x1B
1122     CSI = 0x9B
1123     DEL = 0x7f
1124     ^   = CTRL
1125   +=========+======+===========+==========+==========+
1126   |         | EFI  | UEFI 2.0  |          |          |
1127   |         | Scan |           |  VT100+  |          |
1128   |   KEY   | Code |  PC ANSI  |  VTUTF8  |   VT100  |
1129   +=========+======+===========+==========+==========+
1130   | NULL    | 0x00 |           |          |          |
1131   | UP      | 0x01 | ESC [ A   | ESC [ A  | ESC [ A  |
1132   | DOWN    | 0x02 | ESC [ B   | ESC [ B  | ESC [ B  |
1133   | RIGHT   | 0x03 | ESC [ C   | ESC [ C  | ESC [ C  |
1134   | LEFT    | 0x04 | ESC [ D   | ESC [ D  | ESC [ D  |
1135   | HOME    | 0x05 | ESC [ H   | ESC h    | ESC [ H  |
1136   | END     | 0x06 | ESC [ F   | ESC k    | ESC [ K  |
1137   | INSERT  | 0x07 | ESC [ @   | ESC +    | ESC [ @  |
1138   |         |      | ESC [ L   |          | ESC [ L  |
1139   | DELETE  | 0x08 | ESC [ X   | ESC -    | ESC [ P  |
1140   | PG UP   | 0x09 | ESC [ I   | ESC ?    | ESC [ V  |
1141   |         |      |           |          | ESC [ ?  |
1142   | PG DOWN | 0x0A | ESC [ G   | ESC /    | ESC [ U  |
1143   |         |      |           |          | ESC [ /  |
1144   | F1      | 0x0B | ESC [ M   | ESC 1    | ESC O P  |
1145   | F2      | 0x0C | ESC [ N   | ESC 2    | ESC O Q  |
1146   | F3      | 0x0D | ESC [ O   | ESC 3    | ESC O w  |
1147   | F4      | 0x0E | ESC [ P   | ESC 4    | ESC O x  |
1148   | F5      | 0x0F | ESC [ Q   | ESC 5    | ESC O t  |
1149   | F6      | 0x10 | ESC [ R   | ESC 6    | ESC O u  |
1150   | F7      | 0x11 | ESC [ S   | ESC 7    | ESC O q  |
1151   | F8      | 0x12 | ESC [ T   | ESC 8    | ESC O r  |
1152   | F9      | 0x13 | ESC [ U   | ESC 9    | ESC O p  |
1153   | F10     | 0x14 | ESC [ V   | ESC 0    | ESC O M  |
1154   | Escape  | 0x17 | ESC       | ESC      | ESC      |
1155   | F11     | 0x15 |           | ESC !    |          |
1156   | F12     | 0x16 |           | ESC @    |          |
1157   +=========+======+===========+==========+==========+
1158 
1159   Special Mappings
1160   ================
1161   ESC R ESC r ESC R = Reset System
1162 
1163 
1164   @param TerminalDevice   The terminal device to use to translate raw input into EFI Keys
1165 
1166 **/
1167 VOID
1168 UnicodeToEfiKey (
1169   IN  TERMINAL_DEV    *TerminalDevice
1170   );
1171 
1172 /**
1173   Check if input string is valid Ascii string, valid EFI control characters
1174   or valid text graphics.
1175 
1176   @param  TerminalDevice          The terminal device.
1177   @param  WString                 The input string.
1178 
1179   @retval EFI_UNSUPPORTED         If not all input characters are valid.
1180   @retval EFI_SUCCESS             If all input characters are valid.
1181 
1182 **/
1183 EFI_STATUS
1184 AnsiTestString (
1185   IN  TERMINAL_DEV    *TerminalDevice,
1186   IN  CHAR16          *WString
1187   );
1188 
1189 //
1190 // internal functions for VTUTF8
1191 //
1192 
1193 /**
1194   Translate all VT-UTF8 characters in the Raw FIFI into unicode characters,
1195   and insert them into Unicode FIFO.
1196 
1197   @param VtUtf8Device          The terminal device.
1198 
1199 **/
1200 VOID
1201 VTUTF8RawDataToUnicode (
1202   IN  TERMINAL_DEV    *VtUtf8Device
1203   );
1204 
1205 /**
1206   Check if input string is valid VT-UTF8 string.
1207 
1208   @param  TerminalDevice          The terminal device.
1209   @param  WString                 The input string.
1210 
1211   @retval EFI_SUCCESS             If all input characters are valid.
1212 
1213 **/
1214 EFI_STATUS
1215 VTUTF8TestString (
1216   IN  TERMINAL_DEV    *TerminalDevice,
1217   IN  CHAR16          *WString
1218   );
1219 
1220 /**
1221   Translate one Unicode character into VT-UTF8 characters.
1222 
1223   UTF8 Encoding Table
1224   Bits per Character | Unicode Character Range | Unicode Binary  Encoding |	UTF8 Binary Encoding
1225         0-7	         |     0x0000 - 0x007F	    |     00000000 0xxxxxxx	   |   0xxxxxxx
1226         8-11 	       |     0x0080 - 0x07FF	    |     00000xxx xxxxxxxx 	  |   110xxxxx 10xxxxxx
1227        12-16	        |     0x0800 - 0xFFFF	    |     xxxxxxxx xxxxxxxx	   |   1110xxxx 10xxxxxx 10xxxxxx
1228 
1229 
1230   @param  Unicode          Unicode character need translating.
1231   @param  Utf8Char         Return VT-UTF8 character set.
1232   @param  ValidBytes       The count of valid VT-UTF8 characters. If
1233                            ValidBytes is zero, no valid VT-UTF8 returned.
1234 
1235 **/
1236 VOID
1237 UnicodeToUtf8 (
1238   IN  CHAR16      Unicode,
1239   OUT UTF8_CHAR   *Utf8Char,
1240   OUT UINT8       *ValidBytes
1241   );
1242 
1243 /**
1244   Get one valid VT-UTF8 characters set from Raw Data FIFO.
1245 
1246   @param  Utf8Device          The terminal device.
1247   @param  Utf8Char            Returned valid VT-UTF8 characters set.
1248   @param  ValidBytes          The count of returned VT-VTF8 characters.
1249                               If ValidBytes is zero, no valid VT-UTF8 returned.
1250 
1251 **/
1252 VOID
1253 GetOneValidUtf8Char (
1254   IN  TERMINAL_DEV      *Utf8Device,
1255   OUT UTF8_CHAR         *Utf8Char,
1256   OUT UINT8             *ValidBytes
1257   );
1258 
1259 /**
1260   Translate VT-UTF8 characters into one Unicode character.
1261 
1262   UTF8 Encoding Table
1263   Bits per Character | Unicode Character Range | Unicode Binary  Encoding |	UTF8 Binary Encoding
1264         0-7	         |     0x0000 - 0x007F	    |     00000000 0xxxxxxx	   |   0xxxxxxx
1265         8-11 	       |     0x0080 - 0x07FF	    |     00000xxx xxxxxxxx 	  |   110xxxxx 10xxxxxx
1266        12-16	        |     0x0800 - 0xFFFF	    |     xxxxxxxx xxxxxxxx	   |   1110xxxx 10xxxxxx 10xxxxxx
1267 
1268 
1269   @param  Utf8Char         VT-UTF8 character set needs translating.
1270   @param  ValidBytes       The count of valid VT-UTF8 characters.
1271   @param  UnicodeChar      Returned unicode character.
1272 
1273 **/
1274 VOID
1275 Utf8ToUnicode (
1276   IN  UTF8_CHAR       Utf8Char,
1277   IN  UINT8           ValidBytes,
1278   OUT CHAR16          *UnicodeChar
1279   );
1280 
1281 //
1282 // functions for boxdraw unicode
1283 //
1284 
1285 /**
1286   Detects if a Unicode char is for Box Drawing text graphics.
1287 
1288   @param  Graphic      Unicode char to test.
1289   @param  PcAnsi       Optional pointer to return PCANSI equivalent of
1290                        Graphic.
1291   @param  Ascii        Optional pointer to return ASCII equivalent of
1292                        Graphic.
1293 
1294   @retval TRUE         If Graphic is a supported Unicode Box Drawing character.
1295 
1296 **/
1297 BOOLEAN
1298 TerminalIsValidTextGraphics (
1299   IN  CHAR16  Graphic,
1300   OUT CHAR8   *PcAnsi, OPTIONAL
1301   OUT CHAR8   *Ascii OPTIONAL
1302   );
1303 
1304 /**
1305   Detects if a valid ASCII char.
1306 
1307   @param  Ascii        An ASCII character.
1308 
1309   @retval TRUE         If it is a valid ASCII character.
1310   @retval FALSE        If it is not a valid ASCII character.
1311 
1312 **/
1313 BOOLEAN
1314 TerminalIsValidAscii (
1315   IN  CHAR16  Ascii
1316   );
1317 
1318 /**
1319   Detects if a valid EFI control character.
1320 
1321   @param  CharC        An input EFI Control character.
1322 
1323   @retval TRUE         If it is a valid EFI control character.
1324   @retval FALSE        If it is not a valid EFI control character.
1325 
1326 **/
1327 BOOLEAN
1328 TerminalIsValidEfiCntlChar (
1329   IN  CHAR16  CharC
1330   );
1331 
1332 /**
1333   Check if the device supports hot-plug through its device path.
1334 
1335   This function could be updated to check more types of Hot Plug devices.
1336   Currently, it checks USB and PCCard device.
1337 
1338   @param  DevicePath            Pointer to device's device path.
1339 
1340   @retval TRUE                  The devcie is a hot-plug device
1341   @retval FALSE                 The devcie is not a hot-plug device.
1342 
1343 **/
1344 BOOLEAN
1345 IsHotPlugDevice (
1346   IN  EFI_DEVICE_PATH_PROTOCOL    *DevicePath
1347   );
1348 
1349 /**
1350   Timer handler to poll the key from serial.
1351 
1352   @param  Event                    Indicates the event that invoke this function.
1353   @param  Context                  Indicates the calling context.
1354 **/
1355 VOID
1356 EFIAPI
1357 TerminalConInTimerHandler (
1358   IN EFI_EVENT            Event,
1359   IN VOID                 *Context
1360   );
1361 #endif
1362