2 Header file for USB Keyboard Driver's Data Structures.
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
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.
14 #ifndef _EFI_USB_KB_H_
15 #define _EFI_USB_KB_H_
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>
26 #include <Guid/HiiKeyBoardLayout.h>
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>
39 #include <IndustryStandard/Usb.h>
41 #define MAX_KEY_ALLOWED 32
43 #define HZ 1000 * 1000 * 10
44 #define USBKBD_REPEAT_DELAY ((HZ) / 2)
45 #define USBKBD_REPEAT_RATE ((HZ) / 50)
48 #define SUBCLASS_BOOT 1
49 #define PROTOCOL_KEYBOARD 1
51 #define BOOT_PROTOCOL 0
52 #define REPORT_PROTOCOL 1
60 USB_KEY Buffer
[MAX_KEY_ALLOWED
+ 1];
65 #define USB_KB_DEV_SIGNATURE SIGNATURE_32 ('u', 'k', 'b', 'd')
66 #define USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE SIGNATURE_32 ('u', 'k', 'b', 'x')
68 typedef struct _KEYBOARD_CONSOLE_IN_EX_NOTIFY
{
70 EFI_HANDLE NotifyHandle
;
72 EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn
;
73 LIST_ENTRY NotifyEntry
;
74 } KEYBOARD_CONSOLE_IN_EX_NOTIFY
;
76 #define USB_NS_KEY_SIGNATURE SIGNATURE_32 ('u', 'n', 's', 'k')
83 // The number of EFI_NS_KEY_MODIFIER children definitions
88 // NsKey[0] : Non-spacing key
89 // NsKey[1] ~ NsKey[KeyCount] : Physical keys
91 EFI_KEY_DESCRIPTOR
*NsKey
;
94 #define USB_NS_KEY_FORM_FROM_LINK(a) CR (a, USB_NS_KEY, Link, USB_NS_KEY_SIGNATURE)
97 /// Structure to describe USB keyboard device
101 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
102 EFI_EVENT DelayedRecoveryEvent
;
103 EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleInput
;
104 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL SimpleInputEx
;
105 EFI_USB_IO_PROTOCOL
*UsbIo
;
107 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor
;
108 EFI_USB_ENDPOINT_DESCRIPTOR IntEndpointDescriptor
;
110 USB_KB_BUFFER KeyboardBuffer
;
117 UINT8 LastKeyCodeArray
[8];
121 EFI_EVENT RepeatTimer
;
123 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
131 BOOLEAN RightShiftOn
;
137 EFI_KEY_STATE KeyState
;
139 // Notification function list
141 LIST_ENTRY NotifyList
;
144 // Non-spacing key list
146 LIST_ENTRY NsKeyList
;
147 USB_NS_KEY
*CurrentNsKey
;
148 EFI_KEY_DESCRIPTOR
*KeyConvertionTable
;
149 EFI_EVENT KeyboardLayoutEvent
;
155 extern EFI_DRIVER_BINDING_PROTOCOL gUsbKeyboardDriverBinding
;
156 extern EFI_COMPONENT_NAME_PROTOCOL gUsbKeyboardComponentName
;
157 extern EFI_COMPONENT_NAME2_PROTOCOL gUsbKeyboardComponentName2
;
159 #define USB_KB_DEV_FROM_THIS(a) \
160 CR(a, USB_KB_DEV, SimpleInput, USB_KB_DEV_SIGNATURE)
161 #define TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS(a) \
162 CR(a, USB_KB_DEV, SimpleInputEx, USB_KB_DEV_SIGNATURE)
165 // According to Universal Serial Bus HID Usage Tables document ver 1.12,
166 // a Boot Keyboard should support the keycode range from 0x0 to 0x65 and 0xE0 to 0xE7.
167 // 0xE0 to 0xE7 are for modifier keys, and 0x0 to 0x3 are reserved for typical
168 // keyboard status or keyboard errors.
169 // So the number of valid non-modifier USB keycodes is 0x62, and the number of
170 // valid keycodes is 0x6A.
172 #define NUMBER_OF_VALID_NON_MODIFIER_USB_KEYCODE 0x62
173 #define NUMBER_OF_VALID_USB_KEYCODE 0x6A
175 // 0x0 to 0x3 are reserved for typical keyboard status or keyboard errors.
177 #define USBKBD_VALID_KEYCODE(Key) ((UINT8) (Key) > 3)
182 UINT8 ScrollLock
: 1;
187 // Functions of Driver Binding Protocol
190 Check whether USB keyboard driver supports this device.
192 @param This The USB keyboard driver binding protocol.
193 @param Controller The controller handle to check.
194 @param RemainingDevicePath The remaining device path.
196 @retval EFI_SUCCESS The driver supports this controller.
197 @retval other This device isn't supported.
202 USBKeyboardDriverBindingSupported (
203 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
204 IN EFI_HANDLE Controller
,
205 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
209 Starts the keyboard device with this driver.
211 This function produces Simple Text Input Protocol and Simple Text Input Ex Protocol,
212 initializes the keyboard device, and submit Asynchronous Interrupt Transfer to manage
213 this keyboard device.
215 @param This The USB keyboard driver binding instance.
216 @param Controller Handle of device to bind driver to.
217 @param RemainingDevicePath Optional parameter use to pick a specific child
220 @retval EFI_SUCCESS The controller is controlled by the usb keyboard driver.
221 @retval EFI_UNSUPPORTED No interrupt endpoint can be found.
222 @retval Other This controller cannot be started.
227 USBKeyboardDriverBindingStart (
228 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
229 IN EFI_HANDLE Controller
,
230 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
234 Stop the USB keyboard device handled by this driver.
236 @param This The USB keyboard driver binding protocol.
237 @param Controller The controller to release.
238 @param NumberOfChildren The number of handles in ChildHandleBuffer.
239 @param ChildHandleBuffer The array of child handle.
241 @retval EFI_SUCCESS The device was stopped.
242 @retval EFI_UNSUPPORTED Simple Text In Protocol or Simple Text In Ex Protocol
243 is not installed on Controller.
244 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
245 @retval Others Fail to uninstall protocols attached on the device.
250 USBKeyboardDriverBindingStop (
251 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
252 IN EFI_HANDLE Controller
,
253 IN UINTN NumberOfChildren
,
254 IN EFI_HANDLE
*ChildHandleBuffer
258 // EFI Component Name Functions
261 Retrieves a Unicode string that is the user readable name of the driver.
263 This function retrieves the user readable name of a driver in the form of a
264 Unicode string. If the driver specified by This has a user readable name in
265 the language specified by Language, then a pointer to the driver name is
266 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
267 by This does not support the language specified by Language,
268 then EFI_UNSUPPORTED is returned.
270 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
271 EFI_COMPONENT_NAME_PROTOCOL instance.
272 @param Language A pointer to a Null-terminated ASCII string
273 array indicating the language. This is the
274 language of the driver name that the caller is
275 requesting, and it must match one of the
276 languages specified in SupportedLanguages. The
277 number of languages supported by a driver is up
278 to the driver writer. Language is specified
279 in RFC 3066 or ISO 639-2 language code format.
280 @param DriverName A pointer to the Unicode string to return.
281 This Unicode string is the name of the
282 driver specified by This in the language
283 specified by Language.
285 @retval EFI_SUCCESS The Unicode string for the Driver specified by
286 This and the language specified by Language was
287 returned in DriverName.
288 @retval EFI_INVALID_PARAMETER Language is NULL.
289 @retval EFI_INVALID_PARAMETER DriverName is NULL.
290 @retval EFI_UNSUPPORTED The driver specified by This does not support
291 the language specified by Language.
296 UsbKeyboardComponentNameGetDriverName (
297 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
299 OUT CHAR16
**DriverName
303 Retrieves a Unicode string that is the user readable name of the controller
304 that is being managed by a driver.
306 This function retrieves the user readable name of the controller specified by
307 ControllerHandle and ChildHandle in the form of a Unicode string. If the
308 driver specified by This has a user readable name in the language specified by
309 Language, then a pointer to the controller name is returned in ControllerName,
310 and EFI_SUCCESS is returned. If the driver specified by This is not currently
311 managing the controller specified by ControllerHandle and ChildHandle,
312 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
313 support the language specified by Language, then EFI_UNSUPPORTED is returned.
315 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
316 EFI_COMPONENT_NAME_PROTOCOL instance.
317 @param ControllerHandle The handle of a controller that the driver
318 specified by This is managing. This handle
319 specifies the controller whose name is to be
321 @param ChildHandle The handle of the child controller to retrieve
322 the name of. This is an optional parameter that
323 may be NULL. It will be NULL for device
324 drivers. It will also be NULL for a bus drivers
325 that wish to retrieve the name of the bus
326 controller. It will not be NULL for a bus
327 driver that wishes to retrieve the name of a
329 @param Language A pointer to a Null-terminated ASCII string
330 array indicating the language. This is the
331 language of the driver name that the caller is
332 requesting, and it must match one of the
333 languages specified in SupportedLanguages. The
334 number of languages supported by a driver is up
335 to the driver writer. Language is specified in
336 RFC 3066 or ISO 639-2 language code format.
337 @param ControllerName A pointer to the Unicode string to return.
338 This Unicode string is the name of the
339 controller specified by ControllerHandle and
340 ChildHandle in the language specified by
341 Language from the point of view of the driver
344 @retval EFI_SUCCESS The Unicode string for the user readable name in
345 the language specified by Language for the
346 driver specified by This was returned in
348 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
349 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
351 @retval EFI_INVALID_PARAMETER Language is NULL.
352 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
353 @retval EFI_UNSUPPORTED The driver specified by This is not currently
354 managing the controller specified by
355 ControllerHandle and ChildHandle.
356 @retval EFI_UNSUPPORTED The driver specified by This does not support
357 the language specified by Language.
362 UsbKeyboardComponentNameGetControllerName (
363 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
364 IN EFI_HANDLE ControllerHandle
,
365 IN EFI_HANDLE ChildHandle OPTIONAL
,
367 OUT CHAR16
**ControllerName
371 // Functions of Simple Text Input Protocol
374 Reset the input device and optionaly run diagnostics
376 There are 2 types of reset for USB keyboard.
377 For non-exhaustive reset, only keyboard buffer is cleared.
378 For exhaustive reset, in addition to clearance of keyboard buffer, the hardware status
379 is also re-initialized.
381 @param This Protocol instance pointer.
382 @param ExtendedVerification Driver may perform diagnostics on reset.
384 @retval EFI_SUCCESS The device was reset.
385 @retval EFI_DEVICE_ERROR The device is not functioning properly and could not be reset.
391 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
392 IN BOOLEAN ExtendedVerification
396 Reads the next keystroke from the input device.
398 @param This The EFI_SIMPLE_TEXT_INPUT_PROTOCOL instance.
399 @param Key A pointer to a buffer that is filled in with the keystroke
400 information for the key that was pressed.
402 @retval EFI_SUCCESS The keystroke information was returned.
403 @retval EFI_NOT_READY There was no keystroke data availiable.
404 @retval EFI_DEVICE_ERROR The keydtroke information was not returned due to
410 USBKeyboardReadKeyStroke (
411 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
412 OUT EFI_INPUT_KEY
*Key
416 // Simple Text Input Ex protocol functions
419 Resets the input device hardware.
421 The Reset() function resets the input device hardware. As part
422 of initialization process, the firmware/device will make a quick
423 but reasonable attempt to verify that the device is functioning.
424 If the ExtendedVerification flag is TRUE the firmware may take
425 an extended amount of time to verify the device is operating on
426 reset. Otherwise the reset operation is to occur as quickly as
427 possible. The hardware verification process is not defined by
428 this specification and is left up to the platform firmware or
431 @param This A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
433 @param ExtendedVerification Indicates that the driver may perform a more exhaustive
434 verification operation of the device during reset.
436 @retval EFI_SUCCESS The device was reset.
437 @retval EFI_DEVICE_ERROR The device is not functioning correctly and could not be reset.
443 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
444 IN BOOLEAN ExtendedVerification
448 Reads the next keystroke from the input device.
450 @param This Protocol instance pointer.
451 @param KeyData A pointer to a buffer that is filled in with the keystroke
452 state data for the key that was pressed.
454 @retval EFI_SUCCESS The keystroke information was returned.
455 @retval EFI_NOT_READY There was no keystroke data available.
456 @retval EFI_DEVICE_ERROR The keystroke information was not returned due to
458 @retval EFI_INVALID_PARAMETER KeyData is NULL.
463 USBKeyboardReadKeyStrokeEx (
464 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
465 OUT EFI_KEY_DATA
*KeyData
469 Set certain state for the input device.
471 @param This Protocol instance pointer.
472 @param KeyToggleState A pointer to the EFI_KEY_TOGGLE_STATE to set the
473 state for the input device.
475 @retval EFI_SUCCESS The device state was set appropriately.
476 @retval EFI_DEVICE_ERROR The device is not functioning correctly and could
477 not have the setting adjusted.
478 @retval EFI_UNSUPPORTED The device does not support the ability to have its state set.
479 @retval EFI_INVALID_PARAMETER KeyToggleState is NULL.
484 USBKeyboardSetState (
485 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
486 IN EFI_KEY_TOGGLE_STATE
*KeyToggleState
490 Register a notification function for a particular keystroke for the input device.
492 @param This Protocol instance pointer.
493 @param KeyData A pointer to a buffer that is filled in with the keystroke
494 information data for the key that was pressed.
495 @param KeyNotificationFunction Points to the function to be called when the key
496 sequence is typed specified by KeyData.
497 @param NotifyHandle Points to the unique handle assigned to the registered notification.
499 @retval EFI_SUCCESS The notification function was registered successfully.
500 @retval EFI_OUT_OF_RESOURCES Unable to allocate resources for necesssary data structures.
501 @retval EFI_INVALID_PARAMETER KeyData or NotifyHandle or KeyNotificationFunction is NULL.
506 USBKeyboardRegisterKeyNotify (
507 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
508 IN EFI_KEY_DATA
*KeyData
,
509 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction
,
510 OUT EFI_HANDLE
*NotifyHandle
514 Remove a registered notification function from a particular keystroke.
516 @param This Protocol instance pointer.
517 @param NotificationHandle The handle of the notification function being unregistered.
519 @retval EFI_SUCCESS The notification function was unregistered successfully.
520 @retval EFI_INVALID_PARAMETER The NotificationHandle is invalid
521 @retval EFI_NOT_FOUND Cannot find the matching entry in database.
526 USBKeyboardUnregisterKeyNotify (
527 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
528 IN EFI_HANDLE NotificationHandle
532 Event notification function registered for EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx
533 and EFI_SIMPLE_TEXT_INPUT_PROTOCOL.WaitForKey.
535 @param Event Event to be signaled when a key is pressed.
536 @param Context Points to USB_KB_DEV instance.
541 USBKeyboardWaitForKey (
547 Free keyboard notify list.
549 @param NotifyList The keyboard notify list to free.
551 @retval EFI_SUCCESS Free the notify list successfully.
552 @retval EFI_INVALID_PARAMETER NotifyList is NULL.
558 IN OUT LIST_ENTRY
*NotifyList
562 Check whether there is key pending in the keyboard buffer.
564 @param UsbKeyboardDevice The USB_KB_DEV instance.
566 @retval EFI_SUCCESS There is pending key to read.
567 @retval EFI_NOT_READY No pending key to read.
572 USBKeyboardCheckForKey (
573 IN OUT USB_KB_DEV
*UsbKeyboardDevice
577 Check whether the pressed key matches a registered key or not.
579 @param RegsiteredData A pointer to keystroke data for the key that was registered.
580 @param InputData A pointer to keystroke data for the key that was pressed.
582 @retval TRUE Key pressed matches a registered key.
583 @retval FLASE Key pressed does not matche a registered key.
589 IN EFI_KEY_DATA
*RegsiteredData
,
590 IN EFI_KEY_DATA
*InputData