summaryrefslogtreecommitdiffstats
path: root/sys/dev
diff options
context:
space:
mode:
authorthompsa <thompsa@FreeBSD.org>2008-11-10 20:54:31 +0000
committerthompsa <thompsa@FreeBSD.org>2008-11-10 20:54:31 +0000
commit33e3cbce8e605e9e2818d8d34f721a3bca2b65ff (patch)
tree2a38bb4601a2892888db6d9b14e006bae8a41889 /sys/dev
parent79b0ca8da7a3f9f7743f354dfd1368f99e5c49e8 (diff)
downloadFreeBSD-src-33e3cbce8e605e9e2818d8d34f721a3bca2b65ff.zip
FreeBSD-src-33e3cbce8e605e9e2818d8d34f721a3bca2b65ff.tar.gz
Convert the two main locking areas into macros to make it clear on what we are
grabbing and why. These are now: USB_BUS_LOCK/USB_BUS_UNLOCK USB_XFER_LOCK/USB_XFER_UNLOCK Reviewed by: alfred
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/usb2/controller/at91dci.c42
-rw-r--r--sys/dev/usb2/controller/at91dci_atmelarm.c2
-rw-r--r--sys/dev/usb2/controller/ehci2.c68
-rw-r--r--sys/dev/usb2/controller/ehci2_pci.c2
-rw-r--r--sys/dev/usb2/controller/musb2_otg.c42
-rw-r--r--sys/dev/usb2/controller/musb2_otg_atmelarm.c2
-rw-r--r--sys/dev/usb2/controller/ohci2.c70
-rw-r--r--sys/dev/usb2/controller/ohci2_atmelarm.c2
-rw-r--r--sys/dev/usb2/controller/ohci2_pci.c2
-rw-r--r--sys/dev/usb2/controller/uhci2.c58
-rw-r--r--sys/dev/usb2/controller/uhci2_pci.c6
-rw-r--r--sys/dev/usb2/controller/usb2_bus.h2
-rw-r--r--sys/dev/usb2/controller/usb2_controller.c20
-rw-r--r--sys/dev/usb2/controller/uss820dci.c40
-rw-r--r--sys/dev/usb2/controller/uss820dci_atmelarm.c2
-rw-r--r--sys/dev/usb2/controller/uss820dci_pccard.c2
-rw-r--r--sys/dev/usb2/core/usb2_busdma.c19
-rw-r--r--sys/dev/usb2/core/usb2_core.h9
-rw-r--r--sys/dev/usb2/core/usb2_device.c20
-rw-r--r--sys/dev/usb2/core/usb2_handle_request.c26
-rw-r--r--sys/dev/usb2/core/usb2_hub.c12
-rw-r--r--sys/dev/usb2/core/usb2_request.c27
-rw-r--r--sys/dev/usb2/core/usb2_sw_transfer.c7
-rw-r--r--sys/dev/usb2/core/usb2_transfer.c197
-rw-r--r--sys/dev/usb2/core/usb2_transfer.h1
-rw-r--r--sys/dev/usb2/serial/uvscom2.c4
-rw-r--r--sys/dev/usb2/storage/ata-usb2.c4
27 files changed, 350 insertions, 338 deletions
diff --git a/sys/dev/usb2/controller/at91dci.c b/sys/dev/usb2/controller/at91dci.c
index d5c7508..17eca9f 100644
--- a/sys/dev/usb2/controller/at91dci.c
+++ b/sys/dev/usb2/controller/at91dci.c
@@ -291,7 +291,7 @@ at91dci_rem_wakeup_set(struct usb2_device *udev, uint8_t is_on)
DPRINTFN(5, "is_on=%u\n", is_on);
- mtx_assert(&udev->bus->mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(udev->bus, MA_OWNED);
sc = AT9100_DCI_BUS2SC(udev->bus);
@@ -766,7 +766,7 @@ at91dci_vbus_interrupt(struct usb2_bus *bus, uint8_t is_on)
DPRINTFN(5, "vbus = %u\n", is_on);
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
if (is_on) {
if (!sc->sc_flags.status_vbus) {
sc->sc_flags.status_vbus = 1;
@@ -791,7 +791,7 @@ at91dci_vbus_interrupt(struct usb2_bus *bus, uint8_t is_on)
}
}
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
return;
}
@@ -801,13 +801,13 @@ at91dci_interrupt(struct at91dci_softc *sc)
{
uint32_t status;
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
status = AT91_UDP_READ_4(sc, AT91_UDP_ISR);
status &= AT91_UDP_INT_DEFAULT;
if (!status) {
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
return;
}
/* acknowledge interrupts */
@@ -879,7 +879,7 @@ at91dci_interrupt(struct at91dci_softc *sc)
at91dci_interrupt_poll(sc);
}
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
return;
}
@@ -1065,12 +1065,12 @@ at91dci_timeout(void *arg)
DPRINTF("xfer=%p\n", xfer);
- mtx_assert(&sc->sc_bus.mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
/* transfer is transferred */
at91dci_device_done(xfer, USB_ERR_TIMEOUT);
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
return;
}
@@ -1115,7 +1115,7 @@ at91dci_root_intr_done(struct usb2_xfer *xfer,
DPRINTFN(9, "\n");
- mtx_assert(&sc->sc_bus.mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
if (std->state != USB_SW_TR_PRE_DATA) {
if (std->state == USB_SW_TR_PRE_CALLBACK) {
@@ -1255,7 +1255,7 @@ at91dci_device_done(struct usb2_xfer *xfer, usb2_error_t error)
struct at91dci_softc *sc = xfer->usb2_sc;
uint8_t ep_no;
- mtx_assert(&sc->sc_bus.mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
DPRINTFN(2, "xfer=%p, pipe=%p, error=%d\n",
xfer, xfer->pipe, error);
@@ -1281,7 +1281,7 @@ at91dci_set_stall(struct usb2_device *udev, struct usb2_xfer *xfer,
uint32_t csr_val;
uint8_t csr_reg;
- mtx_assert(&udev->bus->mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(udev->bus, MA_OWNED);
DPRINTFN(5, "pipe=%p\n", pipe);
@@ -1405,7 +1405,7 @@ at91dci_clear_stall(struct usb2_device *udev, struct usb2_pipe *pipe)
DPRINTFN(5, "pipe=%p\n", pipe);
- mtx_assert(&udev->bus->mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(udev->bus, MA_OWNED);
/* check mode */
if (udev->flags.usb2_mode != USB_MODE_DEVICE) {
@@ -1438,7 +1438,7 @@ at91dci_init(struct at91dci_softc *sc)
sc->sc_bus.usbrev = USB_REV_1_1;
sc->sc_bus.methods = &at91dci_bus_methods;
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
/* turn on clocks */
@@ -1446,7 +1446,7 @@ at91dci_init(struct at91dci_softc *sc)
(sc->sc_clocks_on) (sc->sc_clocks_arg);
}
/* wait a little for things to stabilise */
- usb2_pause_mtx(&sc->sc_bus.mtx, 1);
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx, 1);
/* disable and clear all interrupts */
@@ -1483,7 +1483,7 @@ at91dci_init(struct at91dci_softc *sc)
at91dci_clocks_off(sc);
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
/* catch any lost interrupts */
@@ -1495,7 +1495,7 @@ at91dci_init(struct at91dci_softc *sc)
void
at91dci_uninit(struct at91dci_softc *sc)
{
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
/* disable and clear all interrupts */
AT91_UDP_WRITE_4(sc, AT91_UDP_IDR, 0xFFFFFFFF);
@@ -1510,7 +1510,7 @@ at91dci_uninit(struct at91dci_softc *sc)
at91dci_pull_down(sc);
at91dci_clocks_off(sc);
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
return;
}
@@ -1532,10 +1532,10 @@ at91dci_do_poll(struct usb2_bus *bus)
{
struct at91dci_softc *sc = AT9100_DCI_BUS2SC(bus);
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
at91dci_interrupt_poll(sc);
at91dci_root_ctrl_poll(sc);
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
return;
}
@@ -1897,7 +1897,7 @@ at91dci_root_ctrl_done(struct usb2_xfer *xfer,
uint16_t index;
uint8_t use_polling;
- mtx_assert(&sc->sc_bus.mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
if (std->state != USB_SW_TR_SETUP) {
if (std->state == USB_SW_TR_PRE_CALLBACK) {
@@ -1913,7 +1913,7 @@ at91dci_root_ctrl_done(struct usb2_xfer *xfer,
value = UGETW(std->req.wValue);
index = UGETW(std->req.wIndex);
- use_polling = mtx_owned(xfer->priv_mtx) ? 1 : 0;
+ use_polling = mtx_owned(xfer->xfer_mtx) ? 1 : 0;
/* demultiplex the control request */
diff --git a/sys/dev/usb2/controller/at91dci_atmelarm.c b/sys/dev/usb2/controller/at91dci_atmelarm.c
index 0a6f961..dd01773 100644
--- a/sys/dev/usb2/controller/at91dci_atmelarm.c
+++ b/sys/dev/usb2/controller/at91dci_atmelarm.c
@@ -210,7 +210,7 @@ at91_udp_attach(device_t dev)
device_set_ivars(sc->sc_dci.sc_bus.bdev, &sc->sc_dci.sc_bus);
err = usb2_config_td_setup(&sc->sc_dci.sc_config_td, sc,
- &sc->sc_dci.sc_bus.mtx, NULL, 0, 4);
+ &sc->sc_dci.sc_bus.bus_mtx, NULL, 0, 4);
if (err) {
device_printf(dev, "could not setup config thread!\n");
goto error;
diff --git a/sys/dev/usb2/controller/ehci2.c b/sys/dev/usb2/controller/ehci2.c
index 218a362..5797500 100644
--- a/sys/dev/usb2/controller/ehci2.c
+++ b/sys/dev/usb2/controller/ehci2.c
@@ -164,7 +164,7 @@ ehci_hc_reset(ehci_softc_t *sc)
EOWRITE4(sc, EHCI_USBCMD, 0); /* Halt controller */
for (n = 0; n != 100; n++) {
- usb2_pause_mtx(&sc->sc_bus.mtx, 1);
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx, 1);
hcr = EOREAD4(sc, EHCI_USBSTS);
if (hcr & EHCI_STS_HCH) {
hcr = 0;
@@ -180,7 +180,7 @@ ehci_hc_reset(ehci_softc_t *sc)
EOWRITE4(sc, EHCI_USBCMD, EHCI_CMD_HCRESET);
for (n = 0; n != 100; n++) {
- usb2_pause_mtx(&sc->sc_bus.mtx, 1);
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx, 1);
hcr = EOREAD4(sc, EHCI_USBCMD);
if (!(hcr & EHCI_CMD_HCRESET)) {
hcr = 0;
@@ -208,11 +208,11 @@ ehci_init(ehci_softc_t *sc)
uint16_t bit;
usb2_error_t err = 0;
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
DPRINTF("start\n");
- usb2_callout_init_mtx(&sc->sc_tmo_pcd, &sc->sc_bus.mtx,
+ usb2_callout_init_mtx(&sc->sc_tmo_pcd, &sc->sc_bus.bus_mtx,
CALLOUT_RETURNUNLOCKED);
#if USB_DEBUG
@@ -465,7 +465,7 @@ ehci_init(ehci_softc_t *sc)
EOWRITE4(sc, EHCI_CONFIGFLAG, EHCI_CONF_CF);
for (i = 0; i < 100; i++) {
- usb2_pause_mtx(&sc->sc_bus.mtx, 1);
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx, 1);
hcr = EOREAD4(sc, EHCI_USBSTS) & EHCI_STS_HCH;
if (!hcr) {
break;
@@ -477,7 +477,7 @@ ehci_init(ehci_softc_t *sc)
goto done;
}
done:
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
if (!err) {
/* catch any lost interrupts */
@@ -492,7 +492,7 @@ done:
void
ehci_detach(struct ehci_softc *sc)
{
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
usb2_callout_stop(&sc->sc_tmo_pcd);
@@ -502,9 +502,9 @@ ehci_detach(struct ehci_softc *sc)
DPRINTF("reset failed!\n");
}
/* XXX let stray task complete */
- usb2_pause_mtx(&sc->sc_bus.mtx, 50);
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx, 50);
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
usb2_callout_drain(&sc->sc_tmo_pcd);
@@ -518,7 +518,7 @@ ehci_suspend(struct ehci_softc *sc)
uint32_t hcr;
uint8_t i;
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
for (i = 1; i <= sc->sc_noport; i++) {
cmd = EOREAD4(sc, EHCI_PORTSC(i));
@@ -541,7 +541,7 @@ ehci_suspend(struct ehci_softc *sc)
if (hcr == 0) {
break;
}
- usb2_pause_mtx(&sc->sc_bus.mtx, 1);
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx, 1);
}
if (hcr != 0) {
@@ -555,14 +555,14 @@ ehci_suspend(struct ehci_softc *sc)
if (hcr == EHCI_STS_HCH) {
break;
}
- usb2_pause_mtx(&sc->sc_bus.mtx, 1);
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx, 1);
}
if (hcr != EHCI_STS_HCH) {
device_printf(sc->sc_bus.bdev,
"config timeout\n");
}
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
return;
}
@@ -574,7 +574,7 @@ ehci_resume(struct ehci_softc *sc)
uint32_t hcr;
uint8_t i;
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
/* restore things in case the bios doesn't */
EOWRITE4(sc, EHCI_CTRLDSSEGMENT, 0);
@@ -599,7 +599,7 @@ ehci_resume(struct ehci_softc *sc)
}
if (hcr) {
- usb2_pause_mtx(&sc->sc_bus.mtx,
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx,
USB_RESUME_WAIT);
for (i = 1; i <= sc->sc_noport; i++) {
@@ -618,15 +618,15 @@ ehci_resume(struct ehci_softc *sc)
if (hcr != EHCI_STS_HCH) {
break;
}
- usb2_pause_mtx(&sc->sc_bus.mtx, 1);
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx, 1);
}
if (hcr == EHCI_STS_HCH) {
device_printf(sc->sc_bus.bdev, "config timeout\n");
}
- usb2_pause_mtx(&sc->sc_bus.mtx,
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx,
USB_RESUME_WAIT);
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
/* catch any lost interrupts */
ehci_do_poll(&sc->sc_bus);
@@ -639,12 +639,12 @@ ehci_shutdown(ehci_softc_t *sc)
{
DPRINTF("stopping the HC\n");
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
if (ehci_hc_reset(sc)) {
DPRINTF("reset failed!\n");
}
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
}
#if USB_DEBUG
@@ -1415,7 +1415,7 @@ transferred:
static void
ehci_pcd_enable(ehci_softc_t *sc)
{
- mtx_assert(&sc->sc_bus.mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
sc->sc_eintrs |= EHCI_STS_PCD;
EOWRITE4(sc, EHCI_USBINTR, sc->sc_eintrs);
@@ -1426,7 +1426,7 @@ ehci_pcd_enable(ehci_softc_t *sc)
usb2_sw_transfer(&sc->sc_root_intr,
&ehci_root_intr_done);
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
return;
}
@@ -1460,7 +1460,7 @@ ehci_interrupt(ehci_softc_t *sc)
{
uint32_t status;
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
DPRINTFN(16, "real interrupt\n");
@@ -1517,7 +1517,7 @@ ehci_interrupt(ehci_softc_t *sc)
ehci_interrupt_poll(sc);
done:
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
return;
}
@@ -1532,12 +1532,12 @@ ehci_timeout(void *arg)
DPRINTF("xfer=%p\n", xfer);
- mtx_assert(&sc->sc_bus.mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
/* transfer is transferred */
ehci_device_done(xfer, USB_ERR_TIMEOUT);
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
return;
}
@@ -1547,10 +1547,10 @@ ehci_do_poll(struct usb2_bus *bus)
{
struct ehci_softc *sc = EHCI_BUS2SC(bus);
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
ehci_interrupt_poll(sc);
ehci_root_ctrl_poll(sc);
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
return;
}
@@ -1965,7 +1965,7 @@ ehci_root_intr_done(struct usb2_xfer *xfer,
uint16_t i;
uint16_t m;
- mtx_assert(&sc->sc_bus.mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
if (std->state != USB_SW_TR_PRE_DATA) {
if (std->state == USB_SW_TR_PRE_CALLBACK) {
@@ -2124,7 +2124,7 @@ ehci_device_done(struct usb2_xfer *xfer, usb2_error_t error)
struct usb2_pipe_methods *methods = xfer->pipe->methods;
ehci_softc_t *sc = xfer->usb2_sc;
- mtx_assert(&sc->sc_bus.mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
DPRINTFN(2, "xfer=%p, pipe=%p, error=%d\n",
xfer, xfer->pipe, error);
@@ -3076,7 +3076,7 @@ ehci_root_ctrl_done(struct usb2_xfer *xfer,
uint8_t l;
uint8_t use_polling;
- mtx_assert(&sc->sc_bus.mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
if (std->state != USB_SW_TR_SETUP) {
if (std->state == USB_SW_TR_PRE_CALLBACK) {
@@ -3092,7 +3092,7 @@ ehci_root_ctrl_done(struct usb2_xfer *xfer,
value = UGETW(std->req.wValue);
index = UGETW(std->req.wIndex);
- use_polling = mtx_owned(xfer->priv_mtx) ? 1 : 0;
+ use_polling = mtx_owned(xfer->xfer_mtx) ? 1 : 0;
DPRINTFN(3, "type=0x%02x request=0x%02x wLen=0x%04x "
"wValue=0x%04x wIndex=0x%04x\n",
@@ -3373,7 +3373,7 @@ ehci_root_ctrl_done(struct usb2_xfer *xfer,
DELAY(USB_PORT_ROOT_RESET_DELAY * 1000);
} else {
/* Wait for reset to complete. */
- usb2_pause_mtx(&sc->sc_bus.mtx,
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx,
USB_PORT_ROOT_RESET_DELAY);
}
@@ -3385,7 +3385,7 @@ ehci_root_ctrl_done(struct usb2_xfer *xfer,
DELAY(EHCI_PORT_RESET_COMPLETE * 1000);
} else {
/* Wait for HC to complete reset. */
- usb2_pause_mtx(&sc->sc_bus.mtx,
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx,
EHCI_PORT_RESET_COMPLETE);
}
diff --git a/sys/dev/usb2/controller/ehci2_pci.c b/sys/dev/usb2/controller/ehci2_pci.c
index 1fb7dc2..2d33cb0 100644
--- a/sys/dev/usb2/controller/ehci2_pci.c
+++ b/sys/dev/usb2/controller/ehci2_pci.c
@@ -337,7 +337,7 @@ ehci_pci_attach(device_t self)
sprintf(sc->sc_vendor, "(0x%04x)", pci_get_vendor(self));
}
- err = usb2_config_td_setup(&sc->sc_config_td, sc, &sc->sc_bus.mtx,
+ err = usb2_config_td_setup(&sc->sc_config_td, sc, &sc->sc_bus.bus_mtx,
NULL, 0, 4);
if (err) {
device_printf(self, "could not setup config thread!\n");
diff --git a/sys/dev/usb2/controller/musb2_otg.c b/sys/dev/usb2/controller/musb2_otg.c
index b036d5c..f7832dc 100644
--- a/sys/dev/usb2/controller/musb2_otg.c
+++ b/sys/dev/usb2/controller/musb2_otg.c
@@ -221,7 +221,7 @@ musbotg_wakeup_peer(struct usb2_xfer *xfer)
if (!(sc->sc_flags.status_suspend)) {
return;
}
- use_polling = mtx_owned(xfer->priv_mtx) ? 1 : 0;
+ use_polling = mtx_owned(xfer->xfer_mtx) ? 1 : 0;
temp = MUSB2_READ_1(sc, MUSB2_REG_POWER);
temp |= MUSB2_MASK_RESUME;
@@ -233,7 +233,7 @@ musbotg_wakeup_peer(struct usb2_xfer *xfer)
DELAY(8000);
} else {
/* Wait for reset to complete. */
- usb2_pause_mtx(&sc->sc_bus.mtx, 8);
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx, 8);
}
temp = MUSB2_READ_1(sc, MUSB2_REG_POWER);
@@ -982,7 +982,7 @@ musbotg_vbus_interrupt(struct usb2_bus *bus, uint8_t is_on)
DPRINTFN(4, "vbus = %u\n", is_on);
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
if (is_on) {
if (!sc->sc_flags.status_vbus) {
sc->sc_flags.status_vbus = 1;
@@ -1007,7 +1007,7 @@ musbotg_vbus_interrupt(struct usb2_bus *bus, uint8_t is_on)
}
}
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
return;
}
@@ -1021,7 +1021,7 @@ musbotg_interrupt(struct musbotg_softc *sc)
uint8_t temp;
uint8_t to = 2;
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
repeat:
@@ -1116,7 +1116,7 @@ repeat:
if (--to)
goto repeat;
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
return;
}
@@ -1273,12 +1273,12 @@ musbotg_timeout(void *arg)
DPRINTFN(1, "xfer=%p\n", xfer);
- mtx_assert(&sc->sc_bus.mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
/* transfer is transferred */
musbotg_device_done(xfer, USB_ERR_TIMEOUT);
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
return;
}
@@ -1356,7 +1356,7 @@ musbotg_root_intr_done(struct usb2_xfer *xfer,
DPRINTFN(8, "\n");
- mtx_assert(&sc->sc_bus.mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
if (std->state != USB_SW_TR_PRE_DATA) {
if (std->state == USB_SW_TR_PRE_CALLBACK) {
@@ -1516,7 +1516,7 @@ musbotg_set_stall(struct usb2_device *udev, struct usb2_xfer *xfer,
struct musbotg_softc *sc;
uint8_t ep_no;
- mtx_assert(&udev->bus->mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(udev->bus, MA_OWNED);
DPRINTFN(4, "pipe=%p\n", pipe);
@@ -1702,7 +1702,7 @@ musbotg_clear_stall(struct usb2_device *udev, struct usb2_pipe *pipe)
DPRINTFN(4, "pipe=%p\n", pipe);
- mtx_assert(&udev->bus->mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(udev->bus, MA_OWNED);
/* check mode */
if (udev->flags.usb2_mode != USB_MODE_DEVICE) {
@@ -1741,7 +1741,7 @@ musbotg_init(struct musbotg_softc *sc)
sc->sc_bus.usbrev = USB_REV_2_0;
sc->sc_bus.methods = &musbotg_bus_methods;
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
/* turn on clocks */
@@ -1749,7 +1749,7 @@ musbotg_init(struct musbotg_softc *sc)
(sc->sc_clocks_on) (sc->sc_clocks_arg);
}
/* wait a little for things to stabilise */
- usb2_pause_mtx(&sc->sc_bus.mtx, 1);
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx, 1);
/* disable all interrupts */
@@ -1762,7 +1762,7 @@ musbotg_init(struct musbotg_softc *sc)
musbotg_pull_common(sc, 0);
/* wait a little bit (10ms) */
- usb2_pause_mtx(&sc->sc_bus.mtx, 10);
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx, 10);
/* disable double packet buffering */
MUSB2_WRITE_2(sc, MUSB2_REG_RXDBDIS, 0xFFFF);
@@ -1871,7 +1871,7 @@ musbotg_init(struct musbotg_softc *sc)
musbotg_clocks_off(sc);
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
/* catch any lost interrupts */
@@ -1883,7 +1883,7 @@ musbotg_init(struct musbotg_softc *sc)
void
musbotg_uninit(struct musbotg_softc *sc)
{
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
/* disable all interrupts */
MUSB2_WRITE_1(sc, MUSB2_REG_INTUSBE, 0);
@@ -1899,7 +1899,7 @@ musbotg_uninit(struct musbotg_softc *sc)
musbotg_pull_down(sc);
musbotg_clocks_off(sc);
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
return;
}
@@ -1921,10 +1921,10 @@ musbotg_do_poll(struct usb2_bus *bus)
{
struct musbotg_softc *sc = MUSBOTG_BUS2SC(bus);
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
musbotg_interrupt_poll(sc);
musbotg_root_ctrl_poll(sc);
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
return;
}
@@ -2293,7 +2293,7 @@ musbotg_root_ctrl_done(struct usb2_xfer *xfer,
uint16_t index;
uint8_t use_polling;
- mtx_assert(&sc->sc_bus.mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
if (std->state != USB_SW_TR_SETUP) {
if (std->state == USB_SW_TR_PRE_CALLBACK) {
@@ -2309,7 +2309,7 @@ musbotg_root_ctrl_done(struct usb2_xfer *xfer,
value = UGETW(std->req.wValue);
index = UGETW(std->req.wIndex);
- use_polling = mtx_owned(xfer->priv_mtx) ? 1 : 0;
+ use_polling = mtx_owned(xfer->xfer_mtx) ? 1 : 0;
/* demultiplex the control request */
diff --git a/sys/dev/usb2/controller/musb2_otg_atmelarm.c b/sys/dev/usb2/controller/musb2_otg_atmelarm.c
index 58ee134..49b653ff 100644
--- a/sys/dev/usb2/controller/musb2_otg_atmelarm.c
+++ b/sys/dev/usb2/controller/musb2_otg_atmelarm.c
@@ -138,7 +138,7 @@ musbotg_attach(device_t dev)
device_set_ivars(sc->sc_otg.sc_bus.bdev, &sc->sc_otg.sc_bus);
err = usb2_config_td_setup(&sc->sc_otg.sc_config_td, sc,
- &sc->sc_otg.sc_bus.mtx, NULL, 0, 4);
+ &sc->sc_otg.sc_bus.bus_mtx, NULL, 0, 4);
if (err) {
device_printf(dev, "could not setup config thread!\n");
goto error;
diff --git a/sys/dev/usb2/controller/ohci2.c b/sys/dev/usb2/controller/ohci2.c
index 54133ba..8ed49d3 100644
--- a/sys/dev/usb2/controller/ohci2.c
+++ b/sys/dev/usb2/controller/ohci2.c
@@ -173,7 +173,7 @@ ohci_controller_init(ohci_softc_t *sc)
DPRINTF("SMM active, request owner change\n");
OWRITE4(sc, OHCI_COMMAND_STATUS, OHCI_OCR);
for (i = 0; (i < 100) && (ctl & OHCI_IR); i++) {
- usb2_pause_mtx(&sc->sc_bus.mtx, 1);
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx, 1);
ctl = OREAD4(sc, OHCI_CONTROL);
}
if (ctl & OHCI_IR) {
@@ -186,7 +186,7 @@ ohci_controller_init(ohci_softc_t *sc)
DPRINTF("cold started\n");
reset:
/* controller was cold started */
- usb2_pause_mtx(&sc->sc_bus.mtx,
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx,
USB_BUS_RESET_DELAY);
}
@@ -197,7 +197,7 @@ reset:
DPRINTF("%s: resetting\n", device_get_nameunit(sc->sc_bus.bdev));
OWRITE4(sc, OHCI_CONTROL, OHCI_HCFS_RESET);
- usb2_pause_mtx(&sc->sc_bus.mtx,
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx,
USB_BUS_RESET_DELAY);
/* we now own the host controller and the bus has been reset */
@@ -260,7 +260,7 @@ reset:
desca = OREAD4(sc, OHCI_RH_DESCRIPTOR_A);
OWRITE4(sc, OHCI_RH_DESCRIPTOR_A, desca | OHCI_NOCP);
OWRITE4(sc, OHCI_RH_STATUS, OHCI_LPSC); /* Enable port power */
- usb2_pause_mtx(&sc->sc_bus.mtx,
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx,
OHCI_ENABLE_POWER_DELAY);
OWRITE4(sc, OHCI_RH_DESCRIPTOR_A, desca);
@@ -270,7 +270,7 @@ reset:
*/
sc->sc_noport = 0;
for (i = 0; (i < 10) && (sc->sc_noport == 0); i++) {
- usb2_pause_mtx(&sc->sc_bus.mtx,
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx,
OHCI_READ_DESC_DELAY);
sc->sc_noport = OHCI_GET_NDP(OREAD4(sc, OHCI_RH_DESCRIPTOR_A));
}
@@ -309,7 +309,7 @@ ohci_init(ohci_softc_t *sc)
uint16_t x;
uint16_t y;
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
DPRINTF("start\n");
@@ -391,7 +391,7 @@ ohci_init(ohci_softc_t *sc)
/* set up the bus struct */
sc->sc_bus.methods = &ohci_bus_methods;
- usb2_callout_init_mtx(&sc->sc_tmo_rhsc, &sc->sc_bus.mtx,
+ usb2_callout_init_mtx(&sc->sc_tmo_rhsc, &sc->sc_bus.bus_mtx,
CALLOUT_RETURNUNLOCKED);
#if USB_DEBUG
@@ -408,10 +408,10 @@ ohci_init(ohci_softc_t *sc)
sc->sc_bus.usbrev = USB_REV_1_0;
if (ohci_controller_init(sc)) {
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
return (USB_ERR_INVAL);
} else {
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
/* catch any lost interrupts */
ohci_do_poll(&sc->sc_bus);
return (USB_ERR_NORMAL_COMPLETION);
@@ -424,7 +424,7 @@ ohci_init(ohci_softc_t *sc)
void
ohci_detach(struct ohci_softc *sc)
{
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
usb2_callout_stop(&sc->sc_tmo_rhsc);
@@ -432,9 +432,9 @@ ohci_detach(struct ohci_softc *sc)
OWRITE4(sc, OHCI_CONTROL, OHCI_HCFS_RESET);
/* XXX let stray task complete */
- usb2_pause_mtx(&sc->sc_bus.mtx, 50);
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx, 50);
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
usb2_callout_drain(&sc->sc_tmo_rhsc);
@@ -449,7 +449,7 @@ ohci_suspend(ohci_softc_t *sc)
{
uint32_t ctl;
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
#if USB_DEBUG
DPRINTF("\n");
@@ -470,10 +470,10 @@ ohci_suspend(ohci_softc_t *sc)
ctl |= OHCI_HCFS_SUSPEND;
OWRITE4(sc, OHCI_CONTROL, ctl);
- usb2_pause_mtx(&sc->sc_bus.mtx,
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx,
USB_RESUME_WAIT);
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
return;
}
@@ -482,7 +482,7 @@ ohci_resume(ohci_softc_t *sc)
{
uint32_t ctl;
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
#if USB_DEBUG
DPRINTF("\n");
@@ -503,13 +503,13 @@ ohci_resume(ohci_softc_t *sc)
ctl = OREAD4(sc, OHCI_CONTROL);
ctl |= OHCI_HCFS_RESUME;
OWRITE4(sc, OHCI_CONTROL, ctl);
- usb2_pause_mtx(&sc->sc_bus.mtx, USB_RESUME_DELAY);
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx, USB_RESUME_DELAY);
ctl = (ctl & ~OHCI_HCFS_MASK) | OHCI_HCFS_OPERATIONAL;
OWRITE4(sc, OHCI_CONTROL, ctl);
- usb2_pause_mtx(&sc->sc_bus.mtx, USB_RESUME_RECOVERY);
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx, USB_RESUME_RECOVERY);
sc->sc_control = sc->sc_intre = 0;
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
/* catch any lost interrupts */
ohci_do_poll(&sc->sc_bus);
@@ -699,7 +699,7 @@ _ohci_append_qh(ohci_ed_t *sed, uint32_t td_self, ohci_ed_t *last)
{
DPRINTFN(11, "%p to %p\n", sed, last);
- /* (sc->sc_bus.mtx) must be locked */
+ /* (sc->sc_bus.bus_mtx) must be locked */
sed->next = last->next;
sed->ed_next = last->ed_next;
@@ -728,7 +728,7 @@ _ohci_remove_qh(ohci_ed_t *sed, ohci_ed_t *last)
{
DPRINTFN(11, "%p from %p\n", sed, last);
- /* (sc->sc_bus.mtx) must be locked */
+ /* (sc->sc_bus.bus_mtx) must be locked */
/* only remove if not removed from a queue */
if (sed->prev) {
@@ -1099,7 +1099,7 @@ ohci_rhsc_enable(ohci_softc_t *sc)
{
DPRINTFN(5, "\n");
- mtx_assert(&sc->sc_bus.mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
sc->sc_eintrs |= OHCI_RHSC;
OWRITE4(sc, OHCI_INTERRUPT_ENABLE, OHCI_RHSC);
@@ -1110,7 +1110,7 @@ ohci_rhsc_enable(ohci_softc_t *sc)
usb2_sw_transfer(&sc->sc_root_intr,
&ohci_root_intr_done);
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
return;
}
@@ -1146,7 +1146,7 @@ ohci_interrupt(ohci_softc_t *sc)
uint32_t status;
uint32_t done;
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
hcca = ohci_get_hcca(sc);
@@ -1246,7 +1246,7 @@ ohci_interrupt(ohci_softc_t *sc)
ohci_interrupt_poll(sc);
done:
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
return;
}
@@ -1261,12 +1261,12 @@ ohci_timeout(void *arg)
DPRINTF("xfer=%p\n", xfer);
- mtx_assert(&sc->sc_bus.mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
/* transfer is transferred */
ohci_device_done(xfer, USB_ERR_TIMEOUT);
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
return;
}
@@ -1276,10 +1276,10 @@ ohci_do_poll(struct usb2_bus *bus)
{
struct ohci_softc *sc = OHCI_BUS2SC(bus);
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
ohci_interrupt_poll(sc);
ohci_root_ctrl_poll(sc);
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
return;
}
@@ -1617,7 +1617,7 @@ ohci_root_intr_done(struct usb2_xfer *xfer,
uint16_t i;
uint16_t m;
- mtx_assert(&sc->sc_bus.mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
if (std->state != USB_SW_TR_PRE_DATA) {
if (std->state == USB_SW_TR_PRE_CALLBACK) {
@@ -1663,7 +1663,7 @@ ohci_device_done(struct usb2_xfer *xfer, usb2_error_t error)
ohci_softc_t *sc = xfer->usb2_sc;
ohci_ed_t *ed;
- mtx_assert(&sc->sc_bus.mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
DPRINTFN(2, "xfer=%p, pipe=%p, error=%d\n",
@@ -2198,7 +2198,7 @@ ohci_root_ctrl_done(struct usb2_xfer *xfer,
uint8_t l;
uint8_t use_polling;
- mtx_assert(&sc->sc_bus.mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
if (std->state != USB_SW_TR_SETUP) {
if (std->state == USB_SW_TR_PRE_CALLBACK) {
@@ -2214,7 +2214,7 @@ ohci_root_ctrl_done(struct usb2_xfer *xfer,
value = UGETW(std->req.wValue);
index = UGETW(std->req.wIndex);
- use_polling = mtx_owned(xfer->priv_mtx) ? 1 : 0;
+ use_polling = mtx_owned(xfer->xfer_mtx) ? 1 : 0;
DPRINTFN(3, "type=0x%02x request=0x%02x wLen=0x%04x "
"wValue=0x%04x wIndex=0x%04x\n",
@@ -2375,7 +2375,7 @@ ohci_root_ctrl_done(struct usb2_xfer *xfer,
/* enable RHSC interrupt if condition is cleared. */
if ((OREAD4(sc, port) >> 16) == 0) {
ohci_rhsc_enable(sc);
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
}
break;
default:
@@ -2456,7 +2456,7 @@ ohci_root_ctrl_done(struct usb2_xfer *xfer,
/* polling */
DELAY(USB_PORT_ROOT_RESET_DELAY * 1000);
} else {
- usb2_pause_mtx(&sc->sc_bus.mtx,
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx,
USB_PORT_ROOT_RESET_DELAY);
}
diff --git a/sys/dev/usb2/controller/ohci2_atmelarm.c b/sys/dev/usb2/controller/ohci2_atmelarm.c
index 83325be..cd0d332 100644
--- a/sys/dev/usb2/controller/ohci2_atmelarm.c
+++ b/sys/dev/usb2/controller/ohci2_atmelarm.c
@@ -111,7 +111,7 @@ ohci_atmelarm_attach(device_t dev)
strlcpy(sc->sc_ohci.sc_vendor, "Atmel", sizeof(sc->sc_ohci.sc_vendor));
err = usb2_config_td_setup(&sc->sc_ohci.sc_config_td, sc,
- &sc->sc_ohci.sc_bus.mtx, NULL, 0, 4);
+ &sc->sc_ohci.sc_bus.bus_mtx, NULL, 0, 4);
if (err) {
device_printf(dev, "could not setup config thread!\n");
goto error;
diff --git a/sys/dev/usb2/controller/ohci2_pci.c b/sys/dev/usb2/controller/ohci2_pci.c
index 60ae0b6..fe84e9c 100644
--- a/sys/dev/usb2/controller/ohci2_pci.c
+++ b/sys/dev/usb2/controller/ohci2_pci.c
@@ -280,7 +280,7 @@ ohci_pci_attach(device_t self)
sprintf(sc->sc_vendor, "(0x%04x)", pci_get_vendor(self));
}
- err = usb2_config_td_setup(&sc->sc_config_td, sc, &sc->sc_bus.mtx,
+ err = usb2_config_td_setup(&sc->sc_config_td, sc, &sc->sc_bus.bus_mtx,
NULL, 0, 4);
if (err) {
device_printf(self, "could not setup config thread!\n");
diff --git a/sys/dev/usb2/controller/uhci2.c b/sys/dev/usb2/controller/uhci2.c
index 9a938d9..5e23cc1 100644
--- a/sys/dev/usb2/controller/uhci2.c
+++ b/sys/dev/usb2/controller/uhci2.c
@@ -265,7 +265,7 @@ uhci_reset(uhci_softc_t *sc)
struct usb2_page_search buf_res;
uint16_t n;
- mtx_assert(&sc->sc_bus.mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
DPRINTF("resetting the HC\n");
@@ -279,7 +279,7 @@ uhci_reset(uhci_softc_t *sc)
/* wait */
- usb2_pause_mtx(&sc->sc_bus.mtx,
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx,
USB_BUS_RESET_DELAY);
/* terminate all transfers */
@@ -292,7 +292,7 @@ uhci_reset(uhci_softc_t *sc)
while (n--) {
/* wait one millisecond */
- usb2_pause_mtx(&sc->sc_bus.mtx, 1);
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx, 1);
if (!(UREAD2(sc, UHCI_CMD) & UHCI_CMD_HCRESET)) {
goto done_1;
@@ -308,7 +308,7 @@ done_1:
while (n--) {
/* wait one millisecond */
- usb2_pause_mtx(&sc->sc_bus.mtx, 1);
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx, 1);
/* check if HC is stopped */
if (UREAD2(sc, UHCI_STS) & UHCI_STS_HCH) {
@@ -332,7 +332,7 @@ done_2:
static void
uhci_start(uhci_softc_t *sc)
{
- mtx_assert(&sc->sc_bus.mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
DPRINTFN(2, "enabling\n");
@@ -355,7 +355,7 @@ uhci_start(uhci_softc_t *sc)
while (n--) {
/* wait one millisecond */
- usb2_pause_mtx(&sc->sc_bus.mtx, 1);
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx, 1);
/* check that controller has started */
@@ -416,7 +416,7 @@ uhci_init(uhci_softc_t *sc)
uint16_t x;
uint16_t y;
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
DPRINTF("start\n");
@@ -613,7 +613,7 @@ uhci_init(uhci_softc_t *sc)
/* start the controller */
uhci_start(sc);
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
/* catch lost interrupts */
uhci_do_poll(&sc->sc_bus);
@@ -628,7 +628,7 @@ uhci_init(uhci_softc_t *sc)
void
uhci_suspend(uhci_softc_t *sc)
{
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
#if USB_DEBUG
if (uhcidebug > 2) {
@@ -648,16 +648,16 @@ uhci_suspend(uhci_softc_t *sc)
UHCICMD(sc, UHCI_CMD_EGSM);
- usb2_pause_mtx(&sc->sc_bus.mtx, USB_RESUME_WAIT);
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx, USB_RESUME_WAIT);
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
return;
}
void
uhci_resume(uhci_softc_t *sc)
{
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
/* reset the controller */
@@ -667,7 +667,7 @@ uhci_resume(uhci_softc_t *sc)
UHCICMD(sc, UHCI_CMD_FGR);
- usb2_pause_mtx(&sc->sc_bus.mtx,
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx,
USB_RESUME_DELAY);
/* and start traffic again */
@@ -680,7 +680,7 @@ uhci_resume(uhci_softc_t *sc)
}
#endif
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
/* catch lost interrupts */
uhci_do_poll(&sc->sc_bus);
@@ -1448,7 +1448,7 @@ uhci_interrupt(uhci_softc_t *sc)
{
uint32_t status;
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
DPRINTFN(16, "real interrupt\n");
@@ -1506,7 +1506,7 @@ uhci_interrupt(uhci_softc_t *sc)
uhci_interrupt_poll(sc);
done:
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
return;
}
@@ -1521,12 +1521,12 @@ uhci_timeout(void *arg)
DPRINTF("xfer=%p\n", xfer);
- mtx_assert(&sc->sc_bus.mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
/* transfer is transferred */
uhci_device_done(xfer, USB_ERR_TIMEOUT);
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
return;
}
@@ -1536,10 +1536,10 @@ uhci_do_poll(struct usb2_bus *bus)
{
struct uhci_softc *sc = UHCI_BUS2SC(bus);
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
uhci_interrupt_poll(sc);
uhci_root_ctrl_poll(sc);
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
return;
}
@@ -1857,7 +1857,7 @@ uhci_device_done(struct usb2_xfer *xfer, usb2_error_t error)
uhci_softc_t *sc = xfer->usb2_sc;
uhci_qh_t *qh;
- mtx_assert(&sc->sc_bus.mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
DPRINTFN(2, "xfer=%p, pipe=%p, error=%d\n",
xfer, xfer->pipe, error);
@@ -2437,7 +2437,7 @@ uhci_portreset(uhci_softc_t *sc, uint16_t index, uint8_t use_polling)
/* polling */
DELAY(USB_PORT_ROOT_RESET_DELAY * 1000);
} else {
- usb2_pause_mtx(&sc->sc_bus.mtx,
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx,
USB_PORT_ROOT_RESET_DELAY);
}
@@ -2451,7 +2451,7 @@ uhci_portreset(uhci_softc_t *sc, uint16_t index, uint8_t use_polling)
/* polling */
DELAY(1000);
} else {
- usb2_pause_mtx(&sc->sc_bus.mtx, 1);
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx, 1);
}
DPRINTFN(4, "uhci port %d reset, status1 = 0x%04x\n",
@@ -2466,7 +2466,7 @@ uhci_portreset(uhci_softc_t *sc, uint16_t index, uint8_t use_polling)
/* polling */
DELAY(USB_PORT_RESET_DELAY * 1000);
} else {
- usb2_pause_mtx(&sc->sc_bus.mtx,
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx,
USB_PORT_RESET_DELAY);
}
@@ -2560,7 +2560,7 @@ uhci_root_ctrl_done(struct usb2_xfer *xfer,
uint16_t change;
uint8_t use_polling;
- mtx_assert(&sc->sc_bus.mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
if (std->state != USB_SW_TR_SETUP) {
if (std->state == USB_SW_TR_PRE_CALLBACK) {
@@ -2576,7 +2576,7 @@ uhci_root_ctrl_done(struct usb2_xfer *xfer,
value = UGETW(std->req.wValue);
index = UGETW(std->req.wIndex);
- use_polling = mtx_owned(xfer->priv_mtx) ? 1 : 0;
+ use_polling = mtx_owned(xfer->xfer_mtx) ? 1 : 0;
DPRINTFN(3, "type=0x%02x request=0x%02x wLen=0x%04x "
"wValue=0x%04x wIndex=0x%04x\n",
@@ -2913,7 +2913,7 @@ uhci_root_intr_done(struct usb2_xfer *xfer,
{
uhci_softc_t *sc = xfer->usb2_sc;
- mtx_assert(&sc->sc_bus.mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
if (std->state != USB_SW_TR_PRE_DATA) {
if (std->state == USB_SW_TR_PRE_CALLBACK) {
@@ -2941,7 +2941,7 @@ uhci_root_intr_check(void *arg)
DPRINTFN(21, "\n");
- mtx_assert(&sc->sc_bus.mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
sc->sc_hub_idata[0] = 0;
@@ -2960,7 +2960,7 @@ uhci_root_intr_check(void *arg)
usb2_sw_transfer(&sc->sc_root_intr,
&uhci_root_intr_done);
}
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
return;
}
diff --git a/sys/dev/usb2/controller/uhci2_pci.c b/sys/dev/usb2/controller/uhci2_pci.c
index 947f9af..44e0b59 100644
--- a/sys/dev/usb2/controller/uhci2_pci.c
+++ b/sys/dev/usb2/controller/uhci2_pci.c
@@ -321,7 +321,7 @@ uhci_pci_attach(device_t self)
break;
}
- err = usb2_config_td_setup(&sc->sc_config_td, sc, &sc->sc_bus.mtx,
+ err = usb2_config_td_setup(&sc->sc_config_td, sc, &sc->sc_bus.bus_mtx,
NULL, 0, 4);
if (err) {
device_printf(self, "could not setup config thread!\n");
@@ -390,12 +390,12 @@ uhci_pci_detach(device_t self)
* uhci_init.
*/
if (sc->sc_io_res) {
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
/* stop the controller */
uhci_reset(sc);
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
}
pci_disable_busmaster(self);
diff --git a/sys/dev/usb2/controller/usb2_bus.h b/sys/dev/usb2/controller/usb2_bus.h
index cfe98f7..c58c986 100644
--- a/sys/dev/usb2/controller/usb2_bus.h
+++ b/sys/dev/usb2/controller/usb2_bus.h
@@ -54,7 +54,7 @@ struct usb2_bus {
struct usb2_process explore_proc;
struct usb2_bus_msg explore_msg[2];
struct usb2_bus_msg detach_msg[2];
- struct mtx mtx; /* This mutex protects the USB
+ struct mtx bus_mtx; /* This mutex protects the USB
* hardware */
struct usb2_perm perm;
struct usb2_xfer_queue intr_q;
diff --git a/sys/dev/usb2/controller/usb2_controller.c b/sys/dev/usb2/controller/usb2_controller.c
index fdfa3a6..028c312 100644
--- a/sys/dev/usb2/controller/usb2_controller.c
+++ b/sys/dev/usb2/controller/usb2_controller.c
@@ -144,7 +144,7 @@ usb2_detach(device_t dev)
}
/* Let the USB explore process detach all devices. */
- mtx_lock(&bus->mtx);
+ USB_BUS_LOCK(bus);
if (usb2_proc_msignal(&bus->explore_proc,
&bus->detach_msg[0], &bus->detach_msg[1])) {
/* ignore */
@@ -154,7 +154,7 @@ usb2_detach(device_t dev)
usb2_proc_mwait(&bus->explore_proc,
&bus->detach_msg[0], &bus->detach_msg[1]);
- mtx_unlock(&bus->mtx);
+ USB_BUS_UNLOCK(bus);
/* Get rid of USB explore process */
@@ -187,7 +187,7 @@ usb2_bus_explore(struct usb2_proc_msg *pm)
/* avoid zero, hence that is memory default */
bus->driver_added_refcount = 1;
}
- mtx_unlock(&bus->mtx);
+ USB_BUS_UNLOCK(bus);
mtx_lock(&Giant);
@@ -199,7 +199,7 @@ usb2_bus_explore(struct usb2_proc_msg *pm)
mtx_unlock(&Giant);
- mtx_lock(&bus->mtx);
+ USB_BUS_LOCK(bus);
}
return;
}
@@ -221,7 +221,7 @@ usb2_bus_detach(struct usb2_proc_msg *pm)
dev = bus->bdev;
/* clear the softc */
device_set_softc(dev, NULL);
- mtx_unlock(&bus->mtx);
+ USB_BUS_UNLOCK(bus);
mtx_lock(&Giant);
@@ -236,7 +236,7 @@ usb2_bus_detach(struct usb2_proc_msg *pm)
usb2_free_device(udev);
mtx_unlock(&Giant);
- mtx_lock(&bus->mtx);
+ USB_BUS_LOCK(bus);
/* clear bdev variable last */
bus->bdev = NULL;
return;
@@ -320,7 +320,7 @@ usb2_attach_sub(device_t dev, struct usb2_bus *bus)
/* Create a new USB process */
if (usb2_proc_setup(&bus->explore_proc,
- &bus->mtx, USB_PRI_MED)) {
+ &bus->bus_mtx, USB_PRI_MED)) {
printf("WARNING: Creation of USB explore process failed.\n");
}
/* set softc - we are ready */
@@ -432,13 +432,13 @@ usb2_bus_mem_alloc_all(struct usb2_bus *bus, bus_dma_tag_t dmat,
bus->devices_max = USB_MAX_DEVICES;
- mtx_init(&bus->mtx, "USB lock",
+ mtx_init(&bus->bus_mtx, "USB bus lock",
NULL, MTX_DEF | MTX_RECURSE);
TAILQ_INIT(&bus->intr_q.head);
usb2_dma_tag_setup(bus->dma_parent_tag, bus->dma_tags,
- dmat, &bus->mtx, NULL, NULL, 32, USB_BUS_DMA_TAG_MAX);
+ dmat, &bus->bus_mtx, NULL, NULL, 32, USB_BUS_DMA_TAG_MAX);
if (cb) {
cb(bus, &usb2_bus_mem_alloc_all_cb);
@@ -471,7 +471,7 @@ usb2_bus_mem_free_all(struct usb2_bus *bus, usb2_bus_mem_cb_t *cb)
}
usb2_dma_tag_unsetup(bus->dma_parent_tag);
- mtx_destroy(&bus->mtx);
+ mtx_destroy(&bus->bus_mtx);
return;
}
diff --git a/sys/dev/usb2/controller/uss820dci.c b/sys/dev/usb2/controller/uss820dci.c
index cc9f219..e6af4d7 100644
--- a/sys/dev/usb2/controller/uss820dci.c
+++ b/sys/dev/usb2/controller/uss820dci.c
@@ -235,7 +235,7 @@ uss820dci_rem_wakeup_set(struct usb2_device *udev, uint8_t is_on)
DPRINTFN(5, "is_on=%u\n", is_on);
- mtx_assert(&udev->bus->mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(udev->bus, MA_OWNED);
sc = USS820_DCI_BUS2SC(udev->bus);
@@ -755,7 +755,7 @@ uss820dci_interrupt(struct uss820dci_softc *sc)
uint8_t ssr;
uint8_t event;
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
ssr = USS820_READ_1(sc, USS820_SSR);
@@ -826,7 +826,7 @@ uss820dci_interrupt(struct uss820dci_softc *sc)
/* poll all active transfers */
uss820dci_interrupt_poll(sc);
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
return;
}
@@ -993,12 +993,12 @@ uss820dci_timeout(void *arg)
DPRINTF("xfer=%p\n", xfer);
- mtx_assert(&sc->sc_bus.mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
/* transfer is transferred */
uss820dci_device_done(xfer, USB_ERR_TIMEOUT);
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
return;
}
@@ -1078,7 +1078,7 @@ uss820dci_root_intr_done(struct usb2_xfer *xfer,
DPRINTFN(9, "\n");
- mtx_assert(&sc->sc_bus.mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
if (std->state != USB_SW_TR_PRE_DATA) {
if (std->state == USB_SW_TR_PRE_CALLBACK) {
@@ -1215,7 +1215,7 @@ done:
static void
uss820dci_device_done(struct usb2_xfer *xfer, usb2_error_t error)
{
- mtx_assert(xfer->usb2_mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(xfer->udev->bus, MA_OWNED);
DPRINTFN(2, "xfer=%p, pipe=%p, error=%d\n",
xfer, xfer->pipe, error);
@@ -1238,7 +1238,7 @@ uss820dci_set_stall(struct usb2_device *udev, struct usb2_xfer *xfer,
uint8_t ep_dir;
uint8_t temp;
- mtx_assert(&udev->bus->mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(udev->bus, MA_OWNED);
DPRINTFN(5, "pipe=%p\n", pipe);
@@ -1324,7 +1324,7 @@ uss820dci_clear_stall(struct usb2_device *udev, struct usb2_pipe *pipe)
struct uss820dci_softc *sc;
struct usb2_endpoint_descriptor *ed;
- mtx_assert(&udev->bus->mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(udev->bus, MA_OWNED);
DPRINTFN(5, "pipe=%p\n", pipe);
@@ -1361,7 +1361,7 @@ uss820dci_init(struct uss820dci_softc *sc)
sc->sc_bus.usbrev = USB_REV_1_1;
sc->sc_bus.methods = &uss820dci_bus_methods;
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
/* we always have VBUS */
sc->sc_flags.status_vbus = 1;
@@ -1380,7 +1380,7 @@ uss820dci_init(struct uss820dci_softc *sc)
break;
}
if (n == 100) {
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
return (USB_ERR_INVAL);
}
/* wait a little for things to stabilise */
@@ -1391,13 +1391,13 @@ uss820dci_init(struct uss820dci_softc *sc)
uss820dci_pull_down(sc);
/* wait 10ms for pulldown to stabilise */
- usb2_pause_mtx(&sc->sc_bus.mtx, 10);
+ usb2_pause_mtx(&sc->sc_bus.bus_mtx, 10);
/* check hardware revision */
temp = USS820_READ_1(sc, USS820_REV);
if (temp < 0x13) {
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
return (USB_ERR_INVAL);
}
/* enable interrupts */
@@ -1503,7 +1503,7 @@ uss820dci_init(struct uss820dci_softc *sc)
uss820dci_update_shared_1(sc, USS820_EPCON, 0xFF, temp);
}
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
/* catch any lost interrupts */
@@ -1517,7 +1517,7 @@ uss820dci_uninit(struct uss820dci_softc *sc)
{
uint8_t temp;
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
/* disable all interrupts */
temp = USS820_READ_1(sc, USS820_SCR);
@@ -1532,7 +1532,7 @@ uss820dci_uninit(struct uss820dci_softc *sc)
sc->sc_flags.change_connect = 1;
uss820dci_pull_down(sc);
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
return;
}
@@ -1554,10 +1554,10 @@ uss820dci_do_poll(struct usb2_bus *bus)
{
struct uss820dci_softc *sc = USS820_DCI_BUS2SC(bus);
- mtx_lock(&sc->sc_bus.mtx);
+ USB_BUS_LOCK(&sc->sc_bus);
uss820dci_interrupt_poll(sc);
uss820dci_root_ctrl_poll(sc);
- mtx_unlock(&sc->sc_bus.mtx);
+ USB_BUS_UNLOCK(&sc->sc_bus);
return;
}
@@ -1919,7 +1919,7 @@ uss820dci_root_ctrl_done(struct usb2_xfer *xfer,
uint16_t index;
uint8_t use_polling;
- mtx_assert(&sc->sc_bus.mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(&sc->sc_bus, MA_OWNED);
if (std->state != USB_SW_TR_SETUP) {
if (std->state == USB_SW_TR_PRE_CALLBACK) {
@@ -1935,7 +1935,7 @@ uss820dci_root_ctrl_done(struct usb2_xfer *xfer,
value = UGETW(std->req.wValue);
index = UGETW(std->req.wIndex);
- use_polling = mtx_owned(xfer->priv_mtx) ? 1 : 0;
+ use_polling = mtx_owned(xfer->xfer_mtx) ? 1 : 0;
/* demultiplex the control request */
diff --git a/sys/dev/usb2/controller/uss820dci_atmelarm.c b/sys/dev/usb2/controller/uss820dci_atmelarm.c
index be71fb3..3a1eb16 100644
--- a/sys/dev/usb2/controller/uss820dci_atmelarm.c
+++ b/sys/dev/usb2/controller/uss820dci_atmelarm.c
@@ -171,7 +171,7 @@ uss820_atmelarm_attach(device_t dev)
device_set_ivars(sc->sc_bus.bdev, &sc->sc_bus);
err = usb2_config_td_setup(&sc->sc_config_td, sc,
- &sc->sc_bus.mtx, NULL, 0, 4);
+ &sc->sc_bus.bus_mtx, NULL, 0, 4);
if (err) {
device_printf(dev, "could not setup config thread!\n");
goto error;
diff --git a/sys/dev/usb2/controller/uss820dci_pccard.c b/sys/dev/usb2/controller/uss820dci_pccard.c
index f57935d..dde423d 100644
--- a/sys/dev/usb2/controller/uss820dci_pccard.c
+++ b/sys/dev/usb2/controller/uss820dci_pccard.c
@@ -190,7 +190,7 @@ uss820_pccard_attach(device_t dev)
device_set_ivars(sc->sc_bus.bdev, &sc->sc_bus);
err = usb2_config_td_setup(&sc->sc_config_td, sc,
- &sc->sc_bus.mtx, NULL, 0, 4);
+ &sc->sc_bus.bus_mtx, NULL, 0, 4);
if (err) {
device_printf(dev, "could not setup config thread!\n");
goto error;
diff --git a/sys/dev/usb2/core/usb2_busdma.c b/sys/dev/usb2/core/usb2_busdma.c
index 1b8c4a1..b5fbc7f 100644
--- a/sys/dev/usb2/core/usb2_busdma.c
+++ b/sys/dev/usb2/core/usb2_busdma.c
@@ -24,15 +24,20 @@
* SUCH DAMAGE.
*/
+#include <dev/usb2/include/usb2_mfunc.h>
+#include <dev/usb2/include/usb2_error.h>
+#include <dev/usb2/include/usb2_standard.h>
+#include <dev/usb2/include/usb2_defs.h>
+
#include <dev/usb2/core/usb2_core.h>
#include <dev/usb2/core/usb2_busdma.h>
#include <dev/usb2/core/usb2_process.h>
#include <dev/usb2/core/usb2_transfer.h>
+#include <dev/usb2/core/usb2_device.h>
#include <dev/usb2/core/usb2_util.h>
-#include <dev/usb2/include/usb2_mfunc.h>
-#include <dev/usb2/include/usb2_error.h>
-#include <dev/usb2/include/usb2_standard.h>
+#include <dev/usb2/controller/usb2_controller.h>
+#include <dev/usb2/controller/usb2_bus.h>
static void usb2_dma_tag_create(struct usb2_dma_tag *udt, uint32_t size, uint32_t align);
static void usb2_dma_tag_destroy(struct usb2_dma_tag *udt);
@@ -1196,9 +1201,9 @@ usb2_bdma_work_loop(struct usb2_xfer_queue *pq)
if (xfer->error) {
/* some error happened */
- mtx_lock(xfer->usb2_mtx);
+ USB_BUS_LOCK(xfer->udev->bus);
usb2_transfer_done(xfer, 0);
- mtx_unlock(xfer->usb2_mtx);
+ USB_BUS_UNLOCK(xfer->udev->bus);
return;
}
if (!xfer->flags_int.bdma_setup) {
@@ -1270,9 +1275,9 @@ usb2_bdma_work_loop(struct usb2_xfer_queue *pq)
}
if (info->dma_error) {
- mtx_lock(xfer->usb2_mtx);
+ USB_BUS_LOCK(xfer->udev->bus);
usb2_transfer_done(xfer, USB_ERR_DMA_LOAD_FAILED);
- mtx_unlock(xfer->usb2_mtx);
+ USB_BUS_UNLOCK(xfer->udev->bus);
return;
}
if (info->dma_currframe != info->dma_nframes) {
diff --git a/sys/dev/usb2/core/usb2_core.h b/sys/dev/usb2/core/usb2_core.h
index c0cec7a..d8b8860 100644
--- a/sys/dev/usb2/core/usb2_core.h
+++ b/sys/dev/usb2/core/usb2_core.h
@@ -159,6 +159,12 @@
#define usb2_callout_drain(c) callout_drain(&(c)->co)
#define usb2_callout_pending(c) callout_pending(&(c)->co)
+#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)->xfer_mtx)
+#define USB_XFER_UNLOCK(_x) mtx_unlock((_x)->xfer_mtx)
+#define USB_XFER_LOCK_ASSERT(_x, _t) mtx_assert((_x)->xfer_mtx, _t)
/* structure prototypes */
struct file;
@@ -304,8 +310,7 @@ struct usb2_xfer {
struct usb2_page *dma_page_ptr;
struct usb2_pipe *pipe; /* our USB pipe */
struct usb2_device *udev;
- struct mtx *priv_mtx; /* cannot be changed during operation */
- struct mtx *usb2_mtx; /* used by HC driver */
+ struct mtx *xfer_mtx; /* cannot be changed during operation */
struct usb2_xfer_root *usb2_root; /* used by HC driver */
void *usb2_sc; /* used by HC driver */
void *qh_start[2]; /* used by HC driver */
diff --git a/sys/dev/usb2/core/usb2_device.c b/sys/dev/usb2/core/usb2_device.c
index 9348865..10ac7f1 100644
--- a/sys/dev/usb2/core/usb2_device.c
+++ b/sys/dev/usb2/core/usb2_device.c
@@ -295,9 +295,9 @@ usb2_fill_pipe_data(struct usb2_device *udev, uint8_t iface_index,
/* clear stall, if any */
if (udev->bus->methods->clear_stall) {
- mtx_lock(&udev->bus->mtx);
+ USB_BUS_LOCK(udev->bus);
(udev->bus->methods->clear_stall) (udev, pipe);
- mtx_unlock(&udev->bus->mtx);
+ USB_BUS_UNLOCK(udev->bus);
}
return;
}
@@ -730,7 +730,7 @@ usb2_set_endpoint_stall(struct usb2_device *udev, struct usb2_pipe *pipe,
DPRINTF("Invalid endpoint\n");
return (0);
}
- mtx_lock(&udev->bus->mtx);
+ USB_BUS_LOCK(udev->bus);
/* store current stall state */
was_stalled = pipe->is_stalled;
@@ -738,7 +738,7 @@ usb2_set_endpoint_stall(struct usb2_device *udev, struct usb2_pipe *pipe,
/* check for no change */
if (was_stalled && do_stall) {
/* if the pipe is already stalled do nothing */
- mtx_unlock(&udev->bus->mtx);
+ USB_BUS_UNLOCK(udev->bus);
DPRINTF("No change\n");
return (0);
}
@@ -769,7 +769,7 @@ usb2_set_endpoint_stall(struct usb2_device *udev, struct usb2_pipe *pipe,
/* start up the current or next transfer, if any */
usb2_command_wrapper(&pipe->pipe_q, pipe->pipe_q.curr);
}
- mtx_unlock(&udev->bus->mtx);
+ USB_BUS_UNLOCK(udev->bus);
return (0);
}
@@ -1207,15 +1207,15 @@ usb2_suspend_resume(struct usb2_device *udev, uint8_t do_suspend)
sx_assert(udev->default_sx + 1, SA_LOCKED);
- mtx_lock(&udev->bus->mtx);
+ USB_BUS_LOCK(udev->bus);
/* filter the suspend events */
if (udev->flags.suspended == do_suspend) {
- mtx_unlock(&udev->bus->mtx);
+ USB_BUS_UNLOCK(udev->bus);
/* nothing to do */
return (0);
}
udev->flags.suspended = do_suspend;
- mtx_unlock(&udev->bus->mtx);
+ USB_BUS_UNLOCK(udev->bus);
/* do the suspend or resume */
@@ -1243,7 +1243,7 @@ usb2_clear_stall_proc(struct usb2_proc_msg *_pm)
struct usb2_device *udev = pm->udev;
/* Change lock */
- mtx_unlock(&udev->bus->mtx);
+ USB_BUS_UNLOCK(udev->bus);
mtx_lock(udev->default_mtx);
/* Start clear stall callback */
@@ -1251,7 +1251,7 @@ usb2_clear_stall_proc(struct usb2_proc_msg *_pm)
/* Change lock */
mtx_unlock(udev->default_mtx);
- mtx_lock(&udev->bus->mtx);
+ USB_BUS_LOCK(udev->bus);
return;
}
diff --git a/sys/dev/usb2/core/usb2_handle_request.c b/sys/dev/usb2/core/usb2_handle_request.c
index 7dc82c0..6181dc4 100644
--- a/sys/dev/usb2/core/usb2_handle_request.c
+++ b/sys/dev/usb2/core/usb2_handle_request.c
@@ -130,7 +130,7 @@ usb2_handle_set_config(struct usb2_xfer *xfer, uint8_t conf_no)
* We need to protect against other threads doing probe and
* attach:
*/
- mtx_unlock(xfer->priv_mtx);
+ USB_XFER_UNLOCK(xfer);
mtx_lock(&Giant); /* XXX */
sx_xlock(xfer->udev->default_sx + 1);
@@ -157,7 +157,7 @@ usb2_handle_set_config(struct usb2_xfer *xfer, uint8_t conf_no)
done:
mtx_unlock(&Giant); /* XXX */
sx_unlock(xfer->udev->default_sx + 1);
- mtx_lock(xfer->priv_mtx);
+ USB_XFER_LOCK(xfer);
return (err);
}
@@ -189,7 +189,7 @@ usb2_handle_iface_request(struct usb2_xfer *xfer,
* We need to protect against other threads doing probe and
* attach:
*/
- mtx_unlock(xfer->priv_mtx);
+ USB_XFER_UNLOCK(xfer);
mtx_lock(&Giant); /* XXX */
sx_xlock(udev->default_sx + 1);
@@ -310,13 +310,13 @@ tr_repeat:
tr_valid:
mtx_unlock(&Giant);
sx_unlock(udev->default_sx + 1);
- mtx_lock(xfer->priv_mtx);
+ USB_XFER_LOCK(xfer);
return (0);
tr_stalled:
mtx_unlock(&Giant);
sx_unlock(udev->default_sx + 1);
- mtx_lock(xfer->priv_mtx);
+ USB_XFER_LOCK(xfer);
return (USB_ERR_STALLED);
}
@@ -332,10 +332,10 @@ usb2_handle_set_stall(struct usb2_xfer *xfer, uint8_t ep, uint8_t do_stall)
{
usb2_error_t err;
- mtx_unlock(xfer->priv_mtx);
+ USB_XFER_UNLOCK(xfer);
err = usb2_set_endpoint_stall(xfer->udev,
usb2_get_pipe_by_addr(xfer->udev, ep), do_stall);
- mtx_lock(xfer->priv_mtx);
+ USB_XFER_LOCK(xfer);
return (err);
}
@@ -357,9 +357,9 @@ usb2_handle_get_stall(struct usb2_device *udev, uint8_t ea_val)
/* nothing to do */
return (0);
}
- mtx_lock(&udev->bus->mtx);
+ USB_BUS_LOCK(udev->bus);
halted = pipe->is_stalled;
- mtx_unlock(&udev->bus->mtx);
+ USB_BUS_UNLOCK(udev->bus);
return (halted);
}
@@ -380,7 +380,7 @@ usb2_handle_remote_wakeup(struct usb2_xfer *xfer, uint8_t is_on)
udev = xfer->udev;
bus = udev->bus;
- mtx_lock(&bus->mtx);
+ USB_BUS_LOCK(bus);
if (is_on) {
udev->flags.remote_wakeup = 1;
@@ -390,7 +390,7 @@ usb2_handle_remote_wakeup(struct usb2_xfer *xfer, uint8_t is_on)
(bus->methods->rem_wakeup_set) (xfer->udev, is_on);
- mtx_unlock(&bus->mtx);
+ USB_BUS_UNLOCK(bus);
return (0); /* success */
}
@@ -604,14 +604,14 @@ tr_handle_get_status:
wValue = 0;
- mtx_lock(&udev->bus->mtx);
+ USB_BUS_LOCK(udev->bus);
if (udev->flags.remote_wakeup) {
wValue |= UDS_REMOTE_WAKEUP;
}
if (udev->flags.self_powered) {
wValue |= UDS_SELF_POWERED;
}
- mtx_unlock(&udev->bus->mtx);
+ USB_BUS_UNLOCK(udev->bus);
USETW(temp.wStatus, wValue);
src_mcopy = temp.wStatus;
diff --git a/sys/dev/usb2/core/usb2_hub.c b/sys/dev/usb2/core/usb2_hub.c
index b360855..7cc23cc 100644
--- a/sys/dev/usb2/core/usb2_hub.c
+++ b/sys/dev/usb2/core/usb2_hub.c
@@ -756,9 +756,9 @@ uhub_attach(device_t dev)
/* start the interrupt endpoint */
- mtx_lock(sc->sc_xfer[0]->priv_mtx);
+ USB_XFER_LOCK(sc->sc_xfer[0]);
usb2_transfer_start(sc->sc_xfer[0]);
- mtx_unlock(sc->sc_xfer[0]->priv_mtx);
+ USB_XFER_UNLOCK(sc->sc_xfer[0]);
return (0);
@@ -1002,7 +1002,7 @@ usb2_intr_schedule_adjust(struct usb2_device *udev, int16_t len, uint8_t slot)
struct usb2_bus *bus = udev->bus;
struct usb2_hub *hub;
- mtx_assert(&bus->mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(bus, MA_OWNED);
if (usb2_get_speed(udev) == USB_SPEED_HIGH) {
if (slot >= USB_HS_MICRO_FRAMES_MAX) {
@@ -1079,7 +1079,7 @@ usb2_isoc_time_expand(struct usb2_bus *bus, uint16_t isoc_time_curr)
{
uint16_t rem;
- mtx_assert(&bus->mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(bus, MA_OWNED);
rem = bus->isoc_time_last & (USB_ISOC_TIME_MAX - 1);
@@ -1279,7 +1279,7 @@ usb2_needs_explore(struct usb2_bus *bus, uint8_t do_probe)
DPRINTF("No bus pointer!\n");
return;
}
- mtx_lock(&bus->mtx);
+ USB_BUS_LOCK(bus);
if (do_probe) {
bus->do_probe = 1;
}
@@ -1287,7 +1287,7 @@ usb2_needs_explore(struct usb2_bus *bus, uint8_t do_probe)
&bus->explore_msg[0], &bus->explore_msg[1])) {
/* ignore */
}
- mtx_unlock(&bus->mtx);
+ USB_BUS_UNLOCK(bus);
return;
}
diff --git a/sys/dev/usb2/core/usb2_request.c b/sys/dev/usb2/core/usb2_request.c
index 72d9f17..e91d27d 100644
--- a/sys/dev/usb2/core/usb2_request.c
+++ b/sys/dev/usb2/core/usb2_request.c
@@ -45,6 +45,8 @@
#include <dev/usb2/core/usb2_util.h>
#include <dev/usb2/core/usb2_dynamic.h>
+#include <dev/usb2/controller/usb2_controller.h>
+#include <dev/usb2/controller/usb2_bus.h>
#include <sys/ctype.h>
#if USB_DEBUG
@@ -98,7 +100,7 @@ usb2_do_clear_stall_callback(struct usb2_xfer *xfer)
struct usb2_pipe *pipe_first;
uint8_t to = USB_EP_MAX;
- mtx_lock(xfer->usb2_mtx);
+ USB_BUS_LOCK(xfer->udev->bus);
/* round robin pipe clear stall */
@@ -144,11 +146,11 @@ tr_setup:
/* set length */
xfer->frlengths[0] = sizeof(req);
xfer->nframes = 1;
- mtx_unlock(xfer->usb2_mtx);
+ USB_BUS_UNLOCK(xfer->udev->bus);
usb2_start_hardware(xfer);
- mtx_lock(xfer->usb2_mtx);
+ USB_BUS_LOCK(xfer->udev->bus);
break;
}
pipe++;
@@ -165,7 +167,7 @@ tr_setup:
/* store current pipe */
xfer->udev->pipe_curr = pipe;
- mtx_unlock(xfer->usb2_mtx);
+ USB_BUS_UNLOCK(xfer->udev->bus);
return;
}
@@ -313,7 +315,7 @@ usb2_do_request_flags(struct usb2_device *udev, struct mtx *mtx,
err = USB_ERR_NOMEM;
goto done;
}
- mtx_lock(xfer->priv_mtx);
+ USB_XFER_LOCK(xfer);
if (flags & USB_DELAY_STATUS_STAGE) {
xfer->flags.manual_status = 1;
@@ -342,10 +344,10 @@ usb2_do_request_flags(struct usb2_device *udev, struct mtx *mtx,
if (temp > 0) {
if (!(req->bmRequestType & UT_READ)) {
if (flags & USB_USER_DATA_PTR) {
- mtx_unlock(xfer->priv_mtx);
+ USB_XFER_UNLOCK(xfer);
err = usb2_copy_in_user(xfer->frbuffers + 1,
0, data, temp);
- mtx_lock(xfer->priv_mtx);
+ USB_XFER_LOCK(xfer);
if (err) {
err = USB_ERR_INVAL;
break;
@@ -367,7 +369,7 @@ usb2_do_request_flags(struct usb2_device *udev, struct mtx *mtx,
}
if (temp > 0) {
usb2_pause_mtx(
- xfer->priv_mtx, temp);
+ xfer->xfer_mtx, temp);
}
#endif
xfer->flags.manual_status = 0;
@@ -384,7 +386,8 @@ usb2_do_request_flags(struct usb2_device *udev, struct mtx *mtx,
if ((flags & USB_USE_POLLING) || cold) {
usb2_do_poll(udev->default_xfer, USB_DEFAULT_XFER_MAX);
} else {
- usb2_cv_wait(xfer->udev->default_cv, xfer->priv_mtx);
+ usb2_cv_wait(xfer->udev->default_cv,
+ xfer->xfer_mtx);
}
}
@@ -413,10 +416,10 @@ usb2_do_request_flags(struct usb2_device *udev, struct mtx *mtx,
if (temp > 0) {
if (req->bmRequestType & UT_READ) {
if (flags & USB_USER_DATA_PTR) {
- mtx_unlock(xfer->priv_mtx);
+ USB_XFER_UNLOCK(xfer);
err = usb2_copy_out_user(xfer->frbuffers + 1,
0, data, temp);
- mtx_lock(xfer->priv_mtx);
+ USB_XFER_LOCK(xfer);
if (err) {
err = USB_ERR_INVAL;
break;
@@ -460,7 +463,7 @@ usb2_do_request_flags(struct usb2_device *udev, struct mtx *mtx,
*/
usb2_transfer_stop(xfer);
}
- mtx_unlock(xfer->priv_mtx);
+ USB_XFER_UNLOCK(xfer);
done:
sx_xunlock(udev->default_sx);
diff --git a/sys/dev/usb2/core/usb2_sw_transfer.c b/sys/dev/usb2/core/usb2_sw_transfer.c
index bb82502..2a2e1e4 100644
--- a/sys/dev/usb2/core/usb2_sw_transfer.c
+++ b/sys/dev/usb2/core/usb2_sw_transfer.c
@@ -27,6 +27,7 @@
#include <dev/usb2/include/usb2_mfunc.h>
#include <dev/usb2/include/usb2_standard.h>
#include <dev/usb2/include/usb2_error.h>
+#include <dev/usb2/include/usb2_defs.h>
#define USB_DEBUG_VAR usb2_debug
@@ -35,8 +36,12 @@
#include <dev/usb2/core/usb2_busdma.h>
#include <dev/usb2/core/usb2_transfer.h>
#include <dev/usb2/core/usb2_sw_transfer.h>
+#include <dev/usb2/core/usb2_device.h>
#include <dev/usb2/core/usb2_debug.h>
+#include <dev/usb2/controller/usb2_controller.h>
+#include <dev/usb2/controller/usb2_bus.h>
+
/*------------------------------------------------------------------------*
* usb2_sw_transfer - factored out code
*
@@ -67,7 +72,7 @@ usb2_sw_transfer(struct usb2_sw_transfer *std,
DPRINTF("xfer gone\n");
return;
}
- mtx_assert(xfer->usb2_mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(xfer->udev->bus, MA_OWNED);
std->xfer = NULL;
diff --git a/sys/dev/usb2/core/usb2_transfer.c b/sys/dev/usb2/core/usb2_transfer.c
index 2167624..59ac2c9 100644
--- a/sys/dev/usb2/core/usb2_transfer.c
+++ b/sys/dev/usb2/core/usb2_transfer.c
@@ -802,7 +802,6 @@ usb2_transfer_setup(struct usb2_device *udev,
usb2_cv_init(&info->cv_drain, "WDRAIN");
- info->usb2_mtx = &udev->bus->mtx;
info->priv_mtx = priv_mtx;
usb2_dma_tag_setup(&info->dma_parent_tag,
@@ -825,7 +824,7 @@ usb2_transfer_setup(struct usb2_device *udev,
/* create a callback thread */
if (usb2_proc_setup(&info->done_p,
- &udev->bus->mtx, USB_PRI_HIGH)) {
+ &udev->bus->bus_mtx, USB_PRI_HIGH)) {
parm.err = USB_ERR_NO_INTR_THREAD;
goto done;
}
@@ -878,13 +877,12 @@ usb2_transfer_setup(struct usb2_device *udev,
xfer->udev = udev;
xfer->address = udev->address;
xfer->priv_sc = priv_sc;
- xfer->priv_mtx = priv_mtx;
- xfer->usb2_mtx = &udev->bus->mtx;
+ xfer->xfer_mtx = priv_mtx;
xfer->usb2_root = info;
info->setup_refcount++;
- usb2_callout_init_mtx(&xfer->timeout_handle, xfer->usb2_mtx,
- CALLOUT_RETURNUNLOCKED);
+ usb2_callout_init_mtx(&xfer->timeout_handle,
+ &udev->bus->bus_mtx, CALLOUT_RETURNUNLOCKED);
} else {
/*
* Setup a dummy xfer, hence we are
@@ -1020,9 +1018,9 @@ done:
if (info->setup_refcount == 0) {
/*
* "usb2_transfer_unsetup_sub" will unlock
- * "usb2_mtx" before returning !
+ * the bus mutex before returning !
*/
- mtx_lock(info->usb2_mtx);
+ USB_BUS_LOCK(info->bus);
/* something went wrong */
usb2_transfer_unsetup_sub(info, 0);
@@ -1043,15 +1041,15 @@ usb2_transfer_unsetup_sub(struct usb2_xfer_root *info, uint8_t needs_delay)
struct usb2_page_cache *pc;
uint32_t temp;
- mtx_assert(info->usb2_mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(info->bus, MA_OWNED);
/* wait for any outstanding DMA operations */
if (needs_delay) {
temp = usb2_get_dma_delay(info->bus);
- usb2_pause_mtx(info->usb2_mtx, temp);
+ usb2_pause_mtx(&info->bus->bus_mtx, temp);
}
- mtx_unlock(info->usb2_mtx);
+ USB_BUS_UNLOCK(info->bus);
/* wait for interrupt thread to exit */
usb2_proc_unsetup(&info->done_p);
@@ -1105,8 +1103,8 @@ usb2_transfer_unsetup(struct usb2_xfer **pxfer, uint16_t n_setup)
if (xfer) {
if (xfer->pipe) {
- mtx_lock(xfer->priv_mtx);
- mtx_lock(xfer->usb2_mtx);
+ USB_XFER_LOCK(xfer);
+ USB_BUS_LOCK(xfer->udev->bus);
/*
* HINT: when you start/stop a transfer, it
@@ -1130,8 +1128,8 @@ usb2_transfer_unsetup(struct usb2_xfer **pxfer, uint16_t n_setup)
*/
pxfer[n_setup] = NULL;
- mtx_unlock(xfer->usb2_mtx);
- mtx_unlock(xfer->priv_mtx);
+ USB_BUS_UNLOCK(xfer->udev->bus);
+ USB_XFER_UNLOCK(xfer);
usb2_transfer_drain(xfer);
@@ -1154,7 +1152,7 @@ usb2_transfer_unsetup(struct usb2_xfer **pxfer, uint16_t n_setup)
if (xfer->usb2_root) {
info = xfer->usb2_root;
- mtx_lock(info->usb2_mtx);
+ USB_BUS_LOCK(info->bus);
USB_ASSERT(info->setup_refcount != 0,
("Invalid setup "
@@ -1166,7 +1164,7 @@ usb2_transfer_unsetup(struct usb2_xfer **pxfer, uint16_t n_setup)
usb2_transfer_unsetup_sub(info,
needs_delay);
} else {
- mtx_unlock(info->usb2_mtx);
+ USB_BUS_UNLOCK(info->bus);
}
}
}
@@ -1358,16 +1356,16 @@ usb2_start_hardware(struct usb2_xfer *xfer)
#if USB_DEBUG
if (USB_DEBUG_VAR > 0) {
- mtx_lock(xfer->usb2_mtx);
+ USB_BUS_LOCK(xfer->udev->bus);
usb2_dump_pipe(xfer->pipe);
- mtx_unlock(xfer->usb2_mtx);
+ USB_BUS_UNLOCK(xfer->udev->bus);
}
#endif
- mtx_assert(xfer->priv_mtx, MA_OWNED);
- mtx_assert(xfer->usb2_mtx, MA_NOTOWNED);
+ USB_XFER_LOCK_ASSERT(xfer, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(xfer->udev->bus, MA_NOTOWNED);
/* Only open the USB transfer once! */
if (!xfer->flags_int.open) {
@@ -1375,9 +1373,9 @@ usb2_start_hardware(struct usb2_xfer *xfer)
DPRINTF("open\n");
- mtx_lock(xfer->usb2_mtx);
+ USB_BUS_LOCK(xfer->udev->bus);
(xfer->pipe->methods->open) (xfer);
- mtx_unlock(xfer->usb2_mtx);
+ USB_BUS_UNLOCK(xfer->udev->bus);
}
/* set "transferring" flag */
xfer->flags_int.transferring = 1;
@@ -1387,9 +1385,9 @@ usb2_start_hardware(struct usb2_xfer *xfer)
* frequently the "done_q":
*/
if (xfer->wait_queue) {
- mtx_lock(xfer->usb2_mtx);
+ USB_BUS_LOCK(xfer->udev->bus);
usb2_transfer_dequeue(xfer);
- mtx_unlock(xfer->usb2_mtx);
+ USB_BUS_UNLOCK(xfer->udev->bus);
}
/* clear "did_dma_delay" flag */
xfer->flags_int.did_dma_delay = 0;
@@ -1421,16 +1419,16 @@ usb2_start_hardware(struct usb2_xfer *xfer)
*/
DPRINTF("xfer=%p nframes=0: stall "
"or clear stall!\n", xfer);
- mtx_lock(xfer->usb2_mtx);
+ USB_BUS_LOCK(xfer->udev->bus);
xfer->flags_int.can_cancel_immed = 1;
/* start the transfer */
usb2_command_wrapper(&xfer->pipe->pipe_q, xfer);
- mtx_unlock(xfer->usb2_mtx);
+ USB_BUS_UNLOCK(xfer->udev->bus);
return;
}
- mtx_lock(xfer->usb2_mtx);
+ USB_BUS_LOCK(xfer->udev->bus);
usb2_transfer_done(xfer, USB_ERR_INVAL);
- mtx_unlock(xfer->usb2_mtx);
+ USB_BUS_UNLOCK(xfer->udev->bus);
return;
}
/* compute total transfer length */
@@ -1439,9 +1437,9 @@ usb2_start_hardware(struct usb2_xfer *xfer)
xfer->sumlen += xfer->frlengths[x];
if (xfer->sumlen < xfer->frlengths[x]) {
/* length wrapped around */
- mtx_lock(xfer->usb2_mtx);
+ USB_BUS_LOCK(xfer->udev->bus);
usb2_transfer_done(xfer, USB_ERR_INVAL);
- mtx_unlock(xfer->usb2_mtx);
+ USB_BUS_UNLOCK(xfer->udev->bus);
return;
}
}
@@ -1456,9 +1454,9 @@ usb2_start_hardware(struct usb2_xfer *xfer)
if (xfer->flags_int.control_xfr) {
if (usb2_start_hardware_sub(xfer)) {
- mtx_lock(xfer->usb2_mtx);
+ USB_BUS_LOCK(xfer->udev->bus);
usb2_transfer_done(xfer, USB_ERR_STALLED);
- mtx_unlock(xfer->usb2_mtx);
+ USB_BUS_UNLOCK(xfer->udev->bus);
return;
}
}
@@ -1513,9 +1511,9 @@ usb2_pipe_enter(struct usb2_xfer *xfer)
{
struct usb2_pipe *pipe;
- mtx_assert(xfer->priv_mtx, MA_OWNED);
+ USB_XFER_LOCK_ASSERT(xfer, MA_OWNED);
- mtx_lock(xfer->usb2_mtx);
+ USB_BUS_LOCK(xfer->udev->bus);
pipe = xfer->pipe;
@@ -1531,7 +1529,7 @@ usb2_pipe_enter(struct usb2_xfer *xfer)
if (xfer->error) {
/* some error has happened */
usb2_transfer_done(xfer, 0);
- mtx_unlock(xfer->usb2_mtx);
+ USB_BUS_UNLOCK(xfer->udev->bus);
return;
}
} else {
@@ -1540,7 +1538,7 @@ usb2_pipe_enter(struct usb2_xfer *xfer)
/* start the transfer */
usb2_command_wrapper(&pipe->pipe_q, xfer);
- mtx_unlock(xfer->usb2_mtx);
+ USB_BUS_UNLOCK(xfer->udev->bus);
return;
}
@@ -1558,7 +1556,7 @@ usb2_transfer_start(struct usb2_xfer *xfer)
/* transfer is gone */
return;
}
- mtx_assert(xfer->priv_mtx, MA_OWNED);
+ USB_XFER_LOCK_ASSERT(xfer, MA_OWNED);
/* mark the USB transfer started */
@@ -1570,10 +1568,10 @@ usb2_transfer_start(struct usb2_xfer *xfer)
if (xfer->flags_int.transferring) {
return;
}
- mtx_lock(xfer->usb2_mtx);
+ USB_BUS_LOCK(xfer->udev->bus);
/* call the USB transfer callback */
usb2_callback_ss_done_defer(xfer);
- mtx_unlock(xfer->usb2_mtx);
+ USB_BUS_UNLOCK(xfer->udev->bus);
return;
}
@@ -1594,7 +1592,7 @@ usb2_transfer_stop(struct usb2_xfer *xfer)
/* transfer is gone */
return;
}
- mtx_assert(xfer->priv_mtx, MA_OWNED);
+ USB_XFER_LOCK_ASSERT(xfer, MA_OWNED);
/* check if the USB transfer was ever opened */
@@ -1605,7 +1603,7 @@ usb2_transfer_stop(struct usb2_xfer *xfer)
}
/* try to stop the current USB transfer */
- mtx_lock(xfer->usb2_mtx);
+ USB_BUS_LOCK(xfer->udev->bus);
xfer->error = USB_ERR_CANCELLED;/* override any previous error */
/*
* Clear "open" and "started" when both private and USB lock
@@ -1657,7 +1655,7 @@ usb2_transfer_stop(struct usb2_xfer *xfer)
}
}
- mtx_unlock(xfer->usb2_mtx);
+ USB_BUS_UNLOCK(xfer->udev->bus);
return;
}
@@ -1676,16 +1674,16 @@ usb2_transfer_pending(struct usb2_xfer *xfer)
struct usb2_xfer_root *info;
struct usb2_xfer_queue *pq;
- mtx_assert(xfer->priv_mtx, MA_OWNED);
+ USB_XFER_LOCK_ASSERT(xfer, MA_OWNED);
if (xfer->flags_int.transferring) {
/* trivial case */
return (1);
}
- mtx_lock(xfer->usb2_mtx);
+ USB_BUS_LOCK(xfer->udev->bus);
if (xfer->wait_queue) {
/* we are waiting on a queue somewhere */
- mtx_unlock(xfer->usb2_mtx);
+ USB_BUS_UNLOCK(xfer->udev->bus);
return (1);
}
info = xfer->usb2_root;
@@ -1693,11 +1691,11 @@ usb2_transfer_pending(struct usb2_xfer *xfer)
if (pq->curr == xfer) {
/* we are currently scheduled for callback */
- mtx_unlock(xfer->usb2_mtx);
+ USB_BUS_UNLOCK(xfer->udev->bus);
return (1);
}
/* we are not pending */
- mtx_unlock(xfer->usb2_mtx);
+ USB_BUS_UNLOCK(xfer->udev->bus);
return (0);
}
@@ -1719,10 +1717,10 @@ usb2_transfer_drain(struct usb2_xfer *xfer)
/* transfer is gone */
return;
}
- if (xfer->priv_mtx != &Giant) {
- mtx_assert(xfer->priv_mtx, MA_NOTOWNED);
+ if (xfer->xfer_mtx != &Giant) {
+ USB_XFER_LOCK_ASSERT(xfer, MA_NOTOWNED);
}
- mtx_lock(xfer->priv_mtx);
+ USB_XFER_LOCK(xfer);
usb2_transfer_stop(xfer);
@@ -1732,9 +1730,9 @@ usb2_transfer_drain(struct usb2_xfer *xfer)
* Wait until the current outstanding USB
* transfer is complete !
*/
- usb2_cv_wait(&xfer->usb2_root->cv_drain, xfer->priv_mtx);
+ usb2_cv_wait(&xfer->usb2_root->cv_drain, xfer->xfer_mtx);
}
- mtx_unlock(xfer->priv_mtx);
+ USB_XFER_UNLOCK(xfer);
return;
}
@@ -1786,14 +1784,14 @@ usb2_callback_proc(struct usb2_proc_msg *_pm)
struct usb2_xfer_root *info = pm->usb2_root;
/* Change locking order */
- mtx_unlock(info->usb2_mtx);
+ USB_BUS_UNLOCK(info->bus);
/*
* We exploit the fact that the mutex is the same for all
* callbacks that will be called from this thread:
*/
mtx_lock(info->priv_mtx);
- mtx_lock(info->usb2_mtx);
+ USB_BUS_LOCK(info->bus);
/* Continue where we lost track */
usb2_command_wrapper(&info->done_q,
@@ -1815,9 +1813,8 @@ usb2_callback_ss_done_defer(struct usb2_xfer *xfer)
struct usb2_xfer_root *info = xfer->usb2_root;
struct usb2_xfer_queue *pq = &info->done_q;
- if (!mtx_owned(xfer->usb2_mtx)) {
- panic("%s: called unlocked!\n", __FUNCTION__);
- }
+ USB_BUS_LOCK_ASSERT(xfer->udev->bus, MA_OWNED);
+
if (pq->curr != xfer) {
usb2_transfer_enqueue(pq, xfer);
}
@@ -1854,10 +1851,8 @@ usb2_callback_wrapper(struct usb2_xfer_queue *pq)
struct usb2_xfer *xfer = pq->curr;
struct usb2_xfer_root *info = xfer->usb2_root;
- if (!mtx_owned(xfer->usb2_mtx)) {
- panic("%s: called unlocked!\n", __FUNCTION__);
- }
- if (!mtx_owned(xfer->priv_mtx)) {
+ USB_BUS_LOCK_ASSERT(xfer->udev->bus, MA_OWNED);
+ if (!mtx_owned(xfer->xfer_mtx)) {
/*
* Cases that end up here:
*
@@ -1888,22 +1883,22 @@ usb2_callback_wrapper(struct usb2_xfer_queue *pq)
/* get next USB transfer in the queue */
info->done_q.curr = NULL;
- mtx_unlock(xfer->usb2_mtx);
- mtx_assert(xfer->usb2_mtx, MA_NOTOWNED);
+ USB_BUS_UNLOCK(xfer->udev->bus);
+ USB_BUS_LOCK_ASSERT(xfer->udev->bus, MA_NOTOWNED);
/* set correct USB state for callback */
if (!xfer->flags_int.transferring) {
xfer->usb2_state = USB_ST_SETUP;
if (!xfer->flags_int.started) {
/* we got stopped before we even got started */
- mtx_lock(xfer->usb2_mtx);
+ USB_BUS_LOCK(xfer->udev->bus);
goto done;
}
} else {
if (usb2_callback_wrapper_sub(xfer)) {
/* the callback has been deferred */
- mtx_lock(xfer->usb2_mtx);
+ USB_BUS_LOCK(xfer->udev->bus);
goto done;
}
xfer->flags_int.transferring = 0;
@@ -1926,7 +1921,7 @@ usb2_callback_wrapper(struct usb2_xfer_queue *pq)
(xfer->callback) (xfer);
/* pickup the USB mutex again */
- mtx_lock(xfer->usb2_mtx);
+ USB_BUS_LOCK(xfer->udev->bus);
/*
* Check if we got started after that we got cancelled, but
@@ -1965,14 +1960,14 @@ usb2_dma_delay_done_cb(void *arg)
{
struct usb2_xfer *xfer = arg;
- mtx_assert(xfer->usb2_mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(xfer->udev->bus, MA_OWNED);
DPRINTFN(3, "Completed %p\n", xfer);
/* queue callback for execution, again */
usb2_transfer_done(xfer, 0);
- mtx_unlock(xfer->usb2_mtx);
+ USB_BUS_UNLOCK(xfer->udev->bus);
return;
}
@@ -2035,7 +2030,7 @@ usb2_transfer_done(struct usb2_xfer *xfer, usb2_error_t error)
{
struct usb2_xfer_queue *pq;
- mtx_assert(xfer->usb2_mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(xfer->udev->bus, MA_OWNED);
DPRINTF("err=%s\n", usb2_errstr(error));
@@ -2061,7 +2056,7 @@ usb2_transfer_done(struct usb2_xfer *xfer, usb2_error_t error)
*/
usb2_transfer_dequeue(xfer);
- if (mtx_owned(xfer->priv_mtx)) {
+ if (mtx_owned(xfer->xfer_mtx)) {
/*
* If the private USB lock is not locked, then we assume
* that the BUS-DMA load stage has been passed:
@@ -2100,7 +2095,7 @@ usb2_transfer_start_cb(void *arg)
struct usb2_xfer *xfer = arg;
struct usb2_pipe *pipe = xfer->pipe;
- mtx_assert(xfer->usb2_mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(xfer->udev->bus, MA_OWNED);
DPRINTF("start\n");
@@ -2117,7 +2112,7 @@ usb2_transfer_start_cb(void *arg)
} else {
xfer->flags_int.can_cancel_immed = 0;
}
- mtx_unlock(xfer->usb2_mtx);
+ USB_BUS_UNLOCK(xfer->udev->bus);
return;
}
@@ -2135,14 +2130,14 @@ usb2_transfer_set_stall(struct usb2_xfer *xfer)
/* tearing down */
return;
}
- mtx_assert(xfer->priv_mtx, MA_OWNED);
+ USB_XFER_LOCK_ASSERT(xfer, MA_OWNED);
/* avoid any races by locking the USB mutex */
- mtx_lock(xfer->usb2_mtx);
+ USB_BUS_LOCK(xfer->udev->bus);
xfer->flags.stall_pipe = 1;
- mtx_unlock(xfer->usb2_mtx);
+ USB_BUS_UNLOCK(xfer->udev->bus);
return;
}
@@ -2160,14 +2155,14 @@ usb2_transfer_clear_stall(struct usb2_xfer *xfer)
/* tearing down */
return;
}
- mtx_assert(xfer->priv_mtx, MA_OWNED);
+ USB_XFER_LOCK_ASSERT(xfer, MA_OWNED);
/* avoid any races by locking the USB mutex */
- mtx_lock(xfer->usb2_mtx);
+ USB_BUS_LOCK(xfer->udev->bus);
xfer->flags.stall_pipe = 0;
- mtx_unlock(xfer->usb2_mtx);
+ USB_BUS_UNLOCK(xfer->udev->bus);
return;
}
@@ -2187,7 +2182,7 @@ usb2_pipe_start(struct usb2_xfer_queue *pq)
xfer = pq->curr;
pipe = xfer->pipe;
- mtx_assert(xfer->usb2_mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(xfer->udev->bus, MA_OWNED);
/*
* If the pipe is already stalled we do nothing !
@@ -2290,7 +2285,7 @@ void
usb2_transfer_timeout_ms(struct usb2_xfer *xfer,
void (*cb) (void *arg), uint32_t ms)
{
- mtx_assert(xfer->usb2_mtx, MA_OWNED);
+ USB_BUS_LOCK_ASSERT(xfer->udev->bus, MA_OWNED);
/* defer delay */
usb2_callout_reset(&xfer->timeout_handle,
@@ -2324,9 +2319,9 @@ usb2_callback_wrapper_sub(struct usb2_xfer *xfer)
if ((!xfer->flags_int.open) &&
(!xfer->flags_int.did_close)) {
DPRINTF("close\n");
- mtx_lock(xfer->usb2_mtx);
+ USB_BUS_LOCK(xfer->udev->bus);
(xfer->pipe->methods->close) (xfer);
- mtx_unlock(xfer->usb2_mtx);
+ USB_BUS_UNLOCK(xfer->udev->bus);
/* only close once */
xfer->flags_int.did_close = 1;
return (1); /* wait for new callback */
@@ -2353,10 +2348,10 @@ usb2_callback_wrapper_sub(struct usb2_xfer *xfer)
"on %p\n", temp, xfer);
if (temp != 0) {
- mtx_lock(xfer->usb2_mtx);
+ USB_BUS_LOCK(xfer->udev->bus);
usb2_transfer_timeout_ms(xfer,
&usb2_dma_delay_done_cb, temp);
- mtx_unlock(xfer->usb2_mtx);
+ USB_BUS_UNLOCK(xfer->udev->bus);
return (1); /* wait for new callback */
}
}
@@ -2448,7 +2443,7 @@ usb2_callback_wrapper_sub(struct usb2_xfer *xfer)
* If the current USB transfer is completing we need to start the
* next one:
*/
- mtx_lock(xfer->usb2_mtx);
+ USB_BUS_LOCK(xfer->udev->bus);
if (pipe->pipe_q.curr == xfer) {
usb2_command_wrapper(&pipe->pipe_q, NULL);
@@ -2460,7 +2455,7 @@ usb2_callback_wrapper_sub(struct usb2_xfer *xfer)
xfer->pipe->is_synced = 0;
}
}
- mtx_unlock(xfer->usb2_mtx);
+ USB_BUS_UNLOCK(xfer->udev->bus);
done:
return (0);
}
@@ -2544,7 +2539,7 @@ repeat:
xfer = udev->default_xfer[0];
if (xfer) {
- mtx_lock(xfer->priv_mtx);
+ USB_XFER_LOCK(xfer);
no_resetup =
((xfer->address == udev->address) &&
(udev->default_ep_desc.wMaxPacketSize[0] ==
@@ -2559,7 +2554,7 @@ repeat:
usb2_transfer_start(xfer);
}
}
- mtx_unlock(xfer->priv_mtx);
+ USB_XFER_UNLOCK(xfer);
} else {
no_resetup = 0;
}
@@ -2609,9 +2604,9 @@ usb2_clear_data_toggle(struct usb2_device *udev, struct usb2_pipe *pipe)
{
DPRINTFN(5, "udev=%p pipe=%p\n", udev, pipe);
- mtx_lock(&udev->bus->mtx);
+ USB_BUS_LOCK(udev->bus);
pipe->toggle_next = 0;
- mtx_unlock(&udev->bus->mtx);
+ USB_BUS_UNLOCK(udev->bus);
return;
}
@@ -2655,8 +2650,8 @@ usb2_clear_stall_callback(struct usb2_xfer *xfer1,
DPRINTF("NULL input parameter\n");
return (0);
}
- mtx_assert(xfer1->priv_mtx, MA_OWNED);
- mtx_assert(xfer2->priv_mtx, MA_OWNED);
+ USB_XFER_LOCK_ASSERT(xfer1, MA_OWNED);
+ USB_XFER_LOCK_ASSERT(xfer2, MA_OWNED);
switch (USB_GET_STATE(xfer1)) {
case USB_ST_SETUP:
@@ -2786,15 +2781,15 @@ usb2_do_poll(struct usb2_xfer **ppxfer, uint16_t max)
* Poll hardware - signal that we are polling by
* locking the private mutex:
*/
- mtx_lock(xfer->priv_mtx);
+ USB_XFER_LOCK(xfer);
(udev->bus->methods->do_poll) (udev->bus);
- mtx_unlock(xfer->priv_mtx);
+ USB_XFER_UNLOCK(xfer);
/* poll clear stall start */
- mtx_lock(xfer->usb2_mtx);
+ USB_BUS_LOCK(xfer->udev->bus);
pm = &udev->cs_msg[0].hdr;
(pm->pm_callback) (pm);
- mtx_unlock(xfer->usb2_mtx);
+ USB_BUS_UNLOCK(xfer->udev->bus);
if (udev->default_xfer[1]) {
@@ -2802,20 +2797,20 @@ usb2_do_poll(struct usb2_xfer **ppxfer, uint16_t max)
usb2_callout_poll(udev->default_xfer[1]);
/* poll clear stall done thread */
- mtx_lock(xfer->usb2_mtx);
+ USB_BUS_LOCK(xfer->udev->bus);
pm = &udev->default_xfer[1]->
usb2_root->done_m[0].hdr;
(pm->pm_callback) (pm);
- mtx_unlock(xfer->usb2_mtx);
+ USB_BUS_UNLOCK(xfer->udev->bus);
}
/* poll timeout */
usb2_callout_poll(xfer);
/* poll done thread */
- mtx_lock(xfer->usb2_mtx);
+ USB_BUS_LOCK(xfer->udev->bus);
pm = &usb2_root->done_m[0].hdr;
(pm->pm_callback) (pm);
- mtx_unlock(xfer->usb2_mtx);
+ USB_BUS_UNLOCK(xfer->udev->bus);
}
}
return;
diff --git a/sys/dev/usb2/core/usb2_transfer.h b/sys/dev/usb2/core/usb2_transfer.h
index 83920e5..9564477 100644
--- a/sys/dev/usb2/core/usb2_transfer.h
+++ b/sys/dev/usb2/core/usb2_transfer.h
@@ -52,7 +52,6 @@ struct usb2_xfer_root {
struct usb2_process done_p;
void *memory_base;
struct mtx *priv_mtx;
- struct mtx *usb2_mtx;
struct usb2_page_cache *dma_page_cache_start;
struct usb2_page_cache *dma_page_cache_end;
struct usb2_page_cache *xfer_page_cache_start;
diff --git a/sys/dev/usb2/serial/uvscom2.c b/sys/dev/usb2/serial/uvscom2.c
index 96e3c72..33b24b5 100644
--- a/sys/dev/usb2/serial/uvscom2.c
+++ b/sys/dev/usb2/serial/uvscom2.c
@@ -340,9 +340,9 @@ uvscom_attach(device_t dev)
goto detach;
}
/* start interrupt pipe */
- mtx_lock(sc->sc_xfer[4]->priv_mtx);
+ USB_XFER_LOCK(sc->sc_xfer[4]);
usb2_transfer_start(sc->sc_xfer[4]);
- mtx_unlock(sc->sc_xfer[4]->priv_mtx);
+ USB_XFER_UNLOCK(sc->sc_xfer[4]);
return (0);
diff --git a/sys/dev/usb2/storage/ata-usb2.c b/sys/dev/usb2/storage/ata-usb2.c
index 17a63c6..66fd143 100644
--- a/sys/dev/usb2/storage/ata-usb2.c
+++ b/sys/dev/usb2/storage/ata-usb2.c
@@ -778,11 +778,11 @@ atausb2_t_bbb_status_callback(struct usb2_xfer *xfer)
sc->ata_request = NULL;
- mtx_unlock(xfer->priv_mtx);
+ USB_XFER_UNLOCK(xfer);
ata_interrupt(device_get_softc(request->parent));
- mtx_lock(xfer->priv_mtx);
+ USB_XFER_LOCK(xfer);
return;
case USB_ST_SETUP:
OpenPOWER on IntegriCloud