Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/sdmmc use mutex locking for MP safety.



details:   https://anonhg.NetBSD.org/src/rev/97f9e065cb84
branches:  trunk
changeset: 809826:97f9e065cb84
user:      mlelstv <mlelstv%NetBSD.org@localhost>
date:      Mon Aug 03 05:32:50 2015 +0000

description:
use mutex locking for MP safety.

diffstat:

 sys/dev/sdmmc/ld_sdmmc.c  |  10 +++-------
 sys/dev/sdmmc/sdmmc.c     |  11 +++++------
 sys/dev/sdmmc/sdmmc_io.c  |  23 ++++++++++-------------
 sys/dev/sdmmc/sdmmc_mem.c |   8 ++++++--
 4 files changed, 24 insertions(+), 28 deletions(-)

diffs (229 lines):

diff -r 298dd13bd716 -r 97f9e065cb84 sys/dev/sdmmc/ld_sdmmc.c
--- a/sys/dev/sdmmc/ld_sdmmc.c  Mon Aug 03 05:26:53 2015 +0000
+++ b/sys/dev/sdmmc/ld_sdmmc.c  Mon Aug 03 05:32:50 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ld_sdmmc.c,v 1.17 2015/07/27 07:53:46 skrll Exp $      */
+/*     $NetBSD: ld_sdmmc.c,v 1.18 2015/08/03 05:32:50 mlelstv Exp $    */
 
 /*
  * Copyright (c) 2008 KIYOHARA Takashi
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ld_sdmmc.c,v 1.17 2015/07/27 07:53:46 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ld_sdmmc.c,v 1.18 2015/08/03 05:32:50 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_sdmmc.h"
@@ -191,7 +191,7 @@
        struct ld_sdmmc_task *task = (struct ld_sdmmc_task *)arg;
        struct ld_sdmmc_softc *sc = task->task_sc;
        struct buf *bp = task->task_bp;
-       int error, s;
+       int error;
 
        /*
         * I/O operation
@@ -208,13 +208,10 @@
                    bp->b_rawblkno, sc->sc_sf->csd.capacity);
                bp->b_error = EINVAL;
                bp->b_resid = bp->b_bcount;
-               s = splbio();
                lddone(&sc->sc_ld, bp);
-               splx(s);
                return;
        }
 
-       s = splbio();
        if (bp->b_flags & B_READ)
                error = sdmmc_mem_read_block(sc->sc_sf, bp->b_rawblkno,
                    bp->b_data, bp->b_bcount);
@@ -231,7 +228,6 @@
        }
 
        lddone(&sc->sc_ld, bp);
-       splx(s);
 }
 
 static int
diff -r 298dd13bd716 -r 97f9e065cb84 sys/dev/sdmmc/sdmmc.c
--- a/sys/dev/sdmmc/sdmmc.c     Mon Aug 03 05:26:53 2015 +0000
+++ b/sys/dev/sdmmc/sdmmc.c     Mon Aug 03 05:32:50 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sdmmc.c,v 1.27 2015/07/28 06:19:47 mlelstv Exp $       */
+/*     $NetBSD: sdmmc.c,v 1.28 2015/08/03 05:32:50 mlelstv Exp $       */
 /*     $OpenBSD: sdmmc.c,v 1.18 2009/01/09 10:58:38 jsg Exp $  */
 
 /*
@@ -49,7 +49,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sdmmc.c,v 1.27 2015/07/28 06:19:47 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sdmmc.c,v 1.28 2015/08/03 05:32:50 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_sdmmc.h"
@@ -148,7 +148,7 @@
        sdmmc_init_task(&sc->sc_discover_task, sdmmc_discover_task, sc);
        sdmmc_init_task(&sc->sc_intr_task, sdmmc_intr_task, sc);
 
-       mutex_init(&sc->sc_mtx, MUTEX_DEFAULT, IPL_SDMMC);
+       mutex_init(&sc->sc_mtx, MUTEX_DEFAULT, IPL_NONE);
        mutex_init(&sc->sc_tskq_mtx, MUTEX_DEFAULT, IPL_SDMMC);
        mutex_init(&sc->sc_discover_task_mtx, MUTEX_DEFAULT, IPL_SDMMC);
        mutex_init(&sc->sc_intr_task_mtx, MUTEX_DEFAULT, IPL_SDMMC);
@@ -336,9 +336,8 @@
 {
        struct sdmmc_softc *sc = (struct sdmmc_softc *)arg;
        int card_detect;
-       int s;
 
-       s = splsdmmc();
+       mutex_enter(&sc->sc_mtx);
        card_detect = sdmmc_chip_card_detect(sc->sc_sct, sc->sc_sch);
        if (card_detect) {
                if (!ISSET(sc->sc_flags, SMF_CARD_PRESENT)) {
@@ -349,7 +348,7 @@
                        sdmmc_needs_discover(sc->sc_dev);
                }
        }
-       splx(s);
+       mutex_exit(&sc->sc_mtx);
 
        callout_schedule(&sc->sc_card_detect_ch, hz);
 }
diff -r 298dd13bd716 -r 97f9e065cb84 sys/dev/sdmmc/sdmmc_io.c
--- a/sys/dev/sdmmc/sdmmc_io.c  Mon Aug 03 05:26:53 2015 +0000
+++ b/sys/dev/sdmmc/sdmmc_io.c  Mon Aug 03 05:32:50 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sdmmc_io.c,v 1.8 2015/07/28 06:17:53 mlelstv Exp $     */
+/*     $NetBSD: sdmmc_io.c,v 1.9 2015/08/03 05:32:50 mlelstv Exp $     */
 /*     $OpenBSD: sdmmc_io.c,v 1.10 2007/09/17 01:33:33 krw Exp $       */
 
 /*
@@ -20,7 +20,7 @@
 /* Routines for SD I/O cards. */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sdmmc_io.c,v 1.8 2015/07/28 06:17:53 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sdmmc_io.c,v 1.9 2015/08/03 05:32:50 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_sdmmc.h"
