With the enabling of data caches in U-Boot flushing and invalidating MMC
buffers will need to be done in all MMC drivers.  These utility functions
simplify that task slightly.

Signed-off-by: Anton Staaf <robot...@chromium.org>
Cc: Andy Fleming <aflem...@gmail.com>
---
 drivers/mmc/mmc.c |   23 +++++++++++++++++++++++
 include/mmc.h     |   10 ++++++++++
 2 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index 391bc2b..5001bb1 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -47,6 +47,29 @@ int __board_mmc_getcd(u8 *cd, struct mmc *mmc) {
 int board_mmc_getcd(u8 *cd, struct mmc *mmc)__attribute__((weak,
        alias("__board_mmc_getcd")));
 
+/*
+ * Flush the data cache lines associated with the given mmc_data structs 
buffer.
+ */
+void mmc_dcache_flush(struct mmc_data *data)
+{
+       unsigned long start = (unsigned long) data->dest;
+       unsigned long stop = start + (data->blocksize * data->blocks);
+
+       flush_dcache_range(start, stop);
+}
+
+/*
+ * Invalidate the data cache lines associated with the given mmc_data structs
+ * buffer.
+ */
+void mmc_dcache_invalidate(struct mmc_data *data)
+{
+       unsigned long start = (unsigned long) data->dest;
+       unsigned long stop = start + (data->blocksize * data->blocks);
+
+       invalidate_dcache_range(start, stop);
+}
+
 int mmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
 {
 #ifdef CONFIG_MMC_TRACE
diff --git a/include/mmc.h b/include/mmc.h
index 53aff9b..94be2e1 100644
--- a/include/mmc.h
+++ b/include/mmc.h
@@ -315,6 +315,16 @@ int get_mmc_num(void);
 int board_mmc_getcd(u8 *cd, struct mmc *mmc);
 int mmc_switch_part(int dev_num, unsigned int part_num);
 
+/*
+ * Given an mmc_data struct these flush and invalidate the cache range covered
+ * by the mmc_data buffer.  A flush should be done before starting a DMA
+ * transfer from the mmc_data struct.  An invalidate should be done after a
+ * DMA transfer finishes that wrote to the memory referenced in the mmc_data
+ * struct.
+ */
+void mmc_dcache_flush(struct mmc_data *data);
+void mmc_dcache_invalidate(struct mmc_data *data);
+
 #ifdef CONFIG_GENERIC_MMC
 int atmel_mci_init(void *regs);
 #define mmc_host_is_spi(mmc)   ((mmc)->host_caps & MMC_MODE_SPI)
-- 
1.7.3.1

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to