Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/evbarm/dev Replace the simple_lock with a kmutex_t....



details:   https://anonhg.NetBSD.org/src/rev/5d9550a8fdbe
branches:  trunk
changeset: 779334:5d9550a8fdbe
user:      skrll <skrll%NetBSD.org@localhost>
date:      Sun May 20 07:54:40 2012 +0000

description:
Replace the simple_lock with a kmutex_t.  Update the locking to match
com(4) in the few places it didn't already.

diffstat:

 sys/arch/evbarm/dev/plcom.c    |  122 ++++++++++++++--------------------------
 sys/arch/evbarm/dev/plcomvar.h |    4 +-
 2 files changed, 45 insertions(+), 81 deletions(-)

diffs (truncated from 423 to 300 lines):

diff -r 3b06fc4d6f36 -r 5d9550a8fdbe sys/arch/evbarm/dev/plcom.c
--- a/sys/arch/evbarm/dev/plcom.c       Sun May 20 06:17:28 2012 +0000
+++ b/sys/arch/evbarm/dev/plcom.c       Sun May 20 07:54:40 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: plcom.c,v 1.35 2012/05/14 19:40:06 skrll Exp $ */
+/*     $NetBSD: plcom.c,v 1.36 2012/05/20 07:54:40 skrll Exp $ */
 
 /*-
  * Copyright (c) 2001 ARM Ltd
@@ -94,7 +94,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: plcom.c,v 1.35 2012/05/14 19:40:06 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: plcom.c,v 1.36 2012/05/20 07:54:40 skrll Exp $");
 
 #include "opt_plcom.h"
 #include "opt_ddb.h"
@@ -248,9 +248,6 @@
 #define        BW      BUS_SPACE_BARRIER_WRITE
 #define PLCOM_BARRIER(t, h, f) bus_space_barrier((t), (h), 0, PLCOM_UART_SIZE, (f))
 
-#define PLCOM_LOCK(sc) simple_lock(&(sc)->sc_lock)
-#define PLCOM_UNLOCK(sc) simple_unlock(&(sc)->sc_lock)
-
 int
 plcomspeed(long speed, long frequency)
 {
@@ -331,22 +328,21 @@
        return 1;
 }
 
+/*
+ * No locking in this routine; it is only called during attach,
+ * or with the port already locked.
+ */
 static void
 plcom_enable_debugport(struct plcom_softc *sc)
 {
-       int s;
 
        /* Turn on line break interrupt, set carrier. */
-       s = splserial();
-       PLCOM_LOCK(sc);
        sc->sc_cr = PL010_CR_RIE | PL010_CR_RTIE | PL01X_CR_UARTEN;
        bus_space_write_1(sc->sc_iot, sc->sc_ioh, plcom_cr, sc->sc_cr);
        SET(sc->sc_mcr, PL01X_MCR_DTR | PL01X_MCR_RTS);
        /* XXX device_unit() abuse */
        sc->sc_set_mcr(sc->sc_set_mcr_arg, device_unit(&sc->sc_dev),
            sc->sc_mcr);
-       PLCOM_UNLOCK(sc);
-       splx(s);
 }
 
 void
@@ -358,7 +354,7 @@
        struct tty *tp;
 
        callout_init(&sc->sc_diag_callout, 0);
-       simple_lock_init(&sc->sc_lock);
+       mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_HIGH);
 
        /* Disable interrupts before configuring the device. */
        sc->sc_cr = 0;
@@ -505,6 +501,9 @@
        rnd_detach_source(&sc->rnd_source);
 #endif
 
+       /* Destroy the lock. */
+       mutex_destroy(&sc->sc_lock);
+
        return 0;
 }
 
@@ -526,10 +525,7 @@
 plcom_shutdown(struct plcom_softc *sc)
 {
        struct tty *tp = sc->sc_tty;
-       int s;
-
-       s = splserial();
-       PLCOM_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);
@@ -551,12 +547,10 @@
         */
        if (ISSET(tp->t_cflag, HUPCL)) {
                plcom_modem(sc, 0);
-               PLCOM_UNLOCK(sc);
-               splx(s);
-               /* XXX tsleep will only timeout */
-               (void) tsleep(sc, TTIPRI, ttclos, hz);
-               s = splserial();
-               PLCOM_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. */
@@ -567,6 +561,7 @@
                sc->sc_cr = 0;
        bus_space_write_1(sc->sc_iot, sc->sc_ioh, plcom_cr, sc->sc_cr);
 
+       mutex_spin_exit(&sc->sc_lock);
        if (sc->disable) {
 #ifdef DIAGNOSTIC
                if (!sc->enabled)
@@ -575,8 +570,6 @@
                (*sc->disable)(sc);
                sc->enabled = 0;
        }
-       PLCOM_UNLOCK(sc);
-       splx(s);
 }
 
 int
