1
2
3
4
5
6
7#ifndef _I915_ACTIVE_H_
8#define _I915_ACTIVE_H_
9
10#include <linux/lockdep.h>
11
12#include "i915_active_types.h"
13#include "i915_request.h"
14
15struct i915_request;
16struct intel_engine_cs;
17struct intel_timeline;
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48void i915_active_noop(struct dma_fence *fence, struct dma_fence_cb *cb);
49
50
51
52
53
54
55
56
57
58
59
60
61
62static inline void
63__i915_active_fence_init(struct i915_active_fence *active,
64 void *fence,
65 dma_fence_func_t fn)
66{
67 RCU_INIT_POINTER(active->fence, fence);
68 active->cb.func = fn ?: i915_active_noop;
69}
70
71#define INIT_ACTIVE_FENCE(A) \
72 __i915_active_fence_init((A), NULL, NULL)
73
74struct dma_fence *
75__i915_active_fence_set(struct i915_active_fence *active,
76 struct dma_fence *fence);
77
78
79
80
81
82
83
84
85
86
87int __must_check
88i915_active_fence_set(struct i915_active_fence *active,
89 struct i915_request *rq);
90
91
92
93
94
95
96
97
98
99
100static inline struct dma_fence *
101i915_active_fence_get(struct i915_active_fence *active)
102{
103 struct dma_fence *fence;
104
105 rcu_read_lock();
106 fence = dma_fence_get_rcu_safe(&active->fence);
107 rcu_read_unlock();
108
109 return fence;
110}
111
112
113
114
115
116
117
118
119
120static inline bool
121i915_active_fence_isset(const struct i915_active_fence *active)
122{
123 return rcu_access_pointer(active->fence);
124}
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152void __i915_active_init(struct i915_active *ref,
153 int (*active)(struct i915_active *ref),
154 void (*retire)(struct i915_active *ref),
155 unsigned long flags,
156 struct lock_class_key *mkey,
157 struct lock_class_key *wkey);
158
159
160#define i915_active_init(ref, active, retire, flags) do { \
161 static struct lock_class_key __mkey; \
162 static struct lock_class_key __wkey; \
163 \
164 __i915_active_init(ref, active, retire, flags, &__mkey, &__wkey); \
165} while (0)
166
167struct dma_fence *
168__i915_active_ref(struct i915_active *ref, u64 idx, struct dma_fence *fence);
169int i915_active_ref(struct i915_active *ref, u64 idx, struct dma_fence *fence);
170
171static inline int
172i915_active_add_request(struct i915_active *ref, struct i915_request *rq)
173{
174 return i915_active_ref(ref,
175 i915_request_timeline(rq)->fence_context,
176 &rq->fence);
177}
178
179struct dma_fence *
180i915_active_set_exclusive(struct i915_active *ref, struct dma_fence *f);
181
182static inline bool i915_active_has_exclusive(struct i915_active *ref)
183{
184 return rcu_access_pointer(ref->excl.fence);
185}
186
187int __i915_active_wait(struct i915_active *ref, int state);
188static inline int i915_active_wait(struct i915_active *ref)
189{
190 return __i915_active_wait(ref, TASK_INTERRUPTIBLE);
191}
192
193int i915_sw_fence_await_active(struct i915_sw_fence *fence,
194 struct i915_active *ref,
195 unsigned int flags);
196int i915_request_await_active(struct i915_request *rq,
197 struct i915_active *ref,
198 unsigned int flags);
199#define I915_ACTIVE_AWAIT_EXCL BIT(0)
200#define I915_ACTIVE_AWAIT_ACTIVE BIT(1)
201#define I915_ACTIVE_AWAIT_BARRIER BIT(2)
202
203int i915_active_acquire(struct i915_active *ref);
204int i915_active_acquire_for_context(struct i915_active *ref, u64 idx);
205bool i915_active_acquire_if_busy(struct i915_active *ref);
206
207void i915_active_release(struct i915_active *ref);
208
209static inline void __i915_active_acquire(struct i915_active *ref)
210{
211 GEM_BUG_ON(!atomic_read(&ref->count));
212 atomic_inc(&ref->count);
213}
214
215static inline bool
216i915_active_is_idle(const struct i915_active *ref)
217{
218 return !atomic_read(&ref->count);
219}
220
221void i915_active_fini(struct i915_active *ref);
222
223int i915_active_acquire_preallocate_barrier(struct i915_active *ref,
224 struct intel_engine_cs *engine);
225void i915_active_acquire_barrier(struct i915_active *ref);
226void i915_request_add_active_barriers(struct i915_request *rq);
227
228void i915_active_print(struct i915_active *ref, struct drm_printer *m);
229void i915_active_unlock_wait(struct i915_active *ref);
230
231struct i915_active *i915_active_create(void);
232struct i915_active *i915_active_get(struct i915_active *ref);
233void i915_active_put(struct i915_active *ref);
234
235static inline int __i915_request_await_exclusive(struct i915_request *rq,
236 struct i915_active *active)
237{
238 struct dma_fence *fence;
239 int err = 0;
240
241 fence = i915_active_fence_get(&active->excl);
242 if (fence) {
243 err = i915_request_await_dma_fence(rq, fence);
244 dma_fence_put(fence);
245 }
246
247 return err;
248}
249
250#endif
251