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/compat.h> |
| 16 | #include <linux/videodev.h> |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 17 | #include <linux/videodev2.h> |
Nickolay V. Shmyrev | 133b735 | 2006-01-09 15:24:58 -0200 | [diff] [blame] | 18 | #include <linux/module.h> |
Hans Verkuil | e8efb71 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 19 | #include <linux/smp_lock.h> |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 20 | #include <media/v4l2-common.h> |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 21 | |
| 22 | #ifdef CONFIG_COMPAT |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 23 | |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame^] | 24 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 25 | struct video_tuner32 { |
| 26 | compat_int_t tuner; |
| 27 | char name[32]; |
| 28 | compat_ulong_t rangelow, rangehigh; |
| 29 | u32 flags; /* It is really u32 in videodev.h */ |
| 30 | u16 mode, signal; |
| 31 | }; |
| 32 | |
| 33 | static int get_video_tuner32(struct video_tuner *kp, struct video_tuner32 __user *up) |
| 34 | { |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 35 | if(!access_ok(VERIFY_READ, up, sizeof(struct video_tuner32)) || |
| 36 | get_user(kp->tuner, &up->tuner) || |
| 37 | copy_from_user(kp->name, up->name, 32) || |
| 38 | get_user(kp->rangelow, &up->rangelow) || |
| 39 | get_user(kp->rangehigh, &up->rangehigh) || |
| 40 | get_user(kp->flags, &up->flags) || |
| 41 | get_user(kp->mode, &up->mode) || |
| 42 | get_user(kp->signal, &up->signal)) |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 43 | return -EFAULT; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 44 | return 0; |
| 45 | } |
| 46 | |
| 47 | static int put_video_tuner32(struct video_tuner *kp, struct video_tuner32 __user *up) |
| 48 | { |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 49 | if(!access_ok(VERIFY_WRITE, up, sizeof(struct video_tuner32)) || |
| 50 | put_user(kp->tuner, &up->tuner) || |
| 51 | copy_to_user(up->name, kp->name, 32) || |
| 52 | put_user(kp->rangelow, &up->rangelow) || |
| 53 | put_user(kp->rangehigh, &up->rangehigh) || |
| 54 | put_user(kp->flags, &up->flags) || |
| 55 | put_user(kp->mode, &up->mode) || |
| 56 | put_user(kp->signal, &up->signal)) |
| 57 | return -EFAULT; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | struct video_buffer32 { |
| 62 | compat_caddr_t base; |
| 63 | compat_int_t height, width, depth, bytesperline; |
| 64 | }; |
| 65 | |
| 66 | static int get_video_buffer32(struct video_buffer *kp, struct video_buffer32 __user *up) |
| 67 | { |
| 68 | u32 tmp; |
| 69 | |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 70 | if (!access_ok(VERIFY_READ, up, sizeof(struct video_buffer32)) || |
| 71 | get_user(tmp, &up->base) || |
| 72 | get_user(kp->height, &up->height) || |
| 73 | get_user(kp->width, &up->width) || |
| 74 | get_user(kp->depth, &up->depth) || |
| 75 | get_user(kp->bytesperline, &up->bytesperline)) |
| 76 | return -EFAULT; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 77 | |
| 78 | /* This is actually a physical address stored |
| 79 | * as a void pointer. |
| 80 | */ |
| 81 | kp->base = (void *)(unsigned long) tmp; |
| 82 | |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | static int put_video_buffer32(struct video_buffer *kp, struct video_buffer32 __user *up) |
| 87 | { |
| 88 | u32 tmp = (u32)((unsigned long)kp->base); |
| 89 | |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 90 | if(!access_ok(VERIFY_WRITE, up, sizeof(struct video_buffer32)) || |
| 91 | put_user(tmp, &up->base) || |
| 92 | put_user(kp->height, &up->height) || |
| 93 | put_user(kp->width, &up->width) || |
| 94 | put_user(kp->depth, &up->depth) || |
| 95 | put_user(kp->bytesperline, &up->bytesperline)) |
| 96 | return -EFAULT; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | struct video_clip32 { |
| 101 | s32 x, y, width, height; /* Its really s32 in videodev.h */ |
| 102 | compat_caddr_t next; |
| 103 | }; |
| 104 | |
| 105 | struct video_window32 { |
| 106 | u32 x, y, width, height, chromakey, flags; |
| 107 | compat_caddr_t clips; |
| 108 | compat_int_t clipcount; |
| 109 | }; |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame^] | 110 | #endif |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 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 | |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame^] | 128 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 129 | /* You get back everything except the clips... */ |
| 130 | static int put_video_window32(struct video_window *kp, struct video_window32 __user *up) |
| 131 | { |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 132 | if(!access_ok(VERIFY_WRITE, up, sizeof(struct video_window32)) || |
| 133 | put_user(kp->x, &up->x) || |
| 134 | put_user(kp->y, &up->y) || |
| 135 | put_user(kp->width, &up->width) || |
| 136 | put_user(kp->height, &up->height) || |
| 137 | put_user(kp->chromakey, &up->chromakey) || |
| 138 | put_user(kp->flags, &up->flags) || |
| 139 | put_user(kp->clipcount, &up->clipcount)) |
| 140 | return -EFAULT; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 141 | return 0; |
| 142 | } |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame^] | 143 | #endif |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 144 | |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 145 | struct v4l2_clip32 |
| 146 | { |
| 147 | struct v4l2_rect c; |
| 148 | compat_caddr_t next; |
| 149 | }; |
| 150 | |
| 151 | struct v4l2_window32 |
| 152 | { |
| 153 | struct v4l2_rect w; |
| 154 | enum v4l2_field field; |
| 155 | __u32 chromakey; |
| 156 | compat_caddr_t clips; /* actually struct v4l2_clip32 * */ |
| 157 | __u32 clipcount; |
| 158 | compat_caddr_t bitmap; |
| 159 | }; |
| 160 | |
| 161 | static int get_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 __user *up) |
| 162 | { |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 163 | if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_window32)) || |
| 164 | copy_from_user(&kp->w, &up->w, sizeof(up->w)) || |
| 165 | get_user(kp->field, &up->field) || |
| 166 | get_user(kp->chromakey, &up->chromakey) || |
| 167 | get_user(kp->clipcount, &up->clipcount)) |
| 168 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 169 | if (kp->clipcount > 2048) |
| 170 | return -EINVAL; |
| 171 | if (kp->clipcount) { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 172 | struct v4l2_clip32 __user *uclips; |
| 173 | struct v4l2_clip __user *kclips; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 174 | int n = kp->clipcount; |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 175 | compat_caddr_t p; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 176 | |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 177 | if (get_user(p, &up->clips)) |
| 178 | return -EFAULT; |
| 179 | uclips = compat_ptr(p); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 180 | kclips = compat_alloc_user_space(n * sizeof(struct v4l2_clip)); |
| 181 | kp->clips = kclips; |
| 182 | while (--n >= 0) { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 183 | if (copy_in_user(&kclips->c, &uclips->c, sizeof(uclips->c))) |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 184 | return -EFAULT; |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 185 | if (put_user(n ? kclips + 1 : NULL, &kclips->next)) |
| 186 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 187 | uclips += 1; |
| 188 | kclips += 1; |
| 189 | } |
| 190 | } else |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 191 | kp->clips = NULL; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 192 | return 0; |
| 193 | } |
| 194 | |
| 195 | static int put_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 __user *up) |
| 196 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 197 | if (copy_to_user(&up->w, &kp->w, sizeof(up->w)) || |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 198 | put_user(kp->field, &up->field) || |
| 199 | put_user(kp->chromakey, &up->chromakey) || |
| 200 | put_user(kp->clipcount, &up->clipcount)) |
| 201 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 202 | return 0; |
| 203 | } |
| 204 | |
| 205 | static inline int get_v4l2_pix_format(struct v4l2_pix_format *kp, struct v4l2_pix_format __user *up) |
| 206 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 207 | if (copy_from_user(kp, up, sizeof(struct v4l2_pix_format))) |
| 208 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 209 | return 0; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | static inline int put_v4l2_pix_format(struct v4l2_pix_format *kp, struct v4l2_pix_format __user *up) |
| 213 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 214 | if (copy_to_user(up, kp, sizeof(struct v4l2_pix_format))) |
| 215 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 216 | return 0; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | static inline int get_v4l2_vbi_format(struct v4l2_vbi_format *kp, struct v4l2_vbi_format __user *up) |
| 220 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 221 | if (copy_from_user(kp, up, sizeof(struct v4l2_vbi_format))) |
| 222 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 223 | return 0; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | static inline int put_v4l2_vbi_format(struct v4l2_vbi_format *kp, struct v4l2_vbi_format __user *up) |
| 227 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 228 | if (copy_to_user(up, kp, sizeof(struct v4l2_vbi_format))) |
| 229 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 230 | return 0; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | struct v4l2_format32 |
| 234 | { |
| 235 | enum v4l2_buf_type type; |
| 236 | union |
| 237 | { |
| 238 | struct v4l2_pix_format pix; // V4L2_BUF_TYPE_VIDEO_CAPTURE |
| 239 | struct v4l2_window32 win; // V4L2_BUF_TYPE_VIDEO_OVERLAY |
| 240 | struct v4l2_vbi_format vbi; // V4L2_BUF_TYPE_VBI_CAPTURE |
| 241 | __u8 raw_data[200]; // user-defined |
| 242 | } fmt; |
| 243 | }; |
| 244 | |
| 245 | static int get_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up) |
| 246 | { |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 247 | if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_format32)) || |
| 248 | get_user(kp->type, &up->type)) |
| 249 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 250 | switch (kp->type) { |
| 251 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
| 252 | return get_v4l2_pix_format(&kp->fmt.pix, &up->fmt.pix); |
| 253 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: |
| 254 | return get_v4l2_window32(&kp->fmt.win, &up->fmt.win); |
| 255 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
| 256 | return get_v4l2_vbi_format(&kp->fmt.vbi, &up->fmt.vbi); |
| 257 | default: |
| 258 | printk("compat_ioctl : unexpected VIDIOC_FMT type %d\n", |
| 259 | kp->type); |
| 260 | return -ENXIO; |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | static int put_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up) |
| 265 | { |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 266 | if(!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_format32)) || |
| 267 | put_user(kp->type, &up->type)) |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 268 | return -EFAULT; |
| 269 | switch (kp->type) { |
| 270 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
| 271 | return put_v4l2_pix_format(&kp->fmt.pix, &up->fmt.pix); |
| 272 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: |
| 273 | return put_v4l2_window32(&kp->fmt.win, &up->fmt.win); |
| 274 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
| 275 | return put_v4l2_vbi_format(&kp->fmt.vbi, &up->fmt.vbi); |
| 276 | default: |
| 277 | return -ENXIO; |
| 278 | } |
| 279 | } |
| 280 | |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 281 | static inline int get_v4l2_standard(struct v4l2_standard *kp, struct v4l2_standard __user *up) |
| 282 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 283 | if (copy_from_user(kp, up, sizeof(struct v4l2_standard))) |
| 284 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 285 | return 0; |
| 286 | |
| 287 | } |
| 288 | |
| 289 | static inline int put_v4l2_standard(struct v4l2_standard *kp, struct v4l2_standard __user *up) |
| 290 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 291 | if (copy_to_user(up, kp, sizeof(struct v4l2_standard))) |
| 292 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 293 | return 0; |
| 294 | } |
| 295 | |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 296 | struct v4l2_standard32 |
| 297 | { |
| 298 | __u32 index; |
| 299 | __u32 id[2]; /* __u64 would get the alignment wrong */ |
| 300 | __u8 name[24]; |
| 301 | struct v4l2_fract frameperiod; /* Frames, not fields */ |
| 302 | __u32 framelines; |
| 303 | __u32 reserved[4]; |
| 304 | }; |
| 305 | |
| 306 | static int get_v4l2_standard32(struct v4l2_standard *kp, struct v4l2_standard32 __user *up) |
| 307 | { |
| 308 | /* 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] | 309 | if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_standard32)) || |
| 310 | get_user(kp->index, &up->index)) |
| 311 | return -EFAULT; |
| 312 | return 0; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | static int put_v4l2_standard32(struct v4l2_standard *kp, struct v4l2_standard32 __user *up) |
| 316 | { |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 317 | if(!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_standard32)) || |
| 318 | put_user(kp->index, &up->index) || |
| 319 | copy_to_user(up->id, &kp->id, sizeof(__u64)) || |
| 320 | copy_to_user(up->name, kp->name, 24) || |
| 321 | copy_to_user(&up->frameperiod, &kp->frameperiod, sizeof(kp->frameperiod)) || |
| 322 | put_user(kp->framelines, &up->framelines) || |
| 323 | copy_to_user(up->reserved, kp->reserved, 4 * sizeof(__u32))) |
| 324 | return -EFAULT; |
| 325 | return 0; |
| 326 | } |
| 327 | |
| 328 | static inline int get_v4l2_tuner(struct v4l2_tuner *kp, struct v4l2_tuner __user *up) |
| 329 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 330 | if (copy_from_user(kp, up, sizeof(struct v4l2_tuner))) |
| 331 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 332 | return 0; |
| 333 | |
| 334 | } |
| 335 | |
| 336 | static inline int put_v4l2_tuner(struct v4l2_tuner *kp, struct v4l2_tuner __user *up) |
| 337 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 338 | if (copy_to_user(up, kp, sizeof(struct v4l2_tuner))) |
| 339 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 340 | return 0; |
| 341 | } |
| 342 | |
| 343 | struct v4l2_buffer32 |
| 344 | { |
| 345 | __u32 index; |
| 346 | enum v4l2_buf_type type; |
| 347 | __u32 bytesused; |
| 348 | __u32 flags; |
| 349 | enum v4l2_field field; |
| 350 | struct compat_timeval timestamp; |
| 351 | struct v4l2_timecode timecode; |
| 352 | __u32 sequence; |
| 353 | |
| 354 | /* memory location */ |
| 355 | enum v4l2_memory memory; |
| 356 | union { |
| 357 | __u32 offset; |
| 358 | compat_long_t userptr; |
| 359 | } m; |
| 360 | __u32 length; |
| 361 | __u32 input; |
| 362 | __u32 reserved; |
| 363 | }; |
| 364 | |
| 365 | static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user *up) |
| 366 | { |
| 367 | |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 368 | if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_buffer32)) || |
| 369 | get_user(kp->index, &up->index) || |
| 370 | get_user(kp->type, &up->type) || |
| 371 | get_user(kp->flags, &up->flags) || |
| 372 | get_user(kp->memory, &up->memory) || |
| 373 | get_user(kp->input, &up->input)) |
| 374 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 375 | switch(kp->memory) { |
| 376 | case V4L2_MEMORY_MMAP: |
| 377 | break; |
| 378 | case V4L2_MEMORY_USERPTR: |
| 379 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 380 | compat_long_t tmp; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 381 | |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 382 | if (get_user(kp->length, &up->length) || |
| 383 | get_user(tmp, &up->m.userptr)) |
| 384 | return -EFAULT; |
| 385 | |
| 386 | kp->m.userptr = (unsigned long)compat_ptr(tmp); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 387 | } |
| 388 | break; |
| 389 | case V4L2_MEMORY_OVERLAY: |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 390 | if(get_user(kp->m.offset, &up->m.offset)) |
| 391 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 392 | break; |
| 393 | } |
| 394 | return 0; |
| 395 | } |
| 396 | |
| 397 | static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user *up) |
| 398 | { |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 399 | if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_buffer32)) || |
| 400 | put_user(kp->index, &up->index) || |
| 401 | put_user(kp->type, &up->type) || |
| 402 | put_user(kp->flags, &up->flags) || |
| 403 | put_user(kp->memory, &up->memory) || |
| 404 | put_user(kp->input, &up->input)) |
| 405 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 406 | switch(kp->memory) { |
| 407 | case V4L2_MEMORY_MMAP: |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 408 | if (put_user(kp->length, &up->length) || |
| 409 | put_user(kp->m.offset, &up->m.offset)) |
| 410 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 411 | break; |
| 412 | case V4L2_MEMORY_USERPTR: |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 413 | if (put_user(kp->length, &up->length) || |
| 414 | put_user(kp->m.userptr, &up->m.userptr)) |
| 415 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 416 | break; |
| 417 | case V4L2_MEMORY_OVERLAY: |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 418 | if (put_user(kp->m.offset, &up->m.offset)) |
| 419 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 420 | break; |
| 421 | } |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 422 | if (put_user(kp->bytesused, &up->bytesused) || |
| 423 | put_user(kp->field, &up->field) || |
| 424 | put_user(kp->timestamp.tv_sec, &up->timestamp.tv_sec) || |
| 425 | put_user(kp->timestamp.tv_usec, &up->timestamp.tv_usec) || |
| 426 | copy_to_user(&up->timecode, &kp->timecode, sizeof(struct v4l2_timecode)) || |
| 427 | put_user(kp->sequence, &up->sequence) || |
| 428 | put_user(kp->reserved, &up->reserved)) |
| 429 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 430 | return 0; |
| 431 | } |
| 432 | |
| 433 | struct v4l2_framebuffer32 |
| 434 | { |
| 435 | __u32 capability; |
| 436 | __u32 flags; |
| 437 | compat_caddr_t base; |
| 438 | struct v4l2_pix_format fmt; |
| 439 | }; |
| 440 | |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 441 | static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_framebuffer32 __user *up) |
| 442 | { |
| 443 | u32 tmp; |
| 444 | |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 445 | if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_framebuffer32)) || |
| 446 | get_user(tmp, &up->base) || |
| 447 | get_user(kp->capability, &up->capability) || |
| 448 | get_user(kp->flags, &up->flags)) |
| 449 | return -EFAULT; |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 450 | kp->base = compat_ptr(tmp); |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 451 | get_v4l2_pix_format(&kp->fmt, &up->fmt); |
| 452 | return 0; |
| 453 | } |
| 454 | |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 455 | static int put_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_framebuffer32 __user *up) |
| 456 | { |
| 457 | u32 tmp = (u32)((unsigned long)kp->base); |
| 458 | |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 459 | if(!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_framebuffer32)) || |
| 460 | put_user(tmp, &up->base) || |
| 461 | put_user(kp->capability, &up->capability) || |
| 462 | put_user(kp->flags, &up->flags)) |
| 463 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 464 | put_v4l2_pix_format(&kp->fmt, &up->fmt); |
| 465 | return 0; |
| 466 | } |
| 467 | |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 468 | 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] | 469 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 470 | if (copy_from_user(kp, up, sizeof(struct v4l2_input) - 4)) |
| 471 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 472 | return 0; |
| 473 | } |
| 474 | |
| 475 | static inline int put_v4l2_input32(struct v4l2_input *kp, struct v4l2_input __user *up) |
| 476 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 477 | if (copy_to_user(up, kp, sizeof(struct v4l2_input) - 4)) |
| 478 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 479 | return 0; |
| 480 | } |
| 481 | |
| 482 | static inline int get_v4l2_input(struct v4l2_input *kp, struct v4l2_input __user *up) |
| 483 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 484 | if (copy_from_user(kp, up, sizeof(struct v4l2_input))) |
| 485 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 486 | return 0; |
| 487 | } |
| 488 | |
| 489 | static inline int put_v4l2_input(struct v4l2_input *kp, struct v4l2_input __user *up) |
| 490 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 491 | if (copy_to_user(up, kp, sizeof(struct v4l2_input))) |
| 492 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 493 | return 0; |
| 494 | } |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 495 | |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame^] | 496 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
Mauro Carvalho Chehab | eb4eecc | 2006-07-21 18:53:23 -0300 | [diff] [blame] | 497 | struct video_code32 |
| 498 | { |
| 499 | char loadwhat[16]; /* name or tag of file being passed */ |
| 500 | compat_int_t datasize; |
| 501 | unsigned char *data; |
| 502 | }; |
| 503 | |
| 504 | static inline int microcode32(struct video_code *kp, struct video_code32 __user *up) |
| 505 | { |
| 506 | if(!access_ok(VERIFY_READ, up, sizeof(struct video_code32)) || |
| 507 | copy_from_user(kp->loadwhat, up->loadwhat, sizeof (up->loadwhat)) || |
| 508 | get_user(kp->datasize, &up->datasize) || |
| 509 | copy_from_user(kp->data, up->data, up->datasize)) |
| 510 | return -EFAULT; |
| 511 | return 0; |
| 512 | } |
| 513 | |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 514 | #define VIDIOCGTUNER32 _IOWR('v',4, struct video_tuner32) |
| 515 | #define VIDIOCSTUNER32 _IOW('v',5, struct video_tuner32) |
| 516 | #define VIDIOCGWIN32 _IOR('v',9, struct video_window32) |
| 517 | #define VIDIOCSWIN32 _IOW('v',10, struct video_window32) |
| 518 | #define VIDIOCGFBUF32 _IOR('v',11, struct video_buffer32) |
| 519 | #define VIDIOCSFBUF32 _IOW('v',12, struct video_buffer32) |
| 520 | #define VIDIOCGFREQ32 _IOR('v',14, u32) |
| 521 | #define VIDIOCSFREQ32 _IOW('v',15, u32) |
Mauro Carvalho Chehab | eb4eecc | 2006-07-21 18:53:23 -0300 | [diff] [blame] | 522 | #define VIDIOCSMICROCODE32 _IOW('v',27, struct video_code32) |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 523 | |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame^] | 524 | #endif |
| 525 | |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 526 | /* VIDIOC_ENUMINPUT32 is VIDIOC_ENUMINPUT minus 4 bytes of padding alignement */ |
| 527 | #define VIDIOC_ENUMINPUT32 VIDIOC_ENUMINPUT - _IOC(0, 0, 0, 4) |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 528 | #define VIDIOC_G_FMT32 _IOWR ('V', 4, struct v4l2_format32) |
| 529 | #define VIDIOC_S_FMT32 _IOWR ('V', 5, struct v4l2_format32) |
| 530 | #define VIDIOC_QUERYBUF32 _IOWR ('V', 9, struct v4l2_buffer32) |
| 531 | #define VIDIOC_G_FBUF32 _IOR ('V', 10, struct v4l2_framebuffer32) |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 532 | #define VIDIOC_S_FBUF32 _IOW ('V', 11, struct v4l2_framebuffer32) |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 533 | /* VIDIOC_OVERLAY is now _IOW, but was _IOWR */ |
| 534 | #define VIDIOC_OVERLAY32 _IOWR ('V', 14, compat_int_t) |
| 535 | #define VIDIOC_QBUF32 _IOWR ('V', 15, struct v4l2_buffer32) |
| 536 | #define VIDIOC_DQBUF32 _IOWR ('V', 17, struct v4l2_buffer32) |
| 537 | #define VIDIOC_STREAMON32 _IOW ('V', 18, compat_int_t) |
| 538 | #define VIDIOC_STREAMOFF32 _IOW ('V', 19, compat_int_t) |
| 539 | #define VIDIOC_ENUMSTD32 _IOWR ('V', 25, struct v4l2_standard32) |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 540 | /* VIDIOC_S_CTRL is now _IOWR, but was _IOW */ |
| 541 | #define VIDIOC_S_CTRL32 _IOW ('V', 28, struct v4l2_control) |
| 542 | #define VIDIOC_G_INPUT32 _IOR ('V', 38, compat_int_t) |
| 543 | #define VIDIOC_S_INPUT32 _IOWR ('V', 39, compat_int_t) |
| 544 | #define VIDIOC_TRY_FMT32 _IOWR ('V', 64, struct v4l2_format32) |
| 545 | |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame^] | 546 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 547 | enum { |
| 548 | MaxClips = (~0U-sizeof(struct video_window))/sizeof(struct video_clip) |
| 549 | }; |
| 550 | |
| 551 | static int do_set_window(struct file *file, unsigned int cmd, unsigned long arg) |
| 552 | { |
| 553 | struct video_window32 __user *up = compat_ptr(arg); |
| 554 | struct video_window __user *vw; |
| 555 | struct video_clip __user *p; |
| 556 | int nclips; |
| 557 | u32 n; |
| 558 | |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 559 | if (!access_ok(VERIFY_READ, up, sizeof(struct video_window32))) |
| 560 | return -EFAULT; |
| 561 | |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 562 | if (get_user(nclips, &up->clipcount)) |
| 563 | return -EFAULT; |
| 564 | |
| 565 | /* Peculiar interface... */ |
| 566 | if (nclips < 0) |
| 567 | nclips = VIDEO_CLIPMAP_SIZE; |
| 568 | |
| 569 | if (nclips > MaxClips) |
| 570 | return -ENOMEM; |
| 571 | |
| 572 | vw = compat_alloc_user_space(sizeof(struct video_window) + |
| 573 | nclips * sizeof(struct video_clip)); |
| 574 | |
| 575 | p = nclips ? (struct video_clip __user *)(vw + 1) : NULL; |
| 576 | |
| 577 | if (get_user(n, &up->x) || put_user(n, &vw->x) || |
| 578 | get_user(n, &up->y) || put_user(n, &vw->y) || |
| 579 | get_user(n, &up->width) || put_user(n, &vw->width) || |
| 580 | get_user(n, &up->height) || put_user(n, &vw->height) || |
| 581 | get_user(n, &up->chromakey) || put_user(n, &vw->chromakey) || |
| 582 | get_user(n, &up->flags) || put_user(n, &vw->flags) || |
| 583 | get_user(n, &up->clipcount) || put_user(n, &vw->clipcount) || |
| 584 | get_user(n, &up->clips) || put_user(p, &vw->clips)) |
| 585 | return -EFAULT; |
| 586 | |
| 587 | if (nclips) { |
| 588 | struct video_clip32 __user *u = compat_ptr(n); |
| 589 | int i; |
| 590 | if (!u) |
| 591 | return -EINVAL; |
| 592 | for (i = 0; i < nclips; i++, u++, p++) { |
| 593 | s32 v; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 594 | if (!access_ok(VERIFY_READ, u, sizeof(struct video_clip32)) || |
| 595 | !access_ok(VERIFY_WRITE, p, sizeof(struct video_clip32)) || |
| 596 | get_user(v, &u->x) || |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 597 | put_user(v, &p->x) || |
| 598 | get_user(v, &u->y) || |
| 599 | put_user(v, &p->y) || |
| 600 | get_user(v, &u->width) || |
| 601 | put_user(v, &p->width) || |
| 602 | get_user(v, &u->height) || |
| 603 | put_user(v, &p->height) || |
| 604 | put_user(NULL, &p->next)) |
| 605 | return -EFAULT; |
| 606 | } |
| 607 | } |
| 608 | |
Guy Martin | 009494e | 2006-01-09 15:32:45 -0200 | [diff] [blame] | 609 | return native_ioctl(file, VIDIOCSWIN, (unsigned long)vw); |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 610 | } |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame^] | 611 | #endif |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 612 | |
| 613 | static int do_video_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 614 | { |
| 615 | union { |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame^] | 616 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 617 | struct video_tuner vt; |
| 618 | struct video_buffer vb; |
| 619 | struct video_window vw; |
Mauro Carvalho Chehab | eb4eecc | 2006-07-21 18:53:23 -0300 | [diff] [blame] | 620 | struct video_code vc; |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame^] | 621 | #endif |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 622 | struct v4l2_format v2f; |
| 623 | struct v4l2_buffer v2b; |
| 624 | struct v4l2_framebuffer v2fb; |
| 625 | struct v4l2_standard v2s; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 626 | struct v4l2_input v2i; |
| 627 | struct v4l2_tuner v2t; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 628 | unsigned long vx; |
| 629 | } karg; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 630 | void __user *up = compat_ptr(arg); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 631 | int compatible_arg = 1; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 632 | int err = 0; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 633 | int realcmd = cmd; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 634 | |
| 635 | /* First, convert the command. */ |
| 636 | switch(cmd) { |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame^] | 637 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 638 | case VIDIOCGTUNER32: cmd = VIDIOCGTUNER; break; |
| 639 | case VIDIOCSTUNER32: cmd = VIDIOCSTUNER; break; |
| 640 | case VIDIOCGWIN32: cmd = VIDIOCGWIN; break; |
| 641 | case VIDIOCGFBUF32: cmd = VIDIOCGFBUF; break; |
| 642 | case VIDIOCSFBUF32: cmd = VIDIOCSFBUF; break; |
| 643 | case VIDIOCGFREQ32: cmd = VIDIOCGFREQ; break; |
| 644 | case VIDIOCSFREQ32: cmd = VIDIOCSFREQ; break; |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame^] | 645 | case VIDIOCSMICROCODE32: cmd = VIDIOCSMICROCODE; break; |
| 646 | #endif |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 647 | case VIDIOC_G_FMT32: cmd = VIDIOC_G_FMT; break; |
| 648 | case VIDIOC_S_FMT32: cmd = VIDIOC_S_FMT; break; |
| 649 | case VIDIOC_QUERYBUF32: cmd = VIDIOC_QUERYBUF; break; |
| 650 | case VIDIOC_QBUF32: cmd = VIDIOC_QBUF; break; |
| 651 | case VIDIOC_DQBUF32: cmd = VIDIOC_DQBUF; break; |
| 652 | case VIDIOC_STREAMON32: cmd = VIDIOC_STREAMON; break; |
| 653 | case VIDIOC_STREAMOFF32: cmd = VIDIOC_STREAMOFF; break; |
| 654 | case VIDIOC_G_FBUF32: cmd = VIDIOC_G_FBUF; break; |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 655 | case VIDIOC_S_FBUF32: cmd = VIDIOC_S_FBUF; break; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 656 | case VIDIOC_OVERLAY32: cmd = VIDIOC_OVERLAY; break; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 657 | case VIDIOC_ENUMSTD32: realcmd = VIDIOC_ENUMSTD; break; |
| 658 | case VIDIOC_ENUMINPUT32: realcmd = VIDIOC_ENUMINPUT; break; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 659 | case VIDIOC_S_CTRL32: cmd = VIDIOC_S_CTRL; break; |
| 660 | case VIDIOC_G_INPUT32: cmd = VIDIOC_G_INPUT; break; |
| 661 | case VIDIOC_S_INPUT32: cmd = VIDIOC_S_INPUT; break; |
| 662 | case VIDIOC_TRY_FMT32: cmd = VIDIOC_TRY_FMT; break; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 663 | }; |
| 664 | |
| 665 | switch(cmd) { |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame^] | 666 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 667 | case VIDIOCSTUNER: |
| 668 | case VIDIOCGTUNER: |
| 669 | err = get_video_tuner32(&karg.vt, up); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 670 | compatible_arg = 0; |
| 671 | |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 672 | break; |
| 673 | |
| 674 | case VIDIOCSFBUF: |
| 675 | err = get_video_buffer32(&karg.vb, up); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 676 | compatible_arg = 0; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 677 | break; |
| 678 | |
| 679 | case VIDIOCSFREQ: |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame^] | 680 | #endif |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 681 | case VIDIOC_S_INPUT: |
| 682 | case VIDIOC_OVERLAY: |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 683 | case VIDIOC_STREAMON: |
| 684 | case VIDIOC_STREAMOFF: |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 685 | err = get_user(karg.vx, (u32 __user *)up); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 686 | compatible_arg = 0; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 687 | break; |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 688 | |
| 689 | case VIDIOC_S_FBUF: |
| 690 | err = get_v4l2_framebuffer32(&karg.v2fb, up); |
| 691 | compatible_arg = 0; |
| 692 | break; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 693 | |
| 694 | case VIDIOC_G_FMT: |
| 695 | case VIDIOC_S_FMT: |
| 696 | case VIDIOC_TRY_FMT: |
| 697 | err = get_v4l2_format32(&karg.v2f, up); |
| 698 | compatible_arg = 0; |
| 699 | break; |
| 700 | |
| 701 | case VIDIOC_QUERYBUF: |
| 702 | case VIDIOC_QBUF: |
| 703 | case VIDIOC_DQBUF: |
| 704 | err = get_v4l2_buffer32(&karg.v2b, up); |
| 705 | compatible_arg = 0; |
| 706 | break; |
| 707 | |
| 708 | case VIDIOC_ENUMSTD: |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 709 | err = get_v4l2_standard(&karg.v2s, up); |
| 710 | compatible_arg = 0; |
| 711 | break; |
| 712 | |
| 713 | case VIDIOC_ENUMSTD32: |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 714 | err = get_v4l2_standard32(&karg.v2s, up); |
| 715 | compatible_arg = 0; |
| 716 | break; |
| 717 | |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 718 | case VIDIOC_ENUMINPUT: |
| 719 | err = get_v4l2_input(&karg.v2i, up); |
| 720 | compatible_arg = 0; |
| 721 | break; |
| 722 | |
| 723 | case VIDIOC_ENUMINPUT32: |
| 724 | err = get_v4l2_input32(&karg.v2i, up); |
| 725 | compatible_arg = 0; |
| 726 | break; |
| 727 | |
| 728 | case VIDIOC_G_TUNER: |
| 729 | case VIDIOC_S_TUNER: |
| 730 | err = get_v4l2_tuner(&karg.v2t, up); |
| 731 | compatible_arg = 0; |
| 732 | break; |
| 733 | |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame^] | 734 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 735 | case VIDIOCGWIN: |
| 736 | case VIDIOCGFBUF: |
| 737 | case VIDIOCGFREQ: |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame^] | 738 | #endif |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 739 | case VIDIOC_G_FBUF: |
| 740 | case VIDIOC_G_INPUT: |
| 741 | compatible_arg = 0; |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame^] | 742 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
Mauro Carvalho Chehab | eb4eecc | 2006-07-21 18:53:23 -0300 | [diff] [blame] | 743 | case VIDIOCSMICROCODE: |
| 744 | err = microcode32(&karg.vc, up); |
| 745 | compatible_arg = 0; |
| 746 | break; |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame^] | 747 | #endif |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 748 | }; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 749 | if(err) |
| 750 | goto out; |
| 751 | |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 752 | if(compatible_arg) |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 753 | err = native_ioctl(file, realcmd, (unsigned long)up); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 754 | else { |
| 755 | mm_segment_t old_fs = get_fs(); |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 756 | |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 757 | set_fs(KERNEL_DS); |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 758 | err = native_ioctl(file, realcmd, (unsigned long)&karg); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 759 | set_fs(old_fs); |
| 760 | } |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 761 | if(err == 0) { |
| 762 | switch(cmd) { |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame^] | 763 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 764 | case VIDIOCGTUNER: |
| 765 | err = put_video_tuner32(&karg.vt, up); |
| 766 | break; |
| 767 | |
| 768 | case VIDIOCGWIN: |
| 769 | err = put_video_window32(&karg.vw, up); |
| 770 | break; |
| 771 | |
| 772 | case VIDIOCGFBUF: |
| 773 | err = put_video_buffer32(&karg.vb, up); |
| 774 | break; |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame^] | 775 | #endif |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 776 | case VIDIOC_G_FBUF: |
| 777 | err = put_v4l2_framebuffer32(&karg.v2fb, up); |
| 778 | break; |
| 779 | |
| 780 | case VIDIOC_G_FMT: |
| 781 | case VIDIOC_S_FMT: |
| 782 | case VIDIOC_TRY_FMT: |
| 783 | err = put_v4l2_format32(&karg.v2f, up); |
| 784 | break; |
| 785 | |
| 786 | case VIDIOC_QUERYBUF: |
| 787 | case VIDIOC_QBUF: |
| 788 | case VIDIOC_DQBUF: |
| 789 | err = put_v4l2_buffer32(&karg.v2b, up); |
| 790 | break; |
| 791 | |
| 792 | case VIDIOC_ENUMSTD: |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 793 | err = put_v4l2_standard(&karg.v2s, up); |
| 794 | break; |
| 795 | |
| 796 | case VIDIOC_ENUMSTD32: |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 797 | err = put_v4l2_standard32(&karg.v2s, up); |
| 798 | break; |
| 799 | |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 800 | case VIDIOC_G_TUNER: |
| 801 | case VIDIOC_S_TUNER: |
| 802 | err = put_v4l2_tuner(&karg.v2t, up); |
| 803 | break; |
| 804 | |
| 805 | case VIDIOC_ENUMINPUT: |
| 806 | err = put_v4l2_input(&karg.v2i, up); |
| 807 | break; |
| 808 | |
| 809 | case VIDIOC_ENUMINPUT32: |
| 810 | err = put_v4l2_input32(&karg.v2i, up); |
| 811 | break; |
| 812 | |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame^] | 813 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 814 | case VIDIOCGFREQ: |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame^] | 815 | #endif |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 816 | case VIDIOC_G_INPUT: |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 817 | err = put_user(((u32)karg.vx), (u32 __user *)up); |
| 818 | break; |
| 819 | }; |
| 820 | } |
| 821 | out: |
| 822 | return err; |
| 823 | } |
| 824 | |
| 825 | long v4l_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg) |
| 826 | { |
| 827 | int ret = -ENOIOCTLCMD; |
| 828 | |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 829 | if (!file->f_op->ioctl) |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 830 | return ret; |
| 831 | |
| 832 | switch (cmd) { |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame^] | 833 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 834 | case VIDIOCSWIN32: |
| 835 | ret = do_set_window(file, cmd, arg); |
| 836 | break; |
| 837 | case VIDIOCGTUNER32: |
| 838 | case VIDIOCSTUNER32: |
| 839 | case VIDIOCGWIN32: |
| 840 | case VIDIOCGFBUF32: |
| 841 | case VIDIOCSFBUF32: |
| 842 | case VIDIOCGFREQ32: |
Nickolay V. Shmyrev | 133b735 | 2006-01-09 15:24:58 -0200 | [diff] [blame] | 843 | case VIDIOCSFREQ32: |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame^] | 844 | #endif |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 845 | case VIDIOC_QUERYCAP: |
| 846 | case VIDIOC_ENUM_FMT: |
| 847 | case VIDIOC_G_FMT32: |
| 848 | case VIDIOC_S_FMT32: |
| 849 | case VIDIOC_REQBUFS: |
| 850 | case VIDIOC_QUERYBUF32: |
| 851 | case VIDIOC_G_FBUF32: |
| 852 | case VIDIOC_S_FBUF32: |
| 853 | case VIDIOC_OVERLAY32: |
| 854 | case VIDIOC_QBUF32: |
| 855 | case VIDIOC_DQBUF32: |
| 856 | case VIDIOC_STREAMON32: |
| 857 | case VIDIOC_STREAMOFF32: |
| 858 | case VIDIOC_G_PARM: |
| 859 | case VIDIOC_G_STD: |
| 860 | case VIDIOC_S_STD: |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 861 | case VIDIOC_G_TUNER: |
| 862 | case VIDIOC_S_TUNER: |
| 863 | case VIDIOC_ENUMSTD: |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 864 | case VIDIOC_ENUMSTD32: |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 865 | case VIDIOC_ENUMINPUT: |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 866 | case VIDIOC_ENUMINPUT32: |
| 867 | case VIDIOC_G_CTRL: |
| 868 | case VIDIOC_S_CTRL32: |
| 869 | case VIDIOC_QUERYCTRL: |
| 870 | case VIDIOC_G_INPUT32: |
| 871 | case VIDIOC_S_INPUT32: |
| 872 | case VIDIOC_TRY_FMT32: |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 873 | ret = do_video_ioctl(file, cmd, arg); |
| 874 | break; |
| 875 | |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame^] | 876 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 877 | /* Little v, the video4linux ioctls (conflict?) */ |
| 878 | case VIDIOCGCAP: |
| 879 | case VIDIOCGCHAN: |
| 880 | case VIDIOCSCHAN: |
| 881 | case VIDIOCGPICT: |
| 882 | case VIDIOCSPICT: |
| 883 | case VIDIOCCAPTURE: |
| 884 | case VIDIOCKEY: |
| 885 | case VIDIOCGAUDIO: |
| 886 | case VIDIOCSAUDIO: |
| 887 | case VIDIOCSYNC: |
| 888 | case VIDIOCMCAPTURE: |
| 889 | case VIDIOCGMBUF: |
| 890 | case VIDIOCGUNIT: |
| 891 | case VIDIOCGCAPTURE: |
| 892 | case VIDIOCSCAPTURE: |
| 893 | |
| 894 | /* BTTV specific... */ |
| 895 | case _IOW('v', BASE_VIDIOCPRIVATE+0, char [256]): |
| 896 | case _IOR('v', BASE_VIDIOCPRIVATE+1, char [256]): |
| 897 | case _IOR('v' , BASE_VIDIOCPRIVATE+2, unsigned int): |
| 898 | case _IOW('v' , BASE_VIDIOCPRIVATE+3, char [16]): /* struct bttv_pll_info */ |
| 899 | case _IOR('v' , BASE_VIDIOCPRIVATE+4, int): |
| 900 | case _IOR('v' , BASE_VIDIOCPRIVATE+5, int): |
| 901 | case _IOR('v' , BASE_VIDIOCPRIVATE+6, int): |
| 902 | case _IOR('v' , BASE_VIDIOCPRIVATE+7, int): |
| 903 | ret = native_ioctl(file, cmd, (unsigned long)compat_ptr(arg)); |
| 904 | break; |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame^] | 905 | #endif |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 906 | default: |
| 907 | v4l_print_ioctl("compat_ioctl32", cmd); |
MishalĂ… Pytasz | 97e2a01 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 908 | } |
Hans Verkuil | e8efb71 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 909 | return ret; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 910 | } |
| 911 | #else |
| 912 | long v4l_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg) |
| 913 | { |
| 914 | return -ENOIOCTLCMD; |
| 915 | } |
| 916 | #endif |
| 917 | EXPORT_SYMBOL_GPL(v4l_compat_ioctl32); |
Ricardo Cerqueira | 925e699 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 918 | |
| 919 | MODULE_LICENSE("GPL"); |