summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/dev/sdmmc/sdmmc.c33
-rw-r--r--sys/dev/sdmmc/sdmmc_io.c7
-rw-r--r--sys/dev/sdmmc/sdmmc_mem.c11
-rw-r--r--sys/dev/sdmmc/sdmmc_scsi.c7
-rw-r--r--sys/dev/sdmmc/sdmmcvar.h8
5 files changed, 46 insertions, 20 deletions
diff --git a/sys/dev/sdmmc/sdmmc.c b/sys/dev/sdmmc/sdmmc.c
index 6a7fac743a8..9b46846eac0 100644
--- a/sys/dev/sdmmc/sdmmc.c
+++ b/sys/dev/sdmmc/sdmmc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sdmmc.c,v 1.14 2007/09/11 13:39:34 gilles Exp $ */
+/* $OpenBSD: sdmmc.c,v 1.15 2008/11/24 07:32:08 blambert Exp $ */
/*
* Copyright (c) 2006 Uwe Stuehler <uwe@openbsd.org>
@@ -108,7 +108,7 @@ sdmmc_attach(struct device *parent, struct device *self, void *aux)
TAILQ_INIT(&sc->sc_intrq);
sdmmc_init_task(&sc->sc_discover_task, sdmmc_discover_task, sc);
sdmmc_init_task(&sc->sc_intr_task, sdmmc_intr_task, sc);
- lockinit(&sc->sc_lock, PRIBIO, DEVNAME(sc), 0, LK_CANRECURSE);
+ lockinit(&sc->sc_lock, PRIBIO, DEVNAME(sc), 0, 0);
#ifdef SDMMC_IOCTL
if (bio_register(self, sdmmc_ioctl) != 0)
@@ -174,8 +174,11 @@ sdmmc_task_thread(void *arg)
}
splx(s);
- if (ISSET(sc->sc_flags, SMF_CARD_PRESENT))
+ if (ISSET(sc->sc_flags, SMF_CARD_PRESENT)) {
+ SDMMC_LOCK(sc);
sdmmc_card_detach(sc, DETACH_FORCE);
+ SDMMC_UNLOCK(sc);
+ }
sc->sc_task_thread = NULL;
wakeup(sc);
@@ -233,7 +236,9 @@ sdmmc_discover_task(void *arg)
} else {
if (ISSET(sc->sc_flags, SMF_CARD_PRESENT)) {
CLR(sc->sc_flags, SMF_CARD_PRESENT);
+ SDMMC_LOCK(sc);
sdmmc_card_detach(sc, DETACH_FORCE);
+ SDMMC_UNLOCK(sc);
}
}
}
@@ -299,6 +304,8 @@ sdmmc_card_detach(struct sdmmc_softc *sc, int flags)
{
struct sdmmc_function *sf, *sfnext;
+ SDMMC_ASSERT_LOCKED(sc);
+
DPRINTF(1,("%s: detach card\n", DEVNAME(sc)));
if (ISSET(sc->sc_flags, SMF_CARD_ATTACHED)) {
@@ -332,6 +339,8 @@ sdmmc_enable(struct sdmmc_softc *sc)
u_int32_t host_ocr;
int error;
+ SDMMC_ASSERT_LOCKED(sc);
+
/*
* Calculate the equivalent of the card OCR from the host
* capabilities and select the maximum supported bus voltage.
@@ -372,6 +381,7 @@ sdmmc_enable(struct sdmmc_softc *sc)
err:
if (error != 0)
sdmmc_disable(sc);
+
return error;
}
@@ -442,6 +452,9 @@ sdmmc_function_free(struct sdmmc_function *sf)
int
sdmmc_scan(struct sdmmc_softc *sc)
{
+
+ SDMMC_ASSERT_LOCKED(sc);
+
/* Scan for I/O functions. */
if (ISSET(sc->sc_flags, SMF_IO_MODE))
sdmmc_io_scan(sc);
@@ -504,7 +517,7 @@ sdmmc_app_command(struct sdmmc_softc *sc, struct sdmmc_command *cmd)
struct sdmmc_command acmd;
int error;
- SDMMC_LOCK(sc);
+ SDMMC_ASSERT_LOCKED(sc);
bzero(&acmd, sizeof acmd);
acmd.c_opcode = MMC_APP_CMD;
@@ -513,18 +526,15 @@ sdmmc_app_command(struct sdmmc_softc *sc, struct sdmmc_command *cmd)
error = sdmmc_mmc_command(sc, &acmd);
if (error != 0) {
- SDMMC_UNLOCK(sc);
return error;
}
if (!ISSET(MMC_R1(acmd.c_resp), MMC_R1_APP_CMD)) {
/* Card does not support application commands. */
- SDMMC_UNLOCK(sc);
return ENODEV;
}
error = sdmmc_mmc_command(sc, cmd);
- SDMMC_UNLOCK(sc);
return error;
}
@@ -538,7 +548,7 @@ sdmmc_mmc_command(struct sdmmc_softc *sc, struct sdmmc_command *cmd)
{
int error;
- SDMMC_LOCK(sc);
+ SDMMC_ASSERT_LOCKED(sc);
sdmmc_chip_exec_command(sc->sct, sc->sch, cmd);
@@ -549,7 +559,6 @@ sdmmc_mmc_command(struct sdmmc_softc *sc, struct sdmmc_command *cmd)
error = cmd->c_error;
wakeup(cmd);
- SDMMC_UNLOCK(sc);
return error;
}
@@ -561,6 +570,8 @@ sdmmc_go_idle_state(struct sdmmc_softc *sc)
{
struct sdmmc_command cmd;
+ SDMMC_ASSERT_LOCKED(sc);
+
bzero(&cmd, sizeof cmd);
cmd.c_opcode = MMC_GO_IDLE_STATE;
cmd.c_flags = SCF_CMD_BC | SCF_RSP_R0;
@@ -577,6 +588,8 @@ sdmmc_set_relative_addr(struct sdmmc_softc *sc,
{
struct sdmmc_command cmd;
+ SDMMC_ASSERT_LOCKED(sc);
+
bzero(&cmd, sizeof cmd);
if (ISSET(sc->sc_flags, SMF_SD_MODE)) {
@@ -699,12 +712,14 @@ sdmmc_ioctl(struct device *self, u_long request, caddr_t addr)
cmd.c_datalen = ucmd->c_datalen;
}
+ SDMMC_LOCK(sc);
if (request == SDIOCEXECMMC)
error = sdmmc_mmc_command(sc, &cmd);
else
error = sdmmc_app_command(sc, &cmd);
if (error && !cmd.c_error)
cmd.c_error = error;
+ SDMMC_UNLOCK(sc);
bcopy(&cmd.c_resp, ucmd->c_resp, sizeof cmd.c_resp);
ucmd->c_flags = cmd.c_flags;
diff --git a/sys/dev/sdmmc/sdmmc_io.c b/sys/dev/sdmmc/sdmmc_io.c
index 839740ee8be..4fdb9261c42 100644
--- a/sys/dev/sdmmc/sdmmc_io.c
+++ b/sys/dev/sdmmc/sdmmc_io.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sdmmc_io.c,v 1.10 2007/09/17 01:33:33 krw Exp $ */
+/* $OpenBSD: sdmmc_io.c,v 1.11 2008/11/24 07:32:08 blambert Exp $ */
/*
* Copyright (c) 2006 Uwe Stuehler <uwe@openbsd.org>
@@ -133,6 +133,8 @@ sdmmc_io_scan(struct sdmmc_softc *sc)
struct sdmmc_function *sf0, *sf;
int i;
+ SDMMC_ASSERT_LOCKED(sc);
+
sf0 = sdmmc_function_alloc(sc);
sf0->number = 0;
if (sdmmc_set_relative_addr(sc, sf0) != 0) {
@@ -534,7 +536,7 @@ sdmmc_io_send_op_cond(struct sdmmc_softc *sc, u_int32_t ocr, u_int32_t *ocrp)
int error;
int i;
- SDMMC_LOCK(sc);
+ SDMMC_ASSERT_LOCKED(sc);
/*
* If we change the OCR value, retry the command until the OCR
@@ -559,7 +561,6 @@ sdmmc_io_send_op_cond(struct sdmmc_softc *sc, u_int32_t ocr, u_int32_t *ocrp)
if (error == 0 && ocrp != NULL)
*ocrp = MMC_R4(cmd.c_resp);
- SDMMC_UNLOCK(sc);
return error;
}
diff --git a/sys/dev/sdmmc/sdmmc_mem.c b/sys/dev/sdmmc/sdmmc_mem.c
index a6354363de6..151aa385704 100644
--- a/sys/dev/sdmmc/sdmmc_mem.c
+++ b/sys/dev/sdmmc/sdmmc_mem.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sdmmc_mem.c,v 1.7 2007/03/18 22:07:16 uwe Exp $ */
+/* $OpenBSD: sdmmc_mem.c,v 1.8 2008/11/24 07:32:08 blambert Exp $ */
/*
* Copyright (c) 2006 Uwe Stuehler <uwe@openbsd.org>
@@ -51,6 +51,8 @@ sdmmc_mem_enable(struct sdmmc_softc *sc)
u_int32_t host_ocr;
u_int32_t card_ocr;
+ SDMMC_ASSERT_LOCKED(sc);
+
/* Set host mode to SD "combo" card or SD memory-only. */
SET(sc->sc_flags, SMF_SD_MODE|SMF_MEM_MODE);
@@ -114,6 +116,8 @@ sdmmc_mem_scan(struct sdmmc_softc *sc)
int error;
int i;
+ SDMMC_ASSERT_LOCKED(sc);
+
/*
* CMD2 is a broadcast command understood by SD cards and MMC
* cards. All cards begin to respond to the command, but back
@@ -331,7 +335,7 @@ sdmmc_mem_send_op_cond(struct sdmmc_softc *sc, u_int32_t ocr,
int error;
int i;
- SDMMC_LOCK(sc);
+ SDMMC_ASSERT_LOCKED(sc);
/*
* If we change the OCR value, retry the command until the OCR
@@ -361,7 +365,6 @@ sdmmc_mem_send_op_cond(struct sdmmc_softc *sc, u_int32_t ocr,
if (error == 0 && ocrp != NULL)
*ocrp = MMC_R3(cmd.c_resp);
- SDMMC_UNLOCK(sc);
return error;
}
@@ -374,6 +377,8 @@ sdmmc_mem_set_blocklen(struct sdmmc_softc *sc, struct sdmmc_function *sf)
{
struct sdmmc_command cmd;
+ SDMMC_ASSERT_LOCKED(sc);
+
bzero(&cmd, sizeof cmd);
cmd.c_opcode = MMC_SET_BLOCKLEN;
cmd.c_arg = sf->csd.sector_size;
diff --git a/sys/dev/sdmmc/sdmmc_scsi.c b/sys/dev/sdmmc/sdmmc_scsi.c
index 317025e19fe..03be9cb10d8 100644
--- a/sys/dev/sdmmc/sdmmc_scsi.c
+++ b/sys/dev/sdmmc/sdmmc_scsi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sdmmc_scsi.c,v 1.9 2007/09/11 13:39:34 gilles Exp $ */
+/* $OpenBSD: sdmmc_scsi.c,v 1.10 2008/11/24 07:32:08 blambert Exp $ */
/*
* Copyright (c) 2006 Uwe Stuehler <uwe@openbsd.org>
@@ -99,10 +99,9 @@ sdmmc_scsi_attach(struct sdmmc_softc *sc)
struct sdmmc_scsi_softc *scbus;
struct sdmmc_function *sf;
- scbus = (struct sdmmc_scsi_softc *)malloc(sizeof *scbus,
- M_DEVBUF, M_WAITOK | M_ZERO);
+ scbus = malloc(sizeof(*scbus), M_DEVBUF, M_WAITOK | M_ZERO);
- scbus->sc_tgt = (struct sdmmc_scsi_target *)malloc(sizeof(*scbus->sc_tgt) *
+ scbus->sc_tgt = malloc(sizeof(*scbus->sc_tgt) *
(SDMMC_SCSIID_MAX+1), M_DEVBUF, M_WAITOK | M_ZERO);
/*
diff --git a/sys/dev/sdmmc/sdmmcvar.h b/sys/dev/sdmmc/sdmmcvar.h
index 9797983a5e0..26e4f0b99ec 100644
--- a/sys/dev/sdmmc/sdmmcvar.h
+++ b/sys/dev/sdmmc/sdmmcvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sdmmcvar.h,v 1.10 2007/11/29 13:16:06 todd Exp $ */
+/* $OpenBSD: sdmmcvar.h,v 1.11 2008/11/24 07:32:08 blambert Exp $ */
/*
* Copyright (c) 2006 Uwe Stuehler <uwe@openbsd.org>
@@ -187,6 +187,12 @@ struct sdmmc_attach_args {
#define SDMMC_LOCK(sc) lockmgr(&(sc)->sc_lock, LK_EXCLUSIVE, NULL)
#define SDMMC_UNLOCK(sc) lockmgr(&(sc)->sc_lock, LK_RELEASE, NULL)
+#ifdef DIAGNOSTIC
+#define SDMMC_ASSERT_LOCKED(sc) \
+ KASSERT(lockstatus(&((sc))->sc_lock) == LK_EXCLUSIVE)
+#else
+#define SDMMC_ASSERT_LOCKED(sc)
+#endif /* DIAGNOSTIC */
void sdmmc_add_task(struct sdmmc_softc *, struct sdmmc_task *);
void sdmmc_del_task(struct sdmmc_task *);