xref: /linux-6.15/include/drm/drm_syncobj.h (revision 48197bc5)
1 /*
2  * Copyright © 2017 Red Hat
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  *
23  * Authors:
24  *
25  */
26 #ifndef __DRM_SYNCOBJ_H__
27 #define __DRM_SYNCOBJ_H__
28 
29 #include "linux/dma-fence.h"
30 
31 struct drm_syncobj_cb;
32 
33 enum drm_syncobj_type {
34 	DRM_SYNCOBJ_TYPE_BINARY,
35 	DRM_SYNCOBJ_TYPE_TIMELINE
36 };
37 
38 /**
39  * struct drm_syncobj - sync object.
40  *
41  * This structure defines a generic sync object which is timeline based.
42  */
43 struct drm_syncobj {
44 	/**
45 	 * @refcount: Reference count of this object.
46 	 */
47 	struct kref refcount;
48 	/**
49 	 * @type: indicate syncobj type
50 	 */
51 	enum drm_syncobj_type type;
52 	/**
53 	 * @wq: wait signal operation work queue
54 	 */
55 	wait_queue_head_t	wq;
56 	/**
57 	 * @timeline_context: fence context used by timeline
58 	 */
59 	u64 timeline_context;
60 	/**
61 	 * @timeline: syncobj timeline value, which indicates point is signaled.
62 	 */
63 	u64 timeline;
64 	/**
65 	 * @signal_point: which indicates the latest signaler point.
66 	 */
67 	u64 signal_point;
68 	/**
69 	 * @signal_pt_list: signaler point list.
70 	 */
71 	struct list_head signal_pt_list;
72 
73 	/**
74          * @cb_list: List of callbacks to call when the &fence gets replaced.
75          */
76 	struct list_head cb_list;
77 	/**
78 	 * @lock: Protects syncobj list and write-locks &fence.
79 	 */
80 	spinlock_t lock;
81 	/**
82 	 * @file: A file backing for this syncobj.
83 	 */
84 	struct file *file;
85 };
86 
87 typedef void (*drm_syncobj_func_t)(struct drm_syncobj *syncobj,
88 				   struct drm_syncobj_cb *cb);
89 
90 /**
91  * struct drm_syncobj_cb - callback for drm_syncobj_add_callback
92  * @node: used by drm_syncob_add_callback to append this struct to
93  *       &drm_syncobj.cb_list
94  * @func: drm_syncobj_func_t to call
95  *
96  * This struct will be initialized by drm_syncobj_add_callback, additional
97  * data can be passed along by embedding drm_syncobj_cb in another struct.
98  * The callback will get called the next time drm_syncobj_replace_fence is
99  * called.
100  */
101 struct drm_syncobj_cb {
102 	struct list_head node;
103 	drm_syncobj_func_t func;
104 };
105 
106 void drm_syncobj_free(struct kref *kref);
107 
108 /**
109  * drm_syncobj_get - acquire a syncobj reference
110  * @obj: sync object
111  *
112  * This acquires an additional reference to @obj. It is illegal to call this
113  * without already holding a reference. No locks required.
114  */
115 static inline void
116 drm_syncobj_get(struct drm_syncobj *obj)
117 {
118 	kref_get(&obj->refcount);
119 }
120 
121 /**
122  * drm_syncobj_put - release a reference to a sync object.
123  * @obj: sync object.
124  */
125 static inline void
126 drm_syncobj_put(struct drm_syncobj *obj)
127 {
128 	kref_put(&obj->refcount, drm_syncobj_free);
129 }
130 
131 struct drm_syncobj *drm_syncobj_find(struct drm_file *file_private,
132 				     u32 handle);
133 void drm_syncobj_replace_fence(struct drm_syncobj *syncobj, u64 point,
134 			       struct dma_fence *fence);
135 int drm_syncobj_find_fence(struct drm_file *file_private,
136 			   u32 handle, u64 point, u64 flags,
137 			   struct dma_fence **fence);
138 void drm_syncobj_free(struct kref *kref);
139 int drm_syncobj_create(struct drm_syncobj **out_syncobj, uint32_t flags,
140 		       struct dma_fence *fence);
141 int drm_syncobj_get_handle(struct drm_file *file_private,
142 			   struct drm_syncobj *syncobj, u32 *handle);
143 int drm_syncobj_get_fd(struct drm_syncobj *syncobj, int *p_fd);
144 int drm_syncobj_search_fence(struct drm_syncobj *syncobj, u64 point, u64 flags,
145 			     struct dma_fence **fence);
146 
147 #endif
148