xref: /openbsd-src/sys/dev/pci/drm/include/linux/dma-fence.h (revision 5a38ef86d0b61900239c7913d24a05e7b88a58f0)
1 /* Public domain. */
2 
3 #ifndef _LINUX_DMA_FENCE_H
4 #define _LINUX_DMA_FENCE_H
5 
6 #include <sys/types.h>
7 #include <sys/mutex.h>
8 #include <linux/kref.h>
9 #include <linux/list.h>
10 #include <linux/sched.h>
11 #include <linux/rcupdate.h>
12 
13 #define DMA_FENCE_TRACE(fence, fmt, args...) do {} while(0)
14 
15 struct dma_fence {
16 	struct kref refcount;
17 	const struct dma_fence_ops *ops;
18 	unsigned long flags;
19 	uint64_t context;
20 	uint64_t seqno;
21 	struct mutex *lock;
22 	union {
23 		struct list_head cb_list;
24 		ktime_t timestamp;
25 		struct rcu_head rcu;
26 	};
27 	int error;
28 };
29 
30 enum dma_fence_flag_bits {
31 	DMA_FENCE_FLAG_SIGNALED_BIT,
32 	DMA_FENCE_FLAG_TIMESTAMP_BIT,
33 	DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT,
34 	DMA_FENCE_FLAG_USER_BITS,
35 };
36 
37 struct dma_fence_ops {
38 	const char * (*get_driver_name)(struct dma_fence *);
39 	const char * (*get_timeline_name)(struct dma_fence *);
40 	bool (*enable_signaling)(struct dma_fence *);
41 	bool (*signaled)(struct dma_fence *);
42 	long (*wait)(struct dma_fence *, bool, long);
43 	void (*release)(struct dma_fence *);
44 };
45 
46 struct dma_fence_cb;
47 typedef void (*dma_fence_func_t)(struct dma_fence *fence, struct dma_fence_cb *cb);
48 
49 struct dma_fence_cb {
50 	struct list_head node;
51 	dma_fence_func_t func;
52 };
53 
54 uint64_t dma_fence_context_alloc(unsigned int);
55 struct dma_fence *dma_fence_get(struct dma_fence *);
56 struct dma_fence *dma_fence_get_rcu(struct dma_fence *);
57 struct dma_fence *dma_fence_get_rcu_safe(struct dma_fence **);
58 void dma_fence_release(struct kref *);
59 void dma_fence_put(struct dma_fence *);
60 int dma_fence_signal_locked(struct dma_fence *);
61 int dma_fence_signal(struct dma_fence *);
62 bool dma_fence_is_signaled(struct dma_fence *);
63 bool dma_fence_is_signaled_locked(struct dma_fence *);
64 long dma_fence_default_wait(struct dma_fence *, bool, long);
65 long dma_fence_wait_any_timeout(struct dma_fence **, uint32_t, bool, long,
66     uint32_t *);
67 long dma_fence_wait_timeout(struct dma_fence *, bool, long);
68 long dma_fence_wait(struct dma_fence *, bool);
69 void dma_fence_enable_sw_signaling(struct dma_fence *);
70 void dma_fence_init(struct dma_fence *, const struct dma_fence_ops *,
71     struct mutex *, uint64_t, uint64_t);
72 int dma_fence_add_callback(struct dma_fence *, struct dma_fence_cb *,
73     dma_fence_func_t);
74 bool dma_fence_remove_callback(struct dma_fence *, struct dma_fence_cb *);
75 
76 struct dma_fence *dma_fence_get_stub(void);
77 
78 static inline void
79 dma_fence_free(struct dma_fence *fence)
80 {
81 	free(fence, M_DRM, 0);
82 }
83 
84 static inline bool
85 dma_fence_is_later(struct dma_fence *a, struct dma_fence *b)
86 {
87 	return (a->seqno > b->seqno);
88 }
89 
90 static inline void
91 dma_fence_set_error(struct dma_fence *fence, int error)
92 {
93 	fence->error = error;
94 }
95 
96 #endif
97