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 <Protocol/SimpleTextInExNotify.h>
26 #include <Protocol/HotPlugDevice.h>
28 #include <Guid/HiiKeyBoardLayout.h>
30 #include <Library/DebugLib.h>
31 #include <Library/ReportStatusCodeLib.h>
32 #include <Library/BaseMemoryLib.h>
33 #include <Library/UefiRuntimeServicesTableLib.h>
34 #include <Library/UefiDriverEntryPoint.h>
35 #include <Library/UefiBootServicesTableLib.h>
36 #include <Library/UefiLib.h>
37 #include <Library/MemoryAllocationLib.h>
38 #include <Library/PcdLib.h>
39 #include <Library/UefiUsbLib.h>
40 #include <Library/BaseLib.h>
41 #include <Library/UefiUsbLib.h>
43 #include <IndustryStandard/Usb.h>
45 #define MAX_KEY_ALLOWED 32
47 #define HZ 1000 * 1000 * 10
48 #define USBKBD_REPEAT_DELAY ((HZ) / 2)
49 #define USBKBD_REPEAT_RATE ((HZ) / 50)
52 #define SUBCLASS_BOOT 1
53 #define PROTOCOL_KEYBOARD 1
55 #define BOOT_PROTOCOL 0
56 #define REPORT_PROTOCOL 1
64 USB_KEY Buffer
[MAX_KEY_ALLOWED
+ 1];
69 #define USB_KB_DEV_SIGNATURE SIGNATURE_32 ('u', 'k', 'b', 'd')
70 #define USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE SIGNATURE_32 ('u', 'k', 'b', 'x')
72 typedef struct _KEYBOARD_CONSOLE_IN_EX_NOTIFY
{
74 EFI_HANDLE NotifyHandle
;
76 EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn
;
77 LIST_ENTRY NotifyEntry
;
78 } KEYBOARD_CONSOLE_IN_EX_NOTIFY
;
80 #define USB_NS_KEY_SIGNATURE SIGNATURE_32 ('u', 'n', 's', 'k')
87 // The number of EFI_NS_KEY_MODIFIER children definitions
92 // NsKey[0] : Non-spacing key
93 // NsKey[1] ~ NsKey[KeyCount] : Physical keys
95 EFI_KEY_DESCRIPTOR
*NsKey
;
98 #define USB_NS_KEY_FORM_FROM_LINK(a) CR (a, USB_NS_KEY, Link, USB_NS_KEY_SIGNATURE)
101 /// Structure to describe USB keyboard device
105 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
106 EFI_EVENT DelayedRecoveryEvent
;
107 EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleInput
;
108 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL SimpleInputEx
;
109 EFI_USB_IO_PROTOCOL
*UsbIo
;
111 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor
;
112 EFI_USB_ENDPOINT_DESCRIPTOR IntEndpointDescriptor
;
114 USB_KB_BUFFER KeyboardBuffer
;
121 UINT8 LastKeyCodeArray
[8];
125 EFI_EVENT RepeatTimer
;
127 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
135 BOOLEAN RightShiftOn
;
141 EFI_KEY_STATE KeyState
;
143 // Notification function list
145 LIST_ENTRY NotifyList
;
148 // Non-spacing key list
150 LIST_ENTRY NsKeyList
;
151 USB_NS_KEY
*CurrentNsKey
;
152 EFI_KEY_DESCRIPTOR
*KeyConvertionTable
;
153 EFI_EVENT KeyboardLayoutEvent
;
159 extern EFI_DRIVER_BINDING_PROTOCOL gUsbKeyboardDriverBinding
;
160 extern EFI_COMPONENT_NAME_PROTOCOL gUsbKeyboardComponentName
;
161 extern EFI_COMPONENT_NAME2_PROTOCOL gUsbKeyboardComponentName2
;
163 #define USB_KB_DEV_FROM_THIS(a) \
164 CR(a, USB_KB_DEV, SimpleInput, USB_KB_DEV_SIGNATURE)
165 #define TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS(a) \
166 CR(a, USB_KB_DEV, SimpleInputEx, USB_KB_DEV_SIGNATURE)
169 // According to Universal Serial Bus HID Usage Tables document ver 1.12,
170 // a Boot Keyboard should support the keycode range from 0x0 to 0x65 and 0xE0 to 0xE7.
171 // 0xE0 to 0xE7 are for modifier keys, and 0x0 to 0x3 are reserved for typical
172 // keyboard status or keyboard errors.
173 // So the number of valid non-modifier USB keycodes is 0x62, and the number of
174 // valid keycodes is 0x6A.
176 #define NUMBER_OF_VALID_NON_MODIFIER_USB_KEYCODE 0x62
177 #define NUMBER_OF_VALID_USB_KEYCODE 0x6A
179 // 0x0 to 0x3 are reserved for typical keyboard status or keyboard errors.
181 #define USBKBD_VALID_KEYCODE(Key) ((UINT8) (Key) > 3)
186 UINT8 ScrollLock
: 1;
191 // Functions of Driver Binding Protocol
194 Check whether USB keyboard driver supports this device.
196 @param This The USB keyboard driver binding protocol.
197 @param Controller The controller handle to check.
198 @param RemainingDevicePath The remaining device path.
200 @retval EFI_SUCCESS The driver supports this controller.
201 @retval other This device isn't supported.
206 USBKeyboardDriverBindingSupported (
207 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
208 IN EFI_HANDLE Controller
,
209 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
213 Starts the keyboard device with this driver.
215 This function produces Simple Text Input Protocol and Simple Text Input Ex Protocol,
216 initializes the keyboard device, and submit Asynchronous Interrupt Transfer to manage
217 this keyboard device.
219 @param This The USB keyboard driver binding instance.
220 @param Controller Handle of device to bind driver to.
221 @param RemainingDevicePath Optional parameter use to pick a specific child
224 @retval EFI_SUCCESS The controller is controlled by the usb keyboard driver.
225 @retval EFI_UNSUPPORTED No interrupt endpoint can be found.
226 @retval Other This controller cannot be started.
231 USBKeyboardDriverBindingStart (
232 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
233 IN EFI_HANDLE Controller
,
234 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
238 Stop the USB keyboard device handled by this driver.
240 @param This The USB keyboard driver binding protocol.
241 @param Controller The controller to release.
242 @param NumberOfChildren The number of handles in ChildHandleBuffer.
243 @param ChildHandleBuffer The array of child handle.
245 @retval EFI_SUCCESS The device was stopped.
246 @retval EFI_UNSUPPORTED Simple Text In Protocol or Simple Text In Ex Protocol
247 is not installed on Controller.
248 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
249 @retval Others Fail to uninstall protocols attached on the device.
254 USBKeyboardDriverBindingStop (
255 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
256 IN EFI_HANDLE Controller
,
257 IN UINTN NumberOfChildren
,
258 IN EFI_HANDLE
*ChildHandleBuffer
262 // EFI Component Name Functions
265 Retrieves a Unicode string that is the user readable name of the driver.
267 This function retrieves the user readable name of a driver in the form of a
268 Unicode string. If the driver specified by This has a user readable name in
269 the language specified by Language, then a pointer to the driver name is
270 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
271 by This does not support the language specified by Language,
272 then EFI_UNSUPPORTED is returned.
274 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
275 EFI_COMPONENT_NAME_PROTOCOL instance.
276 @param Language A pointer to a Null-terminated ASCII string
277 array indicating the language. This is the
278 language of the driver name that the caller is
279 requesting, and it must match one of the
280 languages specified in SupportedLanguages. The
281 number of languages supported by a driver is up
282 to the driver writer. Language is specified
283 in RFC 3066 or ISO 639-2 language code format.
284 @param DriverName A pointer to the Unicode string to return.
285 This Unicode string is the name of the
286 driver specified by This in the language
287 specified by Language.
289 @retval EFI_SUCCESS The Unicode string for the Driver specified by
290 This and the language specified by Language was
291 returned in DriverName.
292 @retval EFI_INVALID_PARAMETER Language is NULL.
293 @retval EFI_INVALID_PARAMETER DriverName is NULL.
294 @retval EFI_UNSUPPORTED The driver specified by This does not support
295 the language specified by Language.
300 UsbKeyboardComponentNameGetDriverName (
301 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
303 OUT CHAR16
**DriverName
307 Retrieves a Unicode string that is the user readable name of the controller
308 that is being managed by a driver.
310 This function retrieves the user readable name of the controller specified by
311 ControllerHandle and ChildHandle in the form of a Unicode string. If the
312 driver specified by This has a user readable name in the language specified by
313 Language, then a pointer to the controller name is returned in ControllerName,
314 and EFI_SUCCESS is returned. If the driver specified by This is not currently
315 managing the controller specified by ControllerHandle and ChildHandle,
316 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
317 support the language specified by Language, then EFI_UNSUPPORTED is returned.
319 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
320 EFI_COMPONENT_NAME_PROTOCOL instance.
321 @param ControllerHandle The handle of a controller that the driver
322 specified by This is managing. This handle
323 specifies the controller whose name is to be
325 @param ChildHandle The handle of the child controller to retrieve
326 the name of. This is an optional parameter that
327 may be NULL. It will be NULL for device
328 drivers. It will also be NULL for a bus drivers
329 that wish to retrieve the name of the bus
330 controller. It will not be NULL for a bus
331 driver that wishes to retrieve the name of a
333 @param Language A pointer to a Null-terminated ASCII string
334 array indicating the language. This is the
335 language of the driver name that the caller is
336 requesting, and it must match one of the
337 languages specified in SupportedLanguages. The
338 number of languages supported by a driver is up
339 to the driver writer. Language is specified in
340 RFC 3066 or ISO 639-2 language code format.
341 @param ControllerName A pointer to the Unicode string to return.
342 This Unicode string is the name of the
343 controller specified by ControllerHandle and
344 ChildHandle in the language specified by
345 Language from the point of view of the driver
348 @retval EFI_SUCCESS The Unicode string for the user readable name in
349 the language specified by Language for the
350 driver specified by This was returned in
352 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
353 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
355 @retval EFI_INVALID_PARAMETER Language is NULL.
356 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
357 @retval EFI_UNSUPPORTED The driver specified by This is not currently
358 managing the controller specified by
359 ControllerHandle and ChildHandle.
360 @retval EFI_UNSUPPORTED The driver specified by This does not support
361 the language specified by Language.
366 UsbKeyboardComponentNameGetControllerName (
367 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
368 IN EFI_HANDLE ControllerHandle
,
369 IN EFI_HANDLE ChildHandle OPTIONAL
,
371 OUT CHAR16
**ControllerName
375 // Functions of Simple Text Input Protocol
378 Reset the input device and optionaly run diagnostics
380 There are 2 types of reset for USB keyboard.
381 For non-exhaustive reset, only keyboard buffer is cleared.
382 For exhaustive reset, in addition to clearance of keyboard buffer, the hardware status
383 is also re-initialized.
385 @param This Protocol instance pointer.
386 @param ExtendedVerification Driver may perform diagnostics on reset.
388 @retval EFI_SUCCESS The device was reset.
389 @retval EFI_DEVICE_ERROR The device is not functioning properly and could not be reset.
395 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
396 IN BOOLEAN ExtendedVerification
400 Reads the next keystroke from the input device.
402 @param This The EFI_SIMPLE_TEXT_INPUT_PROTOCOL instance.
403 @param Key A pointer to a buffer that is filled in with the keystroke
404 information for the key that was pressed.
406 @retval EFI_SUCCESS The keystroke information was returned.
407 @retval EFI_NOT_READY There was no keystroke data availiable.
408 @retval EFI_DEVICE_ERROR The keydtroke information was not returned due to
414 USBKeyboardReadKeyStroke (
415 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
416 OUT EFI_INPUT_KEY
*Key
420 // Simple Text Input Ex protocol functions
423 Resets the input device hardware.
425 The Reset() function resets the input device hardware. As part
426 of initialization process, the firmware/device will make a quick
427 but reasonable attempt to verify that the device is functioning.
428 If the ExtendedVerification flag is TRUE the firmware may take
429 an extended amount of time to verify the device is operating on
430 reset. Otherwise the reset operation is to occur as quickly as
431 possible. The hardware verification process is not defined by
432 this specification and is left up to the platform firmware or
435 @param This A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
437 @param ExtendedVerification Indicates that the driver may perform a more exhaustive
438 verification operation of the device during reset.
440 @retval EFI_SUCCESS The device was reset.
441 @retval EFI_DEVICE_ERROR The device is not functioning correctly and could not be reset.
447 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
448 IN BOOLEAN ExtendedVerification
452 Reads the next keystroke from the input device.
454 @param This Protocol instance pointer.
455 @param KeyData A pointer to a buffer that is filled in with the keystroke
456 state data for the key that was pressed.
458 @retval EFI_SUCCESS The keystroke information was returned.
459 @retval EFI_NOT_READY There was no keystroke data available.
460 @retval EFI_DEVICE_ERROR The keystroke information was not returned due to
462 @retval EFI_INVALID_PARAMETER KeyData is NULL.
467 USBKeyboardReadKeyStrokeEx (
468 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
469 OUT EFI_KEY_DATA
*KeyData
473 Set certain state for the input device.
475 @param This Protocol instance pointer.
476 @param KeyToggleState A pointer to the EFI_KEY_TOGGLE_STATE to set the
477 state for the input device.
479 @retval EFI_SUCCESS The device state was set appropriately.
480 @retval EFI_DEVICE_ERROR The device is not functioning correctly and could
481 not have the setting adjusted.
482 @retval EFI_UNSUPPORTED The device does not support the ability to have its state set.
483 @retval EFI_INVALID_PARAMETER KeyToggleState is NULL.
488 USBKeyboardSetState (
489 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
490 IN EFI_KEY_TOGGLE_STATE
*KeyToggleState
494 Register a notification function for a particular keystroke for the input device.
496 @param This Protocol instance pointer.
497 @param KeyData A pointer to a buffer that is filled in with the keystroke
498 information data for the key that was pressed.
499 @param KeyNotificationFunction Points to the function to be called when the key
500 sequence is typed specified by KeyData.
501 @param NotifyHandle Points to the unique handle assigned to the registered notification.
503 @retval EFI_SUCCESS The notification function was registered successfully.
504 @retval EFI_OUT_OF_RESOURCES Unable to allocate resources for necesssary data structures.
505 @retval EFI_INVALID_PARAMETER KeyData or NotifyHandle or KeyNotificationFunction is NULL.
510 USBKeyboardRegisterKeyNotify (
511 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
512 IN EFI_KEY_DATA
*KeyData
,
513 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction
,
514 OUT EFI_HANDLE
*NotifyHandle
518 Remove a registered notification function from a particular keystroke.
520 @param This Protocol instance pointer.
521 @param NotificationHandle The handle of the notification function being unregistered.
523 @retval EFI_SUCCESS The notification function was unregistered successfully.
524 @retval EFI_INVALID_PARAMETER The NotificationHandle is invalid
525 @retval EFI_NOT_FOUND Cannot find the matching entry in database.
530 USBKeyboardUnregisterKeyNotify (
531 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
532 IN EFI_HANDLE NotificationHandle
536 Event notification function registered for EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx
537 and EFI_SIMPLE_TEXT_INPUT_PROTOCOL.WaitForKey.
539 @param Event Event to be signaled when a key is pressed.
540 @param Context Points to USB_KB_DEV instance.
545 USBKeyboardWaitForKey (
551 Free keyboard notify list.
553 @param NotifyList The keyboard notify list to free.
555 @retval EFI_SUCCESS Free the notify list successfully.
556 @retval EFI_INVALID_PARAMETER NotifyList is NULL.
562 IN OUT LIST_ENTRY
*NotifyList
566 Check whether there is key pending in the keyboard buffer.
568 @param UsbKeyboardDevice The USB_KB_DEV instance.
570 @retval EFI_SUCCESS There is pending key to read.
571 @retval EFI_NOT_READY No pending key to read.
576 USBKeyboardCheckForKey (
577 IN OUT USB_KB_DEV
*UsbKeyboardDevice
581 Check whether the pressed key matches a registered key or not.
583 @param RegsiteredData A pointer to keystroke data for the key that was registered.
584 @param InputData A pointer to keystroke data for the key that was pressed.
586 @retval TRUE Key pressed matches a registered key.
587 @retval FLASE Key pressed does not matche a registered key.
593 IN EFI_KEY_DATA
*RegsiteredData
,
594 IN EFI_KEY_DATA
*InputData