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