Thread (51 messages) 51 messages, 7 authors, 2014-09-03
STALE4290d

[RFC PATCH 5/7] dma-mapping: detect and configure IOMMU in of_dma_configure

From: arnd@arndb.de (Arnd Bergmann)
Date: 2014-09-01 14:53:34
Also in: linux-iommu

On Friday 29 August 2014 16:54:28 Will Deacon wrote:
 static void of_dma_configure(struct platform_device *pdev)
 {
-       u64 dma_addr, paddr, size;
+       u64 dma_addr, paddr, size, mask;
        int ret;
-       bool coherent;
+       bool coherent, iommu;
        unsigned long offset;
        struct device *dev = &pdev->dev;
 
+       /*
+        * Set default dma-mask to 32 bit. Drivers are expected to setup
+        * the correct supported dma_mask.
+        */
+       mask = DMA_BIT_MASK(32);
+
        ret = of_dma_get_range(dev->of_node, &dma_addr, &paddr, &size);
-       offset = ret < 0 ? 0 : PFN_DOWN(paddr - dma_addr);
-       dev_dbg(dev, "dma_pfn_offset(%#08lx)\n", dev->dma_pfn_offset);
+       if (ret < 0) {
+               dma_addr = offset = 0;
+               size = mask;
+       } else {
+               offset = PFN_DOWN(paddr - dma_addr);
+               dev_dbg(dev, "dma_pfn_offset(%#08lx)\n", dev->dma_pfn_offset);
+       }
 
        coherent = of_dma_is_coherent(dev->of_node);
        dev_dbg(dev, "device is%sdma coherent\n",
                coherent ? " " : " not ");
 
-       /*
-        * Set default dma-mask to 32 bit. Drivers are expected to setup
-        * the correct supported dma_mask.
-        */
-       arch_setup_dma_ops(dev, DMA_BIT_MASK(32), offset, coherent);
+       iommu = !of_iommu_configure(dev);
+       dev_dbg(dev, "device is%sbehind an iommu\n",
+               iommu ? " " : " not ");
+
+       arch_setup_dma_ops(dev, mask, dma_addr, size, offset, coherent, iommu);
 }
Hmm, I was actually expecting of_iommu_configure() to be called from inside
arch_setup_dma_ops(), leaving the choice for how it's set up to the
architecture for now. It's probably not a big difference either way.

	Arnd
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help