summaryrefslogtreecommitdiffstats
path: root/kernel/dma
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2021-01-28 14:53:22 +0100
committerChristoph Hellwig <hch@lst.de>2021-03-15 10:02:31 +0100
commiteedb0b12d091a21909b5e84d9f3e5e649305bd12 (patch)
tree82524abc75941a66dedc9f476cd576eebc7ba225 /kernel/dma
parent1e28eed17697bcf343c6743f0028cc3b5dd88bf0 (diff)
downloadlinux-eedb0b12d091a21909b5e84d9f3e5e649305bd12.tar.gz
linux-eedb0b12d091a21909b5e84d9f3e5e649305bd12.tar.bz2
linux-eedb0b12d091a21909b5e84d9f3e5e649305bd12.zip
dma-mapping: add a dma_mmap_pages helper
Add a helper to map memory allocated using dma_alloc_pages into a user address space, similar to the dma_alloc_attrs function for coherent allocations. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Tomasz Figa <tfiga@chromium.org> Tested-by: Ricardo Ribalda <ribalda@chromium.org>
Diffstat (limited to 'kernel/dma')
-rw-r--r--kernel/dma/mapping.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c
index b6a633679933..9ce86c77651c 100644
--- a/kernel/dma/mapping.c
+++ b/kernel/dma/mapping.c
@@ -517,6 +517,19 @@ void dma_free_pages(struct device *dev, size_t size, struct page *page,
}
EXPORT_SYMBOL_GPL(dma_free_pages);
+int dma_mmap_pages(struct device *dev, struct vm_area_struct *vma,
+ size_t size, struct page *page)
+{
+ unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT;
+
+ if (vma->vm_pgoff >= count || vma_pages(vma) > count - vma->vm_pgoff)
+ return -ENXIO;
+ return remap_pfn_range(vma, vma->vm_start,
+ page_to_pfn(page) + vma->vm_pgoff,
+ vma_pages(vma) << PAGE_SHIFT, vma->vm_page_prot);
+}
+EXPORT_SYMBOL_GPL(dma_mmap_pages);
+
int dma_supported(struct device *dev, u64 mask)
{
const struct dma_map_ops *ops = get_dma_ops(dev);