diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2008-12-02 23:49:55 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2008-12-02 23:49:55 +0000 |
commit | f975abdf986484b1106e54c85f3e4e16a373adc5 (patch) | |
tree | 374d299b0ec7a2f1424d86554336d71df4b4413b /sys/dev | |
parent | 1ae8361b33cb11f409504540583ae41711d3f59d (diff) |
backout: would have been nice if this had been tested, to see that it
crashes the moment a card is plugged in.
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/sdmmc/sdmmc.c | 33 | ||||
-rw-r--r-- | sys/dev/sdmmc/sdmmc_io.c | 7 | ||||
-rw-r--r-- | sys/dev/sdmmc/sdmmc_mem.c | 11 | ||||
-rw-r--r-- | sys/dev/sdmmc/sdmmc_scsi.c | 7 | ||||
-rw-r--r-- | sys/dev/sdmmc/sdmmcvar.h | 8 |
5 files changed, 20 insertions, 46 deletions
diff --git a/sys/dev/sdmmc/sdmmc.c b/sys/dev/sdmmc/sdmmc.c index 9b46846eac0..60edbb6f43b 100644 --- a/sys/dev/sdmmc/sdmmc.c +++ b/sys/dev/sdmmc/sdmmc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sdmmc.c,v 1.15 2008/11/24 07:32:08 blambert Exp $ */ +/* $OpenBSD: sdmmc.c,v 1.16 2008/12/02 23:49:54 deraadt 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, 0); + lockinit(&sc->sc_lock, PRIBIO, DEVNAME(sc), 0, LK_CANRECURSE); #ifdef SDMMC_IOCTL if (bio_register(self, sdmmc_ioctl) != 0) @@ -174,11 +174,8 @@ sdmmc_task_thread(void *arg) } splx(s); - if (ISSET(sc->sc_flags, SMF_CARD_PRESENT)) { - SDMMC_LOCK(sc); + if (ISSET(sc->sc_flags, SMF_CARD_PRESENT)) sdmmc_card_detach(sc, DETACH_FORCE); - SDMMC_UNLOCK(sc); - } sc->sc_task_thread = NULL; wakeup(sc); @@ -236,9 +233,7 @@ 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); } } } @@ -304,8 +299,6 @@ 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)) { @@ -339,8 +332,6 @@ 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. @@ -381,7 +372,6 @@ sdmmc_enable(struct sdmmc_softc *sc) err: if (error != 0) sdmmc_disable(sc); - return error; } @@ -452,9 +442,6 @@ 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); @@ -517,7 +504,7 @@ sdmmc_app_command(struct sdmmc_softc *sc, struct sdmmc_command *cmd) struct sdmmc_command acmd; int error; - SDMMC_ASSERT_LOCKED(sc); + SDMMC_LOCK(sc); bzero(&acmd, sizeof acmd); acmd.c_opcode = MMC_APP_CMD; @@ -526,15 +513,18 @@ 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; } @@ -548,7 +538,7 @@ sdmmc_mmc_command(struct sdmmc_softc *sc, struct sdmmc_command *cmd) { int error; - SDMMC_ASSERT_LOCKED(sc); + SDMMC_LOCK(sc); sdmmc_chip_exec_command(sc->sct, sc->sch, cmd); @@ -559,6 +549,7 @@ sdmmc_mmc_command(struct sdmmc_softc *sc, struct sdmmc_command *cmd) error = cmd->c_error; wakeup(cmd); + SDMMC_UNLOCK(sc); return error; } @@ -570,8 +561,6 @@ 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; @@ -588,8 +577,6 @@ 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)) { @@ -712,14 +699,12 @@ 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 4fdb9261c42..cf891e27ceb 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.11 2008/11/24 07:32:08 blambert Exp $ */ +/* $OpenBSD: sdmmc_io.c,v 1.12 2008/12/02 23:49:54 deraadt Exp $ */ /* * Copyright (c) 2006 Uwe Stuehler <uwe@openbsd.org> @@ -133,8 +133,6 @@ 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) { @@ -536,7 +534,7 @@ sdmmc_io_send_op_cond(struct sdmmc_softc *sc, u_int32_t ocr, u_int32_t *ocrp) int error; int i; - SDMMC_ASSERT_LOCKED(sc); + SDMMC_LOCK(sc); /* * If we change the OCR value, retry the command until the OCR @@ -561,6 +559,7 @@ 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 151aa385704..8beda36b6fb 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.8 2008/11/24 07:32:08 blambert Exp $ */ +/* $OpenBSD: sdmmc_mem.c,v 1.9 2008/12/02 23:49:54 deraadt Exp $ */ /* * Copyright (c) 2006 Uwe Stuehler <uwe@openbsd.org> @@ -51,8 +51,6 @@ 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); @@ -116,8 +114,6 @@ 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 @@ -335,7 +331,7 @@ sdmmc_mem_send_op_cond(struct sdmmc_softc *sc, u_int32_t ocr, int error; int i; - SDMMC_ASSERT_LOCKED(sc); + SDMMC_LOCK(sc); /* * If we change the OCR value, retry the command until the OCR @@ -365,6 +361,7 @@ 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; } @@ -377,8 +374,6 @@ 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 03be9cb10d8..2c18ab4a8bc 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.10 2008/11/24 07:32:08 blambert Exp $ */ +/* $OpenBSD: sdmmc_scsi.c,v 1.11 2008/12/02 23:49:54 deraadt Exp $ */ /* * Copyright (c) 2006 Uwe Stuehler <uwe@openbsd.org> @@ -99,9 +99,10 @@ sdmmc_scsi_attach(struct sdmmc_softc *sc) struct sdmmc_scsi_softc *scbus; struct sdmmc_function *sf; - scbus = malloc(sizeof(*scbus), M_DEVBUF, M_WAITOK | M_ZERO); + scbus = (struct sdmmc_scsi_softc *)malloc(sizeof *scbus, + M_DEVBUF, M_WAITOK | M_ZERO); - scbus->sc_tgt = malloc(sizeof(*scbus->sc_tgt) * + scbus->sc_tgt = (struct sdmmc_scsi_target *)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 26e4f0b99ec..e2016e7fda3 100644 --- a/sys/dev/sdmmc/sdmmcvar.h +++ b/sys/dev/sdmmc/sdmmcvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sdmmcvar.h,v 1.11 2008/11/24 07:32:08 blambert Exp $ */ +/* $OpenBSD: sdmmcvar.h,v 1.12 2008/12/02 23:49:54 deraadt Exp $ */ /* * Copyright (c) 2006 Uwe Stuehler <uwe@openbsd.org> @@ -187,12 +187,6 @@ 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 *); |