Skip to content

Commit b960bc4

Browse files
Nicolin Chenstorulf
authored andcommitted
mmc: tegra: Implement ->set_dma_mask()
The SDHCI controller on Tegra186 supports 40-bit addressing, which is usually enough to address all of system memory. However, if the SDHCI controller is behind an IOMMU, the address space can go beyond. This happens on Tegra186 and later where the ARM SMMU has an input address space of 48 bits. If the DMA API is backed by this ARM SMMU, the top- down IOVA allocator will cause IOV addresses to be returned that the SDHCI controller cannot access. Unfortunately, prior to the introduction of the ->set_dma_mask() host operation, the SDHCI core would set either a 64-bit DMA mask if the controller claimed to support 64-bit addressing, or a 32-bit DMA mask otherwise. Since the full 64 bits cannot be addressed on Tegra, this had to be worked around in commit 68481a7 ("mmc: tegra: Mark 64 bit dma broken on Tegra186") by setting the SDHCI_QUIRK2_BROKEN_64_BIT_DMA quirk, which effectively restricts the DMA mask to 32 bits. One disadvantage of this is that dma_map_*() APIs will now try to use the swiotlb to bounce DMA to addresses beyond of the controller's DMA mask. This in turn caused degraded performance and can lead to situations where the swiotlb buffer is exhausted, which in turn leads to DMA transfers to fail. With the recent introduction of the ->set_dma_mask() host operation, this can now be properly fixed. For each generation of Tegra, the exact supported DMA mask can be configured. This kills two birds with one stone: it avoids the use of bounce buffers because system memory never exceeds the addressable memory range of the SDHCI controllers on these devices, and at the same time when an IOMMU is involved, it prevents IOV addresses from being allocated beyond the addressible range of the controllers. Since the DMA mask is now properly handled, the 64-bit DMA quirk can be removed. Signed-off-by: Nicolin Chen <[email protected]> [[email protected]: provide more background in commit message] Tested-by: Nicolin Chen <[email protected]> Acked-by: Adrian Hunter <[email protected]> Signed-off-by: Thierry Reding <[email protected]> Cc: [email protected] # v4.15 + Signed-off-by: Ulf Hansson <[email protected]>
1 parent 4ee7dde commit b960bc4

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

drivers/mmc/host/sdhci-tegra.c

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
#include <linux/delay.h>
7+
#include <linux/dma-mapping.h>
78
#include <linux/err.h>
89
#include <linux/module.h>
910
#include <linux/init.h>
@@ -104,6 +105,7 @@
104105

