From: Benjamin Gaignard <benjamin.gaignard@collabora.com>
To: nicolas.dufresne@collabora.com, benjamin.gaignard@collabora.com,
p.zabel@pengutronix.de, mchehab@kernel.org
Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org,
linux-kernel@vger.kernel.org, kernel@collabora.com
Subject: [PATCH v1 1/7] media: verisilicon: Add helpers to allocate and free auxiliary buffers
Date: Wed, 16 Sep 2026 14:54:37 +0200 [thread overview]
Message-ID: <20260916125443.78602-2-benjamin.gaignard@collabora.com> (raw)
In-Reply-To: <20260916125443.78602-1-benjamin.gaignard@collabora.com>
Add helpers functions to allocate and free the auxiliary buffers.
That simplify the code and make it more easy to read and maintain.
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
---
drivers/media/platform/verisilicon/hantro.h | 4 +++
.../platform/verisilicon/hantro_postproc.c | 21 ++---------
.../media/platform/verisilicon/hantro_v4l2.c | 35 +++++++++++++++++++
3 files changed, 42 insertions(+), 18 deletions(-)
diff --git a/drivers/media/platform/verisilicon/hantro.h b/drivers/media/platform/verisilicon/hantro.h
index 0353de154a1e..f2f02522a543 100644
--- a/drivers/media/platform/verisilicon/hantro.h
+++ b/drivers/media/platform/verisilicon/hantro.h
@@ -507,4 +507,8 @@ void hantro_postproc_free(struct hantro_ctx *ctx);
int hanto_postproc_enum_framesizes(struct hantro_ctx *ctx,
struct v4l2_frmsizeenum *fsize);
+int hantro_allocate_aux_buf(struct hantro_ctx *ctx, struct hantro_aux_buf *aux_buf,
+ size_t size);
+void hantro_free_aux_buf(struct hantro_ctx *ctx, struct hantro_aux_buf *aux_buf);
+
#endif /* HANTRO_H_ */
diff --git a/drivers/media/platform/verisilicon/hantro_postproc.c b/drivers/media/platform/verisilicon/hantro_postproc.c
index e94d1ba5ef10..3e202076bd2f 100644
--- a/drivers/media/platform/verisilicon/hantro_postproc.c
+++ b/drivers/media/platform/verisilicon/hantro_postproc.c
@@ -180,7 +180,6 @@ static int hantro_postproc_g2_enum_framesizes(struct hantro_ctx *ctx,
void hantro_postproc_free(struct hantro_ctx *ctx)
{
- struct hantro_dev *vpu = ctx->dev;
struct v4l2_m2m_ctx *m2m_ctx = ctx->fh.m2m_ctx;
struct vb2_queue *queue = &m2m_ctx->cap_q_ctx.q;
unsigned int i;
@@ -188,11 +187,7 @@ void hantro_postproc_free(struct hantro_ctx *ctx)
for (i = 0; i < queue->max_num_buffers; ++i) {
struct hantro_aux_buf *priv = &ctx->postproc.dec_q[i];
- if (priv->cpu) {
- dma_free_attrs(vpu->dev, priv->size, priv->cpu,
- priv->dma, priv->attrs);
- priv->cpu = NULL;
- }
+ hantro_free_aux_buf(ctx, priv);
}
}
@@ -223,7 +218,6 @@ static unsigned int hantro_postproc_buffer_size(struct hantro_ctx *ctx)
static int hantro_postproc_alloc(struct hantro_ctx *ctx, int index)
{
- struct hantro_dev *vpu = ctx->dev;
struct hantro_aux_buf *priv = &ctx->postproc.dec_q[index];
unsigned int buf_size = hantro_postproc_buffer_size(ctx);
@@ -235,13 +229,7 @@ static int hantro_postproc_alloc(struct hantro_ctx *ctx, int index)
* buffers for the decoder, so no mapping is needed.
*/
priv->attrs = DMA_ATTR_NO_KERNEL_MAPPING;
- priv->cpu = dma_alloc_attrs(vpu->dev, buf_size, &priv->dma,
- GFP_KERNEL, priv->attrs);
- if (!priv->cpu)
- return -ENOMEM;
- priv->size = buf_size;
-
- return 0;
+ return hantro_allocate_aux_buf(ctx, priv, buf_size);
}
int hantro_postproc_init(struct hantro_ctx *ctx)
@@ -268,14 +256,11 @@ hantro_postproc_get_dec_buf_addr(struct hantro_ctx *ctx, int index)
{
struct hantro_aux_buf *priv = &ctx->postproc.dec_q[index];
unsigned int buf_size = hantro_postproc_buffer_size(ctx);
- struct hantro_dev *vpu = ctx->dev;
int ret;
if (priv->size < buf_size && priv->cpu) {
/* buffer is too small, release it */
- dma_free_attrs(vpu->dev, priv->size, priv->cpu,
- priv->dma, priv->attrs);
- priv->cpu = NULL;
+ hantro_free_aux_buf(ctx, priv);
}
if (!priv->cpu) {
diff --git a/drivers/media/platform/verisilicon/hantro_v4l2.c b/drivers/media/platform/verisilicon/hantro_v4l2.c
index 83af9fa1ce94..ec12950a1ae1 100644
--- a/drivers/media/platform/verisilicon/hantro_v4l2.c
+++ b/drivers/media/platform/verisilicon/hantro_v4l2.c
@@ -1029,3 +1029,38 @@ const struct vb2_ops hantro_queue_ops = {
.start_streaming = hantro_start_streaming,
.stop_streaming = hantro_stop_streaming,
};
+
+int hantro_allocate_aux_buf(struct hantro_ctx *ctx, struct hantro_aux_buf *aux_buf,
+ size_t size)
+{
+ struct hantro_dev *vpu = ctx->dev;
+
+ if (!aux_buf || !ctx || !size)
+ return -EINVAL;
+
+ aux_buf->cpu = dma_alloc_attrs(vpu->dev, size,
+ &aux_buf->dma,
+ GFP_KERNEL,
+ aux_buf->attrs);
+ if (!aux_buf->cpu)
+ return -ENOMEM;
+
+ aux_buf->size = size;
+
+ return 0;
+}
+
+void hantro_free_aux_buf(struct hantro_ctx *ctx, struct hantro_aux_buf *aux_buf)
+{
+ struct hantro_dev *vpu = ctx->dev;
+
+ if (!aux_buf || !ctx)
+ return;
+
+ if (aux_buf->cpu)
+ dma_free_attrs(vpu->dev, aux_buf->size,
+ aux_buf->cpu, aux_buf->dma,
+ aux_buf->attrs);
+ aux_buf->cpu = NULL;
+ aux_buf->size = 0;
+}
--
2.53.0
next prev parent reply other threads:[~2026-09-16 12:54 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-16 12:54 [PATCH v1 0/7] media: verisilicon: simplify auxiliary buffers allocation Benjamin Gaignard
2026-09-16 12:54 ` Benjamin Gaignard [this message]
2026-09-16 12:54 ` [PATCH v1 2/7] media: verisilicon: AV1: Use alloc/free helpers for auxiliary buffers Benjamin Gaignard
2026-09-16 12:54 ` [PATCH v1 3/7] media: verisilicon: h264: " Benjamin Gaignard
2026-09-16 12:54 ` [PATCH v1 4/7] media: verisilicon: hevc: " Benjamin Gaignard
2026-09-16 12:54 ` [PATCH v1 5/7] media: verisilicon: vp8: " Benjamin Gaignard
2026-09-16 12:54 ` [PATCH v1 6/7] media: verisilicon: vp9: " Benjamin Gaignard
2026-09-16 12:54 ` [PATCH v1 7/7] media: verisilicon: mpeg4: " Benjamin Gaignard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260916125443.78602-2-benjamin.gaignard@collabora.com \
--to=benjamin.gaignard@collabora.com \
--cc=kernel@collabora.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=mchehab@kernel.org \
--cc=nicolas.dufresne@collabora.com \
--cc=p.zabel@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®