riscv: introduce basic UART support and interrupts for hypervisor mode
v6 cover riscv: introduce basic UART support and interrupts for hypervisor mode
The patch series introduces basic UART support (in interrupt mode) and support of interrupts for hypervisor mode.
To implement this the following has been added:
- APLIC and IMISC initialization.
- Introduce of intc_hw_operations abstraction.
- Introduce some APLIC and IMSIC operations.
- Introduce init_IRQ(), platform_get_irq() and setup_irq() functions.
- Update do_trap() handler to handle IRQ_S_EXT.
- Introduce some other functions such as: get_s_time(), smp_clear_cpu_maps(), ioremap().
- Enable UART.
CI tests: https://gitlab.com/xen-project/people/olkur/xen/-/pipelines/1910703345
---
Changes in V6:
- Have been merged to staging:
[PATCH v5 2/9] xen/riscv: introduce register_intc_ops() and intc_hw_ops. [PATCH v4 1/9] xen/riscv: dt_processor_hartid()
- All other changes are patch-specific. Please check each patch separately.
---
Changes in V5:
- Update CI tests link.
- Mostly changes are patch-specific. Please check each patch separately.
---
Changes in V4:
- Merged to staging:
- xen/riscv: initialize bitmap to zero in riscv_fill_hwcap_from_isa_string()
- xen/asm-generic: introduce asm-generic/irq-dt.h
- xen/riscv: introduce smp_prepare_boot_cpu()
- xen/riscv: introduce support of Svpbmt extension
- add ioremap_*() variants using ioremap_attr()
- xen/riscv: introduce init_IRQ()
- xen/riscv: introduce platform_get_irq()
- All other changes are patch-specific. Please check each patch separately.
---
Changes in V2:
- Merged to staging:
xen/riscv: initialize bitmap to zero in riscv_fill_hwcap_from_isa_string() xen/asm-generic: introduce asm-generic/irq-dt.h
- All other changes are patch-specific. Please check each patch separately.
---
Oleksii Kurochko (7):
xen/riscv: imsic_init() implementation
xen/riscv: aplic_init() implementation
xen/riscv: introduce intc_init() and helpers xen/riscv: implementation of aplic and imsic operations xen/riscv: add external interrupt handling for hypervisor mode xen/riscv: implement setup_irq()
xen/riscv: add basic UART support
xen/arch/riscv/Kconfig | 1 + xen/arch/riscv/Makefile | 1 + xen/arch/riscv/aplic-priv.h | 38 +++ xen/arch/riscv/aplic.c | 297 ++++++++++++++++++ xen/arch/riscv/imsic.c | 489 +++++++++++++++++++++++++++++ xen/arch/riscv/include/asm/aplic.h | 73 +++++ xen/arch/riscv/include/asm/imsic.h | 74 +++++ xen/arch/riscv/include/asm/intc.h | 13 + xen/arch/riscv/include/asm/irq.h | 8 +- xen/arch/riscv/include/asm/smp.h | 13 + xen/arch/riscv/intc.c | 46 +++ xen/arch/riscv/irq.c | 131 ++++++++ xen/arch/riscv/setup.c | 14 + xen/arch/riscv/traps.c | 19 ++ xen/drivers/char/Kconfig | 3 +- 15 files changed, 1217 insertions(+), 3 deletions(-) create mode 100644 xen/arch/riscv/aplic-priv.h create mode 100644 xen/arch/riscv/imsic.c create mode 100644 xen/arch/riscv/include/asm/aplic.h create mode 100644 xen/arch/riscv/include/asm/imsic.h
Signature · 1 line
2.50.0
PATCH v6 1/7 xen/riscv: imsic_init() implementation
imsic_init() is introduced to parse device tree node, which has the following bindings [2], and based on the parsed information update IMSIC configuration which is stored in imsic_cfg.
The following helpers are introduces for imsic_init() usage:
- imsic_parse_node() parses IMSIC node from DTS
- imsic_get_parent_hartid() returns the hart ( CPU ) ID of the given device tree node.
This patch is based on the code from [1].
Since Microchip originally developed imsic.{c,h}, an internal discussion with them led to the decision to use the MIT license.
[1] https://gitlab.com/xen-project/people/olkur/xen/-/commit/0b1a94f2bc3bb1a81cd26bb75f0bf578f84cb4d4
[2] https://elixir.bootlin.com/linux/v6.12/source/Documentation/devicetree/bindings/interrupt-controller/riscv,imsics.yaml
---
Changes in V6:
- Code style fixes.
- s/xfree/xvfree.
- (*nr_mmios)++ -> ++*nr_mmios.
- Use %u for unsigned int arguments.
- Change name of local variable cpuid to cpu.
---
Changes in V5:
- Drop trailing underscore for an argument of IMSIC_HART_SIZE macros.
- Avoid wrapping format strings across lines.
- Use 'unsigned int' for cpu variable inside imsic_init().
- Use IMSIC_HART_SIZE() instead of open-code it.
- s/msi[cpu].base_addr /mmios[].base_addr for the check which checks
that MMIO addres is properly aligned.
- s/XFREE/xvfree.
- Drop zero-ing of msi[cpu].{offset,base_addr} as msi[] is zero-ed
when is allocated and cpu id can't be found twice.
- Add check to vefiry that CPU won't be found twice in interrupt-extended property of IMSIC node.
---
Changes in V4:
- s/expected/intended in the comment above imsic_get_config().
- [imsic_parse_node()] s/irq_num can be 0/irq_num can't be 0 in panic()
message.
- [imsic_parse_node()] Move "if ( irq_range[1] == IRQ_M_EXT )" after 'for loop' which checks interrupts-extended property.
- [imsic_parse_node()] s/%d/%u for logging unsigned values.
- [imsic_parse_node()] drop redundant check "(imsic_cfg.nr_ids & IMSIC_MIN_ID) != IMSIC_MIN_ID)".
- [imsic_parse_node()] free irq_range much earlier and simlify error paths.
- [imsic_parse_node()] s/-EINVAL/-ENOENT in the case of incorrect value for riscv,group-index-shift and id number.
- [[imsic_parse_node()] s/xzalloc_array/xvzalloc_array.
- s/xen_cpuid/cpu.
- Identation fix.
- use IMSIC_MMIO_PAGE_SZ instead of PAGE_SZ to check if interrupt file base
addr is properly aligned.
- s/ASM__RISCV__IMSIC_H/ASM_RISCV_IMSIC_H.
- Drop *mmios from struct imsic_cfg as it is used only by imsic_init().
- Drop cpus[] form struct imsic_mmios as it isn't really used.
- Update declaration of hartid_to_cpuid() to return unsigned int instead of NR_CPUs as processor_id is in range [0, NR_CPUS) and NR_CPUs is less then unsigned int.
- Calculate hart_index_bits as fls(*nr_parent_irqs - 1) to cover the case if nr_parent_irqs is a power of two.
- Check an MMIO's size for IMSIC node.
---
Changes in V3:
- Drop year in imsic.h in copyrights.
- Correct identation in imsic_parse_node() and imsic_init()
where for imsic_cfg.base_addr a mask is applied.
- Use unsigned int istead of uint32_t for local variable nr_parent_irqs,
index, nr_handlers in imsic_init().
- Fix a leakage of ealiers successfull allocations in case if imsic_init() returns with an error.
- Excess blank in printk() message: "%s: unable to parse MMIO regset %d\n".
- Introduce hartid_to_cpuid() and use it in the check:
if ( hardid_to_cpuid(cpuid) >= num_possible_cpus() )
in imsic_init().
- Use "%u" for unsigned int in printk(...).
- Fix for loop condition: nr_mmios -> "j < nr_mmios".
- [imsic_init()] Drop usage of j in nested loop. It is enough to have only
index.
- Change 0x%lx to %#lx for formatting of an address in printk().
- [imsic_init()] Rename local variable cpuid to hartid.
- s/imsic_get_parent_cpuid/imsic_get_parent_hartid, s/cpuid/hartid for an imsic_get_parent_hartid()'s argument.
- Declare cpus member of struct imsic_mmios as cpumask_t.
- [imsic_init()] Allocate imsic_mmios.cpus by using of alloc_cpumask_var().
- [imsic_init()] Use cpumask_set_cpu() instead of bitmap_set().
- [imsic_parse_node()] add check for correctness of "interrupt-extended" property.
- [imsic_parse_node()] Use dt_node_name() or dt_full_node_name() instead of derefence of struct dt_node.
- [imsic_parse_node()] Add cleanup label and update 'rc = XXX; goto cleanup' instead of 'return rc' as now we have to cleanup dynamically allocated irq_range array.
- Add comments above imsic_init() and imsic_parse_node().
- s/xen/arch/riscv/imsic.h/xen/arch/riscv/include/asm/imsic.h in the comment of imsic.h.
---
Changes in V2:
- Drop years in copyrights.
- s/riscv_of_processor_hartid/dt_processor_cpuid.
- s/imsic_get_parent_hartid/imsic_get_parent_hartid.
Rename argument hartid to cpuid.
Make node argument const.
Return res instead of -EINVAL for the failure case of dt_processor_cpuid(). Drop local variable hart and use cpuid argument instead.
Drop useless return res;
- imsic_parse_node() changes:
- Make node argument const.
- Check the return value of dt_property_read_u32() directly instead of
saving it to rc variable.
- Update tmp usage, use short form "-=".
- Update a check (imsic_cfg.nr_ids >= IMSIC_MAX_ID) to (imsic_cfg.nr_ids > IMSIC_MAX_ID) as IMSIC_MAX_ID is changed to maximum valid value, not just the firsr out-of-range.
- Use rc to return value instead of explicitly use -EINVAL.
- Use do {} while() to find number of MMIO register sets.
- Set IMSIC_MAX_ID to 2047 (maximum possible IRQ number).
- imsic_init() changes:
- Use unsigned int in for's expression1.
- s/xfree/XFEE.
- Allocate msi and cpus array dynamically.
- Drop forward declaration before declaration of imsic_get_config() in asm/imsic.h as it is not used as parameter type.
- Align declaration of imisic_init with defintion.
- s/harts/cpus in imisic_mmios.
Also, change type from bool harts[NR_CPUS] to unsigned long *cpus.
- Allocate msi member of imsic_config dynamically to save some memory.
- Code style fixes.
- Update the commit message.
--- xen/arch/riscv/Makefile | 1 + xen/arch/riscv/imsic.c | 369 +++++++++++++++++++++++++++++ xen/arch/riscv/include/asm/imsic.h | 55 +++++ xen/arch/riscv/include/asm/smp.h | 13 + 4 files changed, 438 insertions(+) create mode 100644 xen/arch/riscv/imsic.c create mode 100644 xen/arch/riscv/include/asm/imsic.h
xen/arch/riscv/Makefile +1 -0
@@ -2,6 +2,7 @@ obj-y += aplic.o obj-y += cpufeature.o obj-$(CONFIG_EARLY_PRINTK) += early_printk.o obj-y += entry.o +obj-y += imsic.o obj-y += intc.o obj-y += irq.o obj-y += mm.o
xen/arch/riscv/imsic.c new file +369 -0
369 lines not on this page · raw message
xen/arch/riscv/include/asm/imsic.h new file +55 -0
55 lines not on this page · raw message
xen/arch/riscv/include/asm/smp.h +13 -0
@@ -3,6 +3,7 @@#define ASM__RISCV__SMP_H #include <xen/cpumask.h> +#include <xen/macros.h> #include <xen/percpu.h> #include <asm/current.h>
@@ -18,6 +19,18 @@ static inline unsigned long cpuid_to_hartid(unsigned long cpuid)return pcpu_info[cpuid].hart_id; } +static inline unsigned int hartid_to_cpuid (unsigned long hartid) +{ +for (unsigned int cpu =0 ; cpu <ARRAY_SIZE (pcpu_info); cpu++ ) + { +if ( hartid ==cpuid_to_hartid (cpu) ) +return cpu; + } + +/* hartid isn't valid for some reason */ +return NR_CPUS ; +} +static inline void set_cpuid_to_hartid (unsigned long cpuid,unsigned long hartid) {
Signature · 1 line
2.50.0
Re: [PATCH v6 1/7] xen/riscv: imsic_init() implementation
Quoted 11 lines · Oleksii Kurochko
imsic_init()is introduced to parse device tree node, which has the following bindings [2], and based on the parsed information update IMSIC configuration which is stored inimsic_cfg.The following helpers are introduces for
imsic_init()usage:
-imsic_parse_node()parses IMSIC node from DTS
-imsic_get_parent_hartid()returns the hart ( CPU ) ID of the given device tree node.This patch is based on the code from [1].
Quoted 8 lines
Since Microchip originally developed imsic.{c,h}, an internal discussion with them led to the decision to use the MIT license.
[1] https://gitlab.com/xen-project/people/olkur/xen/-/commit/0b1a94f2bc3bb1a81cd26bb75f0bf578f84cb4d4
[2] https://elixir.bootlin.com/linux/v6.12/source/Documentation/devicetree/bindings/interrupt-controller/riscv,imsics.yamlCo-developed-by Romain Caritey <[email protected]>Signed-off-by Oleksii Kurochko <[email protected]>
I'm curious though:
Quoted 15 lines
xen/arch/riscv/include/asm/smp.h +2
-0@@ -3,6 +3,7 @@#define ASM__RISCV__SMP_H #include <xen/cpumask.h> +#include <xen/macros.h> #include <xen/percpu.h> #include <asm/current.h> @@ -18,6 +19,18 @@ static inline unsigned long cpuid_to_hartid(unsigned long cpuid)return pcpu_info[cpuid].hart_id; } +static inline unsigned int hartid_to_cpuid (unsigned long hartid)
xen/arch/riscv/include/asm/smp.h static inline unsigned long cpuid_to_hartid(unsigned long cpuid) · line 32
Quoted 10 lines
xen/arch/riscv/include/asm/smp.h +10
-0+{ +for (unsigned int cpu =0 ; cpu <ARRAY_SIZE (pcpu_info); cpu++ ) + { +if ( hartid ==cpuid_to_hartid (cpu) ) +return cpu; + } + +/* hartid isn't valid for some reason */ +return NR_CPUS ; +}
Since there's no FIXME or alike here, is this really intended to remain this way? With many CPUs this form of lookup can be pretty inefficient.
JAn
Re: [PATCH v6 1/7] xen/riscv: imsic_init() implementation
Quoted 38 lines · Jan Beulich
Quoted 11 lines · Oleksii Kurochko
imsic_init()is introduced to parse device tree node, which has the following bindings [2], and based on the parsed information update IMSIC configuration which is stored inimsic_cfg.The following helpers are introduces for
imsic_init()usage:
-imsic_parse_node()parses IMSIC node from DTS
-imsic_get_parent_hartid()returns the hart ( CPU ) ID of the given device tree node.This patch is based on the code from [1].
Quoted 8 lines
Since Microchip originally developed imsic.{c,h}, an internal discussion with them led to the decision to use the MIT license.
[1]https://gitlab.com/xen-project/people/olkur/xen/-/commit/0b1a94f2bc3bb1a81cd26bb75f0bf578f84cb4d4 [2]https://elixir.bootlin.com/linux/v6.12/source/Documentation/devicetree/bindings/interrupt-controller/riscv,imsics.yaml
Co-developed-by Romain Caritey<[email protected]>Signed-off-by Oleksii Kurochko<[email protected]>Acked-by Jan Beulich <[email protected]I'm curious though:
Quoted 14 lines
xen/arch/riscv/include/asm/smp.h +1
-0@@ -3,6 +3,7 @@#define ASM__RISCV__SMP_H #include <xen/cpumask.h> +#include <xen/macros.h> #include <xen/percpu.h> #include <asm/current.h> @@ -18,6 +19,18 @@ static inline unsigned long cpuid_to_hartid(unsigned long cpuid)return pcpu_info[cpuid].hart_id; }
Quoted 13 lines
xen/arch/riscv/include/asm/smp.h static inline unsigned long cpuid_to_hartid(unsigned long cpuid) · line 32
Quoted 11 lines
xen/arch/riscv/include/asm/smp.h +11
-0+static inline unsigned int hartid_to_cpuid (unsigned long hartid) +{ +for (unsigned int cpu =0 ; cpu <ARRAY_SIZE (pcpu_info); cpu++ ) + { +if ( hartid ==cpuid_to_hartid (cpu) ) +return cpu; + } + +/* hartid isn't valid for some reason */ +return NR_CPUS ; +}Since there's no FIXME or alike here, is this really intended to remain this way? With many CPUs this form of lookup can be pretty inefficient.
In the case with a big amount of CPUs it will require to update it. I will create TODO task in my repo to not forget to update it in a future.
Thanks.
~ Oleksii
PATCH v6 2/7 xen/riscv: aplic_init() implementation
In reply to Oleksii Kurochkoaplic_init() function does the following few things:
- checks that IMSIC in device tree node ( by checking msi-parent property in APLIC node ) is present as current one implmenetaion of AIA is supported only MSI method.
- initialize IMSIC based on IMSIC device tree node
- Read value of APLIC's paddr start/end and size.
- Map aplic.regs
- Setup APLIC initial state interrupts (disable all interrupts, set interrupt type and default priority, confgifure APLIC domaincfg) by calling aplic_init_hw_interrutps().
aplic_init() is based on the code from [1] and [2].
Since Microchip originally developed aplic.c, an internal discussion with them led to the decision to use the MIT license.
[1] https://gitlab.com/xen-project/people/olkur/xen/-/commit/7cfb4bd4748ca268142497ac5c327d2766fb342d
[2] https://gitlab.com/xen-project/people/olkur/xen/-/commit/392a531bfad39bf4656ce8128e004b241b8b3f3e
---
Changes in V6:
- Code style fixes.
- Shorten message string in aplic_init().
- Add hex offset for APLIC regs in struct aplic_regs.
---
Changes in V5:
- Fix a typo in panic massege in aplic_init(): s/Failded/Failed.
- Correct size check: (!IS_ALIGNED(size, KB(4)) && (size < KB(16))) -> (!IS_ALIGNED(size, KB(4)) || (size < KB(16))).
- Avoid wrapping format strings across lines.
---
Changes in V4:
- s/ASM__RISCV_PRIV_APLIC_H/ASM_RISCV_PRIV_APLIC_H
- Drop APLIC_MAX_NUM_WIRED_IRQ_SOURCES and use ARRAY_SIZE(aplic.regs->sourcecfg).
- Don't use 'else if' for the case when the earlier if() ends in an unconditional control flow change.
- Use const for aplic_ops and drop __ro_after_init.
- Add checks of APLIC's memory-mapped control region physical address and size.
- s/ASM__RISCV__APLIC_H/ASM_RISCV_APLIC_H.
- Use unsigned int in defintion of APLIC_DOMAINCFG_IE and APLIC_DOMAINCFG_DM.
- set aplic_info.num_irqs to ARRAY_SIZE(aplic.regs->sourcecfg) if DT node provides too much.
- Add some constraints for aplic.paddr_start and aplic.size.
---
Changes in V3:
- Correct the comment on top of aplic-priv.h:
xen/arch/riscv/aplic.h -> .../aplic-priv.h
- Add __iomem for regs member of aplic_priv structure.
- [aplic_init_hw_interrupts] Use ~0U instead of -1U in aplic_init_hw_interrupts() to disable all interrupts.
- [aplic_init_hw_interrupts] Start 'i' (for-cycle variable) from 0, not from 1.
- [aplic_init()] Declare imsic_node as pointer-to-const.
- Use decimal for arrays in struct aplic_regs.
- [aplic_init()] Check that aplic_info.num_irqs are less then 1023.
- [aplic_init()] Drop out check of IMSIC's node interrupt-extended property from aplic_init().
---
Changes in V2:
- use __ro_after_init for aplic_ops.
- s/nr_irqs/num_irqs.
- s/dt_processor_hartid/dt_processor_cpuid.
- Drop confusing comment in aplic_init_hw_interrupts().
- Code style fixes.
- Drop years for Copyright.
- Revert changes which drop nr_irq define from asm/irq.h,
it shouldn't be, at least, part of this patch.
- Drop paddr_enf from struct aplic_regs. It is enough to have pair (paddr_start, size).
- Make struct aplic_priv of asm/aplic.h private by moving it to riscv/aplic-priv.h.
- Add the comment above the initialization of APLIC's target register.
- use writel() to access APLIC's registers.
- use 'unsinged int' for local variable i in aplic_init_hw_interrupts.
- Add the check that all modes in interrupts-extended property of imsic node are equal. And drop rc != EOVERFLOW when interrupts-extended property is read.
- Add cf_check to aplic_init().
- Fix a cycle of clrie register initialization in aplic_init_hw_interrupts(). Previous implementation leads to out-of-boundary.
- Declare member num_irqs in struct intc_info as it is used by APLIC code.
--- xen/arch/riscv/aplic-priv.h | 34 ++++++++++ xen/arch/riscv/aplic.c | 103 +++++++++++++++++++++++++++++ xen/arch/riscv/include/asm/aplic.h | 64 ++++++++++++++++++ xen/arch/riscv/include/asm/intc.h | 3 + 4 files changed, 204 insertions(+) create mode 100644 xen/arch/riscv/aplic-priv.h create mode 100644 xen/arch/riscv/include/asm/aplic.h
xen/arch/riscv/aplic-priv.h new file +34 -0
@@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: MIT */ + +/* +* xen/arch/riscv/aplic-priv.h +* +* Private part of aplic.h header. +* +* RISC-V Advanced Platform-Level Interrupt Controller support +* +* Copyright (c) Microchip. +* Copyright (c) Vates. +*/ + +#ifndef ASM_RISCV_PRIV_APLIC_H +#define ASM_RISCV_PRIV_APLIC_H + +#include <xen/types.h> + +#include <asm/aplic.h> +#include <asm/imsic.h> + +struct aplic_priv { +/* Base physical address and size */ +paddr_t paddr_start; +size_t size; + +/* Registers */ +volatile struct aplic_regs __iomem *regs; + +/* IMSIC configuration */ +const struct imsic_config *imsic_cfg; +}; + +#endif /* ASM_RISCV_PRIV_APLIC_H */
xen/arch/riscv/aplic.c +103 -0
130 lines not on this page · raw message
xen/arch/riscv/include/asm/aplic.h new file +64 -0
64 lines not on this page · raw message
xen/arch/riscv/include/asm/intc.h +3 -0
@@ -19,6 +19,9 @@ struct irq_desc;struct intc_info {enum intc_version hw_version;const struct dt_device_node *node; + +/* number of irqs */ +unsigned int num_irqs; };struct intc_hw_operations {
Signature · 1 line
2.50.0
Re: [PATCH v6 2/7] xen/riscv: aplic_init() implementation
Quoted 13 lines · Oleksii Kurochko
xen/arch/riscv/aplic-priv.h new file +10
-0@@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: MIT */ + +/* +* xen/arch/riscv/aplic-priv.h +* +* Private part of aplic.h header. +* +* RISC-V Advanced Platform-Level Interrupt Controller support +* +* Copyright (c) Microchip.
xen/arch/riscv/aplic-priv.h line 20
Quoted 10 lines
xen/arch/riscv/aplic-priv.h new file +10
-0+* Copyright (c) Vates. +*/ + +#ifndef ASM_RISCV_PRIV_APLIC_H +#define ASM_RISCV_PRIV_APLIC_H + +#include <xen/types.h> + +#include <asm/aplic.h> +#include <asm/imsic.h>
Why is the latter one needed here? Certainly not for ...
xen/arch/riscv/aplic-priv.h line 31
Quoted 10 lines
xen/arch/riscv/aplic-priv.h new file +10
-0+struct aplic_priv { +/* Base physical address and size */ +paddr_t paddr_start; +size_t size; + +/* Registers */ +volatile struct aplic_regs __iomem *regs; + +/* IMSIC configuration */ +const struct imsic_config *imsic_cfg;
... this field decl (which itself serves as a forward decl of the struct tag).
Quoted 15 lines
xen/arch/riscv/aplic.c +4
-0@@ -9,19 +9,118 @@* Copyright (c) 2024-2025 Vates */ +#include <xen/device_tree.h> #include <xen/errno.h> #include <xen/init.h> #include <xen/irq.h> +#include <xen/mm.h> #include <xen/sections.h> #include <xen/types.h> +#include <xen/vmap.h> +
xen/arch/riscv/aplic.c line 30
Quoted 10 lines
xen/arch/riscv/aplic.c +7
-0+#include "aplic-priv.h" #include <asm/device.h> +#include <asm/imsic.h> #include <asm/intc.h> +#include <asm/riscv_encoding.h> + +#define APLIC_DEFAULT_PRIORITY 1 + +static struct aplic_priv aplic;
Is this altered post-init? IOW can it be __ro_after_init? Or otherwise at least __read_mostly?
With these two taken care of (one way or another):
If you clarify what is wanted / needed, I'm also happy to make adjustments while committing.
Jan
Re: [PATCH v6 2/7] xen/riscv: aplic_init() implementation
Quoted 26 lines · Jan Beulich
Quoted 13 lines · Oleksii Kurochko
xen/arch/riscv/aplic-priv.h new file +10
-0@@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: MIT */ + +/* +* xen/arch/riscv/aplic-priv.h +* +* Private part of aplic.h header. +* +* RISC-V Advanced Platform-Level Interrupt Controller support +* +* Copyright (c) Microchip. xen/arch/riscv/aplic-priv.h line 20
Quoted 10 lines
xen/arch/riscv/aplic-priv.h new file +10
-0+* Copyright (c) Vates. +*/ + +#ifndef ASM_RISCV_PRIV_APLIC_H +#define ASM_RISCV_PRIV_APLIC_H + +#include <xen/types.h> + +#include <asm/aplic.h> +#include <asm/imsic.h> Why is the latter one needed here? Certainly not for ...
Quoted 12 lines
xen/arch/riscv/aplic-priv.h line 31
Quoted 10 lines
xen/arch/riscv/aplic-priv.h new file +10
-0+struct aplic_priv { +/* Base physical address and size */ +paddr_t paddr_start; +size_t size; + +/* Registers */ +volatile struct aplic_regs __iomem *regs; + +/* IMSIC configuration */ +const struct imsic_config *imsic_cfg;... this field decl (which itself serves as a forward decl of the struct tag).
The purpose was to deal with a forward decl but I agree that in this case inclusion of <asm/imsic.h> could be dropped.
Quoted 18 lines
Quoted 18 lines
xen/arch/riscv/aplic.c +5
-0@@ -9,19 +9,118 @@* Copyright (c) 2024-2025 Vates */ +#include <xen/device_tree.h> #include <xen/errno.h> #include <xen/init.h> #include <xen/irq.h> +#include <xen/mm.h> #include <xen/sections.h> #include <xen/types.h> +#include <xen/vmap.h> + +#include "aplic-priv.h"
Quoted 10 lines
xen/arch/riscv/aplic.c line 30
Quoted 8 lines
xen/arch/riscv/aplic.c +6
-0#include <asm/device.h> +#include <asm/imsic.h> #include <asm/intc.h> +#include <asm/riscv_encoding.h> + +#define APLIC_DEFAULT_PRIORITY 1 + +static struct aplic_priv aplic;Is this altered post-init? IOW can it be
__ro_after_init? Or otherwise at least__read_mostly?
Looking at the current downstream code there is, at least one case, where aplic->regs are changing (during vaplic_emulate_store()).
So __read_mostly would be better in this case.
Quoted 4 lines
With these two taken care of (one way or another):
Acked-by Jan Beulich<[email protected]>If you clarify what is wanted / needed, I'm also happy to make adjustments while committing.
It would be nice to do the following:
- Drop the inclusion of <asm/imsic.h> in aplic-priv.h.
- Add __read_mostly to the definition of the aplic variable.
Thanks for adjustments.
~ Oleksii
Re: [PATCH v6 2/7] xen/riscv: aplic_init() implementation
Quoted 10 lines · Oleksii Kurochko
Quoted 4 lines · Jan Beulich
Quoted 1 line · Oleksii Kurochko
+static struct
aplic_privaplic;Is this altered post-init? IOW can it be
__ro_after_init? Or otherwise at least__read_mostly?Looking at the current downstream code there is, at least one case, where
aplic->regsare changing (duringvaplic_emulate_store()).
So__read_mostlywould be better in this case.
Quoted 8 lines
Quoted 4 lines
With these two taken care of (one way or another):
Acked-by Jan Beulich<[email protected]>If you clarify what is wanted / needed, I'm also happy to make adjustments while committing.
It would be nice to do the following:
- Drop the inclusion of <asm/imsic.h> inaplic-priv.h.
- Add__read_mostlyto the definition of the aplic variable.
Actually - no. Patch 4 adds a spin lock in the structure. That way it's definitely not mostly read.
Jan
Re: [PATCH v6 2/7] xen/riscv: aplic_init() implementation
In reply to Oleksii KurochkoQuoted 8 lines · Oleksii Kurochko
xen/arch/riscv/aplic-priv.h new file +5
-0@@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: MIT */ + +/* +* xen/arch/riscv/aplic-priv.h +*
xen/arch/riscv/aplic-priv.h line 15
Quoted 10 lines
xen/arch/riscv/aplic-priv.h new file +10
-0+* Private part of aplic.h header. +* +* RISC-V Advanced Platform-Level Interrupt Controller support +* +* Copyright (c) Microchip. +* Copyright (c) Vates. +*/ + +#ifndef ASM_RISCV_PRIV_APLIC_H +#define ASM_RISCV_PRIV_APLIC_H
While, as indicated in an earlier reply, I didn't make the section placement change originally suggested, I did take the liberty to correct the order of name components of this header guard.
Jan
PATCH v6 3/7 xen/riscv: introduce intc_init() and helpers
In reply to Oleksii KurochkoIntroduce intc_init() to initialize the interrupt controller using the registered hardware ops.
Also add intc_route_irq_to_xen() to route IRQs to Xen, with support for setting IRQ type and priority via new internal helpers intc_set_irq_type() and intc_set_irq_priority().
Call intc_init() to do basic initialization steps for APLIC and IMSIC.
---
Changes in V5-V6:
- Nothing changed. Only rebase.
---
Changes in V4:
- Add Acked-by: Jan Beulich <[email protected]>.
---
Changes in V3:
- Drop ASSERIT(intc_hw_ops) in intc_init().
- Drop ASSERT(intc_hw_ops) in intc_set_irq_type() and intc_set_irq_priority() as intc_init() will be called first and so if it won't crash, then intc_hw_ops is registered.
---
Changes in V2:
- This patch was part of "xen/riscv: Introduce intc_hw_operations abstraction" and splitted to have ability to merge patch "xen/riscv: initialize interrupt controller" to the current patch (where intc_init() call is actually introduced).
- Add checks of that callbacks aren't set to NULL in intc_set_irq_priority() and intc_set_irq_type().
- add num_irqs member to struct intc_info as it is used now in intc_route_irq_to_xen().
- Add ASSERT(spin_is_locked(&desc->lock)) to intc_set_irq_priority() in
the case this function will be called outside intc_route_irq_to_xen().
--- xen/arch/riscv/include/asm/intc.h | 4 +++ xen/arch/riscv/intc.c | 41 +++++++++++++++++++++++++++++++ xen/arch/riscv/setup.c | 2 ++ 3 files changed, 47 insertions(+)
xen/arch/riscv/include/asm/intc.h +4 -0
@@ -43,4 +43,8 @@ void intc_preinit(void);void register_intc_ops (const struct intc_hw_operations *ops); +void intc_init (void ); + +void intc_route_irq_to_xen (struct irq_desc *desc,unsigned int priority); +#endif /* ASM__RISCV__INTERRUPT_CONTOLLER_H */
xen/arch/riscv/intc.c +41 -0
53 lines not on this page · raw message
xen/arch/riscv/setup.c +2 -0
@@ -134,6 +134,8 @@ void __init noreturn start_xen(unsigned long bootcpu_id,intc_preinit (); +intc_init (); +printk ("All set up\n" );machine_halt ();
Signature · 1 line
2.50.0
PATCH v6 4/7 xen/riscv: implementation of aplic and imsic operations
In reply to Oleksii KurochkoIntroduce interrupt controller descriptor for host APLIC to describe the low-lovel hardare. It includes implementation of the following functions:
- aplic_irq_startup()
- aplic_irq_enable()
- aplic_irq_disable()
- aplic_set_irq_affinity()
As APLIC is used in MSI mode it requires to enable/disable interrupts not only for APLIC but also for IMSIC. Thereby for the purpose of aplic_irq_{enable,disable}() it is introduced imsic_irq_{enable,disable)().
For the purpose of aplic_set_irq_affinity() aplic_get_cpu_from_mask() is introduced to get hart id.
Also, introduce additional interrupt controller h/w operations and host_irq_type for APLIC:
- aplic_host_irq_type
Patch is based on the code from [1].
[1] https://gitlab.com/xen-project/people/olkur/xen/-/commit/7390e2365828b83e27ead56b03114a56e3699dd5
---
Changes in V6:
- Fix code style issue: start multi-word comments with a capital letter.
- Align properly comment in imsic_irq_enable().
---
Changes in V5:
- Add Acked-by: Jan Beulich <[email protected]>.
---
Changes in V4:
- Code style fixes.
- Add cf_check for hook functions.
- Use min() macros instead of open-coding it in imsic_local_eix_update().
- Update the comment above ASSERT() in imsic_irq_disable():
s/aplic_irq_enable/aplic_irq_disable.
- Add an explanatory comment above initializing of hhxs in aplic_set_irq_affinity().
---
Changes in V3:
- Update the lock above lock member of struct aplic_priv and imsic_config struct.
- Use spin_{un}lock() in aplic_irq_{enable,disable}() as it is IRQ-safe.
Also drop local variable 'flags'.
- Add ASSERT(spin_is_locked(&desc->lock)) to aplic_set_irq_affinity() and aplic_set_irq_type().
- Use an initializer instead of spin_lock_init() for aplic.lock.
- Drop "(l)" in the comment in imsic_irq_enable() as it doesn't point to
anything.
- Use ASSERT(!local_irq_is_enabled()) + spin_lock() in imsic_irq_{enable,disable}().
- Use an initializer instead of spin_lock_init() for imsic_config.lock.
---
Changes in V2:
- Move imsic_ids_local_delivery() and connected to it parts to the current
patch to fix compilation issue. Also, add __init for
imsic_ids_local_delivery().
- Move introduction of aplic_set_irq_type() and aplic_set_irq_priority()
to patch [PATCH v1 12/14] xen/riscv: implement setup_irq() where they
really started to be used.
- Update the commit message.
- Drop is_used variable for imsic_cfg and use (aplic.regs->domaincfg & APLIC_DOMAINCFG_DM) instead.
- Use writel() to write to APLIC regs.
- Drop aplic_irq_shutdown() and use aplic_irq_disable explicitly.
- Drop local variable cpu in aplic_get_cpu_from_mask():
Use cpu_online_map instead of cpu_possible_map.
Remame possible_mask to mask.
- Code style fixes.
- Move spin_lock(&aplic.lock) down before write to the register in aplic_set_irq_affinity.
- Make aplic_host_irq_type const.
- imsic_local_eix_update() updates:
- move unsigned long isel, ireg; to inner loop.
- Drop unnecessary parentheses.
- Optimize inner loop of ireg's setting.
- Drop aplic_irq_ack() and aplic_host_irq_end() as they do nothing.
- Rename s/hwirq/irq.
- Add explanatory comment to imsic_irq_enable() about why there is not -1 for IRQ in comparison with APLIC's sourcecfg.
- Use IMSIC_MMIO_PAGE_SHIFT instead of constant 12 in aplic_set_irq_affinity().
- s/aplic_host_irq_type/aplic_xen_irq_type
- Drop set/clear of IRQ_DISABLED bit in aplic_{enable,disable}() as guest will always first request an interrupt and then only an interrupt will be enabled.
(for example, in Arm, the physical interrupts would be enabled when the
interrupt is initially routed. This could lead to problem because the guest
will usually boot with interrupt disabled.)
--- xen/arch/riscv/aplic-priv.h | 4 + xen/arch/riscv/aplic.c | 123 ++++++++++++++++++++++++++++- xen/arch/riscv/imsic.c | 122 +++++++++++++++++++++++++++- xen/arch/riscv/include/asm/aplic.h | 2 + xen/arch/riscv/include/asm/imsic.h | 18 +++++ 5 files changed, 267 insertions(+), 2 deletions(-)
xen/arch/riscv/aplic-priv.h +4 -0
@@ -14,6 +14,7 @@#ifndef ASM_RISCV_PRIV_APLIC_H #define ASM_RISCV_PRIV_APLIC_H +#include <xen/spinlock.h> #include <xen/types.h> #include <asm/aplic.h>
@@ -27,6 +28,9 @@ struct aplic_priv {/* Registers */ volatile struct aplic_regs __iomem *regs; +/* Lock to protect access to APLIC's registers */ +spinlock_t lock; +/* IMSIC configuration */ const struct imsic_config *imsic_cfg; };
xen/arch/riscv/aplic.c +122 -1
148 lines not on this page · raw message
xen/arch/riscv/imsic.c +121 -1
134 lines not on this page · raw message
xen/arch/riscv/include/asm/aplic.h +2 -0
@@ -18,6 +18,8 @@#define APLIC_DOMAINCFG_IE BIT(8, U)#define APLIC_DOMAINCFG_DM BIT(2, U) +#define APLIC_TARGET_HART_IDX_SHIFT 18 +struct aplic_regs {uint32_t domaincfg;/* 0x0000 */ uint32_t sourcecfg[1023 ];/* 0x0004 */
xen/arch/riscv/include/asm/imsic.h +18 -0
@@ -11,6 +11,7 @@#ifndef ASM_RISCV_IMSIC_H #define ASM_RISCV_IMSIC_H +#include <xen/spinlock.h> #include <xen/types.h> #define IMSIC_MMIO_PAGE_SHIFT 12
@@ -19,6 +20,15 @@#define IMSIC_MIN_ID 63#define IMSIC_MAX_ID 2047 +#define IMSIC_EIDELIVERY 0x70 + +#define IMSIC_EITHRESHOLD 0x72 + +#define IMSIC_EIP0 0x80 +#define IMSIC_EIPx_BITS 32 + +#define IMSIC_EIE0 0xC0 +struct imsic_msi {paddr_t base_addr;unsigned long offset;
@@ -45,6 +55,9 @@ struct imsic_config {/* MSI */ const struct imsic_msi *msi; + +/* Lock to protect access to IMSIC's stuff */ +spinlock_t lock; };struct dt_device_node ;
@@ -52,4 +65,9 @@ int imsic_init(const struct dt_device_node *node);const struct imsic_config *imsic_get_config (void ); +void imsic_irq_enable (unsigned int hwirq); +void imsic_irq_disable (unsigned int hwirq); + +void imsic_ids_local_delivery (bool enable); +#endif /* ASM_RISCV_IMSIC_H */
Signature · 1 line
2.50.0
PATCH v6 5/7 xen/riscv: add external interrupt handling for hypervisor mode
In reply to Oleksii KurochkoImplement functions necessarry to have working external interrupts in hypervisor mode. The following changes are done:
- Add a common function intc_handle_external_irq() to call APLIC specific function to handle an interrupt.
- Update do_trap() function to handle IRQ_S_EXT case; add the check to catch case when cause of trap is an interrupt.
- Add handle_interrrupt() member to intc_hw_operations structure.
- Enable local interrupt delivery for IMSIC by calling of imsic_ids_local_delivery() in imsic_init(); additionally introduce helper imsic_csr_write() to update IMSIC_EITHRESHOLD and IMSIC_EITHRESHOLD.
- Enable hypervisor external interrupts.
- Implement aplic_handler_interrupt() and use it to init ->handle_interrupt member of intc_hw_operations for APLIC.
- Add implementation of do_IRQ() to dispatch the interrupt.
The current patch is based on the code from [1].
[1] https://gitlab.com/xen-project/people/olkur/xen/-/commit/7390e2365828b83e27ead56b03114a56e3699dd5
---
Changes in V6:
- Fix code style issue: start multi-word comments with a capital letter.
- Align properly comment in aplic_set_irq_type().
---
Changes in V4 - V5:
- Nothing changed. Only rebase.
---
Changes in V3:
- Add ASSERT(spin_is_locked(&desc->lock)) to aplic_set_irq_type().
- Fix code style for switch () in aplic_set_irq_type().
- Drop fallthrough between "case IRQ_TYPE_NONE: case IRQ_TYPE_INVALID:" as there is no other statements in "case IRQ_TYPE_NONE".
- Add Acked-by: Jan Beulich <[email protected]>.
---
Changes in V2:
- use BIT() macros instead of 1UL << bit_num in aplic.c.
- Drop passing of a cause to aplic_handle_interrupt() function. And update prototype of handle_interrupt() callback.
- Drop ASSERT() in intc_handle_external_irqs() as it is useless.
- Code style fixes.
- Drop cause argument for intc_handle_external_irqs().
- Update the commit message: drop words that imsic_ids_local_delivery() is implemented in this patch, it is only called.
- Add cf_check for aplic_handle_interrupt(), aplic_set_irq_type().
- Move forward declarations in asm/intc.h up.
- Use plain C operator instead if {clear,set}_bit() for desc->status as it is always used under spinlock().
- use writel() for writing to APLIC's sourcecfg in aplic_set_irq_type().
--- xen/arch/riscv/aplic.c | 73 ++++++++++++++++++++++++++++++ xen/arch/riscv/include/asm/aplic.h | 7 +++ xen/arch/riscv/include/asm/imsic.h | 1 + xen/arch/riscv/include/asm/intc.h | 6 +++ xen/arch/riscv/include/asm/irq.h | 6 ++- xen/arch/riscv/intc.c | 5 ++ xen/arch/riscv/irq.c | 47 +++++++++++++++++++ xen/arch/riscv/traps.c | 19 ++++++++ 8 files changed, 163 insertions(+), 1 deletion(-)
xen/arch/riscv/aplic.c +73 -0
@@ -9,6 +9,7 @@* Copyright (c) 2024-2025 Vates */ +#include <xen/const.h> #include <xen/device_tree.h> #include <xen/errno.h> #include <xen/init.h>
@@ -227,6 +228,73 @@ static void cf_check aplic_set_irq_affinity(struct irq_desc *desc, const cpumaskspin_unlock (&aplic.lock); } +static void cf_check aplic_handle_interrupt(struct cpu_user_regs *regs) +{ +/* Disable to avoid more external interrupts */ +csr_clear (CSR_SIE ,BIT (IRQ_S_EXT ,UL )); + +/* Clear the pending bit */ +csr_clear (CSR_SIP ,BIT (IRQ_S_EXT ,UL )); + +/* Dispatch the interrupt */ +do_IRQ (regs,csr_swap (CSR_STOPEI ,0 ) >>TOPI_IID_SHIFT ); + +/* Enable external interrupts */ +csr_set (CSR_SIE ,BIT (IRQ_S_EXT ,UL )); +} + +static void cf_check aplic_set_irq_type(struct irq_desc *desc, +unsigned int type) +{ +/* +* Interrupt 0 isn't possible based on the spec: +* Each of an APLIC’s interrupt sources has a fixed unique identity +* number in the range 1 to N, where N is the total number of sources at +* the APLIC. The number zero is not a valid interrupt identity number at +* an APLIC. The maximum number of interrupt sources an APLIC may support +* is 1023. +* +* Thereby interrupt 1 will correspond to bit 0 in sourcecfg[] register, +* interrupt 2 ->sourcecfg[1] and so on. +* +* And that is the reason why we need -1. +*/ +unsigned int irq_bit = desc->irq -1 ; + +ASSERT (spin_is_locked (&desc->lock)); + +spin_lock (&aplic.lock); + +switch ( type ) + { +case IRQ_TYPE_EDGE_RISING : +writel (APLIC_SOURCECFG_SM_EDGE_RISE , &aplic.regs->sourcecfg[irq_bit]); +break ; + +case IRQ_TYPE_EDGE_FALLING : +writel (APLIC_SOURCECFG_SM_EDGE_FALL , &aplic.regs->sourcecfg[irq_bit]); +break ; + +case IRQ_TYPE_LEVEL_HIGH : +writel (APLIC_SOURCECFG_SM_LEVEL_HIGH , &aplic.regs->sourcecfg[irq_bit]); +break ; + +case IRQ_TYPE_LEVEL_LOW : +writel (APLIC_SOURCECFG_SM_LEVEL_LOW , &aplic.regs->sourcecfg[irq_bit]); +break ; + +case IRQ_TYPE_NONE : +case IRQ_TYPE_INVALID : +writel (APLIC_SOURCECFG_SM_INACTIVE , &aplic.regs->sourcecfg[irq_bit]); +break ; + +default : +panic ("%s: APLIC doesnt support IRQ type: 0x%x?\n" , __func__, type); + } + +spin_unlock (&aplic.lock); +} +static const hw_irq_controller aplic_xen_irq_type = { .typename ="aplic" , .startup = aplic_irq_startup,
@@ -240,6 +308,8 @@ static const struct intc_hw_operations aplic_ops = { .info = &aplic_info, .init = aplic_init, .host_irq_type = &aplic_xen_irq_type, + .handle_interrupt = aplic_handle_interrupt, + .set_irq_type = aplic_set_irq_type, }; static int cf_check aplic_irq_xlate(const uint32_t *intspec,
@@ -279,6 +349,9 @@ static int __init aplic_preinit(struct dt_device_node *node, const void *dat)register_intc_ops (&aplic_ops); +/* Enable supervisor external interrupt */ +csr_set (CSR_SIE ,BIT (IRQ_S_EXT ,UL )); +return 0 ; }
xen/arch/riscv/include/asm/aplic.h +7 -0
@@ -18,6 +18,13 @@#define APLIC_DOMAINCFG_IE BIT(8, U)#define APLIC_DOMAINCFG_DM BIT(2, U) +#define APLIC_SOURCECFG_SM_INACTIVE 0x0 +#define APLIC_SOURCECFG_SM_DETACH 0x1 +#define APLIC_SOURCECFG_SM_EDGE_RISE 0x4 +#define APLIC_SOURCECFG_SM_EDGE_FALL 0x5 +#define APLIC_SOURCECFG_SM_LEVEL_HIGH 0x6 +#define APLIC_SOURCECFG_SM_LEVEL_LOW 0x7 +#define APLIC_TARGET_HART_IDX_SHIFT 18struct aplic_regs {
xen/arch/riscv/include/asm/imsic.h +1 -0
@@ -12,6 +12,7 @@#define ASM_RISCV_IMSIC_H #include <xen/spinlock.h> +#include <xen/stdbool.h> #include <xen/types.h> #define IMSIC_MMIO_PAGE_SHIFT 12
xen/arch/riscv/include/asm/intc.h +6 -0
@@ -14,6 +14,7 @@ enum intc_version { INTC_APLIC, }; +struct cpu_user_regs ;struct irq_desc ;struct intc_info {
@@ -37,6 +38,9 @@ struct intc_hw_operations {void (*set_irq_type)(struct irq_desc *desc,unsigned int type);/* Set IRQ priority */ void (*set_irq_priority)(struct irq_desc *desc,unsigned int priority); + +/* handle external interrupt */ +void (*handle_interrupt)(struct cpu_user_regs *regs); };void intc_preinit (void );
@@ -47,4 +51,6 @@ void intc_init(void);void intc_route_irq_to_xen (struct irq_desc *desc,unsigned int priority); +void intc_handle_external_irqs (struct cpu_user_regs *regs); +#endif /* ASM__RISCV__INTERRUPT_CONTOLLER_H */
xen/arch/riscv/include/asm/irq.h +5 -1
@@ -33,16 +33,20 @@ struct arch_irq_desc { unsigned int type; }; +struct cpu_user_regs ; +struct dt_device_node ; +static inline void arch_move_irqs (struct vcpu *v) {BUG_ON ("unimplemented" ); } -struct dt_device_node ;int platform_get_irq (const struct dt_device_node *device,int index);void init_IRQ (void ); +void do_IRQ (struct cpu_user_regs *regs,unsigned int irq); +#endif /* ASM__RISCV__IRQ_H */ /*
xen/arch/riscv/intc.c +5 -0
@@ -50,6 +50,11 @@ static void intc_set_irq_priority(struct irq_desc *desc, unsigned int priority) intc_hw_ops->set_irq_priority (desc, priority); } +void intc_handle_external_irqs (struct cpu_user_regs *regs) +{ + intc_hw_ops->handle_interrupt (regs); +} +void intc_route_irq_to_xen (struct irq_desc *desc,unsigned int priority) {ASSERT (desc->status &IRQ_DISABLED );
xen/arch/riscv/irq.c +47 -0
56 lines not on this page · raw message
xen/arch/riscv/traps.c +19 -0
@@ -11,6 +11,7 @@#include <xen/nospec.h> #include <xen/sched.h> +#include <asm/intc.h> #include <asm/processor.h> #include <asm/riscv_encoding.h> #include <asm/traps.h>
@@ -128,6 +129,24 @@ void do_trap(struct cpu_user_regs *cpu_regs) } fallthrough;default : +if ( cause &CAUSE_IRQ_FLAG ) + { +/* Handle interrupt */ +unsigned long icause = cause & ~CAUSE_IRQ_FLAG ; + +switch ( icause ) + { +case IRQ_S_EXT : +intc_handle_external_irqs (cpu_regs); +break ; + +default : +break ; + } + +break ; + } +do_unexpected_trap (cpu_regs);break ; }
Signature · 1 line
2.50.0
PATCH v6 6/7 xen/riscv: implement setup_irq()
In reply to Oleksii KurochkoIntroduce support for IRQ setup on RISC-V by implementing setup_irq() and __setup_irq(), adapted and extended from an initial implementation by [1].
__setup_irq() does the following:
- Sets up an IRQ action.
- Validates that shared IRQs have non-NULL dev_id and are only used when existing handlers allow sharing.
- Uses smp_wmb() to enforce memory ordering after assigning desc->action to ensure visibility before enabling the IRQ.
- Supports multi-action setups via CONFIG_IRQ_HAS_MULTIPLE_ACTION.
setup_irq() does the following:
- Converts IRQ number to descriptor and acquires its lock.
- Rejects registration if the IRQ is already assigned to a guest domain, printing an error.
- Delegates the core setup to __setup_irq().
- On first-time setup, disables the IRQ, routes it to Xen using intc_route_irq_to_xen(), sets default CPU affinity (current CPU), calls the handler’s startup routine, and finally enables the IRQ.
irq_set_affinity() invokes set_affinity() callback from the IRQ handler if present.
Defined IRQ_NO_PRIORITY as default priority used when routing IRQs to Xen.
[1] https://gitlab.com/xen-project/people/olkur/xen/-/commit/7390e2365828b83e27ead56b03114a56e3699dd5
---
Changes in V6:
- Nothing changed. Only rebase.
---
Changes in V5:
- Add Acked-by: Jan Beulich <[email protected]>.
---
Changes in V3-4:
- Nothing changed. Only rebase.
---
Changes in V2:
- Added implenmtation of aplic_set_irq_type() as it is going to be used in this commit. And also, update the implementation of it. Make default case of switch to do panic().
- Move all forward declaration up in asm/irq.h.
- s/__setup_irq/_setup_irq.
- Code style fixes.
- Update commit message.
- use smp_wmb() instead of smp_mb() in _setup_irq().
- Drop irq_set_affinity().
- Use plain C operator instead if {clear,set}_bit() for desc->status as it is always used under spinlock().
- Drop set_bit(_IRQ_DISABLED, &desc->status) in setup_irq() as in the case when IRQ is setuped for a first time, desc->status should be already set to IRQ_DISABLED in init_one_irq_desc().
----
xen/arch/riscv/include/asm/irq.h | 2 + xen/arch/riscv/irq.c | 84 ++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+)
xen/arch/riscv/include/asm/irq.h +2 -0
@@ -17,6 +17,8 @@*/ #define NR_IRQS 1024 +#define IRQ_NO_PRIORITY 0 +/* TODO */ #define nr_irqs 0U#define nr_static_irqs 0
xen/arch/riscv/irq.c +84 -0
96 lines not on this page · raw message
Signature · 1 line
2.50.0
PATCH v6 7/7 xen/riscv: add basic UART support
In reply to Oleksii KurochkoUpdate Kconfig to select GENERIC_UART_INIT for basic UART init ( find a dt node and call device specific device_init() ).
Drop default n if RISCV statement for config HAS_NS16550 as now ns16550 is ready to be compiled and used by RISC-V. Also, make the config user selectable for everyone except X86.
Initialize a minimal amount of stuff to have UART and Xen console:
- Initialize uart by calling uart_init().
- Initialize Xen console by calling console_init_{pre,post}irq().
- Initialize timer and its internal lists which are used by init_timer() which is called by ns16550_init_postirq(); otherwise "Unhandled exception: Store/AMO Page Fault" occurs.
- Enable local interrupt to recieve an input from UART
---
Changes in V4-V6:
- Nothing changed. Only rebase.
---
Changes in v3:
- Drop inclusion of <xen/percpu.h> as nothing in setup.c requires it.
- Add Acked-by: Jan Beulich <[email protected]>.
---
Changes in v2:
- Drop #include <xen/keyhandler.h> in setup.c, isn't needed anymore.
- Drop call of percpu_init_areas() as it was needed when I used polling mode for UART, for this case percpu is used to receive serial port info:
struct serial_port *port = this_cpu(poll_port); So percpu isn't really needed at the current development state. - Make HAS_NS16550 user selectable for everyone, except X86. - Update the commit message. --- xen/arch/riscv/Kconfig | 1 + xen/arch/riscv/setup.c | 12 ++++++++++++ xen/drivers/char/Kconfig | 3 +-- 3 files changed, 14 insertions(+), 2 deletions(-)
xen/arch/riscv/Kconfig +1 -0
@@ -2,6 +2,7 @@ config RISCV def_bool y select FUNCTION_ALIGNMENT_16B select GENERIC_BUG_FRAME + select GENERIC_UART_INIT select HAS_DEVICE_TREE select HAS_PMAP select HAS_UBSAN
xen/arch/riscv/setup.c +12 -0
@@ -4,12 +4,15 @@#include <xen/bug.h> #include <xen/bootfdt.h> #include <xen/compile.h> +#include <xen/console.h> #include <xen/device_tree.h> #include <xen/init.h> #include <xen/irq.h> #include <xen/mm.h> +#include <xen/serial.h> #include <xen/shutdown.h> #include <xen/smp.h> +#include <xen/timer.h> #include <xen/vmap.h> #include <xen/xvmalloc.h>
@@ -134,8 +137,17 @@ void __init noreturn start_xen(unsigned long bootcpu_id,intc_preinit (); +uart_init (); +console_init_preirq (); +intc_init (); +timer_init (); + +local_irq_enable (); + +console_init_postirq (); +printk ("All set up\n" );machine_halt ();
xen/drivers/char/Kconfig +1 -2
@@ -2,8 +2,7 @@ config GENERIC_UART_INIT bool config HAS_NS16550 - bool "NS16550 UART driver" if ARM - default n if RISCV + bool "NS16550 UART driver" if !X86 default y help This selects the 16550-series UART support. For most systems, say Y.
Signature · 1 line
2.50.0