]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Include/Library/UsbLib.h
1. Import UsbKbDxe and UsbMouseDxe into MdeModulePkg
[mirror_edk2.git] / MdePkg / Include / Library / UsbLib.h
CommitLineData
842f5579 1/** @file\r
ed838d0c 2 Common Dxe Libarary for USB\r
fb3df220 3\r
842f5579
A
4 Copyright (c) 2006, Intel Corporation<BR>\r
5 All rights reserved. This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
fb3df220 14\r
fb3df220 15\r
842f5579
A
16#ifndef __USB_DXE_LIB_H__\r
17#define __USB_DXE_LIB_H__\r
fb3df220 18\r
c7d265a9 19#include <Protocol/UsbIo.h>\r
ed838d0c 20\r
21//\r
22// Standard device request and request type\r
23// By [Spec-USB20/Chapter-9.4]\r
24//\r
25#define USB_DEV_GET_STATUS 0x00\r
26#define USB_DEV_GET_STATUS_REQ_TYPE_D 0x80 // Receiver : Device\r
27#define USB_DEV_GET_STATUS_REQ_TYPE_I 0x81 // Receiver : Interface\r
28#define USB_DEV_GET_STATUS_REQ_TYPE_E 0x82 // Receiver : Endpoint\r
29\r
30#define USB_DEV_CLEAR_FEATURE 0x01\r
31#define USB_DEV_CLEAR_FEATURE_REQ_TYPE_D 0x00 // Receiver : Device\r
32#define USB_DEV_CLEAR_FEATURE_REQ_TYPE_I 0x01 // Receiver : Interface\r
33#define USB_DEV_CLEAR_FEATURE_REQ_TYPE_E 0x02 // Receiver : Endpoint\r
34\r
35#define USB_DEV_SET_FEATURE 0x03\r
36#define USB_DEV_SET_FEATURE_REQ_TYPE_D 0x00 // Receiver : Device\r
37#define USB_DEV_SET_FEATURE_REQ_TYPE_I 0x01 // Receiver : Interface\r
38#define USB_DEV_SET_FEATURE_REQ_TYPE_E 0x02 // Receiver : Endpoint\r
39\r
40#define USB_DEV_SET_ADDRESS 0x05\r
41#define USB_DEV_SET_ADDRESS_REQ_TYPE 0x00\r
42\r
43#define USB_DEV_GET_DESCRIPTOR 0x06\r
44#define USB_DEV_GET_DESCRIPTOR_REQ_TYPE 0x80\r
45\r
46#define USB_DEV_SET_DESCRIPTOR 0x07\r
47#define USB_DEV_SET_DESCRIPTOR_REQ_TYPE 0x00\r
48\r
49#define USB_DEV_GET_CONFIGURATION 0x08\r
50#define USB_DEV_GET_CONFIGURATION_REQ_TYPE 0x80\r
51\r
52#define USB_DEV_SET_CONFIGURATION 0x09\r
53#define USB_DEV_SET_CONFIGURATION_REQ_TYPE 0x00\r
54\r
55#define USB_DEV_GET_INTERFACE 0x0A\r
56#define USB_DEV_GET_INTERFACE_REQ_TYPE 0x81\r
57\r
58#define USB_DEV_SET_INTERFACE 0x0B\r
59#define USB_DEV_SET_INTERFACE_REQ_TYPE 0x01\r
60\r
61#define USB_DEV_SYNCH_FRAME 0x0C\r
62#define USB_DEV_SYNCH_FRAME_REQ_TYPE 0x82\r
63\r
fb3df220 64//\r
65// define the timeout time as 3ms\r
66//\r
67#define TIMEOUT_VALUE 3 * 1000\r
68\r
69//\r
70// HID constants definition, see HID rev1.0\r
71//\r
72//\r
73// HID report item format\r
74//\r
75#define HID_ITEM_FORMAT_SHORT 0\r
76#define HID_ITEM_FORMAT_LONG 1\r
77\r
78//\r
79// Special tag indicating long items\r
80//\r
81#define HID_ITEM_TAG_LONG 15\r
82\r
83//\r
84// HID report descriptor item type (prefix bit 2,3)\r
85//\r
86#define HID_ITEM_TYPE_MAIN 0\r
87#define HID_ITEM_TYPE_GLOBAL 1\r
88#define HID_ITEM_TYPE_LOCAL 2\r
89#define HID_ITEM_TYPE_RESERVED 3\r
90\r
91//\r
92// HID report descriptor main item tags\r
93//\r
94#define HID_MAIN_ITEM_TAG_INPUT 8\r
95#define HID_MAIN_ITEM_TAG_OUTPUT 9\r
96#define HID_MAIN_ITEM_TAG_FEATURE 11\r
97#define HID_MAIN_ITEM_TAG_BEGIN_COLLECTION 10\r
98#define HID_MAIN_ITEM_TAG_END_COLLECTION 12\r
99\r
100//\r
101// HID report descriptor main item contents\r
102//\r
103#define HID_MAIN_ITEM_CONSTANT 0x001\r
104#define HID_MAIN_ITEM_VARIABLE 0x002\r
105#define HID_MAIN_ITEM_RELATIVE 0x004\r
106#define HID_MAIN_ITEM_WRAP 0x008\r
107#define HID_MAIN_ITEM_NONLINEAR 0x010\r
108#define HID_MAIN_ITEM_NO_PREFERRED 0x020\r
109#define HID_MAIN_ITEM_NULL_STATE 0x040\r
110#define HID_MAIN_ITEM_VOLATILE 0x080\r
111#define HID_MAIN_ITEM_BUFFERED_BYTE 0x100\r
112\r
113//\r
114// HID report descriptor collection item types\r
115//\r
116#define HID_COLLECTION_PHYSICAL 0\r
117#define HID_COLLECTION_APPLICATION 1\r
118#define HID_COLLECTION_LOGICAL 2\r
119\r
120//\r
121// HID report descriptor global item tags\r
122//\r
123#define HID_GLOBAL_ITEM_TAG_USAGE_PAGE 0\r
124#define HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM 1\r
125#define HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM 2\r
126#define HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM 3\r
127#define HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM 4\r
128#define HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT 5\r
129#define HID_GLOBAL_ITEM_TAG_UNIT 6\r
130#define HID_GLOBAL_ITEM_TAG_REPORT_SIZE 7\r
131#define HID_GLOBAL_ITEM_TAG_REPORT_ID 8\r
132#define HID_GLOBAL_ITEM_TAG_REPORT_COUNT 9\r
133#define HID_GLOBAL_ITEM_TAG_PUSH 10\r
134#define HID_GLOBAL_ITEM_TAG_POP 11\r
135\r
136//\r
137// HID report descriptor local item tags\r
138//\r
139#define HID_LOCAL_ITEM_TAG_USAGE 0\r
140#define HID_LOCAL_ITEM_TAG_USAGE_MINIMUM 1\r
141#define HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM 2\r
142#define HID_LOCAL_ITEM_TAG_DESIGNATOR_INDEX 3\r
143#define HID_LOCAL_ITEM_TAG_DESIGNATOR_MINIMUM 4\r
144#define HID_LOCAL_ITEM_TAG_DESIGNATOR_MAXIMUM 5\r
145#define HID_LOCAL_ITEM_TAG_STRING_INDEX 7\r
146#define HID_LOCAL_ITEM_TAG_STRING_MINIMUM 8\r
147#define HID_LOCAL_ITEM_TAG_STRING_MAXIMUM 9\r
148#define HID_LOCAL_ITEM_TAG_DELIMITER 10\r
149\r
150//\r
151// HID usage tables\r
152//\r
153#define HID_USAGE_PAGE 0xffff0000\r
154\r
155#define HID_UP_GENDESK 0x00010000\r
156#define HID_UP_KEYBOARD 0x00070000\r
157#define HID_UP_LED 0x00080000\r
158#define HID_UP_BUTTON 0x00090000\r
159#define HID_UP_CONSUMER 0x000c0000\r
160#define HID_UP_DIGITIZER 0x000d0000\r
161#define HID_UP_PID 0x000f0000\r
162\r
163#define HID_USAGE 0x0000ffff\r
164\r
165#define HID_GD_POINTER 0x00010001\r
166#define HID_GD_MOUSE 0x00010002\r
167#define HID_GD_JOYSTICK 0x00010004\r
168#define HID_GD_GAMEPAD 0x00010005\r
169#define HID_GD_HATSWITCH 0x00010039\r
170\r
171//\r
172// HID report types\r
173//\r
174#define HID_INPUT_REPORT 1\r
175#define HID_OUTPUT_REPORT 2\r
176#define HID_FEATURE_REPORT 3\r
177\r
178//\r
179// HID device quirks.\r
180//\r
181#define HID_QUIRK_INVERT 0x01\r
182#define HID_QUIRK_NOTOUCH 0x02\r
183\r
184//\r
185// HID class protocol request\r
186//\r
187#define EFI_USB_GET_REPORT_REQUEST 0x01\r
188#define EFI_USB_GET_IDLE_REQUEST 0x02\r
189#define EFI_USB_GET_PROTOCOL_REQUEST 0x03\r
190#define EFI_USB_SET_REPORT_REQUEST 0x09\r
191#define EFI_USB_SET_IDLE_REQUEST 0x0a\r
192#define EFI_USB_SET_PROTOCOL_REQUEST 0x0b\r
193\r
194#pragma pack(1)\r
195//\r
196// Descriptor header for Report/Physical Descriptors\r
197//\r
198typedef struct hid_class_descriptor {\r
199 UINT8 DescriptorType;\r
200 UINT16 DescriptorLength;\r
201} EFI_USB_HID_CLASS_DESCRIPTOR;\r
202\r
203typedef struct hid_descriptor {\r
204 UINT8 Length;\r
205 UINT8 DescriptorType;\r
206 UINT16 BcdHID;\r
207 UINT8 CountryCode;\r
208 UINT8 NumDescriptors;\r
209 EFI_USB_HID_CLASS_DESCRIPTOR HidClassDesc[1];\r
210} EFI_USB_HID_DESCRIPTOR;\r
211\r
212#pragma pack()\r
213\r
214EFI_STATUS\r
215UsbGetHidDescriptor (\r
216 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
217 IN UINT8 InterfaceNum,\r
218 OUT EFI_USB_HID_DESCRIPTOR *HidDescriptor\r
219 );\r
220\r
221EFI_STATUS\r
222UsbGetReportDescriptor (\r
223 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
224 IN UINT8 InterfaceNum,\r
225 IN UINT16 DescriptorSize,\r
226 OUT UINT8 *DescriptorBuffer\r
227 );\r
228\r
229EFI_STATUS\r
230UsbGetProtocolRequest (\r
231 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
232 IN UINT8 Interface,\r
233 IN UINT8 *Protocol\r
234 );\r
235\r
236EFI_STATUS\r
237UsbSetProtocolRequest (\r
238 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
239 IN UINT8 Interface,\r
240 IN UINT8 Protocol\r
241 );\r
242\r
243EFI_STATUS\r
244UsbSetIdleRequest (\r
245 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
246 IN UINT8 Interface,\r
247 IN UINT8 ReportId,\r
248 IN UINT8 Duration\r
249 );\r
250\r
251EFI_STATUS\r
252UsbGetIdleRequest (\r
253 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
254 IN UINT8 Interface,\r
255 IN UINT8 ReportId,\r
256 OUT UINT8 *Duration\r
257 );\r
258\r
259EFI_STATUS\r
260UsbSetReportRequest (\r
261 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
262 IN UINT8 Interface,\r
263 IN UINT8 ReportId,\r
264 IN UINT8 ReportType,\r
265 IN UINT16 ReportLen,\r
266 IN UINT8 *Report\r
267 );\r
268\r
269EFI_STATUS\r
270UsbGetReportRequest (\r
271 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
272 IN UINT8 Interface,\r
273 IN UINT8 ReportId,\r
274 IN UINT8 ReportType,\r
275 IN UINT16 ReportLen,\r
276 IN UINT8 *Report\r
277 );\r
278\r
ed838d0c 279typedef enum {\r
280 EfiUsbEndpointHalt,\r
281 EfiUsbDeviceRemoteWakeup\r
282} EFI_USB_STANDARD_FEATURE_SELECTOR;\r
283\r
fb3df220 284EFI_STATUS\r
285UsbGetDescriptor (\r
286 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
287 IN UINT16 Value,\r
288 IN UINT16 Index,\r
289 IN UINT16 DescriptorLength,\r
290 OUT VOID *Descriptor,\r
291 OUT UINT32 *Status\r
292 );\r
293\r
fb3df220 294EFI_STATUS\r
295UsbSetDescriptor (\r
296 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
297 IN UINT16 Value,\r
298 IN UINT16 Index,\r
299 IN UINT16 DescriptorLength,\r
300 IN VOID *Descriptor,\r
301 OUT UINT32 *Status\r
302 );\r
303\r
fb3df220 304EFI_STATUS\r
ed838d0c 305UsbGetInterface (\r
fb3df220 306 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
307 IN UINT16 Index,\r
308 OUT UINT8 *AltSetting,\r
309 OUT UINT32 *Status\r
310 );\r
311\r
fb3df220 312EFI_STATUS\r
ed838d0c 313UsbSetInterface (\r
fb3df220 314 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
315 IN UINT16 InterfaceNo,\r
316 IN UINT16 AltSetting,\r
317 OUT UINT32 *Status\r
318 );\r
319\r
fb3df220 320EFI_STATUS\r
ed838d0c 321UsbGetConfiguration (\r
fb3df220 322 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
323 OUT UINT8 *ConfigValue,\r
324 OUT UINT32 *Status\r
325 );\r
326\r
fb3df220 327EFI_STATUS\r
ed838d0c 328UsbSetConfiguration (\r
fb3df220 329 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
330 IN UINT16 Value,\r
331 OUT UINT32 *Status\r
332 );\r
333\r
fb3df220 334EFI_STATUS\r
ed838d0c 335UsbSetFeature (\r
fb3df220 336 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
ed838d0c 337 IN UINTN Recipient,\r
fb3df220 338 IN UINT16 Value,\r
339 IN UINT16 Target,\r
340 OUT UINT32 *Status\r
341 );\r
342\r
fb3df220 343EFI_STATUS\r
ed838d0c 344UsbClearFeature (\r
fb3df220 345 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
ed838d0c 346 IN UINTN Recipient,\r
fb3df220 347 IN UINT16 Value,\r
348 IN UINT16 Target,\r
349 OUT UINT32 *Status\r
350 );\r
351\r
fb3df220 352EFI_STATUS\r
ed838d0c 353UsbGetStatus (\r
fb3df220 354 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
ed838d0c 355 IN UINTN Recipient,\r
fb3df220 356 IN UINT16 Target,\r
357 OUT UINT16 *DevStatus,\r
358 OUT UINT32 *Status\r
359 );\r
360\r
fb3df220 361EFI_STATUS\r
ed838d0c 362UsbGetHubDescriptor (\r
fb3df220 363 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
ed838d0c 364 IN UINT16 Value,\r
365 IN UINT16 Index,\r
366 IN UINT16 DescriptorLength,\r
367 OUT VOID *Descriptor,\r
fb3df220 368 OUT UINT32 *Status\r
369 );\r
370\r
371//\r
372// Clear endpoint stall\r
373//\r
374EFI_STATUS\r
375UsbClearEndpointHalt (\r
376 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
377 IN UINT8 EndpointNo,\r
378 OUT UINT32 *Status\r
379 );\r
380\r
381#endif\r