Commit 3e6fb72d authored by Jason Ekstrand's avatar Jason Ekstrand Committed by Dave Airlie

drm/syncobj: Add a syncobj_array_find helper

The wait ioctl has a bunch of code to read an syncobj handle array from
userspace and turn it into an array of syncobj pointers.  We're about to
add two new IOCTLs which will need to work with arrays of syncobj
handles so let's make some helpers.
Signed-off-by: default avatarJason Ekstrand <jason@jlekstrand.net>
Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
parent e7aca503
...@@ -798,58 +798,43 @@ static int drm_syncobj_array_wait(struct drm_device *dev, ...@@ -798,58 +798,43 @@ static int drm_syncobj_array_wait(struct drm_device *dev,
return 0; return 0;
} }
int static int drm_syncobj_array_find(struct drm_file *file_private,
drm_syncobj_wait_ioctl(struct drm_device *dev, void *data, void *user_handles, uint32_t count_handles,
struct drm_file *file_private) struct drm_syncobj ***syncobjs_out)
{ {
struct drm_syncobj_wait *args = data; uint32_t i, *handles;
uint32_t *handles;
struct drm_syncobj **syncobjs; struct drm_syncobj **syncobjs;
int ret = 0; int ret;
uint32_t i;
if (!drm_core_check_feature(dev, DRIVER_SYNCOBJ))
return -ENODEV;
if (args->flags & ~(DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL |
DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT))
return -EINVAL;
if (args->count_handles == 0)
return -EINVAL;
/* Get the handles from userspace */ handles = kmalloc_array(count_handles, sizeof(*handles), GFP_KERNEL);
handles = kmalloc_array(args->count_handles, sizeof(uint32_t),
GFP_KERNEL);
if (handles == NULL) if (handles == NULL)
return -ENOMEM; return -ENOMEM;
if (copy_from_user(handles, if (copy_from_user(handles, user_handles,
u64_to_user_ptr(args->handles), sizeof(uint32_t) * count_handles)) {
sizeof(uint32_t) * args->count_handles)) {
ret = -EFAULT; ret = -EFAULT;
goto err_free_handles; goto err_free_handles;
} }
syncobjs = kcalloc(args->count_handles, syncobjs = kmalloc_array(count_handles, sizeof(*syncobjs), GFP_KERNEL);
sizeof(struct drm_syncobj *), GFP_KERNEL); if (syncobjs == NULL) {
if (!syncobjs) {
ret = -ENOMEM; ret = -ENOMEM;
goto err_free_handles; goto err_free_handles;
} }
for (i = 0; i < args->count_handles; i++) { for (i = 0; i < count_handles; i++) {
syncobjs[i] = drm_syncobj_find(file_private, handles[i]); syncobjs[i] = drm_syncobj_find(file_private, handles[i]);
if (!syncobjs[i]) { if (!syncobjs[i]) {
ret = -ENOENT; ret = -ENOENT;
goto err_free_fence_array; goto err_put_syncobjs;
} }
} }
ret = drm_syncobj_array_wait(dev, file_private, kfree(handles);
args, syncobjs); *syncobjs_out = syncobjs;
return 0;
err_free_fence_array: err_put_syncobjs:
while (i-- > 0) while (i-- > 0)
drm_syncobj_put(syncobjs[i]); drm_syncobj_put(syncobjs[i]);
kfree(syncobjs); kfree(syncobjs);
...@@ -858,3 +843,45 @@ drm_syncobj_wait_ioctl(struct drm_device *dev, void *data, ...@@ -858,3 +843,45 @@ drm_syncobj_wait_ioctl(struct drm_device *dev, void *data,
return ret; return ret;
} }
static void drm_syncobj_array_free(struct drm_syncobj **syncobjs,
uint32_t count)
{
uint32_t i;
for (i = 0; i < count; i++)
drm_syncobj_put(syncobjs[i]);
kfree(syncobjs);
}
int
drm_syncobj_wait_ioctl(struct drm_device *dev, void *data,
struct drm_file *file_private)
{
struct drm_syncobj_wait *args = data;
struct drm_syncobj **syncobjs;
int ret = 0;
if (!drm_core_check_feature(dev, DRIVER_SYNCOBJ))
return -ENODEV;
if (args->flags & ~(DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL |
DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT))
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;
ret = drm_syncobj_array_wait(dev, file_private,
args, syncobjs);
drm_syncobj_array_free(syncobjs, args->count_handles);
return ret;
}
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