diff mbox

drm/nouveau: use new TTM populate/DMA map function

Message ID 20170818142300.9787-1-tom.stdenis@amd.com (mailing list archive)
State New, archived
Headers show

Commit Message

StDenis, Tom Aug. 18, 2017, 2:23 p.m. UTC
Removes common code found in numerous vendor drivers and places
it higher up in the TTM tree.

Signed-off-by: Tom St Denis <tom.stdenis@amd.com>
---
 drivers/gpu/drm/nouveau/nouveau_bo.c | 37 ++----------------------------------
 1 file changed, 2 insertions(+), 35 deletions(-)
diff mbox

Patch

diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index e427f80344c4..6ad0ad53047a 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -1448,8 +1448,6 @@  nouveau_ttm_tt_populate(struct ttm_tt *ttm)
 	struct nvkm_device *device;
 	struct drm_device *dev;
 	struct device *pdev;
-	unsigned i;
-	int r;
 	bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
 
 	if (ttm->state != tt_unpopulated)
@@ -1480,30 +1478,7 @@  nouveau_ttm_tt_populate(struct ttm_tt *ttm)
 	}
 #endif
 
-	r = ttm_pool_populate(ttm);
-	if (r) {
-		return r;
-	}
-
-	for (i = 0; i < ttm->num_pages; i++) {
-		dma_addr_t addr;
-
-		addr = dma_map_page(pdev, ttm->pages[i], 0, PAGE_SIZE,
-				    DMA_BIDIRECTIONAL);
-
-		if (dma_mapping_error(pdev, addr)) {
-			while (i--) {
-				dma_unmap_page(pdev, 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(pdev, ttm_dma);
 }
 
 static void
@@ -1514,7 +1489,6 @@  nouveau_ttm_tt_unpopulate(struct ttm_tt *ttm)
 	struct nvkm_device *device;
 	struct drm_device *dev;
 	struct device *pdev;
-	unsigned i;
 	bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
 
 	if (slave)
@@ -1539,14 +1513,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(pdev, ttm_dma->dma_address[i], PAGE_SIZE,
-				       DMA_BIDIRECTIONAL);
-		}
-	}
-
-	ttm_pool_unpopulate(ttm);
+	ttm_unmap_and_unpopulate_pages(pdev, ttm_dma);
 }
 
 void