Thread (5 messages) flat view 5 messages, 1 author, 13h ago
HOTtoday

[PATCH 3/4] media: verisilicon: Switch to tracked dma allocations

From: Detlev Casanova <detlev.casanova@collabora.com>
Date: 2026-09-16 14:25:58
Also in: linux-media, linux-rockchip, lkml
Subsystem: arm/rockchip soc support, hantro vpu codec driver, media input infrastructure (v4l/dvb), the rest · Maintainers: Heiko Stuebner, Nicolas Dufresne, Benjamin Gaignard, Philipp Zabel, Mauro Carvalho Chehab, Linus Torvalds

Use the newly introduced v4l2_dma_alloc_attrs and v4l2_dma_free_attrs
functions to track all dma allocations and have them exposed to
userspace for easier debug.

Signed-off-by: Detlev Casanova <detlev.casanova@collabora.com>
---
 drivers/media/platform/verisilicon/hantro.h        |   1 +
 drivers/media/platform/verisilicon/hantro_drv.c    |   4 +
 drivers/media/platform/verisilicon/hantro_h264.c   |   7 +-
 drivers/media/platform/verisilicon/hantro_hevc.c   | 100 +++++++------
 drivers/media/platform/verisilicon/hantro_mpeg2.c  |  16 +--
 .../media/platform/verisilicon/hantro_postproc.c   |  14 +-
 drivers/media/platform/verisilicon/hantro_vp8.c    |  25 ++--
 drivers/media/platform/verisilicon/hantro_vp9.c    |  34 +++--
 .../verisilicon/rockchip_vpu981_hw_av1_dec.c       | 160 ++++++++++++---------
 9 files changed, 215 insertions(+), 146 deletions(-)
diff --git a/drivers/media/platform/verisilicon/hantro.h b/drivers/media/platform/verisilicon/hantro.h
index d5cddc783688..acf5312d5ed4 100644
--- a/drivers/media/platform/verisilicon/hantro.h
+++ b/drivers/media/platform/verisilicon/hantro.h
@@ -24,6 +24,7 @@
 #include <media/v4l2-mem2mem.h>
 #include <media/videobuf2-core.h>
 #include <media/videobuf2-dma-contig.h>
+#include <media/v4l2-allocator.h>
 
 #include "hantro_hw.h"
 
diff --git a/drivers/media/platform/verisilicon/hantro_drv.c b/drivers/media/platform/verisilicon/hantro_drv.c
index 32855b14e0f1..2b8aa2033d3f 100644
--- a/drivers/media/platform/verisilicon/hantro_drv.c
+++ b/drivers/media/platform/verisilicon/hantro_drv.c
@@ -232,6 +232,8 @@ queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq)
 	src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
 	src_vq->lock = &ctx->dev->vpu_mutex;
 	src_vq->dev = ctx->dev->v4l2_dev.dev;
+	src_vq->v4l2_dev = &ctx->dev->v4l2_dev;
+	src_vq->v4l2_fh = &ctx->fh;
 	src_vq->supports_requests = true;
 
 	ret = vb2_queue_init(src_vq);
@@ -258,6 +260,8 @@ queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq)
 	dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
 	dst_vq->lock = &ctx->dev->vpu_mutex;
 	dst_vq->dev = ctx->dev->v4l2_dev.dev;
+	dst_vq->v4l2_dev = &ctx->dev->v4l2_dev;
+	dst_vq->v4l2_fh = &ctx->fh;
 
 	return vb2_queue_init(dst_vq);
 }
diff --git a/drivers/media/platform/verisilicon/hantro_h264.c b/drivers/media/platform/verisilicon/hantro_h264.c
index 2414782f1eb6..6b6afd74f8ae 100644
--- a/drivers/media/platform/verisilicon/hantro_h264.c
+++ b/drivers/media/platform/verisilicon/hantro_h264.c
@@ -498,7 +498,7 @@ void hantro_h264_dec_exit(struct hantro_ctx *ctx)
 	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);
