1 // SPDX-License-Identifier: GPL-2.0-only
3 * ioctl32.c: Conversion between 32bit and 64bit native ioctls.
8 * Copyright (C) 2001,2002 Andi Kleen, SuSE Labs
13 * These routines maintain argument size conversion between 32bit and 64bit
17 #include <linux/compat.h>
18 #include <linux/module.h>
19 #include <linux/videodev2.h>
20 #include <linux/v4l2-subdev.h>
21 #include <media/v4l2-dev.h>
22 #include <media/v4l2-fh.h>
23 #include <media/v4l2-ctrls.h>
24 #include <media/v4l2-ioctl.h>
27 * Per-ioctl data copy handlers.
29 * Those come in pairs, with a get_v4l2_foo() and a put_v4l2_foo() routine,
30 * where "v4l2_foo" is the name of the V4L2 struct.
32 * They basically get two __user pointers, one with a 32-bits struct that
33 * came from the userspace call and a 64-bits struct, also allocated as
34 * userspace, but filled internally by do_video_ioctl().
36 * For ioctls that have pointers inside it, the functions will also
37 * receive an ancillary buffer with extra space, used to pass extra
38 * data to the routine.
46 struct v4l2_window32 {
48 __u32 field; /* enum v4l2_field */
50 compat_caddr_t clips; /* actually struct v4l2_clip32 * */
52 compat_caddr_t bitmap;
56 static int get_v4l2_window32(struct v4l2_window *p64,
57 struct v4l2_window32 __user *p32)
59 struct v4l2_window32 w32;
61 if (copy_from_user(&w32, p32, sizeof(w32)))
64 *p64 = (struct v4l2_window) {
67 .chromakey = w32.chromakey,
68 .clips = (void __force *)compat_ptr(w32.clips),
69 .clipcount = w32.clipcount,
70 .bitmap = compat_ptr(w32.bitmap),
71 .global_alpha = w32.global_alpha,
74 if (p64->clipcount > 2048)
82 static int put_v4l2_window32(struct v4l2_window *p64,
83 struct v4l2_window32 __user *p32)
85 struct v4l2_window32 w32;
87 memset(&w32, 0, sizeof(w32));
88 w32 = (struct v4l2_window32) {
91 .chromakey = p64->chromakey,
92 .clips = (uintptr_t)p64->clips,
93 .clipcount = p64->clipcount,
94 .bitmap = ptr_to_compat(p64->bitmap),
95 .global_alpha = p64->global_alpha,
98 /* copy everything except the clips pointer */
99 if (copy_to_user(p32, &w32, offsetof(struct v4l2_window32, clips)) ||
100 copy_to_user(&p32->clipcount, &w32.clipcount,
101 sizeof(w32) - offsetof(struct v4l2_window32, clipcount)))
107 struct v4l2_format32 {
108 __u32 type; /* enum v4l2_buf_type */
110 struct v4l2_pix_format pix;
111 struct v4l2_pix_format_mplane pix_mp;
112 struct v4l2_window32 win;
113 struct v4l2_vbi_format vbi;
114 struct v4l2_sliced_vbi_format sliced;
115 struct v4l2_sdr_format sdr;
116 struct v4l2_meta_format meta;
117 __u8 raw_data[200]; /* user-defined */
122 * struct v4l2_create_buffers32 - VIDIOC_CREATE_BUFS32 argument
123 * @index: on return, index of the first created buffer
124 * @count: entry: number of requested buffers,
125 * return: number of created buffers
126 * @memory: buffer memory type
127 * @format: frame format, for which buffers are requested
128 * @capabilities: capabilities of this buffer type.
129 * @flags: additional buffer management attributes (ignored unless the
130 * queue has V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS capability and
131 * configured for MMAP streaming I/O).
132 * @reserved: future extensions
134 struct v4l2_create_buffers32 {
137 __u32 memory; /* enum v4l2_memory */
138 struct v4l2_format32 format;
144 static int get_v4l2_format32(struct v4l2_format *p64,
145 struct v4l2_format32 __user *p32)
147 if (get_user(p64->type, &p32->type))
151 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
152 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
153 return copy_from_user(&p64->fmt.pix, &p32->fmt.pix,
154 sizeof(p64->fmt.pix)) ? -EFAULT : 0;
155 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
156 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
157 return copy_from_user(&p64->fmt.pix_mp, &p32->fmt.pix_mp,
158 sizeof(p64->fmt.pix_mp)) ? -EFAULT : 0;
159 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
160 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
161 return get_v4l2_window32(&p64->fmt.win, &p32->fmt.win);
162 case V4L2_BUF_TYPE_VBI_CAPTURE:
163 case V4L2_BUF_TYPE_VBI_OUTPUT:
164 return copy_from_user(&p64->fmt.vbi, &p32->fmt.vbi,
165 sizeof(p64->fmt.vbi)) ? -EFAULT : 0;
166 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
167 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
168 return copy_from_user(&p64->fmt.sliced, &p32->fmt.sliced,
169 sizeof(p64->fmt.sliced)) ? -EFAULT : 0;
170 case V4L2_BUF_TYPE_SDR_CAPTURE:
171 case V4L2_BUF_TYPE_SDR_OUTPUT:
172 return copy_from_user(&p64->fmt.sdr, &p32->fmt.sdr,
173 sizeof(p64->fmt.sdr)) ? -EFAULT : 0;
174 case V4L2_BUF_TYPE_META_CAPTURE:
175 case V4L2_BUF_TYPE_META_OUTPUT:
176 return copy_from_user(&p64->fmt.meta, &p32->fmt.meta,
177 sizeof(p64->fmt.meta)) ? -EFAULT : 0;
183 static int get_v4l2_create32(struct v4l2_create_buffers *p64,
184 struct v4l2_create_buffers32 __user *p32)
186 if (copy_from_user(p64, p32,
187 offsetof(struct v4l2_create_buffers32, format)))
189 if (copy_from_user(&p64->flags, &p32->flags, sizeof(p32->flags)))
191 return get_v4l2_format32(&p64->format, &p32->format);
194 static int put_v4l2_format32(struct v4l2_format *p64,
195 struct v4l2_format32 __user *p32)
198 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
199 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
200 return copy_to_user(&p32->fmt.pix, &p64->fmt.pix,
201 sizeof(p64->fmt.pix)) ? -EFAULT : 0;
202 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
203 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
204 return copy_to_user(&p32->fmt.pix_mp, &p64->fmt.pix_mp,
205 sizeof(p64->fmt.pix_mp)) ? -EFAULT : 0;
206 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
207 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
208 return put_v4l2_window32(&p64->fmt.win, &p32->fmt.win);
209 case V4L2_BUF_TYPE_VBI_CAPTURE:
210 case V4L2_BUF_TYPE_VBI_OUTPUT:
211 return copy_to_user(&p32->fmt.vbi, &p64->fmt.vbi,
212 sizeof(p64->fmt.vbi)) ? -EFAULT : 0;
213 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
214 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
215 return copy_to_user(&p32->fmt.sliced, &p64->fmt.sliced,
216 sizeof(p64->fmt.sliced)) ? -EFAULT : 0;
217 case V4L2_BUF_TYPE_SDR_CAPTURE:
218 case V4L2_BUF_TYPE_SDR_OUTPUT:
219 return copy_to_user(&p32->fmt.sdr, &p64->fmt.sdr,
220 sizeof(p64->fmt.sdr)) ? -EFAULT : 0;
221 case V4L2_BUF_TYPE_META_CAPTURE:
222 case V4L2_BUF_TYPE_META_OUTPUT:
223 return copy_to_user(&p32->fmt.meta, &p64->fmt.meta,
224 sizeof(p64->fmt.meta)) ? -EFAULT : 0;
230 static int put_v4l2_create32(struct v4l2_create_buffers *p64,
231 struct v4l2_create_buffers32 __user *p32)
233 if (copy_to_user(p32, p64,
234 offsetof(struct v4l2_create_buffers32, format)) ||
235 put_user(p64->capabilities, &p32->capabilities) ||
236 put_user(p64->flags, &p32->flags) ||
237 copy_to_user(p32->reserved, p64->reserved, sizeof(p64->reserved)))
239 return put_v4l2_format32(&p64->format, &p32->format);
242 struct v4l2_standard32 {
246 struct v4l2_fract frameperiod; /* Frames, not fields */
251 static int get_v4l2_standard32(struct v4l2_standard *p64,
252 struct v4l2_standard32 __user *p32)
254 /* other fields are not set by the user, nor used by the driver */
255 return get_user(p64->index, &p32->index);
258 static int put_v4l2_standard32(struct v4l2_standard *p64,
259 struct v4l2_standard32 __user *p32)
261 if (put_user(p64->index, &p32->index) ||
262 put_user(p64->id, &p32->id) ||
263 copy_to_user(p32->name, p64->name, sizeof(p32->name)) ||
264 copy_to_user(&p32->frameperiod, &p64->frameperiod,
265 sizeof(p32->frameperiod)) ||
266 put_user(p64->framelines, &p32->framelines) ||
267 copy_to_user(p32->reserved, p64->reserved, sizeof(p32->reserved)))
272 struct v4l2_plane32 {
277 compat_long_t userptr;
285 * This is correct for all architectures including i386, but not x32,
286 * which has different alignment requirements for timestamp
288 struct v4l2_buffer32 {
290 __u32 type; /* enum v4l2_buf_type */
293 __u32 field; /* enum v4l2_field */
298 struct v4l2_timecode timecode;
301 /* memory location */
302 __u32 memory; /* enum v4l2_memory */
305 compat_long_t userptr;
306 compat_caddr_t planes;
314 #ifdef CONFIG_COMPAT_32BIT_TIME
315 struct v4l2_buffer32_time32 {
317 __u32 type; /* enum v4l2_buf_type */
320 __u32 field; /* enum v4l2_field */
321 struct old_timeval32 timestamp;
322 struct v4l2_timecode timecode;
325 /* memory location */
326 __u32 memory; /* enum v4l2_memory */
329 compat_long_t userptr;
330 compat_caddr_t planes;
339 static int get_v4l2_plane32(struct v4l2_plane *p64,
340 struct v4l2_plane32 __user *p32,
341 enum v4l2_memory memory)
343 struct v4l2_plane32 plane32;
344 typeof(p64->m) m = {};
346 if (copy_from_user(&plane32, p32, sizeof(plane32)))
350 case V4L2_MEMORY_MMAP:
351 case V4L2_MEMORY_OVERLAY:
352 m.mem_offset = plane32.m.mem_offset;
354 case V4L2_MEMORY_USERPTR:
355 m.userptr = (unsigned long)compat_ptr(plane32.m.userptr);
357 case V4L2_MEMORY_DMABUF:
362 memset(p64, 0, sizeof(*p64));
363 *p64 = (struct v4l2_plane) {
364 .bytesused = plane32.bytesused,
365 .length = plane32.length,
367 .data_offset = plane32.data_offset,
373 static int put_v4l2_plane32(struct v4l2_plane *p64,
374 struct v4l2_plane32 __user *p32,
375 enum v4l2_memory memory)
377 struct v4l2_plane32 plane32;
379 memset(&plane32, 0, sizeof(plane32));
380 plane32 = (struct v4l2_plane32) {
381 .bytesused = p64->bytesused,
382 .length = p64->length,
383 .data_offset = p64->data_offset,
387 case V4L2_MEMORY_MMAP:
388 case V4L2_MEMORY_OVERLAY:
389 plane32.m.mem_offset = p64->m.mem_offset;
391 case V4L2_MEMORY_USERPTR:
392 plane32.m.userptr = (uintptr_t)(p64->m.userptr);
394 case V4L2_MEMORY_DMABUF:
395 plane32.m.fd = p64->m.fd;
399 if (copy_to_user(p32, &plane32, sizeof(plane32)))
405 static int get_v4l2_buffer32(struct v4l2_buffer *vb,
406 struct v4l2_buffer32 __user *arg)
408 struct v4l2_buffer32 vb32;
410 if (copy_from_user(&vb32, arg, sizeof(vb32)))
413 memset(vb, 0, sizeof(*vb));
414 *vb = (struct v4l2_buffer) {
417 .bytesused = vb32.bytesused,
420 .timestamp.tv_sec = vb32.timestamp.tv_sec,
421 .timestamp.tv_usec = vb32.timestamp.tv_usec,
422 .timecode = vb32.timecode,
423 .sequence = vb32.sequence,
424 .memory = vb32.memory,
425 .m.offset = vb32.m.offset,
426 .length = vb32.length,
427 .request_fd = vb32.request_fd,
430 switch (vb->memory) {
431 case V4L2_MEMORY_MMAP:
432 case V4L2_MEMORY_OVERLAY:
433 vb->m.offset = vb32.m.offset;
435 case V4L2_MEMORY_USERPTR:
436 vb->m.userptr = (unsigned long)compat_ptr(vb32.m.userptr);
438 case V4L2_MEMORY_DMABUF:
439 vb->m.fd = vb32.m.fd;
443 if (V4L2_TYPE_IS_MULTIPLANAR(vb->type))
444 vb->m.planes = (void __force *)
445 compat_ptr(vb32.m.planes);
450 #ifdef CONFIG_COMPAT_32BIT_TIME
451 static int get_v4l2_buffer32_time32(struct v4l2_buffer *vb,
452 struct v4l2_buffer32_time32 __user *arg)
454 struct v4l2_buffer32_time32 vb32;
456 if (copy_from_user(&vb32, arg, sizeof(vb32)))
459 *vb = (struct v4l2_buffer) {
462 .bytesused = vb32.bytesused,
465 .timestamp.tv_sec = vb32.timestamp.tv_sec,
466 .timestamp.tv_usec = vb32.timestamp.tv_usec,
467 .timecode = vb32.timecode,
468 .sequence = vb32.sequence,
469 .memory = vb32.memory,
470 .m.offset = vb32.m.offset,
471 .length = vb32.length,
472 .request_fd = vb32.request_fd,
474 switch (vb->memory) {
475 case V4L2_MEMORY_MMAP:
476 case V4L2_MEMORY_OVERLAY:
477 vb->m.offset = vb32.m.offset;
479 case V4L2_MEMORY_USERPTR:
480 vb->m.userptr = (unsigned long)compat_ptr(vb32.m.userptr);
482 case V4L2_MEMORY_DMABUF:
483 vb->m.fd = vb32.m.fd;
487 if (V4L2_TYPE_IS_MULTIPLANAR(vb->type))
488 vb->m.planes = (void __force *)
489 compat_ptr(vb32.m.planes);
495 static int put_v4l2_buffer32(struct v4l2_buffer *vb,
496 struct v4l2_buffer32 __user *arg)
498 struct v4l2_buffer32 vb32;
500 memset(&vb32, 0, sizeof(vb32));
501 vb32 = (struct v4l2_buffer32) {
504 .bytesused = vb->bytesused,
507 .timestamp.tv_sec = vb->timestamp.tv_sec,
508 .timestamp.tv_usec = vb->timestamp.tv_usec,
509 .timecode = vb->timecode,
510 .sequence = vb->sequence,
511 .memory = vb->memory,
512 .m.offset = vb->m.offset,
513 .length = vb->length,
514 .request_fd = vb->request_fd,
517 switch (vb->memory) {
518 case V4L2_MEMORY_MMAP:
519 case V4L2_MEMORY_OVERLAY:
520 vb32.m.offset = vb->m.offset;
522 case V4L2_MEMORY_USERPTR:
523 vb32.m.userptr = (uintptr_t)(vb->m.userptr);
525 case V4L2_MEMORY_DMABUF:
526 vb32.m.fd = vb->m.fd;
530 if (V4L2_TYPE_IS_MULTIPLANAR(vb->type))
531 vb32.m.planes = (uintptr_t)vb->m.planes;
533 if (copy_to_user(arg, &vb32, sizeof(vb32)))
539 #ifdef CONFIG_COMPAT_32BIT_TIME
540 static int put_v4l2_buffer32_time32(struct v4l2_buffer *vb,
541 struct v4l2_buffer32_time32 __user *arg)
543 struct v4l2_buffer32_time32 vb32;
545 memset(&vb32, 0, sizeof(vb32));
546 vb32 = (struct v4l2_buffer32_time32) {
549 .bytesused = vb->bytesused,
552 .timestamp.tv_sec = vb->timestamp.tv_sec,
553 .timestamp.tv_usec = vb->timestamp.tv_usec,
554 .timecode = vb->timecode,
555 .sequence = vb->sequence,
556 .memory = vb->memory,
557 .m.offset = vb->m.offset,
558 .length = vb->length,
559 .request_fd = vb->request_fd,
561 switch (vb->memory) {
562 case V4L2_MEMORY_MMAP:
563 case V4L2_MEMORY_OVERLAY:
564 vb32.m.offset = vb->m.offset;
566 case V4L2_MEMORY_USERPTR:
567 vb32.m.userptr = (uintptr_t)(vb->m.userptr);
569 case V4L2_MEMORY_DMABUF:
570 vb32.m.fd = vb->m.fd;
574 if (V4L2_TYPE_IS_MULTIPLANAR(vb->type))
575 vb32.m.planes = (uintptr_t)vb->m.planes;
577 if (copy_to_user(arg, &vb32, sizeof(vb32)))
584 struct v4l2_framebuffer32 {
600 static int get_v4l2_framebuffer32(struct v4l2_framebuffer *p64,
601 struct v4l2_framebuffer32 __user *p32)
605 if (get_user(tmp, &p32->base) ||
606 get_user(p64->capability, &p32->capability) ||
607 get_user(p64->flags, &p32->flags) ||
608 copy_from_user(&p64->fmt, &p32->fmt, sizeof(p64->fmt)))
610 p64->base = (void __force *)compat_ptr(tmp);
615 static int put_v4l2_framebuffer32(struct v4l2_framebuffer *p64,
616 struct v4l2_framebuffer32 __user *p32)
618 if (put_user((uintptr_t)p64->base, &p32->base) ||
619 put_user(p64->capability, &p32->capability) ||
620 put_user(p64->flags, &p32->flags) ||
621 copy_to_user(&p32->fmt, &p64->fmt, sizeof(p64->fmt)))
627 struct v4l2_input32 {
628 __u32 index; /* Which input */
629 __u8 name[32]; /* Label */
630 __u32 type; /* Type of input */
631 __u32 audioset; /* Associated audios (bitfield) */
632 __u32 tuner; /* Associated tuner */
640 * The 64-bit v4l2_input struct has extra padding at the end of the struct.
641 * Otherwise it is identical to the 32-bit version.
643 static inline int get_v4l2_input32(struct v4l2_input *p64,
644 struct v4l2_input32 __user *p32)
646 if (copy_from_user(p64, p32, sizeof(*p32)))
651 static inline int put_v4l2_input32(struct v4l2_input *p64,
652 struct v4l2_input32 __user *p32)
654 if (copy_to_user(p32, p64, sizeof(*p32)))
659 struct v4l2_ext_controls32 {
665 compat_caddr_t controls; /* actually struct v4l2_ext_control32 * */
668 struct v4l2_ext_control32 {
675 compat_caddr_t string; /* actually char * */
677 } __attribute__ ((packed));
679 /* Return true if this control is a pointer type. */
680 static inline bool ctrl_is_pointer(struct file *file, u32 id)
682 struct video_device *vdev = video_devdata(file);
683 struct v4l2_fh *fh = NULL;
684 struct v4l2_ctrl_handler *hdl = NULL;
685 struct v4l2_query_ext_ctrl qec = { id };
686 const struct v4l2_ioctl_ops *ops = vdev->ioctl_ops;
688 if (test_bit(V4L2_FL_USES_V4L2_FH, &vdev->flags))
689 fh = file->private_data;
691 if (fh && fh->ctrl_handler)
692 hdl = fh->ctrl_handler;
693 else if (vdev->ctrl_handler)
694 hdl = vdev->ctrl_handler;
697 struct v4l2_ctrl *ctrl = v4l2_ctrl_find(hdl, id);
699 return ctrl && ctrl->is_ptr;
702 if (!ops || !ops->vidioc_query_ext_ctrl)
705 return !ops->vidioc_query_ext_ctrl(file, fh, &qec) &&
706 (qec.flags & V4L2_CTRL_FLAG_HAS_PAYLOAD);
709 static int get_v4l2_ext_controls32(struct v4l2_ext_controls *p64,
710 struct v4l2_ext_controls32 __user *p32)
712 struct v4l2_ext_controls32 ec32;
714 if (copy_from_user(&ec32, p32, sizeof(ec32)))
717 *p64 = (struct v4l2_ext_controls) {
720 .error_idx = ec32.error_idx,
721 .request_fd = ec32.request_fd,
722 .reserved[0] = ec32.reserved[0],
723 .controls = (void __force *)compat_ptr(ec32.controls),
729 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *p64,
730 struct v4l2_ext_controls32 __user *p32)
732 struct v4l2_ext_controls32 ec32;
734 memset(&ec32, 0, sizeof(ec32));
735 ec32 = (struct v4l2_ext_controls32) {
738 .error_idx = p64->error_idx,
739 .request_fd = p64->request_fd,
740 .reserved[0] = p64->reserved[0],
741 .controls = (uintptr_t)p64->controls,
744 if (copy_to_user(p32, &ec32, sizeof(ec32)))
752 * x86 is the only compat architecture with different struct alignment
753 * between 32-bit and 64-bit tasks.
755 struct v4l2_event32 {
771 static int put_v4l2_event32(struct v4l2_event *p64,
772 struct v4l2_event32 __user *p32)
774 if (put_user(p64->type, &p32->type) ||
775 copy_to_user(&p32->u, &p64->u, sizeof(p64->u)) ||
776 put_user(p64->pending, &p32->pending) ||
777 put_user(p64->sequence, &p32->sequence) ||
778 put_user(p64->timestamp.tv_sec, &p32->timestamp.tv_sec) ||
779 put_user(p64->timestamp.tv_nsec, &p32->timestamp.tv_nsec) ||
780 put_user(p64->id, &p32->id) ||
781 copy_to_user(p32->reserved, p64->reserved, sizeof(p32->reserved)))
788 #ifdef CONFIG_COMPAT_32BIT_TIME
789 struct v4l2_event32_time32 {
797 struct old_timespec32 timestamp;
802 static int put_v4l2_event32_time32(struct v4l2_event *p64,
803 struct v4l2_event32_time32 __user *p32)
805 if (put_user(p64->type, &p32->type) ||
806 copy_to_user(&p32->u, &p64->u, sizeof(p64->u)) ||
807 put_user(p64->pending, &p32->pending) ||
808 put_user(p64->sequence, &p32->sequence) ||
809 put_user(p64->timestamp.tv_sec, &p32->timestamp.tv_sec) ||
810 put_user(p64->timestamp.tv_nsec, &p32->timestamp.tv_nsec) ||
811 put_user(p64->id, &p32->id) ||
812 copy_to_user(p32->reserved, p64->reserved, sizeof(p32->reserved)))
826 static int get_v4l2_edid32(struct v4l2_edid *p64,
827 struct v4l2_edid32 __user *p32)
831 if (copy_from_user(p64, p32, offsetof(struct v4l2_edid32, edid)) ||
832 get_user(edid, &p32->edid))
835 p64->edid = (void __force *)compat_ptr(edid);
839 static int put_v4l2_edid32(struct v4l2_edid *p64,
840 struct v4l2_edid32 __user *p32)
842 if (copy_to_user(p32, p64, offsetof(struct v4l2_edid32, edid)))
848 * List of ioctls that require 32-bits/64-bits conversion
850 * The V4L2 ioctls that aren't listed there don't have pointer arguments
851 * and the struct size is identical for both 32 and 64 bits versions, so
852 * they don't need translations.
855 #define VIDIOC_G_FMT32 _IOWR('V', 4, struct v4l2_format32)
856 #define VIDIOC_S_FMT32 _IOWR('V', 5, struct v4l2_format32)
857 #define VIDIOC_QUERYBUF32 _IOWR('V', 9, struct v4l2_buffer32)
858 #define VIDIOC_G_FBUF32 _IOR ('V', 10, struct v4l2_framebuffer32)
859 #define VIDIOC_S_FBUF32 _IOW ('V', 11, struct v4l2_framebuffer32)
860 #define VIDIOC_QBUF32 _IOWR('V', 15, struct v4l2_buffer32)
861 #define VIDIOC_DQBUF32 _IOWR('V', 17, struct v4l2_buffer32)
862 #define VIDIOC_ENUMSTD32 _IOWR('V', 25, struct v4l2_standard32)
863 #define VIDIOC_ENUMINPUT32 _IOWR('V', 26, struct v4l2_input32)
864 #define VIDIOC_G_EDID32 _IOWR('V', 40, struct v4l2_edid32)
865 #define VIDIOC_S_EDID32 _IOWR('V', 41, struct v4l2_edid32)
866 #define VIDIOC_TRY_FMT32 _IOWR('V', 64, struct v4l2_format32)
867 #define VIDIOC_G_EXT_CTRLS32 _IOWR('V', 71, struct v4l2_ext_controls32)
868 #define VIDIOC_S_EXT_CTRLS32 _IOWR('V', 72, struct v4l2_ext_controls32)
869 #define VIDIOC_TRY_EXT_CTRLS32 _IOWR('V', 73, struct v4l2_ext_controls32)
870 #define VIDIOC_DQEVENT32 _IOR ('V', 89, struct v4l2_event32)
871 #define VIDIOC_CREATE_BUFS32 _IOWR('V', 92, struct v4l2_create_buffers32)
872 #define VIDIOC_PREPARE_BUF32 _IOWR('V', 93, struct v4l2_buffer32)
874 #ifdef CONFIG_COMPAT_32BIT_TIME
875 #define VIDIOC_QUERYBUF32_TIME32 _IOWR('V', 9, struct v4l2_buffer32_time32)
876 #define VIDIOC_QBUF32_TIME32 _IOWR('V', 15, struct v4l2_buffer32_time32)
877 #define VIDIOC_DQBUF32_TIME32 _IOWR('V', 17, struct v4l2_buffer32_time32)
878 #define VIDIOC_DQEVENT32_TIME32 _IOR ('V', 89, struct v4l2_event32_time32)
879 #define VIDIOC_PREPARE_BUF32_TIME32 _IOWR('V', 93, struct v4l2_buffer32_time32)
882 unsigned int v4l2_compat_translate_cmd(unsigned int cmd)
889 case VIDIOC_TRY_FMT32:
890 return VIDIOC_TRY_FMT;
891 case VIDIOC_G_FBUF32:
892 return VIDIOC_G_FBUF;
893 case VIDIOC_S_FBUF32:
894 return VIDIOC_S_FBUF;
895 #ifdef CONFIG_COMPAT_32BIT_TIME
896 case VIDIOC_QUERYBUF32_TIME32:
897 return VIDIOC_QUERYBUF;
898 case VIDIOC_QBUF32_TIME32:
900 case VIDIOC_DQBUF32_TIME32:
902 case VIDIOC_PREPARE_BUF32_TIME32:
903 return VIDIOC_PREPARE_BUF;
905 case VIDIOC_QUERYBUF32:
906 return VIDIOC_QUERYBUF;
911 case VIDIOC_CREATE_BUFS32:
912 return VIDIOC_CREATE_BUFS;
913 case VIDIOC_G_EXT_CTRLS32:
914 return VIDIOC_G_EXT_CTRLS;
915 case VIDIOC_S_EXT_CTRLS32:
916 return VIDIOC_S_EXT_CTRLS;
917 case VIDIOC_TRY_EXT_CTRLS32:
918 return VIDIOC_TRY_EXT_CTRLS;
919 case VIDIOC_PREPARE_BUF32:
920 return VIDIOC_PREPARE_BUF;
921 case VIDIOC_ENUMSTD32:
922 return VIDIOC_ENUMSTD;
923 case VIDIOC_ENUMINPUT32:
924 return VIDIOC_ENUMINPUT;
925 case VIDIOC_G_EDID32:
926 return VIDIOC_G_EDID;
927 case VIDIOC_S_EDID32:
928 return VIDIOC_S_EDID;
930 case VIDIOC_DQEVENT32:
931 return VIDIOC_DQEVENT;
933 #ifdef CONFIG_COMPAT_32BIT_TIME
934 case VIDIOC_DQEVENT32_TIME32:
935 return VIDIOC_DQEVENT;
941 int v4l2_compat_get_user(void __user *arg, void *parg, unsigned int cmd)
946 case VIDIOC_TRY_FMT32:
947 return get_v4l2_format32(parg, arg);
949 case VIDIOC_S_FBUF32:
950 return get_v4l2_framebuffer32(parg, arg);
951 #ifdef CONFIG_COMPAT_32BIT_TIME
952 case VIDIOC_QUERYBUF32_TIME32:
953 case VIDIOC_QBUF32_TIME32:
954 case VIDIOC_DQBUF32_TIME32:
955 case VIDIOC_PREPARE_BUF32_TIME32:
956 return get_v4l2_buffer32_time32(parg, arg);
958 case VIDIOC_QUERYBUF32:
961 case VIDIOC_PREPARE_BUF32:
962 return get_v4l2_buffer32(parg, arg);
964 case VIDIOC_G_EXT_CTRLS32:
965 case VIDIOC_S_EXT_CTRLS32:
966 case VIDIOC_TRY_EXT_CTRLS32:
967 return get_v4l2_ext_controls32(parg, arg);
969 case VIDIOC_CREATE_BUFS32:
970 return get_v4l2_create32(parg, arg);
972 case VIDIOC_ENUMSTD32:
973 return get_v4l2_standard32(parg, arg);
975 case VIDIOC_ENUMINPUT32:
976 return get_v4l2_input32(parg, arg);
978 case VIDIOC_G_EDID32:
979 case VIDIOC_S_EDID32:
980 return get_v4l2_edid32(parg, arg);
985 int v4l2_compat_put_user(void __user *arg, void *parg, unsigned int cmd)
990 case VIDIOC_TRY_FMT32:
991 return put_v4l2_format32(parg, arg);
993 case VIDIOC_G_FBUF32:
994 return put_v4l2_framebuffer32(parg, arg);
995 #ifdef CONFIG_COMPAT_32BIT_TIME
996 case VIDIOC_QUERYBUF32_TIME32:
997 case VIDIOC_QBUF32_TIME32:
998 case VIDIOC_DQBUF32_TIME32:
999 case VIDIOC_PREPARE_BUF32_TIME32:
1000 return put_v4l2_buffer32_time32(parg, arg);
1002 case VIDIOC_QUERYBUF32:
1004 case VIDIOC_DQBUF32:
1005 case VIDIOC_PREPARE_BUF32:
1006 return put_v4l2_buffer32(parg, arg);
1008 case VIDIOC_G_EXT_CTRLS32:
1009 case VIDIOC_S_EXT_CTRLS32:
1010 case VIDIOC_TRY_EXT_CTRLS32:
1011 return put_v4l2_ext_controls32(parg, arg);
1013 case VIDIOC_CREATE_BUFS32:
1014 return put_v4l2_create32(parg, arg);
1016 case VIDIOC_ENUMSTD32:
1017 return put_v4l2_standard32(parg, arg);
1019 case VIDIOC_ENUMINPUT32:
1020 return put_v4l2_input32(parg, arg);
1022 case VIDIOC_G_EDID32:
1023 case VIDIOC_S_EDID32:
1024 return put_v4l2_edid32(parg, arg);
1025 #ifdef CONFIG_X86_64
1026 case VIDIOC_DQEVENT32:
1027 return put_v4l2_event32(parg, arg);
1029 #ifdef CONFIG_COMPAT_32BIT_TIME
1030 case VIDIOC_DQEVENT32_TIME32:
1031 return put_v4l2_event32_time32(parg, arg);
1037 int v4l2_compat_get_array_args(struct file *file, void *mbuf,
1038 void __user *user_ptr, size_t array_size,
1039 unsigned int cmd, void *arg)
1043 memset(mbuf, 0, array_size);
1046 case VIDIOC_G_FMT32:
1047 case VIDIOC_S_FMT32:
1048 case VIDIOC_TRY_FMT32: {
1049 struct v4l2_format *f64 = arg;
1050 struct v4l2_clip *c64 = mbuf;
1051 struct v4l2_clip32 __user *c32 = user_ptr;
1052 u32 clipcount = f64->fmt.win.clipcount;
1054 if ((f64->type != V4L2_BUF_TYPE_VIDEO_OVERLAY &&
1055 f64->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY) ||
1058 if (clipcount > 2048)
1060 while (clipcount--) {
1061 if (copy_from_user(c64, c32, sizeof(c64->c)))
1069 #ifdef CONFIG_COMPAT_32BIT_TIME
1070 case VIDIOC_QUERYBUF32_TIME32:
1071 case VIDIOC_QBUF32_TIME32:
1072 case VIDIOC_DQBUF32_TIME32:
1073 case VIDIOC_PREPARE_BUF32_TIME32:
1075 case VIDIOC_QUERYBUF32:
1077 case VIDIOC_DQBUF32:
1078 case VIDIOC_PREPARE_BUF32: {
1079 struct v4l2_buffer *b64 = arg;
1080 struct v4l2_plane *p64 = mbuf;
1081 struct v4l2_plane32 __user *p32 = user_ptr;
1083 if (V4L2_TYPE_IS_MULTIPLANAR(b64->type)) {
1084 u32 num_planes = b64->length;
1086 if (num_planes == 0)
1089 while (num_planes--) {
1090 err = get_v4l2_plane32(p64, p32, b64->memory);
1099 case VIDIOC_G_EXT_CTRLS32:
1100 case VIDIOC_S_EXT_CTRLS32:
1101 case VIDIOC_TRY_EXT_CTRLS32: {
1102 struct v4l2_ext_controls *ecs64 = arg;
1103 struct v4l2_ext_control *ec64 = mbuf;
1104 struct v4l2_ext_control32 __user *ec32 = user_ptr;
1107 for (n = 0; n < ecs64->count; n++) {
1108 if (copy_from_user(ec64, ec32, sizeof(*ec32)))
1111 if (ctrl_is_pointer(file, ec64->id)) {
1114 if (get_user(p, &ec32->string))
1116 ec64->string = compat_ptr(p);
1124 if (copy_from_user(mbuf, user_ptr, array_size))
1132 int v4l2_compat_put_array_args(struct file *file, void __user *user_ptr,
1133 void *mbuf, size_t array_size,
1134 unsigned int cmd, void *arg)
1139 case VIDIOC_G_FMT32:
1140 case VIDIOC_S_FMT32:
1141 case VIDIOC_TRY_FMT32: {
1142 struct v4l2_format *f64 = arg;
1143 struct v4l2_clip *c64 = mbuf;
1144 struct v4l2_clip32 __user *c32 = user_ptr;
1145 u32 clipcount = f64->fmt.win.clipcount;
1147 if ((f64->type != V4L2_BUF_TYPE_VIDEO_OVERLAY &&
1148 f64->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY) ||
1151 if (clipcount > 2048)
1153 while (clipcount--) {
1154 if (copy_to_user(c32, c64, sizeof(c64->c)))
1161 #ifdef CONFIG_COMPAT_32BIT_TIME
1162 case VIDIOC_QUERYBUF32_TIME32:
1163 case VIDIOC_QBUF32_TIME32:
1164 case VIDIOC_DQBUF32_TIME32:
1165 case VIDIOC_PREPARE_BUF32_TIME32:
1167 case VIDIOC_QUERYBUF32:
1169 case VIDIOC_DQBUF32:
1170 case VIDIOC_PREPARE_BUF32: {
1171 struct v4l2_buffer *b64 = arg;
1172 struct v4l2_plane *p64 = mbuf;
1173 struct v4l2_plane32 __user *p32 = user_ptr;
1175 if (V4L2_TYPE_IS_MULTIPLANAR(b64->type)) {
1176 u32 num_planes = b64->length;
1178 if (num_planes == 0)
1181 while (num_planes--) {
1182 err = put_v4l2_plane32(p64, p32, b64->memory);
1191 case VIDIOC_G_EXT_CTRLS32:
1192 case VIDIOC_S_EXT_CTRLS32:
1193 case VIDIOC_TRY_EXT_CTRLS32: {
1194 struct v4l2_ext_controls *ecs64 = arg;
1195 struct v4l2_ext_control *ec64 = mbuf;
1196 struct v4l2_ext_control32 __user *ec32 = user_ptr;
1199 for (n = 0; n < ecs64->count; n++) {
1200 unsigned int size = sizeof(*ec32);
1202 * Do not modify the pointer when copying a pointer
1203 * control. The contents of the pointer was changed,
1204 * not the pointer itself.
1205 * The structures are otherwise compatible.
1207 if (ctrl_is_pointer(file, ec64->id))
1208 size -= sizeof(ec32->value64);
1210 if (copy_to_user(ec32, ec64, size))
1219 if (copy_to_user(user_ptr, mbuf, array_size))
1228 * v4l2_compat_ioctl32() - Handles a compat32 ioctl call
1230 * @file: pointer to &struct file with the file handler
1231 * @cmd: ioctl to be called
1232 * @arg: arguments passed from/to the ioctl handler
1234 * This function is meant to be used as .compat_ioctl fops at v4l2-dev.c
1235 * in order to deal with 32-bit calls on a 64-bits Kernel.
1237 * This function calls do_video_ioctl() for non-private V4L2 ioctls.
1238 * If the function is a private one it calls vdev->fops->compat_ioctl32
1241 long v4l2_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)
1243 struct video_device *vdev = video_devdata(file);
1244 long ret = -ENOIOCTLCMD;
1246 if (!file->f_op->unlocked_ioctl)
1249 if (!video_is_registered(vdev))
1252 if (_IOC_TYPE(cmd) == 'V' && _IOC_NR(cmd) < BASE_VIDIOC_PRIVATE)
1253 ret = file->f_op->unlocked_ioctl(file, cmd,
1254 (unsigned long)compat_ptr(arg));
1255 else if (vdev->fops->compat_ioctl32)
1256 ret = vdev->fops->compat_ioctl32(file, cmd, arg);
1258 if (ret == -ENOIOCTLCMD)
1259 pr_debug("compat_ioctl32: unknown ioctl '%c', dir=%d, #%d (0x%08x)\n",
1260 _IOC_TYPE(cmd), _IOC_DIR(cmd), _IOC_NR(cmd), cmd);
1263 EXPORT_SYMBOL_GPL(v4l2_compat_ioctl32);