diff mbox series

[PATCHv4,3/8] videobuf2: split buffer cache_hints initialisation

Message ID 20210727070517.443167-4-senozhatsky@chromium.org (mailing list archive)
State New, archived
Headers show
Series videobuf2: support new noncontiguous DMA API | expand

Commit Message

Sergey Senozhatsky July 27, 2021, 7:05 a.m. UTC
V4L2 is not the perfect place to manage vb2 buffer cache hints.
It works for V4L2 users, but there are backends that use vb2 core
and don't use V4L2. Factor buffer cache hints init and call it
when we allocate vb2 buffer.

Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
---
 .../media/common/videobuf2/videobuf2-core.c   | 22 +++++++++++++++++++
 .../media/common/videobuf2/videobuf2-v4l2.c   | 18 ---------------
 2 files changed, 22 insertions(+), 18 deletions(-)

Comments

Hans Verkuil Aug. 3, 2021, 8:10 a.m. UTC | #1
On 27/07/2021 09:05, Sergey Senozhatsky wrote:
> V4L2 is not the perfect place to manage vb2 buffer cache hints.
> It works for V4L2 users, but there are backends that use vb2 core

use -> use the

> and don't use V4L2. Factor buffer cache hints init and call it

Factor? You mean Refactor?

Regards,

	Hans

> when we allocate vb2 buffer.
> 
> Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
> ---
>  .../media/common/videobuf2/videobuf2-core.c   | 22 +++++++++++++++++++
>  .../media/common/videobuf2/videobuf2-v4l2.c   | 18 ---------------
>  2 files changed, 22 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c
> index 23e41fec9880..76210c006958 100644
> --- a/drivers/media/common/videobuf2/videobuf2-core.c
> +++ b/drivers/media/common/videobuf2/videobuf2-core.c
> @@ -382,6 +382,27 @@ static void __setup_offsets(struct vb2_buffer *vb)
>  	}
>  }
>  
> +static void init_buffer_cache_hints(struct vb2_queue *q, struct vb2_buffer *vb)
> +{
> +	/*
> +	 * DMA exporter should take care of cache syncs, so we can avoid
> +	 * explicit ->prepare()/->finish() syncs. For other ->memory types
> +	 * we always need ->prepare() or/and ->finish() cache sync.
> +	 */
> +	if (q->memory == VB2_MEMORY_DMABUF) {
> +		vb->skip_cache_sync_on_finish = 1;
> +		vb->skip_cache_sync_on_prepare = 1;
> +		return;
> +	}
> +
> +	/*
> +	 * ->finish() cache sync can be avoided when queue direction is
> +	 * TO_DEVICE.
> +	 */
> +	if (q->dma_dir == DMA_TO_DEVICE)
> +		vb->skip_cache_sync_on_finish = 1;
> +}
> +
>  /*
>   * __vb2_queue_alloc() - allocate videobuf buffer structures and (for MMAP type)
>   * video buffer memory for all buffers/planes on the queue and initializes the
> @@ -415,6 +436,7 @@ 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;
> +		init_buffer_cache_hints(q, vb);
>  		for (plane = 0; plane < num_planes; ++plane) {
>  			vb->planes[plane].length = plane_sizes[plane];
>  			vb->planes[plane].min_length = plane_sizes[plane];
> diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c
> index 454d58268602..2fbae9bd7b52 100644
> --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c
> +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c
> @@ -345,17 +345,6 @@ static void set_buffer_cache_hints(struct vb2_queue *q,
>  				   struct vb2_buffer *vb,
>  				   struct v4l2_buffer *b)
>  {
> -	/*
> -	 * DMA exporter should take care of cache syncs, so we can avoid
> -	 * explicit ->prepare()/->finish() syncs. For other ->memory types
> -	 * we always need ->prepare() or/and ->finish() cache sync.
> -	 */
> -	if (q->memory == VB2_MEMORY_DMABUF) {
> -		vb->skip_cache_sync_on_finish = 1;
> -		vb->skip_cache_sync_on_prepare = 1;
> -		return;
> -	}
> -
>  	if (!vb2_queue_allows_cache_hints(q)) {
>  		/*
>  		 * Clear buffer cache flags if queue does not support user
> @@ -367,13 +356,6 @@ static void set_buffer_cache_hints(struct vb2_queue *q,
>  		return;
>  	}
>  
> -	/*
> -	 * ->finish() cache sync can be avoided when queue direction is
> -	 * TO_DEVICE.
> -	 */
> -	if (q->dma_dir == DMA_TO_DEVICE)
> -		vb->skip_cache_sync_on_finish = 1;
> -
>  	if (b->flags & V4L2_BUF_FLAG_NO_CACHE_INVALIDATE)
>  		vb->skip_cache_sync_on_finish = 1;
>  
>
Sergey Senozhatsky Aug. 17, 2021, 10:41 a.m. UTC | #2
On (21/08/03 10:10), Hans Verkuil wrote:
> On 27/07/2021 09:05, Sergey Senozhatsky wrote:
> > V4L2 is not the perfect place to manage vb2 buffer cache hints.
> > It works for V4L2 users, but there are backends that use vb2 core
> 
> use -> use the
> 
> > and don't use V4L2. Factor buffer cache hints init and call it
> 
> Factor? You mean Refactor?

Factor out.
diff mbox series

Patch

diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c
index 23e41fec9880..76210c006958 100644
--- a/drivers/media/common/videobuf2/videobuf2-core.c
+++ b/drivers/media/common/videobuf2/videobuf2-core.c
@@ -382,6 +382,27 @@  static void __setup_offsets(struct vb2_buffer *vb)
 	}
 }
 
