blob: ac236b88c99ca0fb07c49ec5d9487b1e0b38adfe [file] [log] [blame]
Chris Wilsone68a1392016-09-09 14:11:41 +01001/*
2 * (C) Copyright 2016 Intel Corporation
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; version 2
7 * of the License.
8 */
9
10#include <linux/slab.h>
Chris Wilsonf54d1862016-10-25 13:00:45 +010011#include <linux/dma-fence.h>
Chris Wilson81c0ed22017-09-11 09:41:26 +010012#include <linux/irq_work.h>
Chris Wilsone68a1392016-09-09 14:11:41 +010013#include <linux/reservation.h>
14
15#include "i915_sw_fence.h"
Chris Wilson47624cc2017-05-17 13:09:57 +010016#include "i915_selftest.h"
Chris Wilsone68a1392016-09-09 14:11:41 +010017
Chris Wilson7e941862016-10-28 13:58:25 +010018#define I915_SW_FENCE_FLAG_ALLOC BIT(3) /* after WQ_FLAG_* for safety */
19
Chris Wilsone68a1392016-09-09 14:11:41 +010020static DEFINE_SPINLOCK(i915_sw_fence_lock);
21
Chris Wilsonfc158402016-11-25 13:17:18 +000022enum {
23 DEBUG_FENCE_IDLE = 0,
24 DEBUG_FENCE_NOTIFY,
25};
26
27#ifdef CONFIG_DRM_I915_SW_FENCE_DEBUG_OBJECTS
28
29static void *i915_sw_fence_debug_hint(void *addr)
30{
31 return (void *)(((struct i915_sw_fence *)addr)->flags & I915_SW_FENCE_MASK);
32}
33
34static struct debug_obj_descr i915_sw_fence_debug_descr = {
35 .name = "i915_sw_fence",
36 .debug_hint = i915_sw_fence_debug_hint,
37};
38
39static inline void debug_fence_init(struct i915_sw_fence *fence)
40{
41 debug_object_init(fence, &i915_sw_fence_debug_descr);
42}
43
Chris Wilson214707f2017-10-12 13:57:25 +010044static inline void debug_fence_init_onstack(struct i915_sw_fence *fence)
45{
46 debug_object_init_on_stack(fence, &i915_sw_fence_debug_descr);
47}
48
Chris Wilsonfc158402016-11-25 13:17:18 +000049static inline void debug_fence_activate(struct i915_sw_fence *fence)
50{
51 debug_object_activate(fence, &i915_sw_fence_debug_descr);
52}
53
54static inline void debug_fence_set_state(struct i915_sw_fence *fence,
55 int old, int new)
56{
57 debug_object_active_state(fence, &i915_sw_fence_debug_descr, old, new);
58}
59
60static inline void debug_fence_deactivate(struct i915_sw_fence *fence)
61{
62 debug_object_deactivate(fence, &i915_sw_fence_debug_descr);
63}
64
65static inline void debug_fence_destroy(struct i915_sw_fence *fence)
66{
67 debug_object_destroy(fence, &i915_sw_fence_debug_descr);
68}
69
70static inline void debug_fence_free(struct i915_sw_fence *fence)
71{
72 debug_object_free(fence, &i915_sw_fence_debug_descr);
Chris Wilson6f13f292017-01-13 21:43:35 +000073 smp_wmb(); /* flush the change in state before reallocation */
Chris Wilsonfc158402016-11-25 13:17:18 +000074}
75
76static inline void debug_fence_assert(struct i915_sw_fence *fence)
77{
78 debug_object_assert_init(fence, &i915_sw_fence_debug_descr);
79}
80
81#else
82
83static inline void debug_fence_init(struct i915_sw_fence *fence)
84{
85}
86
Chris Wilson214707f2017-10-12 13:57:25 +010087static inline void debug_fence_init_onstack(struct i915_sw_fence *fence)
88{
89}
90
Chris Wilsonfc158402016-11-25 13:17:18 +000091static inline void debug_fence_activate(struct i915_sw_fence *fence)
92{
93}
94
95static inline void debug_fence_set_state(struct i915_sw_fence *fence,
96 int old, int new)
97{
98}
99
100static inline void debug_fence_deactivate(struct i915_sw_fence *fence)
101{
102}
103
104static inline void debug_fence_destroy(struct i915_sw_fence *fence)
105{
106}
107
108static inline void debug_fence_free(struct i915_sw_fence *fence)
109{
110}
111
112static inline void debug_fence_assert(struct i915_sw_fence *fence)
113{
114}
115
116#endif
117
Chris Wilsone68a1392016-09-09 14:11:41 +0100118static int __i915_sw_fence_notify(struct i915_sw_fence *fence,
119 enum i915_sw_fence_notify state)
120{
121 i915_sw_fence_notify_t fn;
122
123 fn = (i915_sw_fence_notify_t)(fence->flags & I915_SW_FENCE_MASK);
124 return fn(fence, state);
125}
126
Chris Wilsonfc158402016-11-25 13:17:18 +0000127#ifdef CONFIG_DRM_I915_SW_FENCE_DEBUG_OBJECTS
128void i915_sw_fence_fini(struct i915_sw_fence *fence)
129{
130 debug_fence_free(fence);
131}
132#endif
133
Chris Wilsone68a1392016-09-09 14:11:41 +0100134static void __i915_sw_fence_wake_up_all(struct i915_sw_fence *fence,
135 struct list_head *continuation)
136{
137 wait_queue_head_t *x = &fence->wait;
Ingo Molnarac6424b2017-06-20 12:06:13 +0200138 wait_queue_entry_t *pos, *next;
Chris Wilsone68a1392016-09-09 14:11:41 +0100139 unsigned long flags;
140
Chris Wilsonfc158402016-11-25 13:17:18 +0000141 debug_fence_deactivate(fence);
Chris Wilsone68a1392016-09-09 14:11:41 +0100142 atomic_set_release(&fence->pending, -1); /* 0 -> -1 [done] */
143
144 /*
145 * To prevent unbounded recursion as we traverse the graph of
Ingo Molnar2055da92017-06-20 12:06:46 +0200146 * i915_sw_fences, we move the entry list from this, the next ready
147 * fence, to the tail of the original fence's entry list
Chris Wilsone68a1392016-09-09 14:11:41 +0100148 * (and so added to the list to be woken).
149 */
150
151 spin_lock_irqsave_nested(&x->lock, flags, 1 + !!continuation);
152 if (continuation) {
Ingo Molnar2055da92017-06-20 12:06:46 +0200153 list_for_each_entry_safe(pos, next, &x->head, entry) {
Chris Wilsone68a1392016-09-09 14:11:41 +0100154 if (pos->func == autoremove_wake_function)
155 pos->func(pos, TASK_NORMAL, 0, continuation);
156 else
Ingo Molnar2055da92017-06-20 12:06:46 +0200157 list_move_tail(&pos->entry, continuation);
Chris Wilsone68a1392016-09-09 14:11:41 +0100158 }
159 } else {
160 LIST_HEAD(extra);
161
162 do {
Ingo Molnar2055da92017-06-20 12:06:46 +0200163 list_for_each_entry_safe(pos, next, &x->head, entry)
Chris Wilsone68a1392016-09-09 14:11:41 +0100164 pos->func(pos, TASK_NORMAL, 0, &extra);
165
166 if (list_empty(&extra))
167 break;
168
Ingo Molnar2055da92017-06-20 12:06:46 +0200169 list_splice_tail_init(&extra, &x->head);
Chris Wilsone68a1392016-09-09 14:11:41 +0100170 } while (1);
171 }
172 spin_unlock_irqrestore(&x->lock, flags);
Chris Wilsonfc158402016-11-25 13:17:18 +0000173
174 debug_fence_assert(fence);
Chris Wilsone68a1392016-09-09 14:11:41 +0100175}
176
177static void __i915_sw_fence_complete(struct i915_sw_fence *fence,
178 struct list_head *continuation)
179{
Chris Wilsonfc158402016-11-25 13:17:18 +0000180 debug_fence_assert(fence);
181
Chris Wilsone68a1392016-09-09 14:11:41 +0100182 if (!atomic_dec_and_test(&fence->pending))
183 return;
184
Chris Wilsonfc158402016-11-25 13:17:18 +0000185 debug_fence_set_state(fence, DEBUG_FENCE_IDLE, DEBUG_FENCE_NOTIFY);
186
Chris Wilson9310cb72017-05-17 13:09:56 +0100187 if (__i915_sw_fence_notify(fence, FENCE_COMPLETE) != NOTIFY_DONE)
Chris Wilsone68a1392016-09-09 14:11:41 +0100188 return;
189
Chris Wilsonfc158402016-11-25 13:17:18 +0000190 debug_fence_set_state(fence, DEBUG_FENCE_NOTIFY, DEBUG_FENCE_IDLE);
191
Chris Wilsone68a1392016-09-09 14:11:41 +0100192 __i915_sw_fence_wake_up_all(fence, continuation);
Chris Wilson9310cb72017-05-17 13:09:56 +0100193
194 debug_fence_destroy(fence);
195 __i915_sw_fence_notify(fence, FENCE_FREE);
Chris Wilsone68a1392016-09-09 14:11:41 +0100196}
197
198static void i915_sw_fence_complete(struct i915_sw_fence *fence)
199{
Chris Wilsonfc158402016-11-25 13:17:18 +0000200 debug_fence_assert(fence);
201
Chris Wilsone68a1392016-09-09 14:11:41 +0100202 if (WARN_ON(i915_sw_fence_done(fence)))
203 return;
204
205 __i915_sw_fence_complete(fence, NULL);
206}
207
208static void i915_sw_fence_await(struct i915_sw_fence *fence)
209{
Chris Wilsonfc158402016-11-25 13:17:18 +0000210 debug_fence_assert(fence);
Chris Wilsone68a1392016-09-09 14:11:41 +0100211 WARN_ON(atomic_inc_return(&fence->pending) <= 1);
212}
213
Chris Wilson556b7482016-11-14 20:40:56 +0000214void __i915_sw_fence_init(struct i915_sw_fence *fence,
215 i915_sw_fence_notify_t fn,
216 const char *name,
217 struct lock_class_key *key)
Chris Wilsone68a1392016-09-09 14:11:41 +0100218{
Chris Wilson9310cb72017-05-17 13:09:56 +0100219 BUG_ON(!fn || (unsigned long)fn & ~I915_SW_FENCE_MASK);
Chris Wilsone68a1392016-09-09 14:11:41 +0100220
Chris Wilsonfc158402016-11-25 13:17:18 +0000221 debug_fence_init(fence);
222
Chris Wilson556b7482016-11-14 20:40:56 +0000223 __init_waitqueue_head(&fence->wait, name, key);
Chris Wilsone68a1392016-09-09 14:11:41 +0100224 atomic_set(&fence->pending, 1);
225 fence->flags = (unsigned long)fn;
226}
227
Chris Wilsonfc158402016-11-25 13:17:18 +0000228void i915_sw_fence_commit(struct i915_sw_fence *fence)
229{
230 debug_fence_activate(fence);
Chris Wilson9310cb72017-05-17 13:09:56 +0100231 i915_sw_fence_complete(fence);
Chris Wilsonfc158402016-11-25 13:17:18 +0000232}
233
Ingo Molnarac6424b2017-06-20 12:06:13 +0200234static int i915_sw_fence_wake(wait_queue_entry_t *wq, unsigned mode, int flags, void *key)
Chris Wilsone68a1392016-09-09 14:11:41 +0100235{
Ingo Molnar2055da92017-06-20 12:06:46 +0200236 list_del(&wq->entry);
Chris Wilsone68a1392016-09-09 14:11:41 +0100237 __i915_sw_fence_complete(wq->private, key);
Chris Wilson9310cb72017-05-17 13:09:56 +0100238
Chris Wilson7e941862016-10-28 13:58:25 +0100239 if (wq->flags & I915_SW_FENCE_FLAG_ALLOC)
240 kfree(wq);
Chris Wilsone68a1392016-09-09 14:11:41 +0100241 return 0;
242}
243
244static bool __i915_sw_fence_check_if_after(struct i915_sw_fence *fence,
245 const struct i915_sw_fence * const signaler)
246{
Ingo Molnarac6424b2017-06-20 12:06:13 +0200247 wait_queue_entry_t *wq;
Chris Wilsone68a1392016-09-09 14:11:41 +0100248
249 if (__test_and_set_bit(I915_SW_FENCE_CHECKED_BIT, &fence->flags))
250 return false;
251
252 if (fence == signaler)
253 return true;
254
Ingo Molnar2055da92017-06-20 12:06:46 +0200255 list_for_each_entry(wq, &fence->wait.head, entry) {
Chris Wilsone68a1392016-09-09 14:11:41 +0100256 if (wq->func != i915_sw_fence_wake)
257 continue;
258
259 if (__i915_sw_fence_check_if_after(wq->private, signaler))
260 return true;
261 }
262
263 return false;
264}
265
266static void __i915_sw_fence_clear_checked_bit(struct i915_sw_fence *fence)
267{
Ingo Molnarac6424b2017-06-20 12:06:13 +0200268 wait_queue_entry_t *wq;
Chris Wilsone68a1392016-09-09 14:11:41 +0100269
270 if (!__test_and_clear_bit(I915_SW_FENCE_CHECKED_BIT, &fence->flags))
271 return;
272
Ingo Molnar2055da92017-06-20 12:06:46 +0200273 list_for_each_entry(wq, &fence->wait.head, entry) {
Chris Wilsone68a1392016-09-09 14:11:41 +0100274 if (wq->func != i915_sw_fence_wake)
275 continue;
276
277 __i915_sw_fence_clear_checked_bit(wq->private);
278 }
279}
280
281static bool i915_sw_fence_check_if_after(struct i915_sw_fence *fence,
282 const struct i915_sw_fence * const signaler)
283{
284 unsigned long flags;
285 bool err;
286
Chris Wilson47624cc2017-05-17 13:09:57 +0100287 if (!IS_ENABLED(CONFIG_DRM_I915_SW_FENCE_CHECK_DAG))
Chris Wilsone68a1392016-09-09 14:11:41 +0100288 return false;
289
290 spin_lock_irqsave(&i915_sw_fence_lock, flags);
291 err = __i915_sw_fence_check_if_after(fence, signaler);
292 __i915_sw_fence_clear_checked_bit(fence);
293 spin_unlock_irqrestore(&i915_sw_fence_lock, flags);
294
295 return err;
296}
297
Chris Wilson7e941862016-10-28 13:58:25 +0100298static int __i915_sw_fence_await_sw_fence(struct i915_sw_fence *fence,
299 struct i915_sw_fence *signaler,
Ingo Molnarac6424b2017-06-20 12:06:13 +0200300 wait_queue_entry_t *wq, gfp_t gfp)
Chris Wilsone68a1392016-09-09 14:11:41 +0100301{
302 unsigned long flags;
303 int pending;
304
Chris Wilsonfc158402016-11-25 13:17:18 +0000305 debug_fence_assert(fence);
306
Chris Wilsone68a1392016-09-09 14:11:41 +0100307 if (i915_sw_fence_done(signaler))
308 return 0;
309
Chris Wilsonfc158402016-11-25 13:17:18 +0000310 debug_fence_assert(signaler);
311
Chris Wilsone68a1392016-09-09 14:11:41 +0100312 /* The dependency graph must be acyclic. */
313 if (unlikely(i915_sw_fence_check_if_after(fence, signaler)))
314 return -EINVAL;
315
Chris Wilson7e941862016-10-28 13:58:25 +0100316 pending = 0;
317 if (!wq) {
318 wq = kmalloc(sizeof(*wq), gfp);
319 if (!wq) {
320 if (!gfpflags_allow_blocking(gfp))
321 return -ENOMEM;
322
323 i915_sw_fence_wait(signaler);
324 return 0;
325 }
326
327 pending |= I915_SW_FENCE_FLAG_ALLOC;
328 }
329
Ingo Molnar2055da92017-06-20 12:06:46 +0200330 INIT_LIST_HEAD(&wq->entry);
Chris Wilson7e941862016-10-28 13:58:25 +0100331 wq->flags = pending;
Chris Wilsone68a1392016-09-09 14:11:41 +0100332 wq->func = i915_sw_fence_wake;
Chris Wilson9310cb72017-05-17 13:09:56 +0100333 wq->private = fence;
Chris Wilsone68a1392016-09-09 14:11:41 +0100334
335 i915_sw_fence_await(fence);
336
337 spin_lock_irqsave(&signaler->wait.lock, flags);
338 if (likely(!i915_sw_fence_done(signaler))) {
Ingo Molnarac6424b2017-06-20 12:06:13 +0200339 __add_wait_queue_entry_tail(&signaler->wait, wq);
Chris Wilsone68a1392016-09-09 14:11:41 +0100340 pending = 1;
341 } else {
342 i915_sw_fence_wake(wq, 0, 0, NULL);
343 pending = 0;
344 }
345 spin_unlock_irqrestore(&signaler->wait.lock, flags);
346
347 return pending;
348}
349
Chris Wilson7e941862016-10-28 13:58:25 +0100350int i915_sw_fence_await_sw_fence(struct i915_sw_fence *fence,
351 struct i915_sw_fence *signaler,
Ingo Molnarac6424b2017-06-20 12:06:13 +0200352 wait_queue_entry_t *wq)
Chris Wilson7e941862016-10-28 13:58:25 +0100353{
354 return __i915_sw_fence_await_sw_fence(fence, signaler, wq, 0);
355}
356
357int i915_sw_fence_await_sw_fence_gfp(struct i915_sw_fence *fence,
358 struct i915_sw_fence *signaler,
359 gfp_t gfp)
360{
361 return __i915_sw_fence_await_sw_fence(fence, signaler, NULL, gfp);
362}
363
Chris Wilsonf54d1862016-10-25 13:00:45 +0100364struct i915_sw_dma_fence_cb {
365 struct dma_fence_cb base;
Chris Wilsone68a1392016-09-09 14:11:41 +0100366 struct i915_sw_fence *fence;
Chris Wilsonf54d1862016-10-25 13:00:45 +0100367 struct dma_fence *dma;
Chris Wilsone68a1392016-09-09 14:11:41 +0100368 struct timer_list timer;
Chris Wilson81c0ed22017-09-11 09:41:26 +0100369 struct irq_work work;
Chris Wilson2cf654d2017-12-13 09:48:02 +0000370 struct rcu_head rcu;
Chris Wilsone68a1392016-09-09 14:11:41 +0100371};
372
Kees Cook39cbf2a2017-10-17 09:53:04 +0300373static void timer_i915_sw_fence_wake(struct timer_list *t)
Chris Wilsone68a1392016-09-09 14:11:41 +0100374{
Kees Cook39cbf2a2017-10-17 09:53:04 +0300375 struct i915_sw_dma_fence_cb *cb = from_timer(cb, t, timer);
Chris Wilson81c0ed22017-09-11 09:41:26 +0100376 struct i915_sw_fence *fence;
377
378 fence = xchg(&cb->fence, NULL);
379 if (!fence)
380 return;
Chris Wilsone68a1392016-09-09 14:11:41 +0100381
Joe Perches8dfe1622017-02-28 04:55:54 -0800382 pr_warn("asynchronous wait on fence %s:%s:%x timed out\n",
383 cb->dma->ops->get_driver_name(cb->dma),
384 cb->dma->ops->get_timeline_name(cb->dma),
385 cb->dma->seqno);
Chris Wilsone68a1392016-09-09 14:11:41 +0100386
Chris Wilson81c0ed22017-09-11 09:41:26 +0100387 i915_sw_fence_complete(fence);
Chris Wilsone68a1392016-09-09 14:11:41 +0100388}
389
Chris Wilsonf54d1862016-10-25 13:00:45 +0100390static void dma_i915_sw_fence_wake(struct dma_fence *dma,
391 struct dma_fence_cb *data)
Chris Wilsone68a1392016-09-09 14:11:41 +0100392{
Chris Wilsonf54d1862016-10-25 13:00:45 +0100393 struct i915_sw_dma_fence_cb *cb = container_of(data, typeof(*cb), base);
Chris Wilson81c0ed22017-09-11 09:41:26 +0100394 struct i915_sw_fence *fence;
395
396 fence = xchg(&cb->fence, NULL);
397 if (fence)
398 i915_sw_fence_complete(fence);
399
400 irq_work_queue(&cb->work);
401}
402
403static void irq_i915_sw_fence_work(struct irq_work *wrk)
404{
405 struct i915_sw_dma_fence_cb *cb = container_of(wrk, typeof(*cb), work);
Chris Wilsone68a1392016-09-09 14:11:41 +0100406
407 del_timer_sync(&cb->timer);
Chris Wilsonf54d1862016-10-25 13:00:45 +0100408 dma_fence_put(cb->dma);
Chris Wilsone68a1392016-09-09 14:11:41 +0100409
Chris Wilson2cf654d2017-12-13 09:48:02 +0000410 kfree_rcu(cb, rcu);
Chris Wilsone68a1392016-09-09 14:11:41 +0100411}
412
413int i915_sw_fence_await_dma_fence(struct i915_sw_fence *fence,
Chris Wilsonf54d1862016-10-25 13:00:45 +0100414 struct dma_fence *dma,
Chris Wilsone68a1392016-09-09 14:11:41 +0100415 unsigned long timeout,
416 gfp_t gfp)
417{
Chris Wilsonf54d1862016-10-25 13:00:45 +0100418 struct i915_sw_dma_fence_cb *cb;
Chris Wilsone68a1392016-09-09 14:11:41 +0100419 int ret;
420
Chris Wilsonfc158402016-11-25 13:17:18 +0000421 debug_fence_assert(fence);
422
Chris Wilsonf54d1862016-10-25 13:00:45 +0100423 if (dma_fence_is_signaled(dma))
Chris Wilsone68a1392016-09-09 14:11:41 +0100424 return 0;
425
426 cb = kmalloc(sizeof(*cb), gfp);
427 if (!cb) {
428 if (!gfpflags_allow_blocking(gfp))
429 return -ENOMEM;
430
Chris Wilsonf54d1862016-10-25 13:00:45 +0100431 return dma_fence_wait(dma, false);
Chris Wilsone68a1392016-09-09 14:11:41 +0100432 }
433
Chris Wilson9310cb72017-05-17 13:09:56 +0100434 cb->fence = fence;
Chris Wilsone68a1392016-09-09 14:11:41 +0100435 i915_sw_fence_await(fence);
436
437 cb->dma = NULL;
Kees Cook39cbf2a2017-10-17 09:53:04 +0300438 timer_setup(&cb->timer, timer_i915_sw_fence_wake, TIMER_IRQSAFE);
Chris Wilson81c0ed22017-09-11 09:41:26 +0100439 init_irq_work(&cb->work, irq_i915_sw_fence_work);
Chris Wilsone68a1392016-09-09 14:11:41 +0100440 if (timeout) {
Chris Wilsonf54d1862016-10-25 13:00:45 +0100441 cb->dma = dma_fence_get(dma);
Chris Wilsone68a1392016-09-09 14:11:41 +0100442 mod_timer(&cb->timer, round_jiffies_up(jiffies + timeout));
443 }
444
Chris Wilsonf54d1862016-10-25 13:00:45 +0100445 ret = dma_fence_add_callback(dma, &cb->base, dma_i915_sw_fence_wake);
Chris Wilsone68a1392016-09-09 14:11:41 +0100446 if (ret == 0) {
447 ret = 1;
448 } else {
449 dma_i915_sw_fence_wake(dma, &cb->base);
450 if (ret == -ENOENT) /* fence already signaled */
451 ret = 0;
452 }
453
454 return ret;
455}
456
457int i915_sw_fence_await_reservation(struct i915_sw_fence *fence,
458 struct reservation_object *resv,
Chris Wilsonf54d1862016-10-25 13:00:45 +0100459 const struct dma_fence_ops *exclude,
Chris Wilsone68a1392016-09-09 14:11:41 +0100460 bool write,
461 unsigned long timeout,
462 gfp_t gfp)
463{
Chris Wilsonf54d1862016-10-25 13:00:45 +0100464 struct dma_fence *excl;
Chris Wilsone68a1392016-09-09 14:11:41 +0100465 int ret = 0, pending;
466
Chris Wilsonfc158402016-11-25 13:17:18 +0000467 debug_fence_assert(fence);
468
Chris Wilsone68a1392016-09-09 14:11:41 +0100469 if (write) {
Chris Wilsonf54d1862016-10-25 13:00:45 +0100470 struct dma_fence **shared;
Chris Wilsone68a1392016-09-09 14:11:41 +0100471 unsigned int count, i;
472
473 ret = reservation_object_get_fences_rcu(resv,
474 &excl, &count, &shared);
475 if (ret)
476 return ret;
477
478 for (i = 0; i < count; i++) {
479 if (shared[i]->ops == exclude)
480 continue;
481
482 pending = i915_sw_fence_await_dma_fence(fence,
483 shared[i],
484 timeout,
485 gfp);
486 if (pending < 0) {
487 ret = pending;
488 break;
489 }
490
491 ret |= pending;
492 }
493
494 for (i = 0; i < count; i++)
Chris Wilsonf54d1862016-10-25 13:00:45 +0100495 dma_fence_put(shared[i]);
Chris Wilsone68a1392016-09-09 14:11:41 +0100496 kfree(shared);
497 } else {
498 excl = reservation_object_get_excl_rcu(resv);
499 }
500
501 if (ret >= 0 && excl && excl->ops != exclude) {
502 pending = i915_sw_fence_await_dma_fence(fence,
503 excl,
504 timeout,
505 gfp);
506 if (pending < 0)
507 ret = pending;
508 else
509 ret |= pending;
510 }
511
Chris Wilsonf54d1862016-10-25 13:00:45 +0100512 dma_fence_put(excl);
Chris Wilsone68a1392016-09-09 14:11:41 +0100513
514 return ret;
515}
Chris Wilson47624cc2017-05-17 13:09:57 +0100516
517#if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
Chris Wilson214707f2017-10-12 13:57:25 +0100518#include "selftests/lib_sw_fence.c"
Chris Wilson47624cc2017-05-17 13:09:57 +0100519#include "selftests/i915_sw_fence.c"
520#endif