blob: 8f7a6a454a4ca72460ac7e3c793a8115c94ea66d [file] [log] [blame]
Philippe De Muytercf664a62006-01-09 15:24:59 -02001/*
2 * ioctl32.c: Conversion between 32bit and 64bit native ioctls.
3 * Separated from fs stuff by Arnd Bergmann <arnd@arndb.de>
4 *
5 * Copyright (C) 1997-2000 Jakub Jelinek (jakub@redhat.com)
6 * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be)
7 * Copyright (C) 2001,2002 Andi Kleen, SuSE Labs
Pavel Macheka2531292010-07-18 14:27:13 +02008 * Copyright (C) 2003 Pavel Machek (pavel@ucw.cz)
Philippe De Muytercf664a62006-01-09 15:24:59 -02009 * Copyright (C) 2005 Philippe De Muyter (phdm@macqel.be)
Hans Verkuil92f45ba2008-12-21 10:35:25 -030010 * Copyright (C) 2008 Hans Verkuil <hverkuil@xs4all.nl>
Philippe De Muytercf664a62006-01-09 15:24:59 -020011 *
12 * These routines maintain argument size conversion between 32bit and 64bit
13 * ioctls.
14 */
15
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -020016#include <linux/compat.h>
Nickolay V. Shmyrev133b7352006-01-09 15:24:58 -020017#include <linux/module.h>
Laurent Pinchartb9d0aa62011-12-18 20:41:19 -030018#include <linux/videodev2.h>
Hans Verkuiled45ce22012-08-10 06:07:12 -030019#include <linux/v4l2-subdev.h>
Laurent Pinchartb9d0aa62011-12-18 20:41:19 -030020#include <media/v4l2-dev.h>
Mauro Carvalho Chehab28644622008-07-20 20:26:54 -030021#include <media/v4l2-ioctl.h>
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -020022
Hans Verkuil069b7472008-12-30 07:04:34 -030023static long native_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -020024{
Hans Verkuil069b7472008-12-30 07:04:34 -030025 long ret = -ENOIOCTLCMD;
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -020026
Philippe De Muyter13d133b2006-01-09 15:25:00 -020027 if (file->f_op->unlocked_ioctl)
28 ret = file->f_op->unlocked_ioctl(file, cmd, arg);
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -020029
30 return ret;
31}
32
33
Hans Verkuild1f81da2008-10-22 00:04:45 -030034struct v4l2_clip32 {
Philippe De Muytercf664a62006-01-09 15:24:59 -020035 struct v4l2_rect c;
36 compat_caddr_t next;
37};
38
Hans Verkuild1f81da2008-10-22 00:04:45 -030039struct v4l2_window32 {
Philippe De Muytercf664a62006-01-09 15:24:59 -020040 struct v4l2_rect w;
Sakari Ailus6016af82012-05-10 02:02:07 -030041 __u32 field; /* enum v4l2_field */
Philippe De Muytercf664a62006-01-09 15:24:59 -020042 __u32 chromakey;
43 compat_caddr_t clips; /* actually struct v4l2_clip32 * */
44 __u32 clipcount;
45 compat_caddr_t bitmap;
46};
47
48static int get_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 __user *up)
49{
Guy Martina113bc72006-01-11 23:40:51 -020050 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_window32)) ||
51 copy_from_user(&kp->w, &up->w, sizeof(up->w)) ||
52 get_user(kp->field, &up->field) ||
53 get_user(kp->chromakey, &up->chromakey) ||
54 get_user(kp->clipcount, &up->clipcount))
55 return -EFAULT;
Philippe De Muytercf664a62006-01-09 15:24:59 -020056 if (kp->clipcount > 2048)
57 return -EINVAL;
58 if (kp->clipcount) {
Al Viro5b1a43d2006-02-01 05:24:20 -050059 struct v4l2_clip32 __user *uclips;
60 struct v4l2_clip __user *kclips;
Philippe De Muytercf664a62006-01-09 15:24:59 -020061 int n = kp->clipcount;
Al Viro5b1a43d2006-02-01 05:24:20 -050062 compat_caddr_t p;
Philippe De Muytercf664a62006-01-09 15:24:59 -020063
Al Viro5b1a43d2006-02-01 05:24:20 -050064 if (get_user(p, &up->clips))
65 return -EFAULT;
66 uclips = compat_ptr(p);
Philippe De Muytercf664a62006-01-09 15:24:59 -020067 kclips = compat_alloc_user_space(n * sizeof(struct v4l2_clip));
68 kp->clips = kclips;
69 while (--n >= 0) {
Al Viro5b1a43d2006-02-01 05:24:20 -050070 if (copy_in_user(&kclips->c, &uclips->c, sizeof(uclips->c)))
Guy Martina113bc72006-01-11 23:40:51 -020071 return -EFAULT;
Al Viro5b1a43d2006-02-01 05:24:20 -050072 if (put_user(n ? kclips + 1 : NULL, &kclips->next))
73 return -EFAULT;
Philippe De Muytercf664a62006-01-09 15:24:59 -020074 uclips += 1;
75 kclips += 1;
76 }
77 } else
Al Viro5b1a43d2006-02-01 05:24:20 -050078 kp->clips = NULL;
Philippe De Muytercf664a62006-01-09 15:24:59 -020079 return 0;
80}
81
82static int put_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 __user *up)
83{
Roel Kluinf2e6c6a2009-12-16 11:35:45 -030084 if (copy_to_user(&up->w, &kp->w, sizeof(kp->w)) ||
Guy Martina113bc72006-01-11 23:40:51 -020085 put_user(kp->field, &up->field) ||
86 put_user(kp->chromakey, &up->chromakey) ||
87 put_user(kp->clipcount, &up->clipcount))
88 return -EFAULT;
Philippe De Muytercf664a62006-01-09 15:24:59 -020089 return 0;
90}
91
92static inline int get_v4l2_pix_format(struct v4l2_pix_format *kp, struct v4l2_pix_format __user *up)
93{
Al Viro5b1a43d2006-02-01 05:24:20 -050094 if (copy_from_user(kp, up, sizeof(struct v4l2_pix_format)))
95 return -EFAULT;
Guy Martina113bc72006-01-11 23:40:51 -020096 return 0;
Philippe De Muytercf664a62006-01-09 15:24:59 -020097}
98
Pawel Osciak52a30822010-07-29 14:56:47 -030099static inline int get_v4l2_pix_format_mplane(struct v4l2_pix_format_mplane *kp,
100 struct v4l2_pix_format_mplane __user *up)
101{
102 if (copy_from_user(kp, up, sizeof(struct v4l2_pix_format_mplane)))
103 return -EFAULT;
104 return 0;
105}
106
Philippe De Muytercf664a62006-01-09 15:24:59 -0200107static inline int put_v4l2_pix_format(struct v4l2_pix_format *kp, struct v4l2_pix_format __user *up)
108{
Al Viro5b1a43d2006-02-01 05:24:20 -0500109 if (copy_to_user(up, kp, sizeof(struct v4l2_pix_format)))
110 return -EFAULT;
Guy Martina113bc72006-01-11 23:40:51 -0200111 return 0;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200112}
113
Pawel Osciak52a30822010-07-29 14:56:47 -0300114static inline int put_v4l2_pix_format_mplane(struct v4l2_pix_format_mplane *kp,
115 struct v4l2_pix_format_mplane __user *up)
116{
117 if (copy_to_user(up, kp, sizeof(struct v4l2_pix_format_mplane)))
118 return -EFAULT;
119 return 0;
120}
121
Philippe De Muytercf664a62006-01-09 15:24:59 -0200122static inline int get_v4l2_vbi_format(struct v4l2_vbi_format *kp, struct v4l2_vbi_format __user *up)
123{
Al Viro5b1a43d2006-02-01 05:24:20 -0500124 if (copy_from_user(kp, up, sizeof(struct v4l2_vbi_format)))
125 return -EFAULT;
Guy Martina113bc72006-01-11 23:40:51 -0200126 return 0;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200127}
128
129static inline int put_v4l2_vbi_format(struct v4l2_vbi_format *kp, struct v4l2_vbi_format __user *up)
130{
Al Viro5b1a43d2006-02-01 05:24:20 -0500131 if (copy_to_user(up, kp, sizeof(struct v4l2_vbi_format)))
132 return -EFAULT;
Guy Martina113bc72006-01-11 23:40:51 -0200133 return 0;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200134}
135
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300136static inline int get_v4l2_sliced_vbi_format(struct v4l2_sliced_vbi_format *kp, struct v4l2_sliced_vbi_format __user *up)
137{
138 if (copy_from_user(kp, up, sizeof(struct v4l2_sliced_vbi_format)))
139 return -EFAULT;
140 return 0;
141}
142
143static inline int put_v4l2_sliced_vbi_format(struct v4l2_sliced_vbi_format *kp, struct v4l2_sliced_vbi_format __user *up)
144{
145 if (copy_to_user(up, kp, sizeof(struct v4l2_sliced_vbi_format)))
146 return -EFAULT;
147 return 0;
148}
149
Hans Verkuild1f81da2008-10-22 00:04:45 -0300150struct v4l2_format32 {
Sakari Ailus6016af82012-05-10 02:02:07 -0300151 __u32 type; /* enum v4l2_buf_type */
Hans Verkuild1f81da2008-10-22 00:04:45 -0300152 union {
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300153 struct v4l2_pix_format pix;
Pawel Osciak52a30822010-07-29 14:56:47 -0300154 struct v4l2_pix_format_mplane pix_mp;
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300155 struct v4l2_window32 win;
156 struct v4l2_vbi_format vbi;
157 struct v4l2_sliced_vbi_format sliced;
Hans Verkuild1f81da2008-10-22 00:04:45 -0300158 __u8 raw_data[200]; /* user-defined */
Philippe De Muytercf664a62006-01-09 15:24:59 -0200159 } fmt;
160};
161
Guennadi Liakhovetski09362ec2011-09-07 18:07:23 -0300162/**
163 * struct v4l2_create_buffers32 - VIDIOC_CREATE_BUFS32 argument
164 * @index: on return, index of the first created buffer
165 * @count: entry: number of requested buffers,
166 * return: number of created buffers
167 * @memory: buffer memory type
168 * @format: frame format, for which buffers are requested
169 * @reserved: future extensions
170 */
Guennadi Liakhovetski21501582011-09-28 11:34:06 -0300171struct v4l2_create_buffers32 {
Guennadi Liakhovetski09362ec2011-09-07 18:07:23 -0300172 __u32 index;
Guennadi Liakhovetski21501582011-09-28 11:34:06 -0300173 __u32 count;
Sakari Ailus6016af82012-05-10 02:02:07 -0300174 __u32 memory; /* enum v4l2_memory */
Guennadi Liakhovetski09362ec2011-09-07 18:07:23 -0300175 struct v4l2_format32 format;
Guennadi Liakhovetski21501582011-09-28 11:34:06 -0300176 __u32 reserved[8];
177};
178
179static int __get_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up)
Philippe De Muytercf664a62006-01-09 15:24:59 -0200180{
Philippe De Muytercf664a62006-01-09 15:24:59 -0200181 switch (kp->type) {
182 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300183 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Philippe De Muytercf664a62006-01-09 15:24:59 -0200184 return get_v4l2_pix_format(&kp->fmt.pix, &up->fmt.pix);
Pawel Osciak52a30822010-07-29 14:56:47 -0300185 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
186 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
187 return get_v4l2_pix_format_mplane(&kp->fmt.pix_mp,
188 &up->fmt.pix_mp);
Philippe De Muytercf664a62006-01-09 15:24:59 -0200189 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300190 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Philippe De Muytercf664a62006-01-09 15:24:59 -0200191 return get_v4l2_window32(&kp->fmt.win, &up->fmt.win);
192 case V4L2_BUF_TYPE_VBI_CAPTURE:
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300193 case V4L2_BUF_TYPE_VBI_OUTPUT:
Philippe De Muytercf664a62006-01-09 15:24:59 -0200194 return get_v4l2_vbi_format(&kp->fmt.vbi, &up->fmt.vbi);
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300195 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
196 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
197 return get_v4l2_sliced_vbi_format(&kp->fmt.sliced, &up->fmt.sliced);
Philippe De Muytercf664a62006-01-09 15:24:59 -0200198 default:
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300199 printk(KERN_INFO "compat_ioctl32: unexpected VIDIOC_FMT type %d\n",
Philippe De Muytercf664a62006-01-09 15:24:59 -0200200 kp->type);
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300201 return -EINVAL;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200202 }
203}
204
Guennadi Liakhovetski21501582011-09-28 11:34:06 -0300205static int get_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up)
Philippe De Muytercf664a62006-01-09 15:24:59 -0200206{
Guennadi Liakhovetski21501582011-09-28 11:34:06 -0300207 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_format32)) ||
208 get_user(kp->type, &up->type))
209 return -EFAULT;
210 return __get_v4l2_format32(kp, up);
211}
212
213static int get_v4l2_create32(struct v4l2_create_buffers *kp, struct v4l2_create_buffers32 __user *up)
214{
215 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_create_buffers32)) ||
216 copy_from_user(kp, up, offsetof(struct v4l2_create_buffers32, format.fmt)))
217 return -EFAULT;
218 return __get_v4l2_format32(&kp->format, &up->format);
219}
220
221static int __put_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up)
222{
Philippe De Muytercf664a62006-01-09 15:24:59 -0200223 switch (kp->type) {
224 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300225 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Philippe De Muytercf664a62006-01-09 15:24:59 -0200226 return put_v4l2_pix_format(&kp->fmt.pix, &up->fmt.pix);
Pawel Osciak52a30822010-07-29 14:56:47 -0300227 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
228 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
229 return put_v4l2_pix_format_mplane(&kp->fmt.pix_mp,
230 &up->fmt.pix_mp);
Philippe De Muytercf664a62006-01-09 15:24:59 -0200231 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300232 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Philippe De Muytercf664a62006-01-09 15:24:59 -0200233 return put_v4l2_window32(&kp->fmt.win, &up->fmt.win);
234 case V4L2_BUF_TYPE_VBI_CAPTURE:
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300235 case V4L2_BUF_TYPE_VBI_OUTPUT:
Philippe De Muytercf664a62006-01-09 15:24:59 -0200236 return put_v4l2_vbi_format(&kp->fmt.vbi, &up->fmt.vbi);
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300237 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
238 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
239 return put_v4l2_sliced_vbi_format(&kp->fmt.sliced, &up->fmt.sliced);
Philippe De Muytercf664a62006-01-09 15:24:59 -0200240 default:
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300241 printk(KERN_INFO "compat_ioctl32: unexpected VIDIOC_FMT type %d\n",
242 kp->type);
243 return -EINVAL;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200244 }
245}
246
Guennadi Liakhovetski21501582011-09-28 11:34:06 -0300247static int put_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up)
248{
249 if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_format32)) ||
250 put_user(kp->type, &up->type))
251 return -EFAULT;
252 return __put_v4l2_format32(kp, up);
253}
254
255static int put_v4l2_create32(struct v4l2_create_buffers *kp, struct v4l2_create_buffers32 __user *up)
256{
257 if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_create_buffers32)) ||
258 copy_to_user(up, kp, offsetof(struct v4l2_create_buffers32, format.fmt)))
259 return -EFAULT;
260 return __put_v4l2_format32(&kp->format, &up->format);
261}
262
Hans Verkuild1f81da2008-10-22 00:04:45 -0300263struct v4l2_standard32 {
Philippe De Muytercf664a62006-01-09 15:24:59 -0200264 __u32 index;
265 __u32 id[2]; /* __u64 would get the alignment wrong */
266 __u8 name[24];
267 struct v4l2_fract frameperiod; /* Frames, not fields */
268 __u32 framelines;
269 __u32 reserved[4];
270};
271
272static int get_v4l2_standard32(struct v4l2_standard *kp, struct v4l2_standard32 __user *up)
273{
274 /* other fields are not set by the user, nor used by the driver */
Guy Martina113bc72006-01-11 23:40:51 -0200275 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_standard32)) ||
276 get_user(kp->index, &up->index))
277 return -EFAULT;
278 return 0;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200279}
280
281static int put_v4l2_standard32(struct v4l2_standard *kp, struct v4l2_standard32 __user *up)
282{
Hans Verkuild1f81da2008-10-22 00:04:45 -0300283 if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_standard32)) ||
Guy Martina113bc72006-01-11 23:40:51 -0200284 put_user(kp->index, &up->index) ||
285 copy_to_user(up->id, &kp->id, sizeof(__u64)) ||
286 copy_to_user(up->name, kp->name, 24) ||
287 copy_to_user(&up->frameperiod, &kp->frameperiod, sizeof(kp->frameperiod)) ||
288 put_user(kp->framelines, &up->framelines) ||
289 copy_to_user(up->reserved, kp->reserved, 4 * sizeof(__u32)))
290 return -EFAULT;
291 return 0;
292}
293
Pawel Osciak52a30822010-07-29 14:56:47 -0300294struct v4l2_plane32 {
295 __u32 bytesused;
296 __u32 length;
297 union {
298 __u32 mem_offset;
299 compat_long_t userptr;
Sumit Semwal051c7782012-06-14 10:37:35 -0300300 __s32 fd;
Pawel Osciak52a30822010-07-29 14:56:47 -0300301 } m;
302 __u32 data_offset;
303 __u32 reserved[11];
304};
305
Hans Verkuild1f81da2008-10-22 00:04:45 -0300306struct v4l2_buffer32 {
Philippe De Muytercf664a62006-01-09 15:24:59 -0200307 __u32 index;
Sakari Ailus6016af82012-05-10 02:02:07 -0300308 __u32 type; /* enum v4l2_buf_type */
Philippe De Muytercf664a62006-01-09 15:24:59 -0200309 __u32 bytesused;
310 __u32 flags;
Sakari Ailus6016af82012-05-10 02:02:07 -0300311 __u32 field; /* enum v4l2_field */
Philippe De Muytercf664a62006-01-09 15:24:59 -0200312 struct compat_timeval timestamp;
313 struct v4l2_timecode timecode;
314 __u32 sequence;
315
316 /* memory location */
Sakari Ailus6016af82012-05-10 02:02:07 -0300317 __u32 memory; /* enum v4l2_memory */
Philippe De Muytercf664a62006-01-09 15:24:59 -0200318 union {
319 __u32 offset;
320 compat_long_t userptr;
Pawel Osciak52a30822010-07-29 14:56:47 -0300321 compat_caddr_t planes;
Sumit Semwal051c7782012-06-14 10:37:35 -0300322 __s32 fd;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200323 } m;
324 __u32 length;
Sakari Ailus2b719d72012-05-02 09:40:03 -0300325 __u32 reserved2;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200326 __u32 reserved;
327};
328
Pawel Osciak52a30822010-07-29 14:56:47 -0300329static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
330 enum v4l2_memory memory)
331{
332 void __user *up_pln;
333 compat_long_t p;
334
335 if (copy_in_user(up, up32, 2 * sizeof(__u32)) ||
336 copy_in_user(&up->data_offset, &up32->data_offset,
337 sizeof(__u32)))
338 return -EFAULT;
339
340 if (memory == V4L2_MEMORY_USERPTR) {
341 if (get_user(p, &up32->m.userptr))
342 return -EFAULT;
343 up_pln = compat_ptr(p);
344 if (put_user((unsigned long)up_pln, &up->m.userptr))
345 return -EFAULT;
Sumit Semwal051c7782012-06-14 10:37:35 -0300346 } else if (memory == V4L2_MEMORY_DMABUF) {
347 if (copy_in_user(&up->m.fd, &up32->m.fd, sizeof(int)))
348 return -EFAULT;
Pawel Osciak52a30822010-07-29 14:56:47 -0300349 } else {
350 if (copy_in_user(&up->m.mem_offset, &up32->m.mem_offset,
351 sizeof(__u32)))
352 return -EFAULT;
353 }
354
355 return 0;
356}
357
358static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
359 enum v4l2_memory memory)
360{
361 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
362 copy_in_user(&up32->data_offset, &up->data_offset,
363 sizeof(__u32)))
364 return -EFAULT;
365
366 /* For MMAP, driver might've set up the offset, so copy it back.
367 * USERPTR stays the same (was userspace-provided), so no copying. */
368 if (memory == V4L2_MEMORY_MMAP)
369 if (copy_in_user(&up32->m.mem_offset, &up->m.mem_offset,
370 sizeof(__u32)))
371 return -EFAULT;
Sumit Semwal051c7782012-06-14 10:37:35 -0300372 /* For DMABUF, driver might've set up the fd, so copy it back. */
373 if (memory == V4L2_MEMORY_DMABUF)
374 if (copy_in_user(&up32->m.fd, &up->m.fd,
375 sizeof(int)))
376 return -EFAULT;
Pawel Osciak52a30822010-07-29 14:56:47 -0300377
378 return 0;
379}
380
Philippe De Muytercf664a62006-01-09 15:24:59 -0200381static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user *up)
382{
Pawel Osciak52a30822010-07-29 14:56:47 -0300383 struct v4l2_plane32 __user *uplane32;
384 struct v4l2_plane __user *uplane;
385 compat_caddr_t p;
386 int num_planes;
387 int ret;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200388
Guy Martina113bc72006-01-11 23:40:51 -0200389 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_buffer32)) ||
390 get_user(kp->index, &up->index) ||
391 get_user(kp->type, &up->type) ||
392 get_user(kp->flags, &up->flags) ||
Mauro Carvalho Chehabcc831f82012-07-05 21:48:58 -0300393 get_user(kp->memory, &up->memory))
Guy Martina113bc72006-01-11 23:40:51 -0200394 return -EFAULT;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200395
Pawel Osciak52a30822010-07-29 14:56:47 -0300396 if (V4L2_TYPE_IS_OUTPUT(kp->type))
397 if (get_user(kp->bytesused, &up->bytesused) ||
398 get_user(kp->field, &up->field) ||
399 get_user(kp->timestamp.tv_sec, &up->timestamp.tv_sec) ||
400 get_user(kp->timestamp.tv_usec,
401 &up->timestamp.tv_usec))
Al Viro5b1a43d2006-02-01 05:24:20 -0500402 return -EFAULT;
403
Pawel Osciak52a30822010-07-29 14:56:47 -0300404 if (V4L2_TYPE_IS_MULTIPLANAR(kp->type)) {
405 if (get_user(kp->length, &up->length))
406 return -EFAULT;
407
408 num_planes = kp->length;
409 if (num_planes == 0) {
410 kp->m.planes = NULL;
411 /* num_planes == 0 is legal, e.g. when userspace doesn't
412 * need planes array on DQBUF*/
413 return 0;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200414 }
Pawel Osciak52a30822010-07-29 14:56:47 -0300415
416 if (get_user(p, &up->m.planes))
Guy Martina113bc72006-01-11 23:40:51 -0200417 return -EFAULT;
Pawel Osciak52a30822010-07-29 14:56:47 -0300418
419 uplane32 = compat_ptr(p);
420 if (!access_ok(VERIFY_READ, uplane32,
421 num_planes * sizeof(struct v4l2_plane32)))
422 return -EFAULT;
423
424 /* We don't really care if userspace decides to kill itself
425 * by passing a very big num_planes value */
426 uplane = compat_alloc_user_space(num_planes *
427 sizeof(struct v4l2_plane));
428 kp->m.planes = uplane;
429
430 while (--num_planes >= 0) {
431 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
432 if (ret)
433 return ret;
434 ++uplane;
435 ++uplane32;
436 }
437 } else {
438 switch (kp->memory) {
439 case V4L2_MEMORY_MMAP:
440 if (get_user(kp->length, &up->length) ||
441 get_user(kp->m.offset, &up->m.offset))
442 return -EFAULT;
443 break;
444 case V4L2_MEMORY_USERPTR:
445 {
446 compat_long_t tmp;
447
448 if (get_user(kp->length, &up->length) ||
449 get_user(tmp, &up->m.userptr))
450 return -EFAULT;
451
452 kp->m.userptr = (unsigned long)compat_ptr(tmp);
453 }
454 break;
455 case V4L2_MEMORY_OVERLAY:
456 if (get_user(kp->m.offset, &up->m.offset))
457 return -EFAULT;
458 break;
Sumit Semwal051c7782012-06-14 10:37:35 -0300459 case V4L2_MEMORY_DMABUF:
460 if (get_user(kp->m.fd, &up->m.fd))
461 return -EFAULT;
462 break;
Pawel Osciak52a30822010-07-29 14:56:47 -0300463 }
Philippe De Muytercf664a62006-01-09 15:24:59 -0200464 }
Pawel Osciak52a30822010-07-29 14:56:47 -0300465
Philippe De Muytercf664a62006-01-09 15:24:59 -0200466 return 0;
467}
468
469static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user *up)
470{
Pawel Osciak52a30822010-07-29 14:56:47 -0300471 struct v4l2_plane32 __user *uplane32;
472 struct v4l2_plane __user *uplane;
473 compat_caddr_t p;
474 int num_planes;
475 int ret;
476
Guy Martina113bc72006-01-11 23:40:51 -0200477 if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_buffer32)) ||
478 put_user(kp->index, &up->index) ||
479 put_user(kp->type, &up->type) ||
480 put_user(kp->flags, &up->flags) ||
Mauro Carvalho Chehabcc831f82012-07-05 21:48:58 -0300481 put_user(kp->memory, &up->memory))
Guy Martina113bc72006-01-11 23:40:51 -0200482 return -EFAULT;
Pawel Osciak52a30822010-07-29 14:56:47 -0300483
Guy Martina113bc72006-01-11 23:40:51 -0200484 if (put_user(kp->bytesused, &up->bytesused) ||
485 put_user(kp->field, &up->field) ||
486 put_user(kp->timestamp.tv_sec, &up->timestamp.tv_sec) ||
487 put_user(kp->timestamp.tv_usec, &up->timestamp.tv_usec) ||
488 copy_to_user(&up->timecode, &kp->timecode, sizeof(struct v4l2_timecode)) ||
489 put_user(kp->sequence, &up->sequence) ||
Sakari Ailus2b719d72012-05-02 09:40:03 -0300490 put_user(kp->reserved2, &up->reserved2) ||
Mauro Carvalho Chehabcc831f82012-07-05 21:48:58 -0300491 put_user(kp->reserved, &up->reserved))
Guy Martina113bc72006-01-11 23:40:51 -0200492 return -EFAULT;
Pawel Osciak52a30822010-07-29 14:56:47 -0300493
494 if (V4L2_TYPE_IS_MULTIPLANAR(kp->type)) {
495 num_planes = kp->length;
496 if (num_planes == 0)
497 return 0;
498
499 uplane = kp->m.planes;
500 if (get_user(p, &up->m.planes))
501 return -EFAULT;
502 uplane32 = compat_ptr(p);
503
504 while (--num_planes >= 0) {
505 ret = put_v4l2_plane32(uplane, uplane32, kp->memory);
506 if (ret)
507 return ret;
508 ++uplane;
509 ++uplane32;
510 }
511 } else {
512 switch (kp->memory) {
513 case V4L2_MEMORY_MMAP:
514 if (put_user(kp->length, &up->length) ||
515 put_user(kp->m.offset, &up->m.offset))
516 return -EFAULT;
517 break;
518 case V4L2_MEMORY_USERPTR:
519 if (put_user(kp->length, &up->length) ||
520 put_user(kp->m.userptr, &up->m.userptr))
521 return -EFAULT;
522 break;
523 case V4L2_MEMORY_OVERLAY:
524 if (put_user(kp->m.offset, &up->m.offset))
525 return -EFAULT;
526 break;
Sumit Semwal051c7782012-06-14 10:37:35 -0300527 case V4L2_MEMORY_DMABUF:
528 if (put_user(kp->m.fd, &up->m.fd))
529 return -EFAULT;
530 break;
Pawel Osciak52a30822010-07-29 14:56:47 -0300531 }
532 }
533
Philippe De Muytercf664a62006-01-09 15:24:59 -0200534 return 0;
535}
536
Hans Verkuild1f81da2008-10-22 00:04:45 -0300537struct v4l2_framebuffer32 {
Philippe De Muytercf664a62006-01-09 15:24:59 -0200538 __u32 capability;
539 __u32 flags;
540 compat_caddr_t base;
541 struct v4l2_pix_format fmt;
542};
543
Philippe De Muyter13d133b2006-01-09 15:25:00 -0200544static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_framebuffer32 __user *up)
545{
546 u32 tmp;
547
Guy Martina113bc72006-01-11 23:40:51 -0200548 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_framebuffer32)) ||
549 get_user(tmp, &up->base) ||
550 get_user(kp->capability, &up->capability) ||
551 get_user(kp->flags, &up->flags))
552 return -EFAULT;
Philippe De Muyter13d133b2006-01-09 15:25:00 -0200553 kp->base = compat_ptr(tmp);
Philippe De Muyter13d133b2006-01-09 15:25:00 -0200554 get_v4l2_pix_format(&kp->fmt, &up->fmt);
555 return 0;
556}
557
Philippe De Muytercf664a62006-01-09 15:24:59 -0200558static int put_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_framebuffer32 __user *up)
559{
560 u32 tmp = (u32)((unsigned long)kp->base);
561
Hans Verkuild1f81da2008-10-22 00:04:45 -0300562 if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_framebuffer32)) ||
Guy Martina113bc72006-01-11 23:40:51 -0200563 put_user(tmp, &up->base) ||
564 put_user(kp->capability, &up->capability) ||
565 put_user(kp->flags, &up->flags))
566 return -EFAULT;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200567 put_v4l2_pix_format(&kp->fmt, &up->fmt);
568 return 0;
569}
570
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300571struct v4l2_input32 {
572 __u32 index; /* Which input */
573 __u8 name[32]; /* Label */
574 __u32 type; /* Type of input */
575 __u32 audioset; /* Associated audios (bitfield) */
576 __u32 tuner; /* Associated tuner */
577 v4l2_std_id std;
578 __u32 status;
579 __u32 reserved[4];
580} __attribute__ ((packed));
581
582/* The 64-bit v4l2_input struct has extra padding at the end of the struct.
583 Otherwise it is identical to the 32-bit version. */
584static inline int get_v4l2_input32(struct v4l2_input *kp, struct v4l2_input32 __user *up)
Philippe De Muytercf664a62006-01-09 15:24:59 -0200585{
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300586 if (copy_from_user(kp, up, sizeof(struct v4l2_input32)))
Al Viro5b1a43d2006-02-01 05:24:20 -0500587 return -EFAULT;
Guy Martina113bc72006-01-11 23:40:51 -0200588 return 0;
589}
590
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300591static inline int put_v4l2_input32(struct v4l2_input *kp, struct v4l2_input32 __user *up)
Guy Martina113bc72006-01-11 23:40:51 -0200592{
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300593 if (copy_to_user(up, kp, sizeof(struct v4l2_input32)))
Al Viro5b1a43d2006-02-01 05:24:20 -0500594 return -EFAULT;
Guy Martina113bc72006-01-11 23:40:51 -0200595 return 0;
596}
597
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300598struct v4l2_ext_controls32 {
599 __u32 ctrl_class;
600 __u32 count;
601 __u32 error_idx;
602 __u32 reserved[2];
603 compat_caddr_t controls; /* actually struct v4l2_ext_control32 * */
Mauro Carvalho Chehabeb4eecc2006-07-21 18:53:23 -0300604};
605
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300606struct v4l2_ext_control32 {
607 __u32 id;
608 __u32 size;
609 __u32 reserved2[1];
610 union {
611 __s32 value;
612 __s64 value64;
613 compat_caddr_t string; /* actually char * */
614 };
615} __attribute__ ((packed));
616
617/* The following function really belong in v4l2-common, but that causes
618 a circular dependency between modules. We need to think about this, but
619 for now this will do. */
620
621/* Return non-zero if this control is a pointer type. Currently only
Eduardo Valentinfdf82dc2009-08-11 18:49:12 -0300622 type STRING is a pointer type. */
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300623static inline int ctrl_is_pointer(u32 id)
624{
Eduardo Valentinfdf82dc2009-08-11 18:49:12 -0300625 switch (id) {
626 case V4L2_CID_RDS_TX_PS_NAME:
627 case V4L2_CID_RDS_TX_RADIO_TEXT:
628 return 1;
629 default:
630 return 0;
631 }
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300632}
633
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300634static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
Mauro Carvalho Chehabeb4eecc2006-07-21 18:53:23 -0300635{
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300636 struct v4l2_ext_control32 __user *ucontrols;
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300637 struct v4l2_ext_control __user *kcontrols;
638 int n;
639 compat_caddr_t p;
640
641 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_ext_controls32)) ||
642 get_user(kp->ctrl_class, &up->ctrl_class) ||
643 get_user(kp->count, &up->count) ||
644 get_user(kp->error_idx, &up->error_idx) ||
645 copy_from_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
Mauro Carvalho Chehabeb4eecc2006-07-21 18:53:23 -0300646 return -EFAULT;
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300647 n = kp->count;
648 if (n == 0) {
649 kp->controls = NULL;
650 return 0;
651 }
652 if (get_user(p, &up->controls))
653 return -EFAULT;
654 ucontrols = compat_ptr(p);
Pawel Osciak52a30822010-07-29 14:56:47 -0300655 if (!access_ok(VERIFY_READ, ucontrols,
656 n * sizeof(struct v4l2_ext_control32)))
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300657 return -EFAULT;
658 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
659 kp->controls = kcontrols;
660 while (--n >= 0) {
Pawel Osciak52a30822010-07-29 14:56:47 -0300661 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300662 return -EFAULT;
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300663 if (ctrl_is_pointer(kcontrols->id)) {
664 void __user *s;
665
666 if (get_user(p, &ucontrols->string))
667 return -EFAULT;
668 s = compat_ptr(p);
669 if (put_user(s, &kcontrols->string))
670 return -EFAULT;
671 }
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300672 ucontrols++;
673 kcontrols++;
674 }
Mauro Carvalho Chehabeb4eecc2006-07-21 18:53:23 -0300675 return 0;
676}
677
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300678static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200679{
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300680 struct v4l2_ext_control32 __user *ucontrols;
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300681 struct v4l2_ext_control __user *kcontrols = kp->controls;
682 int n = kp->count;
683 compat_caddr_t p;
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200684
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300685 if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_ext_controls32)) ||
686 put_user(kp->ctrl_class, &up->ctrl_class) ||
687 put_user(kp->count, &up->count) ||
688 put_user(kp->error_idx, &up->error_idx) ||
689 copy_to_user(up->reserved, kp->reserved, sizeof(up->reserved)))
690 return -EFAULT;
691 if (!kp->count)
692 return 0;
693
694 if (get_user(p, &up->controls))
695 return -EFAULT;
696 ucontrols = compat_ptr(p);
Pawel Osciak52a30822010-07-29 14:56:47 -0300697 if (!access_ok(VERIFY_WRITE, ucontrols,
698 n * sizeof(struct v4l2_ext_control32)))
Guy Martina113bc72006-01-11 23:40:51 -0200699 return -EFAULT;
700
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300701 while (--n >= 0) {
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300702 unsigned size = sizeof(*ucontrols);
703
704 /* Do not modify the pointer when copying a pointer control.
705 The contents of the pointer was changed, not the pointer
706 itself. */
707 if (ctrl_is_pointer(kcontrols->id))
708 size -= sizeof(ucontrols->value64);
709 if (copy_in_user(ucontrols, kcontrols, size))
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300710 return -EFAULT;
711 ucontrols++;
712 kcontrols++;
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200713 }
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300714 return 0;
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200715}
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300716
Hans Verkuil2330fb82011-06-07 11:43:57 -0300717struct v4l2_event32 {
718 __u32 type;
719 union {
720 __u8 data[64];
721 } u;
722 __u32 pending;
723 __u32 sequence;
724 struct compat_timespec timestamp;
725 __u32 id;
726 __u32 reserved[8];
727};
728
729static int put_v4l2_event32(struct v4l2_event *kp, struct v4l2_event32 __user *up)
730{
731 if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_event32)) ||
732 put_user(kp->type, &up->type) ||
733 copy_to_user(&up->u, &kp->u, sizeof(kp->u)) ||
734 put_user(kp->pending, &up->pending) ||
735 put_user(kp->sequence, &up->sequence) ||
736 put_compat_timespec(&kp->timestamp, &up->timestamp) ||
737 put_user(kp->id, &up->id) ||
738 copy_to_user(up->reserved, kp->reserved, 8 * sizeof(__u32)))
739 return -EFAULT;
740 return 0;
741}
742
Hans Verkuiled45ce22012-08-10 06:07:12 -0300743struct v4l2_subdev_edid32 {
744 __u32 pad;
745 __u32 start_block;
746 __u32 blocks;
747 __u32 reserved[5];
748 compat_caddr_t edid;
749};
750
751static int get_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subdev_edid32 __user *up)
752{
753 u32 tmp;
754
755 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_subdev_edid32)) ||
756 get_user(kp->pad, &up->pad) ||
757 get_user(kp->start_block, &up->start_block) ||
758 get_user(kp->blocks, &up->blocks) ||
759 get_user(tmp, &up->edid) ||
760 copy_from_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
761 return -EFAULT;
762 kp->edid = compat_ptr(tmp);
763 return 0;
764}
765
766static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subdev_edid32 __user *up)
767{
768 u32 tmp = (u32)((unsigned long)kp->edid);
769
770 if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_subdev_edid32)) ||
771 put_user(kp->pad, &up->pad) ||
772 put_user(kp->start_block, &up->start_block) ||
773 put_user(kp->blocks, &up->blocks) ||
774 put_user(tmp, &up->edid) ||
775 copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
776 return -EFAULT;
777 return 0;
778}
779
780
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300781#define VIDIOC_G_FMT32 _IOWR('V', 4, struct v4l2_format32)
782#define VIDIOC_S_FMT32 _IOWR('V', 5, struct v4l2_format32)
783#define VIDIOC_QUERYBUF32 _IOWR('V', 9, struct v4l2_buffer32)
784#define VIDIOC_G_FBUF32 _IOR ('V', 10, struct v4l2_framebuffer32)
785#define VIDIOC_S_FBUF32 _IOW ('V', 11, struct v4l2_framebuffer32)
786#define VIDIOC_QBUF32 _IOWR('V', 15, struct v4l2_buffer32)
787#define VIDIOC_DQBUF32 _IOWR('V', 17, struct v4l2_buffer32)
788#define VIDIOC_ENUMSTD32 _IOWR('V', 25, struct v4l2_standard32)
789#define VIDIOC_ENUMINPUT32 _IOWR('V', 26, struct v4l2_input32)
Hans Verkuiled45ce22012-08-10 06:07:12 -0300790#define VIDIOC_SUBDEV_G_EDID32 _IOWR('V', 63, struct v4l2_subdev_edid32)
791#define VIDIOC_SUBDEV_S_EDID32 _IOWR('V', 64, struct v4l2_subdev_edid32)
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300792#define VIDIOC_TRY_FMT32 _IOWR('V', 64, struct v4l2_format32)
793#define VIDIOC_G_EXT_CTRLS32 _IOWR('V', 71, struct v4l2_ext_controls32)
794#define VIDIOC_S_EXT_CTRLS32 _IOWR('V', 72, struct v4l2_ext_controls32)
795#define VIDIOC_TRY_EXT_CTRLS32 _IOWR('V', 73, struct v4l2_ext_controls32)
Hans Verkuil2330fb82011-06-07 11:43:57 -0300796#define VIDIOC_DQEVENT32 _IOR ('V', 89, struct v4l2_event32)
Guennadi Liakhovetski21501582011-09-28 11:34:06 -0300797#define VIDIOC_CREATE_BUFS32 _IOWR('V', 92, struct v4l2_create_buffers32)
798#define VIDIOC_PREPARE_BUF32 _IOWR('V', 93, struct v4l2_buffer32)
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300799
800#define VIDIOC_OVERLAY32 _IOW ('V', 14, s32)
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300801#define VIDIOC_STREAMON32 _IOW ('V', 18, s32)
802#define VIDIOC_STREAMOFF32 _IOW ('V', 19, s32)
803#define VIDIOC_G_INPUT32 _IOR ('V', 38, s32)
804#define VIDIOC_S_INPUT32 _IOWR('V', 39, s32)
805#define VIDIOC_G_OUTPUT32 _IOR ('V', 46, s32)
806#define VIDIOC_S_OUTPUT32 _IOWR('V', 47, s32)
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200807
Hans Verkuil069b7472008-12-30 07:04:34 -0300808static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200809{
810 union {
Philippe De Muytercf664a62006-01-09 15:24:59 -0200811 struct v4l2_format v2f;
812 struct v4l2_buffer v2b;
813 struct v4l2_framebuffer v2fb;
Guy Martina113bc72006-01-11 23:40:51 -0200814 struct v4l2_input v2i;
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300815 struct v4l2_standard v2s;
816 struct v4l2_ext_controls v2ecs;
Hans Verkuil2330fb82011-06-07 11:43:57 -0300817 struct v4l2_event v2ev;
Guennadi Liakhovetski21501582011-09-28 11:34:06 -0300818 struct v4l2_create_buffers v2crt;
Hans Verkuiled45ce22012-08-10 06:07:12 -0300819 struct v4l2_subdev_edid v2edid;
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200820 unsigned long vx;
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300821 int vi;
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200822 } karg;
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200823 void __user *up = compat_ptr(arg);
Philippe De Muytercf664a62006-01-09 15:24:59 -0200824 int compatible_arg = 1;
Hans Verkuil069b7472008-12-30 07:04:34 -0300825 long err = 0;
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200826
827 /* First, convert the command. */
Hans Verkuild1f81da2008-10-22 00:04:45 -0300828 switch (cmd) {
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300829 case VIDIOC_G_FMT32: cmd = VIDIOC_G_FMT; break;
830 case VIDIOC_S_FMT32: cmd = VIDIOC_S_FMT; break;
831 case VIDIOC_QUERYBUF32: cmd = VIDIOC_QUERYBUF; break;
832 case VIDIOC_G_FBUF32: cmd = VIDIOC_G_FBUF; break;
833 case VIDIOC_S_FBUF32: cmd = VIDIOC_S_FBUF; break;
834 case VIDIOC_QBUF32: cmd = VIDIOC_QBUF; break;
835 case VIDIOC_DQBUF32: cmd = VIDIOC_DQBUF; break;
836 case VIDIOC_ENUMSTD32: cmd = VIDIOC_ENUMSTD; break;
837 case VIDIOC_ENUMINPUT32: cmd = VIDIOC_ENUMINPUT; break;
838 case VIDIOC_TRY_FMT32: cmd = VIDIOC_TRY_FMT; break;
839 case VIDIOC_G_EXT_CTRLS32: cmd = VIDIOC_G_EXT_CTRLS; break;
840 case VIDIOC_S_EXT_CTRLS32: cmd = VIDIOC_S_EXT_CTRLS; break;
841 case VIDIOC_TRY_EXT_CTRLS32: cmd = VIDIOC_TRY_EXT_CTRLS; break;
Hans Verkuil2330fb82011-06-07 11:43:57 -0300842 case VIDIOC_DQEVENT32: cmd = VIDIOC_DQEVENT; break;
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300843 case VIDIOC_OVERLAY32: cmd = VIDIOC_OVERLAY; break;
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300844 case VIDIOC_STREAMON32: cmd = VIDIOC_STREAMON; break;
845 case VIDIOC_STREAMOFF32: cmd = VIDIOC_STREAMOFF; break;
846 case VIDIOC_G_INPUT32: cmd = VIDIOC_G_INPUT; break;
847 case VIDIOC_S_INPUT32: cmd = VIDIOC_S_INPUT; break;
848 case VIDIOC_G_OUTPUT32: cmd = VIDIOC_G_OUTPUT; break;
849 case VIDIOC_S_OUTPUT32: cmd = VIDIOC_S_OUTPUT; break;
Guennadi Liakhovetski21501582011-09-28 11:34:06 -0300850 case VIDIOC_CREATE_BUFS32: cmd = VIDIOC_CREATE_BUFS; break;
851 case VIDIOC_PREPARE_BUF32: cmd = VIDIOC_PREPARE_BUF; break;
Hans Verkuiled45ce22012-08-10 06:07:12 -0300852 case VIDIOC_SUBDEV_G_EDID32: cmd = VIDIOC_SUBDEV_G_EDID; break;
853 case VIDIOC_SUBDEV_S_EDID32: cmd = VIDIOC_SUBDEV_S_EDID; break;
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300854 }
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200855
Hans Verkuild1f81da2008-10-22 00:04:45 -0300856 switch (cmd) {
Philippe De Muytercf664a62006-01-09 15:24:59 -0200857 case VIDIOC_OVERLAY:
Philippe De Muyter13d133b2006-01-09 15:25:00 -0200858 case VIDIOC_STREAMON:
859 case VIDIOC_STREAMOFF:
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300860 case VIDIOC_S_INPUT:
861 case VIDIOC_S_OUTPUT:
862 err = get_user(karg.vi, (s32 __user *)up);
863 compatible_arg = 0;
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200864 break;
Philippe De Muyter13d133b2006-01-09 15:25:00 -0200865
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300866 case VIDIOC_G_INPUT:
867 case VIDIOC_G_OUTPUT:
Philippe De Muyter13d133b2006-01-09 15:25:00 -0200868 compatible_arg = 0;
869 break;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200870
Hans Verkuiled45ce22012-08-10 06:07:12 -0300871 case VIDIOC_SUBDEV_G_EDID:
872 case VIDIOC_SUBDEV_S_EDID:
873 err = get_v4l2_subdev_edid32(&karg.v2edid, up);
874 compatible_arg = 0;
875 break;
876
Philippe De Muytercf664a62006-01-09 15:24:59 -0200877 case VIDIOC_G_FMT:
878 case VIDIOC_S_FMT:
879 case VIDIOC_TRY_FMT:
880 err = get_v4l2_format32(&karg.v2f, up);
881 compatible_arg = 0;
882 break;
883
Guennadi Liakhovetski21501582011-09-28 11:34:06 -0300884 case VIDIOC_CREATE_BUFS:
885 err = get_v4l2_create32(&karg.v2crt, up);
886 compatible_arg = 0;
887 break;
888
889 case VIDIOC_PREPARE_BUF:
Philippe De Muytercf664a62006-01-09 15:24:59 -0200890 case VIDIOC_QUERYBUF:
891 case VIDIOC_QBUF:
892 case VIDIOC_DQBUF:
893 err = get_v4l2_buffer32(&karg.v2b, up);
894 compatible_arg = 0;
895 break;
896
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300897 case VIDIOC_S_FBUF:
898 err = get_v4l2_framebuffer32(&karg.v2fb, up);
Guy Martina113bc72006-01-11 23:40:51 -0200899 compatible_arg = 0;
900 break;
901
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300902 case VIDIOC_G_FBUF:
903 compatible_arg = 0;
904 break;
905
906 case VIDIOC_ENUMSTD:
Philippe De Muytercf664a62006-01-09 15:24:59 -0200907 err = get_v4l2_standard32(&karg.v2s, up);
908 compatible_arg = 0;
909 break;
910
Guy Martina113bc72006-01-11 23:40:51 -0200911 case VIDIOC_ENUMINPUT:
Guy Martina113bc72006-01-11 23:40:51 -0200912 err = get_v4l2_input32(&karg.v2i, up);
913 compatible_arg = 0;
914 break;
915
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300916 case VIDIOC_G_EXT_CTRLS:
917 case VIDIOC_S_EXT_CTRLS:
918 case VIDIOC_TRY_EXT_CTRLS:
919 err = get_v4l2_ext_controls32(&karg.v2ecs, up);
Guy Martina113bc72006-01-11 23:40:51 -0200920 compatible_arg = 0;
921 break;
Hans Verkuil2330fb82011-06-07 11:43:57 -0300922 case VIDIOC_DQEVENT:
923 compatible_arg = 0;
924 break;
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300925 }
Hans Verkuild1f81da2008-10-22 00:04:45 -0300926 if (err)
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300927 return err;
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200928
Hans Verkuild1f81da2008-10-22 00:04:45 -0300929 if (compatible_arg)
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300930 err = native_ioctl(file, cmd, (unsigned long)up);
Philippe De Muytercf664a62006-01-09 15:24:59 -0200931 else {
932 mm_segment_t old_fs = get_fs();
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200933
Philippe De Muytercf664a62006-01-09 15:24:59 -0200934 set_fs(KERNEL_DS);
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300935 err = native_ioctl(file, cmd, (unsigned long)&karg);
Philippe De Muytercf664a62006-01-09 15:24:59 -0200936 set_fs(old_fs);
937 }
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200938
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300939 /* Special case: even after an error we need to put the
940 results back for these ioctls since the error_idx will
941 contain information on which control failed. */
942 switch (cmd) {
943 case VIDIOC_G_EXT_CTRLS:
944 case VIDIOC_S_EXT_CTRLS:
945 case VIDIOC_TRY_EXT_CTRLS:
946 if (put_v4l2_ext_controls32(&karg.v2ecs, up))
947 err = -EFAULT;
948 break;
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200949 }
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300950 if (err)
951 return err;
952
953 switch (cmd) {
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300954 case VIDIOC_S_INPUT:
955 case VIDIOC_S_OUTPUT:
956 case VIDIOC_G_INPUT:
957 case VIDIOC_G_OUTPUT:
958 err = put_user(((s32)karg.vi), (s32 __user *)up);
959 break;
960
961 case VIDIOC_G_FBUF:
962 err = put_v4l2_framebuffer32(&karg.v2fb, up);
963 break;
964
Hans Verkuil2330fb82011-06-07 11:43:57 -0300965 case VIDIOC_DQEVENT:
966 err = put_v4l2_event32(&karg.v2ev, up);
967 break;
968
Hans Verkuiled45ce22012-08-10 06:07:12 -0300969 case VIDIOC_SUBDEV_G_EDID:
970 case VIDIOC_SUBDEV_S_EDID:
971 err = put_v4l2_subdev_edid32(&karg.v2edid, up);
972 break;
973
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300974 case VIDIOC_G_FMT:
975 case VIDIOC_S_FMT:
976 case VIDIOC_TRY_FMT:
977 err = put_v4l2_format32(&karg.v2f, up);
978 break;
979
Guennadi Liakhovetski21501582011-09-28 11:34:06 -0300980 case VIDIOC_CREATE_BUFS:
981 err = put_v4l2_create32(&karg.v2crt, up);
982 break;
983
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300984 case VIDIOC_QUERYBUF:
985 case VIDIOC_QBUF:
986 case VIDIOC_DQBUF:
987 err = put_v4l2_buffer32(&karg.v2b, up);
988 break;
989
990 case VIDIOC_ENUMSTD:
991 err = put_v4l2_standard32(&karg.v2s, up);
992 break;
993
994 case VIDIOC_ENUMINPUT:
995 err = put_v4l2_input32(&karg.v2i, up);
996 break;
997 }
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200998 return err;
999}
1000
Hans Verkuil9bb7cde2008-12-30 06:42:40 -03001001long v4l2_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -02001002{
Laurent Pinchartb9d0aa62011-12-18 20:41:19 -03001003 struct video_device *vdev = video_devdata(file);
Hans Verkuil069b7472008-12-30 07:04:34 -03001004 long ret = -ENOIOCTLCMD;
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -02001005
Frederic Weisbeckerc6d7ba82010-08-13 22:29:03 +02001006 if (!file->f_op->unlocked_ioctl)
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -02001007 return ret;
1008
1009 switch (cmd) {
Philippe De Muyter13d133b2006-01-09 15:25:00 -02001010 case VIDIOC_QUERYCAP:
Hans Verkuil92f45ba2008-12-21 10:35:25 -03001011 case VIDIOC_RESERVED:
Philippe De Muyter13d133b2006-01-09 15:25:00 -02001012 case VIDIOC_ENUM_FMT:
1013 case VIDIOC_G_FMT32:
1014 case VIDIOC_S_FMT32:
1015 case VIDIOC_REQBUFS:
1016 case VIDIOC_QUERYBUF32:
1017 case VIDIOC_G_FBUF32:
1018 case VIDIOC_S_FBUF32:
1019 case VIDIOC_OVERLAY32:
1020 case VIDIOC_QBUF32:
Tomasz Stanislawskib799d092012-06-14 11:32:23 -03001021 case VIDIOC_EXPBUF:
Philippe De Muyter13d133b2006-01-09 15:25:00 -02001022 case VIDIOC_DQBUF32:
1023 case VIDIOC_STREAMON32:
1024 case VIDIOC_STREAMOFF32:
1025 case VIDIOC_G_PARM:
Gregor Jasnyc7f09db2008-10-23 09:55:22 -03001026 case VIDIOC_S_PARM:
Philippe De Muyter13d133b2006-01-09 15:25:00 -02001027 case VIDIOC_G_STD:
1028 case VIDIOC_S_STD:
1029 case VIDIOC_ENUMSTD32:
1030 case VIDIOC_ENUMINPUT32:
1031 case VIDIOC_G_CTRL:
Steven Walter7963fa42007-08-09 11:36:35 -03001032 case VIDIOC_S_CTRL:
Hans Verkuil92f45ba2008-12-21 10:35:25 -03001033 case VIDIOC_G_TUNER:
1034 case VIDIOC_S_TUNER:
1035 case VIDIOC_G_AUDIO:
1036 case VIDIOC_S_AUDIO:
Philippe De Muyter13d133b2006-01-09 15:25:00 -02001037 case VIDIOC_QUERYCTRL:
Hans Verkuil92f45ba2008-12-21 10:35:25 -03001038 case VIDIOC_QUERYMENU:
Philippe De Muyter13d133b2006-01-09 15:25:00 -02001039 case VIDIOC_G_INPUT32:
1040 case VIDIOC_S_INPUT32:
Hans Verkuil92f45ba2008-12-21 10:35:25 -03001041 case VIDIOC_G_OUTPUT32:
1042 case VIDIOC_S_OUTPUT32:
1043 case VIDIOC_ENUMOUTPUT:
1044 case VIDIOC_G_AUDOUT:
1045 case VIDIOC_S_AUDOUT:
1046 case VIDIOC_G_MODULATOR:
1047 case VIDIOC_S_MODULATOR:
1048 case VIDIOC_S_FREQUENCY:
1049 case VIDIOC_G_FREQUENCY:
1050 case VIDIOC_CROPCAP:
1051 case VIDIOC_G_CROP:
1052 case VIDIOC_S_CROP:
Tomasz Stanislawski0e8caac2011-08-10 10:37:47 -03001053 case VIDIOC_G_SELECTION:
1054 case VIDIOC_S_SELECTION:
Hans Verkuil92f45ba2008-12-21 10:35:25 -03001055 case VIDIOC_G_JPEGCOMP:
1056 case VIDIOC_S_JPEGCOMP:
1057 case VIDIOC_QUERYSTD:
Philippe De Muyter13d133b2006-01-09 15:25:00 -02001058 case VIDIOC_TRY_FMT32:
Hans Verkuil92f45ba2008-12-21 10:35:25 -03001059 case VIDIOC_ENUMAUDIO:
1060 case VIDIOC_ENUMAUDOUT:
1061 case VIDIOC_G_PRIORITY:
1062 case VIDIOC_S_PRIORITY:
1063 case VIDIOC_G_SLICED_VBI_CAP:
1064 case VIDIOC_LOG_STATUS:
1065 case VIDIOC_G_EXT_CTRLS32:
1066 case VIDIOC_S_EXT_CTRLS32:
1067 case VIDIOC_TRY_EXT_CTRLS32:
Gregor Jasnyc7f09db2008-10-23 09:55:22 -03001068 case VIDIOC_ENUM_FRAMESIZES:
1069 case VIDIOC_ENUM_FRAMEINTERVALS:
Hans Verkuil92f45ba2008-12-21 10:35:25 -03001070 case VIDIOC_G_ENC_INDEX:
1071 case VIDIOC_ENCODER_CMD:
1072 case VIDIOC_TRY_ENCODER_CMD:
Hans Verkuila45c0ad2011-11-24 09:53:43 -03001073 case VIDIOC_DECODER_CMD:
1074 case VIDIOC_TRY_DECODER_CMD:
Hans Verkuil92f45ba2008-12-21 10:35:25 -03001075 case VIDIOC_DBG_S_REGISTER:
1076 case VIDIOC_DBG_G_REGISTER:
Hans Verkuil92f45ba2008-12-21 10:35:25 -03001077 case VIDIOC_S_HW_FREQ_SEEK:
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001078 case VIDIOC_S_DV_TIMINGS:
1079 case VIDIOC_G_DV_TIMINGS:
Sakari Ailusfda10212010-02-24 19:19:05 -03001080 case VIDIOC_DQEVENT:
Hans Verkuil2330fb82011-06-07 11:43:57 -03001081 case VIDIOC_DQEVENT32:
Sakari Ailusfda10212010-02-24 19:19:05 -03001082 case VIDIOC_SUBSCRIBE_EVENT:
1083 case VIDIOC_UNSUBSCRIBE_EVENT:
Guennadi Liakhovetski21501582011-09-28 11:34:06 -03001084 case VIDIOC_CREATE_BUFS32:
1085 case VIDIOC_PREPARE_BUF32:
Hans Verkuil5d7758e2012-05-15 08:06:44 -03001086 case VIDIOC_ENUM_DV_TIMINGS:
1087 case VIDIOC_QUERY_DV_TIMINGS:
1088 case VIDIOC_DV_TIMINGS_CAP:
Hans Verkuil82b655b2012-07-05 06:37:08 -03001089 case VIDIOC_ENUM_FREQ_BANDS:
Hans Verkuiled45ce22012-08-10 06:07:12 -03001090 case VIDIOC_SUBDEV_G_EDID32:
1091 case VIDIOC_SUBDEV_S_EDID32:
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -02001092 ret = do_video_ioctl(file, cmd, arg);
1093 break;
1094
Guy Martina113bc72006-01-11 23:40:51 -02001095 default:
Laurent Pinchartb9d0aa62011-12-18 20:41:19 -03001096 if (vdev->fops->compat_ioctl32)
1097 ret = vdev->fops->compat_ioctl32(file, cmd, arg);
1098
1099 if (ret == -ENOIOCTLCMD)
1100 printk(KERN_WARNING "compat_ioctl32: "
1101 "unknown ioctl '%c', dir=%d, #%d (0x%08x)\n",
1102 _IOC_TYPE(cmd), _IOC_DIR(cmd), _IOC_NR(cmd),
1103 cmd);
Hans Verkuil7d4f0b82008-12-15 07:19:20 -03001104 break;
MishalĂ… Pytasz97e2a012006-01-09 15:24:59 -02001105 }
Hans Verkuile8efb712006-01-09 15:24:59 -02001106 return ret;
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -02001107}
Hans Verkuil9bb7cde2008-12-30 06:42:40 -03001108EXPORT_SYMBOL_GPL(v4l2_compat_ioctl32);