public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] mmc: dcache: Replace ext_csd buffer with cache aligned one
@ 2011-08-12  8:25 Lukasz Majewski
  2011-08-12  9:07 ` Albert ARIBAUD
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Lukasz Majewski @ 2011-08-12  8:25 UTC (permalink / raw)
  To: u-boot

This commit replaces the ext_csd buffer allocated as an automatic
variable with one cache aligned. The ext_csd might be allocated with
alignment not equal to the L1 D cache alignment.

The memalign from common/dlmalloc.c is allowing for buffer allocation
with proper cache alignment.

The common/dlmalloc.c [c|m]alloc alignment is hardwired to 8 bytes,
so out of the box functions cannot be safely used with L1 D cache.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
CC: Andy Fleming <afleming@gmail.com>
CC: Albert ARIBAUD <albert.u.boot@aribaud.net>
---
 drivers/mmc/mmc.c |   55 +++++++++++++++++++++++++++++++++-------------------
 1 files changed, 35 insertions(+), 20 deletions(-)

diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index 7e703c0..422a0f9 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -29,6 +29,7 @@
 #include <mmc.h>
 #include <part.h>
 #include <malloc.h>
+#include <errno.h>
 #include <linux/list.h>
 #include <div64.h>
 
@@ -617,42 +618,45 @@ int mmc_switch(struct mmc *mmc, u8 set, u8 index, u8 value)
 
 int mmc_change_freq(struct mmc *mmc)
 {
-	char ext_csd[512];
 	char cardtype;
 	int err;
+	char *ext_csd = memalign(get_dcache_line_size(), mmc->read_bl_len);
+
+	if (!ext_csd)
+		return -ENOMEM;
 
 	mmc->card_caps = 0;
 
 	if (mmc_host_is_spi(mmc))
-		return 0;
+		goto exit;
 
 	/* Only version 4 supports high-speed */
 	if (mmc->version < MMC_VERSION_4)
-		return 0;
+		goto exit;
 
 	mmc->card_caps |= MMC_MODE_4BIT;
 
 	err = mmc_send_ext_csd(mmc, ext_csd);
 
 	if (err)
-		return err;
+		goto error;
 
 	cardtype = ext_csd[196] & 0xf;
 
 	err = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, 1);
 
 	if (err)
-		return err;
+		goto error;
 
 	/* Now check to see that it worked */
 	err = mmc_send_ext_csd(mmc, ext_csd);
 
 	if (err)
-		return err;
+		goto error;
 
 	/* No high-speed support */
 	if (!ext_csd[185])
-		return 0;
+		goto exit;
 
 	/* High Speed is set, there are two types: 52MHz and 26MHz */
 	if (cardtype & MMC_HS_52MHZ)
@@ -660,7 +664,11 @@ int mmc_change_freq(struct mmc *mmc)
 	else
 		mmc->card_caps |= MMC_MODE_HS;
 
-	return 0;
+ exit:
+	err = 0;
+ error:
+	free(ext_csd);
+	return err;
 }
 
 int mmc_switch_part(int dev_num, unsigned int part_num)
@@ -855,11 +863,15 @@ void mmc_set_bus_width(struct mmc *mmc, uint width)
 
 int mmc_startup(struct mmc *mmc)
 {
-	int err;
+	int err, i;
 	uint mult, freq;
 	u64 cmult, csize, capacity;
 	struct mmc_cmd cmd;
-	char ext_csd[512];
+	char *ext_csd = memalign(get_dcache_line_size(), mmc->read_bl_len);
+
+	if (!ext_csd)
+		return -ENOMEM;
+
 	int timeout = 1000;
 
 #ifdef CONFIG_MMC_SPI_CRC_ON
@@ -871,7 +883,7 @@ int mmc_startup(struct mmc *mmc)
 		err = mmc_send_cmd(mmc, &cmd, NULL);
 
 		if (err)
-			return err;
+			goto error;
 	}
 #endif
 
@@ -885,7 +897,7 @@ int mmc_startup(struct mmc *mmc)
 	err = mmc_send_cmd(mmc, &cmd, NULL);
 
 	if (err)
-		return err;
+		goto error;
 
 	memcpy(mmc->cid, cmd.response, 16);
 
@@ -903,7 +915,7 @@ int mmc_startup(struct mmc *mmc)
 		err = mmc_send_cmd(mmc, &cmd, NULL);
 
 		if (err)
-			return err;
+			goto error;
 
 		if (IS_SD(mmc))
 			mmc->rca = (cmd.response[0] >> 16) & 0xffff;
@@ -921,7 +933,7 @@ int mmc_startup(struct mmc *mmc)
 	mmc_send_status(mmc, timeout);
 
 	if (err)
-		return err;
+		goto error;
 
 	mmc->csd[0] = cmd.response[0];
 	mmc->csd[1] = cmd.response[1];
@@ -994,7 +1006,7 @@ int mmc_startup(struct mmc *mmc)
 		err = mmc_send_cmd(mmc, &cmd, NULL);
 
 		if (err)
-			return err;
+			goto error;
 	}
 
 	/*
@@ -1044,7 +1056,7 @@ int mmc_startup(struct mmc *mmc)
 		err = mmc_change_freq(mmc);
 
 	if (err)
-		return err;
+		goto error;
 
 	/* Restrict card's capabilities by what the host can do */
 	mmc->card_caps &= mmc->host_caps;
@@ -1058,7 +1070,7 @@ int mmc_startup(struct mmc *mmc)
 
 			err = mmc_send_cmd(mmc, &cmd, NULL);
 			if (err)
-				return err;
+				goto error;
 
 			cmd.cmdidx = SD_CMD_APP_SET_BUS_WIDTH;
 			cmd.resp_type = MMC_RSP_R1;
@@ -1066,7 +1078,7 @@ int mmc_startup(struct mmc *mmc)
 			cmd.flags = 0;
 			err = mmc_send_cmd(mmc, &cmd, NULL);
 			if (err)
-				return err;
+				goto error;
 
 			mmc_set_bus_width(mmc, 4);
 		}
@@ -1083,7 +1095,7 @@ int mmc_startup(struct mmc *mmc)
 					EXT_CSD_BUS_WIDTH_4);
 
 			if (err)
-				return err;
+				goto error;
 
 			mmc_set_bus_width(mmc, 4);
 		} else if (mmc->card_caps & MMC_MODE_8BIT) {
@@ -1093,7 +1105,7 @@ int mmc_startup(struct mmc *mmc)
 					EXT_CSD_BUS_WIDTH_8);
 
 			if (err)
-				return err;
+				goto error;
 
 			mmc_set_bus_width(mmc, 8);
 		}
@@ -1122,6 +1134,9 @@ int mmc_startup(struct mmc *mmc)
 	init_part(&mmc->block_dev);
 
 	return 0;
+ error:
+	free(ext_csd);
+	return err;
 }
 
 int mmc_send_if_cond(struct mmc *mmc)
-- 
1.7.2.3

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-08-17  9:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-12  8:25 [U-Boot] [PATCH] mmc: dcache: Replace ext_csd buffer with cache aligned one Lukasz Majewski
2011-08-12  9:07 ` Albert ARIBAUD
2011-08-12  9:35   ` Lukasz Majewski
2011-08-12  9:50     ` Albert ARIBAUD
2011-08-17  2:43 ` Andy Fleming
2011-08-17  9:33 ` [U-Boot] [PATCH v2] " Lukasz Majewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox