From patchwork Tue Aug 23 17:03:57 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton staaf X-Patchwork-Id: 111148 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 68220B6F18 for ; Wed, 24 Aug 2011 03:04:24 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9981E28083; Tue, 23 Aug 2011 19:04:22 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WJd0cejBdDgJ; Tue, 23 Aug 2011 19:04:22 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 69B2A28084; Tue, 23 Aug 2011 19:04:20 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 257BC28084 for ; Tue, 23 Aug 2011 19:04:18 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id r14ZNVyWNzOG for ; Tue, 23 Aug 2011 19:04:17 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from smtp-out.google.com (smtp-out.google.com [74.125.121.67]) by theia.denx.de (Postfix) with ESMTPS id 3C2BD28083 for ; Tue, 23 Aug 2011 19:04:16 +0200 (CEST) Received: from hpaq7.eem.corp.google.com (hpaq7.eem.corp.google.com [172.25.149.7]) by smtp-out.google.com with ESMTP id p7NH4766029355; Tue, 23 Aug 2011 10:04:07 -0700 Received: from servo.mtv.corp.google.com (servo.mtv.corp.google.com [172.22.72.56]) by hpaq7.eem.corp.google.com with ESMTP id p7NH45S4005008; Tue, 23 Aug 2011 10:04:05 -0700 Received: by servo.mtv.corp.google.com (Postfix, from userid 99248) id D37DC13A091; Tue, 23 Aug 2011 10:04:04 -0700 (PDT) From: Anton Staaf To: u-boot@lists.denx.de Date: Tue, 23 Aug 2011 10:03:57 -0700 Message-Id: <1314119037-2835-1-git-send-email-robotboy@chromium.org> X-Mailer: git-send-email 1.7.3.1 X-System-Of-Record: true Cc: Anton Staaf Subject: [U-Boot] [PATCH] mmc: dcache: allocate cache aligned buffer for scr and switch_status X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de 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. Change-Id: Ifa8414f572ef907681bd2d5ff3950285a215357d Signed-off-by: Anton Staaf Cc: Lukasz Majewski Cc: Mike Frysinger Cc: Albert ARIBAUD --- This patch depends on Lukasz Majewski's dcache line size patch sent to the list in: http://patchwork.ozlabs.org/patch/110501/ drivers/mmc/mmc.c | 44 ++++++++++++++++++++++++-------------------- 1 files changed, 24 insertions(+), 20 deletions(-) diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index 7e703c0..55cf9b4 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -699,17 +699,19 @@ int sd_switch(struct mmc *mmc, int mode, int group, u8 value, u8 *resp) int sd_change_freq(struct mmc *mmc) { - int err; + int err = 0; struct mmc_cmd cmd; - uint scr[2]; - uint switch_status[16]; + uint *buffer = memalign(get_dcache_line_size(), 64); struct mmc_data data; int timeout; + if (buffer == NULL) + return -ENOMEM; + mmc->card_caps = 0; if (mmc_host_is_spi(mmc)) - return 0; + goto out; /* Read the SCR to find out if this card supports higher speeds */ cmd.cmdidx = MMC_CMD_APP_CMD; @@ -720,7 +722,7 @@ int sd_change_freq(struct mmc *mmc) err = mmc_send_cmd(mmc, &cmd, NULL); if (err) - return err; + goto out; cmd.cmdidx = SD_CMD_APP_SEND_SCR; cmd.resp_type = MMC_RSP_R1; @@ -730,7 +732,7 @@ int sd_change_freq(struct mmc *mmc) timeout = 3; retry_scr: - data.dest = (char *)&scr; + data.dest = (char *)buffer; data.blocksize = 8; data.blocks = 1; data.flags = MMC_DATA_READ; @@ -741,11 +743,11 @@ retry_scr: if (timeout--) goto retry_scr; - return err; + goto out; } - mmc->scr[0] = __be32_to_cpu(scr[0]); - mmc->scr[1] = __be32_to_cpu(scr[1]); + mmc->scr[0] = __be32_to_cpu(buffer[0]); + mmc->scr[1] = __be32_to_cpu(buffer[1]); switch ((mmc->scr[0] >> 24) & 0xf) { case 0: @@ -767,34 +769,36 @@ retry_scr: /* Version 1.0 doesn't support switching */ if (mmc->version == SD_VERSION_1_0) - return 0; + goto out timeout = 4; while (timeout--) { - err = sd_switch(mmc, SD_SWITCH_CHECK, 0, 1, - (u8 *)&switch_status); + err = sd_switch(mmc, SD_SWITCH_CHECK, 0, 1, (u8 *)buffer); if (err) - return err; + goto out; /* The high-speed function is busy. Try again */ - if (!(__be32_to_cpu(switch_status[7]) & SD_HIGHSPEED_BUSY)) + if (!(__be32_to_cpu(buffer[7]) & SD_HIGHSPEED_BUSY)) break; } /* If high-speed isn't supported, we return */ - if (!(__be32_to_cpu(switch_status[3]) & SD_HIGHSPEED_SUPPORTED)) - return 0; + if (!(__be32_to_cpu(buffer[3]) & SD_HIGHSPEED_SUPPORTED)) + goto out; - err = sd_switch(mmc, SD_SWITCH_SWITCH, 0, 1, (u8 *)&switch_status); + err = sd_switch(mmc, SD_SWITCH_SWITCH, 0, 1, (u8 *)buffer); if (err) - return err; + goto out; - if ((__be32_to_cpu(switch_status[4]) & 0x0f000000) == 0x01000000) + if ((__be32_to_cpu(buffer[4]) & 0x0f000000) == 0x01000000) mmc->card_caps |= MMC_MODE_HS; - return 0; + out: + free(buffer); + + return err; } /* frequency bases */