Problem with PCTV Systems nanoStick T2 290e and frontends

2014-02-25 Thread Peter Fassberg


Hi!

I have an PCTV Systems nanoStick T2 290e.

It shows up very differently with different kernels, and it seems to work 
better (DVB-C support) in an OLDER kernel.

Old kernel is using em28xx and showing two frontends (as stated on the wiki 
docs). New kernel is using em28174 and showing only a DVB-T frontend.

Is there a way to force the new kernel to use em28xx instead?


Excerpt from log:

Using Linux debian 3.2.0-4-amd64 #1 SMP Debian 3.2.54-2 x86_64 GNU/Linux:

[   90.006701] em28xx: New device PCTV Systems PCTV 290e @ 480 Mbps (2013:024f, 
interface 0, class 0)
[   90.007281] em28xx #0: chip ID is em28174
[   90.333600] em28xx #0: Identified as PCTV nanoStick T2 290e (card=78)
[   90.377066] em28xx #0: v4l2 driver version 0.1.3
[   90.447548] em28xx #0: V4L2 video device registered as video0
[   90.447584] usbcore: registered new interface driver em28xx
[   90.447586] em28xx driver loaded
[   90.520717] tda18271 0-0060: creating new instance
[   90.551187] TDA18271HD/C2 detected @ 0-0060
[   91.341140] tda18271 0-0060: attaching existing instance
[   91.341145] DVB: registering new adapter (em28xx #0)
[   91.341150] DVB: registering adapter 0 frontend 0 (Sony CXD2820R 
(DVB-T/T2))...
[   91.342477] DVB: registering adapter 0 frontend 1 (Sony CXD2820R (DVB-C))...
[   91.345700] em28xx #0: Successfully loaded em28xx-dvb
[   91.345706] Em28xx: Initialized (Em28xx dvb Extension) extension


And from Linux debian 3.12-1-amd64 #1 SMP Debian 3.12.9-1 (2014-02-01) x86_64 
GNU/Linux:

[207774.334552] em28xx: New device PCTV Systems PCTV 290e @ 480 Mbps 
(2013:024f, interface 0, class 0)
[207774.334557] em28xx: DVB interface 0 found: isoc
[207774.335059] em28xx: chip ID is em28174
[207774.734814] em28174 #0: Identified as PCTV nanoStick T2 290e (card=78)
[207774.734821] em28174 #0: v4l2 driver version 0.2.0
[207774.814336] em28174 #0: V4L2 video device registered as video0
[207774.814341] em28174 #0: dvb set to isoc mode.
[207774.823844] usbcore: registered new interface driver em28xx
[207774.895574] tda18271 1-0060: creating new instance
[207774.926952] TDA18271HD/C2 detected @ 1-0060
[207775.290440] DVB: registering new adapter (em28174 #0)
[207775.290453] usb 1-1: DVB: registering adapter 0 frontend 0 (Sony 
CXD2820R)...
[207775.294597] em28174 #0: Successfully loaded em28xx-dvb
[207775.294602] Em28xx: Initialized (Em28xx dvb Extension) extension

Linux debian 3.12-1-amd64 #1 SMP Debian 3.12.9-1 (2014-02-01) x86_64 GNU/Linux


Best regards,

-- Peter


--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2] media: soc_camera: rcar_vin: Add support for 10-bit YUV cameras

2014-02-25 Thread Phil Edworthy
Signed-off-by: Phil Edworthy phil.edwor...@renesas.com
---
v2:
  - Fix silly mistake with missing break.

 drivers/media/platform/soc_camera/rcar_vin.c |9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/media/platform/soc_camera/rcar_vin.c 
b/drivers/media/platform/soc_camera/rcar_vin.c
index 3b1c05a..702dc47 100644
--- a/drivers/media/platform/soc_camera/rcar_vin.c
+++ b/drivers/media/platform/soc_camera/rcar_vin.c
@@ -68,6 +68,8 @@
 #define VNMC_YCAL  (1  19)
 #define VNMC_INF_YUV8_BT656(0  16)
 #define VNMC_INF_YUV8_BT601(1  16)
+#define VNMC_INF_YUV10_BT656   (2  16)
+#define VNMC_INF_YUV10_BT601   (3  16)
 #define VNMC_INF_YUV16 (5  16)
 #define VNMC_VUP   (1  10)
 #define VNMC_IM_ODD(0  3)
@@ -275,6 +277,12 @@ static int rcar_vin_setup(struct rcar_vin_priv *priv)
/* BT.656 8bit YCbCr422 or BT.601 8bit YCbCr422 */
vnmc |= priv-pdata-flags  RCAR_VIN_BT656 ?
VNMC_INF_YUV8_BT656 : VNMC_INF_YUV8_BT601;
+   break;
+   case V4L2_MBUS_FMT_YUYV10_2X10:
+   /* BT.656 10bit YCbCr422 or BT.601 10bit YCbCr422 */
+   vnmc |= priv-pdata-flags  RCAR_VIN_BT656 ?
+   VNMC_INF_YUV10_BT656 : VNMC_INF_YUV10_BT601;
+   break;
default:
break;
}
@@ -1003,6 +1011,7 @@ static int rcar_vin_get_formats(struct soc_camera_device 
*icd, unsigned int idx,
switch (code) {
case V4L2_MBUS_FMT_YUYV8_1X16:
case V4L2_MBUS_FMT_YUYV8_2X8:
+   case V4L2_MBUS_FMT_YUYV10_2X10:
if (cam-extra_fmt)
break;
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


patch for media-build for CentOS release 6.5 (Final)

2014-02-25 Thread Jacques Lussier
Hello,

At the end is my output in Terminal while running ./build. The patch I
applied is :

Perl Extension for SHA-1/224/256/384/512
perl-Digest-SHA-5.71.1.el6.rfx (x86_64)

I imagine for those running 32-bit kernels the patch would be:

perl-Digest-SHA-PurePerl-5.48.1.el6.rf (noarch)

Here is the actual output before patch:

 ./build
Checking if the needed tools for CentOS release 6.5 (Final)
are available
ERROR: please install Digest::SHA, otherwise, build
won't work.
I don't know distro CentOS release 6.5 (Final).
So, I can't provide you a hint with the package names. Be welcome to
contribute with a patch for media-build, by submitting a distro-specific
hint to linux-media@vger.kernel.org Build can't procceed as 1 dependency
is missing at ./build line 266.

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 04/10] V4L: Add driver for s5k6a3 image sensor

2014-02-25 Thread Sylwester Nawrocki
Hi Baruch,

On 24/02/14 20:38, Baruch Siach wrote:
 On Mon, Feb 24, 2014 at 06:35:16PM +0100, Sylwester Nawrocki wrote:
  This patch adds subdev driver for Samsung S5K6A3 raw image sensor.
  As it is intended at the moment to be used only with the Exynos
  FIMC-IS (camera ISP) subsystem it is pretty minimal subdev driver.
  It doesn't do any I2C communication since the sensor is controlled
  by the ISP and its own firmware.
  This driver, if needed, can be updated in future into a regular
  subdev driver where the main CPU communicates with the sensor
  directly.
  
  Signed-off-by: Sylwester Nawrocki s.nawro...@samsung.com
  Acked-by: Kyungmin Park kyungmin.p...@samsung.com

 [...]
 
  +static int s5k6a3_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
  +{
  +  struct v4l2_mbus_framefmt *format = v4l2_subdev_get_try_format(fh, 0);
  +
  +  *format = s5k6a3_formats[0];
  +  format-width   = S5K6A3_DEFAULT_WIDTH;
  +  format-height  = S5K6A3_DEFAULT_HEIGHT;
  +
  +  return 0;
  +}
  +
  +static const struct v4l2_subdev_internal_ops s5k6a3_sd_internal_ops = {
  +  .open = s5k6a3_open,
  +};

 Where is this used?

This will be called when user process opens the corresponding /dev/v4l-subdev*
device node. More details on the v4l2 sub-device interface can be found at [1],
[2]. The device node is created by an aggregate media device driver, once all
required sub-devices are registered to it.
The above v4l2_subdev_internal_ops::open() implementation is pretty simple,
it just sets V4L2_SUBDEV_FORMAT_TRY format to some initial default value.
That's a per file handle value, so each process opening a set of sub-devices
can try pipeline configuration independently. 

[1] http://linuxtv.org/downloads/v4l-dvb-apis/subdev.html
[2] http://linuxtv.org/downloads/v4l-dvb-apis/vidioc-subdev-g-fmt.html

Regards,
Sylwester
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[REVIEWv1 PATCH 04/14] vb2: add debugging code to check for unbalanced ops

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

When a vb2_queue is freed check if all the mem_ops and queue ops were balanced.
So the number of calls to e.g. buf_finish has to match the number of calls to
buf_prepare, etc.

This code is only enabled if CONFIG_VIDEO_ADV_DEBUG is set.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
Acked-by: Pawel Osciak pa...@osciak.com
---
 drivers/media/v4l2-core/videobuf2-core.c | 233 ---
 include/media/videobuf2-core.h   |  43 ++
 2 files changed, 226 insertions(+), 50 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index 909f367..8f1578b 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -33,12 +33,63 @@ module_param(debug, int, 0644);
printk(KERN_DEBUG vb2:  fmt, ## arg); \
} while (0)
 
-#define call_memop(q, op, args...) \
-   (((q)-mem_ops-op) ?   \
-   ((q)-mem_ops-op(args)) : 0)
+#ifdef CONFIG_VIDEO_ADV_DEBUG
+
+/*
+ * If advanced debugging is on, then count how often each op is called,
+ * which can either be per-buffer or per-queue.
+ *
+ * If the op failed then the 'fail_' variant is called to decrease the
+ * counter. That makes it easy to check that the 'init' and 'cleanup'
+ * (and variations thereof) stay balanced.
+ */
+
+#define call_memop(vb, op, args...)\
+({ \
+   struct vb2_queue *_q = (vb)-vb2_queue; \
+   dprintk(2, call_memop(%p, %d, %s)%s\n,\
+   _q, (vb)-v4l2_buf.index, #op,  \
+   _q-mem_ops-op ?  :  (nop));   \
+   (vb)-cnt_mem_ ## op++; \
+   _q-mem_ops-op ? _q-mem_ops-op(args) : 0;\
+})
+#define fail_memop(vb, op) ((vb)-cnt_mem_ ## op--)
+
+#define call_qop(q, op, args...)   \
+({ \
+   dprintk(2, call_qop(%p, %s)%s\n, q, #op,  \
+   (q)-ops-op ?  :  (nop));  \
+   (q)-cnt_ ## op++;  \
+   (q)-ops-op ? (q)-ops-op(args) : 0;  \
+})
+#define fail_qop(q, op) ((q)-cnt_ ## op--)
+
+#define call_vb_qop(vb, op, args...)   \
+({ \
+   struct vb2_queue *_q = (vb)-vb2_queue; \
+   dprintk(2, call_vb_qop(%p, %d, %s)%s\n,   \
+   _q, (vb)-v4l2_buf.index, #op,  \
+   _q-ops-op ?  :  (nop));   \
+   (vb)-cnt_ ## op++; \
+   _q-ops-op ? _q-ops-op(args) : 0;\
+})
+#define fail_vb_qop(vb, op) ((vb)-cnt_ ## op--)
+
+#else
+
+#define call_memop(vb, op, args...)\
+   ((vb)-vb2_queue-mem_ops-op ? (vb)-vb2_queue-mem_ops-op(args) : 0)
+#define fail_memop(vb, op)
 
 #define call_qop(q, op, args...)   \
-   (((q)-ops-op) ? ((q)-ops-op(args)) : 0)
+   ((q)-ops-op ? (q)-ops-op(args) : 0)
+#define fail_qop(q, op)
+
+#define call_vb_qop(vb, op, args...)   \
+   ((vb)-vb2_queue-ops-op ? (vb)-vb2_queue-ops-op(args) : 0)
+#define fail_vb_qop(vb, op)
+
+#endif
 
 #define V4L2_BUFFER_MASK_FLAGS (V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_QUEUED | \
 V4L2_BUF_FLAG_DONE | V4L2_BUF_FLAG_ERROR | \
@@ -61,7 +112,7 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
for (plane = 0; plane  vb-num_planes; ++plane) {
unsigned long size = PAGE_ALIGN(q-plane_sizes[plane]);
 
-   mem_priv = call_memop(q, alloc, q-alloc_ctx[plane],
+   mem_priv = call_memop(vb, alloc, q-alloc_ctx[plane],
  size, q-gfp_flags);
if (IS_ERR_OR_NULL(mem_priv))
goto free;
@@ -73,9 +124,10 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
 
return 0;
 free:
+   fail_memop(vb, alloc);
/* Free already allocated memory if one of the allocations failed */
for (; plane  0; --plane) {
-   call_memop(q, put, vb-planes[plane - 1].mem_priv);
+   call_memop(vb, put, vb-planes[plane - 1].mem_priv);
vb-planes[plane - 1].mem_priv = NULL;
}
 
@@ -87,11 +139,10 @@ free:
  */
 static void __vb2_buf_mem_free(struct vb2_buffer *vb)
 {
-   struct vb2_queue *q = 

[REVIEWv1 PATCH 08/14] vb2: fix buf_init/buf_cleanup call sequences

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

Ensure that these ops are properly balanced.

There are two scenarios:

1) for MMAP buf_init is called when the buffers are created and buf_cleanup
   must be called when the queue is finally freed. This scenario was always
   working.

2) for USERPTR and DMABUF it is more complicated. When a buffer is queued
   the code checks if all planes of this buffer have been acquired before.
   If that's the case, then only buf_prepare has to be called. Otherwise
   buf_cleanup needs to be called if the buffer was acquired before, then,
   once all changed planes have been (re)acquired, buf_init has to be
   called followed by buf_prepare. Should buf_prepare fail, then buf_cleanup
   must be called on the newly acquired planes to release them in.

Finally, in __vb2_queue_free we have to check if the buffer was actually
acquired before calling buf_cleanup. While that it always true for MMAP
mode, it is not necessarily true for the other modes. E.g. if you just
call REQBUFS and close the file handle, then buffers were never queued and
so no buf_init was ever called.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/v4l2-core/videobuf2-core.c | 100 +--
 1 file changed, 67 insertions(+), 33 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index b5142e5..eefcff7 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -373,8 +373,10 @@ static int __vb2_queue_free(struct vb2_queue *q, unsigned 
int buffers)
/* Call driver-provided cleanup function for each buffer, if provided */
for (buffer = q-num_buffers - buffers; buffer  q-num_buffers;
 ++buffer) {
-   if (q-bufs[buffer])
-   call_vb_qop(q-bufs[buffer], buf_cleanup, 
q-bufs[buffer]);
+   struct vb2_buffer *vb = q-bufs[buffer];
+
+   if (vb  vb-planes[0].mem_priv)
+   call_vb_qop(vb, buf_cleanup, vb);
}
 
/* Release video buffer memory */
@@ -1161,6 +1163,7 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const 
struct v4l2_buffer *b)
unsigned int plane;
int ret;
int write = !V4L2_TYPE_IS_OUTPUT(q-type);
+   bool reacquired = vb-planes[0].mem_priv == NULL;
 
/* Copy relevant information provided by the userspace */
__fill_vb2_buffer(vb, b, planes);
@@ -1186,12 +1189,16 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const 
struct v4l2_buffer *b)
}
 
/* Release previously acquired memory if present */
-   if (vb-planes[plane].mem_priv)
+   if (vb-planes[plane].mem_priv) {
+   if (!reacquired) {
+   reacquired = true;
+   call_vb_qop(vb, buf_cleanup, vb);
+   }
call_memop(vb, put_userptr, vb-planes[plane].mem_priv);
+   }
 
vb-planes[plane].mem_priv = NULL;
-   vb-v4l2_planes[plane].m.userptr = 0;
-   vb-v4l2_planes[plane].length = 0;
+   memset(vb-v4l2_planes[plane], 0, sizeof(struct v4l2_plane));
 
/* Acquire each plane's memory */
mem_priv = call_memop(vb, get_userptr, q-alloc_ctx[plane],
@@ -1208,23 +1215,34 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const 
struct v4l2_buffer *b)
}
 
/*
-* Call driver-specific initialization on the newly acquired buffer,
-* if provided.
-*/
-   ret = call_vb_qop(vb, buf_init, vb);
-   if (ret) {
-   dprintk(1, qbuf: buffer initialization failed\n);
-   fail_vb_qop(vb, buf_init);
-   goto err;
-   }
-
-   /*
 * Now that everything is in order, copy relevant information
 * provided by userspace.
 */
for (plane = 0; plane  vb-num_planes; ++plane)
vb-v4l2_planes[plane] = planes[plane];
 
+   if (reacquired) {
+   /*
+* One or more planes changed, so we must call buf_init to do
+* the driver-specific initialization on the newly acquired
+* buffer, if provided.
+*/
+   ret = call_vb_qop(vb, buf_init, vb);
+   if (ret) {
+   dprintk(1, qbuf: buffer initialization failed\n);
+   fail_vb_qop(vb, buf_init);
+   goto err;
+   }
+   }
+
+   ret = call_vb_qop(vb, buf_prepare, vb);
+   if (ret) {
+   dprintk(1, qbuf: buffer preparation failed\n);
+   fail_vb_qop(vb, buf_prepare);
+   call_vb_qop(vb, buf_cleanup, vb);
+   goto err;
+   }
+
return 0;
 err:
