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