summaryrefslogtreecommitdiff
path: root/lib/ioctl_wrappers.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2016-02-23 17:45:49 +0000
committerChris Wilson <chris@chris-wilson.co.uk>2016-02-23 18:03:46 +0000
commitf27d295fe3a1ca005dfa0fbfd81d6808b1f5ca47 (patch)
treeeef0a41794f920cdba7023c2d8c12202844e1c08 /lib/ioctl_wrappers.c
parentbabcf40f29d9e9cce5d0739b1784eb94fe91bd26 (diff)
lib: Move gem_wait() to ioctl-wrappers
We intend to use gem_wait() in more tests than gem_wait.c, so move the simple ioctl wrapper into the core. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'lib/ioctl_wrappers.c')
-rw-r--r--lib/ioctl_wrappers.c44
1 files changed, 34 insertions, 10 deletions
diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c
index de56e42d..40712606 100644
--- a/lib/ioctl_wrappers.c
+++ b/lib/ioctl_wrappers.c
@@ -370,28 +370,52 @@ void gem_set_domain(int fd, uint32_t handle,
}
/**
- * gem_sync:
+ * __gem_wait:
* @fd: open i915 drm file descriptor
* @handle: gem buffer object handle
+ * @timeout_ns: [in] time to wait, [out] remaining time (in nanoseconds)
*
- * This functions waits for outstanding rendering to complete.
+ * This functions waits for outstanding rendering to complete, upto
+ * the timeout_ns. If no timeout_ns is provided, the wait is indefinite and
+ * only returns upon an error or when the rendering is complete.
*/
-void gem_sync(int fd, uint32_t handle)
+int gem_wait(int fd, uint32_t handle, int64_t *timeout_ns)
{
struct drm_i915_gem_wait wait;
+ int ret;
memset(&wait, 0, sizeof(wait));
wait.bo_handle = handle;
- wait.timeout_ns =-1;
- if (drmIoctl(fd, DRM_IOCTL_I915_GEM_WAIT, &wait) == 0) {
- errno = 0;
- return;
- }
+ wait.timeout_ns = timeout_ns ? *timeout_ns : -1;
+ wait.flags = 0;
+
+ ret = 0;
+ if (drmIoctl(fd, DRM_IOCTL_I915_GEM_WAIT, &wait))
+ ret = -errno;
+
+ if (timeout_ns)
+ *timeout_ns = wait.timeout_ns;
+
+ return ret;
+}
- gem_set_domain(fd, handle,
- I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
+/**
+ * gem_sync:
+ * @fd: open i915 drm file descriptor
+ * @handle: gem buffer object handle
+ *
+ * This functions waits for outstanding rendering to complete.
+ */
+void gem_sync(int fd, uint32_t handle)
+{
+ if (gem_wait(fd, handle, NULL))
+ gem_set_domain(fd, handle,
+ I915_GEM_DOMAIN_GTT,
+ I915_GEM_DOMAIN_GTT);
+ errno = 0;
}
+
bool gem_create__has_stolen_support(int fd)
{
static int has_stolen_support = -1;