2 Support for USB 2.0 standard.
4 Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
13 // Subset of Class and Subclass definitions from USB Specs
17 // Usb mass storage class code
19 #define USB_MASS_STORE_CLASS 0x08
22 // Usb mass storage subclass code, specify the command set used.
24 #define USB_MASS_STORE_RBC 0x01 ///< Reduced Block Commands
25 #define USB_MASS_STORE_8020I 0x02 ///< SFF-8020i, typically a CD/DVD device
26 #define USB_MASS_STORE_QIC 0x03 ///< Typically a tape device
27 #define USB_MASS_STORE_UFI 0x04 ///< Typically a floppy disk driver device
28 #define USB_MASS_STORE_8070I 0x05 ///< SFF-8070i, typically a floppy disk driver device.
29 #define USB_MASS_STORE_SCSI 0x06 ///< SCSI transparent command set
32 // Usb mass storage protocol code, specify the transport protocol
34 #define USB_MASS_STORE_CBI0 0x00 ///< CBI protocol with command completion interrupt
35 #define USB_MASS_STORE_CBI1 0x01 ///< CBI protocol without command completion interrupt
36 #define USB_MASS_STORE_BOT 0x50 ///< Bulk-Only Transport
39 // Standard device request and request type
40 // USB 2.0 spec, Section 9.4
42 #define USB_DEV_GET_STATUS 0x00
43 #define USB_DEV_GET_STATUS_REQ_TYPE_D 0x80 // Receiver : Device
44 #define USB_DEV_GET_STATUS_REQ_TYPE_I 0x81 // Receiver : Interface
45 #define USB_DEV_GET_STATUS_REQ_TYPE_E 0x82 // Receiver : Endpoint
47 #define USB_DEV_CLEAR_FEATURE 0x01
48 #define USB_DEV_CLEAR_FEATURE_REQ_TYPE_D 0x00 // Receiver : Device
49 #define USB_DEV_CLEAR_FEATURE_REQ_TYPE_I 0x01 // Receiver : Interface
50 #define USB_DEV_CLEAR_FEATURE_REQ_TYPE_E 0x02 // Receiver : Endpoint
52 #define USB_DEV_SET_FEATURE 0x03
53 #define USB_DEV_SET_FEATURE_REQ_TYPE_D 0x00 // Receiver : Device
54 #define USB_DEV_SET_FEATURE_REQ_TYPE_I 0x01 // Receiver : Interface
55 #define USB_DEV_SET_FEATURE_REQ_TYPE_E 0x02 // Receiver : Endpoint
57 #define USB_DEV_SET_ADDRESS 0x05
58 #define USB_DEV_SET_ADDRESS_REQ_TYPE 0x00
60 #define USB_DEV_GET_DESCRIPTOR 0x06
61 #define USB_DEV_GET_DESCRIPTOR_REQ_TYPE 0x80
63 #define USB_DEV_SET_DESCRIPTOR 0x07
64 #define USB_DEV_SET_DESCRIPTOR_REQ_TYPE 0x00
66 #define USB_DEV_GET_CONFIGURATION 0x08
67 #define USB_DEV_GET_CONFIGURATION_REQ_TYPE 0x80
69 #define USB_DEV_SET_CONFIGURATION 0x09
70 #define USB_DEV_SET_CONFIGURATION_REQ_TYPE 0x00
72 #define USB_DEV_GET_INTERFACE 0x0A
73 #define USB_DEV_GET_INTERFACE_REQ_TYPE 0x81
75 #define USB_DEV_SET_INTERFACE 0x0B
76 #define USB_DEV_SET_INTERFACE_REQ_TYPE 0x01
78 #define USB_DEV_SYNCH_FRAME 0x0C
79 #define USB_DEV_SYNCH_FRAME_REQ_TYPE 0x82
83 // USB standard descriptors and reqeust
88 /// Format of Setup Data for USB Device Requests
89 /// USB 2.0 spec, Section 9.3
100 /// Standard Device Descriptor
101 /// USB 2.0 spec, Section 9.6.1
105 UINT8 DescriptorType
;
108 UINT8 DeviceSubClass
;
109 UINT8 DeviceProtocol
;
110 UINT8 MaxPacketSize0
;
114 UINT8 StrManufacturer
;
116 UINT8 StrSerialNumber
;
117 UINT8 NumConfigurations
;
118 } USB_DEVICE_DESCRIPTOR
;
121 /// Standard Configuration Descriptor
122 /// USB 2.0 spec, Section 9.6.3
126 UINT8 DescriptorType
;
129 UINT8 ConfigurationValue
;
133 } USB_CONFIG_DESCRIPTOR
;
136 /// Standard Interface Descriptor
137 /// USB 2.0 spec, Section 9.6.5
141 UINT8 DescriptorType
;
142 UINT8 InterfaceNumber
;
143 UINT8 AlternateSetting
;
145 UINT8 InterfaceClass
;
146 UINT8 InterfaceSubClass
;
147 UINT8 InterfaceProtocol
;
149 } USB_INTERFACE_DESCRIPTOR
;
152 /// Standard Endpoint Descriptor
153 /// USB 2.0 spec, Section 9.6.6
157 UINT8 DescriptorType
;
158 UINT8 EndpointAddress
;
160 UINT16 MaxPacketSize
;
162 } USB_ENDPOINT_DESCRIPTOR
;
165 /// UNICODE String Descriptor
166 /// USB 2.0 spec, Section 9.6.7
170 UINT8 DescriptorType
;
172 } EFI_USB_STRING_DESCRIPTOR
;
181 USB_REQ_TYPE_STANDARD
= (0x00 << 5),
182 USB_REQ_TYPE_CLASS
= (0x01 << 5),
183 USB_REQ_TYPE_VENDOR
= (0x02 << 5),
186 // Standard control transfer request type, or the value
187 // to fill in EFI_USB_DEVICE_REQUEST.Request
189 USB_REQ_GET_STATUS
= 0x00,
190 USB_REQ_CLEAR_FEATURE
= 0x01,
191 USB_REQ_SET_FEATURE
= 0x03,
192 USB_REQ_SET_ADDRESS
= 0x05,
193 USB_REQ_GET_DESCRIPTOR
= 0x06,
194 USB_REQ_SET_DESCRIPTOR
= 0x07,
195 USB_REQ_GET_CONFIG
= 0x08,
196 USB_REQ_SET_CONFIG
= 0x09,
197 USB_REQ_GET_INTERFACE
= 0x0A,
198 USB_REQ_SET_INTERFACE
= 0x0B,
199 USB_REQ_SYNCH_FRAME
= 0x0C,
202 // Usb control transfer target
204 USB_TARGET_DEVICE
= 0,
205 USB_TARGET_INTERFACE
= 0x01,
206 USB_TARGET_ENDPOINT
= 0x02,
207 USB_TARGET_OTHER
= 0x03,
210 // USB Descriptor types
212 USB_DESC_TYPE_DEVICE
= 0x01,
213 USB_DESC_TYPE_CONFIG
= 0x02,
214 USB_DESC_TYPE_STRING
= 0x03,
215 USB_DESC_TYPE_INTERFACE
= 0x04,
216 USB_DESC_TYPE_ENDPOINT
= 0x05,
217 USB_DESC_TYPE_HID
= 0x21,
218 USB_DESC_TYPE_REPORT
= 0x22,
221 // Features to be cleared by CLEAR_FEATURE requests
223 USB_FEATURE_ENDPOINT_HALT
= 0,
226 // USB endpoint types: 00: control, 01: isochronous, 10: bulk, 11: interrupt
228 USB_ENDPOINT_CONTROL
= 0x00,
229 USB_ENDPOINT_ISO
= 0x01,
230 USB_ENDPOINT_BULK
= 0x02,
231 USB_ENDPOINT_INTERRUPT
= 0x03,
233 USB_ENDPOINT_TYPE_MASK
= 0x03,
234 USB_ENDPOINT_DIR_IN
= 0x80,
237 //Use 200 ms to increase the error handling response time
239 EFI_USB_INTERRUPT_DELAY
= 2000000
240 } USB_TYPES_DEFINITION
;
244 // HID constants definition, see Device Class Definition
245 // for Human Interface Devices (HID) rev1.11
249 // HID standard GET_DESCRIPTOR request.
251 #define USB_HID_GET_DESCRIPTOR_REQ_TYPE 0x81
254 // HID specific requests.
256 #define USB_HID_CLASS_GET_REQ_TYPE 0xa1
257 #define USB_HID_CLASS_SET_REQ_TYPE 0x21
260 // HID report item format
262 #define HID_ITEM_FORMAT_SHORT 0
263 #define HID_ITEM_FORMAT_LONG 1
266 // Special tag indicating long items
268 #define HID_ITEM_TAG_LONG 15
271 // HID report descriptor item type (prefix bit 2,3)
273 #define HID_ITEM_TYPE_MAIN 0
274 #define HID_ITEM_TYPE_GLOBAL 1
275 #define HID_ITEM_TYPE_LOCAL 2
276 #define HID_ITEM_TYPE_RESERVED 3
279 // HID report descriptor main item tags
281 #define HID_MAIN_ITEM_TAG_INPUT 8
282 #define HID_MAIN_ITEM_TAG_OUTPUT 9
283 #define HID_MAIN_ITEM_TAG_FEATURE 11
284 #define HID_MAIN_ITEM_TAG_BEGIN_COLLECTION 10
285 #define HID_MAIN_ITEM_TAG_END_COLLECTION 12
288 // HID report descriptor main item contents
290 #define HID_MAIN_ITEM_CONSTANT 0x001
291 #define HID_MAIN_ITEM_VARIABLE 0x002
292 #define HID_MAIN_ITEM_RELATIVE 0x004
293 #define HID_MAIN_ITEM_WRAP 0x008
294 #define HID_MAIN_ITEM_NONLINEAR 0x010
295 #define HID_MAIN_ITEM_NO_PREFERRED 0x020
296 #define HID_MAIN_ITEM_NULL_STATE 0x040
297 #define HID_MAIN_ITEM_VOLATILE 0x080
298 #define HID_MAIN_ITEM_BUFFERED_BYTE 0x100
301 // HID report descriptor collection item types
303 #define HID_COLLECTION_PHYSICAL 0
304 #define HID_COLLECTION_APPLICATION 1
305 #define HID_COLLECTION_LOGICAL 2
308 // HID report descriptor global item tags
310 #define HID_GLOBAL_ITEM_TAG_USAGE_PAGE 0
311 #define HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM 1
312 #define HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM 2
313 #define HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM 3
314 #define HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM 4
315 #define HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT 5
316 #define HID_GLOBAL_ITEM_TAG_UNIT 6
317 #define HID_GLOBAL_ITEM_TAG_REPORT_SIZE 7
318 #define HID_GLOBAL_ITEM_TAG_REPORT_ID 8
319 #define HID_GLOBAL_ITEM_TAG_REPORT_COUNT 9
320 #define HID_GLOBAL_ITEM_TAG_PUSH 10
321 #define HID_GLOBAL_ITEM_TAG_POP 11
324 // HID report descriptor local item tags
326 #define HID_LOCAL_ITEM_TAG_USAGE 0
327 #define HID_LOCAL_ITEM_TAG_USAGE_MINIMUM 1
328 #define HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM 2
329 #define HID_LOCAL_ITEM_TAG_DESIGNATOR_INDEX 3
330 #define HID_LOCAL_ITEM_TAG_DESIGNATOR_MINIMUM 4
331 #define HID_LOCAL_ITEM_TAG_DESIGNATOR_MAXIMUM 5
332 #define HID_LOCAL_ITEM_TAG_STRING_INDEX 7
333 #define HID_LOCAL_ITEM_TAG_STRING_MINIMUM 8
334 #define HID_LOCAL_ITEM_TAG_STRING_MAXIMUM 9
335 #define HID_LOCAL_ITEM_TAG_DELIMITER 10
340 #define HID_INPUT_REPORT 1
341 #define HID_OUTPUT_REPORT 2
342 #define HID_FEATURE_REPORT 3
345 // HID class protocol request
347 #define EFI_USB_GET_REPORT_REQUEST 0x01
348 #define EFI_USB_GET_IDLE_REQUEST 0x02
349 #define EFI_USB_GET_PROTOCOL_REQUEST 0x03
350 #define EFI_USB_SET_REPORT_REQUEST 0x09
351 #define EFI_USB_SET_IDLE_REQUEST 0x0a
352 #define EFI_USB_SET_PROTOCOL_REQUEST 0x0b
356 /// Descriptor header for Report/Physical Descriptors
357 /// HID 1.1, section 6.2.1
359 typedef struct hid_class_descriptor
{
360 UINT8 DescriptorType
;
361 UINT16 DescriptorLength
;
362 } EFI_USB_HID_CLASS_DESCRIPTOR
;
365 /// The HID descriptor identifies the length and type
366 /// of subordinate descriptors for a device.
367 /// HID 1.1, section 6.2.1
369 typedef struct hid_descriptor
{
371 UINT8 DescriptorType
;
374 UINT8 NumDescriptors
;
375 EFI_USB_HID_CLASS_DESCRIPTOR HidClassDesc
[1];
376 } EFI_USB_HID_DESCRIPTOR
;