Linux 2.6.17.7
[linux/fpc-iii.git] / drivers / media / video / compat_ioctl32.c
blob840fe0177121190275008fbda829019258236972
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@suse.cz)
9 * Copyright (C) 2005 Philippe De Muyter (phdm@macqel.be)
11 * These routines maintain argument size conversion between 32bit and 64bit
12 * ioctls.
15 #include <linux/config.h>
16 #include <linux/compat.h>
17 #include <linux/videodev.h>
18 #include <linux/videodev2.h>
19 #include <linux/module.h>
20 #include <linux/smp_lock.h>
21 #include <media/v4l2-common.h>
23 #ifdef CONFIG_COMPAT
26 struct video_tuner32 {
27 compat_int_t tuner;
28 char name[32];
29 compat_ulong_t rangelow, rangehigh;
30 u32 flags; /* It is really u32 in videodev.h */
31 u16 mode, signal;
34 static int get_video_tuner32(struct video_tuner *kp, struct video_tuner32 __user *up)
36 if(!access_ok(VERIFY_READ, up, sizeof(struct video_tuner32)) ||
37 get_user(kp->tuner, &up->tuner) ||
38 copy_from_user(kp->name, up->name, 32) ||
39 get_user(kp->rangelow, &up->rangelow) ||
40 get_user(kp->rangehigh, &up->rangehigh) ||
41 get_user(kp->flags, &up->flags) ||
42 get_user(kp->mode, &up->mode) ||
43 get_user(kp->signal, &up->signal))
44 return -EFAULT;
45 return 0;
48 static int put_video_tuner32(struct video_tuner *kp, struct video_tuner32 __user *up)
50 if(!access_ok(VERIFY_WRITE, up, sizeof(struct video_tuner32)) ||
51 put_user(kp->tuner, &up->tuner) ||
52 copy_to_user(up->name, kp->name, 32) ||
53 put_user(kp->rangelow, &up->rangelow) ||
54 put_user(kp->rangehigh, &up->rangehigh) ||
55 put_user(kp->flags, &up->flags) ||
56 put_user(kp->mode, &up->mode) ||
57 put_user(kp->signal, &up->signal))
58 return -EFAULT;
59 return 0;
62 struct video_buffer32 {
63 compat_caddr_t base;
64 compat_int_t height, width, depth, bytesperline;
67 static int get_video_buffer32(struct video_buffer *kp, struct video_buffer32 __user *up)
69 u32 tmp;
71 if (!access_ok(VERIFY_READ, up, sizeof(struct video_buffer32)) ||
72 get_user(tmp, &up->base) ||
73 get_user(kp->height, &up->height) ||
74 get_user(kp->width, &up->width) ||
75 get_user(kp->depth, &up->depth) ||
76 get_user(kp->bytesperline, &up->bytesperline))
77 return -EFAULT;
79 /* This is actually a physical address stored
80 * as a void pointer.
82 kp->base = (void *)(unsigned long) tmp;
84 return 0;
87 static int put_video_buffer32(struct video_buffer *kp, struct video_buffer32 __user *up)
89 u32 tmp = (u32)((unsigned long)kp->base);
91 if(!access_ok(VERIFY_WRITE, up, sizeof(struct video_buffer32)) ||
92 put_user(tmp, &up->base) ||
93 put_user(kp->height, &up->height) ||
94 put_user(kp->width, &up->width) ||
95 put_user(kp->depth, &up->depth) ||
96 put_user(kp->bytesperline, &up->bytesperline))
97 return -EFAULT;
98 return 0;
101 struct video_clip32 {
102 s32 x, y, width, height; /* Its really s32 in videodev.h */
103 compat_caddr_t next;
106 struct video_window32 {
107 u32 x, y, width, height, chromakey, flags;
108 compat_caddr_t clips;
109 compat_int_t clipcount;
112 static int native_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
114 int ret = -ENOIOCTLCMD;
116 if (file->f_op->unlocked_ioctl)
117 ret = file->f_op->unlocked_ioctl(file, cmd, arg);
118 else if (file->f_op->ioctl) {
119 lock_kernel();
120 ret = file->f_op->ioctl(file->f_dentry->d_inode, file, cmd, arg);
121 unlock_kernel();
124 return ret;
128 /* You get back everything except the clips... */
129 static int put_video_window32(struct video_window *kp, struct video_window32 __user *up)
131 if(!access_ok(VERIFY_WRITE, up, sizeof(struct video_window32)) ||
132 put_user(kp->x, &up->x) ||
133 put_user(kp->y, &up->y) ||
134 put_user(kp->width, &up->width) ||
135 put_user(kp->height, &up->height) ||
136 put_user(kp->chromakey, &up->chromakey) ||
137 put_user(kp->flags, &up->flags) ||
138 put_user(kp->clipcount, &up->clipcount))
139 return -EFAULT;
140 return 0;
143 struct v4l2_clip32
145 struct v4l2_rect c;
146 compat_caddr_t next;
149 struct v4l2_window32
151 struct v4l2_rect w;
152 enum v4l2_field field;
153 __u32 chromakey;
154 compat_caddr_t clips; /* actually struct v4l2_clip32 * */
155 __u32 clipcount;
156 compat_caddr_t bitmap;
159 static int get_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 __user *up)
161 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_window32)) ||
162 copy_from_user(&kp->w, &up->w, sizeof(up->w)) ||
163 get_user(kp->field, &up->field) ||
164 get_user(kp->chromakey, &up->chromakey) ||
165 get_user(kp->clipcount, &up->clipcount))
166 return -EFAULT;
167 if (kp->clipcount > 2048)
168 return -EINVAL;
169 if (kp->clipcount) {
170 struct v4l2_clip32 __user *uclips;
171 struct v4l2_clip __user *kclips;
172 int n = kp->clipcount;
173 compat_caddr_t p;
175 if (get_user(p, &up->clips))
176 return -EFAULT;
177 uclips = compat_ptr(p);
178 kclips = compat_alloc_user_space(n * sizeof(struct v4l2_clip));
179 kp->clips = kclips;
180 while (--n >= 0) {
181 if (copy_in_user(&kclips->c, &uclips->c, sizeof(uclips->c)))
182 return -EFAULT;
183 if (put_user(n ? kclips + 1 : NULL, &kclips->next))
184 return -EFAULT;
185 uclips += 1;
186 kclips += 1;
188 } else
189 kp->clips = NULL;
190 return 0;
193 static int put_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 __user *up)
195 if (copy_to_user(&up->w, &kp->w, sizeof(up->w)) ||
196 put_user(kp->field, &up->field) ||
197 put_user(kp->chromakey, &up->chromakey) ||
198 put_user(kp->clipcount, &up->clipcount))
199 return -EFAULT;
200 return 0;
203 static inline int get_v4l2_pix_format(struct v4l2_pix_format *kp, struct v4l2_pix_format __user *up)
205 if (copy_from_user(kp, up, sizeof(struct v4l2_pix_format)))
206 return -EFAULT;
207 return 0;
210 static inline int put_v4l2_pix_format(struct v4l2_pix_format *kp, struct v4l2_pix_format __user *up)
212 if (copy_to_user(up, kp, sizeof(struct v4l2_pix_format)))
213 return -EFAULT;
214 return 0;
217 static inline int get_v4l2_vbi_format(struct v4l2_vbi_format *kp, struct v4l2_vbi_format __user *up)
219 if (copy_from_user(kp, up, sizeof(struct v4l2_vbi_format)))
220 return -EFAULT;
221 return 0;
224 static inline int put_v4l2_vbi_format(struct v4l2_vbi_format *kp, struct v4l2_vbi_format __user *up)
226 if (copy_to_user(up, kp, sizeof(struct v4l2_vbi_format)))
227 return -EFAULT;
228 return 0;
231 struct v4l2_format32
233 enum v4l2_buf_type type;
234 union
236 struct v4l2_pix_format pix; // V4L2_BUF_TYPE_VIDEO_CAPTURE
237 struct v4l2_window32 win; // V4L2_BUF_TYPE_VIDEO_OVERLAY
238 struct v4l2_vbi_format vbi; // V4L2_BUF_TYPE_VBI_CAPTURE
239 __u8 raw_data[200]; // user-defined
240 } fmt;
243 static int get_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up)
245 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_format32)) ||
246 get_user(kp->type, &up->type))
247 return -EFAULT;
248 switch (kp->type) {
249 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
250 return get_v4l2_pix_format(&kp->fmt.pix, &up->fmt.pix);
251 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
252 return get_v4l2_window32(&kp->fmt.win, &up->fmt.win);
253 case V4L2_BUF_TYPE_VBI_CAPTURE:
254 return get_v4l2_vbi_format(&kp->fmt.vbi, &up->fmt.vbi);
255 default:
256 printk("compat_ioctl : unexpected VIDIOC_FMT type %d\n",
257 kp->type);
258 return -ENXIO;
262 static int put_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up)
264 if(!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_format32)) ||
265 put_user(kp->type, &up->type))
266 return -EFAULT;
267 switch (kp->type) {
268 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
269 return put_v4l2_pix_format(&kp->fmt.pix, &up->fmt.pix);
270 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
271 return put_v4l2_window32(&kp->fmt.win, &up->fmt.win);
272 case V4L2_BUF_TYPE_VBI_CAPTURE:
273 return put_v4l2_vbi_format(&kp->fmt.vbi, &up->fmt.vbi);
274 default:
275 return -ENXIO;
279 static inline int get_v4l2_standard(struct v4l2_standard *kp, struct v4l2_standard __user *up)
281 if (copy_from_user(kp, up, sizeof(struct v4l2_standard)))
282 return -EFAULT;
283 return 0;
287 static inline int put_v4l2_standard(struct v4l2_standard *kp, struct v4l2_standard __user *up)
289 if (copy_to_user(up, kp, sizeof(struct v4l2_standard)))
290 return -EFAULT;
291 return 0;
294 struct v4l2_standard32
296 __u32 index;
297 __u32 id[2]; /* __u64 would get the alignment wrong */
298 __u8 name[24];
299 struct v4l2_fract frameperiod; /* Frames, not fields */
300 __u32 framelines;
301 __u32 reserved[4];
304 static int get_v4l2_standard32(struct v4l2_standard *kp, struct v4l2_standard32 __user *up)
306 /* other fields are not set by the user, nor used by the driver */
307 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_standard32)) ||
308 get_user(kp->index, &up->index))
309 return -EFAULT;
310 return 0;
313 static int put_v4l2_standard32(struct v4l2_standard *kp, struct v4l2_standard32 __user *up)
315 if(!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_standard32)) ||
316 put_user(kp->index, &up->index) ||
317 copy_to_user(up->id, &kp->id, sizeof(__u64)) ||
318 copy_to_user(up->name, kp->name, 24) ||
319 copy_to_user(&up->frameperiod, &kp->frameperiod, sizeof(kp->frameperiod)) ||
320 put_user(kp->framelines, &up->framelines) ||
321 copy_to_user(up->reserved, kp->reserved, 4 * sizeof(__u32)))
322 return -EFAULT;
323 return 0;
326 static inline int get_v4l2_tuner(struct v4l2_tuner *kp, struct v4l2_tuner __user *up)
328 if (copy_from_user(kp, up, sizeof(struct v4l2_tuner)))
329 return -EFAULT;
330 return 0;
334 static inline int put_v4l2_tuner(struct v4l2_tuner *kp, struct v4l2_tuner __user *up)
336 if (copy_to_user(up, kp, sizeof(struct v4l2_tuner)))
337 return -EFAULT;
338 return 0;
341 struct v4l2_buffer32
343 __u32 index;
344 enum v4l2_buf_type type;
345 __u32 bytesused;
346 __u32 flags;
347 enum v4l2_field field;
348 struct compat_timeval timestamp;
349 struct v4l2_timecode timecode;
350 __u32 sequence;
352 /* memory location */
353 enum v4l2_memory memory;
354 union {
355 __u32 offset;
356 compat_long_t userptr;
357 } m;
358 __u32 length;
359 __u32 input;
360 __u32 reserved;
363 static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user *up)
366 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_buffer32)) ||
367 get_user(kp->index, &up->index) ||
368 get_user(kp->type, &up->type) ||
369 get_user(kp->flags, &up->flags) ||
370 get_user(kp->memory, &up->memory) ||
371 get_user(kp->input, &up->input))
372 return -EFAULT;
373 switch(kp->memory) {
374 case V4L2_MEMORY_MMAP:
375 break;
376 case V4L2_MEMORY_USERPTR:
378 compat_long_t tmp;
380 if (get_user(kp->length, &up->length) ||
381 get_user(tmp, &up->m.userptr))
382 return -EFAULT;
384 kp->m.userptr = (unsigned long)compat_ptr(tmp);
386 break;
387 case V4L2_MEMORY_OVERLAY:
388 if(get_user(kp->m.offset, &up->m.offset))
389 return -EFAULT;
390 break;
392 return 0;
395 static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user *up)
397 if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_buffer32)) ||
398 put_user(kp->index, &up->index) ||
399 put_user(kp->type, &up->type) ||
400 put_user(kp->flags, &up->flags) ||
401 put_user(kp->memory, &up->memory) ||
402 put_user(kp->input, &up->input))
403 return -EFAULT;
404 switch(kp->memory) {
405 case V4L2_MEMORY_MMAP:
406 if (put_user(kp->length, &up->length) ||
407 put_user(kp->m.offset, &up->m.offset))
408 return -EFAULT;
409 break;
410 case V4L2_MEMORY_USERPTR:
411 if (put_user(kp->length, &up->length) ||
412 put_user(kp->m.userptr, &up->m.userptr))
413 return -EFAULT;
414 break;
415 case V4L2_MEMORY_OVERLAY:
416 if (put_user(kp->m.offset, &up->m.offset))
417 return -EFAULT;
418 break;
420 if (put_user(kp->bytesused, &up->bytesused) ||
421 put_user(kp->field, &up->field) ||
422 put_user(kp->timestamp.tv_sec, &up->timestamp.tv_sec) ||
423 put_user(kp->timestamp.tv_usec, &up->timestamp.tv_usec) ||
424 copy_to_user(&up->timecode, &kp->timecode, sizeof(struct v4l2_timecode)) ||
425 put_user(kp->sequence, &up->sequence) ||
426 put_user(kp->reserved, &up->reserved))
427 return -EFAULT;
428 return 0;
431 struct v4l2_framebuffer32
433 __u32 capability;
434 __u32 flags;
435 compat_caddr_t base;
436 struct v4l2_pix_format fmt;
439 static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_framebuffer32 __user *up)
441 u32 tmp;
443 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_framebuffer32)) ||
444 get_user(tmp, &up->base) ||
445 get_user(kp->capability, &up->capability) ||
446 get_user(kp->flags, &up->flags))
447 return -EFAULT;
448 kp->base = compat_ptr(tmp);
449 get_v4l2_pix_format(&kp->fmt, &up->fmt);
450 return 0;
453 static int put_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_framebuffer32 __user *up)
455 u32 tmp = (u32)((unsigned long)kp->base);
457 if(!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_framebuffer32)) ||
458 put_user(tmp, &up->base) ||
459 put_user(kp->capability, &up->capability) ||
460 put_user(kp->flags, &up->flags))
461 return -EFAULT;
462 put_v4l2_pix_format(&kp->fmt, &up->fmt);
463 return 0;
466 static inline int get_v4l2_input32(struct v4l2_input *kp, struct v4l2_input __user *up)
468 if (copy_from_user(kp, up, sizeof(struct v4l2_input) - 4))
469 return -EFAULT;
470 return 0;
473 static inline int put_v4l2_input32(struct v4l2_input *kp, struct v4l2_input __user *up)
475 if (copy_to_user(up, kp, sizeof(struct v4l2_input) - 4))
476 return -EFAULT;
477 return 0;
480 static inline int get_v4l2_input(struct v4l2_input *kp, struct v4l2_input __user *up)
482 if (copy_from_user(kp, up, sizeof(struct v4l2_input)))
483 return -EFAULT;
484 return 0;
487 static inline int put_v4l2_input(struct v4l2_input *kp, struct v4l2_input __user *up)
489 if (copy_to_user(up, kp, sizeof(struct v4l2_input)))
490 return -EFAULT;
491 return 0;
494 #define VIDIOCGTUNER32 _IOWR('v',4, struct video_tuner32)
495 #define VIDIOCSTUNER32 _IOW('v',5, struct video_tuner32)
496 #define VIDIOCGWIN32 _IOR('v',9, struct video_window32)
497 #define VIDIOCSWIN32 _IOW('v',10, struct video_window32)
498 #define VIDIOCGFBUF32 _IOR('v',11, struct video_buffer32)
499 #define VIDIOCSFBUF32 _IOW('v',12, struct video_buffer32)
500 #define VIDIOCGFREQ32 _IOR('v',14, u32)
501 #define VIDIOCSFREQ32 _IOW('v',15, u32)
503 /* VIDIOC_ENUMINPUT32 is VIDIOC_ENUMINPUT minus 4 bytes of padding alignement */
504 #define VIDIOC_ENUMINPUT32 VIDIOC_ENUMINPUT - _IOC(0, 0, 0, 4)
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 /* VIDIOC_OVERLAY is now _IOW, but was _IOWR */
511 #define VIDIOC_OVERLAY32 _IOWR ('V', 14, compat_int_t)
512 #define VIDIOC_QBUF32 _IOWR ('V', 15, struct v4l2_buffer32)
513 #define VIDIOC_DQBUF32 _IOWR ('V', 17, struct v4l2_buffer32)
514 #define VIDIOC_STREAMON32 _IOW ('V', 18, compat_int_t)
515 #define VIDIOC_STREAMOFF32 _IOW ('V', 19, compat_int_t)
516 #define VIDIOC_ENUMSTD32 _IOWR ('V', 25, struct v4l2_standard32)
517 /* VIDIOC_S_CTRL is now _IOWR, but was _IOW */
518 #define VIDIOC_S_CTRL32 _IOW ('V', 28, struct v4l2_control)
519 #define VIDIOC_G_INPUT32 _IOR ('V', 38, compat_int_t)
520 #define VIDIOC_S_INPUT32 _IOWR ('V', 39, compat_int_t)
521 #define VIDIOC_TRY_FMT32 _IOWR ('V', 64, struct v4l2_format32)
523 enum {
524 MaxClips = (~0U-sizeof(struct video_window))/sizeof(struct video_clip)
527 static int do_set_window(struct file *file, unsigned int cmd, unsigned long arg)
529 struct video_window32 __user *up = compat_ptr(arg);
530 struct video_window __user *vw;
531 struct video_clip __user *p;
532 int nclips;
533 u32 n;
535 if (!access_ok(VERIFY_READ, up, sizeof(struct video_window32)))
536 return -EFAULT;
538 if (get_user(nclips, &up->clipcount))
539 return -EFAULT;
541 /* Peculiar interface... */
542 if (nclips < 0)
543 nclips = VIDEO_CLIPMAP_SIZE;
545 if (nclips > MaxClips)
546 return -ENOMEM;
548 vw = compat_alloc_user_space(sizeof(struct video_window) +
549 nclips * sizeof(struct video_clip));
551 p = nclips ? (struct video_clip __user *)(vw + 1) : NULL;
553 if (get_user(n, &up->x) || put_user(n, &vw->x) ||
554 get_user(n, &up->y) || put_user(n, &vw->y) ||
555 get_user(n, &up->width) || put_user(n, &vw->width) ||
556 get_user(n, &up->height) || put_user(n, &vw->height) ||
557 get_user(n, &up->chromakey) || put_user(n, &vw->chromakey) ||
558 get_user(n, &up->flags) || put_user(n, &vw->flags) ||
559 get_user(n, &up->clipcount) || put_user(n, &vw->clipcount) ||
560 get_user(n, &up->clips) || put_user(p, &vw->clips))
561 return -EFAULT;
563 if (nclips) {
564 struct video_clip32 __user *u = compat_ptr(n);
565 int i;
566 if (!u)
567 return -EINVAL;
568 for (i = 0; i < nclips; i++, u++, p++) {
569 s32 v;
570 if (!access_ok(VERIFY_READ, u, sizeof(struct video_clip32)) ||
571 !access_ok(VERIFY_WRITE, p, sizeof(struct video_clip32)) ||
572 get_user(v, &u->x) ||
573 put_user(v, &p->x) ||
574 get_user(v, &u->y) ||
575 put_user(v, &p->y) ||
576 get_user(v, &u->width) ||
577 put_user(v, &p->width) ||
578 get_user(v, &u->height) ||
579 put_user(v, &p->height) ||
580 put_user(NULL, &p->next))
581 return -EFAULT;
585 return native_ioctl(file, VIDIOCSWIN, (unsigned long)vw);
588 static int do_video_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
590 union {
591 struct video_tuner vt;
592 struct video_buffer vb;
593 struct video_window vw;
594 struct v4l2_format v2f;
595 struct v4l2_buffer v2b;
596 struct v4l2_framebuffer v2fb;
597 struct v4l2_standard v2s;
598 struct v4l2_input v2i;
599 struct v4l2_tuner v2t;
600 unsigned long vx;
601 } karg;
602 void __user *up = compat_ptr(arg);
603 int compatible_arg = 1;
604 int err = 0;
605 int realcmd = cmd;
607 /* First, convert the command. */
608 switch(cmd) {
609 case VIDIOCGTUNER32: cmd = VIDIOCGTUNER; break;
610 case VIDIOCSTUNER32: cmd = VIDIOCSTUNER; break;
611 case VIDIOCGWIN32: cmd = VIDIOCGWIN; break;
612 case VIDIOCGFBUF32: cmd = VIDIOCGFBUF; break;
613 case VIDIOCSFBUF32: cmd = VIDIOCSFBUF; break;
614 case VIDIOCGFREQ32: cmd = VIDIOCGFREQ; break;
615 case VIDIOCSFREQ32: cmd = VIDIOCSFREQ; break;
616 case VIDIOC_G_FMT32: cmd = VIDIOC_G_FMT; break;
617 case VIDIOC_S_FMT32: cmd = VIDIOC_S_FMT; break;
618 case VIDIOC_QUERYBUF32: cmd = VIDIOC_QUERYBUF; break;
619 case VIDIOC_QBUF32: cmd = VIDIOC_QBUF; break;
620 case VIDIOC_DQBUF32: cmd = VIDIOC_DQBUF; break;
621 case VIDIOC_STREAMON32: cmd = VIDIOC_STREAMON; break;
622 case VIDIOC_STREAMOFF32: cmd = VIDIOC_STREAMOFF; break;
623 case VIDIOC_G_FBUF32: cmd = VIDIOC_G_FBUF; break;
624 case VIDIOC_S_FBUF32: cmd = VIDIOC_S_FBUF; break;
625 case VIDIOC_OVERLAY32: cmd = VIDIOC_OVERLAY; break;
626 case VIDIOC_ENUMSTD32: realcmd = VIDIOC_ENUMSTD; break;
627 case VIDIOC_ENUMINPUT32: realcmd = VIDIOC_ENUMINPUT; break;
628 case VIDIOC_S_CTRL32: cmd = VIDIOC_S_CTRL; break;
629 case VIDIOC_G_INPUT32: cmd = VIDIOC_G_INPUT; break;
630 case VIDIOC_S_INPUT32: cmd = VIDIOC_S_INPUT; break;
631 case VIDIOC_TRY_FMT32: cmd = VIDIOC_TRY_FMT; break;
634 switch(cmd) {
635 case VIDIOCSTUNER:
636 case VIDIOCGTUNER:
637 err = get_video_tuner32(&karg.vt, up);
638 compatible_arg = 0;
640 break;
642 case VIDIOCSFBUF:
643 err = get_video_buffer32(&karg.vb, up);
644 compatible_arg = 0;
645 break;
647 case VIDIOCSFREQ:
648 case VIDIOC_S_INPUT:
649 case VIDIOC_OVERLAY:
650 case VIDIOC_STREAMON:
651 case VIDIOC_STREAMOFF:
652 err = get_user(karg.vx, (u32 __user *)up);
653 compatible_arg = 0;
654 break;
656 case VIDIOC_S_FBUF:
657 err = get_v4l2_framebuffer32(&karg.v2fb, up);
658 compatible_arg = 0;
659 break;
661 case VIDIOC_G_FMT:
662 case VIDIOC_S_FMT:
663 case VIDIOC_TRY_FMT:
664 err = get_v4l2_format32(&karg.v2f, up);
665 compatible_arg = 0;
666 break;
668 case VIDIOC_QUERYBUF:
669 case VIDIOC_QBUF:
670 case VIDIOC_DQBUF:
671 err = get_v4l2_buffer32(&karg.v2b, up);
672 compatible_arg = 0;
673 break;
675 case VIDIOC_ENUMSTD:
676 err = get_v4l2_standard(&karg.v2s, up);
677 compatible_arg = 0;
678 break;
680 case VIDIOC_ENUMSTD32:
681 err = get_v4l2_standard32(&karg.v2s, up);
682 compatible_arg = 0;
683 break;
685 case VIDIOC_ENUMINPUT:
686 err = get_v4l2_input(&karg.v2i, up);
687 compatible_arg = 0;
688 break;
690 case VIDIOC_ENUMINPUT32:
691 err = get_v4l2_input32(&karg.v2i, up);
692 compatible_arg = 0;
693 break;
695 case VIDIOC_G_TUNER:
696 case VIDIOC_S_TUNER:
697 err = get_v4l2_tuner(&karg.v2t, up);
698 compatible_arg = 0;
699 break;
701 case VIDIOCGWIN:
702 case VIDIOCGFBUF:
703 case VIDIOCGFREQ:
704 case VIDIOC_G_FBUF:
705 case VIDIOC_G_INPUT:
706 compatible_arg = 0;
709 if(err)
710 goto out;
712 if(compatible_arg)
713 err = native_ioctl(file, realcmd, (unsigned long)up);
714 else {
715 mm_segment_t old_fs = get_fs();
717 set_fs(KERNEL_DS);
718 err = native_ioctl(file, realcmd, (unsigned long)&karg);
719 set_fs(old_fs);
721 if(err == 0) {
722 switch(cmd) {
723 case VIDIOCGTUNER:
724 err = put_video_tuner32(&karg.vt, up);
725 break;
727 case VIDIOCGWIN:
728 err = put_video_window32(&karg.vw, up);
729 break;
731 case VIDIOCGFBUF:
732 err = put_video_buffer32(&karg.vb, up);
733 break;
735 case VIDIOC_G_FBUF:
736 err = put_v4l2_framebuffer32(&karg.v2fb, up);
737 break;
739 case VIDIOC_G_FMT:
740 case VIDIOC_S_FMT:
741 case VIDIOC_TRY_FMT:
742 err = put_v4l2_format32(&karg.v2f, up);
743 break;
745 case VIDIOC_QUERYBUF:
746 case VIDIOC_QBUF:
747 case VIDIOC_DQBUF:
748 err = put_v4l2_buffer32(&karg.v2b, up);
749 break;
751 case VIDIOC_ENUMSTD:
752 err = put_v4l2_standard(&karg.v2s, up);
753 break;
755 case VIDIOC_ENUMSTD32:
756 err = put_v4l2_standard32(&karg.v2s, up);
757 break;
759 case VIDIOC_G_TUNER:
760 case VIDIOC_S_TUNER:
761 err = put_v4l2_tuner(&karg.v2t, up);
762 break;
764 case VIDIOC_ENUMINPUT:
765 err = put_v4l2_input(&karg.v2i, up);
766 break;
768 case VIDIOC_ENUMINPUT32:
769 err = put_v4l2_input32(&karg.v2i, up);
770 break;
772 case VIDIOCGFREQ:
773 case VIDIOC_G_INPUT:
774 err = put_user(((u32)karg.vx), (u32 __user *)up);
775 break;
778 out:
779 return err;
782 long v4l_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)
784 int ret = -ENOIOCTLCMD;
786 if (!file->f_op->ioctl)
787 return ret;
789 switch (cmd) {
790 case VIDIOCSWIN32:
791 ret = do_set_window(file, cmd, arg);
792 break;
793 case VIDIOCGTUNER32:
794 case VIDIOCSTUNER32:
795 case VIDIOCGWIN32:
796 case VIDIOCGFBUF32:
797 case VIDIOCSFBUF32:
798 case VIDIOCGFREQ32:
799 case VIDIOCSFREQ32:
800 case VIDIOC_QUERYCAP:
801 case VIDIOC_ENUM_FMT:
802 case VIDIOC_G_FMT32:
803 case VIDIOC_S_FMT32:
804 case VIDIOC_REQBUFS:
805 case VIDIOC_QUERYBUF32:
806 case VIDIOC_G_FBUF32:
807 case VIDIOC_S_FBUF32:
808 case VIDIOC_OVERLAY32:
809 case VIDIOC_QBUF32:
810 case VIDIOC_DQBUF32:
811 case VIDIOC_STREAMON32:
812 case VIDIOC_STREAMOFF32:
813 case VIDIOC_G_PARM:
814 case VIDIOC_G_STD:
815 case VIDIOC_S_STD:
816 case VIDIOC_G_TUNER:
817 case VIDIOC_S_TUNER:
818 case VIDIOC_ENUMSTD:
819 case VIDIOC_ENUMSTD32:
820 case VIDIOC_ENUMINPUT:
821 case VIDIOC_ENUMINPUT32:
822 case VIDIOC_G_CTRL:
823 case VIDIOC_S_CTRL32:
824 case VIDIOC_QUERYCTRL:
825 case VIDIOC_G_INPUT32:
826 case VIDIOC_S_INPUT32:
827 case VIDIOC_TRY_FMT32:
828 ret = do_video_ioctl(file, cmd, arg);
829 break;
831 /* Little v, the video4linux ioctls (conflict?) */
832 case VIDIOCGCAP:
833 case VIDIOCGCHAN:
834 case VIDIOCSCHAN:
835 case VIDIOCGPICT:
836 case VIDIOCSPICT:
837 case VIDIOCCAPTURE:
838 case VIDIOCKEY:
839 case VIDIOCGAUDIO:
840 case VIDIOCSAUDIO:
841 case VIDIOCSYNC:
842 case VIDIOCMCAPTURE:
843 case VIDIOCGMBUF:
844 case VIDIOCGUNIT:
845 case VIDIOCGCAPTURE:
846 case VIDIOCSCAPTURE:
848 /* BTTV specific... */
849 case _IOW('v', BASE_VIDIOCPRIVATE+0, char [256]):
850 case _IOR('v', BASE_VIDIOCPRIVATE+1, char [256]):
851 case _IOR('v' , BASE_VIDIOCPRIVATE+2, unsigned int):
852 case _IOW('v' , BASE_VIDIOCPRIVATE+3, char [16]): /* struct bttv_pll_info */
853 case _IOR('v' , BASE_VIDIOCPRIVATE+4, int):
854 case _IOR('v' , BASE_VIDIOCPRIVATE+5, int):
855 case _IOR('v' , BASE_VIDIOCPRIVATE+6, int):
856 case _IOR('v' , BASE_VIDIOCPRIVATE+7, int):
857 ret = native_ioctl(file, cmd, (unsigned long)compat_ptr(arg));
858 break;
859 default:
860 v4l_print_ioctl("compat_ioctl32", cmd);
862 return ret;
864 #else
865 long v4l_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)
867 return -ENOIOCTLCMD;
869 #endif
870 EXPORT_SYMBOL_GPL(v4l_compat_ioctl32);
872 MODULE_LICENSE("GPL");