2 Copyright (c) 2004 - 2007, 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 <Guid/HotPlugDevice.h>
31 #include <Protocol/UsbIo.h>
32 #include <Protocol/DevicePath.h>
34 #include <Library/DebugLib.h>
35 #include <Library/ReportStatusCodeLib.h>
36 #include <Library/BaseMemoryLib.h>
37 #include <Library/UefiRuntimeServicesTableLib.h>
38 #include <Library/UefiDriverEntryPoint.h>
39 #include <Library/UefiBootServicesTableLib.h>
40 #include <Library/UefiLib.h>
41 #include <Library/MemoryAllocationLib.h>
42 #include <Library/PcdLib.h>
43 #include <Library/UsbLib.h>
44 #include <Library/BaseLib.h>
46 #include <IndustryStandard/Usb.h>
48 #define MAX_KEY_ALLOWED 32
50 #define HZ 1000 * 1000 * 10
51 #define USBKBD_REPEAT_DELAY ((HZ) / 2)
52 #define USBKBD_REPEAT_RATE ((HZ) / 50)
55 #define SUBCLASS_BOOT 1
56 #define PROTOCOL_KEYBOARD 1
58 #define BOOT_PROTOCOL 0
59 #define REPORT_PROTOCOL 1
67 USB_KEY buffer
[MAX_KEY_ALLOWED
+ 1];
72 #define USB_KB_DEV_SIGNATURE EFI_SIGNATURE_32 ('u', 'k', 'b', 'd')
73 #define USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE EFI_SIGNATURE_32 ('u', 'k', 'b', 'x')
75 typedef struct _KEYBOARD_CONSOLE_IN_EX_NOTIFY
{
77 EFI_HANDLE NotifyHandle
;
79 EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn
;
80 LIST_ENTRY NotifyEntry
;
81 } KEYBOARD_CONSOLE_IN_EX_NOTIFY
;
84 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
85 EFI_EVENT DelayedRecoveryEvent
;
86 EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleInput
;
87 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL SimpleInputEx
;
88 EFI_USB_IO_PROTOCOL
*UsbIo
;
90 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor
;
91 EFI_USB_ENDPOINT_DESCRIPTOR IntEndpointDescriptor
;
93 USB_KB_BUFFER KeyboardBuffer
;
100 UINT8 LastKeyCodeArray
[8];
104 EFI_EVENT RepeatTimer
;
106 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
119 EFI_KEY_STATE KeyState
;
121 // Notification function list
123 LIST_ENTRY NotifyList
;
129 extern EFI_DRIVER_BINDING_PROTOCOL gUsbKeyboardDriverBinding
;
130 extern EFI_COMPONENT_NAME_PROTOCOL gUsbKeyboardComponentName
;
131 extern EFI_COMPONENT_NAME2_PROTOCOL gUsbKeyboardComponentName2
;
132 extern EFI_GUID gEfiUsbKeyboardDriverGuid
;
133 extern EFI_GUID gSimpleTextInExNotifyGuid
;
136 KbdReportStatusCode (
137 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
138 IN EFI_STATUS_CODE_TYPE CodeType
,
139 IN EFI_STATUS_CODE_VALUE Value
142 #define USB_KB_DEV_FROM_THIS(a) \
143 CR(a, USB_KB_DEV, SimpleInput, USB_KB_DEV_SIGNATURE)
144 #define TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS(a) \
145 CR(a, USB_KB_DEV, SimpleInputEx, USB_KB_DEV_SIGNATURE)
148 #define MOD_CONTROL_L 0x01
149 #define MOD_CONTROL_R 0x10
150 #define MOD_SHIFT_L 0x02
151 #define MOD_SHIFT_R 0x20
152 #define MOD_ALT_L 0x04
153 #define MOD_ALT_R 0x40
154 #define MOD_WIN_L 0x08
155 #define MOD_WIN_R 0x80
162 #define USB_KEYCODE_MAX_MAKE 0x7E
164 #define USBKBD_VALID_KEYCODE(key) ((UINT8) (key) > 3)
169 UINT8 ScrollLock
: 1;
174 // Simple Text Input Ex protocol functions
179 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
180 IN BOOLEAN ExtendedVerification
185 Reset the input device and optionaly run diagnostics
188 This - Protocol instance pointer.
189 ExtendedVerification - Driver may perform diagnostics on reset.
192 EFI_SUCCESS - The device was reset.
193 EFI_DEVICE_ERROR - The device is not functioning properly and could
201 USBKeyboardReadKeyStrokeEx (
202 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
203 OUT EFI_KEY_DATA
*KeyData
208 Reads the next keystroke from the input device. The WaitForKey Event can
209 be used to test for existance of a keystroke via WaitForEvent () call.
212 This - Protocol instance pointer.
213 KeyData - A pointer to a buffer that is filled in with the keystroke
214 state data for the key that was pressed.
217 EFI_SUCCESS - The keystroke information was returned.
218 EFI_NOT_READY - There was no keystroke data availiable.
219 EFI_DEVICE_ERROR - The keystroke information was not returned due to
221 EFI_INVALID_PARAMETER - KeyData is NULL.
228 USBKeyboardSetState (
229 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
230 IN EFI_KEY_TOGGLE_STATE
*KeyToggleState
235 Set certain state for the input device.
238 This - Protocol instance pointer.
239 KeyToggleState - A pointer to the EFI_KEY_TOGGLE_STATE to set the
240 state for the input device.
243 EFI_SUCCESS - The device state was set successfully.
244 EFI_DEVICE_ERROR - The device is not functioning correctly and could
245 not have the setting adjusted.
246 EFI_UNSUPPORTED - The device does not have the ability to set its state.
247 EFI_INVALID_PARAMETER - KeyToggleState is NULL.
254 USBKeyboardRegisterKeyNotify (
255 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
256 IN EFI_KEY_DATA
*KeyData
,
257 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction
,
258 OUT EFI_HANDLE
*NotifyHandle
263 Register a notification function for a particular keystroke for the input device.
266 This - Protocol instance pointer.
267 KeyData - A pointer to a buffer that is filled in with the keystroke
268 information data for the key that was pressed.
269 KeyNotificationFunction - Points to the function to be called when the key
270 sequence is typed specified by KeyData.
271 NotifyHandle - Points to the unique handle assigned to the registered notification.
274 EFI_SUCCESS - The notification function was registered successfully.
275 EFI_OUT_OF_RESOURCES - Unable to allocate resources for necesssary data structures.
276 EFI_INVALID_PARAMETER - KeyData or NotifyHandle is NULL.
283 USBKeyboardUnregisterKeyNotify (
284 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*This
,
285 IN EFI_HANDLE NotificationHandle
290 Remove a registered notification function from a particular keystroke.
293 This - Protocol instance pointer.
294 NotificationHandle - The handle of the notification function being unregistered.
297 EFI_SUCCESS - The notification function was unregistered successfully.
298 EFI_INVALID_PARAMETER - The NotificationHandle is invalid.
299 EFI_NOT_FOUND - Can not find the matching entry in database.