+	v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev, priv->size, priv->cpu, priv->dma, 0);
 }
 
 int hantro_h264_dec_init(struct hantro_ctx *ctx)
@@ -508,8 +508,9 @@ int hantro_h264_dec_init(struct hantro_ctx *ctx)
 	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);
+	priv->cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev,
+					 sizeof(*tbl), &priv->dma,
+					 GFP_KERNEL, 0, &ctx->fh, "h264-priv");
 	if (!priv->cpu)
 		return -ENOMEM;
 
diff --git a/drivers/media/platform/verisilicon/hantro_hevc.c b/drivers/media/platform/verisilicon/hantro_hevc.c
index 83cd12b0ddd6..e73498285bf7 100644
--- a/drivers/media/platform/verisilicon/hantro_hevc.c
+++ b/drivers/media/platform/verisilicon/hantro_hevc.c
@@ -7,6 +7,7 @@
 
 #include <linux/types.h>
 #include <media/v4l2-mem2mem.h>
+#include <media/v4l2-allocator.h>
 
 #include "hantro.h"
 #include "hantro_hw.h"
@@ -89,46 +90,52 @@ static int tile_buffer_reallocate(struct hantro_ctx *ctx)
 
 	/* 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);
+		v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev, hevc_dec->tile_filter.size,
+				    hevc_dec->tile_filter.cpu,
+				    hevc_dec->tile_filter.dma, 0);
 		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);
+		v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev, hevc_dec->tile_sao.size,
+				    hevc_dec->tile_sao.cpu,
+				    hevc_dec->tile_sao.dma, 0);
 		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);
+		v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev, hevc_dec->tile_bsd.size,
+				    hevc_dec->tile_bsd.cpu,
+				    hevc_dec->tile_bsd.dma, 0);
 		hevc_dec->tile_bsd.cpu = NULL;
 	}
 
 	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);
+	hevc_dec->tile_filter.cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev, size,
+							 &hevc_dec->tile_filter.dma,
+							 GFP_KERNEL,
+							 DMA_ATTR_NO_KERNEL_MAPPING,
+							 &ctx->fh, "hevc-tile-filter");
 	if (!hevc_dec->tile_filter.cpu)
 		return -ENOMEM;
 	hevc_dec->tile_filter.size = 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);
+	hevc_dec->tile_sao.cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev, size,
+						      &hevc_dec->tile_sao.dma,
+						      GFP_KERNEL,
+						      DMA_ATTR_NO_KERNEL_MAPPING,
+						      &ctx->fh, "hevc-tile-sao");
 	if (!hevc_dec->tile_sao.cpu)
 		goto err_free_tile_buffers;
 	hevc_dec->tile_sao.size = 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);
+	hevc_dec->tile_bsd.cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev, size,
+						      &hevc_dec->tile_bsd.dma,
+						      GFP_KERNEL,
+						      DMA_ATTR_NO_KERNEL_MAPPING,
+						      &ctx->fh, "hevc-tile-bsd");
 	if (!hevc_dec->tile_bsd.cpu)
 		goto err_free_sao_buffers;
 	hevc_dec->tile_bsd.size = size;
@@ -139,16 +146,16 @@ static int tile_buffer_reallocate(struct hantro_ctx *ctx)
 
 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);
+		v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev, hevc_dec->tile_sao.size,
+				    hevc_dec->tile_sao.cpu,
+				    hevc_dec->tile_sao.dma, 0);
 	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);
+		v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev, hevc_dec->tile_filter.size,
+				    hevc_dec->tile_filter.cpu,
+				    hevc_dec->tile_filter.dma, 0);
 	hevc_dec->tile_filter.cpu = NULL;
 
 	return -ENOMEM;
@@ -218,33 +225,33 @@ void hantro_hevc_dec_exit(struct hantro_ctx *ctx)
 	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);
+		v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev, hevc_dec->tile_sizes.size,
+				    hevc_dec->tile_sizes.cpu,
+				    hevc_dec->tile_sizes.dma, 0);
 	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);
+		v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev, hevc_dec->scaling_lists.size,
+				    hevc_dec->scaling_lists.cpu,
+				    hevc_dec->scaling_lists.dma, 0);
 	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);
+		v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev, hevc_dec->tile_filter.size,
+				    hevc_dec->tile_filter.cpu,
+				    hevc_dec->tile_filter.dma, 0);
 	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);
+		v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev, hevc_dec->tile_sao.size,
+				    hevc_dec->tile_sao.cpu,
+				    hevc_dec->tile_sao.dma, 0);
 	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);
+		v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev, hevc_dec->tile_bsd.size,
+				    hevc_dec->tile_bsd.cpu,
+				    hevc_dec->tile_bsd.dma, 0);
 	hevc_dec->tile_bsd.cpu = NULL;
 }
 
@@ -262,17 +269,20 @@ 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);
+	hevc_dec->tile_sizes.cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev, size,
+							&hevc_dec->tile_sizes.dma,
+							GFP_KERNEL, 0,
+							&ctx->fh, "hevc-tile-sizes");
 	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);
+	hevc_dec->scaling_lists.cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev,
+							   SCALING_LIST_SIZE,
+							   &hevc_dec->scaling_lists.dma,
+							   GFP_KERNEL, 0,
+							   &ctx->fh, "hevc-scaling-lists");
 	if (!hevc_dec->scaling_lists.cpu)
 		return -ENOMEM;
 
diff --git a/drivers/media/platform/verisilicon/hantro_mpeg2.c b/drivers/media/platform/verisilicon/hantro_mpeg2.c
index 04e545eb0a83..edb29204b9c2 100644
--- a/drivers/media/platform/verisilicon/hantro_mpeg2.c
+++ b/drivers/media/platform/verisilicon/hantro_mpeg2.c
@@ -41,10 +41,10 @@ int hantro_mpeg2_dec_init(struct hantro_ctx *ctx)
 
 	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);
+		v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev,
+				     ctx->mpeg2_dec.qtable.size,
+				     &ctx->mpeg2_dec.qtable.dma,
+				     GFP_KERNEL, 0, &ctx->fh, "mpeg2-qtable");
 	if (!ctx->mpeg2_dec.qtable.cpu)
 		return -ENOMEM;
 	return 0;
@@ -54,8 +54,8 @@ 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);
+	v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+			    ctx->mpeg2_dec.qtable.size,
+			    ctx->mpeg2_dec.qtable.cpu,
+			    ctx->mpeg2_dec.qtable.dma, 0);
 }
diff --git a/drivers/media/platform/verisilicon/hantro_postproc.c b/drivers/media/platform/verisilicon/hantro_postproc.c
index e94d1ba5ef10..030db07f96e3 100644
--- a/drivers/media/platform/verisilicon/hantro_postproc.c
+++ b/drivers/media/platform/verisilicon/hantro_postproc.c
@@ -189,8 +189,8 @@ void hantro_postproc_free(struct hantro_ctx *ctx)
 		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);
+			v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev, priv->size, priv->cpu,
+					    priv->dma, priv->attrs);
 			priv->cpu = NULL;
 		}
 	}
@@ -226,6 +226,7 @@ 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);
+	char name[32];
 
 	if (!buf_size)
 		return -EINVAL;
@@ -235,8 +236,9 @@ 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);
+	snprintf(name, sizeof(name), "postproc-dec-%d", index);
+	priv->cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev, buf_size, &priv->dma,
+					 GFP_KERNEL, priv->attrs, &ctx->fh, name);
 	if (!priv->cpu)
 		return -ENOMEM;
 	priv->size = buf_size;
@@ -273,8 +275,8 @@ hantro_postproc_get_dec_buf_addr(struct hantro_ctx *ctx, int index)
 
 	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);
+		v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev, priv->size, priv->cpu,
+				    priv->dma, priv->attrs);
 		priv->cpu = NULL;
 	}
 
diff --git a/drivers/media/platform/verisilicon/hantro_vp8.c b/drivers/media/platform/verisilicon/hantro_vp8.c
index 381bc1d3bfda..c94b1692adbb 100644
--- a/drivers/media/platform/verisilicon/hantro_vp8.c
+++ b/drivers/media/platform/verisilicon/hantro_vp8.c
@@ -161,8 +161,9 @@ int hantro_vp8_dec_init(struct hantro_ctx *ctx)
 	 */
 	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);
