summaryrefslogtreecommitdiff
path: root/sys/dev/ic
diff options
context:
space:
mode:
authorad <ad@NetBSD.org>2007-10-08 16:50:45 +0000
committerad <ad@NetBSD.org>2007-10-08 16:50:45 +0000
commitbe0770a43374dc03eadf5850f4d649558c4a42e7 (patch)
treec7b7a920af799447840f71598e374c36c0634439 /sys/dev/ic
parent2af68666dab8e157d373e74302f79828452ee8df (diff)
Merge from vmlocking: use mutexes and the softint API.
Diffstat (limited to 'sys/dev/ic')
-rw-r--r--sys/dev/ic/com.c130
-rw-r--r--sys/dev/ic/comvar.h13
2 files changed, 57 insertions, 86 deletions
diff --git a/sys/dev/ic/com.c b/sys/dev/ic/com.c
index 5d0c601bf6b..f0380f93367 100644
--- a/sys/dev/ic/com.c
+++ b/sys/dev/ic/com.c
@@ -1,4 +1,4 @@
-/* $NetBSD: com.c,v 1.262 2007/08/16 08:56:49 martin Exp $ */
+/* $NetBSD: com.c,v 1.263 2007/10/08 16:50:45 ad Exp $ */
/*-
* Copyright (c) 1998, 1999, 2004 The NetBSD Foundation, Inc.
@@ -73,7 +73,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: com.c,v 1.262 2007/08/16 08:56:49 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: com.c,v 1.263 2007/10/08 16:50:45 ad Exp $");
#include "opt_com.h"
#include "opt_ddb.h"
@@ -122,8 +122,8 @@ __KERNEL_RCSID(0, "$NetBSD: com.c,v 1.262 2007/08/16 08:56:49 martin Exp $");
#include <sys/timepps.h>
#include <sys/vnode.h>
#include <sys/kauth.h>
+#include <sys/intr.h>
-#include <machine/intr.h>
#include <machine/bus.h>
#include <dev/ic/comreg.h>
@@ -191,7 +191,6 @@ void comcnpollc(dev_t, int);
#define integrate static inline
void comsoft(void *);
-
integrate void com_rxsoft(struct com_softc *, struct tty *);
integrate void com_txsoft(struct com_softc *, struct tty *);
integrate void com_stsoft(struct com_softc *, struct tty *);
@@ -271,9 +270,6 @@ const bus_size_t com_std_map[16] = COM_REG_16550;
#define COM_BARRIER(r, f) \
bus_space_barrier((r)->cr_iot, (r)->cr_ioh, 0, (r)->cr_nports, (f))
-#define COM_LOCK(sc) simple_lock(&(sc)->sc_lock)
-#define COM_UNLOCK(sc) simple_unlock(&(sc)->sc_lock)
-
/*ARGSUSED*/
int
comspeed(long speed, long frequency, int type)
@@ -359,13 +355,16 @@ comprobe1(bus_space_tag_t iot, bus_space_handle_t ioh)
static void
com_enable_debugport(struct com_softc *sc)
{
+
/* Turn on line break interrupt, set carrier. */
+ mutex_spin_enter(&sc->sc_lock);
sc->sc_ier = IER_ERXRDY;
if (sc->sc_type == COM_TYPE_PXA2x0)
sc->sc_ier |= IER_EUART | IER_ERXTOUT;
CSR_WRITE_1(&sc->sc_regs, COM_REG_IER, sc->sc_ier);
SET(sc->sc_mcr, MCR_DTR | MCR_RTS);
CSR_WRITE_1(&sc->sc_regs, COM_REG_MCR, sc->sc_mcr);
+ mutex_spin_exit(&sc->sc_lock);
}
void
@@ -381,7 +380,7 @@ com_attach_subr(struct com_softc *sc)
aprint_naive("\n");
callout_init(&sc->sc_diag_callout, 0);
- simple_lock_init(&sc->sc_lock);
+ mutex_init(&sc->sc_lock, MUTEX_SPIN, IPL_SERIAL);
/* Disable interrupts before configuring the device. */
if (sc->sc_type == COM_TYPE_PXA2x0)
@@ -534,7 +533,7 @@ fifodone:
}
#endif
- sc->sc_si = softintr_establish(IPL_SOFTSERIAL, comsoft, sc);
+ sc->sc_si = softint_establish(SOFTINT_SERIAL, comsoft, sc);
#if NRND > 0 && defined(RND_COM)
rnd_attach_source(&sc->rnd_source, sc->sc_dev.dv_xname,
@@ -644,7 +643,7 @@ com_detach(struct device *self, int flags)
ttyfree(sc->sc_tty);
/* Unhook the soft interrupt handler. */
- softintr_disestablish(sc->sc_si);
+ softint_disestablish(sc->sc_si);
#if NRND > 0 && defined(RND_COM)
/* Unhook the entropy source. */
@@ -658,10 +657,9 @@ int
com_activate(struct device *self, enum devact act)
{
struct com_softc *sc = (struct com_softc *)self;
- int s, rv = 0;
+ int rv = 0;
- s = splserial();
- COM_LOCK(sc);
+ mutex_spin_enter(&sc->sc_lock);
switch (act) {
case DVACT_ACTIVATE:
rv = EOPNOTSUPP;
@@ -680,8 +678,7 @@ com_activate(struct device *self, enum devact act)
break;
}
- COM_UNLOCK(sc);
- splx(s);
+ mutex_spin_exit(&sc->sc_lock);
return (rv);
}
@@ -689,10 +686,8 @@ void
com_shutdown(struct com_softc *sc)
{
struct tty *tp = sc->sc_tty;
- int s;
- s = splserial();
- COM_LOCK(sc);
+ mutex_spin_enter(&sc->sc_lock);
/* If we were asserting flow control, then deassert it. */
SET(sc->sc_rx_flags, RX_IBUF_BLOCKED);
@@ -714,12 +709,10 @@ com_shutdown(struct com_softc *sc)
*/
if (ISSET(tp->t_cflag, HUPCL)) {
com_modem(sc, 0);
- COM_UNLOCK(sc);
- splx(s);
- /* XXX tsleep will only timeout */
- (void) tsleep(sc, TTIPRI, ttclos, hz);
- s = splserial();
- COM_LOCK(sc);
+ mutex_spin_exit(&sc->sc_lock);
+ /* XXX will only timeout */
+ (void) kpause(ttclos, false, hz, NULL);
+ mutex_spin_enter(&sc->sc_lock);
}
/* Turn off interrupts. */
@@ -743,8 +736,7 @@ com_shutdown(struct com_softc *sc)
(*sc->disable)(sc);
sc->enabled = 0;
}
- COM_UNLOCK(sc);
- splx(s);
+ mutex_spin_exit(&sc->sc_lock);
}
int
@@ -752,7 +744,7 @@ comopen(dev_t dev, int flag, int mode, struct lwp *l)
{
struct com_softc *sc;
struct tty *tp;
- int s, s2;
+ int s;
int error;
sc = device_lookup(&com_cd, COMUNIT(dev));
@@ -786,13 +778,11 @@ comopen(dev_t dev, int flag, int mode, struct lwp *l)
tp->t_dev = dev;
- s2 = splserial();
- COM_LOCK(sc);
+ mutex_spin_enter(&sc->sc_lock);
if (sc->enable) {
if ((*sc->enable)(sc)) {
- COM_UNLOCK(sc);
- splx(s2);
+ mutex_spin_exit(&sc->sc_lock);
splx(s);
printf("%s: device enable failed\n",
sc->sc_dev.dv_xname);
@@ -821,8 +811,7 @@ comopen(dev_t dev, int flag, int mode, struct lwp *l)
sc->ppsparam.mode = 0;
#endif /* !__HAVE_TIMECOUNTER */
- COM_UNLOCK(sc);
- splx(s2);
+ mutex_spin_exit(&sc->sc_lock);
/*
* Initialize the termios status to the defaults. Add in the
@@ -851,8 +840,7 @@ comopen(dev_t dev, int flag, int mode, struct lwp *l)
ttychars(tp);
ttsetwater(tp);
- s2 = splserial();
- COM_LOCK(sc);
+ mutex_spin_enter(&sc->sc_lock);
/*
* Turn on DTR. We must always do this, even if carrier is not
@@ -875,8 +863,7 @@ comopen(dev_t dev, int flag, int mode, struct lwp *l)
comstatus(sc, "comopen ");
#endif
- COM_UNLOCK(sc);
- splx(s2);
+ mutex_spin_exit(&sc->sc_lock);
}
splx(s);
@@ -982,7 +969,6 @@ comioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
struct com_softc *sc = device_lookup(&com_cd, COMUNIT(dev));
struct tty *tp = sc->sc_tty;
int error;
- int s;
if (COM_ISALIVE(sc) == 0)
return (EIO);
@@ -1009,8 +995,7 @@ comioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
return error;
}
- s = splserial();
- COM_LOCK(sc);
+ mutex_spin_enter(&sc->sc_lock);
switch (cmd) {
case TIOCSBRK:
@@ -1189,8 +1174,7 @@ comioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
break;
}
- COM_UNLOCK(sc);
- splx(s);
+ mutex_spin_exit(&sc->sc_lock);
#ifdef COM_DEBUG
if (com_debug)
@@ -1207,7 +1191,7 @@ com_schedrx(struct com_softc *sc)
sc->sc_rx_ready = 1;
/* Wake up the poller. */
- softintr_schedule(sc->sc_si);
+ softint_schedule(sc->sc_si);
}
void
@@ -1351,7 +1335,6 @@ comparam(struct tty *tp, struct termios *t)
struct com_softc *sc = device_lookup(&com_cd, COMUNIT(tp->t_dev));
int ospeed;
u_char lcr;
- int s;
if (COM_ISALIVE(sc) == 0)
return (EIO);
@@ -1404,8 +1387,7 @@ comparam(struct tty *tp, struct termios *t)
lcr = ISSET(sc->sc_lcr, LCR_SBREAK) | cflag2lcr(t->c_cflag);
- s = splserial();
- COM_LOCK(sc);
+ mutex_spin_enter(&sc->sc_lock);
sc->sc_lcr = lcr;
@@ -1510,8 +1492,7 @@ comparam(struct tty *tp, struct termios *t)
sc->sc_r_lowat = com_rbuf_lowat;
}
- COM_UNLOCK(sc);
- splx(s);
+ mutex_spin_exit(&sc->sc_lock);
/*
* Update the tty layer's idea of the carrier bit, in case we changed
@@ -1611,7 +1592,6 @@ int
comhwiflow(struct tty *tp, int block)
{
struct com_softc *sc = device_lookup(&com_cd, COMUNIT(tp->t_dev));
- int s;
if (COM_ISALIVE(sc) == 0)
return (0);
@@ -1619,8 +1599,7 @@ comhwiflow(struct tty *tp, int block)
if (sc->sc_mcr_rts == 0)
return (0);
- s = splserial();
- COM_LOCK(sc);
+ mutex_spin_enter(&sc->sc_lock);
if (block) {
if (!ISSET(sc->sc_rx_flags, RX_TTY_BLOCKED)) {
@@ -1638,8 +1617,7 @@ comhwiflow(struct tty *tp, int block)
}
}
- COM_UNLOCK(sc);
- splx(s);
+ mutex_spin_exit(&sc->sc_lock);
return (1);
}
@@ -1699,8 +1677,7 @@ comstart(struct tty *tp)
tba = tp->t_outq.c_cf;
tbc = ndqb(&tp->t_outq, 0);
- (void)splserial();
- COM_LOCK(sc);
+ mutex_spin_enter(&sc->sc_lock);
sc->sc_tba = tba;
sc->sc_tbc = tbc;
@@ -1727,7 +1704,7 @@ comstart(struct tty *tp)
sc->sc_tba += n;
}
- COM_UNLOCK(sc);
+ mutex_spin_exit(&sc->sc_lock);
out:
splx(s);
return;
@@ -1740,10 +1717,8 @@ void
comstop(struct tty *tp, int flag)
{
struct com_softc *sc = device_lookup(&com_cd, COMUNIT(tp->t_dev));
- int s;
- s = splserial();
- COM_LOCK(sc);
+ mutex_spin_enter(&sc->sc_lock);
if (ISSET(tp->t_state, TS_BUSY)) {
/* Stop transmitting at the next chunk. */
sc->sc_tbc = 0;
@@ -1751,8 +1726,7 @@ comstop(struct tty *tp, int flag)
if (!ISSET(tp->t_state, TS_TTSTOP))
SET(tp->t_state, TS_FLUSH);
}
- COM_UNLOCK(sc);
- splx(s);
+ mutex_spin_exit(&sc->sc_lock);
}
void
@@ -1760,17 +1734,14 @@ comdiag(void *arg)
{
struct com_softc *sc = arg;
int overflows, floods;
- int s;
- s = splserial();
- COM_LOCK(sc);
+ mutex_spin_enter(&sc->sc_lock);
overflows = sc->sc_overflows;
sc->sc_overflows = 0;
floods = sc->sc_floods;
sc->sc_floods = 0;
sc->sc_errors = 0;
- COM_UNLOCK(sc);
- splx(s);
+ mutex_spin_exit(&sc->sc_lock);
log(LOG_WARNING, "%s: %d silo overflow%s, %d ibuf flood%s\n",
sc->sc_dev.dv_xname,
@@ -1786,7 +1757,6 @@ com_rxsoft(struct com_softc *sc, struct tty *tp)
u_int cc, scc;
u_char lsr;
int code;
- int s;
end = sc->sc_ebuf;
get = sc->sc_rbget;
@@ -1857,8 +1827,7 @@ com_rxsoft(struct com_softc *sc, struct tty *tp)
if (cc != scc) {
sc->sc_rbget = get;
- s = splserial();
- COM_LOCK(sc);
+ mutex_spin_enter(&sc->sc_lock);
cc = sc->sc_rbavail += scc - cc;
/* Buffers should be ok again, release possible block. */
@@ -1877,8 +1846,7 @@ com_rxsoft(struct com_softc *sc, struct tty *tp)
com_hwiflow(sc);
}
}
- COM_UNLOCK(sc);
- splx(s);
+ mutex_spin_exit(&sc->sc_lock);
}
}
@@ -1898,15 +1866,12 @@ integrate void
com_stsoft(struct com_softc *sc, struct tty *tp)
{
u_char msr, delta;
- int s;
- s = splserial();
- COM_LOCK(sc);
+ mutex_spin_enter(&sc->sc_lock);
msr = sc->sc_msr;
delta = sc->sc_msr_delta;
sc->sc_msr_delta = 0;
- COM_UNLOCK(sc);
- splx(s);
+ mutex_spin_exit(&sc->sc_lock);
if (ISSET(delta, sc->sc_msr_dcd)) {
/*
@@ -1971,10 +1936,10 @@ comintr(void *arg)
if (COM_ISALIVE(sc) == 0)
return (0);
- COM_LOCK(sc);
+ mutex_spin_enter(&sc->sc_lock);
iir = CSR_READ_1(regsp, COM_REG_IIR);
if (ISSET(iir, IIR_NOPEND)) {
- COM_UNLOCK(sc);
+ mutex_spin_exit(&sc->sc_lock);
return (0);
}
@@ -2204,10 +2169,10 @@ again: do {
if (!ISSET((iir = CSR_READ_1(regsp, COM_REG_IIR)), IIR_NOPEND))
goto again;
- COM_UNLOCK(sc);
+ mutex_spin_exit(&sc->sc_lock);
/* Wake up the poller. */
- softintr_schedule(sc->sc_si);
+ softint_schedule(sc->sc_si);
#if NRND > 0 && defined(RND_COM)
rnd_add_uint32(&sc->rnd_source, iir | lsr);
@@ -2509,9 +2474,8 @@ void
com_power(int why, void *arg)
{
struct com_softc *sc = arg;
- int s;
- s = splserial();
+ mutex_spin_enter(&sc->sc_lock);
switch (why) {
case PWR_SUSPEND:
case PWR_STANDBY:
@@ -2525,5 +2489,5 @@ com_power(int why, void *arg)
case PWR_SOFTRESUME:
break;
}
- splx(s);
+ mutex_spin_exit(&sc->sc_lock);
}
diff --git a/sys/dev/ic/comvar.h b/sys/dev/ic/comvar.h
index a3df5c77b8b..0a7c55ac8bb 100644
--- a/sys/dev/ic/comvar.h
+++ b/sys/dev/ic/comvar.h
@@ -1,4 +1,4 @@
-/* $NetBSD: comvar.h,v 1.55 2007/07/14 21:02:37 ad Exp $ */
+/* $NetBSD: comvar.h,v 1.56 2007/10/08 16:50:45 ad Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
@@ -42,7 +42,7 @@
#include <sys/callout.h>
#include <sys/timepps.h>
-#include <sys/lock.h>
+#include <sys/mutex.h>
#include <dev/ic/comreg.h> /* for COM_NPORTS */
@@ -221,7 +221,7 @@ struct com_softc {
rndsource_element_t rnd_source;
#endif
void *sc_powerhook; /* power management hook */
- struct simplelock sc_lock;
+ kmutex_t sc_lock;
};
int comprobe1(bus_space_tag_t, bus_space_handle_t);
@@ -231,3 +231,10 @@ int com_probe_subr(struct com_regs *);
int com_detach(struct device *, int);
int com_activate(struct device *, enum devact);
void com_cleanup(void *);
+
+#ifdef __NO_SOFT_SERIAL_INTERRUPT
+#define IPL_SERIAL IPL_TTY
+#define splserial() spltty()
+#define IPL_SOFTSERIAL IPL_TTY
+#define splsoftserial() spltty()
+#endif