3 Header file for USB Keyboard Driver's Data Structures.
5 Copyright (c) 2004 - 2008, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #ifndef _EFI_USB_KB_H_
16 #define _EFI_USB_KB_H_
21 #include <Protocol/SimpleTextIn.h>
22 #include <Protocol/SimpleTextInEx.h>
23 #include <Protocol/HiiDatabase.h>
24 #include <Protocol/UsbIo.h>
25 #include <Protocol/DevicePath.h>
26 #include <Guid/HiiKeyBoardLayout.h>
27 #include <Guid/HotPlugDevice.h>
29 #include <Library/DebugLib.h>
30 #include <Library/ReportStatusCodeLib.h>
31 #include <Library/BaseMemoryLib.h>
32 #include <Library/UefiRuntimeServicesTableLib.h>
33 #include <Library/UefiDriverEntryPoint.h>
34 #include <Library/UefiBootServicesTableLib.h>
35 #include <Library/UefiLib.h>
36 #include <Library/MemoryAllocationLib.h>
37 #include <Library/PcdLib.h>
38 #include <Library/UsbLib.h>
39 #include <Library/BaseLib.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)
100 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
101 EFI_EVENT DelayedRecoveryEvent
;
102 EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleInput
;
103 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL SimpleInputEx
;
104 EFI_USB_IO_PROTOCOL
*UsbIo
;
106 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor
;
107 EFI_USB_ENDPOINT_DESCRIPTOR IntEndpointDescriptor
;
109 USB_KB_BUFFER KeyboardBuffer
;
116 UINT8 LastKeyCodeArray
[8];
120 EFI_EVENT RepeatTimer
;
122 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
136 EFI_KEY_STATE KeyState
;
138 // Notification function list
140 LIST_ENTRY NotifyList
;
143 // Non-spacing key list
145 LIST_ENTRY NsKeyList
;
146 USB_NS_KEY
*CurrentNsKey
;
147 EFI_KEY_DESCRIPTOR
*KeyConvertionTable
;
148 EFI_EVENT KeyboardLayoutEvent
;
154 extern EFI_DRIVER_BINDING_PROTOCOL gUsbKeyboardDriverBinding
;
155 extern EFI_COMPONENT_NAME_PROTOCOL gUsbKeyboardComponentName
;
156 extern EFI_COMPONENT_NAME2_PROTOCOL gUsbKeyboardComponentName2
;
157 extern EFI_GUID gEfiUsbKeyboardDriverGuid
;
158 extern EFI_GUID gSimpleTextInExNotifyGuid
;
161 Report Status Code in Usb Keyboard Driver.
163 @param DevicePath Use this to get Device Path.
164 @param CodeType Status Code Type.
165 @param CodeValue Status Code Value.
172 KbdReportStatusCode (
173 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
174 IN EFI_STATUS_CODE_TYPE CodeType
,
175 IN EFI_STATUS_CODE_VALUE Value
178 #define USB_KB_DEV_FROM_THIS(a) \
179 CR(a, USB_KB_DEV, SimpleInput, USB_KB_DEV_SIGNATURE)
180 #define TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS(a) \
181 CR(a, USB_KB_DEV, SimpleInputEx, USB_KB_DEV_SIGNATURE)
184 #define MOD_CONTROL_L 0x01
185 #define MOD_CONTROL_R 0x10
186 #define MOD_SHIFT_L 0x02
187 #define MOD_SHIFT_R 0x20
188 #define MOD_ALT_L 0x04
189 #define MOD_ALT_R 0x40
190 #define MOD_WIN_L 0x08
191 #define MOD_WIN_R 0x80
198 #define USB_KEYCODE_MAX_MAKE 0x62
200 #define USBKBD_VALID_KEYCODE(key) ((UINT8) (key) > 3)
205 UINT8 ScrollLock
: 1;
210 // Simple Text Input Ex protocol functions
213 The extension routine to reset the input device.
215 @param This Protocol instance pointer.
216 @param ExtendedVerification Driver may perform diagnostics on reset.
218 @retval EFI_SUCCESS The device was reset.
219 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
226 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
227 IN BOOLEAN ExtendedVerification
232 Reads the next keystroke from the input device. The WaitForKey Event can
233 be used to test for existance of a keystroke via WaitForEvent () call.
235 @param This Protocol instance pointer.
236 @param KeyData A pointer to a buffer that is filled in with the keystroke
237 state data for the key that was pressed.
239 @return EFI_SUCCESS The keystroke information was returned successfully.
240 @retval EFI_INVALID_PARAMETER KeyData is NULL.
241 @retval Other Read key stroke information failed.
246 USBKeyboardReadKeyStrokeEx (
247 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
248 OUT EFI_KEY_DATA
*KeyData
253 Set certain state for the input device.
255 @param This Protocol instance pointer.
256 @param KeyToggleState A pointer to the EFI_KEY_TOGGLE_STATE to set the
257 state for the input device.
259 @retval EFI_SUCCESS The device state was set successfully.
260 @retval EFI_UNSUPPORTED The device does not have the ability to set its state.
261 @retval EFI_INVALID_PARAMETER KeyToggleState is NULL.
266 USBKeyboardSetState (
267 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
268 IN EFI_KEY_TOGGLE_STATE
*KeyToggleState
273 Register a notification function for a particular keystroke for the input device.
275 @param This Protocol instance pointer.
276 @param KeyData A pointer to a buffer that is filled in with the keystroke
277 information data for the key that was pressed.
278 @param KeyNotificationFunction Points to the function to be called when the key
279 sequence is typed specified by KeyData.
280 @param NotifyHandle Points to the unique handle assigned to the registered notification.
282 @retval EFI_SUCCESS The notification function was registered successfully.
283 @retval EFI_OUT_OF_RESOURCES Unable to allocate resources for necesssary data structures.
284 @retval EFI_INVALID_PARAMETER KeyData or NotifyHandle is NULL.
289 USBKeyboardRegisterKeyNotify (
290 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
291 IN EFI_KEY_DATA
*KeyData
,
292 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction
,
293 OUT EFI_HANDLE
*NotifyHandle
298 Remove a registered notification function from a particular keystroke.
300 @param This Protocol instance pointer.
301 @param NotificationHandle The handle of the notification function being unregistered.
303 @retval EFI_SUCCESS The notification function was unregistered successfully.
304 @retval EFI_INVALID_PARAMETER The NotificationHandle is invalid or opening gSimpleTextInExNotifyGuid
305 on NotificationHandle fails.
306 @retval EFI_NOT_FOUND Can not find the matching entry in database.
311 USBKeyboardUnregisterKeyNotify (
312 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
313 IN EFI_HANDLE NotificationHandle