/* In case of errors, release planes that were already 

[REVIEWv1 PATCH 00/16] vb2: fixes, balancing callbacks (PART 1)

2014-02-25 Thread Hans Verkuil
This patch series is the first REVIEW series as opposed to RFC.
It follows RFCv4:

http://www.spinics.net/lists/linux-media/msg73039.html

This is part 1 of vb2 changes. I will post a part 2 RFC series soon
for more vb2 fixes and enhancements.

Ignore patches 1-3: the first is already merged in 3.14, and 2 and 3
are pending to be merged in 3.14. But you need them for some follow-up
patches.

Patches 04-09 and 14 are unchanged from RFCv4.

Changelog since RFCv4:

- Dropped RFCv4 patch 08/11 as it was wrong. Instead, I added patch
  10/14. This fixes a bug in __vb2_queue_free() and improved the code
  that caused my misunderstanding with RFCv4 patch 08/11.
- In patch 11/14 I dropped the check against the minimum number of
  required buffers in create_bufs. Instead, check for this in streamon.
- Added patch 12: vb2: properly clean up PREPARED and QUEUED buffers
  This fixes one corner case that still produced 'Unbalanced' results.
- Added patch 13: vb2: replace BUG by WARN_ON
  Just a small change to be more gentle if the driver tries something
  it shouldn't.

This patch series fixes a series of bugs in vb2. Recently I have been
converting the saa7134 driver to vb2 and as part of that work I discovered
that the op calls were not properly balanced, which caused saa7134 to
fail.

Based on that I did more debugging and I found lots of different issues
with vb2 when it comes to balancing ops. This patch series fixes them.
Many thanks to Pawel Osciak for a good brainstorm session.

Patch 4 adds debugging code to check for unbalanced calls. I used this
when testing since without this it is very hard to verify correctness.
It is currently turned on when CONFIG_VIDEO_ADV_DEBUG is set, but perhaps
this should be placed under a vb2 specific debug option?

The next patch changes the buf_finish return type to void. It must not
fail, and you can't do anything useful if it does anyway.

Patch 6 just improves some comments.

Patches 7 and 8 fix several unbalanced ops.

Patch 9 just renames queue_count to owned_by_drv_count. The old name
suggests the number of buffers in the queue_list, but that's not what
it is. Since the next patch will actually add a real count for the
number of buffers in the queue_list I decided to just rename this,
thus freeing up the name 'queue_count'.

Patch 10 fixes a __vb2_queue_free() bug and makes __reqbufs and
__create_bufs code a bit more understandable.

Patch 11 fixes a bug in the handling of start_streaming: before that op
is called any prequeued buffers are handed over to the driver. But if
start_streaming returns an error, then those buffers are not reclaimed.
Since start_streaming failed, q-streaming is 0, so stop_streaming isn't
called either.

There are two reasons for an error in start_streaming: either a real
error when setting up the DMA engine occurred or there were not enough
buffers queued for the DMA engine to start (start_streaming returns
-ENOBUFS in that case). It makes sense to require that drivers return
queued buffers back to vb2 in case of an error, but not if they also 
have to do that in case of insufficient buffers. So this patch replaces
the -ENOBUFS mechanism by a vb2_queue field that tells vb2 what the
minimum number of buffers is.

Now if start_streaming returns an error the vb2 core will check if there
are still buffers owned by the driver and if so produce a warning and
reclaim those buffers. The same is done when the vb2_queue is freed.

This ensures that the prepare/finish memops are correctly called and
the state of all the buffers is consistent.

Patch 12 fixes another corner case introducing unbalanced ops.

Patch 13 replaces a BUG_ON by WARN_ON.

Patch 14 fixes vivi for this start_streaming issue. Note that there are
many drivers that do not clean up properly in case of an error during
start_streaming.

I have been testing these vb2 changes with vivi (vmalloc based), a patched
saa7134 (dma-contig based) and an out-of-tree PCI driver (dma-sg based),
with the mmap/userptr/dmabuf and read/write streaming modes.

Regards,

Hans



--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[REVIEWv1 PATCH 07/14] vb2: call buf_finish from __dqbuf

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

This ensures that it is also called from queue_cancel, which also calls
__dqbuf(). Without this change any time queue_cancel is called while
streaming the buf_finish op will not be called and any driver cleanup
will not happen.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
Acked-by: Pawel Osciak pa...@osciak.com
---
 drivers/media/v4l2-core/videobuf2-core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index 59bfd85..b5142e5 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -1758,6 +1758,8 @@ static void __vb2_dqbuf(struct vb2_buffer *vb)
if (vb-state == VB2_BUF_STATE_DEQUEUED)
return;
 
+   call_vb_qop(vb, buf_finish, vb);
+
vb-state = VB2_BUF_STATE_DEQUEUED;
 
/* unmap DMABUF buffer */
@@ -1783,8 +1785,6 @@ static int vb2_internal_dqbuf(struct vb2_queue *q, struct 
v4l2_buffer *b, bool n
if (ret  0)
return ret;
 
-   call_vb_qop(vb, buf_finish, vb);
-
switch (vb-state) {
case VB2_BUF_STATE_DONE:
dprintk(3, dqbuf: Returning done buffer\n);
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[REVIEWv1 PATCH 13/14] vb2: replace BUG by WARN_ON

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

No need to oops for this, WARN_ON is good enough.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/v4l2-core/videobuf2-core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index 93b7969..2c3a7f2 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -2531,9 +2531,9 @@ static int __vb2_init_fileio(struct vb2_queue *q, int 
read)
/*
 * Sanity check
 */
-   if ((read  !(q-io_modes  VB2_READ)) ||
-  (!read  !(q-io_modes  VB2_WRITE)))
-   BUG();
+   if (WARN_ON((read  !(q-io_modes  VB2_READ)) ||
+   (!read  !(q-io_modes  VB2_WRITE
+   return -EINVAL;
 
/*
 * Check if device supports mapping buffers to kernel virtual space.
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[REVIEWv1 PATCH 01/14] vb2: Check if there are buffers before streamon

2014-02-25 Thread Hans Verkuil
From: Ricardo Ribalda Delgado ricardo.riba...@gmail.com

This patch adds a test preventing streamon() if there is no buffer
ready.

Without this patch, a user could call streamon() before
preparing any buffer. This leads to a situation where if he calls
close() before calling streamoff() the device is kept streaming.

Signed-off-by: Ricardo Ribalda Delgado ricardo.riba...@gmail.com
Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/v4l2-core/videobuf2-core.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index 5a5fb7f..a127925 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -1776,6 +1776,11 @@ static int vb2_internal_streamon(struct vb2_queue *q, 
enum v4l2_buf_type type)
return 0;
}
 
+   if (!q-num_buffers) {
+   dprintk(1, streamon: no buffers have been allocated\n);
+   return -EINVAL;
+   }
+
/*
 * If any buffers were queued before streamon,
 * we can now pass them to driver for processing.
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[REVIEWv1 PATCH 10/14] vb2: don't init the list if there are still buffers

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

__vb2_queue_free() would init the queued_list at all times, even if
q-num_buffers  0. This should only happen if num_buffers == 0.

This situation can happen if a CREATE_BUFFERS call couldn't allocate
enough buffers and had to free those it did manage to allocate before
returning an error.

While we're at it: __vb2_queue_alloc() returns the number of buffers
allocated, not an error code. So stick the result in allocated_buffers
instead of ret as that's very confusing.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/v4l2-core/videobuf2-core.c | 29 +
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index 2a7815c..90374c0 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -452,9 +452,10 @@ static int __vb2_queue_free(struct vb2_queue *q, unsigned 
int buffers)
}
 
q-num_buffers -= buffers;
-   if (!q-num_buffers)
+   if (!q-num_buffers) {
q-memory = 0;
-   INIT_LIST_HEAD(q-queued_list);
+   INIT_LIST_HEAD(q-queued_list);
+   }
return 0;
 }
 
@@ -820,14 +821,12 @@ static int __reqbufs(struct vb2_queue *q, struct 
v4l2_requestbuffers *req)
}
 
/* Finally, allocate buffers and video memory */
-   ret = __vb2_queue_alloc(q, req-memory, num_buffers, num_planes);
-   if (ret == 0) {
+   allocated_buffers = __vb2_queue_alloc(q, req-memory, num_buffers, 
num_planes);
+   if (allocated_buffers == 0) {
dprintk(1, Memory allocation failed\n);
return -ENOMEM;
}
 
-   allocated_buffers = ret;
-
/*
 * Check if driver can handle the allocated number of buffers.
 */
@@ -851,6 +850,10 @@ static int __reqbufs(struct vb2_queue *q, struct 
v4l2_requestbuffers *req)
q-num_buffers = allocated_buffers;
 
if (ret  0) {
+   /*
+* Note: __vb2_queue_free() will subtract 'allocated_buffers'
+* from q-num_buffers.
+*/
__vb2_queue_free(q, allocated_buffers);
return ret;
}
@@ -924,20 +927,18 @@ static int __create_bufs(struct vb2_queue *q, struct 
v4l2_create_buffers *create
}
 
/* Finally, allocate buffers and video memory */
-   ret = __vb2_queue_alloc(q, create-memory, num_buffers,
+   allocated_buffers = __vb2_queue_alloc(q, create-memory, num_buffers,
num_planes);
-   if (ret == 0) {
+   if (allocated_buffers == 0) {
dprintk(1, Memory allocation failed\n);
return -ENOMEM;
}
 
-   allocated_buffers = ret;
-
/*
 * Check if driver can handle the so far allocated number of buffers.
 */
-   if (ret  num_buffers) {
-   num_buffers = ret;
+   if (allocated_buffers  num_buffers) {
+   num_buffers = allocated_buffers;
 
/*
 * q-num_buffers contains the total number of buffers, that the
@@ -960,6 +961,10 @@ static int __create_bufs(struct vb2_queue *q, struct 
v4l2_create_buffers *create
q-num_buffers += allocated_buffers;
 
if (ret  0) {
+   /*
+* Note: __vb2_queue_free() will subtract 'allocated_buffers'
+* from q-num_buffers.
+*/
__vb2_queue_free(q, allocated_buffers);
return -ENOMEM;
}
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[REVIEWv1 PATCH 14/14] vivi: correctly cleanup after a start_streaming failure

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

If start_streaming fails then any queued buffers must be given back
to the vb2 core.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/platform/vivi.c | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
index e9cd96e..643937b 100644
--- a/drivers/media/platform/vivi.c
+++ b/drivers/media/platform/vivi.c
@@ -889,10 +889,20 @@ static void buffer_queue(struct vb2_buffer *vb)
 static int start_streaming(struct vb2_queue *vq, unsigned int count)
 {
struct vivi_dev *dev = vb2_get_drv_priv(vq);
+   int err;
 
dprintk(dev, 1, %s\n, __func__);
dev-seq_count = 0;
-   return vivi_start_generating(dev);
+   err = vivi_start_generating(dev);
+   if (err) {
+   struct vivi_buffer *buf, *tmp;
+
+   list_for_each_entry_safe(buf, tmp, dev-vidq.active, list) {
+   list_del(buf-list);
+   vb2_buffer_done(buf-vb, VB2_BUF_STATE_QUEUED);
+   }
+   }
+   return err;
 }
 
 /* abort streaming and wait for last buffer */
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[REVIEWv1 PATCH 05/14] vb2: change result code of buf_finish to void

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

The buf_finish op should always work, so change the return type to void.
Update the few drivers that use it. Note that buf_finish can be called
both when the DMA is streaming and when it isn't (during queue_cancel).
Update drivers to check that where appropriate.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
Acked-by: Pawel Osciak pa...@osciak.com
Reviewed-by: Pawel Osciak pa...@osciak.com
---
 drivers/media/parport/bw-qcam.c |  6 --
 drivers/media/pci/sta2x11/sta2x11_vip.c |  7 +++
 drivers/media/platform/marvell-ccic/mcam-core.c |  3 +--
 drivers/media/usb/pwc/pwc-if.c  | 16 +---
 drivers/media/usb/uvc/uvc_queue.c   |  6 +++---
 drivers/media/v4l2-core/videobuf2-core.c|  6 +-
 drivers/staging/media/go7007/go7007-v4l2.c  |  3 +--
 include/media/videobuf2-core.h  |  2 +-
 8 files changed, 23 insertions(+), 26 deletions(-)

diff --git a/drivers/media/parport/bw-qcam.c b/drivers/media/parport/bw-qcam.c
index d12bd33..8d69bfb 100644
--- a/drivers/media/parport/bw-qcam.c
+++ b/drivers/media/parport/bw-qcam.c
@@ -667,13 +667,16 @@ static void buffer_queue(struct vb2_buffer *vb)
vb2_buffer_done(vb, VB2_BUF_STATE_DONE);
 }
 
-static int buffer_finish(struct vb2_buffer *vb)
+static void buffer_finish(struct vb2_buffer *vb)
 {
struct qcam *qcam = vb2_get_drv_priv(vb-vb2_queue);
void *vbuf = vb2_plane_vaddr(vb, 0);
int size = vb-vb2_queue-plane_sizes[0];
int len;
 
+   if (!vb2_is_streaming(vb-vb2_queue))
+   return;
+
mutex_lock(qcam-lock);
parport_claim_or_block(qcam-pdev);
 
@@ -691,7 +694,6 @@ static int buffer_finish(struct vb2_buffer *vb)
if (len != size)
vb-state = VB2_BUF_STATE_ERROR;
vb2_set_plane_payload(vb, 0, len);
-   return 0;
 }
 
 static struct vb2_ops qcam_video_qops = {
diff --git a/drivers/media/pci/sta2x11/sta2x11_vip.c 
b/drivers/media/pci/sta2x11/sta2x11_vip.c
index e5cfb6c..bb11443 100644
--- a/drivers/media/pci/sta2x11/sta2x11_vip.c
+++ b/drivers/media/pci/sta2x11/sta2x11_vip.c
@@ -327,7 +327,7 @@ static void buffer_queue(struct vb2_buffer *vb)
}
spin_unlock(vip-lock);
 }
-static int buffer_finish(struct vb2_buffer *vb)
+static void buffer_finish(struct vb2_buffer *vb)
 {
struct sta2x11_vip *vip = vb2_get_drv_priv(vb-vb2_queue);
struct vip_buffer *vip_buf = to_vip_buffer(vb);
@@ -337,9 +337,8 @@ static int buffer_finish(struct vb2_buffer *vb)
list_del_init(vip_buf-list);
spin_unlock(vip-lock);
 
-   vip_active_buf_next(vip);
-
-   return 0;
+   if (vb2_is_streaming(vb-vb2_queue))
+   vip_active_buf_next(vip);
 }
 
 static int start_streaming(struct vb2_queue *vq, unsigned int count)
diff --git a/drivers/media/platform/marvell-ccic/mcam-core.c 
b/drivers/media/platform/marvell-ccic/mcam-core.c
index 32fab30..8b34c48 100644
--- a/drivers/media/platform/marvell-ccic/mcam-core.c
+++ b/drivers/media/platform/marvell-ccic/mcam-core.c
@@ -1238,7 +1238,7 @@ static int mcam_vb_sg_buf_prepare(struct vb2_buffer *vb)
return 0;
 }
 
-static int mcam_vb_sg_buf_finish(struct vb2_buffer *vb)
+static void mcam_vb_sg_buf_finish(struct vb2_buffer *vb)
 {
struct mcam_camera *cam = vb2_get_drv_priv(vb-vb2_queue);
struct sg_table *sg_table = vb2_dma_sg_plane_desc(vb, 0);
@@ -1246,7 +1246,6 @@ static int mcam_vb_sg_buf_finish(struct vb2_buffer *vb)
if (sg_table)
dma_unmap_sg(cam-dev, sg_table-sgl,
sg_table-nents, DMA_FROM_DEVICE);
-   return 0;
 }
 
 static void mcam_vb_sg_buf_cleanup(struct vb2_buffer *vb)
diff --git a/drivers/media/usb/pwc/pwc-if.c b/drivers/media/usb/pwc/pwc-if.c
index abf365a..b9c9f10 100644
--- a/drivers/media/usb/pwc/pwc-if.c
+++ b/drivers/media/usb/pwc/pwc-if.c
@@ -614,17 +614,19 @@ static int buffer_prepare(struct vb2_buffer *vb)
return 0;
 }
 
-static int buffer_finish(struct vb2_buffer *vb)
+static void buffer_finish(struct vb2_buffer *vb)
 {
struct pwc_device *pdev = vb2_get_drv_priv(vb-vb2_queue);
struct pwc_frame_buf *buf = container_of(vb, struct pwc_frame_buf, vb);
 
-   /*
-* Application has called dqbuf and is getting back a buffer we've
-* filled, take the pwc data we've stored in buf-data and decompress
-* it into a usable format, storing the result in the vb2_buffer
-*/
-   return pwc_decompress(pdev, buf);
+   if (vb-state == VB2_BUF_STATE_DONE) {
+   /*
+* Application has called dqbuf and is getting back a buffer 
we've
+* filled, take the pwc data we've stored in buf-data and 
decompress
+* it into a usable format, storing the result in the vb2_buffer
+*/
+   pwc_decompress(pdev, buf);
+   }
 }
 
 static void 

[REVIEWv1 PATCH 03/14] vb2: fix PREPARE_BUF regression

2014-02-25 Thread Hans Verkuil
Fix an incorrect test in vb2_internal_qbuf() where only DEQUEUED buffers
are allowed. But PREPARED buffers are also OK.

Introduced by commit 4138111a27859dcc56a5592c804dd16bb12a23d1
(vb2: simplify qbuf/prepare_buf by removing callback).

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/v4l2-core/videobuf2-core.c | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index f1a2857c..909f367 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -1420,11 +1420,6 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct 
v4l2_buffer *b)
return ret;
 
vb = q-bufs[b-index];
-   if (vb-state != VB2_BUF_STATE_DEQUEUED) {
-   dprintk(1, %s(): invalid buffer state %d\n, __func__,
-   vb-state);
-   return -EINVAL;
-   }
 
switch (vb-state) {
case VB2_BUF_STATE_DEQUEUED:
@@ -1438,7 +1433,8 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct 
v4l2_buffer *b)
dprintk(1, qbuf: buffer still being prepared\n);
return -EINVAL;
default:
-   dprintk(1, qbuf: buffer already in use\n);
+   dprintk(1, %s(): invalid buffer state %d\n, __func__,
+   vb-state);
return -EINVAL;
}
 
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[REVIEWv1 PATCH 06/14] vb2: add note that buf_finish can be called with !vb2_is_streaming()

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

Drivers need to be aware that buf_finish can be called when there is no
streaming going on, so make a note of that.

Also add a bunch of missing periods at the end of sentences.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
Acked-by: Pawel Osciak pa...@osciak.com
---
 include/media/videobuf2-core.h | 44 ++
 1 file changed, 23 insertions(+), 21 deletions(-)

diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
index f443ce0..82b7f0f 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-core.h
@@ -34,49 +34,49 @@ struct vb2_fileio_data;
  * usually will result in the allocator freeing the buffer (if
  * no other users of this buffer are present); the buf_priv
  * argument is the allocator private per-buffer structure
- * previously returned from the alloc callback
+ * previously returned from the alloc callback.
  * @get_userptr: acquire userspace memory for a hardware operation; used for
  *  USERPTR memory types; vaddr is the address passed to the
  *  videobuf layer when queuing a video buffer of USERPTR type;
  *  should return an allocator private per-buffer structure
  *  associated with the buffer on success, NULL on failure;
  *  the returned private structure will then be passed as buf_priv
- *  argument to other ops in this structure
+ *  argument to other ops in this structure.
  * @put_userptr: inform the allocator that a USERPTR buffer will no longer
- *  be used
+ *  be used.
  * @attach_dmabuf: attach a shared struct dma_buf for a hardware operation;
  *used for DMABUF memory types; alloc_ctx is the alloc context
  *dbuf is the shared dma_buf; returns NULL on failure;
  *allocator private per-buffer structure on success;
- *this needs to be used for further accesses to the buffer
+ *this needs to be used for further accesses to the buffer.
  * @detach_dmabuf: inform the exporter of the buffer that the current DMABUF
  *buffer is no longer used; the buf_priv argument is the
  *allocator private per-buffer structure previously returned
- *from the attach_dmabuf callback
+ *from the attach_dmabuf callback.
  * @map_dmabuf: request for access to the dmabuf from allocator; the allocator
  * of dmabuf is informed that this driver is going to use the
- * dmabuf
+ * dmabuf.
  * @unmap_dmabuf: releases access control to the dmabuf - allocator is notified
- *   that this driver is done using the dmabuf for now
+ *   that this driver is done using the dmabuf for now.
  * @prepare:   called every time the buffer is passed from userspace to the
- * driver, useful for cache synchronisation, optional
+ * driver, useful for cache synchronisation, optional.
  * @finish:called every time the buffer is passed back from the driver
- * to the userspace, also optional
+ * to the userspace, also optional.
  * @vaddr: return a kernel virtual address to a given memory buffer
  * associated with the passed private structure or NULL if no
- * such mapping exists
+ * such mapping exists.
  * @cookie:return allocator specific cookie for a given memory buffer
  * associated with the passed private structure or NULL if not
- * available
+ * available.
  * @num_users: return the current number of users of a memory buffer;
  * return 1 if the videobuf layer (or actually the driver using
- * it) is the only user
+ * it) is the only user.
  * @mmap:  setup a userspace mapping for a given memory buffer under
- * the provided virtual memory region
+ * the provided virtual memory region.
  *
  * Required ops for USERPTR types: get_userptr, put_userptr.
  * Required ops for MMAP types: alloc, put, num_users, mmap.
- * Required ops for read/write access types: alloc, put, num_users, vaddr
+ * Required ops for read/write access types: alloc, put, num_users, vaddr.
  * Required ops for DMABUF types: attach_dmabuf, detach_dmabuf, map_dmabuf,
  *   unmap_dmabuf.
  */
@@ -258,27 +258,29 @@ struct vb2_buffer {
  * @wait_prepare:  release any locks taken while calling vb2 functions;
  * it is called before an ioctl needs to wait for a new
  * buffer to arrive; required to avoid a deadlock in
- * blocking access type
+ * blocking access type.
  * @wait_finish:   reacquire all locks released in the previous callback;
  *

[REVIEWv1 PATCH 09/14] vb2: rename queued_count to owned_by_drv_count

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

'queued_count' is a bit vague since it is not clear to which queue it
refers to: the vb2 internal list of buffers or the driver-owned list
of buffers.

Rename to make it explicit.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
Acked-by: Pawel Osciak pa...@osciak.com
---
 drivers/media/v4l2-core/videobuf2-core.c | 10 +-
 include/media/videobuf2-core.h   |  4 ++--
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index eefcff7..2a7815c 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -1071,7 +1071,7 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum 
vb2_buffer_state state)
spin_lock_irqsave(q-done_lock, flags);
vb-state = state;
list_add_tail(vb-done_entry, q-done_list);
-   atomic_dec(q-queued_count);
+   atomic_dec(q-owned_by_drv_count);
spin_unlock_irqrestore(q-done_lock, flags);
 
/* Inform any processes that may be waiting for buffers */
@@ -1402,7 +1402,7 @@ static void __enqueue_in_driver(struct vb2_buffer *vb)
unsigned int plane;
 
vb-state = VB2_BUF_STATE_ACTIVE;
-   atomic_inc(q-queued_count);
+   atomic_inc(q-owned_by_drv_count);
 
/* sync buffers */
for (plane = 0; plane  vb-num_planes; ++plane)
@@ -1554,7 +1554,7 @@ static int vb2_start_streaming(struct vb2_queue *q)
int ret;
 
/* Tell the driver to start streaming */
-   ret = call_qop(q, start_streaming, q, atomic_read(q-queued_count));
+   ret = call_qop(q, start_streaming, q, 
atomic_read(q-owned_by_drv_count));
if (ret)
fail_qop(q, start_streaming);
 
@@ -1775,7 +1775,7 @@ int vb2_wait_for_all_buffers(struct vb2_queue *q)
}
 
if (!q-retry_start_streaming)
-   wait_event(q-done_wq, !atomic_read(q-queued_count));
+   wait_event(q-done_wq, !atomic_read(q-owned_by_drv_count));
return 0;
 }
 EXPORT_SYMBOL_GPL(vb2_wait_for_all_buffers);
@@ -1907,7 +1907,7 @@ static void __vb2_queue_cancel(struct vb2_queue *q)
 * has not already dequeued before initiating cancel.
 */
INIT_LIST_HEAD(q-done_list);
-   atomic_set(q-queued_count, 0);
+   atomic_set(q-owned_by_drv_count, 0);
wake_up_all(q-done_wq);
 
/*
diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
index 82b7f0f..adaffed 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-core.h
@@ -353,7 +353,7 @@ struct v4l2_fh;
  * @bufs:  videobuf buffer structures
  * @num_buffers: number of allocated/used buffers
  * @queued_list: list of buffers currently queued from userspace
- * @queued_count: number of buffers owned by the driver
+ * @owned_by_drv_count: number of buffers owned by the driver
  * @done_list: list of buffers ready to be dequeued to userspace
  * @done_lock: lock to protect done_list list
  * @done_wq:   waitqueue for processes waiting for buffers ready to be dequeued
@@ -385,7 +385,7 @@ struct vb2_queue {
 
struct list_headqueued_list;
 
-   atomic_tqueued_count;
+   atomic_towned_by_drv_count;
struct list_headdone_list;
spinlock_t  done_lock;
wait_queue_head_t   done_wq;
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[REVIEWv1 PATCH 11/14] vb2: only call start_streaming if sufficient buffers are queued

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

In commit 02f142ecd24aaf891324ffba8527284c1731b561 support was added to
start_streaming to return -ENOBUFS if insufficient buffers were queued
for the DMA engine to start. The vb2 core would attempt calling
start_streaming again if another buffer would be queued up.

Later analysis uncovered problems with the queue management if start_streaming
would return an error: the buffers are enqueued to the driver before the
start_streaming op is called, so after an error they are never returned to
the vb2 core. The solution for this is to let the driver return them to
the vb2 core in case of an error while starting the DMA engine. However,
in the case of -ENOBUFS that would be weird: it is not a real error, it
just says that more buffers are needed. Requiring start_streaming to give
them back only to have them requeued again the next time the application
calls QBUF is inefficient.

This patch changes this mechanism: it adds a 'min_buffers_needed' field
to vb2_queue that drivers can set with the minimum number of buffers
required to start the DMA engine. The start_streaming op is only called
if enough buffers are queued. The -ENOBUFS handling has been dropped in
favor of this new method.

Drivers are expected to return buffers back to vb2 core with state QUEUED
if start_streaming would return an error. The vb2 core checks for this
and produces a warning if that didn't happen and it will forcefully
reclaim such buffers to ensure that the internal vb2 core state remains
consistent and all buffer-related resources have been correctly freed
and all op calls have been balanced.

__reqbufs() has been updated to check that at least min_buffers_needed
buffers could be allocated. If fewer buffers were allocated then __reqbufs
will free what was allocated and return -ENOMEM. Based on a suggestion from
Pawel Osciak.

__create_bufs() doesn't do that check, since the use of __create_bufs
assumes some advance scenario where the user might want more control.
Instead streamon will check if enough buffers were allocated to prevent
streaming with fewer than the minimum required number of buffers.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/platform/davinci/vpbe_display.c   |   6 +-
 drivers/media/platform/davinci/vpif_capture.c   |   7 +-
 drivers/media/platform/davinci/vpif_display.c   |   7 +-
 drivers/media/platform/s5p-tv/mixer_video.c |   6 +-
 drivers/media/v4l2-core/videobuf2-core.c| 146 
 drivers/staging/media/davinci_vpfe/vpfe_video.c |   3 +-
 include/media/videobuf2-core.h  |  14 ++-
 7 files changed, 116 insertions(+), 73 deletions(-)

diff --git a/drivers/media/platform/davinci/vpbe_display.c 
b/drivers/media/platform/davinci/vpbe_display.c
index b02aba4..9231e48 100644
--- a/drivers/media/platform/davinci/vpbe_display.c
+++ b/drivers/media/platform/davinci/vpbe_display.c
@@ -344,11 +344,6 @@ static int vpbe_start_streaming(struct vb2_queue *vq, 
unsigned int count)
struct vpbe_device *vpbe_dev = fh-disp_dev-vpbe_dev;
int ret;
 
-   /* If buffer queue is empty, return error */
-   if (list_empty(layer-dma_queue)) {
-   v4l2_err(vpbe_dev-v4l2_dev, buffer queue is empty\n);
-   return -ENOBUFS;
-   }
/* Get the next frame from the buffer queue */
layer-next_frm = layer-cur_frm = list_entry(layer-dma_queue.next,
struct vpbe_disp_buffer, list);
@@ -1416,6 +1411,7 @@ static int vpbe_display_reqbufs(struct file *file, void 
*priv,
q-mem_ops = vb2_dma_contig_memops;
q-buf_struct_size = sizeof(struct vpbe_disp_buffer);
q-timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
+   q-min_buffers_needed = 1;
 
ret = vb2_queue_init(q);
if (ret) {
diff --git a/drivers/media/platform/davinci/vpif_capture.c 
b/drivers/media/platform/davinci/vpif_capture.c
index 735ec47..9731ad4 100644
--- a/drivers/media/platform/davinci/vpif_capture.c
+++ b/drivers/media/platform/davinci/vpif_capture.c
@@ -272,13 +272,7 @@ static int vpif_start_streaming(struct vb2_queue *vq, 
unsigned int count)
unsigned long flags;
int ret;
 
-   /* If buffer queue is empty, return error */
spin_lock_irqsave(common-irqlock, flags);
-   if (list_empty(common-dma_queue)) {
-   spin_unlock_irqrestore(common-irqlock, flags);
-   vpif_dbg(1, debug, buffer queue is empty\n);
-   return -ENOBUFS;
-   }
 
/* Get the next frame from the buffer queue */
common-cur_frm = common-next_frm = list_entry(common-dma_queue.next,
@@ -1024,6 +1018,7 @@ static int vpif_reqbufs(struct file *file, void *priv,
q-mem_ops = vb2_dma_contig_memops;
q-buf_struct_size = sizeof(struct vpif_cap_buffer);
q-timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
+   q-min_buffers_needed = 1;
 
ret = vb2_queue_init(q);
 

[REVIEWv1 PATCH 02/14] vb2: fix read/write regression

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

Commit 88e268702bfba78448abd20a31129458707383aa (vb2: Improve file I/O
emulation to handle buffers in any order) broke read/write support if
the size of the buffer being read/written is less than the size of the
image.

When the commit was tested originally I used qv4l2, which calls read()
with exactly the size of the image. But if you try 'cat /dev/video0'
then it will fail and typically hang after reading two buffers.

This patch fixes the behavior by adding a new cur_index field that
contains the index of the field currently being filled/read, or it
is num_buffers in which case a new buffer needs to be dequeued.

The old index field has been renamed to initial_index in order to be
a bit more descriptive.

This has been tested with both read and write.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
Tested-by: Hans Verkuil hans.verk...@cisco.com
Cc: Andy Walls awa...@md.metrocast.net
---
 drivers/media/v4l2-core/videobuf2-core.c | 46 +++-
 1 file changed, 40 insertions(+), 6 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index a127925..f1a2857c 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -2251,6 +2251,22 @@ struct vb2_fileio_buf {
 /**
  * struct vb2_fileio_data - queue context used by file io emulator
  *
+ * @cur_index: the index of the buffer currently being read from or
+ * written to. If equal to q-num_buffers then a new buffer
+ * must be dequeued.
+ * @initial_index: in the read() case all buffers are queued up immediately
+ * in __vb2_init_fileio() and __vb2_perform_fileio() just cycles
+ * buffers. However, in the write() case no buffers are initially
+ * queued, instead whenever a buffer is full it is queued up by
+ * __vb2_perform_fileio(). Only once all available buffers have
+ * been queued up will __vb2_perform_fileio() start to dequeue
+ * buffers. This means that initially __vb2_perform_fileio()
+ * needs to know what buffer index to use when it is queuing up
+ * the buffers for the first time. That initial index is stored
+ * in this field. Once it is equal to q-num_buffers all
+ * available buffers have been queued and __vb2_perform_fileio()
+ * should start the normal dequeue/queue cycle.
+ *
  * vb2 provides a compatibility layer and emulator of file io (read and
  * write) calls on top of streaming API. For proper operation it required
  * this structure to save the driver state between each call of the read
@@ -2260,7 +2276,8 @@ struct vb2_fileio_data {
struct v4l2_requestbuffers req;
struct v4l2_buffer b;
struct vb2_fileio_buf bufs[VIDEO_MAX_FRAME];
-   unsigned int index;
+   unsigned int cur_index;
+   unsigned int initial_index;
unsigned int q_count;
unsigned int dq_count;
unsigned int flags;
@@ -2360,7 +2377,12 @@ static int __vb2_init_fileio(struct vb2_queue *q, int 
read)
goto err_reqbufs;
fileio-bufs[i].queued = 1;
}
-   fileio-index = q-num_buffers;
+   /*
+* All buffers have been queued, so mark that by setting
+* initial_index to q-num_buffers
+*/
+   fileio-initial_index = q-num_buffers;
+   fileio-cur_index = q-num_buffers;
}
 
/*
@@ -2439,7 +2461,7 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, 
char __user *data, size_
/*
 * Check if we need to dequeue the buffer.
 */
-   index = fileio-index;
+   index = fileio-cur_index;
if (index = q-num_buffers) {
/*
 * Call vb2_dqbuf to get buffer back.
@@ -2453,7 +2475,7 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, 
char __user *data, size_
return ret;
fileio-dq_count += 1;
 
-   index = fileio-b.index;
+   fileio-cur_index = index = fileio-b.index;
buf = fileio-bufs[index];
 
/*
@@ -2529,8 +2551,20 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, 
char __user *data, size_
buf-queued = 1;
buf-size = vb2_plane_size(q-bufs[index], 0);
fileio-q_count += 1;
-   if (fileio-index  q-num_buffers)
-   fileio-index++;
+   /*
+* If we are queuing up buffers for the first time, then
+* increase initial_index by one.
+*/
+   if (fileio-initial_index  q-num_buffers)
+   fileio-initial_index++;
+   /*
+* The next buffer to use is either a buffer that's 

Re: [PATCH v5 04/10] V4L: Add driver for s5k6a3 image sensor

2014-02-25 Thread Baruch Siach
Hi Sylwester,

On Tue, Feb 25, 2014 at 10:46:58AM +0100, Sylwester Nawrocki wrote:
 On 24/02/14 20:38, Baruch Siach wrote:
  On Mon, Feb 24, 2014 at 06:35:16PM +0100, Sylwester Nawrocki wrote:
   This patch adds subdev driver for Samsung S5K6A3 raw image sensor.
   As it is intended at the moment to be used only with the Exynos
   FIMC-IS (camera ISP) subsystem it is pretty minimal subdev driver.
   It doesn't do any I2C communication since the sensor is controlled
   by the ISP and its own firmware.
   This driver, if needed, can be updated in future into a regular
   subdev driver where the main CPU communicates with the sensor
   directly.
   
   Signed-off-by: Sylwester Nawrocki s.nawro...@samsung.com
   Acked-by: Kyungmin Park kyungmin.p...@samsung.com
 
  [...]
  
   +static int s5k6a3_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh 
   *fh)
   +{
   +struct v4l2_mbus_framefmt *format = 
   v4l2_subdev_get_try_format(fh, 0);
   +
   +*format = s5k6a3_formats[0];
   +format-width   = S5K6A3_DEFAULT_WIDTH;
   +format-height  = S5K6A3_DEFAULT_HEIGHT;
   +
   +return 0;
   +}
   +
   +static const struct v4l2_subdev_internal_ops s5k6a3_sd_internal_ops = {
   +.open = s5k6a3_open,
   +};
 
  Where is this used?
 
 This will be called when user process opens the corresponding /dev/v4l-subdev*
 device node. More details on the v4l2 sub-device interface can be found at 
 [1],
 [2]. The device node is created by an aggregate media device driver, once all
 required sub-devices are registered to it.
 The above v4l2_subdev_internal_ops::open() implementation is pretty simple,
 it just sets V4L2_SUBDEV_FORMAT_TRY format to some initial default value.
 That's a per file handle value, so each process opening a set of sub-devices
 can try pipeline configuration independently. 
 
 [1] http://linuxtv.org/downloads/v4l-dvb-apis/subdev.html
 [2] http://linuxtv.org/downloads/v4l-dvb-apis/vidioc-subdev-g-fmt.html

Thanks for the explanation. However, I've found no reference to the 
s5k6a3_sd_internal_ops struct in the driver code. There surly has to be at 
least one reference for the upper layer to access these ops.

baruch

-- 
 http://baruch.siach.name/blog/  ~. .~   Tk Open Systems
=}ooO--U--Ooo{=
   - bar...@tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFCv1 PATCH 00/20] vb2: more fixes, add dmabuf/expbuf (PART 2)

2014-02-25 Thread Hans Verkuil
Hi all,

This patch series follows on from PART 1: the REVIEWv1 vb2 patch series
just posted.

Patches 1-3 and 11-20 are various code improvements and fixes based
on extensive testing with v4l2-compliance and several test drivers
(vivi and viloop, to be posted later).

Patches 4-10 add support for dmabuf and expbuf to vb2-dma-sg and adds
expbuf support to vmalloc.

This has seen extensive testing as well, but more is needed, in particular
with 'real' hardware as opposed to virtual drivers. I hope to be able to
do some testing for that this week.

Regards,

Hans

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFCv1 PATCH 13/20] vb2: move __qbuf_mmap before __qbuf_userptr

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

__qbuf_mmap was sort of hidden in between the much larger __qbuf_userptr
and __qbuf_dmabuf functions. Move it before __qbuf_userptr which is
also conform the usual order these memory models are implemented: first
mmap, then userptr, then dmabuf.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/v4l2-core/videobuf2-core.c | 50 
 1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index 1f8ab7b..1dc1db8 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -1241,6 +1241,31 @@ static void __buf_finish_memory(struct vb2_buffer *vb)
 }
 
 /**
+ * __qbuf_mmap() - handle qbuf of an MMAP buffer
+ */
+static int __qbuf_mmap(struct vb2_buffer *vb, const struct v4l2_buffer *b)
+{
+   int ret;
+
+   __fill_vb2_buffer(vb, b, vb-v4l2_planes);
+
+   ret = __buf_prepare_memory(vb);
+   if (ret) {
+   call_vb_qop(vb, buf_cleanup, vb);
+   dprintk(1, %s: buffer memory preparation failed\n, __func__);
+   return ret;
+   }
+
+   ret = call_vb_qop(vb, buf_prepare, vb);
+   if (ret) {
+   dprintk(1, %s: buffer preparation failed\n, __func__);
+   fail_vb_qop(vb, buf_prepare);
+   __buf_finish_memory(vb);
+   }
+   return ret;
+}
+
+/**
  * __qbuf_userptr() - handle qbuf of a USERPTR buffer
  */
 static int __qbuf_userptr(struct vb2_buffer *vb, const struct v4l2_buffer *b)
@@ -1354,31 +1379,6 @@ err:
 }
 
 /**
- * __qbuf_mmap() - handle qbuf of an MMAP buffer
- */
-static int __qbuf_mmap(struct vb2_buffer *vb, const struct v4l2_buffer *b)
-{
-   int ret;
-
-   __fill_vb2_buffer(vb, b, vb-v4l2_planes);
-
-   ret = __buf_prepare_memory(vb);
-   if (ret) {
-   call_vb_qop(vb, buf_cleanup, vb);
-   dprintk(1, %s: buffer memory preparation failed\n, __func__);
-   return ret;
-   }
-
-   ret = call_vb_qop(vb, buf_prepare, vb);
-   if (ret) {
-   dprintk(1, %s: buffer preparation failed\n, __func__);
-   fail_vb_qop(vb, buf_prepare);
-   __buf_finish_memory(vb);
-   }
-   return ret;
-}
-
-/**
  * __qbuf_dmabuf() - handle qbuf of a DMABUF buffer
  */
 static int __qbuf_dmabuf(struct vb2_buffer *vb, const struct v4l2_buffer *b)
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFCv1 PATCH 15/20] vb2: replace 'write' by 'dma_dir'

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

The 'write' argument is very ambiguous. I first assumed that if it is 1,
then we're doing video output but instead it meant the reverse.

Since it is used to setup the dma_dir value anyway it is now replaced by
the correct dma_dir value which is unambiguous.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/v4l2-core/videobuf2-core.c   | 15 +
 drivers/media/v4l2-core/videobuf2-dma-contig.c | 46 ++
 drivers/media/v4l2-core/videobuf2-dma-sg.c | 46 --
 drivers/media/v4l2-core/videobuf2-vmalloc.c| 20 ++-
 include/media/videobuf2-core.h | 11 +++---
 5 files changed, 73 insertions(+), 65 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index 52f38d0..b0d1ed9 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -102,7 +102,8 @@ module_param(debug, int, 0644);
 static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
 {
struct vb2_queue *q = vb-vb2_queue;
-   int write = !V4L2_TYPE_IS_OUTPUT(q-type);
+   enum dma_data_direction dma_dir =
+   V4L2_TYPE_IS_OUTPUT(q-type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
void *mem_priv;
int plane;
 
@@ -114,7 +115,7 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
unsigned long size = PAGE_ALIGN(q-plane_sizes[plane]);
 
mem_priv = call_memop(vb, alloc, q-alloc_ctx[plane],
- size, write, q-gfp_flags);
+ size, dma_dir, q-gfp_flags);
if (IS_ERR_OR_NULL(mem_priv))
goto free;
 
@@ -1276,7 +1277,8 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const 
struct v4l2_buffer *b)
void *mem_priv;
unsigned int plane;
int ret;
-   int write = !V4L2_TYPE_IS_OUTPUT(q-type);
+   enum dma_data_direction dma_dir =
+   V4L2_TYPE_IS_OUTPUT(q-type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
bool reacquired = vb-planes[0].mem_priv == NULL;
 
/* Copy relevant information provided by the userspace */
@@ -1316,7 +1318,7 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const 
struct v4l2_buffer *b)
/* Acquire each plane's memory */
mem_priv = call_memop(vb, get_userptr, q-alloc_ctx[plane],
  planes[plane].m.userptr,
- planes[plane].length, write);
+ planes[plane].length, dma_dir);
if (IS_ERR_OR_NULL(mem_priv)) {
dprintk(1, %s: failed acquiring userspace memory for 
plane %d\n,
__func__, plane);
@@ -1389,7 +1391,8 @@ static int __qbuf_dmabuf(struct vb2_buffer *vb, const 
struct v4l2_buffer *b)
void *mem_priv;
unsigned int plane;
int ret;
-   int write = !V4L2_TYPE_IS_OUTPUT(q-type);
+   enum dma_data_direction dma_dir =
+   V4L2_TYPE_IS_OUTPUT(q-type) ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
bool reacquired = vb-planes[0].mem_priv == NULL;
 
/* Copy relevant information provided by the userspace */
@@ -1437,7 +1440,7 @@ static int __qbuf_dmabuf(struct vb2_buffer *vb, const 
struct v4l2_buffer *b)
 
/* Acquire each plane's memory */
mem_priv = call_memop(vb, attach_dmabuf, q-alloc_ctx[plane],
-   dbuf, planes[plane].length, write);
+   dbuf, planes[plane].length, dma_dir);
if (IS_ERR(mem_priv)) {
dprintk(1, %s: failed to attach dmabuf\n, __func__);
fail_memop(vb, attach_dmabuf);
diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c 
b/drivers/media/v4l2-core/videobuf2-dma-contig.c
index 604f2f4..e52a1bc 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-contig.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c
@@ -153,8 +153,8 @@ static void vb2_dc_put(void *buf_priv)
kfree(buf);
 }
 
-static void *vb2_dc_alloc(void *alloc_ctx, unsigned long size, int write,
- gfp_t gfp_flags)
+static void *vb2_dc_alloc(void *alloc_ctx, unsigned long size,
+ enum dma_data_direction dma_dir, gfp_t gfp_flags)
 {
struct vb2_dc_conf *conf = alloc_ctx;
struct device *dev = conf-dev;
@@ -175,7 +175,7 @@ static void *vb2_dc_alloc(void *alloc_ctx, unsigned long 
size, int write,
/* Prevent the device from being released while the buffer is used */
buf-dev = get_device(dev);
buf-size = size;
-   buf-dma_dir = write ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
+   buf-dma_dir = dma_dir;
 
buf-handler.refcount = buf-refcount;
buf-handler.put = vb2_dc_put;
@@ -229,7 +229,7 @@ static int vb2_dc_mmap(void *buf_priv, 

[RFCv1 PATCH 20/20] vb2: simplify a confusing condition.

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

q-start_streaming_called is always true, so the WARN_ON check against
it being false can be dropped.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/v4l2-core/videobuf2-core.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index 8ea78d6..0e40c8d 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -1081,9 +1081,8 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum 
vb2_buffer_state state)
if (!q-start_streaming_called) {
if (WARN_ON(state != VB2_BUF_STATE_QUEUED))
state = VB2_BUF_STATE_QUEUED;
-   } else if (!WARN_ON(!q-start_streaming_called)) {
-   if (WARN_ON(state != VB2_BUF_STATE_DONE 
-   state != VB2_BUF_STATE_ERROR))
+   } else if (WARN_ON(state != VB2_BUF_STATE_DONE 
+  state != VB2_BUF_STATE_ERROR)) {
state = VB2_BUF_STATE_ERROR;
}
 
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFCv1 PATCH 14/20] vb2: allow read/write as long as the format is single planar

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

It was impossible to read() or write() a frame if the queue type was 
multiplanar.
Even if the current format is single planar. Change this to just check whether
the number of planes is 1 or more.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/v4l2-core/videobuf2-core.c | 21 +
 1 file changed, 21 insertions(+)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index 1dc1db8..52f38d0 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -576,6 +576,7 @@ static void __fill_v4l2_buffer(struct vb2_buffer *vb, 
struct v4l2_buffer *b)
 * for it. The caller has already verified memory and size.
 */
b-length = vb-num_planes;
+   b-bytesused = 0;
memcpy(b-m.planes, vb-v4l2_planes,
b-length * sizeof(struct v4l2_plane));
} else {
@@ -2589,6 +2590,7 @@ struct vb2_fileio_buf {
  */
 struct vb2_fileio_data {
struct v4l2_requestbuffers req;
+   struct v4l2_plane p;
struct v4l2_buffer b;
struct vb2_fileio_buf bufs[VIDEO_MAX_FRAME];
unsigned int cur_index;
@@ -2683,8 +2685,16 @@ static int __vb2_init_fileio(struct vb2_queue *q, int 
read)
 */
for (i = 0; i  q-num_buffers; i++) {
struct v4l2_buffer *b = fileio-b;
+
memset(b, 0, sizeof(*b));
b-type = q-type;
+   if (V4L2_TYPE_IS_MULTIPLANAR(q-type)) {
+   struct v4l2_plane *p = fileio-p;
+
+   memset(p, 0, sizeof(*p));
+   b-m.planes = p;
+   b-length = 1;
+   }
b-memory = q-memory;
b-index = i;
ret = vb2_qbuf(q, b);
@@ -2784,6 +2794,11 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, 
char __user *data, size_
memset(fileio-b, 0, sizeof(fileio-b));
fileio-b.type = q-type;
fileio-b.memory = q-memory;
+   if (V4L2_TYPE_IS_MULTIPLANAR(q-type)) {
+   memset(fileio-p, 0, sizeof(fileio-p));
+   fileio-b.m.planes = fileio-p;
+   fileio-b.length = 1;
+   }
ret = vb2_internal_dqbuf(q, fileio-b, nonblock);
dprintk(5, file io: vb2_dqbuf result: %d\n, ret);
if (ret)
@@ -2854,6 +2869,12 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, 
char __user *data, size_
fileio-b.memory = q-memory;
fileio-b.index = index;
fileio-b.bytesused = buf-pos;
+   if (V4L2_TYPE_IS_MULTIPLANAR(q-type)) {
+   memset(fileio-p, 0, sizeof(fileio-p));
+   fileio-p.bytesused = buf-pos;
+   fileio-b.m.planes = fileio-p;
+   fileio-b.length = 1;
+   }
ret = vb2_internal_qbuf(q, fileio-b);
dprintk(5, file io: vb2_dbuf result: %d\n, ret);
if (ret)
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFCv1 PATCH 17/20] vb2: set timestamp when using write()

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

When using write() to write data to an output video node the vb2 core
should set timestamps if V4L2_BUF_FLAG_TIMESTAMP_COPY is set. Nobody
else is able to provide this information with the write() operation.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/v4l2-core/videobuf2-core.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index 2ac98ff..db95dcb 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -22,6 +22,7 @@
 #include media/v4l2-dev.h
 #include media/v4l2-fh.h
 #include media/v4l2-event.h
+#include media/v4l2-common.h
 #include media/videobuf2-core.h
 
 static int debug;
@@ -2797,6 +2798,8 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, 
char __user *data, size_
 {
struct vb2_fileio_data *fileio;
struct vb2_fileio_buf *buf;
+   bool set_timestamp = !read 
+   q-timestamp_type == V4L2_BUF_FLAG_TIMESTAMP_COPY;
int ret, index;
 
dprintk(3, file io: mode %s, offset %ld, count %zd, %sblocking\n,
@@ -2909,6 +2912,8 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, 
char __user *data, size_
fileio-b.m.planes = fileio-p;
fileio-b.length = 1;
}
+   if (set_timestamp)
+   v4l2_get_timestamp(fileio-b.timestamp);
ret = vb2_internal_qbuf(q, fileio-b);
dprintk(5, file io: vb2_dbuf result: %d\n, ret);
if (ret)
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFCv1 PATCH 19/20] vb2: add vb2_fileio_is_active and check it more often

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

Added a vb2_fileio_is_active inline function that returns true if fileio
is in progress. Use it in the source. Check for this too in mmap() (you
don't want apps mmap()ing buffers used by fileio) and expbuf() (same reason).

In addition drivers should be able to check for this in queue_setup() to
return an error if an attempt is made to read() or write() with
V4L2_FIELD_ALTERNATE being configured. This is illegal (there is no way
to pass the TOP/BOTTOM information around using file I/O).

However, in order to be able to check for this the init_fileio function
needs to set q-fileio early on, before the buffers are allocated. So switch
to using internal functions (__reqbufs, vb2_internal_qbuf and
vb2_internal_streamon) to skip the fileio check. Well, that's why the internal
functions were created...

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/v4l2-core/videobuf2-core.c | 35 
 include/media/videobuf2-core.h   | 17 
 2 files changed, 39 insertions(+), 13 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index face6e9..8ea78d6 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -747,7 +747,7 @@ static int __verify_memory_type(struct vb2_queue *q,
 * create_bufs is called with count == 0, but count == 0 should still
 * do the memory and type validation.
 */
-   if (q-fileio) {
+   if (vb2_fileio_is_active(q)) {
dprintk(1, reqbufs: file io in progress\n);
return -EBUSY;
}
@@ -1658,7 +1658,7 @@ int vb2_prepare_buf(struct vb2_queue *q, struct 
v4l2_buffer *b)
struct vb2_buffer *vb;
int ret;
 
-   if (q-fileio) {
+   if (vb2_fileio_is_active(q)) {
dprintk(1, %s(): file io in progress\n, __func__);
return -EBUSY;
}
@@ -1827,7 +1827,7 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct 
v4l2_buffer *b)
  */
 int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
 {
-   if (q-fileio) {
+   if (vb2_fileio_is_active(q)) {
dprintk(1, %s(): file io in progress\n, __func__);
return -EBUSY;
}
@@ -2047,7 +2047,7 @@ static int vb2_internal_dqbuf(struct vb2_queue *q, struct 
v4l2_buffer *b, bool n
  */
 int vb2_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking)
 {
-   if (q-fileio) {
+   if (vb2_fileio_is_active(q)) {
dprintk(1, dqbuf: file io in progress\n);
return -EBUSY;
}
@@ -2173,7 +2173,7 @@ static int vb2_internal_streamon(struct vb2_queue *q, 
enum v4l2_buf_type type)
  */
 int vb2_streamon(struct vb2_queue *q, enum v4l2_buf_type type)
 {
-   if (q-fileio) {
+   if (vb2_fileio_is_active(q)) {
dprintk(1, streamon: file io in progress\n);
return -EBUSY;
}
@@ -2220,7 +2220,7 @@ static int vb2_internal_streamoff(struct vb2_queue *q, 
enum v4l2_buf_type type)
  */
 int vb2_streamoff(struct vb2_queue *q, enum v4l2_buf_type type)
 {
-   if (q-fileio) {
+   if (vb2_fileio_is_active(q)) {
dprintk(1, streamoff: file io in progress\n);
return -EBUSY;
}
@@ -2305,6 +2305,11 @@ int vb2_expbuf(struct vb2_queue *q, struct 
v4l2_exportbuffer *eb)
return -EINVAL;
}
 
+   if (vb2_fileio_is_active(q)) {
+   dprintk(1, expbuf: file io in progress\n);
+   return -EBUSY;
+   }
+
vb_plane = vb-planes[eb-plane];
 
dbuf = call_memop(vb, get_dmabuf, vb_plane-mem_priv, eb-flags  
O_ACCMODE);
@@ -2381,6 +2386,10 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct 
*vma)
return -EINVAL;
}
}
+   if (vb2_fileio_is_active(q)) {
+   dprintk(1, mmap: file io in progress\n);
+   return -EBUSY;
+   }
 
/*
 * Find the plane corresponding to the offset passed by userspace.
@@ -2695,7 +2704,8 @@ static int __vb2_init_fileio(struct vb2_queue *q, int 
read)
fileio-req.count = count;
fileio-req.memory = V4L2_MEMORY_MMAP;
fileio-req.type = q-type;
-   ret = vb2_reqbufs(q, fileio-req);
+   q-fileio = fileio;
+   ret = __reqbufs(q, fileio-req);
if (ret)
goto err_kfree;
 
@@ -2741,7 +2751,7 @@ static int __vb2_init_fileio(struct vb2_queue *q, int 
read)
}
b-memory = q-memory;
b-index = i;
-   ret = vb2_qbuf(q, b);
+   ret = vb2_internal_qbuf(q, b);
if (ret)
goto err_reqbufs;
fileio-bufs[i].queued = 1;
@@ -2757,19 +2767,18 @@ static int __vb2_init_fileio(struct 

[RFCv1 PATCH 03/20] vb2: if bytesused is 0, then fill with output buffer length

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

The application should really always fill in bytesused for output
buffers, unfortunately the vb2 framework never checked for that.

So for single planar formats replace a bytesused of 0 by the length
of the buffer, and for multiplanar format do the same if bytesused is
0 for ALL planes.

This seems to be what the user really intended if v4l2_buffer was
just memset to 0.

I'm afraid that just checking for this and returning an error would
break too many applications. Quite a few drivers never check for bytesused
at all and just use the buffer length instead.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/v4l2-core/videobuf2-core.c | 32 +++-
 1 file changed, 27 insertions(+), 5 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index f9ced55..8070ccc 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -1124,19 +1124,35 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, 
const struct v4l2_buffer *b
memset(v4l2_planes[plane].reserved, 0,
   sizeof(v4l2_planes[plane].reserved));
v4l2_planes[plane].data_offset = 0;
+   v4l2_planes[plane].bytesused = 0;
}
 
/* Fill in driver-provided information for OUTPUT types */
if (V4L2_TYPE_IS_OUTPUT(b-type)) {
+   bool bytesused_is_used;
+
+   /* Check if bytesused == 0 for all planes */
+   for (plane = 0; plane  vb-num_planes; ++plane)
+   if (b-m.planes[plane].bytesused)
+   break;
+   bytesused_is_used = plane  vb-num_planes;
+
/*
 * Will have to go up to b-length when API starts
 * accepting variable number of planes.
+*
+* If bytesused_is_used is false, then fall back to the
+* full buffer size. In that case userspace clearly
+* never bothered to set it and it's a safe assumption
+* that they really meant to use the full plane sizes.
 */
for (plane = 0; plane  vb-num_planes; ++plane) {
-   v4l2_planes[plane].bytesused =
-   b-m.planes[plane].bytesused;
-   v4l2_planes[plane].data_offset =
-   b-m.planes[plane].data_offset;
+   struct v4l2_plane *pdst = v4l2_planes[plane];
+   struct v4l2_plane *psrc = b-m.planes[plane];
+
+   pdst-bytesused = bytesused_is_used ?
+   psrc-bytesused : psrc-length;
+   pdst-data_offset = psrc-data_offset;
}
}
 
@@ -1162,9 +1178,15 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, 
const struct v4l2_buffer *b
 * so fill in relevant v4l2_buffer struct fields instead.
 * In videobuf we use our internal V4l2_planes struct for
 * single-planar buffers as well, for simplicity.
+*
+* If bytesused == 0, then fall back to the full buffer size
+* as that's a sensible default.
 */
if (V4L2_TYPE_IS_OUTPUT(b-type))
-   v4l2_planes[0].bytesused = b-bytesused;
+   v4l2_planes[0].bytesused =
+   b-bytesused ? b-bytesused : b-length;
+   else
+   v4l2_planes[0].bytesused = 0;
/* Single-planar buffers never use data_offset */
v4l2_planes[0].data_offset = 0;
 
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFCv1 PATCH 04/20] vb2-dma-sg: add allocation context to dma-sg

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

Require that dma-sg also uses an allocation context. This is in preparation
for adding prepare/finish memops to sync the memory between DMA and CPU.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/platform/marvell-ccic/mcam-core.c|  7 
 drivers/media/platform/marvell-ccic/mcam-core.h|  1 +
 drivers/media/v4l2-core/videobuf2-core.c   |  3 +-
 drivers/media/v4l2-core/videobuf2-dma-contig.c |  4 +-
 drivers/media/v4l2-core/videobuf2-dma-sg.c | 44 +-
 drivers/media/v4l2-core/videobuf2-vmalloc.c|  3 +-
 drivers/staging/media/solo6x10/solo6x10-v4l2-enc.c | 10 +
 drivers/staging/media/solo6x10/solo6x10.h  |  1 +
 include/media/videobuf2-core.h |  3 +-
 include/media/videobuf2-dma-sg.h   |  3 ++
 10 files changed, 73 insertions(+), 6 deletions(-)

diff --git a/drivers/media/platform/marvell-ccic/mcam-core.c 
b/drivers/media/platform/marvell-ccic/mcam-core.c
index be4b512..99961bf 100644
--- a/drivers/media/platform/marvell-ccic/mcam-core.c
+++ b/drivers/media/platform/marvell-ccic/mcam-core.c
@@ -1080,6 +1080,8 @@ static int mcam_vb_queue_setup(struct vb2_queue *vq,
*nbufs = minbufs;
if (cam-buffer_mode == B_DMA_contig)
alloc_ctxs[0] = cam-vb_alloc_ctx;
+   else if (cam-buffer_mode == B_DMA_sg)
+   alloc_ctxs[0] = cam-vb_alloc_ctx_sg;
return 0;
 }
 
@@ -1298,6 +1300,7 @@ static int mcam_setup_vb2(struct mcam_camera *cam)
vq-ops = mcam_vb2_sg_ops;
vq-mem_ops = vb2_dma_sg_memops;
vq-buf_struct_size = sizeof(struct mcam_vb_buffer);
+   cam-vb_alloc_ctx_sg = vb2_dma_sg_init_ctx(cam-dev);
vq-io_modes = VB2_MMAP | VB2_USERPTR;
cam-dma_setup = mcam_ctlr_dma_sg;
cam-frame_complete = mcam_dma_sg_done;
@@ -1326,6 +1329,10 @@ static void mcam_cleanup_vb2(struct mcam_camera *cam)
if (cam-buffer_mode == B_DMA_contig)
vb2_dma_contig_cleanup_ctx(cam-vb_alloc_ctx);
 #endif
+#ifdef MCAM_MODE_DMA_SG
+   if (cam-buffer_mode == B_DMA_sg)
+   vb2_dma_sg_cleanup_ctx(cam-vb_alloc_ctx_sg);
+#endif
 }
 
 
diff --git a/drivers/media/platform/marvell-ccic/mcam-core.h 
b/drivers/media/platform/marvell-ccic/mcam-core.h
index e0e628c..7b8c201 100644
--- a/drivers/media/platform/marvell-ccic/mcam-core.h
+++ b/drivers/media/platform/marvell-ccic/mcam-core.h
@@ -176,6 +176,7 @@ struct mcam_camera {
/* DMA buffers - DMA modes */
struct mcam_vb_buffer *vb_bufs[MAX_DMA_BUFS];
struct vb2_alloc_ctx *vb_alloc_ctx;
+   struct vb2_alloc_ctx *vb_alloc_ctx_sg;
 
/* Mode-specific ops, set at open time */
void (*dma_setup)(struct mcam_camera *cam);
diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index 8070ccc..bb36fe5 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -102,6 +102,7 @@ module_param(debug, int, 0644);
 static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
 {
struct vb2_queue *q = vb-vb2_queue;
+   int write = !V4L2_TYPE_IS_OUTPUT(q-type);
void *mem_priv;
int plane;
 
@@ -113,7 +114,7 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
unsigned long size = PAGE_ALIGN(q-plane_sizes[plane]);
 
mem_priv = call_memop(vb, alloc, q-alloc_ctx[plane],
- size, q-gfp_flags);
+ size, write, q-gfp_flags);
if (IS_ERR_OR_NULL(mem_priv))
goto free;
 
diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c 
b/drivers/media/v4l2-core/videobuf2-dma-contig.c
index 33d3871d..1e994a9 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-contig.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c
@@ -152,7 +152,8 @@ static void vb2_dc_put(void *buf_priv)
kfree(buf);
 }
 
-static void *vb2_dc_alloc(void *alloc_ctx, unsigned long size, gfp_t gfp_flags)
+static void *vb2_dc_alloc(void *alloc_ctx, unsigned long size, int write,
+ gfp_t gfp_flags)
 {
struct vb2_dc_conf *conf = alloc_ctx;
struct device *dev = conf-dev;
@@ -173,6 +174,7 @@ static void *vb2_dc_alloc(void *alloc_ctx, unsigned long 
size, gfp_t gfp_flags)
/* Prevent the device from being released while the buffer is used */
buf-dev = get_device(dev);
buf-size = size;
+   buf-dma_dir = write ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
 
buf-handler.refcount = buf-refcount;
buf-handler.put = vb2_dc_put;
diff --git a/drivers/media/v4l2-core/videobuf2-dma-sg.c 
b/drivers/media/v4l2-core/videobuf2-dma-sg.c
index c779f21..92b54fa 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-sg.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-sg.c

[RFCv1 PATCH 05/20] vb2-dma-sg: add prepare/finish memops

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

Now that vb2-dma-sg will sync the buffers for you in the prepare/finish
memops we can drop that from the drivers that use dma-sg.

For the solo6x10 driver that was a bit more involved because it needs to
copy JPEG or MPEG headers to the buffer before returning it to userspace,
and that cannot be done in the old place since the buffer there is still
setup for DMA access, not for CPU access. However, the buf_finish op is
the ideal place to do this. By the time buf_finish is called the buffer
is available for CPU access, so copying to the buffer is fine.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/platform/marvell-ccic/mcam-core.c| 18 +---
 drivers/media/v4l2-core/videobuf2-dma-sg.c | 18 
 drivers/staging/media/solo6x10/solo6x10-v4l2-enc.c | 48 ++
 3 files changed, 41 insertions(+), 43 deletions(-)

diff --git a/drivers/media/platform/marvell-ccic/mcam-core.c 
b/drivers/media/platform/marvell-ccic/mcam-core.c
index 99961bf..a21f291 100644
--- a/drivers/media/platform/marvell-ccic/mcam-core.c
+++ b/drivers/media/platform/marvell-ccic/mcam-core.c
@@ -1221,17 +1221,12 @@ static int mcam_vb_sg_buf_init(struct vb2_buffer *vb)
 static int mcam_vb_sg_buf_prepare(struct vb2_buffer *vb)
 {
struct mcam_vb_buffer *mvb = vb_to_mvb(vb);
-   struct mcam_camera *cam = vb2_get_drv_priv(vb-vb2_queue);
struct sg_table *sg_table = vb2_dma_sg_plane_desc(vb, 0);
struct mcam_dma_desc *desc = mvb-dma_desc;
struct scatterlist *sg;
int i;
 
-   mvb-dma_desc_nent = dma_map_sg(cam-dev, sg_table-sgl,
-   sg_table-nents, DMA_FROM_DEVICE);
-   if (mvb-dma_desc_nent = 0)
-   return -EIO;  /* Not sure what's right here */
-   for_each_sg(sg_table-sgl, sg, mvb-dma_desc_nent, i) {
+   for_each_sg(sg_table-sgl, sg, sg_table-nents, i) {
desc-dma_addr = sg_dma_address(sg);
desc-segment_len = sg_dma_len(sg);
desc++;
@@ -1239,16 +1234,6 @@ static int mcam_vb_sg_buf_prepare(struct vb2_buffer *vb)
return 0;
 }
 
-static void mcam_vb_sg_buf_finish(struct vb2_buffer *vb)
-{
-   struct mcam_camera *cam = vb2_get_drv_priv(vb-vb2_queue);
-   struct sg_table *sg_table = vb2_dma_sg_plane_desc(vb, 0);
-
-   if (sg_table)
-   dma_unmap_sg(cam-dev, sg_table-sgl,
-   sg_table-nents, DMA_FROM_DEVICE);
-}
-
 static void mcam_vb_sg_buf_cleanup(struct vb2_buffer *vb)
 {
struct mcam_camera *cam = vb2_get_drv_priv(vb-vb2_queue);
@@ -1265,7 +1250,6 @@ static const struct vb2_ops mcam_vb2_sg_ops = {
.buf_init   = mcam_vb_sg_buf_init,
.buf_prepare= mcam_vb_sg_buf_prepare,
.buf_queue  = mcam_vb_buf_queue,
-   .buf_finish = mcam_vb_sg_buf_finish,
.buf_cleanup= mcam_vb_sg_buf_cleanup,
.start_streaming= mcam_vb_start_streaming,
.stop_streaming = mcam_vb_stop_streaming,
diff --git a/drivers/media/v4l2-core/videobuf2-dma-sg.c 
b/drivers/media/v4l2-core/videobuf2-dma-sg.c
index 92b54fa..c7e0eca 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-sg.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-sg.c
@@ -170,6 +170,22 @@ static void vb2_dma_sg_put(void *buf_priv)
}
 }
 
+static void vb2_dma_sg_prepare(void *buf_priv)
+{
+   struct vb2_dma_sg_buf *buf = buf_priv;
+   struct sg_table *sgt = buf-sg_table;
+
+   dma_map_sg(buf-dev, sgt-sgl, sgt-nents, buf-dma_dir);
+}
+
+static void vb2_dma_sg_finish(void *buf_priv)
+{
+   struct vb2_dma_sg_buf *buf = buf_priv;
+   struct sg_table *sgt = buf-sg_table;
+
+   dma_unmap_sg(buf-dev, sgt-sgl, sgt-nents, buf-dma_dir);
+}
+
 static inline int vma_is_io(struct vm_area_struct *vma)
 {
return !!(vma-vm_flags  (VM_IO | VM_PFNMAP));
@@ -366,6 +382,8 @@ const struct vb2_mem_ops vb2_dma_sg_memops = {
.put= vb2_dma_sg_put,
.get_userptr= vb2_dma_sg_get_userptr,
.put_userptr= vb2_dma_sg_put_userptr,
+   .prepare= vb2_dma_sg_prepare,
+   .finish = vb2_dma_sg_finish,
.vaddr  = vb2_dma_sg_vaddr,
.mmap   = vb2_dma_sg_mmap,
.num_users  = vb2_dma_sg_num_users,
diff --git a/drivers/staging/media/solo6x10/solo6x10-v4l2-enc.c 
b/drivers/staging/media/solo6x10/solo6x10-v4l2-enc.c
index efa6772..0361f28 100644
--- a/drivers/staging/media/solo6x10/solo6x10-v4l2-enc.c
+++ b/drivers/staging/media/solo6x10/solo6x10-v4l2-enc.c
@@ -465,7 +465,6 @@ static int solo_fill_jpeg(struct solo_enc_dev *solo_enc,
struct solo_dev *solo_dev = solo_enc-solo_dev;
struct sg_table *vbuf = vb2_dma_sg_plane_desc(vb, 0);
int frame_size;
-   int ret;
 
vb-v4l2_buf.flags |= V4L2_BUF_FLAG_KEYFRAME;
 
@@ -476,21 +475,10 @@ static int solo_fill_jpeg(struct 

[RFCv1 PATCH 11/20] vb2: improve buf_prepare/finish comments

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

Clarify in the buf_prepare/finish ops what the dma mapping status is of
the provided buffer.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 include/media/videobuf2-core.h | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
index a0dedc1..169e111 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-core.h
@@ -274,12 +274,14 @@ struct vb2_buffer {
  * operation in this callback; drivers that support
  * VIDIOC_CREATE_BUFS must also validate the buffer size;
  * if an error is returned, the buffer will not be queued
- * in driver; optional.
+ * in driver; any necessary DMA mapping action will have
+ * been done before this is called; optional.
  * @buf_finish:called before every dequeue of the buffer back 
to
  * userspace; drivers may perform any operations required
- * before userspace accesses the buffer; optional. Note:
- * this op can be called as well when vb2_is_streaming()
- * returns false!
+ * before userspace accesses the buffer; any necessary DMA
+ * unmapping action will have been done before this is
+ * called; optional. Note: this op can be called as well
+ * when vb2_is_streaming() returns false!
  * @buf_cleanup:   called once before the buffer is freed; drivers may
  * perform any additional cleanup; optional.
  * @start_streaming:   called once to enter 'streaming' state; the driver may
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFCv1 PATCH 06/20] vb2: memop prepare: return errors

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

For vb2-dma-sg the dma_map_sg function can return an error. This means that
the prepare memop also needs to change so an error can be returned.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/v4l2-core/videobuf2-dma-contig.c | 5 +++--
 drivers/media/v4l2-core/videobuf2-dma-sg.c | 4 ++--
 include/media/videobuf2-core.h | 2 +-
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c 
b/drivers/media/v4l2-core/videobuf2-dma-contig.c
index 1e994a9..604f2f4 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-contig.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c
@@ -108,16 +108,17 @@ static unsigned int vb2_dc_num_users(void *buf_priv)
return atomic_read(buf-refcount);
 }
 
-static void vb2_dc_prepare(void *buf_priv)
+static int vb2_dc_prepare(void *buf_priv)
 {
struct vb2_dc_buf *buf = buf_priv;
struct sg_table *sgt = buf-dma_sgt;
 
/* DMABUF exporter will flush the cache for us */
if (!sgt || buf-db_attach)
-   return;
+   return 0;
 
dma_sync_sg_for_device(buf-dev, sgt-sgl, sgt-nents, buf-dma_dir);
+   return 0;
 }
 
 static void vb2_dc_finish(void *buf_priv)
diff --git a/drivers/media/v4l2-core/videobuf2-dma-sg.c 
b/drivers/media/v4l2-core/videobuf2-dma-sg.c
index c7e0eca..c54df54 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-sg.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-sg.c
@@ -170,12 +170,12 @@ static void vb2_dma_sg_put(void *buf_priv)
}
 }
 
-static void vb2_dma_sg_prepare(void *buf_priv)
+static int vb2_dma_sg_prepare(void *buf_priv)
 {
struct vb2_dma_sg_buf *buf = buf_priv;
struct sg_table *sgt = buf-sg_table;
 
-   dma_map_sg(buf-dev, sgt-sgl, sgt-nents, buf-dma_dir);
+   return dma_map_sg(buf-dev, sgt-sgl, sgt-nents, buf-dma_dir) ? 0 : 
-EIO;
 }
 
 static void vb2_dma_sg_finish(void *buf_priv)
diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
index 4b7fed0..a0dedc1 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-core.h
@@ -90,7 +90,7 @@ struct vb2_mem_ops {
unsigned long size, int write);
void(*put_userptr)(void *buf_priv);
 
-   void(*prepare)(void *buf_priv);
+   int (*prepare)(void *buf_priv);
void(*finish)(void *buf_priv);
 
void*(*attach_dmabuf)(void *alloc_ctx, struct dma_buf *dbuf,
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFCv1 PATCH 07/20] vb2: call memop prepare before the buf_prepare op is called

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

The prepare memop now returns an error, so we need to be able to handle that.
In addition, prepare has to be called before buf_prepare since in the dma-sg
case buf_prepare expects that the dma memory is mapped and it can use the
sg_table.

So call the prepare memop before calling buf_prepare and clean up the memory
in case of an error.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/v4l2-core/videobuf2-core.c | 67 +---
 1 file changed, 61 insertions(+), 6 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index bb36fe5..0e0d2a8 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -1207,6 +1207,39 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, 
const struct v4l2_buffer *b
vb-v4l2_buf.flags = b-flags  ~V4L2_BUFFER_MASK_FLAGS;
 }
 
+/*
+ * __buf_prepare_memory() - prepare (sync) a vb2_buffer so it can be enqueued
+ */
+static int __buf_prepare_memory(struct vb2_buffer *vb)
+{
+   unsigned int plane;
+   int err;
+
+   /* sync buffers */
+   for (plane = 0; plane  vb-num_planes; ++plane) {
+   err = call_memop(vb, prepare, vb-planes[plane].mem_priv);
+   if (err) {
+   fail_memop(vb, prepare);
+   for (; plane; plane--)
+   call_memop(vb, finish, vb-planes[plane - 
1].mem_priv);
+   return err;
+   }
+   }
+   return 0;
+}
+
+/*
+ * __buf_finish_memory() - finish (unsync) a vb2_buffer
+ */
+static void __buf_finish_memory(struct vb2_buffer *vb)
+{
+   unsigned int plane;
+
+   /* unsync buffers */
+   for (plane = 0; plane  vb-num_planes; ++plane)
+   call_memop(vb, finish, vb-planes[plane].mem_priv);
+}
+
 /**
  * __qbuf_userptr() - handle qbuf of a USERPTR buffer
  */
@@ -1290,10 +1323,18 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const 
struct v4l2_buffer *b)
}
}
 
+   ret = __buf_prepare_memory(vb);
+   if (ret) {
+   call_vb_qop(vb, buf_cleanup, vb);
+   dprintk(1, qbuf: buffer memory preparation failed\n);
+   goto err;
+   }
+
ret = call_vb_qop(vb, buf_prepare, vb);
if (ret) {
dprintk(1, qbuf: buffer preparation failed\n);
fail_vb_qop(vb, buf_prepare);
+   __buf_finish_memory(vb);
call_vb_qop(vb, buf_cleanup, vb);
goto err;
}
@@ -1320,9 +1361,20 @@ static int __qbuf_mmap(struct vb2_buffer *vb, const 
struct v4l2_buffer *b)
int ret;
 
__fill_vb2_buffer(vb, b, vb-v4l2_planes);
+
+   ret = __buf_prepare_memory(vb);
+   if (ret) {
+   call_vb_qop(vb, buf_cleanup, vb);
+   dprintk(1, qbuf: buffer memory preparation failed\n);
+   return ret;
+   }
+
ret = call_vb_qop(vb, buf_prepare, vb);
-   if (ret)
+   if (ret) {
+   dprintk(1, %s: buffer preparation failed\n, __func__);
fail_vb_qop(vb, buf_prepare);
+   __buf_finish_memory(vb);
+   }
return ret;
 }
 
@@ -1431,10 +1483,18 @@ static int __qbuf_dmabuf(struct vb2_buffer *vb, const 
struct v4l2_buffer *b)
}
}
 
+   ret = __buf_prepare_memory(vb);
+   if (ret) {
+   call_vb_qop(vb, buf_cleanup, vb);
+   dprintk(1, qbuf: buffer memory preparation failed\n);
+   goto err;
+   }
+
ret = call_vb_qop(vb, buf_prepare, vb);
if (ret) {
dprintk(1, qbuf: buffer preparation failed\n);
fail_vb_qop(vb, buf_prepare);
+   __buf_finish_memory(vb);
call_vb_qop(vb, buf_cleanup, vb);
goto err;
}
@@ -1453,15 +1513,10 @@ err:
 static void __enqueue_in_driver(struct vb2_buffer *vb)
 {
struct vb2_queue *q = vb-vb2_queue;
-   unsigned int plane;
 
vb-state = VB2_BUF_STATE_ACTIVE;
atomic_inc(q-owned_by_drv_count);
 
-   /* sync buffers */
-   for (plane = 0; plane  vb-num_planes; ++plane)
-   call_memop(vb, prepare, vb-planes[plane].mem_priv);
-
call_vb_qop(vb, buf_queue, vb);
 }
 
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFCv1 PATCH 09/20] vb2-dma-sg: add get_dmabuf

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hansv...@cisco.com

Add DMABUF export support to vb2-dma-sg.

Signed-off-by: Hans Verkuil hansv...@cisco.com
---
 drivers/media/v4l2-core/videobuf2-dma-sg.c | 170 +
 1 file changed, 170 insertions(+)

diff --git a/drivers/media/v4l2-core/videobuf2-dma-sg.c 
b/drivers/media/v4l2-core/videobuf2-dma-sg.c
index 075acbe..3efa27c 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-sg.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-sg.c
@@ -385,6 +385,175 @@ static int vb2_dma_sg_mmap(void *buf_priv, struct 
vm_area_struct *vma)
 }
 
 /*/
+/* DMABUF ops for exporters  */
+/*/
+
+struct vb2_dma_sg_attachment {
+   struct sg_table sgt;
+   enum dma_data_direction dir;
+};
+
+static int vb2_dma_sg_dmabuf_ops_attach(struct dma_buf *dbuf, struct device 
*dev,
+   struct dma_buf_attachment *dbuf_attach)
+{
+   struct vb2_dma_sg_attachment *attach;
+   unsigned int i;
+   struct scatterlist *rd, *wr;
+   struct sg_table *sgt;
+   struct vb2_dma_sg_buf *buf = dbuf-priv;
+   int ret;
+
+   attach = kzalloc(sizeof(*attach), GFP_KERNEL);
+   if (!attach)
+   return -ENOMEM;
+
+   sgt = attach-sgt;
+   /* Copy the buf-base_sgt scatter list to the attachment, as we can't
+* map the same scatter list to multiple attachments at the same time.
+*/
+   ret = sg_alloc_table(sgt, buf-dma_sgt-orig_nents, GFP_KERNEL);
+   if (ret) {
+   kfree(attach);
+   return -ENOMEM;
+   }
+
+   rd = buf-dma_sgt-sgl;
+   wr = sgt-sgl;
+   for (i = 0; i  sgt-orig_nents; ++i) {
+   sg_set_page(wr, sg_page(rd), rd-length, rd-offset);
+   rd = sg_next(rd);
+   wr = sg_next(wr);
+   }
+
+   attach-dir = DMA_NONE;
+   dbuf_attach-priv = attach;
+
+   return 0;
+}
+
+static void vb2_dma_sg_dmabuf_ops_detach(struct dma_buf *dbuf,
+   struct dma_buf_attachment *db_attach)
+{
+   struct vb2_dma_sg_attachment *attach = db_attach-priv;
+   struct sg_table *sgt;
+
+   if (!attach)
+   return;
+
+   sgt = attach-sgt;
+
+   /* release the scatterlist cache */
+   if (attach-dir != DMA_NONE)
+   dma_unmap_sg(db_attach-dev, sgt-sgl, sgt-orig_nents,
+   attach-dir);
+   sg_free_table(sgt);
+   kfree(attach);
+   db_attach-priv = NULL;
+}
+
+static struct sg_table *vb2_dma_sg_dmabuf_ops_map(
+   struct dma_buf_attachment *db_attach, enum dma_data_direction dir)
+{
+   struct vb2_dma_sg_attachment *attach = db_attach-priv;
+   /* stealing dmabuf mutex to serialize map/unmap operations */
+   struct mutex *lock = db_attach-dmabuf-lock;
+   struct sg_table *sgt;
+   int ret;
+
+   mutex_lock(lock);
+
+   sgt = attach-sgt;
+   /* return previously mapped sg table */
+   if (attach-dir == dir) {
+   mutex_unlock(lock);
+   return sgt;
+   }
+
+   /* release any previous cache */
+   if (attach-dir != DMA_NONE) {
+   dma_unmap_sg(db_attach-dev, sgt-sgl, sgt-orig_nents,
+   attach-dir);
+   attach-dir = DMA_NONE;
+   }
+
+   /* mapping to the client with new direction */
+   ret = dma_map_sg(db_attach-dev, sgt-sgl, sgt-orig_nents, dir);
+   if (ret = 0) {
+   pr_err(failed to map scatterlist\n);
+   mutex_unlock(lock);
+   return ERR_PTR(-EIO);
+   }
+
+   attach-dir = dir;
+
+   mutex_unlock(lock);
+
+   return sgt;
+}
+
+static void vb2_dma_sg_dmabuf_ops_unmap(struct dma_buf_attachment *db_attach,
+   struct sg_table *sgt, enum dma_data_direction dir)
+{
+   /* nothing to be done here */
+}
+
+static void vb2_dma_sg_dmabuf_ops_release(struct dma_buf *dbuf)
+{
+   /* drop reference obtained in vb2_dma_sg_get_dmabuf */
+   vb2_dma_sg_put(dbuf-priv);
+}
+
+static void *vb2_dma_sg_dmabuf_ops_kmap(struct dma_buf *dbuf, unsigned long 
pgnum)
+{
+   struct vb2_dma_sg_buf *buf = dbuf-priv;
+
+   return buf-vaddr + pgnum * PAGE_SIZE;
+}
+
+static void *vb2_dma_sg_dmabuf_ops_vmap(struct dma_buf *dbuf)
+{
+   struct vb2_dma_sg_buf *buf = dbuf-priv;
+
+   return vb2_dma_sg_vaddr(buf);
+}
+
+static int vb2_dma_sg_dmabuf_ops_mmap(struct dma_buf *dbuf,
+   struct vm_area_struct *vma)
+{
+   return vb2_dma_sg_mmap(dbuf-priv, vma);
+}
+
+static struct dma_buf_ops vb2_dma_sg_dmabuf_ops = {
+   .attach = vb2_dma_sg_dmabuf_ops_attach,
+   .detach = vb2_dma_sg_dmabuf_ops_detach,
+   .map_dma_buf = vb2_dma_sg_dmabuf_ops_map,
+   .unmap_dma_buf = vb2_dma_sg_dmabuf_ops_unmap,
+   .kmap = vb2_dma_sg_dmabuf_ops_kmap,
+   .kmap_atomic = vb2_dma_sg_dmabuf_ops_kmap,
+   .vmap = vb2_dma_sg_dmabuf_ops_vmap,
+   .mmap = 

[RFCv1 PATCH 02/20] vb2: fix handling of data_offset and v4l2_plane.reserved[]

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

The videobuf2-core did not zero the reserved array of v4l2_plane as it
should.

More serious is the fact that data_offset was not handled correctly:

- for capture devices it was never zeroed, which meant that it was
  uninitialized. Unless the driver sets it it was a completely random
  number.

- __qbuf_dmabuf had a completely incorrect length check that included
  data_offset.

- in the single-planar case data_offset was never correctly set to 0.
  The single-planar API doesn't support data_offset, so setting it
  to 0 is the right thing to do.

All these issues were found with v4l2-compliance.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/v4l2-core/videobuf2-core.c | 19 ++-
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index 2c3a7f2..f9ced55 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -1120,6 +1120,12 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, 
const struct v4l2_buffer *b
unsigned int plane;
 
if (V4L2_TYPE_IS_MULTIPLANAR(b-type)) {
+   for (plane = 0; plane  vb-num_planes; ++plane) {
+   memset(v4l2_planes[plane].reserved, 0,
+  sizeof(v4l2_planes[plane].reserved));
+   v4l2_planes[plane].data_offset = 0;
+   }
+
/* Fill in driver-provided information for OUTPUT types */
if (V4L2_TYPE_IS_OUTPUT(b-type)) {
/*
@@ -1148,8 +1154,6 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, 
const struct v4l2_buffer *b
b-m.planes[plane].m.fd;
v4l2_planes[plane].length =
b-m.planes[plane].length;
-   v4l2_planes[plane].data_offset =
-   b-m.planes[plane].data_offset;
}
}
} else {
@@ -1159,10 +1163,10 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, 
const struct v4l2_buffer *b
 * In videobuf we use our internal V4l2_planes struct for
 * single-planar buffers as well, for simplicity.
 */
-   if (V4L2_TYPE_IS_OUTPUT(b-type)) {
+   if (V4L2_TYPE_IS_OUTPUT(b-type))
v4l2_planes[0].bytesused = b-bytesused;
-   v4l2_planes[0].data_offset = 0;
-   }
+   /* Single-planar buffers never use data_offset */
+   v4l2_planes[0].data_offset = 0;
 
if (b-memory == V4L2_MEMORY_USERPTR) {
v4l2_planes[0].m.userptr = b-m.userptr;
@@ -1172,9 +1176,7 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, 
const struct v4l2_buffer *b
if (b-memory == V4L2_MEMORY_DMABUF) {
v4l2_planes[0].m.fd = b-m.fd;
v4l2_planes[0].length = b-length;
-   v4l2_planes[0].data_offset = 0;
}
-
}
 
vb-v4l2_buf.field = b-field;
@@ -1331,8 +1333,7 @@ static int __qbuf_dmabuf(struct vb2_buffer *vb, const 
struct v4l2_buffer *b)
if (planes[plane].length == 0)
planes[plane].length = dbuf-size;
 
-   if (planes[plane].length  planes[plane].data_offset +
-   q-plane_sizes[plane]) {
+   if (planes[plane].length  q-plane_sizes[plane]) {
dprintk(1, qbuf: invalid dmabuf length for plane %d\n,
plane);
ret = -EINVAL;
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFCv1 PATCH 10/20] vb2-vmalloc: add get_dmabuf support

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hansv...@cisco.com

Add support for DMABUF exporting to the vb2-vmalloc implementation.

All memory models now have support for both importing and exporting of DMABUFs.

Signed-off-by: Hans Verkuil hansv...@cisco.com
---
 drivers/media/v4l2-core/videobuf2-vmalloc.c | 174 
 1 file changed, 174 insertions(+)

diff --git a/drivers/media/v4l2-core/videobuf2-vmalloc.c 
b/drivers/media/v4l2-core/videobuf2-vmalloc.c
index d77e397..4baa11a 100644
--- a/drivers/media/v4l2-core/videobuf2-vmalloc.c
+++ b/drivers/media/v4l2-core/videobuf2-vmalloc.c
@@ -31,6 +31,9 @@ struct vb2_vmalloc_buf {
atomic_trefcount;
struct vb2_vmarea_handler   handler;
struct dma_buf  *dbuf;
+
+   /* DMABUF related */
+   struct dma_buf_attachment   *db_attach;
 };
 
 static void vb2_vmalloc_put(void *buf_priv);
@@ -210,6 +213,176 @@ static int vb2_vmalloc_mmap(void *buf_priv, struct 
vm_area_struct *vma)
 }
 
 /*/
+/* DMABUF ops for exporters  */
+/*/
+
+struct vb2_vmalloc_attachment {
+   struct sg_table sgt;
+   enum dma_data_direction dir;
+};
+
+static int vb2_vmalloc_dmabuf_ops_attach(struct dma_buf *dbuf, struct device 
*dev,
+   struct dma_buf_attachment *dbuf_attach)
+{
+   struct vb2_vmalloc_attachment *attach;
+   struct vb2_vmalloc_buf *buf = dbuf-priv;
+   int num_pages = PAGE_ALIGN(buf-size) / PAGE_SIZE;
+   struct sg_table *sgt;
+   struct scatterlist *sg;
+   void *vaddr = buf-vaddr;
+   int ret;
+   int i;
+
+   attach = kzalloc(sizeof(*attach), GFP_KERNEL);
+   if (!attach)
+   return -ENOMEM;
+
+   sgt = attach-sgt;
+   ret = sg_alloc_table(sgt, num_pages, GFP_KERNEL);
+   if (ret) {
+   kfree(attach);
+   return ret;
+   }
+   for_each_sg(sgt-sgl, sg, sgt-nents, i) {
+   struct page *page = vmalloc_to_page(vaddr);
+
+   if (!page) {
+   sg_free_table(sgt);
+   kfree(attach);
+   return -ENOMEM;
+   }
+   sg_set_page(sg, page, PAGE_SIZE, 0);
+   vaddr += PAGE_SIZE;
+   }
+
+   attach-dir = DMA_NONE;
+   dbuf_attach-priv = attach;
+   return 0;
+}
+
+static void vb2_vmalloc_dmabuf_ops_detach(struct dma_buf *dbuf,
+   struct dma_buf_attachment *db_attach)
+{
+   struct vb2_vmalloc_attachment *attach = db_attach-priv;
+   struct sg_table *sgt;
+
+   if (!attach)
+   return;
+
+   sgt = attach-sgt;
+
+   /* release the scatterlist cache */
+   if (attach-dir != DMA_NONE)
+   dma_unmap_sg(db_attach-dev, sgt-sgl, sgt-orig_nents,
+   attach-dir);
+   sg_free_table(sgt);
+   kfree(attach);
+   db_attach-priv = NULL;
+}
+
+static struct sg_table *vb2_vmalloc_dmabuf_ops_map(
+   struct dma_buf_attachment *db_attach, enum dma_data_direction dir)
+{
+   struct vb2_vmalloc_attachment *attach = db_attach-priv;
+   /* stealing dmabuf mutex to serialize map/unmap operations */
+   struct mutex *lock = db_attach-dmabuf-lock;
+   struct sg_table *sgt;
+   int ret;
+
+   mutex_lock(lock);
+
+   sgt = attach-sgt;
+   /* return previously mapped sg table */
+   if (attach-dir == dir) {
+   mutex_unlock(lock);
+   return sgt;
+   }
+
+   /* release any previous cache */
+   if (attach-dir != DMA_NONE) {
+   dma_unmap_sg(db_attach-dev, sgt-sgl, sgt-orig_nents,
+   attach-dir);
+   attach-dir = DMA_NONE;
+   }
+
+   /* mapping to the client with new direction */
+   ret = dma_map_sg(db_attach-dev, sgt-sgl, sgt-orig_nents, dir);
+   if (ret = 0) {
+   pr_err(failed to map scatterlist\n);
+   mutex_unlock(lock);
+   return ERR_PTR(-EIO);
+   }
+
+   attach-dir = dir;
+
+   mutex_unlock(lock);
+
+   return sgt;
+}
+
+static void vb2_vmalloc_dmabuf_ops_unmap(struct dma_buf_attachment *db_attach,
+   struct sg_table *sgt, enum dma_data_direction dir)
+{
+   /* nothing to be done here */
+}
+
+static void vb2_vmalloc_dmabuf_ops_release(struct dma_buf *dbuf)
+{
+   /* drop reference obtained in vb2_vmalloc_get_dmabuf */
+   vb2_vmalloc_put(dbuf-priv);
+}
+
+static void *vb2_vmalloc_dmabuf_ops_kmap(struct dma_buf *dbuf, unsigned long 
pgnum)
+{
+   struct vb2_vmalloc_buf *buf = dbuf-priv;
+
+   return buf-vaddr + pgnum * PAGE_SIZE;
+}
+
+static void *vb2_vmalloc_dmabuf_ops_vmap(struct dma_buf *dbuf)
+{
+   struct vb2_vmalloc_buf *buf = dbuf-priv;
+
+   return buf-vaddr;
+}
+
+static int vb2_vmalloc_dmabuf_ops_mmap(struct dma_buf *dbuf,
+   struct vm_area_struct *vma)
+{
+   return 

[RFCv1 PATCH 08/20] vb2-dma-sg: add dmabuf import support

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

Add support for dmabuf to vb2-dma-sg.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/v4l2-core/videobuf2-dma-sg.c | 125 +++--
 1 file changed, 118 insertions(+), 7 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-dma-sg.c 
b/drivers/media/v4l2-core/videobuf2-dma-sg.c
index c54df54..075acbe 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-sg.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-sg.c
@@ -42,11 +42,15 @@ struct vb2_dma_sg_buf {
int offset;
enum dma_data_direction dma_dir;
struct sg_table sg_table;
+   struct sg_table *dma_sgt;
size_t  size;
unsigned intnum_pages;
atomic_trefcount;
struct vb2_vmarea_handler   handler;
struct vm_area_struct   *vma;
+
+   /* DMABUF related */
+   struct dma_buf_attachment   *db_attach;
 };
 
 static void vb2_dma_sg_put(void *buf_priv);
@@ -113,6 +117,7 @@ static void *vb2_dma_sg_alloc(void *alloc_ctx, unsigned 
long size, int write,
/* size is already page aligned */
buf-num_pages = size  PAGE_SHIFT;
buf-dma_dir = write ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
+   buf-dma_sgt = buf-sg_table;
 
buf-pages = kzalloc(buf-num_pages * sizeof(struct page *),
 GFP_KERNEL);
@@ -123,7 +128,7 @@ static void *vb2_dma_sg_alloc(void *alloc_ctx, unsigned 
long size, int write,
if (ret)
goto fail_pages_alloc;
 
-   ret = sg_alloc_table_from_pages(buf-sg_table, buf-pages,
+   ret = sg_alloc_table_from_pages(buf-dma_sgt, buf-pages,
buf-num_pages, 0, size, gfp_flags);
if (ret)
goto fail_table_alloc;
@@ -161,7 +166,7 @@ static void vb2_dma_sg_put(void *buf_priv)
buf-num_pages);
if (buf-vaddr)
vm_unmap_ram(buf-vaddr, buf-num_pages);
-   sg_free_table(buf-sg_table);
+   sg_free_table(buf-dma_sgt);
while (--i = 0)
__free_page(buf-pages[i]);
kfree(buf-pages);
@@ -173,7 +178,11 @@ static void vb2_dma_sg_put(void *buf_priv)
 static int vb2_dma_sg_prepare(void *buf_priv)
 {
struct vb2_dma_sg_buf *buf = buf_priv;
-   struct sg_table *sgt = buf-sg_table;
+   struct sg_table *sgt = buf-dma_sgt;
+
+   /* DMABUF exporter will flush the cache for us */
+   if (buf-db_attach)
+   return 0;
 
return dma_map_sg(buf-dev, sgt-sgl, sgt-nents, buf-dma_dir) ? 0 : 
-EIO;
 }
@@ -181,7 +190,11 @@ static int vb2_dma_sg_prepare(void *buf_priv)
 static void vb2_dma_sg_finish(void *buf_priv)
 {
struct vb2_dma_sg_buf *buf = buf_priv;
-   struct sg_table *sgt = buf-sg_table;
+   struct sg_table *sgt = buf-dma_sgt;
+
+   /* DMABUF exporter will flush the cache for us */
+   if (buf-db_attach)
+   return;
 
dma_unmap_sg(buf-dev, sgt-sgl, sgt-nents, buf-dma_dir);
 }
@@ -209,6 +222,7 @@ static void *vb2_dma_sg_get_userptr(void *alloc_ctx, 
unsigned long vaddr,
buf-offset = vaddr  ~PAGE_MASK;
buf-size = size;
buf-dma_dir = write ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
+   buf-dma_sgt = buf-sg_table;
 
first = (vaddrPAGE_MASK)  PAGE_SHIFT;
last  = ((vaddr + size - 1)  PAGE_MASK)  PAGE_SHIFT;
@@ -261,7 +275,7 @@ static void *vb2_dma_sg_get_userptr(void *alloc_ctx, 
unsigned long vaddr,
if (num_pages_from_user != buf-num_pages)
goto userptr_fail_get_user_pages;
 
-   if (sg_alloc_table_from_pages(buf-sg_table, buf-pages,
+   if (sg_alloc_table_from_pages(buf-dma_sgt, buf-pages,
buf-num_pages, buf-offset, size, 0))
goto userptr_fail_alloc_table_from_pages;
 
@@ -297,7 +311,7 @@ static void vb2_dma_sg_put_userptr(void *buf_priv)
   __func__, buf-num_pages);
if (buf-vaddr)
vm_unmap_ram(buf-vaddr, buf-num_pages);
-   sg_free_table(buf-sg_table);
+   sg_free_table(buf-dma_sgt);
while (--i = 0) {
if (buf-write)
set_page_dirty_lock(buf-pages[i]);
@@ -370,11 +384,104 @@ static int vb2_dma_sg_mmap(void *buf_priv, struct 
vm_area_struct *vma)
return 0;
 }
 
+/*/
+/*   callbacks for DMABUF buffers*/
+/*/
+
+static int vb2_dma_sg_map_dmabuf(void *mem_priv)
+{
+   struct vb2_dma_sg_buf *buf = mem_priv;
+   struct sg_table *sgt;
+
+   if (WARN_ON(!buf-db_attach)) {
+   pr_err(trying to pin a non attached buffer\n);
+   return -EINVAL;
+   }
+
+   if (WARN_ON(buf-dma_sgt)) {
+   

[RFCv1 PATCH 16/20] vb2: fix timecode and flags handling for output buffers

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

When sending a buffer to a video output device some of the fields need
to be copied so they arrive in the driver. These are the KEY/P/BFRAME
flags and the TIMECODE flag, and, if that flag is set, the timecode field
itself.

There are a number of functions involved in this: the __fill_vb2_buffer()
is called while preparing a buffer. For output buffers the buffer contains
the video data, so any meta data associated with that (KEY/P/BFRAME and
the field information) should be stored at that point.

The timecode, timecode flag and timestamp information is not part of that,
that information will have to be set when vb2_internal_qbuf() is called to
actually queue the buffer to the driver. Usually VIDIOC_QBUF will do the
prepare as well, but you can call PREPARE_BUF first and only later VIDIOC_QBUF.
You most likely will want to set the timestamp and timecode when you actually
queue the buffer, not when you prepare it.

Finally, in buf_prepare() make sure the timestamp and sequence fields are
actually cleared so that when you do a QUERYBUF of a prepared-but-not-yet-queued
buffer you will not see stale timestamp/sequence data.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/v4l2-core/videobuf2-core.c | 35 ++--
 1 file changed, 33 insertions(+), 2 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index b0d1ed9..2ac98ff 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -91,10 +91,14 @@ module_param(debug, int, 0644);
 
 #endif
 
+/* Flags that are set by the vb2 core */
 #define V4L2_BUFFER_MASK_FLAGS (V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_QUEUED | \
 V4L2_BUF_FLAG_DONE | V4L2_BUF_FLAG_ERROR | \
 V4L2_BUF_FLAG_PREPARED | \
 V4L2_BUF_FLAG_TIMESTAMP_MASK)
+/* Output buffer flags that should be passed on to the driver */
+#define V4L2_BUFFER_OUT_FLAGS  (V4L2_BUF_FLAG_PFRAME | V4L2_BUF_FLAG_BFRAME | \
+V4L2_BUF_FLAG_KEYFRAME | 
V4L2_BUF_FLAG_TIMECODE)
 
 /**
  * __vb2_buf_mem_alloc() - allocate video memory for the given buffer
@@ -1204,9 +1208,21 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, 
const struct v4l2_buffer *b
}
}
 
-   vb-v4l2_buf.field = b-field;
-   vb-v4l2_buf.timestamp = b-timestamp;
+   /* Zero flags that the vb2 core handles */
vb-v4l2_buf.flags = b-flags  ~V4L2_BUFFER_MASK_FLAGS;
+   if (V4L2_TYPE_IS_OUTPUT(b-type)) {
+   /*
+* For output buffers mask out the timecode flag:
+* this will be handled later in vb2_internal_qbuf().
+* The 'field' is valid metadata for this output buffer
+* and so that needs to be copied here.
+*/
+   vb-v4l2_buf.flags = ~V4L2_BUF_FLAG_TIMECODE;
+   vb-v4l2_buf.field = b-field;
+   } else {
+   /* Zero any output buffer flags as this is a capture buffer */
+   vb-v4l2_buf.flags = ~V4L2_BUFFER_OUT_FLAGS;
+   }
 }
 
 /*
@@ -1540,6 +1556,10 @@ static int __buf_prepare(struct vb2_buffer *vb, const 
struct v4l2_buffer *b)
}
 
vb-state = VB2_BUF_STATE_PREPARING;
+   vb-v4l2_buf.timestamp.tv_sec = 0;
+   vb-v4l2_buf.timestamp.tv_usec = 0;
+   vb-v4l2_buf.sequence = 0;
+
switch (q-memory) {
case V4L2_MEMORY_MMAP:
ret = __qbuf_mmap(vb, b);
@@ -1739,6 +1759,17 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct 
v4l2_buffer *b)
list_add_tail(vb-queued_entry, q-queued_list);
q-queued_count++;
vb-state = VB2_BUF_STATE_QUEUED;
+   if (V4L2_TYPE_IS_OUTPUT(q-type)) {
+   /*
+* For output buffers copy the timestamp if needed,
+* and the timecode field and flag if needed.
+*/
+   if (q-timestamp_type == V4L2_BUF_FLAG_TIMESTAMP_COPY)
+   vb-v4l2_buf.timestamp = b-timestamp;
+   vb-v4l2_buf.flags |= b-flags  V4L2_BUF_FLAG_TIMECODE;
+   if (b-flags  V4L2_BUF_FLAG_TIMECODE)
+   vb-v4l2_buf.timecode = b-timecode;
+   }
 
/*
 * If already streaming, give the buffer to driver for processing.
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFCv1 PATCH 12/20] vb2: use correct prefix

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

The __qbuf_mmap/userptr/dmabuf all uses similar dprintk's, all using the same
'qbuf' prefix. Replace this by the actual function name so I can see which
dprintk is actually executed.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/v4l2-core/videobuf2-core.c | 48 +---
 1 file changed, 25 insertions(+), 23 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index 0e0d2a8..1f8ab7b 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -1263,15 +1263,14 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const 
struct v4l2_buffer *b)
 vb-v4l2_planes[plane].length == planes[plane].length)
continue;
 
-   dprintk(3, qbuf: userspace address for plane %d changed, 
-   reacquiring memory\n, plane);
+   dprintk(3, %s: userspace address for plane %d changed, 
reacquiring memory\n,
+   __func__, plane);
 
/* Check if the provided plane buffer is large enough */
if (planes[plane].length  q-plane_sizes[plane]) {
-   dprintk(1, qbuf: provided buffer size %u is less than 
-   setup size %u for plane %d\n,
-   planes[plane].length,
-   q-plane_sizes[plane], plane);
+   dprintk(1, %s: provided buffer size %u is less than 
setup size %u for plane %d\n,
+   __func__, planes[plane].length,
+   q-plane_sizes[plane], plane);
ret = -EINVAL;
goto err;
}
@@ -1293,8 +1292,8 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const 
struct v4l2_buffer *b)
  planes[plane].m.userptr,
  planes[plane].length, write);
if (IS_ERR_OR_NULL(mem_priv)) {
-   dprintk(1, qbuf: failed acquiring userspace 
-   memory for plane %d\n, plane);
+   dprintk(1, %s: failed acquiring userspace memory for 
plane %d\n,
+   __func__, plane);
fail_memop(vb, get_userptr);
ret = mem_priv ? PTR_ERR(mem_priv) : -EINVAL;
goto err;
@@ -1317,7 +1316,8 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const 
struct v4l2_buffer *b)
 */
ret = call_vb_qop(vb, buf_init, vb);
if (ret) {
-   dprintk(1, qbuf: buffer initialization failed\n);
+   dprintk(1, %s: buffer initialization failed\n,
+   __func__);
fail_vb_qop(vb, buf_init);
goto err;
}
@@ -1326,13 +1326,13 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const 
struct v4l2_buffer *b)
ret = __buf_prepare_memory(vb);
if (ret) {
call_vb_qop(vb, buf_cleanup, vb);
-   dprintk(1, qbuf: buffer memory preparation failed\n);
+   dprintk(1, %s: buffer memory preparation failed\n, __func__);
goto err;
}
 
ret = call_vb_qop(vb, buf_prepare, vb);
if (ret) {
-   dprintk(1, qbuf: buffer preparation failed\n);
+   dprintk(1, %s: buffer preparation failed\n, __func__);
fail_vb_qop(vb, buf_prepare);
__buf_finish_memory(vb);
call_vb_qop(vb, buf_cleanup, vb);
@@ -1365,7 +1365,7 @@ static int __qbuf_mmap(struct vb2_buffer *vb, const 
struct v4l2_buffer *b)
ret = __buf_prepare_memory(vb);
if (ret) {
call_vb_qop(vb, buf_cleanup, vb);
-   dprintk(1, qbuf: buffer memory preparation failed\n);
+   dprintk(1, %s: buffer memory preparation failed\n, __func__);
return ret;
}
 
@@ -1398,8 +1398,8 @@ static int __qbuf_dmabuf(struct vb2_buffer *vb, const 
struct v4l2_buffer *b)
struct dma_buf *dbuf = dma_buf_get(planes[plane].m.fd);
 
if (IS_ERR_OR_NULL(dbuf)) {
-   dprintk(1, qbuf: invalid dmabuf fd for plane %d\n,
-   plane);
+   dprintk(1, %s: invalid dmabuf fd for plane %d\n,
+   __func__, plane);
ret = -EINVAL;
goto err;
}
@@ -1409,8 +1409,8 @@ static int __qbuf_dmabuf(struct vb2_buffer *vb, const 
struct v4l2_buffer *b)
planes[plane].length = dbuf-size;
 
if (planes[plane].length  

[RFCv1 PATCH 01/20] vb2: stop_streaming should return void

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

The vb2 core ignores any return code from the stop_streaming op.
And there really isn't anything it can do anyway in case of an error.
So change the return type to void and update any drivers that implement it.

The int return gave drivers the idea that this operation could actually
fail, but that's really not the case.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/pci/sta2x11/sta2x11_vip.c  | 3 +--
 drivers/media/platform/blackfin/bfin_capture.c   | 6 +-
 drivers/media/platform/coda.c| 4 +---
 drivers/media/platform/exynos-gsc/gsc-m2m.c  | 4 +---
 drivers/media/platform/exynos4-is/fimc-capture.c | 6 +++---
 drivers/media/platform/exynos4-is/fimc-lite.c| 6 +++---
 drivers/media/platform/exynos4-is/fimc-m2m.c | 3 +--
 drivers/media/platform/marvell-ccic/mcam-core.c  | 7 +++
 drivers/media/platform/s3c-camif/camif-capture.c | 4 ++--
 drivers/media/platform/s5p-jpeg/jpeg-core.c  | 4 +---
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c | 3 +--
 drivers/media/platform/s5p-mfc/s5p_mfc_enc.c | 3 +--
 drivers/media/platform/s5p-tv/mixer_video.c  | 3 +--
 drivers/media/platform/soc_camera/atmel-isi.c| 6 ++
 drivers/media/platform/soc_camera/mx2_camera.c   | 4 +---
 drivers/media/platform/soc_camera/mx3_camera.c   | 4 +---
 drivers/media/platform/soc_camera/rcar_vin.c | 4 +---
 drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c | 4 ++--
 drivers/media/platform/vivi.c| 3 +--
 drivers/media/platform/vsp1/vsp1_video.c | 4 +---
 drivers/media/usb/em28xx/em28xx-v4l.h| 2 +-
 drivers/media/usb/em28xx/em28xx-video.c  | 8 ++--
 drivers/media/usb/pwc/pwc-if.c   | 6 ++
 drivers/media/usb/stk1160/stk1160-v4l.c  | 4 ++--
 drivers/media/usb/usbtv/usbtv-video.c| 9 +++--
 drivers/staging/media/davinci_vpfe/vpfe_video.c  | 3 +--
 drivers/staging/media/dt3155v4l/dt3155v4l.c  | 3 +--
 drivers/staging/media/go7007/go7007-v4l2.c   | 3 +--
 drivers/staging/media/msi3101/sdr-msi3101.c  | 6 ++
 drivers/staging/media/solo6x10/solo6x10-v4l2-enc.c   | 3 +--
 drivers/staging/media/solo6x10/solo6x10-v4l2.c   | 3 +--
 include/media/videobuf2-core.h   | 2 +-
 32 files changed, 47 insertions(+), 90 deletions(-)

diff --git a/drivers/media/pci/sta2x11/sta2x11_vip.c 
b/drivers/media/pci/sta2x11/sta2x11_vip.c
index bb11443..7559951 100644
--- a/drivers/media/pci/sta2x11/sta2x11_vip.c
+++ b/drivers/media/pci/sta2x11/sta2x11_vip.c
@@ -357,7 +357,7 @@ static int start_streaming(struct vb2_queue *vq, unsigned 
int count)
 }
 
 /* abort streaming and wait for last buffer */
-static int stop_streaming(struct vb2_queue *vq)
+static void stop_streaming(struct vb2_queue *vq)
 {
struct sta2x11_vip *vip = vb2_get_drv_priv(vq);
struct vip_buffer *vip_buf, *node;
@@ -374,7 +374,6 @@ static int stop_streaming(struct vb2_queue *vq)
list_del(vip_buf-list);
}
spin_unlock(vip-lock);
-   return 0;
 }
 
 static struct vb2_ops vip_video_qops = {
diff --git a/drivers/media/platform/blackfin/bfin_capture.c 
b/drivers/media/platform/blackfin/bfin_capture.c
index 2819165..cf7ceec 100644
--- a/drivers/media/platform/blackfin/bfin_capture.c
+++ b/drivers/media/platform/blackfin/bfin_capture.c
@@ -427,15 +427,12 @@ static int bcap_start_streaming(struct vb2_queue *vq, 
unsigned int count)
return 0;
 }
 
-static int bcap_stop_streaming(struct vb2_queue *vq)
+static void bcap_stop_streaming(struct vb2_queue *vq)
 {
struct bcap_device *bcap_dev = vb2_get_drv_priv(vq);
struct ppi_if *ppi = bcap_dev-ppi;
int ret;
 
-   if (!vb2_is_streaming(vq))
-   return 0;
-
bcap_dev-stop = true;
wait_for_completion(bcap_dev-comp);
ppi-ops-stop(ppi);
@@ -452,7 +449,6 @@ static int bcap_stop_streaming(struct vb2_queue *vq)
list_del(bcap_dev-cur_frm-list);
vb2_buffer_done(bcap_dev-cur_frm-vb, VB2_BUF_STATE_ERROR);
}
-   return 0;
 }
 
 static struct vb2_ops bcap_video_qops = {
diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index 61f3dbc..9e6cf97 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -2269,7 +2269,7 @@ out:
return ret;
 }
 
-static int coda_stop_streaming(struct vb2_queue *q)
+static void coda_stop_streaming(struct vb2_queue *q)
 {
struct coda_ctx *ctx = vb2_get_drv_priv(q);
struct coda_dev *dev = ctx-dev;
@@ -2295,8 +2295,6 @@ static int coda_stop_streaming(struct vb2_queue *q)
ctx-bitstream.vaddr, 

[RFCv1 PATCH 18/20] vb2: reject output buffers with V4L2_FIELD_ALTERNATE

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

This is not allowed by the spec and does in fact not make any sense.
Return -EINVAL if this is the case.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/v4l2-core/videobuf2-core.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index db95dcb..face6e9 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -1555,6 +1555,15 @@ static int __buf_prepare(struct vb2_buffer *vb, const 
struct v4l2_buffer *b)
__func__, ret);
return ret;
}
+   if (V4L2_TYPE_IS_OUTPUT(q-type)  b-field == V4L2_FIELD_ALTERNATE) {
+   /*
+* If field is ALTERNATE, then we return an error.
+* If the format's field is ALTERNATE, then the buffer's field
+* should be either TOP or BOTTOM, but using ALTERNATE here as
+* well makes no sense.
+*/
+   return -EINVAL;
+   }
 
vb-state = VB2_BUF_STATE_PREPARING;
vb-v4l2_buf.timestamp.tv_sec = 0;
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFCv1 PATCH 02/13] v4l2-ioctl: clips, clipcount and bitmap should not be zeroed.

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

Otherwise you cannot get the current clip and bitmap information from
an overlay.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/v4l2-core/v4l2-ioctl.c | 26 +-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
b/drivers/media/v4l2-core/v4l2-ioctl.c
index 69a1948..82bf164 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1062,6 +1062,30 @@ static int v4l_g_fmt(const struct v4l2_ioctl_ops *ops,
bool is_rx = vfd-vfl_dir != VFL_DIR_TX;
bool is_tx = vfd-vfl_dir != VFL_DIR_RX;
 
+   /*
+* fmt can't be cleared for these overlay types due to the 'clips'
+* 'clipcount' and 'bitmap' pointers in struct v4l2_window.
+* Those are provided by the user. So handle these two overlay types
+* first, and then just do a simple memset for the other types.
+*/
+   switch (p-type) {
+   case V4L2_BUF_TYPE_VIDEO_OVERLAY:
+   case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: {
+   struct v4l2_clip *clips = p-fmt.win.clips;
+   u32 clipcount = p-fmt.win.clipcount;
+   void *bitmap = p-fmt.win.bitmap;
+
+   memset(p-fmt, 0, sizeof(p-fmt));
+   p-fmt.win.clips = clips;
+   p-fmt.win.clipcount = clipcount;
+   p-fmt.win.bitmap = bitmap;
+   break;
+   }
+   default:
+   memset(p-fmt, 0, sizeof(p-fmt));
+   break;
+   }
+
switch (p-type) {
case V4L2_BUF_TYPE_VIDEO_CAPTURE:
if (unlikely(!is_rx || !is_vid || !ops-vidioc_g_fmt_vid_cap))
@@ -2029,7 +2053,7 @@ struct v4l2_ioctl_info {
 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_G_FMT, v4l_g_fmt, v4l_print_format, 0),
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)),
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFCv1 PATCH 05/13] vivi: add multiplanar support

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

Add a new multiplanar module option. If set to 1, switch to the multiplanar
BUF_TYPE. This makes it possible to test multiplanar formats in applications
without requiring access to often hard-to-find hardware.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/platform/vivi.c  | 390 +
 include/uapi/linux/videodev2.h |   1 +
 2 files changed, 361 insertions(+), 30 deletions(-)

diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
index 0cc2a20..49a8f89 100644
--- a/drivers/media/platform/vivi.c
+++ b/drivers/media/platform/vivi.c
@@ -66,6 +66,10 @@ static unsigned n_devs = 1;
 module_param(n_devs, uint, 0644);
 MODULE_PARM_DESC(n_devs, number of video devices to create);
 
+static bool multiplanar;
+module_param(multiplanar, bool, 0644);
+MODULE_PARM_DESC(multiplanar, select multiplanar formats);
+
 static unsigned debug;
 module_param(debug, uint, 0644);
 MODULE_PARM_DESC(debug, activates debug info);
@@ -160,6 +164,15 @@ static const struct vivi_fmt formats[] = {
},
 };
 
+static const struct vivi_fmt mplane_formats[] = {
+   {
+   .name = 4:2:2, planar, YUV,
+   .fourcc   = V4L2_PIX_FMT_YUV422M,
+   .depth= 16,
+   .is_yuv   = true,
+   },
+};
+
 static const struct vivi_fmt *__get_format(u32 pixelformat)
 {
const struct vivi_fmt *fmt;
@@ -168,13 +181,17 @@ static const struct vivi_fmt *__get_format(u32 
pixelformat)
for (k = 0; k  ARRAY_SIZE(formats); k++) {
fmt = formats[k];
if (fmt-fourcc == pixelformat)
-   break;
+   return fmt;
}
 
-   if (k == ARRAY_SIZE(formats))
+   if (!multiplanar)
return NULL;
-
-   return formats[k];
+   for (k = 0; k  ARRAY_SIZE(mplane_formats); k++) {
+   fmt = mplane_formats[k];
+   if (fmt-fourcc == pixelformat)
+   return fmt;
+   }
+   return NULL;
 }
 
 static const struct vivi_fmt *get_format(struct v4l2_format *f)
@@ -348,6 +365,7 @@ static void precalculate_bars(struct vivi_dev *dev)
case V4L2_PIX_FMT_UYVY:
case V4L2_PIX_FMT_YVYU:
case V4L2_PIX_FMT_VYUY:
+   case V4L2_PIX_FMT_YUV422M:
case V4L2_PIX_FMT_RGB24:
case V4L2_PIX_FMT_BGR24:
case V4L2_PIX_FMT_RGB32:
@@ -368,7 +386,7 @@ static void precalculate_bars(struct vivi_dev *dev)
 }
 
 /* 'odd' is true for pixels 1, 3, 5, etc. and false for pixels 0, 2, 4, etc. */
