2 Header file for USB Keyboard Driver's Data Structures.
4 Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR>
5 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>
38 #include <Library/HiiLib.h>
40 #include <IndustryStandard/Usb.h>
42 #define MAX_KEY_ALLOWED 32
44 #define HZ 1000 * 1000 * 10
45 #define USBKBD_REPEAT_DELAY ((HZ) / 2)
46 #define USBKBD_REPEAT_RATE ((HZ) / 50)
49 #define SUBCLASS_BOOT 1
50 #define PROTOCOL_KEYBOARD 1
52 #define BOOT_PROTOCOL 0
53 #define REPORT_PROTOCOL 1
61 USB_KEY Buffer
[MAX_KEY_ALLOWED
+ 1];
66 #define USB_KB_DEV_SIGNATURE SIGNATURE_32 ('u', 'k', 'b', 'd')
67 #define USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE SIGNATURE_32 ('u', 'k', 'b', 'x')
69 typedef struct _KEYBOARD_CONSOLE_IN_EX_NOTIFY
{
71 EFI_HANDLE NotifyHandle
;
73 EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn
;
74 LIST_ENTRY NotifyEntry
;
75 } KEYBOARD_CONSOLE_IN_EX_NOTIFY
;
77 #define USB_NS_KEY_SIGNATURE SIGNATURE_32 ('u', 'n', 's', 'k')
84 // The number of EFI_NS_KEY_MODIFIER children definitions
89 // NsKey[0] : Non-spacing key
90 // NsKey[1] ~ NsKey[KeyCount] : Physical keys
92 EFI_KEY_DESCRIPTOR
*NsKey
;
95 #define USB_NS_KEY_FORM_FROM_LINK(a) CR (a, USB_NS_KEY, Link, USB_NS_KEY_SIGNATURE)
98 /// Structure to describe USB keyboard device
102 EFI_HANDLE ControllerHandle
;
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
;
161 #define USB_KB_DEV_FROM_THIS(a) \
162 CR(a, USB_KB_DEV, SimpleInput, USB_KB_DEV_SIGNATURE)
163 #define TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS(a) \
164 CR(a, USB_KB_DEV, SimpleInputEx, USB_KB_DEV_SIGNATURE)
167 // According to Universal Serial Bus HID Usage Tables document ver 1.12,
168 // a Boot Keyboard should support the keycode range from 0x0 to 0x65 and 0xE0 to 0xE7.
169 // 0xE0 to 0xE7 are for modifier keys, and 0x0 to 0x3 are reserved for typical
170 // keyboard status or keyboard errors.
171 // So the number of valid non-modifier USB keycodes is 0x62, and the number of
172 // valid keycodes is 0x6A.
174 #define NUMBER_OF_VALID_NON_MODIFIER_USB_KEYCODE 0x62
175 #define NUMBER_OF_VALID_USB_KEYCODE 0x6A
177 // 0x0 to 0x3 are reserved for typical keyboard status or keyboard errors.
179 #define USBKBD_VALID_KEYCODE(Key) ((UINT8) (Key) > 3)
184 UINT8 ScrollLock
: 1;
189 // Functions of Driver Binding Protocol
192 Check whether USB keyboard driver supports this device.
194 @param This The USB keyboard driver binding protocol.
195 @param Controller The controller handle to check.
196 @param RemainingDevicePath The remaining device path.
198 @retval EFI_SUCCESS The driver supports this controller.
199 @retval other This device isn't supported.
204 USBKeyboardDriverBindingSupported (
205 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
206 IN EFI_HANDLE Controller
,
207 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
211 Starts the keyboard device with this driver.
213 This function produces Simple Text Input Protocol and Simple Text Input Ex Protocol,
214 initializes the keyboard device, and submit Asynchronous Interrupt Transfer to manage
215 this keyboard device.
217 @param This The USB keyboard driver binding instance.
218 @param Controller Handle of device to bind driver to.
219 @param RemainingDevicePath Optional parameter use to pick a specific child
222 @retval EFI_SUCCESS The controller is controlled by the usb keyboard driver.
223 @retval EFI_UNSUPPORTED No interrupt endpoint can be found.
224 @retval Other This controller cannot be started.
229 USBKeyboardDriverBindingStart (
230 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
231 IN EFI_HANDLE Controller
,
232 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
236 Stop the USB keyboard device handled by this driver.
238 @param This The USB keyboard driver binding protocol.
239 @param Controller The controller to release.
240 @param NumberOfChildren The number of handles in ChildHandleBuffer.
241 @param ChildHandleBuffer The array of child handle.
243 @retval EFI_SUCCESS The device was stopped.
244 @retval EFI_UNSUPPORTED Simple Text In Protocol or Simple Text In Ex Protocol
245 is not installed on Controller.
246 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
247 @retval Others Fail to uninstall protocols attached on the device.
252 USBKeyboardDriverBindingStop (
253 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
254 IN EFI_HANDLE Controller
,
255 IN UINTN NumberOfChildren
,
256 IN EFI_HANDLE
*ChildHandleBuffer
260 // EFI Component Name Functions
263 Retrieves a Unicode string that is the user readable name of the driver.
265 This function retrieves the user readable name of a driver in the form of a
266 Unicode string. If the driver specified by This has a user readable name in
267 the language specified by Language, then a pointer to the driver name is
268 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
269 by This does not support the language specified by Language,
270 then EFI_UNSUPPORTED is returned.
272 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
273 EFI_COMPONENT_NAME_PROTOCOL instance.
274 @param Language A pointer to a Null-terminated ASCII string
275 array indicating the language. This is the
276 language of the driver name that the caller is
277 requesting, and it must match one of the
278 languages specified in SupportedLanguages. The
279 number of languages supported by a driver is up
280 to the driver writer. Language is specified
281 in RFC 4646 or ISO 639-2 language code format.
282 @param DriverName A pointer to the Unicode string to return.
283 This Unicode string is the name of the
284 driver specified by This in the language
285 specified by Language.
287 @retval EFI_SUCCESS The Unicode string for the Driver specified by
288 This and the language specified by Language was
289 returned in DriverName.
290 @retval EFI_INVALID_PARAMETER Language is NULL.
291 @retval EFI_INVALID_PARAMETER DriverName is NULL.
292 @retval EFI_UNSUPPORTED The driver specified by This does not support
293 the language specified by Language.
298 UsbKeyboardComponentNameGetDriverName (
299 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
301 OUT CHAR16
**DriverName
305 Retrieves a Unicode string that is the user readable name of the controller
306 that is being managed by a driver.
308 This function retrieves the user readable name of the controller specified by
309 ControllerHandle and ChildHandle in the form of a Unicode string. If the
310 driver specified by This has a user readable name in the language specified by
311 Language, then a pointer to the controller name is returned in ControllerName,
312 and EFI_SUCCESS is returned. If the driver specified by This is not currently
313 managing the controller specified by ControllerHandle and ChildHandle,
314 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
315 support the language specified by Language, then EFI_UNSUPPORTED is returned.
317 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
318 EFI_COMPONENT_NAME_PROTOCOL instance.
319 @param ControllerHandle The handle of a controller that the driver
320 specified by This is managing. This handle
321 specifies the controller whose name is to be
323 @param ChildHandle The handle of the child controller to retrieve
324 the name of. This is an optional parameter that
325 may be NULL. It will be NULL for device
326 drivers. It will also be NULL for a bus drivers
327 that wish to retrieve the name of the bus
328 controller. It will not be NULL for a bus
329 driver that wishes to retrieve the name of a
331 @param Language A pointer to a Null-terminated ASCII string
332 array indicating the language. This is the
333 language of the driver name that the caller is
334 requesting, and it must match one of the
335 languages specified in SupportedLanguages. The
336 number of languages supported by a driver is up
337 to the driver writer. Language is specified in
338 RFC 4646 or ISO 639-2 language code format.
339 @param ControllerName A pointer to the Unicode string to return.
340 This Unicode string is the name of the
341 controller specified by ControllerHandle and
342 ChildHandle in the language specified by
343 Language from the point of view of the driver
346 @retval EFI_SUCCESS The Unicode string for the user readable name in
347 the language specified by Language for the
348 driver specified by This was returned in
350 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
351 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
353 @retval EFI_INVALID_PARAMETER Language is NULL.
354 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
355 @retval EFI_UNSUPPORTED The driver specified by This is not currently
356 managing the controller specified by
357 ControllerHandle and ChildHandle.
358 @retval EFI_UNSUPPORTED The driver specified by This does not support
359 the language specified by Language.
364 UsbKeyboardComponentNameGetControllerName (
365 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
366 IN EFI_HANDLE ControllerHandle
,
367 IN EFI_HANDLE ChildHandle OPTIONAL
,
369 OUT CHAR16
**ControllerName
373 // Functions of Simple Text Input Protocol
376 Reset the input device and optionaly run diagnostics
378 There are 2 types of reset for USB keyboard.
379 For non-exhaustive reset, only keyboard buffer is cleared.
380 For exhaustive reset, in addition to clearance of keyboard buffer, the hardware status
381 is also re-initialized.
383 @param This Protocol instance pointer.
384 @param ExtendedVerification Driver may perform diagnostics on reset.
386 @retval EFI_SUCCESS The device was reset.
387 @retval EFI_DEVICE_ERROR The device is not functioning properly and could not be reset.
393 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
394 IN BOOLEAN ExtendedVerification
398 Reads the next keystroke from the input device.
400 @param This The EFI_SIMPLE_TEXT_INPUT_PROTOCOL instance.
401 @param Key A pointer to a buffer that is filled in with the keystroke
402 information for the key that was pressed.
404 @retval EFI_SUCCESS The keystroke information was returned.
405 @retval EFI_NOT_READY There was no keystroke data availiable.
406 @retval EFI_DEVICE_ERROR The keydtroke information was not returned due to
412 USBKeyboardReadKeyStroke (
413 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
414 OUT EFI_INPUT_KEY
*Key
418 // Simple Text Input Ex protocol functions
421 Resets the input device hardware.
423 The Reset() function resets the input device hardware. As part
424 of initialization process, the firmware/device will make a quick
425 but reasonable attempt to verify that the device is functioning.
426 If the ExtendedVerification flag is TRUE the firmware may take
427 an extended amount of time to verify the device is operating on
428 reset. Otherwise the reset operation is to occur as quickly as
429 possible. The hardware verification process is not defined by
430 this specification and is left up to the platform firmware or
433 @param This A pointer to the EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL instance.
435 @param ExtendedVerification Indicates that the driver may perform a more exhaustive
436 verification operation of the device during reset.
438 @retval EFI_SUCCESS The device was reset.
439 @retval EFI_DEVICE_ERROR The device is not functioning correctly and could not be reset.
445 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
446 IN BOOLEAN ExtendedVerification
450 Reads the next keystroke from the input device.
452 @param This Protocol instance pointer.
453 @param KeyData A pointer to a buffer that is filled in with the keystroke
454 state data for the key that was pressed.
456 @retval EFI_SUCCESS The keystroke information was returned.
457 @retval EFI_NOT_READY There was no keystroke data available.
458 @retval EFI_DEVICE_ERROR The keystroke information was not returned due to
460 @retval EFI_INVALID_PARAMETER KeyData is NULL.
465 USBKeyboardReadKeyStrokeEx (
466 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
467 OUT EFI_KEY_DATA
*KeyData
471 Set certain state for the input device.
473 @param This Protocol instance pointer.
474 @param KeyToggleState A pointer to the EFI_KEY_TOGGLE_STATE to set the
475 state for the input device.
477 @retval EFI_SUCCESS The device state was set appropriately.
478 @retval EFI_DEVICE_ERROR The device is not functioning correctly and could
479 not have the setting adjusted.
480 @retval EFI_UNSUPPORTED The device does not support the ability to have its state set.
481 @retval EFI_INVALID_PARAMETER KeyToggleState is NULL.
486 USBKeyboardSetState (
487 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
488 IN EFI_KEY_TOGGLE_STATE
*KeyToggleState
492 Register a notification function for a particular keystroke for the input device.
494 @param This Protocol instance pointer.
495 @param KeyData A pointer to a buffer that is filled in with the keystroke
496 information data for the key that was pressed.
497 @param KeyNotificationFunction Points to the function to be called when the key
498 sequence is typed specified by KeyData.
499 @param NotifyHandle Points to the unique handle assigned to the registered notification.
501 @retval EFI_SUCCESS The notification function was registered successfully.
502 @retval EFI_OUT_OF_RESOURCES Unable to allocate resources for necesssary data structures.
503 @retval EFI_INVALID_PARAMETER KeyData or NotifyHandle or KeyNotificationFunction is NULL.
508 USBKeyboardRegisterKeyNotify (
509 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
510 IN EFI_KEY_DATA
*KeyData
,
511 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction
,
512 OUT EFI_HANDLE
*NotifyHandle
516 Remove a registered notification function from a particular keystroke.
518 @param This Protocol instance pointer.
519 @param NotificationHandle The handle of the notification function being unregistered.
521 @retval EFI_SUCCESS The notification function was unregistered successfully.
522 @retval EFI_INVALID_PARAMETER The NotificationHandle is invalid
523 @retval EFI_NOT_FOUND Cannot find the matching entry in database.
528 USBKeyboardUnregisterKeyNotify (
529 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
530 IN EFI_HANDLE NotificationHandle
534 Event notification function registered for EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.WaitForKeyEx
535 and EFI_SIMPLE_TEXT_INPUT_PROTOCOL.WaitForKey.
537 @param Event Event to be signaled when a key is pressed.
538 @param Context Points to USB_KB_DEV instance.
543 USBKeyboardWaitForKey (
549 Free keyboard notify list.
551 @param NotifyList The keyboard notify list to free.
553 @retval EFI_SUCCESS Free the notify list successfully.
554 @retval EFI_INVALID_PARAMETER NotifyList is NULL.
560 IN OUT LIST_ENTRY
*NotifyList
564 Check whether there is key pending in the keyboard buffer.
566 @param UsbKeyboardDevice The USB_KB_DEV instance.
568 @retval EFI_SUCCESS There is pending key to read.
569 @retval EFI_NOT_READY No pending key to read.
574 USBKeyboardCheckForKey (
575 IN OUT USB_KB_DEV
*UsbKeyboardDevice
579 Check whether the pressed key matches a registered key or not.
581 @param RegsiteredData A pointer to keystroke data for the key that was registered.
582 @param InputData A pointer to keystroke data for the key that was pressed.
584 @retval TRUE Key pressed matches a registered key.
585 @retval FLASE Key pressed does not matche a registered key.
591 IN EFI_KEY_DATA
*RegsiteredData
,
592 IN EFI_KEY_DATA
*InputData