[RFC 2/8] iommu: Add a helper to check if any iommu device is registered

From: Jacob Pan
Date: Mon Dec 01 2025 - 12:30:32 EST


The dummy IOMMU driver for No-IOMMU mode should only be active when
no real IOMMU devices are present in the system. Introduce a helper
to check this condition, ensuring that the dummy driver does not
interfere when hardware-backed IOMMU support is available.

Signed-off-by: Jacob Pan <jacob.pan@xxxxxxxxxxxxxxxxxxx>
---
drivers/iommu/iommu.c | 10 ++++++++++
include/linux/iommu.h | 1 +
2 files changed, 11 insertions(+)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 0df914a04064..958f612bf176 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -2895,6 +2895,16 @@ static const struct iommu_device *iommu_from_fwnode(const struct fwnode_handle *
return ret;
}

+bool iommu_is_registered(void)
+{
+ bool registered;
+
+ spin_lock(&iommu_device_lock);
+ registered = !list_empty(&iommu_device_list);
+ spin_unlock(&iommu_device_lock);
+ return registered;
+}
+
const struct iommu_ops *iommu_ops_from_fwnode(const struct fwnode_handle *fwnode)
{
const struct iommu_device *iommu = iommu_from_fwnode(fwnode);
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index c30d12e16473..4191ae7312dd 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -933,6 +933,7 @@ extern void iommu_put_resv_regions(struct device *dev, struct list_head *list);
extern void iommu_set_default_passthrough(bool cmd_line);
extern void iommu_set_default_translated(bool cmd_line);
extern bool iommu_default_passthrough(void);
+extern bool iommu_is_registered(void);
extern struct iommu_resv_region *
iommu_alloc_resv_region(phys_addr_t start, size_t length, int prot,
enum iommu_resv_type type, gfp_t gfp);
--
2.34.1