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