Patchwork [U-Boot,v3,3/6] mmc: dcache: allocate cache aligned buffer for scr and switch_status

login
register
mail settings
Submitter Anton staaf
Date Oct. 12, 2011, 11:56 p.m.
Message ID <1318463764-28244-4-git-send-email-robotboy@chromium.org>
Download mbox | patch
Permalink /patch/119331/
State Accepted
Headers show

Comments

Anton staaf - Oct. 12, 2011, 11:56 p.m.
Currently the sd_change_freq function allocates two buffers on the
stack that it passes down to the MMC device driver.  These buffers
could be unaligned to the L1 dcache line size.  This causes problems
when using DMA and with caches enabled.

This patch correctly cache alignes the buffers used for reading the
scr register and switch status values from an MMC device.

Signed-off-by: Anton Staaf <robotboy@chromium.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>
Cc: Lukasz Majewski <l.majewski@samsung.com>
Cc: Mike Frysinger <vapier@gentoo.org>
Cc: Albert ARIBAUD <albert.u.boot@aribaud.net>
---
 drivers/mmc/mmc.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
Mike Frysinger - Oct. 13, 2011, 12:55 a.m.
built fine for me
Acked-by: Mike Frysinger <vapier@gentoo.org>
-mike
Wolfgang Denk - Oct. 25, 2011, 7:25 a.m.
Dear Anton Staaf,

In message <1318463764-28244-4-git-send-email-robotboy@chromium.org> you wrote:
> Currently the sd_change_freq function allocates two buffers on the
> stack that it passes down to the MMC device driver.  These buffers
> could be unaligned to the L1 dcache line size.  This causes problems
> when using DMA and with caches enabled.
> 
> This patch correctly cache alignes the buffers used for reading the
> scr register and switch status values from an MMC device.
> 
> Signed-off-by: Anton Staaf <robotboy@chromium.org>
> Acked-by: Mike Frysinger <vapier@gentoo.org>
> Cc: Lukasz Majewski <l.majewski@samsung.com>
> Cc: Mike Frysinger <vapier@gentoo.org>
> Cc: Albert ARIBAUD <albert.u.boot@aribaud.net>
> ---
>  drivers/mmc/mmc.c |   10 +++++-----
>  1 files changed, 5 insertions(+), 5 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk

Patch

diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index 391bc2b..ba6fbfe 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -702,8 +702,8 @@  int sd_change_freq(struct mmc *mmc)
 {
 	int err;
 	struct mmc_cmd cmd;
-	uint scr[2];
-	uint switch_status[16];
+	ALLOC_CACHE_ALIGN_BUFFER(uint, scr, 2);
+	ALLOC_CACHE_ALIGN_BUFFER(uint, switch_status, 16);
 	struct mmc_data data;
 	int timeout;
 
@@ -731,7 +731,7 @@  int sd_change_freq(struct mmc *mmc)
 	timeout = 3;
 
 retry_scr:
-	data.dest = (char *)&scr;
+	data.dest = (char *)scr;
 	data.blocksize = 8;
 	data.blocks = 1;
 	data.flags = MMC_DATA_READ;
@@ -773,7 +773,7 @@  retry_scr:
 	timeout = 4;
 	while (timeout--) {
 		err = sd_switch(mmc, SD_SWITCH_CHECK, 0, 1,
-				(u8 *)&switch_status);
+				(u8 *)switch_status);
 
 		if (err)
 			return err;
@@ -787,7 +787,7 @@  retry_scr:
 	if (!(__be32_to_cpu(switch_status[3]) & SD_HIGHSPEED_SUPPORTED))
 		return 0;
 
-	err = sd_switch(mmc, SD_SWITCH_SWITCH, 0, 1, (u8 *)&switch_status);
+	err = sd_switch(mmc, SD_SWITCH_SWITCH, 0, 1, (u8 *)switch_status);
 
 	if (err)
 		return err;