/* * Copyright 2017 Red Hat * Parts ported from amdgpu (fence wait code). * Copyright 2016 Advanced Micro Devices, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. * * Authors: * */ /** * DOC: Overview * * DRM synchronisation objects (syncobj) are a persistent objects, * that contain an optional fence. The fence can be updated with a new * fence, or be NULL. * * syncobj's can be waited upon, where it will wait for the underlying * fence. * * syncobj's can be export to fd's and back, these fd's are opaque and * have no other use case, except passing the syncobj between processes. * * Their primary use-case is to implement Vulkan fences and semaphores. * * syncobj have a kref reference count, but also have an optional file. * The file is only created once the syncobj is exported. * The file takes a reference on the kref. */ #include <drm/drmP.h>#include <linux/file.h>#include <linux/fs.h>#include <linux/anon_inodes.h>#include <linux/sync_file.h>#include <linux/sched/signal.h> #include "drm_internal.h"#include <drm/drm_syncobj.h> /** * drm_syncobj_find - lookup and reference a sync object. * @file_private: drm file private pointer * @handle: sync object handle to lookup. * * Returns a reference to the syncobj pointed to by handle or NULL. */struct drm_syncobj *drm_syncobj_find(struct drm_file *file_private, u32 handle){ struct drm_syncobj *syncobj; spin_lock(&file_private->syncobj_table_lock); /* Check if we currently have a reference on the object */ syncobj = idr_find(&file_private->syncobj_idr, handle); if (syncobj) drm_syncobj_get(syncobj); spin_unlock(&file_private->syncobj_table_lock); return syncobj;}EXPORT_SYMBOL(drm_syncobj_find); static void drm_syncobj_add_callback_locked(struct drm_syncobj *syncobj, struct drm_syncobj_cb *cb, drm_syncobj_func_t func){ cb->func = func; list_add_tail(&cb->node, &syncobj->cb_list);} static int drm_syncobj_fence_get_or_add_callback(struct drm_syncobj *syncobj, struct dma_fence **fence, struct drm_syncobj_cb *cb, drm_syncobj_func_t func){ int ret; *fence = drm_syncobj_fence_get(syncobj); if (*fence) return 1; spin_lock(&syncobj->lock); /* We've already tried once to get a fence and failed. Now that we * have the lock, try one more time just to be sure we don't add a * callback when a fence has already been set. */ if (syncobj->fence) { *fence = dma_fence_get(syncobj->fence); ret = 1; } else { *fence = NULL; drm_syncobj_add_callback_locked(syncobj, cb, func); ret = 0; } spin_unlock(&syncobj->lock); return ret;} /** * drm_syncobj_add_callback - adds a callback to syncobj::cb_list * @syncobj: Sync object to which to add the callback * @cb: Callback to add * @func: Func to use when initializing the drm_syncobj_cb struct * * This adds a callback to be called next time the fence is replaced */void drm_syncobj_add_callback(struct drm_syncobj *syncobj, struct drm_syncobj_cb *cb, drm_syncobj_func_t func){ spin_lock(&syncobj->lock); drm_syncobj_add_callback_locked(syncobj, cb, func); spin_unlock(&syncobj->lock);}EXPORT_SYMBOL(drm_syncobj_add_callback); /** * drm_syncobj_add_callback - removes a callback to syncobj::cb_list * @syncobj: Sync object from which to remove the callback * @cb: Callback to remove */void drm_syncobj_remove_callback(struct drm_syncobj *syncobj, struct drm_syncobj_cb *cb){ spin_lock(&syncobj->lock); list_del_init(&cb->node); spin_unlock(&syncobj->lock);}EXPORT_SYMBOL(drm_syncobj_remove_callback); /** * drm_syncobj_replace_fence - replace fence in a sync object. * @syncobj: Sync object to replace fence in * @fence: fence to install in sync file. * * This replaces the fence on a sync object. */void drm_syncobj_replace_fence(struct drm_syncobj *syncobj, struct dma_fence *fence){ struct dma_fence *old_fence; struct drm_syncobj_cb *cur, *tmp; if (fence) dma_fence_get(fence); spin_lock(&syncobj->lock); old_fence = syncobj->fence; syncobj->fence = fence; if (fence != old_fence) { list_for_each_entry_safe(cur, tmp, &syncobj->cb_list, node) { list_del_init(&cur->node); cur->func(syncobj, cur); } } spin_unlock(&syncobj->lock); dma_fence_put(old_fence);}EXPORT_SYMBOL(drm_syncobj_replace_fence); struct drm_syncobj_null_fence { struct dma_fence base; spinlock_t lock;}; static const char *drm_syncobj_null_fence_get_name(struct dma_fence *fence){ return "syncobjnull";} static bool drm_syncobj_null_fence_enable_signaling(struct dma_fence *fence){ dma_fence_enable_sw_signaling(fence); return !dma_fence_is_signaled(fence);} static const struct dma_fence_ops drm_syncobj_null_fence_ops = { .get_driver_name = drm_syncobj_null_fence_get_name, .get_timeline_name = drm_syncobj_null_fence_get_name, .enable_signaling = drm_syncobj_null_fence_enable_signaling, .wait = dma_fence_default_wait, .release = NULL,}; static int drm_syncobj_assign_null_handle(struct drm_syncobj *syncobj){ struct drm_syncobj_null_fence *fence; fence = kzalloc(sizeof(*fence), GFP_KERNEL); if (fence == NULL) return -ENOMEM; spin_lock_init(&fence->lock); dma_fence_init(&fence->base, &drm_syncobj_null_fence_ops, &fence->lock, 0, 0); dma_fence_signal(&fence->base); drm_syncobj_replace_fence(syncobj, &fence->base); dma_fence_put(&fence->base); return 0;} int drm_syncobj_find_fence(struct drm_file *file_private, u32 handle, struct dma_fence **fence){ struct drm_syncobj *syncobj = drm_syncobj_find(file_private, handle); int ret = 0; if (!syncobj) return -ENOENT; *fence = drm_syncobj_fence_get(syncobj); if (!*fence) { ret = -EINVAL; } drm_syncobj_put(syncobj); return ret;}EXPORT_SYMBOL(drm_syncobj_find_fence); /** * drm_syncobj_free - free a sync object. * @kref: kref to free. * * Only to be called from kref_put in drm_syncobj_put. */void drm_syncobj_free(struct kref *kref){ struct drm_syncobj *syncobj = container_of(kref, struct drm_syncobj, refcount); drm_syncobj_replace_fence(syncobj, NULL); kfree(syncobj);}EXPORT_SYMBOL(drm_syncobj_free); static int drm_syncobj_create(struct drm_file *file_private, u32 *handle, uint32_t flags){ int ret; struct drm_syncobj *syncobj; syncobj = kzalloc(sizeof(struct drm_syncobj), GFP_KERNEL); if (!syncobj) return -ENOMEM; kref_init(&syncobj->refcount); INIT_LIST_HEAD(&syncobj->cb_list); spin_lock_init(&syncobj->lock); if (flags & DRM_SYNCOBJ_CREATE_SIGNALED) { ret = drm_syncobj_assign_null_handle(syncobj); if (ret < 0) { drm_syncobj_put(syncobj); return ret; } } idr_preload(GFP_KERNEL); spin_lock(&file_private->syncobj_table_lock); ret = idr_alloc(&file_private->syncobj_idr, syncobj, 1, 0, GFP_NOWAIT); spin_unlock(&file_private->syncobj_table_lock); idr_preload_end(); if (ret < 0) { drm_syncobj_put(syncobj); return ret; } *handle = ret; return 0;} static int drm_syncobj_destroy(struct drm_file *file_private, u32 handle){ struct drm_syncobj *syncobj; spin_lock(&file_private->syncobj_table_lock); syncobj = idr_remove(&file_private->syncobj_idr, handle); spin_unlock(&file_private->syncobj_table_lock); if (!syncobj) return -EINVAL; drm_syncobj_put(syncobj); return 0;} static int drm_syncobj_file_release(struct inode *inode, struct file *file){ struct drm_syncobj *syncobj = file->private_data; drm_syncobj_put(syncobj); return 0;} static const struct file_operations drm_syncobj_file_fops = { .release = drm_syncobj_file_release,}; static int drm_syncobj_alloc_file(struct drm_syncobj *syncobj){ struct file *file = anon_inode_getfile("syncobj_file", &drm_syncobj_file_fops, syncobj, 0); if (IS_ERR(file)) return PTR_ERR(file); drm_syncobj_get(syncobj); if (cmpxchg(&syncobj->file, NULL, file)) { /* lost the race */ fput(file); } return 0;} static int drm_syncobj_handle_to_fd(struct drm_file *file_private, u32 handle, int *p_fd){ struct drm_syncobj *syncobj = drm_syncobj_find(file_private, handle); int ret; int fd; if (!syncobj) return -EINVAL; fd = get_unused_fd_flags(O_CLOEXEC); if (fd < 0) { drm_syncobj_put(syncobj); return fd; } if (!syncobj->file) { ret = drm_syncobj_alloc_file(syncobj); if (ret) goto out_put_fd; } fd_install(fd, syncobj->file); drm_syncobj_put(syncobj); *p_fd = fd; return 0;out_put_fd: put_unused_fd(fd); drm_syncobj_put(syncobj); return ret;} static struct drm_syncobj *drm_syncobj_fdget(int fd){ struct file *file = fget(fd); if (!file) return NULL; if (file->f_op != &drm_syncobj_file_fops) goto err; return file->private_data;err: fput(file); return NULL;}; static int drm_syncobj_fd_to_handle(struct drm_file *file_private, int fd, u32 *handle){ struct drm_syncobj *syncobj = drm_syncobj_fdget(fd); int ret; if (!syncobj) return -EINVAL; /* take a reference to put in the idr */ drm_syncobj_get(syncobj); idr_preload(GFP_KERNEL); spin_lock(&file_private->syncobj_table_lock); ret = idr_alloc(&file_private->syncobj_idr, syncobj, 1, 0, GFP_NOWAIT); spin_unlock(&file_private->syncobj_table_lock); idr_preload_end(); if (ret < 0) { fput(syncobj->file); return ret; } *handle = ret; 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(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_find_fence(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 * @file_private: drm file-private structure to set up * * Called at device open time, sets up the structure for handling refcounting * of sync objects. */voiddrm_syncobj_open(struct drm_file *file_private){ idr_init(&file_private->syncobj_idr); spin_lock_init(&file_private->syncobj_table_lock);} static intdrm_syncobj_release_handle(int id, void *ptr, void *data){ struct drm_syncobj *syncobj = ptr; drm_syncobj_put(syncobj); return 0;} /** * drm_syncobj_release - release file-private sync object resources * @file_private: drm file-private structure to clean up * * Called at close time when the filp is going away.Lines 1–500 of 956. Load more
/* * Copyright 2017 Red Hat * Parts ported from amdgpu (fence wait code). * Copyright 2016 Advanced Micro Devices, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. * * Authors: * */ /** * DOC: Overview * * DRM synchronisation objects (syncobj) are a persistent objects, * that contain an optional fence. The fence can be updated with a new * fence, or be NULL. * * syncobj's can be waited upon, where it will wait for the underlying * fence. * * syncobj's can be export to fd's and back, these fd's are opaque and * have no other use case, except passing the syncobj between processes. * * Their primary use-case is to implement Vulkan fences and semaphores. * * syncobj have a kref reference count, but also have an optional file. * The file is only created once the syncobj is exported. * The file takes a reference on the kref. */ #include <drm/drmP.h> #include <linux/file.h> #include <linux/fs.h> #include <linux/anon_inodes.h> #include <linux/sync_file.h> #include <linux/sched/signal.h> #include "drm_internal.h" #include <drm/drm_syncobj.h> /** * drm_syncobj_find - lookup and reference a sync object. * @file_private: drm file private pointer * @handle: sync object handle to lookup. * * Returns a reference to the syncobj pointed to by handle or NULL. */ struct drm_syncobj *drm_syncobj_find(struct drm_file *file_private, u32 handle) { struct drm_syncobj *syncobj; spin_lock(&file_private->syncobj_table_lock); /* Check if we currently have a reference on the object */ syncobj = idr_find(&file_private->syncobj_idr, handle); if (syncobj) drm_syncobj_get(syncobj); spin_unlock(&file_private->syncobj_table_lock); return syncobj; } EXPORT_SYMBOL(drm_syncobj_find); static void drm_syncobj_add_callback_locked(struct drm_syncobj *syncobj, struct drm_syncobj_cb *cb, drm_syncobj_func_t func) { cb->func = func; list_add_tail(&cb->node, &syncobj->cb_list); } static int drm_syncobj_fence_get_or_add_callback(struct drm_syncobj *syncobj, struct dma_fence **fence, struct drm_syncobj_cb *cb, drm_syncobj_func_t func) { int ret; *fence = drm_syncobj_fence_get(syncobj); if (*fence) return 1; spin_lock(&syncobj->lock); /* We've already tried once to get a fence and failed. Now that we * have the lock, try one more time just to be sure we don't add a * callback when a fence has already been set. */ if (syncobj->fence) { *fence = dma_fence_get(syncobj->fence); ret = 1; } else { *fence = NULL; drm_syncobj_add_callback_locked(syncobj, cb, func); ret = 0; } spin_unlock(&syncobj->lock); return ret; } /** * drm_syncobj_add_callback - adds a callback to syncobj::cb_list * @syncobj: Sync object to which to add the callback * @cb: Callback to add * @func: Func to use when initializing the drm_syncobj_cb struct * * This adds a callback to be called next time the fence is replaced */ void drm_syncobj_add_callback(struct drm_syncobj *syncobj, struct drm_syncobj_cb *cb, drm_syncobj_func_t func) { spin_lock(&syncobj->lock); drm_syncobj_add_callback_locked(syncobj, cb, func); spin_unlock(&syncobj->lock); } EXPORT_SYMBOL(drm_syncobj_add_callback); /** * drm_syncobj_add_callback - removes a callback to syncobj::cb_list * @syncobj: Sync object from which to remove the callback * @cb: Callback to remove */ void drm_syncobj_remove_callback(struct drm_syncobj *syncobj, struct drm_syncobj_cb *cb) { spin_lock(&syncobj->lock); list_del_init(&cb->node); spin_unlock(&syncobj->lock); } EXPORT_SYMBOL(drm_syncobj_remove_callback); /** * drm_syncobj_replace_fence - replace fence in a sync object. * @syncobj: Sync object to replace fence in * @fence: fence to install in sync file. * * This replaces the fence on a sync object. */ void drm_syncobj_replace_fence(struct drm_syncobj *syncobj, struct dma_fence *fence) { struct dma_fence *old_fence; struct drm_syncobj_cb *cur, *tmp; if (fence) dma_fence_get(fence); spin_lock(&syncobj->lock); old_fence = syncobj->fence; syncobj->fence = fence; if (fence != old_fence) { list_for_each_entry_safe(cur, tmp, &syncobj->cb_list, node) { list_del_init(&cur->node); cur->func(syncobj, cur); } } spin_unlock(&syncobj->lock); dma_fence_put(old_fence); } EXPORT_SYMBOL(drm_syncobj_replace_fence); struct drm_syncobj_null_fence { struct dma_fence base; spinlock_t lock; }; static const char *drm_syncobj_null_fence_get_name(struct dma_fence *fence) { return "syncobjnull"; } static bool drm_syncobj_null_fence_enable_signaling(struct dma_fence *fence) { dma_fence_enable_sw_signaling(fence); return !dma_fence_is_signaled(fence); } static const struct dma_fence_ops drm_syncobj_null_fence_ops = { .get_driver_name = drm_syncobj_null_fence_get_name, .get_timeline_name = drm_syncobj_null_fence_get_name, .enable_signaling = drm_syncobj_null_fence_enable_signaling, .wait = dma_fence_default_wait, .release = NULL, }; static int drm_syncobj_assign_null_handle(struct drm_syncobj *syncobj) { struct drm_syncobj_null_fence *fence; fence = kzalloc(sizeof(*fence), GFP_KERNEL); if (fence == NULL) return -ENOMEM; spin_lock_init(&fence->lock); dma_fence_init(&fence->base, &drm_syncobj_null_fence_ops, &fence->lock, 0, 0); dma_fence_signal(&fence->base); drm_syncobj_replace_fence(syncobj, &fence->base); dma_fence_put(&fence->base); return 0; } int drm_syncobj_find_fence(struct drm_file *file_private, u32 handle, struct dma_fence **fence) { struct drm_syncobj *syncobj = drm_syncobj_find(file_private, handle); int ret = 0; if (!syncobj) return -ENOENT; *fence = drm_syncobj_fence_get(syncobj); if (!*fence) { ret = -EINVAL; } drm_syncobj_put(syncobj); return ret; } EXPORT_SYMBOL(drm_syncobj_find_fence); /** * drm_syncobj_free - free a sync object. * @kref: kref to free. * * Only to be called from kref_put in drm_syncobj_put. */ void drm_syncobj_free(struct kref *kref) { struct drm_syncobj *syncobj = container_of(kref, struct drm_syncobj, refcount); drm_syncobj_replace_fence(syncobj, NULL); kfree(syncobj); } EXPORT_SYMBOL(drm_syncobj_free); static int drm_syncobj_create(struct drm_file *file_private, u32 *handle, uint32_t flags) { int ret; struct drm_syncobj *syncobj; syncobj = kzalloc(sizeof(struct drm_syncobj), GFP_KERNEL); if (!syncobj) return -ENOMEM; kref_init(&syncobj->refcount); INIT_LIST_HEAD(&syncobj->cb_list); spin_lock_init(&syncobj->lock); if (flags & DRM_SYNCOBJ_CREATE_SIGNALED) { ret = drm_syncobj_assign_null_handle(syncobj); if (ret < 0) { drm_syncobj_put(syncobj); return ret; } } idr_preload(GFP_KERNEL); spin_lock(&file_private->syncobj_table_lock); ret = idr_alloc(&file_private->syncobj_idr, syncobj, 1, 0, GFP_NOWAIT); spin_unlock(&file_private->syncobj_table_lock); idr_preload_end(); if (ret < 0) { drm_syncobj_put(syncobj); return ret; } *handle = ret; return 0; } static int drm_syncobj_destroy(struct drm_file *file_private, u32 handle) { struct drm_syncobj *syncobj; spin_lock(&file_private->syncobj_table_lock); syncobj = idr_remove(&file_private->syncobj_idr, handle); spin_unlock(&file_private->syncobj_table_lock); if (!syncobj) return -EINVAL; drm_syncobj_put(syncobj); return 0; } static int drm_syncobj_file_release(struct inode *inode, struct file *file) { struct drm_syncobj *syncobj = file->private_data; drm_syncobj_put(syncobj); return 0; } static const struct file_operations drm_syncobj_file_fops = { .release = drm_syncobj_file_release, }; static int drm_syncobj_alloc_file(struct drm_syncobj *syncobj) { struct file *file = anon_inode_getfile("syncobj_file", &drm_syncobj_file_fops, syncobj, 0); if (IS_ERR(file)) return PTR_ERR(file); drm_syncobj_get(syncobj); if (cmpxchg(&syncobj->file, NULL, file)) { /* lost the race */ fput(file); } return 0; } static int drm_syncobj_handle_to_fd(struct drm_file *file_private, u32 handle, int *p_fd) { struct drm_syncobj *syncobj = drm_syncobj_find(file_private, handle); int ret; int fd; if (!syncobj) return -EINVAL; fd = get_unused_fd_flags(O_CLOEXEC); if (fd < 0) { drm_syncobj_put(syncobj); return fd; } if (!syncobj->file) { ret = drm_syncobj_alloc_file(syncobj); if (ret) goto out_put_fd; } fd_install(fd, syncobj->file); drm_syncobj_put(syncobj); *p_fd = fd; return 0; out_put_fd: put_unused_fd(fd); drm_syncobj_put(syncobj); return ret; } static struct drm_syncobj *drm_syncobj_fdget(int fd) { struct file *file = fget(fd); if (!file) return NULL; if (file->f_op != &drm_syncobj_file_fops) goto err; return file->private_data; err: fput(file); return NULL; }; static int drm_syncobj_fd_to_handle(struct drm_file *file_private, int fd, u32 *handle) { struct drm_syncobj *syncobj = drm_syncobj_fdget(fd); int ret; if (!syncobj) return -EINVAL; /* take a reference to put in the idr */ drm_syncobj_get(syncobj); idr_preload(GFP_KERNEL); spin_lock(&file_private->syncobj_table_lock); ret = idr_alloc(&file_private->syncobj_idr, syncobj, 1, 0, GFP_NOWAIT); spin_unlock(&file_private->syncobj_table_lock); idr_preload_end(); if (ret < 0) { fput(syncobj->file); return ret; } *handle = ret; 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(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_find_fence(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 * @file_private: drm file-private structure to set up * * Called at device open time, sets up the structure for handling refcounting * of sync objects. */ void drm_syncobj_open(struct drm_file *file_private) { idr_init(&file_private->syncobj_idr); spin_lock_init(&file_private->syncobj_table_lock); } static int drm_syncobj_release_handle(int id, void *ptr, void *data) { struct drm_syncobj *syncobj = ptr; drm_syncobj_put(syncobj); return 0; } /** * drm_syncobj_release - release file-private sync object resources * @file_private: drm file-private structure to clean up * * Called at close time when the filp is going away.