[PATCH qemu v2 2/7] ot_uart: move to new reset API

~lexbaileylowrisc posted 7 patches 3 days, 7 hours ago
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Alistair Francis <Alistair.Francis@wdc.com>, Palmer Dabbelt <palmer@dabbelt.com>, Weiwei Li <liwei1518@gmail.com>, Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, Chao Liu <chao.liu.zevorn@gmail.com>
[PATCH qemu v2 2/7] ot_uart: move to new reset API
Posted by ~lexbaileylowrisc 4 days, 8 hours ago
From: Lex Bailey <lex.bailey@lowrisc.org>

switch from legacy_reset to new ResettableClass for OpenTitan UART device

Signed-off-by: Lex Bailey <lex.bailey@lowrisc.org>
---
 hw/char/ot_uart.c         | 16 +++++++++++++---
 include/hw/char/ot_uart.h |  8 +++++++-
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/hw/char/ot_uart.c b/hw/char/ot_uart.c
index b3eb619641..2cf0d73cf5 100644
--- a/hw/char/ot_uart.c
+++ b/hw/char/ot_uart.c
@@ -227,9 +227,14 @@ static void uart_write_tx_fifo(OtUARTState *s, const uint8_t *buf,
               (s->char_tx_time * 4));
 }
 
-static void ot_uart_reset(DeviceState *dev)
+static void ot_uart_reset_enter(Object *obj, ResetType type)
 {
-    OtUARTState *s = OT_UART(dev);
+    OtUARTClass *c = OT_UART_GET_CLASS(obj);
+    OtUARTState *s = OT_UART(obj);
+
+    if (c->parent_phases.enter) {
+        c->parent_phases.enter(obj, type);
+    }
 
     s->uart_intr_state = 0x00000000;
     s->uart_intr_state = 0x00000000;
@@ -545,11 +550,15 @@ static void ot_uart_class_init(ObjectClass *klass, const void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
 
-    device_class_set_legacy_reset(dc, ot_uart_reset);
     dc->realize = ot_uart_realize;
     dc->vmsd = &vmstate_ot_uart;
     device_class_set_props(dc, ot_uart_properties);
     set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
+
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
+    OtUARTClass *uc = OT_UART_CLASS(klass);
+    resettable_class_set_parent_phases(rc, &ot_uart_reset_enter, NULL, NULL,
+                                       &uc->parent_phases);
 }
 
 static const TypeInfo ot_uart_info = {
@@ -557,6 +566,7 @@ static const TypeInfo ot_uart_info = {
     .parent        = TYPE_SYS_BUS_DEVICE,
     .instance_size = sizeof(OtUARTState),
     .instance_init = ot_uart_init,
+    .class_size    = sizeof(OtUARTClass),
     .class_init    = ot_uart_class_init,
 };
 
diff --git a/include/hw/char/ot_uart.h b/include/hw/char/ot_uart.h
index 517324b65d..fee2128f90 100644
--- a/include/hw/char/ot_uart.h
+++ b/include/hw/char/ot_uart.h
@@ -34,7 +34,7 @@
 #define OT_UART_CLOCK 50000000 /* 50MHz clock */
 
 #define TYPE_OT_UART "ot-uart"
-OBJECT_DECLARE_SIMPLE_TYPE(OtUARTState, OT_UART)
+OBJECT_DECLARE_TYPE(OtUARTState, OtUARTClass, OT_UART)
 
 struct OtUARTState {
     /* <private> */
@@ -70,4 +70,10 @@ struct OtUARTState {
     qemu_irq tx_empty;
     qemu_irq rx_overflow;
 };
+
+struct OtUARTClass {
+    SysBusDeviceClass parent_class;
+    ResettablePhases parent_phases;
+};
+
 #endif /* HW_OT_UART_H */
-- 
2.49.1
Re: [PATCH qemu v2 2/7] ot_uart: move to new reset API
Posted by Alistair Francis 1 day, 16 hours ago
On Thu, Apr 9, 2026 at 5:42 AM ~lexbaileylowrisc
<lexbaileylowrisc@git.sr.ht> wrote:
>
> From: Lex Bailey <lex.bailey@lowrisc.org>
>
> switch from legacy_reset to new ResettableClass for OpenTitan UART device
>
> Signed-off-by: Lex Bailey <lex.bailey@lowrisc.org>
> ---
>  hw/char/ot_uart.c         | 16 +++++++++++++---
>  include/hw/char/ot_uart.h |  8 +++++++-
>  2 files changed, 20 insertions(+), 4 deletions(-)
>
> diff --git a/hw/char/ot_uart.c b/hw/char/ot_uart.c
> index b3eb619641..2cf0d73cf5 100644
> --- a/hw/char/ot_uart.c
> +++ b/hw/char/ot_uart.c
> @@ -227,9 +227,14 @@ static void uart_write_tx_fifo(OtUARTState *s, const uint8_t *buf,
>                (s->char_tx_time * 4));
>  }
>
> -static void ot_uart_reset(DeviceState *dev)
> +static void ot_uart_reset_enter(Object *obj, ResetType type)
>  {
> -    OtUARTState *s = OT_UART(dev);
> +    OtUARTClass *c = OT_UART_GET_CLASS(obj);
> +    OtUARTState *s = OT_UART(obj);
> +
> +    if (c->parent_phases.enter) {
> +        c->parent_phases.enter(obj, type);
> +    }
>
>      s->uart_intr_state = 0x00000000;
>      s->uart_intr_state = 0x00000000;
> @@ -545,11 +550,15 @@ static void ot_uart_class_init(ObjectClass *klass, const void *data)
>  {
>      DeviceClass *dc = DEVICE_CLASS(klass);
>
> -    device_class_set_legacy_reset(dc, ot_uart_reset);
>      dc->realize = ot_uart_realize;
>      dc->vmsd = &vmstate_ot_uart;
>      device_class_set_props(dc, ot_uart_properties);
>      set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
> +
> +    ResettableClass *rc = RESETTABLE_CLASS(klass);
> +    OtUARTClass *uc = OT_UART_CLASS(klass);

Please don't mix statements and declarations within blocks [1],
checkpatch should catch this

1: https://qemu-project.gitlab.io/qemu/devel/style.html#declarations

Alistair

> +    resettable_class_set_parent_phases(rc, &ot_uart_reset_enter, NULL, NULL,
> +                                       &uc->parent_phases);
>  }
>
>  static const TypeInfo ot_uart_info = {
> @@ -557,6 +566,7 @@ static const TypeInfo ot_uart_info = {
>      .parent        = TYPE_SYS_BUS_DEVICE,
>      .instance_size = sizeof(OtUARTState),
>      .instance_init = ot_uart_init,
> +    .class_size    = sizeof(OtUARTClass),
>      .class_init    = ot_uart_class_init,
>  };
>
> diff --git a/include/hw/char/ot_uart.h b/include/hw/char/ot_uart.h
> index 517324b65d..fee2128f90 100644
> --- a/include/hw/char/ot_uart.h
> +++ b/include/hw/char/ot_uart.h
> @@ -34,7 +34,7 @@
>  #define OT_UART_CLOCK 50000000 /* 50MHz clock */
>
>  #define TYPE_OT_UART "ot-uart"
> -OBJECT_DECLARE_SIMPLE_TYPE(OtUARTState, OT_UART)
> +OBJECT_DECLARE_TYPE(OtUARTState, OtUARTClass, OT_UART)
>
>  struct OtUARTState {
>      /* <private> */
> @@ -70,4 +70,10 @@ struct OtUARTState {
>      qemu_irq tx_empty;
>      qemu_irq rx_overflow;
>  };
> +
> +struct OtUARTClass {
> +    SysBusDeviceClass parent_class;
> +    ResettablePhases parent_phases;
> +};
> +
>  #endif /* HW_OT_UART_H */
> --
> 2.49.1
>
>