]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Console/TerminalDxe/Terminal.h
Code level security checked
[mirror_edk2.git] / MdeModulePkg / Universal / Console / TerminalDxe / Terminal.h
CommitLineData
fb0b259e 1/** @file\r
2 Header file for Terminal driver.\r
95276127 3\r
fb0b259e 4Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
5All rights reserved. This program and the accompanying materials\r
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
23\r
24#include <Protocol/SimpleTextInExNotify.h>\r
25#include <Protocol/HotPlugDevice.h>\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
f3f2e05d 66#define TERMINAL_DEV_SIGNATURE SIGNATURE_32 ('t', 'm', 'n', 'l')\r
95276127 67\r
f3f2e05d 68#define TERMINAL_CONSOLE_IN_EX_NOTIFY_SIGNATURE SIGNATURE_32 ('t', 'm', 'e', 'n')\r
66aa04e4 69\r
70typedef struct _TERMINAL_CONSOLE_IN_EX_NOTIFY {\r
71 UINTN Signature;\r
72 EFI_HANDLE NotifyHandle;\r
73 EFI_KEY_DATA KeyData;\r
74 EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn;\r
75 LIST_ENTRY NotifyEntry;\r
76} TERMINAL_CONSOLE_IN_EX_NOTIFY;\r
95276127 77typedef struct {\r
78 UINTN Signature;\r
79 EFI_HANDLE Handle;\r
80 UINT8 TerminalType;\r
81 EFI_SERIAL_IO_PROTOCOL *SerialIo;\r
82 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
95276127 83 EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleInput;\r
84 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL SimpleTextOutput;\r
85 EFI_SIMPLE_TEXT_OUTPUT_MODE SimpleTextOutputMode;\r
86 UINTN SerialInTimeOut;\r
5c998646 87 RAW_DATA_FIFO *RawFiFo;\r
88 UNICODE_FIFO *UnicodeFiFo;\r
89 EFI_KEY_FIFO *EfiKeyFiFo;\r
95276127 90 EFI_UNICODE_STRING_TABLE *ControllerNameTable;\r
91 EFI_EVENT TwoSecondTimeOut;\r
92 UINT32 InputState;\r
6b88ceec 93 UINT32 ResetState;\r
95276127 94\r
95 //\r
96 // Esc could not be output to the screen by user,\r
97 // but the terminal driver need to output it to\r
98 // the terminal emulation software to send control sequence.\r
99 // This boolean is used by the terminal driver only\r
100 // to indicate whether the Esc could be sent or not.\r
101 //\r
6b88ceec 102 BOOLEAN OutputEscChar;\r
66aa04e4 103 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL SimpleInputEx;\r
104 LIST_ENTRY NotifyList;\r
95276127 105} TERMINAL_DEV;\r
106\r
107#define INPUT_STATE_DEFAULT 0x00\r
108#define INPUT_STATE_ESC 0x01\r
109#define INPUT_STATE_CSI 0x02\r
110#define INPUT_STATE_LEFTOPENBRACKET 0x04\r
111#define INPUT_STATE_O 0x08\r
112#define INPUT_STATE_2 0x10\r
113\r
114#define RESET_STATE_DEFAULT 0x00\r
115#define RESET_STATE_ESC_R 0x01\r
116#define RESET_STATE_ESC_R_ESC_r 0x02\r
117\r
118#define TERMINAL_CON_IN_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleInput, TERMINAL_DEV_SIGNATURE)\r
119#define TERMINAL_CON_OUT_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleTextOutput, TERMINAL_DEV_SIGNATURE)\r
66aa04e4 120#define TERMINAL_CON_IN_EX_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleInputEx, TERMINAL_DEV_SIGNATURE)\r
95276127 121\r
122typedef union {\r
123 UINT8 Utf8_1;\r
124 UINT8 Utf8_2[2];\r
125 UINT8 Utf8_3[3];\r
126} UTF8_CHAR;\r
127\r
e49ef433 128#define PCANSITYPE 0\r
129#define VT100TYPE 1\r
130#define VT100PLUSTYPE 2\r
131#define VTUTF8TYPE 3\r
95276127 132\r
133#define LEFTOPENBRACKET 0x5b // '['\r
134#define ACAP 0x41\r
135#define BCAP 0x42\r
136#define CCAP 0x43\r
137#define DCAP 0x44\r
138\r
139#define MODE0_COLUMN_COUNT 80\r
140#define MODE0_ROW_COUNT 25\r
141\r
7347d5d6 142#define MODE1_COLUMN_COUNT 80\r
143#define MODE1_ROW_COUNT 50\r
144\r
145#define MODE2_COLUMN_COUNT 100\r
146#define MODE2_ROW_COUNT 31\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
239 @retval FLASE Match failed.\r
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
355 OUT EFI_HANDLE *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
375 IN EFI_HANDLE 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
664 IN OUT LIST_ENTRY *ListHead\r
665 );\r
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
687 in RFC 3066 or ISO 639-2 language code format.\r
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
752 RFC 3066 or ISO 639-2 language code format.\r
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
766 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.\r
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
e49ef433 841/**\r
842 Read the EFI variable (VendorGuid/Name) and return a dynamically allocated\r
843 buffer, and the size of the buffer. On failure return NULL.\r
844\r
845 @param Name String part of EFI variable name\r
846 @param VendorGuid GUID part of EFI variable name\r
847 @param VariableSize Returns the size of the EFI variable that was read\r
848\r
849 @return Dynamically allocated memory that contains a copy of the EFI variable.\r
5c998646 850 Caller is repsoncible freeing the buffer. If variable was not read,\r
ab76200c 851 NULL regturned.\r
e49ef433 852\r
853**/\r
00bfdbe1 854VOID *\r
95276127 855TerminalGetVariableAndSize (\r
856 IN CHAR16 *Name,\r
857 IN EFI_GUID *VendorGuid,\r
858 OUT UINTN *VariableSize\r
ed66e1bc 859 );\r
95276127 860\r
8fd98315 861/**\r
862 Build termial device path according to terminal type.\r
863\r
864 @param TerminalType The terminal type is PC ANSI, VT100, VT100+ or VT-UTF8.\r
11baadb6 865 @param ParentDevicePath Parent device path.\r
8fd98315 866 @param TerminalDevicePath Returned terminal device path, if building successfully.\r
867\r
868 @retval EFI_UNSUPPORTED Terminal does not belong to the supported type.\r
869 @retval EFI_OUT_OF_RESOURCES Generate terminal device path failed.\r
870 @retval EFI_SUCCESS Build terminal device path successfully.\r
871\r
872**/\r
95276127 873EFI_STATUS\r
874SetTerminalDevicePath (\r
875 IN UINT8 TerminalType,\r
876 IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath,\r
877 OUT EFI_DEVICE_PATH_PROTOCOL **TerminalDevicePath\r
ed66e1bc 878 );\r
95276127 879\r
e49ef433 880/**\r
881 Get one key out of serial buffer.\r
882\r
883 @param SerialIo Serial I/O protocl attached to the serial device.\r
884 @param Input The fetched key.\r
885\r
00bfdbe1 886 @retval EFI_NOT_READY If serial buffer is empty.\r
887 @retval EFI_DEVICE_ERROR If reading serial buffer encounter error.\r
888 @retval EFI_SUCCESS If reading serial buffer successfully, put\r
e49ef433 889 the fetched key to the parameter output.\r
890\r
891**/\r
95276127 892EFI_STATUS\r
893GetOneKeyFromSerial (\r
894 EFI_SERIAL_IO_PROTOCOL *SerialIo,\r
895 UINT8 *Input\r
ed66e1bc 896 );\r
95276127 897\r
e49ef433 898/**\r
899 Insert one byte raw data into the Raw Data FIFO.\r
900\r
901 @param TerminalDevice Terminal driver private structure.\r
902 @param Input The key will be input.\r
903\r
00bfdbe1 904 @retval TRUE If insert successfully.\r
905 @retval FLASE If Raw Data buffer is full before key insertion,\r
e49ef433 906 and the key is lost.\r
907\r
908**/\r
95276127 909BOOLEAN\r
910RawFiFoInsertOneKey (\r
911 TERMINAL_DEV *TerminalDevice,\r
912 UINT8 Input\r
ed66e1bc 913 );\r
95276127 914\r
e49ef433 915/**\r
916 Remove one pre-fetched key out of the Raw Data FIFO.\r
917\r
918 @param TerminalDevice Terminal driver private structure.\r
919 @param Output The key will be removed.\r
920\r
00bfdbe1 921 @retval TRUE If insert successfully.\r
922 @retval FLASE If Raw Data FIFO buffer is empty before remove operation.\r
e49ef433 923\r
924**/\r
95276127 925BOOLEAN\r
926RawFiFoRemoveOneKey (\r
927 TERMINAL_DEV *TerminalDevice,\r
928 UINT8 *Output\r
ed66e1bc 929 );\r
95276127 930\r
e49ef433 931/**\r
932 Clarify whether Raw Data FIFO buffer is empty.\r
933\r
934 @param TerminalDevice Terminal driver private structure\r
935\r
00bfdbe1 936 @retval TRUE If Raw Data FIFO buffer is empty.\r
937 @retval FLASE If Raw Data FIFO buffer is not empty.\r
e49ef433 938\r
939**/\r
95276127 940BOOLEAN\r
941IsRawFiFoEmpty (\r
942 TERMINAL_DEV *TerminalDevice\r
ed66e1bc 943 );\r
95276127 944\r
e49ef433 945/**\r
946 Clarify whether Raw Data FIFO buffer is full.\r
947\r
948 @param TerminalDevice Terminal driver private structure\r
949\r
00bfdbe1 950 @retval TRUE If Raw Data FIFO buffer is full.\r
951 @retval FLASE If Raw Data FIFO buffer is not full.\r
e49ef433 952\r
953**/\r
95276127 954BOOLEAN\r
955IsRawFiFoFull (\r
956 TERMINAL_DEV *TerminalDevice\r
ed66e1bc 957 );\r
95276127 958\r
e49ef433 959/**\r
960 Insert one pre-fetched key into the FIFO buffer.\r
961\r
962 @param TerminalDevice Terminal driver private structure.\r
963 @param Key The key will be input.\r
964\r
00bfdbe1 965 @retval TRUE If insert successfully.\r
966 @retval FLASE If FIFO buffer is full before key insertion,\r
e49ef433 967 and the key is lost.\r
968\r
969**/\r
95276127 970BOOLEAN\r
971EfiKeyFiFoInsertOneKey (\r
972 TERMINAL_DEV *TerminalDevice,\r
973 EFI_INPUT_KEY Key\r
ed66e1bc 974 );\r
95276127 975\r
e49ef433 976/**\r
977 Remove one pre-fetched key out of the FIFO buffer.\r
978\r
979 @param TerminalDevice Terminal driver private structure.\r
980 @param Output The key will be removed.\r
981\r
00bfdbe1 982 @retval TRUE If insert successfully.\r
983 @retval FLASE If FIFO buffer is empty before remove operation.\r
e49ef433 984\r
985**/\r
95276127 986BOOLEAN\r
987EfiKeyFiFoRemoveOneKey (\r
988 TERMINAL_DEV *TerminalDevice,\r
989 EFI_INPUT_KEY *Output\r
ed66e1bc 990 );\r
95276127 991\r
e49ef433 992/**\r
993 Clarify whether FIFO buffer is empty.\r
994\r
995 @param TerminalDevice Terminal driver private structure\r
996\r
00bfdbe1 997 @retval TRUE If FIFO buffer is empty.\r
998 @retval FLASE If FIFO buffer is not empty.\r
e49ef433 999\r
1000**/\r
95276127 1001BOOLEAN\r
1002IsEfiKeyFiFoEmpty (\r
1003 TERMINAL_DEV *TerminalDevice\r
ed66e1bc 1004 );\r
95276127 1005\r
e49ef433 1006/**\r
1007 Clarify whether FIFO buffer is full.\r
1008\r
1009 @param TerminalDevice Terminal driver private structure\r
1010\r
00bfdbe1 1011 @retval TRUE If FIFO buffer is full.\r
1012 @retval FLASE If FIFO buffer is not full.\r
e49ef433 1013\r
1014**/\r
95276127 1015BOOLEAN\r
1016IsEfiKeyFiFoFull (\r
1017 TERMINAL_DEV *TerminalDevice\r
ed66e1bc 1018 );\r
95276127 1019\r
e49ef433 1020/**\r
1021 Insert one pre-fetched key into the Unicode FIFO buffer.\r
1022\r
1023 @param TerminalDevice Terminal driver private structure.\r
1024 @param Input The key will be input.\r
1025\r
00bfdbe1 1026 @retval TRUE If insert successfully.\r
1027 @retval FLASE If Unicode FIFO buffer is full before key insertion,\r
e49ef433 1028 and the key is lost.\r
1029\r
1030**/\r
95276127 1031BOOLEAN\r
1032UnicodeFiFoInsertOneKey (\r
1033 TERMINAL_DEV *TerminalDevice,\r
1034 UINT16 Input\r
ed66e1bc 1035 );\r
95276127 1036\r
e49ef433 1037/**\r
1038 Remove one pre-fetched key out of the Unicode FIFO buffer.\r
1039\r
1040 @param TerminalDevice Terminal driver private structure.\r
1041 @param Output The key will be removed.\r
1042\r
00bfdbe1 1043 @retval TRUE If insert successfully.\r
1044 @retval FLASE If Unicode FIFO buffer is empty before remove operation.\r
e49ef433 1045\r
1046**/\r
95276127 1047BOOLEAN\r
1048UnicodeFiFoRemoveOneKey (\r
1049 TERMINAL_DEV *TerminalDevice,\r
1050 UINT16 *Output\r
ed66e1bc 1051 );\r
95276127 1052\r
e49ef433 1053/**\r
1054 Clarify whether Unicode FIFO buffer is empty.\r
1055\r
1056 @param TerminalDevice Terminal driver private structure\r
1057\r
00bfdbe1 1058 @retval TRUE If Unicode FIFO buffer is empty.\r
1059 @retval FLASE If Unicode FIFO buffer is not empty.\r
e49ef433 1060\r
1061**/\r
95276127 1062BOOLEAN\r
1063IsUnicodeFiFoEmpty (\r
1064 TERMINAL_DEV *TerminalDevice\r
ed66e1bc 1065 );\r
95276127 1066\r
e49ef433 1067/**\r
1068 Clarify whether Unicode FIFO buffer is full.\r
1069\r
1070 @param TerminalDevice Terminal driver private structure\r
1071\r
00bfdbe1 1072 @retval TRUE If Unicode FIFO buffer is full.\r
1073 @retval FLASE If Unicode FIFO buffer is not full.\r
e49ef433 1074\r
1075**/\r
95276127 1076BOOLEAN\r
1077IsUnicodeFiFoFull (\r
1078 TERMINAL_DEV *TerminalDevice\r
ed66e1bc 1079 );\r
95276127 1080\r
8fd98315 1081/**\r
1082 Count Unicode FIFO buffer.\r
1083\r
1084 @param TerminalDevice Terminal driver private structure\r
1085\r
1086 @return The count in bytes of Unicode FIFO.\r
1087\r
1088**/\r
95276127 1089UINT8\r
1090UnicodeFiFoGetKeyCount (\r
1091 TERMINAL_DEV *TerminalDevice\r
ed66e1bc 1092 );\r
95276127 1093\r
8fd98315 1094/**\r
5c998646 1095 Translate raw data into Unicode (according to different encode), and\r
1096 translate Unicode into key information. (according to different standard).\r
8fd98315 1097\r
1098 @param TerminalDevice Terminal driver private structure.\r
1099\r
8fd98315 1100**/\r
95276127 1101VOID\r
1102TranslateRawDataToEfiKey (\r
1103 IN TERMINAL_DEV *TerminalDevice\r
ed66e1bc 1104 );\r
95276127 1105\r
1106//\r
1107// internal functions for PC ANSI\r
1108//\r
8fd98315 1109\r
1110/**\r
1111 Translate all raw data in the Raw FIFI into unicode, and insert\r
1112 them into Unicode FIFO.\r
1113\r
1114 @param TerminalDevice The terminal device.\r
1115\r
8fd98315 1116**/\r
95276127 1117VOID\r
1118AnsiRawDataToUnicode (\r
8fd98315 1119 IN TERMINAL_DEV *TerminalDevice\r
ed66e1bc 1120 );\r
95276127 1121\r
8fd98315 1122/**\r
1123 Converts a stream of Unicode characters from a terminal input device into EFI Keys that\r
5c998646 1124 can be read through the Simple Input Protocol.\r
1125\r
8fd98315 1126 The table below shows the keyboard input mappings that this function supports.\r
1127 If the ESC sequence listed in one of the columns is presented, then it is translated\r
1128 into the coorespoding EFI Scan Code. If a matching sequence is not found, then the raw\r
1129 key strokes are converted into EFI Keys.\r
1130\r
1131 2 seconds are allowed for an ESC sequence to be completed. If the ESC sequence is not\r
1132 completed in 2 seconds, then the raw key strokes of the partial ESC sequence are\r
1133 converted into EFI Keys.\r
1134 There is one special input sequence that will force the system to reset.\r
1135 This is ESC R ESC r ESC R.\r
1136\r
1137 Symbols used in table below\r
1138 ===========================\r
1139 ESC = 0x1B\r
1140 CSI = 0x9B\r
1141 DEL = 0x7f\r
1142 ^ = CTRL\r
1143 +=========+======+===========+==========+==========+\r
1144 | | EFI | UEFI 2.0 | | |\r
1145 | | Scan | | VT100+ | |\r
1146 | KEY | Code | PC ANSI | VTUTF8 | VT100 |\r
1147 +=========+======+===========+==========+==========+\r
1148 | NULL | 0x00 | | | |\r
1149 | UP | 0x01 | ESC [ A | ESC [ A | ESC [ A |\r
1150 | DOWN | 0x02 | ESC [ B | ESC [ B | ESC [ B |\r
1151 | RIGHT | 0x03 | ESC [ C | ESC [ C | ESC [ C |\r
1152 | LEFT | 0x04 | ESC [ D | ESC [ D | ESC [ D |\r
1153 | HOME | 0x05 | ESC [ H | ESC h | ESC [ H |\r
1154 | END | 0x06 | ESC [ F | ESC k | ESC [ K |\r
1155 | INSERT | 0x07 | ESC [ @ | ESC + | ESC [ @ |\r
1156 | | | ESC [ L | | ESC [ L |\r
1157 | DELETE | 0x08 | ESC [ X | ESC - | ESC [ P |\r
1158 | PG UP | 0x09 | ESC [ I | ESC ? | ESC [ V |\r
1159 | | | | | ESC [ ? |\r
1160 | PG DOWN | 0x0A | ESC [ G | ESC / | ESC [ U |\r
1161 | | | | | ESC [ / |\r
1162 | F1 | 0x0B | ESC [ M | ESC 1 | ESC O P |\r
1163 | F2 | 0x0C | ESC [ N | ESC 2 | ESC O Q |\r
1164 | F3 | 0x0D | ESC [ O | ESC 3 | ESC O w |\r
1165 | F4 | 0x0E | ESC [ P | ESC 4 | ESC O x |\r
1166 | F5 | 0x0F | ESC [ Q | ESC 5 | ESC O t |\r
1167 | F6 | 0x10 | ESC [ R | ESC 6 | ESC O u |\r
1168 | F7 | 0x11 | ESC [ S | ESC 7 | ESC O q |\r
1169 | F8 | 0x12 | ESC [ T | ESC 8 | ESC O r |\r
1170 | F9 | 0x13 | ESC [ U | ESC 9 | ESC O p |\r
1171 | F10 | 0x14 | ESC [ V | ESC 0 | ESC O M |\r
1172 | Escape | 0x17 | ESC | ESC | ESC |\r
1173 | F11 | 0x15 | | ESC ! | |\r
1174 | F12 | 0x16 | | ESC @ | |\r
1175 +=========+======+===========+==========+==========+\r
5c998646 1176\r
8fd98315 1177 Special Mappings\r
1178 ================\r
1179 ESC R ESC r ESC R = Reset System\r
1180\r
1181\r
1182 @param TerminalDevice The terminal device to use to translate raw input into EFI Keys\r
1183\r
8fd98315 1184**/\r
95276127 1185VOID\r
1186UnicodeToEfiKey (\r
ab76200c 1187 IN TERMINAL_DEV *TerminalDevice\r
ed66e1bc 1188 );\r
95276127 1189\r
8fd98315 1190/**\r
1191 Check if input string is valid Ascii string, valid EFI control characters\r
1192 or valid text graphics.\r
1193\r
1194 @param TerminalDevice The terminal device.\r
5c998646 1195 @param WString The input string.\r
1196\r
8fd98315 1197 @retval EFI_UNSUPPORTED If not all input characters are valid.\r
1198 @retval EFI_SUCCESS If all input characters are valid.\r
1199\r
1200**/\r
95276127 1201EFI_STATUS\r
1202AnsiTestString (\r
1203 IN TERMINAL_DEV *TerminalDevice,\r
95276127 1204 IN CHAR16 *WString\r
ed66e1bc 1205 );\r
95276127 1206\r
1207//\r
1208// internal functions for VTUTF8\r
1209//\r
8fd98315 1210\r
1211/**\r
5c998646 1212 Translate all VT-UTF8 characters in the Raw FIFI into unicode characters,\r
8fd98315 1213 and insert them into Unicode FIFO.\r
1214\r
1215 @param VtUtf8Device The terminal device.\r
1216\r
8fd98315 1217**/\r
95276127 1218VOID\r
1219VTUTF8RawDataToUnicode (\r
1220 IN TERMINAL_DEV *VtUtf8Device\r
ed66e1bc 1221 );\r
95276127 1222\r
8fd98315 1223/**\r
1224 Check if input string is valid VT-UTF8 string.\r
1225\r
1226 @param TerminalDevice The terminal device.\r
5c998646 1227 @param WString The input string.\r
1228\r
8fd98315 1229 @retval EFI_SUCCESS If all input characters are valid.\r
1230\r
1231**/\r
95276127 1232EFI_STATUS\r
1233VTUTF8TestString (\r
1234 IN TERMINAL_DEV *TerminalDevice,\r
1235 IN CHAR16 *WString\r
ed66e1bc 1236 );\r
95276127 1237\r
5c998646 1238/**\r
8fd98315 1239 Translate one Unicode character into VT-UTF8 characters.\r
1240\r
1241 UTF8 Encoding Table\r
1242 Bits per Character | Unicode Character Range | Unicode Binary Encoding | UTF8 Binary Encoding\r
11baadb6 1243 0-7 | 0x0000 - 0x007F | 00000000 0xxxxxxx | 0xxxxxxx\r
1244 8-11 | 0x0080 - 0x07FF | 00000xxx xxxxxxxx | 110xxxxx 10xxxxxx\r
1245 12-16 | 0x0800 - 0xFFFF | xxxxxxxx xxxxxxxx | 1110xxxx 10xxxxxx 10xxxxxx\r
8fd98315 1246\r
1247\r
1248 @param Unicode Unicode character need translating.\r
1249 @param Utf8Char Return VT-UTF8 character set.\r
1250 @param ValidBytes The count of valid VT-UTF8 characters. If\r
1251 ValidBytes is zero, no valid VT-UTF8 returned.\r
8fd98315 1252\r
1253**/\r
95276127 1254VOID\r
1255UnicodeToUtf8 (\r
1256 IN CHAR16 Unicode,\r
1257 OUT UTF8_CHAR *Utf8Char,\r
1258 OUT UINT8 *ValidBytes\r
ed66e1bc 1259 );\r
95276127 1260\r
8fd98315 1261/**\r
1262 Get one valid VT-UTF8 characters set from Raw Data FIFO.\r
1263\r
1264 @param Utf8Device The terminal device.\r
1265 @param Utf8Char Returned valid VT-UTF8 characters set.\r
5c998646 1266 @param ValidBytes The count of returned VT-VTF8 characters.\r
8fd98315 1267 If ValidBytes is zero, no valid VT-UTF8 returned.\r
1268\r
8fd98315 1269**/\r
95276127 1270VOID\r
1271GetOneValidUtf8Char (\r
1272 IN TERMINAL_DEV *Utf8Device,\r
1273 OUT UTF8_CHAR *Utf8Char,\r
1274 OUT UINT8 *ValidBytes\r
ed66e1bc 1275 );\r
95276127 1276\r
5c998646 1277/**\r
8fd98315 1278 Translate VT-UTF8 characters into one Unicode character.\r
1279\r
1280 UTF8 Encoding Table\r
1281 Bits per Character | Unicode Character Range | Unicode Binary Encoding | UTF8 Binary Encoding\r
11baadb6 1282 0-7 | 0x0000 - 0x007F | 00000000 0xxxxxxx | 0xxxxxxx\r
1283 8-11 | 0x0080 - 0x07FF | 00000xxx xxxxxxxx | 110xxxxx 10xxxxxx\r
1284 12-16 | 0x0800 - 0xFFFF | xxxxxxxx xxxxxxxx | 1110xxxx 10xxxxxx 10xxxxxx\r
8fd98315 1285\r
1286\r
1287 @param Utf8Char VT-UTF8 character set needs translating.\r
1288 @param ValidBytes The count of valid VT-UTF8 characters.\r
5c998646 1289 @param UnicodeChar Returned unicode character.\r
8fd98315 1290\r
1291**/\r
95276127 1292VOID\r
1293Utf8ToUnicode (\r
1294 IN UTF8_CHAR Utf8Char,\r
1295 IN UINT8 ValidBytes,\r
1296 OUT CHAR16 *UnicodeChar\r
ed66e1bc 1297 );\r
95276127 1298\r
1299//\r
1300// functions for boxdraw unicode\r
1301//\r
8fd98315 1302\r
1303/**\r
1304 Detects if a Unicode char is for Box Drawing text graphics.\r
1305\r
1306 @param Graphic Unicode char to test.\r
1307 @param PcAnsi Optional pointer to return PCANSI equivalent of\r
1308 Graphic.\r
1309 @param Ascii Optional pointer to return ASCII equivalent of\r
1310 Graphic.\r
1311\r
00bfdbe1 1312 @retval TRUE If Graphic is a supported Unicode Box Drawing character.\r
8fd98315 1313\r
1314**/\r
95276127 1315BOOLEAN\r
1316TerminalIsValidTextGraphics (\r
1317 IN CHAR16 Graphic,\r
1318 OUT CHAR8 *PcAnsi, OPTIONAL\r
1319 OUT CHAR8 *Ascii OPTIONAL\r
ed66e1bc 1320 );\r
95276127 1321\r
8fd98315 1322/**\r
1323 Detects if a valid ASCII char.\r
1324\r
1325 @param Ascii An ASCII character.\r
5c998646 1326\r
8fd98315 1327 @retval TRUE If it is a valid ASCII character.\r
1328 @retval FALSE If it is not a valid ASCII character.\r
1329\r
1330**/\r
95276127 1331BOOLEAN\r
1332TerminalIsValidAscii (\r
1333 IN CHAR16 Ascii\r
ed66e1bc 1334 );\r
95276127 1335\r
8fd98315 1336/**\r
1337 Detects if a valid EFI control character.\r
1338\r
1339 @param CharC An input EFI Control character.\r
5c998646 1340\r
8fd98315 1341 @retval TRUE If it is a valid EFI control character.\r
1342 @retval FALSE If it is not a valid EFI control character.\r
1343\r
1344**/\r
95276127 1345BOOLEAN\r
1346TerminalIsValidEfiCntlChar (\r
1347 IN CHAR16 CharC\r
ed66e1bc 1348 );\r
95276127 1349\r
1350#endif\r