dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk>
To: dri-devel@lists.freedesktop.org
Subject: [PATCH 1/3] drm: Wait on the reservation object when sync'ing dmabufs
Date: Sat, 18 Jun 2016 16:20:47 +0100	[thread overview]
Message-ID: <1466263249-18346-1-git-send-email-chris@chris-wilson.co.uk> (raw)

Rendering operations to the dma-buf are tracked implicitly via the
reservation_object (dmabuf->resv). The dmabuf sync ioctl allows
userspace to wait upon outstanding rendering and prepare the object for
CPU access (provided by the prime dma_buf_ops.begin_cpu_access). Fill
this out for the generic drm_gem_prime by waiting on outstanding
rendering via dmabuf->resv. (This offers an alternative to using poll
that is consistent with other drivers that may need to more work to
prepare the object for access by the CPU.)

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 drivers/gpu/drm/drm_prime.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c
index 780589b420a4..479ff7cc3634 100644
--- a/drivers/gpu/drm/drm_prime.c
+++ b/drivers/gpu/drm/drm_prime.c
@@ -28,6 +28,7 @@
 
 #include <linux/export.h>
 #include <linux/dma-buf.h>
+#include <linux/reservation.h>
 #include <drm/drmP.h>
 #include <drm/drm_gem.h>
 
@@ -288,6 +289,22 @@ static int drm_gem_dmabuf_mmap(struct dma_buf *dma_buf,
 	return dev->driver->gem_prime_mmap(obj, vma);
 }
 
+static int drm_gem_begin_cpu_access(struct dma_buf *dma_buf,
+				    enum dma_data_direction direction)
+{
+	bool write = (direction == DMA_BIDIRECTIONAL ||
+		      direction == DMA_TO_DEVICE);
+	struct reservation_object *resv = dma_buf->resv;
+	long ret;
+
+	ret = reservation_object_wait_timeout_rcu(resv, write, true,
+						  MAX_SCHEDULE_TIMEOUT);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
 static const struct dma_buf_ops drm_gem_prime_dmabuf_ops =  {
 	.attach = drm_gem_map_attach,
 	.detach = drm_gem_map_detach,
@@ -301,6 +318,7 @@ static const struct dma_buf_ops drm_gem_prime_dmabuf_ops =  {
 	.mmap = drm_gem_dmabuf_mmap,
 	.vmap = drm_gem_dmabuf_vmap,
 	.vunmap = drm_gem_dmabuf_vunmap,
+	.begin_cpu_access = drm_gem_begin_cpu_access,
 };
 
 /**
-- 
2.8.1

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

             reply	other threads:[~2016-06-18 15:21 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-18 15:20 Chris Wilson [this message]
2016-06-18 15:20 ` [PATCH 2/3] drm/vgem: Fix mmaping Chris Wilson
2016-06-21 21:04   ` Chris Wilson
2016-06-18 15:20 ` [PATCH 3/3] drm/vgem: Enable dmabuf interface for export Chris Wilson
2016-06-19  6:18   ` [PATCH v2] " Chris Wilson
2016-06-20 20:04     ` [PATCH v3 1/3] dmabuf Chris Wilson
2016-06-20 20:04       ` [PATCH v3 2/3] drm: Prevent NULL deref in drm_name_info() Chris Wilson
2016-06-20 20:04       ` [PATCH v3 3/3] meh Chris Wilson
2016-06-20 20:06       ` [PATCH v3 1/3] dmabuf Chris Wilson
2016-06-20 20:06     ` [PATCH v3] drm/vgem: Enable dmabuf interface for export Chris Wilson
2016-06-27 17:57       ` Zach Reizner
2016-06-18 22:37 ` [PATCH 1/3] drm: Wait on the reservation object when sync'ing dmabufs Daniel Vetter

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=1466263249-18346-1-git-send-email-chris@chris-wilson.co.uk \
    --to=chris@chris-wilson.co.uk \
    --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).