Cleaned up EFI Console Variable usage
[mirror_edk2.git] / MdeModulePkg / Universal / Console / TerminalDxe / Terminal.h
CommitLineData
95276127 1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 terminal.h\r
15\r
16Abstract:\r
17\r
18 \r
19Revision History\r
20\r
21--*/\r
22\r
23#ifndef _TERMINAL_H\r
24#define _TERMINAL_H\r
25\r
97a079ed
A
26\r
27#include <PiDxe.h>\r
28#include <Protocol/SimpleTextOut.h>\r
29#include <Protocol/SerialIo.h>\r
30#include <Guid/GlobalVariable.h>\r
31#include <Protocol/DevicePath.h>\r
32#include <Protocol/SimpleTextIn.h>\r
33#include <Guid/HotPlugDevice.h>\r
34#include <Guid/PcAnsi.h>\r
35#include <Library/DebugLib.h>\r
36#include <Library/UefiDriverEntryPoint.h>\r
37#include <Library/UefiLib.h>\r
38#include <Library/ReportStatusCodeLib.h>\r
39#include <Library/BaseMemoryLib.h>\r
40#include <Library/MemoryAllocationLib.h>\r
41#include <Library/UefiBootServicesTableLib.h>\r
42#include <Library/UefiRuntimeServicesTableLib.h>\r
43#include <Library/DevicePathLib.h>\r
44#include <Library/PcdLib.h>\r
45\r
46\r
95276127 47\r
48#define RAW_FIFO_MAX_NUMBER 256\r
49#define FIFO_MAX_NUMBER 128\r
50\r
51typedef struct {\r
52 UINT8 Head;\r
53 UINT8 Tail;\r
54 UINT8 Data[RAW_FIFO_MAX_NUMBER + 1];\r
55} RAW_DATA_FIFO;\r
56\r
57typedef struct {\r
58 UINT8 Head;\r
59 UINT8 Tail;\r
60 UINT16 Data[FIFO_MAX_NUMBER + 1];\r
61} UNICODE_FIFO;\r
62\r
63typedef struct {\r
64 UINT8 Head;\r
65 UINT8 Tail;\r
66 EFI_INPUT_KEY Data[FIFO_MAX_NUMBER + 1];\r
67} EFI_KEY_FIFO;\r
68\r
69#define TERMINAL_DEV_SIGNATURE EFI_SIGNATURE_32 ('t', 'm', 'n', 'l')\r
70\r
71typedef struct {\r
72 UINTN Signature;\r
73 EFI_HANDLE Handle;\r
74 UINT8 TerminalType;\r
75 EFI_SERIAL_IO_PROTOCOL *SerialIo;\r
76 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
95276127 77 EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleInput;\r
78 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL SimpleTextOutput;\r
79 EFI_SIMPLE_TEXT_OUTPUT_MODE SimpleTextOutputMode;\r
80 UINTN SerialInTimeOut;\r
81 RAW_DATA_FIFO RawFiFo;\r
82 UNICODE_FIFO UnicodeFiFo;\r
83 EFI_KEY_FIFO EfiKeyFiFo;\r
84 EFI_UNICODE_STRING_TABLE *ControllerNameTable;\r
85 EFI_EVENT TwoSecondTimeOut;\r
86 UINT32 InputState;\r
6b88ceec 87 UINT32 ResetState;\r
95276127 88\r
89 //\r
90 // Esc could not be output to the screen by user,\r
91 // but the terminal driver need to output it to\r
92 // the terminal emulation software to send control sequence.\r
93 // This boolean is used by the terminal driver only\r
94 // to indicate whether the Esc could be sent or not.\r
95 //\r
6b88ceec 96 BOOLEAN OutputEscChar;\r
95276127 97} TERMINAL_DEV;\r
98\r
99#define INPUT_STATE_DEFAULT 0x00\r
100#define INPUT_STATE_ESC 0x01\r
101#define INPUT_STATE_CSI 0x02\r
102#define INPUT_STATE_LEFTOPENBRACKET 0x04\r
103#define INPUT_STATE_O 0x08\r
104#define INPUT_STATE_2 0x10\r
105\r
106#define RESET_STATE_DEFAULT 0x00\r
107#define RESET_STATE_ESC_R 0x01\r
108#define RESET_STATE_ESC_R_ESC_r 0x02\r
109\r
110#define TERMINAL_CON_IN_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleInput, TERMINAL_DEV_SIGNATURE)\r
111#define TERMINAL_CON_OUT_DEV_FROM_THIS(a) CR (a, TERMINAL_DEV, SimpleTextOutput, TERMINAL_DEV_SIGNATURE)\r
112\r
113typedef union {\r
114 UINT8 Utf8_1;\r
115 UINT8 Utf8_2[2];\r
116 UINT8 Utf8_3[3];\r
117} UTF8_CHAR;\r
118\r
119#define PcAnsiType 0\r
120#define VT100Type 1\r
121#define VT100PlusType 2\r
122#define VTUTF8Type 3\r
123\r
124#define LEFTOPENBRACKET 0x5b // '['\r
125#define ACAP 0x41\r
126#define BCAP 0x42\r
127#define CCAP 0x43\r
128#define DCAP 0x44\r
129\r
130#define MODE0_COLUMN_COUNT 80\r
131#define MODE0_ROW_COUNT 25\r
132\r
133#define BACKSPACE 8\r
134#define ESC 27\r
135#define CSI 0x9B\r
136#define DEL 127\r
137#define BRIGHT_CONTROL_OFFSET 2\r
138#define FOREGROUND_CONTROL_OFFSET 6\r
139#define BACKGROUND_CONTROL_OFFSET 11\r
140#define ROW_OFFSET 2\r
141#define COLUMN_OFFSET 5\r
142\r
143typedef struct {\r
144 UINT16 Unicode;\r
145 CHAR8 PcAnsi;\r
146 CHAR8 Ascii;\r
147} UNICODE_TO_CHAR;\r
148\r
95276127 149//\r
150// Global Variables\r
151//\r
152extern EFI_DRIVER_BINDING_PROTOCOL gTerminalDriverBinding;\r
153extern EFI_COMPONENT_NAME_PROTOCOL gTerminalComponentName;\r
154\r
155//\r
156// Prototypes\r
157//\r
158EFI_STATUS\r
159EFIAPI\r
160InitializeTerminal (\r
161 IN EFI_HANDLE ImageHandle,\r
162 IN EFI_SYSTEM_TABLE *SystemTable\r
163 )\r
164;\r
165\r
166EFI_STATUS\r
167EFIAPI\r
168TerminalConInReset (\r
169 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,\r
170 IN BOOLEAN ExtendedVerification\r
171 )\r
172;\r
173\r
174EFI_STATUS\r
175EFIAPI\r
176TerminalConInReadKeyStroke (\r
177 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,\r
178 OUT EFI_INPUT_KEY *Key\r
179 )\r
180;\r
181\r
182VOID\r
183EFIAPI\r
184TerminalConInWaitForKey (\r
185 IN EFI_EVENT Event,\r
186 IN VOID *Context\r
187 )\r
188;\r
189\r
190EFI_STATUS\r
191EFIAPI\r
192TerminalConOutReset (\r
193 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
194 IN BOOLEAN ExtendedVerification\r
195 )\r
196;\r
197\r
198EFI_STATUS\r
199EFIAPI\r
200TerminalConOutOutputString (\r
201 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
202 IN CHAR16 *WString\r
203 )\r
204;\r
205\r
206EFI_STATUS\r
207EFIAPI\r
208TerminalConOutTestString (\r
209 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
210 IN CHAR16 *WString\r
211 )\r
212;\r
213\r
214EFI_STATUS\r
215EFIAPI\r
216TerminalConOutQueryMode (\r
217 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
218 IN UINTN ModeNumber,\r
219 OUT UINTN *Columns,\r
220 OUT UINTN *Rows\r
221 )\r
222;\r
223\r
224EFI_STATUS\r
225EFIAPI\r
226TerminalConOutSetMode (\r
227 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
228 IN UINTN ModeNumber\r
229 )\r
230;\r
231\r
232EFI_STATUS\r
233EFIAPI\r
234TerminalConOutSetAttribute (\r
235 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
236 IN UINTN Attribute\r
237 )\r
238;\r
239\r
240EFI_STATUS\r
241EFIAPI\r
242TerminalConOutClearScreen (\r
243 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This\r
244 )\r
245;\r
246\r
247EFI_STATUS\r
248EFIAPI\r
249TerminalConOutSetCursorPosition (\r
250 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
251 IN UINTN Column,\r
252 IN UINTN Row\r
253 )\r
254;\r
255\r
256EFI_STATUS\r
257EFIAPI\r
258TerminalConOutEnableCursor (\r
259 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
260 IN BOOLEAN Visible\r
261 )\r
262;\r
263\r
264EFI_STATUS\r
265EFIAPI\r
266TerminalDriverBindingSupported (\r
267 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
268 IN EFI_HANDLE Controller,\r
269 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
270 );\r
271\r
272EFI_STATUS\r
273EFIAPI\r
274TerminalDriverBindingStart (\r
275 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
276 IN EFI_HANDLE Controller,\r
277 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
278 );\r
279\r
280EFI_STATUS\r
281EFIAPI\r
282TerminalDriverBindingStop (\r
283 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
284 IN EFI_HANDLE Controller,\r
285 IN UINTN NumberOfChildren,\r
286 IN EFI_HANDLE *ChildHandleBuffer\r
287 );\r
288\r
289EFI_STATUS\r
290EFIAPI\r
291TerminalComponentNameGetDriverName (\r
292 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
293 IN CHAR8 *Language,\r
294 OUT CHAR16 **DriverName\r
295 );\r
296\r
297EFI_STATUS\r
298EFIAPI\r
299TerminalComponentNameGetControllerName (\r
300 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
301 IN EFI_HANDLE ControllerHandle,\r
302 IN EFI_HANDLE ChildHandle OPTIONAL,\r
303 IN CHAR8 *Language,\r
304 OUT CHAR16 **ControllerName\r
305 );\r
306\r
307//\r
308// internal functions\r
309//\r
310EFI_STATUS\r
311TerminalConInCheckForKey (\r
312 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This\r
313 )\r
314;\r
315\r
316VOID\r
317TerminalUpdateConsoleDevVariable (\r
318 IN CHAR16 *VariableName,\r
319 IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath\r
320 )\r
321;\r
322\r
323VOID\r
324TerminalRemoveConsoleDevVariable (\r
325 IN CHAR16 *VariableName,\r
326 IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath\r
327 )\r
328;\r
329\r
330VOID *\r
331TerminalGetVariableAndSize (\r
332 IN CHAR16 *Name,\r
333 IN EFI_GUID *VendorGuid,\r
334 OUT UINTN *VariableSize\r
335 )\r
336;\r
337\r
338EFI_STATUS\r
339SetTerminalDevicePath (\r
340 IN UINT8 TerminalType,\r
341 IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath,\r
342 OUT EFI_DEVICE_PATH_PROTOCOL **TerminalDevicePath\r
343 )\r
344;\r
345\r
346VOID\r
347InitializeRawFiFo (\r
348 IN TERMINAL_DEV *TerminalDevice\r
349 )\r
350;\r
351\r
352VOID\r
353InitializeUnicodeFiFo (\r
354 IN TERMINAL_DEV *TerminalDevice\r
355 )\r
356;\r
357\r
358VOID\r
359InitializeEfiKeyFiFo (\r
360 IN TERMINAL_DEV *TerminalDevice\r
361 )\r
362;\r
363\r
364EFI_STATUS\r
365GetOneKeyFromSerial (\r
366 EFI_SERIAL_IO_PROTOCOL *SerialIo,\r
367 UINT8 *Input\r
368 )\r
369;\r
370\r
371BOOLEAN\r
372RawFiFoInsertOneKey (\r
373 TERMINAL_DEV *TerminalDevice,\r
374 UINT8 Input\r
375 )\r
376;\r
377\r
378BOOLEAN\r
379RawFiFoRemoveOneKey (\r
380 TERMINAL_DEV *TerminalDevice,\r
381 UINT8 *Output\r
382 )\r
383;\r
384\r
385BOOLEAN\r
386IsRawFiFoEmpty (\r
387 TERMINAL_DEV *TerminalDevice\r
388 )\r
389;\r
390\r
391BOOLEAN\r
392IsRawFiFoFull (\r
393 TERMINAL_DEV *TerminalDevice\r
394 )\r
395;\r
396\r
397BOOLEAN\r
398EfiKeyFiFoInsertOneKey (\r
399 TERMINAL_DEV *TerminalDevice,\r
400 EFI_INPUT_KEY Key\r
401 )\r
402;\r
403\r
404BOOLEAN\r
405EfiKeyFiFoRemoveOneKey (\r
406 TERMINAL_DEV *TerminalDevice,\r
407 EFI_INPUT_KEY *Output\r
408 )\r
409;\r
410\r
411BOOLEAN\r
412IsEfiKeyFiFoEmpty (\r
413 TERMINAL_DEV *TerminalDevice\r
414 )\r
415;\r
416\r
417BOOLEAN\r
418IsEfiKeyFiFoFull (\r
419 TERMINAL_DEV *TerminalDevice\r
420 )\r
421;\r
422\r
423BOOLEAN\r
424UnicodeFiFoInsertOneKey (\r
425 TERMINAL_DEV *TerminalDevice,\r
426 UINT16 Input\r
427 )\r
428;\r
429\r
430BOOLEAN\r
431UnicodeFiFoRemoveOneKey (\r
432 TERMINAL_DEV *TerminalDevice,\r
433 UINT16 *Output\r
434 )\r
435;\r
436\r
437BOOLEAN\r
438IsUnicodeFiFoEmpty (\r
439 TERMINAL_DEV *TerminalDevice\r
440 )\r
441;\r
442\r
443BOOLEAN\r
444IsUnicodeFiFoFull (\r
445 TERMINAL_DEV *TerminalDevice\r
446 )\r
447;\r
448\r
449UINT8\r
450UnicodeFiFoGetKeyCount (\r
451 TERMINAL_DEV *TerminalDevice\r
452 )\r
453;\r
454\r
455VOID\r
456TranslateRawDataToEfiKey (\r
457 IN TERMINAL_DEV *TerminalDevice\r
458 )\r
459;\r
460\r
461//\r
462// internal functions for PC ANSI\r
463//\r
464VOID\r
465AnsiRawDataToUnicode (\r
466 IN TERMINAL_DEV *PcAnsiDevice\r
467 )\r
468;\r
469\r
470VOID\r
471UnicodeToEfiKey (\r
472 IN TERMINAL_DEV *PcAnsiDevice\r
473 )\r
474;\r
475\r
476EFI_STATUS\r
477AnsiTestString (\r
478 IN TERMINAL_DEV *TerminalDevice,\r
479 IN CHAR16 *WString\r
480 )\r
481;\r
482\r
483//\r
484// internal functions for VT100\r
485//\r
486EFI_STATUS\r
487VT100TestString (\r
488 IN TERMINAL_DEV *VT100Device,\r
489 IN CHAR16 *WString\r
490 )\r
491;\r
492\r
493//\r
494// internal functions for VT100Plus\r
495//\r
496EFI_STATUS\r
497VT100PlusTestString (\r
498 IN TERMINAL_DEV *TerminalDevice,\r
499 IN CHAR16 *WString\r
500 )\r
501;\r
502\r
503//\r
504// internal functions for VTUTF8\r
505//\r
506VOID\r
507VTUTF8RawDataToUnicode (\r
508 IN TERMINAL_DEV *VtUtf8Device\r
509 )\r
510;\r
511\r
512EFI_STATUS\r
513VTUTF8TestString (\r
514 IN TERMINAL_DEV *TerminalDevice,\r
515 IN CHAR16 *WString\r
516 )\r
517;\r
518\r
519VOID\r
520UnicodeToUtf8 (\r
521 IN CHAR16 Unicode,\r
522 OUT UTF8_CHAR *Utf8Char,\r
523 OUT UINT8 *ValidBytes\r
524 )\r
525;\r
526\r
527VOID\r
528GetOneValidUtf8Char (\r
529 IN TERMINAL_DEV *Utf8Device,\r
530 OUT UTF8_CHAR *Utf8Char,\r
531 OUT UINT8 *ValidBytes\r
532 )\r
533;\r
534\r
535VOID\r
536Utf8ToUnicode (\r
537 IN UTF8_CHAR Utf8Char,\r
538 IN UINT8 ValidBytes,\r
539 OUT CHAR16 *UnicodeChar\r
540 )\r
541;\r
542\r
543//\r
544// functions for boxdraw unicode\r
545//\r
546BOOLEAN\r
547TerminalIsValidTextGraphics (\r
548 IN CHAR16 Graphic,\r
549 OUT CHAR8 *PcAnsi, OPTIONAL\r
550 OUT CHAR8 *Ascii OPTIONAL\r
551 )\r
552;\r
553\r
554BOOLEAN\r
555TerminalIsValidAscii (\r
556 IN CHAR16 Ascii\r
557 )\r
558;\r
559\r
560BOOLEAN\r
561TerminalIsValidEfiCntlChar (\r
562 IN CHAR16 CharC\r
563 )\r
564;\r
565\r
566#endif\r