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

[xen staging] device-tree: Move Arm's static-evtchn feature to common



commit 902db088395b13ce620f5a201a751556b760c0ef
Author:     Michal Orzel <michal.orzel@xxxxxxx>
AuthorDate: Tue May 27 10:21:17 2025 +0200
Commit:     Michal Orzel <michal.orzel@xxxxxxx>
CommitDate: Fri May 30 08:41:12 2025 +0200

    device-tree: Move Arm's static-evtchn feature to common
    
    There's nothing Arm specific about this feature. Move it to common as
    part of a larger activity to commonalize device tree related features.
    For now, select it only for ARM until others (e.g. RISC-V) verify it
    works for them too.
    
    Signed-off-by: Michal Orzel <michal.orzel@xxxxxxx>
    Reviewed-by: Stefano Stabellini <sstabellini@xxxxxxxxxx>
---
 xen/arch/arm/Kconfig                     |   8 --
 xen/arch/arm/Makefile                    |   1 -
 xen/arch/arm/include/asm/static-evtchn.h |  25 -----
 xen/arch/arm/setup.c                     |   2 +-
 xen/arch/arm/static-evtchn.c             | 161 -------------------------------
 xen/common/Kconfig                       |   8 ++
 xen/common/device-tree/Makefile          |   1 +
 xen/common/device-tree/static-evtchn.c   | 160 ++++++++++++++++++++++++++++++
 xen/include/xen/static-evtchn.h          |  25 +++++
 9 files changed, 195 insertions(+), 196 deletions(-)

diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig
index a5aad97a68..57919d8b3a 100644
--- a/xen/arch/arm/Kconfig
+++ b/xen/arch/arm/Kconfig
@@ -253,14 +253,6 @@ config STATIC_SHM
        help
          This option enables statically shared memory on a dom0less system.
 
-config STATIC_EVTCHN
-       bool "Static event channel support on a dom0less system"
-       depends on DOM0LESS_BOOT
-       default y
-       help
-         This option enables establishing static event channel communication
-         between domains on a dom0less system (domU-domU as well as domU-dom0).
-
 config PARTIAL_EMULATION
        bool "Enable partial emulation of system/coprocessor registers"
        default y
diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile
index 129a109d6e..eeeac4e653 100644
--- a/xen/arch/arm/Makefile
+++ b/xen/arch/arm/Makefile
@@ -51,7 +51,6 @@ obj-y += setup.o
 obj-y += shutdown.o
 obj-y += smp.o
 obj-y += smpboot.o
-obj-$(CONFIG_STATIC_EVTCHN) += static-evtchn.init.o
 obj-$(CONFIG_STATIC_MEMORY) += static-memory.init.o
 obj-$(CONFIG_STATIC_SHM) += static-shmem.init.o
 obj-y += sysctl.o
diff --git a/xen/arch/arm/include/asm/static-evtchn.h 
b/xen/arch/arm/include/asm/static-evtchn.h
deleted file mode 100644
index f964522f6a..0000000000
--- a/xen/arch/arm/include/asm/static-evtchn.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-
-#ifndef __ASM_STATIC_EVTCHN_H_
-#define __ASM_STATIC_EVTCHN_H_
-
-#ifdef CONFIG_STATIC_EVTCHN
-
-void alloc_static_evtchn(void);
-
-#else /* !CONFIG_STATIC_EVTCHN */
-
-static inline void alloc_static_evtchn(void) {};
-
-#endif /* CONFIG_STATIC_EVTCHN */
-
-#endif /* __ASM_STATIC_EVTCHN_H_ */
-
-/*
- * Local variables:
- * mode: C
- * c-file-style: "BSD"
- * c-basic-offset: 4
- * indent-tabs-mode: nil
- * End:
- */
diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
index 10b46d0684..734e23da44 100644
--- a/xen/arch/arm/setup.c
+++ b/xen/arch/arm/setup.c
@@ -31,6 +31,7 @@
 #include <xen/version.h>
 #include <xen/vmap.h>
 #include <xen/stack-protector.h>
+#include <xen/static-evtchn.h>
 #include <xen/trace.h>
 #include <xen/libfdt/libfdt-xen.h>
 #include <xen/acpi.h>
@@ -39,7 +40,6 @@
 #include <asm/alternative.h>
 #include <asm/dom0less-build.h>
 #include <asm/page.h>
