Chris Wilson | e68a139 | 2016-09-09 14:11:41 +0100 | [diff] [blame] | 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 fence; |
| 20 | struct 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, i915_sw_fence_notify_t fn); |
| 44 | void i915_sw_fence_commit(struct i915_sw_fence *fence); |
| 45 | |
| 46 | int i915_sw_fence_await_sw_fence(struct i915_sw_fence *fence, |
| 47 | struct i915_sw_fence *after, |
| 48 | wait_queue_t *wq); |
| 49 | int i915_sw_fence_await_dma_fence(struct i915_sw_fence *fence, |
| 50 | struct fence *dma, |
| 51 | unsigned long timeout, |
| 52 | gfp_t gfp); |
| 53 | int i915_sw_fence_await_reservation(struct i915_sw_fence *fence, |
| 54 | struct reservation_object *resv, |
| 55 | const struct fence_ops *exclude, |
| 56 | bool write, |
| 57 | unsigned long timeout, |
| 58 | gfp_t gfp); |
| 59 | |
| 60 | static inline bool i915_sw_fence_done(const struct i915_sw_fence *fence) |
| 61 | { |
| 62 | return atomic_read(&fence->pending) < 0; |
| 63 | } |
| 64 | |
| 65 | #endif /* _I915_SW_FENCE_H_ */ |