Commit f8092aa1 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Linus Torvalds

staging: media: ipu3: use vmap instead of reimplementing it

Just use vmap instead of messing with vmalloc internals.
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-5-hch@lst.deSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 5bf99174
...@@ -15,14 +15,12 @@ struct imgu_device; ...@@ -15,14 +15,12 @@ struct imgu_device;
* @size: size of the buffer in bytes. * @size: size of the buffer in bytes.
* @vaddr: kernel virtual address. * @vaddr: kernel virtual address.
* @daddr: iova dma address to access IPU3. * @daddr: iova dma address to access IPU3.
* @vma: private, a pointer to &struct vm_struct,
* used for imgu_dmamap_free.
*/ */
struct imgu_css_map { struct imgu_css_map {
size_t size; size_t size;
void *vaddr; void *vaddr;
dma_addr_t daddr; dma_addr_t daddr;
struct vm_struct *vma; struct page **pages;
}; };
/** /**
......
...@@ -96,6 +96,7 @@ void *imgu_dmamap_alloc(struct imgu_device *imgu, struct imgu_css_map *map, ...@@ -96,6 +96,7 @@ void *imgu_dmamap_alloc(struct imgu_device *imgu, struct imgu_css_map *map,
unsigned long shift = iova_shift(&imgu->iova_domain); unsigned long shift = iova_shift(&imgu->iova_domain);
struct device *dev = &imgu->pci_dev->dev; struct device *dev = &imgu->pci_dev->dev;
size_t size = PAGE_ALIGN(len); size_t size = PAGE_ALIGN(len);
int count = size >> PAGE_SHIFT;
struct page **pages; struct page **pages;
dma_addr_t iovaddr; dma_addr_t iovaddr;
struct iova *iova; struct iova *iova;
...@@ -114,7 +115,7 @@ void *imgu_dmamap_alloc(struct imgu_device *imgu, struct imgu_css_map *map, ...@@ -114,7 +115,7 @@ void *imgu_dmamap_alloc(struct imgu_device *imgu, struct imgu_css_map *map,
/* Call IOMMU driver to setup pgt */ /* Call IOMMU driver to setup pgt */
iovaddr = iova_dma_addr(&imgu->iova_domain, iova); iovaddr = iova_dma_addr(&imgu->iova_domain, iova);
for (i = 0; i < size / PAGE_SIZE; ++i) { for (i = 0; i < count; ++i) {
rval = imgu_mmu_map(imgu->mmu, iovaddr, rval = imgu_mmu_map(imgu->mmu, iovaddr,
page_to_phys(pages[i]), PAGE_SIZE); page_to_phys(pages[i]), PAGE_SIZE);
if (rval) if (rval)
...@@ -123,33 +124,23 @@ void *imgu_dmamap_alloc(struct imgu_device *imgu, struct imgu_css_map *map, ...@@ -123,33 +124,23 @@ void *imgu_dmamap_alloc(struct imgu_device *imgu, struct imgu_css_map *map,
iovaddr += PAGE_SIZE; iovaddr += PAGE_SIZE;
} }
/* Now grab a virtual region */ map->vaddr = vmap(pages, count, VM_USERMAP, PAGE_KERNEL);
map->vma = __get_vm_area(size, VM_USERMAP, VMALLOC_START, VMALLOC_END); if (!map->vaddr)
if (!map->vma)
goto out_unmap; goto out_unmap;
map->vma->pages = pages; map->pages = pages;
/* And map it in KVA */
if (map_vm_area(map->vma, PAGE_KERNEL, pages))
goto out_vunmap;
map->size = size; map->size = size;
map->daddr = iova_dma_addr(&imgu->iova_domain, iova); map->daddr = iova_dma_addr(&imgu->iova_domain, iova);
map->vaddr = map->vma->addr;
dev_dbg(dev, "%s: allocated %zu @ IOVA %pad @ VA %p\n", __func__, dev_dbg(dev, "%s: allocated %zu @ IOVA %pad @ VA %p\n", __func__,
size, &map->daddr, map->vma->addr); size, &map->daddr, map->vaddr);
return map->vma->addr;
out_vunmap: return map->vaddr;
vunmap(map->vma->addr);
out_unmap: out_unmap:
imgu_dmamap_free_buffer(pages, size); imgu_dmamap_free_buffer(pages, size);
imgu_mmu_unmap(imgu->mmu, iova_dma_addr(&imgu->iova_domain, iova), imgu_mmu_unmap(imgu->mmu, iova_dma_addr(&imgu->iova_domain, iova),
i * PAGE_SIZE); i * PAGE_SIZE);
map->vma = NULL;
out_free_iova: out_free_iova:
__free_iova(&imgu->iova_domain, iova); __free_iova(&imgu->iova_domain, iova);
...@@ -177,8 +168,6 @@ void imgu_dmamap_unmap(struct imgu_device *imgu, struct imgu_css_map *map) ...@@ -177,8 +168,6 @@ void imgu_dmamap_unmap(struct imgu_device *imgu, struct imgu_css_map *map)
*/ */
void imgu_dmamap_free(struct imgu_device *imgu, struct imgu_css_map *map) void imgu_dmamap_free(struct imgu_device *imgu, struct imgu_css_map *map)
{ {
struct vm_struct *area = map->vma;
dev_dbg(&imgu->pci_dev->dev, "%s: freeing %zu @ IOVA %pad @ VA %p\n", dev_dbg(&imgu->pci_dev->dev, "%s: freeing %zu @ IOVA %pad @ VA %p\n",
__func__, map->size, &map->daddr, map->vaddr); __func__, map->size, &map->daddr, map->vaddr);
...@@ -187,11 +176,8 @@ void imgu_dmamap_free(struct imgu_device *imgu, struct imgu_css_map *map) ...@@ -187,11 +176,8 @@ void imgu_dmamap_free(struct imgu_device *imgu, struct imgu_css_map *map)
imgu_dmamap_unmap(imgu, map); imgu_dmamap_unmap(imgu, map);
if (WARN_ON(!area) || WARN_ON(!area->pages))
return;
imgu_dmamap_free_buffer(area->pages, map->size);
vunmap(map->vaddr); vunmap(map->vaddr);
imgu_dmamap_free_buffer(map->pages, map->size);
map->vaddr = NULL; map->vaddr = NULL;
} }
......
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