1*41ec0267Sriastradh /* $NetBSD: drm_syncobj.h,v 1.2 2021/12/18 23:45:46 riastradh Exp $ */
24e390cabSriastradh
34e390cabSriastradh /*
44e390cabSriastradh * Copyright © 2017 Red Hat
54e390cabSriastradh *
64e390cabSriastradh * Permission is hereby granted, free of charge, to any person obtaining a
74e390cabSriastradh * copy of this software and associated documentation files (the "Software"),
84e390cabSriastradh * to deal in the Software without restriction, including without limitation
94e390cabSriastradh * the rights to use, copy, modify, merge, publish, distribute, sublicense,
104e390cabSriastradh * and/or sell copies of the Software, and to permit persons to whom the
114e390cabSriastradh * Software is furnished to do so, subject to the following conditions:
124e390cabSriastradh *
134e390cabSriastradh * The above copyright notice and this permission notice (including the next
144e390cabSriastradh * paragraph) shall be included in all copies or substantial portions of the
154e390cabSriastradh * Software.
164e390cabSriastradh *
174e390cabSriastradh * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
184e390cabSriastradh * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
194e390cabSriastradh * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
204e390cabSriastradh * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
214e390cabSriastradh * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
224e390cabSriastradh * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
234e390cabSriastradh * IN THE SOFTWARE.
244e390cabSriastradh *
254e390cabSriastradh * Authors:
264e390cabSriastradh *
274e390cabSriastradh */
284e390cabSriastradh #ifndef __DRM_SYNCOBJ_H__
294e390cabSriastradh #define __DRM_SYNCOBJ_H__
304e390cabSriastradh
314e390cabSriastradh #include <linux/dma-fence.h>
324e390cabSriastradh #include <linux/dma-fence-chain.h>
334e390cabSriastradh
344e390cabSriastradh struct drm_file;
354e390cabSriastradh
364e390cabSriastradh /**
374e390cabSriastradh * struct drm_syncobj - sync object.
384e390cabSriastradh *
394e390cabSriastradh * This structure defines a generic sync object which wraps a &dma_fence.
404e390cabSriastradh */
414e390cabSriastradh struct drm_syncobj {
424e390cabSriastradh /**
434e390cabSriastradh * @refcount: Reference count of this object.
444e390cabSriastradh */
454e390cabSriastradh struct kref refcount;
464e390cabSriastradh /**
474e390cabSriastradh * @fence:
484e390cabSriastradh * NULL or a pointer to the fence bound to this object.
494e390cabSriastradh *
504e390cabSriastradh * This field should not be used directly. Use drm_syncobj_fence_get()
514e390cabSriastradh * and drm_syncobj_replace_fence() instead.
524e390cabSriastradh */
534e390cabSriastradh struct dma_fence __rcu *fence;
544e390cabSriastradh /**
554e390cabSriastradh * @cb_list: List of callbacks to call when the &fence gets replaced.
564e390cabSriastradh */
574e390cabSriastradh struct list_head cb_list;
584e390cabSriastradh /**
594e390cabSriastradh * @lock: Protects &cb_list and write-locks &fence.
604e390cabSriastradh */
614e390cabSriastradh spinlock_t lock;
624e390cabSriastradh /**
634e390cabSriastradh * @file: A file backing for this syncobj.
644e390cabSriastradh */
654e390cabSriastradh struct file *file;
664e390cabSriastradh };
674e390cabSriastradh
684e390cabSriastradh void drm_syncobj_free(struct kref *kref);
694e390cabSriastradh
704e390cabSriastradh /**
714e390cabSriastradh * drm_syncobj_get - acquire a syncobj reference
724e390cabSriastradh * @obj: sync object
734e390cabSriastradh *
744e390cabSriastradh * This acquires an additional reference to @obj. It is illegal to call this
754e390cabSriastradh * without already holding a reference. No locks required.
764e390cabSriastradh */
774e390cabSriastradh static inline void
drm_syncobj_get(struct drm_syncobj * obj)784e390cabSriastradh drm_syncobj_get(struct drm_syncobj *obj)
794e390cabSriastradh {
804e390cabSriastradh kref_get(&obj->refcount);
814e390cabSriastradh }
824e390cabSriastradh
834e390cabSriastradh /**
844e390cabSriastradh * drm_syncobj_put - release a reference to a sync object.
854e390cabSriastradh * @obj: sync object.
864e390cabSriastradh */
874e390cabSriastradh static inline void
drm_syncobj_put(struct drm_syncobj * obj)884e390cabSriastradh drm_syncobj_put(struct drm_syncobj *obj)
894e390cabSriastradh {
904e390cabSriastradh kref_put(&obj->refcount, drm_syncobj_free);
914e390cabSriastradh }
924e390cabSriastradh
934e390cabSriastradh /**
944e390cabSriastradh * drm_syncobj_fence_get - get a reference to a fence in a sync object
954e390cabSriastradh * @syncobj: sync object.
964e390cabSriastradh *
974e390cabSriastradh * This acquires additional reference to &drm_syncobj.fence contained in @obj,
984e390cabSriastradh * if not NULL. It is illegal to call this without already holding a reference.
994e390cabSriastradh * No locks required.
1004e390cabSriastradh *
1014e390cabSriastradh * Returns:
1024e390cabSriastradh * Either the fence of @obj or NULL if there's none.
1034e390cabSriastradh */
1044e390cabSriastradh static inline struct dma_fence *
drm_syncobj_fence_get(struct drm_syncobj * syncobj)1054e390cabSriastradh drm_syncobj_fence_get(struct drm_syncobj *syncobj)
1064e390cabSriastradh {
1074e390cabSriastradh struct dma_fence *fence;
1084e390cabSriastradh
1094e390cabSriastradh rcu_read_lock();
1104e390cabSriastradh fence = dma_fence_get_rcu_safe(&syncobj->fence);
1114e390cabSriastradh rcu_read_unlock();
1124e390cabSriastradh
1134e390cabSriastradh return fence;
1144e390cabSriastradh }
1154e390cabSriastradh
1164e390cabSriastradh struct drm_syncobj *drm_syncobj_find(struct drm_file *file_private,
1174e390cabSriastradh u32 handle);
1184e390cabSriastradh void drm_syncobj_add_point(struct drm_syncobj *syncobj,
1194e390cabSriastradh struct dma_fence_chain *chain,
1204e390cabSriastradh struct dma_fence *fence,
1214e390cabSriastradh uint64_t point);
1224e390cabSriastradh void drm_syncobj_replace_fence(struct drm_syncobj *syncobj,
1234e390cabSriastradh struct dma_fence *fence);
1244e390cabSriastradh int drm_syncobj_find_fence(struct drm_file *file_private,
1254e390cabSriastradh u32 handle, u64 point, u64 flags,
1264e390cabSriastradh struct dma_fence **fence);
1274e390cabSriastradh void drm_syncobj_free(struct kref *kref);
1284e390cabSriastradh int drm_syncobj_create(struct drm_syncobj **out_syncobj, uint32_t flags,
1294e390cabSriastradh struct dma_fence *fence);
1304e390cabSriastradh int drm_syncobj_get_handle(struct drm_file *file_private,
1314e390cabSriastradh struct drm_syncobj *syncobj, u32 *handle);
1324e390cabSriastradh int drm_syncobj_get_fd(struct drm_syncobj *syncobj, int *p_fd);
1334e390cabSriastradh
1344e390cabSriastradh #endif
135