]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Usb/UsbKbDxe/efikey.h
Merged in the following trackers from EDK:
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbKbDxe / efikey.h
1 /** @file
2 Copyright (c) 2004 - 2008, Intel Corporation
3 All rights reserved. This program and the accompanying materials
4 are licensed and made available under the terms and conditions of the BSD License
5 which accompanies this distribution. The full text of the license may be found at
6 http://opensource.org/licenses/bsd-license.php
7
8 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
10
11 Module Name:
12
13 EfiKey.h
14
15 Abstract:
16
17 Header file for USB Keyboard Driver's Data Structures
18
19 Revision History
20
21 **/
22 #ifndef _USB_KB_H
23 #define _USB_KB_H
24
25
26 #include <PiDxe.h>
27
28 #include <Protocol/SimpleTextIn.h>
29 #include <Protocol/SimpleTextInEx.h>
30 #include <Protocol/HiiDatabase.h>
31 #include <Protocol/UsbIo.h>
32 #include <Protocol/DevicePath.h>
33 #include <Guid/HiiKeyBoardLayout.h>
34 #include <Guid/HotPlugDevice.h>
35
36 #include <Library/DebugLib.h>
37 #include <Library/ReportStatusCodeLib.h>
38 #include <Library/BaseMemoryLib.h>
39 #include <Library/UefiRuntimeServicesTableLib.h>
40 #include <Library/UefiDriverEntryPoint.h>
41 #include <Library/UefiBootServicesTableLib.h>
42 #include <Library/UefiLib.h>
43 #include <Library/MemoryAllocationLib.h>
44 #include <Library/PcdLib.h>
45 #include <Library/UsbLib.h>
46 #include <Library/BaseLib.h>
47
48 #include <IndustryStandard/Usb.h>
49
50 #define MAX_KEY_ALLOWED 32
51
52 #define HZ 1000 * 1000 * 10
53 #define USBKBD_REPEAT_DELAY ((HZ) / 2)
54 #define USBKBD_REPEAT_RATE ((HZ) / 50)
55
56 #define CLASS_HID 3
57 #define SUBCLASS_BOOT 1
58 #define PROTOCOL_KEYBOARD 1
59
60 #define BOOT_PROTOCOL 0
61 #define REPORT_PROTOCOL 1
62
63 typedef struct {
64 UINT8 Down;
65 UINT8 KeyCode;
66 } USB_KEY;
67
68 typedef struct {
69 USB_KEY buffer[MAX_KEY_ALLOWED + 1];
70 UINT8 bHead;
71 UINT8 bTail;
72 } USB_KB_BUFFER;
73
74 #define USB_KB_DEV_SIGNATURE EFI_SIGNATURE_32 ('u', 'k', 'b', 'd')
75 #define USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE EFI_SIGNATURE_32 ('u', 'k', 'b', 'x')
76
77 typedef struct _KEYBOARD_CONSOLE_IN_EX_NOTIFY {
78 UINTN Signature;
79 EFI_HANDLE NotifyHandle;
80 EFI_KEY_DATA KeyData;
81 EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn;
82 LIST_ENTRY NotifyEntry;
83 } KEYBOARD_CONSOLE_IN_EX_NOTIFY;
84
85 #define USB_NS_KEY_SIGNATURE EFI_SIGNATURE_32 ('u', 'n', 's', 'k')
86
87 typedef struct {
88 UINTN Signature;
89 LIST_ENTRY Link;
90
91 //
92 // The number of EFI_NS_KEY_MODIFIER children definitions
93 //
94 UINTN KeyCount;
95
96 //
97 // NsKey[0] : Non-spacing key
98 // NsKey[1] ~ NsKey[KeyCount] : Physical keys
99 //
100 EFI_KEY_DESCRIPTOR *NsKey;
101 } USB_NS_KEY;
102
103 #define USB_NS_KEY_FORM_FROM_LINK(a) CR (a, USB_NS_KEY, Link, USB_NS_KEY_SIGNATURE)
104
105 typedef struct {
106 UINTN Signature;
107 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
108 EFI_EVENT DelayedRecoveryEvent;
109 EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleInput;
110 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL SimpleInputEx;
111 EFI_USB_IO_PROTOCOL *UsbIo;
112
113 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
114 EFI_USB_ENDPOINT_DESCRIPTOR IntEndpointDescriptor;
115
116 USB_KB_BUFFER KeyboardBuffer;
117 UINT8 CtrlOn;
118 UINT8 AltOn;
119 UINT8 ShiftOn;
120 UINT8 NumLockOn;
121 UINT8 CapsOn;
122 UINT8 ScrollOn;
123 UINT8 LastKeyCodeArray[8];
124 UINT8 CurKeyChar;
125
126 UINT8 RepeatKey;
127 EFI_EVENT RepeatTimer;
128
129 EFI_UNICODE_STRING_TABLE *ControllerNameTable;
130
131 UINT8 LeftCtrlOn;
132 UINT8 LeftAltOn;
133 UINT8 LeftShiftOn;
134 UINT8 LeftLogoOn;
135 UINT8 RightCtrlOn;
136 UINT8 RightAltOn;
137 UINT8 RightShiftOn;
138 UINT8 RightLogoOn;
139 UINT8 MenuKeyOn;
140 UINT8 SysReqOn;
141 UINT8 AltGrOn;
142
143 EFI_KEY_STATE KeyState;
144 //
145 // Notification function list
146 //
147 LIST_ENTRY NotifyList;
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 //
161 extern EFI_DRIVER_BINDING_PROTOCOL gUsbKeyboardDriverBinding;
162 extern EFI_COMPONENT_NAME_PROTOCOL gUsbKeyboardComponentName;
163 extern EFI_COMPONENT_NAME2_PROTOCOL gUsbKeyboardComponentName2;
164 extern EFI_GUID gEfiUsbKeyboardDriverGuid;
165 extern EFI_GUID gSimpleTextInExNotifyGuid;
166
167 VOID
168 KbdReportStatusCode (
169 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
170 IN EFI_STATUS_CODE_TYPE CodeType,
171 IN EFI_STATUS_CODE_VALUE Value
172 );
173
174 #define USB_KB_DEV_FROM_THIS(a) \
175 CR(a, USB_KB_DEV, SimpleInput, USB_KB_DEV_SIGNATURE)
176 #define TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS(a) \
177 CR(a, USB_KB_DEV, SimpleInputEx, USB_KB_DEV_SIGNATURE)
178
179
180 #define MOD_CONTROL_L 0x01
181 #define MOD_CONTROL_R 0x10
182 #define MOD_SHIFT_L 0x02
183 #define MOD_SHIFT_R 0x20
184 #define MOD_ALT_L 0x04
185 #define MOD_ALT_R 0x40
186 #define MOD_WIN_L 0x08
187 #define MOD_WIN_R 0x80
188
189 typedef struct {
190 UINT8 Mask;
191 UINT8 Key;
192 } KB_MODIFIER;
193
194 #define USB_KEYCODE_MAX_MAKE 0x62
195
196 #define USBKBD_VALID_KEYCODE(key) ((UINT8) (key) > 3)
197
198 typedef struct {
199 UINT8 NumLock : 1;
200 UINT8 CapsLock : 1;
201 UINT8 ScrollLock : 1;
202 UINT8 Resrvd : 5;
203 } LED_MAP;
204
205 //
206 // Simple Text Input Ex protocol functions
207 //
208 EFI_STATUS
209 EFIAPI
210 USBKeyboardResetEx (
211 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
212 IN BOOLEAN ExtendedVerification
213 )
214 /*++
215
216 Routine Description:
217 Reset the input device and optionaly run diagnostics
218
219 Arguments:
220 This - Protocol instance pointer.
221 ExtendedVerification - Driver may perform diagnostics on reset.
222
223 Returns:
224 EFI_SUCCESS - The device was reset.
225 EFI_DEVICE_ERROR - The device is not functioning properly and could
226 not be reset.
227
228 --*/
229 ;
230
231 EFI_STATUS
232 EFIAPI
233 USBKeyboardReadKeyStrokeEx (
234 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
235 OUT EFI_KEY_DATA *KeyData
236 )
237 /*++
238
239 Routine Description:
240 Reads the next keystroke from the input device. The WaitForKey Event can
241 be used to test for existance of a keystroke via WaitForEvent () call.
242
243 Arguments:
244 This - Protocol instance pointer.
245 KeyData - A pointer to a buffer that is filled in with the keystroke
246 state data for the key that was pressed.
247
248 Returns:
249 EFI_SUCCESS - The keystroke information was returned.
250 EFI_NOT_READY - There was no keystroke data availiable.
251 EFI_DEVICE_ERROR - The keystroke information was not returned due to
252 hardware errors.
253 EFI_INVALID_PARAMETER - KeyData is NULL.
254
255 --*/
256 ;
257
258 EFI_STATUS
259 EFIAPI
260 USBKeyboardSetState (
261 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
262 IN EFI_KEY_TOGGLE_STATE *KeyToggleState
263 )
264 /*++
265
266 Routine Description:
267 Set certain state for the input device.
268
269 Arguments:
270 This - Protocol instance pointer.
271 KeyToggleState - A pointer to the EFI_KEY_TOGGLE_STATE to set the
272 state for the input device.
273
274 Returns:
275 EFI_SUCCESS - The device state was set successfully.
276 EFI_DEVICE_ERROR - The device is not functioning correctly and could
277 not have the setting adjusted.
278 EFI_UNSUPPORTED - The device does not have the ability to set its state.
279 EFI_INVALID_PARAMETER - KeyToggleState is NULL.
280
281 --*/
282 ;
283
284 EFI_STATUS
285 EFIAPI
286 USBKeyboardRegisterKeyNotify (
287 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
288 IN EFI_KEY_DATA *KeyData,
289 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction,
290 OUT EFI_HANDLE *NotifyHandle
291 )
292 /*++
293
294 Routine Description:
295 Register a notification function for a particular keystroke for the input device.
296
297 Arguments:
298 This - Protocol instance pointer.
299 KeyData - A pointer to a buffer that is filled in with the keystroke
300 information data for the key that was pressed.
301 KeyNotificationFunction - Points to the function to be called when the key
302 sequence is typed specified by KeyData.
303 NotifyHandle - Points to the unique handle assigned to the registered notification.
304
305 Returns:
306 EFI_SUCCESS - The notification function was registered successfully.
307 EFI_OUT_OF_RESOURCES - Unable to allocate resources for necesssary data structures.
308 EFI_INVALID_PARAMETER - KeyData or NotifyHandle is NULL.
309
310 --*/
311 ;
312
313 EFI_STATUS
314 EFIAPI
315 USBKeyboardUnregisterKeyNotify (
316 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
317 IN EFI_HANDLE NotificationHandle
318 )
319 /*++
320
321 Routine Description:
322 Remove a registered notification function from a particular keystroke.
323
324 Arguments:
325 This - Protocol instance pointer.
326 NotificationHandle - The handle of the notification function being unregistered.
327
328 Returns:
329 EFI_SUCCESS - The notification function was unregistered successfully.
330 EFI_INVALID_PARAMETER - The NotificationHandle is invalid.
331 EFI_NOT_FOUND - Can not find the matching entry in database.
332
333 --*/
334 ;
335
336 #endif
337