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