From: Rob Herring <robh@kernel.org>
To: dri-devel@lists.freedesktop.org
Cc: Sean Paul <sean@poorly.run>,
Maxime Ripard <maxime.ripard@bootlin.com>,
David Airlie <airlied@linux.ie>,
linux-arm-msm@vger.kernel.org, etnaviv@lists.freedesktop.org,
Russell King <linux+etnaviv@armlinux.org.uk>,
freedreno@lists.freedesktop.org
Subject: [PATCH 1/5] drm: Add reservation_object to drm_gem_object
Date: Thu, 31 Jan 2019 18:50:53 -0600 [thread overview]
Message-ID: <20190201005057.13648-2-robh@kernel.org> (raw)
In-Reply-To: <20190201005057.13648-1-robh@kernel.org>
Many users of drm_gem_object embed a struct reservation_object into
their subclassed struct, so let's add one to struct drm_gem_object.
This will allow removing the reservation object from the subclasses
and removing the ->gem_prime_res_obj callback.
With the addition, add a drm_gem_reservation_object_wait() helper
function for drivers to use in wait ioctls.
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <maxime.ripard@bootlin.com>
Cc: Sean Paul <sean@poorly.run>
Cc: David Airlie <airlied@linux.ie>
Cc: Daniel Vetter <daniel@ffwll.ch>
Signed-off-by: Rob Herring <robh@kernel.org>
---
Documentation/gpu/todo.rst | 9 ---------
drivers/gpu/drm/drm_gem.c | 39 +++++++++++++++++++++++++++++++++++++
drivers/gpu/drm/drm_prime.c | 1 +
include/drm/drm_gem.h | 7 +++++++
4 files changed, 47 insertions(+), 9 deletions(-)
diff --git a/Documentation/gpu/todo.rst b/Documentation/gpu/todo.rst
index 14191b64446d..6e0a37d0bf6d 100644
--- a/Documentation/gpu/todo.rst
+++ b/Documentation/gpu/todo.rst
@@ -209,15 +209,6 @@ Would be great to refactor this all into a set of small common helpers.
Contact: Daniel Vetter
-Put a reservation_object into drm_gem_object
---------------------------------------------
-
-This would remove the need for the ->gem_prime_res_obj callback. It would also
-allow us to implement generic helpers for waiting for a bo, allowing for quite a
-bit of refactoring in the various wait ioctl implementations.
-
-Contact: Daniel Vetter
-
idr_init_base()
---------------
diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
index 8b55ece97967..91dd06c1b3a8 100644
--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -170,6 +170,10 @@ void drm_gem_private_object_init(struct drm_device *dev,
kref_init(&obj->refcount);
obj->handle_count = 0;
obj->size = size;
+ if (!obj->resv) {
+ obj->resv = &obj->_resv;
+ reservation_object_init(obj->resv);
+ }
drm_vma_node_reset(&obj->vma_node);
}
EXPORT_SYMBOL(drm_gem_private_object_init);
@@ -657,6 +661,40 @@ drm_gem_object_lookup(struct drm_file *filp, u32 handle)
}
EXPORT_SYMBOL(drm_gem_object_lookup);
+/**
+ * drm_gem_object_lookup - Wait on GEM object's reservation's objects
+ * shared and/or exclusive fences.
+ * @filp: DRM file private date
+ * @handle: userspace handle
+ * @wait_all: if true, wait on all fences, else wait on just exclusive fence
+ * @timeout: timeout value in jiffies or zero to return immediately
+ *
+ * Returns:
+ *
+ * Returns -ERESTARTSYS if interrupted, 0 if the wait timed out, or
+ * greater than 0 on success.
+ */
+long drm_gem_reservation_object_wait(struct drm_file *filep, u32 handle,
+ bool wait_all, unsigned long timeout)
+{
+ long ret;
+ struct drm_gem_object *obj;
+
+ obj = drm_gem_object_lookup(filep, handle);
+ if (!obj) {
+ DRM_DEBUG("Failed to look up GEM BO %d\n", handle);
+ return -EINVAL;
+ }
+
+ ret = reservation_object_wait_timeout_rcu(obj->resv, wait_all,
+ true, timeout);
+
+ drm_gem_object_put_unlocked(obj);
+
+ return ret;
+}
+EXPORT_SYMBOL(drm_gem_reservation_object_wait);
+
/**
* drm_gem_close_ioctl - implementation of the GEM_CLOSE ioctl
* @dev: drm_device
@@ -821,6 +859,7 @@ drm_gem_object_release(struct drm_gem_object *obj)
if (obj->filp)
fput(obj->filp);
+ reservation_object_fini(&obj->_resv);
drm_gem_free_mmap_offset(obj);
}
EXPORT_SYMBOL(drm_gem_object_release);
diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c
index 231e3f6d5f41..dc079efb3b0f 100644
--- a/drivers/gpu/drm/drm_prime.c
+++ b/drivers/gpu/drm/drm_prime.c
@@ -504,6 +504,7 @@ struct dma_buf *drm_gem_prime_export(struct drm_device *dev,
.size = obj->size,
.flags = flags,
.priv = obj,
+ .resv = obj->resv,
};
if (dev->driver->gem_prime_res_obj)
diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h
index c95727425284..f450a5b6038e 100644
--- a/include/drm/drm_gem.h
+++ b/include/drm/drm_gem.h
@@ -35,6 +35,7 @@
*/
#include <linux/kref.h>
+#include <linux/reservation.h>
#include <drm/drm_vma_manager.h>
@@ -262,6 +263,10 @@ struct drm_gem_object {
*/
struct dma_buf_attachment *import_attach;
+ /* normally (resv == &_resv) except for imported bo's */
+ struct reservation_object *resv;
+ struct reservation_object _resv;
+
/**
* @funcs:
*
@@ -363,6 +368,8 @@ void drm_gem_put_pages(struct drm_gem_object *obj, struct page **pages,
bool dirty, bool accessed);
struct drm_gem_object *drm_gem_object_lookup(struct drm_file *filp, u32 handle);
+long drm_gem_reservation_object_wait(struct drm_file *filep, u32 handle,
+ bool wait_all, unsigned long timeout);
int drm_gem_dumb_map_offset(struct drm_file *file, struct drm_device *dev,
u32 handle, u64 *offset);
int drm_gem_dumb_destroy(struct drm_file *file,
--
2.19.1
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2019-02-01 0:50 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-01 0:50 [PATCH 0/5] Add reservation_object to drm_gem_object Rob Herring
2019-02-01 0:50 ` Rob Herring [this message]
2019-02-01 12:39 ` [PATCH 1/5] drm: " kbuild test robot
[not found] ` <20190201005057.13648-2-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2019-02-01 17:21 ` Daniel Vetter
[not found] ` <20190201005057.13648-1-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2019-02-01 0:50 ` [PATCH 2/5] drm: etnaviv: Switch to use drm_gem_object reservation_object Rob Herring
2019-02-01 0:50 ` [PATCH 3/5] drm: msm: " Rob Herring
2019-02-01 0:50 ` [PATCH 4/5] drm: v3d: " Rob Herring
[not found] ` <20190201005057.13648-5-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2019-02-01 17:12 ` Eric Anholt
2019-02-01 17:38 ` Rob Herring
2019-02-01 17:23 ` [PATCH 0/5] Add reservation_object to drm_gem_object Daniel Vetter
2019-02-01 0:50 ` [PATCH 5/5] drm: vc4: Switch to use drm_gem_object reservation_object Rob Herring
[not found] ` <20190201005057.13648-6-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2019-02-01 17:13 ` Eric Anholt
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=20190201005057.13648-2-robh@kernel.org \
--to=robh@kernel.org \
--cc=airlied@linux.ie \
--cc=dri-devel@lists.freedesktop.org \
--cc=etnaviv@lists.freedesktop.org \
--cc=freedreno@lists.freedesktop.org \
--cc=linux+etnaviv@armlinux.org.uk \
--cc=linux-arm-msm@vger.kernel.org \
--cc=maxime.ripard@bootlin.com \
--cc=sean@poorly.run \
/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).