2 * Video capture interface for Linux version 2
4 * A generic framework to process V4L2 ioctl commands.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
11 * Authors: Alan Cox, <alan@lxorguk.ukuu.org.uk> (version 1)
12 * Mauro Carvalho Chehab <mchehab@infradead.org> (version 2)
15 #include <linux/module.h>
16 #include <linux/slab.h>
17 #include <linux/types.h>
18 #include <linux/kernel.h>
19 #include <linux/version.h>
21 #include <linux/videodev2.h>
23 #include <media/v4l2-common.h>
24 #include <media/v4l2-ioctl.h>
25 #include <media/v4l2-ctrls.h>
26 #include <media/v4l2-fh.h>
27 #include <media/v4l2-event.h>
28 #include <media/v4l2-device.h>
29 #include <media/v4l2-chip-ident.h>
31 #define dbgarg(cmd, fmt, arg...) \
33 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \
34 printk(KERN_DEBUG "%s: ", vfd->name); \
35 v4l_printk_ioctl(cmd); \
36 printk(" " fmt, ## arg); \
40 #define dbgarg2(fmt, arg...) \
42 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
43 printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\
46 #define dbgarg3(fmt, arg...) \
48 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
49 printk(KERN_CONT "%s: " fmt, vfd->name, ## arg);\
52 /* Zero out the end of the struct pointed to by p. Everything after, but
53 * not including, the specified field is cleared. */
54 #define CLEAR_AFTER_FIELD(p, field) \
55 memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \
56 0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field))
63 static const struct std_descr standards[] = {
64 { V4L2_STD_NTSC, "NTSC" },
65 { V4L2_STD_NTSC_M, "NTSC-M" },
66 { V4L2_STD_NTSC_M_JP, "NTSC-M-JP" },
67 { V4L2_STD_NTSC_M_KR, "NTSC-M-KR" },
68 { V4L2_STD_NTSC_443, "NTSC-443" },
69 { V4L2_STD_PAL, "PAL" },
70 { V4L2_STD_PAL_BG, "PAL-BG" },
71 { V4L2_STD_PAL_B, "PAL-B" },
72 { V4L2_STD_PAL_B1, "PAL-B1" },
73 { V4L2_STD_PAL_G, "PAL-G" },
74 { V4L2_STD_PAL_H, "PAL-H" },
75 { V4L2_STD_PAL_I, "PAL-I" },
76 { V4L2_STD_PAL_DK, "PAL-DK" },
77 { V4L2_STD_PAL_D, "PAL-D" },
78 { V4L2_STD_PAL_D1, "PAL-D1" },
79 { V4L2_STD_PAL_K, "PAL-K" },
80 { V4L2_STD_PAL_M, "PAL-M" },
81 { V4L2_STD_PAL_N, "PAL-N" },
82 { V4L2_STD_PAL_Nc, "PAL-Nc" },
83 { V4L2_STD_PAL_60, "PAL-60" },
84 { V4L2_STD_SECAM, "SECAM" },
85 { V4L2_STD_SECAM_B, "SECAM-B" },
86 { V4L2_STD_SECAM_G, "SECAM-G" },
87 { V4L2_STD_SECAM_H, "SECAM-H" },
88 { V4L2_STD_SECAM_DK, "SECAM-DK" },
89 { V4L2_STD_SECAM_D, "SECAM-D" },
90 { V4L2_STD_SECAM_K, "SECAM-K" },
91 { V4L2_STD_SECAM_K1, "SECAM-K1" },
92 { V4L2_STD_SECAM_L, "SECAM-L" },
93 { V4L2_STD_SECAM_LC, "SECAM-Lc" },
97 /* video4linux standard ID conversion to standard name
99 const char *v4l2_norm_to_name(v4l2_std_id id)
104 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
105 64 bit comparations. So, on that architecture, with some gcc
106 variants, compilation fails. Currently, the max value is 30bit wide.
110 for (i = 0; standards[i].std; i++)
111 if (myid == standards[i].std)
113 return standards[i].descr;
115 EXPORT_SYMBOL(v4l2_norm_to_name);
117 /* Returns frame period for the given standard */
118 void v4l2_video_std_frame_period(int id, struct v4l2_fract *frameperiod)
120 if (id & V4L2_STD_525_60) {
121 frameperiod->numerator = 1001;
122 frameperiod->denominator = 30000;
124 frameperiod->numerator = 1;
125 frameperiod->denominator = 25;
128 EXPORT_SYMBOL(v4l2_video_std_frame_period);
130 /* Fill in the fields of a v4l2_standard structure according to the
131 'id' and 'transmission' parameters. Returns negative on error. */
132 int v4l2_video_std_construct(struct v4l2_standard *vs,
133 int id, const char *name)
136 v4l2_video_std_frame_period(id, &vs->frameperiod);
137 vs->framelines = (id & V4L2_STD_525_60) ? 525 : 625;
138 strlcpy(vs->name, name, sizeof(vs->name));
141 EXPORT_SYMBOL(v4l2_video_std_construct);
143 /* ----------------------------------------------------------------- */
144 /* some arrays for pretty-printing debug messages of enum types */
146 const char *v4l2_field_names[] = {
147 [V4L2_FIELD_ANY] = "any",
148 [V4L2_FIELD_NONE] = "none",
149 [V4L2_FIELD_TOP] = "top",
150 [V4L2_FIELD_BOTTOM] = "bottom",
151 [V4L2_FIELD_INTERLACED] = "interlaced",
152 [V4L2_FIELD_SEQ_TB] = "seq-tb",
153 [V4L2_FIELD_SEQ_BT] = "seq-bt",
154 [V4L2_FIELD_ALTERNATE] = "alternate",
155 [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
156 [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
158 EXPORT_SYMBOL(v4l2_field_names);
160 const char *v4l2_type_names[] = {
161 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "vid-cap",
162 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "vid-overlay",
163 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "vid-out",
164 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
165 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
166 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
167 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out",
168 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "vid-out-overlay",
169 [V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE] = "vid-cap-mplane",
170 [V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE] = "vid-out-mplane",
172 EXPORT_SYMBOL(v4l2_type_names);
174 static const char *v4l2_memory_names[] = {
175 [V4L2_MEMORY_MMAP] = "mmap",
176 [V4L2_MEMORY_USERPTR] = "userptr",
177 [V4L2_MEMORY_OVERLAY] = "overlay",
178 [V4L2_MEMORY_DMABUF] = "dmabuf",
181 #define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
184 /* ------------------------------------------------------------------ */
185 /* debug help functions */
187 struct v4l2_ioctl_info {
190 const char * const name;
193 /* This control needs a priority check */
194 #define INFO_FL_PRIO (1 << 0)
195 /* This control can be valid if the filehandle passes a control handler. */
196 #define INFO_FL_CTRL (1 << 1)
198 #define IOCTL_INFO(_ioctl, _flags) [_IOC_NR(_ioctl)] = { \
204 static struct v4l2_ioctl_info v4l2_ioctls[] = {
205 IOCTL_INFO(VIDIOC_QUERYCAP, 0),
206 IOCTL_INFO(VIDIOC_ENUM_FMT, 0),
207 IOCTL_INFO(VIDIOC_G_FMT, 0),
208 IOCTL_INFO(VIDIOC_S_FMT, INFO_FL_PRIO),
209 IOCTL_INFO(VIDIOC_REQBUFS, INFO_FL_PRIO),
210 IOCTL_INFO(VIDIOC_QUERYBUF, 0),
211 IOCTL_INFO(VIDIOC_G_FBUF, 0),
212 IOCTL_INFO(VIDIOC_S_FBUF, INFO_FL_PRIO),
213 IOCTL_INFO(VIDIOC_OVERLAY, INFO_FL_PRIO),
214 IOCTL_INFO(VIDIOC_QBUF, 0),
215 IOCTL_INFO(VIDIOC_EXPBUF, 0),
216 IOCTL_INFO(VIDIOC_DQBUF, 0),
217 IOCTL_INFO(VIDIOC_STREAMON, INFO_FL_PRIO),
218 IOCTL_INFO(VIDIOC_STREAMOFF, INFO_FL_PRIO),
219 IOCTL_INFO(VIDIOC_G_PARM, 0),
220 IOCTL_INFO(VIDIOC_S_PARM, INFO_FL_PRIO),
221 IOCTL_INFO(VIDIOC_G_STD, 0),
222 IOCTL_INFO(VIDIOC_S_STD, INFO_FL_PRIO),
223 IOCTL_INFO(VIDIOC_ENUMSTD, 0),
224 IOCTL_INFO(VIDIOC_ENUMINPUT, 0),
225 IOCTL_INFO(VIDIOC_G_CTRL, INFO_FL_CTRL),
226 IOCTL_INFO(VIDIOC_S_CTRL, INFO_FL_PRIO | INFO_FL_CTRL),
227 IOCTL_INFO(VIDIOC_G_TUNER, 0),
228 IOCTL_INFO(VIDIOC_S_TUNER, INFO_FL_PRIO),
229 IOCTL_INFO(VIDIOC_G_AUDIO, 0),
230 IOCTL_INFO(VIDIOC_S_AUDIO, INFO_FL_PRIO),
231 IOCTL_INFO(VIDIOC_QUERYCTRL, INFO_FL_CTRL),
232 IOCTL_INFO(VIDIOC_QUERYMENU, INFO_FL_CTRL),
233 IOCTL_INFO(VIDIOC_G_INPUT, 0),
234 IOCTL_INFO(VIDIOC_S_INPUT, INFO_FL_PRIO),
235 IOCTL_INFO(VIDIOC_G_OUTPUT, 0),
236 IOCTL_INFO(VIDIOC_S_OUTPUT, INFO_FL_PRIO),
237 IOCTL_INFO(VIDIOC_ENUMOUTPUT, 0),
238 IOCTL_INFO(VIDIOC_G_AUDOUT, 0),
239 IOCTL_INFO(VIDIOC_S_AUDOUT, INFO_FL_PRIO),
240 IOCTL_INFO(VIDIOC_G_MODULATOR, 0),
241 IOCTL_INFO(VIDIOC_S_MODULATOR, INFO_FL_PRIO),
242 IOCTL_INFO(VIDIOC_G_FREQUENCY, 0),
243 IOCTL_INFO(VIDIOC_S_FREQUENCY, INFO_FL_PRIO),
244 IOCTL_INFO(VIDIOC_CROPCAP, 0),
245 IOCTL_INFO(VIDIOC_G_CROP, 0),
246 IOCTL_INFO(VIDIOC_S_CROP, INFO_FL_PRIO),
247 IOCTL_INFO(VIDIOC_G_SELECTION, 0),
248 IOCTL_INFO(VIDIOC_S_SELECTION, INFO_FL_PRIO),
249 IOCTL_INFO(VIDIOC_G_JPEGCOMP, 0),
250 IOCTL_INFO(VIDIOC_S_JPEGCOMP, INFO_FL_PRIO),
251 IOCTL_INFO(VIDIOC_QUERYSTD, 0),
252 IOCTL_INFO(VIDIOC_TRY_FMT, 0),
253 IOCTL_INFO(VIDIOC_ENUMAUDIO, 0),
254 IOCTL_INFO(VIDIOC_ENUMAUDOUT, 0),
255 IOCTL_INFO(VIDIOC_G_PRIORITY, 0),
256 IOCTL_INFO(VIDIOC_S_PRIORITY, INFO_FL_PRIO),
257 IOCTL_INFO(VIDIOC_G_SLICED_VBI_CAP, 0),
258 IOCTL_INFO(VIDIOC_LOG_STATUS, 0),
259 IOCTL_INFO(VIDIOC_G_EXT_CTRLS, INFO_FL_CTRL),
260 IOCTL_INFO(VIDIOC_S_EXT_CTRLS, INFO_FL_PRIO | INFO_FL_CTRL),
261 IOCTL_INFO(VIDIOC_TRY_EXT_CTRLS, 0),
262 IOCTL_INFO(VIDIOC_ENUM_FRAMESIZES, 0),
263 IOCTL_INFO(VIDIOC_ENUM_FRAMEINTERVALS, 0),
264 IOCTL_INFO(VIDIOC_G_ENC_INDEX, 0),
265 IOCTL_INFO(VIDIOC_ENCODER_CMD, INFO_FL_PRIO),
266 IOCTL_INFO(VIDIOC_TRY_ENCODER_CMD, 0),
267 IOCTL_INFO(VIDIOC_DECODER_CMD, INFO_FL_PRIO),
268 IOCTL_INFO(VIDIOC_TRY_DECODER_CMD, 0),
269 #ifdef CONFIG_VIDEO_ADV_DEBUG
270 IOCTL_INFO(VIDIOC_DBG_S_REGISTER, 0),
271 IOCTL_INFO(VIDIOC_DBG_G_REGISTER, 0),
273 IOCTL_INFO(VIDIOC_DBG_G_CHIP_IDENT, 0),
274 IOCTL_INFO(VIDIOC_S_HW_FREQ_SEEK, INFO_FL_PRIO),
275 IOCTL_INFO(VIDIOC_ENUM_DV_PRESETS, 0),
276 IOCTL_INFO(VIDIOC_S_DV_PRESET, INFO_FL_PRIO),
277 IOCTL_INFO(VIDIOC_G_DV_PRESET, 0),
278 IOCTL_INFO(VIDIOC_QUERY_DV_PRESET, 0),
279 IOCTL_INFO(VIDIOC_S_DV_TIMINGS, INFO_FL_PRIO),
280 IOCTL_INFO(VIDIOC_G_DV_TIMINGS, 0),
281 IOCTL_INFO(VIDIOC_DQEVENT, 0),
282 IOCTL_INFO(VIDIOC_SUBSCRIBE_EVENT, 0),
283 IOCTL_INFO(VIDIOC_UNSUBSCRIBE_EVENT, 0),
284 IOCTL_INFO(VIDIOC_CREATE_BUFS, INFO_FL_PRIO),
285 IOCTL_INFO(VIDIOC_PREPARE_BUF, 0),
287 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
289 bool v4l2_is_known_ioctl(unsigned int cmd)
291 if (_IOC_NR(cmd) >= V4L2_IOCTLS)
293 return v4l2_ioctls[_IOC_NR(cmd)].ioctl == cmd;
296 /* Common ioctl debug function. This function can be used by
297 external ioctl messages as well as internal V4L ioctl */
298 void v4l_printk_ioctl(unsigned int cmd)
302 switch (_IOC_TYPE(cmd)) {
307 if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
311 printk("%s", v4l2_ioctls[_IOC_NR(cmd)].name);
317 switch (_IOC_DIR(cmd)) {
318 case _IOC_NONE: dir = "--"; break;
319 case _IOC_READ: dir = "r-"; break;
320 case _IOC_WRITE: dir = "-w"; break;
321 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
322 default: dir = "*ERR*"; break;
324 printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
325 type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
327 EXPORT_SYMBOL(v4l_printk_ioctl);
329 static void dbgbuf(unsigned int cmd, struct video_device *vfd,
330 struct v4l2_buffer *p)
332 struct v4l2_timecode *tc = &p->timecode;
333 struct v4l2_plane *plane;
336 dbgarg(cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
337 "flags=0x%08d, field=%0d, sequence=%d, memory=%s\n",
338 p->timestamp.tv_sec / 3600,
339 (int)(p->timestamp.tv_sec / 60) % 60,
340 (int)(p->timestamp.tv_sec % 60),
341 (long)p->timestamp.tv_usec,
343 prt_names(p->type, v4l2_type_names),
344 p->flags, p->field, p->sequence,
345 prt_names(p->memory, v4l2_memory_names));
347 if (V4L2_TYPE_IS_MULTIPLANAR(p->type) && p->m.planes) {
348 for (i = 0; i < p->length; ++i) {
349 plane = &p->m.planes[i];
350 dbgarg2("plane %d: bytesused=%d, data_offset=0x%08x "
351 "offset/userptr=0x%08lx, length=%d\n",
352 i, plane->bytesused, plane->data_offset,
353 plane->m.userptr, plane->length);
356 dbgarg2("bytesused=%d, offset/userptr=0x%08lx, length=%d\n",
357 p->bytesused, p->m.userptr, p->length);
360 dbgarg2("timecode=%02d:%02d:%02d type=%d, "
361 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
362 tc->hours, tc->minutes, tc->seconds,
363 tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits);
366 static inline void dbgrect(struct video_device *vfd, char *s,
369 dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s, r->left, r->top,
370 r->width, r->height);
373 static inline void v4l_print_pix_fmt(struct video_device *vfd,
374 struct v4l2_pix_format *fmt)
376 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
377 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
378 fmt->width, fmt->height,
379 (fmt->pixelformat & 0xff),
380 (fmt->pixelformat >> 8) & 0xff,
381 (fmt->pixelformat >> 16) & 0xff,
382 (fmt->pixelformat >> 24) & 0xff,
383 prt_names(fmt->field, v4l2_field_names),
384 fmt->bytesperline, fmt->sizeimage, fmt->colorspace);
387 static inline void v4l_print_pix_fmt_mplane(struct video_device *vfd,
388 struct v4l2_pix_format_mplane *fmt)
392 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
393 "colorspace=%d, num_planes=%d\n",
394 fmt->width, fmt->height,
395 (fmt->pixelformat & 0xff),
396 (fmt->pixelformat >> 8) & 0xff,
397 (fmt->pixelformat >> 16) & 0xff,
398 (fmt->pixelformat >> 24) & 0xff,
399 prt_names(fmt->field, v4l2_field_names),
400 fmt->colorspace, fmt->num_planes);
402 for (i = 0; i < fmt->num_planes; ++i)
403 dbgarg2("plane %d: bytesperline=%d sizeimage=%d\n", i,
404 fmt->plane_fmt[i].bytesperline,
405 fmt->plane_fmt[i].sizeimage);
408 static inline void v4l_print_ext_ctrls(unsigned int cmd,
409 struct video_device *vfd, struct v4l2_ext_controls *c, int show_vals)
413 if (!(vfd->debug & V4L2_DEBUG_IOCTL_ARG))
416 printk(KERN_CONT "class=0x%x", c->ctrl_class);
417 for (i = 0; i < c->count; i++) {
418 if (show_vals && !c->controls[i].size)
419 printk(KERN_CONT " id/val=0x%x/0x%x",
420 c->controls[i].id, c->controls[i].value);
422 printk(KERN_CONT " id=0x%x,size=%u",
423 c->controls[i].id, c->controls[i].size);
425 printk(KERN_CONT "\n");
428 static inline int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
432 /* zero the reserved fields */
433 c->reserved[0] = c->reserved[1] = 0;
434 for (i = 0; i < c->count; i++)
435 c->controls[i].reserved2[0] = 0;
437 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
438 when using extended controls.
439 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
440 is it allowed for backwards compatibility.
442 if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE)
444 /* Check that all controls are from the same control class. */
445 for (i = 0; i < c->count; i++) {
446 if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) {
454 static int check_fmt(const struct v4l2_ioctl_ops *ops, enum v4l2_buf_type type)
460 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
461 if (ops->vidioc_g_fmt_vid_cap ||
462 ops->vidioc_g_fmt_vid_cap_mplane)
465 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
466 if (ops->vidioc_g_fmt_vid_cap_mplane)
469 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
470 if (ops->vidioc_g_fmt_vid_overlay)
473 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
474 if (ops->vidioc_g_fmt_vid_out ||
475 ops->vidioc_g_fmt_vid_out_mplane)
478 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
479 if (ops->vidioc_g_fmt_vid_out_mplane)
482 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
483 if (ops->vidioc_g_fmt_vid_out_overlay)
486 case V4L2_BUF_TYPE_VBI_CAPTURE:
487 if (ops->vidioc_g_fmt_vbi_cap)
490 case V4L2_BUF_TYPE_VBI_OUTPUT:
491 if (ops->vidioc_g_fmt_vbi_out)
494 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
495 if (ops->vidioc_g_fmt_sliced_vbi_cap)
498 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
499 if (ops->vidioc_g_fmt_sliced_vbi_out)
502 case V4L2_BUF_TYPE_PRIVATE:
503 if (ops->vidioc_g_fmt_type_private)
510 static long __video_do_ioctl(struct file *file,
511 unsigned int cmd, void *arg)
513 struct video_device *vfd = video_devdata(file);
514 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
515 void *fh = file->private_data;
516 struct v4l2_fh *vfh = NULL;
521 printk(KERN_WARNING "videodev: \"%s\" has no ioctl_ops.\n",
526 if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) {
527 vfh = file->private_data;
528 use_fh_prio = test_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
531 if (v4l2_is_known_ioctl(cmd)) {
532 struct v4l2_ioctl_info *info = &v4l2_ioctls[_IOC_NR(cmd)];
534 if (!test_bit(_IOC_NR(cmd), vfd->valid_ioctls) &&
535 !((info->flags & INFO_FL_CTRL) && vfh && vfh->ctrl_handler))
538 if (use_fh_prio && (info->flags & INFO_FL_PRIO)) {
539 ret = v4l2_prio_check(vfd->prio, vfh->prio);
545 if ((vfd->debug & V4L2_DEBUG_IOCTL) &&
546 !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
547 v4l_print_ioctl(vfd->name, cmd);
548 printk(KERN_CONT "\n");
553 /* --- capabilities ------------------------------------------ */
554 case VIDIOC_QUERYCAP:
556 struct v4l2_capability *cap = (struct v4l2_capability *)arg;
558 cap->version = LINUX_VERSION_CODE;
559 ret = ops->vidioc_querycap(file, fh, cap);
561 dbgarg(cmd, "driver=%s, card=%s, bus=%s, "
563 "capabilities=0x%08x, "
564 "device_caps=0x%08x\n",
565 cap->driver, cap->card, cap->bus_info,
572 /* --- priority ------------------------------------------ */
573 case VIDIOC_G_PRIORITY:
575 enum v4l2_priority *p = arg;
577 if (ops->vidioc_g_priority) {
578 ret = ops->vidioc_g_priority(file, fh, p);
579 } else if (use_fh_prio) {
580 *p = v4l2_prio_max(&vfd->v4l2_dev->prio);
584 dbgarg(cmd, "priority is %d\n", *p);
587 case VIDIOC_S_PRIORITY:
589 enum v4l2_priority *p = arg;
591 dbgarg(cmd, "setting priority to %d\n", *p);
592 if (ops->vidioc_s_priority)
593 ret = ops->vidioc_s_priority(file, fh, *p);
595 ret = v4l2_prio_change(&vfd->v4l2_dev->prio,
600 /* --- capture ioctls ---------------------------------------- */
601 case VIDIOC_ENUM_FMT:
603 struct v4l2_fmtdesc *f = arg;
607 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
608 if (likely(ops->vidioc_enum_fmt_vid_cap))
609 ret = ops->vidioc_enum_fmt_vid_cap(file, fh, f);
611 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
612 if (likely(ops->vidioc_enum_fmt_vid_cap_mplane))
613 ret = ops->vidioc_enum_fmt_vid_cap_mplane(file,
616 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
617 if (likely(ops->vidioc_enum_fmt_vid_overlay))
618 ret = ops->vidioc_enum_fmt_vid_overlay(file,
621 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
622 if (likely(ops->vidioc_enum_fmt_vid_out))
623 ret = ops->vidioc_enum_fmt_vid_out(file, fh, f);
625 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
626 if (likely(ops->vidioc_enum_fmt_vid_out_mplane))
627 ret = ops->vidioc_enum_fmt_vid_out_mplane(file,
630 case V4L2_BUF_TYPE_PRIVATE:
631 if (likely(ops->vidioc_enum_fmt_type_private))
632 ret = ops->vidioc_enum_fmt_type_private(file,
639 dbgarg(cmd, "index=%d, type=%d, flags=%d, "
640 "pixelformat=%c%c%c%c, description='%s'\n",
641 f->index, f->type, f->flags,
642 (f->pixelformat & 0xff),
643 (f->pixelformat >> 8) & 0xff,
644 (f->pixelformat >> 16) & 0xff,
645 (f->pixelformat >> 24) & 0xff,
651 struct v4l2_format *f = (struct v4l2_format *)arg;
653 /* FIXME: Should be one dump per type */
654 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
658 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
659 if (ops->vidioc_g_fmt_vid_cap)
660 ret = ops->vidioc_g_fmt_vid_cap(file, fh, f);
662 v4l_print_pix_fmt(vfd, &f->fmt.pix);
664 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
665 if (ops->vidioc_g_fmt_vid_cap_mplane)
666 ret = ops->vidioc_g_fmt_vid_cap_mplane(file,
669 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
671 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
672 if (likely(ops->vidioc_g_fmt_vid_overlay))
673 ret = ops->vidioc_g_fmt_vid_overlay(file,
676 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
677 if (ops->vidioc_g_fmt_vid_out)
678 ret = ops->vidioc_g_fmt_vid_out(file, fh, f);
680 v4l_print_pix_fmt(vfd, &f->fmt.pix);
682 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
683 if (ops->vidioc_g_fmt_vid_out_mplane)
684 ret = ops->vidioc_g_fmt_vid_out_mplane(file,
687 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
689 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
690 if (likely(ops->vidioc_g_fmt_vid_out_overlay))
691 ret = ops->vidioc_g_fmt_vid_out_overlay(file,
694 case V4L2_BUF_TYPE_VBI_CAPTURE:
695 if (likely(ops->vidioc_g_fmt_vbi_cap))
696 ret = ops->vidioc_g_fmt_vbi_cap(file, fh, f);
698 case V4L2_BUF_TYPE_VBI_OUTPUT:
699 if (likely(ops->vidioc_g_fmt_vbi_out))
700 ret = ops->vidioc_g_fmt_vbi_out(file, fh, f);
702 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
703 if (likely(ops->vidioc_g_fmt_sliced_vbi_cap))
704 ret = ops->vidioc_g_fmt_sliced_vbi_cap(file,
707 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
708 if (likely(ops->vidioc_g_fmt_sliced_vbi_out))
709 ret = ops->vidioc_g_fmt_sliced_vbi_out(file,
712 case V4L2_BUF_TYPE_PRIVATE:
713 if (likely(ops->vidioc_g_fmt_type_private))
714 ret = ops->vidioc_g_fmt_type_private(file,
722 struct v4l2_format *f = (struct v4l2_format *)arg;
726 /* FIXME: Should be one dump per type */
727 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
730 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
731 CLEAR_AFTER_FIELD(f, fmt.pix);
732 v4l_print_pix_fmt(vfd, &f->fmt.pix);
733 if (ops->vidioc_s_fmt_vid_cap)
734 ret = ops->vidioc_s_fmt_vid_cap(file, fh, f);
736 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
737 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
738 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
739 if (ops->vidioc_s_fmt_vid_cap_mplane)
740 ret = ops->vidioc_s_fmt_vid_cap_mplane(file,
743 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
744 CLEAR_AFTER_FIELD(f, fmt.win);
745 if (ops->vidioc_s_fmt_vid_overlay)
746 ret = ops->vidioc_s_fmt_vid_overlay(file,
749 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
750 CLEAR_AFTER_FIELD(f, fmt.pix);
751 v4l_print_pix_fmt(vfd, &f->fmt.pix);
752 if (ops->vidioc_s_fmt_vid_out)
753 ret = ops->vidioc_s_fmt_vid_out(file, fh, f);
755 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
756 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
757 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
758 if (ops->vidioc_s_fmt_vid_out_mplane)
759 ret = ops->vidioc_s_fmt_vid_out_mplane(file,
762 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
763 CLEAR_AFTER_FIELD(f, fmt.win);
764 if (ops->vidioc_s_fmt_vid_out_overlay)
765 ret = ops->vidioc_s_fmt_vid_out_overlay(file,
768 case V4L2_BUF_TYPE_VBI_CAPTURE:
769 CLEAR_AFTER_FIELD(f, fmt.vbi);
770 if (likely(ops->vidioc_s_fmt_vbi_cap))
771 ret = ops->vidioc_s_fmt_vbi_cap(file, fh, f);
773 case V4L2_BUF_TYPE_VBI_OUTPUT:
774 CLEAR_AFTER_FIELD(f, fmt.vbi);
775 if (likely(ops->vidioc_s_fmt_vbi_out))
776 ret = ops->vidioc_s_fmt_vbi_out(file, fh, f);
778 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
779 CLEAR_AFTER_FIELD(f, fmt.sliced);
780 if (likely(ops->vidioc_s_fmt_sliced_vbi_cap))
781 ret = ops->vidioc_s_fmt_sliced_vbi_cap(file,
784 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
785 CLEAR_AFTER_FIELD(f, fmt.sliced);
786 if (likely(ops->vidioc_s_fmt_sliced_vbi_out))
787 ret = ops->vidioc_s_fmt_sliced_vbi_out(file,
791 case V4L2_BUF_TYPE_PRIVATE:
792 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
793 if (likely(ops->vidioc_s_fmt_type_private))
794 ret = ops->vidioc_s_fmt_type_private(file,
802 struct v4l2_format *f = (struct v4l2_format *)arg;
804 /* FIXME: Should be one dump per type */
805 dbgarg(cmd, "type=%s\n", prt_names(f->type,
809 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
810 CLEAR_AFTER_FIELD(f, fmt.pix);
811 if (ops->vidioc_try_fmt_vid_cap)
812 ret = ops->vidioc_try_fmt_vid_cap(file, fh, f);
814 v4l_print_pix_fmt(vfd, &f->fmt.pix);
816 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
817 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
818 if (ops->vidioc_try_fmt_vid_cap_mplane)
819 ret = ops->vidioc_try_fmt_vid_cap_mplane(file,
822 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
824 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
825 CLEAR_AFTER_FIELD(f, fmt.win);
826 if (likely(ops->vidioc_try_fmt_vid_overlay))
827 ret = ops->vidioc_try_fmt_vid_overlay(file,
830 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
831 CLEAR_AFTER_FIELD(f, fmt.pix);
832 if (ops->vidioc_try_fmt_vid_out)
833 ret = ops->vidioc_try_fmt_vid_out(file, fh, f);
835 v4l_print_pix_fmt(vfd, &f->fmt.pix);
837 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
838 CLEAR_AFTER_FIELD(f, fmt.pix_mp);
839 if (ops->vidioc_try_fmt_vid_out_mplane)
840 ret = ops->vidioc_try_fmt_vid_out_mplane(file,
843 v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
845 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
846 CLEAR_AFTER_FIELD(f, fmt.win);
847 if (likely(ops->vidioc_try_fmt_vid_out_overlay))
848 ret = ops->vidioc_try_fmt_vid_out_overlay(file,
851 case V4L2_BUF_TYPE_VBI_CAPTURE:
852 CLEAR_AFTER_FIELD(f, fmt.vbi);
853 if (likely(ops->vidioc_try_fmt_vbi_cap))
854 ret = ops->vidioc_try_fmt_vbi_cap(file, fh, f);
856 case V4L2_BUF_TYPE_VBI_OUTPUT:
857 CLEAR_AFTER_FIELD(f, fmt.vbi);
858 if (likely(ops->vidioc_try_fmt_vbi_out))
859 ret = ops->vidioc_try_fmt_vbi_out(file, fh, f);
861 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
862 CLEAR_AFTER_FIELD(f, fmt.sliced);
863 if (likely(ops->vidioc_try_fmt_sliced_vbi_cap))
864 ret = ops->vidioc_try_fmt_sliced_vbi_cap(file,
867 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
868 CLEAR_AFTER_FIELD(f, fmt.sliced);
869 if (likely(ops->vidioc_try_fmt_sliced_vbi_out))
870 ret = ops->vidioc_try_fmt_sliced_vbi_out(file,
873 case V4L2_BUF_TYPE_PRIVATE:
874 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
875 if (likely(ops->vidioc_try_fmt_type_private))
876 ret = ops->vidioc_try_fmt_type_private(file,
882 /* FIXME: Those buf reqs could be handled here,
883 with some changes on videobuf to allow its header to be included at
884 videodev2.h or being merged at videodev2.
888 struct v4l2_requestbuffers *p = arg;
890 ret = check_fmt(ops, p->type);
894 if (p->type < V4L2_BUF_TYPE_PRIVATE)
895 CLEAR_AFTER_FIELD(p, memory);
897 ret = ops->vidioc_reqbufs(file, fh, p);
898 dbgarg(cmd, "count=%d, type=%s, memory=%s\n",
900 prt_names(p->type, v4l2_type_names),
901 prt_names(p->memory, v4l2_memory_names));
904 case VIDIOC_QUERYBUF:
906 struct v4l2_buffer *p = arg;
908 ret = check_fmt(ops, p->type);
912 ret = ops->vidioc_querybuf(file, fh, p);
919 struct v4l2_buffer *p = arg;
921 ret = check_fmt(ops, p->type);
925 ret = ops->vidioc_qbuf(file, fh, p);
932 ret = ops->vidioc_expbuf(file, fh, arg);
937 struct v4l2_buffer *p = arg;
939 ret = check_fmt(ops, p->type);
943 ret = ops->vidioc_dqbuf(file, fh, p);
952 dbgarg(cmd, "value=%d\n", *i);
953 ret = ops->vidioc_overlay(file, fh, *i);
958 struct v4l2_framebuffer *p = arg;
960 ret = ops->vidioc_g_fbuf(file, fh, arg);
962 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
963 p->capability, p->flags,
964 (unsigned long)p->base);
965 v4l_print_pix_fmt(vfd, &p->fmt);
971 struct v4l2_framebuffer *p = arg;
973 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
974 p->capability, p->flags, (unsigned long)p->base);
975 v4l_print_pix_fmt(vfd, &p->fmt);
976 ret = ops->vidioc_s_fbuf(file, fh, arg);
979 case VIDIOC_STREAMON:
981 enum v4l2_buf_type i = *(int *)arg;
983 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
984 ret = ops->vidioc_streamon(file, fh, i);
987 case VIDIOC_STREAMOFF:
989 enum v4l2_buf_type i = *(int *)arg;
991 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
992 ret = ops->vidioc_streamoff(file, fh, i);
995 /* ---------- tv norms ---------- */
998 struct v4l2_standard *p = arg;
999 v4l2_std_id id = vfd->tvnorms, curr_id = 0;
1000 unsigned int index = p->index, i, j = 0;
1001 const char *descr = "";
1007 /* Return norm array in a canonical way */
1008 for (i = 0; i <= index && id; i++) {
1009 /* last std value in the standards array is 0, so this
1010 while always ends there since (id & 0) == 0. */
1011 while ((id & standards[j].std) != standards[j].std)
1013 curr_id = standards[j].std;
1014 descr = standards[j].descr;
1018 if (curr_id != V4L2_STD_PAL &&
1019 curr_id != V4L2_STD_SECAM &&
1020 curr_id != V4L2_STD_NTSC)
1026 v4l2_video_std_construct(p, curr_id, descr);
1028 dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1029 "framelines=%d\n", p->index,
1030 (unsigned long long)p->id, p->name,
1031 p->frameperiod.numerator,
1032 p->frameperiod.denominator,
1040 v4l2_std_id *id = arg;
1042 /* Calls the specific handler */
1043 if (ops->vidioc_g_std)
1044 ret = ops->vidioc_g_std(file, fh, id);
1045 else if (vfd->current_norm) {
1047 *id = vfd->current_norm;
1051 dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id);
1056 v4l2_std_id *id = arg, norm;
1058 dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id);
1061 norm = (*id) & vfd->tvnorms;
1062 if (vfd->tvnorms && !norm) /* Check if std is supported */
1065 /* Calls the specific handler */
1066 ret = ops->vidioc_s_std(file, fh, &norm);
1068 /* Updates standard information */
1070 vfd->current_norm = norm;
1073 case VIDIOC_QUERYSTD:
1075 v4l2_std_id *p = arg;
1078 * If nothing detected, it should return all supported
1079 * Drivers just need to mask the std argument, in order
1080 * to remove the standards that don't apply from the mask.
1081 * This means that tuners, audio and video decoders can join
1082 * their efforts to improve the standards detection
1085 ret = ops->vidioc_querystd(file, fh, arg);
1087 dbgarg(cmd, "detected std=%08Lx\n",
1088 (unsigned long long)*p);
1091 /* ------ input switching ---------- */
1092 /* FIXME: Inputs can be handled inside videodev2 */
1093 case VIDIOC_ENUMINPUT:
1095 struct v4l2_input *p = arg;
1098 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1099 * CAP_STD here based on ioctl handler provided by the
1100 * driver. If the driver doesn't support these
1101 * for a specific input, it must override these flags.
1103 if (ops->vidioc_s_std)
1104 p->capabilities |= V4L2_IN_CAP_STD;
1105 if (ops->vidioc_s_dv_preset)
1106 p->capabilities |= V4L2_IN_CAP_PRESETS;
1107 if (ops->vidioc_s_dv_timings)
1108 p->capabilities |= V4L2_IN_CAP_CUSTOM_TIMINGS;
1110 ret = ops->vidioc_enum_input(file, fh, p);
1112 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1114 "tuner=%d, std=%08Lx, status=%d\n",
1115 p->index, p->name, p->type, p->audioset,
1117 (unsigned long long)p->std,
1121 case VIDIOC_G_INPUT:
1123 unsigned int *i = arg;
1125 ret = ops->vidioc_g_input(file, fh, i);
1127 dbgarg(cmd, "value=%d\n", *i);
1130 case VIDIOC_S_INPUT:
1132 unsigned int *i = arg;
1134 dbgarg(cmd, "value=%d\n", *i);
1135 ret = ops->vidioc_s_input(file, fh, *i);
1139 /* ------ output switching ---------- */
1140 case VIDIOC_ENUMOUTPUT:
1142 struct v4l2_output *p = arg;
1145 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1146 * CAP_STD here based on ioctl handler provided by the
1147 * driver. If the driver doesn't support these
1148 * for a specific output, it must override these flags.
1150 if (ops->vidioc_s_std)
1151 p->capabilities |= V4L2_OUT_CAP_STD;
1152 if (ops->vidioc_s_dv_preset)
1153 p->capabilities |= V4L2_OUT_CAP_PRESETS;
1154 if (ops->vidioc_s_dv_timings)
1155 p->capabilities |= V4L2_OUT_CAP_CUSTOM_TIMINGS;
1157 ret = ops->vidioc_enum_output(file, fh, p);
1159 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1161 "modulator=%d, std=0x%08Lx\n",
1162 p->index, p->name, p->type, p->audioset,
1163 p->modulator, (unsigned long long)p->std);
1166 case VIDIOC_G_OUTPUT:
1168 unsigned int *i = arg;
1170 ret = ops->vidioc_g_output(file, fh, i);
1172 dbgarg(cmd, "value=%d\n", *i);
1175 case VIDIOC_S_OUTPUT:
1177 unsigned int *i = arg;
1179 dbgarg(cmd, "value=%d\n", *i);
1180 ret = ops->vidioc_s_output(file, fh, *i);
1184 /* --- controls ---------------------------------------------- */
1185 case VIDIOC_QUERYCTRL:
1187 struct v4l2_queryctrl *p = arg;
1189 if (vfh && vfh->ctrl_handler)
1190 ret = v4l2_queryctrl(vfh->ctrl_handler, p);
1191 else if (vfd->ctrl_handler)
1192 ret = v4l2_queryctrl(vfd->ctrl_handler, p);
1193 else if (ops->vidioc_queryctrl)
1194 ret = ops->vidioc_queryctrl(file, fh, p);
1198 dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1199 "step=%d, default=%d, flags=0x%08x\n",
1200 p->id, p->type, p->name,
1201 p->minimum, p->maximum,
1202 p->step, p->default_value, p->flags);
1204 dbgarg(cmd, "id=0x%x\n", p->id);
1209 struct v4l2_control *p = arg;
1211 if (vfh && vfh->ctrl_handler)
1212 ret = v4l2_g_ctrl(vfh->ctrl_handler, p);
1213 else if (vfd->ctrl_handler)
1214 ret = v4l2_g_ctrl(vfd->ctrl_handler, p);
1215 else if (ops->vidioc_g_ctrl)
1216 ret = ops->vidioc_g_ctrl(file, fh, p);
1217 else if (ops->vidioc_g_ext_ctrls) {
1218 struct v4l2_ext_controls ctrls;
1219 struct v4l2_ext_control ctrl;
1221 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1223 ctrls.controls = &ctrl;
1225 ctrl.value = p->value;
1226 if (check_ext_ctrls(&ctrls, 1)) {
1227 ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls);
1229 p->value = ctrl.value;
1234 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1236 dbgarg(cmd, "id=0x%x\n", p->id);
1241 struct v4l2_control *p = arg;
1242 struct v4l2_ext_controls ctrls;
1243 struct v4l2_ext_control ctrl;
1245 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
1246 !ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls)
1249 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1251 if (vfh && vfh->ctrl_handler) {
1252 ret = v4l2_s_ctrl(vfh, vfh->ctrl_handler, p);
1255 if (vfd->ctrl_handler) {
1256 ret = v4l2_s_ctrl(NULL, vfd->ctrl_handler, p);
1259 if (ops->vidioc_s_ctrl) {
1260 ret = ops->vidioc_s_ctrl(file, fh, p);
1263 if (!ops->vidioc_s_ext_ctrls)
1266 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1268 ctrls.controls = &ctrl;
1270 ctrl.value = p->value;
1271 if (check_ext_ctrls(&ctrls, 1))
1272 ret = ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
1277 case VIDIOC_G_EXT_CTRLS:
1279 struct v4l2_ext_controls *p = arg;
1281 p->error_idx = p->count;
1282 if (vfh && vfh->ctrl_handler)
1283 ret = v4l2_g_ext_ctrls(vfh->ctrl_handler, p);
1284 else if (vfd->ctrl_handler)
1285 ret = v4l2_g_ext_ctrls(vfd->ctrl_handler, p);
1286 else if (ops->vidioc_g_ext_ctrls)
1287 ret = check_ext_ctrls(p, 0) ?
1288 ops->vidioc_g_ext_ctrls(file, fh, p) :
1292 v4l_print_ext_ctrls(cmd, vfd, p, !ret);
1295 case VIDIOC_S_EXT_CTRLS:
1297 struct v4l2_ext_controls *p = arg;
1299 p->error_idx = p->count;
1300 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
1301 !ops->vidioc_s_ext_ctrls)
1303 v4l_print_ext_ctrls(cmd, vfd, p, 1);
1304 if (vfh && vfh->ctrl_handler)
1305 ret = v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, p);
1306 else if (vfd->ctrl_handler)
1307 ret = v4l2_s_ext_ctrls(NULL, vfd->ctrl_handler, p);
1308 else if (check_ext_ctrls(p, 0))
1309 ret = ops->vidioc_s_ext_ctrls(file, fh, p);
1314 case VIDIOC_TRY_EXT_CTRLS:
1316 struct v4l2_ext_controls *p = arg;
1318 p->error_idx = p->count;
1319 if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
1320 !ops->vidioc_try_ext_ctrls)
1322 v4l_print_ext_ctrls(cmd, vfd, p, 1);
1323 if (vfh && vfh->ctrl_handler)
1324 ret = v4l2_try_ext_ctrls(vfh->ctrl_handler, p);
1325 else if (vfd->ctrl_handler)
1326 ret = v4l2_try_ext_ctrls(vfd->ctrl_handler, p);
1327 else if (check_ext_ctrls(p, 0))
1328 ret = ops->vidioc_try_ext_ctrls(file, fh, p);
1333 case VIDIOC_QUERYMENU:
1335 struct v4l2_querymenu *p = arg;
1337 if (vfh && vfh->ctrl_handler)
1338 ret = v4l2_querymenu(vfh->ctrl_handler, p);
1339 else if (vfd->ctrl_handler)
1340 ret = v4l2_querymenu(vfd->ctrl_handler, p);
1341 else if (ops->vidioc_querymenu)
1342 ret = ops->vidioc_querymenu(file, fh, p);
1346 dbgarg(cmd, "id=0x%x, index=%d, name=%s\n",
1347 p->id, p->index, p->name);
1349 dbgarg(cmd, "id=0x%x, index=%d\n",
1353 /* --- audio ---------------------------------------------- */
1354 case VIDIOC_ENUMAUDIO:
1356 struct v4l2_audio *p = arg;
1358 ret = ops->vidioc_enumaudio(file, fh, p);
1360 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1361 "mode=0x%x\n", p->index, p->name,
1362 p->capability, p->mode);
1364 dbgarg(cmd, "index=%d\n", p->index);
1367 case VIDIOC_G_AUDIO:
1369 struct v4l2_audio *p = arg;
1371 ret = ops->vidioc_g_audio(file, fh, p);
1373 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1374 "mode=0x%x\n", p->index,
1375 p->name, p->capability, p->mode);
1377 dbgarg(cmd, "index=%d\n", p->index);
1380 case VIDIOC_S_AUDIO:
1382 struct v4l2_audio *p = arg;
1384 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1385 "mode=0x%x\n", p->index, p->name,
1386 p->capability, p->mode);
1387 ret = ops->vidioc_s_audio(file, fh, p);
1390 case VIDIOC_ENUMAUDOUT:
1392 struct v4l2_audioout *p = arg;
1394 dbgarg(cmd, "Enum for index=%d\n", p->index);
1395 ret = ops->vidioc_enumaudout(file, fh, p);
1397 dbgarg2("index=%d, name=%s, capability=%d, "
1398 "mode=%d\n", p->index, p->name,
1399 p->capability, p->mode);
1402 case VIDIOC_G_AUDOUT:
1404 struct v4l2_audioout *p = arg;
1406 ret = ops->vidioc_g_audout(file, fh, p);
1408 dbgarg2("index=%d, name=%s, capability=%d, "
1409 "mode=%d\n", p->index, p->name,
1410 p->capability, p->mode);
1413 case VIDIOC_S_AUDOUT:
1415 struct v4l2_audioout *p = arg;
1417 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1418 "mode=%d\n", p->index, p->name,
1419 p->capability, p->mode);
1421 ret = ops->vidioc_s_audout(file, fh, p);
1424 case VIDIOC_G_MODULATOR:
1426 struct v4l2_modulator *p = arg;
1428 ret = ops->vidioc_g_modulator(file, fh, p);
1430 dbgarg(cmd, "index=%d, name=%s, "
1431 "capability=%d, rangelow=%d,"
1432 " rangehigh=%d, txsubchans=%d\n",
1433 p->index, p->name, p->capability,
1434 p->rangelow, p->rangehigh,
1438 case VIDIOC_S_MODULATOR:
1440 struct v4l2_modulator *p = arg;
1442 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1443 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1444 p->index, p->name, p->capability, p->rangelow,
1445 p->rangehigh, p->txsubchans);
1446 ret = ops->vidioc_s_modulator(file, fh, p);
1451 struct v4l2_crop *p = arg;
1453 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1455 if (ops->vidioc_g_crop) {
1456 ret = ops->vidioc_g_crop(file, fh, p);
1458 /* simulate capture crop using selection api */
1459 struct v4l2_selection s = {
1463 /* crop means compose for output devices */
1464 if (V4L2_TYPE_IS_OUTPUT(p->type))
1465 s.target = V4L2_SEL_TGT_COMPOSE_ACTIVE;
1467 s.target = V4L2_SEL_TGT_CROP_ACTIVE;
1469 ret = ops->vidioc_g_selection(file, fh, &s);
1471 /* copying results to old structure on success */
1477 dbgrect(vfd, "", &p->c);
1482 struct v4l2_crop *p = arg;
1484 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1485 dbgrect(vfd, "", &p->c);
1487 if (ops->vidioc_s_crop) {
1488 ret = ops->vidioc_s_crop(file, fh, p);
1490 /* simulate capture crop using selection api */
1491 struct v4l2_selection s = {
1496 /* crop means compose for output devices */
1497 if (V4L2_TYPE_IS_OUTPUT(p->type))
1498 s.target = V4L2_SEL_TGT_COMPOSE_ACTIVE;
1500 s.target = V4L2_SEL_TGT_CROP_ACTIVE;
1502 ret = ops->vidioc_s_selection(file, fh, &s);
1506 case VIDIOC_G_SELECTION:
1508 struct v4l2_selection *p = arg;
1510 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1512 ret = ops->vidioc_g_selection(file, fh, p);
1514 dbgrect(vfd, "", &p->r);
1517 case VIDIOC_S_SELECTION:
1519 struct v4l2_selection *p = arg;
1522 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1523 dbgrect(vfd, "", &p->r);
1525 ret = ops->vidioc_s_selection(file, fh, p);
1528 case VIDIOC_CROPCAP:
1530 struct v4l2_cropcap *p = arg;
1532 /*FIXME: Should also show v4l2_fract pixelaspect */
1533 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1534 if (ops->vidioc_cropcap) {
1535 ret = ops->vidioc_cropcap(file, fh, p);
1537 struct v4l2_selection s = { .type = p->type };
1539 /* obtaining bounds */
1540 if (V4L2_TYPE_IS_OUTPUT(p->type))
1541 s.target = V4L2_SEL_TGT_COMPOSE_BOUNDS;
1543 s.target = V4L2_SEL_TGT_CROP_BOUNDS;
1545 ret = ops->vidioc_g_selection(file, fh, &s);
1550 /* obtaining defrect */
1551 if (V4L2_TYPE_IS_OUTPUT(p->type))
1552 s.target = V4L2_SEL_TGT_COMPOSE_DEFAULT;
1554 s.target = V4L2_SEL_TGT_CROP_DEFAULT;
1556 ret = ops->vidioc_g_selection(file, fh, &s);
1561 /* setting trivial pixelaspect */
1562 p->pixelaspect.numerator = 1;
1563 p->pixelaspect.denominator = 1;
1567 dbgrect(vfd, "bounds ", &p->bounds);
1568 dbgrect(vfd, "defrect ", &p->defrect);
1572 case VIDIOC_G_JPEGCOMP:
1574 struct v4l2_jpegcompression *p = arg;
1576 ret = ops->vidioc_g_jpegcomp(file, fh, p);
1578 dbgarg(cmd, "quality=%d, APPn=%d, "
1579 "APP_len=%d, COM_len=%d, "
1580 "jpeg_markers=%d\n",
1581 p->quality, p->APPn, p->APP_len,
1582 p->COM_len, p->jpeg_markers);
1585 case VIDIOC_S_JPEGCOMP:
1587 struct v4l2_jpegcompression *p = arg;
1589 dbgarg(cmd, "quality=%d, APPn=%d, APP_len=%d, "
1590 "COM_len=%d, jpeg_markers=%d\n",
1591 p->quality, p->APPn, p->APP_len,
1592 p->COM_len, p->jpeg_markers);
1593 ret = ops->vidioc_s_jpegcomp(file, fh, p);
1596 case VIDIOC_G_ENC_INDEX:
1598 struct v4l2_enc_idx *p = arg;
1600 ret = ops->vidioc_g_enc_index(file, fh, p);
1602 dbgarg(cmd, "entries=%d, entries_cap=%d\n",
1603 p->entries, p->entries_cap);
1606 case VIDIOC_ENCODER_CMD:
1608 struct v4l2_encoder_cmd *p = arg;
1610 ret = ops->vidioc_encoder_cmd(file, fh, p);
1612 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1615 case VIDIOC_TRY_ENCODER_CMD:
1617 struct v4l2_encoder_cmd *p = arg;
1619 ret = ops->vidioc_try_encoder_cmd(file, fh, p);
1621 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1624 case VIDIOC_DECODER_CMD:
1626 struct v4l2_decoder_cmd *p = arg;
1628 ret = ops->vidioc_decoder_cmd(file, fh, p);
1630 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1633 case VIDIOC_TRY_DECODER_CMD:
1635 struct v4l2_decoder_cmd *p = arg;
1637 ret = ops->vidioc_try_decoder_cmd(file, fh, p);
1639 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1644 struct v4l2_streamparm *p = arg;
1646 if (ops->vidioc_g_parm) {
1647 ret = check_fmt(ops, p->type);
1650 ret = ops->vidioc_g_parm(file, fh, p);
1652 v4l2_std_id std = vfd->current_norm;
1655 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1659 if (ops->vidioc_g_std)
1660 ret = ops->vidioc_g_std(file, fh, &std);
1662 v4l2_video_std_frame_period(std,
1663 &p->parm.capture.timeperframe);
1666 dbgarg(cmd, "type=%d\n", p->type);
1671 struct v4l2_streamparm *p = arg;
1673 ret = check_fmt(ops, p->type);
1677 dbgarg(cmd, "type=%d\n", p->type);
1678 ret = ops->vidioc_s_parm(file, fh, p);
1681 case VIDIOC_G_TUNER:
1683 struct v4l2_tuner *p = arg;
1685 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1686 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1687 ret = ops->vidioc_g_tuner(file, fh, p);
1689 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1690 "capability=0x%x, rangelow=%d, "
1691 "rangehigh=%d, signal=%d, afc=%d, "
1692 "rxsubchans=0x%x, audmode=%d\n",
1693 p->index, p->name, p->type,
1694 p->capability, p->rangelow,
1695 p->rangehigh, p->signal, p->afc,
1696 p->rxsubchans, p->audmode);
1699 case VIDIOC_S_TUNER:
1701 struct v4l2_tuner *p = arg;
1703 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1704 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1705 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1706 "capability=0x%x, rangelow=%d, "
1707 "rangehigh=%d, signal=%d, afc=%d, "
1708 "rxsubchans=0x%x, audmode=%d\n",
1709 p->index, p->name, p->type,
1710 p->capability, p->rangelow,
1711 p->rangehigh, p->signal, p->afc,
1712 p->rxsubchans, p->audmode);
1713 ret = ops->vidioc_s_tuner(file, fh, p);
1716 case VIDIOC_G_FREQUENCY:
1718 struct v4l2_frequency *p = arg;
1720 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1721 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1722 ret = ops->vidioc_g_frequency(file, fh, p);
1724 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1725 p->tuner, p->type, p->frequency);
1728 case VIDIOC_S_FREQUENCY:
1730 struct v4l2_frequency *p = arg;
1731 enum v4l2_tuner_type type;
1733 type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1734 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1735 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1736 p->tuner, p->type, p->frequency);
1737 if (p->type != type)
1740 ret = ops->vidioc_s_frequency(file, fh, p);
1743 case VIDIOC_G_SLICED_VBI_CAP:
1745 struct v4l2_sliced_vbi_cap *p = arg;
1747 /* Clear up to type, everything after type is zerod already */
1748 memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
1750 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1751 ret = ops->vidioc_g_sliced_vbi_cap(file, fh, p);
1753 dbgarg2("service_set=%d\n", p->service_set);
1756 case VIDIOC_LOG_STATUS:
1759 pr_info("%s: ================= START STATUS =================\n",
1760 vfd->v4l2_dev->name);
1761 ret = ops->vidioc_log_status(file, fh);
1763 pr_info("%s: ================== END STATUS ==================\n",
1764 vfd->v4l2_dev->name);
1767 case VIDIOC_DBG_G_REGISTER:
1769 #ifdef CONFIG_VIDEO_ADV_DEBUG
1770 struct v4l2_dbg_register *p = arg;
1772 if (!capable(CAP_SYS_ADMIN))
1775 ret = ops->vidioc_g_register(file, fh, p);
1779 case VIDIOC_DBG_S_REGISTER:
1781 #ifdef CONFIG_VIDEO_ADV_DEBUG
1782 struct v4l2_dbg_register *p = arg;
1784 if (!capable(CAP_SYS_ADMIN))
1787 ret = ops->vidioc_s_register(file, fh, p);
1791 case VIDIOC_DBG_G_CHIP_IDENT:
1793 struct v4l2_dbg_chip_ident *p = arg;
1795 p->ident = V4L2_IDENT_NONE;
1797 ret = ops->vidioc_g_chip_ident(file, fh, p);
1799 dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
1802 case VIDIOC_S_HW_FREQ_SEEK:
1804 struct v4l2_hw_freq_seek *p = arg;
1805 enum v4l2_tuner_type type;
1807 type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1808 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1810 "tuner=%u, type=%u, seek_upward=%u, wrap_around=%u, spacing=%u\n",
1811 p->tuner, p->type, p->seek_upward, p->wrap_around, p->spacing);
1812 if (p->type != type)
1815 ret = ops->vidioc_s_hw_freq_seek(file, fh, p);
1818 case VIDIOC_ENUM_FRAMESIZES:
1820 struct v4l2_frmsizeenum *p = arg;
1822 ret = ops->vidioc_enum_framesizes(file, fh, p);
1824 "index=%d, pixelformat=%c%c%c%c, type=%d ",
1826 (p->pixel_format & 0xff),
1827 (p->pixel_format >> 8) & 0xff,
1828 (p->pixel_format >> 16) & 0xff,
1829 (p->pixel_format >> 24) & 0xff,
1832 case V4L2_FRMSIZE_TYPE_DISCRETE:
1833 dbgarg3("width = %d, height=%d\n",
1834 p->discrete.width, p->discrete.height);
1836 case V4L2_FRMSIZE_TYPE_STEPWISE:
1837 dbgarg3("min %dx%d, max %dx%d, step %dx%d\n",
1838 p->stepwise.min_width, p->stepwise.min_height,
1839 p->stepwise.step_width, p->stepwise.step_height,
1840 p->stepwise.max_width, p->stepwise.max_height);
1842 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
1843 dbgarg3("continuous\n");
1846 dbgarg3("- Unknown type!\n");
1851 case VIDIOC_ENUM_FRAMEINTERVALS:
1853 struct v4l2_frmivalenum *p = arg;
1855 ret = ops->vidioc_enum_frameintervals(file, fh, p);
1857 "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
1858 p->index, p->pixel_format,
1859 p->width, p->height, p->type);
1861 case V4L2_FRMIVAL_TYPE_DISCRETE:
1862 dbgarg2("fps=%d/%d\n",
1863 p->discrete.numerator,
1864 p->discrete.denominator);
1866 case V4L2_FRMIVAL_TYPE_STEPWISE:
1867 dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
1868 p->stepwise.min.numerator,
1869 p->stepwise.min.denominator,
1870 p->stepwise.max.numerator,
1871 p->stepwise.max.denominator,
1872 p->stepwise.step.numerator,
1873 p->stepwise.step.denominator);
1875 case V4L2_FRMIVAL_TYPE_CONTINUOUS:
1876 dbgarg2("continuous\n");
1879 dbgarg2("- Unknown type!\n");
1883 case VIDIOC_ENUM_DV_PRESETS:
1885 struct v4l2_dv_enum_preset *p = arg;
1887 ret = ops->vidioc_enum_dv_presets(file, fh, p);
1890 "index=%d, preset=%d, name=%s, width=%d,"
1892 p->index, p->preset, p->name, p->width,
1896 case VIDIOC_S_DV_PRESET:
1898 struct v4l2_dv_preset *p = arg;
1900 dbgarg(cmd, "preset=%d\n", p->preset);
1901 ret = ops->vidioc_s_dv_preset(file, fh, p);
1904 case VIDIOC_G_DV_PRESET:
1906 struct v4l2_dv_preset *p = arg;
1908 ret = ops->vidioc_g_dv_preset(file, fh, p);
1910 dbgarg(cmd, "preset=%d\n", p->preset);
1913 case VIDIOC_QUERY_DV_PRESET:
1915 struct v4l2_dv_preset *p = arg;
1917 ret = ops->vidioc_query_dv_preset(file, fh, p);
1919 dbgarg(cmd, "preset=%d\n", p->preset);
1922 case VIDIOC_S_DV_TIMINGS:
1924 struct v4l2_dv_timings *p = arg;
1927 case V4L2_DV_BT_656_1120:
1928 dbgarg2("bt-656/1120:interlaced=%d, pixelclock=%lld,"
1929 " width=%d, height=%d, polarities=%x,"
1930 " hfrontporch=%d, hsync=%d, hbackporch=%d,"
1931 " vfrontporch=%d, vsync=%d, vbackporch=%d,"
1932 " il_vfrontporch=%d, il_vsync=%d,"
1933 " il_vbackporch=%d\n",
1934 p->bt.interlaced, p->bt.pixelclock,
1935 p->bt.width, p->bt.height, p->bt.polarities,
1936 p->bt.hfrontporch, p->bt.hsync,
1937 p->bt.hbackporch, p->bt.vfrontporch,
1938 p->bt.vsync, p->bt.vbackporch,
1939 p->bt.il_vfrontporch, p->bt.il_vsync,
1940 p->bt.il_vbackporch);
1941 ret = ops->vidioc_s_dv_timings(file, fh, p);
1944 dbgarg2("Unknown type %d!\n", p->type);
1949 case VIDIOC_G_DV_TIMINGS:
1951 struct v4l2_dv_timings *p = arg;
1953 ret = ops->vidioc_g_dv_timings(file, fh, p);
1956 case V4L2_DV_BT_656_1120:
1957 dbgarg2("bt-656/1120:interlaced=%d,"
1959 " width=%d, height=%d, polarities=%x,"
1960 " hfrontporch=%d, hsync=%d,"
1961 " hbackporch=%d, vfrontporch=%d,"
1962 " vsync=%d, vbackporch=%d,"
1963 " il_vfrontporch=%d, il_vsync=%d,"
1964 " il_vbackporch=%d\n",
1965 p->bt.interlaced, p->bt.pixelclock,
1966 p->bt.width, p->bt.height,
1967 p->bt.polarities, p->bt.hfrontporch,
1968 p->bt.hsync, p->bt.hbackporch,
1969 p->bt.vfrontporch, p->bt.vsync,
1970 p->bt.vbackporch, p->bt.il_vfrontporch,
1971 p->bt.il_vsync, p->bt.il_vbackporch);
1974 dbgarg2("Unknown type %d!\n", p->type);
1980 case VIDIOC_DQEVENT:
1982 struct v4l2_event *ev = arg;
1984 ret = v4l2_event_dequeue(fh, ev, file->f_flags & O_NONBLOCK);
1986 dbgarg(cmd, "no pending events?");
1990 "pending=%d, type=0x%8.8x, sequence=%d, "
1991 "timestamp=%lu.%9.9lu ",
1992 ev->pending, ev->type, ev->sequence,
1993 ev->timestamp.tv_sec, ev->timestamp.tv_nsec);
1996 case VIDIOC_SUBSCRIBE_EVENT:
1998 struct v4l2_event_subscription *sub = arg;
2000 ret = ops->vidioc_subscribe_event(fh, sub);
2002 dbgarg(cmd, "failed, ret=%ld", ret);
2005 dbgarg(cmd, "type=0x%8.8x", sub->type);
2008 case VIDIOC_UNSUBSCRIBE_EVENT:
2010 struct v4l2_event_subscription *sub = arg;
2012 ret = ops->vidioc_unsubscribe_event(fh, sub);
2014 dbgarg(cmd, "failed, ret=%ld", ret);
2017 dbgarg(cmd, "type=0x%8.8x", sub->type);
2020 case VIDIOC_CREATE_BUFS:
2022 struct v4l2_create_buffers *create = arg;
2024 ret = check_fmt(ops, create->format.type);
2028 ret = ops->vidioc_create_bufs(file, fh, create);
2030 dbgarg(cmd, "count=%d @ %d\n", create->count, create->index);
2033 case VIDIOC_PREPARE_BUF:
2035 struct v4l2_buffer *b = arg;
2037 ret = check_fmt(ops, b->type);
2041 ret = ops->vidioc_prepare_buf(file, fh, b);
2043 dbgarg(cmd, "index=%d", b->index);
2047 if (!ops->vidioc_default)
2049 ret = ops->vidioc_default(file, fh, use_fh_prio ?
2050 v4l2_prio_check(vfd->prio, vfh->prio) >= 0 : 0,
2055 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
2057 v4l_print_ioctl(vfd->name, cmd);
2058 printk(KERN_CONT " error %ld\n", ret);
2065 /* In some cases, only a few fields are used as input, i.e. when the app sets
2066 * "index" and then the driver fills in the rest of the structure for the thing
2067 * with that index. We only need to copy up the first non-input field. */
2068 static unsigned long cmd_input_size(unsigned int cmd)
2070 /* Size of structure up to and including 'field' */
2071 #define CMDINSIZE(cmd, type, field) \
2072 case VIDIOC_##cmd: \
2073 return offsetof(struct v4l2_##type, field) + \
2074 sizeof(((struct v4l2_##type *)0)->field);
2077 CMDINSIZE(ENUM_FMT, fmtdesc, type);
2078 CMDINSIZE(G_FMT, format, type);
2079 CMDINSIZE(QUERYBUF, buffer, length);
2080 CMDINSIZE(G_PARM, streamparm, type);
2081 CMDINSIZE(ENUMSTD, standard, index);
2082 CMDINSIZE(ENUMINPUT, input, index);
2083 CMDINSIZE(G_CTRL, control, id);
2084 CMDINSIZE(G_TUNER, tuner, index);
2085 CMDINSIZE(QUERYCTRL, queryctrl, id);
2086 CMDINSIZE(QUERYMENU, querymenu, index);
2087 CMDINSIZE(ENUMOUTPUT, output, index);
2088 CMDINSIZE(G_MODULATOR, modulator, index);
2089 CMDINSIZE(G_FREQUENCY, frequency, tuner);
2090 CMDINSIZE(CROPCAP, cropcap, type);
2091 CMDINSIZE(G_CROP, crop, type);
2092 CMDINSIZE(ENUMAUDIO, audio, index);
2093 CMDINSIZE(ENUMAUDOUT, audioout, index);
2094 CMDINSIZE(ENCODER_CMD, encoder_cmd, flags);
2095 CMDINSIZE(TRY_ENCODER_CMD, encoder_cmd, flags);
2096 CMDINSIZE(G_SLICED_VBI_CAP, sliced_vbi_cap, type);
2097 CMDINSIZE(ENUM_FRAMESIZES, frmsizeenum, pixel_format);
2098 CMDINSIZE(ENUM_FRAMEINTERVALS, frmivalenum, height);
2100 return _IOC_SIZE(cmd);
2104 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
2105 void * __user *user_ptr, void ***kernel_ptr)
2110 case VIDIOC_QUERYBUF:
2112 case VIDIOC_DQBUF: {
2113 struct v4l2_buffer *buf = parg;
2115 if (V4L2_TYPE_IS_MULTIPLANAR(buf->type) && buf->length > 0) {
2116 if (buf->length > VIDEO_MAX_PLANES) {
2120 *user_ptr = (void __user *)buf->m.planes;
2121 *kernel_ptr = (void *)&buf->m.planes;
2122 *array_size = sizeof(struct v4l2_plane) * buf->length;
2128 case VIDIOC_S_EXT_CTRLS:
2129 case VIDIOC_G_EXT_CTRLS:
2130 case VIDIOC_TRY_EXT_CTRLS: {
2131 struct v4l2_ext_controls *ctrls = parg;
2133 if (ctrls->count != 0) {
2134 if (ctrls->count > V4L2_CID_MAX_CTRLS) {
2138 *user_ptr = (void __user *)ctrls->controls;
2139 *kernel_ptr = (void *)&ctrls->controls;
2140 *array_size = sizeof(struct v4l2_ext_control)
2152 video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
2157 void *parg = (void *)arg;
2159 bool has_array_args;
2160 size_t array_size = 0;
2161 void __user *user_ptr = NULL;
2162 void **kernel_ptr = NULL;
2164 /* Copy arguments into temp kernel buffer */
2165 if (_IOC_DIR(cmd) != _IOC_NONE) {
2166 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
2169 /* too big to allocate from stack */
2170 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
2177 if (_IOC_DIR(cmd) & _IOC_WRITE) {
2178 unsigned long n = cmd_input_size(cmd);
2180 if (copy_from_user(parg, (void __user *)arg, n))
2183 /* zero out anything we don't copy from userspace */
2184 if (n < _IOC_SIZE(cmd))
2185 memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n);
2187 /* read-only ioctl */
2188 memset(parg, 0, _IOC_SIZE(cmd));
2192 err = check_array_args(cmd, parg, &array_size, &user_ptr, &kernel_ptr);
2195 has_array_args = err;
2197 if (has_array_args) {
2199 * When adding new types of array args, make sure that the
2200 * parent argument to ioctl (which contains the pointer to the
2201 * array) fits into sbuf (so that mbuf will still remain
2202 * unused up to here).
2204 mbuf = kmalloc(array_size, GFP_KERNEL);
2207 goto out_array_args;
2209 if (copy_from_user(mbuf, user_ptr, array_size))
2210 goto out_array_args;
2215 err = func(file, cmd, parg);
2216 if (err == -ENOIOCTLCMD)
2219 if (has_array_args) {
2220 *kernel_ptr = user_ptr;
2221 if (copy_to_user(user_ptr, mbuf, array_size))
2223 goto out_array_args;
2229 /* Copy results into user buffer */
2230 switch (_IOC_DIR(cmd)) {
2232 case (_IOC_WRITE | _IOC_READ):
2233 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
2242 EXPORT_SYMBOL(video_usercopy);
2244 long video_ioctl2(struct file *file,
2245 unsigned int cmd, unsigned long arg)
2247 return video_usercopy(file, cmd, arg, __video_do_ioctl);
2249 EXPORT_SYMBOL(video_ioctl2);