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