aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/video4linux
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2012-07-02 04:43:34 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-07-06 16:36:46 -0400
commit4a77a8361fe79b78b741640b484a97c8d47e307f (patch)
treee862f23184f8764d174dbc7f8d932d70aff0f5c4 /Documentation/video4linux
parent387c71b262a7a62d271dc9deb00c173264e33357 (diff)
[media] v4l2-framework.txt: Update the locking documentation
This documents the new queue->lock and how to use it. It also removes the documentation of v4l2_disable_ioctl_locking: this is only used in gspca and will be removed once gspca has been converted to vb2. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'Documentation/video4linux')
-rw-r--r--Documentation/video4linux/v4l2-framework.txt73
1 files changed, 39 insertions, 34 deletions
diff --git a/Documentation/video4linux/v4l2-framework.txt b/Documentation/video4linux/v4l2-framework.txt
index 1f5905270050..89318be6c1d2 100644
--- a/Documentation/video4linux/v4l2-framework.txt
+++ b/Documentation/video4linux/v4l2-framework.txt
@@ -594,6 +594,15 @@ You should also set these fields:
594 unlocked_ioctl file operation is called this lock will be taken by the 594 unlocked_ioctl file operation is called this lock will be taken by the
595 core and released afterwards. See the next section for more details. 595 core and released afterwards. See the next section for more details.
596 596
597- queue: a pointer to the struct vb2_queue associated with this device node.
598 If queue is non-NULL, and queue->lock is non-NULL, then queue->lock is
599 used for the queuing ioctls (VIDIOC_REQBUFS, CREATE_BUFS, QBUF, DQBUF,
600 QUERYBUF, PREPARE_BUF, STREAMON and STREAMOFF) instead of the lock above.
601 That way the vb2 queuing framework does not have to wait for other ioctls.
602 This queue pointer is also used by the vb2 helper functions to check for
603 queuing ownership (i.e. is the filehandle calling it allowed to do the
604 operation).
605
597- prio: keeps track of the priorities. Used to implement VIDIOC_G/S_PRIORITY. 606- prio: keeps track of the priorities. Used to implement VIDIOC_G/S_PRIORITY.
598 If left to NULL, then it will use the struct v4l2_prio_state in v4l2_device. 607 If left to NULL, then it will use the struct v4l2_prio_state in v4l2_device.
599 If you want to have a separate priority state per (group of) device node(s), 608 If you want to have a separate priority state per (group of) device node(s),
@@ -647,47 +656,43 @@ manually set the struct media_entity type and name fields.
647A reference to the entity will be automatically acquired/released when the 656A reference to the entity will be automatically acquired/released when the
648video device is opened/closed. 657video device is opened/closed.
649 658
650v4l2_file_operations and locking 659ioctls and locking
651-------------------------------- 660------------------
652
653You can set a pointer to a mutex_lock in struct video_device. Usually this
654will be either a top-level mutex or a mutex per device node. By default this
655lock will be used for unlocked_ioctl, but you can disable locking for
656selected ioctls by calling:
657
658 void v4l2_disable_ioctl_locking(struct video_device *vdev, unsigned int cmd);
659
660E.g.: v4l2_disable_ioctl_locking(vdev, VIDIOC_DQBUF);
661 661
662You have to call this before you register the video_device. 662The V4L core provides optional locking services. The main service is the
663lock field in struct video_device, which is a pointer to a mutex. If you set
664this pointer, then that will be used by unlocked_ioctl to serialize all ioctls.
663 665
664Particularly with USB drivers where certain commands such as setting controls 666If you are using the videobuf2 framework, then there is a second lock that you
665can take a long time you may want to do your own locking for the buffer queuing 667can set: video_device->queue->lock. If set, then this lock will be used instead
666ioctls. 668of video_device->lock to serialize all queuing ioctls (see the previous section
669for the full list of those ioctls).
667 670
668If you want still finer-grained locking then you have to set mutex_lock to NULL 671The advantage of using a different lock for the queuing ioctls is that for some
669and do you own locking completely. 672drivers (particularly USB drivers) certain commands such as setting controls
673can take a long time, so you want to use a separate lock for the buffer queuing
674ioctls. That way your VIDIOC_DQBUF doesn't stall because the driver is busy
675changing the e.g. exposure of the webcam.
670 676
671It is up to the driver developer to decide which method to use. However, if 677Of course, you can always do all the locking yourself by leaving both lock
672your driver has high-latency operations (for example, changing the exposure 678pointers at NULL.
673of a USB webcam might take a long time), then you might be better off with
674doing your own locking if you want to allow the user to do other things with
675the device while waiting for the high-latency command to finish.
676 679
677If a lock is specified then all ioctl commands will be serialized on that 680If you use the old videobuf then you must pass the video_device lock to the
678lock. If you use videobuf then you must pass the same lock to the videobuf 681videobuf queue initialize function: if videobuf has to wait for a frame to
679queue initialize function: if videobuf has to wait for a frame to arrive, then 682arrive, then it will temporarily unlock the lock and relock it afterwards. If
680it will temporarily unlock the lock and relock it afterwards. If your driver 683your driver also waits in the code, then you should do the same to allow other
681also waits in the code, then you should do the same to allow other processes 684processes to access the device node while the first process is waiting for
682to access the device node while the first process is waiting for something. 685something.
683 686
684In the case of videobuf2 you will need to implement the wait_prepare and 687In the case of videobuf2 you will need to implement the wait_prepare and
685wait_finish callbacks to unlock/lock if applicable. In particular, if you use 688wait_finish callbacks to unlock/lock if applicable. If you use the queue->lock
686the lock in struct video_device then you must unlock/lock this mutex in 689pointer, then you can use the helper functions vb2_ops_wait_prepare/finish.
687wait_prepare and wait_finish. 690
688 691The implementation of a hotplug disconnect should also take the lock from
689The implementation of a hotplug disconnect should also take the lock before 692video_device before calling v4l2_device_disconnect. If you are also using
690calling v4l2_device_disconnect. 693video_device->queue->lock, then you have to first lock video_device->queue->lock
694followed by video_device->lock. That way you can be sure no ioctl is running
695when you call v4l2_device_disconnect.
691 696
692video_device registration 697video_device registration
693------------------------- 698-------------------------