Merge branch 'v6v7' into devel
[linux/fpc-iii.git] / drivers / media / video / v4l2-compat-ioctl32.c
blobdc82eb83c1d4de590a33eb9b9c90ee61a9069e21
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/videodev2.h>
19 #include <linux/module.h>
20 #include <media/v4l2-ioctl.h>
22 #ifdef CONFIG_COMPAT
24 static long native_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
26 long ret = -ENOIOCTLCMD;
28 if (file->f_op->unlocked_ioctl)
29 ret = file->f_op->unlocked_ioctl(file, cmd, arg);
31 return ret;
35 struct v4l2_clip32 {
36 struct v4l2_rect c;
37 compat_caddr_t next;
40 struct v4l2_window32 {
41 struct v4l2_rect w;
42 enum v4l2_field field;
43 __u32 chromakey;
44 compat_caddr_t clips; /* actually struct v4l2_clip32 * */
45 __u32 clipcount;
46 compat_caddr_t bitmap;
49 static int get_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 __user *up)
51 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_window32)) ||
52 copy_from_user(&kp->w, &up->w, sizeof(up->w)) ||
53 get_user(kp->field, &up->field) ||
54 get_user(kp->chromakey, &up->chromakey) ||
55 get_user(kp->clipcount, &up->clipcount))
56 return -EFAULT;
57 if (kp->clipcount > 2048)
58 return -EINVAL;
59 if (kp->clipcount) {
60 struct v4l2_clip32 __user *uclips;
61 struct v4l2_clip __user *kclips;
62 int n = kp->clipcount;
63 compat_caddr_t p;
65 if (get_user(p, &up->clips))
66 return -EFAULT;
67 uclips = compat_ptr(p);
68 kclips = compat_alloc_user_space(n * sizeof(struct v4l2_clip));
69 kp->clips = kclips;
70 while (--n >= 0) {
71 if (copy_in_user(&kclips->c, &uclips->c, sizeof(uclips->c)))
72 return -EFAULT;
73 if (put_user(n ? kclips + 1 : NULL, &kclips->next))
74 return -EFAULT;
75 uclips += 1;
76 kclips += 1;
78 } else
79 kp->clips = NULL;
80 return 0;
83 static int put_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 __user *up)
85 if (copy_to_user(&up->w, &kp->w, sizeof(kp->w)) ||
86 put_user(kp->field, &up->field) ||
87 put_user(kp->chromakey, &up->chromakey) ||
88 put_user(kp->clipcount, &up->clipcount))
89 return -EFAULT;
90 return 0;
93 static inline int get_v4l2_pix_format(struct v4l2_pix_format *kp, struct v4l2_pix_format __user *up)
95 if (copy_from_user(kp, up, sizeof(struct v4l2_pix_format)))
96 return -EFAULT;
97 return 0;
100 static inline int put_v4l2_pix_format(struct v4l2_pix_format *kp, struct v4l2_pix_format __user *up)
102 if (copy_to_user(up, kp, sizeof(struct v4l2_pix_format)))
103 return -EFAULT;
104 return 0;
107 static inline int get_v4l2_vbi_format(struct v4l2_vbi_format *kp, struct v4l2_vbi_format __user *up)
109 if (copy_from_user(kp, up, sizeof(struct v4l2_vbi_format)))
110 return -EFAULT;
111 return 0;
114 static inline int put_v4l2_vbi_format(struct v4l2_vbi_format *kp, struct v4l2_vbi_format __user *up)
116 if (copy_to_user(up, kp, sizeof(struct v4l2_vbi_format)))
117 return -EFAULT;
118 return 0;
121 static inline int get_v4l2_sliced_vbi_format(struct v4l2_sliced_vbi_format *kp, struct v4l2_sliced_vbi_format __user *up)
123 if (copy_from_user(kp, up, sizeof(struct v4l2_sliced_vbi_format)))
124 return -EFAULT;
125 return 0;
128 static inline int put_v4l2_sliced_vbi_format(struct v4l2_sliced_vbi_format *kp, struct v4l2_sliced_vbi_format __user *up)
130 if (copy_to_user(up, kp, sizeof(struct v4l2_sliced_vbi_format)))
131 return -EFAULT;
132 return 0;
135 struct v4l2_format32 {
136 enum v4l2_buf_type type;
137 union {
138 struct v4l2_pix_format pix;
139 struct v4l2_window32 win;
140 struct v4l2_vbi_format vbi;
141 struct v4l2_sliced_vbi_format sliced;
142 __u8 raw_data[200]; /* user-defined */
143 } fmt;
146 static int get_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up)
148 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_format32)) ||
149 get_user(kp->type, &up->type))
150 return -EFAULT;
151 switch (kp->type) {
152 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
153 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
154 return get_v4l2_pix_format(&kp->fmt.pix, &up->fmt.pix);
155 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
156 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
157 return get_v4l2_window32(&kp->fmt.win, &up->fmt.win);
158 case V4L2_BUF_TYPE_VBI_CAPTURE:
159 case V4L2_BUF_TYPE_VBI_OUTPUT:
160 return get_v4l2_vbi_format(&kp->fmt.vbi, &up->fmt.vbi);
161 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
162 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
163 return get_v4l2_sliced_vbi_format(&kp->fmt.sliced, &up->fmt.sliced);
164 case V4L2_BUF_TYPE_PRIVATE:
165 if (copy_from_user(kp, up, sizeof(kp->fmt.raw_data)))
166 return -EFAULT;
167 return 0;
168 default:
169 printk(KERN_INFO "compat_ioctl32: unexpected VIDIOC_FMT type %d\n",
170 kp->type);
171 return -EINVAL;
175 static int put_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up)
177 if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_format32)) ||
178 put_user(kp->type, &up->type))
179 return -EFAULT;
180 switch (kp->type) {
181 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
182 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
183 return put_v4l2_pix_format(&kp->fmt.pix, &up->fmt.pix);
184 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
185 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
186 return put_v4l2_window32(&kp->fmt.win, &up->fmt.win);
187 case V4L2_BUF_TYPE_VBI_CAPTURE:
188 case V4L2_BUF_TYPE_VBI_OUTPUT:
189 return put_v4l2_vbi_format(&kp->fmt.vbi, &up->fmt.vbi);
190 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
191 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
192 return put_v4l2_sliced_vbi_format(&kp->fmt.sliced, &up->fmt.sliced);
193 case V4L2_BUF_TYPE_PRIVATE:
194 if (copy_to_user(up, kp, sizeof(up->fmt.raw_data)))
195 return -EFAULT;
196 return 0;
197 default:
198 printk(KERN_INFO "compat_ioctl32: unexpected VIDIOC_FMT type %d\n",
199 kp->type);
200 return -EINVAL;
204 struct v4l2_standard32 {
205 __u32 index;
206 __u32 id[2]; /* __u64 would get the alignment wrong */
207 __u8 name[24];
208 struct v4l2_fract frameperiod; /* Frames, not fields */
209 __u32 framelines;
210 __u32 reserved[4];
213 static int get_v4l2_standard32(struct v4l2_standard *kp, struct v4l2_standard32 __user *up)
215 /* other fields are not set by the user, nor used by the driver */
216 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_standard32)) ||
217 get_user(kp->index, &up->index))
218 return -EFAULT;
219 return 0;
222 static int put_v4l2_standard32(struct v4l2_standard *kp, struct v4l2_standard32 __user *up)
224 if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_standard32)) ||
225 put_user(kp->index, &up->index) ||
226 copy_to_user(up->id, &kp->id, sizeof(__u64)) ||
227 copy_to_user(up->name, kp->name, 24) ||
228 copy_to_user(&up->frameperiod, &kp->frameperiod, sizeof(kp->frameperiod)) ||
229 put_user(kp->framelines, &up->framelines) ||
230 copy_to_user(up->reserved, kp->reserved, 4 * sizeof(__u32)))
231 return -EFAULT;
232 return 0;
235 struct v4l2_buffer32 {
236 __u32 index;
237 enum v4l2_buf_type type;
238 __u32 bytesused;
239 __u32 flags;
240 enum v4l2_field field;
241 struct compat_timeval timestamp;
242 struct v4l2_timecode timecode;
243 __u32 sequence;
245 /* memory location */
246 enum v4l2_memory memory;
247 union {
248 __u32 offset;
249 compat_long_t userptr;
250 } m;
251 __u32 length;
252 __u32 input;
253 __u32 reserved;
256 static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user *up)
259 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_buffer32)) ||
260 get_user(kp->index, &up->index) ||
261 get_user(kp->type, &up->type) ||
262 get_user(kp->flags, &up->flags) ||
263 get_user(kp->memory, &up->memory) ||
264 get_user(kp->input, &up->input))
265 return -EFAULT;
266 switch (kp->memory) {
267 case V4L2_MEMORY_MMAP:
268 if (get_user(kp->length, &up->length) ||
269 get_user(kp->m.offset, &up->m.offset))
270 return -EFAULT;
271 break;
272 case V4L2_MEMORY_USERPTR:
274 compat_long_t tmp;
276 if (get_user(kp->length, &up->length) ||
277 get_user(tmp, &up->m.userptr))
278 return -EFAULT;
280 kp->m.userptr = (unsigned long)compat_ptr(tmp);
282 break;
283 case V4L2_MEMORY_OVERLAY:
284 if (get_user(kp->m.offset, &up->m.offset))
285 return -EFAULT;
286 break;
288 return 0;
291 static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user *up)
293 if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_buffer32)) ||
294 put_user(kp->index, &up->index) ||
295 put_user(kp->type, &up->type) ||
296 put_user(kp->flags, &up->flags) ||
297 put_user(kp->memory, &up->memory) ||
298 put_user(kp->input, &up->input))
299 return -EFAULT;
300 switch (kp->memory) {
301 case V4L2_MEMORY_MMAP:
302 if (put_user(kp->length, &up->length) ||
303 put_user(kp->m.offset, &up->m.offset))
304 return -EFAULT;
305 break;
306 case V4L2_MEMORY_USERPTR:
307 if (put_user(kp->length, &up->length) ||
308 put_user(kp->m.userptr, &up->m.userptr))
309 return -EFAULT;
310 break;
311 case V4L2_MEMORY_OVERLAY:
312 if (put_user(kp->m.offset, &up->m.offset))
313 return -EFAULT;
314 break;
316 if (put_user(kp->bytesused, &up->bytesused) ||
317 put_user(kp->field, &up->field) ||
318 put_user(kp->timestamp.tv_sec, &up->timestamp.tv_sec) ||
319 put_user(kp->timestamp.tv_usec, &up->timestamp.tv_usec) ||
320 copy_to_user(&up->timecode, &kp->timecode, sizeof(struct v4l2_timecode)) ||
321 put_user(kp->sequence, &up->sequence) ||
322 put_user(kp->reserved, &up->reserved))
323 return -EFAULT;
324 return 0;
327 struct v4l2_framebuffer32 {
328 __u32 capability;
329 __u32 flags;
330 compat_caddr_t base;
331 struct v4l2_pix_format fmt;
334 static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_framebuffer32 __user *up)
336 u32 tmp;
338 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_framebuffer32)) ||
339 get_user(tmp, &up->base) ||
340 get_user(kp->capability, &up->capability) ||
341 get_user(kp->flags, &up->flags))
342 return -EFAULT;
343 kp->base = compat_ptr(tmp);
344 get_v4l2_pix_format(&kp->fmt, &up->fmt);
345 return 0;
348 static int put_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_framebuffer32 __user *up)
350 u32 tmp = (u32)((unsigned long)kp->base);
352 if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_framebuffer32)) ||
353 put_user(tmp, &up->base) ||
354 put_user(kp->capability, &up->capability) ||
355 put_user(kp->flags, &up->flags))
356 return -EFAULT;
357 put_v4l2_pix_format(&kp->fmt, &up->fmt);
358 return 0;
361 struct v4l2_input32 {
362 __u32 index; /* Which input */
363 __u8 name[32]; /* Label */
364 __u32 type; /* Type of input */
365 __u32 audioset; /* Associated audios (bitfield) */
366 __u32 tuner; /* Associated tuner */
367 v4l2_std_id std;
368 __u32 status;
369 __u32 reserved[4];
370 } __attribute__ ((packed));
372 /* The 64-bit v4l2_input struct has extra padding at the end of the struct.
373 Otherwise it is identical to the 32-bit version. */
374 static inline int get_v4l2_input32(struct v4l2_input *kp, struct v4l2_input32 __user *up)
376 if (copy_from_user(kp, up, sizeof(struct v4l2_input32)))
377 return -EFAULT;
378 return 0;
381 static inline int put_v4l2_input32(struct v4l2_input *kp, struct v4l2_input32 __user *up)
383 if (copy_to_user(up, kp, sizeof(struct v4l2_input32)))
384 return -EFAULT;
385 return 0;
388 struct v4l2_ext_controls32 {
389 __u32 ctrl_class;
390 __u32 count;
391 __u32 error_idx;
392 __u32 reserved[2];
393 compat_caddr_t controls; /* actually struct v4l2_ext_control32 * */
396 struct v4l2_ext_control32 {
397 __u32 id;
398 __u32 size;
399 __u32 reserved2[1];
400 union {
401 __s32 value;
402 __s64 value64;
403 compat_caddr_t string; /* actually char * */
405 } __attribute__ ((packed));
407 /* The following function really belong in v4l2-common, but that causes
408 a circular dependency between modules. We need to think about this, but
409 for now this will do. */
411 /* Return non-zero if this control is a pointer type. Currently only
412 type STRING is a pointer type. */
413 static inline int ctrl_is_pointer(u32 id)
415 switch (id) {
416 case V4L2_CID_RDS_TX_PS_NAME:
417 case V4L2_CID_RDS_TX_RADIO_TEXT:
418 return 1;
419 default:
420 return 0;
424 static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
426 struct v4l2_ext_control32 __user *ucontrols;
427 struct v4l2_ext_control __user *kcontrols;
428 int n;
429 compat_caddr_t p;
431 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_ext_controls32)) ||
432 get_user(kp->ctrl_class, &up->ctrl_class) ||
433 get_user(kp->count, &up->count) ||
434 get_user(kp->error_idx, &up->error_idx) ||
435 copy_from_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
436 return -EFAULT;
437 n = kp->count;
438 if (n == 0) {
439 kp->controls = NULL;
440 return 0;
442 if (get_user(p, &up->controls))
443 return -EFAULT;
444 ucontrols = compat_ptr(p);
445 if (!access_ok(VERIFY_READ, ucontrols, n * sizeof(struct v4l2_ext_control)))
446 return -EFAULT;
447 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
448 kp->controls = kcontrols;
449 while (--n >= 0) {
450 if (copy_in_user(kcontrols, ucontrols, sizeof(*kcontrols)))
451 return -EFAULT;
452 if (ctrl_is_pointer(kcontrols->id)) {
453 void __user *s;
455 if (get_user(p, &ucontrols->string))
456 return -EFAULT;
457 s = compat_ptr(p);
458 if (put_user(s, &kcontrols->string))
459 return -EFAULT;
461 ucontrols++;
462 kcontrols++;
464 return 0;
467 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
469 struct v4l2_ext_control32 __user *ucontrols;
470 struct v4l2_ext_control __user *kcontrols = kp->controls;
471 int n = kp->count;
472 compat_caddr_t p;
474 if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_ext_controls32)) ||
475 put_user(kp->ctrl_class, &up->ctrl_class) ||
476 put_user(kp->count, &up->count) ||
477 put_user(kp->error_idx, &up->error_idx) ||
478 copy_to_user(up->reserved, kp->reserved, sizeof(up->reserved)))
479 return -EFAULT;
480 if (!kp->count)
481 return 0;
483 if (get_user(p, &up->controls))
484 return -EFAULT;
485 ucontrols = compat_ptr(p);
486 if (!access_ok(VERIFY_WRITE, ucontrols, n * sizeof(struct v4l2_ext_control)))
487 return -EFAULT;
489 while (--n >= 0) {
490 unsigned size = sizeof(*ucontrols);
492 /* Do not modify the pointer when copying a pointer control.
493 The contents of the pointer was changed, not the pointer
494 itself. */
495 if (ctrl_is_pointer(kcontrols->id))
496 size -= sizeof(ucontrols->value64);
497 if (copy_in_user(ucontrols, kcontrols, size))
498 return -EFAULT;
499 ucontrols++;
500 kcontrols++;
502 return 0;
505 #define VIDIOC_G_FMT32 _IOWR('V', 4, struct v4l2_format32)
506 #define VIDIOC_S_FMT32 _IOWR('V', 5, struct v4l2_format32)
507 #define VIDIOC_QUERYBUF32 _IOWR('V', 9, struct v4l2_buffer32)
508 #define VIDIOC_G_FBUF32 _IOR ('V', 10, struct v4l2_framebuffer32)
509 #define VIDIOC_S_FBUF32 _IOW ('V', 11, struct v4l2_framebuffer32)
510 #define VIDIOC_QBUF32 _IOWR('V', 15, struct v4l2_buffer32)
511 #define VIDIOC_DQBUF32 _IOWR('V', 17, struct v4l2_buffer32)
512 #define VIDIOC_ENUMSTD32 _IOWR('V', 25, struct v4l2_standard32)
513 #define VIDIOC_ENUMINPUT32 _IOWR('V', 26, struct v4l2_input32)
514 #define VIDIOC_TRY_FMT32 _IOWR('V', 64, struct v4l2_format32)
515 #define VIDIOC_G_EXT_CTRLS32 _IOWR('V', 71, struct v4l2_ext_controls32)
516 #define VIDIOC_S_EXT_CTRLS32 _IOWR('V', 72, struct v4l2_ext_controls32)
517 #define VIDIOC_TRY_EXT_CTRLS32 _IOWR('V', 73, struct v4l2_ext_controls32)
519 #define VIDIOC_OVERLAY32 _IOW ('V', 14, s32)
520 #ifdef __OLD_VIDIOC_
521 #define VIDIOC_OVERLAY32_OLD _IOWR('V', 14, s32)
522 #endif
523 #define VIDIOC_STREAMON32 _IOW ('V', 18, s32)
524 #define VIDIOC_STREAMOFF32 _IOW ('V', 19, s32)
525 #define VIDIOC_G_INPUT32 _IOR ('V', 38, s32)
526 #define VIDIOC_S_INPUT32 _IOWR('V', 39, s32)
527 #define VIDIOC_G_OUTPUT32 _IOR ('V', 46, s32)
528 #define VIDIOC_S_OUTPUT32 _IOWR('V', 47, s32)
530 static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
532 union {
533 struct v4l2_format v2f;
534 struct v4l2_buffer v2b;
535 struct v4l2_framebuffer v2fb;
536 struct v4l2_input v2i;
537 struct v4l2_standard v2s;
538 struct v4l2_ext_controls v2ecs;
539 unsigned long vx;
540 int vi;
541 } karg;
542 void __user *up = compat_ptr(arg);
543 int compatible_arg = 1;
544 long err = 0;
546 /* First, convert the command. */
547 switch (cmd) {
548 case VIDIOC_G_FMT32: cmd = VIDIOC_G_FMT; break;
549 case VIDIOC_S_FMT32: cmd = VIDIOC_S_FMT; break;
550 case VIDIOC_QUERYBUF32: cmd = VIDIOC_QUERYBUF; break;
551 case VIDIOC_G_FBUF32: cmd = VIDIOC_G_FBUF; break;
552 case VIDIOC_S_FBUF32: cmd = VIDIOC_S_FBUF; break;
553 case VIDIOC_QBUF32: cmd = VIDIOC_QBUF; break;
554 case VIDIOC_DQBUF32: cmd = VIDIOC_DQBUF; break;
555 case VIDIOC_ENUMSTD32: cmd = VIDIOC_ENUMSTD; break;
556 case VIDIOC_ENUMINPUT32: cmd = VIDIOC_ENUMINPUT; break;
557 case VIDIOC_TRY_FMT32: cmd = VIDIOC_TRY_FMT; break;
558 case VIDIOC_G_EXT_CTRLS32: cmd = VIDIOC_G_EXT_CTRLS; break;
559 case VIDIOC_S_EXT_CTRLS32: cmd = VIDIOC_S_EXT_CTRLS; break;
560 case VIDIOC_TRY_EXT_CTRLS32: cmd = VIDIOC_TRY_EXT_CTRLS; break;
561 case VIDIOC_OVERLAY32: cmd = VIDIOC_OVERLAY; break;
562 #ifdef __OLD_VIDIOC_
563 case VIDIOC_OVERLAY32_OLD: cmd = VIDIOC_OVERLAY; break;
564 #endif
565 case VIDIOC_STREAMON32: cmd = VIDIOC_STREAMON; break;
566 case VIDIOC_STREAMOFF32: cmd = VIDIOC_STREAMOFF; break;
567 case VIDIOC_G_INPUT32: cmd = VIDIOC_G_INPUT; break;
568 case VIDIOC_S_INPUT32: cmd = VIDIOC_S_INPUT; break;
569 case VIDIOC_G_OUTPUT32: cmd = VIDIOC_G_OUTPUT; break;
570 case VIDIOC_S_OUTPUT32: cmd = VIDIOC_S_OUTPUT; break;
573 switch (cmd) {
574 case VIDIOC_OVERLAY:
575 case VIDIOC_STREAMON:
576 case VIDIOC_STREAMOFF:
577 case VIDIOC_S_INPUT:
578 case VIDIOC_S_OUTPUT:
579 err = get_user(karg.vi, (s32 __user *)up);
580 compatible_arg = 0;
581 break;
583 case VIDIOC_G_INPUT:
584 case VIDIOC_G_OUTPUT:
585 compatible_arg = 0;
586 break;
588 case VIDIOC_G_FMT:
589 case VIDIOC_S_FMT:
590 case VIDIOC_TRY_FMT:
591 err = get_v4l2_format32(&karg.v2f, up);
592 compatible_arg = 0;
593 break;
595 case VIDIOC_QUERYBUF:
596 case VIDIOC_QBUF:
597 case VIDIOC_DQBUF:
598 err = get_v4l2_buffer32(&karg.v2b, up);
599 compatible_arg = 0;
600 break;
602 case VIDIOC_S_FBUF:
603 err = get_v4l2_framebuffer32(&karg.v2fb, up);
604 compatible_arg = 0;
605 break;
607 case VIDIOC_G_FBUF:
608 compatible_arg = 0;
609 break;
611 case VIDIOC_ENUMSTD:
612 err = get_v4l2_standard32(&karg.v2s, up);
613 compatible_arg = 0;
614 break;
616 case VIDIOC_ENUMINPUT:
617 err = get_v4l2_input32(&karg.v2i, up);
618 compatible_arg = 0;
619 break;
621 case VIDIOC_G_EXT_CTRLS:
622 case VIDIOC_S_EXT_CTRLS:
623 case VIDIOC_TRY_EXT_CTRLS:
624 err = get_v4l2_ext_controls32(&karg.v2ecs, up);
625 compatible_arg = 0;
626 break;
628 if (err)
629 return err;
631 if (compatible_arg)
632 err = native_ioctl(file, cmd, (unsigned long)up);
633 else {
634 mm_segment_t old_fs = get_fs();
636 set_fs(KERNEL_DS);
637 err = native_ioctl(file, cmd, (unsigned long)&karg);
638 set_fs(old_fs);
641 /* Special case: even after an error we need to put the
642 results back for these ioctls since the error_idx will
643 contain information on which control failed. */
644 switch (cmd) {
645 case VIDIOC_G_EXT_CTRLS:
646 case VIDIOC_S_EXT_CTRLS:
647 case VIDIOC_TRY_EXT_CTRLS:
648 if (put_v4l2_ext_controls32(&karg.v2ecs, up))
649 err = -EFAULT;
650 break;
652 if (err)
653 return err;
655 switch (cmd) {
656 case VIDIOC_S_INPUT:
657 case VIDIOC_S_OUTPUT:
658 case VIDIOC_G_INPUT:
659 case VIDIOC_G_OUTPUT:
660 err = put_user(((s32)karg.vi), (s32 __user *)up);
661 break;
663 case VIDIOC_G_FBUF:
664 err = put_v4l2_framebuffer32(&karg.v2fb, up);
665 break;
667 case VIDIOC_G_FMT:
668 case VIDIOC_S_FMT:
669 case VIDIOC_TRY_FMT:
670 err = put_v4l2_format32(&karg.v2f, up);
671 break;
673 case VIDIOC_QUERYBUF:
674 case VIDIOC_QBUF:
675 case VIDIOC_DQBUF:
676 err = put_v4l2_buffer32(&karg.v2b, up);
677 break;
679 case VIDIOC_ENUMSTD:
680 err = put_v4l2_standard32(&karg.v2s, up);
681 break;
683 case VIDIOC_ENUMINPUT:
684 err = put_v4l2_input32(&karg.v2i, up);
685 break;
687 return err;
690 long v4l2_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)
692 long ret = -ENOIOCTLCMD;
694 if (!file->f_op->unlocked_ioctl)
695 return ret;
697 switch (cmd) {
698 #ifdef __OLD_VIDIOC_
699 case VIDIOC_OVERLAY32_OLD:
700 case VIDIOC_S_PARM_OLD:
701 case VIDIOC_S_CTRL_OLD:
702 case VIDIOC_G_AUDIO_OLD:
703 case VIDIOC_G_AUDOUT_OLD:
704 case VIDIOC_CROPCAP_OLD:
705 #endif
706 case VIDIOC_QUERYCAP:
707 case VIDIOC_RESERVED:
708 case VIDIOC_ENUM_FMT:
709 case VIDIOC_G_FMT32:
710 case VIDIOC_S_FMT32:
711 case VIDIOC_REQBUFS:
712 case VIDIOC_QUERYBUF32:
713 case VIDIOC_G_FBUF32:
714 case VIDIOC_S_FBUF32:
715 case VIDIOC_OVERLAY32:
716 case VIDIOC_QBUF32:
717 case VIDIOC_DQBUF32:
718 case VIDIOC_STREAMON32:
719 case VIDIOC_STREAMOFF32:
720 case VIDIOC_G_PARM:
721 case VIDIOC_S_PARM:
722 case VIDIOC_G_STD:
723 case VIDIOC_S_STD:
724 case VIDIOC_ENUMSTD32:
725 case VIDIOC_ENUMINPUT32:
726 case VIDIOC_G_CTRL:
727 case VIDIOC_S_CTRL:
728 case VIDIOC_G_TUNER:
729 case VIDIOC_S_TUNER:
730 case VIDIOC_G_AUDIO:
731 case VIDIOC_S_AUDIO:
732 case VIDIOC_QUERYCTRL:
733 case VIDIOC_QUERYMENU:
734 case VIDIOC_G_INPUT32:
735 case VIDIOC_S_INPUT32:
736 case VIDIOC_G_OUTPUT32:
737 case VIDIOC_S_OUTPUT32:
738 case VIDIOC_ENUMOUTPUT:
739 case VIDIOC_G_AUDOUT:
740 case VIDIOC_S_AUDOUT:
741 case VIDIOC_G_MODULATOR:
742 case VIDIOC_S_MODULATOR:
743 case VIDIOC_S_FREQUENCY:
744 case VIDIOC_G_FREQUENCY:
745 case VIDIOC_CROPCAP:
746 case VIDIOC_G_CROP:
747 case VIDIOC_S_CROP:
748 case VIDIOC_G_JPEGCOMP:
749 case VIDIOC_S_JPEGCOMP:
750 case VIDIOC_QUERYSTD:
751 case VIDIOC_TRY_FMT32:
752 case VIDIOC_ENUMAUDIO:
753 case VIDIOC_ENUMAUDOUT:
754 case VIDIOC_G_PRIORITY:
755 case VIDIOC_S_PRIORITY:
756 case VIDIOC_G_SLICED_VBI_CAP:
757 case VIDIOC_LOG_STATUS:
758 case VIDIOC_G_EXT_CTRLS32:
759 case VIDIOC_S_EXT_CTRLS32:
760 case VIDIOC_TRY_EXT_CTRLS32:
761 case VIDIOC_ENUM_FRAMESIZES:
762 case VIDIOC_ENUM_FRAMEINTERVALS:
763 case VIDIOC_G_ENC_INDEX:
764 case VIDIOC_ENCODER_CMD:
765 case VIDIOC_TRY_ENCODER_CMD:
766 case VIDIOC_DBG_S_REGISTER:
767 case VIDIOC_DBG_G_REGISTER:
768 case VIDIOC_DBG_G_CHIP_IDENT:
769 case VIDIOC_S_HW_FREQ_SEEK:
770 case VIDIOC_ENUM_DV_PRESETS:
771 case VIDIOC_S_DV_PRESET:
772 case VIDIOC_G_DV_PRESET:
773 case VIDIOC_QUERY_DV_PRESET:
774 case VIDIOC_S_DV_TIMINGS:
775 case VIDIOC_G_DV_TIMINGS:
776 case VIDIOC_DQEVENT:
777 case VIDIOC_SUBSCRIBE_EVENT:
778 case VIDIOC_UNSUBSCRIBE_EVENT:
779 ret = do_video_ioctl(file, cmd, arg);
780 break;
782 default:
783 printk(KERN_WARNING "compat_ioctl32: "
784 "unknown ioctl '%c', dir=%d, #%d (0x%08x)\n",
785 _IOC_TYPE(cmd), _IOC_DIR(cmd), _IOC_NR(cmd), cmd);
786 break;
788 return ret;
790 EXPORT_SYMBOL_GPL(v4l2_compat_ioctl32);
791 #endif
793 MODULE_LICENSE("GPL");