All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/7] [RFC] Move VIDIOC_G/S_PRIORITY handling to the V4L core
@ 2010-05-09 19:29 Hans Verkuil
  2010-05-09 19:29 ` [PATCH 1/7] [RFC] v4l2_prio: move from v4l2-common to v4l2-device Hans Verkuil
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Hans Verkuil @ 2010-05-09 19:29 UTC (permalink / raw)
  To: linux-media

Few drivers implement VIDIOC_G/S_PRIORITY and those that do often implement
it incorrectly.

Now that we have a v4l2_fh struct it is easy to add support for priority
handling to the v4l core framework.

There are three types of drivers:

1) Those that use v4l2_fh. There the local priority can be stored in the
   v4l2_fh struct.

2) Those that do not have an open or release function defined in v4l2_file_ops.
   That means that file->private_data will never be filled and so we can use
   that to store the local priority in.

3) Others. In all other cases we leave it to the driver. Of course, the goal is
   to eventually move the 'others' into type 1 or 2.

This patch series shows how it is done and converts ivtv to rely on the core
framework instead of doing it manually.

Comments?

Regards,

	Hans

Hans Verkuil (7):
  v4l2_prio: move from v4l2-common to v4l2-device.
  v4l2-device: add v4l2_prio_state to v4l2_device.
  v4l2-fh: implement v4l2_priority support.
  v4l2-dev: add and support flag V4L2_FH_USE_PRIO.
  v4l2-ioctl: add priority handling support.
  ivtv: drop priority handling, use core framework for this.
  ivtv: add priority checks for the non-standard commands.

 drivers/media/video/cpia2/cpia2.h          |    1 +
 drivers/media/video/ivtv/ivtv-driver.h     |    2 -
 drivers/media/video/ivtv/ivtv-fileops.c    |    2 -
 drivers/media/video/ivtv/ivtv-ioctl.c      |   61 ++++++++------------------
 drivers/media/video/pvrusb2/pvrusb2-v4l2.c |    1 +
 drivers/media/video/v4l2-common.c          |   59 -------------------------
 drivers/media/video/v4l2-dev.c             |   23 +++++++++-
 drivers/media/video/v4l2-device.c          |   62 +++++++++++++++++++++++++++
 drivers/media/video/v4l2-fh.c              |    4 ++
 drivers/media/video/v4l2-ioctl.c           |   64 +++++++++++++++++++++++++---
 include/media/v4l2-common.h                |   15 -------
 include/media/v4l2-dev.h                   |    6 +++
 include/media/v4l2-device.h                |   17 +++++++
 include/media/v4l2-fh.h                    |    1 +
 14 files changed, 190 insertions(+), 128 deletions(-)


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/7] [RFC] v4l2_prio: move from v4l2-common to v4l2-device.
  2010-05-09 19:29 [PATCH 0/7] [RFC] Move VIDIOC_G/S_PRIORITY handling to the V4L core Hans Verkuil
@ 2010-05-09 19:29 ` Hans Verkuil
  2010-05-09 19:29 ` [PATCH 2/7] [RFC] v4l2-device: add v4l2_prio_state to v4l2_device Hans Verkuil
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Hans Verkuil @ 2010-05-09 19:29 UTC (permalink / raw)
  To: linux-media

We are going to move priority handling into the v4l2 core. As a consequence
the v4l2_prio helper functions need to be moved into the core videodev
module as well to prevent circular dependencies.

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
---
 drivers/media/video/cpia2/cpia2.h          |    1 +
 drivers/media/video/pvrusb2/pvrusb2-v4l2.c |    1 +
 drivers/media/video/v4l2-common.c          |   59 ---------------------------
 drivers/media/video/v4l2-device.c          |   61 ++++++++++++++++++++++++++++
 include/media/v4l2-common.h                |   15 -------
 include/media/v4l2-device.h                |   15 +++++++
 6 files changed, 78 insertions(+), 74 deletions(-)

diff --git a/drivers/media/video/cpia2/cpia2.h b/drivers/media/video/cpia2/cpia2.h
index 8d2dfc1..4e2f623 100644
--- a/drivers/media/video/cpia2/cpia2.h
+++ b/drivers/media/video/cpia2/cpia2.h
@@ -33,6 +33,7 @@
 
 #include <linux/version.h>
 #include <linux/videodev.h>
+#include <media/v4l2-device.h>
 #include <media/v4l2-common.h>
 #include <linux/usb.h>
 #include <linux/poll.h>
diff --git a/drivers/media/video/pvrusb2/pvrusb2-v4l2.c b/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
index 338bcc6..9b521f2 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
@@ -29,6 +29,7 @@
 #include "pvrusb2-ioread.h"
 #include <linux/videodev2.h>
 #include <media/v4l2-dev.h>
+#include <media/v4l2-device.h>
 #include <media/v4l2-common.h>
 #include <media/v4l2-ioctl.h>
 
diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c
index 4e53b0b..b53c497 100644
--- a/drivers/media/video/v4l2-common.c
+++ b/drivers/media/video/v4l2-common.c
@@ -81,65 +81,6 @@ MODULE_LICENSE("GPL");
  */
 
 
-/* ----------------------------------------------------------------- */
-/* priority handling                                                 */
-
-#define V4L2_PRIO_VALID(val) (val == V4L2_PRIORITY_BACKGROUND   || \
-			      val == V4L2_PRIORITY_INTERACTIVE  || \
-			      val == V4L2_PRIORITY_RECORD)
-
-void v4l2_prio_init(struct v4l2_prio_state *global)
-{
-	memset(global, 0, sizeof(*global));
-}
-EXPORT_SYMBOL(v4l2_prio_init);
-
-int v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local,
-		     enum v4l2_priority new)
-{
-	if (!V4L2_PRIO_VALID(new))
-		return -EINVAL;
-	if (*local == new)
-		return 0;
-
-	atomic_inc(&global->prios[new]);
-	if (V4L2_PRIO_VALID(*local))
-		atomic_dec(&global->prios[*local]);
-	*local = new;
-	return 0;
-}
-EXPORT_SYMBOL(v4l2_prio_change);
-
-void v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local)
-{
-	v4l2_prio_change(global, local, V4L2_PRIORITY_DEFAULT);
-}
-EXPORT_SYMBOL(v4l2_prio_open);
-
-void v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority local)
-{
-	if (V4L2_PRIO_VALID(local))
-		atomic_dec(&global->prios[local]);
-}
-EXPORT_SYMBOL(v4l2_prio_close);
-
-enum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global)
-{
-	if (atomic_read(&global->prios[V4L2_PRIORITY_RECORD]) > 0)
-		return V4L2_PRIORITY_RECORD;
-	if (atomic_read(&global->prios[V4L2_PRIORITY_INTERACTIVE]) > 0)
-		return V4L2_PRIORITY_INTERACTIVE;
-	if (atomic_read(&global->prios[V4L2_PRIORITY_BACKGROUND]) > 0)
-		return V4L2_PRIORITY_BACKGROUND;
-	return V4L2_PRIORITY_UNSET;
-}
-EXPORT_SYMBOL(v4l2_prio_max);
-
-int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local)
-{
-	return (local < v4l2_prio_max(global)) ? -EBUSY : 0;
-}
-EXPORT_SYMBOL(v4l2_prio_check);
 
 /* ----------------------------------------------------------------- */
 
diff --git a/drivers/media/video/v4l2-device.c b/drivers/media/video/v4l2-device.c
index 5a7dc4a..2386ae6 100644
--- a/drivers/media/video/v4l2-device.c
+++ b/drivers/media/video/v4l2-device.c
@@ -142,3 +142,64 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd)
 	module_put(sd->owner);
 }
 EXPORT_SYMBOL_GPL(v4l2_device_unregister_subdev);
+
+/* ----------------------------------------------------------------- */
+
+/* priority handling helper functions */
+
+#define V4L2_PRIO_VALID(val) (val == V4L2_PRIORITY_BACKGROUND   || \
+			      val == V4L2_PRIORITY_INTERACTIVE  || \
+			      val == V4L2_PRIORITY_RECORD)
+
+void v4l2_prio_init(struct v4l2_prio_state *global)
+{
+	memset(global, 0, sizeof(*global));
+}
+EXPORT_SYMBOL(v4l2_prio_init);
+
+int v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local,
+		     enum v4l2_priority new)
+{
+	if (!V4L2_PRIO_VALID(new))
+		return -EINVAL;
+	if (*local == new)
+		return 0;
+
+	atomic_inc(&global->prios[new]);
+	if (V4L2_PRIO_VALID(*local))
+		atomic_dec(&global->prios[*local]);
+	*local = new;
+	return 0;
+}
+EXPORT_SYMBOL(v4l2_prio_change);
+
+void v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local)
+{
+	v4l2_prio_change(global, local, V4L2_PRIORITY_DEFAULT);
+}
+EXPORT_SYMBOL(v4l2_prio_open);
+
+void v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority local)
+{
+	if (V4L2_PRIO_VALID(local))
+		atomic_dec(&global->prios[local]);
+}
+EXPORT_SYMBOL(v4l2_prio_close);
+
+enum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global)
+{
+	if (atomic_read(&global->prios[V4L2_PRIORITY_RECORD]) > 0)
+		return V4L2_PRIORITY_RECORD;
+	if (atomic_read(&global->prios[V4L2_PRIORITY_INTERACTIVE]) > 0)
+		return V4L2_PRIORITY_INTERACTIVE;
+	if (atomic_read(&global->prios[V4L2_PRIORITY_BACKGROUND]) > 0)
+		return V4L2_PRIORITY_BACKGROUND;
+	return V4L2_PRIORITY_UNSET;
+}
+EXPORT_SYMBOL(v4l2_prio_max);
+
+int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local)
+{
+	return (local < v4l2_prio_max(global)) ? -EBUSY : 0;
+}
+EXPORT_SYMBOL(v4l2_prio_check);
diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h
index 98b3264..e086917 100644
--- a/include/media/v4l2-common.h
+++ b/include/media/v4l2-common.h
@@ -80,21 +80,6 @@
 
 /* ------------------------------------------------------------------------- */
 
-/* Priority helper functions */
-
-struct v4l2_prio_state {
-	atomic_t prios[4];
-};
-void v4l2_prio_init(struct v4l2_prio_state *global);
-int v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local,
-		     enum v4l2_priority new);
-void v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local);
-void v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority local);
-enum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global);
-int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local);
-
-/* ------------------------------------------------------------------------- */
-
 /* Control helper functions */
 
 int v4l2_ctrl_check(struct v4l2_ext_control *ctrl, struct v4l2_queryctrl *qctrl,
diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
index 5d5d550..b497e53 100644
--- a/include/media/v4l2-device.h
+++ b/include/media/v4l2-device.h
@@ -23,6 +23,11 @@
 
 #include <media/v4l2-subdev.h>
 
+/* struct to keep track of the access priority state */
+struct v4l2_prio_state {
+	atomic_t prios[4];
+};
+
 /* Each instance of a V4L2 device should create the v4l2_device struct,
    either stand-alone or embedded in a larger struct.
 
@@ -49,6 +54,16 @@ struct v4l2_device {
 			unsigned int notification, void *arg);
 };
 
+/* Priority helper functions */
+
+void v4l2_prio_init(struct v4l2_prio_state *global);
+int v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local,
+		     enum v4l2_priority new);
+void v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local);
+void v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority local);
+enum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global);
+int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local);
+
 /* Initialize v4l2_dev and make dev->driver_data point to v4l2_dev.
    dev may be NULL in rare cases (ISA devices). In that case you
    must fill in the v4l2_dev->name field before calling this function. */
-- 
1.6.4.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/7] [RFC] v4l2-device: add v4l2_prio_state to v4l2_device.
  2010-05-09 19:29 [PATCH 0/7] [RFC] Move VIDIOC_G/S_PRIORITY handling to the V4L core Hans Verkuil
  2010-05-09 19:29 ` [PATCH 1/7] [RFC] v4l2_prio: move from v4l2-common to v4l2-device Hans Verkuil
