Linux Media Controller development
 help / color / mirror / Atom feed
* [PATCH] media: amphion: Enable non-coherent allocation for raw frame buffers
@ 2026-11-19  7:27 Ming Qian
  2026-11-23 20:54 ` Frank Li
  0 siblings, 1 reply; 4+ messages in thread
From: Ming Qian @ 2026-11-19  7:27 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Hans Verkuil, Nicolas Dufresne
  Cc: Zhou Peng, Frank Li, linux-imx, imx, linux-media, linux-kernel,
	Ming Qian

Allow applications to allocate raw frame buffers with
V4L2_MEMORY_FLAG_NON_COHERENT for efficient CPU access. The required
cache synchronization is handled by videobuf2 in its prepare() and
finish() methods.

Set allow_cache_hints only for the encoder OUTPUT and decoder CAPTURE
queues. Leave it disabled for compressed bitstream queues, as the
driver may access their payloads through the CPU.

Signed-off-by: Ming Qian <ming.qian@oss.nxp.com>
---
 drivers/media/platform/amphion/vpu_v4l2.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/media/platform/amphion/vpu_v4l2.c b/drivers/media/platform/amphion/vpu_v4l2.c
index 7cccc994fc50..c8d52f0af879 100644
--- a/drivers/media/platform/amphion/vpu_v4l2.c
+++ b/drivers/media/platform/amphion/vpu_v4l2.c
@@ -664,6 +664,8 @@ static int vpu_m2m_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_q
 	src_vq->mem_ops = &vb2_dma_contig_memops;
 	if (inst->type == VPU_CORE_TYPE_DEC && inst->use_stream_buffer)
 		src_vq->mem_ops = &vb2_vmalloc_memops;
+	if (inst->type == VPU_CORE_TYPE_ENC)
+		src_vq->allow_cache_hints = 1;
 	src_vq->drv_priv = inst;
 	src_vq->buf_struct_size = sizeof(struct vpu_vb2_buffer);
 	src_vq->dev = inst->vpu->dev;
@@ -680,6 +682,8 @@ static int vpu_m2m_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_q
 	dst_vq->mem_ops = &vb2_dma_contig_memops;
 	if (inst->type == VPU_CORE_TYPE_ENC && inst->use_stream_buffer)
 		dst_vq->mem_ops = &vb2_vmalloc_memops;
+	if (inst->type == VPU_CORE_TYPE_DEC)
+		dst_vq->allow_cache_hints = 1;
 	dst_vq->drv_priv = inst;
 	dst_vq->buf_struct_size = sizeof(struct vpu_vb2_buffer);
 	dst_vq->dev = inst->vpu->dev;

---
base-commit: 7969a6f407cf55b5254c824c87875452655ef11e
change-id: 20261119-amphion-non-coherent-f61009334dff


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] media: amphion: Enable non-coherent allocation for raw frame buffers
  2026-11-19  7:27 [PATCH] media: amphion: Enable non-coherent allocation for raw frame buffers Ming Qian
@ 2026-11-23 20:54 ` Frank Li
  2026-11-24  5:42   ` Ming Qian(OSS)
  0 siblings, 1 reply; 4+ messages in thread
From: Frank Li @ 2026-11-23 20:54 UTC (permalink / raw)
  To: Ming Qian
  Cc: Mauro Carvalho Chehab, Hans Verkuil, Nicolas Dufresne, Zhou Peng,
	Frank Li, linux-imx, imx, linux-media, linux-kernel

On Thu, Nov 19, 2026 at 04:27:14PM +0900, Ming Qian wrote:
> Allow applications to allocate raw frame buffers with
> V4L2_MEMORY_FLAG_NON_COHERENT for efficient CPU access. The required
> cache synchronization is handled by videobuf2 in its prepare() and
> finish() methods.
>
> Set allow_cache_hints only for the encoder OUTPUT and decoder CAPTURE
> queues. Leave it disabled for compressed bitstream queues, as the
> driver may access their payloads through the CPU.

"V4L2_MEMORY_FLAG_NON_COHERENT for efficient CPU access", but here
"Leave it disabled for compressed bitstream queues, as the
 driver may access their payloads through the CPU"

Look like description is contradiction

Frank

>
> Signed-off-by: Ming Qian <ming.qian@oss.nxp.com>
> ---
>  drivers/media/platform/amphion/vpu_v4l2.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/drivers/media/platform/amphion/vpu_v4l2.c b/drivers/media/platform/amphion/vpu_v4l2.c
> index 7cccc994fc50..c8d52f0af879 100644
> --- a/drivers/media/platform/amphion/vpu_v4l2.c
> +++ b/drivers/media/platform/amphion/vpu_v4l2.c
> @@ -664,6 +664,8 @@ static int vpu_m2m_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_q
>  	src_vq->mem_ops = &vb2_dma_contig_memops;
>  	if (inst->type == VPU_CORE_TYPE_DEC && inst->use_stream_buffer)
>  		src_vq->mem_ops = &vb2_vmalloc_memops;
> +	if (inst->type == VPU_CORE_TYPE_ENC)
> +		src_vq->allow_cache_hints = 1;
>  	src_vq->drv_priv = inst;
>  	src_vq->buf_struct_size = sizeof(struct vpu_vb2_buffer);
>  	src_vq->dev = inst->vpu->dev;
> @@ -680,6 +682,8 @@ static int vpu_m2m_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_q
>  	dst_vq->mem_ops = &vb2_dma_contig_memops;
>  	if (inst->type == VPU_CORE_TYPE_ENC && inst->use_stream_buffer)
>  		dst_vq->mem_ops = &vb2_vmalloc_memops;
> +	if (inst->type == VPU_CORE_TYPE_DEC)
> +		dst_vq->allow_cache_hints = 1;
>  	dst_vq->drv_priv = inst;
>  	dst_vq->buf_struct_size = sizeof(struct vpu_vb2_buffer);
>  	dst_vq->dev = inst->vpu->dev;
>
> ---
> base-commit: 7969a6f407cf55b5254c824c87875452655ef11e
> change-id: 20261119-amphion-non-coherent-f61009334dff
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] media: amphion: Enable non-coherent allocation for raw frame buffers
  2026-11-23 20:54 ` Frank Li
