Skip to contentSkip to conversation

hw/char: Convert UART and TTY devices to Resettable interface (part 1)

PATCH New Oscar Alejandro Sánchez Lucero 1 participant 11 messages Dec 2

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover hw/char: Convert UART and TTY devices to Resettable interface (part 1)

Convert the first batch of character device models in hw/char away from the deprecated device_class_set_legacy_reset() wrapper to the ResettableClass interface (hold phase), moving towards removing the legacy_reset callback from DeviceClass once all callers are migrated (as noted in include/hw/core/qdev.h).

---
Oscar Alejandro Sánchez Lucero (10):
hw/char/avr_usart: Convert to Resettable interface hw/char/cmsdk-apb-uart: Convert to Resettable interface hw/char/digic-uart: Convert to Resettable interface hw/char/escc: Convert to Resettable interface hw/char/exynos4210_uart: Convert to Resettable interface hw/char/goldfish_tty: Convert to Resettable interface hw/char/grlib_apbuart: Convert to Resettable interface hw/char/ibex_uart: Convert to Resettable interface hw/char/imx_serial: Convert to Resettable interface hw/char/mcf_uart: Convert to Resettable interface

 hw/char/avr_usart.c       | 11 ++++++-----
 hw/char/cmsdk-apb-uart.c  |  7 ++++---
 hw/char/digic-uart.c      |  7 ++++---
 hw/char/escc.c            |  7 ++++---
 hw/char/exynos4210_uart.c |  7 ++++---
 hw/char/goldfish_tty.c    |  7 ++++---
 hw/char/grlib_apbuart.c   |  7 ++++---
 hw/char/ibex_uart.c       |  7 ++++---
 hw/char/imx_serial.c      |  7 ++++---
 hw/char/mcf_uart.c        |  7 ++++---
 10 files changed, 42 insertions(+), 32 deletions(-)

---
base-commit: bbece0805c03c25f51a8cd89c39142f4f76a6567
change-id: 20261202-char-resettable-1-1707e128a285

Best regards,

Signature · 1 line
Oscar Alejandro Sánchez Lucero <[email protected]>
#1 lore raw

PATCH 1/10 hw/char/avr_usart: Convert to Resettable interface

Replace the deprecated device_class_set_legacy_reset() with the Resettable interface by implementing the hold phase in avr_usart_reset_hold() and calling device_cold_reset() internally.

---
 hw/char/avr_usart.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
hw/char/avr_usart.c +6 -5
index 30e135a..9a7bd87 100644
@@ -90,9 +90,9 @@ static void update_char_mask(AVRUsartState *usart)
     }
 }
 
-static void avr_usart_reset(DeviceState *dev)
+static void avr_usart_reset_hold(Object *obj, ResetType type)
 {
-    AVRUsartState *usart = AVR_USART(dev);
+    AVRUsartState *usart = AVR_USART(obj);
     usart->data_valid = false;
     usart->csra = 0b00100000;
     usart->csrb = 0b00000000;
@@ -270,7 +270,7 @@ static void avr_usart_pr(void *opaque, int irq, int level)
     s->enabled = !level;
 
     if (!s->enabled) {
-        avr_usart_reset(DEVICE(s));
+        device_cold_reset(DEVICE(s));
     }
 }
 
@@ -292,14 +292,15 @@ static void avr_usart_realize(DeviceState *dev, Error **errp)
     qemu_chr_fe_set_handlers(&s->chr, avr_usart_can_receive,
                              avr_usart_receive, NULL, NULL,
                              s, NULL, true);
-    avr_usart_reset(dev);
+    device_cold_reset(dev);
 }
 
 static void avr_usart_class_init(ObjectClass *klass, const void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
 
-    device_class_set_legacy_reset(dc, avr_usart_reset);
+    rc->phases.hold = avr_usart_reset_hold;
     device_class_set_props(dc, avr_usart_properties);
     dc->realize = avr_usart_realize;
 }
Signature · 1 line
2.53.0
#2 lore raw

PATCH 2/10 hw/char/cmsdk-apb-uart: Convert to Resettable interface

In reply to Oscar Alejandro Sánchez Lucero

Replace the deprecated device_class_set_legacy_reset() with the Resettable interface by implementing the hold phase in cmsdk_apb_uart_reset_hold().