@@ -584,7 +577,7 @@
 {
        struct plcom_softc *sc;
        struct tty *tp;
-       int s, s2;
+       int s;
        int error;
 
        sc = device_lookup_private(&plcom_cd, PLCOMUNIT(dev));
@@ -618,20 +611,18 @@
 
                tp->t_dev = dev;
 
-               s2 = splserial();
-               PLCOM_LOCK(sc);
-
                if (sc->enable) {
                        if ((*sc->enable)(sc)) {
-                               PLCOM_UNLOCK(sc);
-                               splx(s2);
                                splx(s);
                                printf("%s: device enable failed\n",
                                       sc->sc_dev.dv_xname);
                                return EIO;
                        }
+                       mutex_spin_enter(&sc->sc_lock);
                        sc->enabled = 1;
                        plcom_config(sc);
+               } else {
+                       mutex_spin_enter(&sc->sc_lock);
                }
 
                /* Turn on interrupts. */
@@ -649,8 +640,7 @@
                sc->ppsparam.mode = 0;
                mutex_spin_exit(&timecounter_lock);
 
-               PLCOM_UNLOCK(sc);
-               splx(s2);
+               mutex_spin_enter(&sc->sc_lock);
 
                /*
                 * Initialize the termios status to the defaults.  Add in the
@@ -679,8 +669,7 @@
                ttychars(tp);
                ttsetwater(tp);
 
-               s2 = splserial();
-               PLCOM_LOCK(sc);
+               mutex_spin_enter(&sc->sc_lock);
 
                /*
                 * Turn on DTR.  We must always do this, even if carrier is not
@@ -703,8 +692,7 @@
                        plcomstatus(sc, "plcomopen  ");
 #endif
 
-               PLCOM_UNLOCK(sc);
-               splx(s2);
+               mutex_spin_exit(&sc->sc_lock);
        }
        
        splx(s);
@@ -816,7 +804,6 @@
                device_lookup_private(&plcom_cd, PLCOMUNIT(dev));
        struct tty *tp = sc->sc_tty;
        int error;
-       int s;
 
        if (PLCOM_ISALIVE(sc) == 0)
                return EIO;
@@ -831,9 +818,7 @@
 
        error = 0;
 
-       s = splserial();
-       PLCOM_LOCK(sc); 
-
+       mutex_spin_enter(&sc->sc_lock);
        switch (cmd) {
        case TIOCSBRK:
                plcom_break(sc, 1);
@@ -984,8 +969,7 @@
                break;
        }
 
-       PLCOM_UNLOCK(sc);
-       splx(s);
+       mutex_spin_exit(&sc->sc_lock);
 
 #ifdef PLCOM_DEBUG
        if (plcom_debug)
@@ -1145,7 +1129,6 @@
                device_lookup_private(&plcom_cd, PLCOMUNIT(tp->t_dev));
        int ospeed;
        u_char lcr;
-       int s;
 
        if (PLCOM_ISALIVE(sc) == 0)
                return EIO;
@@ -1179,8 +1162,7 @@
 
        lcr = ISSET(sc->sc_lcr, PL01X_LCR_BRK) | cflag2lcr(t->c_cflag);
 
-       s = splserial();
-       PLCOM_LOCK(sc); 
+       mutex_spin_enter(&sc->sc_lock);
 
        sc->sc_lcr = lcr;
 
@@ -1276,8 +1258,7 @@
                sc->sc_r_lowat = plcom_rbuf_lowat;
        }
 
-       PLCOM_UNLOCK(sc);
-       splx(s);
+       mutex_spin_exit(&sc->sc_lock);
 
        /*
         * Update the tty layer's idea of the carrier bit, in case we changed
@@ -1357,7 +1338,6 @@
 {
        struct plcom_softc *sc =
                device_lookup_private(&plcom_cd, PLCOMUNIT(tp->t_dev));
-       int s;
 
        if (PLCOM_ISALIVE(sc) == 0)
                return 0;
@@ -1365,8 +1345,7 @@
        if (sc->sc_mcr_rts == 0)
                return 0;
 
-       s = splserial();
-       PLCOM_LOCK(sc);
+       mutex_spin_enter(&sc->sc_lock);
        
        if (block) {
                if (!ISSET(sc->sc_rx_flags, RX_TTY_BLOCKED)) {
@@ -1384,8 +1363,7 @@
                }
        }
 
-       PLCOM_UNLOCK(sc);
-       splx(s);
+       mutex_spin_exit(&sc->sc_lock);
        return 1;
 }
        
@@ -1440,8 +1418,7 @@
                tba = tp->t_outq.c_cf;
                tbc = ndqb(&tp->t_outq, 0);
 
-               (void)splserial();
-               PLCOM_LOCK(sc);
+               mutex_spin_enter(&sc->sc_lock);
 
                sc->sc_tba = tba;
                sc->sc_tbc = tbc;
@@ -1467,7 +1444,7 @@
                sc->sc_tbc -= n;
                sc->sc_tba += n;
        }
-       PLCOM_UNLOCK(sc);
+       mutex_spin_exit(&sc->sc_lock);
 out:
        splx(s);
        return;
@@ -1481,10 +1458,8 @@
 {
        struct plcom_softc *sc =
                device_lookup_private(&plcom_cd, PLCOMUNIT(tp->t_dev));
-       int s;
 
-       s = splserial();
-       PLCOM_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;
@@ -1492,8 +1467,7 @@



Home | Main Index | Thread Index | Old Index