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