2 Implementation for EFI_SIMPLE_TEXT_INPUT_PROTOCOL protocol.
4 (C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
6 Copyright (C) 2016 Silicon Graphics, Inc. All rights reserved.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 Reads the next keystroke from the input device. The WaitForKey Event can
22 be used to test for existence of a keystroke via WaitForEvent () call.
24 @param TerminalDevice Terminal driver private structure
25 @param KeyData A pointer to a buffer that is filled in with the
26 keystroke state data for the key that was
29 @retval EFI_SUCCESS The keystroke information was returned.
30 @retval EFI_NOT_READY There was no keystroke data available.
31 @retval EFI_INVALID_PARAMETER KeyData is NULL.
36 IN TERMINAL_DEV
*TerminalDevice
,
37 OUT EFI_KEY_DATA
*KeyData
40 if (KeyData
== NULL
) {
41 return EFI_INVALID_PARAMETER
;
44 KeyData
->KeyState
.KeyShiftState
= 0;
45 KeyData
->KeyState
.KeyToggleState
= 0;
47 if (!EfiKeyFiFoRemoveOneKey (TerminalDevice
, &KeyData
->Key
)) {
56 Implements EFI_SIMPLE_TEXT_INPUT_PROTOCOL.Reset().
57 This driver only perform dependent serial device reset regardless of
58 the value of ExtendeVerification
60 @param This Indicates the calling context.
61 @param ExtendedVerification Skip by this driver.
63 @retval EFI_SUCCESS The reset operation succeeds.
64 @retval EFI_DEVICE_ERROR The dependent serial port reset fails.
70 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
71 IN BOOLEAN ExtendedVerification
75 TERMINAL_DEV
*TerminalDevice
;
77 TerminalDevice
= TERMINAL_CON_IN_DEV_FROM_THIS (This
);
80 // Report progress code here
82 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
84 (EFI_PERIPHERAL_REMOTE_CONSOLE
| EFI_P_PC_RESET
),
85 TerminalDevice
->DevicePath
88 Status
= TerminalDevice
->SerialIo
->Reset (TerminalDevice
->SerialIo
);
91 // Make all the internal buffer empty for keys
93 TerminalDevice
->RawFiFo
->Head
= TerminalDevice
->RawFiFo
->Tail
;
94 TerminalDevice
->UnicodeFiFo
->Head
= TerminalDevice
->UnicodeFiFo
->Tail
;
95 TerminalDevice
->EfiKeyFiFo
->Head
= TerminalDevice
->EfiKeyFiFo
->Tail
;
96 TerminalDevice
->EfiKeyFiFoForNotify
->Head
= TerminalDevice
->EfiKeyFiFoForNotify
->Tail
;
98 if (EFI_ERROR (Status
)) {
99 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
100 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
101 (EFI_PERIPHERAL_REMOTE_CONSOLE
| EFI_P_EC_CONTROLLER_ERROR
),
102 TerminalDevice
->DevicePath
110 Implements EFI_SIMPLE_TEXT_INPUT_PROTOCOL.ReadKeyStroke().
112 @param This Indicates the calling context.
113 @param Key A pointer to a buffer that is filled in with the
114 keystroke information for the key that was sent
117 @retval EFI_SUCCESS The keystroke information is returned successfully.
118 @retval EFI_NOT_READY There is no keystroke data available.
119 @retval EFI_DEVICE_ERROR The dependent serial device encounters error.
124 TerminalConInReadKeyStroke (
125 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
126 OUT EFI_INPUT_KEY
*Key
129 TERMINAL_DEV
*TerminalDevice
;
131 EFI_KEY_DATA KeyData
;
134 // get TERMINAL_DEV from "This" parameter.
136 TerminalDevice
= TERMINAL_CON_IN_DEV_FROM_THIS (This
);
138 Status
= ReadKeyStrokeWorker (TerminalDevice
, &KeyData
);
139 if (EFI_ERROR (Status
)) {
143 CopyMem (Key
, &KeyData
.Key
, sizeof (EFI_INPUT_KEY
));
150 Check if the key already has been registered.
152 If both RegsiteredData and InputData is NULL, then ASSERT().
154 @param RegsiteredData A pointer to a buffer that is filled in with the
155 keystroke state data for the key that was
157 @param InputData A pointer to a buffer that is filled in with the
158 keystroke state data for the key that was
161 @retval TRUE Key be pressed matches a registered key.
162 @retval FALSE Match failed.
167 IN EFI_KEY_DATA
*RegsiteredData
,
168 IN EFI_KEY_DATA
*InputData
171 ASSERT (RegsiteredData
!= NULL
&& InputData
!= NULL
);
173 if ((RegsiteredData
->Key
.ScanCode
!= InputData
->Key
.ScanCode
) ||
174 (RegsiteredData
->Key
.UnicodeChar
!= InputData
->Key
.UnicodeChar
)) {
184 Event notification function for EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx event
185 Signal the event if there is key available
187 @param Event Indicates the event that invoke this function.
188 @param Context Indicates the calling context.
193 TerminalConInWaitForKeyEx (
198 TerminalConInWaitForKey (Event
, Context
);
202 // Simple Text Input Ex protocol functions
206 Reset the input device and optionally run diagnostics
208 @param This Protocol instance pointer.
209 @param ExtendedVerification Driver may perform diagnostics on reset.
211 @retval EFI_SUCCESS The device was reset.
212 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
218 TerminalConInResetEx (
219 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
220 IN BOOLEAN ExtendedVerification
224 TERMINAL_DEV
*TerminalDevice
;
226 TerminalDevice
= TERMINAL_CON_IN_EX_DEV_FROM_THIS (This
);
228 Status
= TerminalDevice
->SimpleInput
.Reset (&TerminalDevice
->SimpleInput
, ExtendedVerification
);
229 if (EFI_ERROR (Status
)) {
230 return EFI_DEVICE_ERROR
;
239 Reads the next keystroke from the input device. The WaitForKey Event can
240 be used to test for existence of a keystroke via WaitForEvent () call.
242 @param This Protocol instance pointer.
243 @param KeyData A pointer to a buffer that is filled in with the
244 keystroke state data for the key that was
247 @retval EFI_SUCCESS The keystroke information was returned.
248 @retval EFI_NOT_READY There was no keystroke data available.
249 @retval EFI_DEVICE_ERROR The keystroke information was not returned due
251 @retval EFI_INVALID_PARAMETER KeyData is NULL.
256 TerminalConInReadKeyStrokeEx (
257 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
258 OUT EFI_KEY_DATA
*KeyData
261 TERMINAL_DEV
*TerminalDevice
;
263 if (KeyData
== NULL
) {
264 return EFI_INVALID_PARAMETER
;
267 TerminalDevice
= TERMINAL_CON_IN_EX_DEV_FROM_THIS (This
);
269 return ReadKeyStrokeWorker (TerminalDevice
, KeyData
);
275 Set certain state for the input device.
277 @param This Protocol instance pointer.
278 @param KeyToggleState A pointer to the EFI_KEY_TOGGLE_STATE to set the
279 state for the input device.
281 @retval EFI_SUCCESS The device state was set successfully.
282 @retval EFI_DEVICE_ERROR The device is not functioning correctly and
283 could not have the setting adjusted.
284 @retval EFI_UNSUPPORTED The device does not have the ability to set its
286 @retval EFI_INVALID_PARAMETER KeyToggleState is NULL.
291 TerminalConInSetState (
292 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
293 IN EFI_KEY_TOGGLE_STATE
*KeyToggleState
296 if (KeyToggleState
== NULL
) {
297 return EFI_INVALID_PARAMETER
;
300 if ((*KeyToggleState
& EFI_TOGGLE_STATE_VALID
) != EFI_TOGGLE_STATE_VALID
) {
301 return EFI_UNSUPPORTED
;
309 Register a notification function for a particular keystroke for the input device.
311 @param This Protocol instance pointer.
312 @param KeyData A pointer to a buffer that is filled in with
313 the keystroke information for the key that was
314 pressed. If KeyData.Key, KeyData.KeyState.KeyToggleState
315 and KeyData.KeyState.KeyShiftState are 0, then any incomplete
316 keystroke will trigger a notification of the KeyNotificationFunction.
317 @param KeyNotificationFunction Points to the function to be called when the key
318 sequence is typed specified by KeyData. This notification function
319 should be called at <=TPL_CALLBACK.
320 @param NotifyHandle Points to the unique handle assigned to the
321 registered notification.
323 @retval EFI_SUCCESS The notification function was registered
325 @retval EFI_OUT_OF_RESOURCES Unable to allocate resources for necessary data
327 @retval EFI_INVALID_PARAMETER KeyData or NotifyHandle is NULL.
332 TerminalConInRegisterKeyNotify (
333 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
334 IN EFI_KEY_DATA
*KeyData
,
335 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction
,
336 OUT VOID
**NotifyHandle
339 TERMINAL_DEV
*TerminalDevice
;
340 TERMINAL_CONSOLE_IN_EX_NOTIFY
*NewNotify
;
342 LIST_ENTRY
*NotifyList
;
343 TERMINAL_CONSOLE_IN_EX_NOTIFY
*CurrentNotify
;
345 if (KeyData
== NULL
|| NotifyHandle
== NULL
|| KeyNotificationFunction
== NULL
) {
346 return EFI_INVALID_PARAMETER
;
349 TerminalDevice
= TERMINAL_CON_IN_EX_DEV_FROM_THIS (This
);
352 // Return EFI_SUCCESS if the (KeyData, NotificationFunction) is already registered.
354 NotifyList
= &TerminalDevice
->NotifyList
;
355 for (Link
= GetFirstNode (NotifyList
); !IsNull (NotifyList
,Link
); Link
= GetNextNode (NotifyList
,Link
)) {
358 TERMINAL_CONSOLE_IN_EX_NOTIFY
,
360 TERMINAL_CONSOLE_IN_EX_NOTIFY_SIGNATURE
362 if (IsKeyRegistered (&CurrentNotify
->KeyData
, KeyData
)) {
363 if (CurrentNotify
->KeyNotificationFn
== KeyNotificationFunction
) {
364 *NotifyHandle
= CurrentNotify
;
371 // Allocate resource to save the notification function
373 NewNotify
= (TERMINAL_CONSOLE_IN_EX_NOTIFY
*) AllocateZeroPool (sizeof (TERMINAL_CONSOLE_IN_EX_NOTIFY
));
374 if (NewNotify
== NULL
) {
375 return EFI_OUT_OF_RESOURCES
;
378 NewNotify
->Signature
= TERMINAL_CONSOLE_IN_EX_NOTIFY_SIGNATURE
;
379 NewNotify
->KeyNotificationFn
= KeyNotificationFunction
;
380 CopyMem (&NewNotify
->KeyData
, KeyData
, sizeof (EFI_KEY_DATA
));
381 InsertTailList (&TerminalDevice
->NotifyList
, &NewNotify
->NotifyEntry
);
383 *NotifyHandle
= NewNotify
;
390 Remove a registered notification function from a particular keystroke.
392 @param This Protocol instance pointer.
393 @param NotificationHandle The handle of the notification function being
396 @retval EFI_SUCCESS The notification function was unregistered
398 @retval EFI_INVALID_PARAMETER The NotificationHandle is invalid.
403 TerminalConInUnregisterKeyNotify (
404 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
405 IN VOID
*NotificationHandle
408 TERMINAL_DEV
*TerminalDevice
;
410 TERMINAL_CONSOLE_IN_EX_NOTIFY
*CurrentNotify
;
411 LIST_ENTRY
*NotifyList
;
413 if (NotificationHandle
== NULL
) {
414 return EFI_INVALID_PARAMETER
;
417 TerminalDevice
= TERMINAL_CON_IN_EX_DEV_FROM_THIS (This
);
419 NotifyList
= &TerminalDevice
->NotifyList
;
420 for (Link
= GetFirstNode (NotifyList
); !IsNull (NotifyList
,Link
); Link
= GetNextNode (NotifyList
,Link
)) {
423 TERMINAL_CONSOLE_IN_EX_NOTIFY
,
425 TERMINAL_CONSOLE_IN_EX_NOTIFY_SIGNATURE
427 if (CurrentNotify
== NotificationHandle
) {
429 // Remove the notification function from NotifyList and free resources
431 RemoveEntryList (&CurrentNotify
->NotifyEntry
);
433 gBS
->FreePool (CurrentNotify
);
439 // Can not find the matching entry in database.
441 return EFI_INVALID_PARAMETER
;
445 Translate raw data into Unicode (according to different encode), and
446 translate Unicode into key information. (according to different standard).
448 @param TerminalDevice Terminal driver private structure.
452 TranslateRawDataToEfiKey (
453 IN TERMINAL_DEV
*TerminalDevice
456 switch (TerminalDevice
->TerminalType
) {
458 case TerminalTypePcAnsi
:
459 case TerminalTypeVt100
:
460 case TerminalTypeVt100Plus
:
461 case TerminalTypeTtyTerm
:
462 AnsiRawDataToUnicode (TerminalDevice
);
463 UnicodeToEfiKey (TerminalDevice
);
466 case TerminalTypeVtUtf8
:
468 // Process all the raw data in the RawFIFO,
469 // put the processed key into UnicodeFIFO.
471 VTUTF8RawDataToUnicode (TerminalDevice
);
474 // Translate all the Unicode data in the UnicodeFIFO to Efi key,
475 // then put into EfiKeyFIFO.
477 UnicodeToEfiKey (TerminalDevice
);
484 Event notification function for EFI_SIMPLE_TEXT_INPUT_PROTOCOL.WaitForKey event
485 Signal the event if there is key available
487 @param Event Indicates the event that invoke this function.
488 @param Context Indicates the calling context.
493 TerminalConInWaitForKey (
499 // Someone is waiting on the keystroke event, if there's
500 // a key pending, signal the event
502 if (!IsEfiKeyFiFoEmpty ((TERMINAL_DEV
*) Context
)) {
504 gBS
->SignalEvent (Event
);
509 Timer handler to poll the key from serial.
511 @param Event Indicates the event that invoke this function.
512 @param Context Indicates the calling context.
516 TerminalConInTimerHandler (
522 TERMINAL_DEV
*TerminalDevice
;
525 EFI_SERIAL_IO_MODE
*Mode
;
526 EFI_SERIAL_IO_PROTOCOL
*SerialIo
;
527 UINTN SerialInTimeOut
;
529 TerminalDevice
= (TERMINAL_DEV
*) Context
;
531 SerialIo
= TerminalDevice
->SerialIo
;
532 if (SerialIo
== NULL
) {
536 // if current timeout value for serial device is not identical with
537 // the value saved in TERMINAL_DEV structure, then recalculate the
538 // timeout value again and set serial attribute according to this value.
540 Mode
= SerialIo
->Mode
;
541 if (Mode
->Timeout
!= TerminalDevice
->SerialInTimeOut
) {
544 if (Mode
->BaudRate
!= 0) {
546 // According to BAUD rate to calculate the timeout value.
548 SerialInTimeOut
= (1 + Mode
->DataBits
+ Mode
->StopBits
) * 2 * 1000000 / (UINTN
) Mode
->BaudRate
;
551 Status
= SerialIo
->SetAttributes (
554 Mode
->ReceiveFifoDepth
,
555 (UINT32
) SerialInTimeOut
,
556 (EFI_PARITY_TYPE
) (Mode
->Parity
),
557 (UINT8
) Mode
->DataBits
,
558 (EFI_STOP_BITS_TYPE
) (Mode
->StopBits
)
561 if (EFI_ERROR (Status
)) {
562 TerminalDevice
->SerialInTimeOut
= 0;
564 TerminalDevice
->SerialInTimeOut
= SerialInTimeOut
;
568 // Check whether serial buffer is empty.
569 // Skip the key transfer loop only if the SerialIo protocol instance
570 // successfully reports EFI_SERIAL_INPUT_BUFFER_EMPTY.
572 Status
= SerialIo
->GetControl (SerialIo
, &Control
);
573 if (EFI_ERROR (Status
) || ((Control
& EFI_SERIAL_INPUT_BUFFER_EMPTY
) == 0)) {
575 // Fetch all the keys in the serial buffer,
576 // and insert the byte stream into RawFIFO.
578 while (!IsRawFiFoFull (TerminalDevice
)) {
580 Status
= GetOneKeyFromSerial (TerminalDevice
->SerialIo
, &Input
);
582 if (EFI_ERROR (Status
)) {
583 if (Status
== EFI_DEVICE_ERROR
) {
584 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
585 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
586 (EFI_PERIPHERAL_REMOTE_CONSOLE
| EFI_P_EC_INPUT_ERROR
),
587 TerminalDevice
->DevicePath
593 RawFiFoInsertOneKey (TerminalDevice
, Input
);
598 // Translate all the raw data in RawFIFO into EFI Key,
599 // according to different terminal type supported.
601 TranslateRawDataToEfiKey (TerminalDevice
);
607 @param Event Indicates the event that invoke this function.
608 @param Context Indicates the calling context.
612 KeyNotifyProcessHandler (
618 TERMINAL_DEV
*TerminalDevice
;
620 EFI_KEY_DATA KeyData
;
622 LIST_ENTRY
*NotifyList
;
623 TERMINAL_CONSOLE_IN_EX_NOTIFY
*CurrentNotify
;
626 TerminalDevice
= (TERMINAL_DEV
*) Context
;
629 // Invoke notification functions.
631 NotifyList
= &TerminalDevice
->NotifyList
;
634 // Enter critical section
636 OldTpl
= gBS
->RaiseTPL (TPL_NOTIFY
);
637 HasKey
= EfiKeyFiFoForNotifyRemoveOneKey (TerminalDevice
->EfiKeyFiFoForNotify
, &Key
);
638 CopyMem (&KeyData
.Key
, &Key
, sizeof (EFI_INPUT_KEY
));
639 KeyData
.KeyState
.KeyShiftState
= 0;
640 KeyData
.KeyState
.KeyToggleState
= 0;
642 // Leave critical section
644 gBS
->RestoreTPL (OldTpl
);
648 for (Link
= GetFirstNode (NotifyList
); !IsNull (NotifyList
, Link
); Link
= GetNextNode (NotifyList
, Link
)) {
649 CurrentNotify
= CR (Link
, TERMINAL_CONSOLE_IN_EX_NOTIFY
, NotifyEntry
, TERMINAL_CONSOLE_IN_EX_NOTIFY_SIGNATURE
);
650 if (IsKeyRegistered (&CurrentNotify
->KeyData
, &KeyData
)) {
651 CurrentNotify
->KeyNotificationFn (&KeyData
);
658 Get one key out of serial buffer.
660 @param SerialIo Serial I/O protocol attached to the serial device.
661 @param Output The fetched key.
663 @retval EFI_NOT_READY If serial buffer is empty.
664 @retval EFI_DEVICE_ERROR If reading serial buffer encounter error.
665 @retval EFI_SUCCESS If reading serial buffer successfully, put
666 the fetched key to the parameter output.
670 GetOneKeyFromSerial (
671 EFI_SERIAL_IO_PROTOCOL
*SerialIo
,
682 // Read one key from serial I/O device.
684 Status
= SerialIo
->Read (SerialIo
, &Size
, Output
);
686 if (EFI_ERROR (Status
)) {
688 if (Status
== EFI_TIMEOUT
) {
689 return EFI_NOT_READY
;
692 return EFI_DEVICE_ERROR
;
697 return EFI_NOT_READY
;
704 Insert one byte raw data into the Raw Data FIFO.
706 @param TerminalDevice Terminal driver private structure.
707 @param Input The key will be input.
709 @retval TRUE If insert successfully.
710 @retval FALSE If Raw Data buffer is full before key insertion,
715 RawFiFoInsertOneKey (
716 TERMINAL_DEV
*TerminalDevice
,
722 Tail
= TerminalDevice
->RawFiFo
->Tail
;
724 if (IsRawFiFoFull (TerminalDevice
)) {
731 TerminalDevice
->RawFiFo
->Data
[Tail
] = Input
;
733 TerminalDevice
->RawFiFo
->Tail
= (UINT8
) ((Tail
+ 1) % (RAW_FIFO_MAX_NUMBER
+ 1));
739 Remove one pre-fetched key out of the Raw Data FIFO.
741 @param TerminalDevice Terminal driver private structure.
742 @param Output The key will be removed.
744 @retval TRUE If insert successfully.
745 @retval FALSE If Raw Data FIFO buffer is empty before remove operation.
749 RawFiFoRemoveOneKey (
750 TERMINAL_DEV
*TerminalDevice
,
756 Head
= TerminalDevice
->RawFiFo
->Head
;
758 if (IsRawFiFoEmpty (TerminalDevice
)) {
766 *Output
= TerminalDevice
->RawFiFo
->Data
[Head
];
768 TerminalDevice
->RawFiFo
->Head
= (UINT8
) ((Head
+ 1) % (RAW_FIFO_MAX_NUMBER
+ 1));
774 Clarify whether Raw Data FIFO buffer is empty.
776 @param TerminalDevice Terminal driver private structure
778 @retval TRUE If Raw Data FIFO buffer is empty.
779 @retval FALSE If Raw Data FIFO buffer is not empty.
784 TERMINAL_DEV
*TerminalDevice
787 if (TerminalDevice
->RawFiFo
->Head
== TerminalDevice
->RawFiFo
->Tail
) {
795 Clarify whether Raw Data FIFO buffer is full.
797 @param TerminalDevice Terminal driver private structure
799 @retval TRUE If Raw Data FIFO buffer is full.
800 @retval FALSE If Raw Data FIFO buffer is not full.
805 TERMINAL_DEV
*TerminalDevice
811 Tail
= TerminalDevice
->RawFiFo
->Tail
;
812 Head
= TerminalDevice
->RawFiFo
->Head
;
814 if (((Tail
+ 1) % (RAW_FIFO_MAX_NUMBER
+ 1)) == Head
) {
823 Insert one pre-fetched key into the FIFO buffer.
825 @param EfiKeyFiFo Pointer to instance of EFI_KEY_FIFO.
826 @param Input The key will be input.
828 @retval TRUE If insert successfully.
829 @retval FALSE If FIFO buffer is full before key insertion,
834 EfiKeyFiFoForNotifyInsertOneKey (
835 EFI_KEY_FIFO
*EfiKeyFiFo
,
841 Tail
= EfiKeyFiFo
->Tail
;
843 if (IsEfiKeyFiFoForNotifyFull (EfiKeyFiFo
)) {
850 CopyMem (&EfiKeyFiFo
->Data
[Tail
], Input
, sizeof (EFI_INPUT_KEY
));
852 EfiKeyFiFo
->Tail
= (UINT8
) ((Tail
+ 1) % (FIFO_MAX_NUMBER
+ 1));
858 Remove one pre-fetched key out of the FIFO buffer.
860 @param EfiKeyFiFo Pointer to instance of EFI_KEY_FIFO.
861 @param Output The key will be removed.
863 @retval TRUE If remove successfully.
864 @retval FALSE If FIFO buffer is empty before remove operation.
868 EfiKeyFiFoForNotifyRemoveOneKey (
869 EFI_KEY_FIFO
*EfiKeyFiFo
,
870 EFI_INPUT_KEY
*Output
875 Head
= EfiKeyFiFo
->Head
;
876 ASSERT (Head
< FIFO_MAX_NUMBER
+ 1);
878 if (IsEfiKeyFiFoForNotifyEmpty (EfiKeyFiFo
)) {
882 Output
->ScanCode
= SCAN_NULL
;
883 Output
->UnicodeChar
= 0;
887 CopyMem (Output
, &EfiKeyFiFo
->Data
[Head
], sizeof (EFI_INPUT_KEY
));
889 EfiKeyFiFo
->Head
= (UINT8
) ((Head
+ 1) % (FIFO_MAX_NUMBER
+ 1));
895 Clarify whether FIFO buffer is empty.
897 @param EfiKeyFiFo Pointer to instance of EFI_KEY_FIFO.
899 @retval TRUE If FIFO buffer is empty.
900 @retval FALSE If FIFO buffer is not empty.
904 IsEfiKeyFiFoForNotifyEmpty (
905 EFI_KEY_FIFO
*EfiKeyFiFo
908 if (EfiKeyFiFo
->Head
== EfiKeyFiFo
->Tail
) {
916 Clarify whether FIFO buffer is full.
918 @param EfiKeyFiFo Pointer to instance of EFI_KEY_FIFO.
920 @retval TRUE If FIFO buffer is full.
921 @retval FALSE If FIFO buffer is not full.
925 IsEfiKeyFiFoForNotifyFull (
926 EFI_KEY_FIFO
*EfiKeyFiFo
932 Tail
= EfiKeyFiFo
->Tail
;
933 Head
= EfiKeyFiFo
->Head
;
935 if (((Tail
+ 1) % (FIFO_MAX_NUMBER
+ 1)) == Head
) {
943 Insert one pre-fetched key into the FIFO buffer.
945 @param TerminalDevice Terminal driver private structure.
946 @param Key The key will be input.
948 @retval TRUE If insert successfully.
949 @retval FALSE If FIFO buffer is full before key insertion,
954 EfiKeyFiFoInsertOneKey (
955 TERMINAL_DEV
*TerminalDevice
,
961 LIST_ENTRY
*NotifyList
;
962 TERMINAL_CONSOLE_IN_EX_NOTIFY
*CurrentNotify
;
963 EFI_KEY_DATA KeyData
;
965 Tail
= TerminalDevice
->EfiKeyFiFo
->Tail
;
967 CopyMem (&KeyData
.Key
, Key
, sizeof (EFI_INPUT_KEY
));
968 KeyData
.KeyState
.KeyShiftState
= 0;
969 KeyData
.KeyState
.KeyToggleState
= 0;
972 // Signal KeyNotify process event if this key pressed matches any key registered.
974 NotifyList
= &TerminalDevice
->NotifyList
;
975 for (Link
= GetFirstNode (NotifyList
); !IsNull (NotifyList
,Link
); Link
= GetNextNode (NotifyList
,Link
)) {
978 TERMINAL_CONSOLE_IN_EX_NOTIFY
,
980 TERMINAL_CONSOLE_IN_EX_NOTIFY_SIGNATURE
982 if (IsKeyRegistered (&CurrentNotify
->KeyData
, &KeyData
)) {
984 // The key notification function needs to run at TPL_CALLBACK
985 // while current TPL is TPL_NOTIFY. It will be invoked in
986 // KeyNotifyProcessHandler() which runs at TPL_CALLBACK.
988 EfiKeyFiFoForNotifyInsertOneKey (TerminalDevice
->EfiKeyFiFoForNotify
, Key
);
989 gBS
->SignalEvent (TerminalDevice
->KeyNotifyProcessEvent
);
993 if (IsEfiKeyFiFoFull (TerminalDevice
)) {
995 // Efi Key FIFO is full
1000 CopyMem (&TerminalDevice
->EfiKeyFiFo
->Data
[Tail
], Key
, sizeof (EFI_INPUT_KEY
));
1002 TerminalDevice
->EfiKeyFiFo
->Tail
= (UINT8
) ((Tail
+ 1) % (FIFO_MAX_NUMBER
+ 1));
1008 Remove one pre-fetched key out of the FIFO buffer.
1010 @param TerminalDevice Terminal driver private structure.
1011 @param Output The key will be removed.
1013 @retval TRUE If insert successfully.
1014 @retval FALSE If FIFO buffer is empty before remove operation.
1018 EfiKeyFiFoRemoveOneKey (
1019 TERMINAL_DEV
*TerminalDevice
,
1020 EFI_INPUT_KEY
*Output
1025 Head
= TerminalDevice
->EfiKeyFiFo
->Head
;
1026 ASSERT (Head
< FIFO_MAX_NUMBER
+ 1);
1028 if (IsEfiKeyFiFoEmpty (TerminalDevice
)) {
1032 Output
->ScanCode
= SCAN_NULL
;
1033 Output
->UnicodeChar
= 0;
1037 CopyMem (Output
, &TerminalDevice
->EfiKeyFiFo
->Data
[Head
], sizeof (EFI_INPUT_KEY
));
1039 TerminalDevice
->EfiKeyFiFo
->Head
= (UINT8
) ((Head
+ 1) % (FIFO_MAX_NUMBER
+ 1));
1045 Clarify whether FIFO buffer is empty.
1047 @param TerminalDevice Terminal driver private structure
1049 @retval TRUE If FIFO buffer is empty.
1050 @retval FALSE If FIFO buffer is not empty.
1055 TERMINAL_DEV
*TerminalDevice
1058 if (TerminalDevice
->EfiKeyFiFo
->Head
== TerminalDevice
->EfiKeyFiFo
->Tail
) {
1066 Clarify whether FIFO buffer is full.
1068 @param TerminalDevice Terminal driver private structure
1070 @retval TRUE If FIFO buffer is full.
1071 @retval FALSE If FIFO buffer is not full.
1076 TERMINAL_DEV
*TerminalDevice
1082 Tail
= TerminalDevice
->EfiKeyFiFo
->Tail
;
1083 Head
= TerminalDevice
->EfiKeyFiFo
->Head
;
1085 if (((Tail
+ 1) % (FIFO_MAX_NUMBER
+ 1)) == Head
) {
1094 Insert one pre-fetched key into the Unicode FIFO buffer.
1096 @param TerminalDevice Terminal driver private structure.
1097 @param Input The key will be input.
1099 @retval TRUE If insert successfully.
1100 @retval FALSE If Unicode FIFO buffer is full before key insertion,
1101 and the key is lost.
1105 UnicodeFiFoInsertOneKey (
1106 TERMINAL_DEV
*TerminalDevice
,
1112 Tail
= TerminalDevice
->UnicodeFiFo
->Tail
;
1113 ASSERT (Tail
< FIFO_MAX_NUMBER
+ 1);
1116 if (IsUnicodeFiFoFull (TerminalDevice
)) {
1118 // Unicode FIFO is full
1123 TerminalDevice
->UnicodeFiFo
->Data
[Tail
] = Input
;
1125 TerminalDevice
->UnicodeFiFo
->Tail
= (UINT8
) ((Tail
+ 1) % (FIFO_MAX_NUMBER
+ 1));
1131 Remove one pre-fetched key out of the Unicode FIFO buffer.
1132 The caller should guarantee that Unicode FIFO buffer is not empty
1133 by IsUnicodeFiFoEmpty ().
1135 @param TerminalDevice Terminal driver private structure.
1136 @param Output The key will be removed.
1140 UnicodeFiFoRemoveOneKey (
1141 TERMINAL_DEV
*TerminalDevice
,
1147 Head
= TerminalDevice
->UnicodeFiFo
->Head
;
1148 ASSERT (Head
< FIFO_MAX_NUMBER
+ 1);
1150 *Output
= TerminalDevice
->UnicodeFiFo
->Data
[Head
];
1152 TerminalDevice
->UnicodeFiFo
->Head
= (UINT8
) ((Head
+ 1) % (FIFO_MAX_NUMBER
+ 1));
1156 Clarify whether Unicode FIFO buffer is empty.
1158 @param TerminalDevice Terminal driver private structure
1160 @retval TRUE If Unicode FIFO buffer is empty.
1161 @retval FALSE If Unicode FIFO buffer is not empty.
1165 IsUnicodeFiFoEmpty (
1166 TERMINAL_DEV
*TerminalDevice
1169 if (TerminalDevice
->UnicodeFiFo
->Head
== TerminalDevice
->UnicodeFiFo
->Tail
) {
1177 Clarify whether Unicode FIFO buffer is full.
1179 @param TerminalDevice Terminal driver private structure
1181 @retval TRUE If Unicode FIFO buffer is full.
1182 @retval FALSE If Unicode FIFO buffer is not full.
1187 TERMINAL_DEV
*TerminalDevice
1193 Tail
= TerminalDevice
->UnicodeFiFo
->Tail
;
1194 Head
= TerminalDevice
->UnicodeFiFo
->Head
;
1196 if (((Tail
+ 1) % (FIFO_MAX_NUMBER
+ 1)) == Head
) {
1206 Update the Unicode characters from a terminal input device into EFI Keys FIFO.
1208 @param TerminalDevice The terminal device to use to translate raw input into EFI Keys
1212 UnicodeToEfiKeyFlushState (
1213 IN TERMINAL_DEV
*TerminalDevice
1219 InputState
= TerminalDevice
->InputState
;
1221 if (IsEfiKeyFiFoFull (TerminalDevice
)) {
1225 if ((InputState
& INPUT_STATE_ESC
) != 0) {
1226 Key
.ScanCode
= SCAN_ESC
;
1227 Key
.UnicodeChar
= 0;
1228 EfiKeyFiFoInsertOneKey (TerminalDevice
, &Key
);
1231 if ((InputState
& INPUT_STATE_CSI
) != 0) {
1232 Key
.ScanCode
= SCAN_NULL
;
1233 Key
.UnicodeChar
= CSI
;
1234 EfiKeyFiFoInsertOneKey (TerminalDevice
, &Key
);
1237 if ((InputState
& INPUT_STATE_LEFTOPENBRACKET
) != 0) {
1238 Key
.ScanCode
= SCAN_NULL
;
1239 Key
.UnicodeChar
= LEFTOPENBRACKET
;
1240 EfiKeyFiFoInsertOneKey (TerminalDevice
, &Key
);
1243 if ((InputState
& INPUT_STATE_O
) != 0) {
1244 Key
.ScanCode
= SCAN_NULL
;
1245 Key
.UnicodeChar
= 'O';
1246 EfiKeyFiFoInsertOneKey (TerminalDevice
, &Key
);
1249 if ((InputState
& INPUT_STATE_2
) != 0) {
1250 Key
.ScanCode
= SCAN_NULL
;
1251 Key
.UnicodeChar
= '2';
1252 EfiKeyFiFoInsertOneKey (TerminalDevice
, &Key
);
1256 // Cancel the timer.
1259 TerminalDevice
->TwoSecondTimeOut
,
1264 TerminalDevice
->InputState
= INPUT_STATE_DEFAULT
;
1269 Converts a stream of Unicode characters from a terminal input device into EFI Keys that
1270 can be read through the Simple Input Protocol.
1272 The table below shows the keyboard input mappings that this function supports.
1273 If the ESC sequence listed in one of the columns is presented, then it is translated
1274 into the corresponding EFI Scan Code. If a matching sequence is not found, then the raw
1275 key strokes are converted into EFI Keys.
1277 2 seconds are allowed for an ESC sequence to be completed. If the ESC sequence is not
1278 completed in 2 seconds, then the raw key strokes of the partial ESC sequence are
1279 converted into EFI Keys.
1280 There is one special input sequence that will force the system to reset.
1281 This is ESC R ESC r ESC R.
1283 Note: current implementation support terminal types include: PC ANSI, VT100+/VTUTF8, VT100.
1284 The table below is not same with UEFI Spec 2.3 Appendix B Table 201(not support ANSI X3.64 /
1285 DEC VT200-500 and extra support PC ANSI, VT100)since UEFI Table 201 is just an example.
1287 Symbols used in table below
1288 ===========================
1294 +=========+======+===========+==========+==========+
1295 | | EFI | UEFI 2.0 | | |
1296 | | Scan | | VT100+ | |
1297 | KEY | Code | PC ANSI | VTUTF8 | VT100 |
1298 +=========+======+===========+==========+==========+
1299 | NULL | 0x00 | | | |
1300 | UP | 0x01 | ESC [ A | ESC [ A | ESC [ A |
1301 | DOWN | 0x02 | ESC [ B | ESC [ B | ESC [ B |
1302 | RIGHT | 0x03 | ESC [ C | ESC [ C | ESC [ C |
1303 | LEFT | 0x04 | ESC [ D | ESC [ D | ESC [ D |
1304 | HOME | 0x05 | ESC [ H | ESC h | ESC [ H |
1305 | END | 0x06 | ESC [ F | ESC k | ESC [ K |
1306 | INSERT | 0x07 | ESC [ @ | ESC + | ESC [ @ |
1307 | | | ESC [ L | | ESC [ L |
1308 | DELETE | 0x08 | ESC [ X | ESC - | ESC [ P |
1309 | PG UP | 0x09 | ESC [ I | ESC ? | ESC [ V |
1311 | PG DOWN | 0x0A | ESC [ G | ESC / | ESC [ U |
1313 | F1 | 0x0B | ESC [ M | ESC 1 | ESC O P |
1314 | F2 | 0x0C | ESC [ N | ESC 2 | ESC O Q |
1315 | F3 | 0x0D | ESC [ O | ESC 3 | ESC O w |
1316 | F4 | 0x0E | ESC [ P | ESC 4 | ESC O x |
1317 | F5 | 0x0F | ESC [ Q | ESC 5 | ESC O t |
1318 | F6 | 0x10 | ESC [ R | ESC 6 | ESC O u |
1319 | F7 | 0x11 | ESC [ S | ESC 7 | ESC O q |
1320 | F8 | 0x12 | ESC [ T | ESC 8 | ESC O r |
1321 | F9 | 0x13 | ESC [ U | ESC 9 | ESC O p |
1322 | F10 | 0x14 | ESC [ V | ESC 0 | ESC O M |
1323 | Escape | 0x17 | ESC | ESC | ESC |
1324 | F11 | 0x15 | | ESC ! | |
1325 | F12 | 0x16 | | ESC @ | |
1326 +=========+======+===========+==========+==========+
1330 ESC R ESC r ESC R = Reset System
1332 @param TerminalDevice The terminal device to use to translate raw input into EFI Keys
1337 IN TERMINAL_DEV
*TerminalDevice
1341 EFI_STATUS TimerStatus
;
1344 BOOLEAN SetDefaultResetState
;
1346 TimerStatus
= gBS
->CheckEvent (TerminalDevice
->TwoSecondTimeOut
);
1348 if (!EFI_ERROR (TimerStatus
)) {
1349 UnicodeToEfiKeyFlushState (TerminalDevice
);
1350 TerminalDevice
->ResetState
= RESET_STATE_DEFAULT
;
1353 while (!IsUnicodeFiFoEmpty (TerminalDevice
) && !IsEfiKeyFiFoFull (TerminalDevice
)) {
1355 if (TerminalDevice
->InputState
!= INPUT_STATE_DEFAULT
) {
1357 // Check to see if the 2 seconds timer has expired
1359 TimerStatus
= gBS
->CheckEvent (TerminalDevice
->TwoSecondTimeOut
);
1360 if (!EFI_ERROR (TimerStatus
)) {
1361 UnicodeToEfiKeyFlushState (TerminalDevice
);
1362 TerminalDevice
->ResetState
= RESET_STATE_DEFAULT
;
1367 // Fetch one Unicode character from the Unicode FIFO
1369 UnicodeFiFoRemoveOneKey (TerminalDevice
, &UnicodeChar
);
1371 SetDefaultResetState
= TRUE
;
1373 switch (TerminalDevice
->InputState
) {
1374 case INPUT_STATE_DEFAULT
:
1378 case INPUT_STATE_ESC
:
1380 if (UnicodeChar
== LEFTOPENBRACKET
) {
1381 TerminalDevice
->InputState
|= INPUT_STATE_LEFTOPENBRACKET
;
1382 TerminalDevice
->ResetState
= RESET_STATE_DEFAULT
;
1386 if (UnicodeChar
== 'O' && (TerminalDevice
->TerminalType
== TerminalTypeVt100
||
1387 TerminalDevice
->TerminalType
== TerminalTypeTtyTerm
)) {
1388 TerminalDevice
->InputState
|= INPUT_STATE_O
;
1389 TerminalDevice
->ResetState
= RESET_STATE_DEFAULT
;
1393 Key
.ScanCode
= SCAN_NULL
;
1395 if (TerminalDevice
->TerminalType
== TerminalTypeVt100Plus
||
1396 TerminalDevice
->TerminalType
== TerminalTypeVtUtf8
) {
1397 switch (UnicodeChar
) {
1399 Key
.ScanCode
= SCAN_F1
;
1402 Key
.ScanCode
= SCAN_F2
;
1405 Key
.ScanCode
= SCAN_F3
;
1408 Key
.ScanCode
= SCAN_F4
;
1411 Key
.ScanCode
= SCAN_F5
;
1414 Key
.ScanCode
= SCAN_F6
;
1417 Key
.ScanCode
= SCAN_F7
;
1420 Key
.ScanCode
= SCAN_F8
;
1423 Key
.ScanCode
= SCAN_F9
;
1426 Key
.ScanCode
= SCAN_F10
;
1429 Key
.ScanCode
= SCAN_F11
;
1432 Key
.ScanCode
= SCAN_F12
;
1435 Key
.ScanCode
= SCAN_HOME
;
1438 Key
.ScanCode
= SCAN_END
;
1441 Key
.ScanCode
= SCAN_INSERT
;
1444 Key
.ScanCode
= SCAN_DELETE
;
1447 Key
.ScanCode
= SCAN_PAGE_DOWN
;
1450 Key
.ScanCode
= SCAN_PAGE_UP
;
1457 switch (UnicodeChar
) {
1459 if (TerminalDevice
->ResetState
== RESET_STATE_DEFAULT
) {
1460 TerminalDevice
->ResetState
= RESET_STATE_ESC_R
;
1461 SetDefaultResetState
= FALSE
;
1462 } else if (TerminalDevice
->ResetState
== RESET_STATE_ESC_R_ESC_R
) {
1463 gRT
->ResetSystem (EfiResetWarm
, EFI_SUCCESS
, 0, NULL
);
1465 Key
.ScanCode
= SCAN_NULL
;
1468 if (TerminalDevice
->ResetState
== RESET_STATE_ESC_R
) {
1469 TerminalDevice
->ResetState
= RESET_STATE_ESC_R_ESC_R
;
1470 SetDefaultResetState
= FALSE
;
1472 Key
.ScanCode
= SCAN_NULL
;
1478 if (SetDefaultResetState
) {
1479 TerminalDevice
->ResetState
= RESET_STATE_DEFAULT
;
1482 if (Key
.ScanCode
!= SCAN_NULL
) {
1483 Key
.UnicodeChar
= 0;
1484 EfiKeyFiFoInsertOneKey (TerminalDevice
, &Key
);
1485 TerminalDevice
->InputState
= INPUT_STATE_DEFAULT
;
1486 UnicodeToEfiKeyFlushState (TerminalDevice
);
1490 UnicodeToEfiKeyFlushState (TerminalDevice
);
1494 case INPUT_STATE_ESC
| INPUT_STATE_O
:
1496 TerminalDevice
->ResetState
= RESET_STATE_DEFAULT
;
1498 Key
.ScanCode
= SCAN_NULL
;
1500 if (TerminalDevice
->TerminalType
== TerminalTypeVt100
) {
1501 switch (UnicodeChar
) {
1503 Key
.ScanCode
= SCAN_F1
;
1506 Key
.ScanCode
= SCAN_F2
;
1509 Key
.ScanCode
= SCAN_F3
;
1512 Key
.ScanCode
= SCAN_F4
;
1515 Key
.ScanCode
= SCAN_F5
;
1518 Key
.ScanCode
= SCAN_F6
;
1521 Key
.ScanCode
= SCAN_F7
;
1524 Key
.ScanCode
= SCAN_F8
;
1527 Key
.ScanCode
= SCAN_F9
;
1530 Key
.ScanCode
= SCAN_F10
;
1535 } else if (TerminalDevice
->TerminalType
== TerminalTypeTtyTerm
) {
1536 /* Also accept VT100 escape codes for F1-F4, HOME and END for TTY term */
1537 switch (UnicodeChar
) {
1539 Key
.ScanCode
= SCAN_F1
;
1542 Key
.ScanCode
= SCAN_F2
;
1545 Key
.ScanCode
= SCAN_F3
;
1548 Key
.ScanCode
= SCAN_F4
;
1551 Key
.ScanCode
= SCAN_HOME
;
1554 Key
.ScanCode
= SCAN_END
;
1559 if (Key
.ScanCode
!= SCAN_NULL
) {
1560 Key
.UnicodeChar
= 0;
1561 EfiKeyFiFoInsertOneKey (TerminalDevice
, &Key
);
1562 TerminalDevice
->InputState
= INPUT_STATE_DEFAULT
;
1563 UnicodeToEfiKeyFlushState (TerminalDevice
);
1567 UnicodeToEfiKeyFlushState (TerminalDevice
);
1571 case INPUT_STATE_ESC
| INPUT_STATE_LEFTOPENBRACKET
:
1573 TerminalDevice
->ResetState
= RESET_STATE_DEFAULT
;
1575 Key
.ScanCode
= SCAN_NULL
;
1577 if (TerminalDevice
->TerminalType
== TerminalTypePcAnsi
||
1578 TerminalDevice
->TerminalType
== TerminalTypeVt100
||
1579 TerminalDevice
->TerminalType
== TerminalTypeVt100Plus
||
1580 TerminalDevice
->TerminalType
== TerminalTypeVtUtf8
||
1581 TerminalDevice
->TerminalType
== TerminalTypeTtyTerm
) {
1582 switch (UnicodeChar
) {
1584 Key
.ScanCode
= SCAN_UP
;
1587 Key
.ScanCode
= SCAN_DOWN
;
1590 Key
.ScanCode
= SCAN_RIGHT
;
1593 Key
.ScanCode
= SCAN_LEFT
;
1596 if (TerminalDevice
->TerminalType
== TerminalTypePcAnsi
||
1597 TerminalDevice
->TerminalType
== TerminalTypeVt100
||
1598 TerminalDevice
->TerminalType
== TerminalTypeTtyTerm
) {
1599 Key
.ScanCode
= SCAN_HOME
;
1603 if (TerminalDevice
->TerminalType
== TerminalTypePcAnsi
||
1604 TerminalDevice
->TerminalType
== TerminalTypeTtyTerm
) {
1605 Key
.ScanCode
= SCAN_END
;
1609 if (TerminalDevice
->TerminalType
== TerminalTypeVt100
) {
1610 Key
.ScanCode
= SCAN_END
;
1615 if (TerminalDevice
->TerminalType
== TerminalTypePcAnsi
||
1616 TerminalDevice
->TerminalType
== TerminalTypeVt100
) {
1617 Key
.ScanCode
= SCAN_INSERT
;
1621 if (TerminalDevice
->TerminalType
== TerminalTypePcAnsi
) {
1622 Key
.ScanCode
= SCAN_DELETE
;
1626 if (TerminalDevice
->TerminalType
== TerminalTypeVt100
) {
1627 Key
.ScanCode
= SCAN_DELETE
;
1628 } else if (TerminalDevice
->TerminalType
== TerminalTypePcAnsi
) {
1629 Key
.ScanCode
= SCAN_F4
;
1633 if (TerminalDevice
->TerminalType
== TerminalTypePcAnsi
) {
1634 Key
.ScanCode
= SCAN_PAGE_UP
;
1638 if (TerminalDevice
->TerminalType
== TerminalTypePcAnsi
) {
1639 Key
.ScanCode
= SCAN_F10
;
1643 if (TerminalDevice
->TerminalType
== TerminalTypeVt100
) {
1644 Key
.ScanCode
= SCAN_PAGE_UP
;
1648 if (TerminalDevice
->TerminalType
== TerminalTypePcAnsi
) {
1649 Key
.ScanCode
= SCAN_PAGE_DOWN
;
1653 if (TerminalDevice
->TerminalType
== TerminalTypePcAnsi
) {
1654 Key
.ScanCode
= SCAN_F9
;
1658 if (TerminalDevice
->TerminalType
== TerminalTypeVt100
) {
1659 Key
.ScanCode
= SCAN_PAGE_DOWN
;
1663 if (TerminalDevice
->TerminalType
== TerminalTypePcAnsi
) {
1664 Key
.ScanCode
= SCAN_F1
;
1668 if (TerminalDevice
->TerminalType
== TerminalTypePcAnsi
) {
1669 Key
.ScanCode
= SCAN_F2
;
1673 if (TerminalDevice
->TerminalType
== TerminalTypePcAnsi
) {
1674 Key
.ScanCode
= SCAN_F3
;
1678 if (TerminalDevice
->TerminalType
== TerminalTypePcAnsi
) {
1679 Key
.ScanCode
= SCAN_F5
;
1683 if (TerminalDevice
->TerminalType
== TerminalTypePcAnsi
) {
1684 Key
.ScanCode
= SCAN_F6
;
1688 if (TerminalDevice
->TerminalType
== TerminalTypePcAnsi
) {
1689 Key
.ScanCode
= SCAN_F7
;
1693 if (TerminalDevice
->TerminalType
== TerminalTypePcAnsi
) {
1694 Key
.ScanCode
= SCAN_F8
;
1703 * The VT220 escape codes that the TTY terminal accepts all have
1704 * numeric codes, and there are no ambiguous prefixes shared with
1705 * other terminal types.
1707 if (TerminalDevice
->TerminalType
== TerminalTypeTtyTerm
&&
1708 Key
.ScanCode
== SCAN_NULL
&&
1709 UnicodeChar
>= '0' &&
1710 UnicodeChar
<= '9') {
1711 TerminalDevice
->TtyEscapeStr
[0] = UnicodeChar
;
1712 TerminalDevice
->TtyEscapeIndex
= 1;
1713 TerminalDevice
->InputState
|= INPUT_STATE_LEFTOPENBRACKET_2
;
1717 if (Key
.ScanCode
!= SCAN_NULL
) {
1718 Key
.UnicodeChar
= 0;
1719 EfiKeyFiFoInsertOneKey (TerminalDevice
, &Key
);
1720 TerminalDevice
->InputState
= INPUT_STATE_DEFAULT
;
1721 UnicodeToEfiKeyFlushState (TerminalDevice
);
1725 UnicodeToEfiKeyFlushState (TerminalDevice
);
1730 case INPUT_STATE_ESC
| INPUT_STATE_LEFTOPENBRACKET
| INPUT_STATE_LEFTOPENBRACKET_2
:
1732 * Here we handle the VT220 escape codes that we accept. This
1733 * state is only used by the TTY terminal type.
1735 Key
.ScanCode
= SCAN_NULL
;
1736 if (TerminalDevice
->TerminalType
== TerminalTypeTtyTerm
) {
1738 if (UnicodeChar
== '~' && TerminalDevice
->TtyEscapeIndex
<= 2) {
1740 TerminalDevice
->TtyEscapeStr
[TerminalDevice
->TtyEscapeIndex
] = 0; /* Terminate string */
1741 EscCode
= (UINT16
) StrDecimalToUintn(TerminalDevice
->TtyEscapeStr
);
1744 Key
.ScanCode
= SCAN_INSERT
;
1747 Key
.ScanCode
= SCAN_DELETE
;
1750 Key
.ScanCode
= SCAN_PAGE_UP
;
1753 Key
.ScanCode
= SCAN_PAGE_DOWN
;
1760 Key
.ScanCode
= SCAN_F1
+ EscCode
- 11;
1767 Key
.ScanCode
= SCAN_F6
+ EscCode
- 17;
1771 Key
.ScanCode
= SCAN_F11
+ EscCode
- 23;
1776 } else if (TerminalDevice
->TtyEscapeIndex
== 1){
1777 /* 2 character escape code */
1778 TerminalDevice
->TtyEscapeStr
[TerminalDevice
->TtyEscapeIndex
++] = UnicodeChar
;
1782 DEBUG ((EFI_D_ERROR
, "Unexpected state in escape2\n"));
1785 TerminalDevice
->ResetState
= RESET_STATE_DEFAULT
;
1787 if (Key
.ScanCode
!= SCAN_NULL
) {
1788 Key
.UnicodeChar
= 0;
1789 EfiKeyFiFoInsertOneKey (TerminalDevice
, &Key
);
1790 TerminalDevice
->InputState
= INPUT_STATE_DEFAULT
;
1791 UnicodeToEfiKeyFlushState (TerminalDevice
);
1795 UnicodeToEfiKeyFlushState (TerminalDevice
);
1800 // Invalid state. This should never happen.
1804 UnicodeToEfiKeyFlushState (TerminalDevice
);
1809 if (UnicodeChar
== ESC
) {
1810 TerminalDevice
->InputState
= INPUT_STATE_ESC
;
1813 if (UnicodeChar
== CSI
) {
1814 TerminalDevice
->InputState
= INPUT_STATE_CSI
;
1817 if (TerminalDevice
->InputState
!= INPUT_STATE_DEFAULT
) {
1818 Status
= gBS
->SetTimer(
1819 TerminalDevice
->TwoSecondTimeOut
,
1823 ASSERT_EFI_ERROR (Status
);
1827 if (SetDefaultResetState
) {
1828 TerminalDevice
->ResetState
= RESET_STATE_DEFAULT
;
1831 if (UnicodeChar
== DEL
) {
1832 if (TerminalDevice
->TerminalType
== TerminalTypeTtyTerm
) {
1833 Key
.ScanCode
= SCAN_NULL
;
1834 Key
.UnicodeChar
= CHAR_BACKSPACE
;
1837 Key
.ScanCode
= SCAN_DELETE
;
1838 Key
.UnicodeChar
= 0;
1841 Key
.ScanCode
= SCAN_NULL
;
1842 Key
.UnicodeChar
= UnicodeChar
;
1845 EfiKeyFiFoInsertOneKey (TerminalDevice
, &Key
);