OpenCore  1.0.4
OpenCore Bootloader
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
15
16#include <Protocol/SimpleTextIn.h>
17#include <Protocol/SimpleTextInEx.h>
18#include <Protocol/UsbIo.h>
19#include <Protocol/DevicePath.h>
22
23#include <Library/DebugLib.h>
24#include <Library/ReportStatusCodeLib.h>
25#include <Library/BaseMemoryLib.h>
26#include <Library/UefiRuntimeServicesTableLib.h>
27#include <Library/UefiDriverEntryPoint.h>
28#include <Library/UefiBootServicesTableLib.h>
29#include <Library/UefiLib.h>
30#include <Library/MemoryAllocationLib.h>
31#include <Library/PcdLib.h>
32#include <Library/UefiUsbLib.h>
33
34#include <IndustryStandard/Usb.h>
35
36#define KEYBOARD_TIMER_INTERVAL 200000 // 0.02s
37
38#define MAX_KEY_ALLOWED 32
39
40#define HZ 1000 * 1000 * 10
41#define USBKBD_REPEAT_DELAY ((HZ) / 2)
42#define USBKBD_REPEAT_RATE ((HZ) / 50)
43
44#define CLASS_HID 3
45#define SUBCLASS_BOOT 1
46#define PROTOCOL_KEYBOARD 1
47
48#define BOOT_PROTOCOL 0
49#define REPORT_PROTOCOL 1
50
51typedef struct {
52 BOOLEAN Down;
53 UINT8 KeyCode;
54} USB_KEY;
55
56typedef struct {
58 UINTN Head;
59 UINTN Tail;
60 UINTN ItemSize;
62
63#define USB_KB_DEV_SIGNATURE SIGNATURE_32 ('u', 'k', 'b', 'd')
64#define USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE SIGNATURE_32 ('u', 'k', 'b', 'x')
65
67 UINTN Signature;
68 EFI_KEY_DATA KeyData;
69 EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn;
70 LIST_ENTRY NotifyEntry;
72
73#define USB_NS_KEY_SIGNATURE SIGNATURE_32 ('u', 'n', 's', 'k')
74
75typedef struct {
76 UINTN Signature;
77 LIST_ENTRY Link;
78
79 //
80 // The number of EFI_NS_KEY_MODIFIER children definitions
81 //
82 UINTN KeyCount;
83
84 //
85 // NsKey[0] : Non-spacing key
86 // NsKey[1] ~ NsKey[KeyCount] : Physical keys
87 //
88 EFI_KEY_DESCRIPTOR *NsKey;
90
91#define USB_NS_KEY_FORM_FROM_LINK(a) CR (a, USB_NS_KEY, Link, USB_NS_KEY_SIGNATURE)
92
96typedef struct {
97 UINTN Signature;
98 EFI_HANDLE ControllerHandle;
99 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
101 EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleInput;
102 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL SimpleInputEx;
103 EFI_USB_IO_PROTOCOL *UsbIo;
104
105 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
106 EFI_USB_ENDPOINT_DESCRIPTOR IntEndpointDescriptor;
107
111 BOOLEAN CtrlOn;
112 BOOLEAN AltOn;
113 BOOLEAN ShiftOn;
114 BOOLEAN NumLockOn;
115 BOOLEAN CapsOn;
116 BOOLEAN ScrollOn;
117 UINT8 LastKeyCodeArray[8];
119
120 EFI_EVENT TimerEvent;
121
123 EFI_EVENT RepeatTimer;
124
125 EFI_UNICODE_STRING_TABLE *ControllerNameTable;
126
127 BOOLEAN LeftCtrlOn;
128 BOOLEAN LeftAltOn;
129 BOOLEAN LeftShiftOn;
130 BOOLEAN LeftLogoOn;
131 BOOLEAN RightCtrlOn;
132 BOOLEAN RightAltOn;
134 BOOLEAN RightLogoOn;
135 BOOLEAN MenuKeyOn;
136 BOOLEAN SysReqOn;
137 BOOLEAN AltGrOn;
138
140
141 EFI_KEY_STATE KeyState;
142 //
143 // Notification function list
144 //
145 LIST_ENTRY NotifyList;
147
148 //
149 // Non-spacing key list
150 //
151 LIST_ENTRY NsKeyList;
153 EFI_KEY_DESCRIPTOR *KeyConvertionTable;
154
157
160
162} USB_KB_DEV;
163
164//
165// Global Variables
166//
167extern EFI_DRIVER_BINDING_PROTOCOL gUsbKeyboardDriverBinding;
168extern EFI_COMPONENT_NAME_PROTOCOL gUsbKeyboardComponentName;
169extern EFI_COMPONENT_NAME2_PROTOCOL gUsbKeyboardComponentName2;
170
171#define USB_KB_DEV_FROM_THIS(a) \
172 CR(a, USB_KB_DEV, SimpleInput, USB_KB_DEV_SIGNATURE)
173#define TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS(a) \
174 CR(a, USB_KB_DEV, SimpleInputEx, USB_KB_DEV_SIGNATURE)
175
176//
177// According to Universal Serial Bus HID Usage Tables document ver 1.12,
178// a Boot Keyboard should support the keycode range from 0x0 to 0x65 and 0xE0 to 0xE7.
179// 0xE0 to 0xE7 are for modifier keys, and 0x0 to 0x3 are reserved for typical
180// keyboard status or keyboard errors.
181// So the number of valid non-modifier USB keycodes is 0x62, and the number of
182// valid keycodes is 0x6A.
183//
184#define NUMBER_OF_VALID_NON_MODIFIER_USB_KEYCODE 0x62
185#define NUMBER_OF_VALID_USB_KEYCODE 0x6A
186//
187// 0x0 to 0x3 are reserved for typical keyboard status or keyboard errors.
188//
189#define USBKBD_VALID_KEYCODE(Key) ((UINT8) (Key) > 3)
190
191typedef struct {
192 UINT8 NumLock : 1;
193 UINT8 CapsLock : 1;
194 UINT8 ScrollLock : 1;
195 UINT8 Resrvd : 5;
196} LED_MAP;
197
198//
199// Functions of Driver Binding Protocol
200//
201
213EFI_STATUS
214EFIAPI
216 IN EFI_DRIVER_BINDING_PROTOCOL *This,
217 IN EFI_HANDLE Controller,
218 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
219 );
220
238EFI_STATUS
239EFIAPI
241 IN EFI_DRIVER_BINDING_PROTOCOL *This,
242 IN EFI_HANDLE Controller,
243 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
244 );
245
261EFI_STATUS
262EFIAPI
264 IN EFI_DRIVER_BINDING_PROTOCOL *This,
265 IN EFI_HANDLE Controller,
266 IN UINTN NumberOfChildren,
267 IN EFI_HANDLE *ChildHandleBuffer
268 );
269
270//
271// EFI Component Name Functions
272//
273
308EFI_STATUS
309EFIAPI
311 IN EFI_COMPONENT_NAME_PROTOCOL *This,
312 IN CHAR8 *Language,
313 OUT CHAR16 **DriverName
314 );
315
374EFI_STATUS
375EFIAPI
377 IN EFI_COMPONENT_NAME_PROTOCOL *This,
378 IN EFI_HANDLE ControllerHandle,
379 IN EFI_HANDLE ChildHandle OPTIONAL,
380 IN CHAR8 *Language,
381 OUT CHAR16 **ControllerName
382 );
383
384//
385// Functions of Simple Text Input Protocol
386//
387
403EFI_STATUS
404EFIAPI
406 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
407 IN BOOLEAN ExtendedVerification
408 );
409
423EFI_STATUS
424EFIAPI
426 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
427 OUT EFI_INPUT_KEY *Key
428 );
429
430//
431// Simple Text Input Ex protocol functions
432//
433
456EFI_STATUS
457EFIAPI
459 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
460 IN BOOLEAN ExtendedVerification
461 );
462
477EFI_STATUS
478EFIAPI
480 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
481 OUT EFI_KEY_DATA *KeyData
482 );
483
498EFI_STATUS
499EFIAPI
501 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
502 IN EFI_KEY_TOGGLE_STATE *KeyToggleState
503 );
504
524EFI_STATUS
525EFIAPI
527 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
528 IN EFI_KEY_DATA *KeyData,
529 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction,
530 OUT VOID **NotifyHandle
531 );
532
544EFI_STATUS
545EFIAPI
547 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
548 IN VOID *NotificationHandle
549 );
550
559VOID
560EFIAPI
562 IN EFI_EVENT Event,
563 IN VOID *Context
564 );
565
575EFI_STATUS
577 IN OUT LIST_ENTRY *NotifyList
578 );
579
590BOOLEAN
592 IN EFI_KEY_DATA *RegsiteredData,
593 IN EFI_KEY_DATA *InputData
594 );
595
602VOID
603EFIAPI
605 IN EFI_EVENT Event,
606 IN VOID *Context
607 );
608
615VOID
616EFIAPI
618 IN EFI_EVENT Event,
619 IN VOID *Context
620 );
621
628VOID
629EFIAPI
631 IN EFI_EVENT Event,
632 IN VOID *Context
633 );
634
635#endif
EFI_DRIVER_BINDING_PROTOCOL gUsbKeyboardDriverBinding
Definition EfiKey.c:20
EFI_STATUS EFIAPI USBKeyboardDriverBindingSupported(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
Definition EfiKey.c:76
VOID EFIAPI KeyNotifyProcessHandler(IN EFI_EVENT Event, IN VOID *Context)
Definition EfiKey.c:1292
EFI_STATUS EFIAPI USBKeyboardUnregisterKeyNotify(IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, IN VOID *NotificationHandle)
Definition EfiKey.c:1237
EFI_STATUS EFIAPI USBKeyboardResetEx(IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, IN BOOLEAN ExtendedVerification)
Definition EfiKey.c:1024
struct _KEYBOARD_CONSOLE_IN_EX_NOTIFY KEYBOARD_CONSOLE_IN_EX_NOTIFY
VOID EFIAPI USBKeyboardExitBootServices(IN EFI_EVENT Event, IN VOID *Context)
Definition EfiKey.c:905
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:1165
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:526
#define MAX_KEY_ALLOWED
Definition EfiKey.h:38
VOID EFIAPI USBKeyboardWaitForKey(IN EFI_EVENT Event, IN VOID *Context)
Definition EfiKey.c:808
EFI_STATUS EFIAPI USBKeyboardSetState(IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, IN EFI_KEY_TOGGLE_STATE *KeyToggleState)
Definition EfiKey.c:1093
EFI_COMPONENT_NAME2_PROTOCOL gUsbKeyboardComponentName2
EFI_COMPONENT_NAME_PROTOCOL gUsbKeyboardComponentName
VOID EFIAPI USBKeyboardTimerHandler(IN EFI_EVENT Event, IN VOID *Context)
Definition EfiKey.c:862
EFI_STATUS EFIAPI USBKeyboardDriverBindingStart(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
Definition EfiKey.c:141
EFI_STATUS KbdFreeNotifyList(IN OUT LIST_ENTRY *NotifyList)
Definition EfiKey.c:933
EFI_STATUS EFIAPI USBKeyboardReset(IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, IN BOOLEAN ExtendedVerification)
Definition EfiKey.c:690
EFI_STATUS EFIAPI UsbKeyboardComponentNameGetDriverName(IN EFI_COMPONENT_NAME_PROTOCOL *This, IN CHAR8 *Language, OUT CHAR16 **DriverName)
EFI_STATUS EFIAPI USBKeyboardReadKeyStrokeEx(IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This, OUT EFI_KEY_DATA *KeyData)
Definition EfiKey.c:1061
EFI_STATUS EFIAPI USBKeyboardReadKeyStroke(IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, OUT EFI_INPUT_KEY *Key)
Definition EfiKey.c:752
BOOLEAN IsKeyRegistered(IN EFI_KEY_DATA *RegsiteredData, IN EFI_KEY_DATA *InputData)
Definition EfiKey.c:965
OC_TYPING_BUFFER_ENTRY Buffer[OC_TYPING_BUFFER_SIZE]
Definition OcTypingLib.h:42
EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn
Definition EfiKey.h:69
UINT8 NumLock
Definition EfiKey.h:192
UINT8 ScrollLock
Definition EfiKey.h:194
UINT8 Resrvd
Definition EfiKey.h:195
UINT8 CapsLock
Definition EfiKey.h:193
EFI_EVENT KeyNotifyProcessEvent
Definition EfiKey.h:146
EFI_HANDLE ControllerHandle
Definition EfiKey.h:98
BOOLEAN SysReqOn
Definition EfiKey.h:136
BOOLEAN LeftAltOn
Definition EfiKey.h:128
BOOLEAN RightShiftOn
Definition EfiKey.h:133
EFI_USB_ENDPOINT_DESCRIPTOR IntEndpointDescriptor
Definition EfiKey.h:106
BOOLEAN AltGrOn
Definition EfiKey.h:137
EFI_EVENT KeyMapInstallNotifyEvent
Definition EfiKey.h:158
BOOLEAN NumLockOn
Definition EfiKey.h:114
BOOLEAN RightAltOn
Definition EfiKey.h:132
USB_NS_KEY * CurrentNsKey
Definition EfiKey.h:152
BOOLEAN ScrollOn
Definition EfiKey.h:116
UINT8 RepeatKey
Definition EfiKey.h:122
BOOLEAN AltOn
Definition EfiKey.h:112
BOOLEAN RightCtrlOn
Definition EfiKey.h:131
EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL SimpleInputEx
Definition EfiKey.h:102
USB_SIMPLE_QUEUE UsbKeyQueue
Definition EfiKey.h:108
EFI_USB_IO_PROTOCOL * UsbIo
Definition EfiKey.h:103
EFI_KEY_STATE KeyState
Definition EfiKey.h:141
EFI_UNICODE_STRING_TABLE * ControllerNameTable
Definition EfiKey.h:125
UINT8 CurKeyCode
Definition EfiKey.h:118
BOOLEAN MenuKeyOn
Definition EfiKey.h:135
UINTN KeyMapDbIndex
Definition EfiKey.h:156
EFI_EVENT TimerEvent
Definition EfiKey.h:120
EFI_EVENT ExitBootServicesEvent
Definition EfiKey.h:161
EFI_EVENT RepeatTimer
Definition EfiKey.h:123
EFI_KEY_DESCRIPTOR * KeyConvertionTable
Definition EfiKey.h:153
UINTN Signature
Definition EfiKey.h:97
APPLE_KEY_MAP_DATABASE_PROTOCOL * KeyMapDb
Definition EfiKey.h:155
USB_SIMPLE_QUEUE EfiKeyQueue
Definition EfiKey.h:109
EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleInput
Definition EfiKey.h:101
USB_SIMPLE_QUEUE EfiKeyQueueForNotify
Definition EfiKey.h:110
BOOLEAN IsSupportPartialKey
Definition EfiKey.h:139
VOID * KeyMapInstallRegistration
Definition EfiKey.h:159
LIST_ENTRY NotifyList
Definition EfiKey.h:145
BOOLEAN LeftLogoOn
Definition EfiKey.h:130
BOOLEAN CapsOn
Definition EfiKey.h:115
BOOLEAN RightLogoOn
Definition EfiKey.h:134
BOOLEAN ShiftOn
Definition EfiKey.h:113
BOOLEAN LeftShiftOn
Definition EfiKey.h:129
BOOLEAN CtrlOn
Definition EfiKey.h:111
EFI_DEVICE_PATH_PROTOCOL * DevicePath
Definition EfiKey.h:99
LIST_ENTRY NsKeyList
Definition EfiKey.h:151
BOOLEAN LeftCtrlOn
Definition EfiKey.h:127
EFI_EVENT DelayedRecoveryEvent
Definition EfiKey.h:100
EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor
Definition EfiKey.h:105
BOOLEAN Down
Definition EfiKey.h:52
UINT8 KeyCode
Definition EfiKey.h:53
UINTN KeyCount
Definition EfiKey.h:82
LIST_ENTRY Link
Definition EfiKey.h:77
UINTN Signature
Definition EfiKey.h:76
EFI_KEY_DESCRIPTOR * NsKey
Definition EfiKey.h:88
UINTN ItemSize
Definition EfiKey.h:60