]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.h
Fix the USB keyboard driver to call hotkey callback even no one is calling ReadKeyStroke
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbKbDxe / KeyBoard.h
CommitLineData
a7022cec 1/** @file\r
a7022cec 2 Function prototype for USB Keyboard Driver.\r
3\r
c1fd2767 4Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>\r
cd5ebaa0 5This program and the accompanying materials\r
a7022cec 6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#ifndef _EFI_KEYBOARD_H_\r
16#define _EFI_KEYBOARD_H_\r
17\r
18\r
19#include "EfiKey.h"\r
20\r
c41c3e55 21#define USB_KEYBOARD_LAYOUT_PACKAGE_GUID \\r
22 { \\r
23 0xc0f3b43, 0x44de, 0x4907, { 0xb4, 0x78, 0x22, 0x5f, 0x6f, 0x62, 0x89, 0xdc } \\r
24 }\r
25\r
26#define USB_KEYBOARD_LAYOUT_KEY_GUID \\r
27 { \\r
28 0x3a4d7a7c, 0x18a, 0x4b42, { 0x81, 0xb3, 0xdc, 0x10, 0xe3, 0xb5, 0x91, 0xbd } \\r
29 }\r
30\r
31#define USB_KEYBOARD_KEY_COUNT 104\r
32\r
33#define USB_KEYBOARD_LANGUAGE_STR_LEN 5 // RFC4646 Language Code: "en-US"\r
34#define USB_KEYBOARD_DESCRIPTION_STR_LEN (16 + 1) // Description: "English Keyboard"\r
35\r
36#pragma pack (1)\r
37typedef struct {\r
38 //\r
39 // This 4-bytes total array length is required by PreparePackageList()\r
40 //\r
41 UINT32 Length;\r
42\r
43 //\r
44 // Keyboard Layout package definition\r
45 //\r
46 EFI_HII_PACKAGE_HEADER PackageHeader;\r
47 UINT16 LayoutCount;\r
48\r
49 //\r
50 // EFI_HII_KEYBOARD_LAYOUT\r
51 //\r
52 UINT16 LayoutLength;\r
53 EFI_GUID Guid;\r
54 UINT32 LayoutDescriptorStringOffset;\r
55 UINT8 DescriptorCount;\r
56 EFI_KEY_DESCRIPTOR KeyDescriptor[USB_KEYBOARD_KEY_COUNT];\r
57 UINT16 DescriptionCount;\r
58 CHAR16 Language[USB_KEYBOARD_LANGUAGE_STR_LEN];\r
59 CHAR16 Space;\r
60 CHAR16 DescriptionString[USB_KEYBOARD_DESCRIPTION_STR_LEN];\r
61} USB_KEYBOARD_LAYOUT_PACK_BIN;\r
62#pragma pack()\r
a7022cec 63/**\r
b4e73a63 64 Uses USB I/O to check whether the device is a USB keyboard device.\r
a7022cec 65\r
b4e73a63 66 @param UsbIo Pointer to a USB I/O protocol instance.\r
67\r
68 @retval TRUE Device is a USB keyboard device.\r
69 @retval FALSE Device is a not USB keyboard device.\r
a7022cec 70\r
71**/\r
72BOOLEAN\r
a7022cec 73IsUSBKeyboard (\r
74 IN EFI_USB_IO_PROTOCOL *UsbIo\r
75 );\r
76\r
77/**\r
b4e73a63 78 Initialize USB keyboard device and all private data structures.\r
a7022cec 79\r
80 @param UsbKeyboardDevice The USB_KB_DEV instance.\r
81\r
82 @retval EFI_SUCCESS Initialization is successful.\r
b4e73a63 83 @retval EFI_DEVICE_ERROR Keyboard initialization failed.\r
a7022cec 84\r
85**/\r
86EFI_STATUS\r
a7022cec 87InitUSBKeyboard (\r
b4e73a63 88 IN OUT USB_KB_DEV *UsbKeyboardDevice\r
a7022cec 89 );\r
90\r
91/**\r
b4e73a63 92 Initialize USB keyboard layout.\r
93\r
94 This function initializes Key Convertion Table for the USB keyboard device.\r
95 It first tries to retrieve layout from HII database. If failed and default\r
96 layout is enabled, then it just uses the default layout.\r
a7022cec 97\r
98 @param UsbKeyboardDevice The USB_KB_DEV instance.\r
99\r
b4e73a63 100 @retval EFI_SUCCESS Initialization succeeded.\r
101 @retval EFI_NOT_READY Keyboard layout cannot be retrieve from HII\r
102 database, and default layout is disabled.\r
103 @retval Other Fail to register event to EFI_HII_SET_KEYBOARD_LAYOUT_EVENT_GUID group.\r
a7022cec 104\r
105**/\r
106EFI_STATUS\r
a7022cec 107InitKeyboardLayout (\r
b4e73a63 108 OUT USB_KB_DEV *UsbKeyboardDevice\r
a7022cec 109 );\r
110\r
111/**\r
b4e73a63 112 Destroy resources for keyboard layout.\r
a7022cec 113\r
114 @param UsbKeyboardDevice The USB_KB_DEV instance.\r
115\r
116**/\r
117VOID\r
a7022cec 118ReleaseKeyboardLayoutResources (\r
b4e73a63 119 IN OUT USB_KB_DEV *UsbKeyboardDevice\r
a7022cec 120 );\r
121\r
122/**\r
b4e73a63 123 Handler function for USB keyboard's asynchronous interrupt transfer.\r
124\r
125 This function is the handler function for USB keyboard's asynchronous interrupt transfer\r
126 to manage the keyboard. It parses the USB keyboard input report, and inserts data to\r
127 keyboard buffer according to state of modifer keys and normal keys. Timer for repeat key\r
128 is also set accordingly.\r
a7022cec 129\r
130 @param Data A pointer to a buffer that is filled with key data which is\r
131 retrieved via asynchronous interrupt transfer.\r
132 @param DataLength Indicates the size of the data buffer.\r
133 @param Context Pointing to USB_KB_DEV instance.\r
134 @param Result Indicates the result of the asynchronous interrupt transfer.\r
135\r
b4e73a63 136 @retval EFI_SUCCESS Asynchronous interrupt transfer is handled successfully.\r
137 @retval EFI_DEVICE_ERROR Hardware error occurs.\r
a7022cec 138\r
139**/\r
140EFI_STATUS\r
141EFIAPI\r
142KeyboardHandler (\r
143 IN VOID *Data,\r
144 IN UINTN DataLength,\r
145 IN VOID *Context,\r
146 IN UINT32 Result\r
147 );\r
148\r
149/**\r
b4e73a63 150 Handler for Delayed Recovery event.\r
151\r
152 This function is the handler for Delayed Recovery event triggered\r
153 by timer.\r
154 After a device error occurs, the event would be triggered\r
155 with interval of EFI_USB_INTERRUPT_DELAY. EFI_USB_INTERRUPT_DELAY\r
156 is defined in USB standard for error handling.\r
a7022cec 157\r
158 @param Event The Delayed Recovery event.\r
159 @param Context Points to the USB_KB_DEV instance.\r
160\r
a7022cec 161**/\r
162VOID\r
163EFIAPI\r
164USBKeyboardRecoveryHandler (\r
165 IN EFI_EVENT Event,\r
166 IN VOID *Context\r
167 );\r
168\r
169/**\r
b4e73a63 170 Retrieves a USB keycode after parsing the raw data in keyboard buffer.\r
171\r
172 This function parses keyboard buffer. It updates state of modifier key for\r
173 USB_KB_DEV instancem, and returns keycode for output.\r
a7022cec 174\r
175 @param UsbKeyboardDevice The USB_KB_DEV instance.\r
b4e73a63 176 @param KeyCode Pointer to the USB keycode for output.\r
a7022cec 177\r
b4e73a63 178 @retval EFI_SUCCESS Keycode successfully parsed.\r
179 @retval EFI_NOT_READY Keyboard buffer is not ready for a valid keycode\r
a7022cec 180\r
181**/\r
182EFI_STATUS\r
a7022cec 183USBParseKey (\r
184 IN OUT USB_KB_DEV *UsbKeyboardDevice,\r
b4e73a63 185 OUT UINT8 *KeyCode\r
a7022cec 186 );\r
187\r
188/**\r
b4e73a63 189 Converts USB Keycode ranging from 0x4 to 0x65 to EFI_INPUT_KEY.\r
a7022cec 190\r
b4e73a63 191 @param UsbKeyboardDevice The USB_KB_DEV instance.\r
192 @param KeyCode Indicates the key code that will be interpreted.\r
c1fd2767 193 @param KeyData A pointer to a buffer that is filled in with\r
b4e73a63 194 the keystroke information for the key that\r
195 was pressed.\r
a7022cec 196\r
b4e73a63 197 @retval EFI_SUCCESS Success.\r
198 @retval EFI_INVALID_PARAMETER KeyCode is not in the range of 0x4 to 0x65.\r
199 @retval EFI_INVALID_PARAMETER Translated EFI_INPUT_KEY has zero for both ScanCode and UnicodeChar.\r
200 @retval EFI_NOT_READY KeyCode represents a dead key with EFI_NS_KEY_MODIFIER\r
81464cf1 201 @retval EFI_DEVICE_ERROR Keyboard layout is invalid.\r
a7022cec 202\r
203**/\r
204EFI_STATUS\r
5899f27e 205UsbKeyCodeToEfiInputKey (\r
a7022cec 206 IN USB_KB_DEV *UsbKeyboardDevice,\r
b4e73a63 207 IN UINT8 KeyCode,\r
c1fd2767 208 OUT EFI_KEY_DATA *KeyData\r
a7022cec 209 );\r
210\r
c1fd2767 211\r
a7022cec 212/**\r
c1fd2767 213 Create the queue.\r
a7022cec 214\r
c1fd2767
RN
215 @param Queue Points to the queue.\r
216 @param ItemSize Size of the single item.\r
a7022cec 217\r
a7022cec 218**/\r
5899f27e 219VOID\r
c1fd2767
RN
220InitQueue (\r
221 IN OUT USB_SIMPLE_QUEUE *Queue,\r
222 IN UINTN ItemSize\r
223 );\r
224\r
225/**\r
226 Destroy the queue\r
227\r
228 @param Queue Points to the queue.\r
229**/\r
230VOID\r
231DestroyQueue (\r
232 IN OUT USB_SIMPLE_QUEUE *Queue\r
a7022cec 233 );\r
234\r
c1fd2767 235\r
a7022cec 236/**\r
c1fd2767 237 Check whether the queue is empty.\r
a7022cec 238\r
c1fd2767 239 @param Queue Points to the queue.\r
a7022cec 240\r
c1fd2767
RN
241 @retval TRUE Queue is empty.\r
242 @retval FALSE Queue is not empty.\r
a7022cec 243\r
244**/\r
245BOOLEAN\r
c1fd2767
RN
246IsQueueEmpty (\r
247 IN USB_SIMPLE_QUEUE *Queue\r
a7022cec 248 );\r
249\r
c1fd2767 250\r
a7022cec 251/**\r
c1fd2767 252 Check whether the queue is full.\r
a7022cec 253\r
c1fd2767 254 @param Queue Points to the queue.\r
a7022cec 255\r
c1fd2767
RN
256 @retval TRUE Queue is full.\r
257 @retval FALSE Queue is not full.\r
a7022cec 258\r
259**/\r
260BOOLEAN\r
c1fd2767
RN
261IsQueueFull (\r
262 IN USB_SIMPLE_QUEUE *Queue\r
a7022cec 263 );\r
264\r
a7022cec 265\r
c1fd2767
RN
266/**\r
267 Enqueue the item to the queue.\r
a7022cec 268\r
c1fd2767
RN
269 @param Queue Points to the queue.\r
270 @param Item Points to the item to be enqueued.\r
271 @param ItemSize Size of the item.\r
a7022cec 272**/\r
5899f27e 273VOID\r
c1fd2767
RN
274Enqueue (\r
275 IN OUT USB_SIMPLE_QUEUE *Queue,\r
276 IN VOID *Item,\r
277 IN UINTN ItemSize\r
a7022cec 278 );\r
279\r
c1fd2767 280\r
a7022cec 281/**\r
c1fd2767 282 Dequeue a item from the queue.\r
a7022cec 283\r
c1fd2767
RN
284 @param Queue Points to the queue.\r
285 @param Item Receives the item.\r
286 @param ItemSize Size of the item.\r
a7022cec 287\r
c1fd2767
RN
288 @retval EFI_SUCCESS Item was successfully dequeued.\r
289 @retval EFI_DEVICE_ERROR The queue is empty.\r
a7022cec 290\r
291**/\r
292EFI_STATUS\r
c1fd2767
RN
293Dequeue (\r
294 IN OUT USB_SIMPLE_QUEUE *Queue,\r
295 OUT VOID *Item,\r
296 IN UINTN ItemSize\r
a7022cec 297 );\r
298\r
299/**\r
b4e73a63 300 Handler for Repeat Key event.\r
301\r
302 This function is the handler for Repeat Key event triggered\r
303 by timer.\r
304 After a repeatable key is pressed, the event would be triggered\r
305 with interval of USBKBD_REPEAT_DELAY. Once the event is triggered,\r
306 following trigger will come with interval of USBKBD_REPEAT_RATE.\r
a7022cec 307\r
308 @param Event The Repeat Key event.\r
309 @param Context Points to the USB_KB_DEV instance.\r
310\r
a7022cec 311**/\r
312VOID\r
313EFIAPI\r
314USBKeyboardRepeatHandler (\r
315 IN EFI_EVENT Event,\r
316 IN VOID *Context\r
317 );\r
318\r
319/**\r
b4e73a63 320 Sets USB keyboard LED state.\r
a7022cec 321\r
322 @param UsbKeyboardDevice The USB_KB_DEV instance.\r
323\r
a7022cec 324**/\r
5899f27e 325VOID\r
a7022cec 326SetKeyLED (\r
327 IN USB_KB_DEV *UsbKeyboardDevice\r
328 );\r
329\r
330#endif\r