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