drm/syncobj: add transition iotcls between binary and timeline v2
authorChunming Zhou <david1.zhou@amd.com>
Mon, 1 Apr 2019 09:51:01 +0000 (17:51 +0800)
committerChristian König <christian.koenig@amd.com>
Mon, 1 Apr 2019 10:08:44 +0000 (12:08 +0200)
we need to import/export timeline point.

v2: unify to one transfer ioctl

Signed-off-by: Chunming Zhou <david1.zhou@amd.com>
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Link: https://patchwork.freedesktop.org/patch/295790/?series=58813&rev=1
drivers/gpu/drm/drm_internal.h
drivers/gpu/drm/drm_ioctl.c
drivers/gpu/drm/drm_syncobj.c
include/uapi/drm/drm.h

index 695179bb88dcd6b9d8ca5c10ee4a1c992574cd18..dd11ae5f1eef7e5dd3bda74c263e363dbe312a6b 100644 (file)
@@ -180,6 +180,8 @@ int drm_syncobj_handle_to_fd_ioctl(struct drm_device *dev, void *data,
                                   struct drm_file *file_private);
 int drm_syncobj_fd_to_handle_ioctl(struct drm_device *dev, void *data,
                                   struct drm_file *file_private);
+int drm_syncobj_transfer_ioctl(struct drm_device *dev, void *data,
+                              struct drm_file *file_private);
 int drm_syncobj_wait_ioctl(struct drm_device *dev, void *data,
                           struct drm_file *file_private);
 int drm_syncobj_timeline_wait_ioctl(struct drm_device *dev, void *data,
index 7a534c184e522ef230cb1337db6cd4fd1b4fab1a..92b3b7b2fd81b803c16a31b7b23d93b9182357a7 100644 (file)
@@ -686,6 +686,8 @@ static const struct drm_ioctl_desc drm_ioctls[] = {
                      DRM_UNLOCKED|DRM_RENDER_ALLOW),
        DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE, drm_syncobj_fd_to_handle_ioctl,
                      DRM_UNLOCKED|DRM_RENDER_ALLOW),
+       DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_TRANSFER, drm_syncobj_transfer_ioctl,
+                     DRM_UNLOCKED|DRM_RENDER_ALLOW),
        DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_WAIT, drm_syncobj_wait_ioctl,
                      DRM_UNLOCKED|DRM_RENDER_ALLOW),
        DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_TIMELINE_WAIT, drm_syncobj_timeline_wait_ioctl,
index 6c273e73d9202f5e3dbeeebeee87dd4f1e84d3a2..63d5d2bf35c22e73b8e4b9c9a3f38a4ad7fa2986 100644 (file)
@@ -680,6 +680,80 @@ drm_syncobj_fd_to_handle_ioctl(struct drm_device *dev, void *data,
                                        &args->handle);
 }
 
+static int drm_syncobj_transfer_to_timeline(struct drm_file *file_private,
+                                           struct drm_syncobj_transfer *args)
+{
+       struct drm_syncobj *timeline_syncobj = NULL;
+       struct dma_fence *fence;
+       struct dma_fence_chain *chain;
+       int ret;
+
+       timeline_syncobj = drm_syncobj_find(file_private, args->dst_handle);
+       if (!timeline_syncobj) {
+               return -ENOENT;
+       }
+       ret = drm_syncobj_find_fence(file_private, args->src_handle,
+                                    args->src_point, args->flags,
+                                    &fence);
+       if (ret)
+               goto err;
+       chain = kzalloc(sizeof(struct dma_fence_chain), GFP_KERNEL);
+       if (!chain) {
+               ret = -ENOMEM;
+               goto err1;
+       }
+       drm_syncobj_add_point(timeline_syncobj, chain, fence, args->dst_point);
+err1:
+       dma_fence_put(fence);
+err:
+       drm_syncobj_put(timeline_syncobj);
+
+       return ret;
+}
+
+static int
+drm_syncobj_transfer_to_binary(struct drm_file *file_private,
+                              struct drm_syncobj_transfer *args)
+{
+       struct drm_syncobj *binary_syncobj = NULL;
+       struct dma_fence *fence;
+       int ret;
+
+       binary_syncobj = drm_syncobj_find(file_private, args->dst_handle);
+       if (!binary_syncobj)
+               return -ENOENT;
+       ret = drm_syncobj_find_fence(file_private, args->src_handle,
+                                    args->src_point, args->flags, &fence);
+       if (ret)
+               goto err;
+       drm_syncobj_replace_fence(binary_syncobj, fence);
+       dma_fence_put(fence);
+err:
+       drm_syncobj_put(binary_syncobj);
+
+       return ret;
+}
+int
+drm_syncobj_transfer_ioctl(struct drm_device *dev, void *data,
+                          struct drm_file *file_private)
+{
+       struct drm_syncobj_transfer *args = data;
+       int ret;
+
+       if (!drm_core_check_feature(dev, DRIVER_SYNCOBJ))
+               return -ENODEV;
+
+       if (args->pad)
+               return -EINVAL;
+
+       if (args->dst_point)
+               ret = drm_syncobj_transfer_to_timeline(file_private, args);
+       else
+               ret = drm_syncobj_transfer_to_binary(file_private, args);
+
+       return ret;
+}
+
 static void syncobj_wait_fence_func(struct dma_fence *fence,
                                    struct dma_fence_cb *cb)
 {
index c62be0840ba5b93a8e3e5a9fff9c6d51a320fba8..e8d0d6b51875d67fca27bba7c23eb6899976a2f7 100644 (file)
@@ -735,6 +735,15 @@ struct drm_syncobj_handle {
        __u32 pad;
 };
 
+struct drm_syncobj_transfer {
+       __u32 src_handle;
+       __u32 dst_handle;
+       __u64 src_point;
+       __u64 dst_point;
+       __u32 flags;
+       __u32 pad;
+};
+
 #define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL (1 << 0)
 #define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT (1 << 1)
 #define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_AVAILABLE (1 << 2) /* wait for time point to become available */
@@ -933,6 +942,7 @@ extern "C" {
 
 #define DRM_IOCTL_SYNCOBJ_TIMELINE_WAIT        DRM_IOWR(0xCA, struct drm_syncobj_timeline_wait)
 #define DRM_IOCTL_SYNCOBJ_QUERY                DRM_IOWR(0xCB, struct drm_syncobj_timeline_array)
+#define DRM_IOCTL_SYNCOBJ_TRANSFER     DRM_IOWR(0xCC, struct drm_syncobj_transfer)
 
 /**
  * Device specific ioctls should only be in their respective headers