@@ -627,7 +627,6 @@
 {
        struct sdmmc_softc *sc = device_private(dev);
        struct sdmmc_intr_handler *ih;
-       int s;
 
        if (sc->sc_sct->card_enable_intr == NULL)
                return NULL;
@@ -647,13 +646,13 @@
        ih->ih_fun = fun;
        ih->ih_arg = arg;
 
-       s = splhigh();
+       mutex_enter(&sc->sc_mtx);
        if (TAILQ_EMPTY(&sc->sc_intrq)) {
                sdmmc_intr_enable(sc->sc_fn0);
                sdmmc_chip_card_enable_intr(sc->sc_sct, sc->sc_sch, 1);
        }
        TAILQ_INSERT_TAIL(&sc->sc_intrq, ih, entry);
-       splx(s);
+       mutex_exit(&sc->sc_mtx);
 
        return ih;
 }
@@ -666,18 +665,17 @@
 {
        struct sdmmc_intr_handler *ih = cookie;
        struct sdmmc_softc *sc = ih->ih_softc;
-       int s;
 
        if (sc->sc_sct->card_enable_intr == NULL)
                return;
 
-       s = splhigh();
+       mutex_enter(&sc->sc_mtx);
        TAILQ_REMOVE(&sc->sc_intrq, ih, entry);
        if (TAILQ_EMPTY(&sc->sc_intrq)) {
                sdmmc_chip_card_enable_intr(sc->sc_sct, sc->sc_sch, 0);
                sdmmc_intr_disable(sc->sc_fn0);
        }
-       splx(s);
+       mutex_exit(&sc->sc_mtx);
 
        free(ih->ih_name, M_DEVBUF);
        free(ih, M_DEVBUF);
@@ -707,15 +705,14 @@
 {
        struct sdmmc_softc *sc = (struct sdmmc_softc *)arg;
        struct sdmmc_intr_handler *ih;
-       int s;
 
-       s = splsdmmc();
+       mutex_enter(&sc->sc_mtx);
        TAILQ_FOREACH(ih, &sc->sc_intrq, entry) {
-               splx(s);
+               mutex_exit(&sc->sc_mtx);
                /* XXX examine return value and do evcount stuff*/
                (void)(*ih->ih_fun)(ih->ih_arg);
-               s = splsdmmc();
+               mutex_enter(&sc->sc_mtx);
        }
        sdmmc_chip_card_intr_ack(sc->sc_sct, sc->sc_sch);
-       splx(s);
+       mutex_exit(&sc->sc_mtx);
 }
diff -r 298dd13bd716 -r 97f9e065cb84 sys/dev/sdmmc/sdmmc_mem.c
--- a/sys/dev/sdmmc/sdmmc_mem.c Mon Aug 03 05:26:53 2015 +0000
+++ b/sys/dev/sdmmc/sdmmc_mem.c Mon Aug 03 05:32:50 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sdmmc_mem.c,v 1.37 2015/08/03 05:26:53 mlelstv Exp $   */
+/*     $NetBSD: sdmmc_mem.c,v 1.38 2015/08/03 05:32:50 mlelstv Exp $   */
 /*     $OpenBSD: sdmmc_mem.c,v 1.10 2009/01/09 10:55:22 jsg Exp $      */
 
 /*
@@ -45,7 +45,7 @@
 /* Routines for SD/MMC memory cards. */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sdmmc_mem.c,v 1.37 2015/08/03 05:26:53 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sdmmc_mem.c,v 1.38 2015/08/03 05:32:50 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_sdmmc.h"
@@ -1482,6 +1482,7 @@
        int error;
 
        SDMMC_LOCK(sc);
+       mutex_enter(&sc->sc_mtx);
 
        if (ISSET(sc->sc_caps, SMC_CAPS_SINGLE_ONLY)) {
                error = sdmmc_mem_single_read_block(sf, blkno, data, datalen);
@@ -1530,6 +1531,7 @@
        bus_dmamap_unload(sc->sc_dmat, sc->sc_dmap);
 
 out:
+       mutex_exit(&sc->sc_mtx);
        SDMMC_UNLOCK(sc);
 
        return error;
@@ -1693,6 +1695,7 @@
        int error;
 
        SDMMC_LOCK(sc);
+       mutex_enter(&sc->sc_mtx);
 
        if (sdmmc_chip_write_protect(sc->sc_sct, sc->sc_sch)) {
                aprint_normal_dev(sc->sc_dev, "write-protected\n");
@@ -1749,6 +1752,7 @@
        bus_dmamap_unload(sc->sc_dmat, sc->sc_dmap);
 
 out:
+       mutex_exit(&sc->sc_mtx);
        SDMMC_UNLOCK(sc);
 
        return error;



Home | Main Index | Thread Index | Old Index