]>
Commit | Line | Data |
---|---|---|
bb36d470 FB |
1 | /* |
2 | * USB UHCI controller emulation | |
5fafdf24 | 3 | * |
bb36d470 | 4 | * Copyright (c) 2005 Fabrice Bellard |
5fafdf24 | 5 | * |
54f254f9 AL |
6 | * Copyright (c) 2008 Max Krasnyansky |
7 | * Magor rewrite of the UHCI data structures parser and frame processor | |
8 | * Support for fully async operation and multiple outstanding transactions | |
9 | * | |
bb36d470 FB |
10 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
11 | * of this software and associated documentation files (the "Software"), to deal | |
12 | * in the Software without restriction, including without limitation the rights | |
13 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
14 | * copies of the Software, and to permit persons to whom the Software is | |
15 | * furnished to do so, subject to the following conditions: | |
16 | * | |
17 | * The above copyright notice and this permission notice shall be included in | |
18 | * all copies or substantial portions of the Software. | |
19 | * | |
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
23 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
25 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
26 | * THE SOFTWARE. | |
27 | */ | |
f1ae32a1 GH |
28 | #include "hw/hw.h" |
29 | #include "hw/usb.h" | |
30 | #include "hw/pci.h" | |
87ecb68b | 31 | #include "qemu-timer.h" |
4f4321c1 | 32 | #include "iov.h" |
df5e66ee | 33 | #include "dma.h" |
50dcc0f8 | 34 | #include "trace.h" |
bb36d470 FB |
35 | |
36 | //#define DEBUG | |
54f254f9 | 37 | //#define DEBUG_DUMP_DATA |
bb36d470 | 38 | |
96217e31 TS |
39 | #define UHCI_CMD_FGR (1 << 4) |
40 | #define UHCI_CMD_EGSM (1 << 3) | |
bb36d470 FB |
41 | #define UHCI_CMD_GRESET (1 << 2) |
42 | #define UHCI_CMD_HCRESET (1 << 1) | |
43 | #define UHCI_CMD_RS (1 << 0) | |
44 | ||
45 | #define UHCI_STS_HCHALTED (1 << 5) | |
46 | #define UHCI_STS_HCPERR (1 << 4) | |
47 | #define UHCI_STS_HSERR (1 << 3) | |
48 | #define UHCI_STS_RD (1 << 2) | |
49 | #define UHCI_STS_USBERR (1 << 1) | |
50 | #define UHCI_STS_USBINT (1 << 0) | |
51 | ||
52 | #define TD_CTRL_SPD (1 << 29) | |
53 | #define TD_CTRL_ERROR_SHIFT 27 | |
54 | #define TD_CTRL_IOS (1 << 25) | |
55 | #define TD_CTRL_IOC (1 << 24) | |
56 | #define TD_CTRL_ACTIVE (1 << 23) | |
57 | #define TD_CTRL_STALL (1 << 22) | |
58 | #define TD_CTRL_BABBLE (1 << 20) | |
59 | #define TD_CTRL_NAK (1 << 19) | |
60 | #define TD_CTRL_TIMEOUT (1 << 18) | |
61 | ||
9159f679 | 62 | #define UHCI_PORT_SUSPEND (1 << 12) |
bb36d470 FB |
63 | #define UHCI_PORT_RESET (1 << 9) |
64 | #define UHCI_PORT_LSDA (1 << 8) | |
9159f679 | 65 | #define UHCI_PORT_RD (1 << 6) |
bb36d470 FB |
66 | #define UHCI_PORT_ENC (1 << 3) |
67 | #define UHCI_PORT_EN (1 << 2) | |
68 | #define UHCI_PORT_CSC (1 << 1) | |
69 | #define UHCI_PORT_CCS (1 << 0) | |
70 | ||
9159f679 GH |
71 | #define UHCI_PORT_READ_ONLY (0x1bb) |
72 | #define UHCI_PORT_WRITE_CLEAR (UHCI_PORT_CSC | UHCI_PORT_ENC) | |
73 | ||
bb36d470 FB |
74 | #define FRAME_TIMER_FREQ 1000 |
75 | ||
3200d108 | 76 | #define FRAME_MAX_LOOPS 256 |
bb36d470 FB |
77 | |
78 | #define NB_PORTS 2 | |
79 | ||
60e1b2a6 | 80 | enum { |
0cd178ca GH |
81 | TD_RESULT_STOP_FRAME = 10, |
82 | TD_RESULT_COMPLETE, | |
83 | TD_RESULT_NEXT_QH, | |
4efe4ef3 GH |
84 | TD_RESULT_ASYNC_START, |
85 | TD_RESULT_ASYNC_CONT, | |
60e1b2a6 GH |
86 | }; |
87 | ||
7b5a44c5 | 88 | typedef struct UHCIState UHCIState; |
f8af1e88 GH |
89 | typedef struct UHCIAsync UHCIAsync; |
90 | typedef struct UHCIQueue UHCIQueue; | |
7b5a44c5 | 91 | |
54f254f9 AL |
92 | /* |
93 | * Pending async transaction. | |
94 | * 'packet' must be the first field because completion | |
95 | * handler does "(UHCIAsync *) pkt" cast. | |
96 | */ | |
f8af1e88 GH |
97 | |
98 | struct UHCIAsync { | |
54f254f9 | 99 | USBPacket packet; |
df5e66ee | 100 | QEMUSGList sgl; |
f8af1e88 | 101 | UHCIQueue *queue; |
ddf6583f | 102 | QTAILQ_ENTRY(UHCIAsync) next; |
54f254f9 | 103 | uint32_t td; |
8e65b7c0 | 104 | uint8_t isoc; |
54f254f9 | 105 | uint8_t done; |
f8af1e88 GH |
106 | }; |
107 | ||
108 | struct UHCIQueue { | |
109 | uint32_t token; | |
110 | UHCIState *uhci; | |
111 | QTAILQ_ENTRY(UHCIQueue) next; | |
112 | QTAILQ_HEAD(, UHCIAsync) asyncs; | |
113 | int8_t valid; | |
114 | }; | |
54f254f9 | 115 | |
bb36d470 FB |
116 | typedef struct UHCIPort { |
117 | USBPort port; | |
118 | uint16_t ctrl; | |
bb36d470 FB |
119 | } UHCIPort; |
120 | ||
7b5a44c5 | 121 | struct UHCIState { |
bb36d470 | 122 | PCIDevice dev; |
a03f66e4 | 123 | MemoryRegion io_bar; |
35e4977f | 124 | USBBus bus; /* Note unused when we're a companion controller */ |
bb36d470 FB |
125 | uint16_t cmd; /* cmd register */ |
126 | uint16_t status; | |
127 | uint16_t intr; /* interrupt enable register */ | |
128 | uint16_t frnum; /* frame number */ | |
129 | uint32_t fl_base_addr; /* frame list base address */ | |
130 | uint8_t sof_timing; | |
131 | uint8_t status2; /* bit 0 and 1 are used to generate UHCI_STS_USBINT */ | |
8e65b7c0 | 132 | int64_t expire_time; |
bb36d470 | 133 | QEMUTimer *frame_timer; |
9a16c595 | 134 | QEMUBH *bh; |
4aed20e2 | 135 | uint32_t frame_bytes; |
40141d12 | 136 | uint32_t frame_bandwidth; |
bb36d470 | 137 | UHCIPort ports[NB_PORTS]; |
4d611c9a PB |
138 | |
139 | /* Interrupts that should be raised at the end of the current frame. */ | |
140 | uint32_t pending_int_mask; | |
973002c1 | 141 | int irq_pin; |
54f254f9 AL |
142 | |
143 | /* Active packets */ | |
f8af1e88 | 144 | QTAILQ_HEAD(, UHCIQueue) queues; |
64e58fe5 | 145 | uint8_t num_ports_vmstate; |
35e4977f HG |
146 | |
147 | /* Properties */ | |
148 | char *masterbus; | |
149 | uint32_t firstport; | |
7b5a44c5 | 150 | }; |
bb36d470 FB |
151 | |
152 | typedef struct UHCI_TD { | |
153 | uint32_t link; | |
154 | uint32_t ctrl; /* see TD_CTRL_xxx */ | |
155 | uint32_t token; | |
156 | uint32_t buffer; | |
157 | } UHCI_TD; | |
158 | ||
159 | typedef struct UHCI_QH { | |
160 | uint32_t link; | |
161 | uint32_t el_link; | |
162 | } UHCI_QH; | |
163 | ||
f8af1e88 GH |
164 | static inline int32_t uhci_queue_token(UHCI_TD *td) |
165 | { | |
166 | /* covers ep, dev, pid -> identifies the endpoint */ | |
167 | return td->token & 0x7ffff; | |
168 | } | |
169 | ||
170 | static UHCIQueue *uhci_queue_get(UHCIState *s, UHCI_TD *td) | |
171 | { | |
172 | uint32_t token = uhci_queue_token(td); | |
173 | UHCIQueue *queue; | |
174 | ||
175 | QTAILQ_FOREACH(queue, &s->queues, next) { | |
176 | if (queue->token == token) { | |
177 | return queue; | |
178 | } | |
179 | } | |
180 | ||
181 | queue = g_new0(UHCIQueue, 1); | |
182 | queue->uhci = s; | |
183 | queue->token = token; | |
184 | QTAILQ_INIT(&queue->asyncs); | |
185 | QTAILQ_INSERT_HEAD(&s->queues, queue, next); | |
50dcc0f8 | 186 | trace_usb_uhci_queue_add(queue->token); |
f8af1e88 GH |
187 | return queue; |
188 | } | |
189 | ||
190 | static void uhci_queue_free(UHCIQueue *queue) | |
191 | { | |
192 | UHCIState *s = queue->uhci; | |
193 | ||
50dcc0f8 | 194 | trace_usb_uhci_queue_del(queue->token); |
f8af1e88 GH |
195 | QTAILQ_REMOVE(&s->queues, queue, next); |
196 | g_free(queue); | |
197 | } | |
198 | ||
16ce543e | 199 | static UHCIAsync *uhci_async_alloc(UHCIQueue *queue, uint32_t addr) |
54f254f9 | 200 | { |
326700e3 | 201 | UHCIAsync *async = g_new0(UHCIAsync, 1); |
487414f1 | 202 | |
f8af1e88 | 203 | async->queue = queue; |
16ce543e | 204 | async->td = addr; |
4f4321c1 | 205 | usb_packet_init(&async->packet); |
f8af1e88 | 206 | pci_dma_sglist_init(&async->sgl, &queue->uhci->dev, 1); |
50dcc0f8 | 207 | trace_usb_uhci_packet_add(async->queue->token, async->td); |
54f254f9 AL |
208 | |
209 | return async; | |
210 | } | |
211 | ||
f8af1e88 | 212 | static void uhci_async_free(UHCIAsync *async) |
54f254f9 | 213 | { |
50dcc0f8 | 214 | trace_usb_uhci_packet_del(async->queue->token, async->td); |
4f4321c1 | 215 | usb_packet_cleanup(&async->packet); |
df5e66ee | 216 | qemu_sglist_destroy(&async->sgl); |
7267c094 | 217 | g_free(async); |
54f254f9 AL |
218 | } |
219 | ||
f8af1e88 | 220 | static void uhci_async_link(UHCIAsync *async) |
54f254f9 | 221 | { |
f8af1e88 GH |
222 | UHCIQueue *queue = async->queue; |
223 | QTAILQ_INSERT_TAIL(&queue->asyncs, async, next); | |
50dcc0f8 | 224 | trace_usb_uhci_packet_link_async(async->queue->token, async->td); |
54f254f9 AL |
225 | } |
226 | ||
f8af1e88 | 227 | static void uhci_async_unlink(UHCIAsync *async) |
54f254f9 | 228 | { |
f8af1e88 GH |
229 | UHCIQueue *queue = async->queue; |
230 | QTAILQ_REMOVE(&queue->asyncs, async, next); | |
50dcc0f8 | 231 | trace_usb_uhci_packet_unlink_async(async->queue->token, async->td); |
54f254f9 AL |
232 | } |
233 | ||
f8af1e88 | 234 | static void uhci_async_cancel(UHCIAsync *async) |
54f254f9 | 235 | { |
50dcc0f8 | 236 | trace_usb_uhci_packet_cancel(async->queue->token, async->td, async->done); |
54f254f9 AL |
237 | if (!async->done) |
238 | usb_cancel_packet(&async->packet); | |
00a0770d | 239 | usb_packet_unmap(&async->packet, &async->sgl); |
f8af1e88 | 240 | uhci_async_free(async); |
54f254f9 AL |
241 | } |
242 | ||
243 | /* | |
244 | * Mark all outstanding async packets as invalid. | |
245 | * This is used for canceling them when TDs are removed by the HCD. | |
246 | */ | |
f8af1e88 | 247 | static void uhci_async_validate_begin(UHCIState *s) |
54f254f9 | 248 | { |
f8af1e88 | 249 | UHCIQueue *queue; |
54f254f9 | 250 | |
f8af1e88 GH |
251 | QTAILQ_FOREACH(queue, &s->queues, next) { |
252 | queue->valid--; | |
54f254f9 | 253 | } |
54f254f9 AL |
254 | } |
255 | ||
256 | /* | |
257 | * Cancel async packets that are no longer valid | |
258 | */ | |
259 | static void uhci_async_validate_end(UHCIState *s) | |
260 | { | |
f8af1e88 GH |
261 | UHCIQueue *queue, *n; |
262 | UHCIAsync *async; | |
54f254f9 | 263 | |
f8af1e88 GH |
264 | QTAILQ_FOREACH_SAFE(queue, &s->queues, next, n) { |
265 | if (queue->valid > 0) { | |
54f254f9 AL |
266 | continue; |
267 | } | |
f8af1e88 GH |
268 | while (!QTAILQ_EMPTY(&queue->asyncs)) { |
269 | async = QTAILQ_FIRST(&queue->asyncs); | |
270 | uhci_async_unlink(async); | |
271 | uhci_async_cancel(async); | |
272 | } | |
273 | uhci_queue_free(queue); | |
54f254f9 AL |
274 | } |
275 | } | |
276 | ||
07771f6f GH |
277 | static void uhci_async_cancel_device(UHCIState *s, USBDevice *dev) |
278 | { | |
f8af1e88 | 279 | UHCIQueue *queue; |
07771f6f GH |
280 | UHCIAsync *curr, *n; |
281 | ||
f8af1e88 GH |
282 | QTAILQ_FOREACH(queue, &s->queues, next) { |
283 | QTAILQ_FOREACH_SAFE(curr, &queue->asyncs, next, n) { | |
284 | if (!usb_packet_is_inflight(&curr->packet) || | |
285 | curr->packet.ep->dev != dev) { | |
286 | continue; | |
287 | } | |
288 | uhci_async_unlink(curr); | |
289 | uhci_async_cancel(curr); | |
07771f6f | 290 | } |
07771f6f GH |
291 | } |
292 | } | |
293 | ||
54f254f9 AL |
294 | static void uhci_async_cancel_all(UHCIState *s) |
295 | { | |
77fa9aee | 296 | UHCIQueue *queue, *nq; |
ddf6583f | 297 | UHCIAsync *curr, *n; |
54f254f9 | 298 | |
77fa9aee | 299 | QTAILQ_FOREACH_SAFE(queue, &s->queues, next, nq) { |
f8af1e88 GH |
300 | QTAILQ_FOREACH_SAFE(curr, &queue->asyncs, next, n) { |
301 | uhci_async_unlink(curr); | |
302 | uhci_async_cancel(curr); | |
303 | } | |
60f8afcb | 304 | uhci_queue_free(queue); |
54f254f9 | 305 | } |
54f254f9 AL |
306 | } |
307 | ||
f8af1e88 | 308 | static UHCIAsync *uhci_async_find_td(UHCIState *s, uint32_t addr, UHCI_TD *td) |
54f254f9 | 309 | { |
f8af1e88 GH |
310 | uint32_t token = uhci_queue_token(td); |
311 | UHCIQueue *queue; | |
ddf6583f | 312 | UHCIAsync *async; |
e8ee3c72 | 313 | |
f8af1e88 GH |
314 | QTAILQ_FOREACH(queue, &s->queues, next) { |
315 | if (queue->token == token) { | |
316 | break; | |
54f254f9 | 317 | } |
f8af1e88 GH |
318 | } |
319 | if (queue == NULL) { | |
320 | return NULL; | |
54f254f9 | 321 | } |
e8ee3c72 | 322 | |
f8af1e88 GH |
323 | QTAILQ_FOREACH(async, &queue->asyncs, next) { |
324 | if (async->td == addr) { | |
325 | return async; | |
326 | } | |
327 | } | |
e8ee3c72 | 328 | |
f8af1e88 | 329 | return NULL; |
54f254f9 AL |
330 | } |
331 | ||
bb36d470 FB |
332 | static void uhci_update_irq(UHCIState *s) |
333 | { | |
334 | int level; | |
335 | if (((s->status2 & 1) && (s->intr & (1 << 2))) || | |
336 | ((s->status2 & 2) && (s->intr & (1 << 3))) || | |
337 | ((s->status & UHCI_STS_USBERR) && (s->intr & (1 << 0))) || | |
338 | ((s->status & UHCI_STS_RD) && (s->intr & (1 << 1))) || | |
339 | (s->status & UHCI_STS_HSERR) || | |
340 | (s->status & UHCI_STS_HCPERR)) { | |
341 | level = 1; | |
342 | } else { | |
343 | level = 0; | |
344 | } | |
973002c1 | 345 | qemu_set_irq(s->dev.irq[s->irq_pin], level); |
bb36d470 FB |
346 | } |
347 | ||
c8075ac3 | 348 | static void uhci_reset(void *opaque) |
bb36d470 | 349 | { |
c8075ac3 | 350 | UHCIState *s = opaque; |
bb36d470 FB |
351 | uint8_t *pci_conf; |
352 | int i; | |
353 | UHCIPort *port; | |
354 | ||
50dcc0f8 | 355 | trace_usb_uhci_reset(); |
6f382b5e | 356 | |
bb36d470 FB |
357 | pci_conf = s->dev.config; |
358 | ||
359 | pci_conf[0x6a] = 0x01; /* usb clock */ | |
360 | pci_conf[0x6b] = 0x00; | |
361 | s->cmd = 0; | |
362 | s->status = 0; | |
363 | s->status2 = 0; | |
364 | s->intr = 0; | |
365 | s->fl_base_addr = 0; | |
366 | s->sof_timing = 64; | |
54f254f9 | 367 | |
bb36d470 FB |
368 | for(i = 0; i < NB_PORTS; i++) { |
369 | port = &s->ports[i]; | |
370 | port->ctrl = 0x0080; | |
891fb2cd | 371 | if (port->port.dev && port->port.dev->attached) { |
d28f4e2d | 372 | usb_port_reset(&port->port); |
618c169b | 373 | } |
bb36d470 | 374 | } |
54f254f9 AL |
375 | |
376 | uhci_async_cancel_all(s); | |
9a16c595 | 377 | qemu_bh_cancel(s->bh); |
aba1f242 | 378 | uhci_update_irq(s); |
bb36d470 FB |
379 | } |
380 | ||
817afc61 JQ |
381 | static const VMStateDescription vmstate_uhci_port = { |
382 | .name = "uhci port", | |
383 | .version_id = 1, | |
384 | .minimum_version_id = 1, | |
385 | .minimum_version_id_old = 1, | |
386 | .fields = (VMStateField []) { | |
387 | VMSTATE_UINT16(ctrl, UHCIPort), | |
388 | VMSTATE_END_OF_LIST() | |
389 | } | |
390 | }; | |
391 | ||
75f151cd GH |
392 | static int uhci_post_load(void *opaque, int version_id) |
393 | { | |
394 | UHCIState *s = opaque; | |
395 | ||
396 | if (version_id < 2) { | |
397 | s->expire_time = qemu_get_clock_ns(vm_clock) + | |
398 | (get_ticks_per_sec() / FRAME_TIMER_FREQ); | |
399 | } | |
400 | return 0; | |
401 | } | |
402 | ||
817afc61 JQ |
403 | static const VMStateDescription vmstate_uhci = { |
404 | .name = "uhci", | |
6881dd5f | 405 | .version_id = 2, |
817afc61 JQ |
406 | .minimum_version_id = 1, |
407 | .minimum_version_id_old = 1, | |
75f151cd | 408 | .post_load = uhci_post_load, |
817afc61 JQ |
409 | .fields = (VMStateField []) { |
410 | VMSTATE_PCI_DEVICE(dev, UHCIState), | |
411 | VMSTATE_UINT8_EQUAL(num_ports_vmstate, UHCIState), | |
412 | VMSTATE_STRUCT_ARRAY(ports, UHCIState, NB_PORTS, 1, | |
413 | vmstate_uhci_port, UHCIPort), | |
414 | VMSTATE_UINT16(cmd, UHCIState), | |
415 | VMSTATE_UINT16(status, UHCIState), | |
416 | VMSTATE_UINT16(intr, UHCIState), | |
417 | VMSTATE_UINT16(frnum, UHCIState), | |
418 | VMSTATE_UINT32(fl_base_addr, UHCIState), | |
419 | VMSTATE_UINT8(sof_timing, UHCIState), | |
420 | VMSTATE_UINT8(status2, UHCIState), | |
421 | VMSTATE_TIMER(frame_timer, UHCIState), | |
6881dd5f | 422 | VMSTATE_INT64_V(expire_time, UHCIState, 2), |
817afc61 JQ |
423 | VMSTATE_END_OF_LIST() |
424 | } | |
425 | }; | |
b9dc033c | 426 | |
bb36d470 FB |
427 | static void uhci_ioport_writeb(void *opaque, uint32_t addr, uint32_t val) |
428 | { | |
429 | UHCIState *s = opaque; | |
3b46e624 | 430 | |
bb36d470 FB |
431 | addr &= 0x1f; |
432 | switch(addr) { | |
433 | case 0x0c: | |
434 | s->sof_timing = val; | |
435 | break; | |
436 | } | |
437 | } | |
438 | ||
439 | static uint32_t uhci_ioport_readb(void *opaque, uint32_t addr) | |
440 | { | |
441 | UHCIState *s = opaque; | |
442 | uint32_t val; | |
443 | ||
444 | addr &= 0x1f; | |
445 | switch(addr) { | |
446 | case 0x0c: | |
447 | val = s->sof_timing; | |
d80cfb3f | 448 | break; |
bb36d470 FB |
449 | default: |
450 | val = 0xff; | |
451 | break; | |
452 | } | |
453 | return val; | |
454 | } | |
455 | ||
456 | static void uhci_ioport_writew(void *opaque, uint32_t addr, uint32_t val) | |
457 | { | |
458 | UHCIState *s = opaque; | |
3b46e624 | 459 | |
bb36d470 | 460 | addr &= 0x1f; |
50dcc0f8 | 461 | trace_usb_uhci_mmio_writew(addr, val); |
54f254f9 | 462 | |
bb36d470 FB |
463 | switch(addr) { |
464 | case 0x00: | |
465 | if ((val & UHCI_CMD_RS) && !(s->cmd & UHCI_CMD_RS)) { | |
466 | /* start frame processing */ | |
50dcc0f8 | 467 | trace_usb_uhci_schedule_start(); |
94cc916a GH |
468 | s->expire_time = qemu_get_clock_ns(vm_clock) + |
469 | (get_ticks_per_sec() / FRAME_TIMER_FREQ); | |
74475455 | 470 | qemu_mod_timer(s->frame_timer, qemu_get_clock_ns(vm_clock)); |
52328140 | 471 | s->status &= ~UHCI_STS_HCHALTED; |
467d409f | 472 | } else if (!(val & UHCI_CMD_RS)) { |
52328140 | 473 | s->status |= UHCI_STS_HCHALTED; |
bb36d470 FB |
474 | } |
475 | if (val & UHCI_CMD_GRESET) { | |
476 | UHCIPort *port; | |
bb36d470 FB |
477 | int i; |
478 | ||
479 | /* send reset on the USB bus */ | |
480 | for(i = 0; i < NB_PORTS; i++) { | |
481 | port = &s->ports[i]; | |
d28f4e2d | 482 | usb_device_reset(port->port.dev); |
bb36d470 FB |
483 | } |
484 | uhci_reset(s); | |
485 | return; | |
486 | } | |
5e9ab4c4 | 487 | if (val & UHCI_CMD_HCRESET) { |
bb36d470 FB |
488 | uhci_reset(s); |
489 | return; | |
490 | } | |
491 | s->cmd = val; | |
492 | break; | |
493 | case 0x02: | |
494 | s->status &= ~val; | |
495 | /* XXX: the chip spec is not coherent, so we add a hidden | |
496 | register to distinguish between IOC and SPD */ | |
497 | if (val & UHCI_STS_USBINT) | |
498 | s->status2 = 0; | |
499 | uhci_update_irq(s); | |
500 | break; | |
501 | case 0x04: | |
502 | s->intr = val; | |
503 | uhci_update_irq(s); | |
504 | break; | |
505 | case 0x06: | |
506 | if (s->status & UHCI_STS_HCHALTED) | |
507 | s->frnum = val & 0x7ff; | |
508 | break; | |
509 | case 0x10 ... 0x1f: | |
510 | { | |
511 | UHCIPort *port; | |
512 | USBDevice *dev; | |
513 | int n; | |
514 | ||
515 | n = (addr >> 1) & 7; | |
516 | if (n >= NB_PORTS) | |
517 | return; | |
518 | port = &s->ports[n]; | |
a594cfbf | 519 | dev = port->port.dev; |
891fb2cd | 520 | if (dev && dev->attached) { |
bb36d470 | 521 | /* port reset */ |
5fafdf24 | 522 | if ( (val & UHCI_PORT_RESET) && |
bb36d470 | 523 | !(port->ctrl & UHCI_PORT_RESET) ) { |
d28f4e2d | 524 | usb_device_reset(dev); |
bb36d470 FB |
525 | } |
526 | } | |
9159f679 GH |
527 | port->ctrl &= UHCI_PORT_READ_ONLY; |
528 | port->ctrl |= (val & ~UHCI_PORT_READ_ONLY); | |
bb36d470 | 529 | /* some bits are reset when a '1' is written to them */ |
9159f679 | 530 | port->ctrl &= ~(val & UHCI_PORT_WRITE_CLEAR); |
bb36d470 FB |
531 | } |
532 | break; | |
533 | } | |
534 | } | |
535 | ||
536 | static uint32_t uhci_ioport_readw(void *opaque, uint32_t addr) | |
537 | { | |
538 | UHCIState *s = opaque; | |
539 | uint32_t val; | |
540 | ||
541 | addr &= 0x1f; | |
542 | switch(addr) { | |
543 | case 0x00: | |
544 | val = s->cmd; | |
545 | break; | |
546 | case 0x02: | |
547 | val = s->status; | |
548 | break; | |
549 | case 0x04: | |
550 | val = s->intr; | |
551 | break; | |
552 | case 0x06: | |
553 | val = s->frnum; | |
554 | break; | |
555 | case 0x10 ... 0x1f: | |
556 | { | |
557 | UHCIPort *port; | |
558 | int n; | |
559 | n = (addr >> 1) & 7; | |
5fafdf24 | 560 | if (n >= NB_PORTS) |
bb36d470 FB |
561 | goto read_default; |
562 | port = &s->ports[n]; | |
563 | val = port->ctrl; | |
564 | } | |
565 | break; | |
566 | default: | |
567 | read_default: | |
568 | val = 0xff7f; /* disabled port */ | |
569 | break; | |
570 | } | |
54f254f9 | 571 | |
50dcc0f8 | 572 | trace_usb_uhci_mmio_readw(addr, val); |
54f254f9 | 573 | |
bb36d470 FB |
574 | return val; |
575 | } | |
576 | ||
577 | static void uhci_ioport_writel(void *opaque, uint32_t addr, uint32_t val) | |
578 | { | |
579 | UHCIState *s = opaque; | |
580 | ||
581 | addr &= 0x1f; | |
50dcc0f8 | 582 | trace_usb_uhci_mmio_writel(addr, val); |
54f254f9 | 583 | |
bb36d470 FB |
584 | switch(addr) { |
585 | case 0x08: | |
586 | s->fl_base_addr = val & ~0xfff; | |
587 | break; | |
588 | } | |
589 | } | |
590 | ||
591 | static uint32_t uhci_ioport_readl(void *opaque, uint32_t addr) | |
592 | { | |
593 | UHCIState *s = opaque; | |
594 | uint32_t val; | |
595 | ||
596 | addr &= 0x1f; | |
597 | switch(addr) { | |
598 | case 0x08: | |
599 | val = s->fl_base_addr; | |
600 | break; | |
601 | default: | |
602 | val = 0xffffffff; | |
603 | break; | |
604 | } | |
50dcc0f8 | 605 | trace_usb_uhci_mmio_readl(addr, val); |
bb36d470 FB |
606 | return val; |
607 | } | |
608 | ||
96217e31 TS |
609 | /* signal resume if controller suspended */ |
610 | static void uhci_resume (void *opaque) | |
611 | { | |
612 | UHCIState *s = (UHCIState *)opaque; | |
613 | ||
614 | if (!s) | |
615 | return; | |
616 | ||
617 | if (s->cmd & UHCI_CMD_EGSM) { | |
618 | s->cmd |= UHCI_CMD_FGR; | |
619 | s->status |= UHCI_STS_RD; | |
620 | uhci_update_irq(s); | |
621 | } | |
622 | } | |
623 | ||
618c169b | 624 | static void uhci_attach(USBPort *port1) |
bb36d470 FB |
625 | { |
626 | UHCIState *s = port1->opaque; | |
627 | UHCIPort *port = &s->ports[port1->index]; | |
628 | ||
618c169b GH |
629 | /* set connect status */ |
630 | port->ctrl |= UHCI_PORT_CCS | UHCI_PORT_CSC; | |
61064870 | 631 | |
618c169b GH |
632 | /* update speed */ |
633 | if (port->port.dev->speed == USB_SPEED_LOW) { | |
634 | port->ctrl |= UHCI_PORT_LSDA; | |
bb36d470 | 635 | } else { |
618c169b GH |
636 | port->ctrl &= ~UHCI_PORT_LSDA; |
637 | } | |
96217e31 | 638 | |
618c169b GH |
639 | uhci_resume(s); |
640 | } | |
96217e31 | 641 | |
618c169b GH |
642 | static void uhci_detach(USBPort *port1) |
643 | { | |
644 | UHCIState *s = port1->opaque; | |
645 | UHCIPort *port = &s->ports[port1->index]; | |
646 | ||
4706ab6c HG |
647 | uhci_async_cancel_device(s, port1->dev); |
648 | ||
618c169b GH |
649 | /* set connect status */ |
650 | if (port->ctrl & UHCI_PORT_CCS) { | |
651 | port->ctrl &= ~UHCI_PORT_CCS; | |
652 | port->ctrl |= UHCI_PORT_CSC; | |
bb36d470 | 653 | } |
618c169b GH |
654 | /* disable port */ |
655 | if (port->ctrl & UHCI_PORT_EN) { | |
656 | port->ctrl &= ~UHCI_PORT_EN; | |
657 | port->ctrl |= UHCI_PORT_ENC; | |
658 | } | |
659 | ||
660 | uhci_resume(s); | |
bb36d470 FB |
661 | } |
662 | ||
4706ab6c HG |
663 | static void uhci_child_detach(USBPort *port1, USBDevice *child) |
664 | { | |
665 | UHCIState *s = port1->opaque; | |
666 | ||
667 | uhci_async_cancel_device(s, child); | |
668 | } | |
669 | ||
d47e59b8 | 670 | static void uhci_wakeup(USBPort *port1) |
9159f679 | 671 | { |
d47e59b8 HG |
672 | UHCIState *s = port1->opaque; |
673 | UHCIPort *port = &s->ports[port1->index]; | |
9159f679 GH |
674 | |
675 | if (port->ctrl & UHCI_PORT_SUSPEND && !(port->ctrl & UHCI_PORT_RD)) { | |
676 | port->ctrl |= UHCI_PORT_RD; | |
677 | uhci_resume(s); | |
678 | } | |
679 | } | |
680 | ||
461700c1 | 681 | static USBDevice *uhci_find_device(UHCIState *s, uint8_t addr) |
bb36d470 | 682 | { |
461700c1 GH |
683 | USBDevice *dev; |
684 | int i; | |
54f254f9 | 685 | |
461700c1 | 686 | for (i = 0; i < NB_PORTS; i++) { |
54f254f9 | 687 | UHCIPort *port = &s->ports[i]; |
461700c1 GH |
688 | if (!(port->ctrl & UHCI_PORT_EN)) { |
689 | continue; | |
690 | } | |
691 | dev = usb_find_device(&port->port, addr); | |
692 | if (dev != NULL) { | |
693 | return dev; | |
891fb2cd | 694 | } |
bb36d470 | 695 | } |
461700c1 | 696 | return NULL; |
bb36d470 FB |
697 | } |
698 | ||
d47e59b8 | 699 | static void uhci_async_complete(USBPort *port, USBPacket *packet); |
54f254f9 | 700 | static void uhci_process_frame(UHCIState *s); |
4d611c9a | 701 | |
bb36d470 FB |
702 | /* return -1 if fatal error (frame must be stopped) |
703 | 0 if TD successful | |
704 | 1 if TD unsuccessful or inactive | |
705 | */ | |
54f254f9 | 706 | static int uhci_complete_td(UHCIState *s, UHCI_TD *td, UHCIAsync *async, uint32_t *int_mask) |
bb36d470 | 707 | { |
54f254f9 | 708 | int len = 0, max_len, err, ret; |
bb36d470 | 709 | uint8_t pid; |
bb36d470 | 710 | |
54f254f9 AL |
711 | max_len = ((td->token >> 21) + 1) & 0x7ff; |
712 | pid = td->token & 0xff; | |
713 | ||
4f4321c1 | 714 | ret = async->packet.result; |
54f254f9 | 715 | |
54f254f9 AL |
716 | if (td->ctrl & TD_CTRL_IOS) |
717 | td->ctrl &= ~TD_CTRL_ACTIVE; | |
bb36d470 | 718 | |
54f254f9 AL |
719 | if (ret < 0) |
720 | goto out; | |
b9dc033c | 721 | |
4f4321c1 | 722 | len = async->packet.result; |
54f254f9 AL |
723 | td->ctrl = (td->ctrl & ~0x7ff) | ((len - 1) & 0x7ff); |
724 | ||
725 | /* The NAK bit may have been set by a previous frame, so clear it | |
726 | here. The docs are somewhat unclear, but win2k relies on this | |
727 | behavior. */ | |
728 | td->ctrl &= ~(TD_CTRL_ACTIVE | TD_CTRL_NAK); | |
5bd2c0d7 PB |
729 | if (td->ctrl & TD_CTRL_IOC) |
730 | *int_mask |= 0x01; | |
54f254f9 AL |
731 | |
732 | if (pid == USB_TOKEN_IN) { | |
54f254f9 | 733 | if ((td->ctrl & TD_CTRL_SPD) && len < max_len) { |
bb36d470 FB |
734 | *int_mask |= 0x02; |
735 | /* short packet: do not update QH */ | |
50dcc0f8 GH |
736 | trace_usb_uhci_packet_complete_shortxfer(async->queue->token, |
737 | async->td); | |
60e1b2a6 | 738 | return TD_RESULT_NEXT_QH; |
bb36d470 | 739 | } |
54f254f9 AL |
740 | } |
741 | ||
742 | /* success */ | |
50dcc0f8 | 743 | trace_usb_uhci_packet_complete_success(async->queue->token, async->td); |
60e1b2a6 | 744 | return TD_RESULT_COMPLETE; |
54f254f9 AL |
745 | |
746 | out: | |
0132b4b6 HG |
747 | /* |
748 | * We should not do any further processing on a queue with errors! | |
749 | * This is esp. important for bulk endpoints with pipelining enabled | |
750 | * (redirection to a real USB device), where we must cancel all the | |
751 | * transfers after this one so that: | |
752 | * 1) If they've completed already, they are not processed further | |
753 | * causing more stalls, originating from the same failed transfer | |
754 | * 2) If still in flight, they are cancelled before the guest does | |
755 | * a clear stall, otherwise the guest and device can loose sync! | |
756 | */ | |
757 | while (!QTAILQ_EMPTY(&async->queue->asyncs)) { | |
758 | UHCIAsync *as = QTAILQ_FIRST(&async->queue->asyncs); | |
759 | uhci_async_unlink(as); | |
760 | uhci_async_cancel(as); | |
761 | } | |
762 | ||
54f254f9 AL |
763 | switch(ret) { |
764 | case USB_RET_STALL: | |
765 | td->ctrl |= TD_CTRL_STALL; | |
766 | td->ctrl &= ~TD_CTRL_ACTIVE; | |
8656954a | 767 | s->status |= UHCI_STS_USBERR; |
0070f095 GH |
768 | if (td->ctrl & TD_CTRL_IOC) { |
769 | *int_mask |= 0x01; | |
770 | } | |
8656954a | 771 | uhci_update_irq(s); |
50dcc0f8 | 772 | trace_usb_uhci_packet_complete_stall(async->queue->token, async->td); |
60e1b2a6 | 773 | return TD_RESULT_NEXT_QH; |
54f254f9 AL |
774 | |
775 | case USB_RET_BABBLE: | |
776 | td->ctrl |= TD_CTRL_BABBLE | TD_CTRL_STALL; | |
777 | td->ctrl &= ~TD_CTRL_ACTIVE; | |
8656954a | 778 | s->status |= UHCI_STS_USBERR; |
0070f095 GH |
779 | if (td->ctrl & TD_CTRL_IOC) { |
780 | *int_mask |= 0x01; | |
781 | } | |
8656954a | 782 | uhci_update_irq(s); |
54f254f9 | 783 | /* frame interrupted */ |
50dcc0f8 | 784 | trace_usb_uhci_packet_complete_babble(async->queue->token, async->td); |
60e1b2a6 | 785 | return TD_RESULT_STOP_FRAME; |
54f254f9 AL |
786 | |
787 | case USB_RET_NAK: | |
788 | td->ctrl |= TD_CTRL_NAK; | |
789 | if (pid == USB_TOKEN_SETUP) | |
790 | break; | |
60e1b2a6 | 791 | return TD_RESULT_NEXT_QH; |
54f254f9 | 792 | |
d61000a8 | 793 | case USB_RET_IOERROR: |
54f254f9 AL |
794 | case USB_RET_NODEV: |
795 | default: | |
796 | break; | |
797 | } | |
798 | ||
799 | /* Retry the TD if error count is not zero */ | |
800 | ||
801 | td->ctrl |= TD_CTRL_TIMEOUT; | |
802 | err = (td->ctrl >> TD_CTRL_ERROR_SHIFT) & 3; | |
803 | if (err != 0) { | |
804 | err--; | |
805 | if (err == 0) { | |
bb36d470 | 806 | td->ctrl &= ~TD_CTRL_ACTIVE; |
54f254f9 | 807 | s->status |= UHCI_STS_USBERR; |
5bd2c0d7 PB |
808 | if (td->ctrl & TD_CTRL_IOC) |
809 | *int_mask |= 0x01; | |
54f254f9 | 810 | uhci_update_irq(s); |
50dcc0f8 GH |
811 | trace_usb_uhci_packet_complete_error(async->queue->token, |
812 | async->td); | |
bb36d470 FB |
813 | } |
814 | } | |
54f254f9 AL |
815 | td->ctrl = (td->ctrl & ~(3 << TD_CTRL_ERROR_SHIFT)) | |
816 | (err << TD_CTRL_ERROR_SHIFT); | |
60e1b2a6 | 817 | return TD_RESULT_NEXT_QH; |
bb36d470 FB |
818 | } |
819 | ||
ee008ba6 | 820 | static int uhci_handle_td(UHCIState *s, uint32_t addr, UHCI_TD *td, |
36dfe324 HG |
821 | uint32_t *int_mask, bool queuing, |
822 | struct USBEndpoint **ep_ret) | |
54f254f9 AL |
823 | { |
824 | UHCIAsync *async; | |
5d808245 | 825 | int len = 0, max_len; |
f8af1e88 | 826 | uint8_t pid; |
079d0b7f GH |
827 | USBDevice *dev; |
828 | USBEndpoint *ep; | |
54f254f9 AL |
829 | |
830 | /* Is active ? */ | |
883bca77 HG |
831 | if (!(td->ctrl & TD_CTRL_ACTIVE)) { |
832 | /* | |
833 | * ehci11d spec page 22: "Even if the Active bit in the TD is already | |
834 | * cleared when the TD is fetched ... an IOC interrupt is generated" | |
835 | */ | |
836 | if (td->ctrl & TD_CTRL_IOC) { | |
837 | *int_mask |= 0x01; | |
838 | } | |
60e1b2a6 | 839 | return TD_RESULT_NEXT_QH; |
883bca77 | 840 | } |
54f254f9 | 841 | |
f8af1e88 | 842 | async = uhci_async_find_td(s, addr, td); |
54f254f9 AL |
843 | if (async) { |
844 | /* Already submitted */ | |
f8af1e88 | 845 | async->queue->valid = 32; |
54f254f9 AL |
846 | |
847 | if (!async->done) | |
4efe4ef3 | 848 | return TD_RESULT_ASYNC_CONT; |
ee008ba6 GH |
849 | if (queuing) { |
850 | /* we are busy filling the queue, we are not prepared | |
851 | to consume completed packages then, just leave them | |
852 | in async state */ | |
853 | return TD_RESULT_ASYNC_CONT; | |
854 | } | |
54f254f9 | 855 | |
f8af1e88 | 856 | uhci_async_unlink(async); |
54f254f9 AL |
857 | goto done; |
858 | } | |
859 | ||
860 | /* Allocate new packet */ | |
16ce543e | 861 | async = uhci_async_alloc(uhci_queue_get(s, td), addr); |
54f254f9 | 862 | |
8e65b7c0 DA |
863 | /* valid needs to be large enough to handle 10 frame delay |
864 | * for initial isochronous requests | |
865 | */ | |
f8af1e88 | 866 | async->queue->valid = 32; |
e983395d | 867 | async->isoc = td->ctrl & TD_CTRL_IOS; |
54f254f9 AL |
868 | |
869 | max_len = ((td->token >> 21) + 1) & 0x7ff; | |
870 | pid = td->token & 0xff; | |
871 | ||
079d0b7f GH |
872 | dev = uhci_find_device(s, (td->token >> 8) & 0x7f); |
873 | ep = usb_ep_get(dev, pid, (td->token >> 15) & 0xf); | |
36dfe324 HG |
874 | if (ep_ret) { |
875 | *ep_ret = ep; | |
876 | } | |
e983395d | 877 | usb_packet_setup(&async->packet, pid, ep, addr); |
df5e66ee GH |
878 | qemu_sglist_add(&async->sgl, td->buffer, max_len); |
879 | usb_packet_map(&async->packet, &async->sgl); | |
54f254f9 AL |
880 | |
881 | switch(pid) { | |
882 | case USB_TOKEN_OUT: | |
883 | case USB_TOKEN_SETUP: | |
079d0b7f | 884 | len = usb_handle_packet(dev, &async->packet); |
5d808245 AJ |
885 | if (len >= 0) |
886 | len = max_len; | |
54f254f9 AL |
887 | break; |
888 | ||
889 | case USB_TOKEN_IN: | |
079d0b7f | 890 | len = usb_handle_packet(dev, &async->packet); |
54f254f9 AL |
891 | break; |
892 | ||
893 | default: | |
894 | /* invalid pid : frame interrupted */ | |
00a0770d | 895 | usb_packet_unmap(&async->packet, &async->sgl); |
f8af1e88 | 896 | uhci_async_free(async); |
54f254f9 AL |
897 | s->status |= UHCI_STS_HCPERR; |
898 | uhci_update_irq(s); | |
60e1b2a6 | 899 | return TD_RESULT_STOP_FRAME; |
54f254f9 AL |
900 | } |
901 | ||
5d808245 | 902 | if (len == USB_RET_ASYNC) { |
f8af1e88 | 903 | uhci_async_link(async); |
4efe4ef3 | 904 | return TD_RESULT_ASYNC_START; |
54f254f9 AL |
905 | } |
906 | ||
4f4321c1 | 907 | async->packet.result = len; |
54f254f9 AL |
908 | |
909 | done: | |
5d808245 | 910 | len = uhci_complete_td(s, td, async, int_mask); |
e2f89926 | 911 | usb_packet_unmap(&async->packet, &async->sgl); |
f8af1e88 | 912 | uhci_async_free(async); |
5d808245 | 913 | return len; |
54f254f9 AL |
914 | } |
915 | ||
d47e59b8 | 916 | static void uhci_async_complete(USBPort *port, USBPacket *packet) |
4d611c9a | 917 | { |
7b5a44c5 | 918 | UHCIAsync *async = container_of(packet, UHCIAsync, packet); |
f8af1e88 | 919 | UHCIState *s = async->queue->uhci; |
54f254f9 | 920 | |
8e65b7c0 DA |
921 | if (async->isoc) { |
922 | UHCI_TD td; | |
923 | uint32_t link = async->td; | |
924 | uint32_t int_mask = 0, val; | |
d4c4e6fd | 925 | |
9fe2fd67 | 926 | pci_dma_read(&s->dev, link & ~0xf, &td, sizeof(td)); |
8e65b7c0 DA |
927 | le32_to_cpus(&td.link); |
928 | le32_to_cpus(&td.ctrl); | |
929 | le32_to_cpus(&td.token); | |
930 | le32_to_cpus(&td.buffer); | |
931 | ||
f8af1e88 | 932 | uhci_async_unlink(async); |
d4c4e6fd | 933 | uhci_complete_td(s, &td, async, &int_mask); |
8e65b7c0 | 934 | s->pending_int_mask |= int_mask; |
54f254f9 | 935 | |
8e65b7c0 DA |
936 | /* update the status bits of the TD */ |
937 | val = cpu_to_le32(td.ctrl); | |
9fe2fd67 | 938 | pci_dma_write(&s->dev, (link & ~0xf) + 4, &val, sizeof(val)); |
f8af1e88 | 939 | uhci_async_free(async); |
8e65b7c0 DA |
940 | } else { |
941 | async->done = 1; | |
40141d12 | 942 | if (s->frame_bytes < s->frame_bandwidth) { |
9a16c595 GH |
943 | qemu_bh_schedule(s->bh); |
944 | } | |
8e65b7c0 | 945 | } |
54f254f9 AL |
946 | } |
947 | ||
948 | static int is_valid(uint32_t link) | |
949 | { | |
950 | return (link & 1) == 0; | |
951 | } | |
952 | ||
953 | static int is_qh(uint32_t link) | |
954 | { | |
955 | return (link & 2) != 0; | |
956 | } | |
957 | ||
958 | static int depth_first(uint32_t link) | |
959 | { | |
960 | return (link & 4) != 0; | |
961 | } | |
962 | ||
963 | /* QH DB used for detecting QH loops */ | |
964 | #define UHCI_MAX_QUEUES 128 | |
965 | typedef struct { | |
966 | uint32_t addr[UHCI_MAX_QUEUES]; | |
967 | int count; | |
968 | } QhDb; | |
969 | ||
970 | static void qhdb_reset(QhDb *db) | |
971 | { | |
972 | db->count = 0; | |
973 | } | |
974 | ||
975 | /* Add QH to DB. Returns 1 if already present or DB is full. */ | |
976 | static int qhdb_insert(QhDb *db, uint32_t addr) | |
977 | { | |
978 | int i; | |
979 | for (i = 0; i < db->count; i++) | |
980 | if (db->addr[i] == addr) | |
981 | return 1; | |
982 | ||
983 | if (db->count >= UHCI_MAX_QUEUES) | |
984 | return 1; | |
985 | ||
986 | db->addr[db->count++] = addr; | |
987 | return 0; | |
988 | } | |
989 | ||
36dfe324 | 990 | static void uhci_fill_queue(UHCIState *s, UHCI_TD *td, struct USBEndpoint *ep) |
5a248289 GH |
991 | { |
992 | uint32_t int_mask = 0; | |
993 | uint32_t plink = td->link; | |
994 | uint32_t token = uhci_queue_token(td); | |
995 | UHCI_TD ptd; | |
996 | int ret; | |
997 | ||
7c2eaca4 HG |
998 | ptd.ctrl = td->ctrl; |
999 | while (is_valid(plink) && !(ptd.ctrl & TD_CTRL_SPD)) { | |
5a248289 GH |
1000 | pci_dma_read(&s->dev, plink & ~0xf, &ptd, sizeof(ptd)); |
1001 | le32_to_cpus(&ptd.link); | |
1002 | le32_to_cpus(&ptd.ctrl); | |
1003 | le32_to_cpus(&ptd.token); | |
1004 | le32_to_cpus(&ptd.buffer); | |
1005 | if (!(ptd.ctrl & TD_CTRL_ACTIVE)) { | |
1006 | break; | |
1007 | } | |
1008 | if (uhci_queue_token(&ptd) != token) { | |
1009 | break; | |
1010 | } | |
50dcc0f8 | 1011 | trace_usb_uhci_td_queue(plink & ~0xf, ptd.ctrl, ptd.token); |
36dfe324 | 1012 | ret = uhci_handle_td(s, plink, &ptd, &int_mask, true, NULL); |
52b0fecd GH |
1013 | if (ret == TD_RESULT_ASYNC_CONT) { |
1014 | break; | |
1015 | } | |
4efe4ef3 | 1016 | assert(ret == TD_RESULT_ASYNC_START); |
5a248289 GH |
1017 | assert(int_mask == 0); |
1018 | plink = ptd.link; | |
1019 | } | |
36dfe324 | 1020 | usb_device_flush_ep_queue(ep->dev, ep); |
5a248289 GH |
1021 | } |
1022 | ||
54f254f9 AL |
1023 | static void uhci_process_frame(UHCIState *s) |
1024 | { | |
1025 | uint32_t frame_addr, link, old_td_ctrl, val, int_mask; | |
4aed20e2 | 1026 | uint32_t curr_qh, td_count = 0; |
36dfe324 | 1027 | struct USBEndpoint *curr_ep; |
54f254f9 | 1028 | int cnt, ret; |
4d611c9a | 1029 | UHCI_TD td; |
54f254f9 AL |
1030 | UHCI_QH qh; |
1031 | QhDb qhdb; | |
4d611c9a | 1032 | |
54f254f9 AL |
1033 | frame_addr = s->fl_base_addr + ((s->frnum & 0x3ff) << 2); |
1034 | ||
9fe2fd67 | 1035 | pci_dma_read(&s->dev, frame_addr, &link, 4); |
54f254f9 | 1036 | le32_to_cpus(&link); |
b9dc033c | 1037 | |
54f254f9 AL |
1038 | int_mask = 0; |
1039 | curr_qh = 0; | |
1040 | ||
1041 | qhdb_reset(&qhdb); | |
1042 | ||
1043 | for (cnt = FRAME_MAX_LOOPS; is_valid(link) && cnt; cnt--) { | |
40141d12 | 1044 | if (s->frame_bytes >= s->frame_bandwidth) { |
4aed20e2 GH |
1045 | /* We've reached the usb 1.1 bandwidth, which is |
1046 | 1280 bytes/frame, stop processing */ | |
1047 | trace_usb_uhci_frame_stop_bandwidth(); | |
1048 | break; | |
1049 | } | |
54f254f9 AL |
1050 | if (is_qh(link)) { |
1051 | /* QH */ | |
50dcc0f8 | 1052 | trace_usb_uhci_qh_load(link & ~0xf); |
54f254f9 AL |
1053 | |
1054 | if (qhdb_insert(&qhdb, link)) { | |
1055 | /* | |
1056 | * We're going in circles. Which is not a bug because | |
3200d108 GH |
1057 | * HCD is allowed to do that as part of the BW management. |
1058 | * | |
4aed20e2 GH |
1059 | * Stop processing here if no transaction has been done |
1060 | * since we've been here last time. | |
54f254f9 | 1061 | */ |
3200d108 | 1062 | if (td_count == 0) { |
50dcc0f8 | 1063 | trace_usb_uhci_frame_loop_stop_idle(); |
3200d108 | 1064 | break; |
3200d108 | 1065 | } else { |
50dcc0f8 | 1066 | trace_usb_uhci_frame_loop_continue(); |
3200d108 GH |
1067 | td_count = 0; |
1068 | qhdb_reset(&qhdb); | |
1069 | qhdb_insert(&qhdb, link); | |
1070 | } | |
54f254f9 AL |
1071 | } |
1072 | ||
9fe2fd67 | 1073 | pci_dma_read(&s->dev, link & ~0xf, &qh, sizeof(qh)); |
54f254f9 AL |
1074 | le32_to_cpus(&qh.link); |
1075 | le32_to_cpus(&qh.el_link); | |
1076 | ||
54f254f9 AL |
1077 | if (!is_valid(qh.el_link)) { |
1078 | /* QH w/o elements */ | |
1079 | curr_qh = 0; | |
1080 | link = qh.link; | |
1081 | } else { | |
1082 | /* QH with elements */ | |
1083 | curr_qh = link; | |
1084 | link = qh.el_link; | |
1085 | } | |
1086 | continue; | |
1087 | } | |
1088 | ||
1089 | /* TD */ | |
9fe2fd67 | 1090 | pci_dma_read(&s->dev, link & ~0xf, &td, sizeof(td)); |
b9dc033c AZ |
1091 | le32_to_cpus(&td.link); |
1092 | le32_to_cpus(&td.ctrl); | |
1093 | le32_to_cpus(&td.token); | |
1094 | le32_to_cpus(&td.buffer); | |
50dcc0f8 | 1095 | trace_usb_uhci_td_load(curr_qh & ~0xf, link & ~0xf, td.ctrl, td.token); |
54f254f9 AL |
1096 | |
1097 | old_td_ctrl = td.ctrl; | |
36dfe324 | 1098 | ret = uhci_handle_td(s, link, &td, &int_mask, false, &curr_ep); |
b9dc033c | 1099 | if (old_td_ctrl != td.ctrl) { |
54f254f9 | 1100 | /* update the status bits of the TD */ |
b9dc033c | 1101 | val = cpu_to_le32(td.ctrl); |
9fe2fd67 | 1102 | pci_dma_write(&s->dev, (link & ~0xf) + 4, &val, sizeof(val)); |
b9dc033c | 1103 | } |
54f254f9 | 1104 | |
971a5a40 | 1105 | switch (ret) { |
60e1b2a6 | 1106 | case TD_RESULT_STOP_FRAME: /* interrupted frame */ |
971a5a40 | 1107 | goto out; |
b9dc033c | 1108 | |
60e1b2a6 | 1109 | case TD_RESULT_NEXT_QH: |
4efe4ef3 | 1110 | case TD_RESULT_ASYNC_CONT: |
50dcc0f8 | 1111 | trace_usb_uhci_td_nextqh(curr_qh & ~0xf, link & ~0xf); |
54f254f9 AL |
1112 | link = curr_qh ? qh.link : td.link; |
1113 | continue; | |
54f254f9 | 1114 | |
4efe4ef3 | 1115 | case TD_RESULT_ASYNC_START: |
50dcc0f8 | 1116 | trace_usb_uhci_td_async(curr_qh & ~0xf, link & ~0xf); |
36dfe324 | 1117 | uhci_fill_queue(s, &td, curr_ep); |
971a5a40 GH |
1118 | link = curr_qh ? qh.link : td.link; |
1119 | continue; | |
54f254f9 | 1120 | |
60e1b2a6 | 1121 | case TD_RESULT_COMPLETE: |
50dcc0f8 | 1122 | trace_usb_uhci_td_complete(curr_qh & ~0xf, link & ~0xf); |
971a5a40 GH |
1123 | link = td.link; |
1124 | td_count++; | |
4aed20e2 | 1125 | s->frame_bytes += (td.ctrl & 0x7ff) + 1; |
54f254f9 | 1126 | |
971a5a40 GH |
1127 | if (curr_qh) { |
1128 | /* update QH element link */ | |
1129 | qh.el_link = link; | |
1130 | val = cpu_to_le32(qh.el_link); | |
1131 | pci_dma_write(&s->dev, (curr_qh & ~0xf) + 4, &val, sizeof(val)); | |
54f254f9 | 1132 | |
971a5a40 GH |
1133 | if (!depth_first(link)) { |
1134 | /* done with this QH */ | |
971a5a40 GH |
1135 | curr_qh = 0; |
1136 | link = qh.link; | |
1137 | } | |
54f254f9 | 1138 | } |
971a5a40 GH |
1139 | break; |
1140 | ||
1141 | default: | |
1142 | assert(!"unknown return code"); | |
4d611c9a | 1143 | } |
54f254f9 AL |
1144 | |
1145 | /* go to the next entry */ | |
4d611c9a | 1146 | } |
54f254f9 | 1147 | |
971a5a40 | 1148 | out: |
8e65b7c0 | 1149 | s->pending_int_mask |= int_mask; |
4d611c9a PB |
1150 | } |
1151 | ||
9a16c595 GH |
1152 | static void uhci_bh(void *opaque) |
1153 | { | |
1154 | UHCIState *s = opaque; | |
1155 | uhci_process_frame(s); | |
1156 | } | |
1157 | ||
bb36d470 FB |
1158 | static void uhci_frame_timer(void *opaque) |
1159 | { | |
1160 | UHCIState *s = opaque; | |
8e65b7c0 DA |
1161 | |
1162 | /* prepare the timer for the next frame */ | |
1163 | s->expire_time += (get_ticks_per_sec() / FRAME_TIMER_FREQ); | |
4aed20e2 | 1164 | s->frame_bytes = 0; |
9a16c595 | 1165 | qemu_bh_cancel(s->bh); |
bb36d470 FB |
1166 | |
1167 | if (!(s->cmd & UHCI_CMD_RS)) { | |
54f254f9 | 1168 | /* Full stop */ |
50dcc0f8 | 1169 | trace_usb_uhci_schedule_stop(); |
bb36d470 | 1170 | qemu_del_timer(s->frame_timer); |
d9a528db | 1171 | uhci_async_cancel_all(s); |
52328140 FB |
1172 | /* set hchalted bit in status - UHCI11D 2.1.2 */ |
1173 | s->status |= UHCI_STS_HCHALTED; | |
bb36d470 FB |
1174 | return; |
1175 | } | |
54f254f9 AL |
1176 | |
1177 | /* Complete the previous frame */ | |
4d611c9a PB |
1178 | if (s->pending_int_mask) { |
1179 | s->status2 |= s->pending_int_mask; | |
54f254f9 | 1180 | s->status |= UHCI_STS_USBINT; |
4d611c9a PB |
1181 | uhci_update_irq(s); |
1182 | } | |
8e65b7c0 | 1183 | s->pending_int_mask = 0; |
b9dc033c | 1184 | |
54f254f9 AL |
1185 | /* Start new frame */ |
1186 | s->frnum = (s->frnum + 1) & 0x7ff; | |
1187 | ||
50dcc0f8 | 1188 | trace_usb_uhci_frame_start(s->frnum); |
54f254f9 AL |
1189 | |
1190 | uhci_async_validate_begin(s); | |
1191 | ||
1192 | uhci_process_frame(s); | |
1193 | ||
1194 | uhci_async_validate_end(s); | |
b9dc033c | 1195 | |
8e65b7c0 | 1196 | qemu_mod_timer(s->frame_timer, s->expire_time); |
bb36d470 FB |
1197 | } |
1198 | ||
a03f66e4 AK |
1199 | static const MemoryRegionPortio uhci_portio[] = { |
1200 | { 0, 32, 2, .write = uhci_ioport_writew, }, | |
1201 | { 0, 32, 2, .read = uhci_ioport_readw, }, | |
1202 | { 0, 32, 4, .write = uhci_ioport_writel, }, | |
1203 | { 0, 32, 4, .read = uhci_ioport_readl, }, | |
1204 | { 0, 32, 1, .write = uhci_ioport_writeb, }, | |
1205 | { 0, 32, 1, .read = uhci_ioport_readb, }, | |
1206 | PORTIO_END_OF_LIST() | |
1207 | }; | |
1208 | ||
1209 | static const MemoryRegionOps uhci_ioport_ops = { | |
1210 | .old_portio = uhci_portio, | |
1211 | }; | |
bb36d470 | 1212 | |
0d86d2be GH |
1213 | static USBPortOps uhci_port_ops = { |
1214 | .attach = uhci_attach, | |
618c169b | 1215 | .detach = uhci_detach, |
4706ab6c | 1216 | .child_detach = uhci_child_detach, |
9159f679 | 1217 | .wakeup = uhci_wakeup, |
13a9a0d3 | 1218 | .complete = uhci_async_complete, |
0d86d2be GH |
1219 | }; |
1220 | ||
07771f6f | 1221 | static USBBusOps uhci_bus_ops = { |
07771f6f GH |
1222 | }; |
1223 | ||
dc638fad | 1224 | static int usb_uhci_common_initfn(PCIDevice *dev) |
bb36d470 | 1225 | { |
973002c1 | 1226 | PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev); |
dc638fad | 1227 | UHCIState *s = DO_UPCAST(UHCIState, dev, dev); |
6cf9b6f1 | 1228 | uint8_t *pci_conf = s->dev.config; |
bb36d470 FB |
1229 | int i; |
1230 | ||
db579e9e | 1231 | pci_conf[PCI_CLASS_PROG] = 0x00; |
db579e9e | 1232 | /* TODO: reset value should be 0. */ |
e59d33a7 | 1233 | pci_conf[USB_SBRN] = USB_RELEASE_1; // release number |
3b46e624 | 1234 | |
973002c1 GH |
1235 | switch (pc->device_id) { |
1236 | case PCI_DEVICE_ID_INTEL_82801I_UHCI1: | |
1237 | s->irq_pin = 0; /* A */ | |
1238 | break; | |
1239 | case PCI_DEVICE_ID_INTEL_82801I_UHCI2: | |
1240 | s->irq_pin = 1; /* B */ | |
1241 | break; | |
1242 | case PCI_DEVICE_ID_INTEL_82801I_UHCI3: | |
1243 | s->irq_pin = 2; /* C */ | |
1244 | break; | |
1245 | default: | |
1246 | s->irq_pin = 3; /* D */ | |
1247 | break; | |
1248 | } | |
1249 | pci_config_set_interrupt_pin(pci_conf, s->irq_pin + 1); | |
1250 | ||
35e4977f HG |
1251 | if (s->masterbus) { |
1252 | USBPort *ports[NB_PORTS]; | |
1253 | for(i = 0; i < NB_PORTS; i++) { | |
1254 | ports[i] = &s->ports[i].port; | |
1255 | } | |
1256 | if (usb_register_companion(s->masterbus, ports, NB_PORTS, | |
1257 | s->firstport, s, &uhci_port_ops, | |
1258 | USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL) != 0) { | |
1259 | return -1; | |
1260 | } | |
1261 | } else { | |
1262 | usb_bus_new(&s->bus, &uhci_bus_ops, &s->dev.qdev); | |
1263 | for (i = 0; i < NB_PORTS; i++) { | |
1264 | usb_register_port(&s->bus, &s->ports[i].port, s, i, &uhci_port_ops, | |
1265 | USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL); | |
1266 | } | |
bb36d470 | 1267 | } |
9a16c595 | 1268 | s->bh = qemu_bh_new(uhci_bh, s); |
74475455 | 1269 | s->frame_timer = qemu_new_timer_ns(vm_clock, uhci_frame_timer, s); |
64e58fe5 | 1270 | s->num_ports_vmstate = NB_PORTS; |
f8af1e88 | 1271 | QTAILQ_INIT(&s->queues); |
bb36d470 | 1272 | |
a08d4367 | 1273 | qemu_register_reset(uhci_reset, s); |
bb36d470 | 1274 | |
a03f66e4 | 1275 | memory_region_init_io(&s->io_bar, &uhci_ioport_ops, s, "uhci", 0x20); |
38ca0f6d PB |
1276 | /* Use region 4 for consistency with real hardware. BSD guests seem |
1277 | to rely on this. */ | |
e824b2cc | 1278 | pci_register_bar(&s->dev, 4, PCI_BASE_ADDRESS_SPACE_IO, &s->io_bar); |
6f382b5e | 1279 | |
6cf9b6f1 | 1280 | return 0; |
bb36d470 | 1281 | } |
afcc3cdf | 1282 | |
30235a54 HC |
1283 | static int usb_uhci_vt82c686b_initfn(PCIDevice *dev) |
1284 | { | |
1285 | UHCIState *s = DO_UPCAST(UHCIState, dev, dev); | |
1286 | uint8_t *pci_conf = s->dev.config; | |
1287 | ||
30235a54 HC |
1288 | /* USB misc control 1/2 */ |
1289 | pci_set_long(pci_conf + 0x40,0x00001000); | |
1290 | /* PM capability */ | |
1291 | pci_set_long(pci_conf + 0x80,0x00020001); | |
1292 | /* USB legacy support */ | |
1293 | pci_set_long(pci_conf + 0xc0,0x00002000); | |
1294 | ||
dc638fad | 1295 | return usb_uhci_common_initfn(dev); |
30235a54 HC |
1296 | } |
1297 | ||
f90c2bcd | 1298 | static void usb_uhci_exit(PCIDevice *dev) |
a03f66e4 AK |
1299 | { |
1300 | UHCIState *s = DO_UPCAST(UHCIState, dev, dev); | |
1301 | ||
1302 | memory_region_destroy(&s->io_bar); | |
a03f66e4 AK |
1303 | } |
1304 | ||
1b5a7570 GH |
1305 | static Property uhci_properties[] = { |
1306 | DEFINE_PROP_STRING("masterbus", UHCIState, masterbus), | |
1307 | DEFINE_PROP_UINT32("firstport", UHCIState, firstport, 0), | |
40141d12 | 1308 | DEFINE_PROP_UINT32("bandwidth", UHCIState, frame_bandwidth, 1280), |
1b5a7570 GH |
1309 | DEFINE_PROP_END_OF_LIST(), |
1310 | }; | |
1311 | ||
40021f08 AL |
1312 | static void piix3_uhci_class_init(ObjectClass *klass, void *data) |
1313 | { | |
39bffca2 | 1314 | DeviceClass *dc = DEVICE_CLASS(klass); |
40021f08 AL |
1315 | PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); |
1316 | ||
1317 | k->init = usb_uhci_common_initfn; | |
1318 | k->exit = usb_uhci_exit; | |
1319 | k->vendor_id = PCI_VENDOR_ID_INTEL; | |
1320 | k->device_id = PCI_DEVICE_ID_INTEL_82371SB_2; | |
1321 | k->revision = 0x01; | |
1322 | k->class_id = PCI_CLASS_SERIAL_USB; | |
39bffca2 AL |
1323 | dc->vmsd = &vmstate_uhci; |
1324 | dc->props = uhci_properties; | |
40021f08 AL |
1325 | } |
1326 | ||
39bffca2 AL |
1327 | static TypeInfo piix3_uhci_info = { |
1328 | .name = "piix3-usb-uhci", | |
1329 | .parent = TYPE_PCI_DEVICE, | |
1330 | .instance_size = sizeof(UHCIState), | |
1331 | .class_init = piix3_uhci_class_init, | |
e855761c AL |
1332 | }; |
1333 | ||
40021f08 AL |
1334 | static void piix4_uhci_class_init(ObjectClass *klass, void *data) |
1335 | { | |
39bffca2 | 1336 | DeviceClass *dc = DEVICE_CLASS(klass); |
40021f08 AL |
1337 | PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); |
1338 | ||
1339 | k->init = usb_uhci_common_initfn; | |
1340 | k->exit = usb_uhci_exit; | |
1341 | k->vendor_id = PCI_VENDOR_ID_INTEL; | |
1342 | k->device_id = PCI_DEVICE_ID_INTEL_82371AB_2; | |
1343 | k->revision = 0x01; | |
1344 | k->class_id = PCI_CLASS_SERIAL_USB; | |
39bffca2 AL |
1345 | dc->vmsd = &vmstate_uhci; |
1346 | dc->props = uhci_properties; | |
40021f08 AL |
1347 | } |
1348 | ||
39bffca2 AL |
1349 | static TypeInfo piix4_uhci_info = { |
1350 | .name = "piix4-usb-uhci", | |
1351 | .parent = TYPE_PCI_DEVICE, | |
1352 | .instance_size = sizeof(UHCIState), | |
1353 | .class_init = piix4_uhci_class_init, | |
e855761c AL |
1354 | }; |
1355 | ||
40021f08 AL |
1356 | static void vt82c686b_uhci_class_init(ObjectClass *klass, void *data) |
1357 | { | |
39bffca2 | 1358 | DeviceClass *dc = DEVICE_CLASS(klass); |
40021f08 AL |
1359 | PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); |
1360 | ||
1361 | k->init = usb_uhci_vt82c686b_initfn; | |
1362 | k->exit = usb_uhci_exit; | |
1363 | k->vendor_id = PCI_VENDOR_ID_VIA; | |
1364 | k->device_id = PCI_DEVICE_ID_VIA_UHCI; | |
1365 | k->revision = 0x01; | |
1366 | k->class_id = PCI_CLASS_SERIAL_USB; | |
39bffca2 AL |
1367 | dc->vmsd = &vmstate_uhci; |
1368 | dc->props = uhci_properties; | |
40021f08 AL |
1369 | } |
1370 | ||
39bffca2 AL |
1371 | static TypeInfo vt82c686b_uhci_info = { |
1372 | .name = "vt82c686b-usb-uhci", | |
1373 | .parent = TYPE_PCI_DEVICE, | |
1374 | .instance_size = sizeof(UHCIState), | |
1375 | .class_init = vt82c686b_uhci_class_init, | |
e855761c AL |
1376 | }; |
1377 | ||
40021f08 AL |
1378 | static void ich9_uhci1_class_init(ObjectClass *klass, void *data) |
1379 | { | |
39bffca2 | 1380 | DeviceClass *dc = DEVICE_CLASS(klass); |
40021f08 AL |
1381 | PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); |
1382 | ||
1383 | k->init = usb_uhci_common_initfn; | |
1384 | k->vendor_id = PCI_VENDOR_ID_INTEL; | |
1385 | k->device_id = PCI_DEVICE_ID_INTEL_82801I_UHCI1; | |
1386 | k->revision = 0x03; | |
1387 | k->class_id = PCI_CLASS_SERIAL_USB; | |
39bffca2 AL |
1388 | dc->vmsd = &vmstate_uhci; |
1389 | dc->props = uhci_properties; | |
40021f08 AL |
1390 | } |
1391 | ||
39bffca2 AL |
1392 | static TypeInfo ich9_uhci1_info = { |
1393 | .name = "ich9-usb-uhci1", | |
1394 | .parent = TYPE_PCI_DEVICE, | |
1395 | .instance_size = sizeof(UHCIState), | |
1396 | .class_init = ich9_uhci1_class_init, | |
e855761c AL |
1397 | }; |
1398 | ||
40021f08 AL |
1399 | static void ich9_uhci2_class_init(ObjectClass *klass, void *data) |
1400 | { | |
39bffca2 | 1401 | DeviceClass *dc = DEVICE_CLASS(klass); |
40021f08 AL |
1402 | PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); |
1403 | ||
1404 | k->init = usb_uhci_common_initfn; | |
1405 | k->vendor_id = PCI_VENDOR_ID_INTEL; | |
1406 | k->device_id = PCI_DEVICE_ID_INTEL_82801I_UHCI2; | |
1407 | k->revision = 0x03; | |
1408 | k->class_id = PCI_CLASS_SERIAL_USB; | |
39bffca2 AL |
1409 | dc->vmsd = &vmstate_uhci; |
1410 | dc->props = uhci_properties; | |
40021f08 AL |
1411 | } |
1412 | ||
39bffca2 AL |
1413 | static TypeInfo ich9_uhci2_info = { |
1414 | .name = "ich9-usb-uhci2", | |
1415 | .parent = TYPE_PCI_DEVICE, | |
1416 | .instance_size = sizeof(UHCIState), | |
1417 | .class_init = ich9_uhci2_class_init, | |
e855761c AL |
1418 | }; |
1419 | ||
40021f08 AL |
1420 | static void ich9_uhci3_class_init(ObjectClass *klass, void *data) |
1421 | { | |
39bffca2 | 1422 | DeviceClass *dc = DEVICE_CLASS(klass); |
40021f08 AL |
1423 | PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); |
1424 | ||
1425 | k->init = usb_uhci_common_initfn; | |
1426 | k->vendor_id = PCI_VENDOR_ID_INTEL; | |
1427 | k->device_id = PCI_DEVICE_ID_INTEL_82801I_UHCI3; | |
1428 | k->revision = 0x03; | |
1429 | k->class_id = PCI_CLASS_SERIAL_USB; | |
39bffca2 AL |
1430 | dc->vmsd = &vmstate_uhci; |
1431 | dc->props = uhci_properties; | |
40021f08 AL |
1432 | } |
1433 | ||
39bffca2 AL |
1434 | static TypeInfo ich9_uhci3_info = { |
1435 | .name = "ich9-usb-uhci3", | |
1436 | .parent = TYPE_PCI_DEVICE, | |
1437 | .instance_size = sizeof(UHCIState), | |
1438 | .class_init = ich9_uhci3_class_init, | |
6cf9b6f1 | 1439 | }; |
afcc3cdf | 1440 | |
83f7d43a | 1441 | static void uhci_register_types(void) |
6cf9b6f1 | 1442 | { |
39bffca2 AL |
1443 | type_register_static(&piix3_uhci_info); |
1444 | type_register_static(&piix4_uhci_info); | |
1445 | type_register_static(&vt82c686b_uhci_info); | |
1446 | type_register_static(&ich9_uhci1_info); | |
1447 | type_register_static(&ich9_uhci2_info); | |
1448 | type_register_static(&ich9_uhci3_info); | |
6cf9b6f1 | 1449 | } |
83f7d43a AF |
1450 | |
1451 | type_init(uhci_register_types) |