aboutsummaryrefslogtreecommitdiff
path: root/hw/timer
diff options
context:
space:
mode:
Diffstat (limited to 'hw/timer')
-rw-r--r--hw/timer/lm32_timer.c19
-rw-r--r--hw/timer/mc146818rtc.c4
-rw-r--r--hw/timer/milkymist-sysctl.c23
3 files changed, 27 insertions, 19 deletions
diff --git a/hw/timer/lm32_timer.c b/hw/timer/lm32_timer.c
index 3198355aa4..e45a65bb9d 100644
--- a/hw/timer/lm32_timer.c
+++ b/hw/timer/lm32_timer.c
@@ -176,21 +176,26 @@ static void timer_reset(DeviceState *d)
ptimer_stop(s->ptimer);
}
-static int lm32_timer_init(SysBusDevice *dev)
+static void lm32_timer_init(Object *obj)
{
- LM32TimerState *s = LM32_TIMER(dev);
+ LM32TimerState *s = LM32_TIMER(obj);
+ SysBusDevice *dev = SYS_BUS_DEVICE(obj);
sysbus_init_irq(dev, &s->irq);
s->bh = qemu_bh_new(timer_hit, s);
s->ptimer = ptimer_init(s->bh);
- ptimer_set_freq(s->ptimer, s->freq_hz);
- memory_region_init_io(&s->iomem, OBJECT(s), &timer_ops, s,
+ memory_region_init_io(&s->iomem, obj, &timer_ops, s,
"timer", R_MAX * 4);
sysbus_init_mmio(dev, &s->iomem);
+}
- return 0;
+static void lm32_timer_realize(DeviceState *dev, Error **errp)
+{
+ LM32TimerState *s = LM32_TIMER(dev);
+
+ ptimer_set_freq(s->ptimer, s->freq_hz);
}
static const VMStateDescription vmstate_lm32_timer = {
@@ -213,9 +218,8 @@ static Property lm32_timer_properties[] = {
static void lm32_timer_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
- SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
- k->init = lm32_timer_init;
+ dc->realize = lm32_timer_realize;
dc->reset = timer_reset;
dc->vmsd = &vmstate_lm32_timer;
dc->props = lm32_timer_properties;
@@ -225,6 +229,7 @@ static const TypeInfo lm32_timer_info = {
.name = TYPE_LM32_TIMER,
.parent = TYPE_SYS_BUS_DEVICE,
.instance_size = sizeof(LM32TimerState),
+ .instance_init = lm32_timer_init,
.class_init = lm32_timer_class_init,
};
diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c
index a11b8b4b21..f4e333eb8f 100644
--- a/hw/timer/mc146818rtc.c
+++ b/hw/timer/mc146818rtc.c
@@ -105,12 +105,10 @@ static inline bool rtc_running(RTCState *s)
static uint64_t get_guest_rtc_ns(RTCState *s)
{
- uint64_t guest_rtc;
uint64_t guest_clock = qemu_clock_get_ns(rtc_clock);
- guest_rtc = s->base_rtc * NANOSECONDS_PER_SECOND +
+ return s->base_rtc * NANOSECONDS_PER_SECOND +
guest_clock - s->last_update + s->offset;
- return guest_rtc;
}
#ifdef TARGET_I386
diff --git a/hw/timer/milkymist-sysctl.c b/hw/timer/milkymist-sysctl.c
index 5f2948037a..21948328ce 100644
--- a/hw/timer/milkymist-sysctl.c
+++ b/hw/timer/milkymist-sysctl.c
@@ -18,7 +18,7 @@
*
*
* Specification available at:
- * http://www.milkymist.org/socdoc/sysctl.pdf
+ * http://milkymist.walle.cc/socdoc/sysctl.pdf
*/
#include "qemu/osdep.h"
@@ -270,9 +270,10 @@ static void milkymist_sysctl_reset(DeviceState *d)
s->regs[R_GPIO_IN] = s->strappings;
}
-static int milkymist_sysctl_init(SysBusDevice *dev)
+static void milkymist_sysctl_init(Object *obj)
{
- MilkymistSysctlState *s = MILKYMIST_SYSCTL(dev);
+ MilkymistSysctlState *s = MILKYMIST_SYSCTL(obj);
+ SysBusDevice *dev = SYS_BUS_DEVICE(obj);
sysbus_init_irq(dev, &s->gpio_irq);
sysbus_init_irq(dev, &s->timer0_irq);
@@ -282,14 +283,18 @@ static int milkymist_sysctl_init(SysBusDevice *dev)
s->bh1 = qemu_bh_new(timer1_hit, s);
s->ptimer0 = ptimer_init(s->bh0);
s->ptimer1 = ptimer_init(s->bh1);
- ptimer_set_freq(s->ptimer0, s->freq_hz);
- ptimer_set_freq(s->ptimer1, s->freq_hz);
- memory_region_init_io(&s->regs_region, OBJECT(s), &sysctl_mmio_ops, s,
+ memory_region_init_io(&s->regs_region, obj, &sysctl_mmio_ops, s,
"milkymist-sysctl", R_MAX * 4);
sysbus_init_mmio(dev, &s->regs_region);
+}
- return 0;
+static void milkymist_sysctl_realize(DeviceState *dev, Error **errp)
+{
+ MilkymistSysctlState *s = MILKYMIST_SYSCTL(dev);
+
+ ptimer_set_freq(s->ptimer0, s->freq_hz);
+ ptimer_set_freq(s->ptimer1, s->freq_hz);
}
static const VMStateDescription vmstate_milkymist_sysctl = {
@@ -319,9 +324,8 @@ static Property milkymist_sysctl_properties[] = {
static void milkymist_sysctl_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
- SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
- k->init = milkymist_sysctl_init;
+ dc->realize = milkymist_sysctl_realize;
dc->reset = milkymist_sysctl_reset;
dc->vmsd = &vmstate_milkymist_sysctl;
dc->props = milkymist_sysctl_properties;
@@ -331,6 +335,7 @@ static const TypeInfo milkymist_sysctl_info = {
.name = TYPE_MILKYMIST_SYSCTL,
.parent = TYPE_SYS_BUS_DEVICE,
.instance_size = sizeof(MilkymistSysctlState),
+ .instance_init = milkymist_sysctl_init,
.class_init = milkymist_sysctl_class_init,
};