]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdePkg/Include/IndustryStandard/Usb.h
Move some definitions defined in USB spec and HID Spec from Library/Usblib.h to Indus...
[mirror_edk2.git] / MdePkg / Include / IndustryStandard / Usb.h
... / ...
CommitLineData
1/** @file\r
2 Support for USB 1.1 standard.\r
3\r
4 Copyright (c) 2006 - 2007, Intel Corporation\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
14\r
15#ifndef __USB_H__\r
16#define __USB_H__\r
17\r
18//\r
19// Standard device request and request type\r
20// By [Spec-USB20/Chapter-9.4]\r
21//\r
22#define USB_DEV_GET_STATUS 0x00\r
23#define USB_DEV_GET_STATUS_REQ_TYPE_D 0x80 // Receiver : Device\r
24#define USB_DEV_GET_STATUS_REQ_TYPE_I 0x81 // Receiver : Interface\r
25#define USB_DEV_GET_STATUS_REQ_TYPE_E 0x82 // Receiver : Endpoint\r
26\r
27#define USB_DEV_CLEAR_FEATURE 0x01\r
28#define USB_DEV_CLEAR_FEATURE_REQ_TYPE_D 0x00 // Receiver : Device\r
29#define USB_DEV_CLEAR_FEATURE_REQ_TYPE_I 0x01 // Receiver : Interface\r
30#define USB_DEV_CLEAR_FEATURE_REQ_TYPE_E 0x02 // Receiver : Endpoint\r
31\r
32#define USB_DEV_SET_FEATURE 0x03\r
33#define USB_DEV_SET_FEATURE_REQ_TYPE_D 0x00 // Receiver : Device\r
34#define USB_DEV_SET_FEATURE_REQ_TYPE_I 0x01 // Receiver : Interface\r
35#define USB_DEV_SET_FEATURE_REQ_TYPE_E 0x02 // Receiver : Endpoint\r
36\r
37#define USB_DEV_SET_ADDRESS 0x05\r
38#define USB_DEV_SET_ADDRESS_REQ_TYPE 0x00\r
39\r
40#define USB_DEV_GET_DESCRIPTOR 0x06\r
41#define USB_DEV_GET_DESCRIPTOR_REQ_TYPE 0x80\r
42\r
43#define USB_DEV_SET_DESCRIPTOR 0x07\r
44#define USB_DEV_SET_DESCRIPTOR_REQ_TYPE 0x00\r
45\r
46#define USB_DEV_GET_CONFIGURATION 0x08\r
47#define USB_DEV_GET_CONFIGURATION_REQ_TYPE 0x80\r
48\r
49#define USB_DEV_SET_CONFIGURATION 0x09\r
50#define USB_DEV_SET_CONFIGURATION_REQ_TYPE 0x00\r
51\r
52#define USB_DEV_GET_INTERFACE 0x0A\r
53#define USB_DEV_GET_INTERFACE_REQ_TYPE 0x81\r
54\r
55#define USB_DEV_SET_INTERFACE 0x0B\r
56#define USB_DEV_SET_INTERFACE_REQ_TYPE 0x01\r
57\r
58#define USB_DEV_SYNCH_FRAME 0x0C\r
59#define USB_DEV_SYNCH_FRAME_REQ_TYPE 0x82\r
60\r
61//\r
62// Definitions defined in UEFI spec\r
63//\r
64\r
65//\r
66// USB Transfer Results\r
67//\r
68#define EFI_USB_NOERROR 0x00\r
69#define EFI_USB_ERR_NOTEXECUTE 0x01\r
70#define EFI_USB_ERR_STALL 0x02\r
71#define EFI_USB_ERR_BUFFER 0x04\r
72#define EFI_USB_ERR_BABBLE 0x08\r
73#define EFI_USB_ERR_NAK 0x10\r
74#define EFI_USB_ERR_CRC 0x20\r
75#define EFI_USB_ERR_TIMEOUT 0x40\r
76#define EFI_USB_ERR_BITSTUFF 0x80\r
77#define EFI_USB_ERR_SYSTEM 0x100\r
78\r
79//\r
80// Constant value for Port Status & Port Change Status\r
81//\r
82#define USB_PORT_STAT_CONNECTION 0x0001\r
83#define USB_PORT_STAT_ENABLE 0x0002\r
84#define USB_PORT_STAT_SUSPEND 0x0004\r
85#define USB_PORT_STAT_OVERCURRENT 0x0008\r
86#define USB_PORT_STAT_RESET 0x0010\r
87#define USB_PORT_STAT_POWER 0x0100\r
88#define USB_PORT_STAT_LOW_SPEED 0x0200\r
89#define USB_PORT_STAT_HIGH_SPEED 0x0400\r
90#define USB_PORT_STAT_OWNER 0x0800\r
91\r
92#define USB_PORT_STAT_C_CONNECTION 0x0001\r
93#define USB_PORT_STAT_C_ENABLE 0x0002\r
94#define USB_PORT_STAT_C_SUSPEND 0x0004\r
95#define USB_PORT_STAT_C_OVERCURRENT 0x0008\r
96#define USB_PORT_STAT_C_RESET 0x0010\r
97\r
98//\r
99// USB data transfer direction\r
100//\r
101typedef enum {\r
102 EfiUsbDataIn,\r
103 EfiUsbDataOut,\r
104 EfiUsbNoData\r
105} EFI_USB_DATA_DIRECTION;\r
106\r
107//\r
108// Usb port features\r
109//\r
110typedef enum {\r
111 EfiUsbPortEnable = 1,\r
112 EfiUsbPortSuspend = 2,\r
113 EfiUsbPortReset = 4,\r
114 EfiUsbPortPower = 8,\r
115 EfiUsbPortOwner = 13,\r
116 EfiUsbPortConnectChange = 16,\r
117 EfiUsbPortEnableChange = 17,\r
118 EfiUsbPortSuspendChange = 18,\r
119 EfiUsbPortOverCurrentChange = 19,\r
120 EfiUsbPortResetChange = 20\r
121} EFI_USB_PORT_FEATURE;\r
122\r
123\r
124//\r
125// USB standard descriptors and reqeust\r
126//\r
127#pragma pack(1)\r
128typedef struct {\r
129 UINT8 RequestType;\r
130 UINT8 Request;\r
131 UINT16 Value;\r
132 UINT16 Index;\r
133 UINT16 Length;\r
134} EFI_USB_DEVICE_REQUEST;\r
135\r
136typedef struct {\r
137 UINT8 Length;\r
138 UINT8 DescriptorType;\r
139 UINT16 BcdUSB;\r
140 UINT8 DeviceClass;\r
141 UINT8 DeviceSubClass;\r
142 UINT8 DeviceProtocol;\r
143 UINT8 MaxPacketSize0;\r
144 UINT16 IdVendor;\r
145 UINT16 IdProduct;\r
146 UINT16 BcdDevice;\r
147 UINT8 StrManufacturer;\r
148 UINT8 StrProduct;\r
149 UINT8 StrSerialNumber;\r
150 UINT8 NumConfigurations;\r
151} EFI_USB_DEVICE_DESCRIPTOR;\r
152\r
153typedef struct {\r
154 UINT8 Length;\r
155 UINT8 DescriptorType;\r
156 UINT16 TotalLength;\r
157 UINT8 NumInterfaces;\r
158 UINT8 ConfigurationValue;\r
159 UINT8 Configuration;\r
160 UINT8 Attributes;\r
161 UINT8 MaxPower;\r
162} EFI_USB_CONFIG_DESCRIPTOR;\r
163\r
164typedef struct {\r
165 UINT8 Length;\r
166 UINT8 DescriptorType;\r
167 UINT8 InterfaceNumber;\r
168 UINT8 AlternateSetting;\r
169 UINT8 NumEndpoints;\r
170 UINT8 InterfaceClass;\r
171 UINT8 InterfaceSubClass;\r
172 UINT8 InterfaceProtocol;\r
173 UINT8 Interface;\r
174} EFI_USB_INTERFACE_DESCRIPTOR;\r
175\r
176typedef struct {\r
177 UINT8 Length;\r
178 UINT8 DescriptorType;\r
179 UINT8 EndpointAddress;\r
180 UINT8 Attributes;\r
181 UINT16 MaxPacketSize;\r
182 UINT8 Interval;\r
183} EFI_USB_ENDPOINT_DESCRIPTOR;\r
184\r
185typedef struct {\r
186 UINT8 Length;\r
187 UINT8 DescriptorType;\r
188 CHAR16 String[1];\r
189} EFI_USB_STRING_DESCRIPTOR;\r
190\r
191#pragma pack()\r
192\r
193typedef struct {\r
194 UINT16 PortStatus;\r
195 UINT16 PortChangeStatus;\r
196} EFI_USB_PORT_STATUS;\r
197\r
198\r
199//\r
200// Following are definitions not specified by UEFI spec.\r
201// Add new definitions below this line\r
202//\r
203enum {\r
204 //\r
205 // USB request type\r
206 //\r
207 USB_REQ_TYPE_STANDARD = (0x00 << 5),\r
208 USB_REQ_TYPE_CLASS = (0x01 << 5),\r
209 USB_REQ_TYPE_VENDOR = (0x02 << 5),\r
210\r
211 //\r
212 // Standard control transfer request type, or the value\r
213 // to fill in EFI_USB_DEVICE_REQUEST.Request\r
214 //\r
215 USB_REQ_GET_STATUS = 0x00,\r
216 USB_REQ_CLEAR_FEATURE = 0x01,\r
217 USB_REQ_SET_FEATURE = 0x03,\r
218 USB_REQ_SET_ADDRESS = 0x05,\r
219 USB_REQ_GET_DESCRIPTOR = 0x06,\r
220 USB_REQ_SET_DESCRIPTOR = 0x07,\r
221 USB_REQ_GET_CONFIG = 0x08,\r
222 USB_REQ_SET_CONFIG = 0x09,\r
223 USB_REQ_GET_INTERFACE = 0x0A,\r
224 USB_REQ_SET_INTERFACE = 0x0B,\r
225 USB_REQ_SYNCH_FRAME = 0x0C,\r
226\r
227 //\r
228 // Usb control transfer target\r
229 //\r
230 USB_TARGET_DEVICE = 0,\r
231 USB_TARGET_INTERFACE = 0x01,\r
232 USB_TARGET_ENDPOINT = 0x02,\r
233 USB_TARGET_OTHER = 0x03,\r
234\r
235 //\r
236 // USB Descriptor types\r
237 //\r
238 USB_DESC_TYPE_DEVICE = 0x01,\r
239 USB_DESC_TYPE_CONFIG = 0x02,\r
240 USB_DESC_TYPE_STRING = 0x03,\r
241 USB_DESC_TYPE_INTERFACE = 0x04,\r
242 USB_DESC_TYPE_ENDPOINT = 0x05,\r
243 USB_DESC_TYPE_HID = 0x21,\r
244\r
245 //\r
246 // Features to be cleared by CLEAR_FEATURE requests\r
247 //\r
248 USB_FEATURE_ENDPOINT_HALT = 0,\r
249\r
250 //\r
251 // USB endpoint types: 00: control, 01: isochronous, 10: bulk, 11: interrupt\r
252 //\r
253 USB_ENDPOINT_CONTROL = 0x00,\r
254 USB_ENDPOINT_ISO = 0x01,\r
255 USB_ENDPOINT_BULK = 0x02,\r
256 USB_ENDPOINT_INTERRUPT = 0x03,\r
257\r
258 USB_ENDPOINT_TYPE_MASK = 0x03,\r
259 USB_ENDPOINT_DIR_IN = 0x80,\r
260\r
261 //\r
262 //Use 200 ms to increase the error handling response time\r
263 //\r
264 EFI_USB_INTERRUPT_DELAY = 2000000,\r
265};\r
266\r
267\r
268//\r
269// HID constants definition, see HID rev1.0\r
270//\r
271\r
272//\r
273// HID report item format\r
274//\r
275#define HID_ITEM_FORMAT_SHORT 0\r
276#define HID_ITEM_FORMAT_LONG 1\r
277\r
278//\r
279// Special tag indicating long items\r
280//\r
281#define HID_ITEM_TAG_LONG 15\r
282\r
283//\r
284// HID report descriptor item type (prefix bit 2,3)\r
285//\r
286#define HID_ITEM_TYPE_MAIN 0\r
287#define HID_ITEM_TYPE_GLOBAL 1\r
288#define HID_ITEM_TYPE_LOCAL 2\r
289#define HID_ITEM_TYPE_RESERVED 3\r
290\r
291//\r
292// HID report descriptor main item tags\r
293//\r
294#define HID_MAIN_ITEM_TAG_INPUT 8\r
295#define HID_MAIN_ITEM_TAG_OUTPUT 9\r
296#define HID_MAIN_ITEM_TAG_FEATURE 11\r
297#define HID_MAIN_ITEM_TAG_BEGIN_COLLECTION 10\r
298#define HID_MAIN_ITEM_TAG_END_COLLECTION 12\r
299\r
300//\r
301// HID report descriptor main item contents\r
302//\r
303#define HID_MAIN_ITEM_CONSTANT 0x001\r
304#define HID_MAIN_ITEM_VARIABLE 0x002\r
305#define HID_MAIN_ITEM_RELATIVE 0x004\r
306#define HID_MAIN_ITEM_WRAP 0x008\r
307#define HID_MAIN_ITEM_NONLINEAR 0x010\r
308#define HID_MAIN_ITEM_NO_PREFERRED 0x020\r
309#define HID_MAIN_ITEM_NULL_STATE 0x040\r
310#define HID_MAIN_ITEM_VOLATILE 0x080\r
311#define HID_MAIN_ITEM_BUFFERED_BYTE 0x100\r
312\r
313//\r
314// HID report descriptor collection item types\r
315//\r
316#define HID_COLLECTION_PHYSICAL 0\r
317#define HID_COLLECTION_APPLICATION 1\r
318#define HID_COLLECTION_LOGICAL 2\r
319\r
320//\r
321// HID report descriptor global item tags\r
322//\r
323#define HID_GLOBAL_ITEM_TAG_USAGE_PAGE 0\r
324#define HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM 1\r
325#define HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM 2\r
326#define HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM 3\r
327#define HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM 4\r
328#define HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT 5\r
329#define HID_GLOBAL_ITEM_TAG_UNIT 6\r
330#define HID_GLOBAL_ITEM_TAG_REPORT_SIZE 7\r
331#define HID_GLOBAL_ITEM_TAG_REPORT_ID 8\r
332#define HID_GLOBAL_ITEM_TAG_REPORT_COUNT 9\r
333#define HID_GLOBAL_ITEM_TAG_PUSH 10\r
334#define HID_GLOBAL_ITEM_TAG_POP 11\r
335\r
336//\r
337// HID report descriptor local item tags\r
338//\r
339#define HID_LOCAL_ITEM_TAG_USAGE 0\r
340#define HID_LOCAL_ITEM_TAG_USAGE_MINIMUM 1\r
341#define HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM 2\r
342#define HID_LOCAL_ITEM_TAG_DESIGNATOR_INDEX 3\r
343#define HID_LOCAL_ITEM_TAG_DESIGNATOR_MINIMUM 4\r
344#define HID_LOCAL_ITEM_TAG_DESIGNATOR_MAXIMUM 5\r
345#define HID_LOCAL_ITEM_TAG_STRING_INDEX 7\r
346#define HID_LOCAL_ITEM_TAG_STRING_MINIMUM 8\r
347#define HID_LOCAL_ITEM_TAG_STRING_MAXIMUM 9\r
348#define HID_LOCAL_ITEM_TAG_DELIMITER 10\r
349\r
350//\r
351// HID report types\r
352//\r
353#define HID_INPUT_REPORT 1\r
354#define HID_OUTPUT_REPORT 2\r
355#define HID_FEATURE_REPORT 3\r
356\r
357//\r
358// HID class protocol request\r
359//\r
360#define EFI_USB_GET_REPORT_REQUEST 0x01\r
361#define EFI_USB_GET_IDLE_REQUEST 0x02\r
362#define EFI_USB_GET_PROTOCOL_REQUEST 0x03\r
363#define EFI_USB_SET_REPORT_REQUEST 0x09\r
364#define EFI_USB_SET_IDLE_REQUEST 0x0a\r
365#define EFI_USB_SET_PROTOCOL_REQUEST 0x0b\r
366\r
367#pragma pack(1)\r
368//\r
369// Descriptor header for Report/Physical Descriptors\r
370//\r
371typedef struct hid_class_descriptor {\r
372 UINT8 DescriptorType;\r
373 UINT16 DescriptorLength;\r
374} EFI_USB_HID_CLASS_DESCRIPTOR;\r
375\r
376typedef struct hid_descriptor {\r
377 UINT8 Length;\r
378 UINT8 DescriptorType;\r
379 UINT16 BcdHID;\r
380 UINT8 CountryCode;\r
381 UINT8 NumDescriptors;\r
382 EFI_USB_HID_CLASS_DESCRIPTOR HidClassDesc[1];\r
383} EFI_USB_HID_DESCRIPTOR;\r
384\r
385#pragma pack()\r
386\r
387#endif\r