2 * USB xHCI controller emulation
4 * Copyright (c) 2011 Securiforest
5 * Date: 2011-05-11 ; Author: Hector Martin <hector@marcansoft.com>
6 * Based on usb-ohci.c, emulates Renesas NEC USB 3.0
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
22 #include "qemu-timer.h"
32 #define DPRINTF(...) fprintf(stderr, __VA_ARGS__)
34 #define DPRINTF(...) do {} while (0)
36 #define FIXME() do { fprintf(stderr, "FIXME %s:%d\n", \
37 __func__, __LINE__); abort(); } while (0)
45 #define MAXPORTS (USB2_PORTS+USB3_PORTS)
49 /* Very pessimistic, let's hope it's enough for all cases */
50 #define EV_QUEUE (((3*TD_QUEUE)+16)*MAXSLOTS)
51 /* Do not deliver ER Full events. NEC's driver does some things not bound
52 * to the specs when it gets them */
56 #define OFF_OPER LEN_CAP
57 #define LEN_OPER (0x400 + 0x10 * MAXPORTS)
58 #define OFF_RUNTIME ((OFF_OPER + LEN_OPER + 0x20) & ~0x1f)
59 #define LEN_RUNTIME (0x20 + MAXINTRS * 0x20)
60 #define OFF_DOORBELL (OFF_RUNTIME + LEN_RUNTIME)
61 #define LEN_DOORBELL ((MAXSLOTS + 1) * 0x20)
63 /* must be power of 2 */
64 #define LEN_REGS 0x2000
66 #if (OFF_DOORBELL + LEN_DOORBELL) > LEN_REGS
67 # error Increase LEN_REGS
71 # error TODO: only one interrupter supported
75 #define USBCMD_RS (1<<0)
76 #define USBCMD_HCRST (1<<1)
77 #define USBCMD_INTE (1<<2)
78 #define USBCMD_HSEE (1<<3)
79 #define USBCMD_LHCRST (1<<7)
80 #define USBCMD_CSS (1<<8)
81 #define USBCMD_CRS (1<<9)
82 #define USBCMD_EWE (1<<10)
83 #define USBCMD_EU3S (1<<11)
85 #define USBSTS_HCH (1<<0)
86 #define USBSTS_HSE (1<<2)
87 #define USBSTS_EINT (1<<3)
88 #define USBSTS_PCD (1<<4)
89 #define USBSTS_SSS (1<<8)
90 #define USBSTS_RSS (1<<9)
91 #define USBSTS_SRE (1<<10)
92 #define USBSTS_CNR (1<<11)
93 #define USBSTS_HCE (1<<12)
96 #define PORTSC_CCS (1<<0)
97 #define PORTSC_PED (1<<1)
98 #define PORTSC_OCA (1<<3)
99 #define PORTSC_PR (1<<4)
100 #define PORTSC_PLS_SHIFT 5
101 #define PORTSC_PLS_MASK 0xf
102 #define PORTSC_PP (1<<9)
103 #define PORTSC_SPEED_SHIFT 10
104 #define PORTSC_SPEED_MASK 0xf
105 #define PORTSC_SPEED_FULL (1<<10)
106 #define PORTSC_SPEED_LOW (2<<10)
107 #define PORTSC_SPEED_HIGH (3<<10)
108 #define PORTSC_SPEED_SUPER (4<<10)
109 #define PORTSC_PIC_SHIFT 14
110 #define PORTSC_PIC_MASK 0x3
111 #define PORTSC_LWS (1<<16)
112 #define PORTSC_CSC (1<<17)
113 #define PORTSC_PEC (1<<18)
114 #define PORTSC_WRC (1<<19)
115 #define PORTSC_OCC (1<<20)
116 #define PORTSC_PRC (1<<21)
117 #define PORTSC_PLC (1<<22)
118 #define PORTSC_CEC (1<<23)
119 #define PORTSC_CAS (1<<24)
120 #define PORTSC_WCE (1<<25)
121 #define PORTSC_WDE (1<<26)
122 #define PORTSC_WOE (1<<27)
123 #define PORTSC_DR (1<<30)
124 #define PORTSC_WPR (1<<31)
126 #define CRCR_RCS (1<<0)
127 #define CRCR_CS (1<<1)
128 #define CRCR_CA (1<<2)
129 #define CRCR_CRR (1<<3)
131 #define IMAN_IP (1<<0)
132 #define IMAN_IE (1<<1)
134 #define ERDP_EHB (1<<3)
137 typedef struct XHCITRB
{
146 typedef enum TRBType
{
159 CR_CONFIGURE_ENDPOINT
,
167 CR_SET_LATENCY_TOLERANCE
,
168 CR_GET_PORT_BANDWIDTH
,
173 ER_PORT_STATUS_CHANGE
,
174 ER_BANDWIDTH_REQUEST
,
177 ER_DEVICE_NOTIFICATION
,
179 /* vendor specific bits */
180 CR_VENDOR_VIA_CHALLENGE_RESPONSE
= 48,
181 CR_VENDOR_NEC_FIRMWARE_REVISION
= 49,
182 CR_VENDOR_NEC_CHALLENGE_RESPONSE
= 50,
185 #define CR_LINK TR_LINK
187 typedef enum TRBCCode
{
190 CC_DATA_BUFFER_ERROR
,
192 CC_USB_TRANSACTION_ERROR
,
198 CC_INVALID_STREAM_TYPE_ERROR
,
199 CC_SLOT_NOT_ENABLED_ERROR
,
200 CC_EP_NOT_ENABLED_ERROR
,
206 CC_BANDWIDTH_OVERRUN
,
207 CC_CONTEXT_STATE_ERROR
,
208 CC_NO_PING_RESPONSE_ERROR
,
209 CC_EVENT_RING_FULL_ERROR
,
210 CC_INCOMPATIBLE_DEVICE_ERROR
,
211 CC_MISSED_SERVICE_ERROR
,
212 CC_COMMAND_RING_STOPPED
,
215 CC_STOPPED_LENGTH_INVALID
,
216 CC_MAX_EXIT_LATENCY_TOO_LARGE_ERROR
= 29,
217 CC_ISOCH_BUFFER_OVERRUN
= 31,
220 CC_INVALID_STREAM_ID_ERROR
,
221 CC_SECONDARY_BANDWIDTH_ERROR
,
222 CC_SPLIT_TRANSACTION_ERROR
226 #define TRB_TYPE_SHIFT 10
227 #define TRB_TYPE_MASK 0x3f
228 #define TRB_TYPE(t) (((t).control >> TRB_TYPE_SHIFT) & TRB_TYPE_MASK)
230 #define TRB_EV_ED (1<<2)
232 #define TRB_TR_ENT (1<<1)
233 #define TRB_TR_ISP (1<<2)
234 #define TRB_TR_NS (1<<3)
235 #define TRB_TR_CH (1<<4)
236 #define TRB_TR_IOC (1<<5)
237 #define TRB_TR_IDT (1<<6)
238 #define TRB_TR_TBC_SHIFT 7
239 #define TRB_TR_TBC_MASK 0x3
240 #define TRB_TR_BEI (1<<9)
241 #define TRB_TR_TLBPC_SHIFT 16
242 #define TRB_TR_TLBPC_MASK 0xf
243 #define TRB_TR_FRAMEID_SHIFT 20
244 #define TRB_TR_FRAMEID_MASK 0x7ff
245 #define TRB_TR_SIA (1<<31)
247 #define TRB_TR_DIR (1<<16)
249 #define TRB_CR_SLOTID_SHIFT 24
250 #define TRB_CR_SLOTID_MASK 0xff
251 #define TRB_CR_EPID_SHIFT 16
252 #define TRB_CR_EPID_MASK 0x1f
254 #define TRB_CR_BSR (1<<9)
255 #define TRB_CR_DC (1<<9)
257 #define TRB_LK_TC (1<<1)
259 #define EP_TYPE_MASK 0x7
260 #define EP_TYPE_SHIFT 3
262 #define EP_STATE_MASK 0x7
263 #define EP_DISABLED (0<<0)
264 #define EP_RUNNING (1<<0)
265 #define EP_HALTED (2<<0)
266 #define EP_STOPPED (3<<0)
267 #define EP_ERROR (4<<0)
269 #define SLOT_STATE_MASK 0x1f
270 #define SLOT_STATE_SHIFT 27
271 #define SLOT_STATE(s) (((s)>>SLOT_STATE_SHIFT)&SLOT_STATE_MASK)
272 #define SLOT_ENABLED 0
273 #define SLOT_DEFAULT 1
274 #define SLOT_ADDRESSED 2
275 #define SLOT_CONFIGURED 3
277 #define SLOT_CONTEXT_ENTRIES_MASK 0x1f
278 #define SLOT_CONTEXT_ENTRIES_SHIFT 27
280 typedef enum EPType
{
291 typedef struct XHCIRing
{
297 typedef struct XHCIPort
{
303 typedef struct XHCIState XHCIState
;
305 typedef struct XHCITransfer
{
313 unsigned int iso_pkts
;
319 unsigned int trb_count
;
320 unsigned int trb_alloced
;
326 unsigned int pktsize
;
327 unsigned int cur_pkt
;
329 uint64_t mfindex_kick
;
332 typedef struct XHCIEPContext
{
338 unsigned int next_xfer
;
339 unsigned int comp_xfer
;
340 XHCITransfer transfers
[TD_QUEUE
];
344 unsigned int max_psize
;
347 /* iso xfer scheduling */
348 unsigned int interval
;
349 int64_t mfindex_last
;
350 QEMUTimer
*kick_timer
;
353 typedef struct XHCISlot
{
357 unsigned int devaddr
;
358 XHCIEPContext
* eps
[31];
361 typedef struct XHCIEvent
{
378 unsigned int devaddr
;
380 /* Operational Registers */
387 uint32_t dcbaap_high
;
390 XHCIPort ports
[MAXPORTS
];
391 XHCISlot slots
[MAXSLOTS
];
393 /* Runtime Registers */
398 uint32_t erstba_high
;
402 int64_t mfindex_start
;
403 QEMUTimer
*mfwrap_timer
;
408 unsigned int er_ep_idx
;
411 XHCIEvent ev_buffer
[EV_QUEUE
];
412 unsigned int ev_buffer_put
;
413 unsigned int ev_buffer_get
;
418 typedef struct XHCIEvRingSeg
{
425 static void xhci_kick_ep(XHCIState
*xhci
, unsigned int slotid
,
427 static void xhci_event(XHCIState
*xhci
, XHCIEvent
*event
);
428 static void xhci_write_event(XHCIState
*xhci
, XHCIEvent
*event
);
430 static const char *TRBType_names
[] = {
431 [TRB_RESERVED
] = "TRB_RESERVED",
432 [TR_NORMAL
] = "TR_NORMAL",
433 [TR_SETUP
] = "TR_SETUP",
434 [TR_DATA
] = "TR_DATA",
435 [TR_STATUS
] = "TR_STATUS",
436 [TR_ISOCH
] = "TR_ISOCH",
437 [TR_LINK
] = "TR_LINK",
438 [TR_EVDATA
] = "TR_EVDATA",
439 [TR_NOOP
] = "TR_NOOP",
440 [CR_ENABLE_SLOT
] = "CR_ENABLE_SLOT",
441 [CR_DISABLE_SLOT
] = "CR_DISABLE_SLOT",
442 [CR_ADDRESS_DEVICE
] = "CR_ADDRESS_DEVICE",
443 [CR_CONFIGURE_ENDPOINT
] = "CR_CONFIGURE_ENDPOINT",
444 [CR_EVALUATE_CONTEXT
] = "CR_EVALUATE_CONTEXT",
445 [CR_RESET_ENDPOINT
] = "CR_RESET_ENDPOINT",
446 [CR_STOP_ENDPOINT
] = "CR_STOP_ENDPOINT",
447 [CR_SET_TR_DEQUEUE
] = "CR_SET_TR_DEQUEUE",
448 [CR_RESET_DEVICE
] = "CR_RESET_DEVICE",
449 [CR_FORCE_EVENT
] = "CR_FORCE_EVENT",
450 [CR_NEGOTIATE_BW
] = "CR_NEGOTIATE_BW",
451 [CR_SET_LATENCY_TOLERANCE
] = "CR_SET_LATENCY_TOLERANCE",
452 [CR_GET_PORT_BANDWIDTH
] = "CR_GET_PORT_BANDWIDTH",
453 [CR_FORCE_HEADER
] = "CR_FORCE_HEADER",
454 [CR_NOOP
] = "CR_NOOP",
455 [ER_TRANSFER
] = "ER_TRANSFER",
456 [ER_COMMAND_COMPLETE
] = "ER_COMMAND_COMPLETE",
457 [ER_PORT_STATUS_CHANGE
] = "ER_PORT_STATUS_CHANGE",
458 [ER_BANDWIDTH_REQUEST
] = "ER_BANDWIDTH_REQUEST",
459 [ER_DOORBELL
] = "ER_DOORBELL",
460 [ER_HOST_CONTROLLER
] = "ER_HOST_CONTROLLER",
461 [ER_DEVICE_NOTIFICATION
] = "ER_DEVICE_NOTIFICATION",
462 [ER_MFINDEX_WRAP
] = "ER_MFINDEX_WRAP",
463 [CR_VENDOR_VIA_CHALLENGE_RESPONSE
] = "CR_VENDOR_VIA_CHALLENGE_RESPONSE",
464 [CR_VENDOR_NEC_FIRMWARE_REVISION
] = "CR_VENDOR_NEC_FIRMWARE_REVISION",
465 [CR_VENDOR_NEC_CHALLENGE_RESPONSE
] = "CR_VENDOR_NEC_CHALLENGE_RESPONSE",
468 static const char *lookup_name(uint32_t index
, const char **list
, uint32_t llen
)
470 if (index
>= llen
|| list
[index
] == NULL
) {
476 static const char *trb_name(XHCITRB
*trb
)
478 return lookup_name(TRB_TYPE(*trb
), TRBType_names
,
479 ARRAY_SIZE(TRBType_names
));
482 static uint64_t xhci_mfindex_get(XHCIState
*xhci
)
484 int64_t now
= qemu_get_clock_ns(vm_clock
);
485 return (now
- xhci
->mfindex_start
) / 125000;
488 static void xhci_mfwrap_update(XHCIState
*xhci
)
490 const uint32_t bits
= USBCMD_RS
| USBCMD_EWE
;
491 uint32_t mfindex
, left
;
494 if ((xhci
->usbcmd
& bits
) == bits
) {
495 now
= qemu_get_clock_ns(vm_clock
);
496 mfindex
= ((now
- xhci
->mfindex_start
) / 125000) & 0x3fff;
497 left
= 0x4000 - mfindex
;
498 qemu_mod_timer(xhci
->mfwrap_timer
, now
+ left
* 125000);
500 qemu_del_timer(xhci
->mfwrap_timer
);
504 static void xhci_mfwrap_timer(void *opaque
)
506 XHCIState
*xhci
= opaque
;
507 XHCIEvent wrap
= { ER_MFINDEX_WRAP
, CC_SUCCESS
};
509 xhci_event(xhci
, &wrap
);
510 xhci_mfwrap_update(xhci
);
513 static inline dma_addr_t
xhci_addr64(uint32_t low
, uint32_t high
)
515 if (sizeof(dma_addr_t
) == 4) {
518 return low
| (((dma_addr_t
)high
<< 16) << 16);
522 static inline dma_addr_t
xhci_mask64(uint64_t addr
)
524 if (sizeof(dma_addr_t
) == 4) {
525 return addr
& 0xffffffff;
531 static void xhci_irq_update(XHCIState
*xhci
)
535 if (xhci
->iman
& IMAN_IP
&& xhci
->iman
& IMAN_IE
&&
536 xhci
->usbcmd
& USBCMD_INTE
) {
540 if (xhci
->msi
&& msi_enabled(&xhci
->pci_dev
)) {
542 trace_usb_xhci_irq_msi(0);
543 msi_notify(&xhci
->pci_dev
, 0);
546 trace_usb_xhci_irq_intx(level
);
547 qemu_set_irq(xhci
->irq
, level
);
551 static inline int xhci_running(XHCIState
*xhci
)
553 return !(xhci
->usbsts
& USBSTS_HCH
) && !xhci
->er_full
;
556 static void xhci_die(XHCIState
*xhci
)
558 xhci
->usbsts
|= USBSTS_HCE
;
559 fprintf(stderr
, "xhci: asserted controller error\n");
562 static void xhci_write_event(XHCIState
*xhci
, XHCIEvent
*event
)
567 ev_trb
.parameter
= cpu_to_le64(event
->ptr
);
568 ev_trb
.status
= cpu_to_le32(event
->length
| (event
->ccode
<< 24));
569 ev_trb
.control
= (event
->slotid
<< 24) | (event
->epid
<< 16) |
570 event
->flags
| (event
->type
<< TRB_TYPE_SHIFT
);
572 ev_trb
.control
|= TRB_C
;
574 ev_trb
.control
= cpu_to_le32(ev_trb
.control
);
576 trace_usb_xhci_queue_event(xhci
->er_ep_idx
, trb_name(&ev_trb
),
577 ev_trb
.parameter
, ev_trb
.status
, ev_trb
.control
);
579 addr
= xhci
->er_start
+ TRB_SIZE
*xhci
->er_ep_idx
;
580 pci_dma_write(&xhci
->pci_dev
, addr
, &ev_trb
, TRB_SIZE
);
583 if (xhci
->er_ep_idx
>= xhci
->er_size
) {
585 xhci
->er_pcs
= !xhci
->er_pcs
;
589 static void xhci_events_update(XHCIState
*xhci
)
595 if (xhci
->usbsts
& USBSTS_HCH
) {
599 erdp
= xhci_addr64(xhci
->erdp_low
, xhci
->erdp_high
);
600 if (erdp
< xhci
->er_start
||
601 erdp
>= (xhci
->er_start
+ TRB_SIZE
*xhci
->er_size
)) {
602 fprintf(stderr
, "xhci: ERDP out of bounds: "DMA_ADDR_FMT
"\n", erdp
);
603 fprintf(stderr
, "xhci: ER at "DMA_ADDR_FMT
" len %d\n",
604 xhci
->er_start
, xhci
->er_size
);
608 dp_idx
= (erdp
- xhci
->er_start
) / TRB_SIZE
;
609 assert(dp_idx
< xhci
->er_size
);
611 /* NEC didn't read section 4.9.4 of the spec (v1.0 p139 top Note) and thus
612 * deadlocks when the ER is full. Hack it by holding off events until
613 * the driver decides to free at least half of the ring */
615 int er_free
= dp_idx
- xhci
->er_ep_idx
;
617 er_free
+= xhci
->er_size
;
619 if (er_free
< (xhci
->er_size
/2)) {
620 DPRINTF("xhci_events_update(): event ring still "
621 "more than half full (hack)\n");
626 while (xhci
->ev_buffer_put
!= xhci
->ev_buffer_get
) {
627 assert(xhci
->er_full
);
628 if (((xhci
->er_ep_idx
+1) % xhci
->er_size
) == dp_idx
) {
629 DPRINTF("xhci_events_update(): event ring full again\n");
631 XHCIEvent full
= {ER_HOST_CONTROLLER
, CC_EVENT_RING_FULL_ERROR
};
632 xhci_write_event(xhci
, &full
);
637 XHCIEvent
*event
= &xhci
->ev_buffer
[xhci
->ev_buffer_get
];
638 xhci_write_event(xhci
, event
);
639 xhci
->ev_buffer_get
++;
641 if (xhci
->ev_buffer_get
== EV_QUEUE
) {
642 xhci
->ev_buffer_get
= 0;
647 xhci
->erdp_low
|= ERDP_EHB
;
648 xhci
->iman
|= IMAN_IP
;
649 xhci
->usbsts
|= USBSTS_EINT
;
650 xhci_irq_update(xhci
);
653 if (xhci
->er_full
&& xhci
->ev_buffer_put
== xhci
->ev_buffer_get
) {
654 DPRINTF("xhci_events_update(): event ring no longer full\n");
660 static void xhci_event(XHCIState
*xhci
, XHCIEvent
*event
)
666 DPRINTF("xhci_event(): ER full, queueing\n");
667 if (((xhci
->ev_buffer_put
+1) % EV_QUEUE
) == xhci
->ev_buffer_get
) {
668 fprintf(stderr
, "xhci: event queue full, dropping event!\n");
671 xhci
->ev_buffer
[xhci
->ev_buffer_put
++] = *event
;
672 if (xhci
->ev_buffer_put
== EV_QUEUE
) {
673 xhci
->ev_buffer_put
= 0;
678 erdp
= xhci_addr64(xhci
->erdp_low
, xhci
->erdp_high
);
679 if (erdp
< xhci
->er_start
||
680 erdp
>= (xhci
->er_start
+ TRB_SIZE
*xhci
->er_size
)) {
681 fprintf(stderr
, "xhci: ERDP out of bounds: "DMA_ADDR_FMT
"\n", erdp
);
682 fprintf(stderr
, "xhci: ER at "DMA_ADDR_FMT
" len %d\n",
683 xhci
->er_start
, xhci
->er_size
);
688 dp_idx
= (erdp
- xhci
->er_start
) / TRB_SIZE
;
689 assert(dp_idx
< xhci
->er_size
);
691 if ((xhci
->er_ep_idx
+1) % xhci
->er_size
== dp_idx
) {
692 DPRINTF("xhci_event(): ER full, queueing\n");
694 XHCIEvent full
= {ER_HOST_CONTROLLER
, CC_EVENT_RING_FULL_ERROR
};
695 xhci_write_event(xhci
, &full
);
698 if (((xhci
->ev_buffer_put
+1) % EV_QUEUE
) == xhci
->ev_buffer_get
) {
699 fprintf(stderr
, "xhci: event queue full, dropping event!\n");
702 xhci
->ev_buffer
[xhci
->ev_buffer_put
++] = *event
;
703 if (xhci
->ev_buffer_put
== EV_QUEUE
) {
704 xhci
->ev_buffer_put
= 0;
707 xhci_write_event(xhci
, event
);
710 xhci
->erdp_low
|= ERDP_EHB
;
711 xhci
->iman
|= IMAN_IP
;
712 xhci
->usbsts
|= USBSTS_EINT
;
714 xhci_irq_update(xhci
);
717 static void xhci_ring_init(XHCIState
*xhci
, XHCIRing
*ring
,
721 ring
->dequeue
= base
;
725 static TRBType
xhci_ring_fetch(XHCIState
*xhci
, XHCIRing
*ring
, XHCITRB
*trb
,
730 pci_dma_read(&xhci
->pci_dev
, ring
->dequeue
, trb
, TRB_SIZE
);
731 trb
->addr
= ring
->dequeue
;
732 trb
->ccs
= ring
->ccs
;
733 le64_to_cpus(&trb
->parameter
);
734 le32_to_cpus(&trb
->status
);
735 le32_to_cpus(&trb
->control
);
737 trace_usb_xhci_fetch_trb(ring
->dequeue
, trb_name(trb
),
738 trb
->parameter
, trb
->status
, trb
->control
);
740 if ((trb
->control
& TRB_C
) != ring
->ccs
) {
744 type
= TRB_TYPE(*trb
);
746 if (type
!= TR_LINK
) {
748 *addr
= ring
->dequeue
;
750 ring
->dequeue
+= TRB_SIZE
;
753 ring
->dequeue
= xhci_mask64(trb
->parameter
);
754 if (trb
->control
& TRB_LK_TC
) {
755 ring
->ccs
= !ring
->ccs
;
761 static int xhci_ring_chain_length(XHCIState
*xhci
, const XHCIRing
*ring
)
765 dma_addr_t dequeue
= ring
->dequeue
;
766 bool ccs
= ring
->ccs
;
767 /* hack to bundle together the two/three TDs that make a setup transfer */
768 bool control_td_set
= 0;
772 pci_dma_read(&xhci
->pci_dev
, dequeue
, &trb
, TRB_SIZE
);
773 le64_to_cpus(&trb
.parameter
);
774 le32_to_cpus(&trb
.status
);
775 le32_to_cpus(&trb
.control
);
777 if ((trb
.control
& TRB_C
) != ccs
) {
781 type
= TRB_TYPE(trb
);
783 if (type
== TR_LINK
) {
784 dequeue
= xhci_mask64(trb
.parameter
);
785 if (trb
.control
& TRB_LK_TC
) {
794 if (type
== TR_SETUP
) {
796 } else if (type
== TR_STATUS
) {
800 if (!control_td_set
&& !(trb
.control
& TRB_TR_CH
)) {
806 static void xhci_er_reset(XHCIState
*xhci
)
810 /* cache the (sole) event ring segment location */
811 if (xhci
->erstsz
!= 1) {
812 fprintf(stderr
, "xhci: invalid value for ERSTSZ: %d\n", xhci
->erstsz
);
816 dma_addr_t erstba
= xhci_addr64(xhci
->erstba_low
, xhci
->erstba_high
);
817 pci_dma_read(&xhci
->pci_dev
, erstba
, &seg
, sizeof(seg
));
818 le32_to_cpus(&seg
.addr_low
);
819 le32_to_cpus(&seg
.addr_high
);
820 le32_to_cpus(&seg
.size
);
821 if (seg
.size
< 16 || seg
.size
> 4096) {
822 fprintf(stderr
, "xhci: invalid value for segment size: %d\n", seg
.size
);
826 xhci
->er_start
= xhci_addr64(seg
.addr_low
, seg
.addr_high
);
827 xhci
->er_size
= seg
.size
;
833 DPRINTF("xhci: event ring:" DMA_ADDR_FMT
" [%d]\n",
834 xhci
->er_start
, xhci
->er_size
);
837 static void xhci_run(XHCIState
*xhci
)
839 trace_usb_xhci_run();
840 xhci
->usbsts
&= ~USBSTS_HCH
;
841 xhci
->mfindex_start
= qemu_get_clock_ns(vm_clock
);
844 static void xhci_stop(XHCIState
*xhci
)
846 trace_usb_xhci_stop();
847 xhci
->usbsts
|= USBSTS_HCH
;
848 xhci
->crcr_low
&= ~CRCR_CRR
;
851 static void xhci_set_ep_state(XHCIState
*xhci
, XHCIEPContext
*epctx
,
855 if (epctx
->state
== state
) {
859 pci_dma_read(&xhci
->pci_dev
, epctx
->pctx
, ctx
, sizeof(ctx
));
860 ctx
[0] &= ~EP_STATE_MASK
;
862 ctx
[2] = epctx
->ring
.dequeue
| epctx
->ring
.ccs
;
863 ctx
[3] = (epctx
->ring
.dequeue
>> 16) >> 16;
864 DPRINTF("xhci: set epctx: " DMA_ADDR_FMT
" state=%d dequeue=%08x%08x\n",
865 epctx
->pctx
, state
, ctx
[3], ctx
[2]);
866 pci_dma_write(&xhci
->pci_dev
, epctx
->pctx
, ctx
, sizeof(ctx
));
867 epctx
->state
= state
;
870 static void xhci_ep_kick_timer(void *opaque
)
872 XHCIEPContext
*epctx
= opaque
;
873 xhci_kick_ep(epctx
->xhci
, epctx
->slotid
, epctx
->epid
);
876 static TRBCCode
xhci_enable_ep(XHCIState
*xhci
, unsigned int slotid
,
877 unsigned int epid
, dma_addr_t pctx
,
881 XHCIEPContext
*epctx
;
885 trace_usb_xhci_ep_enable(slotid
, epid
);
886 assert(slotid
>= 1 && slotid
<= MAXSLOTS
);
887 assert(epid
>= 1 && epid
<= 31);
889 slot
= &xhci
->slots
[slotid
-1];
890 if (slot
->eps
[epid
-1]) {
891 fprintf(stderr
, "xhci: slot %d ep %d already enabled!\n", slotid
, epid
);
895 epctx
= g_malloc(sizeof(XHCIEPContext
));
896 memset(epctx
, 0, sizeof(XHCIEPContext
));
898 epctx
->slotid
= slotid
;
901 slot
->eps
[epid
-1] = epctx
;
903 dequeue
= xhci_addr64(ctx
[2] & ~0xf, ctx
[3]);
904 xhci_ring_init(xhci
, &epctx
->ring
, dequeue
);
905 epctx
->ring
.ccs
= ctx
[2] & 1;
907 epctx
->type
= (ctx
[1] >> EP_TYPE_SHIFT
) & EP_TYPE_MASK
;
908 DPRINTF("xhci: endpoint %d.%d type is %d\n", epid
/2, epid
%2, epctx
->type
);
910 epctx
->max_psize
= ctx
[1]>>16;
911 epctx
->max_psize
*= 1+((ctx
[1]>>8)&0xff);
912 DPRINTF("xhci: endpoint %d.%d max transaction (burst) size is %d\n",
913 epid
/2, epid
%2, epctx
->max_psize
);
914 for (i
= 0; i
< ARRAY_SIZE(epctx
->transfers
); i
++) {
915 usb_packet_init(&epctx
->transfers
[i
].packet
);
918 epctx
->interval
= 1 << (ctx
[0] >> 16) & 0xff;
919 epctx
->mfindex_last
= 0;
920 epctx
->kick_timer
= qemu_new_timer_ns(vm_clock
, xhci_ep_kick_timer
, epctx
);
922 epctx
->state
= EP_RUNNING
;
923 ctx
[0] &= ~EP_STATE_MASK
;
924 ctx
[0] |= EP_RUNNING
;
929 static int xhci_ep_nuke_xfers(XHCIState
*xhci
, unsigned int slotid
,
933 XHCIEPContext
*epctx
;
934 int i
, xferi
, killed
= 0;
935 assert(slotid
>= 1 && slotid
<= MAXSLOTS
);
936 assert(epid
>= 1 && epid
<= 31);
938 DPRINTF("xhci_ep_nuke_xfers(%d, %d)\n", slotid
, epid
);
940 slot
= &xhci
->slots
[slotid
-1];
942 if (!slot
->eps
[epid
-1]) {
946 epctx
= slot
->eps
[epid
-1];
948 xferi
= epctx
->next_xfer
;
949 for (i
= 0; i
< TD_QUEUE
; i
++) {
950 XHCITransfer
*t
= &epctx
->transfers
[xferi
];
951 if (t
->running_async
) {
952 usb_cancel_packet(&t
->packet
);
953 t
->running_async
= 0;
955 DPRINTF("xhci: cancelling transfer %d, waiting for it to complete...\n", i
);
958 if (t
->running_retry
) {
959 t
->running_retry
= 0;
961 qemu_del_timer(epctx
->kick_timer
);
968 t
->trb_count
= t
->trb_alloced
= 0;
969 xferi
= (xferi
+ 1) % TD_QUEUE
;
974 static TRBCCode
xhci_disable_ep(XHCIState
*xhci
, unsigned int slotid
,
978 XHCIEPContext
*epctx
;
980 trace_usb_xhci_ep_disable(slotid
, epid
);
981 assert(slotid
>= 1 && slotid
<= MAXSLOTS
);
982 assert(epid
>= 1 && epid
<= 31);
984 slot
= &xhci
->slots
[slotid
-1];
986 if (!slot
->eps
[epid
-1]) {
987 DPRINTF("xhci: slot %d ep %d already disabled\n", slotid
, epid
);
991 xhci_ep_nuke_xfers(xhci
, slotid
, epid
);
993 epctx
= slot
->eps
[epid
-1];
995 xhci_set_ep_state(xhci
, epctx
, EP_DISABLED
);
997 qemu_free_timer(epctx
->kick_timer
);
999 slot
->eps
[epid
-1] = NULL
;
1004 static TRBCCode
xhci_stop_ep(XHCIState
*xhci
, unsigned int slotid
,
1008 XHCIEPContext
*epctx
;
1010 trace_usb_xhci_ep_stop(slotid
, epid
);
1011 assert(slotid
>= 1 && slotid
<= MAXSLOTS
);
1013 if (epid
< 1 || epid
> 31) {
1014 fprintf(stderr
, "xhci: bad ep %d\n", epid
);
1015 return CC_TRB_ERROR
;
1018 slot
= &xhci
->slots
[slotid
-1];
1020 if (!slot
->eps
[epid
-1]) {
1021 DPRINTF("xhci: slot %d ep %d not enabled\n", slotid
, epid
);
1022 return CC_EP_NOT_ENABLED_ERROR
;
1025 if (xhci_ep_nuke_xfers(xhci
, slotid
, epid
) > 0) {
1026 fprintf(stderr
, "xhci: FIXME: endpoint stopped w/ xfers running, "
1027 "data might be lost\n");
1030 epctx
= slot
->eps
[epid
-1];
1032 xhci_set_ep_state(xhci
, epctx
, EP_STOPPED
);
1037 static TRBCCode
xhci_reset_ep(XHCIState
*xhci
, unsigned int slotid
,
1041 XHCIEPContext
*epctx
;
1044 trace_usb_xhci_ep_reset(slotid
, epid
);
1045 assert(slotid
>= 1 && slotid
<= MAXSLOTS
);
1047 if (epid
< 1 || epid
> 31) {
1048 fprintf(stderr
, "xhci: bad ep %d\n", epid
);
1049 return CC_TRB_ERROR
;
1052 slot
= &xhci
->slots
[slotid
-1];
1054 if (!slot
->eps
[epid
-1]) {
1055 DPRINTF("xhci: slot %d ep %d not enabled\n", slotid
, epid
);
1056 return CC_EP_NOT_ENABLED_ERROR
;
1059 epctx
= slot
->eps
[epid
-1];
1061 if (epctx
->state
!= EP_HALTED
) {
1062 fprintf(stderr
, "xhci: reset EP while EP %d not halted (%d)\n",
1063 epid
, epctx
->state
);
1064 return CC_CONTEXT_STATE_ERROR
;
1067 if (xhci_ep_nuke_xfers(xhci
, slotid
, epid
) > 0) {
1068 fprintf(stderr
, "xhci: FIXME: endpoint reset w/ xfers running, "
1069 "data might be lost\n");
1072 uint8_t ep
= epid
>>1;
1078 dev
= xhci
->ports
[xhci
->slots
[slotid
-1].port
-1].port
.dev
;
1080 return CC_USB_TRANSACTION_ERROR
;
1083 xhci_set_ep_state(xhci
, epctx
, EP_STOPPED
);
1088 static TRBCCode
xhci_set_ep_dequeue(XHCIState
*xhci
, unsigned int slotid
,
1089 unsigned int epid
, uint64_t pdequeue
)
1092 XHCIEPContext
*epctx
;
1095 assert(slotid
>= 1 && slotid
<= MAXSLOTS
);
1097 if (epid
< 1 || epid
> 31) {
1098 fprintf(stderr
, "xhci: bad ep %d\n", epid
);
1099 return CC_TRB_ERROR
;
1102 DPRINTF("xhci_set_ep_dequeue(%d, %d, %016"PRIx64
")\n", slotid
, epid
, pdequeue
);
1103 dequeue
= xhci_mask64(pdequeue
);
1105 slot
= &xhci
->slots
[slotid
-1];
1107 if (!slot
->eps
[epid
-1]) {
1108 DPRINTF("xhci: slot %d ep %d not enabled\n", slotid
, epid
);
1109 return CC_EP_NOT_ENABLED_ERROR
;
1112 epctx
= slot
->eps
[epid
-1];
1115 if (epctx
->state
!= EP_STOPPED
) {
1116 fprintf(stderr
, "xhci: set EP dequeue pointer while EP %d not stopped\n", epid
);
1117 return CC_CONTEXT_STATE_ERROR
;
1120 xhci_ring_init(xhci
, &epctx
->ring
, dequeue
& ~0xF);
1121 epctx
->ring
.ccs
= dequeue
& 1;
1123 xhci_set_ep_state(xhci
, epctx
, EP_STOPPED
);
1128 static int xhci_xfer_map(XHCITransfer
*xfer
)
1130 int in_xfer
= (xfer
->packet
.pid
== USB_TOKEN_IN
);
1131 XHCIState
*xhci
= xfer
->xhci
;
1134 pci_dma_sglist_init(&xfer
->sgl
, &xhci
->pci_dev
, xfer
->trb_count
);
1135 for (i
= 0; i
< xfer
->trb_count
; i
++) {
1136 XHCITRB
*trb
= &xfer
->trbs
[i
];
1138 unsigned int chunk
= 0;
1140 switch (TRB_TYPE(*trb
)) {
1142 if ((!(trb
->control
& TRB_TR_DIR
)) != (!in_xfer
)) {
1143 fprintf(stderr
, "xhci: data direction mismatch for TR_DATA\n");
1149 addr
= xhci_mask64(trb
->parameter
);
1150 chunk
= trb
->status
& 0x1ffff;
1151 if (trb
->control
& TRB_TR_IDT
) {
1152 if (chunk
> 8 || in_xfer
) {
1153 fprintf(stderr
, "xhci: invalid immediate data TRB\n");
1156 qemu_sglist_add(&xfer
->sgl
, trb
->addr
, chunk
);
1158 qemu_sglist_add(&xfer
->sgl
, addr
, chunk
);
1164 usb_packet_map(&xfer
->packet
, &xfer
->sgl
);
1168 qemu_sglist_destroy(&xfer
->sgl
);
1173 static void xhci_xfer_unmap(XHCITransfer
*xfer
)
1175 usb_packet_unmap(&xfer
->packet
, &xfer
->sgl
);
1176 qemu_sglist_destroy(&xfer
->sgl
);
1179 static void xhci_xfer_report(XHCITransfer
*xfer
)
1185 XHCIEvent event
= {ER_TRANSFER
, CC_SUCCESS
};
1186 XHCIState
*xhci
= xfer
->xhci
;
1189 left
= xfer
->packet
.result
< 0 ? 0 : xfer
->packet
.result
;
1191 for (i
= 0; i
< xfer
->trb_count
; i
++) {
1192 XHCITRB
*trb
= &xfer
->trbs
[i
];
1193 unsigned int chunk
= 0;
1195 switch (TRB_TYPE(*trb
)) {
1199 chunk
= trb
->status
& 0x1ffff;
1202 if (xfer
->status
== CC_SUCCESS
) {
1215 if (!reported
&& ((trb
->control
& TRB_TR_IOC
) ||
1216 (shortpkt
&& (trb
->control
& TRB_TR_ISP
)) ||
1217 (xfer
->status
!= CC_SUCCESS
))) {
1218 event
.slotid
= xfer
->slotid
;
1219 event
.epid
= xfer
->epid
;
1220 event
.length
= (trb
->status
& 0x1ffff) - chunk
;
1222 event
.ptr
= trb
->addr
;
1223 if (xfer
->status
== CC_SUCCESS
) {
1224 event
.ccode
= shortpkt
? CC_SHORT_PACKET
: CC_SUCCESS
;
1226 event
.ccode
= xfer
->status
;
1228 if (TRB_TYPE(*trb
) == TR_EVDATA
) {
1229 event
.ptr
= trb
->parameter
;
1230 event
.flags
|= TRB_EV_ED
;
1231 event
.length
= edtla
& 0xffffff;
1232 DPRINTF("xhci_xfer_data: EDTLA=%d\n", event
.length
);
1235 xhci_event(xhci
, &event
);
1237 if (xfer
->status
!= CC_SUCCESS
) {
1244 static void xhci_stall_ep(XHCITransfer
*xfer
)
1246 XHCIState
*xhci
= xfer
->xhci
;
1247 XHCISlot
*slot
= &xhci
->slots
[xfer
->slotid
-1];
1248 XHCIEPContext
*epctx
= slot
->eps
[xfer
->epid
-1];
1250 epctx
->ring
.dequeue
= xfer
->trbs
[0].addr
;
1251 epctx
->ring
.ccs
= xfer
->trbs
[0].ccs
;
1252 xhci_set_ep_state(xhci
, epctx
, EP_HALTED
);
1253 DPRINTF("xhci: stalled slot %d ep %d\n", xfer
->slotid
, xfer
->epid
);
1254 DPRINTF("xhci: will continue at "DMA_ADDR_FMT
"\n", epctx
->ring
.dequeue
);
1257 static int xhci_submit(XHCIState
*xhci
, XHCITransfer
*xfer
,
1258 XHCIEPContext
*epctx
);
1260 static USBDevice
*xhci_find_device(XHCIPort
*port
, uint8_t addr
)
1262 if (!(port
->portsc
& PORTSC_PED
)) {
1265 return usb_find_device(&port
->port
, addr
);
1268 static int xhci_setup_packet(XHCITransfer
*xfer
)
1270 XHCIState
*xhci
= xfer
->xhci
;
1276 dir
= xfer
->in_xfer
? USB_TOKEN_IN
: USB_TOKEN_OUT
;
1278 if (xfer
->packet
.ep
) {
1279 ep
= xfer
->packet
.ep
;
1282 port
= &xhci
->ports
[xhci
->slots
[xfer
->slotid
-1].port
-1];
1283 dev
= xhci_find_device(port
, xhci
->slots
[xfer
->slotid
-1].devaddr
);
1285 fprintf(stderr
, "xhci: slot %d port %d has no device\n",
1286 xfer
->slotid
, xhci
->slots
[xfer
->slotid
-1].port
);
1289 ep
= usb_ep_get(dev
, dir
, xfer
->epid
>> 1);
1292 usb_packet_setup(&xfer
->packet
, dir
, ep
, xfer
->trbs
[0].addr
);
1293 xhci_xfer_map(xfer
);
1294 DPRINTF("xhci: setup packet pid 0x%x addr %d ep %d\n",
1295 xfer
->packet
.pid
, dev
->addr
, ep
->nr
);
1299 static int xhci_complete_packet(XHCITransfer
*xfer
, int ret
)
1301 if (ret
== USB_RET_ASYNC
) {
1302 trace_usb_xhci_xfer_async(xfer
);
1303 xfer
->running_async
= 1;
1304 xfer
->running_retry
= 0;
1306 xfer
->cancelled
= 0;
1308 } else if (ret
== USB_RET_NAK
) {
1309 trace_usb_xhci_xfer_nak(xfer
);
1310 xfer
->running_async
= 0;
1311 xfer
->running_retry
= 1;
1313 xfer
->cancelled
= 0;
1316 xfer
->running_async
= 0;
1317 xfer
->running_retry
= 0;
1319 xhci_xfer_unmap(xfer
);
1323 trace_usb_xhci_xfer_success(xfer
, ret
);
1324 xfer
->status
= CC_SUCCESS
;
1325 xhci_xfer_report(xfer
);
1330 trace_usb_xhci_xfer_error(xfer
, ret
);
1333 xfer
->status
= CC_USB_TRANSACTION_ERROR
;
1334 xhci_xfer_report(xfer
);
1335 xhci_stall_ep(xfer
);
1338 xfer
->status
= CC_STALL_ERROR
;
1339 xhci_xfer_report(xfer
);
1340 xhci_stall_ep(xfer
);
1343 fprintf(stderr
, "%s: FIXME: ret = %d\n", __FUNCTION__
, ret
);
1349 static int xhci_fire_ctl_transfer(XHCIState
*xhci
, XHCITransfer
*xfer
)
1351 XHCITRB
*trb_setup
, *trb_status
;
1352 uint8_t bmRequestType
;
1355 trb_setup
= &xfer
->trbs
[0];
1356 trb_status
= &xfer
->trbs
[xfer
->trb_count
-1];
1358 trace_usb_xhci_xfer_start(xfer
, xfer
->slotid
, xfer
->epid
);
1360 /* at most one Event Data TRB allowed after STATUS */
1361 if (TRB_TYPE(*trb_status
) == TR_EVDATA
&& xfer
->trb_count
> 2) {
1365 /* do some sanity checks */
1366 if (TRB_TYPE(*trb_setup
) != TR_SETUP
) {
1367 fprintf(stderr
, "xhci: ep0 first TD not SETUP: %d\n",
1368 TRB_TYPE(*trb_setup
));
1371 if (TRB_TYPE(*trb_status
) != TR_STATUS
) {
1372 fprintf(stderr
, "xhci: ep0 last TD not STATUS: %d\n",
1373 TRB_TYPE(*trb_status
));
1376 if (!(trb_setup
->control
& TRB_TR_IDT
)) {
1377 fprintf(stderr
, "xhci: Setup TRB doesn't have IDT set\n");
1380 if ((trb_setup
->status
& 0x1ffff) != 8) {
1381 fprintf(stderr
, "xhci: Setup TRB has bad length (%d)\n",
1382 (trb_setup
->status
& 0x1ffff));
1386 bmRequestType
= trb_setup
->parameter
;
1388 xfer
->in_xfer
= bmRequestType
& USB_DIR_IN
;
1389 xfer
->iso_xfer
= false;
1391 if (xhci_setup_packet(xfer
) < 0) {
1394 xfer
->packet
.parameter
= trb_setup
->parameter
;
1396 ret
= usb_handle_packet(xfer
->packet
.ep
->dev
, &xfer
->packet
);
1398 xhci_complete_packet(xfer
, ret
);
1399 if (!xfer
->running_async
&& !xfer
->running_retry
) {
1400 xhci_kick_ep(xhci
, xfer
->slotid
, xfer
->epid
);
1405 static void xhci_calc_iso_kick(XHCIState
*xhci
, XHCITransfer
*xfer
,
1406 XHCIEPContext
*epctx
, uint64_t mfindex
)
1408 if (xfer
->trbs
[0].control
& TRB_TR_SIA
) {
1409 uint64_t asap
= ((mfindex
+ epctx
->interval
- 1) &
1410 ~(epctx
->interval
-1));
1411 if (asap
>= epctx
->mfindex_last
&&
1412 asap
<= epctx
->mfindex_last
+ epctx
->interval
* 4) {
1413 xfer
->mfindex_kick
= epctx
->mfindex_last
+ epctx
->interval
;
1415 xfer
->mfindex_kick
= asap
;
1418 xfer
->mfindex_kick
= (xfer
->trbs
[0].control
>> TRB_TR_FRAMEID_SHIFT
)
1419 & TRB_TR_FRAMEID_MASK
;
1420 xfer
->mfindex_kick
|= mfindex
& ~0x3fff;
1421 if (xfer
->mfindex_kick
< mfindex
) {
1422 xfer
->mfindex_kick
+= 0x4000;
1427 static void xhci_check_iso_kick(XHCIState
*xhci
, XHCITransfer
*xfer
,
1428 XHCIEPContext
*epctx
, uint64_t mfindex
)
1430 if (xfer
->mfindex_kick
> mfindex
) {
1431 qemu_mod_timer(epctx
->kick_timer
, qemu_get_clock_ns(vm_clock
) +
1432 (xfer
->mfindex_kick
- mfindex
) * 125000);
1433 xfer
->running_retry
= 1;
1435 epctx
->mfindex_last
= xfer
->mfindex_kick
;
1436 qemu_del_timer(epctx
->kick_timer
);
1437 xfer
->running_retry
= 0;
1442 static int xhci_submit(XHCIState
*xhci
, XHCITransfer
*xfer
, XHCIEPContext
*epctx
)
1447 DPRINTF("xhci_submit(slotid=%d,epid=%d)\n", xfer
->slotid
, xfer
->epid
);
1449 xfer
->in_xfer
= epctx
->type
>>2;
1451 switch(epctx
->type
) {
1457 xfer
->iso_xfer
= false;
1462 xfer
->iso_xfer
= true;
1463 mfindex
= xhci_mfindex_get(xhci
);
1464 xhci_calc_iso_kick(xhci
, xfer
, epctx
, mfindex
);
1465 xhci_check_iso_kick(xhci
, xfer
, epctx
, mfindex
);
1466 if (xfer
->running_retry
) {
1471 fprintf(stderr
, "xhci: unknown or unhandled EP "
1472 "(type %d, in %d, ep %02x)\n",
1473 epctx
->type
, xfer
->in_xfer
, xfer
->epid
);
1477 if (xhci_setup_packet(xfer
) < 0) {
1480 ret
= usb_handle_packet(xfer
->packet
.ep
->dev
, &xfer
->packet
);
1482 xhci_complete_packet(xfer
, ret
);
1483 if (!xfer
->running_async
&& !xfer
->running_retry
) {
1484 xhci_kick_ep(xhci
, xfer
->slotid
, xfer
->epid
);
1489 static int xhci_fire_transfer(XHCIState
*xhci
, XHCITransfer
*xfer
, XHCIEPContext
*epctx
)
1491 trace_usb_xhci_xfer_start(xfer
, xfer
->slotid
, xfer
->epid
);
1492 return xhci_submit(xhci
, xfer
, epctx
);
1495 static void xhci_kick_ep(XHCIState
*xhci
, unsigned int slotid
, unsigned int epid
)
1497 XHCIEPContext
*epctx
;
1502 trace_usb_xhci_ep_kick(slotid
, epid
);
1503 assert(slotid
>= 1 && slotid
<= MAXSLOTS
);
1504 assert(epid
>= 1 && epid
<= 31);
1506 if (!xhci
->slots
[slotid
-1].enabled
) {
1507 fprintf(stderr
, "xhci: xhci_kick_ep for disabled slot %d\n", slotid
);
1510 epctx
= xhci
->slots
[slotid
-1].eps
[epid
-1];
1512 fprintf(stderr
, "xhci: xhci_kick_ep for disabled endpoint %d,%d\n",
1518 XHCITransfer
*xfer
= epctx
->retry
;
1521 trace_usb_xhci_xfer_retry(xfer
);
1522 assert(xfer
->running_retry
);
1523 if (xfer
->iso_xfer
) {
1524 /* retry delayed iso transfer */
1525 mfindex
= xhci_mfindex_get(xhci
);
1526 xhci_check_iso_kick(xhci
, xfer
, epctx
, mfindex
);
1527 if (xfer
->running_retry
) {
1530 if (xhci_setup_packet(xfer
) < 0) {
1533 result
= usb_handle_packet(xfer
->packet
.ep
->dev
, &xfer
->packet
);
1534 assert(result
!= USB_RET_NAK
);
1535 xhci_complete_packet(xfer
, result
);
1537 /* retry nak'ed transfer */
1538 if (xhci_setup_packet(xfer
) < 0) {
1541 result
= usb_handle_packet(xfer
->packet
.ep
->dev
, &xfer
->packet
);
1542 if (result
== USB_RET_NAK
) {
1545 xhci_complete_packet(xfer
, result
);
1547 assert(!xfer
->running_retry
);
1548 epctx
->retry
= NULL
;
1551 if (epctx
->state
== EP_HALTED
) {
1552 DPRINTF("xhci: ep halted, not running schedule\n");
1556 xhci_set_ep_state(xhci
, epctx
, EP_RUNNING
);
1559 XHCITransfer
*xfer
= &epctx
->transfers
[epctx
->next_xfer
];
1560 if (xfer
->running_async
|| xfer
->running_retry
) {
1563 length
= xhci_ring_chain_length(xhci
, &epctx
->ring
);
1566 } else if (length
== 0) {
1569 if (xfer
->trbs
&& xfer
->trb_alloced
< length
) {
1570 xfer
->trb_count
= 0;
1571 xfer
->trb_alloced
= 0;
1576 xfer
->trbs
= g_malloc(sizeof(XHCITRB
) * length
);
1577 xfer
->trb_alloced
= length
;
1579 xfer
->trb_count
= length
;
1581 for (i
= 0; i
< length
; i
++) {
1582 assert(xhci_ring_fetch(xhci
, &epctx
->ring
, &xfer
->trbs
[i
], NULL
));
1586 xfer
->slotid
= slotid
;
1589 if (xhci_fire_ctl_transfer(xhci
, xfer
) >= 0) {
1590 epctx
->next_xfer
= (epctx
->next_xfer
+ 1) % TD_QUEUE
;
1592 fprintf(stderr
, "xhci: error firing CTL transfer\n");
1595 if (xhci_fire_transfer(xhci
, xfer
, epctx
) >= 0) {
1596 epctx
->next_xfer
= (epctx
->next_xfer
+ 1) % TD_QUEUE
;
1598 if (!xfer
->iso_xfer
) {
1599 fprintf(stderr
, "xhci: error firing data transfer\n");
1604 if (epctx
->state
== EP_HALTED
) {
1607 if (xfer
->running_retry
) {
1608 DPRINTF("xhci: xfer nacked, stopping schedule\n");
1609 epctx
->retry
= xfer
;
1615 static TRBCCode
xhci_enable_slot(XHCIState
*xhci
, unsigned int slotid
)
1617 trace_usb_xhci_slot_enable(slotid
);
1618 assert(slotid
>= 1 && slotid
<= MAXSLOTS
);
1619 xhci
->slots
[slotid
-1].enabled
= 1;
1620 xhci
->slots
[slotid
-1].port
= 0;
1621 memset(xhci
->slots
[slotid
-1].eps
, 0, sizeof(XHCIEPContext
*)*31);
1626 static TRBCCode
xhci_disable_slot(XHCIState
*xhci
, unsigned int slotid
)
1630 trace_usb_xhci_slot_disable(slotid
);
1631 assert(slotid
>= 1 && slotid
<= MAXSLOTS
);
1633 for (i
= 1; i
<= 31; i
++) {
1634 if (xhci
->slots
[slotid
-1].eps
[i
-1]) {
1635 xhci_disable_ep(xhci
, slotid
, i
);
1639 xhci
->slots
[slotid
-1].enabled
= 0;
1643 static TRBCCode
xhci_address_slot(XHCIState
*xhci
, unsigned int slotid
,
1644 uint64_t pictx
, bool bsr
)
1648 dma_addr_t ictx
, octx
, dcbaap
;
1650 uint32_t ictl_ctx
[2];
1651 uint32_t slot_ctx
[4];
1652 uint32_t ep0_ctx
[5];
1657 trace_usb_xhci_slot_address(slotid
);
1658 assert(slotid
>= 1 && slotid
<= MAXSLOTS
);
1660 dcbaap
= xhci_addr64(xhci
->dcbaap_low
, xhci
->dcbaap_high
);
1661 pci_dma_read(&xhci
->pci_dev
, dcbaap
+ 8*slotid
, &poctx
, sizeof(poctx
));
1662 ictx
= xhci_mask64(pictx
);
1663 octx
= xhci_mask64(le64_to_cpu(poctx
));
1665 DPRINTF("xhci: input context at "DMA_ADDR_FMT
"\n", ictx
);
1666 DPRINTF("xhci: output context at "DMA_ADDR_FMT
"\n", octx
);
1668 pci_dma_read(&xhci
->pci_dev
, ictx
, ictl_ctx
, sizeof(ictl_ctx
));
1670 if (ictl_ctx
[0] != 0x0 || ictl_ctx
[1] != 0x3) {
1671 fprintf(stderr
, "xhci: invalid input context control %08x %08x\n",
1672 ictl_ctx
[0], ictl_ctx
[1]);
1673 return CC_TRB_ERROR
;
1676 pci_dma_read(&xhci
->pci_dev
, ictx
+32, slot_ctx
, sizeof(slot_ctx
));
1677 pci_dma_read(&xhci
->pci_dev
, ictx
+64, ep0_ctx
, sizeof(ep0_ctx
));
1679 DPRINTF("xhci: input slot context: %08x %08x %08x %08x\n",
1680 slot_ctx
[0], slot_ctx
[1], slot_ctx
[2], slot_ctx
[3]);
1682 DPRINTF("xhci: input ep0 context: %08x %08x %08x %08x %08x\n",
1683 ep0_ctx
[0], ep0_ctx
[1], ep0_ctx
[2], ep0_ctx
[3], ep0_ctx
[4]);
1685 port
= (slot_ctx
[1]>>16) & 0xFF;
1686 dev
= xhci
->ports
[port
-1].port
.dev
;
1688 if (port
< 1 || port
> MAXPORTS
) {
1689 fprintf(stderr
, "xhci: bad port %d\n", port
);
1690 return CC_TRB_ERROR
;
1692 fprintf(stderr
, "xhci: port %d not connected\n", port
);
1693 return CC_USB_TRANSACTION_ERROR
;
1696 for (i
= 0; i
< MAXSLOTS
; i
++) {
1697 if (xhci
->slots
[i
].port
== port
) {
1698 fprintf(stderr
, "xhci: port %d already assigned to slot %d\n",
1700 return CC_TRB_ERROR
;
1704 slot
= &xhci
->slots
[slotid
-1];
1709 slot_ctx
[3] = SLOT_DEFAULT
<< SLOT_STATE_SHIFT
;
1711 slot
->devaddr
= xhci
->devaddr
++;
1712 slot_ctx
[3] = (SLOT_ADDRESSED
<< SLOT_STATE_SHIFT
) | slot
->devaddr
;
1713 DPRINTF("xhci: device address is %d\n", slot
->devaddr
);
1714 usb_device_handle_control(dev
, NULL
,
1715 DeviceOutRequest
| USB_REQ_SET_ADDRESS
,
1716 slot
->devaddr
, 0, 0, NULL
);
1719 res
= xhci_enable_ep(xhci
, slotid
, 1, octx
+32, ep0_ctx
);
1721 DPRINTF("xhci: output slot context: %08x %08x %08x %08x\n",
1722 slot_ctx
[0], slot_ctx
[1], slot_ctx
[2], slot_ctx
[3]);
1723 DPRINTF("xhci: output ep0 context: %08x %08x %08x %08x %08x\n",
1724 ep0_ctx
[0], ep0_ctx
[1], ep0_ctx
[2], ep0_ctx
[3], ep0_ctx
[4]);
1726 pci_dma_write(&xhci
->pci_dev
, octx
, slot_ctx
, sizeof(slot_ctx
));
1727 pci_dma_write(&xhci
->pci_dev
, octx
+32, ep0_ctx
, sizeof(ep0_ctx
));
1733 static TRBCCode
xhci_configure_slot(XHCIState
*xhci
, unsigned int slotid
,
1734 uint64_t pictx
, bool dc
)
1736 dma_addr_t ictx
, octx
;
1737 uint32_t ictl_ctx
[2];
1738 uint32_t slot_ctx
[4];
1739 uint32_t islot_ctx
[4];
1744 trace_usb_xhci_slot_configure(slotid
);
1745 assert(slotid
>= 1 && slotid
<= MAXSLOTS
);
1747 ictx
= xhci_mask64(pictx
);
1748 octx
= xhci
->slots
[slotid
-1].ctx
;
1750 DPRINTF("xhci: input context at "DMA_ADDR_FMT
"\n", ictx
);
1751 DPRINTF("xhci: output context at "DMA_ADDR_FMT
"\n", octx
);
1754 for (i
= 2; i
<= 31; i
++) {
1755 if (xhci
->slots
[slotid
-1].eps
[i
-1]) {
1756 xhci_disable_ep(xhci
, slotid
, i
);
1760 pci_dma_read(&xhci
->pci_dev
, octx
, slot_ctx
, sizeof(slot_ctx
));
1761 slot_ctx
[3] &= ~(SLOT_STATE_MASK
<< SLOT_STATE_SHIFT
);
1762 slot_ctx
[3] |= SLOT_ADDRESSED
<< SLOT_STATE_SHIFT
;
1763 DPRINTF("xhci: output slot context: %08x %08x %08x %08x\n",
1764 slot_ctx
[0], slot_ctx
[1], slot_ctx
[2], slot_ctx
[3]);
1765 pci_dma_write(&xhci
->pci_dev
, octx
, slot_ctx
, sizeof(slot_ctx
));
1770 pci_dma_read(&xhci
->pci_dev
, ictx
, ictl_ctx
, sizeof(ictl_ctx
));
1772 if ((ictl_ctx
[0] & 0x3) != 0x0 || (ictl_ctx
[1] & 0x3) != 0x1) {
1773 fprintf(stderr
, "xhci: invalid input context control %08x %08x\n",
1774 ictl_ctx
[0], ictl_ctx
[1]);
1775 return CC_TRB_ERROR
;
1778 pci_dma_read(&xhci
->pci_dev
, ictx
+32, islot_ctx
, sizeof(islot_ctx
));
1779 pci_dma_read(&xhci
->pci_dev
, octx
, slot_ctx
, sizeof(slot_ctx
));
1781 if (SLOT_STATE(slot_ctx
[3]) < SLOT_ADDRESSED
) {
1782 fprintf(stderr
, "xhci: invalid slot state %08x\n", slot_ctx
[3]);
1783 return CC_CONTEXT_STATE_ERROR
;
1786 for (i
= 2; i
<= 31; i
++) {
1787 if (ictl_ctx
[0] & (1<<i
)) {
1788 xhci_disable_ep(xhci
, slotid
, i
);
1790 if (ictl_ctx
[1] & (1<<i
)) {
1791 pci_dma_read(&xhci
->pci_dev
, ictx
+32+(32*i
), ep_ctx
,
1793 DPRINTF("xhci: input ep%d.%d context: %08x %08x %08x %08x %08x\n",
1794 i
/2, i
%2, ep_ctx
[0], ep_ctx
[1], ep_ctx
[2],
1795 ep_ctx
[3], ep_ctx
[4]);
1796 xhci_disable_ep(xhci
, slotid
, i
);
1797 res
= xhci_enable_ep(xhci
, slotid
, i
, octx
+(32*i
), ep_ctx
);
1798 if (res
!= CC_SUCCESS
) {
1801 DPRINTF("xhci: output ep%d.%d context: %08x %08x %08x %08x %08x\n",
1802 i
/2, i
%2, ep_ctx
[0], ep_ctx
[1], ep_ctx
[2],
1803 ep_ctx
[3], ep_ctx
[4]);
1804 pci_dma_write(&xhci
->pci_dev
, octx
+(32*i
), ep_ctx
, sizeof(ep_ctx
));
1808 slot_ctx
[3] &= ~(SLOT_STATE_MASK
<< SLOT_STATE_SHIFT
);
1809 slot_ctx
[3] |= SLOT_CONFIGURED
<< SLOT_STATE_SHIFT
;
1810 slot_ctx
[0] &= ~(SLOT_CONTEXT_ENTRIES_MASK
<< SLOT_CONTEXT_ENTRIES_SHIFT
);
1811 slot_ctx
[0] |= islot_ctx
[0] & (SLOT_CONTEXT_ENTRIES_MASK
<<
1812 SLOT_CONTEXT_ENTRIES_SHIFT
);
1813 DPRINTF("xhci: output slot context: %08x %08x %08x %08x\n",
1814 slot_ctx
[0], slot_ctx
[1], slot_ctx
[2], slot_ctx
[3]);
1816 pci_dma_write(&xhci
->pci_dev
, octx
, slot_ctx
, sizeof(slot_ctx
));
1822 static TRBCCode
xhci_evaluate_slot(XHCIState
*xhci
, unsigned int slotid
,
1825 dma_addr_t ictx
, octx
;
1826 uint32_t ictl_ctx
[2];
1827 uint32_t iep0_ctx
[5];
1828 uint32_t ep0_ctx
[5];
1829 uint32_t islot_ctx
[4];
1830 uint32_t slot_ctx
[4];
1832 trace_usb_xhci_slot_evaluate(slotid
);
1833 assert(slotid
>= 1 && slotid
<= MAXSLOTS
);
1835 ictx
= xhci_mask64(pictx
);
1836 octx
= xhci
->slots
[slotid
-1].ctx
;
1838 DPRINTF("xhci: input context at "DMA_ADDR_FMT
"\n", ictx
);
1839 DPRINTF("xhci: output context at "DMA_ADDR_FMT
"\n", octx
);
1841 pci_dma_read(&xhci
->pci_dev
, ictx
, ictl_ctx
, sizeof(ictl_ctx
));
1843 if (ictl_ctx
[0] != 0x0 || ictl_ctx
[1] & ~0x3) {
1844 fprintf(stderr
, "xhci: invalid input context control %08x %08x\n",
1845 ictl_ctx
[0], ictl_ctx
[1]);
1846 return CC_TRB_ERROR
;
1849 if (ictl_ctx
[1] & 0x1) {
1850 pci_dma_read(&xhci
->pci_dev
, ictx
+32, islot_ctx
, sizeof(islot_ctx
));
1852 DPRINTF("xhci: input slot context: %08x %08x %08x %08x\n",
1853 islot_ctx
[0], islot_ctx
[1], islot_ctx
[2], islot_ctx
[3]);
1855 pci_dma_read(&xhci
->pci_dev
, octx
, slot_ctx
, sizeof(slot_ctx
));
1857 slot_ctx
[1] &= ~0xFFFF; /* max exit latency */
1858 slot_ctx
[1] |= islot_ctx
[1] & 0xFFFF;
1859 slot_ctx
[2] &= ~0xFF00000; /* interrupter target */
1860 slot_ctx
[2] |= islot_ctx
[2] & 0xFF000000;
1862 DPRINTF("xhci: output slot context: %08x %08x %08x %08x\n",
1863 slot_ctx
[0], slot_ctx
[1], slot_ctx
[2], slot_ctx
[3]);
1865 pci_dma_write(&xhci
->pci_dev
, octx
, slot_ctx
, sizeof(slot_ctx
));
1868 if (ictl_ctx
[1] & 0x2) {
1869 pci_dma_read(&xhci
->pci_dev
, ictx
+64, iep0_ctx
, sizeof(iep0_ctx
));
1871 DPRINTF("xhci: input ep0 context: %08x %08x %08x %08x %08x\n",
1872 iep0_ctx
[0], iep0_ctx
[1], iep0_ctx
[2],
1873 iep0_ctx
[3], iep0_ctx
[4]);
1875 pci_dma_read(&xhci
->pci_dev
, octx
+32, ep0_ctx
, sizeof(ep0_ctx
));
1877 ep0_ctx
[1] &= ~0xFFFF0000; /* max packet size*/
1878 ep0_ctx
[1] |= iep0_ctx
[1] & 0xFFFF0000;
1880 DPRINTF("xhci: output ep0 context: %08x %08x %08x %08x %08x\n",
1881 ep0_ctx
[0], ep0_ctx
[1], ep0_ctx
[2], ep0_ctx
[3], ep0_ctx
[4]);
1883 pci_dma_write(&xhci
->pci_dev
, octx
+32, ep0_ctx
, sizeof(ep0_ctx
));
1889 static TRBCCode
xhci_reset_slot(XHCIState
*xhci
, unsigned int slotid
)
1891 uint32_t slot_ctx
[4];
1895 trace_usb_xhci_slot_reset(slotid
);
1896 assert(slotid
>= 1 && slotid
<= MAXSLOTS
);
1898 octx
= xhci
->slots
[slotid
-1].ctx
;
1900 DPRINTF("xhci: output context at "DMA_ADDR_FMT
"\n", octx
);
1902 for (i
= 2; i
<= 31; i
++) {
1903 if (xhci
->slots
[slotid
-1].eps
[i
-1]) {
1904 xhci_disable_ep(xhci
, slotid
, i
);
1908 pci_dma_read(&xhci
->pci_dev
, octx
, slot_ctx
, sizeof(slot_ctx
));
1909 slot_ctx
[3] &= ~(SLOT_STATE_MASK
<< SLOT_STATE_SHIFT
);
1910 slot_ctx
[3] |= SLOT_DEFAULT
<< SLOT_STATE_SHIFT
;
1911 DPRINTF("xhci: output slot context: %08x %08x %08x %08x\n",
1912 slot_ctx
[0], slot_ctx
[1], slot_ctx
[2], slot_ctx
[3]);
1913 pci_dma_write(&xhci
->pci_dev
, octx
, slot_ctx
, sizeof(slot_ctx
));
1918 static unsigned int xhci_get_slot(XHCIState
*xhci
, XHCIEvent
*event
, XHCITRB
*trb
)
1920 unsigned int slotid
;
1921 slotid
= (trb
->control
>> TRB_CR_SLOTID_SHIFT
) & TRB_CR_SLOTID_MASK
;
1922 if (slotid
< 1 || slotid
> MAXSLOTS
) {
1923 fprintf(stderr
, "xhci: bad slot id %d\n", slotid
);
1924 event
->ccode
= CC_TRB_ERROR
;
1926 } else if (!xhci
->slots
[slotid
-1].enabled
) {
1927 fprintf(stderr
, "xhci: slot id %d not enabled\n", slotid
);
1928 event
->ccode
= CC_SLOT_NOT_ENABLED_ERROR
;
1934 static TRBCCode
xhci_get_port_bandwidth(XHCIState
*xhci
, uint64_t pctx
)
1937 uint8_t bw_ctx
[MAXPORTS
+1];
1939 DPRINTF("xhci_get_port_bandwidth()\n");
1941 ctx
= xhci_mask64(pctx
);
1943 DPRINTF("xhci: bandwidth context at "DMA_ADDR_FMT
"\n", ctx
);
1945 /* TODO: actually implement real values here */
1947 memset(&bw_ctx
[1], 80, MAXPORTS
); /* 80% */
1948 pci_dma_write(&xhci
->pci_dev
, ctx
, bw_ctx
, sizeof(bw_ctx
));
1953 static uint32_t rotl(uint32_t v
, unsigned count
)
1956 return (v
<< count
) | (v
>> (32 - count
));
1960 static uint32_t xhci_nec_challenge(uint32_t hi
, uint32_t lo
)
1963 val
= rotl(lo
- 0x49434878, 32 - ((hi
>>8) & 0x1F));
1964 val
+= rotl(lo
+ 0x49434878, hi
& 0x1F);
1965 val
-= rotl(hi
^ 0x49434878, (lo
>> 16) & 0x1F);
1969 static void xhci_via_challenge(XHCIState
*xhci
, uint64_t addr
)
1973 dma_addr_t paddr
= xhci_mask64(addr
);
1975 pci_dma_read(&xhci
->pci_dev
, paddr
, &buf
, 32);
1977 memcpy(obuf
, buf
, sizeof(obuf
));
1979 if ((buf
[0] & 0xff) == 2) {
1980 obuf
[0] = 0x49932000 + 0x54dc200 * buf
[2] + 0x7429b578 * buf
[3];
1981 obuf
[0] |= (buf
[2] * buf
[3]) & 0xff;
1982 obuf
[1] = 0x0132bb37 + 0xe89 * buf
[2] + 0xf09 * buf
[3];
1983 obuf
[2] = 0x0066c2e9 + 0x2091 * buf
[2] + 0x19bd * buf
[3];
1984 obuf
[3] = 0xd5281342 + 0x2cc9691 * buf
[2] + 0x2367662 * buf
[3];
1985 obuf
[4] = 0x0123c75c + 0x1595 * buf
[2] + 0x19ec * buf
[3];
1986 obuf
[5] = 0x00f695de + 0x26fd * buf
[2] + 0x3e9 * buf
[3];
1987 obuf
[6] = obuf
[2] ^ obuf
[3] ^ 0x29472956;
1988 obuf
[7] = obuf
[2] ^ obuf
[3] ^ 0x65866593;
1991 pci_dma_write(&xhci
->pci_dev
, paddr
, &obuf
, 32);
1994 static void xhci_process_commands(XHCIState
*xhci
)
1998 XHCIEvent event
= {ER_COMMAND_COMPLETE
, CC_SUCCESS
};
2000 unsigned int i
, slotid
= 0;
2002 DPRINTF("xhci_process_commands()\n");
2003 if (!xhci_running(xhci
)) {
2004 DPRINTF("xhci_process_commands() called while xHC stopped or paused\n");
2008 xhci
->crcr_low
|= CRCR_CRR
;
2010 while ((type
= xhci_ring_fetch(xhci
, &xhci
->cmd_ring
, &trb
, &addr
))) {
2013 case CR_ENABLE_SLOT
:
2014 for (i
= 0; i
< MAXSLOTS
; i
++) {
2015 if (!xhci
->slots
[i
].enabled
) {
2019 if (i
>= MAXSLOTS
) {
2020 fprintf(stderr
, "xhci: no device slots available\n");
2021 event
.ccode
= CC_NO_SLOTS_ERROR
;
2024 event
.ccode
= xhci_enable_slot(xhci
, slotid
);
2027 case CR_DISABLE_SLOT
:
2028 slotid
= xhci_get_slot(xhci
, &event
, &trb
);
2030 event
.ccode
= xhci_disable_slot(xhci
, slotid
);
2033 case CR_ADDRESS_DEVICE
:
2034 slotid
= xhci_get_slot(xhci
, &event
, &trb
);
2036 event
.ccode
= xhci_address_slot(xhci
, slotid
, trb
.parameter
,
2037 trb
.control
& TRB_CR_BSR
);
2040 case CR_CONFIGURE_ENDPOINT
:
2041 slotid
= xhci_get_slot(xhci
, &event
, &trb
);
2043 event
.ccode
= xhci_configure_slot(xhci
, slotid
, trb
.parameter
,
2044 trb
.control
& TRB_CR_DC
);
2047 case CR_EVALUATE_CONTEXT
:
2048 slotid
= xhci_get_slot(xhci
, &event
, &trb
);
2050 event
.ccode
= xhci_evaluate_slot(xhci
, slotid
, trb
.parameter
);
2053 case CR_STOP_ENDPOINT
:
2054 slotid
= xhci_get_slot(xhci
, &event
, &trb
);
2056 unsigned int epid
= (trb
.control
>> TRB_CR_EPID_SHIFT
)
2058 event
.ccode
= xhci_stop_ep(xhci
, slotid
, epid
);
2061 case CR_RESET_ENDPOINT
:
2062 slotid
= xhci_get_slot(xhci
, &event
, &trb
);
2064 unsigned int epid
= (trb
.control
>> TRB_CR_EPID_SHIFT
)
2066 event
.ccode
= xhci_reset_ep(xhci
, slotid
, epid
);
2069 case CR_SET_TR_DEQUEUE
:
2070 slotid
= xhci_get_slot(xhci
, &event
, &trb
);
2072 unsigned int epid
= (trb
.control
>> TRB_CR_EPID_SHIFT
)
2074 event
.ccode
= xhci_set_ep_dequeue(xhci
, slotid
, epid
,
2078 case CR_RESET_DEVICE
:
2079 slotid
= xhci_get_slot(xhci
, &event
, &trb
);
2081 event
.ccode
= xhci_reset_slot(xhci
, slotid
);
2084 case CR_GET_PORT_BANDWIDTH
:
2085 event
.ccode
= xhci_get_port_bandwidth(xhci
, trb
.parameter
);
2087 case CR_VENDOR_VIA_CHALLENGE_RESPONSE
:
2088 xhci_via_challenge(xhci
, trb
.parameter
);
2090 case CR_VENDOR_NEC_FIRMWARE_REVISION
:
2091 event
.type
= 48; /* NEC reply */
2092 event
.length
= 0x3025;
2094 case CR_VENDOR_NEC_CHALLENGE_RESPONSE
:
2096 uint32_t chi
= trb
.parameter
>> 32;
2097 uint32_t clo
= trb
.parameter
;
2098 uint32_t val
= xhci_nec_challenge(chi
, clo
);
2099 event
.length
= val
& 0xFFFF;
2100 event
.epid
= val
>> 16;
2102 event
.type
= 48; /* NEC reply */
2106 fprintf(stderr
, "xhci: unimplemented command %d\n", type
);
2107 event
.ccode
= CC_TRB_ERROR
;
2110 event
.slotid
= slotid
;
2111 xhci_event(xhci
, &event
);
2115 static void xhci_update_port(XHCIState
*xhci
, XHCIPort
*port
, int is_detach
)
2117 int nr
= port
->port
.index
+ 1;
2119 port
->portsc
= PORTSC_PP
;
2120 if (port
->port
.dev
&& port
->port
.dev
->attached
&& !is_detach
) {
2121 port
->portsc
|= PORTSC_CCS
;
2122 switch (port
->port
.dev
->speed
) {
2124 port
->portsc
|= PORTSC_SPEED_LOW
;
2126 case USB_SPEED_FULL
:
2127 port
->portsc
|= PORTSC_SPEED_FULL
;
2129 case USB_SPEED_HIGH
:
2130 port
->portsc
|= PORTSC_SPEED_HIGH
;
2135 if (xhci_running(xhci
)) {
2136 port
->portsc
|= PORTSC_CSC
;
2137 XHCIEvent ev
= { ER_PORT_STATUS_CHANGE
, CC_SUCCESS
, nr
<< 24};
2138 xhci_event(xhci
, &ev
);
2139 DPRINTF("xhci: port change event for port %d\n", nr
);
2143 static void xhci_reset(DeviceState
*dev
)
2145 XHCIState
*xhci
= DO_UPCAST(XHCIState
, pci_dev
.qdev
, dev
);
2148 trace_usb_xhci_reset();
2149 if (!(xhci
->usbsts
& USBSTS_HCH
)) {
2150 fprintf(stderr
, "xhci: reset while running!\n");
2154 xhci
->usbsts
= USBSTS_HCH
;
2157 xhci
->crcr_high
= 0;
2158 xhci
->dcbaap_low
= 0;
2159 xhci
->dcbaap_high
= 0;
2163 for (i
= 0; i
< MAXSLOTS
; i
++) {
2164 xhci_disable_slot(xhci
, i
+1);
2167 for (i
= 0; i
< MAXPORTS
; i
++) {
2168 xhci_update_port(xhci
, xhci
->ports
+ i
, 0);
2174 xhci
->erstba_low
= 0;
2175 xhci
->erstba_high
= 0;
2177 xhci
->erdp_high
= 0;
2179 xhci
->er_ep_idx
= 0;
2182 xhci
->ev_buffer_put
= 0;
2183 xhci
->ev_buffer_get
= 0;
2185 xhci
->mfindex_start
= qemu_get_clock_ns(vm_clock
);
2186 xhci_mfwrap_update(xhci
);
2189 static uint32_t xhci_cap_read(XHCIState
*xhci
, uint32_t reg
)
2194 case 0x00: /* HCIVERSION, CAPLENGTH */
2195 ret
= 0x01000000 | LEN_CAP
;
2197 case 0x04: /* HCSPARAMS 1 */
2198 ret
= (MAXPORTS
<<24) | (MAXINTRS
<<8) | MAXSLOTS
;
2200 case 0x08: /* HCSPARAMS 2 */
2203 case 0x0c: /* HCSPARAMS 3 */
2206 case 0x10: /* HCCPARAMS */
2207 if (sizeof(dma_addr_t
) == 4) {
2213 case 0x14: /* DBOFF */
2216 case 0x18: /* RTSOFF */
2220 /* extended capabilities */
2221 case 0x20: /* Supported Protocol:00 */
2222 ret
= 0x02000402; /* USB 2.0 */
2224 case 0x24: /* Supported Protocol:04 */
2225 ret
= 0x20425455; /* "USB " */
2227 case 0x28: /* Supported Protocol:08 */
2228 ret
= 0x00000001 | (USB2_PORTS
<<8);
2230 case 0x2c: /* Supported Protocol:0c */
2231 ret
= 0x00000000; /* reserved */
2233 case 0x30: /* Supported Protocol:00 */
2234 ret
= 0x03000002; /* USB 3.0 */
2236 case 0x34: /* Supported Protocol:04 */
2237 ret
= 0x20425455; /* "USB " */
2239 case 0x38: /* Supported Protocol:08 */
2240 ret
= 0x00000000 | (USB2_PORTS
+1) | (USB3_PORTS
<<8);
2242 case 0x3c: /* Supported Protocol:0c */
2243 ret
= 0x00000000; /* reserved */
2246 fprintf(stderr
, "xhci_cap_read: reg %d unimplemented\n", reg
);
2250 trace_usb_xhci_cap_read(reg
, ret
);
2254 static uint32_t xhci_port_read(XHCIState
*xhci
, uint32_t reg
)
2256 uint32_t port
= reg
>> 4;
2259 if (port
>= MAXPORTS
) {
2260 fprintf(stderr
, "xhci_port_read: port %d out of bounds\n", port
);
2265 switch (reg
& 0xf) {
2266 case 0x00: /* PORTSC */
2267 ret
= xhci
->ports
[port
].portsc
;
2269 case 0x04: /* PORTPMSC */
2270 case 0x08: /* PORTLI */
2273 case 0x0c: /* reserved */
2275 fprintf(stderr
, "xhci_port_read (port %d): reg 0x%x unimplemented\n",
2281 trace_usb_xhci_port_read(port
, reg
& 0x0f, ret
);
2285 static void xhci_port_write(XHCIState
*xhci
, uint32_t reg
, uint32_t val
)
2287 uint32_t port
= reg
>> 4;
2290 trace_usb_xhci_port_write(port
, reg
& 0x0f, val
);
2292 if (port
>= MAXPORTS
) {
2293 fprintf(stderr
, "xhci_port_read: port %d out of bounds\n", port
);
2297 switch (reg
& 0xf) {
2298 case 0x00: /* PORTSC */
2299 portsc
= xhci
->ports
[port
].portsc
;
2300 /* write-1-to-clear bits*/
2301 portsc
&= ~(val
& (PORTSC_CSC
|PORTSC_PEC
|PORTSC_WRC
|PORTSC_OCC
|
2302 PORTSC_PRC
|PORTSC_PLC
|PORTSC_CEC
));
2303 if (val
& PORTSC_LWS
) {
2304 /* overwrite PLS only when LWS=1 */
2305 portsc
&= ~(PORTSC_PLS_MASK
<< PORTSC_PLS_SHIFT
);
2306 portsc
|= val
& (PORTSC_PLS_MASK
<< PORTSC_PLS_SHIFT
);
2308 /* read/write bits */
2309 portsc
&= ~(PORTSC_PP
|PORTSC_WCE
|PORTSC_WDE
|PORTSC_WOE
);
2310 portsc
|= (val
& (PORTSC_PP
|PORTSC_WCE
|PORTSC_WDE
|PORTSC_WOE
));
2311 /* write-1-to-start bits */
2312 if (val
& PORTSC_PR
) {
2313 DPRINTF("xhci: port %d reset\n", port
);
2314 usb_device_reset(xhci
->ports
[port
].port
.dev
);
2315 portsc
|= PORTSC_PRC
| PORTSC_PED
;
2317 xhci
->ports
[port
].portsc
= portsc
;
2319 case 0x04: /* PORTPMSC */
2320 case 0x08: /* PORTLI */
2322 fprintf(stderr
, "xhci_port_write (port %d): reg 0x%x unimplemented\n",
2327 static uint32_t xhci_oper_read(XHCIState
*xhci
, uint32_t reg
)
2332 return xhci_port_read(xhci
, reg
- 0x400);
2336 case 0x00: /* USBCMD */
2339 case 0x04: /* USBSTS */
2342 case 0x08: /* PAGESIZE */
2345 case 0x14: /* DNCTRL */
2348 case 0x18: /* CRCR low */
2349 ret
= xhci
->crcr_low
& ~0xe;
2351 case 0x1c: /* CRCR high */
2352 ret
= xhci
->crcr_high
;
2354 case 0x30: /* DCBAAP low */
2355 ret
= xhci
->dcbaap_low
;
2357 case 0x34: /* DCBAAP high */
2358 ret
= xhci
->dcbaap_high
;
2360 case 0x38: /* CONFIG */
2364 fprintf(stderr
, "xhci_oper_read: reg 0x%x unimplemented\n", reg
);
2368 trace_usb_xhci_oper_read(reg
, ret
);
2372 static void xhci_oper_write(XHCIState
*xhci
, uint32_t reg
, uint32_t val
)
2375 xhci_port_write(xhci
, reg
- 0x400, val
);
2379 trace_usb_xhci_oper_write(reg
, val
);
2382 case 0x00: /* USBCMD */
2383 if ((val
& USBCMD_RS
) && !(xhci
->usbcmd
& USBCMD_RS
)) {
2385 } else if (!(val
& USBCMD_RS
) && (xhci
->usbcmd
& USBCMD_RS
)) {
2388 xhci
->usbcmd
= val
& 0xc0f;
2389 xhci_mfwrap_update(xhci
);
2390 if (val
& USBCMD_HCRST
) {
2391 xhci_reset(&xhci
->pci_dev
.qdev
);
2393 xhci_irq_update(xhci
);
2396 case 0x04: /* USBSTS */
2397 /* these bits are write-1-to-clear */
2398 xhci
->usbsts
&= ~(val
& (USBSTS_HSE
|USBSTS_EINT
|USBSTS_PCD
|USBSTS_SRE
));
2399 xhci_irq_update(xhci
);
2402 case 0x14: /* DNCTRL */
2403 xhci
->dnctrl
= val
& 0xffff;
2405 case 0x18: /* CRCR low */
2406 xhci
->crcr_low
= (val
& 0xffffffcf) | (xhci
->crcr_low
& CRCR_CRR
);
2408 case 0x1c: /* CRCR high */
2409 xhci
->crcr_high
= val
;
2410 if (xhci
->crcr_low
& (CRCR_CA
|CRCR_CS
) && (xhci
->crcr_low
& CRCR_CRR
)) {
2411 XHCIEvent event
= {ER_COMMAND_COMPLETE
, CC_COMMAND_RING_STOPPED
};
2412 xhci
->crcr_low
&= ~CRCR_CRR
;
2413 xhci_event(xhci
, &event
);
2414 DPRINTF("xhci: command ring stopped (CRCR=%08x)\n", xhci
->crcr_low
);
2416 dma_addr_t base
= xhci_addr64(xhci
->crcr_low
& ~0x3f, val
);
2417 xhci_ring_init(xhci
, &xhci
->cmd_ring
, base
);
2419 xhci
->crcr_low
&= ~(CRCR_CA
| CRCR_CS
);
2421 case 0x30: /* DCBAAP low */
2422 xhci
->dcbaap_low
= val
& 0xffffffc0;
2424 case 0x34: /* DCBAAP high */
2425 xhci
->dcbaap_high
= val
;
2427 case 0x38: /* CONFIG */
2428 xhci
->config
= val
& 0xff;
2431 fprintf(stderr
, "xhci_oper_write: reg 0x%x unimplemented\n", reg
);
2435 static uint32_t xhci_runtime_read(XHCIState
*xhci
, uint32_t reg
)
2440 case 0x00: /* MFINDEX */
2441 ret
= xhci_mfindex_get(xhci
) & 0x3fff;
2443 case 0x20: /* IMAN */
2446 case 0x24: /* IMOD */
2449 case 0x28: /* ERSTSZ */
2452 case 0x30: /* ERSTBA low */
2453 ret
= xhci
->erstba_low
;
2455 case 0x34: /* ERSTBA high */
2456 ret
= xhci
->erstba_high
;
2458 case 0x38: /* ERDP low */
2459 ret
= xhci
->erdp_low
;
2461 case 0x3c: /* ERDP high */
2462 ret
= xhci
->erdp_high
;
2465 fprintf(stderr
, "xhci_runtime_read: reg 0x%x unimplemented\n", reg
);
2469 trace_usb_xhci_runtime_read(reg
, ret
);
2473 static void xhci_runtime_write(XHCIState
*xhci
, uint32_t reg
, uint32_t val
)
2475 trace_usb_xhci_runtime_read(reg
, val
);
2478 case 0x20: /* IMAN */
2479 if (val
& IMAN_IP
) {
2480 xhci
->iman
&= ~IMAN_IP
;
2482 xhci
->iman
&= ~IMAN_IE
;
2483 xhci
->iman
|= val
& IMAN_IE
;
2484 xhci_irq_update(xhci
);
2486 case 0x24: /* IMOD */
2489 case 0x28: /* ERSTSZ */
2490 xhci
->erstsz
= val
& 0xffff;
2492 case 0x30: /* ERSTBA low */
2493 /* XXX NEC driver bug: it doesn't align this to 64 bytes
2494 xhci->erstba_low = val & 0xffffffc0; */
2495 xhci
->erstba_low
= val
& 0xfffffff0;
2497 case 0x34: /* ERSTBA high */
2498 xhci
->erstba_high
= val
;
2499 xhci_er_reset(xhci
);
2501 case 0x38: /* ERDP low */
2502 if (val
& ERDP_EHB
) {
2503 xhci
->erdp_low
&= ~ERDP_EHB
;
2505 xhci
->erdp_low
= (val
& ~ERDP_EHB
) | (xhci
->erdp_low
& ERDP_EHB
);
2507 case 0x3c: /* ERDP high */
2508 xhci
->erdp_high
= val
;
2509 xhci_events_update(xhci
);
2512 fprintf(stderr
, "xhci_oper_write: reg 0x%x unimplemented\n", reg
);
2516 static uint32_t xhci_doorbell_read(XHCIState
*xhci
, uint32_t reg
)
2518 /* doorbells always read as 0 */
2519 trace_usb_xhci_doorbell_read(reg
, 0);
2523 static void xhci_doorbell_write(XHCIState
*xhci
, uint32_t reg
, uint32_t val
)
2525 trace_usb_xhci_doorbell_write(reg
, val
);
2527 if (!xhci_running(xhci
)) {
2528 fprintf(stderr
, "xhci: wrote doorbell while xHC stopped or paused\n");
2536 xhci_process_commands(xhci
);
2538 fprintf(stderr
, "xhci: bad doorbell 0 write: 0x%x\n", val
);
2541 if (reg
> MAXSLOTS
) {
2542 fprintf(stderr
, "xhci: bad doorbell %d\n", reg
);
2543 } else if (val
> 31) {
2544 fprintf(stderr
, "xhci: bad doorbell %d write: 0x%x\n", reg
, val
);
2546 xhci_kick_ep(xhci
, reg
, val
);
2551 static uint64_t xhci_mem_read(void *ptr
, target_phys_addr_t addr
,
2554 XHCIState
*xhci
= ptr
;
2556 /* Only aligned reads are allowed on xHCI */
2558 fprintf(stderr
, "xhci_mem_read: Mis-aligned read\n");
2562 if (addr
< LEN_CAP
) {
2563 return xhci_cap_read(xhci
, addr
);
2564 } else if (addr
>= OFF_OPER
&& addr
< (OFF_OPER
+ LEN_OPER
)) {
2565 return xhci_oper_read(xhci
, addr
- OFF_OPER
);
2566 } else if (addr
>= OFF_RUNTIME
&& addr
< (OFF_RUNTIME
+ LEN_RUNTIME
)) {
2567 return xhci_runtime_read(xhci
, addr
- OFF_RUNTIME
);
2568 } else if (addr
>= OFF_DOORBELL
&& addr
< (OFF_DOORBELL
+ LEN_DOORBELL
)) {
2569 return xhci_doorbell_read(xhci
, addr
- OFF_DOORBELL
);
2571 fprintf(stderr
, "xhci_mem_read: Bad offset %x\n", (int)addr
);
2576 static void xhci_mem_write(void *ptr
, target_phys_addr_t addr
,
2577 uint64_t val
, unsigned size
)
2579 XHCIState
*xhci
= ptr
;
2581 /* Only aligned writes are allowed on xHCI */
2583 fprintf(stderr
, "xhci_mem_write: Mis-aligned write\n");
2587 if (addr
>= OFF_OPER
&& addr
< (OFF_OPER
+ LEN_OPER
)) {
2588 xhci_oper_write(xhci
, addr
- OFF_OPER
, val
);
2589 } else if (addr
>= OFF_RUNTIME
&& addr
< (OFF_RUNTIME
+ LEN_RUNTIME
)) {
2590 xhci_runtime_write(xhci
, addr
- OFF_RUNTIME
, val
);
2591 } else if (addr
>= OFF_DOORBELL
&& addr
< (OFF_DOORBELL
+ LEN_DOORBELL
)) {
2592 xhci_doorbell_write(xhci
, addr
- OFF_DOORBELL
, val
);
2594 fprintf(stderr
, "xhci_mem_write: Bad offset %x\n", (int)addr
);
2598 static const MemoryRegionOps xhci_mem_ops
= {
2599 .read
= xhci_mem_read
,
2600 .write
= xhci_mem_write
,
2601 .valid
.min_access_size
= 4,
2602 .valid
.max_access_size
= 4,
2603 .endianness
= DEVICE_LITTLE_ENDIAN
,
2606 static void xhci_attach(USBPort
*usbport
)
2608 XHCIState
*xhci
= usbport
->opaque
;
2609 XHCIPort
*port
= &xhci
->ports
[usbport
->index
];
2611 xhci_update_port(xhci
, port
, 0);
2614 static void xhci_detach(USBPort
*usbport
)
2616 XHCIState
*xhci
= usbport
->opaque
;
2617 XHCIPort
*port
= &xhci
->ports
[usbport
->index
];
2619 xhci_update_port(xhci
, port
, 1);
2622 static void xhci_wakeup(USBPort
*usbport
)
2624 XHCIState
*xhci
= usbport
->opaque
;
2625 XHCIPort
*port
= &xhci
->ports
[usbport
->index
];
2626 int nr
= port
->port
.index
+ 1;
2627 XHCIEvent ev
= { ER_PORT_STATUS_CHANGE
, CC_SUCCESS
, nr
<< 24};
2630 pls
= (port
->portsc
>> PORTSC_PLS_SHIFT
) & PORTSC_PLS_MASK
;
2634 port
->portsc
|= 0xf << PORTSC_PLS_SHIFT
;
2635 if (port
->portsc
& PORTSC_PLC
) {
2638 port
->portsc
|= PORTSC_PLC
;
2639 xhci_event(xhci
, &ev
);
2642 static void xhci_complete(USBPort
*port
, USBPacket
*packet
)
2644 XHCITransfer
*xfer
= container_of(packet
, XHCITransfer
, packet
);
2646 xhci_complete_packet(xfer
, packet
->result
);
2647 xhci_kick_ep(xfer
->xhci
, xfer
->slotid
, xfer
->epid
);
2650 static void xhci_child_detach(USBPort
*port
, USBDevice
*child
)
2655 static USBPortOps xhci_port_ops
= {
2656 .attach
= xhci_attach
,
2657 .detach
= xhci_detach
,
2658 .wakeup
= xhci_wakeup
,
2659 .complete
= xhci_complete
,
2660 .child_detach
= xhci_child_detach
,
2663 static int xhci_find_slotid(XHCIState
*xhci
, USBDevice
*dev
)
2668 for (slotid
= 1; slotid
<= MAXSLOTS
; slotid
++) {
2669 slot
= &xhci
->slots
[slotid
-1];
2670 if (slot
->devaddr
== dev
->addr
) {
2677 static int xhci_find_epid(USBEndpoint
*ep
)
2682 if (ep
->pid
== USB_TOKEN_IN
) {
2683 return ep
->nr
* 2 + 1;
2689 static void xhci_wakeup_endpoint(USBBus
*bus
, USBEndpoint
*ep
)
2691 XHCIState
*xhci
= container_of(bus
, XHCIState
, bus
);
2694 DPRINTF("%s\n", __func__
);
2695 slotid
= xhci_find_slotid(xhci
, ep
->dev
);
2696 if (slotid
== 0 || !xhci
->slots
[slotid
-1].enabled
) {
2697 DPRINTF("%s: oops, no slot for dev %d\n", __func__
, ep
->dev
->addr
);
2700 xhci_kick_ep(xhci
, slotid
, xhci_find_epid(ep
));
2703 static USBBusOps xhci_bus_ops
= {
2704 .wakeup_endpoint
= xhci_wakeup_endpoint
,
2707 static void usb_xhci_init(XHCIState
*xhci
, DeviceState
*dev
)
2711 xhci
->usbsts
= USBSTS_HCH
;
2713 usb_bus_new(&xhci
->bus
, &xhci_bus_ops
, &xhci
->pci_dev
.qdev
);
2715 for (i
= 0; i
< MAXPORTS
; i
++) {
2716 memset(&xhci
->ports
[i
], 0, sizeof(xhci
->ports
[i
]));
2717 usb_register_port(&xhci
->bus
, &xhci
->ports
[i
].port
, xhci
, i
,
2719 USB_SPEED_MASK_LOW
|
2720 USB_SPEED_MASK_FULL
|
2721 USB_SPEED_MASK_HIGH
);
2723 for (i
= 0; i
< MAXSLOTS
; i
++) {
2724 xhci
->slots
[i
].enabled
= 0;
2728 static int usb_xhci_initfn(struct PCIDevice
*dev
)
2732 XHCIState
*xhci
= DO_UPCAST(XHCIState
, pci_dev
, dev
);
2734 xhci
->pci_dev
.config
[PCI_CLASS_PROG
] = 0x30; /* xHCI */
2735 xhci
->pci_dev
.config
[PCI_INTERRUPT_PIN
] = 0x01; /* interrupt pin 1 */
2736 xhci
->pci_dev
.config
[PCI_CACHE_LINE_SIZE
] = 0x10;
2737 xhci
->pci_dev
.config
[0x60] = 0x30; /* release number */
2739 usb_xhci_init(xhci
, &dev
->qdev
);
2741 xhci
->mfwrap_timer
= qemu_new_timer_ns(vm_clock
, xhci_mfwrap_timer
, xhci
);
2743 xhci
->irq
= xhci
->pci_dev
.irq
[0];
2745 memory_region_init_io(&xhci
->mem
, &xhci_mem_ops
, xhci
,
2747 pci_register_bar(&xhci
->pci_dev
, 0,
2748 PCI_BASE_ADDRESS_SPACE_MEMORY
|PCI_BASE_ADDRESS_MEM_TYPE_64
,
2751 ret
= pcie_cap_init(&xhci
->pci_dev
, 0xa0, PCI_EXP_TYPE_ENDPOINT
, 0);
2755 ret
= msi_init(&xhci
->pci_dev
, 0x70, 1, true, false);
2762 static void xhci_write_config(PCIDevice
*dev
, uint32_t addr
, uint32_t val
,
2765 XHCIState
*xhci
= DO_UPCAST(XHCIState
, pci_dev
, dev
);
2767 pci_default_write_config(dev
, addr
, val
, len
);
2769 msi_write_config(dev
, addr
, val
, len
);
2773 static const VMStateDescription vmstate_xhci
= {
2778 static Property xhci_properties
[] = {
2779 DEFINE_PROP_UINT32("msi", XHCIState
, msi
, 0),
2780 DEFINE_PROP_END_OF_LIST(),
2783 static void xhci_class_init(ObjectClass
*klass
, void *data
)
2785 PCIDeviceClass
*k
= PCI_DEVICE_CLASS(klass
);
2786 DeviceClass
*dc
= DEVICE_CLASS(klass
);
2788 dc
->vmsd
= &vmstate_xhci
;
2789 dc
->props
= xhci_properties
;
2790 dc
->reset
= xhci_reset
;
2791 k
->init
= usb_xhci_initfn
;
2792 k
->vendor_id
= PCI_VENDOR_ID_NEC
;
2793 k
->device_id
= PCI_DEVICE_ID_NEC_UPD720200
;
2794 k
->class_id
= PCI_CLASS_SERIAL_USB
;
2797 k
->config_write
= xhci_write_config
;
2800 static TypeInfo xhci_info
= {
2801 .name
= "nec-usb-xhci",
2802 .parent
= TYPE_PCI_DEVICE
,
2803 .instance_size
= sizeof(XHCIState
),
2804 .class_init
= xhci_class_init
,
2807 static void xhci_register_types(void)
2809 type_register_static(&xhci_info
);
2812 type_init(xhci_register_types
)