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