diff mbox series

[v3,05/11] mmc: sdhci: put the aligned buffer pointer to struct sdhci_host

Message ID 20200214074027.19824-6-yamada.masahiro@socionext.com
State Accepted
Commit c8cc18b7a7e05da529a3365bfa463e5c5c83efe8
Headers show
Series mmc: sdhci: code clean-up and fix cache coherency problem | expand

Commit Message

Masahiro Yamada Feb. 14, 2020, 7:40 a.m. UTC
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 at 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(-)

Comments

Jaehoon Chung Feb. 18, 2020, 11:19 a.m. UTC | #1
On 2/14/20 4:40 PM, Masahiro Yamada wrote:
> 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 at socionext.com>

Reviewed-by: Jaehoon Chung <jh80.chung at samsung.com>

Best Regards,
Jaehoon Chung

> ---
> 
> 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)
>
diff mbox series

Patch

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)