* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
+
#include "qemu/osdep.h"
#include "hw/hw.h"
#include "qemu/timer.h"
+#include "qemu/module.h"
#include "qemu/queue.h"
#include "hw/usb.h"
#include "hw/pci/pci.h"
uint32_t err;
XHCIStreamContext *sctx;
+ if (epctx->type == ET_ISO_IN || epctx->type == ET_ISO_OUT) {
+ /* never halt isoch endpoints, 4.10.2 */
+ return;
+ }
+
if (epctx->nr_pstreams) {
sctx = xhci_find_stream(epctx, xfer->streamid, &err);
if (sctx == NULL) {
while (1) {
length = xhci_ring_chain_length(xhci, ring);
if (length <= 0) {
+ if (epctx->type == ET_ISO_OUT || epctx->type == ET_ISO_IN) {
+ /* 4.10.3.1 */
+ XHCIEvent ev = { ER_TRANSFER };
+ ev.ccode = epctx->type == ET_ISO_IN ?
+ CC_RING_OVERRUN : CC_RING_UNDERRUN;
+ ev.slotid = epctx->slotid;
+ ev.epid = epctx->epid;
+ ev.ptr = epctx->ring.dequeue;
+ xhci_event(xhci, &ev, xhci->slots[epctx->slotid-1].intr);
+ }
break;
}
xfer = xhci_ep_alloc_xfer(epctx, length);
for (i = 0; i < length; i++) {
TRBType type;
type = xhci_ring_fetch(xhci, ring, &xfer->trbs[i], NULL);
- assert(type);
+ if (!type) {
+ xhci_die(xhci);
+ xhci_ep_free_xfer(xfer);
+ epctx->kick_active--;
+ return;
+ }
}
xfer->streamid = streamid;
xhci->slots[slotid-1].enabled = 0;
xhci->slots[slotid-1].addressed = 0;
xhci->slots[slotid-1].uport = NULL;
+ xhci->slots[slotid-1].intr = 0;
return CC_SUCCESS;
}
slot = &xhci->slots[slotid-1];
slot->uport = uport;
slot->ctx = octx;
+ slot->intr = get_field(slot_ctx[2], TRB_INTR);
/* Make sure device is in USB_STATE_DEFAULT state */
usb_device_reset(dev);
slot_ctx[1] &= ~0xFFFF; /* max exit latency */
slot_ctx[1] |= islot_ctx[1] & 0xFFFF;
- slot_ctx[2] &= ~0xFF00000; /* interrupter target */
- slot_ctx[2] |= islot_ctx[2] & 0xFF000000;
+ /* update interrupter target field */
+ xhci->slots[slotid-1].intr = get_field(islot_ctx[2], TRB_INTR);
+ set_field(&slot_ctx[2], xhci->slots[slotid-1].intr, TRB_INTR);
DPRINTF("xhci: output slot context: %08x %08x %08x %08x\n",
slot_ctx[0], slot_ctx[1], slot_ctx[2], slot_ctx[3]);
{
uint32_t pls = PLS_RX_DETECT;
+ assert(port);
port->portsc = PORTSC_PP;
if (!is_detach && xhci_port_have_device(port)) {
port->portsc |= PORTSC_CCS;
streamid = (val >> 16) & 0xffff;
if (reg > xhci->numslots) {
DPRINTF("xhci: bad doorbell %d\n", (int)reg);
- } else if (epid > 31) {
+ } else if (epid == 0 || epid > 31) {
DPRINTF("xhci: bad doorbell %d write: 0x%x\n",
(int)reg, (uint32_t)val);
} else {
XHCIState *xhci = usbport->opaque;
XHCIPort *port = xhci_lookup_port(xhci, usbport);
+ assert(port);
if (get_field(port->portsc, PORTSC_PLS) != PLS_U3) {
return;
}
return NULL;
}
uport = epctx->xhci->slots[epctx->slotid - 1].uport;
- token = (epctx->epid & 1) ? USB_TOKEN_IN : USB_TOKEN_OUT;
- if (!uport) {
+ if (!uport || !uport->dev) {
return NULL;
}
+ token = (epctx->epid & 1) ? USB_TOKEN_IN : USB_TOKEN_OUT;
return usb_ep_get(uport->dev, token, epctx->epid >> 1);
}
{
DeviceState *dev = DEVICE(xhci);
XHCIPort *port;
- int i, usbports, speedmask;
+ unsigned int i, usbports, speedmask;
xhci->usbsts = USBSTS_HCH;
USB_SPEED_MASK_LOW |
USB_SPEED_MASK_FULL |
USB_SPEED_MASK_HIGH;
+ assert(i < MAXPORTS);
snprintf(port->name, sizeof(port->name), "usb2 port #%d", i+1);
speedmask |= port->speedmask;
}
}
port->uport = &xhci->uports[i];
port->speedmask = USB_SPEED_MASK_SUPER;
+ assert(i < MAXPORTS);
snprintf(port->name, sizeof(port->name), "usb3 port #%d", i+1);
speedmask |= port->speedmask;
}