Implement init_IRQ() to initalize various IRQs. Currently, this function initializes the irq_desc[] array, which stores IRQ descriptors containing various information about each IRQ, such as the type of hardware handling, whether the IRQ is disabled, etc. The initialization is basic at this point and includes setting IRQ_TYPE_INVALID as the IRQ type, assigning the IRQ number ( which is just a consequent index of irq_desc[] array ) to desc->irq, and setting desc->action to NULL.
Additionally, the function init_irq_data() is introduced to initialize the IRQ descriptors for all IRQs in the system. Also, define IRQ_TYPE_* which are the same as the existing device tree definitions for convenience. Signed-off-by: Oleksii Kurochko <oleksii.kuroc...@gmail.com> --- xen/arch/riscv/Makefile | 1 + xen/arch/riscv/include/asm/irq.h | 24 +++++++++++++++++ xen/arch/riscv/irq.c | 44 ++++++++++++++++++++++++++++++++ xen/arch/riscv/setup.c | 3 +++ xen/arch/riscv/stubs.c | 5 ---- 5 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 xen/arch/riscv/irq.c diff --git a/xen/arch/riscv/Makefile b/xen/arch/riscv/Makefile index f551bf32a2..457e8e88a4 100644 --- a/xen/arch/riscv/Makefile +++ b/xen/arch/riscv/Makefile @@ -3,6 +3,7 @@ obj-y += cpufeature.o obj-$(CONFIG_EARLY_PRINTK) += early_printk.o obj-y += entry.o obj-y += intc.o +obj-y += irq.o obj-y += mm.o obj-y += pt.o obj-$(CONFIG_RISCV_64) += riscv64/ diff --git a/xen/arch/riscv/include/asm/irq.h b/xen/arch/riscv/include/asm/irq.h index 2a48da2651..8f936b7d01 100644 --- a/xen/arch/riscv/include/asm/irq.h +++ b/xen/arch/riscv/include/asm/irq.h @@ -3,6 +3,28 @@ #define ASM__RISCV__IRQ_H #include <xen/bug.h> +#include <xen/device_tree.h> + +#define NR_IRQS 1024 + +/* + * TODO: Should IRQ_TYPE_* be moved to xen/irq.h and wrapped into + * #ifdef CONFIG_HAS_DEVICE_TREE? + */ +/* + * These defines correspond to the Xen internal representation of the + * IRQ types. We choose to make them the same as the existing device + * tree definitions for convenience. + */ +#define IRQ_TYPE_NONE DT_IRQ_TYPE_NONE +#define IRQ_TYPE_EDGE_RISING DT_IRQ_TYPE_EDGE_RISING +#define IRQ_TYPE_EDGE_FALLING DT_IRQ_TYPE_EDGE_FALLING +#define IRQ_TYPE_EDGE_BOTH DT_IRQ_TYPE_EDGE_BOTH +#define IRQ_TYPE_LEVEL_HIGH DT_IRQ_TYPE_LEVEL_HIGH +#define IRQ_TYPE_LEVEL_LOW DT_IRQ_TYPE_LEVEL_LOW +#define IRQ_TYPE_LEVEL_MASK DT_IRQ_TYPE_LEVEL_MASK +#define IRQ_TYPE_SENSE_MASK DT_IRQ_TYPE_SENSE_MASK +#define IRQ_TYPE_INVALID DT_IRQ_TYPE_INVALID /* TODO */ #define nr_irqs 0U @@ -25,6 +47,8 @@ static inline void arch_move_irqs(struct vcpu *v) BUG_ON("unimplemented"); } +void init_IRQ(void); + #endif /* ASM__RISCV__IRQ_H */ /* diff --git a/xen/arch/riscv/irq.c b/xen/arch/riscv/irq.c new file mode 100644 index 0000000000..99b8f2095e --- /dev/null +++ b/xen/arch/riscv/irq.c @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +/* + * RISC-V Trap handlers + * + * Copyright (c) 2024 Vates + */ + +#include <xen/bug.h> +#include <xen/init.h> +#include <xen/irq.h> + +static irq_desc_t irq_desc[NR_IRQS]; + +int arch_init_one_irq_desc(struct irq_desc *desc) +{ + desc->arch.type = IRQ_TYPE_INVALID; + return 0; +} + +static int __init init_irq_data(void) +{ + int irq; + + for ( irq = 0; irq < NR_IRQS; irq++ ) + { + struct irq_desc *desc = irq_to_desc(irq); + int rc = init_one_irq_desc(desc); + + if ( rc ) + return rc; + + desc->irq = irq; + desc->action = NULL; + } + + return 0; +} + +void __init init_IRQ(void) +{ + if ( init_irq_data() < 0 ) + panic("initialization of IRQ data failed\n"); +} diff --git a/xen/arch/riscv/setup.c b/xen/arch/riscv/setup.c index 7f68f3f5b7..a3189697da 100644 --- a/xen/arch/riscv/setup.c +++ b/xen/arch/riscv/setup.c @@ -6,6 +6,7 @@ #include <xen/compile.h> #include <xen/device_tree.h> #include <xen/init.h> +#include <xen/irq.h> #include <xen/mm.h> #include <xen/shutdown.h> #include <xen/vmap.h> @@ -127,6 +128,8 @@ void __init noreturn start_xen(unsigned long bootcpu_id, panic("Booting using ACPI isn't supported\n"); } + init_IRQ(); + riscv_fill_hwcap(); preinit_xen_time(); diff --git a/xen/arch/riscv/stubs.c b/xen/arch/riscv/stubs.c index fdcf91054e..e396b67cd3 100644 --- a/xen/arch/riscv/stubs.c +++ b/xen/arch/riscv/stubs.c @@ -107,11 +107,6 @@ void irq_ack_none(struct irq_desc *desc) BUG_ON("unimplemented"); } -int arch_init_one_irq_desc(struct irq_desc *desc) -{ - BUG_ON("unimplemented"); -} - void smp_send_state_dump(unsigned int cpu) { BUG_ON("unimplemented"); -- 2.49.0