@ 2026-11-24  5:42   ` Ming Qian(OSS)
  2026-11-24 16:45     ` Frank Li
  0 siblings, 1 reply; 4+ messages in thread
From: Ming Qian(OSS) @ 2026-11-24  5:42 UTC (permalink / raw)
  To: Frank Li
  Cc: Mauro Carvalho Chehab, Hans Verkuil, Nicolas Dufresne, Zhou Peng,
	Frank Li, linux-imx, imx, linux-media, linux-kernel

Hi Frank,

On Mon, Nov 23, 2026 at 03:54:12PM -0500, Frank Li wrote:
> On Thu, Nov 19, 2026 at 04:27:14PM +0900, Ming Qian wrote:
> > Allow applications to allocate raw frame buffers with
> > V4L2_MEMORY_FLAG_NON_COHERENT for efficient CPU access. The required
> > cache synchronization is handled by videobuf2 in its prepare() and
> > finish() methods.
> >
> > Set allow_cache_hints only for the encoder OUTPUT and decoder CAPTURE
> > queues. Leave it disabled for compressed bitstream queues, as the
> > driver may access their payloads through the CPU.
> 
> "V4L2_MEMORY_FLAG_NON_COHERENT for efficient CPU access", but here
> "Leave it disabled for compressed bitstream queues, as the
>  driver may access their payloads through the CPU"
> 
> Look like description is contradiction
> 
> Frank
> 

Sorry for the confusion. By "efficient CPU access", I meant userspace
access to linear frame buffers.

For linear frame buffers, V4L2_MEMORY_FLAG_NON_COHERENT enables cached
mmap access from userspace, while videobuf2 maintains coherency through
prepare()/finish() during QBUF/DQBUF processing.

For compressed buffers, the amphion driver copies data into the
internal ring stream buffer when decoding, and out of it when encoding.
Enabling non-coherent allocation for these buffers would require
additional synchronization around those CPU copies.

This patch therefore enables the option only for linear frame buffers
and leaves compressed bitstream queues unchanged.

Regards,
Ming

> >
> > Signed-off-by: Ming Qian <ming.qian@oss.nxp.com>
> > ---
> >  drivers/media/platform/amphion/vpu_v4l2.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/drivers/media/platform/amphion/vpu_v4l2.c b/drivers/media/platform/amphion/vpu_v4l2.c
> > index 7cccc994fc50..c8d52f0af879 100644
> > --- a/drivers/media/platform/amphion/vpu_v4l2.c
> > +++ b/drivers/media/platform/amphion/vpu_v4l2.c
> > @@ -664,6 +664,8 @@ static int vpu_m2m_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_q
> >  	src_vq->mem_ops = &vb2_dma_contig_memops;
> >  	if (inst->type == VPU_CORE_TYPE_DEC && inst->use_stream_buffer)
> >  		src_vq->mem_ops = &vb2_vmalloc_memops;
> > +	if (inst->type == VPU_CORE_TYPE_ENC)
> > +		src_vq->allow_cache_hints = 1;
> >  	src_vq->drv_priv = inst;
> >  	src_vq->buf_struct_size = sizeof(struct vpu_vb2_buffer);
> >  	src_vq->dev = inst->vpu->dev;
> > @@ -680,6 +682,8 @@ static int vpu_m2m_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_q
> >  	dst_vq->mem_ops = &vb2_dma_contig_memops;
> >  	if (inst->type == VPU_CORE_TYPE_ENC && inst->use_stream_buffer)
> >  		dst_vq->mem_ops = &vb2_vmalloc_memops;
> > +	if (inst->type == VPU_CORE_TYPE_DEC)
> > +		dst_vq->allow_cache_hints = 1;
> >  	dst_vq->drv_priv = inst;
> >  	dst_vq->buf_struct_size = sizeof(struct vpu_vb2_buffer);
> >  	dst_vq->dev = inst->vpu->dev;
> >
> > ---
> > base-commit: 7969a6f407cf55b5254c824c87875452655ef11e
> > change-id: 20261119-amphion-non-coherent-f61009334dff
> >

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] media: amphion: Enable non-coherent allocation for raw frame buffers
  2026-11-24  5:42   ` Ming Qian(OSS)
@ 2026-11-24 16:45     ` Frank Li
  0 siblings, 0 replies; 4+ messages in thread
