aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/include/linux/dma-noncoherent.h
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2019-06-14 16:06:10 +0200
committerChristoph Hellwig <hch@lst.de>2019-06-25 08:14:43 +0200
commit4b85faed211ccfbcc7f3adf1cd62f0b00d1a172b (patch)
treedcc65552dd34f276ac4e20104f2f981da996bdc6 /include/linux/dma-noncoherent.h
parentopenrisc: remove the partial DMA_ATTR_NON_CONSISTENT support (diff)
downloadwireguard-linux-4b85faed211ccfbcc7f3adf1cd62f0b00d1a172b.tar.xz
wireguard-linux-4b85faed211ccfbcc7f3adf1cd62f0b00d1a172b.zip
dma-mapping: add a dma_alloc_need_uncached helper
Check if we need to allocate uncached memory for a device given the allocation flags. Switch over the uncached segment check to this helper to deal with architectures that do not support the dma_cache_sync operation and thus should not returned cacheable memory for DMA_ATTR_NON_CONSISTENT allocations. Signed-off-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'include/linux/dma-noncoherent.h')
-rw-r--r--include/linux/dma-noncoherent.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/include/linux/dma-noncoherent.h b/include/linux/dma-noncoherent.h
index 7e0126a04e02..732919ac5c11 100644
--- a/include/linux/dma-noncoherent.h
+++ b/include/linux/dma-noncoherent.h
@@ -20,6 +20,20 @@ static inline bool dev_is_dma_coherent(struct device *dev)
}
#endif /* CONFIG_ARCH_HAS_DMA_COHERENCE_H */
+/*
+ * Check if an allocation needs to be marked uncached to be coherent.
+ */
+static inline bool dma_alloc_need_uncached(struct device *dev,
+ unsigned long attrs)
+{
+ if (dev_is_dma_coherent(dev))
+ return false;
+ if (IS_ENABLED(CONFIG_DMA_NONCOHERENT_CACHE_SYNC) &&
+ (attrs & DMA_ATTR_NON_CONSISTENT))
+ return false;
+ return true;
+}
+
void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
gfp_t gfp, unsigned long attrs);
void arch_dma_free(struct device *dev, size_t size, void *cpu_addr,