Commit 1321fd2c authored by Marek Olšák's avatar Marek Olšák Committed by Alex Deucher

drm/syncobj: extract two helpers from drm_syncobj_create

For amdgpu.

drm_syncobj_create is renamed to drm_syncobj_create_as_handle, and new
helpers drm_syncobj_create and drm_syncobj_get_handle are added.
Reviewed-by: default avatarDave Airlie <airlied@redhat.com>
Signed-off-by: default avatarMarek Olšák <marek.olsak@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent e1827a30
...@@ -262,8 +262,14 @@ void drm_syncobj_free(struct kref *kref) ...@@ -262,8 +262,14 @@ void drm_syncobj_free(struct kref *kref)
} }
EXPORT_SYMBOL(drm_syncobj_free); EXPORT_SYMBOL(drm_syncobj_free);
static int drm_syncobj_create(struct drm_file *file_private, /**
u32 *handle, uint32_t flags) * drm_syncobj_create - create a new syncobj
* @out_syncobj: returned syncobj
* @flags: DRM_SYNCOBJ_* flags
* @fence: if non-NULL, the syncobj will represent this fence
*/
int drm_syncobj_create(struct drm_syncobj **out_syncobj, uint32_t flags,
struct dma_fence *fence)
{ {
int ret; int ret;
struct drm_syncobj *syncobj; struct drm_syncobj *syncobj;
...@@ -284,6 +290,25 @@ static int drm_syncobj_create(struct drm_file *file_private, ...@@ -284,6 +290,25 @@ static int drm_syncobj_create(struct drm_file *file_private,
} }
} }
if (fence)
drm_syncobj_replace_fence(syncobj, fence);
*out_syncobj = syncobj;
return 0;
}
EXPORT_SYMBOL(drm_syncobj_create);
/**
* drm_syncobj_get_handle - get a handle from a syncobj
*/
int drm_syncobj_get_handle(struct drm_file *file_private,
struct drm_syncobj *syncobj, u32 *handle)
{
int ret;
/* take a reference to put in the idr */
drm_syncobj_get(syncobj);
idr_preload(GFP_KERNEL); idr_preload(GFP_KERNEL);
spin_lock(&file_private->syncobj_table_lock); spin_lock(&file_private->syncobj_table_lock);
ret = idr_alloc(&file_private->syncobj_idr, syncobj, 1, 0, GFP_NOWAIT); ret = idr_alloc(&file_private->syncobj_idr, syncobj, 1, 0, GFP_NOWAIT);
...@@ -299,6 +324,22 @@ static int drm_syncobj_create(struct drm_file *file_private, ...@@ -299,6 +324,22 @@ static int drm_syncobj_create(struct drm_file *file_private,
*handle = ret; *handle = ret;
return 0; return 0;
} }
EXPORT_SYMBOL(drm_syncobj_get_handle);
static int drm_syncobj_create_as_handle(struct drm_file *file_private,
u32 *handle, uint32_t flags)
{
int ret;
struct drm_syncobj *syncobj;
ret = drm_syncobj_create(&syncobj, flags, NULL);
if (ret)
return ret;
ret = drm_syncobj_get_handle(file_private, syncobj, handle);
drm_syncobj_put(syncobj);
return ret;
}
static int drm_syncobj_destroy(struct drm_file *file_private, static int drm_syncobj_destroy(struct drm_file *file_private,
u32 handle) u32 handle)
...@@ -522,7 +563,7 @@ drm_syncobj_create_ioctl(struct drm_device *dev, void *data, ...@@ -522,7 +563,7 @@ drm_syncobj_create_ioctl(struct drm_device *dev, void *data,
if (args->flags & ~DRM_SYNCOBJ_CREATE_SIGNALED) if (args->flags & ~DRM_SYNCOBJ_CREATE_SIGNALED)
return -EINVAL; return -EINVAL;
return drm_syncobj_create(file_private, return drm_syncobj_create_as_handle(file_private,
&args->handle, args->flags); &args->handle, args->flags);
} }
......
...@@ -136,5 +136,9 @@ int drm_syncobj_find_fence(struct drm_file *file_private, ...@@ -136,5 +136,9 @@ int drm_syncobj_find_fence(struct drm_file *file_private,
u32 handle, u32 handle,
struct dma_fence **fence); struct dma_fence **fence);
void drm_syncobj_free(struct kref *kref); void drm_syncobj_free(struct kref *kref);
int drm_syncobj_create(struct drm_syncobj **out_syncobj, uint32_t flags,
struct dma_fence *fence);
int drm_syncobj_get_handle(struct drm_file *file_private,
struct drm_syncobj *syncobj, u32 *handle);
#endif #endif
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