From: Kevin O'Connor Date: Tue, 3 Oct 2017 15:29:12 +0000 (-0400) Subject: xhci: Verify the device is still present in xhci_cmd_submit() X-Git-Tag: rel-1.11.0~4 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=5c1a2c75951c4a59f1bf2d3c82ca7447244513ad;p=seabios.git xhci: Verify the device is still present in xhci_cmd_submit() Make sure the USB device is still present before altering the xhci "slot" for it. It appears some controllers will hang if a request is sent to a port no longer connected. Signed-off-by: Kevin O'Connor --- diff --git a/src/hw/usb-xhci.c b/src/hw/usb-xhci.c index 0f717c6..08d1e32 100644 --- a/src/hw/usb-xhci.c +++ b/src/hw/usb-xhci.c @@ -780,6 +780,17 @@ static void xhci_trb_queue(struct xhci_ring *ring, static int xhci_cmd_submit(struct usb_xhci_s *xhci, struct xhci_inctx *inctx , u32 flags) { + if (inctx) { + struct xhci_slotctx *slot = (void*)&inctx[1 << xhci->context64]; + u32 port = ((slot->ctx[1] >> 16) & 0xff) - 1; + u32 portsc = readl(&xhci->pr[port].portsc); + if (!(portsc & XHCI_PORTSC_CCS)) { + // Device no longer connected?! + xhci_print_port_state(1, __func__, port, portsc); + return -1; + } + } + mutex_lock(&xhci->cmds->lock); xhci_trb_queue(xhci->cmds, inctx, 0, flags); xhci_doorbell(xhci, 0, 0);