| .. | .. |
|---|
| 1 | 1 | /* |
|---|
| 2 | + * SPDX-License-Identifier: MIT |
|---|
| 3 | + * |
|---|
| 2 | 4 | * i915_sw_fence.h - library routines for N:M synchronisation points |
|---|
| 3 | 5 | * |
|---|
| 4 | 6 | * Copyright (C) 2016 Intel Corporation |
|---|
| 5 | | - * |
|---|
| 6 | | - * This file is released under the GPLv2. |
|---|
| 7 | | - * |
|---|
| 8 | 7 | */ |
|---|
| 9 | 8 | |
|---|
| 10 | 9 | #ifndef _I915_SW_FENCE_H_ |
|---|
| 11 | 10 | #define _I915_SW_FENCE_H_ |
|---|
| 12 | 11 | |
|---|
| 12 | +#include <linux/dma-fence.h> |
|---|
| 13 | 13 | #include <linux/gfp.h> |
|---|
| 14 | 14 | #include <linux/kref.h> |
|---|
| 15 | 15 | #include <linux/notifier.h> /* for NOTIFY_DONE */ |
|---|
| 16 | 16 | #include <linux/wait.h> |
|---|
| 17 | 17 | |
|---|
| 18 | 18 | struct completion; |
|---|
| 19 | | -struct dma_fence; |
|---|
| 20 | | -struct dma_fence_ops; |
|---|
| 21 | | -struct reservation_object; |
|---|
| 19 | +struct dma_resv; |
|---|
| 22 | 20 | |
|---|
| 23 | 21 | struct i915_sw_fence { |
|---|
| 24 | 22 | wait_queue_head_t wait; |
|---|
| 25 | 23 | unsigned long flags; |
|---|
| 26 | 24 | atomic_t pending; |
|---|
| 25 | + int error; |
|---|
| 27 | 26 | }; |
|---|
| 28 | 27 | |
|---|
| 29 | 28 | #define I915_SW_FENCE_CHECKED_BIT 0 /* used internally for DAG checking */ |
|---|
| .. | .. |
|---|
| 55 | 54 | __i915_sw_fence_init((fence), (fn), NULL, NULL) |
|---|
| 56 | 55 | #endif |
|---|
| 57 | 56 | |
|---|
| 57 | +void i915_sw_fence_reinit(struct i915_sw_fence *fence); |
|---|
| 58 | + |
|---|
| 58 | 59 | #ifdef CONFIG_DRM_I915_SW_FENCE_DEBUG_OBJECTS |
|---|
| 59 | 60 | void i915_sw_fence_fini(struct i915_sw_fence *fence); |
|---|
| 60 | 61 | #else |
|---|
| .. | .. |
|---|
| 69 | 70 | int i915_sw_fence_await_sw_fence_gfp(struct i915_sw_fence *fence, |
|---|
| 70 | 71 | struct i915_sw_fence *after, |
|---|
| 71 | 72 | gfp_t gfp); |
|---|
| 73 | + |
|---|
| 74 | +struct i915_sw_dma_fence_cb { |
|---|
| 75 | + struct dma_fence_cb base; |
|---|
| 76 | + struct i915_sw_fence *fence; |
|---|
| 77 | +}; |
|---|
| 78 | + |
|---|
| 79 | +int __i915_sw_fence_await_dma_fence(struct i915_sw_fence *fence, |
|---|
| 80 | + struct dma_fence *dma, |
|---|
| 81 | + struct i915_sw_dma_fence_cb *cb); |
|---|
| 72 | 82 | int i915_sw_fence_await_dma_fence(struct i915_sw_fence *fence, |
|---|
| 73 | 83 | struct dma_fence *dma, |
|---|
| 74 | 84 | unsigned long timeout, |
|---|
| 75 | 85 | gfp_t gfp); |
|---|
| 86 | + |
|---|
| 76 | 87 | int i915_sw_fence_await_reservation(struct i915_sw_fence *fence, |
|---|
| 77 | | - struct reservation_object *resv, |
|---|
| 88 | + struct dma_resv *resv, |
|---|
| 78 | 89 | const struct dma_fence_ops *exclude, |
|---|
| 79 | 90 | bool write, |
|---|
| 80 | 91 | unsigned long timeout, |
|---|
| 81 | 92 | gfp_t gfp); |
|---|
| 93 | + |
|---|
| 94 | +bool i915_sw_fence_await(struct i915_sw_fence *fence); |
|---|
| 95 | +void i915_sw_fence_complete(struct i915_sw_fence *fence); |
|---|
| 82 | 96 | |
|---|
| 83 | 97 | static inline bool i915_sw_fence_signaled(const struct i915_sw_fence *fence) |
|---|
| 84 | 98 | { |
|---|
| .. | .. |
|---|
| 95 | 109 | wait_event(fence->wait, i915_sw_fence_done(fence)); |
|---|
| 96 | 110 | } |
|---|
| 97 | 111 | |
|---|
| 112 | +static inline void |
|---|
| 113 | +i915_sw_fence_set_error_once(struct i915_sw_fence *fence, int error) |
|---|
| 114 | +{ |
|---|
| 115 | + if (unlikely(error)) |
|---|
| 116 | + cmpxchg(&fence->error, 0, error); |
|---|
| 117 | +} |
|---|
| 118 | + |
|---|
| 98 | 119 | #endif /* _I915_SW_FENCE_H_ */ |
|---|