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