-static void gen_twopix(struct vivi_dev *dev, u8 *buf, int colorpos, bool odd)
+static void gen_twopix(struct vivi_dev *dev, u8 *buf, int colorpos, unsigned 
plane, bool odd)
 {
u8 r_y, g_u, b_v;
u8 alpha = dev-alpha_component;
@@ -383,6 +401,7 @@ static void gen_twopix(struct vivi_dev *dev, u8 *buf, int 
colorpos, bool odd)
p = buf + color;
 
switch (dev-fmt-fourcc) {
+   case V4L2_PIX_FMT_YUV422M:
case V4L2_PIX_FMT_YUYV:
switch (color) {
case 0:
@@ -538,11 +557,26 @@ static void precalculate_line(struct vivi_dev *dev)
int wend   = (colorpos+1) * dev-width / 8;
int w;
 
-   gen_twopix(dev, pix[0],colorpos % 8, 0);
-   gen_twopix(dev, pix[pixsize],  colorpos % 8, 1);
-
-   for (w = wstart/2*2, pos = dev-line + w*pixsize; w  wend; w 
+= 2, pos += pixsize2)
-   memcpy(pos, pix, pixsize2);
+   gen_twopix(dev, pix[0],colorpos % 8, 0, 0);
+   gen_twopix(dev, pix[pixsize],  colorpos % 8, 0, 1);
+
+   if (dev-fmt-fourcc == V4L2_PIX_FMT_YUV422M) {
+   u8 tmp;
+
+   /* Change YUYV to YYUV */
+   tmp = pix[1];
+   pix[1] = pix[2];
+   pix[2] = tmp;
+   for (w = wstart/2*2, pos = dev-line + w*pixsize; w  
wend; w += 2, pos += pixsize)
+   memcpy(pos, pix, pixsize);
+   for (w = wstart/2*2, pos = dev-line + MAX_WIDTH * 2 + 
w*pixsize/2; w  wend; w += 2, pos += pixsize / 2)
+   memcpy(pos, pix + 1, pixsize / 2);
+   for (w = wstart/2*2, pos = dev-line + MAX_WIDTH * 4 + 
w*pixsize/2; w  wend; w += 2, pos += pixsize / 2)
+   memcpy(pos, pix + 2, pixsize / 2);
+   } else {
+   for (w = wstart/2*2, pos = dev-line + w*pixsize; w  
wend; w += 2, pos += pixsize2)
+   memcpy(pos, pix, pixsize2);
+   }
}
 }
 
@@ -600,6 +634,7 @@ static void gen_text(struct vivi_dev *dev, char *basep,
 static void vivi_fillbuff(struct 

[RFCv1 PATCH 00/13] core, vivi and mem2mem_testdev fixes

2014-02-25 Thread Hans Verkuil
This patch series builds on the vb2 PART 2 patch series that was just
posted.

It's a bit of a mix:

Patch 1 adds some core sanity checks for CREATE_BUFS.

Patch 2 fixes a bug I found while testing overlay support, and in particular
with the VIDIOC_G_FMT ioctl and struct v4l2_window. Too many fields are
cleared by the core since v4l2_window has some user pointers. This bug
made it impossible to retrieve the clip list and the bitmap (if any).

Patch 3 fixes a bug in a code example in docbook.

Patch 4 fixes a vivi bug in the ENUM_FRAMEINTERVALS handling, which caused
v4l2-compliance to fail.

Patches 5 and 6 are pure RFC: they need some code cleanup in particular, but I
think they are interesting enough to warrant posting them. Patch 5 adds
multiplanar support to vivi (use the multiplanar=1 module option) and patch 6
adds overlay support. I used these new changes for testing these features.

Patches 7-13 fix various bugs in mem2mem_testdev found with v4l2-compliance.

How about renaming mem2mem_testdev to e.g. vim2m or vimem2mem? It's a terrible
name to type...

Regards,

Hans

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFCv1 PATCH 09/13] mem2mem_testdev: set priv to 0

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

v4l2_compliance fix.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/platform/mem2mem_testdev.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/platform/mem2mem_testdev.c 
b/drivers/media/platform/mem2mem_testdev.c
index 886d475..0745d1a 100644
--- a/drivers/media/platform/mem2mem_testdev.c
+++ b/drivers/media/platform/mem2mem_testdev.c
@@ -529,6 +529,7 @@ static int vidioc_try_fmt(struct v4l2_format *f, struct 
m2mtest_fmt *fmt)
f-fmt.pix.width = ~DIM_ALIGN_MASK;
f-fmt.pix.bytesperline = (f-fmt.pix.width * fmt-depth)  3;
f-fmt.pix.sizeimage = f-fmt.pix.height * f-fmt.pix.bytesperline;
+   f-fmt.pix.priv = 0;
 
return 0;
 }
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFCv1 PATCH 10/13] mem2mem_testdev: add USERPTR support.

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

