Commit e66e61cb authored by Russell King's avatar Russell King Committed by Ulf Hansson

mmc: sdhci: allocate alignment and DMA descriptor buffer together

Allocate both the alignment and DMA descriptor buffers together.  The
size of the alignment buffer will always be aligned to the hosts
required alignment, which gives appropriate alignment to the DMA
descriptors.

We have a maximum of 128 segments, and a maximum alignment of 64 bits.
This gives a maximum alignment buffer size of 1024 bytes.

The DMA descriptors are a maximum of 12 bytes, and we allocate 128 * 2
+ 1 of these, which gives a maximum DMA descriptor buffer size of 3084
bytes.

This means the allocation for a 4K page sized system will be an order-1
allocation, since the resulting overall size is 4108.  This is more
prone to failure than page-sized allocations, but since this allocation
commonly occurs at startup, the chances of failure are small.
Signed-off-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
[ Changed to check ADMA table alignment ]
Signed-off-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
Tested-by: default avatarGregory CLEMENT <gregory.clement@free-electrons.com>
Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
parent 7f05538a
...@@ -2960,6 +2960,9 @@ int sdhci_add_host(struct sdhci_host *host) ...@@ -2960,6 +2960,9 @@ int sdhci_add_host(struct sdhci_host *host)
host->flags &= ~SDHCI_USE_SDMA; host->flags &= ~SDHCI_USE_SDMA;
if (host->flags & SDHCI_USE_ADMA) { if (host->flags & SDHCI_USE_ADMA) {
dma_addr_t dma;
void *buf;
/* /*
* The DMA descriptor table size is calculated as the maximum * The DMA descriptor table size is calculated as the maximum
* number of segments times 2, to allow for an alignment * number of segments times 2, to allow for an alignment
...@@ -2975,45 +2978,28 @@ int sdhci_add_host(struct sdhci_host *host) ...@@ -2975,45 +2978,28 @@ int sdhci_add_host(struct sdhci_host *host)
SDHCI_ADMA2_32_DESC_SZ; SDHCI_ADMA2_32_DESC_SZ;
host->desc_sz = SDHCI_ADMA2_32_DESC_SZ; host->desc_sz = SDHCI_ADMA2_32_DESC_SZ;
} }
host->adma_table = dma_alloc_coherent(mmc_dev(mmc),
host->adma_table_sz,
&host->adma_addr,
GFP_KERNEL);
host->align_buffer_sz = SDHCI_MAX_SEGS * SDHCI_ADMA2_ALIGN; host->align_buffer_sz = SDHCI_MAX_SEGS * SDHCI_ADMA2_ALIGN;
host->align_buffer = dma_alloc_coherent(mmc_dev(mmc), buf = dma_alloc_coherent(mmc_dev(mmc), host->align_buffer_sz +
host->align_buffer_sz, host->adma_table_sz, &dma, GFP_KERNEL);
&host->align_addr, if (!buf) {
GFP_KERNEL);
if (!host->adma_table || !host->align_buffer) {
if (host->adma_table)
dma_free_coherent(mmc_dev(mmc),
host->adma_table_sz,
host->adma_table,
host->adma_addr);
if (host->align_buffer)
dma_free_coherent(mmc_dev(mmc),
host->align_buffer_sz,
host->align_buffer,
host->align_addr);
pr_warn("%s: Unable to allocate ADMA buffers - falling back to standard DMA\n", pr_warn("%s: Unable to allocate ADMA buffers - falling back to standard DMA\n",
mmc_hostname(mmc)); mmc_hostname(mmc));
host->flags &= ~SDHCI_USE_ADMA; host->flags &= ~SDHCI_USE_ADMA;
host->adma_table = NULL; } else if ((dma + host->align_buffer_sz) &
host->align_buffer = NULL; (SDHCI_ADMA2_DESC_ALIGN - 1)) {
} else if (host->adma_addr & (SDHCI_ADMA2_DESC_ALIGN - 1)) {
pr_warn("%s: unable to allocate aligned ADMA descriptor\n", pr_warn("%s: unable to allocate aligned ADMA descriptor\n",
mmc_hostname(mmc)); mmc_hostname(mmc));
host->flags &= ~SDHCI_USE_ADMA; host->flags &= ~SDHCI_USE_ADMA;
dma_free_coherent(mmc_dev(mmc), host->adma_table_sz, dma_free_coherent(mmc_dev(mmc), host->align_buffer_sz +
host->adma_table, host->adma_addr); host->adma_table_sz, buf, dma);
dma_free_coherent(mmc_dev(mmc), host->align_buffer_sz, } else {
host->align_buffer, host->align_addr); host->align_buffer = buf;
host->adma_table = NULL; host->align_addr = dma;
host->align_buffer = NULL;
}
/* dma_alloc_coherent returns page aligned and sized buffers */ host->adma_table = buf + host->align_buffer_sz;
BUG_ON(host->align_addr & SDHCI_ADMA2_MASK); host->adma_addr = dma + host->align_buffer_sz;
}
} }
/* /*
...@@ -3473,12 +3459,10 @@ void sdhci_remove_host(struct sdhci_host *host, int dead) ...@@ -3473,12 +3459,10 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)
if (!IS_ERR(mmc->supply.vqmmc)) if (!IS_ERR(mmc->supply.vqmmc))
regulator_disable(mmc->supply.vqmmc); regulator_disable(mmc->supply.vqmmc);
if (host->adma_table)
dma_free_coherent(mmc_dev(mmc), host->adma_table_sz,
host->adma_table, host->adma_addr);
if (host->align_buffer) if (host->align_buffer)
dma_free_coherent(mmc_dev(mmc), host->align_buffer_sz, dma_free_coherent(mmc_dev(mmc), host->align_buffer_sz +
host->align_buffer, host->align_addr); host->adma_table_sz, host->align_buffer,
host->align_addr);
host->adma_table = NULL; host->adma_table = NULL;
host->align_buffer = NULL; host->align_buffer = NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment