cron job: media_tree daily build: OK

2018-06-15 Thread Hans Verkuil
This message is generated daily by a cron job that builds media_tree for
the kernels and architectures in the list below.

Results of the daily build of media_tree:

date:   Sat Jun 16 05:00:24 CEST 2018
media-tree git hash:f2809d20b9250c675fca8268a0f6274277cca7ff
media_build git hash:   464ef972618cc9f845f07c1a4e8957ce2270cf91
v4l-utils git hash: c3b46c2c53d7d815a53c902cfb2ddd96c3732c5b
gcc version:i686-linux-gcc (GCC) 8.1.0
sparse version: 0.5.2
smatch version: 0.5.1
host hardware:  x86_64
host os:4.16.0-1-amd64

linux-git-arm-at91: OK
linux-git-arm-davinci: OK
linux-git-arm-multi: OK
linux-git-arm-pxa: OK
linux-git-arm-stm32: OK
linux-git-arm64: OK
linux-git-i686: OK
linux-git-mips: OK
linux-git-powerpc64: OK
linux-git-sh: OK
linux-git-x86_64: OK
Check COMPILE_TEST: OK
linux-2.6.36.4-i686: OK
linux-2.6.36.4-x86_64: OK
linux-2.6.37.6-i686: OK
linux-2.6.37.6-x86_64: OK
linux-2.6.38.8-i686: OK
linux-2.6.38.8-x86_64: OK
linux-2.6.39.4-i686: OK
linux-2.6.39.4-x86_64: OK
linux-3.0.101-i686: OK
linux-3.0.101-x86_64: OK
linux-3.1.10-i686: OK
linux-3.1.10-x86_64: OK
linux-3.2.101-i686: OK
linux-3.2.101-x86_64: OK
linux-3.3.8-i686: OK
linux-3.3.8-x86_64: OK
linux-3.4.113-i686: OK
linux-3.4.113-x86_64: OK
linux-3.5.7-i686: OK
linux-3.5.7-x86_64: OK
linux-3.6.11-i686: OK
linux-3.6.11-x86_64: OK
linux-3.7.10-i686: OK
linux-3.7.10-x86_64: OK
linux-3.8.13-i686: OK
linux-3.8.13-x86_64: OK
linux-3.9.11-i686: OK
linux-3.9.11-x86_64: OK
linux-3.10.108-i686: OK
linux-3.10.108-x86_64: OK
linux-3.11.10-i686: OK
linux-3.11.10-x86_64: OK
linux-3.12.74-i686: OK
linux-3.12.74-x86_64: OK
linux-3.13.11-i686: OK
linux-3.13.11-x86_64: OK
linux-3.14.79-i686: OK
linux-3.14.79-x86_64: OK
linux-3.15.10-i686: OK
linux-3.15.10-x86_64: OK
linux-3.16.56-i686: OK
linux-3.16.56-x86_64: OK
linux-3.17.8-i686: OK
linux-3.17.8-x86_64: OK
linux-3.18.102-i686: OK
linux-3.18.102-x86_64: OK
linux-3.19.8-i686: OK
linux-3.19.8-x86_64: OK
linux-4.0.9-i686: OK
linux-4.0.9-x86_64: OK
linux-4.1.51-i686: OK
linux-4.1.51-x86_64: OK
linux-4.2.8-i686: OK
linux-4.2.8-x86_64: OK
linux-4.3.6-i686: OK
linux-4.3.6-x86_64: OK
linux-4.4.109-i686: OK
linux-4.4.109-x86_64: OK
linux-4.5.7-i686: OK
linux-4.5.7-x86_64: OK
linux-4.6.7-i686: OK
linux-4.6.7-x86_64: OK
linux-4.7.10-i686: OK
linux-4.7.10-x86_64: OK
linux-4.8.17-i686: OK
linux-4.8.17-x86_64: OK
linux-4.9.91-i686: OK
linux-4.9.91-x86_64: OK
linux-4.10.17-i686: OK
linux-4.10.17-x86_64: OK
linux-4.11.12-i686: OK
linux-4.11.12-x86_64: OK
linux-4.12.14-i686: OK
linux-4.12.14-x86_64: OK
linux-4.13.16-i686: OK
linux-4.13.16-x86_64: OK
linux-4.14.42-i686: OK
linux-4.14.42-x86_64: OK
linux-4.15.14-i686: OK
linux-4.15.14-x86_64: OK
linux-4.16.8-i686: OK
linux-4.16.8-x86_64: OK
linux-4.17-i686: OK
linux-4.17-x86_64: OK
apps: OK
spec-git: OK
sparse: WARNINGS

Detailed results are available here:

http://www.xs4all.nl/~hverkuil/logs/Saturday.log

Full logs are available here:

http://www.xs4all.nl/~hverkuil/logs/Saturday.tar.bz2

The Media Infrastructure API from this daily build is here:

http://www.xs4all.nl/~hverkuil/spec/index.html


Re: [RFC PATCH v2] media: i2c: add SCCB helpers

2018-06-15 Thread Laurent Pinchart
Hello,

On Thursday, 14 June 2018 18:33:58 EEST Wolfram Sang wrote:
> On Wed, Jun 13, 2018 at 12:34:46AM +0900, Akinobu Mita wrote:
> > (This is 2nd version of SCCB helpers patch.  After 1st version was
> > submitted, I sent alternative patch titled "i2c: add I2C_M_FORCE_STOP".
> > But it wasn't accepted because it makes the I2C core code unreadable.
> > I couldn't find out a way to untangle it, so I returned to the original
> > approach.)
> > 
> > This adds Serial Camera Control Bus (SCCB) helper functions
> > (sccb_read_byte and sccb_write_byte) that are intended to be used by some
> > of Omnivision sensor drivers.
> > 
> > The ov772x driver is going to use these functions in order to make it work
> > with most i2c controllers.
> > 
> > As the ov772x device doesn't support repeated starts, this driver
> > currently requires I2C_FUNC_PROTOCOL_MANGLING that is not supported by
> > many i2c controller drivers.
> > 
> > With the sccb_read_byte() that issues two separated requests in order to
> > avoid repeated start, the driver doesn't require
> > I2C_FUNC_PROTOCOL_MANGLING.
> 
> From a first glance, this looks like my preferred solution so far.
> Thanks for doing it! Let me sleep a bit over it for a thorough review...
> 
> > --- /dev/null
> > +++ b/drivers/media/i2c/sccb.h
> 
> I'd prefer this file to be in the i2c realm. Maybe
> 'include/linux/i2c-sccb.h" or something. I will come back to this.

And while at it, I think we also need a .c file, the functions (and especially 
sccb_read_byte()) should not be static inline.

-- 
Regards,

Laurent Pinchart





Re: [RFC 0/2] Memory-to-memory media controller topology

2018-06-15 Thread Ezequiel Garcia
On Tue, 2018-06-12 at 10:42 -0400, Nicolas Dufresne wrote:
> Le mardi 12 juin 2018 à 07:48 -0300, Ezequiel Garcia a écrit :
> > As discussed on IRC, memory-to-memory need to be modeled
> > properly in order to be supported by the media controller
> > framework, and thus to support the Request API.
> > 
> > This RFC is a first draft on the memory-to-memory
> > media controller topology.
> > 
> > The topology looks like this:
> > 
> > Device topology
> > - entity 1: input (1 pad, 1 link)
> > type Node subtype Unknown flags 0
> > pad0: Source
> > -> "proc":1 [ENABLED,IMMUTABLE]
> > 
> > - entity 3: proc (2 pads, 2 links)
> > type Node subtype Unknown flags 0
> > pad0: Source
> > -> "output":0 [ENABLED,IMMUTABLE]
> > pad1: Sink
> > <- "input":0 [ENABLED,IMMUTABLE]
> > 
> > - entity 6: output (1 pad, 1 link)
> > type Node subtype Unknown flags 0
> > pad0: Sink
> > <- "proc":0 [ENABLED,IMMUTABLE]
> 
> Will the end result have "device node name /dev/..." on both entity 1
> and 6 ? 

No. There is just one devnode /dev/videoX, which is accepts
both CAPTURE and OUTPUT directions.

> I got told that in the long run, one should be able to map a
> device (/dev/mediaN) to it's nodes (/dev/video*). In a way that if we
> keep going this way, all the media devices can be enumerated from
> media
> node rather then a mixed between media nodes and orphaned video
> nodes.
> 

Yes, that is the idea I think. For instance, for devices with
multiple audio and video channels, there is currently no
clean way to discover them and correlate e.g. video devices
to audio devices.

Not that this series help on that either :) 


Re: [RFC 2/2] vim2m: add media device

2018-06-15 Thread Ezequiel Garcia
On Tue, 2018-06-12 at 20:44 +0100, emil.veli...@collabora.com wrote:
> Hi Ezequiel,  
> 
> On Tue, Jun 12, 2018 at 07:48:27AM -0300, Ezequiel Garcia wrote:
> 
> > @@ -1013,10 +1016,10 @@ static int vim2m_probe(struct
> > platform_device *pdev)
> > vfd->lock = >dev_mutex;
> > vfd->v4l2_dev = >v4l2_dev;
> >  
> > -   ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0);
> > +   ret = video_register_device(vfd, VFL_TYPE_MEM2MEM, 0);
> 
> Shouldn't the original type be used when building without
> CONFIG_MEDIA_CONTROLLER?
> 

No, the idea was to introduce a new type for mem2mem,
mainly to avoid the video2linux core from registering
mc entities.

Anyway, Hans dislikes this and suggested to drop it.

> 
> > @@ -1050,6 +1076,11 @@ static int vim2m_remove(struct
> > platform_device *pdev)
> > struct vim2m_dev *dev = platform_get_drvdata(pdev);
> >  
> > v4l2_info(>v4l2_dev, "Removing " MEM2MEM_NAME);
> > +
> > +#ifdef CONFIG_MEDIA_CONTROLLER
> 
> Gut suggests that media_device_unregister() should be called here.
> 
> Then again my experience in media/ is limited so I could be miles off
> ;-)
> 

Good catch, it seems it's indeed missing.

Thanks,
Eze


Re: [PATCH 2/3] mem2mem: Make .job_abort optional

2018-06-15 Thread Ezequiel Garcia
On Fri, 2018-06-15 at 10:43 +0200, Hans Verkuil wrote:
> On 14/06/18 17:34, Ezequiel Garcia wrote:
> > Implementing job_abort() does not make sense on some drivers.
> > This is not a problem, as the abort is not required to
> > wait for the job to finish. Quite the opposite, drivers
> > are encouraged not to wait.
> > 
> > Demote v4l2_m2m_ops.job_abort from required to optional, and
> > clean all drivers with dummy or wrong implementations.
> 
> Can you split off the rcar_jpu.c and g2d.c changes into separate
> patches?
> The others are trivial, but those two need a more precise commit log
> and
> I would like to have Acks of the driver maintainers before merging.
> 

Yes, that makes sense.

> I'm going to take the first and third patches of this series, so you
> only have to post a v2 for this patch.
> 

OK.

Thanks,
Eze



[PATCH v4 15/17] videobuf2: assume q->lock is always set

2018-06-15 Thread Ezequiel Garcia
From: Hans Verkuil 

Drop checks for q->lock. Drop calls to wait_finish/prepare, just lock/unlock
q->lock.

Signed-off-by: Hans Verkuil 
---
 .../media/common/videobuf2/videobuf2-core.c   | 21 ++-
 .../media/common/videobuf2/videobuf2-v4l2.c   | 27 +--
 include/media/videobuf2-core.h|  2 --
 3 files changed, 15 insertions(+), 35 deletions(-)

diff --git a/drivers/media/common/videobuf2/videobuf2-core.c 
b/drivers/media/common/videobuf2/videobuf2-core.c
index 0d8e93f9a622..e0c4e1a8f311 100644
--- a/drivers/media/common/videobuf2/videobuf2-core.c
+++ b/drivers/media/common/videobuf2/videobuf2-core.c
@@ -462,8 +462,7 @@ static int __vb2_queue_free(struct vb2_queue *q, unsigned 
int buffers)
 * counters to the kernel log.
 */
if (q->num_buffers) {
-   bool unbalanced = q->cnt_start_streaming != 
q->cnt_stop_streaming ||
- q->cnt_wait_prepare != q->cnt_wait_finish;
+   bool unbalanced = q->cnt_start_streaming != 
q->cnt_stop_streaming;
 
if (unbalanced || debug) {
pr_info("counters for queue %p:%s\n", q,
@@ -471,12 +470,8 @@ static int __vb2_queue_free(struct vb2_queue *q, unsigned 
int buffers)
pr_info(" setup: %u start_streaming: %u 
stop_streaming: %u\n",
q->cnt_queue_setup, q->cnt_start_streaming,
q->cnt_stop_streaming);
-   pr_info(" wait_prepare: %u wait_finish: %u\n",
-   q->cnt_wait_prepare, q->cnt_wait_finish);
}
q->cnt_queue_setup = 0;
-   q->cnt_wait_prepare = 0;
-   q->cnt_wait_finish = 0;
q->cnt_start_streaming = 0;
q->cnt_stop_streaming = 0;
}
@@ -1487,10 +1482,10 @@ static int __vb2_wait_for_done_vb(struct vb2_queue *q, 
int nonblocking)
 
/*
 * We are streaming and blocking, wait for another buffer to
-* become ready or for streamoff. Driver's lock is released to
+* become ready or for streamoff. The queue's lock is released 
to
 * allow streamoff or qbuf to be called while waiting.
 */
-   call_void_qop(q, wait_prepare, q);
+   mutex_unlock(q->lock);
 
/*
 * All locks have been released, it is safe to sleep now.
@@ -1504,7 +1499,7 @@ static int __vb2_wait_for_done_vb(struct vb2_queue *q, 
int nonblocking)
 * We need to reevaluate both conditions again after reacquiring
 * the locks or return an error if one occurred.
 */
-   call_void_qop(q, wait_finish, q);
+   mutex_lock(q->lock);
if (ret) {
dprintk(1, "sleep was interrupted\n");
return ret;
@@ -2531,10 +2526,10 @@ static int vb2_thread(void *data)
vb = q->bufs[index++];
prequeue--;
} else {
-   call_void_qop(q, wait_finish, q);
+   mutex_lock(q->lock);
if (!threadio->stop)
ret = vb2_core_dqbuf(q, , NULL, 0);
-   call_void_qop(q, wait_prepare, q);
+   mutex_unlock(q->lock);
dprintk(5, "file io: vb2_dqbuf result: %d\n", ret);
if (!ret)
vb = q->bufs[index];
@@ -2546,12 +2541,12 @@ static int vb2_thread(void *data)
if (vb->state != VB2_BUF_STATE_ERROR)
if (threadio->fnc(vb, threadio->priv))
break;
-   call_void_qop(q, wait_finish, q);
+   mutex_lock(q->lock);
if (copy_timestamp)
vb->timestamp = ktime_get_ns();
if (!threadio->stop)
ret = vb2_core_qbuf(q, vb->index, NULL);
-   call_void_qop(q, wait_prepare, q);
+   mutex_unlock(q->lock);
if (ret || threadio->stop)
break;
}
diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c 
b/drivers/media/common/videobuf2/videobuf2-v4l2.c
index 886a2d8d5c6c..7d2172468f72 100644
--- a/drivers/media/common/videobuf2/videobuf2-v4l2.c
+++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c
@@ -852,9 +852,8 @@ EXPORT_SYMBOL_GPL(_vb2_fop_release);
 int vb2_fop_release(struct file *file)
 {
struct video_device *vdev = video_devdata(file);
-   struct mutex *lock = vdev->queue->lock ? vdev->queue->lock : vdev->lock;
 
-   return _vb2_fop_release(file, lock);
+   return _vb2_fop_release(file, vdev->queue->lock);
 }
 EXPORT_SYMBOL_GPL(vb2_fop_release);
 
@@ -862,12 +861,11 @@ ssize_t 

[PATCH v4 16/17] v4l2-ioctl.c: assume queue->lock is always set

2018-06-15 Thread Ezequiel Garcia
From: Hans Verkuil 

vb2_queue now expects a valid lock pointer, so drop the checks for
that in v4l2-ioctl.c.

Signed-off-by: Hans Verkuil 
---
 drivers/media/v4l2-core/v4l2-ioctl.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
b/drivers/media/v4l2-core/v4l2-ioctl.c
index db835578e21f..c3da0f9a86e4 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -2715,12 +2715,11 @@ static struct mutex *v4l2_ioctl_get_lock(struct 
video_device *vdev,
struct v4l2_m2m_queue_ctx *ctx = is_output ?
>m2m_ctx->out_q_ctx : >m2m_ctx->cap_q_ctx;
 
-   if (ctx->q.lock)
-   return ctx->q.lock;
+   return ctx->q.lock;
}
 #endif
-   if (vdev->queue && vdev->queue->lock &&
-   (v4l2_ioctls[_IOC_NR(cmd)].flags & INFO_FL_QUEUE))
+   if (vdev->queue &&
+   (v4l2_ioctls[_IOC_NR(cmd)].flags & INFO_FL_QUEUE))
return vdev->queue->lock;
return vdev->lock;
 }
