blob: 86294ed35c9b643cc7bab7411904476d0f7467a7 [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>
Hans Verkuil92f45ba2008-12-21 10:35:25 -030017#define __OLD_VIDIOC_ /* To allow fixing old calls*/
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -020018#include <linux/videodev.h>
Philippe De Muytercf664a62006-01-09 15:24:59 -020019#include <linux/videodev2.h>
Nickolay V. Shmyrev133b7352006-01-09 15:24:58 -020020#include <linux/module.h>
Hans Verkuile8efb712006-01-09 15:24:59 -020021#include <linux/smp_lock.h>
Mauro Carvalho Chehab28644622008-07-20 20:26:54 -030022#include <media/v4l2-ioctl.h>
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -020023
24#ifdef CONFIG_COMPAT
Guy Martina113bc72006-01-11 23:40:51 -020025
Mauro Carvalho Chehab5bdd6cc2006-07-25 16:17:54 -030026#ifdef CONFIG_VIDEO_V4L1_COMPAT
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -020027struct video_tuner32 {
28 compat_int_t tuner;
29 char name[32];
30 compat_ulong_t rangelow, rangehigh;
31 u32 flags; /* It is really u32 in videodev.h */
32 u16 mode, signal;
33};
34
35static int get_video_tuner32(struct video_tuner *kp, struct video_tuner32 __user *up)
36{
Hans Verkuild1f81da2008-10-22 00:04:45 -030037 if (!access_ok(VERIFY_READ, up, sizeof(struct video_tuner32)) ||
Guy Martina113bc72006-01-11 23:40:51 -020038 get_user(kp->tuner, &up->tuner) ||
39 copy_from_user(kp->name, up->name, 32) ||
40 get_user(kp->rangelow, &up->rangelow) ||
41 get_user(kp->rangehigh, &up->rangehigh) ||
42 get_user(kp->flags, &up->flags) ||
43 get_user(kp->mode, &up->mode) ||
44 get_user(kp->signal, &up->signal))
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -020045 return -EFAULT;
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -020046 return 0;
47}
48
49static int put_video_tuner32(struct video_tuner *kp, struct video_tuner32 __user *up)
50{
Hans Verkuild1f81da2008-10-22 00:04:45 -030051 if (!access_ok(VERIFY_WRITE, up, sizeof(struct video_tuner32)) ||
Guy Martina113bc72006-01-11 23:40:51 -020052 put_user(kp->tuner, &up->tuner) ||
53 copy_to_user(up->name, kp->name, 32) ||
54 put_user(kp->rangelow, &up->rangelow) ||
55 put_user(kp->rangehigh, &up->rangehigh) ||
56 put_user(kp->flags, &up->flags) ||
57 put_user(kp->mode, &up->mode) ||
58 put_user(kp->signal, &up->signal))
59 return -EFAULT;
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -020060 return 0;
61}
62
63struct video_buffer32 {
64 compat_caddr_t base;
65 compat_int_t height, width, depth, bytesperline;
66};
67
68static int get_video_buffer32(struct video_buffer *kp, struct video_buffer32 __user *up)
69{
70 u32 tmp;
71
Guy Martina113bc72006-01-11 23:40:51 -020072 if (!access_ok(VERIFY_READ, up, sizeof(struct video_buffer32)) ||
73 get_user(tmp, &up->base) ||
74 get_user(kp->height, &up->height) ||
75 get_user(kp->width, &up->width) ||
76 get_user(kp->depth, &up->depth) ||
77 get_user(kp->bytesperline, &up->bytesperline))
78 return -EFAULT;
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -020079
80 /* This is actually a physical address stored
81 * as a void pointer.
82 */
83 kp->base = (void *)(unsigned long) tmp;
84
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -020085 return 0;
86}
87
88static int put_video_buffer32(struct video_buffer *kp, struct video_buffer32 __user *up)
89{
90 u32 tmp = (u32)((unsigned long)kp->base);
91
Hans Verkuild1f81da2008-10-22 00:04:45 -030092 if (!access_ok(VERIFY_WRITE, up, sizeof(struct video_buffer32)) ||
Guy Martina113bc72006-01-11 23:40:51 -020093 put_user(tmp, &up->base) ||
94 put_user(kp->height, &up->height) ||
95 put_user(kp->width, &up->width) ||
96 put_user(kp->depth, &up->depth) ||
97 put_user(kp->bytesperline, &up->bytesperline))
98 return -EFAULT;
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -020099 return 0;
100}
101
102struct video_clip32 {
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300103 s32 x, y, width, height; /* It's really s32 in videodev.h */
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200104 compat_caddr_t next;
105};
106
107struct video_window32 {
108 u32 x, y, width, height, chromakey, flags;
109 compat_caddr_t clips;
110 compat_int_t clipcount;
111};
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300112
113static int get_video_window32(struct video_window *kp, struct video_window32 __user *up)
114{
115 struct video_clip __user *uclips;
116 struct video_clip __user *kclips;
117 compat_caddr_t p;
118 int nclips;
119
120 if (!access_ok(VERIFY_READ, up, sizeof(struct video_window32)))
121 return -EFAULT;
122
123 if (get_user(nclips, &up->clipcount))
124 return -EFAULT;
125
126 if (!access_ok(VERIFY_READ, up, sizeof(struct video_window32)) ||
127 get_user(kp->x, &up->x) ||
128 get_user(kp->y, &up->y) ||
129 get_user(kp->width, &up->width) ||
130 get_user(kp->height, &up->height) ||
131 get_user(kp->chromakey, &up->chromakey) ||
132 get_user(kp->flags, &up->flags) ||
133 get_user(kp->clipcount, &up->clipcount))
134 return -EFAULT;
135
136 nclips = kp->clipcount;
137 kp->clips = NULL;
138
139 if (nclips == 0)
140 return 0;
141 if (get_user(p, &up->clips))
142 return -EFAULT;
143 uclips = compat_ptr(p);
144
145 /* If nclips < 0, then it is a clipping bitmap of size
146 VIDEO_CLIPMAP_SIZE */
147 if (nclips < 0) {
148 if (!access_ok(VERIFY_READ, uclips, VIDEO_CLIPMAP_SIZE))
149 return -EFAULT;
150 kp->clips = compat_alloc_user_space(VIDEO_CLIPMAP_SIZE);
151 if (copy_in_user(kp->clips, uclips, VIDEO_CLIPMAP_SIZE))
152 return -EFAULT;
153 return 0;
154 }
155
156 /* Otherwise it is an array of video_clip structs. */
157 if (!access_ok(VERIFY_READ, uclips, nclips * sizeof(struct video_clip)))
158 return -EFAULT;
159
160 kp->clips = compat_alloc_user_space(nclips * sizeof(struct video_clip));
161 kclips = kp->clips;
162 while (nclips--) {
163 int err;
164
165 err = copy_in_user(&kclips->x, &uclips->x, sizeof(kclips->x));
166 err |= copy_in_user(&kclips->y, &uclips->y, sizeof(kclips->y));
167 err |= copy_in_user(&kclips->width, &uclips->width, sizeof(kclips->width));
168 err |= copy_in_user(&kclips->height, &uclips->height, sizeof(kclips->height));
169 kclips->next = NULL;
170 if (err)
171 return -EFAULT;
172 kclips++;
173 uclips++;
174 }
175 return 0;
176}
177
178/* You get back everything except the clips... */
179static int put_video_window32(struct video_window *kp, struct video_window32 __user *up)
180{
181 if (!access_ok(VERIFY_WRITE, up, sizeof(struct video_window32)) ||
182 put_user(kp->x, &up->x) ||
183 put_user(kp->y, &up->y) ||
184 put_user(kp->width, &up->width) ||
185 put_user(kp->height, &up->height) ||
186 put_user(kp->chromakey, &up->chromakey) ||
187 put_user(kp->flags, &up->flags) ||
188 put_user(kp->clipcount, &up->clipcount))
189 return -EFAULT;
190 return 0;
191}
192
193struct video_code32 {
194 char loadwhat[16]; /* name or tag of file being passed */
195 compat_int_t datasize;
Linus Torvalds3e645d62010-10-15 11:12:38 -0700196 compat_uptr_t data;
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300197};
198
Linus Torvalds3e645d62010-10-15 11:12:38 -0700199static struct video_code __user *get_microcode32(struct video_code32 *kp)
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300200{
Linus Torvalds3e645d62010-10-15 11:12:38 -0700201 struct video_code __user *up;
202
203 up = compat_alloc_user_space(sizeof(*up));
204
205 /*
206 * NOTE! We don't actually care if these fail. If the
207 * user address is invalid, the native ioctl will do
208 * the error handling for us
209 */
210 (void) copy_to_user(up->loadwhat, kp->loadwhat, sizeof(up->loadwhat));
211 (void) put_user(kp->datasize, &up->datasize);
212 (void) put_user(compat_ptr(kp->data), &up->data);
213 return up;
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300214}
215
216#define VIDIOCGTUNER32 _IOWR('v', 4, struct video_tuner32)
217#define VIDIOCSTUNER32 _IOW('v', 5, struct video_tuner32)
218#define VIDIOCGWIN32 _IOR('v', 9, struct video_window32)
219#define VIDIOCSWIN32 _IOW('v', 10, struct video_window32)
220#define VIDIOCGFBUF32 _IOR('v', 11, struct video_buffer32)
221#define VIDIOCSFBUF32 _IOW('v', 12, struct video_buffer32)
222#define VIDIOCGFREQ32 _IOR('v', 14, u32)
223#define VIDIOCSFREQ32 _IOW('v', 15, u32)
224#define VIDIOCSMICROCODE32 _IOW('v', 27, struct video_code32)
225
226#define VIDIOCCAPTURE32 _IOW('v', 8, s32)
227#define VIDIOCSYNC32 _IOW('v', 18, s32)
228#define VIDIOCSWRITEMODE32 _IOW('v', 25, s32)
229
Mauro Carvalho Chehab5bdd6cc2006-07-25 16:17:54 -0300230#endif
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200231
Hans Verkuil069b7472008-12-30 07:04:34 -0300232static long native_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200233{
Hans Verkuil069b7472008-12-30 07:04:34 -0300234 long ret = -ENOIOCTLCMD;
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200235
Philippe De Muyter13d133b2006-01-09 15:25:00 -0200236 if (file->f_op->unlocked_ioctl)
237 ret = file->f_op->unlocked_ioctl(file, cmd, arg);
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200238
239 return ret;
240}
241
242
Hans Verkuild1f81da2008-10-22 00:04:45 -0300243struct v4l2_clip32 {
Philippe De Muytercf664a62006-01-09 15:24:59 -0200244 struct v4l2_rect c;
245 compat_caddr_t next;
246};
247
Hans Verkuild1f81da2008-10-22 00:04:45 -0300248struct v4l2_window32 {
Philippe De Muytercf664a62006-01-09 15:24:59 -0200249 struct v4l2_rect w;
250 enum v4l2_field field;
251 __u32 chromakey;
252 compat_caddr_t clips; /* actually struct v4l2_clip32 * */
253 __u32 clipcount;
254 compat_caddr_t bitmap;
255};
256
257static int get_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 __user *up)
258{
Guy Martina113bc72006-01-11 23:40:51 -0200259 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_window32)) ||
260 copy_from_user(&kp->w, &up->w, sizeof(up->w)) ||
261 get_user(kp->field, &up->field) ||
262 get_user(kp->chromakey, &up->chromakey) ||
263 get_user(kp->clipcount, &up->clipcount))
264 return -EFAULT;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200265 if (kp->clipcount > 2048)
266 return -EINVAL;
267 if (kp->clipcount) {
Al Viro5b1a43d2006-02-01 05:24:20 -0500268 struct v4l2_clip32 __user *uclips;
269 struct v4l2_clip __user *kclips;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200270 int n = kp->clipcount;
Al Viro5b1a43d2006-02-01 05:24:20 -0500271 compat_caddr_t p;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200272
Al Viro5b1a43d2006-02-01 05:24:20 -0500273 if (get_user(p, &up->clips))
274 return -EFAULT;
275 uclips = compat_ptr(p);
Philippe De Muytercf664a62006-01-09 15:24:59 -0200276 kclips = compat_alloc_user_space(n * sizeof(struct v4l2_clip));
277 kp->clips = kclips;
278 while (--n >= 0) {
Al Viro5b1a43d2006-02-01 05:24:20 -0500279 if (copy_in_user(&kclips->c, &uclips->c, sizeof(uclips->c)))
Guy Martina113bc72006-01-11 23:40:51 -0200280 return -EFAULT;
Al Viro5b1a43d2006-02-01 05:24:20 -0500281 if (put_user(n ? kclips + 1 : NULL, &kclips->next))
282 return -EFAULT;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200283 uclips += 1;
284 kclips += 1;
285 }
286 } else
Al Viro5b1a43d2006-02-01 05:24:20 -0500287 kp->clips = NULL;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200288 return 0;
289}
290
291static int put_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 __user *up)
292{
Roel Kluinf2e6c6a2009-12-16 11:35:45 -0300293 if (copy_to_user(&up->w, &kp->w, sizeof(kp->w)) ||
Guy Martina113bc72006-01-11 23:40:51 -0200294 put_user(kp->field, &up->field) ||
295 put_user(kp->chromakey, &up->chromakey) ||
296 put_user(kp->clipcount, &up->clipcount))
297 return -EFAULT;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200298 return 0;
299}
300
301static inline int get_v4l2_pix_format(struct v4l2_pix_format *kp, struct v4l2_pix_format __user *up)
302{
Al Viro5b1a43d2006-02-01 05:24:20 -0500303 if (copy_from_user(kp, up, sizeof(struct v4l2_pix_format)))
304 return -EFAULT;
Guy Martina113bc72006-01-11 23:40:51 -0200305 return 0;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200306}
307
308static inline int put_v4l2_pix_format(struct v4l2_pix_format *kp, struct v4l2_pix_format __user *up)
309{
Al Viro5b1a43d2006-02-01 05:24:20 -0500310 if (copy_to_user(up, kp, sizeof(struct v4l2_pix_format)))
311 return -EFAULT;
Guy Martina113bc72006-01-11 23:40:51 -0200312 return 0;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200313}
314
315static inline int get_v4l2_vbi_format(struct v4l2_vbi_format *kp, struct v4l2_vbi_format __user *up)
316{
Al Viro5b1a43d2006-02-01 05:24:20 -0500317 if (copy_from_user(kp, up, sizeof(struct v4l2_vbi_format)))
318 return -EFAULT;
Guy Martina113bc72006-01-11 23:40:51 -0200319 return 0;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200320}
321
322static inline int put_v4l2_vbi_format(struct v4l2_vbi_format *kp, struct v4l2_vbi_format __user *up)
323{
Al Viro5b1a43d2006-02-01 05:24:20 -0500324 if (copy_to_user(up, kp, sizeof(struct v4l2_vbi_format)))
325 return -EFAULT;
Guy Martina113bc72006-01-11 23:40:51 -0200326 return 0;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200327}
328
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300329static inline int get_v4l2_sliced_vbi_format(struct v4l2_sliced_vbi_format *kp, struct v4l2_sliced_vbi_format __user *up)
330{
331 if (copy_from_user(kp, up, sizeof(struct v4l2_sliced_vbi_format)))
332 return -EFAULT;
333 return 0;
334}
335
336static inline int put_v4l2_sliced_vbi_format(struct v4l2_sliced_vbi_format *kp, struct v4l2_sliced_vbi_format __user *up)
337{
338 if (copy_to_user(up, kp, sizeof(struct v4l2_sliced_vbi_format)))
339 return -EFAULT;
340 return 0;
341}
342
Hans Verkuild1f81da2008-10-22 00:04:45 -0300343struct v4l2_format32 {
Philippe De Muytercf664a62006-01-09 15:24:59 -0200344 enum v4l2_buf_type type;
Hans Verkuild1f81da2008-10-22 00:04:45 -0300345 union {
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300346 struct v4l2_pix_format pix;
347 struct v4l2_window32 win;
348 struct v4l2_vbi_format vbi;
349 struct v4l2_sliced_vbi_format sliced;
Hans Verkuild1f81da2008-10-22 00:04:45 -0300350 __u8 raw_data[200]; /* user-defined */
Philippe De Muytercf664a62006-01-09 15:24:59 -0200351 } fmt;
352};
353
354static int get_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up)
355{
Guy Martina113bc72006-01-11 23:40:51 -0200356 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_format32)) ||
357 get_user(kp->type, &up->type))
358 return -EFAULT;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200359 switch (kp->type) {
360 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300361 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Philippe De Muytercf664a62006-01-09 15:24:59 -0200362 return get_v4l2_pix_format(&kp->fmt.pix, &up->fmt.pix);
363 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300364 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Philippe De Muytercf664a62006-01-09 15:24:59 -0200365 return get_v4l2_window32(&kp->fmt.win, &up->fmt.win);
366 case V4L2_BUF_TYPE_VBI_CAPTURE:
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300367 case V4L2_BUF_TYPE_VBI_OUTPUT:
Philippe De Muytercf664a62006-01-09 15:24:59 -0200368 return get_v4l2_vbi_format(&kp->fmt.vbi, &up->fmt.vbi);
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300369 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
370 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
371 return get_v4l2_sliced_vbi_format(&kp->fmt.sliced, &up->fmt.sliced);
372 case V4L2_BUF_TYPE_PRIVATE:
373 if (copy_from_user(kp, up, sizeof(kp->fmt.raw_data)))
374 return -EFAULT;
375 return 0;
376 case 0:
377 return -EINVAL;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200378 default:
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300379 printk(KERN_INFO "compat_ioctl32: unexpected VIDIOC_FMT type %d\n",
Philippe De Muytercf664a62006-01-09 15:24:59 -0200380 kp->type);
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300381 return -EINVAL;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200382 }
383}
384
385static int put_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up)
386{
Hans Verkuild1f81da2008-10-22 00:04:45 -0300387 if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_format32)) ||
Guy Martina113bc72006-01-11 23:40:51 -0200388 put_user(kp->type, &up->type))
Philippe De Muytercf664a62006-01-09 15:24:59 -0200389 return -EFAULT;
390 switch (kp->type) {
391 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300392 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Philippe De Muytercf664a62006-01-09 15:24:59 -0200393 return put_v4l2_pix_format(&kp->fmt.pix, &up->fmt.pix);
394 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300395 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Philippe De Muytercf664a62006-01-09 15:24:59 -0200396 return put_v4l2_window32(&kp->fmt.win, &up->fmt.win);
397 case V4L2_BUF_TYPE_VBI_CAPTURE:
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300398 case V4L2_BUF_TYPE_VBI_OUTPUT:
Philippe De Muytercf664a62006-01-09 15:24:59 -0200399 return put_v4l2_vbi_format(&kp->fmt.vbi, &up->fmt.vbi);
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300400 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
401 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
402 return put_v4l2_sliced_vbi_format(&kp->fmt.sliced, &up->fmt.sliced);
403 case V4L2_BUF_TYPE_PRIVATE:
404 if (copy_to_user(up, kp, sizeof(up->fmt.raw_data)))
405 return -EFAULT;
406 return 0;
407 case 0:
408 return -EINVAL;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200409 default:
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300410 printk(KERN_INFO "compat_ioctl32: unexpected VIDIOC_FMT type %d\n",
411 kp->type);
412 return -EINVAL;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200413 }
414}
415
Hans Verkuild1f81da2008-10-22 00:04:45 -0300416struct v4l2_standard32 {
Philippe De Muytercf664a62006-01-09 15:24:59 -0200417 __u32 index;
418 __u32 id[2]; /* __u64 would get the alignment wrong */
419 __u8 name[24];
420 struct v4l2_fract frameperiod; /* Frames, not fields */
421 __u32 framelines;
422 __u32 reserved[4];
423};
424
425static int get_v4l2_standard32(struct v4l2_standard *kp, struct v4l2_standard32 __user *up)
426{
427 /* other fields are not set by the user, nor used by the driver */
Guy Martina113bc72006-01-11 23:40:51 -0200428 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_standard32)) ||
429 get_user(kp->index, &up->index))
430 return -EFAULT;
431 return 0;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200432}
433
434static int put_v4l2_standard32(struct v4l2_standard *kp, struct v4l2_standard32 __user *up)
435{
Hans Verkuild1f81da2008-10-22 00:04:45 -0300436 if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_standard32)) ||
Guy Martina113bc72006-01-11 23:40:51 -0200437 put_user(kp->index, &up->index) ||
438 copy_to_user(up->id, &kp->id, sizeof(__u64)) ||
439 copy_to_user(up->name, kp->name, 24) ||
440 copy_to_user(&up->frameperiod, &kp->frameperiod, sizeof(kp->frameperiod)) ||
441 put_user(kp->framelines, &up->framelines) ||
442 copy_to_user(up->reserved, kp->reserved, 4 * sizeof(__u32)))
443 return -EFAULT;
444 return 0;
445}
446
Hans Verkuild1f81da2008-10-22 00:04:45 -0300447struct v4l2_buffer32 {
Philippe De Muytercf664a62006-01-09 15:24:59 -0200448 __u32 index;
449 enum v4l2_buf_type type;
450 __u32 bytesused;
451 __u32 flags;
452 enum v4l2_field field;
453 struct compat_timeval timestamp;
454 struct v4l2_timecode timecode;
455 __u32 sequence;
456
457 /* memory location */
458 enum v4l2_memory memory;
459 union {
460 __u32 offset;
461 compat_long_t userptr;
462 } m;
463 __u32 length;
464 __u32 input;
465 __u32 reserved;
466};
467
468static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user *up)
469{
470
Guy Martina113bc72006-01-11 23:40:51 -0200471 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_buffer32)) ||
472 get_user(kp->index, &up->index) ||
473 get_user(kp->type, &up->type) ||
474 get_user(kp->flags, &up->flags) ||
475 get_user(kp->memory, &up->memory) ||
476 get_user(kp->input, &up->input))
477 return -EFAULT;
Hans Verkuild1f81da2008-10-22 00:04:45 -0300478 switch (kp->memory) {
Philippe De Muytercf664a62006-01-09 15:24:59 -0200479 case V4L2_MEMORY_MMAP:
Arnaud Patard22c859f2010-01-25 12:02:31 -0300480 if (get_user(kp->length, &up->length) ||
481 get_user(kp->m.offset, &up->m.offset))
482 return -EFAULT;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200483 break;
484 case V4L2_MEMORY_USERPTR:
485 {
Al Viro5b1a43d2006-02-01 05:24:20 -0500486 compat_long_t tmp;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200487
Al Viro5b1a43d2006-02-01 05:24:20 -0500488 if (get_user(kp->length, &up->length) ||
489 get_user(tmp, &up->m.userptr))
490 return -EFAULT;
491
492 kp->m.userptr = (unsigned long)compat_ptr(tmp);
Philippe De Muytercf664a62006-01-09 15:24:59 -0200493 }
494 break;
495 case V4L2_MEMORY_OVERLAY:
Hans Verkuild1f81da2008-10-22 00:04:45 -0300496 if (get_user(kp->m.offset, &up->m.offset))
Guy Martina113bc72006-01-11 23:40:51 -0200497 return -EFAULT;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200498 break;
499 }
500 return 0;
501}
502
503static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user *up)
504{
Guy Martina113bc72006-01-11 23:40:51 -0200505 if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_buffer32)) ||
506 put_user(kp->index, &up->index) ||
507 put_user(kp->type, &up->type) ||
508 put_user(kp->flags, &up->flags) ||
509 put_user(kp->memory, &up->memory) ||
510 put_user(kp->input, &up->input))
511 return -EFAULT;
Hans Verkuild1f81da2008-10-22 00:04:45 -0300512 switch (kp->memory) {
Philippe De Muytercf664a62006-01-09 15:24:59 -0200513 case V4L2_MEMORY_MMAP:
Guy Martina113bc72006-01-11 23:40:51 -0200514 if (put_user(kp->length, &up->length) ||
515 put_user(kp->m.offset, &up->m.offset))
516 return -EFAULT;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200517 break;
518 case V4L2_MEMORY_USERPTR:
Guy Martina113bc72006-01-11 23:40:51 -0200519 if (put_user(kp->length, &up->length) ||
520 put_user(kp->m.userptr, &up->m.userptr))
521 return -EFAULT;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200522 break;
523 case V4L2_MEMORY_OVERLAY:
Guy Martina113bc72006-01-11 23:40:51 -0200524 if (put_user(kp->m.offset, &up->m.offset))
525 return -EFAULT;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200526 break;
527 }
Guy Martina113bc72006-01-11 23:40:51 -0200528 if (put_user(kp->bytesused, &up->bytesused) ||
529 put_user(kp->field, &up->field) ||
530 put_user(kp->timestamp.tv_sec, &up->timestamp.tv_sec) ||
531 put_user(kp->timestamp.tv_usec, &up->timestamp.tv_usec) ||
532 copy_to_user(&up->timecode, &kp->timecode, sizeof(struct v4l2_timecode)) ||
533 put_user(kp->sequence, &up->sequence) ||
534 put_user(kp->reserved, &up->reserved))
535 return -EFAULT;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200536 return 0;
537}
538
Hans Verkuild1f81da2008-10-22 00:04:45 -0300539struct v4l2_framebuffer32 {
Philippe De Muytercf664a62006-01-09 15:24:59 -0200540 __u32 capability;
541 __u32 flags;
542 compat_caddr_t base;
543 struct v4l2_pix_format fmt;
544};
545
Philippe De Muyter13d133b2006-01-09 15:25:00 -0200546static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_framebuffer32 __user *up)
547{
548 u32 tmp;
549
Guy Martina113bc72006-01-11 23:40:51 -0200550 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_framebuffer32)) ||
551 get_user(tmp, &up->base) ||
552 get_user(kp->capability, &up->capability) ||
553 get_user(kp->flags, &up->flags))
554 return -EFAULT;
Philippe De Muyter13d133b2006-01-09 15:25:00 -0200555 kp->base = compat_ptr(tmp);
Philippe De Muyter13d133b2006-01-09 15:25:00 -0200556 get_v4l2_pix_format(&kp->fmt, &up->fmt);
557 return 0;
558}
559
Philippe De Muytercf664a62006-01-09 15:24:59 -0200560static int put_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_framebuffer32 __user *up)
561{
562 u32 tmp = (u32)((unsigned long)kp->base);
563
Hans Verkuild1f81da2008-10-22 00:04:45 -0300564 if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_framebuffer32)) ||
Guy Martina113bc72006-01-11 23:40:51 -0200565 put_user(tmp, &up->base) ||
566 put_user(kp->capability, &up->capability) ||
567 put_user(kp->flags, &up->flags))
568 return -EFAULT;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200569 put_v4l2_pix_format(&kp->fmt, &up->fmt);
570 return 0;
571}
572
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300573struct v4l2_input32 {
574 __u32 index; /* Which input */
575 __u8 name[32]; /* Label */
576 __u32 type; /* Type of input */
577 __u32 audioset; /* Associated audios (bitfield) */
578 __u32 tuner; /* Associated tuner */
579 v4l2_std_id std;
580 __u32 status;
581 __u32 reserved[4];
582} __attribute__ ((packed));
583
584/* The 64-bit v4l2_input struct has extra padding at the end of the struct.
585 Otherwise it is identical to the 32-bit version. */
586static inline int get_v4l2_input32(struct v4l2_input *kp, struct v4l2_input32 __user *up)
Philippe De Muytercf664a62006-01-09 15:24:59 -0200587{
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300588 if (copy_from_user(kp, up, sizeof(struct v4l2_input32)))
Al Viro5b1a43d2006-02-01 05:24:20 -0500589 return -EFAULT;
Guy Martina113bc72006-01-11 23:40:51 -0200590 return 0;
591}
592
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300593static inline int put_v4l2_input32(struct v4l2_input *kp, struct v4l2_input32 __user *up)
Guy Martina113bc72006-01-11 23:40:51 -0200594{
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300595 if (copy_to_user(up, kp, sizeof(struct v4l2_input32)))
Al Viro5b1a43d2006-02-01 05:24:20 -0500596 return -EFAULT;
Guy Martina113bc72006-01-11 23:40:51 -0200597 return 0;
598}
599
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300600struct v4l2_ext_controls32 {
601 __u32 ctrl_class;
602 __u32 count;
603 __u32 error_idx;
604 __u32 reserved[2];
605 compat_caddr_t controls; /* actually struct v4l2_ext_control32 * */
Mauro Carvalho Chehabeb4eecc2006-07-21 18:53:23 -0300606};
607
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300608struct v4l2_ext_control32 {
609 __u32 id;
610 __u32 size;
611 __u32 reserved2[1];
612 union {
613 __s32 value;
614 __s64 value64;
615 compat_caddr_t string; /* actually char * */
616 };
617} __attribute__ ((packed));
618
619/* The following function really belong in v4l2-common, but that causes
620 a circular dependency between modules. We need to think about this, but
621 for now this will do. */
622
623/* Return non-zero if this control is a pointer type. Currently only
Eduardo Valentinfdf82dc2009-08-11 18:49:12 -0300624 type STRING is a pointer type. */
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300625static inline int ctrl_is_pointer(u32 id)
626{
Eduardo Valentinfdf82dc2009-08-11 18:49:12 -0300627 switch (id) {
628 case V4L2_CID_RDS_TX_PS_NAME:
629 case V4L2_CID_RDS_TX_RADIO_TEXT:
630 return 1;
631 default:
632 return 0;
633 }
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300634}
635
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300636static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
Mauro Carvalho Chehabeb4eecc2006-07-21 18:53:23 -0300637{
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300638 struct v4l2_ext_control32 __user *ucontrols;
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300639 struct v4l2_ext_control __user *kcontrols;
640 int n;
641 compat_caddr_t p;
642
643 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_ext_controls32)) ||
644 get_user(kp->ctrl_class, &up->ctrl_class) ||
645 get_user(kp->count, &up->count) ||
646 get_user(kp->error_idx, &up->error_idx) ||
647 copy_from_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
Mauro Carvalho Chehabeb4eecc2006-07-21 18:53:23 -0300648 return -EFAULT;
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300649 n = kp->count;
650 if (n == 0) {
651 kp->controls = NULL;
652 return 0;
653 }
654 if (get_user(p, &up->controls))
655 return -EFAULT;
656 ucontrols = compat_ptr(p);
657 if (!access_ok(VERIFY_READ, ucontrols, n * sizeof(struct v4l2_ext_control)))
658 return -EFAULT;
659 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
660 kp->controls = kcontrols;
661 while (--n >= 0) {
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300662 if (copy_in_user(kcontrols, ucontrols, sizeof(*kcontrols)))
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300663 return -EFAULT;
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300664 if (ctrl_is_pointer(kcontrols->id)) {
665 void __user *s;
666
667 if (get_user(p, &ucontrols->string))
668 return -EFAULT;
669 s = compat_ptr(p);
670 if (put_user(s, &kcontrols->string))
671 return -EFAULT;
672 }
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300673 ucontrols++;
674 kcontrols++;
675 }
Mauro Carvalho Chehabeb4eecc2006-07-21 18:53:23 -0300676 return 0;
677}
678
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300679static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200680{
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300681 struct v4l2_ext_control32 __user *ucontrols;
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300682 struct v4l2_ext_control __user *kcontrols = kp->controls;
683 int n = kp->count;
684 compat_caddr_t p;
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200685
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300686 if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_ext_controls32)) ||
687 put_user(kp->ctrl_class, &up->ctrl_class) ||
688 put_user(kp->count, &up->count) ||
689 put_user(kp->error_idx, &up->error_idx) ||
690 copy_to_user(up->reserved, kp->reserved, sizeof(up->reserved)))
691 return -EFAULT;
692 if (!kp->count)
693 return 0;
694
695 if (get_user(p, &up->controls))
696 return -EFAULT;
697 ucontrols = compat_ptr(p);
698 if (!access_ok(VERIFY_WRITE, ucontrols, n * sizeof(struct v4l2_ext_control)))
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
717#define VIDIOC_G_FMT32 _IOWR('V', 4, struct v4l2_format32)
718#define VIDIOC_S_FMT32 _IOWR('V', 5, struct v4l2_format32)
719#define VIDIOC_QUERYBUF32 _IOWR('V', 9, struct v4l2_buffer32)
720#define VIDIOC_G_FBUF32 _IOR ('V', 10, struct v4l2_framebuffer32)
721#define VIDIOC_S_FBUF32 _IOW ('V', 11, struct v4l2_framebuffer32)
722#define VIDIOC_QBUF32 _IOWR('V', 15, struct v4l2_buffer32)
723#define VIDIOC_DQBUF32 _IOWR('V', 17, struct v4l2_buffer32)
724#define VIDIOC_ENUMSTD32 _IOWR('V', 25, struct v4l2_standard32)
725#define VIDIOC_ENUMINPUT32 _IOWR('V', 26, struct v4l2_input32)
726#define VIDIOC_TRY_FMT32 _IOWR('V', 64, struct v4l2_format32)
727#define VIDIOC_G_EXT_CTRLS32 _IOWR('V', 71, struct v4l2_ext_controls32)
728#define VIDIOC_S_EXT_CTRLS32 _IOWR('V', 72, struct v4l2_ext_controls32)
729#define VIDIOC_TRY_EXT_CTRLS32 _IOWR('V', 73, struct v4l2_ext_controls32)
730
731#define VIDIOC_OVERLAY32 _IOW ('V', 14, s32)
Hans Verkuil15029b32008-12-21 10:44:24 -0300732#ifdef __OLD_VIDIOC_
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300733#define VIDIOC_OVERLAY32_OLD _IOWR('V', 14, s32)
Hans Verkuil15029b32008-12-21 10:44:24 -0300734#endif
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300735#define VIDIOC_STREAMON32 _IOW ('V', 18, s32)
736#define VIDIOC_STREAMOFF32 _IOW ('V', 19, s32)
737#define VIDIOC_G_INPUT32 _IOR ('V', 38, s32)
738#define VIDIOC_S_INPUT32 _IOWR('V', 39, s32)
739#define VIDIOC_G_OUTPUT32 _IOR ('V', 46, s32)
740#define VIDIOC_S_OUTPUT32 _IOWR('V', 47, s32)
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200741
Hans Verkuil069b7472008-12-30 07:04:34 -0300742static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200743{
744 union {
Mauro Carvalho Chehab5bdd6cc2006-07-25 16:17:54 -0300745#ifdef CONFIG_VIDEO_V4L1_COMPAT
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200746 struct video_tuner vt;
747 struct video_buffer vb;
748 struct video_window vw;
Linus Torvalds3e645d62010-10-15 11:12:38 -0700749 struct video_code32 vc;
Mauro Carvalho Chehab8a36ecf2006-08-06 10:16:27 -0300750 struct video_audio va;
Mauro Carvalho Chehab5bdd6cc2006-07-25 16:17:54 -0300751#endif
Philippe De Muytercf664a62006-01-09 15:24:59 -0200752 struct v4l2_format v2f;
753 struct v4l2_buffer v2b;
754 struct v4l2_framebuffer v2fb;
Guy Martina113bc72006-01-11 23:40:51 -0200755 struct v4l2_input v2i;
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300756 struct v4l2_standard v2s;
757 struct v4l2_ext_controls v2ecs;
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200758 unsigned long vx;
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300759 int vi;
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200760 } karg;
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200761 void __user *up = compat_ptr(arg);
Philippe De Muytercf664a62006-01-09 15:24:59 -0200762 int compatible_arg = 1;
Hans Verkuil069b7472008-12-30 07:04:34 -0300763 long err = 0;
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200764
765 /* First, convert the command. */
Hans Verkuild1f81da2008-10-22 00:04:45 -0300766 switch (cmd) {
Mauro Carvalho Chehab5bdd6cc2006-07-25 16:17:54 -0300767#ifdef CONFIG_VIDEO_V4L1_COMPAT
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300768 case VIDIOCGTUNER32: cmd = VIDIOCGTUNER; break;
769 case VIDIOCSTUNER32: cmd = VIDIOCSTUNER; break;
770 case VIDIOCGWIN32: cmd = VIDIOCGWIN; break;
771 case VIDIOCSWIN32: cmd = VIDIOCSWIN; break;
772 case VIDIOCGFBUF32: cmd = VIDIOCGFBUF; break;
773 case VIDIOCSFBUF32: cmd = VIDIOCSFBUF; break;
774 case VIDIOCGFREQ32: cmd = VIDIOCGFREQ; break;
775 case VIDIOCSFREQ32: cmd = VIDIOCSFREQ; break;
776 case VIDIOCSMICROCODE32: cmd = VIDIOCSMICROCODE; break;
Mauro Carvalho Chehab5bdd6cc2006-07-25 16:17:54 -0300777#endif
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300778 case VIDIOC_G_FMT32: cmd = VIDIOC_G_FMT; break;
779 case VIDIOC_S_FMT32: cmd = VIDIOC_S_FMT; break;
780 case VIDIOC_QUERYBUF32: cmd = VIDIOC_QUERYBUF; break;
781 case VIDIOC_G_FBUF32: cmd = VIDIOC_G_FBUF; break;
782 case VIDIOC_S_FBUF32: cmd = VIDIOC_S_FBUF; break;
783 case VIDIOC_QBUF32: cmd = VIDIOC_QBUF; break;
784 case VIDIOC_DQBUF32: cmd = VIDIOC_DQBUF; break;
785 case VIDIOC_ENUMSTD32: cmd = VIDIOC_ENUMSTD; break;
786 case VIDIOC_ENUMINPUT32: cmd = VIDIOC_ENUMINPUT; break;
787 case VIDIOC_TRY_FMT32: cmd = VIDIOC_TRY_FMT; break;
788 case VIDIOC_G_EXT_CTRLS32: cmd = VIDIOC_G_EXT_CTRLS; break;
789 case VIDIOC_S_EXT_CTRLS32: cmd = VIDIOC_S_EXT_CTRLS; break;
790 case VIDIOC_TRY_EXT_CTRLS32: cmd = VIDIOC_TRY_EXT_CTRLS; break;
791 case VIDIOC_OVERLAY32: cmd = VIDIOC_OVERLAY; break;
Hans Verkuil15029b32008-12-21 10:44:24 -0300792#ifdef __OLD_VIDIOC_
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300793 case VIDIOC_OVERLAY32_OLD: cmd = VIDIOC_OVERLAY; break;
Hans Verkuil15029b32008-12-21 10:44:24 -0300794#endif
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300795 case VIDIOC_STREAMON32: cmd = VIDIOC_STREAMON; break;
796 case VIDIOC_STREAMOFF32: cmd = VIDIOC_STREAMOFF; break;
797 case VIDIOC_G_INPUT32: cmd = VIDIOC_G_INPUT; break;
798 case VIDIOC_S_INPUT32: cmd = VIDIOC_S_INPUT; break;
799 case VIDIOC_G_OUTPUT32: cmd = VIDIOC_G_OUTPUT; break;
800 case VIDIOC_S_OUTPUT32: cmd = VIDIOC_S_OUTPUT; break;
801 }
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200802
Hans Verkuild1f81da2008-10-22 00:04:45 -0300803 switch (cmd) {
Mauro Carvalho Chehab5bdd6cc2006-07-25 16:17:54 -0300804#ifdef CONFIG_VIDEO_V4L1_COMPAT
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200805 case VIDIOCSTUNER:
806 case VIDIOCGTUNER:
807 err = get_video_tuner32(&karg.vt, up);
Philippe De Muytercf664a62006-01-09 15:24:59 -0200808 compatible_arg = 0;
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200809 break;
810
811 case VIDIOCSFBUF:
812 err = get_video_buffer32(&karg.vb, up);
Philippe De Muytercf664a62006-01-09 15:24:59 -0200813 compatible_arg = 0;
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200814 break;
815
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300816 case VIDIOCSWIN:
817 err = get_video_window32(&karg.vw, up);
818 compatible_arg = 0;
819 break;
820
821 case VIDIOCGWIN:
822 case VIDIOCGFBUF:
823 case VIDIOCGFREQ:
824 compatible_arg = 0;
825 break;
826
827 case VIDIOCSMICROCODE:
Linus Torvalds3e645d62010-10-15 11:12:38 -0700828 /* Copy the 32-bit "video_code32" to kernel space */
829 if (copy_from_user(&karg.vc, up, sizeof(karg.vc)))
830 return -EFAULT;
831 /* Convert the 32-bit version to a 64-bit version in user space */
832 up = get_microcode32(&karg.vc);
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300833 break;
Mauro Carvalho Chehab8a36ecf2006-08-06 10:16:27 -0300834
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200835 case VIDIOCSFREQ:
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300836 err = get_user(karg.vx, (u32 __user *)up);
837 compatible_arg = 0;
838 break;
839
840 case VIDIOCCAPTURE:
841 case VIDIOCSYNC:
842 case VIDIOCSWRITEMODE:
Mauro Carvalho Chehab5bdd6cc2006-07-25 16:17:54 -0300843#endif
Philippe De Muytercf664a62006-01-09 15:24:59 -0200844 case VIDIOC_OVERLAY:
Philippe De Muyter13d133b2006-01-09 15:25:00 -0200845 case VIDIOC_STREAMON:
846 case VIDIOC_STREAMOFF:
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300847 case VIDIOC_S_INPUT:
848 case VIDIOC_S_OUTPUT:
849 err = get_user(karg.vi, (s32 __user *)up);
850 compatible_arg = 0;
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200851 break;
Philippe De Muyter13d133b2006-01-09 15:25:00 -0200852
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300853 case VIDIOC_G_INPUT:
854 case VIDIOC_G_OUTPUT:
Philippe De Muyter13d133b2006-01-09 15:25:00 -0200855 compatible_arg = 0;
856 break;
Philippe De Muytercf664a62006-01-09 15:24:59 -0200857
858 case VIDIOC_G_FMT:
859 case VIDIOC_S_FMT:
860 case VIDIOC_TRY_FMT:
861 err = get_v4l2_format32(&karg.v2f, up);
862 compatible_arg = 0;
863 break;
864
865 case VIDIOC_QUERYBUF:
866 case VIDIOC_QBUF:
867 case VIDIOC_DQBUF:
868 err = get_v4l2_buffer32(&karg.v2b, up);
869 compatible_arg = 0;
870 break;
871
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300872 case VIDIOC_S_FBUF:
873 err = get_v4l2_framebuffer32(&karg.v2fb, up);
Guy Martina113bc72006-01-11 23:40:51 -0200874 compatible_arg = 0;
875 break;
876
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300877 case VIDIOC_G_FBUF:
878 compatible_arg = 0;
879 break;
880
881 case VIDIOC_ENUMSTD:
Philippe De Muytercf664a62006-01-09 15:24:59 -0200882 err = get_v4l2_standard32(&karg.v2s, up);
883 compatible_arg = 0;
884 break;
885
Guy Martina113bc72006-01-11 23:40:51 -0200886 case VIDIOC_ENUMINPUT:
Guy Martina113bc72006-01-11 23:40:51 -0200887 err = get_v4l2_input32(&karg.v2i, up);
888 compatible_arg = 0;
889 break;
890
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300891 case VIDIOC_G_EXT_CTRLS:
892 case VIDIOC_S_EXT_CTRLS:
893 case VIDIOC_TRY_EXT_CTRLS:
894 err = get_v4l2_ext_controls32(&karg.v2ecs, up);
Guy Martina113bc72006-01-11 23:40:51 -0200895 compatible_arg = 0;
896 break;
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300897 }
Hans Verkuild1f81da2008-10-22 00:04:45 -0300898 if (err)
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300899 return err;
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200900
Hans Verkuild1f81da2008-10-22 00:04:45 -0300901 if (compatible_arg)
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300902 err = native_ioctl(file, cmd, (unsigned long)up);
Philippe De Muytercf664a62006-01-09 15:24:59 -0200903 else {
904 mm_segment_t old_fs = get_fs();
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200905
Philippe De Muytercf664a62006-01-09 15:24:59 -0200906 set_fs(KERNEL_DS);
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300907 err = native_ioctl(file, cmd, (unsigned long)&karg);
Philippe De Muytercf664a62006-01-09 15:24:59 -0200908 set_fs(old_fs);
909 }
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200910
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300911 /* Special case: even after an error we need to put the
912 results back for these ioctls since the error_idx will
913 contain information on which control failed. */
914 switch (cmd) {
915 case VIDIOC_G_EXT_CTRLS:
916 case VIDIOC_S_EXT_CTRLS:
917 case VIDIOC_TRY_EXT_CTRLS:
918 if (put_v4l2_ext_controls32(&karg.v2ecs, up))
919 err = -EFAULT;
920 break;
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200921 }
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300922 if (err)
923 return err;
924
925 switch (cmd) {
926#ifdef CONFIG_VIDEO_V4L1_COMPAT
927 case VIDIOCGTUNER:
928 err = put_video_tuner32(&karg.vt, up);
929 break;
930
931 case VIDIOCGWIN:
932 err = put_video_window32(&karg.vw, up);
933 break;
934
935 case VIDIOCGFBUF:
936 err = put_video_buffer32(&karg.vb, up);
937 break;
938
939 case VIDIOCGFREQ:
940 err = put_user(((u32)karg.vx), (u32 __user *)up);
941 break;
942#endif
943 case VIDIOC_S_INPUT:
944 case VIDIOC_S_OUTPUT:
945 case VIDIOC_G_INPUT:
946 case VIDIOC_G_OUTPUT:
947 err = put_user(((s32)karg.vi), (s32 __user *)up);
948 break;
949
950 case VIDIOC_G_FBUF:
951 err = put_v4l2_framebuffer32(&karg.v2fb, up);
952 break;
953
954 case VIDIOC_G_FMT:
955 case VIDIOC_S_FMT:
956 case VIDIOC_TRY_FMT:
957 err = put_v4l2_format32(&karg.v2f, up);
958 break;
959
960 case VIDIOC_QUERYBUF:
961 case VIDIOC_QBUF:
962 case VIDIOC_DQBUF:
963 err = put_v4l2_buffer32(&karg.v2b, up);
964 break;
965
966 case VIDIOC_ENUMSTD:
967 err = put_v4l2_standard32(&karg.v2s, up);
968 break;
969
970 case VIDIOC_ENUMINPUT:
971 err = put_v4l2_input32(&karg.v2i, up);
972 break;
973 }
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200974 return err;
975}
976
Hans Verkuil9bb7cde2008-12-30 06:42:40 -0300977long v4l2_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200978{
Hans Verkuil069b7472008-12-30 07:04:34 -0300979 long ret = -ENOIOCTLCMD;
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200980
Frederic Weisbeckerc6d7ba82010-08-13 22:29:03 +0200981 if (!file->f_op->unlocked_ioctl)
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200982 return ret;
983
984 switch (cmd) {
Mauro Carvalho Chehab5bdd6cc2006-07-25 16:17:54 -0300985#ifdef CONFIG_VIDEO_V4L1_COMPAT
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300986 case VIDIOCGCAP:
987 case VIDIOCGCHAN:
988 case VIDIOCSCHAN:
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200989 case VIDIOCGTUNER32:
990 case VIDIOCSTUNER32:
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300991 case VIDIOCGPICT:
992 case VIDIOCSPICT:
993 case VIDIOCCAPTURE32:
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200994 case VIDIOCGWIN32:
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300995 case VIDIOCSWIN32:
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200996 case VIDIOCGFBUF32:
997 case VIDIOCSFBUF32:
Hans Verkuil92f45ba2008-12-21 10:35:25 -0300998 case VIDIOCKEY:
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -0200999 case VIDIOCGFREQ32:
Nickolay V. Shmyrev133b7352006-01-09 15:24:58 -02001000 case VIDIOCSFREQ32:
Mauro Carvalho Chehab8a36ecf2006-08-06 10:16:27 -03001001 case VIDIOCGAUDIO:
1002 case VIDIOCSAUDIO:
Hans Verkuil92f45ba2008-12-21 10:35:25 -03001003 case VIDIOCSYNC32:
1004 case VIDIOCMCAPTURE:
1005 case VIDIOCGMBUF:
1006 case VIDIOCGUNIT:
1007 case VIDIOCGCAPTURE:
1008 case VIDIOCSCAPTURE:
1009 case VIDIOCSPLAYMODE:
1010 case VIDIOCSWRITEMODE32:
1011 case VIDIOCGPLAYINFO:
1012 case VIDIOCSMICROCODE32:
Steven Walter7963fa42007-08-09 11:36:35 -03001013 case VIDIOCGVBIFMT:
1014 case VIDIOCSVBIFMT:
Mauro Carvalho Chehab5bdd6cc2006-07-25 16:17:54 -03001015#endif
Hans Verkuil92f45ba2008-12-21 10:35:25 -03001016#ifdef __OLD_VIDIOC_
1017 case VIDIOC_OVERLAY32_OLD:
1018 case VIDIOC_S_PARM_OLD:
1019 case VIDIOC_S_CTRL_OLD:
1020 case VIDIOC_G_AUDIO_OLD:
1021 case VIDIOC_G_AUDOUT_OLD:
1022 case VIDIOC_CROPCAP_OLD:
1023#endif
Philippe De Muyter13d133b2006-01-09 15:25:00 -02001024 case VIDIOC_QUERYCAP:
Hans Verkuil92f45ba2008-12-21 10:35:25 -03001025 case VIDIOC_RESERVED:
Philippe De Muyter13d133b2006-01-09 15:25:00 -02001026 case VIDIOC_ENUM_FMT:
1027 case VIDIOC_G_FMT32:
1028 case VIDIOC_S_FMT32:
1029 case VIDIOC_REQBUFS:
1030 case VIDIOC_QUERYBUF32:
1031 case VIDIOC_G_FBUF32:
1032 case VIDIOC_S_FBUF32:
1033 case VIDIOC_OVERLAY32:
1034 case VIDIOC_QBUF32:
1035 case VIDIOC_DQBUF32:
1036 case VIDIOC_STREAMON32:
1037 case VIDIOC_STREAMOFF32:
1038 case VIDIOC_G_PARM:
Gregor Jasnyc7f09db2008-10-23 09:55:22 -03001039 case VIDIOC_S_PARM:
Philippe De Muyter13d133b2006-01-09 15:25:00 -02001040 case VIDIOC_G_STD:
1041 case VIDIOC_S_STD:
1042 case VIDIOC_ENUMSTD32:
1043 case VIDIOC_ENUMINPUT32:
1044 case VIDIOC_G_CTRL:
Steven Walter7963fa42007-08-09 11:36:35 -03001045 case VIDIOC_S_CTRL:
Hans Verkuil92f45ba2008-12-21 10:35:25 -03001046 case VIDIOC_G_TUNER:
1047 case VIDIOC_S_TUNER:
1048 case VIDIOC_G_AUDIO:
1049 case VIDIOC_S_AUDIO:
Philippe De Muyter13d133b2006-01-09 15:25:00 -02001050 case VIDIOC_QUERYCTRL:
Hans Verkuil92f45ba2008-12-21 10:35:25 -03001051 case VIDIOC_QUERYMENU:
Philippe De Muyter13d133b2006-01-09 15:25:00 -02001052 case VIDIOC_G_INPUT32:
1053 case VIDIOC_S_INPUT32:
Hans Verkuil92f45ba2008-12-21 10:35:25 -03001054 case VIDIOC_G_OUTPUT32:
1055 case VIDIOC_S_OUTPUT32:
1056 case VIDIOC_ENUMOUTPUT:
1057 case VIDIOC_G_AUDOUT:
1058 case VIDIOC_S_AUDOUT:
1059 case VIDIOC_G_MODULATOR:
1060 case VIDIOC_S_MODULATOR:
1061 case VIDIOC_S_FREQUENCY:
1062 case VIDIOC_G_FREQUENCY:
1063 case VIDIOC_CROPCAP:
1064 case VIDIOC_G_CROP:
1065 case VIDIOC_S_CROP:
1066 case VIDIOC_G_JPEGCOMP:
1067 case VIDIOC_S_JPEGCOMP:
1068 case VIDIOC_QUERYSTD:
Philippe De Muyter13d133b2006-01-09 15:25:00 -02001069 case VIDIOC_TRY_FMT32:
Hans Verkuil92f45ba2008-12-21 10:35:25 -03001070 case VIDIOC_ENUMAUDIO:
1071 case VIDIOC_ENUMAUDOUT:
1072 case VIDIOC_G_PRIORITY:
1073 case VIDIOC_S_PRIORITY:
1074 case VIDIOC_G_SLICED_VBI_CAP:
1075 case VIDIOC_LOG_STATUS:
1076 case VIDIOC_G_EXT_CTRLS32:
1077 case VIDIOC_S_EXT_CTRLS32:
1078 case VIDIOC_TRY_EXT_CTRLS32:
Gregor Jasnyc7f09db2008-10-23 09:55:22 -03001079 case VIDIOC_ENUM_FRAMESIZES:
1080 case VIDIOC_ENUM_FRAMEINTERVALS:
Hans Verkuil92f45ba2008-12-21 10:35:25 -03001081 case VIDIOC_G_ENC_INDEX:
1082 case VIDIOC_ENCODER_CMD:
1083 case VIDIOC_TRY_ENCODER_CMD:
1084 case VIDIOC_DBG_S_REGISTER:
1085 case VIDIOC_DBG_G_REGISTER:
Hans Verkuilaecde8b2008-12-30 07:14:19 -03001086 case VIDIOC_DBG_G_CHIP_IDENT:
Hans Verkuil92f45ba2008-12-21 10:35:25 -03001087 case VIDIOC_S_HW_FREQ_SEEK:
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001088 case VIDIOC_ENUM_DV_PRESETS:
1089 case VIDIOC_S_DV_PRESET:
1090 case VIDIOC_G_DV_PRESET:
1091 case VIDIOC_QUERY_DV_PRESET:
1092 case VIDIOC_S_DV_TIMINGS:
1093 case VIDIOC_G_DV_TIMINGS:
Sakari Ailusfda10212010-02-24 19:19:05 -03001094 case VIDIOC_DQEVENT:
1095 case VIDIOC_SUBSCRIBE_EVENT:
1096 case VIDIOC_UNSUBSCRIBE_EVENT:
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -02001097 ret = do_video_ioctl(file, cmd, arg);
1098 break;
1099
Mauro Carvalho Chehab5bdd6cc2006-07-25 16:17:54 -03001100#ifdef CONFIG_VIDEO_V4L1_COMPAT
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -02001101 /* BTTV specific... */
1102 case _IOW('v', BASE_VIDIOCPRIVATE+0, char [256]):
1103 case _IOR('v', BASE_VIDIOCPRIVATE+1, char [256]):
1104 case _IOR('v' , BASE_VIDIOCPRIVATE+2, unsigned int):
1105 case _IOW('v' , BASE_VIDIOCPRIVATE+3, char [16]): /* struct bttv_pll_info */
1106 case _IOR('v' , BASE_VIDIOCPRIVATE+4, int):
1107 case _IOR('v' , BASE_VIDIOCPRIVATE+5, int):
1108 case _IOR('v' , BASE_VIDIOCPRIVATE+6, int):
1109 case _IOR('v' , BASE_VIDIOCPRIVATE+7, int):
1110 ret = native_ioctl(file, cmd, (unsigned long)compat_ptr(arg));
1111 break;
Mauro Carvalho Chehab5bdd6cc2006-07-25 16:17:54 -03001112#endif
Guy Martina113bc72006-01-11 23:40:51 -02001113 default:
Hans Verkuil7943ecf2008-12-23 14:37:43 -03001114 printk(KERN_WARNING "compat_ioctl32: "
1115 "unknown ioctl '%c', dir=%d, #%d (0x%08x)\n",
1116 _IOC_TYPE(cmd), _IOC_DIR(cmd), _IOC_NR(cmd), cmd);
Hans Verkuil7d4f0b82008-12-15 07:19:20 -03001117 break;
MishalĂ… Pytasz97e2a012006-01-09 15:24:59 -02001118 }
Hans Verkuile8efb712006-01-09 15:24:59 -02001119 return ret;
Arnd Bergmann0d0fbf82006-01-09 15:24:57 -02001120}
Hans Verkuil9bb7cde2008-12-30 06:42:40 -03001121EXPORT_SYMBOL_GPL(v4l2_compat_ioctl32);
Hans Verkuilbec43662008-12-30 06:58:20 -03001122#endif
Ricardo Cerqueira925e6992006-01-09 15:24:57 -02001123
1124MODULE_LICENSE("GPL");