summaryrefstree
path: root/kernel/drivers/vision/vision-core/vision-ioctl.c
blob: 289a3772e3453b6c90a16ef8848c8593fa709f03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
 * Samsung Exynos SoC series VPU driver
 *
 * Copyright (c) 2015 Samsung Electronics Co., Ltd
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#include <linux/module.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/string.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/kmod.h>
#include <linux/slab.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/device.h>
#include <asm/uaccess.h>

#include "vision-config.h"
#include "vision-dev.h"
#include "vision-ioctl.h"

long vertex_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
	int ret = 0;
	struct vision_device *vdev = vision_devdata(file);
	const struct vertex_ioctl_ops *ops = vdev->ioctl_ops;
	char sbuf[128];
	void *mbuf = NULL;
	void *parg = (void *)arg;

	if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
		parg = sbuf;
	} else {
		/* too big to allocate from stack */
		mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
		if (NULL == mbuf) {
			vision_err("kmalloc is fail\n");
			ret = -ENOMEM;
			goto p_err;
		}

		parg = mbuf;
	}

	ret = copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd));
	if (ret) {
		vision_err("copy_from_user is fail(%d)\n", ret);
		goto p_err;
	}

	switch (cmd) {
	case VS4L_VERTEXIOC_S_GRAPH:
		{
			ret = ops->vertexioc_s_graph(file, parg);
			if (ret) {
				vision_err("vertexioc_s_graph is fail(%d)\n", ret);
				goto p_err;
			}
		}
		break;
	case VS4L_VERTEXIOC_S_FORMAT:
		{
			ret = ops->vertexioc_s_format(file, parg);
			if (ret) {
				vision_err("vertexioc_s_format is fail(%d)\n", ret);
				goto p_err;
			}
		}
		break;
	case VS4L_VERTEXIOC_S_PARAM:
		{
			ret = ops->vertexioc_s_param(file, parg);
			if (ret) {
				vision_err("vertexioc_s_param is fail(%d)\n", ret);
				goto p_err;
			}
		}
		break;
	case VS4L_VERTEXIOC_S_CTRL:
		{
			ret = ops->vertexioc_s_ctrl(file, parg);
			if (ret) {
				vision_err("vertexioc_s_ctrl is fail(%d)\n", ret);
				goto p_err;
			}
		}
		break;
	case VS4L_VERTEXIOC_STREAM_ON:
		{
			ret = ops->vertexioc_streamon(file);
			if (ret) {
				vision_err("vertexioc_streamon is fail(%d)\n", ret);
				goto p_err;
			}
		}
		break;
	case VS4L_VERTEXIOC_STREAM_OFF:
		{
			ret = ops->vertexioc_streamoff(file);
			if (ret) {
				vision_err("vertexioc_streamoff is fail(%d)\n", ret);
				goto p_err;
			}
		}
		break;
	case VS4L_VERTEXIOC_QBUF:
		{
#if 0
			ret = ops->vertexioc_qbuf(file, parg);
			if (ret) {
				vision_err("vertexioc_qbuf is fail(%d)\n", ret);
				goto p_err;
			}
#endif
			ret = -EINVAL;
			vision_info("SCore:qbuf is not supported at 64-bit\n");
		}
		break;
	case VS4L_VERTEXIOC_DQBUF:
		{
			ret = ops->vertexioc_dqbuf(file, parg);
			if (ret) {
				vision_err("vertexioc_dqbuf is fail(%d)\n", ret);
				goto p_err;
			}
		}
		break;
	default:
		vision_err("%x iocontrol is not supported(%lx, %zd)\n", cmd, VS4L_VERTEXIOC_S_FORMAT, sizeof(struct vs4l_format_list));
		break;
	}

p_err:
	kfree(mbuf);
	return ret;
}