2 Copyright (c) 2004 - 2008, Intel Corporation
3 All rights reserved. This program and the accompanying materials
4 are licensed and made available under the terms and conditions of the BSD License
5 which accompanies this distribution. The full text of the license may be found at
6 http://opensource.org/licenses/bsd-license.php
8 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 Header file for USB Keyboard Driver's Data Structures
28 #include <Protocol/SimpleTextIn.h>
29 #include <Protocol/SimpleTextInEx.h>
30 #include <Protocol/HiiDatabase.h>
31 #include <Protocol/UsbIo.h>
32 #include <Protocol/DevicePath.h>
33 #include <Guid/HiiKeyBoardLayout.h>
34 #include <Guid/HotPlugDevice.h>
36 #include <Library/DebugLib.h>
37 #include <Library/ReportStatusCodeLib.h>
38 #include <Library/BaseMemoryLib.h>
39 #include <Library/UefiRuntimeServicesTableLib.h>
40 #include <Library/UefiDriverEntryPoint.h>
41 #include <Library/UefiBootServicesTableLib.h>
42 #include <Library/UefiLib.h>
43 #include <Library/MemoryAllocationLib.h>
44 #include <Library/PcdLib.h>
45 #include <Library/UsbLib.h>
46 #include <Library/BaseLib.h>
48 #include <IndustryStandard/Usb.h>
50 #define MAX_KEY_ALLOWED 32
52 #define HZ 1000 * 1000 * 10
53 #define USBKBD_REPEAT_DELAY ((HZ) / 2)
54 #define USBKBD_REPEAT_RATE ((HZ) / 50)
57 #define SUBCLASS_BOOT 1
58 #define PROTOCOL_KEYBOARD 1
60 #define BOOT_PROTOCOL 0
61 #define REPORT_PROTOCOL 1
69 USB_KEY buffer
[MAX_KEY_ALLOWED
+ 1];
74 #define USB_KB_DEV_SIGNATURE EFI_SIGNATURE_32 ('u', 'k', 'b', 'd')
75 #define USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE EFI_SIGNATURE_32 ('u', 'k', 'b', 'x')
77 typedef struct _KEYBOARD_CONSOLE_IN_EX_NOTIFY
{
79 EFI_HANDLE NotifyHandle
;
81 EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn
;
82 LIST_ENTRY NotifyEntry
;
83 } KEYBOARD_CONSOLE_IN_EX_NOTIFY
;
85 #define USB_NS_KEY_SIGNATURE EFI_SIGNATURE_32 ('u', 'n', 's', 'k')
92 // The number of EFI_NS_KEY_MODIFIER children definitions
97 // NsKey[0] : Non-spacing key
98 // NsKey[1] ~ NsKey[KeyCount] : Physical keys
100 EFI_KEY_DESCRIPTOR
*NsKey
;
103 #define USB_NS_KEY_FORM_FROM_LINK(a) CR (a, USB_NS_KEY, Link, USB_NS_KEY_SIGNATURE)
107 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
108 EFI_EVENT DelayedRecoveryEvent
;
109 EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleInput
;
110 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL SimpleInputEx
;
111 EFI_USB_IO_PROTOCOL
*UsbIo
;
113 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor
;
114 EFI_USB_ENDPOINT_DESCRIPTOR IntEndpointDescriptor
;
116 USB_KB_BUFFER KeyboardBuffer
;
123 UINT8 LastKeyCodeArray
[8];
127 EFI_EVENT RepeatTimer
;
129 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
143 EFI_KEY_STATE KeyState
;
145 // Notification function list
147 LIST_ENTRY NotifyList
;
150 // Non-spacing key list
152 LIST_ENTRY NsKeyList
;
153 USB_NS_KEY
*CurrentNsKey
;
154 EFI_KEY_DESCRIPTOR
*KeyConvertionTable
;
155 EFI_EVENT KeyboardLayoutEvent
;
161 extern EFI_DRIVER_BINDING_PROTOCOL gUsbKeyboardDriverBinding
;
162 extern EFI_COMPONENT_NAME_PROTOCOL gUsbKeyboardComponentName
;
163 extern EFI_COMPONENT_NAME2_PROTOCOL gUsbKeyboardComponentName2
;
164 extern EFI_GUID gEfiUsbKeyboardDriverGuid
;
165 extern EFI_GUID gSimpleTextInExNotifyGuid
;
168 KbdReportStatusCode (
169 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
170 IN EFI_STATUS_CODE_TYPE CodeType
,
171 IN EFI_STATUS_CODE_VALUE Value
174 #define USB_KB_DEV_FROM_THIS(a) \
175 CR(a, USB_KB_DEV, SimpleInput, USB_KB_DEV_SIGNATURE)
176 #define TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS(a) \
177 CR(a, USB_KB_DEV, SimpleInputEx, USB_KB_DEV_SIGNATURE)
180 #define MOD_CONTROL_L 0x01
181 #define MOD_CONTROL_R 0x10
182 #define MOD_SHIFT_L 0x02
183 #define MOD_SHIFT_R 0x20
184 #define MOD_ALT_L 0x04
185 #define MOD_ALT_R 0x40
186 #define MOD_WIN_L 0x08
187 #define MOD_WIN_R 0x80
194 #define USB_KEYCODE_MAX_MAKE 0x62
196 #define USBKBD_VALID_KEYCODE(key) ((UINT8) (key) > 3)
201 UINT8 ScrollLock
: 1;
206 // Simple Text Input Ex protocol functions
211 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
212 IN BOOLEAN ExtendedVerification
217 Reset the input device and optionaly run diagnostics
220 This - Protocol instance pointer.
221 ExtendedVerification - Driver may perform diagnostics on reset.
224 EFI_SUCCESS - The device was reset.
225 EFI_DEVICE_ERROR - The device is not functioning properly and could
233 USBKeyboardReadKeyStrokeEx (
234 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
235 OUT EFI_KEY_DATA
*KeyData
240 Reads the next keystroke from the input device. The WaitForKey Event can
241 be used to test for existance of a keystroke via WaitForEvent () call.
244 This - Protocol instance pointer.
245 KeyData - A pointer to a buffer that is filled in with the keystroke
246 state data for the key that was pressed.
249 EFI_SUCCESS - The keystroke information was returned.
250 EFI_NOT_READY - There was no keystroke data availiable.
251 EFI_DEVICE_ERROR - The keystroke information was not returned due to
253 EFI_INVALID_PARAMETER - KeyData is NULL.
260 USBKeyboardSetState (
261 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
262 IN EFI_KEY_TOGGLE_STATE
*KeyToggleState
267 Set certain state for the input device.
270 This - Protocol instance pointer.
271 KeyToggleState - A pointer to the EFI_KEY_TOGGLE_STATE to set the
272 state for the input device.
275 EFI_SUCCESS - The device state was set successfully.
276 EFI_DEVICE_ERROR - The device is not functioning correctly and could
277 not have the setting adjusted.
278 EFI_UNSUPPORTED - The device does not have the ability to set its state.
279 EFI_INVALID_PARAMETER - KeyToggleState is NULL.
286 USBKeyboardRegisterKeyNotify (
287 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
288 IN EFI_KEY_DATA
*KeyData
,
289 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction
,
290 OUT EFI_HANDLE
*NotifyHandle
295 Register a notification function for a particular keystroke for the input device.
298 This - Protocol instance pointer.
299 KeyData - A pointer to a buffer that is filled in with the keystroke
300 information data for the key that was pressed.
301 KeyNotificationFunction - Points to the function to be called when the key
302 sequence is typed specified by KeyData.
303 NotifyHandle - Points to the unique handle assigned to the registered notification.
306 EFI_SUCCESS - The notification function was registered successfully.
307 EFI_OUT_OF_RESOURCES - Unable to allocate resources for necesssary data structures.
308 EFI_INVALID_PARAMETER - KeyData or NotifyHandle is NULL.
315 USBKeyboardUnregisterKeyNotify (
316 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
317 IN EFI_HANDLE NotificationHandle
322 Remove a registered notification function from a particular keystroke.
325 This - Protocol instance pointer.
326 NotificationHandle - The handle of the notification function being unregistered.
329 EFI_SUCCESS - The notification function was unregistered successfully.
330 EFI_INVALID_PARAMETER - The NotificationHandle is invalid.
331 EFI_NOT_FOUND - Can not find the matching entry in database.