root / hw / usb.h @ 7e0a9247
History | View | Annotate | Download (17.5 kB)
1 | 62aed765 | Anthony Liguori | #ifndef QEMU_USB_H
|
---|---|---|---|
2 | 62aed765 | Anthony Liguori | #define QEMU_USB_H
|
3 | 62aed765 | Anthony Liguori | |
4 | bb36d470 | bellard | /*
|
5 | bb36d470 | bellard | * QEMU USB API
|
6 | 5fafdf24 | ths | *
|
7 | bb36d470 | bellard | * Copyright (c) 2005 Fabrice Bellard
|
8 | 5fafdf24 | ths | *
|
9 | bb36d470 | bellard | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
10 | bb36d470 | bellard | * of this software and associated documentation files (the "Software"), to deal
|
11 | bb36d470 | bellard | * in the Software without restriction, including without limitation the rights
|
12 | bb36d470 | bellard | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
13 | bb36d470 | bellard | * copies of the Software, and to permit persons to whom the Software is
|
14 | bb36d470 | bellard | * furnished to do so, subject to the following conditions:
|
15 | bb36d470 | bellard | *
|
16 | bb36d470 | bellard | * The above copyright notice and this permission notice shall be included in
|
17 | bb36d470 | bellard | * all copies or substantial portions of the Software.
|
18 | bb36d470 | bellard | *
|
19 | bb36d470 | bellard | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
20 | bb36d470 | bellard | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
21 | bb36d470 | bellard | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
22 | bb36d470 | bellard | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
23 | bb36d470 | bellard | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
24 | bb36d470 | bellard | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
25 | bb36d470 | bellard | * THE SOFTWARE.
|
26 | bb36d470 | bellard | */
|
27 | c0f4ce77 | aliguori | |
28 | 806b6024 | Gerd Hoffmann | #include "qdev.h" |
29 | 72cf2d4f | Blue Swirl | #include "qemu-queue.h" |
30 | c0f4ce77 | aliguori | |
31 | 8e257816 | Brad Hards | /* Constants related to the USB / PCI interaction */
|
32 | 8e257816 | Brad Hards | #define USB_SBRN 0x60 /* Serial Bus Release Number Register */ |
33 | 8e257816 | Brad Hards | #define USB_RELEASE_1 0x10 /* USB 1.0 */ |
34 | 8e257816 | Brad Hards | #define USB_RELEASE_2 0x20 /* USB 2.0 */ |
35 | 8e257816 | Brad Hards | #define USB_RELEASE_3 0x30 /* USB 3.0 */ |
36 | 8e257816 | Brad Hards | |
37 | bb36d470 | bellard | #define USB_TOKEN_SETUP 0x2d |
38 | bb36d470 | bellard | #define USB_TOKEN_IN 0x69 /* device -> host */ |
39 | bb36d470 | bellard | #define USB_TOKEN_OUT 0xe1 /* host -> device */ |
40 | bb36d470 | bellard | |
41 | 9a77a0f5 | Hans de Goede | #define USB_RET_SUCCESS (0) |
42 | 36dfe324 | Hans de Goede | #define USB_RET_NODEV (-1) |
43 | 36dfe324 | Hans de Goede | #define USB_RET_NAK (-2) |
44 | 36dfe324 | Hans de Goede | #define USB_RET_STALL (-3) |
45 | 36dfe324 | Hans de Goede | #define USB_RET_BABBLE (-4) |
46 | 36dfe324 | Hans de Goede | #define USB_RET_IOERROR (-5) |
47 | 36dfe324 | Hans de Goede | #define USB_RET_ASYNC (-6) |
48 | 36dfe324 | Hans de Goede | #define USB_RET_ADD_TO_QUEUE (-7) |
49 | 0cae7b1a | Hans de Goede | #define USB_RET_REMOVE_FROM_QUEUE (-8) |
50 | bb36d470 | bellard | |
51 | bb36d470 | bellard | #define USB_SPEED_LOW 0 |
52 | bb36d470 | bellard | #define USB_SPEED_FULL 1 |
53 | bb36d470 | bellard | #define USB_SPEED_HIGH 2 |
54 | 843d4e0c | Gerd Hoffmann | #define USB_SPEED_SUPER 3 |
55 | 843d4e0c | Gerd Hoffmann | |
56 | 843d4e0c | Gerd Hoffmann | #define USB_SPEED_MASK_LOW (1 << USB_SPEED_LOW) |
57 | 843d4e0c | Gerd Hoffmann | #define USB_SPEED_MASK_FULL (1 << USB_SPEED_FULL) |
58 | 843d4e0c | Gerd Hoffmann | #define USB_SPEED_MASK_HIGH (1 << USB_SPEED_HIGH) |
59 | 843d4e0c | Gerd Hoffmann | #define USB_SPEED_MASK_SUPER (1 << USB_SPEED_SUPER) |
60 | bb36d470 | bellard | |
61 | bb36d470 | bellard | #define USB_STATE_NOTATTACHED 0 |
62 | bb36d470 | bellard | #define USB_STATE_ATTACHED 1 |
63 | bb36d470 | bellard | //#define USB_STATE_POWERED 2
|
64 | bb36d470 | bellard | #define USB_STATE_DEFAULT 3 |
65 | bb36d470 | bellard | //#define USB_STATE_ADDRESS 4
|
66 | bb36d470 | bellard | //#define USB_STATE_CONFIGURED 5
|
67 | bb36d470 | bellard | #define USB_STATE_SUSPENDED 6 |
68 | bb36d470 | bellard | |
69 | a594cfbf | bellard | #define USB_CLASS_AUDIO 1 |
70 | a594cfbf | bellard | #define USB_CLASS_COMM 2 |
71 | a594cfbf | bellard | #define USB_CLASS_HID 3 |
72 | a594cfbf | bellard | #define USB_CLASS_PHYSICAL 5 |
73 | a594cfbf | bellard | #define USB_CLASS_STILL_IMAGE 6 |
74 | a594cfbf | bellard | #define USB_CLASS_PRINTER 7 |
75 | a594cfbf | bellard | #define USB_CLASS_MASS_STORAGE 8 |
76 | a594cfbf | bellard | #define USB_CLASS_HUB 9 |
77 | a594cfbf | bellard | #define USB_CLASS_CDC_DATA 0x0a |
78 | a594cfbf | bellard | #define USB_CLASS_CSCID 0x0b |
79 | a594cfbf | bellard | #define USB_CLASS_CONTENT_SEC 0x0d |
80 | a594cfbf | bellard | #define USB_CLASS_APP_SPEC 0xfe |
81 | a594cfbf | bellard | #define USB_CLASS_VENDOR_SPEC 0xff |
82 | a594cfbf | bellard | |
83 | b870472d | H. Peter Anvin | #define USB_SUBCLASS_UNDEFINED 0 |
84 | b870472d | H. Peter Anvin | #define USB_SUBCLASS_AUDIO_CONTROL 1 |
85 | b870472d | H. Peter Anvin | #define USB_SUBCLASS_AUDIO_STREAMING 2 |
86 | b870472d | H. Peter Anvin | #define USB_SUBCLASS_AUDIO_MIDISTREAMING 3 |
87 | b870472d | H. Peter Anvin | |
88 | bb36d470 | bellard | #define USB_DIR_OUT 0 |
89 | bb36d470 | bellard | #define USB_DIR_IN 0x80 |
90 | bb36d470 | bellard | |
91 | bb36d470 | bellard | #define USB_TYPE_MASK (0x03 << 5) |
92 | bb36d470 | bellard | #define USB_TYPE_STANDARD (0x00 << 5) |
93 | bb36d470 | bellard | #define USB_TYPE_CLASS (0x01 << 5) |
94 | bb36d470 | bellard | #define USB_TYPE_VENDOR (0x02 << 5) |
95 | bb36d470 | bellard | #define USB_TYPE_RESERVED (0x03 << 5) |
96 | bb36d470 | bellard | |
97 | bb36d470 | bellard | #define USB_RECIP_MASK 0x1f |
98 | bb36d470 | bellard | #define USB_RECIP_DEVICE 0x00 |
99 | bb36d470 | bellard | #define USB_RECIP_INTERFACE 0x01 |
100 | bb36d470 | bellard | #define USB_RECIP_ENDPOINT 0x02 |
101 | bb36d470 | bellard | #define USB_RECIP_OTHER 0x03 |
102 | bb36d470 | bellard | |
103 | bb36d470 | bellard | #define DeviceRequest ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_DEVICE)<<8) |
104 | bb36d470 | bellard | #define DeviceOutRequest ((USB_DIR_OUT|USB_TYPE_STANDARD|USB_RECIP_DEVICE)<<8) |
105 | 59ae540c | bellard | #define InterfaceRequest \
|
106 | 59ae540c | bellard | ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_INTERFACE)<<8)
|
107 | 59ae540c | bellard | #define InterfaceOutRequest \
|
108 | 59ae540c | bellard | ((USB_DIR_OUT|USB_TYPE_STANDARD|USB_RECIP_INTERFACE)<<8)
|
109 | 59ae540c | bellard | #define EndpointRequest ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_ENDPOINT)<<8) |
110 | 59ae540c | bellard | #define EndpointOutRequest \
|
111 | 59ae540c | bellard | ((USB_DIR_OUT|USB_TYPE_STANDARD|USB_RECIP_ENDPOINT)<<8)
|
112 | f3571b1a | Max Reitz | #define ClassInterfaceRequest \
|
113 | f3571b1a | Max Reitz | ((USB_DIR_IN|USB_TYPE_CLASS|USB_RECIP_INTERFACE)<<8)
|
114 | f3571b1a | Max Reitz | #define ClassInterfaceOutRequest \
|
115 | f3571b1a | Max Reitz | ((USB_DIR_OUT|USB_TYPE_CLASS|USB_RECIP_INTERFACE)<<8)
|
116 | bb36d470 | bellard | |
117 | bb36d470 | bellard | #define USB_REQ_GET_STATUS 0x00 |
118 | bb36d470 | bellard | #define USB_REQ_CLEAR_FEATURE 0x01 |
119 | bb36d470 | bellard | #define USB_REQ_SET_FEATURE 0x03 |
120 | bb36d470 | bellard | #define USB_REQ_SET_ADDRESS 0x05 |
121 | bb36d470 | bellard | #define USB_REQ_GET_DESCRIPTOR 0x06 |
122 | bb36d470 | bellard | #define USB_REQ_SET_DESCRIPTOR 0x07 |
123 | bb36d470 | bellard | #define USB_REQ_GET_CONFIGURATION 0x08 |
124 | bb36d470 | bellard | #define USB_REQ_SET_CONFIGURATION 0x09 |
125 | bb36d470 | bellard | #define USB_REQ_GET_INTERFACE 0x0A |
126 | bb36d470 | bellard | #define USB_REQ_SET_INTERFACE 0x0B |
127 | bb36d470 | bellard | #define USB_REQ_SYNCH_FRAME 0x0C |
128 | bb36d470 | bellard | |
129 | bb36d470 | bellard | #define USB_DEVICE_SELF_POWERED 0 |
130 | bb36d470 | bellard | #define USB_DEVICE_REMOTE_WAKEUP 1 |
131 | bb36d470 | bellard | |
132 | bb36d470 | bellard | #define USB_DT_DEVICE 0x01 |
133 | bb36d470 | bellard | #define USB_DT_CONFIG 0x02 |
134 | bb36d470 | bellard | #define USB_DT_STRING 0x03 |
135 | bb36d470 | bellard | #define USB_DT_INTERFACE 0x04 |
136 | bb36d470 | bellard | #define USB_DT_ENDPOINT 0x05 |
137 | 25620cba | Gerd Hoffmann | #define USB_DT_DEVICE_QUALIFIER 0x06 |
138 | 25620cba | Gerd Hoffmann | #define USB_DT_OTHER_SPEED_CONFIG 0x07 |
139 | a7fb71d1 | Gerd Hoffmann | #define USB_DT_DEBUG 0x0A |
140 | c6d3ad0f | Brad Hards | #define USB_DT_INTERFACE_ASSOC 0x0B |
141 | 2077469b | Gerd Hoffmann | #define USB_DT_BOS 0x0F |
142 | 2077469b | Gerd Hoffmann | #define USB_DT_DEVICE_CAPABILITY 0x10 |
143 | b870472d | H. Peter Anvin | #define USB_DT_CS_INTERFACE 0x24 |
144 | b870472d | H. Peter Anvin | #define USB_DT_CS_ENDPOINT 0x25 |
145 | b43a2851 | Gerd Hoffmann | #define USB_DT_ENDPOINT_COMPANION 0x30 |
146 | bb36d470 | bellard | |
147 | 2077469b | Gerd Hoffmann | #define USB_DEV_CAP_WIRELESS 0x01 |
148 | 2077469b | Gerd Hoffmann | #define USB_DEV_CAP_USB2_EXT 0x02 |
149 | 2077469b | Gerd Hoffmann | #define USB_DEV_CAP_SUPERSPEED 0x03 |
150 | 2077469b | Gerd Hoffmann | |
151 | 942ac052 | balrog | #define USB_ENDPOINT_XFER_CONTROL 0 |
152 | 942ac052 | balrog | #define USB_ENDPOINT_XFER_ISOC 1 |
153 | 942ac052 | balrog | #define USB_ENDPOINT_XFER_BULK 2 |
154 | 942ac052 | balrog | #define USB_ENDPOINT_XFER_INT 3 |
155 | d8e17efd | Gerd Hoffmann | #define USB_ENDPOINT_XFER_INVALID 255 |
156 | 942ac052 | balrog | |
157 | 7c37e6a4 | Gerd Hoffmann | #define USB_INTERFACE_INVALID 255 |
158 | 7c37e6a4 | Gerd Hoffmann | |
159 | 806b6024 | Gerd Hoffmann | typedef struct USBBus USBBus; |
160 | 07771f6f | Gerd Hoffmann | typedef struct USBBusOps USBBusOps; |
161 | bb36d470 | bellard | typedef struct USBPort USBPort; |
162 | bb36d470 | bellard | typedef struct USBDevice USBDevice; |
163 | 4d611c9a | pbrook | typedef struct USBPacket USBPacket; |
164 | a552a966 | Hans de Goede | typedef struct USBCombinedPacket USBCombinedPacket; |
165 | d8e17efd | Gerd Hoffmann | typedef struct USBEndpoint USBEndpoint; |
166 | bb36d470 | bellard | |
167 | 37fb59d3 | Gerd Hoffmann | typedef struct USBDesc USBDesc; |
168 | 37fb59d3 | Gerd Hoffmann | typedef struct USBDescID USBDescID; |
169 | 37fb59d3 | Gerd Hoffmann | typedef struct USBDescDevice USBDescDevice; |
170 | 37fb59d3 | Gerd Hoffmann | typedef struct USBDescConfig USBDescConfig; |
171 | 6e625fc7 | Brad Hards | typedef struct USBDescIfaceAssoc USBDescIfaceAssoc; |
172 | 37fb59d3 | Gerd Hoffmann | typedef struct USBDescIface USBDescIface; |
173 | 37fb59d3 | Gerd Hoffmann | typedef struct USBDescEndpoint USBDescEndpoint; |
174 | 37fb59d3 | Gerd Hoffmann | typedef struct USBDescOther USBDescOther; |
175 | 132a3f55 | Gerd Hoffmann | typedef struct USBDescString USBDescString; |
176 | 132a3f55 | Gerd Hoffmann | |
177 | 132a3f55 | Gerd Hoffmann | struct USBDescString {
|
178 | 132a3f55 | Gerd Hoffmann | uint8_t index; |
179 | 132a3f55 | Gerd Hoffmann | char *str;
|
180 | 132a3f55 | Gerd Hoffmann | QLIST_ENTRY(USBDescString) next; |
181 | 132a3f55 | Gerd Hoffmann | }; |
182 | 37fb59d3 | Gerd Hoffmann | |
183 | 1de14d43 | Gerd Hoffmann | #define USB_MAX_ENDPOINTS 15 |
184 | 1de14d43 | Gerd Hoffmann | #define USB_MAX_INTERFACES 16 |
185 | 1de14d43 | Gerd Hoffmann | |
186 | d8e17efd | Gerd Hoffmann | struct USBEndpoint {
|
187 | 63095ab5 | Gerd Hoffmann | uint8_t nr; |
188 | 63095ab5 | Gerd Hoffmann | uint8_t pid; |
189 | d8e17efd | Gerd Hoffmann | uint8_t type; |
190 | 82f02fe9 | Gerd Hoffmann | uint8_t ifnum; |
191 | f003397c | Gerd Hoffmann | int max_packet_size;
|
192 | 7936e0f0 | Gerd Hoffmann | bool pipeline;
|
193 | 0132b4b6 | Hans de Goede | bool halted;
|
194 | 25d5de7d | Gerd Hoffmann | USBDevice *dev; |
195 | db4be873 | Gerd Hoffmann | QTAILQ_HEAD(, USBPacket) queue; |
196 | d8e17efd | Gerd Hoffmann | }; |
197 | d8e17efd | Gerd Hoffmann | |
198 | eeb0cf9a | Gerd Hoffmann | enum USBDeviceFlags {
|
199 | eeb0cf9a | Gerd Hoffmann | USB_DEV_FLAG_FULL_PATH, |
200 | be41efde | Hans de Goede | USB_DEV_FLAG_IS_HOST, |
201 | eeb0cf9a | Gerd Hoffmann | }; |
202 | eeb0cf9a | Gerd Hoffmann | |
203 | bb36d470 | bellard | /* definition of a USB device */
|
204 | bb36d470 | bellard | struct USBDevice {
|
205 | 806b6024 | Gerd Hoffmann | DeviceState qdev; |
206 | 618c169b | Gerd Hoffmann | USBPort *port; |
207 | 5f69076b | Gerd Hoffmann | char *port_path;
|
208 | bb36d470 | bellard | void *opaque;
|
209 | eeb0cf9a | Gerd Hoffmann | uint32_t flags; |
210 | 89b9b79f | aliguori | |
211 | ba3f9bfb | Hans de Goede | /* Actual connected speed */
|
212 | 806b6024 | Gerd Hoffmann | int speed;
|
213 | ba3f9bfb | Hans de Goede | /* Supported speeds, not in info because it may be variable (hostdevs) */
|
214 | ba3f9bfb | Hans de Goede | int speedmask;
|
215 | 806b6024 | Gerd Hoffmann | uint8_t addr; |
216 | 0fe6d12e | Markus Armbruster | char product_desc[32]; |
217 | 61e094c0 | Gerd Hoffmann | int auto_attach;
|
218 | a5d2f727 | Gerd Hoffmann | int attached;
|
219 | 806b6024 | Gerd Hoffmann | |
220 | c1ecb40a | Gerd Hoffmann | int32_t state; |
221 | 806b6024 | Gerd Hoffmann | uint8_t setup_buf[8];
|
222 | 19f33223 | Hans de Goede | uint8_t data_buf[4096];
|
223 | c1ecb40a | Gerd Hoffmann | int32_t remote_wakeup; |
224 | c1ecb40a | Gerd Hoffmann | int32_t setup_state; |
225 | c1ecb40a | Gerd Hoffmann | int32_t setup_len; |
226 | c1ecb40a | Gerd Hoffmann | int32_t setup_index; |
227 | 132a3f55 | Gerd Hoffmann | |
228 | 25d5de7d | Gerd Hoffmann | USBEndpoint ep_ctl; |
229 | d8e17efd | Gerd Hoffmann | USBEndpoint ep_in[USB_MAX_ENDPOINTS]; |
230 | d8e17efd | Gerd Hoffmann | USBEndpoint ep_out[USB_MAX_ENDPOINTS]; |
231 | d8e17efd | Gerd Hoffmann | |
232 | 132a3f55 | Gerd Hoffmann | QLIST_HEAD(, USBDescString) strings; |
233 | 386ab487 | Hans de Goede | const USBDesc *usb_desc; /* Overrides class usb_desc if not NULL */ |
234 | a980a065 | Gerd Hoffmann | const USBDescDevice *device;
|
235 | 65360511 | Gerd Hoffmann | |
236 | 65360511 | Gerd Hoffmann | int configuration;
|
237 | 65360511 | Gerd Hoffmann | int ninterfaces;
|
238 | 1de14d43 | Gerd Hoffmann | int altsetting[USB_MAX_INTERFACES];
|
239 | a980a065 | Gerd Hoffmann | const USBDescConfig *config;
|
240 | 1de14d43 | Gerd Hoffmann | const USBDescIface *ifaces[USB_MAX_INTERFACES];
|
241 | 806b6024 | Gerd Hoffmann | }; |
242 | 806b6024 | Gerd Hoffmann | |
243 | 62aed765 | Anthony Liguori | #define TYPE_USB_DEVICE "usb-device" |
244 | 62aed765 | Anthony Liguori | #define USB_DEVICE(obj) \
|
245 | 62aed765 | Anthony Liguori | OBJECT_CHECK(USBDevice, (obj), TYPE_USB_DEVICE) |
246 | 62aed765 | Anthony Liguori | #define USB_DEVICE_CLASS(klass) \
|
247 | 62aed765 | Anthony Liguori | OBJECT_CLASS_CHECK(USBDeviceClass, (klass), TYPE_USB_DEVICE) |
248 | 62aed765 | Anthony Liguori | #define USB_DEVICE_GET_CLASS(obj) \
|
249 | 62aed765 | Anthony Liguori | OBJECT_GET_CLASS(USBDeviceClass, (obj), TYPE_USB_DEVICE) |
250 | 62aed765 | Anthony Liguori | |
251 | 62aed765 | Anthony Liguori | typedef struct USBDeviceClass { |
252 | 62aed765 | Anthony Liguori | DeviceClass parent_class; |
253 | 62aed765 | Anthony Liguori | |
254 | 806b6024 | Gerd Hoffmann | int (*init)(USBDevice *dev);
|
255 | 806b6024 | Gerd Hoffmann | |
256 | 806b6024 | Gerd Hoffmann | /*
|
257 | 73796fe6 | Gerd Hoffmann | * Walk (enabled) downstream ports, check for a matching device.
|
258 | 73796fe6 | Gerd Hoffmann | * Only hubs implement this.
|
259 | 73796fe6 | Gerd Hoffmann | */
|
260 | 73796fe6 | Gerd Hoffmann | USBDevice *(*find_device)(USBDevice *dev, uint8_t addr); |
261 | 73796fe6 | Gerd Hoffmann | |
262 | 73796fe6 | Gerd Hoffmann | /*
|
263 | eb5e680a | Gerd Hoffmann | * Called when a packet is canceled.
|
264 | eb5e680a | Gerd Hoffmann | */
|
265 | eb5e680a | Gerd Hoffmann | void (*cancel_packet)(USBDevice *dev, USBPacket *p);
|
266 | eb5e680a | Gerd Hoffmann | |
267 | eb5e680a | Gerd Hoffmann | /*
|
268 | 89b9b79f | aliguori | * Called when device is destroyed.
|
269 | 89b9b79f | aliguori | */
|
270 | 059809e4 | bellard | void (*handle_destroy)(USBDevice *dev);
|
271 | 059809e4 | bellard | |
272 | 89b9b79f | aliguori | /*
|
273 | b6f77fbe | Gerd Hoffmann | * Attach the device
|
274 | b6f77fbe | Gerd Hoffmann | */
|
275 | b6f77fbe | Gerd Hoffmann | void (*handle_attach)(USBDevice *dev);
|
276 | b6f77fbe | Gerd Hoffmann | |
277 | b6f77fbe | Gerd Hoffmann | /*
|
278 | 89b9b79f | aliguori | * Reset the device
|
279 | 806b6024 | Gerd Hoffmann | */
|
280 | 059809e4 | bellard | void (*handle_reset)(USBDevice *dev);
|
281 | 89b9b79f | aliguori | |
282 | 89b9b79f | aliguori | /*
|
283 | 89b9b79f | aliguori | * Process control request.
|
284 | 89b9b79f | aliguori | * Called from handle_packet().
|
285 | 89b9b79f | aliguori | *
|
286 | 9a77a0f5 | Hans de Goede | * Status gets stored in p->status, and if p->status == USB_RET_SUCCESS
|
287 | 993d46ce | Stefan Weil | * then the number of bytes transferred is stored in p->actual_length
|
288 | 89b9b79f | aliguori | */
|
289 | 9a77a0f5 | Hans de Goede | void (*handle_control)(USBDevice *dev, USBPacket *p, int request, int value, |
290 | 9a77a0f5 | Hans de Goede | int index, int length, uint8_t *data); |
291 | 89b9b79f | aliguori | |
292 | 89b9b79f | aliguori | /*
|
293 | 89b9b79f | aliguori | * Process data transfers (both BULK and ISOC).
|
294 | 89b9b79f | aliguori | * Called from handle_packet().
|
295 | 89b9b79f | aliguori | *
|
296 | 9a77a0f5 | Hans de Goede | * Status gets stored in p->status, and if p->status == USB_RET_SUCCESS
|
297 | 993d46ce | Stefan Weil | * then the number of bytes transferred is stored in p->actual_length
|
298 | 89b9b79f | aliguori | */
|
299 | 9a77a0f5 | Hans de Goede | void (*handle_data)(USBDevice *dev, USBPacket *p);
|
300 | 0958b4cc | Gerd Hoffmann | |
301 | 1de14d43 | Gerd Hoffmann | void (*set_interface)(USBDevice *dev, int interface, |
302 | 1de14d43 | Gerd Hoffmann | int alt_old, int alt_new); |
303 | 1de14d43 | Gerd Hoffmann | |
304 | 36dfe324 | Hans de Goede | /*
|
305 | 36dfe324 | Hans de Goede | * Called when the hcd is done queuing packets for an endpoint, only
|
306 | 36dfe324 | Hans de Goede | * necessary for devices which can return USB_RET_ADD_TO_QUEUE.
|
307 | 36dfe324 | Hans de Goede | */
|
308 | 36dfe324 | Hans de Goede | void (*flush_ep_queue)(USBDevice *dev, USBEndpoint *ep);
|
309 | 36dfe324 | Hans de Goede | |
310 | 06384698 | Markus Armbruster | const char *product_desc; |
311 | 37fb59d3 | Gerd Hoffmann | const USBDesc *usb_desc;
|
312 | 62aed765 | Anthony Liguori | } USBDeviceClass; |
313 | bb36d470 | bellard | |
314 | 0d86d2be | Gerd Hoffmann | typedef struct USBPortOps { |
315 | 618c169b | Gerd Hoffmann | void (*attach)(USBPort *port);
|
316 | 618c169b | Gerd Hoffmann | void (*detach)(USBPort *port);
|
317 | 4706ab6c | Hans de Goede | /*
|
318 | 4706ab6c | Hans de Goede | * This gets called when a device downstream from the device attached to
|
319 | 4706ab6c | Hans de Goede | * the port (iow attached through a hub) gets detached.
|
320 | 4706ab6c | Hans de Goede | */
|
321 | 4706ab6c | Hans de Goede | void (*child_detach)(USBPort *port, USBDevice *child);
|
322 | d47e59b8 | Hans de Goede | void (*wakeup)(USBPort *port);
|
323 | d47e59b8 | Hans de Goede | /*
|
324 | d47e59b8 | Hans de Goede | * Note that port->dev will be different then the device from which
|
325 | f53c398a | Gerd Hoffmann | * the packet originated when a hub is involved.
|
326 | d47e59b8 | Hans de Goede | */
|
327 | d47e59b8 | Hans de Goede | void (*complete)(USBPort *port, USBPacket *p);
|
328 | 0d86d2be | Gerd Hoffmann | } USBPortOps; |
329 | 0d92ed30 | pbrook | |
330 | bb36d470 | bellard | /* USB port on which a device can be connected */
|
331 | bb36d470 | bellard | struct USBPort {
|
332 | a594cfbf | bellard | USBDevice *dev; |
333 | 843d4e0c | Gerd Hoffmann | int speedmask;
|
334 | c7a2196a | Gerd Hoffmann | char path[16]; |
335 | 0d86d2be | Gerd Hoffmann | USBPortOps *ops; |
336 | bb36d470 | bellard | void *opaque;
|
337 | bb36d470 | bellard | int index; /* internal port index, may be used with the opaque */ |
338 | 72cf2d4f | Blue Swirl | QTAILQ_ENTRY(USBPort) next; |
339 | bb36d470 | bellard | }; |
340 | bb36d470 | bellard | |
341 | 4d611c9a | pbrook | typedef void USBCallback(USBPacket * packet, void *opaque); |
342 | 4d611c9a | pbrook | |
343 | f53c398a | Gerd Hoffmann | typedef enum USBPacketState { |
344 | f53c398a | Gerd Hoffmann | USB_PACKET_UNDEFINED = 0,
|
345 | f53c398a | Gerd Hoffmann | USB_PACKET_SETUP, |
346 | db4be873 | Gerd Hoffmann | USB_PACKET_QUEUED, |
347 | f53c398a | Gerd Hoffmann | USB_PACKET_ASYNC, |
348 | f53c398a | Gerd Hoffmann | USB_PACKET_COMPLETE, |
349 | f53c398a | Gerd Hoffmann | USB_PACKET_CANCELED, |
350 | f53c398a | Gerd Hoffmann | } USBPacketState; |
351 | f53c398a | Gerd Hoffmann | |
352 | db4be873 | Gerd Hoffmann | /* Structure used to hold information about an active USB packet. */
|
353 | 4d611c9a | pbrook | struct USBPacket {
|
354 | 4d611c9a | pbrook | /* Data fields for use by the driver. */
|
355 | 4d611c9a | pbrook | int pid;
|
356 | e983395d | Gerd Hoffmann | uint64_t id; |
357 | f53c398a | Gerd Hoffmann | USBEndpoint *ep; |
358 | 4f4321c1 | Gerd Hoffmann | QEMUIOVector iov; |
359 | 1b4b29a1 | Gerd Hoffmann | uint64_t parameter; /* control transfers */
|
360 | 6ba43f1f | Hans de Goede | bool short_not_ok;
|
361 | a6fb2ddb | Hans de Goede | bool int_req;
|
362 | 9a77a0f5 | Hans de Goede | int status; /* USB_RET_* status code */ |
363 | 993d46ce | Stefan Weil | int actual_length; /* Number of bytes actually transferred */ |
364 | 4d611c9a | pbrook | /* Internal use by the USB layer. */
|
365 | f53c398a | Gerd Hoffmann | USBPacketState state; |
366 | a552a966 | Hans de Goede | USBCombinedPacket *combined; |
367 | db4be873 | Gerd Hoffmann | QTAILQ_ENTRY(USBPacket) queue; |
368 | a552a966 | Hans de Goede | QTAILQ_ENTRY(USBPacket) combined_entry; |
369 | a552a966 | Hans de Goede | }; |
370 | a552a966 | Hans de Goede | |
371 | a552a966 | Hans de Goede | struct USBCombinedPacket {
|
372 | a552a966 | Hans de Goede | USBPacket *first; |
373 | a552a966 | Hans de Goede | QTAILQ_HEAD(packets_head, USBPacket) packets; |
374 | a552a966 | Hans de Goede | QEMUIOVector iov; |
375 | 4d611c9a | pbrook | }; |
376 | 4d611c9a | pbrook | |
377 | 4f4321c1 | Gerd Hoffmann | void usb_packet_init(USBPacket *p);
|
378 | db4be873 | Gerd Hoffmann | void usb_packet_set_state(USBPacket *p, USBPacketState state);
|
379 | 5ac2731c | Gerd Hoffmann | void usb_packet_check_state(USBPacket *p, USBPacketState expected);
|
380 | 6ba43f1f | Hans de Goede | void usb_packet_setup(USBPacket *p, int pid, USBEndpoint *ep, uint64_t id, |
381 | a6fb2ddb | Hans de Goede | bool short_not_ok, bool int_req); |
382 | 4f4321c1 | Gerd Hoffmann | void usb_packet_addbuf(USBPacket *p, void *ptr, size_t len); |
383 | 4f4321c1 | Gerd Hoffmann | int usb_packet_map(USBPacket *p, QEMUSGList *sgl);
|
384 | e2f89926 | David Gibson | void usb_packet_unmap(USBPacket *p, QEMUSGList *sgl);
|
385 | 4f4321c1 | Gerd Hoffmann | void usb_packet_copy(USBPacket *p, void *ptr, size_t bytes); |
386 | 4f4321c1 | Gerd Hoffmann | void usb_packet_skip(USBPacket *p, size_t bytes);
|
387 | 4f4321c1 | Gerd Hoffmann | void usb_packet_cleanup(USBPacket *p);
|
388 | 4f4321c1 | Gerd Hoffmann | |
389 | f53c398a | Gerd Hoffmann | static inline bool usb_packet_is_inflight(USBPacket *p) |
390 | f53c398a | Gerd Hoffmann | { |
391 | db4be873 | Gerd Hoffmann | return (p->state == USB_PACKET_QUEUED ||
|
392 | db4be873 | Gerd Hoffmann | p->state == USB_PACKET_ASYNC); |
393 | f53c398a | Gerd Hoffmann | } |
394 | f53c398a | Gerd Hoffmann | |
395 | 73796fe6 | Gerd Hoffmann | USBDevice *usb_find_device(USBPort *port, uint8_t addr); |
396 | 73796fe6 | Gerd Hoffmann | |
397 | 9a77a0f5 | Hans de Goede | void usb_handle_packet(USBDevice *dev, USBPacket *p);
|
398 | 4ff658fb | Gerd Hoffmann | void usb_packet_complete(USBDevice *dev, USBPacket *p);
|
399 | d0ff81b8 | Hans de Goede | void usb_packet_complete_one(USBDevice *dev, USBPacket *p);
|
400 | 4ff658fb | Gerd Hoffmann | void usb_cancel_packet(USBPacket * p);
|
401 | 53aa8c0e | Gerd Hoffmann | |
402 | d8e17efd | Gerd Hoffmann | void usb_ep_init(USBDevice *dev);
|
403 | 19deaa08 | Gerd Hoffmann | void usb_ep_reset(USBDevice *dev);
|
404 | 5b6780d0 | Gerd Hoffmann | void usb_ep_dump(USBDevice *dev);
|
405 | d8e17efd | Gerd Hoffmann | struct USBEndpoint *usb_ep_get(USBDevice *dev, int pid, int ep); |
406 | d8e17efd | Gerd Hoffmann | uint8_t usb_ep_get_type(USBDevice *dev, int pid, int ep); |
407 | 82f02fe9 | Gerd Hoffmann | uint8_t usb_ep_get_ifnum(USBDevice *dev, int pid, int ep); |
408 | d8e17efd | Gerd Hoffmann | void usb_ep_set_type(USBDevice *dev, int pid, int ep, uint8_t type); |
409 | 82f02fe9 | Gerd Hoffmann | void usb_ep_set_ifnum(USBDevice *dev, int pid, int ep, uint8_t ifnum); |
410 | f003397c | Gerd Hoffmann | void usb_ep_set_max_packet_size(USBDevice *dev, int pid, int ep, |
411 | f003397c | Gerd Hoffmann | uint16_t raw); |
412 | f003397c | Gerd Hoffmann | int usb_ep_get_max_packet_size(USBDevice *dev, int pid, int ep); |
413 | 7936e0f0 | Gerd Hoffmann | void usb_ep_set_pipeline(USBDevice *dev, int pid, int ep, bool enabled); |
414 | c13a9e61 | Hans de Goede | USBPacket *usb_ep_find_packet_by_id(USBDevice *dev, int pid, int ep, |
415 | c13a9e61 | Hans de Goede | uint64_t id); |
416 | d8e17efd | Gerd Hoffmann | |
417 | a552a966 | Hans de Goede | void usb_ep_combine_input_packets(USBEndpoint *ep);
|
418 | a552a966 | Hans de Goede | void usb_combined_input_packet_complete(USBDevice *dev, USBPacket *p);
|
419 | a552a966 | Hans de Goede | void usb_combined_packet_cancel(USBDevice *dev, USBPacket *p);
|
420 | a552a966 | Hans de Goede | |
421 | 891fb2cd | Gerd Hoffmann | void usb_attach(USBPort *port);
|
422 | 891fb2cd | Gerd Hoffmann | void usb_detach(USBPort *port);
|
423 | d28f4e2d | Gerd Hoffmann | void usb_port_reset(USBPort *port);
|
424 | d28f4e2d | Gerd Hoffmann | void usb_device_reset(USBDevice *dev);
|
425 | 7567b51f | Gerd Hoffmann | void usb_wakeup(USBEndpoint *ep);
|
426 | 50b7963e | Hans de Goede | void usb_generic_async_ctrl_complete(USBDevice *s, USBPacket *p);
|
427 | bb36d470 | bellard | int set_usb_string(uint8_t *buf, const char *str); |
428 | 4d611c9a | pbrook | |
429 | bb36d470 | bellard | /* usb-linux.c */
|
430 | 3741715c | Jan Kiszka | USBDevice *usb_host_device_open(USBBus *bus, const char *devname); |
431 | 5d0c5750 | aliguori | int usb_host_device_close(const char *devname); |
432 | 376253ec | aliguori | void usb_host_info(Monitor *mon);
|
433 | 59ae540c | bellard | |
434 | e6a6d5ab | balrog | /* usb-bt.c */
|
435 | 3741715c | Jan Kiszka | USBDevice *usb_bt_init(USBBus *bus, HCIInfo *hci); |
436 | e6a6d5ab | balrog | |
437 | 87ecb68b | pbrook | /* usb ports of the VM */
|
438 | 87ecb68b | pbrook | |
439 | 87ecb68b | pbrook | #define VM_USB_HUB_SIZE 8 |
440 | 87ecb68b | pbrook | |
441 | 942ac052 | balrog | /* usb-musb.c */
|
442 | 942ac052 | balrog | enum musb_irq_source_e {
|
443 | 942ac052 | balrog | musb_irq_suspend = 0,
|
444 | 942ac052 | balrog | musb_irq_resume, |
445 | 942ac052 | balrog | musb_irq_rst_babble, |
446 | 942ac052 | balrog | musb_irq_sof, |
447 | 942ac052 | balrog | musb_irq_connect, |
448 | 942ac052 | balrog | musb_irq_disconnect, |
449 | 942ac052 | balrog | musb_irq_vbus_request, |
450 | 942ac052 | balrog | musb_irq_vbus_error, |
451 | 942ac052 | balrog | musb_irq_rx, |
452 | 942ac052 | balrog | musb_irq_tx, |
453 | 942ac052 | balrog | musb_set_vbus, |
454 | 942ac052 | balrog | musb_set_session, |
455 | 9147b752 | Peter Maydell | /* Add new interrupts here */
|
456 | 9147b752 | Peter Maydell | musb_irq_max, /* total number of interrupts defined */
|
457 | 942ac052 | balrog | }; |
458 | 942ac052 | balrog | |
459 | bc24a225 | Paul Brook | typedef struct MUSBState MUSBState; |
460 | 406c2075 | Peter Maydell | MUSBState *musb_init(DeviceState *parent_device, int gpio_base);
|
461 | 5b1cdb4e | Juha Riihimäki | void musb_reset(MUSBState *s);
|
462 | bc24a225 | Paul Brook | uint32_t musb_core_intr_get(MUSBState *s); |
463 | bc24a225 | Paul Brook | void musb_core_intr_clear(MUSBState *s, uint32_t mask);
|
464 | bc24a225 | Paul Brook | void musb_set_size(MUSBState *s, int epnum, int size, int is_tx); |
465 | 806b6024 | Gerd Hoffmann | |
466 | 806b6024 | Gerd Hoffmann | /* usb-bus.c */
|
467 | 806b6024 | Gerd Hoffmann | |
468 | 0d936928 | Anthony Liguori | #define TYPE_USB_BUS "usb-bus" |
469 | 0d936928 | Anthony Liguori | #define USB_BUS(obj) OBJECT_CHECK(USBBus, (obj), TYPE_USB_BUS)
|
470 | 0d936928 | Anthony Liguori | |
471 | 806b6024 | Gerd Hoffmann | struct USBBus {
|
472 | 806b6024 | Gerd Hoffmann | BusState qbus; |
473 | 07771f6f | Gerd Hoffmann | USBBusOps *ops; |
474 | 806b6024 | Gerd Hoffmann | int busnr;
|
475 | 806b6024 | Gerd Hoffmann | int nfree;
|
476 | 806b6024 | Gerd Hoffmann | int nused;
|
477 | 72cf2d4f | Blue Swirl | QTAILQ_HEAD(, USBPort) free; |
478 | 72cf2d4f | Blue Swirl | QTAILQ_HEAD(, USBPort) used; |
479 | 72cf2d4f | Blue Swirl | QTAILQ_ENTRY(USBBus) next; |
480 | 806b6024 | Gerd Hoffmann | }; |
481 | 806b6024 | Gerd Hoffmann | |
482 | 07771f6f | Gerd Hoffmann | struct USBBusOps {
|
483 | ae60fea9 | Hans de Goede | int (*register_companion)(USBBus *bus, USBPort *ports[],
|
484 | ae60fea9 | Hans de Goede | uint32_t portcount, uint32_t firstport); |
485 | 37f32f0f | Gerd Hoffmann | void (*wakeup_endpoint)(USBBus *bus, USBEndpoint *ep);
|
486 | 07771f6f | Gerd Hoffmann | }; |
487 | 07771f6f | Gerd Hoffmann | |
488 | 07771f6f | Gerd Hoffmann | void usb_bus_new(USBBus *bus, USBBusOps *ops, DeviceState *host);
|
489 | 806b6024 | Gerd Hoffmann | USBBus *usb_bus_find(int busnr);
|
490 | ba02430f | Anthony Liguori | void usb_legacy_register(const char *typename, const char *usbdevice_name, |
491 | 3741715c | Jan Kiszka | USBDevice *(*usbdevice_init)(USBBus *bus, |
492 | 3741715c | Jan Kiszka | const char *params)); |
493 | a5d2f727 | Gerd Hoffmann | USBDevice *usb_create(USBBus *bus, const char *name); |
494 | 806b6024 | Gerd Hoffmann | USBDevice *usb_create_simple(USBBus *bus, const char *name); |
495 | 0958b4cc | Gerd Hoffmann | USBDevice *usbdevice_create(const char *cmdline); |
496 | a5d2f727 | Gerd Hoffmann | void usb_register_port(USBBus *bus, USBPort *port, void *opaque, int index, |
497 | ace1318b | Gerd Hoffmann | USBPortOps *ops, int speedmask);
|
498 | ae60fea9 | Hans de Goede | int usb_register_companion(const char *masterbus, USBPort *ports[], |
499 | ae60fea9 | Hans de Goede | uint32_t portcount, uint32_t firstport, |
500 | ae60fea9 | Hans de Goede | void *opaque, USBPortOps *ops, int speedmask); |
501 | c7a2196a | Gerd Hoffmann | void usb_port_location(USBPort *downstream, USBPort *upstream, int portnr); |
502 | a8e662b5 | Gerd Hoffmann | void usb_unregister_port(USBBus *bus, USBPort *port);
|
503 | 891fb2cd | Gerd Hoffmann | int usb_claim_port(USBDevice *dev);
|
504 | 891fb2cd | Gerd Hoffmann | void usb_release_port(USBDevice *dev);
|
505 | a5d2f727 | Gerd Hoffmann | int usb_device_attach(USBDevice *dev);
|
506 | a8e662b5 | Gerd Hoffmann | int usb_device_detach(USBDevice *dev);
|
507 | a5d2f727 | Gerd Hoffmann | int usb_device_delete_addr(int busnr, int addr); |
508 | a5d2f727 | Gerd Hoffmann | |
509 | a5d2f727 | Gerd Hoffmann | static inline USBBus *usb_bus_from_device(USBDevice *d) |
510 | a5d2f727 | Gerd Hoffmann | { |
511 | a5d2f727 | Gerd Hoffmann | return DO_UPCAST(USBBus, qbus, d->qdev.parent_bus);
|
512 | a5d2f727 | Gerd Hoffmann | } |
513 | 701a8f76 | Paolo Bonzini | |
514 | 701a8f76 | Paolo Bonzini | extern const VMStateDescription vmstate_usb_device; |
515 | 701a8f76 | Paolo Bonzini | |
516 | 701a8f76 | Paolo Bonzini | #define VMSTATE_USB_DEVICE(_field, _state) { \
|
517 | 701a8f76 | Paolo Bonzini | .name = (stringify(_field)), \ |
518 | 701a8f76 | Paolo Bonzini | .size = sizeof(USBDevice), \
|
519 | 701a8f76 | Paolo Bonzini | .vmsd = &vmstate_usb_device, \ |
520 | 701a8f76 | Paolo Bonzini | .flags = VMS_STRUCT, \ |
521 | 701a8f76 | Paolo Bonzini | .offset = vmstate_offset_value(_state, _field, USBDevice), \ |
522 | 701a8f76 | Paolo Bonzini | } |
523 | 701a8f76 | Paolo Bonzini | |
524 | 73796fe6 | Gerd Hoffmann | USBDevice *usb_device_find_device(USBDevice *dev, uint8_t addr); |
525 | 73796fe6 | Gerd Hoffmann | |
526 | 62aed765 | Anthony Liguori | void usb_device_cancel_packet(USBDevice *dev, USBPacket *p);
|
527 | 62aed765 | Anthony Liguori | |
528 | 62aed765 | Anthony Liguori | void usb_device_handle_attach(USBDevice *dev);
|
529 | 62aed765 | Anthony Liguori | |
530 | 62aed765 | Anthony Liguori | void usb_device_handle_reset(USBDevice *dev);
|
531 | 62aed765 | Anthony Liguori | |
532 | 9a77a0f5 | Hans de Goede | void usb_device_handle_control(USBDevice *dev, USBPacket *p, int request, |
533 | 9a77a0f5 | Hans de Goede | int val, int index, int length, uint8_t *data); |
534 | 62aed765 | Anthony Liguori | |
535 | 9a77a0f5 | Hans de Goede | void usb_device_handle_data(USBDevice *dev, USBPacket *p);
|
536 | 62aed765 | Anthony Liguori | |
537 | 62aed765 | Anthony Liguori | void usb_device_set_interface(USBDevice *dev, int interface, |
538 | 62aed765 | Anthony Liguori | int alt_old, int alt_new); |
539 | 62aed765 | Anthony Liguori | |
540 | 36dfe324 | Hans de Goede | void usb_device_flush_ep_queue(USBDevice *dev, USBEndpoint *ep);
|
541 | 36dfe324 | Hans de Goede | |
542 | 62aed765 | Anthony Liguori | const char *usb_device_get_product_desc(USBDevice *dev); |
543 | 62aed765 | Anthony Liguori | |
544 | 62aed765 | Anthony Liguori | const USBDesc *usb_device_get_usb_desc(USBDevice *dev);
|
545 | 62aed765 | Anthony Liguori | |
546 | bb4d2b2f | Gerd Hoffmann | int ehci_create_ich9_with_companions(PCIBus *bus, int slot); |
547 | bb4d2b2f | Gerd Hoffmann | |
548 | 62aed765 | Anthony Liguori | #endif
|