DMA-API: provide a helper to setup DMA masks
authorRussell King <rmk+kernel@arm.linux.org.uk>
Fri, 9 May 2014 14:58:15 +0000 (15:58 +0100)
committerMark Brown <broonie@linaro.org>
Mon, 12 May 2014 17:10:22 +0000 (18:10 +0100)
Many drivers contain code such as:

dev->dma_mask = &dev->coherent_dma_mask;
dev->coherent_dma_mask = MASK;

Let's move this pattern out of drivers and have the DMA API provide a
helper for it.  This helper uses dma_set_mask_and_coherent() to allow
platform issues to be properly dealt with via dma_set_mask()/
dma_is_supported().

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
(cherry picked from commit fa6a8d6d65b19ab44e5244ea499bcd553cc72343)
Signed-off-by: Ryan Harkin <ryan.harkin@linaro.org>
Signed-off-by: Mark Brown <broonie@linaro.org>
include/linux/dma-mapping.h

index 8f7a2e84e527dda4769a0ffd865c7e5bc3ee34dc..48ef6f50d86c4cb84a94a319cb1d913813efcee8 100644 (file)
@@ -111,6 +111,16 @@ static inline int dma_set_mask_and_coherent(struct device *dev, u64 mask)
        return rc;
 }
 
+/*
+ * Similar to the above, except it deals with the case where the device
+ * does not have dev->dma_mask appropriately setup.
+ */
+static inline int dma_coerce_mask_and_coherent(struct device *dev, u64 mask)
+{
+       dev->dma_mask = &dev->coherent_dma_mask;
+       return dma_set_mask_and_coherent(dev, mask);
+}
+
 extern u64 dma_get_required_mask(struct device *dev);
 
 static inline unsigned int dma_get_max_seg_size(struct device *dev)