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