summaryrefslogtreecommitdiffstats
path: root/drivers/dma-buf
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2016-10-25 08:00:45 -0400
committerDaniel Vetter <daniel.vetter@ffwll.ch>2016-10-25 08:40:39 -0400
commitf54d1867005c3323f5d8ad83eed823e84226c429 (patch)
tree026c3f57bc546d3a0205389d0f8e0d02ce8a76ac /drivers/dma-buf
parent0fc4f78f44e6c6148cee32456f0d0023ec1c1fd8 (diff)
dma-buf: Rename struct fence to dma_fence
I plan to usurp the short name of struct fence for a core kernel struct, and so I need to rename the specialised fence/timeline for DMA operations to make room. A consensus was reached in https://lists.freedesktop.org/archives/dri-devel/2016-July/113083.html that making clear this fence applies to DMA operations was a good thing. Since then the patch has grown a bit as usage increases, so hopefully it remains a good thing! (v2...: rebase, rerun spatch) v3: Compile on msm, spotted a manual fixup that I broke. v4: Try again for msm, sorry Daniel coccinelle script: @@ @@ - struct fence + struct dma_fence @@ @@ - struct fence_ops + struct dma_fence_ops @@ @@ - struct fence_cb + struct dma_fence_cb @@ @@ - struct fence_array + struct dma_fence_array @@ @@ - enum fence_flag_bits + enum dma_fence_flag_bits @@ @@ ( - fence_init + dma_fence_init | - fence_release + dma_fence_release | - fence_free + dma_fence_free | - fence_get + dma_fence_get | - fence_get_rcu + dma_fence_get_rcu | - fence_put + dma_fence_put | - fence_signal + dma_fence_signal | - fence_signal_locked + dma_fence_signal_locked | - fence_default_wait + dma_fence_default_wait | - fence_add_callback + dma_fence_add_callback | - fence_remove_callback + dma_fence_remove_callback | - fence_enable_sw_signaling + dma_fence_enable_sw_signaling | - fence_is_signaled_locked + dma_fence_is_signaled_locked | - fence_is_signaled + dma_fence_is_signaled | - fence_is_later + dma_fence_is_later | - fence_later + dma_fence_later | - fence_wait_timeout + dma_fence_wait_timeout | - fence_wait_any_timeout + dma_fence_wait_any_timeout | - fence_wait + dma_fence_wait | - fence_context_alloc + dma_fence_context_alloc | - fence_array_create + dma_fence_array_create | - to_fence_array + to_dma_fence_array | - fence_is_array + dma_fence_is_array | - trace_fence_emit + trace_dma_fence_emit | - FENCE_TRACE + DMA_FENCE_TRACE | - FENCE_WARN + DMA_FENCE_WARN | - FENCE_ERR + DMA_FENCE_ERR ) ( ... ) Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Reviewed-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk> Acked-by: Sumit Semwal <sumit.semwal@linaro.org> Acked-by: Christian König <christian.koenig@amd.com> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch> Link: http://patchwork.freedesktop.org/patch/msgid/20161025120045.28839-1-chris@chris-wilson.co.uk
Diffstat (limited to 'drivers/dma-buf')
-rw-r--r--drivers/dma-buf/Kconfig2
-rw-r--r--drivers/dma-buf/Makefile2
-rw-r--r--drivers/dma-buf/dma-buf.c28
-rw-r--r--drivers/dma-buf/dma-fence-array.c (renamed from drivers/dma-buf/fence-array.c)91
-rw-r--r--drivers/dma-buf/dma-fence.c (renamed from drivers/dma-buf/fence.c)199
-rw-r--r--drivers/dma-buf/reservation.c94
-rw-r--r--drivers/dma-buf/seqno-fence.c18
-rw-r--r--drivers/dma-buf/sw_sync.c48
-rw-r--r--drivers/dma-buf/sync_debug.c13
-rw-r--r--drivers/dma-buf/sync_debug.h9
-rw-r--r--drivers/dma-buf/sync_file.c63
11 files changed, 288 insertions, 279 deletions
diff --git a/drivers/dma-buf/Kconfig b/drivers/dma-buf/Kconfig
index 2585821b24ab..ed3b785bae37 100644
--- a/drivers/dma-buf/Kconfig
+++ b/drivers/dma-buf/Kconfig
@@ -7,7 +7,7 @@ config SYNC_FILE
7 select DMA_SHARED_BUFFER 7 select DMA_SHARED_BUFFER
8 ---help--- 8 ---help---
9 The Sync File Framework adds explicit syncronization via 9 The Sync File Framework adds explicit syncronization via
10 userspace. It enables send/receive 'struct fence' objects to/from 10 userspace. It enables send/receive 'struct dma_fence' objects to/from
11 userspace via Sync File fds for synchronization between drivers via 11 userspace via Sync File fds for synchronization between drivers via
12 userspace components. It has been ported from Android. 12 userspace components. It has been ported from Android.
13 13
diff --git a/drivers/dma-buf/Makefile b/drivers/dma-buf/Makefile
index 210a10bfad2b..c33bf8863147 100644
--- a/drivers/dma-buf/Makefile
+++ b/drivers/dma-buf/Makefile
@@ -1,3 +1,3 @@
1obj-y := dma-buf.o fence.o reservation.o seqno-fence.o fence-array.o 1obj-y := dma-buf.o dma-fence.o dma-fence-array.o reservation.o seqno-fence.o
2obj-$(CONFIG_SYNC_FILE) += sync_file.o 2obj-$(CONFIG_SYNC_FILE) += sync_file.o
3obj-$(CONFIG_SW_SYNC) += sw_sync.o sync_debug.o 3obj-$(CONFIG_SW_SYNC) += sw_sync.o sync_debug.o
diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
index cf04d249a6a4..e72e64484131 100644
--- a/drivers/dma-buf/dma-buf.c
+++ b/drivers/dma-buf/dma-buf.c
@@ -25,7 +25,7 @@
25#include <linux/fs.h> 25#include <linux/fs.h>
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/dma-buf.h> 27#include <linux/dma-buf.h>
28#include <linux/fence.h> 28#include <linux/dma-fence.h>
29#include <linux/anon_inodes.h> 29#include <linux/anon_inodes.h>
30#include <linux/export.h> 30#include <linux/export.h>
31#include <linux/debugfs.h> 31#include <linux/debugfs.h>
@@ -124,7 +124,7 @@ static loff_t dma_buf_llseek(struct file *file, loff_t offset, int whence)
124 return base + offset; 124 return base + offset;
125} 125}
126 126
127static void dma_buf_poll_cb(struct fence *fence, struct fence_cb *cb) 127static void dma_buf_poll_cb(struct dma_fence *fence, struct dma_fence_cb *cb)
128{ 128{
129 struct dma_buf_poll_cb_t *dcb = (struct dma_buf_poll_cb_t *)cb; 129 struct dma_buf_poll_cb_t *dcb = (struct dma_buf_poll_cb_t *)cb;
130 unsigned long flags; 130 unsigned long flags;
@@ -140,7 +140,7 @@ static unsigned int dma_buf_poll(struct file *file, poll_table *poll)
140 struct dma_buf *dmabuf; 140 struct dma_buf *dmabuf;
141 struct reservation_object *resv; 141 struct reservation_object *resv;
142 struct reservation_object_list *fobj; 142 struct reservation_object_list *fobj;
143 struct fence *fence_excl; 143 struct dma_fence *fence_excl;
144 unsigned long events; 144 unsigned long events;
145 unsigned shared_count, seq; 145 unsigned shared_count, seq;
146 146
@@ -187,20 +187,20 @@ retry:
187 spin_unlock_irq(&dmabuf->poll.lock); 187 spin_unlock_irq(&dmabuf->poll.lock);
188 188
189 if (events & pevents) { 189 if (events & pevents) {
190 if (!fence_get_rcu(fence_excl)) { 190 if (!dma_fence_get_rcu(fence_excl)) {
191 /* force a recheck */ 191 /* force a recheck */
192 events &= ~pevents; 192 events &= ~pevents;
193 dma_buf_poll_cb(NULL, &dcb->cb); 193 dma_buf_poll_cb(NULL, &dcb->cb);
194 } else if (!fence_add_callback(fence_excl, &dcb->cb, 194 } else if (!dma_fence_add_callback(fence_excl, &dcb->cb,
195 dma_buf_poll_cb)) { 195 dma_buf_poll_cb)) {
196 events &= ~pevents; 196 events &= ~pevents;
197 fence_put(fence_excl); 197 dma_fence_put(fence_excl);
198 } else { 198 } else {
199 /* 199 /*
200 * No callback queued, wake up any additional 200 * No callback queued, wake up any additional
201 * waiters. 201 * waiters.
202 */ 202 */
203 fence_put(fence_excl); 203 dma_fence_put(fence_excl);
204 dma_buf_poll_cb(NULL, &dcb->cb); 204 dma_buf_poll_cb(NULL, &dcb->cb);
205 } 205 }
206 } 206 }
@@ -222,9 +222,9 @@ retry:
222 goto out; 222 goto out;
223 223
224 for (i = 0; i < shared_count; ++i) { 224 for (i = 0; i < shared_count; ++i) {
225 struct fence *fence = rcu_dereference(fobj->shared[i]); 225 struct dma_fence *fence = rcu_dereference(fobj->shared[i]);
226 226
227 if (!fence_get_rcu(fence)) { 227 if (!dma_fence_get_rcu(fence)) {
228 /* 228 /*
229 * fence refcount dropped to zero, this means 229 * fence refcount dropped to zero, this means
230 * that fobj has been freed 230 * that fobj has been freed
@@ -235,13 +235,13 @@ retry:
235 dma_buf_poll_cb(NULL, &dcb->cb); 235 dma_buf_poll_cb(NULL, &dcb->cb);
236 break; 236 break;
237 } 237 }
238 if (!fence_add_callback(fence, &dcb->cb, 238 if (!dma_fence_add_callback(fence, &dcb->cb,
239 dma_buf_poll_cb)) { 239 dma_buf_poll_cb)) {
240 fence_put(fence); 240 dma_fence_put(fence);
241 events &= ~POLLOUT; 241 events &= ~POLLOUT;
242 break; 242 break;
243 } 243 }
244 fence_put(fence); 244 dma_fence_put(fence);
245 } 245 }
246 246
247 /* No callback queued, wake up any additional waiters. */ 247 /* No callback queued, wake up any additional waiters. */
diff --git a/drivers/dma-buf/fence-array.c b/drivers/dma-buf/dma-fence-array.c
index f1989fcaf354..67eb7c8fb88c 100644
--- a/drivers/dma-buf/fence-array.c
+++ b/drivers/dma-buf/dma-fence-array.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * fence-array: aggregate fences to be waited together 2 * dma-fence-array: aggregate fences to be waited together
3 * 3 *
4 * Copyright (C) 2016 Collabora Ltd 4 * Copyright (C) 2016 Collabora Ltd
5 * Copyright (C) 2016 Advanced Micro Devices, Inc. 5 * Copyright (C) 2016 Advanced Micro Devices, Inc.
@@ -19,35 +19,34 @@
19 19
20#include <linux/export.h> 20#include <linux/export.h>
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/fence-array.h> 22#include <linux/dma-fence-array.h>
23 23
24static void fence_array_cb_func(struct fence *f, struct fence_cb *cb); 24static const char *dma_fence_array_get_driver_name(struct dma_fence *fence)
25
26static const char *fence_array_get_driver_name(struct fence *fence)
27{ 25{
28 return "fence_array"; 26 return "dma_fence_array";
29} 27}
30 28
31static const char *fence_array_get_timeline_name(struct fence *fence) 29static const char *dma_fence_array_get_timeline_name(struct dma_fence *fence)
32{ 30{
33 return "unbound"; 31 return "unbound";
34} 32}
35 33
36static void fence_array_cb_func(struct fence *f, struct fence_cb *cb) 34static void dma_fence_array_cb_func(struct dma_fence *f,
35 struct dma_fence_cb *cb)
37{ 36{
38 struct fence_array_cb *array_cb = 37 struct dma_fence_array_cb *array_cb =
39 container_of(cb, struct fence_array_cb, cb); 38 container_of(cb, struct dma_fence_array_cb, cb);
40 struct fence_array *array = array_cb->array; 39 struct dma_fence_array *array = array_cb->array;
41 40
42 if (atomic_dec_and_test(&array->num_pending)) 41 if (atomic_dec_and_test(&array->num_pending))
43 fence_signal(&array->base); 42 dma_fence_signal(&array->base);
44 fence_put(&array->base); 43 dma_fence_put(&array->base);
45} 44}
46 45
47static bool fence_array_enable_signaling(struct fence *fence) 46static bool dma_fence_array_enable_signaling(struct dma_fence *fence)
48{ 47{
49 struct fence_array *array = to_fence_array(fence); 48 struct dma_fence_array *array = to_dma_fence_array(fence);
50 struct fence_array_cb *cb = (void *)(&array[1]); 49 struct dma_fence_array_cb *cb = (void *)(&array[1]);
51 unsigned i; 50 unsigned i;
52 51
53 for (i = 0; i < array->num_fences; ++i) { 52 for (i = 0; i < array->num_fences; ++i) {
@@ -60,10 +59,10 @@ static bool fence_array_enable_signaling(struct fence *fence)
60 * until we signal the array as complete (but that is now 59 * until we signal the array as complete (but that is now
61 * insufficient). 60 * insufficient).
62 */ 61 */
63 fence_get(&array->base); 62 dma_fence_get(&array->base);
64 if (fence_add_callback(array->fences[i], &cb[i].cb, 63 if (dma_fence_add_callback(array->fences[i], &cb[i].cb,
65 fence_array_cb_func)) { 64 dma_fence_array_cb_func)) {
66 fence_put(&array->base); 65 dma_fence_put(&array->base);
67 if (atomic_dec_and_test(&array->num_pending)) 66 if (atomic_dec_and_test(&array->num_pending))
68 return false; 67 return false;
69 } 68 }
@@ -72,69 +71,71 @@ static bool fence_array_enable_signaling(struct fence *fence)
72 return true; 71 return true;
73} 72}
74 73
75static bool fence_array_signaled(struct fence *fence) 74static bool dma_fence_array_signaled(struct dma_fence *fence)
76{ 75{
77 struct fence_array *array = to_fence_array(fence); 76 struct dma_fence_array *array = to_dma_fence_array(fence);
78 77
79 return atomic_read(&array->num_pending) <= 0; 78 return atomic_read(&array->num_pending) <= 0;
80} 79}
81 80
82static void fence_array_release(struct fence *fence) 81static void dma_fence_array_release(struct dma_fence *fence)
83{ 82{
84 struct fence_array *array = to_fence_array(fence); 83 struct dma_fence_array *array = to_dma_fence_array(fence);
85 unsigned i; 84 unsigned i;
86 85
87 for (i = 0; i < array->num_fences; ++i) 86 for (i = 0; i < array->num_fences; ++i)
88 fence_put(array->fences[i]); 87 dma_fence_put(array->fences[i]);
89 88
90 kfree(array->fences); 89 kfree(array->fences);
91 fence_free(fence); 90 dma_fence_free(fence);
92} 91}
93 92
94const struct fence_ops fence_array_ops = { 93const struct dma_fence_ops dma_fence_array_ops = {
95 .get_driver_name = fence_array_get_driver_name, 94 .get_driver_name = dma_fence_array_get_driver_name,
96 .get_timeline_name = fence_array_get_timeline_name, 95 .get_timeline_name = dma_fence_array_get_timeline_name,
97 .enable_signaling = fence_array_enable_signaling, 96 .enable_signaling = dma_fence_array_enable_signaling,
98 .signaled = fence_array_signaled, 97 .signaled = dma_fence_array_signaled,
99 .wait = fence_default_wait, 98 .wait = dma_fence_default_wait,
100 .release = fence_array_release, 99 .release = dma_fence_array_release,
101}; 100};
102EXPORT_SYMBOL(fence_array_ops); 101EXPORT_SYMBOL(dma_fence_array_ops);
103 102
104/** 103/**
105 * fence_array_create - Create a custom fence array 104 * dma_fence_array_create - Create a custom fence array
106 * @num_fences: [in] number of fences to add in the array 105 * @num_fences: [in] number of fences to add in the array
107 * @fences: [in] array containing the fences 106 * @fences: [in] array containing the fences
108 * @context: [in] fence context to use 107 * @context: [in] fence context to use
109 * @seqno: [in] sequence number to use 108 * @seqno: [in] sequence number to use
110 * @signal_on_any: [in] signal on any fence in the array 109 * @signal_on_any: [in] signal on any fence in the array
111 * 110 *
112 * Allocate a fence_array object and initialize the base fence with fence_init(). 111 * Allocate a dma_fence_array object and initialize the base fence with
112 * dma_fence_init().
113 * In case of error it returns NULL. 113 * In case of error it returns NULL.
114 * 114 *
115 * The caller should allocate the fences array with num_fences size 115 * The caller should allocate the fences array with num_fences size
116 * and fill it with the fences it wants to add to the object. Ownership of this 116 * and fill it with the fences it wants to add to the object. Ownership of this
117 * array is taken and fence_put() is used on each fence on release. 117 * array is taken and dma_fence_put() is used on each fence on release.
118 * 118 *
119 * If @signal_on_any is true the fence array signals if any fence in the array 119 * If @signal_on_any is true the fence array signals if any fence in the array
120 * signals, otherwise it signals when all fences in the array signal. 120 * signals, otherwise it signals when all fences in the array signal.
121 */ 121 */
122struct fence_array *fence_array_create(int num_fences, struct fence **fences, 122struct dma_fence_array *dma_fence_array_create(int num_fences,
123 u64 context, unsigned seqno, 123 struct dma_fence **fences,
124 bool signal_on_any) 124 u64 context, unsigned seqno,
125 bool signal_on_any)
125{ 126{
126 struct fence_array *array; 127 struct dma_fence_array *array;
127 size_t size = sizeof(*array); 128 size_t size = sizeof(*array);
128 129
129 /* Allocate the callback structures behind the array. */ 130 /* Allocate the callback structures behind the array. */
130 size += num_fences * sizeof(struct fence_array_cb); 131 size += num_fences * sizeof(struct dma_fence_array_cb);
131 array = kzalloc(size, GFP_KERNEL); 132 array = kzalloc(size, GFP_KERNEL);
132 if (!array) 133 if (!array)
133 return NULL; 134 return NULL;
134 135
135 spin_lock_init(&array->lock); 136 spin_lock_init(&array->lock);
136 fence_init(&array->base, &fence_array_ops, &array->lock, 137 dma_fence_init(&array->base, &dma_fence_array_ops, &array->lock,
137 context, seqno); 138 context, seqno);
138 139
139 array->num_fences = num_fences; 140 array->num_fences = num_fences;
140 atomic_set(&array->num_pending, signal_on_any ? 1 : num_fences); 141 atomic_set(&array->num_pending, signal_on_any ? 1 : num_fences);
@@ -142,4 +143,4 @@ struct fence_array *fence_array_create(int num_fences, struct fence **fences,
142 143
143 return array; 144 return array;
144} 145}
145EXPORT_SYMBOL(fence_array_create); 146EXPORT_SYMBOL(dma_fence_array_create);
diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/dma-fence.c
index cc05dddc77a6..3a7bf009c21c 100644
--- a/drivers/dma-buf/fence.c
+++ b/drivers/dma-buf/dma-fence.c
@@ -21,13 +21,13 @@
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/export.h> 22#include <linux/export.h>
23#include <linux/atomic.h> 23#include <linux/atomic.h>
24#include <linux/fence.h> 24#include <linux/dma-fence.h>
25 25
26#define CREATE_TRACE_POINTS 26#define CREATE_TRACE_POINTS
27#include <trace/events/fence.h> 27#include <trace/events/dma_fence.h>
28 28
29EXPORT_TRACEPOINT_SYMBOL(fence_annotate_wait_on); 29EXPORT_TRACEPOINT_SYMBOL(dma_fence_annotate_wait_on);
30EXPORT_TRACEPOINT_SYMBOL(fence_emit); 30EXPORT_TRACEPOINT_SYMBOL(dma_fence_emit);
31 31
32/* 32/*
33 * fence context counter: each execution context should have its own 33 * fence context counter: each execution context should have its own
@@ -35,37 +35,37 @@ EXPORT_TRACEPOINT_SYMBOL(fence_emit);
35 * context or not. One device can have multiple separate contexts, 35 * context or not. One device can have multiple separate contexts,
36 * and they're used if some engine can run independently of another. 36 * and they're used if some engine can run independently of another.
37 */ 37 */
38static atomic64_t fence_context_counter = ATOMIC64_INIT(0); 38static atomic64_t dma_fence_context_counter = ATOMIC64_INIT(0);
39 39
40/** 40/**
41 * fence_context_alloc - allocate an array of fence contexts 41 * dma_fence_context_alloc - allocate an array of fence contexts
42 * @num: [in] amount of contexts to allocate 42 * @num: [in] amount of contexts to allocate
43 * 43 *
44 * This function will return the first index of the number of fences allocated. 44 * This function will return the first index of the number of fences allocated.
45 * The fence context is used for setting fence->context to a unique number. 45 * The fence context is used for setting fence->context to a unique number.
46 */ 46 */
47u64 fence_context_alloc(unsigned num) 47u64 dma_fence_context_alloc(unsigned num)
48{ 48{
49 BUG_ON(!num); 49 BUG_ON(!num);
50 return atomic64_add_return(num, &fence_context_counter) - num; 50 return atomic64_add_return(num, &dma_fence_context_counter) - num;
51} 51}
52EXPORT_SYMBOL(fence_context_alloc); 52EXPORT_SYMBOL(dma_fence_context_alloc);
53 53
54/** 54/**
55 * fence_signal_locked - signal completion of a fence 55 * dma_fence_signal_locked - signal completion of a fence
56 * @fence: the fence to signal 56 * @fence: the fence to signal
57 * 57 *
58 * Signal completion for software callbacks on a fence, this will unblock 58 * Signal completion for software callbacks on a fence, this will unblock
59 * fence_wait() calls and run all the callbacks added with 59 * dma_fence_wait() calls and run all the callbacks added with
60 * fence_add_callback(). Can be called multiple times, but since a fence 60 * dma_fence_add_callback(). Can be called multiple times, but since a fence
61 * can only go from unsignaled to signaled state, it will only be effective 61 * can only go from unsignaled to signaled state, it will only be effective
62 * the first time. 62 * the first time.
63 * 63 *
64 * Unlike fence_signal, this function must be called with fence->lock held. 64 * Unlike dma_fence_signal, this function must be called with fence->lock held.
65 */ 65 */
66int fence_signal_locked(struct fence *fence) 66int dma_fence_signal_locked(struct dma_fence *fence)
67{ 67{
68 struct fence_cb *cur, *tmp; 68 struct dma_fence_cb *cur, *tmp;
69 int ret = 0; 69 int ret = 0;
70 70
71 lockdep_assert_held(fence->lock); 71 lockdep_assert_held(fence->lock);
@@ -78,15 +78,15 @@ int fence_signal_locked(struct fence *fence)
78 smp_mb__before_atomic(); 78 smp_mb__before_atomic();
79 } 79 }
80 80
81 if (test_and_set_bit(FENCE_FLAG_SIGNALED_BIT, &fence->flags)) { 81 if (test_and_set_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) {
82 ret = -EINVAL; 82 ret = -EINVAL;
83 83
84 /* 84 /*
85 * we might have raced with the unlocked fence_signal, 85 * we might have raced with the unlocked dma_fence_signal,
86 * still run through all callbacks 86 * still run through all callbacks
87 */ 87 */
88 } else 88 } else
89 trace_fence_signaled(fence); 89 trace_dma_fence_signaled(fence);
90 90
91 list_for_each_entry_safe(cur, tmp, &fence->cb_list, node) { 91 list_for_each_entry_safe(cur, tmp, &fence->cb_list, node) {
92 list_del_init(&cur->node); 92 list_del_init(&cur->node);
@@ -94,19 +94,19 @@ int fence_signal_locked(struct fence *fence)
94 } 94 }
95 return ret; 95 return ret;
96} 96}
97EXPORT_SYMBOL(fence_signal_locked); 97EXPORT_SYMBOL(dma_fence_signal_locked);
98 98
99/** 99/**
100 * fence_signal - signal completion of a fence 100 * dma_fence_signal - signal completion of a fence
101 * @fence: the fence to signal 101 * @fence: the fence to signal
102 * 102 *
103 * Signal completion for software callbacks on a fence, this will unblock 103 * Signal completion for software callbacks on a fence, this will unblock
104 * fence_wait() calls and run all the callbacks added with 104 * dma_fence_wait() calls and run all the callbacks added with
105 * fence_add_callback(). Can be called multiple times, but since a fence 105 * dma_fence_add_callback(). Can be called multiple times, but since a fence
106 * can only go from unsignaled to signaled state, it will only be effective 106 * can only go from unsignaled to signaled state, it will only be effective
107 * the first time. 107 * the first time.
108 */ 108 */
109int fence_signal(struct fence *fence) 109int dma_fence_signal(struct dma_fence *fence)
110{ 110{
111 unsigned long flags; 111 unsigned long flags;
112 112
@@ -118,13 +118,13 @@ int fence_signal(struct fence *fence)
118 smp_mb__before_atomic(); 118 smp_mb__before_atomic();
119 } 119 }
120 120
121 if (test_and_set_bit(FENCE_FLAG_SIGNALED_BIT, &fence->flags)) 121 if (test_and_set_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))
122 return -EINVAL; 122 return -EINVAL;
123 123
124 trace_fence_signaled(fence); 124 trace_dma_fence_signaled(fence);
125 125
126 if (test_bit(FENCE_FLAG_ENABLE_SIGNAL_BIT, &fence->flags)) { 126 if (test_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT, &fence->flags)) {
127 struct fence_cb *cur, *tmp; 127 struct dma_fence_cb *cur, *tmp;
128 128
129 spin_lock_irqsave(fence->lock, flags); 129 spin_lock_irqsave(fence->lock, flags);
130 list_for_each_entry_safe(cur, tmp, &fence->cb_list, node) { 130 list_for_each_entry_safe(cur, tmp, &fence->cb_list, node) {
@@ -135,10 +135,10 @@ int fence_signal(struct fence *fence)
135 } 135 }
136 return 0; 136 return 0;
137} 137}
138EXPORT_SYMBOL(fence_signal); 138EXPORT_SYMBOL(dma_fence_signal);
139 139
140/** 140/**
141 * fence_wait_timeout - sleep until the fence gets signaled 141 * dma_fence_wait_timeout - sleep until the fence gets signaled
142 * or until timeout elapses 142 * or until timeout elapses
143 * @fence: [in] the fence to wait on 143 * @fence: [in] the fence to wait on
144 * @intr: [in] if true, do an interruptible wait 144 * @intr: [in] if true, do an interruptible wait
@@ -154,7 +154,7 @@ EXPORT_SYMBOL(fence_signal);
154 * freed before return, resulting in undefined behavior. 154 * freed before return, resulting in undefined behavior.
155 */ 155 */
156signed long 156signed long
157fence_wait_timeout(struct fence *fence, bool intr, signed long timeout) 157dma_fence_wait_timeout(struct dma_fence *fence, bool intr, signed long timeout)
158{ 158{
159 signed long ret; 159 signed long ret;
160 160
@@ -162,70 +162,71 @@ fence_wait_timeout(struct fence *fence, bool intr, signed long timeout)
162 return -EINVAL; 162 return -EINVAL;
163 163
164 if (timeout == 0) 164 if (timeout == 0)
165 return fence_is_signaled(fence); 165 return dma_fence_is_signaled(fence);
166 166
167 trace_fence_wait_start(fence); 167 trace_dma_fence_wait_start(fence);
168 ret = fence->ops->wait(fence, intr, timeout); 168 ret = fence->ops->wait(fence, intr, timeout);
169 trace_fence_wait_end(fence); 169 trace_dma_fence_wait_end(fence);
170 return ret; 170 return ret;
171} 171}
172EXPORT_SYMBOL(fence_wait_timeout); 172EXPORT_SYMBOL(dma_fence_wait_timeout);
173 173
174void fence_release(struct kref *kref) 174void dma_fence_release(struct kref *kref)
175{ 175{
176 struct fence *fence = 176 struct dma_fence *fence =
177 container_of(kref, struct fence, refcount); 177 container_of(kref, struct dma_fence, refcount);
178 178
179 trace_fence_destroy(fence); 179 trace_dma_fence_destroy(fence);
180 180
181 BUG_ON(!list_empty(&fence->cb_list)); 181 BUG_ON(!list_empty(&fence->cb_list));
182 182
183 if (fence->ops->release) 183 if (fence->ops->release)
184 fence->ops->release(fence); 184 fence->ops->release(fence);
185 else 185 else
186 fence_free(fence); 186 dma_fence_free(fence);
187} 187}
188EXPORT_SYMBOL(fence_release); 188EXPORT_SYMBOL(dma_fence_release);
189 189
190void fence_free(struct fence *fence) 190void dma_fence_free(struct dma_fence *fence)
191{ 191{
192 kfree_rcu(fence, rcu); 192 kfree_rcu(fence, rcu);
193} 193}
194EXPORT_SYMBOL(fence_free); 194EXPORT_SYMBOL(dma_fence_free);
195 195
196/** 196/**
197 * fence_enable_sw_signaling - enable signaling on fence 197 * dma_fence_enable_sw_signaling - enable signaling on fence
198 * @fence: [in] the fence to enable 198 * @fence: [in] the fence to enable
199 * 199 *
200 * this will request for sw signaling to be enabled, to make the fence 200 * this will request for sw signaling to be enabled, to make the fence
201 * complete as soon as possible 201 * complete as soon as possible
202 */ 202 */
203void fence_enable_sw_signaling(struct fence *fence) 203void dma_fence_enable_sw_signaling(struct dma_fence *fence)
204{ 204{
205 unsigned long flags; 205 unsigned long flags;
206 206
207 if (!test_and_set_bit(FENCE_FLAG_ENABLE_SIGNAL_BIT, &fence->flags) && 207 if (!test_and_set_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT,
208 !test_bit(FENCE_FLAG_SIGNALED_BIT, &fence->flags)) { 208 &fence->flags) &&
209 trace_fence_enable_signal(fence); 209 !test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) {
210 trace_dma_fence_enable_signal(fence);
210 211
211 spin_lock_irqsave(fence->lock, flags); 212 spin_lock_irqsave(fence->lock, flags);
212 213
213 if (!fence->ops->enable_signaling(fence)) 214 if (!fence->ops->enable_signaling(fence))
214 fence_signal_locked(fence); 215 dma_fence_signal_locked(fence);
215 216
216 spin_unlock_irqrestore(fence->lock, flags); 217 spin_unlock_irqrestore(fence->lock, flags);
217 } 218 }
218} 219}
219EXPORT_SYMBOL(fence_enable_sw_signaling); 220EXPORT_SYMBOL(dma_fence_enable_sw_signaling);
220 221
221/** 222/**
222 * fence_add_callback - add a callback to be called when the fence 223 * dma_fence_add_callback - add a callback to be called when the fence
223 * is signaled 224 * is signaled
224 * @fence: [in] the fence to wait on 225 * @fence: [in] the fence to wait on
225 * @cb: [in] the callback to register 226 * @cb: [in] the callback to register
226 * @func: [in] the function to call 227 * @func: [in] the function to call
227 * 228 *
228 * cb will be initialized by fence_add_callback, no initialization 229 * cb will be initialized by dma_fence_add_callback, no initialization
229 * by the caller is required. Any number of callbacks can be registered 230 * by the caller is required. Any number of callbacks can be registered
230 * to a fence, but a callback can only be registered to one fence at a time. 231 * to a fence, but a callback can only be registered to one fence at a time.
231 * 232 *
@@ -234,15 +235,15 @@ EXPORT_SYMBOL(fence_enable_sw_signaling);
234 * *not* call the callback) 235 * *not* call the callback)
235 * 236 *
236 * Add a software callback to the fence. Same restrictions apply to 237 * Add a software callback to the fence. Same restrictions apply to
237 * refcount as it does to fence_wait, however the caller doesn't need to 238 * refcount as it does to dma_fence_wait, however the caller doesn't need to
238 * keep a refcount to fence afterwards: when software access is enabled, 239 * keep a refcount to fence afterwards: when software access is enabled,
239 * the creator of the fence is required to keep the fence alive until 240 * the creator of the fence is required to keep the fence alive until
240 * after it signals with fence_signal. The callback itself can be called 241 * after it signals with dma_fence_signal. The callback itself can be called
241 * from irq context. 242 * from irq context.
242 * 243 *
243 */ 244 */
244int fence_add_callback(struct fence *fence, struct fence_cb *cb, 245int dma_fence_add_callback(struct dma_fence *fence, struct dma_fence_cb *cb,
245 fence_func_t func) 246 dma_fence_func_t func)
246{ 247{
247 unsigned long flags; 248 unsigned long flags;
248 int ret = 0; 249 int ret = 0;
@@ -251,22 +252,23 @@ int fence_add_callback(struct fence *fence, struct fence_cb *cb,
251 if (WARN_ON(!fence || !func)) 252 if (WARN_ON(!fence || !func))
252 return -EINVAL; 253 return -EINVAL;
253 254
254 if (test_bit(FENCE_FLAG_SIGNALED_BIT, &fence->flags)) { 255 if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) {
255 INIT_LIST_HEAD(&cb->node); 256 INIT_LIST_HEAD(&cb->node);
256 return -ENOENT; 257 return -ENOENT;
257 } 258 }
258 259
259 spin_lock_irqsave(fence->lock, flags); 260 spin_lock_irqsave(fence->lock, flags);
260 261
261 was_set = test_and_set_bit(FENCE_FLAG_ENABLE_SIGNAL_BIT, &fence->flags); 262 was_set = test_and_set_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT,
263 &fence->flags);
262 264
263 if (test_bit(FENCE_FLAG_SIGNALED_BIT, &fence->flags)) 265 if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))
264 ret = -ENOENT; 266 ret = -ENOENT;
265 else if (!was_set) { 267 else if (!was_set) {
266 trace_fence_enable_signal(fence); 268 trace_dma_fence_enable_signal(fence);
267 269
268 if (!fence->ops->enable_signaling(fence)) { 270 if (!fence->ops->enable_signaling(fence)) {
269 fence_signal_locked(fence); 271 dma_fence_signal_locked(fence);
270 ret = -ENOENT; 272 ret = -ENOENT;
271 } 273 }
272 } 274 }
@@ -280,10 +282,10 @@ int fence_add_callback(struct fence *fence, struct fence_cb *cb,
280 282
281 return ret; 283 return ret;
282} 284}
283EXPORT_SYMBOL(fence_add_callback); 285EXPORT_SYMBOL(dma_fence_add_callback);
284 286
285/** 287/**
286 * fence_remove_callback - remove a callback from the signaling list 288 * dma_fence_remove_callback - remove a callback from the signaling list
287 * @fence: [in] the fence to wait on 289 * @fence: [in] the fence to wait on
288 * @cb: [in] the callback to remove 290 * @cb: [in] the callback to remove
289 * 291 *
@@ -298,7 +300,7 @@ EXPORT_SYMBOL(fence_add_callback);
298 * with a reference held to the fence. 300 * with a reference held to the fence.
299 */ 301 */
300bool 302bool
301fence_remove_callback(struct fence *fence, struct fence_cb *cb) 303dma_fence_remove_callback(struct dma_fence *fence, struct dma_fence_cb *cb)
302{ 304{
303 unsigned long flags; 305 unsigned long flags;
304 bool ret; 306 bool ret;
@@ -313,15 +315,15 @@ fence_remove_callback(struct fence *fence, struct fence_cb *cb)
313 315
314 return ret; 316 return ret;
315} 317}
316EXPORT_SYMBOL(fence_remove_callback); 318EXPORT_SYMBOL(dma_fence_remove_callback);
317 319
318struct default_wait_cb { 320struct default_wait_cb {
319 struct fence_cb base; 321 struct dma_fence_cb base;
320 struct task_struct *task; 322 struct task_struct *task;
321}; 323};
322 324
323static void 325static void
324fence_default_wait_cb(struct fence *fence, struct fence_cb *cb) 326dma_fence_default_wait_cb(struct dma_fence *fence, struct dma_fence_cb *cb)
325{ 327{
326 struct default_wait_cb *wait = 328 struct default_wait_cb *wait =
327 container_of(cb, struct default_wait_cb, base); 329 container_of(cb, struct default_wait_cb, base);
@@ -330,7 +332,7 @@ fence_default_wait_cb(struct fence *fence, struct fence_cb *cb)
330} 332}
331 333
332/** 334/**
333 * fence_default_wait - default sleep until the fence gets signaled 335 * dma_fence_default_wait - default sleep until the fence gets signaled
334 * or until timeout elapses 336 * or until timeout elapses
335 * @fence: [in] the fence to wait on 337 * @fence: [in] the fence to wait on
336 * @intr: [in] if true, do an interruptible wait 338 * @intr: [in] if true, do an interruptible wait
@@ -340,14 +342,14 @@ fence_default_wait_cb(struct fence *fence, struct fence_cb *cb)
340 * remaining timeout in jiffies on success. 342 * remaining timeout in jiffies on success.
341 */ 343 */
342signed long 344signed long
343fence_default_wait(struct fence *fence, bool intr, signed long timeout) 345dma_fence_default_wait(struct dma_fence *fence, bool intr, signed long timeout)
344{ 346{
345 struct default_wait_cb cb; 347 struct default_wait_cb cb;
346 unsigned long flags; 348 unsigned long flags;
347 signed long ret = timeout; 349 signed long ret = timeout;
348 bool was_set; 350 bool was_set;
349 351
350 if (test_bit(FENCE_FLAG_SIGNALED_BIT, &fence->flags)) 352 if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))
351 return timeout; 353 return timeout;
352 354
353 spin_lock_irqsave(fence->lock, flags); 355 spin_lock_irqsave(fence->lock, flags);
@@ -357,25 +359,26 @@ fence_default_wait(struct fence *fence, bool intr, signed long timeout)
357 goto out; 359 goto out;
358 } 360 }
359 361
360 was_set = test_and_set_bit(FENCE_FLAG_ENABLE_SIGNAL_BIT, &fence->flags); 362 was_set = test_and_set_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT,
363 &fence->flags);
361 364
362 if (test_bit(FENCE_FLAG_SIGNALED_BIT, &fence->flags)) 365 if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))
363 goto out; 366 goto out;
364 367
365 if (!was_set) { 368 if (!was_set) {
366 trace_fence_enable_signal(fence); 369 trace_dma_fence_enable_signal(fence);
367 370
368 if (!fence->ops->enable_signaling(fence)) { 371 if (!fence->ops->enable_signaling(fence)) {
369 fence_signal_locked(fence); 372 dma_fence_signal_locked(fence);
370 goto out; 373 goto out;
371 } 374 }
372 } 375 }
373 376
374 cb.base.func = fence_default_wait_cb; 377 cb.base.func = dma_fence_default_wait_cb;
375 cb.task = current; 378 cb.task = current;
376 list_add(&cb.base.node, &fence->cb_list); 379 list_add(&cb.base.node, &fence->cb_list);
377 380
378 while (!test_bit(FENCE_FLAG_SIGNALED_BIT, &fence->flags) && ret > 0) { 381 while (!test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags) && ret > 0) {
379 if (intr) 382 if (intr)
380 __set_current_state(TASK_INTERRUPTIBLE); 383 __set_current_state(TASK_INTERRUPTIBLE);
381 else 384 else
@@ -397,23 +400,23 @@ out:
397 spin_unlock_irqrestore(fence->lock, flags); 400 spin_unlock_irqrestore(fence->lock, flags);
398 return ret; 401 return ret;
399} 402}
400EXPORT_SYMBOL(fence_default_wait); 403EXPORT_SYMBOL(dma_fence_default_wait);
401 404
402static bool 405static bool
403fence_test_signaled_any(struct fence **fences, uint32_t count) 406dma_fence_test_signaled_any(struct dma_fence **fences, uint32_t count)
404{ 407{
405 int i; 408 int i;
406 409
407 for (i = 0; i < count; ++i) { 410 for (i = 0; i < count; ++i) {
408 struct fence *fence = fences[i]; 411 struct dma_fence *fence = fences[i];
409 if (test_bit(FENCE_FLAG_SIGNALED_BIT, &fence->flags)) 412 if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags))
410 return true; 413 return true;
411 } 414 }
412 return false; 415 return false;
413} 416}
414 417
415/** 418/**
416 * fence_wait_any_timeout - sleep until any fence gets signaled 419 * dma_fence_wait_any_timeout - sleep until any fence gets signaled
417 * or until timeout elapses 420 * or until timeout elapses
418 * @fences: [in] array of fences to wait on 421 * @fences: [in] array of fences to wait on
419 * @count: [in] number of fences to wait on 422 * @count: [in] number of fences to wait on
@@ -429,8 +432,8 @@ fence_test_signaled_any(struct fence **fences, uint32_t count)
429 * fence might be freed before return, resulting in undefined behavior. 432 * fence might be freed before return, resulting in undefined behavior.
430 */ 433 */
431signed long 434signed long
432fence_wait_any_timeout(struct fence **fences, uint32_t count, 435dma_fence_wait_any_timeout(struct dma_fence **fences, uint32_t count,
433 bool intr, signed long timeout) 436 bool intr, signed long timeout)
434{ 437{
435 struct default_wait_cb *cb; 438 struct default_wait_cb *cb;
436 signed long ret = timeout; 439 signed long ret = timeout;
@@ -441,7 +444,7 @@ fence_wait_any_timeout(struct fence **fences, uint32_t count,
441 444
442 if (timeout == 0) { 445 if (timeout == 0) {
443 for (i = 0; i < count; ++i) 446 for (i = 0; i < count; ++i)
444 if (fence_is_signaled(fences[i])) 447 if (dma_fence_is_signaled(fences[i]))
445 return 1; 448 return 1;
446 449
447 return 0; 450 return 0;
@@ -454,16 +457,16 @@ fence_wait_any_timeout(struct fence **fences, uint32_t count,
454 } 457 }
455 458
456 for (i = 0; i < count; ++i) { 459 for (i = 0; i < count; ++i) {
457 struct fence *fence = fences[i]; 460 struct dma_fence *fence = fences[i];
458 461
459 if (fence->ops->wait != fence_default_wait) { 462 if (fence->ops->wait != dma_fence_default_wait) {
460 ret = -EINVAL; 463 ret = -EINVAL;
461 goto fence_rm_cb; 464 goto fence_rm_cb;
462 } 465 }
463 466
464 cb[i].task = current; 467 cb[i].task = current;
465 if (fence_add_callback(fence, &cb[i].base, 468 if (dma_fence_add_callback(fence, &cb[i].base,
466 fence_default_wait_cb)) { 469 dma_fence_default_wait_cb)) {
467 /* This fence is already signaled */ 470 /* This fence is already signaled */
468 goto fence_rm_cb; 471 goto fence_rm_cb;
469 } 472 }
@@ -475,7 +478,7 @@ fence_wait_any_timeout(struct fence **fences, uint32_t count,
475 else 478 else
476 set_current_state(TASK_UNINTERRUPTIBLE); 479 set_current_state(TASK_UNINTERRUPTIBLE);
477 480
478 if (fence_test_signaled_any(fences, count)) 481 if (dma_fence_test_signaled_any(fences, count))
479 break; 482 break;
480 483
481 ret = schedule_timeout(ret); 484 ret = schedule_timeout(ret);
@@ -488,34 +491,34 @@ fence_wait_any_timeout(struct fence **fences, uint32_t count,
488 491
489fence_rm_cb: 492fence_rm_cb:
490 while (i-- > 0) 493 while (i-- > 0)
491 fence_remove_callback(fences[i], &cb[i].base); 494 dma_fence_remove_callback(fences[i], &cb[i].base);
492 495
493err_free_cb: 496err_free_cb:
494 kfree(cb); 497 kfree(cb);
495 498
496 return ret; 499 return ret;
497} 500}
498EXPORT_SYMBOL(fence_wait_any_timeout); 501EXPORT_SYMBOL(dma_fence_wait_any_timeout);
499 502
500/** 503/**
501 * fence_init - Initialize a custom fence. 504 * dma_fence_init - Initialize a custom fence.
502 * @fence: [in] the fence to initialize 505 * @fence: [in] the fence to initialize
503 * @ops: [in] the fence_ops for operations on this fence 506 * @ops: [in] the dma_fence_ops for operations on this fence
504 * @lock: [in] the irqsafe spinlock to use for locking this fence 507 * @lock: [in] the irqsafe spinlock to use for locking this fence
505 * @context: [in] the execution context this fence is run on 508 * @context: [in] the execution context this fence is run on
506 * @seqno: [in] a linear increasing sequence number for this context 509 * @seqno: [in] a linear increasing sequence number for this context
507 * 510 *
508 * Initializes an allocated fence, the caller doesn't have to keep its 511 * Initializes an allocated fence, the caller doesn't have to keep its
509 * refcount after committing with this fence, but it will need to hold a 512 * refcount after committing with this fence, but it will need to hold a
510 * refcount again if fence_ops.enable_signaling gets called. This can 513 * refcount again if dma_fence_ops.enable_signaling gets called. This can
511 * be used for other implementing other types of fence. 514 * be used for other implementing other types of fence.
512 * 515 *
513 * context and seqno are used for easy comparison between fences, allowing 516 * context and seqno are used for easy comparison between fences, allowing
514 * to check which fence is later by simply using fence_later. 517 * to check which fence is later by simply using dma_fence_later.
515 */ 518 */
516void 519void
517fence_init(struct fence *fence, const struct fence_ops *ops, 520dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops,
518 spinlock_t *lock, u64 context, unsigned seqno) 521 spinlock_t *lock, u64 context, unsigned seqno)
519{ 522{
520 BUG_ON(!lock); 523 BUG_ON(!lock);
521 BUG_ON(!ops || !ops->wait || !ops->enable_signaling || 524 BUG_ON(!ops || !ops->wait || !ops->enable_signaling ||
@@ -529,6 +532,6 @@ fence_init(struct fence *fence, const struct fence_ops *ops,
529 fence->seqno = seqno; 532 fence->seqno = seqno;
530 fence->flags = 0UL; 533 fence->flags = 0UL;
531 534
532 trace_fence_init(fence); 535 trace_dma_fence_init(fence);
533} 536}
534EXPORT_SYMBOL(fence_init); 537EXPORT_SYMBOL(dma_fence_init);
diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c
index 82de59f7cbbd..7ed56f3edfb7 100644
--- a/drivers/dma-buf/reservation.c
+++ b/drivers/dma-buf/reservation.c
@@ -102,17 +102,17 @@ EXPORT_SYMBOL(reservation_object_reserve_shared);
102static void 102static void
103reservation_object_add_shared_inplace(struct reservation_object *obj, 103reservation_object_add_shared_inplace(struct reservation_object *obj,
104 struct reservation_object_list *fobj, 104 struct reservation_object_list *fobj,
105 struct fence *fence) 105 struct dma_fence *fence)
106{ 106{
107 u32 i; 107 u32 i;
108 108
109 fence_get(fence); 109 dma_fence_get(fence);
110 110
111 preempt_disable(); 111 preempt_disable();
112 write_seqcount_begin(&obj->seq); 112 write_seqcount_begin(&obj->seq);
113 113
114 for (i = 0; i < fobj->shared_count; ++i) { 114 for (i = 0; i < fobj->shared_count; ++i) {
115 struct fence *old_fence; 115 struct dma_fence *old_fence;
116 116
117 old_fence = rcu_dereference_protected(fobj->shared[i], 117 old_fence = rcu_dereference_protected(fobj->shared[i],
118 reservation_object_held(obj)); 118 reservation_object_held(obj));
@@ -123,7 +123,7 @@ reservation_object_add_shared_inplace(struct reservation_object *obj,
123 write_seqcount_end(&obj->seq); 123 write_seqcount_end(&obj->seq);
124 preempt_enable(); 124 preempt_enable();
125 125
126 fence_put(old_fence); 126 dma_fence_put(old_fence);
127 return; 127 return;
128 } 128 }
129 } 129 }
@@ -143,12 +143,12 @@ static void
143reservation_object_add_shared_replace(struct reservation_object *obj, 143reservation_object_add_shared_replace(struct reservation_object *obj,
144 struct reservation_object_list *old, 144 struct reservation_object_list *old,
145 struct reservation_object_list *fobj, 145 struct reservation_object_list *fobj,
146 struct fence *fence) 146 struct dma_fence *fence)
147{ 147{
148 unsigned i; 148 unsigned i;
149 struct fence *old_fence = NULL; 149 struct dma_fence *old_fence = NULL;
150 150
151 fence_get(fence); 151 dma_fence_get(fence);
152 152
153 if (!old) { 153 if (!old) {
154 RCU_INIT_POINTER(fobj->shared[0], fence); 154 RCU_INIT_POINTER(fobj->shared[0], fence);
@@ -165,7 +165,7 @@ reservation_object_add_shared_replace(struct reservation_object *obj,
165 fobj->shared_count = old->shared_count; 165 fobj->shared_count = old->shared_count;
166 166
167 for (i = 0; i < old->shared_count; ++i) { 167 for (i = 0; i < old->shared_count; ++i) {
168 struct fence *check; 168 struct dma_fence *check;
169 169
170 check = rcu_dereference_protected(old->shared[i], 170 check = rcu_dereference_protected(old->shared[i],
171 reservation_object_held(obj)); 171 reservation_object_held(obj));
@@ -196,7 +196,7 @@ done:
196 kfree_rcu(old, rcu); 196 kfree_rcu(old, rcu);
197 197
198 if (old_fence) 198 if (old_fence)
199 fence_put(old_fence); 199 dma_fence_put(old_fence);
200} 200}
201 201
202/** 202/**
@@ -208,7 +208,7 @@ done:
208 * reservation_object_reserve_shared() has been called. 208 * reservation_object_reserve_shared() has been called.
209 */ 209 */
210void reservation_object_add_shared_fence(struct reservation_object *obj, 210void reservation_object_add_shared_fence(struct reservation_object *obj,
211 struct fence *fence) 211 struct dma_fence *fence)
212{ 212{
213 struct reservation_object_list *old, *fobj = obj->staged; 213 struct reservation_object_list *old, *fobj = obj->staged;
214 214
@@ -231,9 +231,9 @@ EXPORT_SYMBOL(reservation_object_add_shared_fence);
231 * Add a fence to the exclusive slot. The obj->lock must be held. 231 * Add a fence to the exclusive slot. The obj->lock must be held.
232 */ 232 */
233void reservation_object_add_excl_fence(struct reservation_object *obj, 233void reservation_object_add_excl_fence(struct reservation_object *obj,
234 struct fence *fence) 234 struct dma_fence *fence)
235{ 235{
236 struct fence *old_fence = reservation_object_get_excl(obj); 236 struct dma_fence *old_fence = reservation_object_get_excl(obj);
237 struct reservation_object_list *old; 237 struct reservation_object_list *old;
238 u32 i = 0; 238 u32 i = 0;
239 239
@@ -242,7 +242,7 @@ void reservation_object_add_excl_fence(struct reservation_object *obj,
242 i = old->shared_count; 242 i = old->shared_count;
243 243
244 if (fence) 244 if (fence)
245 fence_get(fence); 245 dma_fence_get(fence);
246 246
247 preempt_disable(); 247 preempt_disable();
248 write_seqcount_begin(&obj->seq); 248 write_seqcount_begin(&obj->seq);
@@ -255,11 +255,11 @@ void reservation_object_add_excl_fence(struct reservation_object *obj,
255 255
256 /* inplace update, no shared fences */ 256 /* inplace update, no shared fences */
257 while (i--) 257 while (i--)
258 fence_put(rcu_dereference_protected(old->shared[i], 258 dma_fence_put(rcu_dereference_protected(old->shared[i],
259 reservation_object_held(obj))); 259 reservation_object_held(obj)));
260 260
261 if (old_fence) 261 if (old_fence)
262 fence_put(old_fence); 262 dma_fence_put(old_fence);
263} 263}
264EXPORT_SYMBOL(reservation_object_add_excl_fence); 264EXPORT_SYMBOL(reservation_object_add_excl_fence);
265 265
@@ -276,12 +276,12 @@ EXPORT_SYMBOL(reservation_object_add_excl_fence);
276 * Zero or -errno 276 * Zero or -errno
277 */ 277 */
278int reservation_object_get_fences_rcu(struct reservation_object *obj, 278int reservation_object_get_fences_rcu(struct reservation_object *obj,
279 struct fence **pfence_excl, 279 struct dma_fence **pfence_excl,
280 unsigned *pshared_count, 280 unsigned *pshared_count,
281 struct fence ***pshared) 281 struct dma_fence ***pshared)
282{ 282{
283 struct fence **shared = NULL; 283 struct dma_fence **shared = NULL;
284 struct fence *fence_excl; 284 struct dma_fence *fence_excl;
285 unsigned int shared_count; 285 unsigned int shared_count;
286 int ret = 1; 286 int ret = 1;
287 287
@@ -296,12 +296,12 @@ int reservation_object_get_fences_rcu(struct reservation_object *obj,
296 seq = read_seqcount_begin(&obj->seq); 296 seq = read_seqcount_begin(&obj->seq);
297 297
298 fence_excl = rcu_dereference(obj->fence_excl); 298 fence_excl = rcu_dereference(obj->fence_excl);
299 if (fence_excl && !fence_get_rcu(fence_excl)) 299 if (fence_excl && !dma_fence_get_rcu(fence_excl))
300 goto unlock; 300 goto unlock;
301 301
302 fobj = rcu_dereference(obj->fence); 302 fobj = rcu_dereference(obj->fence);
303 if (fobj) { 303 if (fobj) {
304 struct fence **nshared; 304 struct dma_fence **nshared;
305 size_t sz = sizeof(*shared) * fobj->shared_max; 305 size_t sz = sizeof(*shared) * fobj->shared_max;
306 306
307 nshared = krealloc(shared, sz, 307 nshared = krealloc(shared, sz,
@@ -322,15 +322,15 @@ int reservation_object_get_fences_rcu(struct reservation_object *obj,
322 322
323 for (i = 0; i < shared_count; ++i) { 323 for (i = 0; i < shared_count; ++i) {
324 shared[i] = rcu_dereference(fobj->shared[i]); 324 shared[i] = rcu_dereference(fobj->shared[i]);
325 if (!fence_get_rcu(shared[i])) 325 if (!dma_fence_get_rcu(shared[i]))
326 break; 326 break;
327 } 327 }
328 } 328 }
329 329
330 if (i != shared_count || read_seqcount_retry(&obj->seq, seq)) { 330 if (i != shared_count || read_seqcount_retry(&obj->seq, seq)) {
331 while (i--) 331 while (i--)
332 fence_put(shared[i]); 332 dma_fence_put(shared[i]);
333 fence_put(fence_excl); 333 dma_fence_put(fence_excl);
334 goto unlock; 334 goto unlock;
335 } 335 }
336 336
@@ -368,7 +368,7 @@ long reservation_object_wait_timeout_rcu(struct reservation_object *obj,
368 bool wait_all, bool intr, 368 bool wait_all, bool intr,
369 unsigned long timeout) 369 unsigned long timeout)
370{ 370{
371 struct fence *fence; 371 struct dma_fence *fence;
372 unsigned seq, shared_count, i = 0; 372 unsigned seq, shared_count, i = 0;
373 long ret = timeout; 373 long ret = timeout;
374 374
@@ -389,16 +389,17 @@ retry:
389 shared_count = fobj->shared_count; 389 shared_count = fobj->shared_count;
390 390
391 for (i = 0; i < shared_count; ++i) { 391 for (i = 0; i < shared_count; ++i) {
392 struct fence *lfence = rcu_dereference(fobj->shared[i]); 392 struct dma_fence *lfence = rcu_dereference(fobj->shared[i]);
393 393
394 if (test_bit(FENCE_FLAG_SIGNALED_BIT, &lfence->flags)) 394 if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT,
395 &lfence->flags))
395 continue; 396 continue;
396 397
397 if (!fence_get_rcu(lfence)) 398 if (!dma_fence_get_rcu(lfence))
398 goto unlock_retry; 399 goto unlock_retry;
399 400
400 if (fence_is_signaled(lfence)) { 401 if (dma_fence_is_signaled(lfence)) {
401 fence_put(lfence); 402 dma_fence_put(lfence);
402 continue; 403 continue;
403 } 404 }
404 405
@@ -408,15 +409,16 @@ retry:
408 } 409 }
409 410
410 if (!shared_count) { 411 if (!shared_count) {
411 struct fence *fence_excl = rcu_dereference(obj->fence_excl); 412 struct dma_fence *fence_excl = rcu_dereference(obj->fence_excl);
412 413
413 if (fence_excl && 414 if (fence_excl &&
414 !test_bit(FENCE_FLAG_SIGNALED_BIT, &fence_excl->flags)) { 415 !test_bit(DMA_FENCE_FLAG_SIGNALED_BIT,
415 if (!fence_get_rcu(fence_excl)) 416 &fence_excl->flags)) {
417 if (!dma_fence_get_rcu(fence_excl))
416 goto unlock_retry; 418 goto unlock_retry;
417 419
418 if (fence_is_signaled(fence_excl)) 420 if (dma_fence_is_signaled(fence_excl))
419 fence_put(fence_excl); 421 dma_fence_put(fence_excl);
420 else 422 else
421 fence = fence_excl; 423 fence = fence_excl;
422 } 424 }
@@ -425,12 +427,12 @@ retry:
425 rcu_read_unlock(); 427 rcu_read_unlock();
426 if (fence) { 428 if (fence) {
427 if (read_seqcount_retry(&obj->seq, seq)) { 429 if (read_seqcount_retry(&obj->seq, seq)) {
428 fence_put(fence); 430 dma_fence_put(fence);
429 goto retry; 431 goto retry;
430 } 432 }
431 433
432 ret = fence_wait_timeout(fence, intr, ret); 434 ret = dma_fence_wait_timeout(fence, intr, ret);
433 fence_put(fence); 435 dma_fence_put(fence);
434 if (ret > 0 && wait_all && (i + 1 < shared_count)) 436 if (ret > 0 && wait_all && (i + 1 < shared_count))
435 goto retry; 437 goto retry;
436 } 438 }
@@ -444,18 +446,18 @@ EXPORT_SYMBOL_GPL(reservation_object_wait_timeout_rcu);
444 446
445 447
446static inline int 448static inline int
447reservation_object_test_signaled_single(struct fence *passed_fence) 449reservation_object_test_signaled_single(struct dma_fence *passed_fence)
448{ 450{
449 struct fence *fence, *lfence = passed_fence; 451 struct dma_fence *fence, *lfence = passed_fence;
450 int ret = 1; 452 int ret = 1;
451 453
452 if (!test_bit(FENCE_FLAG_SIGNALED_BIT, &lfence->flags)) { 454 if (!test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &lfence->flags)) {
453 fence = fence_get_rcu(lfence); 455 fence = dma_fence_get_rcu(lfence);
454 if (!fence) 456 if (!fence)
455 return -1; 457 return -1;
456 458
457 ret = !!fence_is_signaled(fence); 459 ret = !!dma_fence_is_signaled(fence);
458 fence_put(fence); 460 dma_fence_put(fence);
459 } 461 }
460 return ret; 462 return ret;
461} 463}
@@ -492,7 +494,7 @@ retry:
492 shared_count = fobj->shared_count; 494 shared_count = fobj->shared_count;
493 495
494 for (i = 0; i < shared_count; ++i) { 496 for (i = 0; i < shared_count; ++i) {
495 struct fence *fence = rcu_dereference(fobj->shared[i]); 497 struct dma_fence *fence = rcu_dereference(fobj->shared[i]);
496 498
497 ret = reservation_object_test_signaled_single(fence); 499 ret = reservation_object_test_signaled_single(fence);
498 if (ret < 0) 500 if (ret < 0)
@@ -506,7 +508,7 @@ retry:
506 } 508 }
507 509
508 if (!shared_count) { 510 if (!shared_count) {
509 struct fence *fence_excl = rcu_dereference(obj->fence_excl); 511 struct dma_fence *fence_excl = rcu_dereference(obj->fence_excl);
510 512
511 if (fence_excl) { 513 if (fence_excl) {
512 ret = reservation_object_test_signaled_single( 514 ret = reservation_object_test_signaled_single(
diff --git a/drivers/dma-buf/seqno-fence.c b/drivers/dma-buf/seqno-fence.c
index 71127f8f1626..f47112a64763 100644
--- a/drivers/dma-buf/seqno-fence.c
+++ b/drivers/dma-buf/seqno-fence.c
@@ -21,35 +21,35 @@
21#include <linux/export.h> 21#include <linux/export.h>
22#include <linux/seqno-fence.h> 22#include <linux/seqno-fence.h>
23 23
24static const char *seqno_fence_get_driver_name(struct fence *fence) 24static const char *seqno_fence_get_driver_name(struct dma_fence *fence)
25{ 25{
26 struct seqno_fence *seqno_fence = to_seqno_fence(fence); 26 struct seqno_fence *seqno_fence = to_seqno_fence(fence);
27 27
28 return seqno_fence->ops->get_driver_name(fence); 28 return seqno_fence->ops->get_driver_name(fence);
29} 29}
30 30
31static const char *seqno_fence_get_timeline_name(struct fence *fence) 31static const char *seqno_fence_get_timeline_name(struct dma_fence *fence)
32{ 32{
33 struct seqno_fence *seqno_fence = to_seqno_fence(fence); 33 struct seqno_fence *seqno_fence = to_seqno_fence(fence);
34 34
35 return seqno_fence->ops->get_timeline_name(fence); 35 return seqno_fence->ops->get_timeline_name(fence);
36} 36}
37 37
38static bool seqno_enable_signaling(struct fence *fence) 38static bool seqno_enable_signaling(struct dma_fence *fence)
39{ 39{
40 struct seqno_fence *seqno_fence = to_seqno_fence(fence); 40 struct seqno_fence *seqno_fence = to_seqno_fence(fence);
41 41
42 return seqno_fence->ops->enable_signaling(fence); 42 return seqno_fence->ops->enable_signaling(fence);
43} 43}
44 44
45static bool seqno_signaled(struct fence *fence) 45static bool seqno_signaled(struct dma_fence *fence)
46{ 46{
47 struct seqno_fence *seqno_fence = to_seqno_fence(fence); 47 struct seqno_fence *seqno_fence = to_seqno_fence(fence);
48 48
49 return seqno_fence->ops->signaled && seqno_fence->ops->signaled(fence); 49 return seqno_fence->ops->signaled && seqno_fence->ops->signaled(fence);
50} 50}
51 51
52static void seqno_release(struct fence *fence) 52static void seqno_release(struct dma_fence *fence)
53{ 53{
54 struct seqno_fence *f = to_seqno_fence(fence); 54 struct seqno_fence *f = to_seqno_fence(fence);
55 55
@@ -57,18 +57,18 @@ static void seqno_release(struct fence *fence)
57 if (f->ops->release) 57 if (f->ops->release)
58 f->ops->release(fence); 58 f->ops->release(fence);
59 else 59 else
60 fence_free(&f->base); 60 dma_fence_free(&f->base);
61} 61}
62 62
63static signed long seqno_wait(struct fence *fence, bool intr, 63static signed long seqno_wait(struct dma_fence *fence, bool intr,
64 signed long timeout) 64 signed long timeout)
65{ 65{
66 struct seqno_fence *f = to_seqno_fence(fence); 66 struct seqno_fence *f = to_seqno_fence(fence);
67 67
68 return f->ops->wait(fence, intr, timeout); 68 return f->ops->wait(fence, intr, timeout);
69} 69}
70 70
71const struct fence_ops seqno_fence_ops = { 71const struct dma_fence_ops seqno_fence_ops = {
72 .get_driver_name = seqno_fence_get_driver_name, 72 .get_driver_name = seqno_fence_get_driver_name,
73 .get_timeline_name = seqno_fence_get_timeline_name, 73 .get_timeline_name = seqno_fence_get_timeline_name,
74 .enable_signaling = seqno_enable_signaling, 74 .enable_signaling = seqno_enable_signaling,
diff --git a/drivers/dma-buf/sw_sync.c b/drivers/dma-buf/sw_sync.c
index 62e8e6dc7953..82e0ca4dd0c1 100644
--- a/drivers/dma-buf/sw_sync.c
+++ b/drivers/dma-buf/sw_sync.c
@@ -68,9 +68,9 @@ struct sw_sync_create_fence_data {
68 68
69#define SW_SYNC_IOC_INC _IOW(SW_SYNC_IOC_MAGIC, 1, __u32) 69#define SW_SYNC_IOC_INC _IOW(SW_SYNC_IOC_MAGIC, 1, __u32)
70 70
71static const struct fence_ops timeline_fence_ops; 71static const struct dma_fence_ops timeline_fence_ops;
72 72
73static inline struct sync_pt *fence_to_sync_pt(struct fence *fence) 73static inline struct sync_pt *dma_fence_to_sync_pt(struct dma_fence *fence)
74{ 74{
75 if (fence->ops != &timeline_fence_ops) 75 if (fence->ops != &timeline_fence_ops)
76 return NULL; 76 return NULL;
@@ -93,7 +93,7 @@ struct sync_timeline *sync_timeline_create(const char *name)
93 return NULL; 93 return NULL;
94 94
95 kref_init(&obj->kref); 95 kref_init(&obj->kref);
96 obj->context = fence_context_alloc(1); 96 obj->context = dma_fence_context_alloc(1);
97 strlcpy(obj->name, name, sizeof(obj->name)); 97 strlcpy(obj->name, name, sizeof(obj->name));
98 98
99 INIT_LIST_HEAD(&obj->child_list_head); 99 INIT_LIST_HEAD(&obj->child_list_head);
@@ -146,7 +146,7 @@ static void sync_timeline_signal(struct sync_timeline *obj, unsigned int inc)
146 146
147 list_for_each_entry_safe(pt, next, &obj->active_list_head, 147 list_for_each_entry_safe(pt, next, &obj->active_list_head,
148 active_list) { 148 active_list) {
149 if (fence_is_signaled_locked(&pt->base)) 149 if (dma_fence_is_signaled_locked(&pt->base))
150 list_del_init(&pt->active_list); 150 list_del_init(&pt->active_list);
151 } 151 }
152 152
@@ -179,30 +179,30 @@ static struct sync_pt *sync_pt_create(struct sync_timeline *obj, int size,
179 179
180 spin_lock_irqsave(&obj->child_list_lock, flags); 180 spin_lock_irqsave(&obj->child_list_lock, flags);
181 sync_timeline_get(obj); 181 sync_timeline_get(obj);
182 fence_init(&pt->base, &timeline_fence_ops, &obj->child_list_lock, 182 dma_fence_init(&pt->base, &timeline_fence_ops, &obj->child_list_lock,
183 obj->context, value); 183 obj->context, value);
184 list_add_tail(&pt->child_list, &obj->child_list_head); 184 list_add_tail(&pt->child_list, &obj->child_list_head);
185 INIT_LIST_HEAD(&pt->active_list); 185 INIT_LIST_HEAD(&pt->active_list);
186 spin_unlock_irqrestore(&obj->child_list_lock, flags); 186 spin_unlock_irqrestore(&obj->child_list_lock, flags);
187 return pt; 187 return pt;
188} 188}
189 189
190static const char *timeline_fence_get_driver_name(struct fence *fence) 190static const char *timeline_fence_get_driver_name(struct dma_fence *fence)
191{ 191{
192 return "sw_sync"; 192 return "sw_sync";
193} 193}
194 194
195static const char *timeline_fence_get_timeline_name(struct fence *fence) 195static const char *timeline_fence_get_timeline_name(struct dma_fence *fence)
196{ 196{
197 struct sync_timeline *parent = fence_parent(fence); 197 struct sync_timeline *parent = dma_fence_parent(fence);
198 198
199 return parent->name; 199 return parent->name;
200} 200}
201 201
202static void timeline_fence_release(struct fence *fence) 202static void timeline_fence_release(struct dma_fence *fence)
203{ 203{
204 struct sync_pt *pt = fence_to_sync_pt(fence); 204 struct sync_pt *pt = dma_fence_to_sync_pt(fence);
205 struct sync_timeline *parent = fence_parent(fence); 205 struct sync_timeline *parent = dma_fence_parent(fence);
206 unsigned long flags; 206 unsigned long flags;
207 207
208 spin_lock_irqsave(fence->lock, flags); 208 spin_lock_irqsave(fence->lock, flags);
@@ -212,20 +212,20 @@ static void timeline_fence_release(struct fence *fence)
212 spin_unlock_irqrestore(fence->lock, flags); 212 spin_unlock_irqrestore(fence->lock, flags);
213 213
214 sync_timeline_put(parent); 214 sync_timeline_put(parent);
215 fence_free(fence); 215 dma_fence_free(fence);
216} 216}
217 217
218static bool timeline_fence_signaled(struct fence *fence) 218static bool timeline_fence_signaled(struct dma_fence *fence)
219{ 219{
220 struct sync_timeline *parent = fence_parent(fence); 220 struct sync_timeline *parent = dma_fence_parent(fence);
221 221
222 return (fence->seqno > parent->value) ? false : true; 222 return (fence->seqno > parent->value) ? false : true;
223} 223}
224 224
225static bool timeline_fence_enable_signaling(struct fence *fence) 225static bool timeline_fence_enable_signaling(struct dma_fence *fence)
226{ 226{
227 struct sync_pt *pt = fence_to_sync_pt(fence); 227 struct sync_pt *pt = dma_fence_to_sync_pt(fence);
228 struct sync_timeline *parent = fence_parent(fence); 228 struct sync_timeline *parent = dma_fence_parent(fence);
229 229
230 if (timeline_fence_signaled(fence)) 230 if (timeline_fence_signaled(fence))
231 return false; 231 return false;
@@ -234,26 +234,26 @@ static bool timeline_fence_enable_signaling(struct fence *fence)
234 return true; 234 return true;
235} 235}
236 236
237static void timeline_fence_value_str(struct fence *fence, 237static void timeline_fence_value_str(struct dma_fence *fence,
238 char *str, int size) 238 char *str, int size)
239{ 239{
240 snprintf(str, size, "%d", fence->seqno); 240 snprintf(str, size, "%d", fence->seqno);
241} 241}
242 242
243static void timeline_fence_timeline_value_str(struct fence *fence, 243static void timeline_fence_timeline_value_str(struct dma_fence *fence,
244 char *str, int size) 244 char *str, int size)
245{ 245{
246 struct sync_timeline *parent = fence_parent(fence); 246 struct sync_timeline *parent = dma_fence_parent(fence);
247 247
248 snprintf(str, size, "%d", parent->value); 248 snprintf(str, size, "%d", parent->value);
249} 249}
250 250
251static const struct fence_ops timeline_fence_ops = { 251static const struct dma_fence_ops timeline_fence_ops = {
252 .get_driver_name = timeline_fence_get_driver_name, 252 .get_driver_name = timeline_fence_get_driver_name,
253 .get_timeline_name = timeline_fence_get_timeline_name, 253 .get_timeline_name = timeline_fence_get_timeline_name,
254 .enable_signaling = timeline_fence_enable_signaling, 254 .enable_signaling = timeline_fence_enable_signaling,
255 .signaled = timeline_fence_signaled, 255 .signaled = timeline_fence_signaled,
256 .wait = fence_default_wait, 256 .wait = dma_fence_default_wait,
257 .release = timeline_fence_release, 257 .release = timeline_fence_release,
258 .fence_value_str = timeline_fence_value_str, 258 .fence_value_str = timeline_fence_value_str,
259 .timeline_value_str = timeline_fence_timeline_value_str, 259 .timeline_value_str = timeline_fence_timeline_value_str,
@@ -317,7 +317,7 @@ static long sw_sync_ioctl_create_fence(struct sync_timeline *obj,
317 317
318 sync_file = sync_file_create(&pt->base); 318 sync_file = sync_file_create(&pt->base);
319 if (!sync_file) { 319 if (!sync_file) {
320 fence_put(&pt->base); 320 dma_fence_put(&pt->base);
321 err = -ENOMEM; 321 err = -ENOMEM;
322 goto err; 322 goto err;
323 } 323 }
diff --git a/drivers/dma-buf/sync_debug.c b/drivers/dma-buf/sync_debug.c
index 2dd4c3db6caa..48b20e34fb6d 100644
--- a/drivers/dma-buf/sync_debug.c
+++ b/drivers/dma-buf/sync_debug.c
@@ -71,12 +71,13 @@ static const char *sync_status_str(int status)
71 return "error"; 71 return "error";
72} 72}
73 73
74static void sync_print_fence(struct seq_file *s, struct fence *fence, bool show) 74static void sync_print_fence(struct seq_file *s,
75 struct dma_fence *fence, bool show)
75{ 76{
76 int status = 1; 77 int status = 1;
77 struct sync_timeline *parent = fence_parent(fence); 78 struct sync_timeline *parent = dma_fence_parent(fence);
78 79
79 if (fence_is_signaled_locked(fence)) 80 if (dma_fence_is_signaled_locked(fence))
80 status = fence->status; 81 status = fence->status;
81 82
82 seq_printf(s, " %s%sfence %s", 83 seq_printf(s, " %s%sfence %s",
@@ -135,10 +136,10 @@ static void sync_print_sync_file(struct seq_file *s,
135 int i; 136 int i;
136 137
137 seq_printf(s, "[%p] %s: %s\n", sync_file, sync_file->name, 138 seq_printf(s, "[%p] %s: %s\n", sync_file, sync_file->name,
138 sync_status_str(!fence_is_signaled(sync_file->fence))); 139 sync_status_str(!dma_fence_is_signaled(sync_file->fence)));
139 140
140 if (fence_is_array(sync_file->fence)) { 141 if (dma_fence_is_array(sync_file->fence)) {
141 struct fence_array *array = to_fence_array(sync_file->fence); 142 struct dma_fence_array *array = to_dma_fence_array(sync_file->fence);
142 143
143 for (i = 0; i < array->num_fences; ++i) 144 for (i = 0; i < array->num_fences; ++i)
144 sync_print_fence(s, array->fences[i], true); 145 sync_print_fence(s, array->fences[i], true);
diff --git a/drivers/dma-buf/sync_debug.h b/drivers/dma-buf/sync_debug.h
index d269aa6783aa..26fe8b9907b3 100644
--- a/drivers/dma-buf/sync_debug.h
+++ b/drivers/dma-buf/sync_debug.h
@@ -15,7 +15,7 @@
15 15
16#include <linux/list.h> 16#include <linux/list.h>
17#include <linux/spinlock.h> 17#include <linux/spinlock.h>
18#include <linux/fence.h> 18#include <linux/dma-fence.h>
19 19
20#include <linux/sync_file.h> 20#include <linux/sync_file.h>
21#include <uapi/linux/sync_file.h> 21#include <uapi/linux/sync_file.h>
@@ -45,10 +45,9 @@ struct sync_timeline {
45 struct list_head sync_timeline_list; 45 struct list_head sync_timeline_list;
46}; 46};
47 47
48static inline struct sync_timeline *fence_parent(struct fence *fence) 48static inline struct sync_timeline *dma_fence_parent(struct dma_fence *fence)
49{ 49{
50 return container_of(fence->lock, struct sync_timeline, 50 return container_of(fence->lock, struct sync_timeline, child_list_lock);
51 child_list_lock);
52} 51}
53 52
54/** 53/**
@@ -58,7 +57,7 @@ static inline struct sync_timeline *fence_parent(struct fence *fence)
58 * @active_list: sync timeline active child's list 57 * @active_list: sync timeline active child's list
59 */ 58 */
60struct sync_pt { 59struct sync_pt {
61 struct fence base; 60 struct dma_fence base;
62 struct list_head child_list; 61 struct list_head child_list;
63 struct list_head active_list; 62 struct list_head active_list;
64}; 63};
diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c
index 235f8ac113cc..69d8ef98d34c 100644
--- a/drivers/dma-buf/sync_file.c
+++ b/drivers/dma-buf/sync_file.c
@@ -54,7 +54,7 @@ err:
54 return NULL; 54 return NULL;
55} 55}
56 56
57static void fence_check_cb_func(struct fence *f, struct fence_cb *cb) 57static void fence_check_cb_func(struct dma_fence *f, struct dma_fence_cb *cb)
58{ 58{
59 struct sync_file *sync_file; 59 struct sync_file *sync_file;
60 60
@@ -71,7 +71,7 @@ static void fence_check_cb_func(struct fence *f, struct fence_cb *cb)
71 * takes ownership of @fence. The sync_file can be released with 71 * takes ownership of @fence. The sync_file can be released with
72 * fput(sync_file->file). Returns the sync_file or NULL in case of error. 72 * fput(sync_file->file). Returns the sync_file or NULL in case of error.
73 */ 73 */
74struct sync_file *sync_file_create(struct fence *fence) 74struct sync_file *sync_file_create(struct dma_fence *fence)
75{ 75{
76 struct sync_file *sync_file; 76 struct sync_file *sync_file;
77 77
@@ -79,7 +79,7 @@ struct sync_file *sync_file_create(struct fence *fence)
79 if (!sync_file) 79 if (!sync_file)
80 return NULL; 80 return NULL;
81 81
82 sync_file->fence = fence_get(fence); 82 sync_file->fence = dma_fence_get(fence);
83 83
84 snprintf(sync_file->name, sizeof(sync_file->name), "%s-%s%llu-%d", 84 snprintf(sync_file->name, sizeof(sync_file->name), "%s-%s%llu-%d",
85 fence->ops->get_driver_name(fence), 85 fence->ops->get_driver_name(fence),
@@ -121,16 +121,16 @@ err:
121 * Ensures @fd references a valid sync_file and returns a fence that 121 * Ensures @fd references a valid sync_file and returns a fence that
122 * represents all fence in the sync_file. On error NULL is returned. 122 * represents all fence in the sync_file. On error NULL is returned.
123 */ 123 */
124struct fence *sync_file_get_fence(int fd) 124struct dma_fence *sync_file_get_fence(int fd)
125{ 125{
126 struct sync_file *sync_file; 126 struct sync_file *sync_file;
127 struct fence *fence; 127 struct dma_fence *fence;
128 128
129 sync_file = sync_file_fdget(fd); 129 sync_file = sync_file_fdget(fd);
130 if (!sync_file) 130 if (!sync_file)
131 return NULL; 131 return NULL;
132 132
133 fence = fence_get(sync_file->fence); 133 fence = dma_fence_get(sync_file->fence);
134 fput(sync_file->file); 134 fput(sync_file->file);
135 135
136 return fence; 136 return fence;
@@ -138,22 +138,23 @@ struct fence *sync_file_get_fence(int fd)
138EXPORT_SYMBOL(sync_file_get_fence); 138EXPORT_SYMBOL(sync_file_get_fence);
139 139
140static int sync_file_set_fence(struct sync_file *sync_file, 140static int sync_file_set_fence(struct sync_file *sync_file,
141 struct fence **fences, int num_fences) 141 struct dma_fence **fences, int num_fences)
142{ 142{
143 struct fence_array *array; 143 struct dma_fence_array *array;
144 144
145 /* 145 /*
146 * The reference for the fences in the new sync_file and held 146 * The reference for the fences in the new sync_file and held
147 * in add_fence() during the merge procedure, so for num_fences == 1 147 * in add_fence() during the merge procedure, so for num_fences == 1
148 * we already own a new reference to the fence. For num_fence > 1 148 * we already own a new reference to the fence. For num_fence > 1
149 * we own the reference of the fence_array creation. 149 * we own the reference of the dma_fence_array creation.
150 */ 150 */
151 if (num_fences == 1) { 151 if (num_fences == 1) {
152 sync_file->fence = fences[0]; 152 sync_file->fence = fences[0];
153 kfree(fences); 153 kfree(fences);
154 } else { 154 } else {
155 array = fence_array_create(num_fences, fences, 155 array = dma_fence_array_create(num_fences, fences,
156 fence_context_alloc(1), 1, false); 156 dma_fence_context_alloc(1),
157 1, false);
157 if (!array) 158 if (!array)
158 return -ENOMEM; 159 return -ENOMEM;
159 160
@@ -163,10 +164,11 @@ static int sync_file_set_fence(struct sync_file *sync_file,
163 return 0; 164 return 0;
164} 165}
165 166
166static struct fence **get_fences(struct sync_file *sync_file, int *num_fences) 167static struct dma_fence **get_fences(struct sync_file *sync_file,
168 int *num_fences)
167{ 169{
168 if (fence_is_array(sync_file->fence)) { 170 if (dma_fence_is_array(sync_file->fence)) {
169 struct fence_array *array = to_fence_array(sync_file->fence); 171 struct dma_fence_array *array = to_dma_fence_array(sync_file->fence);
170 172
171 *num_fences = array->num_fences; 173 *num_fences = array->num_fences;
172 return array->fences; 174 return array->fences;
@@ -176,12 +178,13 @@ static struct fence **get_fences(struct sync_file *sync_file, int *num_fences)
176 return &sync_file->fence; 178 return &sync_file->fence;
177} 179}
178 180
179static void add_fence(struct fence **fences, int *i, struct fence *fence) 181static void add_fence(struct dma_fence **fences,
182 int *i, struct dma_fence *fence)
180{ 183{
181 fences[*i] = fence; 184 fences[*i] = fence;
182 185
183 if (!fence_is_signaled(fence)) { 186 if (!dma_fence_is_signaled(fence)) {
184 fence_get(fence); 187 dma_fence_get(fence);
185 (*i)++; 188 (*i)++;
186 } 189 }
187} 190}
@@ -200,7 +203,7 @@ static struct sync_file *sync_file_merge(const char *name, struct sync_file *a,
200 struct sync_file *b) 203 struct sync_file *b)
201{ 204{
202 struct sync_file *sync_file; 205 struct sync_file *sync_file;
203 struct fence **fences, **nfences, **a_fences, **b_fences; 206 struct dma_fence **fences, **nfences, **a_fences, **b_fences;
204 int i, i_a, i_b, num_fences, a_num_fences, b_num_fences; 207 int i, i_a, i_b, num_fences, a_num_fences, b_num_fences;
205 208
206 sync_file = sync_file_alloc(); 209 sync_file = sync_file_alloc();
@@ -226,8 +229,8 @@ static struct sync_file *sync_file_merge(const char *name, struct sync_file *a,
226 * and sync_file_create, this is a reasonable assumption. 229 * and sync_file_create, this is a reasonable assumption.
227 */ 230 */
228 for (i = i_a = i_b = 0; i_a < a_num_fences && i_b < b_num_fences; ) { 231 for (i = i_a = i_b = 0; i_a < a_num_fences && i_b < b_num_fences; ) {
229 struct fence *pt_a = a_fences[i_a]; 232 struct dma_fence *pt_a = a_fences[i_a];
230 struct fence *pt_b = b_fences[i_b]; 233 struct dma_fence *pt_b = b_fences[i_b];
231 234
232 if (pt_a->context < pt_b->context) { 235 if (pt_a->context < pt_b->context) {
233 add_fence(fences, &i, pt_a); 236 add_fence(fences, &i, pt_a);
@@ -255,7 +258,7 @@ static struct sync_file *sync_file_merge(const char *name, struct sync_file *a,
255 add_fence(fences, &i, b_fences[i_b]); 258 add_fence(fences, &i, b_fences[i_b]);
256 259
257 if (i == 0) 260 if (i == 0)
258 fences[i++] = fence_get(a_fences[0]); 261 fences[i++] = dma_fence_get(a_fences[0]);
259 262
260 if (num_fences > i) { 263 if (num_fences > i) {
261 nfences = krealloc(fences, i * sizeof(*fences), 264 nfences = krealloc(fences, i * sizeof(*fences),
@@ -286,8 +289,8 @@ static void sync_file_free(struct kref *kref)
286 kref); 289 kref);
287 290
288 if (test_bit(POLL_ENABLED, &sync_file->fence->flags)) 291 if (test_bit(POLL_ENABLED, &sync_file->fence->flags))
289 fence_remove_callback(sync_file->fence, &sync_file->cb); 292 dma_fence_remove_callback(sync_file->fence, &sync_file->cb);
290 fence_put(sync_file->fence); 293 dma_fence_put(sync_file->fence);
291 kfree(sync_file); 294 kfree(sync_file);
292} 295}
293 296
@@ -307,12 +310,12 @@ static unsigned int sync_file_poll(struct file *file, poll_table *wait)
307 310
308 if (!poll_does_not_wait(wait) && 311 if (!poll_does_not_wait(wait) &&
309 !test_and_set_bit(POLL_ENABLED, &sync_file->fence->flags)) { 312 !test_and_set_bit(POLL_ENABLED, &sync_file->fence->flags)) {
310 if (fence_add_callback(sync_file->fence, &sync_file->cb, 313 if (dma_fence_add_callback(sync_file->fence, &sync_file->cb,
311 fence_check_cb_func) < 0) 314 fence_check_cb_func) < 0)
312 wake_up_all(&sync_file->wq); 315 wake_up_all(&sync_file->wq);
313 } 316 }
314 317
315 return fence_is_signaled(sync_file->fence) ? POLLIN : 0; 318 return dma_fence_is_signaled(sync_file->fence) ? POLLIN : 0;
316} 319}
317 320
318static long sync_file_ioctl_merge(struct sync_file *sync_file, 321static long sync_file_ioctl_merge(struct sync_file *sync_file,
@@ -370,14 +373,14 @@ err_put_fd:
370 return err; 373 return err;
371} 374}
372 375
373static void sync_fill_fence_info(struct fence *fence, 376static void sync_fill_fence_info(struct dma_fence *fence,
374 struct sync_fence_info *info) 377 struct sync_fence_info *info)
375{ 378{
376 strlcpy(info->obj_name, fence->ops->get_timeline_name(fence), 379 strlcpy(info->obj_name, fence->ops->get_timeline_name(fence),
377 sizeof(info->obj_name)); 380 sizeof(info->obj_name));
378 strlcpy(info->driver_name, fence->ops->get_driver_name(fence), 381 strlcpy(info->driver_name, fence->ops->get_driver_name(fence),
379 sizeof(info->driver_name)); 382 sizeof(info->driver_name));
380 if (fence_is_signaled(fence)) 383 if (dma_fence_is_signaled(fence))
381 info->status = fence->status >= 0 ? 1 : fence->status; 384 info->status = fence->status >= 0 ? 1 : fence->status;
382 else 385 else
383 info->status = 0; 386 info->status = 0;
@@ -389,7 +392,7 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file,
389{ 392{
390 struct sync_file_info info; 393 struct sync_file_info info;
391 struct sync_fence_info *fence_info = NULL; 394 struct sync_fence_info *fence_info = NULL;
392 struct fence **fences; 395 struct dma_fence **fences;
393 __u32 size; 396 __u32 size;
394 int num_fences, ret, i; 397 int num_fences, ret, i;
395 398
@@ -429,7 +432,7 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file,
429 432
430no_fences: 433no_fences:
431 strlcpy(info.name, sync_file->name, sizeof(info.name)); 434 strlcpy(info.name, sync_file->name, sizeof(info.name));
432 info.status = fence_is_signaled(sync_file->fence); 435 info.status = dma_fence_is_signaled(sync_file->fence);
433 info.num_fences = num_fences; 436 info.num_fences = num_fences;
434 437
435 if (copy_to_user((void __user *)arg, &info, sizeof(info))) 438 if (copy_to_user((void __user *)arg, &info, sizeof(info)))