summaryrefslogtreecommitdiffstats
path: root/kernel/dma/mapping.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2019-08-03 13:31:25 +0300
committerChristoph Hellwig <hch@lst.de>2019-09-04 11:13:18 +0200
commite29ccc188f3dae1cb66f59e10e01e0f150642a54 (patch)
tree50aefa076cec185f9ccc50c2696fb80d38ceb165 /kernel/dma/mapping.c
parentf9f3232a7d0ab73a33d11f4056c5823010f03d55 (diff)
downloadlinux-e29ccc188f3dae1cb66f59e10e01e0f150642a54.tar.gz
linux-e29ccc188f3dae1cb66f59e10e01e0f150642a54.tar.bz2
linux-e29ccc188f3dae1cb66f59e10e01e0f150642a54.zip
dma-mapping: add a dma_can_mmap helper
Add a helper to check if DMA allocations for a specific device can be mapped to userspace using dma_mmap_*. Signed-off-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'kernel/dma/mapping.c')
-rw-r--r--kernel/dma/mapping.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c
index c8b4e46407ba..18ba1ac93fc1 100644
--- a/kernel/dma/mapping.c
+++ b/kernel/dma/mapping.c
@@ -223,6 +223,29 @@ int dma_common_mmap(struct device *dev, struct vm_area_struct *vma,
}
/**
+ * dma_can_mmap - check if a given device supports dma_mmap_*
+ * @dev: device to check
+ *
+ * Returns %true if @dev supports dma_mmap_coherent() and dma_mmap_attrs() to
+ * map DMA allocations to userspace.
+ */
+bool dma_can_mmap(struct device *dev)
+{
+ const struct dma_map_ops *ops = get_dma_ops(dev);
+
+ if (IS_ENABLED(CONFIG_ARCH_NO_COHERENT_DMA_MMAP))
+ return false;
+
+ if (dma_is_direct(ops)) {
+ return dev_is_dma_coherent(dev) ||
+ IS_ENABLED(CONFIG_ARCH_HAS_DMA_COHERENT_TO_PFN);
+ }
+
+ return ops->mmap != NULL;
+}
+EXPORT_SYMBOL_GPL(dma_can_mmap);
+
+/**
* dma_mmap_attrs - map a coherent DMA allocation into user space
* @dev: valid struct device pointer, or NULL for ISA and EISA-like devices
* @vma: vm_area_struct describing requested user mapping