From nobody Tue Feb 10 20:28:30 2026 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB8532D5A0C for ; Tue, 7 Oct 2025 08:32:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759825981; cv=none; b=IxV8gfmJagDZ7KtOTMjKJ+UaSFeaPDLeU/dLl0vjPJ2QbqCy24dI1o9+tROpw7NVno0USsqZ+6G4xmKW0rJ8BSIbuemE/aqKom6rQIyqCx9gJoxs7FPkZINTOzW84bzcKIH91q2r1Kcgspy1O/IRuR1jGIhxUfxL9WDMwOIql04= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759825981; c=relaxed/simple; bh=m8/AYG1WeqfOxv75Mz5AsWV07rJvH181OXXlCgRuSc0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OUL37fnmtt19sUV1RpT1uKBe1Wdk0gUvRAapTrw6SDa+z8YL4c38oyrgF0jtcKuXIIxTgr29PC2L4crSDxvte4OJr+bICAJuD1orClallG2h2ARUbcI/L/mZ5C7fwz1Iv+HM9LLaU4z28hkxcuDja4G3V0FRVhOnjB+JZrB51KU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from ptz.office.stw.pengutronix.de ([2a0a:edc0:0:900:1d::77] helo=peter.mobile.pengutronix.de) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1v637w-0002Hb-U9; Tue, 07 Oct 2025 10:32:57 +0200 From: =?utf-8?q?Sven_P=C3=BCschel?= Date: Tue, 07 Oct 2025 10:32:04 +0200 Subject: [PATCH 11/16] media: rockchip: rga: add iommu restore function Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251007-spu-rga3-v1-11-36ad85570402@pengutronix.de> References: <20251007-spu-rga3-v1-0-36ad85570402@pengutronix.de> In-Reply-To: <20251007-spu-rga3-v1-0-36ad85570402@pengutronix.de> To: Jacob Chen , Ezequiel Garcia , Mauro Carvalho Chehab , Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de, =?utf-8?q?Sven_P=C3=BCschel?= X-Mailer: b4 0.14.2 X-SA-Exim-Connect-IP: 2a0a:edc0:0:900:1d::77 X-SA-Exim-Mail-From: s.pueschel@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Add an iommu restore function in preparation for the rga3 addition. This is necessary for a soft reset, as the rga3 will also reset it's iommu paging table to 0 and disable paging. The empty domain attach/detach to restore the iommu is copied from the rkvdec driver. Signed-off-by: Sven P=C3=BCschel --- drivers/media/platform/rockchip/rga/rga.c | 24 ++++++++++++++++++++++++ drivers/media/platform/rockchip/rga/rga.h | 7 +++++++ 2 files changed, 31 insertions(+) diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/plat= form/rockchip/rga/rga.c index cd4da01645611e5fb51ed94e09b5f1463dad72c5..0a725841b0cfa41bbc5b861b8f5= ceac2452fc2b5 100644 --- a/drivers/media/platform/rockchip/rga/rga.c +++ b/drivers/media/platform/rockchip/rga/rga.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -560,6 +561,19 @@ static const struct video_device rga_videodev =3D { .device_caps =3D V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING, }; =20 +void rga_iommu_restore(struct rockchip_rga *rga) +{ + if (rga->empty_domain) { + /* + * To rewrite mapping into the attached IOMMU core, attach a new empty d= omain that + * will program an empty table, then detach it to restore the default do= main and + * all cached mappings. + */ + iommu_attach_device(rga->empty_domain, rga->dev); + iommu_detach_device(rga->empty_domain, rga->dev); + } +} + static int rga_parse_dt(struct rockchip_rga *rga) { struct reset_control *core_rst, *axi_rst, *ahb_rst; @@ -657,6 +671,13 @@ static int rga_probe(struct platform_device *pdev) goto err_put_clk; } =20 + if (iommu_get_domain_for_dev(rga->dev)) { + rga->empty_domain =3D iommu_paging_domain_alloc(rga->dev); + + if (!rga->empty_domain) + dev_warn(rga->dev, "cannot alloc new empty domain\n"); + } + ret =3D v4l2_device_register(&pdev->dev, &rga->v4l2_dev); if (ret) goto err_put_clk; @@ -741,6 +762,9 @@ static void rga_remove(struct platform_device *pdev) v4l2_device_unregister(&rga->v4l2_dev); =20 pm_runtime_disable(rga->dev); + + if (rga->empty_domain) + iommu_domain_free(rga->empty_domain); } =20 static int __maybe_unused rga_runtime_suspend(struct device *dev) diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/plat= form/rockchip/rga/rga.h index fc4805ba4e8ef7fb311f780a198ba6ba4d3aff17..e19c4c82aca5ae2056f52d52513= 8093fbbb81af8 100644 --- a/drivers/media/platform/rockchip/rga/rga.h +++ b/drivers/media/platform/rockchip/rga/rga.h @@ -75,6 +75,7 @@ struct rockchip_rga { void __iomem *regs; struct clk_bulk_data clks[3]; struct rockchip_rga_version version; + struct iommu_domain *empty_domain; =20 /* vfd lock */ struct mutex mutex; @@ -114,6 +115,12 @@ static inline struct rga_vb_buffer *vb_to_rga(struct v= b2_v4l2_buffer *vb) =20 struct rga_frame *rga_get_frame(struct rga_ctx *ctx, enum v4l2_buf_type ty= pe); =20 +/* + * This should be called in an interrupt handler to make sure no memory + * is mapped through the IOMMU while the empty domain is attached. + */ +void rga_iommu_restore(struct rockchip_rga *rga); + /* RGA Buffers Manage */ extern const struct vb2_ops rga_qops; =20 --=20 2.51.0