QEMU RISC-V AIA support
Subsystems (2)
v10 cover QEMU RISC-V AIA support
From: Anup Patel <[email protected]>
The advanced interrupt architecture (AIA) extends the per-HART local interrupt support. Along with this, it also adds IMSIC (MSI contrllor) and Advanced PLIC (wired interrupt controller).
The latest AIA draft specification can be found here:
https://github.com/riscv/riscv-aia/releases/download/0.2-draft.28/riscv-interrupts-028.pdf
This series adds RISC-V AIA support in QEMU which includes emulating all AIA local CSRs, APLIC, and IMSIC. Only AIA local interrupt filtering is not implemented because we don't have any local interrupt greater than 12.
To enable AIA in QEMU, use one of the following:
1) Only AIA local interrupt CSRs: Pass "x-aia=true" as CPU paramenter in the QEMU command-line
2) Only APLIC for virt machine: Pass "aia=aplic" as machine parameter in the QEMU command-line
3) Both APLIC and IMSIC for virt machine: Pass "aia=aplic-imsic" as machine parameter in the QEMU command-line
4) Both APLIC and IMSIC with 2 guest files for virt machine: Pass "aia=aplic-imsic,aia-guests=2" as machine parameter in the QEMU command-line
To test series, we require Linux with AIA support which can be found in:riscv_aia_v1 branch at https://github.com/avpatel/linux.git
This series can be found riscv_aia_v10 branch at:
https://github.com/avpatel/qemu.git
Changes since v9:
- Rebased on latest riscv-to-apply.next branch of Alistair's repo
- Removed first 18 PATCHs since these are already merged
- Fixed 32-bit system compile error in PATCH3
Changes since v8:
- Use error_setg() in riscv_imsic_realize() added by PATCH20
Changes since v7:
- Rebased on latest riscv-to-apply.next branch of Alistair's repo
- Improved default priority assignment in PATCH9
Changes since v6:
- Fixed priority comparison in riscv_cpu_pending_to_irq() of PATCH9
- Fixed typos in comments added by PATCH11
- Added "pend = true;" for CSR_MSETEIPNUM case of rmw_xsetclreinum() in PATCH15
- Handle ithreshold == 0 case in riscv_aplic_idc_topi() of PATCH18
- Allow setting pending bit for Level0 or Level1 interrupts in riscv_aplic_set_pending() of PATCH18
- Force DOMAINCFG[31:24] bits to 0x80 in riscv_aplic_read() of PATCH18
- For APLIC direct mode, set target.iprio to 1 when zero is writtern in PATCH18
- Handle eithreshold == 0 case in riscv_imsic_topei() of PATCH20
Changes since v5:
- Moved VSTOPI_NUM_SRCS define to top of the file in PATCH13
- Fixed typo in PATCH16
Changes since v4:
- Changed IRQ_LOCAL_MAX to 16 in PATCH2
- Fixed typo in PATCH10
- Replaced TARGET_LONG_BITS with riscv_cpu_mxl_bits(env) in PATCH11
- Replaced TARGET_LONG_BITS with riscv_cpu_mxl_bits(env) in PATCH14
- Replaced TARGET_LONG_BITS with riscv_cpu_mxl_bits(env) in PATCH15
- Replaced TARGET_LONG_BITS with xlen passed via ireg callback in PATCH20
- Retrict maximum IMSIC guest files per-HART of virt machine to 7 in PATCH21.
- Added separate PATCH23 to increase maximum number of allowed CPUs for virt machine
Changes since v3:
- Replaced "aplic,xyz" and "imsic,xyz" DT properties with "riscv,xyz" DT properties because "aplic" and "imsic" are not valid vendor names required by Linux DT schema checker.
Changes since v2:
- Update PATCH4 to check and inject interrupt after V=1 when transitioning from V=0 to V=1
Changes since v1:
- Revamped whole series and created more granular patches
- Added HGEIE and HGEIP CSR emulation for H-extension
- Added APLIC emulation
- Added IMSIC emulation
Anup Patel (5):
hw/riscv: virt: Add optional AIA APLIC support to virt machine hw/intc: Add RISC-V AIA IMSIC device emulation hw/riscv: virt: Add optional AIA IMSIC support to virt machine docs/system: riscv: Document AIA options for virt machine hw/riscv: virt: Increase maximum number of allowed CPUs
docs/system/riscv/virt.rst | 16 + hw/intc/Kconfig | 3 + hw/intc/meson.build | 1 + hw/intc/riscv_imsic.c | 448 ++++++++++++++++++++++ hw/riscv/Kconfig | 2 + hw/riscv/virt.c | 698 ++++++++++++++++++++++++++++------ include/hw/intc/riscv_imsic.h | 68 ++++ include/hw/riscv/virt.h | 41 +- 8 files changed, 1156 insertions(+), 121 deletions(-) create mode 100644 hw/intc/riscv_imsic.c create mode 100644 include/hw/intc/riscv_imsic.h
Signature · 1 line
2.25.1
PATCH v10 1/5 hw/riscv: virt: Add optional AIA APLIC support to virt machine
From: Anup Patel <[email protected]>
We extend virt machine to emulate AIA APLIC devices only when "aia=aplic" parameter is passed along with machine name in QEMU command-line. When "aia=none" or not specified then we fallback to original PLIC device emulation.
--- hw/riscv/Kconfig | 1 + hw/riscv/virt.c | 291 ++++++++++++++++++++++++++++++++-------- include/hw/riscv/virt.h | 26 +++- 3 files changed, 259 insertions(+), 59 deletions(-)
hw/riscv/Kconfig +1 -0
@@ -42,6 +42,7 @@ config RISCV_VIRT select PFLASH_CFI01 select SERIAL select RISCV_ACLINT + select RISCV_APLIC select SIFIVE_PLIC select SIFIVE_TEST select VIRTIO_MMIO
hw/riscv/virt.c +238 -53
443 lines not on this page · raw message
include/hw/riscv/virt.h +20 -6
@@ -32,18 +32,24 @@ typedef struct RISCVVirtState RISCVVirtState;DECLARE_INSTANCE_CHECKER (RISCVVirtState,RISCV_VIRT_MACHINE , TYPE_RISCV_VIRT_MACHINE) +typedef enum RISCVVirtAIAType { +VIRT_AIA_TYPE_NONE =0 , +VIRT_AIA_TYPE_APLIC , +}RISCVVirtAIAType ; +struct RISCVVirtState {/*< private >*/ MachineState parent;/*< public >*/ RISCVHartArrayState soc[VIRT_SOCKETS_MAX ]; -DeviceState *plic[VIRT_SOCKETS_MAX ]; +DeviceState *irqchip[VIRT_SOCKETS_MAX ];PFlashCFI01 *flash[2 ];FWCfgState *fw_cfg;int fdt_size;bool have_aclint; +RISCVVirtAIAType aia_type; };enum {
@@ -54,6 +60,8 @@ enum {VIRT_CLINT ,VIRT_ACLINT_SSWI ,VIRT_PLIC , +VIRT_APLIC_M , +VIRT_APLIC_S ,VIRT_UART0 ,VIRT_VIRTIO , VIRT_FW_CFG,
@@ -73,8 +81,9 @@ enum { VIRTIO_NDEV = 0x35 /* Arbitrary maximum number of interrupts */ }; -#define VIRT_PLIC_NUM_SOURCES 127 -#define VIRT_PLIC_NUM_PRIORITIES 7 +#define VIRT_IRQCHIP_NUM_SOURCES 127 +#define VIRT_IRQCHIP_NUM_PRIO_BITS 3 +#define VIRT_PLIC_PRIORITY_BASE 0x04#define VIRT_PLIC_PENDING_BASE 0x1000#define VIRT_PLIC_ENABLE_BASE 0x2000
@@ -86,9 +95,14 @@ enum {#define FDT_PCI_ADDR_CELLS 3#define FDT_PCI_INT_CELLS 1 -#define FDT_PLIC_ADDR_CELLS 0#define FDT_PLIC_INT_CELLS 1 -#define FDT_INT_MAP_WIDTH (FDT_PCI_ADDR_CELLS + FDT_PCI_INT_CELLS + 1 + \ - FDT_PLIC_ADDR_CELLS + FDT_PLIC_INT_CELLS) +#define FDT_APLIC_INT_CELLS 2 +#define FDT_MAX_INT_CELLS 2 +#define FDT_MAX_INT_MAP_WIDTH (FDT_PCI_ADDR_CELLS + FDT_PCI_INT_CELLS + \ + 1 + FDT_MAX_INT_CELLS) +#define FDT_PLIC_INT_MAP_WIDTH (FDT_PCI_ADDR_CELLS + FDT_PCI_INT_CELLS + \ + 1 + FDT_PLIC_INT_CELLS) +#define FDT_APLIC_INT_MAP_WIDTH (FDT_PCI_ADDR_CELLS + FDT_PCI_INT_CELLS + \ + 1 + FDT_APLIC_INT_CELLS)#endif
Signature · 1 line
2.25.1
PATCH v10 2/5 hw/intc: Add RISC-V AIA IMSIC device emulation
In reply to Anup PatelFrom: Anup Patel <[email protected]>
The RISC-V AIA (Advanced Interrupt Architecture) defines a new interrupt controller for MSIs (message signal interrupts) called IMSIC (Incoming Message Signal Interrupt Controller). The IMSIC is per-HART device and also suppport virtualizaiton of MSIs using dedicated VS-level guest interrupt files.
This patch adds device emulation for RISC-V AIA IMSIC which supports M-level, S-level, and VS-level MSIs.
--- hw/intc/Kconfig | 3 + hw/intc/meson.build | 1 + hw/intc/riscv_imsic.c | 448 ++++++++++++++++++++++++++++++++++ include/hw/intc/riscv_imsic.h | 68 ++++++ 4 files changed, 520 insertions(+) create mode 100644 hw/intc/riscv_imsic.c create mode 100644 include/hw/intc/riscv_imsic.h
hw/intc/Kconfig +3 -0
@@ -73,6 +73,9 @@ config RISCV_ACLINT config RISCV_APLIC bool +config RISCV_IMSIC + bool + config SIFIVE_PLIC bool
hw/intc/meson.build +1 -0
@@ -51,6 +51,7 @@ specific_ss.add(when: 'CONFIG_S390_FLIC_KVM', if_true: files('s390_flic_kvm.c')) specific_ss.add(when: 'CONFIG_SH_INTC', if_true: files('sh_intc.c')) specific_ss.add(when: 'CONFIG_RISCV_ACLINT', if_true: files('riscv_aclint.c')) specific_ss.add(when: 'CONFIG_RISCV_APLIC', if_true: files('riscv_aplic.c')) +specific_ss.add(when: 'CONFIG_RISCV_IMSIC', if_true: files('riscv_imsic.c')) specific_ss.add(when: 'CONFIG_SIFIVE_PLIC', if_true: files('sifive_plic.c')) specific_ss.add(when: 'CONFIG_XICS', if_true: files('xics.c')) specific_ss.add(when: ['CONFIG_KVM', 'CONFIG_XICS'],
hw/intc/riscv_imsic.c new file +448 -0
448 lines not on this page · raw message
include/hw/intc/riscv_imsic.h new file +68 -0
68 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v10 3/5 hw/riscv: virt: Add optional AIA IMSIC support to virt machine
In reply to Anup PatelFrom: Anup Patel <[email protected]>
We extend virt machine to emulate both AIA IMSIC and AIA APLIC devices only when "aia=aplic-imsic" parameter is passed along with machine name in the QEMU command-line. The AIA IMSIC is only a per-HART MSI controller so we use AIA APLIC in MSI-mode to forward all wired interrupts as MSIs to the AIA IMSIC.
We also provide "aia-guests=<xyz>" parameter which can be used to specify number of VS-level AIA IMSIC Guests MMIO pages for each HART.
--- hw/riscv/Kconfig | 1 + hw/riscv/virt.c | 439 ++++++++++++++++++++++++++++++++-------- include/hw/riscv/virt.h | 17 +- 3 files changed, 373 insertions(+), 84 deletions(-)
hw/riscv/Kconfig +1 -0
@@ -43,6 +43,7 @@ config RISCV_VIRT select SERIAL select RISCV_ACLINT select RISCV_APLIC + select RISCV_IMSIC select SIFIVE_PLIC select SIFIVE_TEST select VIRTIO_MMIO
hw/riscv/virt.c +358 -81
633 lines not on this page · raw message
include/hw/riscv/virt.h +14 -3
@@ -24,8 +24,10 @@#include "hw/block/flash.h" #include "qom/object.h" -#define VIRT_CPUS_MAX 32 -#define VIRT_SOCKETS_MAX 8 +#define VIRT_CPUS_MAX_BITS 3 +#define VIRT_CPUS_MAX (1 << VIRT_CPUS_MAX_BITS) +#define VIRT_SOCKETS_MAX_BITS 2 +#define VIRT_SOCKETS_MAX (1 << VIRT_SOCKETS_MAX_BITS)#define TYPE_RISCV_VIRT_MACHINE MACHINE_TYPE_NAME("virt")typedef struct RISCVVirtState RISCVVirtState ;
@@ -35,6 +37,7 @@ DECLARE_INSTANCE_CHECKER(RISCVVirtState, RISCV_VIRT_MACHINE,typedef enum RISCVVirtAIAType {VIRT_AIA_TYPE_NONE =0 ,VIRT_AIA_TYPE_APLIC , +VIRT_AIA_TYPE_APLIC_IMSIC , }RISCVVirtAIAType ;struct RISCVVirtState {
@@ -50,6 +53,7 @@ struct RISCVVirtState {int fdt_size;bool have_aclint;RISCVVirtAIAType aia_type; +int aia_guests; };enum {
@@ -65,6 +69,8 @@ enum {VIRT_UART0 ,VIRT_VIRTIO ,VIRT_FW_CFG , +VIRT_IMSIC_M , +VIRT_IMSIC_S ,VIRT_FLASH ,VIRT_DRAM , VIRT_PCIE_MMIO,
@@ -81,8 +87,12 @@ enum { VIRTIO_NDEV = 0x35 /* Arbitrary maximum number of interrupts */ }; -#define VIRT_IRQCHIP_NUM_SOURCES 127 +#define VIRT_IRQCHIP_IPI_MSI 1 +#define VIRT_IRQCHIP_NUM_MSIS 255 +#define VIRT_IRQCHIP_NUM_SOURCES VIRTIO_NDEV#define VIRT_IRQCHIP_NUM_PRIO_BITS 3 +#define VIRT_IRQCHIP_MAX_GUESTS_BITS 3 +#define VIRT_IRQCHIP_MAX_GUESTS ((1U << VIRT_IRQCHIP_MAX_GUESTS_BITS) - 1U)#define VIRT_PLIC_PRIORITY_BASE 0x04#define VIRT_PLIC_PENDING_BASE 0x1000
@@ -97,6 +107,7 @@ enum {#define FDT_PCI_INT_CELLS 1#define FDT_PLIC_INT_CELLS 1#define FDT_APLIC_INT_CELLS 2 +#define FDT_IMSIC_INT_CELLS 0#define FDT_MAX_INT_CELLS 2#define FDT_MAX_INT_MAP_WIDTH (FDT_PCI_ADDR_CELLS + FDT_PCI_INT_CELLS + \ 1 + FDT_MAX_INT_CELLS)
Signature · 1 line
2.25.1
PATCH v10 4/5 docs/system: riscv: Document AIA options for virt machine
In reply to Anup PatelFrom: Anup Patel <[email protected]>
We have two new machine options "aia" and "aia-guests" available for the RISC-V virt machine so let's document these options.
--- docs/system/riscv/virt.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
docs/system/riscv/virt.rst +16 -0
@@ -63,6 +63,22 @@ The following machine-specific options are supported: When this option is "on", ACLINT devices will be emulated instead of SiFive CLINT. When not specified, this option is assumed to be "off". +- aia=[none|aplic|aplic-imsic] + + This option allows selecting interrupt controller defined by the AIA + (advanced interrupt architecture) specification. The "aia=aplic" selects + APLIC (advanced platform level interrupt controller) to handle wired + interrupts whereas the "aia=aplic-imsic" selects APLIC and IMSIC (incoming + message signaled interrupt controller) to handle both wired interrupts and + MSIs. When not specified, this option is assumed to be "none" which selects + SiFive PLIC to handle wired interrupts. + +- aia-guests=nnn + + The number of per-HART VS-level AIA IMSIC pages to be emulated for a guest + having AIA IMSIC (i.e. "aia=aplic-imsic" selected). When not specified, + the default number of per-HART VS-level AIA IMSIC pages is 0. + Running Linux kernel --------------------
Signature · 1 line
2.25.1
PATCH v10 5/5 hw/riscv: virt: Increase maximum number of allowed CPUs
In reply to Anup PatelFrom: Anup Patel <[email protected]>
To facilitate software development of RISC-V systems with large number of HARTs, we increase the maximum number of allowed CPUs to 512 (2^9).
We also add a detailed source level comments about limit defines which impact the physical address space utilization.
--- hw/riscv/virt.c | 10 ++++++++++ include/hw/riscv/virt.h | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-)
hw/riscv/virt.c +10 -0
@@ -45,6 +45,16 @@#include "hw/pci-host/gpex.h" #include "hw/display/ramfb.h" +/* +* The virt machine physical address space used by some of the devices +* namely ACLINT, PLIC, APLIC, and IMSIC depend on number of Sockets, +* number of CPUs, and number of IMSIC guest files. +* +* Various limits defined by VIRT_SOCKETS_MAX_BITS, VIRT_CPUS_MAX_BITS, +* and VIRT_IRQCHIP_MAX_GUESTS_BITS are tuned for maximum utilization +* of virt machine physical address space. +*/ +#define VIRT_IMSIC_GROUP_MAX_SIZE (1U << IMSIC_MMIO_GROUP_MIN_SHIFT)#if VIRT_IMSIC_GROUP_MAX_SIZE < \IMSIC_GROUP_SIZE (VIRT_CPUS_MAX_BITS ,VIRT_IRQCHIP_MAX_GUESTS_BITS )
include/hw/riscv/virt.h +1 -1
@@ -24,7 +24,7 @@#include "hw/block/flash.h" #include "qom/object.h" -#define VIRT_CPUS_MAX_BITS 3 +#define VIRT_CPUS_MAX_BITS 9#define VIRT_CPUS_MAX (1 << VIRT_CPUS_MAX_BITS)#define VIRT_SOCKETS_MAX_BITS 2#define VIRT_SOCKETS_MAX (1 << VIRT_SOCKETS_MAX_BITS)
Signature · 1 line
2.25.1
Alistair Francis
AppliedQuoted 87 lines · Anup Patel
From: Anup Patel <[email protected]>
The advanced interrupt architecture (AIA) extends the per-HART local interrupt support. Along with this, it also adds IMSIC (MSI contrllor) and Advanced PLIC (wired interrupt controller).
The latest AIA draft specification can be found here:
https://github.com/riscv/riscv-aia/releases/download/0.2-draft.28/riscv-interrupts-028.pdfThis series adds RISC-V AIA support in QEMU which includes emulating all AIA local CSRs, APLIC, and IMSIC. Only AIA local interrupt filtering is not implemented because we don't have any local interrupt greater than 12.
To enable AIA in QEMU, use one of the following:
1) Only AIA local interrupt CSRs: Pass "x-aia=true" as CPU paramenter in the QEMU command-line
2) Only APLIC for virt machine: Pass "aia=aplic" as machine parameter in the QEMU command-line
3) Both APLIC and IMSIC for virt machine: Pass "aia=aplic-imsic" as machine parameter in the QEMU command-line
4) Both APLIC and IMSIC with 2 guest files for virt machine: Pass "aia=aplic-imsic,aia-guests=2" as machine parameter in the QEMU command-lineTo test series, we require Linux with AIA support which can be found in:
riscv_aia_v1branch at https://github.com/avpatel/linux.gitThis series can be found
riscv_aia_v10branch at:
https://github.com/avpatel/qemu.gitChanges since v9:
- Rebased on latest riscv-to-apply.next branch of Alistair's repo
- Removed first 18 PATCHs since these are already merged
- Fixed 32-bit system compile error in PATCH3Changes since v8:
- Useerror_setg()inriscv_imsic_realize()added by PATCH20Changes since v7:
- Rebased on latest riscv-to-apply.next branch of Alistair's repo
- Improved default priority assignment in PATCH9Changes since v6:
- Fixed priority comparison inriscv_cpu_pending_to_irq()of PATCH9
- Fixed typos in comments added by PATCH11
- Added "pend = true;" forCSR_MSETEIPNUMcase ofrmw_xsetclreinum()in PATCH15
- Handle ithreshold == 0 case inriscv_aplic_idc_topi()of PATCH18
- Allow setting pending bit for Level0 or Level1 interrupts inriscv_aplic_set_pending()of PATCH18
- Force DOMAINCFG[31:24] bits to0x80inriscv_aplic_read()of PATCH18
- For APLIC direct mode, set target.iprio to 1 when zero is writtern in PATCH18
- Handle eithreshold == 0 case inriscv_imsic_topei()of PATCH20Changes since v5:
- MovedVSTOPI_NUM_SRCSdefine to top of the file in PATCH13
- Fixed typo in PATCH16Changes since v4:
- ChangedIRQ_LOCAL_MAXto 16 in PATCH2
- Fixed typo in PATCH10
- ReplacedTARGET_LONG_BITSwithriscv_cpu_mxl_bits(env)in PATCH11
- ReplacedTARGET_LONG_BITSwithriscv_cpu_mxl_bits(env)in PATCH14
- ReplacedTARGET_LONG_BITSwithriscv_cpu_mxl_bits(env)in PATCH15
- ReplacedTARGET_LONG_BITSwith xlen passed via ireg callback in PATCH20
- Retrict maximum IMSIC guest files per-HART of virt machine to 7 in PATCH21.
- Added separate PATCH23 to increase maximum number of allowed CPUs for virt machineChanges since v3:
- Replaced "aplic,xyz" and "imsic,xyz" DT properties with "riscv,xyz" DT properties because "aplic" and "imsic" are not valid vendor names required by Linux DT schema checker.Changes since v2:
- Update PATCH4 to check and inject interrupt after V=1 when transitioning from V=0 to V=1Changes since v1:
- Revamped whole series and created more granular patches
- Added HGEIE and HGEIP CSR emulation for H-extension
- Added APLIC emulation
- Added IMSIC emulation
Quoted 6 lines
Anup Patel (5):
hw/riscv: virt: Add optional AIA APLIC support to virt machine hw/intc: Add RISC-V AIA IMSIC device emulation hw/riscv: virt: Add optional AIA IMSIC support to virt machine docs/system: riscv: Document AIA options for virt machine hw/riscv: virt: Increase maximum number of allowed CPUs
Thanks!
Applied to riscv-to-apply.next
Alistair
Quoted 17 lines
docs/system/riscv/virt.rst | 16 + hw/intc/Kconfig | 3 + hw/intc/meson.build | 1 + hw/intc/riscv_imsic.c | 448 ++++++++++++++++++++++ hw/riscv/Kconfig | 2 + hw/riscv/virt.c | 698 ++++++++++++++++++++++++++++------ include/hw/intc/riscv_imsic.h | 68 ++++ include/hw/riscv/virt.h | 41 +- 8 files changed, 1156 insertions(+), 121 deletions(-) create mode 100644 hw/intc/riscv_imsic.c create mode 100644 include/hw/intc/riscv_imsic.h--
2.25.1