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(struct dma_fence *); 61 int dma_fence_signal_locked(struct dma_fence *); 62 int dma_fence_signal_timestamp(struct dma_fence *, ktime_t); 63 int dma_fence_signal_timestamp_locked(struct dma_fence *, ktime_t); 64 bool dma_fence_is_signaled(struct dma_fence *); 65 bool dma_fence_is_signaled_locked(struct dma_fence *); 66 long dma_fence_default_wait(struct dma_fence *, bool, long); 67 long dma_fence_wait_any_timeout(struct dma_fence **, uint32_t, bool, long, 68 uint32_t *); 69 long dma_fence_wait_timeout(struct dma_fence *, bool, long); 70 long dma_fence_wait(struct dma_fence *, bool); 71 void dma_fence_enable_sw_signaling(struct dma_fence *); 72 void dma_fence_init(struct dma_fence *, const struct dma_fence_ops *, 73 struct mutex *, uint64_t, uint64_t); 74 int dma_fence_add_callback(struct dma_fence *, struct dma_fence_cb *, 75 dma_fence_func_t); 76 bool dma_fence_remove_callback(struct dma_fence *, struct dma_fence_cb *); 77 78 struct dma_fence *dma_fence_get_stub(void); 79 struct dma_fence *dma_fence_allocate_private_stub(void); 80 81 static inline void 82 dma_fence_free(struct dma_fence *fence) 83 { 84 free(fence, M_DRM, 0); 85 } 86 87 static inline bool 88 dma_fence_is_later(struct dma_fence *a, struct dma_fence *b) 89 { 90 return (a->seqno > b->seqno); 91 } 92 93 static inline void 94 dma_fence_set_error(struct dma_fence *fence, int error) 95 { 96 fence->error = error; 97 } 98 99 #endif 100