diff mbox series

[03/59] nouveau: use ttm populate mapping functions. (v2)

Message ID 20200804025632.3868079-4-airlied@gmail.com (mailing list archive)
State New, archived
Headers show
Series ttm misc cleanups, mem refactoring, rename objects. (v2) | expand

Commit Message

Dave Airlie Aug. 4, 2020, 2:55 a.m. UTC
From: Dave Airlie <airlied@redhat.com>

Instead of rolling driver copies of them.

v2: cleanup return handling (Ben)
Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/nouveau/nouveau_bo.c | 38 ++--------------------------
 1 file changed, 2 insertions(+), 36 deletions(-)

Comments

Ben Skeggs Aug. 5, 2020, 5:32 a.m. UTC | #1
On Tue, 4 Aug 2020 at 12:57, Dave Airlie <airlied@gmail.com> wrote:
>
> From: Dave Airlie <airlied@redhat.com>
>
> Instead of rolling driver copies of them.
>
> v2: cleanup return handling (Ben)
> Signed-off-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Ben Skeggs <bskeggs@redhat.com>

> ---
>  drivers/gpu/drm/nouveau/nouveau_bo.c | 38 ++--------------------------
>  1 file changed, 2 insertions(+), 36 deletions(-)
>
> diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
> index 356c1aae327d..aebec45b8416 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_bo.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
> @@ -1171,8 +1171,6 @@ nouveau_ttm_tt_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
>         struct ttm_dma_tt *ttm_dma = (void *)ttm;
>         struct nouveau_drm *drm;
>         struct device *dev;
> -       unsigned i;
> -       int r;
>         bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
>
>         if (ttm->state != tt_unpopulated)
> @@ -1200,31 +1198,7 @@ nouveau_ttm_tt_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
>                 return ttm_dma_populate((void *)ttm, dev, ctx);
>         }
>  #endif
> -
> -       r = ttm_pool_populate(ttm, ctx);
> -       if (r) {
> -               return r;
> -       }
> -
> -       for (i = 0; i < ttm->num_pages; i++) {
> -               dma_addr_t addr;
> -
> -               addr = dma_map_page(dev, ttm->pages[i], 0, PAGE_SIZE,
> -                                   DMA_BIDIRECTIONAL);
> -
> -               if (dma_mapping_error(dev, addr)) {
> -                       while (i--) {
> -                               dma_unmap_page(dev, ttm_dma->dma_address[i],
> -                                              PAGE_SIZE, DMA_BIDIRECTIONAL);
> -                               ttm_dma->dma_address[i] = 0;
> -                       }
> -                       ttm_pool_unpopulate(ttm);
> -                       return -EFAULT;
> -               }
> -
> -               ttm_dma->dma_address[i] = addr;
> -       }
> -       return 0;
> +       return ttm_populate_and_map_pages(dev, ttm_dma, ctx);
>  }
>
>  static void
> @@ -1233,7 +1207,6 @@ nouveau_ttm_tt_unpopulate(struct ttm_tt *ttm)
>         struct ttm_dma_tt *ttm_dma = (void *)ttm;
>         struct nouveau_drm *drm;
>         struct device *dev;
> -       unsigned i;
>         bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
>
>         if (slave)
> @@ -1256,14 +1229,7 @@ nouveau_ttm_tt_unpopulate(struct ttm_tt *ttm)
>         }
>  #endif
>
> -       for (i = 0; i < ttm->num_pages; i++) {
> -               if (ttm_dma->dma_address[i]) {
> -                       dma_unmap_page(dev, ttm_dma->dma_address[i], PAGE_SIZE,
> -                                      DMA_BIDIRECTIONAL);
> -               }
> -       }
> -
> -       ttm_pool_unpopulate(ttm);
> +       ttm_unmap_and_unpopulate_pages(dev, ttm_dma);
>  }
>
>  void
> --
> 2.26.2
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
diff mbox series

Patch

diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index 356c1aae327d..aebec45b8416 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -1171,8 +1171,6 @@  nouveau_ttm_tt_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
 	struct ttm_dma_tt *ttm_dma = (void *)ttm;
 	struct nouveau_drm *drm;
 	struct device *dev;
-	unsigned i;
-	int r;
 	bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
 
 	if (ttm->state != tt_unpopulated)
@@ -1200,31 +1198,7 @@  nouveau_ttm_tt_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
 		return ttm_dma_populate((void *)ttm, dev, ctx);
 	}
 #endif
-
-	r = ttm_pool_populate(ttm, ctx);
-	if (r) {
-		return r;
-	}
-
-	for (i = 0; i < ttm->num_pages; i++) {
-		dma_addr_t addr;
-
-		addr = dma_map_page(dev, ttm->pages[i], 0, PAGE_SIZE,
-				    DMA_BIDIRECTIONAL);
-
-		if (dma_mapping_error(dev, addr)) {
-			while (i--) {
-				dma_unmap_page(dev, ttm_dma->dma_address[i],
-					       PAGE_SIZE, DMA_BIDIRECTIONAL);
-				ttm_dma->dma_address[i] = 0;
-			}
-			ttm_pool_unpopulate(ttm);
-			return -EFAULT;
-		}
-
-		ttm_dma->dma_address[i] = addr;
-	}
-	return 0;
+	return ttm_populate_and_map_pages(dev, ttm_dma, ctx);
 }
 
 static void
@@ -1233,7 +1207,6 @@  nouveau_ttm_tt_unpopulate(struct ttm_tt *ttm)
 	struct ttm_dma_tt *ttm_dma = (void *)ttm;
 	struct nouveau_drm *drm;
 	struct device *dev;
-	unsigned i;
 	bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
 
 	if (slave)
@@ -1256,14 +1229,7 @@  nouveau_ttm_tt_unpopulate(struct ttm_tt *ttm)
 	}
 #endif
 
-	for (i = 0; i < ttm->num_pages; i++) {
-		if (ttm_dma->dma_address[i]) {
-			dma_unmap_page(dev, ttm_dma->dma_address[i], PAGE_SIZE,
-				       DMA_BIDIRECTIONAL);
-		}
-	}
-
-	ttm_pool_unpopulate(ttm);
+	ttm_unmap_and_unpopulate_pages(dev, ttm_dma);
 }
 
 void