* [PATCH v3 0/7] media: verisilicon: simplify auxiliary buffers allocation
@ 2026-11-23 9:58 Benjamin Gaignard
2026-11-23 9:58 ` [PATCH v3 1/7] media: verisilicon: Add helpers to allocate and free auxiliary buffers Benjamin Gaignard
` (6 more replies)
0 siblings, 7 replies; 9+ messages in thread
From: Benjamin Gaignard @ 2026-11-23 9:58 UTC (permalink / raw)
To: nicolas.dufresne, p.zabel, mchehab
Cc: linux-media, linux-rockchip, linux-kernel, Benjamin Gaignard
Verisilicon stateless video decoder driver allocates lot of auxiliary
buffers to decode bitstreams. These allocations duplicate a lot of code.
This series add helpers functions to allocate and free auxiliary
buffers. This simplify the driver code and will allow to implement more
easly incoming feature like disentanglement data buffers from mv and rfc
buffers or adding reference frame support for more codecs.
This series has been tested with fluster on IMX8MP for h264, hevc, vp8
and vp9 codecs, and on rk3588 for av1.
This series depends of this one:
https://patchwork.linuxtv.org/project/linux-media/list/?series=34366
Regards,
Benjamin
changes in v3:
- As suggested by Philipp do not mask hantro_allocate_aux_buf() returned
value.
- In hantro_allocate_aux_buf() and hantro_free_aux_buf() only set vpu if
ctx isn't NULL.
changes in v2:
- rebase on top of media: verisilicon: Create AV1 helper library v7
- tag reviewed-by tag
- fix patch 1 and 7 commit messages
Benjamin Gaignard (7):
media: verisilicon: Add helpers to allocate and free auxiliary buffers
media: verisilicon: AV1: Use alloc/free helpers for auxiliary buffers
media: verisilicon: h264: Use alloc/free helpers for auxiliary buffers
media: verisilicon: hevc: Use alloc/free helpers for auxiliary buffers
media: verisilicon: vp8: Use alloc/free helpers for auxiliary buffers
media: verisilicon: vp9: Use alloc/free helpers for auxiliary buffers
media: verisilicon: mpeg4: Use alloc/free helpers for auxiliary
buffers
drivers/media/platform/verisilicon/hantro.h | 4 +
.../media/platform/verisilicon/hantro_av1.c | 191 +++++-------------
.../media/platform/verisilicon/hantro_h264.c | 13 +-
.../media/platform/verisilicon/hantro_hevc.c | 133 ++++--------
.../media/platform/verisilicon/hantro_mpeg2.c | 19 +-
.../platform/verisilicon/hantro_postproc.c | 21 +-
.../media/platform/verisilicon/hantro_v4l2.c | 37 ++++
.../media/platform/verisilicon/hantro_vp8.c | 36 +---
.../media/platform/verisilicon/hantro_vp9.c | 42 ++--
9 files changed, 169 insertions(+), 327 deletions(-)
--
2.53.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v3 1/7] media: verisilicon: Add helpers to allocate and free auxiliary buffers
2026-11-23 9:58 [PATCH v3 0/7] media: verisilicon: simplify auxiliary buffers allocation Benjamin Gaignard
@ 2026-11-23 9:58 ` Benjamin Gaignard
2026-11-23 9:59 ` [PATCH v3 2/7] media: verisilicon: AV1: Use alloc/free helpers for " Benjamin Gaignard
` (5 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Benjamin Gaignard @ 2026-11-23 9:58 UTC (permalink / raw)
To: nicolas.dufresne, p.zabel, mchehab
Cc: linux-media, linux-rockchip, linux-kernel, Benjamin Gaignard
Add helpers functions to allocate and free the auxiliary buffers.
That simplify the code and make it easier to read and maintain.
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
---
changes in v3:
- In hantro_allocate_aux_buf() and hantro_free_aux_buf() only set vpu if
ctx isn't NULL.
drivers/media/platform/verisilicon/hantro.h | 4 ++
.../platform/verisilicon/hantro_postproc.c | 21 ++---------
.../media/platform/verisilicon/hantro_v4l2.c | 37 +++++++++++++++++++
3 files changed, 44 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..9ca6509512e4 100644
--- a/drivers/media/platform/verisilicon/hantro_v4l2.c
+++ b/drivers/media/platform/verisilicon/hantro_v4l2.c
@@ -1029,3 +1029,40 @@ 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;
+
+ if (!aux_buf || !ctx || !size)
+ return -EINVAL;
+
+ vpu = ctx->dev;
+ 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;
+
+ if (!aux_buf || !ctx)
+ return;
+
+ vpu = ctx->dev;
+ 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] 9+ messages in thread
* [PATCH v3 2/7] media: verisilicon: AV1: Use alloc/free helpers for auxiliary buffers
2026-11-23 9:58 [PATCH v3 0/7] media: verisilicon: simplify auxiliary buffers allocation Benjamin Gaignard
2026-11-23 9:58 ` [PATCH v3 1/7] media: verisilicon: Add helpers to allocate and free auxiliary buffers Benjamin Gaignard
@ 2026-11-23 9:59 ` Benjamin Gaignard
2026-11-23 9:59 ` [PATCH v3 3/7] media: verisilicon: h264: " Benjamin Gaignard
` (4 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Benjamin Gaignard @ 2026-11-23 9:59 UTC (permalink / raw)
To: nicolas.dufresne, p.zabel, mchehab
Cc: linux-media, linux-rockchip, linux-kernel, Benjamin Gaignard
Simplify and clean up the code by using the helpers.
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
---
changes in v3:
- As suggested by Philipp do not mask hantro_allocate_aux_buf() returned
value.
.../media/platform/verisilicon/hantro_av1.c | 191 +++++-------------
1 file changed, 56 insertions(+), 135 deletions(-)
diff --git a/drivers/media/platform/verisilicon/hantro_av1.c b/drivers/media/platform/verisilicon/hantro_av1.c
index 2cde32f0e935..a934bce51d67 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,154 +263,97 @@ 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)
+ ret = hantro_allocate_aux_buf(ctx, &av1_dec->db_data_col, size);
+ if (ret)
goto buffer_allocation_error;
- av1_dec->db_data_col.size = 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)
+ ret = hantro_allocate_aux_buf(ctx, &av1_dec->db_ctrl_col, size);
+ if (ret)
goto buffer_allocation_error;
- av1_dec->db_ctrl_col.size = 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)
+ ret = hantro_allocate_aux_buf(ctx, &av1_dec->cdef_col, size);
+ if (ret)
goto buffer_allocation_error;
- av1_dec->cdef_col.size = 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)
+ ret = hantro_allocate_aux_buf(ctx, &av1_dec->sr_col, size);
+ if (ret)
goto buffer_allocation_error;
- av1_dec->sr_col.size = 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;
buffer_allocation_error:
hantro_av1_tiles_free(ctx);
- return -ENOMEM;
+ return ret;
}
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);
+ if (ret)
+ goto buffer_allocation_error;
+
+ ret = hantro_allocate_aux_buf(ctx, &av1_dec->tile_info, AV1_TILE_INFO_SIZE);
+ if (ret)
+ goto buffer_allocation_error;
+
+ ret = hantro_allocate_aux_buf(ctx, &av1_dec->film_grain,
+ ALIGN(sizeof(struct hantro_av1_film_grain), 2048));
+ if (ret)
+ goto buffer_allocation_error;
+
+ ret = hantro_allocate_aux_buf(ctx, &av1_dec->prob_tbl,
+ ALIGN(sizeof(struct av1cdfs), 2048));
+ if (ret)
+ goto buffer_allocation_error;
+
+ 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] 9+ messages in thread
* [PATCH v3 3/7] media: verisilicon: h264: Use alloc/free helpers for auxiliary buffers
2026-11-23 9:58 [PATCH v3 0/7] media: verisilicon: simplify auxiliary buffers allocation Benjamin Gaignard
2026-11-23 9:58 ` [PATCH v3 1/7] media: verisilicon: Add helpers to allocate and free auxiliary buffers Benjamin Gaignard
2026-11-23 9:59 ` [PATCH v3 2/7] media: verisilicon: AV1: Use alloc/free helpers for " Benjamin Gaignard
@ 2026-11-23 9:59 ` Benjamin Gaignard
2026-11-23 9:59 ` [PATCH v3 4/7] media: verisilicon: hevc: " Benjamin Gaignard
` (3 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Benjamin Gaignard @ 2026-11-23 9:59 UTC (permalink / raw)
To: nicolas.dufresne, p.zabel, mchehab
Cc: linux-media, linux-rockchip, linux-kernel, Benjamin Gaignard
Simplify and clean up the code by using the helpers.
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
---
changes in v3:
- As suggested by Philipp do not mask hantro_allocate_aux_buf() returned
value.
drivers/media/platform/verisilicon/hantro_h264.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/drivers/media/platform/verisilicon/hantro_h264.c b/drivers/media/platform/verisilicon/hantro_h264.c
index 2414782f1eb6..3da3083182fb 100644
--- a/drivers/media/platform/verisilicon/hantro_h264.c
+++ b/drivers/media/platform/verisilicon/hantro_h264.c
@@ -494,26 +494,23 @@ 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;
+ int ret;
- priv->cpu = dma_alloc_coherent(vpu->dev, sizeof(*tbl), &priv->dma,
- GFP_KERNEL);
- if (!priv->cpu)
- return -ENOMEM;
+ ret = hantro_allocate_aux_buf(ctx, priv, sizeof(*tbl));
+ if (ret)
+ return ret;
- 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] 9+ messages in thread
* [PATCH v3 4/7] media: verisilicon: hevc: Use alloc/free helpers for auxiliary buffers
2026-11-23 9:58 [PATCH v3 0/7] media: verisilicon: simplify auxiliary buffers allocation Benjamin Gaignard
` (2 preceding siblings ...)
2026-11-23 9:59 ` [PATCH v3 3/7] media: verisilicon: h264: " Benjamin Gaignard
@ 2026-11-23 9:59 ` Benjamin Gaignard
2026-11-23 9:59 ` [PATCH v3 5/7] media: verisilicon: vp8: " Benjamin Gaignard
` (2 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Benjamin Gaignard @ 2026-11-23 9:59 UTC (permalink / raw)
To: nicolas.dufresne, p.zabel, mchehab
Cc: linux-media, linux-rockchip, linux-kernel, Benjamin Gaignard
Simplify and clean up the code by using the helpers.
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
---
changes in v3:
- As suggested by Philipp do not mask hantro_allocate_aux_buf() returned
value.
.../media/platform/verisilicon/hantro_hevc.c | 133 +++++-------------
1 file changed, 36 insertions(+), 97 deletions(-)
diff --git a/drivers/media/platform/verisilicon/hantro_hevc.c b/drivers/media/platform/verisilicon/hantro_hevc.c
index 83cd12b0ddd6..951ecc27ca0f 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,43 @@ 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);
+ if (ret)
+ goto error;
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);
+ if (ret)
+ goto error;
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 +182,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 +205,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 +217,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] 9+ messages in thread
* [PATCH v3 5/7] media: verisilicon: vp8: Use alloc/free helpers for auxiliary buffers
2026-11-23 9:58 [PATCH v3 0/7] media: verisilicon: simplify auxiliary buffers allocation Benjamin Gaignard
` (3 preceding siblings ...)
2026-11-23 9:59 ` [PATCH v3 4/7] media: verisilicon: hevc: " Benjamin Gaignard
@ 2026-11-23 9:59 ` Benjamin Gaignard
2026-11-23 9:59 ` [PATCH v3 6/7] media: verisilicon: vp9: " Benjamin Gaignard
2026-11-23 9:59 ` [PATCH v3 7/7] media: verisilicon: mpeg4: " Benjamin Gaignard
6 siblings, 0 replies; 9+ messages in thread
From: Benjamin Gaignard @ 2026-11-23 9:59 UTC (permalink / raw)
To: nicolas.dufresne, p.zabel, mchehab
Cc: linux-media, linux-rockchip, linux-kernel, Benjamin Gaignard
Simplify and clean up the code by using the helpers.
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
---
changes in v3:
- As suggested by Philipp do not mask hantro_allocate_aux_buf() returned
value.
.../media/platform/verisilicon/hantro_vp8.c | 36 ++++++-------------
1 file changed, 11 insertions(+), 25 deletions(-)
diff --git a/drivers/media/platform/verisilicon/hantro_vp8.c b/drivers/media/platform/verisilicon/hantro_vp8.c
index 381bc1d3bfda..65648c017e76 100644
--- a/drivers/media/platform/verisilicon/hantro_vp8.c
+++ b/drivers/media/platform/verisilicon/hantro_vp8.c
@@ -144,7 +144,6 @@ 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;
@@ -160,42 +159,29 @@ 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;
+ ret = hantro_allocate_aux_buf(ctx, aux_buf, segment_map_size);
+ if (ret)
+ 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;
- }
+ ret = hantro_allocate_aux_buf(ctx, aux_buf, sizeof(struct vp8_prob_tbl_packed));
+ if (ret)
+ 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);
-
+error:
+ hantro_free_aux_buf(ctx, &ctx->vp8_dec.segment_map);
+ hantro_free_aux_buf(ctx, &ctx->vp8_dec.prob_tbl);
return ret;
}
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] 9+ messages in thread
* [PATCH v3 6/7] media: verisilicon: vp9: Use alloc/free helpers for auxiliary buffers
2026-11-23 9:58 [PATCH v3 0/7] media: verisilicon: simplify auxiliary buffers allocation Benjamin Gaignard
` (4 preceding siblings ...)
2026-11-23 9:59 ` [PATCH v3 5/7] media: verisilicon: vp8: " Benjamin Gaignard
@ 2026-11-23 9:59 ` Benjamin Gaignard
2026-11-23 9:59 ` [PATCH v3 7/7] media: verisilicon: mpeg4: " Benjamin Gaignard
6 siblings, 0 replies; 9+ messages in thread
From: Benjamin Gaignard @ 2026-11-23 9:59 UTC (permalink / raw)
To: nicolas.dufresne, p.zabel, mchehab
Cc: linux-media, linux-rockchip, linux-kernel, Benjamin Gaignard
Simplify and clean up the code by using the helpers.
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
---
changes in v3:
- As suggested by Philipp do not mask hantro_allocate_aux_buf() returned
value.
.../media/platform/verisilicon/hantro_vp9.c | 42 +++++++------------
1 file changed, 15 insertions(+), 27 deletions(-)
diff --git a/drivers/media/platform/verisilicon/hantro_vp9.c b/drivers/media/platform/verisilicon/hantro_vp9.c
index 566cd376c097..6f7995076610 100644
--- a/drivers/media/platform/verisilicon/hantro_vp9.c
+++ b/drivers/media/platform/verisilicon/hantro_vp9.c
@@ -164,6 +164,7 @@ int hantro_vp9_dec_init(struct hantro_ctx *ctx)
struct hantro_aux_buf *segment_map = &vp9_dec->segment_map;
struct hantro_aux_buf *misc = &vp9_dec->misc;
u32 i, max_width, max_height, size;
+ int ret;
if (variant->num_dec_fmts < 1)
return -EINVAL;
@@ -181,23 +182,18 @@ 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 */
+ ret = hantro_allocate_aux_buf(ctx, segment_map, size);
+ if (ret)
+ 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 +201,28 @@ 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();
+ ret = hantro_allocate_aux_buf(ctx, misc, size);
+ if (ret)
+ 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;
+ return ret;
}
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] 9+ messages in thread
* [PATCH v3 7/7] media: verisilicon: mpeg4: Use alloc/free helpers for auxiliary buffers
2026-11-23 9:58 [PATCH v3 0/7] media: verisilicon: simplify auxiliary buffers allocation Benjamin Gaignard
` (5 preceding siblings ...)
2026-11-23 9:59 ` [PATCH v3 6/7] media: verisilicon: vp9: " Benjamin Gaignard
@ 2026-11-23 9:59 ` Benjamin Gaignard
2026-11-23 19:15 ` Nicolas Dufresne
6 siblings, 1 reply; 9+ messages in thread
From: Benjamin Gaignard @ 2026-11-23 9:59 UTC (permalink / raw)
To: nicolas.dufresne, p.zabel, mchehab
Cc: linux-media, linux-rockchip, linux-kernel, Benjamin Gaignard
Simplify and clean up the code by using the helpers.
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
---
changes in v3:
- As suggested by Philipp do not mask hantro_allocate_aux_buf() returned
value.
.../media/platform/verisilicon/hantro_mpeg2.c | 19 ++-----------------
1 file changed, 2 insertions(+), 17 deletions(-)
diff --git a/drivers/media/platform/verisilicon/hantro_mpeg2.c b/drivers/media/platform/verisilicon/hantro_mpeg2.c
index 04e545eb0a83..7386cc50b11b 100644
--- a/drivers/media/platform/verisilicon/hantro_mpeg2.c
+++ b/drivers/media/platform/verisilicon/hantro_mpeg2.c
@@ -37,25 +37,10 @@ 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)
- return -ENOMEM;
- return 0;
+ return hantro_allocate_aux_buf(ctx, &ctx->mpeg2_dec.qtable, ARRAY_SIZE(zigzag) * 4);
}
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] 9+ messages in thread
* Re: [PATCH v3 7/7] media: verisilicon: mpeg4: Use alloc/free helpers for auxiliary buffers
2026-11-23 9:59 ` [PATCH v3 7/7] media: verisilicon: mpeg4: " Benjamin Gaignard
@ 2026-11-23 19:15 ` Nicolas Dufresne
0 siblings, 0 replies; 9+ messages in thread
From: Nicolas Dufresne @ 2026-11-23 19:15 UTC (permalink / raw)
To: Benjamin Gaignard, p.zabel, mchehab
Cc: linux-media, linux-rockchip, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1807 bytes --]
Le lundi 23 novembre 2026 à 10:59 +0100, Benjamin Gaignard a écrit :
> Simplify and clean up the code by using the helpers.
I'll pick the series, just wanted to mention that I will edit your subject line
from mpeg4 to mpeg2.
Nicolas
>
> Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
> Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
> ---
> changes in v3:
> - As suggested by Philipp do not mask hantro_allocate_aux_buf() returned
> value.
>
> .../media/platform/verisilicon/hantro_mpeg2.c | 19 ++-----------------
> 1 file changed, 2 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/media/platform/verisilicon/hantro_mpeg2.c b/drivers/media/platform/verisilicon/hantro_mpeg2.c
> index 04e545eb0a83..7386cc50b11b 100644
> --- a/drivers/media/platform/verisilicon/hantro_mpeg2.c
> +++ b/drivers/media/platform/verisilicon/hantro_mpeg2.c
> @@ -37,25 +37,10 @@ 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)
> - return -ENOMEM;
> - return 0;
> + return hantro_allocate_aux_buf(ctx, &ctx->mpeg2_dec.qtable, ARRAY_SIZE(zigzag) * 4);
> }
>
> 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);
> }
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-11-23 19:15 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-23 9:58 [PATCH v3 0/7] media: verisilicon: simplify auxiliary buffers allocation Benjamin Gaignard
2026-11-23 9:58 ` [PATCH v3 1/7] media: verisilicon: Add helpers to allocate and free auxiliary buffers Benjamin Gaignard
2026-11-23 9:59 ` [PATCH v3 2/7] media: verisilicon: AV1: Use alloc/free helpers for " Benjamin Gaignard
2026-11-23 9:59 ` [PATCH v3 3/7] media: verisilicon: h264: " Benjamin Gaignard
2026-11-23 9:59 ` [PATCH v3 4/7] media: verisilicon: hevc: " Benjamin Gaignard
2026-11-23 9:59 ` [PATCH v3 5/7] media: verisilicon: vp8: " Benjamin Gaignard
2026-11-23 9:59 ` [PATCH v3 6/7] media: verisilicon: vp9: " Benjamin Gaignard
2026-11-23 9:59 ` [PATCH v3 7/7] media: verisilicon: mpeg4: " Benjamin Gaignard
2026-11-23 19:15 ` Nicolas Dufresne
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®