diff options
| -rw-r--r-- | drivers/dma-buf/dma-fence.c | 36 | ||||
| -rw-r--r-- | include/linux/dma-fence.h | 1 |
2 files changed, 36 insertions, 1 deletions
diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c index 1551ca7df394..136ec04d683f 100644 --- a/drivers/dma-buf/dma-fence.c +++ b/drivers/dma-buf/dma-fence.c | |||
| @@ -30,13 +30,16 @@ | |||
| 30 | EXPORT_TRACEPOINT_SYMBOL(dma_fence_emit); | 30 | EXPORT_TRACEPOINT_SYMBOL(dma_fence_emit); |
| 31 | EXPORT_TRACEPOINT_SYMBOL(dma_fence_enable_signal); | 31 | EXPORT_TRACEPOINT_SYMBOL(dma_fence_enable_signal); |
| 32 | 32 | ||
| 33 | static DEFINE_SPINLOCK(dma_fence_stub_lock); | ||
| 34 | static struct dma_fence dma_fence_stub; | ||
| 35 | |||
| 33 | /* | 36 | /* |
| 34 | * fence context counter: each execution context should have its own | 37 | * fence context counter: each execution context should have its own |
| 35 | * fence context, this allows checking if fences belong to the same | 38 | * fence context, this allows checking if fences belong to the same |
| 36 | * context or not. One device can have multiple separate contexts, | 39 | * context or not. One device can have multiple separate contexts, |
| 37 | * and they're used if some engine can run independently of another. | 40 | * and they're used if some engine can run independently of another. |
| 38 | */ | 41 | */ |
| 39 | static atomic64_t dma_fence_context_counter = ATOMIC64_INIT(0); | 42 | static atomic64_t dma_fence_context_counter = ATOMIC64_INIT(1); |
| 40 | 43 | ||
| 41 | /** | 44 | /** |
| 42 | * DOC: DMA fences overview | 45 | * DOC: DMA fences overview |
| @@ -68,6 +71,37 @@ static atomic64_t dma_fence_context_counter = ATOMIC64_INIT(0); | |||
| 68 | * &dma_buf.resv pointer. | 71 | * &dma_buf.resv pointer. |
| 69 | */ | 72 | */ |
| 70 | 73 | ||
| 74 | static const char *dma_fence_stub_get_name(struct dma_fence *fence) | ||
| 75 | { | ||
| 76 | return "stub"; | ||
| 77 | } | ||
| 78 | |||
| 79 | static const struct dma_fence_ops dma_fence_stub_ops = { | ||
| 80 | .get_driver_name = dma_fence_stub_get_name, | ||
| 81 | .get_timeline_name = dma_fence_stub_get_name, | ||
| 82 | }; | ||
| 83 | |||
| 84 | /** | ||
| 85 | * dma_fence_get_stub - return a signaled fence | ||
| 86 | * | ||
| 87 | * Return a stub fence which is already signaled. | ||
| 88 | */ | ||
| 89 | struct dma_fence *dma_fence_get_stub(void) | ||
| 90 | { | ||
| 91 | spin_lock(&dma_fence_stub_lock); | ||
| 92 | if (!dma_fence_stub.ops) { | ||
| 93 | dma_fence_init(&dma_fence_stub, | ||
| 94 | &dma_fence_stub_ops, | ||
| 95 | &dma_fence_stub_lock, | ||
| 96 | 0, 0); | ||
| 97 | dma_fence_signal_locked(&dma_fence_stub); | ||
| 98 | } | ||
| 99 | spin_unlock(&dma_fence_stub_lock); | ||
| 100 | |||
| 101 | return dma_fence_get(&dma_fence_stub); | ||
| 102 | } | ||
| 103 | EXPORT_SYMBOL(dma_fence_get_stub); | ||
| 104 | |||
| 71 | /** | 105 | /** |
| 72 | * dma_fence_context_alloc - allocate an array of fence contexts | 106 | * dma_fence_context_alloc - allocate an array of fence contexts |
| 73 | * @num: amount of contexts to allocate | 107 | * @num: amount of contexts to allocate |
diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h index 02dba8cd033d..999e4b104410 100644 --- a/include/linux/dma-fence.h +++ b/include/linux/dma-fence.h | |||
| @@ -541,6 +541,7 @@ static inline signed long dma_fence_wait(struct dma_fence *fence, bool intr) | |||
| 541 | return ret < 0 ? ret : 0; | 541 | return ret < 0 ? ret : 0; |
| 542 | } | 542 | } |
| 543 | 543 | ||
| 544 | struct dma_fence *dma_fence_get_stub(void); | ||
| 544 | u64 dma_fence_context_alloc(unsigned num); | 545 | u64 dma_fence_context_alloc(unsigned num); |
| 545 | 546 | ||
| 546 | #define DMA_FENCE_TRACE(f, fmt, args...) \ | 547 | #define DMA_FENCE_TRACE(f, fmt, args...) \ |
