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