hw/riscv: adding support for NeoRV32 RiscV MCU
Subsystems (2)
cover hw/riscv: adding support for NeoRV32 RiscV MCU
1) Initial support for Neorv32 soft-core MCU
2) IMEM, DMEM memory regions, bootloader ROM
3) Basic support for UART0, Basic support for SPI
4) Added SPI flash memory for loading firmware following bootloader
5) Based on Neorv32 RTL implementation repo
https://github.com/stnolting/neorv32 commit id 7d0ef6b2
Thanks in advance for review!
Michael (1):
hw/riscv: adding support for NeoRV32 RiscV MCU
.gitignore | 1 + configs/devices/riscv32-softmmu/default.mak | 1 + docs/system/riscv/neorv32.rst | 110 +++++ hw/char/Kconfig | 3 + hw/char/meson.build | 1 + hw/char/neorv32_uart.c | 311 ++++++++++++ hw/misc/Kconfig | 2 + hw/misc/meson.build | 1 + hw/misc/neorv32_sysinfo.c | 183 +++++++ hw/misc/neorv32_sysinfo.h | 79 +++ hw/misc/neorv32_sysinfo_rtl.h | 134 ++++++ hw/riscv/Kconfig | 8 + hw/riscv/meson.build | 1 + hw/riscv/neorv32.c | 219 +++++++++ hw/ssi/Kconfig | 4 + hw/ssi/meson.build | 1 + hw/ssi/neorv32_spi.c | 504 ++++++++++++++++++++ include/hw/char/neorv32_uart.h | 68 +++ include/hw/riscv/neorv32.h | 60 +++ include/hw/ssi/neorv32_spi.h | 70 +++ target/riscv/cpu-qom.h | 2 + target/riscv/cpu.c | 18 + target/riscv/cpu.h | 3 + target/riscv/cpu_cfg.h | 1 + target/riscv/cpu_cfg_fields.h.inc | 1 + target/riscv/cpu_vendorid.h | 2 + target/riscv/meson.build | 1 + target/riscv/neorv32_csr.c | 54 +++ 28 files changed, 1843 insertions(+) create mode 100644 docs/system/riscv/neorv32.rst create mode 100644 hw/char/neorv32_uart.c create mode 100644 hw/misc/neorv32_sysinfo.c create mode 100644 hw/misc/neorv32_sysinfo.h create mode 100644 hw/misc/neorv32_sysinfo_rtl.h create mode 100644 hw/riscv/neorv32.c create mode 100644 hw/ssi/neorv32_spi.c create mode 100644 include/hw/char/neorv32_uart.h create mode 100644 include/hw/riscv/neorv32.h create mode 100644 include/hw/ssi/neorv32_spi.h create mode 100644 target/riscv/neorv32_csr.c
Signature · 1 line
2.20.1
PATCH 1/1 hw/riscv: adding support for NeoRV32 RiscV MCU
From: Michael <[email protected]>
1) Initial support for Neorv32 soft-core MCU
2) IMEM, DMEM memory regions, bootloader ROM
3) Basic support for UART0 (no interrupts yet)
4) Basic support for SPI
5) Added SPI flash memory for loading firmware following bootloader
6) Based on Neorv32 RTL implementation repo
https://github.com/stnolting/neorv32
commit id 7d0ef6b2
--- .gitignore | 1 + configs/devices/riscv32-softmmu/default.mak | 1 + docs/system/riscv/neorv32.rst | 110 +++++ hw/char/Kconfig | 3 + hw/char/meson.build | 1 + hw/char/neorv32_uart.c | 311 ++++++++++++ hw/misc/Kconfig | 2 + hw/misc/meson.build | 1 + hw/misc/neorv32_sysinfo.c | 183 +++++++ hw/misc/neorv32_sysinfo.h | 79 +++ hw/misc/neorv32_sysinfo_rtl.h | 134 ++++++ hw/riscv/Kconfig | 8 + hw/riscv/meson.build | 1 + hw/riscv/neorv32.c | 219 +++++++++ hw/ssi/Kconfig | 4 + hw/ssi/meson.build | 1 + hw/ssi/neorv32_spi.c | 504 ++++++++++++++++++++ include/hw/char/neorv32_uart.h | 68 +++ include/hw/riscv/neorv32.h | 60 +++ include/hw/ssi/neorv32_spi.h | 70 +++ target/riscv/cpu-qom.h | 2 + target/riscv/cpu.c | 18 + target/riscv/cpu.h | 3 + target/riscv/cpu_cfg.h | 1 + target/riscv/cpu_cfg_fields.h.inc | 1 + target/riscv/cpu_vendorid.h | 2 + target/riscv/meson.build | 1 + target/riscv/neorv32_csr.c | 54 +++ 28 files changed, 1843 insertions(+) create mode 100644 docs/system/riscv/neorv32.rst create mode 100644 hw/char/neorv32_uart.c create mode 100644 hw/misc/neorv32_sysinfo.c create mode 100644 hw/misc/neorv32_sysinfo.h create mode 100644 hw/misc/neorv32_sysinfo_rtl.h create mode 100644 hw/riscv/neorv32.c create mode 100644 hw/ssi/neorv32_spi.c create mode 100644 include/hw/char/neorv32_uart.h create mode 100644 include/hw/riscv/neorv32.h create mode 100644 include/hw/ssi/neorv32_spi.h create mode 100644 target/riscv/neorv32_csr.c
.gitignore +1 -0
@@ -9,6 +9,7 @@ .clang-format .gdb_history cscope.* +phases.hold tags TAGS GPATH
configs/devices/riscv32-softmmu/default.mak +1 -0
@@ -10,3 +10,4 @@ # CONFIG_SIFIVE_U=n # CONFIG_RISCV_VIRT=n # CONFIG_OPENTITAN=n +# CONFIG_NEORV32=n
docs/system/riscv/neorv32.rst new file +110 -0
110 lines not on this page · raw message
hw/char/Kconfig +3 -0
@@ -95,3 +95,6 @@ config IP_OCTAL_232 bool default y depends on IPACK + +config NEORV32_UART + bool
hw/char/meson.build +1 -0
@@ -31,6 +31,7 @@ system_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_uart.c')) system_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_aux.c')) system_ss.add(when: 'CONFIG_RENESAS_SCI', if_true: files('renesas_sci.c')) system_ss.add(when: 'CONFIG_SIFIVE_UART', if_true: files('sifive_uart.c')) +system_ss.add(when: 'CONFIG_NEORV32_UART', if_true: files('neorv32_uart.c')) system_ss.add(when: 'CONFIG_SH_SCI', if_true: files('sh_serial.c')) system_ss.add(when: 'CONFIG_STM32F2XX_USART', if_true: files('stm32f2xx_usart.c')) system_ss.add(when: 'CONFIG_STM32L4X5_USART', if_true: files('stm32l4x5_usart.c'))
hw/char/neorv32_uart.c new file +311 -0
311 lines not on this page · raw message
hw/misc/Kconfig +2 -0
@@ -235,4 +235,6 @@ config IOSB config XLNX_VERSAL_TRNG bool +config NEORV32_SYSINFO_QEMU + bool source macio/Kconfig
hw/misc/meson.build +1 -0
@@ -34,6 +34,7 @@ system_ss.add(when: 'CONFIG_SIFIVE_E_PRCI', if_true: files('sifive_e_prci.c')) system_ss.add(when: 'CONFIG_SIFIVE_E_AON', if_true: files('sifive_e_aon.c')) system_ss.add(when: 'CONFIG_SIFIVE_U_OTP', if_true: files('sifive_u_otp.c')) system_ss.add(when: 'CONFIG_SIFIVE_U_PRCI', if_true: files('sifive_u_prci.c')) +system_ss.add(when: 'CONFIG_NEORV32_SYSINFO_QEMU', if_true: files('neorv32_sysinfo.c')) subdir('macio')
hw/misc/neorv32_sysinfo.c new file +183 -0
183 lines not on this page · raw message
hw/misc/neorv32_sysinfo.h new file +79 -0
79 lines not on this page · raw message
hw/misc/neorv32_sysinfo_rtl.h new file +134 -0
134 lines not on this page · raw message
hw/riscv/Kconfig +8 -0
@@ -128,3 +128,11 @@ config XIANGSHAN_KUNMINGHU select RISCV_APLIC select RISCV_IMSIC select SERIAL_MM + +config NEORV32 + bool + default y + depends on RISCV32 + select NEORV32_UART + select NEORV32_SPI + select NEORV32_SYSINFO_QEMU
hw/riscv/meson.build +1 -0
@@ -14,5 +14,6 @@ riscv_ss.add(when: 'CONFIG_RISCV_IOMMU', if_true: files( 'riscv-iommu.c', 'riscv-iommu-pci.c', 'riscv-iommu-sys.c', 'riscv-iommu-hpm.c')) riscv_ss.add(when: 'CONFIG_MICROBLAZE_V', if_true: files('microblaze-v-generic.c')) riscv_ss.add(when: 'CONFIG_XIANGSHAN_KUNMINGHU', if_true: files('xiangshan_kmh.c')) +riscv_ss.add(when: 'CONFIG_NEORV32', if_true: files('neorv32.c')) hw_arch += {'riscv': riscv_ss}
hw/riscv/neorv32.c new file +219 -0
219 lines not on this page · raw message
hw/ssi/Kconfig +4 -0
@@ -32,3 +32,7 @@ config PNV_SPI config ALLWINNER_A10_SPI bool select SSI + +config NEORV32_SPI + bool + select SSI
hw/ssi/meson.build +1 -0
@@ -13,3 +13,4 @@ system_ss.add(when: 'CONFIG_IMX', if_true: files('imx_spi.c')) system_ss.add(when: 'CONFIG_IBEX', if_true: files('ibex_spi_host.c')) system_ss.add(when: 'CONFIG_BCM2835_SPI', if_true: files('bcm2835_spi.c')) system_ss.add(when: 'CONFIG_PNV_SPI', if_true: files('pnv_spi.c')) +system_ss.add(when: 'CONFIG_NEORV32_SPI', if_true: files('neorv32_spi.c'))
hw/ssi/neorv32_spi.c new file +504 -0
504 lines not on this page · raw message
include/hw/char/neorv32_uart.h new file +68 -0
68 lines not on this page · raw message
include/hw/riscv/neorv32.h new file +60 -0
60 lines not on this page · raw message
include/hw/ssi/neorv32_spi.h new file +70 -0
70 lines not on this page · raw message
target/riscv/cpu-qom.h +2 -0
@@ -57,6 +57,8 @@#define TYPE_RISCV_CPU_XIANGSHAN_NANHU RISCV_CPU_TYPE_NAME("xiangshan-nanhu")#define TYPE_RISCV_CPU_XIANGSHAN_KMH RISCV_CPU_TYPE_NAME("xiangshan-kunminghu")#define TYPE_RISCV_CPU_HOST RISCV_CPU_TYPE_NAME("host") +#define TYPE_RISCV_CPU_NEORV32 RISCV_CPU_TYPE_NAME("neorv32") +OBJECT_DECLARE_CPU_TYPE (RISCVCPU , RISCVCPUClass,RISCV_CPU )
target/riscv/cpu.c +18 -0
@@ -245,6 +245,7 @@ const RISCVIsaExtData isa_edata_arr[] = {ISA_EXT_DATA_ENTRY (xtheadmempair,PRIV_VERSION_1_11_0 , ext_xtheadmempair),ISA_EXT_DATA_ENTRY (xtheadsync,PRIV_VERSION_1_11_0 , ext_xtheadsync),ISA_EXT_DATA_ENTRY (xventanacondops,PRIV_VERSION_1_12_0 , ext_XVentanaCondOps), + ISA_EXT_DATA_ENTRY(xneorv32xisa,PRIV_VERSION_1_10_0,ext_xneorv32xisa), { }, };
@@ -1365,6 +1366,7 @@ const RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[] = {MULTI_EXT_CFG_BOOL ("xtheadmempair" , ext_xtheadmempair, false),MULTI_EXT_CFG_BOOL ("xtheadsync" , ext_xtheadsync, false),MULTI_EXT_CFG_BOOL ("xventanacondops" , ext_XVentanaCondOps, false), + MULTI_EXT_CFG_BOOL("xneorv32xisa", ext_xneorv32xisa, false), { }, };
@@ -2993,6 +2995,7 @@ static const TypeInfo riscv_cpu_type_infos[] = { .cfg.pmp_regions = 8 ), +#if defined(TARGET_RISCV32 ) || \ (defined(TARGET_RISCV64 ) && !defined(CONFIG_USER_ONLY )) DEFINE_RISCV_CPU(TYPE_RISCV_CPU_BASE32, TYPE_RISCV_DYNAMIC_CPU,
@@ -3036,6 +3039,21 @@ static const TypeInfo riscv_cpu_type_infos[] = { .misa_mxl_max = MXL_RV32, .misa_ext =RVE ), +DEFINE_RISCV_CPU (TYPE_RISCV_CPU_NEORV32 ,TYPE_RISCV_VENDOR_CPU , + .misa_mxl_max = MXL_RV32, + .misa_ext = RVI | RVM | RVA | RVC | RVU, + .priv_spec = PRIV_VERSION_1_10_0, + + .cfg.max_satp_mode = VM_1_10_MBARE, + .cfg.ext_zifencei = true, + .cfg.ext_zicsr = true, + .cfg.pmp = true, + .cfg.pmp_regions = 16, + .cfg.mvendorid = NEORV32_VENDOR_ID, +#ifndef CONFIG_USER_ONLY + .custom_csrs = neorv32_csr_list +#endif + ), #endif #if (defined(TARGET_RISCV64) && !defined(CONFIG_USER_ONLY))
target/riscv/cpu.h +3 -0
@@ -984,5 +984,8 @@ const char *satp_mode_str(uint8_t satp_mode, bool is_32_bit);/* In th_csr.c */ extern const RISCVCSR th_csr_list[]; +/* Implemented in neorv32_csr.c */ +extern const RISCVCSR neorv32_csr_list[]; +const char *priv_spec_to_str (int priv_version);#endif /* RISCV_CPU_H */
target/riscv/cpu_cfg.h +1 -0
@@ -64,5 +64,6 @@ MATERIALISE_EXT_PREDICATE(xtheadmemidx) MATERIALISE_EXT_PREDICATE(xtheadmempair) MATERIALISE_EXT_PREDICATE(xtheadsync) MATERIALISE_EXT_PREDICATE(XVentanaCondOps) +MATERIALISE_EXT_PREDICATE(xneorv32xisa)#endif
target/riscv/cpu_cfg_fields.h.inc +1 -0
@@ -147,6 +147,7 @@ BOOL_FIELD(ext_xtheadmemidx) BOOL_FIELD(ext_xtheadmempair) BOOL_FIELD(ext_xtheadsync) BOOL_FIELD(ext_XVentanaCondOps) +BOOL_FIELD(ext_xneorv32xisa) BOOL_FIELD(mmu) BOOL_FIELD(pmp)
target/riscv/cpu_vendorid.h +2 -0
@@ -7,4 +7,6 @@#define VEYRON_V1_MIMPID 0x111#define VEYRON_V1_MVENDORID 0x61f +#define NEORV32_VENDOR_ID 0xF0000001 +#endif /* TARGET_RISCV_CPU_VENDORID_H */
target/riscv/meson.build +1 -0
@@ -40,6 +40,7 @@ riscv_system_ss.add(files( 'th_csr.c', 'time_helper.c', 'riscv-qmp-cmds.c', + 'neorv32_csr.c', )) subdir('tcg')
target/riscv/neorv32_csr.c new file +54 -0
54 lines not on this page · raw message
Signature · 1 line
2.20.1
Hi Michael,
Quoted 34 lines · Michael Levit
From: Michael <[email protected]>
1) Initial support for Neorv32 soft-core MCU
2) IMEM, DMEM memory regions, bootloader ROM
3) Basic support for UART0 (no interrupts yet)
4) Basic support for SPI
5) Added SPI flash memory for loading firmware following bootloader
6) Based on Neorv32 RTL implementation repo
https://github.com/stnolting/neorv32
commit id7d0ef6b2Signed-off-by Michael Levit <[email protected]>--- .gitignore | 1 + configs/devices/riscv32-softmmu/default.mak | 1 + docs/system/riscv/neorv32.rst | 110 +++++ hw/char/Kconfig | 3 + hw/char/meson.build | 1 + hw/char/neorv32_uart.c | 311 ++++++++++++ hw/misc/Kconfig | 2 + hw/misc/meson.build | 1 + hw/misc/neorv32_sysinfo.c | 183 +++++++ hw/misc/neorv32_sysinfo.h | 79 +++ hw/misc/neorv32_sysinfo_rtl.h | 134 ++++++ hw/riscv/Kconfig | 8 + hw/riscv/meson.build | 1 + hw/riscv/neorv32.c | 219 +++++++++ hw/ssi/Kconfig | 4 + hw/ssi/meson.build | 1 + hw/ssi/neorv32_spi.c | 504 ++++++++++++++++++++ include/hw/char/neorv32_uart.h | 68 +++ include/hw/riscv/neorv32.h | 60 +++ include/hw/ssi/neorv32_spi.h | 70 +++ target/riscv/cpu-qom.h | 2 +
Quoted 8 lines
target/riscv/cpu.c | 18 + target/riscv/cpu.h | 3 + target/riscv/cpu_cfg.h | 1 + target/riscv/cpu_cfg_fields.h.inc | 1 + target/riscv/cpu_vendorid.h | 2 + target/riscv/meson.build | 1 + target/riscv/neorv32_csr.c | 54 +++ 28 files changed, 1843 insertions(+)
Thanks for your contribution! However I'm afraid this patch is too big to be reviewed without missing something. I'd suggest splitting like the 6 bullets you enumerated.
.gitignore line 12
Quoted 9 lines
.gitignore +1
-0@@ -9,6 +9,7 @@ .clang-format .gdb_history cscope.* +phases.hold
Not sure from where this file comes; maybe a shell typo? Regards,
Phil.
Hi Phil,
Thank you for review and suggestions, I will split the patch and re-send it. Yes, change in .gitignore is a mistake.
Best regards,
Michael
Quoted 66 lines · Philippe Mathieu-Daudé
Hi Michael,
Quoted 34 lines · Michael Levit
From: Michael <[email protected]>
1) Initial support for Neorv32 soft-core MCU
2) IMEM, DMEM memory regions, bootloader ROM
3) Basic support for UART0 (no interrupts yet)
4) Basic support for SPI
5) Added SPI flash memory for loading firmware following bootloader
6) Based on Neorv32 RTL implementation repo
https://github.com/stnolting/neorv32
commit id7d0ef6b2Signed-off-by Michael Levit <[email protected]>--- .gitignore | 1 + configs/devices/riscv32-softmmu/default.mak | 1 + docs/system/riscv/neorv32.rst | 110 +++++ hw/char/Kconfig | 3 + hw/char/meson.build | 1 + hw/char/neorv32_uart.c | 311 ++++++++++++ hw/misc/Kconfig | 2 + hw/misc/meson.build | 1 + hw/misc/neorv32_sysinfo.c | 183 +++++++ hw/misc/neorv32_sysinfo.h | 79 +++ hw/misc/neorv32_sysinfo_rtl.h | 134 ++++++ hw/riscv/Kconfig | 8 + hw/riscv/meson.build | 1 + hw/riscv/neorv32.c | 219 +++++++++ hw/ssi/Kconfig | 4 + hw/ssi/meson.build | 1 + hw/ssi/neorv32_spi.c | 504 ++++++++++++++++++++ include/hw/char/neorv32_uart.h | 68 +++ include/hw/riscv/neorv32.h | 60 +++ include/hw/ssi/neorv32_spi.h | 70 +++ target/riscv/cpu-qom.h | 2 +Quoted 8 lines
target/riscv/cpu.c | 18 + target/riscv/cpu.h | 3 + target/riscv/cpu_cfg.h | 1 + target/riscv/cpu_cfg_fields.h.inc | 1 + target/riscv/cpu_vendorid.h | 2 + target/riscv/meson.build | 1 + target/riscv/neorv32_csr.c | 54 +++ 28 files changed, 1843 insertions(+)Thanks for your contribution! However I'm afraid this patch is too big to be reviewed without missing something. I'd suggest splitting like the 6 bullets you enumerated.
.gitignore line 12
Quoted 9 lines
.gitignore +1
-0@@ -9,6 +9,7 @@ .clang-format .gdb_history cscope.* +phases.holdNot sure from where this file comes; maybe a shell typo? Regards,
Phil.