Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 1 | /* |
| 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 |
| 8 | * Copyright (C) 2003 Pavel Machek (pavel@suse.cz) |
| 9 | * Copyright (C) 2005 Philippe De Muyter (phdm@macqel.be) |
| 10 | * |
| 11 | * These routines maintain argument size conversion between 32bit and 64bit |
| 12 | * ioctls. |
| 13 | */ |
| 14 | |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 15 | #include <linux/config.h> |
| 16 | #include <linux/compat.h> |
| 17 | #include <linux/videodev.h> |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 18 | #include <linux/videodev2.h> |
Nickolay V. Shmyrev | 133b735 | 2006-01-09 15:24:58 -0200 | [diff] [blame] | 19 | #include <linux/module.h> |
Hans Verkuil | e8efb71 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 20 | #include <linux/smp_lock.h> |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 21 | #include <media/v4l2-common.h> |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 22 | |
| 23 | #ifdef CONFIG_COMPAT |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 24 | |
| 25 | |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 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; |
| 32 | }; |
| 33 | |
| 34 | static int get_video_tuner32(struct video_tuner *kp, struct video_tuner32 __user *up) |
| 35 | { |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 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)) |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 44 | return -EFAULT; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 45 | return 0; |
| 46 | } |
| 47 | |
| 48 | static int put_video_tuner32(struct video_tuner *kp, struct video_tuner32 __user *up) |
| 49 | { |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 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; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | struct video_buffer32 { |
| 63 | compat_caddr_t base; |
| 64 | compat_int_t height, width, depth, bytesperline; |
| 65 | }; |
| 66 | |
| 67 | static int get_video_buffer32(struct video_buffer *kp, struct video_buffer32 __user *up) |
| 68 | { |
| 69 | u32 tmp; |
| 70 | |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 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; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 78 | |
| 79 | /* This is actually a physical address stored |
| 80 | * as a void pointer. |
| 81 | */ |
| 82 | kp->base = (void *)(unsigned long) tmp; |
| 83 | |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | static int put_video_buffer32(struct video_buffer *kp, struct video_buffer32 __user *up) |
| 88 | { |
| 89 | u32 tmp = (u32)((unsigned long)kp->base); |
| 90 | |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 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; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | struct video_clip32 { |
| 102 | s32 x, y, width, height; /* Its really s32 in videodev.h */ |
| 103 | compat_caddr_t next; |
| 104 | }; |
| 105 | |
| 106 | struct video_window32 { |
| 107 | u32 x, y, width, height, chromakey, flags; |
| 108 | compat_caddr_t clips; |
| 109 | compat_int_t clipcount; |
| 110 | }; |
| 111 | |
| 112 | static int native_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 113 | { |
| 114 | int ret = -ENOIOCTLCMD; |
| 115 | |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 116 | if (file->f_op->unlocked_ioctl) |
| 117 | ret = file->f_op->unlocked_ioctl(file, cmd, arg); |
| 118 | else if (file->f_op->ioctl) { |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 119 | lock_kernel(); |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 120 | ret = file->f_op->ioctl(file->f_dentry->d_inode, file, cmd, arg); |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 121 | unlock_kernel(); |
| 122 | } |
| 123 | |
| 124 | return ret; |
| 125 | } |
| 126 | |
| 127 | |
| 128 | /* You get back everything except the clips... */ |
| 129 | static int put_video_window32(struct video_window *kp, struct video_window32 __user *up) |
| 130 | { |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 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; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 140 | return 0; |
| 141 | } |
| 142 | |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 143 | struct v4l2_clip32 |
| 144 | { |
| 145 | struct v4l2_rect c; |
| 146 | compat_caddr_t next; |
| 147 | }; |
| 148 | |
| 149 | struct v4l2_window32 |
| 150 | { |
| 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; |
| 157 | }; |
| 158 | |
| 159 | static int get_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 __user *up) |
| 160 | { |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 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; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 167 | if (kp->clipcount > 2048) |
| 168 | return -EINVAL; |
| 169 | if (kp->clipcount) { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 170 | struct v4l2_clip32 __user *uclips; |
| 171 | struct v4l2_clip __user *kclips; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 172 | int n = kp->clipcount; |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 173 | compat_caddr_t p; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 174 | |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 175 | if (get_user(p, &up->clips)) |
| 176 | return -EFAULT; |
| 177 | uclips = compat_ptr(p); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 178 | kclips = compat_alloc_user_space(n * sizeof(struct v4l2_clip)); |
| 179 | kp->clips = kclips; |
| 180 | while (--n >= 0) { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 181 | if (copy_in_user(&kclips->c, &uclips->c, sizeof(uclips->c))) |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 182 | return -EFAULT; |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 183 | if (put_user(n ? kclips + 1 : NULL, &kclips->next)) |
| 184 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 185 | uclips += 1; |
| 186 | kclips += 1; |
| 187 | } |
| 188 | } else |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 189 | kp->clips = NULL; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 190 | return 0; |
| 191 | } |
| 192 | |
| 193 | static int put_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 __user *up) |
| 194 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 195 | if (copy_to_user(&up->w, &kp->w, sizeof(up->w)) || |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 196 | put_user(kp->field, &up->field) || |
| 197 | put_user(kp->chromakey, &up->chromakey) || |
| 198 | put_user(kp->clipcount, &up->clipcount)) |
| 199 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 200 | return 0; |
| 201 | } |
| 202 | |
| 203 | static inline int get_v4l2_pix_format(struct v4l2_pix_format *kp, struct v4l2_pix_format __user *up) |
| 204 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 205 | if (copy_from_user(kp, up, sizeof(struct v4l2_pix_format))) |
| 206 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 207 | return 0; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | static inline int put_v4l2_pix_format(struct v4l2_pix_format *kp, struct v4l2_pix_format __user *up) |
| 211 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 212 | if (copy_to_user(up, kp, sizeof(struct v4l2_pix_format))) |
| 213 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 214 | return 0; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | static inline int get_v4l2_vbi_format(struct v4l2_vbi_format *kp, struct v4l2_vbi_format __user *up) |
| 218 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 219 | if (copy_from_user(kp, up, sizeof(struct v4l2_vbi_format))) |
| 220 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 221 | return 0; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | static inline int put_v4l2_vbi_format(struct v4l2_vbi_format *kp, struct v4l2_vbi_format __user *up) |
| 225 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 226 | if (copy_to_user(up, kp, sizeof(struct v4l2_vbi_format))) |
| 227 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 228 | return 0; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | struct v4l2_format32 |
| 232 | { |
| 233 | enum v4l2_buf_type type; |
| 234 | union |
| 235 | { |
| 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; |
| 241 | }; |
| 242 | |
| 243 | static int get_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up) |
| 244 | { |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 245 | if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_format32)) || |
| 246 | get_user(kp->type, &up->type)) |
| 247 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 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; |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | static int put_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up) |
| 263 | { |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 264 | if(!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_format32)) || |
| 265 | put_user(kp->type, &up->type)) |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 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; |
| 276 | } |
| 277 | } |
| 278 | |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 279 | static inline int get_v4l2_standard(struct v4l2_standard *kp, struct v4l2_standard __user *up) |
| 280 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 281 | if (copy_from_user(kp, up, sizeof(struct v4l2_standard))) |
| 282 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 283 | return 0; |
| 284 | |
| 285 | } |
| 286 | |
| 287 | static inline int put_v4l2_standard(struct v4l2_standard *kp, struct v4l2_standard __user *up) |
| 288 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 289 | if (copy_to_user(up, kp, sizeof(struct v4l2_standard))) |
| 290 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 291 | return 0; |
| 292 | } |
| 293 | |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 294 | struct v4l2_standard32 |
| 295 | { |
| 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]; |
| 302 | }; |
| 303 | |
| 304 | static int get_v4l2_standard32(struct v4l2_standard *kp, struct v4l2_standard32 __user *up) |
| 305 | { |
| 306 | /* other fields are not set by the user, nor used by the driver */ |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 307 | if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_standard32)) || |
| 308 | get_user(kp->index, &up->index)) |
| 309 | return -EFAULT; |
| 310 | return 0; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | static int put_v4l2_standard32(struct v4l2_standard *kp, struct v4l2_standard32 __user *up) |
| 314 | { |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 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; |
| 324 | } |
| 325 | |
| 326 | static inline int get_v4l2_tuner(struct v4l2_tuner *kp, struct v4l2_tuner __user *up) |
| 327 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 328 | if (copy_from_user(kp, up, sizeof(struct v4l2_tuner))) |
| 329 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 330 | return 0; |
| 331 | |
| 332 | } |
| 333 | |
| 334 | static inline int put_v4l2_tuner(struct v4l2_tuner *kp, struct v4l2_tuner __user *up) |
| 335 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 336 | if (copy_to_user(up, kp, sizeof(struct v4l2_tuner))) |
| 337 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 338 | return 0; |
| 339 | } |
| 340 | |
| 341 | struct v4l2_buffer32 |
| 342 | { |
| 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; |
| 351 | |
| 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; |
| 361 | }; |
| 362 | |
| 363 | static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user *up) |
| 364 | { |
| 365 | |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 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; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 373 | switch(kp->memory) { |
| 374 | case V4L2_MEMORY_MMAP: |
| 375 | break; |
| 376 | case V4L2_MEMORY_USERPTR: |
| 377 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 378 | compat_long_t tmp; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 379 | |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 380 | if (get_user(kp->length, &up->length) || |
| 381 | get_user(tmp, &up->m.userptr)) |
| 382 | return -EFAULT; |
| 383 | |
| 384 | kp->m.userptr = (unsigned long)compat_ptr(tmp); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 385 | } |
| 386 | break; |
| 387 | case V4L2_MEMORY_OVERLAY: |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 388 | if(get_user(kp->m.offset, &up->m.offset)) |
| 389 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 390 | break; |
| 391 | } |
| 392 | return 0; |
| 393 | } |
| 394 | |
| 395 | static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user *up) |
| 396 | { |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 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; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 404 | switch(kp->memory) { |
| 405 | case V4L2_MEMORY_MMAP: |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 406 | if (put_user(kp->length, &up->length) || |
| 407 | put_user(kp->m.offset, &up->m.offset)) |
| 408 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 409 | break; |
| 410 | case V4L2_MEMORY_USERPTR: |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 411 | if (put_user(kp->length, &up->length) || |
| 412 | put_user(kp->m.userptr, &up->m.userptr)) |
| 413 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 414 | break; |
| 415 | case V4L2_MEMORY_OVERLAY: |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 416 | if (put_user(kp->m.offset, &up->m.offset)) |
| 417 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 418 | break; |
| 419 | } |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 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; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 428 | return 0; |
| 429 | } |
| 430 | |
| 431 | struct v4l2_framebuffer32 |
| 432 | { |
| 433 | __u32 capability; |
| 434 | __u32 flags; |
| 435 | compat_caddr_t base; |
| 436 | struct v4l2_pix_format fmt; |
| 437 | }; |
| 438 | |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 439 | static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_framebuffer32 __user *up) |
| 440 | { |
| 441 | u32 tmp; |
| 442 | |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 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; |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 448 | kp->base = compat_ptr(tmp); |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 449 | get_v4l2_pix_format(&kp->fmt, &up->fmt); |
| 450 | return 0; |
| 451 | } |
| 452 | |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 453 | static int put_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_framebuffer32 __user *up) |
| 454 | { |
| 455 | u32 tmp = (u32)((unsigned long)kp->base); |
| 456 | |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 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; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 462 | put_v4l2_pix_format(&kp->fmt, &up->fmt); |
| 463 | return 0; |
| 464 | } |
| 465 | |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 466 | static inline int get_v4l2_input32(struct v4l2_input *kp, struct v4l2_input __user *up) |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 467 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 468 | if (copy_from_user(kp, up, sizeof(struct v4l2_input) - 4)) |
| 469 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 470 | return 0; |
| 471 | } |
| 472 | |
| 473 | static inline int put_v4l2_input32(struct v4l2_input *kp, struct v4l2_input __user *up) |
| 474 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 475 | if (copy_to_user(up, kp, sizeof(struct v4l2_input) - 4)) |
| 476 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 477 | return 0; |
| 478 | } |
| 479 | |
| 480 | static inline int get_v4l2_input(struct v4l2_input *kp, struct v4l2_input __user *up) |
| 481 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 482 | if (copy_from_user(kp, up, sizeof(struct v4l2_input))) |
| 483 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 484 | return 0; |
| 485 | } |
| 486 | |
| 487 | static inline int put_v4l2_input(struct v4l2_input *kp, struct v4l2_input __user *up) |
| 488 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 489 | if (copy_to_user(up, kp, sizeof(struct v4l2_input))) |
| 490 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 491 | return 0; |
| 492 | } |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 493 | |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 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) |
| 502 | |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 503 | /* VIDIOC_ENUMINPUT32 is VIDIOC_ENUMINPUT minus 4 bytes of padding alignement */ |
| 504 | #define VIDIOC_ENUMINPUT32 VIDIOC_ENUMINPUT - _IOC(0, 0, 0, 4) |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 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) |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 509 | #define VIDIOC_S_FBUF32 _IOW ('V', 11, struct v4l2_framebuffer32) |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 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) |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 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) |
| 522 | |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 523 | enum { |
| 524 | MaxClips = (~0U-sizeof(struct video_window))/sizeof(struct video_clip) |
| 525 | }; |
| 526 | |
| 527 | static int do_set_window(struct file *file, unsigned int cmd, unsigned long arg) |
| 528 | { |
| 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; |
| 534 | |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 535 | if (!access_ok(VERIFY_READ, up, sizeof(struct video_window32))) |
| 536 | return -EFAULT; |
| 537 | |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 538 | if (get_user(nclips, &up->clipcount)) |
| 539 | return -EFAULT; |
| 540 | |
| 541 | /* Peculiar interface... */ |
| 542 | if (nclips < 0) |
| 543 | nclips = VIDEO_CLIPMAP_SIZE; |
| 544 | |
| 545 | if (nclips > MaxClips) |
| 546 | return -ENOMEM; |
| 547 | |
| 548 | vw = compat_alloc_user_space(sizeof(struct video_window) + |
| 549 | nclips * sizeof(struct video_clip)); |
| 550 | |
| 551 | p = nclips ? (struct video_clip __user *)(vw + 1) : NULL; |
| 552 | |
| 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; |
| 562 | |
| 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; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 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) || |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 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; |
| 582 | } |
| 583 | } |
| 584 | |
Guy Martin | 009494e | 2006-01-09 15:32:45 -0200 | [diff] [blame] | 585 | return native_ioctl(file, VIDIOCSWIN, (unsigned long)vw); |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | static int do_video_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 589 | { |
| 590 | union { |
| 591 | struct video_tuner vt; |
| 592 | struct video_buffer vb; |
| 593 | struct video_window vw; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 594 | struct v4l2_format v2f; |
| 595 | struct v4l2_buffer v2b; |
| 596 | struct v4l2_framebuffer v2fb; |
| 597 | struct v4l2_standard v2s; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 598 | struct v4l2_input v2i; |
| 599 | struct v4l2_tuner v2t; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 600 | unsigned long vx; |
| 601 | } karg; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 602 | void __user *up = compat_ptr(arg); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 603 | int compatible_arg = 1; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 604 | int err = 0; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 605 | int realcmd = cmd; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 606 | |
| 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; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 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; |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 624 | case VIDIOC_S_FBUF32: cmd = VIDIOC_S_FBUF; break; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 625 | case VIDIOC_OVERLAY32: cmd = VIDIOC_OVERLAY; break; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 626 | case VIDIOC_ENUMSTD32: realcmd = VIDIOC_ENUMSTD; break; |
| 627 | case VIDIOC_ENUMINPUT32: realcmd = VIDIOC_ENUMINPUT; break; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 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; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 632 | }; |
| 633 | |
| 634 | switch(cmd) { |
| 635 | case VIDIOCSTUNER: |
| 636 | case VIDIOCGTUNER: |
| 637 | err = get_video_tuner32(&karg.vt, up); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 638 | compatible_arg = 0; |
| 639 | |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 640 | break; |
| 641 | |
| 642 | case VIDIOCSFBUF: |
| 643 | err = get_video_buffer32(&karg.vb, up); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 644 | compatible_arg = 0; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 645 | break; |
| 646 | |
| 647 | case VIDIOCSFREQ: |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 648 | case VIDIOC_S_INPUT: |
| 649 | case VIDIOC_OVERLAY: |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 650 | case VIDIOC_STREAMON: |
| 651 | case VIDIOC_STREAMOFF: |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 652 | err = get_user(karg.vx, (u32 __user *)up); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 653 | compatible_arg = 0; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 654 | break; |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 655 | |
| 656 | case VIDIOC_S_FBUF: |
| 657 | err = get_v4l2_framebuffer32(&karg.v2fb, up); |
| 658 | compatible_arg = 0; |
| 659 | break; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 660 | |
| 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; |
| 667 | |
| 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; |
| 674 | |
| 675 | case VIDIOC_ENUMSTD: |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 676 | err = get_v4l2_standard(&karg.v2s, up); |
| 677 | compatible_arg = 0; |
| 678 | break; |
| 679 | |
| 680 | case VIDIOC_ENUMSTD32: |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 681 | err = get_v4l2_standard32(&karg.v2s, up); |
| 682 | compatible_arg = 0; |
| 683 | break; |
| 684 | |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 685 | case VIDIOC_ENUMINPUT: |
| 686 | err = get_v4l2_input(&karg.v2i, up); |
| 687 | compatible_arg = 0; |
| 688 | break; |
| 689 | |
| 690 | case VIDIOC_ENUMINPUT32: |
| 691 | err = get_v4l2_input32(&karg.v2i, up); |
| 692 | compatible_arg = 0; |
| 693 | break; |
| 694 | |
| 695 | case VIDIOC_G_TUNER: |
| 696 | case VIDIOC_S_TUNER: |
| 697 | err = get_v4l2_tuner(&karg.v2t, up); |
| 698 | compatible_arg = 0; |
| 699 | break; |
| 700 | |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 701 | case VIDIOCGWIN: |
| 702 | case VIDIOCGFBUF: |
| 703 | case VIDIOCGFREQ: |
| 704 | case VIDIOC_G_FBUF: |
| 705 | case VIDIOC_G_INPUT: |
| 706 | compatible_arg = 0; |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 707 | }; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 708 | |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 709 | if(err) |
| 710 | goto out; |
| 711 | |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 712 | if(compatible_arg) |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 713 | err = native_ioctl(file, realcmd, (unsigned long)up); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 714 | else { |
| 715 | mm_segment_t old_fs = get_fs(); |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 716 | |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 717 | set_fs(KERNEL_DS); |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 718 | err = native_ioctl(file, realcmd, (unsigned long)&karg); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 719 | set_fs(old_fs); |
| 720 | } |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 721 | if(err == 0) { |
| 722 | switch(cmd) { |
| 723 | case VIDIOCGTUNER: |
| 724 | err = put_video_tuner32(&karg.vt, up); |
| 725 | break; |
| 726 | |
| 727 | case VIDIOCGWIN: |
| 728 | err = put_video_window32(&karg.vw, up); |
| 729 | break; |
| 730 | |
| 731 | case VIDIOCGFBUF: |
| 732 | err = put_video_buffer32(&karg.vb, up); |
| 733 | break; |
| 734 | |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 735 | case VIDIOC_G_FBUF: |
| 736 | err = put_v4l2_framebuffer32(&karg.v2fb, up); |
| 737 | break; |
| 738 | |
| 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; |
| 744 | |
| 745 | case VIDIOC_QUERYBUF: |
| 746 | case VIDIOC_QBUF: |
| 747 | case VIDIOC_DQBUF: |
| 748 | err = put_v4l2_buffer32(&karg.v2b, up); |
| 749 | break; |
| 750 | |
| 751 | case VIDIOC_ENUMSTD: |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 752 | err = put_v4l2_standard(&karg.v2s, up); |
| 753 | break; |
| 754 | |
| 755 | case VIDIOC_ENUMSTD32: |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 756 | err = put_v4l2_standard32(&karg.v2s, up); |
| 757 | break; |
| 758 | |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 759 | case VIDIOC_G_TUNER: |
| 760 | case VIDIOC_S_TUNER: |
| 761 | err = put_v4l2_tuner(&karg.v2t, up); |
| 762 | break; |
| 763 | |
| 764 | case VIDIOC_ENUMINPUT: |
| 765 | err = put_v4l2_input(&karg.v2i, up); |
| 766 | break; |
| 767 | |
| 768 | case VIDIOC_ENUMINPUT32: |
| 769 | err = put_v4l2_input32(&karg.v2i, up); |
| 770 | break; |
| 771 | |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 772 | case VIDIOCGFREQ: |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 773 | case VIDIOC_G_INPUT: |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 774 | err = put_user(((u32)karg.vx), (u32 __user *)up); |
| 775 | break; |
| 776 | }; |
| 777 | } |
| 778 | out: |
| 779 | return err; |
| 780 | } |
| 781 | |
| 782 | long v4l_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg) |
| 783 | { |
| 784 | int ret = -ENOIOCTLCMD; |
| 785 | |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 786 | if (!file->f_op->ioctl) |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 787 | return ret; |
| 788 | |
| 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: |
Nickolay V. Shmyrev | 133b735 | 2006-01-09 15:24:58 -0200 | [diff] [blame] | 799 | case VIDIOCSFREQ32: |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 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: |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 816 | case VIDIOC_G_TUNER: |
| 817 | case VIDIOC_S_TUNER: |
| 818 | case VIDIOC_ENUMSTD: |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 819 | case VIDIOC_ENUMSTD32: |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 820 | case VIDIOC_ENUMINPUT: |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 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: |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 828 | ret = do_video_ioctl(file, cmd, arg); |
| 829 | break; |
| 830 | |
| 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: |
| 847 | |
| 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; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 859 | default: |
| 860 | v4l_print_ioctl("compat_ioctl32", cmd); |
MishalĂ… Pytasz | 97e2a01 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 861 | } |
Hans Verkuil | e8efb71 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 862 | return ret; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 863 | } |
| 864 | #else |
| 865 | long v4l_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg) |
| 866 | { |
| 867 | return -ENOIOCTLCMD; |
| 868 | } |
| 869 | #endif |
| 870 | EXPORT_SYMBOL_GPL(v4l_compat_ioctl32); |
Ricardo Cerqueira | 925e699 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 871 | |
| 872 | MODULE_LICENSE("GPL"); |