mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-14 15:54:15 +08:00
staging: media: ipu3: use vmap instead of reimplementing it
Just use vmap instead of messing with vmalloc internals. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Acked-by: Peter 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.de Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
5bf9917452
commit
f8092aa175
@ -15,14 +15,12 @@ struct imgu_device;
|
||||
* @size: size of the buffer in bytes.
|
||||
* @vaddr: kernel virtual address.
|
||||
* @daddr: iova dma address to access IPU3.
|
||||
* @vma: private, a pointer to &struct vm_struct,
|
||||
* used for imgu_dmamap_free.
|
||||
*/
|
||||
struct imgu_css_map {
|
||||
size_t size;
|
||||
void *vaddr;
|
||||
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,
|
||||
unsigned long shift = iova_shift(&imgu->iova_domain);
|
||||
struct device *dev = &imgu->pci_dev->dev;
|
||||
size_t size = PAGE_ALIGN(len);
|
||||
int count = size >> PAGE_SHIFT;
|
||||
struct page **pages;
|
||||
dma_addr_t iovaddr;
|
||||
struct iova *iova;
|
||||
@ -114,7 +115,7 @@ void *imgu_dmamap_alloc(struct imgu_device *imgu, struct imgu_css_map *map,
|
||||
|
||||
/* Call IOMMU driver to setup pgt */
|
||||
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,
|
||||
page_to_phys(pages[i]), PAGE_SIZE);
|
||||
if (rval)
|
||||
@ -123,33 +124,23 @@ void *imgu_dmamap_alloc(struct imgu_device *imgu, struct imgu_css_map *map,
|
||||
iovaddr += PAGE_SIZE;
|
||||
}
|
||||
|
||||
/* Now grab a virtual region */
|
||||
map->vma = __get_vm_area(size, VM_USERMAP, VMALLOC_START, VMALLOC_END);
|
||||
if (!map->vma)
|
||||
map->vaddr = vmap(pages, count, VM_USERMAP, PAGE_KERNEL);
|
||||
if (!map->vaddr)
|
||||
goto out_unmap;
|
||||
|
||||
map->vma->pages = pages;
|
||||
/* And map it in KVA */
|
||||
if (map_vm_area(map->vma, PAGE_KERNEL, pages))
|
||||
goto out_vunmap;
|
||||
|
||||
map->pages = pages;
|
||||
map->size = size;
|
||||
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__,
|
||||
size, &map->daddr, map->vma->addr);
|
||||
size, &map->daddr, map->vaddr);
|
||||
|
||||
return map->vma->addr;
|
||||
|
||||
out_vunmap:
|
||||
vunmap(map->vma->addr);
|
||||
return map->vaddr;
|
||||
|
||||
out_unmap:
|
||||
imgu_dmamap_free_buffer(pages, size);
|
||||
imgu_mmu_unmap(imgu->mmu, iova_dma_addr(&imgu->iova_domain, iova),
|
||||
i * PAGE_SIZE);
|
||||
map->vma = NULL;
|
||||
|
||||
out_free_iova:
|
||||
__free_iova(&imgu->iova_domain, iova);
|
||||
@ -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)
|
||||
{
|
||||
struct vm_struct *area = map->vma;
|
||||
|
||||
dev_dbg(&imgu->pci_dev->dev, "%s: freeing %zu @ IOVA %pad @ VA %p\n",
|
||||
__func__, map->size, &map->daddr, map->vaddr);
|
||||
|
||||
@ -187,11 +176,8 @@ void imgu_dmamap_free(struct imgu_device *imgu, struct imgu_css_map *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);
|
||||
imgu_dmamap_free_buffer(map->pages, map->size);
|
||||
map->vaddr = NULL;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user