+	aux_buf->cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev,
+					    aux_buf->size, &aux_buf->dma,
+					    GFP_KERNEL, 0, &ctx->fh, "vp8-segment-map");
 	if (!aux_buf->cpu)
 		return -ENOMEM;
 
@@ -172,8 +173,9 @@ int hantro_vp8_dec_init(struct hantro_ctx *ctx)
 	 */
 	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);
+	aux_buf->cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev,
+					    aux_buf->size, &aux_buf->dma,
+					    GFP_KERNEL, 0, &ctx->fh, "vp8-prob-tbl");
 	if (!aux_buf->cpu) {
 		ret = -ENOMEM;
 		goto err_free_seg_map;
@@ -182,9 +184,10 @@ int hantro_vp8_dec_init(struct hantro_ctx *ctx)
 	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);
+	v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+			    ctx->vp8_dec.segment_map.size,
+			    ctx->vp8_dec.segment_map.cpu,
+			    ctx->vp8_dec.segment_map.dma, 0);
 
 	return ret;
 }
@@ -194,8 +197,8 @@ 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);
+	v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev, vp8_dec->segment_map.size,
+			    vp8_dec->segment_map.cpu, vp8_dec->segment_map.dma, 0);
+	v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev, vp8_dec->prob_tbl.size,
+			    vp8_dec->prob_tbl.cpu, vp8_dec->prob_tbl.dma, 0);
 }
