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>
25 #include <Guid/HiiKeyBoardLayout.h>
26 #include <Guid/HotPlugDevice.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>
38 #include <Library/BaseLib.h>
39 #include <Library/UefiUsbLib.h>
41 #include <IndustryStandard/Usb.h>
43 #define MAX_KEY_ALLOWED 32
45 #define HZ 1000 * 1000 * 10
46 #define USBKBD_REPEAT_DELAY ((HZ) / 2)
47 #define USBKBD_REPEAT_RATE ((HZ) / 50)
50 #define SUBCLASS_BOOT 1
51 #define PROTOCOL_KEYBOARD 1
53 #define BOOT_PROTOCOL 0
54 #define REPORT_PROTOCOL 1
62 USB_KEY Buffer
[MAX_KEY_ALLOWED
+ 1];
67 #define USB_KB_DEV_SIGNATURE EFI_SIGNATURE_32 ('u', 'k', 'b', 'd')
68 #define USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE EFI_SIGNATURE_32 ('u', 'k', 'b', 'x')
70 typedef struct _KEYBOARD_CONSOLE_IN_EX_NOTIFY
{
72 EFI_HANDLE NotifyHandle
;
74 EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn
;
75 LIST_ENTRY NotifyEntry
;
76 } KEYBOARD_CONSOLE_IN_EX_NOTIFY
;
78 #define USB_NS_KEY_SIGNATURE EFI_SIGNATURE_32 ('u', 'n', 's', 'k')
85 // The number of EFI_NS_KEY_MODIFIER children definitions
90 // NsKey[0] : Non-spacing key
91 // NsKey[1] ~ NsKey[KeyCount] : Physical keys
93 EFI_KEY_DESCRIPTOR
*NsKey
;
96 #define USB_NS_KEY_FORM_FROM_LINK(a) CR (a, USB_NS_KEY, Link, USB_NS_KEY_SIGNATURE)
99 /// Structure to describe USB keyboard device
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
;
109 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor
;
110 EFI_USB_ENDPOINT_DESCRIPTOR IntEndpointDescriptor
;
112 USB_KB_BUFFER KeyboardBuffer
;
119 UINT8 LastKeyCodeArray
[8];
123 EFI_EVENT RepeatTimer
;
125 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
133 BOOLEAN RightShiftOn
;
139 EFI_KEY_STATE KeyState
;
141 // Notification function list
143 LIST_ENTRY NotifyList
;
146 // Non-spacing key list
148 LIST_ENTRY NsKeyList
;
149 USB_NS_KEY
*CurrentNsKey
;
150 EFI_KEY_DESCRIPTOR
*KeyConvertionTable
;
151 EFI_EVENT KeyboardLayoutEvent
;
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
;
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)
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.
175 #define NUMBER_OF_VALID_NON_MODIFIER_USB_KEYCODE 0x62
176 #define NUMBER_OF_VALID_USB_KEYCODE 0x6A
178 // 0x0 to 0x3 are reserved for typical keyboard status or keyboard errors.
180 #define USBKBD_VALID_KEYCODE(Key) ((UINT8) (Key) > 3)
185 UINT8 ScrollLock
: 1;
190 // Functions of Driver Binding Protocol
193 Check whether USB keyboard driver supports this device.
195 @param This The USB keyboard driver binding protocol.
196 @param Controller The controller handle to check.
197 @param RemainingDevicePath The remaining device path.
199 @retval EFI_SUCCESS The driver supports this controller.
200 @retval other This device isn't supported.
205 USBKeyboardDriverBindingSupported (
206 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
207 IN EFI_HANDLE Controller
,
208 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
212 Starts the device with this driver.
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.
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
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.
230 USBKeyboardDriverBindingStart (
231 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
232 IN EFI_HANDLE Controller
,
233 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
237 Stop the USB keyboard device handled by this driver.
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.
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.
253 USBKeyboardDriverBindingStop (
254 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
255 IN EFI_HANDLE Controller
,
256 IN UINTN NumberOfChildren
,
257 IN EFI_HANDLE
*ChildHandleBuffer
261 // EFI Component Name Functions
264 Retrieves a Unicode string that is the user readable name of the driver.
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.
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.
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.
299 UsbKeyboardComponentNameGetDriverName (
300 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
302 OUT CHAR16
**DriverName
306 Retrieves a Unicode string that is the user readable name of the controller
307 that is being managed by a driver.
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.
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
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
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
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
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
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.
365 UsbKeyboardComponentNameGetControllerName (
366 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
367 IN EFI_HANDLE ControllerHandle
,
368 IN EFI_HANDLE ChildHandle OPTIONAL
,
370 OUT CHAR16
**ControllerName
374 // Functions of Simple Text Input Protocol
377 Reset the input device and optionaly run diagnostics
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.
384 @param This Protocol instance pointer.
385 @param ExtendedVerification Driver may perform diagnostics on reset.
387 @retval EFI_SUCCESS The device was reset.
388 @retval EFI_DEVICE_ERROR The device is not functioning properly and could not be reset.
394 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
395 IN BOOLEAN ExtendedVerification
399 Reads the next keystroke from the input device.
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.
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
413 USBKeyboardReadKeyStroke (
414 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
415 OUT EFI_INPUT_KEY
*Key
419 // Simple Text Input Ex protocol functions
422 Resets the input device hardware.
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
434 @param This A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
436 @param ExtendedVerification Indicates that the driver may perform a more exhaustive
437 verification operation of the device during reset.
439 @retval EFI_SUCCESS The device was reset.
440 @retval EFI_DEVICE_ERROR The device is not functioning correctly and could not be reset.
446 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
447 IN BOOLEAN ExtendedVerification
451 Reads the next keystroke from the input device.
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.
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
461 @retval EFI_INVALID_PARAMETER KeyData is NULL.
466 USBKeyboardReadKeyStrokeEx (
467 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
468 OUT EFI_KEY_DATA
*KeyData
472 Set certain state for the input device.
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.
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.
487 USBKeyboardSetState (
488 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
489 IN EFI_KEY_TOGGLE_STATE
*KeyToggleState
493 Register a notification function for a particular keystroke for the input device.
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.
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.
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
517 Remove a registered notification function from a particular keystroke.
519 @param This Protocol instance pointer.
520 @param NotificationHandle The handle of the notification function being unregistered.
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.
529 USBKeyboardUnregisterKeyNotify (
530 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
531 IN EFI_HANDLE NotificationHandle
535 Event notification function registered for EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx
536 and EFI_SIMPLE_TEXT_INPUT_PROTOCOL.WaitForKey.
538 @param Event Event to be signaled when a key is pressed.
539 @param Context Points to USB_KB_DEV instance.
544 USBKeyboardWaitForKey (
550 Free keyboard notify list.
552 @param NotifyList The keyboard notify list to free.
554 @retval EFI_SUCCESS Free the notify list successfully.
555 @retval EFI_INVALID_PARAMETER NotifyList is NULL.
561 IN OUT LIST_ENTRY
*NotifyList
565 Check whether there is key pending in the keyboard buffer.
567 @param UsbKeyboardDevice The USB_KB_DEV instance.
569 @retval EFI_SUCCESS There is pending key to read.
570 @retval EFI_NOT_READY No pending key to read.
575 USBKeyboardCheckForKey (
576 IN OUT USB_KB_DEV
*UsbKeyboardDevice
580 Check whether the pressed key matches a registered key or not.
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.
585 @retval TRUE Key pressed matches a registered key.
586 @retval FLASE Key pressed does not matche a registered key.
592 IN EFI_KEY_DATA
*RegsiteredData
,
593 IN EFI_KEY_DATA
*InputData