15 #include <linux/module.h>
16 #include <linux/slab.h>
17 #include <linux/types.h>
18 #include <linux/kernel.h>
19 #include <linux/version.h>
21 #include <linux/videodev2.h>
34 #define CLEAR_AFTER_FIELD(p, field) \
35 memset((u8 *)(p) + offsetof(typeof(*(p)), field) + sizeof((p)->field), \
36 0, sizeof(*(p)) - offsetof(typeof(*(p)), field) - sizeof((p)->field))
90 for (i = 0; standards[
i].
std; i++)
91 if (myid == standards[i].
std)
113 int id,
const char *
name)
154 static const char *v4l2_memory_names[] = {
160 #define prt_names(a, arr) (((unsigned)(a)) < ARRAY_SIZE(arr) ? arr[a] : "unknown")
165 static void v4l_print_querycap(
const void *
arg,
bool write_only)
169 pr_cont(
"driver=%s, card=%s, bus=%s, version=0x%08x, "
170 "capabilities=0x%08x, device_caps=0x%08x\n",
175 static void v4l_print_enuminput(
const void *
arg,
bool write_only)
179 pr_cont(
"index=%u, name=%s, type=%u, audioset=0x%x, tuner=%u, "
180 "std=0x%08Lx, status=0x%x, capabilities=0x%x\n",
185 static void v4l_print_enumoutput(
const void *
arg,
bool write_only)
189 pr_cont(
"index=%u, name=%s, type=%u, audioset=0x%x, "
190 "modulator=%u, std=0x%08Lx, capabilities=0x%x\n",
195 static void v4l_print_audio(
const void *
arg,
bool write_only)
202 pr_cont(
"index=%u, name=%s, capability=0x%x, mode=0x%x\n",
206 static void v4l_print_audioout(
const void *arg,
bool write_only)
213 pr_cont(
"index=%u, name=%s, capability=0x%x, mode=0x%x\n",
217 static void v4l_print_fmtdesc(
const void *arg,
bool write_only)
221 pr_cont(
"index=%u, type=%s, flags=0x%x, pixelformat=%c%c%c%c, description='%s'\n",
230 static void v4l_print_format(
const void *arg,
bool write_only)
246 pr_cont(
", width=%u, height=%u, "
247 "pixelformat=%c%c%c%c, field=%s, "
248 "bytesperline=%u sizeimage=%u, colorspace=%d\n",
261 pr_cont(
", width=%u, height=%u, "
262 "format=%c%c%c%c, field=%s, "
263 "colorspace=%d, num_planes=%u\n",
279 pr_cont(
", wxh=%dx%d, x,y=%d,%d, field=%s, "
280 "chromakey=0x%08x, bitmap=%p, "
281 "global_alpha=0x%02x\n",
282 win->
w.width, win->
w.height,
283 win->
w.left, win->
w.top,
289 i, clip->
c.width, clip->
c.height,
290 clip->
c.left, clip->
c.top);
297 pr_cont(
", sampling_rate=%u, offset=%u, samples_per_line=%u, "
298 "sample_format=%c%c%c%c, start=%u,%u, count=%u,%u\n",
311 pr_cont(
", service_set=0x%08x, io_size=%d\n",
313 for (i = 0; i < 24; i++)
321 static void v4l_print_framebuffer(
const void *arg,
bool write_only)
325 pr_cont(
"capability=0x%x, flags=0x%x, base=0x%p, width=%u, "
326 "height=%u, pixelformat=%c%c%c%c, "
327 "bytesperline=%u sizeimage=%u, colorspace=%d\n",
329 p->
fmt.width, p->
fmt.height,
330 (p->
fmt.pixelformat & 0xff),
331 (p->
fmt.pixelformat >> 8) & 0xff,
332 (p->
fmt.pixelformat >> 16) & 0xff,
333 (p->
fmt.pixelformat >> 24) & 0xff,
334 p->
fmt.bytesperline, p->
fmt.sizeimage,
338 static void v4l_print_buftype(
const void *arg,
bool write_only)
343 static void v4l_print_modulator(
const void *arg,
bool write_only)
350 pr_cont(
"index=%u, name=%s, capability=0x%x, "
351 "rangelow=%u, rangehigh=%u, txsubchans=0x%x\n",
356 static void v4l_print_tuner(
const void *arg,
bool write_only)
363 pr_cont(
"index=%u, name=%s, type=%u, capability=0x%x, "
364 "rangelow=%u, rangehigh=%u, signal=%u, afc=%d, "
365 "rxsubchans=0x%x, audmode=%u\n",
372 static void v4l_print_frequency(
const void *arg,
bool write_only)
376 pr_cont(
"tuner=%u, type=%u, frequency=%u\n",
380 static void v4l_print_standard(
const void *arg,
bool write_only)
384 pr_cont(
"index=%u, id=0x%Lx, name=%s, fps=%u/%u, "
385 "framelines=%u\n", p->
index,
386 (
unsigned long long)p->
id, p->
name,
392 static void v4l_print_std(
const void *arg,
bool write_only)
394 pr_cont(
"std=0x%08Lx\n", *(
const long long unsigned *)arg);
397 static void v4l_print_hw_freq_seek(
const void *arg,
bool write_only)
401 pr_cont(
"tuner=%u, type=%u, seek_upward=%u, wrap_around=%u, spacing=%u, "
402 "rangelow=%u, rangehigh=%u\n",
407 static void v4l_print_requestbuffers(
const void *arg,
bool write_only)
411 pr_cont(
"count=%d, type=%s, memory=%s\n",
417 static void v4l_print_buffer(
const void *arg,
bool write_only)
424 pr_cont(
"%02ld:%02d:%02d.%08ld index=%d, type=%s, "
425 "flags=0x%08x, field=%s, sequence=%d, memory=%s",
437 for (i = 0; i < p->
length; ++
i) {
440 "plane %d: bytesused=%d, data_offset=0x%08x "
441 "offset/userptr=0x%lx, length=%d\n",
446 pr_cont(
"bytesused=%d, offset/userptr=0x%lx, length=%d\n",
451 "flags=0x%08x, frames=%d, userbits=0x%08x\n",
456 static void v4l_print_create_buffers(
const void *arg,
bool write_only)
460 pr_cont(
"index=%d, count=%d, memory=%s, ",
463 v4l_print_format(&p->
format, write_only);
466 static void v4l_print_streamparm(
const void *arg,
bool write_only)
476 pr_cont(
", capability=0x%x, capturemode=0x%x, timeperframe=%d/%d, "
477 "extendedmode=%d, readbuffers=%d\n",
485 pr_cont(
", capability=0x%x, outputmode=0x%x, timeperframe=%d/%d, "
486 "extendedmode=%d, writebuffers=%d\n",
493 static void v4l_print_queryctrl(
const void *arg,
bool write_only)
497 pr_cont(
"id=0x%x, type=%d, name=%s, min/max=%d/%d, "
498 "step=%d, default=%d, flags=0x%08x\n",
504 static void v4l_print_querymenu(
const void *arg,
bool write_only)
511 static void v4l_print_control(
const void *arg,
bool write_only)
518 static void v4l_print_ext_controls(
const void *arg,
bool write_only)
523 pr_cont(
"class=0x%x, count=%d, error_idx=%d",
525 for (i = 0; i < p->
count; i++) {
536 static void v4l_print_cropcap(
const void *arg,
bool write_only)
540 pr_cont(
"type=%s, bounds wxh=%dx%d, x,y=%d,%d, "
541 "defrect wxh=%dx%d, x,y=%d,%d\n, "
542 "pixelaspect %d/%d\n",
551 static void v4l_print_crop(
const void *arg,
bool write_only)
555 pr_cont(
"type=%s, wxh=%dx%d, x,y=%d,%d\n",
557 p->
c.width, p->
c.height,
558 p->
c.left, p->
c.top);
561 static void v4l_print_selection(
const void *arg,
bool write_only)
565 pr_cont(
"type=%s, target=%d, flags=0x%x, wxh=%dx%d, x,y=%d,%d\n",
568 p->
r.width, p->
r.height, p->
r.left, p->
r.top);
571 static void v4l_print_jpegcompression(
const void *arg,
bool write_only)
575 pr_cont(
"quality=%d, APPn=%d, APP_len=%d, "
576 "COM_len=%d, jpeg_markers=0x%x\n",
581 static void v4l_print_enc_idx(
const void *arg,
bool write_only)
585 pr_cont(
"entries=%d, entries_cap=%d\n",
589 static void v4l_print_encoder_cmd(
const void *arg,
bool write_only)
593 pr_cont(
"cmd=%d, flags=0x%x\n",
597 static void v4l_print_decoder_cmd(
const void *arg,
bool write_only)
604 pr_info(
"speed=%d, format=%u\n",
610 static void v4l_print_dbg_chip_ident(
const void *arg,
bool write_only)
619 pr_cont(
"chip_ident=%u, revision=0x%x\n",
623 static void v4l_print_dbg_register(
const void *arg,
bool write_only)
632 pr_cont(
"reg=0x%llx, val=0x%llx\n",
636 static void v4l_print_dv_enum_presets(
const void *arg,
bool write_only)
640 pr_cont(
"index=%u, preset=%u, name=%s, width=%u, height=%u\n",
644 static void v4l_print_dv_preset(
const void *arg,
bool write_only)
651 static void v4l_print_dv_timings(
const void *arg,
bool write_only)
657 pr_cont(
"type=bt-656/1120, interlaced=%u, "
659 "width=%u, height=%u, polarities=0x%x, "
660 "hfrontporch=%u, hsync=%u, "
661 "hbackporch=%u, vfrontporch=%u, "
662 "vsync=%u, vbackporch=%u, "
663 "il_vfrontporch=%u, il_vsync=%u, "
664 "il_vbackporch=%u, standards=0x%x, flags=0x%x\n",
665 p->
bt.interlaced, p->
bt.pixelclock,
666 p->
bt.width, p->
bt.height,
667 p->
bt.polarities, p->
bt.hfrontporch,
668 p->
bt.hsync, p->
bt.hbackporch,
669 p->
bt.vfrontporch, p->
bt.vsync,
670 p->
bt.vbackporch, p->
bt.il_vfrontporch,
671 p->
bt.il_vsync, p->
bt.il_vbackporch,
672 p->
bt.standards, p->
bt.flags);
680 static void v4l_print_enum_dv_timings(
const void *arg,
bool write_only)
685 v4l_print_dv_timings(&p->
timings, write_only);
688 static void v4l_print_dv_timings_cap(
const void *arg,
bool write_only)
694 pr_cont(
"type=bt-656/1120, width=%u-%u, height=%u-%u, "
695 "pixelclock=%llu-%llu, standards=0x%x, capabilities=0x%x\n",
696 p->
bt.min_width, p->
bt.max_width,
697 p->
bt.min_height, p->
bt.max_height,
698 p->
bt.min_pixelclock, p->
bt.max_pixelclock,
699 p->
bt.standards, p->
bt.capabilities);
707 static void v4l_print_frmsizeenum(
const void *arg,
bool write_only)
711 pr_cont(
"index=%u, pixelformat=%c%c%c%c, type=%u",
724 pr_cont(
" min=%ux%u, max=%ux%u, step=%ux%u\n",
737 static void v4l_print_frmivalenum(
const void *arg,
bool write_only)
741 pr_cont(
"index=%u, pixelformat=%c%c%c%c, wxh=%ux%u, type=%u",
755 pr_cont(
" min=%d/%d, max=%d/%d, step=%d/%d\n",
771 static void v4l_print_event(
const void *arg,
bool write_only)
776 pr_cont(
"type=0x%x, pending=%u, sequence=%u, id=%u, "
777 "timestamp=%lu.%9.9lu\n",
793 pr_cont(
"flags=0x%x, minimum=%d, maximum=%d, step=%d,"
794 " default_value=%d\n",
805 static void v4l_print_event_subscription(
const void *arg,
bool write_only)
809 pr_cont(
"type=0x%x, id=0x%x, flags=0x%x\n",
813 static void v4l_print_sliced_vbi_cap(
const void *arg,
bool write_only)
818 pr_cont(
"type=%s, service_set=0x%08x\n",
820 for (i = 0; i < 24; i++)
826 static void v4l_print_freq_band(
const void *arg,
bool write_only)
830 pr_cont(
"tuner=%u, type=%u, index=%u, capability=0x%x, "
831 "rangelow=%u, rangehigh=%u, modulation=0x%x\n",
837 static void v4l_print_u32(
const void *arg,
bool write_only)
842 static void v4l_print_newline(
const void *arg,
bool write_only)
847 static void v4l_print_default(
const void *arg,
bool write_only)
849 pr_cont(
"driver-specific ioctl\n");
858 for (i = 0; i < c->
count; i++)
869 for (i = 0; i < c->
count; i++) {
892 if (is_vid && is_rx &&
905 if (is_vid && is_tx &&
940 struct file *file,
void *fh,
void *arg)
944 cap->
version = LINUX_VERSION_CODE;
949 struct file *file,
void *fh,
void *arg)
955 struct file *file,
void *fh,
void *arg)
961 struct file *file,
void *fh,
void *arg)
974 struct file *file,
void *fh,
void *arg)
988 struct file *file,
void *fh,
void *arg)
1009 struct file *file,
void *fh,
void *arg)
1030 struct file *file,
void *fh,
void *arg)
1063 struct file *file,
void *fh,
void *arg)
1117 struct file *file,
void *fh,
void *arg)
1181 struct file *file,
void *fh,
void *arg)
1245 struct file *file,
void *fh,
void *arg)
1251 struct file *file,
void *fh,
void *arg)
1257 struct file *file,
void *fh,
void *arg)
1272 struct file *file,
void *fh,
void *arg)
1283 struct file *file,
void *fh,
void *arg)
1295 struct file *file,
void *fh,
void *arg)
1306 struct file *file,
void *fh,
void *arg)
1314 if (p->
type != type)
1320 struct file *file,
void *fh,
void *arg)
1326 const char *
descr =
"";
1334 for (i = 0; i <= index &&
id; i++) {
1337 while ((
id & standards[j].
std) != standards[j].std)
1339 curr_id = standards[
j].
std;
1340 descr = standards[
j].
descr;
1357 struct file *file,
void *fh,
void *arg)
1373 struct file *file,
void *fh,
void *arg)
1393 struct file *file,
void *fh,
void *arg)
1411 struct file *file,
void *fh,
void *arg)
1419 if (p->
type != type)
1425 struct file *file,
void *fh,
void *arg)
1431 struct file *file,
void *fh,
void *arg)
1434 int ret = check_fmt(file, p->
type);
1445 struct file *file,
void *fh,
void *arg)
1448 int ret = check_fmt(file, p->
type);
1454 struct file *file,
void *fh,
void *arg)
1457 int ret = check_fmt(file, p->
type);
1463 struct file *file,
void *fh,
void *arg)
1466 int ret = check_fmt(file, p->
type);
1472 struct file *file,
void *fh,
void *arg)
1475 int ret = check_fmt(file, create->
format.type);
1481 struct file *file,
void *fh,
void *arg)
1484 int ret = check_fmt(file, b->
type);
1490 struct file *file,
void *fh,
void *arg)
1495 int ret = check_fmt(file, p->
type);
1515 struct file *file,
void *fh,
void *arg)
1518 int ret = check_fmt(file, p->
type);
1524 struct file *file,
void *fh,
void *arg)
1541 struct file *file,
void *fh,
void *arg)
1558 struct file *file,
void *fh,
void *arg)
1578 ctrls.controls = &
ctrl;
1581 if (check_ext_ctrls(&ctrls, 1)) {
1592 struct file *file,
void *fh,
void *arg)
1612 ctrls.controls = &
ctrl;
1615 if (check_ext_ctrls(&ctrls, 1))
1621 struct file *file,
void *fh,
void *arg)
1640 struct file *file,
void *fh,
void *arg)
1659 struct file *file,
void *fh,
void *arg)
1678 struct file *file,
void *fh,
void *arg)
1705 struct file *file,
void *fh,
void *arg)
1727 struct file *file,
void *fh,
void *arg)
1765 struct file *file,
void *fh,
void *arg)
1771 pr_info(
"%s: ================= START STATUS =================\n",
1775 pr_info(
"%s: ================== END STATUS ==================\n",
1781 struct file *file,
void *fh,
void *arg)
1783 #ifdef CONFIG_VIDEO_ADV_DEBUG
1788 return ops->vidioc_g_register(file, fh, p);
1795 struct file *file,
void *fh,
void *arg)
1797 #ifdef CONFIG_VIDEO_ADV_DEBUG
1802 return ops->vidioc_s_register(file, fh, p);
1808 static int v4l_dbg_g_chip_ident(
const struct v4l2_ioctl_ops *ops,
1809 struct file *file,
void *fh,
void *arg)
1819 struct file *file,
void *fh,
void *arg)
1825 struct file *file,
void *fh,
void *arg)
1830 static int v4l_unsubscribe_event(
const struct v4l2_ioctl_ops *ops,
1831 struct file *file,
void *fh,
void *arg)
1836 static int v4l_g_sliced_vbi_cap(
const struct v4l2_ioctl_ops *ops,
1837 struct file *file,
void *fh,
void *arg)
1840 int ret = check_fmt(file, p->
type);
1852 struct file *file,
void *fh,
void *arg)
1862 if (type != p->
type)
1913 struct file *
file,
void *fh,
void *
p);
1919 #define INFO_FL_PRIO (1 << 0)
1921 #define INFO_FL_CTRL (1 << 1)
1923 #define INFO_FL_STD (1 << 2)
1925 #define INFO_FL_FUNC (1 << 3)
1927 #define INFO_FL_QUEUE (1 << 4)
1929 #define INFO_FL_CLEAR(v4l2_struct, field) \
1930 ((offsetof(struct v4l2_struct, field) + \
1931 sizeof(((struct v4l2_struct *)0)->field)) << 16)
1932 #define INFO_FL_CLEAR_MASK (_IOC_SIZEMASK << 16)
1934 #define IOCTL_INFO_STD(_ioctl, _vidioc, _debug, _flags) \
1935 [_IOC_NR(_ioctl)] = { \
1937 .flags = _flags | INFO_FL_STD, \
1939 .u.offset = offsetof(struct v4l2_ioctl_ops, _vidioc), \
1943 #define IOCTL_INFO_FNC(_ioctl, _func, _debug, _flags) \
1944 [_IOC_NR(_ioctl)] = { \
1946 .flags = _flags | INFO_FL_FUNC, \
2036 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
2053 return vdev->
queue->lock;
2087 default: dir =
"*ERR*";
break;
2089 pr_cont(
"%s ioctl '%c', dir=%s, #%d (0x%08x)",
2094 static long __video_do_ioctl(
struct file *file,
2095 unsigned int cmd,
void *arg)
2099 bool write_only =
false;
2104 int use_fh_prio = 0;
2109 pr_warn(
"%s: has no ioctl_ops.\n",
2110 video_device_node_name(vfd));
2120 info = &v4l2_ioctls[
_IOC_NR(cmd)];
2132 default_info.ioctl =
cmd;
2133 default_info.flags = 0;
2134 default_info.debug = v4l_print_default;
2135 info = &default_info;
2142 info->
debug(arg, write_only);
2145 typedef int (*vidioc_op)(
struct file *
file,
void *fh,
void *
p);
2147 const vidioc_op *vidioc = p + info->
u.
offset;
2149 ret = (*vidioc)(
file, fh,
arg);
2151 ret = info->
u.
func(ops, file, fh, arg);
2165 video_device_node_name(vfd), ret);
2170 pr_cont(
": error %ld\n", ret);
2174 info->
debug(arg, write_only);
2177 info->
debug(arg, write_only);
2184 static int check_array_args(
unsigned int cmd,
void *parg,
size_t *array_size,
2185 void * __user *user_ptr,
void ***kernel_ptr)
2202 *kernel_ptr = (
void *)&buf->
m.
planes;
2211 struct v4l2_subdev_edid *
edid = parg;
2214 if (edid->blocks > 256) {
2218 *user_ptr = (
void __user *)edid->edid;
2219 *kernel_ptr = (
void *)&edid->edid;
2220 *array_size = edid->blocks * 128;
2231 if (ctrls->
count != 0) {
2237 *kernel_ptr = (
void *)&ctrls->
controls;
2255 void *parg = (
void *)arg;
2257 bool has_array_args;
2258 size_t array_size = 0;
2260 void **kernel_ptr =
NULL;
2303 err = check_array_args(cmd, parg, &array_size, &user_ptr, &kernel_ptr);
2306 has_array_args =
err;
2308 if (has_array_args) {
2318 goto out_array_args;
2321 goto out_array_args;
2326 err =
func(file, cmd, parg);
2330 if (has_array_args) {
2331 *kernel_ptr = user_ptr;
2334 goto out_array_args;
2358 unsigned int cmd,
unsigned long arg)