Add support for K230 board
Subsystems (2)
v4 cover Add support for K230 board
Hi Alistair,
This patch series adds support for U-Boot + OpenSBI + standard Linux kernel on K230 board. Thanks to Peng Jiang, Mig Yang, Renzao Ren, Yao Zi for their help.
This v4 series has been rebased on the latest master branch and is ready for review.
Test command:
``` $QEMU -M k230 -bios [OpenSBI binary] -m 2G -dtb k230_canmv.dtb -kernel [img] ```
PATCH v4 changelog:
- Rebased on the latest master branch
- No functional changes from v3
PATCH v3 changelog:
- Patch 1: Align T-Head C908 CPU's RISC-V extension with XUANTIE-QEMU
- Patch 2: Adjust PLIC and CLINT addresses to match K230 datasheet
https://lore.kernel.org/qemu-devel/[email protected]/
PATCH v2 changelog:
- Patch 1: Add Svpbmt extension support for the T-Head C908 CPU
- Patch 2: Move the k230.rst definition from MAINTAINERS to Patch 5
- Patch 5: Apply Daniel's bugfix to build the k230 documentation successfully
https://lore.kernel.org/qemu-devel/[email protected]/
PATCH v1 changelog:
- Patch1: Add T-Head C908 and C908v CPU support
- Patch2: Add K230 board initial support(big core is not supported yet)
- Patch3: Add Programmable Watchdog Timer (WDT) peripheral support
- Patch4: Add QEMU test for K230 watchdog
- Patch5: Add documentation for K230 machine
https://lore.kernel.org/qemu-devel/[email protected]/T/#t
Thanks,
Chao
Chao Liu (5):
target/riscv: add thead-c908 cpu support hw/riscv: add k230 board initial support hw/watchdog: add k230 watchdog initial support tests/qtest: add test for K230 watchdog docs/system/riscv: add documentation for k230 machine
MAINTAINERS | 12 +- docs/system/riscv/k230.rst | 48 ++++ docs/system/target-riscv.rst | 1 + hw/riscv/Kconfig | 11 + hw/riscv/k230.c | 501 +++++++++++++++++++++++++++++++++ hw/riscv/meson.build | 2 +- hw/watchdog/Kconfig | 4 + hw/watchdog/k230_wdt.c | 307 ++++++++++++++++++++ hw/watchdog/meson.build | 1 + hw/watchdog/trace-events | 9 + include/hw/riscv/k230.h | 153 ++++++++++ include/hw/watchdog/k230_wdt.h | 130 +++++++++ target/riscv/cpu-qom.h | 2 + target/riscv/cpu.c | 51 ++++ target/riscv/th_csr.c | 380 ++++++++++++++++++++++++- tests/qtest/k230-wdt-test.c | 199 +++++++++++++ tests/qtest/meson.build | 3 +- 17 files changed, 1810 insertions(+), 4 deletions(-) create mode 100644 docs/system/riscv/k230.rst create mode 100644 hw/riscv/k230.c create mode 100644 hw/watchdog/k230_wdt.c create mode 100644 include/hw/riscv/k230.h create mode 100644 include/hw/watchdog/k230_wdt.h create mode 100644 tests/qtest/k230-wdt-test.c
Signature · 1 line
2.52.0
PATCH v4 2/5 hw/riscv: add k230 board initial support
From: Chao Liu <[email protected]>
K230 Board Compatible with kendryte K230 SDK.
Preliminarily supports the C908 small core, which can run the U-Boot and Linux kernel compiled by the K230 SDK.
--- MAINTAINERS | 8 +- hw/riscv/Kconfig | 10 + hw/riscv/k230.c | 483 ++++++++++++++++++++++++++++++++++++++++ hw/riscv/meson.build | 2 +- include/hw/riscv/k230.h | 149 +++++++++++++ 5 files changed, 650 insertions(+), 2 deletions(-) create mode 100644 hw/riscv/k230.c create mode 100644 include/hw/riscv/k230.h
MAINTAINERS +7 -1
@@ -1758,6 +1758,12 @@ F: docs/system/riscv/xiangshan-kunminghu.rst F: hw/riscv/xiangshan_kmh.c F: include/hw/riscv/xiangshan_kmh.h +K230 Machines +M: Chao Liu <[email protected]> +S: Maintained +F: hw/riscv/k230.c +F: include/hw/riscv/k230.h + RX Machines ----------- rx-gdbsim
@@ -3576,7 +3582,7 @@ M: Alexander Bulekov <[email protected]> R: Paolo Bonzini <[email protected]> R: Stefan Hajnoczi <[email protected]> R: Fabiano Rosas <[email protected]> -R: Darren Kenny <[email protected]> +R: Darren Kenny <[email protected]> R: Qiuhao Li <[email protected]> S: Maintained F: tests/qtest/fuzz/
hw/riscv/Kconfig +10 -0
@@ -134,3 +134,13 @@ config MIPS_BOSTON_AIA default y select PCI_EXPRESS select PCI_EXPRESS_XILINX + +config K230 + bool + default y + depends on RISCV64 + select RISCV_ACLINT + select RISCV_APLIC + select RISCV_IMSIC + select SERIAL_MM + select UNIMP
hw/riscv/k230.c new file +483 -0
483 lines not on this page · raw message
hw/riscv/meson.build +1 -1
@@ -14,8 +14,8 @@ 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_RISCV_MIPS_CPS', if_true: files('cps.c')) riscv_ss.add(when: 'CONFIG_MIPS_BOSTON_AIA', if_true: files('boston-aia.c')) +riscv_ss.add(when: 'CONFIG_K230', if_true: files('k230.c')) hw_arch += {'riscv': riscv_ss}
include/hw/riscv/k230.h new file +149 -0
149 lines not on this page · raw message
Signature · 1 line
2.52.0
PATCH v4 5/5 docs/system/riscv: add documentation for k230 machine
In reply to Chao LiuFrom: Chao Liu <[email protected]>
Add documentation for k230 virt reference platform.
--- MAINTAINERS | 1 + docs/system/riscv/k230.rst | 48 ++++++++++++++++++++++++++++++++++++ docs/system/target-riscv.rst | 1 + 3 files changed, 50 insertions(+) create mode 100644 docs/system/riscv/k230.rst
MAINTAINERS +1 -0
@@ -1761,6 +1761,7 @@ F: include/hw/riscv/xiangshan_kmh.h K230 Machines M: Chao Liu <[email protected]> S: Maintained +F: docs/system/riscv/k230.rst F: hw/riscv/k230.c F: hw/watchdog/k230_wdt.c F: include/hw/riscv/k230.h
docs/system/riscv/k230.rst new file +48 -0
48 lines not on this page · raw message
docs/system/target-riscv.rst +1 -0
@@ -66,6 +66,7 @@ undocumented; you can get a complete list by running .. toctree:: :maxdepth: 1 + riscv/k230 riscv/microblaze-v-generic riscv/microchip-icicle-kit riscv/mips
Signature · 1 line
2.52.0
PATCH v4 4/5 tests/qtest: add test for K230 watchdog
In reply to Chao LiuFrom: Chao Liu <[email protected]>
Testing the Basic Functions of K230 WDT:
1. Reset Function
2. Timeout Check
3. Interrupt Function
--- MAINTAINERS | 1 + tests/qtest/k230-wdt-test.c | 199 ++++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 3 +- 3 files changed, 202 insertions(+), 1 deletion(-) create mode 100644 tests/qtest/k230-wdt-test.c
MAINTAINERS +1 -0
@@ -1765,6 +1765,7 @@ F: hw/riscv/k230.c F: hw/watchdog/k230_wdt.c F: include/hw/riscv/k230.h F: include/hw/watchdog/k230_wdt.h +F: tests/qtest/k230-wdt-test.c RX Machines -----------
tests/qtest/k230-wdt-test.c new file +199 -0
199 lines not on this page · raw message
tests/qtest/meson.build +2 -1
@@ -283,7 +283,8 @@ qtests_riscv32 = \ (config_all_devices.has_key('CONFIG_SIFIVE_E_AON') ? ['sifive-e-aon-watchdog-test'] : []) qtests_riscv64 = ['riscv-csr-test'] + \ - (unpack_edk2_blobs ? ['bios-tables-test'] : []) + (unpack_edk2_blobs ? ['bios-tables-test'] : []) + \ + (config_all_devices.has_key('CONFIG_K230') ? ['k230-wdt-test'] : []) qos_test_ss = ss.source_set() qos_test_ss.add(
Signature · 1 line
2.52.0
PATCH v4 1/5 target/riscv: add thead-c908 cpu support
In reply to Chao LiuFrom: Chao Liu <[email protected]>
The C908 processor is based on the RV64GCB[V] instruction set, compatible to RVA22 Profile and implements the XIE (XuanTie Instruction Extension) technology.
--- target/riscv/cpu-qom.h | 2 + target/riscv/cpu.c | 51 ++++++ target/riscv/th_csr.c | 380 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 432 insertions(+), 1 deletion(-)
target/riscv/cpu-qom.h +2 -0
@@ -52,6 +52,8 @@#define TYPE_RISCV_CPU_SIFIVE_U34 RISCV_CPU_TYPE_NAME("sifive-u34")#define TYPE_RISCV_CPU_SIFIVE_U54 RISCV_CPU_TYPE_NAME("sifive-u54")#define TYPE_RISCV_CPU_THEAD_C906 RISCV_CPU_TYPE_NAME("thead-c906") +#define TYPE_RISCV_CPU_THEAD_C908 RISCV_CPU_TYPE_NAME("thead-c908") +#define TYPE_RISCV_CPU_THEAD_C908V RISCV_CPU_TYPE_NAME("thead-c908v")#define TYPE_RISCV_CPU_VEYRON_V1 RISCV_CPU_TYPE_NAME("veyron-v1")#define TYPE_RISCV_CPU_TT_ASCALON RISCV_CPU_TYPE_NAME("tt-ascalon")#define TYPE_RISCV_CPU_XIANGSHAN_NANHU RISCV_CPU_TYPE_NAME("xiangshan-nanhu")
target/riscv/cpu.c +51 -0
57 lines not on this page · raw message
target/riscv/th_csr.c +379 -1
419 lines not on this page · raw message
Signature · 1 line
2.52.0
PATCH v4 3/5 hw/watchdog: add k230 watchdog initial support
In reply to Chao LiuFrom: Chao Liu <[email protected]>
Add programmable Watchdog Timer (WDT) peripheral for K230 machine.
--- MAINTAINERS | 2 + hw/riscv/Kconfig | 1 + hw/riscv/k230.c | 18 ++ hw/watchdog/Kconfig | 4 + hw/watchdog/k230_wdt.c | 307 +++++++++++++++++++++++++++++++++ hw/watchdog/meson.build | 1 + hw/watchdog/trace-events | 9 + include/hw/riscv/k230.h | 4 + include/hw/watchdog/k230_wdt.h | 130 ++++++++++++++ 9 files changed, 476 insertions(+) create mode 100644 hw/watchdog/k230_wdt.c create mode 100644 include/hw/watchdog/k230_wdt.h
MAINTAINERS +2 -0
@@ -1762,7 +1762,9 @@ K230 Machines M: Chao Liu <[email protected]> S: Maintained F: hw/riscv/k230.c +F: hw/watchdog/k230_wdt.c F: include/hw/riscv/k230.h +F: include/hw/watchdog/k230_wdt.h RX Machines -----------
hw/riscv/Kconfig +1 -0
@@ -144,3 +144,4 @@ config K230 select RISCV_IMSIC select SERIAL_MM select UNIMP + select K230_WDT
hw/riscv/k230.c +18 -0
@@ -112,6 +112,9 @@ static void k230_soc_init(Object *obj)RISCVHartArrayState *cpu0 = &s->c908_cpu;object_initialize_child (obj,"c908-cpu" , cpu0,TYPE_RISCV_HART_ARRAY ); +object_initialize_child (obj,"k230-wdt0" , &s->wdt[0 ],TYPE_K230_WDT ); +object_initialize_child (obj,"k230-wdt1" , &s->wdt[1 ],TYPE_K230_WDT ); +qdev_prop_set_uint32 (DEVICE (cpu0),"hartid-base" ,0 );qdev_prop_set_string (DEVICE (cpu0),"cpu-type" ,TYPE_RISCV_CPU_THEAD_C908 ); qdev_prop_set_uint64(DEVICE(cpu0), "resetvec",
@@ -189,6 +192,21 @@ static void k230_soc_realize(DeviceState *dev, Error **errp)qdev_get_gpio_in (DEVICE (s->c908_plic),K230_UART4_IRQ ), 399193, serial_hd(4), DEVICE_LITTLE_ENDIAN); +/* Watchdog */ +for (int i =0 ; i <2 ; i++) { +if (!sysbus_realize (SYS_BUS_DEVICE (&s->wdt[i]), errp)) { +return ; + } + } + +sysbus_mmio_map (SYS_BUS_DEVICE (&s->wdt[0 ]),0 , memmap[K230_DEV_WDT0 ].base); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->wdt[0 ]),0 , +qdev_get_gpio_in (DEVICE (s->c908_plic),K230_WDT0_IRQ )); + +sysbus_mmio_map (SYS_BUS_DEVICE (&s->wdt[1 ]),0 , memmap[K230_DEV_WDT1 ].base); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->wdt[1 ]),0 , +qdev_get_gpio_in (DEVICE (s->c908_plic),K230_WDT1_IRQ )); +/* unimplemented devices */ create_unimplemented_device("kpu.l2-cache", memmap[K230_DEV_KPU_L2_CACHE].base,
hw/watchdog/Kconfig +4 -0
@@ -18,6 +18,10 @@ config WDT_DIAG288 config WDT_IMX2 bool +config K230_WDT + bool + select PTIMER + config WDT_SBSA bool
hw/watchdog/k230_wdt.c new file +307 -0
307 lines not on this page · raw message
hw/watchdog/meson.build +1 -0
@@ -6,5 +6,6 @@ system_ss.add(when: 'CONFIG_WDT_IB700', if_true: files('wdt_ib700.c')) system_ss.add(when: 'CONFIG_WDT_DIAG288', if_true: files('wdt_diag288.c')) system_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('wdt_aspeed.c')) system_ss.add(when: 'CONFIG_WDT_IMX2', if_true: files('wdt_imx2.c')) +system_ss.add(when: 'CONFIG_K230_WDT', if_true: files('k230_wdt.c')) system_ss.add(when: 'CONFIG_WDT_SBSA', if_true: files('sbsa_gwdt.c')) specific_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr_watchdog.c'))
hw/watchdog/trace-events +9 -0
@@ -33,3 +33,12 @@ spapr_watchdog_expired(uint64_t num, unsigned action) "num=%" PRIu64 " action=%u # watchdog.c watchdog_perform_action(unsigned int action) "action=%u" watchdog_set_action(unsigned int action) "action=%u" + +# k230_wdt.c +k230_wdt_read(uint64_t addr, uint32_t data) "K230 WDT read: [0x%" PRIx64 "] -> 0x%" PRIx32 +k230_wdt_write(uint64_t addr, uint64_t data) "K230 WDT write: [0x%" PRIx64 "] <- 0x%" PRIx64 +k230_wdt_timeout(void) "K230 WDT timeout" +k230_wdt_interrupt(void) "K230 WDT interrupt" +k230_wdt_reset(void) "K230 WDT system reset" +k230_wdt_restart(void) "K230 WDT restart" +k230_wdt_reset_device(void) "K230 WDT device reset"
include/hw/riscv/k230.h +4 -0
@@ -27,6 +27,7 @@#include "hw/boards.h" #include "hw/riscv/riscv_hart.h" +#include "hw/watchdog/k230_wdt.h" #define C908_CPU_HARTID (0)
@@ -41,6 +42,7 @@ typedef struct K230SoCState {/*< public >*/ RISCVHartArrayState c908_cpu;/* Small core */ +K230WdtState wdt[2 ];MemoryRegion sram;MemoryRegion bootrom;
@@ -131,6 +133,8 @@ enum {K230_UART2_IRQ =18 ,K230_UART3_IRQ =19 ,K230_UART4_IRQ =20 , +K230_WDT0_IRQ =32 , + K230_WDT1_IRQ = 33, };/*
include/hw/watchdog/k230_wdt.h new file +130 -0
130 lines not on this page · raw message
Signature · 1 line
2.52.0
Re: [PATCH v4 2/5] hw/riscv: add k230 board initial support
In reply to Peng JiangHi Peng:
Quoted 28 lines · Peng Jiang
Hi Chao,
I found a small issue in the
reset_romimplementation inhw/riscv/k230.c.Quoted 11 lines
hw/riscv/k230.c new file +11
-0+static void k230_machine_done (Notifier *notifier,void *data) +{ + ... +/* Mask ROM reset vector */ +uint32_t reset_vec[] = { +/* 0x91200000: auipc t0, 0x0 */ 0x00000297 , +/* 0x91200004: addi t0, t0, 36 # <trap> */ 0x02428293 , +/* 0x91200008: csrw mtvec, t0 */ 0x30529073 , + ... +/* trap: */ +/* 0x91200030: j 0x91200030 # <trap> */ 0x0000006f ,hw/riscv/k230.c line 425
Quoted 10 lines
hw/riscv/k230.c new file +9
-0+ }; + +/* copy in the reset vector in little_endian byte order */ +for (int i =0 ; i <sizeof (reset_vec) >>2 ; i++) { + reset_vec[i] =cpu_to_le32 (reset_vec[i]); + } +rom_add_blob_fixed_as ("mrom.reset" , reset_vec,sizeof (reset_vec), + memmap[K230_DEV_BOOTROM ].base, &address_space_memory); +}It seems the offset for the trap handler is incorrect.
Quoted 8 lines
The instruction at
0x91200004is addi t0, t0, 36. After the auipc at0x91200000, this sets the value of t0 to0x91200000+ 36 (0x91200024), which is then written to the mtvec register.However, the actual trap: label is located at offset
0x30(0x91200030).The immediate value in the addi instruction should probably be 48 (
0x30) instead of 36 (0x24) to point to the correct trap handler address.Best regards,
Panda Jiang
Thank you for reporting this bug. I will fix it in v5. :)
Thanks,
Chao
Re: [PATCH v4 2/5] hw/riscv: add k230 board initial support
In reply to Chao LiuHi Chao,
I found a small issue in the reset_rom implementation in hw/riscv/k230.c.
Quoted 11 lines
hw/riscv/k230.c new file +11
-0+static void k230_machine_done (Notifier *notifier,void *data) +{ + ... +/* Mask ROM reset vector */ +uint32_t reset_vec[] = { +/* 0x91200000: auipc t0, 0x0 */ 0x00000297 , +/* 0x91200004: addi t0, t0, 36 # <trap> */ 0x02428293 , +/* 0x91200008: csrw mtvec, t0 */ 0x30529073 , + ... +/* trap: */ +/* 0x91200030: j 0x91200030 # <trap> */ 0x0000006f ,
hw/riscv/k230.c line 425
Quoted 10 lines
hw/riscv/k230.c new file +9
-0+ }; + +/* copy in the reset vector in little_endian byte order */ +for (int i =0 ; i <sizeof (reset_vec) >>2 ; i++) { + reset_vec[i] =cpu_to_le32 (reset_vec[i]); + } +rom_add_blob_fixed_as ("mrom.reset" , reset_vec,sizeof (reset_vec), + memmap[K230_DEV_BOOTROM ].base, &address_space_memory); +}
It seems the offset for the trap handler is incorrect.
The instruction at 0x91200004 is addi t0, t0, 36. After the auipc at 0x91200000, this sets the value of t0 to 0x91200000 + 36 (0x91200024), which is then written to the mtvec register.
However, the actual trap: label is located at offset 0x30 (0x91200030).
The immediate value in the addi instruction should probably be 48 (0x30) instead of 36 (0x24) to point to the correct trap handler address.
Best regards,
Panda Jiang