Module Name:    src
Committed By:   mlelstv
Date:           Mon Aug  3 05:32:50 UTC 2015

Modified Files:
        src/sys/dev/sdmmc: ld_sdmmc.c sdmmc.c sdmmc_io.c sdmmc_mem.c

Log Message:
use mutex locking for MP safety.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/sdmmc/ld_sdmmc.c
cvs rdiff -u -r1.27 -r1.28 src/sys/dev/sdmmc/sdmmc.c
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/sdmmc/sdmmc_io.c
cvs rdiff -u -r1.37 -r1.38 src/sys/dev/sdmmc/sdmmc_mem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/sdmmc/ld_sdmmc.c
diff -u src/sys/dev/sdmmc/ld_sdmmc.c:1.17 src/sys/dev/sdmmc/ld_sdmmc.c:1.18
--- src/sys/dev/sdmmc/ld_sdmmc.c:1.17	Mon Jul 27 07:53:46 2015
+++ src/sys/dev/sdmmc/ld_sdmmc.c	Mon Aug  3 05:32:50 2015
@@ -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 @@ ld_sdmmc_dobio(void *arg)
 	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 @@ ld_sdmmc_dobio(void *arg)
 		    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 @@ ld_sdmmc_dobio(void *arg)
 	}
 
 	lddone(&sc->sc_ld, bp);
-	splx(s);
 }
 
 static int

Index: src/sys/dev/sdmmc/sdmmc.c
diff -u src/sys/dev/sdmmc/sdmmc.c:1.27 src/sys/dev/sdmmc/sdmmc.c:1.28
--- src/sys/dev/sdmmc/sdmmc.c:1.27	Tue Jul 28 06:19:47 2015
+++ src/sys/dev/sdmmc/sdmmc.c	Mon Aug  3 05:32:50 2015
@@ -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_attach(device_t parent, device_t s
 	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 @@ sdmmc_polling_card(void *arg)
 {
 	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_polling_card(void *arg)
 			sdmmc_needs_discover(sc->sc_dev);
 		}
 	}
-	splx(s);
+	mutex_exit(&sc->sc_mtx);
 
 	callout_schedule(&sc->sc_card_detect_ch, hz);
 }

Index: src/sys/dev/sdmmc/sdmmc_io.c
diff -u src/sys/dev/sdmmc/sdmmc_io.c:1.8 src/sys/dev/sdmmc/sdmmc_io.c:1.9
--- src/sys/dev/sdmmc/sdmmc_io.c:1.8	Tue Jul 28 06:17:53 2015
+++ src/sys/dev/sdmmc/sdmmc_io.c	Mon Aug  3 05:32:50 2015
@@ -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 @@ sdmmc_intr_establish(device_t dev, int (
 {
 	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 @@ sdmmc_intr_establish(device_t dev, int (
 	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 @@ sdmmc_intr_disestablish(void *cookie)
 {
 	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 @@ sdmmc_intr_task(void *arg)
 {
 	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);
 }

Index: src/sys/dev/sdmmc/sdmmc_mem.c
diff -u src/sys/dev/sdmmc/sdmmc_mem.c:1.37 src/sys/dev/sdmmc/sdmmc_mem.c:1.38
--- src/sys/dev/sdmmc/sdmmc_mem.c:1.37	Mon Aug  3 05:26:53 2015
+++ src/sys/dev/sdmmc/sdmmc_mem.c	Mon Aug  3 05:32:50 2015
@@ -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 @@ sdmmc_mem_read_block(struct sdmmc_functi
 	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 @@ unload:
 	bus_dmamap_unload(sc->sc_dmat, sc->sc_dmap);
 
 out:
+	mutex_exit(&sc->sc_mtx);
 	SDMMC_UNLOCK(sc);
 
 	return error;
@@ -1693,6 +1695,7 @@ sdmmc_mem_write_block(struct sdmmc_funct
 	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 @@ unload:
 	bus_dmamap_unload(sc->sc_dmat, sc->sc_dmap);
 
 out:
+	mutex_exit(&sc->sc_mtx);
 	SDMMC_UNLOCK(sc);
 
 	return error;

Reply via email to