Skip to contentSkip to conversation

nouveau: use ttm populate mapping functions. (v2)

PATCH In review Dave Airlie 3 participants 5 messages Jul 28, 2020 – Jul 29, 2020

Subsystems (3)
lore
Share & tools
lore

Dave Airlie

author maintainer
#0 lore raw

PATCH 1/1 nouveau: use ttm populate mapping functions. (v2)

From: Dave Airlie <[email protected]>

Instead of rolling driver copies of them.

v2: cleanup return handling (Ben)

---
 drivers/gpu/drm/nouveau/nouveau_bo.c | 38 ++--------------------------
 1 file changed, 2 insertions(+), 36 deletions(-)
drivers/gpu/drm/nouveau/nouveau_bo.c +2 -36
index 7806278dce57..6ef5085c9a91 100644
@@ -1231,8 +1231,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)
@@ -1260,31 +1258,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
@@ -1293,7 +1267,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)
@@ -1316,14 +1289,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
Signature · 6 lines
2.26.2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw
Quoted 56 lines

-----Original Message-----
From: dri-devel <[email protected]> On Behalf Of Dave Airlie
Sent: Monday, July 27, 2020 11:26 PM
To: [email protected]
Cc: [email protected]
Subject: [PATCH] nouveau: use ttm populate mapping functions. (v2)

From: Dave Airlie <[email protected]>

Instead of rolling driver copies of them.

v2: cleanup return handling (Ben)

---
drivers/gpu/drm/nouveau/nouveau_bo.c | 38 ++--------------------------

1 file changed, 2 insertions(+), 36 deletions(-)
drivers/gpu/drm/nouveau/nouveau_bo.c +0 -2
index 7806278dce57..6ef5085c9a91 100644
@@ -1231,8 +1231,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)
drivers/gpu/drm/nouveau/nouveau_bo.c +0 -16
@@ -1260,31 +1258,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);

drivers/gpu/drm/nouveau/nouveau_bo.c nouveau_ttm_tt_populate(struct ttm_tt *ttm, · line 1264

Quoted 10 lines
drivers/gpu/drm/nouveau/nouveau_bo.c +1 -9
-				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);

This is not a completely straight code replacement.

ttm_populate_and_map_pages() also has code to deal with pages that are contiguous (consolidates them).

Is it possible that the nouveau HW can't handle a contiguous buffer larger than PAG_SIZE?

Thanks,

Mike

Quoted 31 lines

}

static void

drivers/gpu/drm/nouveau/nouveau_bo.c +1 -9
@@ -1293,7 +1267,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)
@@ -1316,14 +1289,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

Quoted 4 lines

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#2 lore raw
Quoted 68 lines · Michael J
Quoted 57 lines

-----Original Message-----
From: dri-devel <[email protected]> On Behalf Of Dave Airlie
Sent: Monday, July 27, 2020 11:26 PM
To: [email protected]
Cc: [email protected]
Subject: [PATCH] nouveau: use ttm populate mapping functions. (v2)

From: Dave Airlie <[email protected]>

Instead of rolling driver copies of them.

v2: cleanup return handling (Ben)

---
drivers/gpu/drm/nouveau/nouveau_bo.c | 38 ++--------------------------

1 file changed, 2 insertions(+), 36 deletions(-)
drivers/gpu/drm/nouveau/nouveau_bo.c +0 -2
index 7806278dce57..6ef5085c9a91 100644
@@ -1231,8 +1231,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)
drivers/gpu/drm/nouveau/nouveau_bo.c +0 -16
@@ -1260,31 +1258,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);

drivers/gpu/drm/nouveau/nouveau_bo.c nouveau_ttm_tt_populate(struct ttm_tt *ttm, · line 1264

Quoted 10 lines
drivers/gpu/drm/nouveau/nouveau_bo.c +1 -9
-                              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);
Quoted 7 lines

This is not a completely straight code replacement.

ttm_populate_and_map_pages() also has code to deal with pages that are contiguous (consolidates them).

Is it possible that the nouveau HW can't handle a contiguous buffer larger than PAG_SIZE?

I think it's fine. The function appears to consolidate the pages for the dma_map_page() call, but otherwise leave dma_address[] in PAGE_SIZE chunks, I don't believe anything else in the driver will care.

Ben.

Quoted 36 lines

Thanks,

Mike

Quoted 31 lines

}

static void

drivers/gpu/drm/nouveau/nouveau_bo.c +1 -9
@@ -1293,7 +1267,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)
@@ -1316,14 +1289,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

Quoted 8 lines
Quoted 4 lines

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Reviewed-by
#3 lore raw
Quoted 83 lines

-----Original Message-----
From: Ben Skeggs <[email protected]>
Sent: Tuesday, July 28, 2020 4:16 PM
To: Ruhl, Michael J <[email protected]>
Cc: Dave Airlie <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH] nouveau: use ttm populate mapping functions. (v2)

Quoted 73 lines · Michael J
Quoted 57 lines

-----Original Message-----
From: dri-devel <[email protected]> On Behalf Of Dave Airlie
Sent: Monday, July 27, 2020 11:26 PM
To: [email protected]
Cc: [email protected]
Subject: [PATCH] nouveau: use ttm populate mapping functions. (v2)

From: Dave Airlie <[email protected]>

Instead of rolling driver copies of them.

v2: cleanup return handling (Ben)

