Message ID | 20250110182759.84071-3-philmd@linaro.org |
---|---|
State | New |
Headers | show |
Series | hw/char/serial: Convert to three-phase reset | expand |
On 1/10/25 10:27, Philippe Mathieu-Daudé wrote: > Convert the TYPE_SERIAL (16550A UART) to three-phase reset. > > Only local states are reset so use the ResetHold handler, > like other legacy devices. > > Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> > --- > hw/char/serial.c | 10 ++++------ > 1 file changed, 4 insertions(+), 6 deletions(-) > > diff --git a/hw/char/serial.c b/hw/char/serial.c > index 562931685e7..9cb6e30c9ce 100644 > --- a/hw/char/serial.c > +++ b/hw/char/serial.c > @@ -851,9 +851,9 @@ const VMStateDescription vmstate_serial = { > } > }; > > -static void serial_reset(void *opaque) > +static void serial_reset_hold(Object *obj, ResetType type) > { > - SerialState *s = opaque; > + SerialState *s = (SerialState *)obj; > > if (s->watch_tag > 0) { > g_source_remove(s->watch_tag); > @@ -928,13 +928,11 @@ static void serial_realize(DeviceState *dev, Error **errp) > s->modem_status_poll = timer_new_ns(QEMU_CLOCK_VIRTUAL, (QEMUTimerCB *) serial_update_msl, s); > > s->fifo_timeout_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, (QEMUTimerCB *) fifo_timeout_int, s); > - qemu_register_reset(serial_reset, s); > > qemu_chr_fe_set_handlers(&s->chr, serial_can_receive1, serial_receive1, > serial_event, serial_be_change, s, NULL, true); > fifo8_create(&s->recv_fifo, UART_FIFO_LENGTH); > fifo8_create(&s->xmit_fifo, UART_FIFO_LENGTH); > - serial_reset(s); > } > > static void serial_unrealize(DeviceState *dev) > @@ -949,8 +947,6 @@ static void serial_unrealize(DeviceState *dev) > > fifo8_destroy(&s->recv_fifo); > fifo8_destroy(&s->xmit_fifo); > - > - qemu_unregister_reset(serial_reset, s); > } > > const MemoryRegionOps serial_io_ops = { > @@ -975,12 +971,14 @@ static const Property serial_properties[] = { > static void serial_class_init(ObjectClass *klass, void* data) > { > DeviceClass *dc = DEVICE_CLASS(klass); > + ResettableClass *rc = RESETTABLE_CLASS(klass); > > /* internal device for serialio/serialmm, not user-creatable */ > dc->user_creatable = false; > dc->realize = serial_realize; > dc->unrealize = serial_unrealize; > device_class_set_props(dc, serial_properties); > + rc->phases.hold = serial_reset_hold; > } > > static const TypeInfo serial_info = { Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
diff --git a/hw/char/serial.c b/hw/char/serial.c index 562931685e7..9cb6e30c9ce 100644 --- a/hw/char/serial.c +++ b/hw/char/serial.c @@ -851,9 +851,9 @@ const VMStateDescription vmstate_serial = { } }; -static void serial_reset(void *opaque) +static void serial_reset_hold(Object *obj, ResetType type) { - SerialState *s = opaque; + SerialState *s = (SerialState *)obj; if (s->watch_tag > 0) { g_source_remove(s->watch_tag); @@ -928,13 +928,11 @@ static void serial_realize(DeviceState *dev, Error **errp) s->modem_status_poll = timer_new_ns(QEMU_CLOCK_VIRTUAL, (QEMUTimerCB *) serial_update_msl, s); s->fifo_timeout_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, (QEMUTimerCB *) fifo_timeout_int, s); - qemu_register_reset(serial_reset, s); qemu_chr_fe_set_handlers(&s->chr, serial_can_receive1, serial_receive1, serial_event, serial_be_change, s, NULL, true); fifo8_create(&s->recv_fifo, UART_FIFO_LENGTH); fifo8_create(&s->xmit_fifo, UART_FIFO_LENGTH); - serial_reset(s); } static void serial_unrealize(DeviceState *dev) @@ -949,8 +947,6 @@ static void serial_unrealize(DeviceState *dev) fifo8_destroy(&s->recv_fifo); fifo8_destroy(&s->xmit_fifo); - - qemu_unregister_reset(serial_reset, s); } const MemoryRegionOps serial_io_ops = { @@ -975,12 +971,14 @@ static const Property serial_properties[] = { static void serial_class_init(ObjectClass *klass, void* data) { DeviceClass *dc = DEVICE_CLASS(klass); + ResettableClass *rc = RESETTABLE_CLASS(klass); /* internal device for serialio/serialmm, not user-creatable */ dc->user_creatable = false; dc->realize = serial_realize; dc->unrealize = serial_unrealize; device_class_set_props(dc, serial_properties); + rc->phases.hold = serial_reset_hold; } static const TypeInfo serial_info = {
Convert the TYPE_SERIAL (16550A UART) to three-phase reset. Only local states are reset so use the ResetHold handler, like other legacy devices. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- hw/char/serial.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)