There is no reason why we shouldn't enable this here.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/platform/mem2mem_testdev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/mem2mem_testdev.c 
b/drivers/media/platform/mem2mem_testdev.c
index 0745d1a..8ca828a 100644
--- a/drivers/media/platform/mem2mem_testdev.c
+++ b/drivers/media/platform/mem2mem_testdev.c
@@ -779,7 +779,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq, 
struct vb2_queue *ds
int ret;
 
src_vq-type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
-   src_vq-io_modes = VB2_MMAP | VB2_DMABUF;
+   src_vq-io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
src_vq-drv_priv = ctx;
src_vq-buf_struct_size = sizeof(struct v4l2_m2m_buffer);
src_vq-ops = m2mtest_qops;
@@ -792,7 +792,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq, 
struct vb2_queue *ds
return ret;
 
dst_vq-type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-   dst_vq-io_modes = VB2_MMAP | VB2_DMABUF;
+   dst_vq-io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
dst_vq-drv_priv = ctx;
dst_vq-buf_struct_size = sizeof(struct v4l2_m2m_buffer);
dst_vq-ops = m2mtest_qops;
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFCv1 PATCH 04/13] vivi: fix ENUM_FRAMEINTERVALS implementation

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

This function never checked if width and height are correct. Add such
a check so the v4l2-compliance tool returns OK again for vivi.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/platform/vivi.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
index f4ac1f9..0cc2a20 100644
--- a/drivers/media/platform/vivi.c
+++ b/drivers/media/platform/vivi.c
@@ -1120,7 +1120,11 @@ static int vidioc_enum_frameintervals(struct file *file, 
void *priv,
if (!fmt)
return -EINVAL;
 
-   /* regarding width  height - we support any */
+   /* check for valid width/height */
+   if (fival-width  48 || fival-width  MAX_WIDTH || (fival-width  3))
+   return -EINVAL;
+   if (fival-height  32 || fival-height  MAX_HEIGHT)
+   return -EINVAL;
 
fival-type = V4L2_FRMIVAL_TYPE_CONTINUOUS;
 
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFCv1 PATCH 01/13] v4l2-ioctl: add CREATE_BUFS sanity checks.

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

Many drivers do not check anything. At least make sure that the various
buffer size related fields are not obviously wrong.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/v4l2-core/v4l2-ioctl.c | 52 ++--
 1 file changed, 50 insertions(+), 2 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
b/drivers/media/v4l2-core/v4l2-ioctl.c
index 707aef7..69a1948 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1444,9 +1444,57 @@ 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(file, create-format.type);
+   const struct v4l2_format *fmt = create-format;
+   const struct v4l2_pix_format *pix = fmt-fmt.pix;
+   const struct v4l2_pix_format_mplane *mp = fmt-fmt.pix_mp;
+   const struct v4l2_plane_pix_format *p;
+   int ret = check_fmt(file, fmt-type);
+   unsigned i;
+
+   if (ret)
+   return ret;
 
-   return ret ? ret : ops-vidioc_create_bufs(file, fh, create);
+   /* Sanity checks */
+   switch (fmt-type) {
+   case V4L2_BUF_TYPE_VIDEO_CAPTURE:
+   case V4L2_BUF_TYPE_VIDEO_OUTPUT:
+   if (pix-sizeimage == 0 || pix-width == 0 || pix-height == 0)
+   return -EINVAL;
+   /* Note: bytesperline is 0 for compressed formats */
+   if (pix-bytesperline 
+   pix-height * pix-bytesperline  pix-sizeimage)
+   return -EINVAL;
+   break;
+   case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
+   case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
+   if (mp-num_planes == 0 || mp-width == 0 || mp-height == 0)
+   return -EINVAL;
+   for (i = 0; i  mp-num_planes; i++) {
+   p = mp-plane_fmt[i];
+
+   if (p-sizeimage == 0)
+   return -EINVAL;
+   /* Note: bytesperline is 0 for compressed formats */
+   if (p-bytesperline 
+   p-bytesperline * mp-height  p-sizeimage)
+   return -EINVAL;
+   }
+   break;
+   case V4L2_BUF_TYPE_VBI_CAPTURE:
+   case V4L2_BUF_TYPE_VBI_OUTPUT:
+   if (fmt-fmt.vbi.count[0] + fmt-fmt.vbi.count[1] == 0)
+   return -EINVAL;
+   break;
+   case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
+   case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
+   if (fmt-fmt.sliced.io_size == 0)
+   return -EINVAL;
+   break;
+   default:
+   /* Overlay formats are invalid */
+   return -EINVAL;
+   }
+   return ops-vidioc_create_bufs(file, fh, create);
 }
 
 static int v4l_prepare_buf(const struct v4l2_ioctl_ops *ops,
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFCv1 PATCH 11/13] mem2mem_testdev: return pending buffers in stop_streaming()

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

To keep the list administration in balance stop_streaming() should return
any pending buffers to the vb2 framework.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/platform/mem2mem_testdev.c | 20 
 1 file changed, 20 insertions(+)

diff --git a/drivers/media/platform/mem2mem_testdev.c 
b/drivers/media/platform/mem2mem_testdev.c
index 8ca828a..2ea27cc 100644
--- a/drivers/media/platform/mem2mem_testdev.c
+++ b/drivers/media/platform/mem2mem_testdev.c
@@ -765,10 +765,30 @@ static void m2mtest_buf_queue(struct vb2_buffer *vb)
v4l2_m2m_buf_queue(ctx-fh.m2m_ctx, vb);
 }
 
+static void m2mtest_stop_streaming(struct vb2_queue *q)
+{
+   struct m2mtest_ctx *ctx = vb2_get_drv_priv(q);
+   struct vb2_buffer *vb;
+   unsigned long flags;
+
+   for (;;) {
+   if (V4L2_TYPE_IS_OUTPUT(q-type))
+   vb = v4l2_m2m_src_buf_remove(ctx-fh.m2m_ctx);
+   else
+   vb = v4l2_m2m_dst_buf_remove(ctx-fh.m2m_ctx);
+   if (vb == NULL)
+   return;
+   spin_lock_irqsave(ctx-dev-irqlock, flags);
+   v4l2_m2m_buf_done(vb, VB2_BUF_STATE_ERROR);
+   spin_unlock_irqrestore(ctx-dev-irqlock, flags);
+   }
+}
+
 static struct vb2_ops m2mtest_qops = {
.queue_setup = m2mtest_queue_setup,
.buf_prepare = m2mtest_buf_prepare,
.buf_queue   = m2mtest_buf_queue,
+   .stop_streaming  = m2mtest_stop_streaming,
.wait_prepare= vb2_ops_wait_prepare,
.wait_finish = vb2_ops_wait_finish,
 };
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFCv1 PATCH 12/13] mem2mem_testdev: fix field, sequence and time copying

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

- Set the sequence counters correctly.
- Copy timestamps, timecode, relevant buffer flags and field from
  the received buffer to the outgoing buffer.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/platform/mem2mem_testdev.c | 23 +++
 1 file changed, 23 insertions(+)

diff --git a/drivers/media/platform/mem2mem_testdev.c 
b/drivers/media/platform/mem2mem_testdev.c
index 2ea27cc..4a25940 100644
--- a/drivers/media/platform/mem2mem_testdev.c
+++ b/drivers/media/platform/mem2mem_testdev.c
@@ -112,6 +112,7 @@ struct m2mtest_q_data {
unsigned intwidth;
unsigned intheight;
unsigned intsizeimage;
+   unsigned intsequence;
struct m2mtest_fmt  *fmt;
 };
 
