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