+static void init_buffer_cache_hints(struct vb2_queue *q, struct vb2_buffer *vb)
+{
+	/*
+	 * DMA exporter should take care of cache syncs, so we can avoid
+	 * explicit ->prepare()/->finish() syncs. For other ->memory types
+	 * we always need ->prepare() or/and ->finish() cache sync.
+	 */
+	if (q->memory == VB2_MEMORY_DMABUF) {
+		vb->skip_cache_sync_on_finish = 1;
+		vb->skip_cache_sync_on_prepare = 1;
+		return;
+	}
+
+	/*
+	 * ->finish() cache sync can be avoided when queue direction is
+	 * TO_DEVICE.
+	 */
+	if (q->dma_dir == DMA_TO_DEVICE)
+		vb->skip_cache_sync_on_finish = 1;
+}
+
 /*
  * __vb2_queue_alloc() - allocate videobuf buffer structures and (for MMAP type)
  * video buffer memory for all buffers/planes on the queue and initializes the
@@ -415,6 +436,7 @@  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;
+		init_buffer_cache_hints(q, vb);
 		for (plane = 0; plane < num_planes; ++plane) {
 			vb->planes[plane].length = plane_sizes[plane];
 			vb->planes[plane].min_length = plane_sizes[plane];
diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c
index 454d58268602..2fbae9bd7b52 100644
--- a/drivers/media/common/videobuf2/videobuf2-v4l2.c
+++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c
@@ -345,17 +345,6 @@  static void set_buffer_cache_hints(struct vb2_queue *q,
 				   struct vb2_buffer *vb,
 				   struct v4l2_buffer *b)
 {
-	/*
-	 * DMA exporter should take care of cache syncs, so we can avoid
-	 * explicit ->prepare()/->finish() syncs. For other ->memory types
-	 * we always need ->prepare() or/and ->finish() cache sync.
-	 */
-	if (q->memory == VB2_MEMORY_DMABUF) {
-		vb->skip_cache_sync_on_finish = 1;
-		vb->skip_cache_sync_on_prepare = 1;
-		return;
-	}
-
 	if (!vb2_queue_allows_cache_hints(q)) {
 		/*
 		 * Clear buffer cache flags if queue does not support user
@@ -367,13 +356,6 @@  static void set_buffer_cache_hints(struct vb2_queue *q,
 		return;
 	}
 
-	/*
-	 * ->finish() cache sync can be avoided when queue direction is
-	 * TO_DEVICE.
-	 */
-	if (q->dma_dir == DMA_TO_DEVICE)
-		vb->skip_cache_sync_on_finish = 1;
-
 	if (b->flags & V4L2_BUF_FLAG_NO_CACHE_INVALIDATE)
 		vb->skip_cache_sync_on_finish = 1;