TianoCore EDK2 master
Loading...
Searching...
No Matches
EfiKey.h
Go to the documentation of this file.
1
9#ifndef _EFI_USB_KB_H_
10#define _EFI_USB_KB_H_
11
12#include <Uefi.h>
13
17#include <Protocol/UsbIo.h>
18#include <Protocol/DevicePath.h>
19
22
23#include <Library/DebugLib.h>
29#include <Library/UefiLib.h>
31#include <Library/PcdLib.h>
32#include <Library/UefiUsbLib.h>
33#include <Library/HiiLib.h>
34
36
37#define KEYBOARD_TIMER_INTERVAL 200000 // 0.02s
38
39#define MAX_KEY_ALLOWED 32
40
41#define HZ 1000 * 1000 * 10
42#define USBKBD_REPEAT_DELAY ((HZ) / 2)
43#define USBKBD_REPEAT_RATE ((HZ) / 50)
44
45#define CLASS_HID 3
46#define SUBCLASS_BOOT 1
47#define PROTOCOL_KEYBOARD 1
48
49#define BOOT_PROTOCOL 0
50#define REPORT_PROTOCOL 1
51
52typedef struct {
53 BOOLEAN Down;
54 UINT8 KeyCode;
55} USB_KEY;
56
57typedef struct {
58 VOID *Buffer[MAX_KEY_ALLOWED + 1];
59 UINTN Head;
60 UINTN Tail;
61 UINTN ItemSize;
63
64#define USB_KB_DEV_SIGNATURE SIGNATURE_32 ('u', 'k', 'b', 'd')
65#define USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE SIGNATURE_32 ('u', 'k', 'b', 'x')
66
67typedef struct _KEYBOARD_CONSOLE_IN_EX_NOTIFY {
68 UINTN Signature;
69 EFI_KEY_DATA KeyData;
70 EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn;
71 LIST_ENTRY NotifyEntry;
73
74#define USB_NS_KEY_SIGNATURE SIGNATURE_32 ('u', 'n', 's', 'k')
75
76typedef struct {
77 UINTN Signature;
78 LIST_ENTRY Link;
79
80 //
81 // The number of EFI_NS_KEY_MODIFIER children definitions
82 //
83 UINTN KeyCount;
84
85 //
86 // NsKey[0] : Non-spacing key
87 // NsKey[1] ~ NsKey[KeyCount] : Physical keys
88 //
89 EFI_KEY_DESCRIPTOR *NsKey;
91
92#define USB_NS_KEY_FORM_FROM_LINK(a) CR (a, USB_NS_KEY, Link, USB_NS_KEY_SIGNATURE)
93
97typedef struct {
98 UINTN Signature;
99 EFI_HANDLE ControllerHandle;
100 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
101 EFI_EVENT DelayedRecoveryEvent;
104 EFI_USB_IO_PROTOCOL *UsbIo;
105
106 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
107 EFI_USB_ENDPOINT_DESCRIPTOR IntEndpointDescriptor;
108
109 USB_SIMPLE_QUEUE UsbKeyQueue;
110 USB_SIMPLE_QUEUE EfiKeyQueue;
111 USB_SIMPLE_QUEUE EfiKeyQueueForNotify;
112 BOOLEAN CtrlOn;
113 BOOLEAN AltOn;
114 BOOLEAN ShiftOn;
115 BOOLEAN NumLockOn;
116 BOOLEAN CapsOn;
117 BOOLEAN ScrollOn;
118 UINT8 LastKeyCodeArray[8];
119 UINT8 CurKeyCode;
120
121 EFI_EVENT TimerEvent;
122
123 UINT8 RepeatKey;
124 EFI_EVENT RepeatTimer;
125
126 EFI_UNICODE_STRING_TABLE *ControllerNameTable;
127
128 BOOLEAN LeftCtrlOn;
129 BOOLEAN LeftAltOn;
130 BOOLEAN LeftShiftOn;
131 BOOLEAN LeftLogoOn;
132 BOOLEAN RightCtrlOn;
133 BOOLEAN RightAltOn;
134 BOOLEAN RightShiftOn;
135 BOOLEAN RightLogoOn;
136 BOOLEAN MenuKeyOn;
137 BOOLEAN SysReqOn;
138 BOOLEAN AltGrOn;
139
140 BOOLEAN IsSupportPartialKey;
141
142 EFI_KEY_STATE KeyState;
143 //
144 // Notification function list
145 //
146 LIST_ENTRY NotifyList;
147 EFI_EVENT KeyNotifyProcessEvent;
148
149 //
150 // Non-spacing key list
151 //
152 LIST_ENTRY NsKeyList;
153 USB_NS_KEY *CurrentNsKey;
154 EFI_KEY_DESCRIPTOR *KeyConvertionTable;
155 EFI_EVENT KeyboardLayoutEvent;
156} USB_KB_DEV;
157
158//
159// Global Variables
160//
161extern EFI_DRIVER_BINDING_PROTOCOL gUsbKeyboardDriverBinding;
162extern EFI_COMPONENT_NAME_PROTOCOL gUsbKeyboardComponentName;
163extern EFI_COMPONENT_NAME2_PROTOCOL gUsbKeyboardComponentName2;
164
165#define USB_KB_DEV_FROM_THIS(a) \
166 CR(a, USB_KB_DEV, SimpleInput, USB_KB_DEV_SIGNATURE)
167#define TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS(a) \
168 CR(a, USB_KB_DEV, SimpleInputEx, USB_KB_DEV_SIGNATURE)
169
170//
171// According to Universal Serial Bus HID Usage Tables document ver 1.12,
172// a Boot Keyboard should support the keycode range from 0x0 to 0x65 and 0xE0 to 0xE7.
173// 0xE0 to 0xE7 are for modifier keys, and 0x0 to 0x3 are reserved for typical
174// keyboard status or keyboard errors.
175// So the number of valid non-modifier USB keycodes is 0x62, and the number of
176// valid keycodes is 0x6A.
177//
178#define NUMBER_OF_VALID_NON_MODIFIER_USB_KEYCODE 0x62
179#define NUMBER_OF_VALID_USB_KEYCODE 0x6A
180//
181// 0x0 to 0x3 are reserved for typical keyboard status or keyboard errors.
182//
183#define USBKBD_VALID_KEYCODE(Key) ((UINT8) (Key) > 3)
184
185typedef struct {
186 UINT8 NumLock : 1;
187 UINT8 CapsLock : 1;
188 UINT8 ScrollLock : 1;
189 UINT8 Resrvd : 5;
190} LED_MAP;
191
192//
193// Functions of Driver Binding Protocol
194//
195
208EFIAPI
211 IN EFI_HANDLE Controller,
212 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
213 );
214
233EFIAPI
236 IN EFI_HANDLE Controller,
237 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
238 );
239
256EFIAPI
259 IN EFI_HANDLE Controller,
260 IN UINTN NumberOfChildren,
261 IN EFI_HANDLE *ChildHandleBuffer
262 );
263
264//
265// EFI Component Name Functions
266//
267
303EFIAPI
306 IN CHAR8 *Language,
307 OUT CHAR16 **DriverName
308 );
309
369EFIAPI
372 IN EFI_HANDLE ControllerHandle,
373 IN EFI_HANDLE ChildHandle OPTIONAL,
374 IN CHAR8 *Language,
375 OUT CHAR16 **ControllerName
376 );
377
378//
379// Functions of Simple Text Input Protocol
380//
381
398EFIAPI
401 IN BOOLEAN ExtendedVerification
402 );
403
419EFIAPI
422 OUT EFI_INPUT_KEY *Key
423 );
424
425//
426// Simple Text Input Ex protocol functions
427//
428
452EFIAPI
455 IN BOOLEAN ExtendedVerification
456 );
457
474EFIAPI
477 OUT EFI_KEY_DATA *KeyData
478 );
479
495EFIAPI
498 IN EFI_KEY_TOGGLE_STATE *KeyToggleState
499 );
500
521EFIAPI
524 IN EFI_KEY_DATA *KeyData,
525 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction,
526 OUT VOID **NotifyHandle
527 );
528
541EFIAPI
544 IN VOID *NotificationHandle
545 );
546
555VOID
556EFIAPI
558 IN EFI_EVENT Event,
559 IN VOID *Context
560 );
561
573 IN OUT LIST_ENTRY *NotifyList
574 );
575
586BOOLEAN
588 IN EFI_KEY_DATA *RegsiteredData,
589 IN EFI_KEY_DATA *InputData
590 );
591
598VOID
599EFIAPI
601 IN EFI_EVENT Event,
602 IN VOID *Context
603 );
604
611VOID
612EFIAPI
614 IN EFI_EVENT Event,
615 IN VOID *Context
616 );
617
618#endif
UINT64 UINTN
EFI_STATUS EFIAPI USBKeyboardDriverBindingSupported(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
Definition: EfiKey.c:72
VOID EFIAPI KeyNotifyProcessHandler(IN EFI_EVENT Event, IN VOID *Context)
EFI_STATUS EFIAPI USBKeyboardUnregisterKeyNotify(IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, IN VOID *NotificationHandle)
Definition: EfiKey.c:1160
EFI_STATUS EFIAPI USBKeyboardResetEx(IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, IN BOOLEAN ExtendedVerification)
Definition: EfiKey.c:946
EFI_STATUS EFIAPI USBKeyboardRegisterKeyNotify(IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, IN EFI_KEY_DATA *KeyData, IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction, OUT VOID **NotifyHandle)
Definition: EfiKey.c:1088
EFI_STATUS EFIAPI UsbKeyboardComponentNameGetControllerName(IN EFI_COMPONENT_NAME_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ChildHandle OPTIONAL, IN CHAR8 *Language, OUT CHAR16 **ControllerName)
EFI_STATUS EFIAPI USBKeyboardDriverBindingStop(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer)
Definition: EfiKey.c:483
VOID EFIAPI USBKeyboardWaitForKey(IN EFI_EVENT Event, IN VOID *Context)
Definition: EfiKey.c:756
EFI_STATUS EFIAPI USBKeyboardSetState(IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, IN EFI_KEY_TOGGLE_STATE *KeyToggleState)
Definition: EfiKey.c:1016
VOID EFIAPI USBKeyboardTimerHandler(IN EFI_EVENT Event, IN VOID *Context)
Definition: EfiKey.c:810
EFI_STATUS EFIAPI USBKeyboardDriverBindingStart(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
Definition: EfiKey.c:135
EFI_STATUS KbdFreeNotifyList(IN OUT LIST_ENTRY *NotifyList)
Definition: Ps2Keyboard.c:618
EFI_STATUS EFIAPI USBKeyboardReset(IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, IN BOOLEAN ExtendedVerification)
Definition: EfiKey.c:637
EFI_STATUS EFIAPI UsbKeyboardComponentNameGetDriverName(IN EFI_COMPONENT_NAME_PROTOCOL *This, IN CHAR8 *Language, OUT CHAR16 **DriverName)
Definition: ComponentName.c:70
EFI_STATUS EFIAPI USBKeyboardReadKeyStrokeEx(IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, OUT EFI_KEY_DATA *KeyData)
Definition: EfiKey.c:984
EFI_STATUS EFIAPI USBKeyboardReadKeyStroke(IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, OUT EFI_INPUT_KEY *Key)
Definition: EfiKey.c:700
BOOLEAN IsKeyRegistered(IN EFI_KEY_DATA *RegsiteredData, IN EFI_KEY_DATA *InputData)
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
UINT8 EFI_KEY_TOGGLE_STATE
EFI_STATUS(EFIAPI * EFI_KEY_NOTIFY_FUNCTION)(IN EFI_KEY_DATA *KeyData)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_EVENT
Definition: UefiBaseType.h:37
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
Definition: EfiKey.h:52