.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * dma-fence-array: aggregate fences to be waited together |
---|
3 | 4 | * |
---|
.. | .. |
---|
6 | 7 | * Authors: |
---|
7 | 8 | * Gustavo Padovan <gustavo@padovan.org> |
---|
8 | 9 | * Christian König <christian.koenig@amd.com> |
---|
9 | | - * |
---|
10 | | - * This program is free software; you can redistribute it and/or modify it |
---|
11 | | - * under the terms of the GNU General Public License version 2 as published by |
---|
12 | | - * the Free Software Foundation. |
---|
13 | | - * |
---|
14 | | - * This program is distributed in the hope that it will be useful, but WITHOUT |
---|
15 | | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
16 | | - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
---|
17 | | - * more details. |
---|
18 | 10 | */ |
---|
19 | 11 | |
---|
20 | 12 | #include <linux/export.h> |
---|
21 | 13 | #include <linux/slab.h> |
---|
22 | 14 | #include <linux/dma-fence-array.h> |
---|
| 15 | + |
---|
| 16 | +#define PENDING_ERROR 1 |
---|
23 | 17 | |
---|
24 | 18 | static const char *dma_fence_array_get_driver_name(struct dma_fence *fence) |
---|
25 | 19 | { |
---|
.. | .. |
---|
31 | 25 | return "unbound"; |
---|
32 | 26 | } |
---|
33 | 27 | |
---|
| 28 | +static void dma_fence_array_set_pending_error(struct dma_fence_array *array, |
---|
| 29 | + int error) |
---|
| 30 | +{ |
---|
| 31 | + /* |
---|
| 32 | + * Propagate the first error reported by any of our fences, but only |
---|
| 33 | + * before we ourselves are signaled. |
---|
| 34 | + */ |
---|
| 35 | + if (error) |
---|
| 36 | + cmpxchg(&array->base.error, PENDING_ERROR, error); |
---|
| 37 | +} |
---|
| 38 | + |
---|
| 39 | +static void dma_fence_array_clear_pending_error(struct dma_fence_array *array) |
---|
| 40 | +{ |
---|
| 41 | + /* Clear the error flag if not actually set. */ |
---|
| 42 | + cmpxchg(&array->base.error, PENDING_ERROR, 0); |
---|
| 43 | +} |
---|
| 44 | + |
---|
34 | 45 | static void irq_dma_fence_array_work(struct irq_work *wrk) |
---|
35 | 46 | { |
---|
36 | 47 | struct dma_fence_array *array = container_of(wrk, typeof(*array), work); |
---|
| 48 | + |
---|
| 49 | + dma_fence_array_clear_pending_error(array); |
---|
37 | 50 | |
---|
38 | 51 | dma_fence_signal(&array->base); |
---|
39 | 52 | dma_fence_put(&array->base); |
---|
.. | .. |
---|
45 | 58 | struct dma_fence_array_cb *array_cb = |
---|
46 | 59 | container_of(cb, struct dma_fence_array_cb, cb); |
---|
47 | 60 | struct dma_fence_array *array = array_cb->array; |
---|
| 61 | + |
---|
| 62 | + dma_fence_array_set_pending_error(array, f->error); |
---|
48 | 63 | |
---|
49 | 64 | if (atomic_dec_and_test(&array->num_pending)) |
---|
50 | 65 | irq_work_queue(&array->work); |
---|
.. | .. |
---|
71 | 86 | dma_fence_get(&array->base); |
---|
72 | 87 | if (dma_fence_add_callback(array->fences[i], &cb[i].cb, |
---|
73 | 88 | dma_fence_array_cb_func)) { |
---|
| 89 | + int error = array->fences[i]->error; |
---|
| 90 | + |
---|
| 91 | + dma_fence_array_set_pending_error(array, error); |
---|
74 | 92 | dma_fence_put(&array->base); |
---|
75 | | - if (atomic_dec_and_test(&array->num_pending)) |
---|
| 93 | + if (atomic_dec_and_test(&array->num_pending)) { |
---|
| 94 | + dma_fence_array_clear_pending_error(array); |
---|
76 | 95 | return false; |
---|
| 96 | + } |
---|
77 | 97 | } |
---|
78 | 98 | } |
---|
79 | 99 | |
---|
.. | .. |
---|
84 | 104 | { |
---|
85 | 105 | struct dma_fence_array *array = to_dma_fence_array(fence); |
---|
86 | 106 | |
---|
87 | | - return atomic_read(&array->num_pending) <= 0; |
---|
| 107 | + if (atomic_read(&array->num_pending) > 0) |
---|
| 108 | + return false; |
---|
| 109 | + |
---|
| 110 | + dma_fence_array_clear_pending_error(array); |
---|
| 111 | + return true; |
---|
88 | 112 | } |
---|
89 | 113 | |
---|
90 | 114 | static void dma_fence_array_release(struct dma_fence *fence) |
---|
.. | .. |
---|
150 | 174 | atomic_set(&array->num_pending, signal_on_any ? 1 : num_fences); |
---|
151 | 175 | array->fences = fences; |
---|
152 | 176 | |
---|
| 177 | + array->base.error = PENDING_ERROR; |
---|
| 178 | + |
---|
153 | 179 | return array; |
---|
154 | 180 | } |
---|
155 | 181 | EXPORT_SYMBOL(dma_fence_array_create); |
---|