hw/timer: add k230 dwapb timer
Subsystems (2)
v2 cover 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.
Changes since v1:
- Split into 3 patches: model, board integration, tests
- Remove goto pattern from read/write handlers
- Fix include order, add explicit bitops.h include
- Add QOM <private>/<public> markers in struct
- Fix copyright headers
raoyi (3):
hw/timer: add k230 dwapb timer model hw/riscv: integrate k230 dwapb timer into k230 board tests/qtest: add k230 dwapb timer test
MAINTAINERS | 3 + hw/riscv/Kconfig | 1 + hw/riscv/k230.c | 23 +- hw/timer/Kconfig | 4 + hw/timer/k230_dwapb_timer.c | 317 ++++++++++++++++++++++++++++ hw/timer/meson.build | 1 + hw/timer/trace-events | 9 + include/hw/riscv/k230.h | 8 + include/hw/timer/k230_dwapb_timer.h | 72 +++++++ tests/qtest/k230-dwapb-timer-test.c | 227 ++++++++++++++++++++ tests/qtest/meson.build | 2 +- 11 files changed, 663 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
Signature · 1 line
2.53.0
PATCH v2 1/3 hw/timer: add k230 dwapb timer model
Add DesignWare APB timer model for K230 machine. The timer uses the Clock framework for frequency input, preparing for future CMU integration.
--- hw/timer/Kconfig | 4 + hw/timer/k230_dwapb_timer.c | 317 ++++++++++++++++++++++++++++ hw/timer/meson.build | 1 + hw/timer/trace-events | 9 + include/hw/timer/k230_dwapb_timer.h | 72 +++++++ 5 files changed, 403 insertions(+) create mode 100644 hw/timer/k230_dwapb_timer.c create mode 100644 include/hw/timer/k230_dwapb_timer.h
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 +317 -0
317 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/timer/k230_dwapb_timer.h new file +72 -0
72 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v2 2/3 hw/riscv: integrate k230 dwapb timer into k230 board
In reply to raoyiWire up the K230 DW APB timer to the K230 SoC, including PLIC IRQ connections and memory mapping. Remove the previous unimplemented timer stub.
--- hw/riscv/Kconfig | 1 + hw/riscv/k230.c | 23 ++++++++++++++++++++--- include/hw/riscv/k230.h | 8 ++++++++ 3 files changed, 29 insertions(+), 3 deletions(-)
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);
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, };
Signature · 1 line
2.53.0
PATCH v2 3/3 tests/qtest: add k230 dwapb timer test
In reply to raoyiAdd qtest coverage for K230 DW APB timer including free-running, periodic, interrupt mask, disable behavior, current value, dynamic reload, and multi-channel scenarios.
Add timer files to MAINTAINERS.
--- MAINTAINERS | 3 + tests/qtest/k230-dwapb-timer-test.c | 227 ++++++++++++++++++++++++++++ tests/qtest/meson.build | 2 +- 3 files changed, 231 insertions(+), 1 deletion(-) 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 -----------
tests/qtest/k230-dwapb-timer-test.c new file +227 -0
227 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 17 lines · raoyi
Add DesignWare APB timer peripheral for K230 machine. The timer uses the Clock framework for frequency input, preparing for future CMU integration.
Changes since v1:
- Split into 3 patches: model, board integration, tests
- Remove goto pattern from read/write handlers
- Fix include order, add explicitbitops.hinclude
- Add QOM <private>/<public> markers in struct
- Fix copyright headersraoyi (3):
hw/timer: add k230 dwapb timer model hw/riscv: integrate k230 dwapb timer into k230 board tests/qtest: add k230 dwapb timer test
Quoted 5 lines
MAINTAINERS | 3 + hw/riscv/Kconfig | 1 + hw/riscv/k230.c | 23 +- hw/timer/Kconfig | 4 + hw/timer/k230_dwapb_timer.c | 317 ++++++++++++++++++++++++++++
This one should be modeled as a generic DesignWare APB Timer, then optionally a K230 customized wrapper model.
Quoted 11 lines
hw/timer/meson.build | 1 + hw/timer/trace-events | 9 + include/hw/riscv/k230.h | 8 + include/hw/timer/k230_dwapb_timer.h | 72 +++++++ tests/qtest/k230-dwapb-timer-test.c | 227 ++++++++++++++++++++ tests/qtest/meson.build | 2 +- 11 files changed, 663 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
Quoted 1 line
--
Regards,
Bin