* [PATCH v1 1/7] media: verisilicon: Add helpers to allocate and free auxiliary buffers
2026-09-16 12:54 [PATCH v1 0/7] media: verisilicon: simplify auxiliary buffers allocation Benjamin Gaignard
@ 2026-09-16 12:54 ` Benjamin Gaignard
2026-09-16 12:54 ` [PATCH v1 2/7] media: verisilicon: AV1: Use alloc/free helpers for " Benjamin Gaignard
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Benjamin Gaignard @ 2026-09-16 12:54 UTC (permalink / raw)
To: nicolas.dufresne, benjamin.gaignard, p.zabel, mchehab
Cc: linux-media, linux-rockchip, linux-kernel, kernel
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
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH v1 2/7] media: verisilicon: AV1: Use alloc/free helpers for auxiliary buffers
2026-09-16 12:54 [PATCH v1 0/7] media: verisilicon: simplify auxiliary buffers allocation Benjamin Gaignard
2026-09-16 12:54 ` [PATCH v1 1/7] media: verisilicon: Add helpers to allocate and free auxiliary buffers Benjamin Gaignard
@ 2026-09-16 12:54 ` Benjamin Gaignard
2026-09-16 12:54 ` [PATCH v1 3/7] media: verisilicon: h264: " Benjamin Gaignard
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Benjamin Gaignard @ 2026-09-16 12:54 UTC (permalink / raw)
To: nicolas.dufresne, benjamin.gaignard, p.zabel, mchehab
Cc: linux-media, linux-rockchip, linux-kernel, kernel
Simplify and clean up the code by using the helpers.
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
---
.../media/platform/verisilicon/hantro_av1.c | 177 ++++--------------
1 file changed, 39 insertions(+), 138 deletions(-)
diff --git a/drivers/media/platform/verisilicon/hantro_av1.c b/drivers/media/platform/verisilicon/hantro_av1.c
index 2cde32f0e935..e05816c7dfa3 100644
--- a/drivers/media/platform/verisilicon/hantro_av1.c
+++ b/drivers/media/platform/verisilicon/hantro_av1.c
@@ -235,40 +235,17 @@ size_t hantro_av1_chroma_size(struct hantro_ctx *ctx)
static void hantro_av1_tiles_free(struct hantro_ctx *ctx)
{
- struct hantro_dev *vpu = ctx->dev;
struct hantro_av1_dec_hw_ctx *av1_dec = &ctx->av1_dec;
- if (av1_dec->db_data_col.cpu)
- dma_free_coherent(vpu->dev, av1_dec->db_data_col.size,
- av1_dec->db_data_col.cpu,
- av1_dec->db_data_col.dma);
- av1_dec->db_data_col.cpu = NULL;
-
- if (av1_dec->db_ctrl_col.cpu)
- dma_free_coherent(vpu->dev, av1_dec->db_ctrl_col.size,
- av1_dec->db_ctrl_col.cpu,
- av1_dec->db_ctrl_col.dma);
- av1_dec->db_ctrl_col.cpu = NULL;
-
- if (av1_dec->cdef_col.cpu)
- dma_free_coherent(vpu->dev, av1_dec->cdef_col.size,
- av1_dec->cdef_col.cpu, av1_dec->cdef_col.dma);
- av1_dec->cdef_col.cpu = NULL;
-
- if (av1_dec->sr_col.cpu)
- dma_free_coherent(vpu->dev, av1_dec->sr_col.size,
- av1_dec->sr_col.cpu, av1_dec->sr_col.dma);
- av1_dec->sr_col.cpu = NULL;
-
- if (av1_dec->lr_col.cpu)
- dma_free_coherent(vpu->dev, av1_dec->lr_col.size,
- av1_dec->lr_col.cpu, av1_dec->lr_col.dma);
- av1_dec->lr_col.cpu = NULL;
+ hantro_free_aux_buf(ctx, &av1_dec->db_data_col);
+ hantro_free_aux_buf(ctx, &av1_dec->db_ctrl_col);
+ hantro_free_aux_buf(ctx, &av1_dec->cdef_col);
+ hantro_free_aux_buf(ctx, &av1_dec->sr_col);
+ hantro_free_aux_buf(ctx, &av1_dec->lr_col);
}
static int hantro_av1_tiles_reallocate(struct hantro_ctx *ctx)
{
- struct hantro_dev *vpu = ctx->dev;
struct hantro_av1_dec_hw_ctx *av1_dec = &ctx->av1_dec;
struct hantro_av1_dec_ctrls *ctrls = &av1_dec->ctrls;
const struct v4l2_av1_tile_info *tile_info = &ctrls->frame->tile_info;
@@ -277,6 +254,7 @@ static int hantro_av1_tiles_reallocate(struct hantro_ctx *ctx)
unsigned int height_in_sb = height / 64;
unsigned int stripe_num = ((height + 8) + 63) / 64;
size_t size;
+ int ret;
if (av1_dec->db_data_col.size >=
ALIGN(height * 12 * ctx->bit_depth / 8, 128) * num_tile_cols)
@@ -285,44 +263,22 @@ static int hantro_av1_tiles_reallocate(struct hantro_ctx *ctx)
hantro_av1_tiles_free(ctx);
size = ALIGN(height * 12 * ctx->bit_depth / 8, 128) * num_tile_cols;
- av1_dec->db_data_col.cpu = dma_alloc_coherent(vpu->dev, size,
- &av1_dec->db_data_col.dma,
- GFP_KERNEL);
- if (!av1_dec->db_data_col.cpu)
- goto buffer_allocation_error;
- av1_dec->db_data_col.size = size;
+ ret = hantro_allocate_aux_buf(ctx, &av1_dec->db_data_col, size);
size = ALIGN(height * 2 * 16 / 4, 128) * num_tile_cols;
- av1_dec->db_ctrl_col.cpu = dma_alloc_coherent(vpu->dev, size,
- &av1_dec->db_ctrl_col.dma,
- GFP_KERNEL);
- if (!av1_dec->db_ctrl_col.cpu)
- goto buffer_allocation_error;
- av1_dec->db_ctrl_col.size = size;
+ ret |= hantro_allocate_aux_buf(ctx, &av1_dec->db_ctrl_col, size);
size = ALIGN(height_in_sb * 44 * ctx->bit_depth * 16 / 8, 128) * num_tile_cols;
- av1_dec->cdef_col.cpu = dma_alloc_coherent(vpu->dev, size,
- &av1_dec->cdef_col.dma,
- GFP_KERNEL);
- if (!av1_dec->cdef_col.cpu)
- goto buffer_allocation_error;
- av1_dec->cdef_col.size = size;
+ ret |= hantro_allocate_aux_buf(ctx, &av1_dec->cdef_col, size);
size = ALIGN(height_in_sb * (3040 + 1280), 128) * num_tile_cols;
- av1_dec->sr_col.cpu = dma_alloc_coherent(vpu->dev, size,
- &av1_dec->sr_col.dma,
- GFP_KERNEL);
- if (!av1_dec->sr_col.cpu)
- goto buffer_allocation_error;
- av1_dec->sr_col.size = size;
+ ret |= hantro_allocate_aux_buf(ctx, &av1_dec->sr_col, size);
size = ALIGN(stripe_num * 1536 * ctx->bit_depth / 8, 128) * num_tile_cols;
- av1_dec->lr_col.cpu = dma_alloc_coherent(vpu->dev, size,
- &av1_dec->lr_col.dma,
- GFP_KERNEL);
- if (!av1_dec->lr_col.cpu)
+ ret |= hantro_allocate_aux_buf(ctx, &av1_dec->lr_col, size);
+
+ if (ret)
goto buffer_allocation_error;
- av1_dec->lr_col.size = size;
av1_dec->num_tile_cols_allocated = num_tile_cols;
return 0;
@@ -334,105 +290,50 @@ static int hantro_av1_tiles_reallocate(struct hantro_ctx *ctx)
void hantro_av1_exit(struct hantro_ctx *ctx)
{
- struct hantro_dev *vpu = ctx->dev;
struct hantro_av1_dec_hw_ctx *av1_dec = &ctx->av1_dec;
- if (av1_dec->global_model.cpu)
- dma_free_coherent(vpu->dev, av1_dec->global_model.size,
- av1_dec->global_model.cpu,
- av1_dec->global_model.dma);
- av1_dec->global_model.cpu = NULL;
-
- if (av1_dec->tile_info.cpu)
- dma_free_coherent(vpu->dev, av1_dec->tile_info.size,
- av1_dec->tile_info.cpu,
- av1_dec->tile_info.dma);
- av1_dec->tile_info.cpu = NULL;
-
- if (av1_dec->film_grain.cpu)
- dma_free_coherent(vpu->dev, av1_dec->film_grain.size,
- av1_dec->film_grain.cpu,
- av1_dec->film_grain.dma);
- av1_dec->film_grain.cpu = NULL;
-
- if (av1_dec->prob_tbl.cpu)
- dma_free_coherent(vpu->dev, av1_dec->prob_tbl.size,
- av1_dec->prob_tbl.cpu, av1_dec->prob_tbl.dma);
- av1_dec->prob_tbl.cpu = NULL;
-
- if (av1_dec->prob_tbl_out.cpu)
- dma_free_coherent(vpu->dev, av1_dec->prob_tbl_out.size,
- av1_dec->prob_tbl_out.cpu,
- av1_dec->prob_tbl_out.dma);
- av1_dec->prob_tbl_out.cpu = NULL;
-
- if (av1_dec->tile_buf.cpu)
- dma_free_coherent(vpu->dev, av1_dec->tile_buf.size,
- av1_dec->tile_buf.cpu, av1_dec->tile_buf.dma);
- av1_dec->tile_buf.cpu = NULL;
+ hantro_free_aux_buf(ctx, &av1_dec->global_model);
+ hantro_free_aux_buf(ctx, &av1_dec->tile_info);
+ hantro_free_aux_buf(ctx, &av1_dec->film_grain);
+ hantro_free_aux_buf(ctx, &av1_dec->prob_tbl);
+ hantro_free_aux_buf(ctx, &av1_dec->prob_tbl_out);
hantro_av1_tiles_free(ctx);
}
int hantro_av1_init(struct hantro_ctx *ctx)
{
- struct hantro_dev *vpu = ctx->dev;
struct hantro_av1_dec_hw_ctx *av1_dec = &ctx->av1_dec;
+ int ret = 0;
memset(av1_dec, 0, sizeof(*av1_dec));
- av1_dec->global_model.cpu = dma_alloc_coherent(vpu->dev, GLOBAL_MODEL_SIZE,
- &av1_dec->global_model.dma,
- GFP_KERNEL);
- if (!av1_dec->global_model.cpu)
- return -ENOMEM;
- av1_dec->global_model.size = GLOBAL_MODEL_SIZE;
-
- av1_dec->tile_info.cpu = dma_alloc_coherent(vpu->dev, AV1_TILE_INFO_SIZE,
- &av1_dec->tile_info.dma,
- GFP_KERNEL);
- if (!av1_dec->tile_info.cpu)
- return -ENOMEM;
- av1_dec->tile_info.size = AV1_TILE_INFO_SIZE;
-
- av1_dec->film_grain.cpu = dma_alloc_coherent(vpu->dev,
- ALIGN(sizeof(struct hantro_av1_film_grain),
- 2048),
- &av1_dec->film_grain.dma,
- GFP_KERNEL);
- if (!av1_dec->film_grain.cpu)
- return -ENOMEM;
- av1_dec->film_grain.size = ALIGN(sizeof(struct hantro_av1_film_grain), 2048);
-
- av1_dec->prob_tbl.cpu = dma_alloc_coherent(vpu->dev,
- ALIGN(sizeof(struct av1cdfs), 2048),
- &av1_dec->prob_tbl.dma,
- GFP_KERNEL);
- if (!av1_dec->prob_tbl.cpu)
- return -ENOMEM;
- av1_dec->prob_tbl.size = ALIGN(sizeof(struct av1cdfs), 2048);
-
- av1_dec->prob_tbl_out.cpu = dma_alloc_coherent(vpu->dev,
- ALIGN(sizeof(struct av1cdfs), 2048),
- &av1_dec->prob_tbl_out.dma,
- GFP_KERNEL);
- if (!av1_dec->prob_tbl_out.cpu)
- return -ENOMEM;
- av1_dec->prob_tbl_out.size = ALIGN(sizeof(struct av1cdfs), 2048);
+ ret |= hantro_allocate_aux_buf(ctx, &av1_dec->global_model, GLOBAL_MODEL_SIZE);
+ ret |= hantro_allocate_aux_buf(ctx, &av1_dec->tile_info, AV1_TILE_INFO_SIZE);
+ ret |= hantro_allocate_aux_buf(ctx, &av1_dec->film_grain,
+ ALIGN(sizeof(struct hantro_av1_film_grain), 2048));
+ ret |= hantro_allocate_aux_buf(ctx, &av1_dec->prob_tbl,
+ ALIGN(sizeof(struct av1cdfs), 2048));
+ ret |= hantro_allocate_aux_buf(ctx, &av1_dec->prob_tbl_out,
+ ALIGN(sizeof(struct av1cdfs), 2048));
+ if (ret)
+ goto buffer_allocation_error;
+
av1_dec->cdfs = &av1_dec->default_cdfs;
av1_dec->cdfs_ndvc = &av1_dec->default_cdfs_ndvc;
hantro_av1_set_default_cdfs(av1_dec->cdfs, av1_dec->cdfs_ndvc);
- av1_dec->tile_buf.cpu = dma_alloc_coherent(vpu->dev,
- AV1_TILE_SIZE,
- &av1_dec->tile_buf.dma,
- GFP_KERNEL);
- if (!av1_dec->tile_buf.cpu)
- return -ENOMEM;
- av1_dec->tile_buf.size = AV1_TILE_SIZE;
-
return 0;
+
+buffer_allocation_error:
+ hantro_free_aux_buf(ctx, &av1_dec->global_model);
+ hantro_free_aux_buf(ctx, &av1_dec->tile_info);
+ hantro_free_aux_buf(ctx, &av1_dec->film_grain);
+ hantro_free_aux_buf(ctx, &av1_dec->prob_tbl);
+ hantro_free_aux_buf(ctx, &av1_dec->prob_tbl_out);
+
+ return -ENOMEM;
}
int hantro_av1_prepare_run(struct hantro_ctx *ctx)
--
2.53.0
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH v1 3/7] media: verisilicon: h264: Use alloc/free helpers for auxiliary buffers
2026-09-16 12:54 [PATCH v1 0/7] media: verisilicon: simplify auxiliary buffers allocation Benjamin Gaignard
2026-09-16 12:54 ` [PATCH v1 1/7] media: verisilicon: Add helpers to allocate and free auxiliary buffers Benjamin Gaignard
2026-09-16 12:54 ` [PATCH v1 2/7] media: verisilicon: AV1: Use alloc/free helpers for " Benjamin Gaignard
@ 2026-09-16 12:54 ` Benjamin Gaignard
2026-09-16 12:54 ` [PATCH v1 4/7] media: verisilicon: hevc: " Benjamin Gaignard
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Benjamin Gaignard @ 2026-09-16 12:54 UTC (permalink / raw)
To: nicolas.dufresne, benjamin.gaignard, p.zabel, mchehab
Cc: linux-media, linux-rockchip, linux-kernel, kernel
Simplify and clean up the code by using the helpers.
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
---
drivers/media/platform/verisilicon/hantro_h264.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/drivers/media/platform/verisilicon/hantro_h264.c b/drivers/media/platform/verisilicon/hantro_h264.c
index 2414782f1eb6..68dde1cd1ac2 100644
--- a/drivers/media/platform/verisilicon/hantro_h264.c
+++ b/drivers/media/platform/verisilicon/hantro_h264.c
@@ -494,26 +494,21 @@ int hantro_h264_dec_prepare_run(struct hantro_ctx *ctx)
void hantro_h264_dec_exit(struct hantro_ctx *ctx)
{
- struct hantro_dev *vpu = ctx->dev;
struct hantro_h264_dec_hw_ctx *h264_dec = &ctx->h264_dec;
struct hantro_aux_buf *priv = &h264_dec->priv;
- dma_free_coherent(vpu->dev, priv->size, priv->cpu, priv->dma);
+ hantro_free_aux_buf(ctx, priv);
}
int hantro_h264_dec_init(struct hantro_ctx *ctx)
{
- struct hantro_dev *vpu = ctx->dev;
struct hantro_h264_dec_hw_ctx *h264_dec = &ctx->h264_dec;
struct hantro_aux_buf *priv = &h264_dec->priv;
struct hantro_h264_dec_priv_tbl *tbl;
- priv->cpu = dma_alloc_coherent(vpu->dev, sizeof(*tbl), &priv->dma,
- GFP_KERNEL);
- if (!priv->cpu)
+ if (hantro_allocate_aux_buf(ctx, priv, sizeof(*tbl)))
return -ENOMEM;
- priv->size = sizeof(*tbl);
tbl = priv->cpu;
memcpy(tbl->cabac_table, h264_cabac_table, sizeof(tbl->cabac_table));
--
2.53.0
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH v1 4/7] media: verisilicon: hevc: Use alloc/free helpers for auxiliary buffers
2026-09-16 12:54 [PATCH v1 0/7] media: verisilicon: simplify auxiliary buffers allocation Benjamin Gaignard
` (2 preceding siblings ...)
2026-09-16 12:54 ` [PATCH v1 3/7] media: verisilicon: h264: " Benjamin Gaignard
@ 2026-09-16 12:54 ` Benjamin Gaignard
2026-09-16 12:54 ` [PATCH v1 5/7] media: verisilicon: vp8: " Benjamin Gaignard
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Benjamin Gaignard @ 2026-09-16 12:54 UTC (permalink / raw)
To: nicolas.dufresne, benjamin.gaignard, p.zabel, mchehab
Cc: linux-media, linux-rockchip, linux-kernel, kernel
Simplify and clean up the code by using the helpers.
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
---
.../media/platform/verisilicon/hantro_hevc.c | 130 +++++-------------
1 file changed, 33 insertions(+), 97 deletions(-)
diff --git a/drivers/media/platform/verisilicon/hantro_hevc.c b/drivers/media/platform/verisilicon/hantro_hevc.c
index 83cd12b0ddd6..cc6fa233c0a0 100644
--- a/drivers/media/platform/verisilicon/hantro_hevc.c
+++ b/drivers/media/platform/verisilicon/hantro_hevc.c
@@ -74,7 +74,6 @@ int hantro_hevc_add_ref_buf(struct hantro_ctx *ctx, int poc, dma_addr_t addr)
static int tile_buffer_reallocate(struct hantro_ctx *ctx)
{
- struct hantro_dev *vpu = ctx->dev;
struct hantro_hevc_dec_hw_ctx *hevc_dec = &ctx->hevc_dec;
const struct hantro_hevc_dec_ctrls *ctrls = &ctx->hevc_dec.ctrls;
const struct v4l2_ctrl_hevc_pps *pps = ctrls->pps;
@@ -82,74 +81,40 @@ static int tile_buffer_reallocate(struct hantro_ctx *ctx)
unsigned int num_tile_cols = pps->num_tile_columns_minus1 + 1;
unsigned int height64 = (sps->pic_height_in_luma_samples + 63) & ~63;
unsigned int size;
+ int ret;
if (num_tile_cols <= 1 ||
num_tile_cols <= hevc_dec->num_tile_cols_allocated)
return 0;
/* Need to reallocate due to tiles passed via PPS */
- if (hevc_dec->tile_filter.cpu) {
- dma_free_coherent(vpu->dev, hevc_dec->tile_filter.size,
- hevc_dec->tile_filter.cpu,
- hevc_dec->tile_filter.dma);
- hevc_dec->tile_filter.cpu = NULL;
- }
-
- if (hevc_dec->tile_sao.cpu) {
- dma_free_coherent(vpu->dev, hevc_dec->tile_sao.size,
- hevc_dec->tile_sao.cpu,
- hevc_dec->tile_sao.dma);
- hevc_dec->tile_sao.cpu = NULL;
- }
-
- if (hevc_dec->tile_bsd.cpu) {
- dma_free_coherent(vpu->dev, hevc_dec->tile_bsd.size,
- hevc_dec->tile_bsd.cpu,
- hevc_dec->tile_bsd.dma);
- hevc_dec->tile_bsd.cpu = NULL;
- }
+ hantro_free_aux_buf(ctx, &hevc_dec->tile_filter);
+ hantro_free_aux_buf(ctx, &hevc_dec->tile_sao);
+ hantro_free_aux_buf(ctx, &hevc_dec->tile_bsd);
size = (VERT_FILTER_RAM_SIZE * height64 * (num_tile_cols - 1) * ctx->bit_depth) / 8;
- hevc_dec->tile_filter.cpu = dma_alloc_coherent(vpu->dev, size,
- &hevc_dec->tile_filter.dma,
- GFP_KERNEL);
- if (!hevc_dec->tile_filter.cpu)
- return -ENOMEM;
- hevc_dec->tile_filter.size = size;
+ hevc_dec->tile_filter.attrs = DMA_ATTR_NO_KERNEL_MAPPING;
+ ret = hantro_allocate_aux_buf(ctx, &hevc_dec->tile_filter, size);
size = (VERT_SAO_RAM_SIZE * height64 * (num_tile_cols - 1) * ctx->bit_depth) / 8;
- hevc_dec->tile_sao.cpu = dma_alloc_coherent(vpu->dev, size,
- &hevc_dec->tile_sao.dma,
- GFP_KERNEL);
- if (!hevc_dec->tile_sao.cpu)
- goto err_free_tile_buffers;
- hevc_dec->tile_sao.size = size;
+ hevc_dec->tile_sao.attrs = DMA_ATTR_NO_KERNEL_MAPPING;
+ ret |= hantro_allocate_aux_buf(ctx, &hevc_dec->tile_sao, size);
size = BSD_CTRL_RAM_SIZE * height64 * (num_tile_cols - 1);
- hevc_dec->tile_bsd.cpu = dma_alloc_coherent(vpu->dev, size,
- &hevc_dec->tile_bsd.dma,
- GFP_KERNEL);
- if (!hevc_dec->tile_bsd.cpu)
- goto err_free_sao_buffers;
- hevc_dec->tile_bsd.size = size;
+ hevc_dec->tile_bsd.attrs = DMA_ATTR_NO_KERNEL_MAPPING;
+ ret |= hantro_allocate_aux_buf(ctx, &hevc_dec->tile_bsd, size);
+
+ if (ret)
+ goto error;
hevc_dec->num_tile_cols_allocated = num_tile_cols;
return 0;
-err_free_sao_buffers:
- if (hevc_dec->tile_sao.cpu)
- dma_free_coherent(vpu->dev, hevc_dec->tile_sao.size,
- hevc_dec->tile_sao.cpu,
- hevc_dec->tile_sao.dma);
- hevc_dec->tile_sao.cpu = NULL;
-
-err_free_tile_buffers:
- if (hevc_dec->tile_filter.cpu)
- dma_free_coherent(vpu->dev, hevc_dec->tile_filter.size,
- hevc_dec->tile_filter.cpu,
- hevc_dec->tile_filter.dma);
- hevc_dec->tile_filter.cpu = NULL;
+error:
+ hantro_free_aux_buf(ctx, &hevc_dec->tile_filter);
+ hantro_free_aux_buf(ctx, &hevc_dec->tile_sao);
+ hantro_free_aux_buf(ctx, &hevc_dec->tile_bsd);
return -ENOMEM;
}
@@ -214,45 +179,20 @@ int hantro_hevc_dec_prepare_run(struct hantro_ctx *ctx)
void hantro_hevc_dec_exit(struct hantro_ctx *ctx)
{
- struct hantro_dev *vpu = ctx->dev;
struct hantro_hevc_dec_hw_ctx *hevc_dec = &ctx->hevc_dec;
- if (hevc_dec->tile_sizes.cpu)
- dma_free_coherent(vpu->dev, hevc_dec->tile_sizes.size,
- hevc_dec->tile_sizes.cpu,
- hevc_dec->tile_sizes.dma);
- hevc_dec->tile_sizes.cpu = NULL;
-
- if (hevc_dec->scaling_lists.cpu)
- dma_free_coherent(vpu->dev, hevc_dec->scaling_lists.size,
- hevc_dec->scaling_lists.cpu,
- hevc_dec->scaling_lists.dma);
- hevc_dec->scaling_lists.cpu = NULL;
-
- if (hevc_dec->tile_filter.cpu)
- dma_free_coherent(vpu->dev, hevc_dec->tile_filter.size,
- hevc_dec->tile_filter.cpu,
- hevc_dec->tile_filter.dma);
- hevc_dec->tile_filter.cpu = NULL;
-
- if (hevc_dec->tile_sao.cpu)
- dma_free_coherent(vpu->dev, hevc_dec->tile_sao.size,
- hevc_dec->tile_sao.cpu,
- hevc_dec->tile_sao.dma);
- hevc_dec->tile_sao.cpu = NULL;
-
- if (hevc_dec->tile_bsd.cpu)
- dma_free_coherent(vpu->dev, hevc_dec->tile_bsd.size,
- hevc_dec->tile_bsd.cpu,
- hevc_dec->tile_bsd.dma);
- hevc_dec->tile_bsd.cpu = NULL;
+ hantro_free_aux_buf(ctx, &hevc_dec->tile_sizes);
+ hantro_free_aux_buf(ctx, &hevc_dec->scaling_lists);
+ hantro_free_aux_buf(ctx, &hevc_dec->tile_filter);
+ hantro_free_aux_buf(ctx, &hevc_dec->tile_sao);
+ hantro_free_aux_buf(ctx, &hevc_dec->tile_bsd);
}
int hantro_hevc_dec_init(struct hantro_ctx *ctx)
{
- struct hantro_dev *vpu = ctx->dev;
struct hantro_hevc_dec_hw_ctx *hevc_dec = &ctx->hevc_dec;
unsigned int size;
+ int ret;
memset(hevc_dec, 0, sizeof(*hevc_dec));
@@ -262,21 +202,11 @@ int hantro_hevc_dec_init(struct hantro_ctx *ctx)
* chunk (HW guys wanted to have this).
*/
size = round_up(MAX_TILE_COLS * MAX_TILE_ROWS * 4 * sizeof(u16) + 16, 16);
- hevc_dec->tile_sizes.cpu = dma_alloc_coherent(vpu->dev, size,
- &hevc_dec->tile_sizes.dma,
- GFP_KERNEL);
- if (!hevc_dec->tile_sizes.cpu)
- return -ENOMEM;
-
- hevc_dec->tile_sizes.size = size;
-
- hevc_dec->scaling_lists.cpu = dma_alloc_coherent(vpu->dev, SCALING_LIST_SIZE,
- &hevc_dec->scaling_lists.dma,
- GFP_KERNEL);
- if (!hevc_dec->scaling_lists.cpu)
- return -ENOMEM;
+ ret = hantro_allocate_aux_buf(ctx, &hevc_dec->tile_sizes, size);
+ ret = hantro_allocate_aux_buf(ctx, &hevc_dec->scaling_lists, SCALING_LIST_SIZE);
- hevc_dec->scaling_lists.size = SCALING_LIST_SIZE;
+ if (ret)
+ goto error;
hantro_hevc_ref_init(ctx);
@@ -284,4 +214,10 @@ int hantro_hevc_dec_init(struct hantro_ctx *ctx)
hevc_use_compression & hantro_needs_postproc(ctx, ctx->vpu_dst_fmt);
return 0;
+
+error:
+ hantro_free_aux_buf(ctx, &hevc_dec->tile_sizes);
+ hantro_free_aux_buf(ctx, &hevc_dec->scaling_lists);
+
+ return -ENOMEM;
}
--
2.53.0
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH v1 5/7] media: verisilicon: vp8: Use alloc/free helpers for auxiliary buffers
2026-09-16 12:54 [PATCH v1 0/7] media: verisilicon: simplify auxiliary buffers allocation Benjamin Gaignard
` (3 preceding siblings ...)
2026-09-16 12:54 ` [PATCH v1 4/7] media: verisilicon: hevc: " Benjamin Gaignard
@ 2026-09-16 12:54 ` 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
6 siblings, 0 replies; 8+ messages in thread
From: Benjamin Gaignard @ 2026-09-16 12:54 UTC (permalink / raw)
To: nicolas.dufresne, benjamin.gaignard, p.zabel, mchehab
Cc: linux-media, linux-rockchip, linux-kernel, kernel
Simplify and clean up the code by using the helpers.
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
---
.../media/platform/verisilicon/hantro_vp8.c | 37 +++++--------------
1 file changed, 10 insertions(+), 27 deletions(-)
diff --git a/drivers/media/platform/verisilicon/hantro_vp8.c b/drivers/media/platform/verisilicon/hantro_vp8.c
index 381bc1d3bfda..881e6c21f0fa 100644
--- a/drivers/media/platform/verisilicon/hantro_vp8.c
+++ b/drivers/media/platform/verisilicon/hantro_vp8.c
@@ -144,11 +144,9 @@ void hantro_vp8_prob_update(struct hantro_ctx *ctx,
int hantro_vp8_dec_init(struct hantro_ctx *ctx)
{
- struct hantro_dev *vpu = ctx->dev;
struct hantro_aux_buf *aux_buf;
unsigned int mb_width, mb_height;
size_t segment_map_size;
- int ret;
/* segment map table size calculation */
mb_width = DIV_ROUND_UP(ctx->dst_fmt.width, 16);
@@ -160,42 +158,27 @@ int hantro_vp8_dec_init(struct hantro_ctx *ctx)
* And the data in segment map buffer must be set to all zero.
*/
aux_buf = &ctx->vp8_dec.segment_map;
- aux_buf->size = segment_map_size;
- aux_buf->cpu = dma_alloc_coherent(vpu->dev, aux_buf->size,
- &aux_buf->dma, GFP_KERNEL);
- if (!aux_buf->cpu)
- return -ENOMEM;
+ if (hantro_allocate_aux_buf(ctx, aux_buf, segment_map_size))
+ goto error;
/*
* Allocate probability table buffer,
* total 1208 bytes, 4K page is far enough.
*/
aux_buf = &ctx->vp8_dec.prob_tbl;
- aux_buf->size = sizeof(struct vp8_prob_tbl_packed);
- aux_buf->cpu = dma_alloc_coherent(vpu->dev, aux_buf->size,
- &aux_buf->dma, GFP_KERNEL);
- if (!aux_buf->cpu) {
- ret = -ENOMEM;
- goto err_free_seg_map;
- }
+ if (hantro_allocate_aux_buf(ctx, aux_buf, sizeof(struct vp8_prob_tbl_packed)))
+ goto error;
return 0;
-err_free_seg_map:
- dma_free_coherent(vpu->dev, ctx->vp8_dec.segment_map.size,
- ctx->vp8_dec.segment_map.cpu,
- ctx->vp8_dec.segment_map.dma);
-
- return ret;
+error:
+ hantro_free_aux_buf(ctx, &ctx->vp8_dec.segment_map);
+ hantro_free_aux_buf(ctx, &ctx->vp8_dec.prob_tbl);
+ return -ENOMEM;
}
void hantro_vp8_dec_exit(struct hantro_ctx *ctx)
{
- struct hantro_vp8_dec_hw_ctx *vp8_dec = &ctx->vp8_dec;
- struct hantro_dev *vpu = ctx->dev;
-
- dma_free_coherent(vpu->dev, vp8_dec->segment_map.size,
- vp8_dec->segment_map.cpu, vp8_dec->segment_map.dma);
- dma_free_coherent(vpu->dev, vp8_dec->prob_tbl.size,
- vp8_dec->prob_tbl.cpu, vp8_dec->prob_tbl.dma);
+ hantro_free_aux_buf(ctx, &ctx->vp8_dec.segment_map);
+ hantro_free_aux_buf(ctx, &ctx->vp8_dec.prob_tbl);
}
--
2.53.0
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH v1 6/7] media: verisilicon: vp9: Use alloc/free helpers for auxiliary buffers
2026-09-16 12:54 [PATCH v1 0/7] media: verisilicon: simplify auxiliary buffers allocation Benjamin Gaignard
` (4 preceding siblings ...)
2026-09-16 12:54 ` [PATCH v1 5/7] media: verisilicon: vp8: " Benjamin Gaignard
@ 2026-09-16 12:54 ` Benjamin Gaignard
2026-09-16 12:54 ` [PATCH v1 7/7] media: verisilicon: mpeg4: " Benjamin Gaignard
6 siblings, 0 replies; 8+ messages in thread
From: Benjamin Gaignard @ 2026-09-16 12:54 UTC (permalink / raw)
To: nicolas.dufresne, benjamin.gaignard, p.zabel, mchehab
Cc: linux-media, linux-rockchip, linux-kernel, kernel
Simplify and clean up the code by using the helpers.
For upstream it should be merged into only one commit.
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
---
.../media/platform/verisilicon/hantro_vp9.c | 37 ++++++-------------
1 file changed, 11 insertions(+), 26 deletions(-)
diff --git a/drivers/media/platform/verisilicon/hantro_vp9.c b/drivers/media/platform/verisilicon/hantro_vp9.c
index 566cd376c097..7a46a4767254 100644
--- a/drivers/media/platform/verisilicon/hantro_vp9.c
+++ b/drivers/media/platform/verisilicon/hantro_vp9.c
@@ -181,23 +181,17 @@ int hantro_vp9_dec_init(struct hantro_ctx *ctx)
size = hantro_vp9_tile_filter_size(max_height);
vp9_dec->bsd_ctrl_offset = size;
size += hantro_vp9_bsd_control_size(max_height);
-
- tile_edge->cpu = dma_alloc_coherent(vpu->dev, size, &tile_edge->dma, GFP_KERNEL);
- if (!tile_edge->cpu)
+ if (hantro_allocate_aux_buf(ctx, tile_edge, size))
return -ENOMEM;
- tile_edge->size = size;
memset(tile_edge->cpu, 0, size);
size = hantro_vp9_segment_map_size(max_width, max_height);
vp9_dec->segment_map_size = size;
size *= 2; /* we need two areas of this size, used alternately */
+ if (hantro_allocate_aux_buf(ctx, segment_map, size))
+ goto error;
- segment_map->cpu = dma_alloc_coherent(vpu->dev, size, &segment_map->dma, GFP_KERNEL);
- if (!segment_map->cpu)
- goto err_segment_map;
-
- segment_map->size = size;
memset(segment_map->cpu, 0, size);
size = hantro_vp9_prob_tab_size();
@@ -205,36 +199,27 @@ int hantro_vp9_dec_init(struct hantro_ctx *ctx)
size += hantro_vp9_count_tab_size();
vp9_dec->tile_info_offset = size;
size += hantro_vp9_tile_info_size();
+ if (hantro_allocate_aux_buf(ctx, misc, size))
+ goto error;
- misc->cpu = dma_alloc_coherent(vpu->dev, size, &misc->dma, GFP_KERNEL);
- if (!misc->cpu)
- goto err_misc;
-
- misc->size = size;
memset(misc->cpu, 0, size);
init_v4l2_vp9_count_tbl(ctx);
return 0;
-err_misc:
- dma_free_coherent(vpu->dev, segment_map->size, segment_map->cpu, segment_map->dma);
-
-err_segment_map:
- dma_free_coherent(vpu->dev, tile_edge->size, tile_edge->cpu, tile_edge->dma);
+error:
+ hantro_free_aux_buf(ctx, segment_map);
+ hantro_free_aux_buf(ctx, tile_edge);
return -ENOMEM;
}
void hantro_vp9_dec_exit(struct hantro_ctx *ctx)
{
- struct hantro_dev *vpu = ctx->dev;
struct hantro_vp9_dec_hw_ctx *vp9_dec = &ctx->vp9_dec;
- struct hantro_aux_buf *tile_edge = &vp9_dec->tile_edge;
- struct hantro_aux_buf *segment_map = &vp9_dec->segment_map;
- struct hantro_aux_buf *misc = &vp9_dec->misc;
- dma_free_coherent(vpu->dev, misc->size, misc->cpu, misc->dma);
- dma_free_coherent(vpu->dev, segment_map->size, segment_map->cpu, segment_map->dma);
- dma_free_coherent(vpu->dev, tile_edge->size, tile_edge->cpu, tile_edge->dma);
+ hantro_free_aux_buf(ctx, &vp9_dec->tile_edge);
+ hantro_free_aux_buf(ctx, &vp9_dec->segment_map);
+ hantro_free_aux_buf(ctx, &vp9_dec->misc);
}
--
2.53.0
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH v1 7/7] media: verisilicon: mpeg4: Use alloc/free helpers for auxiliary buffers
2026-09-16 12:54 [PATCH v1 0/7] media: verisilicon: simplify auxiliary buffers allocation Benjamin Gaignard
` (5 preceding siblings ...)
2026-09-16 12:54 ` [PATCH v1 6/7] media: verisilicon: vp9: " Benjamin Gaignard
@ 2026-09-16 12:54 ` Benjamin Gaignard
6 siblings, 0 replies; 8+ messages in thread
From: Benjamin Gaignard @ 2026-09-16 12:54 UTC (permalink / raw)
To: nicolas.dufresne, benjamin.gaignard, p.zabel, mchehab
Cc: linux-media, linux-rockchip, linux-kernel, kernel
Simplify and clean up the code by using the helpers.
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
---
.../media/platform/verisilicon/hantro_mpeg2.c | 17 ++---------------
1 file changed, 2 insertions(+), 15 deletions(-)
diff --git a/drivers/media/platform/verisilicon/hantro_mpeg2.c b/drivers/media/platform/verisilicon/hantro_mpeg2.c
index 04e545eb0a83..f21115e6bdbe 100644
--- a/drivers/media/platform/verisilicon/hantro_mpeg2.c
+++ b/drivers/media/platform/verisilicon/hantro_mpeg2.c
@@ -37,25 +37,12 @@ void hantro_mpeg2_dec_copy_qtable(u8 *qtable,
int hantro_mpeg2_dec_init(struct hantro_ctx *ctx)
{
- struct hantro_dev *vpu = ctx->dev;
-
- ctx->mpeg2_dec.qtable.size = ARRAY_SIZE(zigzag) * 4;
- ctx->mpeg2_dec.qtable.cpu =
- dma_alloc_coherent(vpu->dev,
- ctx->mpeg2_dec.qtable.size,
- &ctx->mpeg2_dec.qtable.dma,
- GFP_KERNEL);
- if (!ctx->mpeg2_dec.qtable.cpu)
+ if (hantro_allocate_aux_buf(ctx, &ctx->mpeg2_dec.qtable, ARRAY_SIZE(zigzag) * 4))
return -ENOMEM;
return 0;
}
void hantro_mpeg2_dec_exit(struct hantro_ctx *ctx)
{
- struct hantro_dev *vpu = ctx->dev;
-
- dma_free_coherent(vpu->dev,
- ctx->mpeg2_dec.qtable.size,
- ctx->mpeg2_dec.qtable.cpu,
- ctx->mpeg2_dec.qtable.dma);
+ hantro_free_aux_buf(ctx, &ctx->mpeg2_dec.qtable);
}
--
2.53.0
^ permalink raw reply [flat|nested] 8+ messages in thread