Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/i2c Don't sleep with IPL_VM lock held.



details:   https://anonhg.NetBSD.org/src/rev/c937e219bd88
branches:  trunk
changeset: 832329:c937e219bd88
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Mon May 07 15:03:19 2018 +0000

description:
Don't sleep with IPL_VM lock held.

diffstat:

 sys/dev/i2c/gttwsi_core.c |  26 +++++++++++++++++---------
 sys/dev/i2c/gttwsivar.h   |   3 ++-
 2 files changed, 19 insertions(+), 10 deletions(-)

diffs (120 lines):

diff -r a9820f302e90 -r c937e219bd88 sys/dev/i2c/gttwsi_core.c
--- a/sys/dev/i2c/gttwsi_core.c Mon May 07 12:58:58 2018 +0000
+++ b/sys/dev/i2c/gttwsi_core.c Mon May 07 15:03:19 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gttwsi_core.c,v 1.4 2018/05/03 02:08:52 jmcneill Exp $ */
+/*     $NetBSD: gttwsi_core.c,v 1.5 2018/05/07 15:03:19 jmcneill Exp $ */
 /*
  * Copyright (c) 2008 Eiji Kawauchi.
  * All rights reserved.
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: gttwsi_core.c,v 1.4 2018/05/03 02:08:52 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gttwsi_core.c,v 1.5 2018/05/07 15:03:19 jmcneill Exp $");
 #include "locators.h"
 
 #include <sys/param.h>
@@ -195,7 +195,7 @@
        if (val & CONTROL_IFLG) {
                gttwsi_write_4(sc, TWSI_CONTROL, val & ~CONTROL_INTEN);
                mutex_enter(&sc->sc_mtx);
-               cv_signal(&sc->sc_cv);
+               cv_broadcast(&sc->sc_cv);
                mutex_exit(&sc->sc_mtx);
 
                return 1;       /* handled */
@@ -210,6 +210,11 @@
        struct gttwsi_softc *sc = arg;
 
        mutex_enter(&sc->sc_buslock);
+       while (sc->sc_inuse)
+               cv_wait(&sc->sc_cv, &sc->sc_buslock);
+       sc->sc_inuse = true;
+       mutex_exit(&sc->sc_buslock);
+
        return 0;
 }
 
@@ -219,6 +224,9 @@
 {
        struct gttwsi_softc *sc = arg;
 
+       mutex_enter(&sc->sc_buslock);
+       sc->sc_inuse = false;
+       cv_broadcast(&sc->sc_cv);
        mutex_exit(&sc->sc_buslock);
 }
 
@@ -228,7 +236,7 @@
        struct gttwsi_softc *sc = v;
        int expect;
 
-       KASSERT(mutex_owned(&sc->sc_buslock));
+       KASSERT(sc->sc_inuse);
 
        if (sc->sc_started)
                expect = STAT_RSCT;
@@ -245,7 +253,7 @@
        int retry = TWSI_RETRY_COUNT;
        uint32_t control;
 
-       KASSERT(mutex_owned(&sc->sc_buslock));
+       KASSERT(sc->sc_inuse);
 
        sc->sc_started = false;
 
@@ -272,7 +280,7 @@
        uint32_t data, expect;
        int error, read;
 
-       KASSERT(mutex_owned(&sc->sc_buslock));
+       KASSERT(sc->sc_inuse);
 
        gttwsi_send_start(v, flags);
 
@@ -318,7 +326,7 @@
        struct gttwsi_softc *sc = v;
        int error;
 
-       KASSERT(mutex_owned(&sc->sc_buslock));
+       KASSERT(sc->sc_inuse);
 
        if (flags & I2C_F_LAST)
                error = gttwsi_wait(sc, 0, STAT_MRRD_ANT, flags);
@@ -337,7 +345,7 @@
        struct gttwsi_softc *sc = v;
        int error;
 
-       KASSERT(mutex_owned(&sc->sc_buslock));
+       KASSERT(sc->sc_inuse);
 
        gttwsi_write_4(sc, TWSI_DATA, val);
        error = gttwsi_wait(sc, 0, STAT_MTDB_AR, flags);
@@ -353,7 +361,7 @@
        uint32_t status;
        int timo, error = 0;
 
-       KASSERT(mutex_owned(&sc->sc_buslock));
+       KASSERT(sc->sc_inuse);
 
        DELAY(5);
        if (!(flags & I2C_F_POLL))
diff -r a9820f302e90 -r c937e219bd88 sys/dev/i2c/gttwsivar.h
--- a/sys/dev/i2c/gttwsivar.h   Mon May 07 12:58:58 2018 +0000
+++ b/sys/dev/i2c/gttwsivar.h   Mon May 07 15:03:19 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gttwsivar.h,v 1.3 2017/10/29 14:59:05 jmcneill Exp $   */
+/*     $NetBSD: gttwsivar.h,v 1.4 2018/05/07 15:03:19 jmcneill Exp $   */
 /*
  * Copyright (c) 2008 Eiji Kawauchi.
  * All rights reserved.
@@ -86,6 +86,7 @@
        struct i2c_controller sc_i2c;
        kmutex_t sc_buslock;
        kmutex_t sc_mtx;
+       bool sc_inuse;
        kcondvar_t sc_cv;
 
        bool sc_iflg_rwc;



Home | Main Index | Thread Index | Old Index