Lines Matching +full:page +full:- +full:size

1 // SPDX-License-Identifier: GPL-2.0
6 #include <linux/dma-map-ops.h>
7 #include <linux/iommu-dma.h>
9 static struct page *dma_common_vaddr_to_page(void *cpu_addr) in dma_common_vaddr_to_page()
17 * Create scatter-list for the already allocated DMA buffer.
20 void *cpu_addr, dma_addr_t dma_addr, size_t size, in dma_common_get_sgtable() argument
23 struct page *page = dma_common_vaddr_to_page(cpu_addr); in dma_common_get_sgtable() local
28 sg_set_page(sgt->sgl, page, PAGE_ALIGN(size), 0); in dma_common_get_sgtable()
33 * Create userspace mapping for the DMA-coherent memory.
36 void *cpu_addr, dma_addr_t dma_addr, size_t size, in dma_common_mmap() argument
41 unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT; in dma_common_mmap()
42 unsigned long off = vma->vm_pgoff; in dma_common_mmap()
43 struct page *page = dma_common_vaddr_to_page(cpu_addr); in dma_common_mmap() local
44 int ret = -ENXIO; in dma_common_mmap()
46 vma->vm_page_prot = dma_pgprot(dev, vma->vm_page_prot, attrs); in dma_common_mmap()
48 if (dma_mmap_from_dev_coherent(dev, vma, cpu_addr, size, &ret)) in dma_common_mmap()
51 if (off >= count || user_count > count - off) in dma_common_mmap()
52 return -ENXIO; in dma_common_mmap()
54 return remap_pfn_range(vma, vma->vm_start, in dma_common_mmap()
55 page_to_pfn(page) + vma->vm_pgoff, in dma_common_mmap()
56 user_count << PAGE_SHIFT, vma->vm_page_prot); in dma_common_mmap()
58 return -ENXIO; in dma_common_mmap()
62 struct page *dma_common_alloc_pages(struct device *dev, size_t size, in dma_common_alloc_pages() argument
66 struct page *page; in dma_common_alloc_pages() local
68 page = dma_alloc_contiguous(dev, size, gfp); in dma_common_alloc_pages()
69 if (!page) in dma_common_alloc_pages()
70 page = alloc_pages_node(dev_to_node(dev), gfp, get_order(size)); in dma_common_alloc_pages()
71 if (!page) in dma_common_alloc_pages()
75 *dma_handle = iommu_dma_map_page(dev, page, 0, size, dir, in dma_common_alloc_pages()
78 *dma_handle = ops->map_page(dev, page, 0, size, dir, in dma_common_alloc_pages()
81 dma_free_contiguous(dev, page, size); in dma_common_alloc_pages()
85 memset(page_address(page), 0, size); in dma_common_alloc_pages()
86 return page; in dma_common_alloc_pages()
89 void dma_common_free_pages(struct device *dev, size_t size, struct page *page, in dma_common_free_pages() argument
95 iommu_dma_unmap_page(dev, dma_handle, size, dir, in dma_common_free_pages()
97 else if (ops->unmap_page) in dma_common_free_pages()
98 ops->unmap_page(dev, dma_handle, size, dir, in dma_common_free_pages()
100 dma_free_contiguous(dev, page, size); in dma_common_free_pages()