]>
Commit | Line | Data |
---|---|---|
a7ed1e2e | 1 | /** @file\r |
4135253b | 2 | Support for USB 2.0 standard.\r |
a7ed1e2e | 3 | \r |
431dac94 | 4 | Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r |
9344f092 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
a7ed1e2e | 6 | \r |
a7ed1e2e | 7 | **/\r |
8 | \r | |
9 | #ifndef __USB_H__\r | |
10 | #define __USB_H__\r | |
11 | \r | |
431dac94 | 12 | //\r |
13 | // Subset of Class and Subclass definitions from USB Specs\r | |
14 | //\r | |
15 | \r | |
16 | //\r | |
17 | // Usb mass storage class code\r | |
18 | //\r | |
19 | #define USB_MASS_STORE_CLASS 0x08\r | |
20 | \r | |
21 | //\r | |
22 | // Usb mass storage subclass code, specify the command set used.\r | |
23 | //\r | |
24 | #define USB_MASS_STORE_RBC 0x01 ///< Reduced Block Commands\r | |
25 | #define USB_MASS_STORE_8020I 0x02 ///< SFF-8020i, typically a CD/DVD device\r | |
26 | #define USB_MASS_STORE_QIC 0x03 ///< Typically a tape device\r | |
27 | #define USB_MASS_STORE_UFI 0x04 ///< Typically a floppy disk driver device\r | |
28 | #define USB_MASS_STORE_8070I 0x05 ///< SFF-8070i, typically a floppy disk driver device.\r | |
29 | #define USB_MASS_STORE_SCSI 0x06 ///< SCSI transparent command set\r | |
30 | \r | |
31 | //\r | |
32 | // Usb mass storage protocol code, specify the transport protocol\r | |
33 | //\r | |
34 | #define USB_MASS_STORE_CBI0 0x00 ///< CBI protocol with command completion interrupt\r | |
35 | #define USB_MASS_STORE_CBI1 0x01 ///< CBI protocol without command completion interrupt\r | |
36 | #define USB_MASS_STORE_BOT 0x50 ///< Bulk-Only Transport\r | |
37 | \r | |
9d1f975f | 38 | //\r |
39 | // Standard device request and request type\r | |
4135253b | 40 | // USB 2.0 spec, Section 9.4\r |
9d1f975f | 41 | //\r |
42 | #define USB_DEV_GET_STATUS 0x00\r | |
43 | #define USB_DEV_GET_STATUS_REQ_TYPE_D 0x80 // Receiver : Device\r | |
44 | #define USB_DEV_GET_STATUS_REQ_TYPE_I 0x81 // Receiver : Interface\r | |
45 | #define USB_DEV_GET_STATUS_REQ_TYPE_E 0x82 // Receiver : Endpoint\r | |
46 | \r | |
47 | #define USB_DEV_CLEAR_FEATURE 0x01\r | |
48 | #define USB_DEV_CLEAR_FEATURE_REQ_TYPE_D 0x00 // Receiver : Device\r | |
49 | #define USB_DEV_CLEAR_FEATURE_REQ_TYPE_I 0x01 // Receiver : Interface\r | |
50 | #define USB_DEV_CLEAR_FEATURE_REQ_TYPE_E 0x02 // Receiver : Endpoint\r | |
51 | \r | |
52 | #define USB_DEV_SET_FEATURE 0x03\r | |
53 | #define USB_DEV_SET_FEATURE_REQ_TYPE_D 0x00 // Receiver : Device\r | |
54 | #define USB_DEV_SET_FEATURE_REQ_TYPE_I 0x01 // Receiver : Interface\r | |
55 | #define USB_DEV_SET_FEATURE_REQ_TYPE_E 0x02 // Receiver : Endpoint\r | |
56 | \r | |
57 | #define USB_DEV_SET_ADDRESS 0x05\r | |
58 | #define USB_DEV_SET_ADDRESS_REQ_TYPE 0x00\r | |
59 | \r | |
60 | #define USB_DEV_GET_DESCRIPTOR 0x06\r | |
61 | #define USB_DEV_GET_DESCRIPTOR_REQ_TYPE 0x80\r | |
62 | \r | |
63 | #define USB_DEV_SET_DESCRIPTOR 0x07\r | |
64 | #define USB_DEV_SET_DESCRIPTOR_REQ_TYPE 0x00\r | |
65 | \r | |
66 | #define USB_DEV_GET_CONFIGURATION 0x08\r | |
67 | #define USB_DEV_GET_CONFIGURATION_REQ_TYPE 0x80\r | |
68 | \r | |
69 | #define USB_DEV_SET_CONFIGURATION 0x09\r | |
70 | #define USB_DEV_SET_CONFIGURATION_REQ_TYPE 0x00\r | |
71 | \r | |
72 | #define USB_DEV_GET_INTERFACE 0x0A\r | |
73 | #define USB_DEV_GET_INTERFACE_REQ_TYPE 0x81\r | |
74 | \r | |
75 | #define USB_DEV_SET_INTERFACE 0x0B\r | |
76 | #define USB_DEV_SET_INTERFACE_REQ_TYPE 0x01\r | |
77 | \r | |
78 | #define USB_DEV_SYNCH_FRAME 0x0C\r | |
79 | #define USB_DEV_SYNCH_FRAME_REQ_TYPE 0x82\r | |
a7ed1e2e | 80 | \r |
a7ed1e2e | 81 | \r |
a7ed1e2e | 82 | //\r |
196d5cd1 | 83 | // USB standard descriptors and reqeust\r |
a7ed1e2e | 84 | //\r |
766f4bc1 | 85 | #pragma pack(1)\r |
4135253b | 86 | \r |
87 | ///\r | |
88 | /// Format of Setup Data for USB Device Requests\r | |
89 | /// USB 2.0 spec, Section 9.3\r | |
90 | ///\r | |
a7ed1e2e | 91 | typedef struct {\r |
196d5cd1 | 92 | UINT8 RequestType;\r |
93 | UINT8 Request;\r | |
94 | UINT16 Value;\r | |
95 | UINT16 Index;\r | |
96 | UINT16 Length;\r | |
e3c6b3d9 | 97 | } USB_DEVICE_REQUEST;\r |
a7ed1e2e | 98 | \r |
4135253b | 99 | ///\r |
100 | /// Standard Device Descriptor\r | |
101 | /// USB 2.0 spec, Section 9.6.1\r | |
102 | ///\r | |
196d5cd1 | 103 | typedef struct {\r |
104 | UINT8 Length;\r | |
105 | UINT8 DescriptorType;\r | |
106 | UINT16 BcdUSB;\r | |
107 | UINT8 DeviceClass;\r | |
108 | UINT8 DeviceSubClass;\r | |
109 | UINT8 DeviceProtocol;\r | |
110 | UINT8 MaxPacketSize0;\r | |
111 | UINT16 IdVendor;\r | |
112 | UINT16 IdProduct;\r | |
113 | UINT16 BcdDevice;\r | |
114 | UINT8 StrManufacturer;\r | |
115 | UINT8 StrProduct;\r | |
116 | UINT8 StrSerialNumber;\r | |
117 | UINT8 NumConfigurations;\r | |
e3c6b3d9 | 118 | } USB_DEVICE_DESCRIPTOR;\r |
a7ed1e2e | 119 | \r |
4135253b | 120 | ///\r |
121 | /// Standard Configuration Descriptor\r | |
122 | /// USB 2.0 spec, Section 9.6.3\r | |
123 | ///\r | |
a7ed1e2e | 124 | typedef struct {\r |
196d5cd1 | 125 | UINT8 Length;\r |
126 | UINT8 DescriptorType;\r | |
127 | UINT16 TotalLength;\r | |
128 | UINT8 NumInterfaces;\r | |
129 | UINT8 ConfigurationValue;\r | |
130 | UINT8 Configuration;\r | |
131 | UINT8 Attributes;\r | |
132 | UINT8 MaxPower;\r | |
e3c6b3d9 | 133 | } USB_CONFIG_DESCRIPTOR;\r |
a7ed1e2e | 134 | \r |
4135253b | 135 | ///\r |
136 | /// Standard Interface Descriptor\r | |
137 | /// USB 2.0 spec, Section 9.6.5\r | |
138 | ///\r | |
a7ed1e2e | 139 | typedef struct {\r |
196d5cd1 | 140 | UINT8 Length;\r |
141 | UINT8 DescriptorType;\r | |
142 | UINT8 InterfaceNumber;\r | |
143 | UINT8 AlternateSetting;\r | |
144 | UINT8 NumEndpoints;\r | |
145 | UINT8 InterfaceClass;\r | |
146 | UINT8 InterfaceSubClass;\r | |
147 | UINT8 InterfaceProtocol;\r | |
148 | UINT8 Interface;\r | |
e3c6b3d9 | 149 | } USB_INTERFACE_DESCRIPTOR;\r |
a7ed1e2e | 150 | \r |
4135253b | 151 | ///\r |
152 | /// Standard Endpoint Descriptor\r | |
153 | /// USB 2.0 spec, Section 9.6.6\r | |
154 | ///\r | |
a7ed1e2e | 155 | typedef struct {\r |
196d5cd1 | 156 | UINT8 Length;\r |
157 | UINT8 DescriptorType;\r | |
158 | UINT8 EndpointAddress;\r | |
159 | UINT8 Attributes;\r | |
160 | UINT16 MaxPacketSize;\r | |
161 | UINT8 Interval;\r | |
e3c6b3d9 | 162 | } USB_ENDPOINT_DESCRIPTOR;\r |
a7ed1e2e | 163 | \r |
4135253b | 164 | ///\r |
165 | /// UNICODE String Descriptor\r | |
166 | /// USB 2.0 spec, Section 9.6.7\r | |
167 | ///\r | |
a7ed1e2e | 168 | typedef struct {\r |
196d5cd1 | 169 | UINT8 Length;\r |
170 | UINT8 DescriptorType;\r | |
171 | CHAR16 String[1];\r | |
a7ed1e2e | 172 | } EFI_USB_STRING_DESCRIPTOR;\r |
173 | \r | |
766f4bc1 | 174 | #pragma pack()\r |
175 | \r | |
176 | \r | |
42eedea9 | 177 | typedef enum {\r |
196d5cd1 | 178 | //\r |
179 | // USB request type\r | |
180 | //\r | |
181 | USB_REQ_TYPE_STANDARD = (0x00 << 5),\r | |
182 | USB_REQ_TYPE_CLASS = (0x01 << 5),\r | |
183 | USB_REQ_TYPE_VENDOR = (0x02 << 5),\r | |
184 | \r | |
185 | //\r | |
186 | // Standard control transfer request type, or the value\r | |
187 | // to fill in EFI_USB_DEVICE_REQUEST.Request\r | |
188 | //\r | |
189 | USB_REQ_GET_STATUS = 0x00,\r | |
190 | USB_REQ_CLEAR_FEATURE = 0x01,\r | |
191 | USB_REQ_SET_FEATURE = 0x03,\r | |
192 | USB_REQ_SET_ADDRESS = 0x05,\r | |
193 | USB_REQ_GET_DESCRIPTOR = 0x06,\r | |
194 | USB_REQ_SET_DESCRIPTOR = 0x07,\r | |
195 | USB_REQ_GET_CONFIG = 0x08,\r | |
196 | USB_REQ_SET_CONFIG = 0x09,\r | |
197 | USB_REQ_GET_INTERFACE = 0x0A,\r | |
198 | USB_REQ_SET_INTERFACE = 0x0B,\r | |
199 | USB_REQ_SYNCH_FRAME = 0x0C,\r | |
200 | \r | |
201 | //\r | |
202 | // Usb control transfer target\r | |
203 | //\r | |
204 | USB_TARGET_DEVICE = 0,\r | |
205 | USB_TARGET_INTERFACE = 0x01,\r | |
206 | USB_TARGET_ENDPOINT = 0x02,\r | |
207 | USB_TARGET_OTHER = 0x03,\r | |
208 | \r | |
209 | //\r | |
210 | // USB Descriptor types\r | |
211 | //\r | |
212 | USB_DESC_TYPE_DEVICE = 0x01,\r | |
213 | USB_DESC_TYPE_CONFIG = 0x02,\r | |
214 | USB_DESC_TYPE_STRING = 0x03,\r | |
215 | USB_DESC_TYPE_INTERFACE = 0x04,\r | |
216 | USB_DESC_TYPE_ENDPOINT = 0x05,\r | |
217 | USB_DESC_TYPE_HID = 0x21,\r | |
11ceade4 | 218 | USB_DESC_TYPE_REPORT = 0x22,\r |
196d5cd1 | 219 | \r |
220 | //\r | |
221 | // Features to be cleared by CLEAR_FEATURE requests\r | |
222 | //\r | |
223 | USB_FEATURE_ENDPOINT_HALT = 0,\r | |
224 | \r | |
225 | //\r | |
226 | // USB endpoint types: 00: control, 01: isochronous, 10: bulk, 11: interrupt\r | |
227 | //\r | |
228 | USB_ENDPOINT_CONTROL = 0x00,\r | |
229 | USB_ENDPOINT_ISO = 0x01,\r | |
230 | USB_ENDPOINT_BULK = 0x02,\r | |
231 | USB_ENDPOINT_INTERRUPT = 0x03,\r | |
232 | \r | |
233 | USB_ENDPOINT_TYPE_MASK = 0x03,\r | |
234 | USB_ENDPOINT_DIR_IN = 0x80,\r | |
235 | \r | |
236 | //\r | |
237 | //Use 200 ms to increase the error handling response time\r | |
238 | //\r | |
1b2afeaa | 239 | EFI_USB_INTERRUPT_DELAY = 2000000\r |
42eedea9 | 240 | } USB_TYPES_DEFINITION;\r |
9d1f975f | 241 | \r |
242 | \r | |
243 | //\r | |
4135253b | 244 | // HID constants definition, see Device Class Definition\r |
245 | // for Human Interface Devices (HID) rev1.11\r | |
9d1f975f | 246 | //\r |
247 | \r | |
11ceade4 LG |
248 | //\r |
249 | // HID standard GET_DESCRIPTOR request.\r | |
250 | //\r | |
251 | #define USB_HID_GET_DESCRIPTOR_REQ_TYPE 0x81\r | |
252 | \r | |
253 | //\r | |
254 | // HID specific requests.\r | |
255 | //\r | |
256 | #define USB_HID_CLASS_GET_REQ_TYPE 0xa1\r | |
257 | #define USB_HID_CLASS_SET_REQ_TYPE 0x21\r | |
258 | \r | |
9d1f975f | 259 | //\r |
260 | // HID report item format\r | |
261 | //\r | |
262 | #define HID_ITEM_FORMAT_SHORT 0\r | |
263 | #define HID_ITEM_FORMAT_LONG 1\r | |
264 | \r | |
265 | //\r | |
266 | // Special tag indicating long items\r | |
267 | //\r | |
268 | #define HID_ITEM_TAG_LONG 15\r | |
269 | \r | |
270 | //\r | |
271 | // HID report descriptor item type (prefix bit 2,3)\r | |
272 | //\r | |
273 | #define HID_ITEM_TYPE_MAIN 0\r | |
274 | #define HID_ITEM_TYPE_GLOBAL 1\r | |
275 | #define HID_ITEM_TYPE_LOCAL 2\r | |
276 | #define HID_ITEM_TYPE_RESERVED 3\r | |
277 | \r | |
278 | //\r | |
279 | // HID report descriptor main item tags\r | |
280 | //\r | |
281 | #define HID_MAIN_ITEM_TAG_INPUT 8\r | |
282 | #define HID_MAIN_ITEM_TAG_OUTPUT 9\r | |
283 | #define HID_MAIN_ITEM_TAG_FEATURE 11\r | |
284 | #define HID_MAIN_ITEM_TAG_BEGIN_COLLECTION 10\r | |
285 | #define HID_MAIN_ITEM_TAG_END_COLLECTION 12\r | |
286 | \r | |
287 | //\r | |
288 | // HID report descriptor main item contents\r | |
289 | //\r | |
290 | #define HID_MAIN_ITEM_CONSTANT 0x001\r | |
291 | #define HID_MAIN_ITEM_VARIABLE 0x002\r | |
292 | #define HID_MAIN_ITEM_RELATIVE 0x004\r | |
293 | #define HID_MAIN_ITEM_WRAP 0x008\r | |
294 | #define HID_MAIN_ITEM_NONLINEAR 0x010\r | |
295 | #define HID_MAIN_ITEM_NO_PREFERRED 0x020\r | |
296 | #define HID_MAIN_ITEM_NULL_STATE 0x040\r | |
297 | #define HID_MAIN_ITEM_VOLATILE 0x080\r | |
298 | #define HID_MAIN_ITEM_BUFFERED_BYTE 0x100\r | |
299 | \r | |
300 | //\r | |
301 | // HID report descriptor collection item types\r | |
302 | //\r | |
303 | #define HID_COLLECTION_PHYSICAL 0\r | |
304 | #define HID_COLLECTION_APPLICATION 1\r | |
305 | #define HID_COLLECTION_LOGICAL 2\r | |
306 | \r | |
307 | //\r | |
308 | // HID report descriptor global item tags\r | |
309 | //\r | |
310 | #define HID_GLOBAL_ITEM_TAG_USAGE_PAGE 0\r | |
311 | #define HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM 1\r | |
312 | #define HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM 2\r | |
313 | #define HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM 3\r | |
314 | #define HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM 4\r | |
315 | #define HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT 5\r | |
316 | #define HID_GLOBAL_ITEM_TAG_UNIT 6\r | |
317 | #define HID_GLOBAL_ITEM_TAG_REPORT_SIZE 7\r | |
318 | #define HID_GLOBAL_ITEM_TAG_REPORT_ID 8\r | |
319 | #define HID_GLOBAL_ITEM_TAG_REPORT_COUNT 9\r | |
320 | #define HID_GLOBAL_ITEM_TAG_PUSH 10\r | |
321 | #define HID_GLOBAL_ITEM_TAG_POP 11\r | |
322 | \r | |
323 | //\r | |
324 | // HID report descriptor local item tags\r | |
325 | //\r | |
326 | #define HID_LOCAL_ITEM_TAG_USAGE 0\r | |
327 | #define HID_LOCAL_ITEM_TAG_USAGE_MINIMUM 1\r | |
328 | #define HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM 2\r | |
329 | #define HID_LOCAL_ITEM_TAG_DESIGNATOR_INDEX 3\r | |
330 | #define HID_LOCAL_ITEM_TAG_DESIGNATOR_MINIMUM 4\r | |
331 | #define HID_LOCAL_ITEM_TAG_DESIGNATOR_MAXIMUM 5\r | |
332 | #define HID_LOCAL_ITEM_TAG_STRING_INDEX 7\r | |
333 | #define HID_LOCAL_ITEM_TAG_STRING_MINIMUM 8\r | |
334 | #define HID_LOCAL_ITEM_TAG_STRING_MAXIMUM 9\r | |
335 | #define HID_LOCAL_ITEM_TAG_DELIMITER 10\r | |
336 | \r | |
337 | //\r | |
338 | // HID report types\r | |
339 | //\r | |
340 | #define HID_INPUT_REPORT 1\r | |
341 | #define HID_OUTPUT_REPORT 2\r | |
342 | #define HID_FEATURE_REPORT 3\r | |
343 | \r | |
344 | //\r | |
345 | // HID class protocol request\r | |
346 | //\r | |
347 | #define EFI_USB_GET_REPORT_REQUEST 0x01\r | |
348 | #define EFI_USB_GET_IDLE_REQUEST 0x02\r | |
349 | #define EFI_USB_GET_PROTOCOL_REQUEST 0x03\r | |
350 | #define EFI_USB_SET_REPORT_REQUEST 0x09\r | |
351 | #define EFI_USB_SET_IDLE_REQUEST 0x0a\r | |
352 | #define EFI_USB_SET_PROTOCOL_REQUEST 0x0b\r | |
353 | \r | |
354 | #pragma pack(1)\r | |
1bc5d021 | 355 | ///\r |
356 | /// Descriptor header for Report/Physical Descriptors\r | |
427987f5 | 357 | /// HID 1.1, section 6.2.1\r |
1bc5d021 | 358 | ///\r |
9d1f975f | 359 | typedef struct hid_class_descriptor {\r |
360 | UINT8 DescriptorType;\r | |
361 | UINT16 DescriptorLength;\r | |
362 | } EFI_USB_HID_CLASS_DESCRIPTOR;\r | |
363 | \r | |
4135253b | 364 | ///\r |
365 | /// The HID descriptor identifies the length and type\r | |
366 | /// of subordinate descriptors for a device.\r | |
427987f5 | 367 | /// HID 1.1, section 6.2.1\r |
4135253b | 368 | ///\r |
9d1f975f | 369 | typedef struct hid_descriptor {\r |
370 | UINT8 Length;\r | |
371 | UINT8 DescriptorType;\r | |
372 | UINT16 BcdHID;\r | |
373 | UINT8 CountryCode;\r | |
374 | UINT8 NumDescriptors;\r | |
375 | EFI_USB_HID_CLASS_DESCRIPTOR HidClassDesc[1];\r | |
376 | } EFI_USB_HID_DESCRIPTOR;\r | |
766f4bc1 | 377 | \r |
c76a83cc | 378 | #pragma pack()\r |
9d1f975f | 379 | \r |
a7ed1e2e | 380 | #endif\r |