2 * Copyright (C) 2011-2012 ARM Limited. All rights reserved.
4 * This program is free software and is provided to you under the terms of the GNU General Public License version 2
5 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
7 * A copy of the licence is included with the program, and can also be obtained from Free Software
8 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12 * @file mali_sync_user.c
18 #include <linux/sched.h>
19 #include <linux/fdtable.h>
20 #include <linux/file.h>
22 #include <linux/module.h>
23 #include <linux/anon_inodes.h>
24 #include <linux/version.h>
25 #include <asm/uaccess.h>
28 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0)
30 #include "mali_kernel_common.h"
31 #include "mali_sync.h"
33 static int mali_stream_close(struct inode * inode, struct file * file)
35 struct sync_timeline * tl;
36 tl = (struct sync_timeline*)file->private_data;
38 sync_timeline_destroy(tl);
42 static struct file_operations stream_fops =
45 .release = mali_stream_close,
48 _mali_osk_errcode_t mali_stream_create(const char * name, int *out_fd)
50 struct sync_timeline * tl;
53 tl = mali_sync_timeline_alloc(name);
56 return _MALI_OSK_ERR_FAULT;
59 *out_fd = anon_inode_getfd(name, &stream_fops, tl, O_RDONLY | O_CLOEXEC);
63 sync_timeline_destroy(tl);
64 return _MALI_OSK_ERR_FAULT;
68 return _MALI_OSK_ERR_OK;
72 mali_sync_pt *mali_stream_create_point(int tl_fd)
74 struct sync_timeline *tl;
78 tl_file = fget(tl_fd);
82 if (tl_file->f_op != &stream_fops)
88 tl = tl_file->private_data;
90 pt = mali_sync_pt_alloc(tl);
103 int mali_stream_create_fence(mali_sync_pt *pt)
105 struct sync_fence *fence;
106 struct fdtable * fdt;
107 struct files_struct * files;
110 fence = sync_fence_create("mali_fence", pt);
118 /* create a fd representing the fence */
119 fd = get_unused_fd();
122 sync_fence_put(fence);
126 files = current->files;
127 spin_lock(&files->file_lock);
128 fdt = files_fdtable(files);
129 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0)
130 __set_close_on_exec(fd, fdt);
132 FD_SET(fd, fdt->close_on_exec);
134 spin_unlock(&files->file_lock);
136 /* bind fence to the new fd */
137 sync_fence_install(fence, fd);
143 _mali_osk_errcode_t mali_fence_validate(int fd)
145 struct sync_fence * fence;
146 fence = sync_fence_fdget(fd);
149 sync_fence_put(fence);
150 return _MALI_OSK_ERR_OK;
154 return _MALI_OSK_ERR_FAULT;
159 #endif /* CONFIG_SYNC */