summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2018-04-26 15:19:42 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2018-04-26 15:19:42 +0200
commitc7e162abd85cd8247894d84b3352189c6d4cd43c (patch)
tree6a445f743e85a0a5ac264cbcf4909de26513452d
parentat91_mci: Fix use of BOARD_MCK (diff)
downloadrtems-libbsd-c7e162abd85cd8247894d84b3352189c6d4cd43c.tar.bz2
mmc: Optimize mmc_wait_for_req()
Use a self-contained RTEMS binary semaphore instead of msleep() and wakeup(). This is itself more efficient and in addition allows the use of mmc_wakeup() in interrupt context.
-rw-r--r--freebsd/sys/dev/mmc/mmc.c12
-rw-r--r--freebsd/sys/dev/mmc/mmcreg.h7
2 files changed, 19 insertions, 0 deletions
diff --git a/freebsd/sys/dev/mmc/mmc.c b/freebsd/sys/dev/mmc/mmc.c
index c19fae7a..023091eb 100644
--- a/freebsd/sys/dev/mmc/mmc.c
+++ b/freebsd/sys/dev/mmc/mmc.c
@@ -394,6 +394,7 @@ mmc_highest_voltage(uint32_t ocr)
static void
mmc_wakeup(struct mmc_request *req)
{
+#ifndef __rtems__
struct mmc_softc *sc;
sc = (struct mmc_softc *)req->done_data;
@@ -401,12 +402,18 @@ mmc_wakeup(struct mmc_request *req)
req->flags |= MMC_REQ_DONE;
MMC_UNLOCK(sc);
wakeup(req);
+#else /* __rtems__ */
+ rtems_binary_semaphore_post(&req->req_done);
+#endif /* __rtems__ */
}
static int
mmc_wait_for_req(struct mmc_softc *sc, struct mmc_request *req)
{
+#ifdef __rtems__
+ rtems_binary_semaphore_init(&req->req_done, "mmc_req_done");
+#endif /* __rtems__ */
req->done = mmc_wakeup;
req->done_data = sc;
if (mmc_debug > 1) {
@@ -418,10 +425,15 @@ mmc_wait_for_req(struct mmc_softc *sc, struct mmc_request *req)
printf("\n");
}
MMCBR_REQUEST(device_get_parent(sc->dev), sc->dev, req);
+#ifndef __rtems__
MMC_LOCK(sc);
while ((req->flags & MMC_REQ_DONE) == 0)
msleep(req, &sc->sc_mtx, 0, "mmcreq", 0);
MMC_UNLOCK(sc);
+#else /* __rtems__ */
+ rtems_binary_semaphore_wait(&req->req_done);
+ rtems_binary_semaphore_destroy(&req->req_done);
+#endif /* __rtems__ */
if (mmc_debug > 2 || (mmc_debug > 0 && req->cmd->error != MMC_ERR_NONE))
device_printf(sc->dev, "CMD%d RESULT: %d\n",
req->cmd->opcode, req->cmd->error);
diff --git a/freebsd/sys/dev/mmc/mmcreg.h b/freebsd/sys/dev/mmc/mmcreg.h
index 359f31d5..39680ad6 100644
--- a/freebsd/sys/dev/mmc/mmcreg.h
+++ b/freebsd/sys/dev/mmc/mmcreg.h
@@ -54,6 +54,9 @@
#ifndef DEV_MMC_MMCREG_H
#define DEV_MMC_MMCREG_H
+#ifdef __rtems__
+#include <rtems/thread.h>
+#endif /* __rtems__ */
/*
* This file contains the register definitions for the mmc and sd buses.
@@ -173,8 +176,12 @@ struct mmc_request {
struct mmc_command *stop;
void (*done)(struct mmc_request *); /* Completion function */
void *done_data; /* requestor set data */
+#ifndef __rtems__
uint32_t flags;
#define MMC_REQ_DONE 1
+#else /* __rtems__ */
+ rtems_binary_semaphore req_done;
+#endif /* __rtems__ */
};
/* Command definitions */