2 * Copyright 2017 Red Hat
3 * Parts ported from amdgpu (fence wait code).
4 * Copyright 2016 Advanced Micro Devices, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
32 * DRM synchronisation objects (syncobj, see struct &drm_syncobj) are
33 * persistent objects that contain an optional fence. The fence can be updated
34 * with a new fence, or be NULL.
36 * syncobj's can be waited upon, where it will wait for the underlying
39 * syncobj's can be export to fd's and back, these fd's are opaque and
40 * have no other use case, except passing the syncobj between processes.
42 * Their primary use-case is to implement Vulkan fences and semaphores.
44 * syncobj have a kref reference count, but also have an optional file.
45 * The file is only created once the syncobj is exported.
46 * The file takes a reference on the kref.
50 #include <linux/file.h>
52 #include <linux/anon_inodes.h>
53 #include <linux/sync_file.h>
54 #include <linux/sched/signal.h>
56 #include "drm_internal.h"
57 #include <drm/drm_syncobj.h>
60 * drm_syncobj_find - lookup and reference a sync object.
61 * @file_private: drm file private pointer
62 * @handle: sync object handle to lookup.
64 * Returns a reference to the syncobj pointed to by handle or NULL. The
65 * reference must be released by calling drm_syncobj_put().
67 struct drm_syncobj
*drm_syncobj_find(struct drm_file
*file_private
,
70 struct drm_syncobj
*syncobj
;
72 spin_lock(&file_private
->syncobj_table_lock
);
74 /* Check if we currently have a reference on the object */
75 syncobj
= idr_find(&file_private
->syncobj_idr
, handle
);
77 drm_syncobj_get(syncobj
);
79 spin_unlock(&file_private
->syncobj_table_lock
);
83 EXPORT_SYMBOL(drm_syncobj_find
);
85 static void drm_syncobj_add_callback_locked(struct drm_syncobj
*syncobj
,
86 struct drm_syncobj_cb
*cb
,
87 drm_syncobj_func_t func
)
90 list_add_tail(&cb
->node
, &syncobj
->cb_list
);
93 static int drm_syncobj_fence_get_or_add_callback(struct drm_syncobj
*syncobj
,
94 struct dma_fence
**fence
,
95 struct drm_syncobj_cb
*cb
,
96 drm_syncobj_func_t func
)
102 *fence
= drm_syncobj_fence_get(syncobj
);
106 spin_lock(&syncobj
->lock
);
107 /* We've already tried once to get a fence and failed. Now that we
108 * have the lock, try one more time just to be sure we don't add a
109 * callback when a fence has already been set.
111 if (syncobj
->fence
) {
112 *fence
= dma_fence_get(rcu_dereference_protected(syncobj
->fence
,
113 lockdep_is_held(&syncobj
->lock
)));
117 drm_syncobj_add_callback_locked(syncobj
, cb
, func
);
120 spin_unlock(&syncobj
->lock
);
126 * drm_syncobj_add_callback - adds a callback to syncobj::cb_list
127 * @syncobj: Sync object to which to add the callback
128 * @cb: Callback to add
129 * @func: Func to use when initializing the drm_syncobj_cb struct
131 * This adds a callback to be called next time the fence is replaced
133 void drm_syncobj_add_callback(struct drm_syncobj
*syncobj
,
134 struct drm_syncobj_cb
*cb
,
135 drm_syncobj_func_t func
)
137 spin_lock(&syncobj
->lock
);
138 drm_syncobj_add_callback_locked(syncobj
, cb
, func
);
139 spin_unlock(&syncobj
->lock
);
141 EXPORT_SYMBOL(drm_syncobj_add_callback
);
144 * drm_syncobj_add_callback - removes a callback to syncobj::cb_list
145 * @syncobj: Sync object from which to remove the callback
146 * @cb: Callback to remove
148 void drm_syncobj_remove_callback(struct drm_syncobj
*syncobj
,
149 struct drm_syncobj_cb
*cb
)
151 spin_lock(&syncobj
->lock
);
152 list_del_init(&cb
->node
);
153 spin_unlock(&syncobj
->lock
);
155 EXPORT_SYMBOL(drm_syncobj_remove_callback
);
158 * drm_syncobj_replace_fence - replace fence in a sync object.
159 * @syncobj: Sync object to replace fence in
160 * @fence: fence to install in sync file.
162 * This replaces the fence on a sync object.
164 void drm_syncobj_replace_fence(struct drm_syncobj
*syncobj
,
165 struct dma_fence
*fence
)
167 struct dma_fence
*old_fence
;
168 struct drm_syncobj_cb
*cur
, *tmp
;
171 dma_fence_get(fence
);
173 spin_lock(&syncobj
->lock
);
175 old_fence
= rcu_dereference_protected(syncobj
->fence
,
176 lockdep_is_held(&syncobj
->lock
));
177 rcu_assign_pointer(syncobj
->fence
, fence
);
179 if (fence
!= old_fence
) {
180 list_for_each_entry_safe(cur
, tmp
, &syncobj
->cb_list
, node
) {
181 list_del_init(&cur
->node
);
182 cur
->func(syncobj
, cur
);
186 spin_unlock(&syncobj
->lock
);
188 dma_fence_put(old_fence
);
190 EXPORT_SYMBOL(drm_syncobj_replace_fence
);
192 struct drm_syncobj_null_fence
{
193 struct dma_fence base
;
197 static const char *drm_syncobj_null_fence_get_name(struct dma_fence
*fence
)
199 return "syncobjnull";
202 static bool drm_syncobj_null_fence_enable_signaling(struct dma_fence
*fence
)
204 dma_fence_enable_sw_signaling(fence
);
205 return !dma_fence_is_signaled(fence
);
208 static const struct dma_fence_ops drm_syncobj_null_fence_ops
= {
209 .get_driver_name
= drm_syncobj_null_fence_get_name
,
210 .get_timeline_name
= drm_syncobj_null_fence_get_name
,
211 .enable_signaling
= drm_syncobj_null_fence_enable_signaling
,
215 static int drm_syncobj_assign_null_handle(struct drm_syncobj
*syncobj
)
217 struct drm_syncobj_null_fence
*fence
;
218 fence
= kzalloc(sizeof(*fence
), GFP_KERNEL
);
222 spin_lock_init(&fence
->lock
);
223 dma_fence_init(&fence
->base
, &drm_syncobj_null_fence_ops
,
225 dma_fence_signal(&fence
->base
);
227 drm_syncobj_replace_fence(syncobj
, &fence
->base
);
229 dma_fence_put(&fence
->base
);
235 * drm_syncobj_find_fence - lookup and reference the fence in a sync object
236 * @file_private: drm file private pointer
237 * @handle: sync object handle to lookup.
238 * @fence: out parameter for the fence
240 * This is just a convenience function that combines drm_syncobj_find() and
241 * drm_syncobj_fence_get().
243 * Returns 0 on success or a negative error value on failure. On success @fence
244 * contains a reference to the fence, which must be released by calling
247 int drm_syncobj_find_fence(struct drm_file
*file_private
,
249 struct dma_fence
**fence
)
251 struct drm_syncobj
*syncobj
= drm_syncobj_find(file_private
, handle
);
257 *fence
= drm_syncobj_fence_get(syncobj
);
261 drm_syncobj_put(syncobj
);
264 EXPORT_SYMBOL(drm_syncobj_find_fence
);
267 * drm_syncobj_free - free a sync object.
268 * @kref: kref to free.
270 * Only to be called from kref_put in drm_syncobj_put.
272 void drm_syncobj_free(struct kref
*kref
)
274 struct drm_syncobj
*syncobj
= container_of(kref
,
277 drm_syncobj_replace_fence(syncobj
, NULL
);
280 EXPORT_SYMBOL(drm_syncobj_free
);
283 * drm_syncobj_create - create a new syncobj
284 * @out_syncobj: returned syncobj
285 * @flags: DRM_SYNCOBJ_* flags
286 * @fence: if non-NULL, the syncobj will represent this fence
288 * This is the first function to create a sync object. After creating, drivers
289 * probably want to make it available to userspace, either through
290 * drm_syncobj_get_handle() or drm_syncobj_get_fd().
292 * Returns 0 on success or a negative error value on failure.
294 int drm_syncobj_create(struct drm_syncobj
**out_syncobj
, uint32_t flags
,
295 struct dma_fence
*fence
)
298 struct drm_syncobj
*syncobj
;
300 syncobj
= kzalloc(sizeof(struct drm_syncobj
), GFP_KERNEL
);
304 kref_init(&syncobj
->refcount
);
305 INIT_LIST_HEAD(&syncobj
->cb_list
);
306 spin_lock_init(&syncobj
->lock
);
308 if (flags
& DRM_SYNCOBJ_CREATE_SIGNALED
) {
309 ret
= drm_syncobj_assign_null_handle(syncobj
);
311 drm_syncobj_put(syncobj
);
317 drm_syncobj_replace_fence(syncobj
, fence
);
319 *out_syncobj
= syncobj
;
322 EXPORT_SYMBOL(drm_syncobj_create
);
325 * drm_syncobj_get_handle - get a handle from a syncobj
326 * @file_private: drm file private pointer
327 * @syncobj: Sync object to export
328 * @handle: out parameter with the new handle
330 * Exports a sync object created with drm_syncobj_create() as a handle on
331 * @file_private to userspace.
333 * Returns 0 on success or a negative error value on failure.
335 int drm_syncobj_get_handle(struct drm_file
*file_private
,
336 struct drm_syncobj
*syncobj
, u32
*handle
)
340 /* take a reference to put in the idr */
341 drm_syncobj_get(syncobj
);
343 idr_preload(GFP_KERNEL
);
344 spin_lock(&file_private
->syncobj_table_lock
);
345 ret
= idr_alloc(&file_private
->syncobj_idr
, syncobj
, 1, 0, GFP_NOWAIT
);
346 spin_unlock(&file_private
->syncobj_table_lock
);
351 drm_syncobj_put(syncobj
);
358 EXPORT_SYMBOL(drm_syncobj_get_handle
);
360 static int drm_syncobj_create_as_handle(struct drm_file
*file_private
,
361 u32
*handle
, uint32_t flags
)
364 struct drm_syncobj
*syncobj
;
366 ret
= drm_syncobj_create(&syncobj
, flags
, NULL
);
370 ret
= drm_syncobj_get_handle(file_private
, syncobj
, handle
);
371 drm_syncobj_put(syncobj
);
375 static int drm_syncobj_destroy(struct drm_file
*file_private
,
378 struct drm_syncobj
*syncobj
;
380 spin_lock(&file_private
->syncobj_table_lock
);
381 syncobj
= idr_remove(&file_private
->syncobj_idr
, handle
);
382 spin_unlock(&file_private
->syncobj_table_lock
);
387 drm_syncobj_put(syncobj
);
391 static int drm_syncobj_file_release(struct inode
*inode
, struct file
*file
)
393 struct drm_syncobj
*syncobj
= file
->private_data
;
395 drm_syncobj_put(syncobj
);
399 static const struct file_operations drm_syncobj_file_fops
= {
400 .release
= drm_syncobj_file_release
,
404 * drm_syncobj_get_fd - get a file descriptor from a syncobj
405 * @syncobj: Sync object to export
406 * @p_fd: out parameter with the new file descriptor
408 * Exports a sync object created with drm_syncobj_create() as a file descriptor.
410 * Returns 0 on success or a negative error value on failure.
412 int drm_syncobj_get_fd(struct drm_syncobj
*syncobj
, int *p_fd
)
417 fd
= get_unused_fd_flags(O_CLOEXEC
);
421 file
= anon_inode_getfile("syncobj_file",
422 &drm_syncobj_file_fops
,
426 return PTR_ERR(file
);
429 drm_syncobj_get(syncobj
);
430 fd_install(fd
, file
);
435 EXPORT_SYMBOL(drm_syncobj_get_fd
);
437 static int drm_syncobj_handle_to_fd(struct drm_file
*file_private
,
438 u32 handle
, int *p_fd
)
440 struct drm_syncobj
*syncobj
= drm_syncobj_find(file_private
, handle
);
446 ret
= drm_syncobj_get_fd(syncobj
, p_fd
);
447 drm_syncobj_put(syncobj
);
451 static int drm_syncobj_fd_to_handle(struct drm_file
*file_private
,
454 struct drm_syncobj
*syncobj
;
462 if (file
->f_op
!= &drm_syncobj_file_fops
) {
467 /* take a reference to put in the idr */
468 syncobj
= file
->private_data
;
469 drm_syncobj_get(syncobj
);
471 idr_preload(GFP_KERNEL
);
472 spin_lock(&file_private
->syncobj_table_lock
);
473 ret
= idr_alloc(&file_private
->syncobj_idr
, syncobj
, 1, 0, GFP_NOWAIT
);
474 spin_unlock(&file_private
->syncobj_table_lock
);
481 drm_syncobj_put(syncobj
);
487 static int drm_syncobj_import_sync_file_fence(struct drm_file
*file_private
,
490 struct dma_fence
*fence
= sync_file_get_fence(fd
);
491 struct drm_syncobj
*syncobj
;
496 syncobj
= drm_syncobj_find(file_private
, handle
);
498 dma_fence_put(fence
);
502 drm_syncobj_replace_fence(syncobj
, fence
);
503 dma_fence_put(fence
);
504 drm_syncobj_put(syncobj
);
508 static int drm_syncobj_export_sync_file(struct drm_file
*file_private
,
509 int handle
, int *p_fd
)
512 struct dma_fence
*fence
;
513 struct sync_file
*sync_file
;
514 int fd
= get_unused_fd_flags(O_CLOEXEC
);
519 ret
= drm_syncobj_find_fence(file_private
, handle
, &fence
);
523 sync_file
= sync_file_create(fence
);
525 dma_fence_put(fence
);
532 fd_install(fd
, sync_file
->file
);
541 * drm_syncobj_open - initalizes syncobj file-private structures at devnode open time
542 * @file_private: drm file-private structure to set up
544 * Called at device open time, sets up the structure for handling refcounting
548 drm_syncobj_open(struct drm_file
*file_private
)
550 idr_init_base(&file_private
->syncobj_idr
, 1);
551 spin_lock_init(&file_private
->syncobj_table_lock
);
555 drm_syncobj_release_handle(int id
, void *ptr
, void *data
)
557 struct drm_syncobj
*syncobj
= ptr
;
559 drm_syncobj_put(syncobj
);
564 * drm_syncobj_release - release file-private sync object resources
565 * @file_private: drm file-private structure to clean up
567 * Called at close time when the filp is going away.
569 * Releases any remaining references on objects by this filp.
572 drm_syncobj_release(struct drm_file
*file_private
)
574 idr_for_each(&file_private
->syncobj_idr
,
575 &drm_syncobj_release_handle
, file_private
);
576 idr_destroy(&file_private
->syncobj_idr
);
580 drm_syncobj_create_ioctl(struct drm_device
*dev
, void *data
,
581 struct drm_file
*file_private
)
583 struct drm_syncobj_create
*args
= data
;
585 if (!drm_core_check_feature(dev
, DRIVER_SYNCOBJ
))
588 /* no valid flags yet */
589 if (args
->flags
& ~DRM_SYNCOBJ_CREATE_SIGNALED
)
592 return drm_syncobj_create_as_handle(file_private
,
593 &args
->handle
, args
->flags
);
597 drm_syncobj_destroy_ioctl(struct drm_device
*dev
, void *data
,
598 struct drm_file
*file_private
)
600 struct drm_syncobj_destroy
*args
= data
;
602 if (!drm_core_check_feature(dev
, DRIVER_SYNCOBJ
))
605 /* make sure padding is empty */
608 return drm_syncobj_destroy(file_private
, args
->handle
);
612 drm_syncobj_handle_to_fd_ioctl(struct drm_device
*dev
, void *data
,
613 struct drm_file
*file_private
)
615 struct drm_syncobj_handle
*args
= data
;
617 if (!drm_core_check_feature(dev
, DRIVER_SYNCOBJ
))
623 if (args
->flags
!= 0 &&
624 args
->flags
!= DRM_SYNCOBJ_HANDLE_TO_FD_FLAGS_EXPORT_SYNC_FILE
)
627 if (args
->flags
& DRM_SYNCOBJ_HANDLE_TO_FD_FLAGS_EXPORT_SYNC_FILE
)
628 return drm_syncobj_export_sync_file(file_private
, args
->handle
,
631 return drm_syncobj_handle_to_fd(file_private
, args
->handle
,
636 drm_syncobj_fd_to_handle_ioctl(struct drm_device
*dev
, void *data
,
637 struct drm_file
*file_private
)
639 struct drm_syncobj_handle
*args
= data
;
641 if (!drm_core_check_feature(dev
, DRIVER_SYNCOBJ
))
647 if (args
->flags
!= 0 &&
648 args
->flags
!= DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE
)
651 if (args
->flags
& DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE
)
652 return drm_syncobj_import_sync_file_fence(file_private
,
656 return drm_syncobj_fd_to_handle(file_private
, args
->fd
,
660 struct syncobj_wait_entry
{
661 struct task_struct
*task
;
662 struct dma_fence
*fence
;
663 struct dma_fence_cb fence_cb
;
664 struct drm_syncobj_cb syncobj_cb
;
667 static void syncobj_wait_fence_func(struct dma_fence
*fence
,
668 struct dma_fence_cb
*cb
)
670 struct syncobj_wait_entry
*wait
=
671 container_of(cb
, struct syncobj_wait_entry
, fence_cb
);
673 wake_up_process(wait
->task
);
676 static void syncobj_wait_syncobj_func(struct drm_syncobj
*syncobj
,
677 struct drm_syncobj_cb
*cb
)
679 struct syncobj_wait_entry
*wait
=
680 container_of(cb
, struct syncobj_wait_entry
, syncobj_cb
);
682 /* This happens inside the syncobj lock */
683 wait
->fence
= dma_fence_get(rcu_dereference_protected(syncobj
->fence
,
684 lockdep_is_held(&syncobj
->lock
)));
685 wake_up_process(wait
->task
);
688 static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj
**syncobjs
,
694 struct syncobj_wait_entry
*entries
;
695 struct dma_fence
*fence
;
697 uint32_t signaled_count
, i
;
699 entries
= kcalloc(count
, sizeof(*entries
), GFP_KERNEL
);
703 /* Walk the list of sync objects and initialize entries. We do
704 * this up-front so that we can properly return -EINVAL if there is
705 * a syncobj with a missing fence and then never have the chance of
706 * returning -EINVAL again.
709 for (i
= 0; i
< count
; ++i
) {
710 entries
[i
].task
= current
;
711 entries
[i
].fence
= drm_syncobj_fence_get(syncobjs
[i
]);
712 if (!entries
[i
].fence
) {
713 if (flags
& DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT
) {
717 goto cleanup_entries
;
721 if (dma_fence_is_signaled(entries
[i
].fence
)) {
722 if (signaled_count
== 0 && idx
)
728 /* Initialize ret to the max of timeout and 1. That way, the
729 * default return value indicates a successful wait and not a
732 ret
= max_t(signed long, timeout
, 1);
734 if (signaled_count
== count
||
735 (signaled_count
> 0 &&
736 !(flags
& DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL
)))
737 goto cleanup_entries
;
739 /* There's a very annoying laxness in the dma_fence API here, in
740 * that backends are not required to automatically report when a
741 * fence is signaled prior to fence->ops->enable_signaling() being
742 * called. So here if we fail to match signaled_count, we need to
743 * fallthough and try a 0 timeout wait!
746 if (flags
& DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT
) {
747 for (i
= 0; i
< count
; ++i
) {
748 if (entries
[i
].fence
)
751 drm_syncobj_fence_get_or_add_callback(syncobjs
[i
],
753 &entries
[i
].syncobj_cb
,
754 syncobj_wait_syncobj_func
);
759 set_current_state(TASK_INTERRUPTIBLE
);
762 for (i
= 0; i
< count
; ++i
) {
763 fence
= entries
[i
].fence
;
767 if (dma_fence_is_signaled(fence
) ||
768 (!entries
[i
].fence_cb
.func
&&
769 dma_fence_add_callback(fence
,
770 &entries
[i
].fence_cb
,
771 syncobj_wait_fence_func
))) {
772 /* The fence has been signaled */
773 if (flags
& DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL
) {
783 if (signaled_count
== count
)
787 /* If we are doing a 0 timeout wait and we got
788 * here, then we just timed out.
794 ret
= schedule_timeout(ret
);
796 if (ret
> 0 && signal_pending(current
))
801 __set_current_state(TASK_RUNNING
);
804 for (i
= 0; i
< count
; ++i
) {
805 if (entries
[i
].syncobj_cb
.func
)
806 drm_syncobj_remove_callback(syncobjs
[i
],
807 &entries
[i
].syncobj_cb
);
808 if (entries
[i
].fence_cb
.func
)
809 dma_fence_remove_callback(entries
[i
].fence
,
810 &entries
[i
].fence_cb
);
811 dma_fence_put(entries
[i
].fence
);
819 * drm_timeout_abs_to_jiffies - calculate jiffies timeout from absolute value
821 * @timeout_nsec: timeout nsec component in ns, 0 for poll
823 * Calculate the timeout in jiffies from an absolute time in sec/nsec.
825 static signed long drm_timeout_abs_to_jiffies(int64_t timeout_nsec
)
827 ktime_t abs_timeout
, now
;
828 u64 timeout_ns
, timeout_jiffies64
;
830 /* make 0 timeout means poll - absolute 0 doesn't seem valid */
831 if (timeout_nsec
== 0)
834 abs_timeout
= ns_to_ktime(timeout_nsec
);
837 if (!ktime_after(abs_timeout
, now
))
840 timeout_ns
= ktime_to_ns(ktime_sub(abs_timeout
, now
));
842 timeout_jiffies64
= nsecs_to_jiffies64(timeout_ns
);
843 /* clamp timeout to avoid infinite timeout */
844 if (timeout_jiffies64
>= MAX_SCHEDULE_TIMEOUT
- 1)
845 return MAX_SCHEDULE_TIMEOUT
- 1;
847 return timeout_jiffies64
+ 1;
850 static int drm_syncobj_array_wait(struct drm_device
*dev
,
851 struct drm_file
*file_private
,
852 struct drm_syncobj_wait
*wait
,
853 struct drm_syncobj
**syncobjs
)
855 signed long timeout
= drm_timeout_abs_to_jiffies(wait
->timeout_nsec
);
859 ret
= drm_syncobj_array_wait_timeout(syncobjs
,
866 wait
->first_signaled
= first
;
872 static int drm_syncobj_array_find(struct drm_file
*file_private
,
873 void __user
*user_handles
,
874 uint32_t count_handles
,
875 struct drm_syncobj
***syncobjs_out
)
877 uint32_t i
, *handles
;
878 struct drm_syncobj
**syncobjs
;
881 handles
= kmalloc_array(count_handles
, sizeof(*handles
), GFP_KERNEL
);
885 if (copy_from_user(handles
, user_handles
,
886 sizeof(uint32_t) * count_handles
)) {
888 goto err_free_handles
;
891 syncobjs
= kmalloc_array(count_handles
, sizeof(*syncobjs
), GFP_KERNEL
);
892 if (syncobjs
== NULL
) {
894 goto err_free_handles
;
897 for (i
= 0; i
< count_handles
; i
++) {
898 syncobjs
[i
] = drm_syncobj_find(file_private
, handles
[i
]);
901 goto err_put_syncobjs
;
906 *syncobjs_out
= syncobjs
;
911 drm_syncobj_put(syncobjs
[i
]);
919 static void drm_syncobj_array_free(struct drm_syncobj
**syncobjs
,
923 for (i
= 0; i
< count
; i
++)
924 drm_syncobj_put(syncobjs
[i
]);
929 drm_syncobj_wait_ioctl(struct drm_device
*dev
, void *data
,
930 struct drm_file
*file_private
)
932 struct drm_syncobj_wait
*args
= data
;
933 struct drm_syncobj
**syncobjs
;
936 if (!drm_core_check_feature(dev
, DRIVER_SYNCOBJ
))
939 if (args
->flags
& ~(DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL
|
940 DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT
))
943 if (args
->count_handles
== 0)
946 ret
= drm_syncobj_array_find(file_private
,
947 u64_to_user_ptr(args
->handles
),
953 ret
= drm_syncobj_array_wait(dev
, file_private
,
956 drm_syncobj_array_free(syncobjs
, args
->count_handles
);
962 drm_syncobj_reset_ioctl(struct drm_device
*dev
, void *data
,
963 struct drm_file
*file_private
)
965 struct drm_syncobj_array
*args
= data
;
966 struct drm_syncobj
**syncobjs
;
970 if (!drm_core_check_feature(dev
, DRIVER_SYNCOBJ
))
976 if (args
->count_handles
== 0)
979 ret
= drm_syncobj_array_find(file_private
,
980 u64_to_user_ptr(args
->handles
),
986 for (i
= 0; i
< args
->count_handles
; i
++)
987 drm_syncobj_replace_fence(syncobjs
[i
], NULL
);
989 drm_syncobj_array_free(syncobjs
, args
->count_handles
);
995 drm_syncobj_signal_ioctl(struct drm_device
*dev
, void *data
,
996 struct drm_file
*file_private
)
998 struct drm_syncobj_array
*args
= data
;
999 struct drm_syncobj
**syncobjs
;
1003 if (!drm_core_check_feature(dev
, DRIVER_SYNCOBJ
))
1009 if (args
->count_handles
== 0)
1012 ret
= drm_syncobj_array_find(file_private
,
1013 u64_to_user_ptr(args
->handles
),
1014 args
->count_handles
,
1019 for (i
= 0; i
< args
->count_handles
; i
++) {
1020 ret
= drm_syncobj_assign_null_handle(syncobjs
[i
]);
1025 drm_syncobj_array_free(syncobjs
, args
->count_handles
);