1 /* 2 * i915_sw_fence.h - library routines for N:M synchronisation points 3 * 4 * Copyright (C) 2016 Intel Corporation 5 * 6 * This file is released under the GPLv2. 7 * 8 */ 9 10 #ifndef _I915_SW_FENCE_H_ 11 #define _I915_SW_FENCE_H_ 12 13 #include <linux/gfp.h> 14 #include <linux/kref.h> 15 #include <linux/notifier.h> /* for NOTIFY_DONE */ 16 #include <linux/wait.h> 17 18 struct completion; 19 struct dma_fence; 20 struct dma_fence_ops; 21 struct reservation_object; 22 23 struct i915_sw_fence { 24 wait_queue_head_t wait; 25 unsigned long flags; 26 struct kref kref; 27 atomic_t pending; 28 }; 29 30 #define I915_SW_FENCE_CHECKED_BIT 0 /* used internally for DAG checking */ 31 #define I915_SW_FENCE_PRIVATE_BIT 1 /* available for use by owner */ 32 #define I915_SW_FENCE_MASK (~3) 33 34 enum i915_sw_fence_notify { 35 FENCE_COMPLETE, 36 FENCE_FREE 37 }; 38 39 typedef int (*i915_sw_fence_notify_t)(struct i915_sw_fence *, 40 enum i915_sw_fence_notify state); 41 #define __i915_sw_fence_call __aligned(4) 42 43 void __i915_sw_fence_init(struct i915_sw_fence *fence, 44 i915_sw_fence_notify_t fn, 45 const char *name, 46 struct lock_class_key *key); 47 #ifdef CONFIG_LOCKDEP 48 #define i915_sw_fence_init(fence, fn) \ 49 do { \ 50 static struct lock_class_key __key; \ 51 \ 52 __i915_sw_fence_init((fence), (fn), #fence, &__key); \ 53 } while (0) 54 #else 55 #define i915_sw_fence_init(fence, fn) \ 56 __i915_sw_fence_init((fence), (fn), NULL, NULL) 57 #endif 58 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 64 65 void i915_sw_fence_commit(struct i915_sw_fence *fence); 66 67 int i915_sw_fence_await_sw_fence(struct i915_sw_fence *fence, 68 struct i915_sw_fence *after, 69 wait_queue_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); 73 int i915_sw_fence_await_dma_fence(struct i915_sw_fence *fence, 74 struct dma_fence *dma, 75 unsigned long timeout, 76 gfp_t gfp); 77 int i915_sw_fence_await_reservation(struct i915_sw_fence *fence, 78 struct reservation_object *resv, 79 const struct dma_fence_ops *exclude, 80 bool write, 81 unsigned long timeout, 82 gfp_t gfp); 83 84 static inline bool i915_sw_fence_signaled(const struct i915_sw_fence *fence) 85 { 86 return atomic_read(&fence->pending) <= 0; 87 } 88 89 static inline bool i915_sw_fence_done(const struct i915_sw_fence *fence) 90 { 91 return atomic_read(&fence->pending) < 0; 92 } 93 94 static inline void i915_sw_fence_wait(struct i915_sw_fence *fence) 95 { 96 wait_event(fence->wait, i915_sw_fence_done(fence)); 97 } 98 99 #endif /* _I915_SW_FENCE_H_ */ 100