]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Usb/UsbKbDxe/efikey.h
usb kb's bug fix
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbKbDxe / efikey.h
1 /** @file
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
7
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.
10
11 Module Name:
12
13 EfiKey.h
14
15 Abstract:
16
17 Header file for USB Keyboard Driver's Data Structures
18
19 Revision History
20
21 **/
22 #ifndef _USB_KB_H
23 #define _USB_KB_H
24
25
26 #include <PiDxe.h>
27
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>
33
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>
45
46 #include <IndustryStandard/Usb.h>
47
48 #define MAX_KEY_ALLOWED 32
49
50 #define HZ 1000 * 1000 * 10
51 #define USBKBD_REPEAT_DELAY ((HZ) / 2)
52 #define USBKBD_REPEAT_RATE ((HZ) / 50)
53
54 #define CLASS_HID 3
55 #define SUBCLASS_BOOT 1
56 #define PROTOCOL_KEYBOARD 1
57
58 #define BOOT_PROTOCOL 0
59 #define REPORT_PROTOCOL 1
60
61 typedef struct {
62 UINT8 Down;
63 UINT8 KeyCode;
64 } USB_KEY;
65
66 typedef struct {
67 USB_KEY buffer[MAX_KEY_ALLOWED + 1];
68 UINT8 bHead;
69 UINT8 bTail;
70 } USB_KB_BUFFER;
71
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')
74
75 typedef struct _KEYBOARD_CONSOLE_IN_EX_NOTIFY {
76 UINTN Signature;
77 EFI_HANDLE NotifyHandle;
78 EFI_KEY_DATA KeyData;
79 EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn;
80 LIST_ENTRY NotifyEntry;
81 } KEYBOARD_CONSOLE_IN_EX_NOTIFY;
82 typedef struct {
83 UINTN Signature;
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;
89
90 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
91 EFI_USB_ENDPOINT_DESCRIPTOR IntEndpointDescriptor;
92
93 USB_KB_BUFFER KeyboardBuffer;
94 UINT8 CtrlOn;
95 UINT8 AltOn;
96 UINT8 ShiftOn;
97 UINT8 NumLockOn;
98 UINT8 CapsOn;
99 UINT8 ScrollOn;
100 UINT8 LastKeyCodeArray[8];
101 UINT8 CurKeyChar;
102
103 UINT8 RepeatKey;
104 EFI_EVENT RepeatTimer;
105
106 EFI_UNICODE_STRING_TABLE *ControllerNameTable;
107
108 UINT8 LeftCtrlOn;
109 UINT8 LeftAltOn;
110 UINT8 LeftShiftOn;
111 UINT8 LeftLogoOn;
112 UINT8 RightCtrlOn;
113 UINT8 RightAltOn;
114 UINT8 RightShiftOn;
115 UINT8 RightLogoOn;
116 UINT8 MenuKeyOn;
117 UINT8 SysReqOn;
118
119 EFI_KEY_STATE KeyState;
120 //
121 // Notification function list
122 //
123 LIST_ENTRY NotifyList;
124 } USB_KB_DEV;
125
126 //
127 // Global Variables
128 //
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;
134
135 VOID
136 KbdReportStatusCode (
137 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
138 IN EFI_STATUS_CODE_TYPE CodeType,
139 IN EFI_STATUS_CODE_VALUE Value
140 );
141
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)
146
147
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
156
157 typedef struct {
158 UINT8 Mask;
159 UINT8 Key;
160 } KB_MODIFIER;
161
162 #define USB_KEYCODE_MAX_MAKE 0x7E
163
164 #define USBKBD_VALID_KEYCODE(key) ((UINT8) (key) > 3)
165
166 typedef struct {
167 UINT8 NumLock : 1;
168 UINT8 CapsLock : 1;
169 UINT8 ScrollLock : 1;
170 UINT8 Resrvd : 5;
171 } LED_MAP;
172
173 //
174 // Simple Text Input Ex protocol functions
175 //
176 EFI_STATUS
177 EFIAPI
178 USBKeyboardResetEx (
179 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
180 IN BOOLEAN ExtendedVerification
181 )
182 /*++
183
184 Routine Description:
185 Reset the input device and optionaly run diagnostics
186
187 Arguments:
188 This - Protocol instance pointer.
189 ExtendedVerification - Driver may perform diagnostics on reset.
190
191 Returns:
192 EFI_SUCCESS - The device was reset.
193 EFI_DEVICE_ERROR - The device is not functioning properly and could
194 not be reset.
195
196 --*/
197 ;
198
199 EFI_STATUS
200 EFIAPI
201 USBKeyboardReadKeyStrokeEx (
202 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
203 OUT EFI_KEY_DATA *KeyData
204 )
205 /*++
206
207 Routine Description:
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.
210
211 Arguments:
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.
215
216 Returns:
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
220 hardware errors.
221 EFI_INVALID_PARAMETER - KeyData is NULL.
222
223 --*/
224 ;
225
226 EFI_STATUS
227 EFIAPI
228 USBKeyboardSetState (
229 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
230 IN EFI_KEY_TOGGLE_STATE *KeyToggleState
231 )
232 /*++
233
234 Routine Description:
235 Set certain state for the input device.
236
237 Arguments:
238 This - Protocol instance pointer.
239 KeyToggleState - A pointer to the EFI_KEY_TOGGLE_STATE to set the
240 state for the input device.
241
242 Returns:
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.
248
249 --*/
250 ;
251
252 EFI_STATUS
253 EFIAPI
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
259 )
260 /*++
261
262 Routine Description:
263 Register a notification function for a particular keystroke for the input device.
264
265 Arguments:
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.
272
273 Returns:
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.
277
278 --*/
279 ;
280
281 EFI_STATUS
282 EFIAPI
283 USBKeyboardUnregisterKeyNotify (
284 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,
285 IN EFI_HANDLE NotificationHandle
286 )
287 /*++
288
289 Routine Description:
290 Remove a registered notification function from a particular keystroke.
291
292 Arguments:
293 This - Protocol instance pointer.
294 NotificationHandle - The handle of the notification function being unregistered.
295
296 Returns:
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.
300
301 --*/
302 ;
303
304 #endif
305