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
)
100 *fence
= drm_syncobj_fence_get(syncobj
);
104 spin_lock(&syncobj
->lock
);
105 /* We've already tried once to get a fence and failed. Now that we
106 * have the lock, try one more time just to be sure we don't add a
107 * callback when a fence has already been set.
109 if (syncobj
->fence
) {
110 *fence
= dma_fence_get(rcu_dereference_protected(syncobj
->fence
,
111 lockdep_is_held(&syncobj
->lock
)));
115 drm_syncobj_add_callback_locked(syncobj
, cb
, func
);
118 spin_unlock(&syncobj
->lock
);
124 * drm_syncobj_add_callback - adds a callback to syncobj::cb_list
125 * @syncobj: Sync object to which to add the callback
126 * @cb: Callback to add
127 * @func: Func to use when initializing the drm_syncobj_cb struct
129 * This adds a callback to be called next time the fence is replaced
131 void drm_syncobj_add_callback(struct drm_syncobj
*syncobj
,
132 struct drm_syncobj_cb
*cb
,
133 drm_syncobj_func_t func
)
135 spin_lock(&syncobj
->lock
);
136 drm_syncobj_add_callback_locked(syncobj
, cb
, func
);
137 spin_unlock(&syncobj
->lock
);
139 EXPORT_SYMBOL(drm_syncobj_add_callback
);
142 * drm_syncobj_add_callback - removes a callback to syncobj::cb_list
143 * @syncobj: Sync object from which to remove the callback
144 * @cb: Callback to remove
146 void drm_syncobj_remove_callback(struct drm_syncobj
*syncobj
,
147 struct drm_syncobj_cb
*cb
)
149 spin_lock(&syncobj
->lock
);
150 list_del_init(&cb
->node
);
151 spin_unlock(&syncobj
->lock
);
153 EXPORT_SYMBOL(drm_syncobj_remove_callback
);
156 * drm_syncobj_replace_fence - replace fence in a sync object.
157 * @syncobj: Sync object to replace fence in
158 * @fence: fence to install in sync file.
160 * This replaces the fence on a sync object.
162 void drm_syncobj_replace_fence(struct drm_syncobj
*syncobj
,
163 struct dma_fence
*fence
)
165 struct dma_fence
*old_fence
;
166 struct drm_syncobj_cb
*cur
, *tmp
;
169 dma_fence_get(fence
);
171 spin_lock(&syncobj
->lock
);
173 old_fence
= rcu_dereference_protected(syncobj
->fence
,
174 lockdep_is_held(&syncobj
->lock
));
175 rcu_assign_pointer(syncobj
->fence
, fence
);
177 if (fence
!= old_fence
) {
178 list_for_each_entry_safe(cur
, tmp
, &syncobj
->cb_list
, node
) {
179 list_del_init(&cur
->node
);
180 cur
->func(syncobj
, cur
);
184 spin_unlock(&syncobj
->lock
);
186 dma_fence_put(old_fence
);
188 EXPORT_SYMBOL(drm_syncobj_replace_fence
);
190 struct drm_syncobj_null_fence
{
191 struct dma_fence base
;
195 static const char *drm_syncobj_null_fence_get_name(struct dma_fence
*fence
)
197 return "syncobjnull";
200 static bool drm_syncobj_null_fence_enable_signaling(struct dma_fence
*fence
)
202 dma_fence_enable_sw_signaling(fence
);
203 return !dma_fence_is_signaled(fence
);
206 static const struct dma_fence_ops drm_syncobj_null_fence_ops
= {
207 .get_driver_name
= drm_syncobj_null_fence_get_name
,
208 .get_timeline_name
= drm_syncobj_null_fence_get_name
,
209 .enable_signaling
= drm_syncobj_null_fence_enable_signaling
,
210 .wait
= dma_fence_default_wait
,
214 static int drm_syncobj_assign_null_handle(struct drm_syncobj
*syncobj
)
216 struct drm_syncobj_null_fence
*fence
;
217 fence
= kzalloc(sizeof(*fence
), GFP_KERNEL
);
221 spin_lock_init(&fence
->lock
);
222 dma_fence_init(&fence
->base
, &drm_syncobj_null_fence_ops
,
224 dma_fence_signal(&fence
->base
);
226 drm_syncobj_replace_fence(syncobj
, &fence
->base
);
228 dma_fence_put(&fence
->base
);
234 * drm_syncobj_find_fence - lookup and reference the fence in a sync object
235 * @file_private: drm file private pointer
236 * @handle: sync object handle to lookup.
237 * @fence: out parameter for the fence
239 * This is just a convenience function that combines drm_syncobj_find() and
240 * drm_syncobj_fence_get().
242 * Returns 0 on success or a negative error value on failure. On success @fence
243 * contains a reference to the fence, which must be released by calling
246 int drm_syncobj_find_fence(struct drm_file
*file_private
,
248 struct dma_fence
**fence
)
250 struct drm_syncobj
*syncobj
= drm_syncobj_find(file_private
, handle
);
256 *fence
= drm_syncobj_fence_get(syncobj
);
260 drm_syncobj_put(syncobj
);
263 EXPORT_SYMBOL(drm_syncobj_find_fence
);
266 * drm_syncobj_free - free a sync object.
267 * @kref: kref to free.
269 * Only to be called from kref_put in drm_syncobj_put.
271 void drm_syncobj_free(struct kref
*kref
)
273 struct drm_syncobj
*syncobj
= container_of(kref
,
276 drm_syncobj_replace_fence(syncobj
, NULL
);
279 EXPORT_SYMBOL(drm_syncobj_free
);
282 * drm_syncobj_create - create a new syncobj
283 * @out_syncobj: returned syncobj
284 * @flags: DRM_SYNCOBJ_* flags
285 * @fence: if non-NULL, the syncobj will represent this fence
287 * This is the first function to create a sync object. After creating, drivers
288 * probably want to make it available to userspace, either through
289 * drm_syncobj_get_handle() or drm_syncobj_get_fd().
291 * Returns 0 on success or a negative error value on failure.
293 int drm_syncobj_create(struct drm_syncobj
**out_syncobj
, uint32_t flags
,
294 struct dma_fence
*fence
)
297 struct drm_syncobj
*syncobj
;
299 syncobj
= kzalloc(sizeof(struct drm_syncobj
), GFP_KERNEL
);
303 kref_init(&syncobj
->refcount
);
304 INIT_LIST_HEAD(&syncobj
->cb_list
);
305 spin_lock_init(&syncobj
->lock
);
307 if (flags
& DRM_SYNCOBJ_CREATE_SIGNALED
) {
308 ret
= drm_syncobj_assign_null_handle(syncobj
);
310 drm_syncobj_put(syncobj
);
316 drm_syncobj_replace_fence(syncobj
, fence
);
318 *out_syncobj
= syncobj
;
321 EXPORT_SYMBOL(drm_syncobj_create
);
324 * drm_syncobj_get_handle - get a handle from a syncobj
325 * @file_private: drm file private pointer
326 * @syncobj: Sync object to export
327 * @handle: out parameter with the new handle
329 * Exports a sync object created with drm_syncobj_create() as a handle on
330 * @file_private to userspace.
332 * Returns 0 on success or a negative error value on failure.
334 int drm_syncobj_get_handle(struct drm_file
*file_private
,
335 struct drm_syncobj
*syncobj
, u32
*handle
)
339 /* take a reference to put in the idr */
340 drm_syncobj_get(syncobj
);
342 idr_preload(GFP_KERNEL
);
343 spin_lock(&file_private
->syncobj_table_lock
);
344 ret
= idr_alloc(&file_private
->syncobj_idr
, syncobj
, 1, 0, GFP_NOWAIT
);
345 spin_unlock(&file_private
->syncobj_table_lock
);
350 drm_syncobj_put(syncobj
);
357 EXPORT_SYMBOL(drm_syncobj_get_handle
);
359 static int drm_syncobj_create_as_handle(struct drm_file
*file_private
,
360 u32
*handle
, uint32_t flags
)
363 struct drm_syncobj
*syncobj
;
365 ret
= drm_syncobj_create(&syncobj
, flags
, NULL
);
369 ret
= drm_syncobj_get_handle(file_private
, syncobj
, handle
);
370 drm_syncobj_put(syncobj
);
374 static int drm_syncobj_destroy(struct drm_file
*file_private
,
377 struct drm_syncobj
*syncobj
;
379 spin_lock(&file_private
->syncobj_table_lock
);
380 syncobj
= idr_remove(&file_private
->syncobj_idr
, handle
);
381 spin_unlock(&file_private
->syncobj_table_lock
);
386 drm_syncobj_put(syncobj
);
390 static int drm_syncobj_file_release(struct inode
*inode
, struct file
*file
)
392 struct drm_syncobj
*syncobj
= file
->private_data
;
394 drm_syncobj_put(syncobj
);
398 static const struct file_operations drm_syncobj_file_fops
= {
399 .release
= drm_syncobj_file_release
,
403 * drm_syncobj_get_fd - get a file descriptor from a syncobj
404 * @syncobj: Sync object to export
405 * @p_fd: out parameter with the new file descriptor
407 * Exports a sync object created with drm_syncobj_create() as a file descriptor.
409 * Returns 0 on success or a negative error value on failure.
411 int drm_syncobj_get_fd(struct drm_syncobj
*syncobj
, int *p_fd
)
416 fd
= get_unused_fd_flags(O_CLOEXEC
);
420 file
= anon_inode_getfile("syncobj_file",
421 &drm_syncobj_file_fops
,
425 return PTR_ERR(file
);
428 drm_syncobj_get(syncobj
);
429 fd_install(fd
, file
);
434 EXPORT_SYMBOL(drm_syncobj_get_fd
);
436 static int drm_syncobj_handle_to_fd(struct drm_file
*file_private
,
437 u32 handle
, int *p_fd
)
439 struct drm_syncobj
*syncobj
= drm_syncobj_find(file_private
, handle
);
445 ret
= drm_syncobj_get_fd(syncobj
, p_fd
);
446 drm_syncobj_put(syncobj
);
450 static int drm_syncobj_fd_to_handle(struct drm_file
*file_private
,
453 struct drm_syncobj
*syncobj
;
461 if (file
->f_op
!= &drm_syncobj_file_fops
) {
466 /* take a reference to put in the idr */
467 syncobj
= file
->private_data
;
468 drm_syncobj_get(syncobj
);
470 idr_preload(GFP_KERNEL
);
471 spin_lock(&file_private
->syncobj_table_lock
);
472 ret
= idr_alloc(&file_private
->syncobj_idr
, syncobj
, 1, 0, GFP_NOWAIT
);
473 spin_unlock(&file_private
->syncobj_table_lock
);
480 drm_syncobj_put(syncobj
);
486 static int drm_syncobj_import_sync_file_fence(struct drm_file
*file_private
,
489 struct dma_fence
*fence
= sync_file_get_fence(fd
);
490 struct drm_syncobj
*syncobj
;
495 syncobj
= drm_syncobj_find(file_private
, handle
);
497 dma_fence_put(fence
);
501 drm_syncobj_replace_fence(syncobj
, fence
);
502 dma_fence_put(fence
);
503 drm_syncobj_put(syncobj
);
507 static int drm_syncobj_export_sync_file(struct drm_file
*file_private
,
508 int handle
, int *p_fd
)
511 struct dma_fence
*fence
;
512 struct sync_file
*sync_file
;
513 int fd
= get_unused_fd_flags(O_CLOEXEC
);
518 ret
= drm_syncobj_find_fence(file_private
, handle
, &fence
);
522 sync_file
= sync_file_create(fence
);
524 dma_fence_put(fence
);
531 fd_install(fd
, sync_file
->file
);
540 * drm_syncobj_open - initalizes syncobj file-private structures at devnode open time
541 * @file_private: drm file-private structure to set up
543 * Called at device open time, sets up the structure for handling refcounting
547 drm_syncobj_open(struct drm_file
*file_private
)
549 idr_init(&file_private
->syncobj_idr
);
550 spin_lock_init(&file_private
->syncobj_table_lock
);
554 drm_syncobj_release_handle(int id
, void *ptr
, void *data
)
556 struct drm_syncobj
*syncobj
= ptr
;
558 drm_syncobj_put(syncobj
);
563 * drm_syncobj_release - release file-private sync object resources
564 * @file_private: drm file-private structure to clean up
566 * Called at close time when the filp is going away.
568 * Releases any remaining references on objects by this filp.
571 drm_syncobj_release(struct drm_file
*file_private
)
573 idr_for_each(&file_private
->syncobj_idr
,
574 &drm_syncobj_release_handle
, file_private
);
575 idr_destroy(&file_private
->syncobj_idr
);
579 drm_syncobj_create_ioctl(struct drm_device
*dev
, void *data
,
580 struct drm_file
*file_private
)
582 struct drm_syncobj_create
*args
= data
;
584 if (!drm_core_check_feature(dev
, DRIVER_SYNCOBJ
))
587 /* no valid flags yet */
588 if (args
->flags
& ~DRM_SYNCOBJ_CREATE_SIGNALED
)
591 return drm_syncobj_create_as_handle(file_private
,
592 &args
->handle
, args
->flags
);
596 drm_syncobj_destroy_ioctl(struct drm_device
*dev
, void *data
,
597 struct drm_file
*file_private
)
599 struct drm_syncobj_destroy
*args
= data
;
601 if (!drm_core_check_feature(dev
, DRIVER_SYNCOBJ
))
604 /* make sure padding is empty */
607 return drm_syncobj_destroy(file_private
, args
->handle
);
611 drm_syncobj_handle_to_fd_ioctl(struct drm_device
*dev
, void *data
,
612 struct drm_file
*file_private
)
614 struct drm_syncobj_handle
*args
= data
;
616 if (!drm_core_check_feature(dev
, DRIVER_SYNCOBJ
))
622 if (args
->flags
!= 0 &&
623 args
->flags
!= DRM_SYNCOBJ_HANDLE_TO_FD_FLAGS_EXPORT_SYNC_FILE
)
626 if (args
->flags
& DRM_SYNCOBJ_HANDLE_TO_FD_FLAGS_EXPORT_SYNC_FILE
)
627 return drm_syncobj_export_sync_file(file_private
, args
->handle
,
630 return drm_syncobj_handle_to_fd(file_private
, args
->handle
,
635 drm_syncobj_fd_to_handle_ioctl(struct drm_device
*dev
, void *data
,
636 struct drm_file
*file_private
)
638 struct drm_syncobj_handle
*args
= data
;
640 if (!drm_core_check_feature(dev
, DRIVER_SYNCOBJ
))
646 if (args
->flags
!= 0 &&
647 args
->flags
!= DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE
)
650 if (args
->flags
& DRM_SYNCOBJ_FD_TO_HANDLE_FLAGS_IMPORT_SYNC_FILE
)
651 return drm_syncobj_import_sync_file_fence(file_private
,
655 return drm_syncobj_fd_to_handle(file_private
, args
->fd
,
659 struct syncobj_wait_entry
{
660 struct task_struct
*task
;
661 struct dma_fence
*fence
;
662 struct dma_fence_cb fence_cb
;
663 struct drm_syncobj_cb syncobj_cb
;
666 static void syncobj_wait_fence_func(struct dma_fence
*fence
,
667 struct dma_fence_cb
*cb
)
669 struct syncobj_wait_entry
*wait
=
670 container_of(cb
, struct syncobj_wait_entry
, fence_cb
);
672 wake_up_process(wait
->task
);
675 static void syncobj_wait_syncobj_func(struct drm_syncobj
*syncobj
,
676 struct drm_syncobj_cb
*cb
)
678 struct syncobj_wait_entry
*wait
=
679 container_of(cb
, struct syncobj_wait_entry
, syncobj_cb
);
681 /* This happens inside the syncobj lock */
682 wait
->fence
= dma_fence_get(rcu_dereference_protected(syncobj
->fence
,
683 lockdep_is_held(&syncobj
->lock
)));
684 wake_up_process(wait
->task
);
687 static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj
**syncobjs
,
693 struct syncobj_wait_entry
*entries
;
694 struct dma_fence
*fence
;
696 uint32_t signaled_count
, i
;
698 entries
= kcalloc(count
, sizeof(*entries
), GFP_KERNEL
);
702 /* Walk the list of sync objects and initialize entries. We do
703 * this up-front so that we can properly return -EINVAL if there is
704 * a syncobj with a missing fence and then never have the chance of
705 * returning -EINVAL again.
708 for (i
= 0; i
< count
; ++i
) {
709 entries
[i
].task
= current
;
710 entries
[i
].fence
= drm_syncobj_fence_get(syncobjs
[i
]);
711 if (!entries
[i
].fence
) {
712 if (flags
& DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT
) {
716 goto cleanup_entries
;
720 if (dma_fence_is_signaled(entries
[i
].fence
)) {
721 if (signaled_count
== 0 && idx
)
727 /* Initialize ret to the max of timeout and 1. That way, the
728 * default return value indicates a successful wait and not a
731 ret
= max_t(signed long, timeout
, 1);
733 if (signaled_count
== count
||
734 (signaled_count
> 0 &&
735 !(flags
& DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL
)))
736 goto cleanup_entries
;
738 /* There's a very annoying laxness in the dma_fence API here, in
739 * that backends are not required to automatically report when a
740 * fence is signaled prior to fence->ops->enable_signaling() being
741 * called. So here if we fail to match signaled_count, we need to
742 * fallthough and try a 0 timeout wait!
745 if (flags
& DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT
) {
746 for (i
= 0; i
< count
; ++i
) {
747 drm_syncobj_fence_get_or_add_callback(syncobjs
[i
],
749 &entries
[i
].syncobj_cb
,
750 syncobj_wait_syncobj_func
);
755 set_current_state(TASK_INTERRUPTIBLE
);
758 for (i
= 0; i
< count
; ++i
) {
759 fence
= entries
[i
].fence
;
763 if (dma_fence_is_signaled(fence
) ||
764 (!entries
[i
].fence_cb
.func
&&
765 dma_fence_add_callback(fence
,
766 &entries
[i
].fence_cb
,
767 syncobj_wait_fence_func
))) {
768 /* The fence has been signaled */
769 if (flags
& DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL
) {
779 if (signaled_count
== count
)
783 /* If we are doing a 0 timeout wait and we got
784 * here, then we just timed out.
790 ret
= schedule_timeout(ret
);
792 if (ret
> 0 && signal_pending(current
))
797 __set_current_state(TASK_RUNNING
);
800 for (i
= 0; i
< count
; ++i
) {
801 if (entries
[i
].syncobj_cb
.func
)
802 drm_syncobj_remove_callback(syncobjs
[i
],
803 &entries
[i
].syncobj_cb
);
804 if (entries
[i
].fence_cb
.func
)
805 dma_fence_remove_callback(entries
[i
].fence
,
806 &entries
[i
].fence_cb
);
807 dma_fence_put(entries
[i
].fence
);
815 * drm_timeout_abs_to_jiffies - calculate jiffies timeout from absolute value
817 * @timeout_nsec: timeout nsec component in ns, 0 for poll
819 * Calculate the timeout in jiffies from an absolute time in sec/nsec.
821 static signed long drm_timeout_abs_to_jiffies(int64_t timeout_nsec
)
823 ktime_t abs_timeout
, now
;
824 u64 timeout_ns
, timeout_jiffies64
;
826 /* make 0 timeout means poll - absolute 0 doesn't seem valid */
827 if (timeout_nsec
== 0)
830 abs_timeout
= ns_to_ktime(timeout_nsec
);
833 if (!ktime_after(abs_timeout
, now
))
836 timeout_ns
= ktime_to_ns(ktime_sub(abs_timeout
, now
));
838 timeout_jiffies64
= nsecs_to_jiffies64(timeout_ns
);
839 /* clamp timeout to avoid infinite timeout */
840 if (timeout_jiffies64
>= MAX_SCHEDULE_TIMEOUT
- 1)
841 return MAX_SCHEDULE_TIMEOUT
- 1;
843 return timeout_jiffies64
+ 1;
846 static int drm_syncobj_array_wait(struct drm_device
*dev
,
847 struct drm_file
*file_private
,
848 struct drm_syncobj_wait
*wait
,
849 struct drm_syncobj
**syncobjs
)
851 signed long timeout
= drm_timeout_abs_to_jiffies(wait
->timeout_nsec
);
855 ret
= drm_syncobj_array_wait_timeout(syncobjs
,
862 wait
->first_signaled
= first
;
868 static int drm_syncobj_array_find(struct drm_file
*file_private
,
869 void __user
*user_handles
,
870 uint32_t count_handles
,
871 struct drm_syncobj
***syncobjs_out
)
873 uint32_t i
, *handles
;
874 struct drm_syncobj
**syncobjs
;
877 handles
= kmalloc_array(count_handles
, sizeof(*handles
), GFP_KERNEL
);
881 if (copy_from_user(handles
, user_handles
,
882 sizeof(uint32_t) * count_handles
)) {
884 goto err_free_handles
;
887 syncobjs
= kmalloc_array(count_handles
, sizeof(*syncobjs
), GFP_KERNEL
);
888 if (syncobjs
== NULL
) {
890 goto err_free_handles
;
893 for (i
= 0; i
< count_handles
; i
++) {
894 syncobjs
[i
] = drm_syncobj_find(file_private
, handles
[i
]);
897 goto err_put_syncobjs
;
902 *syncobjs_out
= syncobjs
;
907 drm_syncobj_put(syncobjs
[i
]);
915 static void drm_syncobj_array_free(struct drm_syncobj
**syncobjs
,
919 for (i
= 0; i
< count
; i
++)
920 drm_syncobj_put(syncobjs
[i
]);
925 drm_syncobj_wait_ioctl(struct drm_device
*dev
, void *data
,
926 struct drm_file
*file_private
)
928 struct drm_syncobj_wait
*args
= data
;
929 struct drm_syncobj
**syncobjs
;
932 if (!drm_core_check_feature(dev
, DRIVER_SYNCOBJ
))
935 if (args
->flags
& ~(DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL
|
936 DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT
))
939 if (args
->count_handles
== 0)
942 ret
= drm_syncobj_array_find(file_private
,
943 u64_to_user_ptr(args
->handles
),
949 ret
= drm_syncobj_array_wait(dev
, file_private
,
952 drm_syncobj_array_free(syncobjs
, args
->count_handles
);
958 drm_syncobj_reset_ioctl(struct drm_device
*dev
, void *data
,
959 struct drm_file
*file_private
)
961 struct drm_syncobj_array
*args
= data
;
962 struct drm_syncobj
**syncobjs
;
966 if (!drm_core_check_feature(dev
, DRIVER_SYNCOBJ
))
972 if (args
->count_handles
== 0)
975 ret
= drm_syncobj_array_find(file_private
,
976 u64_to_user_ptr(args
->handles
),
982 for (i
= 0; i
< args
->count_handles
; i
++)
983 drm_syncobj_replace_fence(syncobjs
[i
], NULL
);
985 drm_syncobj_array_free(syncobjs
, args
->count_handles
);
991 drm_syncobj_signal_ioctl(struct drm_device
*dev
, void *data
,
992 struct drm_file
*file_private
)
994 struct drm_syncobj_array
*args
= data
;
995 struct drm_syncobj
**syncobjs
;
999 if (!drm_core_check_feature(dev
, DRIVER_SYNCOBJ
))
1005 if (args
->count_handles
== 0)
1008 ret
= drm_syncobj_array_find(file_private
,
1009 u64_to_user_ptr(args
->handles
),
1010 args
->count_handles
,
1015 for (i
= 0; i
< args
->count_handles
; i
++) {
1016 ret
= drm_syncobj_assign_null_handle(syncobjs
[i
]);
1021 drm_syncobj_array_free(syncobjs
, args
->count_handles
);