2 * drivers/dma-buf/sw_sync.c
4 * Copyright (C) 2012 Google, Inc.
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
17 #include <linux/file.h>
19 #include <linux/uaccess.h>
20 #include <linux/sync_file.h>
22 #include "uapi/sw_sync.h"
28 * improper use of this can result in deadlocking kernel drivers from userspace.
31 /* opening sw_sync create a new sync obj */
32 static int sw_sync_debugfs_open(struct inode *inode, struct file *file)
34 struct sync_timeline *obj;
35 char task_comm[TASK_COMM_LEN];
37 get_task_comm(task_comm, current);
39 obj = sync_timeline_create("sw_sync", task_comm);
43 file->private_data = obj;
48 static int sw_sync_debugfs_release(struct inode *inode, struct file *file)
50 struct sync_timeline *obj = file->private_data;
52 sync_timeline_destroy(obj);
56 static long sw_sync_ioctl_create_fence(struct sync_timeline *obj,
59 int fd = get_unused_fd_flags(O_CLOEXEC);
62 struct sync_file *sync_file;
63 struct sw_sync_create_fence_data data;
68 if (copy_from_user(&data, (void __user *)arg, sizeof(data))) {
73 pt = sync_pt_create(obj, sizeof(*pt), data.value);
79 sync_file = sync_file_create(&pt->base);
87 if (copy_to_user((void __user *)arg, &data, sizeof(data))) {
88 fput(sync_file->file);
93 fd_install(fd, sync_file->file);
102 static long sw_sync_ioctl_inc(struct sync_timeline *obj, unsigned long arg)
106 if (copy_from_user(&value, (void __user *)arg, sizeof(value)))
109 sync_timeline_signal(obj, value);
114 static long sw_sync_ioctl(struct file *file, unsigned int cmd,
117 struct sync_timeline *obj = file->private_data;
120 case SW_SYNC_IOC_CREATE_FENCE:
121 return sw_sync_ioctl_create_fence(obj, arg);
123 case SW_SYNC_IOC_INC:
124 return sw_sync_ioctl_inc(obj, arg);
131 const struct file_operations sw_sync_debugfs_fops = {
132 .open = sw_sync_debugfs_open,
133 .release = sw_sync_debugfs_release,
134 .unlocked_ioctl = sw_sync_ioctl,
135 .compat_ioctl = sw_sync_ioctl,