3 * (C) COPYRIGHT 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 <kbase/src/linux/mali_kbase_sync.h>
36 #include <kbase/mali_base_kernel_sync.h>
38 static int kbase_stream_close(struct inode *inode, struct file *file)
40 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 mali_error kbase_stream_create(const char *name, int *const out_fd)
54 struct sync_timeline *tl;
57 tl = kbase_sync_timeline_alloc(name);
59 return MALI_ERROR_FUNCTION_FAILED;
61 *out_fd = anon_inode_getfd(name, &stream_fops, tl, O_RDONLY | O_CLOEXEC);
64 sync_timeline_destroy(tl);
65 return MALI_ERROR_FUNCTION_FAILED;
67 return MALI_ERROR_NONE;
71 int kbase_stream_create_fence(int tl_fd)
73 struct sync_timeline *tl;
75 struct sync_fence *fence;
76 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0)
77 struct files_struct *files;
83 tl_file = fget(tl_fd);
87 if (tl_file->f_op != &stream_fops) {
92 tl = tl_file->private_data;
94 pt = kbase_sync_pt_alloc(tl);
100 fence = sync_fence_create("mali_fence", pt);
107 /* from here the fence owns the sync_pt */
109 /* create a fd representing the fence */
110 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0)
111 fd = get_unused_fd_flags(O_RDWR | O_CLOEXEC);
113 sync_fence_put(fence);
117 fd = get_unused_fd();
119 sync_fence_put(fence);
123 files = current->files;
124 spin_lock(&files->file_lock);
125 fdt = files_fdtable(files);
126 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 0)
127 __set_close_on_exec(fd, fdt);
129 FD_SET(fd, fdt->close_on_exec);
131 spin_unlock(&files->file_lock);
132 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0) */
134 /* bind fence to the new fd */
135 sync_fence_install(fence, fd);
143 mali_error kbase_fence_validate(int fd)
145 struct sync_fence *fence;
146 fence = sync_fence_fdget(fd);
148 sync_fence_put(fence);
149 return MALI_ERROR_NONE;
151 return MALI_ERROR_FUNCTION_FAILED;
155 #endif /* CONFIG_SYNC */