diff --git a/drivers/media/platform/verisilicon/hantro_vp9.c b/drivers/media/platform/verisilicon/hantro_vp9.c
index 566cd376c097..3933a835cc57 100644
--- a/drivers/media/platform/verisilicon/hantro_vp9.c
+++ b/drivers/media/platform/verisilicon/hantro_vp9.c
@@ -182,7 +182,10 @@ int hantro_vp9_dec_init(struct hantro_ctx *ctx)
 	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);
+	tile_edge->cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev,
+					      size, &tile_edge->dma,
+					      GFP_KERNEL, 0, &ctx->fh,
+					      "vp9-tile-edge");
 	if (!tile_edge->cpu)
 		return -ENOMEM;
 
@@ -193,7 +196,10 @@ int hantro_vp9_dec_init(struct hantro_ctx *ctx)
 	vp9_dec->segment_map_size = size;
 	size *= 2; /* we need two areas of this size, used alternately */
 
-	segment_map->cpu = dma_alloc_coherent(vpu->dev, size, &segment_map->dma, GFP_KERNEL);
+	segment_map->cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev,
+						size, &segment_map->dma,
+						GFP_KERNEL, 0, &ctx->fh,
+						"vp9-segment-map");
 	if (!segment_map->cpu)
 		goto err_segment_map;
 
@@ -206,7 +212,10 @@ int hantro_vp9_dec_init(struct hantro_ctx *ctx)
 	vp9_dec->tile_info_offset = size;
 	size += hantro_vp9_tile_info_size();
 
-	misc->cpu = dma_alloc_coherent(vpu->dev, size, &misc->dma, GFP_KERNEL);
+	misc->cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev,
+					 size, &misc->dma,
+					 GFP_KERNEL, 0, &ctx->fh,
+					 "vp9-misc");
 	if (!misc->cpu)
 		goto err_misc;
 
@@ -218,10 +227,14 @@ int hantro_vp9_dec_init(struct hantro_ctx *ctx)
 	return 0;
 
 err_misc:
