All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFCv1 PATCH 00/32] Core and vb2 enhancements
@ 2012-06-10 10:25 Hans Verkuil
  2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
  2012-06-10 16:46 ` [RFCv1 PATCH 00/32] Core and vb2 enhancements Mauro Carvalho Chehab
  0 siblings, 2 replies; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 10:25 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski

Hi all,

This large patch series makes a number of changes to the core (ioctl
handling in particular) and vb2. It all builds on one another, so there
wasn't much point in splitting it. Most patches are fairly trivial, so it
is not as bad as it looks :-)

I will go through the patches one by one:

- Regression fixes.

This is a small patch that fixes a number of regressions that are relevant to
this patch series. These fixes have already been posted to the list.

- v4l2-ioctl.c: move a block of code down, no other changes.

Just move code around, no other changes.

- v4l2-ioctl.c: introduce INFO_FL_CLEAR to replace switch.

This replaces the switch that determines how much of the struct needs to be
copied from userspace with a simple table lookup.

- v4l2-ioctl.c: v4l2-ioctl: add debug and callback/offset functionality.

Prepare for the next step where the large switch is replaced by table lookups.

- v4l2-ioctl.c: remove an unnecessary #ifdef.

A small fix for the table: keep the DBG_G/S_REGISTER ioctl in the table. All
the right checks are already made, and this way you will actually see the ioctl
name in the debug messages if you use it.

- v4l2-ioctl.c: use the new table for querycap and i/o ioctls.
- v4l2-ioctl.c: use the new table for priority ioctls.
- v4l2-ioctl.c: use the new table for format/framebuffer ioctls.
- v4l2-ioctl.c: use the new table for overlay/streamon/off ioctls.
- v4l2-ioctl.c: use the new table for std/tuner/modulator ioctls.
- v4l2-ioctl.c: use the new table for queuing/parm ioctls.
- v4l2-ioctl.c: use the new table for control ioctls.
- v4l2-ioctl.c: use the new table for selection ioctls.
- v4l2-ioctl.c: use the new table for compression ioctls.
- v4l2-ioctl.c: use the new table for debug ioctls.
- v4l2-ioctl.c: use the new table for preset/timings ioctls.
- v4l2-ioctl.c: use the new table for the remaining ioctls.

Here the switch is replaced by table lookups section-by-section.

- v4l2-ioctl.c: finalize table conversion.

Remove the last part of the switch.

- v4l2-dev.c: add debug sysfs entry.

The video_device debug field is pretty useful, if only you could set it. The
solution is simple: export it in sysfs. That way you can easily set the debug
level per device node. Works like a charm.

- v4l2-ioctl: remove v4l_(i2c_)print_ioctl

Clean up a few rarely used macros.

- ivtv: don't mess with vfd->debug.
- cx18: don't mess with vfd->debug.

Rely on the new sysfs debug mechanism instead.

- v4l2-dev/ioctl.c: add vb2_queue support to video_device.

Add core support for vb2 to struct video_device. This will be used in the next patch.
Note: this assumes that there is no more than one vb2_queue per device node. So this
can't be used for mem2mem.

- videobuf2-core: add helper functions.

These helpers simplify using vb2: If you set vdev->queue and vdev->queue_lock then these
helpers will take care of queue ownership and locking. So as soon as REQBUFS or
CREATE_BUFFERS is called, that file handle owns the queue and no other filehandle can do
anything with it except for QUERYBUF and mmap. I'm not sure about mmap: should that also
be limited to the owner?

The locking has been changed: it is now possible to specify a mutex that protects the
queue (vdev->queue_lock), and that will be taken instead of the core lock (vdev->lock) when
the vb2 ioctls are called. If you need to serialize against the core lock, then you should
take that lock in the vb2 ops you implemented. So queue_lock is always taken before vdev->lock.

This approach should remove the need for disabling locking for specific ioctls which was
introduced in 3.5. I believe that was the wrong approach.

I have refactored reqbufs and request_buffers a bit: they call the same code to check for
valid memory and buffer types. In addition, these functions will always return -EINVAL if
the types are invalid, and only then will they check for busy state. That way code like qv4l2
that tries to detect which memory types are available can still do that, even if streaming
is in progress. Currently you can get -EBUSY back and that hides whether the memory type
was valid.

create_buffers now also supports count == 0: if count == 0, then you will never get -EBUSY.

- create_bufs: handle count == 0.

Update documentation.

- vivi: remove pointless g/s_std support
- vivi: embed struct video_device instead of allocating it.
- vivi: use vb2 helper functions.

Two vivi cleanups and implement the vb2 helpers in vivi.

- v4l2-dev.c: also add debug support for the fops.

Show debugging when the fops are called if vdev->debug is set.

- v4l2-ioctl.c: shorten the lines of the table.

Make the ioctl table more readable.

- pwc: use the new vb2 helpers.

Implement the vb2 helpers in pwc.

- pwc: v4l2-compliance fixes.

Fix some complaints from v4l2-compliance.

This patch series is also available here:

git://linuxtv.org/hverkuil/media_tree.git ioctlv5

Personally I think that the table conversion is fairly trivial (just a lot of work).
The interesting bits are with the new debug sysfs entry, the vb2 helpers and the way
the core handles vb2 locking (and yes, you don't have to use vb2 locking, but then
you most likely still have to write wrapper functions).

Comments? Ideas?

Regards,

	Hans

diffstat:

 Documentation/DocBook/media/v4l/vidioc-create-bufs.xml |    8 +-
 drivers/media/video/cx18/cx18-ioctl.c                  |   18 -
 drivers/media/video/cx18/cx18-ioctl.h                  |    2 -
 drivers/media/video/cx18/cx18-streams.c                |    4 +-
 drivers/media/video/ivtv/ivtv-ioctl.c                  |   12 -
 drivers/media/video/ivtv/ivtv-ioctl.h                  |    1 -
 drivers/media/video/ivtv/ivtv-streams.c                |    4 +-
 drivers/media/video/pvrusb2/pvrusb2-v4l2.c             |    4 +-
 drivers/media/video/pwc/pwc-if.c                       |  155 +---
 drivers/media/video/pwc/pwc-v4l.c                      |  165 +---
 drivers/media/video/pwc/pwc.h                          |    3 -
 drivers/media/video/sn9c102/sn9c102.h                  |    2 +-
 drivers/media/video/uvc/uvc_v4l2.c                     |    2 +-
 drivers/media/video/v4l2-dev.c                         |   67 +-
 drivers/media/video/v4l2-ioctl.c                       | 3452 ++++++++++++++++++++++++++++++++++++++--------------------------------------
 drivers/media/video/videobuf2-core.c                   |  353 ++++++--
 drivers/media/video/vivi.c                             |  190 +----
 include/linux/videodev2.h                              |    6 +-
 include/media/v4l2-dev.h                               |    8 +
 include/media/v4l2-ioctl.h                             |   25 +-
 include/media/videobuf2-core.h                         |   19 +
 21 files changed, 2159 insertions(+), 2341 deletions(-)


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

* [RFCv1 PATCH 01/32] Regression fixes.
  2012-06-10 10:25 [RFCv1 PATCH 00/32] Core and vb2 enhancements Hans Verkuil
@ 2012-06-10 10:25 ` Hans Verkuil
  2012-06-10 10:25   ` [RFCv1 PATCH 02/32] v4l2-ioctl.c: move a block of code down, no other changes Hans Verkuil
                     ` (30 more replies)
  2012-06-10 16:46 ` [RFCv1 PATCH 00/32] Core and vb2 enhancements Mauro Carvalho Chehab
  1 sibling, 31 replies; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 10:25 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/video/v4l2-dev.c |    2 ++
 drivers/media/video/vivi.c     |    6 +++++-
 include/linux/videodev2.h      |    6 +++---
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c
index 5ccbd46..1500208 100644
--- a/drivers/media/video/v4l2-dev.c
+++ b/drivers/media/video/v4l2-dev.c
@@ -679,6 +679,8 @@ static void determine_valid_ioctls(struct video_device *vdev)
 	SET_VALID_IOCTL(ops, VIDIOC_QUERY_DV_PRESET, vidioc_query_dv_preset);
 	SET_VALID_IOCTL(ops, VIDIOC_S_DV_TIMINGS, vidioc_s_dv_timings);
 	SET_VALID_IOCTL(ops, VIDIOC_G_DV_TIMINGS, vidioc_g_dv_timings);
+	SET_VALID_IOCTL(ops, VIDIOC_ENUM_DV_TIMINGS, vidioc_enum_dv_timings);
+	SET_VALID_IOCTL(ops, VIDIOC_QUERY_DV_TIMINGS, vidioc_query_dv_timings);
 	/* yes, really vidioc_subscribe_event */
 	SET_VALID_IOCTL(ops, VIDIOC_DQEVENT, vidioc_subscribe_event);
 	SET_VALID_IOCTL(ops, VIDIOC_SUBSCRIBE_EVENT, vidioc_subscribe_event);
diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c
index 0960d7f..08c1024 100644
--- a/drivers/media/video/vivi.c
+++ b/drivers/media/video/vivi.c
@@ -1149,10 +1149,14 @@ static ssize_t
 vivi_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
 {
 	struct vivi_dev *dev = video_drvdata(file);
+	int err;
 
 	dprintk(dev, 1, "read called\n");
-	return vb2_read(&dev->vb_vidq, data, count, ppos,
+	mutex_lock(&dev->mutex);
+	err = vb2_read(&dev->vb_vidq, data, count, ppos,
 		       file->f_flags & O_NONBLOCK);
+	mutex_unlock(&dev->mutex);
+	return err;
 }
 
 static unsigned int
diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h
index 370d111..2039c5d 100644
--- a/include/linux/videodev2.h
+++ b/include/linux/videodev2.h
@@ -2640,9 +2640,9 @@ struct v4l2_create_buffers {
 
 /* Experimental, these three ioctls may change over the next couple of kernel
    versions. */
-#define VIDIOC_ENUM_DV_TIMINGS  _IOWR('V', 96, struct v4l2_enum_dv_timings)
-#define VIDIOC_QUERY_DV_TIMINGS  _IOR('V', 97, struct v4l2_dv_timings)
-#define VIDIOC_DV_TIMINGS_CAP   _IOWR('V', 98, struct v4l2_dv_timings_cap)
+#define VIDIOC_ENUM_DV_TIMINGS  _IOWR('V', 98, struct v4l2_enum_dv_timings)
+#define VIDIOC_QUERY_DV_TIMINGS  _IOR('V', 99, struct v4l2_dv_timings)
+#define VIDIOC_DV_TIMINGS_CAP   _IOWR('V', 100, struct v4l2_dv_timings_cap)
 
 /* Reminder: when adding new ioctls please add support for them to
    drivers/media/video/v4l2-compat-ioctl32.c as well! */
-- 
1.7.10


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

* [RFCv1 PATCH 02/32] v4l2-ioctl.c: move a block of code down, no other changes.
  2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
@ 2012-06-10 10:25   ` Hans Verkuil
  2012-06-10 10:25   ` [RFCv1 PATCH 03/32] v4l2-ioctl.c: introduce INFO_FL_CLEAR to replace switch Hans Verkuil
                     ` (29 subsequent siblings)
  30 siblings, 0 replies; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 10:25 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

A block of code is moved down in the code to make later changes easier.
Do just the move without other changes to keep the diff readable for the
upcoming patch.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/video/v4l2-ioctl.c |  288 +++++++++++++++++++-------------------
 1 file changed, 144 insertions(+), 144 deletions(-)

diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
index 91be4e8..7c6831f 100644
--- a/drivers/media/video/v4l2-ioctl.c
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -183,150 +183,6 @@ static const char *v4l2_memory_names[] = {
 /* ------------------------------------------------------------------ */
 /* debug help functions                                               */
 
-struct v4l2_ioctl_info {
-	unsigned int ioctl;
-	u16 flags;
-	const char * const name;
-};
-
-/* This control needs a priority check */
-#define INFO_FL_PRIO	(1 << 0)
-/* This control can be valid if the filehandle passes a control handler. */
-#define INFO_FL_CTRL	(1 << 1)
-
-#define IOCTL_INFO(_ioctl, _flags) [_IOC_NR(_ioctl)] = {	\
-	.ioctl = _ioctl,					\
-	.flags = _flags,					\
-	.name = #_ioctl,					\
-}
-
-static struct v4l2_ioctl_info v4l2_ioctls[] = {
-	IOCTL_INFO(VIDIOC_QUERYCAP, 0),
-	IOCTL_INFO(VIDIOC_ENUM_FMT, 0),
-	IOCTL_INFO(VIDIOC_G_FMT, 0),
-	IOCTL_INFO(VIDIOC_S_FMT, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_REQBUFS, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_QUERYBUF, 0),
-	IOCTL_INFO(VIDIOC_G_FBUF, 0),
-	IOCTL_INFO(VIDIOC_S_FBUF, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_OVERLAY, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_QBUF, 0),
-	IOCTL_INFO(VIDIOC_DQBUF, 0),
-	IOCTL_INFO(VIDIOC_STREAMON, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_STREAMOFF, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_G_PARM, 0),
-	IOCTL_INFO(VIDIOC_S_PARM, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_G_STD, 0),
-	IOCTL_INFO(VIDIOC_S_STD, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_ENUMSTD, 0),
-	IOCTL_INFO(VIDIOC_ENUMINPUT, 0),
-	IOCTL_INFO(VIDIOC_G_CTRL, INFO_FL_CTRL),
-	IOCTL_INFO(VIDIOC_S_CTRL, INFO_FL_PRIO | INFO_FL_CTRL),
-	IOCTL_INFO(VIDIOC_G_TUNER, 0),
-	IOCTL_INFO(VIDIOC_S_TUNER, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_G_AUDIO, 0),
-	IOCTL_INFO(VIDIOC_S_AUDIO, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_QUERYCTRL, INFO_FL_CTRL),
-	IOCTL_INFO(VIDIOC_QUERYMENU, INFO_FL_CTRL),
-	IOCTL_INFO(VIDIOC_G_INPUT, 0),
-	IOCTL_INFO(VIDIOC_S_INPUT, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_G_OUTPUT, 0),
-	IOCTL_INFO(VIDIOC_S_OUTPUT, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_ENUMOUTPUT, 0),
-	IOCTL_INFO(VIDIOC_G_AUDOUT, 0),
-	IOCTL_INFO(VIDIOC_S_AUDOUT, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_G_MODULATOR, 0),
-	IOCTL_INFO(VIDIOC_S_MODULATOR, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_G_FREQUENCY, 0),
-	IOCTL_INFO(VIDIOC_S_FREQUENCY, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_CROPCAP, 0),
-	IOCTL_INFO(VIDIOC_G_CROP, 0),
-	IOCTL_INFO(VIDIOC_S_CROP, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_G_SELECTION, 0),
-	IOCTL_INFO(VIDIOC_S_SELECTION, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_G_JPEGCOMP, 0),
-	IOCTL_INFO(VIDIOC_S_JPEGCOMP, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_QUERYSTD, 0),
-	IOCTL_INFO(VIDIOC_TRY_FMT, 0),
-	IOCTL_INFO(VIDIOC_ENUMAUDIO, 0),
-	IOCTL_INFO(VIDIOC_ENUMAUDOUT, 0),
-	IOCTL_INFO(VIDIOC_G_PRIORITY, 0),
-	IOCTL_INFO(VIDIOC_S_PRIORITY, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_G_SLICED_VBI_CAP, 0),
-	IOCTL_INFO(VIDIOC_LOG_STATUS, 0),
-	IOCTL_INFO(VIDIOC_G_EXT_CTRLS, INFO_FL_CTRL),
-	IOCTL_INFO(VIDIOC_S_EXT_CTRLS, INFO_FL_PRIO | INFO_FL_CTRL),
-	IOCTL_INFO(VIDIOC_TRY_EXT_CTRLS, 0),
-	IOCTL_INFO(VIDIOC_ENUM_FRAMESIZES, 0),
-	IOCTL_INFO(VIDIOC_ENUM_FRAMEINTERVALS, 0),
-	IOCTL_INFO(VIDIOC_G_ENC_INDEX, 0),
-	IOCTL_INFO(VIDIOC_ENCODER_CMD, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_TRY_ENCODER_CMD, 0),
-	IOCTL_INFO(VIDIOC_DECODER_CMD, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_TRY_DECODER_CMD, 0),
-#ifdef CONFIG_VIDEO_ADV_DEBUG
-	IOCTL_INFO(VIDIOC_DBG_S_REGISTER, 0),
-	IOCTL_INFO(VIDIOC_DBG_G_REGISTER, 0),
-#endif
-	IOCTL_INFO(VIDIOC_DBG_G_CHIP_IDENT, 0),
-	IOCTL_INFO(VIDIOC_S_HW_FREQ_SEEK, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_ENUM_DV_PRESETS, 0),
-	IOCTL_INFO(VIDIOC_S_DV_PRESET, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_G_DV_PRESET, 0),
-	IOCTL_INFO(VIDIOC_QUERY_DV_PRESET, 0),
-	IOCTL_INFO(VIDIOC_S_DV_TIMINGS, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_G_DV_TIMINGS, 0),
-	IOCTL_INFO(VIDIOC_DQEVENT, 0),
-	IOCTL_INFO(VIDIOC_SUBSCRIBE_EVENT, 0),
-	IOCTL_INFO(VIDIOC_UNSUBSCRIBE_EVENT, 0),
-	IOCTL_INFO(VIDIOC_CREATE_BUFS, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_PREPARE_BUF, 0),
-	IOCTL_INFO(VIDIOC_ENUM_DV_TIMINGS, 0),
-	IOCTL_INFO(VIDIOC_QUERY_DV_TIMINGS, 0),
-	IOCTL_INFO(VIDIOC_DV_TIMINGS_CAP, 0),
-};
-#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
-
-bool v4l2_is_known_ioctl(unsigned int cmd)
-{
-	if (_IOC_NR(cmd) >= V4L2_IOCTLS)
-		return false;
-	return v4l2_ioctls[_IOC_NR(cmd)].ioctl == cmd;
-}
-
-/* Common ioctl debug function. This function can be used by
-   external ioctl messages as well as internal V4L ioctl */
-void v4l_printk_ioctl(unsigned int cmd)
-{
-	char *dir, *type;
-
-	switch (_IOC_TYPE(cmd)) {
-	case 'd':
-		type = "v4l2_int";
-		break;
-	case 'V':
-		if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
-			type = "v4l2";
-			break;
-		}
-		printk("%s", v4l2_ioctls[_IOC_NR(cmd)].name);
-		return;
-	default:
-		type = "unknown";
-	}
-
-	switch (_IOC_DIR(cmd)) {
-	case _IOC_NONE:              dir = "--"; break;
-	case _IOC_READ:              dir = "r-"; break;
-	case _IOC_WRITE:             dir = "-w"; break;
-	case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
-	default:                     dir = "*ERR*"; break;
-	}
-	printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
-		type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
-}
-EXPORT_SYMBOL(v4l_printk_ioctl);
-
 static void dbgbuf(unsigned int cmd, struct video_device *vfd,
 					struct v4l2_buffer *p)
 {
@@ -536,6 +392,150 @@ static int check_fmt(const struct v4l2_ioctl_ops *ops, enum v4l2_buf_type type)
 	return -EINVAL;
 }
 
+struct v4l2_ioctl_info {
+	unsigned int ioctl;
+	u16 flags;
+	const char * const name;
+};
+
+/* This control needs a priority check */
+#define INFO_FL_PRIO	(1 << 0)
+/* This control can be valid if the filehandle passes a control handler. */
+#define INFO_FL_CTRL	(1 << 1)
+
+#define IOCTL_INFO(_ioctl, _flags) [_IOC_NR(_ioctl)] = {	\
+	.ioctl = _ioctl,					\
+	.flags = _flags,					\
+	.name = #_ioctl,					\
+}
+
+static struct v4l2_ioctl_info v4l2_ioctls[] = {
+	IOCTL_INFO(VIDIOC_QUERYCAP, 0),
+	IOCTL_INFO(VIDIOC_ENUM_FMT, 0),
+	IOCTL_INFO(VIDIOC_G_FMT, 0),
+	IOCTL_INFO(VIDIOC_S_FMT, INFO_FL_PRIO),
+	IOCTL_INFO(VIDIOC_REQBUFS, INFO_FL_PRIO),
+	IOCTL_INFO(VIDIOC_QUERYBUF, 0),
+	IOCTL_INFO(VIDIOC_G_FBUF, 0),
+	IOCTL_INFO(VIDIOC_S_FBUF, INFO_FL_PRIO),
+	IOCTL_INFO(VIDIOC_OVERLAY, INFO_FL_PRIO),
+	IOCTL_INFO(VIDIOC_QBUF, 0),
+	IOCTL_INFO(VIDIOC_DQBUF, 0),
+	IOCTL_INFO(VIDIOC_STREAMON, INFO_FL_PRIO),
+	IOCTL_INFO(VIDIOC_STREAMOFF, INFO_FL_PRIO),
+	IOCTL_INFO(VIDIOC_G_PARM, 0),
+	IOCTL_INFO(VIDIOC_S_PARM, INFO_FL_PRIO),
+	IOCTL_INFO(VIDIOC_G_STD, 0),
+	IOCTL_INFO(VIDIOC_S_STD, INFO_FL_PRIO),
+	IOCTL_INFO(VIDIOC_ENUMSTD, 0),
+	IOCTL_INFO(VIDIOC_ENUMINPUT, 0),
+	IOCTL_INFO(VIDIOC_G_CTRL, INFO_FL_CTRL),
+	IOCTL_INFO(VIDIOC_S_CTRL, INFO_FL_PRIO | INFO_FL_CTRL),
+	IOCTL_INFO(VIDIOC_G_TUNER, 0),
+	IOCTL_INFO(VIDIOC_S_TUNER, INFO_FL_PRIO),
+	IOCTL_INFO(VIDIOC_G_AUDIO, 0),
+	IOCTL_INFO(VIDIOC_S_AUDIO, INFO_FL_PRIO),
+	IOCTL_INFO(VIDIOC_QUERYCTRL, INFO_FL_CTRL),
+	IOCTL_INFO(VIDIOC_QUERYMENU, INFO_FL_CTRL),
+	IOCTL_INFO(VIDIOC_G_INPUT, 0),
+	IOCTL_INFO(VIDIOC_S_INPUT, INFO_FL_PRIO),
+	IOCTL_INFO(VIDIOC_G_OUTPUT, 0),
+	IOCTL_INFO(VIDIOC_S_OUTPUT, INFO_FL_PRIO),
+	IOCTL_INFO(VIDIOC_ENUMOUTPUT, 0),
+	IOCTL_INFO(VIDIOC_G_AUDOUT, 0),
+	IOCTL_INFO(VIDIOC_S_AUDOUT, INFO_FL_PRIO),
+	IOCTL_INFO(VIDIOC_G_MODULATOR, 0),
+	IOCTL_INFO(VIDIOC_S_MODULATOR, INFO_FL_PRIO),
+	IOCTL_INFO(VIDIOC_G_FREQUENCY, 0),
+	IOCTL_INFO(VIDIOC_S_FREQUENCY, INFO_FL_PRIO),
+	IOCTL_INFO(VIDIOC_CROPCAP, 0),
+	IOCTL_INFO(VIDIOC_G_CROP, 0),
+	IOCTL_INFO(VIDIOC_S_CROP, INFO_FL_PRIO),
+	IOCTL_INFO(VIDIOC_G_SELECTION, 0),
+	IOCTL_INFO(VIDIOC_S_SELECTION, INFO_FL_PRIO),
+	IOCTL_INFO(VIDIOC_G_JPEGCOMP, 0),
+	IOCTL_INFO(VIDIOC_S_JPEGCOMP, INFO_FL_PRIO),
+	IOCTL_INFO(VIDIOC_QUERYSTD, 0),
+	IOCTL_INFO(VIDIOC_TRY_FMT, 0),
+	IOCTL_INFO(VIDIOC_ENUMAUDIO, 0),
+	IOCTL_INFO(VIDIOC_ENUMAUDOUT, 0),
+	IOCTL_INFO(VIDIOC_G_PRIORITY, 0),
+	IOCTL_INFO(VIDIOC_S_PRIORITY, INFO_FL_PRIO),
+	IOCTL_INFO(VIDIOC_G_SLICED_VBI_CAP, 0),
+	IOCTL_INFO(VIDIOC_LOG_STATUS, 0),
+	IOCTL_INFO(VIDIOC_G_EXT_CTRLS, INFO_FL_CTRL),
+	IOCTL_INFO(VIDIOC_S_EXT_CTRLS, INFO_FL_PRIO | INFO_FL_CTRL),
+	IOCTL_INFO(VIDIOC_TRY_EXT_CTRLS, 0),
+	IOCTL_INFO(VIDIOC_ENUM_FRAMESIZES, 0),
+	IOCTL_INFO(VIDIOC_ENUM_FRAMEINTERVALS, 0),
+	IOCTL_INFO(VIDIOC_G_ENC_INDEX, 0),
+	IOCTL_INFO(VIDIOC_ENCODER_CMD, INFO_FL_PRIO),
+	IOCTL_INFO(VIDIOC_TRY_ENCODER_CMD, 0),
+	IOCTL_INFO(VIDIOC_DECODER_CMD, INFO_FL_PRIO),
+	IOCTL_INFO(VIDIOC_TRY_DECODER_CMD, 0),
+#ifdef CONFIG_VIDEO_ADV_DEBUG
+	IOCTL_INFO(VIDIOC_DBG_S_REGISTER, 0),
+	IOCTL_INFO(VIDIOC_DBG_G_REGISTER, 0),
+#endif
+	IOCTL_INFO(VIDIOC_DBG_G_CHIP_IDENT, 0),
+	IOCTL_INFO(VIDIOC_S_HW_FREQ_SEEK, INFO_FL_PRIO),
+	IOCTL_INFO(VIDIOC_ENUM_DV_PRESETS, 0),
+	IOCTL_INFO(VIDIOC_S_DV_PRESET, INFO_FL_PRIO),
+	IOCTL_INFO(VIDIOC_G_DV_PRESET, 0),
+	IOCTL_INFO(VIDIOC_QUERY_DV_PRESET, 0),
+	IOCTL_INFO(VIDIOC_S_DV_TIMINGS, INFO_FL_PRIO),
+	IOCTL_INFO(VIDIOC_G_DV_TIMINGS, 0),
+	IOCTL_INFO(VIDIOC_DQEVENT, 0),
+	IOCTL_INFO(VIDIOC_SUBSCRIBE_EVENT, 0),
+	IOCTL_INFO(VIDIOC_UNSUBSCRIBE_EVENT, 0),
+	IOCTL_INFO(VIDIOC_CREATE_BUFS, INFO_FL_PRIO),
+	IOCTL_INFO(VIDIOC_PREPARE_BUF, 0),
+	IOCTL_INFO(VIDIOC_ENUM_DV_TIMINGS, 0),
+	IOCTL_INFO(VIDIOC_QUERY_DV_TIMINGS, 0),
+	IOCTL_INFO(VIDIOC_DV_TIMINGS_CAP, 0),
+};
+#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
+
+bool v4l2_is_known_ioctl(unsigned int cmd)
+{
+	if (_IOC_NR(cmd) >= V4L2_IOCTLS)
+		return false;
+	return v4l2_ioctls[_IOC_NR(cmd)].ioctl == cmd;
+}
+
+/* Common ioctl debug function. This function can be used by
+   external ioctl messages as well as internal V4L ioctl */
+void v4l_printk_ioctl(unsigned int cmd)
+{
+	char *dir, *type;
+
+	switch (_IOC_TYPE(cmd)) {
+	case 'd':
+		type = "v4l2_int";
+		break;
+	case 'V':
+		if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
+			type = "v4l2";
+			break;
+		}
+		printk("%s", v4l2_ioctls[_IOC_NR(cmd)].name);
+		return;
+	default:
+		type = "unknown";
+	}
+
+	switch (_IOC_DIR(cmd)) {
+	case _IOC_NONE:              dir = "--"; break;
+	case _IOC_READ:              dir = "r-"; break;
+	case _IOC_WRITE:             dir = "-w"; break;
+	case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
+	default:                     dir = "*ERR*"; break;
+	}
+	printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
+		type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
+}
+EXPORT_SYMBOL(v4l_printk_ioctl);
+
 static long __video_do_ioctl(struct file *file,
 		unsigned int cmd, void *arg)
 {
-- 
1.7.10


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

* [RFCv1 PATCH 03/32] v4l2-ioctl.c: introduce INFO_FL_CLEAR to replace switch.
  2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
  2012-06-10 10:25   ` [RFCv1 PATCH 02/32] v4l2-ioctl.c: move a block of code down, no other changes Hans Verkuil
@ 2012-06-10 10:25   ` Hans Verkuil
  2012-06-10 10:25   ` [RFCv1 PATCH 04/32] v4l2-ioctl.c: v4l2-ioctl: add debug and callback/offset functionality Hans Verkuil
                     ` (28 subsequent siblings)
  30 siblings, 0 replies; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 10:25 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

The switch statement that determine how much data should be copied from
userspace is replaced by a table lookup.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/video/v4l2-ioctl.c |  103 +++++++++++++++-----------------------
 1 file changed, 41 insertions(+), 62 deletions(-)

diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
index 7c6831f..a9602db 100644
--- a/drivers/media/video/v4l2-ioctl.c
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -394,7 +394,7 @@ static int check_fmt(const struct v4l2_ioctl_ops *ops, enum v4l2_buf_type type)
 
 struct v4l2_ioctl_info {
 	unsigned int ioctl;
-	u16 flags;
+	u32 flags;
 	const char * const name;
 };
 
@@ -402,6 +402,11 @@ struct v4l2_ioctl_info {
 #define INFO_FL_PRIO	(1 << 0)
 /* This control can be valid if the filehandle passes a control handler. */
 #define INFO_FL_CTRL	(1 << 1)
+/* Zero struct from after the field to the end */
+#define INFO_FL_CLEAR(v4l2_struct, field)			\
+	((offsetof(struct v4l2_struct, field) +			\
+	  sizeof(((struct v4l2_struct *)0)->field)) << 16)
+#define INFO_FL_CLEAR_MASK (_IOC_SIZEMASK << 16)
 
 #define IOCTL_INFO(_ioctl, _flags) [_IOC_NR(_ioctl)] = {	\
 	.ioctl = _ioctl,					\
@@ -411,11 +416,11 @@ struct v4l2_ioctl_info {
 
 static struct v4l2_ioctl_info v4l2_ioctls[] = {
 	IOCTL_INFO(VIDIOC_QUERYCAP, 0),
-	IOCTL_INFO(VIDIOC_ENUM_FMT, 0),
-	IOCTL_INFO(VIDIOC_G_FMT, 0),
+	IOCTL_INFO(VIDIOC_ENUM_FMT, INFO_FL_CLEAR(v4l2_fmtdesc, type)),
+	IOCTL_INFO(VIDIOC_G_FMT, INFO_FL_CLEAR(v4l2_format, type)),
 	IOCTL_INFO(VIDIOC_S_FMT, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_REQBUFS, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_QUERYBUF, 0),
+	IOCTL_INFO(VIDIOC_QUERYBUF, INFO_FL_CLEAR(v4l2_buffer, length)),
 	IOCTL_INFO(VIDIOC_G_FBUF, 0),
 	IOCTL_INFO(VIDIOC_S_FBUF, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_OVERLAY, INFO_FL_PRIO),
@@ -423,33 +428,33 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
 	IOCTL_INFO(VIDIOC_DQBUF, 0),
 	IOCTL_INFO(VIDIOC_STREAMON, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_STREAMOFF, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_G_PARM, 0),
+	IOCTL_INFO(VIDIOC_G_PARM, INFO_FL_CLEAR(v4l2_streamparm, type)),
 	IOCTL_INFO(VIDIOC_S_PARM, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_G_STD, 0),
 	IOCTL_INFO(VIDIOC_S_STD, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_ENUMSTD, 0),
-	IOCTL_INFO(VIDIOC_ENUMINPUT, 0),
+	IOCTL_INFO(VIDIOC_ENUMSTD, INFO_FL_CLEAR(v4l2_standard, index)),
+	IOCTL_INFO(VIDIOC_ENUMINPUT, INFO_FL_CLEAR(v4l2_input, index)),
 	IOCTL_INFO(VIDIOC_G_CTRL, INFO_FL_CTRL),
 	IOCTL_INFO(VIDIOC_S_CTRL, INFO_FL_PRIO | INFO_FL_CTRL),
-	IOCTL_INFO(VIDIOC_G_TUNER, 0),
+	IOCTL_INFO(VIDIOC_G_TUNER, INFO_FL_CLEAR(v4l2_tuner, index)),
 	IOCTL_INFO(VIDIOC_S_TUNER, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_G_AUDIO, 0),
 	IOCTL_INFO(VIDIOC_S_AUDIO, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_QUERYCTRL, INFO_FL_CTRL),
-	IOCTL_INFO(VIDIOC_QUERYMENU, INFO_FL_CTRL),
+	IOCTL_INFO(VIDIOC_QUERYCTRL, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_queryctrl, id)),
+	IOCTL_INFO(VIDIOC_QUERYMENU, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_querymenu, index)),
 	IOCTL_INFO(VIDIOC_G_INPUT, 0),
 	IOCTL_INFO(VIDIOC_S_INPUT, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_G_OUTPUT, 0),
+	IOCTL_INFO(VIDIOC_G_OUTPUT, INFO_FL_CLEAR(v4l2_output, index)),
 	IOCTL_INFO(VIDIOC_S_OUTPUT, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_ENUMOUTPUT, 0),
 	IOCTL_INFO(VIDIOC_G_AUDOUT, 0),
 	IOCTL_INFO(VIDIOC_S_AUDOUT, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_G_MODULATOR, 0),
+	IOCTL_INFO(VIDIOC_G_MODULATOR, INFO_FL_CLEAR(v4l2_modulator, index)),
 	IOCTL_INFO(VIDIOC_S_MODULATOR, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_G_FREQUENCY, 0),
+	IOCTL_INFO(VIDIOC_G_FREQUENCY, INFO_FL_CLEAR(v4l2_frequency, tuner)),
 	IOCTL_INFO(VIDIOC_S_FREQUENCY, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_CROPCAP, 0),
-	IOCTL_INFO(VIDIOC_G_CROP, 0),
+	IOCTL_INFO(VIDIOC_CROPCAP, INFO_FL_CLEAR(v4l2_cropcap, type)),
+	IOCTL_INFO(VIDIOC_G_CROP, INFO_FL_CLEAR(v4l2_crop, type)),
 	IOCTL_INFO(VIDIOC_S_CROP, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_G_SELECTION, 0),
 	IOCTL_INFO(VIDIOC_S_SELECTION, INFO_FL_PRIO),
@@ -457,20 +462,20 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
 	IOCTL_INFO(VIDIOC_S_JPEGCOMP, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_QUERYSTD, 0),
 	IOCTL_INFO(VIDIOC_TRY_FMT, 0),
-	IOCTL_INFO(VIDIOC_ENUMAUDIO, 0),
-	IOCTL_INFO(VIDIOC_ENUMAUDOUT, 0),
+	IOCTL_INFO(VIDIOC_ENUMAUDIO, INFO_FL_CLEAR(v4l2_audio, index)),
+	IOCTL_INFO(VIDIOC_ENUMAUDOUT, INFO_FL_CLEAR(v4l2_audioout, index)),
 	IOCTL_INFO(VIDIOC_G_PRIORITY, 0),
 	IOCTL_INFO(VIDIOC_S_PRIORITY, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_G_SLICED_VBI_CAP, 0),
+	IOCTL_INFO(VIDIOC_G_SLICED_VBI_CAP, INFO_FL_CLEAR(v4l2_sliced_vbi_cap, type)),
 	IOCTL_INFO(VIDIOC_LOG_STATUS, 0),
 	IOCTL_INFO(VIDIOC_G_EXT_CTRLS, INFO_FL_CTRL),
 	IOCTL_INFO(VIDIOC_S_EXT_CTRLS, INFO_FL_PRIO | INFO_FL_CTRL),
 	IOCTL_INFO(VIDIOC_TRY_EXT_CTRLS, 0),
-	IOCTL_INFO(VIDIOC_ENUM_FRAMESIZES, 0),
-	IOCTL_INFO(VIDIOC_ENUM_FRAMEINTERVALS, 0),
+	IOCTL_INFO(VIDIOC_ENUM_FRAMESIZES, INFO_FL_CLEAR(v4l2_frmsizeenum, pixel_format)),
+	IOCTL_INFO(VIDIOC_ENUM_FRAMEINTERVALS, INFO_FL_CLEAR(v4l2_frmivalenum, height)),
 	IOCTL_INFO(VIDIOC_G_ENC_INDEX, 0),
-	IOCTL_INFO(VIDIOC_ENCODER_CMD, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_TRY_ENCODER_CMD, 0),
+	IOCTL_INFO(VIDIOC_ENCODER_CMD, INFO_FL_PRIO | INFO_FL_CLEAR(v4l2_encoder_cmd, flags)),
+	IOCTL_INFO(VIDIOC_TRY_ENCODER_CMD, INFO_FL_CLEAR(v4l2_encoder_cmd, flags)),
 	IOCTL_INFO(VIDIOC_DECODER_CMD, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_TRY_DECODER_CMD, 0),
 #ifdef CONFIG_VIDEO_ADV_DEBUG
@@ -2105,45 +2110,6 @@ static long __video_do_ioctl(struct file *file,
 	return ret;
 }
 
-/* In some cases, only a few fields are used as input, i.e. when the app sets
- * "index" and then the driver fills in the rest of the structure for the thing
- * with that index.  We only need to copy up the first non-input field.  */
-static unsigned long cmd_input_size(unsigned int cmd)
-{
-	/* Size of structure up to and including 'field' */
-#define CMDINSIZE(cmd, type, field) 				\
-	case VIDIOC_##cmd: 					\
-		return offsetof(struct v4l2_##type, field) + 	\
-			sizeof(((struct v4l2_##type *)0)->field);
-
-	switch (cmd) {
-		CMDINSIZE(ENUM_FMT,		fmtdesc,	type);
-		CMDINSIZE(G_FMT,		format,		type);
-		CMDINSIZE(QUERYBUF,		buffer,		length);
-		CMDINSIZE(G_PARM,		streamparm,	type);
-		CMDINSIZE(ENUMSTD,		standard,	index);
-		CMDINSIZE(ENUMINPUT,		input,		index);
-		CMDINSIZE(G_CTRL,		control,	id);
-		CMDINSIZE(G_TUNER,		tuner,		index);
-		CMDINSIZE(QUERYCTRL,		queryctrl,	id);
-		CMDINSIZE(QUERYMENU,		querymenu,	index);
-		CMDINSIZE(ENUMOUTPUT,		output,		index);
-		CMDINSIZE(G_MODULATOR,		modulator,	index);
-		CMDINSIZE(G_FREQUENCY,		frequency,	tuner);
-		CMDINSIZE(CROPCAP,		cropcap,	type);
-		CMDINSIZE(G_CROP,		crop,		type);
-		CMDINSIZE(ENUMAUDIO,		audio, 		index);
-		CMDINSIZE(ENUMAUDOUT,		audioout, 	index);
-		CMDINSIZE(ENCODER_CMD,		encoder_cmd,	flags);
-		CMDINSIZE(TRY_ENCODER_CMD,	encoder_cmd,	flags);
-		CMDINSIZE(G_SLICED_VBI_CAP,	sliced_vbi_cap,	type);
-		CMDINSIZE(ENUM_FRAMESIZES,	frmsizeenum,	pixel_format);
-		CMDINSIZE(ENUM_FRAMEINTERVALS,	frmivalenum,	height);
-	default:
-		return _IOC_SIZE(cmd);
-	}
-}
-
 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
 			    void * __user *user_ptr, void ***kernel_ptr)
 {
@@ -2218,7 +2184,20 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
 
 		err = -EFAULT;
 		if (_IOC_DIR(cmd) & _IOC_WRITE) {
-			unsigned long n = cmd_input_size(cmd);
+			unsigned int n = _IOC_SIZE(cmd);
+
+			/*
+			 * In some cases, only a few fields are used as input,
+			 * i.e. when the app sets "index" and then the driver
+			 * fills in the rest of the structure for the thing
+			 * with that index.  We only need to copy up the first
+			 * non-input field.
+			 */
+			if (v4l2_is_known_ioctl(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;
-- 
1.7.10


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

* [RFCv1 PATCH 04/32] v4l2-ioctl.c: v4l2-ioctl: add debug and callback/offset functionality.
  2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
  2012-06-10 10:25   ` [RFCv1 PATCH 02/32] v4l2-ioctl.c: move a block of code down, no other changes Hans Verkuil
  2012-06-10 10:25   ` [RFCv1 PATCH 03/32] v4l2-ioctl.c: introduce INFO_FL_CLEAR to replace switch Hans Verkuil
@ 2012-06-10 10:25   ` Hans Verkuil
  2012-06-18  9:47     ` Laurent Pinchart
  2012-06-10 10:25   ` [RFCv1 PATCH 05/32] v4l2-ioctl.c: remove an unnecessary #ifdef Hans Verkuil
                     ` (27 subsequent siblings)
  30 siblings, 1 reply; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 10:25 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

Add the necessary plumbing to make it possible to replace the switch by a
table driven implementation.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/video/v4l2-ioctl.c |   91 ++++++++++++++++++++++++++++++++------
 1 file changed, 78 insertions(+), 13 deletions(-)

diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
index a9602db..a4115ce 100644
--- a/drivers/media/video/v4l2-ioctl.c
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -396,12 +396,22 @@ struct v4l2_ioctl_info {
 	unsigned int ioctl;
 	u32 flags;
 	const char * const name;
+	union {
+		u32 offset;
+		int (*func)(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *p);
+	};
+	void (*debug)(const void *arg);
 };
 
 /* This control needs a priority check */
 #define INFO_FL_PRIO	(1 << 0)
 /* This control can be valid if the filehandle passes a control handler. */
 #define INFO_FL_CTRL	(1 << 1)
+/* This is a standard ioctl, no need for special code */
+#define INFO_FL_STD	(1 << 2)
+/* This is ioctl has its own function */
+#define INFO_FL_FUNC	(1 << 3)
 /* Zero struct from after the field to the end */
 #define INFO_FL_CLEAR(v4l2_struct, field)			\
 	((offsetof(struct v4l2_struct, field) +			\
@@ -414,6 +424,24 @@ struct v4l2_ioctl_info {
 	.name = #_ioctl,					\
 }
 
+#define IOCTL_INFO_STD(_ioctl, _vidioc, _debug, _flags)			\
+	[_IOC_NR(_ioctl)] = {						\
+		.ioctl = _ioctl,					\
+		.flags = _flags | INFO_FL_STD,				\
+		.name = #_ioctl,					\
+		.offset = offsetof(struct v4l2_ioctl_ops, _vidioc),	\
+		.debug = _debug,					\
+	}
+
+#define IOCTL_INFO_FNC(_ioctl, _func, _debug, _flags)			\
+	[_IOC_NR(_ioctl)] = {						\
+		.ioctl = _ioctl,					\
+		.flags = _flags | INFO_FL_FUNC,				\
+		.name = #_ioctl,					\
+		.func = _func,						\
+		.debug = _debug,					\
+	}
+
 static struct v4l2_ioctl_info v4l2_ioctls[] = {
 	IOCTL_INFO(VIDIOC_QUERYCAP, 0),
 	IOCTL_INFO(VIDIOC_ENUM_FMT, INFO_FL_CLEAR(v4l2_fmtdesc, type)),
@@ -512,7 +540,7 @@ bool v4l2_is_known_ioctl(unsigned int cmd)
    external ioctl messages as well as internal V4L ioctl */
 void v4l_printk_ioctl(unsigned int cmd)
 {
-	char *dir, *type;
+	const char *dir, *type;
 
 	switch (_IOC_TYPE(cmd)) {
 	case 'd':
@@ -523,10 +551,11 @@ void v4l_printk_ioctl(unsigned int cmd)
 			type = "v4l2";
 			break;
 		}
-		printk("%s", v4l2_ioctls[_IOC_NR(cmd)].name);
+		pr_cont("%s", v4l2_ioctls[_IOC_NR(cmd)].name);
 		return;
 	default:
 		type = "unknown";
+		break;
 	}
 
 	switch (_IOC_DIR(cmd)) {
@@ -536,7 +565,7 @@ void v4l_printk_ioctl(unsigned int cmd)
 	case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
 	default:                     dir = "*ERR*"; break;
 	}
-	printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
+	pr_cont("%s ioctl '%c', dir=%s, #%d (0x%08x)",
 		type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
 }
 EXPORT_SYMBOL(v4l_printk_ioctl);
@@ -546,6 +575,9 @@ static long __video_do_ioctl(struct file *file,
 {
 	struct video_device *vfd = video_devdata(file);
 	const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
+	bool write_only = false;
+	struct v4l2_ioctl_info default_info;
+	const struct v4l2_ioctl_info *info;
 	void *fh = file->private_data;
 	struct v4l2_fh *vfh = NULL;
 	int use_fh_prio = 0;
@@ -563,23 +595,40 @@ static long __video_do_ioctl(struct file *file,
 	}
 
 	if (v4l2_is_known_ioctl(cmd)) {
-		struct v4l2_ioctl_info *info = &v4l2_ioctls[_IOC_NR(cmd)];
+		info = &v4l2_ioctls[_IOC_NR(cmd)];
 
 	        if (!test_bit(_IOC_NR(cmd), vfd->valid_ioctls) &&
 		    !((info->flags & INFO_FL_CTRL) && vfh && vfh->ctrl_handler))
-			return -ENOTTY;
+			goto error;
 
 		if (use_fh_prio && (info->flags & INFO_FL_PRIO)) {
 			ret = v4l2_prio_check(vfd->prio, vfh->prio);
 			if (ret)
-				return ret;
+				goto error;
 		}
+	} else {
+		default_info.ioctl = cmd;
+		default_info.flags = 0;
+		default_info.debug = NULL;
+		info = &default_info;
 	}
 
-	if ((vfd->debug & V4L2_DEBUG_IOCTL) &&
-				!(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
+	write_only = _IOC_DIR(cmd) == _IOC_WRITE;
+	if (info->debug && write_only && vfd->debug > V4L2_DEBUG_IOCTL) {
 		v4l_print_ioctl(vfd->name, cmd);
-		printk(KERN_CONT "\n");
+		pr_cont(": ");
+		info->debug(arg);
+	}
+	if (info->flags & INFO_FL_STD) {
+		typedef int (*vidioc_op)(struct file *file, void *fh, void *p);
+		const void *p = vfd->ioctl_ops;
+		const vidioc_op *vidioc = p + info->offset;
+
+		ret = (*vidioc)(file, fh, arg);
+		goto error;
+	} else if (info->flags & INFO_FL_FUNC) {
+		ret = info->func(ops, file, fh, arg);
+		goto error;
 	}
 
 	switch (cmd) {
@@ -2100,10 +2149,26 @@ static long __video_do_ioctl(struct file *file,
 		break;
 	} /* switch */
 
-	if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
-		if (ret < 0) {
-			v4l_print_ioctl(vfd->name, cmd);
-			printk(KERN_CONT " error %ld\n", ret);
+error:
+	if (vfd->debug) {
+		if (write_only && vfd->debug > V4L2_DEBUG_IOCTL) {
+			if (ret)
+				pr_info("%s: error %ld\n",
+					video_device_node_name(vfd), ret);
+			return ret;
+		}
+		v4l_print_ioctl(vfd->name, cmd);
+		if (ret)
+			pr_cont(": error %ld\n", ret);
+		else if (vfd->debug == V4L2_DEBUG_IOCTL)
+			pr_cont("\n");
+		else if (!info->debug)
+			return ret;
+		else if (_IOC_DIR(cmd) == _IOC_NONE)
+			info->debug(arg);
+		else {
+			pr_cont(": ");
+			info->debug(arg);
 		}
 	}
 
-- 
1.7.10


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

* [RFCv1 PATCH 05/32] v4l2-ioctl.c: remove an unnecessary #ifdef.
  2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
                     ` (2 preceding siblings ...)
  2012-06-10 10:25   ` [RFCv1 PATCH 04/32] v4l2-ioctl.c: v4l2-ioctl: add debug and callback/offset functionality Hans Verkuil
@ 2012-06-10 10:25   ` Hans Verkuil
  2012-06-10 10:25   ` [RFCv1 PATCH 06/32] v4l2-ioctl.c: use the new table for querycap and i/o ioctls Hans Verkuil
                     ` (26 subsequent siblings)
  30 siblings, 0 replies; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 10:25 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/video/v4l2-ioctl.c |    2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
index a4115ce..109615d 100644
--- a/drivers/media/video/v4l2-ioctl.c
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -506,10 +506,8 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
 	IOCTL_INFO(VIDIOC_TRY_ENCODER_CMD, INFO_FL_CLEAR(v4l2_encoder_cmd, flags)),
 	IOCTL_INFO(VIDIOC_DECODER_CMD, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_TRY_DECODER_CMD, 0),
-#ifdef CONFIG_VIDEO_ADV_DEBUG
 	IOCTL_INFO(VIDIOC_DBG_S_REGISTER, 0),
 	IOCTL_INFO(VIDIOC_DBG_G_REGISTER, 0),
-#endif
 	IOCTL_INFO(VIDIOC_DBG_G_CHIP_IDENT, 0),
 	IOCTL_INFO(VIDIOC_S_HW_FREQ_SEEK, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_ENUM_DV_PRESETS, 0),
-- 
1.7.10


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

* [RFCv1 PATCH 06/32] v4l2-ioctl.c: use the new table for querycap and i/o ioctls.
  2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
                     ` (3 preceding siblings ...)
  2012-06-10 10:25   ` [RFCv1 PATCH 05/32] v4l2-ioctl.c: remove an unnecessary #ifdef Hans Verkuil
@ 2012-06-10 10:25   ` Hans Verkuil
  2012-06-10 10:25   ` [RFCv1 PATCH 07/32] v4l2-ioctl.c: use the new table for priority ioctls Hans Verkuil
                     ` (25 subsequent siblings)
  30 siblings, 0 replies; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 10:25 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/video/v4l2-ioctl.c |  336 ++++++++++++++++----------------------
 1 file changed, 141 insertions(+), 195 deletions(-)

diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
index 109615d..f33bb00 100644
--- a/drivers/media/video/v4l2-ioctl.c
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -183,6 +183,71 @@ static const char *v4l2_memory_names[] = {
 /* ------------------------------------------------------------------ */
 /* debug help functions                                               */
 
+static void v4l_print_querycap(const void *arg)
+{
+	const struct v4l2_capability *p = arg;
+
+	pr_cont("driver=%s, card=%s, bus=%s, version=0x%08x, "
+		"capabilities=0x%08x, device_caps=0x%08x\n",
+		p->driver, p->card, p->bus_info,
+		p->version, p->capabilities, p->device_caps);
+}
+
+static void v4l_print_enuminput(const void *arg)
+{
+	const struct v4l2_input *p = arg;
+
+	pr_cont("index=%u, name=%s, type=%u, audioset=0x%x, tuner=%u, "
+		"std=0x%08Lx, status=0x%x, capabilities=0x%x\n",
+		p->index, p->name, p->type, p->audioset, p->tuner,
+		(unsigned long long)p->std, p->status, p->capabilities);
+}
+
+static void v4l_print_enumoutput(const void *arg)
+{
+	const struct v4l2_output *p = arg;
+
+	pr_cont("index=%u, name=%s, type=%u, audioset=0x%x, "
+		"modulator=%u, std=0x%08Lx, capabilities=0x%x\n",
+		p->index, p->name, p->type, p->audioset, p->modulator,
+		(unsigned long long)p->std, p->capabilities);
+}
+
+static void v4l_print_audio(const void *arg)
+{
+	const struct v4l2_audio *p = arg;
+
+	pr_cont("index=%u, name=%s, capability=0x%x, mode=0x%x\n",
+			p->index, p->name, p->capability, p->mode);
+}
+
+static void v4l_print_s_audio(const void *arg)
+{
+	const struct v4l2_audio *p = arg;
+
+	pr_cont("index=%u, mode=0x%x\n", p->index, p->mode);
+}
+
+static void v4l_print_audioout(const void *arg)
+{
+	const struct v4l2_audioout *p = arg;
+
+	pr_cont("index=%u, name=%s, capability=0x%x, mode=0x%x\n",
+			p->index, p->name, p->capability, p->mode);
+}
+
+static void v4l_print_s_audioout(const void *arg)
+{
+	const struct v4l2_audioout *p = arg;
+
+	pr_cont("index=%u\n", p->index);
+}
+
+static void v4l_print_u32(const void *arg)
+{
+	pr_cont("value=%u\n", *(const u32 *)arg);
+}
+
 static void dbgbuf(unsigned int cmd, struct video_device *vfd,
 					struct v4l2_buffer *p)
 {
@@ -392,6 +457,69 @@ static int check_fmt(const struct v4l2_ioctl_ops *ops, enum v4l2_buf_type type)
 	return -EINVAL;
 }
 
+static int v4l_querycap(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct v4l2_capability *cap = (struct v4l2_capability *)arg;
+
+	cap->version = LINUX_VERSION_CODE;
+	return ops->vidioc_querycap(file, fh, cap);
+}
+
+static int v4l_s_input(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	return ops->vidioc_s_input(file, fh, *(unsigned int *)arg);
+}
+
+static int v4l_s_output(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	return ops->vidioc_s_output(file, fh, *(unsigned int *)arg);
+}
+
+static int v4l_enuminput(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct v4l2_input *p = arg;
+
+	/*
+	 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
+	 * CAP_STD here based on ioctl handler provided by the
+	 * driver. If the driver doesn't support these
+	 * for a specific input, it must override these flags.
+	 */
+	if (ops->vidioc_s_std)
+		p->capabilities |= V4L2_IN_CAP_STD;
+	if (ops->vidioc_s_dv_preset)
+		p->capabilities |= V4L2_IN_CAP_PRESETS;
+	if (ops->vidioc_s_dv_timings)
+		p->capabilities |= V4L2_IN_CAP_CUSTOM_TIMINGS;
+
+	return ops->vidioc_enum_input(file, fh, p);
+}
+
+static int v4l_enumoutput(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct v4l2_output *p = arg;
+
+	/*
+	 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
+	 * CAP_STD here based on ioctl handler provided by the
+	 * driver. If the driver doesn't support these
+	 * for a specific output, it must override these flags.
+	 */
+	if (ops->vidioc_s_std)
+		p->capabilities |= V4L2_OUT_CAP_STD;
+	if (ops->vidioc_s_dv_preset)
+		p->capabilities |= V4L2_OUT_CAP_PRESETS;
+	if (ops->vidioc_s_dv_timings)
+		p->capabilities |= V4L2_OUT_CAP_CUSTOM_TIMINGS;
+
+	return ops->vidioc_enum_output(file, fh, p);
+}
+
 struct v4l2_ioctl_info {
 	unsigned int ioctl;
 	u32 flags;
@@ -443,7 +571,7 @@ struct v4l2_ioctl_info {
 	}
 
 static struct v4l2_ioctl_info v4l2_ioctls[] = {
-	IOCTL_INFO(VIDIOC_QUERYCAP, 0),
+	IOCTL_INFO_FNC(VIDIOC_QUERYCAP, v4l_querycap, v4l_print_querycap, 0),
 	IOCTL_INFO(VIDIOC_ENUM_FMT, INFO_FL_CLEAR(v4l2_fmtdesc, type)),
 	IOCTL_INFO(VIDIOC_G_FMT, INFO_FL_CLEAR(v4l2_format, type)),
 	IOCTL_INFO(VIDIOC_S_FMT, INFO_FL_PRIO),
@@ -461,22 +589,22 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
 	IOCTL_INFO(VIDIOC_G_STD, 0),
 	IOCTL_INFO(VIDIOC_S_STD, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_ENUMSTD, INFO_FL_CLEAR(v4l2_standard, index)),
-	IOCTL_INFO(VIDIOC_ENUMINPUT, INFO_FL_CLEAR(v4l2_input, index)),
+	IOCTL_INFO_FNC(VIDIOC_ENUMINPUT, v4l_enuminput, v4l_print_enuminput, INFO_FL_CLEAR(v4l2_input, index)),
 	IOCTL_INFO(VIDIOC_G_CTRL, INFO_FL_CTRL),
 	IOCTL_INFO(VIDIOC_S_CTRL, INFO_FL_PRIO | INFO_FL_CTRL),
 	IOCTL_INFO(VIDIOC_G_TUNER, INFO_FL_CLEAR(v4l2_tuner, index)),
 	IOCTL_INFO(VIDIOC_S_TUNER, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_G_AUDIO, 0),
-	IOCTL_INFO(VIDIOC_S_AUDIO, INFO_FL_PRIO),
+	IOCTL_INFO_STD(VIDIOC_G_AUDIO, vidioc_g_audio, v4l_print_audio, 0),
+	IOCTL_INFO_STD(VIDIOC_S_AUDIO, vidioc_s_audio, v4l_print_s_audio, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_QUERYCTRL, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_queryctrl, id)),
 	IOCTL_INFO(VIDIOC_QUERYMENU, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_querymenu, index)),
-	IOCTL_INFO(VIDIOC_G_INPUT, 0),
-	IOCTL_INFO(VIDIOC_S_INPUT, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_G_OUTPUT, INFO_FL_CLEAR(v4l2_output, index)),
-	IOCTL_INFO(VIDIOC_S_OUTPUT, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_ENUMOUTPUT, 0),
-	IOCTL_INFO(VIDIOC_G_AUDOUT, 0),
-	IOCTL_INFO(VIDIOC_S_AUDOUT, INFO_FL_PRIO),
+	IOCTL_INFO_STD(VIDIOC_G_INPUT, vidioc_g_input, v4l_print_u32, 0),
+	IOCTL_INFO_FNC(VIDIOC_S_INPUT, v4l_s_input, v4l_print_u32, INFO_FL_PRIO),
+	IOCTL_INFO_STD(VIDIOC_G_OUTPUT, vidioc_g_output, v4l_print_u32, 0),
+	IOCTL_INFO_FNC(VIDIOC_S_OUTPUT, v4l_s_output, v4l_print_u32, INFO_FL_PRIO),
+	IOCTL_INFO_FNC(VIDIOC_ENUMOUTPUT, v4l_enumoutput, v4l_print_enumoutput, INFO_FL_CLEAR(v4l2_output, index)),
+	IOCTL_INFO_STD(VIDIOC_G_AUDOUT, vidioc_g_audout, v4l_print_audioout, 0),
+	IOCTL_INFO_STD(VIDIOC_S_AUDOUT, vidioc_s_audout, v4l_print_s_audioout, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_G_MODULATOR, INFO_FL_CLEAR(v4l2_modulator, index)),
 	IOCTL_INFO(VIDIOC_S_MODULATOR, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_G_FREQUENCY, INFO_FL_CLEAR(v4l2_frequency, tuner)),
@@ -490,8 +618,8 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
 	IOCTL_INFO(VIDIOC_S_JPEGCOMP, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_QUERYSTD, 0),
 	IOCTL_INFO(VIDIOC_TRY_FMT, 0),
-	IOCTL_INFO(VIDIOC_ENUMAUDIO, INFO_FL_CLEAR(v4l2_audio, index)),
-	IOCTL_INFO(VIDIOC_ENUMAUDOUT, INFO_FL_CLEAR(v4l2_audioout, index)),
+	IOCTL_INFO_STD(VIDIOC_ENUMAUDIO, vidioc_enumaudio, v4l_print_audio, INFO_FL_CLEAR(v4l2_audio, index)),
+	IOCTL_INFO_STD(VIDIOC_ENUMAUDOUT, vidioc_enumaudout, v4l_print_audioout, INFO_FL_CLEAR(v4l2_audioout, index)),
 	IOCTL_INFO(VIDIOC_G_PRIORITY, 0),
 	IOCTL_INFO(VIDIOC_S_PRIORITY, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_G_SLICED_VBI_CAP, INFO_FL_CLEAR(v4l2_sliced_vbi_cap, type)),
@@ -631,25 +759,6 @@ static long __video_do_ioctl(struct file *file,
 
 	switch (cmd) {
 
-	/* --- capabilities ------------------------------------------ */
-	case VIDIOC_QUERYCAP:
-	{
-		struct v4l2_capability *cap = (struct v4l2_capability *)arg;
-
-		cap->version = LINUX_VERSION_CODE;
-		ret = ops->vidioc_querycap(file, fh, cap);
-		if (!ret)
-			dbgarg(cmd, "driver=%s, card=%s, bus=%s, "
-					"version=0x%08x, "
-					"capabilities=0x%08x, "
-					"device_caps=0x%08x\n",
-					cap->driver, cap->card, cap->bus_info,
-					cap->version,
-					cap->capabilities,
-					cap->device_caps);
-		break;
-	}
-
 	/* --- priority ------------------------------------------ */
 	case VIDIOC_G_PRIORITY:
 	{
@@ -1164,98 +1273,6 @@ static long __video_do_ioctl(struct file *file,
 						(unsigned long long)*p);
 		break;
 	}
-	/* ------ input switching ---------- */
-	/* FIXME: Inputs can be handled inside videodev2 */
-	case VIDIOC_ENUMINPUT:
-	{
-		struct v4l2_input *p = arg;
-
-		/*
-		 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
-		 * CAP_STD here based on ioctl handler provided by the
-		 * driver. If the driver doesn't support these
-		 * for a specific input, it must override these flags.
-		 */
-		if (ops->vidioc_s_std)
-			p->capabilities |= V4L2_IN_CAP_STD;
-		if (ops->vidioc_s_dv_preset)
-			p->capabilities |= V4L2_IN_CAP_PRESETS;
-		if (ops->vidioc_s_dv_timings)
-			p->capabilities |= V4L2_IN_CAP_CUSTOM_TIMINGS;
-
-		ret = ops->vidioc_enum_input(file, fh, p);
-		if (!ret)
-			dbgarg(cmd, "index=%d, name=%s, type=%d, "
-				"audioset=%d, "
-				"tuner=%d, std=%08Lx, status=%d\n",
-				p->index, p->name, p->type, p->audioset,
-				p->tuner,
-				(unsigned long long)p->std,
-				p->status);
-		break;
-	}
-	case VIDIOC_G_INPUT:
-	{
-		unsigned int *i = arg;
-
-		ret = ops->vidioc_g_input(file, fh, i);
-		if (!ret)
-			dbgarg(cmd, "value=%d\n", *i);
-		break;
-	}
-	case VIDIOC_S_INPUT:
-	{
-		unsigned int *i = arg;
-
-		dbgarg(cmd, "value=%d\n", *i);
-		ret = ops->vidioc_s_input(file, fh, *i);
-		break;
-	}
-
-	/* ------ output switching ---------- */
-	case VIDIOC_ENUMOUTPUT:
-	{
-		struct v4l2_output *p = arg;
-
-		/*
-		 * We set the flags for CAP_PRESETS, CAP_CUSTOM_TIMINGS &
-		 * CAP_STD here based on ioctl handler provided by the
-		 * driver. If the driver doesn't support these
-		 * for a specific output, it must override these flags.
-		 */
-		if (ops->vidioc_s_std)
-			p->capabilities |= V4L2_OUT_CAP_STD;
-		if (ops->vidioc_s_dv_preset)
-			p->capabilities |= V4L2_OUT_CAP_PRESETS;
-		if (ops->vidioc_s_dv_timings)
-			p->capabilities |= V4L2_OUT_CAP_CUSTOM_TIMINGS;
-
-		ret = ops->vidioc_enum_output(file, fh, p);
-		if (!ret)
-			dbgarg(cmd, "index=%d, name=%s, type=%d, "
-				"audioset=0x%x, "
-				"modulator=%d, std=0x%08Lx\n",
-				p->index, p->name, p->type, p->audioset,
-				p->modulator, (unsigned long long)p->std);
-		break;
-	}
-	case VIDIOC_G_OUTPUT:
-	{
-		unsigned int *i = arg;
-
-		ret = ops->vidioc_g_output(file, fh, i);
-		if (!ret)
-			dbgarg(cmd, "value=%d\n", *i);
-		break;
-	}
-	case VIDIOC_S_OUTPUT:
-	{
-		unsigned int *i = arg;
-
-		dbgarg(cmd, "value=%d\n", *i);
-		ret = ops->vidioc_s_output(file, fh, *i);
-		break;
-	}
 
 	/* --- controls ---------------------------------------------- */
 	case VIDIOC_QUERYCTRL:
@@ -1426,77 +1443,6 @@ static long __video_do_ioctl(struct file *file,
 				p->id, p->index);
 		break;
 	}
-	/* --- audio ---------------------------------------------- */
-	case VIDIOC_ENUMAUDIO:
-	{
-		struct v4l2_audio *p = arg;
-
-		ret = ops->vidioc_enumaudio(file, fh, p);
-		if (!ret)
-			dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
-					"mode=0x%x\n", p->index, p->name,
-					p->capability, p->mode);
-		else
-			dbgarg(cmd, "index=%d\n", p->index);
-		break;
-	}
-	case VIDIOC_G_AUDIO:
-	{
-		struct v4l2_audio *p = arg;
-
-		ret = ops->vidioc_g_audio(file, fh, p);
-		if (!ret)
-			dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
-					"mode=0x%x\n", p->index,
-					p->name, p->capability, p->mode);
-		else
-			dbgarg(cmd, "index=%d\n", p->index);
-		break;
-	}
-	case VIDIOC_S_AUDIO:
-	{
-		struct v4l2_audio *p = arg;
-
-		dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
-					"mode=0x%x\n", p->index, p->name,
-					p->capability, p->mode);
-		ret = ops->vidioc_s_audio(file, fh, p);
-		break;
-	}
-	case VIDIOC_ENUMAUDOUT:
-	{
-		struct v4l2_audioout *p = arg;
-
-		dbgarg(cmd, "Enum for index=%d\n", p->index);
-		ret = ops->vidioc_enumaudout(file, fh, p);
-		if (!ret)
-			dbgarg2("index=%d, name=%s, capability=%d, "
-					"mode=%d\n", p->index, p->name,
-					p->capability, p->mode);
-		break;
-	}
-	case VIDIOC_G_AUDOUT:
-	{
-		struct v4l2_audioout *p = arg;
-
-		ret = ops->vidioc_g_audout(file, fh, p);
-		if (!ret)
-			dbgarg2("index=%d, name=%s, capability=%d, "
-					"mode=%d\n", p->index, p->name,
-					p->capability, p->mode);
-		break;
-	}
-	case VIDIOC_S_AUDOUT:
-	{
-		struct v4l2_audioout *p = arg;
-
-		dbgarg(cmd, "index=%d, name=%s, capability=%d, "
-					"mode=%d\n", p->index, p->name,
-					p->capability, p->mode);
-
-		ret = ops->vidioc_s_audout(file, fh, p);
-		break;
-	}
 	case VIDIOC_G_MODULATOR:
 	{
 		struct v4l2_modulator *p = arg;
-- 
1.7.10


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

* [RFCv1 PATCH 07/32] v4l2-ioctl.c: use the new table for priority ioctls.
  2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
                     ` (4 preceding siblings ...)
  2012-06-10 10:25   ` [RFCv1 PATCH 06/32] v4l2-ioctl.c: use the new table for querycap and i/o ioctls Hans Verkuil
@ 2012-06-10 10:25   ` Hans Verkuil
  2012-06-10 10:25   ` [RFCv1 PATCH 08/32] v4l2-ioctl.c: use the new table for format/framebuffer ioctls Hans Verkuil
                     ` (24 subsequent siblings)
  30 siblings, 0 replies; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 10:25 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/video/v4l2-ioctl.c |   60 ++++++++++++++++++--------------------
 1 file changed, 29 insertions(+), 31 deletions(-)

diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
index f33bb00..4a7b75b 100644
--- a/drivers/media/video/v4l2-ioctl.c
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -478,6 +478,33 @@ static int v4l_s_output(const struct v4l2_ioctl_ops *ops,
 	return ops->vidioc_s_output(file, fh, *(unsigned int *)arg);
 }
 
+static int v4l_g_priority(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct video_device *vfd;
+	u32 *p = arg;
+
+	if (ops->vidioc_g_priority)
+		return ops->vidioc_g_priority(file, fh, arg);
+	vfd = video_devdata(file);
+	*p = v4l2_prio_max(&vfd->v4l2_dev->prio);
+	return 0;
+}
+
+static int v4l_s_priority(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct video_device *vfd;
+	struct v4l2_fh *vfh;
+	u32 *p = arg;
+
+	if (ops->vidioc_s_priority)
+		return ops->vidioc_s_priority(file, fh, *p);
+	vfd = video_devdata(file);
+	vfh = file->private_data;
+	return v4l2_prio_change(&vfd->v4l2_dev->prio, &vfh->prio, *p);
+}
+
 static int v4l_enuminput(const struct v4l2_ioctl_ops *ops,
 				struct file *file, void *fh, void *arg)
 {
@@ -620,8 +647,8 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
 	IOCTL_INFO(VIDIOC_TRY_FMT, 0),
 	IOCTL_INFO_STD(VIDIOC_ENUMAUDIO, vidioc_enumaudio, v4l_print_audio, INFO_FL_CLEAR(v4l2_audio, index)),
 	IOCTL_INFO_STD(VIDIOC_ENUMAUDOUT, vidioc_enumaudout, v4l_print_audioout, INFO_FL_CLEAR(v4l2_audioout, index)),
-	IOCTL_INFO(VIDIOC_G_PRIORITY, 0),
-	IOCTL_INFO(VIDIOC_S_PRIORITY, INFO_FL_PRIO),
+	IOCTL_INFO_FNC(VIDIOC_G_PRIORITY, v4l_g_priority, v4l_print_u32, 0),
+	IOCTL_INFO_FNC(VIDIOC_S_PRIORITY, v4l_s_priority, v4l_print_u32, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_G_SLICED_VBI_CAP, INFO_FL_CLEAR(v4l2_sliced_vbi_cap, type)),
 	IOCTL_INFO(VIDIOC_LOG_STATUS, 0),
 	IOCTL_INFO(VIDIOC_G_EXT_CTRLS, INFO_FL_CTRL),
@@ -758,35 +785,6 @@ static long __video_do_ioctl(struct file *file,
 	}
 
 	switch (cmd) {
-
-	/* --- priority ------------------------------------------ */
-	case VIDIOC_G_PRIORITY:
-	{
-		enum v4l2_priority *p = arg;
-
-		if (ops->vidioc_g_priority) {
-			ret = ops->vidioc_g_priority(file, fh, p);
-		} else if (use_fh_prio) {
-			*p = v4l2_prio_max(&vfd->v4l2_dev->prio);
-			ret = 0;
-		}
-		if (!ret)
-			dbgarg(cmd, "priority is %d\n", *p);
-		break;
-	}
-	case VIDIOC_S_PRIORITY:
-	{
-		enum v4l2_priority *p = arg;
-
-		dbgarg(cmd, "setting priority to %d\n", *p);
-		if (ops->vidioc_s_priority)
-			ret = ops->vidioc_s_priority(file, fh, *p);
-		else
-			ret = v4l2_prio_change(&vfd->v4l2_dev->prio,
-							&vfh->prio, *p);
-		break;
-	}
-
 	/* --- capture ioctls ---------------------------------------- */
 	case VIDIOC_ENUM_FMT:
 	{
-- 
1.7.10


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

* [RFCv1 PATCH 08/32] v4l2-ioctl.c: use the new table for format/framebuffer ioctls.
  2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
                     ` (5 preceding siblings ...)
  2012-06-10 10:25   ` [RFCv1 PATCH 07/32] v4l2-ioctl.c: use the new table for priority ioctls Hans Verkuil
@ 2012-06-10 10:25   ` Hans Verkuil
  2012-06-10 10:25   ` [RFCv1 PATCH 09/32] v4l2-ioctl.c: use the new table for overlay/streamon/off ioctls Hans Verkuil
                     ` (23 subsequent siblings)
  30 siblings, 0 replies; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 10:25 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/video/v4l2-ioctl.c |  692 +++++++++++++++++++-------------------
 1 file changed, 346 insertions(+), 346 deletions(-)

diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
index 4a7b75b..48852ca 100644
--- a/drivers/media/video/v4l2-ioctl.c
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -243,6 +243,130 @@ static void v4l_print_s_audioout(const void *arg)
 	pr_cont("index=%u\n", p->index);
 }
 
+static void v4l_print_fmtdesc(const void *arg)
+{
+	const struct v4l2_fmtdesc *p = arg;
+
+	pr_cont("index=%u, type=%s, flags=0x%x, pixelformat=%c%c%c%c, description='%s'\n",
+		p->index, prt_names(p->type, v4l2_type_names),
+		p->flags, (p->pixelformat & 0xff),
+		(p->pixelformat >>  8) & 0xff,
+		(p->pixelformat >> 16) & 0xff,
+		(p->pixelformat >> 24) & 0xff,
+		p->description);
+}
+
+static void v4l_print_format(const void *arg)
+{
+	const struct v4l2_format *p = arg;
+	const struct v4l2_pix_format *pix;
+	const struct v4l2_pix_format_mplane *mp;
+	const struct v4l2_vbi_format *vbi;
+	const struct v4l2_sliced_vbi_format *sliced;
+	const struct v4l2_window *win;
+	const struct v4l2_clip *clip;
+	unsigned i;
+
+	pr_cont("type=%s", prt_names(p->type, v4l2_type_names));
+	switch (p->type) {
+	case V4L2_BUF_TYPE_VIDEO_CAPTURE:
+	case V4L2_BUF_TYPE_VIDEO_OUTPUT:
+		pix = &p->fmt.pix;
+		pr_cont(", width=%u, height=%u, "
+			"pixelformat=%c%c%c%c, field=%s, "
+			"bytesperline=%u sizeimage=%u, colorspace=%d\n",
+			pix->width, pix->height,
+			(pix->pixelformat & 0xff),
+			(pix->pixelformat >>  8) & 0xff,
+			(pix->pixelformat >> 16) & 0xff,
+			(pix->pixelformat >> 24) & 0xff,
+			prt_names(pix->field, v4l2_field_names),
+			pix->bytesperline, pix->sizeimage,
+			pix->colorspace);
+		break;
+	case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
+	case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
+		mp = &p->fmt.pix_mp;
+		pr_cont(", width=%u, height=%u, "
+			"format=%c%c%c%c, field=%s, "
+			"colorspace=%d, num_planes=%u\n",
+			mp->width, mp->height,
+			(mp->pixelformat & 0xff),
+			(mp->pixelformat >>  8) & 0xff,
+			(mp->pixelformat >> 16) & 0xff,
+			(mp->pixelformat >> 24) & 0xff,
+			prt_names(mp->field, v4l2_field_names),
+			mp->colorspace, mp->num_planes);
+		for (i = 0; i < mp->num_planes; i++)
+			pr_info("plane %u: bytesperline=%u sizeimage=%u\n", i,
+					mp->plane_fmt[i].bytesperline,
+					mp->plane_fmt[i].sizeimage);
+		break;
+	case V4L2_BUF_TYPE_VIDEO_OVERLAY:
+	case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
+		win = &p->fmt.win;
+		pr_cont(", wxh=%dx%d, x,y=%d,%d, field=%s, "
+			"chromakey=0x%08x, bitmap=%p, "
+			"global_alpha=0x%02x\n",
+			win->w.width, win->w.height,
+			win->w.left, win->w.top,
+			prt_names(win->field, v4l2_field_names),
+			win->chromakey, win->bitmap, win->global_alpha);
+		clip = win->clips;
+		for (i = 0; i < win->clipcount; i++) {
+			pr_info("clip %u: wxh=%dx%d, x,y=%d,%d\n",
+					i, clip->c.width, clip->c.height,
+					clip->c.left, clip->c.top);
+			clip = clip->next;
+		}
+		break;
+	case V4L2_BUF_TYPE_VBI_CAPTURE:
+	case V4L2_BUF_TYPE_VBI_OUTPUT:
+		vbi = &p->fmt.vbi;
+		pr_cont(", sampling_rate=%u, offset=%u, samples_per_line=%u, "
+			"sample_format=%c%c%c%c, start=%u,%u, count=%u,%u\n",
+			vbi->sampling_rate, vbi->offset,
+			vbi->samples_per_line,
+			(vbi->sample_format & 0xff),
+			(vbi->sample_format >>  8) & 0xff,
+			(vbi->sample_format >> 16) & 0xff,
+			(vbi->sample_format >> 24) & 0xff,
+			vbi->start[0], vbi->start[1],
+			vbi->count[0], vbi->count[1]);
+		break;
+	case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
+	case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
+		sliced = &p->fmt.sliced;
+		pr_cont(", service_set=0x%08x, io_size=%d\n",
+				sliced->service_set, sliced->io_size);
+		for (i = 0; i < 24; i++)
+			pr_info("line[%02u]=0x%04x, 0x%04x\n", i,
+				sliced->service_lines[0][i],
+				sliced->service_lines[1][i]);
+		break;
+	case V4L2_BUF_TYPE_PRIVATE:
+		pr_cont("\n");
+		break;
+	}
+}
+
+static void v4l_print_framebuffer(const void *arg)
+{
+	const struct v4l2_framebuffer *p = arg;
+
+	pr_cont("capability=0x%x, flags=0x%x, base=0x%p, width=%u, "
+		"height=%u, pixelformat=%c%c%c%c, "
+		"bytesperline=%u sizeimage=%u, colorspace=%d\n",
+			p->capability, p->flags, p->base,
+			p->fmt.width, p->fmt.height,
+			(p->fmt.pixelformat & 0xff),
+			(p->fmt.pixelformat >>  8) & 0xff,
+			(p->fmt.pixelformat >> 16) & 0xff,
+			(p->fmt.pixelformat >> 24) & 0xff,
+			p->fmt.bytesperline, p->fmt.sizeimage,
+			p->fmt.colorspace);
+}
+
 static void v4l_print_u32(const void *arg)
 {
 	pr_cont("value=%u\n", *(const u32 *)arg);
@@ -320,41 +444,6 @@ static void dbgtimings(struct video_device *vfd,
 	}
 }
 
-static inline void v4l_print_pix_fmt(struct video_device *vfd,
-						struct v4l2_pix_format *fmt)
-{
-	dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
-		"bytesperline=%d sizeimage=%d, colorspace=%d\n",
-		fmt->width, fmt->height,
-		(fmt->pixelformat & 0xff),
-		(fmt->pixelformat >>  8) & 0xff,
-		(fmt->pixelformat >> 16) & 0xff,
-		(fmt->pixelformat >> 24) & 0xff,
-		prt_names(fmt->field, v4l2_field_names),
-		fmt->bytesperline, fmt->sizeimage, fmt->colorspace);
-};
-
-static inline void v4l_print_pix_fmt_mplane(struct video_device *vfd,
-					    struct v4l2_pix_format_mplane *fmt)
-{
-	int i;
-
-	dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
-		"colorspace=%d, num_planes=%d\n",
-		fmt->width, fmt->height,
-		(fmt->pixelformat & 0xff),
-		(fmt->pixelformat >>  8) & 0xff,
-		(fmt->pixelformat >> 16) & 0xff,
-		(fmt->pixelformat >> 24) & 0xff,
-		prt_names(fmt->field, v4l2_field_names),
-		fmt->colorspace, fmt->num_planes);
-
-	for (i = 0; i < fmt->num_planes; ++i)
-		dbgarg2("plane %d: bytesperline=%d sizeimage=%d\n", i,
-			fmt->plane_fmt[i].bytesperline,
-			fmt->plane_fmt[i].sizeimage);
-}
-
 static inline void v4l_print_ext_ctrls(unsigned int cmd,
 	struct video_device *vfd, struct v4l2_ext_controls *c, int show_vals)
 {
@@ -547,6 +636,222 @@ static int v4l_enumoutput(const struct v4l2_ioctl_ops *ops,
 	return ops->vidioc_enum_output(file, fh, p);
 }
 
+static int v4l_enum_fmt(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct v4l2_fmtdesc *p = arg;
+
+	switch (p->type) {
+	case V4L2_BUF_TYPE_VIDEO_CAPTURE:
+		if (unlikely(!ops->vidioc_enum_fmt_vid_cap))
+			break;
+		return ops->vidioc_enum_fmt_vid_cap(file, fh, arg);
+	case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
+		if (unlikely(!ops->vidioc_enum_fmt_vid_cap_mplane))
+			break;
+		return ops->vidioc_enum_fmt_vid_cap_mplane(file, fh, arg);
+	case V4L2_BUF_TYPE_VIDEO_OVERLAY:
+		if (unlikely(!ops->vidioc_enum_fmt_vid_overlay))
+			break;
+		return ops->vidioc_enum_fmt_vid_overlay(file, fh, arg);
+	case V4L2_BUF_TYPE_VIDEO_OUTPUT:
+		if (unlikely(!ops->vidioc_enum_fmt_vid_out))
+			break;
+		return ops->vidioc_enum_fmt_vid_out(file, fh, arg);
+	case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
+		if (unlikely(!ops->vidioc_enum_fmt_vid_out_mplane))
+			break;
+		return ops->vidioc_enum_fmt_vid_out_mplane(file, fh, arg);
+	case V4L2_BUF_TYPE_PRIVATE:
+		if (unlikely(!ops->vidioc_enum_fmt_type_private))
+			break;
+		return ops->vidioc_enum_fmt_type_private(file, fh, arg);
+	}
+	return -EINVAL;
+}
+
+static int v4l_g_fmt(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct v4l2_format *p = arg;
+
+	switch (p->type) {
+	case V4L2_BUF_TYPE_VIDEO_CAPTURE:
+		if (unlikely(!ops->vidioc_g_fmt_vid_cap))
+			break;
+		return ops->vidioc_g_fmt_vid_cap(file, fh, arg);
+	case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
+		if (unlikely(!ops->vidioc_g_fmt_vid_cap_mplane))
+			break;
+		return ops->vidioc_g_fmt_vid_cap_mplane(file, fh, arg);
+	case V4L2_BUF_TYPE_VIDEO_OVERLAY:
+		if (unlikely(!ops->vidioc_g_fmt_vid_overlay))
+			break;
+		return ops->vidioc_g_fmt_vid_overlay(file, fh, arg);
+	case V4L2_BUF_TYPE_VIDEO_OUTPUT:
+		if (unlikely(!ops->vidioc_g_fmt_vid_out))
+			break;
+		return ops->vidioc_g_fmt_vid_out(file, fh, arg);
+	case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
+		if (unlikely(!ops->vidioc_g_fmt_vid_out_mplane))
+			break;
+		return ops->vidioc_g_fmt_vid_out_mplane(file, fh, arg);
+	case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
+		if (unlikely(!ops->vidioc_g_fmt_vid_out_overlay))
+			break;
+		return ops->vidioc_g_fmt_vid_out_overlay(file, fh, arg);
+	case V4L2_BUF_TYPE_VBI_CAPTURE:
+		if (unlikely(!ops->vidioc_g_fmt_vbi_cap))
+			break;
+		return ops->vidioc_g_fmt_vbi_cap(file, fh, arg);
+	case V4L2_BUF_TYPE_VBI_OUTPUT:
+		if (unlikely(!ops->vidioc_g_fmt_vbi_out))
+			break;
+		return ops->vidioc_g_fmt_vbi_out(file, fh, arg);
+	case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
+		if (unlikely(!ops->vidioc_g_fmt_sliced_vbi_cap))
+			break;
+		return ops->vidioc_g_fmt_sliced_vbi_cap(file, fh, arg);
+	case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
+		if (unlikely(!ops->vidioc_g_fmt_sliced_vbi_out))
+			break;
+		return ops->vidioc_g_fmt_sliced_vbi_out(file, fh, arg);
+	case V4L2_BUF_TYPE_PRIVATE:
+		if (unlikely(!ops->vidioc_g_fmt_type_private))
+			break;
+		return ops->vidioc_g_fmt_type_private(file, fh, arg);
+	}
+	return -EINVAL;
+}
+
+static int v4l_s_fmt(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct v4l2_format *p = arg;
+
+	switch (p->type) {
+	case V4L2_BUF_TYPE_VIDEO_CAPTURE:
+		if (unlikely(!ops->vidioc_s_fmt_vid_cap))
+			break;
+		CLEAR_AFTER_FIELD(p, fmt.pix);
+		return ops->vidioc_s_fmt_vid_cap(file, fh, arg);
+	case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
+		if (unlikely(!ops->vidioc_s_fmt_vid_cap_mplane))
+			break;
+		CLEAR_AFTER_FIELD(p, fmt.pix_mp);
+		return ops->vidioc_s_fmt_vid_cap_mplane(file, fh, arg);
+	case V4L2_BUF_TYPE_VIDEO_OVERLAY:
+		if (unlikely(!ops->vidioc_s_fmt_vid_overlay))
+			break;
+		CLEAR_AFTER_FIELD(p, fmt.win);
+		return ops->vidioc_s_fmt_vid_overlay(file, fh, arg);
+	case V4L2_BUF_TYPE_VIDEO_OUTPUT:
+		if (unlikely(!ops->vidioc_s_fmt_vid_out))
+			break;
+		CLEAR_AFTER_FIELD(p, fmt.pix);
+		return ops->vidioc_s_fmt_vid_out(file, fh, arg);
+	case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
+		if (unlikely(!ops->vidioc_s_fmt_vid_out_mplane))
+			break;
+		CLEAR_AFTER_FIELD(p, fmt.pix_mp);
+		return ops->vidioc_s_fmt_vid_out_mplane(file, fh, arg);
+	case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
+		if (unlikely(!ops->vidioc_s_fmt_vid_out_overlay))
+			break;
+		CLEAR_AFTER_FIELD(p, fmt.win);
+		return ops->vidioc_s_fmt_vid_out_overlay(file, fh, arg);
+	case V4L2_BUF_TYPE_VBI_CAPTURE:
+		if (unlikely(!ops->vidioc_s_fmt_vbi_cap))
+			break;
+		CLEAR_AFTER_FIELD(p, fmt.vbi);
+		return ops->vidioc_s_fmt_vbi_cap(file, fh, arg);
+	case V4L2_BUF_TYPE_VBI_OUTPUT:
+		if (unlikely(!ops->vidioc_s_fmt_vbi_out))
+			break;
+		CLEAR_AFTER_FIELD(p, fmt.vbi);
+		return ops->vidioc_s_fmt_vbi_out(file, fh, arg);
+	case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
+		if (unlikely(!ops->vidioc_s_fmt_sliced_vbi_cap))
+			break;
+		CLEAR_AFTER_FIELD(p, fmt.sliced);
+		return ops->vidioc_s_fmt_sliced_vbi_cap(file, fh, arg);
+	case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
+		if (unlikely(!ops->vidioc_s_fmt_sliced_vbi_out))
+			break;
+		CLEAR_AFTER_FIELD(p, fmt.sliced);
+		return ops->vidioc_s_fmt_sliced_vbi_out(file, fh, arg);
+	case V4L2_BUF_TYPE_PRIVATE:
+		if (unlikely(!ops->vidioc_s_fmt_type_private))
+			break;
+		return ops->vidioc_s_fmt_type_private(file, fh, arg);
+	}
+	return -EINVAL;
+}
+
+static int v4l_try_fmt(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct v4l2_format *p = arg;
+
+	switch (p->type) {
+	case V4L2_BUF_TYPE_VIDEO_CAPTURE:
+		if (unlikely(!ops->vidioc_try_fmt_vid_cap))
+			break;
+		CLEAR_AFTER_FIELD(p, fmt.pix);
+		return ops->vidioc_try_fmt_vid_cap(file, fh, arg);
+	case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
+		if (unlikely(!ops->vidioc_try_fmt_vid_cap_mplane))
+			break;
+		CLEAR_AFTER_FIELD(p, fmt.pix_mp);
+		return ops->vidioc_try_fmt_vid_cap_mplane(file, fh, arg);
+	case V4L2_BUF_TYPE_VIDEO_OVERLAY:
+		if (unlikely(!ops->vidioc_try_fmt_vid_overlay))
+			break;
+		CLEAR_AFTER_FIELD(p, fmt.win);
+		return ops->vidioc_try_fmt_vid_overlay(file, fh, arg);
+	case V4L2_BUF_TYPE_VIDEO_OUTPUT:
+		if (unlikely(!ops->vidioc_try_fmt_vid_out))
+			break;
+		CLEAR_AFTER_FIELD(p, fmt.pix);
+		return ops->vidioc_try_fmt_vid_out(file, fh, arg);
+	case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
+		if (unlikely(!ops->vidioc_try_fmt_vid_out_mplane))
+			break;
+		CLEAR_AFTER_FIELD(p, fmt.pix_mp);
+		return ops->vidioc_try_fmt_vid_out_mplane(file, fh, arg);
+	case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
+		if (unlikely(!ops->vidioc_try_fmt_vid_out_overlay))
+			break;
+		CLEAR_AFTER_FIELD(p, fmt.win);
+		return ops->vidioc_try_fmt_vid_out_overlay(file, fh, arg);
+	case V4L2_BUF_TYPE_VBI_CAPTURE:
+		if (unlikely(!ops->vidioc_try_fmt_vbi_cap))
+			break;
+		CLEAR_AFTER_FIELD(p, fmt.vbi);
+		return ops->vidioc_try_fmt_vbi_cap(file, fh, arg);
+	case V4L2_BUF_TYPE_VBI_OUTPUT:
+		if (unlikely(!ops->vidioc_try_fmt_vbi_out))
+			break;
+		CLEAR_AFTER_FIELD(p, fmt.vbi);
+		return ops->vidioc_try_fmt_vbi_out(file, fh, arg);
+	case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
+		if (unlikely(!ops->vidioc_try_fmt_sliced_vbi_cap))
+			break;
+		CLEAR_AFTER_FIELD(p, fmt.sliced);
+		return ops->vidioc_try_fmt_sliced_vbi_cap(file, fh, arg);
+	case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
+		if (unlikely(!ops->vidioc_try_fmt_sliced_vbi_out))
+			break;
+		CLEAR_AFTER_FIELD(p, fmt.sliced);
+		return ops->vidioc_try_fmt_sliced_vbi_out(file, fh, arg);
+	case V4L2_BUF_TYPE_PRIVATE:
+		if (unlikely(!ops->vidioc_try_fmt_type_private))
+			break;
+		return ops->vidioc_try_fmt_type_private(file, fh, arg);
+	}
+	return -EINVAL;
+}
+
 struct v4l2_ioctl_info {
 	unsigned int ioctl;
 	u32 flags;
@@ -599,13 +904,13 @@ struct v4l2_ioctl_info {
 
 static struct v4l2_ioctl_info v4l2_ioctls[] = {
 	IOCTL_INFO_FNC(VIDIOC_QUERYCAP, v4l_querycap, v4l_print_querycap, 0),
-	IOCTL_INFO(VIDIOC_ENUM_FMT, INFO_FL_CLEAR(v4l2_fmtdesc, type)),
-	IOCTL_INFO(VIDIOC_G_FMT, INFO_FL_CLEAR(v4l2_format, type)),
-	IOCTL_INFO(VIDIOC_S_FMT, INFO_FL_PRIO),
+	IOCTL_INFO_FNC(VIDIOC_ENUM_FMT, v4l_enum_fmt, v4l_print_fmtdesc, INFO_FL_CLEAR(v4l2_fmtdesc, type)),
+	IOCTL_INFO_FNC(VIDIOC_G_FMT, v4l_g_fmt, v4l_print_format, INFO_FL_CLEAR(v4l2_format, type)),
+	IOCTL_INFO_FNC(VIDIOC_S_FMT, v4l_s_fmt, v4l_print_format, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_REQBUFS, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_QUERYBUF, INFO_FL_CLEAR(v4l2_buffer, length)),
-	IOCTL_INFO(VIDIOC_G_FBUF, 0),
-	IOCTL_INFO(VIDIOC_S_FBUF, INFO_FL_PRIO),
+	IOCTL_INFO_STD(VIDIOC_G_FBUF, vidioc_g_fbuf, v4l_print_framebuffer, 0),
+	IOCTL_INFO_STD(VIDIOC_S_FBUF, vidioc_s_fbuf, v4l_print_framebuffer, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_OVERLAY, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_QBUF, 0),
 	IOCTL_INFO(VIDIOC_DQBUF, 0),
@@ -644,7 +949,7 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
 	IOCTL_INFO(VIDIOC_G_JPEGCOMP, 0),
 	IOCTL_INFO(VIDIOC_S_JPEGCOMP, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_QUERYSTD, 0),
-	IOCTL_INFO(VIDIOC_TRY_FMT, 0),
+	IOCTL_INFO_FNC(VIDIOC_TRY_FMT, v4l_try_fmt, v4l_print_format, 0),
 	IOCTL_INFO_STD(VIDIOC_ENUMAUDIO, vidioc_enumaudio, v4l_print_audio, INFO_FL_CLEAR(v4l2_audio, index)),
 	IOCTL_INFO_STD(VIDIOC_ENUMAUDOUT, vidioc_enumaudout, v4l_print_audioout, INFO_FL_CLEAR(v4l2_audioout, index)),
 	IOCTL_INFO_FNC(VIDIOC_G_PRIORITY, v4l_g_priority, v4l_print_u32, 0),
@@ -785,288 +1090,6 @@ static long __video_do_ioctl(struct file *file,
 	}
 
 	switch (cmd) {
-	/* --- capture ioctls ---------------------------------------- */
-	case VIDIOC_ENUM_FMT:
-	{
-		struct v4l2_fmtdesc *f = arg;
-
-		ret = -EINVAL;
-		switch (f->type) {
-		case V4L2_BUF_TYPE_VIDEO_CAPTURE:
-			if (likely(ops->vidioc_enum_fmt_vid_cap))
-				ret = ops->vidioc_enum_fmt_vid_cap(file, fh, f);
-			break;
-		case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
-			if (likely(ops->vidioc_enum_fmt_vid_cap_mplane))
-				ret = ops->vidioc_enum_fmt_vid_cap_mplane(file,
-									fh, f);
-			break;
-		case V4L2_BUF_TYPE_VIDEO_OVERLAY:
-			if (likely(ops->vidioc_enum_fmt_vid_overlay))
-				ret = ops->vidioc_enum_fmt_vid_overlay(file,
-					fh, f);
-			break;
-		case V4L2_BUF_TYPE_VIDEO_OUTPUT:
-			if (likely(ops->vidioc_enum_fmt_vid_out))
-				ret = ops->vidioc_enum_fmt_vid_out(file, fh, f);
-			break;
-		case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
-			if (likely(ops->vidioc_enum_fmt_vid_out_mplane))
-				ret = ops->vidioc_enum_fmt_vid_out_mplane(file,
-									fh, f);
-			break;
-		case V4L2_BUF_TYPE_PRIVATE:
-			if (likely(ops->vidioc_enum_fmt_type_private))
-				ret = ops->vidioc_enum_fmt_type_private(file,
-								fh, f);
-			break;
-		default:
-			break;
-		}
-		if (likely(!ret))
-			dbgarg(cmd, "index=%d, type=%d, flags=%d, "
-				"pixelformat=%c%c%c%c, description='%s'\n",
-				f->index, f->type, f->flags,
-				(f->pixelformat & 0xff),
-				(f->pixelformat >>  8) & 0xff,
-				(f->pixelformat >> 16) & 0xff,
-				(f->pixelformat >> 24) & 0xff,
-				f->description);
-		break;
-	}
-	case VIDIOC_G_FMT:
-	{
-		struct v4l2_format *f = (struct v4l2_format *)arg;
-
-		/* FIXME: Should be one dump per type */
-		dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
-
-		ret = -EINVAL;
-		switch (f->type) {
-		case V4L2_BUF_TYPE_VIDEO_CAPTURE:
-			if (ops->vidioc_g_fmt_vid_cap)
-				ret = ops->vidioc_g_fmt_vid_cap(file, fh, f);
-			if (!ret)
-				v4l_print_pix_fmt(vfd, &f->fmt.pix);
-			break;
-		case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
-			if (ops->vidioc_g_fmt_vid_cap_mplane)
-				ret = ops->vidioc_g_fmt_vid_cap_mplane(file,
-									fh, f);
-			if (!ret)
-				v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
-			break;
-		case V4L2_BUF_TYPE_VIDEO_OVERLAY:
-			if (likely(ops->vidioc_g_fmt_vid_overlay))
-				ret = ops->vidioc_g_fmt_vid_overlay(file,
-								    fh, f);
-			break;
-		case V4L2_BUF_TYPE_VIDEO_OUTPUT:
-			if (ops->vidioc_g_fmt_vid_out)
-				ret = ops->vidioc_g_fmt_vid_out(file, fh, f);
-			if (!ret)
-				v4l_print_pix_fmt(vfd, &f->fmt.pix);
-			break;
-		case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
-			if (ops->vidioc_g_fmt_vid_out_mplane)
-				ret = ops->vidioc_g_fmt_vid_out_mplane(file,
-									fh, f);
-			if (!ret)
-				v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
-			break;
-		case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
-			if (likely(ops->vidioc_g_fmt_vid_out_overlay))
-				ret = ops->vidioc_g_fmt_vid_out_overlay(file,
-				       fh, f);
-			break;
-		case V4L2_BUF_TYPE_VBI_CAPTURE:
-			if (likely(ops->vidioc_g_fmt_vbi_cap))
-				ret = ops->vidioc_g_fmt_vbi_cap(file, fh, f);
-			break;
-		case V4L2_BUF_TYPE_VBI_OUTPUT:
-			if (likely(ops->vidioc_g_fmt_vbi_out))
-				ret = ops->vidioc_g_fmt_vbi_out(file, fh, f);
-			break;
-		case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
-			if (likely(ops->vidioc_g_fmt_sliced_vbi_cap))
-				ret = ops->vidioc_g_fmt_sliced_vbi_cap(file,
-									fh, f);
-			break;
-		case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
-			if (likely(ops->vidioc_g_fmt_sliced_vbi_out))
-				ret = ops->vidioc_g_fmt_sliced_vbi_out(file,
-									fh, f);
-			break;
-		case V4L2_BUF_TYPE_PRIVATE:
-			if (likely(ops->vidioc_g_fmt_type_private))
-				ret = ops->vidioc_g_fmt_type_private(file,
-								fh, f);
-			break;
-		}
-		break;
-	}
-	case VIDIOC_S_FMT:
-	{
-		struct v4l2_format *f = (struct v4l2_format *)arg;
-
-		ret = -EINVAL;
-
-		/* FIXME: Should be one dump per type */
-		dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
-
-		switch (f->type) {
-		case V4L2_BUF_TYPE_VIDEO_CAPTURE:
-			CLEAR_AFTER_FIELD(f, fmt.pix);
-			v4l_print_pix_fmt(vfd, &f->fmt.pix);
-			if (ops->vidioc_s_fmt_vid_cap)
-				ret = ops->vidioc_s_fmt_vid_cap(file, fh, f);
-			break;
-		case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
-			CLEAR_AFTER_FIELD(f, fmt.pix_mp);
-			v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
-			if (ops->vidioc_s_fmt_vid_cap_mplane)
-				ret = ops->vidioc_s_fmt_vid_cap_mplane(file,
-									fh, f);
-			break;
-		case V4L2_BUF_TYPE_VIDEO_OVERLAY:
-			CLEAR_AFTER_FIELD(f, fmt.win);
-			if (ops->vidioc_s_fmt_vid_overlay)
-				ret = ops->vidioc_s_fmt_vid_overlay(file,
-								    fh, f);
-			break;
-		case V4L2_BUF_TYPE_VIDEO_OUTPUT:
-			CLEAR_AFTER_FIELD(f, fmt.pix);
-			v4l_print_pix_fmt(vfd, &f->fmt.pix);
-			if (ops->vidioc_s_fmt_vid_out)
-				ret = ops->vidioc_s_fmt_vid_out(file, fh, f);
-			break;
-		case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
-			CLEAR_AFTER_FIELD(f, fmt.pix_mp);
-			v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
-			if (ops->vidioc_s_fmt_vid_out_mplane)
-				ret = ops->vidioc_s_fmt_vid_out_mplane(file,
-									fh, f);
-			break;
-		case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
-			CLEAR_AFTER_FIELD(f, fmt.win);
-			if (ops->vidioc_s_fmt_vid_out_overlay)
-				ret = ops->vidioc_s_fmt_vid_out_overlay(file,
-					fh, f);
-			break;
-		case V4L2_BUF_TYPE_VBI_CAPTURE:
-			CLEAR_AFTER_FIELD(f, fmt.vbi);
-			if (likely(ops->vidioc_s_fmt_vbi_cap))
-				ret = ops->vidioc_s_fmt_vbi_cap(file, fh, f);
-			break;
-		case V4L2_BUF_TYPE_VBI_OUTPUT:
-			CLEAR_AFTER_FIELD(f, fmt.vbi);
-			if (likely(ops->vidioc_s_fmt_vbi_out))
-				ret = ops->vidioc_s_fmt_vbi_out(file, fh, f);
-			break;
-		case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
-			CLEAR_AFTER_FIELD(f, fmt.sliced);
-			if (likely(ops->vidioc_s_fmt_sliced_vbi_cap))
-				ret = ops->vidioc_s_fmt_sliced_vbi_cap(file,
-									fh, f);
-			break;
-		case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
-			CLEAR_AFTER_FIELD(f, fmt.sliced);
-			if (likely(ops->vidioc_s_fmt_sliced_vbi_out))
-				ret = ops->vidioc_s_fmt_sliced_vbi_out(file,
-									fh, f);
-
-			break;
-		case V4L2_BUF_TYPE_PRIVATE:
-			/* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
-			if (likely(ops->vidioc_s_fmt_type_private))
-				ret = ops->vidioc_s_fmt_type_private(file,
-								fh, f);
-			break;
-		}
-		break;
-	}
-	case VIDIOC_TRY_FMT:
-	{
-		struct v4l2_format *f = (struct v4l2_format *)arg;
-
-		/* FIXME: Should be one dump per type */
-		dbgarg(cmd, "type=%s\n", prt_names(f->type,
-						v4l2_type_names));
-		ret = -EINVAL;
-		switch (f->type) {
-		case V4L2_BUF_TYPE_VIDEO_CAPTURE:
-			CLEAR_AFTER_FIELD(f, fmt.pix);
-			if (ops->vidioc_try_fmt_vid_cap)
-				ret = ops->vidioc_try_fmt_vid_cap(file, fh, f);
-			if (!ret)
-				v4l_print_pix_fmt(vfd, &f->fmt.pix);
-			break;
-		case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
-			CLEAR_AFTER_FIELD(f, fmt.pix_mp);
-			if (ops->vidioc_try_fmt_vid_cap_mplane)
-				ret = ops->vidioc_try_fmt_vid_cap_mplane(file,
-									 fh, f);
-			if (!ret)
-				v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
-			break;
-		case V4L2_BUF_TYPE_VIDEO_OVERLAY:
-			CLEAR_AFTER_FIELD(f, fmt.win);
-			if (likely(ops->vidioc_try_fmt_vid_overlay))
-				ret = ops->vidioc_try_fmt_vid_overlay(file,
-					fh, f);
-			break;
-		case V4L2_BUF_TYPE_VIDEO_OUTPUT:
-			CLEAR_AFTER_FIELD(f, fmt.pix);
-			if (ops->vidioc_try_fmt_vid_out)
-				ret = ops->vidioc_try_fmt_vid_out(file, fh, f);
-			if (!ret)
-				v4l_print_pix_fmt(vfd, &f->fmt.pix);
-			break;
-		case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
-			CLEAR_AFTER_FIELD(f, fmt.pix_mp);
-			if (ops->vidioc_try_fmt_vid_out_mplane)
-				ret = ops->vidioc_try_fmt_vid_out_mplane(file,
-									 fh, f);
-			if (!ret)
-				v4l_print_pix_fmt_mplane(vfd, &f->fmt.pix_mp);
-			break;
-		case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
-			CLEAR_AFTER_FIELD(f, fmt.win);
-			if (likely(ops->vidioc_try_fmt_vid_out_overlay))
-				ret = ops->vidioc_try_fmt_vid_out_overlay(file,
-				       fh, f);
-			break;
-		case V4L2_BUF_TYPE_VBI_CAPTURE:
-			CLEAR_AFTER_FIELD(f, fmt.vbi);
-			if (likely(ops->vidioc_try_fmt_vbi_cap))
-				ret = ops->vidioc_try_fmt_vbi_cap(file, fh, f);
-			break;
-		case V4L2_BUF_TYPE_VBI_OUTPUT:
-			CLEAR_AFTER_FIELD(f, fmt.vbi);
-			if (likely(ops->vidioc_try_fmt_vbi_out))
-				ret = ops->vidioc_try_fmt_vbi_out(file, fh, f);
-			break;
-		case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
-			CLEAR_AFTER_FIELD(f, fmt.sliced);
-			if (likely(ops->vidioc_try_fmt_sliced_vbi_cap))
-				ret = ops->vidioc_try_fmt_sliced_vbi_cap(file,
-								fh, f);
-			break;
-		case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
-			CLEAR_AFTER_FIELD(f, fmt.sliced);
-			if (likely(ops->vidioc_try_fmt_sliced_vbi_out))
-				ret = ops->vidioc_try_fmt_sliced_vbi_out(file,
-								fh, f);
-			break;
-		case V4L2_BUF_TYPE_PRIVATE:
-			/* CLEAR_AFTER_FIELD(f, fmt.raw_data); <- does nothing */
-			if (likely(ops->vidioc_try_fmt_type_private))
-				ret = ops->vidioc_try_fmt_type_private(file,
-								fh, f);
-			break;
-		}
-		break;
-	}
 	/* FIXME: Those buf reqs could be handled here,
 	   with some changes on videobuf to allow its header to be included at
 	   videodev2.h or being merged at videodev2.
@@ -1136,29 +1159,6 @@ static long __video_do_ioctl(struct file *file,
 		ret = ops->vidioc_overlay(file, fh, *i);
 		break;
 	}
-	case VIDIOC_G_FBUF:
-	{
-		struct v4l2_framebuffer *p = arg;
-
-		ret = ops->vidioc_g_fbuf(file, fh, arg);
-		if (!ret) {
-			dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
-					p->capability, p->flags,
-					(unsigned long)p->base);
-			v4l_print_pix_fmt(vfd, &p->fmt);
-		}
-		break;
-	}
-	case VIDIOC_S_FBUF:
-	{
-		struct v4l2_framebuffer *p = arg;
-
-		dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
-			p->capability, p->flags, (unsigned long)p->base);
-		v4l_print_pix_fmt(vfd, &p->fmt);
-		ret = ops->vidioc_s_fbuf(file, fh, arg);
-		break;
-	}
 	case VIDIOC_STREAMON:
 	{
 		enum v4l2_buf_type i = *(int *)arg;
-- 
1.7.10


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

* [RFCv1 PATCH 09/32] v4l2-ioctl.c: use the new table for overlay/streamon/off ioctls.
  2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
                     ` (6 preceding siblings ...)
  2012-06-10 10:25   ` [RFCv1 PATCH 08/32] v4l2-ioctl.c: use the new table for format/framebuffer ioctls Hans Verkuil
@ 2012-06-10 10:25   ` Hans Verkuil
  2012-06-10 10:25   ` [RFCv1 PATCH 10/32] v4l2-ioctl.c: use the new table for std/tuner/modulator ioctls Hans Verkuil
                     ` (22 subsequent siblings)
  30 siblings, 0 replies; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 10:25 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/video/v4l2-ioctl.c |   47 ++++++++++++++++----------------------
 1 file changed, 20 insertions(+), 27 deletions(-)

diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
index 48852ca..7d093ca 100644
--- a/drivers/media/video/v4l2-ioctl.c
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -367,6 +367,11 @@ static void v4l_print_framebuffer(const void *arg)
 			p->fmt.colorspace);
 }
 
+static void v4l_print_buftype(const void *arg)
+{
+	pr_cont("type=%s\n", prt_names(*(u32 *)arg, v4l2_type_names));
+}
+
 static void v4l_print_u32(const void *arg)
 {
 	pr_cont("value=%u\n", *(const u32 *)arg);
@@ -852,6 +857,18 @@ static int v4l_try_fmt(const struct v4l2_ioctl_ops *ops,
 	return -EINVAL;
 }
 
+static int v4l_streamon(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	return ops->vidioc_streamon(file, fh, *(unsigned int *)arg);
+}
+
+static int v4l_streamoff(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	return ops->vidioc_streamoff(file, fh, *(unsigned int *)arg);
+}
+
 struct v4l2_ioctl_info {
 	unsigned int ioctl;
 	u32 flags;
@@ -911,11 +928,11 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
 	IOCTL_INFO(VIDIOC_QUERYBUF, INFO_FL_CLEAR(v4l2_buffer, length)),
 	IOCTL_INFO_STD(VIDIOC_G_FBUF, vidioc_g_fbuf, v4l_print_framebuffer, 0),
 	IOCTL_INFO_STD(VIDIOC_S_FBUF, vidioc_s_fbuf, v4l_print_framebuffer, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_OVERLAY, INFO_FL_PRIO),
+	IOCTL_INFO_STD(VIDIOC_OVERLAY, vidioc_overlay, v4l_print_u32, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_QBUF, 0),
 	IOCTL_INFO(VIDIOC_DQBUF, 0),
-	IOCTL_INFO(VIDIOC_STREAMON, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_STREAMOFF, INFO_FL_PRIO),
+	IOCTL_INFO_FNC(VIDIOC_STREAMON, v4l_streamon, v4l_print_buftype, INFO_FL_PRIO),
+	IOCTL_INFO_FNC(VIDIOC_STREAMOFF, v4l_streamoff, v4l_print_buftype, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_G_PARM, INFO_FL_CLEAR(v4l2_streamparm, type)),
 	IOCTL_INFO(VIDIOC_S_PARM, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_G_STD, 0),
@@ -1151,30 +1168,6 @@ static long __video_do_ioctl(struct file *file,
 			dbgbuf(cmd, vfd, p);
 		break;
 	}
-	case VIDIOC_OVERLAY:
-	{
-		int *i = arg;
-
-		dbgarg(cmd, "value=%d\n", *i);
-		ret = ops->vidioc_overlay(file, fh, *i);
-		break;
-	}
-	case VIDIOC_STREAMON:
-	{
-		enum v4l2_buf_type i = *(int *)arg;
-
-		dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
-		ret = ops->vidioc_streamon(file, fh, i);
-		break;
-	}
-	case VIDIOC_STREAMOFF:
-	{
-		enum v4l2_buf_type i = *(int *)arg;
-
-		dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
-		ret = ops->vidioc_streamoff(file, fh, i);
-		break;
-	}
 	/* ---------- tv norms ---------- */
 	case VIDIOC_ENUMSTD:
 	{
-- 
1.7.10


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

* [RFCv1 PATCH 10/32] v4l2-ioctl.c: use the new table for std/tuner/modulator ioctls.
  2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
                     ` (7 preceding siblings ...)
  2012-06-10 10:25   ` [RFCv1 PATCH 09/32] v4l2-ioctl.c: use the new table for overlay/streamon/off ioctls Hans Verkuil
@ 2012-06-10 10:25   ` Hans Verkuil
  2012-06-10 10:25   ` [RFCv1 PATCH 11/32] v4l2-ioctl.c: use the new table for queuing/parm ioctls Hans Verkuil
                     ` (21 subsequent siblings)
  30 siblings, 0 replies; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 10:25 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/video/v4l2-ioctl.c |  438 ++++++++++++++++++++------------------
 1 file changed, 228 insertions(+), 210 deletions(-)

diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
index 7d093ca..a23a7e4 100644
--- a/drivers/media/video/v4l2-ioctl.c
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -372,6 +372,76 @@ static void v4l_print_buftype(const void *arg)
 	pr_cont("type=%s\n", prt_names(*(u32 *)arg, v4l2_type_names));
 }
 
+static void v4l_print_g_modulator(const void *arg)
+{
+	const struct v4l2_modulator *p = arg;
+
+	pr_cont("index=%u, name=%s, capability=0x%x, "
+		"rangelow=%u, rangehigh=%u, txsubchans=0x%x\n",
+			p->index, p->name, p->capability,
+			p->rangelow, p->rangehigh, p->txsubchans);
+}
+
+static void v4l_print_s_modulator(const void *arg)
+{
+	const struct v4l2_modulator *p = arg;
+
+	pr_cont("index=%u, txsubchans=0x%x\n", p->index, p->txsubchans);
+}
+
+static void v4l_print_g_tuner(const void *arg)
+{
+	const struct v4l2_tuner *p = arg;
+
+	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",
+			p->index, p->name, p->type,
+			p->capability, p->rangelow,
+			p->rangehigh, p->signal, p->afc,
+			p->rxsubchans, p->audmode);
+}
+
+static void v4l_print_s_tuner(const void *arg)
+{
+	const struct v4l2_tuner *p = arg;
+
+	pr_cont("index=%u, audmode=%u\n", p->index, p->audmode);
+}
+
+static void v4l_print_frequency(const void *arg)
+{
+	const struct v4l2_frequency *p = arg;
+
+	pr_cont("tuner=%u, type=%u, frequency=%u\n",
+				p->tuner, p->type, p->frequency);
+}
+
+static void v4l_print_standard(const void *arg)
+{
+	const struct v4l2_standard *p = arg;
+
+	pr_cont("index=%u, id=0x%Lx, name=%s, fps=%u/%u, "
+		"framelines=%u\n", p->index,
+		(unsigned long long)p->id, p->name,
+		p->frameperiod.numerator,
+		p->frameperiod.denominator,
+		p->framelines);
+}
+
+static void v4l_print_std(const void *arg)
+{
+	pr_cont("std=0x%08Lx\n", *(const long long unsigned *)arg);
+}
+
+static void v4l_print_hw_freq_seek(const void *arg)
+{
+	const struct v4l2_hw_freq_seek *p = arg;
+
+	pr_cont("tuner=%u, type=%u, seek_upward=%u, wrap_around=%u, spacing=%u\n",
+		p->tuner, p->type, p->seek_upward, p->wrap_around, p->spacing);
+}
+
 static void v4l_print_u32(const void *arg)
 {
 	pr_cont("value=%u\n", *(const u32 *)arg);
@@ -869,6 +939,153 @@ static int v4l_streamoff(const struct v4l2_ioctl_ops *ops,
 	return ops->vidioc_streamoff(file, fh, *(unsigned int *)arg);
 }
 
+static int v4l_g_tuner(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct video_device *vfd = video_devdata(file);
+	struct v4l2_tuner *p = arg;
+
+	p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
+			V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
+	return ops->vidioc_g_tuner(file, fh, p);
+}
+
+static int v4l_s_tuner(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct video_device *vfd = video_devdata(file);
+	struct v4l2_tuner *p = arg;
+
+	p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
+			V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
+	return ops->vidioc_s_tuner(file, fh, p);
+}
+
+static int v4l_g_frequency(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct video_device *vfd = video_devdata(file);
+	struct v4l2_frequency *p = arg;
+
+	p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
+			V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
+	return ops->vidioc_g_frequency(file, fh, p);
+}
+
+static int v4l_s_frequency(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct video_device *vfd = video_devdata(file);
+	struct v4l2_frequency *p = arg;
+	enum v4l2_tuner_type type;
+
+	type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
+			V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
+	if (p->type != type)
+		return -EINVAL;
+	return ops->vidioc_s_frequency(file, fh, p);
+}
+
+static int v4l_enumstd(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct video_device *vfd = video_devdata(file);
+	struct v4l2_standard *p = arg;
+	v4l2_std_id id = vfd->tvnorms, curr_id = 0;
+	unsigned int index = p->index, i, j = 0;
+	const char *descr = "";
+
+	/* Return norm array in a canonical way */
+	for (i = 0; i <= index && id; i++) {
+		/* last std value in the standards array is 0, so this
+		   while always ends there since (id & 0) == 0. */
+		while ((id & standards[j].std) != standards[j].std)
+			j++;
+		curr_id = standards[j].std;
+		descr = standards[j].descr;
+		j++;
+		if (curr_id == 0)
+			break;
+		if (curr_id != V4L2_STD_PAL &&
+				curr_id != V4L2_STD_SECAM &&
+				curr_id != V4L2_STD_NTSC)
+			id &= ~curr_id;
+	}
+	if (i <= index)
+		return -EINVAL;
+
+	v4l2_video_std_construct(p, curr_id, descr);
+	return 0;
+}
+
+static int v4l_g_std(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct video_device *vfd = video_devdata(file);
+	v4l2_std_id *id = arg;
+
+	/* Calls the specific handler */
+	if (ops->vidioc_g_std)
+		return ops->vidioc_g_std(file, fh, arg);
+	if (vfd->current_norm) {
+		*id = vfd->current_norm;
+		return 0;
+	}
+	return -ENOTTY;
+}
+
+static int v4l_s_std(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct video_device *vfd = video_devdata(file);
+	v4l2_std_id *id = arg, norm;
+	int ret;
+
+	norm = (*id) & vfd->tvnorms;
+	if (vfd->tvnorms && !norm)	/* Check if std is supported */
+		return -EINVAL;
+
+	/* Calls the specific handler */
+	ret = ops->vidioc_s_std(file, fh, &norm);
+
+	/* Updates standard information */
+	if (ret >= 0)
+		vfd->current_norm = norm;
+	return ret;
+}
+
+static int v4l_querystd(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct video_device *vfd = video_devdata(file);
+	v4l2_std_id *p = arg;
+
+	/*
+	 * If nothing detected, it should return all supported
+	 * standard.
+	 * Drivers just need to mask the std argument, in order
+	 * to remove the standards that don't apply from the mask.
+	 * This means that tuners, audio and video decoders can join
+	 * their efforts to improve the standards detection.
+	 */
+	*p = vfd->tvnorms;
+	return ops->vidioc_querystd(file, fh, arg);
+}
+
+static int v4l_s_hw_freq_seek(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct video_device *vfd = video_devdata(file);
+	struct v4l2_hw_freq_seek *p = arg;
+	enum v4l2_tuner_type type;
+
+	type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
+		V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
+	if (p->type != type)
+		return -EINVAL;
+	return ops->vidioc_s_hw_freq_seek(file, fh, p);
+}
+
 struct v4l2_ioctl_info {
 	unsigned int ioctl;
 	u32 flags;
@@ -935,14 +1152,14 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
 	IOCTL_INFO_FNC(VIDIOC_STREAMOFF, v4l_streamoff, v4l_print_buftype, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_G_PARM, INFO_FL_CLEAR(v4l2_streamparm, type)),
 	IOCTL_INFO(VIDIOC_S_PARM, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_G_STD, 0),
-	IOCTL_INFO(VIDIOC_S_STD, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_ENUMSTD, INFO_FL_CLEAR(v4l2_standard, index)),
+	IOCTL_INFO_FNC(VIDIOC_G_STD, v4l_g_std, v4l_print_std, 0),
+	IOCTL_INFO_FNC(VIDIOC_S_STD, v4l_s_std, v4l_print_std, INFO_FL_PRIO),
+	IOCTL_INFO_FNC(VIDIOC_ENUMSTD, v4l_enumstd, v4l_print_standard, INFO_FL_CLEAR(v4l2_standard, index)),
 	IOCTL_INFO_FNC(VIDIOC_ENUMINPUT, v4l_enuminput, v4l_print_enuminput, INFO_FL_CLEAR(v4l2_input, index)),
 	IOCTL_INFO(VIDIOC_G_CTRL, INFO_FL_CTRL),
 	IOCTL_INFO(VIDIOC_S_CTRL, INFO_FL_PRIO | INFO_FL_CTRL),
-	IOCTL_INFO(VIDIOC_G_TUNER, INFO_FL_CLEAR(v4l2_tuner, index)),
-	IOCTL_INFO(VIDIOC_S_TUNER, INFO_FL_PRIO),
+	IOCTL_INFO_FNC(VIDIOC_G_TUNER, v4l_g_tuner, v4l_print_g_tuner, INFO_FL_CLEAR(v4l2_tuner, index)),
+	IOCTL_INFO_FNC(VIDIOC_S_TUNER, v4l_s_tuner, v4l_print_s_tuner, INFO_FL_PRIO),
 	IOCTL_INFO_STD(VIDIOC_G_AUDIO, vidioc_g_audio, v4l_print_audio, 0),
 	IOCTL_INFO_STD(VIDIOC_S_AUDIO, vidioc_s_audio, v4l_print_s_audio, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_QUERYCTRL, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_queryctrl, id)),
@@ -954,10 +1171,10 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
 	IOCTL_INFO_FNC(VIDIOC_ENUMOUTPUT, v4l_enumoutput, v4l_print_enumoutput, INFO_FL_CLEAR(v4l2_output, index)),
 	IOCTL_INFO_STD(VIDIOC_G_AUDOUT, vidioc_g_audout, v4l_print_audioout, 0),
 	IOCTL_INFO_STD(VIDIOC_S_AUDOUT, vidioc_s_audout, v4l_print_s_audioout, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_G_MODULATOR, INFO_FL_CLEAR(v4l2_modulator, index)),
-	IOCTL_INFO(VIDIOC_S_MODULATOR, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_G_FREQUENCY, INFO_FL_CLEAR(v4l2_frequency, tuner)),
-	IOCTL_INFO(VIDIOC_S_FREQUENCY, INFO_FL_PRIO),
+	IOCTL_INFO_STD(VIDIOC_G_MODULATOR, vidioc_g_modulator, v4l_print_g_modulator, INFO_FL_CLEAR(v4l2_modulator, index)),
+	IOCTL_INFO_STD(VIDIOC_S_MODULATOR, vidioc_s_modulator, v4l_print_s_modulator, INFO_FL_PRIO),
+	IOCTL_INFO_FNC(VIDIOC_G_FREQUENCY, v4l_g_frequency, v4l_print_frequency, INFO_FL_CLEAR(v4l2_frequency, tuner)),
+	IOCTL_INFO_FNC(VIDIOC_S_FREQUENCY, v4l_s_frequency, v4l_print_frequency, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_CROPCAP, INFO_FL_CLEAR(v4l2_cropcap, type)),
 	IOCTL_INFO(VIDIOC_G_CROP, INFO_FL_CLEAR(v4l2_crop, type)),
 	IOCTL_INFO(VIDIOC_S_CROP, INFO_FL_PRIO),
@@ -965,7 +1182,7 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
 	IOCTL_INFO(VIDIOC_S_SELECTION, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_G_JPEGCOMP, 0),
 	IOCTL_INFO(VIDIOC_S_JPEGCOMP, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_QUERYSTD, 0),
+	IOCTL_INFO_FNC(VIDIOC_QUERYSTD, v4l_querystd, v4l_print_std, 0),
 	IOCTL_INFO_FNC(VIDIOC_TRY_FMT, v4l_try_fmt, v4l_print_format, 0),
 	IOCTL_INFO_STD(VIDIOC_ENUMAUDIO, vidioc_enumaudio, v4l_print_audio, INFO_FL_CLEAR(v4l2_audio, index)),
 	IOCTL_INFO_STD(VIDIOC_ENUMAUDOUT, vidioc_enumaudout, v4l_print_audioout, INFO_FL_CLEAR(v4l2_audioout, index)),
@@ -986,7 +1203,7 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
 	IOCTL_INFO(VIDIOC_DBG_S_REGISTER, 0),
 	IOCTL_INFO(VIDIOC_DBG_G_REGISTER, 0),
 	IOCTL_INFO(VIDIOC_DBG_G_CHIP_IDENT, 0),
-	IOCTL_INFO(VIDIOC_S_HW_FREQ_SEEK, INFO_FL_PRIO),
+	IOCTL_INFO_FNC(VIDIOC_S_HW_FREQ_SEEK, v4l_s_hw_freq_seek, v4l_print_hw_freq_seek, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_ENUM_DV_PRESETS, 0),
 	IOCTL_INFO(VIDIOC_S_DV_PRESET, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_G_DV_PRESET, 0),
@@ -1168,102 +1385,6 @@ static long __video_do_ioctl(struct file *file,
 			dbgbuf(cmd, vfd, p);
 		break;
 	}
-	/* ---------- tv norms ---------- */
-	case VIDIOC_ENUMSTD:
-	{
-		struct v4l2_standard *p = arg;
-		v4l2_std_id id = vfd->tvnorms, curr_id = 0;
-		unsigned int index = p->index, i, j = 0;
-		const char *descr = "";
-
-		if (id == 0)
-			break;
-		ret = -EINVAL;
-
-		/* Return norm array in a canonical way */
-		for (i = 0; i <= index && id; i++) {
-			/* last std value in the standards array is 0, so this
-			   while always ends there since (id & 0) == 0. */
-			while ((id & standards[j].std) != standards[j].std)
-				j++;
-			curr_id = standards[j].std;
-			descr = standards[j].descr;
-			j++;
-			if (curr_id == 0)
-				break;
-			if (curr_id != V4L2_STD_PAL &&
-			    curr_id != V4L2_STD_SECAM &&
-			    curr_id != V4L2_STD_NTSC)
-				id &= ~curr_id;
-		}
-		if (i <= index)
-			break;
-
-		v4l2_video_std_construct(p, curr_id, descr);
-
-		dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
-				"framelines=%d\n", p->index,
-				(unsigned long long)p->id, p->name,
-				p->frameperiod.numerator,
-				p->frameperiod.denominator,
-				p->framelines);
-
-		ret = 0;
-		break;
-	}
-	case VIDIOC_G_STD:
-	{
-		v4l2_std_id *id = arg;
-
-		/* Calls the specific handler */
-		if (ops->vidioc_g_std)
-			ret = ops->vidioc_g_std(file, fh, id);
-		else if (vfd->current_norm) {
-			ret = 0;
-			*id = vfd->current_norm;
-		}
-
-		if (likely(!ret))
-			dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id);
-		break;
-	}
-	case VIDIOC_S_STD:
-	{
-		v4l2_std_id *id = arg, norm;
-
-		dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id);
-
-		ret = -EINVAL;
-		norm = (*id) & vfd->tvnorms;
-		if (vfd->tvnorms && !norm)	/* Check if std is supported */
-			break;
-
-		/* Calls the specific handler */
-		ret = ops->vidioc_s_std(file, fh, &norm);
-
-		/* Updates standard information */
-		if (ret >= 0)
-			vfd->current_norm = norm;
-		break;
-	}
-	case VIDIOC_QUERYSTD:
-	{
-		v4l2_std_id *p = arg;
-
-		/*
-		 * If nothing detected, it should return all supported
-		 * Drivers just need to mask the std argument, in order
-		 * to remove the standards that don't apply from the mask.
-		 * This means that tuners, audio and video decoders can join
-		 * their efforts to improve the standards detection
-		 */
-		*p = vfd->tvnorms;
-		ret = ops->vidioc_querystd(file, fh, arg);
-		if (!ret)
-			dbgarg(cmd, "detected std=%08Lx\n",
-						(unsigned long long)*p);
-		break;
-	}
 
 	/* --- controls ---------------------------------------------- */
 	case VIDIOC_QUERYCTRL:
@@ -1434,31 +1555,6 @@ static long __video_do_ioctl(struct file *file,
 				p->id, p->index);
 		break;
 	}
-	case VIDIOC_G_MODULATOR:
-	{
-		struct v4l2_modulator *p = arg;
-
-		ret = ops->vidioc_g_modulator(file, fh, p);
-		if (!ret)
-			dbgarg(cmd, "index=%d, name=%s, "
-					"capability=%d, rangelow=%d,"
-					" rangehigh=%d, txsubchans=%d\n",
-					p->index, p->name, p->capability,
-					p->rangelow, p->rangehigh,
-					p->txsubchans);
-		break;
-	}
-	case VIDIOC_S_MODULATOR:
-	{
-		struct v4l2_modulator *p = arg;
-
-		dbgarg(cmd, "index=%d, name=%s, capability=%d, "
-				"rangelow=%d, rangehigh=%d, txsubchans=%d\n",
-				p->index, p->name, p->capability, p->rangelow,
-				p->rangehigh, p->txsubchans);
-			ret = ops->vidioc_s_modulator(file, fh, p);
-		break;
-	}
 	case VIDIOC_G_CROP:
 	{
 		struct v4l2_crop *p = arg;
@@ -1691,68 +1787,6 @@ static long __video_do_ioctl(struct file *file,
 		ret = ops->vidioc_s_parm(file, fh, p);
 		break;
 	}
-	case VIDIOC_G_TUNER:
-	{
-		struct v4l2_tuner *p = arg;
-
-		p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
-			V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
-		ret = ops->vidioc_g_tuner(file, fh, p);
-		if (!ret)
-			dbgarg(cmd, "index=%d, name=%s, type=%d, "
-					"capability=0x%x, rangelow=%d, "
-					"rangehigh=%d, signal=%d, afc=%d, "
-					"rxsubchans=0x%x, audmode=%d\n",
-					p->index, p->name, p->type,
-					p->capability, p->rangelow,
-					p->rangehigh, p->signal, p->afc,
-					p->rxsubchans, p->audmode);
-		break;
-	}
-	case VIDIOC_S_TUNER:
-	{
-		struct v4l2_tuner *p = arg;
-
-		p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
-			V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
-		dbgarg(cmd, "index=%d, name=%s, type=%d, "
-				"capability=0x%x, rangelow=%d, "
-				"rangehigh=%d, signal=%d, afc=%d, "
-				"rxsubchans=0x%x, audmode=%d\n",
-				p->index, p->name, p->type,
-				p->capability, p->rangelow,
-				p->rangehigh, p->signal, p->afc,
-				p->rxsubchans, p->audmode);
-		ret = ops->vidioc_s_tuner(file, fh, p);
-		break;
-	}
-	case VIDIOC_G_FREQUENCY:
-	{
-		struct v4l2_frequency *p = arg;
-
-		p->type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
-			V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
-		ret = ops->vidioc_g_frequency(file, fh, p);
-		if (!ret)
-			dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
-					p->tuner, p->type, p->frequency);
-		break;
-	}
-	case VIDIOC_S_FREQUENCY:
-	{
-		struct v4l2_frequency *p = arg;
-		enum v4l2_tuner_type type;
-
-		type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
-			V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
-		dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
-				p->tuner, p->type, p->frequency);
-		if (p->type != type)
-			ret = -EINVAL;
-		else
-			ret = ops->vidioc_s_frequency(file, fh, p);
-		break;
-	}
 	case VIDIOC_G_SLICED_VBI_CAP:
 	{
 		struct v4l2_sliced_vbi_cap *p = arg;
@@ -1812,22 +1846,6 @@ static long __video_do_ioctl(struct file *file,
 			dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
 		break;
 	}
-	case VIDIOC_S_HW_FREQ_SEEK:
-	{
-		struct v4l2_hw_freq_seek *p = arg;
-		enum v4l2_tuner_type type;
-
-		type = (vfd->vfl_type == VFL_TYPE_RADIO) ?
-			V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
-		dbgarg(cmd,
-			"tuner=%u, type=%u, seek_upward=%u, wrap_around=%u, spacing=%u\n",
-			p->tuner, p->type, p->seek_upward, p->wrap_around, p->spacing);
-		if (p->type != type)
-			ret = -EINVAL;
-		else
-			ret = ops->vidioc_s_hw_freq_seek(file, fh, p);
-		break;
-	}
 	case VIDIOC_ENUM_FRAMESIZES:
 	{
 		struct v4l2_frmsizeenum *p = arg;
-- 
1.7.10


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

* [RFCv1 PATCH 11/32] v4l2-ioctl.c: use the new table for queuing/parm ioctls.
  2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
                     ` (8 preceding siblings ...)
  2012-06-10 10:25   ` [RFCv1 PATCH 10/32] v4l2-ioctl.c: use the new table for std/tuner/modulator ioctls Hans Verkuil
@ 2012-06-10 10:25   ` Hans Verkuil
  2012-06-10 10:25   ` [RFCv1 PATCH 12/32] v4l2-ioctl.c: use the new table for control ioctls Hans Verkuil
                     ` (20 subsequent siblings)
  30 siblings, 0 replies; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 10:25 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/video/v4l2-ioctl.c |  314 ++++++++++++++++++++------------------
 1 file changed, 164 insertions(+), 150 deletions(-)

diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
index a23a7e4..1f7982a 100644
--- a/drivers/media/video/v4l2-ioctl.c
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -442,48 +442,96 @@ static void v4l_print_hw_freq_seek(const void *arg)
 		p->tuner, p->type, p->seek_upward, p->wrap_around, p->spacing);
 }
 
-static void v4l_print_u32(const void *arg)
+static void v4l_print_requestbuffers(const void *arg)
 {
-	pr_cont("value=%u\n", *(const u32 *)arg);
+	const struct v4l2_requestbuffers *p = arg;
+
+	pr_cont("count=%d, type=%s, memory=%s\n",
+		p->count,
+		prt_names(p->type, v4l2_type_names),
+		prt_names(p->memory, v4l2_memory_names));
 }
 
-static void dbgbuf(unsigned int cmd, struct video_device *vfd,
-					struct v4l2_buffer *p)
+static void v4l_print_buffer(const void *arg)
 {
-	struct v4l2_timecode *tc = &p->timecode;
-	struct v4l2_plane *plane;
+	const struct v4l2_buffer *p = arg;
+	const struct v4l2_timecode *tc = &p->timecode;
+	const struct v4l2_plane *plane;
 	int i;
 
-	dbgarg(cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
-		"flags=0x%08d, field=%0d, sequence=%d, memory=%s\n",
+	pr_cont("%02ld:%02d:%02d.%08ld index=%d, type=%s, "
+		"flags=0x%08x, field=%s, sequence=%d, memory=%s",
 			p->timestamp.tv_sec / 3600,
 			(int)(p->timestamp.tv_sec / 60) % 60,
 			(int)(p->timestamp.tv_sec % 60),
 			(long)p->timestamp.tv_usec,
 			p->index,
 			prt_names(p->type, v4l2_type_names),
-			p->flags, p->field, p->sequence,
-			prt_names(p->memory, v4l2_memory_names));
+			p->flags, prt_names(p->field, v4l2_field_names),
+			p->sequence, prt_names(p->memory, v4l2_memory_names));
 
 	if (V4L2_TYPE_IS_MULTIPLANAR(p->type) && p->m.planes) {
+		pr_cont("\n");
 		for (i = 0; i < p->length; ++i) {
 			plane = &p->m.planes[i];
-			dbgarg2("plane %d: bytesused=%d, data_offset=0x%08x "
-				"offset/userptr=0x%08lx, length=%d\n",
+			pr_info("plane %d: bytesused=%d, data_offset=0x%08x "
+				"offset/userptr=0x%lx, length=%d\n",
 				i, plane->bytesused, plane->data_offset,
 				plane->m.userptr, plane->length);
 		}
 	} else {
-		dbgarg2("bytesused=%d, offset/userptr=0x%08lx, length=%d\n",
+		pr_cont("bytesused=%d, offset/userptr=0x%lx, length=%d\n",
 			p->bytesused, p->m.userptr, p->length);
 	}
 
-	dbgarg2("timecode=%02d:%02d:%02d type=%d, "
-		"flags=0x%08d, frames=%d, userbits=0x%08x\n",
+	pr_info("timecode=%02d:%02d:%02d type=%d, "
+		"flags=0x%08x, frames=%d, userbits=0x%08x\n",
 			tc->hours, tc->minutes, tc->seconds,
 			tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits);
 }
 
+static void v4l_print_create_buffers(const void *arg)
+{
+	const struct v4l2_create_buffers *p = arg;
+
+	pr_cont("index=%d, count=%d, memory=%s\n",
+			p->index, p->count,
+			prt_names(p->memory, v4l2_memory_names));
+	v4l_print_format(&p->format);
+}
+
+static void v4l_print_streamparm(const void *arg)
+{
+	const struct v4l2_streamparm *p = arg;
+
+	pr_cont("type=%s", prt_names(p->type, v4l2_type_names));
+
+	if (p->type == V4L2_BUF_TYPE_VIDEO_CAPTURE ||
+	    p->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
+		const struct v4l2_captureparm *c = &p->parm.capture;
+
+		pr_cont(", capability=0x%x, capturemode=0x%x, timeperframe=%d/%d, "
+			"extendedmode=%d, readbuffers=%d\n",
+			c->capability, c->capturemode,
+			c->timeperframe.numerator, c->timeperframe.denominator,
+			c->extendedmode, c->readbuffers);
+	} else if (p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT ||
+		   p->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
+		const struct v4l2_outputparm *c = &p->parm.output;
+
+		pr_cont(", capability=0x%x, outputmode=0x%x, timeperframe=%d/%d, "
+			"extendedmode=%d, writebuffers=%d\n",
+			c->capability, c->outputmode,
+			c->timeperframe.numerator, c->timeperframe.denominator,
+			c->extendedmode, c->writebuffers);
+	}
+}
+
+static void v4l_print_u32(const void *arg)
+{
+	pr_cont("value=%u\n", *(const u32 *)arg);
+}
+
 static inline void dbgrect(struct video_device *vfd, char *s,
 							struct v4l2_rect *r)
 {
@@ -1086,6 +1134,99 @@ static int v4l_s_hw_freq_seek(const struct v4l2_ioctl_ops *ops,
 	return ops->vidioc_s_hw_freq_seek(file, fh, p);
 }
 
+static int v4l_reqbufs(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct v4l2_requestbuffers *p = arg;
+	int ret = check_fmt(ops, p->type);
+
+	if (ret)
+		return ret;
+
+	if (p->type < V4L2_BUF_TYPE_PRIVATE)
+		CLEAR_AFTER_FIELD(p, memory);
+
+	return ops->vidioc_reqbufs(file, fh, p);
+}
+
+static int v4l_querybuf(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct v4l2_buffer *p = arg;
+	int ret = check_fmt(ops, p->type);
+
+	return ret ? ret : ops->vidioc_querybuf(file, fh, p);
+}
+
+static int v4l_qbuf(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct v4l2_buffer *p = arg;
+	int ret = check_fmt(ops, p->type);
+
+	return ret ? ret : ops->vidioc_qbuf(file, fh, p);
+}
+
+static int v4l_dqbuf(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct v4l2_buffer *p = arg;
+	int ret = check_fmt(ops, p->type);
+
+	return ret ? ret : ops->vidioc_dqbuf(file, fh, p);
+}
+
+static int v4l_create_bufs(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct v4l2_create_buffers *create = arg;
+	int ret = check_fmt(ops, create->format.type);
+
+	return ret ? ret : ops->vidioc_create_bufs(file, fh, create);
+}
+
+static int v4l_prepare_buf(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct v4l2_buffer *b = arg;
+	int ret = check_fmt(ops, b->type);
+
+	return ret ? ret : ops->vidioc_prepare_buf(file, fh, b);
+}
+
+static int v4l_g_parm(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct video_device *vfd = video_devdata(file);
+	struct v4l2_streamparm *p = arg;
+	v4l2_std_id std;
+	int ret = check_fmt(ops, p->type);
+
+	if (ret)
+		return ret;
+	if (ops->vidioc_g_parm)
+		return ops->vidioc_g_parm(file, fh, p);
+	std = vfd->current_norm;
+	if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
+	    p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)
+		return -EINVAL;
+	if (ops->vidioc_g_std)
+		ret = ops->vidioc_g_std(file, fh, &std);
+	if (ret == 0)
+		v4l2_video_std_frame_period(std,
+			    &p->parm.capture.timeperframe);
+	return ret;
+}
+
+static int v4l_s_parm(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct v4l2_streamparm *p = arg;
+	int ret = check_fmt(ops, p->type);
+
+	return ret ? ret : ops->vidioc_s_parm(file, fh, p);
+}
+
 struct v4l2_ioctl_info {
 	unsigned int ioctl;
 	u32 flags;
@@ -1141,17 +1282,17 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
 	IOCTL_INFO_FNC(VIDIOC_ENUM_FMT, v4l_enum_fmt, v4l_print_fmtdesc, INFO_FL_CLEAR(v4l2_fmtdesc, type)),
 	IOCTL_INFO_FNC(VIDIOC_G_FMT, v4l_g_fmt, v4l_print_format, INFO_FL_CLEAR(v4l2_format, type)),
 	IOCTL_INFO_FNC(VIDIOC_S_FMT, v4l_s_fmt, v4l_print_format, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_REQBUFS, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_QUERYBUF, INFO_FL_CLEAR(v4l2_buffer, length)),
+	IOCTL_INFO_FNC(VIDIOC_REQBUFS, v4l_reqbufs, v4l_print_requestbuffers, INFO_FL_PRIO),
+	IOCTL_INFO_FNC(VIDIOC_QUERYBUF, v4l_querybuf, v4l_print_buffer, INFO_FL_CLEAR(v4l2_buffer, length)),
 	IOCTL_INFO_STD(VIDIOC_G_FBUF, vidioc_g_fbuf, v4l_print_framebuffer, 0),
 	IOCTL_INFO_STD(VIDIOC_S_FBUF, vidioc_s_fbuf, v4l_print_framebuffer, INFO_FL_PRIO),
 	IOCTL_INFO_STD(VIDIOC_OVERLAY, vidioc_overlay, v4l_print_u32, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_QBUF, 0),
-	IOCTL_INFO(VIDIOC_DQBUF, 0),
+	IOCTL_INFO_FNC(VIDIOC_QBUF, v4l_qbuf, v4l_print_buffer, 0),
+	IOCTL_INFO_FNC(VIDIOC_DQBUF, v4l_dqbuf, v4l_print_buffer, 0),
 	IOCTL_INFO_FNC(VIDIOC_STREAMON, v4l_streamon, v4l_print_buftype, INFO_FL_PRIO),
 	IOCTL_INFO_FNC(VIDIOC_STREAMOFF, v4l_streamoff, v4l_print_buftype, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_G_PARM, INFO_FL_CLEAR(v4l2_streamparm, type)),
-	IOCTL_INFO(VIDIOC_S_PARM, INFO_FL_PRIO),
+	IOCTL_INFO_FNC(VIDIOC_G_PARM, v4l_g_parm, v4l_print_streamparm, INFO_FL_CLEAR(v4l2_streamparm, type)),
+	IOCTL_INFO_FNC(VIDIOC_S_PARM, v4l_s_parm, v4l_print_streamparm, INFO_FL_PRIO),
 	IOCTL_INFO_FNC(VIDIOC_G_STD, v4l_g_std, v4l_print_std, 0),
 	IOCTL_INFO_FNC(VIDIOC_S_STD, v4l_s_std, v4l_print_std, INFO_FL_PRIO),
 	IOCTL_INFO_FNC(VIDIOC_ENUMSTD, v4l_enumstd, v4l_print_standard, INFO_FL_CLEAR(v4l2_standard, index)),
@@ -1213,8 +1354,8 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
 	IOCTL_INFO(VIDIOC_DQEVENT, 0),
 	IOCTL_INFO(VIDIOC_SUBSCRIBE_EVENT, 0),
 	IOCTL_INFO(VIDIOC_UNSUBSCRIBE_EVENT, 0),
-	IOCTL_INFO(VIDIOC_CREATE_BUFS, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_PREPARE_BUF, 0),
+	IOCTL_INFO_FNC(VIDIOC_CREATE_BUFS, v4l_create_bufs, v4l_print_create_buffers, INFO_FL_PRIO),
+	IOCTL_INFO_FNC(VIDIOC_PREPARE_BUF, v4l_prepare_buf, v4l_print_buffer, 0),
 	IOCTL_INFO(VIDIOC_ENUM_DV_TIMINGS, 0),
 	IOCTL_INFO(VIDIOC_QUERY_DV_TIMINGS, 0),
 	IOCTL_INFO(VIDIOC_DV_TIMINGS_CAP, 0),
@@ -1324,68 +1465,6 @@ static long __video_do_ioctl(struct file *file,
 	}
 
 	switch (cmd) {
-	/* FIXME: Those buf reqs could be handled here,
-	   with some changes on videobuf to allow its header to be included at
-	   videodev2.h or being merged at videodev2.
-	 */
-	case VIDIOC_REQBUFS:
-	{
-		struct v4l2_requestbuffers *p = arg;
-
-		ret = check_fmt(ops, p->type);
-		if (ret)
-			break;
-
-		if (p->type < V4L2_BUF_TYPE_PRIVATE)
-			CLEAR_AFTER_FIELD(p, memory);
-
-		ret = ops->vidioc_reqbufs(file, fh, p);
-		dbgarg(cmd, "count=%d, type=%s, memory=%s\n",
-				p->count,
-				prt_names(p->type, v4l2_type_names),
-				prt_names(p->memory, v4l2_memory_names));
-		break;
-	}
-	case VIDIOC_QUERYBUF:
-	{
-		struct v4l2_buffer *p = arg;
-
-		ret = check_fmt(ops, p->type);
-		if (ret)
-			break;
-
-		ret = ops->vidioc_querybuf(file, fh, p);
-		if (!ret)
-			dbgbuf(cmd, vfd, p);
-		break;
-	}
-	case VIDIOC_QBUF:
-	{
-		struct v4l2_buffer *p = arg;
-
-		ret = check_fmt(ops, p->type);
-		if (ret)
-			break;
-
-		ret = ops->vidioc_qbuf(file, fh, p);
-		if (!ret)
-			dbgbuf(cmd, vfd, p);
-		break;
-	}
-	case VIDIOC_DQBUF:
-	{
-		struct v4l2_buffer *p = arg;
-
-		ret = check_fmt(ops, p->type);
-		if (ret)
-			break;
-
-		ret = ops->vidioc_dqbuf(file, fh, p);
-		if (!ret)
-			dbgbuf(cmd, vfd, p);
-		break;
-	}
-
 	/* --- controls ---------------------------------------------- */
 	case VIDIOC_QUERYCTRL:
 	{
@@ -1748,45 +1827,6 @@ static long __video_do_ioctl(struct file *file,
 			dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
 		break;
 	}
-	case VIDIOC_G_PARM:
-	{
-		struct v4l2_streamparm *p = arg;
-
-		if (ops->vidioc_g_parm) {
-			ret = check_fmt(ops, p->type);
-			if (ret)
-				break;
-			ret = ops->vidioc_g_parm(file, fh, p);
-		} else {
-			v4l2_std_id std = vfd->current_norm;
-
-			ret = -EINVAL;
-			if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
-				break;
-
-			ret = 0;
-			if (ops->vidioc_g_std)
-				ret = ops->vidioc_g_std(file, fh, &std);
-			if (ret == 0)
-				v4l2_video_std_frame_period(std,
-						    &p->parm.capture.timeperframe);
-		}
-
-		dbgarg(cmd, "type=%d\n", p->type);
-		break;
-	}
-	case VIDIOC_S_PARM:
-	{
-		struct v4l2_streamparm *p = arg;
-
-		ret = check_fmt(ops, p->type);
-		if (ret)
-			break;
-
-		dbgarg(cmd, "type=%d\n", p->type);
-		ret = ops->vidioc_s_parm(file, fh, p);
-		break;
-	}
 	case VIDIOC_G_SLICED_VBI_CAP:
 	{
 		struct v4l2_sliced_vbi_cap *p = arg;
@@ -2067,32 +2107,6 @@ static long __video_do_ioctl(struct file *file,
 		dbgarg(cmd, "type=0x%8.8x", sub->type);
 		break;
 	}
-	case VIDIOC_CREATE_BUFS:
-	{
-		struct v4l2_create_buffers *create = arg;
-
-		ret = check_fmt(ops, create->format.type);
-		if (ret)
-			break;
-
-		ret = ops->vidioc_create_bufs(file, fh, create);
-
-		dbgarg(cmd, "count=%d @ %d\n", create->count, create->index);
-		break;
-	}
-	case VIDIOC_PREPARE_BUF:
-	{
-		struct v4l2_buffer *b = arg;
-
-		ret = check_fmt(ops, b->type);
-		if (ret)
-			break;
-
-		ret = ops->vidioc_prepare_buf(file, fh, b);
-
-		dbgarg(cmd, "index=%d", b->index);
-		break;
-	}
 	default:
 		if (!ops->vidioc_default)
 			break;
-- 
1.7.10


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

* [RFCv1 PATCH 12/32] v4l2-ioctl.c: use the new table for control ioctls.
  2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
                     ` (9 preceding siblings ...)
  2012-06-10 10:25   ` [RFCv1 PATCH 11/32] v4l2-ioctl.c: use the new table for queuing/parm ioctls Hans Verkuil
@ 2012-06-10 10:25   ` Hans Verkuil
  2012-06-10 10:25   ` [RFCv1 PATCH 13/32] v4l2-ioctl.c: use the new table for selection ioctls Hans Verkuil
                     ` (19 subsequent siblings)
  30 siblings, 0 replies; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 10:25 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/video/v4l2-ioctl.c |  395 +++++++++++++++++++-------------------
 1 file changed, 198 insertions(+), 197 deletions(-)

diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
index 1f7982a..4fb113b 100644
--- a/drivers/media/video/v4l2-ioctl.c
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -527,6 +527,49 @@ static void v4l_print_streamparm(const void *arg)
 	}
 }
 
+static void v4l_print_queryctrl(const void *arg)
+{
+	const struct v4l2_queryctrl *p = arg;
+
+	pr_cont("id=0x%x, type=%d, name=%s, min/max=%d/%d, "
+		"step=%d, default=%d, flags=0x%08x\n",
+			p->id, p->type, p->name,
+			p->minimum, p->maximum,
+			p->step, p->default_value, p->flags);
+}
+
+static void v4l_print_querymenu(const void *arg)
+{
+	const struct v4l2_querymenu *p = arg;
+
+	pr_cont("id=0x%x, index=%d\n", p->id, p->index);
+}
+
+static void v4l_print_control(const void *arg)
+{
+	const struct v4l2_control *p = arg;
+
+	pr_cont("id=0x%x, value=%d\n", p->id, p->value);
+}
+
+static void v4l_print_ext_controls(const void *arg)
+{
+	const struct v4l2_ext_controls *p = arg;
+	int i;
+
+	pr_cont("class=0x%x, count=%d, error_idx=%d",
+			p->ctrl_class, p->count, p->error_idx);
+	for (i = 0; i < p->count; i++) {
+		if (p->controls[i].size)
+			pr_cont(", id/val=0x%x/0x%x",
+				p->controls[i].id, p->controls[i].value);
+		else
+			pr_cont(", id/size=0x%x/%u",
+				p->controls[i].id, p->controls[i].size);
+	}
+	pr_cont("\n");
+}
+
 static void v4l_print_u32(const void *arg)
 {
 	pr_cont("value=%u\n", *(const u32 *)arg);
@@ -567,27 +610,7 @@ static void dbgtimings(struct video_device *vfd,
 	}
 }
 
-static inline void v4l_print_ext_ctrls(unsigned int cmd,
-	struct video_device *vfd, struct v4l2_ext_controls *c, int show_vals)
-{
-	__u32 i;
-
-	if (!(vfd->debug & V4L2_DEBUG_IOCTL_ARG))
-		return;
-	dbgarg(cmd, "");
-	printk(KERN_CONT "class=0x%x", c->ctrl_class);
-	for (i = 0; i < c->count; i++) {
-		if (show_vals && !c->controls[i].size)
-			printk(KERN_CONT " id/val=0x%x/0x%x",
-				c->controls[i].id, c->controls[i].value);
-		else
-			printk(KERN_CONT " id=0x%x,size=%u",
-				c->controls[i].id, c->controls[i].size);
-	}
-	printk(KERN_CONT "\n");
-};
-
-static inline int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
+static int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
 {
 	__u32 i;
 
@@ -1227,6 +1250,153 @@ static int v4l_s_parm(const struct v4l2_ioctl_ops *ops,
 	return ret ? ret : ops->vidioc_s_parm(file, fh, p);
 }
 
+static int v4l_queryctrl(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct video_device *vfd = video_devdata(file);
+	struct v4l2_queryctrl *p = arg;
+	struct v4l2_fh *vfh = fh;
+
+	if (vfh && vfh->ctrl_handler)
+		return v4l2_queryctrl(vfh->ctrl_handler, p);
+	if (vfd->ctrl_handler)
+		return v4l2_queryctrl(vfd->ctrl_handler, p);
+	if (ops->vidioc_queryctrl)
+		return ops->vidioc_queryctrl(file, fh, p);
+	return -ENOTTY;
+}
+
+static int v4l_querymenu(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct video_device *vfd = video_devdata(file);
+	struct v4l2_querymenu *p = arg;
+	struct v4l2_fh *vfh = fh;
+
+	if (vfh && vfh->ctrl_handler)
+		return v4l2_querymenu(vfh->ctrl_handler, p);
+	if (vfd->ctrl_handler)
+		return v4l2_querymenu(vfd->ctrl_handler, p);
+	if (ops->vidioc_querymenu)
+		return ops->vidioc_querymenu(file, fh, p);
+	return -ENOTTY;
+}
+
+static int v4l_g_ctrl(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct video_device *vfd = video_devdata(file);
+	struct v4l2_control *p = arg;
+	struct v4l2_fh *vfh = fh;
+	struct v4l2_ext_controls ctrls;
+	struct v4l2_ext_control ctrl;
+
+	if (vfh && vfh->ctrl_handler)
+		return v4l2_g_ctrl(vfh->ctrl_handler, p);
+	if (vfd->ctrl_handler)
+		return v4l2_g_ctrl(vfd->ctrl_handler, p);
+	if (ops->vidioc_g_ctrl)
+		return ops->vidioc_g_ctrl(file, fh, p);
+	if (ops->vidioc_g_ext_ctrls == NULL)
+		return -ENOTTY;
+
+	ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
+	ctrls.count = 1;
+	ctrls.controls = &ctrl;
+	ctrl.id = p->id;
+	ctrl.value = p->value;
+	if (check_ext_ctrls(&ctrls, 1)) {
+		int ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls);
+
+		if (ret == 0)
+			p->value = ctrl.value;
+		return ret;
+	}
+	return -EINVAL;
+}
+
+static int v4l_s_ctrl(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct video_device *vfd = video_devdata(file);
+	struct v4l2_control *p = arg;
+	struct v4l2_fh *vfh = fh;
+	struct v4l2_ext_controls ctrls;
+	struct v4l2_ext_control ctrl;
+
+	if (vfh && vfh->ctrl_handler)
+		return v4l2_s_ctrl(vfh, vfh->ctrl_handler, p);
+	if (vfd->ctrl_handler)
+		return v4l2_s_ctrl(NULL, vfd->ctrl_handler, p);
+	if (ops->vidioc_s_ctrl)
+		return ops->vidioc_s_ctrl(file, fh, p);
+	if (ops->vidioc_s_ext_ctrls == NULL)
+		return -ENOTTY;
+
+	ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
+	ctrls.count = 1;
+	ctrls.controls = &ctrl;
+	ctrl.id = p->id;
+	ctrl.value = p->value;
+	if (check_ext_ctrls(&ctrls, 1))
+		return ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
+	return -EINVAL;
+}
+
+static int v4l_g_ext_ctrls(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct video_device *vfd = video_devdata(file);
+	struct v4l2_ext_controls *p = arg;
+	struct v4l2_fh *vfh = fh;
+
+	p->error_idx = p->count;
+	if (vfh && vfh->ctrl_handler)
+		return v4l2_g_ext_ctrls(vfh->ctrl_handler, p);
+	if (vfd->ctrl_handler)
+		return v4l2_g_ext_ctrls(vfd->ctrl_handler, p);
+	if (ops->vidioc_g_ext_ctrls == NULL)
+		return -ENOTTY;
+	return check_ext_ctrls(p, 0) ? ops->vidioc_g_ext_ctrls(file, fh, p) :
+					-EINVAL;
+}
+
+static int v4l_s_ext_ctrls(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct video_device *vfd = video_devdata(file);
+	struct v4l2_ext_controls *p = arg;
+	struct v4l2_fh *vfh = fh;
+
+	p->error_idx = p->count;
+	if (vfh && vfh->ctrl_handler)
+		return v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, p);
+	if (vfd->ctrl_handler)
+		return v4l2_s_ext_ctrls(NULL, vfd->ctrl_handler, p);
+	if (ops->vidioc_s_ext_ctrls == NULL)
+		return -ENOTTY;
+	return check_ext_ctrls(p, 0) ? ops->vidioc_s_ext_ctrls(file, fh, p) :
+					-EINVAL;
+}
+
+static int v4l_try_ext_ctrls(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct video_device *vfd = video_devdata(file);
+	struct v4l2_ext_controls *p = arg;
+	struct v4l2_fh *vfh = fh;
+
+	p->error_idx = p->count;
+	if (vfh && vfh->ctrl_handler)
+		return v4l2_try_ext_ctrls(vfh->ctrl_handler, p);
+	if (vfd->ctrl_handler)
+		return v4l2_try_ext_ctrls(vfd->ctrl_handler, p);
+	if (ops->vidioc_try_ext_ctrls == NULL)
+		return -ENOTTY;
+	return check_ext_ctrls(p, 0) ? ops->vidioc_try_ext_ctrls(file, fh, p) :
+					-EINVAL;
+}
+
 struct v4l2_ioctl_info {
 	unsigned int ioctl;
 	u32 flags;
@@ -1297,14 +1467,14 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
 	IOCTL_INFO_FNC(VIDIOC_S_STD, v4l_s_std, v4l_print_std, INFO_FL_PRIO),
 	IOCTL_INFO_FNC(VIDIOC_ENUMSTD, v4l_enumstd, v4l_print_standard, INFO_FL_CLEAR(v4l2_standard, index)),
 	IOCTL_INFO_FNC(VIDIOC_ENUMINPUT, v4l_enuminput, v4l_print_enuminput, INFO_FL_CLEAR(v4l2_input, index)),
-	IOCTL_INFO(VIDIOC_G_CTRL, INFO_FL_CTRL),
-	IOCTL_INFO(VIDIOC_S_CTRL, INFO_FL_PRIO | INFO_FL_CTRL),
+	IOCTL_INFO_FNC(VIDIOC_G_CTRL, v4l_g_ctrl, v4l_print_control, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_control, id)),
+	IOCTL_INFO_FNC(VIDIOC_S_CTRL, v4l_s_ctrl, v4l_print_control, INFO_FL_PRIO | INFO_FL_CTRL),
 	IOCTL_INFO_FNC(VIDIOC_G_TUNER, v4l_g_tuner, v4l_print_g_tuner, INFO_FL_CLEAR(v4l2_tuner, index)),
 	IOCTL_INFO_FNC(VIDIOC_S_TUNER, v4l_s_tuner, v4l_print_s_tuner, INFO_FL_PRIO),
 	IOCTL_INFO_STD(VIDIOC_G_AUDIO, vidioc_g_audio, v4l_print_audio, 0),
 	IOCTL_INFO_STD(VIDIOC_S_AUDIO, vidioc_s_audio, v4l_print_s_audio, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_QUERYCTRL, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_queryctrl, id)),
-	IOCTL_INFO(VIDIOC_QUERYMENU, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_querymenu, index)),
+	IOCTL_INFO_FNC(VIDIOC_QUERYCTRL, v4l_queryctrl, v4l_print_queryctrl, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_queryctrl, id)),
+	IOCTL_INFO_FNC(VIDIOC_QUERYMENU, v4l_querymenu, v4l_print_querymenu, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_querymenu, index)),
 	IOCTL_INFO_STD(VIDIOC_G_INPUT, vidioc_g_input, v4l_print_u32, 0),
 	IOCTL_INFO_FNC(VIDIOC_S_INPUT, v4l_s_input, v4l_print_u32, INFO_FL_PRIO),
 	IOCTL_INFO_STD(VIDIOC_G_OUTPUT, vidioc_g_output, v4l_print_u32, 0),
@@ -1331,9 +1501,9 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
 	IOCTL_INFO_FNC(VIDIOC_S_PRIORITY, v4l_s_priority, v4l_print_u32, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_G_SLICED_VBI_CAP, INFO_FL_CLEAR(v4l2_sliced_vbi_cap, type)),
 	IOCTL_INFO(VIDIOC_LOG_STATUS, 0),
-	IOCTL_INFO(VIDIOC_G_EXT_CTRLS, INFO_FL_CTRL),
-	IOCTL_INFO(VIDIOC_S_EXT_CTRLS, INFO_FL_PRIO | INFO_FL_CTRL),
-	IOCTL_INFO(VIDIOC_TRY_EXT_CTRLS, 0),
+	IOCTL_INFO_FNC(VIDIOC_G_EXT_CTRLS, v4l_g_ext_ctrls, v4l_print_ext_controls, INFO_FL_CTRL),
+	IOCTL_INFO_FNC(VIDIOC_S_EXT_CTRLS, v4l_s_ext_ctrls, v4l_print_ext_controls, INFO_FL_PRIO | INFO_FL_CTRL),
+	IOCTL_INFO_FNC(VIDIOC_TRY_EXT_CTRLS, v4l_try_ext_ctrls, v4l_print_ext_controls, 0),
 	IOCTL_INFO(VIDIOC_ENUM_FRAMESIZES, INFO_FL_CLEAR(v4l2_frmsizeenum, pixel_format)),
 	IOCTL_INFO(VIDIOC_ENUM_FRAMEINTERVALS, INFO_FL_CLEAR(v4l2_frmivalenum, height)),
 	IOCTL_INFO(VIDIOC_G_ENC_INDEX, 0),
@@ -1465,175 +1635,6 @@ static long __video_do_ioctl(struct file *file,
 	}
 
 	switch (cmd) {
-	/* --- controls ---------------------------------------------- */
-	case VIDIOC_QUERYCTRL:
-	{
-		struct v4l2_queryctrl *p = arg;
-
-		if (vfh && vfh->ctrl_handler)
-			ret = v4l2_queryctrl(vfh->ctrl_handler, p);
-		else if (vfd->ctrl_handler)
-			ret = v4l2_queryctrl(vfd->ctrl_handler, p);
-		else if (ops->vidioc_queryctrl)
-			ret = ops->vidioc_queryctrl(file, fh, p);
-		else
-			break;
-		if (!ret)
-			dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
-					"step=%d, default=%d, flags=0x%08x\n",
-					p->id, p->type, p->name,
-					p->minimum, p->maximum,
-					p->step, p->default_value, p->flags);
-		else
-			dbgarg(cmd, "id=0x%x\n", p->id);
-		break;
-	}
-	case VIDIOC_G_CTRL:
-	{
-		struct v4l2_control *p = arg;
-
-		if (vfh && vfh->ctrl_handler)
-			ret = v4l2_g_ctrl(vfh->ctrl_handler, p);
-		else if (vfd->ctrl_handler)
-			ret = v4l2_g_ctrl(vfd->ctrl_handler, p);
-		else if (ops->vidioc_g_ctrl)
-			ret = ops->vidioc_g_ctrl(file, fh, p);
-		else if (ops->vidioc_g_ext_ctrls) {
-			struct v4l2_ext_controls ctrls;
-			struct v4l2_ext_control ctrl;
-
-			ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
-			ctrls.count = 1;
-			ctrls.controls = &ctrl;
-			ctrl.id = p->id;
-			ctrl.value = p->value;
-			if (check_ext_ctrls(&ctrls, 1)) {
-				ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls);
-				if (ret == 0)
-					p->value = ctrl.value;
-			}
-		} else
-			break;
-		if (!ret)
-			dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
-		else
-			dbgarg(cmd, "id=0x%x\n", p->id);
-		break;
-	}
-	case VIDIOC_S_CTRL:
-	{
-		struct v4l2_control *p = arg;
-		struct v4l2_ext_controls ctrls;
-		struct v4l2_ext_control ctrl;
-
-		if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
-			!ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls)
-			break;
-
-		dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
-
-		if (vfh && vfh->ctrl_handler) {
-			ret = v4l2_s_ctrl(vfh, vfh->ctrl_handler, p);
-			break;
-		}
-		if (vfd->ctrl_handler) {
-			ret = v4l2_s_ctrl(NULL, vfd->ctrl_handler, p);
-			break;
-		}
-		if (ops->vidioc_s_ctrl) {
-			ret = ops->vidioc_s_ctrl(file, fh, p);
-			break;
-		}
-		if (!ops->vidioc_s_ext_ctrls)
-			break;
-
-		ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
-		ctrls.count = 1;
-		ctrls.controls = &ctrl;
-		ctrl.id = p->id;
-		ctrl.value = p->value;
-		if (check_ext_ctrls(&ctrls, 1))
-			ret = ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
-		else
-			ret = -EINVAL;
-		break;
-	}
-	case VIDIOC_G_EXT_CTRLS:
-	{
-		struct v4l2_ext_controls *p = arg;
-
-		p->error_idx = p->count;
-		if (vfh && vfh->ctrl_handler)
-			ret = v4l2_g_ext_ctrls(vfh->ctrl_handler, p);
-		else if (vfd->ctrl_handler)
-			ret = v4l2_g_ext_ctrls(vfd->ctrl_handler, p);
-		else if (ops->vidioc_g_ext_ctrls)
-			ret = check_ext_ctrls(p, 0) ?
-				ops->vidioc_g_ext_ctrls(file, fh, p) :
-				-EINVAL;
-		else
-			break;
-		v4l_print_ext_ctrls(cmd, vfd, p, !ret);
-		break;
-	}
-	case VIDIOC_S_EXT_CTRLS:
-	{
-		struct v4l2_ext_controls *p = arg;
-
-		p->error_idx = p->count;
-		if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
-				!ops->vidioc_s_ext_ctrls)
-			break;
-		v4l_print_ext_ctrls(cmd, vfd, p, 1);
-		if (vfh && vfh->ctrl_handler)
-			ret = v4l2_s_ext_ctrls(vfh, vfh->ctrl_handler, p);
-		else if (vfd->ctrl_handler)
-			ret = v4l2_s_ext_ctrls(NULL, vfd->ctrl_handler, p);
-		else if (check_ext_ctrls(p, 0))
-			ret = ops->vidioc_s_ext_ctrls(file, fh, p);
-		else
-			ret = -EINVAL;
-		break;
-	}
-	case VIDIOC_TRY_EXT_CTRLS:
-	{
-		struct v4l2_ext_controls *p = arg;
-
-		p->error_idx = p->count;
-		if (!(vfh && vfh->ctrl_handler) && !vfd->ctrl_handler &&
-				!ops->vidioc_try_ext_ctrls)
-			break;
-		v4l_print_ext_ctrls(cmd, vfd, p, 1);
-		if (vfh && vfh->ctrl_handler)
-			ret = v4l2_try_ext_ctrls(vfh->ctrl_handler, p);
-		else if (vfd->ctrl_handler)
-			ret = v4l2_try_ext_ctrls(vfd->ctrl_handler, p);
-		else if (check_ext_ctrls(p, 0))
-			ret = ops->vidioc_try_ext_ctrls(file, fh, p);
-		else
-			ret = -EINVAL;
-		break;
-	}
-	case VIDIOC_QUERYMENU:
-	{
-		struct v4l2_querymenu *p = arg;
-
-		if (vfh && vfh->ctrl_handler)
-			ret = v4l2_querymenu(vfh->ctrl_handler, p);
-		else if (vfd->ctrl_handler)
-			ret = v4l2_querymenu(vfd->ctrl_handler, p);
-		else if (ops->vidioc_querymenu)
-			ret = ops->vidioc_querymenu(file, fh, p);
-		else
-			break;
-		if (!ret)
-			dbgarg(cmd, "id=0x%x, index=%d, name=%s\n",
-				p->id, p->index, p->name);
-		else
-			dbgarg(cmd, "id=0x%x, index=%d\n",
-				p->id, p->index);
-		break;
-	}
 	case VIDIOC_G_CROP:
 	{
 		struct v4l2_crop *p = arg;
-- 
1.7.10


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

* [RFCv1 PATCH 13/32] v4l2-ioctl.c: use the new table for selection ioctls.
  2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
                     ` (10 preceding siblings ...)
  2012-06-10 10:25   ` [RFCv1 PATCH 12/32] v4l2-ioctl.c: use the new table for control ioctls Hans Verkuil
@ 2012-06-10 10:25   ` Hans Verkuil
  2012-06-10 10:25   ` [RFCv1 PATCH 14/32] v4l2-ioctl.c: use the new table for compression ioctls Hans Verkuil
                     ` (18 subsequent siblings)
  30 siblings, 0 replies; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 10:25 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/video/v4l2-ioctl.c |  262 ++++++++++++++++++--------------------
 1 file changed, 127 insertions(+), 135 deletions(-)

diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
index 4fb113b..9e39b74 100644
--- a/drivers/media/video/v4l2-ioctl.c
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -570,17 +570,45 @@ static void v4l_print_ext_controls(const void *arg)
 	pr_cont("\n");
 }
 
-static void v4l_print_u32(const void *arg)
+static void v4l_print_cropcap(const void *arg)
 {
-	pr_cont("value=%u\n", *(const u32 *)arg);
+	const struct v4l2_cropcap *p = arg;
+
+	pr_cont("type=%s, bounds wxh=%dx%d, x,y=%d,%d, "
+		"defrect wxh=%dx%d, x,y=%d,%d\n, "
+		"pixelaspect %d/%d\n",
+		prt_names(p->type, v4l2_type_names),
+		p->bounds.width, p->bounds.height,
+		p->bounds.left, p->bounds.top,
+		p->defrect.width, p->defrect.height,
+		p->defrect.left, p->defrect.top,
+		p->pixelaspect.numerator, p->pixelaspect.denominator);
 }
 
-static inline void dbgrect(struct video_device *vfd, char *s,
-							struct v4l2_rect *r)
+static void v4l_print_crop(const void *arg)
 {
-	dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s, r->left, r->top,
-						r->width, r->height);
-};
+	const struct v4l2_crop *p = arg;
+
+	pr_cont("type=%s, wxh=%dx%d, x,y=%d,%d\n",
+		prt_names(p->type, v4l2_type_names),
+		p->c.width, p->c.height,
+		p->c.left, p->c.top);
+}
+
+static void v4l_print_selection(const void *arg)
+{
+	const struct v4l2_selection *p = arg;
+
+	pr_cont("type=%s, target=%d, flags=0x%x, wxh=%dx%d, x,y=%d,%d\n",
+		prt_names(p->type, v4l2_type_names),
+		p->target, p->flags,
+		p->r.width, p->r.height, p->r.left, p->r.top);
+}
+
+static void v4l_print_u32(const void *arg)
+{
+	pr_cont("value=%u\n", *(const u32 *)arg);
+}
 
 static void dbgtimings(struct video_device *vfd,
 			const struct v4l2_dv_timings *p)
@@ -1397,6 +1425,93 @@ static int v4l_try_ext_ctrls(const struct v4l2_ioctl_ops *ops,
 					-EINVAL;
 }
 
+static int v4l_g_crop(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct v4l2_crop *p = arg;
+	struct v4l2_selection s = {
+		.type = p->type,
+	};
+	int ret;
+
+	if (ops->vidioc_g_crop)
+		return ops->vidioc_g_crop(file, fh, p);
+	/* simulate capture crop using selection api */
+
+	/* crop means compose for output devices */
+	if (V4L2_TYPE_IS_OUTPUT(p->type))
+		s.target = V4L2_SEL_TGT_COMPOSE_ACTIVE;
+	else
+		s.target = V4L2_SEL_TGT_CROP_ACTIVE;
+
+	ret = ops->vidioc_g_selection(file, fh, &s);
+
+	/* copying results to old structure on success */
+	if (!ret)
+		p->c = s.r;
+	return ret;
+}
+
+static int v4l_s_crop(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct v4l2_crop *p = arg;
+	struct v4l2_selection s = {
+		.type = p->type,
+		.r = p->c,
+	};
+
+	if (ops->vidioc_s_crop)
+		return ops->vidioc_s_crop(file, fh, p);
+	/* simulate capture crop using selection api */
+
+	/* crop means compose for output devices */
+	if (V4L2_TYPE_IS_OUTPUT(p->type))
+		s.target = V4L2_SEL_TGT_COMPOSE_ACTIVE;
+	else
+		s.target = V4L2_SEL_TGT_CROP_ACTIVE;
+
+	return ops->vidioc_s_selection(file, fh, &s);
+}
+
+static int v4l_cropcap(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct v4l2_cropcap *p = arg;
+	struct v4l2_selection s = { .type = p->type };
+	int ret;
+
+	if (ops->vidioc_cropcap)
+		return ops->vidioc_cropcap(file, fh, p);
+
+	/* obtaining bounds */
+	if (V4L2_TYPE_IS_OUTPUT(p->type))
+		s.target = V4L2_SEL_TGT_COMPOSE_BOUNDS;
+	else
+		s.target = V4L2_SEL_TGT_CROP_BOUNDS;
+
+	ret = ops->vidioc_g_selection(file, fh, &s);
+	if (ret)
+		return ret;
+	p->bounds = s.r;
+
+	/* obtaining defrect */
+	if (V4L2_TYPE_IS_OUTPUT(p->type))
+		s.target = V4L2_SEL_TGT_COMPOSE_DEFAULT;
+	else
+		s.target = V4L2_SEL_TGT_CROP_DEFAULT;
+
+	ret = ops->vidioc_g_selection(file, fh, &s);
+	if (ret)
+		return ret;
+	p->defrect = s.r;
+
+	/* setting trivial pixelaspect */
+	p->pixelaspect.numerator = 1;
+	p->pixelaspect.denominator = 1;
+	return 0;
+}
+
 struct v4l2_ioctl_info {
 	unsigned int ioctl;
 	u32 flags;
@@ -1486,11 +1601,11 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
 	IOCTL_INFO_STD(VIDIOC_S_MODULATOR, vidioc_s_modulator, v4l_print_s_modulator, INFO_FL_PRIO),
 	IOCTL_INFO_FNC(VIDIOC_G_FREQUENCY, v4l_g_frequency, v4l_print_frequency, INFO_FL_CLEAR(v4l2_frequency, tuner)),
 	IOCTL_INFO_FNC(VIDIOC_S_FREQUENCY, v4l_s_frequency, v4l_print_frequency, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_CROPCAP, INFO_FL_CLEAR(v4l2_cropcap, type)),
-	IOCTL_INFO(VIDIOC_G_CROP, INFO_FL_CLEAR(v4l2_crop, type)),
-	IOCTL_INFO(VIDIOC_S_CROP, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_G_SELECTION, 0),
-	IOCTL_INFO(VIDIOC_S_SELECTION, INFO_FL_PRIO),
+	IOCTL_INFO_FNC(VIDIOC_CROPCAP, v4l_cropcap, v4l_print_cropcap, INFO_FL_CLEAR(v4l2_cropcap, type)),
+	IOCTL_INFO_FNC(VIDIOC_G_CROP, v4l_g_crop, v4l_print_crop, INFO_FL_CLEAR(v4l2_crop, type)),
+	IOCTL_INFO_FNC(VIDIOC_S_CROP, v4l_s_crop, v4l_print_crop, INFO_FL_PRIO),
+	IOCTL_INFO_STD(VIDIOC_G_SELECTION, vidioc_g_selection, v4l_print_selection, 0),
+	IOCTL_INFO_STD(VIDIOC_S_SELECTION, vidioc_s_selection, v4l_print_selection, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_G_JPEGCOMP, 0),
 	IOCTL_INFO(VIDIOC_S_JPEGCOMP, INFO_FL_PRIO),
 	IOCTL_INFO_FNC(VIDIOC_QUERYSTD, v4l_querystd, v4l_print_std, 0),
@@ -1635,129 +1750,6 @@ static long __video_do_ioctl(struct file *file,
 	}
 
 	switch (cmd) {
-	case VIDIOC_G_CROP:
-	{
-		struct v4l2_crop *p = arg;
-
-		dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
-
-		if (ops->vidioc_g_crop) {
-			ret = ops->vidioc_g_crop(file, fh, p);
-		} else {
-			/* simulate capture crop using selection api */
-			struct v4l2_selection s = {
-				.type = p->type,
-			};
-
-			/* crop means compose for output devices */
-			if (V4L2_TYPE_IS_OUTPUT(p->type))
-				s.target = V4L2_SEL_TGT_COMPOSE_ACTIVE;
-			else
-				s.target = V4L2_SEL_TGT_CROP_ACTIVE;
-
-			ret = ops->vidioc_g_selection(file, fh, &s);
-
-			/* copying results to old structure on success */
-			if (!ret)
-				p->c = s.r;
-		}
-
-		if (!ret)
-			dbgrect(vfd, "", &p->c);
-		break;
-	}
-	case VIDIOC_S_CROP:
-	{
-		struct v4l2_crop *p = arg;
-
-		dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
-		dbgrect(vfd, "", &p->c);
-
-		if (ops->vidioc_s_crop) {
-			ret = ops->vidioc_s_crop(file, fh, p);
-		} else {
-			/* simulate capture crop using selection api */
-			struct v4l2_selection s = {
-				.type = p->type,
-				.r = p->c,
-			};
-
-			/* crop means compose for output devices */
-			if (V4L2_TYPE_IS_OUTPUT(p->type))
-				s.target = V4L2_SEL_TGT_COMPOSE_ACTIVE;
-			else
-				s.target = V4L2_SEL_TGT_CROP_ACTIVE;
-
-			ret = ops->vidioc_s_selection(file, fh, &s);
-		}
-		break;
-	}
-	case VIDIOC_G_SELECTION:
-	{
-		struct v4l2_selection *p = arg;
-
-		dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
-
-		ret = ops->vidioc_g_selection(file, fh, p);
-		if (!ret)
-			dbgrect(vfd, "", &p->r);
-		break;
-	}
-	case VIDIOC_S_SELECTION:
-	{
-		struct v4l2_selection *p = arg;
-
-
-		dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
-		dbgrect(vfd, "", &p->r);
-
-		ret = ops->vidioc_s_selection(file, fh, p);
-		break;
-	}
-	case VIDIOC_CROPCAP:
-	{
-		struct v4l2_cropcap *p = arg;
-
-		/*FIXME: Should also show v4l2_fract pixelaspect */
-		dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
-		if (ops->vidioc_cropcap) {
-			ret = ops->vidioc_cropcap(file, fh, p);
-		} else {
-			struct v4l2_selection s = { .type = p->type };
-
-			/* obtaining bounds */
-			if (V4L2_TYPE_IS_OUTPUT(p->type))
-				s.target = V4L2_SEL_TGT_COMPOSE_BOUNDS;
-			else
-				s.target = V4L2_SEL_TGT_CROP_BOUNDS;
-
-			ret = ops->vidioc_g_selection(file, fh, &s);
-			if (ret)
-				break;
-			p->bounds = s.r;
-
-			/* obtaining defrect */
-			if (V4L2_TYPE_IS_OUTPUT(p->type))
-				s.target = V4L2_SEL_TGT_COMPOSE_DEFAULT;
-			else
-				s.target = V4L2_SEL_TGT_CROP_DEFAULT;
-
-			ret = ops->vidioc_g_selection(file, fh, &s);
-			if (ret)
-				break;
-			p->defrect = s.r;
-
-			/* setting trivial pixelaspect */
-			p->pixelaspect.numerator = 1;
-			p->pixelaspect.denominator = 1;
-		}
-
-		if (!ret) {
-			dbgrect(vfd, "bounds ", &p->bounds);
-			dbgrect(vfd, "defrect ", &p->defrect);
-		}
-		break;
-	}
 	case VIDIOC_G_JPEGCOMP:
 	{
 		struct v4l2_jpegcompression *p = arg;
-- 
1.7.10


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

* [RFCv1 PATCH 14/32] v4l2-ioctl.c: use the new table for compression ioctls.
  2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
                     ` (11 preceding siblings ...)
  2012-06-10 10:25   ` [RFCv1 PATCH 13/32] v4l2-ioctl.c: use the new table for selection ioctls Hans Verkuil
@ 2012-06-10 10:25   ` Hans Verkuil
  2012-06-10 10:25   ` [RFCv1 PATCH 15/32] v4l2-ioctl.c: use the new table for debug ioctls Hans Verkuil
                     ` (17 subsequent siblings)
  30 siblings, 0 replies; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 10:25 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/video/v4l2-ioctl.c |  123 ++++++++++++++------------------------
 1 file changed, 46 insertions(+), 77 deletions(-)

diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
index 9e39b74..a7e583e 100644
--- a/drivers/media/video/v4l2-ioctl.c
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -605,6 +605,45 @@ static void v4l_print_selection(const void *arg)
 		p->r.width, p->r.height, p->r.left, p->r.top);
 }
 
+static void v4l_print_jpegcompression(const void *arg)
+{
+	const struct v4l2_jpegcompression *p = arg;
+
+	pr_cont("quality=%d, APPn=%d, APP_len=%d, "
+		"COM_len=%d, jpeg_markers=0x%x\n",
+		p->quality, p->APPn, p->APP_len,
+		p->COM_len, p->jpeg_markers);
+}
+
+static void v4l_print_enc_idx(const void *arg)
+{
+	const struct v4l2_enc_idx *p = arg;
+
+	pr_cont("entries=%d, entries_cap=%d\n",
+			p->entries, p->entries_cap);
+}
+
+static void v4l_print_encoder_cmd(const void *arg)
+{
+	const struct v4l2_encoder_cmd *p = arg;
+
+	pr_cont("cmd=%d, flags=0x%x\n",
+			p->cmd, p->flags);
+}
+
+static void v4l_print_decoder_cmd(const void *arg)
+{
+	const struct v4l2_decoder_cmd *p = arg;
+
+	pr_cont("cmd=%d, flags=0x%x\n", p->cmd, p->flags);
+
+	if (p->cmd == V4L2_DEC_CMD_START)
+		pr_info("speed=%d, format=%u\n",
+				p->start.speed, p->start.format);
+	else if (p->cmd == V4L2_DEC_CMD_STOP)
+		pr_info("pts=%llu\n", p->stop.pts);
+}
+
 static void v4l_print_u32(const void *arg)
 {
 	pr_cont("value=%u\n", *(const u32 *)arg);
@@ -1606,8 +1645,8 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
 	IOCTL_INFO_FNC(VIDIOC_S_CROP, v4l_s_crop, v4l_print_crop, INFO_FL_PRIO),
 	IOCTL_INFO_STD(VIDIOC_G_SELECTION, vidioc_g_selection, v4l_print_selection, 0),
 	IOCTL_INFO_STD(VIDIOC_S_SELECTION, vidioc_s_selection, v4l_print_selection, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_G_JPEGCOMP, 0),
-	IOCTL_INFO(VIDIOC_S_JPEGCOMP, INFO_FL_PRIO),
+	IOCTL_INFO_STD(VIDIOC_G_JPEGCOMP, vidioc_g_jpegcomp, v4l_print_jpegcompression, 0),
+	IOCTL_INFO_STD(VIDIOC_S_JPEGCOMP, vidioc_s_jpegcomp, v4l_print_jpegcompression, INFO_FL_PRIO),
 	IOCTL_INFO_FNC(VIDIOC_QUERYSTD, v4l_querystd, v4l_print_std, 0),
 	IOCTL_INFO_FNC(VIDIOC_TRY_FMT, v4l_try_fmt, v4l_print_format, 0),
 	IOCTL_INFO_STD(VIDIOC_ENUMAUDIO, vidioc_enumaudio, v4l_print_audio, INFO_FL_CLEAR(v4l2_audio, index)),
@@ -1621,11 +1660,11 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
 	IOCTL_INFO_FNC(VIDIOC_TRY_EXT_CTRLS, v4l_try_ext_ctrls, v4l_print_ext_controls, 0),
 	IOCTL_INFO(VIDIOC_ENUM_FRAMESIZES, INFO_FL_CLEAR(v4l2_frmsizeenum, pixel_format)),
 	IOCTL_INFO(VIDIOC_ENUM_FRAMEINTERVALS, INFO_FL_CLEAR(v4l2_frmivalenum, height)),
-	IOCTL_INFO(VIDIOC_G_ENC_INDEX, 0),
-	IOCTL_INFO(VIDIOC_ENCODER_CMD, INFO_FL_PRIO | INFO_FL_CLEAR(v4l2_encoder_cmd, flags)),
-	IOCTL_INFO(VIDIOC_TRY_ENCODER_CMD, INFO_FL_CLEAR(v4l2_encoder_cmd, flags)),
-	IOCTL_INFO(VIDIOC_DECODER_CMD, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_TRY_DECODER_CMD, 0),
+	IOCTL_INFO_STD(VIDIOC_G_ENC_INDEX, vidioc_g_enc_index, v4l_print_enc_idx, 0),
+	IOCTL_INFO_STD(VIDIOC_ENCODER_CMD, vidioc_encoder_cmd, v4l_print_encoder_cmd, INFO_FL_PRIO | INFO_FL_CLEAR(v4l2_encoder_cmd, flags)),
+	IOCTL_INFO_STD(VIDIOC_TRY_ENCODER_CMD, vidioc_try_encoder_cmd, v4l_print_encoder_cmd, INFO_FL_CLEAR(v4l2_encoder_cmd, flags)),
+	IOCTL_INFO_STD(VIDIOC_DECODER_CMD, vidioc_decoder_cmd, v4l_print_decoder_cmd, INFO_FL_PRIO),
+	IOCTL_INFO_STD(VIDIOC_TRY_DECODER_CMD, vidioc_try_decoder_cmd, v4l_print_decoder_cmd, 0),
 	IOCTL_INFO(VIDIOC_DBG_S_REGISTER, 0),
 	IOCTL_INFO(VIDIOC_DBG_G_REGISTER, 0),
 	IOCTL_INFO(VIDIOC_DBG_G_CHIP_IDENT, 0),
@@ -1750,76 +1789,6 @@ static long __video_do_ioctl(struct file *file,
 	}
 
 	switch (cmd) {
-	case VIDIOC_G_JPEGCOMP:
-	{
-		struct v4l2_jpegcompression *p = arg;
-
-		ret = ops->vidioc_g_jpegcomp(file, fh, p);
-		if (!ret)
-			dbgarg(cmd, "quality=%d, APPn=%d, "
-					"APP_len=%d, COM_len=%d, "
-					"jpeg_markers=%d\n",
-					p->quality, p->APPn, p->APP_len,
-					p->COM_len, p->jpeg_markers);
-		break;
-	}
-	case VIDIOC_S_JPEGCOMP:
-	{
-		struct v4l2_jpegcompression *p = arg;
-
-		dbgarg(cmd, "quality=%d, APPn=%d, APP_len=%d, "
-					"COM_len=%d, jpeg_markers=%d\n",
-					p->quality, p->APPn, p->APP_len,
-					p->COM_len, p->jpeg_markers);
-		ret = ops->vidioc_s_jpegcomp(file, fh, p);
-		break;
-	}
-	case VIDIOC_G_ENC_INDEX:
-	{
-		struct v4l2_enc_idx *p = arg;
-
-		ret = ops->vidioc_g_enc_index(file, fh, p);
-		if (!ret)
-			dbgarg(cmd, "entries=%d, entries_cap=%d\n",
-					p->entries, p->entries_cap);
-		break;
-	}
-	case VIDIOC_ENCODER_CMD:
-	{
-		struct v4l2_encoder_cmd *p = arg;
-
-		ret = ops->vidioc_encoder_cmd(file, fh, p);
-		if (!ret)
-			dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
-		break;
-	}
-	case VIDIOC_TRY_ENCODER_CMD:
-	{
-		struct v4l2_encoder_cmd *p = arg;
-
-		ret = ops->vidioc_try_encoder_cmd(file, fh, p);
-		if (!ret)
-			dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
-		break;
-	}
-	case VIDIOC_DECODER_CMD:
-	{
-		struct v4l2_decoder_cmd *p = arg;
-
-		ret = ops->vidioc_decoder_cmd(file, fh, p);
-		if (!ret)
-			dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
-		break;
-	}
-	case VIDIOC_TRY_DECODER_CMD:
-	{
-		struct v4l2_decoder_cmd *p = arg;
-
-		ret = ops->vidioc_try_decoder_cmd(file, fh, p);
-		if (!ret)
-			dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
-		break;
-	}
 	case VIDIOC_G_SLICED_VBI_CAP:
 	{
 		struct v4l2_sliced_vbi_cap *p = arg;
-- 
1.7.10


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

* [RFCv1 PATCH 15/32] v4l2-ioctl.c: use the new table for debug ioctls.
  2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
                     ` (12 preceding siblings ...)
  2012-06-10 10:25   ` [RFCv1 PATCH 14/32] v4l2-ioctl.c: use the new table for compression ioctls Hans Verkuil
@ 2012-06-10 10:25   ` Hans Verkuil
  2012-06-10 10:25   ` [RFCv1 PATCH 16/32] v4l2-ioctl.c: use the new table for preset/timings ioctls Hans Verkuil
                     ` (16 subsequent siblings)
  30 siblings, 0 replies; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 10:25 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/video/v4l2-ioctl.c |  139 ++++++++++++++++++++++++--------------
 1 file changed, 89 insertions(+), 50 deletions(-)

diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
index a7e583e..c22a310 100644
--- a/drivers/media/video/v4l2-ioctl.c
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -644,11 +644,42 @@ static void v4l_print_decoder_cmd(const void *arg)
 		pr_info("pts=%llu\n", p->stop.pts);
 }
 
+static void v4l_print_dbg_chip_ident(const void *arg)
+{
+	const struct v4l2_dbg_chip_ident *p = arg;
+
+	pr_cont("type=%u, ", p->match.type);
+	if (p->match.type == V4L2_CHIP_MATCH_I2C_DRIVER)
+		pr_cont("name=%s, ", p->match.name);
+	else
+		pr_cont("addr=%u, ", p->match.addr);
+	pr_cont("chip_ident=%u, revision=0x%x\n",
+			p->ident, p->revision);
+}
+
+static void v4l_print_dbg_register(const void *arg)
+{
+	const struct v4l2_dbg_register *p = arg;
+
+	pr_cont("type=%u, ", p->match.type);
+	if (p->match.type == V4L2_CHIP_MATCH_I2C_DRIVER)
+		pr_cont("name=%s, ", p->match.name);
+	else
+		pr_cont("addr=%u, ", p->match.addr);
+	pr_cont("reg=0x%llx, val=0x%llx\n",
+			p->reg, p->val);
+}
+
 static void v4l_print_u32(const void *arg)
 {
 	pr_cont("value=%u\n", *(const u32 *)arg);
 }
 
+static void v4l_print_newline(const void *arg)
+{
+	pr_cont("\n");
+}
+
 static void dbgtimings(struct video_device *vfd,
 			const struct v4l2_dv_timings *p)
 {
@@ -1551,6 +1582,60 @@ static int v4l_cropcap(const struct v4l2_ioctl_ops *ops,
 	return 0;
 }
 
+static int v4l_log_status(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct video_device *vfd = video_devdata(file);
+	int ret;
+
+	if (vfd->v4l2_dev)
+		pr_info("%s: =================  START STATUS  =================\n",
+			vfd->v4l2_dev->name);
+	ret = ops->vidioc_log_status(file, fh);
+	if (vfd->v4l2_dev)
+		pr_info("%s: ==================  END STATUS  ==================\n",
+			vfd->v4l2_dev->name);
+	return ret;
+}
+
+static int v4l_dbg_g_register(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+#ifdef CONFIG_VIDEO_ADV_DEBUG
+	struct v4l2_dbg_register *p = arg;
+
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+	return ops->vidioc_g_register(file, fh, p);
+#else
+	return -ENOTTY;
+#endif
+}
+
+static int v4l_dbg_s_register(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+#ifdef CONFIG_VIDEO_ADV_DEBUG
+	struct v4l2_dbg_register *p = arg;
+
+	if (!capable(CAP_SYS_ADMIN))
+		return -EPERM;
+	return ops->vidioc_s_register(file, fh, p);
+#else
+	return -ENOTTY;
+#endif
+}
+
+static int v4l_dbg_g_chip_ident(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct v4l2_dbg_chip_ident *p = arg;
+
+	p->ident = V4L2_IDENT_NONE;
+	p->revision = 0;
+	return ops->vidioc_g_chip_ident(file, fh, p);
+}
+
 struct v4l2_ioctl_info {
 	unsigned int ioctl;
 	u32 flags;
@@ -1654,7 +1739,7 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
 	IOCTL_INFO_FNC(VIDIOC_G_PRIORITY, v4l_g_priority, v4l_print_u32, 0),
 	IOCTL_INFO_FNC(VIDIOC_S_PRIORITY, v4l_s_priority, v4l_print_u32, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_G_SLICED_VBI_CAP, INFO_FL_CLEAR(v4l2_sliced_vbi_cap, type)),
-	IOCTL_INFO(VIDIOC_LOG_STATUS, 0),
+	IOCTL_INFO_FNC(VIDIOC_LOG_STATUS, v4l_log_status, v4l_print_newline, 0),
 	IOCTL_INFO_FNC(VIDIOC_G_EXT_CTRLS, v4l_g_ext_ctrls, v4l_print_ext_controls, INFO_FL_CTRL),
 	IOCTL_INFO_FNC(VIDIOC_S_EXT_CTRLS, v4l_s_ext_ctrls, v4l_print_ext_controls, INFO_FL_PRIO | INFO_FL_CTRL),
 	IOCTL_INFO_FNC(VIDIOC_TRY_EXT_CTRLS, v4l_try_ext_ctrls, v4l_print_ext_controls, 0),
@@ -1665,9 +1750,9 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
 	IOCTL_INFO_STD(VIDIOC_TRY_ENCODER_CMD, vidioc_try_encoder_cmd, v4l_print_encoder_cmd, INFO_FL_CLEAR(v4l2_encoder_cmd, flags)),
 	IOCTL_INFO_STD(VIDIOC_DECODER_CMD, vidioc_decoder_cmd, v4l_print_decoder_cmd, INFO_FL_PRIO),
 	IOCTL_INFO_STD(VIDIOC_TRY_DECODER_CMD, vidioc_try_decoder_cmd, v4l_print_decoder_cmd, 0),
-	IOCTL_INFO(VIDIOC_DBG_S_REGISTER, 0),
-	IOCTL_INFO(VIDIOC_DBG_G_REGISTER, 0),
-	IOCTL_INFO(VIDIOC_DBG_G_CHIP_IDENT, 0),
+	IOCTL_INFO_FNC(VIDIOC_DBG_S_REGISTER, v4l_dbg_s_register, v4l_print_dbg_register, 0),
+	IOCTL_INFO_FNC(VIDIOC_DBG_G_REGISTER, v4l_dbg_g_register, v4l_print_dbg_register, 0),
+	IOCTL_INFO_FNC(VIDIOC_DBG_G_CHIP_IDENT, v4l_dbg_g_chip_ident, v4l_print_dbg_chip_ident, 0),
 	IOCTL_INFO_FNC(VIDIOC_S_HW_FREQ_SEEK, v4l_s_hw_freq_seek, v4l_print_hw_freq_seek, INFO_FL_PRIO),
 	IOCTL_INFO(VIDIOC_ENUM_DV_PRESETS, 0),
 	IOCTL_INFO(VIDIOC_S_DV_PRESET, INFO_FL_PRIO),
@@ -1802,52 +1887,6 @@ static long __video_do_ioctl(struct file *file,
 			dbgarg2("service_set=%d\n", p->service_set);
 		break;
 	}
-	case VIDIOC_LOG_STATUS:
-	{
-		if (vfd->v4l2_dev)
-			pr_info("%s: =================  START STATUS  =================\n",
-				vfd->v4l2_dev->name);
-		ret = ops->vidioc_log_status(file, fh);
-		if (vfd->v4l2_dev)
-			pr_info("%s: ==================  END STATUS  ==================\n",
-				vfd->v4l2_dev->name);
-		break;
-	}
-	case VIDIOC_DBG_G_REGISTER:
-	{
-#ifdef CONFIG_VIDEO_ADV_DEBUG
-		struct v4l2_dbg_register *p = arg;
-
-		if (!capable(CAP_SYS_ADMIN))
-			ret = -EPERM;
-		else
-			ret = ops->vidioc_g_register(file, fh, p);
-#endif
-		break;
-	}
-	case VIDIOC_DBG_S_REGISTER:
-	{
-#ifdef CONFIG_VIDEO_ADV_DEBUG
-		struct v4l2_dbg_register *p = arg;
-
-		if (!capable(CAP_SYS_ADMIN))
-			ret = -EPERM;
-		else
-			ret = ops->vidioc_s_register(file, fh, p);
-#endif
-		break;
-	}
-	case VIDIOC_DBG_G_CHIP_IDENT:
-	{
-		struct v4l2_dbg_chip_ident *p = arg;
-
-		p->ident = V4L2_IDENT_NONE;
-		p->revision = 0;
-		ret = ops->vidioc_g_chip_ident(file, fh, p);
-		if (!ret)
-			dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
-		break;
-	}
 	case VIDIOC_ENUM_FRAMESIZES:
 	{
 		struct v4l2_frmsizeenum *p = arg;
-- 
1.7.10


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

* [RFCv1 PATCH 16/32] v4l2-ioctl.c: use the new table for preset/timings ioctls.
  2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
                     ` (13 preceding siblings ...)
  2012-06-10 10:25   ` [RFCv1 PATCH 15/32] v4l2-ioctl.c: use the new table for debug ioctls Hans Verkuil
@ 2012-06-10 10:25   ` Hans Verkuil
  2012-06-10 10:25   ` [RFCv1 PATCH 17/32] v4l2-ioctl.c: use the new table for the remaining ioctls Hans Verkuil
                     ` (15 subsequent siblings)
  30 siblings, 0 replies; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 10:25 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/video/v4l2-ioctl.c |  207 ++++++++++++--------------------------
 1 file changed, 67 insertions(+), 140 deletions(-)

diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
index c22a310..f5cf92e 100644
--- a/drivers/media/video/v4l2-ioctl.c
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -670,29 +670,35 @@ static void v4l_print_dbg_register(const void *arg)
 			p->reg, p->val);
 }
 
-static void v4l_print_u32(const void *arg)
+static void v4l_print_dv_enum_presets(const void *arg)
 {
-	pr_cont("value=%u\n", *(const u32 *)arg);
+	const struct v4l2_dv_enum_preset *p = arg;
+
+	pr_cont("index=%u, preset=%u, name=%s, width=%u, height=%u\n",
+			p->index, p->preset, p->name, p->width, p->height);
 }
 
-static void v4l_print_newline(const void *arg)
+static void v4l_print_dv_preset(const void *arg)
 {
-	pr_cont("\n");
+	const struct v4l2_dv_preset *p = arg;
+
+	pr_cont("preset=%u\n", p->preset);
 }
 
-static void dbgtimings(struct video_device *vfd,
-			const struct v4l2_dv_timings *p)
+static void v4l_print_dv_timings(const void *arg)
 {
+	const struct v4l2_dv_timings *p = arg;
+
 	switch (p->type) {
 	case V4L2_DV_BT_656_1120:
-		dbgarg2("bt-656/1120:interlaced=%d,"
-				" pixelclock=%lld,"
-				" width=%d, height=%d, polarities=%x,"
-				" hfrontporch=%d, hsync=%d,"
-				" hbackporch=%d, vfrontporch=%d,"
-				" vsync=%d, vbackporch=%d,"
-				" il_vfrontporch=%d, il_vsync=%d,"
-				" il_vbackporch=%d, standards=%x, flags=%x\n",
+		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",
 				p->bt.interlaced, p->bt.pixelclock,
 				p->bt.width, p->bt.height,
 				p->bt.polarities, p->bt.hfrontporch,
@@ -703,11 +709,48 @@ static void dbgtimings(struct video_device *vfd,
 				p->bt.standards, p->bt.flags);
 		break;
 	default:
-		dbgarg2("Unknown type %d!\n", p->type);
+		pr_cont("type=%d\n", p->type);
 		break;
 	}
 }
 
+static void v4l_print_enum_dv_timings(const void *arg)
+{
+	const struct v4l2_enum_dv_timings *p = arg;
+
+	pr_cont("index=%u, ", p->index);
+	v4l_print_dv_timings(&p->timings);
+}
+
+static void v4l_print_dv_timings_cap(const void *arg)
+{
+	const struct v4l2_dv_timings_cap *p = arg;
+
+	switch (p->type) {
+	case V4L2_DV_BT_656_1120:
+		pr_cont("type=bt-656/1120, width=%u-%u, height=%u-%u, "
+			"pixelclock=%llu-%llu, standards=0x%x, capabilities=0x%x\n",
+			p->bt.min_width, p->bt.max_width,
+			p->bt.min_height, p->bt.max_height,
+			p->bt.min_pixelclock, p->bt.max_pixelclock,
+			p->bt.standards, p->bt.capabilities);
+		break;
+	default:
+		pr_cont("type=%u\n", p->type);
+		break;
+	}
+}
+
+static void v4l_print_u32(const void *arg)
+{
+	pr_cont("value=%u\n", *(const u32 *)arg);
+}
+
+static void v4l_print_newline(const void *arg)
+{
+	pr_cont("\n");
+}
+
 static int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
 {
 	__u32 i;
@@ -1754,20 +1797,20 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
 	IOCTL_INFO_FNC(VIDIOC_DBG_G_REGISTER, v4l_dbg_g_register, v4l_print_dbg_register, 0),
 	IOCTL_INFO_FNC(VIDIOC_DBG_G_CHIP_IDENT, v4l_dbg_g_chip_ident, v4l_print_dbg_chip_ident, 0),
 	IOCTL_INFO_FNC(VIDIOC_S_HW_FREQ_SEEK, v4l_s_hw_freq_seek, v4l_print_hw_freq_seek, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_ENUM_DV_PRESETS, 0),
-	IOCTL_INFO(VIDIOC_S_DV_PRESET, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_G_DV_PRESET, 0),
-	IOCTL_INFO(VIDIOC_QUERY_DV_PRESET, 0),
-	IOCTL_INFO(VIDIOC_S_DV_TIMINGS, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_G_DV_TIMINGS, 0),
+	IOCTL_INFO_STD(VIDIOC_ENUM_DV_PRESETS, vidioc_enum_dv_presets, v4l_print_dv_enum_presets, 0),
+	IOCTL_INFO_STD(VIDIOC_S_DV_PRESET, vidioc_s_dv_preset, v4l_print_dv_preset, INFO_FL_PRIO),
+	IOCTL_INFO_STD(VIDIOC_G_DV_PRESET, vidioc_g_dv_preset, v4l_print_dv_preset, 0),
+	IOCTL_INFO_STD(VIDIOC_QUERY_DV_PRESET, vidioc_query_dv_preset, v4l_print_dv_preset, 0),
+	IOCTL_INFO_STD(VIDIOC_S_DV_TIMINGS, vidioc_s_dv_timings, v4l_print_dv_timings, INFO_FL_PRIO),
+	IOCTL_INFO_STD(VIDIOC_G_DV_TIMINGS, vidioc_g_dv_timings, v4l_print_dv_timings, 0),
 	IOCTL_INFO(VIDIOC_DQEVENT, 0),
 	IOCTL_INFO(VIDIOC_SUBSCRIBE_EVENT, 0),
 	IOCTL_INFO(VIDIOC_UNSUBSCRIBE_EVENT, 0),
 	IOCTL_INFO_FNC(VIDIOC_CREATE_BUFS, v4l_create_bufs, v4l_print_create_buffers, INFO_FL_PRIO),
 	IOCTL_INFO_FNC(VIDIOC_PREPARE_BUF, v4l_prepare_buf, v4l_print_buffer, 0),
-	IOCTL_INFO(VIDIOC_ENUM_DV_TIMINGS, 0),
-	IOCTL_INFO(VIDIOC_QUERY_DV_TIMINGS, 0),
-	IOCTL_INFO(VIDIOC_DV_TIMINGS_CAP, 0),
+	IOCTL_INFO_STD(VIDIOC_ENUM_DV_TIMINGS, vidioc_enum_dv_timings, v4l_print_enum_dv_timings, 0),
+	IOCTL_INFO_STD(VIDIOC_QUERY_DV_TIMINGS, vidioc_query_dv_timings, v4l_print_dv_timings, 0),
+	IOCTL_INFO_STD(VIDIOC_DV_TIMINGS_CAP, vidioc_dv_timings_cap, v4l_print_dv_timings_cap, 0),
 };
 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
 
@@ -1952,122 +1995,6 @@ static long __video_do_ioctl(struct file *file,
 		}
 		break;
 	}
-	case VIDIOC_ENUM_DV_PRESETS:
-	{
-		struct v4l2_dv_enum_preset *p = arg;
-
-		ret = ops->vidioc_enum_dv_presets(file, fh, p);
-		if (!ret)
-			dbgarg(cmd,
-				"index=%d, preset=%d, name=%s, width=%d,"
-				" height=%d ",
-				p->index, p->preset, p->name, p->width,
-				p->height);
-		break;
-	}
-	case VIDIOC_S_DV_PRESET:
-	{
-		struct v4l2_dv_preset *p = arg;
-
-		dbgarg(cmd, "preset=%d\n", p->preset);
-		ret = ops->vidioc_s_dv_preset(file, fh, p);
-		break;
-	}
-	case VIDIOC_G_DV_PRESET:
-	{
-		struct v4l2_dv_preset *p = arg;
-
-		ret = ops->vidioc_g_dv_preset(file, fh, p);
-		if (!ret)
-			dbgarg(cmd, "preset=%d\n", p->preset);
-		break;
-	}
-	case VIDIOC_QUERY_DV_PRESET:
-	{
-		struct v4l2_dv_preset *p = arg;
-
-		ret = ops->vidioc_query_dv_preset(file, fh, p);
-		if (!ret)
-			dbgarg(cmd, "preset=%d\n", p->preset);
-		break;
-	}
-	case VIDIOC_S_DV_TIMINGS:
-	{
-		struct v4l2_dv_timings *p = arg;
-
-		dbgtimings(vfd, p);
-		switch (p->type) {
-		case V4L2_DV_BT_656_1120:
-			ret = ops->vidioc_s_dv_timings(file, fh, p);
-			break;
-		default:
-			ret = -EINVAL;
-			break;
-		}
-		break;
-	}
-	case VIDIOC_G_DV_TIMINGS:
-	{
-		struct v4l2_dv_timings *p = arg;
-
-		ret = ops->vidioc_g_dv_timings(file, fh, p);
-		if (!ret)
-			dbgtimings(vfd, p);
-		break;
-	}
-	case VIDIOC_ENUM_DV_TIMINGS:
-	{
-		struct v4l2_enum_dv_timings *p = arg;
-
-		if (!ops->vidioc_enum_dv_timings)
-			break;
-
-		ret = ops->vidioc_enum_dv_timings(file, fh, p);
-		if (!ret) {
-			dbgarg(cmd, "index=%d: ", p->index);
-			dbgtimings(vfd, &p->timings);
-		}
-		break;
-	}
-	case VIDIOC_QUERY_DV_TIMINGS:
-	{
-		struct v4l2_dv_timings *p = arg;
-
-		if (!ops->vidioc_query_dv_timings)
-			break;
-
-		ret = ops->vidioc_query_dv_timings(file, fh, p);
-		if (!ret)
-			dbgtimings(vfd, p);
-		break;
-	}
-	case VIDIOC_DV_TIMINGS_CAP:
-	{
-		struct v4l2_dv_timings_cap *p = arg;
-
-		if (!ops->vidioc_dv_timings_cap)
-			break;
-
-		ret = ops->vidioc_dv_timings_cap(file, fh, p);
-		if (ret)
-			break;
-		switch (p->type) {
-		case V4L2_DV_BT_656_1120:
-			dbgarg(cmd,
-			       "type=%d, width=%u-%u, height=%u-%u, "
-			       "pixelclock=%llu-%llu, standards=%x, capabilities=%x ",
-			       p->type,
-			       p->bt.min_width, p->bt.max_width,
-			       p->bt.min_height, p->bt.max_height,
-			       p->bt.min_pixelclock, p->bt.max_pixelclock,
-			       p->bt.standards, p->bt.capabilities);
-			break;
-		default:
-			dbgarg(cmd, "unknown type ");
-			break;
-		}
-		break;
-	}
 	case VIDIOC_DQEVENT:
 	{
 		struct v4l2_event *ev = arg;
-- 
1.7.10


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

* [RFCv1 PATCH 17/32] v4l2-ioctl.c: use the new table for the remaining ioctls.
  2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
                     ` (14 preceding siblings ...)
  2012-06-10 10:25   ` [RFCv1 PATCH 16/32] v4l2-ioctl.c: use the new table for preset/timings ioctls Hans Verkuil
@ 2012-06-10 10:25   ` Hans Verkuil
  2012-06-10 10:25   ` [RFCv1 PATCH 18/32] v4l2-ioctl.c: finalize table conversion Hans Verkuil
                     ` (14 subsequent siblings)
  30 siblings, 0 replies; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 10:25 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/video/v4l2-ioctl.c |  278 +++++++++++++++++++++-----------------
 1 file changed, 154 insertions(+), 124 deletions(-)

diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
index f5cf92e..0de31c4 100644
--- a/drivers/media/video/v4l2-ioctl.c
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -741,6 +741,125 @@ static void v4l_print_dv_timings_cap(const void *arg)
 	}
 }
 
+static void v4l_print_frmsizeenum(const void *arg)
+{
+	const struct v4l2_frmsizeenum *p = arg;
+
+	pr_cont("index=%u, pixelformat=%c%c%c%c, type=%u",
+			p->index,
+			(p->pixel_format & 0xff),
+			(p->pixel_format >>  8) & 0xff,
+			(p->pixel_format >> 16) & 0xff,
+			(p->pixel_format >> 24) & 0xff,
+			p->type);
+	switch (p->type) {
+	case V4L2_FRMSIZE_TYPE_DISCRETE:
+		pr_cont(" wxh=%ux%u\n",
+			p->discrete.width, p->discrete.height);
+		break;
+	case V4L2_FRMSIZE_TYPE_STEPWISE:
+		pr_cont(" min=%ux%u, max=%ux%u, step=%ux%u\n",
+				p->stepwise.min_width,  p->stepwise.min_height,
+				p->stepwise.step_width, p->stepwise.step_height,
+				p->stepwise.max_width,  p->stepwise.max_height);
+		break;
+	case V4L2_FRMSIZE_TYPE_CONTINUOUS:
+		/* fall through */
+	default:
+		pr_cont("\n");
+		break;
+	}
+}
+
+static void v4l_print_frmivalenum(const void *arg)
+{
+	const struct v4l2_frmivalenum *p = arg;
+
+	pr_cont("index=%u, pixelformat=%c%c%c%c, wxh=%ux%u, type=%u",
+			p->index,
+			(p->pixel_format & 0xff),
+			(p->pixel_format >>  8) & 0xff,
+			(p->pixel_format >> 16) & 0xff,
+			(p->pixel_format >> 24) & 0xff,
+			p->width, p->height, p->type);
+	switch (p->type) {
+	case V4L2_FRMIVAL_TYPE_DISCRETE:
+		pr_cont(" fps=%d/%d\n",
+				p->discrete.numerator,
+				p->discrete.denominator);
+		break;
+	case V4L2_FRMIVAL_TYPE_STEPWISE:
+		pr_cont(" min=%d/%d, max=%d/%d, step=%d/%d\n",
+				p->stepwise.min.numerator,
+				p->stepwise.min.denominator,
+				p->stepwise.max.numerator,
+				p->stepwise.max.denominator,
+				p->stepwise.step.numerator,
+				p->stepwise.step.denominator);
+		break;
+	case V4L2_FRMIVAL_TYPE_CONTINUOUS:
+		/* fall through */
+	default:
+		pr_cont("\n");
+		break;
+	}
+}
+
+static void v4l_print_event(const void *arg)
+{
+	const struct v4l2_event *p = arg;
+	const struct v4l2_event_ctrl *c;
+
+	pr_cont("type=0x%x, pending=%u, sequence=%u, id=%u, "
+		"timestamp=%lu.%9.9lu\n",
+			p->type, p->pending, p->sequence, p->id,
+			p->timestamp.tv_sec, p->timestamp.tv_nsec);
+	switch (p->type) {
+	case V4L2_EVENT_VSYNC:
+		pr_info("field=%s\n",
+			prt_names(p->u.vsync.field, v4l2_field_names));
+		break;
+	case V4L2_EVENT_CTRL:
+		c = &p->u.ctrl;
+		pr_info("changes=0x%x, type=%u, ",
+			c->changes, c->type);
+		if (c->type == V4L2_CTRL_TYPE_INTEGER64)
+			pr_cont("value64=%lld, ", c->value64);
+		else
+			pr_cont("value=%d, ", c->value);
+		pr_cont("flags=0x%x, minimum=%d, maximum=%d, step=%d,"
+				" default_value=%d\n",
+			c->flags, c->minimum, c->maximum,
+			c->step, c->default_value);
+		break;
+	case V4L2_EVENT_FRAME_SYNC:
+		pr_cont("frame_sequence=%u\n",
+			p->u.frame_sync.frame_sequence);
+		break;
+	}
+}
+
+static void v4l_print_event_subscription(const void *arg)
+{
+	const struct v4l2_event_subscription *p = arg;
+
+	pr_cont("type=0x%x, id=0x%x, flags=0x%x\n",
+			p->type, p->id, p->flags);
+}
+
+static void v4l_print_sliced_vbi_cap(const void *arg)
+{
+	const struct v4l2_sliced_vbi_cap *p = arg;
+	int i;
+
+	pr_cont("type=%s, service_set=0x%08x\n",
+			prt_names(p->type, v4l2_type_names), p->service_set);
+	for (i = 0; i < 24; i++)
+		pr_info("line[%02u]=0x%04x, 0x%04x\n", i,
+				p->service_lines[0][i],
+				p->service_lines[1][i]);
+}
+
 static void v4l_print_u32(const void *arg)
 {
 	pr_cont("value=%u\n", *(const u32 *)arg);
@@ -1679,6 +1798,35 @@ static int v4l_dbg_g_chip_ident(const struct v4l2_ioctl_ops *ops,
 	return ops->vidioc_g_chip_ident(file, fh, p);
 }
 
+static int v4l_dqevent(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	return v4l2_event_dequeue(fh, arg, file->f_flags & O_NONBLOCK);
+}
+
+static int v4l_subscribe_event(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	return ops->vidioc_subscribe_event(fh, arg);
+}
+
+static int v4l_unsubscribe_event(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	return ops->vidioc_unsubscribe_event(fh, arg);
+}
+
+static int v4l_g_sliced_vbi_cap(const struct v4l2_ioctl_ops *ops,
+				struct file *file, void *fh, void *arg)
+{
+	struct v4l2_sliced_vbi_cap *p = arg;
+
+	/* Clear up to type, everything after type is zeroed already */
+	memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
+
+	return ops->vidioc_g_sliced_vbi_cap(file, fh, p);
+}
+
 struct v4l2_ioctl_info {
 	unsigned int ioctl;
 	u32 flags;
@@ -1781,13 +1929,13 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
 	IOCTL_INFO_STD(VIDIOC_ENUMAUDOUT, vidioc_enumaudout, v4l_print_audioout, INFO_FL_CLEAR(v4l2_audioout, index)),
 	IOCTL_INFO_FNC(VIDIOC_G_PRIORITY, v4l_g_priority, v4l_print_u32, 0),
 	IOCTL_INFO_FNC(VIDIOC_S_PRIORITY, v4l_s_priority, v4l_print_u32, INFO_FL_PRIO),
-	IOCTL_INFO(VIDIOC_G_SLICED_VBI_CAP, INFO_FL_CLEAR(v4l2_sliced_vbi_cap, type)),
+	IOCTL_INFO_FNC(VIDIOC_G_SLICED_VBI_CAP, v4l_g_sliced_vbi_cap, v4l_print_sliced_vbi_cap, INFO_FL_CLEAR(v4l2_sliced_vbi_cap, type)),
 	IOCTL_INFO_FNC(VIDIOC_LOG_STATUS, v4l_log_status, v4l_print_newline, 0),
 	IOCTL_INFO_FNC(VIDIOC_G_EXT_CTRLS, v4l_g_ext_ctrls, v4l_print_ext_controls, INFO_FL_CTRL),
 	IOCTL_INFO_FNC(VIDIOC_S_EXT_CTRLS, v4l_s_ext_ctrls, v4l_print_ext_controls, INFO_FL_PRIO | INFO_FL_CTRL),
 	IOCTL_INFO_FNC(VIDIOC_TRY_EXT_CTRLS, v4l_try_ext_ctrls, v4l_print_ext_controls, 0),
-	IOCTL_INFO(VIDIOC_ENUM_FRAMESIZES, INFO_FL_CLEAR(v4l2_frmsizeenum, pixel_format)),
-	IOCTL_INFO(VIDIOC_ENUM_FRAMEINTERVALS, INFO_FL_CLEAR(v4l2_frmivalenum, height)),
+	IOCTL_INFO_STD(VIDIOC_ENUM_FRAMESIZES, vidioc_enum_framesizes, v4l_print_frmsizeenum, INFO_FL_CLEAR(v4l2_frmsizeenum, pixel_format)),
+	IOCTL_INFO_STD(VIDIOC_ENUM_FRAMEINTERVALS, vidioc_enum_frameintervals, v4l_print_frmivalenum, INFO_FL_CLEAR(v4l2_frmivalenum, height)),
 	IOCTL_INFO_STD(VIDIOC_G_ENC_INDEX, vidioc_g_enc_index, v4l_print_enc_idx, 0),
 	IOCTL_INFO_STD(VIDIOC_ENCODER_CMD, vidioc_encoder_cmd, v4l_print_encoder_cmd, INFO_FL_PRIO | INFO_FL_CLEAR(v4l2_encoder_cmd, flags)),
 	IOCTL_INFO_STD(VIDIOC_TRY_ENCODER_CMD, vidioc_try_encoder_cmd, v4l_print_encoder_cmd, INFO_FL_CLEAR(v4l2_encoder_cmd, flags)),
@@ -1803,9 +1951,9 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
 	IOCTL_INFO_STD(VIDIOC_QUERY_DV_PRESET, vidioc_query_dv_preset, v4l_print_dv_preset, 0),
 	IOCTL_INFO_STD(VIDIOC_S_DV_TIMINGS, vidioc_s_dv_timings, v4l_print_dv_timings, INFO_FL_PRIO),
 	IOCTL_INFO_STD(VIDIOC_G_DV_TIMINGS, vidioc_g_dv_timings, v4l_print_dv_timings, 0),
-	IOCTL_INFO(VIDIOC_DQEVENT, 0),
-	IOCTL_INFO(VIDIOC_SUBSCRIBE_EVENT, 0),
-	IOCTL_INFO(VIDIOC_UNSUBSCRIBE_EVENT, 0),
+	IOCTL_INFO_FNC(VIDIOC_DQEVENT, v4l_dqevent, v4l_print_event, 0),
+	IOCTL_INFO_FNC(VIDIOC_SUBSCRIBE_EVENT, v4l_subscribe_event, v4l_print_event_subscription, 0),
+	IOCTL_INFO_FNC(VIDIOC_UNSUBSCRIBE_EVENT, v4l_unsubscribe_event, v4l_print_event_subscription, 0),
 	IOCTL_INFO_FNC(VIDIOC_CREATE_BUFS, v4l_create_bufs, v4l_print_create_buffers, INFO_FL_PRIO),
 	IOCTL_INFO_FNC(VIDIOC_PREPARE_BUF, v4l_prepare_buf, v4l_print_buffer, 0),
 	IOCTL_INFO_STD(VIDIOC_ENUM_DV_TIMINGS, vidioc_enum_dv_timings, v4l_print_enum_dv_timings, 0),
@@ -1917,124 +2065,6 @@ static long __video_do_ioctl(struct file *file,
 	}
 
 	switch (cmd) {
-	case VIDIOC_G_SLICED_VBI_CAP:
-	{
-		struct v4l2_sliced_vbi_cap *p = arg;
-
-		/* Clear up to type, everything after type is zerod already */
-		memset(p, 0, offsetof(struct v4l2_sliced_vbi_cap, type));
-
-		dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
-		ret = ops->vidioc_g_sliced_vbi_cap(file, fh, p);
-		if (!ret)
-			dbgarg2("service_set=%d\n", p->service_set);
-		break;
-	}
-	case VIDIOC_ENUM_FRAMESIZES:
-	{
-		struct v4l2_frmsizeenum *p = arg;
-
-		ret = ops->vidioc_enum_framesizes(file, fh, p);
-		dbgarg(cmd,
-			"index=%d, pixelformat=%c%c%c%c, type=%d ",
-			p->index,
-			(p->pixel_format & 0xff),
-			(p->pixel_format >>  8) & 0xff,
-			(p->pixel_format >> 16) & 0xff,
-			(p->pixel_format >> 24) & 0xff,
-			p->type);
-		switch (p->type) {
-		case V4L2_FRMSIZE_TYPE_DISCRETE:
-			dbgarg3("width = %d, height=%d\n",
-				p->discrete.width, p->discrete.height);
-			break;
-		case V4L2_FRMSIZE_TYPE_STEPWISE:
-			dbgarg3("min %dx%d, max %dx%d, step %dx%d\n",
-				p->stepwise.min_width,  p->stepwise.min_height,
-				p->stepwise.step_width, p->stepwise.step_height,
-				p->stepwise.max_width,  p->stepwise.max_height);
-			break;
-		case V4L2_FRMSIZE_TYPE_CONTINUOUS:
-			dbgarg3("continuous\n");
-			break;
-		default:
-			dbgarg3("- Unknown type!\n");
-		}
-
-		break;
-	}
-	case VIDIOC_ENUM_FRAMEINTERVALS:
-	{
-		struct v4l2_frmivalenum *p = arg;
-
-		ret = ops->vidioc_enum_frameintervals(file, fh, p);
-		dbgarg(cmd,
-			"index=%d, pixelformat=%d, width=%d, height=%d, type=%d ",
-			p->index, p->pixel_format,
-			p->width, p->height, p->type);
-		switch (p->type) {
-		case V4L2_FRMIVAL_TYPE_DISCRETE:
-			dbgarg2("fps=%d/%d\n",
-				p->discrete.numerator,
-				p->discrete.denominator);
-			break;
-		case V4L2_FRMIVAL_TYPE_STEPWISE:
-			dbgarg2("min=%d/%d, max=%d/%d, step=%d/%d\n",
-				p->stepwise.min.numerator,
-				p->stepwise.min.denominator,
-				p->stepwise.max.numerator,
-				p->stepwise.max.denominator,
-				p->stepwise.step.numerator,
-				p->stepwise.step.denominator);
-			break;
-		case V4L2_FRMIVAL_TYPE_CONTINUOUS:
-			dbgarg2("continuous\n");
-			break;
-		default:
-			dbgarg2("- Unknown type!\n");
-		}
-		break;
-	}
-	case VIDIOC_DQEVENT:
-	{
-		struct v4l2_event *ev = arg;
-
-		ret = v4l2_event_dequeue(fh, ev, file->f_flags & O_NONBLOCK);
-		if (ret < 0) {
-			dbgarg(cmd, "no pending events?");
-			break;
-		}
-		dbgarg(cmd,
-		       "pending=%d, type=0x%8.8x, sequence=%d, "
-		       "timestamp=%lu.%9.9lu ",
-		       ev->pending, ev->type, ev->sequence,
-		       ev->timestamp.tv_sec, ev->timestamp.tv_nsec);
-		break;
-	}
-	case VIDIOC_SUBSCRIBE_EVENT:
-	{
-		struct v4l2_event_subscription *sub = arg;
-
-		ret = ops->vidioc_subscribe_event(fh, sub);
-		if (ret < 0) {
-			dbgarg(cmd, "failed, ret=%ld", ret);
-			break;
-		}
-		dbgarg(cmd, "type=0x%8.8x", sub->type);
-		break;
-	}
-	case VIDIOC_UNSUBSCRIBE_EVENT:
-	{
-		struct v4l2_event_subscription *sub = arg;
-
-		ret = ops->vidioc_unsubscribe_event(fh, sub);
-		if (ret < 0) {
-			dbgarg(cmd, "failed, ret=%ld", ret);
-			break;
-		}
-		dbgarg(cmd, "type=0x%8.8x", sub->type);
-		break;
-	}
 	default:
 		if (!ops->vidioc_default)
 			break;
-- 
1.7.10


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

* [RFCv1 PATCH 18/32] v4l2-ioctl.c: finalize table conversion.
  2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
                     ` (15 preceding siblings ...)
  2012-06-10 10:25   ` [RFCv1 PATCH 17/32] v4l2-ioctl.c: use the new table for the remaining ioctls Hans Verkuil
@ 2012-06-10 10:25   ` Hans Verkuil
  2012-06-18  9:46     ` Laurent Pinchart
  2012-06-10 10:25   ` [RFCv1 PATCH 19/32] v4l2-dev.c: add debug sysfs entry Hans Verkuil
                     ` (13 subsequent siblings)
  30 siblings, 1 reply; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 10:25 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/video/v4l2-ioctl.c |   35 +++++++++++++----------------------
 1 file changed, 13 insertions(+), 22 deletions(-)

diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
index 0de31c4..6c91674 100644
--- a/drivers/media/video/v4l2-ioctl.c
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -870,6 +870,11 @@ static void v4l_print_newline(const void *arg)
 	pr_cont("\n");
 }
 
+static void v4l_print_default(const void *arg)
+{
+	pr_cont("non-standard ioctl\n");
+}
+
 static int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
 {
 	__u32 i;
@@ -1853,12 +1858,6 @@ struct v4l2_ioctl_info {
 	  sizeof(((struct v4l2_struct *)0)->field)) << 16)
 #define INFO_FL_CLEAR_MASK (_IOC_SIZEMASK << 16)
 
-#define IOCTL_INFO(_ioctl, _flags) [_IOC_NR(_ioctl)] = {	\
-	.ioctl = _ioctl,					\
-	.flags = _flags,					\
-	.name = #_ioctl,					\
-}
-
 #define IOCTL_INFO_STD(_ioctl, _vidioc, _debug, _flags)			\
 	[_IOC_NR(_ioctl)] = {						\
 		.ioctl = _ioctl,					\
@@ -2042,12 +2041,12 @@ static long __video_do_ioctl(struct file *file,
 	} else {
 		default_info.ioctl = cmd;
 		default_info.flags = 0;
-		default_info.debug = NULL;
+		default_info.debug = v4l_print_default;
 		info = &default_info;
 	}
 
 	write_only = _IOC_DIR(cmd) == _IOC_WRITE;
-	if (info->debug && write_only && vfd->debug > V4L2_DEBUG_IOCTL) {
+	if (write_only && vfd->debug > V4L2_DEBUG_IOCTL) {
 		v4l_print_ioctl(vfd->name, cmd);
 		pr_cont(": ");
 		info->debug(arg);
@@ -2058,22 +2057,16 @@ static long __video_do_ioctl(struct file *file,
 		const vidioc_op *vidioc = p + info->offset;
 
 		ret = (*vidioc)(file, fh, arg);
-		goto error;
 	} else if (info->flags & INFO_FL_FUNC) {
 		ret = info->func(ops, file, fh, arg);
-		goto error;
+	} else if (!ops->vidioc_default) {
+		ret = -ENOTTY;
+	} else {
+		ret = ops->vidioc_default(file, fh,
+			use_fh_prio ? v4l2_prio_check(vfd->prio, vfh->prio) >= 0 : 0,
+			cmd, arg);
 	}
 
-	switch (cmd) {
-	default:
-		if (!ops->vidioc_default)
-			break;
-		ret = ops->vidioc_default(file, fh, use_fh_prio ?
-				v4l2_prio_check(vfd->prio, vfh->prio) >= 0 : 0,
-				cmd, arg);
-		break;
-	} /* switch */
-
 error:
 	if (vfd->debug) {
 		if (write_only && vfd->debug > V4L2_DEBUG_IOCTL) {
@@ -2087,8 +2080,6 @@ error:
 			pr_cont(": error %ld\n", ret);
 		else if (vfd->debug == V4L2_DEBUG_IOCTL)
 			pr_cont("\n");
-		else if (!info->debug)
-			return ret;
 		else if (_IOC_DIR(cmd) == _IOC_NONE)
 			info->debug(arg);
 		else {
-- 
1.7.10


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

* [RFCv1 PATCH 19/32] v4l2-dev.c: add debug sysfs entry.
  2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
                     ` (16 preceding siblings ...)
  2012-06-10 10:25   ` [RFCv1 PATCH 18/32] v4l2-ioctl.c: finalize table conversion Hans Verkuil
@ 2012-06-10 10:25   ` Hans Verkuil
  2012-06-18  9:48     ` Laurent Pinchart
  2012-06-10 10:25   ` [RFCv1 PATCH 20/32] v4l2-ioctl: remove v4l_(i2c_)print_ioctl Hans Verkuil
                     ` (12 subsequent siblings)
  30 siblings, 1 reply; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 10:25 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/video/v4l2-dev.c |   24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c
index 1500208..5c0bb18 100644
--- a/drivers/media/video/v4l2-dev.c
+++ b/drivers/media/video/v4l2-dev.c
@@ -46,6 +46,29 @@ static ssize_t show_index(struct device *cd,
 	return sprintf(buf, "%i\n", vdev->index);
 }
 
+static ssize_t show_debug(struct device *cd,
+			 struct device_attribute *attr, char *buf)
+{
+	struct video_device *vdev = to_video_device(cd);
+
+	return sprintf(buf, "%i\n", vdev->debug);
+}
+
+static ssize_t set_debug(struct device *cd, struct device_attribute *attr,
+		   const char *buf, size_t len)
+{
+	struct video_device *vdev = to_video_device(cd);
+	int res = 0;
+	u16 value;
+
+	res = kstrtou16(buf, 0, &value);
+	if (res)
+		return res;
+
+	vdev->debug = value;
+	return len;
+}
+
 static ssize_t show_name(struct device *cd,
 			 struct device_attribute *attr, char *buf)
 {
@@ -56,6 +79,7 @@ static ssize_t show_name(struct device *cd,
 
 static struct device_attribute video_device_attrs[] = {
 	__ATTR(name, S_IRUGO, show_name, NULL),
+	__ATTR(debug, 0644, show_debug, set_debug),
 	__ATTR(index, S_IRUGO, show_index, NULL),
 	__ATTR_NULL
 };
-- 
1.7.10


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

* [RFCv1 PATCH 20/32] v4l2-ioctl: remove v4l_(i2c_)print_ioctl
  2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
                     ` (17 preceding siblings ...)
  2012-06-10 10:25   ` [RFCv1 PATCH 19/32] v4l2-dev.c: add debug sysfs entry Hans Verkuil
@ 2012-06-10 10:25   ` Hans Verkuil
  2012-06-18  9:50     ` Laurent Pinchart
  2012-06-10 10:25   ` [RFCv1 PATCH 21/32] ivtv: don't mess with vfd->debug Hans Verkuil
                     ` (11 subsequent siblings)
  30 siblings, 1 reply; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 10:25 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

v4l_i2c_print_ioctl wasn't used and v4l_print_ioctl could be replaced by
v4l_i2c_printk_ioctl.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/video/pvrusb2/pvrusb2-v4l2.c |    4 ++--
 drivers/media/video/sn9c102/sn9c102.h      |    2 +-
 drivers/media/video/uvc/uvc_v4l2.c         |    2 +-
 drivers/media/video/v4l2-ioctl.c           |   34 +++++++---------------------
 include/media/v4l2-ioctl.h                 |   20 +++-------------
 5 files changed, 15 insertions(+), 47 deletions(-)

diff --git a/drivers/media/video/pvrusb2/pvrusb2-v4l2.c b/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
index 7bddfae..81ac586 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
@@ -965,7 +965,7 @@ static long pvr2_v4l2_ioctl(struct file *file,
 	long ret = -EINVAL;
 
 	if (pvrusb2_debug & PVR2_TRACE_V4LIOCTL)
-		v4l_print_ioctl(pvr2_hdw_get_driver_name(hdw), cmd);
+		v4l_printk_ioctl(pvr2_hdw_get_driver_name(hdw), cmd);
 
 	if (!pvr2_hdw_dev_ok(hdw)) {
 		pvr2_trace(PVR2_TRACE_ERROR_LEGS,
@@ -998,7 +998,7 @@ static long pvr2_v4l2_ioctl(struct file *file,
 				pvr2_trace(PVR2_TRACE_V4LIOCTL,
 					   "pvr2_v4l2_do_ioctl failure, ret=%ld"
 					   " command was:", ret);
-				v4l_print_ioctl(pvr2_hdw_get_driver_name(hdw),
+				v4l_printk_ioctl(pvr2_hdw_get_driver_name(hdw),
 						cmd);
 			}
 		}
diff --git a/drivers/media/video/sn9c102/sn9c102.h b/drivers/media/video/sn9c102/sn9c102.h
index 22ea211..2bc153e 100644
--- a/drivers/media/video/sn9c102/sn9c102.h
+++ b/drivers/media/video/sn9c102/sn9c102.h
@@ -182,7 +182,7 @@ do {                                                                          \
 #	define V4LDBG(level, name, cmd)                                       \
 do {                                                                          \
 	if (debug >= (level))                                                 \
-		v4l_print_ioctl(name, cmd);                                   \
+		v4l_printk_ioctl(name, cmd);                                  \
 } while (0)
 #	define KDBG(level, fmt, args...)                                      \
 do {                                                                          \
diff --git a/drivers/media/video/uvc/uvc_v4l2.c b/drivers/media/video/uvc/uvc_v4l2.c
index 759bef8..f00db30 100644
--- a/drivers/media/video/uvc/uvc_v4l2.c
+++ b/drivers/media/video/uvc/uvc_v4l2.c
@@ -1051,7 +1051,7 @@ static long uvc_v4l2_ioctl(struct file *file,
 {
 	if (uvc_trace_param & UVC_TRACE_IOCTL) {
 		uvc_printk(KERN_DEBUG, "uvc_v4l2_ioctl(");
-		v4l_printk_ioctl(cmd);
+		v4l_printk_ioctl(NULL, cmd);
 		printk(")\n");
 	}
 
diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
index 6c91674..c82cf98 100644
--- a/drivers/media/video/v4l2-ioctl.c
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -28,27 +28,6 @@
 #include <media/v4l2-device.h>
 #include <media/v4l2-chip-ident.h>
 
-#define dbgarg(cmd, fmt, arg...) \
-		do {							\
-		    if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {		\
-			printk(KERN_DEBUG "%s: ",  vfd->name);		\
-			v4l_printk_ioctl(cmd);				\
-			printk(" " fmt,  ## arg);			\
-		    }							\
-		} while (0)
-
-#define dbgarg2(fmt, arg...) \
-		do {							\
-		    if (vfd->debug & V4L2_DEBUG_IOCTL_ARG)		\
-			printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\
-		} while (0)
-
-#define dbgarg3(fmt, arg...) \
-		do {							\
-		    if (vfd->debug & V4L2_DEBUG_IOCTL_ARG)		\
-			printk(KERN_CONT "%s: " fmt, vfd->name, ## arg);\
-		} while (0)
-
 /* Zero out the end of the struct pointed to by p.  Everything after, but
  * not including, the specified field is cleared. */
 #define CLEAR_AFTER_FIELD(p, field) \
@@ -1970,10 +1949,13 @@ bool v4l2_is_known_ioctl(unsigned int cmd)
 
 /* Common ioctl debug function. This function can be used by
    external ioctl messages as well as internal V4L ioctl */
-void v4l_printk_ioctl(unsigned int cmd)
+void v4l_printk_ioctl(const char *prefix, unsigned int cmd)
 {
 	const char *dir, *type;
 
+	if (prefix)
+		pr_info("%s: ", prefix);
+
 	switch (_IOC_TYPE(cmd)) {
 	case 'd':
 		type = "v4l2_int";
@@ -2016,8 +1998,8 @@ static long __video_do_ioctl(struct file *file,
 	long ret = -ENOTTY;
 
 	if (ops == NULL) {
-		printk(KERN_WARNING "videodev: \"%s\" has no ioctl_ops.\n",
-				vfd->name);
+		pr_warn("%s: has no ioctl_ops.\n",
+				video_device_node_name(vfd));
 		return ret;
 	}
 
@@ -2047,7 +2029,7 @@ static long __video_do_ioctl(struct file *file,
 
 	write_only = _IOC_DIR(cmd) == _IOC_WRITE;
 	if (write_only && vfd->debug > V4L2_DEBUG_IOCTL) {
-		v4l_print_ioctl(vfd->name, cmd);
+		v4l_printk_ioctl(video_device_node_name(vfd), cmd);
 		pr_cont(": ");
 		info->debug(arg);
 	}
@@ -2075,7 +2057,7 @@ error:
 					video_device_node_name(vfd), ret);
 			return ret;
 		}
-		v4l_print_ioctl(vfd->name, cmd);
+		v4l_printk_ioctl(video_device_node_name(vfd), cmd);
 		if (ret)
 			pr_cont(": error %ld\n", ret);
 		else if (vfd->debug == V4L2_DEBUG_IOCTL)
diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
index d8b76f7..dfd984f 100644
--- a/include/media/v4l2-ioctl.h
+++ b/include/media/v4l2-ioctl.h
@@ -295,28 +295,14 @@ struct v4l2_ioctl_ops {
 #define V4L2_DEBUG_IOCTL     0x01
 #define V4L2_DEBUG_IOCTL_ARG 0x02
 
-/* Use this macro for non-I2C drivers. Pass the driver name as the first arg. */
-#define v4l_print_ioctl(name, cmd)  		 \
-	do {  					 \
-		printk(KERN_DEBUG "%s: ", name); \
-		v4l_printk_ioctl(cmd);		 \
-	} while (0)
-
-/* Use this macro in I2C drivers where 'client' is the struct i2c_client
-   pointer */
-#define v4l_i2c_print_ioctl(client, cmd) 		   \
-	do {      					   \
-		v4l_client_printk(KERN_DEBUG, client, ""); \
-		v4l_printk_ioctl(cmd);			   \
-	} while (0)
-
 /*  Video standard functions  */
 extern const char *v4l2_norm_to_name(v4l2_std_id id);
 extern void v4l2_video_std_frame_period(int id, struct v4l2_fract *frameperiod);
 extern int v4l2_video_std_construct(struct v4l2_standard *vs,
 				    int id, const char *name);
-/* Prints the ioctl in a human-readable format */
-extern void v4l_printk_ioctl(unsigned int cmd);
+/* Prints the ioctl in a human-readable format. If prefix != NULL,
+   then do printk(KERN_DEBUG "%s: ", prefix) first. */
+extern void v4l_printk_ioctl(const char *prefix, unsigned int cmd);
 
 /* names for fancy debug output */
 extern const char *v4l2_field_names[];
-- 
1.7.10


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

* [RFCv1 PATCH 21/32] ivtv: don't mess with vfd->debug.
  2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
                     ` (18 preceding siblings ...)
  2012-06-10 10:25   ` [RFCv1 PATCH 20/32] v4l2-ioctl: remove v4l_(i2c_)print_ioctl Hans Verkuil
@ 2012-06-10 10:25   ` Hans Verkuil
  2012-06-10 10:25   ` [RFCv1 PATCH 22/32] cx18: " Hans Verkuil
                     ` (10 subsequent siblings)
  30 siblings, 0 replies; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 10:25 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

This is now controlled by sysfs.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/video/ivtv/ivtv-ioctl.c   |   12 ------------
 drivers/media/video/ivtv/ivtv-ioctl.h   |    1 -
 drivers/media/video/ivtv/ivtv-streams.c |    4 ++--
 3 files changed, 2 insertions(+), 15 deletions(-)

diff --git a/drivers/media/video/ivtv/ivtv-ioctl.c b/drivers/media/video/ivtv/ivtv-ioctl.c
index f7d57b3..32a5910 100644
--- a/drivers/media/video/ivtv/ivtv-ioctl.c
+++ b/drivers/media/video/ivtv/ivtv-ioctl.c
@@ -1830,18 +1830,6 @@ static long ivtv_default(struct file *file, void *fh, bool valid_prio,
 	return 0;
 }
 
-long ivtv_v4l2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
-{
-	struct video_device *vfd = video_devdata(filp);
-	long ret;
-
-	if (ivtv_debug & IVTV_DBGFLG_IOCTL)
-		vfd->debug = V4L2_DEBUG_IOCTL | V4L2_DEBUG_IOCTL_ARG;
-	ret = video_ioctl2(filp, cmd, arg);
-	vfd->debug = 0;
-	return ret;
-}
-
 static const struct v4l2_ioctl_ops ivtv_ioctl_ops = {
 	.vidioc_querycap    		    = ivtv_querycap,
 	.vidioc_s_audio     		    = ivtv_s_audio,
diff --git a/drivers/media/video/ivtv/ivtv-ioctl.h b/drivers/media/video/ivtv/ivtv-ioctl.h
index 89185ca..7c553d1 100644
--- a/drivers/media/video/ivtv/ivtv-ioctl.h
+++ b/drivers/media/video/ivtv/ivtv-ioctl.h
@@ -31,6 +31,5 @@ void ivtv_s_std_enc(struct ivtv *itv, v4l2_std_id *std);
 void ivtv_s_std_dec(struct ivtv *itv, v4l2_std_id *std);
 int ivtv_s_frequency(struct file *file, void *fh, struct v4l2_frequency *vf);
 int ivtv_s_input(struct file *file, void *fh, unsigned int inp);
-long ivtv_v4l2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
 
 #endif
diff --git a/drivers/media/video/ivtv/ivtv-streams.c b/drivers/media/video/ivtv/ivtv-streams.c
index 6738592..87990c5 100644
--- a/drivers/media/video/ivtv/ivtv-streams.c
+++ b/drivers/media/video/ivtv/ivtv-streams.c
@@ -50,7 +50,7 @@ static const struct v4l2_file_operations ivtv_v4l2_enc_fops = {
 	.read = ivtv_v4l2_read,
 	.write = ivtv_v4l2_write,
 	.open = ivtv_v4l2_open,
-	.unlocked_ioctl = ivtv_v4l2_ioctl,
+	.unlocked_ioctl = video_ioctl2,
 	.release = ivtv_v4l2_close,
 	.poll = ivtv_v4l2_enc_poll,
 };
@@ -60,7 +60,7 @@ static const struct v4l2_file_operations ivtv_v4l2_dec_fops = {
 	.read = ivtv_v4l2_read,
 	.write = ivtv_v4l2_write,
 	.open = ivtv_v4l2_open,
-	.unlocked_ioctl = ivtv_v4l2_ioctl,
+	.unlocked_ioctl = video_ioctl2,
 	.release = ivtv_v4l2_close,
 	.poll = ivtv_v4l2_dec_poll,
 };
-- 
1.7.10


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

* [RFCv1 PATCH 22/32] cx18: don't mess with vfd->debug.
  2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
                     ` (19 preceding siblings ...)
  2012-06-10 10:25   ` [RFCv1 PATCH 21/32] ivtv: don't mess with vfd->debug Hans Verkuil
@ 2012-06-10 10:25   ` Hans Verkuil
  2012-06-10 10:25   ` [RFCv1 PATCH 23/32] v4l2-dev/ioctl.c: add vb2_queue support to video_device Hans Verkuil
                     ` (9 subsequent siblings)
  30 siblings, 0 replies; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 10:25 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

That is now handled by sysfs.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/video/cx18/cx18-ioctl.c   |   18 ------------------
 drivers/media/video/cx18/cx18-ioctl.h   |    2 --
 drivers/media/video/cx18/cx18-streams.c |    4 ++--
 3 files changed, 2 insertions(+), 22 deletions(-)

diff --git a/drivers/media/video/cx18/cx18-ioctl.c b/drivers/media/video/cx18/cx18-ioctl.c
index 35fde4e..e9912db 100644
--- a/drivers/media/video/cx18/cx18-ioctl.c
+++ b/drivers/media/video/cx18/cx18-ioctl.c
@@ -1142,24 +1142,6 @@ static long cx18_default(struct file *file, void *fh, bool valid_prio,
 	return 0;
 }
 
-long cx18_v4l2_ioctl(struct file *filp, unsigned int cmd,
-		    unsigned long arg)
-{
-	struct video_device *vfd = video_devdata(filp);
-	struct cx18_open_id *id = file2id(filp);
-	struct cx18 *cx = id->cx;
-	long res;
-
-	mutex_lock(&cx->serialize_lock);
-
-	if (cx18_debug & CX18_DBGFLG_IOCTL)
-		vfd->debug = V4L2_DEBUG_IOCTL | V4L2_DEBUG_IOCTL_ARG;
-	res = video_ioctl2(filp, cmd, arg);
-	vfd->debug = 0;
-	mutex_unlock(&cx->serialize_lock);
-	return res;
-}
-
 static const struct v4l2_ioctl_ops cx18_ioctl_ops = {
 	.vidioc_querycap                = cx18_querycap,
 	.vidioc_s_audio                 = cx18_s_audio,
diff --git a/drivers/media/video/cx18/cx18-ioctl.h b/drivers/media/video/cx18/cx18-ioctl.h
index dcb2559..2f9dd59 100644
--- a/drivers/media/video/cx18/cx18-ioctl.h
+++ b/drivers/media/video/cx18/cx18-ioctl.h
@@ -29,5 +29,3 @@ void cx18_set_funcs(struct video_device *vdev);
 int cx18_s_std(struct file *file, void *fh, v4l2_std_id *std);
 int cx18_s_frequency(struct file *file, void *fh, struct v4l2_frequency *vf);
 int cx18_s_input(struct file *file, void *fh, unsigned int inp);
-long cx18_v4l2_ioctl(struct file *filp, unsigned int cmd,
-		    unsigned long arg);
diff --git a/drivers/media/video/cx18/cx18-streams.c b/drivers/media/video/cx18/cx18-streams.c
index 4185bcb..9d598ab 100644
--- a/drivers/media/video/cx18/cx18-streams.c
+++ b/drivers/media/video/cx18/cx18-streams.c
@@ -40,8 +40,7 @@ static struct v4l2_file_operations cx18_v4l2_enc_fops = {
 	.owner = THIS_MODULE,
 	.read = cx18_v4l2_read,
 	.open = cx18_v4l2_open,
-	/* FIXME change to video_ioctl2 if serialization lock can be removed */
-	.unlocked_ioctl = cx18_v4l2_ioctl,
+	.unlocked_ioctl = video_ioctl2,
 	.release = cx18_v4l2_close,
 	.poll = cx18_v4l2_enc_poll,
 	.mmap = cx18_v4l2_mmap,
@@ -376,6 +375,7 @@ static int cx18_prep_dev(struct cx18 *cx, int type)
 	s->video_dev->fops = &cx18_v4l2_enc_fops;
 	s->video_dev->release = video_device_release;
 	s->video_dev->tvnorms = V4L2_STD_ALL;
+	s->video_dev->lock = &cx->serialize_lock;
 	set_bit(V4L2_FL_USE_FH_PRIO, &s->video_dev->flags);
 	cx18_set_funcs(s->video_dev);
 	return 0;
-- 
1.7.10


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

* [RFCv1 PATCH 23/32] v4l2-dev/ioctl.c: add vb2_queue support to video_device.
  2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
                     ` (20 preceding siblings ...)
  2012-06-10 10:25   ` [RFCv1 PATCH 22/32] cx18: " Hans Verkuil
@ 2012-06-10 10:25   ` Hans Verkuil
  2012-06-10 10:25   ` [RFCv1 PATCH 24/32] videobuf2-core: add helper functions Hans Verkuil
                     ` (8 subsequent siblings)
  30 siblings, 0 replies; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 10:25 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

This prepares struct video_device for easier integration with vb2.

It also introduces a new lock that protects the vb2_queue. It is up
to the driver to use it or not.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/video/v4l2-ioctl.c |   29 +++++++++++++++++++++--------
 include/media/v4l2-dev.h         |    8 ++++++++
 include/media/v4l2-ioctl.h       |    5 +++++
 3 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
index c82cf98..dfd5337 100644
--- a/drivers/media/video/v4l2-ioctl.c
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -1831,6 +1831,8 @@ struct v4l2_ioctl_info {
 #define INFO_FL_STD	(1 << 2)
 /* This is ioctl has its own function */
 #define INFO_FL_FUNC	(1 << 3)
+/* Queuing ioctl */
+#define INFO_FL_QUEUE	(1 << 4)
 /* Zero struct from after the field to the end */
 #define INFO_FL_CLEAR(v4l2_struct, field)			\
 	((offsetof(struct v4l2_struct, field) +			\
@@ -1860,15 +1862,15 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
 	IOCTL_INFO_FNC(VIDIOC_ENUM_FMT, v4l_enum_fmt, v4l_print_fmtdesc, INFO_FL_CLEAR(v4l2_fmtdesc, type)),
 	IOCTL_INFO_FNC(VIDIOC_G_FMT, v4l_g_fmt, v4l_print_format, INFO_FL_CLEAR(v4l2_format, type)),
 	IOCTL_INFO_FNC(VIDIOC_S_FMT, v4l_s_fmt, v4l_print_format, INFO_FL_PRIO),
-	IOCTL_INFO_FNC(VIDIOC_REQBUFS, v4l_reqbufs, v4l_print_requestbuffers, INFO_FL_PRIO),
-	IOCTL_INFO_FNC(VIDIOC_QUERYBUF, v4l_querybuf, v4l_print_buffer, INFO_FL_CLEAR(v4l2_buffer, length)),
+	IOCTL_INFO_FNC(VIDIOC_REQBUFS, v4l_reqbufs, v4l_print_requestbuffers, INFO_FL_PRIO | INFO_FL_QUEUE),
+	IOCTL_INFO_FNC(VIDIOC_QUERYBUF, v4l_querybuf, v4l_print_buffer, INFO_FL_QUEUE | INFO_FL_CLEAR(v4l2_buffer, length)),
 	IOCTL_INFO_STD(VIDIOC_G_FBUF, vidioc_g_fbuf, v4l_print_framebuffer, 0),
 	IOCTL_INFO_STD(VIDIOC_S_FBUF, vidioc_s_fbuf, v4l_print_framebuffer, INFO_FL_PRIO),
 	IOCTL_INFO_STD(VIDIOC_OVERLAY, vidioc_overlay, v4l_print_u32, INFO_FL_PRIO),
-	IOCTL_INFO_FNC(VIDIOC_QBUF, v4l_qbuf, v4l_print_buffer, 0),
-	IOCTL_INFO_FNC(VIDIOC_DQBUF, v4l_dqbuf, v4l_print_buffer, 0),
-	IOCTL_INFO_FNC(VIDIOC_STREAMON, v4l_streamon, v4l_print_buftype, INFO_FL_PRIO),
-	IOCTL_INFO_FNC(VIDIOC_STREAMOFF, v4l_streamoff, v4l_print_buftype, INFO_FL_PRIO),
+	IOCTL_INFO_FNC(VIDIOC_QBUF, v4l_qbuf, v4l_print_buffer, INFO_FL_QUEUE),
+	IOCTL_INFO_FNC(VIDIOC_DQBUF, v4l_dqbuf, v4l_print_buffer, INFO_FL_QUEUE),
+	IOCTL_INFO_FNC(VIDIOC_STREAMON, v4l_streamon, v4l_print_buftype, INFO_FL_PRIO | INFO_FL_QUEUE),
+	IOCTL_INFO_FNC(VIDIOC_STREAMOFF, v4l_streamoff, v4l_print_buftype, INFO_FL_PRIO | INFO_FL_QUEUE),
 	IOCTL_INFO_FNC(VIDIOC_G_PARM, v4l_g_parm, v4l_print_streamparm, INFO_FL_CLEAR(v4l2_streamparm, type)),
 	IOCTL_INFO_FNC(VIDIOC_S_PARM, v4l_s_parm, v4l_print_streamparm, INFO_FL_PRIO),
 	IOCTL_INFO_FNC(VIDIOC_G_STD, v4l_g_std, v4l_print_std, 0),
@@ -1932,8 +1934,8 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
 	IOCTL_INFO_FNC(VIDIOC_DQEVENT, v4l_dqevent, v4l_print_event, 0),
 	IOCTL_INFO_FNC(VIDIOC_SUBSCRIBE_EVENT, v4l_subscribe_event, v4l_print_event_subscription, 0),
 	IOCTL_INFO_FNC(VIDIOC_UNSUBSCRIBE_EVENT, v4l_unsubscribe_event, v4l_print_event_subscription, 0),
-	IOCTL_INFO_FNC(VIDIOC_CREATE_BUFS, v4l_create_bufs, v4l_print_create_buffers, INFO_FL_PRIO),
-	IOCTL_INFO_FNC(VIDIOC_PREPARE_BUF, v4l_prepare_buf, v4l_print_buffer, 0),
+	IOCTL_INFO_FNC(VIDIOC_CREATE_BUFS, v4l_create_bufs, v4l_print_create_buffers, INFO_FL_PRIO | INFO_FL_QUEUE),
+	IOCTL_INFO_FNC(VIDIOC_PREPARE_BUF, v4l_prepare_buf, v4l_print_buffer, INFO_FL_QUEUE),
 	IOCTL_INFO_STD(VIDIOC_ENUM_DV_TIMINGS, vidioc_enum_dv_timings, v4l_print_enum_dv_timings, 0),
 	IOCTL_INFO_STD(VIDIOC_QUERY_DV_TIMINGS, vidioc_query_dv_timings, v4l_print_dv_timings, 0),
 	IOCTL_INFO_STD(VIDIOC_DV_TIMINGS_CAP, vidioc_dv_timings_cap, v4l_print_dv_timings_cap, 0),
@@ -1947,6 +1949,17 @@ bool v4l2_is_known_ioctl(unsigned int cmd)
 	return v4l2_ioctls[_IOC_NR(cmd)].ioctl == cmd;
 }
 
+struct mutex *v4l2_ioctl_get_lock(struct video_device *vdev, unsigned cmd)
+{
+	if (_IOC_NR(cmd) >= V4L2_IOCTLS)
+		return vdev->lock;
+	if (test_bit(_IOC_NR(cmd), vdev->disable_locking))
+		return NULL;
+	if (vdev->queue_lock && (v4l2_ioctls[_IOC_NR(cmd)].flags & INFO_FL_QUEUE))
+		return vdev->queue_lock;
+	return vdev->lock;
+}
+
 /* Common ioctl debug function. This function can be used by
    external ioctl messages as well as internal V4L ioctl */
 void v4l_printk_ioctl(const char *prefix, unsigned int cmd)
diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
index a056e6e..ea678f2 100644
--- a/include/media/v4l2-dev.h
+++ b/include/media/v4l2-dev.h
@@ -100,6 +100,14 @@ struct video_device
 	/* Control handler associated with this device node. May be NULL. */
 	struct v4l2_ctrl_handler *ctrl_handler;
 
+	/* vb2_queue associated with this device node. May be NULL. */
+	struct vb2_queue *queue;
+	/* The current owner of the queue. May be NULL. */
+	struct v4l2_fh *queue_owner;
+	/* The mutex that protects the queue. May be NULL, in which case the
+	   serialization lock is used. */
+	struct mutex *queue_lock;
+
 	/* Priority state. If NULL, then v4l2_dev->prio will be used. */
 	struct v4l2_prio_state *prio;
 
diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
index dfd984f..19e9352 100644
--- a/include/media/v4l2-ioctl.h
+++ b/include/media/v4l2-ioctl.h
@@ -304,6 +304,11 @@ extern int v4l2_video_std_construct(struct v4l2_standard *vs,
    then do printk(KERN_DEBUG "%s: ", prefix) first. */
 extern void v4l_printk_ioctl(const char *prefix, unsigned int cmd);
 
+/* Internal use only: get the mutex (if any) that we need to lock for the
+   given command. */
+struct video_device;
+extern struct mutex *v4l2_ioctl_get_lock(struct video_device *vdev, unsigned cmd);
+
 /* names for fancy debug output */
 extern const char *v4l2_field_names[];
 extern const char *v4l2_type_names[];
-- 
1.7.10


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

* [RFCv1 PATCH 24/32] videobuf2-core: add helper functions.
  2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
                     ` (21 preceding siblings ...)
  2012-06-10 10:25   ` [RFCv1 PATCH 23/32] v4l2-dev/ioctl.c: add vb2_queue support to video_device Hans Verkuil
@ 2012-06-10 10:25   ` Hans Verkuil
  2012-06-18 10:23     ` Laurent Pinchart
  2012-06-10 10:25   ` [RFCv1 PATCH 25/32] create_bufs: handle count == 0 Hans Verkuil
                     ` (7 subsequent siblings)
  30 siblings, 1 reply; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 10:25 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

Add helper functions to make it easier to adapt drivers to vb2.

These helpers take care of core locking and check if the filehandle is the
owner of the queue.

This patch also adds support for count == 0 in create_bufs.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/video/videobuf2-core.c |  353 ++++++++++++++++++++++++++--------
 include/media/videobuf2-core.h       |   19 ++
 2 files changed, 297 insertions(+), 75 deletions(-)

diff --git a/drivers/media/video/videobuf2-core.c b/drivers/media/video/videobuf2-core.c
index 9d4e9ed..80bcc5d 100644
--- a/drivers/media/video/videobuf2-core.c
+++ b/drivers/media/video/videobuf2-core.c
@@ -454,7 +454,48 @@ static int __verify_mmap_ops(struct vb2_queue *q)
 }
 
 /**
- * vb2_reqbufs() - Initiate streaming
+ * __verify_memory_type() - do basic checks for memory and type
+ */
+static int __verify_memory_type(struct vb2_queue *q, __u32 memory, __u32 type)
+{
+	if (memory != V4L2_MEMORY_MMAP && memory != V4L2_MEMORY_USERPTR) {
+		dprintk(1, "reqbufs: unsupported memory type\n");
+		return -EINVAL;
+	}
+
+	if (type != q->type) {
+		dprintk(1, "reqbufs: requested type is incorrect\n");
+		return -EINVAL;
+	}
+
+	/*
+	 * Make sure all the required memory ops for given memory type
+	 * are available.
+	 */
+	if (memory == V4L2_MEMORY_MMAP && __verify_mmap_ops(q)) {
+		dprintk(1, "reqbufs: MMAP for current setup unsupported\n");
+		return -EINVAL;
+	}
+
+	if (memory == V4L2_MEMORY_USERPTR && __verify_userptr_ops(q)) {
+		dprintk(1, "reqbufs: USERPTR for current setup unsupported\n");
+		return -EINVAL;
+	}
+
+	if (q->fileio) {
+		dprintk(1, "reqbufs: file io in progress\n");
+		return -EBUSY;
+	}
+
+	if (q->streaming) {
+		dprintk(1, "reqbufs: streaming active\n");
+		return -EBUSY;
+	}
+	return 0;
+}
+
+/**
+ * __reqbufs() - Initiate streaming
  * @q:		videobuf2 queue
  * @req:	struct passed from userspace to vidioc_reqbufs handler in driver
  *
@@ -476,45 +517,10 @@ static int __verify_mmap_ops(struct vb2_queue *q)
  * The return values from this function are intended to be directly returned
  * from vidioc_reqbufs handler in driver.
  */
-int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
+static int __reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
 {
 	unsigned int num_buffers, allocated_buffers, num_planes = 0;
-	int ret = 0;
-
-	if (q->fileio) {
-		dprintk(1, "reqbufs: file io in progress\n");
-		return -EBUSY;
-	}
-
-	if (req->memory != V4L2_MEMORY_MMAP
-			&& req->memory != V4L2_MEMORY_USERPTR) {
-		dprintk(1, "reqbufs: unsupported memory type\n");
-		return -EINVAL;
-	}
-
-	if (req->type != q->type) {
-		dprintk(1, "reqbufs: requested type is incorrect\n");
-		return -EINVAL;
-	}
-
-	if (q->streaming) {
-		dprintk(1, "reqbufs: streaming active\n");
-		return -EBUSY;
-	}
-
-	/*
-	 * Make sure all the required memory ops for given memory type
-	 * are available.
-	 */
-	if (req->memory == V4L2_MEMORY_MMAP && __verify_mmap_ops(q)) {
-		dprintk(1, "reqbufs: MMAP for current setup unsupported\n");
-		return -EINVAL;
-	}
-
-	if (req->memory == V4L2_MEMORY_USERPTR && __verify_userptr_ops(q)) {
-		dprintk(1, "reqbufs: USERPTR for current setup unsupported\n");
-		return -EINVAL;
-	}
+	int ret;
 
 	if (req->count == 0 || q->num_buffers != 0 || q->memory != req->memory) {
 		/*
@@ -595,10 +601,23 @@ int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
 
 	return 0;
 }
+
+/**
+ * vb2_reqbufs() - Wrapper for __reqbufs() that also verifies the memory and
+ * type values.
+ * @q:		videobuf2 queue
+ * @req:	struct passed from userspace to vidioc_reqbufs handler in driver
+ */
+int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
+{
+	int ret = __verify_memory_type(q, req->memory, req->type);
+
+	return ret ? ret : __reqbufs(q, req);
+}
 EXPORT_SYMBOL_GPL(vb2_reqbufs);
 
 /**
- * vb2_create_bufs() - Allocate buffers and any required auxiliary structs
+ * __create_bufs() - Allocate buffers and any required auxiliary structs
  * @q:		videobuf2 queue
  * @create:	creation parameters, passed from userspace to vidioc_create_bufs
  *		handler in driver
@@ -612,40 +631,10 @@ EXPORT_SYMBOL_GPL(vb2_reqbufs);
  * The return values from this function are intended to be directly returned
  * from vidioc_create_bufs handler in driver.
  */
-int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create)
+static int __create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create)
 {
 	unsigned int num_planes = 0, num_buffers, allocated_buffers;
-	int ret = 0;
-
-	if (q->fileio) {
-		dprintk(1, "%s(): file io in progress\n", __func__);
-		return -EBUSY;
-	}
-
-	if (create->memory != V4L2_MEMORY_MMAP
-			&& create->memory != V4L2_MEMORY_USERPTR) {
-		dprintk(1, "%s(): unsupported memory type\n", __func__);
-		return -EINVAL;
-	}
-
-	if (create->format.type != q->type) {
-		dprintk(1, "%s(): requested type is incorrect\n", __func__);
-		return -EINVAL;
-	}
-
-	/*
-	 * Make sure all the required memory ops for given memory type
-	 * are available.
-	 */
-	if (create->memory == V4L2_MEMORY_MMAP && __verify_mmap_ops(q)) {
-		dprintk(1, "%s(): MMAP for current setup unsupported\n", __func__);
-		return -EINVAL;
-	}
-
-	if (create->memory == V4L2_MEMORY_USERPTR && __verify_userptr_ops(q)) {
-		dprintk(1, "%s(): USERPTR for current setup unsupported\n", __func__);
-		return -EINVAL;
-	}
+	int ret;
 
 	if (q->num_buffers == VIDEO_MAX_FRAME) {
 		dprintk(1, "%s(): maximum number of buffers already allocated\n",
@@ -653,8 +642,6 @@ int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create)
 		return -ENOBUFS;
 	}
 
-	create->index = q->num_buffers;
-
 	if (!q->num_buffers) {
 		memset(q->plane_sizes, 0, sizeof(q->plane_sizes));
 		memset(q->alloc_ctx, 0, sizeof(q->alloc_ctx));
@@ -706,9 +693,9 @@ int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create)
 
 	q->num_buffers += allocated_buffers;
 
-	if (ret < 0) {
+	if (ret == 0) {
 		__vb2_queue_free(q, allocated_buffers);
-		return ret;
+		return -ENOMEM;
 	}
 
 	/*
@@ -719,6 +706,23 @@ int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create)
 
 	return 0;
 }
+
+/**
+ * vb2_reqbufs() - Wrapper for __reqbufs() that also verifies the memory and
+ * type values.
+ * @q:		videobuf2 queue
+ * @create:	creation parameters, passed from userspace to vidioc_create_bufs
+ *		handler in driver
+ */
+int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create)
+{
+	int ret = __verify_memory_type(q, create->memory, create->format.type);
+
+	create->index = q->num_buffers;
+	if (create->count == 0)
+		return ret == -EINVAL ? ret : 0;
+	return ret ? ret : __create_bufs(q, create);
+}
 EXPORT_SYMBOL_GPL(vb2_create_bufs);
 
 /**
@@ -2115,6 +2119,205 @@ size_t vb2_write(struct vb2_queue *q, char __user *data, size_t count,
 }
 EXPORT_SYMBOL_GPL(vb2_write);
 
+static inline bool vb2_queue_is_busy(struct video_device *vdev, struct file *file)
+{
+	return vdev->queue_owner && vdev->queue_owner != file->private_data;
+}
+
+int vb2_ioctl_reqbufs(struct file *file, void *priv,
+			  struct v4l2_requestbuffers *p)
+{
+	struct video_device *vdev = video_devdata(file);
+	int res = __verify_memory_type(vdev->queue, p->memory, p->type);
+
+	if (res)
+		return res;
+	if (vb2_queue_is_busy(vdev, file))
+		return -EBUSY;
+	res = __reqbufs(vdev->queue, p);
+	if (res == 0)
+		vdev->queue_owner = p->count ? file->private_data : NULL;
+	return res;
+}
+EXPORT_SYMBOL_GPL(vb2_ioctl_reqbufs);
+
+int vb2_ioctl_create_bufs(struct file *file, void *priv,
+			  struct v4l2_create_buffers *p)
+{
+	struct video_device *vdev = video_devdata(file);
+	int res = __verify_memory_type(vdev->queue, p->memory, p->format.type);
+
+	p->index = vdev->queue->num_buffers;
+	if (p->count == 0)
+		return res == -EINVAL ? res : 0;
+	if (res)
+		return res;
+	if (vb2_queue_is_busy(vdev, file))
+		return -EBUSY;
+	res = __create_bufs(vdev->queue, p);
+	if (res == 0)
+		vdev->queue_owner = file->private_data;
+	return res;
+}
+EXPORT_SYMBOL_GPL(vb2_ioctl_create_bufs);
+
+int vb2_ioctl_prepare_buf(struct file *file, void *priv,
+			  struct v4l2_buffer *p)
+{
+	struct video_device *vdev = video_devdata(file);
+
+	if (vb2_queue_is_busy(vdev, file))
+		return -EBUSY;
+	return vb2_prepare_buf(vdev->queue, p);
+}
+EXPORT_SYMBOL_GPL(vb2_ioctl_prepare_buf);
+
+int vb2_ioctl_querybuf(struct file *file, void *priv, struct v4l2_buffer *p)
+{
+	struct video_device *vdev = video_devdata(file);
+
+	return vb2_querybuf(vdev->queue, p);
+}
+EXPORT_SYMBOL_GPL(vb2_ioctl_querybuf);
+
+int vb2_ioctl_qbuf(struct file *file, void *priv, struct v4l2_buffer *p)
+{
+	struct video_device *vdev = video_devdata(file);
+
+	if (vb2_queue_is_busy(vdev, file))
+		return -EBUSY;
+	return vb2_qbuf(vdev->queue, p);
+}
+EXPORT_SYMBOL_GPL(vb2_ioctl_qbuf);
+
+int vb2_ioctl_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
+{
+	struct video_device *vdev = video_devdata(file);
+
+	if (vb2_queue_is_busy(vdev, file))
+		return -EBUSY;
+	return vb2_dqbuf(vdev->queue, p, file->f_flags & O_NONBLOCK);
+}
+EXPORT_SYMBOL_GPL(vb2_ioctl_dqbuf);
+
+int vb2_ioctl_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
+{
+	struct video_device *vdev = video_devdata(file);
+
+	if (vb2_queue_is_busy(vdev, file))
+		return -EBUSY;
+	return vb2_streamon(vdev->queue, i);
+}
+EXPORT_SYMBOL_GPL(vb2_ioctl_streamon);
+
+int vb2_ioctl_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
+{
+	struct video_device *vdev = video_devdata(file);
+
+	if (vb2_queue_is_busy(vdev, file))
+		return -EBUSY;
+	return vb2_streamoff(vdev->queue, i);
+}
+EXPORT_SYMBOL_GPL(vb2_ioctl_streamoff);
+
+int vb2_fop_mmap(struct file *file, struct vm_area_struct *vma)
+{
+	struct video_device *vdev = video_devdata(file);
+
+	return vb2_mmap(vdev->queue, vma);
+}
+EXPORT_SYMBOL_GPL(vb2_fop_mmap);
+
+int vb2_fop_release(struct file *file)
+{
+	struct video_device *vdev = video_devdata(file);
+
+	if (file->private_data == vdev->queue_owner) {
+		vb2_queue_release(vdev->queue);
+		vdev->queue_owner = NULL;
+	}
+	return v4l2_fh_release(file);
+}
+EXPORT_SYMBOL_GPL(vb2_fop_release);
+
+ssize_t vb2_fop_write(struct file *file, char __user *buf,
+		size_t count, loff_t *ppos)
+{
+	struct video_device *vdev = video_devdata(file);
+	struct mutex *lock = vdev->queue_lock ? vdev->queue_lock : vdev->lock;
+	bool must_lock = !test_bit(V4L2_FL_LOCK_ALL_FOPS, &vdev->flags) && lock;
+	int err = -EBUSY;
+
+	if (must_lock && mutex_lock_interruptible(lock))
+		return -ERESTARTSYS;
+	if (vb2_queue_is_busy(vdev, file))
+		goto exit;
+	err = vb2_write(vdev->queue, buf, count, ppos,
+		       file->f_flags & O_NONBLOCK);
+	if (err >= 0)
+		vdev->queue_owner = file->private_data;
+exit:
+	if (must_lock)
+		mutex_unlock(lock);
+	return err;
+}
+EXPORT_SYMBOL_GPL(vb2_fop_write);
+
+ssize_t vb2_fop_read(struct file *file, char __user *buf,
+		size_t count, loff_t *ppos)
+{
+	struct video_device *vdev = video_devdata(file);
+	struct mutex *lock = vdev->queue_lock ? vdev->queue_lock : vdev->lock;
+	bool must_lock = !test_bit(V4L2_FL_LOCK_ALL_FOPS, &vdev->flags) && vdev->lock;
+	int err = -EBUSY;
+
+	if (must_lock && mutex_lock_interruptible(lock))
+		return -ERESTARTSYS;
+	if (vb2_queue_is_busy(vdev, file))
+		goto exit;
+	err = vb2_read(vdev->queue, buf, count, ppos,
+		       file->f_flags & O_NONBLOCK);
+	if (err >= 0)
+		vdev->queue_owner = file->private_data;
+exit:
+	if (must_lock)
+		mutex_unlock(lock);
+	return err;
+}
+EXPORT_SYMBOL_GPL(vb2_fop_read);
+
+unsigned int vb2_fop_poll(struct file *file, poll_table *wait)
+{
+	struct video_device *vdev = video_devdata(file);
+	struct vb2_queue *q = vdev->queue;
+	struct mutex *lock = vdev->queue_lock ? vdev->queue_lock : vdev->lock;
+	unsigned res;
+	unsigned long req_events = poll_requested_events(wait);
+	void *fileio = q->fileio;
+	bool must_lock = false;
+
+	if (lock && q && q->num_buffers == 0 && fileio == NULL &&
+			!test_bit(V4L2_FL_LOCK_ALL_FOPS, &vdev->flags)) {
+		if (!V4L2_TYPE_IS_OUTPUT(q->type) && (q->io_modes & VB2_READ) &&
+				(req_events & (POLLIN | POLLRDNORM)))
+			must_lock = true;
+		else if (V4L2_TYPE_IS_OUTPUT(q->type) && (q->io_modes & VB2_WRITE) &&
+				(req_events & (POLLOUT | POLLWRNORM)))
+			must_lock = true;
+	}
+
+	if (must_lock && mutex_lock_interruptible(lock))
+		return POLLERR;
+
+	res = vb2_poll(vdev->queue, file, wait);
+	if (!fileio && vdev->queue->fileio)
+		vdev->queue_owner = file->private_data;
+	if (must_lock)
+		mutex_unlock(lock);
+	return res;
+}
+EXPORT_SYMBOL_GPL(vb2_fop_poll);
+
 MODULE_DESCRIPTION("Driver helper framework for Video for Linux 2");
 MODULE_AUTHOR("Pawel Osciak <pawel@osciak.com>, Marek Szyprowski");
 MODULE_LICENSE("GPL");
diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
index a15d1f1..4b1c8d3 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-core.h
@@ -404,4 +404,23 @@ vb2_plane_size(struct vb2_buffer *vb, unsigned int plane_no)
 	return 0;
 }
 
+int vb2_ioctl_reqbufs(struct file *file, void *priv,
+			  struct v4l2_requestbuffers *p);
+int vb2_ioctl_create_bufs(struct file *file, void *priv,
+			  struct v4l2_create_buffers *p);
+int vb2_ioctl_prepare_buf(struct file *file, void *priv,
+			  struct v4l2_buffer *p);
+int vb2_ioctl_querybuf(struct file *file, void *priv, struct v4l2_buffer *p);
+int vb2_ioctl_qbuf(struct file *file, void *priv, struct v4l2_buffer *p);
+int vb2_ioctl_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p);
+int vb2_ioctl_streamon(struct file *file, void *priv, enum v4l2_buf_type i);
+int vb2_ioctl_streamoff(struct file *file, void *priv, enum v4l2_buf_type i);
+int vb2_fop_mmap(struct file *file, struct vm_area_struct *vma);
+int vb2_fop_release(struct file *file);
+ssize_t vb2_fop_write(struct file *file, char __user *buf,
+		size_t count, loff_t *ppos);
+ssize_t vb2_fop_read(struct file *file, char __user *buf,
+		size_t count, loff_t *ppos);
+unsigned int vb2_fop_poll(struct file *file, poll_table *wait);
+
 #endif /* _MEDIA_VIDEOBUF2_CORE_H */
-- 
1.7.10


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

* [RFCv1 PATCH 25/32] create_bufs: handle count == 0.
  2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
                     ` (22 preceding siblings ...)
  2012-06-10 10:25   ` [RFCv1 PATCH 24/32] videobuf2-core: add helper functions Hans Verkuil
@ 2012-06-10 10:25   ` Hans Verkuil
  2012-06-18 10:11     ` Laurent Pinchart
  2012-06-10 10:25   ` [RFCv1 PATCH 26/32] vivi: remove pointless g/s_std support Hans Verkuil
                     ` (6 subsequent siblings)
  30 siblings, 1 reply; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 10:25 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 Documentation/DocBook/media/v4l/vidioc-create-bufs.xml |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/Documentation/DocBook/media/v4l/vidioc-create-bufs.xml b/Documentation/DocBook/media/v4l/vidioc-create-bufs.xml
index 765549f..afdba4d 100644
--- a/Documentation/DocBook/media/v4l/vidioc-create-bufs.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-create-bufs.xml
@@ -97,7 +97,13 @@ information.</para>
 	  <row>
 	    <entry>__u32</entry>
 	    <entry><structfield>count</structfield></entry>
-	    <entry>The number of buffers requested or granted.</entry>
+	    <entry>The number of buffers requested or granted. If count == 0, then
+	    <constant>VIDIOC_CREATE_BUFS</constant> will set <structfield>index</structfield>
+	    to the starting buffer index, and it will check the validity of
+	    <structfield>memory</structfield> and <structfield>format.type</structfield>.
+	    If those are invalid -1 is returned and errno is set to &EINVAL;,
+	    otherwise <constant>VIDIOC_CREATE_BUFS</constant> returns 0. It will
+	    never set errno to &EBUSY; in this particular case.</entry>
 	  </row>
 	  <row>
 	    <entry>__u32</entry>
-- 
1.7.10


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

* [RFCv1 PATCH 26/32] vivi: remove pointless g/s_std support
  2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
                     ` (23 preceding siblings ...)
  2012-06-10 10:25   ` [RFCv1 PATCH 25/32] create_bufs: handle count == 0 Hans Verkuil
@ 2012-06-10 10:25   ` Hans Verkuil
  2012-06-10 10:25   ` [RFCv1 PATCH 27/32] vivi: embed struct video_device instead of allocating it Hans Verkuil
                     ` (5 subsequent siblings)
  30 siblings, 0 replies; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 10:25 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/video/vivi.c |    9 ---------
 1 file changed, 9 deletions(-)

diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c
index 08c1024..8dd5ae6 100644
--- a/drivers/media/video/vivi.c
+++ b/drivers/media/video/vivi.c
@@ -1072,11 +1072,6 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
 	return vb2_streamoff(&dev->vb_vidq, i);
 }
 
-static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *i)
-{
-	return 0;
-}
-
 /* only one input in this sample driver */
 static int vidioc_enum_input(struct file *file, void *priv,
 				struct v4l2_input *inp)
@@ -1318,7 +1313,6 @@ static const struct v4l2_ioctl_ops vivi_ioctl_ops = {
 	.vidioc_querybuf      = vidioc_querybuf,
 	.vidioc_qbuf          = vidioc_qbuf,
 	.vidioc_dqbuf         = vidioc_dqbuf,
-	.vidioc_s_std         = vidioc_s_std,
 	.vidioc_enum_input    = vidioc_enum_input,
 	.vidioc_g_input       = vidioc_g_input,
 	.vidioc_s_input       = vidioc_s_input,
@@ -1334,9 +1328,6 @@ static struct video_device vivi_template = {
 	.fops           = &vivi_fops,
 	.ioctl_ops 	= &vivi_ioctl_ops,
 	.release	= video_device_release,
-
-	.tvnorms              = V4L2_STD_525_60,
-	.current_norm         = V4L2_STD_NTSC_M,
 };
 
 /* -----------------------------------------------------------------
-- 
1.7.10


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

* [RFCv1 PATCH 27/32] vivi: embed struct video_device instead of allocating it.
  2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
                     ` (24 preceding siblings ...)
  2012-06-10 10:25   ` [RFCv1 PATCH 26/32] vivi: remove pointless g/s_std support Hans Verkuil
@ 2012-06-10 10:25   ` Hans Verkuil
  2012-06-18 10:13     ` Laurent Pinchart
  2012-06-10 10:25   ` [RFCv1 PATCH 28/32] vivi: use vb2 helper functions Hans Verkuil
                     ` (4 subsequent siblings)
  30 siblings, 1 reply; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 10:25 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/video/vivi.c |   25 +++++++------------------
 1 file changed, 7 insertions(+), 18 deletions(-)

diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c
index 8dd5ae6..1e4da5e 100644
--- a/drivers/media/video/vivi.c
+++ b/drivers/media/video/vivi.c
@@ -188,6 +188,7 @@ struct vivi_dev {
 	struct list_head           vivi_devlist;
 	struct v4l2_device 	   v4l2_dev;
 	struct v4l2_ctrl_handler   ctrl_handler;
+	struct video_device	   vdev;
 
 	/* controls */
 	struct v4l2_ctrl	   *brightness;
@@ -213,9 +214,6 @@ struct vivi_dev {
 	spinlock_t                 slock;
 	struct mutex		   mutex;
 
-	/* various device info */
-	struct video_device        *vfd;
-
 	struct vivi_dmaqueue       vidq;
 
 	/* Several counters */
@@ -1080,7 +1078,6 @@ static int vidioc_enum_input(struct file *file, void *priv,
 		return -EINVAL;
 
 	inp->type = V4L2_INPUT_TYPE_CAMERA;
-	inp->std = V4L2_STD_525_60;
 	sprintf(inp->name, "Camera %u", inp->index);
 	return 0;
 }
@@ -1327,7 +1324,7 @@ static struct video_device vivi_template = {
 	.name		= "vivi",
 	.fops           = &vivi_fops,
 	.ioctl_ops 	= &vivi_ioctl_ops,
-	.release	= video_device_release,
+	.release	= video_device_release_empty,
 };
 
 /* -----------------------------------------------------------------
@@ -1345,8 +1342,8 @@ static int vivi_release(void)
 		dev = list_entry(list, struct vivi_dev, vivi_devlist);
 
 		v4l2_info(&dev->v4l2_dev, "unregistering %s\n",
-			video_device_node_name(dev->vfd));
-		video_unregister_device(dev->vfd);
+			video_device_node_name(&dev->vdev));
+		video_unregister_device(&dev->vdev);
 		v4l2_device_unregister(&dev->v4l2_dev);
 		v4l2_ctrl_handler_free(&dev->ctrl_handler);
 		kfree(dev);
@@ -1431,11 +1428,7 @@ static int __init vivi_create_instance(int inst)
 	INIT_LIST_HEAD(&dev->vidq.active);
 	init_waitqueue_head(&dev->vidq.wq);
 
-	ret = -ENOMEM;
-	vfd = video_device_alloc();
-	if (!vfd)
-		goto unreg_dev;
-
+	vfd = &dev->vdev;
 	*vfd = vivi_template;
 	vfd->debug = debug;
 	vfd->v4l2_dev = &dev->v4l2_dev;
@@ -1446,12 +1439,11 @@ static int __init vivi_create_instance(int inst)
 	 * all fops and v4l2 ioctls.
 	 */
 	vfd->lock = &dev->mutex;
+	video_set_drvdata(vfd, dev);
 
 	ret = video_register_device(vfd, VFL_TYPE_GRABBER, video_nr);
 	if (ret < 0)
-		goto rel_vdev;
-
-	video_set_drvdata(vfd, dev);
+		goto unreg_dev;
 
 	/* Now that everything is fine, let's add it to device list */
 	list_add_tail(&dev->vivi_devlist, &vivi_devlist);
@@ -1459,13 +1451,10 @@ static int __init vivi_create_instance(int inst)
 	if (video_nr != -1)
 		video_nr++;
 
-	dev->vfd = vfd;
 	v4l2_info(&dev->v4l2_dev, "V4L2 device registered as %s\n",
 		  video_device_node_name(vfd));
 	return 0;
 
-rel_vdev:
-	video_device_release(vfd);
 unreg_dev:
 	v4l2_ctrl_handler_free(hdl);
 	v4l2_device_unregister(&dev->v4l2_dev);
-- 
1.7.10


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

* [RFCv1 PATCH 28/32] vivi: use vb2 helper functions.
  2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
                     ` (25 preceding siblings ...)
  2012-06-10 10:25   ` [RFCv1 PATCH 27/32] vivi: embed struct video_device instead of allocating it Hans Verkuil
@ 2012-06-10 10:25   ` Hans Verkuil
  2012-06-18 10:08     ` Laurent Pinchart
  2012-06-10 10:25   ` [RFCv1 PATCH 29/32] v4l2-dev.c: also add debug support for the fops Hans Verkuil
                     ` (3 subsequent siblings)
  30 siblings, 1 reply; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 10:25 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/video/vivi.c |  160 ++++++--------------------------------------
 1 file changed, 21 insertions(+), 139 deletions(-)

diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c
index 1e4da5e..1e8c4f3 100644
--- a/drivers/media/video/vivi.c
+++ b/drivers/media/video/vivi.c
@@ -767,7 +767,13 @@ static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
 	struct vivi_dev *dev = vb2_get_drv_priv(vq);
 	unsigned long size;
 
-	size = dev->width * dev->height * dev->pixelsize;
+	if (fmt)
+		size = fmt->fmt.pix.sizeimage;
+	else
+		size = dev->width * dev->height * dev->pixelsize;
+
+	if (size == 0)
+		return -EINVAL;
 
 	if (0 == *nbuffers)
 		*nbuffers = 32;
@@ -790,27 +796,6 @@ static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
 	return 0;
 }
 
-static int buffer_init(struct vb2_buffer *vb)
-{
-	struct vivi_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
-
-	BUG_ON(NULL == dev->fmt);
-
-	/*
-	 * This callback is called once per buffer, after its allocation.
-	 *
-	 * Vivi does not allow changing format during streaming, but it is
-	 * possible to do so when streaming is paused (i.e. in streamoff state).
-	 * Buffers however are not freed when going into streamoff and so
-	 * buffer size verification has to be done in buffer_prepare, on each
-	 * qbuf.
-	 * It would be best to move verification code here to buf_init and
-	 * s_fmt though.
-	 */
-
-	return 0;
-}
-
 static int buffer_prepare(struct vb2_buffer *vb)
 {
 	struct vivi_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
@@ -848,20 +833,6 @@ static int buffer_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
-static int buffer_finish(struct vb2_buffer *vb)
-{
-	struct vivi_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
-	dprintk(dev, 1, "%s\n", __func__);
-	return 0;
-}
-
-static void buffer_cleanup(struct vb2_buffer *vb)
-{
-	struct vivi_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
-	dprintk(dev, 1, "%s\n", __func__);
-
-}
-
 static void buffer_queue(struct vb2_buffer *vb)
 {
 	struct vivi_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
@@ -907,10 +878,7 @@ static void vivi_unlock(struct vb2_queue *vq)
 
 static struct vb2_ops vivi_video_qops = {
 	.queue_setup		= queue_setup,
-	.buf_init		= buffer_init,
 	.buf_prepare		= buffer_prepare,
-	.buf_finish		= buffer_finish,
-	.buf_cleanup		= buffer_cleanup,
 	.buf_queue		= buffer_queue,
 	.start_streaming	= start_streaming,
 	.stop_streaming		= stop_streaming,
@@ -1019,7 +987,7 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
 	if (ret < 0)
 		return ret;
 
-	if (vb2_is_streaming(q)) {
+	if (vb2_is_busy(q)) {
 		dprintk(dev, 1, "%s device busy\n", __func__);
 		return -EBUSY;
 	}
@@ -1033,43 +1001,6 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
 	return 0;
 }
 
-static int vidioc_reqbufs(struct file *file, void *priv,
-			  struct v4l2_requestbuffers *p)
-{
-	struct vivi_dev *dev = video_drvdata(file);
-	return vb2_reqbufs(&dev->vb_vidq, p);
-}
-
-static int vidioc_querybuf(struct file *file, void *priv, struct v4l2_buffer *p)
-{
-	struct vivi_dev *dev = video_drvdata(file);
-	return vb2_querybuf(&dev->vb_vidq, p);
-}
-
-static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *p)
-{
-	struct vivi_dev *dev = video_drvdata(file);
-	return vb2_qbuf(&dev->vb_vidq, p);
-}
-
-static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
-{
-	struct vivi_dev *dev = video_drvdata(file);
-	return vb2_dqbuf(&dev->vb_vidq, p, file->f_flags & O_NONBLOCK);
-}
-
-static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
-{
-	struct vivi_dev *dev = video_drvdata(file);
-	return vb2_streamon(&dev->vb_vidq, i);
-}
-
-static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
-{
-	struct vivi_dev *dev = video_drvdata(file);
-	return vb2_streamoff(&dev->vb_vidq, i);
-}
-
 /* only one input in this sample driver */
 static int vidioc_enum_input(struct file *file, void *priv,
 				struct v4l2_input *inp)
@@ -1137,58 +1068,6 @@ static int vivi_s_ctrl(struct v4l2_ctrl *ctrl)
 	File operations for the device
    ------------------------------------------------------------------*/
 
-static ssize_t
-vivi_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
-{
-	struct vivi_dev *dev = video_drvdata(file);
-	int err;
-
-	dprintk(dev, 1, "read called\n");
-	mutex_lock(&dev->mutex);
-	err = vb2_read(&dev->vb_vidq, data, count, ppos,
-		       file->f_flags & O_NONBLOCK);
-	mutex_unlock(&dev->mutex);
-	return err;
-}
-
-static unsigned int
-vivi_poll(struct file *file, struct poll_table_struct *wait)
-{
-	struct vivi_dev *dev = video_drvdata(file);
-	struct vb2_queue *q = &dev->vb_vidq;
-
-	dprintk(dev, 1, "%s\n", __func__);
-	return vb2_poll(q, file, wait);
-}
-
-static int vivi_close(struct file *file)
-{
-	struct video_device  *vdev = video_devdata(file);
-	struct vivi_dev *dev = video_drvdata(file);
-
-	dprintk(dev, 1, "close called (dev=%s), file %p\n",
-		video_device_node_name(vdev), file);
-
-	if (v4l2_fh_is_singular_file(file))
-		vb2_queue_release(&dev->vb_vidq);
-	return v4l2_fh_release(file);
-}
-
-static int vivi_mmap(struct file *file, struct vm_area_struct *vma)
-{
-	struct vivi_dev *dev = video_drvdata(file);
-	int ret;
-
-	dprintk(dev, 1, "mmap called, vma=0x%08lx\n", (unsigned long)vma);
-
-	ret = vb2_mmap(&dev->vb_vidq, vma);
-	dprintk(dev, 1, "vma start=0x%08lx, size=%ld, ret=%d\n",
-		(unsigned long)vma->vm_start,
-		(unsigned long)vma->vm_end - (unsigned long)vma->vm_start,
-		ret);
-	return ret;
-}
-
 static const struct v4l2_ctrl_ops vivi_ctrl_ops = {
 	.g_volatile_ctrl = vivi_g_volatile_ctrl,
 	.s_ctrl = vivi_s_ctrl,
@@ -1293,11 +1172,11 @@ static const struct v4l2_ctrl_config vivi_ctrl_int_menu = {
 static const struct v4l2_file_operations vivi_fops = {
 	.owner		= THIS_MODULE,
 	.open           = v4l2_fh_open,
-	.release        = vivi_close,
-	.read           = vivi_read,
-	.poll		= vivi_poll,
+	.release        = vb2_fop_release,
+	.read           = vb2_fop_read,
+	.poll		= vb2_fop_poll,
 	.unlocked_ioctl = video_ioctl2, /* V4L2 ioctl handler */
-	.mmap           = vivi_mmap,
+	.mmap           = vb2_fop_mmap,
 };
 
 static const struct v4l2_ioctl_ops vivi_ioctl_ops = {
@@ -1306,15 +1185,17 @@ static const struct v4l2_ioctl_ops vivi_ioctl_ops = {
 	.vidioc_g_fmt_vid_cap     = vidioc_g_fmt_vid_cap,
 	.vidioc_try_fmt_vid_cap   = vidioc_try_fmt_vid_cap,
 	.vidioc_s_fmt_vid_cap     = vidioc_s_fmt_vid_cap,
-	.vidioc_reqbufs       = vidioc_reqbufs,
-	.vidioc_querybuf      = vidioc_querybuf,
-	.vidioc_qbuf          = vidioc_qbuf,
-	.vidioc_dqbuf         = vidioc_dqbuf,
+	.vidioc_reqbufs       = vb2_ioctl_reqbufs,
+	.vidioc_create_bufs   = vb2_ioctl_create_bufs,
+	.vidioc_prepare_buf   = vb2_ioctl_prepare_buf,
+	.vidioc_querybuf      = vb2_ioctl_querybuf,
+	.vidioc_qbuf          = vb2_ioctl_qbuf,
+	.vidioc_dqbuf         = vb2_ioctl_dqbuf,
 	.vidioc_enum_input    = vidioc_enum_input,
 	.vidioc_g_input       = vidioc_g_input,
 	.vidioc_s_input       = vidioc_s_input,
-	.vidioc_streamon      = vidioc_streamon,
-	.vidioc_streamoff     = vidioc_streamoff,
+	.vidioc_streamon      = vb2_ioctl_streamon,
+	.vidioc_streamoff     = vb2_ioctl_streamoff,
 	.vidioc_log_status    = v4l2_ctrl_log_status,
 	.vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
 	.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
@@ -1432,6 +1313,7 @@ static int __init vivi_create_instance(int inst)
 	*vfd = vivi_template;
 	vfd->debug = debug;
 	vfd->v4l2_dev = &dev->v4l2_dev;
+	vfd->queue = q;
 	set_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
 
 	/*
-- 
1.7.10


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

* [RFCv1 PATCH 29/32] v4l2-dev.c: also add debug support for the fops.
  2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
                     ` (26 preceding siblings ...)
  2012-06-10 10:25   ` [RFCv1 PATCH 28/32] vivi: use vb2 helper functions Hans Verkuil
@ 2012-06-10 10:25   ` Hans Verkuil
  2012-06-18 10:01     ` Laurent Pinchart
  2012-06-10 10:25   ` [RFCv1 PATCH 30/32] v4l2-ioctl.c: shorten the lines of the table Hans Verkuil
                     ` (2 subsequent siblings)
  30 siblings, 1 reply; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 10:25 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/video/v4l2-dev.c |   41 ++++++++++++++++++++++++++++------------
 1 file changed, 29 insertions(+), 12 deletions(-)

diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c
index 5c0bb18..54f387d 100644
--- a/drivers/media/video/v4l2-dev.c
+++ b/drivers/media/video/v4l2-dev.c
@@ -305,6 +305,9 @@ static ssize_t v4l2_read(struct file *filp, char __user *buf,
 		ret = vdev->fops->read(filp, buf, sz, off);
 	if (test_bit(V4L2_FL_LOCK_ALL_FOPS, &vdev->flags))
 		mutex_unlock(vdev->lock);
+	if (vdev->debug)
+		pr_info("%s: read: %zd (%d)\n",
+			video_device_node_name(vdev), sz, ret);
 	return ret;
 }
 
@@ -323,6 +326,9 @@ static ssize_t v4l2_write(struct file *filp, const char __user *buf,
 		ret = vdev->fops->write(filp, buf, sz, off);
 	if (test_bit(V4L2_FL_LOCK_ALL_FOPS, &vdev->flags))
 		mutex_unlock(vdev->lock);
+	if (vdev->debug)
+		pr_info("%s: write: %zd (%d)\n",
+			video_device_node_name(vdev), sz, ret);
 	return ret;
 }
 
@@ -339,6 +345,9 @@ static unsigned int v4l2_poll(struct file *filp, struct poll_table_struct *poll)
 		ret = vdev->fops->poll(filp, poll);
 	if (test_bit(V4L2_FL_LOCK_ALL_FOPS, &vdev->flags))
 		mutex_unlock(vdev->lock);
+	if (vdev->debug)
+		pr_info("%s: poll: %08x\n",
+			video_device_node_name(vdev), ret);
 	return ret;
 }
 
@@ -348,20 +357,14 @@ static long v4l2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 	int ret = -ENODEV;
 
 	if (vdev->fops->unlocked_ioctl) {
-		bool locked = false;
+		struct mutex *lock = v4l2_ioctl_get_lock(vdev, cmd);
 
-		if (vdev->lock) {
-			/* always lock unless the cmd is marked as "don't use lock" */
-			locked = !v4l2_is_known_ioctl(cmd) ||
-				 !test_bit(_IOC_NR(cmd), vdev->disable_locking);
-
-			if (locked && mutex_lock_interruptible(vdev->lock))
-				return -ERESTARTSYS;
-		}
+		if (lock && mutex_lock_interruptible(lock))
+			return -ERESTARTSYS;
 		if (video_is_registered(vdev))
 			ret = vdev->fops->unlocked_ioctl(filp, cmd, arg);
-		if (locked)
-			mutex_unlock(vdev->lock);
+		if (lock)
+			mutex_unlock(lock);
 	} else if (vdev->fops->ioctl) {
 		/* This code path is a replacement for the BKL. It is a major
 		 * hack but it will have to do for those drivers that are not
@@ -409,12 +412,17 @@ static unsigned long v4l2_get_unmapped_area(struct file *filp,
 		unsigned long flags)
 {
 	struct video_device *vdev = video_devdata(filp);
+	int ret;
 
 	if (!vdev->fops->get_unmapped_area)
 		return -ENOSYS;
 	if (!video_is_registered(vdev))
 		return -ENODEV;
-	return vdev->fops->get_unmapped_area(filp, addr, len, pgoff, flags);
+	ret = vdev->fops->get_unmapped_area(filp, addr, len, pgoff, flags);
+	if (vdev->debug)
+		pr_info("%s: get_unmapped_area (%d)\n",
+			video_device_node_name(vdev), ret);
+	return ret;
 }
 #endif
 
@@ -432,6 +440,9 @@ static int v4l2_mmap(struct file *filp, struct vm_area_struct *vm)
 		ret = vdev->fops->mmap(filp, vm);
 	if (test_bit(V4L2_FL_LOCK_ALL_FOPS, &vdev->flags))
 		mutex_unlock(vdev->lock);
+	if (vdev->debug)
+		pr_info("%s: mmap (%d)\n",
+			video_device_node_name(vdev), ret);
 	return ret;
 }
 
@@ -470,6 +481,9 @@ err:
 	/* decrease the refcount in case of an error */
 	if (ret)
 		video_put(vdev);
+	if (vdev->debug)
+		pr_info("%s: open (%d)\n",
+			video_device_node_name(vdev), ret);
 	return ret;
 }
 
@@ -489,6 +503,9 @@ static int v4l2_release(struct inode *inode, struct file *filp)
 	/* decrease the refcount unconditionally since the release()
 	   return value is ignored. */
 	video_put(vdev);
+	if (vdev->debug)
+		pr_info("%s: release\n",
+			video_device_node_name(vdev));
 	return ret;
 }
 
-- 
1.7.10


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

* [RFCv1 PATCH 30/32] v4l2-ioctl.c: shorten the lines of the table.
  2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
                     ` (27 preceding siblings ...)
  2012-06-10 10:25   ` [RFCv1 PATCH 29/32] v4l2-dev.c: also add debug support for the fops Hans Verkuil
@ 2012-06-10 10:25   ` Hans Verkuil
  2012-06-18  9:57     ` Laurent Pinchart
  2012-06-10 10:25   ` [RFCv1 PATCH 31/32] pwc: use the new vb2 helpers Hans Verkuil
  2012-06-10 10:25   ` [RFCv1 PATCH 32/32] pwc: v4l2-compliance fixes Hans Verkuil
  30 siblings, 1 reply; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 10:25 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

Use some macro magic to reduce the length of the lines in the table. This
makes it more readable.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/video/v4l2-ioctl.c |  189 +++++++++++++++++++-------------------
 1 file changed, 96 insertions(+), 93 deletions(-)

diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
index dfd5337..c40ce1e 100644
--- a/drivers/media/video/v4l2-ioctl.c
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -1839,106 +1839,109 @@ struct v4l2_ioctl_info {
 	  sizeof(((struct v4l2_struct *)0)->field)) << 16)
 #define INFO_FL_CLEAR_MASK (_IOC_SIZEMASK << 16)
 
-#define IOCTL_INFO_STD(_ioctl, _vidioc, _debug, _flags)			\
-	[_IOC_NR(_ioctl)] = {						\
-		.ioctl = _ioctl,					\
+/* Standard calling sequence: use the offset of the op in v4l2_ioctl_ops */
+#define STD(_ioctl, _vidioc, _debug, _flags)				\
+	[_IOC_NR(VIDIOC_ ## _ioctl)] = {				\
+		.ioctl = VIDIOC_ ## _ioctl,				\
 		.flags = _flags | INFO_FL_STD,				\
-		.name = #_ioctl,					\
-		.offset = offsetof(struct v4l2_ioctl_ops, _vidioc),	\
-		.debug = _debug,					\
+		.name = "VIDIOC_" #_ioctl,				\
+		.offset = offsetof(struct v4l2_ioctl_ops, vidioc_ ## _vidioc),	\
+		.debug = v4l_print_ ## _debug,				\
 	}
 
-#define IOCTL_INFO_FNC(_ioctl, _func, _debug, _flags)			\
-	[_IOC_NR(_ioctl)] = {						\
-		.ioctl = _ioctl,					\
+/* Call a function instead of the op for ioctls where the core needs to do
+   something extra. */
+#define FNC(_ioctl, _func, _debug, _flags)				\
+	[_IOC_NR(VIDIOC_ ## _ioctl)] = {				\
+		.ioctl = VIDIOC_ ## _ioctl,				\
 		.flags = _flags | INFO_FL_FUNC,				\
-		.name = #_ioctl,					\
-		.func = _func,						\
-		.debug = _debug,					\
+		.name = "VIDIOC_" #_ioctl,				\
+		.func = v4l_ ## _func,					\
+		.debug = v4l_print_ ## _debug,				\
 	}
 
 static struct v4l2_ioctl_info v4l2_ioctls[] = {
-	IOCTL_INFO_FNC(VIDIOC_QUERYCAP, v4l_querycap, v4l_print_querycap, 0),
-	IOCTL_INFO_FNC(VIDIOC_ENUM_FMT, v4l_enum_fmt, v4l_print_fmtdesc, INFO_FL_CLEAR(v4l2_fmtdesc, type)),
-	IOCTL_INFO_FNC(VIDIOC_G_FMT, v4l_g_fmt, v4l_print_format, INFO_FL_CLEAR(v4l2_format, type)),
-	IOCTL_INFO_FNC(VIDIOC_S_FMT, v4l_s_fmt, v4l_print_format, INFO_FL_PRIO),
-	IOCTL_INFO_FNC(VIDIOC_REQBUFS, v4l_reqbufs, v4l_print_requestbuffers, INFO_FL_PRIO | INFO_FL_QUEUE),
-	IOCTL_INFO_FNC(VIDIOC_QUERYBUF, v4l_querybuf, v4l_print_buffer, INFO_FL_QUEUE | INFO_FL_CLEAR(v4l2_buffer, length)),
-	IOCTL_INFO_STD(VIDIOC_G_FBUF, vidioc_g_fbuf, v4l_print_framebuffer, 0),
-	IOCTL_INFO_STD(VIDIOC_S_FBUF, vidioc_s_fbuf, v4l_print_framebuffer, INFO_FL_PRIO),
-	IOCTL_INFO_STD(VIDIOC_OVERLAY, vidioc_overlay, v4l_print_u32, INFO_FL_PRIO),
-	IOCTL_INFO_FNC(VIDIOC_QBUF, v4l_qbuf, v4l_print_buffer, INFO_FL_QUEUE),
-	IOCTL_INFO_FNC(VIDIOC_DQBUF, v4l_dqbuf, v4l_print_buffer, INFO_FL_QUEUE),
-	IOCTL_INFO_FNC(VIDIOC_STREAMON, v4l_streamon, v4l_print_buftype, INFO_FL_PRIO | INFO_FL_QUEUE),
-	IOCTL_INFO_FNC(VIDIOC_STREAMOFF, v4l_streamoff, v4l_print_buftype, INFO_FL_PRIO | INFO_FL_QUEUE),
-	IOCTL_INFO_FNC(VIDIOC_G_PARM, v4l_g_parm, v4l_print_streamparm, INFO_FL_CLEAR(v4l2_streamparm, type)),
-	IOCTL_INFO_FNC(VIDIOC_S_PARM, v4l_s_parm, v4l_print_streamparm, INFO_FL_PRIO),
-	IOCTL_INFO_FNC(VIDIOC_G_STD, v4l_g_std, v4l_print_std, 0),
-	IOCTL_INFO_FNC(VIDIOC_S_STD, v4l_s_std, v4l_print_std, INFO_FL_PRIO),
-	IOCTL_INFO_FNC(VIDIOC_ENUMSTD, v4l_enumstd, v4l_print_standard, INFO_FL_CLEAR(v4l2_standard, index)),
-	IOCTL_INFO_FNC(VIDIOC_ENUMINPUT, v4l_enuminput, v4l_print_enuminput, INFO_FL_CLEAR(v4l2_input, index)),
-	IOCTL_INFO_FNC(VIDIOC_G_CTRL, v4l_g_ctrl, v4l_print_control, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_control, id)),
-	IOCTL_INFO_FNC(VIDIOC_S_CTRL, v4l_s_ctrl, v4l_print_control, INFO_FL_PRIO | INFO_FL_CTRL),
-	IOCTL_INFO_FNC(VIDIOC_G_TUNER, v4l_g_tuner, v4l_print_g_tuner, INFO_FL_CLEAR(v4l2_tuner, index)),
-	IOCTL_INFO_FNC(VIDIOC_S_TUNER, v4l_s_tuner, v4l_print_s_tuner, INFO_FL_PRIO),
-	IOCTL_INFO_STD(VIDIOC_G_AUDIO, vidioc_g_audio, v4l_print_audio, 0),
-	IOCTL_INFO_STD(VIDIOC_S_AUDIO, vidioc_s_audio, v4l_print_s_audio, INFO_FL_PRIO),
-	IOCTL_INFO_FNC(VIDIOC_QUERYCTRL, v4l_queryctrl, v4l_print_queryctrl, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_queryctrl, id)),
-	IOCTL_INFO_FNC(VIDIOC_QUERYMENU, v4l_querymenu, v4l_print_querymenu, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_querymenu, index)),
-	IOCTL_INFO_STD(VIDIOC_G_INPUT, vidioc_g_input, v4l_print_u32, 0),
-	IOCTL_INFO_FNC(VIDIOC_S_INPUT, v4l_s_input, v4l_print_u32, INFO_FL_PRIO),
-	IOCTL_INFO_STD(VIDIOC_G_OUTPUT, vidioc_g_output, v4l_print_u32, 0),
-	IOCTL_INFO_FNC(VIDIOC_S_OUTPUT, v4l_s_output, v4l_print_u32, INFO_FL_PRIO),
-	IOCTL_INFO_FNC(VIDIOC_ENUMOUTPUT, v4l_enumoutput, v4l_print_enumoutput, INFO_FL_CLEAR(v4l2_output, index)),
-	IOCTL_INFO_STD(VIDIOC_G_AUDOUT, vidioc_g_audout, v4l_print_audioout, 0),
-	IOCTL_INFO_STD(VIDIOC_S_AUDOUT, vidioc_s_audout, v4l_print_s_audioout, INFO_FL_PRIO),
-	IOCTL_INFO_STD(VIDIOC_G_MODULATOR, vidioc_g_modulator, v4l_print_g_modulator, INFO_FL_CLEAR(v4l2_modulator, index)),
-	IOCTL_INFO_STD(VIDIOC_S_MODULATOR, vidioc_s_modulator, v4l_print_s_modulator, INFO_FL_PRIO),
-	IOCTL_INFO_FNC(VIDIOC_G_FREQUENCY, v4l_g_frequency, v4l_print_frequency, INFO_FL_CLEAR(v4l2_frequency, tuner)),
-	IOCTL_INFO_FNC(VIDIOC_S_FREQUENCY, v4l_s_frequency, v4l_print_frequency, INFO_FL_PRIO),
-	IOCTL_INFO_FNC(VIDIOC_CROPCAP, v4l_cropcap, v4l_print_cropcap, INFO_FL_CLEAR(v4l2_cropcap, type)),
-	IOCTL_INFO_FNC(VIDIOC_G_CROP, v4l_g_crop, v4l_print_crop, INFO_FL_CLEAR(v4l2_crop, type)),
-	IOCTL_INFO_FNC(VIDIOC_S_CROP, v4l_s_crop, v4l_print_crop, INFO_FL_PRIO),
-	IOCTL_INFO_STD(VIDIOC_G_SELECTION, vidioc_g_selection, v4l_print_selection, 0),
-	IOCTL_INFO_STD(VIDIOC_S_SELECTION, vidioc_s_selection, v4l_print_selection, INFO_FL_PRIO),
-	IOCTL_INFO_STD(VIDIOC_G_JPEGCOMP, vidioc_g_jpegcomp, v4l_print_jpegcompression, 0),
-	IOCTL_INFO_STD(VIDIOC_S_JPEGCOMP, vidioc_s_jpegcomp, v4l_print_jpegcompression, INFO_FL_PRIO),
-	IOCTL_INFO_FNC(VIDIOC_QUERYSTD, v4l_querystd, v4l_print_std, 0),
-	IOCTL_INFO_FNC(VIDIOC_TRY_FMT, v4l_try_fmt, v4l_print_format, 0),
-	IOCTL_INFO_STD(VIDIOC_ENUMAUDIO, vidioc_enumaudio, v4l_print_audio, INFO_FL_CLEAR(v4l2_audio, index)),
-	IOCTL_INFO_STD(VIDIOC_ENUMAUDOUT, vidioc_enumaudout, v4l_print_audioout, INFO_FL_CLEAR(v4l2_audioout, index)),
-	IOCTL_INFO_FNC(VIDIOC_G_PRIORITY, v4l_g_priority, v4l_print_u32, 0),
-	IOCTL_INFO_FNC(VIDIOC_S_PRIORITY, v4l_s_priority, v4l_print_u32, INFO_FL_PRIO),
-	IOCTL_INFO_FNC(VIDIOC_G_SLICED_VBI_CAP, v4l_g_sliced_vbi_cap, v4l_print_sliced_vbi_cap, INFO_FL_CLEAR(v4l2_sliced_vbi_cap, type)),
-	IOCTL_INFO_FNC(VIDIOC_LOG_STATUS, v4l_log_status, v4l_print_newline, 0),
-	IOCTL_INFO_FNC(VIDIOC_G_EXT_CTRLS, v4l_g_ext_ctrls, v4l_print_ext_controls, INFO_FL_CTRL),
-	IOCTL_INFO_FNC(VIDIOC_S_EXT_CTRLS, v4l_s_ext_ctrls, v4l_print_ext_controls, INFO_FL_PRIO | INFO_FL_CTRL),
-	IOCTL_INFO_FNC(VIDIOC_TRY_EXT_CTRLS, v4l_try_ext_ctrls, v4l_print_ext_controls, 0),
-	IOCTL_INFO_STD(VIDIOC_ENUM_FRAMESIZES, vidioc_enum_framesizes, v4l_print_frmsizeenum, INFO_FL_CLEAR(v4l2_frmsizeenum, pixel_format)),
-	IOCTL_INFO_STD(VIDIOC_ENUM_FRAMEINTERVALS, vidioc_enum_frameintervals, v4l_print_frmivalenum, INFO_FL_CLEAR(v4l2_frmivalenum, height)),
-	IOCTL_INFO_STD(VIDIOC_G_ENC_INDEX, vidioc_g_enc_index, v4l_print_enc_idx, 0),
-	IOCTL_INFO_STD(VIDIOC_ENCODER_CMD, vidioc_encoder_cmd, v4l_print_encoder_cmd, INFO_FL_PRIO | INFO_FL_CLEAR(v4l2_encoder_cmd, flags)),
-	IOCTL_INFO_STD(VIDIOC_TRY_ENCODER_CMD, vidioc_try_encoder_cmd, v4l_print_encoder_cmd, INFO_FL_CLEAR(v4l2_encoder_cmd, flags)),
-	IOCTL_INFO_STD(VIDIOC_DECODER_CMD, vidioc_decoder_cmd, v4l_print_decoder_cmd, INFO_FL_PRIO),
-	IOCTL_INFO_STD(VIDIOC_TRY_DECODER_CMD, vidioc_try_decoder_cmd, v4l_print_decoder_cmd, 0),
-	IOCTL_INFO_FNC(VIDIOC_DBG_S_REGISTER, v4l_dbg_s_register, v4l_print_dbg_register, 0),
-	IOCTL_INFO_FNC(VIDIOC_DBG_G_REGISTER, v4l_dbg_g_register, v4l_print_dbg_register, 0),
-	IOCTL_INFO_FNC(VIDIOC_DBG_G_CHIP_IDENT, v4l_dbg_g_chip_ident, v4l_print_dbg_chip_ident, 0),
-	IOCTL_INFO_FNC(VIDIOC_S_HW_FREQ_SEEK, v4l_s_hw_freq_seek, v4l_print_hw_freq_seek, INFO_FL_PRIO),
-	IOCTL_INFO_STD(VIDIOC_ENUM_DV_PRESETS, vidioc_enum_dv_presets, v4l_print_dv_enum_presets, 0),
-	IOCTL_INFO_STD(VIDIOC_S_DV_PRESET, vidioc_s_dv_preset, v4l_print_dv_preset, INFO_FL_PRIO),
-	IOCTL_INFO_STD(VIDIOC_G_DV_PRESET, vidioc_g_dv_preset, v4l_print_dv_preset, 0),
-	IOCTL_INFO_STD(VIDIOC_QUERY_DV_PRESET, vidioc_query_dv_preset, v4l_print_dv_preset, 0),
-	IOCTL_INFO_STD(VIDIOC_S_DV_TIMINGS, vidioc_s_dv_timings, v4l_print_dv_timings, INFO_FL_PRIO),
-	IOCTL_INFO_STD(VIDIOC_G_DV_TIMINGS, vidioc_g_dv_timings, v4l_print_dv_timings, 0),
-	IOCTL_INFO_FNC(VIDIOC_DQEVENT, v4l_dqevent, v4l_print_event, 0),
-	IOCTL_INFO_FNC(VIDIOC_SUBSCRIBE_EVENT, v4l_subscribe_event, v4l_print_event_subscription, 0),
-	IOCTL_INFO_FNC(VIDIOC_UNSUBSCRIBE_EVENT, v4l_unsubscribe_event, v4l_print_event_subscription, 0),
-	IOCTL_INFO_FNC(VIDIOC_CREATE_BUFS, v4l_create_bufs, v4l_print_create_buffers, INFO_FL_PRIO | INFO_FL_QUEUE),
-	IOCTL_INFO_FNC(VIDIOC_PREPARE_BUF, v4l_prepare_buf, v4l_print_buffer, INFO_FL_QUEUE),
-	IOCTL_INFO_STD(VIDIOC_ENUM_DV_TIMINGS, vidioc_enum_dv_timings, v4l_print_enum_dv_timings, 0),
-	IOCTL_INFO_STD(VIDIOC_QUERY_DV_TIMINGS, vidioc_query_dv_timings, v4l_print_dv_timings, 0),
-	IOCTL_INFO_STD(VIDIOC_DV_TIMINGS_CAP, vidioc_dv_timings_cap, v4l_print_dv_timings_cap, 0),
+	FNC(QUERYCAP, querycap, querycap, 0),
+	FNC(ENUM_FMT, enum_fmt, fmtdesc, INFO_FL_CLEAR(v4l2_fmtdesc, type)),
+	FNC(G_FMT, g_fmt, format, INFO_FL_CLEAR(v4l2_format, type)),
+	FNC(S_FMT, s_fmt, format, INFO_FL_PRIO),
+	FNC(REQBUFS, reqbufs, requestbuffers, INFO_FL_PRIO | INFO_FL_QUEUE),
+	FNC(QUERYBUF, querybuf, buffer, INFO_FL_QUEUE | INFO_FL_CLEAR(v4l2_buffer, length)),
+	STD(G_FBUF, g_fbuf, framebuffer, 0),
+	STD(S_FBUF, s_fbuf, framebuffer, INFO_FL_PRIO),
+	STD(OVERLAY, overlay, u32, INFO_FL_PRIO),
+	FNC(QBUF, qbuf, buffer, INFO_FL_QUEUE),
+	FNC(DQBUF, dqbuf, buffer, INFO_FL_QUEUE),
+	FNC(STREAMON, streamon, buftype, INFO_FL_PRIO | INFO_FL_QUEUE),
+	FNC(STREAMOFF, streamoff, buftype, INFO_FL_PRIO | INFO_FL_QUEUE),
+	FNC(G_PARM, g_parm, streamparm, INFO_FL_CLEAR(v4l2_streamparm, type)),
+	FNC(S_PARM, s_parm, streamparm, INFO_FL_PRIO),
+	FNC(G_STD, g_std, std, 0),
+	FNC(S_STD, s_std, std, INFO_FL_PRIO),
+	FNC(ENUMSTD, enumstd, standard, INFO_FL_CLEAR(v4l2_standard, index)),
+	FNC(ENUMINPUT, enuminput, enuminput, INFO_FL_CLEAR(v4l2_input, index)),
+	FNC(G_CTRL, g_ctrl, control, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_control, id)),
+	FNC(S_CTRL, s_ctrl, control, INFO_FL_PRIO | INFO_FL_CTRL),
+	FNC(G_TUNER, g_tuner, g_tuner, INFO_FL_CLEAR(v4l2_tuner, index)),
+	FNC(S_TUNER, s_tuner, s_tuner, INFO_FL_PRIO),
+	STD(G_AUDIO, g_audio, audio, 0),
+	STD(S_AUDIO, s_audio, s_audio, INFO_FL_PRIO),
+	FNC(QUERYCTRL, queryctrl, queryctrl, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_queryctrl, id)),
+	FNC(QUERYMENU, querymenu, querymenu, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_querymenu, index)),
+	STD(G_INPUT, g_input, u32, 0),
+	FNC(S_INPUT, s_input, u32, INFO_FL_PRIO),
+	STD(G_OUTPUT, g_output, u32, 0),
+	FNC(S_OUTPUT, s_output, u32, INFO_FL_PRIO),
+	FNC(ENUMOUTPUT, enumoutput, enumoutput, INFO_FL_CLEAR(v4l2_output, index)),
+	STD(G_AUDOUT, g_audout, audioout, 0),
+	STD(S_AUDOUT, s_audout, s_audioout, INFO_FL_PRIO),
+	STD(G_MODULATOR, g_modulator, g_modulator, INFO_FL_CLEAR(v4l2_modulator, index)),
+	STD(S_MODULATOR, s_modulator, s_modulator, INFO_FL_PRIO),
+	FNC(G_FREQUENCY, g_frequency, frequency, INFO_FL_CLEAR(v4l2_frequency, tuner)),
+	FNC(S_FREQUENCY, s_frequency, frequency, INFO_FL_PRIO),
+	FNC(CROPCAP, cropcap, cropcap, INFO_FL_CLEAR(v4l2_cropcap, type)),
+	FNC(G_CROP, g_crop, crop, INFO_FL_CLEAR(v4l2_crop, type)),
+	FNC(S_CROP, s_crop, crop, INFO_FL_PRIO),
+	STD(G_SELECTION, g_selection, selection, 0),
+	STD(S_SELECTION, s_selection, selection, INFO_FL_PRIO),
+	STD(G_JPEGCOMP, g_jpegcomp, jpegcompression, 0),
+	STD(S_JPEGCOMP, s_jpegcomp, jpegcompression, INFO_FL_PRIO),
+	FNC(QUERYSTD, querystd, std, 0),
+	FNC(TRY_FMT, try_fmt, format, 0),
+	STD(ENUMAUDIO, enumaudio, audio, INFO_FL_CLEAR(v4l2_audio, index)),
+	STD(ENUMAUDOUT, enumaudout, audioout, INFO_FL_CLEAR(v4l2_audioout, index)),
+	FNC(G_PRIORITY, g_priority, u32, 0),
+	FNC(S_PRIORITY, s_priority, u32, INFO_FL_PRIO),
+	FNC(G_SLICED_VBI_CAP, g_sliced_vbi_cap, sliced_vbi_cap, INFO_FL_CLEAR(v4l2_sliced_vbi_cap, type)),
+	FNC(LOG_STATUS, log_status, newline, 0),
+	FNC(G_EXT_CTRLS, g_ext_ctrls, ext_controls, INFO_FL_CTRL),
+	FNC(S_EXT_CTRLS, s_ext_ctrls, ext_controls, INFO_FL_PRIO | INFO_FL_CTRL),
+	FNC(TRY_EXT_CTRLS, try_ext_ctrls, ext_controls, 0),
+	STD(ENUM_FRAMESIZES, enum_framesizes, frmsizeenum, INFO_FL_CLEAR(v4l2_frmsizeenum, pixel_format)),
+	STD(ENUM_FRAMEINTERVALS, enum_frameintervals, frmivalenum, INFO_FL_CLEAR(v4l2_frmivalenum, height)),
+	STD(G_ENC_INDEX, g_enc_index, enc_idx, 0),
+	STD(ENCODER_CMD, encoder_cmd, encoder_cmd, INFO_FL_PRIO | INFO_FL_CLEAR(v4l2_encoder_cmd, flags)),
+	STD(TRY_ENCODER_CMD, try_encoder_cmd, encoder_cmd, INFO_FL_CLEAR(v4l2_encoder_cmd, flags)),
+	STD(DECODER_CMD, decoder_cmd, decoder_cmd, INFO_FL_PRIO),
+	STD(TRY_DECODER_CMD, try_decoder_cmd, decoder_cmd, 0),
+	FNC(DBG_S_REGISTER, dbg_s_register, dbg_register, 0),
+	FNC(DBG_G_REGISTER, dbg_g_register, dbg_register, 0),
+	FNC(DBG_G_CHIP_IDENT, dbg_g_chip_ident, dbg_chip_ident, 0),
+	FNC(S_HW_FREQ_SEEK, s_hw_freq_seek, hw_freq_seek, INFO_FL_PRIO),
+	STD(ENUM_DV_PRESETS, enum_dv_presets, dv_enum_presets, 0),
+	STD(S_DV_PRESET, s_dv_preset, dv_preset, INFO_FL_PRIO),
+	STD(G_DV_PRESET, g_dv_preset, dv_preset, 0),
+	STD(QUERY_DV_PRESET, query_dv_preset, dv_preset, 0),
+	STD(S_DV_TIMINGS, s_dv_timings, dv_timings, INFO_FL_PRIO),
+	STD(G_DV_TIMINGS, g_dv_timings, dv_timings, 0),
+	FNC(DQEVENT, dqevent, event, 0),
+	FNC(SUBSCRIBE_EVENT, subscribe_event, event_subscription, 0),
+	FNC(UNSUBSCRIBE_EVENT, unsubscribe_event, event_subscription, 0),
+	FNC(CREATE_BUFS, create_bufs, create_buffers, INFO_FL_PRIO | INFO_FL_QUEUE),
+	FNC(PREPARE_BUF, prepare_buf, buffer, INFO_FL_QUEUE),
+	STD(ENUM_DV_TIMINGS, enum_dv_timings, enum_dv_timings, 0),
+	STD(QUERY_DV_TIMINGS, query_dv_timings, dv_timings, 0),
+	STD(DV_TIMINGS_CAP, dv_timings_cap, dv_timings_cap, 0),
 };
 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
 
-- 
1.7.10


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

* [RFCv1 PATCH 31/32] pwc: use the new vb2 helpers.
  2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
                     ` (28 preceding siblings ...)
  2012-06-10 10:25   ` [RFCv1 PATCH 30/32] v4l2-ioctl.c: shorten the lines of the table Hans Verkuil
@ 2012-06-10 10:25   ` Hans Verkuil
  2012-06-10 10:25   ` [RFCv1 PATCH 32/32] pwc: v4l2-compliance fixes Hans Verkuil
  30 siblings, 0 replies; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 10:25 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/video/pwc/pwc-if.c  |  155 ++++---------------------------------
 drivers/media/video/pwc/pwc-v4l.c |  140 +++------------------------------
 drivers/media/video/pwc/pwc.h     |    3 -
 3 files changed, 24 insertions(+), 274 deletions(-)

diff --git a/drivers/media/video/pwc/pwc-if.c b/drivers/media/video/pwc/pwc-if.c
index ec4e2ef..0ae87ec 100644
--- a/drivers/media/video/pwc/pwc-if.c
+++ b/drivers/media/video/pwc/pwc-if.c
@@ -136,19 +136,13 @@ static int leds[2] = { 100, 0 };
 
 /***/
 
-static int pwc_video_close(struct file *file);
-static ssize_t pwc_video_read(struct file *file, char __user *buf,
-			  size_t count, loff_t *ppos);
-static unsigned int pwc_video_poll(struct file *file, poll_table *wait);
-static int  pwc_video_mmap(struct file *file, struct vm_area_struct *vma);
-
 static const struct v4l2_file_operations pwc_fops = {
 	.owner =	THIS_MODULE,
 	.open =		v4l2_fh_open,
-	.release =     	pwc_video_close,
-	.read =		pwc_video_read,
-	.poll =		pwc_video_poll,
-	.mmap =		pwc_video_mmap,
+	.release =	vb2_fop_release,
+	.read =		vb2_fop_read,
+	.poll =		vb2_fop_poll,
+	.mmap =		vb2_fop_mmap,
 	.unlocked_ioctl = video_ioctl2,
 };
 static struct video_device pwc_template = {
@@ -562,17 +556,6 @@ static const char *pwc_sensor_type_to_string(unsigned int sensor_type)
 /***************************************************************************/
 /* Video4Linux functions */
 
-int pwc_test_n_set_capt_file(struct pwc_device *pdev, struct file *file)
-{
-	if (pdev->capt_file != NULL &&
-	    pdev->capt_file != file)
-		return -EBUSY;
-
-	pdev->capt_file = file;
-
-	return 0;
-}
-
 static void pwc_video_release(struct v4l2_device *v)
 {
 	struct pwc_device *pdev = container_of(v, struct pwc_device, v4l2_dev);
@@ -583,113 +566,6 @@ static void pwc_video_release(struct v4l2_device *v)
 	kfree(pdev);
 }
 
-static int pwc_video_close(struct file *file)
-{
-	struct pwc_device *pdev = video_drvdata(file);
-
-	/*
-	 * If we're still streaming vb2_queue_release will call stream_stop
-	 * so we must take both the v4l2_lock and the vb_queue_lock.
-	 */
-	if (mutex_lock_interruptible(&pdev->v4l2_lock))
-		return -ERESTARTSYS;
-	if (mutex_lock_interruptible(&pdev->vb_queue_lock)) {
-		mutex_unlock(&pdev->v4l2_lock);
-		return -ERESTARTSYS;
-	}
-
-	if (pdev->capt_file == file) {
-		vb2_queue_release(&pdev->vb_queue);
-		pdev->capt_file = NULL;
-	}
-
-	mutex_unlock(&pdev->vb_queue_lock);
-	mutex_unlock(&pdev->v4l2_lock);
-
-	return v4l2_fh_release(file);
-}
-
-static ssize_t pwc_video_read(struct file *file, char __user *buf,
-			      size_t count, loff_t *ppos)
-{
-	struct pwc_device *pdev = video_drvdata(file);
-	int lock_v4l2 = 0;
-	ssize_t ret;
-
-	if (mutex_lock_interruptible(&pdev->vb_queue_lock))
-		return -ERESTARTSYS;
-
-	ret = pwc_test_n_set_capt_file(pdev, file);
-	if (ret)
-		goto out;
-
-	/* stream_start will get called so we must take the v4l2_lock */
-	if (pdev->vb_queue.fileio == NULL)
-		lock_v4l2 = 1;
-
-	/* Use try_lock, since we're taking the locks in the *wrong* order! */
-	if (lock_v4l2 && !mutex_trylock(&pdev->v4l2_lock)) {
-		ret = -ERESTARTSYS;
-		goto out;
-	}
-	ret = vb2_read(&pdev->vb_queue, buf, count, ppos,
-		       file->f_flags & O_NONBLOCK);
-	if (lock_v4l2)
-		mutex_unlock(&pdev->v4l2_lock);
-out:
-	mutex_unlock(&pdev->vb_queue_lock);
-	return ret;
-}
-
-static unsigned int pwc_video_poll(struct file *file, poll_table *wait)
-{
-	struct pwc_device *pdev = video_drvdata(file);
-	struct vb2_queue *q = &pdev->vb_queue;
-	unsigned long req_events = poll_requested_events(wait);
-	unsigned int ret = POLL_ERR;
-	int lock_v4l2 = 0;
-
-	if (mutex_lock_interruptible(&pdev->vb_queue_lock))
-		return POLL_ERR;
-
-	/* Will this start fileio and thus call start_stream? */
-	if ((req_events & (POLLIN | POLLRDNORM)) &&
-	    q->num_buffers == 0 && !q->streaming && q->fileio == NULL) {
-		if (pwc_test_n_set_capt_file(pdev, file))
-			goto out;
-		lock_v4l2 = 1;
-	}
-
-	/* Use try_lock, since we're taking the locks in the *wrong* order! */
-	if (lock_v4l2 && !mutex_trylock(&pdev->v4l2_lock))
-		goto out;
-	ret = vb2_poll(&pdev->vb_queue, file, wait);
-	if (lock_v4l2)
-		mutex_unlock(&pdev->v4l2_lock);
-
-out:
-	if (!pdev->udev)
-		ret |= POLLHUP;
-	mutex_unlock(&pdev->vb_queue_lock);
-	return ret;
-}
-
-static int pwc_video_mmap(struct file *file, struct vm_area_struct *vma)
-{
-	struct pwc_device *pdev = video_drvdata(file);
-	int ret;
-
-	if (mutex_lock_interruptible(&pdev->vb_queue_lock))
-		return -ERESTARTSYS;
-
-	ret = pwc_test_n_set_capt_file(pdev, file);
-	if (ret == 0)
-		ret = vb2_mmap(&pdev->vb_queue, vma);
-
-	mutex_unlock(&pdev->vb_queue_lock);
-	return ret;
-}
-
 /***************************************************************************/
 /* Videobuf2 operations */
 
@@ -782,6 +658,8 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
 	if (!pdev->udev)
 		return -ENODEV;
 
+	if (mutex_lock_interruptible(&pdev->v4l2_lock))
+		return -ERESTARTSYS;
 	/* Turn on camera and set LEDS on */
 	pwc_camera_power(pdev, 1);
 	pwc_set_leds(pdev, leds[0], leds[1]);
@@ -794,6 +672,7 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
 		/* And cleanup any queued bufs!! */
 		pwc_cleanup_queued_bufs(pdev);
 	}
+	mutex_unlock(&pdev->v4l2_lock);
 
 	return r;
 }
@@ -802,6 +681,8 @@ static int stop_streaming(struct vb2_queue *vq)
 {
 	struct pwc_device *pdev = vb2_get_drv_priv(vq);
 
+	if (mutex_lock_interruptible(&pdev->v4l2_lock))
+		return -ERESTARTSYS;
 	if (pdev->udev) {
 		pwc_set_leds(pdev, 0, 0);
 		pwc_camera_power(pdev, 0);
@@ -809,6 +690,7 @@ static int stop_streaming(struct vb2_queue *vq)
 	}
 
 	pwc_cleanup_queued_bufs(pdev);
+	mutex_unlock(&pdev->v4l2_lock);
 
 	return 0;
 }
@@ -1136,6 +1018,8 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id
 	/* Init video_device structure */
 	memcpy(&pdev->vdev, &pwc_template, sizeof(pwc_template));
 	strcpy(pdev->vdev.name, name);
+	pdev->vdev.queue = &pdev->vb_queue;
+	pdev->vdev.queue_lock = &pdev->vb_queue_lock;
 	set_bit(V4L2_FL_USE_FH_PRIO, &pdev->vdev.flags);
 	video_set_drvdata(&pdev->vdev, pdev);
 
@@ -1190,15 +1074,6 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id
 	pdev->vdev.v4l2_dev = &pdev->v4l2_dev;
 	pdev->vdev.lock = &pdev->v4l2_lock;
 
-	/*
-	 * Don't take v4l2_lock for these ioctls. This improves latency if
-	 * v4l2_lock is taken for a long time, e.g. when changing a control
-	 * value, and a new frame is ready to be dequeued.
-	 */
-	v4l2_disable_ioctl_locking(&pdev->vdev, VIDIOC_DQBUF);
-	v4l2_disable_ioctl_locking(&pdev->vdev, VIDIOC_QBUF);
-	v4l2_disable_ioctl_locking(&pdev->vdev, VIDIOC_QUERYBUF);
-
 	rc = video_register_device(&pdev->vdev, VFL_TYPE_GRABBER, -1);
 	if (rc < 0) {
 		PWC_ERROR("Failed to register as video device (%d).\n", rc);
@@ -1253,20 +1128,18 @@ static void usb_pwc_disconnect(struct usb_interface *intf)
 	struct v4l2_device *v = usb_get_intfdata(intf);
 	struct pwc_device *pdev = container_of(v, struct pwc_device, v4l2_dev);
 
-	mutex_lock(&pdev->v4l2_lock);
-
 	mutex_lock(&pdev->vb_queue_lock);
+	mutex_lock(&pdev->v4l2_lock);
 	/* No need to keep the urbs around after disconnection */
 	if (pdev->vb_queue.streaming)
 		pwc_isoc_cleanup(pdev);
 	pdev->udev = NULL;
 	pwc_cleanup_queued_bufs(pdev);
-	mutex_unlock(&pdev->vb_queue_lock);
 
 	v4l2_device_disconnect(&pdev->v4l2_dev);
 	video_unregister_device(&pdev->vdev);
-
 	mutex_unlock(&pdev->v4l2_lock);
+	mutex_unlock(&pdev->vb_queue_lock);
 
 #ifdef CONFIG_USB_PWC_INPUT_EVDEV
 	if (pdev->button_dev)
diff --git a/drivers/media/video/pwc/pwc-v4l.c b/drivers/media/video/pwc/pwc-v4l.c
index c691e29..114ae41 100644
--- a/drivers/media/video/pwc/pwc-v4l.c
+++ b/drivers/media/video/pwc/pwc-v4l.c
@@ -468,17 +468,8 @@ static int pwc_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f)
 	if (ret < 0)
 		return ret;
 
-	if (mutex_lock_interruptible(&pdev->vb_queue_lock))
-		return -ERESTARTSYS;
-
-	ret = pwc_test_n_set_capt_file(pdev, file);
-	if (ret)
-		goto leave;
-
-	if (pdev->vb_queue.streaming) {
-		ret = -EBUSY;
-		goto leave;
-	}
+	if (vb2_is_busy(&pdev->vb_queue))
+		return -EBUSY;
 
 	pixelformat = f->fmt.pix.pixelformat;
 
@@ -496,8 +487,6 @@ static int pwc_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f)
 	PWC_DEBUG_IOCTL("pwc_set_video_mode(), return=%d\n", ret);
 
 	pwc_vidioc_fill_fmt(f, pdev->width, pdev->height, pdev->pixfmt);
-leave:
-	mutex_unlock(&pdev->vb_queue_lock);
 	return ret;
 }
 
@@ -933,104 +922,6 @@ static int pwc_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *
 	return pwc_vidioc_try_fmt(pdev, f);
 }
 
-static int pwc_reqbufs(struct file *file, void *fh,
-		       struct v4l2_requestbuffers *rb)
-{
-	struct pwc_device *pdev = video_drvdata(file);
-	int ret;
-
-	if (mutex_lock_interruptible(&pdev->vb_queue_lock))
-		return -ERESTARTSYS;
-
-	ret = pwc_test_n_set_capt_file(pdev, file);
-	if (ret == 0)
-		ret = vb2_reqbufs(&pdev->vb_queue, rb);
-
-	mutex_unlock(&pdev->vb_queue_lock);
-	return ret;
-}
-
-static int pwc_querybuf(struct file *file, void *fh, struct v4l2_buffer *buf)
-{
-	struct pwc_device *pdev = video_drvdata(file);
-	int ret;
-
-	if (mutex_lock_interruptible(&pdev->vb_queue_lock))
-		return -ERESTARTSYS;
-
-	ret = pwc_test_n_set_capt_file(pdev, file);
-	if (ret == 0)
-		ret = vb2_querybuf(&pdev->vb_queue, buf);
-
-	mutex_unlock(&pdev->vb_queue_lock);
-	return ret;
-}
-
-static int pwc_qbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
-{
-	struct pwc_device *pdev = video_drvdata(file);
-	int ret;
-
-	if (mutex_lock_interruptible(&pdev->vb_queue_lock))
-		return -ERESTARTSYS;
-
-	ret = pwc_test_n_set_capt_file(pdev, file);
-	if (ret == 0)
-		ret = vb2_qbuf(&pdev->vb_queue, buf);
-
-	mutex_unlock(&pdev->vb_queue_lock);
-	return ret;
-}
-
-static int pwc_dqbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
-{
-	struct pwc_device *pdev = video_drvdata(file);
-	int ret;
-
-	if (mutex_lock_interruptible(&pdev->vb_queue_lock))
-		return -ERESTARTSYS;
-
-	ret = pwc_test_n_set_capt_file(pdev, file);
-	if (ret == 0)
-		ret = vb2_dqbuf(&pdev->vb_queue, buf,
-				file->f_flags & O_NONBLOCK);
-
-	mutex_unlock(&pdev->vb_queue_lock);
-	return ret;
-}
-
-static int pwc_streamon(struct file *file, void *fh, enum v4l2_buf_type i)
-{
-	struct pwc_device *pdev = video_drvdata(file);
-	int ret;
-
-	if (mutex_lock_interruptible(&pdev->vb_queue_lock))
-		return -ERESTARTSYS;
-
-	ret = pwc_test_n_set_capt_file(pdev, file);
-	if (ret == 0)
-		ret = vb2_streamon(&pdev->vb_queue, i);
-
-	mutex_unlock(&pdev->vb_queue_lock);
-	return ret;
-}
-
-static int pwc_streamoff(struct file *file, void *fh, enum v4l2_buf_type i)
-{
-	struct pwc_device *pdev = video_drvdata(file);
-	int ret;
-
-	if (mutex_lock_interruptible(&pdev->vb_queue_lock))
-		return -ERESTARTSYS;
-
-	ret = pwc_test_n_set_capt_file(pdev, file);
-	if (ret == 0)
-		ret = vb2_streamoff(&pdev->vb_queue, i);
-
-	mutex_unlock(&pdev->vb_queue_lock);
-	return ret;
-}
-
 static int pwc_enum_framesizes(struct file *file, void *fh,
 					 struct v4l2_frmsizeenum *fsize)
 {
@@ -1119,25 +1010,14 @@ static int pwc_s_parm(struct file *file, void *fh,
 	fps = parm->parm.capture.timeperframe.denominator /
 	      parm->parm.capture.timeperframe.numerator;
 
-	if (mutex_lock_interruptible(&pdev->vb_queue_lock))
-		return -ERESTARTSYS;
-
-	ret = pwc_test_n_set_capt_file(pdev, file);
-	if (ret)
-		goto leave;
-
-	if (pdev->vb_queue.streaming) {
-		ret = -EBUSY;
-		goto leave;
-	}
+	if (vb2_is_busy(&pdev->vb_queue))
+		return -EBUSY;
 
 	ret = pwc_set_video_mode(pdev, pdev->width, pdev->height, pdev->pixfmt,
 				 fps, &compression, 0);
 
 	pwc_g_parm(file, fh, parm);
 
-leave:
-	mutex_unlock(&pdev->vb_queue_lock);
 	return ret;
 }
 
@@ -1150,12 +1030,12 @@ const struct v4l2_ioctl_ops pwc_ioctl_ops = {
 	.vidioc_g_fmt_vid_cap		    = pwc_g_fmt_vid_cap,
 	.vidioc_s_fmt_vid_cap		    = pwc_s_fmt_vid_cap,
 	.vidioc_try_fmt_vid_cap		    = pwc_try_fmt_vid_cap,
-	.vidioc_reqbufs			    = pwc_reqbufs,
-	.vidioc_querybuf		    = pwc_querybuf,
-	.vidioc_qbuf			    = pwc_qbuf,
-	.vidioc_dqbuf			    = pwc_dqbuf,
-	.vidioc_streamon		    = pwc_streamon,
-	.vidioc_streamoff		    = pwc_streamoff,
+	.vidioc_reqbufs			    = vb2_ioctl_reqbufs,
+	.vidioc_querybuf		    = vb2_ioctl_querybuf,
+	.vidioc_qbuf			    = vb2_ioctl_qbuf,
+	.vidioc_dqbuf			    = vb2_ioctl_dqbuf,
+	.vidioc_streamon		    = vb2_ioctl_streamon,
+	.vidioc_streamoff		    = vb2_ioctl_streamoff,
 	.vidioc_log_status		    = v4l2_ctrl_log_status,
 	.vidioc_enum_framesizes		    = pwc_enum_framesizes,
 	.vidioc_enum_frameintervals	    = pwc_enum_frameintervals,
diff --git a/drivers/media/video/pwc/pwc.h b/drivers/media/video/pwc/pwc.h
index d6b5b21..7a6a0d3 100644
--- a/drivers/media/video/pwc/pwc.h
+++ b/drivers/media/video/pwc/pwc.h
@@ -239,7 +239,6 @@ struct pwc_device
 	int features;		/* feature bits */
 
 	/*** Video data ***/
-	struct file *capt_file;	/* file doing video capture */
 	int vendpoint;		/* video isoc endpoint */
 	int vcinterface;	/* video control interface */
 	int valternate;		/* alternate interface needed */
@@ -355,8 +354,6 @@ struct pwc_device
 extern int pwc_trace;
 #endif
 
-int pwc_test_n_set_capt_file(struct pwc_device *pdev, struct file *file);
-
 /** Functions in pwc-misc.c */
 /* sizes in pixels */
 extern const int pwc_image_sizes[PSZ_MAX][2];
-- 
1.7.10


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

* [RFCv1 PATCH 32/32] pwc: v4l2-compliance fixes.
  2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
                     ` (29 preceding siblings ...)
  2012-06-10 10:25   ` [RFCv1 PATCH 31/32] pwc: use the new vb2 helpers Hans Verkuil
@ 2012-06-10 10:25   ` Hans Verkuil
  30 siblings, 0 replies; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 10:25 UTC (permalink / raw)
  To: linux-media
  Cc: Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

From: Hans Verkuil <hans.verkuil@cisco.com>

- add device_caps
- set colorspace
- s_parm should support a fps of 0 (== reset to nominal fps)

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/video/pwc/pwc-v4l.c |   25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/drivers/media/video/pwc/pwc-v4l.c b/drivers/media/video/pwc/pwc-v4l.c
index 114ae41..545e9bb 100644
--- a/drivers/media/video/pwc/pwc-v4l.c
+++ b/drivers/media/video/pwc/pwc-v4l.c
@@ -405,6 +405,7 @@ static void pwc_vidioc_fill_fmt(struct v4l2_format *f,
 	f->fmt.pix.pixelformat  = pixfmt;
 	f->fmt.pix.bytesperline = f->fmt.pix.width;
 	f->fmt.pix.sizeimage	= f->fmt.pix.height * f->fmt.pix.width * 3 / 2;
+	f->fmt.pix.colorspace	= V4L2_COLORSPACE_SRGB;
 	PWC_DEBUG_IOCTL("pwc_vidioc_fill_fmt() "
 			"width=%d, height=%d, bytesperline=%d, sizeimage=%d, pixelformat=%c%c%c%c\n",
 			f->fmt.pix.width,
@@ -497,10 +498,9 @@ static int pwc_querycap(struct file *file, void *fh, struct v4l2_capability *cap
 	strcpy(cap->driver, PWC_NAME);
 	strlcpy(cap->card, pdev->vdev.name, sizeof(cap->card));
 	usb_make_path(pdev->udev, cap->bus_info, sizeof(cap->bus_info));
-	cap->capabilities =
-		V4L2_CAP_VIDEO_CAPTURE	|
-		V4L2_CAP_STREAMING	|
-		V4L2_CAP_READWRITE;
+	cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING |
+					V4L2_CAP_READWRITE;
+	cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
 	return 0;
 }
 
@@ -509,7 +509,8 @@ static int pwc_enum_input(struct file *file, void *fh, struct v4l2_input *i)
 	if (i->index)	/* Only one INPUT is supported */
 		return -EINVAL;
 
-	strcpy(i->name, "usb");
+	strlcpy(i->name, "Camera", sizeof(i->name));
+	i->type = V4L2_INPUT_TYPE_CAMERA;
 	return 0;
 }
 
@@ -1003,12 +1004,18 @@ static int pwc_s_parm(struct file *file, void *fh,
 	int compression = 0;
 	int ret, fps;
 
-	if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
-	    parm->parm.capture.timeperframe.numerator == 0)
+	if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
 		return -EINVAL;
 
-	fps = parm->parm.capture.timeperframe.denominator /
-	      parm->parm.capture.timeperframe.numerator;
+	/* If timeperframe == 0, then reset the framerate to the nominal value.
+	   We pick a high framerate here, and let pwc_set_video_mode() figure
+	   out the best match. */
+	if (parm->parm.capture.timeperframe.numerator == 0 ||
+	    parm->parm.capture.timeperframe.denominator == 0)
+		fps = 30;
+	else
+		fps = parm->parm.capture.timeperframe.denominator /
+		      parm->parm.capture.timeperframe.numerator;
 
 	if (vb2_is_busy(&pdev->vb_queue))
 		return -EBUSY;
-- 
1.7.10


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

* Re: [RFCv1 PATCH 00/32] Core and vb2 enhancements
  2012-06-10 10:25 [RFCv1 PATCH 00/32] Core and vb2 enhancements Hans Verkuil
  2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
@ 2012-06-10 16:46 ` Mauro Carvalho Chehab
  2012-06-10 17:32   ` Hans Verkuil
  1 sibling, 1 reply; 69+ messages in thread
From: Mauro Carvalho Chehab @ 2012-06-10 16:46 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: linux-media, Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski

Em 10-06-2012 07:25, Hans Verkuil escreveu:
> Hi all,
> 
> This large patch series makes a number of changes to the core (ioctl
> handling in particular) and vb2. It all builds on one another, so there
> wasn't much point in splitting it. Most patches are fairly trivial, so it
> is not as bad as it looks :-)
> 
> I will go through the patches one by one:
> 
> - Regression fixes.
> 
> This is a small patch that fixes a number of regressions that are relevant to
> this patch series. These fixes have already been posted to the list.
> 
> - v4l2-ioctl.c: move a block of code down, no other changes.
> 
> Just move code around, no other changes.
> 
> - v4l2-ioctl.c: introduce INFO_FL_CLEAR to replace switch.
> 
> This replaces the switch that determines how much of the struct needs to be
> copied from userspace with a simple table lookup.
> 
> - v4l2-ioctl.c: v4l2-ioctl: add debug and callback/offset functionality.
> 
> Prepare for the next step where the large switch is replaced by table lookups.
> 
> - v4l2-ioctl.c: remove an unnecessary #ifdef.
> 
> A small fix for the table: keep the DBG_G/S_REGISTER ioctl in the table. All
> the right checks are already made, and this way you will actually see the ioctl
> name in the debug messages if you use it.
> 
> - v4l2-ioctl.c: use the new table for querycap and i/o ioctls.
> - v4l2-ioctl.c: use the new table for priority ioctls.
> - v4l2-ioctl.c: use the new table for format/framebuffer ioctls.
> - v4l2-ioctl.c: use the new table for overlay/streamon/off ioctls.
> - v4l2-ioctl.c: use the new table for std/tuner/modulator ioctls.
> - v4l2-ioctl.c: use the new table for queuing/parm ioctls.
> - v4l2-ioctl.c: use the new table for control ioctls.
> - v4l2-ioctl.c: use the new table for selection ioctls.
> - v4l2-ioctl.c: use the new table for compression ioctls.
> - v4l2-ioctl.c: use the new table for debug ioctls.
> - v4l2-ioctl.c: use the new table for preset/timings ioctls.
> - v4l2-ioctl.c: use the new table for the remaining ioctls.
> 
> Here the switch is replaced by table lookups section-by-section.
> 
> - v4l2-ioctl.c: finalize table conversion.
> 
> Remove the last part of the switch.
> 
> - v4l2-dev.c: add debug sysfs entry.
> 
> The video_device debug field is pretty useful, if only you could set it. The
> solution is simple: export it in sysfs. That way you can easily set the debug
> level per device node. Works like a charm.
> 
> - v4l2-ioctl: remove v4l_(i2c_)print_ioctl
> 
> Clean up a few rarely used macros.
> 
> - ivtv: don't mess with vfd->debug.
> - cx18: don't mess with vfd->debug.
> 
> Rely on the new sysfs debug mechanism instead.
> 
> - v4l2-dev/ioctl.c: add vb2_queue support to video_device.
> 
> Add core support for vb2 to struct video_device. This will be used in the next patch.
> Note: this assumes that there is no more than one vb2_queue per device node. So this
> can't be used for mem2mem.
> 
> - videobuf2-core: add helper functions.
> 
> These helpers simplify using vb2: If you set vdev->queue and vdev->queue_lock then these
> helpers will take care of queue ownership and locking. So as soon as REQBUFS or
> CREATE_BUFFERS is called, that file handle owns the queue and no other filehandle can do
> anything with it except for QUERYBUF and mmap. I'm not sure about mmap: should that also
> be limited to the owner?
> 
> The locking has been changed: it is now possible to specify a mutex that protects the
> queue (vdev->queue_lock), and that will be taken instead of the core lock (vdev->lock) when
> the vb2 ioctls are called. If you need to serialize against the core lock, then you should
> take that lock in the vb2 ops you implemented. So queue_lock is always taken before vdev->lock.
> 
> This approach should remove the need for disabling locking for specific ioctls which was
> introduced in 3.5. I believe that was the wrong approach.
> 
> I have refactored reqbufs and request_buffers a bit: they call the same code to check for
> valid memory and buffer types. In addition, these functions will always return -EINVAL if
> the types are invalid, and only then will they check for busy state. That way code like qv4l2
> that tries to detect which memory types are available can still do that, even if streaming
> is in progress. Currently you can get -EBUSY back and that hides whether the memory type
> was valid.
> 
> create_buffers now also supports count == 0: if count == 0, then you will never get -EBUSY.
> 
> - create_bufs: handle count == 0.
> 
> Update documentation.
> 
> - vivi: remove pointless g/s_std support
> - vivi: embed struct video_device instead of allocating it.
> - vivi: use vb2 helper functions.
> 
> Two vivi cleanups and implement the vb2 helpers in vivi.
> 
> - v4l2-dev.c: also add debug support for the fops.
> 
> Show debugging when the fops are called if vdev->debug is set.
> 
> - v4l2-ioctl.c: shorten the lines of the table.
> 
> Make the ioctl table more readable.
> 
> - pwc: use the new vb2 helpers.
> 
> Implement the vb2 helpers in pwc.
> 
> - pwc: v4l2-compliance fixes.
> 
> Fix some complaints from v4l2-compliance.
> 
> This patch series is also available here:
> 
> git://linuxtv.org/hverkuil/media_tree.git ioctlv5
> 
> Personally I think that the table conversion is fairly trivial (just a lot of work).
> The interesting bits are with the new debug sysfs entry, the vb2 helpers and the way
> the core handles vb2 locking (and yes, you don't have to use vb2 locking, but then
> you most likely still have to write wrapper functions).
> 
> Comments? Ideas?
> 

I just a quick look at the patch series, but I have a few generic
comments:

1) Why are you commenting things on patch 0/0, instead of adding a better description
inside each patch? Some patches deserve descriptions, like this one "v4l2-ioctl.c: finalize table conversion."
The description says nothing, and it seems that it does more than just "Remove the last part of the switch"
as said above.

2) The check you're using to know if an ioctl exists is:

1948 bool v4l2_is_known_ioctl(unsigned int cmd)
1949 {
1950         if (_IOC_NR(cmd) >= V4L2_IOCTLS)
1951                 return false;
1952         return v4l2_ioctls[_IOC_NR(cmd)].ioctl == cmd;
1953 }

That assumes that: 
	a) there's just one ioctl using the same number.
	b) all ioctl's using numbers from 0 to ARRAY_SIZE(v4l2_ioctls) are valid;

With regards to (a), an ioctl code is given not only by its number, but also by
its size, it could be possible that two ioctls would share the same number,
but having different sizes.

Subsystems like input use that for some things: there, GET/SET ioctl's share
the same number (with different read/write flags). Also, different versions
of an ioctl uses different struct sizes.

We currently don't use this way (although it migh be required in the future, if we
need to extend some ioctl out of the current reserved range). So, it may be
interesting to add some note there about the current restriction added by this
patchset.

With regards to (b), this is more serious, as, if an ioctl number is not used, the
code may be doing wrong things (and even OOPSing). 

There are actually some unused numbers: 3, 6, 7, ... Also, as time goes by, ioctl's
can be deprecated and removed (like VIDIOC_G_JPEGCOMP/VIDIOC_S_JPEGCOMP). So,
it is important to actually look inside one of the ioctl fields, to check if the table
entry is really filled.

3) it would be interesting if you could benchmark the previous code and the new
one, to see what gains this change introduced, in terms of v4l2-core footprint and
performance.

Regards,
Mauro


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

* Re: [RFCv1 PATCH 00/32] Core and vb2 enhancements
  2012-06-10 16:46 ` [RFCv1 PATCH 00/32] Core and vb2 enhancements Mauro Carvalho Chehab
@ 2012-06-10 17:32   ` Hans Verkuil
  2012-06-10 19:27     ` Hans Verkuil
  0 siblings, 1 reply; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 17:32 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linux-media, Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski

On Sun June 10 2012 18:46:52 Mauro Carvalho Chehab wrote:
> Em 10-06-2012 07:25, Hans Verkuil escreveu:
> > Hi all,
> > 
> > This large patch series makes a number of changes to the core (ioctl
> > handling in particular) and vb2. It all builds on one another, so there
> > wasn't much point in splitting it. Most patches are fairly trivial, so it
> > is not as bad as it looks :-)
> > 
> > I will go through the patches one by one:
> > 
> > - Regression fixes.
> > 
> > This is a small patch that fixes a number of regressions that are relevant to
> > this patch series. These fixes have already been posted to the list.
> > 
> > - v4l2-ioctl.c: move a block of code down, no other changes.
> > 
> > Just move code around, no other changes.
> > 
> > - v4l2-ioctl.c: introduce INFO_FL_CLEAR to replace switch.
> > 
> > This replaces the switch that determines how much of the struct needs to be
> > copied from userspace with a simple table lookup.
> > 
> > - v4l2-ioctl.c: v4l2-ioctl: add debug and callback/offset functionality.
> > 
> > Prepare for the next step where the large switch is replaced by table lookups.
> > 
> > - v4l2-ioctl.c: remove an unnecessary #ifdef.
> > 
> > A small fix for the table: keep the DBG_G/S_REGISTER ioctl in the table. All
> > the right checks are already made, and this way you will actually see the ioctl
> > name in the debug messages if you use it.
> > 
> > - v4l2-ioctl.c: use the new table for querycap and i/o ioctls.
> > - v4l2-ioctl.c: use the new table for priority ioctls.
> > - v4l2-ioctl.c: use the new table for format/framebuffer ioctls.
> > - v4l2-ioctl.c: use the new table for overlay/streamon/off ioctls.
> > - v4l2-ioctl.c: use the new table for std/tuner/modulator ioctls.
> > - v4l2-ioctl.c: use the new table for queuing/parm ioctls.
> > - v4l2-ioctl.c: use the new table for control ioctls.
> > - v4l2-ioctl.c: use the new table for selection ioctls.
> > - v4l2-ioctl.c: use the new table for compression ioctls.
> > - v4l2-ioctl.c: use the new table for debug ioctls.
> > - v4l2-ioctl.c: use the new table for preset/timings ioctls.
> > - v4l2-ioctl.c: use the new table for the remaining ioctls.
> > 
> > Here the switch is replaced by table lookups section-by-section.
> > 
> > - v4l2-ioctl.c: finalize table conversion.
> > 
> > Remove the last part of the switch.
> > 
> > - v4l2-dev.c: add debug sysfs entry.
> > 
> > The video_device debug field is pretty useful, if only you could set it. The
> > solution is simple: export it in sysfs. That way you can easily set the debug
> > level per device node. Works like a charm.
> > 
> > - v4l2-ioctl: remove v4l_(i2c_)print_ioctl
> > 
> > Clean up a few rarely used macros.
> > 
> > - ivtv: don't mess with vfd->debug.
> > - cx18: don't mess with vfd->debug.
> > 
> > Rely on the new sysfs debug mechanism instead.
> > 
> > - v4l2-dev/ioctl.c: add vb2_queue support to video_device.
> > 
> > Add core support for vb2 to struct video_device. This will be used in the next patch.
> > Note: this assumes that there is no more than one vb2_queue per device node. So this
> > can't be used for mem2mem.
> > 
> > - videobuf2-core: add helper functions.
> > 
> > These helpers simplify using vb2: If you set vdev->queue and vdev->queue_lock then these
> > helpers will take care of queue ownership and locking. So as soon as REQBUFS or
> > CREATE_BUFFERS is called, that file handle owns the queue and no other filehandle can do
> > anything with it except for QUERYBUF and mmap. I'm not sure about mmap: should that also
> > be limited to the owner?
> > 
> > The locking has been changed: it is now possible to specify a mutex that protects the
> > queue (vdev->queue_lock), and that will be taken instead of the core lock (vdev->lock) when
> > the vb2 ioctls are called. If you need to serialize against the core lock, then you should
> > take that lock in the vb2 ops you implemented. So queue_lock is always taken before vdev->lock.
> > 
> > This approach should remove the need for disabling locking for specific ioctls which was
> > introduced in 3.5. I believe that was the wrong approach.
> > 
> > I have refactored reqbufs and request_buffers a bit: they call the same code to check for
> > valid memory and buffer types. In addition, these functions will always return -EINVAL if
> > the types are invalid, and only then will they check for busy state. That way code like qv4l2
> > that tries to detect which memory types are available can still do that, even if streaming
> > is in progress. Currently you can get -EBUSY back and that hides whether the memory type
> > was valid.
> > 
> > create_buffers now also supports count == 0: if count == 0, then you will never get -EBUSY.
> > 
> > - create_bufs: handle count == 0.
> > 
> > Update documentation.
> > 
> > - vivi: remove pointless g/s_std support
> > - vivi: embed struct video_device instead of allocating it.
> > - vivi: use vb2 helper functions.
> > 
> > Two vivi cleanups and implement the vb2 helpers in vivi.
> > 
> > - v4l2-dev.c: also add debug support for the fops.
> > 
> > Show debugging when the fops are called if vdev->debug is set.
> > 
> > - v4l2-ioctl.c: shorten the lines of the table.
> > 
> > Make the ioctl table more readable.
> > 
> > - pwc: use the new vb2 helpers.
> > 
> > Implement the vb2 helpers in pwc.
> > 
> > - pwc: v4l2-compliance fixes.
> > 
> > Fix some complaints from v4l2-compliance.
> > 
> > This patch series is also available here:
> > 
> > git://linuxtv.org/hverkuil/media_tree.git ioctlv5
> > 
> > Personally I think that the table conversion is fairly trivial (just a lot of work).
> > The interesting bits are with the new debug sysfs entry, the vb2 helpers and the way
> > the core handles vb2 locking (and yes, you don't have to use vb2 locking, but then
> > you most likely still have to write wrapper functions).
> > 
> > Comments? Ideas?
> > 
> 
> I just a quick look at the patch series, but I have a few generic
> comments:
> 
> 1) Why are you commenting things on patch 0/0, instead of adding a better description
> inside each patch? Some patches deserve descriptions, like this one "v4l2-ioctl.c: finalize table conversion."
> The description says nothing, and it seems that it does more than just "Remove the last part of the switch"
> as said above.

For this particular patch it should have said:

"To finalize the table conversion implement the default case and remove the switch."

And I agree that the descriptions can be improved. Something for RFCv2.

> 2) The check you're using to know if an ioctl exists is:
> 
> 1948 bool v4l2_is_known_ioctl(unsigned int cmd)
> 1949 {
> 1950         if (_IOC_NR(cmd) >= V4L2_IOCTLS)
> 1951                 return false;
> 1952         return v4l2_ioctls[_IOC_NR(cmd)].ioctl == cmd;
> 1953 }
> 
> That assumes that: 
> 	a) there's just one ioctl using the same number.

Correct.

> 	b) all ioctl's using numbers from 0 to ARRAY_SIZE(v4l2_ioctls) are valid;

No. The invalid ioctls have an empty entry in the table, so for those
v4l2_ioctls[_IOC_NR(cmd)].ioctl == 0, and 0 != cmd. So these are automatically
marked as invalid.

> 
> With regards to (a), an ioctl code is given not only by its number, but also by
> its size, it could be possible that two ioctls would share the same number,
> but having different sizes.
> 
> Subsystems like input use that for some things: there, GET/SET ioctl's share
> the same number (with different read/write flags). Also, different versions
> of an ioctl uses different struct sizes.
> 
> We currently don't use this way (although it migh be required in the future, if we
> need to extend some ioctl out of the current reserved range). So, it may be
> interesting to add some note there about the current restriction added by this
> patchset.

Good idea.

> With regards to (b), this is more serious, as, if an ioctl number is not used, the
> code may be doing wrong things (and even OOPSing). 
> 
> There are actually some unused numbers: 3, 6, 7, ... Also, as time goes by, ioctl's
> can be deprecated and removed (like VIDIOC_G_JPEGCOMP/VIDIOC_S_JPEGCOMP). So,
> it is important to actually look inside one of the ioctl fields, to check if the table
> entry is really filled.
> 
> 3) it would be interesting if you could benchmark the previous code and the new
> one, to see what gains this change introduced, in terms of v4l2-core footprint and
> performance.

I'll try that, should be interesting. Actually, my prediction is that I won't notice any
difference. Todays CPUs are so fast that the overhead of the switch is probably hard to
measure.

Regards,

	Hans

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

* Re: [RFCv1 PATCH 00/32] Core and vb2 enhancements
  2012-06-10 17:32   ` Hans Verkuil
@ 2012-06-10 19:27     ` Hans Verkuil
  2012-06-12 11:35       ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 69+ messages in thread
From: Hans Verkuil @ 2012-06-10 19:27 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linux-media, Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski

On Sun June 10 2012 19:32:36 Hans Verkuil wrote:
> On Sun June 10 2012 18:46:52 Mauro Carvalho Chehab wrote:
> > 3) it would be interesting if you could benchmark the previous code and the new
> > one, to see what gains this change introduced, in terms of v4l2-core footprint and
> > performance.
> 
> I'll try that, should be interesting. Actually, my prediction is that I won't notice any
> difference. Todays CPUs are so fast that the overhead of the switch is probably hard to
> measure.

I did some tests, calling various ioctls 100,000,000 times. The actual call into the
driver was disabled so that I only measure the time spent in v4l2-ioctl.c.

I ran the test program with 'time ./t' and measured the sys time.

For each ioctl I tested 5 times and averaged the results. Times are in seconds.

					Old		New
QUERYCAP			24.86	24.37
UNSUBSCRIBE_EVENT	23.40	23.10
LOG_STATUS			18.84	18.76
ENUMINPUT			28.82	28.90

Particularly for QUERYCAP and UNSUBSCRIBE_EVENT I found a small but reproducible
improvement in speed. The results for LOG_STATUS and ENUMINPUT are too close to
call.

After looking at the assembly code that the old code produces I suspect (but it
is hard to be sure) that LOG_STATUS and ENUMINPUT are tested quite early on, whereas
QUERYCAP and UNSUBSCRIBE_EVENT are tested quite late. The order in which the compiler
tests definitely has no relationship with the order of the case statements in the
switch.

This would certainly explain what I am seeing. I'm actually a bit surprised that
this is measurable at all.

Regards,

	Hans

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

* Re: [RFCv1 PATCH 00/32] Core and vb2 enhancements
  2012-06-10 19:27     ` Hans Verkuil
@ 2012-06-12 11:35       ` Mauro Carvalho Chehab
  2012-06-12 13:21         ` Hans Verkuil
  2012-06-12 13:24         ` Hans de Goede
  0 siblings, 2 replies; 69+ messages in thread
From: Mauro Carvalho Chehab @ 2012-06-12 11:35 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: linux-media, Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski

Em 10-06-2012 16:27, Hans Verkuil escreveu:
> On Sun June 10 2012 19:32:36 Hans Verkuil wrote:
>> On Sun June 10 2012 18:46:52 Mauro Carvalho Chehab wrote:
>>> 3) it would be interesting if you could benchmark the previous code and the new
>>> one, to see what gains this change introduced, in terms of v4l2-core footprint and
>>> performance.
>>
>> I'll try that, should be interesting. Actually, my prediction is that I won't notice any
>> difference. Todays CPUs are so fast that the overhead of the switch is probably hard to
>> measure.
> 
> I did some tests, calling various ioctls 100,000,000 times. The actual call into the
> driver was disabled so that I only measure the time spent in v4l2-ioctl.c.
> 
> I ran the test program with 'time ./t' and measured the sys time.
> 
> For each ioctl I tested 5 times and averaged the results. Times are in seconds.
> 
> 					Old		New
> QUERYCAP			24.86	24.37
> UNSUBSCRIBE_EVENT	23.40	23.10
> LOG_STATUS			18.84	18.76
> ENUMINPUT			28.82	28.90
> 
> Particularly for QUERYCAP and UNSUBSCRIBE_EVENT I found a small but reproducible
> improvement in speed. The results for LOG_STATUS and ENUMINPUT are too close to
> call.
> 
> After looking at the assembly code that the old code produces I suspect (but it
> is hard to be sure) that LOG_STATUS and ENUMINPUT are tested quite early on, whereas
> QUERYCAP and UNSUBSCRIBE_EVENT are tested quite late. The order in which the compiler
> tests definitely has no relationship with the order of the case statements in the
> switch.

The ioctl's are reordered, as gcc optimizes them in order to do a tree search and to avoid
cache flush. The worse case is likely converted into 7 CMP asm calls (log2(128)).

On your code, gcc may not be able to predict the JMP's, so it may actually have cache flushes,
depending on the cache size, and if the caller functions are before of after the video_ioctl2
handler.

I suspect that, if you compare the code with debug enabled, the new code can actually be worse
than the previous one.

It would be good if you could test what happens with QBUF/DQBUF.

> This would certainly explain what I am seeing. I'm actually a bit surprised that
> this is measurable at all.

The timing difference is not significant, especially because those ioctl's aren't the ones
used inside the streaming loop. The only ioctl's that are more time-sensitive are the streaming
ones, especially QBUF/DQBUF.

Regards,
Mauro

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

* Re: [RFCv1 PATCH 00/32] Core and vb2 enhancements
  2012-06-12 11:35       ` Mauro Carvalho Chehab
@ 2012-06-12 13:21         ` Hans Verkuil
  2012-06-12 13:24         ` Hans de Goede
  1 sibling, 0 replies; 69+ messages in thread
From: Hans Verkuil @ 2012-06-12 13:21 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linux-media, Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski

On Tue 12 June 2012 13:35:10 Mauro Carvalho Chehab wrote:
> Em 10-06-2012 16:27, Hans Verkuil escreveu:
> > On Sun June 10 2012 19:32:36 Hans Verkuil wrote:
> >> On Sun June 10 2012 18:46:52 Mauro Carvalho Chehab wrote:
> >>> 3) it would be interesting if you could benchmark the previous code and the new
> >>> one, to see what gains this change introduced, in terms of v4l2-core footprint and
> >>> performance.
> >>
> >> I'll try that, should be interesting. Actually, my prediction is that I won't notice any
> >> difference. Todays CPUs are so fast that the overhead of the switch is probably hard to
> >> measure.
> > 
> > I did some tests, calling various ioctls 100,000,000 times. The actual call into the
> > driver was disabled so that I only measure the time spent in v4l2-ioctl.c.
> > 
> > I ran the test program with 'time ./t' and measured the sys time.
> > 
> > For each ioctl I tested 5 times and averaged the results. Times are in seconds.
> > 
> > 					Old		New
> > QUERYCAP			24.86	24.37
> > UNSUBSCRIBE_EVENT	23.40	23.10
> > LOG_STATUS			18.84	18.76
> > ENUMINPUT			28.82	28.90
> > 
> > Particularly for QUERYCAP and UNSUBSCRIBE_EVENT I found a small but reproducible
> > improvement in speed. The results for LOG_STATUS and ENUMINPUT are too close to
> > call.
> > 
> > After looking at the assembly code that the old code produces I suspect (but it
> > is hard to be sure) that LOG_STATUS and ENUMINPUT are tested quite early on, whereas
> > QUERYCAP and UNSUBSCRIBE_EVENT are tested quite late. The order in which the compiler
> > tests definitely has no relationship with the order of the case statements in the
> > switch.
> 
> The ioctl's are reordered, as gcc optimizes them in order to do a tree search and to avoid
> cache flush. The worse case is likely converted into 7 CMP asm calls (log2(128)).
> 
> On your code, gcc may not be able to predict the JMP's, so it may actually have cache flushes,
> depending on the cache size, and if the caller functions are before of after the video_ioctl2
> handler.
> 
> I suspect that, if you compare the code with debug enabled, the new code can actually be worse
> than the previous one.
> 
> It would be good if you could test what happens with QBUF/DQBUF.

Again, I'm averaging 5 runs of 100,000,000 calls with the actual (d)qbuf driver operation disabled.

QBUF old: 28.95s
QBUF new: 28.31s

DQBUF old: 28.89s
DQBUF new: 28.40s

The new code is faster by 1-3%.

The timings were very consistent with little variation.

BTW, just to put this in perspective: if you are streaming 60 frames per second, then that is
120 ioctl calls. With the old code those would take 34.704 usecs, with the new code 34.026 usecs.

So you win 0.678 usecs per second, which is about 2.5 milliseconds per hour.

I did this table conversion because it improves the code and because it makes it easy to have ioctl
annotations in the form of flags in the table that allowed me to do some fancy ioctl-specific
stuff. The speed increase is completely negligible. It is falls away compared to the much, much
more CPU intensive work of displaying or processing the image data. Only by artificial tests
as I did can you even measure it.

There are no performance issues in V4L2. There are code complexity, readability and maintainability
issues that are much more important and real. Our focus should be on those issues, not on
performance at this low level.

Regards,

	Hans

> > This would certainly explain what I am seeing. I'm actually a bit surprised that
> > this is measurable at all.
> 
> The timing difference is not significant, especially because those ioctl's aren't the ones
> used inside the streaming loop. The only ioctl's that are more time-sensitive are the streaming
> ones, especially QBUF/DQBUF.
> 
> Regards,
> Mauro
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

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

* Re: [RFCv1 PATCH 00/32] Core and vb2 enhancements
  2012-06-12 11:35       ` Mauro Carvalho Chehab
  2012-06-12 13:21         ` Hans Verkuil
@ 2012-06-12 13:24         ` Hans de Goede
  1 sibling, 0 replies; 69+ messages in thread
From: Hans de Goede @ 2012-06-12 13:24 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Hans Verkuil, linux-media, Mauro Carvalho Chehab, Andy Walls,
	Laurent Pinchart, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski

Hi,

On 06/12/2012 01:35 PM, Mauro Carvalho Chehab wrote:
> Em 10-06-2012 16:27, Hans Verkuil escreveu:
>> On Sun June 10 2012 19:32:36 Hans Verkuil wrote:
>>> On Sun June 10 2012 18:46:52 Mauro Carvalho Chehab wrote:
>>>> 3) it would be interesting if you could benchmark the previous code and the new
>>>> one, to see what gains this change introduced, in terms of v4l2-core footprint and
>>>> performance.
>>>
>>> I'll try that, should be interesting. Actually, my prediction is that I won't notice any
>>> difference. Todays CPUs are so fast that the overhead of the switch is probably hard to
>>> measure.
>>
>> I did some tests, calling various ioctls 100,000,000 times. The actual call into the
>> driver was disabled so that I only measure the time spent in v4l2-ioctl.c.
>>
>> I ran the test program with 'time ./t' and measured the sys time.
>>
>> For each ioctl I tested 5 times and averaged the results. Times are in seconds.
>>
>> 					Old		New
>> QUERYCAP			24.86	24.37
>> UNSUBSCRIBE_EVENT	23.40	23.10
>> LOG_STATUS			18.84	18.76
>> ENUMINPUT			28.82	28.90
>>
>> Particularly for QUERYCAP and UNSUBSCRIBE_EVENT I found a small but reproducible
>> improvement in speed. The results for LOG_STATUS and ENUMINPUT are too close to
>> call.
>>
>> After looking at the assembly code that the old code produces I suspect (but it
>> is hard to be sure) that LOG_STATUS and ENUMINPUT are tested quite early on, whereas
>> QUERYCAP and UNSUBSCRIBE_EVENT are tested quite late. The order in which the compiler
>> tests definitely has no relationship with the order of the case statements in the
>> switch.
>
> The ioctl's are reordered, as gcc optimizes them in order to do a tree search and to avoid
> cache flush. The worse case is likely converted into 7 CMP asm calls (log2(128)).
>
> On your code, gcc may not be able to predict the JMP's, so it may actually have cache flushes,
> depending on the cache size, and if the caller functions are before of after the video_ioctl2
> handler.
>
> I suspect that, if you compare the code with debug enabled, the new code can actually be worse
> than the previous one.
>
> It would be good if you could test what happens with QBUF/DQBUF.
>
>> This would certainly explain what I am seeing. I'm actually a bit surprised that
>> this is measurable at all.
>
> The timing difference is not significant, especially because those ioctl's aren't the ones
> used inside the streaming loop. The only ioctl's that are more time-sensitive are the streaming
> ones, especially QBUF/DQBUF.

Even QBUF / DQBUF are called max circa 100 times / second. I think Hans V's patchset should not
be seen from a performance pov (other then that it should not cause performance regressions), but
more as a nice code cleanup / simplification.

It certainly makes things a lot more readable by avoiding a lot of code duplication. Not sure if
in the end it actually saves any lines of code, but readability, and being able to understand the
intent of the code is key here IMHO.

Regards,

Hans (who likes Hans V's patchset :)


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

* Re: [RFCv1 PATCH 18/32] v4l2-ioctl.c: finalize table conversion.
  2012-06-10 10:25   ` [RFCv1 PATCH 18/32] v4l2-ioctl.c: finalize table conversion Hans Verkuil
@ 2012-06-18  9:46     ` Laurent Pinchart
  2012-06-18 10:50       ` Mauro Carvalho Chehab
  2012-06-18 11:17       ` Hans Verkuil
  0 siblings, 2 replies; 69+ messages in thread
From: Laurent Pinchart @ 2012-06-18  9:46 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: linux-media, Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Guennadi Liakhovetski, Pawel Osciak, Tomasz Stanislawski,
	Hans Verkuil

Hi Hans,

Thanks for the patch.

On Sunday 10 June 2012 12:25:40 Hans Verkuil wrote:
> From: Hans Verkuil <hans.verkuil@cisco.com>
> 
> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> ---
>  drivers/media/video/v4l2-ioctl.c |   35 +++++++++++++----------------------
> 1 file changed, 13 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/media/video/v4l2-ioctl.c
> b/drivers/media/video/v4l2-ioctl.c index 0de31c4..6c91674 100644
> --- a/drivers/media/video/v4l2-ioctl.c
> +++ b/drivers/media/video/v4l2-ioctl.c
> @@ -870,6 +870,11 @@ static void v4l_print_newline(const void *arg)
>  	pr_cont("\n");
>  }
> 
> +static void v4l_print_default(const void *arg)
> +{
> +	pr_cont("non-standard ioctl\n");

I'd say "driver-specific ioctl" instead. "non-standard" may sound like an 
error to users.

> +}
> +
>  static int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
>  {
>  	__u32 i;
> @@ -1853,12 +1858,6 @@ struct v4l2_ioctl_info {
>  	  sizeof(((struct v4l2_struct *)0)->field)) << 16)
>  #define INFO_FL_CLEAR_MASK (_IOC_SIZEMASK << 16)
> 
> -#define IOCTL_INFO(_ioctl, _flags) [_IOC_NR(_ioctl)] = {	\
> -	.ioctl = _ioctl,					\
> -	.flags = _flags,					\
> -	.name = #_ioctl,					\
> -}
> -
>  #define IOCTL_INFO_STD(_ioctl, _vidioc, _debug, _flags)			\
>  	[_IOC_NR(_ioctl)] = {						\
>  		.ioctl = _ioctl,					\
> @@ -2042,12 +2041,12 @@ static long __video_do_ioctl(struct file *file,
>  	} else {
>  		default_info.ioctl = cmd;
>  		default_info.flags = 0;
> -		default_info.debug = NULL;
> +		default_info.debug = v4l_print_default;
>  		info = &default_info;
>  	}
> 
>  	write_only = _IOC_DIR(cmd) == _IOC_WRITE;
> -	if (info->debug && write_only && vfd->debug > V4L2_DEBUG_IOCTL) {
> +	if (write_only && vfd->debug > V4L2_DEBUG_IOCTL) {
>  		v4l_print_ioctl(vfd->name, cmd);
>  		pr_cont(": ");
>  		info->debug(arg);
> @@ -2058,22 +2057,16 @@ static long __video_do_ioctl(struct file *file,
>  		const vidioc_op *vidioc = p + info->offset;
> 
>  		ret = (*vidioc)(file, fh, arg);
> -		goto error;
>  	} else if (info->flags & INFO_FL_FUNC) {
>  		ret = info->func(ops, file, fh, arg);
> -		goto error;
> +	} else if (!ops->vidioc_default) {
> +		ret = -ENOTTY;
> +	} else {
> +		ret = ops->vidioc_default(file, fh,
> +			use_fh_prio ? v4l2_prio_check(vfd->prio, vfh->prio) >= 0 : 0,
> +			cmd, arg);
>  	}
> 
> -	switch (cmd) {
> -	default:
> -		if (!ops->vidioc_default)
> -			break;
> -		ret = ops->vidioc_default(file, fh, use_fh_prio ?
> -				v4l2_prio_check(vfd->prio, vfh->prio) >= 0 : 0,
> -				cmd, arg);
> -		break;
> -	} /* switch */
> -
>  error:
>  	if (vfd->debug) {
>  		if (write_only && vfd->debug > V4L2_DEBUG_IOCTL) {
> @@ -2087,8 +2080,6 @@ error:
>  			pr_cont(": error %ld\n", ret);
>  		else if (vfd->debug == V4L2_DEBUG_IOCTL)
>  			pr_cont("\n");
> -		else if (!info->debug)
> -			return ret;
>  		else if (_IOC_DIR(cmd) == _IOC_NONE)
>  			info->debug(arg);
>  		else {
-- 
Regards,

Laurent Pinchart


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

* Re: [RFCv1 PATCH 04/32] v4l2-ioctl.c: v4l2-ioctl: add debug and callback/offset functionality.
  2012-06-10 10:25   ` [RFCv1 PATCH 04/32] v4l2-ioctl.c: v4l2-ioctl: add debug and callback/offset functionality Hans Verkuil
@ 2012-06-18  9:47     ` Laurent Pinchart
  2012-06-18 11:25       ` Hans Verkuil
  0 siblings, 1 reply; 69+ messages in thread
From: Laurent Pinchart @ 2012-06-18  9:47 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: linux-media, Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Guennadi Liakhovetski, Pawel Osciak, Tomasz Stanislawski,
	Hans Verkuil

Hi Hans,

Thanks for the patch.

On Sunday 10 June 2012 12:25:26 Hans Verkuil wrote:
> From: Hans Verkuil <hans.verkuil@cisco.com>
> 
> Add the necessary plumbing to make it possible to replace the switch by a
> table driven implementation.
> 
> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> ---
>  drivers/media/video/v4l2-ioctl.c |   91
> ++++++++++++++++++++++++++++++++------ 1 file changed, 78 insertions(+), 13
> deletions(-)
> 
> diff --git a/drivers/media/video/v4l2-ioctl.c
> b/drivers/media/video/v4l2-ioctl.c index a9602db..a4115ce 100644
> --- a/drivers/media/video/v4l2-ioctl.c
> +++ b/drivers/media/video/v4l2-ioctl.c
> @@ -396,12 +396,22 @@ struct v4l2_ioctl_info {
>  	unsigned int ioctl;
>  	u32 flags;
>  	const char * const name;
> +	union {
> +		u32 offset;
> +		int (*func)(const struct v4l2_ioctl_ops *ops,
> +				struct file *file, void *fh, void *p);
> +	};
> +	void (*debug)(const void *arg);
>  };
> 
>  /* This control needs a priority check */
>  #define INFO_FL_PRIO	(1 << 0)
>  /* This control can be valid if the filehandle passes a control handler. */
> #define INFO_FL_CTRL	(1 << 1)
> +/* This is a standard ioctl, no need for special code */
> +#define INFO_FL_STD	(1 << 2)
> +/* This is ioctl has its own function */
> +#define INFO_FL_FUNC	(1 << 3)
>  /* Zero struct from after the field to the end */
>  #define INFO_FL_CLEAR(v4l2_struct, field)			\
>  	((offsetof(struct v4l2_struct, field) +			\
> @@ -414,6 +424,24 @@ struct v4l2_ioctl_info {
>  	.name = #_ioctl,					\
>  }
> 
> +#define IOCTL_INFO_STD(_ioctl, _vidioc, _debug, _flags)			\
> +	[_IOC_NR(_ioctl)] = {						\
> +		.ioctl = _ioctl,					\
> +		.flags = _flags | INFO_FL_STD,				\
> +		.name = #_ioctl,					\
> +		.offset = offsetof(struct v4l2_ioctl_ops, _vidioc),	\
> +		.debug = _debug,					\
> +	}
> +
> +#define IOCTL_INFO_FNC(_ioctl, _func, _debug, _flags)			\
> +	[_IOC_NR(_ioctl)] = {						\
> +		.ioctl = _ioctl,					\
> +		.flags = _flags | INFO_FL_FUNC,				\
> +		.name = #_ioctl,					\
> +		.func = _func,						\
> +		.debug = _debug,					\
> +	}
> +
>  static struct v4l2_ioctl_info v4l2_ioctls[] = {
>  	IOCTL_INFO(VIDIOC_QUERYCAP, 0),
>  	IOCTL_INFO(VIDIOC_ENUM_FMT, INFO_FL_CLEAR(v4l2_fmtdesc, type)),
> @@ -512,7 +540,7 @@ bool v4l2_is_known_ioctl(unsigned int cmd)
>     external ioctl messages as well as internal V4L ioctl */
>  void v4l_printk_ioctl(unsigned int cmd)
>  {
> -	char *dir, *type;
> +	const char *dir, *type;
> 
>  	switch (_IOC_TYPE(cmd)) {
>  	case 'd':
> @@ -523,10 +551,11 @@ void v4l_printk_ioctl(unsigned int cmd)
>  			type = "v4l2";
>  			break;
>  		}
> -		printk("%s", v4l2_ioctls[_IOC_NR(cmd)].name);
> +		pr_cont("%s", v4l2_ioctls[_IOC_NR(cmd)].name);
>  		return;
>  	default:
>  		type = "unknown";
> +		break;
>  	}
> 
>  	switch (_IOC_DIR(cmd)) {
> @@ -536,7 +565,7 @@ void v4l_printk_ioctl(unsigned int cmd)
>  	case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
>  	default:                     dir = "*ERR*"; break;
>  	}
> -	printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
> +	pr_cont("%s ioctl '%c', dir=%s, #%d (0x%08x)",
>  		type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
>  }
>  EXPORT_SYMBOL(v4l_printk_ioctl);
> @@ -546,6 +575,9 @@ static long __video_do_ioctl(struct file *file,
>  {
>  	struct video_device *vfd = video_devdata(file);
>  	const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
> +	bool write_only = false;
> +	struct v4l2_ioctl_info default_info;
> +	const struct v4l2_ioctl_info *info;
>  	void *fh = file->private_data;
>  	struct v4l2_fh *vfh = NULL;
>  	int use_fh_prio = 0;
> @@ -563,23 +595,40 @@ static long __video_do_ioctl(struct file *file,
>  	}
> 
>  	if (v4l2_is_known_ioctl(cmd)) {
> -		struct v4l2_ioctl_info *info = &v4l2_ioctls[_IOC_NR(cmd)];
> +		info = &v4l2_ioctls[_IOC_NR(cmd)];
> 
>  	        if (!test_bit(_IOC_NR(cmd), vfd->valid_ioctls) &&
>  		    !((info->flags & INFO_FL_CTRL) && vfh && vfh->ctrl_handler))
> -			return -ENOTTY;
> +			goto error;
> 
>  		if (use_fh_prio && (info->flags & INFO_FL_PRIO)) {
>  			ret = v4l2_prio_check(vfd->prio, vfh->prio);
>  			if (ret)
> -				return ret;
> +				goto error;
>  		}
> +	} else {
> +		default_info.ioctl = cmd;
> +		default_info.flags = 0;
> +		default_info.debug = NULL;
> +		info = &default_info;
>  	}
> 
> -	if ((vfd->debug & V4L2_DEBUG_IOCTL) &&
> -				!(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
> +	write_only = _IOC_DIR(cmd) == _IOC_WRITE;
> +	if (info->debug && write_only && vfd->debug > V4L2_DEBUG_IOCTL) {
>  		v4l_print_ioctl(vfd->name, cmd);
> -		printk(KERN_CONT "\n");
> +		pr_cont(": ");
> +		info->debug(arg);
> +	}

Shouldn't you print the ioctl name and information even if info->debug is NULL 
?

> +	if (info->flags & INFO_FL_STD) {
> +		typedef int (*vidioc_op)(struct file *file, void *fh, void *p);
> +		const void *p = vfd->ioctl_ops;
> +		const vidioc_op *vidioc = p + info->offset;
> +
> +		ret = (*vidioc)(file, fh, arg);
> +		goto error;
> +	} else if (info->flags & INFO_FL_FUNC) {
> +		ret = info->func(ops, file, fh, arg);
> +		goto error;
>  	}
> 
>  	switch (cmd) {
> @@ -2100,10 +2149,26 @@ static long __video_do_ioctl(struct file *file,
>  		break;
>  	} /* switch */
> 
> -	if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
> -		if (ret < 0) {
> -			v4l_print_ioctl(vfd->name, cmd);
> -			printk(KERN_CONT " error %ld\n", ret);
> +error:

This isn't an error, is it ? I'd call it done instead.

> +	if (vfd->debug) {
> +		if (write_only && vfd->debug > V4L2_DEBUG_IOCTL) {

vfd->debug is a bitmask (or at least is documented as being a bitmask in 
include/media/v4l2-ioctl.h).

> +			if (ret)

Shouldn't you test for < 0 instead ? Driver-specific ioctls might return a > 0 
value in case of success.

> +				pr_info("%s: error %ld\n",
> +					video_device_node_name(vfd), ret);
> +			return ret;
> +		}
> +		v4l_print_ioctl(vfd->name, cmd);
> +		if (ret)
> +			pr_cont(": error %ld\n", ret);
> +		else if (vfd->debug == V4L2_DEBUG_IOCTL)
> +			pr_cont("\n");
> +		else if (!info->debug)
> +			return ret;
> +		else if (_IOC_DIR(cmd) == _IOC_NONE)
> +			info->debug(arg);
> +		else {
> +			pr_cont(": ");
> +			info->debug(arg);
>  		}

Ouch. What are you trying to do here ? Can't we simplify debug messages ?

>  	}

-- 
Regards,

Laurent Pinchart


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

* Re: [RFCv1 PATCH 19/32] v4l2-dev.c: add debug sysfs entry.
  2012-06-10 10:25   ` [RFCv1 PATCH 19/32] v4l2-dev.c: add debug sysfs entry Hans Verkuil
@ 2012-06-18  9:48     ` Laurent Pinchart
  2012-06-18 11:30       ` Hans Verkuil
  0 siblings, 1 reply; 69+ messages in thread
From: Laurent Pinchart @ 2012-06-18  9:48 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: linux-media, Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Guennadi Liakhovetski, Pawel Osciak, Tomasz Stanislawski,
	Hans Verkuil

Hi Hans,

Thanks for the patch.

On Sunday 10 June 2012 12:25:41 Hans Verkuil wrote:
> From: Hans Verkuil <hans.verkuil@cisco.com>
> 
> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> ---
>  drivers/media/video/v4l2-dev.c |   24 ++++++++++++++++++++++++
>  1 file changed, 24 insertions(+)
> 
> diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c
> index 1500208..5c0bb18 100644
> --- a/drivers/media/video/v4l2-dev.c
> +++ b/drivers/media/video/v4l2-dev.c
> @@ -46,6 +46,29 @@ static ssize_t show_index(struct device *cd,
>  	return sprintf(buf, "%i\n", vdev->index);
>  }
> 
> +static ssize_t show_debug(struct device *cd,
> +			 struct device_attribute *attr, char *buf)
> +{
> +	struct video_device *vdev = to_video_device(cd);
> +
> +	return sprintf(buf, "%i\n", vdev->debug);
> +}
> +
> +static ssize_t set_debug(struct device *cd, struct device_attribute *attr,
> +		   const char *buf, size_t len)
> +{
> +	struct video_device *vdev = to_video_device(cd);
> +	int res = 0;
> +	u16 value;
> +
> +	res = kstrtou16(buf, 0, &value);
> +	if (res)
> +		return res;
> +
> +	vdev->debug = value;

Can't this race with the various vdev->debug tests we have in the V4L core ?

> +	return len;
> +}
> +
>  static ssize_t show_name(struct device *cd,
>  			 struct device_attribute *attr, char *buf)
>  {
> @@ -56,6 +79,7 @@ static ssize_t show_name(struct device *cd,
> 
>  static struct device_attribute video_device_attrs[] = {
>  	__ATTR(name, S_IRUGO, show_name, NULL),
> +	__ATTR(debug, 0644, show_debug, set_debug),
>  	__ATTR(index, S_IRUGO, show_index, NULL),
>  	__ATTR_NULL
>  };
-- 
Regards,

Laurent Pinchart


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

* Re: [RFCv1 PATCH 20/32] v4l2-ioctl: remove v4l_(i2c_)print_ioctl
  2012-06-10 10:25   ` [RFCv1 PATCH 20/32] v4l2-ioctl: remove v4l_(i2c_)print_ioctl Hans Verkuil
@ 2012-06-18  9:50     ` Laurent Pinchart
  2012-06-18 11:33       ` Hans Verkuil
  0 siblings, 1 reply; 69+ messages in thread
From: Laurent Pinchart @ 2012-06-18  9:50 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: linux-media, Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Guennadi Liakhovetski, Pawel Osciak, Tomasz Stanislawski,
	Hans Verkuil

Hi Hans,

Thanks for the patch.

On Sunday 10 June 2012 12:25:42 Hans Verkuil wrote:
> From: Hans Verkuil <hans.verkuil@cisco.com>
> 
> v4l_i2c_print_ioctl wasn't used and v4l_print_ioctl could be replaced by
> v4l_i2c_printk_ioctl.

I suppose you meant v4l_printk_ioctl herE.

> 
> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>

-- 
Regards,

Laurent Pinchart


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

* Re: [RFCv1 PATCH 30/32] v4l2-ioctl.c: shorten the lines of the table.
  2012-06-10 10:25   ` [RFCv1 PATCH 30/32] v4l2-ioctl.c: shorten the lines of the table Hans Verkuil
@ 2012-06-18  9:57     ` Laurent Pinchart
  2012-06-18 11:34       ` Hans Verkuil
  0 siblings, 1 reply; 69+ messages in thread
From: Laurent Pinchart @ 2012-06-18  9:57 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: linux-media, Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Guennadi Liakhovetski, Pawel Osciak, Tomasz Stanislawski,
	Hans Verkuil

Hi Hans,

Thanks for the patch.

On Sunday 10 June 2012 12:25:52 Hans Verkuil wrote:
> From: Hans Verkuil <hans.verkuil@cisco.com>
> 
> Use some macro magic to reduce the length of the lines in the table. This
> makes it more readable.

It indeed shortens the lines, but to be honest I find the result less 
readable.

> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>

-- 
Regards,

Laurent Pinchart


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

* Re: [RFCv1 PATCH 29/32] v4l2-dev.c: also add debug support for the fops.
  2012-06-10 10:25   ` [RFCv1 PATCH 29/32] v4l2-dev.c: also add debug support for the fops Hans Verkuil
@ 2012-06-18 10:01     ` Laurent Pinchart
  2012-06-18 11:40       ` Hans Verkuil
  0 siblings, 1 reply; 69+ messages in thread
From: Laurent Pinchart @ 2012-06-18 10:01 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: linux-media, Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Guennadi Liakhovetski, Pawel Osciak, Tomasz Stanislawski,
	Hans Verkuil

Hi Hans,

Thanks for the patch.

On Sunday 10 June 2012 12:25:51 Hans Verkuil wrote:
> From: Hans Verkuil <hans.verkuil@cisco.com>
> 
> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> ---
>  drivers/media/video/v4l2-dev.c |   41 ++++++++++++++++++++++++++-----------
>  1 file changed, 29 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c
> index 5c0bb18..54f387d 100644
> --- a/drivers/media/video/v4l2-dev.c
> +++ b/drivers/media/video/v4l2-dev.c
> @@ -305,6 +305,9 @@ static ssize_t v4l2_read(struct file *filp, char __user
> *buf, ret = vdev->fops->read(filp, buf, sz, off);
>  	if (test_bit(V4L2_FL_LOCK_ALL_FOPS, &vdev->flags))
>  		mutex_unlock(vdev->lock);
> +	if (vdev->debug)

As vdev->debug is a bitmask, shouldn't we add an fops debug bit ?

> +		pr_info("%s: read: %zd (%d)\n",
> +			video_device_node_name(vdev), sz, ret);

Shouldn't we use KERN_DEBUG instead of KERN_INFO ? BTW, what about replacing 
the pr_* calls with dev_* calls ?

>  	return ret;
>  }
> 
> @@ -323,6 +326,9 @@ static ssize_t v4l2_write(struct file *filp, const char
> __user *buf, ret = vdev->fops->write(filp, buf, sz, off);
>  	if (test_bit(V4L2_FL_LOCK_ALL_FOPS, &vdev->flags))
>  		mutex_unlock(vdev->lock);
> +	if (vdev->debug)
> +		pr_info("%s: write: %zd (%d)\n",
> +			video_device_node_name(vdev), sz, ret);
>  	return ret;
>  }
> 
> @@ -339,6 +345,9 @@ static unsigned int v4l2_poll(struct file *filp, struct
> poll_table_struct *poll) ret = vdev->fops->poll(filp, poll);
>  	if (test_bit(V4L2_FL_LOCK_ALL_FOPS, &vdev->flags))
>  		mutex_unlock(vdev->lock);
> +	if (vdev->debug)
> +		pr_info("%s: poll: %08x\n",
> +			video_device_node_name(vdev), ret);
>  	return ret;
>  }
> 
> @@ -348,20 +357,14 @@ static long v4l2_ioctl(struct file *filp, unsigned int
> cmd, unsigned long arg) int ret = -ENODEV;
> 
>  	if (vdev->fops->unlocked_ioctl) {
> -		bool locked = false;
> +		struct mutex *lock = v4l2_ioctl_get_lock(vdev, cmd);
> 
> -		if (vdev->lock) {
> -			/* always lock unless the cmd is marked as "don't use lock" */
> -			locked = !v4l2_is_known_ioctl(cmd) ||
> -				 !test_bit(_IOC_NR(cmd), vdev->disable_locking);
> -
> -			if (locked && mutex_lock_interruptible(vdev->lock))
> -				return -ERESTARTSYS;
> -		}
> +		if (lock && mutex_lock_interruptible(lock))
> +			return -ERESTARTSYS;
>  		if (video_is_registered(vdev))
>  			ret = vdev->fops->unlocked_ioctl(filp, cmd, arg);
> -		if (locked)
> -			mutex_unlock(vdev->lock);
> +		if (lock)
> +			mutex_unlock(lock);
>  	} else if (vdev->fops->ioctl) {
>  		/* This code path is a replacement for the BKL. It is a major
>  		 * hack but it will have to do for those drivers that are not
> @@ -409,12 +412,17 @@ static unsigned long v4l2_get_unmapped_area(struct
> file *filp, unsigned long flags)
>  {
>  	struct video_device *vdev = video_devdata(filp);
> +	int ret;
> 
>  	if (!vdev->fops->get_unmapped_area)
>  		return -ENOSYS;
>  	if (!video_is_registered(vdev))
>  		return -ENODEV;
> -	return vdev->fops->get_unmapped_area(filp, addr, len, pgoff, flags);
> +	ret = vdev->fops->get_unmapped_area(filp, addr, len, pgoff, flags);
> +	if (vdev->debug)
> +		pr_info("%s: get_unmapped_area (%d)\n",
> +			video_device_node_name(vdev), ret);
> +	return ret;
>  }
>  #endif
> 
> @@ -432,6 +440,9 @@ static int v4l2_mmap(struct file *filp, struct
> vm_area_struct *vm) ret = vdev->fops->mmap(filp, vm);
>  	if (test_bit(V4L2_FL_LOCK_ALL_FOPS, &vdev->flags))
>  		mutex_unlock(vdev->lock);
> +	if (vdev->debug)
> +		pr_info("%s: mmap (%d)\n",
> +			video_device_node_name(vdev), ret);
>  	return ret;
>  }
> 
> @@ -470,6 +481,9 @@ err:
>  	/* decrease the refcount in case of an error */
>  	if (ret)
>  		video_put(vdev);
> +	if (vdev->debug)
> +		pr_info("%s: open (%d)\n",
> +			video_device_node_name(vdev), ret);
>  	return ret;
>  }
> 
> @@ -489,6 +503,9 @@ static int v4l2_release(struct inode *inode, struct file
> *filp) /* decrease the refcount unconditionally since the release()
>  	   return value is ignored. */
>  	video_put(vdev);
> +	if (vdev->debug)
> +		pr_info("%s: release\n",
> +			video_device_node_name(vdev));
>  	return ret;
>  }
-- 
Regards,

Laurent Pinchart


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

* Re: [RFCv1 PATCH 28/32] vivi: use vb2 helper functions.
  2012-06-10 10:25   ` [RFCv1 PATCH 28/32] vivi: use vb2 helper functions Hans Verkuil
@ 2012-06-18 10:08     ` Laurent Pinchart
  2012-06-18 11:40       ` Hans Verkuil
  0 siblings, 1 reply; 69+ messages in thread
From: Laurent Pinchart @ 2012-06-18 10:08 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: linux-media, Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Guennadi Liakhovetski, Pawel Osciak, Tomasz Stanislawski,
	Hans Verkuil

Hi Hans,

Thanks for the patch.

On Sunday 10 June 2012 12:25:50 Hans Verkuil wrote:
> From: Hans Verkuil <hans.verkuil@cisco.com>
> 
> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> ---
>  drivers/media/video/vivi.c |  160 ++++++-----------------------------------
>  1 file changed, 21 insertions(+), 139 deletions(-)
> 
> diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c
> index 1e4da5e..1e8c4f3 100644
> --- a/drivers/media/video/vivi.c
> +++ b/drivers/media/video/vivi.c
> @@ -767,7 +767,13 @@ static int queue_setup(struct vb2_queue *vq, const
> struct v4l2_format *fmt, struct vivi_dev *dev = vb2_get_drv_priv(vq);
>  	unsigned long size;
> 
> -	size = dev->width * dev->height * dev->pixelsize;
> +	if (fmt)
> +		size = fmt->fmt.pix.sizeimage;
> +	else
> +		size = dev->width * dev->height * dev->pixelsize;
> +
> +	if (size == 0)
> +		return -EINVAL;

If I'm not mistaken, this is a bug fix to properly support CREATE_BUF, right ? 
If so it should be split to its own patch.

>  	if (0 == *nbuffers)
>  		*nbuffers = 32;

-- 
Regards,

Laurent Pinchart


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

* Re: [RFCv1 PATCH 25/32] create_bufs: handle count == 0.
  2012-06-10 10:25   ` [RFCv1 PATCH 25/32] create_bufs: handle count == 0 Hans Verkuil
@ 2012-06-18 10:11     ` Laurent Pinchart
  2012-06-18 11:43       ` Hans Verkuil
  0 siblings, 1 reply; 69+ messages in thread
From: Laurent Pinchart @ 2012-06-18 10:11 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: linux-media, Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Guennadi Liakhovetski, Pawel Osciak, Tomasz Stanislawski,
	Hans Verkuil

Hi Hans,

Thanks for the patch.

On Sunday 10 June 2012 12:25:47 Hans Verkuil wrote:
> From: Hans Verkuil <hans.verkuil@cisco.com>
> 
> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> ---
>  Documentation/DocBook/media/v4l/vidioc-create-bufs.xml |    8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/DocBook/media/v4l/vidioc-create-bufs.xml
> b/Documentation/DocBook/media/v4l/vidioc-create-bufs.xml index
> 765549f..afdba4d 100644
> --- a/Documentation/DocBook/media/v4l/vidioc-create-bufs.xml
> +++ b/Documentation/DocBook/media/v4l/vidioc-create-bufs.xml
> @@ -97,7 +97,13 @@ information.</para>
>  	  <row>
>  	    <entry>__u32</entry>
>  	    <entry><structfield>count</structfield></entry>
> -	    <entry>The number of buffers requested or granted.</entry>
> +	    <entry>The number of buffers requested or granted. If count == 0,
> then
> +	    <constant>VIDIOC_CREATE_BUFS</constant> will set
> <structfield>index</structfield>
> +	    to the starting buffer index,

I find "starting buffer index" a bit unclear in this context, as we don't 
create any buffer.

> and it will check the validity of
> +	    <structfield>memory</structfield> and
> <structfield>format.type</structfield>.
> +	    If those are invalid -1 is returned and errno is set to &EINVAL;,
> +	    otherwise <constant>VIDIOC_CREATE_BUFS</constant> returns 0. It will
> +	    never set errno to &EBUSY; in this particular case.</entry>
>  	  </row>
>  	  <row>
>  	    <entry>__u32</entry>
-- 
Regards,

Laurent Pinchart


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

* Re: [RFCv1 PATCH 27/32] vivi: embed struct video_device instead of allocating it.
  2012-06-10 10:25   ` [RFCv1 PATCH 27/32] vivi: embed struct video_device instead of allocating it Hans Verkuil
@ 2012-06-18 10:13     ` Laurent Pinchart
  2012-06-18 11:44       ` Hans Verkuil
  0 siblings, 1 reply; 69+ messages in thread
From: Laurent Pinchart @ 2012-06-18 10:13 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: linux-media, Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Guennadi Liakhovetski, Pawel Osciak, Tomasz Stanislawski,
	Hans Verkuil

Hi Hans,

Thanks for the patch.

On Sunday 10 June 2012 12:25:49 Hans Verkuil wrote:
> From: Hans Verkuil <hans.verkuil@cisco.com>
> 
> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> ---
>  drivers/media/video/vivi.c |   25 +++++++------------------
>  1 file changed, 7 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c
> index 8dd5ae6..1e4da5e 100644
> --- a/drivers/media/video/vivi.c
> +++ b/drivers/media/video/vivi.c

[snip]

> @@ -1080,7 +1078,6 @@ static int vidioc_enum_input(struct file *file, void
> *priv, return -EINVAL;
> 
>  	inp->type = V4L2_INPUT_TYPE_CAMERA;
> -	inp->std = V4L2_STD_525_60;

Doesn't this belong to the previous patch ?

>  	sprintf(inp->name, "Camera %u", inp->index);
>  	return 0;
>  }

-- 
Regards,

Laurent Pinchart


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

* Re: [RFCv1 PATCH 24/32] videobuf2-core: add helper functions.
  2012-06-10 10:25   ` [RFCv1 PATCH 24/32] videobuf2-core: add helper functions Hans Verkuil
@ 2012-06-18 10:23     ` Laurent Pinchart
  2012-06-18 11:49       ` Hans Verkuil
  0 siblings, 1 reply; 69+ messages in thread
From: Laurent Pinchart @ 2012-06-18 10:23 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: linux-media, Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Guennadi Liakhovetski, Pawel Osciak, Tomasz Stanislawski,
	Hans Verkuil

Hi Hans,

Thanks for the patch.

On Sunday 10 June 2012 12:25:46 Hans Verkuil wrote:
> From: Hans Verkuil <hans.verkuil@cisco.com>
> 
> Add helper functions to make it easier to adapt drivers to vb2.

What about moving those functions to videobuf2-ioctl.c ? The helper functions 
are based on top of an existing vb2 core that isn't aware of queue ownership. 
It's not clear (to me at least) how the helpers will evolve and whether they 
will be used by all drivers or not, or whether part of what they do will get 
merged into the vb2 core. Splitting the helpers in a separate file would help 
not mixing code too much without really thinking about it.

> These helpers take care of core locking and check if the filehandle is the
> owner of the queue.
> 
> This patch also adds support for count == 0 in create_bufs.

Could you please split that to its own patch ? The addition of 
__verify_memory_type() should be split as well.

> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>

-- 
Regards,

Laurent Pinchart


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

* Re: [RFCv1 PATCH 18/32] v4l2-ioctl.c: finalize table conversion.
  2012-06-18  9:46     ` Laurent Pinchart
@ 2012-06-18 10:50       ` Mauro Carvalho Chehab
  2012-06-18 11:03         ` Laurent Pinchart
  2012-06-18 11:49         ` Hans Verkuil
  2012-06-18 11:17       ` Hans Verkuil
  1 sibling, 2 replies; 69+ messages in thread
From: Mauro Carvalho Chehab @ 2012-06-18 10:50 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Hans Verkuil, linux-media, Mauro Carvalho Chehab, Hans de Goede,
	Andy Walls, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

Em 18-06-2012 06:46, Laurent Pinchart escreveu:
> Hi Hans,
> 
> Thanks for the patch.
> 
> On Sunday 10 June 2012 12:25:40 Hans Verkuil wrote:
>> From: Hans Verkuil <hans.verkuil@cisco.com>
>>
>> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
>> ---
>>   drivers/media/video/v4l2-ioctl.c |   35 +++++++++++++----------------------
>> 1 file changed, 13 insertions(+), 22 deletions(-)
>>
>> diff --git a/drivers/media/video/v4l2-ioctl.c
>> b/drivers/media/video/v4l2-ioctl.c index 0de31c4..6c91674 100644
>> --- a/drivers/media/video/v4l2-ioctl.c
>> +++ b/drivers/media/video/v4l2-ioctl.c
>> @@ -870,6 +870,11 @@ static void v4l_print_newline(const void *arg)
>>   	pr_cont("\n");
>>   }
>>
>> +static void v4l_print_default(const void *arg)
>> +{
>> +	pr_cont("non-standard ioctl\n");
> 
> I'd say "driver-specific ioctl" instead. "non-standard" may sound like an
> error to users.

This message is useless as-is, as it provides no glue about what ioctl was
called. You should either remove it or print the ioctl number, in hexa.

Regards,
Mauro

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

* Re: [RFCv1 PATCH 18/32] v4l2-ioctl.c: finalize table conversion.
  2012-06-18 10:50       ` Mauro Carvalho Chehab
@ 2012-06-18 11:03         ` Laurent Pinchart
  2012-06-18 11:49         ` Hans Verkuil
  1 sibling, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2012-06-18 11:03 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Hans Verkuil, linux-media, Mauro Carvalho Chehab, Hans de Goede,
	Andy Walls, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

Hi Mauro,

On Monday 18 June 2012 07:50:35 Mauro Carvalho Chehab wrote:
> Em 18-06-2012 06:46, Laurent Pinchart escreveu:
> > On Sunday 10 June 2012 12:25:40 Hans Verkuil wrote:
> >> From: Hans Verkuil <hans.verkuil@cisco.com>
> >> 
> >> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> >> ---
> >> 
> >>   drivers/media/video/v4l2-ioctl.c |   35
> >>   +++++++++++++----------------------
> >> 
> >> 1 file changed, 13 insertions(+), 22 deletions(-)
> >> 
> >> diff --git a/drivers/media/video/v4l2-ioctl.c
> >> b/drivers/media/video/v4l2-ioctl.c index 0de31c4..6c91674 100644
> >> --- a/drivers/media/video/v4l2-ioctl.c
> >> +++ b/drivers/media/video/v4l2-ioctl.c
> >> @@ -870,6 +870,11 @@ static void v4l_print_newline(const void *arg)
> >> 
> >>   	pr_cont("\n");
> >>   
> >>   }
> >> 
> >> +static void v4l_print_default(const void *arg)
> >> +{
> >> +	pr_cont("non-standard ioctl\n");
> > 
> > I'd say "driver-specific ioctl" instead. "non-standard" may sound like an
> > error to users.
> 
> This message is useless as-is, as it provides no glue about what ioctl was
> called. You should either remove it or print the ioctl number, in hexa.

I think the ioctl number is already printed by the caller of 
v4l_print_default.

-- 
Regards,

Laurent Pinchart


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

* Re: [RFCv1 PATCH 18/32] v4l2-ioctl.c: finalize table conversion.
  2012-06-18  9:46     ` Laurent Pinchart
  2012-06-18 10:50       ` Mauro Carvalho Chehab
@ 2012-06-18 11:17       ` Hans Verkuil
  1 sibling, 0 replies; 69+ messages in thread
From: Hans Verkuil @ 2012-06-18 11:17 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Guennadi Liakhovetski, Pawel Osciak, Tomasz Stanislawski,
	Hans Verkuil

On Mon June 18 2012 11:46:57 Laurent Pinchart wrote:
> Hi Hans,
> 
> Thanks for the patch.
> 
> On Sunday 10 June 2012 12:25:40 Hans Verkuil wrote:
> > From: Hans Verkuil <hans.verkuil@cisco.com>
> > 
> > Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> > ---
> >  drivers/media/video/v4l2-ioctl.c |   35 +++++++++++++----------------------
> > 1 file changed, 13 insertions(+), 22 deletions(-)
> > 
> > diff --git a/drivers/media/video/v4l2-ioctl.c
> > b/drivers/media/video/v4l2-ioctl.c index 0de31c4..6c91674 100644
> > --- a/drivers/media/video/v4l2-ioctl.c
> > +++ b/drivers/media/video/v4l2-ioctl.c
> > @@ -870,6 +870,11 @@ static void v4l_print_newline(const void *arg)
> >  	pr_cont("\n");
> >  }
> > 
> > +static void v4l_print_default(const void *arg)
> > +{
> > +	pr_cont("non-standard ioctl\n");
> 
> I'd say "driver-specific ioctl" instead. "non-standard" may sound like an 
> error to users.

Much better, thank you!

Regards,

	Hans

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

* Re: [RFCv1 PATCH 04/32] v4l2-ioctl.c: v4l2-ioctl: add debug and callback/offset functionality.
  2012-06-18  9:47     ` Laurent Pinchart
@ 2012-06-18 11:25       ` Hans Verkuil
  0 siblings, 0 replies; 69+ messages in thread
From: Hans Verkuil @ 2012-06-18 11:25 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Guennadi Liakhovetski, Pawel Osciak, Tomasz Stanislawski,
	Hans Verkuil

On Mon June 18 2012 11:47:07 Laurent Pinchart wrote:
> Hi Hans,
> 
> Thanks for the patch.
> 
> On Sunday 10 June 2012 12:25:26 Hans Verkuil wrote:
> > From: Hans Verkuil <hans.verkuil@cisco.com>
> > 
> > Add the necessary plumbing to make it possible to replace the switch by a
> > table driven implementation.
> > 
> > Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> > ---
> >  drivers/media/video/v4l2-ioctl.c |   91
> > ++++++++++++++++++++++++++++++++------ 1 file changed, 78 insertions(+), 13
> > deletions(-)
> > 
> > diff --git a/drivers/media/video/v4l2-ioctl.c
> > b/drivers/media/video/v4l2-ioctl.c index a9602db..a4115ce 100644
> > --- a/drivers/media/video/v4l2-ioctl.c
> > +++ b/drivers/media/video/v4l2-ioctl.c
> > @@ -563,23 +595,40 @@ static long __video_do_ioctl(struct file *file,
> >  	}
> > 
> >  	if (v4l2_is_known_ioctl(cmd)) {
> > -		struct v4l2_ioctl_info *info = &v4l2_ioctls[_IOC_NR(cmd)];
> > +		info = &v4l2_ioctls[_IOC_NR(cmd)];
> > 
> >  	        if (!test_bit(_IOC_NR(cmd), vfd->valid_ioctls) &&
> >  		    !((info->flags & INFO_FL_CTRL) && vfh && vfh->ctrl_handler))
> > -			return -ENOTTY;
> > +			goto error;
> > 
> >  		if (use_fh_prio && (info->flags & INFO_FL_PRIO)) {
> >  			ret = v4l2_prio_check(vfd->prio, vfh->prio);
> >  			if (ret)
> > -				return ret;
> > +				goto error;
> >  		}
> > +	} else {
> > +		default_info.ioctl = cmd;
> > +		default_info.flags = 0;
> > +		default_info.debug = NULL;
> > +		info = &default_info;
> >  	}
> > 
> > -	if ((vfd->debug & V4L2_DEBUG_IOCTL) &&
> > -				!(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
> > +	write_only = _IOC_DIR(cmd) == _IOC_WRITE;
> > +	if (info->debug && write_only && vfd->debug > V4L2_DEBUG_IOCTL) {
> >  		v4l_print_ioctl(vfd->name, cmd);
> > -		printk(KERN_CONT "\n");
> > +		pr_cont(": ");
> > +		info->debug(arg);
> > +	}
> 
> Shouldn't you print the ioctl name and information even if info->debug is NULL 
> ?

The 'info->debug' test is temporary. Once the conversion is finished this test
will be removed since then info->debug will never be NULL.

> 
> > +	if (info->flags & INFO_FL_STD) {
> > +		typedef int (*vidioc_op)(struct file *file, void *fh, void *p);
> > +		const void *p = vfd->ioctl_ops;
> > +		const vidioc_op *vidioc = p + info->offset;
> > +
> > +		ret = (*vidioc)(file, fh, arg);
> > +		goto error;
> > +	} else if (info->flags & INFO_FL_FUNC) {
> > +		ret = info->func(ops, file, fh, arg);
> > +		goto error;
> >  	}
> > 
> >  	switch (cmd) {
> > @@ -2100,10 +2149,26 @@ static long __video_do_ioctl(struct file *file,
> >  		break;
> >  	} /* switch */
> > 
> > -	if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
> > -		if (ret < 0) {
> > -			v4l_print_ioctl(vfd->name, cmd);
> > -			printk(KERN_CONT " error %ld\n", ret);
> > +error:
> 
> This isn't an error, is it ? I'd call it done instead.

True, I'll change this.

> 
> > +	if (vfd->debug) {
> > +		if (write_only && vfd->debug > V4L2_DEBUG_IOCTL) {
> 
> vfd->debug is a bitmask (or at least is documented as being a bitmask in 
> include/media/v4l2-ioctl.h).

Yeah, and that makes no sense. Having V4L2_DEBUG_IOCTL_ARG without
V4L2_DEBUG_IOCTL is undefined. It is much more logical to have 0 for no
debugging, 1 for just ioctl name debugging and >= 2 for extensive debugging.
It's just weird to have to set the debug sysfs entry to 0, 1 or 3.

In a later patch I want to change the few drivers that use this accordingly.

> 
> > +			if (ret)
> 
> Shouldn't you test for < 0 instead ? Driver-specific ioctls might return a > 0 
> value in case of success.

Good catch. Yes, I need to do that.

> 
> > +				pr_info("%s: error %ld\n",
> > +					video_device_node_name(vfd), ret);
> > +			return ret;
> > +		}
> > +		v4l_print_ioctl(vfd->name, cmd);
> > +		if (ret)
> > +			pr_cont(": error %ld\n", ret);
> > +		else if (vfd->debug == V4L2_DEBUG_IOCTL)
> > +			pr_cont("\n");
> > +		else if (!info->debug)
> > +			return ret;
> > +		else if (_IOC_DIR(cmd) == _IOC_NONE)
> > +			info->debug(arg);
> > +		else {
> > +			pr_cont(": ");
> > +			info->debug(arg);
> >  		}
> 
> Ouch. What are you trying to do here ? Can't we simplify debug messages ?

It's simplified a bit in a later patch when the temporary info->debug test
can be dropped.

Regards,

	Hans

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

* Re: [RFCv1 PATCH 19/32] v4l2-dev.c: add debug sysfs entry.
  2012-06-18  9:48     ` Laurent Pinchart
@ 2012-06-18 11:30       ` Hans Verkuil
  2012-06-18 11:36         ` Laurent Pinchart
  0 siblings, 1 reply; 69+ messages in thread
From: Hans Verkuil @ 2012-06-18 11:30 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Guennadi Liakhovetski, Pawel Osciak, Tomasz Stanislawski,
	Hans Verkuil

On Mon June 18 2012 11:48:45 Laurent Pinchart wrote:
> Hi Hans,
> 
> Thanks for the patch.
> 
> On Sunday 10 June 2012 12:25:41 Hans Verkuil wrote:
> > From: Hans Verkuil <hans.verkuil@cisco.com>
> > 
> > Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> > ---
> >  drivers/media/video/v4l2-dev.c |   24 ++++++++++++++++++++++++
> >  1 file changed, 24 insertions(+)
> > 
> > diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c
> > index 1500208..5c0bb18 100644
> > --- a/drivers/media/video/v4l2-dev.c
> > +++ b/drivers/media/video/v4l2-dev.c
> > @@ -46,6 +46,29 @@ static ssize_t show_index(struct device *cd,
> >  	return sprintf(buf, "%i\n", vdev->index);
> >  }
> > 
> > +static ssize_t show_debug(struct device *cd,
> > +			 struct device_attribute *attr, char *buf)
> > +{
> > +	struct video_device *vdev = to_video_device(cd);
> > +
> > +	return sprintf(buf, "%i\n", vdev->debug);
> > +}
> > +
> > +static ssize_t set_debug(struct device *cd, struct device_attribute *attr,
> > +		   const char *buf, size_t len)
> > +{
> > +	struct video_device *vdev = to_video_device(cd);
> > +	int res = 0;
> > +	u16 value;
> > +
> > +	res = kstrtou16(buf, 0, &value);
> > +	if (res)
> > +		return res;
> > +
> > +	vdev->debug = value;
> 
> Can't this race with the various vdev->debug tests we have in the V4L core ?

Not really. You may have a short race where you set it, but some core test is
just reading it and gets the old value. But that's no problem in this case.
The worst that can happen is that you get one more or one less debug message
in the log.

It probably deserves a comment, though.

Regards,

	Hans

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

* Re: [RFCv1 PATCH 20/32] v4l2-ioctl: remove v4l_(i2c_)print_ioctl
  2012-06-18  9:50     ` Laurent Pinchart
@ 2012-06-18 11:33       ` Hans Verkuil
  0 siblings, 0 replies; 69+ messages in thread
From: Hans Verkuil @ 2012-06-18 11:33 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Guennadi Liakhovetski, Pawel Osciak, Tomasz Stanislawski,
	Hans Verkuil

On Mon June 18 2012 11:50:38 Laurent Pinchart wrote:
> Hi Hans,
> 
> Thanks for the patch.
> 
> On Sunday 10 June 2012 12:25:42 Hans Verkuil wrote:
> > From: Hans Verkuil <hans.verkuil@cisco.com>
> > 
> > v4l_i2c_print_ioctl wasn't used and v4l_print_ioctl could be replaced by
> > v4l_i2c_printk_ioctl.
> 
> I suppose you meant v4l_printk_ioctl herE.

Yes indeed.

Regards,

	Hans

> 
> > 
> > Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> 
> 

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

* Re: [RFCv1 PATCH 30/32] v4l2-ioctl.c: shorten the lines of the table.
  2012-06-18  9:57     ` Laurent Pinchart
@ 2012-06-18 11:34       ` Hans Verkuil
  2012-06-18 12:15         ` Laurent Pinchart
  0 siblings, 1 reply; 69+ messages in thread
From: Hans Verkuil @ 2012-06-18 11:34 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Guennadi Liakhovetski, Pawel Osciak, Tomasz Stanislawski,
	Hans Verkuil

On Mon June 18 2012 11:57:24 Laurent Pinchart wrote:
> Hi Hans,
> 
> Thanks for the patch.
> 
> On Sunday 10 June 2012 12:25:52 Hans Verkuil wrote:
> > From: Hans Verkuil <hans.verkuil@cisco.com>
> > 
> > Use some macro magic to reduce the length of the lines in the table. This
> > makes it more readable.
> 
> It indeed shortens the lines, but to be honest I find the result less 
> readable.

What do you think, should I just keep those long lines?

I've tried splitting them up, but that too made it harder to read.

Regards,

	Hans

> 
> > Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> 
> 

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

* Re: [RFCv1 PATCH 19/32] v4l2-dev.c: add debug sysfs entry.
  2012-06-18 11:30       ` Hans Verkuil
@ 2012-06-18 11:36         ` Laurent Pinchart
  0 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2012-06-18 11:36 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: linux-media, Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Guennadi Liakhovetski, Pawel Osciak, Tomasz Stanislawski,
	Hans Verkuil

Hi Hans,

On Monday 18 June 2012 13:30:18 Hans Verkuil wrote:
> On Mon June 18 2012 11:48:45 Laurent Pinchart wrote:
> > On Sunday 10 June 2012 12:25:41 Hans Verkuil wrote:
> > > From: Hans Verkuil <hans.verkuil@cisco.com>
> > > 
> > > Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> > > ---
> > > 
> > >  drivers/media/video/v4l2-dev.c |   24 ++++++++++++++++++++++++
> > >  1 file changed, 24 insertions(+)
> > > 
> > > diff --git a/drivers/media/video/v4l2-dev.c
> > > b/drivers/media/video/v4l2-dev.c index 1500208..5c0bb18 100644
> > > --- a/drivers/media/video/v4l2-dev.c
> > > +++ b/drivers/media/video/v4l2-dev.c
> > > @@ -46,6 +46,29 @@ static ssize_t show_index(struct device *cd,
> > > 
> > >  	return sprintf(buf, "%i\n", vdev->index);
> > >  
> > >  }
> > > 
> > > +static ssize_t show_debug(struct device *cd,
> > > +			 struct device_attribute *attr, char *buf)
> > > +{
> > > +	struct video_device *vdev = to_video_device(cd);
> > > +
> > > +	return sprintf(buf, "%i\n", vdev->debug);
> > > +}
> > > +
> > > +static ssize_t set_debug(struct device *cd, struct device_attribute
> > > *attr,
> > > +		   const char *buf, size_t len)
> > > +{
> > > +	struct video_device *vdev = to_video_device(cd);
> > > +	int res = 0;
> > > +	u16 value;
> > > +
> > > +	res = kstrtou16(buf, 0, &value);
> > > +	if (res)
> > > +		return res;
> > > +
> > > +	vdev->debug = value;
> > 
> > Can't this race with the various vdev->debug tests we have in the V4L core
> > ?
> Not really. You may have a short race where you set it, but some core test
> is just reading it and gets the old value. But that's no problem in this
> case. The worst that can happen is that you get one more or one less debug
> message in the log.

You test the debug value several times in the __video_do_ioctl() function. I 
haven't checked in details whether changing the value between the two tests 
could for instance lead to a KERN_CONT print without a previous non-KERN_CONT 
message. That won't crash the machine :-) but it should still be avoided.

> It probably deserves a comment, though.

-- 
Regards,

Laurent Pinchart


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

* Re: [RFCv1 PATCH 29/32] v4l2-dev.c: also add debug support for the fops.
  2012-06-18 10:01     ` Laurent Pinchart
@ 2012-06-18 11:40       ` Hans Verkuil
  2012-06-18 12:19         ` Laurent Pinchart
  0 siblings, 1 reply; 69+ messages in thread
From: Hans Verkuil @ 2012-06-18 11:40 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Guennadi Liakhovetski, Pawel Osciak, Tomasz Stanislawski,
	Hans Verkuil

On Mon June 18 2012 12:01:47 Laurent Pinchart wrote:
> Hi Hans,
> 
> Thanks for the patch.
> 
> On Sunday 10 June 2012 12:25:51 Hans Verkuil wrote:
> > From: Hans Verkuil <hans.verkuil@cisco.com>
> > 
> > Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> > ---
> >  drivers/media/video/v4l2-dev.c |   41 ++++++++++++++++++++++++++-----------
> >  1 file changed, 29 insertions(+), 12 deletions(-)
> > 
> > diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c
> > index 5c0bb18..54f387d 100644
> > --- a/drivers/media/video/v4l2-dev.c
> > +++ b/drivers/media/video/v4l2-dev.c
> > @@ -305,6 +305,9 @@ static ssize_t v4l2_read(struct file *filp, char __user
> > *buf, ret = vdev->fops->read(filp, buf, sz, off);
> >  	if (test_bit(V4L2_FL_LOCK_ALL_FOPS, &vdev->flags))
> >  		mutex_unlock(vdev->lock);
> > +	if (vdev->debug)
> 
> As vdev->debug is a bitmask, shouldn't we add an fops debug bit ?

I actually want to move away from the bitmask idea. I've never really liked
it here.

> 
> > +		pr_info("%s: read: %zd (%d)\n",
> > +			video_device_node_name(vdev), sz, ret);
> 
> Shouldn't we use KERN_DEBUG instead of KERN_INFO ? BTW, what about replacing 
> the pr_* calls with dev_* calls ?

KERN_DEBUG vs KERN_INFO is actually a good question. My reasoning is that you
explicitly enable logging, and so you really want to see it in the log, so we
use KERN_INFO. With KERN_DEBUG you might have the situation where the debug
level of the logging is disabled, so the messages are ignored.

However, if people disagree with this, then I'm happy to move it back to
KERN_DEBUG.

With regards to dev_ vs pr_: I'd have to test this to see what dev_ prints as
prefix.

Regards,

	Hans

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

* Re: [RFCv1 PATCH 28/32] vivi: use vb2 helper functions.
  2012-06-18 10:08     ` Laurent Pinchart
@ 2012-06-18 11:40       ` Hans Verkuil
  0 siblings, 0 replies; 69+ messages in thread
From: Hans Verkuil @ 2012-06-18 11:40 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Guennadi Liakhovetski, Pawel Osciak, Tomasz Stanislawski,
	Hans Verkuil

On Mon June 18 2012 12:08:10 Laurent Pinchart wrote:
> Hi Hans,
> 
> Thanks for the patch.
> 
> On Sunday 10 June 2012 12:25:50 Hans Verkuil wrote:
> > From: Hans Verkuil <hans.verkuil@cisco.com>
> > 
> > Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> > ---
> >  drivers/media/video/vivi.c |  160 ++++++-----------------------------------
> >  1 file changed, 21 insertions(+), 139 deletions(-)
> > 
> > diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c
> > index 1e4da5e..1e8c4f3 100644
> > --- a/drivers/media/video/vivi.c
> > +++ b/drivers/media/video/vivi.c
> > @@ -767,7 +767,13 @@ static int queue_setup(struct vb2_queue *vq, const
> > struct v4l2_format *fmt, struct vivi_dev *dev = vb2_get_drv_priv(vq);
> >  	unsigned long size;
> > 
> > -	size = dev->width * dev->height * dev->pixelsize;
> > +	if (fmt)
> > +		size = fmt->fmt.pix.sizeimage;
> > +	else
> > +		size = dev->width * dev->height * dev->pixelsize;
> > +
> > +	if (size == 0)
> > +		return -EINVAL;
> 
> If I'm not mistaken, this is a bug fix to properly support CREATE_BUF, right ? 
> If so it should be split to its own patch.

OK.

	Hans

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

* Re: [RFCv1 PATCH 25/32] create_bufs: handle count == 0.
  2012-06-18 10:11     ` Laurent Pinchart
@ 2012-06-18 11:43       ` Hans Verkuil
  2012-06-18 12:20         ` Laurent Pinchart
  0 siblings, 1 reply; 69+ messages in thread
From: Hans Verkuil @ 2012-06-18 11:43 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Guennadi Liakhovetski, Pawel Osciak, Tomasz Stanislawski,
	Hans Verkuil

On Mon June 18 2012 12:11:27 Laurent Pinchart wrote:
> Hi Hans,
> 
> Thanks for the patch.
> 
> On Sunday 10 June 2012 12:25:47 Hans Verkuil wrote:
> > From: Hans Verkuil <hans.verkuil@cisco.com>
> > 
> > Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> > ---
> >  Documentation/DocBook/media/v4l/vidioc-create-bufs.xml |    8 +++++++-
> >  1 file changed, 7 insertions(+), 1 deletion(-)
> > 
> > diff --git a/Documentation/DocBook/media/v4l/vidioc-create-bufs.xml
> > b/Documentation/DocBook/media/v4l/vidioc-create-bufs.xml index
> > 765549f..afdba4d 100644
> > --- a/Documentation/DocBook/media/v4l/vidioc-create-bufs.xml
> > +++ b/Documentation/DocBook/media/v4l/vidioc-create-bufs.xml
> > @@ -97,7 +97,13 @@ information.</para>
> >  	  <row>
> >  	    <entry>__u32</entry>
> >  	    <entry><structfield>count</structfield></entry>
> > -	    <entry>The number of buffers requested or granted.</entry>
> > +	    <entry>The number of buffers requested or granted. If count == 0,
> > then
> > +	    <constant>VIDIOC_CREATE_BUFS</constant> will set
> > <structfield>index</structfield>
> > +	    to the starting buffer index,
> 
> I find "starting buffer index" a bit unclear in this context, as we don't 
> create any buffer.

How about:

... will set index to the current number of created buffers,

Better alternatives welcome :-)

	Hans

> 
> > and it will check the validity of
> > +	    <structfield>memory</structfield> and
> > <structfield>format.type</structfield>.
> > +	    If those are invalid -1 is returned and errno is set to &EINVAL;,
> > +	    otherwise <constant>VIDIOC_CREATE_BUFS</constant> returns 0. It will
> > +	    never set errno to &EBUSY; in this particular case.</entry>
> >  	  </row>
> >  	  <row>
> >  	    <entry>__u32</entry>
> 

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

* Re: [RFCv1 PATCH 27/32] vivi: embed struct video_device instead of allocating it.
  2012-06-18 10:13     ` Laurent Pinchart
@ 2012-06-18 11:44       ` Hans Verkuil
  0 siblings, 0 replies; 69+ messages in thread
From: Hans Verkuil @ 2012-06-18 11:44 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Guennadi Liakhovetski, Pawel Osciak, Tomasz Stanislawski,
	Hans Verkuil

On Mon June 18 2012 12:13:38 Laurent Pinchart wrote:
> Hi Hans,
> 
> Thanks for the patch.
> 
> On Sunday 10 June 2012 12:25:49 Hans Verkuil wrote:
> > From: Hans Verkuil <hans.verkuil@cisco.com>
> > 
> > Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> > ---
> >  drivers/media/video/vivi.c |   25 +++++++------------------
> >  1 file changed, 7 insertions(+), 18 deletions(-)
> > 
> > diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c
> > index 8dd5ae6..1e4da5e 100644
> > --- a/drivers/media/video/vivi.c
> > +++ b/drivers/media/video/vivi.c
> 
> [snip]
> 
> > @@ -1080,7 +1078,6 @@ static int vidioc_enum_input(struct file *file, void
> > *priv, return -EINVAL;
> > 
> >  	inp->type = V4L2_INPUT_TYPE_CAMERA;
> > -	inp->std = V4L2_STD_525_60;
> 
> Doesn't this belong to the previous patch ?

Indeed.

	Hans

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

* Re: [RFCv1 PATCH 24/32] videobuf2-core: add helper functions.
  2012-06-18 10:23     ` Laurent Pinchart
@ 2012-06-18 11:49       ` Hans Verkuil
  0 siblings, 0 replies; 69+ messages in thread
From: Hans Verkuil @ 2012-06-18 11:49 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Guennadi Liakhovetski, Pawel Osciak, Tomasz Stanislawski,
	Hans Verkuil

On Mon June 18 2012 12:23:26 Laurent Pinchart wrote:
> Hi Hans,
> 
> Thanks for the patch.
> 
> On Sunday 10 June 2012 12:25:46 Hans Verkuil wrote:
> > From: Hans Verkuil <hans.verkuil@cisco.com>
> > 
> > Add helper functions to make it easier to adapt drivers to vb2.
> 
> What about moving those functions to videobuf2-ioctl.c ? The helper functions 
> are based on top of an existing vb2 core that isn't aware of queue ownership. 
> It's not clear (to me at least) how the helpers will evolve and whether they 
> will be used by all drivers or not, or whether part of what they do will get 
> merged into the vb2 core. Splitting the helpers in a separate file would help 
> not mixing code too much without really thinking about it.

Sounds reasonable. One thing that I want to think about when preparing RFCv2 is
whether the new queue_lock in video_device shouldn't be moved to vb2_queue
instead, since it is a per-vb2_queue lock. I need to check whether that still
makes it possible to split it up like you suggest. It almost certainly will make
sense to do this.

> 
> > These helpers take care of core locking and check if the filehandle is the
> > owner of the queue.
> > 
> > This patch also adds support for count == 0 in create_bufs.
> 
> Could you please split that to its own patch ? The addition of 
> __verify_memory_type() should be split as well.

OK.

Regards,

	Hans

> 
> > Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> 
> 

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

* Re: [RFCv1 PATCH 18/32] v4l2-ioctl.c: finalize table conversion.
  2012-06-18 10:50       ` Mauro Carvalho Chehab
  2012-06-18 11:03         ` Laurent Pinchart
@ 2012-06-18 11:49         ` Hans Verkuil
  2012-06-18 12:03           ` Mauro Carvalho Chehab
  1 sibling, 1 reply; 69+ messages in thread
From: Hans Verkuil @ 2012-06-18 11:49 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Laurent Pinchart, linux-media, Mauro Carvalho Chehab,
	Hans de Goede, Andy Walls, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

On Mon June 18 2012 12:50:35 Mauro Carvalho Chehab wrote:
> Em 18-06-2012 06:46, Laurent Pinchart escreveu:
> > Hi Hans,
> > 
> > Thanks for the patch.
> > 
> > On Sunday 10 June 2012 12:25:40 Hans Verkuil wrote:
> >> From: Hans Verkuil <hans.verkuil@cisco.com>
> >>
> >> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> >> ---
> >>   drivers/media/video/v4l2-ioctl.c |   35 +++++++++++++----------------------
> >> 1 file changed, 13 insertions(+), 22 deletions(-)
> >>
> >> diff --git a/drivers/media/video/v4l2-ioctl.c
> >> b/drivers/media/video/v4l2-ioctl.c index 0de31c4..6c91674 100644
> >> --- a/drivers/media/video/v4l2-ioctl.c
> >> +++ b/drivers/media/video/v4l2-ioctl.c
> >> @@ -870,6 +870,11 @@ static void v4l_print_newline(const void *arg)
> >>   	pr_cont("\n");
> >>   }
> >>
> >> +static void v4l_print_default(const void *arg)
> >> +{
> >> +	pr_cont("non-standard ioctl\n");
> > 
> > I'd say "driver-specific ioctl" instead. "non-standard" may sound like an
> > error to users.
> 
> This message is useless as-is, as it provides no glue about what ioctl was
> called. You should either remove it or print the ioctl number, in hexa.

That ioctl number is already printed in front of this message.

Regards,

	Hans

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

* Re: [RFCv1 PATCH 18/32] v4l2-ioctl.c: finalize table conversion.
  2012-06-18 11:49         ` Hans Verkuil
@ 2012-06-18 12:03           ` Mauro Carvalho Chehab
  2012-06-18 12:22             ` Hans Verkuil
  0 siblings, 1 reply; 69+ messages in thread
From: Mauro Carvalho Chehab @ 2012-06-18 12:03 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: Laurent Pinchart, linux-media, Mauro Carvalho Chehab,
	Hans de Goede, Andy Walls, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

Em 18-06-2012 08:49, Hans Verkuil escreveu:
> On Mon June 18 2012 12:50:35 Mauro Carvalho Chehab wrote:
>> Em 18-06-2012 06:46, Laurent Pinchart escreveu:
>>> Hi Hans,
>>>
>>> Thanks for the patch.
>>>
>>> On Sunday 10 June 2012 12:25:40 Hans Verkuil wrote:
>>>> From: Hans Verkuil <hans.verkuil@cisco.com>
>>>>
>>>> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
>>>> ---
>>>>    drivers/media/video/v4l2-ioctl.c |   35 +++++++++++++----------------------
>>>> 1 file changed, 13 insertions(+), 22 deletions(-)
>>>>
>>>> diff --git a/drivers/media/video/v4l2-ioctl.c
>>>> b/drivers/media/video/v4l2-ioctl.c index 0de31c4..6c91674 100644
>>>> --- a/drivers/media/video/v4l2-ioctl.c
>>>> +++ b/drivers/media/video/v4l2-ioctl.c
>>>> @@ -870,6 +870,11 @@ static void v4l_print_newline(const void *arg)
>>>>    	pr_cont("\n");
>>>>    }
>>>>
>>>> +static void v4l_print_default(const void *arg)
>>>> +{
>>>> +	pr_cont("non-standard ioctl\n");
>>>
>>> I'd say "driver-specific ioctl" instead. "non-standard" may sound like an
>>> error to users.
>>
>> This message is useless as-is, as it provides no glue about what ioctl was
>> called. You should either remove it or print the ioctl number, in hexa.
> 
> That ioctl number is already printed in front of this message.

Hmm... should we print it when the ioctl is known? IMHO, the behavior should be to
either print the ioctl name or its number, as those debug messages are generally big.
So, better to not pollute it with duplicated information.
> 
> Regards,
> 
> 	Hans
> 



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

* Re: [RFCv1 PATCH 30/32] v4l2-ioctl.c: shorten the lines of the table.
  2012-06-18 11:34       ` Hans Verkuil
@ 2012-06-18 12:15         ` Laurent Pinchart
  0 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2012-06-18 12:15 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: linux-media, Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Guennadi Liakhovetski, Pawel Osciak, Tomasz Stanislawski,
	Hans Verkuil

Hi Hans,

On Monday 18 June 2012 13:34:33 Hans Verkuil wrote:
> On Mon June 18 2012 11:57:24 Laurent Pinchart wrote:
> > On Sunday 10 June 2012 12:25:52 Hans Verkuil wrote:
> > > From: Hans Verkuil <hans.verkuil@cisco.com>
> > > 
> > > Use some macro magic to reduce the length of the lines in the table.
> > > This makes it more readable.
> > 
> > It indeed shortens the lines, but to be honest I find the result less
> > readable.
> 
> What do you think, should I just keep those long lines?

I think that's better. If several fields could be computed from the same 
information in all cases then I'd be fine with specifying the common 
information only, but just shortening names makes the code less readable in my 
opinion. 

> I've tried splitting them up, but that too made it harder to read.

-- 
Regards,

Laurent Pinchart


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

* Re: [RFCv1 PATCH 29/32] v4l2-dev.c: also add debug support for the fops.
  2012-06-18 11:40       ` Hans Verkuil
@ 2012-06-18 12:19         ` Laurent Pinchart
  2012-06-18 12:48           ` Hans Verkuil
  0 siblings, 1 reply; 69+ messages in thread
From: Laurent Pinchart @ 2012-06-18 12:19 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: linux-media, Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Guennadi Liakhovetski, Pawel Osciak, Tomasz Stanislawski,
	Hans Verkuil

Hi Hans,

On Monday 18 June 2012 13:40:24 Hans Verkuil wrote:
> On Mon June 18 2012 12:01:47 Laurent Pinchart wrote:
> > On Sunday 10 June 2012 12:25:51 Hans Verkuil wrote:
> > > From: Hans Verkuil <hans.verkuil@cisco.com>
> > > 
> > > Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> > > ---
> > > 
> > >  drivers/media/video/v4l2-dev.c |   41 ++++++++++++++++++++++-----------
> > >  1 file changed, 29 insertions(+), 12 deletions(-)
> > > 
> > > diff --git a/drivers/media/video/v4l2-dev.c
> > > b/drivers/media/video/v4l2-dev.c index 5c0bb18..54f387d 100644
> > > --- a/drivers/media/video/v4l2-dev.c
> > > +++ b/drivers/media/video/v4l2-dev.c
> > > @@ -305,6 +305,9 @@ static ssize_t v4l2_read(struct file *filp, char
> > > __user
> > > *buf, ret = vdev->fops->read(filp, buf, sz, off);
> > > 
> > >  	if (test_bit(V4L2_FL_LOCK_ALL_FOPS, &vdev->flags))
> > >  	
> > >  		mutex_unlock(vdev->lock);
> > > 
> > > +	if (vdev->debug)
> > 
> > As vdev->debug is a bitmask, shouldn't we add an fops debug bit ?
> 
> I actually want to move away from the bitmask idea. I've never really liked
> it here.

Would using dev_dbg with dynamic printk instead of creating our own logging 
system be an option ?

> > > +		pr_info("%s: read: %zd (%d)\n",
> > > +			video_device_node_name(vdev), sz, ret);
> > 
> > Shouldn't we use KERN_DEBUG instead of KERN_INFO ? BTW, what about
> > replacing the pr_* calls with dev_* calls ?
> 
> KERN_DEBUG vs KERN_INFO is actually a good question. My reasoning is that
> you explicitly enable logging, and so you really want to see it in the log,
> so we use KERN_INFO. With KERN_DEBUG you might have the situation where the
> debug level of the logging is disabled, so the messages are ignored.
> 
> However, if people disagree with this, then I'm happy to move it back to
> KERN_DEBUG.

On embedded systems KERN_INFO will be printed to the serial console. 
Interleaving kernel messages with application output during capture result in 
a mess.

If someone enables debugging I expect him/her to know enough to get the kernel 
log debug messages.

> With regards to dev_ vs pr_: I'd have to test this to see what dev_ prints
> as prefix.

-- 
Regards,

Laurent Pinchart


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

* Re: [RFCv1 PATCH 25/32] create_bufs: handle count == 0.
  2012-06-18 11:43       ` Hans Verkuil
@ 2012-06-18 12:20         ` Laurent Pinchart
  0 siblings, 0 replies; 69+ messages in thread
From: Laurent Pinchart @ 2012-06-18 12:20 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: linux-media, Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Guennadi Liakhovetski, Pawel Osciak, Tomasz Stanislawski,
	Hans Verkuil

Hi Hans,

On Monday 18 June 2012 13:43:22 Hans Verkuil wrote:
> On Mon June 18 2012 12:11:27 Laurent Pinchart wrote:
> > On Sunday 10 June 2012 12:25:47 Hans Verkuil wrote:
> > > From: Hans Verkuil <hans.verkuil@cisco.com>
> > > 
> > > Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> > > ---
> > > 
> > >  Documentation/DocBook/media/v4l/vidioc-create-bufs.xml |    8 +++++++-
> > >  1 file changed, 7 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/Documentation/DocBook/media/v4l/vidioc-create-bufs.xml
> > > b/Documentation/DocBook/media/v4l/vidioc-create-bufs.xml index
> > > 765549f..afdba4d 100644
> > > --- a/Documentation/DocBook/media/v4l/vidioc-create-bufs.xml
> > > +++ b/Documentation/DocBook/media/v4l/vidioc-create-bufs.xml
> > > @@ -97,7 +97,13 @@ information.</para>
> > > 
> > >  	  <row>
> > >  	  
> > >  	    <entry>__u32</entry>
> > >  	    <entry><structfield>count</structfield></entry>
> > > 
> > > -	    <entry>The number of buffers requested or granted.</entry>
> > > +	    <entry>The number of buffers requested or granted. If count == 0,
> > > then
> > > +	    <constant>VIDIOC_CREATE_BUFS</constant> will set
> > > <structfield>index</structfield>
> > > +	    to the starting buffer index,
> > 
> > I find "starting buffer index" a bit unclear in this context, as we don't
> > create any buffer.
> 
> How about:
> 
> ... will set index to the current number of created buffers,

Sounds good to me for now (but it won't be true anymore when we'll support 
deleting buffers individually).

> Better alternatives welcome :-)

-- 
Regards,

Laurent Pinchart


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

* Re: [RFCv1 PATCH 18/32] v4l2-ioctl.c: finalize table conversion.
  2012-06-18 12:03           ` Mauro Carvalho Chehab
@ 2012-06-18 12:22             ` Hans Verkuil
  0 siblings, 0 replies; 69+ messages in thread
From: Hans Verkuil @ 2012-06-18 12:22 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Laurent Pinchart, linux-media, Mauro Carvalho Chehab,
	Hans de Goede, Andy Walls, Guennadi Liakhovetski, Pawel Osciak,
	Tomasz Stanislawski, Hans Verkuil

On Mon June 18 2012 14:03:14 Mauro Carvalho Chehab wrote:
> Em 18-06-2012 08:49, Hans Verkuil escreveu:
> > On Mon June 18 2012 12:50:35 Mauro Carvalho Chehab wrote:
> >> Em 18-06-2012 06:46, Laurent Pinchart escreveu:
> >>> Hi Hans,
> >>>
> >>> Thanks for the patch.
> >>>
> >>> On Sunday 10 June 2012 12:25:40 Hans Verkuil wrote:
> >>>> From: Hans Verkuil <hans.verkuil@cisco.com>
> >>>>
> >>>> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> >>>> ---
> >>>>    drivers/media/video/v4l2-ioctl.c |   35 +++++++++++++----------------------
> >>>> 1 file changed, 13 insertions(+), 22 deletions(-)
> >>>>
> >>>> diff --git a/drivers/media/video/v4l2-ioctl.c
> >>>> b/drivers/media/video/v4l2-ioctl.c index 0de31c4..6c91674 100644
> >>>> --- a/drivers/media/video/v4l2-ioctl.c
> >>>> +++ b/drivers/media/video/v4l2-ioctl.c
> >>>> @@ -870,6 +870,11 @@ static void v4l_print_newline(const void *arg)
> >>>>    	pr_cont("\n");
> >>>>    }
> >>>>
> >>>> +static void v4l_print_default(const void *arg)
> >>>> +{
> >>>> +	pr_cont("non-standard ioctl\n");
> >>>
> >>> I'd say "driver-specific ioctl" instead. "non-standard" may sound like an
> >>> error to users.
> >>
> >> This message is useless as-is, as it provides no glue about what ioctl was
> >> called. You should either remove it or print the ioctl number, in hexa.
> > 
> > That ioctl number is already printed in front of this message.
> 
> Hmm... should we print it when the ioctl is known? IMHO, the behavior should be to
> either print the ioctl name or its number, as those debug messages are generally big.
> So, better to not pollute it with duplicated information.

If it's known, then the name is printed. If it is unknown, then the ioctl number is
printed. That code hasn't changed at all.

Regards,

	Hans

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

* Re: [RFCv1 PATCH 29/32] v4l2-dev.c: also add debug support for the fops.
  2012-06-18 12:19         ` Laurent Pinchart
@ 2012-06-18 12:48           ` Hans Verkuil
  0 siblings, 0 replies; 69+ messages in thread
From: Hans Verkuil @ 2012-06-18 12:48 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: linux-media, Mauro Carvalho Chehab, Hans de Goede, Andy Walls,
	Guennadi Liakhovetski, Pawel Osciak, Tomasz Stanislawski,
	Hans Verkuil

On Mon June 18 2012 14:19:51 Laurent Pinchart wrote:
> Hi Hans,
> 
> On Monday 18 June 2012 13:40:24 Hans Verkuil wrote:
> > On Mon June 18 2012 12:01:47 Laurent Pinchart wrote:
> > > On Sunday 10 June 2012 12:25:51 Hans Verkuil wrote:
> > > > From: Hans Verkuil <hans.verkuil@cisco.com>
> > > > 
> > > > Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> > > > ---
> > > > 
> > > >  drivers/media/video/v4l2-dev.c |   41 ++++++++++++++++++++++-----------
> > > >  1 file changed, 29 insertions(+), 12 deletions(-)
> > > > 
> > > > diff --git a/drivers/media/video/v4l2-dev.c
> > > > b/drivers/media/video/v4l2-dev.c index 5c0bb18..54f387d 100644
> > > > --- a/drivers/media/video/v4l2-dev.c
> > > > +++ b/drivers/media/video/v4l2-dev.c
> > > > @@ -305,6 +305,9 @@ static ssize_t v4l2_read(struct file *filp, char
> > > > __user
> > > > *buf, ret = vdev->fops->read(filp, buf, sz, off);
> > > > 
> > > >  	if (test_bit(V4L2_FL_LOCK_ALL_FOPS, &vdev->flags))
> > > >  	
> > > >  		mutex_unlock(vdev->lock);
> > > > 
> > > > +	if (vdev->debug)
> > > 
> > > As vdev->debug is a bitmask, shouldn't we add an fops debug bit ?
> > 
> > I actually want to move away from the bitmask idea. I've never really liked
> > it here.
> 
> Would using dev_dbg with dynamic printk instead of creating our own logging 
> system be an option ?

I don't think so. There are lots of printk message you'd all have to enable.
You just want to have a standard method of debugging which ioctls are called
that anyone can use and that's consistent for all v4l drivers.

This does just that.

> 
> > > > +		pr_info("%s: read: %zd (%d)\n",
> > > > +			video_device_node_name(vdev), sz, ret);
> > > 
> > > Shouldn't we use KERN_DEBUG instead of KERN_INFO ? BTW, what about
> > > replacing the pr_* calls with dev_* calls ?
> > 
> > KERN_DEBUG vs KERN_INFO is actually a good question. My reasoning is that
> > you explicitly enable logging, and so you really want to see it in the log,
> > so we use KERN_INFO. With KERN_DEBUG you might have the situation where the
> > debug level of the logging is disabled, so the messages are ignored.
> > 
> > However, if people disagree with this, then I'm happy to move it back to
> > KERN_DEBUG.
> 
> On embedded systems KERN_INFO will be printed to the serial console. 
> Interleaving kernel messages with application output during capture result in 
> a mess.
> 
> If someone enables debugging I expect him/her to know enough to get the kernel 
> log debug messages.

OK, I'll change this back to KERN_DEBUG. Good argument.

Regards,

	Hans

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

end of thread, other threads:[~2012-06-18 12:49 UTC | newest]

Thread overview: 69+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-10 10:25 [RFCv1 PATCH 00/32] Core and vb2 enhancements Hans Verkuil
2012-06-10 10:25 ` [RFCv1 PATCH 01/32] Regression fixes Hans Verkuil
2012-06-10 10:25   ` [RFCv1 PATCH 02/32] v4l2-ioctl.c: move a block of code down, no other changes Hans Verkuil
2012-06-10 10:25   ` [RFCv1 PATCH 03/32] v4l2-ioctl.c: introduce INFO_FL_CLEAR to replace switch Hans Verkuil
2012-06-10 10:25   ` [RFCv1 PATCH 04/32] v4l2-ioctl.c: v4l2-ioctl: add debug and callback/offset functionality Hans Verkuil
2012-06-18  9:47     ` Laurent Pinchart
2012-06-18 11:25       ` Hans Verkuil
2012-06-10 10:25   ` [RFCv1 PATCH 05/32] v4l2-ioctl.c: remove an unnecessary #ifdef Hans Verkuil
2012-06-10 10:25   ` [RFCv1 PATCH 06/32] v4l2-ioctl.c: use the new table for querycap and i/o ioctls Hans Verkuil
2012-06-10 10:25   ` [RFCv1 PATCH 07/32] v4l2-ioctl.c: use the new table for priority ioctls Hans Verkuil
2012-06-10 10:25   ` [RFCv1 PATCH 08/32] v4l2-ioctl.c: use the new table for format/framebuffer ioctls Hans Verkuil
2012-06-10 10:25   ` [RFCv1 PATCH 09/32] v4l2-ioctl.c: use the new table for overlay/streamon/off ioctls Hans Verkuil
2012-06-10 10:25   ` [RFCv1 PATCH 10/32] v4l2-ioctl.c: use the new table for std/tuner/modulator ioctls Hans Verkuil
2012-06-10 10:25   ` [RFCv1 PATCH 11/32] v4l2-ioctl.c: use the new table for queuing/parm ioctls Hans Verkuil
2012-06-10 10:25   ` [RFCv1 PATCH 12/32] v4l2-ioctl.c: use the new table for control ioctls Hans Verkuil
2012-06-10 10:25   ` [RFCv1 PATCH 13/32] v4l2-ioctl.c: use the new table for selection ioctls Hans Verkuil
2012-06-10 10:25   ` [RFCv1 PATCH 14/32] v4l2-ioctl.c: use the new table for compression ioctls Hans Verkuil
2012-06-10 10:25   ` [RFCv1 PATCH 15/32] v4l2-ioctl.c: use the new table for debug ioctls Hans Verkuil
2012-06-10 10:25   ` [RFCv1 PATCH 16/32] v4l2-ioctl.c: use the new table for preset/timings ioctls Hans Verkuil
2012-06-10 10:25   ` [RFCv1 PATCH 17/32] v4l2-ioctl.c: use the new table for the remaining ioctls Hans Verkuil
2012-06-10 10:25   ` [RFCv1 PATCH 18/32] v4l2-ioctl.c: finalize table conversion Hans Verkuil
2012-06-18  9:46     ` Laurent Pinchart
2012-06-18 10:50       ` Mauro Carvalho Chehab
2012-06-18 11:03         ` Laurent Pinchart
2012-06-18 11:49         ` Hans Verkuil
2012-06-18 12:03           ` Mauro Carvalho Chehab
2012-06-18 12:22             ` Hans Verkuil
2012-06-18 11:17       ` Hans Verkuil
2012-06-10 10:25   ` [RFCv1 PATCH 19/32] v4l2-dev.c: add debug sysfs entry Hans Verkuil
2012-06-18  9:48     ` Laurent Pinchart
2012-06-18 11:30       ` Hans Verkuil
2012-06-18 11:36         ` Laurent Pinchart
2012-06-10 10:25   ` [RFCv1 PATCH 20/32] v4l2-ioctl: remove v4l_(i2c_)print_ioctl Hans Verkuil
2012-06-18  9:50     ` Laurent Pinchart
2012-06-18 11:33       ` Hans Verkuil
2012-06-10 10:25   ` [RFCv1 PATCH 21/32] ivtv: don't mess with vfd->debug Hans Verkuil
2012-06-10 10:25   ` [RFCv1 PATCH 22/32] cx18: " Hans Verkuil
2012-06-10 10:25   ` [RFCv1 PATCH 23/32] v4l2-dev/ioctl.c: add vb2_queue support to video_device Hans Verkuil
2012-06-10 10:25   ` [RFCv1 PATCH 24/32] videobuf2-core: add helper functions Hans Verkuil
2012-06-18 10:23     ` Laurent Pinchart
2012-06-18 11:49       ` Hans Verkuil
2012-06-10 10:25   ` [RFCv1 PATCH 25/32] create_bufs: handle count == 0 Hans Verkuil
2012-06-18 10:11     ` Laurent Pinchart
2012-06-18 11:43       ` Hans Verkuil
2012-06-18 12:20         ` Laurent Pinchart
2012-06-10 10:25   ` [RFCv1 PATCH 26/32] vivi: remove pointless g/s_std support Hans Verkuil
2012-06-10 10:25   ` [RFCv1 PATCH 27/32] vivi: embed struct video_device instead of allocating it Hans Verkuil
2012-06-18 10:13     ` Laurent Pinchart
2012-06-18 11:44       ` Hans Verkuil
2012-06-10 10:25   ` [RFCv1 PATCH 28/32] vivi: use vb2 helper functions Hans Verkuil
2012-06-18 10:08     ` Laurent Pinchart
2012-06-18 11:40       ` Hans Verkuil
2012-06-10 10:25   ` [RFCv1 PATCH 29/32] v4l2-dev.c: also add debug support for the fops Hans Verkuil
2012-06-18 10:01     ` Laurent Pinchart
2012-06-18 11:40       ` Hans Verkuil
2012-06-18 12:19         ` Laurent Pinchart
2012-06-18 12:48           ` Hans Verkuil
2012-06-10 10:25   ` [RFCv1 PATCH 30/32] v4l2-ioctl.c: shorten the lines of the table Hans Verkuil
2012-06-18  9:57     ` Laurent Pinchart
2012-06-18 11:34       ` Hans Verkuil
2012-06-18 12:15         ` Laurent Pinchart
2012-06-10 10:25   ` [RFCv1 PATCH 31/32] pwc: use the new vb2 helpers Hans Verkuil
2012-06-10 10:25   ` [RFCv1 PATCH 32/32] pwc: v4l2-compliance fixes Hans Verkuil
2012-06-10 16:46 ` [RFCv1 PATCH 00/32] Core and vb2 enhancements Mauro Carvalho Chehab
2012-06-10 17:32   ` Hans Verkuil
2012-06-10 19:27     ` Hans Verkuil
2012-06-12 11:35       ` Mauro Carvalho Chehab
2012-06-12 13:21         ` Hans Verkuil
2012-06-12 13:24         ` Hans de Goede

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.