105106
struct sdhci_tegra_soc_data {
106107
const struct sdhci_pltfm_data *pdata;
108+
u64 dma_mask;
107109
u32 nvquirks;
108110
u8 min_tap_delay;
109111
u8 max_tap_delay;
@@ -1233,11 +1235,25 @@ static const struct cqhci_host_ops sdhci_tegra_cqhci_ops = {
12331235
.update_dcmd_desc = sdhci_tegra_update_dcmd_desc,
12341236
};
12351237

1238+
static int tegra_sdhci_set_dma_mask(struct sdhci_host *host)
1239+
{
1240+
struct sdhci_pltfm_host *platform = sdhci_priv(host);
1241+
struct sdhci_tegra *tegra = sdhci_pltfm_priv(platform);
1242+
const struct sdhci_tegra_soc_data *soc = tegra->soc_data;
1243+
struct device *dev = mmc_dev(host->mmc);
1244+
1245+
if (soc->dma_mask)
1246+
return dma_set_mask_and_coherent(dev, soc->dma_mask);
1247+
1248+
return 0;
1249+
}
1250+
12361251
static const struct sdhci_ops tegra_sdhci_ops = {
12371252
.get_ro = tegra_sdhci_get_ro,
12381253
.read_w = tegra_sdhci_readw,
12391254
.write_l = tegra_sdhci_writel,
12401255
.set_clock = tegra_sdhci_set_clock,
1256+
.set_dma_mask = tegra_sdhci_set_dma_mask,
12411257
.set_bus_width = sdhci_set_bus_width,
12421258
.reset = tegra_sdhci_reset,
12431259
.platform_execute_tuning = tegra_sdhci_execute_tuning,
@@ -1257,6 +1273,7 @@ static const struct sdhci_pltfm_data sdhci_tegra20_pdata = {
12571273

12581274
static const struct sdhci_tegra_soc_data soc_data_tegra20 = {
12591275
.pdata = &sdhci_tegra20_pdata,
1276+
.dma_mask = DMA_BIT_MASK(32),
12601277
.nvquirks = NVQUIRK_FORCE_SDHCI_SPEC_200 |
12611278
NVQUIRK_ENABLE_BLOCK_GAP_DET,
12621279
};
@@ -1283,6 +1300,7 @@ static const struct sdhci_pltfm_data sdhci_tegra30_pdata = {
12831300

12841301
static const struct sdhci_tegra_soc_data soc_data_tegra30 = {
12851302
.pdata = &sdhci_tegra30_pdata,
1303+
.dma_mask = DMA_BIT_MASK(32),
12861304
.nvquirks = NVQUIRK_ENABLE_SDHCI_SPEC_300 |
12871305
NVQUIRK_ENABLE_SDR50 |
12881306
NVQUIRK_ENABLE_SDR104 |
@@ -1295,6 +1313,7 @@ static const struct sdhci_ops tegra114_sdhci_ops = {
12951313
.write_w = tegra_sdhci_writew,
12961314
.write_l = tegra_sdhci_writel,
12971315
.set_clock = tegra_sdhci_set_clock,
1316+
.set_dma_mask = tegra_sdhci_set_dma_mask,
12981317
.set_bus_width = sdhci_set_bus_width,
12991318
.reset = tegra_sdhci_reset,
13001319
.platform_execute_tuning = tegra_sdhci_execute_tuning,
@@ -1316,6 +1335,7 @@ static const struct sdhci_pltfm_data sdhci_tegra114_pdata = {
13161335

13171336
static const struct sdhci_tegra_soc_data soc_data_tegra114 = {
13181337
.pdata = &sdhci_tegra114_pdata,
1338+
.dma_mask = DMA_BIT_MASK(32),
13191339
};
13201340

13211341
static const struct sdhci_pltfm_data sdhci_tegra124_pdata = {
@@ -1325,22 +1345,13 @@ static const struct sdhci_pltfm_data sdhci_tegra124_pdata = {
13251345
SDHCI_QUIRK_NO_HISPD_BIT |
13261346
SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC |
13271347
SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN,
1328-
.quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
1329-
/*
1330-
* The TRM states that the SD/MMC controller found on
1331-
* Tegra124 can address 34 bits (the maximum supported by
1332-
* the Tegra memory controller), but tests show that DMA
1333-
* to or from above 4 GiB doesn't work. This is possibly
1334-
* caused by missing programming, though it's not obvious
1335-
* what sequence is required. Mark 64-bit DMA broken for
1336-
* now to fix this for existing users (e.g. Nyan boards).
1337-
*/
1338-
SDHCI_QUIRK2_BROKEN_64_BIT_DMA,
1348+
.quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN,
13391349
.ops = &tegra114_sdhci_ops,
13401350
};
13411351

13421352
static const struct sdhci_tegra_soc_data soc_data_tegra124 = {
13431353
.pdata = &sdhci_tegra124_pdata,
1354+
.dma_mask = DMA_BIT_MASK(34),
13441355
};
13451356

13461357
static const struct sdhci_ops tegra210_sdhci_ops = {
@@ -1349,6 +1360,7 @@ static const struct sdhci_ops tegra210_sdhci_ops = {
13491360
.write_w = tegra210_sdhci_writew,
13501361
.write_l = tegra_sdhci_writel,
13511362
.set_clock = tegra_sdhci_set_clock,
1363+
.set_dma_mask = tegra_sdhci_set_dma_mask,
13521364
.set_bus_width = sdhci_set_bus_width,
13531365
.reset = tegra_sdhci_reset,
13541366
.set_uhs_signaling = tegra_sdhci_set_uhs_signaling,
@@ -1369,6 +1381,7 @@ static const struct sdhci_pltfm_data sdhci_tegra210_pdata = {
13691381

13701382
static const struct sdhci_tegra_soc_data soc_data_tegra210 = {
13711383
.pdata = &sdhci_tegra210_pdata,
1384+
.dma_mask = DMA_BIT_MASK(34),
13721385
.nvquirks = NVQUIRK_NEEDS_PAD_CONTROL |
13731386
NVQUIRK_HAS_PADCALIB |
13741387
NVQUIRK_DIS_CARD_CLK_CONFIG_TAP |
@@ -1383,6 +1396,7 @@ static const struct sdhci_ops tegra186_sdhci_ops = {
13831396
.read_w = tegra_sdhci_readw,
13841397
.write_l = tegra_sdhci_writel,
13851398
.set_clock = tegra_sdhci_set_clock,
1399+
.set_dma_mask = tegra_sdhci_set_dma_mask,
13861400
.set_bus_width = sdhci_set_bus_width,
13871401
.reset = tegra_sdhci_reset,
13881402
.set_uhs_signaling = tegra_sdhci_set_uhs_signaling,
@@ -1398,20 +1412,13 @@ static const struct sdhci_pltfm_data sdhci_tegra186_pdata = {
13981412
SDHCI_QUIRK_NO_HISPD_BIT |
13991413
SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC |
14001414
SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN,
1401-
.quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
1402-
/* SDHCI controllers on Tegra186 support 40-bit addressing.
1403-
* IOVA addresses are 48-bit wide on Tegra186.
1404-
* With 64-bit dma mask used for SDHCI, accesses can
1405-
* be broken. Disable 64-bit dma, which would fall back
1406-
* to 32-bit dma mask. Ideally 40-bit dma mask would work,
1407-
* But it is not supported as of now.
1408-
*/
1409-
SDHCI_QUIRK2_BROKEN_64_BIT_DMA,
1415+
.quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN,
14101416
.ops = &tegra186_sdhci_ops,
14111417
};
14121418

14131419
static const struct sdhci_tegra_soc_data soc_data_tegra186 = {
14141420
.pdata = &sdhci_tegra186_pdata,
1421+
.dma_mask = DMA_BIT_MASK(40),
14151422
.nvquirks = NVQUIRK_NEEDS_PAD_CONTROL |
14161423
NVQUIRK_HAS_PADCALIB |
14171424
NVQUIRK_DIS_CARD_CLK_CONFIG_TAP |
@@ -1424,6 +1431,7 @@ static const struct sdhci_tegra_soc_data soc_data_tegra186 = {
14241431

14251432
static const struct sdhci_tegra_soc_data soc_data_tegra194 = {
14261433
.pdata = &sdhci_tegra186_pdata,
1434+
.dma_mask = DMA_BIT_MASK(39),
14271435
.nvquirks = NVQUIRK_NEEDS_PAD_CONTROL |
14281436
NVQUIRK_HAS_PADCALIB |
14291437
NVQUIRK_DIS_CARD_CLK_CONFIG_TAP |

0 commit comments

Comments
 (0)