diff options
| author | riastradh <riastradh@NetBSD.org> | 2022-03-13 11:30:04 +0000 |
|---|---|---|
| committer | riastradh <riastradh@NetBSD.org> | 2022-03-13 11:30:04 +0000 |
| commit | 7d7eb7b1d0cac6ba3bcd892121f577ec2653cb45 (patch) | |
| tree | 28bde3742f2fdb95b4fa695ff8007c2a16d2bc82 /sys/dev | |
| parent | 314e71baae9f5838556237539fa79bceb0366fa5 (diff) | |
xhci(4): Serialize access to portsc registers.
Both xhci_roothub_ctrl and xhci_suspend/resume do r/m/w on them, so
use a mutex to serialize access to avoid stomping on each other.
Diffstat (limited to 'sys/dev')
| -rw-r--r-- | sys/dev/usb/xhci.c | 41 | ||||
| -rw-r--r-- | sys/dev/usb/xhcivar.h | 3 |
2 files changed, 38 insertions, 6 deletions
diff --git a/sys/dev/usb/xhci.c b/sys/dev/usb/xhci.c index e4bad1e9ac9..159ffbb9c8a 100644 --- a/sys/dev/usb/xhci.c +++ b/sys/dev/usb/xhci.c @@ -1,4 +1,4 @@ -/* $NetBSD: xhci.c,v 1.161 2022/03/13 11:29:55 riastradh Exp $ */ +/* $NetBSD: xhci.c,v 1.162 2022/03/13 11:30:04 riastradh Exp $ */ /* * Copyright (c) 2013 Jonathan A. Kollasch @@ -34,7 +34,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.161 2022/03/13 11:29:55 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.162 2022/03/13 11:30:04 riastradh Exp $"); #ifdef _KERNEL_OPT #include "opt_usb.h" @@ -709,6 +709,12 @@ xhci_suspend(device_t self, const pmf_qual_t *qual) mutex_exit(&sc->sc_lock); /* + * Block roothub xfers which might touch portsc registers until + * we're done suspending. + */ + mutex_enter(&sc->sc_rhlock); + + /* * xHCI Requirements Specification 1.2, May 2019, Sec. 4.23.2: * xHCI Power Management, p. 342 * https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/extensible-host-controler-interface-usb-xhci.pdf#page=342 @@ -889,7 +895,8 @@ xhci_suspend(device_t self, const pmf_qual_t *qual) /* Success! */ ok = true; -out: return ok; +out: mutex_exit(&sc->sc_rhlock); + return ok; } bool @@ -906,6 +913,12 @@ xhci_resume(device_t self, const pmf_qual_t *qual) KASSERT(sc->sc_suspender); /* + * Block roothub xfers which might touch portsc registers until + * we're done resuming. + */ + mutex_enter(&sc->sc_rhlock); + + /* * xHCI Requirements Specification 1.2, May 2019, Sec. 4.23.2: * xHCI Power Management, p. 343 * https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/extensible-host-controler-interface-usb-xhci.pdf#page=343 @@ -1089,7 +1102,8 @@ xhci_resume(device_t self, const pmf_qual_t *qual) /* Success! */ ok = true; -out: return ok; +out: mutex_exit(&sc->sc_rhlock); + return ok; } bool @@ -1591,6 +1605,7 @@ xhci_init(struct xhci_softc *sc) cv_init(&sc->sc_command_cv, "xhcicmd"); cv_init(&sc->sc_cmdbusy_cv, "xhcicmdq"); + mutex_init(&sc->sc_rhlock, MUTEX_DEFAULT, IPL_NONE); mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_SOFTUSB); mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_USB); @@ -3863,7 +3878,7 @@ xhci_noop(struct usbd_pipe *pipe) * Process root hub request. */ static int -xhci_roothub_ctrl(struct usbd_bus *bus, usb_device_request_t *req, +xhci_roothub_ctrl_locked(struct usbd_bus *bus, usb_device_request_t *req, void *buf, int buflen) { struct xhci_softc * const sc = XHCI_BUS2SC(bus); @@ -3875,6 +3890,8 @@ xhci_roothub_ctrl(struct usbd_bus *bus, usb_device_request_t *req, XHCIHIST_FUNC(); + KASSERT(mutex_owned(&sc->sc_rhlock)); + if (sc->sc_dying) return -1; @@ -4127,6 +4144,20 @@ xhci_roothub_ctrl(struct usbd_bus *bus, usb_device_request_t *req, return totlen; } +static int +xhci_roothub_ctrl(struct usbd_bus *bus, usb_device_request_t *req, + void *buf, int buflen) +{ + struct xhci_softc *sc = XHCI_BUS2SC(bus); + int actlen; + + mutex_enter(&sc->sc_rhlock); + actlen = xhci_roothub_ctrl_locked(bus, req, buf, buflen); + mutex_exit(&sc->sc_rhlock); + + return actlen; +} + /* root hub interrupt */ static usbd_status diff --git a/sys/dev/usb/xhcivar.h b/sys/dev/usb/xhcivar.h index e2191f07170..f5380e3c830 100644 --- a/sys/dev/usb/xhcivar.h +++ b/sys/dev/usb/xhcivar.h @@ -1,4 +1,4 @@ -/* $NetBSD: xhcivar.h,v 1.20 2022/03/03 06:09:03 riastradh Exp $ */ +/* $NetBSD: xhcivar.h,v 1.21 2022/03/13 11:30:04 riastradh Exp $ */ /* * Copyright (c) 2013 Jonathan A. Kollasch @@ -96,6 +96,7 @@ struct xhci_softc { struct usbd_bus sc_bus; /* USB 3 bus */ struct usbd_bus sc_bus2; /* USB 2 bus */ + kmutex_t sc_rhlock; kmutex_t sc_lock; kmutex_t sc_intr_lock; |
