Expose the clock frequency via the QOM 'freq-hz' property, as it might be useful for QTests.
HMP example: $ qemu-system-mips -S -monitor stdio -M mipssim (qemu) qom-get /machine/cpu-refclk freq-hz 12000000 Inspired-by: Inès Varhol <ines.var...@telecom-paris.fr> Signed-off-by: Philippe Mathieu-Daudé <phi...@linaro.org> --- hw/core/clock.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hw/core/clock.c b/hw/core/clock.c index e212865307..55f86ef483 100644 --- a/hw/core/clock.c +++ b/hw/core/clock.c @@ -13,6 +13,7 @@ #include "qemu/osdep.h" #include "qemu/cutils.h" +#include "qapi/visitor.h" #include "hw/clock.h" #include "trace.h" @@ -158,6 +159,14 @@ bool clock_set_mul_div(Clock *clk, uint32_t multiplier, uint32_t divider) return true; } +static void clock_prop_freq_get(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + Clock *clk = CLOCK(obj); + uint64_t freq_hz = clock_get_hz(clk); + visit_type_uint64(v, name, &freq_hz, errp); +} + static void clock_initfn(Object *obj) { Clock *clk = CLOCK(obj); @@ -166,6 +175,9 @@ static void clock_initfn(Object *obj) clk->divider = 1; QLIST_INIT(&clk->children); + + object_property_add(obj, "freq-hz", "uint64", + clock_prop_freq_get, NULL, NULL, NULL); } static void clock_finalizefn(Object *obj) -- 2.41.0