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