Sun Apr 10 15:47:58 2016 UTC ()
Fix lock assertion in xhci_softintr() when entering DDB on ukbd.
Move this KASSERT to xhci_softintr() from xhci_handle_event().

From Takahiro HAYASHI


(skrll)
diff -r1.28.2.57 -r1.28.2.58 src/sys/dev/usb/xhci.c

cvs diff -r1.28.2.57 -r1.28.2.58 src/sys/dev/usb/xhci.c (expand / switch to unified diff)

--- src/sys/dev/usb/xhci.c 2016/04/10 15:46:46 1.28.2.57
+++ src/sys/dev/usb/xhci.c 2016/04/10 15:47:58 1.28.2.58
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: xhci.c,v 1.28.2.57 2016/04/10 15:46:46 skrll Exp $ */ 1/* $NetBSD: xhci.c,v 1.28.2.58 2016/04/10 15:47:58 skrll Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2013 Jonathan A. Kollasch 4 * Copyright (c) 2013 Jonathan A. Kollasch
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -26,27 +26,27 @@ @@ -26,27 +26,27 @@
26 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29/* 29/*
30 * USB rev 3.1 specification 30 * USB rev 3.1 specification
31 * http://www.usb.org/developers/docs/usb_31_040315.zip 31 * http://www.usb.org/developers/docs/usb_31_040315.zip
32 * USB rev 2.0 specification 32 * USB rev 2.0 specification
33 * http://www.usb.org/developers/docs/usb20_docs/usb_20_031815.zip 33 * http://www.usb.org/developers/docs/usb20_docs/usb_20_031815.zip
34 * xHCI rev 1.1 specification 34 * xHCI rev 1.1 specification
35 * http://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/extensible-host-controler-interface-usb-xhci.pdf 35 * http://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/extensible-host-controler-interface-usb-xhci.pdf
36 */ 36 */
37 37
38#include <sys/cdefs.h> 38#include <sys/cdefs.h>
39__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.28.2.57 2016/04/10 15:46:46 skrll Exp $"); 39__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.28.2.58 2016/04/10 15:47:58 skrll Exp $");
40 40
41#include "opt_usb.h" 41#include "opt_usb.h"
42 42
43#include <sys/param.h> 43#include <sys/param.h>
44#include <sys/systm.h> 44#include <sys/systm.h>
45#include <sys/kernel.h> 45#include <sys/kernel.h>
46#include <sys/kmem.h> 46#include <sys/kmem.h>
47#include <sys/device.h> 47#include <sys/device.h>
48#include <sys/select.h> 48#include <sys/select.h>
49#include <sys/proc.h> 49#include <sys/proc.h>
50#include <sys/queue.h> 50#include <sys/queue.h>
51#include <sys/mutex.h> 51#include <sys/mutex.h>
52#include <sys/condvar.h> 52#include <sys/condvar.h>
@@ -1940,28 +1940,26 @@ xhci_event_cmd(struct xhci_softc * const @@ -1940,28 +1940,26 @@ xhci_event_cmd(struct xhci_softc * const
1940/* 1940/*
1941 * Process events. 1941 * Process events.
1942 * called from xhci_softintr 1942 * called from xhci_softintr
1943 */ 1943 */
1944static void 1944static void
1945xhci_handle_event(struct xhci_softc * const sc, 1945xhci_handle_event(struct xhci_softc * const sc,
1946 const struct xhci_trb * const trb) 1946 const struct xhci_trb * const trb)
1947{ 1947{
1948 uint64_t trb_0; 1948 uint64_t trb_0;
1949 uint32_t trb_2, trb_3; 1949 uint32_t trb_2, trb_3;
1950 1950
1951 XHCIHIST_FUNC(); XHCIHIST_CALLED(); 1951 XHCIHIST_FUNC(); XHCIHIST_CALLED();
1952 1952
1953 KASSERT(mutex_owned(&sc->sc_lock)); 
1954 
1955 trb_0 = le64toh(trb->trb_0); 1953 trb_0 = le64toh(trb->trb_0);
1956 trb_2 = le32toh(trb->trb_2); 1954 trb_2 = le32toh(trb->trb_2);
1957 trb_3 = le32toh(trb->trb_3); 1955 trb_3 = le32toh(trb->trb_3);
1958 1956
1959 DPRINTFN(14, "event: %p 0x%016"PRIx64" 0x%08"PRIx32" 0x%08"PRIx32, 1957 DPRINTFN(14, "event: %p 0x%016"PRIx64" 0x%08"PRIx32" 0x%08"PRIx32,
1960 trb, trb_0, trb_2, trb_3); 1958 trb, trb_0, trb_2, trb_3);
1961 1959
1962 /* 1960 /*
1963 * 4.11.3.1, 6.4.2.1 1961 * 4.11.3.1, 6.4.2.1
1964 * TRB Pointer is invalid for these completion codes. 1962 * TRB Pointer is invalid for these completion codes.
1965 */ 1963 */
1966 switch (XHCI_TRB_2_ERROR_GET(trb_2)) { 1964 switch (XHCI_TRB_2_ERROR_GET(trb_2)) {
1967 case XHCI_TRB_ERROR_RING_UNDERRUN: 1965 case XHCI_TRB_ERROR_RING_UNDERRUN:
@@ -1991,26 +1989,28 @@ xhci_handle_event(struct xhci_softc * co @@ -1991,26 +1989,28 @@ xhci_handle_event(struct xhci_softc * co
1991} 1989}
1992 1990
1993static void 1991static void
1994xhci_softintr(void *v) 1992xhci_softintr(void *v)
1995{ 1993{
1996 struct usbd_bus * const bus = v; 1994 struct usbd_bus * const bus = v;
1997 struct xhci_softc * const sc = XHCI_BUS2SC(bus); 1995 struct xhci_softc * const sc = XHCI_BUS2SC(bus);
1998 struct xhci_ring * const er = &sc->sc_er; 1996 struct xhci_ring * const er = &sc->sc_er;
1999 struct xhci_trb *trb; 1997 struct xhci_trb *trb;
2000 int i, j, k; 1998 int i, j, k;
2001 1999
2002 XHCIHIST_FUNC(); XHCIHIST_CALLED(); 2000 XHCIHIST_FUNC(); XHCIHIST_CALLED();
2003 2001
 2002 KASSERT(sc->sc_bus.ub_usepolling || mutex_owned(&sc->sc_lock));
 2003
2004 i = er->xr_ep; 2004 i = er->xr_ep;
2005 j = er->xr_cs; 2005 j = er->xr_cs;
2006 2006
2007 DPRINTFN(16, "xr_ep %d xr_cs %d", i, j, 0, 0); 2007 DPRINTFN(16, "xr_ep %d xr_cs %d", i, j, 0, 0);
2008 2008
2009 while (1) { 2009 while (1) {
2010 usb_syncmem(&er->xr_dma, XHCI_TRB_SIZE * i, XHCI_TRB_SIZE, 2010 usb_syncmem(&er->xr_dma, XHCI_TRB_SIZE * i, XHCI_TRB_SIZE,
2011 BUS_DMASYNC_POSTREAD); 2011 BUS_DMASYNC_POSTREAD);
2012 trb = &er->xr_trb[i]; 2012 trb = &er->xr_trb[i];
2013 k = (le32toh(trb->trb_3) & XHCI_TRB_3_CYCLE_BIT) ? 1 : 0; 2013 k = (le32toh(trb->trb_3) & XHCI_TRB_3_CYCLE_BIT) ? 1 : 0;
2014 2014
2015 if (j != k) 2015 if (j != k)
2016 break; 2016 break;