3 * (C) COPYRIGHT 2012-2015 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>
36 #include <mali_base_kernel_sync.h>
38 static int kbase_stream_close(struct inode *inode, struct file *file)
40 struct sync_timeline *tl;
42 tl = (struct sync_timeline *)file->private_data;
44 sync_timeline_destroy(tl);
48 static const struct file_operations stream_fops = {
50 .release = kbase_stream_close,
53 int kbase_stream_create(const char *name, int *const out_fd)
55 struct sync_timeline *tl;
59 tl = kbase_sync_timeline_alloc(name);
63 *out_fd = anon_inode_getfd(name, &stream_fops, tl, O_RDONLY | O_CLOEXEC);
66 sync_timeline_destroy(tl);
73 int kbase_stream_create_fence(int tl_fd)
75 struct sync_timeline *tl;
77 struct sync_fence *fence;
78 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0)
79 struct files_struct *files;
85 tl_file = fget(tl_fd);
89 if (tl_file->f_op != &stream_fops) {
94 tl = tl_file->private_data;
96 pt = kbase_sync_pt_alloc(tl);
102 fence = sync_fence_create("mali_fence", pt);
109 /* from here the fence owns the sync_pt */
111 /* create a fd representing the fence */
112 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0)
113 fd = get_unused_fd_flags(O_RDWR | O_CLOEXEC);
115 sync_fence_put(fence);
119 fd = get_unused_fd();
121 sync_fence_put(fence);
125 files = current->files;
126 spin_lock(&files->file_lock);
127 fdt = files_fdtable(files);
128 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0)
129 __set_close_on_exec(fd, fdt);
131 FD_SET(fd, fdt->close_on_exec);
133 spin_unlock(&files->file_lock);
134 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0) */
136 /* bind fence to the new fd */
137 sync_fence_install(fence, fd);
145 int kbase_fence_validate(int fd)
147 struct sync_fence *fence;
149 fence = sync_fence_fdget(fd);
153 sync_fence_put(fence);
157 #endif /* CONFIG_SYNC */