Skip to content

Commit f54d186

Browse files
ickledanvet
authored andcommitted
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 <[email protected]> Reviewed-by: Gustavo Padovan <[email protected]> Acked-by: Sumit Semwal <[email protected]> Acked-by: Christian König <[email protected]> Signed-off-by: Daniel Vetter <[email protected]> Link: http://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 0fc4f78 commit f54d186

File tree

110 files changed

+1252
-1214
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+1252
-1214
lines changed

Documentation/sync_file.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
This document serves as a guide for device drivers writers on what the
88
sync_file API is, and how drivers can support it. Sync file is the carrier of
9-
the fences(struct fence) that are needed to synchronize between drivers or
9+
the fences(struct dma_fence) that are needed to synchronize between drivers or
1010
across process boundaries.
1111

1212
The sync_file API is meant to be used to send and receive fence information
@@ -32,9 +32,9 @@ in-fences and out-fences
3232
Sync files can go either to or from userspace. When a sync_file is sent from
3333
the driver to userspace we call the fences it contains 'out-fences'. They are
3434
related to a buffer that the driver is processing or is going to process, so
35-
the driver creates an out-fence to be able to notify, through fence_signal(),
36-
when it has finished using (or processing) that buffer. Out-fences are fences
37-
that the driver creates.
35+
the driver creates an out-fence to be able to notify, through
36+
dma_fence_signal(), when it has finished using (or processing) that buffer.
37+
Out-fences are fences that the driver creates.
3838

3939
On the other hand if the driver receives fence(s) through a sync_file from
4040
userspace we call these fence(s) 'in-fences'. Receiveing in-fences means that
@@ -47,7 +47,7 @@ Creating Sync Files
4747
When a driver needs to send an out-fence userspace it creates a sync_file.
4848

4949
Interface:
50-
struct sync_file *sync_file_create(struct fence *fence);
50+
struct sync_file *sync_file_create(struct dma_fence *fence);
5151

5252
The caller pass the out-fence and gets back the sync_file. That is just the
5353
first step, next it needs to install an fd on sync_file->file. So it gets an
@@ -72,11 +72,11 @@ of the Sync File to the kernel. The kernel can then retrieve the fences
7272
from it.
7373

7474
Interface:
75-
struct fence *sync_file_get_fence(int fd);
75+
struct dma_fence *sync_file_get_fence(int fd);
7676

7777

7878
The returned reference is owned by the caller and must be disposed of
79-
afterwards using fence_put(). In case of error, a NULL is returned instead.
79+
afterwards using dma_fence_put(). In case of error, a NULL is returned instead.
8080

8181
References:
8282
[1] struct sync_file in include/linux/sync_file.h

drivers/base/Kconfig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,11 @@ config DMA_SHARED_BUFFER
248248
APIs extension; the file's descriptor can then be passed on to other
249249
driver.
250250

251-
config FENCE_TRACE
252-
bool "Enable verbose FENCE_TRACE messages"
251+
config DMA_FENCE_TRACE
252+
bool "Enable verbose DMA_FENCE_TRACE messages"
253253
depends on DMA_SHARED_BUFFER
254254
help
255-
Enable the FENCE_TRACE printks. This will add extra
255+
Enable the DMA_FENCE_TRACE printks. This will add extra
256256
spam to the console log, but will make it easier to diagnose
257257
lockup related problems for dma-buffers shared across multiple
258258
devices.

drivers/dma-buf/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ config SYNC_FILE
77
select DMA_SHARED_BUFFER
88
---help---
99
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
1111
userspace via Sync File fds for synchronization between drivers via
1212
userspace components. It has been ported from Android.
1313

drivers/dma-buf/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
obj-y := dma-buf.o fence.o reservation.o seqno-fence.o fence-array.o
1+
obj-y := dma-buf.o dma-fence.o dma-fence-array.o reservation.o seqno-fence.o
22
obj-$(CONFIG_SYNC_FILE) += sync_file.o
33
obj-$(CONFIG_SW_SYNC) += sw_sync.o sync_debug.o

drivers/dma-buf/dma-buf.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <linux/fs.h>
2626
#include <linux/slab.h>
2727
#include <linux/dma-buf.h>
28-
#include <linux/fence.h>
28+
#include <linux/dma-fence.h>
2929
#include <linux/anon_inodes.h>
3030
#include <linux/export.h>
3131
#include <linux/debugfs.h>
@@ -124,7 +124,7 @@ static loff_t dma_buf_llseek(struct file *file, loff_t offset, int whence)
124124
return base + offset;
125125
}
126126

