Commit 4dbe7eab authored by Sergey Senozhatsky's avatar Sergey Senozhatsky Committed by Mauro Carvalho Chehab
Browse files

media: videobuf2: inverse buffer cache_hints flags



It would be less error prone if the default cache hints value
(we kzalloc() structs, so it's zeroed out by default) would be
to "always sync/flush" caches. Inverse and rename cache hints
flags.

Signed-off-by: default avatarSergey Senozhatsky <senozhatsky@chromium.org>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent a4b83deb
Loading
Loading
Loading
Loading
+10 −21
Original line number Diff line number Diff line
@@ -327,12 +327,12 @@ static void __vb2_buf_mem_prepare(struct vb2_buffer *vb)
	if (vb->synced)
		return;

	if (vb->need_cache_sync_on_prepare) {
		for (plane = 0; plane < vb->num_planes; ++plane)
			call_void_memop(vb, prepare,
					vb->planes[plane].mem_priv);
	}
	vb->synced = 1;
	if (vb->skip_cache_sync_on_prepare)
		return;

	for (plane = 0; plane < vb->num_planes; ++plane)
		call_void_memop(vb, prepare, vb->planes[plane].mem_priv);
}

/*
@@ -346,12 +346,12 @@ static void __vb2_buf_mem_finish(struct vb2_buffer *vb)
	if (!vb->synced)
		return;

	if (vb->need_cache_sync_on_finish) {
		for (plane = 0; plane < vb->num_planes; ++plane)
			call_void_memop(vb, finish,
					vb->planes[plane].mem_priv);
	}
	vb->synced = 0;
	if (vb->skip_cache_sync_on_finish)
		return;

	for (plane = 0; plane < vb->num_planes; ++plane)
		call_void_memop(vb, finish, vb->planes[plane].mem_priv);
}

/*
@@ -415,17 +415,6 @@ 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];
+5 −12
Original line number Diff line number Diff line
@@ -351,18 +351,11 @@ static void set_buffer_cache_hints(struct vb2_queue *q,
	 * we always need ->prepare() or/and ->finish() cache sync.
	 */
	if (q->memory == VB2_MEMORY_DMABUF) {
		vb->need_cache_sync_on_finish = 0;
		vb->need_cache_sync_on_prepare = 0;
		vb->skip_cache_sync_on_finish = 1;
		vb->skip_cache_sync_on_prepare = 1;
		return;
	}

	/*
	 * Cache sync/invalidation flags are set by default in order to
	 * preserve existing behaviour for old apps/drivers.
	 */
	vb->need_cache_sync_on_prepare = 1;
	vb->need_cache_sync_on_finish = 1;

	if (!vb2_queue_allows_cache_hints(q)) {
		/*
		 * Clear buffer cache flags if queue does not support user
@@ -379,13 +372,13 @@ static void set_buffer_cache_hints(struct vb2_queue *q,
	 * TO_DEVICE.
	 */
	if (q->dma_dir == DMA_TO_DEVICE)
		vb->need_cache_sync_on_finish = 0;
		vb->skip_cache_sync_on_finish = 1;

	if (b->flags & V4L2_BUF_FLAG_NO_CACHE_INVALIDATE)
		vb->need_cache_sync_on_finish = 0;
		vb->skip_cache_sync_on_finish = 1;

	if (b->flags & V4L2_BUF_FLAG_NO_CACHE_CLEAN)
		vb->need_cache_sync_on_prepare = 0;
		vb->skip_cache_sync_on_prepare = 1;
}

static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct media_device *mdev,
+6 −6
Original line number Diff line number Diff line
@@ -267,10 +267,10 @@ struct vb2_buffer {
	 *			after the 'buf_finish' op is called.
	 * copied_timestamp:	the timestamp of this capture buffer was copied
	 *			from an output buffer.
	 * need_cache_sync_on_prepare: when set buffer's ->prepare() function
	 *			performs cache sync/invalidation.
	 * need_cache_sync_on_finish: when set buffer's ->finish() function
	 *			performs cache sync/invalidation.
	 * skip_cache_sync_on_prepare: when set buffer's ->prepare() function
	 *			skips cache sync/invalidation.
	 * skip_cache_sync_on_finish: when set buffer's ->finish() function
	 *			skips cache sync/invalidation.
	 * queued_entry:	entry on the queued buffers list, which holds
	 *			all buffers queued from userspace
	 * done_entry:		entry on the list that stores all buffers ready
@@ -281,8 +281,8 @@ struct vb2_buffer {
	unsigned int		synced:1;
	unsigned int		prepared:1;
	unsigned int		copied_timestamp:1;
	unsigned int		need_cache_sync_on_prepare:1;
	unsigned int		need_cache_sync_on_finish:1;
	unsigned int		skip_cache_sync_on_prepare:1;
	unsigned int		skip_cache_sync_on_finish:1;

	struct vb2_plane	planes[VB2_MAX_PLANES];
	struct list_head	queued_entry;