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