xen/common: Move gic_dt_preinit() to common code
PATCH v3 1/1 xen/common: Move gic_dt_preinit() to common code
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.
---
Changes in v3:
- s/ic/intc.
- Update the commit message.
- Move intc_dt_preinit() to common/device-tree/intc.c.
- Add declaration of intc_dt_preinit() in xen/device_tree.h.
- Revert intc_preinit()-related changes and just back gic_preinit() in Arm's gic.c.
- Revert ACPI-related changes.
---
Changes in v2:
- Revert changes connected to moving of gic_acpi_preinit() to common code as it isn't really architecture indepent part.
- Update the commit message.
- Move stub of ic_acpi_preinit() to <asm-generic/device.h> for the case when CONFIG_ACPI=n.
--- xen/arch/arm/gic.c | 32 +------------------------------ xen/common/device-tree/Makefile | 1 + xen/common/device-tree/intc.c | 34 +++++++++++++++++++++++++++++++++ xen/include/xen/device_tree.h | 6 ++++++ 4 files changed, 42 insertions(+), 31 deletions(-) create mode 100644 xen/common/device-tree/intc.c
xen/arch/arm/gic.c +1 -31
@@ -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 (); }
xen/common/device-tree/Makefile +1 -0
@@ -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
xen/common/device-tree/intc.c new file +34 -0
@@ -0,0 +1,34 @@ + +#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_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 ; + +if ( !device_init (node,DEVICE_INTERRUPT_CONTROLLER ,NULL ) ) + { +/* NOTE: Only one GIC is supported */ + num_gics =1 ; +break ; + } + } + +if ( !num_gics ) +panic ("Unable to find compatible interrupt contoller" +"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 ); +}
xen/include/xen/device_tree.h +6 -0
@@ -238,6 +238,12 @@ extern rwlock_t dt_host_lock;struct dt_device_node *dt_find_interrupt_controller (const struct dt_device_match *matches); +#ifdef CONFIG_HAS_DEVICE_TREE +void intc_dt_preinit (void ); +#else +static inline void intc_dt_preinit (void ) { } +#endif +#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))
Signature · 1 line
2.47.0
Hi,
Quoted 102 lines · Oleksii Kurochko
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 callsdevice_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 ingic_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 <[email protected]>---
Changes in v3:
- s/ic/intc.
- Update the commit message.
- Moveintc_dt_preinit()tocommon/device-tree/intc.c.
- Add declaration ofintc_dt_preinit()inxen/device_tree.h.
- Revert intc_preinit()-related changes and just backgic_preinit()in Arm'sgic.c.
- Revert ACPI-related changes.
---
Changes in v2:
- Revert changes connected to moving ofgic_acpi_preinit()to common code as it isn't really architecture indepent part.
- Update the commit message.
- Move stub ofic_acpi_preinit()to <asm-generic/device.h> for the case whenCONFIG_ACPI=n.--- xen/arch/arm/gic.c | 32 +------------------------------ xen/common/device-tree/Makefile | 1 + xen/common/device-tree/intc.c | 34 +++++++++++++++++++++++++++++++++ xen/include/xen/device_tree.h | 6 ++++++ 4 files changed, 42 insertions(+), 31 deletions(-)create mode 100644
xen/common/device-tree/intc.cxen/arch/arm/gic.c +1
-31@@ -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 (); }xen/common/device-tree/Makefile +1
-0@@ -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.oxen/common/device-tree/intc.c new file +0
-0
xen/common/device-tree/intc.c line 1
Quoted 1 line
xen/common/device-tree/intc.c new file +1
-0@@ -0,0 +1,34 @@ +
Missing SPDX. Because this code is not brand new, the license will derive from gic.c which is unfortunately GPLv2+. So it would need to be:
/* SPDX-License-Identifier: GPL-2.0-or-later */
xen/common/device-tree/intc.c line 9
Quoted 8 lines
xen/common/device-tree/intc.c new file +8
-0+#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_gics =0 ;
I think you want to rename this variable to num_intc.
xen/common/device-tree/intc.c line 21
Quoted 12 lines
xen/common/device-tree/intc.c new file +12
-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 GIC is supported */
And this probably need to be updated to "Only one interrupt controlled is supported".
Quoted 20 lines
xen/common/device-tree/intc.c new file +13
-0+ num_gics =1 ; +break ; + } + } + +if ( !num_gics ) +panic ("Unable to find compatible interrupt contoller" +"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 ); +}xen/include/xen/device_tree.h +0
-0@@ -238,6 +238,12 @@ extern rwlock_t dt_host_lock;struct dt_device_node *dt_find_interrupt_controller (const struct dt_device_match *matches);
xen/include/xen/device_tree.h extern rwlock_t dt_host_lock; · line 249
Quoted 10 lines
xen/include/xen/device_tree.h +6
-0+#ifdef CONFIG_HAS_DEVICE_TREE +void intc_dt_preinit (void ); +#else +static inline void intc_dt_preinit (void ) { } +#endif +#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))
Cheers,
Signature · 1 line
Julien Grall