media: vb2: set cache sync hints when init buffers
authorSergey Senozhatsky <senozhatsky@chromium.org>
Mon, 30 Nov 2020 15:00:54 +0000 (16:00 +0100)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Wed, 2 Dec 2020 12:00:57 +0000 (13:00 +0100)
We need to set ->need_cache_sync_on_prepare and
->need_cache_sync_on_finish when we initialize vb2 buffer.

Currently these flags are set/adjusted only in V4L2's
vb2_queue_or_prepare_buf(), which means that for the code
paths that don't use V4L2 vb2 will always tell videobuf2
core to skip ->prepare() and ->finish() cache syncs/flushes.
Fix this by setting cache sync hints for new buffers; except
VB2_MEMORY_DMABUF buffers, for which DMA exporter syncs
caches.

Fixes: f5f5fa73fbfb ("media: videobuf2: handle V4L2 buffer cache flags")
Reported-by: Tomasz Figa <tfiga@chromium.org>
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/media/common/videobuf2/videobuf2-core.c

index 4eab6d81cce170f4c708cd14ed10b017db8cc761..89e38392509c12c68b9056a60ef942b38854c18e 100644 (file)
@@ -414,6 +414,17 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory,
                vb->index = q->num_buffers + buffer;
                vb->type = q->type;
                vb->memory = memory;
+               /*
+                * We need to set these flags here so that the videobuf2 core
+                * will call ->prepare()/->finish() cache sync/flush on vb2
+                * buffers when appropriate. However, we can avoid explicit
+                * ->prepare() and ->finish() cache sync for DMABUF buffers,
+                * because DMA exporter takes care of it.
+                */
+               if (q->memory != VB2_MEMORY_DMABUF) {
+                       vb->need_cache_sync_on_prepare = 1;
+                       vb->need_cache_sync_on_finish = 1;
+               }
                for (plane = 0; plane < num_planes; ++plane) {
                        vb->planes[plane].length = plane_sizes[plane];
                        vb->planes[plane].min_length = plane_sizes[plane];