blob: 179b22c80b4da7a825fc2568eb6e7d303d24c051 [file] [log] [blame]
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001/*
2 * Video capture interface for Linux version 2
3 *
4 * A generic framework to process V4L2 ioctl commands.
5 *
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.
10 *
Alan Coxd9b01442008-10-27 15:13:47 -030011 * Authors: Alan Cox, <alan@lxorguk.ukuu.org.uk> (version 1)
Hans Verkuil35ea11f2008-07-20 08:12:02 -030012 * Mauro Carvalho Chehab <mchehab@infradead.org> (version 2)
13 */
14
15#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090016#include <linux/slab.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030017#include <linux/types.h>
18#include <linux/kernel.h>
Mauro Carvalho Chehabae6db512011-06-24 13:14:14 -030019#include <linux/version.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030020
Hans Verkuil35ea11f2008-07-20 08:12:02 -030021#include <linux/videodev2.h>
22
Hans Verkuil35ea11f2008-07-20 08:12:02 -030023#include <media/v4l2-common.h>
24#include <media/v4l2-ioctl.h>
Hans Verkuil11bbc1c2010-05-16 09:24:06 -030025#include <media/v4l2-ctrls.h>
Sakari Ailusd3d7c962010-03-27 11:02:10 -030026#include <media/v4l2-fh.h>
27#include <media/v4l2-event.h>
Hans Verkuil99cd47bc2011-03-11 19:00:56 -030028#include <media/v4l2-device.h>
Hans Verkuil80b36e02009-02-07 11:00:02 -030029#include <media/v4l2-chip-ident.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030030
31#define dbgarg(cmd, fmt, arg...) \
32 do { \
33 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \
34 printk(KERN_DEBUG "%s: ", vfd->name); \
35 v4l_printk_ioctl(cmd); \
36 printk(" " fmt, ## arg); \
37 } \
38 } while (0)
39
40#define dbgarg2(fmt, arg...) \
41 do { \
42 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
43 printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\
44 } while (0)
45
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -030046#define dbgarg3(fmt, arg...) \
47 do { \
48 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
49 printk(KERN_CONT "%s: " fmt, vfd->name, ## arg);\
50 } while (0)
51
Lucas De Marchi25985ed2011-03-30 22:57:33 -030052/* Zero out the end of the struct pointed to by p. Everything after, but
Trent Piepho7ecc0cf2009-04-30 21:03:34 -030053 * 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))
57
Hans Verkuil35ea11f2008-07-20 08:12:02 -030058struct std_descr {
59 v4l2_std_id std;
60 const char *descr;
61};
62
63static 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" },
94 { 0, "Unknown" }
95};
96
97/* video4linux standard ID conversion to standard name
98 */
99const char *v4l2_norm_to_name(v4l2_std_id id)
100{
101 u32 myid = id;
102 int i;
103
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.
107 */
108 BUG_ON(myid != id);
109
110 for (i = 0; standards[i].std; i++)
111 if (myid == standards[i].std)
112 break;
113 return standards[i].descr;
114}
115EXPORT_SYMBOL(v4l2_norm_to_name);
116
Trent Piepho51f0b8d52009-03-04 01:21:02 -0300117/* Returns frame period for the given standard */
118void v4l2_video_std_frame_period(int id, struct v4l2_fract *frameperiod)
119{
120 if (id & V4L2_STD_525_60) {
121 frameperiod->numerator = 1001;
122 frameperiod->denominator = 30000;
123 } else {
124 frameperiod->numerator = 1;
125 frameperiod->denominator = 25;
126 }
127}
128EXPORT_SYMBOL(v4l2_video_std_frame_period);
129
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300130/* Fill in the fields of a v4l2_standard structure according to the
131 'id' and 'transmission' parameters. Returns negative on error. */
132int v4l2_video_std_construct(struct v4l2_standard *vs,
133 int id, const char *name)
134{
Trent Piepho51f0b8d52009-03-04 01:21:02 -0300135 vs->id = id;
136 v4l2_video_std_frame_period(id, &vs->frameperiod);
137 vs->framelines = (id & V4L2_STD_525_60) ? 525 : 625;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300138 strlcpy(vs->name, name, sizeof(vs->name));
139 return 0;
140}
141EXPORT_SYMBOL(v4l2_video_std_construct);
142
143/* ----------------------------------------------------------------- */
144/* some arrays for pretty-printing debug messages of enum types */
145
146const 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",
157};
158EXPORT_SYMBOL(v4l2_field_names);
159
160const 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",
Pawel Osciakf8f39142010-07-29 14:44:25 -0300169 [V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE] = "vid-cap-mplane",
170 [V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE] = "vid-out-mplane",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300171};
172EXPORT_SYMBOL(v4l2_type_names);
173
174static const char *v4l2_memory_names[] = {
175 [V4L2_MEMORY_MMAP] = "mmap",
176 [V4L2_MEMORY_USERPTR] = "userptr",
177 [V4L2_MEMORY_OVERLAY] = "overlay",
178};
179
180#define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
181 arr[a] : "unknown")
182
183/* ------------------------------------------------------------------ */
184/* debug help functions */
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300185
Hans Verkuil59076122012-06-22 06:09:54 -0300186static void v4l_print_querycap(const void *arg, bool write_only)
187{
188 const struct v4l2_capability *p = arg;
189
190 pr_cont("driver=%s, card=%s, bus=%s, version=0x%08x, "
191 "capabilities=0x%08x, device_caps=0x%08x\n",
192 p->driver, p->card, p->bus_info,
193 p->version, p->capabilities, p->device_caps);
194}
195
196static void v4l_print_enuminput(const void *arg, bool write_only)
197{
198 const struct v4l2_input *p = arg;
199
200 pr_cont("index=%u, name=%s, type=%u, audioset=0x%x, tuner=%u, "
201 "std=0x%08Lx, status=0x%x, capabilities=0x%x\n",
202 p->index, p->name, p->type, p->audioset, p->tuner,
203 (unsigned long long)p->std, p->status, p->capabilities);
204}
205
206static void v4l_print_enumoutput(const void *arg, bool write_only)
207{
208 const struct v4l2_output *p = arg;
209
210 pr_cont("index=%u, name=%s, type=%u, audioset=0x%x, "
211 "modulator=%u, std=0x%08Lx, capabilities=0x%x\n",
212 p->index, p->name, p->type, p->audioset, p->modulator,
213 (unsigned long long)p->std, p->capabilities);
214}
215
216static void v4l_print_audio(const void *arg, bool write_only)
217{
218 const struct v4l2_audio *p = arg;
219
220 if (write_only)
221 pr_cont("index=%u, mode=0x%x\n", p->index, p->mode);
222 else
223 pr_cont("index=%u, name=%s, capability=0x%x, mode=0x%x\n",
224 p->index, p->name, p->capability, p->mode);
225}
226
227static void v4l_print_audioout(const void *arg, bool write_only)
228{
229 const struct v4l2_audioout *p = arg;
230
231 if (write_only)
232 pr_cont("index=%u\n", p->index);
233 else
234 pr_cont("index=%u, name=%s, capability=0x%x, mode=0x%x\n",
235 p->index, p->name, p->capability, p->mode);
236}
237
Hans Verkuilbe6c64e2012-06-22 06:12:57 -0300238static void v4l_print_fmtdesc(const void *arg, bool write_only)
239{
240 const struct v4l2_fmtdesc *p = arg;
241
242 pr_cont("index=%u, type=%s, flags=0x%x, pixelformat=%c%c%c%c, description='%s'\n",
243 p->index, prt_names(p->type, v4l2_type_names),
244 p->flags, (p->pixelformat & 0xff),
245 (p->pixelformat >> 8) & 0xff,
246 (p->pixelformat >> 16) & 0xff,
247 (p->pixelformat >> 24) & 0xff,
248 p->description);
249}
250
251static void v4l_print_format(const void *arg, bool write_only)
252{
253 const struct v4l2_format *p = arg;
254 const struct v4l2_pix_format *pix;
255 const struct v4l2_pix_format_mplane *mp;
256 const struct v4l2_vbi_format *vbi;
257 const struct v4l2_sliced_vbi_format *sliced;
258 const struct v4l2_window *win;
259 const struct v4l2_clip *clip;
260 unsigned i;
261
262 pr_cont("type=%s", prt_names(p->type, v4l2_type_names));
263 switch (p->type) {
264 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
265 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
266 pix = &p->fmt.pix;
267 pr_cont(", width=%u, height=%u, "
268 "pixelformat=%c%c%c%c, field=%s, "
269 "bytesperline=%u sizeimage=%u, colorspace=%d\n",
270 pix->width, pix->height,
271 (pix->pixelformat & 0xff),
272 (pix->pixelformat >> 8) & 0xff,
273 (pix->pixelformat >> 16) & 0xff,
274 (pix->pixelformat >> 24) & 0xff,
275 prt_names(pix->field, v4l2_field_names),
276 pix->bytesperline, pix->sizeimage,
277 pix->colorspace);
278 break;
279 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
280 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
281 mp = &p->fmt.pix_mp;
282 pr_cont(", width=%u, height=%u, "
283 "format=%c%c%c%c, field=%s, "
284 "colorspace=%d, num_planes=%u\n",
285 mp->width, mp->height,
286 (mp->pixelformat & 0xff),
287 (mp->pixelformat >> 8) & 0xff,
288 (mp->pixelformat >> 16) & 0xff,
289 (mp->pixelformat >> 24) & 0xff,
290 prt_names(mp->field, v4l2_field_names),
291 mp->colorspace, mp->num_planes);
292 for (i = 0; i < mp->num_planes; i++)
293 printk(KERN_DEBUG "plane %u: bytesperline=%u sizeimage=%u\n", i,
294 mp->plane_fmt[i].bytesperline,
295 mp->plane_fmt[i].sizeimage);
296 break;
297 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
298 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
299 win = &p->fmt.win;
300 pr_cont(", wxh=%dx%d, x,y=%d,%d, field=%s, "
301 "chromakey=0x%08x, bitmap=%p, "
302 "global_alpha=0x%02x\n",
303 win->w.width, win->w.height,
304 win->w.left, win->w.top,
305 prt_names(win->field, v4l2_field_names),
306 win->chromakey, win->bitmap, win->global_alpha);
307 clip = win->clips;
308 for (i = 0; i < win->clipcount; i++) {
309 printk(KERN_DEBUG "clip %u: wxh=%dx%d, x,y=%d,%d\n",
310 i, clip->c.width, clip->c.height,
311 clip->c.left, clip->c.top);
312 clip = clip->next;
313 }
314 break;
315 case V4L2_BUF_TYPE_VBI_CAPTURE:
316 case V4L2_BUF_TYPE_VBI_OUTPUT:
317 vbi = &p->fmt.vbi;
318 pr_cont(", sampling_rate=%u, offset=%u, samples_per_line=%u, "
319 "sample_format=%c%c%c%c, start=%u,%u, count=%u,%u\n",
320 vbi->sampling_rate, vbi->offset,
321 vbi->samples_per_line,
322 (vbi->sample_format & 0xff),
323 (vbi->sample_format >> 8) & 0xff,
324 (vbi->sample_format >> 16) & 0xff,
325 (vbi->sample_format >> 24) & 0xff,
326 vbi->start[0], vbi->start[1],
327 vbi->count[0], vbi->count[1]);
328 break;
329 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
330 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
331 sliced = &p->fmt.sliced;
332 pr_cont(", service_set=0x%08x, io_size=%d\n",
333 sliced->service_set, sliced->io_size);
334 for (i = 0; i < 24; i++)
335 printk(KERN_DEBUG "line[%02u]=0x%04x, 0x%04x\n", i,
336 sliced->service_lines[0][i],
337 sliced->service_lines[1][i]);
338 break;
339 case V4L2_BUF_TYPE_PRIVATE:
340 pr_cont("\n");
341 break;
342 }
343}
344
345static void v4l_print_framebuffer(const void *arg, bool write_only)
346{
347 const struct v4l2_framebuffer *p = arg;
348
349 pr_cont("capability=0x%x, flags=0x%x, base=0x%p, width=%u, "
350 "height=%u, pixelformat=%c%c%c%c, "
351 "bytesperline=%u sizeimage=%u, colorspace=%d\n",
352 p->capability, p->flags, p->base,
353 p->fmt.width, p->fmt.height,
354 (p->fmt.pixelformat & 0xff),
355 (p->fmt.pixelformat >> 8) & 0xff,
356 (p->fmt.pixelformat >> 16) & 0xff,
357 (p->fmt.pixelformat >> 24) & 0xff,
358 p->fmt.bytesperline, p->fmt.sizeimage,
359 p->fmt.colorspace);
360}
361
Hans Verkuile325b242012-06-09 12:50:15 -0300362static void v4l_print_buftype(const void *arg, bool write_only)
363{
364 pr_cont("type=%s\n", prt_names(*(u32 *)arg, v4l2_type_names));
365}
366
Hans Verkuil4b1e2e42012-06-22 06:17:48 -0300367static void v4l_print_modulator(const void *arg, bool write_only)
368{
369 const struct v4l2_modulator *p = arg;
370
371 if (write_only)
372 pr_cont("index=%u, txsubchans=0x%x", p->index, p->txsubchans);
373 else
374 pr_cont("index=%u, name=%s, capability=0x%x, "
375 "rangelow=%u, rangehigh=%u, txsubchans=0x%x\n",
376 p->index, p->name, p->capability,
377 p->rangelow, p->rangehigh, p->txsubchans);
378}
379
380static void v4l_print_tuner(const void *arg, bool write_only)
381{
382 const struct v4l2_tuner *p = arg;
383
384 if (write_only)
385 pr_cont("index=%u, audmode=%u\n", p->index, p->audmode);
386 else
387 pr_cont("index=%u, name=%s, type=%u, capability=0x%x, "
388 "rangelow=%u, rangehigh=%u, signal=%u, afc=%d, "
389 "rxsubchans=0x%x, audmode=%u\n",
390 p->index, p->name, p->type,
391 p->capability, p->rangelow,
392 p->rangehigh, p->signal, p->afc,
393 p->rxsubchans, p->audmode);
394}
395
396static void v4l_print_frequency(const void *arg, bool write_only)
397{
398 const struct v4l2_frequency *p = arg;
399
400 pr_cont("tuner=%u, type=%u, frequency=%u\n",
401 p->tuner, p->type, p->frequency);
402}
403
404static void v4l_print_standard(const void *arg, bool write_only)
405{
406 const struct v4l2_standard *p = arg;
407
408 pr_cont("index=%u, id=0x%Lx, name=%s, fps=%u/%u, "
409 "framelines=%u\n", p->index,
410 (unsigned long long)p->id, p->name,
411 p->frameperiod.numerator,
412 p->frameperiod.denominator,
413 p->framelines);
414}
415
416static void v4l_print_std(const void *arg, bool write_only)
417{
418 pr_cont("std=0x%08Lx\n", *(const long long unsigned *)arg);
419}
420
421static void v4l_print_hw_freq_seek(const void *arg, bool write_only)
422{
423 const struct v4l2_hw_freq_seek *p = arg;
424
425 pr_cont("tuner=%u, type=%u, seek_upward=%u, wrap_around=%u, spacing=%u\n",
426 p->tuner, p->type, p->seek_upward, p->wrap_around, p->spacing);
427}
428
Hans Verkuileb3728e2012-06-22 06:23:59 -0300429static void v4l_print_requestbuffers(const void *arg, bool write_only)
Hans Verkuil59076122012-06-22 06:09:54 -0300430{
Hans Verkuileb3728e2012-06-22 06:23:59 -0300431 const struct v4l2_requestbuffers *p = arg;
432
433 pr_cont("count=%d, type=%s, memory=%s\n",
434 p->count,
435 prt_names(p->type, v4l2_type_names),
436 prt_names(p->memory, v4l2_memory_names));
Hans Verkuil59076122012-06-22 06:09:54 -0300437}
438
Hans Verkuileb3728e2012-06-22 06:23:59 -0300439static void v4l_print_buffer(const void *arg, bool write_only)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300440{
Hans Verkuileb3728e2012-06-22 06:23:59 -0300441 const struct v4l2_buffer *p = arg;
442 const struct v4l2_timecode *tc = &p->timecode;
443 const struct v4l2_plane *plane;
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300444 int i;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300445
Hans Verkuileb3728e2012-06-22 06:23:59 -0300446 pr_cont("%02ld:%02d:%02d.%08ld index=%d, type=%s, "
447 "flags=0x%08x, field=%s, sequence=%d, memory=%s",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300448 p->timestamp.tv_sec / 3600,
449 (int)(p->timestamp.tv_sec / 60) % 60,
450 (int)(p->timestamp.tv_sec % 60),
Alexander Beregalovb0459792008-09-03 16:47:38 -0300451 (long)p->timestamp.tv_usec,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300452 p->index,
453 prt_names(p->type, v4l2_type_names),
Hans Verkuileb3728e2012-06-22 06:23:59 -0300454 p->flags, prt_names(p->field, v4l2_field_names),
455 p->sequence, prt_names(p->memory, v4l2_memory_names));
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300456
457 if (V4L2_TYPE_IS_MULTIPLANAR(p->type) && p->m.planes) {
Hans Verkuileb3728e2012-06-22 06:23:59 -0300458 pr_cont("\n");
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300459 for (i = 0; i < p->length; ++i) {
460 plane = &p->m.planes[i];
Hans Verkuileb3728e2012-06-22 06:23:59 -0300461 printk(KERN_DEBUG
462 "plane %d: bytesused=%d, data_offset=0x%08x "
463 "offset/userptr=0x%lx, length=%d\n",
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300464 i, plane->bytesused, plane->data_offset,
465 plane->m.userptr, plane->length);
466 }
467 } else {
Hans Verkuileb3728e2012-06-22 06:23:59 -0300468 pr_cont("bytesused=%d, offset/userptr=0x%lx, length=%d\n",
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300469 p->bytesused, p->m.userptr, p->length);
470 }
471
Hans Verkuileb3728e2012-06-22 06:23:59 -0300472 printk(KERN_DEBUG "timecode=%02d:%02d:%02d type=%d, "
473 "flags=0x%08x, frames=%d, userbits=0x%08x\n",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300474 tc->hours, tc->minutes, tc->seconds,
475 tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits);
476}
477
Hans Verkuileb3728e2012-06-22 06:23:59 -0300478static void v4l_print_create_buffers(const void *arg, bool write_only)
479{
480 const struct v4l2_create_buffers *p = arg;
481
482 pr_cont("index=%d, count=%d, memory=%s, ",
483 p->index, p->count,
484 prt_names(p->memory, v4l2_memory_names));
485 v4l_print_format(&p->format, write_only);
486}
487
488static void v4l_print_streamparm(const void *arg, bool write_only)
489{
490 const struct v4l2_streamparm *p = arg;
491
492 pr_cont("type=%s", prt_names(p->type, v4l2_type_names));
493
494 if (p->type == V4L2_BUF_TYPE_VIDEO_CAPTURE ||
495 p->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
496 const struct v4l2_captureparm *c = &p->parm.capture;
497
498 pr_cont(", capability=0x%x, capturemode=0x%x, timeperframe=%d/%d, "
499 "extendedmode=%d, readbuffers=%d\n",
500 c->capability, c->capturemode,
501 c->timeperframe.numerator, c->timeperframe.denominator,
502 c->extendedmode, c->readbuffers);
503 } else if (p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT ||
504 p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
505 const struct v4l2_outputparm *c = &p->parm.output;
506
507 pr_cont(", capability=0x%x, outputmode=0x%x, timeperframe=%d/%d, "
508 "extendedmode=%d, writebuffers=%d\n",
509 c->capability, c->outputmode,
510 c->timeperframe.numerator, c->timeperframe.denominator,
511 c->extendedmode, c->writebuffers);
512 }
513}
514
Hans Verkuilefbceec2012-06-09 12:54:02 -0300515static void v4l_print_queryctrl(const void *arg, bool write_only)
516{
517 const struct v4l2_queryctrl *p = arg;
518
519 pr_cont("id=0x%x, type=%d, name=%s, min/max=%d/%d, "
520 "step=%d, default=%d, flags=0x%08x\n",
521 p->id, p->type, p->name,
522 p->minimum, p->maximum,
523 p->step, p->default_value, p->flags);
524}
525
526static void v4l_print_querymenu(const void *arg, bool write_only)
527{
528 const struct v4l2_querymenu *p = arg;
529
530 pr_cont("id=0x%x, index=%d\n", p->id, p->index);
531}
532
533static void v4l_print_control(const void *arg, bool write_only)
534{
535 const struct v4l2_control *p = arg;
536
537 pr_cont("id=0x%x, value=%d\n", p->id, p->value);
538}
539
540static void v4l_print_ext_controls(const void *arg, bool write_only)
541{
542 const struct v4l2_ext_controls *p = arg;
543 int i;
544
545 pr_cont("class=0x%x, count=%d, error_idx=%d",
546 p->ctrl_class, p->count, p->error_idx);
547 for (i = 0; i < p->count; i++) {
548 if (p->controls[i].size)
549 pr_cont(", id/val=0x%x/0x%x",
550 p->controls[i].id, p->controls[i].value);
551 else
552 pr_cont(", id/size=0x%x/%u",
553 p->controls[i].id, p->controls[i].size);
554 }
555 pr_cont("\n");
556}
557
Hans Verkuild84f2d942012-06-09 11:57:46 -0300558static void v4l_print_cropcap(const void *arg, bool write_only)
559{
560 const struct v4l2_cropcap *p = arg;
561
562 pr_cont("type=%s, bounds wxh=%dx%d, x,y=%d,%d, "
563 "defrect wxh=%dx%d, x,y=%d,%d\n, "
564 "pixelaspect %d/%d\n",
565 prt_names(p->type, v4l2_type_names),
566 p->bounds.width, p->bounds.height,
567 p->bounds.left, p->bounds.top,
568 p->defrect.width, p->defrect.height,
569 p->defrect.left, p->defrect.top,
570 p->pixelaspect.numerator, p->pixelaspect.denominator);
571}
572
573static void v4l_print_crop(const void *arg, bool write_only)
574{
575 const struct v4l2_crop *p = arg;
576
577 pr_cont("type=%s, wxh=%dx%d, x,y=%d,%d\n",
578 prt_names(p->type, v4l2_type_names),
579 p->c.width, p->c.height,
580 p->c.left, p->c.top);
581}
582
583static void v4l_print_selection(const void *arg, bool write_only)
584{
585 const struct v4l2_selection *p = arg;
586
587 pr_cont("type=%s, target=%d, flags=0x%x, wxh=%dx%d, x,y=%d,%d\n",
588 prt_names(p->type, v4l2_type_names),
589 p->target, p->flags,
590 p->r.width, p->r.height, p->r.left, p->r.top);
591}
592
Hans Verkuileb3728e2012-06-22 06:23:59 -0300593static void v4l_print_u32(const void *arg, bool write_only)
594{
595 pr_cont("value=%u\n", *(const u32 *)arg);
596}
597
Hans Verkuil5d7758e2012-05-15 08:06:44 -0300598static void dbgtimings(struct video_device *vfd,
599 const struct v4l2_dv_timings *p)
600{
601 switch (p->type) {
602 case V4L2_DV_BT_656_1120:
603 dbgarg2("bt-656/1120:interlaced=%d,"
604 " pixelclock=%lld,"
605 " width=%d, height=%d, polarities=%x,"
606 " hfrontporch=%d, hsync=%d,"
607 " hbackporch=%d, vfrontporch=%d,"
608 " vsync=%d, vbackporch=%d,"
609 " il_vfrontporch=%d, il_vsync=%d,"
610 " il_vbackporch=%d, standards=%x, flags=%x\n",
611 p->bt.interlaced, p->bt.pixelclock,
612 p->bt.width, p->bt.height,
613 p->bt.polarities, p->bt.hfrontporch,
614 p->bt.hsync, p->bt.hbackporch,
615 p->bt.vfrontporch, p->bt.vsync,
616 p->bt.vbackporch, p->bt.il_vfrontporch,
617 p->bt.il_vsync, p->bt.il_vbackporch,
618 p->bt.standards, p->bt.flags);
619 break;
620 default:
621 dbgarg2("Unknown type %d!\n", p->type);
622 break;
623 }
624}
625
Hans Verkuilefbceec2012-06-09 12:54:02 -0300626static int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300627{
628 __u32 i;
629
630 /* zero the reserved fields */
631 c->reserved[0] = c->reserved[1] = 0;
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300632 for (i = 0; i < c->count; i++)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300633 c->controls[i].reserved2[0] = 0;
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300634
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300635 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
636 when using extended controls.
637 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
638 is it allowed for backwards compatibility.
639 */
640 if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE)
641 return 0;
642 /* Check that all controls are from the same control class. */
643 for (i = 0; i < c->count; i++) {
644 if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) {
645 c->error_idx = i;
646 return 0;
647 }
648 }
649 return 1;
650}
651
Hans Verkuila3998102008-07-21 02:57:38 -0300652static int check_fmt(const struct v4l2_ioctl_ops *ops, enum v4l2_buf_type type)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300653{
Hans Verkuila3998102008-07-21 02:57:38 -0300654 if (ops == NULL)
655 return -EINVAL;
656
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300657 switch (type) {
658 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300659 if (ops->vidioc_g_fmt_vid_cap ||
660 ops->vidioc_g_fmt_vid_cap_mplane)
661 return 0;
662 break;
663 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
664 if (ops->vidioc_g_fmt_vid_cap_mplane)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300665 return 0;
666 break;
667 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho1175d612009-04-30 21:03:34 -0300668 if (ops->vidioc_g_fmt_vid_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300669 return 0;
670 break;
671 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Pawel Osciakd14e6d72010-12-23 04:15:27 -0300672 if (ops->vidioc_g_fmt_vid_out ||
673 ops->vidioc_g_fmt_vid_out_mplane)
674 return 0;
675 break;
676 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
677 if (ops->vidioc_g_fmt_vid_out_mplane)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300678 return 0;
679 break;
680 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho1175d612009-04-30 21:03:34 -0300681 if (ops->vidioc_g_fmt_vid_out_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300682 return 0;
683 break;
684 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho1175d612009-04-30 21:03:34 -0300685 if (ops->vidioc_g_fmt_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300686 return 0;
687 break;
688 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho1175d612009-04-30 21:03:34 -0300689 if (ops->vidioc_g_fmt_vbi_out)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300690 return 0;
691 break;
692 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho1175d612009-04-30 21:03:34 -0300693 if (ops->vidioc_g_fmt_sliced_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300694 return 0;
695 break;
696 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho1175d612009-04-30 21:03:34 -0300697 if (ops->vidioc_g_fmt_sliced_vbi_out)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300698 return 0;
699 break;
700 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho1175d612009-04-30 21:03:34 -0300701 if (ops->vidioc_g_fmt_type_private)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300702 return 0;
703 break;
704 }
705 return -EINVAL;
706}
707
Hans Verkuil59076122012-06-22 06:09:54 -0300708static int v4l_querycap(const struct v4l2_ioctl_ops *ops,
709 struct file *file, void *fh, void *arg)
710{
711 struct v4l2_capability *cap = (struct v4l2_capability *)arg;
712
713 cap->version = LINUX_VERSION_CODE;
714 return ops->vidioc_querycap(file, fh, cap);
715}
716
717static int v4l_s_input(const struct v4l2_ioctl_ops *ops,
718 struct file *file, void *fh, void *arg)
719{
720 return ops->vidioc_s_input(file, fh, *(unsigned int *)arg);
721}
722
723static int v4l_s_output(const struct v4l2_ioctl_ops *ops,
724 struct file *file, void *fh, void *arg)
725{
726 return ops->vidioc_s_output(file, fh, *(unsigned int *)arg);
727}
728
Hans Verkuild0547cb2012-06-09 09:27:10 -0300729static int v4l_g_priority(const struct v4l2_ioctl_ops *ops,
730 struct file *file, void *fh, void *arg)
731{
732 struct video_device *vfd;
733 u32 *p = arg;
734
735 if (ops->vidioc_g_priority)
736 return ops->vidioc_g_priority(file, fh, arg);
737 vfd = video_devdata(file);
738 *p = v4l2_prio_max(&vfd->v4l2_dev->prio);
739 return 0;
740}
741
742static int v4l_s_priority(const struct v4l2_ioctl_ops *ops,
743 struct file *file, void *fh, void *arg)
744{
745 struct video_device *vfd;
746 struct v4l2_fh *vfh;
747 u32 *p = arg;
748
749 if (ops->vidioc_s_priority)
750 return ops->vidioc_s_priority(file, fh, *p);
751 vfd = video_devdata(file);
752 vfh = file->private_data;
753 return v4l2_prio_change(&vfd->v4l2_dev->prio, &vfh->prio, *p);
754}
755
Hans Verkuil59076122012-06-22 06:09:54 -0300756static int v4l_enuminput(const struct v4l2_ioctl_ops *ops,
757 struct file *file, void *fh, void *arg)
758{
759 struct v4l2_input *p = arg;
760
761 /*
762 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
763 * CAP_STD here based on ioctl handler provided by the
764 * driver. If the driver doesn't support these
765 * for a specific input, it must override these flags.
766 */
767 if (ops->vidioc_s_std)
768 p->capabilities |= V4L2_IN_CAP_STD;
769 if (ops->vidioc_s_dv_preset)
770 p->capabilities |= V4L2_IN_CAP_PRESETS;
771 if (ops->vidioc_s_dv_timings)
772 p->capabilities |= V4L2_IN_CAP_CUSTOM_TIMINGS;
773
774 return ops->vidioc_enum_input(file, fh, p);
775}
776
777static int v4l_enumoutput(const struct v4l2_ioctl_ops *ops,
778 struct file *file, void *fh, void *arg)
779{
780 struct v4l2_output *p = arg;
781
782 /*
783 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
784 * CAP_STD here based on ioctl handler provided by the
785 * driver. If the driver doesn't support these
786 * for a specific output, it must override these flags.
787 */
788 if (ops->vidioc_s_std)
789 p->capabilities |= V4L2_OUT_CAP_STD;
790 if (ops->vidioc_s_dv_preset)
791 p->capabilities |= V4L2_OUT_CAP_PRESETS;
792 if (ops->vidioc_s_dv_timings)
793 p->capabilities |= V4L2_OUT_CAP_CUSTOM_TIMINGS;
794
795 return ops->vidioc_enum_output(file, fh, p);
796}
797
Hans Verkuilbe6c64e2012-06-22 06:12:57 -0300798static int v4l_enum_fmt(const struct v4l2_ioctl_ops *ops,
799 struct file *file, void *fh, void *arg)
800{
801 struct v4l2_fmtdesc *p = arg;
802
803 switch (p->type) {
804 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
805 if (unlikely(!ops->vidioc_enum_fmt_vid_cap))
806 break;
807 return ops->vidioc_enum_fmt_vid_cap(file, fh, arg);
808 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
809 if (unlikely(!ops->vidioc_enum_fmt_vid_cap_mplane))
810 break;
811 return ops->vidioc_enum_fmt_vid_cap_mplane(file, fh, arg);
812 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
813 if (unlikely(!ops->vidioc_enum_fmt_vid_overlay))
814 break;
815 return ops->vidioc_enum_fmt_vid_overlay(file, fh, arg);
816 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
817 if (unlikely(!ops->vidioc_enum_fmt_vid_out))
818 break;
819 return ops->vidioc_enum_fmt_vid_out(file, fh, arg);
820 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
821 if (unlikely(!ops->vidioc_enum_fmt_vid_out_mplane))
822 break;
823 return ops->vidioc_enum_fmt_vid_out_mplane(file, fh, arg);
824 case V4L2_BUF_TYPE_PRIVATE:
825 if (unlikely(!ops->vidioc_enum_fmt_type_private))
826 break;
827 return ops->vidioc_enum_fmt_type_private(file, fh, arg);
828 }
829 return -EINVAL;
830}
831
832static int v4l_g_fmt(const struct v4l2_ioctl_ops *ops,
833 struct file *file, void *fh, void *arg)
834{
835 struct v4l2_format *p = arg;
836
837 switch (p->type) {
838 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
839 if (unlikely(!ops->vidioc_g_fmt_vid_cap))
840 break;
841 return ops->vidioc_g_fmt_vid_cap(file, fh, arg);
842 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
843 if (unlikely(!ops->vidioc_g_fmt_vid_cap_mplane))
844 break;
845 return ops->vidioc_g_fmt_vid_cap_mplane(file, fh, arg);
846 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
847 if (unlikely(!ops->vidioc_g_fmt_vid_overlay))
848 break;
849 return ops->vidioc_g_fmt_vid_overlay(file, fh, arg);
850 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
851 if (unlikely(!ops->vidioc_g_fmt_vid_out))
852 break;
853 return ops->vidioc_g_fmt_vid_out(file, fh, arg);
854 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
855 if (unlikely(!ops->vidioc_g_fmt_vid_out_mplane))
856 break;
857 return ops->vidioc_g_fmt_vid_out_mplane(file, fh, arg);
858 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
859 if (unlikely(!ops->vidioc_g_fmt_vid_out_overlay))
860 break;
861 return ops->vidioc_g_fmt_vid_out_overlay(file, fh, arg);
862 case V4L2_BUF_TYPE_VBI_CAPTURE:
863 if (unlikely(!ops->vidioc_g_fmt_vbi_cap))
864 break;
865 return ops->vidioc_g_fmt_vbi_cap(file, fh, arg);
866 case V4L2_BUF_TYPE_VBI_OUTPUT:
867 if (unlikely(!ops->vidioc_g_fmt_vbi_out))
868 break;
869 return ops->vidioc_g_fmt_vbi_out(file, fh, arg);
870 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
871 if (unlikely(!ops->vidioc_g_fmt_sliced_vbi_cap))
872 break;
873 return ops->vidioc_g_fmt_sliced_vbi_cap(file, fh, arg);
874 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
875 if (unlikely(!ops->vidioc_g_fmt_sliced_vbi_out))
876 break;
877 return ops->vidioc_g_fmt_sliced_vbi_out(file, fh, arg);
878 case V4L2_BUF_TYPE_PRIVATE:
879 if (unlikely(!ops->vidioc_g_fmt_type_private))
880 break;
881 return ops->vidioc_g_fmt_type_private(file, fh, arg);
882 }
883 return -EINVAL;
884}
885
886static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops,
887 struct file *file, void *fh, void *arg)
888{
889 struct v4l2_format *p = arg;
890
891 switch (p->type) {
892 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
893 if (unlikely(!ops->vidioc_s_fmt_vid_cap))
894 break;
895 CLEAR_AFTER_FIELD(p, fmt.pix);
896 return ops->vidioc_s_fmt_vid_cap(file, fh, arg);
897 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
898 if (unlikely(!ops->vidioc_s_fmt_vid_cap_mplane))
899 break;
900 CLEAR_AFTER_FIELD(p, fmt.pix_mp);
901 return ops->vidioc_s_fmt_vid_cap_mplane(file, fh, arg);
902 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
903 if (unlikely(!ops->vidioc_s_fmt_vid_overlay))
904 break;
905 CLEAR_AFTER_FIELD(p, fmt.win);
906 return ops->vidioc_s_fmt_vid_overlay(file, fh, arg);
907 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
908 if (unlikely(!ops->vidioc_s_fmt_vid_out))
909 break;
910 CLEAR_AFTER_FIELD(p, fmt.pix);
911 return ops->vidioc_s_fmt_vid_out(file, fh, arg);
912 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
913 if (unlikely(!ops->vidioc_s_fmt_vid_out_mplane))
914 break;
915 CLEAR_AFTER_FIELD(p, fmt.pix_mp);
916 return ops->vidioc_s_fmt_vid_out_mplane(file, fh, arg);
917 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
918 if (unlikely(!ops->vidioc_s_fmt_vid_out_overlay))
919 break;
920 CLEAR_AFTER_FIELD(p, fmt.win);
921 return ops->vidioc_s_fmt_vid_out_overlay(file, fh, arg);
922 case V4L2_BUF_TYPE_VBI_CAPTURE:
923 if (unlikely(!ops->vidioc_s_fmt_vbi_cap))
924 break;
925 CLEAR_AFTER_FIELD(p, fmt.vbi);
926 return ops->vidioc_s_fmt_vbi_cap(file, fh, arg);
927 case V4L2_BUF_TYPE_VBI_OUTPUT:
928 if (unlikely(!ops->vidioc_s_fmt_vbi_out))
929 break;
930 CLEAR_AFTER_FIELD(p, fmt.vbi);
931 return ops->vidioc_s_fmt_vbi_out(file, fh, arg);
932 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
933 if (unlikely(!ops->vidioc_s_fmt_sliced_vbi_cap))
934 break;
935 CLEAR_AFTER_FIELD(p, fmt.sliced);
936 return ops->vidioc_s_fmt_sliced_vbi_cap(file, fh, arg);
937 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
938 if (unlikely(!ops->vidioc_s_fmt_sliced_vbi_out))
939 break;
940 CLEAR_AFTER_FIELD(p, fmt.sliced);
941 return ops->vidioc_s_fmt_sliced_vbi_out(file, fh, arg);
942 case V4L2_BUF_TYPE_PRIVATE:
943 if (unlikely(!ops->vidioc_s_fmt_type_private))
944 break;
945 return ops->vidioc_s_fmt_type_private(file, fh, arg);
946 }
947 return -EINVAL;
948}
949
950static int v4l_try_fmt(const struct v4l2_ioctl_ops *ops,
951 struct file *file, void *fh, void *arg)
952{
953 struct v4l2_format *p = arg;
954
955 switch (p->type) {
956 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
957 if (unlikely(!ops->vidioc_try_fmt_vid_cap))
958 break;
959 CLEAR_AFTER_FIELD(p, fmt.pix);
960 return ops->vidioc_try_fmt_vid_cap(file, fh, arg);
961 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
962 if (unlikely(!ops->vidioc_try_fmt_vid_cap_mplane))
963 break;
964 CLEAR_AFTER_FIELD(p, fmt.pix_mp);
965 return ops->vidioc_try_fmt_vid_cap_mplane(file, fh, arg);
966 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
967 if (unlikely(!ops->vidioc_try_fmt_vid_overlay))
968 break;
969 CLEAR_AFTER_FIELD(p, fmt.win);
970 return ops->vidioc_try_fmt_vid_overlay(file, fh, arg);
971 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
972 if (unlikely(!ops->vidioc_try_fmt_vid_out))
973 break;
974 CLEAR_AFTER_FIELD(p, fmt.pix);
975 return ops->vidioc_try_fmt_vid_out(file, fh, arg);
976 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
977 if (unlikely(!ops->vidioc_try_fmt_vid_out_mplane))
978 break;
979 CLEAR_AFTER_FIELD(p, fmt.pix_mp);
980 return ops->vidioc_try_fmt_vid_out_mplane(file, fh, arg);
981 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
982 if (unlikely(!ops->vidioc_try_fmt_vid_out_overlay))
983 break;
984 CLEAR_AFTER_FIELD(p, fmt.win);
985 return ops->vidioc_try_fmt_vid_out_overlay(file, fh, arg);
986 case V4L2_BUF_TYPE_VBI_CAPTURE:
987 if (unlikely(!ops->vidioc_try_fmt_vbi_cap))
988 break;
989 CLEAR_AFTER_FIELD(p, fmt.vbi);
990 return ops->vidioc_try_fmt_vbi_cap(file, fh, arg);
991 case V4L2_BUF_TYPE_VBI_OUTPUT:
992 if (unlikely(!ops->vidioc_try_fmt_vbi_out))
993 break;
994 CLEAR_AFTER_FIELD(p, fmt.vbi);
995 return ops->vidioc_try_fmt_vbi_out(file, fh, arg);
996 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
997 if (unlikely(!ops->vidioc_try_fmt_sliced_vbi_cap))
998 break;
999 CLEAR_AFTER_FIELD(p, fmt.sliced);
1000 return ops->vidioc_try_fmt_sliced_vbi_cap(file, fh, arg);
1001 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
1002 if (unlikely(!ops->vidioc_try_fmt_sliced_vbi_out))
1003 break;
1004 CLEAR_AFTER_FIELD(p, fmt.sliced);
1005 return ops->vidioc_try_fmt_sliced_vbi_out(file, fh, arg);
1006 case V4L2_BUF_TYPE_PRIVATE:
1007 if (unlikely(!ops->vidioc_try_fmt_type_private))
1008 break;
1009 return ops->vidioc_try_fmt_type_private(file, fh, arg);
1010 }
1011 return -EINVAL;
1012}
1013
Hans Verkuile325b242012-06-09 12:50:15 -03001014static int v4l_streamon(const struct v4l2_ioctl_ops *ops,
1015 struct file *file, void *fh, void *arg)
1016{
1017 return ops->vidioc_streamon(file, fh, *(unsigned int *)arg);
1018}
1019
1020static int v4l_streamoff(const struct v4l2_ioctl_ops *ops,
1021 struct file *file, void *fh, void *arg)
1022{
1023 return ops->vidioc_streamoff(file, fh, *(unsigned int *)arg);
1024}
1025
Hans Verkuil4b1e2e42012-06-22 06:17:48 -03001026static int v4l_g_tuner(const struct v4l2_ioctl_ops *ops,
1027 struct file *file, void *fh, void *arg)
1028{
1029 struct video_device *vfd = video_devdata(file);
1030 struct v4l2_tuner *p = arg;
1031
1032 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1033 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1034 return ops->vidioc_g_tuner(file, fh, p);
1035}
1036
1037static int v4l_s_tuner(const struct v4l2_ioctl_ops *ops,
1038 struct file *file, void *fh, void *arg)
1039{
1040 struct video_device *vfd = video_devdata(file);
1041 struct v4l2_tuner *p = arg;
1042
1043 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1044 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1045 return ops->vidioc_s_tuner(file, fh, p);
1046}
1047
1048static int v4l_g_frequency(const struct v4l2_ioctl_ops *ops,
1049 struct file *file, void *fh, void *arg)
1050{
1051 struct video_device *vfd = video_devdata(file);
1052 struct v4l2_frequency *p = arg;
1053
1054 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1055 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1056 return ops->vidioc_g_frequency(file, fh, p);
1057}
1058
1059static int v4l_s_frequency(const struct v4l2_ioctl_ops *ops,
1060 struct file *file, void *fh, void *arg)
1061{
1062 struct video_device *vfd = video_devdata(file);
1063 struct v4l2_frequency *p = arg;
1064 enum v4l2_tuner_type type;
1065
1066 type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1067 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1068 if (p->type != type)
1069 return -EINVAL;
1070 return ops->vidioc_s_frequency(file, fh, p);
1071}
1072
1073static int v4l_enumstd(const struct v4l2_ioctl_ops *ops,
1074 struct file *file, void *fh, void *arg)
1075{
1076 struct video_device *vfd = video_devdata(file);
1077 struct v4l2_standard *p = arg;
1078 v4l2_std_id id = vfd->tvnorms, curr_id = 0;
1079 unsigned int index = p->index, i, j = 0;
1080 const char *descr = "";
1081
1082 /* Return norm array in a canonical way */
1083 for (i = 0; i <= index && id; i++) {
1084 /* last std value in the standards array is 0, so this
1085 while always ends there since (id & 0) == 0. */
1086 while ((id & standards[j].std) != standards[j].std)
1087 j++;
1088 curr_id = standards[j].std;
1089 descr = standards[j].descr;
1090 j++;
1091 if (curr_id == 0)
1092 break;
1093 if (curr_id != V4L2_STD_PAL &&
1094 curr_id != V4L2_STD_SECAM &&
1095 curr_id != V4L2_STD_NTSC)
1096 id &= ~curr_id;
1097 }
1098 if (i <= index)
1099 return -EINVAL;
1100
1101 v4l2_video_std_construct(p, curr_id, descr);
1102 return 0;
1103}
1104
1105static int v4l_g_std(const struct v4l2_ioctl_ops *ops,
1106 struct file *file, void *fh, void *arg)
1107{
1108 struct video_device *vfd = video_devdata(file);
1109 v4l2_std_id *id = arg;
1110
1111 /* Calls the specific handler */
1112 if (ops->vidioc_g_std)
1113 return ops->vidioc_g_std(file, fh, arg);
1114 if (vfd->current_norm) {
1115 *id = vfd->current_norm;
1116 return 0;
1117 }
1118 return -ENOTTY;
1119}
1120
1121static int v4l_s_std(const struct v4l2_ioctl_ops *ops,
1122 struct file *file, void *fh, void *arg)
1123{
1124 struct video_device *vfd = video_devdata(file);
1125 v4l2_std_id *id = arg, norm;
1126 int ret;
1127
1128 norm = (*id) & vfd->tvnorms;
1129 if (vfd->tvnorms && !norm) /* Check if std is supported */
1130 return -EINVAL;
1131
1132 /* Calls the specific handler */
1133 ret = ops->vidioc_s_std(file, fh, &norm);
1134
1135 /* Updates standard information */
1136 if (ret >= 0)
1137 vfd->current_norm = norm;
1138 return ret;
1139}
1140
1141static int v4l_querystd(const struct v4l2_ioctl_ops *ops,
1142 struct file *file, void *fh, void *arg)
1143{
1144 struct video_device *vfd = video_devdata(file);
1145 v4l2_std_id *p = arg;
1146
1147 /*
1148 * If nothing detected, it should return all supported
1149 * standard.
1150 * Drivers just need to mask the std argument, in order
1151 * to remove the standards that don't apply from the mask.
1152 * This means that tuners, audio and video decoders can join
1153 * their efforts to improve the standards detection.
1154 */
1155 *p = vfd->tvnorms;
1156 return ops->vidioc_querystd(file, fh, arg);
1157}
1158
1159static int v4l_s_hw_freq_seek(const struct v4l2_ioctl_ops *ops,
1160 struct file *file, void *fh, void *arg)
1161{
1162 struct video_device *vfd = video_devdata(file);
1163 struct v4l2_hw_freq_seek *p = arg;
1164 enum v4l2_tuner_type type;
1165
1166 type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1167 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1168 if (p->type != type)
1169 return -EINVAL;
1170 return ops->vidioc_s_hw_freq_seek(file, fh, p);
1171}
1172
Hans Verkuileb3728e2012-06-22 06:23:59 -03001173static int v4l_reqbufs(const struct v4l2_ioctl_ops *ops,
1174 struct file *file, void *fh, void *arg)
1175{
1176 struct v4l2_requestbuffers *p = arg;
1177 int ret = check_fmt(ops, p->type);
1178
1179 if (ret)
1180 return ret;
1181
1182 if (p->type < V4L2_BUF_TYPE_PRIVATE)
1183 CLEAR_AFTER_FIELD(p, memory);
1184
1185 return ops->vidioc_reqbufs(file, fh, p);
1186}
1187
1188static int v4l_querybuf(const struct v4l2_ioctl_ops *ops,
1189 struct file *file, void *fh, void *arg)
1190{
1191 struct v4l2_buffer *p = arg;
1192 int ret = check_fmt(ops, p->type);
1193
1194 return ret ? ret : ops->vidioc_querybuf(file, fh, p);
1195}
1196
1197static int v4l_qbuf(const struct v4l2_ioctl_ops *ops,
1198 struct file *file, void *fh, void *arg)
1199{
1200 struct v4l2_buffer *p = arg;
1201 int ret = check_fmt(ops, p->type);
1202
1203 return ret ? ret : ops->vidioc_qbuf(file, fh, p);
1204}
1205
1206static int v4l_dqbuf(const struct v4l2_ioctl_ops *ops,
1207 struct file *file, void *fh, void *arg)
1208{
1209 struct v4l2_buffer *p = arg;
1210 int ret = check_fmt(ops, p->type);
1211
1212 return ret ? ret : ops->vidioc_dqbuf(file, fh, p);
1213}
1214
1215static int v4l_create_bufs(const struct v4l2_ioctl_ops *ops,
1216 struct file *file, void *fh, void *arg)
1217{
1218 struct v4l2_create_buffers *create = arg;
1219 int ret = check_fmt(ops, create->format.type);
1220
1221 return ret ? ret : ops->vidioc_create_bufs(file, fh, create);
1222}
1223
1224static int v4l_prepare_buf(const struct v4l2_ioctl_ops *ops,
1225 struct file *file, void *fh, void *arg)
1226{
1227 struct v4l2_buffer *b = arg;
1228 int ret = check_fmt(ops, b->type);
1229
1230 return ret ? ret : ops->vidioc_prepare_buf(file, fh, b);
1231}
1232
1233static int v4l_g_parm(const struct v4l2_ioctl_ops *ops,
1234 struct file *file, void *fh, void *arg)
1235{
1236 struct video_device *vfd = video_devdata(file);
1237 struct v4l2_streamparm *p = arg;
1238 v4l2_std_id std;
1239 int ret = check_fmt(ops, p->type);
1240
1241 if (ret)
1242 return ret;
1243 if (ops->vidioc_g_parm)
1244 return ops->vidioc_g_parm(file, fh, p);
1245 std = vfd->current_norm;
1246 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
1247 p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
1248 return -EINVAL;
1249 p->parm.capture.readbuffers = 2;
1250 if (ops->vidioc_g_std)
1251 ret = ops->vidioc_g_std(file, fh, &std);
1252 if (ret == 0)
1253 v4l2_video_std_frame_period(std,
1254 &p->parm.capture.timeperframe);
1255 return ret;
1256}
1257
1258static int v4l_s_parm(const struct v4l2_ioctl_ops *ops,
1259 struct file *file, void *fh, void *arg)
1260{
1261 struct v4l2_streamparm *p = arg;
1262 int ret = check_fmt(ops, p->type);
1263
1264 return ret ? ret : ops->vidioc_s_parm(file, fh, p);
1265}
1266
Hans Verkuilefbceec2012-06-09 12:54:02 -03001267static int v4l_queryctrl(const struct v4l2_ioctl_ops *ops,
1268 struct file *file, void *fh, void *arg)
1269{
1270 struct video_device *vfd = video_devdata(file);
1271 struct v4l2_queryctrl *p = arg;
1272 struct v4l2_fh *vfh = fh;
1273
1274 if (vfh && vfh->ctrl_handler)
1275 return v4l2_queryctrl(vfh->ctrl_handler, p);
1276 if (vfd->ctrl_handler)
1277 return v4l2_queryctrl(vfd->ctrl_handler, p);
1278 if (ops->vidioc_queryctrl)
1279 return ops->vidioc_queryctrl(file, fh, p);
1280 return -ENOTTY;
1281}
1282
1283static int v4l_querymenu(const struct v4l2_ioctl_ops *ops,
1284 struct file *file, void *fh, void *arg)
1285{
1286 struct video_device *vfd = video_devdata(file);
1287 struct v4l2_querymenu *p = arg;
1288 struct v4l2_fh *vfh = fh;
1289
1290 if (vfh && vfh->ctrl_handler)
1291 return v4l2_querymenu(vfh->ctrl_handler, p);
1292 if (vfd->ctrl_handler)
1293 return v4l2_querymenu(vfd->ctrl_handler, p);
1294 if (ops->vidioc_querymenu)
1295 return ops->vidioc_querymenu(file, fh, p);
1296 return -ENOTTY;
1297}
1298
1299static int v4l_g_ctrl(const struct v4l2_ioctl_ops *ops,
1300 struct file *file, void *fh, void *arg)
1301{
1302 struct video_device *vfd = video_devdata(file);
1303 struct v4l2_control *p = arg;
1304 struct v4l2_fh *vfh = fh;
1305 struct v4l2_ext_controls ctrls;
1306 struct v4l2_ext_control ctrl;
1307
1308 if (vfh && vfh->ctrl_handler)
1309 return v4l2_g_ctrl(vfh->ctrl_handler, p);
1310 if (vfd->ctrl_handler)
1311 return v4l2_g_ctrl(vfd->ctrl_handler, p);
1312 if (ops->vidioc_g_ctrl)
1313 return ops->vidioc_g_ctrl(file, fh, p);
1314 if (ops->vidioc_g_ext_ctrls == NULL)
1315 return -ENOTTY;
1316
1317 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1318 ctrls.count = 1;
1319 ctrls.controls = &ctrl;
1320 ctrl.id = p->id;
1321 ctrl.value = p->value;
1322 if (check_ext_ctrls(&ctrls, 1)) {
1323 int ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls);
1324
1325 if (ret == 0)
1326 p->value = ctrl.value;
1327 return ret;
1328 }
1329 return -EINVAL;
1330}
1331
1332static int v4l_s_ctrl(const struct v4l2_ioctl_ops *ops,
1333 struct file *file, void *fh, void *arg)
1334{
1335 struct video_device *vfd = video_devdata(file);
1336 struct v4l2_control *p = arg;
1337 struct v4l2_fh *vfh = fh;
1338 struct v4l2_ext_controls ctrls;
1339 struct v4l2_ext_control ctrl;
1340
1341 if (vfh && vfh->ctrl_handler)
1342 return v4l2_s_ctrl(vfh, vfh->ctrl_handler, p);
1343 if (vfd->ctrl_handler)
1344 return v4l2_s_ctrl(NULL, vfd->ctrl_handler, p);
1345 if (ops->vidioc_s_ctrl)
1346 return ops->vidioc_s_ctrl(file, fh, p);
1347 if (ops->vidioc_s_ext_ctrls == NULL)
1348 return -ENOTTY;
1349
1350 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1351 ctrls.count = 1;
1352 ctrls.controls = &ctrl;
1353 ctrl.id = p->id;
1354 ctrl.value = p->value;
1355 if (check_ext_ctrls(&ctrls, 1))
1356 return ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
1357 return -EINVAL;
1358}
1359
1360static int v4l_g_ext_ctrls(const struct v4l2_ioctl_ops *ops,
1361 struct file *file, void *fh, void *arg)
1362{
1363 struct video_device *vfd = video_devdata(file);
1364 struct v4l2_ext_controls *p = arg;
1365 struct v4l2_fh *vfh = fh;
1366
1367 p->error_idx = p->count;
1368 if (vfh && vfh->ctrl_handler)
1369 return v4l2_g_ext_ctrls(vfh->ctrl_handler, p);
1370 if (vfd->ctrl_handler)
1371 return v4l2_g_ext_ctrls(vfd->ctrl_handler, p);
1372 if (ops->vidioc_g_ext_ctrls == NULL)
1373 return -ENOTTY;
1374 return check_ext_ctrls(p, 0) ? ops->vidioc_g_ext_ctrls(file, fh, p) :
1375 -EINVAL;
1376}
1377
1378static int v4l_s_ext_ctrls(const struct v4l2_ioctl_ops *ops,
1379 struct file *file, void *fh, void *arg)
1380{
1381 struct video_device *vfd = video_devdata(file);
1382 struct v4l2_ext_controls *p = arg;
1383 struct v4l2_fh *vfh = fh;
1384
1385 p->error_idx = p->count;
1386 if (vfh && vfh->ctrl_handler)
1387 return v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, p);
1388 if (vfd->ctrl_handler)
1389 return v4l2_s_ext_ctrls(NULL, vfd->ctrl_handler, p);
1390 if (ops->vidioc_s_ext_ctrls == NULL)
1391 return -ENOTTY;
1392 return check_ext_ctrls(p, 0) ? ops->vidioc_s_ext_ctrls(file, fh, p) :
1393 -EINVAL;
1394}
1395
1396static int v4l_try_ext_ctrls(const struct v4l2_ioctl_ops *ops,
1397 struct file *file, void *fh, void *arg)
1398{
1399 struct video_device *vfd = video_devdata(file);
1400 struct v4l2_ext_controls *p = arg;
1401 struct v4l2_fh *vfh = fh;
1402
1403 p->error_idx = p->count;
1404 if (vfh && vfh->ctrl_handler)
1405 return v4l2_try_ext_ctrls(vfh->ctrl_handler, p);
1406 if (vfd->ctrl_handler)
1407 return v4l2_try_ext_ctrls(vfd->ctrl_handler, p);
1408 if (ops->vidioc_try_ext_ctrls == NULL)
1409 return -ENOTTY;
1410 return check_ext_ctrls(p, 0) ? ops->vidioc_try_ext_ctrls(file, fh, p) :
1411 -EINVAL;
1412}
1413
Hans Verkuild84f2d942012-06-09 11:57:46 -03001414static int v4l_g_crop(const struct v4l2_ioctl_ops *ops,
1415 struct file *file, void *fh, void *arg)
1416{
1417 struct v4l2_crop *p = arg;
1418 struct v4l2_selection s = {
1419 .type = p->type,
1420 };
1421 int ret;
1422
1423 if (ops->vidioc_g_crop)
1424 return ops->vidioc_g_crop(file, fh, p);
1425 /* simulate capture crop using selection api */
1426
1427 /* crop means compose for output devices */
1428 if (V4L2_TYPE_IS_OUTPUT(p->type))
1429 s.target = V4L2_SEL_TGT_COMPOSE_ACTIVE;
1430 else
1431 s.target = V4L2_SEL_TGT_CROP_ACTIVE;
1432
1433 ret = ops->vidioc_g_selection(file, fh, &s);
1434
1435 /* copying results to old structure on success */
1436 if (!ret)
1437 p->c = s.r;
1438 return ret;
1439}
1440
1441static int v4l_s_crop(const struct v4l2_ioctl_ops *ops,
1442 struct file *file, void *fh, void *arg)
1443{
1444 struct v4l2_crop *p = arg;
1445 struct v4l2_selection s = {
1446 .type = p->type,
1447 .r = p->c,
1448 };
1449
1450 if (ops->vidioc_s_crop)
1451 return ops->vidioc_s_crop(file, fh, p);
1452 /* simulate capture crop using selection api */
1453
1454 /* crop means compose for output devices */
1455 if (V4L2_TYPE_IS_OUTPUT(p->type))
1456 s.target = V4L2_SEL_TGT_COMPOSE_ACTIVE;
1457 else
1458 s.target = V4L2_SEL_TGT_CROP_ACTIVE;
1459
1460 return ops->vidioc_s_selection(file, fh, &s);
1461}
1462
1463static int v4l_cropcap(const struct v4l2_ioctl_ops *ops,
1464 struct file *file, void *fh, void *arg)
1465{
1466 struct v4l2_cropcap *p = arg;
1467 struct v4l2_selection s = { .type = p->type };
1468 int ret;
1469
1470 if (ops->vidioc_cropcap)
1471 return ops->vidioc_cropcap(file, fh, p);
1472
1473 /* obtaining bounds */
1474 if (V4L2_TYPE_IS_OUTPUT(p->type))
1475 s.target = V4L2_SEL_TGT_COMPOSE_BOUNDS;
1476 else
1477 s.target = V4L2_SEL_TGT_CROP_BOUNDS;
1478
1479 ret = ops->vidioc_g_selection(file, fh, &s);
1480 if (ret)
1481 return ret;
1482 p->bounds = s.r;
1483
1484 /* obtaining defrect */
1485 if (V4L2_TYPE_IS_OUTPUT(p->type))
1486 s.target = V4L2_SEL_TGT_COMPOSE_DEFAULT;
1487 else
1488 s.target = V4L2_SEL_TGT_CROP_DEFAULT;
1489
1490 ret = ops->vidioc_g_selection(file, fh, &s);
1491 if (ret)
1492 return ret;
1493 p->defrect = s.r;
1494
1495 /* setting trivial pixelaspect */
1496 p->pixelaspect.numerator = 1;
1497 p->pixelaspect.denominator = 1;
1498 return 0;
1499}
1500
Hans Verkuil4839e6c2012-06-04 05:23:40 -03001501struct v4l2_ioctl_info {
1502 unsigned int ioctl;
Hans Verkuil27cd2ab2012-06-09 08:55:31 -03001503 u32 flags;
Hans Verkuil4839e6c2012-06-04 05:23:40 -03001504 const char * const name;
Hans Verkuil86748f32012-06-22 06:04:16 -03001505 union {
1506 u32 offset;
1507 int (*func)(const struct v4l2_ioctl_ops *ops,
1508 struct file *file, void *fh, void *p);
1509 };
1510 void (*debug)(const void *arg, bool write_only);
Hans Verkuil4839e6c2012-06-04 05:23:40 -03001511};
1512
1513/* This control needs a priority check */
1514#define INFO_FL_PRIO (1 << 0)
1515/* This control can be valid if the filehandle passes a control handler. */
1516#define INFO_FL_CTRL (1 << 1)
Hans Verkuil86748f32012-06-22 06:04:16 -03001517/* This is a standard ioctl, no need for special code */
1518#define INFO_FL_STD (1 << 2)
1519/* This is ioctl has its own function */
1520#define INFO_FL_FUNC (1 << 3)
Hans Verkuil27cd2ab2012-06-09 08:55:31 -03001521/* Zero struct from after the field to the end */
1522#define INFO_FL_CLEAR(v4l2_struct, field) \
1523 ((offsetof(struct v4l2_struct, field) + \
1524 sizeof(((struct v4l2_struct *)0)->field)) << 16)
1525#define INFO_FL_CLEAR_MASK (_IOC_SIZEMASK << 16)
Hans Verkuil4839e6c2012-06-04 05:23:40 -03001526
1527#define IOCTL_INFO(_ioctl, _flags) [_IOC_NR(_ioctl)] = { \
1528 .ioctl = _ioctl, \
1529 .flags = _flags, \
1530 .name = #_ioctl, \
1531}
1532
Hans Verkuil86748f32012-06-22 06:04:16 -03001533#define IOCTL_INFO_STD(_ioctl, _vidioc, _debug, _flags) \
1534 [_IOC_NR(_ioctl)] = { \
1535 .ioctl = _ioctl, \
1536 .flags = _flags | INFO_FL_STD, \
1537 .name = #_ioctl, \
1538 .offset = offsetof(struct v4l2_ioctl_ops, _vidioc), \
1539 .debug = _debug, \
1540 }
1541
1542#define IOCTL_INFO_FNC(_ioctl, _func, _debug, _flags) \
1543 [_IOC_NR(_ioctl)] = { \
1544 .ioctl = _ioctl, \
1545 .flags = _flags | INFO_FL_FUNC, \
1546 .name = #_ioctl, \
1547 .func = _func, \
1548 .debug = _debug, \
1549 }
1550
Hans Verkuil4839e6c2012-06-04 05:23:40 -03001551static struct v4l2_ioctl_info v4l2_ioctls[] = {
Hans Verkuil59076122012-06-22 06:09:54 -03001552 IOCTL_INFO_FNC(VIDIOC_QUERYCAP, v4l_querycap, v4l_print_querycap, 0),
Hans Verkuilbe6c64e2012-06-22 06:12:57 -03001553 IOCTL_INFO_FNC(VIDIOC_ENUM_FMT, v4l_enum_fmt, v4l_print_fmtdesc, INFO_FL_CLEAR(v4l2_fmtdesc, type)),
1554 IOCTL_INFO_FNC(VIDIOC_G_FMT, v4l_g_fmt, v4l_print_format, INFO_FL_CLEAR(v4l2_format, type)),
1555 IOCTL_INFO_FNC(VIDIOC_S_FMT, v4l_s_fmt, v4l_print_format, INFO_FL_PRIO),
Hans Verkuileb3728e2012-06-22 06:23:59 -03001556 IOCTL_INFO_FNC(VIDIOC_REQBUFS, v4l_reqbufs, v4l_print_requestbuffers, INFO_FL_PRIO),
1557 IOCTL_INFO_FNC(VIDIOC_QUERYBUF, v4l_querybuf, v4l_print_buffer, INFO_FL_CLEAR(v4l2_buffer, length)),
Hans Verkuilbe6c64e2012-06-22 06:12:57 -03001558 IOCTL_INFO_STD(VIDIOC_G_FBUF, vidioc_g_fbuf, v4l_print_framebuffer, 0),
1559 IOCTL_INFO_STD(VIDIOC_S_FBUF, vidioc_s_fbuf, v4l_print_framebuffer, INFO_FL_PRIO),
Hans Verkuile325b242012-06-09 12:50:15 -03001560 IOCTL_INFO_STD(VIDIOC_OVERLAY, vidioc_overlay, v4l_print_u32, INFO_FL_PRIO),
Hans Verkuileb3728e2012-06-22 06:23:59 -03001561 IOCTL_INFO_FNC(VIDIOC_QBUF, v4l_qbuf, v4l_print_buffer, 0),
1562 IOCTL_INFO_FNC(VIDIOC_DQBUF, v4l_dqbuf, v4l_print_buffer, 0),
Hans Verkuile325b242012-06-09 12:50:15 -03001563 IOCTL_INFO_FNC(VIDIOC_STREAMON, v4l_streamon, v4l_print_buftype, INFO_FL_PRIO),
1564 IOCTL_INFO_FNC(VIDIOC_STREAMOFF, v4l_streamoff, v4l_print_buftype, INFO_FL_PRIO),
Hans Verkuileb3728e2012-06-22 06:23:59 -03001565 IOCTL_INFO_FNC(VIDIOC_G_PARM, v4l_g_parm, v4l_print_streamparm, INFO_FL_CLEAR(v4l2_streamparm, type)),
1566 IOCTL_INFO_FNC(VIDIOC_S_PARM, v4l_s_parm, v4l_print_streamparm, INFO_FL_PRIO),
Hans Verkuil4b1e2e42012-06-22 06:17:48 -03001567 IOCTL_INFO_FNC(VIDIOC_G_STD, v4l_g_std, v4l_print_std, 0),
1568 IOCTL_INFO_FNC(VIDIOC_S_STD, v4l_s_std, v4l_print_std, INFO_FL_PRIO),
1569 IOCTL_INFO_FNC(VIDIOC_ENUMSTD, v4l_enumstd, v4l_print_standard, INFO_FL_CLEAR(v4l2_standard, index)),
Hans Verkuil59076122012-06-22 06:09:54 -03001570 IOCTL_INFO_FNC(VIDIOC_ENUMINPUT, v4l_enuminput, v4l_print_enuminput, INFO_FL_CLEAR(v4l2_input, index)),
Hans Verkuilefbceec2012-06-09 12:54:02 -03001571 IOCTL_INFO_FNC(VIDIOC_G_CTRL, v4l_g_ctrl, v4l_print_control, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_control, id)),
1572 IOCTL_INFO_FNC(VIDIOC_S_CTRL, v4l_s_ctrl, v4l_print_control, INFO_FL_PRIO | INFO_FL_CTRL),
Hans Verkuil4b1e2e42012-06-22 06:17:48 -03001573 IOCTL_INFO_FNC(VIDIOC_G_TUNER, v4l_g_tuner, v4l_print_tuner, INFO_FL_CLEAR(v4l2_tuner, index)),
1574 IOCTL_INFO_FNC(VIDIOC_S_TUNER, v4l_s_tuner, v4l_print_tuner, INFO_FL_PRIO),
Hans Verkuil59076122012-06-22 06:09:54 -03001575 IOCTL_INFO_STD(VIDIOC_G_AUDIO, vidioc_g_audio, v4l_print_audio, 0),
1576 IOCTL_INFO_STD(VIDIOC_S_AUDIO, vidioc_s_audio, v4l_print_audio, INFO_FL_PRIO),
Hans Verkuilefbceec2012-06-09 12:54:02 -03001577 IOCTL_INFO_FNC(VIDIOC_QUERYCTRL, v4l_queryctrl, v4l_print_queryctrl, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_queryctrl, id)),
1578 IOCTL_INFO_FNC(VIDIOC_QUERYMENU, v4l_querymenu, v4l_print_querymenu, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_querymenu, index)),
Hans Verkuil59076122012-06-22 06:09:54 -03001579 IOCTL_INFO_STD(VIDIOC_G_INPUT, vidioc_g_input, v4l_print_u32, 0),
1580 IOCTL_INFO_FNC(VIDIOC_S_INPUT, v4l_s_input, v4l_print_u32, INFO_FL_PRIO),
1581 IOCTL_INFO_STD(VIDIOC_G_OUTPUT, vidioc_g_output, v4l_print_u32, 0),
1582 IOCTL_INFO_FNC(VIDIOC_S_OUTPUT, v4l_s_output, v4l_print_u32, INFO_FL_PRIO),
1583 IOCTL_INFO_FNC(VIDIOC_ENUMOUTPUT, v4l_enumoutput, v4l_print_enumoutput, INFO_FL_CLEAR(v4l2_output, index)),
1584 IOCTL_INFO_STD(VIDIOC_G_AUDOUT, vidioc_g_audout, v4l_print_audioout, 0),
1585 IOCTL_INFO_STD(VIDIOC_S_AUDOUT, vidioc_s_audout, v4l_print_audioout, INFO_FL_PRIO),
Hans Verkuil4b1e2e42012-06-22 06:17:48 -03001586 IOCTL_INFO_STD(VIDIOC_G_MODULATOR, vidioc_g_modulator, v4l_print_modulator, INFO_FL_CLEAR(v4l2_modulator, index)),
1587 IOCTL_INFO_STD(VIDIOC_S_MODULATOR, vidioc_s_modulator, v4l_print_modulator, INFO_FL_PRIO),
1588 IOCTL_INFO_FNC(VIDIOC_G_FREQUENCY, v4l_g_frequency, v4l_print_frequency, INFO_FL_CLEAR(v4l2_frequency, tuner)),
1589 IOCTL_INFO_FNC(VIDIOC_S_FREQUENCY, v4l_s_frequency, v4l_print_frequency, INFO_FL_PRIO),
Hans Verkuild84f2d942012-06-09 11:57:46 -03001590 IOCTL_INFO_FNC(VIDIOC_CROPCAP, v4l_cropcap, v4l_print_cropcap, INFO_FL_CLEAR(v4l2_cropcap, type)),
1591 IOCTL_INFO_FNC(VIDIOC_G_CROP, v4l_g_crop, v4l_print_crop, INFO_FL_CLEAR(v4l2_crop, type)),
1592 IOCTL_INFO_FNC(VIDIOC_S_CROP, v4l_s_crop, v4l_print_crop, INFO_FL_PRIO),
1593 IOCTL_INFO_STD(VIDIOC_G_SELECTION, vidioc_g_selection, v4l_print_selection, 0),
1594 IOCTL_INFO_STD(VIDIOC_S_SELECTION, vidioc_s_selection, v4l_print_selection, INFO_FL_PRIO),
Hans Verkuil4839e6c2012-06-04 05:23:40 -03001595 IOCTL_INFO(VIDIOC_G_JPEGCOMP, 0),
1596 IOCTL_INFO(VIDIOC_S_JPEGCOMP, INFO_FL_PRIO),
Hans Verkuil4b1e2e42012-06-22 06:17:48 -03001597 IOCTL_INFO_FNC(VIDIOC_QUERYSTD, v4l_querystd, v4l_print_std, 0),
Hans Verkuilbe6c64e2012-06-22 06:12:57 -03001598 IOCTL_INFO_FNC(VIDIOC_TRY_FMT, v4l_try_fmt, v4l_print_format, 0),
Hans Verkuil59076122012-06-22 06:09:54 -03001599 IOCTL_INFO_STD(VIDIOC_ENUMAUDIO, vidioc_enumaudio, v4l_print_audio, INFO_FL_CLEAR(v4l2_audio, index)),
1600 IOCTL_INFO_STD(VIDIOC_ENUMAUDOUT, vidioc_enumaudout, v4l_print_audioout, INFO_FL_CLEAR(v4l2_audioout, index)),
Hans Verkuild0547cb2012-06-09 09:27:10 -03001601 IOCTL_INFO_FNC(VIDIOC_G_PRIORITY, v4l_g_priority, v4l_print_u32, 0),
1602 IOCTL_INFO_FNC(VIDIOC_S_PRIORITY, v4l_s_priority, v4l_print_u32, INFO_FL_PRIO),
Hans Verkuil27cd2ab2012-06-09 08:55:31 -03001603 IOCTL_INFO(VIDIOC_G_SLICED_VBI_CAP, INFO_FL_CLEAR(v4l2_sliced_vbi_cap, type)),
Hans Verkuil4839e6c2012-06-04 05:23:40 -03001604 IOCTL_INFO(VIDIOC_LOG_STATUS, 0),
Hans Verkuilefbceec2012-06-09 12:54:02 -03001605 IOCTL_INFO_FNC(VIDIOC_G_EXT_CTRLS, v4l_g_ext_ctrls, v4l_print_ext_controls, INFO_FL_CTRL),
1606 IOCTL_INFO_FNC(VIDIOC_S_EXT_CTRLS, v4l_s_ext_ctrls, v4l_print_ext_controls, INFO_FL_PRIO | INFO_FL_CTRL),
1607 IOCTL_INFO_FNC(VIDIOC_TRY_EXT_CTRLS, v4l_try_ext_ctrls, v4l_print_ext_controls, 0),
Hans Verkuil27cd2ab2012-06-09 08:55:31 -03001608 IOCTL_INFO(VIDIOC_ENUM_FRAMESIZES, INFO_FL_CLEAR(v4l2_frmsizeenum, pixel_format)),
1609 IOCTL_INFO(VIDIOC_ENUM_FRAMEINTERVALS, INFO_FL_CLEAR(v4l2_frmivalenum, height)),
Hans Verkuil4839e6c2012-06-04 05:23:40 -03001610 IOCTL_INFO(VIDIOC_G_ENC_INDEX, 0),
Hans Verkuil27cd2ab2012-06-09 08:55:31 -03001611 IOCTL_INFO(VIDIOC_ENCODER_CMD, INFO_FL_PRIO | INFO_FL_CLEAR(v4l2_encoder_cmd, flags)),
1612 IOCTL_INFO(VIDIOC_TRY_ENCODER_CMD, INFO_FL_CLEAR(v4l2_encoder_cmd, flags)),
Hans Verkuil4839e6c2012-06-04 05:23:40 -03001613 IOCTL_INFO(VIDIOC_DECODER_CMD, INFO_FL_PRIO),
1614 IOCTL_INFO(VIDIOC_TRY_DECODER_CMD, 0),
Hans Verkuil4839e6c2012-06-04 05:23:40 -03001615 IOCTL_INFO(VIDIOC_DBG_S_REGISTER, 0),
1616 IOCTL_INFO(VIDIOC_DBG_G_REGISTER, 0),
Hans Verkuil4839e6c2012-06-04 05:23:40 -03001617 IOCTL_INFO(VIDIOC_DBG_G_CHIP_IDENT, 0),
Hans Verkuil4b1e2e42012-06-22 06:17:48 -03001618 IOCTL_INFO_FNC(VIDIOC_S_HW_FREQ_SEEK, v4l_s_hw_freq_seek, v4l_print_hw_freq_seek, INFO_FL_PRIO),
Hans Verkuil4839e6c2012-06-04 05:23:40 -03001619 IOCTL_INFO(VIDIOC_ENUM_DV_PRESETS, 0),
1620 IOCTL_INFO(VIDIOC_S_DV_PRESET, INFO_FL_PRIO),
1621 IOCTL_INFO(VIDIOC_G_DV_PRESET, 0),
1622 IOCTL_INFO(VIDIOC_QUERY_DV_PRESET, 0),
1623 IOCTL_INFO(VIDIOC_S_DV_TIMINGS, INFO_FL_PRIO),
1624 IOCTL_INFO(VIDIOC_G_DV_TIMINGS, 0),
1625 IOCTL_INFO(VIDIOC_DQEVENT, 0),
1626 IOCTL_INFO(VIDIOC_SUBSCRIBE_EVENT, 0),
1627 IOCTL_INFO(VIDIOC_UNSUBSCRIBE_EVENT, 0),
Hans Verkuileb3728e2012-06-22 06:23:59 -03001628 IOCTL_INFO_FNC(VIDIOC_CREATE_BUFS, v4l_create_bufs, v4l_print_create_buffers, INFO_FL_PRIO),
1629 IOCTL_INFO_FNC(VIDIOC_PREPARE_BUF, v4l_prepare_buf, v4l_print_buffer, 0),
Hans Verkuil4839e6c2012-06-04 05:23:40 -03001630 IOCTL_INFO(VIDIOC_ENUM_DV_TIMINGS, 0),
1631 IOCTL_INFO(VIDIOC_QUERY_DV_TIMINGS, 0),
1632 IOCTL_INFO(VIDIOC_DV_TIMINGS_CAP, 0),
1633};
1634#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
1635
1636bool v4l2_is_known_ioctl(unsigned int cmd)
1637{
1638 if (_IOC_NR(cmd) >= V4L2_IOCTLS)
1639 return false;
1640 return v4l2_ioctls[_IOC_NR(cmd)].ioctl == cmd;
1641}
1642
1643/* Common ioctl debug function. This function can be used by
1644 external ioctl messages as well as internal V4L ioctl */
1645void v4l_printk_ioctl(unsigned int cmd)
1646{
Hans Verkuil86748f32012-06-22 06:04:16 -03001647 const char *dir, *type;
Hans Verkuil4839e6c2012-06-04 05:23:40 -03001648
1649 switch (_IOC_TYPE(cmd)) {
1650 case 'd':
1651 type = "v4l2_int";
1652 break;
1653 case 'V':
1654 if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
1655 type = "v4l2";
1656 break;
1657 }
Hans Verkuil86748f32012-06-22 06:04:16 -03001658 pr_cont("%s", v4l2_ioctls[_IOC_NR(cmd)].name);
Hans Verkuil4839e6c2012-06-04 05:23:40 -03001659 return;
1660 default:
1661 type = "unknown";
Hans Verkuil86748f32012-06-22 06:04:16 -03001662 break;
Hans Verkuil4839e6c2012-06-04 05:23:40 -03001663 }
1664
1665 switch (_IOC_DIR(cmd)) {
1666 case _IOC_NONE: dir = "--"; break;
1667 case _IOC_READ: dir = "r-"; break;
1668 case _IOC_WRITE: dir = "-w"; break;
1669 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
1670 default: dir = "*ERR*"; break;
1671 }
Hans Verkuil86748f32012-06-22 06:04:16 -03001672 pr_cont("%s ioctl '%c', dir=%s, #%d (0x%08x)",
Hans Verkuil4839e6c2012-06-04 05:23:40 -03001673 type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
1674}
1675EXPORT_SYMBOL(v4l_printk_ioctl);
1676
Hans Verkuil069b7472008-12-30 07:04:34 -03001677static long __video_do_ioctl(struct file *file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001678 unsigned int cmd, void *arg)
1679{
1680 struct video_device *vfd = video_devdata(file);
Hans Verkuila3998102008-07-21 02:57:38 -03001681 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
Hans Verkuil86748f32012-06-22 06:04:16 -03001682 bool write_only = false;
1683 struct v4l2_ioctl_info default_info;
1684 const struct v4l2_ioctl_info *info;
Hans Verkuild5fbf322008-10-18 13:39:53 -03001685 void *fh = file->private_data;
Hans Verkuil99cd47bc2011-03-11 19:00:56 -03001686 struct v4l2_fh *vfh = NULL;
Hans Verkuilb1a873a2011-03-22 10:14:07 -03001687 int use_fh_prio = 0;
Mauro Carvalho Chehab9190d192011-07-06 14:08:08 -03001688 long ret = -ENOTTY;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001689
Hans Verkuil6a717882010-04-06 15:56:08 -03001690 if (ops == NULL) {
1691 printk(KERN_WARNING "videodev: \"%s\" has no ioctl_ops.\n",
1692 vfd->name);
Mauro Carvalho Chehab9190d192011-07-06 14:08:08 -03001693 return ret;
Hans Verkuil6a717882010-04-06 15:56:08 -03001694 }
1695
Hans Verkuil48ea0be2012-05-10 05:36:00 -03001696 if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) {
1697 vfh = file->private_data;
1698 use_fh_prio = test_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
Hans Verkuil48ea0be2012-05-10 05:36:00 -03001699 }
1700
1701 if (v4l2_is_known_ioctl(cmd)) {
Hans Verkuil86748f32012-06-22 06:04:16 -03001702 info = &v4l2_ioctls[_IOC_NR(cmd)];
Hans Verkuil48ea0be2012-05-10 05:36:00 -03001703
1704 if (!test_bit(_IOC_NR(cmd), vfd->valid_ioctls) &&
1705 !((info->flags & INFO_FL_CTRL) && vfh && vfh->ctrl_handler))
Hans Verkuil86748f32012-06-22 06:04:16 -03001706 goto done;
Hans Verkuil4b902fe2012-05-10 05:40:50 -03001707
1708 if (use_fh_prio && (info->flags & INFO_FL_PRIO)) {
1709 ret = v4l2_prio_check(vfd->prio, vfh->prio);
1710 if (ret)
Hans Verkuil86748f32012-06-22 06:04:16 -03001711 goto done;
Hans Verkuil4b902fe2012-05-10 05:40:50 -03001712 }
Hans Verkuil86748f32012-06-22 06:04:16 -03001713 } else {
1714 default_info.ioctl = cmd;
1715 default_info.flags = 0;
1716 default_info.debug = NULL;
1717 info = &default_info;
Hans Verkuil48ea0be2012-05-10 05:36:00 -03001718 }
1719
Hans Verkuil86748f32012-06-22 06:04:16 -03001720 write_only = _IOC_DIR(cmd) == _IOC_WRITE;
1721 if (info->debug && write_only && vfd->debug > V4L2_DEBUG_IOCTL) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001722 v4l_print_ioctl(vfd->name, cmd);
Hans Verkuil86748f32012-06-22 06:04:16 -03001723 pr_cont(": ");
1724 info->debug(arg, write_only);
1725 }
1726 if (info->flags & INFO_FL_STD) {
1727 typedef int (*vidioc_op)(struct file *file, void *fh, void *p);
1728 const void *p = vfd->ioctl_ops;
1729 const vidioc_op *vidioc = p + info->offset;
1730
1731 ret = (*vidioc)(file, fh, arg);
1732 goto done;
1733 } else if (info->flags & INFO_FL_FUNC) {
1734 ret = info->func(ops, file, fh, arg);
1735 goto done;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001736 }
1737
Hans Verkuil6a717882010-04-06 15:56:08 -03001738 switch (cmd) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001739 case VIDIOC_G_JPEGCOMP:
1740 {
1741 struct v4l2_jpegcompression *p = arg;
1742
Hans Verkuila3998102008-07-21 02:57:38 -03001743 ret = ops->vidioc_g_jpegcomp(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001744 if (!ret)
1745 dbgarg(cmd, "quality=%d, APPn=%d, "
1746 "APP_len=%d, COM_len=%d, "
1747 "jpeg_markers=%d\n",
1748 p->quality, p->APPn, p->APP_len,
1749 p->COM_len, p->jpeg_markers);
1750 break;
1751 }
1752 case VIDIOC_S_JPEGCOMP:
1753 {
1754 struct v4l2_jpegcompression *p = arg;
1755
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001756 dbgarg(cmd, "quality=%d, APPn=%d, APP_len=%d, "
1757 "COM_len=%d, jpeg_markers=%d\n",
1758 p->quality, p->APPn, p->APP_len,
1759 p->COM_len, p->jpeg_markers);
Hans Verkuil93d5a302011-08-09 09:32:06 -03001760 ret = ops->vidioc_s_jpegcomp(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001761 break;
1762 }
1763 case VIDIOC_G_ENC_INDEX:
1764 {
1765 struct v4l2_enc_idx *p = arg;
1766
Hans Verkuila3998102008-07-21 02:57:38 -03001767 ret = ops->vidioc_g_enc_index(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001768 if (!ret)
1769 dbgarg(cmd, "entries=%d, entries_cap=%d\n",
1770 p->entries, p->entries_cap);
1771 break;
1772 }
1773 case VIDIOC_ENCODER_CMD:
1774 {
1775 struct v4l2_encoder_cmd *p = arg;
1776
Hans Verkuila3998102008-07-21 02:57:38 -03001777 ret = ops->vidioc_encoder_cmd(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001778 if (!ret)
1779 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1780 break;
1781 }
1782 case VIDIOC_TRY_ENCODER_CMD:
1783 {
1784 struct v4l2_encoder_cmd *p = arg;
1785
Hans Verkuila3998102008-07-21 02:57:38 -03001786 ret = ops->vidioc_try_encoder_cmd(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001787 if (!ret)
1788 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1789 break;
1790 }
Hans Verkuila45c0ad2011-11-24 09:53:43 -03001791 case VIDIOC_DECODER_CMD:
1792 {
1793 struct v4l2_decoder_cmd *p = arg;
1794
Hans Verkuila45c0ad2011-11-24 09:53:43 -03001795 ret = ops->vidioc_decoder_cmd(file, fh, p);
1796 if (!ret)
1797 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1798 break;
1799 }
1800 case VIDIOC_TRY_DECODER_CMD:
1801 {
1802 struct v4l2_decoder_cmd *p = arg;
1803
Hans Verkuila45c0ad2011-11-24 09:53:43 -03001804 ret = ops->vidioc_try_decoder_cmd(file, fh, p);
1805 if (!ret)
1806 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1807 break;
1808 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001809 case VIDIOC_G_SLICED_VBI_CAP:
1810 {
1811 struct v4l2_sliced_vbi_cap *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001812
Trent Piepho19c96e42009-03-04 01:21:02 -03001813 /* Clear up to type, everything after type is zerod already */
1814 memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
1815
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001816 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001817 ret = ops->vidioc_g_sliced_vbi_cap(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001818 if (!ret)
1819 dbgarg2("service_set=%d\n", p->service_set);
1820 break;
1821 }
1822 case VIDIOC_LOG_STATUS:
1823 {
Hans Verkuile2ecb252012-02-02 08:20:53 -03001824 if (vfd->v4l2_dev)
1825 pr_info("%s: ================= START STATUS =================\n",
1826 vfd->v4l2_dev->name);
Hans Verkuila3998102008-07-21 02:57:38 -03001827 ret = ops->vidioc_log_status(file, fh);
Hans Verkuile2ecb252012-02-02 08:20:53 -03001828 if (vfd->v4l2_dev)
1829 pr_info("%s: ================== END STATUS ==================\n",
1830 vfd->v4l2_dev->name);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001831 break;
1832 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001833 case VIDIOC_DBG_G_REGISTER:
1834 {
Hans Verkuil8ab75e32012-05-10 02:51:31 -03001835#ifdef CONFIG_VIDEO_ADV_DEBUG
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001836 struct v4l2_dbg_register *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001837
Hans Verkuil48ea0be2012-05-10 05:36:00 -03001838 if (!capable(CAP_SYS_ADMIN))
1839 ret = -EPERM;
1840 else
1841 ret = ops->vidioc_g_register(file, fh, p);
Hans Verkuil8ab75e32012-05-10 02:51:31 -03001842#endif
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001843 break;
1844 }
1845 case VIDIOC_DBG_S_REGISTER:
1846 {
Hans Verkuil8ab75e32012-05-10 02:51:31 -03001847#ifdef CONFIG_VIDEO_ADV_DEBUG
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001848 struct v4l2_dbg_register *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001849
Hans Verkuil48ea0be2012-05-10 05:36:00 -03001850 if (!capable(CAP_SYS_ADMIN))
1851 ret = -EPERM;
1852 else
1853 ret = ops->vidioc_s_register(file, fh, p);
Hans Verkuil8ab75e32012-05-10 02:51:31 -03001854#endif
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001855 break;
1856 }
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001857 case VIDIOC_DBG_G_CHIP_IDENT:
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001858 {
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001859 struct v4l2_dbg_chip_ident *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001860
Hans Verkuil80b36e02009-02-07 11:00:02 -03001861 p->ident = V4L2_IDENT_NONE;
1862 p->revision = 0;
Hans Verkuila3998102008-07-21 02:57:38 -03001863 ret = ops->vidioc_g_chip_ident(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001864 if (!ret)
1865 dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
1866 break;
1867 }
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001868 case VIDIOC_ENUM_FRAMESIZES:
1869 {
1870 struct v4l2_frmsizeenum *p = arg;
1871
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001872 ret = ops->vidioc_enum_framesizes(file, fh, p);
1873 dbgarg(cmd,
Mauro Carvalho Chehabd1afe422009-06-21 22:37:12 -03001874 "index=%d, pixelformat=%c%c%c%c, type=%d ",
1875 p->index,
1876 (p->pixel_format & 0xff),
1877 (p->pixel_format >> 8) & 0xff,
1878 (p->pixel_format >> 16) & 0xff,
1879 (p->pixel_format >> 24) & 0xff,
1880 p->type);
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001881 switch (p->type) {
1882 case V4L2_FRMSIZE_TYPE_DISCRETE:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001883 dbgarg3("width = %d, height=%d\n",
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001884 p->discrete.width, p->discrete.height);
1885 break;
1886 case V4L2_FRMSIZE_TYPE_STEPWISE:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001887 dbgarg3("min %dx%d, max %dx%d, step %dx%d\n",
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001888 p->stepwise.min_width, p->stepwise.min_height,
1889 p->stepwise.step_width, p->stepwise.step_height,
1890 p->stepwise.max_width, p->stepwise.max_height);
1891 break;
1892 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001893 dbgarg3("continuous\n");
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001894 break;
1895 default:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001896 dbgarg3("- Unknown type!\n");
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001897 }
1898
1899 break;
1900 }
1901 case VIDIOC_ENUM_FRAMEINTERVALS:
1902 {
1903 struct v4l2_frmivalenum *p = arg;
1904
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001905 ret = ops->vidioc_enum_frameintervals(file, fh, p);
1906 dbgarg(cmd,
1907 "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
1908 p->index, p->pixel_format,
1909 p->width, p->height, p->type);
1910 switch (p->type) {
1911 case V4L2_FRMIVAL_TYPE_DISCRETE:
1912 dbgarg2("fps=%d/%d\n",
1913 p->discrete.numerator,
1914 p->discrete.denominator);
1915 break;
1916 case V4L2_FRMIVAL_TYPE_STEPWISE:
Mauro Carvalho Chehab19585782008-11-12 01:03:02 -03001917 dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
1918 p->stepwise.min.numerator,
1919 p->stepwise.min.denominator,
1920 p->stepwise.max.numerator,
1921 p->stepwise.max.denominator,
1922 p->stepwise.step.numerator,
1923 p->stepwise.step.denominator);
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001924 break;
1925 case V4L2_FRMIVAL_TYPE_CONTINUOUS:
1926 dbgarg2("continuous\n");
1927 break;
1928 default:
1929 dbgarg2("- Unknown type!\n");
1930 }
1931 break;
1932 }
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001933 case VIDIOC_ENUM_DV_PRESETS:
1934 {
1935 struct v4l2_dv_enum_preset *p = arg;
1936
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001937 ret = ops->vidioc_enum_dv_presets(file, fh, p);
1938 if (!ret)
1939 dbgarg(cmd,
1940 "index=%d, preset=%d, name=%s, width=%d,"
1941 " height=%d ",
1942 p->index, p->preset, p->name, p->width,
1943 p->height);
1944 break;
1945 }
1946 case VIDIOC_S_DV_PRESET:
1947 {
1948 struct v4l2_dv_preset *p = arg;
1949
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001950 dbgarg(cmd, "preset=%d\n", p->preset);
1951 ret = ops->vidioc_s_dv_preset(file, fh, p);
1952 break;
1953 }
1954 case VIDIOC_G_DV_PRESET:
1955 {
1956 struct v4l2_dv_preset *p = arg;
1957
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001958 ret = ops->vidioc_g_dv_preset(file, fh, p);
1959 if (!ret)
1960 dbgarg(cmd, "preset=%d\n", p->preset);
1961 break;
1962 }
1963 case VIDIOC_QUERY_DV_PRESET:
1964 {
1965 struct v4l2_dv_preset *p = arg;
1966
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001967 ret = ops->vidioc_query_dv_preset(file, fh, p);
1968 if (!ret)
1969 dbgarg(cmd, "preset=%d\n", p->preset);
1970 break;
1971 }
1972 case VIDIOC_S_DV_TIMINGS:
1973 {
1974 struct v4l2_dv_timings *p = arg;
1975
Hans Verkuil5d7758e2012-05-15 08:06:44 -03001976 dbgtimings(vfd, p);
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001977 switch (p->type) {
1978 case V4L2_DV_BT_656_1120:
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001979 ret = ops->vidioc_s_dv_timings(file, fh, p);
1980 break;
1981 default:
Hans Verkuil5d7758e2012-05-15 08:06:44 -03001982 ret = -EINVAL;
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001983 break;
1984 }
1985 break;
1986 }
1987 case VIDIOC_G_DV_TIMINGS:
1988 {
1989 struct v4l2_dv_timings *p = arg;
1990
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001991 ret = ops->vidioc_g_dv_timings(file, fh, p);
Hans Verkuil5d7758e2012-05-15 08:06:44 -03001992 if (!ret)
1993 dbgtimings(vfd, p);
1994 break;
1995 }
1996 case VIDIOC_ENUM_DV_TIMINGS:
1997 {
1998 struct v4l2_enum_dv_timings *p = arg;
1999
2000 if (!ops->vidioc_enum_dv_timings)
2001 break;
2002
2003 ret = ops->vidioc_enum_dv_timings(file, fh, p);
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03002004 if (!ret) {
Hans Verkuil5d7758e2012-05-15 08:06:44 -03002005 dbgarg(cmd, "index=%d: ", p->index);
2006 dbgtimings(vfd, &p->timings);
2007 }
2008 break;
2009 }
2010 case VIDIOC_QUERY_DV_TIMINGS:
2011 {
2012 struct v4l2_dv_timings *p = arg;
2013
2014 if (!ops->vidioc_query_dv_timings)
2015 break;
2016
2017 ret = ops->vidioc_query_dv_timings(file, fh, p);
2018 if (!ret)
2019 dbgtimings(vfd, p);
2020 break;
2021 }
2022 case VIDIOC_DV_TIMINGS_CAP:
2023 {
2024 struct v4l2_dv_timings_cap *p = arg;
2025
2026 if (!ops->vidioc_dv_timings_cap)
2027 break;
2028
2029 ret = ops->vidioc_dv_timings_cap(file, fh, p);
2030 if (ret)
2031 break;
2032 switch (p->type) {
2033 case V4L2_DV_BT_656_1120:
2034 dbgarg(cmd,
2035 "type=%d, width=%u-%u, height=%u-%u, "
2036 "pixelclock=%llu-%llu, standards=%x, capabilities=%x ",
2037 p->type,
2038 p->bt.min_width, p->bt.max_width,
2039 p->bt.min_height, p->bt.max_height,
2040 p->bt.min_pixelclock, p->bt.max_pixelclock,
2041 p->bt.standards, p->bt.capabilities);
2042 break;
2043 default:
2044 dbgarg(cmd, "unknown type ");
2045 break;
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03002046 }
2047 break;
2048 }
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002049 case VIDIOC_DQEVENT:
2050 {
2051 struct v4l2_event *ev = arg;
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03002052
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002053 ret = v4l2_event_dequeue(fh, ev, file->f_flags & O_NONBLOCK);
2054 if (ret < 0) {
2055 dbgarg(cmd, "no pending events?");
2056 break;
2057 }
2058 dbgarg(cmd,
2059 "pending=%d, type=0x%8.8x, sequence=%d, "
2060 "timestamp=%lu.%9.9lu ",
2061 ev->pending, ev->type, ev->sequence,
2062 ev->timestamp.tv_sec, ev->timestamp.tv_nsec);
2063 break;
2064 }
2065 case VIDIOC_SUBSCRIBE_EVENT:
2066 {
2067 struct v4l2_event_subscription *sub = arg;
2068
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002069 ret = ops->vidioc_subscribe_event(fh, sub);
2070 if (ret < 0) {
2071 dbgarg(cmd, "failed, ret=%ld", ret);
2072 break;
2073 }
2074 dbgarg(cmd, "type=0x%8.8x", sub->type);
2075 break;
2076 }
2077 case VIDIOC_UNSUBSCRIBE_EVENT:
2078 {
2079 struct v4l2_event_subscription *sub = arg;
2080
Sakari Ailusd3d7c962010-03-27 11:02:10 -03002081 ret = ops->vidioc_unsubscribe_event(fh, sub);
2082 if (ret < 0) {
2083 dbgarg(cmd, "failed, ret=%ld", ret);
2084 break;
2085 }
2086 dbgarg(cmd, "type=0x%8.8x", sub->type);
2087 break;
2088 }
Hans Verkuila3998102008-07-21 02:57:38 -03002089 default:
Hans Verkuila3998102008-07-21 02:57:38 -03002090 if (!ops->vidioc_default)
2091 break;
Hans Verkuil4b902fe2012-05-10 05:40:50 -03002092 ret = ops->vidioc_default(file, fh, use_fh_prio ?
2093 v4l2_prio_check(vfd->prio, vfh->prio) >= 0 : 0,
2094 cmd, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002095 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002096 } /* switch */
2097
Hans Verkuil86748f32012-06-22 06:04:16 -03002098done:
2099 if (vfd->debug) {
2100 if (write_only && vfd->debug > V4L2_DEBUG_IOCTL) {
2101 if (ret < 0)
2102 printk(KERN_DEBUG "%s: error %ld\n",
2103 video_device_node_name(vfd), ret);
2104 return ret;
2105 }
2106 v4l_print_ioctl(vfd->name, cmd);
2107 if (ret < 0)
2108 pr_cont(": error %ld\n", ret);
2109 else if (vfd->debug == V4L2_DEBUG_IOCTL)
2110 pr_cont("\n");
2111 else if (!info->debug)
2112 return ret;
2113 else if (_IOC_DIR(cmd) == _IOC_NONE)
2114 info->debug(arg, write_only);
2115 else {
2116 pr_cont(": ");
2117 info->debug(arg, write_only);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002118 }
2119 }
2120
2121 return ret;
2122}
2123
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002124static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
2125 void * __user *user_ptr, void ***kernel_ptr)
2126{
2127 int ret = 0;
2128
2129 switch (cmd) {
2130 case VIDIOC_QUERYBUF:
2131 case VIDIOC_QBUF:
2132 case VIDIOC_DQBUF: {
2133 struct v4l2_buffer *buf = parg;
2134
2135 if (V4L2_TYPE_IS_MULTIPLANAR(buf->type) && buf->length > 0) {
2136 if (buf->length > VIDEO_MAX_PLANES) {
2137 ret = -EINVAL;
2138 break;
2139 }
2140 *user_ptr = (void __user *)buf->m.planes;
Hans Petter Selasky2ef40372011-05-23 08:13:06 -03002141 *kernel_ptr = (void *)&buf->m.planes;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002142 *array_size = sizeof(struct v4l2_plane) * buf->length;
2143 ret = 1;
2144 }
2145 break;
2146 }
2147
2148 case VIDIOC_S_EXT_CTRLS:
2149 case VIDIOC_G_EXT_CTRLS:
2150 case VIDIOC_TRY_EXT_CTRLS: {
2151 struct v4l2_ext_controls *ctrls = parg;
2152
2153 if (ctrls->count != 0) {
Dan Carpenter6c061082012-01-05 02:27:57 -03002154 if (ctrls->count > V4L2_CID_MAX_CTRLS) {
2155 ret = -EINVAL;
2156 break;
2157 }
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002158 *user_ptr = (void __user *)ctrls->controls;
Hans Petter Selasky2ef40372011-05-23 08:13:06 -03002159 *kernel_ptr = (void *)&ctrls->controls;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002160 *array_size = sizeof(struct v4l2_ext_control)
2161 * ctrls->count;
2162 ret = 1;
2163 }
2164 break;
2165 }
2166 }
2167
2168 return ret;
2169}
2170
Laurent Pinchartfc0a8072010-07-12 11:09:41 -03002171long
2172video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
2173 v4l2_kioctl func)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002174{
2175 char sbuf[128];
2176 void *mbuf = NULL;
Hans Verkuil1d94aa32010-04-06 08:12:21 -03002177 void *parg = (void *)arg;
Hans Verkuil069b7472008-12-30 07:04:34 -03002178 long err = -EINVAL;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002179 bool has_array_args;
2180 size_t array_size = 0;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002181 void __user *user_ptr = NULL;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002182 void **kernel_ptr = NULL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002183
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002184 /* Copy arguments into temp kernel buffer */
Trent Piepho337f9d22009-03-04 01:21:02 -03002185 if (_IOC_DIR(cmd) != _IOC_NONE) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002186 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
2187 parg = sbuf;
2188 } else {
2189 /* too big to allocate from stack */
2190 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
2191 if (NULL == mbuf)
2192 return -ENOMEM;
2193 parg = mbuf;
2194 }
2195
2196 err = -EFAULT;
Trent Piepho19c96e42009-03-04 01:21:02 -03002197 if (_IOC_DIR(cmd) & _IOC_WRITE) {
Hans Verkuil27cd2ab2012-06-09 08:55:31 -03002198 unsigned int n = _IOC_SIZE(cmd);
2199
2200 /*
2201 * In some cases, only a few fields are used as input,
2202 * i.e. when the app sets "index" and then the driver
2203 * fills in the rest of the structure for the thing
2204 * with that index. We only need to copy up the first
2205 * non-input field.
2206 */
2207 if (v4l2_is_known_ioctl(cmd)) {
2208 u32 flags = v4l2_ioctls[_IOC_NR(cmd)].flags;
2209 if (flags & INFO_FL_CLEAR_MASK)
2210 n = (flags & INFO_FL_CLEAR_MASK) >> 16;
2211 }
Trent Piepho19c96e42009-03-04 01:21:02 -03002212
2213 if (copy_from_user(parg, (void __user *)arg, n))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002214 goto out;
Trent Piepho19c96e42009-03-04 01:21:02 -03002215
2216 /* zero out anything we don't copy from userspace */
2217 if (n < _IOC_SIZE(cmd))
2218 memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n);
Trent Piepho337f9d22009-03-04 01:21:02 -03002219 } else {
2220 /* read-only ioctl */
2221 memset(parg, 0, _IOC_SIZE(cmd));
Trent Piepho19c96e42009-03-04 01:21:02 -03002222 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002223 }
2224
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002225 err = check_array_args(cmd, parg, &array_size, &user_ptr, &kernel_ptr);
2226 if (err < 0)
2227 goto out;
2228 has_array_args = err;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002229
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002230 if (has_array_args) {
2231 /*
2232 * When adding new types of array args, make sure that the
2233 * parent argument to ioctl (which contains the pointer to the
2234 * array) fits into sbuf (so that mbuf will still remain
2235 * unused up to here).
2236 */
2237 mbuf = kmalloc(array_size, GFP_KERNEL);
2238 err = -ENOMEM;
2239 if (NULL == mbuf)
2240 goto out_array_args;
2241 err = -EFAULT;
2242 if (copy_from_user(mbuf, user_ptr, array_size))
2243 goto out_array_args;
2244 *kernel_ptr = mbuf;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002245 }
2246
2247 /* Handles IOCTL */
Laurent Pinchartfc0a8072010-07-12 11:09:41 -03002248 err = func(file, cmd, parg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002249 if (err == -ENOIOCTLCMD)
Hans Verkuil02bbb812012-02-08 08:09:36 -03002250 err = -ENOTTY;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002251
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002252 if (has_array_args) {
2253 *kernel_ptr = user_ptr;
2254 if (copy_to_user(user_ptr, mbuf, array_size))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002255 err = -EFAULT;
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002256 goto out_array_args;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002257 }
Hans Verkuil5d7758e2012-05-15 08:06:44 -03002258 /* VIDIOC_QUERY_DV_TIMINGS can return an error, but still have valid
2259 results that must be returned. */
2260 if (err < 0 && cmd != VIDIOC_QUERY_DV_TIMINGS)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002261 goto out;
2262
Pawel Osciakd14e6d72010-12-23 04:15:27 -03002263out_array_args:
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002264 /* Copy results into user buffer */
2265 switch (_IOC_DIR(cmd)) {
2266 case _IOC_READ:
2267 case (_IOC_WRITE | _IOC_READ):
2268 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
2269 err = -EFAULT;
2270 break;
2271 }
2272
2273out:
2274 kfree(mbuf);
2275 return err;
2276}
Laurent Pinchartfc0a8072010-07-12 11:09:41 -03002277EXPORT_SYMBOL(video_usercopy);
2278
2279long video_ioctl2(struct file *file,
2280 unsigned int cmd, unsigned long arg)
2281{
2282 return video_usercopy(file, cmd, arg, __video_do_ioctl);
2283}
Mauro Carvalho Chehab8a522c92008-10-21 11:58:39 -03002284EXPORT_SYMBOL(video_ioctl2);