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