[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v4 13/22] xen/arm: vsmmuv3: IOMMU device tree node for dom0


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Milan Djokic <milan_djokic@xxxxxxxx>
  • Date: Wed, 7 Oct 2026 00:07:04 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=80QaLYCIkbbd3V9618ZPaglbC0xPD61hD7G2WmvMdYg=; b=IoKBKwZrdwXZBXuyNqLnmQMayoWuhCli02UF6nesXBm+PY0FDy2lwf9Dx0FKT/czMUMC9GmgZPkjl4I/LhI40h+qZrVZnX/bQdXjjurU27tPqef8ztbh7aKK2qb+R1ffh7+9BPsm3CSX9qSRfz6oflbUKEiKFt4vMEFeA8JXXfSI70Ada9PLChW8tosQHdIkt2j19CteQI9WNlKoFRE8JSq57JOsHtl4BdP+OZPdtYKRCTe0ZPRMoUB3G3J7Yk1u6FTx62fclnKojKq9T4anblsXPOla7pVQjnA9/9xyyR1lh5SojArcUZJVpwufasyhb3mwwyQ3TAmbkCtyB2i6Bg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=kROg9S3up0FcySHzCosPr82VITPT7t0nIeOXhvsOBTtH8L8HkQY98QxvkjeILZeucOJXWZuG7QgmGwSkqiHM18jstnmnwFIoVAfpICkBgjQdKVLA6svWA2T9BYulfmOM4Za6gjyDL3xLC+y67jepzyjN2GWCRcO7U2XZLAD1R2HAjxgy4qHiPSpIwL4vb8DDM8KTG1gUOwbVVGGw2NFwi6XnPpC3iGctYUj68s1FRFr7BmcH49+Np/tWTcGKYWQ8coAV6bnehjJZxN/QBR4GNqR4v0UgptAc5aEliawSrVL/DNXlSk+fmRS/70KzkCbGxKQvEXmRg4GJbhrAmIBzkw==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=epam.com header.i="@epam.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:x-ms-exchange-senderadcheck"
  • Authentication-results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com;
  • Cc: Rahul Singh <rahul.singh@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Milan Djokic <milan_djokic@xxxxxxxx>
  • Delivery-date: Wed, 07 Oct 2026 00:07:08 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHdVe/IIN84IILw1U2j1MPuKYXDMQ==
  • Thread-topic: [PATCH v4 13/22] xen/arm: vsmmuv3: IOMMU device tree node for dom0

From: Rahul Singh <rahul.singh@xxxxxxx>

XEN will create an IOMMU device tree node in the device tree
to enable the dom0 to discover the virtual SMMUv3 during dom0 boot.
IOMMU device tree node will only be created when viommu is enabled
via Kconfig build options.

"iommus" property will be added for dom0 devices to virtual
IOMMU node to enable the dom0 linux kernel to configure the IOMMU.

Signed-off-by: Rahul Singh <rahul.singh@xxxxxxx>
Signed-off-by: Milan Djokic <milan_djokic@xxxxxxxx>
---
 xen/arch/arm/domain_build.c       | 102 +++++++++++++++++++++++++++++-
 xen/arch/arm/include/asm/viommu.h |   1 +
 2 files changed, 101 insertions(+), 2 deletions(-)

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index cd2e09f005..6513140133 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -557,9 +557,12 @@ static int __init write_properties(struct domain *d, 
struct kernel_info *kinfo,
             continue;
         }
 
-        if ( iommu_node )
+        /*
+         * Expose IOMMU specific properties to hwdom when vIOMMU is
+         * enabled.
+         */
+        if ( iommu_node && viommu_get_type() == XEN_DOMCTL_CONFIG_VIOMMU_NONE )
         {
-            /* Don't expose IOMMU specific properties to hwdom */
             if ( dt_property_name_is_equal(prop, "iommus") )
                 continue;
 
@@ -1457,6 +1460,95 @@ int __init make_timer_node(const struct kernel_info 
*kinfo)
     return res;
 }
 
