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 |
Pavel Machek | a253129 | 2010-07-18 14:27:13 +0200 | [diff] [blame] | 8 | * Copyright (C) 2003 Pavel Machek (pavel@ucw.cz) |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 9 | * Copyright (C) 2005 Philippe De Muyter (phdm@macqel.be) |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 10 | * Copyright (C) 2008 Hans Verkuil <hverkuil@xs4all.nl> |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 11 | * |
| 12 | * These routines maintain argument size conversion between 32bit and 64bit |
| 13 | * ioctls. |
| 14 | */ |
| 15 | |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 16 | #include <linux/compat.h> |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 17 | #define __OLD_VIDIOC_ /* To allow fixing old calls*/ |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 18 | #include <linux/videodev.h> |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 19 | #include <linux/videodev2.h> |
Nickolay V. Shmyrev | 133b735 | 2006-01-09 15:24:58 -0200 | [diff] [blame] | 20 | #include <linux/module.h> |
Hans Verkuil | e8efb71 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 21 | #include <linux/smp_lock.h> |
Mauro Carvalho Chehab | 2864462 | 2008-07-20 20:26:54 -0300 | [diff] [blame] | 22 | #include <media/v4l2-ioctl.h> |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 23 | |
| 24 | #ifdef CONFIG_COMPAT |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 25 | |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame] | 26 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 27 | struct video_tuner32 { |
| 28 | compat_int_t tuner; |
| 29 | char name[32]; |
| 30 | compat_ulong_t rangelow, rangehigh; |
| 31 | u32 flags; /* It is really u32 in videodev.h */ |
| 32 | u16 mode, signal; |
| 33 | }; |
| 34 | |
| 35 | static int get_video_tuner32(struct video_tuner *kp, struct video_tuner32 __user *up) |
| 36 | { |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 37 | if (!access_ok(VERIFY_READ, up, sizeof(struct video_tuner32)) || |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 38 | get_user(kp->tuner, &up->tuner) || |
| 39 | copy_from_user(kp->name, up->name, 32) || |
| 40 | get_user(kp->rangelow, &up->rangelow) || |
| 41 | get_user(kp->rangehigh, &up->rangehigh) || |
| 42 | get_user(kp->flags, &up->flags) || |
| 43 | get_user(kp->mode, &up->mode) || |
| 44 | get_user(kp->signal, &up->signal)) |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 45 | return -EFAULT; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | static int put_video_tuner32(struct video_tuner *kp, struct video_tuner32 __user *up) |
| 50 | { |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 51 | if (!access_ok(VERIFY_WRITE, up, sizeof(struct video_tuner32)) || |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 52 | put_user(kp->tuner, &up->tuner) || |
| 53 | copy_to_user(up->name, kp->name, 32) || |
| 54 | put_user(kp->rangelow, &up->rangelow) || |
| 55 | put_user(kp->rangehigh, &up->rangehigh) || |
| 56 | put_user(kp->flags, &up->flags) || |
| 57 | put_user(kp->mode, &up->mode) || |
| 58 | put_user(kp->signal, &up->signal)) |
| 59 | return -EFAULT; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | struct video_buffer32 { |
| 64 | compat_caddr_t base; |
| 65 | compat_int_t height, width, depth, bytesperline; |
| 66 | }; |
| 67 | |
| 68 | static int get_video_buffer32(struct video_buffer *kp, struct video_buffer32 __user *up) |
| 69 | { |
| 70 | u32 tmp; |
| 71 | |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 72 | if (!access_ok(VERIFY_READ, up, sizeof(struct video_buffer32)) || |
| 73 | get_user(tmp, &up->base) || |
| 74 | get_user(kp->height, &up->height) || |
| 75 | get_user(kp->width, &up->width) || |
| 76 | get_user(kp->depth, &up->depth) || |
| 77 | get_user(kp->bytesperline, &up->bytesperline)) |
| 78 | return -EFAULT; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 79 | |
| 80 | /* This is actually a physical address stored |
| 81 | * as a void pointer. |
| 82 | */ |
| 83 | kp->base = (void *)(unsigned long) tmp; |
| 84 | |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | static int put_video_buffer32(struct video_buffer *kp, struct video_buffer32 __user *up) |
| 89 | { |
| 90 | u32 tmp = (u32)((unsigned long)kp->base); |
| 91 | |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 92 | if (!access_ok(VERIFY_WRITE, up, sizeof(struct video_buffer32)) || |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 93 | put_user(tmp, &up->base) || |
| 94 | put_user(kp->height, &up->height) || |
| 95 | put_user(kp->width, &up->width) || |
| 96 | put_user(kp->depth, &up->depth) || |
| 97 | put_user(kp->bytesperline, &up->bytesperline)) |
| 98 | return -EFAULT; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | struct video_clip32 { |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 103 | s32 x, y, width, height; /* It's really s32 in videodev.h */ |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 104 | compat_caddr_t next; |
| 105 | }; |
| 106 | |
| 107 | struct video_window32 { |
| 108 | u32 x, y, width, height, chromakey, flags; |
| 109 | compat_caddr_t clips; |
| 110 | compat_int_t clipcount; |
| 111 | }; |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 112 | |
| 113 | static int get_video_window32(struct video_window *kp, struct video_window32 __user *up) |
| 114 | { |
| 115 | struct video_clip __user *uclips; |
| 116 | struct video_clip __user *kclips; |
| 117 | compat_caddr_t p; |
| 118 | int nclips; |
| 119 | |
| 120 | if (!access_ok(VERIFY_READ, up, sizeof(struct video_window32))) |
| 121 | return -EFAULT; |
| 122 | |
| 123 | if (get_user(nclips, &up->clipcount)) |
| 124 | return -EFAULT; |
| 125 | |
| 126 | if (!access_ok(VERIFY_READ, up, sizeof(struct video_window32)) || |
| 127 | get_user(kp->x, &up->x) || |
| 128 | get_user(kp->y, &up->y) || |
| 129 | get_user(kp->width, &up->width) || |
| 130 | get_user(kp->height, &up->height) || |
| 131 | get_user(kp->chromakey, &up->chromakey) || |
| 132 | get_user(kp->flags, &up->flags) || |
| 133 | get_user(kp->clipcount, &up->clipcount)) |
| 134 | return -EFAULT; |
| 135 | |
| 136 | nclips = kp->clipcount; |
| 137 | kp->clips = NULL; |
| 138 | |
| 139 | if (nclips == 0) |
| 140 | return 0; |
| 141 | if (get_user(p, &up->clips)) |
| 142 | return -EFAULT; |
| 143 | uclips = compat_ptr(p); |
| 144 | |
| 145 | /* If nclips < 0, then it is a clipping bitmap of size |
| 146 | VIDEO_CLIPMAP_SIZE */ |
| 147 | if (nclips < 0) { |
| 148 | if (!access_ok(VERIFY_READ, uclips, VIDEO_CLIPMAP_SIZE)) |
| 149 | return -EFAULT; |
| 150 | kp->clips = compat_alloc_user_space(VIDEO_CLIPMAP_SIZE); |
| 151 | if (copy_in_user(kp->clips, uclips, VIDEO_CLIPMAP_SIZE)) |
| 152 | return -EFAULT; |
| 153 | return 0; |
| 154 | } |
| 155 | |
| 156 | /* Otherwise it is an array of video_clip structs. */ |
| 157 | if (!access_ok(VERIFY_READ, uclips, nclips * sizeof(struct video_clip))) |
| 158 | return -EFAULT; |
| 159 | |
| 160 | kp->clips = compat_alloc_user_space(nclips * sizeof(struct video_clip)); |
| 161 | kclips = kp->clips; |
| 162 | while (nclips--) { |
| 163 | int err; |
| 164 | |
| 165 | err = copy_in_user(&kclips->x, &uclips->x, sizeof(kclips->x)); |
| 166 | err |= copy_in_user(&kclips->y, &uclips->y, sizeof(kclips->y)); |
| 167 | err |= copy_in_user(&kclips->width, &uclips->width, sizeof(kclips->width)); |
| 168 | err |= copy_in_user(&kclips->height, &uclips->height, sizeof(kclips->height)); |
| 169 | kclips->next = NULL; |
| 170 | if (err) |
| 171 | return -EFAULT; |
| 172 | kclips++; |
| 173 | uclips++; |
| 174 | } |
| 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | /* You get back everything except the clips... */ |
| 179 | static int put_video_window32(struct video_window *kp, struct video_window32 __user *up) |
| 180 | { |
| 181 | if (!access_ok(VERIFY_WRITE, up, sizeof(struct video_window32)) || |
| 182 | put_user(kp->x, &up->x) || |
| 183 | put_user(kp->y, &up->y) || |
| 184 | put_user(kp->width, &up->width) || |
| 185 | put_user(kp->height, &up->height) || |
| 186 | put_user(kp->chromakey, &up->chromakey) || |
| 187 | put_user(kp->flags, &up->flags) || |
| 188 | put_user(kp->clipcount, &up->clipcount)) |
| 189 | return -EFAULT; |
| 190 | return 0; |
| 191 | } |
| 192 | |
| 193 | struct video_code32 { |
| 194 | char loadwhat[16]; /* name or tag of file being passed */ |
| 195 | compat_int_t datasize; |
| 196 | unsigned char *data; |
| 197 | }; |
| 198 | |
| 199 | static int get_microcode32(struct video_code *kp, struct video_code32 __user *up) |
| 200 | { |
| 201 | if (!access_ok(VERIFY_READ, up, sizeof(struct video_code32)) || |
| 202 | copy_from_user(kp->loadwhat, up->loadwhat, sizeof(up->loadwhat)) || |
| 203 | get_user(kp->datasize, &up->datasize) || |
| 204 | copy_from_user(kp->data, up->data, up->datasize)) |
| 205 | return -EFAULT; |
| 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | #define VIDIOCGTUNER32 _IOWR('v', 4, struct video_tuner32) |
| 210 | #define VIDIOCSTUNER32 _IOW('v', 5, struct video_tuner32) |
| 211 | #define VIDIOCGWIN32 _IOR('v', 9, struct video_window32) |
| 212 | #define VIDIOCSWIN32 _IOW('v', 10, struct video_window32) |
| 213 | #define VIDIOCGFBUF32 _IOR('v', 11, struct video_buffer32) |
| 214 | #define VIDIOCSFBUF32 _IOW('v', 12, struct video_buffer32) |
| 215 | #define VIDIOCGFREQ32 _IOR('v', 14, u32) |
| 216 | #define VIDIOCSFREQ32 _IOW('v', 15, u32) |
| 217 | #define VIDIOCSMICROCODE32 _IOW('v', 27, struct video_code32) |
| 218 | |
| 219 | #define VIDIOCCAPTURE32 _IOW('v', 8, s32) |
| 220 | #define VIDIOCSYNC32 _IOW('v', 18, s32) |
| 221 | #define VIDIOCSWRITEMODE32 _IOW('v', 25, s32) |
| 222 | |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame] | 223 | #endif |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 224 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 225 | static long native_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 226 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 227 | long ret = -ENOIOCTLCMD; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 228 | |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 229 | if (file->f_op->unlocked_ioctl) |
| 230 | ret = file->f_op->unlocked_ioctl(file, cmd, arg); |
| 231 | else if (file->f_op->ioctl) { |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 232 | lock_kernel(); |
Josef Sipek | 723731b | 2006-12-08 02:37:47 -0800 | [diff] [blame] | 233 | ret = file->f_op->ioctl(file->f_path.dentry->d_inode, file, cmd, arg); |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 234 | unlock_kernel(); |
| 235 | } |
| 236 | |
| 237 | return ret; |
| 238 | } |
| 239 | |
| 240 | |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 241 | struct v4l2_clip32 { |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 242 | struct v4l2_rect c; |
| 243 | compat_caddr_t next; |
| 244 | }; |
| 245 | |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 246 | struct v4l2_window32 { |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 247 | struct v4l2_rect w; |
| 248 | enum v4l2_field field; |
| 249 | __u32 chromakey; |
| 250 | compat_caddr_t clips; /* actually struct v4l2_clip32 * */ |
| 251 | __u32 clipcount; |
| 252 | compat_caddr_t bitmap; |
| 253 | }; |
| 254 | |
| 255 | static int get_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 __user *up) |
| 256 | { |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 257 | if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_window32)) || |
| 258 | copy_from_user(&kp->w, &up->w, sizeof(up->w)) || |
| 259 | get_user(kp->field, &up->field) || |
| 260 | get_user(kp->chromakey, &up->chromakey) || |
| 261 | get_user(kp->clipcount, &up->clipcount)) |
| 262 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 263 | if (kp->clipcount > 2048) |
| 264 | return -EINVAL; |
| 265 | if (kp->clipcount) { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 266 | struct v4l2_clip32 __user *uclips; |
| 267 | struct v4l2_clip __user *kclips; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 268 | int n = kp->clipcount; |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 269 | compat_caddr_t p; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 270 | |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 271 | if (get_user(p, &up->clips)) |
| 272 | return -EFAULT; |
| 273 | uclips = compat_ptr(p); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 274 | kclips = compat_alloc_user_space(n * sizeof(struct v4l2_clip)); |
| 275 | kp->clips = kclips; |
| 276 | while (--n >= 0) { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 277 | if (copy_in_user(&kclips->c, &uclips->c, sizeof(uclips->c))) |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 278 | return -EFAULT; |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 279 | if (put_user(n ? kclips + 1 : NULL, &kclips->next)) |
| 280 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 281 | uclips += 1; |
| 282 | kclips += 1; |
| 283 | } |
| 284 | } else |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 285 | kp->clips = NULL; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 286 | return 0; |
| 287 | } |
| 288 | |
| 289 | static int put_v4l2_window32(struct v4l2_window *kp, struct v4l2_window32 __user *up) |
| 290 | { |
Roel Kluin | f2e6c6a | 2009-12-16 11:35:45 -0300 | [diff] [blame] | 291 | if (copy_to_user(&up->w, &kp->w, sizeof(kp->w)) || |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 292 | put_user(kp->field, &up->field) || |
| 293 | put_user(kp->chromakey, &up->chromakey) || |
| 294 | put_user(kp->clipcount, &up->clipcount)) |
| 295 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 296 | return 0; |
| 297 | } |
| 298 | |
| 299 | static inline int get_v4l2_pix_format(struct v4l2_pix_format *kp, struct v4l2_pix_format __user *up) |
| 300 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 301 | if (copy_from_user(kp, up, sizeof(struct v4l2_pix_format))) |
| 302 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 303 | return 0; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | static inline int put_v4l2_pix_format(struct v4l2_pix_format *kp, struct v4l2_pix_format __user *up) |
| 307 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 308 | if (copy_to_user(up, kp, sizeof(struct v4l2_pix_format))) |
| 309 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 310 | return 0; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | static inline int get_v4l2_vbi_format(struct v4l2_vbi_format *kp, struct v4l2_vbi_format __user *up) |
| 314 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 315 | if (copy_from_user(kp, up, sizeof(struct v4l2_vbi_format))) |
| 316 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 317 | return 0; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | static inline int put_v4l2_vbi_format(struct v4l2_vbi_format *kp, struct v4l2_vbi_format __user *up) |
| 321 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 322 | if (copy_to_user(up, kp, sizeof(struct v4l2_vbi_format))) |
| 323 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 324 | return 0; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 325 | } |
| 326 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 327 | static inline int get_v4l2_sliced_vbi_format(struct v4l2_sliced_vbi_format *kp, struct v4l2_sliced_vbi_format __user *up) |
| 328 | { |
| 329 | if (copy_from_user(kp, up, sizeof(struct v4l2_sliced_vbi_format))) |
| 330 | return -EFAULT; |
| 331 | return 0; |
| 332 | } |
| 333 | |
| 334 | static inline int put_v4l2_sliced_vbi_format(struct v4l2_sliced_vbi_format *kp, struct v4l2_sliced_vbi_format __user *up) |
| 335 | { |
| 336 | if (copy_to_user(up, kp, sizeof(struct v4l2_sliced_vbi_format))) |
| 337 | return -EFAULT; |
| 338 | return 0; |
| 339 | } |
| 340 | |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 341 | struct v4l2_format32 { |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 342 | enum v4l2_buf_type type; |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 343 | union { |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 344 | struct v4l2_pix_format pix; |
| 345 | struct v4l2_window32 win; |
| 346 | struct v4l2_vbi_format vbi; |
| 347 | struct v4l2_sliced_vbi_format sliced; |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 348 | __u8 raw_data[200]; /* user-defined */ |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 349 | } fmt; |
| 350 | }; |
| 351 | |
| 352 | static int get_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up) |
| 353 | { |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 354 | if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_format32)) || |
| 355 | get_user(kp->type, &up->type)) |
| 356 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 357 | switch (kp->type) { |
| 358 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 359 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 360 | return get_v4l2_pix_format(&kp->fmt.pix, &up->fmt.pix); |
| 361 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 362 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 363 | return get_v4l2_window32(&kp->fmt.win, &up->fmt.win); |
| 364 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 365 | case V4L2_BUF_TYPE_VBI_OUTPUT: |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 366 | return get_v4l2_vbi_format(&kp->fmt.vbi, &up->fmt.vbi); |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 367 | case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: |
| 368 | case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: |
| 369 | return get_v4l2_sliced_vbi_format(&kp->fmt.sliced, &up->fmt.sliced); |
| 370 | case V4L2_BUF_TYPE_PRIVATE: |
| 371 | if (copy_from_user(kp, up, sizeof(kp->fmt.raw_data))) |
| 372 | return -EFAULT; |
| 373 | return 0; |
| 374 | case 0: |
| 375 | return -EINVAL; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 376 | default: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 377 | printk(KERN_INFO "compat_ioctl32: unexpected VIDIOC_FMT type %d\n", |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 378 | kp->type); |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 379 | return -EINVAL; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 380 | } |
| 381 | } |
| 382 | |
| 383 | static int put_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up) |
| 384 | { |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 385 | if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_format32)) || |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 386 | put_user(kp->type, &up->type)) |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 387 | return -EFAULT; |
| 388 | switch (kp->type) { |
| 389 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 390 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 391 | return put_v4l2_pix_format(&kp->fmt.pix, &up->fmt.pix); |
| 392 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 393 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 394 | return put_v4l2_window32(&kp->fmt.win, &up->fmt.win); |
| 395 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 396 | case V4L2_BUF_TYPE_VBI_OUTPUT: |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 397 | return put_v4l2_vbi_format(&kp->fmt.vbi, &up->fmt.vbi); |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 398 | case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: |
| 399 | case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: |
| 400 | return put_v4l2_sliced_vbi_format(&kp->fmt.sliced, &up->fmt.sliced); |
| 401 | case V4L2_BUF_TYPE_PRIVATE: |
| 402 | if (copy_to_user(up, kp, sizeof(up->fmt.raw_data))) |
| 403 | return -EFAULT; |
| 404 | return 0; |
| 405 | case 0: |
| 406 | return -EINVAL; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 407 | default: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 408 | printk(KERN_INFO "compat_ioctl32: unexpected VIDIOC_FMT type %d\n", |
| 409 | kp->type); |
| 410 | return -EINVAL; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 411 | } |
| 412 | } |
| 413 | |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 414 | struct v4l2_standard32 { |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 415 | __u32 index; |
| 416 | __u32 id[2]; /* __u64 would get the alignment wrong */ |
| 417 | __u8 name[24]; |
| 418 | struct v4l2_fract frameperiod; /* Frames, not fields */ |
| 419 | __u32 framelines; |
| 420 | __u32 reserved[4]; |
| 421 | }; |
| 422 | |
| 423 | static int get_v4l2_standard32(struct v4l2_standard *kp, struct v4l2_standard32 __user *up) |
| 424 | { |
| 425 | /* 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] | 426 | if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_standard32)) || |
| 427 | get_user(kp->index, &up->index)) |
| 428 | return -EFAULT; |
| 429 | return 0; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | static int put_v4l2_standard32(struct v4l2_standard *kp, struct v4l2_standard32 __user *up) |
| 433 | { |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 434 | if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_standard32)) || |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 435 | put_user(kp->index, &up->index) || |
| 436 | copy_to_user(up->id, &kp->id, sizeof(__u64)) || |
| 437 | copy_to_user(up->name, kp->name, 24) || |
| 438 | copy_to_user(&up->frameperiod, &kp->frameperiod, sizeof(kp->frameperiod)) || |
| 439 | put_user(kp->framelines, &up->framelines) || |
| 440 | copy_to_user(up->reserved, kp->reserved, 4 * sizeof(__u32))) |
| 441 | return -EFAULT; |
| 442 | return 0; |
| 443 | } |
| 444 | |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 445 | struct v4l2_buffer32 { |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 446 | __u32 index; |
| 447 | enum v4l2_buf_type type; |
| 448 | __u32 bytesused; |
| 449 | __u32 flags; |
| 450 | enum v4l2_field field; |
| 451 | struct compat_timeval timestamp; |
| 452 | struct v4l2_timecode timecode; |
| 453 | __u32 sequence; |
| 454 | |
| 455 | /* memory location */ |
| 456 | enum v4l2_memory memory; |
| 457 | union { |
| 458 | __u32 offset; |
| 459 | compat_long_t userptr; |
| 460 | } m; |
| 461 | __u32 length; |
| 462 | __u32 input; |
| 463 | __u32 reserved; |
| 464 | }; |
| 465 | |
| 466 | static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user *up) |
| 467 | { |
| 468 | |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 469 | if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_buffer32)) || |
| 470 | get_user(kp->index, &up->index) || |
| 471 | get_user(kp->type, &up->type) || |
| 472 | get_user(kp->flags, &up->flags) || |
| 473 | get_user(kp->memory, &up->memory) || |
| 474 | get_user(kp->input, &up->input)) |
| 475 | return -EFAULT; |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 476 | switch (kp->memory) { |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 477 | case V4L2_MEMORY_MMAP: |
Arnaud Patard | 22c859fa | 2010-01-25 12:02:31 -0300 | [diff] [blame] | 478 | if (get_user(kp->length, &up->length) || |
| 479 | get_user(kp->m.offset, &up->m.offset)) |
| 480 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 481 | break; |
| 482 | case V4L2_MEMORY_USERPTR: |
| 483 | { |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 484 | compat_long_t tmp; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 485 | |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 486 | if (get_user(kp->length, &up->length) || |
| 487 | get_user(tmp, &up->m.userptr)) |
| 488 | return -EFAULT; |
| 489 | |
| 490 | kp->m.userptr = (unsigned long)compat_ptr(tmp); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 491 | } |
| 492 | break; |
| 493 | case V4L2_MEMORY_OVERLAY: |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 494 | if (get_user(kp->m.offset, &up->m.offset)) |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 495 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 496 | break; |
| 497 | } |
| 498 | return 0; |
| 499 | } |
| 500 | |
| 501 | static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user *up) |
| 502 | { |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 503 | if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_buffer32)) || |
| 504 | put_user(kp->index, &up->index) || |
| 505 | put_user(kp->type, &up->type) || |
| 506 | put_user(kp->flags, &up->flags) || |
| 507 | put_user(kp->memory, &up->memory) || |
| 508 | put_user(kp->input, &up->input)) |
| 509 | return -EFAULT; |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 510 | switch (kp->memory) { |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 511 | case V4L2_MEMORY_MMAP: |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 512 | if (put_user(kp->length, &up->length) || |
| 513 | put_user(kp->m.offset, &up->m.offset)) |
| 514 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 515 | break; |
| 516 | case V4L2_MEMORY_USERPTR: |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 517 | if (put_user(kp->length, &up->length) || |
| 518 | put_user(kp->m.userptr, &up->m.userptr)) |
| 519 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 520 | break; |
| 521 | case V4L2_MEMORY_OVERLAY: |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 522 | if (put_user(kp->m.offset, &up->m.offset)) |
| 523 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 524 | break; |
| 525 | } |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 526 | if (put_user(kp->bytesused, &up->bytesused) || |
| 527 | put_user(kp->field, &up->field) || |
| 528 | put_user(kp->timestamp.tv_sec, &up->timestamp.tv_sec) || |
| 529 | put_user(kp->timestamp.tv_usec, &up->timestamp.tv_usec) || |
| 530 | copy_to_user(&up->timecode, &kp->timecode, sizeof(struct v4l2_timecode)) || |
| 531 | put_user(kp->sequence, &up->sequence) || |
| 532 | put_user(kp->reserved, &up->reserved)) |
| 533 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 534 | return 0; |
| 535 | } |
| 536 | |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 537 | struct v4l2_framebuffer32 { |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 538 | __u32 capability; |
| 539 | __u32 flags; |
| 540 | compat_caddr_t base; |
| 541 | struct v4l2_pix_format fmt; |
| 542 | }; |
| 543 | |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 544 | static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_framebuffer32 __user *up) |
| 545 | { |
| 546 | u32 tmp; |
| 547 | |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 548 | if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_framebuffer32)) || |
| 549 | get_user(tmp, &up->base) || |
| 550 | get_user(kp->capability, &up->capability) || |
| 551 | get_user(kp->flags, &up->flags)) |
| 552 | return -EFAULT; |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 553 | kp->base = compat_ptr(tmp); |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 554 | get_v4l2_pix_format(&kp->fmt, &up->fmt); |
| 555 | return 0; |
| 556 | } |
| 557 | |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 558 | static int put_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_framebuffer32 __user *up) |
| 559 | { |
| 560 | u32 tmp = (u32)((unsigned long)kp->base); |
| 561 | |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 562 | if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_framebuffer32)) || |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 563 | put_user(tmp, &up->base) || |
| 564 | put_user(kp->capability, &up->capability) || |
| 565 | put_user(kp->flags, &up->flags)) |
| 566 | return -EFAULT; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 567 | put_v4l2_pix_format(&kp->fmt, &up->fmt); |
| 568 | return 0; |
| 569 | } |
| 570 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 571 | struct v4l2_input32 { |
| 572 | __u32 index; /* Which input */ |
| 573 | __u8 name[32]; /* Label */ |
| 574 | __u32 type; /* Type of input */ |
| 575 | __u32 audioset; /* Associated audios (bitfield) */ |
| 576 | __u32 tuner; /* Associated tuner */ |
| 577 | v4l2_std_id std; |
| 578 | __u32 status; |
| 579 | __u32 reserved[4]; |
| 580 | } __attribute__ ((packed)); |
| 581 | |
| 582 | /* The 64-bit v4l2_input struct has extra padding at the end of the struct. |
| 583 | Otherwise it is identical to the 32-bit version. */ |
| 584 | static inline int get_v4l2_input32(struct v4l2_input *kp, struct v4l2_input32 __user *up) |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 585 | { |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 586 | if (copy_from_user(kp, up, sizeof(struct v4l2_input32))) |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 587 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 588 | return 0; |
| 589 | } |
| 590 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 591 | static inline int put_v4l2_input32(struct v4l2_input *kp, struct v4l2_input32 __user *up) |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 592 | { |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 593 | if (copy_to_user(up, kp, sizeof(struct v4l2_input32))) |
Al Viro | 5b1a43d | 2006-02-01 05:24:20 -0500 | [diff] [blame] | 594 | return -EFAULT; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 595 | return 0; |
| 596 | } |
| 597 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 598 | struct v4l2_ext_controls32 { |
| 599 | __u32 ctrl_class; |
| 600 | __u32 count; |
| 601 | __u32 error_idx; |
| 602 | __u32 reserved[2]; |
| 603 | compat_caddr_t controls; /* actually struct v4l2_ext_control32 * */ |
Mauro Carvalho Chehab | eb4eecc | 2006-07-21 18:53:23 -0300 | [diff] [blame] | 604 | }; |
| 605 | |
Hans Verkuil | 6b5a949 | 2009-08-11 18:47:18 -0300 | [diff] [blame] | 606 | struct v4l2_ext_control32 { |
| 607 | __u32 id; |
| 608 | __u32 size; |
| 609 | __u32 reserved2[1]; |
| 610 | union { |
| 611 | __s32 value; |
| 612 | __s64 value64; |
| 613 | compat_caddr_t string; /* actually char * */ |
| 614 | }; |
| 615 | } __attribute__ ((packed)); |
| 616 | |
| 617 | /* The following function really belong in v4l2-common, but that causes |
| 618 | a circular dependency between modules. We need to think about this, but |
| 619 | for now this will do. */ |
| 620 | |
| 621 | /* Return non-zero if this control is a pointer type. Currently only |
Eduardo Valentin | fdf82dc | 2009-08-11 18:49:12 -0300 | [diff] [blame] | 622 | type STRING is a pointer type. */ |
Hans Verkuil | 6b5a949 | 2009-08-11 18:47:18 -0300 | [diff] [blame] | 623 | static inline int ctrl_is_pointer(u32 id) |
| 624 | { |
Eduardo Valentin | fdf82dc | 2009-08-11 18:49:12 -0300 | [diff] [blame] | 625 | switch (id) { |
| 626 | case V4L2_CID_RDS_TX_PS_NAME: |
| 627 | case V4L2_CID_RDS_TX_RADIO_TEXT: |
| 628 | return 1; |
| 629 | default: |
| 630 | return 0; |
| 631 | } |
Hans Verkuil | 6b5a949 | 2009-08-11 18:47:18 -0300 | [diff] [blame] | 632 | } |
| 633 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 634 | static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up) |
Mauro Carvalho Chehab | eb4eecc | 2006-07-21 18:53:23 -0300 | [diff] [blame] | 635 | { |
Hans Verkuil | 6b5a949 | 2009-08-11 18:47:18 -0300 | [diff] [blame] | 636 | struct v4l2_ext_control32 __user *ucontrols; |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 637 | struct v4l2_ext_control __user *kcontrols; |
| 638 | int n; |
| 639 | compat_caddr_t p; |
| 640 | |
| 641 | if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_ext_controls32)) || |
| 642 | get_user(kp->ctrl_class, &up->ctrl_class) || |
| 643 | get_user(kp->count, &up->count) || |
| 644 | get_user(kp->error_idx, &up->error_idx) || |
| 645 | copy_from_user(kp->reserved, up->reserved, sizeof(kp->reserved))) |
Mauro Carvalho Chehab | eb4eecc | 2006-07-21 18:53:23 -0300 | [diff] [blame] | 646 | return -EFAULT; |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 647 | n = kp->count; |
| 648 | if (n == 0) { |
| 649 | kp->controls = NULL; |
| 650 | return 0; |
| 651 | } |
| 652 | if (get_user(p, &up->controls)) |
| 653 | return -EFAULT; |
| 654 | ucontrols = compat_ptr(p); |
| 655 | if (!access_ok(VERIFY_READ, ucontrols, n * sizeof(struct v4l2_ext_control))) |
| 656 | return -EFAULT; |
| 657 | kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control)); |
| 658 | kp->controls = kcontrols; |
| 659 | while (--n >= 0) { |
Hans Verkuil | 6b5a949 | 2009-08-11 18:47:18 -0300 | [diff] [blame] | 660 | if (copy_in_user(kcontrols, ucontrols, sizeof(*kcontrols))) |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 661 | return -EFAULT; |
Hans Verkuil | 6b5a949 | 2009-08-11 18:47:18 -0300 | [diff] [blame] | 662 | if (ctrl_is_pointer(kcontrols->id)) { |
| 663 | void __user *s; |
| 664 | |
| 665 | if (get_user(p, &ucontrols->string)) |
| 666 | return -EFAULT; |
| 667 | s = compat_ptr(p); |
| 668 | if (put_user(s, &kcontrols->string)) |
| 669 | return -EFAULT; |
| 670 | } |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 671 | ucontrols++; |
| 672 | kcontrols++; |
| 673 | } |
Mauro Carvalho Chehab | eb4eecc | 2006-07-21 18:53:23 -0300 | [diff] [blame] | 674 | return 0; |
| 675 | } |
| 676 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 677 | static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up) |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 678 | { |
Hans Verkuil | 6b5a949 | 2009-08-11 18:47:18 -0300 | [diff] [blame] | 679 | struct v4l2_ext_control32 __user *ucontrols; |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 680 | struct v4l2_ext_control __user *kcontrols = kp->controls; |
| 681 | int n = kp->count; |
| 682 | compat_caddr_t p; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 683 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 684 | if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_ext_controls32)) || |
| 685 | put_user(kp->ctrl_class, &up->ctrl_class) || |
| 686 | put_user(kp->count, &up->count) || |
| 687 | put_user(kp->error_idx, &up->error_idx) || |
| 688 | copy_to_user(up->reserved, kp->reserved, sizeof(up->reserved))) |
| 689 | return -EFAULT; |
| 690 | if (!kp->count) |
| 691 | return 0; |
| 692 | |
| 693 | if (get_user(p, &up->controls)) |
| 694 | return -EFAULT; |
| 695 | ucontrols = compat_ptr(p); |
| 696 | if (!access_ok(VERIFY_WRITE, ucontrols, n * sizeof(struct v4l2_ext_control))) |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 697 | return -EFAULT; |
| 698 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 699 | while (--n >= 0) { |
Hans Verkuil | 6b5a949 | 2009-08-11 18:47:18 -0300 | [diff] [blame] | 700 | unsigned size = sizeof(*ucontrols); |
| 701 | |
| 702 | /* Do not modify the pointer when copying a pointer control. |
| 703 | The contents of the pointer was changed, not the pointer |
| 704 | itself. */ |
| 705 | if (ctrl_is_pointer(kcontrols->id)) |
| 706 | size -= sizeof(ucontrols->value64); |
| 707 | if (copy_in_user(ucontrols, kcontrols, size)) |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 708 | return -EFAULT; |
| 709 | ucontrols++; |
| 710 | kcontrols++; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 711 | } |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 712 | return 0; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 713 | } |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 714 | |
| 715 | #define VIDIOC_G_FMT32 _IOWR('V', 4, struct v4l2_format32) |
| 716 | #define VIDIOC_S_FMT32 _IOWR('V', 5, struct v4l2_format32) |
| 717 | #define VIDIOC_QUERYBUF32 _IOWR('V', 9, struct v4l2_buffer32) |
| 718 | #define VIDIOC_G_FBUF32 _IOR ('V', 10, struct v4l2_framebuffer32) |
| 719 | #define VIDIOC_S_FBUF32 _IOW ('V', 11, struct v4l2_framebuffer32) |
| 720 | #define VIDIOC_QBUF32 _IOWR('V', 15, struct v4l2_buffer32) |
| 721 | #define VIDIOC_DQBUF32 _IOWR('V', 17, struct v4l2_buffer32) |
| 722 | #define VIDIOC_ENUMSTD32 _IOWR('V', 25, struct v4l2_standard32) |
| 723 | #define VIDIOC_ENUMINPUT32 _IOWR('V', 26, struct v4l2_input32) |
| 724 | #define VIDIOC_TRY_FMT32 _IOWR('V', 64, struct v4l2_format32) |
| 725 | #define VIDIOC_G_EXT_CTRLS32 _IOWR('V', 71, struct v4l2_ext_controls32) |
| 726 | #define VIDIOC_S_EXT_CTRLS32 _IOWR('V', 72, struct v4l2_ext_controls32) |
| 727 | #define VIDIOC_TRY_EXT_CTRLS32 _IOWR('V', 73, struct v4l2_ext_controls32) |
| 728 | |
| 729 | #define VIDIOC_OVERLAY32 _IOW ('V', 14, s32) |
Hans Verkuil | 15029b3 | 2008-12-21 10:44:24 -0300 | [diff] [blame] | 730 | #ifdef __OLD_VIDIOC_ |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 731 | #define VIDIOC_OVERLAY32_OLD _IOWR('V', 14, s32) |
Hans Verkuil | 15029b3 | 2008-12-21 10:44:24 -0300 | [diff] [blame] | 732 | #endif |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 733 | #define VIDIOC_STREAMON32 _IOW ('V', 18, s32) |
| 734 | #define VIDIOC_STREAMOFF32 _IOW ('V', 19, s32) |
| 735 | #define VIDIOC_G_INPUT32 _IOR ('V', 38, s32) |
| 736 | #define VIDIOC_S_INPUT32 _IOWR('V', 39, s32) |
| 737 | #define VIDIOC_G_OUTPUT32 _IOR ('V', 46, s32) |
| 738 | #define VIDIOC_S_OUTPUT32 _IOWR('V', 47, s32) |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 739 | |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 740 | static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 741 | { |
| 742 | union { |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame] | 743 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 744 | struct video_tuner vt; |
| 745 | struct video_buffer vb; |
| 746 | struct video_window vw; |
Mauro Carvalho Chehab | eb4eecc | 2006-07-21 18:53:23 -0300 | [diff] [blame] | 747 | struct video_code vc; |
Mauro Carvalho Chehab | 8a36ecf | 2006-08-06 10:16:27 -0300 | [diff] [blame] | 748 | struct video_audio va; |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame] | 749 | #endif |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 750 | struct v4l2_format v2f; |
| 751 | struct v4l2_buffer v2b; |
| 752 | struct v4l2_framebuffer v2fb; |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 753 | struct v4l2_input v2i; |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 754 | struct v4l2_standard v2s; |
| 755 | struct v4l2_ext_controls v2ecs; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 756 | unsigned long vx; |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 757 | int vi; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 758 | } karg; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 759 | void __user *up = compat_ptr(arg); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 760 | int compatible_arg = 1; |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 761 | long err = 0; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 762 | |
| 763 | /* First, convert the command. */ |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 764 | switch (cmd) { |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame] | 765 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 766 | case VIDIOCGTUNER32: cmd = VIDIOCGTUNER; break; |
| 767 | case VIDIOCSTUNER32: cmd = VIDIOCSTUNER; break; |
| 768 | case VIDIOCGWIN32: cmd = VIDIOCGWIN; break; |
| 769 | case VIDIOCSWIN32: cmd = VIDIOCSWIN; break; |
| 770 | case VIDIOCGFBUF32: cmd = VIDIOCGFBUF; break; |
| 771 | case VIDIOCSFBUF32: cmd = VIDIOCSFBUF; break; |
| 772 | case VIDIOCGFREQ32: cmd = VIDIOCGFREQ; break; |
| 773 | case VIDIOCSFREQ32: cmd = VIDIOCSFREQ; break; |
| 774 | case VIDIOCSMICROCODE32: cmd = VIDIOCSMICROCODE; break; |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame] | 775 | #endif |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 776 | case VIDIOC_G_FMT32: cmd = VIDIOC_G_FMT; break; |
| 777 | case VIDIOC_S_FMT32: cmd = VIDIOC_S_FMT; break; |
| 778 | case VIDIOC_QUERYBUF32: cmd = VIDIOC_QUERYBUF; break; |
| 779 | case VIDIOC_G_FBUF32: cmd = VIDIOC_G_FBUF; break; |
| 780 | case VIDIOC_S_FBUF32: cmd = VIDIOC_S_FBUF; break; |
| 781 | case VIDIOC_QBUF32: cmd = VIDIOC_QBUF; break; |
| 782 | case VIDIOC_DQBUF32: cmd = VIDIOC_DQBUF; break; |
| 783 | case VIDIOC_ENUMSTD32: cmd = VIDIOC_ENUMSTD; break; |
| 784 | case VIDIOC_ENUMINPUT32: cmd = VIDIOC_ENUMINPUT; break; |
| 785 | case VIDIOC_TRY_FMT32: cmd = VIDIOC_TRY_FMT; break; |
| 786 | case VIDIOC_G_EXT_CTRLS32: cmd = VIDIOC_G_EXT_CTRLS; break; |
| 787 | case VIDIOC_S_EXT_CTRLS32: cmd = VIDIOC_S_EXT_CTRLS; break; |
| 788 | case VIDIOC_TRY_EXT_CTRLS32: cmd = VIDIOC_TRY_EXT_CTRLS; break; |
| 789 | case VIDIOC_OVERLAY32: cmd = VIDIOC_OVERLAY; break; |
Hans Verkuil | 15029b3 | 2008-12-21 10:44:24 -0300 | [diff] [blame] | 790 | #ifdef __OLD_VIDIOC_ |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 791 | case VIDIOC_OVERLAY32_OLD: cmd = VIDIOC_OVERLAY; break; |
Hans Verkuil | 15029b3 | 2008-12-21 10:44:24 -0300 | [diff] [blame] | 792 | #endif |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 793 | case VIDIOC_STREAMON32: cmd = VIDIOC_STREAMON; break; |
| 794 | case VIDIOC_STREAMOFF32: cmd = VIDIOC_STREAMOFF; break; |
| 795 | case VIDIOC_G_INPUT32: cmd = VIDIOC_G_INPUT; break; |
| 796 | case VIDIOC_S_INPUT32: cmd = VIDIOC_S_INPUT; break; |
| 797 | case VIDIOC_G_OUTPUT32: cmd = VIDIOC_G_OUTPUT; break; |
| 798 | case VIDIOC_S_OUTPUT32: cmd = VIDIOC_S_OUTPUT; break; |
| 799 | } |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 800 | |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 801 | switch (cmd) { |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame] | 802 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 803 | case VIDIOCSTUNER: |
| 804 | case VIDIOCGTUNER: |
| 805 | err = get_video_tuner32(&karg.vt, up); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 806 | compatible_arg = 0; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 807 | break; |
| 808 | |
| 809 | case VIDIOCSFBUF: |
| 810 | err = get_video_buffer32(&karg.vb, up); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 811 | compatible_arg = 0; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 812 | break; |
| 813 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 814 | case VIDIOCSWIN: |
| 815 | err = get_video_window32(&karg.vw, up); |
| 816 | compatible_arg = 0; |
| 817 | break; |
| 818 | |
| 819 | case VIDIOCGWIN: |
| 820 | case VIDIOCGFBUF: |
| 821 | case VIDIOCGFREQ: |
| 822 | compatible_arg = 0; |
| 823 | break; |
| 824 | |
| 825 | case VIDIOCSMICROCODE: |
| 826 | err = get_microcode32(&karg.vc, up); |
| 827 | compatible_arg = 0; |
| 828 | break; |
Mauro Carvalho Chehab | 8a36ecf | 2006-08-06 10:16:27 -0300 | [diff] [blame] | 829 | |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 830 | case VIDIOCSFREQ: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 831 | err = get_user(karg.vx, (u32 __user *)up); |
| 832 | compatible_arg = 0; |
| 833 | break; |
| 834 | |
| 835 | case VIDIOCCAPTURE: |
| 836 | case VIDIOCSYNC: |
| 837 | case VIDIOCSWRITEMODE: |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame] | 838 | #endif |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 839 | case VIDIOC_OVERLAY: |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 840 | case VIDIOC_STREAMON: |
| 841 | case VIDIOC_STREAMOFF: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 842 | case VIDIOC_S_INPUT: |
| 843 | case VIDIOC_S_OUTPUT: |
| 844 | err = get_user(karg.vi, (s32 __user *)up); |
| 845 | compatible_arg = 0; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 846 | break; |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 847 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 848 | case VIDIOC_G_INPUT: |
| 849 | case VIDIOC_G_OUTPUT: |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 850 | compatible_arg = 0; |
| 851 | break; |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 852 | |
| 853 | case VIDIOC_G_FMT: |
| 854 | case VIDIOC_S_FMT: |
| 855 | case VIDIOC_TRY_FMT: |
| 856 | err = get_v4l2_format32(&karg.v2f, up); |
| 857 | compatible_arg = 0; |
| 858 | break; |
| 859 | |
| 860 | case VIDIOC_QUERYBUF: |
| 861 | case VIDIOC_QBUF: |
| 862 | case VIDIOC_DQBUF: |
| 863 | err = get_v4l2_buffer32(&karg.v2b, up); |
| 864 | compatible_arg = 0; |
| 865 | break; |
| 866 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 867 | case VIDIOC_S_FBUF: |
| 868 | err = get_v4l2_framebuffer32(&karg.v2fb, up); |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 869 | compatible_arg = 0; |
| 870 | break; |
| 871 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 872 | case VIDIOC_G_FBUF: |
| 873 | compatible_arg = 0; |
| 874 | break; |
| 875 | |
| 876 | case VIDIOC_ENUMSTD: |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 877 | err = get_v4l2_standard32(&karg.v2s, up); |
| 878 | compatible_arg = 0; |
| 879 | break; |
| 880 | |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 881 | case VIDIOC_ENUMINPUT: |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 882 | err = get_v4l2_input32(&karg.v2i, up); |
| 883 | compatible_arg = 0; |
| 884 | break; |
| 885 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 886 | case VIDIOC_G_EXT_CTRLS: |
| 887 | case VIDIOC_S_EXT_CTRLS: |
| 888 | case VIDIOC_TRY_EXT_CTRLS: |
| 889 | err = get_v4l2_ext_controls32(&karg.v2ecs, up); |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 890 | compatible_arg = 0; |
| 891 | break; |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 892 | } |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 893 | if (err) |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 894 | return err; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 895 | |
Hans Verkuil | d1f81da | 2008-10-22 00:04:45 -0300 | [diff] [blame] | 896 | if (compatible_arg) |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 897 | err = native_ioctl(file, cmd, (unsigned long)up); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 898 | else { |
| 899 | mm_segment_t old_fs = get_fs(); |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 900 | |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 901 | set_fs(KERNEL_DS); |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 902 | err = native_ioctl(file, cmd, (unsigned long)&karg); |
Philippe De Muyter | cf664a6 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 903 | set_fs(old_fs); |
| 904 | } |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 905 | |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 906 | /* Special case: even after an error we need to put the |
| 907 | results back for these ioctls since the error_idx will |
| 908 | contain information on which control failed. */ |
| 909 | switch (cmd) { |
| 910 | case VIDIOC_G_EXT_CTRLS: |
| 911 | case VIDIOC_S_EXT_CTRLS: |
| 912 | case VIDIOC_TRY_EXT_CTRLS: |
| 913 | if (put_v4l2_ext_controls32(&karg.v2ecs, up)) |
| 914 | err = -EFAULT; |
| 915 | break; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 916 | } |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 917 | if (err) |
| 918 | return err; |
| 919 | |
| 920 | switch (cmd) { |
| 921 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
| 922 | case VIDIOCGTUNER: |
| 923 | err = put_video_tuner32(&karg.vt, up); |
| 924 | break; |
| 925 | |
| 926 | case VIDIOCGWIN: |
| 927 | err = put_video_window32(&karg.vw, up); |
| 928 | break; |
| 929 | |
| 930 | case VIDIOCGFBUF: |
| 931 | err = put_video_buffer32(&karg.vb, up); |
| 932 | break; |
| 933 | |
| 934 | case VIDIOCGFREQ: |
| 935 | err = put_user(((u32)karg.vx), (u32 __user *)up); |
| 936 | break; |
| 937 | #endif |
| 938 | case VIDIOC_S_INPUT: |
| 939 | case VIDIOC_S_OUTPUT: |
| 940 | case VIDIOC_G_INPUT: |
| 941 | case VIDIOC_G_OUTPUT: |
| 942 | err = put_user(((s32)karg.vi), (s32 __user *)up); |
| 943 | break; |
| 944 | |
| 945 | case VIDIOC_G_FBUF: |
| 946 | err = put_v4l2_framebuffer32(&karg.v2fb, up); |
| 947 | break; |
| 948 | |
| 949 | case VIDIOC_G_FMT: |
| 950 | case VIDIOC_S_FMT: |
| 951 | case VIDIOC_TRY_FMT: |
| 952 | err = put_v4l2_format32(&karg.v2f, up); |
| 953 | break; |
| 954 | |
| 955 | case VIDIOC_QUERYBUF: |
| 956 | case VIDIOC_QBUF: |
| 957 | case VIDIOC_DQBUF: |
| 958 | err = put_v4l2_buffer32(&karg.v2b, up); |
| 959 | break; |
| 960 | |
| 961 | case VIDIOC_ENUMSTD: |
| 962 | err = put_v4l2_standard32(&karg.v2s, up); |
| 963 | break; |
| 964 | |
| 965 | case VIDIOC_ENUMINPUT: |
| 966 | err = put_v4l2_input32(&karg.v2i, up); |
| 967 | break; |
| 968 | } |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 969 | return err; |
| 970 | } |
| 971 | |
Hans Verkuil | 9bb7cde | 2008-12-30 06:42:40 -0300 | [diff] [blame] | 972 | long v4l2_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg) |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 973 | { |
Hans Verkuil | 069b747 | 2008-12-30 07:04:34 -0300 | [diff] [blame] | 974 | long ret = -ENOIOCTLCMD; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 975 | |
Hans Verkuil | 3ca81a5 | 2008-12-16 08:32:37 -0300 | [diff] [blame] | 976 | if (!file->f_op->ioctl && !file->f_op->unlocked_ioctl) |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 977 | return ret; |
| 978 | |
| 979 | switch (cmd) { |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame] | 980 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 981 | case VIDIOCGCAP: |
| 982 | case VIDIOCGCHAN: |
| 983 | case VIDIOCSCHAN: |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 984 | case VIDIOCGTUNER32: |
| 985 | case VIDIOCSTUNER32: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 986 | case VIDIOCGPICT: |
| 987 | case VIDIOCSPICT: |
| 988 | case VIDIOCCAPTURE32: |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 989 | case VIDIOCGWIN32: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 990 | case VIDIOCSWIN32: |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 991 | case VIDIOCGFBUF32: |
| 992 | case VIDIOCSFBUF32: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 993 | case VIDIOCKEY: |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 994 | case VIDIOCGFREQ32: |
Nickolay V. Shmyrev | 133b735 | 2006-01-09 15:24:58 -0200 | [diff] [blame] | 995 | case VIDIOCSFREQ32: |
Mauro Carvalho Chehab | 8a36ecf | 2006-08-06 10:16:27 -0300 | [diff] [blame] | 996 | case VIDIOCGAUDIO: |
| 997 | case VIDIOCSAUDIO: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 998 | case VIDIOCSYNC32: |
| 999 | case VIDIOCMCAPTURE: |
| 1000 | case VIDIOCGMBUF: |
| 1001 | case VIDIOCGUNIT: |
| 1002 | case VIDIOCGCAPTURE: |
| 1003 | case VIDIOCSCAPTURE: |
| 1004 | case VIDIOCSPLAYMODE: |
| 1005 | case VIDIOCSWRITEMODE32: |
| 1006 | case VIDIOCGPLAYINFO: |
| 1007 | case VIDIOCSMICROCODE32: |
Steven Walter | 7963fa4 | 2007-08-09 11:36:35 -0300 | [diff] [blame] | 1008 | case VIDIOCGVBIFMT: |
| 1009 | case VIDIOCSVBIFMT: |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame] | 1010 | #endif |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1011 | #ifdef __OLD_VIDIOC_ |
| 1012 | case VIDIOC_OVERLAY32_OLD: |
| 1013 | case VIDIOC_S_PARM_OLD: |
| 1014 | case VIDIOC_S_CTRL_OLD: |
| 1015 | case VIDIOC_G_AUDIO_OLD: |
| 1016 | case VIDIOC_G_AUDOUT_OLD: |
| 1017 | case VIDIOC_CROPCAP_OLD: |
| 1018 | #endif |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 1019 | case VIDIOC_QUERYCAP: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1020 | case VIDIOC_RESERVED: |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 1021 | case VIDIOC_ENUM_FMT: |
| 1022 | case VIDIOC_G_FMT32: |
| 1023 | case VIDIOC_S_FMT32: |
| 1024 | case VIDIOC_REQBUFS: |
| 1025 | case VIDIOC_QUERYBUF32: |
| 1026 | case VIDIOC_G_FBUF32: |
| 1027 | case VIDIOC_S_FBUF32: |
| 1028 | case VIDIOC_OVERLAY32: |
| 1029 | case VIDIOC_QBUF32: |
| 1030 | case VIDIOC_DQBUF32: |
| 1031 | case VIDIOC_STREAMON32: |
| 1032 | case VIDIOC_STREAMOFF32: |
| 1033 | case VIDIOC_G_PARM: |
Gregor Jasny | c7f09db | 2008-10-23 09:55:22 -0300 | [diff] [blame] | 1034 | case VIDIOC_S_PARM: |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 1035 | case VIDIOC_G_STD: |
| 1036 | case VIDIOC_S_STD: |
| 1037 | case VIDIOC_ENUMSTD32: |
| 1038 | case VIDIOC_ENUMINPUT32: |
| 1039 | case VIDIOC_G_CTRL: |
Steven Walter | 7963fa4 | 2007-08-09 11:36:35 -0300 | [diff] [blame] | 1040 | case VIDIOC_S_CTRL: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1041 | case VIDIOC_G_TUNER: |
| 1042 | case VIDIOC_S_TUNER: |
| 1043 | case VIDIOC_G_AUDIO: |
| 1044 | case VIDIOC_S_AUDIO: |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 1045 | case VIDIOC_QUERYCTRL: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1046 | case VIDIOC_QUERYMENU: |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 1047 | case VIDIOC_G_INPUT32: |
| 1048 | case VIDIOC_S_INPUT32: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1049 | case VIDIOC_G_OUTPUT32: |
| 1050 | case VIDIOC_S_OUTPUT32: |
| 1051 | case VIDIOC_ENUMOUTPUT: |
| 1052 | case VIDIOC_G_AUDOUT: |
| 1053 | case VIDIOC_S_AUDOUT: |
| 1054 | case VIDIOC_G_MODULATOR: |
| 1055 | case VIDIOC_S_MODULATOR: |
| 1056 | case VIDIOC_S_FREQUENCY: |
| 1057 | case VIDIOC_G_FREQUENCY: |
| 1058 | case VIDIOC_CROPCAP: |
| 1059 | case VIDIOC_G_CROP: |
| 1060 | case VIDIOC_S_CROP: |
| 1061 | case VIDIOC_G_JPEGCOMP: |
| 1062 | case VIDIOC_S_JPEGCOMP: |
| 1063 | case VIDIOC_QUERYSTD: |
Philippe De Muyter | 13d133b | 2006-01-09 15:25:00 -0200 | [diff] [blame] | 1064 | case VIDIOC_TRY_FMT32: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1065 | case VIDIOC_ENUMAUDIO: |
| 1066 | case VIDIOC_ENUMAUDOUT: |
| 1067 | case VIDIOC_G_PRIORITY: |
| 1068 | case VIDIOC_S_PRIORITY: |
| 1069 | case VIDIOC_G_SLICED_VBI_CAP: |
| 1070 | case VIDIOC_LOG_STATUS: |
| 1071 | case VIDIOC_G_EXT_CTRLS32: |
| 1072 | case VIDIOC_S_EXT_CTRLS32: |
| 1073 | case VIDIOC_TRY_EXT_CTRLS32: |
Gregor Jasny | c7f09db | 2008-10-23 09:55:22 -0300 | [diff] [blame] | 1074 | case VIDIOC_ENUM_FRAMESIZES: |
| 1075 | case VIDIOC_ENUM_FRAMEINTERVALS: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1076 | case VIDIOC_G_ENC_INDEX: |
| 1077 | case VIDIOC_ENCODER_CMD: |
| 1078 | case VIDIOC_TRY_ENCODER_CMD: |
| 1079 | case VIDIOC_DBG_S_REGISTER: |
| 1080 | case VIDIOC_DBG_G_REGISTER: |
Hans Verkuil | aecde8b5 | 2008-12-30 07:14:19 -0300 | [diff] [blame] | 1081 | case VIDIOC_DBG_G_CHIP_IDENT: |
Hans Verkuil | 92f45ba | 2008-12-21 10:35:25 -0300 | [diff] [blame] | 1082 | case VIDIOC_S_HW_FREQ_SEEK: |
Muralidharan Karicheri | b6456c0 | 2009-11-19 12:00:31 -0300 | [diff] [blame] | 1083 | case VIDIOC_ENUM_DV_PRESETS: |
| 1084 | case VIDIOC_S_DV_PRESET: |
| 1085 | case VIDIOC_G_DV_PRESET: |
| 1086 | case VIDIOC_QUERY_DV_PRESET: |
| 1087 | case VIDIOC_S_DV_TIMINGS: |
| 1088 | case VIDIOC_G_DV_TIMINGS: |
Sakari Ailus | fda1021 | 2010-02-24 19:19:05 -0300 | [diff] [blame] | 1089 | case VIDIOC_DQEVENT: |
| 1090 | case VIDIOC_SUBSCRIBE_EVENT: |
| 1091 | case VIDIOC_UNSUBSCRIBE_EVENT: |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 1092 | ret = do_video_ioctl(file, cmd, arg); |
| 1093 | break; |
| 1094 | |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame] | 1095 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 1096 | /* BTTV specific... */ |
| 1097 | case _IOW('v', BASE_VIDIOCPRIVATE+0, char [256]): |
| 1098 | case _IOR('v', BASE_VIDIOCPRIVATE+1, char [256]): |
| 1099 | case _IOR('v' , BASE_VIDIOCPRIVATE+2, unsigned int): |
| 1100 | case _IOW('v' , BASE_VIDIOCPRIVATE+3, char [16]): /* struct bttv_pll_info */ |
| 1101 | case _IOR('v' , BASE_VIDIOCPRIVATE+4, int): |
| 1102 | case _IOR('v' , BASE_VIDIOCPRIVATE+5, int): |
| 1103 | case _IOR('v' , BASE_VIDIOCPRIVATE+6, int): |
| 1104 | case _IOR('v' , BASE_VIDIOCPRIVATE+7, int): |
| 1105 | ret = native_ioctl(file, cmd, (unsigned long)compat_ptr(arg)); |
| 1106 | break; |
Mauro Carvalho Chehab | 5bdd6cc | 2006-07-25 16:17:54 -0300 | [diff] [blame] | 1107 | #endif |
Guy Martin | a113bc7 | 2006-01-11 23:40:51 -0200 | [diff] [blame] | 1108 | default: |
Hans Verkuil | 7943ecf | 2008-12-23 14:37:43 -0300 | [diff] [blame] | 1109 | printk(KERN_WARNING "compat_ioctl32: " |
| 1110 | "unknown ioctl '%c', dir=%d, #%d (0x%08x)\n", |
| 1111 | _IOC_TYPE(cmd), _IOC_DIR(cmd), _IOC_NR(cmd), cmd); |
Hans Verkuil | 7d4f0b8 | 2008-12-15 07:19:20 -0300 | [diff] [blame] | 1112 | break; |
MishalĂ… Pytasz | 97e2a01 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 1113 | } |
Hans Verkuil | e8efb71 | 2006-01-09 15:24:59 -0200 | [diff] [blame] | 1114 | return ret; |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 1115 | } |
Hans Verkuil | 9bb7cde | 2008-12-30 06:42:40 -0300 | [diff] [blame] | 1116 | EXPORT_SYMBOL_GPL(v4l2_compat_ioctl32); |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 1117 | #endif |
Ricardo Cerqueira | 925e699 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 1118 | |
| 1119 | MODULE_LICENSE("GPL"); |