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 4/7] media: verisilicon: hevc: Use alloc/free helpers for auxiliary buffers
Date: Wed, 16 Sep 2026 14:54:40 +0200 [thread overview]
Message-ID: <20260916125443.78602-5-benjamin.gaignard@collabora.com> (raw)
In-Reply-To: <20260916125443.78602-1-benjamin.gaignard@collabora.com>
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
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 ` [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 ` [PATCH v1 3/7] media: verisilicon: h264: " Benjamin Gaignard
2026-09-16 12:54 ` Benjamin Gaignard [this message]
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-5-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®