Commit 3ee45a3b authored by Dave Airlie's avatar Dave Airlie

drm/syncobj: add sync_file interaction. (v1.2)

This interface allows importing the fence from a sync_file into
an existing drm sync object, or exporting the fence attached to
an existing drm sync object into a new sync file object.

This should only be used to interact with sync files where necessary.

v1.1: fence put fixes (Chris), drop fence from ioctl names (Chris)
fixup for new fence replace API.
Reviewed-by: default avatarSean Paul <seanpaul@chromium.org>
Reviewed-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
parent e9083420
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include <linux/file.h> #include <linux/file.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/anon_inodes.h> #include <linux/anon_inodes.h>
#include <linux/sync_file.h>
#include "drm_internal.h" #include "drm_internal.h"
#include <drm/drm_syncobj.h> #include <drm/drm_syncobj.h>
...@@ -276,6 +277,59 @@ static int drm_syncobj_fd_to_handle(struct drm_file *file_private, ...@@ -276,6 +277,59 @@ static int drm_syncobj_fd_to_handle(struct drm_file *file_private,
return 0; return 0;
} }
int drm_syncobj_import_sync_file_fence(struct drm_file *file_private,
int fd, int handle)
{
struct dma_fence *fence = sync_file_get_fence(fd);
struct drm_syncobj *syncobj;
if (!fence)
return -EINVAL;
syncobj = drm_syncobj_find(file_private, handle);
if (!syncobj) {
dma_fence_put(fence);
return -ENOENT;
}
drm_syncobj_replace_fence(file_private, syncobj, fence);
dma_fence_put(fence);
drm_syncobj_put(syncobj);
return 0;
}
int drm_syncobj_export_sync_file(struct drm_file *file_private,
int handle, int *p_fd)
{
int ret;
struct dma_fence *fence;
struct sync_file *sync_file;
int fd = get_unused_fd_flags(O_CLOEXEC);
if (fd < 0)
return fd;
ret = drm_syncobj_fence_get(file_private, handle, &fence);
if (ret)
goto err_put_fd;
sync_file = sync_file_create(fence);
dma_fence_put(fence);
if (!sync_file) {
ret = -EINVAL;
goto err_put_fd;
}
fd_install(fd, sync_file->file);
*p_fd = fd;
return 0;
err_put_fd:
put_unused_fd(fd);
return ret;
}
/** /**
* drm_syncobj_open - initalizes syncobj file-private structures at devnode open time * drm_syncobj_open - initalizes syncobj file-private structures at devnode open time
* @dev: drm_device which is being opened by userspace * @dev: drm_device which is being opened by userspace
...@@ -358,9 +412,17 @@ drm_syncobj_handle_to_fd_ioctl(struct drm_device *dev, void *data, ...@@ -358,9 +412,17 @@ drm_syncobj_handle_to_fd_ioctl(struct drm_device *dev, void *data,
if (!drm_core_check_feature(dev, DRIVER_SYNCOBJ)) if (!drm_core_check_feature(dev, DRIVER_SYNCOBJ))
return -ENODEV; return -ENODEV;
if (args->pad || args->flags) if (args->pad)
return -EINVAL; return -EINVAL;
if (args->flags != 0 &&
args->flags != DRM_SYNCOBJ_HANDLE_TO_FD_FLAGS_EXPORT_SYNC_FILE)
return -EINVAL;
if (args->flags & DRM_SYNCOBJ_HANDLE_TO_FD_FLAGS_EXPORT_SYNC_FILE)
return drm_syncobj_export_sync_file(file_private, args->handle,
&args->fd);
return drm_syncobj_handle_to_fd(file_private, args->handle, return drm_syncobj_handle_to_fd(file_private, args->handle,
&args->fd); &args->fd);
} }
...@@ -374,9 +436,18 @@ drm_syncobj_fd_to_handle_ioctl(struct drm_device *dev, void *data, ...@@ -374,9 +436,18 @@ drm_syncobj_fd_to_handle_ioctl(struct drm_device *dev, void *data,
if (!drm_core_check_feature(dev, DRIVER_SYNCOBJ)) if (!drm_core_check_feature(dev, DRIVER_SYNCOBJ))
return -ENODEV; return -ENODEV;
if (args->pad || args->flags) if (args->pad)
return -EINVAL;
if (args->flags != 0 &&
args->flags != DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE)
return -EINVAL; return -EINVAL;
if (args->flags & DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE)
return drm_syncobj_import_sync_file_fence(file_private,
args->fd,
args->handle);
return drm_syncobj_fd_to_handle(file_private, args->fd, return drm_syncobj_fd_to_handle(file_private, args->fd,
&args->handle); &args->handle);
} }
...@@ -708,6 +708,8 @@ struct drm_syncobj_destroy { ...@@ -708,6 +708,8 @@ struct drm_syncobj_destroy {
__u32 pad; __u32 pad;
}; };
#define DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE (1 << 0)
#define DRM_SYNCOBJ_HANDLE_TO_FD_FLAGS_EXPORT_SYNC_FILE (1 << 0)
struct drm_syncobj_handle { struct drm_syncobj_handle {
__u32 handle; __u32 handle;
__u32 flags; __u32 flags;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment