All of lore.kernel.org
 help / color / mirror / Atom feed
From: Masahiro Yamada <yamada.masahiro@socionext.com>
To: u-boot@lists.denx.de
Subject: [PATCH v3 05/11] mmc: sdhci: put the aligned buffer pointer to struct sdhci_host
Date: Fri, 14 Feb 2020 16:40:21 +0900	[thread overview]
Message-ID: <20200214074027.19824-6-yamada.masahiro@socionext.com> (raw)
In-Reply-To: <20200214074027.19824-1-yamada.masahiro@socionext.com>

Using the global variable does not look nice.

Add a new field sthci::align_buffer to point to the bounce buffer.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

Changes in v3: None
Changes in v2: None

 drivers/mmc/sdhci.c | 27 +++++++++++++--------------
 include/sdhci.h     |  1 +
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c
index 01fa5a9d4d5b..18fbcb5f1864 100644
--- a/drivers/mmc/sdhci.c
+++ b/drivers/mmc/sdhci.c
@@ -16,12 +16,6 @@
 #include <sdhci.h>
 #include <dm.h>
 
-#if defined(CONFIG_FIXED_SDHCI_ALIGNED_BUFFER)
-void *aligned_buffer = (void *)CONFIG_FIXED_SDHCI_ALIGNED_BUFFER;
-#else
-void *aligned_buffer;
-#endif
-
 static void sdhci_reset(struct sdhci_host *host, u8 mask)
 {
 	unsigned long timeout;
@@ -149,9 +143,10 @@ static void sdhci_prepare_dma(struct sdhci_host *host, struct mmc_data *data,
 		if ((host->quirks & SDHCI_QUIRK_32BIT_DMA_ADDR) &&
 		    (host->start_addr & 0x7) != 0x0) {
 			*is_aligned = 0;
-			host->start_addr = (unsigned long)aligned_buffer;
+			host->start_addr = (unsigned long)host->align_buffer;
 			if (data->flags != MMC_DATA_READ)
-				memcpy(aligned_buffer, data->src, trans_bytes);
+				memcpy(host->align_buffer, data->src,
+				       trans_bytes);
 		}
 
 #if defined(CONFIG_FIXED_SDHCI_ALIGNED_BUFFER)
@@ -160,9 +155,9 @@ static void sdhci_prepare_dma(struct sdhci_host *host, struct mmc_data *data,
 		 * CONFIG_FIXED_SDHCI_ALIGNED_BUFFER is defined
 		 */
 		*is_aligned = 0;
-		host->start_addr = (unsigned long)aligned_buffer;
+		host->start_addr = (unsigned long)host->align_buffer;
 		if (data->flags != MMC_DATA_READ)
-			memcpy(aligned_buffer, data->src, trans_bytes);
+			memcpy(host->align_buffer, data->src, trans_bytes);
 #endif
 		sdhci_writel(host, host->start_addr, SDHCI_DMA_ADDRESS);
 
@@ -381,7 +376,7 @@ static int sdhci_send_command(struct mmc *mmc, struct mmc_cmd *cmd,
 	if (!ret) {
 		if ((host->quirks & SDHCI_QUIRK_32BIT_DMA_ADDR) &&
 				!is_aligned && (data->flags == MMC_DATA_READ))
-			memcpy(data->dest, aligned_buffer, trans_bytes);
+			memcpy(data->dest, host->align_buffer, trans_bytes);
 		return 0;
 	}
 
@@ -630,14 +625,18 @@ static int sdhci_init(struct mmc *mmc)
 
 	sdhci_reset(host, SDHCI_RESET_ALL);
 
-	if ((host->quirks & SDHCI_QUIRK_32BIT_DMA_ADDR) && !aligned_buffer) {
-		aligned_buffer = memalign(8, 512*1024);
-		if (!aligned_buffer) {
+#if defined(CONFIG_FIXED_SDHCI_ALIGNED_BUFFER)
+	host->align_buffer = (void *)CONFIG_FIXED_SDHCI_ALIGNED_BUFFER;
+#else
+	if (host->quirks & SDHCI_QUIRK_32BIT_DMA_ADDR) {
+		host->align_buffer = memalign(8, 512 * 1024);
+		if (!host->align_buffer) {
 			printf("%s: Aligned buffer alloc failed!!!\n",
 			       __func__);
 			return -ENOMEM;
 		}
 	}
+#endif
 
 	sdhci_set_power(host, fls(mmc->cfg->voltages) - 1);
 
diff --git a/include/sdhci.h b/include/sdhci.h
index 01addb7a6036..1358218270b8 100644
--- a/include/sdhci.h
+++ b/include/sdhci.h
@@ -321,6 +321,7 @@ struct sdhci_host {
 	uint	voltages;
 
 	struct mmc_config cfg;
+	void *align_buffer;
 	dma_addr_t start_addr;
 	int flags;
 #define USE_SDMA	(0x1 << 0)
-- 
2.17.1

  parent reply	other threads:[~2020-02-14  7:40 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-14  7:40 [PATCH v3 00/11] mmc: sdhci: code clean-up and fix cache coherency problem Masahiro Yamada
2020-02-14  7:40 ` [PATCH v3 01/11] dma-mapping: fix the prototype of dma_map_single() Masahiro Yamada
2020-02-14  7:40 ` [PATCH v3 02/11] dma-mapping: fix the prototype of dma_unmap_single() Masahiro Yamada
2020-02-14  7:40 ` [PATCH v3 03/11] dma-mapping: move dma_map_(un)single() to <linux/dma-mapping.h> Masahiro Yamada
2020-02-14  7:40 ` [PATCH v3 04/11] dma-mapping: add <asm/dma-mapping.h> for all architectures Masahiro Yamada
2020-02-14  7:40 ` Masahiro Yamada [this message]
2020-02-18 11:19   ` [PATCH v3 05/11] mmc: sdhci: put the aligned buffer pointer to struct sdhci_host Jaehoon Chung
2020-02-14  7:40 ` [PATCH v3 06/11] mmc: sdhci: reduce code duplication for aligned buffer Masahiro Yamada
2020-02-18 11:19   ` Jaehoon Chung
2020-02-14  7:40 ` [PATCH v3 07/11] mmc: sdhci: use lower_32_bit2() and upper_32_bits() for setting adma_addr Masahiro Yamada
2020-02-18 11:19   ` Jaehoon Chung
2020-02-14  7:40 ` [PATCH v3 08/11] mmc: sdhci: remove unneeded casts Masahiro Yamada
2020-02-18 11:20   ` Jaehoon Chung
2020-02-14  7:40 ` [PATCH v3 09/11] mmc: add mmc_get_dma_dir() helper Masahiro Yamada
2020-02-18 11:20   ` Jaehoon Chung
2020-02-14  7:40 ` [PATCH v3 10/11] mmc: sdhci: use dma_map_single() instead of flush_cache() before DMA Masahiro Yamada
2020-02-14  7:40 ` [PATCH v3 11/11] mmc: sdhci: fix missing cache invalidation after reading by DMA Masahiro Yamada

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200214074027.19824-6-yamada.masahiro@socionext.com \
    --to=yamada.masahiro@socionext.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.