hw/timer: add k230 dwapb timer
Subsystems (2)
PATCH 1/1 hw/timer: add k230 dwapb timer
Add DesignWare APB timer peripheral for K230 machine. The timer uses the Clock framework for frequency input, preparing for future CMU integration.
--- MAINTAINERS | 3 + hw/riscv/Kconfig | 1 + hw/riscv/k230.c | 23 +- hw/timer/Kconfig | 4 + hw/timer/k230_dwapb_timer.c | 332 ++++++++++++++++++++++++++++ hw/timer/meson.build | 1 + hw/timer/trace-events | 9 + include/hw/riscv/k230.h | 8 + include/hw/timer/k230_dwapb_timer.h | 68 ++++++ tests/qtest/k230-dwapb-timer-test.c | 224 +++++++++++++++++++ tests/qtest/meson.build | 2 +- 11 files changed, 671 insertions(+), 4 deletions(-) create mode 100644 hw/timer/k230_dwapb_timer.c create mode 100644 include/hw/timer/k230_dwapb_timer.h create mode 100644 tests/qtest/k230-dwapb-timer-test.c
MAINTAINERS +3 -0
@@ -1826,9 +1826,12 @@ S: Maintained F: docs/system/riscv/k230.rst F: hw/riscv/k230.c F: hw/watchdog/k230_wdt.c +F: hw/timer/k230_dwapb_timer.c F: include/hw/riscv/k230.h F: include/hw/watchdog/k230_wdt.h +F: include/hw/timer/k230_dwapb_timer.h F: tests/qtest/k230-wdt-test.c +F: tests/qtest/k230-dwapb-timer-test.c RX Machines -----------
hw/riscv/Kconfig +1 -0
@@ -162,3 +162,4 @@ config K230 select SERIAL_MM select UNIMP select K230_WDT + select K230_TIMER
hw/riscv/k230.c +20 -3
@@ -24,6 +24,8 @@#include "target/riscv/cpu.h" #include "hw/core/loader.h" #include "hw/core/sysbus.h" +#include "hw/core/clock.h" +#include "hw/core/qdev-clock.h" #include "hw/riscv/k230.h" #include "hw/riscv/boot.h" #include "hw/riscv/machines-qom.h"
@@ -110,6 +112,12 @@ static void k230_soc_init(Object *obj)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 ); +object_initialize_child (obj,"k230-dwapb-timer" , &s->timer, +TYPE_K230_TIMER ); + +Clock *timer_clk =clock_new (OBJECT (s),"timer-clk" ); +clock_set_hz (timer_clk,K230_APBTMR_DEFAULT_FREQ ); +qdev_connect_clock_in (DEVICE (&s->timer),"pclk" , timer_clk);qdev_prop_set_uint32 (DEVICE (cpu0),"hartid-base" ,0 );qdev_prop_set_string (DEVICE (cpu0),"cpu-type" ,TYPE_RISCV_CPU_THEAD_C908 );
@@ -191,6 +199,18 @@ static void k230_soc_realize(DeviceState *dev, Error **errp)k230_create_uart (sys_mem,DEVICE (s->c908_plic), i); } +/* Timer */ +if (!sysbus_realize (SYS_BUS_DEVICE (&s->timer), errp)) { +return ; + } +sysbus_mmio_map (SYS_BUS_DEVICE (&s->timer),0 , memmap[K230_DEV_TIMER ].base); + +for (int i =0 ; i <K230_APBTMR_NUM_TIMERS ; i++) { +sysbus_connect_irq (SYS_BUS_DEVICE (&s->timer), i, +qdev_get_gpio_in (DEVICE (s->c908_plic), +K230_TIMER0_IRQ + i)); + } +/* Watchdog */ for (int i =0 ; i <2 ; i++) {if (!sysbus_realize (SYS_BUS_DEVICE (&s->wdt[i]), errp)) {
@@ -283,9 +303,6 @@ static void k230_soc_realize(DeviceState *dev, Error **errp)create_unimplemented_device ("iomux" , memmap[K230_DEV_IOMUX ].base, memmap[K230_DEV_IOMUX ].size); -create_unimplemented_device ("timer" , memmap[K230_DEV_TIMER ].base, - memmap[K230_DEV_TIMER ].size); -create_unimplemented_device ("wdt0" , memmap[K230_DEV_WDT0 ].base, memmap[K230_DEV_WDT0 ].size);
hw/timer/Kconfig +4 -0
@@ -65,3 +65,7 @@ config STELLARIS_GPTM config AVR_TIMER16 bool + +config K230_TIMER + bool + select PTIMER
hw/timer/k230_dwapb_timer.c new file +332 -0
332 lines not on this page · raw message
hw/timer/meson.build +1 -0
@@ -34,3 +34,4 @@ specific_ss.add(when: 'CONFIG_IBEX', if_true: files('ibex_timer.c')) system_ss.add(when: 'CONFIG_SIFIVE_PWM', if_true: files('sifive_pwm.c')) system_ss.add(when: 'CONFIG_AVR_TIMER16', if_true: files('avr_timer16.c')) +system_ss.add(when: 'CONFIG_K230_TIMER', if_true: files('k230_dwapb_timer.c'))
hw/timer/trace-events +9 -0
@@ -1,5 +1,14 @@ # See docs/devel/tracing.rst for syntax documentation. +# k230_dwapb_timer.c +k230_timer_read(uint64_t addr, uint32_t val) "K230 timer read: [0x%" PRIx64 "] -> 0x%" PRIx32 +k230_timer_write(uint64_t addr, uint64_t val) "K230 timer write: [0x%" PRIx64 "] <- 0x%" PRIx64 +k230_timer_tick(int idx) "K230 timer %d tick" +k230_timer_interrupt(int idx) "K230 timer %d IRQ asserted" +k230_timer_irq_clear(int idx) "K230 timer %d IRQ cleared" +k230_timer_enable(int idx, uint32_t load) "K230 timer %d enabled load=0x%" PRIx32 +k230_timer_disable(int idx) "K230 timer %d disabled" + # slavio_timer.c slavio_timer_get_out(uint64_t limit, uint32_t counthigh, uint32_t count) "limit 0x%"PRIx64" count 0x%x0x%08x" slavio_timer_irq(uint32_t counthigh, uint32_t count) "callback: count 0x%x0x%08x"
include/hw/riscv/k230.h +8 -0
@@ -18,6 +18,7 @@#include "hw/core/boards.h" #include "hw/riscv/riscv_hart.h" #include "hw/watchdog/k230_wdt.h" +#include "hw/timer/k230_dwapb_timer.h" #define C908_CPU_HARTID (0)
@@ -33,6 +34,7 @@ typedef struct K230SoCState {RISCVHartArrayState c908_cpu;/* Small core */ K230WdtState wdt[2 ]; +K230TimerState timer;MemoryRegion sram;MemoryRegion bootrom;
@@ -127,6 +129,12 @@ enum {K230_UART2_IRQ =18 ,K230_UART3_IRQ =19 ,K230_UART4_IRQ =20 , +K230_TIMER0_IRQ =101 , +K230_TIMER1_IRQ =102 , +K230_TIMER2_IRQ =103 , +K230_TIMER3_IRQ =104 , +K230_TIMER4_IRQ =105 , +K230_TIMER5_IRQ =106 ,K230_WDT0_IRQ =107 , K230_WDT1_IRQ = 108, };
include/hw/timer/k230_dwapb_timer.h new file +68 -0
68 lines not on this page · raw message
tests/qtest/k230-dwapb-timer-test.c new file +224 -0
224 lines not on this page · raw message
tests/qtest/meson.build +1 -1
@@ -297,7 +297,7 @@ qtests_riscv64 = ['riscv-csr-test'] + \ (config_all_devices.has_key('CONFIG_IOMMU_TESTDEV') and config_all_devices.has_key('CONFIG_RISCV_IOMMU') ? ['iommu-riscv-test'] : []) + \ - (config_all_devices.has_key('CONFIG_K230') ? ['k230-wdt-test'] : []) + (config_all_devices.has_key('CONFIG_K230') ? ['k230-wdt-test', 'k230-dwapb-timer-test'] : []) qtests_hexagon = ['boot-serial-test']
Signature · 1 line
2.53.0
Quoted 5 lines · raoyi
Add DesignWare APB timer peripheral for K230 machine. The timer uses the Clock framework for frequency input, preparing for future CMU integration.
Signed-off-by raoyi <[email protected]>
Thank you very much for your contribution.
I recommend splitting this patch into three separate patches.The plan consists of three patches:
We want to keep the coding style as consistent as possible with the previous patch.
1. The implementation of the K230 DesignWare APB (DWAPB) timer model (k230_dwapb_timer.c).
2. The integration of peripheral models into the K230 board.
3. Testing and documentation.
Additionally, this patch has a conflict with the current master branch. Please do a rebase when the maintainer asks for the merge. There's no need to do it right now.
Signature · 1 line
Junze Cao <[email protected]>