-	dma_free_coherent(vpu->dev, segment_map->size, segment_map->cpu, segment_map->dma);
+	v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+			    segment_map->size, segment_map->cpu,
+			    segment_map->dma, 0);
 
 err_segment_map:
-	dma_free_coherent(vpu->dev, tile_edge->size, tile_edge->cpu, tile_edge->dma);
+	v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+			    tile_edge->size, tile_edge->cpu,
+			    tile_edge->dma, 0);
 
 	return -ENOMEM;
 }
@@ -234,7 +247,12 @@ void hantro_vp9_dec_exit(struct hantro_ctx *ctx)
 	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);
+	v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+			    misc->size, misc->cpu, misc->dma, 0);
+	v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+			    segment_map->size, segment_map->cpu,
+			    segment_map->dma, 0);
+	v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+			    tile_edge->size, tile_edge->cpu,
+			    tile_edge->dma, 0);
 }
diff --git a/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c b/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c
index e4e21ad37323..f48e8dbfc880 100644
--- a/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c
+++ b/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c
@@ -232,30 +232,38 @@ static void rockchip_vpu981_av1_dec_tiles_free(struct hantro_ctx *ctx)
 	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);
+		v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+				    av1_dec->db_data_col.size,
+				    av1_dec->db_data_col.cpu,
+				    av1_dec->db_data_col.dma, 0);
 	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);
+		v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+				    av1_dec->db_ctrl_col.size,
+				    av1_dec->db_ctrl_col.cpu,
+				    av1_dec->db_ctrl_col.dma, 0);
 	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);
+		v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+				    av1_dec->cdef_col.size,
+				    av1_dec->cdef_col.cpu,
+				    av1_dec->cdef_col.dma, 0);
 	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);
+		v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+				    av1_dec->sr_col.size,
+				    av1_dec->sr_col.cpu,
+				    av1_dec->sr_col.dma, 0);
 	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);
+		v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+				    av1_dec->lr_col.size,
+				    av1_dec->lr_col.cpu,
+				    av1_dec->lr_col.dma, 0);
 	av1_dec->lr_col.cpu = NULL;
 }
 
@@ -278,41 +286,46 @@ static int rockchip_vpu981_av1_dec_tiles_reallocate(struct hantro_ctx *ctx)
 	rockchip_vpu981_av1_dec_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);
+	av1_dec->db_data_col.cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev, size,
+							&av1_dec->db_data_col.dma,
+							GFP_KERNEL, 0, &ctx->fh,
+							"av1-db-data-col");
 	if (!av1_dec->db_data_col.cpu)
 		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);
+	av1_dec->db_ctrl_col.cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev, size,
+							&av1_dec->db_ctrl_col.dma,
+							GFP_KERNEL, 0, &ctx->fh,
+							"av1-db-ctrl-col");
 	if (!av1_dec->db_ctrl_col.cpu)
 		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);
+	av1_dec->cdef_col.cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev, size,
+						     &av1_dec->cdef_col.dma,
+						     GFP_KERNEL, 0, &ctx->fh,
+						     "av1-cdef-col");
 	if (!av1_dec->cdef_col.cpu)
 		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);
+	av1_dec->sr_col.cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev, size,
+						   &av1_dec->sr_col.dma,
+						   GFP_KERNEL, 0, &ctx->fh,
+						   "av1-sr-col");
 	if (!av1_dec->sr_col.cpu)
 		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);
+	av1_dec->lr_col.cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev, size,
+						   &av1_dec->lr_col.dma,
+						   GFP_KERNEL, 0, &ctx->fh,
+						   "av1-lr-col");
 	if (!av1_dec->lr_col.cpu)
 		goto buffer_allocation_error;
 	av1_dec->lr_col.size = size;
@@ -331,37 +344,45 @@ void rockchip_vpu981_av1_dec_exit(struct hantro_ctx *ctx)
 	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);
