From: Philippe Mathieu-Daudé <f4bug@amsat.org>
TYPE_ETRAX_FS_TIMER is a sysbus device, so its DeviceClass::reset()
handler is called automatically when its qbus parent is reset
(we don't need to register it manually).
Convert the generic reset to a enter/exit resettable ones, and
remove the qemu_register_reset() call.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
hw/timer/etraxfs_timer.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/hw/timer/etraxfs_timer.c b/hw/timer/etraxfs_timer.c
index 5379006086f..7dd3daf6771 100644
--- a/hw/timer/etraxfs_timer.c
+++ b/hw/timer/etraxfs_timer.c
@@ -309,9 +309,9 @@ static const MemoryRegionOps timer_ops = {
}
};
-static void etraxfs_timer_reset(void *opaque)
+static void etraxfs_timer_reset_enter(Object *obj, ResetType type)
{
- ETRAXTimerState *t = opaque;
+ ETRAXTimerState *t = ETRAX_TIMER(obj);
ptimer_transaction_begin(t->ptimer_t0);
ptimer_stop(t->ptimer_t0);
@@ -325,6 +325,12 @@ static void etraxfs_timer_reset(void *opaque)
t->rw_wd_ctrl = 0;
t->r_intr = 0;
t->rw_intr_mask = 0;
+}
+
+static void etraxfs_timer_reset_exit(Object *obj)
+{
+ ETRAXTimerState *t = ETRAX_TIMER(obj);
+
qemu_irq_lower(t->irq);
}
@@ -343,14 +349,16 @@ static void etraxfs_timer_realize(DeviceState *dev, Error **errp)
memory_region_init_io(&t->mmio, OBJECT(t), &timer_ops, t,
"etraxfs-timer", 0x5c);
sysbus_init_mmio(sbd, &t->mmio);
- qemu_register_reset(etraxfs_timer_reset, t);
}
static void etraxfs_timer_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
+ ResettableClass *rc = RESETTABLE_CLASS(klass);
dc->realize = etraxfs_timer_realize;
+ rc->phases.enter = etraxfs_timer_reset_enter;
+ rc->phases.exit = etraxfs_timer_reset_exit;
}
static const TypeInfo etraxfs_timer_info = {
--
2.26.3
On Sun, May 02, 2021 at 12:13:49AM +0200, Philippe Mathieu-Daudé wrote:
> From: Philippe Mathieu-Daudé <f4bug@amsat.org>
>
> TYPE_ETRAX_FS_TIMER is a sysbus device, so its DeviceClass::reset()
> handler is called automatically when its qbus parent is reset
> (we don't need to register it manually).
>
> Convert the generic reset to a enter/exit resettable ones, and
> remove the qemu_register_reset() call.
Hi Philippe,
The interrupt should be updated in the reset_hold phase, otherwise
interrupts stay asserted while the device is in reset.
Otherwise this looks good to me.
Cheers,
Edgar
>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> hw/timer/etraxfs_timer.c | 14 +++++++++++---
> 1 file changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/hw/timer/etraxfs_timer.c b/hw/timer/etraxfs_timer.c
> index 5379006086f..7dd3daf6771 100644
> --- a/hw/timer/etraxfs_timer.c
> +++ b/hw/timer/etraxfs_timer.c
> @@ -309,9 +309,9 @@ static const MemoryRegionOps timer_ops = {
> }
> };
>
> -static void etraxfs_timer_reset(void *opaque)
> +static void etraxfs_timer_reset_enter(Object *obj, ResetType type)
> {
> - ETRAXTimerState *t = opaque;
> + ETRAXTimerState *t = ETRAX_TIMER(obj);
>
> ptimer_transaction_begin(t->ptimer_t0);
> ptimer_stop(t->ptimer_t0);
> @@ -325,6 +325,12 @@ static void etraxfs_timer_reset(void *opaque)
> t->rw_wd_ctrl = 0;
> t->r_intr = 0;
> t->rw_intr_mask = 0;
> +}
> +
> +static void etraxfs_timer_reset_exit(Object *obj)
> +{
> + ETRAXTimerState *t = ETRAX_TIMER(obj);
> +
> qemu_irq_lower(t->irq);
> }
>
> @@ -343,14 +349,16 @@ static void etraxfs_timer_realize(DeviceState *dev, Error **errp)
> memory_region_init_io(&t->mmio, OBJECT(t), &timer_ops, t,
> "etraxfs-timer", 0x5c);
> sysbus_init_mmio(sbd, &t->mmio);
> - qemu_register_reset(etraxfs_timer_reset, t);
> }
>
> static void etraxfs_timer_class_init(ObjectClass *klass, void *data)
> {
> DeviceClass *dc = DEVICE_CLASS(klass);
> + ResettableClass *rc = RESETTABLE_CLASS(klass);
>
> dc->realize = etraxfs_timer_realize;
> + rc->phases.enter = etraxfs_timer_reset_enter;
> + rc->phases.exit = etraxfs_timer_reset_exit;
> }
>
> static const TypeInfo etraxfs_timer_info = {
> --
> 2.26.3
>
Hi Edgar, +Damien/Luc/Markus On 5/2/21 8:21 AM, Edgar E. Iglesias wrote: > On Sun, May 02, 2021 at 12:13:49AM +0200, Philippe Mathieu-Daudé wrote: >> From: Philippe Mathieu-Daudé <f4bug@amsat.org> >> >> TYPE_ETRAX_FS_TIMER is a sysbus device, so its DeviceClass::reset() >> handler is called automatically when its qbus parent is reset >> (we don't need to register it manually). >> >> Convert the generic reset to a enter/exit resettable ones, and >> remove the qemu_register_reset() call. > > Hi Philippe, > > The interrupt should be updated in the reset_hold phase, otherwise > interrupts stay asserted while the device is in reset. OK. I took some time to understand in which handler the IRQ call had to go, so I think to documentation is not clear enough: * @phases.hold: This phase is called for entry into reset, once every object * in the system which is being reset has had its @phases.enter method called. * At this point devices can do actions that affect other objects. * * @phases.exit: This phase is called when the object leaves the reset state. * Actions affecting other objects are permitted. Do you mind sending a patch to clarify? Personally I find listing what can be done where easier to understand (explicit list) rather than being generic and letting the developer choose. > > Otherwise this looks good to me. > > Cheers, > Edgar
On Sun, May 02, 2021 at 12:13:49AM +0200, Philippe Mathieu-Daudé wrote:
> From: Philippe Mathieu-Daudé <f4bug@amsat.org>
>
> TYPE_ETRAX_FS_TIMER is a sysbus device, so its DeviceClass::reset()
> handler is called automatically when its qbus parent is reset
> (we don't need to register it manually).
>
> Convert the generic reset to a enter/exit resettable ones, and
> remove the qemu_register_reset() call.
Same comment here regarding reset_exit -> reset_hold.
Cheers,
Edgar
>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> hw/timer/etraxfs_timer.c | 14 +++++++++++---
> 1 file changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/hw/timer/etraxfs_timer.c b/hw/timer/etraxfs_timer.c
> index 5379006086f..7dd3daf6771 100644
> --- a/hw/timer/etraxfs_timer.c
> +++ b/hw/timer/etraxfs_timer.c
> @@ -309,9 +309,9 @@ static const MemoryRegionOps timer_ops = {
> }
> };
>
> -static void etraxfs_timer_reset(void *opaque)
> +static void etraxfs_timer_reset_enter(Object *obj, ResetType type)
> {
> - ETRAXTimerState *t = opaque;
> + ETRAXTimerState *t = ETRAX_TIMER(obj);
>
> ptimer_transaction_begin(t->ptimer_t0);
> ptimer_stop(t->ptimer_t0);
> @@ -325,6 +325,12 @@ static void etraxfs_timer_reset(void *opaque)
> t->rw_wd_ctrl = 0;
> t->r_intr = 0;
> t->rw_intr_mask = 0;
> +}
> +
> +static void etraxfs_timer_reset_exit(Object *obj)
> +{
> + ETRAXTimerState *t = ETRAX_TIMER(obj);
> +
> qemu_irq_lower(t->irq);
> }
>
> @@ -343,14 +349,16 @@ static void etraxfs_timer_realize(DeviceState *dev, Error **errp)
> memory_region_init_io(&t->mmio, OBJECT(t), &timer_ops, t,
> "etraxfs-timer", 0x5c);
> sysbus_init_mmio(sbd, &t->mmio);
> - qemu_register_reset(etraxfs_timer_reset, t);
> }
>
> static void etraxfs_timer_class_init(ObjectClass *klass, void *data)
> {
> DeviceClass *dc = DEVICE_CLASS(klass);
> + ResettableClass *rc = RESETTABLE_CLASS(klass);
>
> dc->realize = etraxfs_timer_realize;
> + rc->phases.enter = etraxfs_timer_reset_enter;
> + rc->phases.exit = etraxfs_timer_reset_exit;
> }
>
> static const TypeInfo etraxfs_timer_info = {
> --
> 2.26.3
>
© 2016 - 2026 Red Hat, Inc.