]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Usb/UsbKbDxe/efikey.h
Merged in the following trackers from EDK:
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbKbDxe / efikey.h
CommitLineData
ed838d0c 1/** @file\r
813acf3a 2Copyright (c) 2004 - 2008, Intel Corporation\r
ed838d0c 3All rights reserved. This program and the accompanying materials\r
4are licensed and made available under the terms and conditions of the BSD License\r
5which accompanies this distribution. The full text of the license may be found at\r
6http://opensource.org/licenses/bsd-license.php\r
7\r
8THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
9WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
10\r
11Module Name:\r
12\r
13 EfiKey.h\r
14\r
15Abstract:\r
16\r
17 Header file for USB Keyboard Driver's Data Structures\r
18\r
19Revision History\r
20\r
21**/\r
22#ifndef _USB_KB_H\r
23#define _USB_KB_H\r
24\r
ed7748fe 25\r
ed838d0c 26#include <PiDxe.h>\r
ed7748fe 27\r
ed838d0c 28#include <Protocol/SimpleTextIn.h>\r
66aa04e4 29#include <Protocol/SimpleTextInEx.h>\r
813acf3a 30#include <Protocol/HiiDatabase.h>\r
ed838d0c 31#include <Protocol/UsbIo.h>\r
32#include <Protocol/DevicePath.h>\r
813acf3a 33#include <Guid/HiiKeyBoardLayout.h>\r
34#include <Guid/HotPlugDevice.h>\r
ed7748fe 35\r
ed838d0c 36#include <Library/DebugLib.h>\r
37#include <Library/ReportStatusCodeLib.h>\r
38#include <Library/BaseMemoryLib.h>\r
39#include <Library/UefiRuntimeServicesTableLib.h>\r
40#include <Library/UefiDriverEntryPoint.h>\r
41#include <Library/UefiBootServicesTableLib.h>\r
42#include <Library/UefiLib.h>\r
43#include <Library/MemoryAllocationLib.h>\r
44#include <Library/PcdLib.h>\r
45#include <Library/UsbLib.h>\r
66aa04e4 46#include <Library/BaseLib.h>\r
ed838d0c 47\r
48#include <IndustryStandard/Usb.h>\r
49\r
50#define MAX_KEY_ALLOWED 32\r
51\r
52#define HZ 1000 * 1000 * 10\r
53#define USBKBD_REPEAT_DELAY ((HZ) / 2)\r
54#define USBKBD_REPEAT_RATE ((HZ) / 50)\r
55\r
56#define CLASS_HID 3\r
57#define SUBCLASS_BOOT 1\r
58#define PROTOCOL_KEYBOARD 1\r
59\r
60#define BOOT_PROTOCOL 0\r
61#define REPORT_PROTOCOL 1\r
62\r
63typedef struct {\r
64 UINT8 Down;\r
65 UINT8 KeyCode;\r
66} USB_KEY;\r
67\r
68typedef struct {\r
69 USB_KEY buffer[MAX_KEY_ALLOWED + 1];\r
70 UINT8 bHead;\r
71 UINT8 bTail;\r
72} USB_KB_BUFFER;\r
73\r
74#define USB_KB_DEV_SIGNATURE EFI_SIGNATURE_32 ('u', 'k', 'b', 'd')\r
66aa04e4 75#define USB_KB_CONSOLE_IN_EX_NOTIFY_SIGNATURE EFI_SIGNATURE_32 ('u', 'k', 'b', 'x')\r
76\r
77typedef struct _KEYBOARD_CONSOLE_IN_EX_NOTIFY {\r
78 UINTN Signature;\r
79 EFI_HANDLE NotifyHandle;\r
80 EFI_KEY_DATA KeyData;\r
81 EFI_KEY_NOTIFY_FUNCTION KeyNotificationFn;\r
82 LIST_ENTRY NotifyEntry;\r
83} KEYBOARD_CONSOLE_IN_EX_NOTIFY;\r
813acf3a 84\r
85#define USB_NS_KEY_SIGNATURE EFI_SIGNATURE_32 ('u', 'n', 's', 'k')\r
86\r
87typedef struct {\r
88 UINTN Signature;\r
89 LIST_ENTRY Link;\r
90\r
91 //\r
92 // The number of EFI_NS_KEY_MODIFIER children definitions\r
93 //\r
94 UINTN KeyCount;\r
95\r
96 //\r
97 // NsKey[0] : Non-spacing key\r
98 // NsKey[1] ~ NsKey[KeyCount] : Physical keys\r
99 //\r
100 EFI_KEY_DESCRIPTOR *NsKey;\r
101} USB_NS_KEY;\r
102\r
103#define USB_NS_KEY_FORM_FROM_LINK(a) CR (a, USB_NS_KEY, Link, USB_NS_KEY_SIGNATURE)\r
104\r
ed838d0c 105typedef struct {\r
106 UINTN Signature;\r
107 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
108 EFI_EVENT DelayedRecoveryEvent;\r
109 EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleInput;\r
66aa04e4 110 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL SimpleInputEx;\r
111 EFI_USB_IO_PROTOCOL *UsbIo;\r
ed838d0c 112\r
113 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;\r
114 EFI_USB_ENDPOINT_DESCRIPTOR IntEndpointDescriptor;\r
115\r
116 USB_KB_BUFFER KeyboardBuffer;\r
117 UINT8 CtrlOn;\r
118 UINT8 AltOn;\r
119 UINT8 ShiftOn;\r
120 UINT8 NumLockOn;\r
121 UINT8 CapsOn;\r
122 UINT8 ScrollOn;\r
123 UINT8 LastKeyCodeArray[8];\r
124 UINT8 CurKeyChar;\r
125\r
126 UINT8 RepeatKey;\r
127 EFI_EVENT RepeatTimer;\r
128\r
129 EFI_UNICODE_STRING_TABLE *ControllerNameTable;\r
66aa04e4 130 \r
131 UINT8 LeftCtrlOn;\r
132 UINT8 LeftAltOn;\r
133 UINT8 LeftShiftOn;\r
134 UINT8 LeftLogoOn;\r
135 UINT8 RightCtrlOn;\r
136 UINT8 RightAltOn;\r
137 UINT8 RightShiftOn;\r
138 UINT8 RightLogoOn; \r
139 UINT8 MenuKeyOn;\r
140 UINT8 SysReqOn;\r
813acf3a 141 UINT8 AltGrOn;\r
66aa04e4 142\r
143 EFI_KEY_STATE KeyState;\r
144 //\r
145 // Notification function list\r
146 //\r
147 LIST_ENTRY NotifyList;\r
813acf3a 148\r
149 //\r
150 // Non-spacing key list\r
151 //\r
152 LIST_ENTRY NsKeyList;\r
153 USB_NS_KEY *CurrentNsKey;\r
154 EFI_KEY_DESCRIPTOR *KeyConvertionTable;\r
155 EFI_EVENT KeyboardLayoutEvent;\r
ed838d0c 156} USB_KB_DEV;\r
157\r
158//\r
159// Global Variables\r
160//\r
62b9bb55 161extern EFI_DRIVER_BINDING_PROTOCOL gUsbKeyboardDriverBinding;\r
162extern EFI_COMPONENT_NAME_PROTOCOL gUsbKeyboardComponentName;\r
163extern EFI_COMPONENT_NAME2_PROTOCOL gUsbKeyboardComponentName2;\r
164extern EFI_GUID gEfiUsbKeyboardDriverGuid;\r
66aa04e4 165extern EFI_GUID gSimpleTextInExNotifyGuid;\r
ed838d0c 166\r
167VOID\r
168KbdReportStatusCode (\r
169 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
170 IN EFI_STATUS_CODE_TYPE CodeType,\r
171 IN EFI_STATUS_CODE_VALUE Value\r
172 );\r
173\r
174#define USB_KB_DEV_FROM_THIS(a) \\r
175 CR(a, USB_KB_DEV, SimpleInput, USB_KB_DEV_SIGNATURE)\r
66aa04e4 176#define TEXT_INPUT_EX_USB_KB_DEV_FROM_THIS(a) \\r
177 CR(a, USB_KB_DEV, SimpleInputEx, USB_KB_DEV_SIGNATURE)\r
178\r
ed838d0c 179\r
180#define MOD_CONTROL_L 0x01\r
181#define MOD_CONTROL_R 0x10\r
182#define MOD_SHIFT_L 0x02\r
183#define MOD_SHIFT_R 0x20\r
184#define MOD_ALT_L 0x04\r
185#define MOD_ALT_R 0x40\r
186#define MOD_WIN_L 0x08\r
187#define MOD_WIN_R 0x80\r
188\r
189typedef struct {\r
190 UINT8 Mask;\r
191 UINT8 Key;\r
192} KB_MODIFIER;\r
193\r
813acf3a 194#define USB_KEYCODE_MAX_MAKE 0x62\r
ed838d0c 195\r
196#define USBKBD_VALID_KEYCODE(key) ((UINT8) (key) > 3)\r
197\r
198typedef struct {\r
199 UINT8 NumLock : 1;\r
200 UINT8 CapsLock : 1;\r
201 UINT8 ScrollLock : 1;\r
202 UINT8 Resrvd : 5;\r
203} LED_MAP;\r
66aa04e4 204\r
205//\r
206// Simple Text Input Ex protocol functions\r
207//\r
208EFI_STATUS\r
209EFIAPI\r
210USBKeyboardResetEx (\r
211 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
212 IN BOOLEAN ExtendedVerification\r
213 )\r
214/*++\r
215\r
216 Routine Description:\r
217 Reset the input device and optionaly run diagnostics\r
218\r
219 Arguments:\r
220 This - Protocol instance pointer.\r
221 ExtendedVerification - Driver may perform diagnostics on reset.\r
222\r
223 Returns:\r
224 EFI_SUCCESS - The device was reset.\r
225 EFI_DEVICE_ERROR - The device is not functioning properly and could \r
226 not be reset.\r
227\r
228--*/\r
229;\r
230\r
231EFI_STATUS\r
232EFIAPI\r
233USBKeyboardReadKeyStrokeEx (\r
234 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
235 OUT EFI_KEY_DATA *KeyData\r
236 )\r
237/*++\r
238\r
239 Routine Description:\r
240 Reads the next keystroke from the input device. The WaitForKey Event can \r
241 be used to test for existance of a keystroke via WaitForEvent () call.\r
242\r
243 Arguments:\r
244 This - Protocol instance pointer.\r
245 KeyData - A pointer to a buffer that is filled in with the keystroke \r
246 state data for the key that was pressed.\r
247\r
248 Returns:\r
249 EFI_SUCCESS - The keystroke information was returned.\r
250 EFI_NOT_READY - There was no keystroke data availiable.\r
251 EFI_DEVICE_ERROR - The keystroke information was not returned due to \r
252 hardware errors.\r
253 EFI_INVALID_PARAMETER - KeyData is NULL. \r
254\r
255--*/\r
256;\r
257\r
258EFI_STATUS\r
259EFIAPI\r
260USBKeyboardSetState (\r
261 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
262 IN EFI_KEY_TOGGLE_STATE *KeyToggleState\r
263 )\r
264/*++\r
265\r
266 Routine Description:\r
267 Set certain state for the input device.\r
268\r
269 Arguments:\r
270 This - Protocol instance pointer.\r
271 KeyToggleState - A pointer to the EFI_KEY_TOGGLE_STATE to set the \r
272 state for the input device.\r
273 \r
274 Returns: \r
275 EFI_SUCCESS - The device state was set successfully.\r
276 EFI_DEVICE_ERROR - The device is not functioning correctly and could \r
277 not have the setting adjusted.\r
278 EFI_UNSUPPORTED - The device does not have the ability to set its state.\r
279 EFI_INVALID_PARAMETER - KeyToggleState is NULL. \r
280\r
281--*/ \r
282;\r
283\r
284EFI_STATUS\r
285EFIAPI\r
286USBKeyboardRegisterKeyNotify (\r
287 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
288 IN EFI_KEY_DATA *KeyData,\r
289 IN EFI_KEY_NOTIFY_FUNCTION KeyNotificationFunction,\r
290 OUT EFI_HANDLE *NotifyHandle\r
291 )\r
292/*++\r
293\r
294 Routine Description:\r
295 Register a notification function for a particular keystroke for the input device.\r
296\r
297 Arguments:\r
298 This - Protocol instance pointer.\r
299 KeyData - A pointer to a buffer that is filled in with the keystroke \r
300 information data for the key that was pressed.\r
301 KeyNotificationFunction - Points to the function to be called when the key \r
302 sequence is typed specified by KeyData. \r
303 NotifyHandle - Points to the unique handle assigned to the registered notification. \r
304\r
305 Returns:\r
306 EFI_SUCCESS - The notification function was registered successfully.\r
307 EFI_OUT_OF_RESOURCES - Unable to allocate resources for necesssary data structures.\r
308 EFI_INVALID_PARAMETER - KeyData or NotifyHandle is NULL. \r
309 \r
310--*/ \r
311;\r
312\r
313EFI_STATUS\r
314EFIAPI\r
315USBKeyboardUnregisterKeyNotify (\r
316 IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *This,\r
317 IN EFI_HANDLE NotificationHandle\r
318 )\r
319/*++\r
320\r
321 Routine Description:\r
322 Remove a registered notification function from a particular keystroke.\r
323\r
324 Arguments:\r
325 This - Protocol instance pointer. \r
326 NotificationHandle - The handle of the notification function being unregistered.\r
327\r
328 Returns:\r
329 EFI_SUCCESS - The notification function was unregistered successfully.\r
330 EFI_INVALID_PARAMETER - The NotificationHandle is invalid.\r
331 EFI_NOT_FOUND - Can not find the matching entry in database. \r
332 \r
333--*/ \r
334;\r
335\r
ed838d0c 336#endif\r
66aa04e4 337\r