[RFC PATCH v2 1/3] iommu/rockchip: Report the reserved regions from the devicetree

Francesco Saverio Pavone pavone.lawyer at gmail.com
Fri Dec 4 02:27:51 PST 2026


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 at 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




More information about the linux-arm-kernel mailing list