Lines Matching defs:sync_file
3 * drivers/dma-buf/sync_file.c
17 #include <linux/sync_file.h>
18 #include <uapi/linux/sync_file.h>
22 static struct sync_file *sync_file_alloc(void)
24 struct sync_file *sync_file;
26 sync_file = kzalloc(sizeof(*sync_file), GFP_KERNEL);
27 if (!sync_file)
30 sync_file->file = anon_inode_getfile("sync_file", &sync_file_fops,
31 sync_file, 0);
32 if (IS_ERR(sync_file->file))
35 init_waitqueue_head(&sync_file->wq);
37 INIT_LIST_HEAD(&sync_file->cb.node);
39 return sync_file;
42 kfree(sync_file);
48 struct sync_file *sync_file;
50 sync_file = container_of(cb, struct sync_file, cb);
52 wake_up_all(&sync_file->wq);
59 * Creates a sync_file containg @fence. This function acquires and additional
60 * reference of @fence for the newly-created &sync_file, if it succeeds. The
61 * sync_file can be released with fput(sync_file->file). Returns the
62 * sync_file or NULL in case of error.
64 struct sync_file *sync_file_create(struct dma_fence *fence)
66 struct sync_file *sync_file;
68 sync_file = sync_file_alloc();
69 if (!sync_file)
72 sync_file->fence = dma_fence_get(fence);
74 return sync_file;
78 static struct sync_file *sync_file_fdget(int fd)
96 * sync_file_get_fence - get the fence related to the sync_file fd
97 * @fd: sync_file fd to get the fence from
99 * Ensures @fd references a valid sync_file and returns a fence that
100 * represents all fence in the sync_file. On error NULL is returned.
104 struct sync_file *sync_file;
107 sync_file = sync_file_fdget(fd);
108 if (!sync_file)
111 fence = dma_fence_get(sync_file->fence);
112 fput(sync_file->file);
119 * sync_file_get_name - get the name of the sync_file
120 * @sync_file: sync_file to get the fence from
121 * @buf: destination buffer to copy sync_file name into
124 * Each sync_file may have a name assigned either by the user (when merging
131 char *sync_file_get_name(struct sync_file *sync_file, char *buf, int len)
133 if (sync_file->user_name[0]) {
134 strlcpy(buf, sync_file->user_name, len);
136 struct dma_fence *fence = sync_file->fence;
148 static int sync_file_set_fence(struct sync_file *sync_file,
154 * The reference for the fences in the new sync_file and held
160 sync_file->fence = fences[0];
169 sync_file->fence = &array->base;
175 static struct dma_fence **get_fences(struct sync_file *sync_file,
178 if (dma_fence_is_array(sync_file->fence)) {
179 struct dma_fence_array *array = to_dma_fence_array(sync_file->fence);
186 return &sync_file->fence;
203 * @a: sync_file a
204 * @b: sync_file b
206 * Creates a new sync_file which contains copies of all the fences in both
207 * @a and @b. @a and @b remain valid, independent sync_file. Returns the
208 * new merged sync_file or NULL in case of error.
210 static struct sync_file *sync_file_merge(const char *name, struct sync_file *a,
211 struct sync_file *b)
213 struct sync_file *sync_file;
217 sync_file = sync_file_alloc();
218 if (!sync_file)
233 * Assume sync_file a and b are both ordered and have no
236 * If a sync_file can only be created with sync_file_merge
281 if (sync_file_set_fence(sync_file, fences, i) < 0)
284 strlcpy(sync_file->user_name, name, sizeof(sync_file->user_name));
285 return sync_file;
291 fput(sync_file->file);
298 struct sync_file *sync_file = file->private_data;
300 if (test_bit(POLL_ENABLED, &sync_file->flags))
301 dma_fence_remove_callback(sync_file->fence, &sync_file->cb);
302 dma_fence_put(sync_file->fence);
303 kfree(sync_file);
310 struct sync_file *sync_file = file->private_data;
312 poll_wait(file, &sync_file->wq, wait);
314 if (list_empty(&sync_file->cb.node) &&
315 !test_and_set_bit(POLL_ENABLED, &sync_file->flags)) {
316 if (dma_fence_add_callback(sync_file->fence, &sync_file->cb,
318 wake_up_all(&sync_file->wq);
321 return dma_fence_is_signaled(sync_file->fence) ? EPOLLIN : 0;
324 static long sync_file_ioctl_merge(struct sync_file *sync_file,
329 struct sync_file *fence2, *fence3;
352 fence3 = sync_file_merge(data.name, sync_file, fence2);
399 static long sync_file_ioctl_fence_info(struct sync_file *sync_file,
414 fences = get_fences(sync_file, &num_fences);
423 info.status = dma_fence_get_status(sync_file->fence);
449 sync_file_get_name(sync_file, info.name, sizeof(info.name));
466 struct sync_file *sync_file = file->private_data;
470 return sync_file_ioctl_merge(sync_file, arg);
473 return sync_file_ioctl_fence_info(sync_file, arg);