Hi,
I'd like to understand why of_dma_configure() is limiting the dma and coherent masks
instead of overriding them.
see commits
a5516219b102 ("of/platform: Initialise default DMA masks")
ee7b1f31200d ("of: fix DMA mask generation")
In of_platform_device_create_pdata(), we initialize both masks to 32-bits unconditionally,
which is fine to support legacy cases.
ÂÂÂÂdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
ÂÂÂÂÂÂÂ if (!dev->dev.dma_mask)
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ dev->dev.dma_mask = &dev->dev.coherent_dma_mask;
Then in of_dma_configure() we limit it like so.
ÂÂÂÂÂÂÂ dev->coherent_dma_mask &= mask;
ÂÂÂÂÂÂÂ *dev->dma_mask &= mask;
This way, legitimate devices which correctly set dma-ranges in DT
will never get a dma_mask above 32-bits at all. How is this expected to work?
For a test, I added this in dra7.dtsi sata node. (NOTE: CONFIG_ARM_LPAE=y)
diff --git a/arch/arm/boot/dts/dra7.dtsi b/arch/arm/boot/dts/dra7.dtsi
index 93aa65c75b45..cd8c6cea23d5 100644
--- a/arch/arm/boot/dts/dra7.dtsi
+++ b/arch/arm/boot/dts/dra7.dtsi
@@ -571,6 +571,8 @@
ÂÂÂÂÂÂÂÂ sata: sata@4a141100 {
ÂÂÂÂÂÂÂÂÂÂÂÂ compatible = "snps,dwc-ahci";
ÂÂÂÂÂÂÂÂÂÂÂÂ reg = <0x4a140000 0x1100>, <0x4a141100 0x7>;
+ÂÂÂÂÂÂÂÂÂÂÂ #size-cells = <2>;
+ÂÂÂÂÂÂÂÂÂÂÂ dma-ranges = <0x00000000 0x00000000 0x10 0x00000000>;
ÂÂÂÂÂÂÂÂÂÂÂÂ interrupts = <GIC_SPI 49 IRQ_TYPE_LEVEL_HIGH>;
ÂÂÂÂÂÂÂÂÂÂÂÂ phys = <&sata_phy>;
ÂÂÂÂÂÂÂÂÂÂÂÂ phy-names = "sata-phy";
----------------------------- drivers/of/device.c -----------------------------
index e9127db7b067..1072cebad57a 100644
@@ -95,6 +95,7 @@ int of_dma_configure(struct device *dev, struct device_node *np, bool force_dma)
ÂÂÂÂ const struct iommu_ops *iommu;
ÂÂÂÂ u64 mask, end;
+ÂÂÂ dev_info(dev, "of_dma_configure\n");
ÂÂÂÂ ret = of_dma_get_range(np, &dma_addr, &paddr, &size);
ÂÂÂÂ if (ret < 0) {
ÂÂÂÂÂÂÂÂ /*
@@ -123,7 +124,8 @@ int of_dma_configure(struct device *dev, struct device_node *np, bool force_dma)
ÂÂÂÂÂÂÂÂÂÂÂÂ dev_err(dev, "Adjusted size 0x%llx invalid\n", size);
ÂÂÂÂÂÂÂÂÂÂÂÂ return -EINVAL;
ÂÂÂÂÂÂÂÂ }
-ÂÂÂÂÂÂÂ dev_dbg(dev, "dma_pfn_offset(%#08lx)\n", offset);
+ÂÂÂÂÂÂÂ dev_info(dev, "dma %llx paddr %llx size %llx\n", dma_addr, paddr, size);
+ÂÂÂÂÂÂÂ dev_info(dev, "dma_pfn_offset(%#08lx)\n", offset);
ÂÂÂÂ }
ÂÂÂÂ /*
@@ -152,6 +154,8 @@ int of_dma_configure(struct device *dev, struct device_node *np, bool force_dma)
ÂÂÂÂ mask = DMA_BIT_MASK(ilog2(end) + 1);
ÂÂÂÂ dev->coherent_dma_mask &= mask;
ÂÂÂÂ *dev->dma_mask &= mask;
+
+ÂÂÂ dev_info(dev, "end %llx, mask %llx\n", end, mask);
ÂÂÂÂ /* ...but only set bus limit if we found valid dma-ranges earlier */
ÂÂÂÂ if (!ret)
ÂÂÂÂÂÂÂÂ dev->bus_dma_limit = end;
And I see.
[ÂÂÂ 1.134294]Â 4a140000.sata: of_platform
[ÂÂ 13.203917] ahci 4a140000.sata: of_dma_configure
[ÂÂ 13.225635] ahci 4a140000.sata: dma 0 paddr 0 size 1000000000
[ÂÂ 13.266178] ahci 4a140000.sata: dma_pfn_offset(0x000000)
[ÂÂ 13.297621] ahci 4a140000.sata: end fffffffff, mask fffffffff
[ÂÂ 13.585499] ahci 4a140000.sata: dma_mask 0xffffffff, coherent_mask 0xffffffff
[ÂÂ 13.599082] ahci 4a140000.sata: setting 64-bit mask ffffffffffffffff
Truncation of dma_mask and coherent_mask is undesired in this case.
How about fixing it like so?
-ÂÂÂÂ dev->coherent_dma_mask &= mask;
-ÂÂÂ *dev->dma_mask &= mask;
+ÂÂÂÂ dev->coherent_dma_mask = mask;
+ÂÂÂÂ *dev->dma_mask = mask;
Also this comment doesn't make sense anymore?
ÂÂÂÂÂÂÂ /*
ÂÂÂÂÂÂÂÂ * Limit coherent and dma mask based on size and default mask
ÂÂÂÂÂÂÂÂ * set by the driver.
ÂÂÂÂÂÂÂÂ */