-- 
2.17.1



[PATCH v4 17/17] media: Remove wait_{prepare, finish}

2018-06-15 Thread Ezequiel Garcia
Now that all drivers provide a proper vb2_queue lock,
and that wait_{prepare, finish} are no longer in use,
get rid of them.

Signed-off-by: Ezequiel Garcia 
---
 Documentation/media/kapi/v4l2-dev.rst  |  7 +++
 drivers/input/rmi4/rmi_f54.c   |  2 --
 drivers/input/touchscreen/atmel_mxt_ts.c   |  2 --
 drivers/input/touchscreen/sur40.c  |  2 --
 .../media/common/videobuf2/videobuf2-v4l2.c| 14 --
 drivers/media/dvb-core/dvb_vb2.c   |  2 --
 drivers/media/dvb-frontends/rtl2832_sdr.c  |  2 --
 drivers/media/i2c/video-i2c.c  |  2 --
 drivers/media/pci/cobalt/cobalt-v4l2.c |  2 --
 drivers/media/pci/cx23885/cx23885-417.c|  2 --
 drivers/media/pci/cx23885/cx23885-dvb.c|  2 --
 drivers/media/pci/cx23885/cx23885-vbi.c|  2 --
 drivers/media/pci/cx23885/cx23885-video.c  |  2 --
 drivers/media/pci/cx25821/cx25821-video.c  |  2 --
 drivers/media/pci/cx88/cx88-blackbird.c|  2 --
 drivers/media/pci/cx88/cx88-dvb.c  |  2 --
 drivers/media/pci/cx88/cx88-vbi.c  |  2 --
 drivers/media/pci/cx88/cx88-video.c|  2 --
 drivers/media/pci/dt3155/dt3155.c  |  2 --
 drivers/media/pci/intel/ipu3/ipu3-cio2.c   |  2 --
 drivers/media/pci/saa7134/saa7134-empress.c|  2 --
 drivers/media/pci/saa7134/saa7134-ts.c |  2 --
 drivers/media/pci/saa7134/saa7134-vbi.c|  2 --
 drivers/media/pci/saa7134/saa7134-video.c  |  2 --
 drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c |  2 --
 drivers/media/pci/solo6x10/solo6x10-v4l2.c |  2 --
 drivers/media/pci/sta2x11/sta2x11_vip.c|  2 --
 drivers/media/pci/tw5864/tw5864-video.c|  2 --
 drivers/media/pci/tw68/tw68-video.c|  2 --
 drivers/media/pci/tw686x/tw686x-video.c|  2 --
 drivers/media/platform/am437x/am437x-vpfe.c|  2 --
 drivers/media/platform/atmel/atmel-isc.c   |  2 --
 drivers/media/platform/atmel/atmel-isi.c   |  2 --
 drivers/media/platform/coda/coda-common.c  |  2 --
 drivers/media/platform/davinci/vpbe_display.c  |  2 --
 drivers/media/platform/davinci/vpif_capture.c  |  2 --
 drivers/media/platform/davinci/vpif_display.c  |  2 --
 drivers/media/platform/exynos-gsc/gsc-m2m.c|  2 --
 .../media/platform/exynos4-is/fimc-capture.c   |  2 --
 .../media/platform/exynos4-is/fimc-isp-video.c |  2 --
 drivers/media/platform/exynos4-is/fimc-lite.c  |  2 --
 drivers/media/platform/exynos4-is/fimc-m2m.c   |  2 --
 drivers/media/platform/m2m-deinterlace.c   |  2 --
 .../media/platform/marvell-ccic/mcam-core.c|  4 
 .../media/platform/mtk-jpeg/mtk_jpeg_core.c|  2 --
 drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c   |  2 --
 .../media/platform/mtk-vcodec/mtk_vcodec_dec.c |  2 --
 .../media/platform/mtk-vcodec/mtk_vcodec_enc.c |  2 --
 drivers/media/platform/mx2_emmaprp.c   |  2 --
 drivers/media/platform/omap3isp/ispvideo.c |  2 --
 drivers/media/platform/pxa_camera.c|  2 --
 .../platform/qcom/camss-8x16/camss-video.c |  2 --
 drivers/media/platform/qcom/venus/vdec.c   |  2 --
 drivers/media/platform/qcom/venus/venc.c   |  2 --
 drivers/media/platform/rcar-vin/rcar-dma.c |  2 --
 drivers/media/platform/rcar_drif.c |  2 --
 drivers/media/platform/rcar_fdp1.c |  2 --
 drivers/media/platform/rcar_jpu.c  |  2 --
 drivers/media/platform/renesas-ceu.c   |  2 --
 drivers/media/platform/rockchip/rga/rga-buf.c  |  2 --
 .../media/platform/s3c-camif/camif-capture.c   |  2 --
 drivers/media/platform/s5p-g2d/g2d.c   |  2 --
 drivers/media/platform/s5p-jpeg/jpeg-core.c|  2 --
 drivers/media/platform/s5p-mfc/s5p_mfc_dec.c   |  2 --
 drivers/media/platform/s5p-mfc/s5p_mfc_enc.c   |  2 --
 drivers/media/platform/sh_veu.c|  2 --
 drivers/media/platform/sh_vou.c|  2 --
 .../platform/soc_camera/sh_mobile_ceu_camera.c |  2 --
 drivers/media/platform/sti/bdisp/bdisp-v4l2.c  |  2 --
 drivers/media/platform/sti/delta/delta-v4l2.c  |  4 
 drivers/media/platform/sti/hva/hva-v4l2.c  |  2 --
 drivers/media/platform/stm32/stm32-dcmi.c  |  2 --
 drivers/media/platform/ti-vpe/cal.c|  2 --
 drivers/media/platform/ti-vpe/vpe.c|  2 --
 drivers/media/platform/vim2m.c |  2 --
 drivers/media/platform/vimc/vimc-capture.c |  6 --
 drivers/media/platform/vivid/vivid-sdr-cap.c   |  2 --
 drivers/media/platform/vivid/vivid-vbi-cap.c   |  2 --
 drivers/media/platform/vivid/vivid-vbi-out.c   |  2 --
 drivers/media/platform/vivid/vivid-vid-cap.c   |  2 --
 drivers/media/platform/vivid/vivid-vid-out.c   |  2 --
 drivers/media/platform/vsp1/vsp1_histo.c   |  2 --
 drivers/media/platform/vsp1/vsp1_video.c   |  2 --
 drivers/media/platform/xilinx/xilinx-dma.c |  2 --
 drivers/media/usb/airspy/airspy.c  |  2 --
 drivers/media/usb/au0828/au0828-vbi.c  |  

[PATCH v4 13/17] dvb-core: Provide lock for vb2_queue

2018-06-15 Thread Ezequiel Garcia
Use the vb2 context mutex to protect the vb2_queue.
This allows to replace the ad-hoc wait_{prepare, finish}
with vb2_ops_wait_{prepare, finish}.

Signed-off-by: Ezequiel Garcia 
---
 drivers/media/dvb-core/dvb_vb2.c | 22 +++---
 1 file changed, 3 insertions(+), 19 deletions(-)

diff --git a/drivers/media/dvb-core/dvb_vb2.c b/drivers/media/dvb-core/dvb_vb2.c
index b811adf88afa..cd3ea44f0ae9 100644
--- a/drivers/media/dvb-core/dvb_vb2.c
+++ b/drivers/media/dvb-core/dvb_vb2.c
@@ -107,31 +107,14 @@ static void _stop_streaming(struct vb2_queue *vq)
spin_unlock_irqrestore(>slock, flags);
 }
 
-static void _dmxdev_lock(struct vb2_queue *vq)
-{
-   struct dvb_vb2_ctx *ctx = vb2_get_drv_priv(vq);
-
-   mutex_lock(>mutex);
-   dprintk(3, "[%s]\n", ctx->name);
-}
-
-static void _dmxdev_unlock(struct vb2_queue *vq)
-{
-   struct dvb_vb2_ctx *ctx = vb2_get_drv_priv(vq);
-
-   if (mutex_is_locked(>mutex))
-   mutex_unlock(>mutex);
-   dprintk(3, "[%s]\n", ctx->name);
-}
-
 static const struct vb2_ops dvb_vb2_qops = {
.queue_setup= _queue_setup,
.buf_prepare= _buffer_prepare,
.buf_queue  = _buffer_queue,
.start_streaming= _start_streaming,
.stop_streaming = _stop_streaming,
-   .wait_prepare   = _dmxdev_unlock,
-   .wait_finish= _dmxdev_lock,
+   .wait_prepare   = vb2_ops_wait_prepare,
+   .wait_finish= vb2_ops_wait_finish,
 };
 
 static void _fill_dmx_buffer(struct vb2_buffer *vb, void *pb)