-#include <asm/static-evtchn.h>
 #include <asm/current.h>
 #include <asm/setup.h>
 #include <asm/gic.h>
diff --git a/xen/arch/arm/static-evtchn.c b/xen/arch/arm/static-evtchn.c
deleted file mode 100644
index 49db08d5c6..0000000000
--- a/xen/arch/arm/static-evtchn.c
+++ /dev/null
@@ -1,161 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-
-#include <xen/event.h>
-
-#include <asm/static-evtchn.h>
-
-#define STATIC_EVTCHN_NODE_SIZE_CELLS 2
-
-static int __init get_evtchn_dt_property(const struct dt_device_node *np,
-                                         uint32_t *port, uint32_t *phandle)
-{
-    const __be32 *prop = NULL;
-    uint32_t len;
-
-    prop = dt_get_property(np, "xen,evtchn", &len);
-    if ( !prop )
-    {
-        printk(XENLOG_ERR "xen,evtchn property should not be empty.\n");
-        return -EINVAL;
-    }
-
-    if ( !len || len < dt_cells_to_size(STATIC_EVTCHN_NODE_SIZE_CELLS) )
-    {
-        printk(XENLOG_ERR "xen,evtchn property value is not valid.\n");
-        return -EINVAL;
-    }
-
-    *port = dt_next_cell(1, &prop);
-    *phandle = dt_next_cell(1, &prop);
-
-    return 0;
-}
-
-static int __init alloc_domain_evtchn(struct dt_device_node *node)
-{
-    int rc;
-    uint32_t domU1_port, domU2_port, remote_phandle;
-    struct dt_device_node *remote_node;
-    const struct dt_device_node *p1_node, *p2_node;
-    struct evtchn_alloc_unbound alloc_unbound;
-    struct evtchn_bind_interdomain bind_interdomain;
-    struct domain *d1 = NULL, *d2 = NULL;
-
-    if ( !dt_device_is_compatible(node, "xen,evtchn-v1") )
-        return 0;
-
-    /*
-     * Event channel is already created while parsing the other side of
-     * evtchn node.
-     */
-    if ( dt_device_static_evtchn_created(node) )
-        return 0;
-
-    rc = get_evtchn_dt_property(node, &domU1_port, &remote_phandle);
-    if ( rc )
-        return rc;
-
-    remote_node = dt_find_node_by_phandle(remote_phandle);
-    if ( !remote_node )
-    {
-        printk(XENLOG_ERR
-                "evtchn: could not find remote evtchn phandle\n");
-        return -EINVAL;
-    }
-
-    rc = get_evtchn_dt_property(remote_node, &domU2_port, &remote_phandle);
-    if ( rc )
-        return rc;
-
-    if ( node->phandle != remote_phandle )
-    {
-        printk(XENLOG_ERR "xen,evtchn property is not setup correctly.\n");
-        return -EINVAL;
-    }
-
-    p1_node = dt_get_parent(node);
-    if ( !p1_node )
-    {
-        printk(XENLOG_ERR "evtchn: evtchn parent node is NULL\n" );
-        return -EINVAL;
-    }
-
-    p2_node = dt_get_parent(remote_node);
-    if ( !p2_node )
-    {
-        printk(XENLOG_ERR "evtchn: remote parent node is NULL\n" );
-        return -EINVAL;
-    }
-
-    d1 = get_domain_by_id(p1_node->used_by);
-    d2 = get_domain_by_id(p2_node->used_by);
-
-    if ( !d1 || !d2 )
-    {
-        printk(XENLOG_ERR "evtchn: could not find domains\n" );
-        return -EINVAL;
-    }
-
-    alloc_unbound.dom = d1->domain_id;
-    alloc_unbound.remote_dom = d2->domain_id;
-
-    rc = evtchn_alloc_unbound(&alloc_unbound, domU1_port);
-    if ( rc < 0 )
-    {
-        printk(XENLOG_ERR
-                "evtchn_alloc_unbound() failure (Error %d) \n", rc);
-        return rc;
-    }
-
-    bind_interdomain.remote_dom  = d1->domain_id;
-    bind_interdomain.remote_port = domU1_port;
-
-    rc = evtchn_bind_interdomain(&bind_interdomain, d2, domU2_port);
-    if ( rc < 0 )
-    {
-        printk(XENLOG_ERR
-                "evtchn_bind_interdomain() failure (Error %d) \n", rc);
-        return rc;
-    }
-
-    dt_device_set_static_evtchn_created(node);
-    dt_device_set_static_evtchn_created(remote_node);
-
-    return 0;
-}
-
-void __init alloc_static_evtchn(void)
-{
-    struct dt_device_node *node, *evtchn_node;
-    struct dt_device_node *chosen = dt_find_node_by_path("/chosen");
-
-    BUG_ON(chosen == NULL);
-
-    if ( hardware_domain )
-        dt_device_set_used_by(chosen, hardware_domain->domain_id);
-
-    dt_for_each_child_node(chosen, node)
-    {
-        if ( hardware_domain )
-        {
-            if ( alloc_domain_evtchn(node) != 0 )
-                panic("Could not set up domains evtchn\n");
-        }
-
-        dt_for_each_child_node(node, evtchn_node)
-        {
-            if ( alloc_domain_evtchn(evtchn_node) != 0 )
-                panic("Could not set up domains evtchn\n");
-        }
-    }
-}
-
-/*
- * Local variables:
- * mode: C
- * c-file-style: "BSD"
- * c-basic-offset: 4
- * tab-width: 4
- * indent-tabs-mode: nil
- * End:
- */
diff --git a/xen/common/Kconfig b/xen/common/Kconfig
index 3d66d09397..0951d4c2f2 100644
--- a/xen/common/Kconfig
+++ b/xen/common/Kconfig
@@ -162,6 +162,14 @@ config STATIC_MEMORY
 
          If unsure, say N.
 
