[PATCH v13 4/6] media: verisilicon: AV1: Restore IOMMU context before decoding a frame

Benjamin Gaignard
2026-02-16T09:51:53Z

AV1 is a stateless decoder which means multiple AV1 bitstreams could be
decoded at the same time using the same hardware block. Before decoding
a frame it is needed to restore the iommu tables to avoid mixing decode
contexts.

Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
---
.../verisilicon/rockchip_vpu981_hw_av1_dec.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)

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 e4703bb6be7c..d9e68e0ded68 100644
--- a/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c
+++ b/drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c
@@ -5,6 +5,9 @@
* Author: Benjamin Gaignard <benjamin.gaignard@collabora.com>
*/

+#include <linux/iommu.h>
+#include <linux/vsi-iommu.h>
+
#include <media/v4l2-mem2mem.h>
#include "hantro.h"
#include "hantro_v4l2.h"
@@ -2095,12 +2098,24 @@ rockchip_vpu981_av1_dec_set_output_buffer(struct hantro_ctx *ctx)
hantro_write_addr(vpu, AV1_TILE_OUT_MV, mv_addr);
}

+static void rockchip_vpu981_av1_restore_iommu(struct hantro_ctx *ctx)
+{
+ struct iommu_domain *domain;
+
+ /* Before decoding any frame iommu context need to be restored */
+ domain = iommu_get_domain_for_dev(ctx->dev->v4l2_dev.dev);
+ if (domain)
+ vsi_iommu_restore_ctx(domain);
+}
+
int rockchip_vpu981_av1_dec_run(struct hantro_ctx *ctx)
{
struct hantro_dev *vpu = ctx->dev;
struct vb2_v4l2_buffer *vb2_src;
int ret;

+ rockchip_vpu981_av1_restore_iommu(ctx);
+
hantro_start_prepare_run(ctx);

ret = rockchip_vpu981_av1_dec_prepare_run(ctx);
--
2.43.0