Commit | Line | Data |
---|---|---|
35ea11ff HV |
1 | /* |
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 | * | |
d9b01449 | 11 | * Authors: Alan Cox, <alan@lxorguk.ukuu.org.uk> (version 1) |
35ea11ff HV |
12 | * Mauro Carvalho Chehab <mchehab@infradead.org> (version 2) |
13 | */ | |
14 | ||
15 | #include <linux/module.h> | |
5a0e3ad6 | 16 | #include <linux/slab.h> |
35ea11ff HV |
17 | #include <linux/types.h> |
18 | #include <linux/kernel.h> | |
ae6db515 | 19 | #include <linux/version.h> |
35ea11ff | 20 | |
35ea11ff HV |
21 | #include <linux/videodev2.h> |
22 | ||
35ea11ff HV |
23 | #include <media/v4l2-common.h> |
24 | #include <media/v4l2-ioctl.h> | |
11bbc1ca | 25 | #include <media/v4l2-ctrls.h> |
d3d7c963 SA |
26 | #include <media/v4l2-fh.h> |
27 | #include <media/v4l2-event.h> | |
99cd47bc | 28 | #include <media/v4l2-device.h> |
80b36e0f | 29 | #include <media/v4l2-chip-ident.h> |
35ea11ff HV |
30 | |
31 | #define dbgarg(cmd, fmt, arg...) \ | |
32 | do { \ | |
33 | if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \ | |
34 | printk(KERN_DEBUG "%s: ", vfd->name); \ | |
35 | v4l_printk_ioctl(cmd); \ | |
36 | printk(" " fmt, ## arg); \ | |
37 | } \ | |
38 | } while (0) | |
39 | ||
40 | #define dbgarg2(fmt, arg...) \ | |
41 | do { \ | |
42 | if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \ | |
43 | printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\ | |
44 | } while (0) | |
45 | ||
d33fbcbb MCC |
46 | #define dbgarg3(fmt, arg...) \ |
47 | do { \ | |
48 | if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \ | |
49 | printk(KERN_CONT "%s: " fmt, vfd->name, ## arg);\ | |
50 | } while (0) | |
51 | ||
25985edc | 52 | /* Zero out the end of the struct pointed to by p. Everything after, but |
7ecc0cf9 TP |
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)) | |
57 | ||
35ea11ff HV |
58 | struct std_descr { |
59 | v4l2_std_id std; | |
60 | const char *descr; | |
61 | }; | |
62 | ||
63 | static const struct std_descr standards[] = { | |
64 | { V4L2_STD_NTSC, "NTSC" }, | |
65 | { V4L2_STD_NTSC_M, "NTSC-M" }, | |
66 | { V4L2_STD_NTSC_M_JP, "NTSC-M-JP" }, | |
67 | { V4L2_STD_NTSC_M_KR, "NTSC-M-KR" }, | |
68 | { V4L2_STD_NTSC_443, "NTSC-443" }, | |
69 | { V4L2_STD_PAL, "PAL" }, | |
70 | { V4L2_STD_PAL_BG, "PAL-BG" }, | |
71 | { V4L2_STD_PAL_B, "PAL-B" }, | |
72 | { V4L2_STD_PAL_B1, "PAL-B1" }, | |
73 | { V4L2_STD_PAL_G, "PAL-G" }, | |
74 | { V4L2_STD_PAL_H, "PAL-H" }, | |
75 | { V4L2_STD_PAL_I, "PAL-I" }, | |
76 | { V4L2_STD_PAL_DK, "PAL-DK" }, | |
77 | { V4L2_STD_PAL_D, "PAL-D" }, | |
78 | { V4L2_STD_PAL_D1, "PAL-D1" }, | |
79 | { V4L2_STD_PAL_K, "PAL-K" }, | |
80 | { V4L2_STD_PAL_M, "PAL-M" }, | |
81 | { V4L2_STD_PAL_N, "PAL-N" }, | |
82 | { V4L2_STD_PAL_Nc, "PAL-Nc" }, | |
83 | { V4L2_STD_PAL_60, "PAL-60" }, | |
84 | { V4L2_STD_SECAM, "SECAM" }, | |
85 | { V4L2_STD_SECAM_B, "SECAM-B" }, | |
86 | { V4L2_STD_SECAM_G, "SECAM-G" }, | |
87 | { V4L2_STD_SECAM_H, "SECAM-H" }, | |
88 | { V4L2_STD_SECAM_DK, "SECAM-DK" }, | |
89 | { V4L2_STD_SECAM_D, "SECAM-D" }, | |
90 | { V4L2_STD_SECAM_K, "SECAM-K" }, | |
91 | { V4L2_STD_SECAM_K1, "SECAM-K1" }, | |
92 | { V4L2_STD_SECAM_L, "SECAM-L" }, | |
93 | { V4L2_STD_SECAM_LC, "SECAM-Lc" }, | |
94 | { 0, "Unknown" } | |
95 | }; | |
96 | ||
97 | /* video4linux standard ID conversion to standard name | |
98 | */ | |
99 | const char *v4l2_norm_to_name(v4l2_std_id id) | |
100 | { | |
101 | u32 myid = id; | |
102 | int i; | |
103 | ||
104 | /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle | |
105 | 64 bit comparations. So, on that architecture, with some gcc | |
106 | variants, compilation fails. Currently, the max value is 30bit wide. | |
107 | */ | |
108 | BUG_ON(myid != id); | |
109 | ||
110 | for (i = 0; standards[i].std; i++) | |
111 | if (myid == standards[i].std) | |
112 | break; | |
113 | return standards[i].descr; | |
114 | } | |
115 | EXPORT_SYMBOL(v4l2_norm_to_name); | |
116 | ||
51f0b8d5 TP |
117 | /* Returns frame period for the given standard */ |
118 | void v4l2_video_std_frame_period(int id, struct v4l2_fract *frameperiod) | |
119 | { | |
120 | if (id & V4L2_STD_525_60) { | |
121 | frameperiod->numerator = 1001; | |
122 | frameperiod->denominator = 30000; | |
123 | } else { | |
124 | frameperiod->numerator = 1; | |
125 | frameperiod->denominator = 25; | |
126 | } | |
127 | } | |
128 | EXPORT_SYMBOL(v4l2_video_std_frame_period); | |
129 | ||
35ea11ff HV |
130 | /* Fill in the fields of a v4l2_standard structure according to the |
131 | 'id' and 'transmission' parameters. Returns negative on error. */ | |
132 | int v4l2_video_std_construct(struct v4l2_standard *vs, | |
133 | int id, const char *name) | |
134 | { | |
51f0b8d5 TP |
135 | vs->id = id; |
136 | v4l2_video_std_frame_period(id, &vs->frameperiod); | |
137 | vs->framelines = (id & V4L2_STD_525_60) ? 525 : 625; | |
35ea11ff HV |
138 | strlcpy(vs->name, name, sizeof(vs->name)); |
139 | return 0; | |
140 | } | |
141 | EXPORT_SYMBOL(v4l2_video_std_construct); | |
142 | ||
143 | /* ----------------------------------------------------------------- */ | |
144 | /* some arrays for pretty-printing debug messages of enum types */ | |
145 | ||
146 | const char *v4l2_field_names[] = { | |
147 | [V4L2_FIELD_ANY] = "any", | |
148 | [V4L2_FIELD_NONE] = "none", | |
149 | [V4L2_FIELD_TOP] = "top", | |
150 | [V4L2_FIELD_BOTTOM] = "bottom", | |
151 | [V4L2_FIELD_INTERLACED] = "interlaced", | |
152 | [V4L2_FIELD_SEQ_TB] = "seq-tb", | |
153 | [V4L2_FIELD_SEQ_BT] = "seq-bt", | |
154 | [V4L2_FIELD_ALTERNATE] = "alternate", | |
155 | [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb", | |
156 | [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt", | |
157 | }; | |
158 | EXPORT_SYMBOL(v4l2_field_names); | |
159 | ||
160 | const char *v4l2_type_names[] = { | |
161 | [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "vid-cap", | |
162 | [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "vid-overlay", | |
163 | [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "vid-out", | |
164 | [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap", | |
165 | [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out", | |
166 | [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap", | |
167 | [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out", | |
168 | [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "vid-out-overlay", | |
f8f3914c PO |
169 | [V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE] = "vid-cap-mplane", |
170 | [V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE] = "vid-out-mplane", | |
35ea11ff HV |
171 | }; |
172 | EXPORT_SYMBOL(v4l2_type_names); | |
173 | ||
174 | static const char *v4l2_memory_names[] = { | |
175 | [V4L2_MEMORY_MMAP] = "mmap", | |
176 | [V4L2_MEMORY_USERPTR] = "userptr", | |
177 | [V4L2_MEMORY_OVERLAY] = "overlay", | |
178 | }; | |
179 | ||
180 | #define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \ | |
181 | arr[a] : "unknown") | |
182 | ||
183 | /* ------------------------------------------------------------------ */ | |
184 | /* debug help functions */ | |
8ab75e3e | 185 | |
59076122 HV |
186 | static void v4l_print_querycap(const void *arg, bool write_only) |
187 | { | |
188 | const struct v4l2_capability *p = arg; | |
189 | ||
190 | pr_cont("driver=%s, card=%s, bus=%s, version=0x%08x, " | |
191 | "capabilities=0x%08x, device_caps=0x%08x\n", | |
192 | p->driver, p->card, p->bus_info, | |
193 | p->version, p->capabilities, p->device_caps); | |
194 | } | |
195 | ||
196 | static void v4l_print_enuminput(const void *arg, bool write_only) | |
197 | { | |
198 | const struct v4l2_input *p = arg; | |
199 | ||
200 | pr_cont("index=%u, name=%s, type=%u, audioset=0x%x, tuner=%u, " | |
201 | "std=0x%08Lx, status=0x%x, capabilities=0x%x\n", | |
202 | p->index, p->name, p->type, p->audioset, p->tuner, | |
203 | (unsigned long long)p->std, p->status, p->capabilities); | |
204 | } | |
205 | ||
206 | static void v4l_print_enumoutput(const void *arg, bool write_only) | |
207 | { | |
208 | const struct v4l2_output *p = arg; | |
209 | ||
210 | pr_cont("index=%u, name=%s, type=%u, audioset=0x%x, " | |
211 | "modulator=%u, std=0x%08Lx, capabilities=0x%x\n", | |
212 | p->index, p->name, p->type, p->audioset, p->modulator, | |
213 | (unsigned long long)p->std, p->capabilities); | |
214 | } | |
215 | ||
216 | static void v4l_print_audio(const void *arg, bool write_only) | |
217 | { | |
218 | const struct v4l2_audio *p = arg; | |
219 | ||
220 | if (write_only) | |
221 | pr_cont("index=%u, mode=0x%x\n", p->index, p->mode); | |
222 | else | |
223 | pr_cont("index=%u, name=%s, capability=0x%x, mode=0x%x\n", | |
224 | p->index, p->name, p->capability, p->mode); | |
225 | } | |
226 | ||
227 | static void v4l_print_audioout(const void *arg, bool write_only) | |
228 | { | |
229 | const struct v4l2_audioout *p = arg; | |
230 | ||
231 | if (write_only) | |
232 | pr_cont("index=%u\n", p->index); | |
233 | else | |
234 | pr_cont("index=%u, name=%s, capability=0x%x, mode=0x%x\n", | |
235 | p->index, p->name, p->capability, p->mode); | |
236 | } | |
237 | ||
238 | static void v4l_print_u32(const void *arg, bool write_only) | |
239 | { | |
240 | pr_cont("value=%u\n", *(const u32 *)arg); | |
241 | } | |
242 | ||
35ea11ff HV |
243 | static void dbgbuf(unsigned int cmd, struct video_device *vfd, |
244 | struct v4l2_buffer *p) | |
245 | { | |
246 | struct v4l2_timecode *tc = &p->timecode; | |
d14e6d76 PO |
247 | struct v4l2_plane *plane; |
248 | int i; | |
35ea11ff HV |
249 | |
250 | dbgarg(cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, " | |
d14e6d76 | 251 | "flags=0x%08d, field=%0d, sequence=%d, memory=%s\n", |
35ea11ff HV |
252 | p->timestamp.tv_sec / 3600, |
253 | (int)(p->timestamp.tv_sec / 60) % 60, | |
254 | (int)(p->timestamp.tv_sec % 60), | |
b045979d | 255 | (long)p->timestamp.tv_usec, |
35ea11ff HV |
256 | p->index, |
257 | prt_names(p->type, v4l2_type_names), | |
d14e6d76 PO |
258 | p->flags, p->field, p->sequence, |
259 | prt_names(p->memory, v4l2_memory_names)); | |
260 | ||
261 | if (V4L2_TYPE_IS_MULTIPLANAR(p->type) && p->m.planes) { | |
262 | for (i = 0; i < p->length; ++i) { | |
263 | plane = &p->m.planes[i]; | |
264 | dbgarg2("plane %d: bytesused=%d, data_offset=0x%08x " | |
265 | "offset/userptr=0x%08lx, length=%d\n", | |
266 | i, plane->bytesused, plane->data_offset, | |
267 | plane->m.userptr, plane->length); | |
268 | } | |
269 | } else { | |
270 | dbgarg2("bytesused=%d, offset/userptr=0x%08lx, length=%d\n", | |
271 | p->bytesused, p->m.userptr, p->length); | |
272 | } | |
273 | ||
35ea11ff HV |
274 | dbgarg2("timecode=%02d:%02d:%02d type=%d, " |
275 | "flags=0x%08d, frames=%d, userbits=0x%08x\n", | |
276 | tc->hours, tc->minutes, tc->seconds, | |
277 | tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits); | |
278 | } | |
279 | ||
280 | static inline void dbgrect(struct video_device *vfd, char *s, | |
281 | struct v4l2_rect *r) | |
282 | { | |
283 | dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s, r->left, r->top, | |
284 | r->width, r->height); | |
285 | }; | |
286 | ||
5d7758ee HV |
287 | static void dbgtimings(struct video_device *vfd, |
288 | const struct v4l2_dv_timings *p) | |
289 | { | |
290 | switch (p->type) { | |
291 | case V4L2_DV_BT_656_1120: | |
292 | dbgarg2("bt-656/1120:interlaced=%d," | |
293 | " pixelclock=%lld," | |
294 | " width=%d, height=%d, polarities=%x," | |
295 | " hfrontporch=%d, hsync=%d," | |
296 | " hbackporch=%d, vfrontporch=%d," | |
297 | " vsync=%d, vbackporch=%d," | |
298 | " il_vfrontporch=%d, il_vsync=%d," | |
299 | " il_vbackporch=%d, standards=%x, flags=%x\n", | |
300 | p->bt.interlaced, p->bt.pixelclock, | |
301 | p->bt.width, p->bt.height, | |
302 | p->bt.polarities, p->bt.hfrontporch, | |
303 | p->bt.hsync, p->bt.hbackporch, | |
304 | p->bt.vfrontporch, p->bt.vsync, | |
305 | p->bt.vbackporch, p->bt.il_vfrontporch, | |
306 | p->bt.il_vsync, p->bt.il_vbackporch, | |
307 | p->bt.standards, p->bt.flags); | |
308 | break; | |
309 | default: | |
310 | dbgarg2("Unknown type %d!\n", p->type); | |
311 | break; | |
312 | } | |
313 | } | |
314 | ||
35ea11ff HV |
315 | static inline void v4l_print_pix_fmt(struct video_device *vfd, |
316 | struct v4l2_pix_format *fmt) | |
317 | { | |
318 | dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, " | |
319 | "bytesperline=%d sizeimage=%d, colorspace=%d\n", | |
320 | fmt->width, fmt->height, | |
321 | (fmt->pixelformat & 0xff), | |
322 | (fmt->pixelformat >> 8) & 0xff, | |
323 | (fmt->pixelformat >> 16) & 0xff, | |
324 | (fmt->pixelformat >> 24) & 0xff, | |
325 | prt_names(fmt->field, v4l2_field_names), | |
326 | fmt->bytesperline, fmt->sizeimage, fmt->colorspace); | |
327 | }; | |
328 | ||
d14e6d76 PO |
329 | static inline void v4l_print_pix_fmt_mplane(struct video_device *vfd, |
330 | struct v4l2_pix_format_mplane *fmt) | |
331 | { | |
332 | int i; | |
333 | ||
334 | dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, " | |
335 | "colorspace=%d, num_planes=%d\n", | |
336 | fmt->width, fmt->height, | |
337 | (fmt->pixelformat & 0xff), | |
338 | (fmt->pixelformat >> 8) & 0xff, | |
339 | (fmt->pixelformat >> 16) & 0xff, | |
340 | (fmt->pixelformat >> 24) & 0xff, | |
341 | prt_names(fmt->field, v4l2_field_names), | |
342 | fmt->colorspace, fmt->num_planes); | |
343 | ||
344 | for (i = 0; i < fmt->num_planes; ++i) | |
345 | dbgarg2("plane %d: bytesperline=%d sizeimage=%d\n", i, | |
346 | fmt->plane_fmt[i].bytesperline, | |
347 | fmt->plane_fmt[i].sizeimage); | |
348 | } | |
349 | ||
35ea11ff HV |
350 | static inline void v4l_print_ext_ctrls(unsigned int cmd, |
351 | struct video_device *vfd, struct v4l2_ext_controls *c, int show_vals) | |
352 | { | |
353 | __u32 i; | |
354 | ||
355 | if (!(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) | |
356 | return; | |
357 | dbgarg(cmd, ""); | |
358 | printk(KERN_CONT "class=0x%x", c->ctrl_class); | |
359 | for (i = 0; i < c->count; i++) { | |
6b5a9492 | 360 | if (show_vals && !c->controls[i].size) |
35ea11ff HV |
361 | printk(KERN_CONT " id/val=0x%x/0x%x", |
362 | c->controls[i].id, c->controls[i].value); | |
363 | else | |
6b5a9492 HV |
364 | printk(KERN_CONT " id=0x%x,size=%u", |
365 | c->controls[i].id, c->controls[i].size); | |
35ea11ff HV |
366 | } |
367 | printk(KERN_CONT "\n"); | |
368 | }; | |
369 | ||
370 | static inline int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv) | |
371 | { | |
372 | __u32 i; | |
373 | ||
374 | /* zero the reserved fields */ | |
375 | c->reserved[0] = c->reserved[1] = 0; | |
6b5a9492 | 376 | for (i = 0; i < c->count; i++) |
35ea11ff | 377 | c->controls[i].reserved2[0] = 0; |
6b5a9492 | 378 | |
35ea11ff HV |
379 | /* V4L2_CID_PRIVATE_BASE cannot be used as control class |
380 | when using extended controls. | |
381 | Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL | |
382 | is it allowed for backwards compatibility. | |
383 | */ | |
384 | if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE) | |
385 | return 0; | |
386 | /* Check that all controls are from the same control class. */ | |
387 | for (i = 0; i < c->count; i++) { | |
388 | if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) { | |
389 | c->error_idx = i; | |
390 | return 0; | |
391 | } | |
392 | } | |
393 | return 1; | |
394 | } | |
395 | ||
a399810c | 396 | static int check_fmt(const struct v4l2_ioctl_ops *ops, enum v4l2_buf_type type) |
35ea11ff | 397 | { |
a399810c HV |
398 | if (ops == NULL) |
399 | return -EINVAL; | |
400 | ||
35ea11ff HV |
401 | switch (type) { |
402 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: | |
d14e6d76 PO |
403 | if (ops->vidioc_g_fmt_vid_cap || |
404 | ops->vidioc_g_fmt_vid_cap_mplane) | |
405 | return 0; | |
406 | break; | |
407 | case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: | |
408 | if (ops->vidioc_g_fmt_vid_cap_mplane) | |
35ea11ff HV |
409 | return 0; |
410 | break; | |
411 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: | |
1175d613 | 412 | if (ops->vidioc_g_fmt_vid_overlay) |
35ea11ff HV |
413 | return 0; |
414 | break; | |
415 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: | |
d14e6d76 PO |
416 | if (ops->vidioc_g_fmt_vid_out || |
417 | ops->vidioc_g_fmt_vid_out_mplane) | |
418 | return 0; | |
419 | break; | |
420 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: | |
421 | if (ops->vidioc_g_fmt_vid_out_mplane) | |
35ea11ff HV |
422 | return 0; |
423 | break; | |
424 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: | |
1175d613 | 425 | if (ops->vidioc_g_fmt_vid_out_overlay) |
35ea11ff HV |
426 | return 0; |
427 | break; | |
428 | case V4L2_BUF_TYPE_VBI_CAPTURE: | |
1175d613 | 429 | if (ops->vidioc_g_fmt_vbi_cap) |
35ea11ff HV |
430 | return 0; |
431 | break; | |
432 | case V4L2_BUF_TYPE_VBI_OUTPUT: | |
1175d613 | 433 | if (ops->vidioc_g_fmt_vbi_out) |
35ea11ff HV |
434 | return 0; |
435 | break; | |
436 | case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: | |
1175d613 | 437 | if (ops->vidioc_g_fmt_sliced_vbi_cap) |
35ea11ff HV |
438 | return 0; |
439 | break; | |
440 | case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: | |
1175d613 | 441 | if (ops->vidioc_g_fmt_sliced_vbi_out) |
35ea11ff HV |
442 | return 0; |
443 | break; | |
444 | case V4L2_BUF_TYPE_PRIVATE: | |
1175d613 | 445 | if (ops->vidioc_g_fmt_type_private) |
35ea11ff HV |
446 | return 0; |
447 | break; | |
448 | } | |
449 | return -EINVAL; | |
450 | } | |
451 | ||
59076122 HV |
452 | static int v4l_querycap(const struct v4l2_ioctl_ops *ops, |
453 | struct file *file, void *fh, void *arg) | |
454 | { | |
455 | struct v4l2_capability *cap = (struct v4l2_capability *)arg; | |
456 | ||
457 | cap->version = LINUX_VERSION_CODE; | |
458 | return ops->vidioc_querycap(file, fh, cap); | |
459 | } | |
460 | ||
461 | static int v4l_s_input(const struct v4l2_ioctl_ops *ops, | |
462 | struct file *file, void *fh, void *arg) | |
463 | { | |
464 | return ops->vidioc_s_input(file, fh, *(unsigned int *)arg); | |
465 | } | |
466 | ||
467 | static int v4l_s_output(const struct v4l2_ioctl_ops *ops, | |
468 | struct file *file, void *fh, void *arg) | |
469 | { | |
470 | return ops->vidioc_s_output(file, fh, *(unsigned int *)arg); | |
471 | } | |
472 | ||
d0547cba HV |
473 | static int v4l_g_priority(const struct v4l2_ioctl_ops *ops, |
474 | struct file *file, void *fh, void *arg) | |
475 | { | |
476 | struct video_device *vfd; | |
477 | u32 *p = arg; | |
478 | ||
479 | if (ops->vidioc_g_priority) | |
480 | return ops->vidioc_g_priority(file, fh, arg); | |
481 | vfd = video_devdata(file); | |
482 | *p = v4l2_prio_max(&vfd->v4l2_dev->prio); | |
483 | return 0; | |
484 | } | |
485 | ||
486 | static int v4l_s_priority(const struct v4l2_ioctl_ops *ops, | |
487 | struct file *file, void *fh, void *arg) | |
488 | { | |
489 | struct video_device *vfd; | |
490 | struct v4l2_fh *vfh; | |
491 | u32 *p = arg; | |
492 | ||
493 | if (ops->vidioc_s_priority) | |
494 | return ops->vidioc_s_priority(file, fh, *p); | |
495 | vfd = video_devdata(file); | |
496 | vfh = file->private_data; | |
497 | return v4l2_prio_change(&vfd->v4l2_dev->prio, &vfh->prio, *p); | |
498 | } | |
499 | ||
59076122 HV |
500 | static int v4l_enuminput(const struct v4l2_ioctl_ops *ops, |
501 | struct file *file, void *fh, void *arg) | |
502 | { | |
503 | struct v4l2_input *p = arg; | |
504 | ||
505 | /* | |
506 | * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS & | |
507 | * CAP_STD here based on ioctl handler provided by the | |
508 | * driver. If the driver doesn't support these | |
509 | * for a specific input, it must override these flags. | |
510 | */ | |
511 | if (ops->vidioc_s_std) | |
512 | p->capabilities |= V4L2_IN_CAP_STD; | |
513 | if (ops->vidioc_s_dv_preset) | |
514 | p->capabilities |= V4L2_IN_CAP_PRESETS; | |
515 | if (ops->vidioc_s_dv_timings) | |
516 | p->capabilities |= V4L2_IN_CAP_CUSTOM_TIMINGS; | |
517 | ||
518 | return ops->vidioc_enum_input(file, fh, p); | |
519 | } | |
520 | ||
521 | static int v4l_enumoutput(const struct v4l2_ioctl_ops *ops, | |
522 | struct file *file, void *fh, void *arg) | |
523 | { | |
524 | struct v4l2_output *p = arg; | |
525 | ||
526 | /* | |
527 | * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS & | |
528 | * CAP_STD here based on ioctl handler provided by the | |
529 | * driver. If the driver doesn't support these | |
530 | * for a specific output, it must override these flags. | |
531 | */ | |
532 | if (ops->vidioc_s_std) | |
533 | p->capabilities |= V4L2_OUT_CAP_STD; | |
534 | if (ops->vidioc_s_dv_preset) | |
535 | p->capabilities |= V4L2_OUT_CAP_PRESETS; | |
536 | if (ops->vidioc_s_dv_timings) | |
537 | p->capabilities |= V4L2_OUT_CAP_CUSTOM_TIMINGS; | |
538 | ||
539 | return ops->vidioc_enum_output(file, fh, p); | |
540 | } | |
541 | ||
4839e6c2 HV |
542 | struct v4l2_ioctl_info { |
543 | unsigned int ioctl; | |
27cd2aba | 544 | u32 flags; |
4839e6c2 | 545 | const char * const name; |
86748f35 HV |
546 | union { |
547 | u32 offset; | |
548 | int (*func)(const struct v4l2_ioctl_ops *ops, | |
549 | struct file *file, void *fh, void *p); | |
550 | }; | |
551 | void (*debug)(const void *arg, bool write_only); | |
4839e6c2 HV |
552 | }; |
553 | ||
554 | /* This control needs a priority check */ | |
555 | #define INFO_FL_PRIO (1 << 0) | |
556 | /* This control can be valid if the filehandle passes a control handler. */ | |
557 | #define INFO_FL_CTRL (1 << 1) | |
86748f35 HV |
558 | /* This is a standard ioctl, no need for special code */ |
559 | #define INFO_FL_STD (1 << 2) | |
560 | /* This is ioctl has its own function */ | |
561 | #define INFO_FL_FUNC (1 << 3) | |
27cd2aba HV |
562 | /* Zero struct from after the field to the end */ |
563 | #define INFO_FL_CLEAR(v4l2_struct, field) \ | |
564 | ((offsetof(struct v4l2_struct, field) + \ | |
565 | sizeof(((struct v4l2_struct *)0)->field)) << 16) | |
566 | #define INFO_FL_CLEAR_MASK (_IOC_SIZEMASK << 16) | |
4839e6c2 HV |
567 | |
568 | #define IOCTL_INFO(_ioctl, _flags) [_IOC_NR(_ioctl)] = { \ | |
569 | .ioctl = _ioctl, \ | |
570 | .flags = _flags, \ | |
571 | .name = #_ioctl, \ | |
572 | } | |
573 | ||
86748f35 HV |
574 | #define IOCTL_INFO_STD(_ioctl, _vidioc, _debug, _flags) \ |
575 | [_IOC_NR(_ioctl)] = { \ | |
576 | .ioctl = _ioctl, \ | |
577 | .flags = _flags | INFO_FL_STD, \ | |
578 | .name = #_ioctl, \ | |
579 | .offset = offsetof(struct v4l2_ioctl_ops, _vidioc), \ | |
580 | .debug = _debug, \ | |
581 | } | |
582 | ||
583 | #define IOCTL_INFO_FNC(_ioctl, _func, _debug, _flags) \ | |
584 | [_IOC_NR(_ioctl)] = { \ | |
585 | .ioctl = _ioctl, \ | |
586 | .flags = _flags | INFO_FL_FUNC, \ | |
587 | .name = #_ioctl, \ | |
588 | .func = _func, \ | |
589 | .debug = _debug, \ | |
590 | } | |
591 | ||
4839e6c2 | 592 | static struct v4l2_ioctl_info v4l2_ioctls[] = { |
59076122 | 593 | IOCTL_INFO_FNC(VIDIOC_QUERYCAP, v4l_querycap, v4l_print_querycap, 0), |
27cd2aba HV |
594 | IOCTL_INFO(VIDIOC_ENUM_FMT, INFO_FL_CLEAR(v4l2_fmtdesc, type)), |
595 | IOCTL_INFO(VIDIOC_G_FMT, INFO_FL_CLEAR(v4l2_format, type)), | |
4839e6c2 HV |
596 | IOCTL_INFO(VIDIOC_S_FMT, INFO_FL_PRIO), |
597 | IOCTL_INFO(VIDIOC_REQBUFS, INFO_FL_PRIO), | |
27cd2aba | 598 | IOCTL_INFO(VIDIOC_QUERYBUF, INFO_FL_CLEAR(v4l2_buffer, length)), |
4839e6c2 HV |
599 | IOCTL_INFO(VIDIOC_G_FBUF, 0), |
600 | IOCTL_INFO(VIDIOC_S_FBUF, INFO_FL_PRIO), | |
601 | IOCTL_INFO(VIDIOC_OVERLAY, INFO_FL_PRIO), | |
602 | IOCTL_INFO(VIDIOC_QBUF, 0), | |
603 | IOCTL_INFO(VIDIOC_DQBUF, 0), | |
604 | IOCTL_INFO(VIDIOC_STREAMON, INFO_FL_PRIO), | |
605 | IOCTL_INFO(VIDIOC_STREAMOFF, INFO_FL_PRIO), | |
27cd2aba | 606 | IOCTL_INFO(VIDIOC_G_PARM, INFO_FL_CLEAR(v4l2_streamparm, type)), |
4839e6c2 HV |
607 | IOCTL_INFO(VIDIOC_S_PARM, INFO_FL_PRIO), |
608 | IOCTL_INFO(VIDIOC_G_STD, 0), | |
609 | IOCTL_INFO(VIDIOC_S_STD, INFO_FL_PRIO), | |
27cd2aba | 610 | IOCTL_INFO(VIDIOC_ENUMSTD, INFO_FL_CLEAR(v4l2_standard, index)), |
59076122 | 611 | IOCTL_INFO_FNC(VIDIOC_ENUMINPUT, v4l_enuminput, v4l_print_enuminput, INFO_FL_CLEAR(v4l2_input, index)), |
4839e6c2 HV |
612 | IOCTL_INFO(VIDIOC_G_CTRL, INFO_FL_CTRL), |
613 | IOCTL_INFO(VIDIOC_S_CTRL, INFO_FL_PRIO | INFO_FL_CTRL), | |
27cd2aba | 614 | IOCTL_INFO(VIDIOC_G_TUNER, INFO_FL_CLEAR(v4l2_tuner, index)), |
4839e6c2 | 615 | IOCTL_INFO(VIDIOC_S_TUNER, INFO_FL_PRIO), |
59076122 HV |
616 | IOCTL_INFO_STD(VIDIOC_G_AUDIO, vidioc_g_audio, v4l_print_audio, 0), |
617 | IOCTL_INFO_STD(VIDIOC_S_AUDIO, vidioc_s_audio, v4l_print_audio, INFO_FL_PRIO), | |
27cd2aba HV |
618 | IOCTL_INFO(VIDIOC_QUERYCTRL, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_queryctrl, id)), |
619 | IOCTL_INFO(VIDIOC_QUERYMENU, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_querymenu, index)), | |
59076122 HV |
620 | IOCTL_INFO_STD(VIDIOC_G_INPUT, vidioc_g_input, v4l_print_u32, 0), |
621 | IOCTL_INFO_FNC(VIDIOC_S_INPUT, v4l_s_input, v4l_print_u32, INFO_FL_PRIO), | |
622 | IOCTL_INFO_STD(VIDIOC_G_OUTPUT, vidioc_g_output, v4l_print_u32, 0), | |
623 | IOCTL_INFO_FNC(VIDIOC_S_OUTPUT, v4l_s_output, v4l_print_u32, INFO_FL_PRIO), | |
624 | IOCTL_INFO_FNC(VIDIOC_ENUMOUTPUT, v4l_enumoutput, v4l_print_enumoutput, INFO_FL_CLEAR(v4l2_output, index)), | |
625 | IOCTL_INFO_STD(VIDIOC_G_AUDOUT, vidioc_g_audout, v4l_print_audioout, 0), | |
626 | IOCTL_INFO_STD(VIDIOC_S_AUDOUT, vidioc_s_audout, v4l_print_audioout, INFO_FL_PRIO), | |
27cd2aba | 627 | IOCTL_INFO(VIDIOC_G_MODULATOR, INFO_FL_CLEAR(v4l2_modulator, index)), |
4839e6c2 | 628 | IOCTL_INFO(VIDIOC_S_MODULATOR, INFO_FL_PRIO), |
27cd2aba | 629 | IOCTL_INFO(VIDIOC_G_FREQUENCY, INFO_FL_CLEAR(v4l2_frequency, tuner)), |
4839e6c2 | 630 | IOCTL_INFO(VIDIOC_S_FREQUENCY, INFO_FL_PRIO), |
27cd2aba HV |
631 | IOCTL_INFO(VIDIOC_CROPCAP, INFO_FL_CLEAR(v4l2_cropcap, type)), |
632 | IOCTL_INFO(VIDIOC_G_CROP, INFO_FL_CLEAR(v4l2_crop, type)), | |
4839e6c2 HV |
633 | IOCTL_INFO(VIDIOC_S_CROP, INFO_FL_PRIO), |
634 | IOCTL_INFO(VIDIOC_G_SELECTION, 0), | |
635 | IOCTL_INFO(VIDIOC_S_SELECTION, INFO_FL_PRIO), | |
636 | IOCTL_INFO(VIDIOC_G_JPEGCOMP, 0), | |
637 | IOCTL_INFO(VIDIOC_S_JPEGCOMP, INFO_FL_PRIO), | |
638 | IOCTL_INFO(VIDIOC_QUERYSTD, 0), | |
639 | IOCTL_INFO(VIDIOC_TRY_FMT, 0), | |
59076122 HV |
640 | IOCTL_INFO_STD(VIDIOC_ENUMAUDIO, vidioc_enumaudio, v4l_print_audio, INFO_FL_CLEAR(v4l2_audio, index)), |
641 | IOCTL_INFO_STD(VIDIOC_ENUMAUDOUT, vidioc_enumaudout, v4l_print_audioout, INFO_FL_CLEAR(v4l2_audioout, index)), | |
d0547cba HV |
642 | IOCTL_INFO_FNC(VIDIOC_G_PRIORITY, v4l_g_priority, v4l_print_u32, 0), |
643 | IOCTL_INFO_FNC(VIDIOC_S_PRIORITY, v4l_s_priority, v4l_print_u32, INFO_FL_PRIO), | |
27cd2aba | 644 | IOCTL_INFO(VIDIOC_G_SLICED_VBI_CAP, INFO_FL_CLEAR(v4l2_sliced_vbi_cap, type)), |
4839e6c2 HV |
645 | IOCTL_INFO(VIDIOC_LOG_STATUS, 0), |
646 | IOCTL_INFO(VIDIOC_G_EXT_CTRLS, INFO_FL_CTRL), | |
647 | IOCTL_INFO(VIDIOC_S_EXT_CTRLS, INFO_FL_PRIO | INFO_FL_CTRL), | |
648 | IOCTL_INFO(VIDIOC_TRY_EXT_CTRLS, 0), | |
27cd2aba HV |
649 | IOCTL_INFO(VIDIOC_ENUM_FRAMESIZES, INFO_FL_CLEAR(v4l2_frmsizeenum, pixel_format)), |
650 | IOCTL_INFO(VIDIOC_ENUM_FRAMEINTERVALS, INFO_FL_CLEAR(v4l2_frmivalenum, height)), | |
4839e6c2 | 651 | IOCTL_INFO(VIDIOC_G_ENC_INDEX, 0), |
27cd2aba HV |
652 | IOCTL_INFO(VIDIOC_ENCODER_CMD, INFO_FL_PRIO | INFO_FL_CLEAR(v4l2_encoder_cmd, flags)), |
653 | IOCTL_INFO(VIDIOC_TRY_ENCODER_CMD, INFO_FL_CLEAR(v4l2_encoder_cmd, flags)), | |
4839e6c2 HV |
654 | IOCTL_INFO(VIDIOC_DECODER_CMD, INFO_FL_PRIO), |
655 | IOCTL_INFO(VIDIOC_TRY_DECODER_CMD, 0), | |
4839e6c2 HV |
656 | IOCTL_INFO(VIDIOC_DBG_S_REGISTER, 0), |
657 | IOCTL_INFO(VIDIOC_DBG_G_REGISTER, 0), | |
4839e6c2 HV |
658 | IOCTL_INFO(VIDIOC_DBG_G_CHIP_IDENT, 0), |
659 | IOCTL_INFO(VIDIOC_S_HW_FREQ_SEEK, INFO_FL_PRIO), | |
660 | IOCTL_INFO(VIDIOC_ENUM_DV_PRESETS, 0), | |
661 | IOCTL_INFO(VIDIOC_S_DV_PRESET, INFO_FL_PRIO), | |
662 | IOCTL_INFO(VIDIOC_G_DV_PRESET, 0), | |
663 | IOCTL_INFO(VIDIOC_QUERY_DV_PRESET, 0), | |
664 | IOCTL_INFO(VIDIOC_S_DV_TIMINGS, INFO_FL_PRIO), | |
665 | IOCTL_INFO(VIDIOC_G_DV_TIMINGS, 0), | |
666 | IOCTL_INFO(VIDIOC_DQEVENT, 0), | |
667 | IOCTL_INFO(VIDIOC_SUBSCRIBE_EVENT, 0), | |
668 | IOCTL_INFO(VIDIOC_UNSUBSCRIBE_EVENT, 0), | |
669 | IOCTL_INFO(VIDIOC_CREATE_BUFS, INFO_FL_PRIO), | |
670 | IOCTL_INFO(VIDIOC_PREPARE_BUF, 0), | |
671 | IOCTL_INFO(VIDIOC_ENUM_DV_TIMINGS, 0), | |
672 | IOCTL_INFO(VIDIOC_QUERY_DV_TIMINGS, 0), | |
673 | IOCTL_INFO(VIDIOC_DV_TIMINGS_CAP, 0), | |
674 | }; | |
675 | #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls) | |
676 | ||
677 | bool v4l2_is_known_ioctl(unsigned int cmd) | |
678 | { | |
679 | if (_IOC_NR(cmd) >= V4L2_IOCTLS) | |
680 | return false; | |
681 | return v4l2_ioctls[_IOC_NR(cmd)].ioctl == cmd; | |
682 | } | |
683 | ||
684 | /* Common ioctl debug function. This function can be used by | |
685 | external ioctl messages as well as internal V4L ioctl */ | |
686 | void v4l_printk_ioctl(unsigned int cmd) | |
687 | { | |
86748f35 | 688 | const char *dir, *type; |
4839e6c2 HV |
689 | |
690 | switch (_IOC_TYPE(cmd)) { | |
691 | case 'd': | |
692 | type = "v4l2_int"; | |
693 | break; | |
694 | case 'V': | |
695 | if (_IOC_NR(cmd) >= V4L2_IOCTLS) { | |
696 | type = "v4l2"; | |
697 | break; | |
698 | } | |
86748f35 | 699 | pr_cont("%s", v4l2_ioctls[_IOC_NR(cmd)].name); |
4839e6c2 HV |
700 | return; |
701 | default: | |
702 | type = "unknown"; | |
86748f35 | 703 | break; |
4839e6c2 HV |
704 | } |
705 | ||
706 | switch (_IOC_DIR(cmd)) { | |
707 | case _IOC_NONE: dir = "--"; break; | |
708 | case _IOC_READ: dir = "r-"; break; | |
709 | case _IOC_WRITE: dir = "-w"; break; | |
710 | case _IOC_READ | _IOC_WRITE: dir = "rw"; break; | |
711 | default: dir = "*ERR*"; break; | |
712 | } | |
86748f35 | 713 | pr_cont("%s ioctl '%c', dir=%s, #%d (0x%08x)", |
4839e6c2 HV |
714 | type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd); |
715 | } | |
716 | EXPORT_SYMBOL(v4l_printk_ioctl); | |
717 | ||
069b7479 | 718 | static long __video_do_ioctl(struct file *file, |
35ea11ff HV |
719 | unsigned int cmd, void *arg) |
720 | { | |
721 | struct video_device *vfd = video_devdata(file); | |
a399810c | 722 | const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops; |
86748f35 HV |
723 | bool write_only = false; |
724 | struct v4l2_ioctl_info default_info; | |
725 | const struct v4l2_ioctl_info *info; | |
d5fbf32f | 726 | void *fh = file->private_data; |
99cd47bc | 727 | struct v4l2_fh *vfh = NULL; |
b1a873a3 | 728 | int use_fh_prio = 0; |
9190d191 | 729 | long ret = -ENOTTY; |
35ea11ff | 730 | |
6a717883 HV |
731 | if (ops == NULL) { |
732 | printk(KERN_WARNING "videodev: \"%s\" has no ioctl_ops.\n", | |
733 | vfd->name); | |
9190d191 | 734 | return ret; |
6a717883 HV |
735 | } |
736 | ||
b1a873a3 | 737 | if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) { |
99cd47bc | 738 | vfh = file->private_data; |
b1a873a3 HV |
739 | use_fh_prio = test_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags); |
740 | } | |
99cd47bc | 741 | |
48ea0be0 | 742 | if (v4l2_is_known_ioctl(cmd)) { |
86748f35 | 743 | info = &v4l2_ioctls[_IOC_NR(cmd)]; |
48ea0be0 HV |
744 | |
745 | if (!test_bit(_IOC_NR(cmd), vfd->valid_ioctls) && | |
746 | !((info->flags & INFO_FL_CTRL) && vfh && vfh->ctrl_handler)) | |
86748f35 | 747 | goto done; |
4b902fec HV |
748 | |
749 | if (use_fh_prio && (info->flags & INFO_FL_PRIO)) { | |
750 | ret = v4l2_prio_check(vfd->prio, vfh->prio); | |
751 | if (ret) | |
86748f35 | 752 | goto done; |
4b902fec | 753 | } |
86748f35 HV |
754 | } else { |
755 | default_info.ioctl = cmd; | |
756 | default_info.flags = 0; | |
757 | default_info.debug = NULL; | |
758 | info = &default_info; | |
48ea0be0 HV |
759 | } |
760 | ||
86748f35 HV |
761 | write_only = _IOC_DIR(cmd) == _IOC_WRITE; |
762 | if (info->debug && write_only && vfd->debug > V4L2_DEBUG_IOCTL) { | |
48ea0be0 | 763 | v4l_print_ioctl(vfd->name, cmd); |
86748f35 HV |
764 | pr_cont(": "); |
765 | info->debug(arg, write_only); | |
766 | } | |
767 | if (info->flags & INFO_FL_STD) { | |
768 | typedef int (*vidioc_op)(struct file *file, void *fh, void *p); | |
769 | const void *p = vfd->ioctl_ops; | |
770 | const vidioc_op *vidioc = p + info->offset; | |
771 | ||
772 | ret = (*vidioc)(file, fh, arg); | |
773 | goto done; | |
774 | } else if (info->flags & INFO_FL_FUNC) { | |
775 | ret = info->func(ops, file, fh, arg); | |
776 | goto done; | |
48ea0be0 | 777 | } |
99cd47bc | 778 | |
6a717883 | 779 | switch (cmd) { |
35ea11ff HV |
780 | /* --- capture ioctls ---------------------------------------- */ |
781 | case VIDIOC_ENUM_FMT: | |
782 | { | |
783 | struct v4l2_fmtdesc *f = arg; | |
35ea11ff | 784 | |
48ea0be0 | 785 | ret = -EINVAL; |
19c96e4b | 786 | switch (f->type) { |
35ea11ff | 787 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
a5f2db53 | 788 | if (likely(ops->vidioc_enum_fmt_vid_cap)) |
a399810c | 789 | ret = ops->vidioc_enum_fmt_vid_cap(file, fh, f); |
35ea11ff | 790 | break; |
d14e6d76 | 791 | case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: |
a5f2db53 | 792 | if (likely(ops->vidioc_enum_fmt_vid_cap_mplane)) |
d14e6d76 PO |
793 | ret = ops->vidioc_enum_fmt_vid_cap_mplane(file, |
794 | fh, f); | |
795 | break; | |
35ea11ff | 796 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: |
a5f2db53 | 797 | if (likely(ops->vidioc_enum_fmt_vid_overlay)) |
a399810c | 798 | ret = ops->vidioc_enum_fmt_vid_overlay(file, |
35ea11ff HV |
799 | fh, f); |
800 | break; | |
35ea11ff | 801 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: |
a5f2db53 | 802 | if (likely(ops->vidioc_enum_fmt_vid_out)) |
a399810c | 803 | ret = ops->vidioc_enum_fmt_vid_out(file, fh, f); |
35ea11ff | 804 | break; |
d14e6d76 | 805 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: |
a5f2db53 | 806 | if (likely(ops->vidioc_enum_fmt_vid_out_mplane)) |
d14e6d76 PO |
807 | ret = ops->vidioc_enum_fmt_vid_out_mplane(file, |
808 | fh, f); | |
809 | break; | |
35ea11ff | 810 | case V4L2_BUF_TYPE_PRIVATE: |
a5f2db53 | 811 | if (likely(ops->vidioc_enum_fmt_type_private)) |
a399810c | 812 | ret = ops->vidioc_enum_fmt_type_private(file, |
35ea11ff HV |
813 | fh, f); |
814 | break; | |
815 | default: | |
816 | break; | |
817 | } | |
48ea0be0 | 818 | if (likely(!ret)) |
35ea11ff HV |
819 | dbgarg(cmd, "index=%d, type=%d, flags=%d, " |
820 | "pixelformat=%c%c%c%c, description='%s'\n", | |
821 | f->index, f->type, f->flags, | |
822 | (f->pixelformat & 0xff), | |
823 | (f->pixelformat >> 8) & 0xff, | |
824 | (f->pixelformat >> 16) & 0xff, | |
825 | (f->pixelformat >> 24) & 0xff, | |
826 | f->description); | |
827 | break; | |
828 | } | |
829 | case VIDIOC_G_FMT: | |
830 | { | |
831 | struct v4l2_format *f = (struct v4l2_format *)arg; | |
832 | ||
35ea11ff HV |
833 | /* FIXME: Should be one dump per type */ |
834 | dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names)); | |
835 | ||
48ea0be0 | 836 | ret = -EINVAL; |
35ea11ff HV |
837 | switch (f->type) { |
838 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: | |
1d0c86ca | 839 | if (ops->vidioc_g_fmt_vid_cap) |
a399810c | 840 | ret = ops->vidioc_g_fmt_vid_cap(file, fh, f); |
35ea11ff HV |
841 | if (!ret) |
842 | v4l_print_pix_fmt(vfd, &f->fmt.pix); | |
843 | break; | |
d14e6d76 | 844 | case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: |
1d0c86ca | 845 | if (ops->vidioc_g_fmt_vid_cap_mplane) |
d14e6d76 PO |
846 | ret = ops->vidioc_g_fmt_vid_cap_mplane(file, |
847 | fh, f); | |
d14e6d76 PO |
848 | if (!ret) |
849 | v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp); | |
850 | break; | |
35ea11ff | 851 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: |
a5f2db53 | 852 | if (likely(ops->vidioc_g_fmt_vid_overlay)) |
a399810c | 853 | ret = ops->vidioc_g_fmt_vid_overlay(file, |
35ea11ff HV |
854 | fh, f); |
855 | break; | |
856 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: | |
1d0c86ca | 857 | if (ops->vidioc_g_fmt_vid_out) |
a399810c | 858 | ret = ops->vidioc_g_fmt_vid_out(file, fh, f); |
35ea11ff HV |
859 | if (!ret) |
860 | v4l_print_pix_fmt(vfd, &f->fmt.pix); | |
861 | break; | |
d14e6d76 | 862 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: |
1d0c86ca | 863 | if (ops->vidioc_g_fmt_vid_out_mplane) |
d14e6d76 PO |
864 | ret = ops->vidioc_g_fmt_vid_out_mplane(file, |
865 | fh, f); | |
d14e6d76 PO |
866 | if (!ret) |
867 | v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp); | |
868 | break; | |
35ea11ff | 869 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: |
a5f2db53 | 870 | if (likely(ops->vidioc_g_fmt_vid_out_overlay)) |
a399810c | 871 | ret = ops->vidioc_g_fmt_vid_out_overlay(file, |
35ea11ff HV |
872 | fh, f); |
873 | break; | |
874 | case V4L2_BUF_TYPE_VBI_CAPTURE: | |
a5f2db53 | 875 | if (likely(ops->vidioc_g_fmt_vbi_cap)) |
a399810c | 876 | ret = ops->vidioc_g_fmt_vbi_cap(file, fh, f); |
35ea11ff HV |
877 | break; |
878 | case V4L2_BUF_TYPE_VBI_OUTPUT: | |
a5f2db53 | 879 | if (likely(ops->vidioc_g_fmt_vbi_out)) |
a399810c | 880 | ret = ops->vidioc_g_fmt_vbi_out(file, fh, f); |
35ea11ff HV |
881 | break; |
882 | case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: | |
a5f2db53 | 883 | if (likely(ops->vidioc_g_fmt_sliced_vbi_cap)) |
a399810c | 884 | ret = ops->vidioc_g_fmt_sliced_vbi_cap(file, |
35ea11ff HV |
885 | fh, f); |
886 | break; | |
887 | case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: | |
a5f2db53 | 888 | if (likely(ops->vidioc_g_fmt_sliced_vbi_out)) |
a399810c | 889 | ret = ops->vidioc_g_fmt_sliced_vbi_out(file, |
35ea11ff HV |
890 | fh, f); |
891 | break; | |
892 | case V4L2_BUF_TYPE_PRIVATE: | |
a5f2db53 | 893 | if (likely(ops->vidioc_g_fmt_type_private)) |
a399810c | 894 | ret = ops->vidioc_g_fmt_type_private(file, |
35ea11ff HV |
895 | fh, f); |
896 | break; | |
897 | } | |
35ea11ff HV |
898 | break; |
899 | } | |
900 | case VIDIOC_S_FMT: | |
901 | { | |
902 | struct v4l2_format *f = (struct v4l2_format *)arg; | |
903 | ||
93d5a30b HV |
904 | ret = -EINVAL; |
905 | ||
35ea11ff HV |
906 | /* FIXME: Should be one dump per type */ |
907 | dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names)); | |
908 | ||
909 | switch (f->type) { | |
910 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: | |
7ecc0cf9 | 911 | CLEAR_AFTER_FIELD(f, fmt.pix); |
35ea11ff | 912 | v4l_print_pix_fmt(vfd, &f->fmt.pix); |
1d0c86ca | 913 | if (ops->vidioc_s_fmt_vid_cap) |
a399810c | 914 | ret = ops->vidioc_s_fmt_vid_cap(file, fh, f); |
d14e6d76 PO |
915 | break; |
916 | case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: | |
917 | CLEAR_AFTER_FIELD(f, fmt.pix_mp); | |
918 | v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp); | |
1d0c86ca | 919 | if (ops->vidioc_s_fmt_vid_cap_mplane) |
d14e6d76 PO |
920 | ret = ops->vidioc_s_fmt_vid_cap_mplane(file, |
921 | fh, f); | |
35ea11ff HV |
922 | break; |
923 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: | |
7ecc0cf9 | 924 | CLEAR_AFTER_FIELD(f, fmt.win); |
a399810c HV |
925 | if (ops->vidioc_s_fmt_vid_overlay) |
926 | ret = ops->vidioc_s_fmt_vid_overlay(file, | |
35ea11ff HV |
927 | fh, f); |
928 | break; | |
929 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: | |
7ecc0cf9 | 930 | CLEAR_AFTER_FIELD(f, fmt.pix); |
35ea11ff | 931 | v4l_print_pix_fmt(vfd, &f->fmt.pix); |
1d0c86ca | 932 | if (ops->vidioc_s_fmt_vid_out) |
a399810c | 933 | ret = ops->vidioc_s_fmt_vid_out(file, fh, f); |
d14e6d76 PO |
934 | break; |
935 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: | |
936 | CLEAR_AFTER_FIELD(f, fmt.pix_mp); | |
937 | v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp); | |
1d0c86ca | 938 | if (ops->vidioc_s_fmt_vid_out_mplane) |
d14e6d76 PO |
939 | ret = ops->vidioc_s_fmt_vid_out_mplane(file, |
940 | fh, f); | |
35ea11ff HV |
941 | break; |
942 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: | |
7ecc0cf9 | 943 | CLEAR_AFTER_FIELD(f, fmt.win); |
a399810c HV |
944 | if (ops->vidioc_s_fmt_vid_out_overlay) |
945 | ret = ops->vidioc_s_fmt_vid_out_overlay(file, | |
35ea11ff HV |
946 | fh, f); |
947 | break; | |
948 | case V4L2_BUF_TYPE_VBI_CAPTURE: | |
7ecc0cf9 | 949 | CLEAR_AFTER_FIELD(f, fmt.vbi); |
a5f2db53 | 950 | if (likely(ops->vidioc_s_fmt_vbi_cap)) |
a399810c | 951 | ret = ops->vidioc_s_fmt_vbi_cap(file, fh, f); |
35ea11ff HV |
952 | break; |
953 | case V4L2_BUF_TYPE_VBI_OUTPUT: | |
7ecc0cf9 | 954 | CLEAR_AFTER_FIELD(f, fmt.vbi); |
a5f2db53 | 955 | if (likely(ops->vidioc_s_fmt_vbi_out)) |
a399810c | 956 | ret = ops->vidioc_s_fmt_vbi_out(file, fh, f); |
35ea11ff HV |
957 | break; |
958 | case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: | |
7ecc0cf9 | 959 | CLEAR_AFTER_FIELD(f, fmt.sliced); |
a5f2db53 | 960 | if (likely(ops->vidioc_s_fmt_sliced_vbi_cap)) |
a399810c | 961 | ret = ops->vidioc_s_fmt_sliced_vbi_cap(file, |
35ea11ff HV |
962 | fh, f); |
963 | break; | |
964 | case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: | |
7ecc0cf9 | 965 | CLEAR_AFTER_FIELD(f, fmt.sliced); |
a5f2db53 | 966 | if (likely(ops->vidioc_s_fmt_sliced_vbi_out)) |
a399810c | 967 | ret = ops->vidioc_s_fmt_sliced_vbi_out(file, |
35ea11ff | 968 | fh, f); |
a5f2db53 | 969 | |
35ea11ff HV |
970 | break; |
971 | case V4L2_BUF_TYPE_PRIVATE: | |
7ecc0cf9 | 972 | /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */ |
a5f2db53 | 973 | if (likely(ops->vidioc_s_fmt_type_private)) |
a399810c | 974 | ret = ops->vidioc_s_fmt_type_private(file, |
35ea11ff HV |
975 | fh, f); |
976 | break; | |
977 | } | |
978 | break; | |
979 | } | |
980 | case VIDIOC_TRY_FMT: | |
981 | { | |
982 | struct v4l2_format *f = (struct v4l2_format *)arg; | |
983 | ||
984 | /* FIXME: Should be one dump per type */ | |
985 | dbgarg(cmd, "type=%s\n", prt_names(f->type, | |
986 | v4l2_type_names)); | |
48ea0be0 | 987 | ret = -EINVAL; |
35ea11ff HV |
988 | switch (f->type) { |
989 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: | |
7ecc0cf9 | 990 | CLEAR_AFTER_FIELD(f, fmt.pix); |
1d0c86ca | 991 | if (ops->vidioc_try_fmt_vid_cap) |
a399810c | 992 | ret = ops->vidioc_try_fmt_vid_cap(file, fh, f); |
35ea11ff HV |
993 | if (!ret) |
994 | v4l_print_pix_fmt(vfd, &f->fmt.pix); | |
995 | break; | |
d14e6d76 PO |
996 | case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: |
997 | CLEAR_AFTER_FIELD(f, fmt.pix_mp); | |
1d0c86ca | 998 | if (ops->vidioc_try_fmt_vid_cap_mplane) |
d14e6d76 PO |
999 | ret = ops->vidioc_try_fmt_vid_cap_mplane(file, |
1000 | fh, f); | |
d14e6d76 PO |
1001 | if (!ret) |
1002 | v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp); | |
1003 | break; | |
35ea11ff | 1004 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: |
7ecc0cf9 | 1005 | CLEAR_AFTER_FIELD(f, fmt.win); |
a5f2db53 | 1006 | if (likely(ops->vidioc_try_fmt_vid_overlay)) |
a399810c | 1007 | ret = ops->vidioc_try_fmt_vid_overlay(file, |
35ea11ff HV |
1008 | fh, f); |
1009 | break; | |
1010 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: | |
7ecc0cf9 | 1011 | CLEAR_AFTER_FIELD(f, fmt.pix); |
1d0c86ca | 1012 | if (ops->vidioc_try_fmt_vid_out) |
a399810c | 1013 | ret = ops->vidioc_try_fmt_vid_out(file, fh, f); |
35ea11ff HV |
1014 | if (!ret) |
1015 | v4l_print_pix_fmt(vfd, &f->fmt.pix); | |
1016 | break; | |
d14e6d76 PO |
1017 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: |
1018 | CLEAR_AFTER_FIELD(f, fmt.pix_mp); | |
1d0c86ca | 1019 | if (ops->vidioc_try_fmt_vid_out_mplane) |
d14e6d76 PO |
1020 | ret = ops->vidioc_try_fmt_vid_out_mplane(file, |
1021 | fh, f); | |
d14e6d76 PO |
1022 | if (!ret) |
1023 | v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp); | |
1024 | break; | |
35ea11ff | 1025 | case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: |
7ecc0cf9 | 1026 | CLEAR_AFTER_FIELD(f, fmt.win); |
a5f2db53 | 1027 | if (likely(ops->vidioc_try_fmt_vid_out_overlay)) |
a399810c | 1028 | ret = ops->vidioc_try_fmt_vid_out_overlay(file, |
35ea11ff HV |
1029 | fh, f); |
1030 | break; | |
1031 | case V4L2_BUF_TYPE_VBI_CAPTURE: | |
7ecc0cf9 | 1032 | CLEAR_AFTER_FIELD(f, fmt.vbi); |
a5f2db53 | 1033 | if (likely(ops->vidioc_try_fmt_vbi_cap)) |
a399810c | 1034 | ret = ops->vidioc_try_fmt_vbi_cap(file, fh, f); |
35ea11ff HV |
1035 | break; |
1036 | case V4L2_BUF_TYPE_VBI_OUTPUT: | |
7ecc0cf9 | 1037 | CLEAR_AFTER_FIELD(f, fmt.vbi); |
a5f2db53 | 1038 | if (likely(ops->vidioc_try_fmt_vbi_out)) |
a399810c | 1039 | ret = ops->vidioc_try_fmt_vbi_out(file, fh, f); |
35ea11ff HV |
1040 | break; |
1041 | case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: | |
7ecc0cf9 | 1042 | CLEAR_AFTER_FIELD(f, fmt.sliced); |
a5f2db53 | 1043 | if (likely(ops->vidioc_try_fmt_sliced_vbi_cap)) |
a399810c | 1044 | ret = ops->vidioc_try_fmt_sliced_vbi_cap(file, |
35ea11ff HV |
1045 | fh, f); |
1046 | break; | |
1047 | case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: | |
7ecc0cf9 | 1048 | CLEAR_AFTER_FIELD(f, fmt.sliced); |
a5f2db53 | 1049 | if (likely(ops->vidioc_try_fmt_sliced_vbi_out)) |
a399810c | 1050 | ret = ops->vidioc_try_fmt_sliced_vbi_out(file, |
35ea11ff HV |
1051 | fh, f); |
1052 | break; | |
1053 | case V4L2_BUF_TYPE_PRIVATE: | |
7ecc0cf9 | 1054 | /* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */ |
a5f2db53 | 1055 | if (likely(ops->vidioc_try_fmt_type_private)) |
a399810c | 1056 | ret = ops->vidioc_try_fmt_type_private(file, |
35ea11ff HV |
1057 | fh, f); |
1058 | break; | |
1059 | } | |
35ea11ff HV |
1060 | break; |
1061 | } | |
1062 | /* FIXME: Those buf reqs could be handled here, | |
1063 | with some changes on videobuf to allow its header to be included at | |
1064 | videodev2.h or being merged at videodev2. | |
1065 | */ | |
1066 | case VIDIOC_REQBUFS: | |
1067 | { | |
1068 | struct v4l2_requestbuffers *p = arg; | |
1069 | ||
a399810c | 1070 | ret = check_fmt(ops, p->type); |
35ea11ff HV |
1071 | if (ret) |
1072 | break; | |
1073 | ||
7ecc0cf9 TP |
1074 | if (p->type < V4L2_BUF_TYPE_PRIVATE) |
1075 | CLEAR_AFTER_FIELD(p, memory); | |
1076 | ||
a399810c | 1077 | ret = ops->vidioc_reqbufs(file, fh, p); |
35ea11ff HV |
1078 | dbgarg(cmd, "count=%d, type=%s, memory=%s\n", |
1079 | p->count, | |
1080 | prt_names(p->type, v4l2_type_names), | |
1081 | prt_names(p->memory, v4l2_memory_names)); | |
1082 | break; | |
1083 | } | |
1084 | case VIDIOC_QUERYBUF: | |
1085 | { | |
1086 | struct v4l2_buffer *p = arg; | |
1087 | ||
a399810c | 1088 | ret = check_fmt(ops, p->type); |
35ea11ff HV |
1089 | if (ret) |
1090 | break; | |
1091 | ||
a399810c | 1092 | ret = ops->vidioc_querybuf(file, fh, p); |
35ea11ff HV |
1093 | if (!ret) |
1094 | dbgbuf(cmd, vfd, p); | |
1095 | break; | |
1096 | } | |
1097 | case VIDIOC_QBUF: | |
1098 | { | |
1099 | struct v4l2_buffer *p = arg; | |
1100 | ||
a399810c | 1101 | ret = check_fmt(ops, p->type); |
35ea11ff HV |
1102 | if (ret) |
1103 | break; | |
1104 | ||
a399810c | 1105 | ret = ops->vidioc_qbuf(file, fh, p); |
35ea11ff HV |
1106 | if (!ret) |
1107 | dbgbuf(cmd, vfd, p); | |
1108 | break; | |
1109 | } | |
1110 | case VIDIOC_DQBUF: | |
1111 | { | |
1112 | struct v4l2_buffer *p = arg; | |
1113 | ||
a399810c | 1114 | ret = check_fmt(ops, p->type); |
35ea11ff HV |
1115 | if (ret) |
1116 | break; | |
1117 | ||
a399810c | 1118 | ret = ops->vidioc_dqbuf(file, fh, p); |
35ea11ff HV |
1119 | if (!ret) |
1120 | dbgbuf(cmd, vfd, p); | |
1121 | break; | |
1122 | } | |
1123 | case VIDIOC_OVERLAY: | |
1124 | { | |
1125 | int *i = arg; | |
1126 | ||
35ea11ff | 1127 | dbgarg(cmd, "value=%d\n", *i); |
a399810c | 1128 | ret = ops->vidioc_overlay(file, fh, *i); |
35ea11ff HV |
1129 | break; |
1130 | } | |
1131 | case VIDIOC_G_FBUF: | |
1132 | { | |
1133 | struct v4l2_framebuffer *p = arg; | |
1134 | ||
a399810c | 1135 | ret = ops->vidioc_g_fbuf(file, fh, arg); |
35ea11ff HV |
1136 | if (!ret) { |
1137 | dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n", | |
1138 | p->capability, p->flags, | |
1139 | (unsigned long)p->base); | |
1140 | v4l_print_pix_fmt(vfd, &p->fmt); | |
1141 | } | |
1142 | break; | |
1143 | } | |
1144 | case VIDIOC_S_FBUF: | |
1145 | { | |
1146 | struct v4l2_framebuffer *p = arg; | |
1147 | ||
35ea11ff HV |
1148 | dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n", |
1149 | p->capability, p->flags, (unsigned long)p->base); | |
1150 | v4l_print_pix_fmt(vfd, &p->fmt); | |
a399810c | 1151 | ret = ops->vidioc_s_fbuf(file, fh, arg); |
35ea11ff HV |
1152 | break; |
1153 | } | |
1154 | case VIDIOC_STREAMON: | |
1155 | { | |
1156 | enum v4l2_buf_type i = *(int *)arg; | |
1157 | ||
35ea11ff | 1158 | dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names)); |
a399810c | 1159 | ret = ops->vidioc_streamon(file, fh, i); |
35ea11ff HV |
1160 | break; |
1161 | } | |
1162 | case VIDIOC_STREAMOFF: | |
1163 | { | |
1164 | enum v4l2_buf_type i = *(int *)arg; | |
1165 | ||
35ea11ff | 1166 | dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names)); |
a399810c | 1167 | ret = ops->vidioc_streamoff(file, fh, i); |
35ea11ff HV |
1168 | break; |
1169 | } | |
1170 | /* ---------- tv norms ---------- */ | |
1171 | case VIDIOC_ENUMSTD: | |
1172 | { | |
1173 | struct v4l2_standard *p = arg; | |
1174 | v4l2_std_id id = vfd->tvnorms, curr_id = 0; | |
1175 | unsigned int index = p->index, i, j = 0; | |
1176 | const char *descr = ""; | |
1177 | ||
93d5a30b HV |
1178 | if (id == 0) |
1179 | break; | |
1180 | ret = -EINVAL; | |
1181 | ||
35ea11ff HV |
1182 | /* Return norm array in a canonical way */ |
1183 | for (i = 0; i <= index && id; i++) { | |
1184 | /* last std value in the standards array is 0, so this | |
1185 | while always ends there since (id & 0) == 0. */ | |
1186 | while ((id & standards[j].std) != standards[j].std) | |
1187 | j++; | |
1188 | curr_id = standards[j].std; | |
1189 | descr = standards[j].descr; | |
1190 | j++; | |
1191 | if (curr_id == 0) | |
1192 | break; | |
1193 | if (curr_id != V4L2_STD_PAL && | |
1194 | curr_id != V4L2_STD_SECAM && | |
1195 | curr_id != V4L2_STD_NTSC) | |
1196 | id &= ~curr_id; | |
1197 | } | |
1198 | if (i <= index) | |
3f5e1824 | 1199 | break; |
35ea11ff HV |
1200 | |
1201 | v4l2_video_std_construct(p, curr_id, descr); | |
35ea11ff HV |
1202 | |
1203 | dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, " | |
1204 | "framelines=%d\n", p->index, | |
1205 | (unsigned long long)p->id, p->name, | |
1206 | p->frameperiod.numerator, | |
1207 | p->frameperiod.denominator, | |
1208 | p->framelines); | |
1209 | ||
1210 | ret = 0; | |
1211 | break; | |
1212 | } | |
1213 | case VIDIOC_G_STD: | |
1214 | { | |
1215 | v4l2_std_id *id = arg; | |
1216 | ||
35ea11ff | 1217 | /* Calls the specific handler */ |
a399810c HV |
1218 | if (ops->vidioc_g_std) |
1219 | ret = ops->vidioc_g_std(file, fh, id); | |
a5f2db53 MCC |
1220 | else if (vfd->current_norm) { |
1221 | ret = 0; | |
35ea11ff | 1222 | *id = vfd->current_norm; |
a5f2db53 | 1223 | } |
35ea11ff | 1224 | |
a5f2db53 | 1225 | if (likely(!ret)) |
35ea11ff HV |
1226 | dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id); |
1227 | break; | |
1228 | } | |
1229 | case VIDIOC_S_STD: | |
1230 | { | |
1231 | v4l2_std_id *id = arg, norm; | |
1232 | ||
1233 | dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id); | |
1234 | ||
93d5a30b | 1235 | ret = -EINVAL; |
35ea11ff HV |
1236 | norm = (*id) & vfd->tvnorms; |
1237 | if (vfd->tvnorms && !norm) /* Check if std is supported */ | |
1238 | break; | |
1239 | ||
1240 | /* Calls the specific handler */ | |
93d5a30b | 1241 | ret = ops->vidioc_s_std(file, fh, &norm); |
35ea11ff HV |
1242 | |
1243 | /* Updates standard information */ | |
1244 | if (ret >= 0) | |
1245 | vfd->current_norm = norm; | |
1246 | break; | |
1247 | } | |
1248 | case VIDIOC_QUERYSTD: | |
1249 | { | |
1250 | v4l2_std_id *p = arg; | |
1251 | ||
8715e6cb MCC |
1252 | /* |
1253 | * If nothing detected, it should return all supported | |
1254 | * Drivers just need to mask the std argument, in order | |
1255 | * to remove the standards that don't apply from the mask. | |
1256 | * This means that tuners, audio and video decoders can join | |
1257 | * their efforts to improve the standards detection | |
1258 | */ | |
1259 | *p = vfd->tvnorms; | |
a399810c | 1260 | ret = ops->vidioc_querystd(file, fh, arg); |
35ea11ff HV |
1261 | if (!ret) |
1262 | dbgarg(cmd, "detected std=%08Lx\n", | |
1263 | (unsigned long long)*p); | |
1264 | break; | |
1265 | } | |
35ea11ff HV |
1266 | |
1267 | /* --- controls ---------------------------------------------- */ | |
1268 | case VIDIOC_QUERYCTRL: | |
1269 | { | |
1270 | struct v4l2_queryctrl *p = arg; | |
1271 | ||
2d28b686 HV |
1272 | if (vfh && vfh->ctrl_handler) |
1273 | ret = v4l2_queryctrl(vfh->ctrl_handler, p); | |
1274 | else if (vfd->ctrl_handler) | |
11bbc1ca HV |
1275 | ret = v4l2_queryctrl(vfd->ctrl_handler, p); |
1276 | else if (ops->vidioc_queryctrl) | |
1277 | ret = ops->vidioc_queryctrl(file, fh, p); | |
1278 | else | |
35ea11ff | 1279 | break; |
35ea11ff HV |
1280 | if (!ret) |
1281 | dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, " | |
1282 | "step=%d, default=%d, flags=0x%08x\n", | |
1283 | p->id, p->type, p->name, | |
1284 | p->minimum, p->maximum, | |
1285 | p->step, p->default_value, p->flags); | |
1286 | else | |
1287 | dbgarg(cmd, "id=0x%x\n", p->id); | |
1288 | break; | |
1289 | } | |
1290 | case VIDIOC_G_CTRL: | |
1291 | { | |
1292 | struct v4l2_control *p = arg; | |
1293 | ||
2d28b686 HV |
1294 | if (vfh && vfh->ctrl_handler) |
1295 | ret = v4l2_g_ctrl(vfh->ctrl_handler, p); | |
1296 | else if (vfd->ctrl_handler) | |
11bbc1ca HV |
1297 | ret = v4l2_g_ctrl(vfd->ctrl_handler, p); |
1298 | else if (ops->vidioc_g_ctrl) | |
a399810c HV |
1299 | ret = ops->vidioc_g_ctrl(file, fh, p); |
1300 | else if (ops->vidioc_g_ext_ctrls) { | |
35ea11ff HV |
1301 | struct v4l2_ext_controls ctrls; |
1302 | struct v4l2_ext_control ctrl; | |
1303 | ||
1304 | ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id); | |
1305 | ctrls.count = 1; | |
1306 | ctrls.controls = &ctrl; | |
1307 | ctrl.id = p->id; | |
1308 | ctrl.value = p->value; | |
1309 | if (check_ext_ctrls(&ctrls, 1)) { | |
a399810c | 1310 | ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls); |
35ea11ff HV |
1311 | if (ret == 0) |
1312 | p->value = ctrl.value; | |
1313 | } | |
1314 | } else | |
1315 | break; | |
1316 | if (!ret) | |
1317 | dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value); | |
1318 | else | |
1319 | dbgarg(cmd, "id=0x%x\n", p->id); | |
1320 | break; | |
1321 | } | |
1322 | case VIDIOC_S_CTRL: | |
1323 | { | |
1324 | struct v4l2_control *p = arg; | |
1325 | struct v4l2_ext_controls ctrls; | |
1326 | struct v4l2_ext_control ctrl; | |
1327 | ||
2d28b686 | 1328 | if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler && |
11bbc1ca | 1329 | !ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls) |
35ea11ff HV |
1330 | break; |
1331 | ||
1332 | dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value); | |
1333 | ||
2d28b686 | 1334 | if (vfh && vfh->ctrl_handler) { |
ab892bac | 1335 | ret = v4l2_s_ctrl(vfh, vfh->ctrl_handler, p); |
2d28b686 HV |
1336 | break; |
1337 | } | |
11bbc1ca | 1338 | if (vfd->ctrl_handler) { |
ab892bac | 1339 | ret = v4l2_s_ctrl(NULL, vfd->ctrl_handler, p); |
11bbc1ca HV |
1340 | break; |
1341 | } | |
a399810c HV |
1342 | if (ops->vidioc_s_ctrl) { |
1343 | ret = ops->vidioc_s_ctrl(file, fh, p); | |
35ea11ff HV |
1344 | break; |
1345 | } | |
a399810c | 1346 | if (!ops->vidioc_s_ext_ctrls) |
35ea11ff HV |
1347 | break; |
1348 | ||
1349 | ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id); | |
1350 | ctrls.count = 1; | |
1351 | ctrls.controls = &ctrl; | |
1352 | ctrl.id = p->id; | |
1353 | ctrl.value = p->value; | |
1354 | if (check_ext_ctrls(&ctrls, 1)) | |
a399810c | 1355 | ret = ops->vidioc_s_ext_ctrls(file, fh, &ctrls); |
93d5a30b HV |
1356 | else |
1357 | ret = -EINVAL; | |
35ea11ff HV |
1358 | break; |
1359 | } | |
1360 | case VIDIOC_G_EXT_CTRLS: | |
1361 | { | |
1362 | struct v4l2_ext_controls *p = arg; | |
1363 | ||
1364 | p->error_idx = p->count; | |
2d28b686 HV |
1365 | if (vfh && vfh->ctrl_handler) |
1366 | ret = v4l2_g_ext_ctrls(vfh->ctrl_handler, p); | |
1367 | else if (vfd->ctrl_handler) | |
11bbc1ca | 1368 | ret = v4l2_g_ext_ctrls(vfd->ctrl_handler, p); |
93d5a30b HV |
1369 | else if (ops->vidioc_g_ext_ctrls) |
1370 | ret = check_ext_ctrls(p, 0) ? | |
1371 | ops->vidioc_g_ext_ctrls(file, fh, p) : | |
1372 | -EINVAL; | |
11bbc1ca HV |
1373 | else |
1374 | break; | |
35ea11ff HV |
1375 | v4l_print_ext_ctrls(cmd, vfd, p, !ret); |
1376 | break; | |
1377 | } | |
1378 | case VIDIOC_S_EXT_CTRLS: | |
1379 | { | |
1380 | struct v4l2_ext_controls *p = arg; | |
1381 | ||
1382 | p->error_idx = p->count; | |
2d28b686 HV |
1383 | if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler && |
1384 | !ops->vidioc_s_ext_ctrls) | |
35ea11ff HV |
1385 | break; |
1386 | v4l_print_ext_ctrls(cmd, vfd, p, 1); | |
2d28b686 | 1387 | if (vfh && vfh->ctrl_handler) |
ab892bac | 1388 | ret = v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, p); |
2d28b686 | 1389 | else if (vfd->ctrl_handler) |
ab892bac | 1390 | ret = v4l2_s_ext_ctrls(NULL, vfd->ctrl_handler, p); |
11bbc1ca | 1391 | else if (check_ext_ctrls(p, 0)) |
a399810c | 1392 | ret = ops->vidioc_s_ext_ctrls(file, fh, p); |
93d5a30b HV |
1393 | else |
1394 | ret = -EINVAL; | |
35ea11ff HV |
1395 | break; |
1396 | } | |
1397 | case VIDIOC_TRY_EXT_CTRLS: | |
1398 | { | |
1399 | struct v4l2_ext_controls *p = arg; | |
1400 | ||
1401 | p->error_idx = p->count; | |
2d28b686 HV |
1402 | if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler && |
1403 | !ops->vidioc_try_ext_ctrls) | |
35ea11ff HV |
1404 | break; |
1405 | v4l_print_ext_ctrls(cmd, vfd, p, 1); | |
2d28b686 HV |
1406 | if (vfh && vfh->ctrl_handler) |
1407 | ret = v4l2_try_ext_ctrls(vfh->ctrl_handler, p); | |
1408 | else if (vfd->ctrl_handler) | |
11bbc1ca HV |
1409 | ret = v4l2_try_ext_ctrls(vfd->ctrl_handler, p); |
1410 | else if (check_ext_ctrls(p, 0)) | |
a399810c | 1411 | ret = ops->vidioc_try_ext_ctrls(file, fh, p); |
93d5a30b HV |
1412 | else |
1413 | ret = -EINVAL; | |
35ea11ff HV |
1414 | break; |
1415 | } | |
1416 | case VIDIOC_QUERYMENU: | |
1417 | { | |
1418 | struct v4l2_querymenu *p = arg; | |
1419 | ||
2d28b686 HV |
1420 | if (vfh && vfh->ctrl_handler) |
1421 | ret = v4l2_querymenu(vfh->ctrl_handler, p); | |
1422 | else if (vfd->ctrl_handler) | |
11bbc1ca HV |
1423 | ret = v4l2_querymenu(vfd->ctrl_handler, p); |
1424 | else if (ops->vidioc_querymenu) | |
1425 | ret = ops->vidioc_querymenu(file, fh, p); | |
1426 | else | |
35ea11ff | 1427 | break; |
35ea11ff HV |
1428 | if (!ret) |
1429 | dbgarg(cmd, "id=0x%x, index=%d, name=%s\n", | |
1430 | p->id, p->index, p->name); | |
1431 | else | |
1432 | dbgarg(cmd, "id=0x%x, index=%d\n", | |
1433 | p->id, p->index); | |
1434 | break; | |
1435 | } | |
35ea11ff HV |
1436 | case VIDIOC_G_MODULATOR: |
1437 | { | |
1438 | struct v4l2_modulator *p = arg; | |
1439 | ||
a399810c | 1440 | ret = ops->vidioc_g_modulator(file, fh, p); |
35ea11ff HV |
1441 | if (!ret) |
1442 | dbgarg(cmd, "index=%d, name=%s, " | |
1443 | "capability=%d, rangelow=%d," | |
1444 | " rangehigh=%d, txsubchans=%d\n", | |
1445 | p->index, p->name, p->capability, | |
1446 | p->rangelow, p->rangehigh, | |
1447 | p->txsubchans); | |
1448 | break; | |
1449 | } | |
1450 | case VIDIOC_S_MODULATOR: | |
1451 | { | |
1452 | struct v4l2_modulator *p = arg; | |
1453 | ||
35ea11ff HV |
1454 | dbgarg(cmd, "index=%d, name=%s, capability=%d, " |
1455 | "rangelow=%d, rangehigh=%d, txsubchans=%d\n", | |
1456 | p->index, p->name, p->capability, p->rangelow, | |
1457 | p->rangehigh, p->txsubchans); | |
a399810c | 1458 | ret = ops->vidioc_s_modulator(file, fh, p); |
35ea11ff HV |
1459 | break; |
1460 | } | |
1461 | case VIDIOC_G_CROP: | |
1462 | { | |
1463 | struct v4l2_crop *p = arg; | |
1464 | ||
35ea11ff | 1465 | dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names)); |
992efeff TS |
1466 | |
1467 | if (ops->vidioc_g_crop) { | |
1468 | ret = ops->vidioc_g_crop(file, fh, p); | |
1469 | } else { | |
1470 | /* simulate capture crop using selection api */ | |
1471 | struct v4l2_selection s = { | |
1472 | .type = p->type, | |
1473 | }; | |
1474 | ||
1475 | /* crop means compose for output devices */ | |
1476 | if (V4L2_TYPE_IS_OUTPUT(p->type)) | |
1477 | s.target = V4L2_SEL_TGT_COMPOSE_ACTIVE; | |
1478 | else | |
1479 | s.target = V4L2_SEL_TGT_CROP_ACTIVE; | |
1480 | ||
1481 | ret = ops->vidioc_g_selection(file, fh, &s); | |
1482 | ||
1483 | /* copying results to old structure on success */ | |
1484 | if (!ret) | |
1485 | p->c = s.r; | |
1486 | } | |
1487 | ||
35ea11ff HV |
1488 | if (!ret) |
1489 | dbgrect(vfd, "", &p->c); | |
1490 | break; | |
1491 | } | |
1492 | case VIDIOC_S_CROP: | |
1493 | { | |
1494 | struct v4l2_crop *p = arg; | |
1495 | ||
35ea11ff HV |
1496 | dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names)); |
1497 | dbgrect(vfd, "", &p->c); | |
992efeff TS |
1498 | |
1499 | if (ops->vidioc_s_crop) { | |
1500 | ret = ops->vidioc_s_crop(file, fh, p); | |
1501 | } else { | |
1502 | /* simulate capture crop using selection api */ | |
1503 | struct v4l2_selection s = { | |
1504 | .type = p->type, | |
1505 | .r = p->c, | |
1506 | }; | |
1507 | ||
1508 | /* crop means compose for output devices */ | |
1509 | if (V4L2_TYPE_IS_OUTPUT(p->type)) | |
1510 | s.target = V4L2_SEL_TGT_COMPOSE_ACTIVE; | |
1511 | else | |
1512 | s.target = V4L2_SEL_TGT_CROP_ACTIVE; | |
1513 | ||
1514 | ret = ops->vidioc_s_selection(file, fh, &s); | |
1515 | } | |
35ea11ff HV |
1516 | break; |
1517 | } | |
0e8caace TS |
1518 | case VIDIOC_G_SELECTION: |
1519 | { | |
1520 | struct v4l2_selection *p = arg; | |
1521 | ||
0e8caace TS |
1522 | dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names)); |
1523 | ||
1524 | ret = ops->vidioc_g_selection(file, fh, p); | |
1525 | if (!ret) | |
1526 | dbgrect(vfd, "", &p->r); | |
1527 | break; | |
1528 | } | |
1529 | case VIDIOC_S_SELECTION: | |
1530 | { | |
1531 | struct v4l2_selection *p = arg; | |
1532 | ||
0e8caace TS |
1533 | |
1534 | dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names)); | |
1535 | dbgrect(vfd, "", &p->r); | |
1536 | ||
1537 | ret = ops->vidioc_s_selection(file, fh, p); | |
1538 | break; | |
1539 | } | |
35ea11ff HV |
1540 | case VIDIOC_CROPCAP: |
1541 | { | |
1542 | struct v4l2_cropcap *p = arg; | |
1543 | ||
1544 | /*FIXME: Should also show v4l2_fract pixelaspect */ | |
35ea11ff | 1545 | dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names)); |
992efeff TS |
1546 | if (ops->vidioc_cropcap) { |
1547 | ret = ops->vidioc_cropcap(file, fh, p); | |
1548 | } else { | |
1549 | struct v4l2_selection s = { .type = p->type }; | |
1550 | ||
1551 | /* obtaining bounds */ | |
1552 | if (V4L2_TYPE_IS_OUTPUT(p->type)) | |
1553 | s.target = V4L2_SEL_TGT_COMPOSE_BOUNDS; | |
1554 | else | |
1555 | s.target = V4L2_SEL_TGT_CROP_BOUNDS; | |
1556 | ||
1557 | ret = ops->vidioc_g_selection(file, fh, &s); | |
1558 | if (ret) | |
1559 | break; | |
1560 | p->bounds = s.r; | |
1561 | ||
1562 | /* obtaining defrect */ | |
1563 | if (V4L2_TYPE_IS_OUTPUT(p->type)) | |
1564 | s.target = V4L2_SEL_TGT_COMPOSE_DEFAULT; | |
1565 | else | |
1566 | s.target = V4L2_SEL_TGT_CROP_DEFAULT; | |
1567 | ||
1568 | ret = ops->vidioc_g_selection(file, fh, &s); | |
1569 | if (ret) | |
1570 | break; | |
1571 | p->defrect = s.r; | |
1572 | ||
1573 | /* setting trivial pixelaspect */ | |
1574 | p->pixelaspect.numerator = 1; | |
1575 | p->pixelaspect.denominator = 1; | |
1576 | } | |
1577 | ||
35ea11ff HV |
1578 | if (!ret) { |
1579 | dbgrect(vfd, "bounds ", &p->bounds); | |
1580 | dbgrect(vfd, "defrect ", &p->defrect); | |
1581 | } | |
1582 | break; | |
1583 | } | |
1584 | case VIDIOC_G_JPEGCOMP: | |
1585 | { | |
1586 | struct v4l2_jpegcompression *p = arg; | |
1587 | ||
a399810c | 1588 | ret = ops->vidioc_g_jpegcomp(file, fh, p); |
35ea11ff HV |
1589 | if (!ret) |
1590 | dbgarg(cmd, "quality=%d, APPn=%d, " | |
1591 | "APP_len=%d, COM_len=%d, " | |
1592 | "jpeg_markers=%d\n", | |
1593 | p->quality, p->APPn, p->APP_len, | |
1594 | p->COM_len, p->jpeg_markers); | |
1595 | break; | |
1596 | } | |
1597 | case VIDIOC_S_JPEGCOMP: | |
1598 | { | |
1599 | struct v4l2_jpegcompression *p = arg; | |
1600 | ||
35ea11ff HV |
1601 | dbgarg(cmd, "quality=%d, APPn=%d, APP_len=%d, " |
1602 | "COM_len=%d, jpeg_markers=%d\n", | |
1603 | p->quality, p->APPn, p->APP_len, | |
1604 | p->COM_len, p->jpeg_markers); | |
93d5a30b | 1605 | ret = ops->vidioc_s_jpegcomp(file, fh, p); |
35ea11ff HV |
1606 | break; |
1607 | } | |
1608 | case VIDIOC_G_ENC_INDEX: | |
1609 | { | |
1610 | struct v4l2_enc_idx *p = arg; | |
1611 | ||
a399810c | 1612 | ret = ops->vidioc_g_enc_index(file, fh, p); |
35ea11ff HV |
1613 | if (!ret) |
1614 | dbgarg(cmd, "entries=%d, entries_cap=%d\n", | |
1615 | p->entries, p->entries_cap); | |
1616 | break; | |
1617 | } | |
1618 | case VIDIOC_ENCODER_CMD: | |
1619 | { | |
1620 | struct v4l2_encoder_cmd *p = arg; | |
1621 | ||
a399810c | 1622 | ret = ops->vidioc_encoder_cmd(file, fh, p); |
35ea11ff HV |
1623 | if (!ret) |
1624 | dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags); | |
1625 | break; | |
1626 | } | |
1627 | case VIDIOC_TRY_ENCODER_CMD: | |
1628 | { | |
1629 | struct v4l2_encoder_cmd *p = arg; | |
1630 | ||
a399810c | 1631 | ret = ops->vidioc_try_encoder_cmd(file, fh, p); |
35ea11ff HV |
1632 | if (!ret) |
1633 | dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags); | |
1634 | break; | |
1635 | } | |
a45c0ad5 HV |
1636 | case VIDIOC_DECODER_CMD: |
1637 | { | |
1638 | struct v4l2_decoder_cmd *p = arg; | |
1639 | ||
a45c0ad5 HV |
1640 | ret = ops->vidioc_decoder_cmd(file, fh, p); |
1641 | if (!ret) | |
1642 | dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags); | |
1643 | break; | |
1644 | } | |
1645 | case VIDIOC_TRY_DECODER_CMD: | |
1646 | { | |
1647 | struct v4l2_decoder_cmd *p = arg; | |
1648 | ||
a45c0ad5 HV |
1649 | ret = ops->vidioc_try_decoder_cmd(file, fh, p); |
1650 | if (!ret) | |
1651 | dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags); | |
1652 | break; | |
1653 | } | |
35ea11ff HV |
1654 | case VIDIOC_G_PARM: |
1655 | { | |
1656 | struct v4l2_streamparm *p = arg; | |
35ea11ff | 1657 | |
a399810c | 1658 | if (ops->vidioc_g_parm) { |
34796bc0 TP |
1659 | ret = check_fmt(ops, p->type); |
1660 | if (ret) | |
1661 | break; | |
a399810c | 1662 | ret = ops->vidioc_g_parm(file, fh, p); |
35ea11ff | 1663 | } else { |
9bedc7f7 HV |
1664 | v4l2_std_id std = vfd->current_norm; |
1665 | ||
93d5a30b | 1666 | ret = -EINVAL; |
35ea11ff | 1667 | if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
3f5e1824 | 1668 | break; |
35ea11ff | 1669 | |
35ea11ff | 1670 | ret = 0; |
0c142c86 | 1671 | p->parm.capture.readbuffers = 2; |
9bedc7f7 HV |
1672 | if (ops->vidioc_g_std) |
1673 | ret = ops->vidioc_g_std(file, fh, &std); | |
9bedc7f7 HV |
1674 | if (ret == 0) |
1675 | v4l2_video_std_frame_period(std, | |
1676 | &p->parm.capture.timeperframe); | |
35ea11ff HV |
1677 | } |
1678 | ||
1679 | dbgarg(cmd, "type=%d\n", p->type); | |
1680 | break; | |
1681 | } | |
1682 | case VIDIOC_S_PARM: | |
1683 | { | |
1684 | struct v4l2_streamparm *p = arg; | |
1685 | ||
34796bc0 TP |
1686 | ret = check_fmt(ops, p->type); |
1687 | if (ret) | |
1688 | break; | |
1689 | ||
35ea11ff | 1690 | dbgarg(cmd, "type=%d\n", p->type); |
a399810c | 1691 | ret = ops->vidioc_s_parm(file, fh, p); |
35ea11ff HV |
1692 | break; |
1693 | } | |
1694 | case VIDIOC_G_TUNER: | |
1695 | { | |
1696 | struct v4l2_tuner *p = arg; | |
35ea11ff | 1697 | |
227690df HV |
1698 | p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ? |
1699 | V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; | |
a399810c | 1700 | ret = ops->vidioc_g_tuner(file, fh, p); |
35ea11ff HV |
1701 | if (!ret) |
1702 | dbgarg(cmd, "index=%d, name=%s, type=%d, " | |
1703 | "capability=0x%x, rangelow=%d, " | |
1704 | "rangehigh=%d, signal=%d, afc=%d, " | |
1705 | "rxsubchans=0x%x, audmode=%d\n", | |
1706 | p->index, p->name, p->type, | |
1707 | p->capability, p->rangelow, | |
1708 | p->rangehigh, p->signal, p->afc, | |
1709 | p->rxsubchans, p->audmode); | |
1710 | break; | |
1711 | } | |
1712 | case VIDIOC_S_TUNER: | |
1713 | { | |
1714 | struct v4l2_tuner *p = arg; | |
1715 | ||
227690df HV |
1716 | p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ? |
1717 | V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; | |
35ea11ff HV |
1718 | dbgarg(cmd, "index=%d, name=%s, type=%d, " |
1719 | "capability=0x%x, rangelow=%d, " | |
1720 | "rangehigh=%d, signal=%d, afc=%d, " | |
1721 | "rxsubchans=0x%x, audmode=%d\n", | |
1722 | p->index, p->name, p->type, | |
1723 | p->capability, p->rangelow, | |
1724 | p->rangehigh, p->signal, p->afc, | |
1725 | p->rxsubchans, p->audmode); | |
a399810c | 1726 | ret = ops->vidioc_s_tuner(file, fh, p); |
35ea11ff HV |
1727 | break; |
1728 | } | |
1729 | case VIDIOC_G_FREQUENCY: | |
1730 | { | |
1731 | struct v4l2_frequency *p = arg; | |
1732 | ||
227690df HV |
1733 | p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ? |
1734 | V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; | |
a399810c | 1735 | ret = ops->vidioc_g_frequency(file, fh, p); |
35ea11ff HV |
1736 | if (!ret) |
1737 | dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n", | |
1738 | p->tuner, p->type, p->frequency); | |
1739 | break; | |
1740 | } | |
1741 | case VIDIOC_S_FREQUENCY: | |
1742 | { | |
1743 | struct v4l2_frequency *p = arg; | |
aa07eec5 | 1744 | enum v4l2_tuner_type type; |
35ea11ff | 1745 | |
aa07eec5 HV |
1746 | type = (vfd->vfl_type == VFL_TYPE_RADIO) ? |
1747 | V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; | |
35ea11ff HV |
1748 | dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n", |
1749 | p->tuner, p->type, p->frequency); | |
aa07eec5 HV |
1750 | if (p->type != type) |
1751 | ret = -EINVAL; | |
1752 | else | |
1753 | ret = ops->vidioc_s_frequency(file, fh, p); | |
35ea11ff HV |
1754 | break; |
1755 | } | |
1756 | case VIDIOC_G_SLICED_VBI_CAP: | |
1757 | { | |
1758 | struct v4l2_sliced_vbi_cap *p = arg; | |
35ea11ff | 1759 | |
19c96e4b TP |
1760 | /* Clear up to type, everything after type is zerod already */ |
1761 | memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type)); | |
1762 | ||
35ea11ff | 1763 | dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names)); |
a399810c | 1764 | ret = ops->vidioc_g_sliced_vbi_cap(file, fh, p); |
35ea11ff HV |
1765 | if (!ret) |
1766 | dbgarg2("service_set=%d\n", p->service_set); | |
1767 | break; | |
1768 | } | |
1769 | case VIDIOC_LOG_STATUS: | |
1770 | { | |
e2ecb257 HV |
1771 | if (vfd->v4l2_dev) |
1772 | pr_info("%s: ================= START STATUS =================\n", | |
1773 | vfd->v4l2_dev->name); | |
a399810c | 1774 | ret = ops->vidioc_log_status(file, fh); |
e2ecb257 HV |
1775 | if (vfd->v4l2_dev) |
1776 | pr_info("%s: ================== END STATUS ==================\n", | |
1777 | vfd->v4l2_dev->name); | |
35ea11ff HV |
1778 | break; |
1779 | } | |
35ea11ff HV |
1780 | case VIDIOC_DBG_G_REGISTER: |
1781 | { | |
8ab75e3e | 1782 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
aecde8b5 | 1783 | struct v4l2_dbg_register *p = arg; |
35ea11ff | 1784 | |
48ea0be0 HV |
1785 | if (!capable(CAP_SYS_ADMIN)) |
1786 | ret = -EPERM; | |
1787 | else | |
1788 | ret = ops->vidioc_g_register(file, fh, p); | |
8ab75e3e | 1789 | #endif |
35ea11ff HV |
1790 | break; |
1791 | } | |
1792 | case VIDIOC_DBG_S_REGISTER: | |
1793 | { | |
8ab75e3e | 1794 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
aecde8b5 | 1795 | struct v4l2_dbg_register *p = arg; |
35ea11ff | 1796 | |
48ea0be0 HV |
1797 | if (!capable(CAP_SYS_ADMIN)) |
1798 | ret = -EPERM; | |
1799 | else | |
1800 | ret = ops->vidioc_s_register(file, fh, p); | |
8ab75e3e | 1801 | #endif |
35ea11ff HV |
1802 | break; |
1803 | } | |
aecde8b5 | 1804 | case VIDIOC_DBG_G_CHIP_IDENT: |
35ea11ff | 1805 | { |
aecde8b5 | 1806 | struct v4l2_dbg_chip_ident *p = arg; |
35ea11ff | 1807 | |
80b36e0f HV |
1808 | p->ident = V4L2_IDENT_NONE; |
1809 | p->revision = 0; | |
a399810c | 1810 | ret = ops->vidioc_g_chip_ident(file, fh, p); |
35ea11ff HV |
1811 | if (!ret) |
1812 | dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision); | |
1813 | break; | |
1814 | } | |
35ea11ff HV |
1815 | case VIDIOC_S_HW_FREQ_SEEK: |
1816 | { | |
1817 | struct v4l2_hw_freq_seek *p = arg; | |
a6cf90a9 | 1818 | enum v4l2_tuner_type type; |
35ea11ff | 1819 | |
a6cf90a9 HV |
1820 | type = (vfd->vfl_type == VFL_TYPE_RADIO) ? |
1821 | V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; | |
35ea11ff | 1822 | dbgarg(cmd, |
a6cf90a9 HV |
1823 | "tuner=%u, type=%u, seek_upward=%u, wrap_around=%u, spacing=%u\n", |
1824 | p->tuner, p->type, p->seek_upward, p->wrap_around, p->spacing); | |
1825 | if (p->type != type) | |
1826 | ret = -EINVAL; | |
1827 | else | |
1828 | ret = ops->vidioc_s_hw_freq_seek(file, fh, p); | |
a399810c HV |
1829 | break; |
1830 | } | |
74d83fa0 MCC |
1831 | case VIDIOC_ENUM_FRAMESIZES: |
1832 | { | |
1833 | struct v4l2_frmsizeenum *p = arg; | |
1834 | ||
74d83fa0 MCC |
1835 | ret = ops->vidioc_enum_framesizes(file, fh, p); |
1836 | dbgarg(cmd, | |
d1afe425 MCC |
1837 | "index=%d, pixelformat=%c%c%c%c, type=%d ", |
1838 | p->index, | |
1839 | (p->pixel_format & 0xff), | |
1840 | (p->pixel_format >> 8) & 0xff, | |
1841 | (p->pixel_format >> 16) & 0xff, | |
1842 | (p->pixel_format >> 24) & 0xff, | |
1843 | p->type); | |
74d83fa0 MCC |
1844 | switch (p->type) { |
1845 | case V4L2_FRMSIZE_TYPE_DISCRETE: | |
d33fbcbb | 1846 | dbgarg3("width = %d, height=%d\n", |
74d83fa0 MCC |
1847 | p->discrete.width, p->discrete.height); |
1848 | break; | |
1849 | case V4L2_FRMSIZE_TYPE_STEPWISE: | |
d33fbcbb | 1850 | dbgarg3("min %dx%d, max %dx%d, step %dx%d\n", |
74d83fa0 MCC |
1851 | p->stepwise.min_width, p->stepwise.min_height, |
1852 | p->stepwise.step_width, p->stepwise.step_height, | |
1853 | p->stepwise.max_width, p->stepwise.max_height); | |
1854 | break; | |
1855 | case V4L2_FRMSIZE_TYPE_CONTINUOUS: | |
d33fbcbb | 1856 | dbgarg3("continuous\n"); |
74d83fa0 MCC |
1857 | break; |
1858 | default: | |
d33fbcbb | 1859 | dbgarg3("- Unknown type!\n"); |
74d83fa0 MCC |
1860 | } |
1861 | ||
1862 | break; | |
1863 | } | |
1864 | case VIDIOC_ENUM_FRAMEINTERVALS: | |
1865 | { | |
1866 | struct v4l2_frmivalenum *p = arg; | |
1867 | ||
74d83fa0 MCC |
1868 | ret = ops->vidioc_enum_frameintervals(file, fh, p); |
1869 | dbgarg(cmd, | |
1870 | "index=%d, pixelformat=%d, width=%d, height=%d, type=%d ", | |
1871 | p->index, p->pixel_format, | |
1872 | p->width, p->height, p->type); | |
1873 | switch (p->type) { | |
1874 | case V4L2_FRMIVAL_TYPE_DISCRETE: | |
1875 | dbgarg2("fps=%d/%d\n", | |
1876 | p->discrete.numerator, | |
1877 | p->discrete.denominator); | |
1878 | break; | |
1879 | case V4L2_FRMIVAL_TYPE_STEPWISE: | |
1958578d MCC |
1880 | dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n", |
1881 | p->stepwise.min.numerator, | |
1882 | p->stepwise.min.denominator, | |
1883 | p->stepwise.max.numerator, | |
1884 | p->stepwise.max.denominator, | |
1885 | p->stepwise.step.numerator, | |
1886 | p->stepwise.step.denominator); | |
74d83fa0 MCC |
1887 | break; |
1888 | case V4L2_FRMIVAL_TYPE_CONTINUOUS: | |
1889 | dbgarg2("continuous\n"); | |
1890 | break; | |
1891 | default: | |
1892 | dbgarg2("- Unknown type!\n"); | |
1893 | } | |
1894 | break; | |
1895 | } | |
b6456c0c MK |
1896 | case VIDIOC_ENUM_DV_PRESETS: |
1897 | { | |
1898 | struct v4l2_dv_enum_preset *p = arg; | |
1899 | ||
b6456c0c MK |
1900 | ret = ops->vidioc_enum_dv_presets(file, fh, p); |
1901 | if (!ret) | |
1902 | dbgarg(cmd, | |
1903 | "index=%d, preset=%d, name=%s, width=%d," | |
1904 | " height=%d ", | |
1905 | p->index, p->preset, p->name, p->width, | |
1906 | p->height); | |
1907 | break; | |
1908 | } | |
1909 | case VIDIOC_S_DV_PRESET: | |
1910 | { | |
1911 | struct v4l2_dv_preset *p = arg; | |
1912 | ||
b6456c0c MK |
1913 | dbgarg(cmd, "preset=%d\n", p->preset); |
1914 | ret = ops->vidioc_s_dv_preset(file, fh, p); | |
1915 | break; | |
1916 | } | |
1917 | case VIDIOC_G_DV_PRESET: | |
1918 | { | |
1919 | struct v4l2_dv_preset *p = arg; | |
1920 | ||
b6456c0c MK |
1921 | ret = ops->vidioc_g_dv_preset(file, fh, p); |
1922 | if (!ret) | |
1923 | dbgarg(cmd, "preset=%d\n", p->preset); | |
1924 | break; | |
1925 | } | |
1926 | case VIDIOC_QUERY_DV_PRESET: | |
1927 | { | |
1928 | struct v4l2_dv_preset *p = arg; | |
1929 | ||
b6456c0c MK |
1930 | ret = ops->vidioc_query_dv_preset(file, fh, p); |
1931 | if (!ret) | |
1932 | dbgarg(cmd, "preset=%d\n", p->preset); | |
1933 | break; | |
1934 | } | |
1935 | case VIDIOC_S_DV_TIMINGS: | |
1936 | { | |
1937 | struct v4l2_dv_timings *p = arg; | |
1938 | ||
5d7758ee | 1939 | dbgtimings(vfd, p); |
b6456c0c MK |
1940 | switch (p->type) { |
1941 | case V4L2_DV_BT_656_1120: | |
b6456c0c MK |
1942 | ret = ops->vidioc_s_dv_timings(file, fh, p); |
1943 | break; | |
1944 | default: | |
5d7758ee | 1945 | ret = -EINVAL; |
b6456c0c MK |
1946 | break; |
1947 | } | |
1948 | break; | |
1949 | } | |
1950 | case VIDIOC_G_DV_TIMINGS: | |
1951 | { | |
1952 | struct v4l2_dv_timings *p = arg; | |
1953 | ||
b6456c0c | 1954 | ret = ops->vidioc_g_dv_timings(file, fh, p); |
5d7758ee HV |
1955 | if (!ret) |
1956 | dbgtimings(vfd, p); | |
1957 | break; | |
1958 | } | |
1959 | case VIDIOC_ENUM_DV_TIMINGS: | |
1960 | { | |
1961 | struct v4l2_enum_dv_timings *p = arg; | |
1962 | ||
1963 | if (!ops->vidioc_enum_dv_timings) | |
1964 | break; | |
1965 | ||
1966 | ret = ops->vidioc_enum_dv_timings(file, fh, p); | |
b6456c0c | 1967 | if (!ret) { |
5d7758ee HV |
1968 | dbgarg(cmd, "index=%d: ", p->index); |
1969 | dbgtimings(vfd, &p->timings); | |
1970 | } | |
1971 | break; | |
1972 | } | |
1973 | case VIDIOC_QUERY_DV_TIMINGS: | |
1974 | { | |
1975 | struct v4l2_dv_timings *p = arg; | |
1976 | ||
1977 | if (!ops->vidioc_query_dv_timings) | |
1978 | break; | |
1979 | ||
1980 | ret = ops->vidioc_query_dv_timings(file, fh, p); | |
1981 | if (!ret) | |
1982 | dbgtimings(vfd, p); | |
1983 | break; | |
1984 | } | |
1985 | case VIDIOC_DV_TIMINGS_CAP: | |
1986 | { | |
1987 | struct v4l2_dv_timings_cap *p = arg; | |
1988 | ||
1989 | if (!ops->vidioc_dv_timings_cap) | |
1990 | break; | |
1991 | ||
1992 | ret = ops->vidioc_dv_timings_cap(file, fh, p); | |
1993 | if (ret) | |
1994 | break; | |
1995 | switch (p->type) { | |
1996 | case V4L2_DV_BT_656_1120: | |
1997 | dbgarg(cmd, | |
1998 | "type=%d, width=%u-%u, height=%u-%u, " | |
1999 | "pixelclock=%llu-%llu, standards=%x, capabilities=%x ", | |
2000 | p->type, | |
2001 | p->bt.min_width, p->bt.max_width, | |
2002 | p->bt.min_height, p->bt.max_height, | |
2003 | p->bt.min_pixelclock, p->bt.max_pixelclock, | |
2004 | p->bt.standards, p->bt.capabilities); | |
2005 | break; | |
2006 | default: | |
2007 | dbgarg(cmd, "unknown type "); | |
2008 | break; | |
b6456c0c MK |
2009 | } |
2010 | break; | |
2011 | } | |
d3d7c963 SA |
2012 | case VIDIOC_DQEVENT: |
2013 | { | |
2014 | struct v4l2_event *ev = arg; | |
2015 | ||
d3d7c963 SA |
2016 | ret = v4l2_event_dequeue(fh, ev, file->f_flags & O_NONBLOCK); |
2017 | if (ret < 0) { | |
2018 | dbgarg(cmd, "no pending events?"); | |
2019 | break; | |
2020 | } | |
2021 | dbgarg(cmd, | |
2022 | "pending=%d, type=0x%8.8x, sequence=%d, " | |
2023 | "timestamp=%lu.%9.9lu ", | |
2024 | ev->pending, ev->type, ev->sequence, | |
2025 | ev->timestamp.tv_sec, ev->timestamp.tv_nsec); | |
2026 | break; | |
2027 | } | |
2028 | case VIDIOC_SUBSCRIBE_EVENT: | |
2029 | { | |
2030 | struct v4l2_event_subscription *sub = arg; | |
2031 | ||
d3d7c963 SA |
2032 | ret = ops->vidioc_subscribe_event(fh, sub); |
2033 | if (ret < 0) { | |
2034 | dbgarg(cmd, "failed, ret=%ld", ret); | |
2035 | break; | |
2036 | } | |
2037 | dbgarg(cmd, "type=0x%8.8x", sub->type); | |
2038 | break; | |
2039 | } | |
2040 | case VIDIOC_UNSUBSCRIBE_EVENT: | |
2041 | { | |
2042 | struct v4l2_event_subscription *sub = arg; | |
2043 | ||
d3d7c963 SA |
2044 | ret = ops->vidioc_unsubscribe_event(fh, sub); |
2045 | if (ret < 0) { | |
2046 | dbgarg(cmd, "failed, ret=%ld", ret); | |
2047 | break; | |
2048 | } | |
2049 | dbgarg(cmd, "type=0x%8.8x", sub->type); | |
2050 | break; | |
2051 | } | |
2150158b GL |
2052 | case VIDIOC_CREATE_BUFS: |
2053 | { | |
2054 | struct v4l2_create_buffers *create = arg; | |
2055 | ||
2150158b GL |
2056 | ret = check_fmt(ops, create->format.type); |
2057 | if (ret) | |
2058 | break; | |
2059 | ||
2060 | ret = ops->vidioc_create_bufs(file, fh, create); | |
2061 | ||
2062 | dbgarg(cmd, "count=%d @ %d\n", create->count, create->index); | |
2063 | break; | |
2064 | } | |
2065 | case VIDIOC_PREPARE_BUF: | |
2066 | { | |
2067 | struct v4l2_buffer *b = arg; | |
2068 | ||
2150158b GL |
2069 | ret = check_fmt(ops, b->type); |
2070 | if (ret) | |
2071 | break; | |
2072 | ||
2073 | ret = ops->vidioc_prepare_buf(file, fh, b); | |
2074 | ||
2075 | dbgarg(cmd, "index=%d", b->index); | |
2076 | break; | |
2077 | } | |
a399810c | 2078 | default: |
a399810c HV |
2079 | if (!ops->vidioc_default) |
2080 | break; | |
4b902fec HV |
2081 | ret = ops->vidioc_default(file, fh, use_fh_prio ? |
2082 | v4l2_prio_check(vfd->prio, vfh->prio) >= 0 : 0, | |
2083 | cmd, arg); | |
35ea11ff | 2084 | break; |
35ea11ff HV |
2085 | } /* switch */ |
2086 | ||
86748f35 HV |
2087 | done: |
2088 | if (vfd->debug) { | |
2089 | if (write_only && vfd->debug > V4L2_DEBUG_IOCTL) { | |
2090 | if (ret < 0) | |
2091 | printk(KERN_DEBUG "%s: error %ld\n", | |
2092 | video_device_node_name(vfd), ret); | |
2093 | return ret; | |
2094 | } | |
2095 | v4l_print_ioctl(vfd->name, cmd); | |
2096 | if (ret < 0) | |
2097 | pr_cont(": error %ld\n", ret); | |
2098 | else if (vfd->debug == V4L2_DEBUG_IOCTL) | |
2099 | pr_cont("\n"); | |
2100 | else if (!info->debug) | |
2101 | return ret; | |
2102 | else if (_IOC_DIR(cmd) == _IOC_NONE) | |
2103 | info->debug(arg, write_only); | |
2104 | else { | |
2105 | pr_cont(": "); | |
2106 | info->debug(arg, write_only); | |
35ea11ff HV |
2107 | } |
2108 | } | |
2109 | ||
2110 | return ret; | |
2111 | } | |
2112 | ||
d14e6d76 PO |
2113 | static int check_array_args(unsigned int cmd, void *parg, size_t *array_size, |
2114 | void * __user *user_ptr, void ***kernel_ptr) | |
2115 | { | |
2116 | int ret = 0; | |
2117 | ||
2118 | switch (cmd) { | |
2119 | case VIDIOC_QUERYBUF: | |
2120 | case VIDIOC_QBUF: | |
2121 | case VIDIOC_DQBUF: { | |
2122 | struct v4l2_buffer *buf = parg; | |
2123 | ||
2124 | if (V4L2_TYPE_IS_MULTIPLANAR(buf->type) && buf->length > 0) { | |
2125 | if (buf->length > VIDEO_MAX_PLANES) { | |
2126 | ret = -EINVAL; | |
2127 | break; | |
2128 | } | |
2129 | *user_ptr = (void __user *)buf->m.planes; | |
2ef40370 | 2130 | *kernel_ptr = (void *)&buf->m.planes; |
d14e6d76 PO |
2131 | *array_size = sizeof(struct v4l2_plane) * buf->length; |
2132 | ret = 1; | |
2133 | } | |
2134 | break; | |
2135 | } | |
2136 | ||
2137 | case VIDIOC_S_EXT_CTRLS: | |
2138 | case VIDIOC_G_EXT_CTRLS: | |
2139 | case VIDIOC_TRY_EXT_CTRLS: { | |
2140 | struct v4l2_ext_controls *ctrls = parg; | |
2141 | ||
2142 | if (ctrls->count != 0) { | |
6c06108b DC |
2143 | if (ctrls->count > V4L2_CID_MAX_CTRLS) { |
2144 | ret = -EINVAL; | |
2145 | break; | |
2146 | } | |
d14e6d76 | 2147 | *user_ptr = (void __user *)ctrls->controls; |
2ef40370 | 2148 | *kernel_ptr = (void *)&ctrls->controls; |
d14e6d76 PO |
2149 | *array_size = sizeof(struct v4l2_ext_control) |
2150 | * ctrls->count; | |
2151 | ret = 1; | |
2152 | } | |
2153 | break; | |
2154 | } | |
2155 | } | |
2156 | ||
2157 | return ret; | |
2158 | } | |
2159 | ||
fc0a8079 LP |
2160 | long |
2161 | video_usercopy(struct file *file, unsigned int cmd, unsigned long arg, | |
2162 | v4l2_kioctl func) | |
35ea11ff HV |
2163 | { |
2164 | char sbuf[128]; | |
2165 | void *mbuf = NULL; | |
1d94aa36 | 2166 | void *parg = (void *)arg; |
069b7479 | 2167 | long err = -EINVAL; |
d14e6d76 PO |
2168 | bool has_array_args; |
2169 | size_t array_size = 0; | |
35ea11ff | 2170 | void __user *user_ptr = NULL; |
d14e6d76 | 2171 | void **kernel_ptr = NULL; |
35ea11ff | 2172 | |
35ea11ff | 2173 | /* Copy arguments into temp kernel buffer */ |
337f9d20 | 2174 | if (_IOC_DIR(cmd) != _IOC_NONE) { |
35ea11ff HV |
2175 | if (_IOC_SIZE(cmd) <= sizeof(sbuf)) { |
2176 | parg = sbuf; | |
2177 | } else { | |
2178 | /* too big to allocate from stack */ | |
2179 | mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL); | |
2180 | if (NULL == mbuf) | |
2181 | return -ENOMEM; | |
2182 | parg = mbuf; | |
2183 | } | |
2184 | ||
2185 | err = -EFAULT; | |
19c96e4b | 2186 | if (_IOC_DIR(cmd) & _IOC_WRITE) { |
27cd2aba HV |
2187 | unsigned int n = _IOC_SIZE(cmd); |
2188 | ||
2189 | /* | |
2190 | * In some cases, only a few fields are used as input, | |
2191 | * i.e. when the app sets "index" and then the driver | |
2192 | * fills in the rest of the structure for the thing | |
2193 | * with that index. We only need to copy up the first | |
2194 | * non-input field. | |
2195 | */ | |
2196 | if (v4l2_is_known_ioctl(cmd)) { | |
2197 | u32 flags = v4l2_ioctls[_IOC_NR(cmd)].flags; | |
2198 | if (flags & INFO_FL_CLEAR_MASK) | |
2199 | n = (flags & INFO_FL_CLEAR_MASK) >> 16; | |
2200 | } | |
19c96e4b TP |
2201 | |
2202 | if (copy_from_user(parg, (void __user *)arg, n)) | |
35ea11ff | 2203 | goto out; |
19c96e4b TP |
2204 | |
2205 | /* zero out anything we don't copy from userspace */ | |
2206 | if (n < _IOC_SIZE(cmd)) | |
2207 | memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n); | |
337f9d20 TP |
2208 | } else { |
2209 | /* read-only ioctl */ | |
2210 | memset(parg, 0, _IOC_SIZE(cmd)); | |
19c96e4b | 2211 | } |
35ea11ff HV |
2212 | } |
2213 | ||
d14e6d76 PO |
2214 | err = check_array_args(cmd, parg, &array_size, &user_ptr, &kernel_ptr); |
2215 | if (err < 0) | |
2216 | goto out; | |
2217 | has_array_args = err; | |
35ea11ff | 2218 | |
d14e6d76 PO |
2219 | if (has_array_args) { |
2220 | /* | |
2221 | * When adding new types of array args, make sure that the | |
2222 | * parent argument to ioctl (which contains the pointer to the | |
2223 | * array) fits into sbuf (so that mbuf will still remain | |
2224 | * unused up to here). | |
2225 | */ | |
2226 | mbuf = kmalloc(array_size, GFP_KERNEL); | |
2227 | err = -ENOMEM; | |
2228 | if (NULL == mbuf) | |
2229 | goto out_array_args; | |
2230 | err = -EFAULT; | |
2231 | if (copy_from_user(mbuf, user_ptr, array_size)) | |
2232 | goto out_array_args; | |
2233 | *kernel_ptr = mbuf; | |
35ea11ff HV |
2234 | } |
2235 | ||
2236 | /* Handles IOCTL */ | |
fc0a8079 | 2237 | err = func(file, cmd, parg); |
35ea11ff | 2238 | if (err == -ENOIOCTLCMD) |
02bbb814 | 2239 | err = -ENOTTY; |
35ea11ff | 2240 | |
d14e6d76 PO |
2241 | if (has_array_args) { |
2242 | *kernel_ptr = user_ptr; | |
2243 | if (copy_to_user(user_ptr, mbuf, array_size)) | |
35ea11ff | 2244 | err = -EFAULT; |
d14e6d76 | 2245 | goto out_array_args; |
35ea11ff | 2246 | } |
5d7758ee HV |
2247 | /* VIDIOC_QUERY_DV_TIMINGS can return an error, but still have valid |
2248 | results that must be returned. */ | |
2249 | if (err < 0 && cmd != VIDIOC_QUERY_DV_TIMINGS) | |
35ea11ff HV |
2250 | goto out; |
2251 | ||
d14e6d76 | 2252 | out_array_args: |
35ea11ff HV |
2253 | /* Copy results into user buffer */ |
2254 | switch (_IOC_DIR(cmd)) { | |
2255 | case _IOC_READ: | |
2256 | case (_IOC_WRITE | _IOC_READ): | |
2257 | if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd))) | |
2258 | err = -EFAULT; | |
2259 | break; | |
2260 | } | |
2261 | ||
2262 | out: | |
2263 | kfree(mbuf); | |
2264 | return err; | |
2265 | } | |
fc0a8079 LP |
2266 | EXPORT_SYMBOL(video_usercopy); |
2267 | ||
2268 | long video_ioctl2(struct file *file, | |
2269 | unsigned int cmd, unsigned long arg) | |
2270 | { | |
2271 | return video_usercopy(file, cmd, arg, __video_do_ioctl); | |
2272 | } | |
8a522c91 | 2273 | EXPORT_SYMBOL(video_ioctl2); |