Merge tag 'io_uring-5.11-2021-01-16' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / gpu / drm / i915 / i915_sw_fence.h
blob30a863353ee6813fb700618ec493a2fdd5dd8537
1 /*
2 * SPDX-License-Identifier: MIT
4 * i915_sw_fence.h - library routines for N:M synchronisation points
6 * Copyright (C) 2016 Intel Corporation
7 */
9 #ifndef _I915_SW_FENCE_H_
10 #define _I915_SW_FENCE_H_
12 #include <linux/dma-fence.h>
13 #include <linux/gfp.h>
14 #include <linux/kref.h>
15 #include <linux/notifier.h> /* for NOTIFY_DONE */
16 #include <linux/wait.h>
18 struct completion;
19 struct dma_resv;
21 struct i915_sw_fence {
22 wait_queue_head_t wait;
23 unsigned long flags;
24 atomic_t pending;
25 int error;
28 #define I915_SW_FENCE_CHECKED_BIT 0 /* used internally for DAG checking */
29 #define I915_SW_FENCE_PRIVATE_BIT 1 /* available for use by owner */
30 #define I915_SW_FENCE_MASK (~3)
32 enum i915_sw_fence_notify {
33 FENCE_COMPLETE,
34 FENCE_FREE
37 typedef int (*i915_sw_fence_notify_t)(struct i915_sw_fence *,
38 enum i915_sw_fence_notify state);
39 #define __i915_sw_fence_call __aligned(4)
41 void __i915_sw_fence_init(struct i915_sw_fence *fence,
42 i915_sw_fence_notify_t fn,
43 const char *name,
44 struct lock_class_key *key);
45 #ifdef CONFIG_LOCKDEP
46 #define i915_sw_fence_init(fence, fn) \
47 do { \
48 static struct lock_class_key __key; \
50 __i915_sw_fence_init((fence), (fn), #fence, &__key); \
51 } while (0)
52 #else
53 #define i915_sw_fence_init(fence, fn) \
54 __i915_sw_fence_init((fence), (fn), NULL, NULL)
55 #endif
57 void i915_sw_fence_reinit(struct i915_sw_fence *fence);
59 #ifdef CONFIG_DRM_I915_SW_FENCE_DEBUG_OBJECTS
60 void i915_sw_fence_fini(struct i915_sw_fence *fence);
61 #else
62 static inline void i915_sw_fence_fini(struct i915_sw_fence *fence) {}
63 #endif
65 void i915_sw_fence_commit(struct i915_sw_fence *fence);
67 int i915_sw_fence_await_sw_fence(struct i915_sw_fence *fence,
68 struct i915_sw_fence *after,
69 wait_queue_entry_t *wq);
70 int i915_sw_fence_await_sw_fence_gfp(struct i915_sw_fence *fence,
71 struct i915_sw_fence *after,
72 gfp_t gfp);
74 struct i915_sw_dma_fence_cb {
75 struct dma_fence_cb base;
76 struct i915_sw_fence *fence;
79 int __i915_sw_fence_await_dma_fence(struct i915_sw_fence *fence,
80 struct dma_fence *dma,
81 struct i915_sw_dma_fence_cb *cb);
82 int i915_sw_fence_await_dma_fence(struct i915_sw_fence *fence,
83 struct dma_fence *dma,
84 unsigned long timeout,
85 gfp_t gfp);
87 int i915_sw_fence_await_reservation(struct i915_sw_fence *fence,
88 struct dma_resv *resv,
89 const struct dma_fence_ops *exclude,
90 bool write,
91 unsigned long timeout,
92 gfp_t gfp);
94 bool i915_sw_fence_await(struct i915_sw_fence *fence);
95 void i915_sw_fence_complete(struct i915_sw_fence *fence);
97 static inline bool i915_sw_fence_signaled(const struct i915_sw_fence *fence)
99 return atomic_read(&fence->pending) <= 0;
102 static inline bool i915_sw_fence_done(const struct i915_sw_fence *fence)
104 return atomic_read(&fence->pending) < 0;
107 static inline void i915_sw_fence_wait(struct i915_sw_fence *fence)
109 wait_event(fence->wait, i915_sw_fence_done(fence));
112 static inline void
113 i915_sw_fence_set_error_once(struct i915_sw_fence *fence, int error)
115 if (unlikely(error))
116 cmpxchg(&fence->error, 0, error);
119 #endif /* _I915_SW_FENCE_H_ */