Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Simplify sdhc(4) locking
details: https://anonhg.NetBSD.org/src/rev/976a53043020
branches: trunk
changeset: 339628:976a53043020
user: jmcneill <jmcneill%NetBSD.org@localhost>
date: Fri Jul 31 15:00:07 2015 +0000
description:
Simplify sdhc(4) locking
diffstat:
sys/arch/arm/broadcom/bcm2835_emmc.c | 19 ++---
sys/arch/arm/omap/omap3_sdhc.c | 18 ++--
sys/dev/sdmmc/sdhc.c | 116 +++++++++++++++-------------------
sys/dev/sdmmc/sdhcvar.h | 3 +-
4 files changed, 72 insertions(+), 84 deletions(-)
diffs (truncated from 660 to 300 lines):
diff -r 56c9a6af7502 -r 976a53043020 sys/arch/arm/broadcom/bcm2835_emmc.c
--- a/sys/arch/arm/broadcom/bcm2835_emmc.c Fri Jul 31 12:51:32 2015 +0000
+++ b/sys/arch/arm/broadcom/bcm2835_emmc.c Fri Jul 31 15:00:07 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bcm2835_emmc.c,v 1.23 2015/07/29 14:22:49 skrll Exp $ */
+/* $NetBSD: bcm2835_emmc.c,v 1.24 2015/07/31 15:00:07 jmcneill Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bcm2835_emmc.c,v 1.23 2015/07/29 14:22:49 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcm2835_emmc.c,v 1.24 2015/07/31 15:00:07 jmcneill Exp $");
#include "bcmdmac.h"
@@ -64,7 +64,6 @@
struct sdhc_host *sc_hosts[1];
void *sc_ih;
- kmutex_t sc_lock;
kcondvar_t sc_cv;
enum bcmemmc_dma_state sc_state;
@@ -165,7 +164,6 @@
sc->sc.sc_vendor_transfer_data_dma = bcmemmc_xfer_data_dma;
sc->sc_state = EMMC_DMA_STATE_IDLE;
- mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_SDMMC);
cv_init(&sc->sc_cv, "bcmemmcdma");
int rseg;
@@ -242,9 +240,12 @@
bcmemmc_xfer_data_dma(struct sdhc_softc *sdhc_sc, struct sdmmc_command *cmd)
{
struct bcmemmc_softc * const sc = device_private(sdhc_sc->sc_dev);
+ kmutex_t *plock = sdhc_host_lock(sc->sc_hosts[0]);
size_t seg;
int error;
+ KASSERT(mutex_owned(plock));
+
for (seg = 0; seg < cmd->c_dmamap->dm_nsegs; seg++) {
sc->sc_cblk[seg].cb_ti =
__SHIFTIN(11, DMAC_TI_PERMAP); /* e.MMC */
@@ -303,14 +304,13 @@
error = 0;
- mutex_enter(&sc->sc_lock);
KASSERT(sc->sc_state == EMMC_DMA_STATE_IDLE);
sc->sc_state = EMMC_DMA_STATE_BUSY;
bcm_dmac_set_conblk_addr(sc->sc_dmac,
sc->sc_dmamap->dm_segs[0].ds_addr);
bcm_dmac_transfer(sc->sc_dmac);
while (sc->sc_state == EMMC_DMA_STATE_BUSY) {
- error = cv_timedwait(&sc->sc_cv, &sc->sc_lock, hz * 10);
+ error = cv_timedwait(&sc->sc_cv, plock, hz * 10);
if (error == EWOULDBLOCK) {
device_printf(sc->sc.sc_dev, "transfer timeout!\n");
bcm_dmac_halt(sc->sc_dmac);
@@ -319,7 +319,6 @@
break;
}
}
- mutex_exit(&sc->sc_lock);
bus_dmamap_sync(sc->sc.sc_dmat, sc->sc_dmamap, 0,
sc->sc_dmamap->dm_mapsize, BUS_DMASYNC_POSTWRITE);
@@ -331,12 +330,12 @@
bcmemmc_dma_done(void *arg)
{
struct bcmemmc_softc * const sc = arg;
+ kmutex_t *plock = sdhc_host_lock(sc->sc_hosts[0]);
- mutex_enter(&sc->sc_lock);
+ mutex_enter(plock);
KASSERT(sc->sc_state == EMMC_DMA_STATE_BUSY);
sc->sc_state = EMMC_DMA_STATE_IDLE;
cv_broadcast(&sc->sc_cv);
- mutex_exit(&sc->sc_lock);
-
+ mutex_exit(plock);
}
#endif
diff -r 56c9a6af7502 -r 976a53043020 sys/arch/arm/omap/omap3_sdhc.c
--- a/sys/arch/arm/omap/omap3_sdhc.c Fri Jul 31 12:51:32 2015 +0000
+++ b/sys/arch/arm/omap/omap3_sdhc.c Fri Jul 31 15:00:07 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: omap3_sdhc.c,v 1.16 2015/04/14 18:45:25 bouyer Exp $ */
+/* $NetBSD: omap3_sdhc.c,v 1.17 2015/07/31 15:00:07 jmcneill Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
* All rights reserved.
@@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: omap3_sdhc.c,v 1.16 2015/04/14 18:45:25 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: omap3_sdhc.c,v 1.17 2015/07/31 15:00:07 jmcneill Exp $");
#include "opt_omap.h"
#include "edma.h"
@@ -102,7 +102,6 @@
struct edma_channel *sc_edma_rx;
uint16_t sc_edma_param_tx[EDMA_MAX_PARAMS];
uint16_t sc_edma_param_rx[EDMA_MAX_PARAMS];
- kmutex_t sc_edma_lock;
kcondvar_t sc_edma_cv;
bus_addr_t sc_edma_fifo;
bool sc_edma_pending;
@@ -230,7 +229,6 @@
#if NEDMA > 0
if (oa->obio_edmabase != -1) {
- mutex_init(&sc->sc_edma_lock, MUTEX_DEFAULT, IPL_SCHED);
cv_init(&sc->sc_edma_cv, "sdhcedma");
sc->sc_edma_fifo = oa->obio_addr +
OMAP3_SDMMC_SDHC_OFFSET + SDHC_DATA;
@@ -468,6 +466,7 @@
obiosdhc_edma_xfer_data(struct sdhc_softc *sdhc_sc, struct sdmmc_command *cmd)
{
struct obiosdhc_softc *sc = device_private(sdhc_sc->sc_dev);
+ kmutex_t *plock = sdhc_host_lock(sc->sc_hosts[0]);
struct edma_channel *edma;
uint16_t *edma_param;
struct edma_param ep;
@@ -475,6 +474,8 @@
int error;
int blksize = MIN(cmd->c_datalen, cmd->c_blklen);
+ KASSERT(mutex_owned(plock));
+
edma = ISSET(cmd->c_flags, SCF_CMD_READ) ?
sc->sc_edma_rx : sc->sc_edma_tx;
edma_param = ISSET(cmd->c_flags, SCF_CMD_READ) ?
@@ -540,12 +541,11 @@
#endif
}
- mutex_enter(&sc->sc_edma_lock);
error = 0;
sc->sc_edma_pending = true;
edma_transfer_enable(edma, edma_param[0]);
while (sc->sc_edma_pending) {
- error = cv_timedwait(&sc->sc_edma_cv, &sc->sc_edma_lock, hz*10);
+ error = cv_timedwait(&sc->sc_edma_cv, plock, hz*10);
if (error == EWOULDBLOCK) {
device_printf(sc->sc.sc_dev, "transfer timeout!\n");
edma_dump(edma);
@@ -557,7 +557,6 @@
}
}
edma_halt(edma);
- mutex_exit(&sc->sc_edma_lock);
return error;
}
@@ -566,11 +565,12 @@
obiosdhc_edma_done(void *priv)
{
struct obiosdhc_softc *sc = priv;
+ kmutex_t *plock = sdhc_host_lock(sc->sc_hosts[0]);
- mutex_enter(&sc->sc_edma_lock);
+ mutex_enter(plock);
KASSERT(sc->sc_edma_pending == true);
sc->sc_edma_pending = false;
cv_broadcast(&sc->sc_edma_cv);
- mutex_exit(&sc->sc_edma_lock);
+ mutex_exit(plock);
}
#endif
diff -r 56c9a6af7502 -r 976a53043020 sys/dev/sdmmc/sdhc.c
--- a/sys/dev/sdmmc/sdhc.c Fri Jul 31 12:51:32 2015 +0000
+++ b/sys/dev/sdmmc/sdhc.c Fri Jul 31 15:00:07 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sdhc.c,v 1.64 2015/07/30 15:03:14 jmcneill Exp $ */
+/* $NetBSD: sdhc.c,v 1.65 2015/07/31 15:00:08 jmcneill Exp $ */
/* $OpenBSD: sdhc.c,v 1.25 2009/01/13 19:44:20 grange Exp $ */
/*
@@ -23,7 +23,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sdhc.c,v 1.64 2015/07/30 15:03:14 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sdhc.c,v 1.65 2015/07/31 15:00:08 jmcneill Exp $");
#ifdef _KERNEL_OPT
#include "opt_sdmmc.h"
@@ -66,8 +66,6 @@
device_t sdmmc; /* generic SD/MMC device */
- struct kmutex host_mtx;
-
u_int clkbase; /* base clock frequency in KHz */
int maxblklen; /* maximum block length */
uint32_t ocr; /* OCR value from capabilities */
@@ -76,8 +74,8 @@
uint16_t intr_status; /* soft interrupt status */
uint16_t intr_error_status; /* soft error status */
- struct kmutex intr_mtx;
- struct kcondvar intr_cv;
+ kmutex_t intr_lock;
+ kcondvar_t intr_cv;
int specver; /* spec. version */
@@ -271,8 +269,7 @@
hp->ios = iosize;
hp->dmat = sc->sc_dmat;
- mutex_init(&hp->host_mtx, MUTEX_DEFAULT, IPL_SDMMC);
- mutex_init(&hp->intr_mtx, MUTEX_DEFAULT, IPL_SDMMC);
+ mutex_init(&hp->intr_lock, MUTEX_DEFAULT, IPL_SDMMC);
cv_init(&hp->intr_cv, "sdhcintr");
if (ISSET(hp->sc->sc_flags, SDHC_FLAG_ENHANCED)) {
@@ -315,9 +312,7 @@
if (ISSET(sc->sc_flags, SDHC_FLAG_HOSTCAPS)) {
caps = sc->sc_caps;
} else {
- mutex_enter(&hp->host_mtx);
caps = HREAD4(hp, SDHC_CAPABILITIES);
- mutex_exit(&hp->host_mtx);
}
/*
@@ -528,8 +523,7 @@
err:
cv_destroy(&hp->intr_cv);
- mutex_destroy(&hp->intr_mtx);
- mutex_destroy(&hp->host_mtx);
+ mutex_destroy(&hp->intr_lock);
free(hp, M_DEVBUF);
sc->sc_host[--sc->sc_nhosts] = NULL;
err1:
@@ -562,8 +556,7 @@
sdhc_soft_reset(hp, SDHC_RESET_ALL);
}
cv_destroy(&hp->intr_cv);
- mutex_destroy(&hp->intr_mtx);
- mutex_destroy(&hp->host_mtx);
+ mutex_destroy(&hp->intr_lock);
if (hp->ios > 0) {
bus_space_unmap(hp->iot, hp->ioh, hp->ios);
hp->ios = 0;
@@ -672,7 +665,7 @@
uint32_t sdhcimask;
int error;
- /* Don't lock. */
+ KASSERT(mutex_owned(&hp->intr_lock));
/* Disable all interrupts. */
if (ISSET(hp->sc->sc_flags, SDHC_FLAG_32BIT_ACCESS)) {
@@ -697,7 +690,6 @@
#endif
/* Enable interrupts. */
- mutex_enter(&hp->intr_mtx);
sdhcimask = SDHC_CARD_REMOVAL | SDHC_CARD_INSERTION |
SDHC_BUFFER_READ_READY | SDHC_BUFFER_WRITE_READY |
SDHC_DMA_INTERRUPT | SDHC_BLOCK_GAP_EVENT |
@@ -716,7 +708,6 @@
HWRITE2(hp, SDHC_NINTR_SIGNAL_EN, sdhcimask);
HWRITE2(hp, SDHC_EINTR_SIGNAL_EN, SDHC_EINTR_SIGNAL_MASK);
}
- mutex_exit(&hp->intr_mtx);
out:
return error;
@@ -728,9 +719,9 @@
struct sdhc_host *hp = (struct sdhc_host *)sch;
int error;
- mutex_enter(&hp->host_mtx);
+ mutex_enter(&hp->intr_lock);
error = sdhc_host_reset1(sch);
- mutex_exit(&hp->host_mtx);
+ mutex_exit(&hp->intr_lock);
return error;
}
@@ -763,9 +754,7 @@
if (hp->sc->sc_vendor_card_detect)
return (*hp->sc->sc_vendor_card_detect)(hp->sc);
- mutex_enter(&hp->host_mtx);
r = ISSET(HREAD4(hp, SDHC_PRESENT_STATE), SDHC_CARD_INSERTED);
- mutex_exit(&hp->host_mtx);
return r ? 1 : 0;
}
Home |
Main Index |
Thread Index |
Old Index