---
 hw/char/cmsdk-apb-uart.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/char/cmsdk-apb-uart.c +4 -3
index 0631821..50cd472 100644
@@ -309,9 +309,9 @@ static const MemoryRegionOps uart_ops = {
     .endianness = DEVICE_LITTLE_ENDIAN,
 };
 
-static void cmsdk_apb_uart_reset(DeviceState *dev)
+static void cmsdk_apb_uart_reset_hold(Object *obj, ResetType type)
 {
-    CMSDKAPBUART *s = CMSDK_APB_UART(dev);
+    CMSDKAPBUART *s = CMSDK_APB_UART(obj);
 
     trace_cmsdk_apb_uart_reset();
     uart_cancel_transmit(s);
@@ -390,10 +390,11 @@ static const Property cmsdk_apb_uart_properties[] = {
 static void cmsdk_apb_uart_class_init(ObjectClass *klass, const void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
 
     dc->realize = cmsdk_apb_uart_realize;
     dc->vmsd = &cmsdk_apb_uart_vmstate;
-    device_class_set_legacy_reset(dc, cmsdk_apb_uart_reset);
+    rc->phases.hold = cmsdk_apb_uart_reset_hold;
     device_class_set_props(dc, cmsdk_apb_uart_properties);
 }
 
Signature · 1 line
2.53.0
#3 lore raw

PATCH 3/10 hw/char/digic-uart: Convert to Resettable interface

In reply to Oscar Alejandro Sánchez Lucero

Replace the deprecated device_class_set_legacy_reset() with the Resettable interface by implementing the hold phase in digic_uart_reset_hold().

---
 hw/char/digic-uart.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/char/digic-uart.c +4 -3
index bd66917..0c9f8b6 100644
@@ -136,9 +136,9 @@ static void uart_event(void *opaque, QEMUChrEvent event)
 {
 }
 
-static void digic_uart_reset(DeviceState *d)
+static void digic_uart_reset_hold(Object *obj, ResetType type)
 {
-    DigicUartState *s = DIGIC_UART(d);
+    DigicUartState *s = DIGIC_UART(obj);
 
     s->reg_rx = 0;
     s->reg_st = ST_TX_RDY;
@@ -179,9 +179,10 @@ static const Property digic_uart_properties[] = {
 static void digic_uart_class_init(ObjectClass *klass, const void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
 
     dc->realize = digic_uart_realize;
-    device_class_set_legacy_reset(dc, digic_uart_reset);
+    rc->phases.hold = digic_uart_reset_hold;
     dc->vmsd = &vmstate_digic_uart;
     device_class_set_props(dc, digic_uart_properties);
 }
Signature · 1 line
2.53.0
#4 lore raw

PATCH 4/10 hw/char/escc: Convert to Resettable interface

In reply to Oscar Alejandro Sánchez Lucero

Replace the deprecated device_class_set_legacy_reset() with the Resettable interface by implementing the hold phase in escc_reset_hold().

---
 hw/char/escc.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/char/escc.c +4 -3
index 7aae627..8e38009 100644
@@ -340,9 +340,9 @@ static void escc_hard_reset_chn(ESCCChannelState *s)
     s->wregs[W_MISC2] |= MISC2_LCL_LOOP | MISC2_PLLCMD0;
 }
 
-static void escc_reset(DeviceState *d)
+static void escc_reset_hold(Object *obj, ResetType type)
 {
-    ESCCState *s = ESCC(d);
+    ESCCState *s = ESCC(obj);
     int i, j;
 
     for (i = 0; i < 2; i++) {
@@ -1099,8 +1099,9 @@ static const Property escc_properties[] = {
 static void escc_class_init(ObjectClass *klass, const void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
 
-    device_class_set_legacy_reset(dc, escc_reset);
+    rc->phases.hold = escc_reset_hold;
     dc->realize = escc_realize;
     dc->vmsd = &vmstate_escc;
     device_class_set_props(dc, escc_properties);
Signature · 1 line
2.53.0
#5 lore raw

PATCH 5/10 hw/char/exynos4210_uart: Convert to Resettable interface

In reply to Oscar Alejandro Sánchez Lucero

Replace the deprecated device_class_set_legacy_reset() with the Resettable interface by implementing the hold phase in exynos4210_uart_reset_hold().

---
 hw/char/exynos4210_uart.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/char/exynos4210_uart.c +4 -3
index 9d18251..5cebad8 100644
@@ -556,9 +556,9 @@ static void exynos4210_uart_event(void *opaque, QEMUChrEvent event)
 }
 
 
-static void exynos4210_uart_reset(DeviceState *dev)
+static void exynos4210_uart_reset_hold(Object *obj, ResetType type)
 {
-    Exynos4210UartState *s = EXYNOS4210_UART(dev);
+    Exynos4210UartState *s = EXYNOS4210_UART(obj);
     int i;
 
     for (i = 0; i < ARRAY_SIZE(exynos4210_uart_regs); i++) {
@@ -661,9 +661,10 @@ static const Property exynos4210_uart_properties[] = {
 static void exynos4210_uart_class_init(ObjectClass *klass, const void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
 
     dc->realize = exynos4210_uart_realize;
-    device_class_set_legacy_reset(dc, exynos4210_uart_reset);
+    rc->phases.hold = exynos4210_uart_reset_hold;
     device_class_set_props(dc, exynos4210_uart_properties);
     dc->vmsd = &vmstate_exynos4210_uart;
 }
Signature · 1 line
2.53.0
#6 lore raw

PATCH 6/10 hw/char/goldfish_tty: Convert to Resettable interface

In reply to Oscar Alejandro Sánchez Lucero

Replace the deprecated device_class_set_legacy_reset() with the Resettable interface by implementing the hold phase in goldfish_tty_reset_hold().

---
 hw/char/goldfish_tty.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/char/goldfish_tty.c +4 -3
index 8e1e922..b94dbb7 100644
@@ -190,9 +190,9 @@ static void goldfish_tty_receive(void *opaque, const uint8_t *buffer, int size)
     }
 }
 
-static void goldfish_tty_reset(DeviceState *dev)
+static void goldfish_tty_reset_hold(Object *obj, ResetType type)
 {
-    GoldfishTTYState *s = GOLDFISH_TTY(dev);
+    GoldfishTTYState *s = GOLDFISH_TTY(obj);
 
     trace_goldfish_tty_reset(s);
 
@@ -259,9 +259,10 @@ static void goldfish_tty_instance_init(Object *obj)
 static void goldfish_tty_class_init(ObjectClass *oc, const void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(oc);
+    ResettableClass *rc = RESETTABLE_CLASS(oc);
 
     device_class_set_props(dc, goldfish_tty_properties);
-    device_class_set_legacy_reset(dc, goldfish_tty_reset);
+    rc->phases.hold = goldfish_tty_reset_hold;
     dc->realize = goldfish_tty_realize;
     dc->unrealize = goldfish_tty_unrealize;
     dc->vmsd = &vmstate_goldfish_tty;
Signature · 1 line
2.53.0
#7 lore raw

PATCH 7/10 hw/char/grlib_apbuart: Convert to Resettable interface

In reply to Oscar Alejandro Sánchez Lucero

Replace the deprecated device_class_set_legacy_reset() with the Resettable interface by implementing the hold phase in grlib_apbuart_reset_hold().

---
 hw/char/grlib_apbuart.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/char/grlib_apbuart.c +4 -3
index d828c3f..8691206 100644
@@ -264,9 +264,9 @@ static void grlib_apbuart_realize(DeviceState *dev, Error **errp)
     sysbus_init_mmio(sbd, &uart->iomem);
 }
 
-static void grlib_apbuart_reset(DeviceState *d)
+static void grlib_apbuart_reset_hold(Object *obj, ResetType type)
 {
-    UART *uart = GRLIB_APB_UART(d);
+    UART *uart = GRLIB_APB_UART(obj);
 
     /* Transmitter FIFO and shift registers are always empty in QEMU */
     uart->status =  UART_TRANSMIT_FIFO_EMPTY | UART_TRANSMIT_SHIFT_EMPTY;
@@ -284,9 +284,10 @@ static const Property grlib_apbuart_properties[] = {
 static void grlib_apbuart_class_init(ObjectClass *klass, const void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
 
     dc->realize = grlib_apbuart_realize;
-    device_class_set_legacy_reset(dc, grlib_apbuart_reset);
+    rc->phases.hold = grlib_apbuart_reset_hold;
     device_class_set_props(dc, grlib_apbuart_properties);
 }
 
Signature · 1 line
2.53.0
#8 lore raw

PATCH 8/10 hw/char/ibex_uart: Convert to Resettable interface

In reply to Oscar Alejandro Sánchez Lucero

Replace the deprecated device_class_set_legacy_reset() with the Resettable interface by implementing the hold phase in ibex_uart_reset_hold().

---
 hw/char/ibex_uart.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/char/ibex_uart.c +4 -3
index 26ed1ae..4929671 100644
@@ -227,9 +227,9 @@ static void uart_write_tx_fifo(IbexUartState *s, const uint8_t *buf,
               (s->char_tx_time * 4));
 }
 
-static void ibex_uart_reset(DeviceState *dev)
+static void ibex_uart_reset_hold(Object *obj, ResetType type)
 {
-    IbexUartState *s = IBEX_UART(dev);
+    IbexUartState *s = IBEX_UART(obj);
 
     s->uart_intr_state = 0x00000000;
     s->uart_intr_state = 0x00000000;
@@ -545,8 +545,9 @@ static void ibex_uart_realize(DeviceState *dev, Error **errp)
 static void ibex_uart_class_init(ObjectClass *klass, const void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
 
-    device_class_set_legacy_reset(dc, ibex_uart_reset);
+    rc->phases.hold = ibex_uart_reset_hold;
     dc->realize = ibex_uart_realize;
     dc->vmsd = &vmstate_ibex_uart;
     device_class_set_props(dc, ibex_uart_properties);
Signature · 1 line
2.53.0
#9 lore raw

PATCH 9/10 hw/char/imx_serial: Convert to Resettable interface

In reply to Oscar Alejandro Sánchez Lucero

Replace the deprecated device_class_set_legacy_reset() with the Resettable interface by implementing the hold phase in imx_serial_reset_at_boot_hold().

---
 hw/char/imx_serial.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/char/imx_serial.c +4 -3
index 8780678..9a82356 100644
@@ -167,9 +167,9 @@ static void imx_serial_reset(IMXSerialState *s)
     timer_del(&s->ageing_timer);
 }
 
-static void imx_serial_reset_at_boot(DeviceState *dev)
+static void imx_serial_reset_at_boot_hold(Object *obj, ResetType type)
 {
-    IMXSerialState *s = IMX_SERIAL(dev);
+    IMXSerialState *s = IMX_SERIAL(obj);
 
     imx_serial_reset(s);
 
@@ -471,10 +471,11 @@ static const Property imx_serial_properties[] = {
 static void imx_serial_class_init(ObjectClass *klass, const void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
 
     dc->realize = imx_serial_realize;
     dc->vmsd = &vmstate_imx_serial;
-    device_class_set_legacy_reset(dc, imx_serial_reset_at_boot);
+    rc->phases.hold = imx_serial_reset_at_boot_hold;
     set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
     dc->desc = "i.MX series UART";
     device_class_set_props(dc, imx_serial_properties);
Signature · 1 line
2.53.0
#10 lore raw

PATCH 10/10 hw/char/mcf_uart: Convert to Resettable interface

In reply to Oscar Alejandro Sánchez Lucero

Replace the deprecated device_class_set_legacy_reset() with the Resettable interface by implementing the hold phase in mcf_uart_reset_hold().

---
 hw/char/mcf_uart.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
hw/char/mcf_uart.c +4 -3
index 24fd42d..404200c 100644
@@ -232,9 +232,9 @@ void mcf_uart_write(void *opaque, hwaddr addr,
     mcf_uart_update(s);
 }
 
-static void mcf_uart_reset(DeviceState *dev)
+static void mcf_uart_reset_hold(Object *obj, ResetType type)
 {
-    mcf_uart_state *s = MCF_UART(dev);
+    mcf_uart_state *s = MCF_UART(obj);
 
     s->fifo_len = 0;
     s->mr[0] = 0;
@@ -325,9 +325,10 @@ static const Property mcf_uart_properties[] = {
 static void mcf_uart_class_init(ObjectClass *oc, const void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(oc);
+    ResettableClass *rc = RESETTABLE_CLASS(oc);
 
     dc->realize = mcf_uart_realize;
-    device_class_set_legacy_reset(dc, mcf_uart_reset);
+    rc->phases.hold = mcf_uart_reset_hold;
     device_class_set_props(dc, mcf_uart_properties);
     set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
 }
Signature · 1 line
2.53.0