+config STATIC_EVTCHN
+       bool "Static event channel support on a dom0less system"
+       depends on DOM0LESS_BOOT && ARM
+       default y
+       help
+         This option enables establishing static event channel communication
+         between domains on a dom0less system (domU-domU as well as domU-dom0).
+
 menu "Speculative hardening"
 
 config INDIRECT_THUNK
diff --git a/xen/common/device-tree/Makefile b/xen/common/device-tree/Makefile
index ff54a8ef2b..57b9e6ca00 100644
--- a/xen/common/device-tree/Makefile
+++ b/xen/common/device-tree/Makefile
@@ -6,3 +6,4 @@ obj-$(CONFIG_DOM0LESS_BOOT) += dom0less-build.init.o
 obj-$(CONFIG_OVERLAY_DTB) += dt-overlay.o
 obj-y += intc.o
 obj-$(CONFIG_DOMAIN_BUILD_HELPERS) += kernel.o
+obj-$(CONFIG_STATIC_EVTCHN) += static-evtchn.init.o
diff --git a/xen/common/device-tree/static-evtchn.c 
b/xen/common/device-tree/static-evtchn.c
new file mode 100644
index 0000000000..8b82e6b3d8
--- /dev/null
+++ b/xen/common/device-tree/static-evtchn.c
@@ -0,0 +1,160 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <xen/event.h>
+#include <xen/static-evtchn.h>
+
+#define STATIC_EVTCHN_NODE_SIZE_CELLS 2
+
+static int __init get_evtchn_dt_property(const struct dt_device_node *np,
+                                         uint32_t *port, uint32_t *phandle)
+{
+    const __be32 *prop = NULL;
+    uint32_t len;
+
+    prop = dt_get_property(np, "xen,evtchn", &len);
+    if ( !prop )
+    {
+        printk(XENLOG_ERR "xen,evtchn property should not be empty.\n");
+        return -EINVAL;
+    }
+
+    if ( !len || len < dt_cells_to_size(STATIC_EVTCHN_NODE_SIZE_CELLS) )
+    {
+        printk(XENLOG_ERR "xen,evtchn property value is not valid.\n");
+        return -EINVAL;
+    }
+
+    *port = dt_next_cell(1, &prop);
+    *phandle = dt_next_cell(1, &prop);
+
+    return 0;
+}
+
+static int __init alloc_domain_evtchn(struct dt_device_node *node)
+{
+    int rc;
+    uint32_t domU1_port, domU2_port, remote_phandle;
+    struct dt_device_node *remote_node;
+    const struct dt_device_node *p1_node, *p2_node;
+    struct evtchn_alloc_unbound alloc_unbound;
+    struct evtchn_bind_interdomain bind_interdomain;
+    struct domain *d1 = NULL, *d2 = NULL;
+
+    if ( !dt_device_is_compatible(node, "xen,evtchn-v1") )
+        return 0;
+
+    /*
+     * Event channel is already created while parsing the other side of
+     * evtchn node.
+     */
+    if ( dt_device_static_evtchn_created(node) )
+        return 0;
+
+    rc = get_evtchn_dt_property(node, &domU1_port, &remote_phandle);
+    if ( rc )
+        return rc;
+
+    remote_node = dt_find_node_by_phandle(remote_phandle);
+    if ( !remote_node )
+    {
+        printk(XENLOG_ERR
+                "evtchn: could not find remote evtchn phandle\n");
+        return -EINVAL;
+    }
+
+    rc = get_evtchn_dt_property(remote_node, &domU2_port, &remote_phandle);
+    if ( rc )
+        return rc;
+
+    if ( node->phandle != remote_phandle )
+    {
+        printk(XENLOG_ERR "xen,evtchn property is not setup correctly.\n");
+        return -EINVAL;
+    }
+
+    p1_node = dt_get_parent(node);
+    if ( !p1_node )
+    {
+        printk(XENLOG_ERR "evtchn: evtchn parent node is NULL\n" );
+        return -EINVAL;
+    }
+
+    p2_node = dt_get_parent(remote_node);
+    if ( !p2_node )
+    {
+        printk(XENLOG_ERR "evtchn: remote parent node is NULL\n" );
+        return -EINVAL;
+    }
+
+    d1 = get_domain_by_id(p1_node->used_by);
+    d2 = get_domain_by_id(p2_node->used_by);
+
+    if ( !d1 || !d2 )
+    {
+        printk(XENLOG_ERR "evtchn: could not find domains\n" );
+        return -EINVAL;
+    }
+
+    alloc_unbound.dom = d1->domain_id;
+    alloc_unbound.remote_dom = d2->domain_id;
+
+    rc = evtchn_alloc_unbound(&alloc_unbound, domU1_port);
+    if ( rc < 0 )
+    {
+        printk(XENLOG_ERR
+                "evtchn_alloc_unbound() failure (Error %d) \n", rc);
+        return rc;
+    }
+
+    bind_interdomain.remote_dom  = d1->domain_id;
+    bind_interdomain.remote_port = domU1_port;
+
+    rc = evtchn_bind_interdomain(&bind_interdomain, d2, domU2_port);
+    if ( rc < 0 )
+    {
+        printk(XENLOG_ERR
+                "evtchn_bind_interdomain() failure (Error %d) \n", rc);
+        return rc;
+    }
+
+    dt_device_set_static_evtchn_created(node);
+    dt_device_set_static_evtchn_created(remote_node);
+
+    return 0;
+}
+
+void __init alloc_static_evtchn(void)
+{
+    struct dt_device_node *node, *evtchn_node;
+    struct dt_device_node *chosen = dt_find_node_by_path("/chosen");
+
+    BUG_ON(chosen == NULL);
+
+    if ( hardware_domain )
+        dt_device_set_used_by(chosen, hardware_domain->domain_id);
+
+    dt_for_each_child_node(chosen, node)
+    {
+        if ( hardware_domain )
+        {
+            if ( alloc_domain_evtchn(node) != 0 )
+                panic("Could not set up domains evtchn\n");
+        }
+
+        dt_for_each_child_node(node, evtchn_node)
+        {
+            if ( alloc_domain_evtchn(evtchn_node) != 0 )
+                panic("Could not set up domains evtchn\n");
+        }
+    }
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/xen/include/xen/static-evtchn.h b/xen/include/xen/static-evtchn.h
new file mode 100644
index 0000000000..31ae92741a
--- /dev/null
+++ b/xen/include/xen/static-evtchn.h
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef XEN_STATIC_EVTCHN_H
+#define XEN_STATIC_EVTCHN_H
+
+#ifdef CONFIG_STATIC_EVTCHN
+
+void alloc_static_evtchn(void);
+
+#else /* !CONFIG_STATIC_EVTCHN */
+
+static inline void alloc_static_evtchn(void) {};
+
+#endif /* CONFIG_STATIC_EVTCHN */
+
+#endif /* XEN_STATIC_EVTCHN_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
--
generated by git-patchbot for /home/xen/git/xen.git#staging



 


Rackspace

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