1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Video capture interface for Linux version 2 4 * 5 * A generic framework to process V4L2 ioctl commands. 6 * 7 * Authors: Alan Cox, <alan@lxorguk.ukuu.org.uk> (version 1) 8 * Mauro Carvalho Chehab <mchehab@kernel.org> (version 2) 9 */ 10 11 #include <linux/compat.h> 12 #include <linux/mm.h> 13 #include <linux/module.h> 14 #include <linux/slab.h> 15 #include <linux/types.h> 16 #include <linux/kernel.h> 17 #include <linux/version.h> 18 19 #include <linux/videodev2.h> 20 21 #include <media/v4l2-common.h> 22 #include <media/v4l2-ioctl.h> 23 #include <media/v4l2-ctrls.h> 24 #include <media/v4l2-fh.h> 25 #include <media/v4l2-event.h> 26 #include <media/v4l2-device.h> 27 #include <media/videobuf2-v4l2.h> 28 #include <media/v4l2-mc.h> 29 #include <media/v4l2-mem2mem.h> 30 31 #include <trace/events/v4l2.h> 32 33 /* Zero out the end of the struct pointed to by p. Everything after, but 34 * not including, the specified field is cleared. */ 35 #define CLEAR_AFTER_FIELD(p, field) \ 36 memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \ 37 0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field)) 38 39 #define is_valid_ioctl(vfd, cmd) test_bit(_IOC_NR(cmd), (vfd)->valid_ioctls) 40 41 struct std_descr { 42 v4l2_std_id std; 43 const char *descr; 44 }; 45 46 static const struct std_descr standards[] = { 47 { V4L2_STD_NTSC, "NTSC" }, 48 { V4L2_STD_NTSC_M, "NTSC-M" }, 49 { V4L2_STD_NTSC_M_JP, "NTSC-M-JP" }, 50 { V4L2_STD_NTSC_M_KR, "NTSC-M-KR" }, 51 { V4L2_STD_NTSC_443, "NTSC-443" }, 52 { V4L2_STD_PAL, "PAL" }, 53 { V4L2_STD_PAL_BG, "PAL-BG" }, 54 { V4L2_STD_PAL_B, "PAL-B" }, 55 { V4L2_STD_PAL_B1, "PAL-B1" }, 56 { V4L2_STD_PAL_G, "PAL-G" }, 57 { V4L2_STD_PAL_H, "PAL-H" }, 58 { V4L2_STD_PAL_I, "PAL-I" }, 59 { V4L2_STD_PAL_DK, "PAL-DK" }, 60 { V4L2_STD_PAL_D, "PAL-D" }, 61 { V4L2_STD_PAL_D1, "PAL-D1" }, 62 { V4L2_STD_PAL_K, "PAL-K" }, 63 { V4L2_STD_PAL_M, "PAL-M" }, 64 { V4L2_STD_PAL_N, "PAL-N" }, 65 { V4L2_STD_PAL_Nc, "PAL-Nc" }, 66 { V4L2_STD_PAL_60, "PAL-60" }, 67 { V4L2_STD_SECAM, "SECAM" }, 68 { V4L2_STD_SECAM_B, "SECAM-B" }, 69 { V4L2_STD_SECAM_G, "SECAM-G" }, 70 { V4L2_STD_SECAM_H, "SECAM-H" }, 71 { V4L2_STD_SECAM_DK, "SECAM-DK" }, 72 { V4L2_STD_SECAM_D, "SECAM-D" }, 73 { V4L2_STD_SECAM_K, "SECAM-K" }, 74 { V4L2_STD_SECAM_K1, "SECAM-K1" }, 75 { V4L2_STD_SECAM_L, "SECAM-L" }, 76 { V4L2_STD_SECAM_LC, "SECAM-Lc" }, 77 { 0, "Unknown" } 78 }; 79 80 /* video4linux standard ID conversion to standard name 81 */ 82 const char *v4l2_norm_to_name(v4l2_std_id id) 83 { 84 u32 myid = id; 85 int i; 86 87 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle 88 64 bit comparisons. So, on that architecture, with some gcc 89 variants, compilation fails. Currently, the max value is 30bit wide. 90 */ 91 BUG_ON(myid != id); 92 93 for (i = 0; standards[i].std; i++) 94 if (myid == standards[i].std) 95 break; 96 return standards[i].descr; 97 } 98 EXPORT_SYMBOL(v4l2_norm_to_name); 99 100 /* Returns frame period for the given standard */ 101 void v4l2_video_std_frame_period(int id, struct v4l2_fract *frameperiod) 102 { 103 if (id & V4L2_STD_525_60) { 104 frameperiod->numerator = 1001; 105 frameperiod->denominator = 30000; 106 } else { 107 frameperiod->numerator = 1; 108 frameperiod->denominator = 25; 109 } 110 } 111 EXPORT_SYMBOL(v4l2_video_std_frame_period); 112 113 /* Fill in the fields of a v4l2_standard structure according to the 114 'id' and 'transmission' parameters. Returns negative on error. */ 115 int v4l2_video_std_construct(struct v4l2_standard *vs, 116 int id, const char *name) 117 { 118 vs->id = id; 119 v4l2_video_std_frame_period(id, &vs->frameperiod); 120 vs->framelines = (id & V4L2_STD_525_60) ? 525 : 625; 121 strscpy(vs->name, name, sizeof(vs->name)); 122 return 0; 123 } 124 EXPORT_SYMBOL(v4l2_video_std_construct); 125 126 /* Fill in the fields of a v4l2_standard structure according to the 127 * 'id' and 'vs->index' parameters. Returns negative on error. */ 128 int v4l_video_std_enumstd(struct v4l2_standard *vs, v4l2_std_id id) 129 { 130 v4l2_std_id curr_id = 0; 131 unsigned int index = vs->index, i, j = 0; 132 const char *descr = ""; 133 134 /* Return -ENODATA if the id for the current input 135 or output is 0, meaning that it doesn't support this API. */ 136 if (id == 0) 137 return -ENODATA; 138 139 /* Return norm array in a canonical way */ 140 for (i = 0; i <= index && id; i++) { 141 /* last std value in the standards array is 0, so this 142 while always ends there since (id & 0) == 0. */ 143 while ((id & standards[j].std) != standards[j].std) 144 j++; 145 curr_id = standards[j].std; 146 descr = standards[j].descr; 147 j++; 148 if (curr_id == 0) 149 break; 150 if (curr_id != V4L2_STD_PAL && 151 curr_id != V4L2_STD_SECAM && 152 curr_id != V4L2_STD_NTSC) 153 id &= ~curr_id; 154 } 155 if (i <= index) 156 return -EINVAL; 157 158 v4l2_video_std_construct(vs, curr_id, descr); 159 return 0; 160 } 161 162 /* ----------------------------------------------------------------- */ 163 /* some arrays for pretty-printing debug messages of enum types */ 164 165 const char *v4l2_field_names[] = { 166 [V4L2_FIELD_ANY] = "any", 167 [V4L2_FIELD_NONE] = "none", 168 [V4L2_FIELD_TOP] = "top", 169 [V4L2_FIELD_BOTTOM] = "bottom", 170 [V4L2_FIELD_INTERLACED] = "interlaced", 171 [V4L2_FIELD_SEQ_TB] = "seq-tb", 172 [V4L2_FIELD_SEQ_BT] = "seq-bt", 173 [V4L2_FIELD_ALTERNATE] = "alternate", 174 [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb", 175 [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt", 176 }; 177 EXPORT_SYMBOL(v4l2_field_names); 178 179 const char *v4l2_type_names[] = { 180 [0] = "0", 181 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "vid-cap", 182 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "vid-overlay", 183 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "vid-out", 184 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap", 185 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out", 186 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap", 187 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out", 188 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "vid-out-overlay", 189 [V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE] = "vid-cap-mplane", 190 [V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE] = "vid-out-mplane", 191 [V4L2_BUF_TYPE_SDR_CAPTURE] = "sdr-cap", 192 [V4L2_BUF_TYPE_SDR_OUTPUT] = "sdr-out", 193 [V4L2_BUF_TYPE_META_CAPTURE] = "meta-cap", 194 [V4L2_BUF_TYPE_META_OUTPUT] = "meta-out", 195 }; 196 EXPORT_SYMBOL(v4l2_type_names); 197 198 static const char *v4l2_memory_names[] = { 199 [V4L2_MEMORY_MMAP] = "mmap", 200 [V4L2_MEMORY_USERPTR] = "userptr", 201 [V4L2_MEMORY_OVERLAY] = "overlay", 202 [V4L2_MEMORY_DMABUF] = "dmabuf", 203 }; 204 205 #define prt_names(a, arr) (((unsigned)(a)) < ARRAY_SIZE(arr) ? arr[a] : "unknown") 206 207 /* ------------------------------------------------------------------ */ 208 /* debug help functions */ 209 210 static void v4l_print_querycap(const void *arg, bool write_only) 211 { 212 const struct v4l2_capability *p = arg; 213 214 pr_cont("driver=%.*s, card=%.*s, bus=%.*s, version=0x%08x, capabilities=0x%08x, device_caps=0x%08x\n", 215 (int)sizeof(p->driver), p->driver, 216 (int)sizeof(p->card), p->card, 217 (int)sizeof(p->bus_info), p->bus_info, 218 p->version, p->capabilities, p->device_caps); 219 } 220 221 static void v4l_print_enuminput(const void *arg, bool write_only) 222 { 223 const struct v4l2_input *p = arg; 224 225 pr_cont("index=%u, name=%.*s, type=%u, audioset=0x%x, tuner=%u, std=0x%08Lx, status=0x%x, capabilities=0x%x\n", 226 p->index, (int)sizeof(p->name), p->name, p->type, p->audioset, 227 p->tuner, (unsigned long long)p->std, p->status, 228 p->capabilities); 229 } 230 231 static void v4l_print_enumoutput(const void *arg, bool write_only) 232 { 233 const struct v4l2_output *p = arg; 234 235 pr_cont("index=%u, name=%.*s, type=%u, audioset=0x%x, modulator=%u, std=0x%08Lx, capabilities=0x%x\n", 236 p->index, (int)sizeof(p->name), p->name, p->type, p->audioset, 237 p->modulator, (unsigned long long)p->std, p->capabilities); 238 } 239 240 static void v4l_print_audio(const void *arg, bool write_only) 241 { 242 const struct v4l2_audio *p = arg; 243 244 if (write_only) 245 pr_cont("index=%u, mode=0x%x\n", p->index, p->mode); 246 else 247 pr_cont("index=%u, name=%.*s, capability=0x%x, mode=0x%x\n", 248 p->index, (int)sizeof(p->name), p->name, 249 p->capability, p->mode); 250 } 251 252 static void v4l_print_audioout(const void *arg, bool write_only) 253 { 254 const struct v4l2_audioout *p = arg; 255 256 if (write_only) 257 pr_cont("index=%u\n", p->index); 258 else 259 pr_cont("index=%u, name=%.*s, capability=0x%x, mode=0x%x\n", 260 p->index, (int)sizeof(p->name), p->name, 261 p->capability, p->mode); 262 } 263 264 static void v4l_print_fmtdesc(const void *arg, bool write_only) 265 { 266 const struct v4l2_fmtdesc *p = arg; 267 268 pr_cont("index=%u, type=%s, flags=0x%x, pixelformat=%p4cc, mbus_code=0x%04x, description='%.*s'\n", 269 p->index, prt_names(p->type, v4l2_type_names), 270 p->flags, &p->pixelformat, p->mbus_code, 271 (int)sizeof(p->description), p->description); 272 } 273 274 static void v4l_print_format(const void *arg, bool write_only) 275 { 276 const struct v4l2_format *p = arg; 277 const struct v4l2_pix_format *pix; 278 const struct v4l2_pix_format_mplane *mp; 279 const struct v4l2_vbi_format *vbi; 280 const struct v4l2_sliced_vbi_format *sliced; 281 const struct v4l2_window *win; 282 const struct v4l2_sdr_format *sdr; 283 const struct v4l2_meta_format *meta; 284 u32 planes; 285 unsigned i; 286 287 pr_cont("type=%s", prt_names(p->type, v4l2_type_names)); 288 switch (p->type) { 289 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 290 case V4L2_BUF_TYPE_VIDEO_OUTPUT: 291 pix = &p->fmt.pix; 292 pr_cont(", width=%u, height=%u, pixelformat=%p4cc, field=%s, bytesperline=%u, sizeimage=%u, colorspace=%d, flags=0x%x, ycbcr_enc=%u, quantization=%u, xfer_func=%u\n", 293 pix->width, pix->height, &pix->pixelformat, 294 prt_names(pix->field, v4l2_field_names), 295 pix->bytesperline, pix->sizeimage, 296 pix->colorspace, pix->flags, pix->ycbcr_enc, 297 pix->quantization, pix->xfer_func); 298 break; 299 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: 300 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: 301 mp = &p->fmt.pix_mp; 302 pr_cont(", width=%u, height=%u, format=%p4cc, field=%s, colorspace=%d, num_planes=%u, flags=0x%x, ycbcr_enc=%u, quantization=%u, xfer_func=%u\n", 303 mp->width, mp->height, &mp->pixelformat, 304 prt_names(mp->field, v4l2_field_names), 305 mp->colorspace, mp->num_planes, mp->flags, 306 mp->ycbcr_enc, mp->quantization, mp->xfer_func); 307 planes = min_t(u32, mp->num_planes, VIDEO_MAX_PLANES); 308 for (i = 0; i < planes; i++) 309 printk(KERN_DEBUG "plane %u: bytesperline=%u sizeimage=%u\n", i, 310 mp->plane_fmt[i].bytesperline, 311 mp->plane_fmt[i].sizeimage); 312 break; 313 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 314 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: 315 win = &p->fmt.win; 316 /* Note: we can't print the clip list here since the clips 317 * pointer is a userspace pointer, not a kernelspace 318 * pointer. */ 319 pr_cont(", wxh=%dx%d, x,y=%d,%d, field=%s, chromakey=0x%08x, clipcount=%u, clips=%p, bitmap=%p, global_alpha=0x%02x\n", 320 win->w.width, win->w.height, win->w.left, win->w.top, 321 prt_names(win->field, v4l2_field_names), 322 win->chromakey, win->clipcount, win->clips, 323 win->bitmap, win->global_alpha); 324 break; 325 case V4L2_BUF_TYPE_VBI_CAPTURE: 326 case V4L2_BUF_TYPE_VBI_OUTPUT: 327 vbi = &p->fmt.vbi; 328 pr_cont(", sampling_rate=%u, offset=%u, samples_per_line=%u, sample_format=%p4cc, start=%u,%u, count=%u,%u\n", 329 vbi->sampling_rate, vbi->offset, 330 vbi->samples_per_line, &vbi->sample_format, 331 vbi->start[0], vbi->start[1], 332 vbi->count[0], vbi->count[1]); 333 break; 334 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: 335 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: 336 sliced = &p->fmt.sliced; 337 pr_cont(", service_set=0x%08x, io_size=%d\n", 338 sliced->service_set, sliced->io_size); 339 for (i = 0; i < 24; i++) 340 printk(KERN_DEBUG "line[%02u]=0x%04x, 0x%04x\n", i, 341 sliced->service_lines[0][i], 342 sliced->service_lines[1][i]); 343 break; 344 case V4L2_BUF_TYPE_SDR_CAPTURE: 345 case V4L2_BUF_TYPE_SDR_OUTPUT: 346 sdr = &p->fmt.sdr; 347 pr_cont(", pixelformat=%p4cc\n", &sdr->pixelformat); 348 break; 349 case V4L2_BUF_TYPE_META_CAPTURE: 350 case V4L2_BUF_TYPE_META_OUTPUT: 351 meta = &p->fmt.meta; 352 pr_cont(", dataformat=%p4cc, buffersize=%u\n", 353 &meta->dataformat, meta->buffersize); 354 break; 355 } 356 } 357 358 static void v4l_print_framebuffer(const void *arg, bool write_only) 359 { 360 const struct v4l2_framebuffer *p = arg; 361 362 pr_cont("capability=0x%x, flags=0x%x, base=0x%p, width=%u, height=%u, pixelformat=%p4cc, bytesperline=%u, sizeimage=%u, colorspace=%d\n", 363 p->capability, p->flags, p->base, p->fmt.width, p->fmt.height, 364 &p->fmt.pixelformat, p->fmt.bytesperline, p->fmt.sizeimage, 365 p->fmt.colorspace); 366 } 367 368 static void v4l_print_buftype(const void *arg, bool write_only) 369 { 370 pr_cont("type=%s\n", prt_names(*(u32 *)arg, v4l2_type_names)); 371 } 372 373 static void v4l_print_modulator(const void *arg, bool write_only) 374 { 375 const struct v4l2_modulator *p = arg; 376 377 if (write_only) 378 pr_cont("index=%u, txsubchans=0x%x\n", p->index, p->txsubchans); 379 else 380 pr_cont("index=%u, name=%.*s, capability=0x%x, rangelow=%u, rangehigh=%u, txsubchans=0x%x\n", 381 p->index, (int)sizeof(p->name), p->name, p->capability, 382 p->rangelow, p->rangehigh, p->txsubchans); 383 } 384 385 static void v4l_print_tuner(const void *arg, bool write_only) 386 { 387 const struct v4l2_tuner *p = arg; 388 389 if (write_only) 390 pr_cont("index=%u, audmode=%u\n", p->index, p->audmode); 391 else 392 pr_cont("index=%u, name=%.*s, type=%u, capability=0x%x, rangelow=%u, rangehigh=%u, signal=%u, afc=%d, rxsubchans=0x%x, audmode=%u\n", 393 p->index, (int)sizeof(p->name), p->name, p->type, 394 p->capability, p->rangelow, 395 p->rangehigh, p->signal, p->afc, 396 p->rxsubchans, p->audmode); 397 } 398 399 static void v4l_print_frequency(const void *arg, bool write_only) 400 { 401 const struct v4l2_frequency *p = arg; 402 403 pr_cont("tuner=%u, type=%u, frequency=%u\n", 404 p->tuner, p->type, p->frequency); 405 } 406 407 static void v4l_print_standard(const void *arg, bool write_only) 408 { 409 const struct v4l2_standard *p = arg; 410 411 pr_cont("index=%u, id=0x%Lx, name=%.*s, fps=%u/%u, framelines=%u\n", 412 p->index, 413 (unsigned long long)p->id, (int)sizeof(p->name), p->name, 414 p->frameperiod.numerator, 415 p->frameperiod.denominator, 416 p->framelines); 417 } 418 419 static void v4l_print_std(const void *arg, bool write_only) 420 { 421 pr_cont("std=0x%08Lx\n", *(const long long unsigned *)arg); 422 } 423 424 static void v4l_print_hw_freq_seek(const void *arg, bool write_only) 425 { 426 const struct v4l2_hw_freq_seek *p = arg; 427 428 pr_cont("tuner=%u, type=%u, seek_upward=%u, wrap_around=%u, spacing=%u, rangelow=%u, rangehigh=%u\n", 429 p->tuner, p->type, p->seek_upward, p->wrap_around, p->spacing, 430 p->rangelow, p->rangehigh); 431 } 432 433 static void v4l_print_requestbuffers(const void *arg, bool write_only) 434 { 435 const struct v4l2_requestbuffers *p = arg; 436 437 pr_cont("count=%d, type=%s, memory=%s\n", 438 p->count, 439 prt_names(p->type, v4l2_type_names), 440 prt_names(p->memory, v4l2_memory_names)); 441 } 442 443 static void v4l_print_buffer(const void *arg, bool write_only) 444 { 445 const struct v4l2_buffer *p = arg; 446 const struct v4l2_timecode *tc = &p->timecode; 447 const struct v4l2_plane *plane; 448 int i; 449 450 pr_cont("%02d:%02d:%02d.%06ld index=%d, type=%s, request_fd=%d, flags=0x%08x, field=%s, sequence=%d, memory=%s", 451 (int)p->timestamp.tv_sec / 3600, 452 ((int)p->timestamp.tv_sec / 60) % 60, 453 ((int)p->timestamp.tv_sec % 60), 454 (long)p->timestamp.tv_usec, 455 p->index, 456 prt_names(p->type, v4l2_type_names), p->request_fd, 457 p->flags, prt_names(p->field, v4l2_field_names), 458 p->sequence, prt_names(p->memory, v4l2_memory_names)); 459 460 if (V4L2_TYPE_IS_MULTIPLANAR(p->type) && p->m.planes) { 461 pr_cont("\n"); 462 for (i = 0; i < p->length; ++i) { 463 plane = &p->m.planes[i]; 464 printk(KERN_DEBUG 465 "plane %d: bytesused=%d, data_offset=0x%08x, offset/userptr=0x%lx, length=%d\n", 466 i, plane->bytesused, plane->data_offset, 467 plane->m.userptr, plane->length); 468 } 469 } else { 470 pr_cont(", bytesused=%d, offset/userptr=0x%lx, length=%d\n", 471 p->bytesused, p->m.userptr, p->length); 472 } 473 474 printk(KERN_DEBUG "timecode=%02d:%02d:%02d type=%d, flags=0x%08x, frames=%d, userbits=0x%08x\n", 475 tc->hours, tc->minutes, tc->seconds, 476 tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits); 477 } 478 479 static void v4l_print_exportbuffer(const void *arg, bool write_only) 480 { 481 const struct v4l2_exportbuffer *p = arg; 482 483 pr_cont("fd=%d, type=%s, index=%u, plane=%u, flags=0x%08x\n", 484 p->fd, prt_names(p->type, v4l2_type_names), 485 p->index, p->plane, p->flags); 486 } 487 488 static void v4l_print_create_buffers(const void *arg, bool write_only) 489 { 490 const struct v4l2_create_buffers *p = arg; 491 492 pr_cont("index=%d, count=%d, memory=%s, capabilities=0x%08x, ", 493 p->index, p->count, prt_names(p->memory, v4l2_memory_names), 494 p->capabilities); 495 v4l_print_format(&p->format, write_only); 496 } 497 498 static void v4l_print_streamparm(const void *arg, bool write_only) 499 { 500 const struct v4l2_streamparm *p = arg; 501 502 pr_cont("type=%s", prt_names(p->type, v4l2_type_names)); 503 504 if (p->type == V4L2_BUF_TYPE_VIDEO_CAPTURE || 505 p->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { 506 const struct v4l2_captureparm *c = &p->parm.capture; 507 508 pr_cont(", capability=0x%x, capturemode=0x%x, timeperframe=%d/%d, extendedmode=%d, readbuffers=%d\n", 509 c->capability, c->capturemode, 510 c->timeperframe.numerator, c->timeperframe.denominator, 511 c->extendedmode, c->readbuffers); 512 } else if (p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT || 513 p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { 514 const struct v4l2_outputparm *c = &p->parm.output; 515 516 pr_cont(", capability=0x%x, outputmode=0x%x, timeperframe=%d/%d, extendedmode=%d, writebuffers=%d\n", 517 c->capability, c->outputmode, 518 c->timeperframe.numerator, c->timeperframe.denominator, 519 c->extendedmode, c->writebuffers); 520 } else { 521 pr_cont("\n"); 522 } 523 } 524 525 static void v4l_print_queryctrl(const void *arg, bool write_only) 526 { 527 const struct v4l2_queryctrl *p = arg; 528 529 pr_cont("id=0x%x, type=%d, name=%.*s, min/max=%d/%d, step=%d, default=%d, flags=0x%08x\n", 530 p->id, p->type, (int)sizeof(p->name), p->name, 531 p->minimum, p->maximum, 532 p->step, p->default_value, p->flags); 533 } 534 535 static void v4l_print_query_ext_ctrl(const void *arg, bool write_only) 536 { 537 const struct v4l2_query_ext_ctrl *p = arg; 538 539 pr_cont("id=0x%x, type=%d, name=%.*s, min/max=%lld/%lld, step=%lld, default=%lld, flags=0x%08x, elem_size=%u, elems=%u, nr_of_dims=%u, dims=%u,%u,%u,%u\n", 540 p->id, p->type, (int)sizeof(p->name), p->name, 541 p->minimum, p->maximum, 542 p->step, p->default_value, p->flags, 543 p->elem_size, p->elems, p->nr_of_dims, 544 p->dims[0], p->dims[1], p->dims[2], p->dims[3]); 545 } 546 547 static void v4l_print_querymenu(const void *arg, bool write_only) 548 { 549 const struct v4l2_querymenu *p = arg; 550 551 pr_cont("id=0x%x, index=%d\n", p->id, p->index); 552 } 553 554 static void v4l_print_control(const void *arg, bool write_only) 555 { 556 const struct v4l2_control *p = arg; 557 const char *name = v4l2_ctrl_get_name(p->id); 558 559 if (name) 560 pr_cont("name=%s, ", name); 561 pr_cont("id=0x%x, value=%d\n", p->id, p->value); 562 } 563 564 static void v4l_print_ext_controls(const void *arg, bool write_only) 565 { 566 const struct v4l2_ext_controls *p = arg; 567 int i; 568 569 pr_cont("which=0x%x, count=%d, error_idx=%d, request_fd=%d", 570 p->which, p->count, p->error_idx, p->request_fd); 571 for (i = 0; i < p->count; i++) { 572 unsigned int id = p->controls[i].id; 573 const char *name = v4l2_ctrl_get_name(id); 574 575 if (name) 576 pr_cont(", name=%s", name); 577 if (!p->controls[i].size) 578 pr_cont(", id/val=0x%x/0x%x", id, p->controls[i].value); 579 else 580 pr_cont(", id/size=0x%x/%u", id, p->controls[i].size); 581 } 582 pr_cont("\n"); 583 } 584 585 static void v4l_print_cropcap(const void *arg, bool write_only) 586 { 587 const struct v4l2_cropcap *p = arg; 588 589 pr_cont("type=%s, bounds wxh=%dx%d, x,y=%d,%d, defrect wxh=%dx%d, x,y=%d,%d, pixelaspect %d/%d\n", 590 prt_names(p->type, v4l2_type_names), 591 p->bounds.width, p->bounds.height, 592 p->bounds.left, p->bounds.top, 593 p->defrect.width, p->defrect.height, 594 p->defrect.left, p->defrect.top, 595 p->pixelaspect.numerator, p->pixelaspect.denominator); 596 } 597 598 static void v4l_print_crop(const void *arg, bool write_only) 599 { 600 const struct v4l2_crop *p = arg; 601 602 pr_cont("type=%s, wxh=%dx%d, x,y=%d,%d\n", 603 prt_names(p->type, v4l2_type_names), 604 p->c.width, p->c.height, 605 p->c.left, p->c.top); 606 } 607 608 static void v4l_print_selection(const void *arg, bool write_only) 609 { 610 const struct v4l2_selection *p = arg; 611 612 pr_cont("type=%s, target=%d, flags=0x%x, wxh=%dx%d, x,y=%d,%d\n", 613 prt_names(p->type, v4l2_type_names), 614 p->target, p->flags, 615 p->r.width, p->r.height, p->r.left, p->r.top); 616 } 617 618 static void v4l_print_jpegcompression(const void *arg, bool write_only) 619 { 620 const struct v4l2_jpegcompression *p = arg; 621 622 pr_cont("quality=%d, APPn=%d, APP_len=%d, COM_len=%d, jpeg_markers=0x%x\n", 623 p->quality, p->APPn, p->APP_len, 624 p->COM_len, p->jpeg_markers); 625 } 626 627 static void v4l_print_enc_idx(const void *arg, bool write_only) 628 { 629 const struct v4l2_enc_idx *p = arg; 630 631 pr_cont("entries=%d, entries_cap=%d\n", 632 p->entries, p->entries_cap); 633 } 634 635 static void v4l_print_encoder_cmd(const void *arg, bool write_only) 636 { 637 const struct v4l2_encoder_cmd *p = arg; 638 639 pr_cont("cmd=%d, flags=0x%x\n", 640 p->cmd, p->flags); 641 } 642 643 static void v4l_print_decoder_cmd(const void *arg, bool write_only) 644 { 645 const struct v4l2_decoder_cmd *p = arg; 646 647 pr_cont("cmd=%d, flags=0x%x\n", p->cmd, p->flags); 648 649 if (p->cmd == V4L2_DEC_CMD_START) 650 pr_info("speed=%d, format=%u\n", 651 p->start.speed, p->start.format); 652 else if (p->cmd == V4L2_DEC_CMD_STOP) 653 pr_info("pts=%llu\n", p->stop.pts); 654 } 655 656 static void v4l_print_dbg_chip_info(const void *arg, bool write_only) 657 { 658 const struct v4l2_dbg_chip_info *p = arg; 659 660 pr_cont("type=%u, ", p->match.type); 661 if (p->match.type == V4L2_CHIP_MATCH_I2C_DRIVER) 662 pr_cont("name=%.*s, ", 663 (int)sizeof(p->match.name), p->match.name); 664 else 665 pr_cont("addr=%u, ", p->match.addr); 666 pr_cont("name=%.*s\n", (int)sizeof(p->name), p->name); 667 } 668 669 static void v4l_print_dbg_register(const void *arg, bool write_only) 670 { 671 const struct v4l2_dbg_register *p = arg; 672 673 pr_cont("type=%u, ", p->match.type); 674 if (p->match.type == V4L2_CHIP_MATCH_I2C_DRIVER) 675 pr_cont("name=%.*s, ", 676 (int)sizeof(p->match.name), p->match.name); 677 else 678 pr_cont("addr=%u, ", p->match.addr); 679 pr_cont("reg=0x%llx, val=0x%llx\n", 680 p->reg, p->val); 681 } 682 683 static void v4l_print_dv_timings(const void *arg, bool write_only) 684 { 685 const struct v4l2_dv_timings *p = arg; 686 687 switch (p->type) { 688 case V4L2_DV_BT_656_1120: 689 pr_cont("type=bt-656/1120, interlaced=%u, pixelclock=%llu, width=%u, height=%u, polarities=0x%x, hfrontporch=%u, hsync=%u, hbackporch=%u, vfrontporch=%u, vsync=%u, vbackporch=%u, il_vfrontporch=%u, il_vsync=%u, il_vbackporch=%u, standards=0x%x, flags=0x%x\n", 690 p->bt.interlaced, p->bt.pixelclock, 691 p->bt.width, p->bt.height, 692 p->bt.polarities, p->bt.hfrontporch, 693 p->bt.hsync, p->bt.hbackporch, 694 p->bt.vfrontporch, p->bt.vsync, 695 p->bt.vbackporch, p->bt.il_vfrontporch, 696 p->bt.il_vsync, p->bt.il_vbackporch, 697 p->bt.standards, p->bt.flags); 698 break; 699 default: 700 pr_cont("type=%d\n", p->type); 701 break; 702 } 703 } 704 705 static void v4l_print_enum_dv_timings(const void *arg, bool write_only) 706 { 707 const struct v4l2_enum_dv_timings *p = arg; 708 709 pr_cont("index=%u, ", p->index); 710 v4l_print_dv_timings(&p->timings, write_only); 711 } 712 713 static void v4l_print_dv_timings_cap(const void *arg, bool write_only) 714 { 715 const struct v4l2_dv_timings_cap *p = arg; 716 717 switch (p->type) { 718 case V4L2_DV_BT_656_1120: 719 pr_cont("type=bt-656/1120, width=%u-%u, height=%u-%u, pixelclock=%llu-%llu, standards=0x%x, capabilities=0x%x\n", 720 p->bt.min_width, p->bt.max_width, 721 p->bt.min_height, p->bt.max_height, 722 p->bt.min_pixelclock, p->bt.max_pixelclock, 723 p->bt.standards, p->bt.capabilities); 724 break; 725 default: 726 pr_cont("type=%u\n", p->type); 727 break; 728 } 729 } 730 731 static void v4l_print_frmsizeenum(const void *arg, bool write_only) 732 { 733 const struct v4l2_frmsizeenum *p = arg; 734 735 pr_cont("index=%u, pixelformat=%p4cc, type=%u", 736 p->index, &p->pixel_format, p->type); 737 switch (p->type) { 738 case V4L2_FRMSIZE_TYPE_DISCRETE: 739 pr_cont(", wxh=%ux%u\n", 740 p->discrete.width, p->discrete.height); 741 break; 742 case V4L2_FRMSIZE_TYPE_STEPWISE: 743 pr_cont(", min=%ux%u, max=%ux%u, step=%ux%u\n", 744 p->stepwise.min_width, 745 p->stepwise.min_height, 746 p->stepwise.max_width, 747 p->stepwise.max_height, 748 p->stepwise.step_width, 749 p->stepwise.step_height); 750 break; 751 case V4L2_FRMSIZE_TYPE_CONTINUOUS: 752 default: 753 pr_cont("\n"); 754 break; 755 } 756 } 757 758 static void v4l_print_frmivalenum(const void *arg, bool write_only) 759 { 760 const struct v4l2_frmivalenum *p = arg; 761 762 pr_cont("index=%u, pixelformat=%p4cc, wxh=%ux%u, type=%u", 763 p->index, &p->pixel_format, p->width, p->height, p->type); 764 switch (p->type) { 765 case V4L2_FRMIVAL_TYPE_DISCRETE: 766 pr_cont(", fps=%d/%d\n", 767 p->discrete.numerator, 768 p->discrete.denominator); 769 break; 770 case V4L2_FRMIVAL_TYPE_STEPWISE: 771 pr_cont(", min=%d/%d, max=%d/%d, step=%d/%d\n", 772 p->stepwise.min.numerator, 773 p->stepwise.min.denominator, 774 p->stepwise.max.numerator, 775 p->stepwise.max.denominator, 776 p->stepwise.step.numerator, 777 p->stepwise.step.denominator); 778 break; 779 case V4L2_FRMIVAL_TYPE_CONTINUOUS: 780 default: 781 pr_cont("\n"); 782 break; 783 } 784 } 785 786 static void v4l_print_event(const void *arg, bool write_only) 787 { 788 const struct v4l2_event *p = arg; 789 const struct v4l2_event_ctrl *c; 790 791 pr_cont("type=0x%x, pending=%u, sequence=%u, id=%u, timestamp=%llu.%9.9llu\n", 792 p->type, p->pending, p->sequence, p->id, 793 p->timestamp.tv_sec, p->timestamp.tv_nsec); 794 switch (p->type) { 795 case V4L2_EVENT_VSYNC: 796 printk(KERN_DEBUG "field=%s\n", 797 prt_names(p->u.vsync.field, v4l2_field_names)); 798 break; 799 case V4L2_EVENT_CTRL: 800 c = &p->u.ctrl; 801 printk(KERN_DEBUG "changes=0x%x, type=%u, ", 802 c->changes, c->type); 803 if (c->type == V4L2_CTRL_TYPE_INTEGER64) 804 pr_cont("value64=%lld, ", c->value64); 805 else 806 pr_cont("value=%d, ", c->value); 807 pr_cont("flags=0x%x, minimum=%d, maximum=%d, step=%d, default_value=%d\n", 808 c->flags, c->minimum, c->maximum, 809 c->step, c->default_value); 810 break; 811 case V4L2_EVENT_FRAME_SYNC: 812 pr_cont("frame_sequence=%u\n", 813 p->u.frame_sync.frame_sequence); 814 break; 815 } 816 } 817 818 static void v4l_print_event_subscription(const void *arg, bool write_only) 819 { 820 const struct v4l2_event_subscription *p = arg; 821 822 pr_cont("type=0x%x, id=0x%x, flags=0x%x\n", 823 p->type, p->id, p->flags); 824 } 825 826 static void v4l_print_sliced_vbi_cap(const void *arg, bool write_only) 827 { 828 const struct v4l2_sliced_vbi_cap *p = arg; 829 int i; 830 831 pr_cont("type=%s, service_set=0x%08x\n", 832 prt_names(p->type, v4l2_type_names), p->service_set); 833 for (i = 0; i < 24; i++) 834 printk(KERN_DEBUG "line[%02u]=0x%04x, 0x%04x\n", i, 835 p->service_lines[0][i], 836 p->service_lines[1][i]); 837 } 838 839 static void v4l_print_freq_band(const void *arg, bool write_only) 840 { 841 const struct v4l2_frequency_band *p = arg; 842 843 pr_cont("tuner=%u, type=%u, index=%u, capability=0x%x, rangelow=%u, rangehigh=%u, modulation=0x%x\n", 844 p->tuner, p->type, p->index, 845 p->capability, p->rangelow, 846 p->rangehigh, p->modulation); 847 } 848 849 static void v4l_print_edid(const void *arg, bool write_only) 850 { 851 const struct v4l2_edid *p = arg; 852 853 pr_cont("pad=%u, start_block=%u, blocks=%u\n", 854 p->pad, p->start_block, p->blocks); 855 } 856 857 static void v4l_print_u32(const void *arg, bool write_only) 858 { 859 pr_cont("value=%u\n", *(const u32 *)arg); 860 } 861 862 static void v4l_print_newline(const void *arg, bool write_only) 863 { 864 pr_cont("\n"); 865 } 866 867 static void v4l_print_default(const void *arg, bool write_only) 868 { 869 pr_cont("driver-specific ioctl\n"); 870 } 871 872 static int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv) 873 { 874 __u32 i; 875 876 /* zero the reserved fields */ 877 c->reserved[0] = 0; 878 for (i = 0; i < c->count; i++) 879 c->controls[i].reserved2[0] = 0; 880 881 /* V4L2_CID_PRIVATE_BASE cannot be used as control class 882 when using extended controls. 883 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL 884 is it allowed for backwards compatibility. 885 */ 886 if (!allow_priv && c->which == V4L2_CID_PRIVATE_BASE) 887 return 0; 888 if (!c->which) 889 return 1; 890 /* Check that all controls are from the same control class. */ 891 for (i = 0; i < c->count; i++) { 892 if (V4L2_CTRL_ID2WHICH(c->controls[i].id) != c->which) { 893 c->error_idx = i; 894 return 0; 895 } 896 } 897 return 1; 898 } 899 900 static int check_fmt(struct file *file, enum v4l2_buf_type type) 901 { 902 const u32 vid_caps = V4L2_CAP_VIDEO_CAPTURE | 903 V4L2_CAP_VIDEO_CAPTURE_MPLANE | 904 V4L2_CAP_VIDEO_OUTPUT | 905 V4L2_CAP_VIDEO_OUTPUT_MPLANE | 906 V4L2_CAP_VIDEO_M2M | V4L2_CAP_VIDEO_M2M_MPLANE; 907 const u32 meta_caps = V4L2_CAP_META_CAPTURE | 908 V4L2_CAP_META_OUTPUT; 909 struct video_device *vfd = video_devdata(file); 910 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops; 911 bool is_vid = vfd->vfl_type == VFL_TYPE_VIDEO && 912 (vfd->device_caps & vid_caps); 913 bool is_vbi = vfd->vfl_type == VFL_TYPE_VBI; 914 bool is_sdr = vfd->vfl_type == VFL_TYPE_SDR; 915 bool is_tch = vfd->vfl_type == VFL_TYPE_TOUCH; 916 bool is_meta = vfd->vfl_type == VFL_TYPE_VIDEO && 917 (vfd->device_caps & meta_caps); 918 bool is_rx = vfd->vfl_dir != VFL_DIR_TX; 919 bool is_tx = vfd->vfl_dir != VFL_DIR_RX; 920 921 if (ops == NULL) 922 return -EINVAL; 923 924 switch (type) { 925 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 926 if ((is_vid || is_tch) && is_rx && 927 (ops->vidioc_g_fmt_vid_cap || ops->vidioc_g_fmt_vid_cap_mplane)) 928 return 0; 929 break; 930 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: 931 if ((is_vid || is_tch) && is_rx && ops->vidioc_g_fmt_vid_cap_mplane) 932 return 0; 933 break; 934 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 935 if (is_vid && is_rx && ops->vidioc_g_fmt_vid_overlay) 936 return 0; 937 break; 938 case V4L2_BUF_TYPE_VIDEO_OUTPUT: 939 if (is_vid && is_tx && 940 (ops->vidioc_g_fmt_vid_out || ops->vidioc_g_fmt_vid_out_mplane)) 941 return 0; 942 break; 943 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: 944 if (is_vid && is_tx && ops->vidioc_g_fmt_vid_out_mplane) 945 return 0; 946 break; 947 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: 948 if (is_vid && is_tx && ops->vidioc_g_fmt_vid_out_overlay) 949 return 0; 950 break; 951 case V4L2_BUF_TYPE_VBI_CAPTURE: 952 if (is_vbi && is_rx && ops->vidioc_g_fmt_vbi_cap) 953 return 0; 954 break; 955 case V4L2_BUF_TYPE_VBI_OUTPUT: 956 if (is_vbi && is_tx && ops->vidioc_g_fmt_vbi_out) 957 return 0; 958 break; 959 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: 960 if (is_vbi && is_rx && ops->vidioc_g_fmt_sliced_vbi_cap) 961 return 0; 962 break; 963 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: 964 if (is_vbi && is_tx && ops->vidioc_g_fmt_sliced_vbi_out) 965 return 0; 966 break; 967 case V4L2_BUF_TYPE_SDR_CAPTURE: 968 if (is_sdr && is_rx && ops->vidioc_g_fmt_sdr_cap) 969 return 0; 970 break; 971 case V4L2_BUF_TYPE_SDR_OUTPUT: 972 if (is_sdr && is_tx && ops->vidioc_g_fmt_sdr_out) 973 return 0; 974 break; 975 case V4L2_BUF_TYPE_META_CAPTURE: 976 if (is_meta && is_rx && ops->vidioc_g_fmt_meta_cap) 977 return 0; 978 break; 979 case V4L2_BUF_TYPE_META_OUTPUT: 980 if (is_meta && is_tx && ops->vidioc_g_fmt_meta_out) 981 return 0; 982 break; 983 default: 984 break; 985 } 986 return -EINVAL; 987 } 988 989 static void v4l_sanitize_format(struct v4l2_format *fmt) 990 { 991 unsigned int offset; 992 993 /* Make sure num_planes is not bogus */ 994 if (fmt->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE || 995 fmt->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) 996 fmt->fmt.pix_mp.num_planes = min_t(u32, fmt->fmt.pix_mp.num_planes, 997 VIDEO_MAX_PLANES); 998 999 /* 1000 * The v4l2_pix_format structure has been extended with fields that were 1001 * not previously required to be set to zero by applications. The priv 1002 * field, when set to a magic value, indicates the the extended fields 1003 * are valid. Otherwise they will contain undefined values. To simplify 1004 * the API towards drivers zero the extended fields and set the priv 1005 * field to the magic value when the extended pixel format structure 1006 * isn't used by applications. 1007 */ 1008 1009 if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE && 1010 fmt->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) 1011 return; 1012 1013 if (fmt->fmt.pix.priv == V4L2_PIX_FMT_PRIV_MAGIC) 1014 return; 1015 1016 fmt->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC; 1017 1018 offset = offsetof(struct v4l2_pix_format, priv) 1019 + sizeof(fmt->fmt.pix.priv); 1020 memset(((void *)&fmt->fmt.pix) + offset, 0, 1021 sizeof(fmt->fmt.pix) - offset); 1022 } 1023 1024 static int v4l_querycap(const struct v4l2_ioctl_ops *ops, 1025 struct file *file, void *fh, void *arg) 1026 { 1027 struct v4l2_capability *cap = (struct v4l2_capability *)arg; 1028 struct video_device *vfd = video_devdata(file); 1029 int ret; 1030 1031 cap->version = LINUX_VERSION_CODE; 1032 cap->device_caps = vfd->device_caps; 1033 cap->capabilities = vfd->device_caps | V4L2_CAP_DEVICE_CAPS; 1034 1035 ret = ops->vidioc_querycap(file, fh, cap); 1036 1037 /* 1038 * Drivers must not change device_caps, so check for this and 1039 * warn if this happened. 1040 */ 1041 WARN_ON(cap->device_caps != vfd->device_caps); 1042 /* 1043 * Check that capabilities is a superset of 1044 * vfd->device_caps | V4L2_CAP_DEVICE_CAPS 1045 */ 1046 WARN_ON((cap->capabilities & 1047 (vfd->device_caps | V4L2_CAP_DEVICE_CAPS)) != 1048 (vfd->device_caps | V4L2_CAP_DEVICE_CAPS)); 1049 cap->capabilities |= V4L2_CAP_EXT_PIX_FORMAT; 1050 cap->device_caps |= V4L2_CAP_EXT_PIX_FORMAT; 1051 1052 return ret; 1053 } 1054 1055 static int v4l_g_input(const struct v4l2_ioctl_ops *ops, 1056 struct file *file, void *fh, void *arg) 1057 { 1058 struct video_device *vfd = video_devdata(file); 1059 1060 if (vfd->device_caps & V4L2_CAP_IO_MC) { 1061 *(int *)arg = 0; 1062 return 0; 1063 } 1064 1065 return ops->vidioc_g_input(file, fh, arg); 1066 } 1067 1068 static int v4l_g_output(const struct v4l2_ioctl_ops *ops, 1069 struct file *file, void *fh, void *arg) 1070 { 1071 struct video_device *vfd = video_devdata(file); 1072 1073 if (vfd->device_caps & V4L2_CAP_IO_MC) { 1074 *(int *)arg = 0; 1075 return 0; 1076 } 1077 1078 return ops->vidioc_g_output(file, fh, arg); 1079 } 1080 1081 static int v4l_s_input(const struct v4l2_ioctl_ops *ops, 1082 struct file *file, void *fh, void *arg) 1083 { 1084 struct video_device *vfd = video_devdata(file); 1085 int ret; 1086 1087 ret = v4l_enable_media_source(vfd); 1088 if (ret) 1089 return ret; 1090 1091 if (vfd->device_caps & V4L2_CAP_IO_MC) 1092 return *(int *)arg ? -EINVAL : 0; 1093 1094 return ops->vidioc_s_input(file, fh, *(unsigned int *)arg); 1095 } 1096 1097 static int v4l_s_output(const struct v4l2_ioctl_ops *ops, 1098 struct file *file, void *fh, void *arg) 1099 { 1100 struct video_device *vfd = video_devdata(file); 1101 1102 if (vfd->device_caps & V4L2_CAP_IO_MC) 1103 return *(int *)arg ? -EINVAL : 0; 1104 1105 return ops->vidioc_s_output(file, fh, *(unsigned int *)arg); 1106 } 1107 1108 static int v4l_g_priority(const struct v4l2_ioctl_ops *ops, 1109 struct file *file, void *fh, void *arg) 1110 { 1111 struct video_device *vfd; 1112 u32 *p = arg; 1113 1114 vfd = video_devdata(file); 1115 *p = v4l2_prio_max(vfd->prio); 1116 return 0; 1117 } 1118 1119 static int v4l_s_priority(const struct v4l2_ioctl_ops *ops, 1120 struct file *file, void *fh, void *arg) 1121 { 1122 struct video_device *vfd; 1123 struct v4l2_fh *vfh; 1124 u32 *p = arg; 1125 1126 vfd = video_devdata(file); 1127 if (!test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) 1128 return -ENOTTY; 1129 vfh = file->private_data; 1130 return v4l2_prio_change(vfd->prio, &vfh->prio, *p); 1131 } 1132 1133 static int v4l_enuminput(const struct v4l2_ioctl_ops *ops, 1134 struct file *file, void *fh, void *arg) 1135 { 1136 struct video_device *vfd = video_devdata(file); 1137 struct v4l2_input *p = arg; 1138 1139 /* 1140 * We set the flags for CAP_DV_TIMINGS & 1141 * CAP_STD here based on ioctl handler provided by the 1142 * driver. If the driver doesn't support these 1143 * for a specific input, it must override these flags. 1144 */ 1145 if (is_valid_ioctl(vfd, VIDIOC_S_STD)) 1146 p->capabilities |= V4L2_IN_CAP_STD; 1147 1148 if (vfd->device_caps & V4L2_CAP_IO_MC) { 1149 if (p->index) 1150 return -EINVAL; 1151 strscpy(p->name, vfd->name, sizeof(p->name)); 1152 p->type = V4L2_INPUT_TYPE_CAMERA; 1153 return 0; 1154 } 1155 1156 return ops->vidioc_enum_input(file, fh, p); 1157 } 1158 1159 static int v4l_enumoutput(const struct v4l2_ioctl_ops *ops, 1160 struct file *file, void *fh, void *arg) 1161 { 1162 struct video_device *vfd = video_devdata(file); 1163 struct v4l2_output *p = arg; 1164 1165 /* 1166 * We set the flags for CAP_DV_TIMINGS & 1167 * CAP_STD here based on ioctl handler provided by the 1168 * driver. If the driver doesn't support these 1169 * for a specific output, it must override these flags. 1170 */ 1171 if (is_valid_ioctl(vfd, VIDIOC_S_STD)) 1172 p->capabilities |= V4L2_OUT_CAP_STD; 1173 1174 if (vfd->device_caps & V4L2_CAP_IO_MC) { 1175 if (p->index) 1176 return -EINVAL; 1177 strscpy(p->name, vfd->name, sizeof(p->name)); 1178 p->type = V4L2_OUTPUT_TYPE_ANALOG; 1179 return 0; 1180 } 1181 1182 return ops->vidioc_enum_output(file, fh, p); 1183 } 1184 1185 static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt) 1186 { 1187 const unsigned sz = sizeof(fmt->description); 1188 const char *descr = NULL; 1189 u32 flags = 0; 1190 1191 /* 1192 * We depart from the normal coding style here since the descriptions 1193 * should be aligned so it is easy to see which descriptions will be 1194 * longer than 31 characters (the max length for a description). 1195 * And frankly, this is easier to read anyway. 1196 * 1197 * Note that gcc will use O(log N) comparisons to find the right case. 1198 */ 1199 switch (fmt->pixelformat) { 1200 /* Max description length mask: descr = "0123456789012345678901234567890" */ 1201 case V4L2_PIX_FMT_RGB332: descr = "8-bit RGB 3-3-2"; break; 1202 case V4L2_PIX_FMT_RGB444: descr = "16-bit A/XRGB 4-4-4-4"; break; 1203 case V4L2_PIX_FMT_ARGB444: descr = "16-bit ARGB 4-4-4-4"; break; 1204 case V4L2_PIX_FMT_XRGB444: descr = "16-bit XRGB 4-4-4-4"; break; 1205 case V4L2_PIX_FMT_RGBA444: descr = "16-bit RGBA 4-4-4-4"; break; 1206 case V4L2_PIX_FMT_RGBX444: descr = "16-bit RGBX 4-4-4-4"; break; 1207 case V4L2_PIX_FMT_ABGR444: descr = "16-bit ABGR 4-4-4-4"; break; 1208 case V4L2_PIX_FMT_XBGR444: descr = "16-bit XBGR 4-4-4-4"; break; 1209 case V4L2_PIX_FMT_BGRA444: descr = "16-bit BGRA 4-4-4-4"; break; 1210 case V4L2_PIX_FMT_BGRX444: descr = "16-bit BGRX 4-4-4-4"; break; 1211 case V4L2_PIX_FMT_RGB555: descr = "16-bit A/XRGB 1-5-5-5"; break; 1212 case V4L2_PIX_FMT_ARGB555: descr = "16-bit ARGB 1-5-5-5"; break; 1213 case V4L2_PIX_FMT_XRGB555: descr = "16-bit XRGB 1-5-5-5"; break; 1214 case V4L2_PIX_FMT_ABGR555: descr = "16-bit ABGR 1-5-5-5"; break; 1215 case V4L2_PIX_FMT_XBGR555: descr = "16-bit XBGR 1-5-5-5"; break; 1216 case V4L2_PIX_FMT_RGBA555: descr = "16-bit RGBA 5-5-5-1"; break; 1217 case V4L2_PIX_FMT_RGBX555: descr = "16-bit RGBX 5-5-5-1"; break; 1218 case V4L2_PIX_FMT_BGRA555: descr = "16-bit BGRA 5-5-5-1"; break; 1219 case V4L2_PIX_FMT_BGRX555: descr = "16-bit BGRX 5-5-5-1"; break; 1220 case V4L2_PIX_FMT_RGB565: descr = "16-bit RGB 5-6-5"; break; 1221 case V4L2_PIX_FMT_RGB555X: descr = "16-bit A/XRGB 1-5-5-5 BE"; break; 1222 case V4L2_PIX_FMT_ARGB555X: descr = "16-bit ARGB 1-5-5-5 BE"; break; 1223 case V4L2_PIX_FMT_XRGB555X: descr = "16-bit XRGB 1-5-5-5 BE"; break; 1224 case V4L2_PIX_FMT_RGB565X: descr = "16-bit RGB 5-6-5 BE"; break; 1225 case V4L2_PIX_FMT_BGR666: descr = "18-bit BGRX 6-6-6-14"; break; 1226 case V4L2_PIX_FMT_BGR24: descr = "24-bit BGR 8-8-8"; break; 1227 case V4L2_PIX_FMT_RGB24: descr = "24-bit RGB 8-8-8"; break; 1228 case V4L2_PIX_FMT_BGR32: descr = "32-bit BGRA/X 8-8-8-8"; break; 1229 case V4L2_PIX_FMT_ABGR32: descr = "32-bit BGRA 8-8-8-8"; break; 1230 case V4L2_PIX_FMT_XBGR32: descr = "32-bit BGRX 8-8-8-8"; break; 1231 case V4L2_PIX_FMT_RGB32: descr = "32-bit A/XRGB 8-8-8-8"; break; 1232 case V4L2_PIX_FMT_ARGB32: descr = "32-bit ARGB 8-8-8-8"; break; 1233 case V4L2_PIX_FMT_XRGB32: descr = "32-bit XRGB 8-8-8-8"; break; 1234 case V4L2_PIX_FMT_BGRA32: descr = "32-bit ABGR 8-8-8-8"; break; 1235 case V4L2_PIX_FMT_BGRX32: descr = "32-bit XBGR 8-8-8-8"; break; 1236 case V4L2_PIX_FMT_RGBA32: descr = "32-bit RGBA 8-8-8-8"; break; 1237 case V4L2_PIX_FMT_RGBX32: descr = "32-bit RGBX 8-8-8-8"; break; 1238 case V4L2_PIX_FMT_GREY: descr = "8-bit Greyscale"; break; 1239 case V4L2_PIX_FMT_Y4: descr = "4-bit Greyscale"; break; 1240 case V4L2_PIX_FMT_Y6: descr = "6-bit Greyscale"; break; 1241 case V4L2_PIX_FMT_Y10: descr = "10-bit Greyscale"; break; 1242 case V4L2_PIX_FMT_Y12: descr = "12-bit Greyscale"; break; 1243 case V4L2_PIX_FMT_Y14: descr = "14-bit Greyscale"; break; 1244 case V4L2_PIX_FMT_Y16: descr = "16-bit Greyscale"; break; 1245 case V4L2_PIX_FMT_Y16_BE: descr = "16-bit Greyscale BE"; break; 1246 case V4L2_PIX_FMT_Y10BPACK: descr = "10-bit Greyscale (Packed)"; break; 1247 case V4L2_PIX_FMT_Y10P: descr = "10-bit Greyscale (MIPI Packed)"; break; 1248 case V4L2_PIX_FMT_Y8I: descr = "Interleaved 8-bit Greyscale"; break; 1249 case V4L2_PIX_FMT_Y12I: descr = "Interleaved 12-bit Greyscale"; break; 1250 case V4L2_PIX_FMT_Z16: descr = "16-bit Depth"; break; 1251 case V4L2_PIX_FMT_INZI: descr = "Planar 10:16 Greyscale Depth"; break; 1252 case V4L2_PIX_FMT_CNF4: descr = "4-bit Depth Confidence (Packed)"; break; 1253 case V4L2_PIX_FMT_PAL8: descr = "8-bit Palette"; break; 1254 case V4L2_PIX_FMT_UV8: descr = "8-bit Chrominance UV 4-4"; break; 1255 case V4L2_PIX_FMT_YVU410: descr = "Planar YVU 4:1:0"; break; 1256 case V4L2_PIX_FMT_YVU420: descr = "Planar YVU 4:2:0"; break; 1257 case V4L2_PIX_FMT_YUYV: descr = "YUYV 4:2:2"; break; 1258 case V4L2_PIX_FMT_YYUV: descr = "YYUV 4:2:2"; break; 1259 case V4L2_PIX_FMT_YVYU: descr = "YVYU 4:2:2"; break; 1260 case V4L2_PIX_FMT_UYVY: descr = "UYVY 4:2:2"; break; 1261 case V4L2_PIX_FMT_VYUY: descr = "VYUY 4:2:2"; break; 1262 case V4L2_PIX_FMT_YUV422P: descr = "Planar YUV 4:2:2"; break; 1263 case V4L2_PIX_FMT_YUV411P: descr = "Planar YUV 4:1:1"; break; 1264 case V4L2_PIX_FMT_Y41P: descr = "YUV 4:1:1 (Packed)"; break; 1265 case V4L2_PIX_FMT_YUV444: descr = "16-bit A/XYUV 4-4-4-4"; break; 1266 case V4L2_PIX_FMT_YUV555: descr = "16-bit A/XYUV 1-5-5-5"; break; 1267 case V4L2_PIX_FMT_YUV565: descr = "16-bit YUV 5-6-5"; break; 1268 case V4L2_PIX_FMT_YUV24: descr = "24-bit YUV 4:4:4 8-8-8"; break; 1269 case V4L2_PIX_FMT_YUV32: descr = "32-bit A/XYUV 8-8-8-8"; break; 1270 case V4L2_PIX_FMT_AYUV32: descr = "32-bit AYUV 8-8-8-8"; break; 1271 case V4L2_PIX_FMT_XYUV32: descr = "32-bit XYUV 8-8-8-8"; break; 1272 case V4L2_PIX_FMT_VUYA32: descr = "32-bit VUYA 8-8-8-8"; break; 1273 case V4L2_PIX_FMT_VUYX32: descr = "32-bit VUYX 8-8-8-8"; break; 1274 case V4L2_PIX_FMT_YUV410: descr = "Planar YUV 4:1:0"; break; 1275 case V4L2_PIX_FMT_YUV420: descr = "Planar YUV 4:2:0"; break; 1276 case V4L2_PIX_FMT_HI240: descr = "8-bit Dithered RGB (BTTV)"; break; 1277 case V4L2_PIX_FMT_M420: descr = "YUV 4:2:0 (M420)"; break; 1278 case V4L2_PIX_FMT_NV12: descr = "Y/CbCr 4:2:0"; break; 1279 case V4L2_PIX_FMT_NV21: descr = "Y/CrCb 4:2:0"; break; 1280 case V4L2_PIX_FMT_NV16: descr = "Y/CbCr 4:2:2"; break; 1281 case V4L2_PIX_FMT_NV61: descr = "Y/CrCb 4:2:2"; break; 1282 case V4L2_PIX_FMT_NV24: descr = "Y/CbCr 4:4:4"; break; 1283 case V4L2_PIX_FMT_NV42: descr = "Y/CrCb 4:4:4"; break; 1284 case V4L2_PIX_FMT_NV12_4L4: descr = "Y/CbCr 4:2:0 (4x4 Linear)"; break; 1285 case V4L2_PIX_FMT_NV12_16L16: descr = "Y/CbCr 4:2:0 (16x16 Linear)"; break; 1286 case V4L2_PIX_FMT_NV12_32L32: descr = "Y/CbCr 4:2:0 (32x32 Linear)"; break; 1287 case V4L2_PIX_FMT_NV12M: descr = "Y/CbCr 4:2:0 (N-C)"; break; 1288 case V4L2_PIX_FMT_NV21M: descr = "Y/CrCb 4:2:0 (N-C)"; break; 1289 case V4L2_PIX_FMT_NV16M: descr = "Y/CbCr 4:2:2 (N-C)"; break; 1290 case V4L2_PIX_FMT_NV61M: descr = "Y/CrCb 4:2:2 (N-C)"; break; 1291 case V4L2_PIX_FMT_NV12MT: descr = "Y/CbCr 4:2:0 (64x32 MB, N-C)"; break; 1292 case V4L2_PIX_FMT_NV12MT_16X16: descr = "Y/CbCr 4:2:0 (16x16 MB, N-C)"; break; 1293 case V4L2_PIX_FMT_YUV420M: descr = "Planar YUV 4:2:0 (N-C)"; break; 1294 case V4L2_PIX_FMT_YVU420M: descr = "Planar YVU 4:2:0 (N-C)"; break; 1295 case V4L2_PIX_FMT_YUV422M: descr = "Planar YUV 4:2:2 (N-C)"; break; 1296 case V4L2_PIX_FMT_YVU422M: descr = "Planar YVU 4:2:2 (N-C)"; break; 1297 case V4L2_PIX_FMT_YUV444M: descr = "Planar YUV 4:4:4 (N-C)"; break; 1298 case V4L2_PIX_FMT_YVU444M: descr = "Planar YVU 4:4:4 (N-C)"; break; 1299 case V4L2_PIX_FMT_SBGGR8: descr = "8-bit Bayer BGBG/GRGR"; break; 1300 case V4L2_PIX_FMT_SGBRG8: descr = "8-bit Bayer GBGB/RGRG"; break; 1301 case V4L2_PIX_FMT_SGRBG8: descr = "8-bit Bayer GRGR/BGBG"; break; 1302 case V4L2_PIX_FMT_SRGGB8: descr = "8-bit Bayer RGRG/GBGB"; break; 1303 case V4L2_PIX_FMT_SBGGR10: descr = "10-bit Bayer BGBG/GRGR"; break; 1304 case V4L2_PIX_FMT_SGBRG10: descr = "10-bit Bayer GBGB/RGRG"; break; 1305 case V4L2_PIX_FMT_SGRBG10: descr = "10-bit Bayer GRGR/BGBG"; break; 1306 case V4L2_PIX_FMT_SRGGB10: descr = "10-bit Bayer RGRG/GBGB"; break; 1307 case V4L2_PIX_FMT_SBGGR10P: descr = "10-bit Bayer BGBG/GRGR Packed"; break; 1308 case V4L2_PIX_FMT_SGBRG10P: descr = "10-bit Bayer GBGB/RGRG Packed"; break; 1309 case V4L2_PIX_FMT_SGRBG10P: descr = "10-bit Bayer GRGR/BGBG Packed"; break; 1310 case V4L2_PIX_FMT_SRGGB10P: descr = "10-bit Bayer RGRG/GBGB Packed"; break; 1311 case V4L2_PIX_FMT_IPU3_SBGGR10: descr = "10-bit bayer BGGR IPU3 Packed"; break; 1312 case V4L2_PIX_FMT_IPU3_SGBRG10: descr = "10-bit bayer GBRG IPU3 Packed"; break; 1313 case V4L2_PIX_FMT_IPU3_SGRBG10: descr = "10-bit bayer GRBG IPU3 Packed"; break; 1314 case V4L2_PIX_FMT_IPU3_SRGGB10: descr = "10-bit bayer RGGB IPU3 Packed"; break; 1315 case V4L2_PIX_FMT_SBGGR10ALAW8: descr = "8-bit Bayer BGBG/GRGR (A-law)"; break; 1316 case V4L2_PIX_FMT_SGBRG10ALAW8: descr = "8-bit Bayer GBGB/RGRG (A-law)"; break; 1317 case V4L2_PIX_FMT_SGRBG10ALAW8: descr = "8-bit Bayer GRGR/BGBG (A-law)"; break; 1318 case V4L2_PIX_FMT_SRGGB10ALAW8: descr = "8-bit Bayer RGRG/GBGB (A-law)"; break; 1319 case V4L2_PIX_FMT_SBGGR10DPCM8: descr = "8-bit Bayer BGBG/GRGR (DPCM)"; break; 1320 case V4L2_PIX_FMT_SGBRG10DPCM8: descr = "8-bit Bayer GBGB/RGRG (DPCM)"; break; 1321 case V4L2_PIX_FMT_SGRBG10DPCM8: descr = "8-bit Bayer GRGR/BGBG (DPCM)"; break; 1322 case V4L2_PIX_FMT_SRGGB10DPCM8: descr = "8-bit Bayer RGRG/GBGB (DPCM)"; break; 1323 case V4L2_PIX_FMT_SBGGR12: descr = "12-bit Bayer BGBG/GRGR"; break; 1324 case V4L2_PIX_FMT_SGBRG12: descr = "12-bit Bayer GBGB/RGRG"; break; 1325 case V4L2_PIX_FMT_SGRBG12: descr = "12-bit Bayer GRGR/BGBG"; break; 1326 case V4L2_PIX_FMT_SRGGB12: descr = "12-bit Bayer RGRG/GBGB"; break; 1327 case V4L2_PIX_FMT_SBGGR12P: descr = "12-bit Bayer BGBG/GRGR Packed"; break; 1328 case V4L2_PIX_FMT_SGBRG12P: descr = "12-bit Bayer GBGB/RGRG Packed"; break; 1329 case V4L2_PIX_FMT_SGRBG12P: descr = "12-bit Bayer GRGR/BGBG Packed"; break; 1330 case V4L2_PIX_FMT_SRGGB12P: descr = "12-bit Bayer RGRG/GBGB Packed"; break; 1331 case V4L2_PIX_FMT_SBGGR14: descr = "14-bit Bayer BGBG/GRGR"; break; 1332 case V4L2_PIX_FMT_SGBRG14: descr = "14-bit Bayer GBGB/RGRG"; break; 1333 case V4L2_PIX_FMT_SGRBG14: descr = "14-bit Bayer GRGR/BGBG"; break; 1334 case V4L2_PIX_FMT_SRGGB14: descr = "14-bit Bayer RGRG/GBGB"; break; 1335 case V4L2_PIX_FMT_SBGGR14P: descr = "14-bit Bayer BGBG/GRGR Packed"; break; 1336 case V4L2_PIX_FMT_SGBRG14P: descr = "14-bit Bayer GBGB/RGRG Packed"; break; 1337 case V4L2_PIX_FMT_SGRBG14P: descr = "14-bit Bayer GRGR/BGBG Packed"; break; 1338 case V4L2_PIX_FMT_SRGGB14P: descr = "14-bit Bayer RGRG/GBGB Packed"; break; 1339 case V4L2_PIX_FMT_SBGGR16: descr = "16-bit Bayer BGBG/GRGR"; break; 1340 case V4L2_PIX_FMT_SGBRG16: descr = "16-bit Bayer GBGB/RGRG"; break; 1341 case V4L2_PIX_FMT_SGRBG16: descr = "16-bit Bayer GRGR/BGBG"; break; 1342 case V4L2_PIX_FMT_SRGGB16: descr = "16-bit Bayer RGRG/GBGB"; break; 1343 case V4L2_PIX_FMT_SN9C20X_I420: descr = "GSPCA SN9C20X I420"; break; 1344 case V4L2_PIX_FMT_SPCA501: descr = "GSPCA SPCA501"; break; 1345 case V4L2_PIX_FMT_SPCA505: descr = "GSPCA SPCA505"; break; 1346 case V4L2_PIX_FMT_SPCA508: descr = "GSPCA SPCA508"; break; 1347 case V4L2_PIX_FMT_STV0680: descr = "GSPCA STV0680"; break; 1348 case V4L2_PIX_FMT_TM6000: descr = "A/V + VBI Mux Packet"; break; 1349 case V4L2_PIX_FMT_CIT_YYVYUY: descr = "GSPCA CIT YYVYUY"; break; 1350 case V4L2_PIX_FMT_KONICA420: descr = "GSPCA KONICA420"; break; 1351 case V4L2_PIX_FMT_MM21: descr = "Mediatek 8-bit Block Format"; break; 1352 case V4L2_PIX_FMT_HSV24: descr = "24-bit HSV 8-8-8"; break; 1353 case V4L2_PIX_FMT_HSV32: descr = "32-bit XHSV 8-8-8-8"; break; 1354 case V4L2_SDR_FMT_CU8: descr = "Complex U8"; break; 1355 case V4L2_SDR_FMT_CU16LE: descr = "Complex U16LE"; break; 1356 case V4L2_SDR_FMT_CS8: descr = "Complex S8"; break; 1357 case V4L2_SDR_FMT_CS14LE: descr = "Complex S14LE"; break; 1358 case V4L2_SDR_FMT_RU12LE: descr = "Real U12LE"; break; 1359 case V4L2_SDR_FMT_PCU16BE: descr = "Planar Complex U16BE"; break; 1360 case V4L2_SDR_FMT_PCU18BE: descr = "Planar Complex U18BE"; break; 1361 case V4L2_SDR_FMT_PCU20BE: descr = "Planar Complex U20BE"; break; 1362 case V4L2_TCH_FMT_DELTA_TD16: descr = "16-bit Signed Deltas"; break; 1363 case V4L2_TCH_FMT_DELTA_TD08: descr = "8-bit Signed Deltas"; break; 1364 case V4L2_TCH_FMT_TU16: descr = "16-bit Unsigned Touch Data"; break; 1365 case V4L2_TCH_FMT_TU08: descr = "8-bit Unsigned Touch Data"; break; 1366 case V4L2_META_FMT_VSP1_HGO: descr = "R-Car VSP1 1-D Histogram"; break; 1367 case V4L2_META_FMT_VSP1_HGT: descr = "R-Car VSP1 2-D Histogram"; break; 1368 case V4L2_META_FMT_UVC: descr = "UVC Payload Header Metadata"; break; 1369 case V4L2_META_FMT_D4XX: descr = "Intel D4xx UVC Metadata"; break; 1370 case V4L2_META_FMT_VIVID: descr = "Vivid Metadata"; break; 1371 case V4L2_META_FMT_RK_ISP1_PARAMS: descr = "Rockchip ISP1 3A Parameters"; break; 1372 case V4L2_META_FMT_RK_ISP1_STAT_3A: descr = "Rockchip ISP1 3A Statistics"; break; 1373 1374 default: 1375 /* Compressed formats */ 1376 flags = V4L2_FMT_FLAG_COMPRESSED; 1377 switch (fmt->pixelformat) { 1378 /* Max description length mask: descr = "0123456789012345678901234567890" */ 1379 case V4L2_PIX_FMT_MJPEG: descr = "Motion-JPEG"; break; 1380 case V4L2_PIX_FMT_JPEG: descr = "JFIF JPEG"; break; 1381 case V4L2_PIX_FMT_DV: descr = "1394"; break; 1382 case V4L2_PIX_FMT_MPEG: descr = "MPEG-1/2/4"; break; 1383 case V4L2_PIX_FMT_H264: descr = "H.264"; break; 1384 case V4L2_PIX_FMT_H264_NO_SC: descr = "H.264 (No Start Codes)"; break; 1385 case V4L2_PIX_FMT_H264_MVC: descr = "H.264 MVC"; break; 1386 case V4L2_PIX_FMT_H264_SLICE: descr = "H.264 Parsed Slice Data"; break; 1387 case V4L2_PIX_FMT_H263: descr = "H.263"; break; 1388 case V4L2_PIX_FMT_MPEG1: descr = "MPEG-1 ES"; break; 1389 case V4L2_PIX_FMT_MPEG2: descr = "MPEG-2 ES"; break; 1390 case V4L2_PIX_FMT_MPEG2_SLICE: descr = "MPEG-2 Parsed Slice Data"; break; 1391 case V4L2_PIX_FMT_MPEG4: descr = "MPEG-4 Part 2 ES"; break; 1392 case V4L2_PIX_FMT_XVID: descr = "Xvid"; break; 1393 case V4L2_PIX_FMT_VC1_ANNEX_G: descr = "VC-1 (SMPTE 412M Annex G)"; break; 1394 case V4L2_PIX_FMT_VC1_ANNEX_L: descr = "VC-1 (SMPTE 412M Annex L)"; break; 1395 case V4L2_PIX_FMT_VP8: descr = "VP8"; break; 1396 case V4L2_PIX_FMT_VP8_FRAME: descr = "VP8 Frame"; break; 1397 case V4L2_PIX_FMT_VP9: descr = "VP9"; break; 1398 case V4L2_PIX_FMT_HEVC: descr = "HEVC"; break; /* aka H.265 */ 1399 case V4L2_PIX_FMT_HEVC_SLICE: descr = "HEVC Parsed Slice Data"; break; 1400 case V4L2_PIX_FMT_FWHT: descr = "FWHT"; break; /* used in vicodec */ 1401 case V4L2_PIX_FMT_FWHT_STATELESS: descr = "FWHT Stateless"; break; /* used in vicodec */ 1402 case V4L2_PIX_FMT_CPIA1: descr = "GSPCA CPiA YUV"; break; 1403 case V4L2_PIX_FMT_WNVA: descr = "WNVA"; break; 1404 case V4L2_PIX_FMT_SN9C10X: descr = "GSPCA SN9C10X"; break; 1405 case V4L2_PIX_FMT_PWC1: descr = "Raw Philips Webcam Type (Old)"; break; 1406 case V4L2_PIX_FMT_PWC2: descr = "Raw Philips Webcam Type (New)"; break; 1407 case V4L2_PIX_FMT_ET61X251: descr = "GSPCA ET61X251"; break; 1408 case V4L2_PIX_FMT_SPCA561: descr = "GSPCA SPCA561"; break; 1409 case V4L2_PIX_FMT_PAC207: descr = "GSPCA PAC207"; break; 1410 case V4L2_PIX_FMT_MR97310A: descr = "GSPCA MR97310A"; break; 1411 case V4L2_PIX_FMT_JL2005BCD: descr = "GSPCA JL2005BCD"; break; 1412 case V4L2_PIX_FMT_SN9C2028: descr = "GSPCA SN9C2028"; break; 1413 case V4L2_PIX_FMT_SQ905C: descr = "GSPCA SQ905C"; break; 1414 case V4L2_PIX_FMT_PJPG: descr = "GSPCA PJPG"; break; 1415 case V4L2_PIX_FMT_OV511: descr = "GSPCA OV511"; break; 1416 case V4L2_PIX_FMT_OV518: descr = "GSPCA OV518"; break; 1417 case V4L2_PIX_FMT_JPGL: descr = "JPEG Lite"; break; 1418 case V4L2_PIX_FMT_SE401: descr = "GSPCA SE401"; break; 1419 case V4L2_PIX_FMT_S5C_UYVY_JPG: descr = "S5C73MX interleaved UYVY/JPEG"; break; 1420 case V4L2_PIX_FMT_MT21C: descr = "Mediatek Compressed Format"; break; 1421 default: 1422 if (fmt->description[0]) 1423 return; 1424 WARN(1, "Unknown pixelformat 0x%08x\n", fmt->pixelformat); 1425 flags = 0; 1426 snprintf(fmt->description, sz, "%p4cc", 1427 &fmt->pixelformat); 1428 break; 1429 } 1430 } 1431 1432 if (descr) 1433 WARN_ON(strscpy(fmt->description, descr, sz) < 0); 1434 fmt->flags |= flags; 1435 } 1436 1437 static int v4l_enum_fmt(const struct v4l2_ioctl_ops *ops, 1438 struct file *file, void *fh, void *arg) 1439 { 1440 struct video_device *vdev = video_devdata(file); 1441 struct v4l2_fmtdesc *p = arg; 1442 int ret = check_fmt(file, p->type); 1443 u32 mbus_code; 1444 u32 cap_mask; 1445 1446 if (ret) 1447 return ret; 1448 ret = -EINVAL; 1449 1450 if (!(vdev->device_caps & V4L2_CAP_IO_MC)) 1451 p->mbus_code = 0; 1452 1453 mbus_code = p->mbus_code; 1454 CLEAR_AFTER_FIELD(p, type); 1455 p->mbus_code = mbus_code; 1456 1457 switch (p->type) { 1458 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 1459 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: 1460 cap_mask = V4L2_CAP_VIDEO_CAPTURE_MPLANE | 1461 V4L2_CAP_VIDEO_M2M_MPLANE; 1462 if (!!(vdev->device_caps & cap_mask) != 1463 (p->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)) 1464 break; 1465 1466 if (unlikely(!ops->vidioc_enum_fmt_vid_cap)) 1467 break; 1468 ret = ops->vidioc_enum_fmt_vid_cap(file, fh, arg); 1469 break; 1470 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 1471 if (unlikely(!ops->vidioc_enum_fmt_vid_overlay)) 1472 break; 1473 ret = ops->vidioc_enum_fmt_vid_overlay(file, fh, arg); 1474 break; 1475 case V4L2_BUF_TYPE_VIDEO_OUTPUT: 1476 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: 1477 cap_mask = V4L2_CAP_VIDEO_OUTPUT_MPLANE | 1478 V4L2_CAP_VIDEO_M2M_MPLANE; 1479 if (!!(vdev->device_caps & cap_mask) != 1480 (p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)) 1481 break; 1482 1483 if (unlikely(!ops->vidioc_enum_fmt_vid_out)) 1484 break; 1485 ret = ops->vidioc_enum_fmt_vid_out(file, fh, arg); 1486 break; 1487 case V4L2_BUF_TYPE_SDR_CAPTURE: 1488 if (unlikely(!ops->vidioc_enum_fmt_sdr_cap)) 1489 break; 1490 ret = ops->vidioc_enum_fmt_sdr_cap(file, fh, arg); 1491 break; 1492 case V4L2_BUF_TYPE_SDR_OUTPUT: 1493 if (unlikely(!ops->vidioc_enum_fmt_sdr_out)) 1494 break; 1495 ret = ops->vidioc_enum_fmt_sdr_out(file, fh, arg); 1496 break; 1497 case V4L2_BUF_TYPE_META_CAPTURE: 1498 if (unlikely(!ops->vidioc_enum_fmt_meta_cap)) 1499 break; 1500 ret = ops->vidioc_enum_fmt_meta_cap(file, fh, arg); 1501 break; 1502 case V4L2_BUF_TYPE_META_OUTPUT: 1503 if (unlikely(!ops->vidioc_enum_fmt_meta_out)) 1504 break; 1505 ret = ops->vidioc_enum_fmt_meta_out(file, fh, arg); 1506 break; 1507 } 1508 if (ret == 0) 1509 v4l_fill_fmtdesc(p); 1510 return ret; 1511 } 1512 1513 static void v4l_pix_format_touch(struct v4l2_pix_format *p) 1514 { 1515 /* 1516 * The v4l2_pix_format structure contains fields that make no sense for 1517 * touch. Set them to default values in this case. 1518 */ 1519 1520 p->field = V4L2_FIELD_NONE; 1521 p->colorspace = V4L2_COLORSPACE_RAW; 1522 p->flags = 0; 1523 p->ycbcr_enc = 0; 1524 p->quantization = 0; 1525 p->xfer_func = 0; 1526 } 1527 1528 static int v4l_g_fmt(const struct v4l2_ioctl_ops *ops, 1529 struct file *file, void *fh, void *arg) 1530 { 1531 struct v4l2_format *p = arg; 1532 struct video_device *vfd = video_devdata(file); 1533 int ret = check_fmt(file, p->type); 1534 1535 if (ret) 1536 return ret; 1537 1538 /* 1539 * fmt can't be cleared for these overlay types due to the 'clips' 1540 * 'clipcount' and 'bitmap' pointers in struct v4l2_window. 1541 * Those are provided by the user. So handle these two overlay types 1542 * first, and then just do a simple memset for the other types. 1543 */ 1544 switch (p->type) { 1545 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 1546 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: { 1547 struct v4l2_clip *clips = p->fmt.win.clips; 1548 u32 clipcount = p->fmt.win.clipcount; 1549 void __user *bitmap = p->fmt.win.bitmap; 1550 1551 memset(&p->fmt, 0, sizeof(p->fmt)); 1552 p->fmt.win.clips = clips; 1553 p->fmt.win.clipcount = clipcount; 1554 p->fmt.win.bitmap = bitmap; 1555 break; 1556 } 1557 default: 1558 memset(&p->fmt, 0, sizeof(p->fmt)); 1559 break; 1560 } 1561 1562 switch (p->type) { 1563 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 1564 if (unlikely(!ops->vidioc_g_fmt_vid_cap)) 1565 break; 1566 p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC; 1567 ret = ops->vidioc_g_fmt_vid_cap(file, fh, arg); 1568 /* just in case the driver zeroed it again */ 1569 p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC; 1570 if (vfd->vfl_type == VFL_TYPE_TOUCH) 1571 v4l_pix_format_touch(&p->fmt.pix); 1572 return ret; 1573 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: 1574 return ops->vidioc_g_fmt_vid_cap_mplane(file, fh, arg); 1575 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 1576 return ops->vidioc_g_fmt_vid_overlay(file, fh, arg); 1577 case V4L2_BUF_TYPE_VBI_CAPTURE: 1578 return ops->vidioc_g_fmt_vbi_cap(file, fh, arg); 1579 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: 1580 return ops->vidioc_g_fmt_sliced_vbi_cap(file, fh, arg); 1581 case V4L2_BUF_TYPE_VIDEO_OUTPUT: 1582 if (unlikely(!ops->vidioc_g_fmt_vid_out)) 1583 break; 1584 p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC; 1585 ret = ops->vidioc_g_fmt_vid_out(file, fh, arg); 1586 /* just in case the driver zeroed it again */ 1587 p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC; 1588 return ret; 1589 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: 1590 return ops->vidioc_g_fmt_vid_out_mplane(file, fh, arg); 1591 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: 1592 return ops->vidioc_g_fmt_vid_out_overlay(file, fh, arg); 1593 case V4L2_BUF_TYPE_VBI_OUTPUT: 1594 return ops->vidioc_g_fmt_vbi_out(file, fh, arg); 1595 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: 1596 return ops->vidioc_g_fmt_sliced_vbi_out(file, fh, arg); 1597 case V4L2_BUF_TYPE_SDR_CAPTURE: 1598 return ops->vidioc_g_fmt_sdr_cap(file, fh, arg); 1599 case V4L2_BUF_TYPE_SDR_OUTPUT: 1600 return ops->vidioc_g_fmt_sdr_out(file, fh, arg); 1601 case V4L2_BUF_TYPE_META_CAPTURE: 1602 return ops->vidioc_g_fmt_meta_cap(file, fh, arg); 1603 case V4L2_BUF_TYPE_META_OUTPUT: 1604 return ops->vidioc_g_fmt_meta_out(file, fh, arg); 1605 } 1606 return -EINVAL; 1607 } 1608 1609 static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops, 1610 struct file *file, void *fh, void *arg) 1611 { 1612 struct v4l2_format *p = arg; 1613 struct video_device *vfd = video_devdata(file); 1614 int ret = check_fmt(file, p->type); 1615 unsigned int i; 1616 1617 if (ret) 1618 return ret; 1619 1620 ret = v4l_enable_media_source(vfd); 1621 if (ret) 1622 return ret; 1623 v4l_sanitize_format(p); 1624 1625 switch (p->type) { 1626 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 1627 if (unlikely(!ops->vidioc_s_fmt_vid_cap)) 1628 break; 1629 CLEAR_AFTER_FIELD(p, fmt.pix); 1630 ret = ops->vidioc_s_fmt_vid_cap(file, fh, arg); 1631 /* just in case the driver zeroed it again */ 1632 p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC; 1633 if (vfd->vfl_type == VFL_TYPE_TOUCH) 1634 v4l_pix_format_touch(&p->fmt.pix); 1635 return ret; 1636 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: 1637 if (unlikely(!ops->vidioc_s_fmt_vid_cap_mplane)) 1638 break; 1639 CLEAR_AFTER_FIELD(p, fmt.pix_mp.xfer_func); 1640 for (i = 0; i < p->fmt.pix_mp.num_planes; i++) 1641 CLEAR_AFTER_FIELD(&p->fmt.pix_mp.plane_fmt[i], 1642 bytesperline); 1643 return ops->vidioc_s_fmt_vid_cap_mplane(file, fh, arg); 1644 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 1645 if (unlikely(!ops->vidioc_s_fmt_vid_overlay)) 1646 break; 1647 CLEAR_AFTER_FIELD(p, fmt.win); 1648 return ops->vidioc_s_fmt_vid_overlay(file, fh, arg); 1649 case V4L2_BUF_TYPE_VBI_CAPTURE: 1650 if (unlikely(!ops->vidioc_s_fmt_vbi_cap)) 1651 break; 1652 CLEAR_AFTER_FIELD(p, fmt.vbi.flags); 1653 return ops->vidioc_s_fmt_vbi_cap(file, fh, arg); 1654 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: 1655 if (unlikely(!ops->vidioc_s_fmt_sliced_vbi_cap)) 1656 break; 1657 CLEAR_AFTER_FIELD(p, fmt.sliced.io_size); 1658 return ops->vidioc_s_fmt_sliced_vbi_cap(file, fh, arg); 1659 case V4L2_BUF_TYPE_VIDEO_OUTPUT: 1660 if (unlikely(!ops->vidioc_s_fmt_vid_out)) 1661 break; 1662 CLEAR_AFTER_FIELD(p, fmt.pix); 1663 ret = ops->vidioc_s_fmt_vid_out(file, fh, arg); 1664 /* just in case the driver zeroed it again */ 1665 p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC; 1666 return ret; 1667 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: 1668 if (unlikely(!ops->vidioc_s_fmt_vid_out_mplane)) 1669 break; 1670 CLEAR_AFTER_FIELD(p, fmt.pix_mp.xfer_func); 1671 for (i = 0; i < p->fmt.pix_mp.num_planes; i++) 1672 CLEAR_AFTER_FIELD(&p->fmt.pix_mp.plane_fmt[i], 1673 bytesperline); 1674 return ops->vidioc_s_fmt_vid_out_mplane(file, fh, arg); 1675 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: 1676 if (unlikely(!ops->vidioc_s_fmt_vid_out_overlay)) 1677 break; 1678 CLEAR_AFTER_FIELD(p, fmt.win); 1679 return ops->vidioc_s_fmt_vid_out_overlay(file, fh, arg); 1680 case V4L2_BUF_TYPE_VBI_OUTPUT: 1681 if (unlikely(!ops->vidioc_s_fmt_vbi_out)) 1682 break; 1683 CLEAR_AFTER_FIELD(p, fmt.vbi.flags); 1684 return ops->vidioc_s_fmt_vbi_out(file, fh, arg); 1685 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: 1686 if (unlikely(!ops->vidioc_s_fmt_sliced_vbi_out)) 1687 break; 1688 CLEAR_AFTER_FIELD(p, fmt.sliced.io_size); 1689 return ops->vidioc_s_fmt_sliced_vbi_out(file, fh, arg); 1690 case V4L2_BUF_TYPE_SDR_CAPTURE: 1691 if (unlikely(!ops->vidioc_s_fmt_sdr_cap)) 1692 break; 1693 CLEAR_AFTER_FIELD(p, fmt.sdr.buffersize); 1694 return ops->vidioc_s_fmt_sdr_cap(file, fh, arg); 1695 case V4L2_BUF_TYPE_SDR_OUTPUT: 1696 if (unlikely(!ops->vidioc_s_fmt_sdr_out)) 1697 break; 1698 CLEAR_AFTER_FIELD(p, fmt.sdr.buffersize); 1699 return ops->vidioc_s_fmt_sdr_out(file, fh, arg); 1700 case V4L2_BUF_TYPE_META_CAPTURE: 1701 if (unlikely(!ops->vidioc_s_fmt_meta_cap)) 1702 break; 1703 CLEAR_AFTER_FIELD(p, fmt.meta); 1704 return ops->vidioc_s_fmt_meta_cap(file, fh, arg); 1705 case V4L2_BUF_TYPE_META_OUTPUT: 1706 if (unlikely(!ops->vidioc_s_fmt_meta_out)) 1707 break; 1708 CLEAR_AFTER_FIELD(p, fmt.meta); 1709 return ops->vidioc_s_fmt_meta_out(file, fh, arg); 1710 } 1711 return -EINVAL; 1712 } 1713 1714 static int v4l_try_fmt(const struct v4l2_ioctl_ops *ops, 1715 struct file *file, void *fh, void *arg) 1716 { 1717 struct v4l2_format *p = arg; 1718 struct video_device *vfd = video_devdata(file); 1719 int ret = check_fmt(file, p->type); 1720 unsigned int i; 1721 1722 if (ret) 1723 return ret; 1724 1725 v4l_sanitize_format(p); 1726 1727 switch (p->type) { 1728 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 1729 if (unlikely(!ops->vidioc_try_fmt_vid_cap)) 1730 break; 1731 CLEAR_AFTER_FIELD(p, fmt.pix); 1732 ret = ops->vidioc_try_fmt_vid_cap(file, fh, arg); 1733 /* just in case the driver zeroed it again */ 1734 p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC; 1735 if (vfd->vfl_type == VFL_TYPE_TOUCH) 1736 v4l_pix_format_touch(&p->fmt.pix); 1737 return ret; 1738 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: 1739 if (unlikely(!ops->vidioc_try_fmt_vid_cap_mplane)) 1740 break; 1741 CLEAR_AFTER_FIELD(p, fmt.pix_mp.xfer_func); 1742 for (i = 0; i < p->fmt.pix_mp.num_planes; i++) 1743 CLEAR_AFTER_FIELD(&p->fmt.pix_mp.plane_fmt[i], 1744 bytesperline); 1745 return ops->vidioc_try_fmt_vid_cap_mplane(file, fh, arg); 1746 case V4L2_BUF_TYPE_VIDEO_OVERLAY: 1747 if (unlikely(!ops->vidioc_try_fmt_vid_overlay)) 1748 break; 1749 CLEAR_AFTER_FIELD(p, fmt.win); 1750 return ops->vidioc_try_fmt_vid_overlay(file, fh, arg); 1751 case V4L2_BUF_TYPE_VBI_CAPTURE: 1752 if (unlikely(!ops->vidioc_try_fmt_vbi_cap)) 1753 break; 1754 CLEAR_AFTER_FIELD(p, fmt.vbi.flags); 1755 return ops->vidioc_try_fmt_vbi_cap(file, fh, arg); 1756 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: 1757 if (unlikely(!ops->vidioc_try_fmt_sliced_vbi_cap)) 1758 break; 1759 CLEAR_AFTER_FIELD(p, fmt.sliced.io_size); 1760 return ops->vidioc_try_fmt_sliced_vbi_cap(file, fh, arg); 1761 case V4L2_BUF_TYPE_VIDEO_OUTPUT: 1762 if (unlikely(!ops->vidioc_try_fmt_vid_out)) 1763 break; 1764 CLEAR_AFTER_FIELD(p, fmt.pix); 1765 ret = ops->vidioc_try_fmt_vid_out(file, fh, arg); 1766 /* just in case the driver zeroed it again */ 1767 p->fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC; 1768 return ret; 1769 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: 1770 if (unlikely(!ops->vidioc_try_fmt_vid_out_mplane)) 1771 break; 1772 CLEAR_AFTER_FIELD(p, fmt.pix_mp.xfer_func); 1773 for (i = 0; i < p->fmt.pix_mp.num_planes; i++) 1774 CLEAR_AFTER_FIELD(&p->fmt.pix_mp.plane_fmt[i], 1775 bytesperline); 1776 return ops->vidioc_try_fmt_vid_out_mplane(file, fh, arg); 1777 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: 1778 if (unlikely(!ops->vidioc_try_fmt_vid_out_overlay)) 1779 break; 1780 CLEAR_AFTER_FIELD(p, fmt.win); 1781 return ops->vidioc_try_fmt_vid_out_overlay(file, fh, arg); 1782 case V4L2_BUF_TYPE_VBI_OUTPUT: 1783 if (unlikely(!ops->vidioc_try_fmt_vbi_out)) 1784 break; 1785 CLEAR_AFTER_FIELD(p, fmt.vbi.flags); 1786 return ops->vidioc_try_fmt_vbi_out(file, fh, arg); 1787 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: 1788 if (unlikely(!ops->vidioc_try_fmt_sliced_vbi_out)) 1789 break; 1790 CLEAR_AFTER_FIELD(p, fmt.sliced.io_size); 1791 return ops->vidioc_try_fmt_sliced_vbi_out(file, fh, arg); 1792 case V4L2_BUF_TYPE_SDR_CAPTURE: 1793 if (unlikely(!ops->vidioc_try_fmt_sdr_cap)) 1794 break; 1795 CLEAR_AFTER_FIELD(p, fmt.sdr.buffersize); 1796 return ops->vidioc_try_fmt_sdr_cap(file, fh, arg); 1797 case V4L2_BUF_TYPE_SDR_OUTPUT: 1798 if (unlikely(!ops->vidioc_try_fmt_sdr_out)) 1799 break; 1800 CLEAR_AFTER_FIELD(p, fmt.sdr.buffersize); 1801 return ops->vidioc_try_fmt_sdr_out(file, fh, arg); 1802 case V4L2_BUF_TYPE_META_CAPTURE: 1803 if (unlikely(!ops->vidioc_try_fmt_meta_cap)) 1804 break; 1805 CLEAR_AFTER_FIELD(p, fmt.meta); 1806 return ops->vidioc_try_fmt_meta_cap(file, fh, arg); 1807 case V4L2_BUF_TYPE_META_OUTPUT: 1808 if (unlikely(!ops->vidioc_try_fmt_meta_out)) 1809 break; 1810 CLEAR_AFTER_FIELD(p, fmt.meta); 1811 return ops->vidioc_try_fmt_meta_out(file, fh, arg); 1812 } 1813 return -EINVAL; 1814 } 1815 1816 static int v4l_streamon(const struct v4l2_ioctl_ops *ops, 1817 struct file *file, void *fh, void *arg) 1818 { 1819 return ops->vidioc_streamon(file, fh, *(unsigned int *)arg); 1820 } 1821 1822 static int v4l_streamoff(const struct v4l2_ioctl_ops *ops, 1823 struct file *file, void *fh, void *arg) 1824 { 1825 return ops->vidioc_streamoff(file, fh, *(unsigned int *)arg); 1826 } 1827 1828 static int v4l_g_tuner(const struct v4l2_ioctl_ops *ops, 1829 struct file *file, void *fh, void *arg) 1830 { 1831 struct video_device *vfd = video_devdata(file); 1832 struct v4l2_tuner *p = arg; 1833 int err; 1834 1835 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ? 1836 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; 1837 err = ops->vidioc_g_tuner(file, fh, p); 1838 if (!err) 1839 p->capability |= V4L2_TUNER_CAP_FREQ_BANDS; 1840 return err; 1841 } 1842 1843 static int v4l_s_tuner(const struct v4l2_ioctl_ops *ops, 1844 struct file *file, void *fh, void *arg) 1845 { 1846 struct video_device *vfd = video_devdata(file); 1847 struct v4l2_tuner *p = arg; 1848 int ret; 1849 1850 ret = v4l_enable_media_source(vfd); 1851 if (ret) 1852 return ret; 1853 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ? 1854 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; 1855 return ops->vidioc_s_tuner(file, fh, p); 1856 } 1857 1858 static int v4l_g_modulator(const struct v4l2_ioctl_ops *ops, 1859 struct file *file, void *fh, void *arg) 1860 { 1861 struct video_device *vfd = video_devdata(file); 1862 struct v4l2_modulator *p = arg; 1863 int err; 1864 1865 if (vfd->vfl_type == VFL_TYPE_RADIO) 1866 p->type = V4L2_TUNER_RADIO; 1867 1868 err = ops->vidioc_g_modulator(file, fh, p); 1869 if (!err) 1870 p->capability |= V4L2_TUNER_CAP_FREQ_BANDS; 1871 return err; 1872 } 1873 1874 static int v4l_s_modulator(const struct v4l2_ioctl_ops *ops, 1875 struct file *file, void *fh, void *arg) 1876 { 1877 struct video_device *vfd = video_devdata(file); 1878 struct v4l2_modulator *p = arg; 1879 1880 if (vfd->vfl_type == VFL_TYPE_RADIO) 1881 p->type = V4L2_TUNER_RADIO; 1882 1883 return ops->vidioc_s_modulator(file, fh, p); 1884 } 1885 1886 static int v4l_g_frequency(const struct v4l2_ioctl_ops *ops, 1887 struct file *file, void *fh, void *arg) 1888 { 1889 struct video_device *vfd = video_devdata(file); 1890 struct v4l2_frequency *p = arg; 1891 1892 if (vfd->vfl_type == VFL_TYPE_SDR) 1893 p->type = V4L2_TUNER_SDR; 1894 else 1895 p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ? 1896 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; 1897 return ops->vidioc_g_frequency(file, fh, p); 1898 } 1899 1900 static int v4l_s_frequency(const struct v4l2_ioctl_ops *ops, 1901 struct file *file, void *fh, void *arg) 1902 { 1903 struct video_device *vfd = video_devdata(file); 1904 const struct v4l2_frequency *p = arg; 1905 enum v4l2_tuner_type type; 1906 int ret; 1907 1908 ret = v4l_enable_media_source(vfd); 1909 if (ret) 1910 return ret; 1911 if (vfd->vfl_type == VFL_TYPE_SDR) { 1912 if (p->type != V4L2_TUNER_SDR && p->type != V4L2_TUNER_RF) 1913 return -EINVAL; 1914 } else { 1915 type = (vfd->vfl_type == VFL_TYPE_RADIO) ? 1916 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; 1917 if (type != p->type) 1918 return -EINVAL; 1919 } 1920 return ops->vidioc_s_frequency(file, fh, p); 1921 } 1922 1923 static int v4l_enumstd(const struct v4l2_ioctl_ops *ops, 1924 struct file *file, void *fh, void *arg) 1925 { 1926 struct video_device *vfd = video_devdata(file); 1927 struct v4l2_standard *p = arg; 1928 1929 return v4l_video_std_enumstd(p, vfd->tvnorms); 1930 } 1931 1932 static int v4l_s_std(const struct v4l2_ioctl_ops *ops, 1933 struct file *file, void *fh, void *arg) 1934 { 1935 struct video_device *vfd = video_devdata(file); 1936 v4l2_std_id id = *(v4l2_std_id *)arg, norm; 1937 int ret; 1938 1939 ret = v4l_enable_media_source(vfd); 1940 if (ret) 1941 return ret; 1942 norm = id & vfd->tvnorms; 1943 if (vfd->tvnorms && !norm) /* Check if std is supported */ 1944 return -EINVAL; 1945 1946 /* Calls the specific handler */ 1947 return ops->vidioc_s_std(file, fh, norm); 1948 } 1949 1950 static int v4l_querystd(const struct v4l2_ioctl_ops *ops, 1951 struct file *file, void *fh, void *arg) 1952 { 1953 struct video_device *vfd = video_devdata(file); 1954 v4l2_std_id *p = arg; 1955 int ret; 1956 1957 ret = v4l_enable_media_source(vfd); 1958 if (ret) 1959 return ret; 1960 /* 1961 * If no signal is detected, then the driver should return 1962 * V4L2_STD_UNKNOWN. Otherwise it should return tvnorms with 1963 * any standards that do not apply removed. 1964 * 1965 * This means that tuners, audio and video decoders can join 1966 * their efforts to improve the standards detection. 1967 */ 1968 *p = vfd->tvnorms; 1969 return ops->vidioc_querystd(file, fh, arg); 1970 } 1971 1972 static int v4l_s_hw_freq_seek(const struct v4l2_ioctl_ops *ops, 1973 struct file *file, void *fh, void *arg) 1974 { 1975 struct video_device *vfd = video_devdata(file); 1976 struct v4l2_hw_freq_seek *p = arg; 1977 enum v4l2_tuner_type type; 1978 int ret; 1979 1980 ret = v4l_enable_media_source(vfd); 1981 if (ret) 1982 return ret; 1983 /* s_hw_freq_seek is not supported for SDR for now */ 1984 if (vfd->vfl_type == VFL_TYPE_SDR) 1985 return -EINVAL; 1986 1987 type = (vfd->vfl_type == VFL_TYPE_RADIO) ? 1988 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; 1989 if (p->type != type) 1990 return -EINVAL; 1991 return ops->vidioc_s_hw_freq_seek(file, fh, p); 1992 } 1993 1994 static int v4l_overlay(const struct v4l2_ioctl_ops *ops, 1995 struct file *file, void *fh, void *arg) 1996 { 1997 return ops->vidioc_overlay(file, fh, *(unsigned int *)arg); 1998 } 1999 2000 static int v4l_reqbufs(const struct v4l2_ioctl_ops *ops, 2001 struct file *file, void *fh, void *arg) 2002 { 2003 struct v4l2_requestbuffers *p = arg; 2004 int ret = check_fmt(file, p->type); 2005 2006 if (ret) 2007 return ret; 2008 2009 CLEAR_AFTER_FIELD(p, capabilities); 2010 2011 return ops->vidioc_reqbufs(file, fh, p); 2012 } 2013 2014 static int v4l_querybuf(const struct v4l2_ioctl_ops *ops, 2015 struct file *file, void *fh, void *arg) 2016 { 2017 struct v4l2_buffer *p = arg; 2018 int ret = check_fmt(file, p->type); 2019 2020 return ret ? ret : ops->vidioc_querybuf(file, fh, p); 2021 } 2022 2023 static int v4l_qbuf(const struct v4l2_ioctl_ops *ops, 2024 struct file *file, void *fh, void *arg) 2025 { 2026 struct v4l2_buffer *p = arg; 2027 int ret = check_fmt(file, p->type); 2028 2029 return ret ? ret : ops->vidioc_qbuf(file, fh, p); 2030 } 2031 2032 static int v4l_dqbuf(const struct v4l2_ioctl_ops *ops, 2033 struct file *file, void *fh, void *arg) 2034 { 2035 struct v4l2_buffer *p = arg; 2036 int ret = check_fmt(file, p->type); 2037 2038 return ret ? ret : ops->vidioc_dqbuf(file, fh, p); 2039 } 2040 2041 static int v4l_create_bufs(const struct v4l2_ioctl_ops *ops, 2042 struct file *file, void *fh, void *arg) 2043 { 2044 struct v4l2_create_buffers *create = arg; 2045 int ret = check_fmt(file, create->format.type); 2046 2047 if (ret) 2048 return ret; 2049 2050 CLEAR_AFTER_FIELD(create, capabilities); 2051 2052 v4l_sanitize_format(&create->format); 2053 2054 ret = ops->vidioc_create_bufs(file, fh, create); 2055 2056 if (create->format.type == V4L2_BUF_TYPE_VIDEO_CAPTURE || 2057 create->format.type == V4L2_BUF_TYPE_VIDEO_OUTPUT) 2058 create->format.fmt.pix.priv = V4L2_PIX_FMT_PRIV_MAGIC; 2059 2060 return ret; 2061 } 2062 2063 static int v4l_prepare_buf(const struct v4l2_ioctl_ops *ops, 2064 struct file *file, void *fh, void *arg) 2065 { 2066 struct v4l2_buffer *b = arg; 2067 int ret = check_fmt(file, b->type); 2068 2069 return ret ? ret : ops->vidioc_prepare_buf(file, fh, b); 2070 } 2071 2072 static int v4l_g_parm(const struct v4l2_ioctl_ops *ops, 2073 struct file *file, void *fh, void *arg) 2074 { 2075 struct v4l2_streamparm *p = arg; 2076 v4l2_std_id std; 2077 int ret = check_fmt(file, p->type); 2078 2079 if (ret) 2080 return ret; 2081 if (ops->vidioc_g_parm) 2082 return ops->vidioc_g_parm(file, fh, p); 2083 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE && 2084 p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) 2085 return -EINVAL; 2086 p->parm.capture.readbuffers = 2; 2087 ret = ops->vidioc_g_std(file, fh, &std); 2088 if (ret == 0) 2089 v4l2_video_std_frame_period(std, &p->parm.capture.timeperframe); 2090 return ret; 2091 } 2092 2093 static int v4l_s_parm(const struct v4l2_ioctl_ops *ops, 2094 struct file *file, void *fh, void *arg) 2095 { 2096 struct v4l2_streamparm *p = arg; 2097 int ret = check_fmt(file, p->type); 2098 2099 if (ret) 2100 return ret; 2101 2102 /* Note: extendedmode is never used in drivers */ 2103 if (V4L2_TYPE_IS_OUTPUT(p->type)) { 2104 memset(p->parm.output.reserved, 0, 2105 sizeof(p->parm.output.reserved)); 2106 p->parm.output.extendedmode = 0; 2107 p->parm.output.outputmode &= V4L2_MODE_HIGHQUALITY; 2108 } else { 2109 memset(p->parm.capture.reserved, 0, 2110 sizeof(p->parm.capture.reserved)); 2111 p->parm.capture.extendedmode = 0; 2112 p->parm.capture.capturemode &= V4L2_MODE_HIGHQUALITY; 2113 } 2114 return ops->vidioc_s_parm(file, fh, p); 2115 } 2116 2117 static int v4l_queryctrl(const struct v4l2_ioctl_ops *ops, 2118 struct file *file, void *fh, void *arg) 2119 { 2120 struct video_device *vfd = video_devdata(file); 2121 struct v4l2_queryctrl *p = arg; 2122 struct v4l2_fh *vfh = 2123 test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL; 2124 2125 if (vfh && vfh->ctrl_handler) 2126 return v4l2_queryctrl(vfh->ctrl_handler, p); 2127 if (vfd->ctrl_handler) 2128 return v4l2_queryctrl(vfd->ctrl_handler, p); 2129 if (ops->vidioc_queryctrl) 2130 return ops->vidioc_queryctrl(file, fh, p); 2131 return -ENOTTY; 2132 } 2133 2134 static int v4l_query_ext_ctrl(const struct v4l2_ioctl_ops *ops, 2135 struct file *file, void *fh, void *arg) 2136 { 2137 struct video_device *vfd = video_devdata(file); 2138 struct v4l2_query_ext_ctrl *p = arg; 2139 struct v4l2_fh *vfh = 2140 test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL; 2141 2142 if (vfh && vfh->ctrl_handler) 2143 return v4l2_query_ext_ctrl(vfh->ctrl_handler, p); 2144 if (vfd->ctrl_handler) 2145 return v4l2_query_ext_ctrl(vfd->ctrl_handler, p); 2146 if (ops->vidioc_query_ext_ctrl) 2147 return ops->vidioc_query_ext_ctrl(file, fh, p); 2148 return -ENOTTY; 2149 } 2150 2151 static int v4l_querymenu(const struct v4l2_ioctl_ops *ops, 2152 struct file *file, void *fh, void *arg) 2153 { 2154 struct video_device *vfd = video_devdata(file); 2155 struct v4l2_querymenu *p = arg; 2156 struct v4l2_fh *vfh = 2157 test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL; 2158 2159 if (vfh && vfh->ctrl_handler) 2160 return v4l2_querymenu(vfh->ctrl_handler, p); 2161 if (vfd->ctrl_handler) 2162 return v4l2_querymenu(vfd->ctrl_handler, p); 2163 if (ops->vidioc_querymenu) 2164 return ops->vidioc_querymenu(file, fh, p); 2165 return -ENOTTY; 2166 } 2167 2168 static int v4l_g_ctrl(const struct v4l2_ioctl_ops *ops, 2169 struct file *file, void *fh, void *arg) 2170 { 2171 struct video_device *vfd = video_devdata(file); 2172 struct v4l2_control *p = arg; 2173 struct v4l2_fh *vfh = 2174 test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL; 2175 struct v4l2_ext_controls ctrls; 2176 struct v4l2_ext_control ctrl; 2177 2178 if (vfh && vfh->ctrl_handler) 2179 return v4l2_g_ctrl(vfh->ctrl_handler, p); 2180 if (vfd->ctrl_handler) 2181 return v4l2_g_ctrl(vfd->ctrl_handler, p); 2182 if (ops->vidioc_g_ctrl) 2183 return ops->vidioc_g_ctrl(file, fh, p); 2184 if (ops->vidioc_g_ext_ctrls == NULL) 2185 return -ENOTTY; 2186 2187 ctrls.which = V4L2_CTRL_ID2WHICH(p->id); 2188 ctrls.count = 1; 2189 ctrls.controls = &ctrl; 2190 ctrl.id = p->id; 2191 ctrl.value = p->value; 2192 if (check_ext_ctrls(&ctrls, 1)) { 2193 int ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls); 2194 2195 if (ret == 0) 2196 p->value = ctrl.value; 2197 return ret; 2198 } 2199 return -EINVAL; 2200 } 2201 2202 static int v4l_s_ctrl(const struct v4l2_ioctl_ops *ops, 2203 struct file *file, void *fh, void *arg) 2204 { 2205 struct video_device *vfd = video_devdata(file); 2206 struct v4l2_control *p = arg; 2207 struct v4l2_fh *vfh = 2208 test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL; 2209 struct v4l2_ext_controls ctrls; 2210 struct v4l2_ext_control ctrl; 2211 2212 if (vfh && vfh->ctrl_handler) 2213 return v4l2_s_ctrl(vfh, vfh->ctrl_handler, p); 2214 if (vfd->ctrl_handler) 2215 return v4l2_s_ctrl(NULL, vfd->ctrl_handler, p); 2216 if (ops->vidioc_s_ctrl) 2217 return ops->vidioc_s_ctrl(file, fh, p); 2218 if (ops->vidioc_s_ext_ctrls == NULL) 2219 return -ENOTTY; 2220 2221 ctrls.which = V4L2_CTRL_ID2WHICH(p->id); 2222 ctrls.count = 1; 2223 ctrls.controls = &ctrl; 2224 ctrl.id = p->id; 2225 ctrl.value = p->value; 2226 if (check_ext_ctrls(&ctrls, 1)) 2227 return ops->vidioc_s_ext_ctrls(file, fh, &ctrls); 2228 return -EINVAL; 2229 } 2230 2231 static int v4l_g_ext_ctrls(const struct v4l2_ioctl_ops *ops, 2232 struct file *file, void *fh, void *arg) 2233 { 2234 struct video_device *vfd = video_devdata(file); 2235 struct v4l2_ext_controls *p = arg; 2236 struct v4l2_fh *vfh = 2237 test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL; 2238 2239 p->error_idx = p->count; 2240 if (vfh && vfh->ctrl_handler) 2241 return v4l2_g_ext_ctrls(vfh->ctrl_handler, 2242 vfd, vfd->v4l2_dev->mdev, p); 2243 if (vfd->ctrl_handler) 2244 return v4l2_g_ext_ctrls(vfd->ctrl_handler, 2245 vfd, vfd->v4l2_dev->mdev, p); 2246 if (ops->vidioc_g_ext_ctrls == NULL) 2247 return -ENOTTY; 2248 return check_ext_ctrls(p, 0) ? ops->vidioc_g_ext_ctrls(file, fh, p) : 2249 -EINVAL; 2250 } 2251 2252 static int v4l_s_ext_ctrls(const struct v4l2_ioctl_ops *ops, 2253 struct file *file, void *fh, void *arg) 2254 { 2255 struct video_device *vfd = video_devdata(file); 2256 struct v4l2_ext_controls *p = arg; 2257 struct v4l2_fh *vfh = 2258 test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL; 2259 2260 p->error_idx = p->count; 2261 if (vfh && vfh->ctrl_handler) 2262 return v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, 2263 vfd, vfd->v4l2_dev->mdev, p); 2264 if (vfd->ctrl_handler) 2265 return v4l2_s_ext_ctrls(NULL, vfd->ctrl_handler, 2266 vfd, vfd->v4l2_dev->mdev, p); 2267 if (ops->vidioc_s_ext_ctrls == NULL) 2268 return -ENOTTY; 2269 return check_ext_ctrls(p, 0) ? ops->vidioc_s_ext_ctrls(file, fh, p) : 2270 -EINVAL; 2271 } 2272 2273 static int v4l_try_ext_ctrls(const struct v4l2_ioctl_ops *ops, 2274 struct file *file, void *fh, void *arg) 2275 { 2276 struct video_device *vfd = video_devdata(file); 2277 struct v4l2_ext_controls *p = arg; 2278 struct v4l2_fh *vfh = 2279 test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL; 2280 2281 p->error_idx = p->count; 2282 if (vfh && vfh->ctrl_handler) 2283 return v4l2_try_ext_ctrls(vfh->ctrl_handler, 2284 vfd, vfd->v4l2_dev->mdev, p); 2285 if (vfd->ctrl_handler) 2286 return v4l2_try_ext_ctrls(vfd->ctrl_handler, 2287 vfd, vfd->v4l2_dev->mdev, p); 2288 if (ops->vidioc_try_ext_ctrls == NULL) 2289 return -ENOTTY; 2290 return check_ext_ctrls(p, 0) ? ops->vidioc_try_ext_ctrls(file, fh, p) : 2291 -EINVAL; 2292 } 2293 2294 /* 2295 * The selection API specified originally that the _MPLANE buffer types 2296 * shouldn't be used. The reasons for this are lost in the mists of time 2297 * (or just really crappy memories). Regardless, this is really annoying 2298 * for userspace. So to keep things simple we map _MPLANE buffer types 2299 * to their 'regular' counterparts before calling the driver. And we 2300 * restore it afterwards. This way applications can use either buffer 2301 * type and drivers don't need to check for both. 2302 */ 2303 static int v4l_g_selection(const struct v4l2_ioctl_ops *ops, 2304 struct file *file, void *fh, void *arg) 2305 { 2306 struct v4l2_selection *p = arg; 2307 u32 old_type = p->type; 2308 int ret; 2309 2310 if (p->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) 2311 p->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 2312 else if (p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) 2313 p->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; 2314 ret = ops->vidioc_g_selection(file, fh, p); 2315 p->type = old_type; 2316 return ret; 2317 } 2318 2319 static int v4l_s_selection(const struct v4l2_ioctl_ops *ops, 2320 struct file *file, void *fh, void *arg) 2321 { 2322 struct v4l2_selection *p = arg; 2323 u32 old_type = p->type; 2324 int ret; 2325 2326 if (p->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) 2327 p->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 2328 else if (p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) 2329 p->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; 2330 ret = ops->vidioc_s_selection(file, fh, p); 2331 p->type = old_type; 2332 return ret; 2333 } 2334 2335 static int v4l_g_crop(const struct v4l2_ioctl_ops *ops, 2336 struct file *file, void *fh, void *arg) 2337 { 2338 struct video_device *vfd = video_devdata(file); 2339 struct v4l2_crop *p = arg; 2340 struct v4l2_selection s = { 2341 .type = p->type, 2342 }; 2343 int ret; 2344 2345 /* simulate capture crop using selection api */ 2346 2347 /* crop means compose for output devices */ 2348 if (V4L2_TYPE_IS_OUTPUT(p->type)) 2349 s.target = V4L2_SEL_TGT_COMPOSE; 2350 else 2351 s.target = V4L2_SEL_TGT_CROP; 2352 2353 if (test_bit(V4L2_FL_QUIRK_INVERTED_CROP, &vfd->flags)) 2354 s.target = s.target == V4L2_SEL_TGT_COMPOSE ? 2355 V4L2_SEL_TGT_CROP : V4L2_SEL_TGT_COMPOSE; 2356 2357 ret = v4l_g_selection(ops, file, fh, &s); 2358 2359 /* copying results to old structure on success */ 2360 if (!ret) 2361 p->c = s.r; 2362 return ret; 2363 } 2364 2365 static int v4l_s_crop(const struct v4l2_ioctl_ops *ops, 2366 struct file *file, void *fh, void *arg) 2367 { 2368 struct video_device *vfd = video_devdata(file); 2369 struct v4l2_crop *p = arg; 2370 struct v4l2_selection s = { 2371 .type = p->type, 2372 .r = p->c, 2373 }; 2374 2375 /* simulate capture crop using selection api */ 2376 2377 /* crop means compose for output devices */ 2378 if (V4L2_TYPE_IS_OUTPUT(p->type)) 2379 s.target = V4L2_SEL_TGT_COMPOSE; 2380 else 2381 s.target = V4L2_SEL_TGT_CROP; 2382 2383 if (test_bit(V4L2_FL_QUIRK_INVERTED_CROP, &vfd->flags)) 2384 s.target = s.target == V4L2_SEL_TGT_COMPOSE ? 2385 V4L2_SEL_TGT_CROP : V4L2_SEL_TGT_COMPOSE; 2386 2387 return v4l_s_selection(ops, file, fh, &s); 2388 } 2389 2390 static int v4l_cropcap(const struct v4l2_ioctl_ops *ops, 2391 struct file *file, void *fh, void *arg) 2392 { 2393 struct video_device *vfd = video_devdata(file); 2394 struct v4l2_cropcap *p = arg; 2395 struct v4l2_selection s = { .type = p->type }; 2396 int ret = 0; 2397 2398 /* setting trivial pixelaspect */ 2399 p->pixelaspect.numerator = 1; 2400 p->pixelaspect.denominator = 1; 2401 2402 if (s.type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) 2403 s.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 2404 else if (s.type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) 2405 s.type = V4L2_BUF_TYPE_VIDEO_OUTPUT; 2406 2407 /* 2408 * The determine_valid_ioctls() call already should ensure 2409 * that this can never happen, but just in case... 2410 */ 2411 if (WARN_ON(!ops->vidioc_g_selection)) 2412 return -ENOTTY; 2413 2414 if (ops->vidioc_g_pixelaspect) 2415 ret = ops->vidioc_g_pixelaspect(file, fh, s.type, 2416 &p->pixelaspect); 2417 2418 /* 2419 * Ignore ENOTTY or ENOIOCTLCMD error returns, just use the 2420 * square pixel aspect ratio in that case. 2421 */ 2422 if (ret && ret != -ENOTTY && ret != -ENOIOCTLCMD) 2423 return ret; 2424 2425 /* Use g_selection() to fill in the bounds and defrect rectangles */ 2426 2427 /* obtaining bounds */ 2428 if (V4L2_TYPE_IS_OUTPUT(p->type)) 2429 s.target = V4L2_SEL_TGT_COMPOSE_BOUNDS; 2430 else 2431 s.target = V4L2_SEL_TGT_CROP_BOUNDS; 2432 2433 if (test_bit(V4L2_FL_QUIRK_INVERTED_CROP, &vfd->flags)) 2434 s.target = s.target == V4L2_SEL_TGT_COMPOSE_BOUNDS ? 2435 V4L2_SEL_TGT_CROP_BOUNDS : V4L2_SEL_TGT_COMPOSE_BOUNDS; 2436 2437 ret = v4l_g_selection(ops, file, fh, &s); 2438 if (ret) 2439 return ret; 2440 p->bounds = s.r; 2441 2442 /* obtaining defrect */ 2443 if (s.target == V4L2_SEL_TGT_COMPOSE_BOUNDS) 2444 s.target = V4L2_SEL_TGT_COMPOSE_DEFAULT; 2445 else 2446 s.target = V4L2_SEL_TGT_CROP_DEFAULT; 2447 2448 ret = v4l_g_selection(ops, file, fh, &s); 2449 if (ret) 2450 return ret; 2451 p->defrect = s.r; 2452 2453 return 0; 2454 } 2455 2456 static int v4l_log_status(const struct v4l2_ioctl_ops *ops, 2457 struct file *file, void *fh, void *arg) 2458 { 2459 struct video_device *vfd = video_devdata(file); 2460 int ret; 2461 2462 if (vfd->v4l2_dev) 2463 pr_info("%s: ================= START STATUS =================\n", 2464 vfd->v4l2_dev->name); 2465 ret = ops->vidioc_log_status(file, fh); 2466 if (vfd->v4l2_dev) 2467 pr_info("%s: ================== END STATUS ==================\n", 2468 vfd->v4l2_dev->name); 2469 return ret; 2470 } 2471 2472 static int v4l_dbg_g_register(const struct v4l2_ioctl_ops *ops, 2473 struct file *file, void *fh, void *arg) 2474 { 2475 #ifdef CONFIG_VIDEO_ADV_DEBUG 2476 struct v4l2_dbg_register *p = arg; 2477 struct video_device *vfd = video_devdata(file); 2478 struct v4l2_subdev *sd; 2479 int idx = 0; 2480 2481 if (!capable(CAP_SYS_ADMIN)) 2482 return -EPERM; 2483 if (p->match.type == V4L2_CHIP_MATCH_SUBDEV) { 2484 if (vfd->v4l2_dev == NULL) 2485 return -EINVAL; 2486 v4l2_device_for_each_subdev(sd, vfd->v4l2_dev) 2487 if (p->match.addr == idx++) 2488 return v4l2_subdev_call(sd, core, g_register, p); 2489 return -EINVAL; 2490 } 2491 if (ops->vidioc_g_register && p->match.type == V4L2_CHIP_MATCH_BRIDGE && 2492 (ops->vidioc_g_chip_info || p->match.addr == 0)) 2493 return ops->vidioc_g_register(file, fh, p); 2494 return -EINVAL; 2495 #else 2496 return -ENOTTY; 2497 #endif 2498 } 2499 2500 static int v4l_dbg_s_register(const struct v4l2_ioctl_ops *ops, 2501 struct file *file, void *fh, void *arg) 2502 { 2503 #ifdef CONFIG_VIDEO_ADV_DEBUG 2504 const struct v4l2_dbg_register *p = arg; 2505 struct video_device *vfd = video_devdata(file); 2506 struct v4l2_subdev *sd; 2507 int idx = 0; 2508 2509 if (!capable(CAP_SYS_ADMIN)) 2510 return -EPERM; 2511 if (p->match.type == V4L2_CHIP_MATCH_SUBDEV) { 2512 if (vfd->v4l2_dev == NULL) 2513 return -EINVAL; 2514 v4l2_device_for_each_subdev(sd, vfd->v4l2_dev) 2515 if (p->match.addr == idx++) 2516 return v4l2_subdev_call(sd, core, s_register, p); 2517 return -EINVAL; 2518 } 2519 if (ops->vidioc_s_register && p->match.type == V4L2_CHIP_MATCH_BRIDGE && 2520 (ops->vidioc_g_chip_info || p->match.addr == 0)) 2521 return ops->vidioc_s_register(file, fh, p); 2522 return -EINVAL; 2523 #else 2524 return -ENOTTY; 2525 #endif 2526 } 2527 2528 static int v4l_dbg_g_chip_info(const struct v4l2_ioctl_ops *ops, 2529 struct file *file, void *fh, void *arg) 2530 { 2531 #ifdef CONFIG_VIDEO_ADV_DEBUG 2532 struct video_device *vfd = video_devdata(file); 2533 struct v4l2_dbg_chip_info *p = arg; 2534 struct v4l2_subdev *sd; 2535 int idx = 0; 2536 2537 switch (p->match.type) { 2538 case V4L2_CHIP_MATCH_BRIDGE: 2539 if (ops->vidioc_s_register) 2540 p->flags |= V4L2_CHIP_FL_WRITABLE; 2541 if (ops->vidioc_g_register) 2542 p->flags |= V4L2_CHIP_FL_READABLE; 2543 strscpy(p->name, vfd->v4l2_dev->name, sizeof(p->name)); 2544 if (ops->vidioc_g_chip_info) 2545 return ops->vidioc_g_chip_info(file, fh, arg); 2546 if (p->match.addr) 2547 return -EINVAL; 2548 return 0; 2549 2550 case V4L2_CHIP_MATCH_SUBDEV: 2551 if (vfd->v4l2_dev == NULL) 2552 break; 2553 v4l2_device_for_each_subdev(sd, vfd->v4l2_dev) { 2554 if (p->match.addr != idx++) 2555 continue; 2556 if (sd->ops->core && sd->ops->core->s_register) 2557 p->flags |= V4L2_CHIP_FL_WRITABLE; 2558 if (sd->ops->core && sd->ops->core->g_register) 2559 p->flags |= V4L2_CHIP_FL_READABLE; 2560 strscpy(p->name, sd->name, sizeof(p->name)); 2561 return 0; 2562 } 2563 break; 2564 } 2565 return -EINVAL; 2566 #else 2567 return -ENOTTY; 2568 #endif 2569 } 2570 2571 static int v4l_dqevent(const struct v4l2_ioctl_ops *ops, 2572 struct file *file, void *fh, void *arg) 2573 { 2574 return v4l2_event_dequeue(fh, arg, file->f_flags & O_NONBLOCK); 2575 } 2576 2577 static int v4l_subscribe_event(const struct v4l2_ioctl_ops *ops, 2578 struct file *file, void *fh, void *arg) 2579 { 2580 return ops->vidioc_subscribe_event(fh, arg); 2581 } 2582 2583 static int v4l_unsubscribe_event(const struct v4l2_ioctl_ops *ops, 2584 struct file *file, void *fh, void *arg) 2585 { 2586 return ops->vidioc_unsubscribe_event(fh, arg); 2587 } 2588 2589 static int v4l_g_sliced_vbi_cap(const struct v4l2_ioctl_ops *ops, 2590 struct file *file, void *fh, void *arg) 2591 { 2592 struct v4l2_sliced_vbi_cap *p = arg; 2593 int ret = check_fmt(file, p->type); 2594 2595 if (ret) 2596 return ret; 2597 2598 /* Clear up to type, everything after type is zeroed already */ 2599 memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type)); 2600 2601 return ops->vidioc_g_sliced_vbi_cap(file, fh, p); 2602 } 2603 2604 static int v4l_enum_freq_bands(const struct v4l2_ioctl_ops *ops, 2605 struct file *file, void *fh, void *arg) 2606 { 2607 struct video_device *vfd = video_devdata(file); 2608 struct v4l2_frequency_band *p = arg; 2609 enum v4l2_tuner_type type; 2610 int err; 2611 2612 if (vfd->vfl_type == VFL_TYPE_SDR) { 2613 if (p->type != V4L2_TUNER_SDR && p->type != V4L2_TUNER_RF) 2614 return -EINVAL; 2615 type = p->type; 2616 } else { 2617 type = (vfd->vfl_type == VFL_TYPE_RADIO) ? 2618 V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; 2619 if (type != p->type) 2620 return -EINVAL; 2621 } 2622 if (ops->vidioc_enum_freq_bands) { 2623 err = ops->vidioc_enum_freq_bands(file, fh, p); 2624 if (err != -ENOTTY) 2625 return err; 2626 } 2627 if (is_valid_ioctl(vfd, VIDIOC_G_TUNER)) { 2628 struct v4l2_tuner t = { 2629 .index = p->tuner, 2630 .type = type, 2631 }; 2632 2633 if (p->index) 2634 return -EINVAL; 2635 err = ops->vidioc_g_tuner(file, fh, &t); 2636 if (err) 2637 return err; 2638 p->capability = t.capability | V4L2_TUNER_CAP_FREQ_BANDS; 2639 p->rangelow = t.rangelow; 2640 p->rangehigh = t.rangehigh; 2641 p->modulation = (type == V4L2_TUNER_RADIO) ? 2642 V4L2_BAND_MODULATION_FM : V4L2_BAND_MODULATION_VSB; 2643 return 0; 2644 } 2645 if (is_valid_ioctl(vfd, VIDIOC_G_MODULATOR)) { 2646 struct v4l2_modulator m = { 2647 .index = p->tuner, 2648 }; 2649 2650 if (type != V4L2_TUNER_RADIO) 2651 return -EINVAL; 2652 if (p->index) 2653 return -EINVAL; 2654 err = ops->vidioc_g_modulator(file, fh, &m); 2655 if (err) 2656 return err; 2657 p->capability = m.capability | V4L2_TUNER_CAP_FREQ_BANDS; 2658 p->rangelow = m.rangelow; 2659 p->rangehigh = m.rangehigh; 2660 p->modulation = (type == V4L2_TUNER_RADIO) ? 2661 V4L2_BAND_MODULATION_FM : V4L2_BAND_MODULATION_VSB; 2662 return 0; 2663 } 2664 return -ENOTTY; 2665 } 2666 2667 struct v4l2_ioctl_info { 2668 unsigned int ioctl; 2669 u32 flags; 2670 const char * const name; 2671 int (*func)(const struct v4l2_ioctl_ops *ops, struct file *file, 2672 void *fh, void *p); 2673 void (*debug)(const void *arg, bool write_only); 2674 }; 2675 2676 /* This control needs a priority check */ 2677 #define INFO_FL_PRIO (1 << 0) 2678 /* This control can be valid if the filehandle passes a control handler. */ 2679 #define INFO_FL_CTRL (1 << 1) 2680 /* Queuing ioctl */ 2681 #define INFO_FL_QUEUE (1 << 2) 2682 /* Always copy back result, even on error */ 2683 #define INFO_FL_ALWAYS_COPY (1 << 3) 2684 /* Zero struct from after the field to the end */ 2685 #define INFO_FL_CLEAR(v4l2_struct, field) \ 2686 ((offsetof(struct v4l2_struct, field) + \ 2687 sizeof_field(struct v4l2_struct, field)) << 16) 2688 #define INFO_FL_CLEAR_MASK (_IOC_SIZEMASK << 16) 2689 2690 #define DEFINE_V4L_STUB_FUNC(_vidioc) \ 2691 static int v4l_stub_ ## _vidioc( \ 2692 const struct v4l2_ioctl_ops *ops, \ 2693 struct file *file, void *fh, void *p) \ 2694 { \ 2695 return ops->vidioc_ ## _vidioc(file, fh, p); \ 2696 } 2697 2698 #define IOCTL_INFO(_ioctl, _func, _debug, _flags) \ 2699 [_IOC_NR(_ioctl)] = { \ 2700 .ioctl = _ioctl, \ 2701 .flags = _flags, \ 2702 .name = #_ioctl, \ 2703 .func = _func, \ 2704 .debug = _debug, \ 2705 } 2706 2707 DEFINE_V4L_STUB_FUNC(g_fbuf) 2708 DEFINE_V4L_STUB_FUNC(s_fbuf) 2709 DEFINE_V4L_STUB_FUNC(expbuf) 2710 DEFINE_V4L_STUB_FUNC(g_std) 2711 DEFINE_V4L_STUB_FUNC(g_audio) 2712 DEFINE_V4L_STUB_FUNC(s_audio) 2713 DEFINE_V4L_STUB_FUNC(g_edid) 2714 DEFINE_V4L_STUB_FUNC(s_edid) 2715 DEFINE_V4L_STUB_FUNC(g_audout) 2716 DEFINE_V4L_STUB_FUNC(s_audout) 2717 DEFINE_V4L_STUB_FUNC(g_jpegcomp) 2718 DEFINE_V4L_STUB_FUNC(s_jpegcomp) 2719 DEFINE_V4L_STUB_FUNC(enumaudio) 2720 DEFINE_V4L_STUB_FUNC(enumaudout) 2721 DEFINE_V4L_STUB_FUNC(enum_framesizes) 2722 DEFINE_V4L_STUB_FUNC(enum_frameintervals) 2723 DEFINE_V4L_STUB_FUNC(g_enc_index) 2724 DEFINE_V4L_STUB_FUNC(encoder_cmd) 2725 DEFINE_V4L_STUB_FUNC(try_encoder_cmd) 2726 DEFINE_V4L_STUB_FUNC(decoder_cmd) 2727 DEFINE_V4L_STUB_FUNC(try_decoder_cmd) 2728 DEFINE_V4L_STUB_FUNC(s_dv_timings) 2729 DEFINE_V4L_STUB_FUNC(g_dv_timings) 2730 DEFINE_V4L_STUB_FUNC(enum_dv_timings) 2731 DEFINE_V4L_STUB_FUNC(query_dv_timings) 2732 DEFINE_V4L_STUB_FUNC(dv_timings_cap) 2733 2734 static const struct v4l2_ioctl_info v4l2_ioctls[] = { 2735 IOCTL_INFO(VIDIOC_QUERYCAP, v4l_querycap, v4l_print_querycap, 0), 2736 IOCTL_INFO(VIDIOC_ENUM_FMT, v4l_enum_fmt, v4l_print_fmtdesc, 0), 2737 IOCTL_INFO(VIDIOC_G_FMT, v4l_g_fmt, v4l_print_format, 0), 2738 IOCTL_INFO(VIDIOC_S_FMT, v4l_s_fmt, v4l_print_format, INFO_FL_PRIO), 2739 IOCTL_INFO(VIDIOC_REQBUFS, v4l_reqbufs, v4l_print_requestbuffers, INFO_FL_PRIO | INFO_FL_QUEUE), 2740 IOCTL_INFO(VIDIOC_QUERYBUF, v4l_querybuf, v4l_print_buffer, INFO_FL_QUEUE | INFO_FL_CLEAR(v4l2_buffer, length)), 2741 IOCTL_INFO(VIDIOC_G_FBUF, v4l_stub_g_fbuf, v4l_print_framebuffer, 0), 2742 IOCTL_INFO(VIDIOC_S_FBUF, v4l_stub_s_fbuf, v4l_print_framebuffer, INFO_FL_PRIO), 2743 IOCTL_INFO(VIDIOC_OVERLAY, v4l_overlay, v4l_print_u32, INFO_FL_PRIO), 2744 IOCTL_INFO(VIDIOC_QBUF, v4l_qbuf, v4l_print_buffer, INFO_FL_QUEUE), 2745 IOCTL_INFO(VIDIOC_EXPBUF, v4l_stub_expbuf, v4l_print_exportbuffer, INFO_FL_QUEUE | INFO_FL_CLEAR(v4l2_exportbuffer, flags)), 2746 IOCTL_INFO(VIDIOC_DQBUF, v4l_dqbuf, v4l_print_buffer, INFO_FL_QUEUE), 2747 IOCTL_INFO(VIDIOC_STREAMON, v4l_streamon, v4l_print_buftype, INFO_FL_PRIO | INFO_FL_QUEUE), 2748 IOCTL_INFO(VIDIOC_STREAMOFF, v4l_streamoff, v4l_print_buftype, INFO_FL_PRIO | INFO_FL_QUEUE), 2749 IOCTL_INFO(VIDIOC_G_PARM, v4l_g_parm, v4l_print_streamparm, INFO_FL_CLEAR(v4l2_streamparm, type)), 2750 IOCTL_INFO(VIDIOC_S_PARM, v4l_s_parm, v4l_print_streamparm, INFO_FL_PRIO), 2751 IOCTL_INFO(VIDIOC_G_STD, v4l_stub_g_std, v4l_print_std, 0), 2752 IOCTL_INFO(VIDIOC_S_STD, v4l_s_std, v4l_print_std, INFO_FL_PRIO), 2753 IOCTL_INFO(VIDIOC_ENUMSTD, v4l_enumstd, v4l_print_standard, INFO_FL_CLEAR(v4l2_standard, index)), 2754 IOCTL_INFO(VIDIOC_ENUMINPUT, v4l_enuminput, v4l_print_enuminput, INFO_FL_CLEAR(v4l2_input, index)), 2755 IOCTL_INFO(VIDIOC_G_CTRL, v4l_g_ctrl, v4l_print_control, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_control, id)), 2756 IOCTL_INFO(VIDIOC_S_CTRL, v4l_s_ctrl, v4l_print_control, INFO_FL_PRIO | INFO_FL_CTRL), 2757 IOCTL_INFO(VIDIOC_G_TUNER, v4l_g_tuner, v4l_print_tuner, INFO_FL_CLEAR(v4l2_tuner, index)), 2758 IOCTL_INFO(VIDIOC_S_TUNER, v4l_s_tuner, v4l_print_tuner, INFO_FL_PRIO), 2759 IOCTL_INFO(VIDIOC_G_AUDIO, v4l_stub_g_audio, v4l_print_audio, 0), 2760 IOCTL_INFO(VIDIOC_S_AUDIO, v4l_stub_s_audio, v4l_print_audio, INFO_FL_PRIO), 2761 IOCTL_INFO(VIDIOC_QUERYCTRL, v4l_queryctrl, v4l_print_queryctrl, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_queryctrl, id)), 2762 IOCTL_INFO(VIDIOC_QUERYMENU, v4l_querymenu, v4l_print_querymenu, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_querymenu, index)), 2763 IOCTL_INFO(VIDIOC_G_INPUT, v4l_g_input, v4l_print_u32, 0), 2764 IOCTL_INFO(VIDIOC_S_INPUT, v4l_s_input, v4l_print_u32, INFO_FL_PRIO), 2765 IOCTL_INFO(VIDIOC_G_EDID, v4l_stub_g_edid, v4l_print_edid, INFO_FL_ALWAYS_COPY), 2766 IOCTL_INFO(VIDIOC_S_EDID, v4l_stub_s_edid, v4l_print_edid, INFO_FL_PRIO | INFO_FL_ALWAYS_COPY), 2767 IOCTL_INFO(VIDIOC_G_OUTPUT, v4l_g_output, v4l_print_u32, 0), 2768 IOCTL_INFO(VIDIOC_S_OUTPUT, v4l_s_output, v4l_print_u32, INFO_FL_PRIO), 2769 IOCTL_INFO(VIDIOC_ENUMOUTPUT, v4l_enumoutput, v4l_print_enumoutput, INFO_FL_CLEAR(v4l2_output, index)), 2770 IOCTL_INFO(VIDIOC_G_AUDOUT, v4l_stub_g_audout, v4l_print_audioout, 0), 2771 IOCTL_INFO(VIDIOC_S_AUDOUT, v4l_stub_s_audout, v4l_print_audioout, INFO_FL_PRIO), 2772 IOCTL_INFO(VIDIOC_G_MODULATOR, v4l_g_modulator, v4l_print_modulator, INFO_FL_CLEAR(v4l2_modulator, index)), 2773 IOCTL_INFO(VIDIOC_S_MODULATOR, v4l_s_modulator, v4l_print_modulator, INFO_FL_PRIO), 2774 IOCTL_INFO(VIDIOC_G_FREQUENCY, v4l_g_frequency, v4l_print_frequency, INFO_FL_CLEAR(v4l2_frequency, tuner)), 2775 IOCTL_INFO(VIDIOC_S_FREQUENCY, v4l_s_frequency, v4l_print_frequency, INFO_FL_PRIO), 2776 IOCTL_INFO(VIDIOC_CROPCAP, v4l_cropcap, v4l_print_cropcap, INFO_FL_CLEAR(v4l2_cropcap, type)), 2777 IOCTL_INFO(VIDIOC_G_CROP, v4l_g_crop, v4l_print_crop, INFO_FL_CLEAR(v4l2_crop, type)), 2778 IOCTL_INFO(VIDIOC_S_CROP, v4l_s_crop, v4l_print_crop, INFO_FL_PRIO), 2779 IOCTL_INFO(VIDIOC_G_SELECTION, v4l_g_selection, v4l_print_selection, INFO_FL_CLEAR(v4l2_selection, r)), 2780 IOCTL_INFO(VIDIOC_S_SELECTION, v4l_s_selection, v4l_print_selection, INFO_FL_PRIO | INFO_FL_CLEAR(v4l2_selection, r)), 2781 IOCTL_INFO(VIDIOC_G_JPEGCOMP, v4l_stub_g_jpegcomp, v4l_print_jpegcompression, 0), 2782 IOCTL_INFO(VIDIOC_S_JPEGCOMP, v4l_stub_s_jpegcomp, v4l_print_jpegcompression, INFO_FL_PRIO), 2783 IOCTL_INFO(VIDIOC_QUERYSTD, v4l_querystd, v4l_print_std, 0), 2784 IOCTL_INFO(VIDIOC_TRY_FMT, v4l_try_fmt, v4l_print_format, 0), 2785 IOCTL_INFO(VIDIOC_ENUMAUDIO, v4l_stub_enumaudio, v4l_print_audio, INFO_FL_CLEAR(v4l2_audio, index)), 2786 IOCTL_INFO(VIDIOC_ENUMAUDOUT, v4l_stub_enumaudout, v4l_print_audioout, INFO_FL_CLEAR(v4l2_audioout, index)), 2787 IOCTL_INFO(VIDIOC_G_PRIORITY, v4l_g_priority, v4l_print_u32, 0), 2788 IOCTL_INFO(VIDIOC_S_PRIORITY, v4l_s_priority, v4l_print_u32, INFO_FL_PRIO), 2789 IOCTL_INFO(VIDIOC_G_SLICED_VBI_CAP, v4l_g_sliced_vbi_cap, v4l_print_sliced_vbi_cap, INFO_FL_CLEAR(v4l2_sliced_vbi_cap, type)), 2790 IOCTL_INFO(VIDIOC_LOG_STATUS, v4l_log_status, v4l_print_newline, 0), 2791 IOCTL_INFO(VIDIOC_G_EXT_CTRLS, v4l_g_ext_ctrls, v4l_print_ext_controls, INFO_FL_CTRL), 2792 IOCTL_INFO(VIDIOC_S_EXT_CTRLS, v4l_s_ext_ctrls, v4l_print_ext_controls, INFO_FL_PRIO | INFO_FL_CTRL), 2793 IOCTL_INFO(VIDIOC_TRY_EXT_CTRLS, v4l_try_ext_ctrls, v4l_print_ext_controls, INFO_FL_CTRL), 2794 IOCTL_INFO(VIDIOC_ENUM_FRAMESIZES, v4l_stub_enum_framesizes, v4l_print_frmsizeenum, INFO_FL_CLEAR(v4l2_frmsizeenum, pixel_format)), 2795 IOCTL_INFO(VIDIOC_ENUM_FRAMEINTERVALS, v4l_stub_enum_frameintervals, v4l_print_frmivalenum, INFO_FL_CLEAR(v4l2_frmivalenum, height)), 2796 IOCTL_INFO(VIDIOC_G_ENC_INDEX, v4l_stub_g_enc_index, v4l_print_enc_idx, 0), 2797 IOCTL_INFO(VIDIOC_ENCODER_CMD, v4l_stub_encoder_cmd, v4l_print_encoder_cmd, INFO_FL_PRIO | INFO_FL_CLEAR(v4l2_encoder_cmd, flags)), 2798 IOCTL_INFO(VIDIOC_TRY_ENCODER_CMD, v4l_stub_try_encoder_cmd, v4l_print_encoder_cmd, INFO_FL_CLEAR(v4l2_encoder_cmd, flags)), 2799 IOCTL_INFO(VIDIOC_DECODER_CMD, v4l_stub_decoder_cmd, v4l_print_decoder_cmd, INFO_FL_PRIO), 2800 IOCTL_INFO(VIDIOC_TRY_DECODER_CMD, v4l_stub_try_decoder_cmd, v4l_print_decoder_cmd, 0), 2801 IOCTL_INFO(VIDIOC_DBG_S_REGISTER, v4l_dbg_s_register, v4l_print_dbg_register, 0), 2802 IOCTL_INFO(VIDIOC_DBG_G_REGISTER, v4l_dbg_g_register, v4l_print_dbg_register, 0), 2803 IOCTL_INFO(VIDIOC_S_HW_FREQ_SEEK, v4l_s_hw_freq_seek, v4l_print_hw_freq_seek, INFO_FL_PRIO), 2804 IOCTL_INFO(VIDIOC_S_DV_TIMINGS, v4l_stub_s_dv_timings, v4l_print_dv_timings, INFO_FL_PRIO | INFO_FL_CLEAR(v4l2_dv_timings, bt.flags)), 2805 IOCTL_INFO(VIDIOC_G_DV_TIMINGS, v4l_stub_g_dv_timings, v4l_print_dv_timings, 0), 2806 IOCTL_INFO(VIDIOC_DQEVENT, v4l_dqevent, v4l_print_event, 0), 2807 IOCTL_INFO(VIDIOC_SUBSCRIBE_EVENT, v4l_subscribe_event, v4l_print_event_subscription, 0), 2808 IOCTL_INFO(VIDIOC_UNSUBSCRIBE_EVENT, v4l_unsubscribe_event, v4l_print_event_subscription, 0), 2809 IOCTL_INFO(VIDIOC_CREATE_BUFS, v4l_create_bufs, v4l_print_create_buffers, INFO_FL_PRIO | INFO_FL_QUEUE), 2810 IOCTL_INFO(VIDIOC_PREPARE_BUF, v4l_prepare_buf, v4l_print_buffer, INFO_FL_QUEUE), 2811 IOCTL_INFO(VIDIOC_ENUM_DV_TIMINGS, v4l_stub_enum_dv_timings, v4l_print_enum_dv_timings, INFO_FL_CLEAR(v4l2_enum_dv_timings, pad)), 2812 IOCTL_INFO(VIDIOC_QUERY_DV_TIMINGS, v4l_stub_query_dv_timings, v4l_print_dv_timings, INFO_FL_ALWAYS_COPY), 2813 IOCTL_INFO(VIDIOC_DV_TIMINGS_CAP, v4l_stub_dv_timings_cap, v4l_print_dv_timings_cap, INFO_FL_CLEAR(v4l2_dv_timings_cap, pad)), 2814 IOCTL_INFO(VIDIOC_ENUM_FREQ_BANDS, v4l_enum_freq_bands, v4l_print_freq_band, 0), 2815 IOCTL_INFO(VIDIOC_DBG_G_CHIP_INFO, v4l_dbg_g_chip_info, v4l_print_dbg_chip_info, INFO_FL_CLEAR(v4l2_dbg_chip_info, match)), 2816 IOCTL_INFO(VIDIOC_QUERY_EXT_CTRL, v4l_query_ext_ctrl, v4l_print_query_ext_ctrl, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_query_ext_ctrl, id)), 2817 }; 2818 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls) 2819 2820 static bool v4l2_is_known_ioctl(unsigned int cmd) 2821 { 2822 if (_IOC_NR(cmd) >= V4L2_IOCTLS) 2823 return false; 2824 return v4l2_ioctls[_IOC_NR(cmd)].ioctl == cmd; 2825 } 2826 2827 static struct mutex *v4l2_ioctl_get_lock(struct video_device *vdev, 2828 struct v4l2_fh *vfh, unsigned int cmd, 2829 void *arg) 2830 { 2831 if (_IOC_NR(cmd) >= V4L2_IOCTLS) 2832 return vdev->lock; 2833 if (vfh && vfh->m2m_ctx && 2834 (v4l2_ioctls[_IOC_NR(cmd)].flags & INFO_FL_QUEUE)) { 2835 if (vfh->m2m_ctx->q_lock) 2836 return vfh->m2m_ctx->q_lock; 2837 } 2838 if (vdev->queue && vdev->queue->lock && 2839 (v4l2_ioctls[_IOC_NR(cmd)].flags & INFO_FL_QUEUE)) 2840 return vdev->queue->lock; 2841 return vdev->lock; 2842 } 2843 2844 /* Common ioctl debug function. This function can be used by 2845 external ioctl messages as well as internal V4L ioctl */ 2846 void v4l_printk_ioctl(const char *prefix, unsigned int cmd) 2847 { 2848 const char *dir, *type; 2849 2850 if (prefix) 2851 printk(KERN_DEBUG "%s: ", prefix); 2852 2853 switch (_IOC_TYPE(cmd)) { 2854 case 'd': 2855 type = "v4l2_int"; 2856 break; 2857 case 'V': 2858 if (_IOC_NR(cmd) >= V4L2_IOCTLS) { 2859 type = "v4l2"; 2860 break; 2861 } 2862 pr_cont("%s", v4l2_ioctls[_IOC_NR(cmd)].name); 2863 return; 2864 default: 2865 type = "unknown"; 2866 break; 2867 } 2868 2869 switch (_IOC_DIR(cmd)) { 2870 case _IOC_NONE: dir = "--"; break; 2871 case _IOC_READ: dir = "r-"; break; 2872 case _IOC_WRITE: dir = "-w"; break; 2873 case _IOC_READ | _IOC_WRITE: dir = "rw"; break; 2874 default: dir = "*ERR*"; break; 2875 } 2876 pr_cont("%s ioctl '%c', dir=%s, #%d (0x%08x)", 2877 type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd); 2878 } 2879 EXPORT_SYMBOL(v4l_printk_ioctl); 2880 2881 static long __video_do_ioctl(struct file *file, 2882 unsigned int cmd, void *arg) 2883 { 2884 struct video_device *vfd = video_devdata(file); 2885 struct mutex *req_queue_lock = NULL; 2886 struct mutex *lock; /* ioctl serialization mutex */ 2887 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops; 2888 bool write_only = false; 2889 struct v4l2_ioctl_info default_info; 2890 const struct v4l2_ioctl_info *info; 2891 void *fh = file->private_data; 2892 struct v4l2_fh *vfh = NULL; 2893 int dev_debug = vfd->dev_debug; 2894 long ret = -ENOTTY; 2895 2896 if (ops == NULL) { 2897 pr_warn("%s: has no ioctl_ops.\n", 2898 video_device_node_name(vfd)); 2899 return ret; 2900 } 2901 2902 if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) 2903 vfh = file->private_data; 2904 2905 /* 2906 * We need to serialize streamon/off with queueing new requests. 2907 * These ioctls may trigger the cancellation of a streaming 2908 * operation, and that should not be mixed with queueing a new 2909 * request at the same time. 2910 */ 2911 if (v4l2_device_supports_requests(vfd->v4l2_dev) && 2912 (cmd == VIDIOC_STREAMON || cmd == VIDIOC_STREAMOFF)) { 2913 req_queue_lock = &vfd->v4l2_dev->mdev->req_queue_mutex; 2914 2915 if (mutex_lock_interruptible(req_queue_lock)) 2916 return -ERESTARTSYS; 2917 } 2918 2919 lock = v4l2_ioctl_get_lock(vfd, vfh, cmd, arg); 2920 2921 if (lock && mutex_lock_interruptible(lock)) { 2922 if (req_queue_lock) 2923 mutex_unlock(req_queue_lock); 2924 return -ERESTARTSYS; 2925 } 2926 2927 if (!video_is_registered(vfd)) { 2928 ret = -ENODEV; 2929 goto unlock; 2930 } 2931 2932 if (v4l2_is_known_ioctl(cmd)) { 2933 info = &v4l2_ioctls[_IOC_NR(cmd)]; 2934 2935 if (!test_bit(_IOC_NR(cmd), vfd->valid_ioctls) && 2936 !((info->flags & INFO_FL_CTRL) && vfh && vfh->ctrl_handler)) 2937 goto done; 2938 2939 if (vfh && (info->flags & INFO_FL_PRIO)) { 2940 ret = v4l2_prio_check(vfd->prio, vfh->prio); 2941 if (ret) 2942 goto done; 2943 } 2944 } else { 2945 default_info.ioctl = cmd; 2946 default_info.flags = 0; 2947 default_info.debug = v4l_print_default; 2948 info = &default_info; 2949 } 2950 2951 write_only = _IOC_DIR(cmd) == _IOC_WRITE; 2952 if (info != &default_info) { 2953 ret = info->func(ops, file, fh, arg); 2954 } else if (!ops->vidioc_default) { 2955 ret = -ENOTTY; 2956 } else { 2957 ret = ops->vidioc_default(file, fh, 2958 vfh ? v4l2_prio_check(vfd->prio, vfh->prio) >= 0 : 0, 2959 cmd, arg); 2960 } 2961 2962 done: 2963 if (dev_debug & (V4L2_DEV_DEBUG_IOCTL | V4L2_DEV_DEBUG_IOCTL_ARG)) { 2964 if (!(dev_debug & V4L2_DEV_DEBUG_STREAMING) && 2965 (cmd == VIDIOC_QBUF || cmd == VIDIOC_DQBUF)) 2966 goto unlock; 2967 2968 v4l_printk_ioctl(video_device_node_name(vfd), cmd); 2969 if (ret < 0) 2970 pr_cont(": error %ld", ret); 2971 if (!(dev_debug & V4L2_DEV_DEBUG_IOCTL_ARG)) 2972 pr_cont("\n"); 2973 else if (_IOC_DIR(cmd) == _IOC_NONE) 2974 info->debug(arg, write_only); 2975 else { 2976 pr_cont(": "); 2977 info->debug(arg, write_only); 2978 } 2979 } 2980 2981 unlock: 2982 if (lock) 2983 mutex_unlock(lock); 2984 if (req_queue_lock) 2985 mutex_unlock(req_queue_lock); 2986 return ret; 2987 } 2988 2989 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size, 2990 void __user **user_ptr, void ***kernel_ptr) 2991 { 2992 int ret = 0; 2993 2994 switch (cmd) { 2995 case VIDIOC_PREPARE_BUF: 2996 case VIDIOC_QUERYBUF: 2997 case VIDIOC_QBUF: 2998 case VIDIOC_DQBUF: { 2999 struct v4l2_buffer *buf = parg; 3000 3001 if (V4L2_TYPE_IS_MULTIPLANAR(buf->type) && buf->length > 0) { 3002 if (buf->length > VIDEO_MAX_PLANES) { 3003 ret = -EINVAL; 3004 break; 3005 } 3006 *user_ptr = (void __user *)buf->m.planes; 3007 *kernel_ptr = (void **)&buf->m.planes; 3008 *array_size = sizeof(struct v4l2_plane) * buf->length; 3009 ret = 1; 3010 } 3011 break; 3012 } 3013 3014 case VIDIOC_G_EDID: 3015 case VIDIOC_S_EDID: { 3016 struct v4l2_edid *edid = parg; 3017 3018 if (edid->blocks) { 3019 if (edid->blocks > 256) { 3020 ret = -EINVAL; 3021 break; 3022 } 3023 *user_ptr = (void __user *)edid->edid; 3024 *kernel_ptr = (void **)&edid->edid; 3025 *array_size = edid->blocks * 128; 3026 ret = 1; 3027 } 3028 break; 3029 } 3030 3031 case VIDIOC_S_EXT_CTRLS: 3032 case VIDIOC_G_EXT_CTRLS: 3033 case VIDIOC_TRY_EXT_CTRLS: { 3034 struct v4l2_ext_controls *ctrls = parg; 3035 3036 if (ctrls->count != 0) { 3037 if (ctrls->count > V4L2_CID_MAX_CTRLS) { 3038 ret = -EINVAL; 3039 break; 3040 } 3041 *user_ptr = (void __user *)ctrls->controls; 3042 *kernel_ptr = (void **)&ctrls->controls; 3043 *array_size = sizeof(struct v4l2_ext_control) 3044 * ctrls->count; 3045 ret = 1; 3046 } 3047 break; 3048 } 3049 case VIDIOC_G_FMT: 3050 case VIDIOC_S_FMT: 3051 case VIDIOC_TRY_FMT: { 3052 struct v4l2_format *fmt = parg; 3053 3054 if (fmt->type != V4L2_BUF_TYPE_VIDEO_OVERLAY && 3055 fmt->type != V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY) 3056 break; 3057 if (fmt->fmt.win.clipcount > 2048) 3058 return -EINVAL; 3059 if (!fmt->fmt.win.clipcount) 3060 break; 3061 3062 *user_ptr = (void __user *)fmt->fmt.win.clips; 3063 *kernel_ptr = (void **)&fmt->fmt.win.clips; 3064 *array_size = sizeof(struct v4l2_clip) 3065 * fmt->fmt.win.clipcount; 3066 3067 ret = 1; 3068 break; 3069 } 3070 } 3071 3072 return ret; 3073 } 3074 3075 static unsigned int video_translate_cmd(unsigned int cmd) 3076 { 3077 #if !defined(CONFIG_64BIT) && defined(CONFIG_COMPAT_32BIT_TIME) 3078 switch (cmd) { 3079 case VIDIOC_DQEVENT_TIME32: 3080 return VIDIOC_DQEVENT; 3081 case VIDIOC_QUERYBUF_TIME32: 3082 return VIDIOC_QUERYBUF; 3083 case VIDIOC_QBUF_TIME32: 3084 return VIDIOC_QBUF; 3085 case VIDIOC_DQBUF_TIME32: 3086 return VIDIOC_DQBUF; 3087 case VIDIOC_PREPARE_BUF_TIME32: 3088 return VIDIOC_PREPARE_BUF; 3089 } 3090 #endif 3091 if (in_compat_syscall()) 3092 return v4l2_compat_translate_cmd(cmd); 3093 3094 return cmd; 3095 } 3096 3097 static int video_get_user(void __user *arg, void *parg, 3098 unsigned int real_cmd, unsigned int cmd, 3099 bool *always_copy) 3100 { 3101 unsigned int n = _IOC_SIZE(real_cmd); 3102 int err = 0; 3103 3104 if (!(_IOC_DIR(cmd) & _IOC_WRITE)) { 3105 /* read-only ioctl */ 3106 memset(parg, 0, n); 3107 return 0; 3108 } 3109 3110 /* 3111 * In some cases, only a few fields are used as input, 3112 * i.e. when the app sets "index" and then the driver 3113 * fills in the rest of the structure for the thing 3114 * with that index. We only need to copy up the first 3115 * non-input field. 3116 */ 3117 if (v4l2_is_known_ioctl(real_cmd)) { 3118 u32 flags = v4l2_ioctls[_IOC_NR(real_cmd)].flags; 3119 3120 if (flags & INFO_FL_CLEAR_MASK) 3121 n = (flags & INFO_FL_CLEAR_MASK) >> 16; 3122 *always_copy = flags & INFO_FL_ALWAYS_COPY; 3123 } 3124 3125 if (cmd == real_cmd) { 3126 if (copy_from_user(parg, (void __user *)arg, n)) 3127 err = -EFAULT; 3128 } else if (in_compat_syscall()) { 3129 memset(parg, 0, n); 3130 err = v4l2_compat_get_user(arg, parg, cmd); 3131 } else { 3132 memset(parg, 0, n); 3133 #if !defined(CONFIG_64BIT) && defined(CONFIG_COMPAT_32BIT_TIME) 3134 switch (cmd) { 3135 case VIDIOC_QUERYBUF_TIME32: 3136 case VIDIOC_QBUF_TIME32: 3137 case VIDIOC_DQBUF_TIME32: 3138 case VIDIOC_PREPARE_BUF_TIME32: { 3139 struct v4l2_buffer_time32 vb32; 3140 struct v4l2_buffer *vb = parg; 3141 3142 if (copy_from_user(&vb32, arg, sizeof(vb32))) 3143 return -EFAULT; 3144 3145 *vb = (struct v4l2_buffer) { 3146 .index = vb32.index, 3147 .type = vb32.type, 3148 .bytesused = vb32.bytesused, 3149 .flags = vb32.flags, 3150 .field = vb32.field, 3151 .timestamp.tv_sec = vb32.timestamp.tv_sec, 3152 .timestamp.tv_usec = vb32.timestamp.tv_usec, 3153 .timecode = vb32.timecode, 3154 .sequence = vb32.sequence, 3155 .memory = vb32.memory, 3156 .m.userptr = vb32.m.userptr, 3157 .length = vb32.length, 3158 .request_fd = vb32.request_fd, 3159 }; 3160 break; 3161 } 3162 } 3163 #endif 3164 } 3165 3166 /* zero out anything we don't copy from userspace */ 3167 if (!err && n < _IOC_SIZE(real_cmd)) 3168 memset((u8 *)parg + n, 0, _IOC_SIZE(real_cmd) - n); 3169 return err; 3170 } 3171 3172 static int video_put_user(void __user *arg, void *parg, 3173 unsigned int real_cmd, unsigned int cmd) 3174 { 3175 if (!(_IOC_DIR(cmd) & _IOC_READ)) 3176 return 0; 3177 3178 if (cmd == real_cmd) { 3179 /* Copy results into user buffer */ 3180 if (copy_to_user(arg, parg, _IOC_SIZE(cmd))) 3181 return -EFAULT; 3182 return 0; 3183 } 3184 3185 if (in_compat_syscall()) 3186 return v4l2_compat_put_user(arg, parg, cmd); 3187 3188 #if !defined(CONFIG_64BIT) && defined(CONFIG_COMPAT_32BIT_TIME) 3189 switch (cmd) { 3190 case VIDIOC_DQEVENT_TIME32: { 3191 struct v4l2_event *ev = parg; 3192 struct v4l2_event_time32 ev32; 3193 3194 memset(&ev32, 0, sizeof(ev32)); 3195 3196 ev32.type = ev->type; 3197 ev32.pending = ev->pending; 3198 ev32.sequence = ev->sequence; 3199 ev32.timestamp.tv_sec = ev->timestamp.tv_sec; 3200 ev32.timestamp.tv_nsec = ev->timestamp.tv_nsec; 3201 ev32.id = ev->id; 3202 3203 memcpy(&ev32.u, &ev->u, sizeof(ev->u)); 3204 memcpy(&ev32.reserved, &ev->reserved, sizeof(ev->reserved)); 3205 3206 if (copy_to_user(arg, &ev32, sizeof(ev32))) 3207 return -EFAULT; 3208 break; 3209 } 3210 case VIDIOC_QUERYBUF_TIME32: 3211 case VIDIOC_QBUF_TIME32: 3212 case VIDIOC_DQBUF_TIME32: 3213 case VIDIOC_PREPARE_BUF_TIME32: { 3214 struct v4l2_buffer *vb = parg; 3215 struct v4l2_buffer_time32 vb32; 3216 3217 memset(&vb32, 0, sizeof(vb32)); 3218 3219 vb32.index = vb->index; 3220 vb32.type = vb->type; 3221 vb32.bytesused = vb->bytesused; 3222 vb32.flags = vb->flags; 3223 vb32.field = vb->field; 3224 vb32.timestamp.tv_sec = vb->timestamp.tv_sec; 3225 vb32.timestamp.tv_usec = vb->timestamp.tv_usec; 3226 vb32.timecode = vb->timecode; 3227 vb32.sequence = vb->sequence; 3228 vb32.memory = vb->memory; 3229 vb32.m.userptr = vb->m.userptr; 3230 vb32.length = vb->length; 3231 vb32.request_fd = vb->request_fd; 3232 3233 if (copy_to_user(arg, &vb32, sizeof(vb32))) 3234 return -EFAULT; 3235 break; 3236 } 3237 } 3238 #endif 3239 3240 return 0; 3241 } 3242 3243 long 3244 video_usercopy(struct file *file, unsigned int orig_cmd, unsigned long arg, 3245 v4l2_kioctl func) 3246 { 3247 char sbuf[128]; 3248 void *mbuf = NULL, *array_buf = NULL; 3249 void *parg = (void *)arg; 3250 long err = -EINVAL; 3251 bool has_array_args; 3252 bool always_copy = false; 3253 size_t array_size = 0; 3254 void __user *user_ptr = NULL; 3255 void **kernel_ptr = NULL; 3256 unsigned int cmd = video_translate_cmd(orig_cmd); 3257 const size_t ioc_size = _IOC_SIZE(cmd); 3258 3259 /* Copy arguments into temp kernel buffer */ 3260 if (_IOC_DIR(cmd) != _IOC_NONE) { 3261 if (ioc_size <= sizeof(sbuf)) { 3262 parg = sbuf; 3263 } else { 3264 /* too big to allocate from stack */ 3265 mbuf = kmalloc(ioc_size, GFP_KERNEL); 3266 if (NULL == mbuf) 3267 return -ENOMEM; 3268 parg = mbuf; 3269 } 3270 3271 err = video_get_user((void __user *)arg, parg, cmd, 3272 orig_cmd, &always_copy); 3273 if (err) 3274 goto out; 3275 } 3276 3277 err = check_array_args(cmd, parg, &array_size, &user_ptr, &kernel_ptr); 3278 if (err < 0) 3279 goto out; 3280 has_array_args = err; 3281 3282 if (has_array_args) { 3283 array_buf = kvmalloc(array_size, GFP_KERNEL); 3284 err = -ENOMEM; 3285 if (array_buf == NULL) 3286 goto out_array_args; 3287 err = -EFAULT; 3288 if (in_compat_syscall()) 3289 err = v4l2_compat_get_array_args(file, array_buf, 3290 user_ptr, array_size, 3291 orig_cmd, parg); 3292 else 3293 err = copy_from_user(array_buf, user_ptr, array_size) ? 3294 -EFAULT : 0; 3295 if (err) 3296 goto out_array_args; 3297 *kernel_ptr = array_buf; 3298 } 3299 3300 /* Handles IOCTL */ 3301 err = func(file, cmd, parg); 3302 if (err == -ENOTTY || err == -ENOIOCTLCMD) { 3303 err = -ENOTTY; 3304 goto out; 3305 } 3306 3307 if (err == 0) { 3308 if (cmd == VIDIOC_DQBUF) 3309 trace_v4l2_dqbuf(video_devdata(file)->minor, parg); 3310 else if (cmd == VIDIOC_QBUF) 3311 trace_v4l2_qbuf(video_devdata(file)->minor, parg); 3312 } 3313 3314 if (has_array_args) { 3315 *kernel_ptr = (void __force *)user_ptr; 3316 if (in_compat_syscall()) { 3317 int put_err; 3318 3319 put_err = v4l2_compat_put_array_args(file, user_ptr, 3320 array_buf, 3321 array_size, 3322 orig_cmd, parg); 3323 if (put_err) 3324 err = put_err; 3325 } else if (copy_to_user(user_ptr, array_buf, array_size)) { 3326 err = -EFAULT; 3327 } 3328 goto out_array_args; 3329 } 3330 /* 3331 * Some ioctls can return an error, but still have valid 3332 * results that must be returned. 3333 */ 3334 if (err < 0 && !always_copy) 3335 goto out; 3336 3337 out_array_args: 3338 if (video_put_user((void __user *)arg, parg, cmd, orig_cmd)) 3339 err = -EFAULT; 3340 out: 3341 kvfree(array_buf); 3342 kfree(mbuf); 3343 return err; 3344 } 3345 3346 long video_ioctl2(struct file *file, 3347 unsigned int cmd, unsigned long arg) 3348 { 3349 return video_usercopy(file, cmd, arg, __video_do_ioctl); 3350 } 3351 EXPORT_SYMBOL(video_ioctl2); 3352