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/videobuf2-core.h>
31 #define CREATE_TRACE_POINTS
32 #include <trace/events/v4l2.h>
34 /* Zero out the end of the struct pointed to by p. Everything after, but
35 * not including, the specified field is cleared. */
36 #define CLEAR_AFTER_FIELD(p, field) \
37 memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \
38 0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field))
40 #define is_valid_ioctl(vfd, cmd) test_bit(_IOC_NR(cmd), (vfd)->valid_ioctls)
47 static const struct std_descr standards[] = {
48 { V4L2_STD_NTSC, "NTSC" },
49 { V4L2_STD_NTSC_M, "NTSC-M" },
50 { V4L2_STD_NTSC_M_JP, "NTSC-M-JP" },
51 { V4L2_STD_NTSC_M_KR, "NTSC-M-KR" },
52 { V4L2_STD_NTSC_443, "NTSC-443" },
53 { V4L2_STD_PAL, "PAL" },
54 { V4L2_STD_PAL_BG, "PAL-BG" },
55 { V4L2_STD_PAL_B, "PAL-B" },
56 { V4L2_STD_PAL_B1, "PAL-B1" },
57 { V4L2_STD_PAL_G, "PAL-G" },
58 { V4L2_STD_PAL_H, "PAL-H" },
59 { V4L2_STD_PAL_I, "PAL-I" },
60 { V4L2_STD_PAL_DK, "PAL-DK" },
61 { V4L2_STD_PAL_D, "PAL-D" },
62 { V4L2_STD_PAL_D1, "PAL-D1" },
63 { V4L2_STD_PAL_K, "PAL-K" },
64 { V4L2_STD_PAL_M, "PAL-M" },
65 { V4L2_STD_PAL_N, "PAL-N" },
66 { V4L2_STD_PAL_Nc, "PAL-Nc" },
67 { V4L2_STD_PAL_60, "PAL-60" },
68 { V4L2_STD_SECAM, "SECAM" },
69 { V4L2_STD_SECAM_B, "SECAM-B" },
70 { V4L2_STD_SECAM_G, "SECAM-G" },
71 { V4L2_STD_SECAM_H, "SECAM-H" },
72 { V4L2_STD_SECAM_DK, "SECAM-DK" },
73 { V4L2_STD_SECAM_D, "SECAM-D" },
74 { V4L2_STD_SECAM_K, "SECAM-K" },
75 { V4L2_STD_SECAM_K1, "SECAM-K1" },
76 { V4L2_STD_SECAM_L, "SECAM-L" },
77 { V4L2_STD_SECAM_LC, "SECAM-Lc" },
81 /* video4linux standard ID conversion to standard name
83 const char *v4l2_norm_to_name(v4l2_std_id id)
88 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
89 64 bit comparations. So, on that architecture, with some gcc
90 variants, compilation fails. Currently, the max value is 30bit wide.
94 for (i = 0; standards[i].std; i++)
95 if (myid == standards[i].std)
97 return standards[i].descr;
99 EXPORT_SYMBOL(v4l2_norm_to_name);
101 /* Returns frame period for the given standard */
102 void v4l2_video_std_frame_period(int id, struct v4l2_fract *frameperiod)
104 if (id & V4L2_STD_525_60) {
105 frameperiod->numerator = 1001;
106 frameperiod->denominator = 30000;
108 frameperiod->numerator = 1;
109 frameperiod->denominator = 25;
112 EXPORT_SYMBOL(v4l2_video_std_frame_period);
114 /* Fill in the fields of a v4l2_standard structure according to the
115 'id' and 'transmission' parameters. Returns negative on error. */
116 int v4l2_video_std_construct(struct v4l2_standard *vs,
117 int id, const char *name)
120 v4l2_video_std_frame_period(id, &vs->frameperiod);
121 vs->framelines = (id & V4L2_STD_525_60) ? 525 : 625;
122 strlcpy(vs->name, name, sizeof(vs->name));
125 EXPORT_SYMBOL(v4l2_video_std_construct);
127 /* ----------------------------------------------------------------- */
128 /* some arrays for pretty-printing debug messages of enum types */
130 const char *v4l2_field_names[] = {
131 [V4L2_FIELD_ANY] = "any",
132 [V4L2_FIELD_NONE] = "none",
133 [V4L2_FIELD_TOP] = "top",
134 [V4L2_FIELD_BOTTOM] = "bottom",
135 [V4L2_FIELD_INTERLACED] = "interlaced",
136 [V4L2_FIELD_SEQ_TB] = "seq-tb",
137 [V4L2_FIELD_SEQ_BT] = "seq-bt",
138 [V4L2_FIELD_ALTERNATE] = "alternate",
139 [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
140 [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
142 EXPORT_SYMBOL(v4l2_field_names);
144 const char *v4l2_type_names[] = {
145 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "vid-cap",
146 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "vid-overlay",
147 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "vid-out",
148 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
149 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
150 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
151 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out",
152 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "vid-out-overlay",
153 [V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE] = "vid-cap-mplane",
154 [V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE] = "vid-out-mplane",
156 EXPORT_SYMBOL(v4l2_type_names);
158 static const char *v4l2_memory_names[] = {
159 [V4L2_MEMORY_MMAP] = "mmap",
160 [V4L2_MEMORY_USERPTR] = "userptr",
161 [V4L2_MEMORY_OVERLAY] = "overlay",
162 [V4L2_MEMORY_DMABUF] = "dmabuf",
165 #define prt_names(a, arr) (((unsigned)(a)) < ARRAY_SIZE(arr) ? arr[a] : "unknown")
167 /* ------------------------------------------------------------------ */
168 /* debug help functions */
170 static void v4l_print_querycap(const void *arg, bool write_only)
172 const struct v4l2_capability *p = arg;
174 pr_cont("driver=%.*s, card=%.*s, bus=%.*s, version=0x%08x, "
175 "capabilities=0x%08x, device_caps=0x%08x\n",
176 (int)sizeof(p->driver), p->driver,
177 (int)sizeof(p->card), p->card,
178 (int)sizeof(p->bus_info), p->bus_info,
179 p->version, p->capabilities, p->device_caps);
182 static void v4l_print_enuminput(const void *arg, bool write_only)
184 const struct v4l2_input *p = arg;
186 pr_cont("index=%u, name=%.*s, type=%u, audioset=0x%x, tuner=%u, "
187 "std=0x%08Lx, status=0x%x, capabilities=0x%x\n",
188 p->index, (int)sizeof(p->name), p->name, p->type, p->audioset,
189 p->tuner, (unsigned long long)p->std, p->status,
193 static void v4l_print_enumoutput(const void *arg, bool write_only)
195 const struct v4l2_output *p = arg;
197 pr_cont("index=%u, name=%.*s, type=%u, audioset=0x%x, "
198 "modulator=%u, std=0x%08Lx, capabilities=0x%x\n",
199 p->index, (int)sizeof(p->name), p->name, p->type, p->audioset,
200 p->modulator, (unsigned long long)p->std, p->capabilities);
203 static void v4l_print_audio(const void *arg, bool write_only)
205 const struct v4l2_audio *p = arg;
208 pr_cont("index=%u, mode=0x%x\n", p->index, p->mode);
210 pr_cont("index=%u, name=%.*s, capability=0x%x, mode=0x%x\n",
211 p->index, (int)sizeof(p->name), p->name,
212 p->capability, p->mode);
215 static void v4l_print_audioout(const void *arg, bool write_only)
217 const struct v4l2_audioout *p = arg;
220 pr_cont("index=%u\n", p->index);
222 pr_cont("index=%u, name=%.*s, capability=0x%x, mode=0x%x\n",
223 p->index, (int)sizeof(p->name), p->name,
224 p->capability, p->mode);
227 static void v4l_print_fmtdesc(const void *arg, bool write_only)
229 const struct v4l2_fmtdesc *p = arg;
231 pr_cont("index=%u, type=%s, flags=0x%x, pixelformat=%c%c%c%c, description='%.*s'\n",
232 p->index, prt_names(p->type, v4l2_type_names),
233 p->flags, (p->pixelformat & 0xff),
234 (p->pixelformat >> 8) & 0xff,
235 (p->pixelformat >> 16) & 0xff,
236 (p->pixelformat >> 24) & 0xff,
237 (int)sizeof(p->description), p->description);
240 static void v4l_print_format(const void *arg, bool write_only)
242 const struct v4l2_format *p = arg;
243 const struct v4l2_pix_format *pix;
244 const struct v4l2_pix_format_mplane *mp;
245 const struct v4l2_vbi_format *vbi;
246 const struct v4l2_sliced_vbi_format *sliced;
247 const struct v4l2_window *win;
250 pr_cont("type=%s", prt_names(p->type, v4l2_type_names));
252 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
253 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
255 pr_cont(", width=%u, height=%u, "
256 "pixelformat=%c%c%c%c, field=%s, "
257 "bytesperline=%u, sizeimage=%u, colorspace=%d, "
259 pix->width, pix->height,
260 (pix->pixelformat & 0xff),
261 (pix->pixelformat >> 8) & 0xff,
262 (pix->pixelformat >> 16) & 0xff,
263 (pix->pixelformat >> 24) & 0xff,
264 prt_names(pix->field, v4l2_field_names),
265 pix->bytesperline, pix->sizeimage,
266 pix->colorspace, pix->flags);
268 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
269 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
271 pr_cont(", width=%u, height=%u, "
272 "format=%c%c%c%c, field=%s, "
273 "colorspace=%d, num_planes=%u\n",
274 mp->width, mp->height,
275 (mp->pixelformat & 0xff),
276 (mp->pixelformat >> 8) & 0xff,
277 (mp->pixelformat >> 16) & 0xff,
278 (mp->pixelformat >> 24) & 0xff,
279 prt_names(mp->field, v4l2_field_names),
280 mp->colorspace, mp->num_planes);
281 for (i = 0; i < mp->num_planes; i++)
282 printk(KERN_DEBUG "plane %u: bytesperline=%u sizeimage=%u\n", i,
283 mp->plane_fmt[i].bytesperline,
284 mp->plane_fmt[i].sizeimage);
286 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
287 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
289 /* Note: we can't print the clip list here since the clips
290 * pointer is a userspace pointer, not a kernelspace
292 pr_cont(", wxh=%dx%d, x,y=%d,%d, field=%s, chromakey=0x%08x, clipcount=%u, clips=%p, bitmap=%p, global_alpha=0x%02x\n",
293 win->w.width, win->w.height, win->w.left, win->w.top,
294 prt_names(win->field, v4l2_field_names),
295 win->chromakey, win->clipcount, win->clips,
296 win->bitmap, win->global_alpha);
298 case V4L2_BUF_TYPE_VBI_CAPTURE:
299 case V4L2_BUF_TYPE_VBI_OUTPUT:
301 pr_cont(", sampling_rate=%u, offset=%u, samples_per_line=%u, "
302 "sample_format=%c%c%c%c, start=%u,%u, count=%u,%u\n",
303 vbi->sampling_rate, vbi->offset,
304 vbi->samples_per_line,
305 (vbi->sample_format & 0xff),
306 (vbi->sample_format >> 8) & 0xff,
307 (vbi->sample_format >> 16) & 0xff,
308 (vbi->sample_format >> 24) & 0xff,
309 vbi->start[0], vbi->start[1],
310 vbi->count[0], vbi->count[1]);
312 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
313 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
314 sliced = &p->fmt.sliced;
315 pr_cont(", service_set=0x%08x, io_size=%d\n",
316 sliced->service_set, sliced->io_size);
317 for (i = 0; i < 24; i++)
318 printk(KERN_DEBUG "line[%02u]=0x%04x, 0x%04x\n", i,
319 sliced->service_lines[0][i],
320 sliced->service_lines[1][i]);
325 static void v4l_print_framebuffer(const void *arg, bool write_only)
327 const struct v4l2_framebuffer *p = arg;
329 pr_cont("capability=0x%x, flags=0x%x, base=0x%p, width=%u, "
330 "height=%u, pixelformat=%c%c%c%c, "
331 "bytesperline=%u, sizeimage=%u, colorspace=%d\n",
332 p->capability, p->flags, p->base,
333 p->fmt.width, p->fmt.height,
334 (p->fmt.pixelformat & 0xff),
335 (p->fmt.pixelformat >> 8) & 0xff,
336 (p->fmt.pixelformat >> 16) & 0xff,
337 (p->fmt.pixelformat >> 24) & 0xff,
338 p->fmt.bytesperline, p->fmt.sizeimage,
342 static void v4l_print_buftype(const void *arg, bool write_only)
344 pr_cont("type=%s\n", prt_names(*(u32 *)arg, v4l2_type_names));
347 static void v4l_print_modulator(const void *arg, bool write_only)
349 const struct v4l2_modulator *p = arg;
352 pr_cont("index=%u, txsubchans=0x%x\n", p->index, p->txsubchans);
354 pr_cont("index=%u, name=%.*s, capability=0x%x, "
355 "rangelow=%u, rangehigh=%u, txsubchans=0x%x\n",
356 p->index, (int)sizeof(p->name), p->name, p->capability,
357 p->rangelow, p->rangehigh, p->txsubchans);
360 static void v4l_print_tuner(const void *arg, bool write_only)
362 const struct v4l2_tuner *p = arg;
365 pr_cont("index=%u, audmode=%u\n", p->index, p->audmode);
367 pr_cont("index=%u, name=%.*s, type=%u, capability=0x%x, "
368 "rangelow=%u, rangehigh=%u, signal=%u, afc=%d, "
369 "rxsubchans=0x%x, audmode=%u\n",
370 p->index, (int)sizeof(p->name), p->name, p->type,
371 p->capability, p->rangelow,
372 p->rangehigh, p->signal, p->afc,
373 p->rxsubchans, p->audmode);
376 static void v4l_print_frequency(const void *arg, bool write_only)
378 const struct v4l2_frequency *p = arg;
380 pr_cont("tuner=%u, type=%u, frequency=%u\n",
381 p->tuner, p->type, p->frequency);
384 static void v4l_print_standard(const void *arg, bool write_only)
386 const struct v4l2_standard *p = arg;
388 pr_cont("index=%u, id=0x%Lx, name=%.*s, fps=%u/%u, "
389 "framelines=%u\n", p->index,
390 (unsigned long long)p->id, (int)sizeof(p->name), p->name,
391 p->frameperiod.numerator,
392 p->frameperiod.denominator,
396 static void v4l_print_std(const void *arg, bool write_only)
398 pr_cont("std=0x%08Lx\n", *(const long long unsigned *)arg);
401 static void v4l_print_hw_freq_seek(const void *arg, bool write_only)
403 const struct v4l2_hw_freq_seek *p = arg;
405 pr_cont("tuner=%u, type=%u, seek_upward=%u, wrap_around=%u, spacing=%u, "
406 "rangelow=%u, rangehigh=%u\n",
407 p->tuner, p->type, p->seek_upward, p->wrap_around, p->spacing,
408 p->rangelow, p->rangehigh);
411 static void v4l_print_requestbuffers(const void *arg, bool write_only)
413 const struct v4l2_requestbuffers *p = arg;
415 pr_cont("count=%d, type=%s, memory=%s\n",
417 prt_names(p->type, v4l2_type_names),
418 prt_names(p->memory, v4l2_memory_names));
421 static void v4l_print_buffer(const void *arg, bool write_only)
423 const struct v4l2_buffer *p = arg;
424 const struct v4l2_timecode *tc = &p->timecode;
425 const struct v4l2_plane *plane;
428 pr_cont("%02ld:%02d:%02d.%08ld index=%d, type=%s, "
429 "flags=0x%08x, field=%s, sequence=%d, memory=%s",
430 p->timestamp.tv_sec / 3600,
431 (int)(p->timestamp.tv_sec / 60) % 60,
432 (int)(p->timestamp.tv_sec % 60),
433 (long)p->timestamp.tv_usec,
435 prt_names(p->type, v4l2_type_names),
436 p->flags, prt_names(p->field, v4l2_field_names),
437 p->sequence, prt_names(p->memory, v4l2_memory_names));
439 if (V4L2_TYPE_IS_MULTIPLANAR(p->type) && p->m.planes) {
441 for (i = 0; i < p->length; ++i) {
442 plane = &p->m.planes[i];
444 "plane %d: bytesused=%d, data_offset=0x%08x, "
445 "offset/userptr=0x%lx, length=%d\n",
446 i, plane->bytesused, plane->data_offset,
447 plane->m.userptr, plane->length);
450 pr_cont(", bytesused=%d, offset/userptr=0x%lx, length=%d\n",
451 p->bytesused, p->m.userptr, p->length);
454 printk(KERN_DEBUG "timecode=%02d:%02d:%02d type=%d, "
455 "flags=0x%08x, frames=%d, userbits=0x%08x\n",
456 tc->hours, tc->minutes, tc->seconds,
457 tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits);
460 static void v4l_print_exportbuffer(const void *arg, bool write_only)
462 const struct v4l2_exportbuffer *p = arg;
464 pr_cont("fd=%d, type=%s, index=%u, plane=%u, flags=0x%08x\n",
465 p->fd, prt_names(p->type, v4l2_type_names),
466 p->index, p->plane, p->flags);
469 static void v4l_print_create_buffers(const void *arg, bool write_only)
471 const struct v4l2_create_buffers *p = arg;
473 pr_cont("index=%d, count=%d, memory=%s, ",
475 prt_names(p->memory, v4l2_memory_names));
476 v4l_print_format(&p->format, write_only);
479 static void v4l_print_streamparm(const void *arg, bool write_only)
481 const struct v4l2_streamparm *p = arg;
483 pr_cont("type=%s", prt_names(p->type, v4l2_type_names));
485 if (p->type == V4L2_BUF_TYPE_VIDEO_CAPTURE ||
486 p->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
487 const struct v4l2_captureparm *c = &p->parm.capture;
489 pr_cont(", capability=0x%x, capturemode=0x%x, timeperframe=%d/%d, "
490 "extendedmode=%d, readbuffers=%d\n",
491 c->capability, c->capturemode,
492 c->timeperframe.numerator, c->timeperframe.denominator,
493 c->extendedmode, c->readbuffers);
494 } else if (p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT ||
495 p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
496 const struct v4l2_outputparm *c = &p->parm.output;
498 pr_cont(", capability=0x%x, outputmode=0x%x, timeperframe=%d/%d, "
499 "extendedmode=%d, writebuffers=%d\n",
500 c->capability, c->outputmode,
501 c->timeperframe.numerator, c->timeperframe.denominator,
502 c->extendedmode, c->writebuffers);
508 static void v4l_print_queryctrl(const void *arg, bool write_only)
510 const struct v4l2_queryctrl *p = arg;
512 pr_cont("id=0x%x, type=%d, name=%.*s, min/max=%d/%d, "
513 "step=%d, default=%d, flags=0x%08x\n",
514 p->id, p->type, (int)sizeof(p->name), p->name,
515 p->minimum, p->maximum,
516 p->step, p->default_value, p->flags);
519 static void v4l_print_querymenu(const void *arg, bool write_only)
521 const struct v4l2_querymenu *p = arg;
523 pr_cont("id=0x%x, index=%d\n", p->id, p->index);
526 static void v4l_print_control(const void *arg, bool write_only)
528 const struct v4l2_control *p = arg;
530 pr_cont("id=0x%x, value=%d\n", p->id, p->value);
533 static void v4l_print_ext_controls(const void *arg, bool write_only)
535 const struct v4l2_ext_controls *p = arg;
538 pr_cont("class=0x%x, count=%d, error_idx=%d",
539 p->ctrl_class, p->count, p->error_idx);
540 for (i = 0; i < p->count; i++) {
541 if (p->controls[i].size)
542 pr_cont(", id/val=0x%x/0x%x",
543 p->controls[i].id, p->controls[i].value);
545 pr_cont(", id/size=0x%x/%u",
546 p->controls[i].id, p->controls[i].size);
551 static void v4l_print_cropcap(const void *arg, bool write_only)
553 const struct v4l2_cropcap *p = arg;
555 pr_cont("type=%s, bounds wxh=%dx%d, x,y=%d,%d, "
556 "defrect wxh=%dx%d, x,y=%d,%d\n, "
557 "pixelaspect %d/%d\n",
558 prt_names(p->type, v4l2_type_names),
559 p->bounds.width, p->bounds.height,
560 p->bounds.left, p->bounds.top,
561 p->defrect.width, p->defrect.height,
562 p->defrect.left, p->defrect.top,
563 p->pixelaspect.numerator, p->pixelaspect.denominator);
566 static void v4l_print_crop(const void *arg, bool write_only)
568 const struct v4l2_crop *p = arg;
570 pr_cont("type=%s, wxh=%dx%d, x,y=%d,%d\n",
571 prt_names(p->type, v4l2_type_names),
572 p->c.width, p->c.height,
573 p->c.left, p->c.top);
576 static void v4l_print_selection(const void *arg, bool write_only)
578 const struct v4l2_selection *p = arg;
580 pr_cont("type=%s, target=%d, flags=0x%x, wxh=%dx%d, x,y=%d,%d\n",
581 prt_names(p->type, v4l2_type_names),
583 p->r.width, p->r.height, p->r.left, p->r.top);
586 static void v4l_print_jpegcompression(const void *arg, bool write_only)
588 const struct v4l2_jpegcompression *p = arg;
590 pr_cont("quality=%d, APPn=%d, APP_len=%d, "
591 "COM_len=%d, jpeg_markers=0x%x\n",
592 p->quality, p->APPn, p->APP_len,
593 p->COM_len, p->jpeg_markers);
596 static void v4l_print_enc_idx(const void *arg, bool write_only)
598 const struct v4l2_enc_idx *p = arg;
600 pr_cont("entries=%d, entries_cap=%d\n",
601 p->entries, p->entries_cap);
604 static void v4l_print_encoder_cmd(const void *arg, bool write_only)
606 const struct v4l2_encoder_cmd *p = arg;
608 pr_cont("cmd=%d, flags=0x%x\n",
612 static void v4l_print_decoder_cmd(const void *arg, bool write_only)
614 const struct v4l2_decoder_cmd *p = arg;
616 pr_cont("cmd=%d, flags=0x%x\n", p->cmd, p->flags);
618 if (p->cmd == V4L2_DEC_CMD_START)
619 pr_info("speed=%d, format=%u\n",
620 p->start.speed, p->start.format);
621 else if (p->cmd == V4L2_DEC_CMD_STOP)
622 pr_info("pts=%llu\n", p->stop.pts);
625 static void v4l_print_dbg_chip_info(const void *arg, bool write_only)
627 const struct v4l2_dbg_chip_info *p = arg;
629 pr_cont("type=%u, ", p->match.type);
630 if (p->match.type == V4L2_CHIP_MATCH_I2C_DRIVER)
631 pr_cont("name=%.*s, ",
632 (int)sizeof(p->match.name), p->match.name);
634 pr_cont("addr=%u, ", p->match.addr);
635 pr_cont("name=%.*s\n", (int)sizeof(p->name), p->name);
638 static void v4l_print_dbg_register(const void *arg, bool write_only)
640 const struct v4l2_dbg_register *p = arg;
642 pr_cont("type=%u, ", p->match.type);
643 if (p->match.type == V4L2_CHIP_MATCH_I2C_DRIVER)
644 pr_cont("name=%.*s, ",
645 (int)sizeof(p->match.name), p->match.name);
647 pr_cont("addr=%u, ", p->match.addr);
648 pr_cont("reg=0x%llx, val=0x%llx\n",
652 static void v4l_print_dv_timings(const void *arg, bool write_only)
654 const struct v4l2_dv_timings *p = arg;
657 case V4L2_DV_BT_656_1120:
658 pr_cont("type=bt-656/1120, interlaced=%u, "
660 "width=%u, height=%u, polarities=0x%x, "
661 "hfrontporch=%u, hsync=%u, "
662 "hbackporch=%u, vfrontporch=%u, "
663 "vsync=%u, vbackporch=%u, "
664 "il_vfrontporch=%u, il_vsync=%u, "
665 "il_vbackporch=%u, standards=0x%x, flags=0x%x\n",
666 p->bt.interlaced, p->bt.pixelclock,
667 p->bt.width, p->bt.height,
668 p->bt.polarities, p->bt.hfrontporch,
669 p->bt.hsync, p->bt.hbackporch,
670 p->bt.vfrontporch, p->bt.vsync,
671 p->bt.vbackporch, p->bt.il_vfrontporch,
672 p->bt.il_vsync, p->bt.il_vbackporch,
673 p->bt.standards, p->bt.flags);
676 pr_cont("type=%d\n", p->type);
681 static void v4l_print_enum_dv_timings(const void *arg, bool write_only)
683 const struct v4l2_enum_dv_timings *p = arg;
685 pr_cont("index=%u, ", p->index);
686 v4l_print_dv_timings(&p->timings, write_only);
689 static void v4l_print_dv_timings_cap(const void *arg, bool write_only)
691 const struct v4l2_dv_timings_cap *p = arg;
694 case V4L2_DV_BT_656_1120:
695 pr_cont("type=bt-656/1120, width=%u-%u, height=%u-%u, "
696 "pixelclock=%llu-%llu, standards=0x%x, capabilities=0x%x\n",
697 p->bt.min_width, p->bt.max_width,
698 p->bt.min_height, p->bt.max_height,
699 p->bt.min_pixelclock, p->bt.max_pixelclock,
700 p->bt.standards, p->bt.capabilities);
703 pr_cont("type=%u\n", p->type);
708 static void v4l_print_frmsizeenum(const void *arg, bool write_only)
710 const struct v4l2_frmsizeenum *p = arg;
712 pr_cont("index=%u, pixelformat=%c%c%c%c, type=%u",
714 (p->pixel_format & 0xff),
715 (p->pixel_format >> 8) & 0xff,
716 (p->pixel_format >> 16) & 0xff,
717 (p->pixel_format >> 24) & 0xff,
720 case V4L2_FRMSIZE_TYPE_DISCRETE:
721 pr_cont(", wxh=%ux%u\n",
722 p->discrete.width, p->discrete.height);
724 case V4L2_FRMSIZE_TYPE_STEPWISE:
725 pr_cont(", min=%ux%u, max=%ux%u, step=%ux%u\n",
726 p->stepwise.min_width, p->stepwise.min_height,
727 p->stepwise.step_width, p->stepwise.step_height,
728 p->stepwise.max_width, p->stepwise.max_height);
730 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
738 static void v4l_print_frmivalenum(const void *arg, bool write_only)
740 const struct v4l2_frmivalenum *p = arg;
742 pr_cont("index=%u, pixelformat=%c%c%c%c, wxh=%ux%u, type=%u",
744 (p->pixel_format & 0xff),
745 (p->pixel_format >> 8) & 0xff,
746 (p->pixel_format >> 16) & 0xff,
747 (p->pixel_format >> 24) & 0xff,
748 p->width, p->height, p->type);
750 case V4L2_FRMIVAL_TYPE_DISCRETE:
751 pr_cont(", fps=%d/%d\n",
752 p->discrete.numerator,
753 p->discrete.denominator);
755 case V4L2_FRMIVAL_TYPE_STEPWISE:
756 pr_cont(", min=%d/%d, max=%d/%d, step=%d/%d\n",
757 p->stepwise.min.numerator,
758 p->stepwise.min.denominator,
759 p->stepwise.max.numerator,
760 p->stepwise.max.denominator,
761 p->stepwise.step.numerator,
762 p->stepwise.step.denominator);
764 case V4L2_FRMIVAL_TYPE_CONTINUOUS:
772 static void v4l_print_event(const void *arg, bool write_only)
774 const struct v4l2_event *p = arg;
775 const struct v4l2_event_ctrl *c;
777 pr_cont("type=0x%x, pending=%u, sequence=%u, id=%u, "
778 "timestamp=%lu.%9.9lu\n",
779 p->type, p->pending, p->sequence, p->id,
780 p->timestamp.tv_sec, p->timestamp.tv_nsec);
782 case V4L2_EVENT_VSYNC:
783 printk(KERN_DEBUG "field=%s\n",
784 prt_names(p->u.vsync.field, v4l2_field_names));
786 case V4L2_EVENT_CTRL:
788 printk(KERN_DEBUG "changes=0x%x, type=%u, ",
789 c->changes, c->type);
790 if (c->type == V4L2_CTRL_TYPE_INTEGER64)
791 pr_cont("value64=%lld, ", c->value64);
793 pr_cont("value=%d, ", c->value);
794 pr_cont("flags=0x%x, minimum=%d, maximum=%d, step=%d, "
795 "default_value=%d\n",
796 c->flags, c->minimum, c->maximum,
797 c->step, c->default_value);
799 case V4L2_EVENT_FRAME_SYNC:
800 pr_cont("frame_sequence=%u\n",
801 p->u.frame_sync.frame_sequence);
806 static void v4l_print_event_subscription(const void *arg, bool write_only)
808 const struct v4l2_event_subscription *p = arg;
810 pr_cont("type=0x%x, id=0x%x, flags=0x%x\n",
811 p->type, p->id, p->flags);
814 static void v4l_print_sliced_vbi_cap(const void *arg, bool write_only)
816 const struct v4l2_sliced_vbi_cap *p = arg;
819 pr_cont("type=%s, service_set=0x%08x\n",
820 prt_names(p->type, v4l2_type_names), p->service_set);
821 for (i = 0; i < 24; i++)
822 printk(KERN_DEBUG "line[%02u]=0x%04x, 0x%04x\n", i,
823 p->service_lines[0][i],
824 p->service_lines[1][i]);
827 static void v4l_print_freq_band(const void *arg, bool write_only)
829 const struct v4l2_frequency_band *p = arg;
831 pr_cont("tuner=%u, type=%u, index=%u, capability=0x%x, "
832 "rangelow=%u, rangehigh=%u, modulation=0x%x\n",
833 p->tuner, p->type, p->index,
834 p->capability, p->rangelow,
835 p->rangehigh, p->modulation);
838 static void v4l_print_u32(const void *arg, bool write_only)
840 pr_cont("value=%u\n", *(const u32 *)arg);
843 static void v4l_print_newline(const void *arg, bool write_only)
848 static void v4l_print_default(const void *arg, bool write_only)
850 pr_cont("driver-specific ioctl\n");
853 static int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
857 /* zero the reserved fields */
858 c->reserved[0] = c->reserved[1] = 0;
859 for (i = 0; i < c->count; i++)
860 c->controls[i].reserved2[0] = 0;
862 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
863 when using extended controls.
864 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
865 is it allowed for backwards compatibility.
867 if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE)
869 /* Check that all controls are from the same control class. */
870 for (i = 0; i < c->count; i++) {
871 if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) {
879 static int check_fmt(struct file *file, enum v4l2_buf_type type)
881 struct video_device *vfd = video_devdata(file);
882 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
883 bool is_vid = vfd->vfl_type == VFL_TYPE_GRABBER;
884 bool is_vbi = vfd->vfl_type == VFL_TYPE_VBI;
885 bool is_rx = vfd->vfl_dir != VFL_DIR_TX;
886 bool is_tx = vfd->vfl_dir != VFL_DIR_RX;
892 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
893 if (is_vid && is_rx &&
894 (ops->vidioc_g_fmt_vid_cap || ops->vidioc_g_fmt_vid_cap_mplane))
897 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
898 if (is_vid && is_rx && ops->vidioc_g_fmt_vid_cap_mplane)
901 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
902 if (is_vid && is_rx && ops->vidioc_g_fmt_vid_overlay)
905 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
906 if (is_vid && is_tx &&
907 (ops->vidioc_g_fmt_vid_out || ops->vidioc_g_fmt_vid_out_mplane))
910 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
911 if (is_vid && is_tx && ops->vidioc_g_fmt_vid_out_mplane)
914 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
915 if (is_vid && is_tx && ops->vidioc_g_fmt_vid_out_overlay)
918 case V4L2_BUF_TYPE_VBI_CAPTURE:
919 if (is_vbi && is_rx && ops->vidioc_g_fmt_vbi_cap)
922 case V4L2_BUF_TYPE_VBI_OUTPUT:
923 if (is_vbi && is_tx && ops->vidioc_g_fmt_vbi_out)
926 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
927 if (is_vbi && is_rx && ops->vidioc_g_fmt_sliced_vbi_cap)
930 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
931 if (is_vbi && is_tx && ops->vidioc_g_fmt_sliced_vbi_out)
940 static void v4l_sanitize_format(struct v4l2_format *fmt)
945 * The v4l2_pix_format structure has been extended with fields that were
946 * not previously required to be set to zero by applications. The priv
947 * field, when set to a magic value, indicates the the extended fields
948 * are valid. Otherwise they will contain undefined values. To simplify
949 * the API towards drivers zero the extended fields and set the priv
950 * field to the magic value when the extended pixel format structure
951 * isn't used by applications.
954 if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
955 fmt->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
958 if (fmt->fmt.pix.priv == V4L2_PIX_FMT_PRIV_MAGIC)
961 fmt->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;
963 offset = offsetof(struct v4l2_pix_format, priv)
964 + sizeof(fmt->fmt.pix.priv);
965 memset(((void *)&fmt->fmt.pix) + offset, 0,
966 sizeof(fmt->fmt.pix) - offset);
969 static int v4l_querycap(const struct v4l2_ioctl_ops *ops,
970 struct file *file, void *fh, void *arg)
972 struct v4l2_capability *cap = (struct v4l2_capability *)arg;
975 cap->version = LINUX_VERSION_CODE;
977 ret = ops->vidioc_querycap(file, fh, cap);
979 cap->capabilities |= V4L2_CAP_EXT_PIX_FORMAT;
984 static int v4l_s_input(const struct v4l2_ioctl_ops *ops,
985 struct file *file, void *fh, void *arg)
987 return ops->vidioc_s_input(file, fh, *(unsigned int *)arg);
990 static int v4l_s_output(const struct v4l2_ioctl_ops *ops,
991 struct file *file, void *fh, void *arg)
993 return ops->vidioc_s_output(file, fh, *(unsigned int *)arg);
996 static int v4l_g_priority(const struct v4l2_ioctl_ops *ops,
997 struct file *file, void *fh, void *arg)
999 struct video_device *vfd;
1002 if (ops->vidioc_g_priority)
1003 return ops->vidioc_g_priority(file, fh, arg);
1004 vfd = video_devdata(file);
1005 *p = v4l2_prio_max(&vfd->v4l2_dev->prio);
1009 static int v4l_s_priority(const struct v4l2_ioctl_ops *ops,
1010 struct file *file, void *fh, void *arg)
1012 struct video_device *vfd;
1013 struct v4l2_fh *vfh;
1016 if (ops->vidioc_s_priority)
1017 return ops->vidioc_s_priority(file, fh, *p);
1018 vfd = video_devdata(file);
1019 vfh = file->private_data;
1020 return v4l2_prio_change(&vfd->v4l2_dev->prio, &vfh->prio, *p);
1023 static int v4l_enuminput(const struct v4l2_ioctl_ops *ops,
1024 struct file *file, void *fh, void *arg)
1026 struct video_device *vfd = video_devdata(file);
1027 struct v4l2_input *p = arg;
1030 * We set the flags for CAP_DV_TIMINGS &
1031 * CAP_STD here based on ioctl handler provided by the
1032 * driver. If the driver doesn't support these
1033 * for a specific input, it must override these flags.
1035 if (is_valid_ioctl(vfd, VIDIOC_S_STD))
1036 p->capabilities |= V4L2_IN_CAP_STD;
1038 return ops->vidioc_enum_input(file, fh, p);
1041 static int v4l_enumoutput(const struct v4l2_ioctl_ops *ops,
1042 struct file *file, void *fh, void *arg)
1044 struct video_device *vfd = video_devdata(file);
1045 struct v4l2_output *p = arg;
1048 * We set the flags for CAP_DV_TIMINGS &
1049 * CAP_STD here based on ioctl handler provided by the
1050 * driver. If the driver doesn't support these
1051 * for a specific output, it must override these flags.
1053 if (is_valid_ioctl(vfd, VIDIOC_S_STD))
1054 p->capabilities |= V4L2_OUT_CAP_STD;
1056 return ops->vidioc_enum_output(file, fh, p);
1059 static int v4l_enum_fmt(const struct v4l2_ioctl_ops *ops,
1060 struct file *file, void *fh, void *arg)
1062 struct v4l2_fmtdesc *p = arg;
1063 struct video_device *vfd = video_devdata(file);
1064 bool is_rx = vfd->vfl_dir != VFL_DIR_TX;
1065 bool is_tx = vfd->vfl_dir != VFL_DIR_RX;
1068 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1069 if (unlikely(!is_rx || !ops->vidioc_enum_fmt_vid_cap))
1071 return ops->vidioc_enum_fmt_vid_cap(file, fh, arg);
1072 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
1073 if (unlikely(!is_rx || !ops->vidioc_enum_fmt_vid_cap_mplane))
1075 return ops->vidioc_enum_fmt_vid_cap_mplane(file, fh, arg);
1076 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
1077 if (unlikely(!is_rx || !ops->vidioc_enum_fmt_vid_overlay))
1079 return ops->vidioc_enum_fmt_vid_overlay(file, fh, arg);
1080 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
1081 if (unlikely(!is_tx || !ops->vidioc_enum_fmt_vid_out))
1083 return ops->vidioc_enum_fmt_vid_out(file, fh, arg);
1084 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
1085 if (unlikely(!is_tx || !ops->vidioc_enum_fmt_vid_out_mplane))
1087 return ops->vidioc_enum_fmt_vid_out_mplane(file, fh, arg);
1092 static int v4l_g_fmt(const struct v4l2_ioctl_ops *ops,
1093 struct file *file, void *fh, void *arg)
1095 struct v4l2_format *p = arg;
1096 struct video_device *vfd = video_devdata(file);
1097 bool is_vid = vfd->vfl_type == VFL_TYPE_GRABBER;
1098 bool is_rx = vfd->vfl_dir != VFL_DIR_TX;
1099 bool is_tx = vfd->vfl_dir != VFL_DIR_RX;
1102 v4l_sanitize_format(p);
1105 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1106 if (unlikely(!is_rx || !is_vid || !ops->vidioc_g_fmt_vid_cap))
1108 ret = ops->vidioc_g_fmt_vid_cap(file, fh, arg);
1109 p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;
1111 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
1112 if (unlikely(!is_rx || !is_vid || !ops->vidioc_g_fmt_vid_cap_mplane))
1114 return ops->vidioc_g_fmt_vid_cap_mplane(file, fh, arg);
1115 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
1116 if (unlikely(!is_rx || !is_vid || !ops->vidioc_g_fmt_vid_overlay))
1118 return ops->vidioc_g_fmt_vid_overlay(file, fh, arg);
1119 case V4L2_BUF_TYPE_VBI_CAPTURE:
1120 if (unlikely(!is_rx || is_vid || !ops->vidioc_g_fmt_vbi_cap))
1122 return ops->vidioc_g_fmt_vbi_cap(file, fh, arg);
1123 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
1124 if (unlikely(!is_rx || is_vid || !ops->vidioc_g_fmt_sliced_vbi_cap))
1126 return ops->vidioc_g_fmt_sliced_vbi_cap(file, fh, arg);
1127 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
1128 if (unlikely(!is_tx || !is_vid || !ops->vidioc_g_fmt_vid_out))
1130 ret = ops->vidioc_g_fmt_vid_out(file, fh, arg);
1131 p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;
1133 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
1134 if (unlikely(!is_tx || !is_vid || !ops->vidioc_g_fmt_vid_out_mplane))
1136 return ops->vidioc_g_fmt_vid_out_mplane(file, fh, arg);
1137 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
1138 if (unlikely(!is_tx || !is_vid || !ops->vidioc_g_fmt_vid_out_overlay))
1140 return ops->vidioc_g_fmt_vid_out_overlay(file, fh, arg);
1141 case V4L2_BUF_TYPE_VBI_OUTPUT:
1142 if (unlikely(!is_tx || is_vid || !ops->vidioc_g_fmt_vbi_out))
1144 return ops->vidioc_g_fmt_vbi_out(file, fh, arg);
1145 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
1146 if (unlikely(!is_tx || is_vid || !ops->vidioc_g_fmt_sliced_vbi_out))
1148 return ops->vidioc_g_fmt_sliced_vbi_out(file, fh, arg);
1153 static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops,
1154 struct file *file, void *fh, void *arg)
1156 struct v4l2_format *p = arg;
1157 struct video_device *vfd = video_devdata(file);
1158 bool is_vid = vfd->vfl_type == VFL_TYPE_GRABBER;
1159 bool is_rx = vfd->vfl_dir != VFL_DIR_TX;
1160 bool is_tx = vfd->vfl_dir != VFL_DIR_RX;
1163 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1164 if (unlikely(!is_rx || !is_vid || !ops->vidioc_s_fmt_vid_cap))
1166 CLEAR_AFTER_FIELD(p, fmt.pix);
1167 return ops->vidioc_s_fmt_vid_cap(file, fh, arg);
1168 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
1169 if (unlikely(!is_rx || !is_vid || !ops->vidioc_s_fmt_vid_cap_mplane))
1171 CLEAR_AFTER_FIELD(p, fmt.pix_mp);
1172 return ops->vidioc_s_fmt_vid_cap_mplane(file, fh, arg);
1173 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
1174 if (unlikely(!is_rx || !is_vid || !ops->vidioc_s_fmt_vid_overlay))
1176 CLEAR_AFTER_FIELD(p, fmt.win);
1177 return ops->vidioc_s_fmt_vid_overlay(file, fh, arg);
1178 case V4L2_BUF_TYPE_VBI_CAPTURE:
1179 if (unlikely(!is_rx || is_vid || !ops->vidioc_s_fmt_vbi_cap))
1181 CLEAR_AFTER_FIELD(p, fmt.vbi);
1182 return ops->vidioc_s_fmt_vbi_cap(file, fh, arg);
1183 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
1184 if (unlikely(!is_rx || is_vid || !ops->vidioc_s_fmt_sliced_vbi_cap))
1186 CLEAR_AFTER_FIELD(p, fmt.sliced);
1187 return ops->vidioc_s_fmt_sliced_vbi_cap(file, fh, arg);
1188 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
1189 if (unlikely(!is_tx || !is_vid || !ops->vidioc_s_fmt_vid_out))
1191 CLEAR_AFTER_FIELD(p, fmt.pix);
1192 return ops->vidioc_s_fmt_vid_out(file, fh, arg);
1193 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
1194 if (unlikely(!is_tx || !is_vid || !ops->vidioc_s_fmt_vid_out_mplane))
1196 CLEAR_AFTER_FIELD(p, fmt.pix_mp);
1197 return ops->vidioc_s_fmt_vid_out_mplane(file, fh, arg);
1198 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
1199 if (unlikely(!is_tx || !is_vid || !ops->vidioc_s_fmt_vid_out_overlay))
1201 CLEAR_AFTER_FIELD(p, fmt.win);
1202 return ops->vidioc_s_fmt_vid_out_overlay(file, fh, arg);
1203 case V4L2_BUF_TYPE_VBI_OUTPUT:
1204 if (unlikely(!is_tx || is_vid || !ops->vidioc_s_fmt_vbi_out))
1206 CLEAR_AFTER_FIELD(p, fmt.vbi);
1207 return ops->vidioc_s_fmt_vbi_out(file, fh, arg);
1208 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
1209 if (unlikely(!is_tx || is_vid || !ops->vidioc_s_fmt_sliced_vbi_out))
1211 CLEAR_AFTER_FIELD(p, fmt.sliced);
1212 return ops->vidioc_s_fmt_sliced_vbi_out(file, fh, arg);
1217 static int v4l_try_fmt(const struct v4l2_ioctl_ops *ops,
1218 struct file *file, void *fh, void *arg)
1220 struct v4l2_format *p = arg;
1221 struct video_device *vfd = video_devdata(file);
1222 bool is_vid = vfd->vfl_type == VFL_TYPE_GRABBER;
1223 bool is_rx = vfd->vfl_dir != VFL_DIR_TX;
1224 bool is_tx = vfd->vfl_dir != VFL_DIR_RX;
1227 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1228 if (unlikely(!is_rx || !is_vid || !ops->vidioc_try_fmt_vid_cap))
1230 CLEAR_AFTER_FIELD(p, fmt.pix);
1231 return ops->vidioc_try_fmt_vid_cap(file, fh, arg);
1232 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
1233 if (unlikely(!is_rx || !is_vid || !ops->vidioc_try_fmt_vid_cap_mplane))
1235 CLEAR_AFTER_FIELD(p, fmt.pix_mp);
1236 return ops->vidioc_try_fmt_vid_cap_mplane(file, fh, arg);
1237 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
1238 if (unlikely(!is_rx || !is_vid || !ops->vidioc_try_fmt_vid_overlay))
1240 CLEAR_AFTER_FIELD(p, fmt.win);
1241 return ops->vidioc_try_fmt_vid_overlay(file, fh, arg);
1242 case V4L2_BUF_TYPE_VBI_CAPTURE:
1243 if (unlikely(!is_rx || is_vid || !ops->vidioc_try_fmt_vbi_cap))
1245 CLEAR_AFTER_FIELD(p, fmt.vbi);
1246 return ops->vidioc_try_fmt_vbi_cap(file, fh, arg);
1247 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
1248 if (unlikely(!is_rx || is_vid || !ops->vidioc_try_fmt_sliced_vbi_cap))
1250 CLEAR_AFTER_FIELD(p, fmt.sliced);
1251 return ops->vidioc_try_fmt_sliced_vbi_cap(file, fh, arg);
1252 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
1253 if (unlikely(!is_tx || !is_vid || !ops->vidioc_try_fmt_vid_out))
1255 CLEAR_AFTER_FIELD(p, fmt.pix);
1256 return ops->vidioc_try_fmt_vid_out(file, fh, arg);
1257 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
1258 if (unlikely(!is_tx || !is_vid || !ops->vidioc_try_fmt_vid_out_mplane))
1260 CLEAR_AFTER_FIELD(p, fmt.pix_mp);
1261 return ops->vidioc_try_fmt_vid_out_mplane(file, fh, arg);
1262 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
1263 if (unlikely(!is_tx || !is_vid || !ops->vidioc_try_fmt_vid_out_overlay))
1265 CLEAR_AFTER_FIELD(p, fmt.win);
1266 return ops->vidioc_try_fmt_vid_out_overlay(file, fh, arg);
1267 case V4L2_BUF_TYPE_VBI_OUTPUT:
1268 if (unlikely(!is_tx || is_vid || !ops->vidioc_try_fmt_vbi_out))
1270 CLEAR_AFTER_FIELD(p, fmt.vbi);
1271 return ops->vidioc_try_fmt_vbi_out(file, fh, arg);
1272 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
1273 if (unlikely(!is_tx || is_vid || !ops->vidioc_try_fmt_sliced_vbi_out))
1275 CLEAR_AFTER_FIELD(p, fmt.sliced);
1276 return ops->vidioc_try_fmt_sliced_vbi_out(file, fh, arg);
1281 static int v4l_streamon(const struct v4l2_ioctl_ops *ops,
1282 struct file *file, void *fh, void *arg)
1284 return ops->vidioc_streamon(file, fh, *(unsigned int *)arg);
1287 static int v4l_streamoff(const struct v4l2_ioctl_ops *ops,
1288 struct file *file, void *fh, void *arg)
1290 return ops->vidioc_streamoff(file, fh, *(unsigned int *)arg);
1293 static int v4l_g_tuner(const struct v4l2_ioctl_ops *ops,
1294 struct file *file, void *fh, void *arg)
1296 struct video_device *vfd = video_devdata(file);
1297 struct v4l2_tuner *p = arg;
1300 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1301 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1302 err = ops->vidioc_g_tuner(file, fh, p);
1304 p->capability |= V4L2_TUNER_CAP_FREQ_BANDS;
1308 static int v4l_s_tuner(const struct v4l2_ioctl_ops *ops,
1309 struct file *file, void *fh, void *arg)
1311 struct video_device *vfd = video_devdata(file);
1312 struct v4l2_tuner *p = arg;
1314 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1315 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1316 return ops->vidioc_s_tuner(file, fh, p);
1319 static int v4l_g_modulator(const struct v4l2_ioctl_ops *ops,
1320 struct file *file, void *fh, void *arg)
1322 struct v4l2_modulator *p = arg;
1325 err = ops->vidioc_g_modulator(file, fh, p);
1327 p->capability |= V4L2_TUNER_CAP_FREQ_BANDS;
1331 static int v4l_g_frequency(const struct v4l2_ioctl_ops *ops,
1332 struct file *file, void *fh, void *arg)
1334 struct video_device *vfd = video_devdata(file);
1335 struct v4l2_frequency *p = arg;
1337 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1338 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1339 return ops->vidioc_g_frequency(file, fh, p);
1342 static int v4l_s_frequency(const struct v4l2_ioctl_ops *ops,
1343 struct file *file, void *fh, void *arg)
1345 struct video_device *vfd = video_devdata(file);
1346 const struct v4l2_frequency *p = arg;
1347 enum v4l2_tuner_type type;
1349 type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1350 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1351 if (p->type != type)
1353 return ops->vidioc_s_frequency(file, fh, p);
1356 static int v4l_enumstd(const struct v4l2_ioctl_ops *ops,
1357 struct file *file, void *fh, void *arg)
1359 struct video_device *vfd = video_devdata(file);
1360 struct v4l2_standard *p = arg;
1361 v4l2_std_id id = vfd->tvnorms, curr_id = 0;
1362 unsigned int index = p->index, i, j = 0;
1363 const char *descr = "";
1365 /* Return -ENODATA if the tvnorms for the current input
1366 or output is 0, meaning that it doesn't support this API. */
1370 /* Return norm array in a canonical way */
1371 for (i = 0; i <= index && id; i++) {
1372 /* last std value in the standards array is 0, so this
1373 while always ends there since (id & 0) == 0. */
1374 while ((id & standards[j].std) != standards[j].std)
1376 curr_id = standards[j].std;
1377 descr = standards[j].descr;
1381 if (curr_id != V4L2_STD_PAL &&
1382 curr_id != V4L2_STD_SECAM &&
1383 curr_id != V4L2_STD_NTSC)
1389 v4l2_video_std_construct(p, curr_id, descr);
1393 static int v4l_s_std(const struct v4l2_ioctl_ops *ops,
1394 struct file *file, void *fh, void *arg)
1396 struct video_device *vfd = video_devdata(file);
1397 v4l2_std_id id = *(v4l2_std_id *)arg, norm;
1399 norm = id & vfd->tvnorms;
1400 if (vfd->tvnorms && !norm) /* Check if std is supported */
1403 /* Calls the specific handler */
1404 return ops->vidioc_s_std(file, fh, norm);
1407 static int v4l_querystd(const struct v4l2_ioctl_ops *ops,
1408 struct file *file, void *fh, void *arg)
1410 struct video_device *vfd = video_devdata(file);
1411 v4l2_std_id *p = arg;
1414 * If no signal is detected, then the driver should return
1415 * V4L2_STD_UNKNOWN. Otherwise it should return tvnorms with
1416 * any standards that do not apply removed.
1418 * This means that tuners, audio and video decoders can join
1419 * their efforts to improve the standards detection.
1422 return ops->vidioc_querystd(file, fh, arg);
1425 static int v4l_s_hw_freq_seek(const struct v4l2_ioctl_ops *ops,
1426 struct file *file, void *fh, void *arg)
1428 struct video_device *vfd = video_devdata(file);
1429 struct v4l2_hw_freq_seek *p = arg;
1430 enum v4l2_tuner_type type;
1432 type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1433 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1434 if (p->type != type)
1436 return ops->vidioc_s_hw_freq_seek(file, fh, p);
1439 static int v4l_overlay(const struct v4l2_ioctl_ops *ops,
1440 struct file *file, void *fh, void *arg)
1442 return ops->vidioc_overlay(file, fh, *(unsigned int *)arg);
1445 static int v4l_reqbufs(const struct v4l2_ioctl_ops *ops,
1446 struct file *file, void *fh, void *arg)
1448 struct v4l2_requestbuffers *p = arg;
1449 int ret = check_fmt(file, p->type);
1454 CLEAR_AFTER_FIELD(p, memory);
1456 return ops->vidioc_reqbufs(file, fh, p);
1459 static int v4l_querybuf(const struct v4l2_ioctl_ops *ops,
1460 struct file *file, void *fh, void *arg)
1462 struct v4l2_buffer *p = arg;
1463 int ret = check_fmt(file, p->type);
1465 return ret ? ret : ops->vidioc_querybuf(file, fh, p);
1468 static int v4l_qbuf(const struct v4l2_ioctl_ops *ops,
1469 struct file *file, void *fh, void *arg)
1471 struct v4l2_buffer *p = arg;
1472 int ret = check_fmt(file, p->type);
1474 return ret ? ret : ops->vidioc_qbuf(file, fh, p);
1477 static int v4l_dqbuf(const struct v4l2_ioctl_ops *ops,
1478 struct file *file, void *fh, void *arg)
1480 struct v4l2_buffer *p = arg;
1481 int ret = check_fmt(file, p->type);
1483 return ret ? ret : ops->vidioc_dqbuf(file, fh, p);
1486 static int v4l_create_bufs(const struct v4l2_ioctl_ops *ops,
1487 struct file *file, void *fh, void *arg)
1489 struct v4l2_create_buffers *create = arg;
1490 int ret = check_fmt(file, create->format.type);
1495 v4l_sanitize_format(&create->format);
1497 ret = ops->vidioc_create_bufs(file, fh, create);
1499 if (create->format.type == V4L2_BUF_TYPE_VIDEO_CAPTURE ||
1500 create->format.type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
1501 create->format.fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC;
1506 static int v4l_prepare_buf(const struct v4l2_ioctl_ops *ops,
1507 struct file *file, void *fh, void *arg)
1509 struct v4l2_buffer *b = arg;
1510 int ret = check_fmt(file, b->type);
1512 return ret ? ret : ops->vidioc_prepare_buf(file, fh, b);
1515 static int v4l_g_parm(const struct v4l2_ioctl_ops *ops,
1516 struct file *file, void *fh, void *arg)
1518 struct v4l2_streamparm *p = arg;
1520 int ret = check_fmt(file, p->type);
1524 if (ops->vidioc_g_parm)
1525 return ops->vidioc_g_parm(file, fh, p);
1526 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
1527 p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
1529 p->parm.capture.readbuffers = 2;
1530 ret = ops->vidioc_g_std(file, fh, &std);
1532 v4l2_video_std_frame_period(std, &p->parm.capture.timeperframe);
1536 static int v4l_s_parm(const struct v4l2_ioctl_ops *ops,
1537 struct file *file, void *fh, void *arg)
1539 struct v4l2_streamparm *p = arg;
1540 int ret = check_fmt(file, p->type);
1542 return ret ? ret : ops->vidioc_s_parm(file, fh, p);
1545 static int v4l_queryctrl(const struct v4l2_ioctl_ops *ops,
1546 struct file *file, void *fh, void *arg)
1548 struct video_device *vfd = video_devdata(file);
1549 struct v4l2_queryctrl *p = arg;
1550 struct v4l2_fh *vfh =
1551 test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL;
1553 if (vfh && vfh->ctrl_handler)
1554 return v4l2_queryctrl(vfh->ctrl_handler, p);
1555 if (vfd->ctrl_handler)
1556 return v4l2_queryctrl(vfd->ctrl_handler, p);
1557 if (ops->vidioc_queryctrl)
1558 return ops->vidioc_queryctrl(file, fh, p);
1562 static int v4l_querymenu(const struct v4l2_ioctl_ops *ops,
1563 struct file *file, void *fh, void *arg)
1565 struct video_device *vfd = video_devdata(file);
1566 struct v4l2_querymenu *p = arg;
1567 struct v4l2_fh *vfh =
1568 test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL;
1570 if (vfh && vfh->ctrl_handler)
1571 return v4l2_querymenu(vfh->ctrl_handler, p);
1572 if (vfd->ctrl_handler)
1573 return v4l2_querymenu(vfd->ctrl_handler, p);
1574 if (ops->vidioc_querymenu)
1575 return ops->vidioc_querymenu(file, fh, p);
1579 static int v4l_g_ctrl(const struct v4l2_ioctl_ops *ops,
1580 struct file *file, void *fh, void *arg)
1582 struct video_device *vfd = video_devdata(file);
1583 struct v4l2_control *p = arg;
1584 struct v4l2_fh *vfh =
1585 test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL;
1586 struct v4l2_ext_controls ctrls;
1587 struct v4l2_ext_control ctrl;
1589 if (vfh && vfh->ctrl_handler)
1590 return v4l2_g_ctrl(vfh->ctrl_handler, p);
1591 if (vfd->ctrl_handler)
1592 return v4l2_g_ctrl(vfd->ctrl_handler, p);
1593 if (ops->vidioc_g_ctrl)
1594 return ops->vidioc_g_ctrl(file, fh, p);
1595 if (ops->vidioc_g_ext_ctrls == NULL)
1598 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1600 ctrls.controls = &ctrl;
1602 ctrl.value = p->value;
1603 if (check_ext_ctrls(&ctrls, 1)) {
1604 int ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls);
1607 p->value = ctrl.value;
1613 static int v4l_s_ctrl(const struct v4l2_ioctl_ops *ops,
1614 struct file *file, void *fh, void *arg)
1616 struct video_device *vfd = video_devdata(file);
1617 struct v4l2_control *p = arg;
1618 struct v4l2_fh *vfh =
1619 test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL;
1620 struct v4l2_ext_controls ctrls;
1621 struct v4l2_ext_control ctrl;
1623 if (vfh && vfh->ctrl_handler)
1624 return v4l2_s_ctrl(vfh, vfh->ctrl_handler, p);
1625 if (vfd->ctrl_handler)
1626 return v4l2_s_ctrl(NULL, vfd->ctrl_handler, p);
1627 if (ops->vidioc_s_ctrl)
1628 return ops->vidioc_s_ctrl(file, fh, p);
1629 if (ops->vidioc_s_ext_ctrls == NULL)
1632 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1634 ctrls.controls = &ctrl;
1636 ctrl.value = p->value;
1637 if (check_ext_ctrls(&ctrls, 1))
1638 return ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
1642 static int v4l_g_ext_ctrls(const struct v4l2_ioctl_ops *ops,
1643 struct file *file, void *fh, void *arg)
1645 struct video_device *vfd = video_devdata(file);
1646 struct v4l2_ext_controls *p = arg;
1647 struct v4l2_fh *vfh =
1648 test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL;
1650 p->error_idx = p->count;
1651 if (vfh && vfh->ctrl_handler)
1652 return v4l2_g_ext_ctrls(vfh->ctrl_handler, p);
1653 if (vfd->ctrl_handler)
1654 return v4l2_g_ext_ctrls(vfd->ctrl_handler, p);
1655 if (ops->vidioc_g_ext_ctrls == NULL)
1657 return check_ext_ctrls(p, 0) ? ops->vidioc_g_ext_ctrls(file, fh, p) :
1661 static int v4l_s_ext_ctrls(const struct v4l2_ioctl_ops *ops,
1662 struct file *file, void *fh, void *arg)
1664 struct video_device *vfd = video_devdata(file);
1665 struct v4l2_ext_controls *p = arg;
1666 struct v4l2_fh *vfh =
1667 test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL;
1669 p->error_idx = p->count;
1670 if (vfh && vfh->ctrl_handler)
1671 return v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, p);
1672 if (vfd->ctrl_handler)
1673 return v4l2_s_ext_ctrls(NULL, vfd->ctrl_handler, p);
1674 if (ops->vidioc_s_ext_ctrls == NULL)
1676 return check_ext_ctrls(p, 0) ? ops->vidioc_s_ext_ctrls(file, fh, p) :
1680 static int v4l_try_ext_ctrls(const struct v4l2_ioctl_ops *ops,
1681 struct file *file, void *fh, void *arg)
1683 struct video_device *vfd = video_devdata(file);
1684 struct v4l2_ext_controls *p = arg;
1685 struct v4l2_fh *vfh =
1686 test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL;
1688 p->error_idx = p->count;
1689 if (vfh && vfh->ctrl_handler)
1690 return v4l2_try_ext_ctrls(vfh->ctrl_handler, p);
1691 if (vfd->ctrl_handler)
1692 return v4l2_try_ext_ctrls(vfd->ctrl_handler, p);
1693 if (ops->vidioc_try_ext_ctrls == NULL)
1695 return check_ext_ctrls(p, 0) ? ops->vidioc_try_ext_ctrls(file, fh, p) :
1699 static int v4l_g_crop(const struct v4l2_ioctl_ops *ops,
1700 struct file *file, void *fh, void *arg)
1702 struct v4l2_crop *p = arg;
1703 struct v4l2_selection s = {
1708 if (ops->vidioc_g_crop)
1709 return ops->vidioc_g_crop(file, fh, p);
1710 /* simulate capture crop using selection api */
1712 /* crop means compose for output devices */
1713 if (V4L2_TYPE_IS_OUTPUT(p->type))
1714 s.target = V4L2_SEL_TGT_COMPOSE_ACTIVE;
1716 s.target = V4L2_SEL_TGT_CROP_ACTIVE;
1718 ret = ops->vidioc_g_selection(file, fh, &s);
1720 /* copying results to old structure on success */
1726 static int v4l_s_crop(const struct v4l2_ioctl_ops *ops,
1727 struct file *file, void *fh, void *arg)
1729 struct v4l2_crop *p = arg;
1730 struct v4l2_selection s = {
1735 if (ops->vidioc_s_crop)
1736 return ops->vidioc_s_crop(file, fh, p);
1737 /* simulate capture crop using selection api */
1739 /* crop means compose for output devices */
1740 if (V4L2_TYPE_IS_OUTPUT(p->type))
1741 s.target = V4L2_SEL_TGT_COMPOSE_ACTIVE;
1743 s.target = V4L2_SEL_TGT_CROP_ACTIVE;
1745 return ops->vidioc_s_selection(file, fh, &s);
1748 static int v4l_cropcap(const struct v4l2_ioctl_ops *ops,
1749 struct file *file, void *fh, void *arg)
1751 struct v4l2_cropcap *p = arg;
1752 struct v4l2_selection s = { .type = p->type };
1755 if (ops->vidioc_cropcap)
1756 return ops->vidioc_cropcap(file, fh, p);
1758 /* obtaining bounds */
1759 if (V4L2_TYPE_IS_OUTPUT(p->type))
1760 s.target = V4L2_SEL_TGT_COMPOSE_BOUNDS;
1762 s.target = V4L2_SEL_TGT_CROP_BOUNDS;
1764 ret = ops->vidioc_g_selection(file, fh, &s);
1769 /* obtaining defrect */
1770 if (V4L2_TYPE_IS_OUTPUT(p->type))
1771 s.target = V4L2_SEL_TGT_COMPOSE_DEFAULT;
1773 s.target = V4L2_SEL_TGT_CROP_DEFAULT;
1775 ret = ops->vidioc_g_selection(file, fh, &s);
1780 /* setting trivial pixelaspect */
1781 p->pixelaspect.numerator = 1;
1782 p->pixelaspect.denominator = 1;
1786 static int v4l_log_status(const struct v4l2_ioctl_ops *ops,
1787 struct file *file, void *fh, void *arg)
1789 struct video_device *vfd = video_devdata(file);
1793 pr_info("%s: ================= START STATUS =================\n",
1794 vfd->v4l2_dev->name);
1795 ret = ops->vidioc_log_status(file, fh);
1797 pr_info("%s: ================== END STATUS ==================\n",
1798 vfd->v4l2_dev->name);
1802 static int v4l_dbg_g_register(const struct v4l2_ioctl_ops *ops,
1803 struct file *file, void *fh, void *arg)
1805 #ifdef CONFIG_VIDEO_ADV_DEBUG
1806 struct v4l2_dbg_register *p = arg;
1807 struct video_device *vfd = video_devdata(file);
1808 struct v4l2_subdev *sd;
1811 if (!capable(CAP_SYS_ADMIN))
1813 if (p->match.type == V4L2_CHIP_MATCH_SUBDEV) {
1814 if (vfd->v4l2_dev == NULL)
1816 v4l2_device_for_each_subdev(sd, vfd->v4l2_dev)
1817 if (p->match.addr == idx++)
1818 return v4l2_subdev_call(sd, core, g_register, p);
1821 if (ops->vidioc_g_register && p->match.type == V4L2_CHIP_MATCH_BRIDGE &&
1822 (ops->vidioc_g_chip_info || p->match.addr == 0))
1823 return ops->vidioc_g_register(file, fh, p);
1830 static int v4l_dbg_s_register(const struct v4l2_ioctl_ops *ops,
1831 struct file *file, void *fh, void *arg)
1833 #ifdef CONFIG_VIDEO_ADV_DEBUG
1834 const struct v4l2_dbg_register *p = arg;
1835 struct video_device *vfd = video_devdata(file);
1836 struct v4l2_subdev *sd;
1839 if (!capable(CAP_SYS_ADMIN))
1841 if (p->match.type == V4L2_CHIP_MATCH_SUBDEV) {
1842 if (vfd->v4l2_dev == NULL)
1844 v4l2_device_for_each_subdev(sd, vfd->v4l2_dev)
1845 if (p->match.addr == idx++)
1846 return v4l2_subdev_call(sd, core, s_register, p);
1849 if (ops->vidioc_s_register && p->match.type == V4L2_CHIP_MATCH_BRIDGE &&
1850 (ops->vidioc_g_chip_info || p->match.addr == 0))
1851 return ops->vidioc_s_register(file, fh, p);
1858 static int v4l_dbg_g_chip_info(const struct v4l2_ioctl_ops *ops,
1859 struct file *file, void *fh, void *arg)
1861 #ifdef CONFIG_VIDEO_ADV_DEBUG
1862 struct video_device *vfd = video_devdata(file);
1863 struct v4l2_dbg_chip_info *p = arg;
1864 struct v4l2_subdev *sd;
1867 switch (p->match.type) {
1868 case V4L2_CHIP_MATCH_BRIDGE:
1869 if (ops->vidioc_s_register)
1870 p->flags |= V4L2_CHIP_FL_WRITABLE;
1871 if (ops->vidioc_g_register)
1872 p->flags |= V4L2_CHIP_FL_READABLE;
1873 strlcpy(p->name, vfd->v4l2_dev->name, sizeof(p->name));
1874 if (ops->vidioc_g_chip_info)
1875 return ops->vidioc_g_chip_info(file, fh, arg);
1880 case V4L2_CHIP_MATCH_SUBDEV:
1881 if (vfd->v4l2_dev == NULL)
1883 v4l2_device_for_each_subdev(sd, vfd->v4l2_dev) {
1884 if (p->match.addr != idx++)
1886 if (sd->ops->core && sd->ops->core->s_register)
1887 p->flags |= V4L2_CHIP_FL_WRITABLE;
1888 if (sd->ops->core && sd->ops->core->g_register)
1889 p->flags |= V4L2_CHIP_FL_READABLE;
1890 strlcpy(p->name, sd->name, sizeof(p->name));
1901 static int v4l_dqevent(const struct v4l2_ioctl_ops *ops,
1902 struct file *file, void *fh, void *arg)
1904 return v4l2_event_dequeue(fh, arg, file->f_flags & O_NONBLOCK);
1907 static int v4l_subscribe_event(const struct v4l2_ioctl_ops *ops,
1908 struct file *file, void *fh, void *arg)
1910 return ops->vidioc_subscribe_event(fh, arg);
1913 static int v4l_unsubscribe_event(const struct v4l2_ioctl_ops *ops,
1914 struct file *file, void *fh, void *arg)
1916 return ops->vidioc_unsubscribe_event(fh, arg);
1919 static int v4l_g_sliced_vbi_cap(const struct v4l2_ioctl_ops *ops,
1920 struct file *file, void *fh, void *arg)
1922 struct v4l2_sliced_vbi_cap *p = arg;
1923 int ret = check_fmt(file, p->type);
1928 /* Clear up to type, everything after type is zeroed already */
1929 memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
1931 return ops->vidioc_g_sliced_vbi_cap(file, fh, p);
1934 static int v4l_enum_freq_bands(const struct v4l2_ioctl_ops *ops,
1935 struct file *file, void *fh, void *arg)
1937 struct video_device *vfd = video_devdata(file);
1938 struct v4l2_frequency_band *p = arg;
1939 enum v4l2_tuner_type type;
1942 type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1943 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1945 if (type != p->type)
1947 if (ops->vidioc_enum_freq_bands)
1948 return ops->vidioc_enum_freq_bands(file, fh, p);
1949 if (is_valid_ioctl(vfd, VIDIOC_G_TUNER)) {
1950 struct v4l2_tuner t = {
1957 err = ops->vidioc_g_tuner(file, fh, &t);
1960 p->capability = t.capability | V4L2_TUNER_CAP_FREQ_BANDS;
1961 p->rangelow = t.rangelow;
1962 p->rangehigh = t.rangehigh;
1963 p->modulation = (type == V4L2_TUNER_RADIO) ?
1964 V4L2_BAND_MODULATION_FM : V4L2_BAND_MODULATION_VSB;
1967 if (is_valid_ioctl(vfd, VIDIOC_G_MODULATOR)) {
1968 struct v4l2_modulator m = {
1972 if (type != V4L2_TUNER_RADIO)
1976 err = ops->vidioc_g_modulator(file, fh, &m);
1979 p->capability = m.capability | V4L2_TUNER_CAP_FREQ_BANDS;
1980 p->rangelow = m.rangelow;
1981 p->rangehigh = m.rangehigh;
1982 p->modulation = (type == V4L2_TUNER_RADIO) ?
1983 V4L2_BAND_MODULATION_FM : V4L2_BAND_MODULATION_VSB;
1989 struct v4l2_ioctl_info {
1992 const char * const name;
1995 int (*func)(const struct v4l2_ioctl_ops *ops,
1996 struct file *file, void *fh, void *p);
1998 void (*debug)(const void *arg, bool write_only);
2001 /* This control needs a priority check */
2002 #define INFO_FL_PRIO (1 << 0)
2003 /* This control can be valid if the filehandle passes a control handler. */
2004 #define INFO_FL_CTRL (1 << 1)
2005 /* This is a standard ioctl, no need for special code */
2006 #define INFO_FL_STD (1 << 2)
2007 /* This is ioctl has its own function */
2008 #define INFO_FL_FUNC (1 << 3)
2010 #define INFO_FL_QUEUE (1 << 4)
2011 /* Zero struct from after the field to the end */
2012 #define INFO_FL_CLEAR(v4l2_struct, field) \
2013 ((offsetof(struct v4l2_struct, field) + \
2014 sizeof(((struct v4l2_struct *)0)->field)) << 16)
2015 #define INFO_FL_CLEAR_MASK (_IOC_SIZEMASK << 16)
2017 #define IOCTL_INFO_STD(_ioctl, _vidioc, _debug, _flags) \
2018 [_IOC_NR(_ioctl)] = { \
2020 .flags = _flags | INFO_FL_STD, \
2022 .u.offset = offsetof(struct v4l2_ioctl_ops, _vidioc), \
2026 #define IOCTL_INFO_FNC(_ioctl, _func, _debug, _flags) \
2027 [_IOC_NR(_ioctl)] = { \
2029 .flags = _flags | INFO_FL_FUNC, \
2035 static struct v4l2_ioctl_info v4l2_ioctls[] = {
2036 IOCTL_INFO_FNC(VIDIOC_QUERYCAP, v4l_querycap, v4l_print_querycap, 0),
2037 IOCTL_INFO_FNC(VIDIOC_ENUM_FMT, v4l_enum_fmt, v4l_print_fmtdesc, INFO_FL_CLEAR(v4l2_fmtdesc, type)),
2038 IOCTL_INFO_FNC(VIDIOC_G_FMT, v4l_g_fmt, v4l_print_format, INFO_FL_CLEAR(v4l2_format, type)),
2039 IOCTL_INFO_FNC(VIDIOC_S_FMT, v4l_s_fmt, v4l_print_format, INFO_FL_PRIO),
2040 IOCTL_INFO_FNC(VIDIOC_REQBUFS, v4l_reqbufs, v4l_print_requestbuffers, INFO_FL_PRIO | INFO_FL_QUEUE),
2041 IOCTL_INFO_FNC(VIDIOC_QUERYBUF, v4l_querybuf, v4l_print_buffer, INFO_FL_QUEUE | INFO_FL_CLEAR(v4l2_buffer, length)),
2042 IOCTL_INFO_STD(VIDIOC_G_FBUF, vidioc_g_fbuf, v4l_print_framebuffer, 0),
2043 IOCTL_INFO_STD(VIDIOC_S_FBUF, vidioc_s_fbuf, v4l_print_framebuffer, INFO_FL_PRIO),
2044 IOCTL_INFO_FNC(VIDIOC_OVERLAY, v4l_overlay, v4l_print_u32, INFO_FL_PRIO),
2045 IOCTL_INFO_FNC(VIDIOC_QBUF, v4l_qbuf, v4l_print_buffer, INFO_FL_QUEUE),
2046 IOCTL_INFO_STD(VIDIOC_EXPBUF, vidioc_expbuf, v4l_print_exportbuffer, INFO_FL_QUEUE | INFO_FL_CLEAR(v4l2_exportbuffer, flags)),
2047 IOCTL_INFO_FNC(VIDIOC_DQBUF, v4l_dqbuf, v4l_print_buffer, INFO_FL_QUEUE),
2048 IOCTL_INFO_FNC(VIDIOC_STREAMON, v4l_streamon, v4l_print_buftype, INFO_FL_PRIO | INFO_FL_QUEUE),
2049 IOCTL_INFO_FNC(VIDIOC_STREAMOFF, v4l_streamoff, v4l_print_buftype, INFO_FL_PRIO | INFO_FL_QUEUE),
2050 IOCTL_INFO_FNC(VIDIOC_G_PARM, v4l_g_parm, v4l_print_streamparm, INFO_FL_CLEAR(v4l2_streamparm, type)),
2051 IOCTL_INFO_FNC(VIDIOC_S_PARM, v4l_s_parm, v4l_print_streamparm, INFO_FL_PRIO),
2052 IOCTL_INFO_STD(VIDIOC_G_STD, vidioc_g_std, v4l_print_std, 0),
2053 IOCTL_INFO_FNC(VIDIOC_S_STD, v4l_s_std, v4l_print_std, INFO_FL_PRIO),
2054 IOCTL_INFO_FNC(VIDIOC_ENUMSTD, v4l_enumstd, v4l_print_standard, INFO_FL_CLEAR(v4l2_standard, index)),
2055 IOCTL_INFO_FNC(VIDIOC_ENUMINPUT, v4l_enuminput, v4l_print_enuminput, INFO_FL_CLEAR(v4l2_input, index)),
2056 IOCTL_INFO_FNC(VIDIOC_G_CTRL, v4l_g_ctrl, v4l_print_control, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_control, id)),
2057 IOCTL_INFO_FNC(VIDIOC_S_CTRL, v4l_s_ctrl, v4l_print_control, INFO_FL_PRIO | INFO_FL_CTRL),
2058 IOCTL_INFO_FNC(VIDIOC_G_TUNER, v4l_g_tuner, v4l_print_tuner, INFO_FL_CLEAR(v4l2_tuner, index)),
2059 IOCTL_INFO_FNC(VIDIOC_S_TUNER, v4l_s_tuner, v4l_print_tuner, INFO_FL_PRIO),
2060 IOCTL_INFO_STD(VIDIOC_G_AUDIO, vidioc_g_audio, v4l_print_audio, 0),
2061 IOCTL_INFO_STD(VIDIOC_S_AUDIO, vidioc_s_audio, v4l_print_audio, INFO_FL_PRIO),
2062 IOCTL_INFO_FNC(VIDIOC_QUERYCTRL, v4l_queryctrl, v4l_print_queryctrl, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_queryctrl, id)),
2063 IOCTL_INFO_FNC(VIDIOC_QUERYMENU, v4l_querymenu, v4l_print_querymenu, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_querymenu, index)),
2064 IOCTL_INFO_STD(VIDIOC_G_INPUT, vidioc_g_input, v4l_print_u32, 0),
2065 IOCTL_INFO_FNC(VIDIOC_S_INPUT, v4l_s_input, v4l_print_u32, INFO_FL_PRIO),
2066 IOCTL_INFO_STD(VIDIOC_G_OUTPUT, vidioc_g_output, v4l_print_u32, 0),
2067 IOCTL_INFO_FNC(VIDIOC_S_OUTPUT, v4l_s_output, v4l_print_u32, INFO_FL_PRIO),
2068 IOCTL_INFO_FNC(VIDIOC_ENUMOUTPUT, v4l_enumoutput, v4l_print_enumoutput, INFO_FL_CLEAR(v4l2_output, index)),
2069 IOCTL_INFO_STD(VIDIOC_G_AUDOUT, vidioc_g_audout, v4l_print_audioout, 0),
2070 IOCTL_INFO_STD(VIDIOC_S_AUDOUT, vidioc_s_audout, v4l_print_audioout, INFO_FL_PRIO),
2071 IOCTL_INFO_FNC(VIDIOC_G_MODULATOR, v4l_g_modulator, v4l_print_modulator, INFO_FL_CLEAR(v4l2_modulator, index)),
2072 IOCTL_INFO_STD(VIDIOC_S_MODULATOR, vidioc_s_modulator, v4l_print_modulator, INFO_FL_PRIO),
2073 IOCTL_INFO_FNC(VIDIOC_G_FREQUENCY, v4l_g_frequency, v4l_print_frequency, INFO_FL_CLEAR(v4l2_frequency, tuner)),
2074 IOCTL_INFO_FNC(VIDIOC_S_FREQUENCY, v4l_s_frequency, v4l_print_frequency, INFO_FL_PRIO),
2075 IOCTL_INFO_FNC(VIDIOC_CROPCAP, v4l_cropcap, v4l_print_cropcap, INFO_FL_CLEAR(v4l2_cropcap, type)),
2076 IOCTL_INFO_FNC(VIDIOC_G_CROP, v4l_g_crop, v4l_print_crop, INFO_FL_CLEAR(v4l2_crop, type)),
2077 IOCTL_INFO_FNC(VIDIOC_S_CROP, v4l_s_crop, v4l_print_crop, INFO_FL_PRIO),
2078 IOCTL_INFO_STD(VIDIOC_G_SELECTION, vidioc_g_selection, v4l_print_selection, 0),
2079 IOCTL_INFO_STD(VIDIOC_S_SELECTION, vidioc_s_selection, v4l_print_selection, INFO_FL_PRIO),
2080 IOCTL_INFO_STD(VIDIOC_G_JPEGCOMP, vidioc_g_jpegcomp, v4l_print_jpegcompression, 0),
2081 IOCTL_INFO_STD(VIDIOC_S_JPEGCOMP, vidioc_s_jpegcomp, v4l_print_jpegcompression, INFO_FL_PRIO),
2082 IOCTL_INFO_FNC(VIDIOC_QUERYSTD, v4l_querystd, v4l_print_std, 0),
2083 IOCTL_INFO_FNC(VIDIOC_TRY_FMT, v4l_try_fmt, v4l_print_format, 0),
2084 IOCTL_INFO_STD(VIDIOC_ENUMAUDIO, vidioc_enumaudio, v4l_print_audio, INFO_FL_CLEAR(v4l2_audio, index)),
2085 IOCTL_INFO_STD(VIDIOC_ENUMAUDOUT, vidioc_enumaudout, v4l_print_audioout, INFO_FL_CLEAR(v4l2_audioout, index)),
2086 IOCTL_INFO_FNC(VIDIOC_G_PRIORITY, v4l_g_priority, v4l_print_u32, 0),
2087 IOCTL_INFO_FNC(VIDIOC_S_PRIORITY, v4l_s_priority, v4l_print_u32, INFO_FL_PRIO),
2088 IOCTL_INFO_FNC(VIDIOC_G_SLICED_VBI_CAP, v4l_g_sliced_vbi_cap, v4l_print_sliced_vbi_cap, INFO_FL_CLEAR(v4l2_sliced_vbi_cap, type)),
2089 IOCTL_INFO_FNC(VIDIOC_LOG_STATUS, v4l_log_status, v4l_print_newline, 0),
2090 IOCTL_INFO_FNC(VIDIOC_G_EXT_CTRLS, v4l_g_ext_ctrls, v4l_print_ext_controls, INFO_FL_CTRL),
2091 IOCTL_INFO_FNC(VIDIOC_S_EXT_CTRLS, v4l_s_ext_ctrls, v4l_print_ext_controls, INFO_FL_PRIO | INFO_FL_CTRL),
2092 IOCTL_INFO_FNC(VIDIOC_TRY_EXT_CTRLS, v4l_try_ext_ctrls, v4l_print_ext_controls, INFO_FL_CTRL),
2093 IOCTL_INFO_STD(VIDIOC_ENUM_FRAMESIZES, vidioc_enum_framesizes, v4l_print_frmsizeenum, INFO_FL_CLEAR(v4l2_frmsizeenum, pixel_format)),
2094 IOCTL_INFO_STD(VIDIOC_ENUM_FRAMEINTERVALS, vidioc_enum_frameintervals, v4l_print_frmivalenum, INFO_FL_CLEAR(v4l2_frmivalenum, height)),
2095 IOCTL_INFO_STD(VIDIOC_G_ENC_INDEX, vidioc_g_enc_index, v4l_print_enc_idx, 0),
2096 IOCTL_INFO_STD(VIDIOC_ENCODER_CMD, vidioc_encoder_cmd, v4l_print_encoder_cmd, INFO_FL_PRIO | INFO_FL_CLEAR(v4l2_encoder_cmd, flags)),
2097 IOCTL_INFO_STD(VIDIOC_TRY_ENCODER_CMD, vidioc_try_encoder_cmd, v4l_print_encoder_cmd, INFO_FL_CLEAR(v4l2_encoder_cmd, flags)),
2098 IOCTL_INFO_STD(VIDIOC_DECODER_CMD, vidioc_decoder_cmd, v4l_print_decoder_cmd, INFO_FL_PRIO),
2099 IOCTL_INFO_STD(VIDIOC_TRY_DECODER_CMD, vidioc_try_decoder_cmd, v4l_print_decoder_cmd, 0),
2100 IOCTL_INFO_FNC(VIDIOC_DBG_S_REGISTER, v4l_dbg_s_register, v4l_print_dbg_register, 0),
2101 IOCTL_INFO_FNC(VIDIOC_DBG_G_REGISTER, v4l_dbg_g_register, v4l_print_dbg_register, 0),
2102 IOCTL_INFO_FNC(VIDIOC_S_HW_FREQ_SEEK, v4l_s_hw_freq_seek, v4l_print_hw_freq_seek, INFO_FL_PRIO),
2103 IOCTL_INFO_STD(VIDIOC_S_DV_TIMINGS, vidioc_s_dv_timings, v4l_print_dv_timings, INFO_FL_PRIO),
2104 IOCTL_INFO_STD(VIDIOC_G_DV_TIMINGS, vidioc_g_dv_timings, v4l_print_dv_timings, 0),
2105 IOCTL_INFO_FNC(VIDIOC_DQEVENT, v4l_dqevent, v4l_print_event, 0),
2106 IOCTL_INFO_FNC(VIDIOC_SUBSCRIBE_EVENT, v4l_subscribe_event, v4l_print_event_subscription, 0),
2107 IOCTL_INFO_FNC(VIDIOC_UNSUBSCRIBE_EVENT, v4l_unsubscribe_event, v4l_print_event_subscription, 0),
2108 IOCTL_INFO_FNC(VIDIOC_CREATE_BUFS, v4l_create_bufs, v4l_print_create_buffers, INFO_FL_PRIO | INFO_FL_QUEUE),
2109 IOCTL_INFO_FNC(VIDIOC_PREPARE_BUF, v4l_prepare_buf, v4l_print_buffer, INFO_FL_QUEUE),
2110 IOCTL_INFO_STD(VIDIOC_ENUM_DV_TIMINGS, vidioc_enum_dv_timings, v4l_print_enum_dv_timings, 0),
2111 IOCTL_INFO_STD(VIDIOC_QUERY_DV_TIMINGS, vidioc_query_dv_timings, v4l_print_dv_timings, 0),
2112 IOCTL_INFO_STD(VIDIOC_DV_TIMINGS_CAP, vidioc_dv_timings_cap, v4l_print_dv_timings_cap, INFO_FL_CLEAR(v4l2_dv_timings_cap, type)),
2113 IOCTL_INFO_FNC(VIDIOC_ENUM_FREQ_BANDS, v4l_enum_freq_bands, v4l_print_freq_band, 0),
2114 IOCTL_INFO_FNC(VIDIOC_DBG_G_CHIP_INFO, v4l_dbg_g_chip_info, v4l_print_dbg_chip_info, INFO_FL_CLEAR(v4l2_dbg_chip_info, match)),
2116 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
2118 bool v4l2_is_known_ioctl(unsigned int cmd)
2120 if (_IOC_NR(cmd) >= V4L2_IOCTLS)
2122 return v4l2_ioctls[_IOC_NR(cmd)].ioctl == cmd;
2125 struct mutex *v4l2_ioctl_get_lock(struct video_device *vdev, unsigned cmd)
2127 if (_IOC_NR(cmd) >= V4L2_IOCTLS)
2129 if (test_bit(_IOC_NR(cmd), vdev->disable_locking))
2131 if (vdev->queue && vdev->queue->lock &&
2132 (v4l2_ioctls[_IOC_NR(cmd)].flags & INFO_FL_QUEUE))
2133 return vdev->queue->lock;
2137 /* Common ioctl debug function. This function can be used by
2138 external ioctl messages as well as internal V4L ioctl */
2139 void v4l_printk_ioctl(const char *prefix, unsigned int cmd)
2141 const char *dir, *type;
2144 printk(KERN_DEBUG "%s: ", prefix);
2146 switch (_IOC_TYPE(cmd)) {
2151 if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
2155 pr_cont("%s", v4l2_ioctls[_IOC_NR(cmd)].name);
2162 switch (_IOC_DIR(cmd)) {
2163 case _IOC_NONE: dir = "--"; break;
2164 case _IOC_READ: dir = "r-"; break;
2165 case _IOC_WRITE: dir = "-w"; break;
2166 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
2167 default: dir = "*ERR*"; break;
2169 pr_cont("%s ioctl '%c', dir=%s, #%d (0x%08x)",
2170 type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
2172 EXPORT_SYMBOL(v4l_printk_ioctl);
2174 static long __video_do_ioctl(struct file *file,
2175 unsigned int cmd, void *arg)
2177 struct video_device *vfd = video_devdata(file);
2178 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
2179 bool write_only = false;
2180 struct v4l2_ioctl_info default_info;
2181 const struct v4l2_ioctl_info *info;
2182 void *fh = file->private_data;
2183 struct v4l2_fh *vfh = NULL;
2184 int use_fh_prio = 0;
2185 int debug = vfd->debug;
2189 pr_warn("%s: has no ioctl_ops.\n",
2190 video_device_node_name(vfd));
2194 if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) {
2195 vfh = file->private_data;
2196 use_fh_prio = test_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
2199 if (v4l2_is_known_ioctl(cmd)) {
2200 info = &v4l2_ioctls[_IOC_NR(cmd)];
2202 if (!test_bit(_IOC_NR(cmd), vfd->valid_ioctls) &&
2203 !((info->flags & INFO_FL_CTRL) && vfh && vfh->ctrl_handler))
2206 if (use_fh_prio && (info->flags & INFO_FL_PRIO)) {
2207 ret = v4l2_prio_check(vfd->prio, vfh->prio);
2212 default_info.ioctl = cmd;
2213 default_info.flags = 0;
2214 default_info.debug = v4l_print_default;
2215 info = &default_info;
2218 write_only = _IOC_DIR(cmd) == _IOC_WRITE;
2219 if (info->flags & INFO_FL_STD) {
2220 typedef int (*vidioc_op)(struct file *file, void *fh, void *p);
2221 const void *p = vfd->ioctl_ops;
2222 const vidioc_op *vidioc = p + info->u.offset;
2224 ret = (*vidioc)(file, fh, arg);
2225 } else if (info->flags & INFO_FL_FUNC) {
2226 ret = info->u.func(ops, file, fh, arg);
2227 } else if (!ops->vidioc_default) {
2230 ret = ops->vidioc_default(file, fh,
2231 use_fh_prio ? v4l2_prio_check(vfd->prio, vfh->prio) >= 0 : 0,
2237 v4l_printk_ioctl(video_device_node_name(vfd), cmd);
2239 pr_cont(": error %ld", ret);
2240 if (debug == V4L2_DEBUG_IOCTL)
2242 else if (_IOC_DIR(cmd) == _IOC_NONE)
2243 info->debug(arg, write_only);
2246 info->debug(arg, write_only);
2253 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
2254 void * __user *user_ptr, void ***kernel_ptr)
2259 case VIDIOC_PREPARE_BUF:
2260 case VIDIOC_QUERYBUF:
2262 case VIDIOC_DQBUF: {
2263 struct v4l2_buffer *buf = parg;
2265 if (V4L2_TYPE_IS_MULTIPLANAR(buf->type) && buf->length > 0) {
2266 if (buf->length > VIDEO_MAX_PLANES) {
2270 *user_ptr = (void __user *)buf->m.planes;
2271 *kernel_ptr = (void *)&buf->m.planes;
2272 *array_size = sizeof(struct v4l2_plane) * buf->length;
2278 case VIDIOC_SUBDEV_G_EDID:
2279 case VIDIOC_SUBDEV_S_EDID: {
2280 struct v4l2_subdev_edid *edid = parg;
2283 if (edid->blocks > 256) {
2287 *user_ptr = (void __user *)edid->edid;
2288 *kernel_ptr = (void *)&edid->edid;
2289 *array_size = edid->blocks * 128;
2295 case VIDIOC_S_EXT_CTRLS:
2296 case VIDIOC_G_EXT_CTRLS:
2297 case VIDIOC_TRY_EXT_CTRLS: {
2298 struct v4l2_ext_controls *ctrls = parg;
2300 if (ctrls->count != 0) {
2301 if (ctrls->count > V4L2_CID_MAX_CTRLS) {
2305 *user_ptr = (void __user *)ctrls->controls;
2306 *kernel_ptr = (void *)&ctrls->controls;
2307 *array_size = sizeof(struct v4l2_ext_control)
2319 video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
2324 void *parg = (void *)arg;
2326 bool has_array_args;
2327 size_t array_size = 0;
2328 void __user *user_ptr = NULL;
2329 void **kernel_ptr = NULL;
2331 /* Copy arguments into temp kernel buffer */
2332 if (_IOC_DIR(cmd) != _IOC_NONE) {
2333 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
2336 /* too big to allocate from stack */
2337 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
2344 if (_IOC_DIR(cmd) & _IOC_WRITE) {
2345 unsigned int n = _IOC_SIZE(cmd);
2348 * In some cases, only a few fields are used as input,
2349 * i.e. when the app sets "index" and then the driver
2350 * fills in the rest of the structure for the thing
2351 * with that index. We only need to copy up the first
2354 if (v4l2_is_known_ioctl(cmd)) {
2355 u32 flags = v4l2_ioctls[_IOC_NR(cmd)].flags;
2356 if (flags & INFO_FL_CLEAR_MASK)
2357 n = (flags & INFO_FL_CLEAR_MASK) >> 16;
2360 if (copy_from_user(parg, (void __user *)arg, n))
2363 /* zero out anything we don't copy from userspace */
2364 if (n < _IOC_SIZE(cmd))
2365 memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n);
2367 /* read-only ioctl */
2368 memset(parg, 0, _IOC_SIZE(cmd));
2372 err = check_array_args(cmd, parg, &array_size, &user_ptr, &kernel_ptr);
2375 has_array_args = err;
2377 if (has_array_args) {
2379 * When adding new types of array args, make sure that the
2380 * parent argument to ioctl (which contains the pointer to the
2381 * array) fits into sbuf (so that mbuf will still remain
2382 * unused up to here).
2384 mbuf = kmalloc(array_size, GFP_KERNEL);
2387 goto out_array_args;
2389 if (copy_from_user(mbuf, user_ptr, array_size))
2390 goto out_array_args;
2395 err = func(file, cmd, parg);
2396 if (err == -ENOIOCTLCMD)
2399 if (cmd == VIDIOC_DQBUF)
2400 trace_v4l2_dqbuf(video_devdata(file)->minor, parg);
2401 else if (cmd == VIDIOC_QBUF)
2402 trace_v4l2_qbuf(video_devdata(file)->minor, parg);
2405 if (has_array_args) {
2406 *kernel_ptr = user_ptr;
2407 if (copy_to_user(user_ptr, mbuf, array_size))
2409 goto out_array_args;
2411 /* VIDIOC_QUERY_DV_TIMINGS can return an error, but still have valid
2412 results that must be returned. */
2413 if (err < 0 && cmd != VIDIOC_QUERY_DV_TIMINGS)
2417 /* Copy results into user buffer */
2418 switch (_IOC_DIR(cmd)) {
2420 case (_IOC_WRITE | _IOC_READ):
2421 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
2430 EXPORT_SYMBOL(video_usercopy);
2432 long video_ioctl2(struct file *file,
2433 unsigned int cmd, unsigned long arg)
2435 return video_usercopy(file, cmd, arg, __video_do_ioctl);
2437 EXPORT_SYMBOL(video_ioctl2);