+#ifdef CONFIG_ARM_VIRTUAL_IOMMU
+static int __init make_hwdom_viommu_node(const struct kernel_info *kinfo)
+{
+    uint32_t len;
+    int res;
+    char buf[24];
+    void *fdt = kinfo->fdt;
+    const void *prop = NULL;
+    const struct dt_device_node *iommu = NULL;
+    struct host_iommu *iommu_data;
+    gic_interrupt_t intr;
+
+    if ( list_empty(&host_iommu_list) )
+        return 0;
+
+    list_for_each_entry( iommu_data, &host_iommu_list, entry )
+    {
+        if ( iommu_data->hwdom_node_created )
+            return 0;
+
+        iommu = iommu_data->dt_node;
+
+        snprintf(buf, sizeof(buf), "iommu@%"PRIx64, iommu_data->addr);
+
+        res = fdt_begin_node(fdt, buf);
+        if ( res )
+            return res;
+
+        prop = dt_get_property(iommu, "compatible", &len);
+        if ( !prop )
+        {
+            res = -FDT_ERR_XEN(ENOENT);
+            return res;
+        }
+
+        res = fdt_property(fdt, "compatible", prop, len);
+        if ( res )
+            return res;
+
+        if ( iommu->phandle )
+        {
+            res = fdt_property_cell(fdt, "phandle", iommu->phandle);
+            if ( res )
+                return res;
+        }
+
+        /* Use the same reg regions as the IOMMU node in host DTB. */
+        prop = dt_get_property(iommu, "reg", &len);
+        if ( !prop )
+        {
+            printk(XENLOG_ERR "vIOMMU: Can't find IOMMU reg property.\n");
+            res = -FDT_ERR_XEN(ENOENT);
+            return res;
+        }
+
+        res = fdt_property(fdt, "reg", prop, len);
+        if ( res )
+            return res;
+
+        prop = dt_get_property(iommu, "#iommu-cells", &len);
+        if ( !prop )
+        {
+            res = -FDT_ERR_XEN(ENOENT);
+            return res;
+        }
+
+        res = fdt_property(fdt, "#iommu-cells", prop, len);
+        if ( res )
+            return res;
+
+        res = fdt_property_string(fdt, "interrupt-names", "combined");
+        if ( res )
+            return res;
+
+        set_interrupt(intr, iommu_data->irq, 0xf, DT_IRQ_TYPE_LEVEL_HIGH);
+
+        res = fdt_property_interrupts(kinfo, &intr, 1);
+        if ( res )
+            return res;
+
+        iommu_data->hwdom_node_created = true;
+
+        fdt_end_node(fdt);
+    }
+
+    return res;
+}
+#endif
+
 static int __init handle_node(struct domain *d, struct kernel_info *kinfo,
                               struct dt_device_node *node,
                               p2m_type_t p2mt)
@@ -1525,6 +1617,12 @@ static int __init handle_node(struct domain *d, struct 
kernel_info *kinfo,
     if ( dt_match_node(timer_matches, node) )
         return make_timer_node(kinfo);
 
+#ifdef CONFIG_ARM_VIRTUAL_IOMMU
+    if ( device_get_class(node) == DEVICE_IOMMU &&
+         viommu_get_type() != XEN_DOMCTL_CONFIG_VIOMMU_NONE )
+        return make_hwdom_viommu_node(kinfo);
+#endif
+
     /* Skip nodes used by Xen */
     if ( dt_device_used_by(node) == DOMID_XEN )
     {
diff --git a/xen/arch/arm/include/asm/viommu.h 
b/xen/arch/arm/include/asm/viommu.h
index 844cf34d56..5ae21042f0 100644
--- a/xen/arch/arm/include/asm/viommu.h
+++ b/xen/arch/arm/include/asm/viommu.h
@@ -20,6 +20,7 @@ struct host_iommu {
     paddr_t size;
     /* Used for dom0 EVTQ and GERROR interrupts (1-1 IRQ mapping) */
     uint32_t irq;
+    bool hwdom_node_created;
 };
 
 struct viommu_ops {
-- 
2.43.0

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.