@ 2010-05-09 19:29 ` Hans Verkuil
  2010-05-09 19:29 ` [PATCH 3/7] [RFC] v4l2-fh: implement v4l2_priority support Hans Verkuil
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Hans Verkuil @ 2010-05-09 19:29 UTC (permalink / raw)
  To: linux-media

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
---
 drivers/media/video/v4l2-device.c |    1 +
 include/media/v4l2-device.h       |    2 ++
 2 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/drivers/media/video/v4l2-device.c b/drivers/media/video/v4l2-device.c
index 2386ae6..86ce0c9 100644
--- a/drivers/media/video/v4l2-device.c
+++ b/drivers/media/video/v4l2-device.c
@@ -34,6 +34,7 @@ int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev)
 
 	INIT_LIST_HEAD(&v4l2_dev->subdevs);
 	spin_lock_init(&v4l2_dev->lock);
+	v4l2_prio_init(&v4l2_dev->prio);
 	v4l2_dev->dev = dev;
 	if (dev == NULL) {
 		/* If dev == NULL, then name must be filled in by the caller */
diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
index b497e53..322c377 100644
--- a/include/media/v4l2-device.h
+++ b/include/media/v4l2-device.h
@@ -49,6 +49,8 @@ struct v4l2_device {
 	spinlock_t lock;
 	/* unique device name, by default the driver name + bus ID */
 	char name[V4L2_DEVICE_NAME_SIZE];
+	/* Device's priority state */
+	struct v4l2_prio_state prio;
 	/* notify callback called by some sub-devices. */
 	void (*notify)(struct v4l2_subdev *sd,
 			unsigned int notification, void *arg);
-- 
1.6.4.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/7] [RFC] v4l2-fh: implement v4l2_priority support.
  2010-05-09 19:29 [PATCH 0/7] [RFC] Move VIDIOC_G/S_PRIORITY handling to the V4L core Hans Verkuil
  2010-05-09 19:29 ` [PATCH 1/7] [RFC] v4l2_prio: move from v4l2-common to v4l2-device Hans Verkuil
  2010-05-09 19:29 ` [PATCH 2/7] [RFC] v4l2-device: add v4l2_prio_state to v4l2_device Hans Verkuil
@ 2010-05-09 19:29 ` Hans Verkuil
  2010-05-09 19:29 ` [PATCH 4/7] [RFC] v4l2-dev: add and support flag V4L2_FH_USE_PRIO Hans Verkuil
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Hans Verkuil @ 2010-05-09 19:29 UTC (permalink / raw)
  To: linux-media

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
---
 drivers/media/video/v4l2-fh.c |    4 ++++
 include/media/v4l2-fh.h       |    1 +
 2 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/drivers/media/video/v4l2-fh.c b/drivers/media/video/v4l2-fh.c
index d78f184..d57908a 100644
--- a/drivers/media/video/v4l2-fh.c
+++ b/drivers/media/video/v4l2-fh.c
@@ -27,12 +27,14 @@
 #include <media/v4l2-fh.h>
 #include <media/v4l2-event.h>
 #include <media/v4l2-ioctl.h>
+#include <media/v4l2-device.h>
 
 int v4l2_fh_init(struct v4l2_fh *fh, struct video_device *vdev)
 {
 	fh->vdev = vdev;
 	INIT_LIST_HEAD(&fh->list);
 	set_bit(V4L2_FL_USES_V4L2_FH, &fh->vdev->flags);
+	fh->prio = V4L2_PRIORITY_UNSET;
 
 	/*
 	 * fh->events only needs to be initialized if the driver
@@ -51,6 +53,7 @@ void v4l2_fh_add(struct v4l2_fh *fh)
 {
 	unsigned long flags;
 
+	v4l2_prio_open(&fh->vdev->v4l2_dev->prio, &fh->prio);
 	spin_lock_irqsave(&fh->vdev->fh_lock, flags);
 	list_add(&fh->list, &fh->vdev->fh_list);
 	spin_unlock_irqrestore(&fh->vdev->fh_lock, flags);
@@ -64,6 +67,7 @@ void v4l2_fh_del(struct v4l2_fh *fh)
 	spin_lock_irqsave(&fh->vdev->fh_lock, flags);
 	list_del_init(&fh->list);
 	spin_unlock_irqrestore(&fh->vdev->fh_lock, flags);
+	v4l2_prio_close(&fh->vdev->v4l2_dev->prio, fh->prio);
 }
 EXPORT_SYMBOL_GPL(v4l2_fh_del);
 
diff --git a/include/media/v4l2-fh.h b/include/media/v4l2-fh.h
index 1d72dde..ff513fe 100644
--- a/include/media/v4l2-fh.h
+++ b/include/media/v4l2-fh.h
@@ -35,6 +35,7 @@ struct v4l2_fh {
 	struct list_head	list;
 	struct video_device	*vdev;
 	struct v4l2_events      *events; /* events, pending and subscribed */
+	enum v4l2_priority 	prio;
 };
 
 /*
-- 
1.6.4.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 4/7] [RFC] v4l2-dev: add and support flag V4L2_FH_USE_PRIO.
  2010-05-09 19:29 [PATCH 0/7] [RFC] Move VIDIOC_G/S_PRIORITY handling to the V4L core Hans Verkuil
                   ` (2 preceding siblings ...)
  2010-05-09 19:29 ` [PATCH 3/7] [RFC] v4l2-fh: implement v4l2_priority support Hans Verkuil
@ 2010-05-09 19:29 ` Hans Verkuil
  2010-05-09 19:29 ` [PATCH 5/7] [RFC] v4l2-ioctl: add priority handling support Hans Verkuil
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Hans Verkuil @ 2010-05-09 19:29 UTC (permalink / raw)
  To: linux-media

Flag V4L2_FH_USE_PRIO is set if we can safely store the priority level
in file->private_data. Support this flag for the open and release file
operations.

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
---
 drivers/media/video/v4l2-dev.c |   23 +++++++++++++++++++++--
 include/media/v4l2-dev.h       |    6 ++++++
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c
index 0ca7ec9..fd536ff 100644
--- a/drivers/media/video/v4l2-dev.c
+++ b/drivers/media/video/v4l2-dev.c
@@ -283,6 +283,15 @@ static int v4l2_open(struct inode *inode, struct file *filp)
 	/* and increase the device refcount */
 	video_get(vdev);
 	mutex_unlock(&videodev_lock);
+
+	if (test_bit(V4L2_FL_USES_V4L2_PRIO, &vdev->flags)) {
+		enum v4l2_priority prio =
+			(enum v4l2_priority)filp->private_data;
+
+		v4l2_prio_open(&vdev->v4l2_dev->prio, &prio);
+		filp->private_data = (void *)prio;
+	}
+
 	if (vdev->fops->open)
 		ret = vdev->fops->open(filp);
 
@@ -296,15 +305,20 @@ static int v4l2_open(struct inode *inode, struct file *filp)
 static int v4l2_release(struct inode *inode, struct file *filp)
 {
 	struct video_device *vdev = video_devdata(filp);
-	int ret = 0;
 
+	if (test_bit(V4L2_FL_USES_V4L2_PRIO, &vdev->flags)) {
+		enum v4l2_priority prio =
+			(enum v4l2_priority)filp->private_data;
+
+		v4l2_prio_close(&vdev->v4l2_dev->prio, prio);
+	}
 	if (vdev->fops->release)
 		vdev->fops->release(filp);
 
 	/* decrease the refcount unconditionally since the release()
 	   return value is ignored. */
 	video_put(vdev);
-	return ret;
+	return 0;
 }
 
 static const struct file_operations v4l2_unlocked_fops = {
@@ -515,6 +529,11 @@ static int __video_register_device(struct video_device *vdev, int type, int nr,
 	vdev->index = get_index(vdev);
 	mutex_unlock(&videodev_lock);
 
+	/* Determine if we can store v4l2_priority in file->private_data */
+	if (vdev->fops->open == NULL && vdev->fops->release == NULL &&
+	    vdev->v4l2_dev != NULL)
+		set_bit(V4L2_FL_USES_V4L2_PRIO, &vdev->flags);
+
 	/* Part 3: Initialize the character device */
 	vdev->cdev = cdev_alloc();
 	if (vdev->cdev == NULL) {
diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
index bebe44b..a116bc5 100644
--- a/include/media/v4l2-dev.h
+++ b/include/media/v4l2-dev.h
@@ -32,7 +32,13 @@ struct v4l2_device;
    Drivers can clear this flag if they want to block all future
    device access. It is cleared by video_unregister_device. */
 #define V4L2_FL_REGISTERED	(0)
+/* Flag to mark that the driver stores a pointer to struct v4l2_fh in
+   file->private_data. Is automatically detected. */
 #define V4L2_FL_USES_V4L2_FH	(1)
+/* Flag to mark that the driver stores the local v4l2_priority in
+   file->private_data. Will be used if open and release are both NULL.
+   Drivers can also set it manually. */
+#define V4L2_FL_USES_V4L2_PRIO	(2)
 
 struct v4l2_file_operations {
 	struct module *owner;
-- 
1.6.4.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 5/7] [RFC] v4l2-ioctl: add priority handling support.
  2010-05-09 19:29 [PATCH 0/7] [RFC] Move VIDIOC_G/S_PRIORITY handling to the V4L core Hans Verkuil
                   ` (3 preceding siblings ...)
  2010-05-09 19:29 ` [PATCH 4/7] [RFC] v4l2-dev: add and support flag V4L2_FH_USE_PRIO Hans Verkuil
@ 2010-05-09 19:29 ` Hans Verkuil
  2010-05-09 19:29 ` [PATCH 6/7] [RFC] ivtv: drop priority handling, use core framework for this Hans Verkuil
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Hans Verkuil @ 2010-05-09 19:29 UTC (permalink / raw)
  To: linux-media

Drivers that use either v4l2_fh or don't use filehandles at all can now
use the core framework support of g/s_priority.

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
---
 drivers/media/video/v4l2-ioctl.c |   64 ++++++++++++++++++++++++++++++++++---
 1 files changed, 58 insertions(+), 6 deletions(-)

diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
index 0395b1c..f928f80 100644
--- a/drivers/media/video/v4l2-ioctl.c
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -27,6 +27,7 @@
 #include <media/v4l2-ioctl.h>
 #include <media/v4l2-fh.h>
 #include <media/v4l2-event.h>
+#include <media/v4l2-device.h>
 #include <media/v4l2-chip-ident.h>
 
 #define dbgarg(cmd, fmt, arg...) \
@@ -611,6 +612,7 @@ static long __video_do_ioctl(struct file *file,
 {
 	struct video_device *vfd = video_devdata(file);
 	const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
+	enum v4l2_priority prio = V4L2_PRIORITY_UNSET;
 	void *fh = file->private_data;
 	long ret = -EINVAL;
 
@@ -640,6 +642,40 @@ static long __video_do_ioctl(struct file *file,
 		printk(KERN_CONT "\n");
 	}
 
+	if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags))
+		prio = ((struct v4l2_fh *)fh)->prio;
+	else if (test_bit(V4L2_FL_USES_V4L2_PRIO, &vfd->flags))
+		prio = (enum v4l2_priority)fh;
+	if (prio != V4L2_PRIORITY_UNSET) {
+		switch (cmd) {
+		case VIDIOC_S_CTRL:
+		case VIDIOC_S_STD:
+		case VIDIOC_S_INPUT:
+		case VIDIOC_S_OUTPUT:
+		case VIDIOC_S_TUNER:
+		case VIDIOC_S_FREQUENCY:
+		case VIDIOC_S_FMT:
+		case VIDIOC_S_CROP:
+		case VIDIOC_S_AUDIO:
+		case VIDIOC_S_AUDOUT:
+		case VIDIOC_S_EXT_CTRLS:
+		case VIDIOC_S_FBUF:
+		case VIDIOC_S_PRIORITY:
+		case VIDIOC_S_DV_PRESET:
+		case VIDIOC_S_DV_TIMINGS:
+		case VIDIOC_S_JPEGCOMP:
+		case VIDIOC_S_MODULATOR:
+		case VIDIOC_S_PARM:
+		case VIDIOC_S_HW_FREQ_SEEK:
+		case VIDIOC_ENCODER_CMD:
+		case VIDIOC_OVERLAY:
+			ret = v4l2_prio_check(&vfd->v4l2_dev->prio, prio);
+			if (ret)
+				goto exit_prio;
+			break;
+		}
+	}
+
 	switch (cmd) {
 
 #ifdef CONFIG_VIDEO_V4L1_COMPAT
@@ -689,9 +725,14 @@ static long __video_do_ioctl(struct file *file,
 	{
 		enum v4l2_priority *p = arg;
 
-		if (!ops->vidioc_g_priority)
-			break;
-		ret = ops->vidioc_g_priority(file, fh, p);
+		if (!ops->vidioc_g_priority) {
+			if (prio == V4L2_PRIORITY_UNSET)
+				break;
+			*p = v4l2_prio_max(&vfd->v4l2_dev->prio);
+			ret = 0;
+		} else {
+			ret = ops->vidioc_g_priority(file, fh, p);
+		}
 		if (!ret)
 			dbgarg(cmd, "priority is %d\n", *p);
 		break;
@@ -700,10 +741,20 @@ static long __video_do_ioctl(struct file *file,
 	{
 		enum v4l2_priority *p = arg;
 
-		if (!ops->vidioc_s_priority)
-			break;
+		if (!ops->vidioc_s_priority && prio == V4L2_PRIORITY_UNSET)
+				break;
 		dbgarg(cmd, "setting priority to %d\n", *p);
-		ret = ops->vidioc_s_priority(file, fh, *p);
+		if (ops->vidioc_s_priority) {
+			ret = ops->vidioc_s_priority(file, fh, *p);
+		} else {
+			ret = v4l2_prio_change(&vfd->v4l2_dev->prio, &prio, *p);
+			if (!ret) {
+				if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags))
+					((struct v4l2_fh *)fh)->prio = prio;
+				else
+					file->private_data = (void *)prio;
+			}
+		}
 		break;
 	}
 
@@ -2010,6 +2061,7 @@ static long __video_do_ioctl(struct file *file,
 	}
 	} /* switch */
 
+exit_prio:
 	if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
 		if (ret < 0) {
 			v4l_print_ioctl(vfd->name, cmd);
-- 
1.6.4.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 6/7] [RFC] ivtv: drop priority handling, use core framework for this.
  2010-05-09 19:29 [PATCH 0/7] [RFC] Move VIDIOC_G/S_PRIORITY handling to the V4L core Hans Verkuil
                   ` (4 preceding siblings ...)
  2010-05-09 19:29 ` [PATCH 5/7] [RFC] v4l2-ioctl: add priority handling support Hans Verkuil
@ 2010-05-09 19:29 ` Hans Verkuil
  2010-05-09 19:29 ` [PATCH 7/7] [RFC] ivtv: add priority checks for the non-standard commands Hans Verkuil
  2010-05-10 10:54 ` [PATCH 0/7] [RFC] Move VIDIOC_G/S_PRIORITY handling to the V4L core Laurent Pinchart
  7 siblings, 0 replies; 9+ messages in thread
From: Hans Verkuil @ 2010-05-09 19:29 UTC (permalink / raw)
  To: linux-media

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
---
 drivers/media/video/ivtv/ivtv-driver.h  |    2 -
 drivers/media/video/ivtv/ivtv-fileops.c |    2 -
 drivers/media/video/ivtv/ivtv-ioctl.c   |   41 -------------------------------
 3 files changed, 0 insertions(+), 45 deletions(-)

diff --git a/drivers/media/video/ivtv/ivtv-driver.h b/drivers/media/video/ivtv/ivtv-driver.h
index 584c8e0..136214c 100644
--- a/drivers/media/video/ivtv/ivtv-driver.h
+++ b/drivers/media/video/ivtv/ivtv-driver.h
@@ -379,7 +379,6 @@ struct ivtv_open_id {
 	u32 open_id;                    /* unique ID for this file descriptor */
 	int type;                       /* stream type */
 	int yuv_frames;                 /* 1: started OUT_UDMA_YUV output mode */
-	enum v4l2_priority prio;        /* priority */
 	struct ivtv *itv;
 };
 
@@ -704,7 +703,6 @@ struct ivtv {
 
 	/* Miscellaneous */
 	u32 open_id;			/* incremented each time an open occurs, is >= 1 */
-	struct v4l2_prio_state prio;    /* priority state */
 	int search_pack_header;         /* 1 if ivtv_copy_buf_to_user() is scanning for a pack header (0xba) */
 	int speed;                      /* current playback speed setting */
 	u8 speed_mute_audio;            /* 1 if audio should be muted when fast forward */
diff --git a/drivers/media/video/ivtv/ivtv-fileops.c b/drivers/media/video/ivtv/ivtv-fileops.c
index abf4109..083a586 100644
--- a/drivers/media/video/ivtv/ivtv-fileops.c
+++ b/drivers/media/video/ivtv/ivtv-fileops.c
@@ -853,7 +853,6 @@ int ivtv_v4l2_close(struct file *filp)
 
 	IVTV_DEBUG_FILE("close %s\n", s->name);
 
-	v4l2_prio_close(&itv->prio, id->prio);
 	v4l2_fh_del(fh);
 	v4l2_fh_exit(fh);
 
@@ -949,7 +948,6 @@ static int ivtv_serialized_open(struct ivtv_stream *s, struct file *filp)
 	}
 	item->itv = itv;
 	item->type = s->type;
-	v4l2_prio_open(&itv->prio, &item->prio);
 
 	item->open_id = itv->open_id++;
 	filp->private_data = &item->fh;
diff --git a/drivers/media/video/ivtv/ivtv-ioctl.c b/drivers/media/video/ivtv/ivtv-ioctl.c
index fa9f0d9..c532b77 100644
--- a/drivers/media/video/ivtv/ivtv-ioctl.c
+++ b/drivers/media/video/ivtv/ivtv-ioctl.c
@@ -748,23 +748,6 @@ static int ivtv_s_register(struct file *file, void *fh, struct v4l2_dbg_register
 }
 #endif
 
-static int ivtv_g_priority(struct file *file, void *fh, enum v4l2_priority *p)
-{
-	struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
-
-	*p = v4l2_prio_max(&itv->prio);
-
-	return 0;
-}
-
-static int ivtv_s_priority(struct file *file, void *fh, enum v4l2_priority prio)
-{
-	struct ivtv_open_id *id = fh;
-	struct ivtv *itv = id->itv;
-
-	return v4l2_prio_change(&itv->prio, &id->prio, prio);
-}
-
 static int ivtv_querycap(struct file *file, void *fh, struct v4l2_capability *vcap)
 {
 	struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
@@ -1833,30 +1816,8 @@ static long ivtv_serialized_ioctl(struct ivtv *itv, struct file *filp,
 		unsigned int cmd, unsigned long arg)
 {
 	struct video_device *vfd = video_devdata(filp);
-	struct ivtv_open_id *id = fh2id(filp->private_data);
 	long ret;
 
-	/* check priority */
-	switch (cmd) {
-	case VIDIOC_S_CTRL:
-	case VIDIOC_S_STD:
-	case VIDIOC_S_INPUT:
-	case VIDIOC_S_OUTPUT:
-	case VIDIOC_S_TUNER:
-	case VIDIOC_S_FREQUENCY:
-	case VIDIOC_S_FMT:
-	case VIDIOC_S_CROP:
-	case VIDIOC_S_AUDIO:
-	case VIDIOC_S_AUDOUT:
-	case VIDIOC_S_EXT_CTRLS:
-	case VIDIOC_S_FBUF:
-	case VIDIOC_S_PRIORITY:
-	case VIDIOC_OVERLAY:
-		ret = v4l2_prio_check(&itv->prio, id->prio);
-		if (ret)
-			return ret;
-	}
-
 	if (ivtv_debug & IVTV_DBGFLG_IOCTL)
 		vfd->debug = V4L2_DEBUG_IOCTL | V4L2_DEBUG_IOCTL_ARG;
 	ret = video_ioctl2(filp, cmd, arg);
@@ -1881,8 +1842,6 @@ long ivtv_v4l2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 
 static const struct v4l2_ioctl_ops ivtv_ioctl_ops = {
 	.vidioc_querycap    		    = ivtv_querycap,
-	.vidioc_g_priority  		    = ivtv_g_priority,
-	.vidioc_s_priority  		    = ivtv_s_priority,
 	.vidioc_s_audio     		    = ivtv_s_audio,
 	.vidioc_g_audio     		    = ivtv_g_audio,
 	.vidioc_enumaudio   		    = ivtv_enumaudio,
-- 
1.6.4.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 7/7] [RFC] ivtv: add priority checks for the non-standard commands.
  2010-05-09 19:29 [PATCH 0/7] [RFC] Move VIDIOC_G/S_PRIORITY handling to the V4L core Hans Verkuil
                   ` (5 preceding siblings ...)
  2010-05-09 19:29 ` [PATCH 6/7] [RFC] ivtv: drop priority handling, use core framework for this Hans Verkuil
@ 2010-05-09 19:29 ` Hans Verkuil
  2010-05-10 10:54 ` [PATCH 0/7] [RFC] Move VIDIOC_G/S_PRIORITY handling to the V4L core Laurent Pinchart
  7 siblings, 0 replies; 9+ messages in thread
From: Hans Verkuil @ 2010-05-09 19:29 UTC (permalink / raw)
  To: linux-media

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
---
 drivers/media/video/ivtv/ivtv-ioctl.c |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/drivers/media/video/ivtv/ivtv-ioctl.c b/drivers/media/video/ivtv/ivtv-ioctl.c
index c532b77..de392a2 100644
--- a/drivers/media/video/ivtv/ivtv-ioctl.c
+++ b/drivers/media/video/ivtv/ivtv-ioctl.c
@@ -1777,7 +1777,25 @@ static int ivtv_decoder_ioctls(struct file *filp, unsigned int cmd, void *arg)
 
 static long ivtv_default(struct file *file, void *fh, int cmd, void *arg)
 {
-	struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
+	struct ivtv_open_id *id = fh2id(fh);
+	struct ivtv *itv = id->itv;
+	int ret;
+
+	switch (cmd) {
+	case VIDEO_PLAY:
+	case VIDEO_STOP:
+	case VIDEO_FREEZE:
+	case VIDEO_CONTINUE:
+	case VIDEO_COMMAND:
+	case VIDEO_SELECT_SOURCE:
+	case AUDIO_SET_MUTE:
+	case AUDIO_CHANNEL_SELECT:
+	case AUDIO_BILINGUAL_CHANNEL_SELECT:
+		ret = v4l2_prio_check(&itv->v4l2_dev.prio, id->fh.prio);
+		if (ret)
+			return ret;
+		break;
+	}
 
 	switch (cmd) {
 	case VIDIOC_INT_RESET: {
-- 
1.6.4.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/7] [RFC] Move VIDIOC_G/S_PRIORITY handling to the V4L core
  2010-05-09 19:29 [PATCH 0/7] [RFC] Move VIDIOC_G/S_PRIORITY handling to the V4L core Hans Verkuil
                   ` (6 preceding siblings ...)
  2010-05-09 19:29 ` [PATCH 7/7] [RFC] ivtv: add priority checks for the non-standard commands Hans Verkuil
@ 2010-05-10 10:54 ` Laurent Pinchart
  7 siblings, 0 replies; 9+ messages in thread
From: Laurent Pinchart @ 2010-05-10 10:54 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: linux-media

Hi Hans,

On Sunday 09 May 2010 21:29:05 Hans Verkuil wrote:
> Few drivers implement VIDIOC_G/S_PRIORITY and those that do often implement
> it incorrectly.
> 
> Now that we have a v4l2_fh struct it is easy to add support for priority
> handling to the v4l core framework.
> 
> There are three types of drivers:
> 
> 1) Those that use v4l2_fh. There the local priority can be stored in the
>    v4l2_fh struct.
> 
> 2) Those that do not have an open or release function defined in
> v4l2_file_ops. That means that file->private_data will never be filled and
> so we can use that to store the local priority in.
> 
> 3) Others. In all other cases we leave it to the driver. Of course, the
> goal is to eventually move the 'others' into type 1 or 2.
> 
> This patch series shows how it is done and converts ivtv to rely on the
> core framework instead of doing it manually.
> 
> Comments?

I don't think this is right. You're moving the priority ioctls support to 
v4l2_device, while it would make more sense to move it to video_device. If a 
device can capture two independent video streams simultaneously, your patches 
would prevent it from working at all.

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2010-05-10 10:53 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-09 19:29 [PATCH 0/7] [RFC] Move VIDIOC_G/S_PRIORITY handling to the V4L core Hans Verkuil
2010-05-09 19:29 ` [PATCH 1/7] [RFC] v4l2_prio: move from v4l2-common to v4l2-device Hans Verkuil
2010-05-09 19:29 ` [PATCH 2/7] [RFC] v4l2-device: add v4l2_prio_state to v4l2_device Hans Verkuil
2010-05-09 19:29 ` [PATCH 3/7] [RFC] v4l2-fh: implement v4l2_priority support Hans Verkuil
2010-05-09 19:29 ` [PATCH 4/7] [RFC] v4l2-dev: add and support flag V4L2_FH_USE_PRIO Hans Verkuil
2010-05-09 19:29 ` [PATCH 5/7] [RFC] v4l2-ioctl: add priority handling support Hans Verkuil
2010-05-09 19:29 ` [PATCH 6/7] [RFC] ivtv: drop priority handling, use core framework for this Hans Verkuil
2010-05-09 19:29 ` [PATCH 7/7] [RFC] ivtv: add priority checks for the non-standard commands Hans Verkuil
2010-05-10 10:54 ` [PATCH 0/7] [RFC] Move VIDIOC_G/S_PRIORITY handling to the V4L core Laurent Pinchart

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.