v4l2_ioctl调用过程

本文详细解析了V4L2框架中v4l2_ioctl调用的过程,从应用层到驱动层,介绍了函数定义及回调函数的作用,强调了结构体在V4L2操作中的核心地位,通过该结构体执行各种命令,明确了ioctl调用的流程。
摘要由CSDN通过智能技术生成

v4l2_ioctl调用过程

在这里插入图片描述

应用层:

ioctl(dev->fd, VIDIOC_DQBUF, &buf))
ioctl(dev->fd, VIDIOC_QBUF, &buf)

驱动层:

v4L2_fops.unlocked_ioctl
-->.v4L2_ioctl
	-->vdev = video_devdata(filp);
	   vdev->fops->unlocked_ioctl(filp, cmd, arg);//调用设备提供的unlocked_ioctl 如果是uvc则指向.unlocked_ioctl= video_ioctl2
	   video_ioctl2//函数位置为kernel\drivers\media\v4l2-core\v4l2-ioctl.c
	   		-->video_usercopy(file, cmd, arg, __video_do_ioctl)//__video_do_ioctl为一个回调函数,在video_usercopy中调用
				-->__video_do_ioctl

video_usercopy函数定义如下:

long video_usercopy(struct file *file, unsigned int cmd, unsigned long arg, v4l2_kioctl func)
{
   ......
    if (v4l2_is_known_ioctl(cmd)) {
   //检查cmd是否支持
        u32 flags = v4l2_ioctls[_IOC_NR(cmd)].flags;
        if (flags & INFO_FL_CLEAR_MASK)
            n = (flags & INFO_FL_CLEAR_MASK) >> 16;
	}
    if (copy_from_user(parg, (void __user *)arg, n))//从用户空间拷贝数据到内核空间
        goto out;
 	/* Handles IOCTL */
	err = func(file, cmd, parg);//执行对应的ioctl操作就对应到__video_do_ioctl
	if (err == -ENOTTY || err == -ENOIOCTLCMD) {
   
		err = -ENOTTY;
		goto out;
	}
 	if (has_array_args) {
   
		*kernel_ptr = (void __force *)user_ptr;
		if (copy_to_user(user_ptr, mbuf, array_size))//将数据拷贝回到用户空间
			err = -EFAULT;
		goto out_array_args;
	}
 ......
}

回调函数__video_do_ioctl定义如下:

static long __video_do_ioctl(struct file *file,
		unsigned int cmd, void *arg)
{
   ......
	if (ops == NULL) {
   
		pr_warn("%s: has no ioctl_ops.\n",
				video_device_node_name(vfd));
		return ret;
	}
	if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags))
		vfh = file->private_data;
	if (v4l2_is_known_ioctl(cmd)) {
   //这个函数没啥好讲的,看着就是判定cmd是否在当前所有支持的里面。
		info = &v4l2_ioctls[_IOC_NR(cmd)];//获取对应cmd的info参数
		if (!test_bit(_IOC_NR(cmd), vfd->valid_ioctls) &&
		    !((
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

nineyole

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值