[PATCH 5/9] hw/intc/riscv_aclint: implement the RISCVCPUTimeSrcIf interface

Luc Michel posted 9 patches 1 week ago
Maintainers: Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Weiwei Li <liwei1518@gmail.com>, Daniel Henrique Barboza <dbarboza@ventanamicro.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>
[PATCH 5/9] hw/intc/riscv_aclint: implement the RISCVCPUTimeSrcIf interface
Posted by Luc Michel 1 week ago
Implement the RISCVCPUTimeSrcIf QOM interface in the ACLINT mtimer device
model.

Signed-off-by: Luc Michel <luc.michel@amd.com>
---
 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
Re: [PATCH 5/9] hw/intc/riscv_aclint: implement the RISCVCPUTimeSrcIf interface
Posted by Philippe Mathieu-Daudé 5 days, 1 hour ago
On 7/11/25 11:23, Luc Michel wrote:
> Implement the RISCVCPUTimeSrcIf QOM interface in the ACLINT mtimer device
> model.
> 
> Signed-off-by: Luc Michel <luc.michel@amd.com>
> ---
>   hw/intc/riscv_aclint.c | 22 ++++++++++++++++++++++
>   1 file changed, 22 insertions(+)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>