Skip to contentSkip to conversation

hw/char/serial: Migrate I/O serial device

PATCH In review Philippe Mathieu-Daudé 4 participants 8 messages Jul 3, 2020 – Jul 10, 2020

lore
Share & tools
lore
#0 lore raw

cover hw/char/serial: Migrate I/O serial device

We migrate the memory mapped device, but not the I/O one. No particular reason, so let it be migratable.

Philippe Mathieu-Daudé (2):
hw/char/serial: Separate and document static properties hw/char/serial: Allow migration of the I/O serial device

 include/hw/char/serial.h |  7 +++++--
 hw/char/serial.c         | 12 +++++++++++-
 2 files changed, 16 insertions(+), 3 deletions(-)
Signature · 1 line
2.21.3
#1 lore raw

PATCH 1/2 hw/char/serial: Separate and document static properties

Add more descriptive comments to keep a clear separation between static property vs runtime changeable.

---
 include/hw/char/serial.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
include/hw/char/serial.h +5 -2
index 535fa23a2b..d955963ef1 100644
@@ -55,9 +55,7 @@ typedef struct SerialState {
        it can be reset while reading iir */
     int thr_ipending;
     qemu_irq irq;
-    CharBackend chr;
     int last_break_enable;
-    uint32_t baudbase;
     uint32_t tsr_retry;
     guint watch_tag;
     uint32_t wakeup;
@@ -77,6 +75,10 @@ typedef struct SerialState {
 
     QEMUTimer *modem_status_poll;
     MemoryRegion io;
+
+    /* Properties */
+    CharBackend chr;
+    uint32_t baudbase;
 } SerialState;
 
 typedef struct SerialMM {
@@ -84,6 +86,7 @@ typedef struct SerialMM {
 
     SerialState serial;
 
+    /* Properties */
     uint8_t regshift;
     uint8_t endianness;
 } SerialMM;
Signature · 1 line
2.21.3
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] hw/char/serial: Separate and document static properties

Quoted 35 lines · Philippe Mathieu-Daudé

Add more descriptive comments to keep a clear separation between static property vs runtime changeable.

---
 include/hw/char/serial.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
include/hw/char/serial.h +4 -2
index 535fa23a2b..d955963ef1 100644
@@ -55,9 +55,7 @@ typedef struct SerialState {
        it can be reset while reading iir */
     int thr_ipending;
     qemu_irq irq;
-    CharBackend chr;
     int last_break_enable;
-    uint32_t baudbase;
     uint32_t tsr_retry;
     guint watch_tag;
     uint32_t wakeup;
@@ -77,6 +75,10 @@ typedef struct SerialState {
 
     QEMUTimer *modem_status_poll;
     MemoryRegion io;
+
+    /* Properties */
+    CharBackend chr;
+    uint32_t baudbase;
 } SerialState;
 
 typedef struct SerialMM {

include/hw/char/serial.h typedef struct SerialMM { · line 92

Quoted 7 lines
include/hw/char/serial.h +1 -0
@@ -84,6 +86,7 @@ typedef struct SerialMM {
 
     SerialState serial;
 
+    /* Properties */
     uint8_t regshift;
     uint8_t endianness;
 } SerialMM;

Incidentally 'baudbase' is technically runtime updateable via the serial_set_frequency() function, except that there are no callers of it. We should delete that as unused code.

thanks
-- PMM

#4 lore raw

PATCH 2/2 hw/char/serial: Allow migration of the I/O serial device

In reply to Philippe Mathieu-Daudé

The serial device mapped on the I/O bus hold a migratable SerialState. Keep the same version range from SerialState:

837 const VMStateDescription vmstate_serial = {

 838     .name = "serial",
 839     .version_id = 3,
 840     .minimum_version_id = 2,
Fixes 10315a7089 ("serial: make SerialIO a sysbus device")
---
 hw/char/serial.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
hw/char/serial.c +11 -1
index 9eebcb27e7..c167b584fb 100644
@@ -1002,12 +1002,22 @@ static void serial_io_realize(DeviceState *dev, Error **errp)
     sysbus_init_irq(SYS_BUS_DEVICE(sio), &s->irq);
 }
 
+static const VMStateDescription vmstate_serial_io = {
+    .name = "serial",
+    .version_id = 3,
+    .minimum_version_id = 2,
+    .fields = (VMStateField[]) {
+        VMSTATE_STRUCT(serial, SerialIO, 0, vmstate_serial, SerialState),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 static void serial_io_class_init(ObjectClass *klass, void* data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
 
     dc->realize = serial_io_realize;
-    /* No dc->vmsd: class has no migratable state */
+    dc->vmsd = &vmstate_serial_io;
 }
 
 static void serial_io_instance_init(Object *o)
Signature · 1 line
2.21.3
#5 lore raw

Re: [PATCH 2/2] hw/char/serial: Allow migration of the I/O serial device

Quoted 33 lines · Philippe Mathieu-Daudé

The serial device mapped on the I/O bus hold a migratable SerialState. Keep the same version range from SerialState:

837 const VMStateDescription vmstate_serial = {

 838     .name = "serial",
 839     .version_id = 3,
 840     .minimum_version_id = 2,
Fixes 10315a7089 ("serial: make SerialIO a sysbus device")
---
 hw/char/serial.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
hw/char/serial.c +10 -0
index 9eebcb27e7..c167b584fb 100644
@@ -1002,12 +1002,22 @@ static void serial_io_realize(DeviceState *dev, Error **errp)
     sysbus_init_irq(SYS_BUS_DEVICE(sio), &s->irq);
 }
 
+static const VMStateDescription vmstate_serial_io = {
+    .name = "serial",
+    .version_id = 3,
+    .minimum_version_id = 2,
+    .fields = (VMStateField[]) {
+        VMSTATE_STRUCT(serial, SerialIO, 0, vmstate_serial, SerialState),
+        VMSTATE_END_OF_LIST()
+    }
+};
+

hw/char/serial.c static void serial_io_realize(DeviceState *dev, Error **errp) · line 1023

Quoted 10 lines
hw/char/serial.c +1 -1
 static void serial_io_class_init(ObjectClass *klass, void* data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
 
     dc->realize = serial_io_realize;
-    /* No dc->vmsd: class has no migratable state */
+    dc->vmsd = &vmstate_serial_io;
 }
 
 static void serial_io_instance_init(Object *o)

Is there any difference between SerialMM and SerialIO at this point?

Paolo

#6 lore raw

Re: [PATCH 2/2] hw/char/serial: Allow migration of the I/O serial device

Quoted 43 lines · Paolo Bonzini
Quoted 41 lines · Philippe Mathieu-Daudé

The serial device mapped on the I/O bus hold a migratable SerialState. Keep the same version range from SerialState:

837 const VMStateDescription vmstate_serial = {

 838     .name = "serial",
 839     .version_id = 3,
 840     .minimum_version_id = 2,
Fixes 10315a7089 ("serial: make SerialIO a sysbus device")
---
 hw/char/serial.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
hw/char/serial.c +11 -1
index 9eebcb27e7..c167b584fb 100644
@@ -1002,12 +1002,22 @@ static void serial_io_realize(DeviceState *dev, Error **errp)
     sysbus_init_irq(SYS_BUS_DEVICE(sio), &s->irq);
 }
 
+static const VMStateDescription vmstate_serial_io = {
+    .name = "serial",
+    .version_id = 3,
+    .minimum_version_id = 2,
+    .fields = (VMStateField[]) {
+        VMSTATE_STRUCT(serial, SerialIO, 0, vmstate_serial, SerialState),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 static void serial_io_class_init(ObjectClass *klass, void* data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
 
     dc->realize = serial_io_realize;
-    /* No dc->vmsd: class has no migratable state */
+    dc->vmsd = &vmstate_serial_io;
 }
 
Quoted 4 lines

hw/char/serial.c static void serial_io_realize(DeviceState *dev, Error **errp) · line 1023

Quoted 2 lines
hw/char/serial.c +0 -0
 static void serial_io_instance_init(Object *o)

Is there any difference between SerialMM and SerialIO at this point?

SerialIO insists on 1-byte wide accesses; SerialMM allows the creator of the device to specify the spacing between registers and the endianness. So I suppose SerialIO is kind of a subset of SerialMM.

It looks like the only user of TYPE_SERIAL_IO is hw/mips/mipssim.c, Adding the migration state here would be a forwards migration compat break anyway, so I think we could just change that machine to use TYPE_SERIAL_MM and then delete TYPE_SERIAL_IO ?

thanks
-- PMM

Reviewed-by on v1 2/2
#7 lore raw

Re: [PATCH 2/2] hw/char/serial: Allow migration of the I/O serial device

In reply to Philippe Mathieu-Daudé
Quoted 10 lines · Philippe Mathieu-Daudé

The serial device mapped on the I/O bus hold a migratable SerialState. Keep the same version range from SerialState:

837 const VMStateDescription vmstate_serial = {

 838     .name = "serial",
 839     .version_id = 3,
 840     .minimum_version_id = 2,
Fixes 10315a7089 ("serial: make SerialIO a sysbus device")

In the sense that the vmstate stuff is correct.

But as Peter says, it appears that it is better to just drop the whole serial_io infrastructure if we can switch the mips simulator implementation to use mm, no?

Later, Juan.