1 /* Public domain. */ 2 3 #ifndef _LINUX_DMA_FENCE_CHAIN_H 4 #define _LINUX_DMA_FENCE_CHAIN_H 5 6 #include <linux/dma-fence.h> 7 8 struct dma_fence_chain { 9 struct dma_fence base; 10 struct dma_fence *fence; 11 struct dma_fence *prev; 12 uint64_t prev_seqno; 13 struct mutex lock; 14 union { 15 struct timeout to; 16 struct dma_fence_cb cb; 17 }; 18 }; 19 20 int dma_fence_chain_find_seqno(struct dma_fence **, uint64_t); 21 void dma_fence_chain_init(struct dma_fence_chain *, struct dma_fence *, 22 struct dma_fence *, uint64_t); 23 24 extern const struct dma_fence_ops dma_fence_chain_ops; 25 26 static inline struct dma_fence_chain * 27 to_dma_fence_chain(struct dma_fence *fence) 28 { 29 if ((fence == NULL) || (fence->ops != &dma_fence_chain_ops)) 30 return NULL; 31 32 return container_of(fence, struct dma_fence_chain, base); 33 } 34 35 struct dma_fence *dma_fence_chain_walk(struct dma_fence *); 36 37 #define dma_fence_chain_for_each(f, h) \ 38 for (f = dma_fence_get(h); f != NULL; f = dma_fence_chain_walk(f)) 39 40 static inline struct dma_fence_chain * 41 dma_fence_chain_alloc(void) 42 { 43 return malloc(sizeof(struct dma_fence_chain), M_DRM, 44 M_WAITOK | M_CANFAIL); 45 } 46 47 static inline void 48 dma_fence_chain_free(struct dma_fence_chain *dfc) 49 { 50 free(dfc, M_DRM, sizeof(struct dma_fence_chain)); 51 } 52 53 static inline struct dma_fence * 54 dma_fence_chain_contained(struct dma_fence *f) 55 { 56 struct dma_fence_chain *dfc = to_dma_fence_chain(f); 57 58 if (dfc != NULL) 59 return dfc->fence; 60 return f; 61 } 62 63 #endif 64