---
drivers/gpu/drm/nouveau/nouveau_bo.c | 38 ++--------------------------

1 file changed, 2 insertions(+), 36 deletions(-)
drivers/gpu/drm/nouveau/nouveau_bo.c +0 -2
index 7806278dce57..6ef5085c9a91 100644
@@ -1231,8 +1231,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)
drivers/gpu/drm/nouveau/nouveau_bo.c +0 -16
@@ -1260,31 +1258,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);

drivers/gpu/drm/nouveau/nouveau_bo.c nouveau_ttm_tt_populate(struct ttm_tt *ttm, · line 1264

Quoted 10 lines
drivers/gpu/drm/nouveau/nouveau_bo.c +1 -9
-                              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);

This is not a completely straight code replacement.

ttm_populate_and_map_pages() also has code to deal with pages that are contiguous (consolidates them).

Quoted 6 lines
Quoted 2 lines

Is it possible that the nouveau HW can't handle a contiguous buffer larger than PAG_SIZE?

I think it's fine. The function appears to consolidate the pages for the dma_map_page() call, but otherwise leave dma_address[] in PAGE_SIZE chunks, I don't believe anything else in the driver will care.

Ahh.. I misread it. This is limiting the calls to dma_map_page(). Instead
of calling it for each page, just do it for the first one...

Thanks for setting me straight. 😊

Mike

Quoted 17 lines

Ben.

Quoted 15 lines

Thanks,

Mike

Quoted 10 lines

}

static void

drivers/gpu/drm/nouveau/nouveau_bo.c +0 -1
@@ -1293,7 +1267,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);
 
Quoted 30 lines
Quoted 2 lines

drivers/gpu/drm/nouveau/nouveau_bo.c nouveau_ttm_tt_unpopulate(struct ttm_tt

Quoted 2 lines
drivers/gpu/drm/nouveau/nouveau_bo.c +0 -0
      if (slave)
@@ -1316,14 +1289,7 @@ nouveau_ttm_tt_unpopulate(struct ttm_tt

*ttm)

Quoted 27 lines
Quoted 19 lines
drivers/gpu/drm/nouveau/nouveau_bo.c +1 -8
      }
 #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

Quoted 4 lines

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#4 lore raw
Quoted 91 lines · Michael J
Quoted 8 lines

-----Original Message-----
From: Ben Skeggs <[email protected]>
Sent: Tuesday, July 28, 2020 4:16 PM
To: Ruhl, Michael J <[email protected]>
Cc: Dave Airlie <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH] nouveau: use ttm populate mapping functions. (v2)

Quoted 76 lines
Quoted 74 lines · Michael J
Quoted 57 lines

-----Original Message-----
From: dri-devel <[email protected]> On Behalf Of Dave Airlie
Sent: Monday, July 27, 2020 11:26 PM
To: [email protected]
Cc: [email protected]
Subject: [PATCH] nouveau: use ttm populate mapping functions. (v2)

From: Dave Airlie <[email protected]>

Instead of rolling driver copies of them.

v2: cleanup return handling (Ben)

---
drivers/gpu/drm/nouveau/nouveau_bo.c | 38 ++--------------------------

1 file changed, 2 insertions(+), 36 deletions(-)
drivers/gpu/drm/nouveau/nouveau_bo.c +0 -2
index 7806278dce57..6ef5085c9a91 100644
@@ -1231,8 +1231,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)
drivers/gpu/drm/nouveau/nouveau_bo.c +0 -16
@@ -1260,31 +1258,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);

drivers/gpu/drm/nouveau/nouveau_bo.c nouveau_ttm_tt_populate(struct ttm_tt *ttm, · line 1264

Quoted 10 lines
drivers/gpu/drm/nouveau/nouveau_bo.c +1 -9
-                              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);

This is not a completely straight code replacement.

ttm_populate_and_map_pages() also has code to deal with pages that are contiguous (consolidates them).

Is it possible that the nouveau HW can't handle a contiguous buffer

larger

Quoted 5 lines
Quoted 1 line

than PAG_SIZE?

I think it's fine. The function appears to consolidate the pages for the dma_map_page() call, but otherwise leave dma_address[] in PAGE_SIZE chunks, I don't believe anything else in the driver will care.

Quoted 8 lines

Ahh.. I misread it. This is limiting the calls to dma_map_page().
Instead
of calling it for each page, just do it for the first one...

Thanks for setting me straight. 😊

Thanks for the review! I've got the patch in my tree.

Ben.

Quoted 52 lines

Mike

Quoted 47 lines

Ben.

Quoted 15 lines

Thanks,

Mike

Quoted 10 lines

}

static void

drivers/gpu/drm/nouveau/nouveau_bo.c +0 -1
@@ -1293,7 +1267,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);
 
Quoted 2 lines

drivers/gpu/drm/nouveau/nouveau_bo.c nouveau_ttm_tt_unpopulate(struct ttm_tt

Quoted 2 lines
drivers/gpu/drm/nouveau/nouveau_bo.c +0 -0
      if (slave)
@@ -1316,14 +1289,7 @@ nouveau_ttm_tt_unpopulate(struct ttm_tt

*ttm)

Quoted 27 lines
Quoted 19 lines
drivers/gpu/drm/nouveau/nouveau_bo.c +1 -8
      }
 #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

Quoted 4 lines

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel