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