127-
static void dma_buf_poll_cb(struct fence *fence, struct fence_cb *cb)
127+
static void dma_buf_poll_cb(struct dma_fence *fence, struct dma_fence_cb *cb)
128128
{
129129
struct dma_buf_poll_cb_t *dcb = (struct dma_buf_poll_cb_t *)cb;
130130
unsigned long flags;
@@ -140,7 +140,7 @@ static unsigned int dma_buf_poll(struct file *file, poll_table *poll)
140140
struct dma_buf *dmabuf;
141141
struct reservation_object *resv;
142142
struct reservation_object_list *fobj;
143-
struct fence *fence_excl;
143+
struct dma_fence *fence_excl;
144144
unsigned long events;
145145
unsigned shared_count, seq;
146146

@@ -187,20 +187,20 @@ static unsigned int dma_buf_poll(struct file *file, poll_table *poll)
187187
spin_unlock_irq(&dmabuf->poll.lock);
188188

189189
if (events & pevents) {
190-
if (!fence_get_rcu(fence_excl)) {
190+
if (!dma_fence_get_rcu(fence_excl)) {
191191
/* force a recheck */
192192
events &= ~pevents;
193193
dma_buf_poll_cb(NULL, &dcb->cb);
194-
} else if (!fence_add_callback(fence_excl, &dcb->cb,
195-
dma_buf_poll_cb)) {
194+
} else if (!dma_fence_add_callback(fence_excl, &dcb->cb,
195+
dma_buf_poll_cb)) {
196196
events &= ~pevents;
197-
fence_put(fence_excl);
197+
dma_fence_put(fence_excl);
198198
} else {
199199
/*
200200
* No callback queued, wake up any additional
201201
* waiters.
202202
*/
203-
fence_put(fence_excl);
203+
dma_fence_put(fence_excl);
204204
dma_buf_poll_cb(NULL, &dcb->cb);
205205
}
206206
}
@@ -222,9 +222,9 @@ static unsigned int dma_buf_poll(struct file *file, poll_table *poll)
222222
goto out;
223223

224224
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]);
226226

