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