]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.h
Clean up to update the reference of the these macros:
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbKbDxe / EfiKey.h
1 /** @file
2 Header file for USB Keyboard Driver's Data Structures.
3
4 Copyright (c) 2004 - 2008, Intel Corporation
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 #ifndef _EFI_USB_KB_H_
15 #define _EFI_USB_KB_H_
16
17
18 #include <Uefi.h>
19
20 #include <Protocol/SimpleTextIn.h>
21 #include <Protocol/SimpleTextInEx.h>
22 #include <Protocol/HiiDatabase.h>
23 #include <Protocol/UsbIo.h>
24 #include <Protocol/DevicePath.h>
25 #include <Guid/HiiKeyBoardLayout.h>
26 #include <Guid/HotPlugDevice.h>
27
28 #include <Library/DebugLib.h>
29 #include <Library/ReportStatusCodeLib.h>
30 #include <Library/BaseMemoryLib.h>
31 #include <Library/UefiRuntimeServicesTableLib.h>
32 #include <Library/UefiDriverEntryPoint.h>
33 #include <Library/UefiBootServicesTableLib.h>
34 #include <Library/UefiLib.h>
35 #include <Library/MemoryAllocationLib.h>
36 #include <Library/PcdLib.h>
37 #include <Library/UefiUsbLib.h>
38 #include <Library/BaseLib.h>
39 #include <Library/UefiUsbLib.h>
40
41 #include <IndustryStandard/Usb.h>
42
43 #define MAX_KEY_ALLOWED 32
44
45 #define HZ 1000 * 1000 * 10
46 #define USBKBD_REPEAT_DELAY ((HZ) / 2)
47 #define USBKBD_REPEAT_RATE ((HZ) / 50)
48
49 #define CLASS_HID 3
50 #define SUBCLASS_BOOT 1
51 #define PROTOCOL_KEYBOARD 1
52
53 #define BOOT_PROTOCOL 0
54 #define REPORT_PROTOCOL 1
55
56 typedef struct {
57 BOOLEAN Down;
58 UINT8 KeyCode;
59 } USB_KEY;
60
61 typedef struct {
62 USB_KEY Buffer[MAX_KEY_ALLOWED + 1];
63 UINT8 BufferHead;
64 UINT8 BufferTail;
65 } USB_KB_BUFFER;
66
67 #define USB_KB_DEV_SIGNATURE SIGNATURE_32 ('u', 'k', 'b', 'd')
68 #define USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE SIGNATURE_32 ('u', 'k', 'b', 'x')
69
70 typedef struct _KEYBOARD_CONSOLE_IN_EX_NOTIFY {
71 UINTN Signature;
72 EFI_HANDLE NotifyHandle;
73 EFI_KEY_DATA KeyData;
74 EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn;
75 LIST_ENTRY NotifyEntry;
76 } KEYBOARD_CONSOLE_IN_EX_NOTIFY;
77
78 #define USB_NS_KEY_SIGNATURE SIGNATURE_32 ('u', 'n', 's', 'k')
79
80 typedef struct {
81 UINTN Signature;
82 LIST_ENTRY Link;
83
84 //
85 // The number of EFI_NS_KEY_MODIFIER children definitions
86 //
87 UINTN KeyCount;
88
89 //
90 // NsKey[0] : Non-spacing key
91 // NsKey[1] ~ NsKey[KeyCount] : Physical keys
92 //
93 EFI_KEY_DESCRIPTOR *NsKey;
94 } USB_NS_KEY;
95
96 #define USB_NS_KEY_FORM_FROM_LINK(a) CR (a, USB_NS_KEY, Link, USB_NS_KEY_SIGNATURE)
97
98 ///
99 /// Structure to describe USB keyboard device
100 ///
101 typedef struct {
102 UINTN Signature;
103 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
104 EFI_EVENT DelayedRecoveryEvent;
105 EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleInput;
106 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL SimpleInputEx;
107 EFI_USB_IO_PROTOCOL *UsbIo;
108
109 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
110 EFI_USB_ENDPOINT_DESCRIPTOR IntEndpointDescriptor;
111
112 USB_KB_BUFFER KeyboardBuffer;
113 BOOLEAN CtrlOn;
114 BOOLEAN AltOn;
115 BOOLEAN ShiftOn;
116 BOOLEAN NumLockOn;
117 BOOLEAN CapsOn;
118 BOOLEAN ScrollOn;
119 UINT8 LastKeyCodeArray[8];
120 UINT8 CurKeyCode;
121
122 UINT8 RepeatKey;
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;
133 BOOLEAN RightShiftOn;
134 BOOLEAN RightLogoOn;
135 BOOLEAN MenuKeyOn;
136 BOOLEAN SysReqOn;
137 BOOLEAN AltGrOn;
138
139 EFI_KEY_STATE KeyState;
140 //
141 // Notification function list
142 //
143 LIST_ENTRY NotifyList;
144
145 //
146 // Non-spacing key list
147 //
148 LIST_ENTRY NsKeyList;
149 USB_NS_KEY *CurrentNsKey;
150 EFI_KEY_DESCRIPTOR *KeyConvertionTable;
151 EFI_EVENT KeyboardLayoutEvent;
152 } USB_KB_DEV;
153
154 //
155 // Global Variables
156 //
157 extern EFI_DRIVER_BINDING_PROTOCOL gUsbKeyboardDriverBinding;
158 extern EFI_COMPONENT_NAME_PROTOCOL gUsbKeyboardComponentName;
159 extern EFI_COMPONENT_NAME2_PROTOCOL gUsbKeyboardComponentName2;
160 extern EFI_GUID gSimpleTextInExNotifyGuid;
161
162 #define USB_KB_DEV_FROM_THIS(a) \
163 CR(a, USB_KB_DEV, SimpleInput, USB_KB_DEV_SIGNATURE)
164 #define TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS(a) \
165 CR(a, USB_KB_DEV, SimpleInputEx, USB_KB_DEV_SIGNATURE)
166
167 //
168 // According to Universal Serial Bus HID Usage Tables document ver 1.12,
169 // a Boot Keyboard should support the keycode range from 0x0 to 0x65 and 0xE0 to 0xE7.
170 // 0xE0 to 0xE7 are for modifier keys, and 0x0 to 0x3 are reserved for typical
171 // keyboard status or keyboard errors.
172 // So the number of valid non-modifier USB keycodes is 0x62, and the number of
173 // valid keycodes is 0x6A.
174 //
175 #define NUMBER_OF_VALID_NON_MODIFIER_USB_KEYCODE 0x62
176 #define NUMBER_OF_VALID_USB_KEYCODE 0x6A
177 //
178 // 0x0 to 0x3 are reserved for typical keyboard status or keyboard errors.
179 //
180 #define USBKBD_VALID_KEYCODE(Key) ((UINT8) (Key) > 3)
181
182 typedef struct {
183 UINT8 NumLock : 1;
184 UINT8 CapsLock : 1;
185 UINT8 ScrollLock : 1;
186 UINT8 Resrvd : 5;
187 } LED_MAP;
188
189 //
190 // Functions of Driver Binding Protocol
191 //
192 /**
193 Check whether USB keyboard driver supports this device.
194
195 @param This The USB keyboard driver binding protocol.
196 @param Controller The controller handle to check.
197 @param RemainingDevicePath The remaining device path.
198
199 @retval EFI_SUCCESS The driver supports this controller.
200 @retval other This device isn't supported.
201
202 **/
203 EFI_STATUS
204 EFIAPI
205 USBKeyboardDriverBindingSupported (
206 IN EFI_DRIVER_BINDING_PROTOCOL *This,
207 IN EFI_HANDLE Controller,
208 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
209 );
210
211 /**
212 Starts the device with this driver.
213
214 This function produces Simple Text Input Protocol and Simple Text Input Ex Protocol,
215 initializes the keyboard device, and submit Asynchronous Interrupt Transfer to manage
216 this keyboard device.
217
218 @param This The USB keyboard driver binding instance.
219 @param Controller Handle of device to bind driver to.
220 @param RemainingDevicePath Optional parameter use to pick a specific child
221 device to start.
222
223 @retval EFI_SUCCESS The controller is controlled by the usb keyboard driver.
224 @retval EFI_UNSUPPORTED No interrupt endpoint can be found.
225 @retval Other This controller cannot be started.
226
227 **/
228 EFI_STATUS
229 EFIAPI
230 USBKeyboardDriverBindingStart (
231 IN EFI_DRIVER_BINDING_PROTOCOL *This,
232 IN EFI_HANDLE Controller,
233 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
234 );
235
236 /**
237 Stop the USB keyboard device handled by this driver.
238
239 @param This The USB keyboard driver binding protocol.
240 @param Controller The controller to release.
241 @param NumberOfChildren The number of handles in ChildHandleBuffer.
242 @param ChildHandleBuffer The array of child handle.
243
244 @retval EFI_SUCCESS The device was stopped.
245 @retval EFI_UNSUPPORTED Simple Text In Protocol or Simple Text In Ex Protocol
246 is not installed on Controller.
247 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
248 @retval Others Fail to uninstall protocols attached on the device.
249
250 **/
251 EFI_STATUS
252 EFIAPI
253 USBKeyboardDriverBindingStop (
254 IN EFI_DRIVER_BINDING_PROTOCOL *This,
255 IN EFI_HANDLE Controller,
256 IN UINTN NumberOfChildren,
257 IN EFI_HANDLE *ChildHandleBuffer
258 );
259
260 //
261 // EFI Component Name Functions
262 //
263 /**
264 Retrieves a Unicode string that is the user readable name of the driver.
265
266 This function retrieves the user readable name of a driver in the form of a
267 Unicode string. If the driver specified by This has a user readable name in
268 the language specified by Language, then a pointer to the driver name is
269 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
270 by This does not support the language specified by Language,
271 then EFI_UNSUPPORTED is returned.
272
273 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
274 EFI_COMPONENT_NAME_PROTOCOL instance.
275 @param Language A pointer to a Null-terminated ASCII string
276 array indicating the language. This is the
277 language of the driver name that the caller is
278 requesting, and it must match one of the
279 languages specified in SupportedLanguages. The
280 number of languages supported by a driver is up
281 to the driver writer. Language is specified
282 in RFC 3066 or ISO 639-2 language code format.
283 @param DriverName A pointer to the Unicode string to return.
284 This Unicode string is the name of the
285 driver specified by This in the language
286 specified by Language.
287
288 @retval EFI_SUCCESS The Unicode string for the Driver specified by
289 This and the language specified by Language was
290 returned in DriverName.
291 @retval EFI_INVALID_PARAMETER Language is NULL.
292 @retval EFI_INVALID_PARAMETER DriverName is NULL.
293 @retval EFI_UNSUPPORTED The driver specified by This does not support
294 the language specified by Language.
295
296 **/
297 EFI_STATUS
298 EFIAPI
299 UsbKeyboardComponentNameGetDriverName (
300 IN EFI_COMPONENT_NAME_PROTOCOL *This,
301 IN CHAR8 *Language,
302 OUT CHAR16 **DriverName
303 );
304
305 /**
306 Retrieves a Unicode string that is the user readable name of the controller
307 that is being managed by a driver.
308
309 This function retrieves the user readable name of the controller specified by
310 ControllerHandle and ChildHandle in the form of a Unicode string. If the
311 driver specified by This has a user readable name in the language specified by
312 Language, then a pointer to the controller name is returned in ControllerName,
313 and EFI_SUCCESS is returned. If the driver specified by This is not currently
314 managing the controller specified by ControllerHandle and ChildHandle,
315 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
316 support the language specified by Language, then EFI_UNSUPPORTED is returned.
317
318 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
319 EFI_COMPONENT_NAME_PROTOCOL instance.
320 @param ControllerHandle The handle of a controller that the driver
321 specified by This is managing. This handle
322 specifies the controller whose name is to be
323 returned.
324 @param ChildHandle The handle of the child controller to retrieve
325 the name of. This is an optional parameter that
326 may be NULL. It will be NULL for device
327 drivers. It will also be NULL for a bus drivers
328 that wish to retrieve the name of the bus
329 controller. It will not be NULL for a bus
330 driver that wishes to retrieve the name of a
331 child controller.
332 @param Language A pointer to a Null-terminated ASCII string
333 array indicating the language. This is the
334 language of the driver name that the caller is
335 requesting, and it must match one of the
336 languages specified in SupportedLanguages. The
337 number of languages supported by a driver is up
338 to the driver writer. Language is specified in
339 RFC 3066 or ISO 639-2 language code format.
340 @param ControllerName A pointer to the Unicode string to return.
341 This Unicode string is the name of the
342 controller specified by ControllerHandle and
343 ChildHandle in the language specified by
344 Language from the point of view of the driver
345 specified by This.
346
347 @retval EFI_SUCCESS The Unicode string for the user readable name in
348 the language specified by Language for the
349 driver specified by This was returned in
350 DriverName.
351 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
352 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
353 EFI_HANDLE.
354 @retval EFI_INVALID_PARAMETER Language is NULL.
355 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
356 @retval EFI_UNSUPPORTED The driver specified by This is not currently
357 managing the controller specified by
358 ControllerHandle and ChildHandle.
359 @retval EFI_UNSUPPORTED The driver specified by This does not support
360 the language specified by Language.
361
362 **/
363 EFI_STATUS
364 EFIAPI
365 UsbKeyboardComponentNameGetControllerName (
366 IN EFI_COMPONENT_NAME_PROTOCOL *This,
367 IN EFI_HANDLE ControllerHandle,
368 IN EFI_HANDLE ChildHandle OPTIONAL,
369 IN CHAR8 *Language,
370 OUT CHAR16 **ControllerName
371 );
372
373 //
374 // Functions of Simple Text Input Protocol
375 //
376 /**
377 Reset the input device and optionaly run diagnostics
378
379 There are 2 types of reset for USB keyboard.
380 For non-exhaustive reset, only keyboard buffer is cleared.
381 For exhaustive reset, in addition to clearance of keyboard buffer, the hardware status
382 is also re-initialized.
383
384 @param This Protocol instance pointer.
385 @param ExtendedVerification Driver may perform diagnostics on reset.
386
387 @retval EFI_SUCCESS The device was reset.
388 @retval EFI_DEVICE_ERROR The device is not functioning properly and could not be reset.
389
390 **/
391 EFI_STATUS
392 EFIAPI
393 USBKeyboardReset (
394 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
395 IN BOOLEAN ExtendedVerification
396 );
397
398 /**
399 Reads the next keystroke from the input device.
400
401 @param This The EFI_SIMPLE_TEXT_INPUT_PROTOCOL instance.
402 @param Key A pointer to a buffer that is filled in with the keystroke
403 information for the key that was pressed.
404
405 @retval EFI_SUCCESS The keystroke information was returned.
406 @retval EFI_NOT_READY There was no keystroke data availiable.
407 @retval EFI_DEVICE_ERROR The keydtroke information was not returned due to
408 hardware errors.
409
410 **/
411 EFI_STATUS
412 EFIAPI
413 USBKeyboardReadKeyStroke (
414 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
415 OUT EFI_INPUT_KEY *Key
416 );
417
418 //
419 // Simple Text Input Ex protocol functions
420 //
421 /**
422 Resets the input device hardware.
423
424 The Reset() function resets the input device hardware. As part
425 of initialization process, the firmware/device will make a quick
426 but reasonable attempt to verify that the device is functioning.
427 If the ExtendedVerification flag is TRUE the firmware may take
428 an extended amount of time to verify the device is operating on
429 reset. Otherwise the reset operation is to occur as quickly as
430 possible. The hardware verification process is not defined by
431 this specification and is left up to the platform firmware or
432 driver to implement.
433
434 @param This A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
435
436 @param ExtendedVerification Indicates that the driver may perform a more exhaustive
437 verification operation of the device during reset.
438
439 @retval EFI_SUCCESS The device was reset.
440 @retval EFI_DEVICE_ERROR The device is not functioning correctly and could not be reset.
441
442 **/
443 EFI_STATUS
444 EFIAPI
445 USBKeyboardResetEx (
446 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
447 IN BOOLEAN ExtendedVerification
448 );
449
450 /**
451 Reads the next keystroke from the input device.
452
453 @param This Protocol instance pointer.
454 @param KeyData A pointer to a buffer that is filled in with the keystroke
455 state data for the key that was pressed.
456
457 @retval EFI_SUCCESS The keystroke information was returned.
458 @retval EFI_NOT_READY There was no keystroke data available.
459 @retval EFI_DEVICE_ERROR The keystroke information was not returned due to
460 hardware errors.
461 @retval EFI_INVALID_PARAMETER KeyData is NULL.
462
463 **/
464 EFI_STATUS
465 EFIAPI
466 USBKeyboardReadKeyStrokeEx (
467 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
468 OUT EFI_KEY_DATA *KeyData
469 );
470
471 /**
472 Set certain state for the input device.
473
474 @param This Protocol instance pointer.
475 @param KeyToggleState A pointer to the EFI_KEY_TOGGLE_STATE to set the
476 state for the input device.
477
478 @retval EFI_SUCCESS The device state was set appropriately.
479 @retval EFI_DEVICE_ERROR The device is not functioning correctly and could
480 not have the setting adjusted.
481 @retval EFI_UNSUPPORTED The device does not support the ability to have its state set.
482 @retval EFI_INVALID_PARAMETER KeyToggleState is NULL.
483
484 **/
485 EFI_STATUS
486 EFIAPI
487 USBKeyboardSetState (
488 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
489 IN EFI_KEY_TOGGLE_STATE *KeyToggleState
490 );
491
492 /**
493 Register a notification function for a particular keystroke for the input device.
494
495 @param This Protocol instance pointer.
496 @param KeyData A pointer to a buffer that is filled in with the keystroke
497 information data for the key that was pressed.
498 @param KeyNotificationFunction Points to the function to be called when the key
499 sequence is typed specified by KeyData.
500 @param NotifyHandle Points to the unique handle assigned to the registered notification.
501
502 @retval EFI_SUCCESS The notification function was registered successfully.
503 @retval EFI_OUT_OF_RESOURCES Unable to allocate resources for necesssary data structures.
504 @retval EFI_INVALID_PARAMETER KeyData or NotifyHandle or KeyNotificationFunction is NULL.
505
506 **/
507 EFI_STATUS
508 EFIAPI
509 USBKeyboardRegisterKeyNotify (
510 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
511 IN EFI_KEY_DATA *KeyData,
512 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction,
513 OUT EFI_HANDLE *NotifyHandle
514 );
515
516 /**
517 Remove a registered notification function from a particular keystroke.
518
519 @param This Protocol instance pointer.
520 @param NotificationHandle The handle of the notification function being unregistered.
521
522 @retval EFI_SUCCESS The notification function was unregistered successfully.
523 @retval EFI_INVALID_PARAMETER The NotificationHandle is invalid
524 @retval EFI_NOT_FOUND Cannot find the matching entry in database.
525
526 **/
527 EFI_STATUS
528 EFIAPI
529 USBKeyboardUnregisterKeyNotify (
530 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
531 IN EFI_HANDLE NotificationHandle
532 );
533
534 /**
535 Event notification function registered for EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx
536 and EFI_SIMPLE_TEXT_INPUT_PROTOCOL.WaitForKey.
537
538 @param Event Event to be signaled when a key is pressed.
539 @param Context Points to USB_KB_DEV instance.
540
541 **/
542 VOID
543 EFIAPI
544 USBKeyboardWaitForKey (
545 IN EFI_EVENT Event,
546 IN VOID *Context
547 );
548
549 /**
550 Free keyboard notify list.
551
552 @param NotifyList The keyboard notify list to free.
553
554 @retval EFI_SUCCESS Free the notify list successfully.
555 @retval EFI_INVALID_PARAMETER NotifyList is NULL.
556
557 **/
558 EFI_STATUS
559 EFIAPI
560 KbdFreeNotifyList (
561 IN OUT LIST_ENTRY *NotifyList
562 );
563
564 /**
565 Check whether there is key pending in the keyboard buffer.
566
567 @param UsbKeyboardDevice The USB_KB_DEV instance.
568
569 @retval EFI_SUCCESS There is pending key to read.
570 @retval EFI_NOT_READY No pending key to read.
571
572 **/
573 EFI_STATUS
574 EFIAPI
575 USBKeyboardCheckForKey (
576 IN OUT USB_KB_DEV *UsbKeyboardDevice
577 );
578
579 /**
580 Check whether the pressed key matches a registered key or not.
581
582 @param RegsiteredData A pointer to keystroke data for the key that was registered.
583 @param InputData A pointer to keystroke data for the key that was pressed.
584
585 @retval TRUE Key pressed matches a registered key.
586 @retval FLASE Key pressed does not matche a registered key.
587
588 **/
589 BOOLEAN
590 EFIAPI
591 IsKeyRegistered (
592 IN EFI_KEY_DATA *RegsiteredData,
593 IN EFI_KEY_DATA *InputData
594 );
595
596 #endif
597