2
* Video capture interface for Linux version 2
4
* A generic framework to process V4L2 ioctl commands.
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version
9
* 2 of the License, or (at your option) any later version.
11
* Authors: Alan Cox, <alan@lxorguk.ukuu.org.uk> (version 1)
12
* Mauro Carvalho Chehab <mchehab@infradead.org> (version 2)
15
#include <linux/module.h>
16
#include <linux/slab.h>
17
#include <linux/types.h>
18
#include <linux/kernel.h>
19
#include <linux/version.h>
21
#include <linux/videodev2.h>
23
#include <media/v4l2-common.h>
24
#include <media/v4l2-ioctl.h>
25
#include <media/v4l2-ctrls.h>
26
#include <media/v4l2-fh.h>
27
#include <media/v4l2-event.h>
28
#include <media/v4l2-device.h>
29
#include <media/v4l2-chip-ident.h>
31
#define dbgarg(cmd, fmt, arg...) \
33
if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \
34
printk(KERN_DEBUG "%s: ", vfd->name); \
35
v4l_printk_ioctl(cmd); \
36
printk(" " fmt, ## arg); \
40
#define dbgarg2(fmt, arg...) \
42
if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
43
printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\
46
#define dbgarg3(fmt, arg...) \
48
if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
49
printk(KERN_CONT "%s: " fmt, vfd->name, ## arg);\
52
/* Zero out the end of the struct pointed to by p. Everything after, but
53
* not including, the specified field is cleared. */
54
#define CLEAR_AFTER_FIELD(p, field) \
55
memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \
56
0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field))
58
#define have_fmt_ops(foo) ( \
59
ops->vidioc_##foo##_fmt_vid_cap || \
60
ops->vidioc_##foo##_fmt_vid_out || \
61
ops->vidioc_##foo##_fmt_vid_cap_mplane || \
62
ops->vidioc_##foo##_fmt_vid_out_mplane || \
63
ops->vidioc_##foo##_fmt_vid_overlay || \
64
ops->vidioc_##foo##_fmt_vbi_cap || \
65
ops->vidioc_##foo##_fmt_vid_out_overlay || \
66
ops->vidioc_##foo##_fmt_vbi_out || \
67
ops->vidioc_##foo##_fmt_sliced_vbi_cap || \
68
ops->vidioc_##foo##_fmt_sliced_vbi_out || \
69
ops->vidioc_##foo##_fmt_type_private)
76
static const struct std_descr standards[] = {
77
{ V4L2_STD_NTSC, "NTSC" },
78
{ V4L2_STD_NTSC_M, "NTSC-M" },
79
{ V4L2_STD_NTSC_M_JP, "NTSC-M-JP" },
80
{ V4L2_STD_NTSC_M_KR, "NTSC-M-KR" },
81
{ V4L2_STD_NTSC_443, "NTSC-443" },
82
{ V4L2_STD_PAL, "PAL" },
83
{ V4L2_STD_PAL_BG, "PAL-BG" },
84
{ V4L2_STD_PAL_B, "PAL-B" },
85
{ V4L2_STD_PAL_B1, "PAL-B1" },
86
{ V4L2_STD_PAL_G, "PAL-G" },
87
{ V4L2_STD_PAL_H, "PAL-H" },
88
{ V4L2_STD_PAL_I, "PAL-I" },
89
{ V4L2_STD_PAL_DK, "PAL-DK" },
90
{ V4L2_STD_PAL_D, "PAL-D" },
91
{ V4L2_STD_PAL_D1, "PAL-D1" },
92
{ V4L2_STD_PAL_K, "PAL-K" },
93
{ V4L2_STD_PAL_M, "PAL-M" },
94
{ V4L2_STD_PAL_N, "PAL-N" },
95
{ V4L2_STD_PAL_Nc, "PAL-Nc" },
96
{ V4L2_STD_PAL_60, "PAL-60" },
97
{ V4L2_STD_SECAM, "SECAM" },
98
{ V4L2_STD_SECAM_B, "SECAM-B" },
99
{ V4L2_STD_SECAM_G, "SECAM-G" },
100
{ V4L2_STD_SECAM_H, "SECAM-H" },
101
{ V4L2_STD_SECAM_DK, "SECAM-DK" },
102
{ V4L2_STD_SECAM_D, "SECAM-D" },
103
{ V4L2_STD_SECAM_K, "SECAM-K" },
104
{ V4L2_STD_SECAM_K1, "SECAM-K1" },
105
{ V4L2_STD_SECAM_L, "SECAM-L" },
106
{ V4L2_STD_SECAM_LC, "SECAM-Lc" },
110
/* video4linux standard ID conversion to standard name
112
const char *v4l2_norm_to_name(v4l2_std_id id)
117
/* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
118
64 bit comparations. So, on that architecture, with some gcc
119
variants, compilation fails. Currently, the max value is 30bit wide.
123
for (i = 0; standards[i].std; i++)
124
if (myid == standards[i].std)
126
return standards[i].descr;
128
EXPORT_SYMBOL(v4l2_norm_to_name);
130
/* Returns frame period for the given standard */
131
void v4l2_video_std_frame_period(int id, struct v4l2_fract *frameperiod)
133
if (id & V4L2_STD_525_60) {
134
frameperiod->numerator = 1001;
135
frameperiod->denominator = 30000;
137
frameperiod->numerator = 1;
138
frameperiod->denominator = 25;
141
EXPORT_SYMBOL(v4l2_video_std_frame_period);
143
/* Fill in the fields of a v4l2_standard structure according to the
144
'id' and 'transmission' parameters. Returns negative on error. */
145
int v4l2_video_std_construct(struct v4l2_standard *vs,
146
int id, const char *name)
149
v4l2_video_std_frame_period(id, &vs->frameperiod);
150
vs->framelines = (id & V4L2_STD_525_60) ? 525 : 625;
151
strlcpy(vs->name, name, sizeof(vs->name));
154
EXPORT_SYMBOL(v4l2_video_std_construct);
156
/* ----------------------------------------------------------------- */
157
/* some arrays for pretty-printing debug messages of enum types */
159
const char *v4l2_field_names[] = {
160
[V4L2_FIELD_ANY] = "any",
161
[V4L2_FIELD_NONE] = "none",
162
[V4L2_FIELD_TOP] = "top",
163
[V4L2_FIELD_BOTTOM] = "bottom",
164
[V4L2_FIELD_INTERLACED] = "interlaced",
165
[V4L2_FIELD_SEQ_TB] = "seq-tb",
166
[V4L2_FIELD_SEQ_BT] = "seq-bt",
167
[V4L2_FIELD_ALTERNATE] = "alternate",
168
[V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
169
[V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
171
EXPORT_SYMBOL(v4l2_field_names);
173
const char *v4l2_type_names[] = {
174
[V4L2_BUF_TYPE_VIDEO_CAPTURE] = "vid-cap",
175
[V4L2_BUF_TYPE_VIDEO_OVERLAY] = "vid-overlay",
176
[V4L2_BUF_TYPE_VIDEO_OUTPUT] = "vid-out",
177
[V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
178
[V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
179
[V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
180
[V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out",
181
[V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "vid-out-overlay",
182
[V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE] = "vid-cap-mplane",
183
[V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE] = "vid-out-mplane",
185
EXPORT_SYMBOL(v4l2_type_names);
187
static const char *v4l2_memory_names[] = {
188
[V4L2_MEMORY_MMAP] = "mmap",
189
[V4L2_MEMORY_USERPTR] = "userptr",
190
[V4L2_MEMORY_OVERLAY] = "overlay",
193
#define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
196
/* ------------------------------------------------------------------ */
197
/* debug help functions */
198
static const char *v4l2_ioctls[] = {
199
[_IOC_NR(VIDIOC_QUERYCAP)] = "VIDIOC_QUERYCAP",
200
[_IOC_NR(VIDIOC_RESERVED)] = "VIDIOC_RESERVED",
201
[_IOC_NR(VIDIOC_ENUM_FMT)] = "VIDIOC_ENUM_FMT",
202
[_IOC_NR(VIDIOC_G_FMT)] = "VIDIOC_G_FMT",
203
[_IOC_NR(VIDIOC_S_FMT)] = "VIDIOC_S_FMT",
204
[_IOC_NR(VIDIOC_REQBUFS)] = "VIDIOC_REQBUFS",
205
[_IOC_NR(VIDIOC_QUERYBUF)] = "VIDIOC_QUERYBUF",
206
[_IOC_NR(VIDIOC_G_FBUF)] = "VIDIOC_G_FBUF",
207
[_IOC_NR(VIDIOC_S_FBUF)] = "VIDIOC_S_FBUF",
208
[_IOC_NR(VIDIOC_OVERLAY)] = "VIDIOC_OVERLAY",
209
[_IOC_NR(VIDIOC_QBUF)] = "VIDIOC_QBUF",
210
[_IOC_NR(VIDIOC_DQBUF)] = "VIDIOC_DQBUF",
211
[_IOC_NR(VIDIOC_STREAMON)] = "VIDIOC_STREAMON",
212
[_IOC_NR(VIDIOC_STREAMOFF)] = "VIDIOC_STREAMOFF",
213
[_IOC_NR(VIDIOC_G_PARM)] = "VIDIOC_G_PARM",
214
[_IOC_NR(VIDIOC_S_PARM)] = "VIDIOC_S_PARM",
215
[_IOC_NR(VIDIOC_G_STD)] = "VIDIOC_G_STD",
216
[_IOC_NR(VIDIOC_S_STD)] = "VIDIOC_S_STD",
217
[_IOC_NR(VIDIOC_ENUMSTD)] = "VIDIOC_ENUMSTD",
218
[_IOC_NR(VIDIOC_ENUMINPUT)] = "VIDIOC_ENUMINPUT",
219
[_IOC_NR(VIDIOC_G_CTRL)] = "VIDIOC_G_CTRL",
220
[_IOC_NR(VIDIOC_S_CTRL)] = "VIDIOC_S_CTRL",
221
[_IOC_NR(VIDIOC_G_TUNER)] = "VIDIOC_G_TUNER",
222
[_IOC_NR(VIDIOC_S_TUNER)] = "VIDIOC_S_TUNER",
223
[_IOC_NR(VIDIOC_G_AUDIO)] = "VIDIOC_G_AUDIO",
224
[_IOC_NR(VIDIOC_S_AUDIO)] = "VIDIOC_S_AUDIO",
225
[_IOC_NR(VIDIOC_QUERYCTRL)] = "VIDIOC_QUERYCTRL",
226
[_IOC_NR(VIDIOC_QUERYMENU)] = "VIDIOC_QUERYMENU",
227
[_IOC_NR(VIDIOC_G_INPUT)] = "VIDIOC_G_INPUT",
228
[_IOC_NR(VIDIOC_S_INPUT)] = "VIDIOC_S_INPUT",
229
[_IOC_NR(VIDIOC_G_OUTPUT)] = "VIDIOC_G_OUTPUT",
230
[_IOC_NR(VIDIOC_S_OUTPUT)] = "VIDIOC_S_OUTPUT",
231
[_IOC_NR(VIDIOC_ENUMOUTPUT)] = "VIDIOC_ENUMOUTPUT",
232
[_IOC_NR(VIDIOC_G_AUDOUT)] = "VIDIOC_G_AUDOUT",
233
[_IOC_NR(VIDIOC_S_AUDOUT)] = "VIDIOC_S_AUDOUT",
234
[_IOC_NR(VIDIOC_G_MODULATOR)] = "VIDIOC_G_MODULATOR",
235
[_IOC_NR(VIDIOC_S_MODULATOR)] = "VIDIOC_S_MODULATOR",
236
[_IOC_NR(VIDIOC_G_FREQUENCY)] = "VIDIOC_G_FREQUENCY",
237
[_IOC_NR(VIDIOC_S_FREQUENCY)] = "VIDIOC_S_FREQUENCY",
238
[_IOC_NR(VIDIOC_CROPCAP)] = "VIDIOC_CROPCAP",
239
[_IOC_NR(VIDIOC_G_CROP)] = "VIDIOC_G_CROP",
240
[_IOC_NR(VIDIOC_S_CROP)] = "VIDIOC_S_CROP",
241
[_IOC_NR(VIDIOC_G_JPEGCOMP)] = "VIDIOC_G_JPEGCOMP",
242
[_IOC_NR(VIDIOC_S_JPEGCOMP)] = "VIDIOC_S_JPEGCOMP",
243
[_IOC_NR(VIDIOC_QUERYSTD)] = "VIDIOC_QUERYSTD",
244
[_IOC_NR(VIDIOC_TRY_FMT)] = "VIDIOC_TRY_FMT",
245
[_IOC_NR(VIDIOC_ENUMAUDIO)] = "VIDIOC_ENUMAUDIO",
246
[_IOC_NR(VIDIOC_ENUMAUDOUT)] = "VIDIOC_ENUMAUDOUT",
247
[_IOC_NR(VIDIOC_G_PRIORITY)] = "VIDIOC_G_PRIORITY",
248
[_IOC_NR(VIDIOC_S_PRIORITY)] = "VIDIOC_S_PRIORITY",
249
[_IOC_NR(VIDIOC_G_SLICED_VBI_CAP)] = "VIDIOC_G_SLICED_VBI_CAP",
250
[_IOC_NR(VIDIOC_LOG_STATUS)] = "VIDIOC_LOG_STATUS",
251
[_IOC_NR(VIDIOC_G_EXT_CTRLS)] = "VIDIOC_G_EXT_CTRLS",
252
[_IOC_NR(VIDIOC_S_EXT_CTRLS)] = "VIDIOC_S_EXT_CTRLS",
253
[_IOC_NR(VIDIOC_TRY_EXT_CTRLS)] = "VIDIOC_TRY_EXT_CTRLS",
255
[_IOC_NR(VIDIOC_ENUM_FRAMESIZES)] = "VIDIOC_ENUM_FRAMESIZES",
256
[_IOC_NR(VIDIOC_ENUM_FRAMEINTERVALS)] = "VIDIOC_ENUM_FRAMEINTERVALS",
257
[_IOC_NR(VIDIOC_G_ENC_INDEX)] = "VIDIOC_G_ENC_INDEX",
258
[_IOC_NR(VIDIOC_ENCODER_CMD)] = "VIDIOC_ENCODER_CMD",
259
[_IOC_NR(VIDIOC_TRY_ENCODER_CMD)] = "VIDIOC_TRY_ENCODER_CMD",
261
[_IOC_NR(VIDIOC_DBG_S_REGISTER)] = "VIDIOC_DBG_S_REGISTER",
262
[_IOC_NR(VIDIOC_DBG_G_REGISTER)] = "VIDIOC_DBG_G_REGISTER",
264
[_IOC_NR(VIDIOC_DBG_G_CHIP_IDENT)] = "VIDIOC_DBG_G_CHIP_IDENT",
265
[_IOC_NR(VIDIOC_S_HW_FREQ_SEEK)] = "VIDIOC_S_HW_FREQ_SEEK",
267
[_IOC_NR(VIDIOC_ENUM_DV_PRESETS)] = "VIDIOC_ENUM_DV_PRESETS",
268
[_IOC_NR(VIDIOC_S_DV_PRESET)] = "VIDIOC_S_DV_PRESET",
269
[_IOC_NR(VIDIOC_G_DV_PRESET)] = "VIDIOC_G_DV_PRESET",
270
[_IOC_NR(VIDIOC_QUERY_DV_PRESET)] = "VIDIOC_QUERY_DV_PRESET",
271
[_IOC_NR(VIDIOC_S_DV_TIMINGS)] = "VIDIOC_S_DV_TIMINGS",
272
[_IOC_NR(VIDIOC_G_DV_TIMINGS)] = "VIDIOC_G_DV_TIMINGS",
273
[_IOC_NR(VIDIOC_DQEVENT)] = "VIDIOC_DQEVENT",
274
[_IOC_NR(VIDIOC_SUBSCRIBE_EVENT)] = "VIDIOC_SUBSCRIBE_EVENT",
275
[_IOC_NR(VIDIOC_UNSUBSCRIBE_EVENT)] = "VIDIOC_UNSUBSCRIBE_EVENT",
276
[_IOC_NR(VIDIOC_CREATE_BUFS)] = "VIDIOC_CREATE_BUFS",
277
[_IOC_NR(VIDIOC_PREPARE_BUF)] = "VIDIOC_PREPARE_BUF",
279
#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
281
/* Common ioctl debug function. This function can be used by
282
external ioctl messages as well as internal V4L ioctl */
283
void v4l_printk_ioctl(unsigned int cmd)
287
switch (_IOC_TYPE(cmd)) {
292
if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
296
printk("%s", v4l2_ioctls[_IOC_NR(cmd)]);
302
switch (_IOC_DIR(cmd)) {
303
case _IOC_NONE: dir = "--"; break;
304
case _IOC_READ: dir = "r-"; break;
305
case _IOC_WRITE: dir = "-w"; break;
306
case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
307
default: dir = "*ERR*"; break;
309
printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
310
type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
312
EXPORT_SYMBOL(v4l_printk_ioctl);
314
static void dbgbuf(unsigned int cmd, struct video_device *vfd,
315
struct v4l2_buffer *p)
317
struct v4l2_timecode *tc = &p->timecode;
318
struct v4l2_plane *plane;
321
dbgarg(cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
322
"flags=0x%08d, field=%0d, sequence=%d, memory=%s\n",
323
p->timestamp.tv_sec / 3600,
324
(int)(p->timestamp.tv_sec / 60) % 60,
325
(int)(p->timestamp.tv_sec % 60),
326
(long)p->timestamp.tv_usec,
328
prt_names(p->type, v4l2_type_names),
329
p->flags, p->field, p->sequence,
330
prt_names(p->memory, v4l2_memory_names));
332
if (V4L2_TYPE_IS_MULTIPLANAR(p->type) && p->m.planes) {
333
for (i = 0; i < p->length; ++i) {
334
plane = &p->m.planes[i];
335
dbgarg2("plane %d: bytesused=%d, data_offset=0x%08x "
336
"offset/userptr=0x%08lx, length=%d\n",
337
i, plane->bytesused, plane->data_offset,
338
plane->m.userptr, plane->length);
341
dbgarg2("bytesused=%d, offset/userptr=0x%08lx, length=%d\n",
342
p->bytesused, p->m.userptr, p->length);
345
dbgarg2("timecode=%02d:%02d:%02d type=%d, "
346
"flags=0x%08d, frames=%d, userbits=0x%08x\n",
347
tc->hours, tc->minutes, tc->seconds,
348
tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits);
351
static inline void dbgrect(struct video_device *vfd, char *s,
354
dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s, r->left, r->top,
355
r->width, r->height);
358
static inline void v4l_print_pix_fmt(struct video_device *vfd,
359
struct v4l2_pix_format *fmt)
361
dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
362
"bytesperline=%d sizeimage=%d, colorspace=%d\n",
363
fmt->width, fmt->height,
364
(fmt->pixelformat & 0xff),
365
(fmt->pixelformat >> 8) & 0xff,
366
(fmt->pixelformat >> 16) & 0xff,
367
(fmt->pixelformat >> 24) & 0xff,
368
prt_names(fmt->field, v4l2_field_names),
369
fmt->bytesperline, fmt->sizeimage, fmt->colorspace);
372
static inline void v4l_print_pix_fmt_mplane(struct video_device *vfd,
373
struct v4l2_pix_format_mplane *fmt)
377
dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
378
"colorspace=%d, num_planes=%d\n",
379
fmt->width, fmt->height,
380
(fmt->pixelformat & 0xff),
381
(fmt->pixelformat >> 8) & 0xff,
382
(fmt->pixelformat >> 16) & 0xff,
383
(fmt->pixelformat >> 24) & 0xff,
384
prt_names(fmt->field, v4l2_field_names),
385
fmt->colorspace, fmt->num_planes);
387
for (i = 0; i < fmt->num_planes; ++i)
388
dbgarg2("plane %d: bytesperline=%d sizeimage=%d\n", i,
389
fmt->plane_fmt[i].bytesperline,
390
fmt->plane_fmt[i].sizeimage);
393
static inline void v4l_print_ext_ctrls(unsigned int cmd,
394
struct video_device *vfd, struct v4l2_ext_controls *c, int show_vals)
398
if (!(vfd->debug & V4L2_DEBUG_IOCTL_ARG))
401
printk(KERN_CONT "class=0x%x", c->ctrl_class);
402
for (i = 0; i < c->count; i++) {
403
if (show_vals && !c->controls[i].size)
404
printk(KERN_CONT " id/val=0x%x/0x%x",
405
c->controls[i].id, c->controls[i].value);
407
printk(KERN_CONT " id=0x%x,size=%u",
408
c->controls[i].id, c->controls[i].size);
410
printk(KERN_CONT "\n");
413
static inline int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
417
/* zero the reserved fields */
418
c->reserved[0] = c->reserved[1] = 0;
419
for (i = 0; i < c->count; i++)
420
c->controls[i].reserved2[0] = 0;
422
/* V4L2_CID_PRIVATE_BASE cannot be used as control class
423
when using extended controls.
424
Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
425
is it allowed for backwards compatibility.
427
if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE)
429
/* Check that all controls are from the same control class. */
430
for (i = 0; i < c->count; i++) {
431
if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) {
439
static int check_fmt(const struct v4l2_ioctl_ops *ops, enum v4l2_buf_type type)
445
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
446
if (ops->vidioc_g_fmt_vid_cap ||
447
ops->vidioc_g_fmt_vid_cap_mplane)
450
case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
451
if (ops->vidioc_g_fmt_vid_cap_mplane)
454
case V4L2_BUF_TYPE_VIDEO_OVERLAY:
455
if (ops->vidioc_g_fmt_vid_overlay)
458
case V4L2_BUF_TYPE_VIDEO_OUTPUT:
459
if (ops->vidioc_g_fmt_vid_out ||
460
ops->vidioc_g_fmt_vid_out_mplane)
463
case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
464
if (ops->vidioc_g_fmt_vid_out_mplane)
467
case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
468
if (ops->vidioc_g_fmt_vid_out_overlay)
471
case V4L2_BUF_TYPE_VBI_CAPTURE:
472
if (ops->vidioc_g_fmt_vbi_cap)
475
case V4L2_BUF_TYPE_VBI_OUTPUT:
476
if (ops->vidioc_g_fmt_vbi_out)
479
case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
480
if (ops->vidioc_g_fmt_sliced_vbi_cap)
483
case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
484
if (ops->vidioc_g_fmt_sliced_vbi_out)
487
case V4L2_BUF_TYPE_PRIVATE:
488
if (ops->vidioc_g_fmt_type_private)
495
static long __video_do_ioctl(struct file *file,
496
unsigned int cmd, void *arg)
498
struct video_device *vfd = video_devdata(file);
499
const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
500
void *fh = file->private_data;
501
struct v4l2_fh *vfh = NULL;
507
printk(KERN_WARNING "videodev: \"%s\" has no ioctl_ops.\n",
512
if ((vfd->debug & V4L2_DEBUG_IOCTL) &&
513
!(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
514
v4l_print_ioctl(vfd->name, cmd);
515
printk(KERN_CONT "\n");
518
if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) {
519
vfh = file->private_data;
520
use_fh_prio = test_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
524
ret_prio = v4l2_prio_check(vfd->prio, vfh->prio);
528
/* --- capabilities ------------------------------------------ */
529
case VIDIOC_QUERYCAP:
531
struct v4l2_capability *cap = (struct v4l2_capability *)arg;
533
if (!ops->vidioc_querycap)
536
cap->version = LINUX_VERSION_CODE;
537
ret = ops->vidioc_querycap(file, fh, cap);
539
dbgarg(cmd, "driver=%s, card=%s, bus=%s, "
541
"capabilities=0x%08x\n",
542
cap->driver, cap->card, cap->bus_info,
548
/* --- priority ------------------------------------------ */
549
case VIDIOC_G_PRIORITY:
551
enum v4l2_priority *p = arg;
553
if (ops->vidioc_g_priority) {
554
ret = ops->vidioc_g_priority(file, fh, p);
555
} else if (use_fh_prio) {
556
*p = v4l2_prio_max(&vfd->v4l2_dev->prio);
560
dbgarg(cmd, "priority is %d\n", *p);
563
case VIDIOC_S_PRIORITY:
565
enum v4l2_priority *p = arg;
567
if (!ops->vidioc_s_priority && !use_fh_prio)
569
dbgarg(cmd, "setting priority to %d\n", *p);
570
if (ops->vidioc_s_priority)
571
ret = ops->vidioc_s_priority(file, fh, *p);
573
ret = ret_prio ? ret_prio :
574
v4l2_prio_change(&vfd->v4l2_dev->prio,
579
/* --- capture ioctls ---------------------------------------- */
580
case VIDIOC_ENUM_FMT:
582
struct v4l2_fmtdesc *f = arg;
585
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
586
if (likely(ops->vidioc_enum_fmt_vid_cap))
587
ret = ops->vidioc_enum_fmt_vid_cap(file, fh, f);
589
case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
590
if (likely(ops->vidioc_enum_fmt_vid_cap_mplane))
591
ret = ops->vidioc_enum_fmt_vid_cap_mplane(file,
594
case V4L2_BUF_TYPE_VIDEO_OVERLAY:
595
if (likely(ops->vidioc_enum_fmt_vid_overlay))
596
ret = ops->vidioc_enum_fmt_vid_overlay(file,
599
case V4L2_BUF_TYPE_VIDEO_OUTPUT:
600
if (likely(ops->vidioc_enum_fmt_vid_out))
601
ret = ops->vidioc_enum_fmt_vid_out(file, fh, f);
603
case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
604
if (likely(ops->vidioc_enum_fmt_vid_out_mplane))
605
ret = ops->vidioc_enum_fmt_vid_out_mplane(file,
608
case V4L2_BUF_TYPE_PRIVATE:
609
if (likely(ops->vidioc_enum_fmt_type_private))
610
ret = ops->vidioc_enum_fmt_type_private(file,
617
dbgarg(cmd, "index=%d, type=%d, flags=%d, "
618
"pixelformat=%c%c%c%c, description='%s'\n",
619
f->index, f->type, f->flags,
620
(f->pixelformat & 0xff),
621
(f->pixelformat >> 8) & 0xff,
622
(f->pixelformat >> 16) & 0xff,
623
(f->pixelformat >> 24) & 0xff,
625
else if (ret == -ENOTTY &&
626
(ops->vidioc_enum_fmt_vid_cap ||
627
ops->vidioc_enum_fmt_vid_out ||
628
ops->vidioc_enum_fmt_vid_cap_mplane ||
629
ops->vidioc_enum_fmt_vid_out_mplane ||
630
ops->vidioc_enum_fmt_vid_overlay ||
631
ops->vidioc_enum_fmt_type_private))
637
struct v4l2_format *f = (struct v4l2_format *)arg;
639
/* FIXME: Should be one dump per type */
640
dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
643
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
644
if (ops->vidioc_g_fmt_vid_cap)
645
ret = ops->vidioc_g_fmt_vid_cap(file, fh, f);
647
v4l_print_pix_fmt(vfd, &f->fmt.pix);
649
case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
650
if (ops->vidioc_g_fmt_vid_cap_mplane)
651
ret = ops->vidioc_g_fmt_vid_cap_mplane(file,
654
v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
656
case V4L2_BUF_TYPE_VIDEO_OVERLAY:
657
if (likely(ops->vidioc_g_fmt_vid_overlay))
658
ret = ops->vidioc_g_fmt_vid_overlay(file,
661
case V4L2_BUF_TYPE_VIDEO_OUTPUT:
662
if (ops->vidioc_g_fmt_vid_out)
663
ret = ops->vidioc_g_fmt_vid_out(file, fh, f);
665
v4l_print_pix_fmt(vfd, &f->fmt.pix);
667
case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
668
if (ops->vidioc_g_fmt_vid_out_mplane)
669
ret = ops->vidioc_g_fmt_vid_out_mplane(file,
672
v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
674
case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
675
if (likely(ops->vidioc_g_fmt_vid_out_overlay))
676
ret = ops->vidioc_g_fmt_vid_out_overlay(file,
679
case V4L2_BUF_TYPE_VBI_CAPTURE:
680
if (likely(ops->vidioc_g_fmt_vbi_cap))
681
ret = ops->vidioc_g_fmt_vbi_cap(file, fh, f);
683
case V4L2_BUF_TYPE_VBI_OUTPUT:
684
if (likely(ops->vidioc_g_fmt_vbi_out))
685
ret = ops->vidioc_g_fmt_vbi_out(file, fh, f);
687
case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
688
if (likely(ops->vidioc_g_fmt_sliced_vbi_cap))
689
ret = ops->vidioc_g_fmt_sliced_vbi_cap(file,
692
case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
693
if (likely(ops->vidioc_g_fmt_sliced_vbi_out))
694
ret = ops->vidioc_g_fmt_sliced_vbi_out(file,
697
case V4L2_BUF_TYPE_PRIVATE:
698
if (likely(ops->vidioc_g_fmt_type_private))
699
ret = ops->vidioc_g_fmt_type_private(file,
703
if (unlikely(ret == -ENOTTY && have_fmt_ops(g)))
710
struct v4l2_format *f = (struct v4l2_format *)arg;
712
if (!have_fmt_ops(s))
720
/* FIXME: Should be one dump per type */
721
dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
724
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
725
CLEAR_AFTER_FIELD(f, fmt.pix);
726
v4l_print_pix_fmt(vfd, &f->fmt.pix);
727
if (ops->vidioc_s_fmt_vid_cap)
728
ret = ops->vidioc_s_fmt_vid_cap(file, fh, f);
730
case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
731
CLEAR_AFTER_FIELD(f, fmt.pix_mp);
732
v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
733
if (ops->vidioc_s_fmt_vid_cap_mplane)
734
ret = ops->vidioc_s_fmt_vid_cap_mplane(file,
737
case V4L2_BUF_TYPE_VIDEO_OVERLAY:
738
CLEAR_AFTER_FIELD(f, fmt.win);
739
if (ops->vidioc_s_fmt_vid_overlay)
740
ret = ops->vidioc_s_fmt_vid_overlay(file,
743
case V4L2_BUF_TYPE_VIDEO_OUTPUT:
744
CLEAR_AFTER_FIELD(f, fmt.pix);
745
v4l_print_pix_fmt(vfd, &f->fmt.pix);
746
if (ops->vidioc_s_fmt_vid_out)
747
ret = ops->vidioc_s_fmt_vid_out(file, fh, f);
749
case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
750
CLEAR_AFTER_FIELD(f, fmt.pix_mp);
751
v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
752
if (ops->vidioc_s_fmt_vid_out_mplane)
753
ret = ops->vidioc_s_fmt_vid_out_mplane(file,
756
case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
757
CLEAR_AFTER_FIELD(f, fmt.win);
758
if (ops->vidioc_s_fmt_vid_out_overlay)
759
ret = ops->vidioc_s_fmt_vid_out_overlay(file,
762
case V4L2_BUF_TYPE_VBI_CAPTURE:
763
CLEAR_AFTER_FIELD(f, fmt.vbi);
764
if (likely(ops->vidioc_s_fmt_vbi_cap))
765
ret = ops->vidioc_s_fmt_vbi_cap(file, fh, f);
767
case V4L2_BUF_TYPE_VBI_OUTPUT:
768
CLEAR_AFTER_FIELD(f, fmt.vbi);
769
if (likely(ops->vidioc_s_fmt_vbi_out))
770
ret = ops->vidioc_s_fmt_vbi_out(file, fh, f);
772
case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
773
CLEAR_AFTER_FIELD(f, fmt.sliced);
774
if (likely(ops->vidioc_s_fmt_sliced_vbi_cap))
775
ret = ops->vidioc_s_fmt_sliced_vbi_cap(file,
778
case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
779
CLEAR_AFTER_FIELD(f, fmt.sliced);
780
if (likely(ops->vidioc_s_fmt_sliced_vbi_out))
781
ret = ops->vidioc_s_fmt_sliced_vbi_out(file,
785
case V4L2_BUF_TYPE_PRIVATE:
786
/* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
787
if (likely(ops->vidioc_s_fmt_type_private))
788
ret = ops->vidioc_s_fmt_type_private(file,
796
struct v4l2_format *f = (struct v4l2_format *)arg;
798
/* FIXME: Should be one dump per type */
799
dbgarg(cmd, "type=%s\n", prt_names(f->type,
802
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
803
CLEAR_AFTER_FIELD(f, fmt.pix);
804
if (ops->vidioc_try_fmt_vid_cap)
805
ret = ops->vidioc_try_fmt_vid_cap(file, fh, f);
807
v4l_print_pix_fmt(vfd, &f->fmt.pix);
809
case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
810
CLEAR_AFTER_FIELD(f, fmt.pix_mp);
811
if (ops->vidioc_try_fmt_vid_cap_mplane)
812
ret = ops->vidioc_try_fmt_vid_cap_mplane(file,
815
v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
817
case V4L2_BUF_TYPE_VIDEO_OVERLAY:
818
CLEAR_AFTER_FIELD(f, fmt.win);
819
if (likely(ops->vidioc_try_fmt_vid_overlay))
820
ret = ops->vidioc_try_fmt_vid_overlay(file,
823
case V4L2_BUF_TYPE_VIDEO_OUTPUT:
824
CLEAR_AFTER_FIELD(f, fmt.pix);
825
if (ops->vidioc_try_fmt_vid_out)
826
ret = ops->vidioc_try_fmt_vid_out(file, fh, f);
828
v4l_print_pix_fmt(vfd, &f->fmt.pix);
830
case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
831
CLEAR_AFTER_FIELD(f, fmt.pix_mp);
832
if (ops->vidioc_try_fmt_vid_out_mplane)
833
ret = ops->vidioc_try_fmt_vid_out_mplane(file,
836
v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
838
case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
839
CLEAR_AFTER_FIELD(f, fmt.win);
840
if (likely(ops->vidioc_try_fmt_vid_out_overlay))
841
ret = ops->vidioc_try_fmt_vid_out_overlay(file,
844
case V4L2_BUF_TYPE_VBI_CAPTURE:
845
CLEAR_AFTER_FIELD(f, fmt.vbi);
846
if (likely(ops->vidioc_try_fmt_vbi_cap))
847
ret = ops->vidioc_try_fmt_vbi_cap(file, fh, f);
849
case V4L2_BUF_TYPE_VBI_OUTPUT:
850
CLEAR_AFTER_FIELD(f, fmt.vbi);
851
if (likely(ops->vidioc_try_fmt_vbi_out))
852
ret = ops->vidioc_try_fmt_vbi_out(file, fh, f);
854
case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
855
CLEAR_AFTER_FIELD(f, fmt.sliced);
856
if (likely(ops->vidioc_try_fmt_sliced_vbi_cap))
857
ret = ops->vidioc_try_fmt_sliced_vbi_cap(file,
860
case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
861
CLEAR_AFTER_FIELD(f, fmt.sliced);
862
if (likely(ops->vidioc_try_fmt_sliced_vbi_out))
863
ret = ops->vidioc_try_fmt_sliced_vbi_out(file,
866
case V4L2_BUF_TYPE_PRIVATE:
867
/* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
868
if (likely(ops->vidioc_try_fmt_type_private))
869
ret = ops->vidioc_try_fmt_type_private(file,
873
if (unlikely(ret == -ENOTTY && have_fmt_ops(try)))
877
/* FIXME: Those buf reqs could be handled here,
878
with some changes on videobuf to allow its header to be included at
879
videodev2.h or being merged at videodev2.
883
struct v4l2_requestbuffers *p = arg;
885
if (!ops->vidioc_reqbufs)
891
ret = check_fmt(ops, p->type);
895
if (p->type < V4L2_BUF_TYPE_PRIVATE)
896
CLEAR_AFTER_FIELD(p, memory);
898
ret = ops->vidioc_reqbufs(file, fh, p);
899
dbgarg(cmd, "count=%d, type=%s, memory=%s\n",
901
prt_names(p->type, v4l2_type_names),
902
prt_names(p->memory, v4l2_memory_names));
905
case VIDIOC_QUERYBUF:
907
struct v4l2_buffer *p = arg;
909
if (!ops->vidioc_querybuf)
911
ret = check_fmt(ops, p->type);
915
ret = ops->vidioc_querybuf(file, fh, p);
922
struct v4l2_buffer *p = arg;
924
if (!ops->vidioc_qbuf)
926
ret = check_fmt(ops, p->type);
930
ret = ops->vidioc_qbuf(file, fh, p);
937
struct v4l2_buffer *p = arg;
939
if (!ops->vidioc_dqbuf)
941
ret = check_fmt(ops, p->type);
945
ret = ops->vidioc_dqbuf(file, fh, p);
954
if (!ops->vidioc_overlay)
960
dbgarg(cmd, "value=%d\n", *i);
961
ret = ops->vidioc_overlay(file, fh, *i);
966
struct v4l2_framebuffer *p = arg;
968
if (!ops->vidioc_g_fbuf)
970
ret = ops->vidioc_g_fbuf(file, fh, arg);
972
dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
973
p->capability, p->flags,
974
(unsigned long)p->base);
975
v4l_print_pix_fmt(vfd, &p->fmt);
981
struct v4l2_framebuffer *p = arg;
983
if (!ops->vidioc_s_fbuf)
989
dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
990
p->capability, p->flags, (unsigned long)p->base);
991
v4l_print_pix_fmt(vfd, &p->fmt);
992
ret = ops->vidioc_s_fbuf(file, fh, arg);
995
case VIDIOC_STREAMON:
997
enum v4l2_buf_type i = *(int *)arg;
999
if (!ops->vidioc_streamon)
1005
dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
1006
ret = ops->vidioc_streamon(file, fh, i);
1009
case VIDIOC_STREAMOFF:
1011
enum v4l2_buf_type i = *(int *)arg;
1013
if (!ops->vidioc_streamoff)
1019
dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
1020
ret = ops->vidioc_streamoff(file, fh, i);
1023
/* ---------- tv norms ---------- */
1024
case VIDIOC_ENUMSTD:
1026
struct v4l2_standard *p = arg;
1027
v4l2_std_id id = vfd->tvnorms, curr_id = 0;
1028
unsigned int index = p->index, i, j = 0;
1029
const char *descr = "";
1035
/* Return norm array in a canonical way */
1036
for (i = 0; i <= index && id; i++) {
1037
/* last std value in the standards array is 0, so this
1038
while always ends there since (id & 0) == 0. */
1039
while ((id & standards[j].std) != standards[j].std)
1041
curr_id = standards[j].std;
1042
descr = standards[j].descr;
1046
if (curr_id != V4L2_STD_PAL &&
1047
curr_id != V4L2_STD_SECAM &&
1048
curr_id != V4L2_STD_NTSC)
1054
v4l2_video_std_construct(p, curr_id, descr);
1056
dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1057
"framelines=%d\n", p->index,
1058
(unsigned long long)p->id, p->name,
1059
p->frameperiod.numerator,
1060
p->frameperiod.denominator,
1068
v4l2_std_id *id = arg;
1070
/* Calls the specific handler */
1071
if (ops->vidioc_g_std)
1072
ret = ops->vidioc_g_std(file, fh, id);
1073
else if (vfd->current_norm) {
1075
*id = vfd->current_norm;
1079
dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id);
1084
v4l2_std_id *id = arg, norm;
1086
dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id);
1088
if (!ops->vidioc_s_std)
1096
norm = (*id) & vfd->tvnorms;
1097
if (vfd->tvnorms && !norm) /* Check if std is supported */
1100
/* Calls the specific handler */
1101
ret = ops->vidioc_s_std(file, fh, &norm);
1103
/* Updates standard information */
1105
vfd->current_norm = norm;
1108
case VIDIOC_QUERYSTD:
1110
v4l2_std_id *p = arg;
1112
if (!ops->vidioc_querystd)
1115
* If nothing detected, it should return all supported
1116
* Drivers just need to mask the std argument, in order
1117
* to remove the standards that don't apply from the mask.
1118
* This means that tuners, audio and video decoders can join
1119
* their efforts to improve the standards detection
1122
ret = ops->vidioc_querystd(file, fh, arg);
1124
dbgarg(cmd, "detected std=%08Lx\n",
1125
(unsigned long long)*p);
1128
/* ------ input switching ---------- */
1129
/* FIXME: Inputs can be handled inside videodev2 */
1130
case VIDIOC_ENUMINPUT:
1132
struct v4l2_input *p = arg;
1135
* We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1136
* CAP_STD here based on ioctl handler provided by the
1137
* driver. If the driver doesn't support these
1138
* for a specific input, it must override these flags.
1140
if (ops->vidioc_s_std)
1141
p->capabilities |= V4L2_IN_CAP_STD;
1142
if (ops->vidioc_s_dv_preset)
1143
p->capabilities |= V4L2_IN_CAP_PRESETS;
1144
if (ops->vidioc_s_dv_timings)
1145
p->capabilities |= V4L2_IN_CAP_CUSTOM_TIMINGS;
1147
if (!ops->vidioc_enum_input)
1150
ret = ops->vidioc_enum_input(file, fh, p);
1152
dbgarg(cmd, "index=%d, name=%s, type=%d, "
1154
"tuner=%d, std=%08Lx, status=%d\n",
1155
p->index, p->name, p->type, p->audioset,
1157
(unsigned long long)p->std,
1161
case VIDIOC_G_INPUT:
1163
unsigned int *i = arg;
1165
if (!ops->vidioc_g_input)
1167
ret = ops->vidioc_g_input(file, fh, i);
1169
dbgarg(cmd, "value=%d\n", *i);
1172
case VIDIOC_S_INPUT:
1174
unsigned int *i = arg;
1176
if (!ops->vidioc_s_input)
1182
dbgarg(cmd, "value=%d\n", *i);
1183
ret = ops->vidioc_s_input(file, fh, *i);
1187
/* ------ output switching ---------- */
1188
case VIDIOC_ENUMOUTPUT:
1190
struct v4l2_output *p = arg;
1192
if (!ops->vidioc_enum_output)
1196
* We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
1197
* CAP_STD here based on ioctl handler provided by the
1198
* driver. If the driver doesn't support these
1199
* for a specific output, it must override these flags.
1201
if (ops->vidioc_s_std)
1202
p->capabilities |= V4L2_OUT_CAP_STD;
1203
if (ops->vidioc_s_dv_preset)
1204
p->capabilities |= V4L2_OUT_CAP_PRESETS;
1205
if (ops->vidioc_s_dv_timings)
1206
p->capabilities |= V4L2_OUT_CAP_CUSTOM_TIMINGS;
1208
ret = ops->vidioc_enum_output(file, fh, p);
1210
dbgarg(cmd, "index=%d, name=%s, type=%d, "
1212
"modulator=%d, std=0x%08Lx\n",
1213
p->index, p->name, p->type, p->audioset,
1214
p->modulator, (unsigned long long)p->std);
1217
case VIDIOC_G_OUTPUT:
1219
unsigned int *i = arg;
1221
if (!ops->vidioc_g_output)
1223
ret = ops->vidioc_g_output(file, fh, i);
1225
dbgarg(cmd, "value=%d\n", *i);
1228
case VIDIOC_S_OUTPUT:
1230
unsigned int *i = arg;
1232
if (!ops->vidioc_s_output)
1238
dbgarg(cmd, "value=%d\n", *i);
1239
ret = ops->vidioc_s_output(file, fh, *i);
1243
/* --- controls ---------------------------------------------- */
1244
case VIDIOC_QUERYCTRL:
1246
struct v4l2_queryctrl *p = arg;
1248
if (vfh && vfh->ctrl_handler)
1249
ret = v4l2_queryctrl(vfh->ctrl_handler, p);
1250
else if (vfd->ctrl_handler)
1251
ret = v4l2_queryctrl(vfd->ctrl_handler, p);
1252
else if (ops->vidioc_queryctrl)
1253
ret = ops->vidioc_queryctrl(file, fh, p);
1257
dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1258
"step=%d, default=%d, flags=0x%08x\n",
1259
p->id, p->type, p->name,
1260
p->minimum, p->maximum,
1261
p->step, p->default_value, p->flags);
1263
dbgarg(cmd, "id=0x%x\n", p->id);
1268
struct v4l2_control *p = arg;
1270
if (vfh && vfh->ctrl_handler)
1271
ret = v4l2_g_ctrl(vfh->ctrl_handler, p);
1272
else if (vfd->ctrl_handler)
1273
ret = v4l2_g_ctrl(vfd->ctrl_handler, p);
1274
else if (ops->vidioc_g_ctrl)
1275
ret = ops->vidioc_g_ctrl(file, fh, p);
1276
else if (ops->vidioc_g_ext_ctrls) {
1277
struct v4l2_ext_controls ctrls;
1278
struct v4l2_ext_control ctrl;
1280
ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1282
ctrls.controls = &ctrl;
1284
ctrl.value = p->value;
1285
if (check_ext_ctrls(&ctrls, 1)) {
1286
ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls);
1288
p->value = ctrl.value;
1293
dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1295
dbgarg(cmd, "id=0x%x\n", p->id);
1300
struct v4l2_control *p = arg;
1301
struct v4l2_ext_controls ctrls;
1302
struct v4l2_ext_control ctrl;
1304
if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
1305
!ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls)
1312
dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1314
if (vfh && vfh->ctrl_handler) {
1315
ret = v4l2_s_ctrl(vfh, vfh->ctrl_handler, p);
1318
if (vfd->ctrl_handler) {
1319
ret = v4l2_s_ctrl(NULL, vfd->ctrl_handler, p);
1322
if (ops->vidioc_s_ctrl) {
1323
ret = ops->vidioc_s_ctrl(file, fh, p);
1326
if (!ops->vidioc_s_ext_ctrls)
1329
ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1331
ctrls.controls = &ctrl;
1333
ctrl.value = p->value;
1334
if (check_ext_ctrls(&ctrls, 1))
1335
ret = ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
1340
case VIDIOC_G_EXT_CTRLS:
1342
struct v4l2_ext_controls *p = arg;
1344
p->error_idx = p->count;
1345
if (vfh && vfh->ctrl_handler)
1346
ret = v4l2_g_ext_ctrls(vfh->ctrl_handler, p);
1347
else if (vfd->ctrl_handler)
1348
ret = v4l2_g_ext_ctrls(vfd->ctrl_handler, p);
1349
else if (ops->vidioc_g_ext_ctrls)
1350
ret = check_ext_ctrls(p, 0) ?
1351
ops->vidioc_g_ext_ctrls(file, fh, p) :
1355
v4l_print_ext_ctrls(cmd, vfd, p, !ret);
1358
case VIDIOC_S_EXT_CTRLS:
1360
struct v4l2_ext_controls *p = arg;
1362
p->error_idx = p->count;
1363
if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
1364
!ops->vidioc_s_ext_ctrls)
1370
v4l_print_ext_ctrls(cmd, vfd, p, 1);
1371
if (vfh && vfh->ctrl_handler)
1372
ret = v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, p);
1373
else if (vfd->ctrl_handler)
1374
ret = v4l2_s_ext_ctrls(NULL, vfd->ctrl_handler, p);
1375
else if (check_ext_ctrls(p, 0))
1376
ret = ops->vidioc_s_ext_ctrls(file, fh, p);
1381
case VIDIOC_TRY_EXT_CTRLS:
1383
struct v4l2_ext_controls *p = arg;
1385
p->error_idx = p->count;
1386
if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
1387
!ops->vidioc_try_ext_ctrls)
1389
v4l_print_ext_ctrls(cmd, vfd, p, 1);
1390
if (vfh && vfh->ctrl_handler)
1391
ret = v4l2_try_ext_ctrls(vfh->ctrl_handler, p);
1392
else if (vfd->ctrl_handler)
1393
ret = v4l2_try_ext_ctrls(vfd->ctrl_handler, p);
1394
else if (check_ext_ctrls(p, 0))
1395
ret = ops->vidioc_try_ext_ctrls(file, fh, p);
1400
case VIDIOC_QUERYMENU:
1402
struct v4l2_querymenu *p = arg;
1404
if (vfh && vfh->ctrl_handler)
1405
ret = v4l2_querymenu(vfh->ctrl_handler, p);
1406
else if (vfd->ctrl_handler)
1407
ret = v4l2_querymenu(vfd->ctrl_handler, p);
1408
else if (ops->vidioc_querymenu)
1409
ret = ops->vidioc_querymenu(file, fh, p);
1413
dbgarg(cmd, "id=0x%x, index=%d, name=%s\n",
1414
p->id, p->index, p->name);
1416
dbgarg(cmd, "id=0x%x, index=%d\n",
1420
/* --- audio ---------------------------------------------- */
1421
case VIDIOC_ENUMAUDIO:
1423
struct v4l2_audio *p = arg;
1425
if (!ops->vidioc_enumaudio)
1427
ret = ops->vidioc_enumaudio(file, fh, p);
1429
dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1430
"mode=0x%x\n", p->index, p->name,
1431
p->capability, p->mode);
1433
dbgarg(cmd, "index=%d\n", p->index);
1436
case VIDIOC_G_AUDIO:
1438
struct v4l2_audio *p = arg;
1440
if (!ops->vidioc_g_audio)
1443
ret = ops->vidioc_g_audio(file, fh, p);
1445
dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1446
"mode=0x%x\n", p->index,
1447
p->name, p->capability, p->mode);
1449
dbgarg(cmd, "index=%d\n", p->index);
1452
case VIDIOC_S_AUDIO:
1454
struct v4l2_audio *p = arg;
1456
if (!ops->vidioc_s_audio)
1462
dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1463
"mode=0x%x\n", p->index, p->name,
1464
p->capability, p->mode);
1465
ret = ops->vidioc_s_audio(file, fh, p);
1468
case VIDIOC_ENUMAUDOUT:
1470
struct v4l2_audioout *p = arg;
1472
if (!ops->vidioc_enumaudout)
1474
dbgarg(cmd, "Enum for index=%d\n", p->index);
1475
ret = ops->vidioc_enumaudout(file, fh, p);
1477
dbgarg2("index=%d, name=%s, capability=%d, "
1478
"mode=%d\n", p->index, p->name,
1479
p->capability, p->mode);
1482
case VIDIOC_G_AUDOUT:
1484
struct v4l2_audioout *p = arg;
1486
if (!ops->vidioc_g_audout)
1489
ret = ops->vidioc_g_audout(file, fh, p);
1491
dbgarg2("index=%d, name=%s, capability=%d, "
1492
"mode=%d\n", p->index, p->name,
1493
p->capability, p->mode);
1496
case VIDIOC_S_AUDOUT:
1498
struct v4l2_audioout *p = arg;
1500
if (!ops->vidioc_s_audout)
1506
dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1507
"mode=%d\n", p->index, p->name,
1508
p->capability, p->mode);
1510
ret = ops->vidioc_s_audout(file, fh, p);
1513
case VIDIOC_G_MODULATOR:
1515
struct v4l2_modulator *p = arg;
1517
if (!ops->vidioc_g_modulator)
1519
ret = ops->vidioc_g_modulator(file, fh, p);
1521
dbgarg(cmd, "index=%d, name=%s, "
1522
"capability=%d, rangelow=%d,"
1523
" rangehigh=%d, txsubchans=%d\n",
1524
p->index, p->name, p->capability,
1525
p->rangelow, p->rangehigh,
1529
case VIDIOC_S_MODULATOR:
1531
struct v4l2_modulator *p = arg;
1533
if (!ops->vidioc_s_modulator)
1539
dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1540
"rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1541
p->index, p->name, p->capability, p->rangelow,
1542
p->rangehigh, p->txsubchans);
1543
ret = ops->vidioc_s_modulator(file, fh, p);
1548
struct v4l2_crop *p = arg;
1550
if (!ops->vidioc_g_crop)
1553
dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1554
ret = ops->vidioc_g_crop(file, fh, p);
1556
dbgrect(vfd, "", &p->c);
1561
struct v4l2_crop *p = arg;
1563
if (!ops->vidioc_s_crop)
1569
dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1570
dbgrect(vfd, "", &p->c);
1571
ret = ops->vidioc_s_crop(file, fh, p);
1574
case VIDIOC_CROPCAP:
1576
struct v4l2_cropcap *p = arg;
1578
/*FIXME: Should also show v4l2_fract pixelaspect */
1579
if (!ops->vidioc_cropcap)
1582
dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1583
ret = ops->vidioc_cropcap(file, fh, p);
1585
dbgrect(vfd, "bounds ", &p->bounds);
1586
dbgrect(vfd, "defrect ", &p->defrect);
1590
case VIDIOC_G_JPEGCOMP:
1592
struct v4l2_jpegcompression *p = arg;
1594
if (!ops->vidioc_g_jpegcomp)
1597
ret = ops->vidioc_g_jpegcomp(file, fh, p);
1599
dbgarg(cmd, "quality=%d, APPn=%d, "
1600
"APP_len=%d, COM_len=%d, "
1601
"jpeg_markers=%d\n",
1602
p->quality, p->APPn, p->APP_len,
1603
p->COM_len, p->jpeg_markers);
1606
case VIDIOC_S_JPEGCOMP:
1608
struct v4l2_jpegcompression *p = arg;
1610
if (!ops->vidioc_g_jpegcomp)
1616
dbgarg(cmd, "quality=%d, APPn=%d, APP_len=%d, "
1617
"COM_len=%d, jpeg_markers=%d\n",
1618
p->quality, p->APPn, p->APP_len,
1619
p->COM_len, p->jpeg_markers);
1620
ret = ops->vidioc_s_jpegcomp(file, fh, p);
1623
case VIDIOC_G_ENC_INDEX:
1625
struct v4l2_enc_idx *p = arg;
1627
if (!ops->vidioc_g_enc_index)
1629
ret = ops->vidioc_g_enc_index(file, fh, p);
1631
dbgarg(cmd, "entries=%d, entries_cap=%d\n",
1632
p->entries, p->entries_cap);
1635
case VIDIOC_ENCODER_CMD:
1637
struct v4l2_encoder_cmd *p = arg;
1639
if (!ops->vidioc_encoder_cmd)
1645
ret = ops->vidioc_encoder_cmd(file, fh, p);
1647
dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1650
case VIDIOC_TRY_ENCODER_CMD:
1652
struct v4l2_encoder_cmd *p = arg;
1654
if (!ops->vidioc_try_encoder_cmd)
1656
ret = ops->vidioc_try_encoder_cmd(file, fh, p);
1658
dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1663
struct v4l2_streamparm *p = arg;
1665
if (!ops->vidioc_g_parm && !vfd->current_norm)
1667
if (ops->vidioc_g_parm) {
1668
ret = check_fmt(ops, p->type);
1671
ret = ops->vidioc_g_parm(file, fh, p);
1673
v4l2_std_id std = vfd->current_norm;
1676
if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1680
if (ops->vidioc_g_std)
1681
ret = ops->vidioc_g_std(file, fh, &std);
1683
v4l2_video_std_frame_period(std,
1684
&p->parm.capture.timeperframe);
1687
dbgarg(cmd, "type=%d\n", p->type);
1692
struct v4l2_streamparm *p = arg;
1694
if (!ops->vidioc_s_parm)
1700
ret = check_fmt(ops, p->type);
1704
dbgarg(cmd, "type=%d\n", p->type);
1705
ret = ops->vidioc_s_parm(file, fh, p);
1708
case VIDIOC_G_TUNER:
1710
struct v4l2_tuner *p = arg;
1712
if (!ops->vidioc_g_tuner)
1715
p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1716
V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1717
ret = ops->vidioc_g_tuner(file, fh, p);
1719
dbgarg(cmd, "index=%d, name=%s, type=%d, "
1720
"capability=0x%x, rangelow=%d, "
1721
"rangehigh=%d, signal=%d, afc=%d, "
1722
"rxsubchans=0x%x, audmode=%d\n",
1723
p->index, p->name, p->type,
1724
p->capability, p->rangelow,
1725
p->rangehigh, p->signal, p->afc,
1726
p->rxsubchans, p->audmode);
1729
case VIDIOC_S_TUNER:
1731
struct v4l2_tuner *p = arg;
1733
if (!ops->vidioc_s_tuner)
1739
p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1740
V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1741
dbgarg(cmd, "index=%d, name=%s, type=%d, "
1742
"capability=0x%x, rangelow=%d, "
1743
"rangehigh=%d, signal=%d, afc=%d, "
1744
"rxsubchans=0x%x, audmode=%d\n",
1745
p->index, p->name, p->type,
1746
p->capability, p->rangelow,
1747
p->rangehigh, p->signal, p->afc,
1748
p->rxsubchans, p->audmode);
1749
ret = ops->vidioc_s_tuner(file, fh, p);
1752
case VIDIOC_G_FREQUENCY:
1754
struct v4l2_frequency *p = arg;
1756
if (!ops->vidioc_g_frequency)
1759
p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1760
V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1761
ret = ops->vidioc_g_frequency(file, fh, p);
1763
dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1764
p->tuner, p->type, p->frequency);
1767
case VIDIOC_S_FREQUENCY:
1769
struct v4l2_frequency *p = arg;
1771
if (!ops->vidioc_s_frequency)
1777
dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1778
p->tuner, p->type, p->frequency);
1779
ret = ops->vidioc_s_frequency(file, fh, p);
1782
case VIDIOC_G_SLICED_VBI_CAP:
1784
struct v4l2_sliced_vbi_cap *p = arg;
1786
if (!ops->vidioc_g_sliced_vbi_cap)
1789
/* Clear up to type, everything after type is zerod already */
1790
memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
1792
dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1793
ret = ops->vidioc_g_sliced_vbi_cap(file, fh, p);
1795
dbgarg2("service_set=%d\n", p->service_set);
1798
case VIDIOC_LOG_STATUS:
1800
if (!ops->vidioc_log_status)
1802
ret = ops->vidioc_log_status(file, fh);
1805
#ifdef CONFIG_VIDEO_ADV_DEBUG
1806
case VIDIOC_DBG_G_REGISTER:
1808
struct v4l2_dbg_register *p = arg;
1810
if (ops->vidioc_g_register) {
1811
if (!capable(CAP_SYS_ADMIN))
1814
ret = ops->vidioc_g_register(file, fh, p);
1818
case VIDIOC_DBG_S_REGISTER:
1820
struct v4l2_dbg_register *p = arg;
1822
if (ops->vidioc_s_register) {
1823
if (!capable(CAP_SYS_ADMIN))
1826
ret = ops->vidioc_s_register(file, fh, p);
1831
case VIDIOC_DBG_G_CHIP_IDENT:
1833
struct v4l2_dbg_chip_ident *p = arg;
1835
if (!ops->vidioc_g_chip_ident)
1837
p->ident = V4L2_IDENT_NONE;
1839
ret = ops->vidioc_g_chip_ident(file, fh, p);
1841
dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
1844
case VIDIOC_S_HW_FREQ_SEEK:
1846
struct v4l2_hw_freq_seek *p = arg;
1847
enum v4l2_tuner_type type;
1849
if (!ops->vidioc_s_hw_freq_seek)
1855
type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
1856
V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
1858
"tuner=%u, type=%u, seek_upward=%u, wrap_around=%u, spacing=%u\n",
1859
p->tuner, p->type, p->seek_upward, p->wrap_around, p->spacing);
1860
if (p->type != type)
1863
ret = ops->vidioc_s_hw_freq_seek(file, fh, p);
1866
case VIDIOC_ENUM_FRAMESIZES:
1868
struct v4l2_frmsizeenum *p = arg;
1870
if (!ops->vidioc_enum_framesizes)
1873
ret = ops->vidioc_enum_framesizes(file, fh, p);
1875
"index=%d, pixelformat=%c%c%c%c, type=%d ",
1877
(p->pixel_format & 0xff),
1878
(p->pixel_format >> 8) & 0xff,
1879
(p->pixel_format >> 16) & 0xff,
1880
(p->pixel_format >> 24) & 0xff,
1883
case V4L2_FRMSIZE_TYPE_DISCRETE:
1884
dbgarg3("width = %d, height=%d\n",
1885
p->discrete.width, p->discrete.height);
1887
case V4L2_FRMSIZE_TYPE_STEPWISE:
1888
dbgarg3("min %dx%d, max %dx%d, step %dx%d\n",
1889
p->stepwise.min_width, p->stepwise.min_height,
1890
p->stepwise.step_width, p->stepwise.step_height,
1891
p->stepwise.max_width, p->stepwise.max_height);
1893
case V4L2_FRMSIZE_TYPE_CONTINUOUS:
1894
dbgarg3("continuous\n");
1897
dbgarg3("- Unknown type!\n");
1902
case VIDIOC_ENUM_FRAMEINTERVALS:
1904
struct v4l2_frmivalenum *p = arg;
1906
if (!ops->vidioc_enum_frameintervals)
1909
ret = ops->vidioc_enum_frameintervals(file, fh, p);
1911
"index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
1912
p->index, p->pixel_format,
1913
p->width, p->height, p->type);
1915
case V4L2_FRMIVAL_TYPE_DISCRETE:
1916
dbgarg2("fps=%d/%d\n",
1917
p->discrete.numerator,
1918
p->discrete.denominator);
1920
case V4L2_FRMIVAL_TYPE_STEPWISE:
1921
dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
1922
p->stepwise.min.numerator,
1923
p->stepwise.min.denominator,
1924
p->stepwise.max.numerator,
1925
p->stepwise.max.denominator,
1926
p->stepwise.step.numerator,
1927
p->stepwise.step.denominator);
1929
case V4L2_FRMIVAL_TYPE_CONTINUOUS:
1930
dbgarg2("continuous\n");
1933
dbgarg2("- Unknown type!\n");
1937
case VIDIOC_ENUM_DV_PRESETS:
1939
struct v4l2_dv_enum_preset *p = arg;
1941
if (!ops->vidioc_enum_dv_presets)
1944
ret = ops->vidioc_enum_dv_presets(file, fh, p);
1947
"index=%d, preset=%d, name=%s, width=%d,"
1949
p->index, p->preset, p->name, p->width,
1953
case VIDIOC_S_DV_PRESET:
1955
struct v4l2_dv_preset *p = arg;
1957
if (!ops->vidioc_s_dv_preset)
1964
dbgarg(cmd, "preset=%d\n", p->preset);
1965
ret = ops->vidioc_s_dv_preset(file, fh, p);
1968
case VIDIOC_G_DV_PRESET:
1970
struct v4l2_dv_preset *p = arg;
1972
if (!ops->vidioc_g_dv_preset)
1975
ret = ops->vidioc_g_dv_preset(file, fh, p);
1977
dbgarg(cmd, "preset=%d\n", p->preset);
1980
case VIDIOC_QUERY_DV_PRESET:
1982
struct v4l2_dv_preset *p = arg;
1984
if (!ops->vidioc_query_dv_preset)
1987
ret = ops->vidioc_query_dv_preset(file, fh, p);
1989
dbgarg(cmd, "preset=%d\n", p->preset);
1992
case VIDIOC_S_DV_TIMINGS:
1994
struct v4l2_dv_timings *p = arg;
1996
if (!ops->vidioc_s_dv_timings)
2004
case V4L2_DV_BT_656_1120:
2005
dbgarg2("bt-656/1120:interlaced=%d, pixelclock=%lld,"
2006
" width=%d, height=%d, polarities=%x,"
2007
" hfrontporch=%d, hsync=%d, hbackporch=%d,"
2008
" vfrontporch=%d, vsync=%d, vbackporch=%d,"
2009
" il_vfrontporch=%d, il_vsync=%d,"
2010
" il_vbackporch=%d\n",
2011
p->bt.interlaced, p->bt.pixelclock,
2012
p->bt.width, p->bt.height, p->bt.polarities,
2013
p->bt.hfrontporch, p->bt.hsync,
2014
p->bt.hbackporch, p->bt.vfrontporch,
2015
p->bt.vsync, p->bt.vbackporch,
2016
p->bt.il_vfrontporch, p->bt.il_vsync,
2017
p->bt.il_vbackporch);
2018
ret = ops->vidioc_s_dv_timings(file, fh, p);
2021
dbgarg2("Unknown type %d!\n", p->type);
2026
case VIDIOC_G_DV_TIMINGS:
2028
struct v4l2_dv_timings *p = arg;
2030
if (!ops->vidioc_g_dv_timings)
2033
ret = ops->vidioc_g_dv_timings(file, fh, p);
2036
case V4L2_DV_BT_656_1120:
2037
dbgarg2("bt-656/1120:interlaced=%d,"
2039
" width=%d, height=%d, polarities=%x,"
2040
" hfrontporch=%d, hsync=%d,"
2041
" hbackporch=%d, vfrontporch=%d,"
2042
" vsync=%d, vbackporch=%d,"
2043
" il_vfrontporch=%d, il_vsync=%d,"
2044
" il_vbackporch=%d\n",
2045
p->bt.interlaced, p->bt.pixelclock,
2046
p->bt.width, p->bt.height,
2047
p->bt.polarities, p->bt.hfrontporch,
2048
p->bt.hsync, p->bt.hbackporch,
2049
p->bt.vfrontporch, p->bt.vsync,
2050
p->bt.vbackporch, p->bt.il_vfrontporch,
2051
p->bt.il_vsync, p->bt.il_vbackporch);
2054
dbgarg2("Unknown type %d!\n", p->type);
2060
case VIDIOC_DQEVENT:
2062
struct v4l2_event *ev = arg;
2064
if (!ops->vidioc_subscribe_event)
2067
ret = v4l2_event_dequeue(fh, ev, file->f_flags & O_NONBLOCK);
2069
dbgarg(cmd, "no pending events?");
2073
"pending=%d, type=0x%8.8x, sequence=%d, "
2074
"timestamp=%lu.%9.9lu ",
2075
ev->pending, ev->type, ev->sequence,
2076
ev->timestamp.tv_sec, ev->timestamp.tv_nsec);
2079
case VIDIOC_SUBSCRIBE_EVENT:
2081
struct v4l2_event_subscription *sub = arg;
2083
if (!ops->vidioc_subscribe_event)
2086
ret = ops->vidioc_subscribe_event(fh, sub);
2088
dbgarg(cmd, "failed, ret=%ld", ret);
2091
dbgarg(cmd, "type=0x%8.8x", sub->type);
2094
case VIDIOC_UNSUBSCRIBE_EVENT:
2096
struct v4l2_event_subscription *sub = arg;
2098
if (!ops->vidioc_unsubscribe_event)
2101
ret = ops->vidioc_unsubscribe_event(fh, sub);
2103
dbgarg(cmd, "failed, ret=%ld", ret);
2106
dbgarg(cmd, "type=0x%8.8x", sub->type);
2109
case VIDIOC_CREATE_BUFS:
2111
struct v4l2_create_buffers *create = arg;
2113
if (!ops->vidioc_create_bufs)
2119
ret = check_fmt(ops, create->format.type);
2123
ret = ops->vidioc_create_bufs(file, fh, create);
2125
dbgarg(cmd, "count=%d @ %d\n", create->count, create->index);
2128
case VIDIOC_PREPARE_BUF:
2130
struct v4l2_buffer *b = arg;
2132
if (!ops->vidioc_prepare_buf)
2134
ret = check_fmt(ops, b->type);
2138
ret = ops->vidioc_prepare_buf(file, fh, b);
2140
dbgarg(cmd, "index=%d", b->index);
2144
if (!ops->vidioc_default)
2146
ret = ops->vidioc_default(file, fh, ret_prio >= 0, cmd, arg);
2150
if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
2152
v4l_print_ioctl(vfd->name, cmd);
2153
printk(KERN_CONT " error %ld\n", ret);
2160
/* In some cases, only a few fields are used as input, i.e. when the app sets
2161
* "index" and then the driver fills in the rest of the structure for the thing
2162
* with that index. We only need to copy up the first non-input field. */
2163
static unsigned long cmd_input_size(unsigned int cmd)
2165
/* Size of structure up to and including 'field' */
2166
#define CMDINSIZE(cmd, type, field) \
2167
case VIDIOC_##cmd: \
2168
return offsetof(struct v4l2_##type, field) + \
2169
sizeof(((struct v4l2_##type *)0)->field);
2172
CMDINSIZE(ENUM_FMT, fmtdesc, type);
2173
CMDINSIZE(G_FMT, format, type);
2174
CMDINSIZE(QUERYBUF, buffer, length);
2175
CMDINSIZE(G_PARM, streamparm, type);
2176
CMDINSIZE(ENUMSTD, standard, index);
2177
CMDINSIZE(ENUMINPUT, input, index);
2178
CMDINSIZE(G_CTRL, control, id);
2179
CMDINSIZE(G_TUNER, tuner, index);
2180
CMDINSIZE(QUERYCTRL, queryctrl, id);
2181
CMDINSIZE(QUERYMENU, querymenu, index);
2182
CMDINSIZE(ENUMOUTPUT, output, index);
2183
CMDINSIZE(G_MODULATOR, modulator, index);
2184
CMDINSIZE(G_FREQUENCY, frequency, tuner);
2185
CMDINSIZE(CROPCAP, cropcap, type);
2186
CMDINSIZE(G_CROP, crop, type);
2187
CMDINSIZE(ENUMAUDIO, audio, index);
2188
CMDINSIZE(ENUMAUDOUT, audioout, index);
2189
CMDINSIZE(ENCODER_CMD, encoder_cmd, flags);
2190
CMDINSIZE(TRY_ENCODER_CMD, encoder_cmd, flags);
2191
CMDINSIZE(G_SLICED_VBI_CAP, sliced_vbi_cap, type);
2192
CMDINSIZE(ENUM_FRAMESIZES, frmsizeenum, pixel_format);
2193
CMDINSIZE(ENUM_FRAMEINTERVALS, frmivalenum, height);
2195
return _IOC_SIZE(cmd);
2199
static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
2200
void * __user *user_ptr, void ***kernel_ptr)
2205
case VIDIOC_QUERYBUF:
2207
case VIDIOC_DQBUF: {
2208
struct v4l2_buffer *buf = parg;
2210
if (V4L2_TYPE_IS_MULTIPLANAR(buf->type) && buf->length > 0) {
2211
if (buf->length > VIDEO_MAX_PLANES) {
2215
*user_ptr = (void __user *)buf->m.planes;
2216
*kernel_ptr = (void *)&buf->m.planes;
2217
*array_size = sizeof(struct v4l2_plane) * buf->length;
2223
case VIDIOC_S_EXT_CTRLS:
2224
case VIDIOC_G_EXT_CTRLS:
2225
case VIDIOC_TRY_EXT_CTRLS: {
2226
struct v4l2_ext_controls *ctrls = parg;
2228
if (ctrls->count != 0) {
2229
*user_ptr = (void __user *)ctrls->controls;
2230
*kernel_ptr = (void *)&ctrls->controls;
2231
*array_size = sizeof(struct v4l2_ext_control)
2243
video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
2248
void *parg = (void *)arg;
2250
bool has_array_args;
2251
size_t array_size = 0;
2252
void __user *user_ptr = NULL;
2253
void **kernel_ptr = NULL;
2255
/* Copy arguments into temp kernel buffer */
2256
if (_IOC_DIR(cmd) != _IOC_NONE) {
2257
if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
2260
/* too big to allocate from stack */
2261
mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
2268
if (_IOC_DIR(cmd) & _IOC_WRITE) {
2269
unsigned long n = cmd_input_size(cmd);
2271
if (copy_from_user(parg, (void __user *)arg, n))
2274
/* zero out anything we don't copy from userspace */
2275
if (n < _IOC_SIZE(cmd))
2276
memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n);
2278
/* read-only ioctl */
2279
memset(parg, 0, _IOC_SIZE(cmd));
2283
err = check_array_args(cmd, parg, &array_size, &user_ptr, &kernel_ptr);
2286
has_array_args = err;
2288
if (has_array_args) {
2290
* When adding new types of array args, make sure that the
2291
* parent argument to ioctl (which contains the pointer to the
2292
* array) fits into sbuf (so that mbuf will still remain
2293
* unused up to here).
2295
mbuf = kmalloc(array_size, GFP_KERNEL);
2298
goto out_array_args;
2300
if (copy_from_user(mbuf, user_ptr, array_size))
2301
goto out_array_args;
2306
err = func(file, cmd, parg);
2307
if (err == -ENOIOCTLCMD)
2310
if (has_array_args) {
2311
*kernel_ptr = user_ptr;
2312
if (copy_to_user(user_ptr, mbuf, array_size))
2314
goto out_array_args;
2320
/* Copy results into user buffer */
2321
switch (_IOC_DIR(cmd)) {
2323
case (_IOC_WRITE | _IOC_READ):
2324
if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
2333
EXPORT_SYMBOL(video_usercopy);
2335
long video_ioctl2(struct file *file,
2336
unsigned int cmd, unsigned long arg)
2338
return video_usercopy(file, cmd, arg, __video_do_ioctl);
2340
EXPORT_SYMBOL(video_ioctl2);