@@ -183,6 +166,7 @@ int dvb_vb2_init(struct dvb_vb2_ctx *ctx, const char *name, 
int nonblocking)
q->mem_ops = _vmalloc_memops;
q->buf_ops = _vb2_buf_ops;
q->num_buffers = 0;
+   q->lock = >mutex;
ret = vb2_core_queue_init(q);
if (ret) {
ctx->state = DVB_VB2_STATE_NONE;
-- 
2.17.1



[PATCH v4 14/17] videobuf2-core: require q->lock

2018-06-15 Thread Ezequiel Garcia
From: Hans Verkuil 

Refuse to initialize a vb2 queue if there is no lock specified.

Signed-off-by: Hans Verkuil 
---
 drivers/media/common/videobuf2/videobuf2-core.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/common/videobuf2/videobuf2-core.c 
b/drivers/media/common/videobuf2/videobuf2-core.c
index f32ec7342ef0..0d8e93f9a622 100644
--- a/drivers/media/common/videobuf2/videobuf2-core.c
+++ b/drivers/media/common/videobuf2/videobuf2-core.c
@@ -2005,6 +2005,7 @@ int vb2_core_queue_init(struct vb2_queue *q)
if (WARN_ON(!q)   ||
WARN_ON(!q->ops)  ||
WARN_ON(!q->mem_ops)  ||
+   WARN_ON(!q->lock) ||
WARN_ON(!q->type) ||
WARN_ON(!q->io_modes) ||
WARN_ON(!q->ops->queue_setup) ||
-- 
2.17.1



[PATCH v4 06/17] s5p-g2d: Implement wait_prepare and wait_finish

2018-06-15 Thread Ezequiel Garcia
This driver is currently specifying a vb2_queue lock,
which means it straightforward to implement wait_prepare
and wait_finish.

Having these callbacks releases the queue lock while blocking,
which improves latency by allowing for example streamoff
or qbuf operations while waiting in dqbuf.

Signed-off-by: Ezequiel Garcia 
---
 drivers/media/platform/s5p-g2d/g2d.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/media/platform/s5p-g2d/g2d.c 
b/drivers/media/platform/s5p-g2d/g2d.c
index 66aa8cf1d048..ce4280730835 100644
--- a/drivers/media/platform/s5p-g2d/g2d.c
+++ b/drivers/media/platform/s5p-g2d/g2d.c
@@ -142,6 +142,8 @@ static const struct vb2_ops g2d_qops = {
.queue_setup= g2d_queue_setup,
.buf_prepare= g2d_buf_prepare,
.buf_queue  = g2d_buf_queue,
+   .wait_prepare   = vb2_ops_wait_prepare,
+   .wait_finish= vb2_ops_wait_finish,
 };
 
 static int queue_init(void *priv, struct vb2_queue *src_vq,
-- 
2.17.1



[PATCH v4 04/17] omap3isp: Add vb2_queue lock

2018-06-15 Thread Ezequiel Garcia
vb2_queue locks is now mandatory. Add it, remove driver ad-hoc locks,
and implement wait_{prepare, finish}.

Signed-off-by: Ezequiel Garcia 
---
 drivers/media/platform/omap3isp/ispvideo.c | 65 --
 drivers/media/platform/omap3isp/ispvideo.h |  1 -
 2 files changed, 11 insertions(+), 55 deletions(-)

diff --git a/drivers/media/platform/omap3isp/ispvideo.c 
b/drivers/media/platform/omap3isp/ispvideo.c
index 9d228eac24ea..f835aeb9ddc5 100644
--- a/drivers/media/platform/omap3isp/ispvideo.c
+++ b/drivers/media/platform/omap3isp/ispvideo.c
@@ -496,6 +496,8 @@ static const struct vb2_ops isp_video_queue_ops = {
.buf_prepare = isp_video_buffer_prepare,
.buf_queue = isp_video_buffer_queue,
.start_streaming = isp_video_start_streaming,
+   .wait_prepare = vb2_ops_wait_prepare,
+   .wait_finish = vb2_ops_wait_finish,
 };
 
 /*
@@ -628,11 +630,8 @@ void omap3isp_video_resume(struct isp_video *video, int 
continuous)
 {
struct isp_buffer *buf = NULL;
 
-   if (continuous && video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
-   mutex_lock(>queue_lock);
+   if (continuous && video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
vb2_discard_done(video->queue);
-   mutex_unlock(>queue_lock);
-   }
 
if (!list_empty(>dmaqueue)) {
buf = list_first_entry(>dmaqueue,
@@ -909,13 +908,8 @@ isp_video_reqbufs(struct file *file, void *fh, struct 
v4l2_requestbuffers *rb)
 {
struct isp_video_fh *vfh = to_isp_video_fh(fh);
struct isp_video *video = video_drvdata(file);
-   int ret;
-
-   mutex_lock(>queue_lock);
-   ret = vb2_reqbufs(>queue, rb);
-   mutex_unlock(>queue_lock);
 
-   return ret;
+   return vb2_reqbufs(>queue, rb);
 }
 
 static int
@@ -923,13 +917,8 @@ isp_video_querybuf(struct file *file, void *fh, struct 
v4l2_buffer *b)
 {
struct isp_video_fh *vfh = to_isp_video_fh(fh);
struct isp_video *video = video_drvdata(file);
-   int ret;
 
-   mutex_lock(>queue_lock);
-   ret = vb2_querybuf(>queue, b);
-   mutex_unlock(>queue_lock);
-
-   return ret;
+   return vb2_querybuf(>queue, b);
 }
 
 static int
@@ -937,13 +926,8 @@ isp_video_qbuf(struct file *file, void *fh, struct 
v4l2_buffer *b)
 {
struct isp_video_fh *vfh = to_isp_video_fh(fh);
struct isp_video *video = video_drvdata(file);
-   int ret;
 
-   mutex_lock(>queue_lock);
-   ret = vb2_qbuf(>queue, b);
-   mutex_unlock(>queue_lock);
-
-   return ret;
+   return vb2_qbuf(>queue, b);
 }
 
 static int
@@ -951,13 +935,8 @@ isp_video_dqbuf(struct file *file, void *fh, struct 
v4l2_buffer *b)
 {
struct isp_video_fh *vfh = to_isp_video_fh(fh);
struct isp_video *video = video_drvdata(file);
-   int ret;
 
-   mutex_lock(>queue_lock);
-   ret = vb2_dqbuf(>queue, b, file->f_flags & O_NONBLOCK);
-   mutex_unlock(>queue_lock);
-
-   return ret;
+   return vb2_dqbuf(>queue, b, file->f_flags & O_NONBLOCK);
 }
 
 static int isp_video_check_external_subdevs(struct isp_video *video,
@@ -1096,8 +1075,6 @@ isp_video_streamon(struct file *file, void *fh, enum 
v4l2_buf_type type)
if (type != video->type)
return -EINVAL;
 
-   mutex_lock(>stream_lock);
-
/* Start streaming on the pipeline. No link touching an entity in the
 * pipeline can be activated or deactivated once streaming is started.
 */
@@ -1106,7 +1083,7 @@ isp_video_streamon(struct file *file, void *fh, enum 
v4l2_buf_type type)
 
ret = media_entity_enum_init(>ent_enum, >isp->media_dev);
if (ret)
-   goto err_enum_init;
+   return ret;
 
/* TODO: Implement PM QoS */
pipe->l3_ick = clk_get_rate(video->isp->clock[ISP_CLK_L3_ICK]);
@@ -1158,14 +1135,10 @@ isp_video_streamon(struct file *file, void *fh, enum 
v4l2_buf_type type)
atomic_set(>frame_number, -1);
pipe->field = vfh->format.fmt.pix.field;
 
-   mutex_lock(>queue_lock);
ret = vb2_streamon(>queue, type);
-   mutex_unlock(>queue_lock);
if (ret < 0)
goto err_check_format;
 
-   mutex_unlock(>stream_lock);
-
return 0;
 
 err_check_format:
@@ -1184,9 +1157,6 @@ isp_video_streamon(struct file *file, void *fh, enum 
v4l2_buf_type type)
 
media_entity_enum_cleanup(>ent_enum);
 
-err_enum_init:
-   mutex_unlock(>stream_lock);
-
return ret;
 }
 
@@ -1203,15 +1173,10 @@ isp_video_streamoff(struct file *file, void *fh, enum 
v4l2_buf_type type)
if (type != video->type)
return -EINVAL;
 
-   mutex_lock(>stream_lock);
-
/* Make sure we're not streaming yet. */
-   mutex_lock(>queue_lock);
streaming = vb2_is_streaming(>queue);
-   mutex_unlock(>queue_lock);
-
if (!streaming)
-   goto done;
+   return 0;
 
/* Update the 

[PATCH v4 07/17] staging: bcm2835-camera: Provide lock for vb2_queue

2018-06-15 Thread Ezequiel Garcia
Use the device mutex to protect the vb2_queue.
This allows to replace the ad-hoc wait_{prepare, finish}
with vb2_ops_wait_{prepare, finish}.

Signed-off-by: Ezequiel Garcia 
---
 .../bcm2835-camera/bcm2835-camera.c   | 24 ---
 1 file changed, 5 insertions(+), 19 deletions(-)

diff --git a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c 
b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
index ce26741ae9d9..6dd0c838db05 100644
--- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
+++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
@@ -628,20 +628,6 @@ static void stop_streaming(struct vb2_queue *vq)
v4l2_err(>v4l2_dev, "Failed to disable camera\n");
 }
 
-static void bm2835_mmal_lock(struct vb2_queue *vq)
-{
-   struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
-
-   mutex_lock(>mutex);
-}
-
-static void bm2835_mmal_unlock(struct vb2_queue *vq)
-{
-   struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
-
-   mutex_unlock(>mutex);
-}
-
 static const struct vb2_ops bm2835_mmal_video_qops = {
.queue_setup = queue_setup,
.buf_init = buffer_init,
@@ -650,8 +636,8 @@ static const struct vb2_ops bm2835_mmal_video_qops = {
.buf_queue = buffer_queue,
.start_streaming = start_streaming,
.stop_streaming = stop_streaming,
-   .wait_prepare = bm2835_mmal_unlock,
-   .wait_finish = bm2835_mmal_lock,
+   .wait_prepare = vb2_ops_wait_prepare,
+   .wait_finish = vb2_ops_wait_finish,
 };
 
 /* --
@@ -1864,6 +1850,8 @@ static int bcm2835_mmal_probe(struct platform_device 
*pdev)
goto cleanup_gdev;
}
 
+   /* v4l2 core mutex used to protect all fops and v4l2 ioctls. */
+   mutex_init(>mutex);
dev->camera_num = camera;
dev->max_width = resolutions[camera][0];
dev->max_height = resolutions[camera][1];
@@ -1908,13 +1896,11 @@ static int bcm2835_mmal_probe(struct platform_device 
*pdev)
q->ops = _mmal_video_qops;
q->mem_ops = _vmalloc_memops;
q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
+   q->lock = >mutex;
ret = vb2_queue_init(q);
if (ret < 0)
goto unreg_dev;
 
-   /* v4l2 core mutex used to protect all fops and v4l2 ioctls. */
-   mutex_init(>mutex);
-
/* initialise video devices */
ret = bm2835_mmal_init_device(dev, >vdev);
if (ret < 0)
-- 
2.17.1



[PATCH v4 11/17] m2m-deinterlace: Implement wait_prepare and wait_finish

2018-06-15 Thread Ezequiel Garcia
This driver is currently specifying a video_device lock,
which means it is protecting all the ioctls (including
queue ioctls) with a single mutex.

It's therefore straightforward to implement wait_prepare
and wait_finish, by explicitly setting the vb2_queue lock.

Having these callbacks releases the queue lock while blocking,
which improves latency by allowing for example streamoff
or qbuf operations while waiting in dqbuf.

Signed-off-by: Ezequiel Garcia 
---
 drivers/media/platform/m2m-deinterlace.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/media/platform/m2m-deinterlace.c 
b/drivers/media/platform/m2m-deinterlace.c
index 1e4195144f39..94dd8ec0f265 100644
--- a/drivers/media/platform/m2m-deinterlace.c
+++ b/drivers/media/platform/m2m-deinterlace.c
@@ -856,6 +856,8 @@ static const struct vb2_ops deinterlace_qops = {
.queue_setup = deinterlace_queue_setup,
.buf_prepare = deinterlace_buf_prepare,
.buf_queue   = deinterlace_buf_queue,
+   .wait_prepare= vb2_ops_wait_prepare,
+   .wait_finish = vb2_ops_wait_finish,
 };
 
 static int queue_init(void *priv, struct vb2_queue *src_vq,
@@ -872,6 +874,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
src_vq->mem_ops = _dma_contig_memops;
src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
src_vq->dev = ctx->dev->v4l2_dev.dev;
+   src_vq->lock = >dev->dev_mutex;
q_data[V4L2_M2M_SRC].fmt = [0];
q_data[V4L2_M2M_SRC].width = 640;
q_data[V4L2_M2M_SRC].height = 480;
@@ -890,6 +893,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
dst_vq->mem_ops = _dma_contig_memops;
dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
dst_vq->dev = ctx->dev->v4l2_dev.dev;
+   dst_vq->lock = >dev->dev_mutex;
q_data[V4L2_M2M_DST].fmt = [0];
q_data[V4L2_M2M_DST].width = 640;
q_data[V4L2_M2M_DST].height = 480;
-- 
2.17.1



[PATCH v4 08/17] venus: Add video_device and vb2_queue locks

2018-06-15 Thread Ezequiel Garcia
video_device and vb2_queue locks are now both
mandatory. Add them, remove driver ad-hoc locking,
and implement wait_{prepare, finish}.

To stay on the safe side, this commit uses a single mutex
for both locks. Better latency can be obtained by separating
these if needed.

Signed-off-by: Ezequiel Garcia 
---
 drivers/media/platform/qcom/venus/core.h|  4 +++-
 drivers/media/platform/qcom/venus/helpers.c | 16 ++---
 drivers/media/platform/qcom/venus/vdec.c| 25 +
 drivers/media/platform/qcom/venus/venc.c| 19 
 4 files changed, 30 insertions(+), 34 deletions(-)

diff --git a/drivers/media/platform/qcom/venus/core.h 
b/drivers/media/platform/qcom/venus/core.h
index 0360d295f4c8..5617d0af990f 100644
--- a/drivers/media/platform/qcom/venus/core.h
+++ b/drivers/media/platform/qcom/venus/core.h
@@ -102,6 +102,8 @@ struct venus_core {
struct device *dev_dec;
struct device *dev_enc;
struct mutex lock;
+   struct mutex dec_lock;
+   struct mutex enc_lock;
struct list_head instances;
atomic_t insts_count;
unsigned int state;
@@ -243,7 +245,7 @@ struct venus_buffer {
  */
 struct venus_inst {
struct list_head list;
-   struct mutex lock;
+   struct mutex *lock;
struct venus_core *core;
struct list_head internalbufs;
struct list_head registeredbufs;
diff --git a/drivers/media/platform/qcom/venus/helpers.c 
b/drivers/media/platform/qcom/venus/helpers.c
index 0ce9559a2924..5a2dda6fb984 100644
--- a/drivers/media/platform/qcom/venus/helpers.c
+++ b/drivers/media/platform/qcom/venus/helpers.c
@@ -512,7 +512,7 @@ static void delayed_process_buf_func(struct work_struct 
*work)
 
inst = container_of(work, struct venus_inst, delayed_process_work);
 
-   mutex_lock(>lock);
+   mutex_lock(inst->lock);
 
if (!(inst->streamon_out & inst->streamon_cap))
goto unlock;
@@ -528,7 +528,7 @@ static void delayed_process_buf_func(struct work_struct 
*work)
list_del_init(>ref_list);
}
 unlock:
-   mutex_unlock(>lock);
+   mutex_unlock(inst->lock);
 }
 
 void venus_helper_release_buf_ref(struct venus_inst *inst, unsigned int idx)
@@ -621,7 +621,7 @@ void venus_helper_vb2_buf_queue(struct vb2_buffer *vb)
struct v4l2_m2m_ctx *m2m_ctx = inst->m2m_ctx;
int ret;
 
-   mutex_lock(>lock);
+   mutex_lock(inst->lock);
 
v4l2_m2m_buf_queue(m2m_ctx, vbuf);
 
@@ -637,7 +637,7 @@ void venus_helper_vb2_buf_queue(struct vb2_buffer *vb)
return_buf_error(inst, vbuf);
 
 unlock:
-   mutex_unlock(>lock);
+   mutex_unlock(inst->lock);
 }
 EXPORT_SYMBOL_GPL(venus_helper_vb2_buf_queue);
 
@@ -659,7 +659,7 @@ void venus_helper_vb2_stop_streaming(struct vb2_queue *q)
struct venus_core *core = inst->core;
int ret;
 
-   mutex_lock(>lock);
+   mutex_lock(inst->lock);
 
if (inst->streamon_out & inst->streamon_cap) {
ret = hfi_session_stop(inst);
@@ -685,7 +685,7 @@ void venus_helper_vb2_stop_streaming(struct vb2_queue *q)
else
inst->streamon_cap = 0;
 
-   mutex_unlock(>lock);
+   mutex_unlock(inst->lock);
 }
 EXPORT_SYMBOL_GPL(venus_helper_vb2_stop_streaming);
 
@@ -731,7 +731,7 @@ void venus_helper_m2m_device_run(void *priv)
struct v4l2_m2m_buffer *buf, *n;
int ret;
 
-   mutex_lock(>lock);
+   mutex_lock(inst->lock);
 
v4l2_m2m_for_each_dst_buf_safe(m2m_ctx, buf, n) {
ret = session_process_buf(inst, >vb);
@@ -745,7 +745,7 @@ void venus_helper_m2m_device_run(void *priv)
return_buf_error(inst, >vb);
}
 
-   mutex_unlock(>lock);
+   mutex_unlock(inst->lock);
 }
 EXPORT_SYMBOL_GPL(venus_helper_m2m_device_run);
 
diff --git a/drivers/media/platform/qcom/venus/vdec.c 
b/drivers/media/platform/qcom/venus/vdec.c
index 49bbd1861d3a..41d14df46f5d 100644
--- a/drivers/media/platform/qcom/venus/vdec.c
+++ b/drivers/media/platform/qcom/venus/vdec.c
@@ -493,14 +493,12 @@ vdec_decoder_cmd(struct file *file, void *fh, struct 
v4l2_decoder_cmd *cmd)
if (ret)
return ret;
 
-   mutex_lock(>lock);
-
/*
 * Implement V4L2_DEC_CMD_STOP by enqueue an empty buffer on decoder
 * input to signal EOS.
 */
if (!(inst->streamon_out & inst->streamon_cap))
-   goto unlock;
+   return 0;
 
fdata.buffer_type = HFI_BUFFER_INPUT;
fdata.flags |= HFI_BUFFERFLAG_EOS;
@@ -508,8 +506,6 @@ vdec_decoder_cmd(struct file *file, void *fh, struct 
v4l2_decoder_cmd *cmd)
 
ret = hfi_session_process_buf(inst, );
 
-unlock:
-   mutex_unlock(>lock);
return ret;
 }
 
@@ -720,17 +716,13 @@ static int vdec_start_streaming(struct vb2_queue *q, 
unsigned int count)
u32 ptype;
int ret;
 
-   mutex_lock(>lock);
-
if (q->type == 

[PATCH v4 05/17] mtk-mdp: Add locks for capture and output vb2_queues

2018-06-15 Thread Ezequiel Garcia
Use the mutex in struct mtk_mdp_ctx to protect the
capture and output  vb2_queues. This allows to replace
the ad-hoc wait_{prepare, finish} with
vb2_ops_wait_{prepare, finish}.

Signed-off-by: Ezequiel Garcia 
---
 drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c | 20 
 1 file changed, 4 insertions(+), 16 deletions(-)

diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c 
b/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
index 583d47724ee8..c2e2f5f1ebf1 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
@@ -394,20 +394,6 @@ static bool mtk_mdp_ctx_state_is_set(struct mtk_mdp_ctx 
*ctx, u32 mask)
return ret;
 }
 
-static void mtk_mdp_ctx_lock(struct vb2_queue *vq)
-{
-   struct mtk_mdp_ctx *ctx = vb2_get_drv_priv(vq);
-
-   mutex_lock(>mdp_dev->lock);
-}
-
-static void mtk_mdp_ctx_unlock(struct vb2_queue *vq)
-{
-   struct mtk_mdp_ctx *ctx = vb2_get_drv_priv(vq);
-
-   mutex_unlock(>mdp_dev->lock);
-}
-
 static void mtk_mdp_set_frame_size(struct mtk_mdp_frame *frame, int width,
   int height)
 {
@@ -625,10 +611,10 @@ static const struct vb2_ops mtk_mdp_m2m_qops = {
.queue_setup = mtk_mdp_m2m_queue_setup,
.buf_prepare = mtk_mdp_m2m_buf_prepare,
.buf_queue   = mtk_mdp_m2m_buf_queue,
-   .wait_prepare= mtk_mdp_ctx_unlock,
-   .wait_finish = mtk_mdp_ctx_lock,
.stop_streaming  = mtk_mdp_m2m_stop_streaming,
.start_streaming = mtk_mdp_m2m_start_streaming,
+   .wait_prepare= vb2_ops_wait_prepare,
+   .wait_finish = vb2_ops_wait_finish,
 };
 
 static int mtk_mdp_m2m_querycap(struct file *file, void *fh,
@@ -996,6 +982,7 @@ static int mtk_mdp_m2m_queue_init(void *priv, struct 
vb2_queue *src_vq,
src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
src_vq->dev = >mdp_dev->pdev->dev;
+   src_vq->lock = >mdp_dev->lock;
 
ret = vb2_queue_init(src_vq);
if (ret)
@@ -1010,6 +997,7 @@ static int mtk_mdp_m2m_queue_init(void *priv, struct 
vb2_queue *src_vq,
dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
dst_vq->dev = >mdp_dev->pdev->dev;
+   dst_vq->lock = >mdp_dev->lock;
 
return vb2_queue_init(dst_vq);
 }
-- 
2.17.1



[PATCH v4 03/17] omap4iss: Add vb2_queue lock

2018-06-15 Thread Ezequiel Garcia
vb2_queue lock is now mandatory. Add it, remove driver ad-hoc
locks, and implement wait_{prepare, finish}.

Signed-off-by: Ezequiel Garcia 
---
 drivers/staging/media/omap4iss/iss_video.c | 13 ++---
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/media/omap4iss/iss_video.c 
b/drivers/staging/media/omap4iss/iss_video.c
index a3a83424a926..d919bae83828 100644
--- a/drivers/staging/media/omap4iss/iss_video.c
+++ b/drivers/staging/media/omap4iss/iss_video.c
@@ -873,8 +873,6 @@ iss_video_streamon(struct file *file, void *fh, enum 
v4l2_buf_type type)
if (type != video->type)
return -EINVAL;
 
-   mutex_lock(>stream_lock);
-
/*
 * Start streaming on the pipeline. No link touching an entity in the
 * pipeline can be activated or deactivated once streaming is started.
@@ -978,8 +976,6 @@ iss_video_streamon(struct file *file, void *fh, enum 
v4l2_buf_type type)
 
media_graph_walk_cleanup();
 
-   mutex_unlock(>stream_lock);
-
return 0;
 
 err_omap4iss_set_stream:
@@ -996,8 +992,6 @@ iss_video_streamon(struct file *file, void *fh, enum 
v4l2_buf_type type)
 err_graph_walk_init:
media_entity_enum_cleanup(>ent_enum);
 
-   mutex_unlock(>stream_lock);
-
return ret;
 }
 
@@ -1013,10 +1007,8 @@ iss_video_streamoff(struct file *file, void *fh, enum 
v4l2_buf_type type)
if (type != video->type)
return -EINVAL;
 
-   mutex_lock(>stream_lock);
-
if (!vb2_is_streaming(>queue))
-   goto done;
+   return 0;
 
/* Update the pipeline state. */
if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
@@ -1041,8 +1033,6 @@ iss_video_streamoff(struct file *file, void *fh, enum 
v4l2_buf_type type)
video->iss->pdata->set_constraints(video->iss, false);
media_pipeline_stop(>video.entity);
 
-done:
-   mutex_unlock(>stream_lock);
return 0;
 }
 
@@ -1137,6 +1127,7 @@ static int iss_video_open(struct file *file)
q->buf_struct_size = sizeof(struct iss_buffer);
q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
q->dev = video->iss->dev;
+   q->lock = >stream_lock;
 
ret = vb2_queue_init(q);
if (ret) {
-- 
2.17.1



[PATCH v4 09/17] davinci_vpfe: Add video_device and vb2_queue locks

2018-06-15 Thread Ezequiel Garcia
Currently, this driver does not serialize its video4linux
ioctls, which is a bug, as race conditions might appear.

In addition, video_device and vb2_queue locks are now both
mandatory. Add them, and implement wait_prepare and
wait_finish.

To stay on the safe side, this commit uses a single mutex
for both locks. Better latency can be obtained by separating
these if needed.

Signed-off-by: Ezequiel Garcia 
---
 drivers/staging/media/davinci_vpfe/vpfe_video.c | 6 +-
 drivers/staging/media/davinci_vpfe/vpfe_video.h | 2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c 
b/drivers/staging/media/davinci_vpfe/vpfe_video.c
index 390fc98d07dd..1269a983455e 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
+++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
@@ -1312,6 +1312,8 @@ static const struct vb2_ops video_qops = {
.stop_streaming = vpfe_stop_streaming,
.buf_cleanup= vpfe_buf_cleanup,
.buf_queue  = vpfe_buffer_queue,
+   .wait_prepare   = vb2_ops_wait_prepare,
+   .wait_finish= vb2_ops_wait_finish,
 };
 
 /*
@@ -1357,6 +1359,7 @@ static int vpfe_reqbufs(struct file *file, void *priv,
q->buf_struct_size = sizeof(struct vpfe_cap_buffer);
q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
q->dev = vpfe_dev->pdev;
+   q->lock = >lock;
 
ret = vb2_queue_init(q);
if (ret) {
@@ -1598,17 +1601,18 @@ int vpfe_video_init(struct vpfe_video_device *video, 
const char *name)
return -EINVAL;
}
/* Initialize field of video device */
+   mutex_init(>lock);
video->video_dev.release = video_device_release;
video->video_dev.fops = _fops;
video->video_dev.ioctl_ops = _ioctl_ops;
video->video_dev.minor = -1;
video->video_dev.tvnorms = 0;
+   video->video_dev.lock = >lock;
snprintf(video->video_dev.name, sizeof(video->video_dev.name),
 "DAVINCI VIDEO %s %s", name, direction);
 
spin_lock_init(>irqlock);
spin_lock_init(>dma_queue_lock);
-   mutex_init(>lock);
ret = media_entity_pads_init(>video_dev.entity,
1, >pad);
if (ret < 0)
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.h 
b/drivers/staging/media/davinci_vpfe/vpfe_video.h
index 22136d3dadcb..4bbd219e8329 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_video.h
+++ b/drivers/staging/media/davinci_vpfe/vpfe_video.h
@@ -128,7 +128,7 @@ struct vpfe_video_device {
spinlock_t  irqlock;
/* IRQ lock for DMA queue */
spinlock_t  dma_queue_lock;
-   /* lock used to access this structure */
+   /* lock used to serialize all video4linux ioctls */
struct mutexlock;
/* number of users performing IO */
u32 io_usrs;
-- 
2.17.1



[PATCH v4 10/17] mx_emmaprp: Implement wait_prepare and wait_finish

2018-06-15 Thread Ezequiel Garcia
This driver is currently specifying a video_device lock,
which means it is protecting all the ioctls (including
queue ioctls) with a single mutex.

It's therefore straightforward to implement wait_prepare
and wait_finish, by explicitly setting the vb2_queue lock.

Having these callbacks releases the queue lock while blocking,
which improves latency by allowing for example streamoff
or qbuf operations while waiting in dqbuf.

Signed-off-by: Ezequiel Garcia 
---
 drivers/media/platform/mx2_emmaprp.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/media/platform/mx2_emmaprp.c 
b/drivers/media/platform/mx2_emmaprp.c
index 5a8eff60e95f..7f9b356e7cc7 100644
--- a/drivers/media/platform/mx2_emmaprp.c
+++ b/drivers/media/platform/mx2_emmaprp.c
@@ -747,6 +747,8 @@ static const struct vb2_ops emmaprp_qops = {
.queue_setup = emmaprp_queue_setup,
.buf_prepare = emmaprp_buf_prepare,
.buf_queue   = emmaprp_buf_queue,
+   .wait_prepare= vb2_ops_wait_prepare,
+   .wait_finish = vb2_ops_wait_finish,
 };
 
 static int queue_init(void *priv, struct vb2_queue *src_vq,
@@ -763,6 +765,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
src_vq->mem_ops = _dma_contig_memops;
src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
src_vq->dev = ctx->dev->v4l2_dev.dev;
+   src_vq->lock = >dev->dev_mutex;
 
ret = vb2_queue_init(src_vq);
if (ret)
@@ -776,6 +779,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
dst_vq->mem_ops = _dma_contig_memops;
dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
dst_vq->dev = ctx->dev->v4l2_dev.dev;
+   dst_vq->lock = >dev->dev_mutex;
 
return vb2_queue_init(dst_vq);
 }
-- 
2.17.1



[PATCH v4 12/17] stk1160: Set the vb2_queue lock before calling vb2_queue_init

2018-06-15 Thread Ezequiel Garcia
The vb2_queue will soon be mandatory. The videobuf2 core
will throw a verbose warning if it's not set.

The stk1160 driver is setting the queue lock, but after
the vb2_queue_init call. Avoid the warning by setting
the lock before the queue initialization.

Signed-off-by: Ezequiel Garcia 
---
 drivers/media/usb/stk1160/stk1160-v4l.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/usb/stk1160/stk1160-v4l.c 
b/drivers/media/usb/stk1160/stk1160-v4l.c
index 77b759a0bcd9..504e413edcd2 100644
--- a/drivers/media/usb/stk1160/stk1160-v4l.c
+++ b/drivers/media/usb/stk1160/stk1160-v4l.c
@@ -802,6 +802,7 @@ int stk1160_vb2_setup(struct stk1160 *dev)
q->buf_struct_size = sizeof(struct stk1160_buffer);
q->ops = _video_qops;
q->mem_ops = _vmalloc_memops;
+   q->lock = >vb_queue_lock;
q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
 
rc = vb2_queue_init(q);
@@ -827,7 +828,6 @@ int stk1160_video_register(struct stk1160 *dev)
 * It will be used to protect *only* v4l2 ioctls.
 */
dev->vdev.lock = >v4l_lock;
-   dev->vdev.queue->lock = >vb_queue_lock;
 
/* This will be used to set video_device parent */
dev->vdev.v4l2_dev = >v4l2_dev;
-- 
2.17.1



[PATCH v4 02/17] sta2x11: Add video_device and vb2_queue locks

2018-06-15 Thread Ezequiel Garcia
Currently, this driver does not serialize its video4linux
ioctls, which is a bug, as race conditions might appear.

In addition, video_device and vb2_queue locks are now both
mandatory. Add them, and implement wait_prepare and
wait_finish.

To stay on the safe side, this commit uses a single mutex
for both locks. Better latency can be obtained by separating
these if needed.

Signed-off-by: Ezequiel Garcia 
---
 drivers/media/pci/sta2x11/sta2x11_vip.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/media/pci/sta2x11/sta2x11_vip.c 
b/drivers/media/pci/sta2x11/sta2x11_vip.c
index 069c4a853346..da2b2a2292d0 100644
--- a/drivers/media/pci/sta2x11/sta2x11_vip.c
+++ b/drivers/media/pci/sta2x11/sta2x11_vip.c
@@ -145,6 +145,7 @@ struct sta2x11_vip {
unsigned int sequence;
struct vip_buffer *active; /* current active buffer */
spinlock_t lock; /* Used in videobuf2 callback */
+   struct mutex v4l_lock;
 
/* Interrupt counters */
int tcount, bcount;
@@ -385,6 +386,8 @@ static const struct vb2_ops vip_video_qops = {
.buf_queue  = buffer_queue,
.start_streaming= start_streaming,
.stop_streaming = stop_streaming,
+   .wait_prepare   = vb2_ops_wait_prepare,
+   .wait_finish= vb2_ops_wait_finish,
 };
 
 
@@ -870,6 +873,7 @@ static int sta2x11_vip_init_buffer(struct sta2x11_vip *vip)
vip->vb_vidq.mem_ops = _dma_contig_memops;
vip->vb_vidq.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
vip->vb_vidq.dev = >pdev->dev;
+   vip->vb_vidq.lock = >v4l_lock;
err = vb2_queue_init(>vb_vidq);
if (err)
return err;
@@ -1034,6 +1038,7 @@ static int sta2x11_vip_init_one(struct pci_dev *pdev,
vip->std = V4L2_STD_PAL;
vip->format = formats_50[0];
vip->config = config;
+   mutex_init(>v4l_lock);
 
ret = sta2x11_vip_init_controls(vip);
if (ret)
@@ -1080,6 +1085,7 @@ static int sta2x11_vip_init_one(struct pci_dev *pdev,
vip->video_dev = video_dev_template;
vip->video_dev.v4l2_dev = >v4l2_dev;
vip->video_dev.queue = >vb_vidq;
+   vip->video_dev.lock = >v4l_lock;
video_set_drvdata(>video_dev, vip);
 
ret = video_register_device(>video_dev, VFL_TYPE_GRABBER, -1);
-- 
2.17.1



[PATCH v4 01/17] v4l2-ioctl.c: use correct vb2_queue lock for m2m devices

2018-06-15 Thread Ezequiel Garcia
From: Hans Verkuil 

For m2m devices the vdev->queue lock was always taken instead of the
lock for the specific capture or output queue. Now that we pushed
the locking down into __video_do_ioctl() we can pick the correct
lock and improve the performance of m2m devices.

Signed-off-by: Hans Verkuil 
---
 drivers/media/v4l2-core/v4l2-ioctl.c | 59 ++--
 1 file changed, 55 insertions(+), 4 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
b/drivers/media/v4l2-core/v4l2-ioctl.c
index dd210067151f..db835578e21f 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -29,6 +29,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -2662,11 +2663,62 @@ static bool v4l2_is_known_ioctl(unsigned int cmd)
return v4l2_ioctls[_IOC_NR(cmd)].ioctl == cmd;
 }
 
+#if IS_ENABLED(CONFIG_V4L2_MEM2MEM_DEV)
+static bool v4l2_ioctl_m2m_queue_is_output(unsigned int cmd, void *arg)
+{
+   switch (cmd) {
+   case VIDIOC_CREATE_BUFS: {
+   struct v4l2_create_buffers *cbufs = arg;
+
+   return V4L2_TYPE_IS_OUTPUT(cbufs->format.type);
+   }
+   case VIDIOC_REQBUFS: {
+   struct v4l2_requestbuffers *rbufs = arg;
+
+   return V4L2_TYPE_IS_OUTPUT(rbufs->type);
+   }
+   case VIDIOC_QBUF:
+   case VIDIOC_DQBUF:
+   case VIDIOC_QUERYBUF:
+   case VIDIOC_PREPARE_BUF: {
+   struct v4l2_buffer *buf = arg;
+
+   return V4L2_TYPE_IS_OUTPUT(buf->type);
+   }
+   case VIDIOC_EXPBUF: {
+   struct v4l2_exportbuffer *expbuf = arg;
+
+   return V4L2_TYPE_IS_OUTPUT(expbuf->type);
+   }
+   case VIDIOC_STREAMON:
+   case VIDIOC_STREAMOFF: {
+   int *type = arg;
+
+   return V4L2_TYPE_IS_OUTPUT(*type);
+   }
+   default:
+   return false;
+   }
+}
+#endif
+
 static struct mutex *v4l2_ioctl_get_lock(struct video_device *vdev,
-unsigned int cmd)
+struct v4l2_fh *vfh, unsigned cmd,
+void *arg)
 {
if (_IOC_NR(cmd) >= V4L2_IOCTLS)
return vdev->lock;
+#if IS_ENABLED(CONFIG_V4L2_MEM2MEM_DEV)
+   if (vfh && vfh->m2m_ctx &&
+   (v4l2_ioctls[_IOC_NR(cmd)].flags & INFO_FL_QUEUE)) {
+   bool is_output = v4l2_ioctl_m2m_queue_is_output(cmd, arg);
+   struct v4l2_m2m_queue_ctx *ctx = is_output ?
+   >m2m_ctx->out_q_ctx : >m2m_ctx->cap_q_ctx;
+
+   if (ctx->q.lock)
+   return ctx->q.lock;
+   }
+#endif
if (vdev->queue && vdev->queue->lock &&
(v4l2_ioctls[_IOC_NR(cmd)].flags & INFO_FL_QUEUE))
return vdev->queue->lock;
@@ -2714,7 +2766,7 @@ static long __video_do_ioctl(struct file *file,
unsigned int cmd, void *arg)
 {
struct video_device *vfd = video_devdata(file);
-   struct mutex *lock; /* ioctl serialization mutex */
+   struct mutex *lock;
const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
bool write_only = false;
struct v4l2_ioctl_info default_info;
@@ -2733,8 +2785,7 @@ static long __video_do_ioctl(struct file *file,
if (test_bit(V4L2_FL_USES_V4L2_FH, >flags))
vfh = file->private_data;
 
-   lock = v4l2_ioctl_get_lock(vfd, cmd);
-
+   lock = v4l2_ioctl_get_lock(vfd, vfh, cmd, arg);
if (lock && mutex_lock_interruptible(lock))
return -ERESTARTSYS;
 
-- 
2.17.1



[PATCH v4 00/17] v4l2 core: push ioctl lock down to ioctl handler

2018-06-15 Thread Ezequiel Garcia
Fourth spin of the series posted by Hans:

https://www.mail-archive.com/linux-media@vger.kernel.org/msg131363.html

There aren't any changes from v3, aside from rebasing
and re-ordering the patches as requested by Hans.

See v3 cover letter for more details.

Series was tested with tw686x, gspca sonixj and UVC devices.
Build tested with the 0-day kbuild test robot.

Changelog
-

v4:
Rebased on top of today's next.

v3:
Reduce changes in patches 6 and 7 for omap3isp and omap4iss
drivers, as suggested by Hans.

v2:
Add the required driver modifications, fixing all
drivers so they define a proper vb2_queue lock.

Ezequiel Garcia (13):
  sta2x11: Add video_device and vb2_queue locks
  omap4iss: Add vb2_queue lock
  omap3isp: Add vb2_queue lock
  mtk-mdp: Add locks for capture and output vb2_queues
  s5p-g2d: Implement wait_prepare and wait_finish
  staging: bcm2835-camera: Provide lock for vb2_queue
  venus: Add video_device and vb2_queue locks
  davinci_vpfe: Add video_device and vb2_queue locks
  mx_emmaprp: Implement wait_prepare and wait_finish
  m2m-deinterlace: Implement wait_prepare and wait_finish
  stk1160: Set the vb2_queue lock before calling vb2_queue_init
  dvb-core: Provide lock for vb2_queue
  media: Remove wait_{prepare, finish}

Hans Verkuil (4):
  v4l2-ioctl.c: use correct vb2_queue lock for m2m devices
  videobuf2-core: require q->lock
  videobuf2: assume q->lock is always set
  v4l2-ioctl.c: assume queue->lock is always set

 Documentation/media/kapi/v4l2-dev.rst |  7 +--
 drivers/input/rmi4/rmi_f54.c  |  2 -
 drivers/input/touchscreen/atmel_mxt_ts.c  |  2 -
 drivers/input/touchscreen/sur40.c |  2 -
 .../media/common/videobuf2/videobuf2-core.c   | 22 +++
 .../media/common/videobuf2/videobuf2-v4l2.c   | 41 +++-
 drivers/media/dvb-core/dvb_vb2.c  | 20 +-
 drivers/media/dvb-frontends/rtl2832_sdr.c |  2 -
 drivers/media/i2c/video-i2c.c |  2 -
 drivers/media/pci/cobalt/cobalt-v4l2.c|  2 -
 drivers/media/pci/cx23885/cx23885-417.c   |  2 -
 drivers/media/pci/cx23885/cx23885-dvb.c   |  2 -
 drivers/media/pci/cx23885/cx23885-vbi.c   |  2 -
 drivers/media/pci/cx23885/cx23885-video.c |  2 -
 drivers/media/pci/cx25821/cx25821-video.c |  2 -
 drivers/media/pci/cx88/cx88-blackbird.c   |  2 -
 drivers/media/pci/cx88/cx88-dvb.c |  2 -
 drivers/media/pci/cx88/cx88-vbi.c |  2 -
 drivers/media/pci/cx88/cx88-video.c   |  2 -
 drivers/media/pci/dt3155/dt3155.c |  2 -
 drivers/media/pci/intel/ipu3/ipu3-cio2.c  |  2 -
 drivers/media/pci/saa7134/saa7134-empress.c   |  2 -
 drivers/media/pci/saa7134/saa7134-ts.c|  2 -
 drivers/media/pci/saa7134/saa7134-vbi.c   |  2 -
 drivers/media/pci/saa7134/saa7134-video.c |  2 -
 .../media/pci/solo6x10/solo6x10-v4l2-enc.c|  2 -
 drivers/media/pci/solo6x10/solo6x10-v4l2.c|  2 -
 drivers/media/pci/sta2x11/sta2x11_vip.c   |  4 ++
 drivers/media/pci/tw5864/tw5864-video.c   |  2 -
 drivers/media/pci/tw68/tw68-video.c   |  2 -
 drivers/media/pci/tw686x/tw686x-video.c   |  2 -
 drivers/media/platform/am437x/am437x-vpfe.c   |  2 -
 drivers/media/platform/atmel/atmel-isc.c  |  2 -
 drivers/media/platform/atmel/atmel-isi.c  |  2 -
 drivers/media/platform/coda/coda-common.c |  2 -
 drivers/media/platform/davinci/vpbe_display.c |  2 -
 drivers/media/platform/davinci/vpif_capture.c |  2 -
 drivers/media/platform/davinci/vpif_display.c |  2 -
 drivers/media/platform/exynos-gsc/gsc-m2m.c   |  2 -
 .../media/platform/exynos4-is/fimc-capture.c  |  2 -
 .../platform/exynos4-is/fimc-isp-video.c  |  2 -
 drivers/media/platform/exynos4-is/fimc-lite.c |  2 -
 drivers/media/platform/exynos4-is/fimc-m2m.c  |  2 -
 drivers/media/platform/m2m-deinterlace.c  |  2 +
 .../media/platform/marvell-ccic/mcam-core.c   |  4 --
 .../media/platform/mtk-jpeg/mtk_jpeg_core.c   |  2 -
 drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c  | 18 +-
 .../platform/mtk-vcodec/mtk_vcodec_dec.c  |  2 -
 .../platform/mtk-vcodec/mtk_vcodec_enc.c  |  2 -
 drivers/media/platform/mx2_emmaprp.c  |  2 +
 drivers/media/platform/omap3isp/ispvideo.c| 63 +++
 drivers/media/platform/omap3isp/ispvideo.h|  1 -
 drivers/media/platform/pxa_camera.c   |  2 -
 .../platform/qcom/camss-8x16/camss-video.c|  2 -
 drivers/media/platform/qcom/venus/core.h  |  4 +-
 drivers/media/platform/qcom/venus/helpers.c   | 16 ++---
 drivers/media/platform/qcom/venus/vdec.c  | 23 +++
 drivers/media/platform/qcom/venus/venc.c  | 17 +++--
 drivers/media/platform/rcar-vin/rcar-dma.c|  2 -
 drivers/media/platform/rcar_drif.c|  2 -
 drivers/media/platform/rcar_fdp1.c|  2 -
 drivers/media/platform/rcar_jpu.c |  2 -
 drivers/media/platform/renesas-ceu.c  |  2 -
 drivers/media/platform/rockchip/rga/rga-buf.c |  2 -
 

Re: [RFC 1/2] media: add helpers for memory-to-memory media controller

2018-06-15 Thread Ezequiel Garcia
Hi Hans,

Thanks for the review.

On Fri, 2018-06-15 at 11:24 +0200, Hans Verkuil wrote:
> On 12/06/18 12:48, Ezequiel Garcia wrote:
> > A memory-to-memory pipeline device consists in three
> > entities: two DMA engine and one video processing entities.
> > The DMA engine entities are linked to a V4L interface.
> > 
> > This commit add a new v4l2_m2m_{un}register_media_controller
> > API to register this topology.
> > 
> > For instance, a typical mem2mem device topology would
> > look like this:
> > 
> > - entity 1: input (1 pad, 1 link)
> > type Node subtype Unknown flags 0
> > pad0: Source
> > -> "proc":1 [ENABLED,IMMUTABLE]
> > 
> > - entity 3: proc (2 pads, 2 links)
> > type Node subtype Unknown flags 0
> > pad0: Source
> > -> "output":0 [ENABLED,IMMUTABLE]
> > pad1: Sink
> > <- "input":0 [ENABLED,IMMUTABLE]
> > 
> > - entity 6: output (1 pad, 1 link)
> > type Node subtype Unknown flags 0
> > pad0: Sink
> > <- "proc":0 [ENABLED,IMMUTABLE]
> > 
> > Suggested-by: Laurent Pinchart 
> > Suggested-by: Hans Verkuil 
> > Signed-off-by: Ezequiel Garcia 
> > ---
> >  drivers/media/v4l2-core/v4l2-dev.c |  23 ++--
> >  drivers/media/v4l2-core/v4l2-mem2mem.c | 157 +
> >  include/media/media-entity.h   |   4 +
> >  include/media/v4l2-dev.h   |   2 +
> >  include/media/v4l2-mem2mem.h   |   5 +
> >  include/uapi/linux/media.h |   2 +
> >  6 files changed, 186 insertions(+), 7 deletions(-)
> > 
> > diff --git a/drivers/media/v4l2-core/v4l2-dev.c 
> > b/drivers/media/v4l2-core/v4l2-dev.c
> > index 4ffd7d60a901..ec8f20f0fdc5 100644
> > --- a/drivers/media/v4l2-core/v4l2-dev.c
> > +++ b/drivers/media/v4l2-core/v4l2-dev.c
> > @@ -202,7 +202,7 @@ static void v4l2_device_release(struct device *cd)
> > mutex_unlock(_lock);
> >  
> >  #if defined(CONFIG_MEDIA_CONTROLLER)
> > -   if (v4l2_dev->mdev) {
> > +   if (v4l2_dev->mdev && vdev->vfl_type != VFL_TYPE_MEM2MEM) {
> 
> As mentioned this should be vfl_dir != VFL_DIR_M2M. No need for a new 
> VFL_TYPE.
> 

Right.

> > /* Remove interfaces and interface links */
> > media_devnode_remove(vdev->intf_devnode);
> > if (vdev->entity.function != MEDIA_ENT_F_UNKNOWN)
> > @@ -530,6 +530,7 @@ static void determine_valid_ioctls(struct video_device 
> > *vdev)
> > bool is_radio = vdev->vfl_type == VFL_TYPE_RADIO;
> > bool is_sdr = vdev->vfl_type == VFL_TYPE_SDR;
> > bool is_tch = vdev->vfl_type == VFL_TYPE_TOUCH;
> > +   bool is_m2m = vdev->vfl_type == VFL_TYPE_MEM2MEM;
> 
> And that means that this is also no longer needed.
> 

Right, it should be simplified a lot. I hated to introduce
a new type, just thought it was the cleaner way.

> > bool is_rx = vdev->vfl_dir != VFL_DIR_TX;
> > bool is_tx = vdev->vfl_dir != VFL_DIR_RX;
> >  
> > @@ -576,7 +577,7 @@ static void determine_valid_ioctls(struct video_device 
> > *vdev)
> > if (ops->vidioc_enum_freq_bands || ops->vidioc_g_tuner || 
> > ops->vidioc_g_modulator)
> > set_bit(_IOC_NR(VIDIOC_ENUM_FREQ_BANDS), valid_ioctls);
> >  
> > -   if (is_vid || is_tch) {
> > +   if (is_vid || is_m2m || is_tch) {
> > /* video and metadata specific ioctls */
> > if ((is_rx && (ops->vidioc_enum_fmt_vid_cap ||
> >ops->vidioc_enum_fmt_vid_cap_mplane ||
> > @@ -669,7 +670,7 @@ static void determine_valid_ioctls(struct video_device 
> > *vdev)
> > set_bit(_IOC_NR(VIDIOC_TRY_FMT), valid_ioctls);
> > }
> >  
> > -   if (is_vid || is_vbi || is_sdr || is_tch) {
> > +   if (is_vid || is_m2m || is_vbi || is_sdr || is_tch) {
> > /* ioctls valid for video, metadata, vbi or sdr */
> > SET_VALID_IOCTL(ops, VIDIOC_REQBUFS, vidioc_reqbufs);
> > SET_VALID_IOCTL(ops, VIDIOC_QUERYBUF, vidioc_querybuf);
> > @@ -682,7 +683,7 @@ static void determine_valid_ioctls(struct video_device 
> > *vdev)
> > SET_VALID_IOCTL(ops, VIDIOC_STREAMOFF, vidioc_streamoff);
> > }
> >  
> > -   if (is_vid || is_vbi || is_tch) {
> > +   if (is_vid || is_m2m || is_vbi || is_tch) {
> > /* ioctls valid for video or vbi */
> > if (ops->vidioc_s_std)
> > set_bit(_IOC_NR(VIDIOC_ENUMSTD), valid_ioctls);
> > @@ -733,7 +734,7 @@ static void determine_valid_ioctls(struct video_device 
> > *vdev)
> > BASE_VIDIOC_PRIVATE);
> >  }
> >  
> > -static int video_register_media_controller(struct video_device *vdev, int 
> > type)
> > +static int video_register_media_controller(struct video_device *vdev)
> >  {
> >  #if defined(CONFIG_MEDIA_CONTROLLER)
> > u32 intf_type;
> > @@ -745,7 +746,7 @@ static int video_register_media_controller(struct 
> > video_device *vdev, int type)
> > vdev->entity.obj_type = MEDIA_ENTITY_TYPE_VIDEO_DEVICE;
> > vdev->entity.function = 

[PATCH 3/3] media.h: remove __NEED_MEDIA_LEGACY_API

2018-06-15 Thread Hans Verkuil
From: Hans Verkuil 

The __NEED_MEDIA_LEGACY_API define is 1) ugly and 2) dangerous
since it is all too easy for drivers to define it to get hold of
legacy defines. Instead just define what we need in media-device.c
which is the only place where we need the legacy define
(MEDIA_ENT_T_DEVNODE_UNKNOWN).

Signed-off-by: Hans Verkuil 
---
 drivers/media/media-device.c | 13 ++---
 include/uapi/linux/media.h   |  2 +-
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index ae59c3177555..47bb2254fbfd 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -16,9 +16,6 @@
  * GNU General Public License for more details.
  */
 
-/* We need to access legacy defines from linux/media.h */
-#define __NEED_MEDIA_LEGACY_API
-
 #include 
 #include 
 #include 
@@ -35,6 +32,16 @@
 
 #ifdef CONFIG_MEDIA_CONTROLLER
 
+/*
+ * Legacy defines from linux/media.h. This is the only place we need this
+ * so we just define it here. The media.h header doesn't expose it to the
+ * kernel to prevent it from being used by drivers, but here (and only here!)
+ * we need it to handle the legacy behavior.
+ */
+#define MEDIA_ENT_SUBTYPE_MASK 0x
+#define MEDIA_ENT_T_DEVNODE_UNKNOWN(MEDIA_ENT_F_OLD_BASE | \
+MEDIA_ENT_SUBTYPE_MASK)
+
 /* 
-
  * Userspace API
  */
diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
index c7e9a5cba24e..86c7dcc9cba3 100644
--- a/include/uapi/linux/media.h
+++ b/include/uapi/linux/media.h
@@ -348,7 +348,7 @@ struct media_v2_topology {
 #define MEDIA_IOC_SETUP_LINK   _IOWR('|', 0x03, struct media_link_desc)
 #define MEDIA_IOC_G_TOPOLOGY   _IOWR('|', 0x04, struct media_v2_topology)
 
-#if !defined(__KERNEL__) || defined(__NEED_MEDIA_LEGACY_API)
+#ifndef __KERNEL__
 
 /*
  * Legacy symbols used to avoid userspace compilation breakages.
-- 
2.17.0



[PATCH 0/3] media: doc fixes, drop __NEED_MEDIA_LEGACY_API

2018-06-15 Thread Hans Verkuil
From: Hans Verkuil 

This patch series drops the '-  .. row 1' lines in the mediactl
documentation (the last media docs that used this), fixes incorrect
types in subdev-formats.rst and removes the __NEED_MEDIA_LEGACY_API
define.

The last two patches were also the first two patches in this older
patch series:

https://www.mail-archive.com/linux-media@vger.kernel.org/msg129417.html

These three should be uncontroversial and they simplify the other
media patches in that older patch series.

Regards,

Hans

Hans Verkuil (3):
  Documentation/media/uapi/mediactl: redo tables
  subdev-formats.rst: fix incorrect types
  media.h: remove __NEED_MEDIA_LEGACY_API

 .../uapi/mediactl/media-ioc-device-info.rst   |  48 +-
 .../uapi/mediactl/media-ioc-enum-entities.rst |  83 +--
 .../uapi/mediactl/media-ioc-enum-links.rst|  70 +--
 .../uapi/mediactl/media-ioc-g-topology.rst| 204 ++-
 .../media/uapi/mediactl/media-types.rst   | 499 +-
 .../media/uapi/v4l/subdev-formats.rst |  15 +-
 drivers/media/media-device.c  |  13 +-
 include/uapi/linux/media.h|   2 +-
 8 files changed, 205 insertions(+), 729 deletions(-)

-- 
2.17.0



[PATCH 2/3] subdev-formats.rst: fix incorrect types

2018-06-15 Thread Hans Verkuil
From: Hans Verkuil 

The ycbcr_enc, quantization and xfer_func fields are __u16 and not enums.

Signed-off-by: Hans Verkuil 
---
 Documentation/media/uapi/v4l/subdev-formats.rst | 15 +--
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/Documentation/media/uapi/v4l/subdev-formats.rst 
b/Documentation/media/uapi/v4l/subdev-formats.rst
index 9fcabe7f9367..a4739f79d9c3 100644
--- a/Documentation/media/uapi/v4l/subdev-formats.rst
+++ b/Documentation/media/uapi/v4l/subdev-formats.rst
@@ -37,19 +37,22 @@ Media Bus Formats
   - Image colorspace, from enum
:c:type:`v4l2_colorspace`. See
:ref:`colorspaces` for details.
-* - enum :c:type:`v4l2_ycbcr_encoding`
+* - __u16
   - ``ycbcr_enc``
-  - This information supplements the ``colorspace`` and must be set by
+  - Y'CbCr encoding, from enum :c:type:`v4l2_ycbcr_encoding`.
+This information supplements the ``colorspace`` and must be set by
the driver for capture streams and by the application for output
streams, see :ref:`colorspaces`.
-* - enum :c:type:`v4l2_quantization`
+* - __u16
   - ``quantization``
-  - This information supplements the ``colorspace`` and must be set by
+  - Quantization range, from enum :c:type:`v4l2_quantization`.
+This information supplements the ``colorspace`` and must be set by
the driver for capture streams and by the application for output
streams, see :ref:`colorspaces`.
-* - enum :c:type:`v4l2_xfer_func`
+* - __u16
   - ``xfer_func``
-  - This information supplements the ``colorspace`` and must be set by
+  - Transfer function, from enum :c:type:`v4l2_xfer_func`.
+This information supplements the ``colorspace`` and must be set by
the driver for capture streams and by the application for output
streams, see :ref:`colorspaces`.
 * - __u16
-- 
2.17.0



[PATCH 1/3] Documentation/media/uapi/mediactl: redo tables

2018-06-15 Thread Hans Verkuil
From: Hans Verkuil 

Drop the '-  .. row 1' lines to make it easier to add new rows to
the tables in the future without having to renumber these lines.

Signed-off-by: Hans Verkuil 
---
 .../uapi/mediactl/media-ioc-device-info.rst   |  48 +-
 .../uapi/mediactl/media-ioc-enum-entities.rst |  83 +--
 .../uapi/mediactl/media-ioc-enum-links.rst|  70 +--
 .../uapi/mediactl/media-ioc-g-topology.rst| 204 ++-
 .../media/uapi/mediactl/media-types.rst   | 499 +-
 5 files changed, 185 insertions(+), 719 deletions(-)

diff --git a/Documentation/media/uapi/mediactl/media-ioc-device-info.rst 
b/Documentation/media/uapi/mediactl/media-ioc-device-info.rst
index f690f9afc470..649cb3d9e058 100644
--- a/Documentation/media/uapi/mediactl/media-ioc-device-info.rst
+++ b/Documentation/media/uapi/mediactl/media-ioc-device-info.rst
@@ -48,12 +48,8 @@ ioctl never fails.
 :widths:   1 1 2
 
 
--  .. row 1
-
-   -  char
-
+*  -  char
-  ``driver``\ [16]
-
-  Name of the driver implementing the media API as a NUL-terminated
  ASCII string. The driver version is stored in the
  ``driver_version`` field.
@@ -62,66 +58,38 @@ ioctl never fails.
  the driver identity. It is also useful to work around known bugs,
  or to identify drivers in error reports.
 
--  .. row 2
-
-   -  char
-
+*  -  char
-  ``model``\ [32]
-
-  Device model name as a NUL-terminated UTF-8 string. The device
  version is stored in the ``device_version`` field and is not be
  appended to the model name.
 
--  .. row 3
-
-   -  char
-
+*  -  char
-  ``serial``\ [40]
-
-  Serial number as a NUL-terminated ASCII string.
 
--  .. row 4
-
-   -  char
-
+*  -  char
-  ``bus_info``\ [32]
-
-  Location of the device in the system as a NUL-terminated ASCII
  string. This includes the bus type name (PCI, USB, ...) and a
  bus-specific identifier.
 
--  .. row 5
-
-   -  __u32
-
+*  -  __u32
-  ``media_version``
-
-  Media API version, formatted with the ``KERNEL_VERSION()`` macro.
 
--  .. row 6
-
-   -  __u32
-
+*  -  __u32
-  ``hw_revision``
-
-  Hardware device revision in a driver-specific format.
 
--  .. row 7
-
-   -  __u32
-
+*  -  __u32
-  ``driver_version``
-
-  Media device driver version, formatted with the
  ``KERNEL_VERSION()`` macro. Together with the ``driver`` field
  this identifies a particular driver.
 
--  .. row 8
-
-   -  __u32
-
+*  -  __u32
-  ``reserved``\ [31]
-
-  Reserved for future extensions. Drivers and applications must set
  this array to zero.
 
diff --git a/Documentation/media/uapi/mediactl/media-ioc-enum-entities.rst 
b/Documentation/media/uapi/mediactl/media-ioc-enum-entities.rst
index 582fda488810..961466ae821d 100644
--- a/Documentation/media/uapi/mediactl/media-ioc-enum-entities.rst
+++ b/Documentation/media/uapi/mediactl/media-ioc-enum-entities.rst
@@ -58,142 +58,87 @@ id's until they get an error.
 :stub-columns: 0
 :widths: 1 1 1 1 8
 
-
--  .. row 1
-
-   -  __u32
-
+*  -  __u32
-  ``id``
-
-
-
-  Entity id, set by the application. When the id is or'ed with
  ``MEDIA_ENT_ID_FLAG_NEXT``, the driver clears the flag and returns
  the first entity with a larger id.
 
--  .. row 2
-
-   -  char
-
+*  -  char
-  ``name``\ [32]
-
-
-
-  Entity name as an UTF-8 NULL-terminated string.
 
--  .. row 3
-
-   -  __u32
-
+*  -  __u32
-  ``type``
-
-
-
-  Entity type, see :ref:`media-entity-functions` for details.
 
--  .. row 4
-
-   -  __u32
-
+*  -  __u32
-  ``revision``
-
-
-
-  Entity revision. Always zero (obsolete)
 
--  .. row 5
-
-   -  __u32
-
+*  -  __u32
-  ``flags``
-
-
-
-  Entity flags, see :ref:`media-entity-flag` for details.
 
--  .. row 6
-
-   -  __u32
-
+*  -  __u32
-  ``group_id``
-
-
-
-  Entity group ID. Always zero (obsolete)
 
--  .. row 7
-
-   -  __u16
-
+*  -  __u16
-  ``pads``
-
-
-
-  Number of pads
 
--  .. row 8
-
-   -  __u16
-
+*  -  __u16
-  ``links``
-
-
-
-  Total number of outbound links. Inbound links are not counted in
  this field.
 
--  .. row 9
-
-   -  __u32
-
+*  -  __u32
-  ``reserved[4]``
-
-
-
-  Reserved for future extensions. Drivers and applications must set
   the array to zero.
 
--  .. row 10
-
-   -  union
-
--  .. row 11
+*  -  union
 
-   -
+*  -
-  struct
-
-  ``dev``
-
 

Re: [PATCHv2 6/9] media: add 'index' to struct media_v2_pad

2018-06-15 Thread Hans Verkuil
On 17/04/18 14:19, Hans Verkuil wrote:
> On 04/17/18 14:16, Mauro Carvalho Chehab wrote:
>> Em Tue, 17 Apr 2018 14:01:06 +0200
>> Hans Verkuil  escreveu:
>>
>>> On 04/17/18 13:55, Mauro Carvalho Chehab wrote:
 Em Tue, 17 Apr 2018 11:59:40 +0200
 Hans Verkuil  escreveu:
   
> On 04/16/18 21:41, Hans Verkuil wrote:  
>> On 04/16/2018 08:09 PM, Mauro Carvalho Chehab wrote:
>>> Em Mon, 16 Apr 2018 15:03:35 -0300
>>> Mauro Carvalho Chehab  escreveu:
>>>
 Em Mon, 16 Apr 2018 15:21:18 +0200
 Hans Verkuil  escreveu:

> From: Hans Verkuil 
>
> The v2 pad structure never exposed the pad index, which made it 
> impossible
> to call the MEDIA_IOC_SETUP_LINK ioctl, which needs that information.
>
> It is really trivial to just expose this information, so implement 
> this.  

 Acked-by: Mauro Carvalho Chehab 
>>>
>>> Err... I looked on it too fast... See my comments below.
>>>
>>> The same applies to patch 8/9.
>>>
>
> Signed-off-by: Hans Verkuil 
> ---
>  drivers/media/media-device.c | 1 +
>  include/uapi/linux/media.h   | 7 ++-
>  2 files changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/media/media-device.c 
> b/drivers/media/media-device.c
> index dca1e5a3e0f9..73ffea3e81c9 100644
> --- a/drivers/media/media-device.c
> +++ b/drivers/media/media-device.c
> @@ -331,6 +331,7 @@ static long media_device_get_topology(struct 
> media_device *mdev,
>   kpad.id = pad->graph_obj.id;
>   kpad.entity_id = pad->entity->graph_obj.id;
>   kpad.flags = pad->flags;
> + kpad.index = pad->index;
>  
>   if (copy_to_user(upad, , sizeof(kpad)))
>   ret = -EFAULT;
> diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> index ac08acffdb65..15f7f432f808 100644
> --- a/include/uapi/linux/media.h
> +++ b/include/uapi/linux/media.h
> @@ -310,11 +310,16 @@ struct media_v2_interface {
>   };
>  } __attribute__ ((packed));
>  
> +/* Appeared in 4.18.0 */
> +#define MEDIA_V2_PAD_HAS_INDEX(media_version) \
> + ((media_version) >= 0x00041200)
> +
>>>
>>> I don't like this, for a couple of reasons:
>>>
>>> 1) it has a magic number on it, with is actually a parsed
>>>version of LINUX_VERSION() macro;
>>
>> I can/should change that to KERNEL_VERSION().  

 I don't think so. The macro is not there at include/uapi.
   
>> 
>>>
>>> 2) it sounds really weird to ship a header file with a new
>>>kernel version meant to provide backward compatibility with
>>>older versions;
>>>
>>> 3) this isn't any different than:
>>>
>>> #define MEDIA_V2_PAD_HAS_INDEX -1
>>>
>>> I think we need to think a little bit more about that.
>>
>> What typically happens is that applications (like those in v4l-utils
>> for example) copy the headers locally. So they are compiled with the 
>> headers
>> of a specific kernel version, but they can run with very different 
>> kernels.
>>
>> This is normal for distros where you can install different kernel 
>> versions
>> without needing to modify applications.
>>
>> In fact, we (Cisco) use the latest v4l-utils code on kernels ranging 
>> between
>> 2.6.39 to 4.10 (I think that's the latest one in use).  

 Well, if you use a macro, the "compat" code at v4l-utils (or whatever other
 app you use) will be assuming the specific Kernel version you used when you
 built it, with is probably not what you want.

 The way of checking if a feature is there or not is, instead, to ask for
 the media version via MEDIA_IOC_DEVICE_INFO. It should provide the
 media API version.

 This is already filled with:
info->media_version = LINUX_VERSION_CODE;

 So, all we need to do is to document that the new fields are available only
 for such version or above and add such check at v4l-utils.  
>>>
>>> Yes, and that's what you stick in the macro argument:
>>>
>>> ioctl(fd, MEDIA_IOC_DEVICE_INFO, );
>>> if (MEDIA_V2_PAD_HAS_INDEX(info.media_version)) {
>>> // I can use the index field
>>> }
>>>
>>> I think I did not document this clearly.
>>
>> Ok, makes sense. It should be better documented, IMO.
>>
>> Still have an issue with KERNEL_VERSION: this macro doesn't exist
>> anymore on any Kernel header files. It is produced dynamically
>> at /Makefile:
>>
>>  define filechk_version.h
>>  (echo \#define LINUX_VERSION_CODE $(shell   

Re: [RFC 0/2] Memory-to-memory media controller topology

2018-06-15 Thread Ezequiel Garcia
On Fri, 2018-06-15 at 10:59 +0200, Hans Verkuil wrote:
> On 12/06/18 12:48, Ezequiel Garcia wrote:
> > As discussed on IRC, memory-to-memory need to be modeled
> > properly in order to be supported by the media controller
> > framework, and thus to support the Request API.
> > 
> > This RFC is a first draft on the memory-to-memory
> > media controller topology.
> > 
> > The topology looks like this:
> > 
> > Device topology
> > - entity 1: input (1 pad, 1 link)
> > type Node subtype Unknown flags 0
> > pad0: Source
> > -> "proc":1 [ENABLED,IMMUTABLE]
> > 
> > - entity 3: proc (2 pads, 2 links)
> > type Node subtype Unknown flags 0
> > pad0: Source
> > -> "output":0 [ENABLED,IMMUTABLE]
> > pad1: Sink
> > <- "input":0 [ENABLED,IMMUTABLE]
> > 
> > - entity 6: output (1 pad, 1 link)
> > type Node subtype Unknown flags 0
> > pad0: Sink
> > <- "proc":0 [ENABLED,IMMUTABLE]
> > 
> > The first commit introduces a register/unregister API,
> > that creates/destroys all the entities and pads needed,
> > and links them.
> > 
> > The second commit uses this API to support the vim2m driver.
> > 
> > Notes
> > -
> > 
> > * A new device node type is introduced VFL_TYPE_MEM2MEM,
> >   this is mostly done so the video4linux core doesn't
> >   try to register other media controller entities.
> 
> There is no need for this. You can check if vfl_dir == VFL_DIR_M2M
> instead. I'd rather not add a new VFL_TYPE.
> 

OK, sounds good.

Thanks,
Eze


[GIT PULL FOR v4.19] Various fixes/enhancements

2018-06-15 Thread Hans Verkuil
A fair number of stm32-dcmi fixes/improvements, and the remainder is all over
the place.

Regards,

Hans

The following changes since commit f2809d20b9250c675fca8268a0f6274277cca7ff:

  media: omap2: fix compile-testing with FB_OMAP2=m (2018-06-05 09:56:56 -0400)

are available in the Git repository at:

  git://linuxtv.org/hverkuil/media_tree.git for-v4.19c

for you to fetch changes up to 6939cdcd6bc4d026f2a245b9a589aff06b634fa3:

  Revert "[media] tvp5150: fix pad format frame height" (2018-06-15 10:46:04 
+0200)


Alexandre Courbot (1):
  media: venus: keep resolution when adjusting format

Anton Leontiev (6):
  vim2m: Remove surplus name initialization
  ti-vpe: Remove surplus name initialization
  s5p-g2d: Remove surplus name initialization
  mx2: Remove surplus name initialization
  m2m-deinterlace: Remove surplus name initialization
  rga: Remove surplus name initialization

Colin Ian King (2):
  media: bt8xx: bttv: fix spelling mistake: "culpit" -> "culprit"
  cx18: remove redundant zero check on retval

Corentin Labbe (1):
  media: cx25821: remove cx25821-audio-upstream.c and 
cx25821-video-upstream.c

Ezequiel Garcia (5):
  mem2mem: Remove excessive try_run call
  rockchip/rga: Fix broken .start_streaming
  rockchip/rga: Remove unrequired wait in .job_abort
  mem2mem: Remove unused v4l2_m2m_ops .lock/.unlock
  rcar_vpu: Drop unneeded job_ready

Hugues Fruchet (8):
  media: stm32-dcmi: increase max width/height to 2592
  media: stm32-dcmi: code cleanup
  media: stm32-dcmi: do not fall into error on buffer starvation
  media: stm32-dcmi: return buffer in error state on dma error
  media: stm32-dcmi: clarify state logic on buffer starvation
  media: stm32-dcmi: revisit buffer list management
  media: stm32-dcmi: revisit stop streaming ops
  media: stm32-dcmi: add power saving support

Javier Martinez Canillas (1):
  Revert "[media] tvp5150: fix pad format frame height"

Nicholas Mc Guire (3):
  media: stm32-dcmi: drop unnecessary while(1) loop
  media: stm32-dcmi: add mandatory of_node_put() in success path
  media: stm32-dcmi: simplify of_node_put usage

Steve Longerbeam (1):
  media: i2c: adv748x: csi2: set entity function to video interface bridge

Zhouyang Jia (2):
  media: cx88: add error handling for snd_ctl_add
  media: tm6000: add error handling for dvb_register_adapter

 drivers/media/i2c/adv748x/adv748x-csi2.c   |   2 +-
 drivers/media/i2c/tvp5150.c|   2 +-
 drivers/media/pci/bt8xx/bttv-driver.c  |   2 +-
 drivers/media/pci/cx18/cx18-driver.c   |   2 -
 drivers/media/pci/cx25821/cx25821-audio-upstream.c | 679 

 drivers/media/pci/cx25821/cx25821-audio-upstream.h |  58 -
 drivers/media/pci/cx25821/cx25821-video-upstream.c | 673 
---
 drivers/media/pci/cx25821/cx25821-video-upstream.h | 135 ---
 drivers/media/pci/cx25821/cx25821.h|  12 -
 drivers/media/pci/cx88/cx88-alsa.c |   7 +-
 drivers/media/platform/coda/coda-common.c  |  26 +-
 drivers/media/platform/m2m-deinterlace.c   |  21 +-
 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c |  18 --
 drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c |  16 --
 drivers/media/platform/mx2_emmaprp.c   |  17 --
 drivers/media/platform/qcom/venus/vdec.c   |   2 -
 drivers/media/platform/qcom/venus/venc.c   |   2 -
 drivers/media/platform/rcar_jpu.c  |   6 -
 drivers/media/platform/rockchip/rga/rga-buf.c  |  45 ++--
 drivers/media/platform/rockchip/rga/rga.c  |  14 +-
 drivers/media/platform/rockchip/rga/rga.h  |   2 -
 drivers/media/platform/s5p-g2d/g2d.c   |   1 -
 drivers/media/platform/sti/delta/delta-v4l2.c  |  18 --
 drivers/media/platform/stm32/stm32-dcmi.c  | 259 ++--
 drivers/media/platform/ti-vpe/vpe.c|  20 --
 drivers/media/platform/vim2m.c |   1 -
 drivers/media/usb/tm6000/tm6000-dvb.c  |   5 +
 drivers/media/v4l2-core/v4l2-mem2mem.c |   1 -
 include/media/v4l2-mem2mem.h   |   6 -
 29 files changed, 175 insertions(+), 1877 deletions(-)
 delete mode 100644 drivers/media/pci/cx25821/cx25821-audio-upstream.c
 delete mode 100644 drivers/media/pci/cx25821/cx25821-audio-upstream.h
 delete mode 100644 drivers/media/pci/cx25821/cx25821-video-upstream.c
 delete mode 100644 drivers/media/pci/cx25821/cx25821-video-upstream.h


Re: [RFC 1/2] media: add helpers for memory-to-memory media controller

2018-06-15 Thread Hans Verkuil
On 12/06/18 12:48, Ezequiel Garcia wrote:
> A memory-to-memory pipeline device consists in three
> entities: two DMA engine and one video processing entities.
> The DMA engine entities are linked to a V4L interface.
> 
> This commit add a new v4l2_m2m_{un}register_media_controller
> API to register this topology.
> 
> For instance, a typical mem2mem device topology would
> look like this:
> 
> - entity 1: input (1 pad, 1 link)
> type Node subtype Unknown flags 0
>   pad0: Source
>   -> "proc":1 [ENABLED,IMMUTABLE]
> 
> - entity 3: proc (2 pads, 2 links)
> type Node subtype Unknown flags 0
>   pad0: Source
>   -> "output":0 [ENABLED,IMMUTABLE]
>   pad1: Sink
>   <- "input":0 [ENABLED,IMMUTABLE]
> 
> - entity 6: output (1 pad, 1 link)
> type Node subtype Unknown flags 0
>   pad0: Sink
>   <- "proc":0 [ENABLED,IMMUTABLE]
> 
> Suggested-by: Laurent Pinchart 
> Suggested-by: Hans Verkuil 
> Signed-off-by: Ezequiel Garcia 
> ---
>  drivers/media/v4l2-core/v4l2-dev.c |  23 ++--
>  drivers/media/v4l2-core/v4l2-mem2mem.c | 157 +
>  include/media/media-entity.h   |   4 +
>  include/media/v4l2-dev.h   |   2 +
>  include/media/v4l2-mem2mem.h   |   5 +
>  include/uapi/linux/media.h |   2 +
>  6 files changed, 186 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-dev.c 
> b/drivers/media/v4l2-core/v4l2-dev.c
> index 4ffd7d60a901..ec8f20f0fdc5 100644
> --- a/drivers/media/v4l2-core/v4l2-dev.c
> +++ b/drivers/media/v4l2-core/v4l2-dev.c
> @@ -202,7 +202,7 @@ static void v4l2_device_release(struct device *cd)
>   mutex_unlock(_lock);
>  
>  #if defined(CONFIG_MEDIA_CONTROLLER)
> - if (v4l2_dev->mdev) {
> + if (v4l2_dev->mdev && vdev->vfl_type != VFL_TYPE_MEM2MEM) {

As mentioned this should be vfl_dir != VFL_DIR_M2M. No need for a new VFL_TYPE.

>   /* Remove interfaces and interface links */
>   media_devnode_remove(vdev->intf_devnode);
>   if (vdev->entity.function != MEDIA_ENT_F_UNKNOWN)
> @@ -530,6 +530,7 @@ static void determine_valid_ioctls(struct video_device 
> *vdev)
>   bool is_radio = vdev->vfl_type == VFL_TYPE_RADIO;
>   bool is_sdr = vdev->vfl_type == VFL_TYPE_SDR;
>   bool is_tch = vdev->vfl_type == VFL_TYPE_TOUCH;
> + bool is_m2m = vdev->vfl_type == VFL_TYPE_MEM2MEM;

And that means that this is also no longer needed.

>   bool is_rx = vdev->vfl_dir != VFL_DIR_TX;
>   bool is_tx = vdev->vfl_dir != VFL_DIR_RX;
>  
> @@ -576,7 +577,7 @@ static void determine_valid_ioctls(struct video_device 
> *vdev)
>   if (ops->vidioc_enum_freq_bands || ops->vidioc_g_tuner || 
> ops->vidioc_g_modulator)
>   set_bit(_IOC_NR(VIDIOC_ENUM_FREQ_BANDS), valid_ioctls);
>  
> - if (is_vid || is_tch) {
> + if (is_vid || is_m2m || is_tch) {
>   /* video and metadata specific ioctls */
>   if ((is_rx && (ops->vidioc_enum_fmt_vid_cap ||
>  ops->vidioc_enum_fmt_vid_cap_mplane ||
> @@ -669,7 +670,7 @@ static void determine_valid_ioctls(struct video_device 
> *vdev)
>   set_bit(_IOC_NR(VIDIOC_TRY_FMT), valid_ioctls);
>   }
>  
> - if (is_vid || is_vbi || is_sdr || is_tch) {
> + if (is_vid || is_m2m || is_vbi || is_sdr || is_tch) {
>   /* ioctls valid for video, metadata, vbi or sdr */
>   SET_VALID_IOCTL(ops, VIDIOC_REQBUFS, vidioc_reqbufs);
>   SET_VALID_IOCTL(ops, VIDIOC_QUERYBUF, vidioc_querybuf);
> @@ -682,7 +683,7 @@ static void determine_valid_ioctls(struct video_device 
> *vdev)
>   SET_VALID_IOCTL(ops, VIDIOC_STREAMOFF, vidioc_streamoff);
>   }
>  
> - if (is_vid || is_vbi || is_tch) {
> + if (is_vid || is_m2m || is_vbi || is_tch) {
>   /* ioctls valid for video or vbi */
>   if (ops->vidioc_s_std)
>   set_bit(_IOC_NR(VIDIOC_ENUMSTD), valid_ioctls);
> @@ -733,7 +734,7 @@ static void determine_valid_ioctls(struct video_device 
> *vdev)
>   BASE_VIDIOC_PRIVATE);
>  }
>  
> -static int video_register_media_controller(struct video_device *vdev, int 
> type)
> +static int video_register_media_controller(struct video_device *vdev)
>  {
>  #if defined(CONFIG_MEDIA_CONTROLLER)
>   u32 intf_type;
> @@ -745,7 +746,7 @@ static int video_register_media_controller(struct 
> video_device *vdev, int type)
>   vdev->entity.obj_type = MEDIA_ENTITY_TYPE_VIDEO_DEVICE;
>   vdev->entity.function = MEDIA_ENT_F_UNKNOWN;
>  
> - switch (type) {
> + switch (vdev->vfl_type) {
>   case VFL_TYPE_GRABBER:
>   intf_type = MEDIA_INTF_T_V4L_VIDEO;
>   vdev->entity.function = MEDIA_ENT_F_IO_V4L;
> @@ -774,6 +775,10 @@ static int video_register_media_controller(struct 
> video_device *vdev, int type)
>   intf_type = 

Re: [RFC 0/2] Memory-to-memory media controller topology

2018-06-15 Thread Hans Verkuil
On 12/06/18 12:48, Ezequiel Garcia wrote:
> As discussed on IRC, memory-to-memory need to be modeled
> properly in order to be supported by the media controller
> framework, and thus to support the Request API.
> 
> This RFC is a first draft on the memory-to-memory
> media controller topology.
> 
> The topology looks like this:
> 
> Device topology
> - entity 1: input (1 pad, 1 link)
> type Node subtype Unknown flags 0
>   pad0: Source
>   -> "proc":1 [ENABLED,IMMUTABLE]
> 
> - entity 3: proc (2 pads, 2 links)
> type Node subtype Unknown flags 0
>   pad0: Source
>   -> "output":0 [ENABLED,IMMUTABLE]
>   pad1: Sink
>   <- "input":0 [ENABLED,IMMUTABLE]
> 
> - entity 6: output (1 pad, 1 link)
> type Node subtype Unknown flags 0
>   pad0: Sink
>   <- "proc":0 [ENABLED,IMMUTABLE]
> 
> The first commit introduces a register/unregister API,
> that creates/destroys all the entities and pads needed,
> and links them.
> 
> The second commit uses this API to support the vim2m driver.
> 
> Notes
> -
> 
> * A new device node type is introduced VFL_TYPE_MEM2MEM,
>   this is mostly done so the video4linux core doesn't
>   try to register other media controller entities.

There is no need for this. You can check if vfl_dir == VFL_DIR_M2M
instead. I'd rather not add a new VFL_TYPE.

Regards,

Hans

> 
> * Also, a new media entity type is introduced. Memory-to-memory
>   devices have a multi-entity description and so can't
>   be simply embedded in other structs, or cast from other structs.
> 
> Ezequiel Garcia (1):
>   media: add helpers for memory-to-memory media controller
> 
> Hans Verkuil (1):
>   vim2m: add media device
> 
>  drivers/media/platform/vim2m.c |  41 ++-
>  drivers/media/v4l2-core/v4l2-dev.c |  23 ++--
>  drivers/media/v4l2-core/v4l2-mem2mem.c | 157 +
>  include/media/media-entity.h   |   4 +
>  include/media/v4l2-dev.h   |   2 +
>  include/media/v4l2-mem2mem.h   |   5 +
>  include/uapi/linux/media.h |   2 +
>  7 files changed, 222 insertions(+), 12 deletions(-)
> 



Re: [PATCH 2/3] mem2mem: Make .job_abort optional

2018-06-15 Thread Hans Verkuil
On 14/06/18 17:34, Ezequiel Garcia wrote:
> Implementing job_abort() does not make sense on some drivers.
> This is not a problem, as the abort is not required to
> wait for the job to finish. Quite the opposite, drivers
> are encouraged not to wait.
> 
> Demote v4l2_m2m_ops.job_abort from required to optional, and
> clean all drivers with dummy or wrong implementations.

Can you split off the rcar_jpu.c and g2d.c changes into separate patches?
The others are trivial, but those two need a more precise commit log and
I would like to have Acks of the driver maintainers before merging.

I'm going to take the first and third patches of this series, so you
only have to post a v2 for this patch.

Regards,

Hans

> 
> Signed-off-by: Ezequiel Garcia 
> ---
>  drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c |  5 -
>  drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c|  5 -
>  drivers/media/platform/rcar_jpu.c   | 16 
>  drivers/media/platform/rockchip/rga/rga.c   |  6 --
>  drivers/media/platform/s5p-g2d/g2d.c| 14 --
>  drivers/media/platform/s5p-jpeg/jpeg-core.c |  7 ---
>  drivers/media/v4l2-core/v4l2-mem2mem.c  |  6 +++---
>  include/media/v4l2-mem2mem.h|  2 +-
>  8 files changed, 4 insertions(+), 57 deletions(-)
> 
> diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c 
> b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
> index 328e8f650d9b..4f24da8afecc 100644
> --- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
> +++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
> @@ -861,14 +861,9 @@ static int mtk_jpeg_job_ready(void *priv)
>   return (ctx->state == MTK_JPEG_RUNNING) ? 1 : 0;
>  }
>  
> -static void mtk_jpeg_job_abort(void *priv)
> -{
> -}
> -
>  static const struct v4l2_m2m_ops mtk_jpeg_m2m_ops = {
>   .device_run = mtk_jpeg_device_run,
>   .job_ready  = mtk_jpeg_job_ready,
> - .job_abort  = mtk_jpeg_job_abort,
>  };
>  
>  static int mtk_jpeg_queue_init(void *priv, struct vb2_queue *src_vq,
> diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c 
> b/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
> index 583d47724ee8..1198e19060a2 100644
> --- a/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
> +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
> @@ -455,10 +455,6 @@ static void mtk_mdp_m2m_stop_streaming(struct vb2_queue 
> *q)
>   pm_runtime_put(>mdp_dev->pdev->dev);
>  }
>  
> -static void mtk_mdp_m2m_job_abort(void *priv)
> -{
> -}
> -
>  /* The color format (num_planes) must be already configured. */
>  static void mtk_mdp_prepare_addr(struct mtk_mdp_ctx *ctx,
>struct vb2_buffer *vb,
> @@ -1227,7 +1223,6 @@ static const struct v4l2_file_operations 
> mtk_mdp_m2m_fops = {
>  
>  static const struct v4l2_m2m_ops mtk_mdp_m2m_ops = {
>   .device_run = mtk_mdp_m2m_device_run,
> - .job_abort  = mtk_mdp_m2m_job_abort,
>  };
>  
>  int mtk_mdp_register_m2m_device(struct mtk_mdp_dev *mdp)
> diff --git a/drivers/media/platform/rcar_jpu.c 
> b/drivers/media/platform/rcar_jpu.c
> index 8b44a849ab41..10d24ddcea5f 100644
> --- a/drivers/media/platform/rcar_jpu.c
> +++ b/drivers/media/platform/rcar_jpu.c
> @@ -198,7 +198,6 @@
>   * @vfd_decoder: video device node for decoder mem2mem mode
>   * @m2m_dev: v4l2 mem2mem device data
>   * @curr: pointer to current context
> - * @irq_queue:   interrupt handler waitqueue
>   * @regs: JPEG IP registers mapping
>   * @irq: JPEG IP irq
>   * @clk: JPEG IP clock
> @@ -213,7 +212,6 @@ struct jpu {
>   struct video_device vfd_decoder;
>   struct v4l2_m2m_dev *m2m_dev;
>   struct jpu_ctx  *curr;
> - wait_queue_head_t   irq_queue;
>  
>   void __iomem*regs;
>   unsigned intirq;
> @@ -1499,19 +1497,9 @@ static int jpu_job_ready(void *priv)
>   return 1;
>  }
>  
> -static void jpu_job_abort(void *priv)
> -{
> - struct jpu_ctx *ctx = priv;
> -
> - if (!wait_event_timeout(ctx->jpu->irq_queue, !ctx->jpu->curr,
> - msecs_to_jiffies(JPU_JOB_TIMEOUT)))
> - jpu_cleanup(ctx, true);
> -}
> -
>  static const struct v4l2_m2m_ops jpu_m2m_ops = {
>   .device_run = jpu_device_run,
>   .job_ready  = jpu_job_ready,
> - .job_abort  = jpu_job_abort,
>  };
>  
>  /*
> @@ -1592,9 +1580,6 @@ static irqreturn_t jpu_irq_handler(int irq, void 
> *dev_id)
>  
>   v4l2_m2m_job_finish(jpu->m2m_dev, curr_ctx->fh.m2m_ctx);
>  
> - /* ...wakeup abort routine if needed */
> - wake_up(>irq_queue);
> -
>   return IRQ_HANDLED;
>  
>  handled:
> @@ -1628,7 +1613,6 @@ static int jpu_probe(struct platform_device *pdev)
>   if (!jpu)
>   return -ENOMEM;
>  
> - init_waitqueue_head(>irq_queue);
>   mutex_init(>mutex);
>   spin_lock_init(>lock);
>   jpu->dev = >dev;
> diff --git a/drivers/media/platform/rockchip/rga/rga.c 
> 

Re: [PATCH] gpu: ipu-v3: Allow negative offsets for interlaced scanning

2018-06-15 Thread Krzysztof Hałasa
Steve Longerbeam  writes:

> Right, the selection of interweave is moved to the capture devices,
> so the following will enable interweave:
>
> v4l2-ctl -dN --set-fmt-video=field=interlaced_tb

and

> So the patch to adv7180 needs to be modified to report # field lines.
>
> Try the following:
>
> --- a/drivers/media/i2c/adv7180.c
> +++ b/drivers/media/i2c/adv7180.c

With this patch, fix-csi-interlaced.3 seems to work for me.
"ipu2_csi1":2 reports [fmt:AYUV32/720x576 field:seq-tb], but the
/dev/videoX shows (when requested) 720 x 576 NV12 interlaced, top field
first, and I'm getting valid output.

Thanks for your work.
-- 
Krzysztof Halasa

Industrial Research Institute for Automation and Measurements PIAP
Al. Jerozolimskie 202, 02-486 Warsaw, Poland


Re: [PATCH v3 00/20] v4l2 core: push ioctl lock down to ioctl handler

2018-06-15 Thread Hans Verkuil
On 08/06/18 15:24, Ezequiel Garcia wrote:
> On Fri, 2018-06-08 at 14:11 +0200, Hans Verkuil wrote:
>> Hi Ezequiel,
>>
>> On 05/24/2018 10:35 PM, Ezequiel Garcia wrote:
>>> Third spin of the series posted by Hans:
>>>
>>> https://www.mail-archive.com/linux-media@vger.kernel.org/msg131363.html
>>
>> Can you rebase this? Several patches have already been merged, so it would
>> be nice to have a new clean v4. Can you also move patch 11/20 (dvb-core) to
>> after patch 16/20? It makes it a bit easier for me to apply the patches 
>> before
>> that since the dvb patch needs an Ack from Mauro at the very least.
>>
>> But I can take the v4l patches, that should be no problem.
>>
>>
> 
> No problem.

Haven't seen a v4 yet. I'm processing patches today and Monday, so if I have
a clean patch series I can merge most of it quickly.

Regards,

Hans


Re: [PATCHv15 14/35] v4l2-ctrls: support g/s_ext_ctrls for requests

2018-06-15 Thread Hans Verkuil
On 04/06/18 13:46, Hans Verkuil wrote:
> From: Hans Verkuil 
> 
> The v4l2_g/s_ext_ctrls functions now support control handlers that
> represent requests.
> 
> The v4l2_ctrls_find_req_obj() function is responsible for finding the
> request from the fd.
> 
> Signed-off-by: Hans Verkuil 
> ---
>  drivers/media/platform/omap3isp/ispvideo.c |   2 +-
>  drivers/media/v4l2-core/v4l2-ctrls.c   | 128 +++--
>  drivers/media/v4l2-core/v4l2-ioctl.c   |  12 +-
>  drivers/media/v4l2-core/v4l2-subdev.c  |   9 +-
>  include/media/v4l2-ctrls.h |   7 +-
>  5 files changed, 139 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/media/platform/omap3isp/ispvideo.c 
> b/drivers/media/platform/omap3isp/ispvideo.c
> index 9d228eac24ea..674e7fd3ad99 100644
> --- a/drivers/media/platform/omap3isp/ispvideo.c
> +++ b/drivers/media/platform/omap3isp/ispvideo.c
> @@ -1028,7 +1028,7 @@ static int isp_video_check_external_subdevs(struct 
> isp_video *video,
>   ctrls.count = 1;
>   ctrls.controls = 
>  
> - ret = v4l2_g_ext_ctrls(pipe->external->ctrl_handler, );
> + ret = v4l2_g_ext_ctrls(pipe->external->ctrl_handler, NULL, );
>   if (ret < 0) {
>   dev_warn(isp->dev, "no pixel rate control in subdev %s\n",
>pipe->external->name);
> diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c 
> b/drivers/media/v4l2-core/v4l2-ctrls.c
> index bd4818507486..ab5e8827fde0 100644
> --- a/drivers/media/v4l2-core/v4l2-ctrls.c
> +++ b/drivers/media/v4l2-core/v4l2-ctrls.c
> @@ -3124,7 +3124,8 @@ static int class_check(struct v4l2_ctrl_handler *hdl, 
> u32 which)
>  }
>  
>  /* Get extended controls. Allocates the helpers array if needed. */
> -int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls 
> *cs)
> +int __v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl,
> +struct v4l2_ext_controls *cs)
>  {
>   struct v4l2_ctrl_helper helper[4];
>   struct v4l2_ctrl_helper *helpers = helper;
> @@ -3204,6 +3205,77 @@ int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, 
> struct v4l2_ext_controls *cs
>   kvfree(helpers);
>   return ret;
>  }
> +
> +static struct media_request_object *
> +v4l2_ctrls_find_req_obj(struct v4l2_ctrl_handler *hdl,
> + struct media_request *req, bool set)
> +{
> + struct media_request_object *obj;
> + struct v4l2_ctrl_handler *new_hdl;
> + int ret;
> +
> + if (IS_ERR(req))
> + return ERR_CAST(req);
> +
> + if (set && WARN_ON(req->state != MEDIA_REQUEST_STATE_UPDATING))
> + return ERR_PTR(-EBUSY);
> +
> + obj = media_request_object_find(req, _ops, hdl);
> + if (obj)
> + return obj;
> + if (!set)
> + return ERR_PTR(-ENOENT);
> +
> + new_hdl = kzalloc(sizeof(*new_hdl), GFP_KERNEL);
> + if (!new_hdl)
> + return ERR_PTR(-ENOMEM);
> +
> + obj = _hdl->req_obj;
> + ret = v4l2_ctrl_handler_init(new_hdl, (hdl->nr_of_buckets - 1) * 8);
> + if (!ret)
> + ret = v4l2_ctrl_request_bind(req, new_hdl, hdl);
> + if (ret) {
> + kfree(new_hdl);
> +
> + return ERR_PTR(ret);
> + }
> +
> + media_request_object_get(obj);
> + return obj;
> +}
> +
> +int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct media_device 
> *mdev,
> +  struct v4l2_ext_controls *cs)
> +{
> + struct media_request_object *obj = NULL;
> + int ret;
> +
> + if (cs->which == V4L2_CTRL_WHICH_REQUEST_VAL) {
> + struct media_request *req;
> +
> + if (!mdev || cs->request_fd < 0)
> + return -EINVAL;
> +
> + req = media_request_get_by_fd(mdev, cs->request_fd);
> + if (IS_ERR(req))
> + return PTR_ERR(req);
> +
> + obj = v4l2_ctrls_find_req_obj(hdl, req, false);
> + /* Reference to the request held through obj */
> + media_request_put(req);
> + if (IS_ERR(obj))
> + return PTR_ERR(obj);
> +
> + hdl = container_of(obj, struct v4l2_ctrl_handler,
> +req_obj);
> + }
> +
> + ret = __v4l2_g_ext_ctrls(hdl, cs);
> +
> + if (obj)
> + media_request_object_put(obj);
> + return ret;
> +}
>  EXPORT_SYMBOL(v4l2_g_ext_ctrls);
>  
>  /* Helper function to get a single control */
> @@ -3379,9 +3451,9 @@ static void update_from_auto_cluster(struct v4l2_ctrl 
> *master)
>  }
>  
>  /* Try or try-and-set controls */
> -static int try_set_ext_ctrls(struct v4l2_fh *fh, struct v4l2_ctrl_handler 
> *hdl,
> -  struct v4l2_ext_controls *cs,
> -  bool set)
> +static int __try_set_ext_ctrls(struct v4l2_fh *fh,
> +struct v4l2_ctrl_handler *hdl,
> +struct v4l2_ext_controls *cs, bool set)
>  {
>   struct v4l2_ctrl_helper 

Re: [PATCHv15 13/35] v4l2-ctrls: add core request support

2018-06-15 Thread Hans Verkuil
On 04/06/18 13:46, Hans Verkuil wrote:
> From: Hans Verkuil 
> 
> Integrate the request support. This adds the v4l2_ctrl_request_complete
> and v4l2_ctrl_request_setup functions to complete a request and (as a
> helper function) to apply a request to the hardware.
> 
> It takes care of queuing requests and correctly chaining control values
> in the request queue.
> 
> Note that when a request is marked completed it will copy control values
> to the internal request state. This can be optimized in the future since
> this is sub-optimal when dealing with large compound and/or array controls.
> 
> For the initial 'stateless codec' use-case the current implementation is
> sufficient.
> 
> Signed-off-by: Hans Verkuil 
> ---
>  drivers/media/v4l2-core/v4l2-ctrls.c | 331 ++-
>  include/media/v4l2-ctrls.h   |  51 +
>  2 files changed, 376 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c 
> b/drivers/media/v4l2-core/v4l2-ctrls.c
> index da4cc1485dc4..bd4818507486 100644
> --- a/drivers/media/v4l2-core/v4l2-ctrls.c
> +++ b/drivers/media/v4l2-core/v4l2-ctrls.c
> @@ -1647,6 +1647,13 @@ static int new_to_user(struct v4l2_ext_control *c,
>   return ptr_to_user(c, ctrl, ctrl->p_new);
>  }
>  
> +/* Helper function: copy the request value back to the caller */
> +static int req_to_user(struct v4l2_ext_control *c,
> +struct v4l2_ctrl_ref *ref)
> +{
> + return ptr_to_user(c, ref->ctrl, ref->p_req);
> +}
> +
>  /* Helper function: copy the initial control value back to the caller */
>  static int def_to_user(struct v4l2_ext_control *c, struct v4l2_ctrl *ctrl)
>  {
> @@ -1766,6 +1773,26 @@ static void cur_to_new(struct v4l2_ctrl *ctrl)
>   ptr_to_ptr(ctrl, ctrl->p_cur, ctrl->p_new);
>  }
>  
> +/* Copy the new value to the request value */
> +static void new_to_req(struct v4l2_ctrl_ref *ref)
> +{
> + if (!ref)
> + return;
> + ptr_to_ptr(ref->ctrl, ref->ctrl->p_new, ref->p_req);
> + ref->req = ref;
> +}
> +
> +/* Copy the request value to the new value */
> +static void req_to_new(struct v4l2_ctrl_ref *ref)
> +{
> + if (!ref)
> + return;
> + if (ref->req)
> + ptr_to_ptr(ref->ctrl, ref->req->p_req, ref->ctrl->p_new);
> + else
> + ptr_to_ptr(ref->ctrl, ref->ctrl->p_cur, ref->ctrl->p_new);
> +}
> +
>  /* Return non-zero if one or more of the controls in the cluster has a new
> value that differs from the current value. */
>  static int cluster_changed(struct v4l2_ctrl *master)
> @@ -1875,6 +1902,9 @@ int v4l2_ctrl_handler_init_class(struct 
> v4l2_ctrl_handler *hdl,
>   lockdep_set_class_and_name(hdl->lock, key, name);
>   INIT_LIST_HEAD(>ctrls);
>   INIT_LIST_HEAD(>ctrl_refs);
> + INIT_LIST_HEAD(>requests);
> + INIT_LIST_HEAD(>requests_queued);
> + hdl->request_is_queued = false;
>   hdl->nr_of_buckets = 1 + nr_of_controls_hint / 8;
>   hdl->buckets = kvmalloc_array(hdl->nr_of_buckets,
> sizeof(hdl->buckets[0]),
> @@ -1895,6 +1925,14 @@ void v4l2_ctrl_handler_free(struct v4l2_ctrl_handler 
> *hdl)
>   if (hdl == NULL || hdl->buckets == NULL)
>   return;
>  
> + if (!hdl->req_obj.req && !list_empty(>requests)) {
> + struct v4l2_ctrl_handler *req, *next_req;
> +
> + list_for_each_entry_safe(req, next_req, >requests, 
> requests) {
> + media_request_object_unbind(>req_obj);
> + media_request_object_put(>req_obj);
> + }
> + }
>   mutex_lock(hdl->lock);
>   /* Free all nodes */
>   list_for_each_entry_safe(ref, next_ref, >ctrl_refs, node) {
> @@ -2816,6 +2854,128 @@ int v4l2_querymenu(struct v4l2_ctrl_handler *hdl, 
> struct v4l2_querymenu *qm)
>  }
>  EXPORT_SYMBOL(v4l2_querymenu);
>  
> +static int v4l2_ctrl_request_clone(struct v4l2_ctrl_handler *hdl,
> +const struct v4l2_ctrl_handler *from)
> +{
> + struct v4l2_ctrl_ref *ref;
> + int err;
> +
> + if (WARN_ON(!hdl || hdl == from))
> + return -EINVAL;
> +
> + if (hdl->error)
> + return hdl->error;
> +
> + WARN_ON(hdl->lock != >_lock);
> +
> + mutex_lock(from->lock);
> + list_for_each_entry(ref, >ctrl_refs, node) {
> + struct v4l2_ctrl *ctrl = ref->ctrl;
> + struct v4l2_ctrl_ref *new_ref;
> +
> + /* Skip refs inherited from other devices */
> + if (ref->from_other_dev)
> + continue;
> + /* And buttons */
> + if (ctrl->type == V4L2_CTRL_TYPE_BUTTON)
> + continue;
> + err = handler_new_ref(hdl, ctrl, _ref, false, true);
> + if (err) {
> + printk("%s: handler_new_ref on control %x (%s) returned 
> %d\n", __func__, ctrl->id, ctrl->name, err);
> + err = 0;
> +

Re: [PATCHv15 02/35] media-request: implement media requests

2018-06-15 Thread Hans Verkuil
On 04/06/18 13:46, Hans Verkuil wrote:
> From: Hans Verkuil 
> 
> Add initial media request support:
> 
> 1) Add MEDIA_IOC_REQUEST_ALLOC ioctl support to media-device.c
> 2) Add struct media_request to store request objects.
> 3) Add struct media_request_object to represent a request object.
> 4) Add MEDIA_REQUEST_IOC_QUEUE/REINIT ioctl support.
> 
> Basic lifecycle: the application allocates a request, adds
> objects to it, queues the request, polls until it is completed
> and can then read the final values of the objects at the time
> of completion. When it closes the file descriptor the request
> memory will be freed (actually, when the last user of that request
> releases the request).
> 
> Drivers will bind an object to a request (the 'adds objects to it'
> phase), when MEDIA_REQUEST_IOC_QUEUE is called the request is
> validated (req_validate op), then queued (the req_queue op).
> 
> When done with an object it can either be unbound from the request
> (e.g. when the driver has finished with a vb2 buffer) or marked as
> completed (e.g. for controls associated with a buffer). When all
> objects in the request are completed (or unbound), then the request
> fd will signal an exception (poll).
> 
> Signed-off-by: Hans Verkuil 
> Co-developed-by: Sakari Ailus 
> Signed-off-by: Sakari Ailus 
> Co-developed-by: Laurent Pinchart 
> Co-developed-by: Alexandre Courbot 
> ---
>  drivers/media/Makefile|   3 +-
>  drivers/media/media-device.c  |  14 ++
>  drivers/media/media-request.c | 421 ++
>  include/media/media-device.h  |  24 ++
>  include/media/media-request.h | 326 ++
>  5 files changed, 787 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/media/media-request.c
>  create mode 100644 include/media/media-request.h
> 



> diff --git a/include/media/media-request.h b/include/media/media-request.h
> new file mode 100644
> index ..8acd2627835c
> --- /dev/null
> +++ b/include/media/media-request.h
> @@ -0,0 +1,326 @@



> +/**
> + * struct media_request - Media device request
> + * @mdev: Media device this request belongs to
> + * @kref: Reference count
> + * @debug_str: Prefix for debug messages (process name:fd)
> + * @state: The state of the request
> + * @updating_count: count the number of request updates that are in progress
> + * @objects: List of @struct media_request_object request objects
> + * @num_incomplete_objects: The number of incomplete objects in the request
> + * @poll_wait: Wait queue for poll
> + * @lock: Serializes access to this struct
> + */
> +struct media_request {
> + struct media_device *mdev;
> + struct kref kref;
> + char debug_str[TASK_COMM_LEN + 11];
> + enum media_request_state state;
> + refcount_t updating_count;

This will be replaced by unsigned int: it turns out that if 
CONFIG_REFCOUNT_FULL is set,
the refcount implementation will complain when you increase the refcount from 0 
to 1
since it expects that refcount_t it used as it is in kref. Since updating_count 
is
protected by the spinlock anyway there is no need to use refcount_t, a simple
unsigned int works just as well.

Regards,

Hans

> + struct list_head objects;
> + unsigned int num_incomplete_objects;
> + struct wait_queue_head poll_wait;
> + spinlock_t lock;
> +};