drm/syncobj: Add a signal ioctl (v3)
authorJason Ekstrand <jason@jlekstrand.net>
Mon, 28 Aug 2017 21:10:28 +0000 (14:10 -0700)
committerDave Airlie <airlied@redhat.com>
Tue, 29 Aug 2017 00:16:25 +0000 (10:16 +1000)
This IOCTL provides a mechanism for userspace to trigger a sync object
directly.  There are other ways that userspace can trigger a syncobj
such as submitting a dummy batch somewhere or hanging on to a triggered
sync_file and doing an import.  This just provides an easy way to
manually trigger the sync object without weird hacks.

The motivation for this IOCTL is Vulkan fences.  Vulkan lets you create
a fence already in the signaled state so that you can wait on it
immediatly without stalling.  We could also handle this with a new
create flag to ask the driver to create a syncobj that is already
signaled but the IOCTL seemed a bit cleaner and more generic.

v2:
 - Take an array of sync objects (Dave Airlie)
v3:
 - Throw -EINVAL if pad != 0

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Signed-off-by: Dave Airlie <airlied@redhat.com>
drivers/gpu/drm/drm_internal.h
drivers/gpu/drm/drm_ioctl.c
drivers/gpu/drm/drm_syncobj.c
include/uapi/drm/drm.h

index 83f1615eb1ec632a79c9cb2fc7b1931bdfea8a5c..fbc3f308fa1997ab5889f3f25fb7357106ea5909 100644 (file)
@@ -171,3 +171,5 @@ int drm_syncobj_wait_ioctl(struct drm_device *dev, void *data,
                           struct drm_file *file_private);
 int drm_syncobj_reset_ioctl(struct drm_device *dev, void *data,
                            struct drm_file *file_private);
+int drm_syncobj_signal_ioctl(struct drm_device *dev, void *data,
+                            struct drm_file *file_private);
index 16c5d51a43aa209c53af0a7dafa30926592b36a8..a9ae6dd2d593996a62da625e3b6d0eaabd16dac8 100644 (file)
@@ -661,6 +661,8 @@ static const struct drm_ioctl_desc drm_ioctls[] = {
                      DRM_UNLOCKED|DRM_RENDER_ALLOW),
        DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_RESET, drm_syncobj_reset_ioctl,
                      DRM_UNLOCKED|DRM_RENDER_ALLOW),
+       DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_SIGNAL, drm_syncobj_signal_ioctl,
+                     DRM_UNLOCKED|DRM_RENDER_ALLOW),
 };
 
 #define DRM_CORE_IOCTL_COUNT   ARRAY_SIZE( drm_ioctls )
index 40d2ad293661a3d208b5769d0fc27db79485987a..0422b8c2c2e7392c24107cd9d07b771b25722065 100644 (file)
@@ -918,3 +918,39 @@ drm_syncobj_reset_ioctl(struct drm_device *dev, void *data,
 
        return 0;
 }
+
+int
+drm_syncobj_signal_ioctl(struct drm_device *dev, void *data,
+                        struct drm_file *file_private)
+{
+       struct drm_syncobj_array *args = data;
+       struct drm_syncobj **syncobjs;
+       uint32_t i;
+       int ret;
+
+       if (!drm_core_check_feature(dev, DRIVER_SYNCOBJ))
+               return -ENODEV;
+
+       if (args->pad != 0)
+               return -EINVAL;
+
+       if (args->count_handles == 0)
+               return -EINVAL;
+
+       ret = drm_syncobj_array_find(file_private,
+                                    u64_to_user_ptr(args->handles),
+                                    args->count_handles,
+                                    &syncobjs);
+       if (ret < 0)
+               return ret;
+
+       for (i = 0; i < args->count_handles; i++) {
+               ret = drm_syncobj_assign_null_handle(syncobjs[i]);
+               if (ret < 0)
+                       break;
+       }
+
+       drm_syncobj_array_free(syncobjs, args->count_handles);
+
+       return ret;
+}
index b037fdf9e43ba7acef227fb526472c43b02c0772..97677cd6964db099689f96f11b9731c748bebcfa 100644 (file)
@@ -861,6 +861,7 @@ extern "C" {
 #define DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE DRM_IOWR(0xC2, struct drm_syncobj_handle)
 #define DRM_IOCTL_SYNCOBJ_WAIT         DRM_IOWR(0xC3, struct drm_syncobj_wait)
 #define DRM_IOCTL_SYNCOBJ_RESET                DRM_IOWR(0xC4, struct drm_syncobj_array)
+#define DRM_IOCTL_SYNCOBJ_SIGNAL       DRM_IOWR(0xC5, struct drm_syncobj_array)
 
 /**
  * Device specific ioctls should only be in their respective headers