blob: dd9283fcb5643584d44628d447ec0791b86654a9 [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>
19
20#define __OLD_VIDIOC_ /* To allow fixing old calls */
Mauro Carvalho Chehab7e0a16f2009-03-10 05:31:34 -030021#include <linux/videodev.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030022#include <linux/videodev2.h>
23
24#ifdef CONFIG_VIDEO_V4L1
25#include <linux/videodev.h>
26#endif
27#include <media/v4l2-common.h>
28#include <media/v4l2-ioctl.h>
Hans Verkuil11bbc1c2010-05-16 09:24:06 -030029#include <media/v4l2-ctrls.h>
Sakari Ailusd3d7c962010-03-27 11:02:10 -030030#include <media/v4l2-fh.h>
31#include <media/v4l2-event.h>
Hans Verkuil80b36e02009-02-07 11:00:02 -030032#include <media/v4l2-chip-ident.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030033
34#define dbgarg(cmd, fmt, arg...) \
35 do { \
36 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \
37 printk(KERN_DEBUG "%s: ", vfd->name); \
38 v4l_printk_ioctl(cmd); \
39 printk(" " fmt, ## arg); \
40 } \
41 } while (0)
42
43#define dbgarg2(fmt, arg...) \
44 do { \
45 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
46 printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\
47 } while (0)
48
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -030049#define dbgarg3(fmt, arg...) \
50 do { \
51 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
52 printk(KERN_CONT "%s: " fmt, vfd->name, ## arg);\
53 } while (0)
54
Trent Piepho7ecc0cf2009-04-30 21:03:34 -030055/* Zero out the end of the struct pointed to by p. Everthing after, but
56 * not including, the specified field is cleared. */
57#define CLEAR_AFTER_FIELD(p, field) \
58 memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \
59 0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field))
60
Hans Verkuil35ea11f2008-07-20 08:12:02 -030061struct std_descr {
62 v4l2_std_id std;
63 const char *descr;
64};
65
66static const struct std_descr standards[] = {
67 { V4L2_STD_NTSC, "NTSC" },
68 { V4L2_STD_NTSC_M, "NTSC-M" },
69 { V4L2_STD_NTSC_M_JP, "NTSC-M-JP" },
70 { V4L2_STD_NTSC_M_KR, "NTSC-M-KR" },
71 { V4L2_STD_NTSC_443, "NTSC-443" },
72 { V4L2_STD_PAL, "PAL" },
73 { V4L2_STD_PAL_BG, "PAL-BG" },
74 { V4L2_STD_PAL_B, "PAL-B" },
75 { V4L2_STD_PAL_B1, "PAL-B1" },
76 { V4L2_STD_PAL_G, "PAL-G" },
77 { V4L2_STD_PAL_H, "PAL-H" },
78 { V4L2_STD_PAL_I, "PAL-I" },
79 { V4L2_STD_PAL_DK, "PAL-DK" },
80 { V4L2_STD_PAL_D, "PAL-D" },
81 { V4L2_STD_PAL_D1, "PAL-D1" },
82 { V4L2_STD_PAL_K, "PAL-K" },
83 { V4L2_STD_PAL_M, "PAL-M" },
84 { V4L2_STD_PAL_N, "PAL-N" },
85 { V4L2_STD_PAL_Nc, "PAL-Nc" },
86 { V4L2_STD_PAL_60, "PAL-60" },
87 { V4L2_STD_SECAM, "SECAM" },
88 { V4L2_STD_SECAM_B, "SECAM-B" },
89 { V4L2_STD_SECAM_G, "SECAM-G" },
90 { V4L2_STD_SECAM_H, "SECAM-H" },
91 { V4L2_STD_SECAM_DK, "SECAM-DK" },
92 { V4L2_STD_SECAM_D, "SECAM-D" },
93 { V4L2_STD_SECAM_K, "SECAM-K" },
94 { V4L2_STD_SECAM_K1, "SECAM-K1" },
95 { V4L2_STD_SECAM_L, "SECAM-L" },
96 { V4L2_STD_SECAM_LC, "SECAM-Lc" },
97 { 0, "Unknown" }
98};
99
100/* video4linux standard ID conversion to standard name
101 */
102const char *v4l2_norm_to_name(v4l2_std_id id)
103{
104 u32 myid = id;
105 int i;
106
107 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
108 64 bit comparations. So, on that architecture, with some gcc
109 variants, compilation fails. Currently, the max value is 30bit wide.
110 */
111 BUG_ON(myid != id);
112
113 for (i = 0; standards[i].std; i++)
114 if (myid == standards[i].std)
115 break;
116 return standards[i].descr;
117}
118EXPORT_SYMBOL(v4l2_norm_to_name);
119
Trent Piepho51f0b8d52009-03-04 01:21:02 -0300120/* Returns frame period for the given standard */
121void v4l2_video_std_frame_period(int id, struct v4l2_fract *frameperiod)
122{
123 if (id & V4L2_STD_525_60) {
124 frameperiod->numerator = 1001;
125 frameperiod->denominator = 30000;
126 } else {
127 frameperiod->numerator = 1;
128 frameperiod->denominator = 25;
129 }
130}
131EXPORT_SYMBOL(v4l2_video_std_frame_period);
132
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300133/* Fill in the fields of a v4l2_standard structure according to the
134 'id' and 'transmission' parameters. Returns negative on error. */
135int v4l2_video_std_construct(struct v4l2_standard *vs,
136 int id, const char *name)
137{
Trent Piepho51f0b8d52009-03-04 01:21:02 -0300138 vs->id = id;
139 v4l2_video_std_frame_period(id, &vs->frameperiod);
140 vs->framelines = (id & V4L2_STD_525_60) ? 525 : 625;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300141 strlcpy(vs->name, name, sizeof(vs->name));
142 return 0;
143}
144EXPORT_SYMBOL(v4l2_video_std_construct);
145
146/* ----------------------------------------------------------------- */
147/* some arrays for pretty-printing debug messages of enum types */
148
149const char *v4l2_field_names[] = {
150 [V4L2_FIELD_ANY] = "any",
151 [V4L2_FIELD_NONE] = "none",
152 [V4L2_FIELD_TOP] = "top",
153 [V4L2_FIELD_BOTTOM] = "bottom",
154 [V4L2_FIELD_INTERLACED] = "interlaced",
155 [V4L2_FIELD_SEQ_TB] = "seq-tb",
156 [V4L2_FIELD_SEQ_BT] = "seq-bt",
157 [V4L2_FIELD_ALTERNATE] = "alternate",
158 [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
159 [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
160};
161EXPORT_SYMBOL(v4l2_field_names);
162
163const char *v4l2_type_names[] = {
164 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "vid-cap",
165 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "vid-overlay",
166 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "vid-out",
167 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
168 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
169 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
170 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out",
171 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "vid-out-overlay",
172};
173EXPORT_SYMBOL(v4l2_type_names);
174
175static const char *v4l2_memory_names[] = {
176 [V4L2_MEMORY_MMAP] = "mmap",
177 [V4L2_MEMORY_USERPTR] = "userptr",
178 [V4L2_MEMORY_OVERLAY] = "overlay",
179};
180
181#define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
182 arr[a] : "unknown")
183
184/* ------------------------------------------------------------------ */
185/* debug help functions */
186
187#ifdef CONFIG_VIDEO_V4L1_COMPAT
188static const char *v4l1_ioctls[] = {
189 [_IOC_NR(VIDIOCGCAP)] = "VIDIOCGCAP",
190 [_IOC_NR(VIDIOCGCHAN)] = "VIDIOCGCHAN",
191 [_IOC_NR(VIDIOCSCHAN)] = "VIDIOCSCHAN",
192 [_IOC_NR(VIDIOCGTUNER)] = "VIDIOCGTUNER",
193 [_IOC_NR(VIDIOCSTUNER)] = "VIDIOCSTUNER",
194 [_IOC_NR(VIDIOCGPICT)] = "VIDIOCGPICT",
195 [_IOC_NR(VIDIOCSPICT)] = "VIDIOCSPICT",
196 [_IOC_NR(VIDIOCCAPTURE)] = "VIDIOCCAPTURE",
197 [_IOC_NR(VIDIOCGWIN)] = "VIDIOCGWIN",
198 [_IOC_NR(VIDIOCSWIN)] = "VIDIOCSWIN",
199 [_IOC_NR(VIDIOCGFBUF)] = "VIDIOCGFBUF",
200 [_IOC_NR(VIDIOCSFBUF)] = "VIDIOCSFBUF",
201 [_IOC_NR(VIDIOCKEY)] = "VIDIOCKEY",
202 [_IOC_NR(VIDIOCGFREQ)] = "VIDIOCGFREQ",
203 [_IOC_NR(VIDIOCSFREQ)] = "VIDIOCSFREQ",
204 [_IOC_NR(VIDIOCGAUDIO)] = "VIDIOCGAUDIO",
205 [_IOC_NR(VIDIOCSAUDIO)] = "VIDIOCSAUDIO",
206 [_IOC_NR(VIDIOCSYNC)] = "VIDIOCSYNC",
207 [_IOC_NR(VIDIOCMCAPTURE)] = "VIDIOCMCAPTURE",
208 [_IOC_NR(VIDIOCGMBUF)] = "VIDIOCGMBUF",
209 [_IOC_NR(VIDIOCGUNIT)] = "VIDIOCGUNIT",
210 [_IOC_NR(VIDIOCGCAPTURE)] = "VIDIOCGCAPTURE",
211 [_IOC_NR(VIDIOCSCAPTURE)] = "VIDIOCSCAPTURE",
212 [_IOC_NR(VIDIOCSPLAYMODE)] = "VIDIOCSPLAYMODE",
213 [_IOC_NR(VIDIOCSWRITEMODE)] = "VIDIOCSWRITEMODE",
214 [_IOC_NR(VIDIOCGPLAYINFO)] = "VIDIOCGPLAYINFO",
215 [_IOC_NR(VIDIOCSMICROCODE)] = "VIDIOCSMICROCODE",
216 [_IOC_NR(VIDIOCGVBIFMT)] = "VIDIOCGVBIFMT",
217 [_IOC_NR(VIDIOCSVBIFMT)] = "VIDIOCSVBIFMT"
218};
219#define V4L1_IOCTLS ARRAY_SIZE(v4l1_ioctls)
220#endif
221
222static const char *v4l2_ioctls[] = {
223 [_IOC_NR(VIDIOC_QUERYCAP)] = "VIDIOC_QUERYCAP",
224 [_IOC_NR(VIDIOC_RESERVED)] = "VIDIOC_RESERVED",
225 [_IOC_NR(VIDIOC_ENUM_FMT)] = "VIDIOC_ENUM_FMT",
226 [_IOC_NR(VIDIOC_G_FMT)] = "VIDIOC_G_FMT",
227 [_IOC_NR(VIDIOC_S_FMT)] = "VIDIOC_S_FMT",
228 [_IOC_NR(VIDIOC_REQBUFS)] = "VIDIOC_REQBUFS",
229 [_IOC_NR(VIDIOC_QUERYBUF)] = "VIDIOC_QUERYBUF",
230 [_IOC_NR(VIDIOC_G_FBUF)] = "VIDIOC_G_FBUF",
231 [_IOC_NR(VIDIOC_S_FBUF)] = "VIDIOC_S_FBUF",
232 [_IOC_NR(VIDIOC_OVERLAY)] = "VIDIOC_OVERLAY",
233 [_IOC_NR(VIDIOC_QBUF)] = "VIDIOC_QBUF",
234 [_IOC_NR(VIDIOC_DQBUF)] = "VIDIOC_DQBUF",
235 [_IOC_NR(VIDIOC_STREAMON)] = "VIDIOC_STREAMON",
236 [_IOC_NR(VIDIOC_STREAMOFF)] = "VIDIOC_STREAMOFF",
237 [_IOC_NR(VIDIOC_G_PARM)] = "VIDIOC_G_PARM",
238 [_IOC_NR(VIDIOC_S_PARM)] = "VIDIOC_S_PARM",
239 [_IOC_NR(VIDIOC_G_STD)] = "VIDIOC_G_STD",
240 [_IOC_NR(VIDIOC_S_STD)] = "VIDIOC_S_STD",
241 [_IOC_NR(VIDIOC_ENUMSTD)] = "VIDIOC_ENUMSTD",
242 [_IOC_NR(VIDIOC_ENUMINPUT)] = "VIDIOC_ENUMINPUT",
243 [_IOC_NR(VIDIOC_G_CTRL)] = "VIDIOC_G_CTRL",
244 [_IOC_NR(VIDIOC_S_CTRL)] = "VIDIOC_S_CTRL",
245 [_IOC_NR(VIDIOC_G_TUNER)] = "VIDIOC_G_TUNER",
246 [_IOC_NR(VIDIOC_S_TUNER)] = "VIDIOC_S_TUNER",
247 [_IOC_NR(VIDIOC_G_AUDIO)] = "VIDIOC_G_AUDIO",
248 [_IOC_NR(VIDIOC_S_AUDIO)] = "VIDIOC_S_AUDIO",
249 [_IOC_NR(VIDIOC_QUERYCTRL)] = "VIDIOC_QUERYCTRL",
250 [_IOC_NR(VIDIOC_QUERYMENU)] = "VIDIOC_QUERYMENU",
251 [_IOC_NR(VIDIOC_G_INPUT)] = "VIDIOC_G_INPUT",
252 [_IOC_NR(VIDIOC_S_INPUT)] = "VIDIOC_S_INPUT",
253 [_IOC_NR(VIDIOC_G_OUTPUT)] = "VIDIOC_G_OUTPUT",
254 [_IOC_NR(VIDIOC_S_OUTPUT)] = "VIDIOC_S_OUTPUT",
255 [_IOC_NR(VIDIOC_ENUMOUTPUT)] = "VIDIOC_ENUMOUTPUT",
256 [_IOC_NR(VIDIOC_G_AUDOUT)] = "VIDIOC_G_AUDOUT",
257 [_IOC_NR(VIDIOC_S_AUDOUT)] = "VIDIOC_S_AUDOUT",
258 [_IOC_NR(VIDIOC_G_MODULATOR)] = "VIDIOC_G_MODULATOR",
259 [_IOC_NR(VIDIOC_S_MODULATOR)] = "VIDIOC_S_MODULATOR",
260 [_IOC_NR(VIDIOC_G_FREQUENCY)] = "VIDIOC_G_FREQUENCY",
261 [_IOC_NR(VIDIOC_S_FREQUENCY)] = "VIDIOC_S_FREQUENCY",
262 [_IOC_NR(VIDIOC_CROPCAP)] = "VIDIOC_CROPCAP",
263 [_IOC_NR(VIDIOC_G_CROP)] = "VIDIOC_G_CROP",
264 [_IOC_NR(VIDIOC_S_CROP)] = "VIDIOC_S_CROP",
265 [_IOC_NR(VIDIOC_G_JPEGCOMP)] = "VIDIOC_G_JPEGCOMP",
266 [_IOC_NR(VIDIOC_S_JPEGCOMP)] = "VIDIOC_S_JPEGCOMP",
267 [_IOC_NR(VIDIOC_QUERYSTD)] = "VIDIOC_QUERYSTD",
268 [_IOC_NR(VIDIOC_TRY_FMT)] = "VIDIOC_TRY_FMT",
269 [_IOC_NR(VIDIOC_ENUMAUDIO)] = "VIDIOC_ENUMAUDIO",
270 [_IOC_NR(VIDIOC_ENUMAUDOUT)] = "VIDIOC_ENUMAUDOUT",
271 [_IOC_NR(VIDIOC_G_PRIORITY)] = "VIDIOC_G_PRIORITY",
272 [_IOC_NR(VIDIOC_S_PRIORITY)] = "VIDIOC_S_PRIORITY",
273 [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP)] = "VIDIOC_G_SLICED_VBI_CAP",
274 [_IOC_NR(VIDIOC_LOG_STATUS)] = "VIDIOC_LOG_STATUS",
275 [_IOC_NR(VIDIOC_G_EXT_CTRLS)] = "VIDIOC_G_EXT_CTRLS",
276 [_IOC_NR(VIDIOC_S_EXT_CTRLS)] = "VIDIOC_S_EXT_CTRLS",
277 [_IOC_NR(VIDIOC_TRY_EXT_CTRLS)] = "VIDIOC_TRY_EXT_CTRLS",
278#if 1
279 [_IOC_NR(VIDIOC_ENUM_FRAMESIZES)] = "VIDIOC_ENUM_FRAMESIZES",
280 [_IOC_NR(VIDIOC_ENUM_FRAMEINTERVALS)] = "VIDIOC_ENUM_FRAMEINTERVALS",
281 [_IOC_NR(VIDIOC_G_ENC_INDEX)] = "VIDIOC_G_ENC_INDEX",
282 [_IOC_NR(VIDIOC_ENCODER_CMD)] = "VIDIOC_ENCODER_CMD",
283 [_IOC_NR(VIDIOC_TRY_ENCODER_CMD)] = "VIDIOC_TRY_ENCODER_CMD",
284
285 [_IOC_NR(VIDIOC_DBG_S_REGISTER)] = "VIDIOC_DBG_S_REGISTER",
286 [_IOC_NR(VIDIOC_DBG_G_REGISTER)] = "VIDIOC_DBG_G_REGISTER",
287
Hans Verkuilaecde8b52008-12-30 07:14:19 -0300288 [_IOC_NR(VIDIOC_DBG_G_CHIP_IDENT)] = "VIDIOC_DBG_G_CHIP_IDENT",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300289 [_IOC_NR(VIDIOC_S_HW_FREQ_SEEK)] = "VIDIOC_S_HW_FREQ_SEEK",
290#endif
Muralidharan Karicherib6456c02009-11-19 12:00:31 -0300291 [_IOC_NR(VIDIOC_ENUM_DV_PRESETS)] = "VIDIOC_ENUM_DV_PRESETS",
292 [_IOC_NR(VIDIOC_S_DV_PRESET)] = "VIDIOC_S_DV_PRESET",
293 [_IOC_NR(VIDIOC_G_DV_PRESET)] = "VIDIOC_G_DV_PRESET",
294 [_IOC_NR(VIDIOC_QUERY_DV_PRESET)] = "VIDIOC_QUERY_DV_PRESET",
295 [_IOC_NR(VIDIOC_S_DV_TIMINGS)] = "VIDIOC_S_DV_TIMINGS",
296 [_IOC_NR(VIDIOC_G_DV_TIMINGS)] = "VIDIOC_G_DV_TIMINGS",
Sakari Ailusfda10212010-02-24 19:19:05 -0300297 [_IOC_NR(VIDIOC_DQEVENT)] = "VIDIOC_DQEVENT",
298 [_IOC_NR(VIDIOC_SUBSCRIBE_EVENT)] = "VIDIOC_SUBSCRIBE_EVENT",
299 [_IOC_NR(VIDIOC_UNSUBSCRIBE_EVENT)] = "VIDIOC_UNSUBSCRIBE_EVENT",
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300300};
301#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
302
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300303/* Common ioctl debug function. This function can be used by
304 external ioctl messages as well as internal V4L ioctl */
305void v4l_printk_ioctl(unsigned int cmd)
306{
307 char *dir, *type;
308
309 switch (_IOC_TYPE(cmd)) {
310 case 'd':
Hans Verkuil78a3b4d2009-04-01 03:41:09 -0300311 type = "v4l2_int";
312 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300313#ifdef CONFIG_VIDEO_V4L1_COMPAT
314 case 'v':
315 if (_IOC_NR(cmd) >= V4L1_IOCTLS) {
316 type = "v4l1";
317 break;
318 }
319 printk("%s", v4l1_ioctls[_IOC_NR(cmd)]);
320 return;
321#endif
322 case 'V':
323 if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
324 type = "v4l2";
325 break;
326 }
327 printk("%s", v4l2_ioctls[_IOC_NR(cmd)]);
328 return;
329 default:
330 type = "unknown";
331 }
332
333 switch (_IOC_DIR(cmd)) {
334 case _IOC_NONE: dir = "--"; break;
335 case _IOC_READ: dir = "r-"; break;
336 case _IOC_WRITE: dir = "-w"; break;
337 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
338 default: dir = "*ERR*"; break;
339 }
340 printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
341 type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
342}
343EXPORT_SYMBOL(v4l_printk_ioctl);
344
345/*
346 * helper function -- handles userspace copying for ioctl arguments
347 */
348
349#ifdef __OLD_VIDIOC_
350static unsigned int
351video_fix_command(unsigned int cmd)
352{
353 switch (cmd) {
354 case VIDIOC_OVERLAY_OLD:
355 cmd = VIDIOC_OVERLAY;
356 break;
357 case VIDIOC_S_PARM_OLD:
358 cmd = VIDIOC_S_PARM;
359 break;
360 case VIDIOC_S_CTRL_OLD:
361 cmd = VIDIOC_S_CTRL;
362 break;
363 case VIDIOC_G_AUDIO_OLD:
364 cmd = VIDIOC_G_AUDIO;
365 break;
366 case VIDIOC_G_AUDOUT_OLD:
367 cmd = VIDIOC_G_AUDOUT;
368 break;
369 case VIDIOC_CROPCAP_OLD:
370 cmd = VIDIOC_CROPCAP;
371 break;
372 }
373 return cmd;
374}
375#endif
376
377/*
378 * Obsolete usercopy function - Should be removed soon
379 */
Hans Verkuil069b7472008-12-30 07:04:34 -0300380long
Hans Verkuilf473bf72008-11-01 08:25:11 -0300381video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
382 v4l2_kioctl func)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300383{
384 char sbuf[128];
385 void *mbuf = NULL;
386 void *parg = NULL;
Hans Verkuil069b7472008-12-30 07:04:34 -0300387 long err = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300388 int is_ext_ctrl;
389 size_t ctrls_size = 0;
390 void __user *user_ptr = NULL;
391
392#ifdef __OLD_VIDIOC_
393 cmd = video_fix_command(cmd);
394#endif
395 is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
396 cmd == VIDIOC_TRY_EXT_CTRLS);
397
398 /* Copy arguments into temp kernel buffer */
399 switch (_IOC_DIR(cmd)) {
400 case _IOC_NONE:
401 parg = NULL;
402 break;
403 case _IOC_READ:
404 case _IOC_WRITE:
405 case (_IOC_WRITE | _IOC_READ):
406 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
407 parg = sbuf;
408 } else {
409 /* too big to allocate from stack */
410 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
411 if (NULL == mbuf)
412 return -ENOMEM;
413 parg = mbuf;
414 }
415
416 err = -EFAULT;
417 if (_IOC_DIR(cmd) & _IOC_WRITE)
418 if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
419 goto out;
420 break;
421 }
422 if (is_ext_ctrl) {
423 struct v4l2_ext_controls *p = parg;
424
425 /* In case of an error, tell the caller that it wasn't
426 a specific control that caused it. */
427 p->error_idx = p->count;
428 user_ptr = (void __user *)p->controls;
429 if (p->count) {
430 ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
431 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
432 mbuf = kmalloc(ctrls_size, GFP_KERNEL);
433 err = -ENOMEM;
434 if (NULL == mbuf)
435 goto out_ext_ctrl;
436 err = -EFAULT;
437 if (copy_from_user(mbuf, user_ptr, ctrls_size))
438 goto out_ext_ctrl;
439 p->controls = mbuf;
440 }
441 }
442
443 /* call driver */
Hans Verkuilf473bf72008-11-01 08:25:11 -0300444 err = func(file, cmd, parg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300445 if (err == -ENOIOCTLCMD)
446 err = -EINVAL;
447 if (is_ext_ctrl) {
448 struct v4l2_ext_controls *p = parg;
449
450 p->controls = (void *)user_ptr;
451 if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
452 err = -EFAULT;
453 goto out_ext_ctrl;
454 }
455 if (err < 0)
456 goto out;
457
458out_ext_ctrl:
459 /* Copy results into user buffer */
460 switch (_IOC_DIR(cmd)) {
461 case _IOC_READ:
462 case (_IOC_WRITE | _IOC_READ):
463 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
464 err = -EFAULT;
465 break;
466 }
467
468out:
469 kfree(mbuf);
470 return err;
471}
472EXPORT_SYMBOL(video_usercopy);
473
474static void dbgbuf(unsigned int cmd, struct video_device *vfd,
475 struct v4l2_buffer *p)
476{
477 struct v4l2_timecode *tc = &p->timecode;
478
479 dbgarg(cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
480 "bytesused=%d, flags=0x%08d, "
481 "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx, length=%d\n",
482 p->timestamp.tv_sec / 3600,
483 (int)(p->timestamp.tv_sec / 60) % 60,
484 (int)(p->timestamp.tv_sec % 60),
Alexander Beregalovb0459792008-09-03 16:47:38 -0300485 (long)p->timestamp.tv_usec,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300486 p->index,
487 prt_names(p->type, v4l2_type_names),
488 p->bytesused, p->flags,
489 p->field, p->sequence,
490 prt_names(p->memory, v4l2_memory_names),
491 p->m.userptr, p->length);
492 dbgarg2("timecode=%02d:%02d:%02d type=%d, "
493 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
494 tc->hours, tc->minutes, tc->seconds,
495 tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits);
496}
497
498static inline void dbgrect(struct video_device *vfd, char *s,
499 struct v4l2_rect *r)
500{
501 dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s, r->left, r->top,
502 r->width, r->height);
503};
504
505static inline void v4l_print_pix_fmt(struct video_device *vfd,
506 struct v4l2_pix_format *fmt)
507{
508 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
509 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
510 fmt->width, fmt->height,
511 (fmt->pixelformat & 0xff),
512 (fmt->pixelformat >> 8) & 0xff,
513 (fmt->pixelformat >> 16) & 0xff,
514 (fmt->pixelformat >> 24) & 0xff,
515 prt_names(fmt->field, v4l2_field_names),
516 fmt->bytesperline, fmt->sizeimage, fmt->colorspace);
517};
518
519static inline void v4l_print_ext_ctrls(unsigned int cmd,
520 struct video_device *vfd, struct v4l2_ext_controls *c, int show_vals)
521{
522 __u32 i;
523
524 if (!(vfd->debug & V4L2_DEBUG_IOCTL_ARG))
525 return;
526 dbgarg(cmd, "");
527 printk(KERN_CONT "class=0x%x", c->ctrl_class);
528 for (i = 0; i < c->count; i++) {
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300529 if (show_vals && !c->controls[i].size)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300530 printk(KERN_CONT " id/val=0x%x/0x%x",
531 c->controls[i].id, c->controls[i].value);
532 else
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300533 printk(KERN_CONT " id=0x%x,size=%u",
534 c->controls[i].id, c->controls[i].size);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300535 }
536 printk(KERN_CONT "\n");
537};
538
539static inline int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
540{
541 __u32 i;
542
543 /* zero the reserved fields */
544 c->reserved[0] = c->reserved[1] = 0;
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300545 for (i = 0; i < c->count; i++)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300546 c->controls[i].reserved2[0] = 0;
Hans Verkuil6b5a9492009-08-11 18:47:18 -0300547
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300548 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
549 when using extended controls.
550 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
551 is it allowed for backwards compatibility.
552 */
553 if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE)
554 return 0;
555 /* Check that all controls are from the same control class. */
556 for (i = 0; i < c->count; i++) {
557 if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) {
558 c->error_idx = i;
559 return 0;
560 }
561 }
562 return 1;
563}
564
Hans Verkuila3998102008-07-21 02:57:38 -0300565static int check_fmt(const struct v4l2_ioctl_ops *ops, enum v4l2_buf_type type)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300566{
Hans Verkuila3998102008-07-21 02:57:38 -0300567 if (ops == NULL)
568 return -EINVAL;
569
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300570 switch (type) {
571 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Trent Piepho1175d612009-04-30 21:03:34 -0300572 if (ops->vidioc_g_fmt_vid_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300573 return 0;
574 break;
575 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho1175d612009-04-30 21:03:34 -0300576 if (ops->vidioc_g_fmt_vid_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300577 return 0;
578 break;
579 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Trent Piepho1175d612009-04-30 21:03:34 -0300580 if (ops->vidioc_g_fmt_vid_out)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300581 return 0;
582 break;
583 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho1175d612009-04-30 21:03:34 -0300584 if (ops->vidioc_g_fmt_vid_out_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300585 return 0;
586 break;
587 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho1175d612009-04-30 21:03:34 -0300588 if (ops->vidioc_g_fmt_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300589 return 0;
590 break;
591 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho1175d612009-04-30 21:03:34 -0300592 if (ops->vidioc_g_fmt_vbi_out)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300593 return 0;
594 break;
595 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho1175d612009-04-30 21:03:34 -0300596 if (ops->vidioc_g_fmt_sliced_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300597 return 0;
598 break;
599 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho1175d612009-04-30 21:03:34 -0300600 if (ops->vidioc_g_fmt_sliced_vbi_out)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300601 return 0;
602 break;
603 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho1175d612009-04-30 21:03:34 -0300604 if (ops->vidioc_g_fmt_type_private)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300605 return 0;
606 break;
607 }
608 return -EINVAL;
609}
610
Hans Verkuil069b7472008-12-30 07:04:34 -0300611static long __video_do_ioctl(struct file *file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300612 unsigned int cmd, void *arg)
613{
614 struct video_device *vfd = video_devdata(file);
Hans Verkuila3998102008-07-21 02:57:38 -0300615 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
Hans Verkuild5fbf322008-10-18 13:39:53 -0300616 void *fh = file->private_data;
Hans Verkuil069b7472008-12-30 07:04:34 -0300617 long ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300618
Hans Verkuil6a717882010-04-06 15:56:08 -0300619 if (ops == NULL) {
620 printk(KERN_WARNING "videodev: \"%s\" has no ioctl_ops.\n",
621 vfd->name);
622 return -EINVAL;
623 }
624
625#ifdef CONFIG_VIDEO_V4L1_COMPAT
626 /********************************************************
627 All other V4L1 calls are handled by v4l1_compat module.
628 Those calls will be translated into V4L2 calls, and
629 __video_do_ioctl will be called again, with one or more
630 V4L2 ioctls.
631 ********************************************************/
632 if (_IOC_TYPE(cmd) == 'v' && cmd != VIDIOCGMBUF &&
633 _IOC_NR(cmd) < BASE_VIDIOCPRIVATE) {
634 return v4l_compat_translate_ioctl(file, cmd, arg,
635 __video_do_ioctl);
636 }
637#endif
638
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300639 if ((vfd->debug & V4L2_DEBUG_IOCTL) &&
640 !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
641 v4l_print_ioctl(vfd->name, cmd);
642 printk(KERN_CONT "\n");
643 }
644
Hans Verkuil6a717882010-04-06 15:56:08 -0300645 switch (cmd) {
Hans Verkuila3998102008-07-21 02:57:38 -0300646
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300647#ifdef CONFIG_VIDEO_V4L1_COMPAT
648 /***********************************************************
649 Handles calls to the obsoleted V4L1 API
650 Due to the nature of VIDIOCGMBUF, each driver that supports
651 V4L1 should implement its own handler for this ioctl.
652 ***********************************************************/
653
654 /* --- streaming capture ------------------------------------- */
Hans Verkuil6a717882010-04-06 15:56:08 -0300655 case VIDIOCGMBUF:
656 {
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300657 struct video_mbuf *p = arg;
658
Hans Verkuila3998102008-07-21 02:57:38 -0300659 if (!ops->vidiocgmbuf)
Hans Verkuil6a717882010-04-06 15:56:08 -0300660 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300661 ret = ops->vidiocgmbuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300662 if (!ret)
663 dbgarg(cmd, "size=%d, frames=%d, offsets=0x%08lx\n",
664 p->size, p->frames,
665 (unsigned long)p->offsets);
Hans Verkuil6a717882010-04-06 15:56:08 -0300666 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300667 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300668#endif
669
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300670 /* --- capabilities ------------------------------------------ */
671 case VIDIOC_QUERYCAP:
672 {
673 struct v4l2_capability *cap = (struct v4l2_capability *)arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300674
Hans Verkuila3998102008-07-21 02:57:38 -0300675 if (!ops->vidioc_querycap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300676 break;
677
Hans Verkuila3998102008-07-21 02:57:38 -0300678 ret = ops->vidioc_querycap(file, fh, cap);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300679 if (!ret)
680 dbgarg(cmd, "driver=%s, card=%s, bus=%s, "
681 "version=0x%08x, "
682 "capabilities=0x%08x\n",
683 cap->driver, cap->card, cap->bus_info,
684 cap->version,
685 cap->capabilities);
686 break;
687 }
688
689 /* --- priority ------------------------------------------ */
690 case VIDIOC_G_PRIORITY:
691 {
692 enum v4l2_priority *p = arg;
693
Hans Verkuila3998102008-07-21 02:57:38 -0300694 if (!ops->vidioc_g_priority)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300695 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300696 ret = ops->vidioc_g_priority(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300697 if (!ret)
698 dbgarg(cmd, "priority is %d\n", *p);
699 break;
700 }
701 case VIDIOC_S_PRIORITY:
702 {
703 enum v4l2_priority *p = arg;
704
Hans Verkuila3998102008-07-21 02:57:38 -0300705 if (!ops->vidioc_s_priority)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300706 break;
707 dbgarg(cmd, "setting priority to %d\n", *p);
Hans Verkuila3998102008-07-21 02:57:38 -0300708 ret = ops->vidioc_s_priority(file, fh, *p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300709 break;
710 }
711
712 /* --- capture ioctls ---------------------------------------- */
713 case VIDIOC_ENUM_FMT:
714 {
715 struct v4l2_fmtdesc *f = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300716
Trent Piepho19c96e42009-03-04 01:21:02 -0300717 switch (f->type) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300718 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Hans Verkuila3998102008-07-21 02:57:38 -0300719 if (ops->vidioc_enum_fmt_vid_cap)
720 ret = ops->vidioc_enum_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300721 break;
722 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Hans Verkuila3998102008-07-21 02:57:38 -0300723 if (ops->vidioc_enum_fmt_vid_overlay)
724 ret = ops->vidioc_enum_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300725 fh, f);
726 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300727 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Hans Verkuila3998102008-07-21 02:57:38 -0300728 if (ops->vidioc_enum_fmt_vid_out)
729 ret = ops->vidioc_enum_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300730 break;
731 case V4L2_BUF_TYPE_PRIVATE:
Hans Verkuila3998102008-07-21 02:57:38 -0300732 if (ops->vidioc_enum_fmt_type_private)
733 ret = ops->vidioc_enum_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300734 fh, f);
735 break;
736 default:
737 break;
738 }
739 if (!ret)
740 dbgarg(cmd, "index=%d, type=%d, flags=%d, "
741 "pixelformat=%c%c%c%c, description='%s'\n",
742 f->index, f->type, f->flags,
743 (f->pixelformat & 0xff),
744 (f->pixelformat >> 8) & 0xff,
745 (f->pixelformat >> 16) & 0xff,
746 (f->pixelformat >> 24) & 0xff,
747 f->description);
748 break;
749 }
750 case VIDIOC_G_FMT:
751 {
752 struct v4l2_format *f = (struct v4l2_format *)arg;
753
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300754 /* FIXME: Should be one dump per type */
755 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
756
757 switch (f->type) {
758 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Hans Verkuila3998102008-07-21 02:57:38 -0300759 if (ops->vidioc_g_fmt_vid_cap)
760 ret = ops->vidioc_g_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300761 if (!ret)
762 v4l_print_pix_fmt(vfd, &f->fmt.pix);
763 break;
764 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Hans Verkuila3998102008-07-21 02:57:38 -0300765 if (ops->vidioc_g_fmt_vid_overlay)
766 ret = ops->vidioc_g_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300767 fh, f);
768 break;
769 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Hans Verkuila3998102008-07-21 02:57:38 -0300770 if (ops->vidioc_g_fmt_vid_out)
771 ret = ops->vidioc_g_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300772 if (!ret)
773 v4l_print_pix_fmt(vfd, &f->fmt.pix);
774 break;
775 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Hans Verkuila3998102008-07-21 02:57:38 -0300776 if (ops->vidioc_g_fmt_vid_out_overlay)
777 ret = ops->vidioc_g_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300778 fh, f);
779 break;
780 case V4L2_BUF_TYPE_VBI_CAPTURE:
Hans Verkuila3998102008-07-21 02:57:38 -0300781 if (ops->vidioc_g_fmt_vbi_cap)
782 ret = ops->vidioc_g_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300783 break;
784 case V4L2_BUF_TYPE_VBI_OUTPUT:
Hans Verkuila3998102008-07-21 02:57:38 -0300785 if (ops->vidioc_g_fmt_vbi_out)
786 ret = ops->vidioc_g_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300787 break;
788 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Hans Verkuila3998102008-07-21 02:57:38 -0300789 if (ops->vidioc_g_fmt_sliced_vbi_cap)
790 ret = ops->vidioc_g_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300791 fh, f);
792 break;
793 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Hans Verkuila3998102008-07-21 02:57:38 -0300794 if (ops->vidioc_g_fmt_sliced_vbi_out)
795 ret = ops->vidioc_g_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300796 fh, f);
797 break;
798 case V4L2_BUF_TYPE_PRIVATE:
Hans Verkuila3998102008-07-21 02:57:38 -0300799 if (ops->vidioc_g_fmt_type_private)
800 ret = ops->vidioc_g_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300801 fh, f);
802 break;
803 }
804
805 break;
806 }
807 case VIDIOC_S_FMT:
808 {
809 struct v4l2_format *f = (struct v4l2_format *)arg;
810
811 /* FIXME: Should be one dump per type */
812 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
813
814 switch (f->type) {
815 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300816 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300817 v4l_print_pix_fmt(vfd, &f->fmt.pix);
Hans Verkuila3998102008-07-21 02:57:38 -0300818 if (ops->vidioc_s_fmt_vid_cap)
819 ret = ops->vidioc_s_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300820 break;
821 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300822 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -0300823 if (ops->vidioc_s_fmt_vid_overlay)
824 ret = ops->vidioc_s_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300825 fh, f);
826 break;
827 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300828 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300829 v4l_print_pix_fmt(vfd, &f->fmt.pix);
Hans Verkuila3998102008-07-21 02:57:38 -0300830 if (ops->vidioc_s_fmt_vid_out)
831 ret = ops->vidioc_s_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300832 break;
833 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300834 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -0300835 if (ops->vidioc_s_fmt_vid_out_overlay)
836 ret = ops->vidioc_s_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300837 fh, f);
838 break;
839 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300840 CLEAR_AFTER_FIELD(f, fmt.vbi);
Hans Verkuila3998102008-07-21 02:57:38 -0300841 if (ops->vidioc_s_fmt_vbi_cap)
842 ret = ops->vidioc_s_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300843 break;
844 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300845 CLEAR_AFTER_FIELD(f, fmt.vbi);
Hans Verkuila3998102008-07-21 02:57:38 -0300846 if (ops->vidioc_s_fmt_vbi_out)
847 ret = ops->vidioc_s_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300848 break;
849 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300850 CLEAR_AFTER_FIELD(f, fmt.sliced);
Hans Verkuila3998102008-07-21 02:57:38 -0300851 if (ops->vidioc_s_fmt_sliced_vbi_cap)
852 ret = ops->vidioc_s_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300853 fh, f);
854 break;
855 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300856 CLEAR_AFTER_FIELD(f, fmt.sliced);
Hans Verkuila3998102008-07-21 02:57:38 -0300857 if (ops->vidioc_s_fmt_sliced_vbi_out)
858 ret = ops->vidioc_s_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300859 fh, f);
860 break;
861 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300862 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
Hans Verkuila3998102008-07-21 02:57:38 -0300863 if (ops->vidioc_s_fmt_type_private)
864 ret = ops->vidioc_s_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300865 fh, f);
866 break;
867 }
868 break;
869 }
870 case VIDIOC_TRY_FMT:
871 {
872 struct v4l2_format *f = (struct v4l2_format *)arg;
873
874 /* FIXME: Should be one dump per type */
875 dbgarg(cmd, "type=%s\n", prt_names(f->type,
876 v4l2_type_names));
877 switch (f->type) {
878 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300879 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuila3998102008-07-21 02:57:38 -0300880 if (ops->vidioc_try_fmt_vid_cap)
881 ret = ops->vidioc_try_fmt_vid_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300882 if (!ret)
883 v4l_print_pix_fmt(vfd, &f->fmt.pix);
884 break;
885 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300886 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -0300887 if (ops->vidioc_try_fmt_vid_overlay)
888 ret = ops->vidioc_try_fmt_vid_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300889 fh, f);
890 break;
891 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300892 CLEAR_AFTER_FIELD(f, fmt.pix);
Hans Verkuila3998102008-07-21 02:57:38 -0300893 if (ops->vidioc_try_fmt_vid_out)
894 ret = ops->vidioc_try_fmt_vid_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300895 if (!ret)
896 v4l_print_pix_fmt(vfd, &f->fmt.pix);
897 break;
898 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300899 CLEAR_AFTER_FIELD(f, fmt.win);
Hans Verkuila3998102008-07-21 02:57:38 -0300900 if (ops->vidioc_try_fmt_vid_out_overlay)
901 ret = ops->vidioc_try_fmt_vid_out_overlay(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300902 fh, f);
903 break;
904 case V4L2_BUF_TYPE_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300905 CLEAR_AFTER_FIELD(f, fmt.vbi);
Hans Verkuila3998102008-07-21 02:57:38 -0300906 if (ops->vidioc_try_fmt_vbi_cap)
907 ret = ops->vidioc_try_fmt_vbi_cap(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300908 break;
909 case V4L2_BUF_TYPE_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300910 CLEAR_AFTER_FIELD(f, fmt.vbi);
Hans Verkuila3998102008-07-21 02:57:38 -0300911 if (ops->vidioc_try_fmt_vbi_out)
912 ret = ops->vidioc_try_fmt_vbi_out(file, fh, f);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300913 break;
914 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300915 CLEAR_AFTER_FIELD(f, fmt.sliced);
Hans Verkuila3998102008-07-21 02:57:38 -0300916 if (ops->vidioc_try_fmt_sliced_vbi_cap)
917 ret = ops->vidioc_try_fmt_sliced_vbi_cap(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300918 fh, f);
919 break;
920 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300921 CLEAR_AFTER_FIELD(f, fmt.sliced);
Hans Verkuila3998102008-07-21 02:57:38 -0300922 if (ops->vidioc_try_fmt_sliced_vbi_out)
923 ret = ops->vidioc_try_fmt_sliced_vbi_out(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300924 fh, f);
925 break;
926 case V4L2_BUF_TYPE_PRIVATE:
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300927 /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
Hans Verkuila3998102008-07-21 02:57:38 -0300928 if (ops->vidioc_try_fmt_type_private)
929 ret = ops->vidioc_try_fmt_type_private(file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300930 fh, f);
931 break;
932 }
933
934 break;
935 }
936 /* FIXME: Those buf reqs could be handled here,
937 with some changes on videobuf to allow its header to be included at
938 videodev2.h or being merged at videodev2.
939 */
940 case VIDIOC_REQBUFS:
941 {
942 struct v4l2_requestbuffers *p = arg;
943
Hans Verkuila3998102008-07-21 02:57:38 -0300944 if (!ops->vidioc_reqbufs)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300945 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300946 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300947 if (ret)
948 break;
949
Trent Piepho7ecc0cf2009-04-30 21:03:34 -0300950 if (p->type < V4L2_BUF_TYPE_PRIVATE)
951 CLEAR_AFTER_FIELD(p, memory);
952
Hans Verkuila3998102008-07-21 02:57:38 -0300953 ret = ops->vidioc_reqbufs(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300954 dbgarg(cmd, "count=%d, type=%s, memory=%s\n",
955 p->count,
956 prt_names(p->type, v4l2_type_names),
957 prt_names(p->memory, v4l2_memory_names));
958 break;
959 }
960 case VIDIOC_QUERYBUF:
961 {
962 struct v4l2_buffer *p = arg;
963
Hans Verkuila3998102008-07-21 02:57:38 -0300964 if (!ops->vidioc_querybuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300965 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300966 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300967 if (ret)
968 break;
969
Hans Verkuila3998102008-07-21 02:57:38 -0300970 ret = ops->vidioc_querybuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300971 if (!ret)
972 dbgbuf(cmd, vfd, p);
973 break;
974 }
975 case VIDIOC_QBUF:
976 {
977 struct v4l2_buffer *p = arg;
978
Hans Verkuila3998102008-07-21 02:57:38 -0300979 if (!ops->vidioc_qbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300980 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300981 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300982 if (ret)
983 break;
984
Hans Verkuila3998102008-07-21 02:57:38 -0300985 ret = ops->vidioc_qbuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300986 if (!ret)
987 dbgbuf(cmd, vfd, p);
988 break;
989 }
990 case VIDIOC_DQBUF:
991 {
992 struct v4l2_buffer *p = arg;
993
Hans Verkuila3998102008-07-21 02:57:38 -0300994 if (!ops->vidioc_dqbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300995 break;
Hans Verkuila3998102008-07-21 02:57:38 -0300996 ret = check_fmt(ops, p->type);
Hans Verkuil35ea11f2008-07-20 08:12:02 -0300997 if (ret)
998 break;
999
Hans Verkuila3998102008-07-21 02:57:38 -03001000 ret = ops->vidioc_dqbuf(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001001 if (!ret)
1002 dbgbuf(cmd, vfd, p);
1003 break;
1004 }
1005 case VIDIOC_OVERLAY:
1006 {
1007 int *i = arg;
1008
Hans Verkuila3998102008-07-21 02:57:38 -03001009 if (!ops->vidioc_overlay)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001010 break;
1011 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001012 ret = ops->vidioc_overlay(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001013 break;
1014 }
1015 case VIDIOC_G_FBUF:
1016 {
1017 struct v4l2_framebuffer *p = arg;
1018
Hans Verkuila3998102008-07-21 02:57:38 -03001019 if (!ops->vidioc_g_fbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001020 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001021 ret = ops->vidioc_g_fbuf(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001022 if (!ret) {
1023 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
1024 p->capability, p->flags,
1025 (unsigned long)p->base);
1026 v4l_print_pix_fmt(vfd, &p->fmt);
1027 }
1028 break;
1029 }
1030 case VIDIOC_S_FBUF:
1031 {
1032 struct v4l2_framebuffer *p = arg;
1033
Hans Verkuila3998102008-07-21 02:57:38 -03001034 if (!ops->vidioc_s_fbuf)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001035 break;
1036 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
1037 p->capability, p->flags, (unsigned long)p->base);
1038 v4l_print_pix_fmt(vfd, &p->fmt);
Hans Verkuila3998102008-07-21 02:57:38 -03001039 ret = ops->vidioc_s_fbuf(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001040 break;
1041 }
1042 case VIDIOC_STREAMON:
1043 {
1044 enum v4l2_buf_type i = *(int *)arg;
1045
Hans Verkuila3998102008-07-21 02:57:38 -03001046 if (!ops->vidioc_streamon)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001047 break;
1048 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001049 ret = ops->vidioc_streamon(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001050 break;
1051 }
1052 case VIDIOC_STREAMOFF:
1053 {
1054 enum v4l2_buf_type i = *(int *)arg;
1055
Hans Verkuila3998102008-07-21 02:57:38 -03001056 if (!ops->vidioc_streamoff)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001057 break;
1058 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001059 ret = ops->vidioc_streamoff(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001060 break;
1061 }
1062 /* ---------- tv norms ---------- */
1063 case VIDIOC_ENUMSTD:
1064 {
1065 struct v4l2_standard *p = arg;
1066 v4l2_std_id id = vfd->tvnorms, curr_id = 0;
1067 unsigned int index = p->index, i, j = 0;
1068 const char *descr = "";
1069
1070 /* Return norm array in a canonical way */
1071 for (i = 0; i <= index && id; i++) {
1072 /* last std value in the standards array is 0, so this
1073 while always ends there since (id & 0) == 0. */
1074 while ((id & standards[j].std) != standards[j].std)
1075 j++;
1076 curr_id = standards[j].std;
1077 descr = standards[j].descr;
1078 j++;
1079 if (curr_id == 0)
1080 break;
1081 if (curr_id != V4L2_STD_PAL &&
1082 curr_id != V4L2_STD_SECAM &&
1083 curr_id != V4L2_STD_NTSC)
1084 id &= ~curr_id;
1085 }
1086 if (i <= index)
Hans Verkuil3f5e1822010-04-06 08:14:11 -03001087 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001088
1089 v4l2_video_std_construct(p, curr_id, descr);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001090
1091 dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1092 "framelines=%d\n", p->index,
1093 (unsigned long long)p->id, p->name,
1094 p->frameperiod.numerator,
1095 p->frameperiod.denominator,
1096 p->framelines);
1097
1098 ret = 0;
1099 break;
1100 }
1101 case VIDIOC_G_STD:
1102 {
1103 v4l2_std_id *id = arg;
1104
1105 ret = 0;
1106 /* Calls the specific handler */
Hans Verkuila3998102008-07-21 02:57:38 -03001107 if (ops->vidioc_g_std)
1108 ret = ops->vidioc_g_std(file, fh, id);
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001109 else if (vfd->current_norm)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001110 *id = vfd->current_norm;
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001111 else
1112 ret = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001113
1114 if (!ret)
1115 dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id);
1116 break;
1117 }
1118 case VIDIOC_S_STD:
1119 {
1120 v4l2_std_id *id = arg, norm;
1121
1122 dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id);
1123
1124 norm = (*id) & vfd->tvnorms;
1125 if (vfd->tvnorms && !norm) /* Check if std is supported */
1126 break;
1127
1128 /* Calls the specific handler */
Hans Verkuila3998102008-07-21 02:57:38 -03001129 if (ops->vidioc_s_std)
1130 ret = ops->vidioc_s_std(file, fh, &norm);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001131 else
1132 ret = -EINVAL;
1133
1134 /* Updates standard information */
1135 if (ret >= 0)
1136 vfd->current_norm = norm;
1137 break;
1138 }
1139 case VIDIOC_QUERYSTD:
1140 {
1141 v4l2_std_id *p = arg;
1142
Hans Verkuila3998102008-07-21 02:57:38 -03001143 if (!ops->vidioc_querystd)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001144 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001145 ret = ops->vidioc_querystd(file, fh, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001146 if (!ret)
1147 dbgarg(cmd, "detected std=%08Lx\n",
1148 (unsigned long long)*p);
1149 break;
1150 }
1151 /* ------ input switching ---------- */
1152 /* FIXME: Inputs can be handled inside videodev2 */
1153 case VIDIOC_ENUMINPUT:
1154 {
1155 struct v4l2_input *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001156
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001157 /*
1158 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1159 * CAP_STD here based on ioctl handler provided by the
1160 * driver. If the driver doesn't support these
1161 * for a specific input, it must override these flags.
1162 */
1163 if (ops->vidioc_s_std)
1164 p->capabilities |= V4L2_IN_CAP_STD;
1165 if (ops->vidioc_s_dv_preset)
1166 p->capabilities |= V4L2_IN_CAP_PRESETS;
1167 if (ops->vidioc_s_dv_timings)
1168 p->capabilities |= V4L2_IN_CAP_CUSTOM_TIMINGS;
1169
Hans Verkuila3998102008-07-21 02:57:38 -03001170 if (!ops->vidioc_enum_input)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001171 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001172
Hans Verkuila3998102008-07-21 02:57:38 -03001173 ret = ops->vidioc_enum_input(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001174 if (!ret)
1175 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1176 "audioset=%d, "
1177 "tuner=%d, std=%08Lx, status=%d\n",
1178 p->index, p->name, p->type, p->audioset,
1179 p->tuner,
1180 (unsigned long long)p->std,
1181 p->status);
1182 break;
1183 }
1184 case VIDIOC_G_INPUT:
1185 {
1186 unsigned int *i = arg;
1187
Hans Verkuila3998102008-07-21 02:57:38 -03001188 if (!ops->vidioc_g_input)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001189 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001190 ret = ops->vidioc_g_input(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001191 if (!ret)
1192 dbgarg(cmd, "value=%d\n", *i);
1193 break;
1194 }
1195 case VIDIOC_S_INPUT:
1196 {
1197 unsigned int *i = arg;
1198
Hans Verkuila3998102008-07-21 02:57:38 -03001199 if (!ops->vidioc_s_input)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001200 break;
1201 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001202 ret = ops->vidioc_s_input(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001203 break;
1204 }
1205
1206 /* ------ output switching ---------- */
1207 case VIDIOC_ENUMOUTPUT:
1208 {
1209 struct v4l2_output *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001210
Hans Verkuila3998102008-07-21 02:57:38 -03001211 if (!ops->vidioc_enum_output)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001212 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001213
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001214 /*
1215 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1216 * CAP_STD here based on ioctl handler provided by the
1217 * driver. If the driver doesn't support these
1218 * for a specific output, it must override these flags.
1219 */
1220 if (ops->vidioc_s_std)
1221 p->capabilities |= V4L2_OUT_CAP_STD;
1222 if (ops->vidioc_s_dv_preset)
1223 p->capabilities |= V4L2_OUT_CAP_PRESETS;
1224 if (ops->vidioc_s_dv_timings)
1225 p->capabilities |= V4L2_OUT_CAP_CUSTOM_TIMINGS;
1226
Hans Verkuila3998102008-07-21 02:57:38 -03001227 ret = ops->vidioc_enum_output(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001228 if (!ret)
1229 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1230 "audioset=0x%x, "
1231 "modulator=%d, std=0x%08Lx\n",
1232 p->index, p->name, p->type, p->audioset,
1233 p->modulator, (unsigned long long)p->std);
1234 break;
1235 }
1236 case VIDIOC_G_OUTPUT:
1237 {
1238 unsigned int *i = arg;
1239
Hans Verkuila3998102008-07-21 02:57:38 -03001240 if (!ops->vidioc_g_output)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001241 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001242 ret = ops->vidioc_g_output(file, fh, i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001243 if (!ret)
1244 dbgarg(cmd, "value=%d\n", *i);
1245 break;
1246 }
1247 case VIDIOC_S_OUTPUT:
1248 {
1249 unsigned int *i = arg;
1250
Hans Verkuila3998102008-07-21 02:57:38 -03001251 if (!ops->vidioc_s_output)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001252 break;
1253 dbgarg(cmd, "value=%d\n", *i);
Hans Verkuila3998102008-07-21 02:57:38 -03001254 ret = ops->vidioc_s_output(file, fh, *i);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001255 break;
1256 }
1257
1258 /* --- controls ---------------------------------------------- */
1259 case VIDIOC_QUERYCTRL:
1260 {
1261 struct v4l2_queryctrl *p = arg;
1262
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001263 if (vfd->ctrl_handler)
1264 ret = v4l2_queryctrl(vfd->ctrl_handler, p);
1265 else if (ops->vidioc_queryctrl)
1266 ret = ops->vidioc_queryctrl(file, fh, p);
1267 else
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001268 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001269 if (!ret)
1270 dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1271 "step=%d, default=%d, flags=0x%08x\n",
1272 p->id, p->type, p->name,
1273 p->minimum, p->maximum,
1274 p->step, p->default_value, p->flags);
1275 else
1276 dbgarg(cmd, "id=0x%x\n", p->id);
1277 break;
1278 }
1279 case VIDIOC_G_CTRL:
1280 {
1281 struct v4l2_control *p = arg;
1282
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001283 if (vfd->ctrl_handler)
1284 ret = v4l2_g_ctrl(vfd->ctrl_handler, p);
1285 else if (ops->vidioc_g_ctrl)
Hans Verkuila3998102008-07-21 02:57:38 -03001286 ret = ops->vidioc_g_ctrl(file, fh, p);
1287 else if (ops->vidioc_g_ext_ctrls) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001288 struct v4l2_ext_controls ctrls;
1289 struct v4l2_ext_control ctrl;
1290
1291 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1292 ctrls.count = 1;
1293 ctrls.controls = &ctrl;
1294 ctrl.id = p->id;
1295 ctrl.value = p->value;
1296 if (check_ext_ctrls(&ctrls, 1)) {
Hans Verkuila3998102008-07-21 02:57:38 -03001297 ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001298 if (ret == 0)
1299 p->value = ctrl.value;
1300 }
1301 } else
1302 break;
1303 if (!ret)
1304 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1305 else
1306 dbgarg(cmd, "id=0x%x\n", p->id);
1307 break;
1308 }
1309 case VIDIOC_S_CTRL:
1310 {
1311 struct v4l2_control *p = arg;
1312 struct v4l2_ext_controls ctrls;
1313 struct v4l2_ext_control ctrl;
1314
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001315 if (!vfd->ctrl_handler &&
1316 !ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001317 break;
1318
1319 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1320
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001321 if (vfd->ctrl_handler) {
1322 ret = v4l2_s_ctrl(vfd->ctrl_handler, p);
1323 break;
1324 }
Hans Verkuila3998102008-07-21 02:57:38 -03001325 if (ops->vidioc_s_ctrl) {
1326 ret = ops->vidioc_s_ctrl(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001327 break;
1328 }
Hans Verkuila3998102008-07-21 02:57:38 -03001329 if (!ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001330 break;
1331
1332 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1333 ctrls.count = 1;
1334 ctrls.controls = &ctrl;
1335 ctrl.id = p->id;
1336 ctrl.value = p->value;
1337 if (check_ext_ctrls(&ctrls, 1))
Hans Verkuila3998102008-07-21 02:57:38 -03001338 ret = ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001339 break;
1340 }
1341 case VIDIOC_G_EXT_CTRLS:
1342 {
1343 struct v4l2_ext_controls *p = arg;
1344
1345 p->error_idx = p->count;
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001346 if (vfd->ctrl_handler)
1347 ret = v4l2_g_ext_ctrls(vfd->ctrl_handler, p);
1348 else if (ops->vidioc_g_ext_ctrls && check_ext_ctrls(p, 0))
Hans Verkuila3998102008-07-21 02:57:38 -03001349 ret = ops->vidioc_g_ext_ctrls(file, fh, p);
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001350 else
1351 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001352 v4l_print_ext_ctrls(cmd, vfd, p, !ret);
1353 break;
1354 }
1355 case VIDIOC_S_EXT_CTRLS:
1356 {
1357 struct v4l2_ext_controls *p = arg;
1358
1359 p->error_idx = p->count;
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001360 if (!vfd->ctrl_handler && !ops->vidioc_s_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001361 break;
1362 v4l_print_ext_ctrls(cmd, vfd, p, 1);
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001363 if (vfd->ctrl_handler)
1364 ret = v4l2_s_ext_ctrls(vfd->ctrl_handler, p);
1365 else if (check_ext_ctrls(p, 0))
Hans Verkuila3998102008-07-21 02:57:38 -03001366 ret = ops->vidioc_s_ext_ctrls(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001367 break;
1368 }
1369 case VIDIOC_TRY_EXT_CTRLS:
1370 {
1371 struct v4l2_ext_controls *p = arg;
1372
1373 p->error_idx = p->count;
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001374 if (!vfd->ctrl_handler && !ops->vidioc_try_ext_ctrls)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001375 break;
1376 v4l_print_ext_ctrls(cmd, vfd, p, 1);
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001377 if (vfd->ctrl_handler)
1378 ret = v4l2_try_ext_ctrls(vfd->ctrl_handler, p);
1379 else if (check_ext_ctrls(p, 0))
Hans Verkuila3998102008-07-21 02:57:38 -03001380 ret = ops->vidioc_try_ext_ctrls(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001381 break;
1382 }
1383 case VIDIOC_QUERYMENU:
1384 {
1385 struct v4l2_querymenu *p = arg;
1386
Hans Verkuil11bbc1c2010-05-16 09:24:06 -03001387 if (vfd->ctrl_handler)
1388 ret = v4l2_querymenu(vfd->ctrl_handler, p);
1389 else if (ops->vidioc_querymenu)
1390 ret = ops->vidioc_querymenu(file, fh, p);
1391 else
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001392 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001393 if (!ret)
1394 dbgarg(cmd, "id=0x%x, index=%d, name=%s\n",
1395 p->id, p->index, p->name);
1396 else
1397 dbgarg(cmd, "id=0x%x, index=%d\n",
1398 p->id, p->index);
1399 break;
1400 }
1401 /* --- audio ---------------------------------------------- */
1402 case VIDIOC_ENUMAUDIO:
1403 {
1404 struct v4l2_audio *p = arg;
1405
Hans Verkuila3998102008-07-21 02:57:38 -03001406 if (!ops->vidioc_enumaudio)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001407 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001408 ret = ops->vidioc_enumaudio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001409 if (!ret)
1410 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1411 "mode=0x%x\n", p->index, p->name,
1412 p->capability, p->mode);
1413 else
1414 dbgarg(cmd, "index=%d\n", p->index);
1415 break;
1416 }
1417 case VIDIOC_G_AUDIO:
1418 {
1419 struct v4l2_audio *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001420
Hans Verkuila3998102008-07-21 02:57:38 -03001421 if (!ops->vidioc_g_audio)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001422 break;
1423
Hans Verkuila3998102008-07-21 02:57:38 -03001424 ret = ops->vidioc_g_audio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001425 if (!ret)
1426 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1427 "mode=0x%x\n", p->index,
1428 p->name, p->capability, p->mode);
1429 else
1430 dbgarg(cmd, "index=%d\n", p->index);
1431 break;
1432 }
1433 case VIDIOC_S_AUDIO:
1434 {
1435 struct v4l2_audio *p = arg;
1436
Hans Verkuila3998102008-07-21 02:57:38 -03001437 if (!ops->vidioc_s_audio)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001438 break;
1439 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1440 "mode=0x%x\n", p->index, p->name,
1441 p->capability, p->mode);
Hans Verkuila3998102008-07-21 02:57:38 -03001442 ret = ops->vidioc_s_audio(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001443 break;
1444 }
1445 case VIDIOC_ENUMAUDOUT:
1446 {
1447 struct v4l2_audioout *p = arg;
1448
Hans Verkuila3998102008-07-21 02:57:38 -03001449 if (!ops->vidioc_enumaudout)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001450 break;
1451 dbgarg(cmd, "Enum for index=%d\n", p->index);
Hans Verkuila3998102008-07-21 02:57:38 -03001452 ret = ops->vidioc_enumaudout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001453 if (!ret)
1454 dbgarg2("index=%d, name=%s, capability=%d, "
1455 "mode=%d\n", p->index, p->name,
1456 p->capability, p->mode);
1457 break;
1458 }
1459 case VIDIOC_G_AUDOUT:
1460 {
1461 struct v4l2_audioout *p = arg;
1462
Hans Verkuila3998102008-07-21 02:57:38 -03001463 if (!ops->vidioc_g_audout)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001464 break;
Trent Piepho337f9d22009-03-04 01:21:02 -03001465
Hans Verkuila3998102008-07-21 02:57:38 -03001466 ret = ops->vidioc_g_audout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001467 if (!ret)
1468 dbgarg2("index=%d, name=%s, capability=%d, "
1469 "mode=%d\n", p->index, p->name,
1470 p->capability, p->mode);
1471 break;
1472 }
1473 case VIDIOC_S_AUDOUT:
1474 {
1475 struct v4l2_audioout *p = arg;
1476
Hans Verkuila3998102008-07-21 02:57:38 -03001477 if (!ops->vidioc_s_audout)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001478 break;
1479 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1480 "mode=%d\n", p->index, p->name,
1481 p->capability, p->mode);
1482
Hans Verkuila3998102008-07-21 02:57:38 -03001483 ret = ops->vidioc_s_audout(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001484 break;
1485 }
1486 case VIDIOC_G_MODULATOR:
1487 {
1488 struct v4l2_modulator *p = arg;
1489
Hans Verkuila3998102008-07-21 02:57:38 -03001490 if (!ops->vidioc_g_modulator)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001491 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001492 ret = ops->vidioc_g_modulator(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001493 if (!ret)
1494 dbgarg(cmd, "index=%d, name=%s, "
1495 "capability=%d, rangelow=%d,"
1496 " rangehigh=%d, txsubchans=%d\n",
1497 p->index, p->name, p->capability,
1498 p->rangelow, p->rangehigh,
1499 p->txsubchans);
1500 break;
1501 }
1502 case VIDIOC_S_MODULATOR:
1503 {
1504 struct v4l2_modulator *p = arg;
1505
Hans Verkuila3998102008-07-21 02:57:38 -03001506 if (!ops->vidioc_s_modulator)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001507 break;
1508 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1509 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1510 p->index, p->name, p->capability, p->rangelow,
1511 p->rangehigh, p->txsubchans);
Hans Verkuila3998102008-07-21 02:57:38 -03001512 ret = ops->vidioc_s_modulator(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001513 break;
1514 }
1515 case VIDIOC_G_CROP:
1516 {
1517 struct v4l2_crop *p = arg;
1518
Hans Verkuila3998102008-07-21 02:57:38 -03001519 if (!ops->vidioc_g_crop)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001520 break;
Mauro Carvalho Chehaba56a18c2008-11-11 21:15:03 -03001521
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001522 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001523 ret = ops->vidioc_g_crop(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001524 if (!ret)
1525 dbgrect(vfd, "", &p->c);
1526 break;
1527 }
1528 case VIDIOC_S_CROP:
1529 {
1530 struct v4l2_crop *p = arg;
1531
Hans Verkuila3998102008-07-21 02:57:38 -03001532 if (!ops->vidioc_s_crop)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001533 break;
1534 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1535 dbgrect(vfd, "", &p->c);
Hans Verkuila3998102008-07-21 02:57:38 -03001536 ret = ops->vidioc_s_crop(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001537 break;
1538 }
1539 case VIDIOC_CROPCAP:
1540 {
1541 struct v4l2_cropcap *p = arg;
1542
1543 /*FIXME: Should also show v4l2_fract pixelaspect */
Hans Verkuila3998102008-07-21 02:57:38 -03001544 if (!ops->vidioc_cropcap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001545 break;
Mauro Carvalho Chehaba56a18c2008-11-11 21:15:03 -03001546
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001547 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001548 ret = ops->vidioc_cropcap(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001549 if (!ret) {
1550 dbgrect(vfd, "bounds ", &p->bounds);
1551 dbgrect(vfd, "defrect ", &p->defrect);
1552 }
1553 break;
1554 }
1555 case VIDIOC_G_JPEGCOMP:
1556 {
1557 struct v4l2_jpegcompression *p = arg;
1558
Hans Verkuila3998102008-07-21 02:57:38 -03001559 if (!ops->vidioc_g_jpegcomp)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001560 break;
Mauro Carvalho Chehaba56a18c2008-11-11 21:15:03 -03001561
Hans Verkuila3998102008-07-21 02:57:38 -03001562 ret = ops->vidioc_g_jpegcomp(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001563 if (!ret)
1564 dbgarg(cmd, "quality=%d, APPn=%d, "
1565 "APP_len=%d, COM_len=%d, "
1566 "jpeg_markers=%d\n",
1567 p->quality, p->APPn, p->APP_len,
1568 p->COM_len, p->jpeg_markers);
1569 break;
1570 }
1571 case VIDIOC_S_JPEGCOMP:
1572 {
1573 struct v4l2_jpegcompression *p = arg;
1574
Hans Verkuila3998102008-07-21 02:57:38 -03001575 if (!ops->vidioc_g_jpegcomp)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001576 break;
1577 dbgarg(cmd, "quality=%d, APPn=%d, APP_len=%d, "
1578 "COM_len=%d, jpeg_markers=%d\n",
1579 p->quality, p->APPn, p->APP_len,
1580 p->COM_len, p->jpeg_markers);
Hans Verkuila3998102008-07-21 02:57:38 -03001581 ret = ops->vidioc_s_jpegcomp(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001582 break;
1583 }
1584 case VIDIOC_G_ENC_INDEX:
1585 {
1586 struct v4l2_enc_idx *p = arg;
1587
Hans Verkuila3998102008-07-21 02:57:38 -03001588 if (!ops->vidioc_g_enc_index)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001589 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001590 ret = ops->vidioc_g_enc_index(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001591 if (!ret)
1592 dbgarg(cmd, "entries=%d, entries_cap=%d\n",
1593 p->entries, p->entries_cap);
1594 break;
1595 }
1596 case VIDIOC_ENCODER_CMD:
1597 {
1598 struct v4l2_encoder_cmd *p = arg;
1599
Hans Verkuila3998102008-07-21 02:57:38 -03001600 if (!ops->vidioc_encoder_cmd)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001601 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001602 ret = ops->vidioc_encoder_cmd(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001603 if (!ret)
1604 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1605 break;
1606 }
1607 case VIDIOC_TRY_ENCODER_CMD:
1608 {
1609 struct v4l2_encoder_cmd *p = arg;
1610
Hans Verkuila3998102008-07-21 02:57:38 -03001611 if (!ops->vidioc_try_encoder_cmd)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001612 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001613 ret = ops->vidioc_try_encoder_cmd(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001614 if (!ret)
1615 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1616 break;
1617 }
1618 case VIDIOC_G_PARM:
1619 {
1620 struct v4l2_streamparm *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001621
Hans Verkuila3998102008-07-21 02:57:38 -03001622 if (ops->vidioc_g_parm) {
Trent Piepho34796bc2009-03-28 22:25:35 -03001623 ret = check_fmt(ops, p->type);
1624 if (ret)
1625 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001626 ret = ops->vidioc_g_parm(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001627 } else {
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001628 v4l2_std_id std = vfd->current_norm;
1629
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001630 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
Hans Verkuil3f5e1822010-04-06 08:14:11 -03001631 break;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001632
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001633 ret = 0;
Hans Verkuil9bedc7f2009-08-07 07:28:16 -03001634 if (ops->vidioc_g_std)
1635 ret = ops->vidioc_g_std(file, fh, &std);
1636 else if (std == 0)
1637 ret = -EINVAL;
1638 if (ret == 0)
1639 v4l2_video_std_frame_period(std,
1640 &p->parm.capture.timeperframe);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001641 }
1642
1643 dbgarg(cmd, "type=%d\n", p->type);
1644 break;
1645 }
1646 case VIDIOC_S_PARM:
1647 {
1648 struct v4l2_streamparm *p = arg;
1649
Hans Verkuila3998102008-07-21 02:57:38 -03001650 if (!ops->vidioc_s_parm)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001651 break;
Trent Piepho34796bc2009-03-28 22:25:35 -03001652 ret = check_fmt(ops, p->type);
1653 if (ret)
1654 break;
1655
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001656 dbgarg(cmd, "type=%d\n", p->type);
Hans Verkuila3998102008-07-21 02:57:38 -03001657 ret = ops->vidioc_s_parm(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001658 break;
1659 }
1660 case VIDIOC_G_TUNER:
1661 {
1662 struct v4l2_tuner *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001663
Hans Verkuila3998102008-07-21 02:57:38 -03001664 if (!ops->vidioc_g_tuner)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001665 break;
1666
Hans Verkuila3998102008-07-21 02:57:38 -03001667 ret = ops->vidioc_g_tuner(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001668 if (!ret)
1669 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1670 "capability=0x%x, rangelow=%d, "
1671 "rangehigh=%d, signal=%d, afc=%d, "
1672 "rxsubchans=0x%x, audmode=%d\n",
1673 p->index, p->name, p->type,
1674 p->capability, p->rangelow,
1675 p->rangehigh, p->signal, p->afc,
1676 p->rxsubchans, p->audmode);
1677 break;
1678 }
1679 case VIDIOC_S_TUNER:
1680 {
1681 struct v4l2_tuner *p = arg;
1682
Hans Verkuila3998102008-07-21 02:57:38 -03001683 if (!ops->vidioc_s_tuner)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001684 break;
1685 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1686 "capability=0x%x, rangelow=%d, "
1687 "rangehigh=%d, signal=%d, afc=%d, "
1688 "rxsubchans=0x%x, audmode=%d\n",
1689 p->index, p->name, p->type,
1690 p->capability, p->rangelow,
1691 p->rangehigh, p->signal, p->afc,
1692 p->rxsubchans, p->audmode);
Hans Verkuila3998102008-07-21 02:57:38 -03001693 ret = ops->vidioc_s_tuner(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001694 break;
1695 }
1696 case VIDIOC_G_FREQUENCY:
1697 {
1698 struct v4l2_frequency *p = arg;
1699
Hans Verkuila3998102008-07-21 02:57:38 -03001700 if (!ops->vidioc_g_frequency)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001701 break;
1702
Hans Verkuila3998102008-07-21 02:57:38 -03001703 ret = ops->vidioc_g_frequency(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001704 if (!ret)
1705 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1706 p->tuner, p->type, p->frequency);
1707 break;
1708 }
1709 case VIDIOC_S_FREQUENCY:
1710 {
1711 struct v4l2_frequency *p = arg;
1712
Hans Verkuila3998102008-07-21 02:57:38 -03001713 if (!ops->vidioc_s_frequency)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001714 break;
1715 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1716 p->tuner, p->type, p->frequency);
Hans Verkuila3998102008-07-21 02:57:38 -03001717 ret = ops->vidioc_s_frequency(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001718 break;
1719 }
1720 case VIDIOC_G_SLICED_VBI_CAP:
1721 {
1722 struct v4l2_sliced_vbi_cap *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001723
Hans Verkuila3998102008-07-21 02:57:38 -03001724 if (!ops->vidioc_g_sliced_vbi_cap)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001725 break;
Trent Piepho19c96e42009-03-04 01:21:02 -03001726
1727 /* Clear up to type, everything after type is zerod already */
1728 memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
1729
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001730 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
Hans Verkuila3998102008-07-21 02:57:38 -03001731 ret = ops->vidioc_g_sliced_vbi_cap(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001732 if (!ret)
1733 dbgarg2("service_set=%d\n", p->service_set);
1734 break;
1735 }
1736 case VIDIOC_LOG_STATUS:
1737 {
Hans Verkuila3998102008-07-21 02:57:38 -03001738 if (!ops->vidioc_log_status)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001739 break;
Hans Verkuila3998102008-07-21 02:57:38 -03001740 ret = ops->vidioc_log_status(file, fh);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001741 break;
1742 }
1743#ifdef CONFIG_VIDEO_ADV_DEBUG
1744 case VIDIOC_DBG_G_REGISTER:
1745 {
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001746 struct v4l2_dbg_register *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001747
1748 if (!capable(CAP_SYS_ADMIN))
1749 ret = -EPERM;
Hans Verkuila3998102008-07-21 02:57:38 -03001750 else if (ops->vidioc_g_register)
1751 ret = ops->vidioc_g_register(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001752 break;
1753 }
1754 case VIDIOC_DBG_S_REGISTER:
1755 {
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001756 struct v4l2_dbg_register *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001757
1758 if (!capable(CAP_SYS_ADMIN))
1759 ret = -EPERM;
Hans Verkuila3998102008-07-21 02:57:38 -03001760 else if (ops->vidioc_s_register)
1761 ret = ops->vidioc_s_register(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001762 break;
1763 }
1764#endif
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001765 case VIDIOC_DBG_G_CHIP_IDENT:
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001766 {
Hans Verkuilaecde8b52008-12-30 07:14:19 -03001767 struct v4l2_dbg_chip_ident *p = arg;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001768
Hans Verkuila3998102008-07-21 02:57:38 -03001769 if (!ops->vidioc_g_chip_ident)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001770 break;
Hans Verkuil80b36e02009-02-07 11:00:02 -03001771 p->ident = V4L2_IDENT_NONE;
1772 p->revision = 0;
Hans Verkuila3998102008-07-21 02:57:38 -03001773 ret = ops->vidioc_g_chip_ident(file, fh, p);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001774 if (!ret)
1775 dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
1776 break;
1777 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001778 case VIDIOC_S_HW_FREQ_SEEK:
1779 {
1780 struct v4l2_hw_freq_seek *p = arg;
1781
Hans Verkuila3998102008-07-21 02:57:38 -03001782 if (!ops->vidioc_s_hw_freq_seek)
Hans Verkuil35ea11f2008-07-20 08:12:02 -03001783 break;
1784 dbgarg(cmd,
1785 "tuner=%d, type=%d, seek_upward=%d, wrap_around=%d\n",
1786 p->tuner, p->type, p->seek_upward, p->wrap_around);
Hans Verkuila3998102008-07-21 02:57:38 -03001787 ret = ops->vidioc_s_hw_freq_seek(file, fh, p);
1788 break;
1789 }
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001790 case VIDIOC_ENUM_FRAMESIZES:
1791 {
1792 struct v4l2_frmsizeenum *p = arg;
1793
1794 if (!ops->vidioc_enum_framesizes)
1795 break;
1796
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001797 ret = ops->vidioc_enum_framesizes(file, fh, p);
1798 dbgarg(cmd,
Mauro Carvalho Chehabd1afe422009-06-21 22:37:12 -03001799 "index=%d, pixelformat=%c%c%c%c, type=%d ",
1800 p->index,
1801 (p->pixel_format & 0xff),
1802 (p->pixel_format >> 8) & 0xff,
1803 (p->pixel_format >> 16) & 0xff,
1804 (p->pixel_format >> 24) & 0xff,
1805 p->type);
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001806 switch (p->type) {
1807 case V4L2_FRMSIZE_TYPE_DISCRETE:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001808 dbgarg3("width = %d, height=%d\n",
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001809 p->discrete.width, p->discrete.height);
1810 break;
1811 case V4L2_FRMSIZE_TYPE_STEPWISE:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001812 dbgarg3("min %dx%d, max %dx%d, step %dx%d\n",
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001813 p->stepwise.min_width, p->stepwise.min_height,
1814 p->stepwise.step_width, p->stepwise.step_height,
1815 p->stepwise.max_width, p->stepwise.max_height);
1816 break;
1817 case V4L2_FRMSIZE_TYPE_CONTINUOUS:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001818 dbgarg3("continuous\n");
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001819 break;
1820 default:
Mauro Carvalho Chehabd33fbcb2009-07-02 17:07:32 -03001821 dbgarg3("- Unknown type!\n");
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001822 }
1823
1824 break;
1825 }
1826 case VIDIOC_ENUM_FRAMEINTERVALS:
1827 {
1828 struct v4l2_frmivalenum *p = arg;
1829
1830 if (!ops->vidioc_enum_frameintervals)
1831 break;
1832
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001833 ret = ops->vidioc_enum_frameintervals(file, fh, p);
1834 dbgarg(cmd,
1835 "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
1836 p->index, p->pixel_format,
1837 p->width, p->height, p->type);
1838 switch (p->type) {
1839 case V4L2_FRMIVAL_TYPE_DISCRETE:
1840 dbgarg2("fps=%d/%d\n",
1841 p->discrete.numerator,
1842 p->discrete.denominator);
1843 break;
1844 case V4L2_FRMIVAL_TYPE_STEPWISE:
Mauro Carvalho Chehab19585782008-11-12 01:03:02 -03001845 dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
1846 p->stepwise.min.numerator,
1847 p->stepwise.min.denominator,
1848 p->stepwise.max.numerator,
1849 p->stepwise.max.denominator,
1850 p->stepwise.step.numerator,
1851 p->stepwise.step.denominator);
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001852 break;
1853 case V4L2_FRMIVAL_TYPE_CONTINUOUS:
1854 dbgarg2("continuous\n");
1855 break;
1856 default:
1857 dbgarg2("- Unknown type!\n");
1858 }
1859 break;
1860 }
Muralidharan Karicherib6456c02009-11-19 12:00:31 -03001861 case VIDIOC_ENUM_DV_PRESETS:
1862 {
1863 struct v4l2_dv_enum_preset *p = arg;
1864
1865 if (!ops->vidioc_enum_dv_presets)
1866 break;
1867
1868 ret = ops->vidioc_enum_dv_presets(file, fh, p);
1869 if (!ret)
1870 dbgarg(cmd,
1871 "index=%d, preset=%d, name=%s, width=%d,"
1872 " height=%d ",
1873 p->index, p->preset, p->name, p->width,
1874 p->height);
1875 break;
1876 }
1877 case VIDIOC_S_DV_PRESET:
1878 {
1879 struct v4l2_dv_preset *p = arg;
1880
1881 if (!ops->vidioc_s_dv_preset)
1882 break;
1883
1884 dbgarg(cmd, "preset=%d\n", p->preset);
1885 ret = ops->vidioc_s_dv_preset(file, fh, p);
1886 break;
1887 }
1888 case VIDIOC_G_DV_PRESET:
1889 {
1890 struct v4l2_dv_preset *p = arg;
1891
1892 if (!ops->vidioc_g_dv_preset)
1893 break;
1894
1895 ret = ops->vidioc_g_dv_preset(file, fh, p);
1896 if (!ret)
1897 dbgarg(cmd, "preset=%d\n", p->preset);
1898 break;
1899 }
1900 case VIDIOC_QUERY_DV_PRESET:
1901 {
1902 struct v4l2_dv_preset *p = arg;
1903
1904 if (!ops->vidioc_query_dv_preset)
1905 break;
1906
1907 ret = ops->vidioc_query_dv_preset(file, fh, p);
1908 if (!ret)
1909 dbgarg(cmd, "preset=%d\n", p->preset);
1910 break;
1911 }
1912 case VIDIOC_S_DV_TIMINGS:
1913 {
1914 struct v4l2_dv_timings *p = arg;
1915
1916 if (!ops->vidioc_s_dv_timings)
1917 break;
1918
1919 switch (p->type) {
1920 case V4L2_DV_BT_656_1120:
1921 dbgarg2("bt-656/1120:interlaced=%d, pixelclock=%lld,"
1922 " width=%d, height=%d, polarities=%x,"
1923 " hfrontporch=%d, hsync=%d, hbackporch=%d,"
1924 " vfrontporch=%d, vsync=%d, vbackporch=%d,"
1925 " il_vfrontporch=%d, il_vsync=%d,"
1926 " il_vbackporch=%d\n",
1927 p->bt.interlaced, p->bt.pixelclock,
1928 p->bt.width, p->bt.height, p->bt.polarities,
1929 p->bt.hfrontporch, p->bt.hsync,
1930 p->bt.hbackporch, p->bt.vfrontporch,
1931 p->bt.vsync, p->bt.vbackporch,
1932 p->bt.il_vfrontporch, p->bt.il_vsync,
1933 p->bt.il_vbackporch);
1934 ret = ops->vidioc_s_dv_timings(file, fh, p);
1935 break;
1936 default:
1937 dbgarg2("Unknown type %d!\n", p->type);
1938 break;
1939 }
1940 break;
1941 }
1942 case VIDIOC_G_DV_TIMINGS:
1943 {
1944 struct v4l2_dv_timings *p = arg;
1945
1946 if (!ops->vidioc_g_dv_timings)
1947 break;
1948
1949 ret = ops->vidioc_g_dv_timings(file, fh, p);
1950 if (!ret) {
1951 switch (p->type) {
1952 case V4L2_DV_BT_656_1120:
1953 dbgarg2("bt-656/1120:interlaced=%d,"
1954 " pixelclock=%lld,"
1955 " width=%d, height=%d, polarities=%x,"
1956 " hfrontporch=%d, hsync=%d,"
1957 " hbackporch=%d, vfrontporch=%d,"
1958 " vsync=%d, vbackporch=%d,"
1959 " il_vfrontporch=%d, il_vsync=%d,"
1960 " il_vbackporch=%d\n",
1961 p->bt.interlaced, p->bt.pixelclock,
1962 p->bt.width, p->bt.height,
1963 p->bt.polarities, p->bt.hfrontporch,
1964 p->bt.hsync, p->bt.hbackporch,
1965 p->bt.vfrontporch, p->bt.vsync,
1966 p->bt.vbackporch, p->bt.il_vfrontporch,
1967 p->bt.il_vsync, p->bt.il_vbackporch);
1968 break;
1969 default:
1970 dbgarg2("Unknown type %d!\n", p->type);
1971 break;
1972 }
1973 }
1974 break;
1975 }
Sakari Ailusd3d7c962010-03-27 11:02:10 -03001976 case VIDIOC_DQEVENT:
1977 {
1978 struct v4l2_event *ev = arg;
Mauro Carvalho Chehab74d83fa2008-11-11 21:13:47 -03001979
Sakari Ailusd3d7c962010-03-27 11:02:10 -03001980 if (!ops->vidioc_subscribe_event)
1981 break;
1982
1983 ret = v4l2_event_dequeue(fh, ev, file->f_flags & O_NONBLOCK);
1984 if (ret < 0) {
1985 dbgarg(cmd, "no pending events?");
1986 break;
1987 }
1988 dbgarg(cmd,
1989 "pending=%d, type=0x%8.8x, sequence=%d, "
1990 "timestamp=%lu.%9.9lu ",
1991 ev->pending, ev->type, ev->sequence,
1992 ev->timestamp.tv_sec, ev->timestamp.tv_nsec);
1993 break;
1994 }
1995 case VIDIOC_SUBSCRIBE_EVENT:
1996 {
1997 struct v4l2_event_subscription *sub = arg;
1998
1999 if (!ops->vidioc_subscribe_event)
2000 break;
2001
2002 ret = ops->vidioc_subscribe_event(fh, sub);
2003 if (ret < 0) {
2004 dbgarg(cmd, "failed, ret=%ld", ret);
2005 break;
2006 }
2007 dbgarg(cmd, "type=0x%8.8x", sub->type);
2008 break;
2009 }
2010 case VIDIOC_UNSUBSCRIBE_EVENT:
2011 {
2012 struct v4l2_event_subscription *sub = arg;
2013
2014 if (!ops->vidioc_unsubscribe_event)
2015 break;
2016
2017 ret = ops->vidioc_unsubscribe_event(fh, sub);
2018 if (ret < 0) {
2019 dbgarg(cmd, "failed, ret=%ld", ret);
2020 break;
2021 }
2022 dbgarg(cmd, "type=0x%8.8x", sub->type);
2023 break;
2024 }
Hans Verkuila3998102008-07-21 02:57:38 -03002025 default:
2026 {
2027 if (!ops->vidioc_default)
2028 break;
2029 ret = ops->vidioc_default(file, fh, cmd, arg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002030 break;
2031 }
2032 } /* switch */
2033
2034 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
2035 if (ret < 0) {
2036 v4l_print_ioctl(vfd->name, cmd);
Hans Verkuil069b7472008-12-30 07:04:34 -03002037 printk(KERN_CONT " error %ld\n", ret);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002038 }
2039 }
2040
2041 return ret;
2042}
2043
Trent Piepho19c96e42009-03-04 01:21:02 -03002044/* In some cases, only a few fields are used as input, i.e. when the app sets
2045 * "index" and then the driver fills in the rest of the structure for the thing
2046 * with that index. We only need to copy up the first non-input field. */
2047static unsigned long cmd_input_size(unsigned int cmd)
2048{
2049 /* Size of structure up to and including 'field' */
Hans Verkuil9f1a6932009-03-08 10:35:23 -03002050#define CMDINSIZE(cmd, type, field) \
2051 case VIDIOC_##cmd: \
2052 return offsetof(struct v4l2_##type, field) + \
2053 sizeof(((struct v4l2_##type *)0)->field);
Trent Piepho19c96e42009-03-04 01:21:02 -03002054
Hans Verkuil9f1a6932009-03-08 10:35:23 -03002055 switch (cmd) {
Trent Piepho19c96e42009-03-04 01:21:02 -03002056 CMDINSIZE(ENUM_FMT, fmtdesc, type);
2057 CMDINSIZE(G_FMT, format, type);
2058 CMDINSIZE(QUERYBUF, buffer, type);
2059 CMDINSIZE(G_PARM, streamparm, type);
2060 CMDINSIZE(ENUMSTD, standard, index);
2061 CMDINSIZE(ENUMINPUT, input, index);
2062 CMDINSIZE(G_CTRL, control, id);
2063 CMDINSIZE(G_TUNER, tuner, index);
2064 CMDINSIZE(QUERYCTRL, queryctrl, id);
2065 CMDINSIZE(QUERYMENU, querymenu, index);
2066 CMDINSIZE(ENUMOUTPUT, output, index);
2067 CMDINSIZE(G_MODULATOR, modulator, index);
2068 CMDINSIZE(G_FREQUENCY, frequency, tuner);
2069 CMDINSIZE(CROPCAP, cropcap, type);
2070 CMDINSIZE(G_CROP, crop, type);
2071 CMDINSIZE(ENUMAUDIO, audio, index);
2072 CMDINSIZE(ENUMAUDOUT, audioout, index);
2073 CMDINSIZE(ENCODER_CMD, encoder_cmd, flags);
2074 CMDINSIZE(TRY_ENCODER_CMD, encoder_cmd, flags);
2075 CMDINSIZE(G_SLICED_VBI_CAP, sliced_vbi_cap, type);
2076 CMDINSIZE(ENUM_FRAMESIZES, frmsizeenum, pixel_format);
2077 CMDINSIZE(ENUM_FRAMEINTERVALS, frmivalenum, height);
2078 default:
2079 return _IOC_SIZE(cmd);
2080 }
2081}
2082
Hans Verkuil069b7472008-12-30 07:04:34 -03002083long video_ioctl2(struct file *file,
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002084 unsigned int cmd, unsigned long arg)
2085{
2086 char sbuf[128];
2087 void *mbuf = NULL;
Hans Verkuil1d94aa32010-04-06 08:12:21 -03002088 void *parg = (void *)arg;
Hans Verkuil069b7472008-12-30 07:04:34 -03002089 long err = -EINVAL;
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002090 int is_ext_ctrl;
2091 size_t ctrls_size = 0;
2092 void __user *user_ptr = NULL;
2093
2094#ifdef __OLD_VIDIOC_
2095 cmd = video_fix_command(cmd);
2096#endif
2097 is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
2098 cmd == VIDIOC_TRY_EXT_CTRLS);
2099
2100 /* Copy arguments into temp kernel buffer */
Trent Piepho337f9d22009-03-04 01:21:02 -03002101 if (_IOC_DIR(cmd) != _IOC_NONE) {
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002102 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
2103 parg = sbuf;
2104 } else {
2105 /* too big to allocate from stack */
2106 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
2107 if (NULL == mbuf)
2108 return -ENOMEM;
2109 parg = mbuf;
2110 }
2111
2112 err = -EFAULT;
Trent Piepho19c96e42009-03-04 01:21:02 -03002113 if (_IOC_DIR(cmd) & _IOC_WRITE) {
2114 unsigned long n = cmd_input_size(cmd);
2115
2116 if (copy_from_user(parg, (void __user *)arg, n))
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002117 goto out;
Trent Piepho19c96e42009-03-04 01:21:02 -03002118
2119 /* zero out anything we don't copy from userspace */
2120 if (n < _IOC_SIZE(cmd))
2121 memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n);
Trent Piepho337f9d22009-03-04 01:21:02 -03002122 } else {
2123 /* read-only ioctl */
2124 memset(parg, 0, _IOC_SIZE(cmd));
Trent Piepho19c96e42009-03-04 01:21:02 -03002125 }
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002126 }
2127
2128 if (is_ext_ctrl) {
2129 struct v4l2_ext_controls *p = parg;
2130
2131 /* In case of an error, tell the caller that it wasn't
2132 a specific control that caused it. */
2133 p->error_idx = p->count;
2134 user_ptr = (void __user *)p->controls;
2135 if (p->count) {
2136 ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
2137 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
2138 mbuf = kmalloc(ctrls_size, GFP_KERNEL);
2139 err = -ENOMEM;
2140 if (NULL == mbuf)
2141 goto out_ext_ctrl;
2142 err = -EFAULT;
2143 if (copy_from_user(mbuf, user_ptr, ctrls_size))
2144 goto out_ext_ctrl;
2145 p->controls = mbuf;
2146 }
2147 }
2148
2149 /* Handles IOCTL */
Mauro Carvalho Chehabb1f88402008-10-21 11:27:20 -03002150 err = __video_do_ioctl(file, cmd, parg);
Hans Verkuil35ea11f2008-07-20 08:12:02 -03002151 if (err == -ENOIOCTLCMD)
2152 err = -EINVAL;
2153 if (is_ext_ctrl) {
2154 struct v4l2_ext_controls *p = parg;
2155
2156 p->controls = (void *)user_ptr;
2157 if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
2158 err = -EFAULT;
2159 goto out_ext_ctrl;
2160 }
2161 if (err < 0)
2162 goto out;
2163
2164out_ext_ctrl:
2165 /* Copy results into user buffer */
2166 switch (_IOC_DIR(cmd)) {
2167 case _IOC_READ:
2168 case (_IOC_WRITE | _IOC_READ):
2169 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
2170 err = -EFAULT;
2171 break;
2172 }
2173
2174out:
2175 kfree(mbuf);
2176 return err;
2177}
Mauro Carvalho Chehab8a522c92008-10-21 11:58:39 -03002178EXPORT_SYMBOL(video_ioctl2);