From: Frank Li @ 2026-11-24 16:45 UTC (permalink / raw)
  To: Ming Qian(OSS)
  Cc: Mauro Carvalho Chehab, Hans Verkuil, Nicolas Dufresne, Zhou Peng,
	Frank Li, linux-imx, imx, linux-media, linux-kernel

On Tue, Nov 24, 2026 at 02:42:19PM +0900, Ming Qian(OSS) wrote:
> Hi Frank,
>
> On Mon, Nov 23, 2026 at 03:54:12PM -0500, Frank Li wrote:
> > On Thu, Nov 19, 2026 at 04:27:14PM +0900, Ming Qian wrote:
> > > Allow applications to allocate raw frame buffers with
> > > V4L2_MEMORY_FLAG_NON_COHERENT for efficient CPU access. The required
> > > cache synchronization is handled by videobuf2 in its prepare() and
> > > finish() methods.
> > >
> > > Set allow_cache_hints only for the encoder OUTPUT and decoder CAPTURE
> > > queues. Leave it disabled for compressed bitstream queues, as the
> > > driver may access their payloads through the CPU.
> >
> > "V4L2_MEMORY_FLAG_NON_COHERENT for efficient CPU access", but here
> > "Leave it disabled for compressed bitstream queues, as the
> >  driver may access their payloads through the CPU"
> >
> > Look like description is contradiction
> >
> > Frank
> >
>
> Sorry for the confusion. By "efficient CPU access", I meant userspace
> access to linear frame buffers.
>
> For linear frame buffers, V4L2_MEMORY_FLAG_NON_COHERENT enables cached
> mmap access from userspace, while videobuf2 maintains coherency through
> prepare()/finish() during QBUF/DQBUF processing.
>
> For compressed buffers, the amphion driver copies data into the
> internal ring stream buffer when decoding, and out of it when encoding.
> Enabling non-coherent allocation for these buffers would require
> additional synchronization around those CPU copies.
>
> This patch therefore enables the option only for linear frame buffers
> and leaves compressed bitstream queues unchanged.

Okay, is it more clean

For compressed buffers, driver simple copy data into internal buffer and
non-coherent can't bring much benefit and involve additional
synchronization.

Frank

>
> Regards,
> Ming
>
> > >
> > > Signed-off-by: Ming Qian <ming.qian@oss.nxp.com>
> > > ---
> > >  drivers/media/platform/amphion/vpu_v4l2.c | 4 ++++
> > >  1 file changed, 4 insertions(+)
> > >
> > > diff --git a/drivers/media/platform/amphion/vpu_v4l2.c b/drivers/media/platform/amphion/vpu_v4l2.c
> > > index 7cccc994fc50..c8d52f0af879 100644
> > > --- a/drivers/media/platform/amphion/vpu_v4l2.c
> > > +++ b/drivers/media/platform/amphion/vpu_v4l2.c
> > > @@ -664,6 +664,8 @@ static int vpu_m2m_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_q
> > >  	src_vq->mem_ops = &vb2_dma_contig_memops;
> > >  	if (inst->type == VPU_CORE_TYPE_DEC && inst->use_stream_buffer)
> > >  		src_vq->mem_ops = &vb2_vmalloc_memops;
> > > +	if (inst->type == VPU_CORE_TYPE_ENC)
> > > +		src_vq->allow_cache_hints = 1;
> > >  	src_vq->drv_priv = inst;
> > >  	src_vq->buf_struct_size = sizeof(struct vpu_vb2_buffer);
> > >  	src_vq->dev = inst->vpu->dev;
> > > @@ -680,6 +682,8 @@ static int vpu_m2m_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_q
> > >  	dst_vq->mem_ops = &vb2_dma_contig_memops;
> > >  	if (inst->type == VPU_CORE_TYPE_ENC && inst->use_stream_buffer)
> > >  		dst_vq->mem_ops = &vb2_vmalloc_memops;
> > > +	if (inst->type == VPU_CORE_TYPE_DEC)
> > > +		dst_vq->allow_cache_hints = 1;
> > >  	dst_vq->drv_priv = inst;
> > >  	dst_vq->buf_struct_size = sizeof(struct vpu_vb2_buffer);
> > >  	dst_vq->dev = inst->vpu->dev;
> > >
> > > ---
> > > base-commit: 7969a6f407cf55b5254c824c87875452655ef11e
> > > change-id: 20261119-amphion-non-coherent-f61009334dff
> > >

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-24 16:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19  7:27 [PATCH] media: amphion: Enable non-coherent allocation for raw frame buffers Ming Qian
2026-11-23 20:54 ` Frank Li
2026-11-24  5:42   ` Ming Qian(OSS)
2026-11-24 16:45     ` Frank Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox