dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Shane Francis <bigbeeshane@gmail.com>
To: dri-devel@lists.freedesktop.org
Cc: bigbeeshane@gmail.com
Subject: [PATCH 1/2] drm/prime: correct logic for mapping sg to arrays
Date: Mon, 23 Mar 2020 20:51:36 +0000	[thread overview]
Message-ID: <20200323205137.136530-2-bigbeeshane@gmail.com> (raw)
In-Reply-To: <20200323205137.136530-1-bigbeeshane@gmail.com>

Previously drm_prime_sg_to_page_addr_arrays did not allow for
scatter-gather tables where the length had been reduced in a
dma_map.

This commit enables this via drm_prime_dma_sg_to_page_addr_arrays
while still keeping the original logic in place for tables that
that have not been through dma mapping

Signed-off-by: Shane Francis <bigbeeshane@gmail.com>
---
 drivers/gpu/drm/drm_prime.c | 71 ++++++++++++++++++++++++++++++++-----
 include/drm/drm_prime.h     |  5 +++
 2 files changed, 67 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c
index 86d9b0e45c8c..ed045043323e 100644
--- a/drivers/gpu/drm/drm_prime.c
+++ b/drivers/gpu/drm/drm_prime.c
@@ -943,21 +943,22 @@ struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev,
 }
 EXPORT_SYMBOL(drm_gem_prime_import);
 
+
 /**
  * drm_prime_sg_to_page_addr_arrays - convert an sg table into a page array
  * @sgt: scatter-gather table to convert
  * @pages: optional array of page pointers to store the page array in
  * @addrs: optional array to store the dma bus address of each page
  * @max_entries: size of both the passed-in arrays
+ * @sg_length: size of scatter-gather table
+ * @dma_mapped: if the supplied scatter-gather table has been dma mapped
  *
- * Exports an sg table into an array of pages and addresses. This is currently
- * required by the TTM driver in order to do correct fault handling.
- *
- * Drivers can use this in their &drm_driver.gem_prime_import_sg_table
- * implementation.
+ * Used internally to dri for both drm_prime_sg_to_page_addr_arrays and
+ * drm_prime_dma_sg_to_page_addr_arrays
  */
-int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages,
-				     dma_addr_t *addrs, int max_entries)
+static int drm_prime_sg_to_arrays(struct sg_table *sgt, struct page **pages,
+				     dma_addr_t *addrs, int max_entries,
+				     unsigned sg_length, bool dma_mapped)
 {
 	unsigned count;
 	struct scatterlist *sg;
@@ -966,8 +967,11 @@ int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages,
 	dma_addr_t addr;
 
 	index = 0;
-	for_each_sg(sgt->sgl, sg, sgt->nents, count) {
-		len = sg->length;
+	for_each_sg(sgt->sgl, sg, sg_length, count) {
+		if (!dma_mapped)
+			len = sg->length;
+		else
+			len = sg_dma_len(sg);
 		page = sg_page(sg);
 		addr = sg_dma_address(sg);
 
@@ -987,8 +991,57 @@ int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages,
 	}
 	return 0;
 }
+
+
+/**
+ * drm_prime_sg_to_page_addr_arrays - convert an sg table into a page array
+ * @sgt: scatter-gather table to convert
+ * @pages: optional array of page pointers to store the page array in
+ * @addrs: optional array to store the dma bus address of each page
+ * @max_entries: size of both the passed-in arrays
+ *
+ * Exports an sg table into an array of pages and addresses. This is currently
+ * required by the TTM driver in order to do correct fault handling.
+ *
+ * Used in instances when sgt->nents is the true length of the scatter-gather
+ * table
+ *
+ * Drivers can use this in their &drm_driver.gem_prime_import_sg_table
+ * implementation.
+ */
+int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages,
+				     dma_addr_t *addrs, int max_entries)
+{
+    return drm_prime_sg_to_arrays(sgt, pages, addrs, max_entries, sgt->nents,
+					false);
+}
 EXPORT_SYMBOL(drm_prime_sg_to_page_addr_arrays);
 
+
+/**
+ * drm_prime_dma_sg_to_page_addr_arrays - convert an sg table into a page array
+ * @sgt: scatter-gather table to convert
+ * @pages: optional array of page pointers to store the page array in
+ * @addrs: optional array to store the dma bus address of each page
+ * @max_entries: size of both the passed-in arrays
+ * @sg_length: size of scatter-gather table (this has the potential to differ
+ *           from sgt->nents due to dma_mapping)
+ *
+ *
+ * Used in instances when sgt->nents is not a valid length of the scatter-gather
+ * table
+ */
+int drm_prime_dma_sg_to_page_addr_arrays(struct sg_table *sgt,
+					struct page **pages,
+					dma_addr_t *addrs, int max_entries,
+					unsigned sg_length)
+{
+    return drm_prime_sg_to_arrays(sgt, pages, addrs, max_entries, sg_length,
+					true);
+}
+EXPORT_SYMBOL(drm_prime_dma_sg_to_page_addr_arrays);
+
+
 /**
  * drm_prime_gem_destroy - helper to clean up a PRIME-imported GEM object
  * @obj: GEM object which was created from a dma-buf
diff --git a/include/drm/drm_prime.h b/include/drm/drm_prime.h
index 9af7422b44cf..83fa7b28fc1f 100644
--- a/include/drm/drm_prime.h
+++ b/include/drm/drm_prime.h
@@ -104,5 +104,10 @@ void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg);
 int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages,
 				     dma_addr_t *addrs, int max_pages);
 
+int drm_prime_dma_sg_to_page_addr_arrays(struct sg_table *sgt,
+					struct page **pages,
+					dma_addr_t *addrs, int max_pages,
+					unsigned entries);
+
 
 #endif /* __DRM_PRIME_H__ */
-- 
2.26.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2020-03-23 20:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-23 20:51 [PATCH 0/2] AMDGPU / DRM Fix mapping of user pages Shane Francis
2020-03-23 20:51 ` Shane Francis [this message]
2020-03-23 20:51 ` [PATCH 2/2] drm/amdgpu: fix scatter-gather mapping with " Shane Francis
2020-03-23 21:36   ` Alex Deucher
2020-03-23 22:38     ` Shane Francis
2020-03-23 23:51 ` [PATCH v2 0/3] AMDGPU / RADEON / DRM Fix mapping of " Shane Francis
2020-03-23 23:51   ` [PATCH v2 1/3] drm/prime: correct logic for mapping sg to arrays Shane Francis
2020-03-23 23:51   ` [PATCH v2 2/3] drm/amdgpu: fix scatter-gather mapping with user pages Shane Francis
2020-03-23 23:51   ` [PATCH v2 3/3] drm/radeon: " Shane Francis
  -- strict thread matches above, loose matches on Subject: below --
2020-03-23 18:51 [PATCH 1/2] drm/prime: correct logic for mapping sg to arrays Shane Francis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200323205137.136530-2-bigbeeshane@gmail.com \
    --to=bigbeeshane@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).