227-
if (!fence_get_rcu(fence)) {
227+
if (!dma_fence_get_rcu(fence)) {
228228
/*
229229
* fence refcount dropped to zero, this means
230230
* that fobj has been freed
@@ -235,13 +235,13 @@ static unsigned int dma_buf_poll(struct file *file, poll_table *poll)
235235
dma_buf_poll_cb(NULL, &dcb->cb);
236236
break;
237237
}
238-
if (!fence_add_callback(fence, &dcb->cb,
239-
dma_buf_poll_cb)) {
240-
fence_put(fence);
238+
if (!dma_fence_add_callback(fence, &dcb->cb,
239+
dma_buf_poll_cb)) {
240+
dma_fence_put(fence);
241241
events &= ~POLLOUT;
242242
break;
243243
}
244-
fence_put(fence);
244+
dma_fence_put(fence);
245245
}
246246

247247
/* No callback queued, wake up any additional waiters. */
Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* fence-array: aggregate fences to be waited together
2+
* dma-fence-array: aggregate fences to be waited together
33
*
44
* Copyright (C) 2016 Collabora Ltd
55
* Copyright (C) 2016 Advanced Micro Devices, Inc.
@@ -19,35 +19,34 @@
1919

2020
#include <linux/export.h>
2121
#include <linux/slab.h>
22-
#include <linux/fence-array.h>
22+
#include <linux/dma-fence-array.h>
2323

24-
static void fence_array_cb_func(struct fence *f, struct fence_cb *cb);
25-
26-
static const char *fence_array_get_driver_name(struct fence *fence)
24+
static const char *dma_fence_array_get_driver_name(struct dma_fence *fence)
2725
{
28-
return "fence_array";
26+
return "dma_fence_array";
2927
}
3028

31-
static const char *fence_array_get_timeline_name(struct fence *fence)
29+
static const char *dma_fence_array_get_timeline_name(struct dma_fence *fence)
3230
{
3331
return "unbound";
3432
}
3533

36-
static void fence_array_cb_func(struct fence *f, struct fence_cb *cb)
34+
static void dma_fence_array_cb_func(struct dma_fence *f,
35+
struct dma_fence_cb *cb)
3736
{
38-
struct fence_array_cb *array_cb =
39-
container_of(cb, struct fence_array_cb, cb);
40-
struct fence_array *array = array_cb->array;
37+
struct dma_fence_array_cb *array_cb =
38+
container_of(cb, struct dma_fence_array_cb, cb);
39+
struct dma_fence_array *array = array_cb->array;
4140

4241
if (atomic_dec_and_test(&array->num_pending))
43-
fence_signal(&array->base);
44-
fence_put(&array->base);
42+
dma_fence_signal(&array->base);
43+
dma_fence_put(&array->base);
4544
}
4645

47-
static bool fence_array_enable_signaling(struct fence *fence)
46+
static bool dma_fence_array_enable_signaling(struct dma_fence *fence)
4847
{
49-
struct fence_array *array = to_fence_array(fence);
50-
struct fence_array_cb *cb = (void *)(&array[1]);
48+
struct dma_fence_array *array = to_dma_fence_array(fence);
49+
struct dma_fence_array_cb *cb = (void *)(&array[1]);
5150
unsigned i;
5251

5352
for (i = 0; i < array->num_fences; ++i) {
@@ -60,10 +59,10 @@ static bool fence_array_enable_signaling(struct fence *fence)
6059
* until we signal the array as complete (but that is now
6160
* insufficient).
6261
*/
63-
fence_get(&array->base);
64-
if (fence_add_callback(array->fences[i], &cb[i].cb,
65-
fence_array_cb_func)) {
66-
fence_put(&array->base);
62+
dma_fence_get(&array->base);
63+
if (dma_fence_add_callback(array->fences[i], &cb[i].cb,
64+
dma_fence_array_cb_func)) {
65+
dma_fence_put(&array->base);
6766
if (atomic_dec_and_test(&array->num_pending))
6867
return false;
6968
}
@@ -72,74 +71,76 @@ static bool fence_array_enable_signaling(struct fence *fence)
7271
return true;
7372
}
7473

75-
static bool fence_array_signaled(struct fence *fence)
74+
static bool dma_fence_array_signaled(struct dma_fence *fence)
7675
{
77-
struct fence_array *array = to_fence_array(fence);
76+
struct dma_fence_array *array = to_dma_fence_array(fence);
7877

7978
return atomic_read(&array->num_pending) <= 0;
8079
}
8180

82-
static void fence_array_release(struct fence *fence)
81+
static void dma_fence_array_release(struct dma_fence *fence)
8382
{
84-
struct fence_array *array = to_fence_array(fence);
83+
struct dma_fence_array *array = to_dma_fence_array(fence);
8584
unsigned i;
8685

8786
for (i = 0; i < array->num_fences; ++i)
88-
fence_put(array->fences[i]);
87+
dma_fence_put(array->fences[i]);
8988

9089
kfree(array->fences);
91-
fence_free(fence);
90+
dma_fence_free(fence);
9291
}
9392

94-
const struct fence_ops fence_array_ops = {
95-
.get_driver_name = fence_array_get_driver_name,
96-
.get_timeline_name = fence_array_get_timeline_name,
97-
.enable_signaling = fence_array_enable_signaling,
98-
.signaled = fence_array_signaled,
99-
.wait = fence_default_wait,
100-
.release = fence_array_release,
93+
const struct dma_fence_ops dma_fence_array_ops = {
94+
.get_driver_name = dma_fence_array_get_driver_name,
95+
.get_timeline_name = dma_fence_array_get_timeline_name,
96+
.enable_signaling = dma_fence_array_enable_signaling,
97+
.signaled = dma_fence_array_signaled,
98+
.wait = dma_fence_default_wait,
99+
.release = dma_fence_array_release,
101100
};
102-
EXPORT_SYMBOL(fence_array_ops);
101+
EXPORT_SYMBOL(dma_fence_array_ops);
103102

104103
/**
105-
* fence_array_create - Create a custom fence array
104+
* dma_fence_array_create - Create a custom fence array
106105
* @num_fences: [in] number of fences to add in the array
107106
* @fences: [in] array containing the fences
108107
* @context: [in] fence context to use
109108
* @seqno: [in] sequence number to use
110109
* @signal_on_any: [in] signal on any fence in the array
111110
*
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().
113113
* In case of error it returns NULL.
114114
*
115115
* The caller should allocate the fences array with num_fences size
116116
* 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.
118118
*
119119
* If @signal_on_any is true the fence array signals if any fence in the array
120120
* signals, otherwise it signals when all fences in the array signal.
121121
*/
122-
struct fence_array *fence_array_create(int num_fences, struct fence **fences,
123-
u64 context, unsigned seqno,
124-
bool signal_on_any)
122+
struct dma_fence_array *dma_fence_array_create(int num_fences,
123+
struct dma_fence **fences,
124+
u64 context, unsigned seqno,
125+
bool signal_on_any)
125126
{
126-
struct fence_array *array;
127+
struct dma_fence_array *array;
127128
size_t size = sizeof(*array);
128129

129130
/* 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);
131132
array = kzalloc(size, GFP_KERNEL);
132133
if (!array)
133134
return NULL;
134135

135136
spin_lock_init(&array->lock);
136-
fence_init(&array->base, &fence_array_ops, &array->lock,
137-
context, seqno);
137+
dma_fence_init(&array->base, &dma_fence_array_ops, &array->lock,
138+
context, seqno);
138139

139140
array->num_fences = num_fences;
140141
atomic_set(&array->num_pending, signal_on_any ? 1 : num_fences);
141142
array->fences = fences;
142143

143144
return array;
144145
}
145-
EXPORT_SYMBOL(fence_array_create);
146+
EXPORT_SYMBOL(dma_fence_array_create);

0 commit comments

Comments
 (0)