@@ -234,9 +235,20 @@ static int device_process(struct m2mtest_ctx *ctx,
bytes_left = bytesperline - tile_w * MEM2MEM_NUM_TILES;
w = 0;
 
+   out_vb-v4l2_buf.sequence = get_q_data(ctx, 
V4L2_BUF_TYPE_VIDEO_CAPTURE)-sequence++;
+   in_vb-v4l2_buf.sequence = q_data-sequence++;
memcpy(out_vb-v4l2_buf.timestamp,
in_vb-v4l2_buf.timestamp,
sizeof(struct timeval));
+   if (in_vb-v4l2_buf.flags  V4L2_BUF_FLAG_TIMECODE)
+   memcpy(out_vb-v4l2_buf.timecode, in_vb-v4l2_buf.timecode,
+   sizeof(struct v4l2_timecode));
+   out_vb-v4l2_buf.field = in_vb-v4l2_buf.field;
+   out_vb-v4l2_buf.flags = in_vb-v4l2_buf.flags 
+   (V4L2_BUF_FLAG_TIMECODE |
+V4L2_BUF_FLAG_KEYFRAME |
+V4L2_BUF_FLAG_PFRAME |
+V4L2_BUF_FLAG_BFRAME);
 
switch (ctx-mode) {
case MEM2MEM_HFLIP | MEM2MEM_VFLIP:
@@ -762,9 +774,19 @@ static int m2mtest_buf_prepare(struct vb2_buffer *vb)
 static void m2mtest_buf_queue(struct vb2_buffer *vb)
 {
struct m2mtest_ctx *ctx = vb2_get_drv_priv(vb-vb2_queue);
+
v4l2_m2m_buf_queue(ctx-fh.m2m_ctx, vb);
 }
 
+static int m2mtest_start_streaming(struct vb2_queue *q, unsigned count)
+{
+   struct m2mtest_ctx *ctx = vb2_get_drv_priv(q);
+   struct m2mtest_q_data *q_data = get_q_data(ctx, q-type);
+
+   q_data-sequence = 0;
+   return 0;
+}
+
 static void m2mtest_stop_streaming(struct vb2_queue *q)
 {
struct m2mtest_ctx *ctx = vb2_get_drv_priv(q);
@@ -788,6 +810,7 @@ static struct vb2_ops m2mtest_qops = {
.queue_setup = m2mtest_queue_setup,
.buf_prepare = m2mtest_buf_prepare,
.buf_queue   = m2mtest_buf_queue,
+   .start_streaming = m2mtest_start_streaming,
.stop_streaming  = m2mtest_stop_streaming,
.wait_prepare= vb2_ops_wait_prepare,
.wait_finish = vb2_ops_wait_finish,
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFCv1 PATCH 07/13] mem2mem_testdev: use 40ms default transfer time.

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

The default of 1 second is a bit painful, switch to a 25 Hz framerate.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/platform/mem2mem_testdev.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/media/platform/mem2mem_testdev.c 
b/drivers/media/platform/mem2mem_testdev.c
index 08e2437..35b2327 100644
--- a/drivers/media/platform/mem2mem_testdev.c
+++ b/drivers/media/platform/mem2mem_testdev.c
@@ -60,9 +60,7 @@ MODULE_PARM_DESC(debug, activates debug info);
 #define MEM2MEM_VID_MEM_LIMIT  (16 * 1024 * 1024)
 
 /* Default transaction time in msec */
-#define MEM2MEM_DEF_TRANSTIME  1000
-/* Default number of buffers per transaction */
-#define MEM2MEM_DEF_TRANSLEN   1
+#define MEM2MEM_DEF_TRANSTIME  40
 #define MEM2MEM_COLOR_STEP (0xff  4)
 #define MEM2MEM_NUM_TILES  8
 
@@ -801,10 +799,10 @@ static const struct v4l2_ctrl_config 
m2mtest_ctrl_trans_time_msec = {
.id = V4L2_CID_TRANS_TIME_MSEC,
.name = Transaction Time (msec),
.type = V4L2_CTRL_TYPE_INTEGER,
-   .def = 1001,
+   .def = MEM2MEM_DEF_TRANSTIME,
.min = 1,
.max = 10001,
-   .step = 100,
+   .step = 1,
 };
 
 static const struct v4l2_ctrl_config m2mtest_ctrl_trans_num_bufs = {
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFCv1 PATCH 03/13] DocBook: fix incorrect code example

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

The code said for (i = 0; i  30; ++i) instead of i  30.

Fix this and clean it up a bit at the same time.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 Documentation/DocBook/media/v4l/dev-osd.xml | 22 +++---
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/Documentation/DocBook/media/v4l/dev-osd.xml 
b/Documentation/DocBook/media/v4l/dev-osd.xml
index dd91d61..5485332 100644
--- a/Documentation/DocBook/media/v4l/dev-osd.xml
+++ b/Documentation/DocBook/media/v4l/dev-osd.xml
@@ -56,18 +56,18 @@ framebuffer device./para
 unsigned int i;
 int fb_fd;
 
-if (-1 == ioctl (fd, VIDIOC_G_FBUF, amp;fbuf)) {
-   perror (VIDIOC_G_FBUF);
-   exit (EXIT_FAILURE);
+if (-1 == ioctl(fd, VIDIOC_G_FBUF, amp;fbuf)) {
+   perror(VIDIOC_G_FBUF);
+   exit(EXIT_FAILURE);
 }
 
-for (i = 0; i gt; 30; ++i) {
+for (i = 0; i lt; 30; i++) {
char dev_name[16];
struct fb_fix_screeninfo si;
 
-   snprintf (dev_name, sizeof (dev_name), /dev/fb%u, i);
+   snprintf(dev_name, sizeof(dev_name), /dev/fb%u, i);
 
-   fb_fd = open (dev_name, O_RDWR);
+   fb_fd = open(dev_name, O_RDWR);
if (-1 == fb_fd) {
switch (errno) {
case ENOENT: /* no such file */
@@ -75,19 +75,19 @@ for (i = 0; i gt; 30; ++i) {
continue;
 
default:
-   perror (open);
-   exit (EXIT_FAILURE);
+   perror(open);
+   exit(EXIT_FAILURE);
}
}
 
-   if (0 == ioctl (fb_fd, FBIOGET_FSCREENINFO, amp;si)) {
-   if (si.smem_start == (unsigned long) fbuf.base)
+   if (0 == ioctl(fb_fd, FBIOGET_FSCREENINFO, amp;si)) {
+   if (si.smem_start == (unsigned long)fbuf.base)
break;
} else {
/* Apparently not a framebuffer device. */
}
 
-   close (fb_fd);
+   close(fb_fd);
fb_fd = -1;
 }
 
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFCv1 PATCH 13/13] mem2mem_testdev: improve field handling

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

try_fmt should just set field to NONE and not return an error if
a different field was passed.

buf_prepare should check if the field passed in from userspace has a
supported field value. At the moment only NONE is supported and ANY
is mapped to NONE.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/platform/mem2mem_testdev.c | 21 ++---
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/drivers/media/platform/mem2mem_testdev.c 
b/drivers/media/platform/mem2mem_testdev.c
index 4a25940..67894f2 100644
--- a/drivers/media/platform/mem2mem_testdev.c
+++ b/drivers/media/platform/mem2mem_testdev.c
@@ -515,19 +515,8 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void 
*priv,
 
 static int vidioc_try_fmt(struct v4l2_format *f, struct m2mtest_fmt *fmt)
 {
-   enum v4l2_field field;
-
-   field = f-fmt.pix.field;
-
-   if (field == V4L2_FIELD_ANY)
-   field = V4L2_FIELD_NONE;
-   else if (V4L2_FIELD_NONE != field)
-   return -EINVAL;
-
/* V4L2 specification suggests the driver corrects the format struct
 * if any of the dimensions is unsupported */
-   f-fmt.pix.field = field;
-
if (f-fmt.pix.height  MIN_H)
f-fmt.pix.height = MIN_H;
else if (f-fmt.pix.height  MAX_H)
@@ -541,6 +530,7 @@ static int vidioc_try_fmt(struct v4l2_format *f, struct 
m2mtest_fmt *fmt)
f-fmt.pix.width = ~DIM_ALIGN_MASK;
f-fmt.pix.bytesperline = (f-fmt.pix.width * fmt-depth)  3;
f-fmt.pix.sizeimage = f-fmt.pix.height * f-fmt.pix.bytesperline;
+   f-fmt.pix.field = V4L2_FIELD_NONE;
f-fmt.pix.priv = 0;
 
return 0;
@@ -759,6 +749,15 @@ static int m2mtest_buf_prepare(struct vb2_buffer *vb)
dprintk(ctx-dev, type: %d\n, vb-vb2_queue-type);
 
q_data = get_q_data(ctx, vb-vb2_queue-type);
+   if (V4L2_TYPE_IS_OUTPUT(vb-vb2_queue-type)) {
+   if (vb-v4l2_buf.field == V4L2_FIELD_ANY)
+   vb-v4l2_buf.field = V4L2_FIELD_NONE;
+   if (vb-v4l2_buf.field != V4L2_FIELD_NONE) {
+   dprintk(ctx-dev, %s field isn't supported\n,
+   __func__);
+   return -EINVAL;
+   }
+   }
 
if (vb2_plane_size(vb, 0)  q_data-sizeimage) {
dprintk(ctx-dev, %s data will not fit into plane (%lu  
%lu)\n,
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFCv1 PATCH 06/13] vivi: add support for a video overlay

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/platform/vivi.c | 330 +-
 1 file changed, 328 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
index 49a8f89..349d61f 100644
--- a/drivers/media/platform/vivi.c
+++ b/drivers/media/platform/vivi.c
@@ -48,8 +48,9 @@
  */
 #define FPS_MAX 1000
 
-#define MAX_WIDTH 1920
+#define MAX_WIDTH  1920
 #define MAX_HEIGHT 1200
+#define MAX_CLIPS  16
 
 #define VIVI_VERSION 0.8.1
 
@@ -173,6 +174,19 @@ static const struct vivi_fmt mplane_formats[] = {
},
 };
 
+static const struct vivi_fmt formats_ovl[] = {
+   {
+   .name = RGB565 (LE),
+   .fourcc   = V4L2_PIX_FMT_RGB565, /* gggb rggg */
+   .depth= 16,
+   },
+   {
+   .name = RGB555 (LE),
+   .fourcc   = V4L2_PIX_FMT_RGB555, /* gggb argg */
+   .depth= 16,
+   },
+};
+
 static const struct vivi_fmt *__get_format(u32 pixelformat)
 {
const struct vivi_fmt *fmt;
@@ -246,6 +260,16 @@ struct vivi_dev {
struct v4l2_ctrl   *bitmask;
struct v4l2_ctrl   *int_menu;
 
+   /* Overlays */
+   struct v4l2_framebufferfb;
+   bool   do_overlay;
+   void   *fb_vbase;
+   intoverlay_top, overlay_left;
+   void   *bitmap;
+   struct v4l2_clip   clips[MAX_CLIPS];
+   struct v4l2_clip   try_clips[MAX_CLIPS];
+   unsigned   clipcount;
+
spinlock_t slock;
struct mutex   mutex;
 
@@ -733,6 +757,27 @@ done:
v4l2_get_timestamp(buf-vb.v4l2_buf.timestamp);
 }
 
+static bool valid_pix(struct vivi_dev *dev, int win_y, int win_x, int fb_y, 
int fb_x)
+{
+   bool valid = true;
+
+   if (dev-bitmap)
+   valid = ((__u8 *)dev-bitmap)[((dev-width + 7) / 8) * win_y + 
win_x / 8]  (1  (win_x  7));
+   if (valid  dev-clipcount) {
+   int i;
+
+   for (i = 0; i  dev-clipcount; i++) {
+   struct v4l2_rect *r = dev-clips[i].c;
+
+   if (fb_y = r-top  fb_y  r-top + r-height 
+   fb_x = r-left  fb_x  r-left + r-width)
+   return true;
+   }
+   valid = false;
+   }
+   return valid;
+}
+
 static void vivi_thread_tick(struct vivi_dev *dev)
 {
struct vivi_dmaqueue *dma_q = dev-vidq;
@@ -757,7 +802,51 @@ static void vivi_thread_tick(struct vivi_dev *dev)
/* Fill buffer */
vivi_fillbuff(dev, buf);
dprintk(dev, 1, filled buffer %p\n, buf);
+   if (dev-do_overlay  dev-fb.base) {
+   void *vbase = dev-fb_vbase;
+   void *vbuf = vb2_plane_vaddr(buf-vb, 0);
+   unsigned stride = dev-width * dev-pixelsize;
+   bool quick = dev-bitmap == NULL  dev-clipcount == 0;
+   int x, y, w, out_x = 0;
+
+   x = dev-overlay_left;
+   w = dev-width;
+   if (x  0) {
+   out_x = -x;
+   w = w - out_x;
+   x = 0;
+   } else {
+   w = dev-fb.fmt.width - x;
+   if (w  dev-width)
+   w = dev-width;
+   }
+   if (w = 0)
+   goto done;
+   if (dev-overlay_top = 0)
+   vbase += dev-overlay_top * dev-fb.fmt.bytesperline;
+   for (y = dev-overlay_top; y  dev-overlay_top + 
(int)dev-height; y++) {
+   if (y = 0  y  dev-fb.fmt.height) {
+   if (quick) {
+   memcpy(vbase + x * dev-pixelsize,
+  vbuf + out_x * dev-pixelsize, w 
* dev-pixelsize);
+   } else {
+   int px;
+
+   for (px = 0; px  w; px++) {
+   if (valid_pix(dev, y - 
dev-overlay_top, px + out_x,
+  y, px + x))
+   memcpy(vbase + (px + x) 
* dev-pixelsize,
+  vbuf + (px + 
out_x) * dev-pixelsize,
+  dev-pixelsize);
+   }
+   }
+   vbase += dev-fb.fmt.bytesperline;
+   }
+   vbuf += stride;
+   }
+   }
 
+done:
vb2_buffer_done(buf-vb, 

[RFCv1 PATCH 08/13] mem2mem_testdev: pick default format with try_fmt.

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

This resolves an issue raised by v4l2-compliance.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/platform/mem2mem_testdev.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/mem2mem_testdev.c 
b/drivers/media/platform/mem2mem_testdev.c
index 35b2327..886d475 100644
--- a/drivers/media/platform/mem2mem_testdev.c
+++ b/drivers/media/platform/mem2mem_testdev.c
@@ -540,7 +540,11 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void 
*priv,
struct m2mtest_ctx *ctx = file2ctx(file);
 
fmt = find_format(f);
-   if (!fmt || !(fmt-types  MEM2MEM_CAPTURE)) {
+   if (!fmt) {
+   f-fmt.pix.pixelformat = formats[0].fourcc;
+   fmt = find_format(f);
+   }
+   if (!(fmt-types  MEM2MEM_CAPTURE)) {
v4l2_err(ctx-dev-v4l2_dev,
 Fourcc format (0x%08x) invalid.\n,
 f-fmt.pix.pixelformat);
@@ -558,7 +562,11 @@ static int vidioc_try_fmt_vid_out(struct file *file, void 
*priv,
struct m2mtest_ctx *ctx = file2ctx(file);
 
fmt = find_format(f);
-   if (!fmt || !(fmt-types  MEM2MEM_OUTPUT)) {
+   if (!fmt) {
+   f-fmt.pix.pixelformat = formats[0].fourcc;
+   fmt = find_format(f);
+   }
+   if (!(fmt-types  MEM2MEM_OUTPUT)) {
v4l2_err(ctx-dev-v4l2_dev,
 Fourcc format (0x%08x) invalid.\n,
 f-fmt.pix.pixelformat);
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFCv1 PATCH 1/2] viloop: add video loopback driver

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

Create a virtual video loopback driver. It is by default singleplanar, but
by loading it with multiplanar=1 it can be set to multiplanar mode.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/platform/Kconfig  |   24 +-
 drivers/media/platform/Makefile |1 +
 drivers/media/platform/viloop.c | 1107 +++
 3 files changed, 1128 insertions(+), 4 deletions(-)
 create mode 100644 drivers/media/platform/viloop.c

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index b2a4403..5eb9a63 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -239,7 +239,7 @@ menuconfig V4L_TEST_DRIVERS
 
 if V4L_TEST_DRIVERS
 config VIDEO_VIVI
-   tristate Virtual Video Driver
+   tristate Virtual Video Capture Driver
depends on VIDEO_DEV  VIDEO_V4L2  !SPARC32  !SPARC64
select FONT_SUPPORT
select FONT_8x16
@@ -248,9 +248,22 @@ config VIDEO_VIVI
---help---
  Enables a virtual video driver. This device shows a color bar
  and a timestamp, as a real device would generate by using V4L2
- api.
- Say Y here if you want to test video apps or debug V4L devices.
- In doubt, say N.
+ api. Use this driver to test video apps or debug V4L devices.
+
+ To compile this driver as a module, choose M here: the module
+ will be called vivi. If in doubt, say N.
+
+config VIDEO_VILOOP
+   tristate Virtual Video Loopback Driver
+   depends on VIDEO_DEV  VIDEO_V4L2
+   select VIDEOBUF2_VMALLOC
+   ---help---
+ Enables a virtual video loopback driver. This device creates
+ two video nodes, one for output and one for capture and anything
+ written to the output node will appear at the capture node.
+
+ To compile this driver as a module, choose M here: the module
+ will be called viloop. If in doubt, say N.
 
 config VIDEO_MEM2MEM_TESTDEV
tristate Virtual test device for mem2mem framework
@@ -261,4 +274,7 @@ config VIDEO_MEM2MEM_TESTDEV
---help---
  This is a virtual test device for the memory-to-memory driver
  framework.
+
+ To compile this driver as a module, choose M here: the module
+ will be called mem2mem_testdev. If in doubt, say N.
 endif #V4L_TEST_DRIVERS
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index e5269da..3cdc7df 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -16,6 +16,7 @@ obj-$(CONFIG_VIDEO_OMAP3) += omap3isp/
 
 obj-$(CONFIG_VIDEO_VIU) += fsl-viu.o
 obj-$(CONFIG_VIDEO_VIVI) += vivi.o
+obj-$(CONFIG_VIDEO_VILOOP) += viloop.o
 
 obj-$(CONFIG_VIDEO_MEM2MEM_TESTDEV) += mem2mem_testdev.o
 
diff --git a/drivers/media/platform/viloop.c b/drivers/media/platform/viloop.c
new file mode 100644
index 000..0eca58f
--- /dev/null
+++ b/drivers/media/platform/viloop.c
@@ -0,0 +1,1107 @@
+/*
+ * Virtual Video loopback driver
+ *
+ * Based on the vivi driver:
+ * Copyright (c) 2006 by:
+ *  Mauro Carvalho Chehab mchehab--a.t--infradead.org
+ *  Ted Walther ted--a.t--enumera.com
+ *  John Sokol sokol--a.t--videotechnology.com
+ *  http://v4l.videotechnology.com/
+ *
+ *  Conversion to videobuf2 by Pawel Osciak  Marek Szyprowski
+ *  Copyright (c) 2010 Samsung Electronics
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the BSD Licence, GNU General Public License
+ * as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version
+ */
+#include linux/module.h
+#include linux/errno.h
+#include linux/kernel.h
+#include linux/init.h
+#include linux/sched.h
+#include linux/slab.h
+#include linux/font.h
+#include linux/mutex.h
+#include linux/videodev2.h
+#include linux/kthread.h
+#include linux/freezer.h
+#include media/videobuf2-vmalloc.h
+#include media/v4l2-device.h
+#include media/v4l2-ioctl.h
+#include media/v4l2-ctrls.h
+#include media/v4l2-fh.h
+#include media/v4l2-event.h
+#include media/v4l2-common.h
+
+#define VILOOP_MODULE_NAME viloop
+
+#define MAX_WIDTH 1920
+#define MAX_HEIGHT 1200
+
+#define VILOOP_VERSION 0.1.0
+
+MODULE_DESCRIPTION(Video Loopback Driver);
+MODULE_AUTHOR(Hans Verkuil);
+MODULE_LICENSE(Dual BSD/GPL);
+MODULE_VERSION(VILOOP_VERSION);
+
+static unsigned video_nr = -1;
+module_param(video_nr, uint, 0644);
+MODULE_PARM_DESC(video_nr, videoX start number, -1 is autodetect);
+
+static unsigned n_devs = 1;
+module_param(n_devs, uint, 0644);
+MODULE_PARM_DESC(n_devs, number of video device pairs to create);
+
+static bool multiplanar;
+module_param(multiplanar, bool, 0644);
+MODULE_PARM_DESC(multiplanar, select multiplanar formats);
+
+static unsigned debug;
+module_param(debug, uint, 0644);
+MODULE_PARM_DESC(debug, activates debug info);
+
+#define dprintk(dev, 

[RFCv1 PATCH 0/2] Add viloop and vioverlay drivers

2014-02-25 Thread Hans Verkuil
Hi all,

I wanted to share these two drivers, even though they need more work,
particular w.r.t. code quality.

They assume that PART 1 and PART 2 of the vb2 patch series are applied.

The viloop driver loops video from one device to another. It will create
pairs of video devices, the first an output device, the second a capture
device, and just copy the video data from one device to the other.

It can be loaded in multiplanar mode with the multiplanar=1 option.
It's a clean implementation using all the latest frameworks, in particular
all streaming memory models are supported as well as EXPBUF.

I did look at first at the out-of-tree v4l2-loopback driver, but it was
quicker to just write my own.

The vioverlay driver is a driver to test overlay support, both capture and
output overlays. Few drivers support this, so it is very hard to have
applications test their support for overlays, or to test drivers with overlay
support.

Overlay may be less and less important, but it is part of the API and you
need a way to test it.

The vioverlay driver creates a framebuffer, an output video node and a capture
video node. The output video node is used to pass video to the driver which
will be used as the video for the video output overlay feature. The capture
node is used to capture the result of the framebuffer contents mixed in with
the video output overlay.

Currently clipping and bitmap support is in, but not yet alpha blending and
chromakeying.

Feedback and ideas are welcome.

Again, I am well aware that these drivers need some more code cleanup work,
so don't bother commenting on that :-) They've been written in just the past
3-4 days so they are freshly baked...

Regards,

Hans

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFCv1 PATCH 2/2] vioverlay: add video overlay test driver

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

This driver creates a framebuffer, a video output device and a video capture
device which shows the framebuffer blended with the contents of the output
device. This can be combined with vivi to have both a capture overlay (vivi
overlaying the video into the framebuffer) and an output overlay (the output
video node provides the video for that).

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/platform/Kconfig |   16 +
 drivers/media/platform/Makefile|1 +
 drivers/media/platform/vioverlay.c | 1532 
 3 files changed, 1549 insertions(+)
 create mode 100644 drivers/media/platform/vioverlay.c

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index 5eb9a63..50263a1 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -265,6 +265,22 @@ config VIDEO_VILOOP
  To compile this driver as a module, choose M here: the module
  will be called viloop. If in doubt, say N.
 
+config VIDEO_VIOVERLAY
+   tristate Virtual Video Overlay Driver
+   depends on VIDEO_DEV  VIDEO_V4L2
+   select VIDEOBUF2_VMALLOC
+   ---help---
+ Enables a virtual video overlay driver. This device creates
+ a framebuffer device, a video output device and a video capture
+ device. The output device can be used as the source of the output
+ video which will be combined with the framebuffer and the result
+ will be available through the capture device.
+ Drivers supporting capture or output overlay can use this driver
+ for testing.
+
+ To compile this driver as a module, choose M here: the module
+ will be called vioverlay. If in doubt, say N.
+
 config VIDEO_MEM2MEM_TESTDEV
tristate Virtual test device for mem2mem framework
depends on VIDEO_DEV  VIDEO_V4L2
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index 3cdc7df..fe5382c 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -17,6 +17,7 @@ obj-$(CONFIG_VIDEO_OMAP3) += omap3isp/
 obj-$(CONFIG_VIDEO_VIU) += fsl-viu.o
 obj-$(CONFIG_VIDEO_VIVI) += vivi.o
 obj-$(CONFIG_VIDEO_VILOOP) += viloop.o
+obj-$(CONFIG_VIDEO_VIOVERLAY) += vioverlay.o
 
 obj-$(CONFIG_VIDEO_MEM2MEM_TESTDEV) += mem2mem_testdev.o
 
diff --git a/drivers/media/platform/vioverlay.c 
b/drivers/media/platform/vioverlay.c
new file mode 100644
index 000..6915776
--- /dev/null
+++ b/drivers/media/platform/vioverlay.c
@@ -0,0 +1,1532 @@
+/*
+ * Virtual Video Overlay driver
+ *
+ * Based on the viovl driver:
+ * Copyright (c) 2006 by:
+ *  Mauro Carvalho Chehab mchehab--a.t--infradead.org
+ *  Ted Walther ted--a.t--enumera.com
+ *  John Sokol sokol--a.t--videotechnology.com
+ *  http://v4l.videotechnology.com/
+ *
+ *  Conversion to videobuf2 by Pawel Osciak  Marek Szyprowski
+ *  Copyright (c) 2010 Samsung Electronics
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the BSD Licence, GNU General Public License
+ * as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version
+ */
+#include linux/module.h
+#include linux/errno.h
+#include linux/kernel.h
+#include linux/init.h
+#include linux/sched.h
+#include linux/slab.h
+#include linux/font.h
+#include linux/mutex.h
+#include linux/videodev2.h
+#include linux/kthread.h
+#include linux/freezer.h
+#include linux/fb.h
+#include media/videobuf2-vmalloc.h
+#include media/v4l2-device.h
+#include media/v4l2-ioctl.h
+#include media/v4l2-ctrls.h
+#include media/v4l2-fh.h
+#include media/v4l2-event.h
+#include media/v4l2-common.h
+
+#ifdef CONFIG_MTRR
+#include asm/mtrr.h
+#endif
+
+#define VIOVL_MODULE_NAME vioverlay
+
+#define MAX_WIDTH  720
+#define MAX_HEIGHT 576
+#define MAX_CLIPS  16
+
+#define VIOVL_VERSION 0.1.0
+
+MODULE_DESCRIPTION(Video Overlay Driver);
+MODULE_AUTHOR(Hans Verkuil);
+MODULE_LICENSE(Dual BSD/GPL);
+MODULE_VERSION(VIOVL_VERSION);
+
+static unsigned video_nr = -1;
+module_param(video_nr, uint, 0644);
+MODULE_PARM_DESC(video_nr, videoX start number, -1 is autodetect);
+
+static unsigned n_devs = 1;
+module_param(n_devs, uint, 0644);
+MODULE_PARM_DESC(n_devs, number of video device pairs to create);
+
+static unsigned debug;
+module_param(debug, uint, 0644);
+MODULE_PARM_DESC(debug, activates debug info);
+
+#define dprintk(dev, level, fmt, arg...) \
+   v4l2_dbg(level, debug, dev-v4l2_dev, fmt, ## arg)
+
+#define VIOVL_CID_CUSTOM_BASE  (V4L2_CID_USER_BASE | 0xf000)
+
+/* --
+   Basic structures
+   --*/
+
+struct viovl_fmt {
+   const char *name;
+   u32   fourcc;  /* v4l2 format id */
+   u8depth;
+   bool  is_yuv;
+};
+

Re: [PATCH v5 2/7] v4l: Use full 32 bits for buffer flags

2014-02-25 Thread 'Sakari Ailus'
Hi Kamil and Hans,

On Mon, Feb 24, 2014 at 05:13:49PM +0100, Kamil Debski wrote:
  From: Sakari Ailus [mailto:sakari.ai...@iki.fi]
  Sent: Monday, February 24, 2014 4:35 PM
  
  Hans Verkuil wrote:
   On 02/15/2014 09:53 PM, Sakari Ailus wrote:
   The buffer flags field is 32 bits but the defined only used 16. This
   is fine, but as more than 16 bits will be used in the very near
   future, define them as 32-bit numbers for consistency.
  
   Signed-off-by: Sakari Ailus sakari.ai...@iki.fi
   ---
Documentation/DocBook/media/v4l/io.xml |   30 -
  
include/uapi/linux/videodev2.h |   38 +++--
  ---
2 files changed, 38 insertions(+), 30 deletions(-)
  
   diff --git a/Documentation/DocBook/media/v4l/io.xml
   b/Documentation/DocBook/media/v4l/io.xml
   index 8facac4..46d24b3 100644
   --- a/Documentation/DocBook/media/v4l/io.xml
   +++ b/Documentation/DocBook/media/v4l/io.xml
  
   snip
  
   @@ -1115,7 +1115,7 @@ in which case caches have not been
  used./entry
  /row
  row
  
  entryconstantV4L2_BUF_FLAG_TIMESTAMP_COPY/constant/entry
   -entry0x4000/entry
   +entry0x4000/entry
entryThe CAPTURE buffer timestamp has been taken from the
corresponding OUTPUT buffer. This flag applies only to
  mem2mem devices./entry
  /row
  
   Should we add here that if TIMESTAMP_COPY is set and the TIMECODE
  flag
   is set, then drivers should copy the TIMECODE struct as well? This is
   happening already in various drivers and I think that is appropriate.
   Although to be honest nobody is actually using the timecode struct,
   but we plan to hijack that for hardware timestamps in the future
  anyway.
  
  Is there a single driver which uses the timecode field? The fact is
  that many m2m drivers copy it but that's probably mostly copying what
  one of them happened to do by accident. :-)
 
 Let's focus on not breaking m2m drivers with timestamp patches this time.
 I'm sure it was a matter of accident with the initial timestamp patches.

This patch extends the documentation of the buffer flags from 16 bits to 32
bits. There are no other changes in functionality nor documentation.

The patchset does indeed change the way timestamp and timestamp flags are
copied: from source to destination rather than the other way around. I'd
appreciate if you'd review especially that one (patch 5/7).

There are no other changes to the way timestamps (or timecode) are handled.

 I agree with Hans here, not sure about hijacking it in the future, though.

This patchset does not change the handling of the timecode field, other than
the fixes in patch 5/7. I would prefer to get this old patchset in and unify
the timecode field handling once it has been discussed and agreed on.

-- 
Kind regards,

Sakari Ailus
e-mail: sakari.ai...@iki.fi XMPP: sai...@retiisi.org.uk
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 2/7] v4l: Use full 32 bits for buffer flags

2014-02-25 Thread Hans Verkuil
On 02/25/14 12:44, 'Sakari Ailus' wrote:
 Hi Kamil and Hans,
 
 On Mon, Feb 24, 2014 at 05:13:49PM +0100, Kamil Debski wrote:
 From: Sakari Ailus [mailto:sakari.ai...@iki.fi]
 Sent: Monday, February 24, 2014 4:35 PM

 Hans Verkuil wrote:
 On 02/15/2014 09:53 PM, Sakari Ailus wrote:
 The buffer flags field is 32 bits but the defined only used 16. This
 is fine, but as more than 16 bits will be used in the very near
 future, define them as 32-bit numbers for consistency.

 Signed-off-by: Sakari Ailus sakari.ai...@iki.fi
 ---
  Documentation/DocBook/media/v4l/io.xml |   30 -
 
  include/uapi/linux/videodev2.h |   38 +++--
 ---
  2 files changed, 38 insertions(+), 30 deletions(-)

 diff --git a/Documentation/DocBook/media/v4l/io.xml
 b/Documentation/DocBook/media/v4l/io.xml
 index 8facac4..46d24b3 100644
 --- a/Documentation/DocBook/media/v4l/io.xml
 +++ b/Documentation/DocBook/media/v4l/io.xml

 snip

 @@ -1115,7 +1115,7 @@ in which case caches have not been
 used./entry
 /row
 row

 entryconstantV4L2_BUF_FLAG_TIMESTAMP_COPY/constant/entry
 - entry0x4000/entry
 + entry0x4000/entry
   entryThe CAPTURE buffer timestamp has been taken from the
   corresponding OUTPUT buffer. This flag applies only to
 mem2mem devices./entry
 /row

 Should we add here that if TIMESTAMP_COPY is set and the TIMECODE
 flag
 is set, then drivers should copy the TIMECODE struct as well? This is
 happening already in various drivers and I think that is appropriate.
 Although to be honest nobody is actually using the timecode struct,
 but we plan to hijack that for hardware timestamps in the future
 anyway.

 Is there a single driver which uses the timecode field? The fact is
 that many m2m drivers copy it but that's probably mostly copying what
 one of them happened to do by accident. :-)

 Let's focus on not breaking m2m drivers with timestamp patches this time.
 I'm sure it was a matter of accident with the initial timestamp patches.
 
 This patch extends the documentation of the buffer flags from 16 bits to 32
 bits. There are no other changes in functionality nor documentation.
 
 The patchset does indeed change the way timestamp and timestamp flags are
 copied: from source to destination rather than the other way around. I'd
 appreciate if you'd review especially that one (patch 5/7).
 
 There are no other changes to the way timestamps (or timecode) are handled.
 
 I agree with Hans here, not sure about hijacking it in the future, though.
 
 This patchset does not change the handling of the timecode field, other than
 the fixes in patch 5/7. I would prefer to get this old patchset in and unify
 the timecode field handling once it has been discussed and agreed on.
 

That's fine by me with respect to timecode handling. That can be handled later.
My comment about patch 7/7 still stands (about having no guarantees when
dealing with TIMESTAMP_COPY). I think this should be mentioned, perhaps with
a note that since it is userspace that provides the source timestamps in this
case, it is also userspace's problem :-) Garbage in, garbage out.

Regards,

Hans
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Problem with PCTV Systems nanoStick T2 290e and frontends

2014-02-25 Thread Mauro Carvalho Chehab
Em Tue, 25 Feb 2014 09:22:28 +0100 (SNT)
Peter Fassberg p...@leissner.se escreveu:

 
 Hi!
 
 I have an PCTV Systems nanoStick T2 290e.
 
 It shows up very differently with different kernels, and it seems to work 
 better (DVB-C support) in an OLDER kernel.
 
 Old kernel is using em28xx and showing two frontends (as stated on the wiki 
 docs). New kernel is using em28174

The driver is the same. The printed messages were improved: they now
prints the exact chipset name (em28174, on your case), instead of
em28xx (where xx is an alias for whatever).

 and showing only a DVB-T frontend.

Is this device capable of streaming with both DVB-C and DVB-T at the same
time? E. g., does it have two separate frontend chips?

If not, then the driver is actually detecting the device right,
and it is likely exporting just one frontend with is capable of either
work with DVB-T or DVB-C (with is configurable via the DVBv5 API).

If you're using an application that only implements the legacy DVBv3 API,
then you can use the dvb-fe-tool tool (part of v4l-utils) to manually
switch between DVB-T2, DVB-T and DVB-C modes.

 
 Is there a way to force the new kernel to use em28xx instead?
 
 
 Excerpt from log:
 
 Using Linux debian 3.2.0-4-amd64 #1 SMP Debian 3.2.54-2 x86_64 GNU/Linux:
 
 [   90.006701] em28xx: New device PCTV Systems PCTV 290e @ 480 Mbps 
 (2013:024f, interface 0, class 0)
 [   90.007281] em28xx #0: chip ID is em28174
 [   90.333600] em28xx #0: Identified as PCTV nanoStick T2 290e (card=78)
 [   90.377066] em28xx #0: v4l2 driver version 0.1.3
 [   90.447548] em28xx #0: V4L2 video device registered as video0
 [   90.447584] usbcore: registered new interface driver em28xx
 [   90.447586] em28xx driver loaded
 [   90.520717] tda18271 0-0060: creating new instance
 [   90.551187] TDA18271HD/C2 detected @ 0-0060
 [   91.341140] tda18271 0-0060: attaching existing instance
 [   91.341145] DVB: registering new adapter (em28xx #0)
 [   91.341150] DVB: registering adapter 0 frontend 0 (Sony CXD2820R 
 (DVB-T/T2))...
 [   91.342477] DVB: registering adapter 0 frontend 1 (Sony CXD2820R 
 (DVB-C))...

Yeah, from this log, it is clear that your device has only one frontend:
Sony CXD2820R. This frontend could be used for DVB-T/T2/C, but not at the
same time.

 [   91.345700] em28xx #0: Successfully loaded em28xx-dvb
 [   91.345706] Em28xx: Initialized (Em28xx dvb Extension) extension
 
 
 And from Linux debian 3.12-1-amd64 #1 SMP Debian 3.12.9-1 (2014-02-01) x86_64 
 GNU/Linux:
 
 [207774.334552] em28xx: New device PCTV Systems PCTV 290e @ 480 Mbps 
 (2013:024f, interface 0, class 0)
 [207774.334557] em28xx: DVB interface 0 found: isoc
 [207774.335059] em28xx: chip ID is em28174
 [207774.734814] em28174 #0: Identified as PCTV nanoStick T2 290e (card=78)
 [207774.734821] em28174 #0: v4l2 driver version 0.2.0
 [207774.814336] em28174 #0: V4L2 video device registered as video0
 [207774.814341] em28174 #0: dvb set to isoc mode.
 [207774.823844] usbcore: registered new interface driver em28xx
 [207774.895574] tda18271 1-0060: creating new instance
 [207774.926952] TDA18271HD/C2 detected @ 1-0060
 [207775.290440] DVB: registering new adapter (em28174 #0)
 [207775.290453] usb 1-1: DVB: registering adapter 0 frontend 0 (Sony 
 CXD2820R)...

And the Sony frontend now is properly mapped as just one device.

 [207775.294597] em28174 #0: Successfully loaded em28xx-dvb
 [207775.294602] Em28xx: Initialized (Em28xx dvb Extension) extension
 
 Linux debian 3.12-1-amd64 #1 SMP Debian 3.12.9-1 (2014-02-01) x86_64 GNU/Linux
 
 
 Best regards,
 
 -- Peter
 

Regards,
-- 

Cheers,
Mauro
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[REVIEWv2 PATCH 00/15] vb2: fixes, balancing callbacks (PART 1)

2014-02-25 Thread Hans Verkuil
My previous patch series had a bug in patch 12/14 and I found a new bug as
well that had to be fixed.

Changes since REVIEWv1:

- patch 12/14 has been replaced with a new patch that really fixes the problem
- a new patch 14 was added to fix a streamoff problem.

This patch series is the second REVIEW series as opposed to an RFC
series. It follows RFCv4:

http://www.spinics.net/lists/linux-media/msg73039.html

This is part 1 of vb2 changes. Part 2 has already been posted.

Ignore patches 1-3: the first is already merged in 3.14, and 2 and 3
are pending to be merged in 3.14. But you need them for some follow-up
patches.

Patches 04-09 and 15 are unchanged from RFCv4.

Changelog since RFCv4:

- Dropped RFCv4 patch 08/11 as it was wrong. Instead, I added patch
  10/14. This fixes a bug in __vb2_queue_free() and improved the code
  that caused my misunderstanding with RFCv4 patch 08/11.
- In patch 11/14 I dropped the check against the minimum number of
  required buffers in create_bufs. Instead, check for this in streamon.
- Added patch 12: vb2: properly clean up PREPARED and QUEUED buffers
  This fixes one corner case that still produced 'Unbalanced' results.
- Added patch 13: vb2: replace BUG by WARN_ON
  Just a small change to be more gentle if the driver tries something
  it shouldn't.

This patch series fixes a series of bugs in vb2. Recently I have been
converting the saa7134 driver to vb2 and as part of that work I discovered
that the op calls were not properly balanced, which caused saa7134 to
fail.

Based on that I did more debugging and I found lots of different issues
with vb2 when it comes to balancing ops. This patch series fixes them.
Many thanks to Pawel Osciak for a good brainstorm session.

Patch 4 adds debugging code to check for unbalanced calls. I used this
when testing since without this it is very hard to verify correctness.
It is currently turned on when CONFIG_VIDEO_ADV_DEBUG is set, but perhaps
this should be placed under a vb2 specific debug option?

The next patch changes the buf_finish return type to void. It must not
fail, and you can't do anything useful if it does anyway.

Patch 6 just improves some comments.

Patches 7 and 8 fix several unbalanced ops.

Patch 9 just renames queue_count to owned_by_drv_count. The old name
suggests the number of buffers in the queue_list, but that's not what
it is. Since the next patch will actually add a real count for the
number of buffers in the queue_list I decided to just rename this,
thus freeing up the name 'queue_count'.

Patch 10 fixes a __vb2_queue_free() bug and makes __reqbufs and
__create_bufs code a bit more understandable.

Patch 11 fixes a bug in the handling of start_streaming: before that op
is called any prequeued buffers are handed over to the driver. But if
start_streaming returns an error, then those buffers are not reclaimed.
Since start_streaming failed, q-streaming is 0, so stop_streaming isn't
called either.

There are two reasons for an error in start_streaming: either a real
error when setting up the DMA engine occurred or there were not enough
buffers queued for the DMA engine to start (start_streaming returns
-ENOBUFS in that case). It makes sense to require that drivers return
queued buffers back to vb2 in case of an error, but not if they also 
have to do that in case of insufficient buffers. So this patch replaces
the -ENOBUFS mechanism by a vb2_queue field that tells vb2 what the
minimum number of buffers is.

Now if start_streaming returns an error the vb2 core will check if there
are still buffers owned by the driver and if so produce a warning and
reclaim those buffers. The same is done when the vb2_queue is freed.

This ensures that the prepare/finish memops are correctly called and
the state of all the buffers is consistent.

Patch 12 fixes another corner case introducing unbalanced ops.

Patch 13 replaces a BUG_ON by WARN_ON.

Patch 14 fixes a problem with STREAMOFF that doesn't do what you expect
if STREAMON hasn't been called but buffers have been prepared or queued.

Patch 15 fixes vivi for this start_streaming issue. Note that there are
many drivers that do not clean up properly in case of an error during
start_streaming.

I have been testing these vb2 changes with vivi (vmalloc based), a patched
saa7134 (dma-contig based) and an out-of-tree PCI driver (dma-sg based),
with the mmap/userptr/dmabuf and read/write streaming modes.

Regards,

Hans


--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[REVIEWv2 PATCH 14/15] vb2: fix streamoff handling if streamon wasn't called.

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

If you request buffers, then queue buffers and then call STREAMOFF
those buffers are not returned to their dequeued state because streamoff
will just return if q-streaming was 0.

This means that afterwards you can never QBUF that same buffer again unless
you do STREAMON, REQBUFS or close the filehandle first.

It is clear that if you do STREAMOFF even if no STREAMON was called before,
you still want to have all buffers returned to their proper dequeued state.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/v4l2-core/videobuf2-core.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index 68f3def..4af6457 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -2067,14 +2067,14 @@ static int vb2_internal_streamoff(struct vb2_queue *q, 
enum v4l2_buf_type type)
return -EINVAL;
}
 
-   if (!q-streaming) {
-   dprintk(3, streamoff successful: not streaming\n);
-   return 0;
-   }
-
/*
 * Cancel will pause streaming and remove all buffers from the driver
 * and videobuf, effectively returning control over them to userspace.
+*
+* Note that we do this even if q-streaming == 0: if you prepare or
+* queue buffers, and then call streamoff without ever having called
+* streamon, you would still expect those buffers to be returned to
+* their normal dequeued state.
 */
__vb2_queue_cancel(q);
 
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[REVIEWv2 PATCH 01/15] vb2: Check if there are buffers before streamon

2014-02-25 Thread Hans Verkuil
From: Ricardo Ribalda Delgado ricardo.riba...@gmail.com

This patch adds a test preventing streamon() if there is no buffer
ready.

Without this patch, a user could call streamon() before
preparing any buffer. This leads to a situation where if he calls
close() before calling streamoff() the device is kept streaming.

Signed-off-by: Ricardo Ribalda Delgado ricardo.riba...@gmail.com
Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/v4l2-core/videobuf2-core.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index 5a5fb7f..a127925 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -1776,6 +1776,11 @@ static int vb2_internal_streamon(struct vb2_queue *q, 
enum v4l2_buf_type type)
return 0;
}
 
+   if (!q-num_buffers) {
+   dprintk(1, streamon: no buffers have been allocated\n);
+   return -EINVAL;
+   }
+
/*
 * If any buffers were queued before streamon,
 * we can now pass them to driver for processing.
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[REVIEWv2 PATCH 04/15] vb2: add debugging code to check for unbalanced ops

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

When a vb2_queue is freed check if all the mem_ops and queue ops were balanced.
So the number of calls to e.g. buf_finish has to match the number of calls to
buf_prepare, etc.

This code is only enabled if CONFIG_VIDEO_ADV_DEBUG is set.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
Acked-by: Pawel Osciak pa...@osciak.com
---
 drivers/media/v4l2-core/videobuf2-core.c | 233 ---
 include/media/videobuf2-core.h   |  43 ++
 2 files changed, 226 insertions(+), 50 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index 909f367..8f1578b 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -33,12 +33,63 @@ module_param(debug, int, 0644);
printk(KERN_DEBUG vb2:  fmt, ## arg); \
} while (0)
 
-#define call_memop(q, op, args...) \
-   (((q)-mem_ops-op) ?   \
-   ((q)-mem_ops-op(args)) : 0)
+#ifdef CONFIG_VIDEO_ADV_DEBUG
+
+/*
+ * If advanced debugging is on, then count how often each op is called,
+ * which can either be per-buffer or per-queue.
+ *
+ * If the op failed then the 'fail_' variant is called to decrease the
+ * counter. That makes it easy to check that the 'init' and 'cleanup'
+ * (and variations thereof) stay balanced.
+ */
+
+#define call_memop(vb, op, args...)\
+({ \
+   struct vb2_queue *_q = (vb)-vb2_queue; \
+   dprintk(2, call_memop(%p, %d, %s)%s\n,\
+   _q, (vb)-v4l2_buf.index, #op,  \
+   _q-mem_ops-op ?  :  (nop));   \
+   (vb)-cnt_mem_ ## op++; \
+   _q-mem_ops-op ? _q-mem_ops-op(args) : 0;\
+})
+#define fail_memop(vb, op) ((vb)-cnt_mem_ ## op--)
+
+#define call_qop(q, op, args...)   \
+({ \
+   dprintk(2, call_qop(%p, %s)%s\n, q, #op,  \
+   (q)-ops-op ?  :  (nop));  \
+   (q)-cnt_ ## op++;  \
+   (q)-ops-op ? (q)-ops-op(args) : 0;  \
+})
+#define fail_qop(q, op) ((q)-cnt_ ## op--)
+
+#define call_vb_qop(vb, op, args...)   \
+({ \
+   struct vb2_queue *_q = (vb)-vb2_queue; \
+   dprintk(2, call_vb_qop(%p, %d, %s)%s\n,   \
+   _q, (vb)-v4l2_buf.index, #op,  \
+   _q-ops-op ?  :  (nop));   \
+   (vb)-cnt_ ## op++; \
+   _q-ops-op ? _q-ops-op(args) : 0;\
+})
+#define fail_vb_qop(vb, op) ((vb)-cnt_ ## op--)
+
+#else
+
+#define call_memop(vb, op, args...)\
+   ((vb)-vb2_queue-mem_ops-op ? (vb)-vb2_queue-mem_ops-op(args) : 0)
+#define fail_memop(vb, op)
 
 #define call_qop(q, op, args...)   \
-   (((q)-ops-op) ? ((q)-ops-op(args)) : 0)
+   ((q)-ops-op ? (q)-ops-op(args) : 0)
+#define fail_qop(q, op)
+
+#define call_vb_qop(vb, op, args...)   \
+   ((vb)-vb2_queue-ops-op ? (vb)-vb2_queue-ops-op(args) : 0)
+#define fail_vb_qop(vb, op)
+
+#endif
 
 #define V4L2_BUFFER_MASK_FLAGS (V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_QUEUED | \
 V4L2_BUF_FLAG_DONE | V4L2_BUF_FLAG_ERROR | \
@@ -61,7 +112,7 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
for (plane = 0; plane  vb-num_planes; ++plane) {
unsigned long size = PAGE_ALIGN(q-plane_sizes[plane]);
 
-   mem_priv = call_memop(q, alloc, q-alloc_ctx[plane],
+   mem_priv = call_memop(vb, alloc, q-alloc_ctx[plane],
  size, q-gfp_flags);
if (IS_ERR_OR_NULL(mem_priv))
goto free;
@@ -73,9 +124,10 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb)
 
return 0;
 free:
+   fail_memop(vb, alloc);
/* Free already allocated memory if one of the allocations failed */
for (; plane  0; --plane) {
-   call_memop(q, put, vb-planes[plane - 1].mem_priv);
+   call_memop(vb, put, vb-planes[plane - 1].mem_priv);
vb-planes[plane - 1].mem_priv = NULL;
}
 
@@ -87,11 +139,10 @@ free:
  */
 static void __vb2_buf_mem_free(struct vb2_buffer *vb)
 {
-   struct vb2_queue *q = 

[REVIEWv2 PATCH 03/15] vb2: fix PREPARE_BUF regression

2014-02-25 Thread Hans Verkuil
Fix an incorrect test in vb2_internal_qbuf() where only DEQUEUED buffers
are allowed. But PREPARED buffers are also OK.

Introduced by commit 4138111a27859dcc56a5592c804dd16bb12a23d1
(vb2: simplify qbuf/prepare_buf by removing callback).

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/v4l2-core/videobuf2-core.c | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index f1a2857c..909f367 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -1420,11 +1420,6 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct 
v4l2_buffer *b)
return ret;
 
vb = q-bufs[b-index];
-   if (vb-state != VB2_BUF_STATE_DEQUEUED) {
-   dprintk(1, %s(): invalid buffer state %d\n, __func__,
-   vb-state);
-   return -EINVAL;
-   }
 
switch (vb-state) {
case VB2_BUF_STATE_DEQUEUED:
@@ -1438,7 +1433,8 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct 
v4l2_buffer *b)
dprintk(1, qbuf: buffer still being prepared\n);
return -EINVAL;
default:
-   dprintk(1, qbuf: buffer already in use\n);
+   dprintk(1, %s(): invalid buffer state %d\n, __func__,
+   vb-state);
return -EINVAL;
}
 
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[REVIEWv2 PATCH 13/15] vb2: replace BUG by WARN_ON

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

No need to oops for this, WARN_ON is good enough.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/v4l2-core/videobuf2-core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index 3815f9c..68f3def 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -2536,9 +2536,9 @@ static int __vb2_init_fileio(struct vb2_queue *q, int 
read)
/*
 * Sanity check
 */
-   if ((read  !(q-io_modes  VB2_READ)) ||
-  (!read  !(q-io_modes  VB2_WRITE)))
-   BUG();
+   if (WARN_ON((read  !(q-io_modes  VB2_READ)) ||
+   (!read  !(q-io_modes  VB2_WRITE
+   return -EINVAL;
 
/*
 * Check if device supports mapping buffers to kernel virtual space.
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[REVIEWv2 PATCH 12/15] vb2: properly clean up PREPARED and QUEUED buffers

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

In __vb2_dqbuf we need to call the finish memop for any pending
buffers in the PREPARED or QUEUED state. This can happen if PREPARE_BUF
or QBUF was called without ever calling STREAMON.

In that case, when either REQBUFS(0) is called or the filehandle is
closed __vb2_queue_cancel needs to handle such buffers correctly.

For the same reason a call to __vb2_queue_cancel was added in __reqbufs
so that these buffers are cleaned up there as well.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/v4l2-core/videobuf2-core.c | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index f156475..3815f9c 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -96,6 +96,8 @@ module_param(debug, int, 0644);
 V4L2_BUF_FLAG_PREPARED | \
 V4L2_BUF_FLAG_TIMESTAMP_MASK)
 
+static void __vb2_queue_cancel(struct vb2_queue *q);
+
 /**
  * __vb2_buf_mem_alloc() - allocate video memory for the given buffer
  */
@@ -789,6 +791,12 @@ static int __reqbufs(struct vb2_queue *q, struct 
v4l2_requestbuffers *req)
return -EBUSY;
}
 
+   /*
+* Call queue_cancel to clean up any buffers in the PREPARED or
+* QUEUED state which is possible if buffers were prepared or
+* queued without ever calling STREAMON.
+*/
+   __vb2_queue_cancel(q);
ret = __vb2_queue_free(q, q-num_buffers);
if (ret)
return ret;
@@ -1839,12 +1847,23 @@ EXPORT_SYMBOL_GPL(vb2_wait_for_all_buffers);
 static void __vb2_dqbuf(struct vb2_buffer *vb)
 {
struct vb2_queue *q = vb-vb2_queue;
+   unsigned int plane;
unsigned int i;
 
/* nothing to do if the buffer is already dequeued */
if (vb-state == VB2_BUF_STATE_DEQUEUED)
return;
 
+   /*
+* If it is prepared or queued the we 'finish' the buffer.
+* This can happen if buffers were prepared or queued without STREAMON
+* being called, and we are called by __vb2_queue_cancel.
+*/
+   if (vb-state == VB2_BUF_STATE_PREPARED ||
+   vb-state == VB2_BUF_STATE_QUEUED)
+   for (plane = 0; plane  vb-num_planes; ++plane)
+   call_memop(vb, finish, vb-planes[plane].mem_priv);
+
call_vb_qop(vb, buf_finish, vb);
 
vb-state = VB2_BUF_STATE_DEQUEUED;
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[REVIEWv2 PATCH 08/15] vb2: fix buf_init/buf_cleanup call sequences

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

Ensure that these ops are properly balanced.

There are two scenarios:

1) for MMAP buf_init is called when the buffers are created and buf_cleanup
   must be called when the queue is finally freed. This scenario was always
   working.

2) for USERPTR and DMABUF it is more complicated. When a buffer is queued
   the code checks if all planes of this buffer have been acquired before.
   If that's the case, then only buf_prepare has to be called. Otherwise
   buf_cleanup needs to be called if the buffer was acquired before, then,
   once all changed planes have been (re)acquired, buf_init has to be
   called followed by buf_prepare. Should buf_prepare fail, then buf_cleanup
   must be called on the newly acquired planes to release them in.

Finally, in __vb2_queue_free we have to check if the buffer was actually
acquired before calling buf_cleanup. While that it always true for MMAP
mode, it is not necessarily true for the other modes. E.g. if you just
call REQBUFS and close the file handle, then buffers were never queued and
so no buf_init was ever called.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/v4l2-core/videobuf2-core.c | 100 +--
 1 file changed, 67 insertions(+), 33 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index b5142e5..eefcff7 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -373,8 +373,10 @@ static int __vb2_queue_free(struct vb2_queue *q, unsigned 
int buffers)
/* Call driver-provided cleanup function for each buffer, if provided */
for (buffer = q-num_buffers - buffers; buffer  q-num_buffers;
 ++buffer) {
-   if (q-bufs[buffer])
-   call_vb_qop(q-bufs[buffer], buf_cleanup, 
q-bufs[buffer]);
+   struct vb2_buffer *vb = q-bufs[buffer];
+
+   if (vb  vb-planes[0].mem_priv)
+   call_vb_qop(vb, buf_cleanup, vb);
}
 
/* Release video buffer memory */
@@ -1161,6 +1163,7 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const 
struct v4l2_buffer *b)
unsigned int plane;
int ret;
int write = !V4L2_TYPE_IS_OUTPUT(q-type);
+   bool reacquired = vb-planes[0].mem_priv == NULL;
 
/* Copy relevant information provided by the userspace */
__fill_vb2_buffer(vb, b, planes);
@@ -1186,12 +1189,16 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const 
struct v4l2_buffer *b)
}
 
/* Release previously acquired memory if present */
-   if (vb-planes[plane].mem_priv)
+   if (vb-planes[plane].mem_priv) {
+   if (!reacquired) {
+   reacquired = true;
+   call_vb_qop(vb, buf_cleanup, vb);
+   }
call_memop(vb, put_userptr, vb-planes[plane].mem_priv);
+   }
 
vb-planes[plane].mem_priv = NULL;
-   vb-v4l2_planes[plane].m.userptr = 0;
-   vb-v4l2_planes[plane].length = 0;
+   memset(vb-v4l2_planes[plane], 0, sizeof(struct v4l2_plane));
 
/* Acquire each plane's memory */
mem_priv = call_memop(vb, get_userptr, q-alloc_ctx[plane],
@@ -1208,23 +1215,34 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const 
struct v4l2_buffer *b)
}
 
/*
-* Call driver-specific initialization on the newly acquired buffer,
-* if provided.
-*/
-   ret = call_vb_qop(vb, buf_init, vb);
-   if (ret) {
-   dprintk(1, qbuf: buffer initialization failed\n);
-   fail_vb_qop(vb, buf_init);
-   goto err;
-   }
-
-   /*
 * Now that everything is in order, copy relevant information
 * provided by userspace.
 */
for (plane = 0; plane  vb-num_planes; ++plane)
vb-v4l2_planes[plane] = planes[plane];
 
+   if (reacquired) {
+   /*
+* One or more planes changed, so we must call buf_init to do
+* the driver-specific initialization on the newly acquired
+* buffer, if provided.
+*/
+   ret = call_vb_qop(vb, buf_init, vb);
+   if (ret) {
+   dprintk(1, qbuf: buffer initialization failed\n);
+   fail_vb_qop(vb, buf_init);
+   goto err;
+   }
+   }
+
+   ret = call_vb_qop(vb, buf_prepare, vb);
+   if (ret) {
+   dprintk(1, qbuf: buffer preparation failed\n);
+   fail_vb_qop(vb, buf_prepare);
+   call_vb_qop(vb, buf_cleanup, vb);
+   goto err;
+   }
+
return 0;
 err:
/* In case of errors, release planes that were already 

[REVIEWv2 PATCH 06/15] vb2: add note that buf_finish can be called with !vb2_is_streaming()

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

Drivers need to be aware that buf_finish can be called when there is no
streaming going on, so make a note of that.

Also add a bunch of missing periods at the end of sentences.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
Acked-by: Pawel Osciak pa...@osciak.com
---
 include/media/videobuf2-core.h | 44 ++
 1 file changed, 23 insertions(+), 21 deletions(-)

diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
index f443ce0..82b7f0f 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-core.h
@@ -34,49 +34,49 @@ struct vb2_fileio_data;
  * usually will result in the allocator freeing the buffer (if
  * no other users of this buffer are present); the buf_priv
  * argument is the allocator private per-buffer structure
- * previously returned from the alloc callback
+ * previously returned from the alloc callback.
  * @get_userptr: acquire userspace memory for a hardware operation; used for
  *  USERPTR memory types; vaddr is the address passed to the
  *  videobuf layer when queuing a video buffer of USERPTR type;
  *  should return an allocator private per-buffer structure
  *  associated with the buffer on success, NULL on failure;
  *  the returned private structure will then be passed as buf_priv
- *  argument to other ops in this structure
+ *  argument to other ops in this structure.
  * @put_userptr: inform the allocator that a USERPTR buffer will no longer
- *  be used
+ *  be used.
  * @attach_dmabuf: attach a shared struct dma_buf for a hardware operation;
  *used for DMABUF memory types; alloc_ctx is the alloc context
  *dbuf is the shared dma_buf; returns NULL on failure;
  *allocator private per-buffer structure on success;
- *this needs to be used for further accesses to the buffer
+ *this needs to be used for further accesses to the buffer.
  * @detach_dmabuf: inform the exporter of the buffer that the current DMABUF
  *buffer is no longer used; the buf_priv argument is the
  *allocator private per-buffer structure previously returned
- *from the attach_dmabuf callback
+ *from the attach_dmabuf callback.
  * @map_dmabuf: request for access to the dmabuf from allocator; the allocator
  * of dmabuf is informed that this driver is going to use the
- * dmabuf
+ * dmabuf.
  * @unmap_dmabuf: releases access control to the dmabuf - allocator is notified
- *   that this driver is done using the dmabuf for now
+ *   that this driver is done using the dmabuf for now.
  * @prepare:   called every time the buffer is passed from userspace to the
- * driver, useful for cache synchronisation, optional
+ * driver, useful for cache synchronisation, optional.
  * @finish:called every time the buffer is passed back from the driver
- * to the userspace, also optional
+ * to the userspace, also optional.
  * @vaddr: return a kernel virtual address to a given memory buffer
  * associated with the passed private structure or NULL if no
- * such mapping exists
+ * such mapping exists.
  * @cookie:return allocator specific cookie for a given memory buffer
  * associated with the passed private structure or NULL if not
- * available
+ * available.
  * @num_users: return the current number of users of a memory buffer;
  * return 1 if the videobuf layer (or actually the driver using
- * it) is the only user
+ * it) is the only user.
  * @mmap:  setup a userspace mapping for a given memory buffer under
- * the provided virtual memory region
+ * the provided virtual memory region.
  *
  * Required ops for USERPTR types: get_userptr, put_userptr.
  * Required ops for MMAP types: alloc, put, num_users, mmap.
- * Required ops for read/write access types: alloc, put, num_users, vaddr
+ * Required ops for read/write access types: alloc, put, num_users, vaddr.
  * Required ops for DMABUF types: attach_dmabuf, detach_dmabuf, map_dmabuf,
  *   unmap_dmabuf.
  */
@@ -258,27 +258,29 @@ struct vb2_buffer {
  * @wait_prepare:  release any locks taken while calling vb2 functions;
  * it is called before an ioctl needs to wait for a new
  * buffer to arrive; required to avoid a deadlock in
- * blocking access type
+ * blocking access type.
  * @wait_finish:   reacquire all locks released in the previous callback;
  *

[REVIEWv2 PATCH 02/15] vb2: fix read/write regression

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

Commit 88e268702bfba78448abd20a31129458707383aa (vb2: Improve file I/O
emulation to handle buffers in any order) broke read/write support if
the size of the buffer being read/written is less than the size of the
image.

When the commit was tested originally I used qv4l2, which calls read()
with exactly the size of the image. But if you try 'cat /dev/video0'
then it will fail and typically hang after reading two buffers.

This patch fixes the behavior by adding a new cur_index field that
contains the index of the field currently being filled/read, or it
is num_buffers in which case a new buffer needs to be dequeued.

The old index field has been renamed to initial_index in order to be
a bit more descriptive.

This has been tested with both read and write.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
Tested-by: Hans Verkuil hans.verk...@cisco.com
Cc: Andy Walls awa...@md.metrocast.net
---
 drivers/media/v4l2-core/videobuf2-core.c | 46 +++-
 1 file changed, 40 insertions(+), 6 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index a127925..f1a2857c 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -2251,6 +2251,22 @@ struct vb2_fileio_buf {
 /**
  * struct vb2_fileio_data - queue context used by file io emulator
  *
+ * @cur_index: the index of the buffer currently being read from or
+ * written to. If equal to q-num_buffers then a new buffer
+ * must be dequeued.
+ * @initial_index: in the read() case all buffers are queued up immediately
+ * in __vb2_init_fileio() and __vb2_perform_fileio() just cycles
+ * buffers. However, in the write() case no buffers are initially
+ * queued, instead whenever a buffer is full it is queued up by
+ * __vb2_perform_fileio(). Only once all available buffers have
+ * been queued up will __vb2_perform_fileio() start to dequeue
+ * buffers. This means that initially __vb2_perform_fileio()
+ * needs to know what buffer index to use when it is queuing up
+ * the buffers for the first time. That initial index is stored
+ * in this field. Once it is equal to q-num_buffers all
+ * available buffers have been queued and __vb2_perform_fileio()
+ * should start the normal dequeue/queue cycle.
+ *
  * vb2 provides a compatibility layer and emulator of file io (read and
  * write) calls on top of streaming API. For proper operation it required
  * this structure to save the driver state between each call of the read
@@ -2260,7 +2276,8 @@ struct vb2_fileio_data {
struct v4l2_requestbuffers req;
struct v4l2_buffer b;
struct vb2_fileio_buf bufs[VIDEO_MAX_FRAME];
-   unsigned int index;
+   unsigned int cur_index;
+   unsigned int initial_index;
unsigned int q_count;
unsigned int dq_count;
unsigned int flags;
@@ -2360,7 +2377,12 @@ static int __vb2_init_fileio(struct vb2_queue *q, int 
read)
goto err_reqbufs;
fileio-bufs[i].queued = 1;
}
-   fileio-index = q-num_buffers;
+   /*
+* All buffers have been queued, so mark that by setting
+* initial_index to q-num_buffers
+*/
+   fileio-initial_index = q-num_buffers;
+   fileio-cur_index = q-num_buffers;
}
 
/*
@@ -2439,7 +2461,7 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, 
char __user *data, size_
/*
 * Check if we need to dequeue the buffer.
 */
-   index = fileio-index;
+   index = fileio-cur_index;
if (index = q-num_buffers) {
/*
 * Call vb2_dqbuf to get buffer back.
@@ -2453,7 +2475,7 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, 
char __user *data, size_
return ret;
fileio-dq_count += 1;
 
-   index = fileio-b.index;
+   fileio-cur_index = index = fileio-b.index;
buf = fileio-bufs[index];
 
/*
@@ -2529,8 +2551,20 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, 
char __user *data, size_
buf-queued = 1;
buf-size = vb2_plane_size(q-bufs[index], 0);
fileio-q_count += 1;
-   if (fileio-index  q-num_buffers)
-   fileio-index++;
+   /*
+* If we are queuing up buffers for the first time, then
+* increase initial_index by one.
+*/
+   if (fileio-initial_index  q-num_buffers)
+   fileio-initial_index++;
+   /*
+* The next buffer to use is either a buffer that's 

[REVIEWv2 PATCH 09/15] vb2: rename queued_count to owned_by_drv_count

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

'queued_count' is a bit vague since it is not clear to which queue it
refers to: the vb2 internal list of buffers or the driver-owned list
of buffers.

Rename to make it explicit.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
Acked-by: Pawel Osciak pa...@osciak.com
---
 drivers/media/v4l2-core/videobuf2-core.c | 10 +-
 include/media/videobuf2-core.h   |  4 ++--
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index eefcff7..2a7815c 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -1071,7 +1071,7 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum 
vb2_buffer_state state)
spin_lock_irqsave(q-done_lock, flags);
vb-state = state;
list_add_tail(vb-done_entry, q-done_list);
-   atomic_dec(q-queued_count);
+   atomic_dec(q-owned_by_drv_count);
spin_unlock_irqrestore(q-done_lock, flags);
 
/* Inform any processes that may be waiting for buffers */
@@ -1402,7 +1402,7 @@ static void __enqueue_in_driver(struct vb2_buffer *vb)
unsigned int plane;
 
vb-state = VB2_BUF_STATE_ACTIVE;
-   atomic_inc(q-queued_count);
+   atomic_inc(q-owned_by_drv_count);
 
/* sync buffers */
for (plane = 0; plane  vb-num_planes; ++plane)
@@ -1554,7 +1554,7 @@ static int vb2_start_streaming(struct vb2_queue *q)
int ret;
 
/* Tell the driver to start streaming */
-   ret = call_qop(q, start_streaming, q, atomic_read(q-queued_count));
+   ret = call_qop(q, start_streaming, q, 
atomic_read(q-owned_by_drv_count));
if (ret)
fail_qop(q, start_streaming);
 
@@ -1775,7 +1775,7 @@ int vb2_wait_for_all_buffers(struct vb2_queue *q)
}
 
if (!q-retry_start_streaming)
-   wait_event(q-done_wq, !atomic_read(q-queued_count));
+   wait_event(q-done_wq, !atomic_read(q-owned_by_drv_count));
return 0;
 }
 EXPORT_SYMBOL_GPL(vb2_wait_for_all_buffers);
@@ -1907,7 +1907,7 @@ static void __vb2_queue_cancel(struct vb2_queue *q)
 * has not already dequeued before initiating cancel.
 */
INIT_LIST_HEAD(q-done_list);
-   atomic_set(q-queued_count, 0);
+   atomic_set(q-owned_by_drv_count, 0);
wake_up_all(q-done_wq);
 
/*
diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h
index 82b7f0f..adaffed 100644
--- a/include/media/videobuf2-core.h
+++ b/include/media/videobuf2-core.h
@@ -353,7 +353,7 @@ struct v4l2_fh;
  * @bufs:  videobuf buffer structures
  * @num_buffers: number of allocated/used buffers
  * @queued_list: list of buffers currently queued from userspace
- * @queued_count: number of buffers owned by the driver
+ * @owned_by_drv_count: number of buffers owned by the driver
  * @done_list: list of buffers ready to be dequeued to userspace
  * @done_lock: lock to protect done_list list
  * @done_wq:   waitqueue for processes waiting for buffers ready to be dequeued
@@ -385,7 +385,7 @@ struct vb2_queue {
 
struct list_headqueued_list;
 
-   atomic_tqueued_count;
+   atomic_towned_by_drv_count;
struct list_headdone_list;
spinlock_t  done_lock;
wait_queue_head_t   done_wq;
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[REVIEWv2 PATCH 11/15] vb2: only call start_streaming if sufficient buffers are queued

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

In commit 02f142ecd24aaf891324ffba8527284c1731b561 support was added to
start_streaming to return -ENOBUFS if insufficient buffers were queued
for the DMA engine to start. The vb2 core would attempt calling
start_streaming again if another buffer would be queued up.

Later analysis uncovered problems with the queue management if start_streaming
would return an error: the buffers are enqueued to the driver before the
start_streaming op is called, so after an error they are never returned to
the vb2 core. The solution for this is to let the driver return them to
the vb2 core in case of an error while starting the DMA engine. However,
in the case of -ENOBUFS that would be weird: it is not a real error, it
just says that more buffers are needed. Requiring start_streaming to give
them back only to have them requeued again the next time the application
calls QBUF is inefficient.

This patch changes this mechanism: it adds a 'min_buffers_needed' field
to vb2_queue that drivers can set with the minimum number of buffers
required to start the DMA engine. The start_streaming op is only called
if enough buffers are queued. The -ENOBUFS handling has been dropped in
favor of this new method.

Drivers are expected to return buffers back to vb2 core with state QUEUED
if start_streaming would return an error. The vb2 core checks for this
and produces a warning if that didn't happen and it will forcefully
reclaim such buffers to ensure that the internal vb2 core state remains
consistent and all buffer-related resources have been correctly freed
and all op calls have been balanced.

__reqbufs() has been updated to check that at least min_buffers_needed
buffers could be allocated. If fewer buffers were allocated then __reqbufs
will free what was allocated and return -ENOMEM. Based on a suggestion from
Pawel Osciak.

__create_bufs() doesn't do that check, since the use of __create_bufs
assumes some advance scenario where the user might want more control.
Instead streamon will check if enough buffers were allocated to prevent
streaming with fewer than the minimum required number of buffers.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/platform/davinci/vpbe_display.c   |   6 +-
 drivers/media/platform/davinci/vpif_capture.c   |   7 +-
 drivers/media/platform/davinci/vpif_display.c   |   7 +-
 drivers/media/platform/s5p-tv/mixer_video.c |   6 +-
 drivers/media/v4l2-core/videobuf2-core.c| 146 
 drivers/staging/media/davinci_vpfe/vpfe_video.c |   3 +-
 include/media/videobuf2-core.h  |  14 ++-
 7 files changed, 116 insertions(+), 73 deletions(-)

diff --git a/drivers/media/platform/davinci/vpbe_display.c 
b/drivers/media/platform/davinci/vpbe_display.c
index b02aba4..9231e48 100644
--- a/drivers/media/platform/davinci/vpbe_display.c
+++ b/drivers/media/platform/davinci/vpbe_display.c
@@ -344,11 +344,6 @@ static int vpbe_start_streaming(struct vb2_queue *vq, 
unsigned int count)
struct vpbe_device *vpbe_dev = fh-disp_dev-vpbe_dev;
int ret;
 
-   /* If buffer queue is empty, return error */
-   if (list_empty(layer-dma_queue)) {
-   v4l2_err(vpbe_dev-v4l2_dev, buffer queue is empty\n);
-   return -ENOBUFS;
-   }
/* Get the next frame from the buffer queue */
layer-next_frm = layer-cur_frm = list_entry(layer-dma_queue.next,
struct vpbe_disp_buffer, list);
@@ -1416,6 +1411,7 @@ static int vpbe_display_reqbufs(struct file *file, void 
*priv,
q-mem_ops = vb2_dma_contig_memops;
q-buf_struct_size = sizeof(struct vpbe_disp_buffer);
q-timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
+   q-min_buffers_needed = 1;
 
ret = vb2_queue_init(q);
if (ret) {
diff --git a/drivers/media/platform/davinci/vpif_capture.c 
b/drivers/media/platform/davinci/vpif_capture.c
index 735ec47..9731ad4 100644
--- a/drivers/media/platform/davinci/vpif_capture.c
+++ b/drivers/media/platform/davinci/vpif_capture.c
@@ -272,13 +272,7 @@ static int vpif_start_streaming(struct vb2_queue *vq, 
unsigned int count)
unsigned long flags;
int ret;
 
-   /* If buffer queue is empty, return error */
spin_lock_irqsave(common-irqlock, flags);
-   if (list_empty(common-dma_queue)) {
-   spin_unlock_irqrestore(common-irqlock, flags);
-   vpif_dbg(1, debug, buffer queue is empty\n);
-   return -ENOBUFS;
-   }
 
/* Get the next frame from the buffer queue */
common-cur_frm = common-next_frm = list_entry(common-dma_queue.next,
@@ -1024,6 +1018,7 @@ static int vpif_reqbufs(struct file *file, void *priv,
q-mem_ops = vb2_dma_contig_memops;
q-buf_struct_size = sizeof(struct vpif_cap_buffer);
q-timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
+   q-min_buffers_needed = 1;
 
ret = vb2_queue_init(q);
 

[REVIEWv2 PATCH 05/15] vb2: change result code of buf_finish to void

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

The buf_finish op should always work, so change the return type to void.
Update the few drivers that use it. Note that buf_finish can be called
both when the DMA is streaming and when it isn't (during queue_cancel).
Update drivers to check that where appropriate.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
Acked-by: Pawel Osciak pa...@osciak.com
Reviewed-by: Pawel Osciak pa...@osciak.com
---
 drivers/media/parport/bw-qcam.c |  6 --
 drivers/media/pci/sta2x11/sta2x11_vip.c |  7 +++
 drivers/media/platform/marvell-ccic/mcam-core.c |  3 +--
 drivers/media/usb/pwc/pwc-if.c  | 16 +---
 drivers/media/usb/uvc/uvc_queue.c   |  6 +++---
 drivers/media/v4l2-core/videobuf2-core.c|  6 +-
 drivers/staging/media/go7007/go7007-v4l2.c  |  3 +--
 include/media/videobuf2-core.h  |  2 +-
 8 files changed, 23 insertions(+), 26 deletions(-)

diff --git a/drivers/media/parport/bw-qcam.c b/drivers/media/parport/bw-qcam.c
index d12bd33..8d69bfb 100644
--- a/drivers/media/parport/bw-qcam.c
+++ b/drivers/media/parport/bw-qcam.c
@@ -667,13 +667,16 @@ static void buffer_queue(struct vb2_buffer *vb)
vb2_buffer_done(vb, VB2_BUF_STATE_DONE);
 }
 
-static int buffer_finish(struct vb2_buffer *vb)
+static void buffer_finish(struct vb2_buffer *vb)
 {
struct qcam *qcam = vb2_get_drv_priv(vb-vb2_queue);
void *vbuf = vb2_plane_vaddr(vb, 0);
int size = vb-vb2_queue-plane_sizes[0];
int len;
 
+   if (!vb2_is_streaming(vb-vb2_queue))
+   return;
+
mutex_lock(qcam-lock);
parport_claim_or_block(qcam-pdev);
 
@@ -691,7 +694,6 @@ static int buffer_finish(struct vb2_buffer *vb)
if (len != size)
vb-state = VB2_BUF_STATE_ERROR;
vb2_set_plane_payload(vb, 0, len);
-   return 0;
 }
 
 static struct vb2_ops qcam_video_qops = {
diff --git a/drivers/media/pci/sta2x11/sta2x11_vip.c 
b/drivers/media/pci/sta2x11/sta2x11_vip.c
index e5cfb6c..bb11443 100644
--- a/drivers/media/pci/sta2x11/sta2x11_vip.c
+++ b/drivers/media/pci/sta2x11/sta2x11_vip.c
@@ -327,7 +327,7 @@ static void buffer_queue(struct vb2_buffer *vb)
}
spin_unlock(vip-lock);
 }
-static int buffer_finish(struct vb2_buffer *vb)
+static void buffer_finish(struct vb2_buffer *vb)
 {
struct sta2x11_vip *vip = vb2_get_drv_priv(vb-vb2_queue);
struct vip_buffer *vip_buf = to_vip_buffer(vb);
@@ -337,9 +337,8 @@ static int buffer_finish(struct vb2_buffer *vb)
list_del_init(vip_buf-list);
spin_unlock(vip-lock);
 
-   vip_active_buf_next(vip);
-
-   return 0;
+   if (vb2_is_streaming(vb-vb2_queue))
+   vip_active_buf_next(vip);
 }
 
 static int start_streaming(struct vb2_queue *vq, unsigned int count)
diff --git a/drivers/media/platform/marvell-ccic/mcam-core.c 
b/drivers/media/platform/marvell-ccic/mcam-core.c
index 32fab30..8b34c48 100644
--- a/drivers/media/platform/marvell-ccic/mcam-core.c
+++ b/drivers/media/platform/marvell-ccic/mcam-core.c
@@ -1238,7 +1238,7 @@ static int mcam_vb_sg_buf_prepare(struct vb2_buffer *vb)
return 0;
 }
 
-static int mcam_vb_sg_buf_finish(struct vb2_buffer *vb)
+static void mcam_vb_sg_buf_finish(struct vb2_buffer *vb)
 {
struct mcam_camera *cam = vb2_get_drv_priv(vb-vb2_queue);
struct sg_table *sg_table = vb2_dma_sg_plane_desc(vb, 0);
@@ -1246,7 +1246,6 @@ static int mcam_vb_sg_buf_finish(struct vb2_buffer *vb)
if (sg_table)
dma_unmap_sg(cam-dev, sg_table-sgl,
sg_table-nents, DMA_FROM_DEVICE);
-   return 0;
 }
 
 static void mcam_vb_sg_buf_cleanup(struct vb2_buffer *vb)
diff --git a/drivers/media/usb/pwc/pwc-if.c b/drivers/media/usb/pwc/pwc-if.c
index abf365a..b9c9f10 100644
--- a/drivers/media/usb/pwc/pwc-if.c
+++ b/drivers/media/usb/pwc/pwc-if.c
@@ -614,17 +614,19 @@ static int buffer_prepare(struct vb2_buffer *vb)
return 0;
 }
 
-static int buffer_finish(struct vb2_buffer *vb)
+static void buffer_finish(struct vb2_buffer *vb)
 {
struct pwc_device *pdev = vb2_get_drv_priv(vb-vb2_queue);
struct pwc_frame_buf *buf = container_of(vb, struct pwc_frame_buf, vb);
 
-   /*
-* Application has called dqbuf and is getting back a buffer we've
-* filled, take the pwc data we've stored in buf-data and decompress
-* it into a usable format, storing the result in the vb2_buffer
-*/
-   return pwc_decompress(pdev, buf);
+   if (vb-state == VB2_BUF_STATE_DONE) {
+   /*
+* Application has called dqbuf and is getting back a buffer 
we've
+* filled, take the pwc data we've stored in buf-data and 
decompress
+* it into a usable format, storing the result in the vb2_buffer
+*/
+   pwc_decompress(pdev, buf);
+   }
 }
 
 static void 

[REVIEWv2 PATCH 15/15] vivi: correctly cleanup after a start_streaming failure

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

If start_streaming fails then any queued buffers must be given back
to the vb2 core.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/platform/vivi.c | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
index e9cd96e..643937b 100644
--- a/drivers/media/platform/vivi.c
+++ b/drivers/media/platform/vivi.c
@@ -889,10 +889,20 @@ static void buffer_queue(struct vb2_buffer *vb)
 static int start_streaming(struct vb2_queue *vq, unsigned int count)
 {
struct vivi_dev *dev = vb2_get_drv_priv(vq);
+   int err;
 
dprintk(dev, 1, %s\n, __func__);
dev-seq_count = 0;
-   return vivi_start_generating(dev);
+   err = vivi_start_generating(dev);
+   if (err) {
+   struct vivi_buffer *buf, *tmp;
+
+   list_for_each_entry_safe(buf, tmp, dev-vidq.active, list) {
+   list_del(buf-list);
+   vb2_buffer_done(buf-vb, VB2_BUF_STATE_QUEUED);
+   }
+   }
+   return err;
 }
 
 /* abort streaming and wait for last buffer */
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[REVIEWv2 PATCH 07/15] vb2: call buf_finish from __dqbuf

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

This ensures that it is also called from queue_cancel, which also calls
__dqbuf(). Without this change any time queue_cancel is called while
streaming the buf_finish op will not be called and any driver cleanup
will not happen.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
Acked-by: Pawel Osciak pa...@osciak.com
---
 drivers/media/v4l2-core/videobuf2-core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index 59bfd85..b5142e5 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -1758,6 +1758,8 @@ static void __vb2_dqbuf(struct vb2_buffer *vb)
if (vb-state == VB2_BUF_STATE_DEQUEUED)
return;
 
+   call_vb_qop(vb, buf_finish, vb);
+
vb-state = VB2_BUF_STATE_DEQUEUED;
 
/* unmap DMABUF buffer */
@@ -1783,8 +1785,6 @@ static int vb2_internal_dqbuf(struct vb2_queue *q, struct 
v4l2_buffer *b, bool n
if (ret  0)
return ret;
 
-   call_vb_qop(vb, buf_finish, vb);
-
switch (vb-state) {
case VB2_BUF_STATE_DONE:
dprintk(3, dqbuf: Returning done buffer\n);
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[REVIEWv2 PATCH 10/15] vb2: don't init the list if there are still buffers

2014-02-25 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

__vb2_queue_free() would init the queued_list at all times, even if
q-num_buffers  0. This should only happen if num_buffers == 0.

This situation can happen if a CREATE_BUFFERS call couldn't allocate
enough buffers and had to free those it did manage to allocate before
returning an error.

While we're at it: __vb2_queue_alloc() returns the number of buffers
allocated, not an error code. So stick the result in allocated_buffers
instead of ret as that's very confusing.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/v4l2-core/videobuf2-core.c | 29 +
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c 
b/drivers/media/v4l2-core/videobuf2-core.c
index 2a7815c..90374c0 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -452,9 +452,10 @@ static int __vb2_queue_free(struct vb2_queue *q, unsigned 
int buffers)
}
 
q-num_buffers -= buffers;
-   if (!q-num_buffers)
+   if (!q-num_buffers) {
q-memory = 0;
-   INIT_LIST_HEAD(q-queued_list);
+   INIT_LIST_HEAD(q-queued_list);
+   }
return 0;
 }
 
@@ -820,14 +821,12 @@ static int __reqbufs(struct vb2_queue *q, struct 
v4l2_requestbuffers *req)
}
 
/* Finally, allocate buffers and video memory */
-   ret = __vb2_queue_alloc(q, req-memory, num_buffers, num_planes);
-   if (ret == 0) {
+   allocated_buffers = __vb2_queue_alloc(q, req-memory, num_buffers, 
num_planes);
+   if (allocated_buffers == 0) {
dprintk(1, Memory allocation failed\n);
return -ENOMEM;
}
 
-   allocated_buffers = ret;
-
/*
 * Check if driver can handle the allocated number of buffers.
 */
@@ -851,6 +850,10 @@ static int __reqbufs(struct vb2_queue *q, struct 
v4l2_requestbuffers *req)
q-num_buffers = allocated_buffers;
 
if (ret  0) {
+   /*
+* Note: __vb2_queue_free() will subtract 'allocated_buffers'
+* from q-num_buffers.
+*/
__vb2_queue_free(q, allocated_buffers);
return ret;
}
@@ -924,20 +927,18 @@ static int __create_bufs(struct vb2_queue *q, struct 
v4l2_create_buffers *create
}
 
/* Finally, allocate buffers and video memory */
-   ret = __vb2_queue_alloc(q, create-memory, num_buffers,
+   allocated_buffers = __vb2_queue_alloc(q, create-memory, num_buffers,
num_planes);
-   if (ret == 0) {
+   if (allocated_buffers == 0) {
dprintk(1, Memory allocation failed\n);
return -ENOMEM;
}
 
-   allocated_buffers = ret;
-
/*
 * Check if driver can handle the so far allocated number of buffers.
 */
-   if (ret  num_buffers) {
-   num_buffers = ret;
+   if (allocated_buffers  num_buffers) {
+   num_buffers = allocated_buffers;
 
/*
 * q-num_buffers contains the total number of buffers, that the
@@ -960,6 +961,10 @@ static int __create_bufs(struct vb2_queue *q, struct 
v4l2_create_buffers *create
q-num_buffers += allocated_buffers;
 
if (ret  0) {
+   /*
+* Note: __vb2_queue_free() will subtract 'allocated_buffers'
+* from q-num_buffers.
+*/
__vb2_queue_free(q, allocated_buffers);
return -ENOMEM;
}
-- 
1.9.0

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


RE: [PATCH v5 5/7] exynos-gsc, m2m-deinterlace, mx2_emmaprp: Copy v4l2_buffer data from src to dst

2014-02-25 Thread Kamil Debski
Hi Sakari,

 From: Sakari Ailus [mailto:sakari.ai...@iki.fi]
 Sent: Saturday, February 15, 2014 9:53 PM
 
 The timestamp and timecode fields were copied from destination to
 source, not the other way around as they should. Fix it.
 
 Signed-off-by: Sakari Ailus sakari.ai...@iki.fi

Acked-by: Kamil Debski k.deb...@samsung.com

 ---
  drivers/media/platform/exynos-gsc/gsc-m2m.c |4 ++--
  drivers/media/platform/m2m-deinterlace.c|4 ++--
  drivers/media/platform/mx2_emmaprp.c|4 ++--
  3 files changed, 6 insertions(+), 6 deletions(-)
 
 diff --git a/drivers/media/platform/exynos-gsc/gsc-m2m.c
 b/drivers/media/platform/exynos-gsc/gsc-m2m.c
 index 810c3e1..62c84d5 100644
 --- a/drivers/media/platform/exynos-gsc/gsc-m2m.c
 +++ b/drivers/media/platform/exynos-gsc/gsc-m2m.c
 @@ -88,8 +88,8 @@ void gsc_m2m_job_finish(struct gsc_ctx *ctx, int
 vb_state)
   dst_vb = v4l2_m2m_dst_buf_remove(ctx-m2m_ctx);
 
   if (src_vb  dst_vb) {
 - src_vb-v4l2_buf.timestamp = dst_vb-v4l2_buf.timestamp;
 - src_vb-v4l2_buf.timecode = dst_vb-v4l2_buf.timecode;
 + dst_vb-v4l2_buf.timestamp = src_vb-v4l2_buf.timestamp;
 + dst_vb-v4l2_buf.timecode = src_vb-v4l2_buf.timecode;

It is such a silly mistake that I had to think for a while why
could it be copied the other way. I suppose this happens when
coding in a hurry :( Thank you for spotting this.

 
   v4l2_m2m_buf_done(src_vb, vb_state);
   v4l2_m2m_buf_done(dst_vb, vb_state);
 diff --git a/drivers/media/platform/m2m-deinterlace.c
 b/drivers/media/platform/m2m-deinterlace.c
 index 6bb86b5..1f272d3 100644
 --- a/drivers/media/platform/m2m-deinterlace.c
 +++ b/drivers/media/platform/m2m-deinterlace.c
 @@ -207,8 +207,8 @@ static void dma_callback(void *data)
   src_vb = v4l2_m2m_src_buf_remove(curr_ctx-m2m_ctx);
   dst_vb = v4l2_m2m_dst_buf_remove(curr_ctx-m2m_ctx);
 
 - src_vb-v4l2_buf.timestamp = dst_vb-v4l2_buf.timestamp;
 - src_vb-v4l2_buf.timecode = dst_vb-v4l2_buf.timecode;
 + dst_vb-v4l2_buf.timestamp = src_vb-v4l2_buf.timestamp;
 + dst_vb-v4l2_buf.timecode = src_vb-v4l2_buf.timecode;
 
   v4l2_m2m_buf_done(src_vb, VB2_BUF_STATE_DONE);
   v4l2_m2m_buf_done(dst_vb, VB2_BUF_STATE_DONE); diff --git
 a/drivers/media/platform/mx2_emmaprp.c
 b/drivers/media/platform/mx2_emmaprp.c
 index c690435..91056ac0 100644
 --- a/drivers/media/platform/mx2_emmaprp.c
 +++ b/drivers/media/platform/mx2_emmaprp.c
 @@ -377,8 +377,8 @@ static irqreturn_t emmaprp_irq(int irq_emma, void
 *data)
   src_vb = v4l2_m2m_src_buf_remove(curr_ctx-m2m_ctx);
   dst_vb = v4l2_m2m_dst_buf_remove(curr_ctx-m2m_ctx);
 
 - src_vb-v4l2_buf.timestamp = dst_vb-
 v4l2_buf.timestamp;
 - src_vb-v4l2_buf.timecode = dst_vb-
 v4l2_buf.timecode;
 + dst_vb-v4l2_buf.timestamp = src_vb-
 v4l2_buf.timestamp;
 + dst_vb-v4l2_buf.timecode = src_vb-
 v4l2_buf.timecode;
 
   spin_lock_irqsave(pcdev-irqlock, flags);
   v4l2_m2m_buf_done(src_vb, VB2_BUF_STATE_DONE);
 --
 1.7.10.4

Best wishes,
-- 
Kamil Debski
Samsung RD Institute Poland

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


RE: [PATCH v5 6/7] v4l: Copy timestamp source flags to destination on m2m devices

2014-02-25 Thread Kamil Debski
Hi Sakari,

 From: Sakari Ailus [mailto:sakari.ai...@iki.fi]
 Sent: Saturday, February 15, 2014 9:53 PM
 
 Copy the flags containing the timestamp source from source buffer flags
 to the destination buffer flags on memory-to-memory devices. This is
 analogous to copying the timestamp field from source to destination.

This patch looks good to me.
 
 Signed-off-by: Sakari Ailus sakari.ai...@iki.fi

Acked-by: Kamil Debski k.deb...@samsung.com

 ---
  drivers/media/platform/coda.c|3 +++
  drivers/media/platform/exynos-gsc/gsc-m2m.c  |4 
  drivers/media/platform/exynos4-is/fimc-m2m.c |3 +++
  drivers/media/platform/m2m-deinterlace.c |3 +++
  drivers/media/platform/mem2mem_testdev.c |3 +++
  drivers/media/platform/mx2_emmaprp.c |5 +
  drivers/media/platform/s5p-g2d/g2d.c |3 +++
  drivers/media/platform/s5p-jpeg/jpeg-core.c  |3 +++
  drivers/media/platform/s5p-mfc/s5p_mfc.c |5 +
  drivers/media/platform/ti-vpe/vpe.c  |2 ++
  10 files changed, 34 insertions(+)
 
 diff --git a/drivers/media/platform/coda.c
 b/drivers/media/platform/coda.c index 61f3dbc..fe6dee6 100644
 --- a/drivers/media/platform/coda.c
 +++ b/drivers/media/platform/coda.c
 @@ -2829,6 +2829,9 @@ static void coda_finish_encode(struct coda_ctx
 *ctx)
   }
 
   dst_buf-v4l2_buf.timestamp = src_buf-v4l2_buf.timestamp;
 + dst_buf-v4l2_buf.flags = ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
 + dst_buf-v4l2_buf.flags |=
 + src_buf-v4l2_buf.flags  V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
   dst_buf-v4l2_buf.timecode = src_buf-v4l2_buf.timecode;
 
   v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_DONE); diff --git
 a/drivers/media/platform/exynos-gsc/gsc-m2m.c
 b/drivers/media/platform/exynos-gsc/gsc-m2m.c
 index 62c84d5..4260ea5 100644
 --- a/drivers/media/platform/exynos-gsc/gsc-m2m.c
 +++ b/drivers/media/platform/exynos-gsc/gsc-m2m.c
 @@ -90,6 +90,10 @@ void gsc_m2m_job_finish(struct gsc_ctx *ctx, int
 vb_state)
   if (src_vb  dst_vb) {
   dst_vb-v4l2_buf.timestamp = src_vb-v4l2_buf.timestamp;
   dst_vb-v4l2_buf.timecode = src_vb-v4l2_buf.timecode;
 + dst_vb-v4l2_buf.flags = ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
 + dst_vb-v4l2_buf.flags |=
 + src_vb-v4l2_buf.flags
 +  V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
 
   v4l2_m2m_buf_done(src_vb, vb_state);
   v4l2_m2m_buf_done(dst_vb, vb_state);
 diff --git a/drivers/media/platform/exynos4-is/fimc-m2m.c
 b/drivers/media/platform/exynos4-is/fimc-m2m.c
 index 9da95bd..a4249a1 100644
 --- a/drivers/media/platform/exynos4-is/fimc-m2m.c
 +++ b/drivers/media/platform/exynos4-is/fimc-m2m.c
 @@ -134,6 +134,9 @@ static void fimc_device_run(void *priv)
   goto dma_unlock;
 
   dst_vb-v4l2_buf.timestamp = src_vb-v4l2_buf.timestamp;
 + dst_vb-v4l2_buf.flags = ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
 + dst_vb-v4l2_buf.flags |=
 + src_vb-v4l2_buf.flags  V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
 
   /* Reconfigure hardware if the context has changed. */
   if (fimc-m2m.ctx != ctx) {
 diff --git a/drivers/media/platform/m2m-deinterlace.c
 b/drivers/media/platform/m2m-deinterlace.c
 index 1f272d3..79ffdab 100644
 --- a/drivers/media/platform/m2m-deinterlace.c
 +++ b/drivers/media/platform/m2m-deinterlace.c
 @@ -208,6 +208,9 @@ static void dma_callback(void *data)
   dst_vb = v4l2_m2m_dst_buf_remove(curr_ctx-m2m_ctx);
 
   dst_vb-v4l2_buf.timestamp = src_vb-v4l2_buf.timestamp;
 + dst_vb-v4l2_buf.flags = ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
 + dst_vb-v4l2_buf.flags |=
 + src_vb-v4l2_buf.flags  V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
   dst_vb-v4l2_buf.timecode = src_vb-v4l2_buf.timecode;
 
   v4l2_m2m_buf_done(src_vb, VB2_BUF_STATE_DONE); diff --git
 a/drivers/media/platform/mem2mem_testdev.c
 b/drivers/media/platform/mem2mem_testdev.c
 index 08e2437..b91da7f 100644
 --- a/drivers/media/platform/mem2mem_testdev.c
 +++ b/drivers/media/platform/mem2mem_testdev.c
 @@ -239,6 +239,9 @@ static int device_process(struct m2mtest_ctx *ctx,
   memcpy(out_vb-v4l2_buf.timestamp,
   in_vb-v4l2_buf.timestamp,
   sizeof(struct timeval));
 + out_vb-v4l2_buf.flags = ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
 + out_vb-v4l2_buf.flags |=
 + in_vb-v4l2_buf.flags  V4L2_BUF_FLAG_TSTAMP_SRC_MASK;
 
   switch (ctx-mode) {
   case MEM2MEM_HFLIP | MEM2MEM_VFLIP:
 diff --git a/drivers/media/platform/mx2_emmaprp.c
 b/drivers/media/platform/mx2_emmaprp.c
 index 91056ac0..0f59082 100644
 --- a/drivers/media/platform/mx2_emmaprp.c
 +++ b/drivers/media/platform/mx2_emmaprp.c
 @@ -378,6 +378,11 @@ static irqreturn_t emmaprp_irq(int irq_emma, void
 *data)
   dst_vb = v4l2_m2m_dst_buf_remove(curr_ctx-m2m_ctx);
 
   dst_vb-v4l2_buf.timestamp = src_vb-
 v4l2_buf.timestamp;
 + 

RE: [PATCH v5 3/7] v4l: Add timestamp source flags, mask and document them

2014-02-25 Thread Kamil Debski
Hi Sakari,

 From: Sakari Ailus [mailto:sakari.ai...@iki.fi]
 Sent: Saturday, February 15, 2014 9:53 PM
 
 Some devices do not produce timestamps that correspond to the end of
 the frame. The user space should be informed on the matter. This patch
 achieves that by adding buffer flags (and a mask) for timestamp sources
 since more possible timestamping points are expected than just two.
 
 A three-bit mask is defined (V4L2_BUF_FLAG_TSTAMP_SRC_MASK) and two of
 the eight possible values is are defined V4L2_BUF_FLAG_TSTAMP_SRC_EOF
 for end of frame (value zero) V4L2_BUF_FLAG_TSTAMP_SRC_SOE for start of
 exposure (next value).
 

Changes in videobuf2-core.c look good.

 Signed-off-by: Sakari Ailus sakari.ai...@iki.fi

Acked-by: Kamil Debski k.deb...@samsung.com

 ---
  Documentation/DocBook/media/v4l/io.xml   |   31
 --
  drivers/media/v4l2-core/videobuf2-core.c |4 +++-
  include/media/videobuf2-core.h   |2 ++
  include/uapi/linux/videodev2.h   |4 
  4 files changed, 34 insertions(+), 7 deletions(-)
 
 diff --git a/Documentation/DocBook/media/v4l/io.xml
 b/Documentation/DocBook/media/v4l/io.xml
 index 46d24b3..fbd0c6e 100644
 --- a/Documentation/DocBook/media/v4l/io.xml
 +++ b/Documentation/DocBook/media/v4l/io.xml
 @@ -653,12 +653,6 @@ plane, are stored in struct
 structnamev4l2_plane/structname instead.
  In that case, struct structnamev4l2_buffer/structname contains an
 array of  plane structures./para
 
 -  paraFor timestamp types that are sampled from the system clock
 -(V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC) it is guaranteed that the
 timestamp is -taken after the complete frame has been received (or
 transmitted in -case of video output devices). For other kinds of -
 timestamps this may vary depending on the driver./para
 -
  table frame=none pgwide=1 id=v4l2-buffer
titlestruct structnamev4l2_buffer/structname/title
tgroup cols=4
 @@ -1119,6 +1113,31 @@ in which case caches have not been used./entry
   entryThe CAPTURE buffer timestamp has been taken from the
   corresponding OUTPUT buffer. This flag applies only to
 mem2mem devices./entry
 /row
 +   row
 +
 entryconstantV4L2_BUF_FLAG_TSTAMP_SRC_MASK/constant/entry
 + entry0x0007/entry
 + entryMask for timestamp sources below. The timestamp source
 + defines the point of time the timestamp is taken in relation
 to
 + the frame. Logical and operation between the
 + structfieldflags/structfield field and
 + constantV4L2_BUF_FLAG_TSTAMP_SRC_MASK/constant produces
 the
 + value of the timestamp source./entry
 +   /row
 +   row
 +
 entryconstantV4L2_BUF_FLAG_TSTAMP_SRC_EOF/constant/entry
 + entry0x/entry
 + entryEnd of frame. The buffer timestamp has been taken
 + when the last pixel of the frame has been received or the
 + last pixel of the frame has been transmitted./entry
 +   /row
 +   row
 +
 entryconstantV4L2_BUF_FLAG_TSTAMP_SRC_SOE/constant/entry
 + entry0x0001/entry
 + entryStart of exposure. The buffer timestamp has been
 taken
 + when the exposure of the frame has begun. This is only
 + valid for buffer type
 + constantV4L2_BUF_TYPE_VIDEO_CAPTURE/constant./entry
 +   /row
   /tbody
/tgroup
  /table
 diff --git a/drivers/media/v4l2-core/videobuf2-core.c
 b/drivers/media/v4l2-core/videobuf2-core.c
 index 5a5fb7f..6e314b0 100644
 --- a/drivers/media/v4l2-core/videobuf2-core.c
 +++ b/drivers/media/v4l2-core/videobuf2-core.c
 @@ -2195,7 +2195,9 @@ int vb2_queue_init(struct vb2_queue *q)
   WARN_ON(!q-io_modes) ||
   WARN_ON(!q-ops-queue_setup) ||
   WARN_ON(!q-ops-buf_queue)   ||
 - WARN_ON(q-timestamp_type  ~V4L2_BUF_FLAG_TIMESTAMP_MASK))
 + WARN_ON(q-timestamp_type 
 + ~(V4L2_BUF_FLAG_TIMESTAMP_MASK |
 +   V4L2_BUF_FLAG_TSTAMP_SRC_MASK)))
   return -EINVAL;

Looks good.

 
   /* Warn that the driver should choose an appropriate timestamp
 type */ diff --git a/include/media/videobuf2-core.h
 b/include/media/videobuf2-core.h index bef53ce..b6b992d 100644
 --- a/include/media/videobuf2-core.h
 +++ b/include/media/videobuf2-core.h
 @@ -312,6 +312,8 @@ struct v4l2_fh;
   * @buf_struct_size: size of the driver-specific buffer structure;
   *   0 indicates the driver doesn't want to use a custom
 buffer
   *   structure type, so sizeof(struct vb2_buffer) will is used
 + * @timestamp_type: Timestamp flags; V4L2_BUF_FLAGS_TIMESTAMP_* and
 + *   V4L2_BUF_FLAGS_TSTAMP_SRC_*
   * @gfp_flags:   additional gfp flags used when allocating the
 buffers.
   *   Typically this is 0, but it may be e.g. GFP_DMA or
 __GFP_DMA32
   *   to force the buffer allocation to a specific memory zone.
 diff --git a/include/uapi/linux/videodev2.h
 

Re: [PATCH v5 04/10] V4L: Add driver for s5k6a3 image sensor

2014-02-25 Thread Sylwester Nawrocki
On 25/02/14 10:55, Baruch Siach wrote:
 Thanks for the explanation. However, I've found no reference to the 
 s5k6a3_sd_internal_ops struct in the driver code. There surly has to be at 
 least one reference for the upper layer to access these ops.

There is indeed an assignment missing to sd-internal_ops in probe().
Thanks for spotting this, I've corrected that for next iteration.

--
Regards,
Sylwester
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] media: soc_camera: rcar_vin: Add support for 10-bit YUV cameras

2014-02-25 Thread Valentine

On 02/24/2014 10:38 PM, Laurent Pinchart wrote:

Hi Phil,

Thank you for the patch.

On Monday 24 February 2014 15:49:05 Phil Edworthy wrote:

Signed-off-by: Phil Edworthy phil.edwor...@renesas.com
---
  drivers/media/platform/soc_camera/rcar_vin.c |7 +++
  1 file changed, 7 insertions(+)

diff --git a/drivers/media/platform/soc_camera/rcar_vin.c
b/drivers/media/platform/soc_camera/rcar_vin.c index 3b1c05a..9929375
100644
--- a/drivers/media/platform/soc_camera/rcar_vin.c
+++ b/drivers/media/platform/soc_camera/rcar_vin.c
@@ -68,6 +68,8 @@
  #define VNMC_YCAL (1  19)
  #define VNMC_INF_YUV8_BT656   (0  16)
  #define VNMC_INF_YUV8_BT601   (1  16)
+#define VNMC_INF_YUV10_BT656   (2  16)
+#define VNMC_INF_YUV10_BT601   (3  16)
  #define VNMC_INF_YUV16(5  16)
  #define VNMC_VUP  (1  10)
  #define VNMC_IM_ODD   (0  3)
@@ -275,6 +277,10 @@ static int rcar_vin_setup(struct rcar_vin_priv *priv)
/* BT.656 8bit YCbCr422 or BT.601 8bit YCbCr422 */
vnmc |= priv-pdata-flags  RCAR_VIN_BT656 ?
VNMC_INF_YUV8_BT656 : VNMC_INF_YUV8_BT601;


Aren't you missing a break here ?


+   case V4L2_MBUS_FMT_YUYV10_2X10:
+   /* BT.656 10bit YCbCr422 or BT.601 10bit YCbCr422 */
+   vnmc |= priv-pdata-flags  RCAR_VIN_BT656 ?
+   VNMC_INF_YUV10_BT656 : VNMC_INF_YUV10_BT601;


You should add one here as well. Although not strictly necessary, it would
help to avoid making the same mistake again.

The rest looks good to me, but I'm not familiar with the hardware, so I'll let
Valentine have the last word.


Thanks, looks good to me.




default:
break;
}
@@ -1003,6 +1009,7 @@ static int rcar_vin_get_formats(struct
soc_camera_device *icd, unsigned int idx, switch (code) {
case V4L2_MBUS_FMT_YUYV8_1X16:
case V4L2_MBUS_FMT_YUYV8_2X8:
+   case V4L2_MBUS_FMT_YUYV10_2X10:
if (cam-extra_fmt)
break;




--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2] media: soc_camera: rcar_vin: Add support for 10-bit YUV cameras

2014-02-25 Thread Vladimir Barinov

On 02/25/2014 01:10 PM, Phil Edworthy wrote:

Signed-off-by: Phil Edworthyphil.edwor...@renesas.com

Acked-by: Vladimir Barinovvladimir.bari...@cogentembedded.com

(Valentine can't do the review atm)


---
v2:
   - Fix silly mistake with missing break.

  drivers/media/platform/soc_camera/rcar_vin.c |9 +
  1 file changed, 9 insertions(+)

diff --git a/drivers/media/platform/soc_camera/rcar_vin.c 
b/drivers/media/platform/soc_camera/rcar_vin.c
index 3b1c05a..702dc47 100644
--- a/drivers/media/platform/soc_camera/rcar_vin.c
+++ b/drivers/media/platform/soc_camera/rcar_vin.c
@@ -68,6 +68,8 @@
  #define VNMC_YCAL (1  19)
  #define VNMC_INF_YUV8_BT656   (0  16)
  #define VNMC_INF_YUV8_BT601   (1  16)
+#define VNMC_INF_YUV10_BT656   (2  16)
+#define VNMC_INF_YUV10_BT601   (3  16)
  #define VNMC_INF_YUV16(5  16)
  #define VNMC_VUP  (1  10)
  #define VNMC_IM_ODD   (0  3)
@@ -275,6 +277,12 @@ static int rcar_vin_setup(struct rcar_vin_priv *priv)
/* BT.656 8bit YCbCr422 or BT.601 8bit YCbCr422 */
vnmc |= priv-pdata-flags  RCAR_VIN_BT656 ?
VNMC_INF_YUV8_BT656 : VNMC_INF_YUV8_BT601;
+   break;
+   case V4L2_MBUS_FMT_YUYV10_2X10:
+   /* BT.656 10bit YCbCr422 or BT.601 10bit YCbCr422 */
+   vnmc |= priv-pdata-flags  RCAR_VIN_BT656 ?
+   VNMC_INF_YUV10_BT656 : VNMC_INF_YUV10_BT601;
+   break;
default:
break;
}
@@ -1003,6 +1011,7 @@ static int rcar_vin_get_formats(struct soc_camera_device 
*icd, unsigned int idx,
switch (code) {
case V4L2_MBUS_FMT_YUYV8_1X16:
case V4L2_MBUS_FMT_YUYV8_2X8:
+   case V4L2_MBUS_FMT_YUYV10_2X10:
if (cam-extra_fmt)
break;


Regards,
Vladimir


--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 1/3] [media] of: move graph helpers from drivers/media/v4l2-core to drivers/of

2014-02-25 Thread Philipp Zabel
From: Philipp Zabel philipp.za...@gmail.com

This patch moves the parsing helpers used to parse connected graphs
in the device tree, like the video interface bindings documented in
Documentation/devicetree/bindings/media/video-interfaces.txt, from
drivers/media/v4l2-core to drivers/of.

This allows to reuse the same parser code from outside the V4L2
framework, most importantly from display drivers.
The functions v4l2_of_get_next_endpoint, v4l2_of_get_remote_port,
and v4l2_of_get_remote_port_parent are moved. They are renamed to
of_graph_get_next_endpoint, of_graph_get_remote_port, and
of_graph_get_remote_port_parent, respectively.
Since there are not that many current users yet, switch all of
them to the new functions right away.

Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
Changes since v3:
 - Moved back to drivers/of
---
 drivers/media/i2c/adv7343.c   |   4 +-
 drivers/media/i2c/mt9p031.c   |   4 +-
 drivers/media/i2c/s5k5baf.c   |   3 +-
 drivers/media/i2c/tvp514x.c   |   3 +-
 drivers/media/i2c/tvp7002.c   |   3 +-
 drivers/media/platform/exynos4-is/fimc-is.c   |   6 +-
 drivers/media/platform/exynos4-is/media-dev.c |   3 +-
 drivers/media/platform/exynos4-is/mipi-csis.c |   3 +-
 drivers/media/v4l2-core/v4l2-of.c | 117 --
 drivers/of/Makefile   |   1 +
 drivers/of/of_graph.c | 134 ++
 include/linux/of_graph.h  |  46 +
 include/media/v4l2-of.h   |  25 +
 13 files changed, 199 insertions(+), 153 deletions(-)
 create mode 100644 drivers/of/of_graph.c
 create mode 100644 include/linux/of_graph.h

diff --git a/drivers/media/i2c/adv7343.c b/drivers/media/i2c/adv7343.c
index d4e15a6..9d38f7b 100644
--- a/drivers/media/i2c/adv7343.c
+++ b/drivers/media/i2c/adv7343.c
@@ -26,12 +26,12 @@
 #include linux/videodev2.h
 #include linux/uaccess.h
 #include linux/of.h
+#include linux/of_graph.h
 
 #include media/adv7343.h
 #include media/v4l2-async.h
 #include media/v4l2-device.h
 #include media/v4l2-ctrls.h
-#include media/v4l2-of.h
 
 #include adv7343_regs.h
 
@@ -410,7 +410,7 @@ adv7343_get_pdata(struct i2c_client *client)
if (!IS_ENABLED(CONFIG_OF) || !client-dev.of_node)
return client-dev.platform_data;
 
-   np = v4l2_of_get_next_endpoint(client-dev.of_node, NULL);
+   np = of_graph_get_next_endpoint(client-dev.of_node, NULL);
if (!np)
return NULL;
 
diff --git a/drivers/media/i2c/mt9p031.c b/drivers/media/i2c/mt9p031.c
index e5ddf47..192c4aa 100644
--- a/drivers/media/i2c/mt9p031.c
+++ b/drivers/media/i2c/mt9p031.c
@@ -21,6 +21,7 @@
 #include linux/module.h
 #include linux/of.h
 #include linux/of_gpio.h
+#include linux/of_graph.h
 #include linux/pm.h
 #include linux/regulator/consumer.h
 #include linux/slab.h
@@ -29,7 +30,6 @@
 #include media/mt9p031.h
 #include media/v4l2-ctrls.h
 #include media/v4l2-device.h
-#include media/v4l2-of.h
 #include media/v4l2-subdev.h
 
 #include aptina-pll.h
@@ -943,7 +943,7 @@ mt9p031_get_pdata(struct i2c_client *client)
if (!IS_ENABLED(CONFIG_OF) || !client-dev.of_node)
return client-dev.platform_data;
 
-   np = v4l2_of_get_next_endpoint(client-dev.of_node, NULL);
+   np = of_graph_get_next_endpoint(client-dev.of_node, NULL);
if (!np)
return NULL;
 
diff --git a/drivers/media/i2c/s5k5baf.c b/drivers/media/i2c/s5k5baf.c
index 77e10e0..2d768ef 100644
--- a/drivers/media/i2c/s5k5baf.c
+++ b/drivers/media/i2c/s5k5baf.c
@@ -21,6 +21,7 @@
 #include linux/media.h
 #include linux/module.h
 #include linux/of_gpio.h
+#include linux/of_graph.h
 #include linux/regulator/consumer.h
 #include linux/slab.h
 
@@ -1855,7 +1856,7 @@ static int s5k5baf_parse_device_node(struct s5k5baf 
*state, struct device *dev)
if (ret  0)
return ret;
 
-   node_ep = v4l2_of_get_next_endpoint(node, NULL);
+   node_ep = of_graph_get_next_endpoint(node, NULL);
if (!node_ep) {
dev_err(dev, no endpoint defined at node %s\n,
node-full_name);
diff --git a/drivers/media/i2c/tvp514x.c b/drivers/media/i2c/tvp514x.c
index 83d85df..ca00117 100644
--- a/drivers/media/i2c/tvp514x.c
+++ b/drivers/media/i2c/tvp514x.c
@@ -36,6 +36,7 @@
 #include linux/module.h
 #include linux/v4l2-mediabus.h
 #include linux/of.h
+#include linux/of_graph.h
 
 #include media/v4l2-async.h
 #include media/v4l2-device.h
@@ -1068,7 +1069,7 @@ tvp514x_get_pdata(struct i2c_client *client)
if (!IS_ENABLED(CONFIG_OF) || !client-dev.of_node)
return client-dev.platform_data;
 
-   endpoint = v4l2_of_get_next_endpoint(client-dev.of_node, NULL);
+   endpoint = of_graph_get_next_endpoint(client-dev.of_node, NULL);
if (!endpoint)
return NULL;
 
diff --git 

[PATCH v4 2/3] [media] of: move common endpoint parsing to drivers/of

2014-02-25 Thread Philipp Zabel
This patch adds a new struct of_endpoint which is then embedded in struct
v4l2_of_endpoint and contains the endpoint properties that are not V4L2
specific, or in fact not even media specific: port number, endpoint id,
local device tree node and remote endpoint phandle.
of_graph_parse_endpoint parses those properties and is used by
v4l2_of_parse_endpoint, which just adds the V4L2 MBUS information
to the containing v4l2_of_endpoint structure.

Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
 drivers/media/v4l2-core/v4l2-of.c | 16 +++-
 drivers/of/of_graph.c | 32 
 include/linux/of_graph.h  | 20 
 include/media/v4l2-of.h   |  9 +++--
 4 files changed, 58 insertions(+), 19 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-of.c 
b/drivers/media/v4l2-core/v4l2-of.c
index f919db3..222ed58 100644
--- a/drivers/media/v4l2-core/v4l2-of.c
+++ b/drivers/media/v4l2-core/v4l2-of.c
@@ -127,17 +127,9 @@ static void v4l2_of_parse_parallel_bus(const struct 
device_node *node,
 int v4l2_of_parse_endpoint(const struct device_node *node,
   struct v4l2_of_endpoint *endpoint)
 {
-   struct device_node *port_node = of_get_parent(node);
-
-   memset(endpoint, 0, offsetof(struct v4l2_of_endpoint, head));
-
-   endpoint-local_node = node;
-   /*
-* It doesn't matter whether the two calls below succeed.
-* If they don't then the default value 0 is used.
-*/
-   of_property_read_u32(port_node, reg, endpoint-port);
-   of_property_read_u32(node, reg, endpoint-id);
+   of_graph_parse_endpoint(node, endpoint-ep);
+   endpoint-bus_type = 0;
+   memset(endpoint-bus, 0, sizeof(endpoint-bus));
 
v4l2_of_parse_csi_bus(node, endpoint);
/*
@@ -147,8 +139,6 @@ int v4l2_of_parse_endpoint(const struct device_node *node,
if (endpoint-bus.mipi_csi2.flags == 0)
v4l2_of_parse_parallel_bus(node, endpoint);
 
-   of_node_put(port_node);
-
return 0;
 }
 EXPORT_SYMBOL(v4l2_of_parse_endpoint);
diff --git a/drivers/of/of_graph.c b/drivers/of/of_graph.c
index 267d8f7..d0f1683 100644
--- a/drivers/of/of_graph.c
+++ b/drivers/of/of_graph.c
@@ -15,6 +15,38 @@
 #include linux/of.h
 #include linux/of_graph.h
 #include linux/types.h
+#include media/of_graph.h
+
+/**
+ * of_graph_parse_endpoint() - parse common endpoint node properties
+ * @node: pointer to endpoint device_node
+ * @endpoint: pointer to the OF endpoint data structure
+ *
+ * All properties are optional. If none are found, we don't set any flags.
+ * This means the port has a static configuration and no properties have
+ * to be specified explicitly.
+ * The caller should hold a reference to @node.
+ */
+int of_graph_parse_endpoint(const struct device_node *node,
+   struct of_endpoint *endpoint)
+{
+   struct device_node *port_node = of_get_parent(node);
+
+   memset(endpoint, 0, sizeof(*endpoint));
+
+   endpoint-local_node = node;
+   /*
+* It doesn't matter whether the two calls below succeed.
+* If they don't then the default value 0 is used.
+*/
+   of_property_read_u32(port_node, reg, endpoint-port);
+   of_property_read_u32(node, reg, endpoint-id);
+
+   of_node_put(port_node);
+
+   return 0;
+}
+EXPORT_SYMBOL(of_graph_parse_endpoint);
 
 /**
  * of_graph_get_next_endpoint() - get next endpoint node
diff --git a/include/linux/of_graph.h b/include/linux/of_graph.h
index 3bbeb60..2b233db 100644
--- a/include/linux/of_graph.h
+++ b/include/linux/of_graph.h
@@ -14,7 +14,21 @@
 #ifndef __LINUX_OF_GRAPH_H
 #define __LINUX_OF_GRAPH_H
 
+/**
+ * struct of_endpoint - the OF graph endpoint data structure
+ * @port: identifier (value of reg property) of a port this endpoint belongs to
+ * @id: identifier (value of reg property) of this endpoint
+ * @local_node: pointer to device_node of this endpoint
+ */
+struct of_endpoint {
+   unsigned int port;
+   unsigned int id;
+   const struct device_node *local_node;
+};
+
 #ifdef CONFIG_OF
+int of_graph_parse_endpoint(const struct device_node *node,
+   struct of_endpoint *endpoint);
 struct device_node *of_graph_get_next_endpoint(const struct device_node 
*parent,
struct device_node *previous);
 struct device_node *of_graph_get_remote_port_parent(
@@ -22,6 +36,12 @@ struct device_node *of_graph_get_remote_port_parent(
 struct device_node *of_graph_get_remote_port(const struct device_node *node);
 #else
 
+static inline int of_graph_parse_endpoint(const struct device_node *node,
+   struct of_endpoint *endpoint);
+{
+   return -ENOSYS;
+}
+
 static inline struct device_node *of_graph_get_next_endpoint(
const struct device_node *parent,

[PATCH v4 0/3] Move device tree graph parsing helpers to drivers/of

2014-02-25 Thread Philipp Zabel
Hi,

this version moves the graph helpers to drivers/of again instead of
drivers/media. Since the location changed again, I have dropped the
Acks. A second patch is added that splits out the common parts from
v4l2_of_parse_endpoint into of_graph_parse_endpoint and I have added
a binding description Documentation/devicetree/bindings/graph.txt.

Changes since v3:
 - Moved back to drivers/of
 - Added DT binding documentation

regards
Philipp

Philipp Zabel (3):
  [media] of: move graph helpers from drivers/media/v4l2-core to
drivers/of
  [media] of: move common endpoint parsing to drivers/of
  Documentation: of: Document graph bindings

 Documentation/devicetree/bindings/graph.txt   |  98 +++
 drivers/media/i2c/adv7343.c   |   4 +-
 drivers/media/i2c/mt9p031.c   |   4 +-
 drivers/media/i2c/s5k5baf.c   |   3 +-
 drivers/media/i2c/tvp514x.c   |   3 +-
 drivers/media/i2c/tvp7002.c   |   3 +-
 drivers/media/platform/exynos4-is/fimc-is.c   |   6 +-
 drivers/media/platform/exynos4-is/media-dev.c |   3 +-
 drivers/media/platform/exynos4-is/mipi-csis.c |   3 +-
 drivers/media/v4l2-core/v4l2-of.c | 133 +
 drivers/of/Makefile   |   1 +
 drivers/of/of_graph.c | 166 ++
 include/linux/of_graph.h  |  66 ++
 include/media/v4l2-of.h   |  34 +-
 14 files changed, 355 insertions(+), 172 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/graph.txt
 create mode 100644 drivers/of/of_graph.c
 create mode 100644 include/linux/of_graph.h

-- 
1.8.5.3

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 3/3] Documentation: of: Document graph bindings

2014-02-25 Thread Philipp Zabel
The device tree graph bindings as used by V4L2 and documented in
Documentation/device-tree/bindings/media/video-interfaces.txt contain
generic parts that are not media specific but could be useful for any
subsystem with data flow between multiple devices. This document
describe the generic bindings.

Signed-off-by: Philipp Zabel p.za...@pengutronix.de
---
 Documentation/devicetree/bindings/graph.txt | 98 +
 1 file changed, 98 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/graph.txt

diff --git a/Documentation/devicetree/bindings/graph.txt 
b/Documentation/devicetree/bindings/graph.txt
new file mode 100644
index 000..97c877e
--- /dev/null
+++ b/Documentation/devicetree/bindings/graph.txt
@@ -0,0 +1,98 @@
+Common bindings for device graphs
+
+General concept
+---
+
+The hierarchical organisation of the device tree is well suited to describe
+control flow to devices, but data flow between devices that work together to
+form a logical compound device can follow arbitrarily complex graphs.
+The device tree graph bindings allow to describe data bus connections between
+individual devices, that can not be inferred from device tree parent-child
+relationships. The common bindings do not contain any information about the
+direction or type of data flow, they just map connections. Specific properties
+of the connections are described by specialized bindings depending on the type
+of connection. To see how this binding applies to video pipelines, see for
+example Documentation/device-tree/bindings/media/video-interfaces.txt.
+
+Devices can have multiple data interfaces, each of which can be connected to
+the data interfaces of one or more remote devices via a data bus.
+Data interfaces are described by the device nodes' child 'port' nodes. A port
+node contains an 'endpoint' subnode for each remote device port connected to
+this port via a bus. If a port is connected to more than one remote device on
+the same bus, an 'endpoint' child node must be provided for each of them. If
+more than one port is present in a device node or there is more than one
+endpoint at a port, or port node needs to be associated with a selected
+hardware interface, a common scheme using '#address-cells', '#size-cells'
+and 'reg' properties is used.
+
+device {
+...
+#address-cells = 1;
+#size-cells = 0;
+
+port@0 {
+...
+endpoint@0 { ... };
+endpoint@1 { ... };
+};
+
+port@1 { ... };
+};
+
+All 'port' nodes can be grouped under optional 'ports' node, which allows to
+specify #address-cells, #size-cells properties independently for the 'port'
+and 'endpoint' nodes and any child device nodes a device might have.
+
+device {
+...
+ports {
+#address-cells = 1;
+#size-cells = 0;
+
+port@0 {
+...
+endpoint@0 { ... };
+endpoint@1 { ... };
+};
+
+port@1 { ... };
+};
+};
+
+Each endpoint can contain a 'remote-endpoint' phandle property that points to
+the corresponding endpoint in the port of the remote device. Two 'endpoint'
+nodes are linked with each other through their 'remote-endpoint' phandles.
+
+device_1 {
+port {
+device_1_output: endpoint {
+remote-endpoint = device_2_input;
+};
+};
+};
+
+device_1 {
+port {
+device_2_input: endpoint {
+remote-endpoint = device_1_output;
+};
+};
+};
+
+
+Required properties
+---
+
+If there is more than one 'port' or more than one 'endpoint' node or 'reg'
+property is present in port and/or endpoint nodes the following properties
+are required in a relevant parent node:
+
+ - #address-cells : number of cells required to define port/endpoint
+identifier, should be 1.
+ - #size-cells: should be zero.
+
+Optional endpoint properties
+
+
+- remote-endpoint: phandle to an 'endpoint' subnode of a remote device node.
+
-- 
1.8.5.3

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Kedves e-mail felhasználók;

2014-02-25 Thread 臺科大光機電中心
Kedves e-mail felhasználók;
 
Túllépte 23.432 doboz állította be
Web Service / Admin, és akkor lesz probléma a küldő és
fogadhat e-maileket, amíg meg újra ellenőrizni. Kérjük, frissítse kattintva
linkre és töltse ki a részleteket, hogy ellenőrizze a számla
Kérjük, kövesse az alábbi linket vagy másolja illessze be a böngésző
ellenőrizze a vágólapra.
 
http://webmailupdategsheyhu4.jimdo.com/
Figyelem!
Ha nem így lesz csak korlátozottan férnek hozzá az e-mail postafiókját. ha
nem frissíteni? véve három napon belül frissül
értesítés fiókját véglegesen be kell zárni.
Tisztelettel,
Rendszergazda 
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 7/7] v4l: Document timestamp buffer flag behaviour

2014-02-25 Thread Sakari Ailus
Hi Hans,

On Sun, Feb 23, 2014 at 12:45:28PM +0100, Hans Verkuil wrote:
 On 02/15/2014 09:53 PM, Sakari Ailus wrote:
  Timestamp buffer flags are constant at the moment. Document them so that 1)
  they're always valid and 2) not changed by the drivers. This leaves room to
  extend the functionality later on if needed.
  
  Signed-off-by: Sakari Ailus sakari.ai...@iki.fi
  ---
   Documentation/DocBook/media/v4l/io.xml |   10 ++
   1 file changed, 10 insertions(+)
  
  diff --git a/Documentation/DocBook/media/v4l/io.xml 
  b/Documentation/DocBook/media/v4l/io.xml
  index fbd0c6e..4f76565 100644
  --- a/Documentation/DocBook/media/v4l/io.xml
  +++ b/Documentation/DocBook/media/v4l/io.xml
  @@ -653,6 +653,16 @@ plane, are stored in struct 
  structnamev4l2_plane/structname instead.
   In that case, struct structnamev4l2_buffer/structname contains an 
  array of
   plane structures./para
   
  +paraDequeued video buffers come with timestamps. These
  +timestamps can be taken from different clocks and at different
  +part of the frame, depending on the driver. Please see flags in
  +the masks constantV4L2_BUF_FLAG_TIMESTAMP_MASK/constant and
  +constantV4L2_BUF_FLAG_TSTAMP_SRC_MASK/constant in xref
  +linkend=buffer-flags. These flags are guaranteed to be always
  +valid and will not be changed by the driver autonomously. Changes
  +in these flags may take place due as a side effect of
  +VIDIOC-S-INPUT; or VIDIOC-S-OUTPUT; however./para
 
 There is one exception to this: if the timestamps are copied from the output
 buffer to the capture buffer (TIMESTAMP_COPY), then it can change 
 theoretically
 for every buffer since it entirely depends on what is being sent to it. The
 value comes from userspace and you simply don't have any control over that.

Yes; I agree.

And a good point as well --- the timestamp source flags currently come from
__fill_v4l2_buffer() which takes them from q-timestamp. This isn't right
for m2m devices.

I'll fix and resend (3rd patch most likely).

 I'm stress testing vb2 in lots of different ways, including timestamp 
 handling.
 It's not a pretty sight, I'm afraid. Expect a looong list of patches in the
 coming week.

:-)

-- 
Kind regards,

Sakari Ailus
e-mail: sakari.ai...@iki.fi XMPP: sai...@retiisi.org.uk
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 7/7] v4l: Document timestamp buffer flag behaviour

2014-02-25 Thread Hans Verkuil
On 02/25/2014 06:08 PM, Sakari Ailus wrote:
 Hi Hans,
 
 On Sun, Feb 23, 2014 at 12:45:28PM +0100, Hans Verkuil wrote:
 On 02/15/2014 09:53 PM, Sakari Ailus wrote:
 Timestamp buffer flags are constant at the moment. Document them so that 1)
 they're always valid and 2) not changed by the drivers. This leaves room to
 extend the functionality later on if needed.

 Signed-off-by: Sakari Ailus sakari.ai...@iki.fi
 ---
  Documentation/DocBook/media/v4l/io.xml |   10 ++
  1 file changed, 10 insertions(+)

 diff --git a/Documentation/DocBook/media/v4l/io.xml 
 b/Documentation/DocBook/media/v4l/io.xml
 index fbd0c6e..4f76565 100644
 --- a/Documentation/DocBook/media/v4l/io.xml
 +++ b/Documentation/DocBook/media/v4l/io.xml
 @@ -653,6 +653,16 @@ plane, are stored in struct 
 structnamev4l2_plane/structname instead.
  In that case, struct structnamev4l2_buffer/structname contains an 
 array of
  plane structures./para
  
 +paraDequeued video buffers come with timestamps. These
 +timestamps can be taken from different clocks and at different
 +part of the frame, depending on the driver. Please see flags in
 +the masks constantV4L2_BUF_FLAG_TIMESTAMP_MASK/constant and
 +constantV4L2_BUF_FLAG_TSTAMP_SRC_MASK/constant in xref
 +linkend=buffer-flags. These flags are guaranteed to be always
 +valid and will not be changed by the driver autonomously. Changes
 +in these flags may take place due as a side effect of
 +VIDIOC-S-INPUT; or VIDIOC-S-OUTPUT; however./para

 There is one exception to this: if the timestamps are copied from the output
 buffer to the capture buffer (TIMESTAMP_COPY), then it can change 
 theoretically
 for every buffer since it entirely depends on what is being sent to it. The
 value comes from userspace and you simply don't have any control over that.
 
 Yes; I agree.
 
 And a good point as well --- the timestamp source flags currently come from
 __fill_v4l2_buffer() which takes them from q-timestamp. This isn't right
 for m2m devices.
 
 I'll fix and resend (3rd patch most likely).

You'll want to reference this patch I posted today:

[RFCv1 PATCH 16/20] vb2: fix timecode and flags handling for output buffers

Also available in this git repo:

http://git.linuxtv.org/hverkuil/media_tree.git/shortlog/refs/heads/vb2-part4

The current implementation in vb2 is actually broken (which is one of the
things fixed by this patch): if you prepare a buffer (VIDIOC_PREPARE_BUF)
and only then call VIDIOC_QBUF with a timestamp, that timestamp will be
lost since it will use the one set by PREPARE_BUF (either that or it is
zeroed, I've forgotten which of the two it was).

If you want to take that patch and add your own changes to it, then that's
fine by me. It should be pretty much standalone.

Regards,

Hans
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Upstreaming SAA716x driver to the media_tree

2014-02-25 Thread Luis Alves
Hi Manu,

How's the progress going?
Looking forward to finally see this driver in the tree :D

Regards,
Luis

On Tue, Feb 11, 2014 at 7:47 PM, Manu Abraham abraham.m...@gmail.com wrote:
 On Tue, Feb 11, 2014 at 7:14 PM, Luis Alves lja...@gmail.com wrote:
 Hi,

 Any update on this?

 I need to address the issues Mauro pointed out, prior to the merge.
 Will address the issues during the next week. Have been a bit busy
 restoring the system at my end after a crash.

 Regards,

 Manu
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 7/7] v4l: Document timestamp buffer flag behaviour

2014-02-25 Thread Sakari Ailus
Hi Hans,

On Tue, Feb 25, 2014 at 06:28:06PM +0100, Hans Verkuil wrote:
 On 02/25/2014 06:08 PM, Sakari Ailus wrote:
  Hi Hans,
  
  On Sun, Feb 23, 2014 at 12:45:28PM +0100, Hans Verkuil wrote:
  On 02/15/2014 09:53 PM, Sakari Ailus wrote:
  Timestamp buffer flags are constant at the moment. Document them so that 
  1)
  they're always valid and 2) not changed by the drivers. This leaves room 
  to
  extend the functionality later on if needed.
 
  Signed-off-by: Sakari Ailus sakari.ai...@iki.fi
  ---
   Documentation/DocBook/media/v4l/io.xml |   10 ++
   1 file changed, 10 insertions(+)
 
  diff --git a/Documentation/DocBook/media/v4l/io.xml 
  b/Documentation/DocBook/media/v4l/io.xml
  index fbd0c6e..4f76565 100644
  --- a/Documentation/DocBook/media/v4l/io.xml
  +++ b/Documentation/DocBook/media/v4l/io.xml
  @@ -653,6 +653,16 @@ plane, are stored in struct 
  structnamev4l2_plane/structname instead.
   In that case, struct structnamev4l2_buffer/structname contains an 
  array of
   plane structures./para
   
  +paraDequeued video buffers come with timestamps. These
  +timestamps can be taken from different clocks and at different
  +part of the frame, depending on the driver. Please see flags in
  +the masks constantV4L2_BUF_FLAG_TIMESTAMP_MASK/constant and
  +constantV4L2_BUF_FLAG_TSTAMP_SRC_MASK/constant in xref
  +linkend=buffer-flags. These flags are guaranteed to be always
  +valid and will not be changed by the driver autonomously. Changes
  +in these flags may take place due as a side effect of
  +VIDIOC-S-INPUT; or VIDIOC-S-OUTPUT; however./para
 
  There is one exception to this: if the timestamps are copied from the 
  output
  buffer to the capture buffer (TIMESTAMP_COPY), then it can change 
  theoretically
  for every buffer since it entirely depends on what is being sent to it. The
  value comes from userspace and you simply don't have any control over that.
  
  Yes; I agree.
  
  And a good point as well --- the timestamp source flags currently come from
  __fill_v4l2_buffer() which takes them from q-timestamp. This isn't right
  for m2m devices.
  
  I'll fix and resend (3rd patch most likely).
 
 You'll want to reference this patch I posted today:
 
 [RFCv1 PATCH 16/20] vb2: fix timecode and flags handling for output buffers
 
 Also available in this git repo:
 
 http://git.linuxtv.org/hverkuil/media_tree.git/shortlog/refs/heads/vb2-part4
 
 The current implementation in vb2 is actually broken (which is one of the
 things fixed by this patch): if you prepare a buffer (VIDIOC_PREPARE_BUF)
 and only then call VIDIOC_QBUF with a timestamp, that timestamp will be
 lost since it will use the one set by PREPARE_BUF (either that or it is
 zeroed, I've forgotten which of the two it was).
 
 If you want to take that patch and add your own changes to it, then that's
 fine by me. It should be pretty much standalone.

I'll keep that as-is and write another to pass the timestamp source flags
when needed. Would it be ok if I prepend the patch to the set?

-- 
Kind regards,

Sakari Ailus
e-mail: sakari.ai...@iki.fi XMPP: sai...@retiisi.org.uk
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 7/7] v4l: Document timestamp buffer flag behaviour

2014-02-25 Thread Hans Verkuil
On 02/26/2014 01:04 AM, Sakari Ailus wrote:
 Hi Hans,
 
 On Tue, Feb 25, 2014 at 06:28:06PM +0100, Hans Verkuil wrote:
 On 02/25/2014 06:08 PM, Sakari Ailus wrote:
 Hi Hans,

 On Sun, Feb 23, 2014 at 12:45:28PM +0100, Hans Verkuil wrote:
 On 02/15/2014 09:53 PM, Sakari Ailus wrote:
 Timestamp buffer flags are constant at the moment. Document them so that 
 1)
 they're always valid and 2) not changed by the drivers. This leaves room 
 to
 extend the functionality later on if needed.

 Signed-off-by: Sakari Ailus sakari.ai...@iki.fi
 ---
  Documentation/DocBook/media/v4l/io.xml |   10 ++
  1 file changed, 10 insertions(+)

 diff --git a/Documentation/DocBook/media/v4l/io.xml 
 b/Documentation/DocBook/media/v4l/io.xml
 index fbd0c6e..4f76565 100644
 --- a/Documentation/DocBook/media/v4l/io.xml
 +++ b/Documentation/DocBook/media/v4l/io.xml
 @@ -653,6 +653,16 @@ plane, are stored in struct 
 structnamev4l2_plane/structname instead.
  In that case, struct structnamev4l2_buffer/structname contains an 
 array of
  plane structures./para
  
 +paraDequeued video buffers come with timestamps. These
 +timestamps can be taken from different clocks and at different
 +part of the frame, depending on the driver. Please see flags in
 +the masks constantV4L2_BUF_FLAG_TIMESTAMP_MASK/constant and
 +constantV4L2_BUF_FLAG_TSTAMP_SRC_MASK/constant in xref
 +linkend=buffer-flags. These flags are guaranteed to be always
 +valid and will not be changed by the driver autonomously. Changes
 +in these flags may take place due as a side effect of
 +VIDIOC-S-INPUT; or VIDIOC-S-OUTPUT; however./para

 There is one exception to this: if the timestamps are copied from the 
 output
 buffer to the capture buffer (TIMESTAMP_COPY), then it can change 
 theoretically
 for every buffer since it entirely depends on what is being sent to it. The
 value comes from userspace and you simply don't have any control over that.

 Yes; I agree.

 And a good point as well --- the timestamp source flags currently come from
 __fill_v4l2_buffer() which takes them from q-timestamp. This isn't right
 for m2m devices.

 I'll fix and resend (3rd patch most likely).

 You'll want to reference this patch I posted today:

 [RFCv1 PATCH 16/20] vb2: fix timecode and flags handling for output buffers

 Also available in this git repo:

 http://git.linuxtv.org/hverkuil/media_tree.git/shortlog/refs/heads/vb2-part4

 The current implementation in vb2 is actually broken (which is one of the
 things fixed by this patch): if you prepare a buffer (VIDIOC_PREPARE_BUF)
 and only then call VIDIOC_QBUF with a timestamp, that timestamp will be
 lost since it will use the one set by PREPARE_BUF (either that or it is
 zeroed, I've forgotten which of the two it was).

 If you want to take that patch and add your own changes to it, then that's
 fine by me. It should be pretty much standalone.
 
 I'll keep that as-is and write another to pass the timestamp source flags
 when needed. Would it be ok if I prepend the patch to the set?
 

Sure, no problem.

Hans
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 3/7] v4l: Add timestamp source flags, mask and document them

2014-02-25 Thread 'Sakari Ailus'
On Tue, Feb 25, 2014 at 02:09:41PM +0100, Kamil Debski wrote:
 Hi Sakari,
 
  From: Sakari Ailus [mailto:sakari.ai...@iki.fi]
  Sent: Saturday, February 15, 2014 9:53 PM
  
  Some devices do not produce timestamps that correspond to the end of
  the frame. The user space should be informed on the matter. This patch
  achieves that by adding buffer flags (and a mask) for timestamp sources
  since more possible timestamping points are expected than just two.
  
  A three-bit mask is defined (V4L2_BUF_FLAG_TSTAMP_SRC_MASK) and two of
  the eight possible values is are defined V4L2_BUF_FLAG_TSTAMP_SRC_EOF
  for end of frame (value zero) V4L2_BUF_FLAG_TSTAMP_SRC_SOE for start of
  exposure (next value).
  
 
 Changes in videobuf2-core.c look good.
 
  Signed-off-by: Sakari Ailus sakari.ai...@iki.fi
 
 Acked-by: Kamil Debski k.deb...@samsung.com

Many thanks for the reviews, Kamil! :-)

-- 
Kind regards,

Sakari Ailus
e-mail: sakari.ai...@iki.fi XMPP: sai...@retiisi.org.uk
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[GIT PULL] git://linuxtv.org/mkrufky/dvb dvb

2014-02-25 Thread Michael Krufky
The following changes since commit
efab6b6a6ea9364ececb955f69a9d3ffc6b782a1:

  [media] vivi: queue_setup improvements (2014-02-24 10:59:15 -0300)

are available in the git repository at:

  git://linuxtv.org/mkrufky/dvb dvb

for you to fetch changes up to e9abfeefb9d35229669f4d899832070ee623058e:

  stb6100: fix buffer length check in stb6100_write_reg_range()
  (2014-02-25 21:41:14 -0500)


Alexander Shiyan (1):
  stb6100: fix buffer length check in stb6100_write_reg_range()

Dan Carpenter (1):
  stv0900: remove an unneeded check

Malcolm Priestley (2):
  m88rs2000: add caps FE_CAN_INVERSION_AUTO
  m88rs2000: prevent frontend crash on continuous transponder scans

 drivers/media/dvb-frontends/m88rs2000.c  | 19 ++-
 drivers/media/dvb-frontends/stb6100.c|  2 +-
 drivers/media/dvb-frontends/stv0900_sw.c |  2 +-
 3 files changed, 20 insertions(+), 3 deletions(-)
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


GOOD NEWS

2014-02-25 Thread Dave and Angela
You have been Nominated by i and my wife Angela for Donation.Contact us 
:dave_angela0...@yahoo.com
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFC v6,2/3] controls.xml : add addtional Flash fault bits

2014-02-25 Thread Daniel Jeong
Descriptions for flash faluts.
 V4L2_FLASH_FAULT_UNDER_VOLTAGE,
 V4L2_FLASH_FAULT_INPUT_VOLTAGE,
 and V4L2_FLASH_FAULT_LED_OVER_TEMPERATURE

Signed-off-by: Daniel Jeong gshark.je...@gmail.com
---
 Documentation/DocBook/media/v4l/controls.xml |   18 ++
 1 file changed, 18 insertions(+)

diff --git a/Documentation/DocBook/media/v4l/controls.xml 
b/Documentation/DocBook/media/v4l/controls.xml
index a5a3188..16f8af3 100644
--- a/Documentation/DocBook/media/v4l/controls.xml
+++ b/Documentation/DocBook/media/v4l/controls.xml
@@ -4370,6 +4370,24 @@ interface and may change in the future./para
  entryThe flash controller has detected a short or open
  circuit condition on the indicator LED./entry
/row
+   row
+ 
entryconstantV4L2_FLASH_FAULT_UNDER_VOLTAGE/constant/entry
+ entryFlash controller voltage to the flash LED
+ has been below the minimum limit specific to the flash
+ controller./entry
+   /row
+   row
+ 
entryconstantV4L2_FLASH_FAULT_INPUT_VOLTAGE/constant/entry
+ entryThe flash current can't reach to the target current
+ because the input voltage is dropped below lower limit. 
+ and Flash controller have adjusted the flash current
+ not to occur under voltage event./entry
+   /row
+   row
+ 
entryconstantV4L2_FLASH_FAULT_LED_OVER_TEMPERATURE/constant/entry
+ entryThe temperature of the LED has exceeded its
+ allowed upper limit./entry
+   /row
  /tbody
/entrytbl
  /row
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFC v6,3/3] media: i2c: add new dual LED Flash driver, lm364

2014-02-25 Thread Daniel Jeong
 This patch adds the driver for the LM3646, dual LED Flash driver.
The LM3646 has two 1.5A sync. boost converter with dual white current source.
It is controlled via an I2C compatible interface.
Each flash brightness, torch brightness and enable/disable can be controlled.
Under voltage, input voltage monitor and thermal threshhold Faults are added.
Please refer the datasheet http://www.ti.com/lit/ds/snvs962/snvs962.pdf

Signed-off-by: Daniel Jeong gshark.je...@gmail.com
---
 drivers/media/i2c/Kconfig  |9 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/lm3646.c |  419 
 include/media/lm3646.h |   87 +
 4 files changed, 516 insertions(+)
 create mode 100644 drivers/media/i2c/lm3646.c
 create mode 100644 include/media/lm3646.h

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 4aa9c53..c7f2823 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -629,6 +629,15 @@ config VIDEO_LM3560
  This is a driver for the lm3560 dual flash controllers. It controls
  flash, torch LEDs.
 
+config VIDEO_LM3646
+   tristate LM3646 dual flash driver support
+   depends on I2C  VIDEO_V4L2  MEDIA_CONTROLLER
+   depends on MEDIA_CAMERA_SUPPORT
+   select REGMAP_I2C
+   ---help---
+ This is a driver for the lm3646 dual flash controllers. It controls
+ flash, torch LEDs.
+
 comment Video improvement chips
 
 config VIDEO_UPD64031A
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index 4ae..01b6bfc 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -72,6 +72,7 @@ obj-$(CONFIG_VIDEO_S5C73M3)   += s5c73m3/
 obj-$(CONFIG_VIDEO_ADP1653)+= adp1653.o
 obj-$(CONFIG_VIDEO_AS3645A)+= as3645a.o
 obj-$(CONFIG_VIDEO_LM3560) += lm3560.o
+obj-$(CONFIG_VIDEO_LM3646) += lm3646.o
 obj-$(CONFIG_VIDEO_SMIAPP_PLL) += smiapp-pll.o
 obj-$(CONFIG_VIDEO_AK881X) += ak881x.o
 obj-$(CONFIG_VIDEO_IR_I2C)  += ir-kbd-i2c.o
diff --git a/drivers/media/i2c/lm3646.c b/drivers/media/i2c/lm3646.c
new file mode 100644
index 000..97d79a7
--- /dev/null
+++ b/drivers/media/i2c/lm3646.c
@@ -0,0 +1,419 @@
+/*
+ * drivers/media/i2c/lm3646.c
+ * General device driver for TI lm3646, Dual FLASH LED Driver
+ *
+ * Copyright (C) 2014 Texas Instruments
+ *
+ * Contact: Daniel Jeong gshark.je...@gmail.com
+ * Ldd-Mlp ldd-...@list.ti.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ */
+
+#include linux/delay.h
+#include linux/module.h
+#include linux/i2c.h
+#include linux/slab.h
+#include linux/regmap.h
+#include linux/videodev2.h
+#include media/lm3646.h
+#include media/v4l2-ctrls.h
+#include media/v4l2-device.h
+
+/* registers definitions */
+#define REG_ENABLE 0x01
+#define REG_TORCH_BR   0x05
+#define REG_FLASH_BR   0x05
+#define REG_FLASH_TOUT 0x04
+#define REG_FLAG   0x08
+#define REG_STROBE_SRC 0x06
+#define REG_LED1_FLASH_BR 0x06
+#define REG_LED1_TORCH_BR 0x07
+
+#define MASK_ENABLE0x03
+#define MASK_TORCH_BR  0x70
+#define MASK_FLASH_BR  0x0F
+#define MASK_FLASH_TOUT0x07
+#define MASK_FLAG  0xFF
+#define MASK_STROBE_SRC0x80
+
+/* Fault Mask */
+#define FAULT_TIMEOUT  (10)
+#define FAULT_SHORT_CIRCUIT(11)
+#define FAULT_UVLO (12)
+#define FAULT_IVFM (13)
+#define FAULT_OCP  (14)
+#define FAULT_OVERTEMP (15)
+#define FAULT_NTC_TRIP (16)
+#define FAULT_OVP  (17)
+
+enum led_mode {
+   MODE_SHDN = 0x0,
+   MODE_TORCH = 0x2,
+   MODE_FLASH = 0x3,
+};
+
+/*
+ * struct lm3646_flash
+ *
+ * @pdata: platform data
+ * @regmap: reg. map for i2c
+ * @lock: muxtex for serial access.
+ * @led_mode: V4L2 LED mode
+ * @ctrls_led: V4L2 contols
+ * @subdev_led: V4L2 subdev
+ * @mode_reg : mode register value
+ */
+struct lm3646_flash {
+   struct device *dev;
+   struct lm3646_platform_data *pdata;
+   struct regmap *regmap;
+
+   struct v4l2_ctrl_handler ctrls_led;
+   struct v4l2_subdev subdev_led;
+
+   u8 mode_reg;
+};
+
+#define to_lm3646_flash(_ctrl) \
+   container_of(_ctrl-handler, struct lm3646_flash, ctrls_led)
+
+/* enable mode control */
+static int lm3646_mode_ctrl(struct lm3646_flash *flash,
+   enum v4l2_flash_led_mode led_mode)
+{
+   int rval = -EINVAL;
+
+   switch (led_mode) {
+   case V4L2_FLASH_LED_MODE_NONE:
+   rval = regmap_write(flash-regmap,
+   REG_ENABLE, flash-mode_reg | MODE_SHDN);
+   break;
+   case V4L2_FLASH_LED_MODE_TORCH:
+   rval = regmap_write(flash-regmap,
+   REG_ENABLE, flash-mode_reg | MODE_TORCH);
+   break;
+   case 

[RFC v6 1/3] v4l2-controls.h: add addtional Flash fault bits

2014-02-25 Thread Daniel Jeong
 Three Flash fault are added.
 V4L2_FLASH_FAULT_UNDER_VOLTAGE for the case low voltage below the min. limit.
 V4L2_FLASH_FAULT_INPUT_VOLTAGE for the case falling input voltage and chip  
 adjust flash current not occur under voltage event.
 V4L2_FLASH_FAULT_LED_OVER_TEMPERATURE for the case the temperature exceed
 the maximun limit

Signed-off-by: Daniel Jeong gshark.je...@gmail.com
---
 include/uapi/linux/v4l2-controls.h |3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/uapi/linux/v4l2-controls.h 
b/include/uapi/linux/v4l2-controls.h
index 2cbe605..1d662f6 100644
--- a/include/uapi/linux/v4l2-controls.h
+++ b/include/uapi/linux/v4l2-controls.h
@@ -812,6 +812,9 @@ enum v4l2_flash_strobe_source {
 #define V4L2_FLASH_FAULT_SHORT_CIRCUIT (1  3)
 #define V4L2_FLASH_FAULT_OVER_CURRENT  (1  4)
 #define V4L2_FLASH_FAULT_INDICATOR (1  5)
+#define V4L2_FLASH_FAULT_UNDER_VOLTAGE (1  6)
+#define V4L2_FLASH_FAULT_INPUT_VOLTAGE (1  7)
+#define V4L2_FLASH_FAULT_LED_OVER_TEMPERATURE  (1  8)
 
 #define V4L2_CID_FLASH_CHARGE  (V4L2_CID_FLASH_CLASS_BASE + 11)
 #define V4L2_CID_FLASH_READY   (V4L2_CID_FLASH_CLASS_BASE + 12)
-- 
1.7.9.5

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html