v4l: Remove reference to bkl ioctl in compat ioctl handling
[linux-2.6/libata-dev.git] / drivers / media / video / v4l2-compat-ioctl32.c
blob073f01390cdd0a00de7e34dc7cd30360b72912c4
1 /*
2 * ioctl32.c: Conversion between 32bit and 64bit native ioctls.
3 * Separated from fs stuff by Arnd Bergmann <arnd@arndb.de>
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
8 * Copyright (C) 2003 Pavel Machek (pavel@ucw.cz)
9 * Copyright (C) 2005 Philippe De Muyter (phdm@macqel.be)
10 * Copyright (C) 2008 Hans Verkuil <hverkuil@xs4all.nl>
12 * These routines maintain argument size conversion between 32bit and 64bit
13 * ioctls.
16 #include <linux/compat.h>
17 #define __OLD_VIDIOC_ /* To allow fixing old calls*/
18 #include <linux/videodev.h>
19 #include <linux/videodev2.h>
20 #include <linux/module.h>
21 #include <linux/smp_lock.h>
22 #include <media/v4l2-ioctl.h>
24 #ifdef CONFIG_COMPAT
26 #ifdef CONFIG_VIDEO_V4L1_COMPAT
27 struct 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;
35 static int get_video_tuner32(struct video_tuner *kp, struct video_tuner32 __user *up)
37 if (!access_ok(VERIFY_READ, up, sizeof(struct video_tuner32)) ||
38 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))
45 return -EFAULT;
46 return 0;
49 static int put_video_tuner32(struct video_tuner *kp, struct video_tuner32 __user *up)
51 if (!access_ok(VERIFY_WRITE, up, sizeof(struct video_tuner32)) ||
52 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;
60 return 0;
63 struct video_buffer32 {
64 compat_caddr_t base;
65 compat_int_t height, width, depth, bytesperline;
68 static int get_video_buffer32(struct video_buffer *kp, struct video_buffer32 __user *up)
70 u32 tmp;
72 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;
80 /* This is actually a physical address stored
81 * as a void pointer.
83 kp->base = (void *)(unsigned long) tmp;
85 return 0;
88 static int put_video_buffer32(struct video_buffer *kp, struct video_buffer32 __user *up)
90 u32 tmp = (u32)((unsigned long)kp->base);
92 if (!access_ok(VERIFY_WRITE, up, sizeof(struct video_buffer32)) ||
93 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;
99 return 0;
102 struct video_clip32 {
103 s32 x, y, width, height; /* It's really s32 in videodev.h */
104 compat_caddr_t next;
107 struct video_window32 {
108 u32 x, y, width, height, chromakey, flags;
109 compat_caddr_t clips;
110 compat_int_t clipcount;
113 static int get_video_window32(struct video_window *kp, struct video_window32 __user *up)
115 struct video_clip __user *uclips;
116 struct video_clip __user *kclips;
117 compat_caddr_t p;
118 int nclips;
120 if (!access_ok(VERIFY_READ, up, sizeof(struct video_window32)))
121 return -EFAULT;
123 if (get_user(nclips, &up->clipcount))
124 return -EFAULT;
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;
136 nclips = kp->clipcount;
137 kp->clips = NULL;
139 if (nclips == 0)
140 return 0;
141 if (get_user(p, &up->clips))
142 return -EFAULT;
143 uclips = compat_ptr(p);
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;
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;
160 kp->clips = compat_alloc_user_space(nclips * sizeof(struct video_clip));
161 kclips = kp->clips;
162 while (nclips--) {
163 int err;
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++;
175 return 0;
178 /* You get back everything except the clips... */
179 static int put_video_window32(struct video_window *kp, struct video_window32 __user *up)
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;
193 struct video_code32 {
194 char loadwhat[16]; /* name or tag of file being passed */
195 compat_int_t datasize;
196 unsigned char *data;
199 static int get_microcode32(struct video_code *kp, struct video_code32 __user *up)
201 if (!access_ok(VERIFY_READ, up, sizeof(struct video_code32)) ||
202 copy_from_user(kp->loadwhat, up->loadwhat, sizeof(up->loadwhat)) ||
203 get_user(kp->datasize, &up->datasize) ||
204 copy_from_user(kp->data, up->data, up->datasize))
205 return -EFAULT;
206 return 0;
209 #define VIDIOCGTUNER32 _IOWR('v', 4, struct video_tuner32)
210 #define VIDIOCSTUNER32 _IOW('v', 5, struct video_tuner32)
211 #define VIDIOCGWIN32 _IOR('v', 9, struct video_window32)
212 #define VIDIOCSWIN32 _IOW('v', 10, struct video_window32)
213 #define VIDIOCGFBUF32 _IOR('v', 11, struct video_buffer32)
214 #define VIDIOCSFBUF32 _IOW('v', 12, struct video_buffer32)
215 #define VIDIOCGFREQ32 _IOR('v', 14, u32)
216 #define VIDIOCSFREQ32 _IOW('v', 15, u32)
217 #define VIDIOCSMICROCODE32 _IOW('v', 27, struct video_code32)
219 #define VIDIOCCAPTURE32 _IOW('v', 8, s32)
220 #define VIDIOCSYNC32 _IOW('v', 18, s32)
221 #define VIDIOCSWRITEMODE32 _IOW('v', 25, s32)
223 #endif
225 static long native_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
227 long ret = -ENOIOCTLCMD;
229 if (file->f_op->unlocked_ioctl)
230 ret = file->f_op->unlocked_ioctl(file, cmd, arg);
232 return ret;
236 struct v4l2_clip32 {
237 struct v4l2_rect c;
238 compat_caddr_t next;
241 struct v4l2_window32 {
242 struct v4l2_rect w;
243 enum v4l2_field field;
244 __u32 chromakey;
245 compat_caddr_t clips; /* actually struct v4l2_clip32 * */
246 __u32 clipcount;
247 compat_caddr_t bitmap;
250 static int get_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 __user *up)
252 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_window32)) ||
253 copy_from_user(&kp->w, &up->w, sizeof(up->w)) ||
254 get_user(kp->field, &up->field) ||
255 get_user(kp->chromakey, &up->chromakey) ||
256 get_user(kp->clipcount, &up->clipcount))
257 return -EFAULT;
258 if (kp->clipcount > 2048)
259 return -EINVAL;
260 if (kp->clipcount) {
261 struct v4l2_clip32 __user *uclips;
262 struct v4l2_clip __user *kclips;
263 int n = kp->clipcount;
264 compat_caddr_t p;
266 if (get_user(p, &up->clips))
267 return -EFAULT;
268 uclips = compat_ptr(p);
269 kclips = compat_alloc_user_space(n * sizeof(struct v4l2_clip));
270 kp->clips = kclips;
271 while (--n >= 0) {
272 if (copy_in_user(&kclips->c, &uclips->c, sizeof(uclips->c)))
273 return -EFAULT;
274 if (put_user(n ? kclips + 1 : NULL, &kclips->next))
275 return -EFAULT;
276 uclips += 1;
277 kclips += 1;
279 } else
280 kp->clips = NULL;
281 return 0;
284 static int put_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 __user *up)
286 if (copy_to_user(&up->w, &kp->w, sizeof(kp->w)) ||
287 put_user(kp->field, &up->field) ||
288 put_user(kp->chromakey, &up->chromakey) ||
289 put_user(kp->clipcount, &up->clipcount))
290 return -EFAULT;
291 return 0;
294 static inline int get_v4l2_pix_format(struct v4l2_pix_format *kp, struct v4l2_pix_format __user *up)
296 if (copy_from_user(kp, up, sizeof(struct v4l2_pix_format)))
297 return -EFAULT;
298 return 0;
301 static inline int put_v4l2_pix_format(struct v4l2_pix_format *kp, struct v4l2_pix_format __user *up)
303 if (copy_to_user(up, kp, sizeof(struct v4l2_pix_format)))
304 return -EFAULT;
305 return 0;
308 static inline int get_v4l2_vbi_format(struct v4l2_vbi_format *kp, struct v4l2_vbi_format __user *up)
310 if (copy_from_user(kp, up, sizeof(struct v4l2_vbi_format)))
311 return -EFAULT;
312 return 0;
315 static inline int put_v4l2_vbi_format(struct v4l2_vbi_format *kp, struct v4l2_vbi_format __user *up)
317 if (copy_to_user(up, kp, sizeof(struct v4l2_vbi_format)))
318 return -EFAULT;
319 return 0;
322 static inline int get_v4l2_sliced_vbi_format(struct v4l2_sliced_vbi_format *kp, struct v4l2_sliced_vbi_format __user *up)
324 if (copy_from_user(kp, up, sizeof(struct v4l2_sliced_vbi_format)))
325 return -EFAULT;
326 return 0;
329 static inline int put_v4l2_sliced_vbi_format(struct v4l2_sliced_vbi_format *kp, struct v4l2_sliced_vbi_format __user *up)
331 if (copy_to_user(up, kp, sizeof(struct v4l2_sliced_vbi_format)))
332 return -EFAULT;
333 return 0;
336 struct v4l2_format32 {
337 enum v4l2_buf_type type;
338 union {
339 struct v4l2_pix_format pix;
340 struct v4l2_window32 win;
341 struct v4l2_vbi_format vbi;
342 struct v4l2_sliced_vbi_format sliced;
343 __u8 raw_data[200]; /* user-defined */
344 } fmt;
347 static int get_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up)
349 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_format32)) ||
350 get_user(kp->type, &up->type))
351 return -EFAULT;
352 switch (kp->type) {
353 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
354 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
355 return get_v4l2_pix_format(&kp->fmt.pix, &up->fmt.pix);
356 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
357 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
358 return get_v4l2_window32(&kp->fmt.win, &up->fmt.win);
359 case V4L2_BUF_TYPE_VBI_CAPTURE:
360 case V4L2_BUF_TYPE_VBI_OUTPUT:
361 return get_v4l2_vbi_format(&kp->fmt.vbi, &up->fmt.vbi);
362 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
363 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
364 return get_v4l2_sliced_vbi_format(&kp->fmt.sliced, &up->fmt.sliced);
365 case V4L2_BUF_TYPE_PRIVATE:
366 if (copy_from_user(kp, up, sizeof(kp->fmt.raw_data)))
367 return -EFAULT;
368 return 0;
369 case 0:
370 return -EINVAL;
371 default:
372 printk(KERN_INFO "compat_ioctl32: unexpected VIDIOC_FMT type %d\n",
373 kp->type);
374 return -EINVAL;
378 static int put_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up)
380 if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_format32)) ||
381 put_user(kp->type, &up->type))
382 return -EFAULT;
383 switch (kp->type) {
384 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
385 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
386 return put_v4l2_pix_format(&kp->fmt.pix, &up->fmt.pix);
387 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
388 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
389 return put_v4l2_window32(&kp->fmt.win, &up->fmt.win);
390 case V4L2_BUF_TYPE_VBI_CAPTURE:
391 case V4L2_BUF_TYPE_VBI_OUTPUT:
392 return put_v4l2_vbi_format(&kp->fmt.vbi, &up->fmt.vbi);
393 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
394 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
395 return put_v4l2_sliced_vbi_format(&kp->fmt.sliced, &up->fmt.sliced);
396 case V4L2_BUF_TYPE_PRIVATE:
397 if (copy_to_user(up, kp, sizeof(up->fmt.raw_data)))
398 return -EFAULT;
399 return 0;
400 case 0:
401 return -EINVAL;
402 default:
403 printk(KERN_INFO "compat_ioctl32: unexpected VIDIOC_FMT type %d\n",
404 kp->type);
405 return -EINVAL;
409 struct v4l2_standard32 {
410 __u32 index;
411 __u32 id[2]; /* __u64 would get the alignment wrong */
412 __u8 name[24];
413 struct v4l2_fract frameperiod; /* Frames, not fields */
414 __u32 framelines;
415 __u32 reserved[4];
418 static int get_v4l2_standard32(struct v4l2_standard *kp, struct v4l2_standard32 __user *up)
420 /* other fields are not set by the user, nor used by the driver */
421 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_standard32)) ||
422 get_user(kp->index, &up->index))
423 return -EFAULT;
424 return 0;
427 static int put_v4l2_standard32(struct v4l2_standard *kp, struct v4l2_standard32 __user *up)
429 if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_standard32)) ||
430 put_user(kp->index, &up->index) ||
431 copy_to_user(up->id, &kp->id, sizeof(__u64)) ||
432 copy_to_user(up->name, kp->name, 24) ||
433 copy_to_user(&up->frameperiod, &kp->frameperiod, sizeof(kp->frameperiod)) ||
434 put_user(kp->framelines, &up->framelines) ||
435 copy_to_user(up->reserved, kp->reserved, 4 * sizeof(__u32)))
436 return -EFAULT;
437 return 0;
440 struct v4l2_buffer32 {
441 __u32 index;
442 enum v4l2_buf_type type;
443 __u32 bytesused;
444 __u32 flags;
445 enum v4l2_field field;
446 struct compat_timeval timestamp;
447 struct v4l2_timecode timecode;
448 __u32 sequence;
450 /* memory location */
451 enum v4l2_memory memory;
452 union {
453 __u32 offset;
454 compat_long_t userptr;
455 } m;
456 __u32 length;
457 __u32 input;
458 __u32 reserved;
461 static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user *up)
464 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_buffer32)) ||
465 get_user(kp->index, &up->index) ||
466 get_user(kp->type, &up->type) ||
467 get_user(kp->flags, &up->flags) ||
468 get_user(kp->memory, &up->memory) ||
469 get_user(kp->input, &up->input))
470 return -EFAULT;
471 switch (kp->memory) {
472 case V4L2_MEMORY_MMAP:
473 if (get_user(kp->length, &up->length) ||
474 get_user(kp->m.offset, &up->m.offset))
475 return -EFAULT;
476 break;
477 case V4L2_MEMORY_USERPTR:
479 compat_long_t tmp;
481 if (get_user(kp->length, &up->length) ||
482 get_user(tmp, &up->m.userptr))
483 return -EFAULT;
485 kp->m.userptr = (unsigned long)compat_ptr(tmp);
487 break;
488 case V4L2_MEMORY_OVERLAY:
489 if (get_user(kp->m.offset, &up->m.offset))
490 return -EFAULT;
491 break;
493 return 0;
496 static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user *up)
498 if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_buffer32)) ||
499 put_user(kp->index, &up->index) ||
500 put_user(kp->type, &up->type) ||
501 put_user(kp->flags, &up->flags) ||
502 put_user(kp->memory, &up->memory) ||
503 put_user(kp->input, &up->input))
504 return -EFAULT;
505 switch (kp->memory) {
506 case V4L2_MEMORY_MMAP:
507 if (put_user(kp->length, &up->length) ||
508 put_user(kp->m.offset, &up->m.offset))
509 return -EFAULT;
510 break;
511 case V4L2_MEMORY_USERPTR:
512 if (put_user(kp->length, &up->length) ||
513 put_user(kp->m.userptr, &up->m.userptr))
514 return -EFAULT;
515 break;
516 case V4L2_MEMORY_OVERLAY:
517 if (put_user(kp->m.offset, &up->m.offset))
518 return -EFAULT;
519 break;
521 if (put_user(kp->bytesused, &up->bytesused) ||
522 put_user(kp->field, &up->field) ||
523 put_user(kp->timestamp.tv_sec, &up->timestamp.tv_sec) ||
524 put_user(kp->timestamp.tv_usec, &up->timestamp.tv_usec) ||
525 copy_to_user(&up->timecode, &kp->timecode, sizeof(struct v4l2_timecode)) ||
526 put_user(kp->sequence, &up->sequence) ||
527 put_user(kp->reserved, &up->reserved))
528 return -EFAULT;
529 return 0;
532 struct v4l2_framebuffer32 {
533 __u32 capability;
534 __u32 flags;
535 compat_caddr_t base;
536 struct v4l2_pix_format fmt;
539 static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_framebuffer32 __user *up)
541 u32 tmp;
543 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_framebuffer32)) ||
544 get_user(tmp, &up->base) ||
545 get_user(kp->capability, &up->capability) ||
546 get_user(kp->flags, &up->flags))
547 return -EFAULT;
548 kp->base = compat_ptr(tmp);
549 get_v4l2_pix_format(&kp->fmt, &up->fmt);
550 return 0;
553 static int put_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_framebuffer32 __user *up)
555 u32 tmp = (u32)((unsigned long)kp->base);
557 if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_framebuffer32)) ||
558 put_user(tmp, &up->base) ||
559 put_user(kp->capability, &up->capability) ||
560 put_user(kp->flags, &up->flags))
561 return -EFAULT;
562 put_v4l2_pix_format(&kp->fmt, &up->fmt);
563 return 0;
566 struct v4l2_input32 {
567 __u32 index; /* Which input */
568 __u8 name[32]; /* Label */
569 __u32 type; /* Type of input */
570 __u32 audioset; /* Associated audios (bitfield) */
571 __u32 tuner; /* Associated tuner */
572 v4l2_std_id std;
573 __u32 status;
574 __u32 reserved[4];
575 } __attribute__ ((packed));
577 /* The 64-bit v4l2_input struct has extra padding at the end of the struct.
578 Otherwise it is identical to the 32-bit version. */
579 static inline int get_v4l2_input32(struct v4l2_input *kp, struct v4l2_input32 __user *up)
581 if (copy_from_user(kp, up, sizeof(struct v4l2_input32)))
582 return -EFAULT;
583 return 0;
586 static inline int put_v4l2_input32(struct v4l2_input *kp, struct v4l2_input32 __user *up)
588 if (copy_to_user(up, kp, sizeof(struct v4l2_input32)))
589 return -EFAULT;
590 return 0;
593 struct v4l2_ext_controls32 {
594 __u32 ctrl_class;
595 __u32 count;
596 __u32 error_idx;
597 __u32 reserved[2];
598 compat_caddr_t controls; /* actually struct v4l2_ext_control32 * */
601 struct v4l2_ext_control32 {
602 __u32 id;
603 __u32 size;
604 __u32 reserved2[1];
605 union {
606 __s32 value;
607 __s64 value64;
608 compat_caddr_t string; /* actually char * */
610 } __attribute__ ((packed));
612 /* The following function really belong in v4l2-common, but that causes
613 a circular dependency between modules. We need to think about this, but
614 for now this will do. */
616 /* Return non-zero if this control is a pointer type. Currently only
617 type STRING is a pointer type. */
618 static inline int ctrl_is_pointer(u32 id)
620 switch (id) {
621 case V4L2_CID_RDS_TX_PS_NAME:
622 case V4L2_CID_RDS_TX_RADIO_TEXT:
623 return 1;
624 default:
625 return 0;
629 static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
631 struct v4l2_ext_control32 __user *ucontrols;
632 struct v4l2_ext_control __user *kcontrols;
633 int n;
634 compat_caddr_t p;
636 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_ext_controls32)) ||
637 get_user(kp->ctrl_class, &up->ctrl_class) ||
638 get_user(kp->count, &up->count) ||
639 get_user(kp->error_idx, &up->error_idx) ||
640 copy_from_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
641 return -EFAULT;
642 n = kp->count;
643 if (n == 0) {
644 kp->controls = NULL;
645 return 0;
647 if (get_user(p, &up->controls))
648 return -EFAULT;
649 ucontrols = compat_ptr(p);
650 if (!access_ok(VERIFY_READ, ucontrols, n * sizeof(struct v4l2_ext_control)))
651 return -EFAULT;
652 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
653 kp->controls = kcontrols;
654 while (--n >= 0) {
655 if (copy_in_user(kcontrols, ucontrols, sizeof(*kcontrols)))
656 return -EFAULT;
657 if (ctrl_is_pointer(kcontrols->id)) {
658 void __user *s;
660 if (get_user(p, &ucontrols->string))
661 return -EFAULT;
662 s = compat_ptr(p);
663 if (put_user(s, &kcontrols->string))
664 return -EFAULT;
666 ucontrols++;
667 kcontrols++;
669 return 0;
672 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
674 struct v4l2_ext_control32 __user *ucontrols;
675 struct v4l2_ext_control __user *kcontrols = kp->controls;
676 int n = kp->count;
677 compat_caddr_t p;
679 if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_ext_controls32)) ||
680 put_user(kp->ctrl_class, &up->ctrl_class) ||
681 put_user(kp->count, &up->count) ||
682 put_user(kp->error_idx, &up->error_idx) ||
683 copy_to_user(up->reserved, kp->reserved, sizeof(up->reserved)))
684 return -EFAULT;
685 if (!kp->count)
686 return 0;
688 if (get_user(p, &up->controls))
689 return -EFAULT;
690 ucontrols = compat_ptr(p);
691 if (!access_ok(VERIFY_WRITE, ucontrols, n * sizeof(struct v4l2_ext_control)))
692 return -EFAULT;
694 while (--n >= 0) {
695 unsigned size = sizeof(*ucontrols);
697 /* Do not modify the pointer when copying a pointer control.
698 The contents of the pointer was changed, not the pointer
699 itself. */
700 if (ctrl_is_pointer(kcontrols->id))
701 size -= sizeof(ucontrols->value64);
702 if (copy_in_user(ucontrols, kcontrols, size))
703 return -EFAULT;
704 ucontrols++;
705 kcontrols++;
707 return 0;
710 #define VIDIOC_G_FMT32 _IOWR('V', 4, struct v4l2_format32)
711 #define VIDIOC_S_FMT32 _IOWR('V', 5, struct v4l2_format32)
712 #define VIDIOC_QUERYBUF32 _IOWR('V', 9, struct v4l2_buffer32)
713 #define VIDIOC_G_FBUF32 _IOR ('V', 10, struct v4l2_framebuffer32)
714 #define VIDIOC_S_FBUF32 _IOW ('V', 11, struct v4l2_framebuffer32)
715 #define VIDIOC_QBUF32 _IOWR('V', 15, struct v4l2_buffer32)
716 #define VIDIOC_DQBUF32 _IOWR('V', 17, struct v4l2_buffer32)
717 #define VIDIOC_ENUMSTD32 _IOWR('V', 25, struct v4l2_standard32)
718 #define VIDIOC_ENUMINPUT32 _IOWR('V', 26, struct v4l2_input32)
719 #define VIDIOC_TRY_FMT32 _IOWR('V', 64, struct v4l2_format32)
720 #define VIDIOC_G_EXT_CTRLS32 _IOWR('V', 71, struct v4l2_ext_controls32)
721 #define VIDIOC_S_EXT_CTRLS32 _IOWR('V', 72, struct v4l2_ext_controls32)
722 #define VIDIOC_TRY_EXT_CTRLS32 _IOWR('V', 73, struct v4l2_ext_controls32)
724 #define VIDIOC_OVERLAY32 _IOW ('V', 14, s32)
725 #ifdef __OLD_VIDIOC_
726 #define VIDIOC_OVERLAY32_OLD _IOWR('V', 14, s32)
727 #endif
728 #define VIDIOC_STREAMON32 _IOW ('V', 18, s32)
729 #define VIDIOC_STREAMOFF32 _IOW ('V', 19, s32)
730 #define VIDIOC_G_INPUT32 _IOR ('V', 38, s32)
731 #define VIDIOC_S_INPUT32 _IOWR('V', 39, s32)
732 #define VIDIOC_G_OUTPUT32 _IOR ('V', 46, s32)
733 #define VIDIOC_S_OUTPUT32 _IOWR('V', 47, s32)
735 static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
737 union {
738 #ifdef CONFIG_VIDEO_V4L1_COMPAT
739 struct video_tuner vt;
740 struct video_buffer vb;
741 struct video_window vw;
742 struct video_code vc;
743 struct video_audio va;
744 #endif
745 struct v4l2_format v2f;
746 struct v4l2_buffer v2b;
747 struct v4l2_framebuffer v2fb;
748 struct v4l2_input v2i;
749 struct v4l2_standard v2s;
750 struct v4l2_ext_controls v2ecs;
751 unsigned long vx;
752 int vi;
753 } karg;
754 void __user *up = compat_ptr(arg);
755 int compatible_arg = 1;
756 long err = 0;
758 /* First, convert the command. */
759 switch (cmd) {
760 #ifdef CONFIG_VIDEO_V4L1_COMPAT
761 case VIDIOCGTUNER32: cmd = VIDIOCGTUNER; break;
762 case VIDIOCSTUNER32: cmd = VIDIOCSTUNER; break;
763 case VIDIOCGWIN32: cmd = VIDIOCGWIN; break;
764 case VIDIOCSWIN32: cmd = VIDIOCSWIN; break;
765 case VIDIOCGFBUF32: cmd = VIDIOCGFBUF; break;
766 case VIDIOCSFBUF32: cmd = VIDIOCSFBUF; break;
767 case VIDIOCGFREQ32: cmd = VIDIOCGFREQ; break;
768 case VIDIOCSFREQ32: cmd = VIDIOCSFREQ; break;
769 case VIDIOCSMICROCODE32: cmd = VIDIOCSMICROCODE; break;
770 #endif
771 case VIDIOC_G_FMT32: cmd = VIDIOC_G_FMT; break;
772 case VIDIOC_S_FMT32: cmd = VIDIOC_S_FMT; break;
773 case VIDIOC_QUERYBUF32: cmd = VIDIOC_QUERYBUF; break;
774 case VIDIOC_G_FBUF32: cmd = VIDIOC_G_FBUF; break;
775 case VIDIOC_S_FBUF32: cmd = VIDIOC_S_FBUF; break;
776 case VIDIOC_QBUF32: cmd = VIDIOC_QBUF; break;
777 case VIDIOC_DQBUF32: cmd = VIDIOC_DQBUF; break;
778 case VIDIOC_ENUMSTD32: cmd = VIDIOC_ENUMSTD; break;
779 case VIDIOC_ENUMINPUT32: cmd = VIDIOC_ENUMINPUT; break;
780 case VIDIOC_TRY_FMT32: cmd = VIDIOC_TRY_FMT; break;
781 case VIDIOC_G_EXT_CTRLS32: cmd = VIDIOC_G_EXT_CTRLS; break;
782 case VIDIOC_S_EXT_CTRLS32: cmd = VIDIOC_S_EXT_CTRLS; break;
783 case VIDIOC_TRY_EXT_CTRLS32: cmd = VIDIOC_TRY_EXT_CTRLS; break;
784 case VIDIOC_OVERLAY32: cmd = VIDIOC_OVERLAY; break;
785 #ifdef __OLD_VIDIOC_
786 case VIDIOC_OVERLAY32_OLD: cmd = VIDIOC_OVERLAY; break;
787 #endif
788 case VIDIOC_STREAMON32: cmd = VIDIOC_STREAMON; break;
789 case VIDIOC_STREAMOFF32: cmd = VIDIOC_STREAMOFF; break;
790 case VIDIOC_G_INPUT32: cmd = VIDIOC_G_INPUT; break;
791 case VIDIOC_S_INPUT32: cmd = VIDIOC_S_INPUT; break;
792 case VIDIOC_G_OUTPUT32: cmd = VIDIOC_G_OUTPUT; break;
793 case VIDIOC_S_OUTPUT32: cmd = VIDIOC_S_OUTPUT; break;
796 switch (cmd) {
797 #ifdef CONFIG_VIDEO_V4L1_COMPAT
798 case VIDIOCSTUNER:
799 case VIDIOCGTUNER:
800 err = get_video_tuner32(&karg.vt, up);
801 compatible_arg = 0;
802 break;
804 case VIDIOCSFBUF:
805 err = get_video_buffer32(&karg.vb, up);
806 compatible_arg = 0;
807 break;
809 case VIDIOCSWIN:
810 err = get_video_window32(&karg.vw, up);
811 compatible_arg = 0;
812 break;
814 case VIDIOCGWIN:
815 case VIDIOCGFBUF:
816 case VIDIOCGFREQ:
817 compatible_arg = 0;
818 break;
820 case VIDIOCSMICROCODE:
821 err = get_microcode32(&karg.vc, up);
822 compatible_arg = 0;
823 break;
825 case VIDIOCSFREQ:
826 err = get_user(karg.vx, (u32 __user *)up);
827 compatible_arg = 0;
828 break;
830 case VIDIOCCAPTURE:
831 case VIDIOCSYNC:
832 case VIDIOCSWRITEMODE:
833 #endif
834 case VIDIOC_OVERLAY:
835 case VIDIOC_STREAMON:
836 case VIDIOC_STREAMOFF:
837 case VIDIOC_S_INPUT:
838 case VIDIOC_S_OUTPUT:
839 err = get_user(karg.vi, (s32 __user *)up);
840 compatible_arg = 0;
841 break;
843 case VIDIOC_G_INPUT:
844 case VIDIOC_G_OUTPUT:
845 compatible_arg = 0;
846 break;
848 case VIDIOC_G_FMT:
849 case VIDIOC_S_FMT:
850 case VIDIOC_TRY_FMT:
851 err = get_v4l2_format32(&karg.v2f, up);
852 compatible_arg = 0;
853 break;
855 case VIDIOC_QUERYBUF:
856 case VIDIOC_QBUF:
857 case VIDIOC_DQBUF:
858 err = get_v4l2_buffer32(&karg.v2b, up);
859 compatible_arg = 0;
860 break;
862 case VIDIOC_S_FBUF:
863 err = get_v4l2_framebuffer32(&karg.v2fb, up);
864 compatible_arg = 0;
865 break;
867 case VIDIOC_G_FBUF:
868 compatible_arg = 0;
869 break;
871 case VIDIOC_ENUMSTD:
872 err = get_v4l2_standard32(&karg.v2s, up);
873 compatible_arg = 0;
874 break;
876 case VIDIOC_ENUMINPUT:
877 err = get_v4l2_input32(&karg.v2i, up);
878 compatible_arg = 0;
879 break;
881 case VIDIOC_G_EXT_CTRLS:
882 case VIDIOC_S_EXT_CTRLS:
883 case VIDIOC_TRY_EXT_CTRLS:
884 err = get_v4l2_ext_controls32(&karg.v2ecs, up);
885 compatible_arg = 0;
886 break;
888 if (err)
889 return err;
891 if (compatible_arg)
892 err = native_ioctl(file, cmd, (unsigned long)up);
893 else {
894 mm_segment_t old_fs = get_fs();
896 set_fs(KERNEL_DS);
897 err = native_ioctl(file, cmd, (unsigned long)&karg);
898 set_fs(old_fs);
901 /* Special case: even after an error we need to put the
902 results back for these ioctls since the error_idx will
903 contain information on which control failed. */
904 switch (cmd) {
905 case VIDIOC_G_EXT_CTRLS:
906 case VIDIOC_S_EXT_CTRLS:
907 case VIDIOC_TRY_EXT_CTRLS:
908 if (put_v4l2_ext_controls32(&karg.v2ecs, up))
909 err = -EFAULT;
910 break;
912 if (err)
913 return err;
915 switch (cmd) {
916 #ifdef CONFIG_VIDEO_V4L1_COMPAT
917 case VIDIOCGTUNER:
918 err = put_video_tuner32(&karg.vt, up);
919 break;
921 case VIDIOCGWIN:
922 err = put_video_window32(&karg.vw, up);
923 break;
925 case VIDIOCGFBUF:
926 err = put_video_buffer32(&karg.vb, up);
927 break;
929 case VIDIOCGFREQ:
930 err = put_user(((u32)karg.vx), (u32 __user *)up);
931 break;
932 #endif
933 case VIDIOC_S_INPUT:
934 case VIDIOC_S_OUTPUT:
935 case VIDIOC_G_INPUT:
936 case VIDIOC_G_OUTPUT:
937 err = put_user(((s32)karg.vi), (s32 __user *)up);
938 break;
940 case VIDIOC_G_FBUF:
941 err = put_v4l2_framebuffer32(&karg.v2fb, up);
942 break;
944 case VIDIOC_G_FMT:
945 case VIDIOC_S_FMT:
946 case VIDIOC_TRY_FMT:
947 err = put_v4l2_format32(&karg.v2f, up);
948 break;
950 case VIDIOC_QUERYBUF:
951 case VIDIOC_QBUF:
952 case VIDIOC_DQBUF:
953 err = put_v4l2_buffer32(&karg.v2b, up);
954 break;
956 case VIDIOC_ENUMSTD:
957 err = put_v4l2_standard32(&karg.v2s, up);
958 break;
960 case VIDIOC_ENUMINPUT:
961 err = put_v4l2_input32(&karg.v2i, up);
962 break;
964 return err;
967 long v4l2_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)
969 long ret = -ENOIOCTLCMD;
971 if (!file->f_op->unlocked_ioctl)
972 return ret;
974 switch (cmd) {
975 #ifdef CONFIG_VIDEO_V4L1_COMPAT
976 case VIDIOCGCAP:
977 case VIDIOCGCHAN:
978 case VIDIOCSCHAN:
979 case VIDIOCGTUNER32:
980 case VIDIOCSTUNER32:
981 case VIDIOCGPICT:
982 case VIDIOCSPICT:
983 case VIDIOCCAPTURE32:
984 case VIDIOCGWIN32:
985 case VIDIOCSWIN32:
986 case VIDIOCGFBUF32:
987 case VIDIOCSFBUF32:
988 case VIDIOCKEY:
989 case VIDIOCGFREQ32:
990 case VIDIOCSFREQ32:
991 case VIDIOCGAUDIO:
992 case VIDIOCSAUDIO:
993 case VIDIOCSYNC32:
994 case VIDIOCMCAPTURE:
995 case VIDIOCGMBUF:
996 case VIDIOCGUNIT:
997 case VIDIOCGCAPTURE:
998 case VIDIOCSCAPTURE:
999 case VIDIOCSPLAYMODE:
1000 case VIDIOCSWRITEMODE32:
1001 case VIDIOCGPLAYINFO:
1002 case VIDIOCSMICROCODE32:
1003 case VIDIOCGVBIFMT:
1004 case VIDIOCSVBIFMT:
1005 #endif
1006 #ifdef __OLD_VIDIOC_
1007 case VIDIOC_OVERLAY32_OLD:
1008 case VIDIOC_S_PARM_OLD:
1009 case VIDIOC_S_CTRL_OLD:
1010 case VIDIOC_G_AUDIO_OLD:
1011 case VIDIOC_G_AUDOUT_OLD:
1012 case VIDIOC_CROPCAP_OLD:
1013 #endif
1014 case VIDIOC_QUERYCAP:
1015 case VIDIOC_RESERVED:
1016 case VIDIOC_ENUM_FMT:
1017 case VIDIOC_G_FMT32:
1018 case VIDIOC_S_FMT32:
1019 case VIDIOC_REQBUFS:
1020 case VIDIOC_QUERYBUF32:
1021 case VIDIOC_G_FBUF32:
1022 case VIDIOC_S_FBUF32:
1023 case VIDIOC_OVERLAY32:
1024 case VIDIOC_QBUF32:
1025 case VIDIOC_DQBUF32:
1026 case VIDIOC_STREAMON32:
1027 case VIDIOC_STREAMOFF32:
1028 case VIDIOC_G_PARM:
1029 case VIDIOC_S_PARM:
1030 case VIDIOC_G_STD:
1031 case VIDIOC_S_STD:
1032 case VIDIOC_ENUMSTD32:
1033 case VIDIOC_ENUMINPUT32:
1034 case VIDIOC_G_CTRL:
1035 case VIDIOC_S_CTRL:
1036 case VIDIOC_G_TUNER:
1037 case VIDIOC_S_TUNER:
1038 case VIDIOC_G_AUDIO:
1039 case VIDIOC_S_AUDIO:
1040 case VIDIOC_QUERYCTRL:
1041 case VIDIOC_QUERYMENU:
1042 case VIDIOC_G_INPUT32:
1043 case VIDIOC_S_INPUT32:
1044 case VIDIOC_G_OUTPUT32:
1045 case VIDIOC_S_OUTPUT32:
1046 case VIDIOC_ENUMOUTPUT:
1047 case VIDIOC_G_AUDOUT:
1048 case VIDIOC_S_AUDOUT:
1049 case VIDIOC_G_MODULATOR:
1050 case VIDIOC_S_MODULATOR:
1051 case VIDIOC_S_FREQUENCY:
1052 case VIDIOC_G_FREQUENCY:
1053 case VIDIOC_CROPCAP:
1054 case VIDIOC_G_CROP:
1055 case VIDIOC_S_CROP:
1056 case VIDIOC_G_JPEGCOMP:
1057 case VIDIOC_S_JPEGCOMP:
1058 case VIDIOC_QUERYSTD:
1059 case VIDIOC_TRY_FMT32:
1060 case VIDIOC_ENUMAUDIO:
1061 case VIDIOC_ENUMAUDOUT:
1062 case VIDIOC_G_PRIORITY:
1063 case VIDIOC_S_PRIORITY:
1064 case VIDIOC_G_SLICED_VBI_CAP:
1065 case VIDIOC_LOG_STATUS:
1066 case VIDIOC_G_EXT_CTRLS32:
1067 case VIDIOC_S_EXT_CTRLS32:
1068 case VIDIOC_TRY_EXT_CTRLS32:
1069 case VIDIOC_ENUM_FRAMESIZES:
1070 case VIDIOC_ENUM_FRAMEINTERVALS:
1071 case VIDIOC_G_ENC_INDEX:
1072 case VIDIOC_ENCODER_CMD:
1073 case VIDIOC_TRY_ENCODER_CMD:
1074 case VIDIOC_DBG_S_REGISTER:
1075 case VIDIOC_DBG_G_REGISTER:
1076 case VIDIOC_DBG_G_CHIP_IDENT:
1077 case VIDIOC_S_HW_FREQ_SEEK:
1078 case VIDIOC_ENUM_DV_PRESETS:
1079 case VIDIOC_S_DV_PRESET:
1080 case VIDIOC_G_DV_PRESET:
1081 case VIDIOC_QUERY_DV_PRESET:
1082 case VIDIOC_S_DV_TIMINGS:
1083 case VIDIOC_G_DV_TIMINGS:
1084 case VIDIOC_DQEVENT:
1085 case VIDIOC_SUBSCRIBE_EVENT:
1086 case VIDIOC_UNSUBSCRIBE_EVENT:
1087 ret = do_video_ioctl(file, cmd, arg);
1088 break;
1090 #ifdef CONFIG_VIDEO_V4L1_COMPAT
1091 /* BTTV specific... */
1092 case _IOW('v', BASE_VIDIOCPRIVATE+0, char [256]):
1093 case _IOR('v', BASE_VIDIOCPRIVATE+1, char [256]):
1094 case _IOR('v' , BASE_VIDIOCPRIVATE+2, unsigned int):
1095 case _IOW('v' , BASE_VIDIOCPRIVATE+3, char [16]): /* struct bttv_pll_info */
1096 case _IOR('v' , BASE_VIDIOCPRIVATE+4, int):
1097 case _IOR('v' , BASE_VIDIOCPRIVATE+5, int):
1098 case _IOR('v' , BASE_VIDIOCPRIVATE+6, int):
1099 case _IOR('v' , BASE_VIDIOCPRIVATE+7, int):
1100 ret = native_ioctl(file, cmd, (unsigned long)compat_ptr(arg));
1101 break;
1102 #endif
1103 default:
1104 printk(KERN_WARNING "compat_ioctl32: "
1105 "unknown ioctl '%c', dir=%d, #%d (0x%08x)\n",
1106 _IOC_TYPE(cmd), _IOC_DIR(cmd), _IOC_NR(cmd), cmd);
1107 break;
1109 return ret;
1111 EXPORT_SYMBOL_GPL(v4l2_compat_ioctl32);
1112 #endif
1114 MODULE_LICENSE("GPL");