usb4bsd: Perform the usual porting on the controller, storage and core code.
authorSascha Wildner <saw@online.de>
Wed, 26 Sep 2012 17:31:51 +0000 (19:31 +0200)
committerSascha Wildner <saw@online.de>
Thu, 11 Oct 2012 09:27:40 +0000 (11:27 +0200)
malloc -> kmalloc, printf -> kprintf, locking, and so forth.

Submitted-by: Markus Pfeiffer <markus.pfeiffer@morphism.de>
48 files changed:
sys/bus/u4b/controller/ehci.c
sys/bus/u4b/controller/ehci_pci.c
sys/bus/u4b/controller/ohci.c
sys/bus/u4b/controller/ohci_pci.c
sys/bus/u4b/controller/uhci.c
sys/bus/u4b/controller/uhci_pci.c
sys/bus/u4b/controller/usb_controller.c
sys/bus/u4b/controller/xhci.c
sys/bus/u4b/controller/xhci.h
sys/bus/u4b/controller/xhci_pci.c
sys/bus/u4b/storage/umass.c
sys/bus/u4b/storage/ustorage_fs.c
sys/bus/u4b/usb_bus.h
sys/bus/u4b/usb_busdma.c
sys/bus/u4b/usb_busdma.h
sys/bus/u4b/usb_compat_linux.c
sys/bus/u4b/usb_controller.h
sys/bus/u4b/usb_core.c
sys/bus/u4b/usb_core.h
sys/bus/u4b/usb_debug.c
sys/bus/u4b/usb_debug.h
sys/bus/u4b/usb_dev.c
sys/bus/u4b/usb_dev.h
sys/bus/u4b/usb_device.c
sys/bus/u4b/usb_device.h
sys/bus/u4b/usb_dynamic.c
sys/bus/u4b/usb_error.c
sys/bus/u4b/usb_freebsd.h
sys/bus/u4b/usb_generic.c
sys/bus/u4b/usb_handle_request.c
sys/bus/u4b/usb_hid.c
sys/bus/u4b/usb_hub.c
sys/bus/u4b/usb_lookup.c
sys/bus/u4b/usb_mbuf.c
sys/bus/u4b/usb_msctest.c
sys/bus/u4b/usb_parse.c
sys/bus/u4b/usb_pci.h
sys/bus/u4b/usb_pf.c
sys/bus/u4b/usb_process.c
sys/bus/u4b/usb_process.h
sys/bus/u4b/usb_request.c
sys/bus/u4b/usb_request.h
sys/bus/u4b/usb_transfer.c
sys/bus/u4b/usb_transfer.h
sys/bus/u4b/usb_util.c
sys/bus/u4b/usbdi.h
sys/bus/u4b/usbdi_util.h
sys/bus/u4b/usbhid.h

index f59c801..4738d9d 100644 (file)
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+//__FBSDID("$FreeBSD$");
 
 #include <sys/stdint.h>
-#include <sys/stddef.h>
 #include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/types.h>
@@ -56,33 +55,31 @@ __FBSDID("$FreeBSD$");
 #include <sys/bus.h>
 #include <sys/module.h>
 #include <sys/lock.h>
-#include <sys/mutex.h>
 #include <sys/condvar.h>
 #include <sys/sysctl.h>
-#include <sys/sx.h>
 #include <sys/unistd.h>
 #include <sys/callout.h>
 #include <sys/malloc.h>
 #include <sys/priv.h>
 
-#include <dev/usb/usb.h>
-#include <dev/usb/usbdi.h>
+#include <bus/u4b/usb.h>
+#include <bus/u4b/usbdi.h>
 
 #define        USB_DEBUG_VAR ehcidebug
 
-#include <dev/usb/usb_core.h>
-#include <dev/usb/usb_debug.h>
-#include <dev/usb/usb_busdma.h>
-#include <dev/usb/usb_process.h>
-#include <dev/usb/usb_transfer.h>
-#include <dev/usb/usb_device.h>
-#include <dev/usb/usb_hub.h>
-#include <dev/usb/usb_util.h>
+#include <bus/u4b/usb_core.h>
+#include <bus/u4b/usb_debug.h>
+#include <bus/u4b/usb_busdma.h>
+#include <bus/u4b/usb_process.h>
+#include <bus/u4b/usb_transfer.h>
+#include <bus/u4b/usb_device.h>
+#include <bus/u4b/usb_hub.h>
+#include <bus/u4b/usb_util.h>
 
