Skip to content

Commit

Permalink
Merge remote-tracking branch 'kraxel/usb.76' into staging
Browse files Browse the repository at this point in the history
* kraxel/usb.76:
  usb-host: Initialize dev->port the obviously safe way
  usb-host: Drop superfluous null test from usb_host_auto_scan()
  ehci: Assert state machine is sane w.r.t. EHCIQueue
  xhci: nuke transfe5rs on detach
  xhci: call xhci_detach_slot on root port detach too
  xhci: create xhci_detach_slot helper function

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
  • Loading branch information
Anthony Liguori committed Jan 14, 2013
2 parents 167eb81 + 0360784 commit b55160c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
4 changes: 4 additions & 0 deletions hw/usb/hcd-ehci.c
Expand Up @@ -2092,18 +2092,22 @@ static void ehci_advance_state(EHCIState *ehci, int async)
break;

case EST_ADVANCEQUEUE:
assert(q != NULL);
again = ehci_state_advqueue(q);
break;

case EST_FETCHQTD:
assert(q != NULL);
again = ehci_state_fetchqtd(q);
break;

case EST_HORIZONTALQH:
assert(q != NULL);
again = ehci_state_horizqh(q);
break;

case EST_EXECUTE:
assert(q != NULL);
again = ehci_state_execute(q);
if (async) {
ehci->async_stepdown = 0;
Expand Down
31 changes: 25 additions & 6 deletions hw/usb/hcd-xhci.c
Expand Up @@ -1197,6 +1197,7 @@ static int xhci_ep_nuke_xfers(XHCIState *xhci, unsigned int slotid,
ep = epctx->transfers[xferi].packet.ep;
}
killed += xhci_ep_nuke_one_xfer(&epctx->transfers[xferi]);
epctx->transfers[xferi].packet.ep = NULL;
xferi = (xferi + 1) % TD_QUEUE;
}
if (ep) {
Expand Down Expand Up @@ -2198,6 +2199,28 @@ static unsigned int xhci_get_slot(XHCIState *xhci, XHCIEvent *event, XHCITRB *tr
return slotid;
}

/* cleanup slot state on usb device detach */
static void xhci_detach_slot(XHCIState *xhci, USBPort *uport)
{
int slot, ep;

for (slot = 0; slot < xhci->numslots; slot++) {
if (xhci->slots[slot].uport == uport) {
break;
}
}
if (slot == xhci->numslots) {
return;
}

for (ep = 0; ep < 31; ep++) {
if (xhci->slots[slot].eps[ep]) {
xhci_ep_nuke_xfers(xhci, slot+1, ep+1);
}
}
xhci->slots[slot].uport = NULL;
}

static TRBCCode xhci_get_port_bandwidth(XHCIState *xhci, uint64_t pctx)
{
dma_addr_t ctx;
Expand Down Expand Up @@ -2940,6 +2963,7 @@ static void xhci_detach(USBPort *usbport)
XHCIState *xhci = usbport->opaque;
XHCIPort *port = xhci_lookup_port(xhci, usbport);

xhci_detach_slot(xhci, usbport);
xhci_port_update(port, 1);
}

Expand Down Expand Up @@ -2971,13 +2995,8 @@ static void xhci_child_detach(USBPort *uport, USBDevice *child)
{
USBBus *bus = usb_bus_from_device(child);
XHCIState *xhci = container_of(bus, XHCIState, bus);
int i;

for (i = 0; i < xhci->numslots; i++) {
if (xhci->slots[i].uport == uport) {
xhci->slots[i].uport = NULL;
}
}
xhci_detach_slot(xhci, uport);
}

static USBPortOps xhci_uport_ops = {
Expand Down
4 changes: 2 additions & 2 deletions hw/usb/host-linux.c
Expand Up @@ -1314,7 +1314,7 @@ static int usb_host_open(USBHostDevice *dev, int bus_num,

dev->bus_num = bus_num;
dev->addr = addr;
strcpy(dev->port, port);
pstrcpy(dev->port, sizeof(dev->port), port);
dev->fd = fd;

/* read the device description */
Expand Down Expand Up @@ -1760,7 +1760,7 @@ static int usb_host_auto_scan(void *opaque, int bus_num,
if (f->addr > 0 && f->addr != addr) {
continue;
}
if (f->port != NULL && (port == NULL || strcmp(f->port, port) != 0)) {
if (f->port != NULL && strcmp(f->port, port) != 0) {
continue;
}

Expand Down

0 comments on commit b55160c

Please sign in to comment.