diff options
author | marcel <marcel@FreeBSD.org> | 2003-09-17 01:41:21 +0000 |
---|---|---|
committer | marcel <marcel@FreeBSD.org> | 2003-09-17 01:41:21 +0000 |
commit | 96dbeb7199a05e6fb1bc00cdfcd8727467423d09 (patch) | |
tree | 976d5fcb92d42c5763ac054fcd83a3a3ba593d98 /sys/dev/uart/uart_dev_sab82532.c | |
parent | 25d51778fc93c3659f92b88183b9b4f4814bc3f4 (diff) | |
download | FreeBSD-src-96dbeb7199a05e6fb1bc00cdfcd8727467423d09.zip FreeBSD-src-96dbeb7199a05e6fb1bc00cdfcd8727467423d09.tar.gz |
Add locking to the hardware drivers. I intended to figure out more
precisely where locking would be needed before adding it, but it
seems uart(4) draws slightly too much attention to have it without
locking for too long.
The lock added is a spinlock that protects access to the underlying
hardware. As a first and obvious stab at this, each method of the
hardware interface grabs the lock. Roughly speaking this serializes
the methods. Exceptions are the probe, attach and detach methods.
Diffstat (limited to 'sys/dev/uart/uart_dev_sab82532.c')
-rw-r--r-- | sys/dev/uart/uart_dev_sab82532.c | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/sys/dev/uart/uart_dev_sab82532.c b/sys/dev/uart/uart_dev_sab82532.c index 5345e97..ec1c9f5 100644 --- a/sys/dev/uart/uart_dev_sab82532.c +++ b/sys/dev/uart/uart_dev_sab82532.c @@ -425,7 +425,9 @@ static int sab82532_bus_flush(struct uart_softc *sc, int what) { + mtx_lock_spin(&sc->sc_hwmtx); sab82532_flush(&sc->sc_bas, what); + mtx_unlock_spin(&sc->sc_hwmtx); return (0); } @@ -440,6 +442,7 @@ sab82532_bus_getsig(struct uart_softc *sc) do { old = sc->sc_hwsig; sig = old; + mtx_lock_spin(&sc->sc_hwmtx); star = uart_getreg(bas, SAB_STAR); SIGCHG(star & SAB_STAR_CTS, sig, UART_SIG_CTS, UART_SIG_DCTS); vstr = uart_getreg(bas, SAB_VSTR); @@ -447,6 +450,7 @@ sab82532_bus_getsig(struct uart_softc *sc) pvr = uart_getreg(bas, SAB_PVR); pvr &= (IS_CHANNEL_A(bas)) ? SAB_PVR_DSR_A : SAB_PVR_DSR_B; SIGCHG(~pvr, sig, UART_SIG_DSR, UART_SIG_DDSR); + mtx_unlock_spin(&sc->sc_hwmtx); new = sig & ~UART_SIGMASK_DELTA; } while (!atomic_cmpset_32(&sc->sc_hwsig, old, new)); return (sig); @@ -457,8 +461,11 @@ sab82532_bus_ioctl(struct uart_softc *sc, int request, intptr_t data) { struct uart_bas *bas; uint8_t dafo, mode; + int error; bas = &sc->sc_bas; + error = 0; + mtx_lock_spin(&sc->sc_hwmtx); switch (request) { case UART_IOCTL_BREAK: dafo = uart_getreg(bas, SAB_DAFO); @@ -491,9 +498,11 @@ sab82532_bus_ioctl(struct uart_softc *sc, int request, intptr_t data) uart_barrier(bas); break; default: - return (EINVAL); + error = EINVAL; + break; } - return (0); + mtx_unlock_spin(&sc->sc_hwmtx); + return (error); } static int @@ -504,16 +513,17 @@ sab82532_bus_ipend(struct uart_softc *sc) uint8_t isr0, isr1; bas = &sc->sc_bas; + mtx_lock_spin(&sc->sc_hwmtx); isr0 = uart_getreg(bas, SAB_ISR0); isr1 = uart_getreg(bas, SAB_ISR1); uart_barrier(bas); - if (isr0 & SAB_ISR0_TIME) { while (uart_getreg(bas, SAB_STAR) & SAB_STAR_CEC) ; uart_setreg(bas, SAB_CMDR, SAB_CMDR_RFRD); uart_barrier(bas); } + mtx_unlock_spin(&sc->sc_hwmtx); ipend = 0; if (isr1 & SAB_ISR1_BRKT) @@ -535,9 +545,13 @@ sab82532_bus_param(struct uart_softc *sc, int baudrate, int databits, int stopbits, int parity) { struct uart_bas *bas; + int error; bas = &sc->sc_bas; - return (sab82532_param(bas, baudrate, databits, stopbits, parity)); + mtx_lock_spin(&sc->sc_hwmtx); + error = sab82532_param(bas, baudrate, databits, stopbits, parity); + mtx_unlock_spin(&sc->sc_hwmtx); + return (error); } static int @@ -584,6 +598,7 @@ sab82532_bus_receive(struct uart_softc *sc) uint8_t s; bas = &sc->sc_bas; + mtx_lock_spin(&sc->sc_hwmtx); if (uart_getreg(bas, SAB_STAR) & SAB_STAR_RFNE) { rbcl = uart_getreg(bas, SAB_RBCL) & 31; if (rbcl == 0) @@ -607,6 +622,7 @@ sab82532_bus_receive(struct uart_softc *sc) ; uart_setreg(bas, SAB_CMDR, SAB_CMDR_RMC); uart_barrier(bas); + mtx_unlock_spin(&sc->sc_hwmtx); return (0); } @@ -631,6 +647,7 @@ sab82532_bus_setsig(struct uart_softc *sc, int sig) } } while (!atomic_cmpset_32(&sc->sc_hwsig, old, new)); + mtx_lock_spin(&sc->sc_hwmtx); /* Set DTR pin. */ pvr = uart_getreg(bas, SAB_PVR); if (new & UART_SIG_DTR) @@ -647,6 +664,7 @@ sab82532_bus_setsig(struct uart_softc *sc, int sig) mode |= SAB_MODE_FRTS; uart_setreg(bas, SAB_MODE, mode); uart_barrier(bas); + mtx_unlock_spin(&sc->sc_hwmtx); return (0); } @@ -657,6 +675,7 @@ sab82532_bus_transmit(struct uart_softc *sc) int i; bas = &sc->sc_bas; + mtx_lock_spin(&sc->sc_hwmtx); while (!(uart_getreg(bas, SAB_STAR) & SAB_STAR_XFW)) ; for (i = 0; i < sc->sc_txdatasz; i++) @@ -666,5 +685,6 @@ sab82532_bus_transmit(struct uart_softc *sc) ; uart_setreg(bas, SAB_CMDR, SAB_CMDR_XF); sc->sc_txbusy = 1; + mtx_unlock_spin(&sc->sc_hwmtx); return (0); } |