-#include <dev/usb/usb_controller.h>
-#include <dev/usb/usb_bus.h>
-#include <dev/usb/controller/ehci.h>
-#include <dev/usb/controller/ehcireg.h>
+#include <bus/u4b/usb_controller.h>
+#include <bus/u4b/usb_bus.h>
+#include <bus/u4b/controller/ehci.h>
+#include <bus/u4b/controller/ehcireg.h>
 
 #define        EHCI_BUS2SC(bus) \
    ((ehci_softc_t *)(((uint8_t *)(bus)) - \
@@ -307,8 +304,8 @@ ehci_init(ehci_softc_t *sc)
 
        DPRINTF("start\n");
 
-       usb_callout_init_mtx(&sc->sc_tmo_pcd, &sc->sc_bus.bus_mtx, 0);
-       usb_callout_init_mtx(&sc->sc_tmo_poll, &sc->sc_bus.bus_mtx, 0);
+       usb_callout_init_mtx(&sc->sc_tmo_pcd, &sc->sc_bus.bus_lock, 0);
+       usb_callout_init_mtx(&sc->sc_tmo_poll, &sc->sc_bus.bus_lock, 0);
 
        sc->sc_offs = EHCI_CAPLENGTH(EREAD4(sc, EHCI_CAPLEN_HCIVERSION));
 
@@ -614,75 +611,75 @@ ehci_dump_regs(ehci_softc_t *sc)
        uint32_t i;
 
        i = EOREAD4(sc, EHCI_USBCMD);
-       printf("cmd=0x%08x\n", i);
+       kprintf("cmd=0x%08x\n", i);
 
        if (i & EHCI_CMD_ITC_1)
-               printf(" EHCI_CMD_ITC_1\n");
+               kprintf(" EHCI_CMD_ITC_1\n");
        if (i & EHCI_CMD_ITC_2)
-               printf(" EHCI_CMD_ITC_2\n");
+               kprintf(" EHCI_CMD_ITC_2\n");
        if (i & EHCI_CMD_ITC_4)
-               printf(" EHCI_CMD_ITC_4\n");
+               kprintf(" EHCI_CMD_ITC_4\n");
        if (i & EHCI_CMD_ITC_8)
-               printf(" EHCI_CMD_ITC_8\n");
+               kprintf(" EHCI_CMD_ITC_8\n");
        if (i & EHCI_CMD_ITC_16)
-               printf(" EHCI_CMD_ITC_16\n");
+               kprintf(" EHCI_CMD_ITC_16\n");
        if (i & EHCI_CMD_ITC_32)
-               printf(" EHCI_CMD_ITC_32\n");
+               kprintf(" EHCI_CMD_ITC_32\n");
        if (i & EHCI_CMD_ITC_64)
-               printf(" EHCI_CMD_ITC_64\n");
+               kprintf(" EHCI_CMD_ITC_64\n");
        if (i & EHCI_CMD_ASPME)
-               printf(" EHCI_CMD_ASPME\n");
+               kprintf(" EHCI_CMD_ASPME\n");
        if (i & EHCI_CMD_ASPMC)
-               printf(" EHCI_CMD_ASPMC\n");
+               kprintf(" EHCI_CMD_ASPMC\n");
        if (i & EHCI_CMD_LHCR)
-               printf(" EHCI_CMD_LHCR\n");
+               kprintf(" EHCI_CMD_LHCR\n");
        if (i & EHCI_CMD_IAAD)
-               printf(" EHCI_CMD_IAAD\n");
+               kprintf(" EHCI_CMD_IAAD\n");
        if (i & EHCI_CMD_ASE)
-               printf(" EHCI_CMD_ASE\n");
+               kprintf(" EHCI_CMD_ASE\n");
        if (i & EHCI_CMD_PSE)
-               printf(" EHCI_CMD_PSE\n");
+               kprintf(" EHCI_CMD_PSE\n");
        if (i & EHCI_CMD_FLS_M)
-               printf(" EHCI_CMD_FLS_M\n");
+               kprintf(" EHCI_CMD_FLS_M\n");
        if (i & EHCI_CMD_HCRESET)
-               printf(" EHCI_CMD_HCRESET\n");
+               kprintf(" EHCI_CMD_HCRESET\n");
        if (i & EHCI_CMD_RS)
-               printf(" EHCI_CMD_RS\n");
+               kprintf(" EHCI_CMD_RS\n");
 
        i = EOREAD4(sc, EHCI_USBSTS);
 
-       printf("sts=0x%08x\n", i);
+       kprintf("sts=0x%08x\n", i);
 
        if (i & EHCI_STS_ASS)
-               printf(" EHCI_STS_ASS\n");
+               kprintf(" EHCI_STS_ASS\n");
        if (i & EHCI_STS_PSS)
-               printf(" EHCI_STS_PSS\n");
+               kprintf(" EHCI_STS_PSS\n");
        if (i & EHCI_STS_REC)
-               printf(" EHCI_STS_REC\n");
+               kprintf(" EHCI_STS_REC\n");
        if (i & EHCI_STS_HCH)
-               printf(" EHCI_STS_HCH\n");
+               kprintf(" EHCI_STS_HCH\n");
        if (i & EHCI_STS_IAA)
-               printf(" EHCI_STS_IAA\n");
+               kprintf(" EHCI_STS_IAA\n");
        if (i & EHCI_STS_HSE)
-               printf(" EHCI_STS_HSE\n");
+               kprintf(" EHCI_STS_HSE\n");
        if (i & EHCI_STS_FLR)
-               printf(" EHCI_STS_FLR\n");
+               kprintf(" EHCI_STS_FLR\n");
        if (i & EHCI_STS_PCD)
-               printf(" EHCI_STS_PCD\n");
+               kprintf(" EHCI_STS_PCD\n");
        if (i & EHCI_STS_ERRINT)
-               printf(" EHCI_STS_ERRINT\n");
+               kprintf(" EHCI_STS_ERRINT\n");
        if (i & EHCI_STS_INT)
-               printf(" EHCI_STS_INT\n");
+               kprintf(" EHCI_STS_INT\n");
 
-       printf("ien=0x%08x\n",
+       kprintf("ien=0x%08x\n",
            EOREAD4(sc, EHCI_USBINTR));
-       printf("frindex=0x%08x ctrdsegm=0x%08x periodic=0x%08x async=0x%08x\n",
+       kprintf("frindex=0x%08x ctrdsegm=0x%08x periodic=0x%08x async=0x%08x\n",
            EOREAD4(sc, EHCI_FRINDEX),
            EOREAD4(sc, EHCI_CTRLDSSEGMENT),
            EOREAD4(sc, EHCI_PERIODICLISTBASE),
            EOREAD4(sc, EHCI_ASYNCLISTADDR));
        for (i = 1; i <= sc->sc_noport; i++) {
-               printf("port %d status=0x%08x\n", i,
+               kprintf("port %d status=0x%08x\n", i,
                    EOREAD4(sc, EHCI_PORTSC(i)));
        }
 }
@@ -691,28 +688,28 @@ static void
 ehci_dump_link(ehci_softc_t *sc, uint32_t link, int type)
 {
        link = hc32toh(sc, link);
-       printf("0x%08x", link);
+       kprintf("0x%08x", link);
        if (link & EHCI_LINK_TERMINATE)
-               printf("<T>");
+               kprintf("<T>");
        else {
-               printf("<");
+               kprintf("<");
                if (type) {
                        switch (EHCI_LINK_TYPE(link)) {
                        case EHCI_LINK_ITD:
-                               printf("ITD");
+                               kprintf("ITD");
                                break;
                        case EHCI_LINK_QH:
-                               printf("QH");
+                               kprintf("QH");
                                break;
                        case EHCI_LINK_SITD:
-                               printf("SITD");
+                               kprintf("SITD");
                                break;
                        case EHCI_LINK_FSTN:
-                               printf("FSTN");
+                               kprintf("FSTN");
                                break;
                        }
                }
-               printf(">");
+               kprintf(">");
        }
 }
 
@@ -721,16 +718,16 @@ ehci_dump_qtd(ehci_softc_t *sc, ehci_qtd_t *qtd)
 {
        uint32_t s;
 
-       printf("  next=");
+       kprintf("  next=");
        ehci_dump_link(sc, qtd->qtd_next, 0);
-       printf(" altnext=");
+       kprintf(" altnext=");
        ehci_dump_link(sc, qtd->qtd_altnext, 0);
-       printf("\n");
+       kprintf("\n");
        s = hc32toh(sc, qtd->qtd_status);
-       printf("  status=0x%08x: toggle=%d bytes=0x%x ioc=%d c_page=0x%x\n",
+       kprintf("  status=0x%08x: toggle=%d bytes=0x%x ioc=%d c_page=0x%x\n",
            s, EHCI_QTD_GET_TOGGLE(s), EHCI_QTD_GET_BYTES(s),
            EHCI_QTD_GET_IOC(s), EHCI_QTD_GET_C_PAGE(s));
-       printf("    cerr=%d pid=%d stat=%s%s%s%s%s%s%s%s\n",
+       kprintf("    cerr=%d pid=%d stat=%s%s%s%s%s%s%s%s\n",
            EHCI_QTD_GET_CERR(s), EHCI_QTD_GET_PID(s),
            (s & EHCI_QTD_ACTIVE) ? "ACTIVE" : "NOT_ACTIVE",
            (s & EHCI_QTD_HALTED) ? "-HALTED" : "",
@@ -742,11 +739,11 @@ ehci_dump_qtd(ehci_softc_t *sc, ehci_qtd_t *qtd)
            (s & EHCI_QTD_PINGSTATE) ? "-PING" : "");
 
        for (s = 0; s < 5; s++) {
-               printf("  buffer[%d]=0x%08x\n", s,
+               kprintf("  buffer[%d]=0x%08x\n", s,
                    hc32toh(sc, qtd->qtd_buffer[s]));
        }
        for (s = 0; s < 5; s++) {
-               printf("  buffer_hi[%d]=0x%08x\n", s,
+               kprintf("  buffer_hi[%d]=0x%08x\n", s,
                    hc32toh(sc, qtd->qtd_buffer_hi[s]));
        }
 }
@@ -757,7 +754,7 @@ ehci_dump_sqtd(ehci_softc_t *sc, ehci_qtd_t *sqtd)
        uint8_t temp;
 
        usb_pc_cpu_invalidate(sqtd->page_cache);
-       printf("QTD(%p) at 0x%08x:\n", sqtd, hc32toh(sc, sqtd->qtd_self));
+       kprintf("QTD(%p) at 0x%08x:\n", sqtd, hc32toh(sc, sqtd->qtd_self));
        ehci_dump_qtd(sc, sqtd);
        temp = (sqtd->qtd_next & htohc32(sc, EHCI_LINK_TERMINATE)) ? 1 : 0;
        return (temp);
@@ -774,7 +771,7 @@ ehci_dump_sqtds(ehci_softc_t *sc, ehci_qtd_t *sqtd)
                stop = ehci_dump_sqtd(sc, sqtd);
        }
        if (sqtd) {
-               printf("dump aborted, too many TDs\n");
+               kprintf("dump aborted, too many TDs\n");
        }
 }
 
@@ -785,29 +782,29 @@ ehci_dump_sqh(ehci_softc_t *sc, ehci_qh_t *qh)
        uint32_t endphub;
 
        usb_pc_cpu_invalidate(qh->page_cache);
-       printf("QH(%p) at 0x%08x:\n", qh, hc32toh(sc, qh->qh_self) & ~0x1F);
-       printf("  link=");
+       kprintf("QH(%p) at 0x%08x:\n", qh, hc32toh(sc, qh->qh_self) & ~0x1F);
+       kprintf("  link=");
        ehci_dump_link(sc, qh->qh_link, 1);
-       printf("\n");
+       kprintf("\n");
        endp = hc32toh(sc, qh->qh_endp);
-       printf("  endp=0x%08x\n", endp);
-       printf("    addr=0x%02x inact=%d endpt=%d eps=%d dtc=%d hrecl=%d\n",
+       kprintf("  endp=0x%08x\n", endp);
+       kprintf("    addr=0x%02x inact=%d endpt=%d eps=%d dtc=%d hrecl=%d\n",
            EHCI_QH_GET_ADDR(endp), EHCI_QH_GET_INACT(endp),
            EHCI_QH_GET_ENDPT(endp), EHCI_QH_GET_EPS(endp),
            EHCI_QH_GET_DTC(endp), EHCI_QH_GET_HRECL(endp));
-       printf("    mpl=0x%x ctl=%d nrl=%d\n",
+       kprintf("    mpl=0x%x ctl=%d nrl=%d\n",
            EHCI_QH_GET_MPL(endp), EHCI_QH_GET_CTL(endp),
            EHCI_QH_GET_NRL(endp));
        endphub = hc32toh(sc, qh->qh_endphub);
-       printf("  endphub=0x%08x\n", endphub);
-       printf("    smask=0x%02x cmask=0x%02x huba=0x%02x port=%d mult=%d\n",
+       kprintf("  endphub=0x%08x\n", endphub);
+       kprintf("    smask=0x%02x cmask=0x%02x huba=0x%02x port=%d mult=%d\n",
            EHCI_QH_GET_SMASK(endphub), EHCI_QH_GET_CMASK(endphub),
            EHCI_QH_GET_HUBA(endphub), EHCI_QH_GET_PORT(endphub),
            EHCI_QH_GET_MULT(endphub));
-       printf("  curqtd=");
+       kprintf("  curqtd=");
        ehci_dump_link(sc, qh->qh_curqtd, 0);
-       printf("\n");
-       printf("Overlay qTD:\n");
+       kprintf("\n");
+       kprintf("Overlay qTD:\n");
        ehci_dump_qtd(sc, (void *)&qh->qh_qtd);
 }
 
@@ -815,9 +812,9 @@ static void
 ehci_dump_sitd(ehci_softc_t *sc, ehci_sitd_t *sitd)
 {
        usb_pc_cpu_invalidate(sitd->page_cache);
-       printf("SITD(%p) at 0x%08x\n", sitd, hc32toh(sc, sitd->sitd_self) & ~0x1F);
-       printf(" next=0x%08x\n", hc32toh(sc, sitd->sitd_next));
-       printf(" portaddr=0x%08x dir=%s addr=%d endpt=0x%x port=0x%x huba=0x%x\n",
+       kprintf("SITD(%p) at 0x%08x\n", sitd, hc32toh(sc, sitd->sitd_self) & ~0x1F);
+       kprintf(" next=0x%08x\n", hc32toh(sc, sitd->sitd_next));
+       kprintf(" portaddr=0x%08x dir=%s addr=%d endpt=0x%x port=0x%x huba=0x%x\n",
            hc32toh(sc, sitd->sitd_portaddr),
            (sitd->sitd_portaddr & htohc32(sc, EHCI_SITD_SET_DIR_IN))
            ? "in" : "out",
@@ -825,11 +822,11 @@ ehci_dump_sitd(ehci_softc_t *sc, ehci_sitd_t *sitd)
            EHCI_SITD_GET_ENDPT(hc32toh(sc, sitd->sitd_portaddr)),
            EHCI_SITD_GET_PORT(hc32toh(sc, sitd->sitd_portaddr)),
            EHCI_SITD_GET_HUBA(hc32toh(sc, sitd->sitd_portaddr)));
-       printf(" mask=0x%08x\n", hc32toh(sc, sitd->sitd_mask));
-       printf(" status=0x%08x <%s> len=0x%x\n", hc32toh(sc, sitd->sitd_status),
+       kprintf(" mask=0x%08x\n", hc32toh(sc, sitd->sitd_mask));
+       kprintf(" status=0x%08x <%s> len=0x%x\n", hc32toh(sc, sitd->sitd_status),
            (sitd->sitd_status & htohc32(sc, EHCI_SITD_ACTIVE)) ? "ACTIVE" : "",
            EHCI_SITD_GET_LEN(hc32toh(sc, sitd->sitd_status)));
-       printf(" back=0x%08x, bp=0x%08x,0x%08x,0x%08x,0x%08x\n",
+       kprintf(" back=0x%08x, bp=0x%08x,0x%08x,0x%08x,0x%08x\n",
            hc32toh(sc, sitd->sitd_back),
            hc32toh(sc, sitd->sitd_bp[0]),
            hc32toh(sc, sitd->sitd_bp[1]),
@@ -841,39 +838,39 @@ static void
 ehci_dump_itd(ehci_softc_t *sc, ehci_itd_t *itd)
 {
        usb_pc_cpu_invalidate(itd->page_cache);
-       printf("ITD(%p) at 0x%08x\n", itd, hc32toh(sc, itd->itd_self) & ~0x1F);
-       printf(" next=0x%08x\n", hc32toh(sc, itd->itd_next));
-       printf(" status[0]=0x%08x; <%s>\n", hc32toh(sc, itd->itd_status[0]),
+       kprintf("ITD(%p) at 0x%08x\n", itd, hc32toh(sc, itd->itd_self) & ~0x1F);
+       kprintf(" next=0x%08x\n", hc32toh(sc, itd->itd_next));
+       kprintf(" status[0]=0x%08x; <%s>\n", hc32toh(sc, itd->itd_status[0]),
            (itd->itd_status[0] & htohc32(sc, EHCI_ITD_ACTIVE)) ? "ACTIVE" : "");
-       printf(" status[1]=0x%08x; <%s>\n", hc32toh(sc, itd->itd_status[1]),
+       kprintf(" status[1]=0x%08x; <%s>\n", hc32toh(sc, itd->itd_status[1]),
            (itd->itd_status[1] & htohc32(sc, EHCI_ITD_ACTIVE)) ? "ACTIVE" : "");
-       printf(" status[2]=0x%08x; <%s>\n", hc32toh(sc, itd->itd_status[2]),
+       kprintf(" status[2]=0x%08x; <%s>\n", hc32toh(sc, itd->itd_status[2]),
            (itd->itd_status[2] & htohc32(sc, EHCI_ITD_ACTIVE)) ? "ACTIVE" : "");
-       printf(" status[3]=0x%08x; <%s>\n", hc32toh(sc, itd->itd_status[3]),
+       kprintf(" status[3]=0x%08x; <%s>\n", hc32toh(sc, itd->itd_status[3]),
            (itd->itd_status[3] & htohc32(sc, EHCI_ITD_ACTIVE)) ? "ACTIVE" : "");
-       printf(" status[4]=0x%08x; <%s>\n", hc32toh(sc, itd->itd_status[4]),
+       kprintf(" status[4]=0x%08x; <%s>\n", hc32toh(sc, itd->itd_status[4]),
            (itd->itd_status[4] & htohc32(sc, EHCI_ITD_ACTIVE)) ? "ACTIVE" : "");
-       printf(" status[5]=0x%08x; <%s>\n", hc32toh(sc, itd->itd_status[5]),
+       kprintf(" status[5]=0x%08x; <%s>\n", hc32toh(sc, itd->itd_status[5]),
            (itd->itd_status[5] & htohc32(sc, EHCI_ITD_ACTIVE)) ? "ACTIVE" : "");
-       printf(" status[6]=0x%08x; <%s>\n", hc32toh(sc, itd->itd_status[6]),
+       kprintf(" status[6]=0x%08x; <%s>\n", hc32toh(sc, itd->itd_status[6]),
            (itd->itd_status[6] & htohc32(sc, EHCI_ITD_ACTIVE)) ? "ACTIVE" : "");
-       printf(" status[7]=0x%08x; <%s>\n", hc32toh(sc, itd->itd_status[7]),
+       kprintf(" status[7]=0x%08x; <%s>\n", hc32toh(sc, itd->itd_status[7]),
            (itd->itd_status[7] & htohc32(sc, EHCI_ITD_ACTIVE)) ? "ACTIVE" : "");
-       printf(" bp[0]=0x%08x\n", hc32toh(sc, itd->itd_bp[0]));
-       printf("  addr=0x%02x; endpt=0x%01x\n",
+       kprintf(" bp[0]=0x%08x\n", hc32toh(sc, itd->itd_bp[0]));
+       kprintf("  addr=0x%02x; endpt=0x%01x\n",
            EHCI_ITD_GET_ADDR(hc32toh(sc, itd->itd_bp[0])),
            EHCI_ITD_GET_ENDPT(hc32toh(sc, itd->itd_bp[0])));
-       printf(" bp[1]=0x%08x\n", hc32toh(sc, itd->itd_bp[1]));
-       printf(" dir=%s; mpl=0x%02x\n",
+       kprintf(" bp[1]=0x%08x\n", hc32toh(sc, itd->itd_bp[1]));
+       kprintf(" dir=%s; mpl=0x%02x\n",
            (hc32toh(sc, itd->itd_bp[1]) & EHCI_ITD_SET_DIR_IN) ? "in" : "out",
            EHCI_ITD_GET_MPL(hc32toh(sc, itd->itd_bp[1])));
-       printf(" bp[2..6]=0x%08x,0x%08x,0x%08x,0x%08x,0x%08x\n",
+       kprintf(" bp[2..6]=0x%08x,0x%08x,0x%08x,0x%08x,0x%08x\n",
            hc32toh(sc, itd->itd_bp[2]),
            hc32toh(sc, itd->itd_bp[3]),
            hc32toh(sc, itd->itd_bp[4]),
            hc32toh(sc, itd->itd_bp[5]),
            hc32toh(sc, itd->itd_bp[6]));
-       printf(" bp_hi=0x%08x,0x%08x,0x%08x,0x%08x,\n"
+       kprintf(" bp_hi=0x%08x,0x%08x,0x%08x,0x%08x,\n"
            "       0x%08x,0x%08x,0x%08x\n",
            hc32toh(sc, itd->itd_bp_hi[0]),
            hc32toh(sc, itd->itd_bp_hi[1]),
@@ -895,7 +892,7 @@ ehci_dump_isoc(ehci_softc_t *sc)
        pos = (EOREAD4(sc, EHCI_FRINDEX) / 8) &
            (EHCI_VIRTUAL_FRAMELIST_COUNT - 1);
 
-       printf("%s: isochronous dump from frame 0x%03x:\n",
+       kprintf("%s: isochronous dump from frame 0x%03x:\n",
            __FUNCTION__, pos);
 
        itd = sc->sc_isoc_hs_p_last[pos];
@@ -1407,8 +1404,7 @@ transferred:
 static void
 ehci_pcd_enable(ehci_softc_t *sc)
 {
-       USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
-
+       USB_BUS_LOCK_ASSERT(&sc->sc_bus);
        sc->sc_eintrs |= EHCI_STS_PCD;
        EOWRITE4(sc, EHCI_USBINTR, sc->sc_eintrs);
 
@@ -1492,7 +1488,7 @@ ehci_interrupt(ehci_softc_t *sc)
        status &= sc->sc_eintrs;
 
        if (status & EHCI_STS_HSE) {
-               printf("%s: unrecoverable error, "
+               kprintf("%s: unrecoverable error, "
                    "controller halted\n", __FUNCTION__);
 #ifdef USB_DEBUG
                ehci_dump_regs(sc);
@@ -1519,7 +1515,7 @@ ehci_interrupt(ehci_softc_t *sc)
                /* block unprocessed interrupts */
                sc->sc_eintrs &= ~status;
                EOWRITE4(sc, EHCI_USBINTR, sc->sc_eintrs);
-               printf("%s: blocking interrupts 0x%x\n", __FUNCTION__, status);
+               kprintf("%s: blocking interrupts 0x%x\n", __FUNCTION__, status);
        }
        /* poll all the USB transfers */
        ehci_interrupt_poll(sc);
@@ -1543,7 +1539,7 @@ ehci_timeout(void *arg)
 
        DPRINTF("xfer=%p\n", xfer);
 
-       USB_BUS_LOCK_ASSERT(xfer->xroot->bus, MA_OWNED);
+       USB_BUS_LOCK_ASSERT(xfer->xroot->bus);
 
        /* transfer is transferred */
        ehci_device_done(xfer, USB_ERR_TIMEOUT);
@@ -2007,7 +2003,7 @@ ehci_root_intr(ehci_softc_t *sc)
        uint16_t i;
        uint16_t m;
 
-       USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
+       USB_BUS_LOCK_ASSERT(&sc->sc_bus);
 
        /* clear any old interrupt data */
        memset(sc->sc_hub_idata, 0, sizeof(sc->sc_hub_idata));
@@ -2160,7 +2156,7 @@ ehci_device_done(struct usb_xfer *xfer, usb_error_t error)
        struct usb_pipe_methods *methods = xfer->endpoint->methods;
        ehci_softc_t *sc = EHCI_BUS2SC(xfer->xroot->bus);
 
-       USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
+       USB_BUS_LOCK_ASSERT(&sc->sc_bus);
 
        DPRINTFN(2, "xfer=%p, endpoint=%p, error=%d\n",
            xfer, xfer->endpoint, error);
@@ -2539,7 +2535,7 @@ ehci_device_isoc_fs_enter(struct usb_xfer *xfer)
 #ifdef USB_DEBUG
                        if (once) {
                                once = 0;
-                               printf("%s: frame length(%d) exceeds %d "
+                               kprintf("%s: frame length(%d) exceeds %d "
                                    "bytes (frame truncated)\n",
                                    __FUNCTION__, *plen,
                                    xfer->max_frame_size);
@@ -2825,7 +2821,7 @@ ehci_device_isoc_hs_enter(struct usb_xfer *xfer)
 #ifdef USB_DEBUG
                        if (once) {
                                once = 0;
-                               printf("%s: frame length(%d) exceeds %d bytes "
+                               kprintf("%s: frame length(%d) exceeds %d bytes "
                                    "(frame truncated)\n",
                                    __FUNCTION__, *plen, xfer->max_frame_size);
                        }
@@ -3048,7 +3044,7 @@ ehci_roothub_exec(struct usb_device *udev,
        uint16_t index;
        usb_error_t err;
 
-       USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
+       USB_BUS_LOCK_ASSERT(&sc->sc_bus);
 
        /* buffer reset */
        ptr = (const void *)&sc->sc_hub_desc;
@@ -3204,13 +3200,13 @@ ehci_roothub_exec(struct usb_device *udev,
                                EOWRITE4(sc, port, v | EHCI_PS_FPR);
                        }
                        /* wait 20ms for resume sequence to complete */
-                       usb_pause_mtx(&sc->sc_bus.bus_mtx, hz / 50);
+                       usb_pause_mtx(&sc->sc_bus.bus_lock, hz / 50);
 
                        EOWRITE4(sc, port, v & ~(EHCI_PS_SUSP |
                            EHCI_PS_FPR | (3 << 10) /* High Speed */ ));
 
                        /* 4ms settle time */
-                       usb_pause_mtx(&sc->sc_bus.bus_mtx, hz / 250);
+                       usb_pause_mtx(&sc->sc_bus.bus_lock, hz / 250);
                        break;
                case UHF_PORT_POWER:
                        EOWRITE4(sc, port, v & ~EHCI_PS_PP);
@@ -3364,7 +3360,7 @@ ehci_roothub_exec(struct usb_device *udev,
                        EOWRITE4(sc, port, v | EHCI_PS_PR);
 
                        /* Wait for reset to complete. */
-                       usb_pause_mtx(&sc->sc_bus.bus_mtx,
+                       usb_pause_mtx(&sc->sc_bus.bus_lock,
                            USB_MS_TO_TICKS(USB_PORT_ROOT_RESET_DELAY));
 
                        /* Terminate reset sequence. */
@@ -3372,7 +3368,7 @@ ehci_roothub_exec(struct usb_device *udev,
                                EOWRITE4(sc, port, v);
 
                        /* Wait for HC to complete reset. */
-                       usb_pause_mtx(&sc->sc_bus.bus_mtx,
+                       usb_pause_mtx(&sc->sc_bus.bus_lock,
                            USB_MS_TO_TICKS(EHCI_PORT_RESET_COMPLETE));
 
                        v = EOREAD4(sc, port);
index e293ec8..d8ef48d 100644 (file)
@@ -29,7 +29,6 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
 
 /*
  * USB Enhanced Host Controller Driver, a.k.a. USB 2.0 controller.
@@ -46,7 +45,6 @@ __FBSDID("$FreeBSD$");
  */
 
 #include <sys/stdint.h>
-#include <sys/stddef.h>
 #include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/types.h>
@@ -55,28 +53,26 @@ __FBSDID("$FreeBSD$");
 #include <sys/bus.h>
 #include <sys/module.h>
 #include <sys/lock.h>
-#include <sys/mutex.h>
 #include <sys/condvar.h>
 #include <sys/sysctl.h>
-#include <sys/sx.h>
 #include <sys/unistd.h>
 #include <sys/callout.h>
 #include <sys/malloc.h>
 #include <sys/priv.h>
 
-#include <dev/usb/usb.h>
-#include <dev/usb/usbdi.h>
+#include <bus/u4b/usb.h>
+#include <bus/u4b/usbdi.h>
 
-#include <dev/usb/usb_core.h>
-#include <dev/usb/usb_busdma.h>
-#include <dev/usb/usb_process.h>
-#include <dev/usb/usb_util.h>
+#include <bus/u4b/usb_core.h>
+#include <bus/u4b/usb_busdma.h>
+#include <bus/u4b/usb_process.h>
+#include <bus/u4b/usb_util.h>
 
-#include <dev/usb/usb_controller.h>
-#include <dev/usb/usb_bus.h>
-#include <dev/usb/usb_pci.h>
-#include <dev/usb/controller/ehci.h>
-#include <dev/usb/controller/ehcireg.h>
+#include <bus/u4b/usb_controller.h>
+#include <bus/u4b/usb_bus.h>
+#include <bus/u4b/usb_pci.h>
+#include <bus/u4b/controller/ehci.h>
+#include <bus/u4b/controller/ehcireg.h>
 #include "usb_if.h"
 
 #define        PCI_EHCI_VENDORID_ACERLABS      0x10b9
@@ -320,56 +316,53 @@ ehci_pci_attach(device_t self)
        device_set_desc(sc->sc_bus.bdev, ehci_pci_match(self));
        switch (pci_get_vendor(self)) {
        case PCI_EHCI_VENDORID_ACERLABS:
-               sprintf(sc->sc_vendor, "AcerLabs");
+               ksprintf(sc->sc_vendor, "AcerLabs");
                break;
        case PCI_EHCI_VENDORID_AMD:
-               sprintf(sc->sc_vendor, "AMD");
+               ksprintf(sc->sc_vendor, "AMD");
                break;
        case PCI_EHCI_VENDORID_APPLE:
-               sprintf(sc->sc_vendor, "Apple");
+               ksprintf(sc->sc_vendor, "Apple");
                break;
        case PCI_EHCI_VENDORID_ATI:
-               sprintf(sc->sc_vendor, "ATI");
+               ksprintf(sc->sc_vendor, "ATI");
                break;
        case PCI_EHCI_VENDORID_CMDTECH:
-               sprintf(sc->sc_vendor, "CMDTECH");
+               ksprintf(sc->sc_vendor, "CMDTECH");
                break;
        case PCI_EHCI_VENDORID_INTEL:
-               sprintf(sc->sc_vendor, "Intel");
+               ksprintf(sc->sc_vendor, "Intel");
                break;
        case PCI_EHCI_VENDORID_NEC:
-               sprintf(sc->sc_vendor, "NEC");
+               ksprintf(sc->sc_vendor, "NEC");
                break;
        case PCI_EHCI_VENDORID_OPTI:
-               sprintf(sc->sc_vendor, "OPTi");
+               ksprintf(sc->sc_vendor, "OPTi");
                break;
        case PCI_EHCI_VENDORID_PHILIPS:
-               sprintf(sc->sc_vendor, "Philips");
+               ksprintf(sc->sc_vendor, "Philips");
                break;
        case PCI_EHCI_VENDORID_SIS:
-               sprintf(sc->sc_vendor, "SiS");
+               ksprintf(sc->sc_vendor, "SiS");
                break;
        case PCI_EHCI_VENDORID_NVIDIA:
        case PCI_EHCI_VENDORID_NVIDIA2:
-               sprintf(sc->sc_vendor, "nVidia");
+               ksprintf(sc->sc_vendor, "nVidia");
                break;
        case PCI_EHCI_VENDORID_VIA:
-               sprintf(sc->sc_vendor, "VIA");
+               ksprintf(sc->sc_vendor, "VIA");
                break;
        default:
                if (bootverbose)
                        device_printf(self, "(New EHCI DeviceId=0x%08x)\n",
                            pci_get_devid(self));
-               sprintf(sc->sc_vendor, "(0x%04x)", pci_get_vendor(self));
+               ksprintf(sc->sc_vendor, "(0x%04x)", pci_get_vendor(self));
        }
 
-#if (__FreeBSD_version >= 700031)
-       err = bus_setup_intr(self, sc->sc_irq_res, INTR_TYPE_BIO | INTR_MPSAFE,
-           NULL, (driver_intr_t *)ehci_interrupt, sc, &sc->sc_intr_hdl);
-#else
-       err = bus_setup_intr(self, sc->sc_irq_res, INTR_TYPE_BIO | INTR_MPSAFE,
-           (driver_intr_t *)ehci_interrupt, sc, &sc->sc_intr_hdl);
-#endif
+    /* XXX Can we make good use of the serialiser? */
+       err = bus_setup_intr(self, sc->sc_irq_res, INTR_MPSAFE,
+           (driver_intr_t *)ehci_interrupt, sc, &sc->sc_intr_hdl, NULL);
+
        if (err) {
                device_printf(self, "Could not setup irq, %d\n", err);
                sc->sc_intr_hdl = NULL;
@@ -455,7 +448,9 @@ ehci_pci_detach(device_t self)
                device_delete_child(self, bdev);
        }
        /* during module unload there are lots of children leftover */
+    /* XXX
        device_delete_children(self);
+    */
 
        pci_disable_busmaster(self);
 
@@ -543,7 +538,7 @@ static device_method_t ehci_pci_methods[] = {
        DEVMETHOD(device_shutdown, bus_generic_shutdown),
        DEVMETHOD(usb_take_controller, ehci_pci_take_controller),
 
-       DEVMETHOD_END
+    { 0, 0 }
 };
 
 static driver_t ehci_driver = {
index 93c2bb2..8b75319 100644 (file)
@@ -26,7 +26,6 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
 
 /*
  * USB Open Host Controller driver.
@@ -36,7 +35,6 @@ __FBSDID("$FreeBSD$");
  */
 
 #include <sys/stdint.h>
-#include <sys/stddef.h>
 #include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/types.h>
@@ -48,30 +46,29 @@ __FBSDID("$FreeBSD$");
 #include <sys/mutex.h>
 #include <sys/condvar.h>
 #include <sys/sysctl.h>
-#include <sys/sx.h>
 #include <sys/unistd.h>
 #include <sys/callout.h>
 #include <sys/malloc.h>
 #include <sys/priv.h>
 
-#include <dev/usb/usb.h>
-#include <dev/usb/usbdi.h>
+#include <bus/u4b/usb.h>
+#include <bus/u4b/usbdi.h>
 
 #define        USB_DEBUG_VAR ohcidebug
 
-#include <dev/usb/usb_core.h>
-#include <dev/usb/usb_debug.h>
-#include <dev/usb/usb_busdma.h>
-#include <dev/usb/usb_process.h>
-#include <dev/usb/usb_transfer.h>
-#include <dev/usb/usb_device.h>
-#include <dev/usb/usb_hub.h>
-#include <dev/usb/usb_util.h>
+#include <bus/u4b/usb_core.h>
+#include <bus/u4b/usb_debug.h>
+#include <bus/u4b/usb_busdma.h>
+#include <bus/u4b/usb_process.h>
+#include <bus/u4b/usb_transfer.h>
+#include <bus/u4b/usb_device.h>
+#include <bus/u4b/usb_hub.h>
+#include <bus/u4b/usb_util.h>
 
-#include <dev/usb/usb_controller.h>
-#include <dev/usb/usb_bus.h>
-#include <dev/usb/controller/ohci.h>
-#include <dev/usb/controller/ohcireg.h>
+#include <bus/u4b/usb_controller.h>
+#include <bus/u4b/usb_bus.h>
+#include <bus/u4b/controller/ohci.h>
+#include <bus/u4b/controller/ohcireg.h>
 
 #define        OHCI_BUS2SC(bus) \
    ((ohci_softc_t *)(((uint8_t *)(bus)) - \
@@ -405,15 +402,15 @@ ohci_init(ohci_softc_t *sc)
        /* set up the bus struct */
        sc->sc_bus.methods = &ohci_bus_methods;
 
-       usb_callout_init_mtx(&sc->sc_tmo_rhsc, &sc->sc_bus.bus_mtx, 0);
+       usb_callout_init_mtx(&sc->sc_tmo_rhsc, &sc->sc_bus.bus_lock, 0);
 
 #ifdef USB_DEBUG
        if (ohcidebug > 15) {
                for (i = 0; i != OHCI_NO_EDS; i++) {
-                       printf("ed#%d ", i);
+                       kprintf("ed#%d ", i);
                        ohci_dump_ed(sc->sc_intr_p_last[i]);
                }
-               printf("iso ");
+               kprintf("iso ");
                ohci_dump_ed(sc->sc_isoc_p_last);
        }
 #endif
@@ -545,7 +542,7 @@ ohci_dump_td(ohci_td_t *std)
        td_flags = le32toh(std->td_flags);
        temp = (std->td_next == 0);
 
-       printf("TD(%p) at 0x%08x: %s%s%s%s%s delay=%d ec=%d "
+       kprintf("TD(%p) at 0x%08x: %s%s%s%s%s delay=%d ec=%d "
            "cc=%d\ncbp=0x%08x next=0x%08x be=0x%08x\n",
            std, le32toh(std->td_self),
            (td_flags & OHCI_TD_R) ? "-R" : "",
@@ -575,7 +572,7 @@ ohci_dump_itd(ohci_itd_t *sitd)
        itd_flags = le32toh(sitd->itd_flags);
        temp = (sitd->itd_next == 0);
 
-       printf("ITD(%p) at 0x%08x: sf=%d di=%d fc=%d cc=%d\n"
+       kprintf("ITD(%p) at 0x%08x: sf=%d di=%d fc=%d cc=%d\n"
            "bp0=0x%08x next=0x%08x be=0x%08x\n",
            sitd, le32toh(sitd->itd_self),
            OHCI_ITD_GET_SF(itd_flags),
@@ -586,10 +583,10 @@ ohci_dump_itd(ohci_itd_t *sitd)
            le32toh(sitd->itd_next),
            le32toh(sitd->itd_be));
        for (i = 0; i < OHCI_ITD_NOFFSET; i++) {
-               printf("offs[%d]=0x%04x ", i,
+               kprintf("offs[%d]=0x%04x ", i,
                    (uint32_t)le16toh(sitd->itd_offset[i]));
        }
-       printf("\n");
+       kprintf("\n");
 
        return (temp);
 }
@@ -615,7 +612,7 @@ ohci_dump_ed(ohci_ed_t *sed)
        ed_flags = le32toh(sed->ed_flags);
        ed_headp = le32toh(sed->ed_headp);
 
-       printf("ED(%p) at 0x%08x: addr=%d endpt=%d maxp=%d flags=%s%s%s%s%s\n"
+       kprintf("ED(%p) at 0x%08x: addr=%d endpt=%d maxp=%d flags=%s%s%s%s%s\n"
            "tailp=0x%08x headflags=%s%s headp=0x%08x nexted=0x%08x\n",
            sed, le32toh(sed->ed_self),
            OHCI_ED_GET_FA(ed_flags),
@@ -662,7 +659,7 @@ _ohci_append_qh(ohci_ed_t *sed, ohci_ed_t *last)
                DPRINTFN(0, "ED already linked!\n");
                return (last);
        }
-       /* (sc->sc_bus.bus_mtx) must be locked */
+       /* (sc->sc_bus.bus_lock) must be locked */
 
        sed->next = last->next;
        sed->ed_next = last->ed_next;
@@ -690,7 +687,7 @@ _ohci_remove_qh(ohci_ed_t *sed, ohci_ed_t *last)
 {
        DPRINTFN(11, "%p from %p\n", sed, last);
 
-       /* (sc->sc_bus.bus_mtx) must be locked */
+       /* (sc->sc_bus.bus_lock) must be locked */
 
        /* only remove if not removed from a queue */
        if (sed->prev) {
@@ -1073,7 +1070,7 @@ ohci_rhsc_enable(ohci_softc_t *sc)
 {
        DPRINTFN(5, "\n");
 
-       USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
+       USB_BUS_LOCK_ASSERT(&sc->sc_bus);
 
        sc->sc_eintrs |= OHCI_RHSC;
        OWRITE4(sc, OHCI_INTERRUPT_ENABLE, OHCI_RHSC);
@@ -1178,11 +1175,11 @@ ohci_interrupt(ohci_softc_t *sc)
                }
 #endif
                if (status & OHCI_RD) {
-                       printf("%s: resume detect\n", __FUNCTION__);
+                       kprintf("%s: resume detect\n", __FUNCTION__);
                        /* XXX process resume detect */
                }
                if (status & OHCI_UE) {
-                       printf("%s: unrecoverable error, "
+                       kprintf("%s: unrecoverable error, "
                            "controller halted\n", __FUNCTION__);
                        OWRITE4(sc, OHCI_CONTROL, OHCI_HCFS_RESET);
                        /* XXX what else */
@@ -1207,7 +1204,7 @@ ohci_interrupt(ohci_softc_t *sc)
                /* Block unprocessed interrupts. XXX */
                OWRITE4(sc, OHCI_INTERRUPT_DISABLE, status);
                sc->sc_eintrs &= ~status;
-               printf("%s: blocking intrs 0x%x\n",
+               kprintf("%s: blocking intrs 0x%x\n",
                    __FUNCTION__, status);
        }
        /* poll all the USB transfers */
@@ -1227,7 +1224,7 @@ ohci_timeout(void *arg)
 
        DPRINTF("xfer=%p\n", xfer);
 
-       USB_BUS_LOCK_ASSERT(xfer->xroot->bus, MA_OWNED);
+       USB_BUS_LOCK_ASSERT(xfer->xroot->bus);
 
        /* transfer is transferred */
        ohci_device_done(xfer, USB_ERR_TIMEOUT);
@@ -1598,7 +1595,7 @@ ohci_root_intr(ohci_softc_t *sc)
        uint16_t i;
        uint16_t m;
 
-       USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
+       USB_BUS_LOCK_ASSERT(&sc->sc_bus);
 
        /* clear any old interrupt data */
        memset(sc->sc_hub_idata, 0, sizeof(sc->sc_hub_idata));
@@ -1634,7 +1631,7 @@ ohci_device_done(struct usb_xfer *xfer, usb_error_t error)
        ohci_softc_t *sc = OHCI_BUS2SC(xfer->xroot->bus);
        ohci_ed_t *ed;
 
-       USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
+       USB_BUS_LOCK_ASSERT(&sc->sc_bus);
 
 
        DPRINTFN(2, "xfer=%p, endpoint=%p, error=%d\n",
@@ -2104,7 +2101,7 @@ ohci_roothub_exec(struct usb_device *udev,
        uint8_t l;
        usb_error_t err;
 
-       USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
+       USB_BUS_LOCK_ASSERT(&sc->sc_bus);
 
        /* buffer reset */
        ptr = (const void *)&sc->sc_hub_desc.temp;
@@ -2348,7 +2345,7 @@ ohci_roothub_exec(struct usb_device *udev,
                        OWRITE4(sc, port, UPS_RESET);
                        for (v = 0;; v++) {
                                if (v < 12) {
-                                       usb_pause_mtx(&sc->sc_bus.bus_mtx,
+                                       usb_pause_mtx(&sc->sc_bus.bus_lock,
                                            USB_MS_TO_TICKS(USB_PORT_ROOT_RESET_DELAY));
 
                                        if ((OREAD4(sc, port) & UPS_RESET) == 0) {
index 864376b..335177c 100644 (file)
@@ -29,7 +29,6 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
 
 /*
  * USB Open Host Controller driver.
@@ -43,7 +42,6 @@ __FBSDID("$FreeBSD$");
  */
 
 #include <sys/stdint.h>
-#include <sys/stddef.h>
 #include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/types.h>
@@ -52,28 +50,26 @@ __FBSDID("$FreeBSD$");
 #include <sys/bus.h>
 #include <sys/module.h>
 #include <sys/lock.h>
-#include <sys/mutex.h>
 #include <sys/condvar.h>
 #include <sys/sysctl.h>
-#include <sys/sx.h>
 #include <sys/unistd.h>
 #include <sys/callout.h>
 #include <sys/malloc.h>
 #include <sys/priv.h>
 
-#include <dev/usb/usb.h>
-#include <dev/usb/usbdi.h>
+#include <bus/u4b/usb.h>
+#include <bus/u4b/usbdi.h>
 
-#include <dev/usb/usb_core.h>
-#include <dev/usb/usb_busdma.h>
-#include <dev/usb/usb_process.h>
-#include <dev/usb/usb_util.h>
+#include <bus/u4b/usb_core.h>
+#include <bus/u4b/usb_busdma.h>
+#include <bus/u4b/usb_process.h>
+#include <bus/u4b/usb_util.h>
 
-#include <dev/usb/usb_controller.h>
-#include <dev/usb/usb_bus.h>
-#include <dev/usb/usb_pci.h>
-#include <dev/usb/controller/ohci.h>
-#include <dev/usb/controller/ohcireg.h>
+#include <bus/u4b/usb_controller.h>
+#include <bus/u4b/usb_bus.h>
+#include <bus/u4b/usb_pci.h>
+#include <bus/u4b/controller/ohci.h>
+#include <bus/u4b/controller/ohcireg.h>
 #include "usb_if.h"
 
 #define        PCI_OHCI_VENDORID_ACERLABS      0x10b9
@@ -252,53 +248,49 @@ ohci_pci_attach(device_t self)
        device_set_desc(sc->sc_bus.bdev, ohci_pci_match(self));
        switch (pci_get_vendor(self)) {
        case PCI_OHCI_VENDORID_ACERLABS:
-               sprintf(sc->sc_vendor, "AcerLabs");
+               ksprintf(sc->sc_vendor, "AcerLabs");
                break;
        case PCI_OHCI_VENDORID_AMD:
-               sprintf(sc->sc_vendor, "AMD");
+               ksprintf(sc->sc_vendor, "AMD");
                break;
        case PCI_OHCI_VENDORID_APPLE:
-               sprintf(sc->sc_vendor, "Apple");
+               ksprintf(sc->sc_vendor, "Apple");
                break;
        case PCI_OHCI_VENDORID_ATI:
-               sprintf(sc->sc_vendor, "ATI");
+               ksprintf(sc->sc_vendor, "ATI");
                break;
        case PCI_OHCI_VENDORID_CMDTECH:
-               sprintf(sc->sc_vendor, "CMDTECH");
+               ksprintf(sc->sc_vendor, "CMDTECH");
                break;
        case PCI_OHCI_VENDORID_NEC:
-               sprintf(sc->sc_vendor, "NEC");
+               ksprintf(sc->sc_vendor, "NEC");
                break;
        case PCI_OHCI_VENDORID_NVIDIA:
        case PCI_OHCI_VENDORID_NVIDIA2:
-               sprintf(sc->sc_vendor, "nVidia");
+               ksprintf(sc->sc_vendor, "nVidia");
                break;
        case PCI_OHCI_VENDORID_OPTI:
-               sprintf(sc->sc_vendor, "OPTi");
+               ksprintf(sc->sc_vendor, "OPTi");
                break;
        case PCI_OHCI_VENDORID_SIS:
-               sprintf(sc->sc_vendor, "SiS");
+               ksprintf(sc->sc_vendor, "SiS");
                break;
        case PCI_OHCI_VENDORID_SUN:
-               sprintf(sc->sc_vendor, "SUN");
+               ksprintf(sc->sc_vendor, "SUN");
                break;
        default:
                if (bootverbose) {
                        device_printf(self, "(New OHCI DeviceId=0x%08x)\n",
                            pci_get_devid(self));
                }
-               sprintf(sc->sc_vendor, "(0x%04x)", pci_get_vendor(self));
+               ksprintf(sc->sc_vendor, "(0x%04x)", pci_get_vendor(self));
        }
 
        /* sc->sc_bus.usbrev; set by ohci_init() */
 
-#if (__FreeBSD_version >= 700031)
-       err = bus_setup_intr(self, sc->sc_irq_res, INTR_TYPE_BIO | INTR_MPSAFE,
-           NULL, (driver_intr_t *)ohci_interrupt, sc, &sc->sc_intr_hdl);
-#else
-       err = bus_setup_intr(self, sc->sc_irq_res, INTR_TYPE_BIO | INTR_MPSAFE,
-           (driver_intr_t *)ohci_interrupt, sc, &sc->sc_intr_hdl);
-#endif
+       err = bus_setup_intr(self, sc->sc_irq_res, INTR_MPSAFE,
+           (driver_intr_t *)ohci_interrupt, sc, &sc->sc_intr_hdl, NULL);
+
        if (err) {
                device_printf(self, "Could not setup irq, %d\n", err);
                sc->sc_intr_hdl = NULL;
@@ -331,7 +323,9 @@ ohci_pci_detach(device_t self)
                device_delete_child(self, bdev);
        }
        /* during module unload there are lots of children leftover */
+    /* XXX Implement this
        device_delete_children(self);
+    */
 
        pci_disable_busmaster(self);
 
@@ -374,7 +368,7 @@ static device_method_t ohci_pci_methods[] = {
        DEVMETHOD(device_shutdown, bus_generic_shutdown),
        DEVMETHOD(usb_take_controller, ohci_pci_take_controller),
 
-       DEVMETHOD_END
+    { 0, 0 }
 };
 
 static driver_t ohci_driver = {
index d9091c9..fe15913 100644 (file)
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
 
 /*
  * USB Universal Host Controller driver.
- * Handles e.g. PIIX3 and PIIX4.
+ * hANDLES e.g. PIIX3 and PIIX4.
  *
  * UHCI spec: http://developer.intel.com/design/USB/UHCI11D.htm
  * USB spec:  http://www.usb.org/developers/docs/usbspec.zip
@@ -39,7 +38,6 @@ __FBSDID("$FreeBSD$");
  */
 
 #include <sys/stdint.h>
-#include <sys/stddef.h>
 #include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/types.h>
@@ -48,33 +46,31 @@ __FBSDID("$FreeBSD$");
 #include <sys/bus.h>
 #include <sys/module.h>
 #include <sys/lock.h>
-#include <sys/mutex.h>
 #include <sys/condvar.h>
 #include <sys/sysctl.h>
-#include <sys/sx.h>
 #include <sys/unistd.h>
 #include <sys/callout.h>
 #include <sys/malloc.h>
 #include <sys/priv.h>
 
-#include <dev/usb/usb.h>
-#include <dev/usb/usbdi.h>
+#include <bus/u4b/usb.h>
+#include <bus/u4b/usbdi.h>
 
 #define        USB_DEBUG_VAR uhcidebug
 
-#include <dev/usb/usb_core.h>
-#include <dev/usb/usb_debug.h>
-#include <dev/usb/usb_busdma.h>
-#include <dev/usb/usb_process.h>
-#include <dev/usb/usb_transfer.h>
-#include <dev/usb/usb_device.h>
-#include <dev/usb/usb_hub.h>
-#include <dev/usb/usb_util.h>
+#include <bus/u4b/usb_core.h>
+#include <bus/u4b/usb_debug.h>
+#include <bus/u4b/usb_busdma.h>
+#include <bus/u4b/usb_process.h>
+#include <bus/u4b/usb_transfer.h>
+#include <bus/u4b/usb_device.h>
+#include <bus/u4b/usb_hub.h>
+#include <bus/u4b/usb_util.h>
 
-#include <dev/usb/usb_controller.h>
-#include <dev/usb/usb_bus.h>
-#include <dev/usb/controller/uhci.h>
-#include <dev/usb/controller/uhcireg.h>
+#include <bus/u4b/usb_controller.h>
+#include <bus/u4b/usb_bus.h>
+#include <bus/u4b/controller/uhci.h>
+#include <bus/u4b/controller/uhcireg.h>
 
 #define        alt_next next
 #define        UHCI_BUS2SC(bus) \
@@ -280,7 +276,7 @@ uhci_restart(uhci_softc_t *sc)
 {
        struct usb_page_search buf_res;
 
-       USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
+       USB_BUS_LOCK_ASSERT(&sc->sc_bus);
 
        if (UREAD2(sc, UHCI_CMD) & UHCI_CMD_RS) {
                DPRINTFN(2, "Already started\n");
@@ -301,7 +297,7 @@ uhci_restart(uhci_softc_t *sc)
 
        /* wait 10 milliseconds */
 
-       usb_pause_mtx(&sc->sc_bus.bus_mtx, hz / 100);
+       usb_pause_mtx(&sc->sc_bus.bus_lock, hz / 100);
 
        /* check that controller has started */
 
@@ -317,7 +313,7 @@ uhci_reset(uhci_softc_t *sc)
 {
        uint16_t n;
 
-       USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
+       USB_BUS_LOCK_ASSERT(&sc->sc_bus);
 
        DPRINTF("resetting the HC\n");
 
@@ -331,7 +327,7 @@ uhci_reset(uhci_softc_t *sc)
 
        /* wait */
 
-       usb_pause_mtx(&sc->sc_bus.bus_mtx,
+       usb_pause_mtx(&sc->sc_bus.bus_lock,
            USB_MS_TO_TICKS(USB_BUS_RESET_DELAY));
 
        /* terminate all transfers */
@@ -344,7 +340,7 @@ uhci_reset(uhci_softc_t *sc)
        while (n--) {
                /* wait one millisecond */
 
-               usb_pause_mtx(&sc->sc_bus.bus_mtx, hz / 1000);
+               usb_pause_mtx(&sc->sc_bus.bus_lock, hz / 1000);
 
                if (!(UREAD2(sc, UHCI_CMD) & UHCI_CMD_HCRESET)) {
                        goto done_1;
@@ -360,7 +356,7 @@ done_1:
        while (n--) {
                /* wait one millisecond */
 
-               usb_pause_mtx(&sc->sc_bus.bus_mtx, hz / 1000);
+               usb_pause_mtx(&sc->sc_bus.bus_lock, hz / 1000);
 
                /* check if HC is stopped */
                if (UREAD2(sc, UHCI_STS) & UHCI_STS_HCH) {
@@ -389,7 +385,7 @@ done_2:
 static void
 uhci_start(uhci_softc_t *sc)
 {
-       USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
+       USB_BUS_LOCK_ASSERT(&sc->sc_bus);
 
        DPRINTFN(2, "enabling\n");
 
@@ -457,7 +453,7 @@ uhci_init(uhci_softc_t *sc)
 
        DPRINTF("start\n");
 
-       usb_callout_init_mtx(&sc->sc_root_intr, &sc->sc_bus.bus_mtx, 0);
+       usb_callout_init_mtx(&sc->sc_root_intr, &sc->sc_bus.bus_lock, 0);
 
 #ifdef USB_DEBUG
        if (uhcidebug > 2) {
@@ -743,7 +739,7 @@ uhci_dump_td(uhci_td_t *p)
         */
        temp = ((td_next & UHCI_PTR_T) || (td_next == 0));
 
-       printf("TD(%p) at 0x%08x = link=0x%08x status=0x%08x "
+       kprintf("TD(%p) at 0x%08x = link=0x%08x status=0x%08x "
            "token=0x%08x buffer=0x%08x\n",
            p,
            le32toh(p->td_self),
@@ -752,7 +748,7 @@ uhci_dump_td(uhci_td_t *p)
            td_token,
            le32toh(p->td_buffer));
 
-       printf("TD(%p) td_next=%s%s%s td_status=%s%s%s%s%s%s%s%s%s%s%s, errcnt=%d, actlen=%d pid=%02x,"
+       kprintf("TD(%p) td_next=%s%s%s td_status=%s%s%s%s%s%s%s%s%s%s%s, errcnt=%d, actlen=%d pid=%02x,"
            "addr=%d,endpt=%d,D=%d,maxlen=%d\n",
            p,
            (td_next & 1) ? "-T" : "",
@@ -896,7 +892,7 @@ _uhci_append_td(uhci_td_t *std, uhci_td_t *last)
 {
        DPRINTFN(11, "%p to %p\n", std, last);
 
-       /* (sc->sc_bus.mtx) must be locked */
+       /* (sc->sc_bus.lock) must be locked */
 
        std->next = last->next;
        std->td_next = last->td_next;
@@ -927,7 +923,7 @@ _uhci_append_qh(uhci_qh_t *sqh, uhci_qh_t *last)
                DPRINTFN(0, "QH already linked!\n");
                return (last);
        }
-       /* (sc->sc_bus.mtx) must be locked */
+       /* (sc->sc_bus.lock) must be locked */
 
        sqh->h_next = last->h_next;
        sqh->qh_h_next = last->qh_h_next;
@@ -958,7 +954,7 @@ _uhci_remove_td(uhci_td_t *std, uhci_td_t *last)
 {
        DPRINTFN(11, "%p from %p\n", std, last);
 
-       /* (sc->sc_bus.mtx) must be locked */
+       /* (sc->sc_bus.lock) must be locked */
 
        std->prev->next = std->next;
        std->prev->td_next = std->td_next;
@@ -978,7 +974,7 @@ _uhci_remove_qh(uhci_qh_t *sqh, uhci_qh_t *last)
 {
        DPRINTFN(11, "%p from %p\n", sqh, last);
 
-       /* (sc->sc_bus.mtx) must be locked */
+       /* (sc->sc_bus.lock) must be locked */
 
        /* only remove if not removed from a queue */
        if (sqh->h_prev) {
@@ -1443,16 +1439,16 @@ uhci_interrupt(uhci_softc_t *sc)
 
                if (status & UHCI_STS_RD) {
 #ifdef USB_DEBUG
-                       printf("%s: resume detect\n",
+                       kprintf("%s: resume detect\n",
                            __FUNCTION__);
 #endif
                }
                if (status & UHCI_STS_HSE) {
-                       printf("%s: host system error\n",
+                       kprintf("%s: host system error\n",
                            __FUNCTION__);
                }
                if (status & UHCI_STS_HCPE) {
-                       printf("%s: host controller process error\n",
+                       kprintf("%s: host controller process error\n",
                            __FUNCTION__);
                }
                if (status & UHCI_STS_HCH) {
@@ -1497,7 +1493,7 @@ uhci_timeout(void *arg)
 
        DPRINTF("xfer=%p\n", xfer);
 
-       USB_BUS_LOCK_ASSERT(xfer->xroot->bus, MA_OWNED);
+       USB_BUS_LOCK_ASSERT(xfer->xroot->bus);
 
        /* transfer is transferred */
        uhci_device_done(xfer, USB_ERR_TIMEOUT);
@@ -1842,7 +1838,7 @@ uhci_device_done(struct usb_xfer *xfer, usb_error_t error)
        uhci_softc_t *sc = UHCI_BUS2SC(xfer->xroot->bus);
        uhci_qh_t *qh;
 
-       USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
+       USB_BUS_LOCK_ASSERT(&sc->sc_bus);
 
        DPRINTFN(2, "xfer=%p, endpoint=%p, error=%d\n",
            xfer, xfer->endpoint, error);
@@ -2212,7 +2208,7 @@ uhci_device_isoc_enter(struct usb_xfer *xfer)
 #ifdef USB_DEBUG
                        if (once) {
                                once = 0;
-                               printf("%s: frame length(%d) exceeds %d "
+                               kprintf("%s: frame length(%d) exceeds %d "
                                    "bytes (frame truncated)\n",
                                    __FUNCTION__, *plen,
                                    xfer->max_frame_size);
@@ -2394,7 +2390,7 @@ uhci_portreset(uhci_softc_t *sc, uint16_t index)
        x = URWMASK(UREAD2(sc, port));
        UWRITE2(sc, port, x | UHCI_PORTSC_PR);
 
-       usb_pause_mtx(&sc->sc_bus.bus_mtx,
+       usb_pause_mtx(&sc->sc_bus.bus_lock,
            USB_MS_TO_TICKS(USB_PORT_ROOT_RESET_DELAY));
 
        DPRINTFN(4, "uhci port %d reset, status0 = 0x%04x\n",
@@ -2404,7 +2400,7 @@ uhci_portreset(uhci_softc_t *sc, uint16_t index)
        UWRITE2(sc, port, x & ~UHCI_PORTSC_PR);
 
 
-       mtx_unlock(&sc->sc_bus.bus_mtx);
+       lockmgr(&sc->sc_bus.bus_lock, LK_RELEASE);
 
        /* 
         * This delay needs to be exactly 100us, else some USB devices
@@ -2412,7 +2408,7 @@ uhci_portreset(uhci_softc_t *sc, uint16_t index)
         */
        DELAY(100);
 
-       mtx_lock(&sc->sc_bus.bus_mtx);
+       lockmgr(&sc->sc_bus.bus_lock, LK_EXCLUSIVE);
 
        DPRINTFN(4, "uhci port %d reset, status1 = 0x%04x\n",
            index, UREAD2(sc, port));
@@ -2422,7 +2418,7 @@ uhci_portreset(uhci_softc_t *sc, uint16_t index)
 
        for (lim = 0; lim < 12; lim++) {
 
-               usb_pause_mtx(&sc->sc_bus.bus_mtx,
+               usb_pause_mtx(&sc->sc_bus.bus_lock,
                    USB_MS_TO_TICKS(USB_PORT_RESET_DELAY));
 
                x = UREAD2(sc, port);
@@ -2488,7 +2484,7 @@ uhci_roothub_exec(struct usb_device *udev,
        uint16_t len;
        usb_error_t err;
 
-       USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
+       USB_BUS_LOCK_ASSERT(&sc->sc_bus);
 
        /* buffer reset */
        ptr = (const void *)&sc->sc_hub_desc.temp;
@@ -2717,14 +2713,14 @@ uhci_roothub_exec(struct usb_device *udev,
                        UWRITE2(sc, port, URWMASK(x));
 
                        /* wait 20ms for resume sequence to complete */
-                       usb_pause_mtx(&sc->sc_bus.bus_mtx, hz / 50);
+                       usb_pause_mtx(&sc->sc_bus.bus_lock, hz / 50);
 
                        /* clear suspend and resume detect */
                        UWRITE2(sc, port, URWMASK(x) & ~(UHCI_PORTSC_RD |
                            UHCI_PORTSC_SUSP));
 
                        /* wait a little bit */
-                       usb_pause_mtx(&sc->sc_bus.bus_mtx, hz / 500);
+                       usb_pause_mtx(&sc->sc_bus.bus_lock, hz / 500);
 
                        sc->sc_isresumed |= (1 << index);
 
@@ -2802,7 +2798,7 @@ uhci_root_intr(uhci_softc_t *sc)
 {
        DPRINTFN(21, "\n");
 
-       USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
+       USB_BUS_LOCK_ASSERT(&sc->sc_bus);
 
        sc->sc_hub_idata[0] = 0;
 
index 454b904..15f4c0b 100644 (file)
@@ -29,7 +29,6 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
 
 /* Universal Host Controller Interface
  *
@@ -42,7 +41,6 @@ __FBSDID("$FreeBSD$");
  */
 
 #include <sys/stdint.h>
-#include <sys/stddef.h>
 #include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/types.h>
@@ -51,29 +49,27 @@ __FBSDID("$FreeBSD$");
 #include <sys/bus.h>
 #include <sys/module.h>
 #include <sys/lock.h>
-#include <sys/mutex.h>
 #include <sys/condvar.h>
 #include <sys/sysctl.h>
-#include <sys/sx.h>
 #include <sys/unistd.h>
 #include <sys/callout.h>
 #include <sys/malloc.h>
 #include <sys/priv.h>
 
-#include <dev/usb/usb.h>
-#include <dev/usb/usbdi.h>
+#include <bus/u4b/usb.h>
+#include <bus/u4b/usbdi.h>
 
-#include <dev/usb/usb_core.h>
-#include <dev/usb/usb_busdma.h>
-#include <dev/usb/usb_process.h>
-#include <dev/usb/usb_util.h>
-#include <dev/usb/usb_debug.h>
+#include <bus/u4b/usb_core.h>
+#include <bus/u4b/usb_busdma.h>
+#include <bus/u4b/usb_process.h>
+#include <bus/u4b/usb_util.h>
+#include <bus/u4b/usb_debug.h>
 
-#include <dev/usb/usb_controller.h>
-#include <dev/usb/usb_bus.h>
-#include <dev/usb/usb_pci.h>
-#include <dev/usb/controller/uhci.h>
-#include <dev/usb/controller/uhcireg.h>
+#include <bus/u4b/usb_controller.h>
+#include <bus/u4b/usb_bus.h>
+#include <bus/u4b/usb_pci.h>
+#include <bus/u4b/controller/uhci.h>
+#include <bus/u4b/controller/uhcireg.h>
 #include "usb_if.h"
 
 #define        PCI_UHCI_VENDORID_INTEL         0x8086
@@ -306,17 +302,17 @@ uhci_pci_attach(device_t self)
        device_set_desc(sc->sc_bus.bdev, uhci_pci_match(self));
        switch (pci_get_vendor(self)) {
        case PCI_UHCI_VENDORID_INTEL:
-               sprintf(sc->sc_vendor, "Intel");
+               ksprintf(sc->sc_vendor, "Intel");
                break;
        case PCI_UHCI_VENDORID_VIA:
-               sprintf(sc->sc_vendor, "VIA");
+               ksprintf(sc->sc_vendor, "VIA");
                break;
        default:
                if (bootverbose) {
                        device_printf(self, "(New UHCI DeviceId=0x%08x)\n",
                            pci_get_devid(self));
                }
-               sprintf(sc->sc_vendor, "(0x%04x)", pci_get_vendor(self));
+               ksprintf(sc->sc_vendor, "(0x%04x)", pci_get_vendor(self));
        }
 
        switch (pci_read_config(self, PCI_USBREV, 1) & PCI_USB_REV_MASK) {
@@ -333,13 +329,8 @@ uhci_pci_attach(device_t self)
                break;
        }
 
-#if (__FreeBSD_version >= 700031)
-       err = bus_setup_intr(self, sc->sc_irq_res, INTR_TYPE_BIO | INTR_MPSAFE,
-           NULL, (driver_intr_t *)uhci_interrupt, sc, &sc->sc_intr_hdl);
-#else
-       err = bus_setup_intr(self, sc->sc_irq_res, INTR_TYPE_BIO | INTR_MPSAFE,
-           (driver_intr_t *)uhci_interrupt, sc, &sc->sc_intr_hdl);
-#endif
+       err = bus_setup_intr(self, sc->sc_irq_res, INTR_MPSAFE,
+           (driver_intr_t *)uhci_interrupt, sc, &sc->sc_intr_hdl, NULL);
 
        if (err) {
                device_printf(self, "Could not setup irq, %d\n", err);
@@ -387,8 +378,9 @@ uhci_pci_detach(device_t self)
                device_delete_child(self, bdev);
        }
        /* during module unload there are lots of children leftover */
-       device_delete_children(self);
-
+/* XXX */
+/*     device_delete_children(self);
+*/
        /*
         * disable interrupts that might have been switched on in
         * uhci_init.
@@ -437,7 +429,7 @@ static device_method_t uhci_pci_methods[] = {
        DEVMETHOD(device_shutdown, bus_generic_shutdown),
        DEVMETHOD(usb_take_controller, uhci_pci_take_controller),
 
-       DEVMETHOD_END
+    { 0, 0 }
 };
 
 static driver_t uhci_driver = {
index 0f942e1..37e76e4 100644 (file)
@@ -27,7 +27,6 @@
 #include "opt_ddb.h"
 
 #include <sys/stdint.h>
-#include <sys/stddef.h>
 #include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/types.h>
 #include <sys/bus.h>
 #include <sys/module.h>
 #include <sys/lock.h>
-#include <sys/mutex.h>
 #include <sys/condvar.h>
 #include <sys/sysctl.h>
-#include <sys/sx.h>
 #include <sys/unistd.h>
 #include <sys/callout.h>
 #include <sys/malloc.h>
 #include <sys/priv.h>
 
-#include <dev/usb/usb.h>
-#include <dev/usb/usbdi.h>
+#include <bus/u4b/usb.h>
+#include <bus/u4b/usbdi.h>
 
 #define        USB_DEBUG_VAR usb_ctrl_debug
 
-#include <dev/usb/usb_core.h>
-#include <dev/usb/usb_debug.h>
-#include <dev/usb/usb_process.h>
-#include <dev/usb/usb_busdma.h>
-#include <dev/usb/usb_dynamic.h>
-#include <dev/usb/usb_device.h>
-#include <dev/usb/usb_hub.h>
-
-#include <dev/usb/usb_controller.h>
-#include <dev/usb/usb_bus.h>
-#include <dev/usb/usb_pf.h>
+#include <bus/u4b/usb_core.h>
+#include <bus/u4b/usb_debug.h>
+#include <bus/u4b/usb_process.h>
+#include <bus/u4b/usb_busdma.h>
+#include <bus/u4b/usb_dynamic.h>
+#include <bus/u4b/usb_device.h>
+#include <bus/u4b/usb_hub.h>
+
+#include <bus/u4b/usb_controller.h>
+#include <bus/u4b/usb_bus.h>
+#include <bus/u4b/usb_pf.h>
 #include "usb_if.h"
 
 /* function prototypes  */
@@ -86,12 +83,13 @@ SYSCTL_INT(_hw_usb_ctrl, OID_AUTO, debug, CTLFLAG_RW, &usb_ctrl_debug, 0,
 
 static int usb_no_boot_wait = 0;
 TUNABLE_INT("hw.usb.no_boot_wait", &usb_no_boot_wait);
-SYSCTL_INT(_hw_usb, OID_AUTO, no_boot_wait, CTLFLAG_RDTUN, &usb_no_boot_wait, 0,
+/* XXX freebsd uses CTLFLAG_RDTUN here */
+SYSCTL_INT(_hw_usb, OID_AUTO, no_boot_wait, CTLFLAG_RW, &usb_no_boot_wait, 0,
     "No USB device enumerate waiting at boot.");
 
 static int usb_no_shutdown_wait = 0;
 TUNABLE_INT("hw.usb.no_shutdown_wait", &usb_no_shutdown_wait);
-SYSCTL_INT(_hw_usb, OID_AUTO, no_shutdown_wait, CTLFLAG_RW|CTLFLAG_TUN, &usb_no_shutdown_wait, 0,
+SYSCTL_INT(_hw_usb, OID_AUTO, no_shutdown_wait, CTLFLAG_RW, &usb_no_shutdown_wait, 0,
     "No USB device waiting at system shutdown.");
 
 static devclass_t usb_devclass;
@@ -141,7 +139,8 @@ usb_root_mount_rel(struct usb_bus *bus)
 {
        if (bus->bus_roothold != NULL) {
                DPRINTF("Releasing root mount hold %p\n", bus->bus_roothold);
-               root_mount_rel(bus->bus_roothold);
+        /* XXX Dragonflybsd seems to not have this? */
+               /*root_mount_rel(bus->bus_roothold);*/
                bus->bus_roothold = NULL;
        }
 }
@@ -163,7 +162,10 @@ usb_attach(device_t dev)
 
        if (usb_no_boot_wait == 0) {
                /* delay vfs_mountroot until the bus is explored */
+        /* XXX: Dragonfly does not seem to have this mechanism? */
+        /*
                bus->bus_roothold = root_mount_hold(device_get_nameunit(dev));
+        */
        }
 
        usb_attach_sub(dev, bus);
@@ -190,7 +192,7 @@ usb_detach(device_t dev)
 
        /* Let the USB explore process detach all devices. */
        usb_root_mount_rel(bus);
-
+    
        USB_BUS_LOCK(bus);
 
        /* Queue detach job */
@@ -373,9 +375,7 @@ usb_bus_detach(struct usb_proc_msg *pm)
        USB_BUS_UNLOCK(bus);
 
        /* detach children first */
-       mtx_lock(&Giant);
        bus_generic_detach(dev);
-       mtx_unlock(&Giant);
 
        /*
         * Free USB device and all subdevices, if any.
@@ -538,8 +538,7 @@ static void
 usb_power_wdog(void *arg)
 {
        struct usb_bus *bus = arg;
-
-       USB_BUS_LOCK_ASSERT(bus, MA_OWNED);
+       USB_BUS_LOCK_ASSERT(bus);
 
        usb_callout_reset(&bus->power_wdog,
            4 * hz, usb_power_wdog, arg);
@@ -670,10 +669,8 @@ usb_attach_sub(device_t dev, struct usb_bus *bus)
 {
        const char *pname = device_get_nameunit(dev);
 
-       mtx_lock(&Giant);
        if (usb_devclass_ptr == NULL)
                usb_devclass_ptr = devclass_find("usbus");
-       mtx_unlock(&Giant);
 
 #if USB_HAVE_PF
        usbpf_attach(bus);
@@ -712,19 +709,19 @@ usb_attach_sub(device_t dev, struct usb_bus *bus)
        /* Create USB explore and callback processes */
 
        if (usb_proc_create(&bus->giant_callback_proc,
-           &bus->bus_mtx, pname, USB_PRI_MED)) {
+           &bus->bus_lock, pname, USB_PRI_MED)) {
                device_printf(dev, "WARNING: Creation of USB Giant "
                    "callback process failed.\n");
        } else if (usb_proc_create(&bus->non_giant_callback_proc,
-           &bus->bus_mtx, pname, USB_PRI_HIGH)) {
+           &bus->bus_lock, pname, USB_PRI_HIGH)) {
                device_printf(dev, "WARNING: Creation of USB non-Giant "
                    "callback process failed.\n");
        } else if (usb_proc_create(&bus->explore_proc,
-           &bus->bus_mtx, pname, USB_PRI_MED)) {
+           &bus->bus_lock, pname, USB_PRI_MED)) {
                device_printf(dev, "WARNING: Creation of USB explore "
                    "process failed.\n");
        } else if (usb_proc_create(&bus->control_xfer_proc,
-           &bus->bus_mtx, pname, USB_PRI_MED)) {
+           &bus->bus_lock, pname, USB_PRI_MED)) {
                device_printf(dev, "WARNING: Creation of USB control transfer "
                    "process failed.\n");
        } else {
@@ -739,7 +736,7 @@ usb_attach_sub(device_t dev, struct usb_bus *bus)
        }
 }
 
-SYSUNINIT(usb_bus_unload, SI_SUB_KLD, SI_ORDER_ANY, usb_bus_unload, NULL);
+SYSUNINIT(usb_bus_unload, SI_SUB_CONFIGURE, SI_ORDER_ANY, usb_bus_unload, NULL);
 
 /*------------------------------------------------------------------------*
  *     usb_bus_mem_flush_all_cb
@@ -795,18 +792,21 @@ usb_bus_mem_alloc_all(struct usb_bus *bus, bus_dma_tag_t dmat,
     usb_bus_mem_cb_t *cb)
 {
        bus->alloc_failed = 0;
-
-       mtx_init(&bus->bus_mtx, device_get_nameunit(bus->parent),
-           NULL, MTX_DEF | MTX_RECURSE);
+    /* XXX: Type mismatch, device_get_nameunit gives
+     * const char*, lockinit wants char *
+     */
+    const char *pname = device_get_nameunit(bus->parent);
+    kprintf("usb_bus_mem_alloc_all %s\n", pname);
+       lockinit(&bus->bus_lock, "USB bus mem", 0, LK_CANRECURSE);
 
        usb_callout_init_mtx(&bus->power_wdog,
-           &bus->bus_mtx, 0);
+           &bus->bus_lock, 0);
 
        TAILQ_INIT(&bus->intr_q.head);
 
 #if USB_HAVE_BUSDMA
        usb_dma_tag_setup(bus->dma_parent_tag, bus->dma_tags,
-           dmat, &bus->bus_mtx, NULL, 32, USB_BUS_DMA_TAG_MAX);
+           dmat, &bus->bus_lock, NULL, 32, USB_BUS_DMA_TAG_MAX);
 #endif
        if ((bus->devices_max > USB_MAX_DEVICES) ||
            (bus->devices_max < USB_MIN_DEVICES) ||
@@ -851,5 +851,5 @@ usb_bus_mem_free_all(struct usb_bus *bus, usb_bus_mem_cb_t *cb)
        usb_dma_tag_unsetup(bus->dma_parent_tag);
 #endif
 
-       mtx_destroy(&bus->bus_mtx);
+    lockuninit(&bus->bus_lock);
 }
index a9690f9..b7ed08a 100644 (file)
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
 
 #include <sys/stdint.h>
-#include <sys/stddef.h>
 #include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/types.h>
@@ -51,33 +49,31 @@ __FBSDID("$FreeBSD$");
 #include <sys/bus.h>
 #include <sys/module.h>
 #include <sys/lock.h>
-#include <sys/mutex.h>
 #include <sys/condvar.h>
 #include <sys/sysctl.h>
-#include <sys/sx.h>
 #include <sys/unistd.h>
 #include <sys/callout.h>
 #include <sys/malloc.h>
 #include <sys/priv.h>
 
-#include <dev/usb/usb.h>
-#include <dev/usb/usbdi.h>
+#include <bus/u4b/usb.h>
+#include <bus/u4b/usbdi.h>
 
 #define        USB_DEBUG_VAR xhcidebug
 
-#include <dev/usb/usb_core.h>
-#include <dev/usb/usb_debug.h>
-#include <dev/usb/usb_busdma.h>
-#include <dev/usb/usb_process.h>
-#include <dev/usb/usb_transfer.h>
-#include <dev/usb/usb_device.h>
-#include <dev/usb/usb_hub.h>
-#include <dev/usb/usb_util.h>
+#include <bus/u4b/usb_core.h>
+#include <bus/u4b/usb_debug.h>
+#include <bus/u4b/usb_busdma.h>
+#include <bus/u4b/usb_process.h>
+#include <bus/u4b/usb_transfer.h>
+#include <bus/u4b/usb_device.h>
+#include <bus/u4b/usb_hub.h>
+#include <bus/u4b/usb_util.h>
 
-#include <dev/usb/usb_controller.h>
-#include <dev/usb/usb_bus.h>
-#include <dev/usb/controller/xhci.h>
-#include <dev/usb/controller/xhcireg.h>
+#include <bus/u4b/usb_controller.h>
+#include <bus/u4b/usb_bus.h>
+#include <bus/u4b/controller/xhci.h>
+#include <bus/u4b/controller/xhcireg.h>
 
 #define        XHCI_BUS2SC(bus) \
    ((struct xhci_softc *)(((uint8_t *)(bus)) - \
@@ -518,7 +514,7 @@ xhci_init(struct xhci_softc *sc, device_t self)
 
        /* setup command queue mutex and condition varible */
        cv_init(&sc->sc_cmd_cv, "CMDQ");
-       sx_init(&sc->sc_cmd_sx, "CMDQ lock");
+    lockinit(&sc->sc_cmd_lock, "CMDQ lock", 0, 0);
 
        /* get all DMA memory */
        if (usb_bus_mem_alloc_all(&sc->sc_bus,
@@ -532,8 +528,8 @@ xhci_init(struct xhci_softc *sc, device_t self)
         sc->sc_config_msg[1].bus = &sc->sc_bus;
 
        if (usb_proc_create(&sc->sc_config_proc,
-           &sc->sc_bus.bus_mtx, device_get_nameunit(self), USB_PRI_MED)) {
-                printf("WARNING: Creation of XHCI configure "
+           &sc->sc_bus.bus_lock, device_get_nameunit(self), USB_PRI_MED)) {
+                kprintf("WARNING: Creation of XHCI configure "
                     "callback process failed.\n");
         }
        return (0);
@@ -547,7 +543,7 @@ xhci_uninit(struct xhci_softc *sc)
        usb_bus_mem_free_all(&sc->sc_bus, &xhci_iterate_hw_softc);
 
        cv_destroy(&sc->sc_cmd_cv);
-       sx_destroy(&sc->sc_cmd_sx);
+       lockuninit(&sc->sc_cmd_lock);
 }
 
 static void
@@ -1076,7 +1072,7 @@ xhci_do_command(struct xhci_softc *sc, struct xhci_trb *trb,
 
        XWRITE4(sc, door, XHCI_DOORBELL(0), 0);
 
-       err = cv_timedwait(&sc->sc_cmd_cv, &sc->sc_bus.bus_mtx,
+       err = cv_timedwait(&sc->sc_cmd_cv, &sc->sc_bus.bus_lock,
            USB_MS_TO_TICKS(timeout_ms));
 
        if (err) {
@@ -1183,7 +1179,7 @@ xhci_cmd_set_address(struct xhci_softc *sc, uint64_t input_ctx,
 }
 
 static usb_error_t
-xhci_set_address(struct usb_device *udev, struct mtx *mtx, uint16_t address)
+xhci_set_address(struct usb_device *udev, struct lock *lock, uint16_t address)
 {
        struct usb_page_search buf_inp;
        struct usb_page_search buf_dev;
@@ -1204,8 +1200,8 @@ xhci_set_address(struct usb_device *udev, struct mtx *mtx, uint16_t address)
 
        hdev =  &sc->sc_hw.devs[index];
 
-       if (mtx != NULL)
-               mtx_unlock(mtx);
+       if (lock != NULL)
+               lockmgr(lock, LK_RELEASE);
 
        XHCI_CMD_LOCK(sc);
 
@@ -1288,8 +1284,8 @@ xhci_set_address(struct usb_device *udev, struct mtx *mtx, uint16_t address)
        }
        XHCI_CMD_UNLOCK(sc);
 
-       if (mtx != NULL)
-               mtx_lock(mtx);
+       if (lock != NULL)
+               lockmgr(lock, LK_EXCLUSIVE);
 
        return (err);
 }
@@ -1452,17 +1448,17 @@ xhci_interrupt(struct xhci_softc *sc)
                }
 
                if (status & XHCI_STS_HCH) {
-                       printf("%s: host controller halted\n",
+                       kprintf("%s: host controller halted\n",
                            __FUNCTION__);
                }
 
                if (status & XHCI_STS_HSE) {
-                       printf("%s: host system error\n",
+                       kprintf("%s: host system error\n",
                            __FUNCTION__);
                }
 
                if (status & XHCI_STS_HCE) {
-                       printf("%s: host controller error\n",
+                       kprintf("%s: host controller error\n",
                           __FUNCTION__);
                }
        }
@@ -1482,7 +1478,7 @@ xhci_timeout(void *arg)
 
        DPRINTF("xfer=%p\n", xfer);
 
-       USB_BUS_LOCK_ASSERT(xfer->xroot->bus, MA_OWNED);
+       USB_BUS_LOCK_ASSERT(xfer->xroot->bus);
 
        /* transfer is transferred */
        xhci_device_done(xfer, USB_ERR_TIMEOUT);
@@ -2651,7 +2647,7 @@ xhci_root_intr(struct xhci_softc *sc)
 {
        uint16_t i;
 
-       USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
+       USB_BUS_LOCK_ASSERT(&sc->sc_bus);
 
        /* clear any old interrupt data */
        memset(sc->sc_hub_idata, 0, sizeof(sc->sc_hub_idata));
@@ -2918,7 +2914,7 @@ xhci_roothub_exec(struct usb_device *udev,
        uint8_t j;
        usb_error_t err;
 
-       USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
+       USB_BUS_LOCK_ASSERT(&sc->sc_bus);
 
        /* buffer reset */
        ptr = (const void *)&sc->sc_hub_desc;
@@ -3101,7 +3097,7 @@ xhci_roothub_exec(struct usb_device *udev,
                        }
 
                        /* wait 20ms for resume sequence to complete */
-                       usb_pause_mtx(&sc->sc_bus.bus_mtx, hz / 50);
+                       usb_pause_mtx(&sc->sc_bus.bus_lock, hz / 50);
 
                        /* U0 */
                        XWRITE4(sc, oper, port, v |
@@ -3274,7 +3270,7 @@ xhci_roothub_exec(struct usb_device *udev,
                        XWRITE4(sc, oper, port, v |
                            XHCI_PS_PLS_SET(i) | XHCI_PS_LWS);
                        /* 4ms settle time */
-                       usb_pause_mtx(&sc->sc_bus.bus_mtx, hz / 250);
+                       usb_pause_mtx(&sc->sc_bus.bus_lock, hz / 250);
                        break;
                case UHF_PORT_ENABLE:
                        DPRINTFN(3, "set port enable %d\n", index);
index 14afcaf..76dcff8 100644 (file)
@@ -432,7 +432,7 @@ struct xhci_softc {
        union xhci_hub_desc     sc_hub_desc;
 
        struct cv               sc_cmd_cv;
-       struct sx               sc_cmd_sx;
+       struct lock             sc_cmd_lock;
 
        struct usb_device       *sc_devices[XHCI_MAX_DEVICES];
        struct resource         *sc_io_res;
@@ -484,9 +484,9 @@ struct xhci_softc {
        char                    sc_vendor[16];
 };
 
-#define        XHCI_CMD_LOCK(sc)       sx_xlock(&(sc)->sc_cmd_sx)
-#define        XHCI_CMD_UNLOCK(sc)     sx_xunlock(&(sc)->sc_cmd_sx)
-#define        XHCI_CMD_ASSERT_LOCKED(sc) sx_assert(&(sc)->sc_cmd_sx, SA_LOCKED)
+#define        XHCI_CMD_LOCK(sc)       lockmgr(&(sc)->sc_cmd_lock, LK_EXCLUSIVE)
+#define        XHCI_CMD_UNLOCK(sc)     lockmgr(&(sc)->sc_cmd_lock, LK_RELEASE)
+#define        XHCI_CMD_ASSERT_LOCKED(sc) KKASSERT(lockstatus(&(sc)->sc_cmd_lock, curthread) == LK_EXCLUSIVE)
 
 /* prototypes */
 
index 80877ac..52b1a07 100644 (file)
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
 
 #include <sys/stdint.h>
-#include <sys/stddef.h>
 #include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/types.h>
@@ -39,25 +37,24 @@ __FBSDID("$FreeBSD$");
 #include <sys/mutex.h>
 #include <sys/condvar.h>
 #include <sys/sysctl.h>
-#include <sys/sx.h>
 #include <sys/unistd.h>
 #include <sys/callout.h>
 #include <sys/malloc.h>
 #include <sys/priv.h>
 
-#include <dev/usb/usb.h>
-#include <dev/usb/usbdi.h>
+#include <bus/u4b/usb.h>
+#include <bus/u4b/usbdi.h>
 
-#include <dev/usb/usb_core.h>
-#include <dev/usb/usb_busdma.h>
-#include <dev/usb/usb_process.h>
-#include <dev/usb/usb_util.h>
+#include <bus/u4b/usb_core.h>
+#include <bus/u4b/usb_busdma.h>
+#include <bus/u4b/usb_process.h>
+#include <bus/u4b/usb_util.h>
 
-#include <dev/usb/usb_controller.h>
-#include <dev/usb/usb_bus.h>
-#include <dev/usb/usb_pci.h>
-#include <dev/usb/controller/xhci.h>
-#include <dev/usb/controller/xhcireg.h>
+#include <bus/u4b/usb_controller.h>
+#include <bus/u4b/usb_bus.h>
+#include <bus/u4b/usb_pci.h>
+#include <bus/u4b/controller/xhci.h>
+#include <bus/u4b/controller/xhcireg.h>
 #include "usb_if.h"
 
 static device_probe_t xhci_pci_probe;
@@ -75,7 +72,7 @@ static device_method_t xhci_device_methods[] = {
        DEVMETHOD(device_shutdown, bus_generic_shutdown),
        DEVMETHOD(usb_take_controller, xhci_pci_take_controller),
 
-       DEVMETHOD_END
+    { 0, 0 }
 };
 
 static driver_t xhci_driver = {
@@ -155,15 +152,10 @@ xhci_pci_attach(device_t self)
        }
        device_set_ivars(sc->sc_bus.bdev, &sc->sc_bus);
 
-       sprintf(sc->sc_vendor, "0x%04x", pci_get_vendor(self));
+       ksprintf(sc->sc_vendor, "0x%04x", pci_get_vendor(self));
 
-#if (__FreeBSD_version >= 700031)
-       err = bus_setup_intr(self, sc->sc_irq_res, INTR_TYPE_BIO | INTR_MPSAFE,
-           NULL, (driver_intr_t *)xhci_interrupt, sc, &sc->sc_intr_hdl);
-#else
-       err = bus_setup_intr(self, sc->sc_irq_res, INTR_TYPE_BIO | INTR_MPSAFE,
-           (driver_intr_t *)xhci_interrupt, sc, &sc->sc_intr_hdl);
-#endif
+       err = bus_setup_intr(self, sc->sc_irq_res, INTR_MPSAFE,
+           (driver_intr_t *)xhci_interrupt, sc, &sc->sc_intr_hdl, NULL);
        if (err) {
                device_printf(self, "Could not setup IRQ, err=%d\n", err);
                sc->sc_intr_hdl = NULL;
@@ -202,8 +194,9 @@ xhci_pci_detach(device_t self)
                device_delete_child(self, bdev);
        }
        /* during module unload there are lots of children leftover */
+    /* XXX
        device_delete_children(self);
-
+    */
        pci_disable_busmaster(self);
 
        if (sc->sc_irq_res && sc->sc_intr_hdl) {
index 3f2bd11..9497395 100644 (file)
@@ -1,6 +1,3 @@
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
 /*-
  * Copyright (c) 1999 MAEKAWA Masahide <bishop@rr.iij4u.or.jp>,
  *                   Nick Hibma <n_hibma@FreeBSD.org>
@@ -103,7 +100,6 @@ __FBSDID("$FreeBSD$");
  */
 
 #include <sys/stdint.h>
-#include <sys/stddef.h>
 #include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/types.h>
@@ -112,30 +108,30 @@ __FBSDID("$FreeBSD$");
 #include <sys/bus.h>
 #include <sys/module.h>
 #include <sys/lock.h>
-#include <sys/mutex.h>
 #include <sys/condvar.h>
 #include <sys/sysctl.h>
-#include <sys/sx.h>
 #include <sys/unistd.h>
 #include <sys/callout.h>
 #include <sys/malloc.h>
 #include <sys/priv.h>
 
-#include <dev/usb/usb.h>
-#include <dev/usb/usbdi.h>
-#include <dev/usb/usbdi_util.h>
+#include <bus/u4b/usb.h>
+#include <bus/u4b/usbdi.h>
+#include <bus/u4b/usbdi_util.h>
+#include <bus/u4b/usbdevs.h>
+/*
 #include "usbdevs.h"
+*/
+#include <bus/u4b/quirk/usb_quirk.h>
 
-#include <dev/usb/quirk/usb_quirk.h>
-
-#include <cam/cam.h>
-#include <cam/cam_ccb.h>
-#include <cam/cam_sim.h>
-#include <cam/cam_xpt_sim.h>
-#include <cam/scsi/scsi_all.h>
-#include <cam/scsi/scsi_da.h>
+#include <bus/cam/cam.h>
+#include <bus/cam/cam_ccb.h>
+#include <bus/cam/cam_sim.h>
+#include <bus/cam/cam_xpt_sim.h>
+#include <bus/cam/scsi/scsi_all.h>
+#include <bus/cam/scsi/scsi_da.h>
 
-#include <cam/cam_periph.h>
+#include <bus/cam/cam_periph.h>
 
 #define UMASS_EXT_BUFFER
 #ifdef UMASS_EXT_BUFFER
@@ -154,7 +150,7 @@ __FBSDID("$FreeBSD$");
 #define        DPRINTF(sc, m, fmt, ...)                        \
   do {                                                 \
     if (umass_debug & (m)) {                           \
-        printf("%s:%s: " fmt,                          \
+        kprintf("%s:%s: " fmt,                         \
               (sc) ? (const char *)(sc)->sc_name :     \
               (const char *)"umassX",                  \
                __FUNCTION__ ,## __VA_ARGS__);          \
@@ -377,7 +373,7 @@ struct umass_softc {
 
        struct scsi_sense cam_scsi_sense;
        struct scsi_test_unit_ready cam_scsi_test_unit_ready;
-       struct mtx sc_mtx;
+       struct lock sc_lock;
        struct {
                uint8_t *data_ptr;
                union ccb *ccb;
@@ -902,13 +898,12 @@ umass_attach(device_t dev)
        sc->sc_quirks = temp.quirks;
        sc->sc_unit = device_get_unit(dev);
 
-       snprintf(sc->sc_name, sizeof(sc->sc_name),
+       ksnprintf(sc->sc_name, sizeof(sc->sc_name),
            "%s", device_get_nameunit(dev));
 
        device_set_usb_desc(dev);
 
-        mtx_init(&sc->sc_mtx, device_get_nameunit(dev), 
-           NULL, MTX_DEF | MTX_RECURSE);
+       lockinit(&sc->sc_lock, device_get_nameunit(dev), 0, LK_CANRECURSE);
 
        /* get interface index */
 
@@ -925,41 +920,41 @@ umass_attach(device_t dev)
 
        switch (sc->sc_proto & UMASS_PROTO_COMMAND) {
        case UMASS_PROTO_SCSI:
-               printf("SCSI");
+               kprintf("SCSI");
                break;
        case UMASS_PROTO_ATAPI:
-               printf("8070i (ATAPI)");
+               kprintf("8070i (ATAPI)");
                break;
        case UMASS_PROTO_UFI:
-               printf("UFI");
+               kprintf("UFI");
                break;
        case UMASS_PROTO_RBC:
-               printf("RBC");
+               kprintf("RBC");
                break;
        default:
-               printf("(unknown 0x%02x)",
+               kprintf("(unknown 0x%02x)",
                    sc->sc_proto & UMASS_PROTO_COMMAND);
                break;
        }
 
-       printf(" over ");
+       kprintf(" over ");
 
        switch (sc->sc_proto & UMASS_PROTO_WIRE) {
        case UMASS_PROTO_BBB:
-               printf("Bulk-Only");
+               kprintf("Bulk-Only");
                break;
        case UMASS_PROTO_CBI:           /* uses Comand/Bulk pipes */
-               printf("CBI");
+               kprintf("CBI");
                break;
        case UMASS_PROTO_CBI_I: /* uses Comand/Bulk/Interrupt pipes */
-               printf("CBI with CCI");
+               kprintf("CBI with CCI");
                break;
        default:
-               printf("(unknown 0x%02x)",
+               kprintf("(unknown 0x%02x)",
                    sc->sc_proto & UMASS_PROTO_WIRE);
        }
 
-       printf("; quirks = 0x%04x\n", sc->sc_quirks);
+       kprintf("; quirks = 0x%04x\n", sc->sc_quirks);
 #endif
 
        if (sc->sc_quirks & ALT_IFACE_1) {
@@ -978,7 +973,7 @@ umass_attach(device_t dev)
 
                err = usbd_transfer_setup(uaa->device,
                    &uaa->info.bIfaceIndex, sc->sc_xfer, umass_bbb_config,
-                   UMASS_T_BBB_MAX, sc, &sc->sc_mtx);
+                   UMASS_T_BBB_MAX, sc, &sc->sc_lock);
 
                /* skip reset first time */
                sc->sc_last_xfer_index = UMASS_T_BBB_COMMAND;
@@ -987,7 +982,7 @@ umass_attach(device_t dev)
 
                err = usbd_transfer_setup(uaa->device,
                    &uaa->info.bIfaceIndex, sc->sc_xfer, umass_cbi_config,
-                   UMASS_T_CBI_MAX, sc, &sc->sc_mtx);
+                   UMASS_T_CBI_MAX, sc, &sc->sc_lock);
 
                /* skip reset first time */
                sc->sc_last_xfer_index = UMASS_T_CBI_COMMAND;
@@ -1053,15 +1048,11 @@ umass_detach(device_t dev)
 
        usbd_transfer_unsetup(sc->sc_xfer, UMASS_T_MAX);
 
-#if (__FreeBSD_version >= 700037)
-       mtx_lock(&sc->sc_mtx);
-#endif
+       lockmgr(&sc->sc_lock, LK_EXCLUSIVE);
        umass_cam_detach_sim(sc);
 
-#if (__FreeBSD_version >= 700037)
-       mtx_unlock(&sc->sc_mtx);
-#endif
-       mtx_destroy(&sc->sc_mtx);
+    lockmgr(&sc->sc_lock, LK_RELEASE);
+    lockuninit(&sc->sc_lock);
 
        return (0);                     /* success */
 }
@@ -1124,8 +1115,8 @@ umass_cancel_ccb(struct umass_softc *sc)
 {
        union ccb *ccb;
 
-       mtx_assert(&sc->sc_mtx, MA_OWNED);
-
+/*    KKASSERT(lockstatus(&sc->sc_lock, curthread) != 0);
+*/
        ccb = sc->sc_transfer.ccb;
        sc->sc_transfer.ccb = NULL;
        sc->sc_last_xfer_index = 0;
@@ -1632,7 +1623,7 @@ umass_bbb_get_max_lun(struct umass_softc *sc)
                buf = 0;
 
                /* Device doesn't support Get Max Lun request. */
-               printf("%s: Get Max Lun not supported (%s)\n",
+               kprintf("%s: Get Max Lun not supported (%s)\n",
                    sc->sc_name, usbd_errstr(err));
        }
        return (buf);
@@ -2117,43 +2108,30 @@ umass_cam_attach_sim(struct umass_softc *sc)
                return (ENOMEM);
        }
        sc->sc_sim = cam_sim_alloc
-           (&umass_cam_action, &umass_cam_poll,
+           (umass_cam_action, umass_cam_poll,
            DEVNAME_SIM,
            sc /* priv */ ,
            sc->sc_unit /* unit number */ ,
-#if (__FreeBSD_version >= 700037)
-           &sc->sc_mtx /* mutex */ ,
-#endif
+           &sc->sc_lock /* mutex */ ,
            1 /* maximum device openings */ ,
            0 /* maximum tagged device openings */ ,
            devq);
 
+       cam_simq_release(devq);
        if (sc->sc_sim == NULL) {
-               cam_simq_free(devq);
                return (ENOMEM);
        }
 
-#if (__FreeBSD_version >= 700037)
-       mtx_lock(&sc->sc_mtx);
-#endif
+    lockmgr(&sc->sc_lock, LK_EXCLUSIVE);
 
-#if (__FreeBSD_version >= 700048)
-       if (xpt_bus_register(sc->sc_sim, sc->sc_dev, sc->sc_unit) != CAM_SUCCESS) {
-               mtx_unlock(&sc->sc_mtx);
-               return (ENOMEM);
-       }
-#else
        if (xpt_bus_register(sc->sc_sim, sc->sc_unit) != CAM_SUCCESS) {
-#if (__FreeBSD_version >= 700037)
-               mtx_unlock(&sc->sc_mtx);
-#endif
+               lockmgr(&sc->sc_lock, LK_RELEASE);
+               cam_sim_free(sc->sc_sim);
+               sc->sc_sim = NULL;
                return (ENOMEM);
        }
-#endif
 
-#if (__FreeBSD_version >= 700037)
-       mtx_unlock(&sc->sc_mtx);
-#endif
+       lockmgr(&sc->sc_lock, LK_RELEASE);
        return (0);
 }
 
@@ -2163,7 +2141,7 @@ umass_cam_attach(struct umass_softc *sc)
 #ifndef USB_DEBUG
        if (bootverbose)
 #endif
-               printf("%s:%d:%d:%d: Attached to scbus%d\n",
+               kprintf("%s:%d:%d:%d: Attached to scbus%d\n",
                    sc->sc_name, cam_sim_path(sc->sc_sim),
                    sc->sc_unit, CAM_LUN_WILDCARD,
                    cam_sim_path(sc->sc_sim));
@@ -2180,7 +2158,7 @@ umass_cam_detach_sim(struct umass_softc *sc)
                if (xpt_bus_deregister(cam_sim_path(sc->sc_sim))) {
                        /* accessing the softc is not possible after this */
                        sc->sc_sim->softc = UMASS_GONE;
-                       cam_sim_free(sc->sc_sim, /* free_devq */ TRUE);
+                       cam_sim_free(sc->sc_sim);
                } else {
                        panic("%s: CAM layer is busy\n",
                            sc->sc_name);
@@ -2205,9 +2183,7 @@ umass_cam_action(struct cam_sim *sim, union ccb *ccb)
                return;
        }
        if (sc) {
-#if (__FreeBSD_version < 700037)
-               mtx_lock(&sc->sc_mtx);
-#endif
+               lockmgr(&sc->sc_lock, LK_EXCLUSIVE);
        }
        /*
         * Verify, depending on the operation to perform, that we either got
@@ -2347,6 +2323,7 @@ umass_cam_action(struct cam_sim *sim, union ccb *ccb)
                                        if ((sc->sc_quirks & (NO_INQUIRY_EVPD | NO_INQUIRY)) &&
                                            (sc->sc_transfer.cmd_data[1] & SI_EVPD)) {
 
+#ifdef XXXDF
                                                scsi_set_sense_data(&ccb->csio.sense_data,
                                                        /*sense_format*/ SSD_TYPE_NONE,
                                                        /*current_error*/ 1,
@@ -2354,6 +2331,7 @@ umass_cam_action(struct cam_sim *sim, union ccb *ccb)
                                                        /*asc*/ 0x24,
                                                        /*ascq*/ 0x00,
                                                        /*extra args*/ SSD_ELEM_NONE);
+#endif
                                                ccb->csio.scsi_status = SCSI_STATUS_CHECK_COND;
                                                ccb->ccb_h.status = CAM_SCSI_STATUS_ERROR |
                                                    CAM_AUTOSNS_VALID;
@@ -2411,12 +2389,12 @@ umass_cam_action(struct cam_sim *sim, union ccb *ccb)
                        strlcpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
                        cpi->unit_number = cam_sim_unit(sim);
                        cpi->bus_id = sc->sc_unit;
-#if (__FreeBSD_version >= 700025)
+//#if (__FreeBSD_version >= 700025)
                        cpi->protocol = PROTO_SCSI;
                        cpi->protocol_version = SCSI_REV_2;
                        cpi->transport = XPORT_USB;
                        cpi->transport_version = 0;
-#endif
+//#endif
                        if (sc == NULL) {
                                cpi->base_transfer_speed = 0;
                                cpi->max_lun = 0;
@@ -2429,7 +2407,9 @@ umass_cam_action(struct cam_sim *sim, union ccb *ccb)
                                        case USB_SPEED_SUPER:
                                                cpi->base_transfer_speed =
                                                    UMASS_SUPER_TRANSFER_SPEED;
+                        /* XXX
                                                cpi->maxio = MAXPHYS;
+                        */
                                                break;
                                        case USB_SPEED_HIGH:
                                                cpi->base_transfer_speed =
@@ -2468,16 +2448,11 @@ umass_cam_action(struct cam_sim *sim, union ccb *ccb)
                            cam_sim_path(sc->sc_sim), ccb->ccb_h.target_id,
                            ccb->ccb_h.target_lun);
 
-#if (__FreeBSD_version >= 700025)
                        cts->protocol = PROTO_SCSI;
                        cts->protocol_version = SCSI_REV_2;
                        cts->transport = XPORT_USB;
                        cts->transport_version = 0;
                        cts->xport_specific.valid = 0;
-#else
-                       cts->valid = 0;
-                       cts->flags = 0; /* no disconnection, tagging */
-#endif
                        ccb->ccb_h.status = CAM_REQ_CMP;
                        xpt_done(ccb);
                        break;
@@ -2520,11 +2495,9 @@ umass_cam_action(struct cam_sim *sim, union ccb *ccb)
        }
 
 done:
-#if (__FreeBSD_version < 700037)
        if (sc) {
-               mtx_unlock(&sc->sc_mtx);
+               lockmgr(&sc->sc_lock, LK_RELEASE);
        }
-#endif
        return;
 }
 
@@ -2638,13 +2611,16 @@ umass_cam_sense_cb(struct umass_softc *sc, union ccb *ccb, uint32_t residue,
        case STATUS_CMD_OK:
        case STATUS_CMD_UNKNOWN:
        case STATUS_CMD_FAILED: {
-               int key, sense_len;
+               int error, key, asc, ascq;
 
-               ccb->csio.sense_resid = residue;
+               /* XXX
+       ccb->csio.sense_resid = residue;
                sense_len = ccb->csio.sense_len - ccb->csio.sense_resid;
                key = scsi_get_sense_key(&ccb->csio.sense_data, sense_len,
-                                        /*show_errors*/ 1);
-
+                                        1);
+        */
+        scsi_extract_sense(&ccb->csio.sense_data, &error, &key, 
+                            &asc, &ascq);
                if (ccb->csio.ccb_h.flags & CAM_CDB_POINTER) {
                        cmd = (uint8_t *)(ccb->csio.cdb_io.cdb_ptr);
                } else {
@@ -3097,7 +3073,7 @@ umass_dump_buffer(struct umass_softc *sc, uint8_t *buffer, uint32_t buflen,
        s1[0] = '\0';
        s3[0] = '\0';
 
-       sprintf(s2, " buffer=%p, buflen=%d", buffer, buflen);
+       ksprintf(s2, " buffer=%p, buflen=%d", buffer, buflen);
        for (i = 0; (i < buflen) && (i < printlen); i++) {
                j = i % 16;
                if (j == 0 && i != 0) {
@@ -3105,10 +3081,10 @@ umass_dump_buffer(struct umass_softc *sc, uint8_t *buffer, uint32_t buflen,
                            s1, s2);
                        s2[0] = '\0';
                }
-               sprintf(&s1[j * 2], "%02x", buffer[i] & 0xff);
+               ksprintf(&s1[j * 2], "%02x", buffer[i] & 0xff);
        }
        if (buflen > printlen)
-               sprintf(s3, " ...");
+               ksprintf(s3, " ...");
        DPRINTF(sc, UDMASS_GEN, "0x %s%s%s\n",
            s1, s2, s3);
 }
index dd6b413..2eabf30 100644 (file)
@@ -37,7 +37,6 @@
  */
 
 #include <sys/stdint.h>
-#include <sys/stddef.h>
 #include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/types.h>
 #include <sys/mutex.h>
 #include <sys/condvar.h>
 #include <sys/sysctl.h>
-#include <sys/sx.h>
 #include <sys/unistd.h>
 #include <sys/callout.h>
 #include <sys/malloc.h>
 #include <sys/priv.h>
 
-#include <dev/usb/usb.h>
-#include <dev/usb/usbdi.h>
-#include "usbdevs.h"
+#include <bus/u4b/usb.h>
+#include <bus/u4b/usbdi.h>
+#include <bus/u4b/usbdevs.h>
 #include "usb_if.h"
 
 #define        USB_DEBUG_VAR ustorage_fs_debug
-#include <dev/usb/usb_debug.h>
+#include <bus/u4b/usb_debug.h>
 
 #ifdef USB_DEBUG
 static int ustorage_fs_debug = 0;
@@ -179,7 +177,7 @@ struct ustorage_fs_softc {
        ustorage_fs_bbb_cbw_t sc_cbw;   /* Command Wrapper Block */
        ustorage_fs_bbb_csw_t sc_csw;   /* Command Status Block */
 
-       struct mtx sc_mtx;
+       struct lock sc_lock;
 
        struct ustorage_fs_lun sc_lun[USTORAGE_FS_MAX_LUN];
 
@@ -374,7 +372,7 @@ ustorage_fs_attach(device_t dev)
                         * further
                         */
                        ustorage_fs_ramdisk =
-                           malloc(USTORAGE_FS_RAM_SECT << 9, M_USB,
+                           kmalloc(USTORAGE_FS_RAM_SECT << 9, M_USB,
                            M_ZERO | M_WAITOK);
 
                        if (ustorage_fs_ramdisk == NULL) {
@@ -388,9 +386,7 @@ ustorage_fs_attach(device_t dev)
 
        device_set_usb_desc(dev);
 
-       mtx_init(&sc->sc_mtx, "USTORAGE_FS lock",
-           NULL, (MTX_DEF | MTX_RECURSE));
-
+    lockinit(&sc->sc_lock, "USTORAGE_FS lock", 0, LK_CANRECURSE);
        /* get interface index */
 
        id = usbd_get_interface_descriptor(uaa->iface);
@@ -403,7 +399,7 @@ ustorage_fs_attach(device_t dev)
 
        err = usbd_transfer_setup(uaa->device,
            &uaa->info.bIfaceIndex, sc->sc_xfer, ustorage_fs_bbb_config,
-           USTORAGE_FS_T_BBB_MAX, sc, &sc->sc_mtx);
+           USTORAGE_FS_T_BBB_MAX, sc, &sc->sc_lock);
        if (err) {
                device_printf(dev, "could not setup required "
                    "transfers, %s\n", usbd_errstr(err));
@@ -411,9 +407,9 @@ ustorage_fs_attach(device_t dev)
        }
        /* start Mass Storage State Machine */
 
-       mtx_lock(&sc->sc_mtx);
+    lockmgr(&sc->sc_lock, LK_EXCLUSIVE);
        ustorage_fs_transfer_start(sc, USTORAGE_FS_T_BBB_COMMAND);
-       mtx_unlock(&sc->sc_mtx);
+    lockmgr(&sc->sc_lock, LK_RELEASE);
 
        return (0);                     /* success */
 
@@ -431,7 +427,7 @@ ustorage_fs_detach(device_t dev)
 
        usbd_transfer_unsetup(sc->sc_xfer, USTORAGE_FS_T_BBB_MAX);
 
-       mtx_destroy(&sc->sc_mtx);
+       lockuninit(&sc->sc_lock);
 
        return (0);                     /* success */
 }
@@ -467,9 +463,9 @@ static void
 ustorage_fs_transfer_stop(struct ustorage_fs_softc *sc)
 {
        usbd_transfer_stop(sc->sc_xfer[sc->sc_last_xfer_index]);
-       mtx_unlock(&sc->sc_mtx);
+    lockmgr(&sc->sc_lock, LK_RELEASE);
        usbd_transfer_drain(sc->sc_xfer[sc->sc_last_xfer_index]);
-       mtx_lock(&sc->sc_mtx);
+    lockmgr(&sc->sc_lock, LK_EXCLUSIVE);
 }
 
 static int
@@ -485,12 +481,12 @@ ustorage_fs_handle_request(device_t dev,
                if ((req->bmRequestType == UT_WRITE_CLASS_INTERFACE) &&
                    (req->bRequest == UR_BBB_RESET)) {
                        *plen = 0;
-                       mtx_lock(&sc->sc_mtx);
+            lockmgr(&sc->sc_lock, LK_EXCLUSIVE);
                        ustorage_fs_transfer_stop(sc);
                        sc->sc_transfer.data_error = 1;
                        ustorage_fs_transfer_start(sc,
                            USTORAGE_FS_T_BBB_COMMAND);
-                       mtx_unlock(&sc->sc_mtx);
+            lockmgr(&sc->sc_lock, LK_RELEASE);
                        return (0);
                } else if ((req->bmRequestType == UT_READ_CLASS_INTERFACE) &&
                           (req->bRequest == UR_BBB_GET_MAX_LUN)) {
index 07207cf..0f09e5e 100644 (file)
@@ -75,7 +75,7 @@ struct usb_bus {
        /*
         * This mutex protects the USB hardware:
         */
-       struct mtx bus_mtx;
+       struct lock bus_lock;
        struct usb_xfer_queue intr_q;
        struct usb_callout power_wdog;  /* power management */
 
index d31aeec..e30f5cb 100644 (file)
@@ -1,4 +1,4 @@
-/* $FreeBSD$ */
+/* $fREEbSD$ */
 /*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
@@ -25,7 +25,6 @@
  */
 
 #include <sys/stdint.h>
-#include <sys/stddef.h>
 #include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/types.h>
 #include <sys/module.h>
 #include <sys/lock.h>
 #include <sys/mutex.h>
+#include <sys/mutex2.h>
 #include <sys/condvar.h>
 #include <sys/sysctl.h>
-#include <sys/sx.h>
 #include <sys/unistd.h>
 #include <sys/callout.h>
 #include <sys/malloc.h>
 #include <sys/priv.h>
 
-#include <dev/usb/usb.h>
-#include <dev/usb/usbdi.h>
-#include <dev/usb/usbdi_util.h>
+#include <bus/u4b/usb.h>
+#include <bus/u4b/usbdi.h>
+#include <bus/u4b/usbdi_util.h>
 
 #define        USB_DEBUG_VAR usb_debug
 
-#include <dev/usb/usb_core.h>
-#include <dev/usb/usb_busdma.h>
-#include <dev/usb/usb_process.h>
-#include <dev/usb/usb_transfer.h>
-#include <dev/usb/usb_device.h>
-#include <dev/usb/usb_util.h>
-#include <dev/usb/usb_debug.h>
+#include <bus/u4b/usb_core.h>
+#include <bus/u4b/usb_busdma.h>
+#include <bus/u4b/usb_process.h>
+#include <bus/u4b/usb_transfer.h>
+#include <bus/u4b/usb_device.h>
+#include <bus/u4b/usb_util.h>
+#include <bus/u4b/usb_debug.h>
 
-#include <dev/usb/usb_controller.h>
-#include <dev/usb/usb_bus.h>
+#include <bus/u4b/usb_controller.h>
+#include <bus/u4b/usb_bus.h>
 
 #if USB_HAVE_BUSDMA
 static void    usb_dma_tag_create(struct usb_dma_tag *, usb_size_t, usb_size_t);
 static void    usb_dma_tag_destroy(struct usb_dma_tag *);
-static void    usb_dma_lock_cb(void *, bus_dma_lock_op_t);
+//static void  usb_dma_lock_cb(void *); //, bus_dma_lock_op_t);
 static void    usb_pc_alloc_mem_cb(void *, bus_dma_segment_t *, int, int);
 static void    usb_pc_load_mem_cb(void *, bus_dma_segment_t *, int, int);
 static void    usb_pc_common_mem_cb(void *, bus_dma_segment_t *, int, int,
@@ -337,11 +336,11 @@ usbd_frame_zero(struct usb_page_cache *cache, usb_frlength_t offset,
 /*------------------------------------------------------------------------*
  *     usb_dma_lock_cb - dummy callback
  *------------------------------------------------------------------------*/
-static void
-usb_dma_lock_cb(void *arg, bus_dma_lock_op_t op)
-{
-       /* we use "mtx_owned()" instead of this function */
-}
+// static void
+//usb_dma_lock_cb(void *arg) // , bus_dma_lock_op_t op)
+//{
+//     /* we use "mtx_owned()" instead of this function */
+//}
 
 /*------------------------------------------------------------------------*
  *     usb_dma_tag_create - allocate a DMA tag
@@ -369,9 +368,7 @@ usb_dma_tag_create(struct usb_dma_tag *udt,
            (2 + (size / USB_PAGE_SIZE)) : 1,
             /* maxsegsz  */ (align == 1 && size > USB_PAGE_SIZE) ?
            USB_PAGE_SIZE : size,
-            /* flags     */ BUS_DMA_KEEP_PG_OFFSET,
-            /* lockfn    */ &usb_dma_lock_cb,
-            /* lockarg   */ NULL,
+            /* flags     */ BUS_DMA_ALIGNED | BUS_DMA_KEEP_PG_OFFSET, /* XXX: Find out what this is supposed to do! */
            &tag)) {
                tag = NULL;
        }
@@ -457,9 +454,9 @@ usb_pc_common_mem_cb(void *arg, bus_dma_segment_t *segs,
        }
 
 done:
-       owned = mtx_owned(uptag->mtx);
+       owned = (lockstatus(uptag->lock, curthread) == LK_EXCLUSIVE);
        if (!owned)
-               mtx_lock(uptag->mtx);
+               lockmgr(uptag->lock, LK_EXCLUSIVE);
 
        uptag->dma_error = (error ? 1 : 0);
        if (isload) {
@@ -468,7 +465,7 @@ done:
                cv_broadcast(uptag->cv);
        }
        if (!owned)
-               mtx_unlock(uptag->mtx);
+               lockmgr(uptag->lock, LK_RELEASE);
 }
 
 /*------------------------------------------------------------------------*
@@ -543,7 +540,7 @@ usb_pc_alloc_mem(struct usb_page_cache *pc, struct usb_page *pg,
        pc->tag = utag->tag;
        pc->ismultiseg = (align == 1);
 
-       mtx_lock(uptag->mtx);
+       lockmgr(uptag->lock, LK_EXCLUSIVE);
 
        /* load memory into DMA */
        err = bus_dmamap_load(
@@ -551,10 +548,10 @@ usb_pc_alloc_mem(struct usb_page_cache *pc, struct usb_page *pg,
            pc, (BUS_DMA_WAITOK | BUS_DMA_COHERENT));
 
        if (err == EINPROGRESS) {
-               cv_wait(uptag->cv, uptag->mtx);
+               cv_wait(uptag->cv, uptag->lock);
                err = 0;
        }
-       mtx_unlock(uptag->mtx);
+       lockmgr(uptag->lock, LK_RELEASE);
 
        if (err || uptag->dma_error) {
                bus_dmamem_free(utag->tag, ptr, map);
@@ -610,7 +607,8 @@ usb_pc_load_mem(struct usb_page_cache *pc, usb_size_t size, uint8_t sync)
        pc->page_offset_end = size;
        pc->ismultiseg = 1;
 
-       mtx_assert(pc->tag_parent->mtx, MA_OWNED);
+       // mtx_assert(pc->tag_parent->mtx, MA_OWNED);
+    KKASSERT(lockstatus(pc->tag_parent->lock, curthread) != 0);
 
        if (size > 0) {
                if (sync) {
@@ -632,7 +630,7 @@ usb_pc_load_mem(struct usb_page_cache *pc, usb_size_t size, uint8_t sync)
                            pc->tag, pc->map, pc->buffer, size,
                            &usb_pc_alloc_mem_cb, pc, BUS_DMA_WAITOK);
                        if (err == EINPROGRESS) {
-                               cv_wait(uptag->cv, uptag->mtx);
+                               cv_wait(uptag->cv, uptag->lock);
                                err = 0;
                        }
                        if (err || uptag->dma_error) {
@@ -794,7 +792,7 @@ usb_dma_tag_find(struct usb_dma_parent_tag *udpt,
 void
 usb_dma_tag_setup(struct usb_dma_parent_tag *udpt,
     struct usb_dma_tag *udt, bus_dma_tag_t dmat,
-    struct mtx *mtx, usb_dma_callback_t *func,
+    struct lock *lock, usb_dma_callback_t *func,
     uint8_t ndmabits, uint8_t nudt)
 {
        memset(udpt, 0, sizeof(*udpt));
@@ -802,7 +800,7 @@ usb_dma_tag_setup(struct usb_dma_parent_tag *udpt,
        /* sanity checking */
        if ((nudt == 0) ||
            (ndmabits == 0) ||
-           (mtx == NULL)) {
+           (lock == NULL)) {
                /* something is corrupt */
                return;
        }
@@ -810,7 +808,7 @@ usb_dma_tag_setup(struct usb_dma_parent_tag *udpt,
        cv_init(udpt->cv, "USB DMA CV");
 
        /* store some information */
-       udpt->mtx = mtx;
+       udpt->lock = lock;
        udpt->func = func;
        udpt->tag = dmat;
        udpt->utag_first = udt;
@@ -868,7 +866,7 @@ usb_bdma_work_loop(struct usb_xfer_queue *pq)
        xfer = pq->curr;
        info = xfer->xroot;
 
-       mtx_assert(info->xfer_mtx, MA_OWNED);
+    KKASSERT(lockstatus(info->xfer_lock, curthread) != 0);
 
        if (xfer->error) {
                /* some error happened */
@@ -992,7 +990,8 @@ usb_bdma_done_event(struct usb_dma_parent_tag *udpt)
 
        info = USB_DMATAG_TO_XROOT(udpt);
 
-       mtx_assert(info->xfer_mtx, MA_OWNED);
+       // mtx_assert(info->xfer_mtx, MA_OWNED);
+    KKASSERT(lockstatus(info->xfer_lock, curthread) != 0);
 
        /* copy error */
        info->dma_error = udpt->dma_error;
index 6b6e403..4af5994 100644 (file)
 #include <sys/uio.h>
 #include <sys/mbuf.h>
 
-#include <machine/bus.h>
+#include <sys/bus.h>
+
+#define USB_HAVE_BUSDMA 1
 
 /* defines */
 
 #define        USB_PAGE_SIZE PAGE_SIZE         /* use system PAGE_SIZE */
 
-#if (__FreeBSD_version >= 700020)
-#define        USB_GET_DMA_TAG(dev) bus_get_dma_tag(dev)
-#else
 #define        USB_GET_DMA_TAG(dev) NULL       /* XXX */
-#endif
 
 /* structure prototypes */
 
@@ -109,7 +107,7 @@ struct usb_dma_parent_tag {
        struct cv cv[1];                /* internal condition variable */
        bus_dma_tag_t tag;              /* always set */
 
-       struct mtx *mtx;                /* private mutex, always set */
+       struct lock *lock;              /* private mutex, always set */
        usb_dma_callback_t *func;       /* load complete callback function */
        struct usb_dma_tag *utag_first;/* pointer to first USB DMA tag */
        uint8_t dma_error;              /* set if DMA load operation failed */
@@ -150,7 +148,7 @@ void        usb_bdma_post_sync(struct usb_xfer *xfer);
 void   usb_bdma_pre_sync(struct usb_xfer *xfer);
 void   usb_bdma_work_loop(struct usb_xfer_queue *pq);
 void   usb_dma_tag_setup(struct usb_dma_parent_tag *udpt,
-           struct usb_dma_tag *udt, bus_dma_tag_t dmat, struct mtx *mtx,
+           struct usb_dma_tag *udt, bus_dma_tag_t dmat, struct lock *lock,
            usb_dma_callback_t *func, uint8_t ndmabits, uint8_t nudt);
 void   usb_dma_tag_unsetup(struct usb_dma_parent_tag *udpt);
 void   usb_pc_cpu_flush(struct usb_page_cache *pc);
index 2f78d9f..3567f51 100644 (file)
@@ -26,7 +26,6 @@
  */
 
 #include <sys/stdint.h>
-#include <sys/stddef.h>
 #include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/types.h>
 #include <sys/mutex.h>
 #include <sys/condvar.h>
 #include <sys/sysctl.h>
-#include <sys/sx.h>
+//#include <sys/sx.h>
 #include <sys/unistd.h>
 #include <sys/callout.h>
 #include <sys/malloc.h>
 #include <sys/priv.h>
 
-#include <dev/usb/usb.h>
-#include <dev/usb/usb_ioctl.h>
-#include <dev/usb/usbdi.h>
-#include <dev/usb/usbdi_util.h>
+#include <bus/u4b/usb.h>
+#include <bus/u4b/usb_ioctl.h>
+#include <bus/u4b/usbdi.h>
+#include <bus/u4b/usbdi_util.h>
 
 #define        USB_DEBUG_VAR usb_debug
 
-#include <dev/usb/usb_core.h>
-#include <dev/usb/usb_compat_linux.h>
-#include <dev/usb/usb_process.h>
-#include <dev/usb/usb_device.h>
-#include <dev/usb/usb_util.h>
-#include <dev/usb/usb_busdma.h>
-#include <dev/usb/usb_transfer.h>
-#include <dev/usb/usb_hub.h>
-#include <dev/usb/usb_request.h>
-#include <dev/usb/usb_debug.h>
+#include <bus/u4b/usb_core.h>
+#include <bus/u4b/usb_compat_linux.h>
+#include <bus/u4b/usb_process.h>
+#include <bus/u4b/usb_device.h>
+#include <bus/u4b/usb_util.h>
+#include <bus/u4b/usb_busdma.h>
+#include <bus/u4b/usb_transfer.h>
+#include <bus/u4b/usb_hub.h>
+#include <bus/u4b/usb_request.h>
+#include <bus/u4b/usb_debug.h>
 
 struct usb_linux_softc {
        LIST_ENTRY(usb_linux_softc) sc_attached_list;
index 4ffc041..b02100e 100644 (file)
@@ -142,7 +142,7 @@ struct usb_bus_methods {
 
        /* Optional for host mode */
 
-       usb_error_t     (*set_address) (struct usb_device *, struct mtx *, uint16_t);
+       usb_error_t     (*set_address) (struct usb_device *, struct lock *, uint16_t);
 };
 
 /*
index 1bd05c8..5d4aa3a 100644 (file)
@@ -31,7 +31,6 @@
  */
 
 #include <sys/stdint.h>
-#include <sys/stddef.h>
 #include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/types.h>
 #include <sys/mutex.h>
 #include <sys/condvar.h>
 #include <sys/sysctl.h>
-#include <sys/sx.h>
+////#include <sys/sx.h>
 #include <sys/unistd.h>
 #include <sys/callout.h>
 #include <sys/malloc.h>
 #include <sys/priv.h>
 
-#include <dev/usb/usb.h>
-#include <dev/usb/usbdi.h>
+#include <bus/u4b/usb.h>
+#include <bus/u4b/usbdi.h>
 
 MALLOC_DEFINE(M_USB, "USB", "USB");
 MALLOC_DEFINE(M_USBDEV, "USBdev", "USB device");
index 3dfd0d1..ca06ae8 100644 (file)
 
 /* macros */
 
-#define        USB_BUS_LOCK(_b)                mtx_lock(&(_b)->bus_mtx)
-#define        USB_BUS_UNLOCK(_b)              mtx_unlock(&(_b)->bus_mtx)
-#define        USB_BUS_LOCK_ASSERT(_b, _t)     mtx_assert(&(_b)->bus_mtx, _t)
-#define        USB_XFER_LOCK(_x)               mtx_lock((_x)->xroot->xfer_mtx)
-#define        USB_XFER_UNLOCK(_x)             mtx_unlock((_x)->xroot->xfer_mtx)
-#define        USB_XFER_LOCK_ASSERT(_x, _t)    mtx_assert((_x)->xroot->xfer_mtx, _t)
+#define        USB_BUS_LOCK(_b)                lockmgr(&(_b)->bus_lock, LK_EXCLUSIVE)
+#define        USB_BUS_UNLOCK(_b)              lockmgr(&(_b)->bus_lock, LK_RELEASE)
+#define        USB_BUS_LOCK_ASSERT(_b) KKASSERT(lockowned(&(_b)->bus_lock))
+#define USB_BUS_LOCK_ASSERT_NOTOWNED(_b) KKASSERT(!lockowned(&(_b)->bus_lock))
+#define        USB_XFER_LOCK(_x)               lockmgr((_x)->xroot->xfer_lock, LK_EXCLUSIVE)
+#define        USB_XFER_UNLOCK(_x)             lockmgr((_x)->xroot->xfer_lock, LK_RELEASE)
+#define        USB_XFER_LOCK_ASSERT(_x)        KKASSERT(lockstatus((_x)->xroot->xfer_lock, curthread) != 0)
+#define USB_XFER_LOCK_ASSERT_NOTOWNED(_x)   KKASSERT(lockstatus((_x)->xroot->xfer_lock, curthread) == 0)
 
 /* helper for converting pointers to integers */
 #define        USB_P2U(ptr) \
@@ -172,7 +174,7 @@ struct usb_xfer {
 
 /* external variables */
 
-extern struct mtx usb_ref_lock;
+extern struct lock usb_ref_lock;
 
 /* typedefs */
 
index a39d400..8c7656c 100644 (file)
@@ -25,8 +25,6 @@
  */
 
 #include <sys/stdint.h>
-#include <sys/stddef.h>
-#include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/types.h>
 #include <sys/systm.h>
 #include <sys/mutex.h>
 #include <sys/condvar.h>
 #include <sys/sysctl.h>
-#include <sys/sx.h>
 #include <sys/unistd.h>
 #include <sys/callout.h>
 #include <sys/malloc.h>
 #include <sys/priv.h>
 
-#include <dev/usb/usb.h>
-#include <dev/usb/usbdi.h>
+#include <bus/u4b/usb.h>
+#include <bus/u4b/usbdi.h>
 
-#include <dev/usb/usb_core.h>
-#include <dev/usb/usb_debug.h>
-#include <dev/usb/usb_process.h>
-#include <dev/usb/usb_device.h>
-#include <dev/usb/usb_busdma.h>
-#include <dev/usb/usb_transfer.h>
+#include <bus/u4b/usb_core.h>
+#include <bus/u4b/usb_debug.h>
+#include <bus/u4b/usb_process.h>
+#include <bus/u4b/usb_device.h>
+#include <bus/u4b/usb_busdma.h>
+#include <bus/u4b/usb_transfer.h>
 
 #include <ddb/ddb.h>
 #include <ddb/db_sym.h>
@@ -76,11 +73,11 @@ TUNABLE_INT("hw.usb.debug", &usb_debug);
 void
 usb_dump_iface(struct usb_interface *iface)
 {
-       printf("usb_dump_iface: iface=%p\n", iface);
+       kprintf("usb_dump_iface: iface=%p\n", iface);
        if (iface == NULL) {
                return;
        }
-       printf(" iface=%p idesc=%p altindex=%d\n",
+       kprintf(" iface=%p idesc=%p altindex=%d\n",
            iface, iface->idesc, iface->alt_index);
 }
 
@@ -92,11 +89,11 @@ usb_dump_iface(struct usb_interface *iface)
 void
 usb_dump_device(struct usb_device *udev)
 {
-       printf("usb_dump_device: dev=%p\n", udev);
+       kprintf("usb_dump_device: dev=%p\n", udev);
        if (udev == NULL) {
                return;
        }
-       printf(" bus=%p \n"
+       kprintf(" bus=%p \n"
            " address=%d config=%d depth=%d speed=%d self_powered=%d\n"
            " power=%d langid=%d\n",
            udev->bus,
@@ -114,11 +111,11 @@ usb_dump_queue(struct usb_endpoint *ep)
 {
        struct usb_xfer *xfer;
 
-       printf("usb_dump_queue: endpoint=%p xfer: ", ep);
+       kprintf("usb_dump_queue: endpoint=%p xfer: ", ep);
        TAILQ_FOREACH(xfer, &ep->endpoint_q.head, wait_entry) {
-               printf(" %p", xfer);
+               kprintf(" %p", xfer);
        }
-       printf("\n");
+       kprintf("\n");
 }
 
 /*------------------------------------------------------------------------*
@@ -130,19 +127,19 @@ void
 usb_dump_endpoint(struct usb_endpoint *ep)
 {
        if (ep) {
-               printf("usb_dump_endpoint: endpoint=%p", ep);
+               kprintf("usb_dump_endpoint: endpoint=%p", ep);
 
-               printf(" edesc=%p isoc_next=%d toggle_next=%d",
+               kprintf(" edesc=%p isoc_next=%d toggle_next=%d",
                    ep->edesc, ep->isoc_next, ep->toggle_next);
 
                if (ep->edesc) {
-                       printf(" bEndpointAddress=0x%02x",
+                       kprintf(" bEndpointAddress=0x%02x",
                            ep->edesc->bEndpointAddress);
                }
-               printf("\n");
+               kprintf("\n");
                usb_dump_queue(ep);
        } else {
-               printf("usb_dump_endpoint: endpoint=NULL\n");
+               kprintf("usb_dump_endpoint: endpoint=NULL\n");
        }
 }
 
@@ -155,17 +152,17 @@ void
 usb_dump_xfer(struct usb_xfer *xfer)
 {
        struct usb_device *udev;
-       printf("usb_dump_xfer: xfer=%p\n", xfer);
+       kprintf("usb_dump_xfer: xfer=%p\n", xfer);
        if (xfer == NULL) {
                return;
        }
        if (xfer->endpoint == NULL) {
-               printf("xfer %p: endpoint=NULL\n",
+               kprintf("xfer %p: endpoint=NULL\n",
                    xfer);
                return;
        }
        udev = xfer->xroot->udev;
-       printf("xfer %p: udev=%p vid=0x%04x pid=0x%04x addr=%d "
+       kprintf("xfer %p: udev=%p vid=0x%04x pid=0x%04x addr=%d "
            "endpoint=%p ep=0x%02x attr=0x%02x\n",
            xfer, udev,
            UGETW(udev->ddesc.idVendor),
index 8718c89..8697c13 100644 (file)
@@ -37,7 +37,7 @@ extern int usb_debug;
 #ifdef USB_DEBUG
 #define        DPRINTFN(n,fmt,...) do {                \
   if ((USB_DEBUG_VAR) >= (n)) {                        \
-    printf("%s: " fmt,                         \
+    kprintf("%s: " fmt,                                \
           __FUNCTION__,## __VA_ARGS__);        \
   }                                            \
 } while (0)
index 2b99036..09ce6e2 100644 (file)
@@ -28,7 +28,6 @@
  */
 
 #include <sys/stdint.h>
-#include <sys/stddef.h>
 #include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/types.h>
@@ -40,7 +39,6 @@
 #include <sys/mutex.h>
 #include <sys/condvar.h>
 #include <sys/sysctl.h>
-#include <sys/sx.h>
 #include <sys/unistd.h>
 #include <sys/callout.h>
 #include <sys/malloc.h>
 #include <sys/conf.h>
 #include <sys/fcntl.h>
 
-#include <dev/usb/usb.h>
-#include <dev/usb/usb_ioctl.h>
-#include <dev/usb/usbdi.h>
-#include <dev/usb/usbdi_util.h>
+#include <bus/u4b/usb.h>
+#include <bus/u4b/usb_ioctl.h>
+#include <bus/u4b/usbdi.h>
+#include <bus/u4b/usbdi_util.h>
 
 #define        USB_DEBUG_VAR usb_fifo_debug
 
-#include <dev/usb/usb_core.h>
-#include <dev/usb/usb_dev.h>
-#include <dev/usb/usb_mbuf.h>
-#include <dev/usb/usb_process.h>
-#include <dev/usb/usb_device.h>
-#include <dev/usb/usb_debug.h>
-#include <dev/usb/usb_busdma.h>
-#include <dev/usb/usb_generic.h>
-#include <dev/usb/usb_dynamic.h>
-#include <dev/usb/usb_util.h>
+#include <bus/u4b/usb_core.h>
+#include <bus/u4b/usb_dev.h>
+#include <bus/u4b/usb_mbuf.h>
+#include <bus/u4b/usb_process.h>
+#include <bus/u4b/usb_device.h>
+#include <bus/u4b/usb_debug.h>
+#include <bus/u4b/usb_busdma.h>
+#include <bus/u4b/usb_generic.h>
+#include <bus/u4b/usb_dynamic.h>
+#include <bus/u4b/usb_util.h>
 
-#include <dev/usb/usb_controller.h>
-#include <dev/usb/usb_bus.h>
+#include <bus/u4b/usb_controller.h>
+#include <bus/u4b/usb_bus.h>
 
 #include <sys/filio.h>
 #include <sys/ttycom.h>
-#include <sys/syscallsubr.h>
+#include <sys/kern_syscall.h>
 
 #include <machine/stdarg.h>
 
@@ -111,17 +109,16 @@ static struct     usb_endpoint *usb_dev_get_ep(struct usb_device *, uint8_t,
                    uint8_t);
 static void    usb_loc_fill(struct usb_fs_privdata *,
                    struct usb_cdev_privdata *);
-static void    usb_close(void *);
 static usb_error_t usb_ref_device(struct usb_cdev_privdata *, struct usb_cdev_refdata *, int);
 static usb_error_t usb_usb_ref_device(struct usb_cdev_privdata *, struct usb_cdev_refdata *);
 static void    usb_unref_device(struct usb_cdev_privdata *, struct usb_cdev_refdata *);
 
 static d_open_t usb_open;
+static d_close_t usb_close;
 static d_ioctl_t usb_ioctl;
 static d_read_t usb_read;
 static d_write_t usb_write;
-static d_poll_t usb_poll;
-
+static d_kqfilter_t usb_kqfilter;
 static d_ioctl_t usb_static_ioctl;
 
 static usb_fifo_open_t usb_fifo_dummy_open;
@@ -130,30 +127,30 @@ static usb_fifo_ioctl_t usb_fifo_dummy_ioctl;
 static usb_fifo_cmd_t usb_fifo_dummy_cmd;
 
 /* character device structure used for devices (/dev/ugenX.Y and /dev/uXXX) */
-struct cdevsw usb_devsw = {
-       .d_version = D_VERSION,
+struct dev_ops usb_devsw = {
+/*     .d_version = D_VERSION, */
+    { "usbdev", 0, D_MEM },
        .d_open = usb_open,
-       .d_ioctl = usb_ioctl,
-       .d_name = "usbdev",
-       .d_flags = D_TRACKCLOSE,
+    .d_close = usb_close,
+    .d_ioctl = usb_ioctl,
        .d_read = usb_read,
        .d_write = usb_write,
-       .d_poll = usb_poll
+    .d_kqfilter = usb_kqfilter
 };
 
 static struct cdev* usb_dev = NULL;
 
-/* character device structure used for /dev/usb */
-static struct cdevsw usb_static_devsw = {
-       .d_version = D_VERSION,
+/* character device structure used for /bus/u4b */
+static struct dev_ops usb_static_devsw = {
+    { "usb", 0, D_MEM },
+/*     .d_version = D_VERSION, */
        .d_ioctl = usb_static_ioctl,
-       .d_name = "usb"
 };
 
 static TAILQ_HEAD(, usb_symlink) usb_sym_head;
-static struct sx usb_sym_lock;
+static struct lock usb_sym_lock;
 
-struct mtx usb_ref_lock;
+struct lock usb_ref_lock;
 
 /*------------------------------------------------------------------------*
  *     usb_loc_fill
@@ -193,7 +190,7 @@ usb_ref_device(struct usb_cdev_privdata *cpd,
        /* clear all refs */
        memset(crd, 0, sizeof(*crd));
 
-       mtx_lock(&usb_ref_lock);
+    lockmgr(&usb_ref_lock, LK_EXCLUSIVE);
        cpd->bus = devclass_get_softc(usb_devclass_ptr, cpd->bus_index);
        if (cpd->bus == NULL) {
                DPRINTFN(2, "no bus at %u\n", cpd->bus_index);
@@ -212,7 +209,7 @@ usb_ref_device(struct usb_cdev_privdata *cpd,
                DPRINTFN(2, "ref udev - needed\n");
                cpd->udev->refcount++;
 
-               mtx_unlock(&usb_ref_lock);
+               lockmgr(&usb_ref_lock, LK_RELEASE);
 
                /*
                 * We need to grab the sx-lock before grabbing the
@@ -220,7 +217,7 @@ usb_ref_device(struct usb_cdev_privdata *cpd,
                 */
                usbd_enum_lock(cpd->udev);
 
-               mtx_lock(&usb_ref_lock);
+        lockmgr(&usb_ref_lock, LK_EXCLUSIVE);
 
                /* 
                 * Set "is_uref" after grabbing the default SX lock
@@ -274,7 +271,7 @@ usb_ref_device(struct usb_cdev_privdata *cpd,
                DPRINTFN(2, "ref read\n");
                crd->rxfifo->refcount++;
        }
-       mtx_unlock(&usb_ref_lock);
+    lockmgr(&usb_ref_lock, LK_EXCLUSIVE);
 
        return (0);
 
@@ -286,7 +283,7 @@ error:
                        cv_signal(&cpd->udev->ref_cv);
                }
        }
-       mtx_unlock(&usb_ref_lock);
+    lockmgr(&usb_ref_lock, LK_RELEASE);
        DPRINTFN(2, "fail\n");
        return (USB_ERR_INVAL);
 }
@@ -336,7 +333,7 @@ usb_unref_device(struct usb_cdev_privdata *cpd,
        if (crd->is_uref)
                usbd_enum_unlock(cpd->udev);
 
-       mtx_lock(&usb_ref_lock);
+    lockmgr(&usb_ref_lock, LK_EXCLUSIVE);
        if (crd->is_read) {
                if (--(crd->rxfifo->refcount) == 0) {
                        cv_signal(&crd->rxfifo->cv_drain);
@@ -355,7 +352,7 @@ usb_unref_device(struct usb_cdev_privdata *cpd,
                }
                crd->is_uref = 0;
        }
-       mtx_unlock(&usb_ref_lock);
+    lockmgr(&usb_ref_lock, LK_RELEASE);
 }
 
 static struct usb_fifo *
@@ -363,7 +360,7 @@ usb_fifo_alloc(void)
 {
        struct usb_fifo *f;
 
-       f = malloc(sizeof(*f), M_USBDEV, M_WAITOK | M_ZERO);
+       f = kmalloc(sizeof(*f), M_USBDEV, M_WAITOK | M_ZERO);
        if (f) {
                cv_init(&f->cv_io, "FIFO-IO");
                cv_init(&f->cv_drain, "FIFO-DRAIN");
@@ -499,14 +496,14 @@ usb_fifo_create(struct usb_cdev_privdata *cpd,
                /* update some fields */
                f->fifo_index = n + USB_FIFO_TX;
                f->dev_ep_index = e;
-               f->priv_mtx = &udev->device_mtx;
+               f->priv_lock = &udev->device_lock;
                f->priv_sc0 = ep;
                f->methods = &usb_ugen_methods;
                f->iface_index = ep->iface_index;
                f->udev = udev;
-               mtx_lock(&usb_ref_lock);
+        lockmgr(&usb_ref_lock, LK_EXCLUSIVE);
                udev->fifo[n + USB_FIFO_TX] = f;
-               mtx_unlock(&usb_ref_lock);
+               lockmgr(&usb_ref_lock, LK_RELEASE);
        }
        /* Check RX FIFO */
        if (is_rx &&
@@ -526,14 +523,14 @@ usb_fifo_create(struct usb_cdev_privdata *cpd,
                /* update some fields */
                f->fifo_index = n + USB_FIFO_RX;
                f->dev_ep_index = e;
-               f->priv_mtx = &udev->device_mtx;
+               f->priv_lock = &udev->device_lock;
                f->priv_sc0 = ep;
                f->methods = &usb_ugen_methods;
                f->iface_index = ep->iface_index;
                f->udev = udev;
-               mtx_lock(&usb_ref_lock);
+               lockmgr(&usb_ref_lock, LK_EXCLUSIVE);
                udev->fifo[n + USB_FIFO_RX] = f;
-               mtx_unlock(&usb_ref_lock);
+               lockmgr(&usb_ref_lock, LK_RELEASE);
        }
        if (is_tx) {
                crd->txfifo = udev->fifo[n + USB_FIFO_TX];
@@ -566,7 +563,7 @@ usb_fifo_free(struct usb_fifo *f)
                        f->symlink[n] = NULL;
                }
        }
-       mtx_lock(&usb_ref_lock);
+    lockmgr(&usb_ref_lock, LK_EXCLUSIVE);
 
        /* delink ourselves to stop calls from userland */
        if ((f->fifo_index < USB_FIFO_MAX) &&
@@ -583,20 +580,20 @@ usb_fifo_free(struct usb_fifo *f)
        f->flag_iserror = 1;
        /* need to wait until all callers have exited */
        while (f->refcount != 0) {
-               mtx_unlock(&usb_ref_lock);      /* avoid LOR */
-               mtx_lock(f->priv_mtx);
+        lockmgr(&usb_ref_lock, LK_RELEASE); /* avoid LOR */
+        lockmgr(f->priv_lock, LK_EXCLUSIVE);
                /* get I/O thread out of any sleep state */
                if (f->flag_sleeping) {
                        f->flag_sleeping = 0;
                        cv_broadcast(&f->cv_io);
                }
-               mtx_unlock(f->priv_mtx);
-               mtx_lock(&usb_ref_lock);
+        lockmgr(f->priv_lock, LK_RELEASE);
+        lockmgr(&usb_ref_lock, LK_EXCLUSIVE);
 
                /* wait for sync */
                cv_wait(&f->cv_drain, &usb_ref_lock);
        }
-       mtx_unlock(&usb_ref_lock);
+    lockmgr(&usb_ref_lock, LK_RELEASE);
 
        /* take care of closing the device here, if any */
        usb_fifo_close(f, 0);
@@ -604,7 +601,7 @@ usb_fifo_free(struct usb_fifo *f)
        cv_destroy(&f->cv_io);
        cv_destroy(&f->cv_drain);
 
-       free(f, M_USBDEV);
+       kfree(f, M_USBDEV);
 }
 
 static struct usb_endpoint *
@@ -686,7 +683,7 @@ usb_fifo_open(struct usb_cdev_privdata *cpd,
        if (err) {
                goto done;
        }
-       mtx_lock(f->priv_mtx);
+       lockmgr(f->priv_lock, LK_EXCLUSIVE);
 
        /* reset sleep flag */
        f->flag_sleeping = 0;
@@ -706,15 +703,15 @@ usb_fifo_open(struct usb_cdev_privdata *cpd,
        /* reset ASYNC proc flag */
        f->async_p = NULL;
 
-       mtx_lock(&usb_ref_lock);
+       lockmgr(&usb_ref_lock, LK_EXCLUSIVE);
        /* flag the fifo as opened to prevent others */
        f->curr_cpd = cpd;
-       mtx_unlock(&usb_ref_lock);
+       lockmgr(&usb_ref_lock, LK_RELEASE);
 
        /* reset queue */
        usb_fifo_reset(f);
 
-       mtx_unlock(f->priv_mtx);
+       lockmgr(f->priv_lock, LK_RELEASE);
 done:
        return (err);
 }
@@ -755,21 +752,22 @@ usb_fifo_close(struct usb_fifo *f, int fflags)
                /* nothing to do - already closed */
                return;
        }
-       mtx_lock(f->priv_mtx);
+       lockmgr(f->priv_lock, LK_EXCLUSIVE);
 
        /* clear current cdev private data pointer */
        f->curr_cpd = NULL;
 
        /* check if we are selected */
        if (f->flag_isselect) {
+#ifdef XXXDF
                selwakeup(&f->selinfo);
+#endif
                f->flag_isselect = 0;
        }
        /* check if a thread wants SIGIO */
-       if (f->async_p != NULL) {
-               PROC_LOCK(f->async_p);
-               kern_psignal(f->async_p, SIGIO);
-               PROC_UNLOCK(f->async_p);
+       if (f->async_p != NULL && lwkt_trytoken(&f->async_p->p_token)) {
+               ksignal(f->async_p, SIGIO);
+        lwkt_reltoken(&f->async_p->p_token);
                f->async_p = NULL;
        }
        /* remove FWRITE and FREAD flags */
@@ -801,7 +799,7 @@ usb_fifo_close(struct usb_fifo *f, int fflags)
                            (!f->flag_iserror)) {
                                /* wait until all data has been written */
                                f->flag_sleeping = 1;
-                               err = cv_wait_sig(&f->cv_io, f->priv_mtx);
+                               err = cv_wait_sig(&f->cv_io, f->priv_lock);
                                if (err) {
                                        DPRINTF("signal received\n");
                                        break;
@@ -823,7 +821,7 @@ usb_fifo_close(struct usb_fifo *f, int fflags)
        if (f->flag_sleeping) {
                DPRINTFN(2, "Sleeping at close!\n");
        }
-       mtx_unlock(f->priv_mtx);
+       lockmgr(f->priv_lock, LK_RELEASE);
 
        /* call close method */
        (f->methods->f_close) (f, fflags);
@@ -835,8 +833,12 @@ usb_fifo_close(struct usb_fifo *f, int fflags)
  *     usb_open - cdev callback
  *------------------------------------------------------------------------*/
 static int
-usb_open(struct cdev *dev, int fflags, int devtype, struct thread *td)
+usb_open(struct dev_open_args *ap)
+/*struct cdev *dev, int fflags, int devtype, struct thread *td)
+*/
 {
+    struct cdev *dev = ap->a_head.a_dev;
+    int fflags = ap->a_oflags;
        struct usb_fs_privdata* pd = (struct usb_fs_privdata*)dev->si_drv1;
        struct usb_cdev_refdata refs;
        struct usb_cdev_privdata *cpd;
@@ -851,14 +853,14 @@ usb_open(struct cdev *dev, int fflags, int devtype, struct thread *td)
                return (EPERM);
        }
 
-       cpd = malloc(sizeof(*cpd), M_USBDEV, M_WAITOK | M_ZERO);
+       cpd = kmalloc(sizeof(*cpd), M_USBDEV, M_WAITOK | M_ZERO);
        ep = cpd->ep_addr = pd->ep_addr;
 
        usb_loc_fill(pd, cpd);
        err = usb_ref_device(cpd, &refs, 1);
        if (err) {
                DPRINTFN(2, "cannot ref device\n");
-               free(cpd, M_USBDEV);
+               kfree(cpd, M_USBDEV);
                return (ENXIO);
        }
        cpd->fflags = fflags;   /* access mode for open lifetime */
@@ -869,7 +871,7 @@ usb_open(struct cdev *dev, int fflags, int devtype, struct thread *td)
        if (err) {
                DPRINTFN(2, "cannot create fifo\n");
                usb_unref_device(cpd, &refs);
-               free(cpd, M_USBDEV);
+               kfree(cpd, M_USBDEV);
                return (err);
        }
        if (fflags & FREAD) {
@@ -877,7 +879,7 @@ usb_open(struct cdev *dev, int fflags, int devtype, struct thread *td)
                if (err) {
                        DPRINTFN(2, "read open failed\n");
                        usb_unref_device(cpd, &refs);
-                       free(cpd, M_USBDEV);
+                       kfree(cpd, M_USBDEV);
                        return (err);
                }
        }
@@ -889,24 +891,28 @@ usb_open(struct cdev *dev, int fflags, int devtype, struct thread *td)
                                usb_fifo_close(refs.rxfifo, fflags);
                        }
                        usb_unref_device(cpd, &refs);
-                       free(cpd, M_USBDEV);
+                       kfree(cpd, M_USBDEV);
                        return (err);
                }
        }
        usb_unref_device(cpd, &refs);
+    /* XXX: markusp: which privs? 
        devfs_set_cdevpriv(cpd, usb_close);
-
+    */
+    /* XXX: This might not work as I expect! */
+       dev->si_drv2 = (void *)cpd;
        return (0);
 }
 
 /*------------------------------------------------------------------------*
  *     usb_close - cdev callback
  *------------------------------------------------------------------------*/
-static void
-usb_close(void *arg)
+static int
+usb_close(struct dev_close_args *ap)
 {
+    struct cdev *dev = ap->a_head.a_dev;
        struct usb_cdev_refdata refs;
-       struct usb_cdev_privdata *cpd = arg;
+       struct usb_cdev_privdata *cpd = (struct usb_cdev_privdata *)dev->si_drv2;
        int err;
 
        DPRINTFN(2, "cpd=%p\n", cpd);
@@ -937,27 +943,29 @@ usb_close(void *arg)
        }
        usb_unref_device(cpd, &refs);
 done:
-       free(cpd, M_USBDEV);
+       kfree(cpd, M_USBDEV);
+    return 0;
 }
 
 static void
 usb_dev_init(void *arg)
 {
-       mtx_init(&usb_ref_lock, "USB ref mutex", NULL, MTX_DEF);
-       sx_init(&usb_sym_lock, "USB sym mutex");
+       lockinit(&usb_ref_lock, "USB ref mutex", 0, 0);
+    lockinit(&usb_sym_lock, "USB sym mutex", 0, 0);
        TAILQ_INIT(&usb_sym_head);
 
        /* check the UGEN methods */
        usb_fifo_check_methods(&usb_ugen_methods);
 }
 
-SYSINIT(usb_dev_init, SI_SUB_KLD, SI_ORDER_FIRST, usb_dev_init, NULL);
+/* XXX SI_SUB_KLD? */
+SYSINIT(usb_dev_init, SI_SUB_CONFIGURE, SI_ORDER_FIRST, usb_dev_init, NULL);
 
 static void
 usb_dev_init_post(void *arg)
 {
        /*
-        * Create /dev/usb - this is needed for usbconfig(8), which
+        * Create /bus/u4b - this is needed for usbconfig(8), which
         * needs a well-known device name to access.
         */
        usb_dev = make_dev(&usb_static_devsw, 0, UID_ROOT, GID_OPERATOR,
@@ -976,15 +984,14 @@ usb_dev_uninit(void *arg)
                destroy_dev(usb_dev);
                usb_dev = NULL;
        }
-       mtx_destroy(&usb_ref_lock);
-       sx_destroy(&usb_sym_lock);
+       lockuninit(&usb_ref_lock);
+       lockuninit(&usb_sym_lock);
 }
 
 SYSUNINIT(usb_dev_uninit, SI_SUB_KICK_SCHEDULER, SI_ORDER_ANY, usb_dev_uninit, NULL);
 
 static int
-usb_ioctl_f_sub(struct usb_fifo *f, u_long cmd, void *addr,
-    struct thread *td)
+usb_ioctl_f_sub(struct usb_fifo *f, u_long cmd, void *addr, struct thread *td)
 {
        int error = 0;
 
@@ -1031,8 +1038,15 @@ usb_ioctl_f_sub(struct usb_fifo *f, u_long cmd, void *addr,
  *     usb_ioctl - cdev callback
  *------------------------------------------------------------------------*/
 static int
-usb_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int fflag, struct thread* td)
+usb_ioctl(struct dev_ioctl_args *ap)
+/*usb_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int fflag, struct thread* td)
+*/
 {
+    struct cdev *dev = ap->a_head.a_dev;
+    u_long cmd = ap->a_cmd;
+    caddr_t addr = ap->a_data;
+    /* XXX: What is this thread and where is it supposed to come from */
+    struct thread *td = curthread;
        struct usb_cdev_refdata refs;
        struct usb_cdev_privdata* cpd;
        struct usb_fifo *f;
@@ -1041,10 +1055,18 @@ usb_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int fflag, struct thread*
 
        DPRINTFN(2, "cmd=0x%lx\n", cmd);
 
+    /* XXX: cdev?
        err = devfs_get_cdevpriv((void **)&cpd);
        if (err != 0)
                return (err);
-
+    */
+    /* XXX: This might not work as I would like it to
+     * also I need a proper return value if it does */
+    if(dev->si_drv2 == NULL)
+        return(-1);
+    
+    cpd = (struct usb_cdev_privdata *)dev->si_drv2;
+    
        /* 
         * Performance optimisation: We try to check for IOCTL's that
         * don't need the USB reference first. Then we grab the USB
@@ -1112,10 +1134,21 @@ done:
        return (err);
 }
 
+
+static int
+usb_kqfilter(struct dev_kqfilter_args *ap)
+{
+    usb_close(NULL);
+    return 0;
+}
+
+/* XXX implement using kqfilter */
+#if XXXDF
 /* ARGSUSED */
 static int
 usb_poll(struct cdev* dev, int events, struct thread* td)
 {
+
        struct usb_cdev_refdata refs;
        struct usb_cdev_privdata* cpd;
        struct usb_fifo *f;
@@ -1136,7 +1169,7 @@ usb_poll(struct cdev* dev, int events, struct thread* td)
 
                f = refs.txfifo;
 
-               mtx_lock(f->priv_mtx);
+               lockmgr(f->priv_lock, LK_EXCLUSIVE);
 
                if (!refs.is_usbfs) {
                        if (f->flag_iserror) {
@@ -1168,14 +1201,14 @@ usb_poll(struct cdev* dev, int events, struct thread* td)
                        selrecord(td, &f->selinfo);
                }
 
-               mtx_unlock(f->priv_mtx);
+               lockmgr(f->priv_lock);
        }
        if ((events & (POLLIN | POLLRDNORM)) &&
            (fflags & FREAD)) {
 
                f = refs.rxfifo;
 
-               mtx_lock(f->priv_mtx);
+               lockmgr(f->priv_lock, LK_EXCLUSIVE);
 
                if (!refs.is_usbfs) {
                        if (f->flag_iserror) {
@@ -1212,15 +1245,19 @@ usb_poll(struct cdev* dev, int events, struct thread* td)
                        }
                }
 
-               mtx_unlock(f->priv_mtx);
+               lockmgr(f->priv_lock, LK_RELEASE);
        }
        usb_unref_device(cpd, &refs);
        return (revents);
 }
-
+#endif
 static int
-usb_read(struct cdev *dev, struct uio *uio, int ioflag)
+/*usb_read(struct cdev *dev, struct uio *uio, int ioflag)*/
+usb_read(struct dev_read_args *ap)
 {
+    struct cdev *dev = ap->a_head.a_dev;
+    struct uio *uio = ap->a_uio;
+    int ioflag = ap->a_ioflag;
        struct usb_cdev_refdata refs;
        struct usb_cdev_privdata* cpd;
        struct usb_fifo *f;
@@ -1231,10 +1268,17 @@ usb_read(struct cdev *dev, struct uio *uio, int ioflag)
        int err;
        uint8_t tr_data = 0;
 
+    /*
        err = devfs_get_cdevpriv((void **)&cpd);
        if (err != 0)
                return (err);
+    */
 
+    if(dev->si_drv2 == NULL)
+        return(-1);
+    
+    cpd = (struct usb_cdev_privdata *)dev->si_drv2;
+  
        err = usb_ref_device(cpd, &refs, 0 /* no uref */ );
        if (err) {
                return (ENXIO);
@@ -1250,7 +1294,7 @@ usb_read(struct cdev *dev, struct uio *uio, int ioflag)
 
        resid = uio->uio_resid;
 
-       mtx_lock(f->priv_mtx);
+       lockmgr(f->priv_lock, LK_EXCLUSIVE);
 
        /* check for permanent read error */
        if (f->flag_iserror) {
@@ -1334,7 +1378,7 @@ usb_read(struct cdev *dev, struct uio *uio, int ioflag)
                }
        }
 done:
-       mtx_unlock(f->priv_mtx);
+       lockmgr(f->priv_lock, LK_RELEASE);
 
        usb_unref_device(cpd, &refs);
 
@@ -1342,8 +1386,12 @@ done:
 }
 
 static int
-usb_write(struct cdev *dev, struct uio *uio, int ioflag)
+/* usb_write(struct cdev *dev, struct uio *uio, int ioflag) */
+usb_write(struct dev_write_args *ap)
 {
+    struct cdev *dev = ap->a_head.a_dev;
+    struct uio *uio = ap->a_uio;
+    int ioflag = ap->a_ioflag;
        struct usb_cdev_refdata refs;
        struct usb_cdev_privdata* cpd;
        struct usb_fifo *f;
@@ -1357,10 +1405,16 @@ usb_write(struct cdev *dev, struct uio *uio, int ioflag)
 
        DPRINTFN(2, "\n");
 
+#ifdef XXXDF
        err = devfs_get_cdevpriv((void **)&cpd);
        if (err != 0)
                return (err);
-
+#endif
+    if(dev->si_drv2 == NULL)
+        return(-1);
+    
+    cpd = (struct usb_cdev_privdata *)dev->si_drv2;
+  
        err = usb_ref_device(cpd, &refs, 0 /* no uref */ );
        if (err) {
                return (ENXIO);
@@ -1375,7 +1429,7 @@ usb_write(struct cdev *dev, struct uio *uio, int ioflag)
        }
        resid = uio->uio_resid;
 
-       mtx_lock(f->priv_mtx);
+       lockmgr(f->priv_lock, LK_EXCLUSIVE);
 
        /* check for permanent write error */
        if (f->flag_iserror) {
@@ -1475,7 +1529,7 @@ usb_write(struct cdev *dev, struct uio *uio, int ioflag)
 
        } while (uio->uio_resid > 0);
 done:
-       mtx_unlock(f->priv_mtx);
+       lockmgr(f->priv_lock, LK_RELEASE);
 
        usb_unref_device(cpd, &refs);
 
@@ -1483,9 +1537,19 @@ done:
 }
 
 int
+usb_static_ioctl(struct dev_ioctl_args *ap)
+/*
 usb_static_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
     struct thread *td)
+*/
 {
+    u_long cmd = ap->a_cmd;
+    caddr_t data = ap->a_data;
+    /* XXX: what is this thread descriptor and where is it
+     * supposed to come  from? 
+     */
+    struct thread *td = NULL;
+    int fflag = ap->a_fflag;
        union {
                struct usb_read_dir *urd;
                void* data;
@@ -1527,7 +1591,7 @@ usb_fifo_uiomove(struct usb_fifo *f, void *cp,
 {
        int error;
 
-       mtx_unlock(f->priv_mtx);
+       lockmgr(f->priv_lock, LK_RELEASE);
 
        /*
         * "uiomove()" can sleep so one needs to make a wrapper,
@@ -1535,7 +1599,7 @@ usb_fifo_uiomove(struct usb_fifo *f, void *cp,
         */
        error = uiomove(cp, n, uio);
 
-       mtx_lock(f->priv_mtx);
+       lockmgr(f->priv_lock, LK_EXCLUSIVE);
 
        return (error);
 }
@@ -1545,7 +1609,7 @@ usb_fifo_wait(struct usb_fifo *f)
 {
        int err;
 
-       mtx_assert(f->priv_mtx, MA_OWNED);
+       KKASSERT(lockstatus(f->priv_lock, curthread) != 0);
 
        if (f->flag_iserror) {
                /* we are gone */
@@ -1553,7 +1617,7 @@ usb_fifo_wait(struct usb_fifo *f)
        }
        f->flag_sleeping = 1;
 
-       err = cv_wait_sig(&f->cv_io, f->priv_mtx);
+       err = cv_wait_sig(&f->cv_io, f->priv_lock);
 
        if (f->flag_iserror) {
                /* we are gone */
@@ -1577,13 +1641,14 @@ usb_fifo_wakeup(struct usb_fifo *f)
        usb_fifo_signal(f);
 
        if (f->flag_isselect) {
+#ifdef XXXDF
                selwakeup(&f->selinfo);
+#endif
                f->flag_isselect = 0;
        }
-       if (f->async_p != NULL) {
-               PROC_LOCK(f->async_p);
-               kern_psignal(f->async_p, SIGIO);
-               PROC_UNLOCK(f->async_p);
+       if (f->async_p != NULL && lwkt_trytoken(&f->async_p->p_token)) {
+               ksignal(f->async_p, SIGIO);
+        lwkt_reltoken(&f->async_p->p_token);
        }
 }
 
@@ -1652,7 +1717,7 @@ usb_fifo_check_methods(struct usb_fifo_methods *pm)
  *------------------------------------------------------------------------*/
 int
 usb_fifo_attach(struct usb_device *udev, void *priv_sc,
-    struct mtx *priv_mtx, struct usb_fifo_methods *pm,
+    struct lock *priv_lock, struct usb_fifo_methods *pm,
     struct usb_fifo_sc *f_sc, uint16_t unit, uint16_t subunit,
     uint8_t iface_index, uid_t uid, gid_t gid, int mode)
 {
@@ -1670,9 +1735,6 @@ usb_fifo_attach(struct usb_device *udev, void *priv_sc,
        /* check the methods */
        usb_fifo_check_methods(pm);
 
-       if (priv_mtx == NULL)
-               priv_mtx = &Giant;
-
        /* search for a free FIFO slot */
        for (n = 0;; n += 2) {
 
@@ -1703,7 +1765,7 @@ usb_fifo_attach(struct usb_device *udev, void *priv_sc,
 
        f_tx->fifo_index = n + USB_FIFO_TX;
        f_tx->dev_ep_index = -1;
-       f_tx->priv_mtx = priv_mtx;
+       f_tx->priv_lock = priv_lock;
        f_tx->priv_sc0 = priv_sc;
        f_tx->methods = pm;
        f_tx->iface_index = iface_index;
@@ -1711,7 +1773,7 @@ usb_fifo_attach(struct usb_device *udev, void *priv_sc,
 
        f_rx->fifo_index = n + USB_FIFO_RX;
        f_rx->dev_ep_index = -1;
-       f_rx->priv_mtx = priv_mtx;
+       f_rx->priv_lock = priv_lock;
        f_rx->priv_sc0 = priv_sc;
        f_rx->methods = pm;
        f_rx->iface_index = iface_index;
@@ -1720,10 +1782,10 @@ usb_fifo_attach(struct usb_device *udev, void *priv_sc,
        f_sc->fp[USB_FIFO_TX] = f_tx;
        f_sc->fp[USB_FIFO_RX] = f_rx;
 
-       mtx_lock(&usb_ref_lock);
+       lockmgr(&usb_ref_lock, LK_EXCLUSIVE);
        udev->fifo[f_tx->fifo_index] = f_tx;
        udev->fifo[f_rx->fifo_index] = f_rx;
-       mtx_unlock(&usb_ref_lock);
+       lockmgr(&usb_ref_lock, LK_RELEASE);
 
        for (n = 0; n != 4; n++) {
 
@@ -1731,14 +1793,14 @@ usb_fifo_attach(struct usb_device *udev, void *priv_sc,
                        continue;
                }
                if (subunit == 0xFFFF) {
-                       if (snprintf(devname, sizeof(devname),
+                       if (ksnprintf(devname, sizeof(devname),
                            "%s%u%s", pm->basename[n],
                            unit, pm->postfix[n] ?
                            pm->postfix[n] : "")) {
                                /* ignore */
                        }
                } else {
-                       if (snprintf(devname, sizeof(devname),
+                       if (ksnprintf(devname, sizeof(devname),
                            "%s%u.%u%s", pm->basename[n],
                            unit, subunit, pm->postfix[n] ?
                            pm->postfix[n] : "")) {
@@ -1804,7 +1866,7 @@ usb_fifo_free_buffer(struct usb_fifo *f)
 {
        if (f->queue_data) {
                /* free old buffer */
-               free(f->queue_data, M_USBDEV);
+               kfree(f->queue_data, M_USBDEV);
                f->queue_data = NULL;
        }
        /* reset queues */
@@ -2132,7 +2194,7 @@ usb_alloc_symlink(const char *target)
 {
        struct usb_symlink *ps;
 
-       ps = malloc(sizeof(*ps), M_USBDEV, M_WAITOK);
+       ps = kmalloc(sizeof(*ps), M_USBDEV, M_WAITOK);
        if (ps == NULL) {
                return (ps);
        }
@@ -2142,9 +2204,9 @@ usb_alloc_symlink(const char *target)
        strlcpy(ps->dst_path, target, sizeof(ps->dst_path));
        ps->dst_len = strlen(ps->dst_path);
 
-       sx_xlock(&usb_sym_lock);
+       lockmgr(&usb_sym_lock, LK_EXCLUSIVE);
        TAILQ_INSERT_TAIL(&usb_sym_head, ps, sym_entry);
-       sx_unlock(&usb_sym_lock);
+       lockmgr(&usb_sym_lock, LK_RELEASE);
        return (ps);
 }
 
@@ -2157,11 +2219,11 @@ usb_free_symlink(struct usb_symlink *ps)
        if (ps == NULL) {
                return;
        }
-       sx_xlock(&usb_sym_lock);
+       lockmgr(&usb_sym_lock, LK_EXCLUSIVE);
        TAILQ_REMOVE(&usb_sym_head, ps, sym_entry);
-       sx_unlock(&usb_sym_lock);
+       lockmgr(&usb_sym_lock, LK_RELEASE);
 
-       free(ps, M_USBDEV);
+       kfree(ps, M_USBDEV);
 }
 
 /*------------------------------------------------------------------------*
@@ -2180,7 +2242,7 @@ usb_read_symlink(uint8_t *user_ptr, uint32_t startentry, uint32_t user_len)
        uint8_t len;
        int error = 0;
 
-       sx_xlock(&usb_sym_lock);
+       lockmgr(&usb_sym_lock, LK_EXCLUSIVE);
 
        TAILQ_FOREACH(ps, &usb_sym_head, sym_entry) {
 
@@ -2261,7 +2323,7 @@ usb_read_symlink(uint8_t *user_ptr, uint32_t startentry, uint32_t user_len)
                error = copyout(&len,
                    USB_ADD_BYTES(user_ptr, delta), 1);
        }
-       sx_unlock(&usb_sym_lock);
+       lockmgr(&usb_sym_lock, LK_RELEASE);
        return (error);
 }
 
index aa9197f..5ab1095 100644 (file)
@@ -28,7 +28,7 @@
 #define        _USB_DEV_H_
 
 #include <sys/file.h>
-#include <sys/selinfo.h>
+//#include <sys/selinfo.h>
 #include <sys/poll.h>
 #include <sys/signalvar.h>
 #include <sys/proc.h>
@@ -102,7 +102,9 @@ struct usb_fs_privdata {
 struct usb_fifo {
        struct usb_ifqueue free_q;
        struct usb_ifqueue used_q;
+#ifdef XXXDF
        struct selinfo selinfo;
+#endif
        struct cv cv_io;
        struct cv cv_drain;
        struct usb_fifo_methods *methods;
@@ -112,7 +114,7 @@ struct usb_fifo {
        struct usb_device *udev;
        struct usb_xfer *xfer[2];
        struct usb_xfer **fs_xfer;
-       struct mtx *priv_mtx;           /* client data */
+       struct lock *priv_lock;         /* client data */
        /* set if FIFO is opened by a FILE: */
        struct usb_cdev_privdata *curr_cpd;
        void   *priv_sc0;               /* client data */
@@ -141,7 +143,7 @@ struct usb_fifo {
 #define        USB_FIFO_REF_MAX 0xFF
 };
 
-extern struct cdevsw usb_devsw;
+extern struct dev_ops usb_devsw;
 
 int    usb_fifo_wait(struct usb_fifo *fifo);
 void   usb_fifo_signal(struct usb_fifo *fifo);
index 726d7a7..1d74dfc 100644 (file)
@@ -25,7 +25,6 @@
  */
 
 #include <sys/stdint.h>
-#include <sys/stddef.h>
 #include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/types.h>
 #include <sys/mutex.h>
 #include <sys/condvar.h>
 #include <sys/sysctl.h>
-#include <sys/sx.h>
 #include <sys/unistd.h>
 #include <sys/callout.h>
 #include <sys/malloc.h>
 #include <sys/priv.h>
 #include <sys/conf.h>
 #include <sys/fcntl.h>
+#include <sys/devfs.h>
 
-#include <dev/usb/usb.h>
-#include <dev/usb/usbdi.h>
-#include <dev/usb/usbdi_util.h>
-#include <dev/usb/usb_ioctl.h>
+#include <bus/u4b/usb.h>
+#include <bus/u4b/usbdi.h>
+#include <bus/u4b/usbdi_util.h>
+#include <bus/u4b/usb_ioctl.h>
 
 #if USB_HAVE_UGEN
 #include <sys/sbuf.h>
 
 #define        USB_DEBUG_VAR usb_debug
 
-#include <dev/usb/usb_core.h>
-#include <dev/usb/usb_debug.h>
-#include <dev/usb/usb_process.h>
-#include <dev/usb/usb_device.h>
-#include <dev/usb/usb_busdma.h>
-#include <dev/usb/usb_transfer.h>
-#include <dev/usb/usb_request.h>
-#include <dev/usb/usb_dynamic.h>
-#include <dev/usb/usb_hub.h>
-#include <dev/usb/usb_util.h>
-#include <dev/usb/usb_msctest.h>
+#include <bus/u4b/usb_core.h>
+#include <bus/u4b/usb_debug.h>
+#include <bus/u4b/usb_process.h>
+#include <bus/u4b/usb_device.h>
+#include <bus/u4b/usb_busdma.h>
+#include <bus/u4b/usb_transfer.h>
+#include <bus/u4b/usb_request.h>
+#include <bus/u4b/usb_dynamic.h>
+#include <bus/u4b/usb_hub.h>
+#include <bus/u4b/usb_util.h>
+#include <bus/u4b/usb_msctest.h>
 #if USB_HAVE_UGEN
-#include <dev/usb/usb_dev.h>
-#include <dev/usb/usb_generic.h>
+#include <bus/u4b/usb_dev.h>
+#include <bus/u4b/usb_generic.h>
 #endif
 
-#include <dev/usb/quirk/usb_quirk.h>
+#include <bus/u4b/quirk/usb_quirk.h>
 
-#include <dev/usb/usb_controller.h>
-#include <dev/usb/usb_bus.h>
+#include <bus/u4b/usb_controller.h>
+#include <bus/u4b/usb_bus.h>
 
 /* function prototypes  */
 
@@ -477,7 +476,7 @@ usb_unconfigure(struct usb_device *udev, uint8_t flag)
        /* free "cdesc" after "ifaces" and "endpoints", if any */
        if (udev->cdesc != NULL) {
                if (udev->flags.usb_mode != USB_MODE_DEVICE)
-                       free(udev->cdesc, M_USB);
+                       kfree(udev->cdesc, M_USB);
                udev->cdesc = NULL;
        }
        /* set unconfigured state */
@@ -681,8 +680,7 @@ usb_config_parse(struct usb_device *udev, uint8_t iface_index, uint8_t cmd)
                goto cleanup;
 
        if (cmd == USB_CFG_INIT) {
-               sx_assert(&udev->enum_sx, SA_LOCKED);
-
+               KKASSERT(lockstatus(&udev->enum_lock, curthread) == LK_EXCLUSIVE);
                /* check for in-use endpoints */
 
                ep = udev->endpoints;
@@ -798,7 +796,7 @@ usb_config_parse(struct usb_device *udev, uint8_t iface_index, uint8_t cmd)
                udev->ifaces_max = ips.iface_index;
                udev->ifaces = NULL;
                if (udev->ifaces_max != 0) {
-                       udev->ifaces = malloc(sizeof(*iface) * udev->ifaces_max,
+                       udev->ifaces = kmalloc(sizeof(*iface) * udev->ifaces_max,
                                M_USB, M_WAITOK | M_ZERO);
                        if (udev->ifaces == NULL) {
                                err = USB_ERR_NOMEM;
@@ -806,7 +804,7 @@ usb_config_parse(struct usb_device *udev, uint8_t iface_index, uint8_t cmd)
                        }
                }
                if (ep_max != 0) {
-                       udev->endpoints = malloc(sizeof(*ep) * ep_max,
+                       udev->endpoints = kmalloc(sizeof(*ep) * ep_max,
                                M_USB, M_WAITOK | M_ZERO);
                        if (udev->endpoints == NULL) {
                                err = USB_ERR_NOMEM;
@@ -834,9 +832,9 @@ cleanup:
 
                        /* cleanup */
                        if (udev->ifaces != NULL)
-                               free(udev->ifaces, M_USB);
+                               kfree(udev->ifaces, M_USB);
                        if (udev->endpoints != NULL)
-                               free(udev->endpoints, M_USB);
+                               kfree(udev->endpoints, M_USB);
 
                        udev->ifaces = NULL;
                        udev->endpoints = NULL;
@@ -1071,7 +1069,7 @@ usb_detach_device_sub(struct usb_device *udev, device_t *ppdev,
        pnpinfo = *ppnpinfo;
        if (pnpinfo != NULL) {
                *ppnpinfo = NULL;
-               free(pnpinfo, M_USBDEV);
+               kfree(pnpinfo, M_USBDEV);
        }
        return;
 
@@ -1101,7 +1099,9 @@ usb_detach_device(struct usb_device *udev, uint8_t iface_index,
        }
        DPRINTFN(4, "udev=%p\n", udev);
 
-       sx_assert(&udev->enum_sx, SA_LOCKED);
+       /*
+     *  sx_assert(&udev->enum_sx, SA_LOCKED);
+     */
 
        /*
         * First detach the child to give the child's detach routine a
@@ -1425,7 +1425,9 @@ usb_suspend_resume(struct usb_device *udev, uint8_t do_suspend)
        }
        DPRINTFN(4, "udev=%p do_suspend=%d\n", udev, do_suspend);
 
-       sx_assert(&udev->sr_sx, SA_LOCKED);
+       /*
+     *  sx_assert(&udev->sr_sx, SA_LOCKED);
+    */
 
        USB_BUS_LOCK(udev->bus);
        /* filter the suspend events */
@@ -1464,13 +1466,13 @@ usbd_clear_stall_proc(struct usb_proc_msg *_pm)
 
        /* Change lock */
        USB_BUS_UNLOCK(udev->bus);
-       mtx_lock(&udev->device_mtx);
+       lockmgr(&udev->mtx_lock, LK_EXCLUSIVE);
 
        /* Start clear stall callback */
        usbd_transfer_start(udev->ctrl_xfer[1]);
 
        /* Change lock */
-       mtx_unlock(&udev->device_mtx);
+       lockmgr(&udev->mtx_lock, LK_RELEASE);
        USB_BUS_LOCK(udev->bus);
 }
 
@@ -1531,22 +1533,26 @@ usb_alloc_device(device_t parent_dev, struct usb_bus *bus,
                    "Invalid device depth\n");
                return (NULL);
        }
-       udev = malloc(sizeof(*udev), M_USB, M_WAITOK | M_ZERO);
+       udev = kmalloc(sizeof(*udev), M_USB, M_WAITOK | M_ZERO);
        if (udev == NULL) {
                return (NULL);
        }
        /* initialise our SX-lock */
-       sx_init_flags(&udev->ctrl_sx, "USB device SX lock", SX_DUPOK);
+       /* sx_init_flags(&udev->ctrl_sx, "USB device SX lock", SX_DUPOK); */
+    lockinit(&udev->ctrl_lock, "USB device SX lock", 0, 0);
 
        /* initialise our SX-lock */
-       sx_init_flags(&udev->enum_sx, "USB config SX lock", SX_DUPOK);
+       /* sx_init_flags(&udev->enum_sx, "USB config SX lock", SX_DUPOK);
        sx_init_flags(&udev->sr_sx, "USB suspend and resume SX lock", SX_NOWITNESS);
+    */
+    lockinit(&udev->enum_lock, "USB config SX lock", 0, 0);
+    lockinit(&udev->sr_lock, "USB suspend and resume SX lock", 0, 0);
 
        cv_init(&udev->ctrlreq_cv, "WCTRL");
        cv_init(&udev->ref_cv, "UGONE");
 
        /* initialise our mutex */
-       mtx_init(&udev->device_mtx, "USB device mutex", NULL, MTX_DEF);
+       lockinit(&udev->mtx_lock, "USB device mutex", 0, 0);
 
        /* initialise generic clear stall */
        udev->cs_msg[0].hdr.pm_callback = &usbd_clear_stall_proc;
@@ -1618,7 +1624,7 @@ usb_alloc_device(device_t parent_dev, struct usb_bus *bus,
 
 #if USB_HAVE_UGEN
        /* Create ugen name */
-       snprintf(udev->ugen_name, sizeof(udev->ugen_name),
+       ksnprintf(udev->ugen_name, sizeof(udev->ugen_name),
            USB_GENERIC_NAME "%u.%u", device_get_unit(bus->bdev),
            device_index);
        LIST_INIT(&udev->pd_list);
@@ -1879,7 +1885,7 @@ config_done:
        udev->ugen_symlink = usb_alloc_symlink(udev->ugen_name);
 
        /* Announce device */
-       printf("%s: <%s> at %s\n", udev->ugen_name,
+       kprintf("%s: <%s> at %s\n", udev->ugen_name,
            usb_get_manufacturer(udev),
            device_get_nameunit(udev->bus->bdev));
 #endif
@@ -1907,7 +1913,7 @@ usb_make_dev(struct usb_device *udev, const char *devname, int ep,
        char buffer[32];
 
        /* Store information to locate ourselves again later */
-       pd = malloc(sizeof(struct usb_fs_privdata), M_USBDEV,
+       pd = kmalloc(sizeof(struct usb_fs_privdata), M_USBDEV,
            M_WAITOK | M_ZERO);
        pd->bus_index = device_get_unit(udev->bus->bdev);
        pd->dev_index = udev->device_index;
@@ -1918,7 +1924,7 @@ usb_make_dev(struct usb_device *udev, const char *devname, int ep,
        /* Now, create the device itself */
        if (devname == NULL) {
                devname = buffer;
-               snprintf(buffer, sizeof(buffer), USB_DEVICE_DIR "/%u.%u.%u",
+               ksnprintf(buffer, sizeof(buffer), USB_DEVICE_DIR "/%u.%u.%u",
                    pd->bus_index, pd->dev_index, pd->ep_addr);
        }
 
@@ -1926,7 +1932,7 @@ usb_make_dev(struct usb_device *udev, const char *devname, int ep,
 
        if (pd->cdev == NULL) {
                DPRINTFN(0, "Failed to create device %s\n", devname);
-               free(pd, M_USBDEV);
+               kfree(pd, M_USBDEV);
                return (NULL);
        }
 
@@ -1944,7 +1950,7 @@ usb_destroy_dev(struct usb_fs_privdata *pd)
 
        destroy_dev(pd->cdev);
 
-       free(pd, M_USBDEV);
+       kfree(pd, M_USBDEV);
 }
 
 static void
@@ -2051,7 +2057,7 @@ usb_free_device(struct usb_device *udev, uint8_t flag)
 #endif
 
 #if USB_HAVE_UGEN
-       printf("%s: <%s> at %s (disconnected)\n", udev->ugen_name,
+       kprintf("%s: <%s> at %s (disconnected)\n", udev->ugen_name,
            usb_get_manufacturer(udev), device_get_nameunit(bus->bdev));
 
        /* Destroy UGEN symlink, if any */
@@ -2070,12 +2076,12 @@ usb_free_device(struct usb_device *udev, uint8_t flag)
 
 #if USB_HAVE_UGEN
        /* wait for all pending references to go away: */
-       mtx_lock(&usb_ref_lock);
+       lockmgr(&usb_ref_lock, LK_EXCLUSIVE);
        udev->refcount--;
        while (udev->refcount != 0) {
                cv_wait(&udev->ref_cv, &usb_ref_lock);
        }
-       mtx_unlock(&usb_ref_lock);
+       lockmgr(&usb_ref_lock, LK_RELEASE);
 
        usb_destroy_dev(udev->ctrl_dev);
 #endif
@@ -2103,14 +2109,14 @@ usb_free_device(struct usb_device *udev, uint8_t flag)
            &udev->cs_msg[0], &udev->cs_msg[1]);
        USB_BUS_UNLOCK(udev->bus);
 
-       sx_destroy(&udev->ctrl_sx);
-       sx_destroy(&udev->enum_sx);
-       sx_destroy(&udev->sr_sx);
+       lockuninit(&udev->ctrl_lock);
+       lockuninit(&udev->enum_lock);
+       lockuninit(&udev->sr_lock);
 
        cv_destroy(&udev->ctrlreq_cv);
        cv_destroy(&udev->ref_cv);
 
-       mtx_destroy(&udev->device_mtx);
+       lockuninit(&udev->mtx_lock);
 #if USB_HAVE_UGEN
        KASSERT(LIST_FIRST(&udev->pd_list) == NULL, ("leaked cdev entries"));
 #endif
@@ -2120,10 +2126,10 @@ usb_free_device(struct usb_device *udev, uint8_t flag)
                (bus->methods->device_uninit) (udev);
 
        /* free device */
-       free(udev->serial, M_USB);
-       free(udev->manufacturer, M_USB);
-       free(udev->product, M_USB);
-       free(udev, M_USB);
+       kfree(udev->serial, M_USB);
+       kfree(udev->manufacturer, M_USB);
+       kfree(udev->product, M_USB);
+       kfree(udev, M_USB);
 }
 
 /*------------------------------------------------------------------------*
@@ -2218,7 +2224,7 @@ usb_devinfo(struct usb_device *udev, char *dst_ptr, uint16_t dst_len)
        bcdDevice = UGETW(udd->bcdDevice);
 
        if (udd->bDeviceClass != 0xFF) {
-               snprintf(dst_ptr, dst_len, "%s %s, class %d/%d, rev %x.%02x/"
+               ksnprintf(dst_ptr, dst_len, "%s %s, class %d/%d, rev %x.%02x/"
                    "%x.%02x, addr %d",
                    usb_get_manufacturer(udev),
                    usb_get_product(udev),
@@ -2227,7 +2233,7 @@ usb_devinfo(struct usb_device *udev, char *dst_ptr, uint16_t dst_len)
                    (bcdDevice >> 8), bcdDevice & 0xFF,
                    udev->address);
        } else {
-               snprintf(dst_ptr, dst_len, "%s %s, rev %x.%02x/"
+               ksnprintf(dst_ptr, dst_len, "%s %s, rev %x.%02x/"
                    "%x.%02x, addr %d",
                    usb_get_manufacturer(udev),
                    usb_get_product(udev),
@@ -2276,21 +2282,21 @@ usbd_set_device_strings(struct usb_device *udev)
        /* get serial number string */
        usbd_req_get_string_any(udev, NULL, temp_ptr, temp_size,
            udev->ddesc.iSerialNumber);
-       udev->serial = strdup(temp_ptr, M_USB);
+       udev->serial = kstrdup(temp_ptr, M_USB);
 
        /* get manufacturer string */
        usbd_req_get_string_any(udev, NULL, temp_ptr, temp_size,
            udev->ddesc.iManufacturer);
        usb_trim_spaces(temp_ptr);
        if (temp_ptr[0] != '\0')
-               udev->manufacturer = strdup(temp_ptr, M_USB);
+               udev->manufacturer = kstrdup(temp_ptr, M_USB);
 
        /* get product string */
        usbd_req_get_string_any(udev, NULL, temp_ptr, temp_size,
            udev->ddesc.iProduct);
        usb_trim_spaces(temp_ptr);
        if (temp_ptr[0] != '\0')
-               udev->product = strdup(temp_ptr, M_USB);
+               udev->product = kstrdup(temp_ptr, M_USB);
 
 #ifdef USB_VERBOSE
        if (udev->manufacturer == NULL || udev->product == NULL) {
@@ -2303,12 +2309,12 @@ usbd_set_device_strings(struct usb_device *udev)
                if (kdp->vendorname != NULL) {
                        /* XXX should use pointer to knowndevs string */
                        if (udev->manufacturer == NULL) {
-                               udev->manufacturer = strdup(kdp->vendorname,
+                               udev->manufacturer = kstrdup(kdp->vendorname,
                                    M_USB);
                        }
                        if (udev->product == NULL &&
                            (kdp->flags & USB_KNOWNDEV_NOPROD) == 0) {
-                               udev->product = strdup(kdp->productname,
+                               udev->product = kstrdup(kdp->productname,
                                    M_USB);
                        }
                }
@@ -2316,12 +2322,12 @@ usbd_set_device_strings(struct usb_device *udev)
 #endif
        /* Provide default strings if none were found */
        if (udev->manufacturer == NULL) {
-               snprintf(temp_ptr, temp_size, "vendor 0x%04x", vendor_id);
-               udev->manufacturer = strdup(temp_ptr, M_USB);
+               ksnprintf(temp_ptr, temp_size, "vendor 0x%04x", vendor_id);
+               udev->manufacturer = kstrdup(temp_ptr, M_USB);
        }
        if (udev->product == NULL) {
-               snprintf(temp_ptr, temp_size, "product 0x%04x", product_id);
-               udev->product = strdup(temp_ptr, M_USB);
+               ksnprintf(temp_ptr, temp_size, "product 0x%04x", product_id);
+               udev->product = kstrdup(temp_ptr, M_USB);
        }
 }
 
@@ -2439,7 +2445,7 @@ usb_notify_addq(const char *type, struct usb_device *udev)
        int i;
 
        /* announce the device */
-       sb = sbuf_new_auto();
+       sb = sbuf_new(NULL, NULL, 4096, SBUF_AUTOEXTEND);
        sbuf_printf(sb,
 #if USB_HAVE_UGEN
            "ugen=%s "
@@ -2481,13 +2487,15 @@ usb_notify_addq(const char *type, struct usb_device *udev)
 
        /* announce each interface */
        for (i = 0; i < USB_IFACE_MAX; i++) {
-               iface = usbd_get_iface(udev, i);
+        break;
+        iface = usbd_get_iface(udev, i);
                if (iface == NULL)
                        break;          /* end of interfaces */
                if (iface->idesc == NULL)
                        continue;       /* no interface descriptor */
-
-               sb = sbuf_new_auto();
+               
+        sb = 0;
+        sb = sbuf_new(NULL, NULL, 4096, SBUF_AUTOEXTEND);
                sbuf_printf(sb,
 #if USB_HAVE_UGEN
                    "ugen=%s "
@@ -2640,14 +2648,14 @@ usbd_device_attached(struct usb_device *udev)
 void
 usbd_enum_lock(struct usb_device *udev)
 {
-       sx_xlock(&udev->enum_sx);
-       sx_xlock(&udev->sr_sx);
+    lockmgr(&udev->enum_lock, LK_EXCLUSIVE);
+    lockmgr(&udev->sr_lock, LK_EXCLUSIVE);
        /* 
         * NEWBUS LOCK NOTE: We should check if any parent SX locks
         * are locked before locking Giant. Else the lock can be
         * locked multiple times.
         */
-       mtx_lock(&Giant);
+       /* mtx_lock(&Giant); */
 }
 
 /* The following function unlocks enumerating the given USB device. */
@@ -2655,9 +2663,11 @@ usbd_enum_lock(struct usb_device *udev)
 void
 usbd_enum_unlock(struct usb_device *udev)
 {
-       mtx_unlock(&Giant);
-       sx_xunlock(&udev->enum_sx);
-       sx_xunlock(&udev->sr_sx);
+       /* mtx_unlock(&Giant); */
+       /* sx_xunlock(&udev->enum_sx);
+       sx_xunlock(&udev->sr_sx); */
+    lockmgr(&udev->enum_lock, LK_RELEASE);
+    lockmgr(&udev->sr_lock, LK_RELEASE);
 }
 
 /* The following function locks suspend and resume. */
@@ -2665,13 +2675,13 @@ usbd_enum_unlock(struct usb_device *udev)
 void
 usbd_sr_lock(struct usb_device *udev)
 {
-       sx_xlock(&udev->sr_sx);
+    lockmgr(&udev->sr_lock, LK_EXCLUSIVE);
        /* 
         * NEWBUS LOCK NOTE: We should check if any parent SX locks
         * are locked before locking Giant. Else the lock can be
         * locked multiple times.
         */
-       mtx_lock(&Giant);
+       /* mtx_lock(&Giant); */
 }
 
 /* The following function unlocks suspend and resume. */
@@ -2679,8 +2689,9 @@ usbd_sr_lock(struct usb_device *udev)
 void
 usbd_sr_unlock(struct usb_device *udev)
 {
-       mtx_unlock(&Giant);
-       sx_xunlock(&udev->sr_sx);
+/*     mtx_unlock(&Giant);*/
+/*     sx_xunlock(&udev->sr_sx);*/
+    lockmgr(&udev->sr_lock, LK_RELEASE);
 }
 
 /*
@@ -2691,7 +2702,8 @@ usbd_sr_unlock(struct usb_device *udev)
 uint8_t
 usbd_enum_is_locked(struct usb_device *udev)
 {
-       return (sx_xlocked(&udev->enum_sx));
+    /* XXX: Make sure that we return a correct value here */
+       return (lockstatus(&udev->enum_lock, curthread) == LK_EXCLUSIVE);
 }
 
 /*
@@ -2713,14 +2725,14 @@ usbd_set_pnpinfo(struct usb_device *udev, uint8_t iface_index, const char *pnpin
                return (USB_ERR_INVAL);
 
        if (iface->pnpinfo != NULL) {
-               free(iface->pnpinfo, M_USBDEV);
+               kfree(iface->pnpinfo, M_USBDEV);
                iface->pnpinfo = NULL;
        }
 
        if (pnpinfo == NULL || pnpinfo[0] == 0)
                return (0);             /* success */
 
-       iface->pnpinfo = strdup(pnpinfo, M_USBDEV);
+       iface->pnpinfo = kstrdup(pnpinfo, M_USBDEV);
        if (iface->pnpinfo == NULL)
                return (USB_ERR_NOMEM);
 
index bde20b0..2b699bc 100644 (file)
@@ -114,10 +114,16 @@ struct usb_power_save {
 struct usb_device {
        struct usb_clear_stall_msg cs_msg[2];   /* generic clear stall
                                                 * messages */
-       struct sx ctrl_sx;
+       struct lock ctrl_lock;
+       struct lock enum_lock;
+       struct lock sr_lock;
+       struct lock mtx_lock;
+    struct lock device_lock;
+
+/*     struct sx ctrl_sx;
        struct sx enum_sx;
-       struct sx sr_sx;
-       struct mtx device_mtx;
+       struct sx sr_sx; 
+       struct mtx device_mtx; */
        struct cv ctrlreq_cv;
        struct cv ref_cv;
        struct usb_interface *ifaces;
index 1358b30..1649188 100644 (file)
@@ -25,7 +25,6 @@
  */
 
 #include <sys/stdint.h>
-#include <sys/stddef.h>
 #include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/types.h>
 #include <sys/mutex.h>
 #include <sys/condvar.h>
 #include <sys/sysctl.h>
-#include <sys/sx.h>
 #include <sys/unistd.h>
 #include <sys/callout.h>
 #include <sys/malloc.h>
 #include <sys/priv.h>
 
-#include <dev/usb/usb.h>
-#include <dev/usb/usbdi.h>
+#include <bus/u4b/usb.h>
+#include <bus/u4b/usbdi.h>
 
-#include <dev/usb/usb_core.h>
-#include <dev/usb/usb_process.h>
-#include <dev/usb/usb_device.h>
-#include <dev/usb/usb_dynamic.h>
+#include <bus/u4b/usb_core.h>
+#include <bus/u4b/usb_process.h>
+#include <bus/u4b/usb_device.h>
+#include <bus/u4b/usb_dynamic.h>
 
 /* function prototypes */
 static usb_handle_req_t usb_temp_get_desc_w;
@@ -96,7 +94,7 @@ usb_temp_unsetup_w(struct usb_device *udev)
 {
        if (udev->usb_template_ptr) {
 
-               free(udev->usb_template_ptr, M_USB);
+               kfree(udev->usb_template_ptr, M_USB);
 
                udev->usb_template_ptr = NULL;
        }
@@ -113,8 +111,9 @@ usb_quirk_unload(void *arg)
        /* wait for CPU to exit the loaded functions, if any */
 
        /* XXX this is a tradeoff */
-
-       pause("WAIT", hz);
+    /* XXX tsleep? */
+    tsleep(usb_quirk_unload, 0, "WAIT", hz);
+       /* pause("WAIT", hz); */
 }
 
 void
@@ -129,8 +128,10 @@ usb_temp_unload(void *arg)
        /* wait for CPU to exit the loaded functions, if any */
 
        /* XXX this is a tradeoff */
+    /* XXX tsleep? */
+       /* pause("WAIT", hz); */
 
-       pause("WAIT", hz);
+    tsleep(usb_quirk_unload, 0, "WAIT", hz);
 }
 
 void
@@ -144,5 +145,6 @@ usb_bus_unload(void *arg)
 
        /* XXX this is a tradeoff */
 
-       pause("WAIT", hz);
+   /*  pause("WAIT", hz); */
+    tsleep(usb_quirk_unload, 0, "WAIT", hz);
 }
index 119c617..3f0e054 100644 (file)
@@ -25,7 +25,6 @@
  */
 
 #include <sys/stdint.h>
-#include <sys/stddef.h>
 #include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/types.h>
 #include <sys/mutex.h>
 #include <sys/condvar.h>
 #include <sys/sysctl.h>
-#include <sys/sx.h>
 #include <sys/unistd.h>
 #include <sys/callout.h>
 #include <sys/malloc.h>
 #include <sys/priv.h>
 
-#include <dev/usb/usb.h>
-#include <dev/usb/usbdi.h>
+#include <bus/u4b/usb.h>
+#include <bus/u4b/usbdi.h>
 
 static const char* usb_errstr_table[USB_ERR_MAX] = {
        [USB_ERR_NORMAL_COMPLETION]     = "USB_ERR_NORMAL_COMPLETION",
index 349e13e..fe8c0be 100644 (file)
 #define        USB_HAVE_UGEN 1
 #define        USB_HAVE_DEVCTL 1
 #define        USB_HAVE_BUSDMA 1
+/* XXX
 #define        USB_HAVE_COMPAT_LINUX 1
+*/
 #define        USB_HAVE_USER_IO 1
 #define        USB_HAVE_MBUF 1
 #define        USB_HAVE_TT_SUPPORT 1
 #define        USB_HAVE_POWERD 1
 #define        USB_HAVE_MSCTEST 1
+/* XXX
 #define        USB_HAVE_PF 1
+*/
 
 #define        USB_TD_GET_PROC(td) (td)->td_proc
 #define        USB_PROC_GET_GID(td) (td)->p_pgid
index f175eb9..a365ef7 100644 (file)
@@ -25,7 +25,6 @@
  */
 
 #include <sys/stdint.h>
-#include <sys/stddef.h>
 #include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/types.h>
@@ -37,7 +36,6 @@
 #include <sys/mutex.h>
 #include <sys/condvar.h>
 #include <sys/sysctl.h>
-#include <sys/sx.h>
 #include <sys/unistd.h>
 #include <sys/callout.h>
 #include <sys/malloc.h>
 #include <sys/conf.h>
 #include <sys/fcntl.h>
 
-#include <dev/usb/usb.h>
-#include <dev/usb/usb_ioctl.h>
-#include <dev/usb/usbdi.h>
-#include <dev/usb/usbdi_util.h>
+#include <bus/u4b/usb.h>
+#include <bus/u4b/usb_ioctl.h>
+#include <bus/u4b/usbdi.h>
+#include <bus/u4b/usbdi_util.h>
 
 #define        USB_DEBUG_VAR ugen_debug
 
-#include <dev/usb/usb_core.h>
-#include <dev/usb/usb_dev.h>
-#include <dev/usb/usb_mbuf.h>
-#include <dev/usb/usb_process.h>
-#include <dev/usb/usb_device.h>
-#include <dev/usb/usb_debug.h>
-#include <dev/usb/usb_request.h>
-#include <dev/usb/usb_busdma.h>
-#include <dev/usb/usb_util.h>
-#include <dev/usb/usb_hub.h>
-#include <dev/usb/usb_generic.h>
-#include <dev/usb/usb_transfer.h>
-
-#include <dev/usb/usb_controller.h>
-#include <dev/usb/usb_bus.h>
+#include <bus/u4b/usb_core.h>
+#include <bus/u4b/usb_dev.h>
+#include <bus/u4b/usb_mbuf.h>
+#include <bus/u4b/usb_process.h>
+#include <bus/u4b/usb_device.h>
+#include <bus/u4b/usb_debug.h>
+#include <bus/u4b/usb_request.h>
+#include <bus/u4b/usb_busdma.h>
+#include <bus/u4b/usb_util.h>
+#include <bus/u4b/usb_hub.h>
+#include <bus/u4b/usb_generic.h>
+#include <bus/u4b/usb_transfer.h>
+
+#include <bus/u4b/usb_controller.h>
+#include <bus/u4b/usb_bus.h>
 
 #if USB_HAVE_UGEN
 
@@ -145,14 +143,14 @@ ugen_transfer_setup(struct usb_fifo *f,
        uint8_t iface_index = ep->iface_index;
        int error;
 
-       mtx_unlock(f->priv_mtx);
+    lockmgr(f->priv_lock, LK_RELEASE);
 
        /*
         * "usbd_transfer_setup()" can sleep so one needs to make a wrapper,
         * exiting the mutex and checking things
         */
        error = usbd_transfer_setup(udev, &iface_index, f->xfer,
-           setup, n_setup, f, f->priv_mtx);
+           setup, n_setup, f, f->priv_lock);
        if (error == 0) {
 
                if (f->xfer[0]->nframes == 1) {
@@ -167,7 +165,7 @@ ugen_transfer_setup(struct usb_fifo *f,
                        usbd_transfer_unsetup(f->xfer, n_setup);
                }
        }
-       mtx_lock(f->priv_mtx);
+    lockmgr(f->priv_lock, LK_EXCLUSIVE);
 
        return (error);
 }
@@ -181,7 +179,7 @@ ugen_open(struct usb_fifo *f, int fflags)
 
        DPRINTFN(6, "flag=0x%x\n", fflags);
 
-       mtx_lock(f->priv_mtx);
+    lockmgr(f->priv_lock, LK_EXCLUSIVE);
        switch (usbd_get_speed(f->udev)) {
        case USB_SPEED_LOW:
        case USB_SPEED_FULL:
@@ -201,7 +199,7 @@ ugen_open(struct usb_fifo *f, int fflags)
        f->timeout = USB_NO_TIMEOUT;
        f->flag_short = 0;
        f->fifo_zlp = 0;
-       mtx_unlock(f->priv_mtx);
+    lockmgr(f->priv_lock, LK_RELEASE);
 
        return (0);
 }
@@ -213,10 +211,10 @@ ugen_close(struct usb_fifo *f, int fflags)
 
        /* cleanup */
 
-       mtx_lock(f->priv_mtx);
+    lockmgr(f->priv_lock, LK_EXCLUSIVE);
        usbd_transfer_stop(f->xfer[0]);
        usbd_transfer_stop(f->xfer[1]);
-       mtx_unlock(f->priv_mtx);
+    lockmgr(f->priv_lock, LK_RELEASE);
 
        usbd_transfer_unsetup(f->xfer, 2);
        usb_fifo_free_buffer(f);
@@ -234,7 +232,7 @@ ugen_open_pipe_write(struct usb_fifo *f)
        struct usb_endpoint *ep = usb_fifo_softc(f);
        struct usb_endpoint_descriptor *ed = ep->edesc;
 
-       mtx_assert(f->priv_mtx, MA_OWNED);
+    KKASSERT(lockstatus(f->priv_lock, curthread) != 0);
 
        if (f->xfer[0] || f->xfer[1]) {
                /* transfers are already opened */
@@ -302,7 +300,7 @@ ugen_open_pipe_read(struct usb_fifo *f)
        struct usb_endpoint *ep = usb_fifo_softc(f);
        struct usb_endpoint_descriptor *ed = ep->edesc;
 
-       mtx_assert(f->priv_mtx, MA_OWNED);
+    KKASSERT(lockstatus(f->priv_lock, curthread) != 0);
 
        if (f->xfer[0] || f->xfer[1]) {
                /* transfers are already opened */
@@ -709,7 +707,7 @@ ugen_get_cdesc(struct usb_fifo *f, struct usb_gen_descriptor *ugd)
        error = copyout(cdesc, ugd->ugd_data, len);
 
        if (free_data) {
-               free(cdesc, M_USBDEV);
+               kfree(cdesc, M_USBDEV);
        }
        return (error);
 }
@@ -781,7 +779,7 @@ ugen_get_iface_driver(struct usb_fifo *f, struct usb_gen_descriptor *ugd)
            (desc = device_get_desc(iface->subdev))) {
 
                /* print description */
-               snprintf(buf, sizeof(buf), "%s: <%s>", ptr, desc);
+               ksnprintf(buf, sizeof(buf), "%s: <%s>", ptr, desc);
 
                /* range checks */
                maxlen = ugd->ugd_maxlen - 1;
@@ -978,7 +976,7 @@ ugen_fs_uninit(struct usb_fifo *f)
                return (EINVAL);
        }
        usbd_transfer_unsetup(f->fs_xfer, f->fs_ep_max);
-       free(f->fs_xfer, M_USB);
+       kfree(f->fs_xfer, M_USB);
        f->fs_xfer = NULL;
        f->fs_ep_max = 0;
        f->fs_ep_ptr = NULL;
@@ -1054,12 +1052,12 @@ ugen_fs_copy_in(struct usb_fifo *f, uint8_t ep_index)
        if (xfer == NULL) {
                return (EINVAL);
        }
-       mtx_lock(f->priv_mtx);
+    lockmgr(f->priv_lock, LK_EXCLUSIVE);
        if (usbd_transfer_pending(xfer)) {
-               mtx_unlock(f->priv_mtx);
+        lockmgr(f->priv_lock, LK_RELEASE);
                return (EBUSY);         /* should not happen */
        }
-       mtx_unlock(f->priv_mtx);
+    lockmgr(f->priv_lock, LK_RELEASE);
 
        error = copyin(f->fs_ep_ptr +
            ep_index, &fs_ep, sizeof(fs_ep));
@@ -1202,9 +1200,9 @@ ugen_fs_copy_in(struct usb_fifo *f, uint8_t ep_index)
        return (error);
 
 complete:
-       mtx_lock(f->priv_mtx);
+    lockmgr(f->priv_lock, LK_EXCLUSIVE);
        ugen_fs_set_complete(f, ep_index);
-       mtx_unlock(f->priv_mtx);
+    lockmgr(f->priv_lock, LK_RELEASE);
        return (0);
 }
 
@@ -1231,13 +1229,13 @@ ugen_fs_copy_out(struct usb_fifo *f, uint8_t ep_index)
        xfer = f->fs_xfer[ep_index];
        if (xfer == NULL)
                return (EINVAL);
-
-       mtx_lock(f->priv_mtx);
+    
+    lockmgr(f->priv_lock, LK_EXCLUSIVE);
        if (usbd_transfer_pending(xfer)) {
-               mtx_unlock(f->priv_mtx);
+        lockmgr(f->priv_lock, LK_RELEASE);
                return (EBUSY);         /* should not happen */
        }
-       mtx_unlock(f->priv_mtx);
+    lockmgr(f->priv_lock, LK_RELEASE);
 
        fs_ep_uptr = f->fs_ep_ptr + ep_index;
        error = copyin(fs_ep_uptr, &fs_ep, sizeof(fs_ep));
@@ -1410,9 +1408,9 @@ ugen_ioctl(struct usb_fifo *f, u_long cmd, void *addr, int fflags)
 
        switch (cmd) {
        case USB_FS_COMPLETE:
-               mtx_lock(f->priv_mtx);
+        lockmgr(f->priv_lock, LK_EXCLUSIVE);
                error = ugen_fs_get_complete(f, &ep_index);
-               mtx_unlock(f->priv_mtx);
+        lockmgr(f->priv_lock, LK_RELEASE);
 
                if (error) {
                        error = EBUSY;
@@ -1426,10 +1424,10 @@ ugen_ioctl(struct usb_fifo *f, u_long cmd, void *addr, int fflags)
                error = ugen_fs_copy_in(f, u.pstart->ep_index);
                if (error)
                        break;
-               mtx_lock(f->priv_mtx);
+        lockmgr(f->priv_lock, LK_EXCLUSIVE);
                xfer = f->fs_xfer[u.pstart->ep_index];
                usbd_transfer_start(xfer);
-               mtx_unlock(f->priv_mtx);
+        lockmgr(f->priv_lock, LK_RELEASE);
                break;
 
        case USB_FS_STOP:
@@ -1437,7 +1435,7 @@ ugen_ioctl(struct usb_fifo *f, u_long cmd, void *addr, int fflags)
                        error = EINVAL;
                        break;
                }
-               mtx_lock(f->priv_mtx);
+        lockmgr(f->priv_lock, LK_EXCLUSIVE);
                xfer = f->fs_xfer[u.pstart->ep_index];
                if (usbd_transfer_pending(xfer)) {
                        usbd_transfer_stop(xfer);
@@ -1451,7 +1449,7 @@ ugen_ioctl(struct usb_fifo *f, u_long cmd, void *addr, int fflags)
                                    USB_P2U(xfer->priv_fifo));
                        }
                }
-               mtx_unlock(f->priv_mtx);
+        lockmgr(f->priv_lock, LK_RELEASE);
                break;
 
        case USB_FS_OPEN:
@@ -1535,7 +1533,7 @@ ugen_ioctl(struct usb_fifo *f, u_long cmd, void *addr, int fflags)
                }
                error = usbd_transfer_setup(f->udev, &iface_index,
                    f->fs_xfer + u.popen->ep_index, usb_config, 1,
-                   f, f->priv_mtx);
+                   f, f->priv_lock);
                if (error == 0) {
                        /* update maximums */
                        u.popen->max_packet_length =
@@ -1578,9 +1576,9 @@ ugen_ioctl(struct usb_fifo *f, u_long cmd, void *addr, int fflags)
                        error = EINVAL;
                        break;
                }
-               mtx_lock(f->priv_mtx);
+        lockmgr(f->priv_lock, LK_EXCLUSIVE);
                error = usbd_transfer_pending(f->fs_xfer[u.pstall->ep_index]);
-               mtx_unlock(f->priv_mtx);
+        lockmgr(f->priv_lock, LK_RELEASE);
 
                if (error) {
                        return (EBUSY);
@@ -2217,7 +2215,7 @@ ugen_ioctl_post(struct usb_fifo *f, u_long cmd, void *addr, int fflags)
                if (error) {
                        break;
                }
-               f->fs_xfer = malloc(sizeof(f->fs_xfer[0]) *
+               f->fs_xfer = kmalloc(sizeof(f->fs_xfer[0]) *
                    u.pinit->ep_index_max, M_USB, M_WAITOK | M_ZERO);
                if (f->fs_xfer == NULL) {
                        usb_fifo_free_buffer(f);
@@ -2237,9 +2235,9 @@ ugen_ioctl_post(struct usb_fifo *f, u_long cmd, void *addr, int fflags)
                break;
 
        default:
-               mtx_lock(f->priv_mtx);
+        lockmgr(f->priv_lock, LK_EXCLUSIVE);
                error = ugen_iface_ioctl(f, cmd, addr, fflags);
-               mtx_unlock(f->priv_mtx);
+        lockmgr(f->priv_lock, LK_RELEASE);
                break;
        }
        DPRINTFN(6, "error=%d\n", error);
index 2d8d107..da498dd 100644 (file)
@@ -25,7 +25,6 @@
  */
 
 #include <sys/stdint.h>
-#include <sys/stddef.h>
 #include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/types.h>
 #include <sys/mutex.h>
 #include <sys/condvar.h>
 #include <sys/sysctl.h>
-#include <sys/sx.h>
 #include <sys/unistd.h>
 #include <sys/callout.h>
 #include <sys/malloc.h>
 #include <sys/priv.h>
 
-#include <dev/usb/usb.h>
-#include <dev/usb/usbdi.h>
-#include <dev/usb/usbdi_util.h>
+#include <bus/u4b/usb.h>
+#include <bus/u4b/usbdi.h>
+#include <bus/u4b/usbdi_util.h>
 #include "usb_if.h"
 
 #define        USB_DEBUG_VAR usb_debug
 
-#include <dev/usb/usb_core.h>
-#include <dev/usb/usb_process.h>
-#include <dev/usb/usb_busdma.h>
-#include <dev/usb/usb_transfer.h>
-#include <dev/usb/usb_device.h>
-#include <dev/usb/usb_debug.h>
-#include <dev/usb/usb_dynamic.h>
-#include <dev/usb/usb_hub.h>
-
-#include <dev/usb/usb_controller.h>
-#include <dev/usb/usb_bus.h>
+#include <bus/u4b/usb_core.h>
+#include <bus/u4b/usb_process.h>
+#include <bus/u4b/usb_busdma.h>
+#include <bus/u4b/usb_transfer.h>
+#include <bus/u4b/usb_device.h>
+#include <bus/u4b/usb_debug.h>
+#include <bus/u4b/usb_dynamic.h>
+#include <bus/u4b/usb_hub.h>
+
+#include <bus/u4b/usb_controller.h>
+#include <bus/u4b/usb_bus.h>
 
 /* function prototypes */
 
index 6bd51cd..40fb5ce 100644 (file)
@@ -2,7 +2,7 @@
 
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+// __FBSDID("$FreeBSD$");
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -34,7 +34,6 @@ __FBSDID("$FreeBSD$");
  */
 
 #include <sys/stdint.h>
-#include <sys/stddef.h>
 #include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/types.h>
@@ -46,24 +45,23 @@ __FBSDID("$FreeBSD$");
 #include <sys/mutex.h>
 #include <sys/condvar.h>
 #include <sys/sysctl.h>
-#include <sys/sx.h>
 #include <sys/unistd.h>
 #include <sys/callout.h>
 #include <sys/malloc.h>
 #include <sys/priv.h>
 
-#include <dev/usb/usb.h>
-#include <dev/usb/usbdi.h>
-#include <dev/usb/usbdi_util.h>
-#include <dev/usb/usbhid.h>
+#include <bus/u4b/usb.h>
+#include <bus/u4b/usbdi.h>
+#include <bus/u4b/usbdi_util.h>
+#include <bus/u4b/usbhid.h>
 
 #define        USB_DEBUG_VAR usb_debug
 
-#include <dev/usb/usb_core.h>
-#include <dev/usb/usb_debug.h>
-#include <dev/usb/usb_process.h>
-#include <dev/usb/usb_device.h>
-#include <dev/usb/usb_request.h>
+#include <bus/u4b/usb_core.h>
+#include <bus/u4b/usb_debug.h>
+#include <bus/u4b/usb_process.h>
+#include <bus/u4b/usb_device.h>
+#include <bus/u4b/usb_request.h>
 
 static void hid_clear_local(struct hid_item *);
 static uint8_t hid_get_byte(struct hid_data *s, const uint16_t wSize);
@@ -185,7 +183,7 @@ hid_start_parse(const void *d, usb_size_t len, int kindset)
                return (NULL);
        }
 
-       s = malloc(sizeof *s, M_TEMP, M_WAITOK | M_ZERO);
+       s = kmalloc(sizeof *s, M_TEMP, M_WAITOK | M_ZERO);
        s->start = s->p = d;
        s->end = ((const uint8_t *)d) + len;
        s->kindset = kindset;
@@ -201,7 +199,7 @@ hid_end_parse(struct hid_data *s)
        if (s == NULL)
                return;
 
-       free(s, M_TEMP);
+       kfree(s, M_TEMP);
 }
 
 /*------------------------------------------------------------------------*
@@ -803,7 +801,7 @@ hid_get_descriptor_from_usb(struct usb_config_descriptor *cd,
  * Else: Success. The pointer should eventually be passed to free().
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_get_hid_desc(struct usb_device *udev, struct mtx *mtx,
+usbd_req_get_hid_desc(struct usb_device *udev, struct lock *lock,
     void **descp, uint16_t *sizep,
     struct malloc_type *mem, uint8_t iface_index)
 {
@@ -824,22 +822,22 @@ usbd_req_get_hid_desc(struct usb_device *udev, struct mtx *mtx,
        if (*sizep == 0) {
                return (USB_ERR_IOERROR);
        }
-       if (mtx)
-               mtx_unlock(mtx);
+       if (lock)
+               lockmgr(lock, LK_RELEASE);
 
-       *descp = malloc(*sizep, mem, M_ZERO | M_WAITOK);
+       *descp = kmalloc(*sizep, mem, M_ZERO | M_WAITOK);
 
-       if (mtx)
-               mtx_lock(mtx);
+       if (lock)
+               lockmgr(lock, LK_EXCLUSIVE);
 
        if (*descp == NULL) {
                return (USB_ERR_NOMEM);
        }
        err = usbd_req_get_report_descriptor
-           (udev, mtx, *descp, *sizep, iface_index);
+           (udev, lock, *descp, *sizep, iface_index);
 
        if (err) {
-               free(*descp, mem);
+               kfree(*descp, mem);
                *descp = NULL;
                return (err);
        }
index fe40100..82e5955 100644 (file)
@@ -31,7 +31,6 @@
  */
 
 #include <sys/stdint.h>
-#include <sys/stddef.h>
 #include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/types.h>
 #include <sys/mutex.h>
 #include <sys/condvar.h>
 #include <sys/sysctl.h>
-#include <sys/sx.h>
 #include <sys/unistd.h>
 #include <sys/callout.h>
 #include <sys/malloc.h>
 #include <sys/priv.h>
 
-#include <dev/usb/usb.h>
-#include <dev/usb/usb_ioctl.h>
-#include <dev/usb/usbdi.h>
-#include <dev/usb/usbdi_util.h>
+#include <bus/u4b/usb.h>
+#include <bus/u4b/usb_ioctl.h>
+#include <bus/u4b/usbdi.h>
+#include <bus/u4b/usbdi_util.h>
 
 #define        USB_DEBUG_VAR uhub_debug
 
-#include <dev/usb/usb_core.h>
-#include <dev/usb/usb_process.h>
-#include <dev/usb/usb_device.h>
-#include <dev/usb/usb_request.h>
-#include <dev/usb/usb_debug.h>
-#include <dev/usb/usb_hub.h>
-#include <dev/usb/usb_util.h>
-#include <dev/usb/usb_busdma.h>
-#include <dev/usb/usb_transfer.h>
-#include <dev/usb/usb_dynamic.h>
+#include <bus/u4b/usb_core.h>
+#include <bus/u4b/usb_process.h>
+#include <bus/u4b/usb_device.h>
+#include <bus/u4b/usb_request.h>
+#include <bus/u4b/usb_debug.h>
+#include <bus/u4b/usb_hub.h>
+#include <bus/u4b/usb_util.h>
+#include <bus/u4b/usb_busdma.h>
+#include <bus/u4b/usb_transfer.h>
+#include <bus/u4b/usb_dynamic.h>
 
-#include <dev/usb/usb_controller.h>
-#include <dev/usb/usb_bus.h>
+#include <bus/u4b/usb_controller.h>
+#include <bus/u4b/usb_bus.h>
 
 #define        UHUB_INTR_INTERVAL 250          /* ms */
 #define        UHUB_N_TRANSFER 1
@@ -98,7 +96,7 @@ struct uhub_current_state {
 struct uhub_softc {
        struct uhub_current_state sc_st;/* current state */
        device_t sc_dev;                /* base device */
-       struct mtx sc_mtx;              /* our mutex */
+       struct lock sc_lock;            /* our mutex */
        struct usb_device *sc_udev;     /* USB device */
        struct usb_xfer *sc_xfer[UHUB_N_TRANSFER];      /* interrupt xfer */
        uint8_t sc_flags;
@@ -669,7 +667,7 @@ done:
 void
 uhub_root_intr(struct usb_bus *bus, const uint8_t *ptr, uint8_t len)
 {
-       USB_BUS_LOCK_ASSERT(bus, MA_OWNED);
+       USB_BUS_LOCK_ASSERT(bus);
 
        usb_needs_explore(bus, 0);
 }
@@ -921,9 +919,10 @@ uhub_attach(device_t dev)
        sc->sc_udev = udev;
        sc->sc_dev = dev;
 
-       mtx_init(&sc->sc_mtx, "USB HUB mutex", NULL, MTX_DEF);
+       lockinit(&sc->sc_lock, "USB HUB mutex", 0, 0);
 
-       snprintf(sc->sc_name, sizeof(sc->sc_name), "%s",
+
+       ksnprintf(sc->sc_name, sizeof(sc->sc_name), "%s",
            device_get_nameunit(dev));
 
        device_set_usb_desc(dev);
@@ -1049,7 +1048,7 @@ uhub_attach(device_t dev)
                DPRINTFN(0, "portless HUB\n");
                goto error;
        }
-       hub = malloc(sizeof(hub[0]) + (sizeof(hub->ports[0]) * nports),
+       hub = kmalloc(sizeof(hub[0]) + (sizeof(hub->ports[0]) * nports),
            M_USBDEV, M_WAITOK | M_ZERO);
 
        if (hub == NULL) {
@@ -1082,7 +1081,7 @@ uhub_attach(device_t dev)
        } else {
                /* normal HUB */
                err = usbd_transfer_setup(udev, &iface_index, sc->sc_xfer,
-                   uhub_config, UHUB_N_TRANSFER, sc, &sc->sc_mtx);
+                   uhub_config, UHUB_N_TRANSFER, sc, &sc->sc_lock);
        }
        if (err) {
                DPRINTFN(0, "cannot setup interrupt transfer, "
@@ -1169,9 +1168,9 @@ uhub_attach(device_t dev)
        /* Start the interrupt endpoint, if any */
 
        if (sc->sc_xfer[0] != NULL) {
-               mtx_lock(&sc->sc_mtx);
+               lockmgr(&sc->sc_lock, LK_EXCLUSIVE);
                usbd_transfer_start(sc->sc_xfer[0]);
-               mtx_unlock(&sc->sc_mtx);
+               lockmgr(&sc->sc_lock, LK_RELEASE);
        }
 
        /* Enable automatic power save on all USB HUBs */
@@ -1184,11 +1183,11 @@ error:
        usbd_transfer_unsetup(sc->sc_xfer, UHUB_N_TRANSFER);
 
        if (udev->hub) {
-               free(udev->hub, M_USBDEV);
+               kfree(udev->hub, M_USBDEV);
                udev->hub = NULL;
        }
 
-       mtx_destroy(&sc->sc_mtx);
+       lockuninit(&sc->sc_lock);
 
        return (ENXIO);
 }
@@ -1226,10 +1225,10 @@ uhub_detach(device_t dev)
                usb_free_device(child, 0);
        }
 
-       free(hub, M_USBDEV);
+       kfree(hub, M_USBDEV);
        sc->sc_udev->hub = NULL;
 
-       mtx_destroy(&sc->sc_mtx);
+       lockuninit(&sc->sc_lock);
 
        return (0);
 }
@@ -1312,7 +1311,9 @@ uhub_child_location_string(device_t parent, device_t child,
        sc = device_get_softc(parent);
        hub = sc->sc_udev->hub;
 
-       mtx_lock(&Giant);
+       /* XXX 
+     * mtx_lock(&Giant);
+     */
        uhub_find_iface_index(hub, child, &res);
        if (!res.udev) {
                DPRINTF("device not on hub\n");
@@ -1321,12 +1322,14 @@ uhub_child_location_string(device_t parent, device_t child,
                }
                goto done;
        }
-       snprintf(buf, buflen, "bus=%u hubaddr=%u port=%u devaddr=%u interface=%u",
+       ksnprintf(buf, buflen, "bus=%u hubaddr=%u port=%u devaddr=%u interface=%u",
            (res.udev->parent_hub != NULL) ? res.udev->parent_hub->device_index : 0,
            res.portno, device_get_unit(res.udev->bus->bdev),
            res.udev->device_index, res.iface_index);
 done:
-       mtx_unlock(&Giant);
+       /* XXX
+     * mtx_unlock(&Giant);
+     */
 
        return (0);
 }
@@ -1349,7 +1352,9 @@ uhub_child_pnpinfo_string(device_t parent, device_t child,
        sc = device_get_softc(parent);
        hub = sc->sc_udev->hub;
 
+    /* XXX
        mtx_lock(&Giant);
+    */
        uhub_find_iface_index(hub, child, &res);
        if (!res.udev) {
                DPRINTF("device not on hub\n");
@@ -1360,7 +1365,7 @@ uhub_child_pnpinfo_string(device_t parent, device_t child,
        }
        iface = usbd_get_iface(res.udev, res.iface_index);
        if (iface && iface->idesc) {
-               snprintf(buf, buflen, "vendor=0x%04x product=0x%04x "
+               ksnprintf(buf, buflen, "vendor=0x%04x product=0x%04x "
                    "devclass=0x%02x devsubclass=0x%02x "
                    "sernum=\"%s\" "
                    "release=0x%04x "
@@ -1386,8 +1391,9 @@ uhub_child_pnpinfo_string(device_t parent, device_t child,
                goto done;
        }
 done:
+    /* XXX
        mtx_unlock(&Giant);
-
+    */
        return (0);
 }
 
@@ -1484,9 +1490,8 @@ usb_hs_bandwidth_adjust(struct usb_device *udev, int16_t len,
        struct usb_hub *hub;
        enum usb_dev_speed speed;
        uint8_t x;
-
-       USB_BUS_LOCK_ASSERT(bus, MA_OWNED);
-
+    
+       USB_BUS_LOCK_ASSERT(bus);
        speed = usbd_get_speed(udev);
 
        switch (speed) {
@@ -1704,7 +1709,7 @@ usb_isoc_time_expand(struct usb_bus *bus, uint16_t isoc_time_curr)
 {
        uint16_t rem;
 
-       USB_BUS_LOCK_ASSERT(bus, MA_OWNED);
+       USB_BUS_LOCK_ASSERT(bus);
 
        rem = bus->isoc_time_last & (USB_ISOC_TIME_MAX - 1);
 
@@ -1883,11 +1888,11 @@ usb_bus_port_set_device(struct usb_bus *bus, struct usb_port *up,
         */
        if (device_index != 0) {
 #if USB_HAVE_UGEN
-               mtx_lock(&usb_ref_lock);
+               lockmgr(&usb_ref_lock, LK_EXCLUSIVE);
 #endif
                bus->devices[device_index] = udev;
 #if USB_HAVE_UGEN
-               mtx_unlock(&usb_ref_lock);
+               lockmgr(&usb_ref_lock, LK_RELEASE);
 #endif
        }
        /*
@@ -1917,7 +1922,7 @@ usb_needs_explore(struct usb_bus *bus, uint8_t do_probe)
                DPRINTF("No root HUB\n");
                return;
        }
-       if (mtx_owned(&bus->bus_mtx)) {
+       if (lockstatus(&bus->bus_lock, curthread) != 0) {
                do_unlock = 0;
        } else {
                USB_BUS_LOCK(bus);
index e03f9b6..00f8518 100644 (file)
@@ -25,7 +25,6 @@
  */
 
 #include <sys/stdint.h>
-#include <sys/stddef.h>
 #include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/types.h>
@@ -37,7 +36,6 @@
 #include <sys/mutex.h>
 #include <sys/condvar.h>
 #include <sys/sysctl.h>
-#include <sys/sx.h>
 #include <sys/unistd.h>
 #include <sys/callout.h>
 #include <sys/malloc.h>
@@ -45,8 +43,8 @@
 #include <sys/limits.h>
 #include <sys/endian.h>
 
-#include <dev/usb/usb.h>
-#include <dev/usb/usbdi.h>
+#include <bus/u4b/usb.h>
+#include <bus/u4b/usbdi.h>
 
 /*------------------------------------------------------------------------*
  *     usbd_lookup_id_by_info
index 65b2a91..d466e5c 100644 (file)
@@ -25,7 +25,6 @@
  */
 
 #include <sys/stdint.h>
-#include <sys/stddef.h>
 #include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/types.h>
 #include <sys/mutex.h>
 #include <sys/condvar.h>
 #include <sys/sysctl.h>
-#include <sys/sx.h>
 #include <sys/unistd.h>
 #include <sys/callout.h>
 #include <sys/malloc.h>
 #include <sys/priv.h>
 
-#include <dev/usb/usb.h>
-#include <dev/usb/usbdi.h>
-#include <dev/usb/usb_dev.h>
-#include <dev/usb/usb_mbuf.h>
+#include <bus/u4b/usb.h>
+#include <bus/u4b/usbdi.h>
+#include <bus/u4b/usb_dev.h>
+#include <bus/u4b/usb_mbuf.h>
 
 /*------------------------------------------------------------------------*
  *      usb_alloc_mbufs - allocate mbufs to an usbd interface queue
@@ -71,7 +69,7 @@ usb_alloc_mbufs(struct malloc_type *type, struct usb_ifqueue *ifq,
 
                alloc_size = (block_size + sizeof(struct usb_mbuf)) * nblocks;
 
-               free_ptr = malloc(alloc_size, type, M_WAITOK | M_ZERO);
+               free_ptr = kmalloc(alloc_size, type, M_WAITOK | M_ZERO);
 
                if (free_ptr == NULL) {
                        goto done;
index a6b01b8..c74c79e 100644 (file)
@@ -33,7 +33,6 @@
  */
 
 #include <sys/stdint.h>
-#include <sys/stddef.h>
 #include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/types.h>
 #include <sys/mutex.h>
 #include <sys/condvar.h>
 #include <sys/sysctl.h>
-#include <sys/sx.h>
 #include <sys/unistd.h>
 #include <sys/callout.h>
 #include <sys/malloc.h>
 #include <sys/priv.h>
 
-#include <dev/usb/usb.h>
-#include <dev/usb/usbdi.h>
-#include <dev/usb/usbdi_util.h>
+#include <bus/u4b/usb.h>
+#include <bus/u4b/usbdi.h>
+#include <bus/u4b/usbdi_util.h>
 
 #define        USB_DEBUG_VAR usb_debug
 
-#include <dev/usb/usb_busdma.h>
-#include <dev/usb/usb_process.h>
-#include <dev/usb/usb_transfer.h>
-#include <dev/usb/usb_msctest.h>
-#include <dev/usb/usb_debug.h>
-#include <dev/usb/usb_device.h>
-#include <dev/usb/usb_request.h>
-#include <dev/usb/usb_util.h>
-#include <dev/usb/quirk/usb_quirk.h>
+#include <bus/u4b/usb_busdma.h>
+#include <bus/u4b/usb_process.h>
+#include <bus/u4b/usb_transfer.h>
+#include <bus/u4b/usb_msctest.h>
+#include <bus/u4b/usb_debug.h>
+#include <bus/u4b/usb_device.h>
+#include <bus/u4b/usb_request.h>
+#include <bus/u4b/usb_util.h>
+#include <bus/u4b/quirk/usb_quirk.h>
 
 enum {
        ST_COMMAND,
@@ -135,7 +133,7 @@ struct bbb_csw {
 } __packed;
 
 struct bbb_transfer {
-       struct mtx mtx;
+       struct lock lock;
        struct cv cv;
        struct bbb_cbw cbw;
        struct bbb_csw csw;
@@ -479,13 +477,13 @@ bbb_command_start(struct bbb_transfer *sc, uint8_t dir, uint8_t lun,
        memcpy(&sc->cbw.CBWCDB, cmd_ptr, cmd_len);
        DPRINTFN(1, "SCSI cmd = %*D\n", (int)cmd_len, (char *)sc->cbw.CBWCDB, ":");
 
-       mtx_lock(&sc->mtx);
+       lockmgr(&sc->lock, LK_EXCLUSIVE);
        usbd_transfer_start(sc->xfer[sc->state]);
 
        while (usbd_transfer_pending(sc->xfer[sc->state])) {
-               cv_wait(&sc->cv, &sc->mtx);
+               cv_wait(&sc->cv, &sc->lock);
        }
-       mtx_unlock(&sc->mtx);
+       lockmgr(&sc->lock, LK_RELEASE);
        return (sc->error);
 }
 
@@ -541,12 +539,13 @@ bbb_attach(struct usb_device *udev, uint8_t iface_index)
                return (NULL);
        }
 
-       sc = malloc(sizeof(*sc), M_USB, M_WAITOK | M_ZERO);
-       mtx_init(&sc->mtx, "USB autoinstall", NULL, MTX_DEF);
+       sc = kmalloc(sizeof(*sc), M_USB, M_WAITOK | M_ZERO);
+       lockinit(&sc->lock, "USB autoinstall", 0, 0);
+
        cv_init(&sc->cv, "WBBB");
 
        err = usbd_transfer_setup(udev, &iface_index, sc->xfer, bbb_config,
-           ST_MAX, sc, &sc->mtx);
+           ST_MAX, sc, &sc->lock);
        if (err) {
                bbb_detach(sc);
                return (NULL);
@@ -558,9 +557,9 @@ static void
 bbb_detach(struct bbb_transfer *sc)
 {
        usbd_transfer_unsetup(sc->xfer, ST_MAX);
-       mtx_destroy(&sc->mtx);
+       lockuninit(&sc->lock);
        cv_destroy(&sc->cv);
-       free(sc, M_USB);
+       kfree(sc, M_USB);
 }
 
 /*------------------------------------------------------------------------*
@@ -790,7 +789,7 @@ usb_msc_eject(struct usb_device *udev, uint8_t iface_index, int method)
                    sizeof(scsi_tct_eject), USB_MS_HZ);
                break;
        default:
-               printf("usb_msc_eject: unknown eject method (%d)\n", method);
+               kprintf("usb_msc_eject: unknown eject method (%d)\n", method);
                break;
        }
        DPRINTF("Eject CD command status: %s\n", usbd_errstr(err));
index 66ab5fa..c56a36e 100644 (file)
@@ -25,7 +25,6 @@
  */
 
 #include <sys/stdint.h>
-#include <sys/stddef.h>
 #include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/types.h>
 #include <sys/mutex.h>
 #include <sys/condvar.h>
 #include <sys/sysctl.h>
-#include <sys/sx.h>
 #include <sys/unistd.h>
 #include <sys/callout.h>
 #include <sys/malloc.h>
 #include <sys/priv.h>
 
-#include <dev/usb/usb.h>
-#include <dev/usb/usbdi.h>
-#include <dev/usb/usbdi_util.h>
+#include <bus/u4b/usb.h>
+#include <bus/u4b/usbdi.h>
+#include <bus/u4b/usbdi_util.h>
 
 
 /*------------------------------------------------------------------------*
index 071dfc3..db68df4 100644 (file)
@@ -31,8 +31,8 @@
  * We don't want the following files included everywhere, that's why
  * they are in a separate file.
  */
-#include <dev/pci/pcireg.h>
-#include <dev/pci/pcivar.h>
+#include <bus/pci/pcireg.h>
+#include <bus/pci/pcivar.h>
 
 #include <sys/rman.h>
 
index 6d65439..3a3840d 100644 (file)
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+//__FBSDID("$FreeBSD$");
 #include <sys/param.h>
 #include <sys/kernel.h>
 #include <sys/bus.h>
@@ -46,17 +46,18 @@ __FBSDID("$FreeBSD$");
 #include <net/if_types.h>
 #include <net/bpf.h>
 #include <sys/sysctl.h>
-
-#include <dev/usb/usb.h>
-#include <dev/usb/usbdi.h>
-#include <dev/usb/usb_busdma.h>
-#include <dev/usb/usb_controller.h>
-#include <dev/usb/usb_core.h>
-#include <dev/usb/usb_process.h>
-#include <dev/usb/usb_device.h>
-#include <dev/usb/usb_bus.h>
-#include <dev/usb/usb_pf.h>
-#include <dev/usb/usb_transfer.h>
+#include <sys/condvar.h>
+
+#include <bus/u4b/usb.h>
+#include <bus/u4b/usbdi.h>
+#include <bus/u4b/usb_busdma.h>
+#include <bus/u4b/usb_controller.h>
+#include <bus/u4b/usb_core.h>
+#include <bus/u4b/usb_process.h>
+#include <bus/u4b/usb_device.h>
+#include <bus/u4b/usb_bus.h>
+#include <bus/u4b/usb_pf.h>
+#include <bus/u4b/usb_transfer.h>
 
 static int usb_no_pf;
 
index ab579f2..5c5d382 100644 (file)
@@ -27,7 +27,6 @@
 #define        USB_DEBUG_VAR usb_proc_debug
 
 #include <sys/stdint.h>
-#include <sys/stddef.h>
 #include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/types.h>
 #include <sys/mutex.h>
 #include <sys/condvar.h>
 #include <sys/sysctl.h>
-#include <sys/sx.h>
 #include <sys/unistd.h>
 #include <sys/callout.h>
 #include <sys/malloc.h>
 #include <sys/priv.h>
 
-#include <dev/usb/usb.h>
-#include <dev/usb/usbdi.h>
-#include <dev/usb/usbdi_util.h>
-#include <dev/usb/usb_process.h>
-#include <dev/usb/usb_debug.h>
-#include <dev/usb/usb_util.h>
+#include <bus/u4b/usb.h>
+#include <bus/u4b/usbdi.h>
+#include <bus/u4b/usbdi_util.h>
+#include <bus/u4b/usb_process.h>
+#include <bus/u4b/usb_debug.h>
+#include <bus/u4b/usb_util.h>
 
 #include <sys/proc.h>
 #include <sys/kthread.h>
 #include <sys/sched.h>
 
-#if (__FreeBSD_version < 700000)
-#define        thread_lock(td) mtx_lock_spin(&sched_lock)
-#define        thread_unlock(td) mtx_unlock_spin(&sched_lock)
-#endif
 
-#if (__FreeBSD_version >= 800000)
-static struct proc *usbproc;
 static int usb_pcount;
 #define        USB_THREAD_CREATE(f, s, p, ...) \
-               kproc_kthread_add((f), (s), &usbproc, (p), RFHIGHPID, \
-                   0, "usb", __VA_ARGS__)
-#if (__FreeBSD_version >= 900000)
-#define        USB_THREAD_SUSPEND_CHECK() kthread_suspend_check()
-#else
-#define        USB_THREAD_SUSPEND_CHECK() kthread_suspend_check(curthread)
-#endif
-#define        USB_THREAD_SUSPEND(p)   kthread_suspend(p,0)
-#define        USB_THREAD_EXIT(err)    kthread_exit()
-#else
-#define        USB_THREAD_CREATE(f, s, p, ...) \
-               kthread_create((f), (s), (p), RFHIGHPID, 0, __VA_ARGS__)
+               kthread_create((f), (s), (p), __VA_ARGS__)
 #define        USB_THREAD_SUSPEND_CHECK() kthread_suspend_check(curproc)
-#define        USB_THREAD_SUSPEND(p)   kthread_suspend(p,0)
-#define        USB_THREAD_EXIT(err)    kthread_exit(err)
-#endif
+#define        USB_THREAD_SUSPEND(p)   suspend_kproc(p,0)
+#define        USB_THREAD_EXIT(err)    kthread_exit()
 
 #ifdef USB_DEBUG
 static int usb_proc_debug;
@@ -105,15 +85,14 @@ usb_process(void *arg)
        struct thread *td;
 
        /* in case of attach error, check for suspended */
-       USB_THREAD_SUSPEND_CHECK();
+       /* XXX Suspend here?
+    *  USB_THREAD_SUSPEND_CHECK();
+    */
 
        /* adjust priority */
-       td = curthread;
-       thread_lock(td);
-       sched_prio(td, up->up_prio);
-       thread_unlock(td);
-
-       mtx_lock(up->up_mtx);
+    td = curthread;
+    lwkt_setpri(td, up->up_prio);
+       lockmgr(up->up_lock, LK_EXCLUSIVE);
 
        up->up_curtd = td;
 
@@ -188,18 +167,17 @@ usb_process(void *arg)
                        cv_broadcast(&up->up_drain);
                }
                up->up_msleep = 1;
-               cv_wait(&up->up_cv, up->up_mtx);
+               cv_wait(&up->up_cv, up->up_lock);
        }
 
        up->up_ptr = NULL;
        cv_signal(&up->up_cv);
-       mtx_unlock(up->up_mtx);
-#if (__FreeBSD_version >= 800000)
+       lockmgr(up->up_lock, LK_RELEASE);
        /* Clear the proc pointer if this is the last thread. */
+/*
        if (--usb_pcount == 0)
                usbproc = NULL;
-#endif
-
+*/
        USB_THREAD_EXIT(0);
 }
 
@@ -217,10 +195,12 @@ usb_process(void *arg)
  * Else: failure
  *------------------------------------------------------------------------*/
 int
-usb_proc_create(struct usb_process *up, struct mtx *p_mtx,
+usb_proc_create(struct usb_process *up, struct lock *p_lock,
     const char *pmesg, uint8_t prio)
 {
-       up->up_mtx = p_mtx;
+    kprintf("Creating usb_proc: %s\n", pmesg);
+
+       up->up_lock = p_lock;
        up->up_prio = prio;
 
        TAILQ_INIT(&up->up_qhead);
@@ -234,9 +214,7 @@ usb_proc_create(struct usb_process *up, struct mtx *p_mtx,
                up->up_ptr = NULL;
                goto error;
        }
-#if (__FreeBSD_version >= 800000)
        usb_pcount++;
-#endif
        return (0);
 
 error:
@@ -257,7 +235,7 @@ void
 usb_proc_free(struct usb_process *up)
 {
        /* check if not initialised */
-       if (up->up_mtx == NULL)
+       if (up->up_lock == NULL)
                return;
 
        usb_proc_drain(up);
@@ -266,7 +244,7 @@ usb_proc_free(struct usb_process *up)
        cv_destroy(&up->up_drain);
 
        /* make sure that we do not enter here again */
-       up->up_mtx = NULL;
+       up->up_lock = NULL;
 }
 
 /*------------------------------------------------------------------------*
@@ -293,7 +271,7 @@ usb_proc_msignal(struct usb_process *up, void *_pm0, void *_pm1)
        if (up->up_gone)
                return (_pm0);
 
-       mtx_assert(up->up_mtx, MA_OWNED);
+    KKASSERT(lockstatus(up->up_lock, curthread) != 0);
 
        t = 0;
 
@@ -373,8 +351,9 @@ usb_proc_is_gone(struct usb_process *up)
         * Allow calls when up_mtx is NULL, before the USB process
         * structure is initialised.
         */
-       if (up->up_mtx != NULL)
-               mtx_assert(up->up_mtx, MA_OWNED);
+       if (up->up_lock != NULL)
+        KKASSERT(lockstatus(up->up_lock, curthread)!=0);
+
        return (0);
 }
 
@@ -395,7 +374,7 @@ usb_proc_mwait(struct usb_process *up, void *_pm0, void *_pm1)
        if (up->up_gone)
                return;
 
-       mtx_assert(up->up_mtx, MA_OWNED);
+    KKASSERT(lockstatus(up->up_lock, curthread) != 0);
 
        if (up->up_curtd == curthread) {
                /* Just remove the messages from the queue. */
@@ -414,7 +393,7 @@ usb_proc_mwait(struct usb_process *up, void *_pm0, void *_pm1)
                        if (up->up_gone)
                                break;
                        up->up_dsleep = 1;
-                       cv_wait(&up->up_drain, up->up_mtx);
+                       cv_wait(&up->up_drain, up->up_lock);
                }
 }
 
@@ -431,13 +410,15 @@ void
 usb_proc_drain(struct usb_process *up)
 {
        /* check if not initialised */
-       if (up->up_mtx == NULL)
+       if (up->up_lock == NULL)
                return;
        /* handle special case with Giant */
+    /* XXX
        if (up->up_mtx != &Giant)
                mtx_assert(up->up_mtx, MA_NOTOWNED);
-
-       mtx_lock(up->up_mtx);
+    */
+    KKASSERT(lockstatus(up->up_lock, curthread) == 0);
+       lockmgr(up->up_lock, LK_EXCLUSIVE);
 
        /* Set the gone flag */
 
@@ -456,11 +437,11 @@ usb_proc_drain(struct usb_process *up)
 
                if (cold) {
                        USB_THREAD_SUSPEND(up->up_ptr);
-                       printf("WARNING: A USB process has "
+                       kprintf("WARNING: A USB process has "
                            "been left suspended\n");
                        break;
                }
-               cv_wait(&up->up_cv, up->up_mtx);
+               cv_wait(&up->up_cv, up->up_lock);
        }
        /* Check if someone is waiting - should not happen */
 
@@ -470,7 +451,7 @@ usb_proc_drain(struct usb_process *up)
                DPRINTF("WARNING: Someone is waiting "
                    "for USB process drain!\n");
        }
-       mtx_unlock(up->up_mtx);
+    lockmgr(up->up_lock, LK_RELEASE);
 }
 
 /*------------------------------------------------------------------------*
@@ -479,19 +460,18 @@ usb_proc_drain(struct usb_process *up)
  * This function is called to re-wakeup the given USB
  * process. This usually happens after that the USB system has been in
  * polling mode, like during a panic. This function must be called
- * having "up->up_mtx" locked.
+ * having "up->up_lock" locked.
  *------------------------------------------------------------------------*/
 void
 usb_proc_rewakeup(struct usb_process *up)
 {
        /* check if not initialised */
-       if (up->up_mtx == NULL)
+       if (up->up_lock == NULL)
                return;
        /* check if gone */
        if (up->up_gone)
                return;
-
-       mtx_assert(up->up_mtx, MA_OWNED);
+       KKASSERT(lockstatus(up->up_lock, curthread) != 0);
 
        if (up->up_msleep == 0) {
                /* re-wakeup */
index 23cf660..03ae242 100644 (file)
 #define        _USB_PROCESS_H_
 
 #include <sys/interrupt.h>
-#include <sys/priority.h>
-#include <sys/runq.h>
+#include <sys/signalvar.h>
+#include <sys/thread.h>
+//#include <sys/priority.h>
+//#include <sys/runq.h>
 
 /* defines */
-#define        USB_PRI_HIGH    PI_SWI(SWI_NET)
-#define        USB_PRI_MED     PI_SWI(SWI_CAMBIO)
+#define        USB_PRI_HIGH    TDPRI_INT_HIGH
+#define        USB_PRI_MED TDPRI_INT_MED
 
 #define        USB_PROC_WAIT_TIMEOUT 2
 #define        USB_PROC_WAIT_DRAIN   1
@@ -51,13 +53,9 @@ struct usb_process {
        struct cv up_cv;
        struct cv up_drain;
 
-#if (__FreeBSD_version >= 800000)
        struct thread *up_ptr;
-#else
-       struct proc *up_ptr;
-#endif
        struct thread *up_curtd;
-       struct mtx *up_mtx;
+       struct lock *up_lock;
 
        usb_size_t up_msg_num;
 
@@ -71,7 +69,7 @@ struct usb_process {
 /* prototypes */
 
 uint8_t        usb_proc_is_gone(struct usb_process *up);
-int    usb_proc_create(struct usb_process *up, struct mtx *p_mtx,
+int    usb_proc_create(struct usb_process *up, struct lock *p_lock,
            const char *pmesg, uint8_t prio);
 void   usb_proc_drain(struct usb_process *up);
 void   usb_proc_mwait(struct usb_process *up, void *pm0, void *pm1);
index c403a70..8448100 100644 (file)
@@ -27,7 +27,6 @@
  */ 
 
 #include <sys/stdint.h>
-#include <sys/stddef.h>
 #include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/types.h>
 #include <sys/mutex.h>
 #include <sys/condvar.h>
 #include <sys/sysctl.h>
-#include <sys/sx.h>
+//#include <sys/sx.h>
 #include <sys/unistd.h>
 #include <sys/callout.h>
 #include <sys/malloc.h>
 #include <sys/priv.h>
 
-#include <dev/usb/usb.h>
-#include <dev/usb/usbdi.h>
-#include <dev/usb/usbdi_util.h>
-#include <dev/usb/usb_ioctl.h>
-#include <dev/usb/usbhid.h>
+#include <bus/u4b/usb.h>
+#include <bus/u4b/usbdi.h>
+#include <bus/u4b/usbdi_util.h>
+#include <bus/u4b/usb_ioctl.h>
+#include <bus/u4b/usbhid.h>
 
 #define        USB_DEBUG_VAR usb_debug
 
-#include <dev/usb/usb_core.h>
-#include <dev/usb/usb_busdma.h>
-#include <dev/usb/usb_request.h>
-#include <dev/usb/usb_process.h>
-#include <dev/usb/usb_transfer.h>
-#include <dev/usb/usb_debug.h>
-#include <dev/usb/usb_device.h>
-#include <dev/usb/usb_util.h>
-#include <dev/usb/usb_dynamic.h>
-
-#include <dev/usb/usb_controller.h>
-#include <dev/usb/usb_bus.h>
+#include <bus/u4b/usb_core.h>
+#include <bus/u4b/usb_busdma.h>
+#include <bus/u4b/usb_request.h>
+#include <bus/u4b/usb_process.h>
+#include <bus/u4b/usb_transfer.h>
+#include <bus/u4b/usb_debug.h>
+#include <bus/u4b/usb_device.h>
+#include <bus/u4b/usb_util.h>
+#include <bus/u4b/usb_dynamic.h>
+
+#include <bus/u4b/usb_controller.h>
+#include <bus/u4b/usb_bus.h>
 #include <sys/ctype.h>
 
 static int usb_no_cs_fail;
@@ -399,7 +398,7 @@ usbd_get_hr_func(struct usb_device *udev)
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_do_request_flags(struct usb_device *udev, struct mtx *mtx,
+usbd_do_request_flags(struct usb_device *udev, struct lock *lock,
     struct usb_device_request *req, void *data, uint16_t flags,
     uint16_t *actlen, usb_timeout_t timeout)
 {
@@ -454,9 +453,12 @@ usbd_do_request_flags(struct usb_device *udev, struct mtx *mtx,
        if (flags & USB_USER_DATA_PTR)
                return (USB_ERR_INVAL);
 #endif
+    /*
        if ((mtx != NULL) && (mtx != &Giant)) {
-               mtx_unlock(mtx);
-               mtx_assert(mtx, MA_NOTOWNED);
+    */
+    if (lock != NULL) {
+               lockmgr(lock, LK_RELEASE);
+        KKASSERT(lockstatus(lock, curthread) == 0);
        }
 
        /*
@@ -470,7 +472,7 @@ usbd_do_request_flags(struct usb_device *udev, struct mtx *mtx,
         * Grab the default sx-lock so that serialisation
         * is achieved when multiple threads are involved:
         */
-       sx_xlock(&udev->ctrl_sx);
+    lockmgr(&udev->ctrl_lock, LK_EXCLUSIVE);
 
        hr_func = usbd_get_hr_func(udev);
 
@@ -581,7 +583,7 @@ usbd_do_request_flags(struct usb_device *udev, struct mtx *mtx,
                                }
                                if (dbg.ds_delay > 0) {
                                        usb_pause_mtx(
-                                           xfer->xroot->xfer_mtx,
+                                           xfer->xroot->xfer_lock,
                                            USB_MS_TO_TICKS(dbg.ds_delay));
                                        /* make sure we don't time out */
                                        start_ticks = ticks;
@@ -619,7 +621,7 @@ usbd_do_request_flags(struct usb_device *udev, struct mtx *mtx,
                                        }
                                        if (dbg.ss_delay > 0) {
                                                usb_pause_mtx(
-                                                   xfer->xroot->xfer_mtx,
+                                                   xfer->xroot->xfer_lock,
                                                    USB_MS_TO_TICKS(dbg.ss_delay));
                                                /* make sure we don't time out */
                                                start_ticks = ticks;
@@ -637,7 +639,7 @@ usbd_do_request_flags(struct usb_device *udev, struct mtx *mtx,
 
                while (usbd_transfer_pending(xfer)) {
                        cv_wait(&udev->ctrlreq_cv,
-                           xfer->xroot->xfer_mtx);
+                           xfer->xroot->xfer_lock);
                }
 
                err = xfer->error;
@@ -714,13 +716,16 @@ usbd_do_request_flags(struct usb_device *udev, struct mtx *mtx,
        USB_XFER_UNLOCK(xfer);
 
 done:
-       sx_xunlock(&udev->ctrl_sx);
+    lockmgr(&udev->ctrl_lock, LK_RELEASE);
 
        if (enum_locked)
                usbd_sr_lock(udev);
 
+/*
        if ((mtx != NULL) && (mtx != &Giant))
-               mtx_lock(mtx);
+*/
+    if (lock != NULL)
+               lockmgr(lock, LK_EXCLUSIVE);
 
        return ((usb_error_t)err);
 }
@@ -753,7 +758,7 @@ usbd_do_request_proc(struct usb_device *udev, struct usb_process *pproc,
        }
 
        /* forward the USB request */
-       err = usbd_do_request_flags(udev, pproc->up_mtx,
+       err = usbd_do_request_flags(udev, pproc->up_lock,
            req, data, flags, actlen, timeout);
 
 done:
@@ -780,7 +785,7 @@ done:
  *       disabled.
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_reset_port(struct usb_device *udev, struct mtx *mtx, uint8_t port)
+usbd_req_reset_port(struct usb_device *udev, struct lock *lock, uint8_t port)
 {
        struct usb_port_status ps;
        usb_error_t err;
@@ -798,11 +803,11 @@ usbd_req_reset_port(struct usb_device *udev, struct mtx *mtx, uint8_t port)
 
        /* clear any leftover port reset changes first */
        usbd_req_clear_port_feature(
-           udev, mtx, port, UHF_C_PORT_RESET);
+           udev, lock, port, UHF_C_PORT_RESET);
 
        /* assert port reset on the given port */
        err = usbd_req_set_port_feature(
-           udev, mtx, port, UHF_PORT_RESET);
+           udev, lock, port, UHF_PORT_RESET);
 
        /* check for errors */
        if (err)
@@ -824,14 +829,14 @@ usbd_req_reset_port(struct usb_device *udev, struct mtx *mtx, uint8_t port)
        while (1) {
 #ifdef USB_DEBUG
                /* wait for the device to recover from reset */
-               usb_pause_mtx(mtx, USB_MS_TO_TICKS(pr_poll_delay));
+               usb_pause_mtx(lock, USB_MS_TO_TICKS(pr_poll_delay));
                n += pr_poll_delay;
 #else
                /* wait for the device to recover from reset */
-               usb_pause_mtx(mtx, USB_MS_TO_TICKS(USB_PORT_RESET_DELAY));
+               usb_pause_mtx(lock, USB_MS_TO_TICKS(USB_PORT_RESET_DELAY));
                n += USB_PORT_RESET_DELAY;
 #endif
-               err = usbd_req_get_port_status(udev, mtx, &ps, port);
+               err = usbd_req_get_port_status(udev, lock, &ps, port);
                if (err)
                        goto done;
 
@@ -863,7 +868,7 @@ usbd_req_reset_port(struct usb_device *udev, struct mtx *mtx, uint8_t port)
 
        /* clear port reset first */
        err = usbd_req_clear_port_feature(
-           udev, mtx, port, UHF_C_PORT_RESET);
+           udev, lock, port, UHF_C_PORT_RESET);
        if (err)
                goto done;
 
@@ -874,10 +879,10 @@ usbd_req_reset_port(struct usb_device *udev, struct mtx *mtx, uint8_t port)
        }
 #ifdef USB_DEBUG
        /* wait for the device to recover from reset */
-       usb_pause_mtx(mtx, USB_MS_TO_TICKS(pr_recovery_delay));
+       usb_pause_mtx(lock, USB_MS_TO_TICKS(pr_recovery_delay));
 #else
        /* wait for the device to recover from reset */
-       usb_pause_mtx(mtx, USB_MS_TO_TICKS(USB_PORT_RESET_RECOVERY));
+       usb_pause_mtx(lock, USB_MS_TO_TICKS(USB_PORT_RESET_RECOVERY));
 #endif
 
 done:
@@ -900,7 +905,7 @@ done:
  *       disabled.
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_warm_reset_port(struct usb_device *udev, struct mtx *mtx,
+usbd_req_warm_reset_port(struct usb_device *udev, struct lock *lock,
     uint8_t port)
 {
        struct usb_port_status ps;
@@ -917,7 +922,7 @@ usbd_req_warm_reset_port(struct usb_device *udev, struct mtx *mtx,
 
        DPRINTF("\n");
 
-       err = usbd_req_get_port_status(udev, mtx, &ps, port);
+       err = usbd_req_get_port_status(udev, lock, &ps, port);
        if (err)
                goto done;
 
@@ -935,11 +940,11 @@ usbd_req_warm_reset_port(struct usb_device *udev, struct mtx *mtx,
        }
 
        /* clear any leftover warm port reset changes first */
-       usbd_req_clear_port_feature(udev, mtx,
+       usbd_req_clear_port_feature(udev, lock,
            port, UHF_C_BH_PORT_RESET);
 
        /* set warm port reset */
-       err = usbd_req_set_port_feature(udev, mtx,
+       err = usbd_req_set_port_feature(udev, lock,
            port, UHF_BH_PORT_RESET);
        if (err)
                goto done;
@@ -961,14 +966,14 @@ usbd_req_warm_reset_port(struct usb_device *udev, struct mtx *mtx,
        while (1) {
 #ifdef USB_DEBUG
                /* wait for the device to recover from reset */
-               usb_pause_mtx(mtx, USB_MS_TO_TICKS(pr_poll_delay));
+               usb_pause_mtx(lock, USB_MS_TO_TICKS(pr_poll_delay));
                n += pr_poll_delay;
 #else
                /* wait for the device to recover from reset */
-               usb_pause_mtx(mtx, USB_MS_TO_TICKS(USB_PORT_RESET_DELAY));
+               usb_pause_mtx(lock, USB_MS_TO_TICKS(USB_PORT_RESET_DELAY));
                n += USB_PORT_RESET_DELAY;
 #endif
-               err = usbd_req_get_port_status(udev, mtx, &ps, port);
+               err = usbd_req_get_port_status(udev, lock, &ps, port);
                if (err)
                        goto done;
 
@@ -992,7 +997,7 @@ usbd_req_warm_reset_port(struct usb_device *udev, struct mtx *mtx,
 
        /* clear port reset first */
        err = usbd_req_clear_port_feature(
-           udev, mtx, port, UHF_C_BH_PORT_RESET);
+           udev, lock, port, UHF_C_BH_PORT_RESET);
        if (err)
                goto done;
 
@@ -1003,10 +1008,10 @@ usbd_req_warm_reset_port(struct usb_device *udev, struct mtx *mtx,
        }
 #ifdef USB_DEBUG
        /* wait for the device to recover from reset */
-       usb_pause_mtx(mtx, USB_MS_TO_TICKS(pr_recovery_delay));
+       usb_pause_mtx(lock, USB_MS_TO_TICKS(pr_recovery_delay));
 #else
        /* wait for the device to recover from reset */
-       usb_pause_mtx(mtx, USB_MS_TO_TICKS(USB_PORT_RESET_RECOVERY));
+       usb_pause_mtx(lock, USB_MS_TO_TICKS(USB_PORT_RESET_RECOVERY));
 #endif
 
 done:
@@ -1041,7 +1046,7 @@ done:
  *------------------------------------------------------------------------*/
 usb_error_t
 usbd_req_get_desc(struct usb_device *udev,
-    struct mtx *mtx, uint16_t *actlen, void *desc,
+    struct lock *lock, uint16_t *actlen, void *desc,
     uint16_t min_len, uint16_t max_len,
     uint16_t id, uint8_t type, uint8_t index,
     uint8_t retries)
@@ -1066,7 +1071,7 @@ usbd_req_get_desc(struct usb_device *udev,
                }
                USETW(req.wLength, min_len);
 
-               err = usbd_do_request_flags(udev, mtx, &req,
+               err = usbd_do_request_flags(udev, lock, &req,
                    desc, 0, NULL, 1000);
 
                if (err) {
@@ -1075,7 +1080,7 @@ usbd_req_get_desc(struct usb_device *udev,
                        }
                        retries--;
 
-                       usb_pause_mtx(mtx, hz / 5);
+                       usb_pause_mtx(lock, hz / 5);
 
                        continue;
                }
@@ -1131,7 +1136,7 @@ done:
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_get_string_any(struct usb_device *udev, struct mtx *mtx, char *buf,
+usbd_req_get_string_any(struct usb_device *udev, struct lock *lock, char *buf,
     uint16_t len, uint8_t string_index)
 {
        char *s;
@@ -1156,7 +1161,7 @@ usbd_req_get_string_any(struct usb_device *udev, struct mtx *mtx, char *buf,
                return (USB_ERR_STALLED);
        }
        err = usbd_req_get_string_desc
-           (udev, mtx, buf, len, udev->langid, string_index);
+           (udev, lock, buf, len, udev->langid, string_index);
        if (err) {
                buf[0] = 0;
                return (err);
@@ -1233,11 +1238,11 @@ usbd_req_get_string_any(struct usb_device *udev, struct mtx *mtx, char *buf,
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_get_string_desc(struct usb_device *udev, struct mtx *mtx, void *sdesc,
+usbd_req_get_string_desc(struct usb_device *udev, struct lock *lock, void *sdesc,
     uint16_t max_len, uint16_t lang_id,
     uint8_t string_index)
 {
-       return (usbd_req_get_desc(udev, mtx, NULL, sdesc, 2, max_len, lang_id,
+       return (usbd_req_get_desc(udev, lock, NULL, sdesc, 2, max_len, lang_id,
            UDESC_STRING, string_index, 0));
 }
 
@@ -1299,14 +1304,14 @@ usbd_req_get_descriptor_ptr(struct usb_device *udev,
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_get_config_desc(struct usb_device *udev, struct mtx *mtx,
+usbd_req_get_config_desc(struct usb_device *udev, struct lock *lock,
     struct usb_config_descriptor *d, uint8_t conf_index)
 {
        usb_error_t err;
 
        DPRINTFN(4, "confidx=%d\n", conf_index);
 
-       err = usbd_req_get_desc(udev, mtx, NULL, d, sizeof(*d),
+       err = usbd_req_get_desc(udev, lock, NULL, d, sizeof(*d),
            sizeof(*d), 0, UDESC_CONFIG, conf_index, 0);
        if (err) {
                goto done;
@@ -1330,7 +1335,7 @@ done:
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_get_config_desc_full(struct usb_device *udev, struct mtx *mtx,
+usbd_req_get_config_desc_full(struct usb_device *udev, struct lock *lock,
     struct usb_config_descriptor **ppcd, struct malloc_type *mtype,
     uint8_t index)
 {
@@ -1343,7 +1348,7 @@ usbd_req_get_config_desc_full(struct usb_device *udev, struct mtx *mtx,
 
        *ppcd = NULL;
 
-       err = usbd_req_get_config_desc(udev, mtx, &cd, index);
+       err = usbd_req_get_config_desc(udev, lock, &cd, index);
        if (err) {
                return (err);
        }
@@ -1353,14 +1358,14 @@ usbd_req_get_config_desc_full(struct usb_device *udev, struct mtx *mtx,
                /* corrupt descriptor */
                return (USB_ERR_INVAL);
        }
-       cdesc = malloc(len, mtype, M_WAITOK);
+       cdesc = kmalloc(len, mtype, M_WAITOK);
        if (cdesc == NULL) {
                return (USB_ERR_NOMEM);
        }
-       err = usbd_req_get_desc(udev, mtx, NULL, cdesc, len, len, 0,
+       err = usbd_req_get_desc(udev, lock, NULL, cdesc, len, len, 0,
            UDESC_CONFIG, index, 3);
        if (err) {
-               free(cdesc, mtype);
+               kfree(cdesc, mtype);
                return (err);
        }
        /* make sure that the device is not fooling us: */
@@ -1379,11 +1384,11 @@ usbd_req_get_config_desc_full(struct usb_device *udev, struct mtx *mtx,
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_get_device_desc(struct usb_device *udev, struct mtx *mtx,
+usbd_req_get_device_desc(struct usb_device *udev, struct lock *lock,
     struct usb_device_descriptor *d)
 {
        DPRINTFN(4, "\n");
-       return (usbd_req_get_desc(udev, mtx, NULL, d, sizeof(*d),
+       return (usbd_req_get_desc(udev, lock, NULL, d, sizeof(*d),
            sizeof(*d), 0, UDESC_DEVICE, 0, 3));
 }
 
@@ -1395,7 +1400,7 @@ usbd_req_get_device_desc(struct usb_device *udev, struct mtx *mtx,
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_get_alt_interface_no(struct usb_device *udev, struct mtx *mtx,
+usbd_req_get_alt_interface_no(struct usb_device *udev, struct lock *lock,
     uint8_t *alt_iface_no, uint8_t iface_index)
 {
        struct usb_interface *iface = usbd_get_iface(udev, iface_index);
@@ -1410,7 +1415,7 @@ usbd_req_get_alt_interface_no(struct usb_device *udev, struct mtx *mtx,
        req.wIndex[0] = iface->idesc->bInterfaceNumber;
        req.wIndex[1] = 0;
        USETW(req.wLength, 1);
-       return (usbd_do_request(udev, mtx, &req, alt_iface_no));
+       return (usbd_do_request(udev, lock, &req, alt_iface_no));
 }
 
 /*------------------------------------------------------------------------*
@@ -1421,7 +1426,7 @@ usbd_req_get_alt_interface_no(struct usb_device *udev, struct mtx *mtx,
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_set_alt_interface_no(struct usb_device *udev, struct mtx *mtx,
+usbd_req_set_alt_interface_no(struct usb_device *udev, struct lock *lock,
     uint8_t iface_index, uint8_t alt_no)
 {
        struct usb_interface *iface = usbd_get_iface(udev, iface_index);
@@ -1437,7 +1442,7 @@ usbd_req_set_alt_interface_no(struct usb_device *udev, struct mtx *mtx,
        req.wIndex[0] = iface->idesc->bInterfaceNumber;
        req.wIndex[1] = 0;
        USETW(req.wLength, 0);
-       return (usbd_do_request(udev, mtx, &req, 0));
+       return (usbd_do_request(udev, lock, &req, 0));
 }
 
 /*------------------------------------------------------------------------*
@@ -1448,7 +1453,7 @@ usbd_req_set_alt_interface_no(struct usb_device *udev, struct mtx *mtx,
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_get_device_status(struct usb_device *udev, struct mtx *mtx,
+usbd_req_get_device_status(struct usb_device *udev, struct lock *lock,
     struct usb_status *st)
 {
        struct usb_device_request req;
@@ -1458,7 +1463,7 @@ usbd_req_get_device_status(struct usb_device *udev, struct mtx *mtx,
        USETW(req.wValue, 0);
        USETW(req.wIndex, 0);
        USETW(req.wLength, sizeof(*st));
-       return (usbd_do_request(udev, mtx, &req, st));
+       return (usbd_do_request(udev, lock, &req, st));
 }
 
 /*------------------------------------------------------------------------*
@@ -1469,7 +1474,7 @@ usbd_req_get_device_status(struct usb_device *udev, struct mtx *mtx,
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_get_hub_descriptor(struct usb_device *udev, struct mtx *mtx,
+usbd_req_get_hub_descriptor(struct usb_device *udev, struct lock *lock,
     struct usb_hub_descriptor *hd, uint8_t nports)
 {
        struct usb_device_request req;
@@ -1480,7 +1485,7 @@ usbd_req_get_hub_descriptor(struct usb_device *udev, struct mtx *mtx,
        USETW2(req.wValue, UDESC_HUB, 0);
        USETW(req.wIndex, 0);
        USETW(req.wLength, len);
-       return (usbd_do_request(udev, mtx, &req, hd));
+       return (usbd_do_request(udev, lock, &req, hd));
 }
 
 /*------------------------------------------------------------------------*
@@ -1491,7 +1496,7 @@ usbd_req_get_hub_descriptor(struct usb_device *udev, struct mtx *mtx,
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_get_ss_hub_descriptor(struct usb_device *udev, struct mtx *mtx,
+usbd_req_get_ss_hub_descriptor(struct usb_device *udev, struct lock *lock,
     struct usb_hub_ss_descriptor *hd, uint8_t nports)
 {
        struct usb_device_request req;
@@ -1502,7 +1507,7 @@ usbd_req_get_ss_hub_descriptor(struct usb_device *udev, struct mtx *mtx,
        USETW2(req.wValue, UDESC_SS_HUB, 0);
        USETW(req.wIndex, 0);
        USETW(req.wLength, len);
-       return (usbd_do_request(udev, mtx, &req, hd));
+       return (usbd_do_request(udev, lock, &req, hd));
 }
 
 /*------------------------------------------------------------------------*
@@ -1513,7 +1518,7 @@ usbd_req_get_ss_hub_descriptor(struct usb_device *udev, struct mtx *mtx,
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_get_hub_status(struct usb_device *udev, struct mtx *mtx,
+usbd_req_get_hub_status(struct usb_device *udev, struct lock *lock,
     struct usb_hub_status *st)
 {
        struct usb_device_request req;
@@ -1523,7 +1528,7 @@ usbd_req_get_hub_status(struct usb_device *udev, struct mtx *mtx,
        USETW(req.wValue, 0);
        USETW(req.wIndex, 0);
        USETW(req.wLength, sizeof(struct usb_hub_status));
-       return (usbd_do_request(udev, mtx, &req, st));
+       return (usbd_do_request(udev, lock, &req, st));
 }
 
 /*------------------------------------------------------------------------*
@@ -1537,7 +1542,7 @@ usbd_req_get_hub_status(struct usb_device *udev, struct mtx *mtx,
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_set_address(struct usb_device *udev, struct mtx *mtx, uint16_t addr)
+usbd_req_set_address(struct usb_device *udev, struct lock *lock, uint16_t addr)
 {
        struct usb_device_request req;
        usb_error_t err;
@@ -1554,18 +1559,18 @@ usbd_req_set_address(struct usb_device *udev, struct mtx *mtx, uint16_t addr)
 
        /* check if USB controller handles set address */
        if (udev->bus->methods->set_address != NULL)
-               err = (udev->bus->methods->set_address) (udev, mtx, addr);
+               err = (udev->bus->methods->set_address) (udev, lock, addr);
 
        if (err != USB_ERR_INVAL)
                goto done;
 
        /* Setting the address should not take more than 1 second ! */
-       err = usbd_do_request_flags(udev, mtx, &req, NULL,
+       err = usbd_do_request_flags(udev, lock, &req, NULL,
            USB_DELAY_STATUS_STAGE, NULL, 1000);
 
 done:
        /* allow device time to set new address */
-       usb_pause_mtx(mtx,
+       usb_pause_mtx(lock,
            USB_MS_TO_TICKS(USB_SET_ADDRESS_SETTLE));
 
        return (err);
@@ -1579,7 +1584,7 @@ done:
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_get_port_status(struct usb_device *udev, struct mtx *mtx,
+usbd_req_get_port_status(struct usb_device *udev, struct lock *lock,
     struct usb_port_status *ps, uint8_t port)
 {
        struct usb_device_request req;
@@ -1590,7 +1595,7 @@ usbd_req_get_port_status(struct usb_device *udev, struct mtx *mtx,
        req.wIndex[0] = port;
        req.wIndex[1] = 0;
        USETW(req.wLength, sizeof *ps);
-       return (usbd_do_request(udev, mtx, &req, ps));
+       return (usbd_do_request(udev, lock, &req, ps));
 }
 
 /*------------------------------------------------------------------------*
@@ -1601,7 +1606,7 @@ usbd_req_get_port_status(struct usb_device *udev, struct mtx *mtx,
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_clear_hub_feature(struct usb_device *udev, struct mtx *mtx,
+usbd_req_clear_hub_feature(struct usb_device *udev, struct lock *lock,
     uint16_t sel)
 {
        struct usb_device_request req;
@@ -1611,7 +1616,7 @@ usbd_req_clear_hub_feature(struct usb_device *udev, struct mtx *mtx,
        USETW(req.wValue, sel);
        USETW(req.wIndex, 0);
        USETW(req.wLength, 0);
-       return (usbd_do_request(udev, mtx, &req, 0));
+       return (usbd_do_request(udev, lock, &req, 0));
 }
 
 /*------------------------------------------------------------------------*
@@ -1622,7 +1627,7 @@ usbd_req_clear_hub_feature(struct usb_device *udev, struct mtx *mtx,
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_set_hub_feature(struct usb_device *udev, struct mtx *mtx,
+usbd_req_set_hub_feature(struct usb_device *udev, struct lock *lock,
     uint16_t sel)
 {
        struct usb_device_request req;
@@ -1632,7 +1637,7 @@ usbd_req_set_hub_feature(struct usb_device *udev, struct mtx *mtx,
        USETW(req.wValue, sel);
        USETW(req.wIndex, 0);
        USETW(req.wLength, 0);
-       return (usbd_do_request(udev, mtx, &req, 0));
+       return (usbd_do_request(udev, lock, &req, 0));
 }
 
 /*------------------------------------------------------------------------*
@@ -1643,7 +1648,7 @@ usbd_req_set_hub_feature(struct usb_device *udev, struct mtx *mtx,
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_set_hub_u1_timeout(struct usb_device *udev, struct mtx *mtx,
+usbd_req_set_hub_u1_timeout(struct usb_device *udev, struct lock *lock,
     uint8_t port, uint8_t timeout)
 {
        struct usb_device_request req;
@@ -1654,7 +1659,7 @@ usbd_req_set_hub_u1_timeout(struct usb_device *udev, struct mtx *mtx,
        req.wIndex[0] = port;
        req.wIndex[1] = timeout;
        USETW(req.wLength, 0);
-       return (usbd_do_request(udev, mtx, &req, 0));
+       return (usbd_do_request(udev, lock, &req, 0));
 }
 
 /*------------------------------------------------------------------------*
@@ -1665,7 +1670,7 @@ usbd_req_set_hub_u1_timeout(struct usb_device *udev, struct mtx *mtx,
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_set_hub_u2_timeout(struct usb_device *udev, struct mtx *mtx,
+usbd_req_set_hub_u2_timeout(struct usb_device *udev, struct lock *lock,
     uint8_t port, uint8_t timeout)
 {
        struct usb_device_request req;
@@ -1676,7 +1681,7 @@ usbd_req_set_hub_u2_timeout(struct usb_device *udev, struct mtx *mtx,
        req.wIndex[0] = port;
        req.wIndex[1] = timeout;
        USETW(req.wLength, 0);
-       return (usbd_do_request(udev, mtx, &req, 0));
+       return (usbd_do_request(udev, lock, &req, 0));
 }
 
 /*------------------------------------------------------------------------*
@@ -1687,7 +1692,7 @@ usbd_req_set_hub_u2_timeout(struct usb_device *udev, struct mtx *mtx,
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_set_hub_depth(struct usb_device *udev, struct mtx *mtx,
+usbd_req_set_hub_depth(struct usb_device *udev, struct lock *lock,
     uint16_t depth)
 {
        struct usb_device_request req;
@@ -1697,7 +1702,7 @@ usbd_req_set_hub_depth(struct usb_device *udev, struct mtx *mtx,
        USETW(req.wValue, depth);
        USETW(req.wIndex, 0);
        USETW(req.wLength, 0);
-       return (usbd_do_request(udev, mtx, &req, 0));
+       return (usbd_do_request(udev, lock, &req, 0));
 }
 
 /*------------------------------------------------------------------------*
@@ -1708,7 +1713,7 @@ usbd_req_set_hub_depth(struct usb_device *udev, struct mtx *mtx,
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_clear_port_feature(struct usb_device *udev, struct mtx *mtx,
+usbd_req_clear_port_feature(struct usb_device *udev, struct lock *lock,
     uint8_t port, uint16_t sel)
 {
        struct usb_device_request req;
@@ -1719,7 +1724,7 @@ usbd_req_clear_port_feature(struct usb_device *udev, struct mtx *mtx,
        req.wIndex[0] = port;
        req.wIndex[1] = 0;
        USETW(req.wLength, 0);
-       return (usbd_do_request(udev, mtx, &req, 0));
+       return (usbd_do_request(udev, lock, &req, 0));
 }
 
 /*------------------------------------------------------------------------*
@@ -1730,7 +1735,7 @@ usbd_req_clear_port_feature(struct usb_device *udev, struct mtx *mtx,
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_set_port_feature(struct usb_device *udev, struct mtx *mtx,
+usbd_req_set_port_feature(struct usb_device *udev, struct lock *lock,
     uint8_t port, uint16_t sel)
 {
        struct usb_device_request req;
@@ -1741,7 +1746,7 @@ usbd_req_set_port_feature(struct usb_device *udev, struct mtx *mtx,
        req.wIndex[0] = port;
        req.wIndex[1] = 0;
        USETW(req.wLength, 0);
-       return (usbd_do_request(udev, mtx, &req, 0));
+       return (usbd_do_request(udev, lock, &req, 0));
 }
 
 /*------------------------------------------------------------------------*
@@ -1752,7 +1757,7 @@ usbd_req_set_port_feature(struct usb_device *udev, struct mtx *mtx,
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_set_protocol(struct usb_device *udev, struct mtx *mtx,
+usbd_req_set_protocol(struct usb_device *udev, struct lock *lock,
     uint8_t iface_index, uint16_t report)
 {
        struct usb_interface *iface = usbd_get_iface(udev, iface_index);
@@ -1770,7 +1775,7 @@ usbd_req_set_protocol(struct usb_device *udev, struct mtx *mtx,
        req.wIndex[0] = iface->idesc->bInterfaceNumber;
        req.wIndex[1] = 0;
        USETW(req.wLength, 0);
-       return (usbd_do_request(udev, mtx, &req, 0));
+       return (usbd_do_request(udev, lock, &req, 0));
 }
 
 /*------------------------------------------------------------------------*
@@ -1781,7 +1786,7 @@ usbd_req_set_protocol(struct usb_device *udev, struct mtx *mtx,
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_set_report(struct usb_device *udev, struct mtx *mtx, void *data, uint16_t len,
+usbd_req_set_report(struct usb_device *udev, struct lock *lock, void *data, uint16_t len,
     uint8_t iface_index, uint8_t type, uint8_t id)
 {
        struct usb_interface *iface = usbd_get_iface(udev, iface_index);
@@ -1798,7 +1803,7 @@ usbd_req_set_report(struct usb_device *udev, struct mtx *mtx, void *data, uint16
        req.wIndex[0] = iface->idesc->bInterfaceNumber;
        req.wIndex[1] = 0;
        USETW(req.wLength, len);
-       return (usbd_do_request(udev, mtx, &req, data));
+       return (usbd_do_request(udev, lock, &req, data));
 }
 
 /*------------------------------------------------------------------------*
@@ -1809,7 +1814,7 @@ usbd_req_set_report(struct usb_device *udev, struct mtx *mtx, void *data, uint16
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_get_report(struct usb_device *udev, struct mtx *mtx, void *data,
+usbd_req_get_report(struct usb_device *udev, struct lock *lock, void *data,
     uint16_t len, uint8_t iface_index, uint8_t type, uint8_t id)
 {
        struct usb_interface *iface = usbd_get_iface(udev, iface_index);
@@ -1826,7 +1831,7 @@ usbd_req_get_report(struct usb_device *udev, struct mtx *mtx, void *data,
        req.wIndex[0] = iface->idesc->bInterfaceNumber;
        req.wIndex[1] = 0;
        USETW(req.wLength, len);
-       return (usbd_do_request(udev, mtx, &req, data));
+       return (usbd_do_request(udev, lock, &req, data));
 }
 
 /*------------------------------------------------------------------------*
@@ -1837,7 +1842,7 @@ usbd_req_get_report(struct usb_device *udev, struct mtx *mtx, void *data,
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_set_idle(struct usb_device *udev, struct mtx *mtx,
+usbd_req_set_idle(struct usb_device *udev, struct lock *lock,
     uint8_t iface_index, uint8_t duration, uint8_t id)
 {
        struct usb_interface *iface = usbd_get_iface(udev, iface_index);
@@ -1854,7 +1859,7 @@ usbd_req_set_idle(struct usb_device *udev, struct mtx *mtx,
        req.wIndex[0] = iface->idesc->bInterfaceNumber;
        req.wIndex[1] = 0;
        USETW(req.wLength, 0);
-       return (usbd_do_request(udev, mtx, &req, 0));
+       return (usbd_do_request(udev, lock, &req, 0));
 }
 
 /*------------------------------------------------------------------------*
@@ -1865,7 +1870,7 @@ usbd_req_set_idle(struct usb_device *udev, struct mtx *mtx,
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_get_report_descriptor(struct usb_device *udev, struct mtx *mtx,
+usbd_req_get_report_descriptor(struct usb_device *udev, struct lock *lock,
     void *d, uint16_t size, uint8_t iface_index)
 {
        struct usb_interface *iface = usbd_get_iface(udev, iface_index);
@@ -1880,7 +1885,7 @@ usbd_req_get_report_descriptor(struct usb_device *udev, struct mtx *mtx,
        req.wIndex[0] = iface->idesc->bInterfaceNumber;
        req.wIndex[1] = 0;
        USETW(req.wLength, size);
-       return (usbd_do_request(udev, mtx, &req, d));
+       return (usbd_do_request(udev, lock, &req, d));
 }
 
 /*------------------------------------------------------------------------*
@@ -1895,7 +1900,7 @@ usbd_req_get_report_descriptor(struct usb_device *udev, struct mtx *mtx,
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_set_config(struct usb_device *udev, struct mtx *mtx, uint8_t conf)
+usbd_req_set_config(struct usb_device *udev, struct lock *lock, uint8_t conf)
 {
        struct usb_device_request req;
 
@@ -1909,7 +1914,7 @@ usbd_req_set_config(struct usb_device *udev, struct mtx *mtx, uint8_t conf)
        req.wValue[1] = 0;
        USETW(req.wIndex, 0);
        USETW(req.wLength, 0);
-       return (usbd_do_request(udev, mtx, &req, 0));
+       return (usbd_do_request(udev, lock, &req, 0));
 }
 
 /*------------------------------------------------------------------------*
@@ -1920,7 +1925,7 @@ usbd_req_set_config(struct usb_device *udev, struct mtx *mtx, uint8_t conf)
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_get_config(struct usb_device *udev, struct mtx *mtx, uint8_t *pconf)
+usbd_req_get_config(struct usb_device *udev, struct lock *lock, uint8_t *pconf)
 {
        struct usb_device_request req;
 
@@ -1929,14 +1934,14 @@ usbd_req_get_config(struct usb_device *udev, struct mtx *mtx, uint8_t *pconf)
        USETW(req.wValue, 0);
        USETW(req.wIndex, 0);
        USETW(req.wLength, 1);
-       return (usbd_do_request(udev, mtx, &req, pconf));
+       return (usbd_do_request(udev, lock, &req, pconf));
 }
 
 /*------------------------------------------------------------------------*
  *     usbd_setup_device_desc
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_setup_device_desc(struct usb_device *udev, struct mtx *mtx)
+usbd_setup_device_desc(struct usb_device *udev, struct lock *lock)
 {
        usb_error_t err;
 
@@ -1953,7 +1958,7 @@ usbd_setup_device_desc(struct usb_device *udev, struct mtx *mtx)
        switch (udev->speed) {
        case USB_SPEED_FULL:
        case USB_SPEED_LOW:
-               err = usbd_req_get_desc(udev, mtx, NULL, &udev->ddesc,
+               err = usbd_req_get_desc(udev, lock, NULL, &udev->ddesc,
                    USB_MAX_IPACKET, USB_MAX_IPACKET, 0, UDESC_DEVICE, 0, 0);
                if (err != 0) {
                        DPRINTFN(0, "getting device descriptor "
@@ -1969,11 +1974,11 @@ usbd_setup_device_desc(struct usb_device *udev, struct mtx *mtx)
        }
 
        /* get the full device descriptor */
-       err = usbd_req_get_device_desc(udev, mtx, &udev->ddesc);
+       err = usbd_req_get_device_desc(udev, lock, &udev->ddesc);
 
        /* try one more time, if error */
        if (err)
-               err = usbd_req_get_device_desc(udev, mtx, &udev->ddesc);
+               err = usbd_req_get_device_desc(udev, lock, &udev->ddesc);
 
        if (err) {
                DPRINTF("addr=%d, getting full desc failed\n",
@@ -2006,7 +2011,7 @@ usbd_setup_device_desc(struct usb_device *udev, struct mtx *mtx)
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_re_enumerate(struct usb_device *udev, struct mtx *mtx)
+usbd_req_re_enumerate(struct usb_device *udev, struct lock *lock)
 {
        struct usb_device *parent_hub;
        usb_error_t err;
@@ -2040,10 +2045,10 @@ retry:
 
        /* Try to warm reset first */
        if (parent_hub->speed == USB_SPEED_SUPER)
-               usbd_req_warm_reset_port(parent_hub, mtx, udev->port_no);
+               usbd_req_warm_reset_port(parent_hub, lock, udev->port_no);
 
        /* Try to reset the parent HUB port. */
-       err = usbd_req_reset_port(parent_hub, mtx, udev->port_no);
+       err = usbd_req_reset_port(parent_hub, lock, udev->port_no);
        if (err) {
                DPRINTFN(0, "addr=%d, port reset failed, %s\n", 
                    old_addr, usbd_errstr(err));
@@ -2065,7 +2070,7 @@ retry:
        /*
         * Restore device address:
         */
-       err = usbd_req_set_address(udev, mtx, old_addr);
+       err = usbd_req_set_address(udev, lock, old_addr);
        if (err) {
                /* XXX ignore any errors! */
                DPRINTFN(0, "addr=%d, set address failed! (%s, ignored)\n",
@@ -2079,12 +2084,12 @@ retry:
                udev->address = old_addr;
 
        /* setup the device descriptor and the initial "wMaxPacketSize" */
-       err = usbd_setup_device_desc(udev, mtx);
+       err = usbd_setup_device_desc(udev, lock);
 
 done:
        if (err && do_retry) {
                /* give the USB firmware some time to load */
-               usb_pause_mtx(mtx, hz / 2);
+               usb_pause_mtx(lock, hz / 2);
                /* no more retries after this retry */
                do_retry = 0;
                /* try again */
@@ -2107,7 +2112,7 @@ done:
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_clear_device_feature(struct usb_device *udev, struct mtx *mtx,
+usbd_req_clear_device_feature(struct usb_device *udev, struct lock *lock,
     uint16_t sel)
 {
        struct usb_device_request req;
@@ -2117,7 +2122,7 @@ usbd_req_clear_device_feature(struct usb_device *udev, struct mtx *mtx,
        USETW(req.wValue, sel);
        USETW(req.wIndex, 0);
        USETW(req.wLength, 0);
-       return (usbd_do_request(udev, mtx, &req, 0));
+       return (usbd_do_request(udev, lock, &req, 0));
 }
 
 /*------------------------------------------------------------------------*
@@ -2128,7 +2133,7 @@ usbd_req_clear_device_feature(struct usb_device *udev, struct mtx *mtx,
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_set_device_feature(struct usb_device *udev, struct mtx *mtx,
+usbd_req_set_device_feature(struct usb_device *udev, struct lock *lock,
     uint16_t sel)
 {
        struct usb_device_request req;
@@ -2138,7 +2143,7 @@ usbd_req_set_device_feature(struct usb_device *udev, struct mtx *mtx,
        USETW(req.wValue, sel);
        USETW(req.wIndex, 0);
        USETW(req.wLength, 0);
-       return (usbd_do_request(udev, mtx, &req, 0));
+       return (usbd_do_request(udev, lock, &req, 0));
 }
 
 /*------------------------------------------------------------------------*
@@ -2149,7 +2154,7 @@ usbd_req_set_device_feature(struct usb_device *udev, struct mtx *mtx,
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_reset_tt(struct usb_device *udev, struct mtx *mtx,
+usbd_req_reset_tt(struct usb_device *udev, struct lock *lock,
     uint8_t port)
 {
        struct usb_device_request req;
@@ -2166,7 +2171,7 @@ usbd_req_reset_tt(struct usb_device *udev, struct mtx *mtx,
        req.wIndex[0] = port;
        req.wIndex[1] = 0;
        USETW(req.wLength, 0);
-       return (usbd_do_request(udev, mtx, &req, 0));
+       return (usbd_do_request(udev, lock, &req, 0));
 }
 
 /*------------------------------------------------------------------------*
@@ -2179,7 +2184,7 @@ usbd_req_reset_tt(struct usb_device *udev, struct mtx *mtx,
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_clear_tt_buffer(struct usb_device *udev, struct mtx *mtx,
+usbd_req_clear_tt_buffer(struct usb_device *udev, struct lock *lock,
     uint8_t port, uint8_t addr, uint8_t type, uint8_t endpoint)
 {
        struct usb_device_request req;
@@ -2200,7 +2205,7 @@ usbd_req_clear_tt_buffer(struct usb_device *udev, struct mtx *mtx,
        req.wIndex[0] = port;
        req.wIndex[1] = 0;
        USETW(req.wLength, 0);
-       return (usbd_do_request(udev, mtx, &req, 0));
+       return (usbd_do_request(udev, lock, &req, 0));
 }
 
 /*------------------------------------------------------------------------*
@@ -2213,7 +2218,7 @@ usbd_req_clear_tt_buffer(struct usb_device *udev, struct mtx *mtx,
  * Else: Failure
  *------------------------------------------------------------------------*/
 usb_error_t
-usbd_req_set_port_link_state(struct usb_device *udev, struct mtx *mtx,
+usbd_req_set_port_link_state(struct usb_device *udev, struct lock *lock,
     uint8_t port, uint8_t link_state)
 {
        struct usb_device_request req;
@@ -2224,5 +2229,5 @@ usbd_req_set_port_link_state(struct usb_device *udev, struct mtx *mtx,
        req.wIndex[0] = port;
        req.wIndex[1] = link_state;
        USETW(req.wLength, 0);
-       return (usbd_do_request(udev, mtx, &req, 0));
+       return (usbd_do_request(udev, lock, &req, 0));
 }
index 74823af..8242386 100644 (file)
 struct usb_process;
 
 usb_error_t usbd_req_clear_hub_feature(struct usb_device *udev,
-                   struct mtx *mtx, uint16_t sel);
+                   struct lock *lock, uint16_t sel);
 usb_error_t usbd_req_clear_port_feature(struct usb_device *udev,
-                   struct mtx *mtx, uint8_t port, uint16_t sel);
+                   struct lock *lock, uint8_t port, uint16_t sel);
 usb_error_t usbd_req_get_alt_interface_no(struct usb_device *udev,
-                   struct mtx *mtx, uint8_t *alt_iface_no,
+                   struct lock *lock, uint8_t *alt_iface_no,
                    uint8_t iface_index);
-usb_error_t usbd_req_get_config(struct usb_device *udev, struct mtx *mtx,
+usb_error_t usbd_req_get_config(struct usb_device *udev, struct lock *lock,
                    uint8_t *pconf);
 usb_error_t usbd_req_get_descriptor_ptr(struct usb_device *udev,
                    struct usb_config_descriptor **ppcd, uint16_t wValue);
-usb_error_t usbd_req_get_config_desc(struct usb_device *udev, struct mtx *mtx,
+usb_error_t usbd_req_get_config_desc(struct usb_device *udev, struct lock *lock,
                    struct usb_config_descriptor *d, uint8_t conf_index);
 usb_error_t usbd_req_get_config_desc_full(struct usb_device *udev,
-                   struct mtx *mtx, struct usb_config_descriptor **ppcd,
+                   struct lock *lock, struct usb_config_descriptor **ppcd,
                    struct malloc_type *mtype, uint8_t conf_index);
-usb_error_t usbd_req_get_desc(struct usb_device *udev, struct mtx *mtx,
+usb_error_t usbd_req_get_desc(struct usb_device *udev, struct lock *lock,
                    uint16_t *actlen, void *desc, uint16_t min_len,
                    uint16_t max_len, uint16_t id, uint8_t type,
                    uint8_t index, uint8_t retries);
-usb_error_t usbd_req_get_device_desc(struct usb_device *udev, struct mtx *mtx,
+usb_error_t usbd_req_get_device_desc(struct usb_device *udev, struct lock *lock,
                    struct usb_device_descriptor *d);
 usb_error_t usbd_req_get_device_status(struct usb_device *udev,
-                   struct mtx *mtx, struct usb_status *st);
+                   struct lock *lock, struct usb_status *st);
 usb_error_t usbd_req_get_hub_descriptor(struct usb_device *udev,
-                   struct mtx *mtx, struct usb_hub_descriptor *hd,
+                   struct lock *lock, struct usb_hub_descriptor *hd,
                    uint8_t nports);
 usb_error_t usbd_req_get_ss_hub_descriptor(struct usb_device *udev,
-                   struct mtx *mtx, struct usb_hub_ss_descriptor *hd,
+                   struct lock *lock, struct usb_hub_ss_descriptor *hd,
                    uint8_t nports);
-usb_error_t usbd_req_get_hub_status(struct usb_device *udev, struct mtx *mtx,
+usb_error_t usbd_req_get_hub_status(struct usb_device *udev, struct lock *lock,
                    struct usb_hub_status *st);
-usb_error_t usbd_req_get_port_status(struct usb_device *udev, struct mtx *mtx,
+usb_error_t usbd_req_get_port_status(struct usb_device *udev, struct lock *lock,
                    struct usb_port_status *ps, uint8_t port);
-usb_error_t usbd_req_reset_port(struct usb_device *udev, struct mtx *mtx,
+usb_error_t usbd_req_reset_port(struct usb_device *udev, struct lock *lock,
                    uint8_t port);
 usb_error_t usbd_req_warm_reset_port(struct usb_device *udev,
-                   struct mtx *mtx, uint8_t port);
-usb_error_t usbd_req_set_address(struct usb_device *udev, struct mtx *mtx,
+                   struct lock *lock, uint8_t port);
+usb_error_t usbd_req_set_address(struct usb_device *udev, struct lock *lock,
                    uint16_t addr);
-usb_error_t usbd_req_set_hub_feature(struct usb_device *udev, struct mtx *mtx,
+usb_error_t usbd_req_set_hub_feature(struct usb_device *udev, struct lock *lock,
                    uint16_t sel);
 usb_error_t usbd_req_set_port_feature(struct usb_device *udev,
-                   struct mtx *mtx, uint8_t port, uint16_t sel);
-usb_error_t usbd_setup_device_desc(struct usb_device *udev, struct mtx *mtx);
-usb_error_t usbd_req_re_enumerate(struct usb_device *udev, struct mtx *mtx);
+                   struct lock *lock, uint8_t port, uint16_t sel);
+usb_error_t usbd_setup_device_desc(struct usb_device *udev, struct lock *lock);
+usb_error_t usbd_req_re_enumerate(struct usb_device *udev, struct lock *lock);
 usb_error_t usbd_req_clear_device_feature(struct usb_device *udev,
-                   struct mtx *mtx, uint16_t sel);
+                   struct lock *lock, uint16_t sel);
 usb_error_t usbd_req_set_device_feature(struct usb_device *udev,
-                   struct mtx *mtx, uint16_t sel);
+                   struct lock *lock, uint16_t sel);
 usb_error_t usbd_req_set_hub_u1_timeout(struct usb_device *udev,
-                   struct mtx *mtx, uint8_t port, uint8_t timeout);
+                   struct lock *lock, uint8_t port, uint8_t timeout);
 usb_error_t usbd_req_set_hub_u2_timeout(struct usb_device *udev,
-                   struct mtx *mtx, uint8_t port, uint8_t timeout);
+                   struct lock *lock, uint8_t port, uint8_t timeout);
 usb_error_t usbd_req_set_hub_depth(struct usb_device *udev,
-                   struct mtx *mtx, uint16_t depth);
-usb_error_t usbd_req_reset_tt(struct usb_device *udev, struct mtx *mtx,
+                   struct lock *lock, uint16_t depth);
+usb_error_t usbd_req_reset_tt(struct usb_device *udev, struct lock *lock,
                    uint8_t port);
-usb_error_t usbd_req_clear_tt_buffer(struct usb_device *udev, struct mtx *mtx,
+usb_error_t usbd_req_clear_tt_buffer(struct usb_device *udev, struct lock *lock,
                    uint8_t port, uint8_t addr, uint8_t type, uint8_t endpoint);
 usb_error_t usbd_req_set_port_link_state(struct usb_device *udev,
-                   struct mtx *mtx, uint8_t port, uint8_t link_state);
+                   struct lock *lock, uint8_t port, uint8_t link_state);
 
 #endif                                 /* _USB_REQUEST_H_ */
index e948299..9b88e38 100644 (file)
@@ -25,7 +25,6 @@
  */ 
 
 #include <sys/stdint.h>
-#include <sys/stddef.h>
 #include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/types.h>
 #include <sys/mutex.h>
 #include <sys/condvar.h>
 #include <sys/sysctl.h>
-#include <sys/sx.h>
 #include <sys/unistd.h>
 #include <sys/callout.h>
 #include <sys/malloc.h>
 #include <sys/priv.h>
 #include <sys/proc.h>
 
-#include <dev/usb/usb.h>
-#include <dev/usb/usbdi.h>
-#include <dev/usb/usbdi_util.h>
+#include <bus/u4b/usb.h>
+#include <bus/u4b/usbdi.h>
+#include <bus/u4b/usbdi_util.h>
 
 #define        USB_DEBUG_VAR usb_debug
 
-#include <dev/usb/usb_core.h>
-#include <dev/usb/usb_busdma.h>
-#include <dev/usb/usb_process.h>
-#include <dev/usb/usb_transfer.h>
-#include <dev/usb/usb_device.h>
-#include <dev/usb/usb_debug.h>
-#include <dev/usb/usb_util.h>
+#include <bus/u4b/usb_core.h>
+#include <bus/u4b/usb_busdma.h>
+#include <bus/u4b/usb_process.h>
+#include <bus/u4b/usb_transfer.h>
+#include <bus/u4b/usb_device.h>
+#include <bus/u4b/usb_debug.h>
+#include <bus/u4b/usb_util.h>
 
-#include <dev/usb/usb_controller.h>
-#include <dev/usb/usb_bus.h>
-#include <dev/usb/usb_pf.h>
+#include <bus/u4b/usb_controller.h>
+#include <bus/u4b/usb_bus.h>
+#include <bus/u4b/usb_pf.h>
 
 struct usb_std_packet_size {
        struct {
@@ -200,11 +198,12 @@ usbd_transfer_setup_sub_malloc(struct usb_setup_params *parm,
        usb_size_t y;
        usb_size_t r;
        usb_size_t z;
-
+    
+    /*
        USB_ASSERT(align > 1, ("Invalid alignment, 0x%08x\n",
            align));
        USB_ASSERT(size > 0, ("Invalid size = 0\n"));
-
+    */
        if (count == 0) {
                return (0);             /* nothing to allocate */
        }
@@ -283,12 +282,12 @@ usbd_transfer_setup_sub_malloc(struct usb_setup_params *parm,
                        pc->buffer = USB_ADD_BYTES(buf, y * size);
                        pc->page_start = pg;
 
-                       mtx_lock(pc->tag_parent->mtx);
+            lockmgr(pc->tag_parent->lock, LK_EXCLUSIVE);
                        if (usb_pc_load_mem(pc, size, 1 /* synchronous */ )) {
-                               mtx_unlock(pc->tag_parent->mtx);
+                lockmgr(pc->tag_parent->lock, LK_RELEASE);
                                return (1);     /* failure */
                        }
-                       mtx_unlock(pc->tag_parent->mtx);
+            lockmgr(pc->tag_parent->lock, LK_RELEASE);
                }
        }
 
@@ -808,7 +807,7 @@ usb_error_t
 usbd_transfer_setup(struct usb_device *udev,
     const uint8_t *ifaces, struct usb_xfer **ppxfer,
     const struct usb_config *setup_start, uint16_t n_setup,
-    void *priv_sc, struct mtx *xfer_mtx)
+    void *priv_sc, struct lock *xfer_lock)
 {
        struct usb_xfer dummy;
        struct usb_setup_params parm;
@@ -825,9 +824,10 @@ usbd_transfer_setup(struct usb_device *udev,
        refcount = 0;
        info = NULL;
 
+    /*   
        WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
            "usbd_transfer_setup can sleep!");
-
+    */
        /* do some checking first */
 
        if (n_setup == 0) {
@@ -838,9 +838,8 @@ usbd_transfer_setup(struct usb_device *udev,
                DPRINTFN(6, "ifaces array is NULL!\n");
                return (USB_ERR_INVAL);
        }
-       if (xfer_mtx == NULL) {
+       if (xfer_lock == NULL) {
                DPRINTFN(6, "using global lock\n");
-               xfer_mtx = &Giant;
        }
        /* sanity checks */
        for (setup = setup_start, n = 0;
@@ -892,11 +891,11 @@ usbd_transfer_setup(struct usb_device *udev,
 
                        cv_init(&info->cv_drain, "WDRAIN");
 
-                       info->xfer_mtx = xfer_mtx;
+                       info->xfer_lock = xfer_lock;
 #if USB_HAVE_BUSDMA
                        usb_dma_tag_setup(&info->dma_parent_tag,
                            parm.dma_tag_p, udev->bus->dma_parent_tag[0].tag,
-                           xfer_mtx, &usb_bdma_done_event, 32, parm.dma_tag_max);
+                           xfer_lock, &usb_bdma_done_event, 32, parm.dma_tag_max);
 #endif
 
                        info->bus = udev->bus;
@@ -922,9 +921,6 @@ usbd_transfer_setup(struct usb_device *udev,
                        if (setup_start == usb_control_ep_cfg)
                                info->done_p = 
                                    &udev->bus->control_xfer_proc;
-                       else if (xfer_mtx == &Giant)
-                               info->done_p = 
-                                   &udev->bus->giant_callback_proc;
                        else
                                info->done_p = 
                                    &udev->bus->non_giant_callback_proc;
@@ -973,7 +969,7 @@ usbd_transfer_setup(struct usb_device *udev,
                                xfer->xroot = info;
 
                                usb_callout_init_mtx(&xfer->timeout_handle,
-                                   &udev->bus->bus_mtx, 0);
+                                   &udev->bus->bus_lock, 0);
                        } else {
                                /*
                                 * Setup a dummy xfer, hence we are
@@ -1114,7 +1110,7 @@ usbd_transfer_setup(struct usb_device *udev,
                parm.size[0] += ((-parm.size[0]) & (USB_HOST_ALIGN - 1));
 
                /* allocate zeroed memory */
-               buf = malloc(parm.size[0], M_USB, M_WAITOK | M_ZERO);
+               buf = kmalloc(parm.size[0], M_USB, M_WAITOK | M_ZERO);
 
                if (buf == NULL) {
                        parm.err = USB_ERR_NOMEM;
@@ -1159,7 +1155,7 @@ usbd_transfer_unsetup_sub(struct usb_xfer_root *info, uint8_t needs_delay)
        struct usb_page_cache *pc;
 #endif
 
-       USB_BUS_LOCK_ASSERT(info->bus, MA_OWNED);
+       USB_BUS_LOCK_ASSERT(info->bus);
 
        /* wait for any outstanding DMA operations */
 
@@ -1167,7 +1163,7 @@ usbd_transfer_unsetup_sub(struct usb_xfer_root *info, uint8_t needs_delay)
                usb_timeout_t temp;
                temp = usbd_get_dma_delay(info->udev);
                if (temp != 0) {
-                       usb_pause_mtx(&info->bus->bus_mtx,
+                       usb_pause_mtx(&info->bus->bus_lock,
                            USB_MS_TO_TICKS(temp));
                }
        }
@@ -1202,7 +1198,7 @@ usbd_transfer_unsetup_sub(struct usb_xfer_root *info, uint8_t needs_delay)
         * free the "memory_base" last, hence the "info" structure is
         * contained within the "memory_base"!
         */
-       free(info->memory_base, M_USB);