Hi,

apparently one of the main concepts in the SDMMC I/O subsystem is that
the driver attached to an SDIO card always holds the lock and only
releases it if it detaches.  Now with that in mind, some time ago the
sdmmc_io_function_disable() and sdmmc_io_function_ready() was changed
to only assert the write lock and not take it.  The funny thing though
is that sdmmc_io_function_enable() wasn't changed and still enters and
exits the lock, and then calls _ready(), which asserts the write lock.
This does not seem to be right.  Similarly, the interrupt code does
the enter/exit dance, even though it should be called out of a context
where the lock is taken.  I propose to remove the dance and change
those to simple write lock assertions.  Apparently there is no SDIO
driver yet/anymore which would trigger those issues.

Opinions?

Patrick

diff --git a/sys/dev/sdmmc/sdmmc_io.c b/sys/dev/sdmmc/sdmmc_io.c
index 110e9f15e1d..6a25bfae33a 100644
--- a/sys/dev/sdmmc/sdmmc_io.c
+++ b/sys/dev/sdmmc/sdmmc_io.c
@@ -236,14 +236,14 @@ sdmmc_io_function_enable(struct sdmmc_function *sf)
        u_int8_t rv;
        int retry = 5;
 
+       rw_assert_wrlock(&sc->sc_lock);
+
        if (sf->number == 0)
                return 0;       /* FN0 is always enabled */
 
-       rw_enter_write(&sc->sc_lock);
        rv = sdmmc_io_read_1(sf0, SD_IO_CCCR_FN_ENABLE);
        rv |= (1<<sf->number);
        sdmmc_io_write_1(sf0, SD_IO_CCCR_FN_ENABLE, rv);
-       rw_exit(&sc->sc_lock);
 
        while (!sdmmc_io_function_ready(sf) && retry-- > 0)
                tsleep(&lbolt, PPAUSE, "pause", 0);
@@ -621,11 +621,11 @@ sdmmc_intr_enable(struct sdmmc_function *sf)
        struct sdmmc_function *sf0 = sc->sc_fn0;
        u_int8_t imask;
 
-       rw_enter_write(&sc->sc_lock);
+       rw_assert_wrlock(&sc->sc_lock);
+
        imask = sdmmc_io_read_1(sf0, SD_IO_CCCR_INT_ENABLE);
        imask |= 1 << sf->number;
        sdmmc_io_write_1(sf0, SD_IO_CCCR_INT_ENABLE, imask);
-       rw_exit(&sc->sc_lock);
 }
 
 void
@@ -635,11 +635,11 @@ sdmmc_intr_disable(struct sdmmc_function *sf)
        struct sdmmc_function *sf0 = sc->sc_fn0;
        u_int8_t imask;
 
-       rw_enter_write(&sc->sc_lock);
+       rw_assert_wrlock(&sc->sc_lock);
+
        imask = sdmmc_io_read_1(sf0, SD_IO_CCCR_INT_ENABLE);
        imask &= ~(1 << sf->number);
        sdmmc_io_write_1(sf0, SD_IO_CCCR_INT_ENABLE, imask);
-       rw_exit(&sc->sc_lock);
 }
 
 /*

Reply via email to