3 * (C) COPYRIGHT 2012-2016 ARM Limited. All rights reserved.
5 * This program is free software and is provided to you under the terms of the
6 * GNU General Public License version 2 as published by the Free Software
7 * Foundation, and any use by you of this program is subject to the terms
10 * A copy of the licence is included with the program, and can also be obtained
11 * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
12 * Boston, MA 02110-1301, USA.
21 * @file mali_kbase_sync_user.c
27 #include <linux/sched.h>
28 #include <linux/fdtable.h>
29 #include <linux/file.h>
31 #include <linux/module.h>
32 #include <linux/anon_inodes.h>
33 #include <linux/version.h>
34 #include <linux/uaccess.h>
35 #include <mali_kbase_sync.h>
37 static int kbase_stream_close(struct inode *inode, struct file *file)
39 struct sync_timeline *tl;
41 tl = (struct sync_timeline *)file->private_data;
43 sync_timeline_destroy(tl);
47 static const struct file_operations stream_fops = {
49 .release = kbase_stream_close,
52 int kbase_stream_create(const char *name, int *const out_fd)
54 struct sync_timeline *tl;
58 tl = kbase_sync_timeline_alloc(name);
62 *out_fd = anon_inode_getfd(name, &stream_fops, tl, O_RDONLY | O_CLOEXEC);
65 sync_timeline_destroy(tl);
72 int kbase_stream_create_fence(int tl_fd)
74 struct sync_timeline *tl;
76 struct sync_fence *fence;
77 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0)
78 struct files_struct *files;
84 tl_file = fget(tl_fd);
88 if (tl_file->f_op != &stream_fops) {
93 tl = tl_file->private_data;
95 pt = kbase_sync_pt_alloc(tl);
101 fence = sync_fence_create("mali_fence", pt);
108 /* from here the fence owns the sync_pt */
110 /* create a fd representing the fence */
111 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0)
112 fd = get_unused_fd_flags(O_RDWR | O_CLOEXEC);
114 sync_fence_put(fence);
118 fd = get_unused_fd();
120 sync_fence_put(fence);
124 files = current->files;
125 spin_lock(&files->file_lock);
126 fdt = files_fdtable(files);
127 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0)
128 __set_close_on_exec(fd, fdt);
130 FD_SET(fd, fdt->close_on_exec);
132 spin_unlock(&files->file_lock);
133 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0) */
135 /* bind fence to the new fd */
136 sync_fence_install(fence, fd);
144 int kbase_fence_validate(int fd)
146 struct sync_fence *fence;
148 fence = sync_fence_fdget(fd);
152 sync_fence_put(fence);
156 #endif /* CONFIG_SYNC */