Commit 515e5b6d authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Linus Torvalds

dma-mapping: use vmap insted of reimplementing it

Replace the open coded instance of vmap with the actual function.  In
the non-contiguous (IOMMU) case this requires an extra find_vm_area,
but given that this isn't a fast path function that is a small price
to pay.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: Christophe Leroy <christophe.leroy@c-s.fr>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: David Airlie <airlied@linux.ie>
Cc: Gao Xiang <xiang@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: "K. Y. Srinivasan" <kys@microsoft.com>
Cc: Laura Abbott <labbott@redhat.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Kelley <mikelley@microsoft.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Nitin Gupta <ngupta@vflare.org>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: Stephen Hemminger <sthemmin@microsoft.com>
Cc: Sumit Semwal <sumit.semwal@linaro.org>
Cc: Wei Liu <wei.liu@kernel.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Paul Mackerras <paulus@ozlabs.org>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Will Deacon <will@kernel.org>
Link: http://lkml.kernel.org/r/20200414131348.444715-6-hch@lst.deSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent f8092aa1
...@@ -20,23 +20,6 @@ struct page **dma_common_find_pages(void *cpu_addr) ...@@ -20,23 +20,6 @@ struct page **dma_common_find_pages(void *cpu_addr)
return area->pages; return area->pages;
} }
static struct vm_struct *__dma_common_pages_remap(struct page **pages,
size_t size, pgprot_t prot, const void *caller)
{
struct vm_struct *area;
area = get_vm_area_caller(size, VM_DMA_COHERENT, caller);
if (!area)
return NULL;
if (map_vm_area(area, prot, pages)) {
vunmap(area->addr);
return NULL;
}
return area;
}
/* /*
* Remaps an array of PAGE_SIZE pages into another vm_area. * Remaps an array of PAGE_SIZE pages into another vm_area.
* Cannot be used in non-sleeping contexts * Cannot be used in non-sleeping contexts
...@@ -44,15 +27,12 @@ static struct vm_struct *__dma_common_pages_remap(struct page **pages, ...@@ -44,15 +27,12 @@ static struct vm_struct *__dma_common_pages_remap(struct page **pages,
void *dma_common_pages_remap(struct page **pages, size_t size, void *dma_common_pages_remap(struct page **pages, size_t size,
pgprot_t prot, const void *caller) pgprot_t prot, const void *caller)
{ {
struct vm_struct *area; void *vaddr;
area = __dma_common_pages_remap(pages, size, prot, caller); vaddr = vmap(pages, size >> PAGE_SHIFT, VM_DMA_COHERENT, prot);
if (!area) if (vaddr)
return NULL; find_vm_area(vaddr)->pages = pages;
return vaddr;
area->pages = pages;
return area->addr;
} }
/* /*
...@@ -62,24 +42,20 @@ void *dma_common_pages_remap(struct page **pages, size_t size, ...@@ -62,24 +42,20 @@ void *dma_common_pages_remap(struct page **pages, size_t size,
void *dma_common_contiguous_remap(struct page *page, size_t size, void *dma_common_contiguous_remap(struct page *page, size_t size,
pgprot_t prot, const void *caller) pgprot_t prot, const void *caller)
{ {
int i; int count = size >> PAGE_SHIFT;
struct page **pages; struct page **pages;
struct vm_struct *area; void *vaddr;
int i;
pages = kmalloc(sizeof(struct page *) << get_order(size), GFP_KERNEL); pages = kmalloc_array(count, sizeof(struct page *), GFP_KERNEL);
if (!pages) if (!pages)
return NULL; return NULL;
for (i = 0; i < count; i++)
for (i = 0; i < (size >> PAGE_SHIFT); i++)
pages[i] = nth_page(page, i); pages[i] = nth_page(page, i);
vaddr = vmap(pages, count, VM_DMA_COHERENT, prot);
area = __dma_common_pages_remap(pages, size, prot, caller);
kfree(pages); kfree(pages);
if (!area) return vaddr;
return NULL;
return area->addr;
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment