]> xenbits.xensource.com Git - xen.git/commitdiff
xen/common: Move gic_dt_preinit() to common code
authorOleksii Kurochko <oleksii.kurochko@gmail.com>
Mon, 25 Nov 2024 10:34:40 +0000 (11:34 +0100)
committerJan Beulich <jbeulich@suse.com>
Mon, 25 Nov 2024 10:34:40 +0000 (11:34 +0100)
Introduce intc_dt_preinit() in the common codebase, as it is not
architecture-specific and can be reused by both PPC and RISC-V.
This function identifies the node with the interrupt-controller property
in the device tree and calls device_init() to handle architecture-specific
initialization of the interrupt controller.

Make minor adjustments compared to the original ARM implementation of
gic_dt_preinit():
 - Remove the local rc variable in gic_dt_preinit() since it is only used once.
 - Change the prefix from gic to intc to clarify that the function is not
   specific to ARM’s GIC, making it suitable for other architectures as well.

Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
xen/arch/arm/gic.c
xen/common/device-tree/Makefile
xen/common/device-tree/intc.c [new file with mode: 0644]
xen/include/xen/device_tree.h

index 3eaf670fd731dbb8830e2f9980459777d3fce7c7..acf61a4de373e02fdfc30f860381a0ee9ceba2de 100644 (file)
@@ -214,36 +214,6 @@ int gic_map_hwdom_extra_mappings(struct domain *d)
     return 0;
 }
 
-static void __init gic_dt_preinit(void)
-{
-    int rc;
-    struct dt_device_node *node;
-    uint8_t num_gics = 0;
-
-    dt_for_each_device_node( dt_host, node )
-    {
-        if ( !dt_get_property(node, "interrupt-controller", NULL) )
-            continue;
-
-        if ( !dt_get_parent(node) )
-            continue;
-
-        rc = device_init(node, DEVICE_INTERRUPT_CONTROLLER, NULL);
-        if ( !rc )
-        {
-            /* NOTE: Only one GIC is supported */
-            num_gics = 1;
-            break;
-        }
-    }
-    if ( !num_gics )
-        panic("Unable to find compatible GIC in the device tree\n");
-
-    /* Set the GIC as the primary interrupt controller */
-    dt_interrupt_controller = node;
-    dt_device_set_used_by(node, DOMID_XEN);
-}
-
 #ifdef CONFIG_ACPI
 static void __init gic_acpi_preinit(void)
 {
@@ -269,7 +239,7 @@ static void __init gic_acpi_preinit(void) { }
 void __init gic_preinit(void)
 {
     if ( acpi_disabled )
-        gic_dt_preinit();
+        intc_dt_preinit();
     else
         gic_acpi_preinit();
 }
index 58052d074e626cdc2aad31050ea22507460286c7..7c549be38a14328e3a4ed4429e904bb629416567 100644 (file)
@@ -2,3 +2,4 @@ obj-y += bootfdt.init.o
 obj-y += bootinfo.init.o
 obj-y += device-tree.o
 obj-$(CONFIG_OVERLAY_DTB) += dt-overlay.o
+obj-y += intc.o
diff --git a/xen/common/device-tree/intc.c b/xen/common/device-tree/intc.c
new file mode 100644 (file)
index 0000000..b09fbf6
--- /dev/null
@@ -0,0 +1,43 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include <xen/device_tree.h>
+#include <xen/init.h>
+#include <xen/lib.h>
+
+void __init intc_dt_preinit(void)
+{
+    struct dt_device_node *node;
+    uint8_t num_intc = 0;
+
+    dt_for_each_device_node( dt_host, node )
+    {
+        if ( !dt_get_property(node, "interrupt-controller", NULL) )
+            continue;
+
+        if ( !dt_get_parent(node) )
+            continue;
+
+        if ( !device_init(node, DEVICE_INTERRUPT_CONTROLLER, NULL) )
+        {
+            /* NOTE: Only one interrupt controller is supported */
+            num_intc = 1;
+            break;
+        }
+    }
+
+    if ( !num_intc )
+        panic("Unable to find compatible interrupt controller in the device tree\n");
+
+    /* Set the interrupt controller as the primary interrupt controller */
+    dt_interrupt_controller = node;
+    dt_device_set_used_by(node, DOMID_XEN);
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
index e6287305a7b5f5cf1ce813a4d8175e5b1d93d24a..5ff763bb80bb17b05a4883b0e6067f8eefe77876 100644 (file)
@@ -238,6 +238,8 @@ extern rwlock_t dt_host_lock;
 struct dt_device_node *
 dt_find_interrupt_controller(const struct dt_device_match *matches);
 
+void intc_dt_preinit(void);
+
 #define dt_prop_cmp(s1, s2) strcmp((s1), (s2))
 #define dt_node_cmp(s1, s2) strcasecmp((s1), (s2))
 #define dt_compat_cmp(s1, s2) strcasecmp((s1), (s2))