Implement the RISCVCPUTimeSrcIf QOM interface in the ACLINT mtimer device model.
Signed-off-by: Luc Michel <[email protected]> --- hw/intc/riscv_aclint.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/hw/intc/riscv_aclint.c b/hw/intc/riscv_aclint.c index 95398e48821..4a4449d9d2f 100644 --- a/hw/intc/riscv_aclint.c +++ b/hw/intc/riscv_aclint.c @@ -325,10 +325,25 @@ static void riscv_aclint_mtimer_reset_enter(Object *obj, ResetType type) * Pending mtime interrupts will also be cleared at the same time. */ riscv_aclint_mtimer_write(mtimer, mtimer->time_base, 0, 8); } +static uint64_t riscv_aclint_mtimer_time_src_get_ticks(RISCVCPUTimeSrcIf *iface) +{ + RISCVAclintMTimerState *mtimer = RISCV_ACLINT_MTIMER(iface); + + return riscv_aclint_mtimer_get_ticks(mtimer); +} + +static uint32_t riscv_aclint_mtimer_time_src_get_tick_freq(RISCVCPUTimeSrcIf *iface) +{ + RISCVAclintMTimerState *mtimer = RISCV_ACLINT_MTIMER(iface); + + return mtimer->timebase_freq; +} + + static const VMStateDescription vmstate_riscv_mtimer = { .name = "riscv_mtimer", .version_id = 3, .minimum_version_id = 3, .fields = (const VMStateField[]) { @@ -344,22 +359,29 @@ static const VMStateDescription vmstate_riscv_mtimer = { static void riscv_aclint_mtimer_class_init(ObjectClass *klass, const void *data) { DeviceClass *dc = DEVICE_CLASS(klass); ResettableClass *rc = RESETTABLE_CLASS(klass); + RISCVCPUTimeSrcIfClass *rctsc = RISCV_CPU_TIME_SRC_IF_CLASS(klass); dc->realize = riscv_aclint_mtimer_realize; device_class_set_props(dc, riscv_aclint_mtimer_properties); rc->phases.enter = riscv_aclint_mtimer_reset_enter; dc->vmsd = &vmstate_riscv_mtimer; + rctsc->get_ticks = riscv_aclint_mtimer_time_src_get_ticks; + rctsc->get_tick_freq = riscv_aclint_mtimer_time_src_get_tick_freq; } static const TypeInfo riscv_aclint_mtimer_info = { .name = TYPE_RISCV_ACLINT_MTIMER, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(RISCVAclintMTimerState), .class_init = riscv_aclint_mtimer_class_init, + .interfaces = (const InterfaceInfo []) { + { TYPE_RISCV_CPU_TIME_SRC_IF }, + { }, + }, }; /* * Create ACLINT MTIMER device. */ -- 2.51.0
