@@ -172,13 +172,6 @@ static void of_dma_configure(struct device *dev)
dev->coherent_dma_mask = DMA_BIT_MASK(32);
/*
- * Set it to coherent_dma_mask by default if the architecture
- * code has not set it.
- */
- if (!dev->dma_mask)
- dev->dma_mask = &dev->coherent_dma_mask;
-
- /*
* if dma-coherent property exist, call arch hook to setup
* dma coherent operations.
*/
@@ -188,18 +181,32 @@ static void of_dma_configure(struct device *dev)
}
/*
- * if dma-ranges property doesn't exist - just return else
- * setup the dma offset
+ * If dma-ranges property exists - setup the dma offset.
*/
ret = of_dma_get_range(dev->of_node, &dma_addr, &paddr, &size);
if (ret < 0) {
dev_dbg(dev, "no dma range information to setup\n");
- return;
+ size = 0;
+ } else {
+ /* DMA ranges found. Calculate and set dma_pfn_offset */
+ dev->dma_pfn_offset = PFN_DOWN(paddr - dma_addr);
+ dev_dbg(dev, "dma_pfn_offset(%#08lx)\n", dev->dma_pfn_offset);
}
- /* DMA ranges found. Calculate and set dma_pfn_offset */
- dev->dma_pfn_offset = PFN_DOWN(paddr - dma_addr);
- dev_dbg(dev, "dma_pfn_offset(%#08lx)\n", dev->dma_pfn_offset);
+ /*
+ * If the bus dma-ranges property specifies a size smaller than 4GB,
+ * the device would not be capable of accessing the whole 32-bit
+ * space, so reduce the default coherent_dma_mask accordingly.
+ */
+ if (size && size < (1ULL << 32))
+ dev->coherent_dma_mask = DMA_BIT_MASK(ilog2(size));
+
+ /*
+ * Set dma_mask to coherent_dma_mask by default if the architecture
+ * code has not set it and DMA on such mask is supported.
+ */
+ if (!dev->dma_mask && dma_supported(dev, dev->coherent_dma_mask))
+ dev->dma_mask = &dev->coherent_dma_mask;
}
/**