All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Airlie <airlied@gmail.com>
To: dri-devel@lists.freedesktop.org
Subject: [PATCH 1/7] drm/prime: introduce sg->pages/addr arrays helper
Date: Tue, 22 May 2012 13:49:58 +0100	[thread overview]
Message-ID: <1337691004-13202-1-git-send-email-airlied@gmail.com> (raw)

From: Dave Airlie <airlied@redhat.com>

the ttm drivers need this currently, in order to get fault handling
working and efficient.

It also allows addrs to be NULL for devices like udl.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/drm_prime.c |   36 ++++++++++++++++++++++++++++++++++++
 include/drm/drmP.h          |    2 ++
 2 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c
index 1bdf2b5..20dbf2c 100644
--- a/drivers/gpu/drm/drm_prime.c
+++ b/drivers/gpu/drm/drm_prime.c
@@ -227,6 +227,42 @@ out:
 }
 EXPORT_SYMBOL(drm_prime_pages_to_sg);
 
+/* export 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 */
+int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages,
+				     dma_addr_t *addrs, int max_pages)
+{
+	unsigned count;
+	struct scatterlist *sg;
+	struct page *page;
+	u32 len, offset;
+	int pg_index;
+	dma_addr_t addr;
+
+	pg_index = 0;
+	for_each_sg(sgt->sgl, sg, sgt->nents, count) {
+		len = sg->length;
+		offset = sg->offset;
+		page = sg_page(sg);
+		addr = sg_dma_address(sg);
+
+		while (len > 0) {
+			if (WARN_ON(pg_index >= max_pages))
+				return -1;
+			pages[pg_index] = page;
+			if (addrs)
+				addrs[pg_index] = addr;
+
+			page++;
+			addr += PAGE_SIZE;
+			len -= PAGE_SIZE;
+			pg_index++;
+		}
+	}
+	return 0;
+}
+EXPORT_SYMBOL(drm_prime_sg_to_page_addr_arrays);
 /* helper function to cleanup a GEM/prime object */
 void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg)
 {
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 15d9179..31ad880 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -1558,6 +1558,8 @@ extern int drm_prime_handle_to_fd_ioctl(struct drm_device *dev, void *data,
 extern int drm_prime_fd_to_handle_ioctl(struct drm_device *dev, void *data,
 					struct drm_file *file_priv);
 
+extern int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **pages,
+					    dma_addr_t *addrs, int max_pages);
 extern struct sg_table *drm_prime_pages_to_sg(struct page **pages, int nr_pages);
 extern void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg);
 
-- 
1.7.6

             reply	other threads:[~2012-05-22 12:50 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-22 12:49 Dave Airlie [this message]
2012-05-22 12:49 ` [PATCH 2/7] drm/prime: add exported buffers to current fprivs imported buffer list (v2) Dave Airlie
2012-05-22 12:50 ` [PATCH 3/7] udl: add prime fd->handle support Dave Airlie
2012-05-22 21:11   ` Alex Deucher
2012-05-22 12:50 ` [PATCH 4/7] ttm: add prime sharing support to TTM (v2) Dave Airlie
2012-05-22 20:55   ` Jerome Glisse
2012-05-22 21:09   ` Alex Deucher
2012-05-22 12:50 ` [PATCH 5/7] nouveau: add PRIME support Dave Airlie
2012-05-22 21:13   ` Alex Deucher
2012-05-22 12:50 ` [PATCH 6/7] i915: add dmabuf/prime buffer sharing support Dave Airlie
2012-05-22 13:28   ` Chris Wilson
2012-05-22 12:50 ` [PATCH 7/7] drm/radeon: add PRIME support (v2) Dave Airlie
2012-05-22 20:56   ` Jerome Glisse
2012-05-22 21:09   ` Alex Deucher
2012-05-22 21:08 ` [PATCH 1/7] drm/prime: introduce sg->pages/addr arrays helper Alex Deucher

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=1337691004-13202-1-git-send-email-airlied@gmail.com \
    --to=airlied@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.