Skip to contentSkip to conversation

staging: imgu: Use vmap() instead of __get_vm_area() and map_vm_area()

PATCH In review Sakari Ailus 2 participants 4 messages Apr 17, 2020 – Apr 26, 2020

Subsystems (3)
lore
Share & tools
lore

Sakari Ailus

author maintainer
#0 lore raw

PATCH 1/1 staging: imgu: Use vmap() instead of __get_vm_area() and map_vm_area()

Switch to vmap() instead of using both __get_vm_area() and map_vm_area().

While at it, also assign vm_struct.nr_pages field.

---
This is just compile tested but reasonably trivial.

 drivers/staging/media/ipu3/ipu3-dmamap.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/staging/media/ipu3/ipu3-dmamap.c +2 -9
index 7431322379f6..58e6683e5770 100644
@@ -123,16 +123,12 @@ 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);
+	map->vma = vmap(pages, size / PAGE_SIZE, VM_USERMAP, PAGE_KERNEL);
 	if (!map->vma)
 		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->vma->nr_pages = size / PAGE_SIZE;
 	map->size = size;
 	map->daddr = iova_dma_addr(&imgu->iova_domain, iova);
 	map->vaddr = map->vma->addr;
@@ -142,9 +138,6 @@ void *imgu_dmamap_alloc(struct imgu_device *imgu, struct imgu_css_map *map,
 
 	return map->vma->addr;
 
-out_vunmap:
-	vunmap(map->vma->addr);
-
 out_unmap:
 	imgu_dmamap_free_buffer(pages, size);
 	imgu_mmu_unmap(imgu->mmu, iova_dma_addr(&imgu->iova_domain, iova),
Signature · 1 line
2.20.1
#1 lore raw

Hi, Sakari

Quoted 17 lines · Sakari Ailus

Switch to vmap() instead of using both __get_vm_area() and map_vm_area().

While at it, also assign vm_struct.nr_pages field.

---
This is just compile tested but reasonably trivial.

 drivers/staging/media/ipu3/ipu3-dmamap.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/staging/media/ipu3/ipu3-dmamap.c +0 -0
index 7431322379f6..58e6683e5770 100644

drivers/staging/media/ipu3/ipu3-dmamap.c void *imgu_dmamap_alloc(struct imgu_device *imgu, struct imgu_css_map *map, · line 126

Quoted 6 lines
drivers/staging/media/ipu3/ipu3-dmamap.c +1 -2
@@ -123,16 +123,12 @@ 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);
+	map->vma = vmap(pages, size / PAGE_SIZE, VM_USERMAP, PAGE_KERNEL);

vmap() returns the address of virtual area not the area itself, right?

Quoted 23 lines
drivers/staging/media/ipu3/ipu3-dmamap.c +1 -7
 	if (!map->vma)
 		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->vma->nr_pages = size / PAGE_SIZE;
 	map->size = size;
 	map->daddr = iova_dma_addr(&imgu->iova_domain, iova);
 	map->vaddr = map->vma->addr;
@@ -142,9 +138,6 @@ void *imgu_dmamap_alloc(struct imgu_device *imgu, struct imgu_css_map *map,
 
 	return map->vma->addr;
 
-out_vunmap:
-	vunmap(map->vma->addr);
-
 out_unmap:
 	imgu_dmamap_free_buffer(pages, size);
 	imgu_mmu_unmap(imgu->mmu, iova_dma_addr(&imgu->iova_domain, iova),
Signature · 2 lines
Best regards,
Bingbu Cao
author maintainer
#2 lore raw

Hi Bingbu,

Quoted 23 lines · Bingbu Cao

Hi, Sakari

Quoted 20 lines · Sakari Ailus

Switch to vmap() instead of using both __get_vm_area() and map_vm_area().

While at it, also assign vm_struct.nr_pages field.

---
This is just compile tested but reasonably trivial.

 drivers/staging/media/ipu3/ipu3-dmamap.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/staging/media/ipu3/ipu3-dmamap.c +0 -0
index 7431322379f6..58e6683e5770 100644
@@ -123,16 +123,12 @@ void *imgu_dmamap_alloc(struct imgu_device *imgu, struct imgu_css_map *map,
 		iovaddr += PAGE_SIZE;
 	}
 
Quoted 5 lines

drivers/staging/media/ipu3/ipu3-dmamap.c void *imgu_dmamap_alloc(struct imgu_device *imgu, struct imgu_css_map *map, · line 126

Quoted 3 lines
drivers/staging/media/ipu3/ipu3-dmamap.c +1 -2
-	/* Now grab a virtual region */
-	map->vma = __get_vm_area(size, VM_USERMAP, VMALLOC_START, VMALLOC_END);
+	map->vma = vmap(pages, size / PAGE_SIZE, VM_USERMAP, PAGE_KERNEL);

vmap() returns the address of virtual area not the area itself, right?

Yes. But there's a cleaner patches from Christoph here:

<URL:https://lore.kernel.org/lkml/[email protected]/>

So I've dropped mine.

Quoted 25 lines
Quoted 24 lines
drivers/staging/media/ipu3/ipu3-dmamap.c +1 -7
 	if (!map->vma)
 		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->vma->nr_pages = size / PAGE_SIZE;
 	map->size = size;
 	map->daddr = iova_dma_addr(&imgu->iova_domain, iova);
 	map->vaddr = map->vma->addr;
@@ -142,9 +138,6 @@ void *imgu_dmamap_alloc(struct imgu_device *imgu, struct imgu_css_map *map,
 
 	return map->vma->addr;
 
-out_vunmap:
-	vunmap(map->vma->addr);
-
 out_unmap:
 	imgu_dmamap_free_buffer(pages, size);
 	imgu_mmu_unmap(imgu->mmu, iova_dma_addr(&imgu->iova_domain, iova),
Signature · 3 lines
Kind regards,

Sakari Ailus
#3 lore raw
Quoted 32 lines · Sakari Ailus

Hi Bingbu,

Quoted 23 lines · Bingbu Cao

Hi, Sakari

Quoted 20 lines · Sakari Ailus

Switch to vmap() instead of using both __get_vm_area() and map_vm_area().

While at it, also assign vm_struct.nr_pages field.

---
This is just compile tested but reasonably trivial.

 drivers/staging/media/ipu3/ipu3-dmamap.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/staging/media/ipu3/ipu3-dmamap.c +0 -0
index 7431322379f6..58e6683e5770 100644
@@ -123,16 +123,12 @@ void *imgu_dmamap_alloc(struct imgu_device *imgu, struct imgu_css_map *map,
 		iovaddr += PAGE_SIZE;
 	}
 
Quoted 5 lines

drivers/staging/media/ipu3/ipu3-dmamap.c void *imgu_dmamap_alloc(struct imgu_device *imgu, struct imgu_css_map *map, · line 126

Quoted 3 lines
drivers/staging/media/ipu3/ipu3-dmamap.c +1 -2
-	/* Now grab a virtual region */
-	map->vma = __get_vm_area(size, VM_USERMAP, VMALLOC_START, VMALLOC_END);
+	map->vma = vmap(pages, size / PAGE_SIZE, VM_USERMAP, PAGE_KERNEL);

vmap() returns the address of virtual area not the area itself, right?

Quoted 3 lines

Yes. But there's a cleaner patches from Christoph here:

<URL:https://lore.kernel.org/lkml/[email protected]/>

Thanks, I just did a simple test with Christoph's patch, the basic camera functions are OK.

Quoted 29 lines

So I've dropped mine.

Quoted 25 lines
Quoted 24 lines
drivers/staging/media/ipu3/ipu3-dmamap.c +1 -7
 	if (!map->vma)
 		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->vma->nr_pages = size / PAGE_SIZE;
 	map->size = size;
 	map->daddr = iova_dma_addr(&imgu->iova_domain, iova);
 	map->vaddr = map->vma->addr;
@@ -142,9 +138,6 @@ void *imgu_dmamap_alloc(struct imgu_device *imgu, struct imgu_css_map *map,
 
 	return map->vma->addr;
 
-out_vunmap:
-	vunmap(map->vma->addr);
-
 out_unmap:
 	imgu_dmamap_free_buffer(pages, size);
 	imgu_mmu_unmap(imgu->mmu, iova_dma_addr(&imgu->iova_domain, iova),
Signature · 2 lines
Best regards,
Bingbu Cao