+		v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+				    av1_dec->global_model.size,
+				    av1_dec->global_model.cpu,
+				    av1_dec->global_model.dma, 0);
 	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);
+		v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+				    av1_dec->tile_info.size,
+				    av1_dec->tile_info.cpu,
+				    av1_dec->tile_info.dma, 0);
 	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);
+		v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+				    av1_dec->film_grain.size,
+				    av1_dec->film_grain.cpu,
+				    av1_dec->film_grain.dma, 0);
 	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);
+		v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+				    av1_dec->prob_tbl.size,
+				    av1_dec->prob_tbl.cpu,
+				    av1_dec->prob_tbl.dma, 0);
 	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);
+		v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+				    av1_dec->prob_tbl_out.size,
+				    av1_dec->prob_tbl_out.cpu,
+				    av1_dec->prob_tbl_out.dma, 0);
 	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);
+		v4l2_dma_free_attrs(&vpu->v4l2_dev, vpu->dev,
+				    av1_dec->tile_buf.size,
+				    av1_dec->tile_buf.cpu,
+				    av1_dec->tile_buf.dma, 0);
 	av1_dec->tile_buf.cpu = NULL;
 
 	rockchip_vpu981_av1_dec_tiles_free(ctx);
@@ -374,40 +395,48 @@ int rockchip_vpu981_av1_dec_init(struct hantro_ctx *ctx)
 
 	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);
+	av1_dec->global_model.cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev,
+							 GLOBAL_MODEL_SIZE,
+							 &av1_dec->global_model.dma,
+							 GFP_KERNEL, 0, &ctx->fh,
+							 "av1-global-model");
 	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);
+	av1_dec->tile_info.cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev,
+						      AV1_TILE_INFO_SIZE,
+						      &av1_dec->tile_info.dma,
+						      GFP_KERNEL, 0, &ctx->fh,
+						      "av1-tile-info");
 	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 rockchip_av1_film_grain), 2048),
-						     &av1_dec->film_grain.dma,
-						     GFP_KERNEL);
+	av1_dec->film_grain.cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev,
+						       ALIGN(sizeof(struct rockchip_av1_film_grain),
+							     2048),
+						       &av1_dec->film_grain.dma,
+						       GFP_KERNEL, 0, &ctx->fh,
+						       "av1-film-grain");
 	if (!av1_dec->film_grain.cpu)
 		return -ENOMEM;
 	av1_dec->film_grain.size = ALIGN(sizeof(struct rockchip_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);
+	av1_dec->prob_tbl.cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev,
+						     ALIGN(sizeof(struct av1cdfs), 2048),
+						     &av1_dec->prob_tbl.dma,
+						     GFP_KERNEL, 0, &ctx->fh,
+						     "av1-prob-tbl");
 	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);
+	av1_dec->prob_tbl_out.cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev,
+							 ALIGN(sizeof(struct av1cdfs), 2048),
+							 &av1_dec->prob_tbl_out.dma,
+							 GFP_KERNEL, 0, &ctx->fh,
+							 "av1-prob-tbl-out");
 	if (!av1_dec->prob_tbl_out.cpu)
 		return -ENOMEM;
 	av1_dec->prob_tbl_out.size = ALIGN(sizeof(struct av1cdfs), 2048);
@@ -416,10 +445,11 @@ int rockchip_vpu981_av1_dec_init(struct hantro_ctx *ctx)
 
 	rockchip_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);
+	av1_dec->tile_buf.cpu = v4l2_dma_alloc_attrs(&vpu->v4l2_dev, vpu->dev,
+						     AV1_TILE_SIZE,
+						     &av1_dec->tile_buf.dma,
+						     GFP_KERNEL, 0, &ctx->fh,
+						     "av1-tile-buf");
 	if (!av1_dec->tile_buf.cpu)
 		return -ENOMEM;
 	av1_dec->tile_buf.size = AV1_TILE_SIZE;
-- 
2.55.0

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help