Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Francesco Saverio Pavone <pavone.lawyer@gmail.com>
To: Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
	Robin Murphy <robin.murphy@arm.com>,
	Sandy Huang <hjc@rock-chips.com>,
	Heiko Stuebner <heiko@sntech.de>, Andy Yan <andyshrk@163.com>,
	Chaoyi Chen <chaoyi.chen@rock-chips.com>
Cc: Damon Ding <damon.ding@rock-chips.com>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Jiaxing Hu <gahing@gahingwoo.com>,
	iommu@lists.linux.dev, dri-devel@lists.freedesktop.org,
	devicetree@vger.kernel.org, linux-rockchip@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org
Subject: [RFC PATCH v2 1/3] iommu/rockchip: Report the reserved regions from the devicetree
Date: Fri,  4 Dec 2026 11:27:51 +0100	[thread overview]
Message-ID: <20261204102757.47697-2-pavone.lawyer@gmail.com> (raw)
In-Reply-To: <20261204102757.47697-1-pavone.lawyer@gmail.com>

The driver has no .get_resv_regions callback, so the iommu core ignores
a reserved-memory node that lists a device in "iommu-addresses". A
bootloader framebuffer that the VOP still scans out is then not mapped
in the default domain, and the VOP MMU faults on it.

Report the regions with of_iommu_get_resv_regions(). It is called
directly, not through iommu_dma_get_resv_regions(), so that the DRM
driver can read the regions on 32-bit ARM too.

The IOVA space is 32 bits wide and the page table index would wrap a
higher address. So drop a direct region that does not fit, with a
warning, clip a reserved one that crosses 4 GiB and drop one above it.
Signed-off-by: Francesco Saverio Pavone <pavone.lawyer@gmail.com>
---
 drivers/iommu/rockchip-iommu.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
index 1fa3110b142ad..2df71a3e62e2e 100644
--- a/drivers/iommu/rockchip-iommu.c
+++ b/drivers/iommu/rockchip-iommu.c
@@ -20,6 +20,7 @@
 #include <linux/mm.h>
 #include <linux/init.h>
 #include <linux/of.h>
+#include <linux/of_iommu.h>
 #include <linux/of_platform.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
@@ -1198,12 +1199,43 @@ static int rk_iommu_of_xlate(struct device *dev,
 	return 0;
 }
 
+static void rk_iommu_get_resv_regions(struct device *dev,
+				      struct list_head *head)
+{
+	struct iommu_resv_region *region, *next;
+	LIST_HEAD(regions);
+	LIST_HEAD(drop);
+
+	of_iommu_get_resv_regions(dev, &regions);
+
+	/* The IOVA is 32 bits wide, see rk_iova_dte_index() */
+	list_for_each_entry_safe(region, next, &regions, list) {
+		if (region->start <= DMA_BIT_MASK(32) &&
+		    region->length - 1 <= DMA_BIT_MASK(32) - region->start)
+			continue;
+
+		if (region->type == IOMMU_RESV_RESERVED &&
+		    region->start <= DMA_BIT_MASK(32)) {
+			region->length = DMA_BIT_MASK(32) - region->start + 1;
+			continue;
+		}
+
+		dev_warn_ratelimited(dev, "ignoring reserved region %pa+%#zx beyond 4 GiB\n",
+				     &region->start, region->length);
+		list_move_tail(&region->list, &drop);
+	}
+
+	iommu_put_resv_regions(dev, &drop);
+	list_splice_tail(&regions, head);
+}
+
 static const struct iommu_ops rk_iommu_ops = {
 	.identity_domain = &rk_identity_domain,
 	.domain_alloc_paging = rk_iommu_domain_alloc_paging,
 	.probe_device = rk_iommu_probe_device,
 	.release_device = rk_iommu_release_device,
 	.device_group = generic_single_device_group,
+	.get_resv_regions = rk_iommu_get_resv_regions,
 	.of_xlate = rk_iommu_of_xlate,
 	.default_domain_ops = &(const struct iommu_domain_ops) {
 		.attach_dev	= rk_iommu_attach_device,
-- 
2.54.0



  reply	other threads:[~2026-12-04 10:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 10:27 [RFC PATCH v2 0/3] rockchip: keep the bootloader framebuffer mapped behind the VOP IOMMU Francesco Saverio Pavone
2026-12-04 10:27 ` Francesco Saverio Pavone [this message]
2026-12-04 10:27 ` [RFC PATCH v2 2/3] dt-bindings: display: vop2: Allow memory-region Francesco Saverio Pavone
2026-12-04 10:27 ` [RFC PATCH v2 3/3] drm/rockchip: Map the reserved regions 1:1 in the DRM IOMMU domain Francesco Saverio Pavone
2026-12-04 12:00   ` Robin Murphy
2026-12-04 15:32     ` Francesco Saverio Pavone
2026-12-04 17:14       ` Robin Murphy

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=20261204102757.47697-2-pavone.lawyer@gmail.com \
    --to=pavone.lawyer@gmail.com \
    --cc=airlied@gmail.com \
    --cc=andyshrk@163.com \
    --cc=chaoyi.chen@rock-chips.com \
    --cc=conor+dt@kernel.org \
    --cc=damon.ding@rock-chips.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gahing@gahingwoo.com \
    --cc=heiko@sntech.de \
    --cc=hjc@rock-chips.com \
    --cc=iommu@lists.linux.dev \
    --cc=joro@8bytes.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=robh@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=simona@ffwll.ch \
    --cc=tzimmermann@suse.de \
    --cc=will@kernel.org \
    /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