Skip to contentSkip to conversation

integrate more device handling bits with qdev.

PATCH In review Gerd Hoffmann 2 participants 8 messages Sep 1, 2009 – Sep 2, 2009 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

cover integrate more device handling bits with qdev.

Hi,

Short patch series to outline how qdev can help us to reduce the number of register_foo() calls in drivers. This is part one of the plan: move register_foo() calls to qdev code.

Once all drivers are converted to qdev we maybe can do step two: Make todays users of the callback lists (qemu_system_reset for example) walk the qdev tree to find all reset handlers and drop the callback lists.

cheers,
Gerd

#1 lore raw

PATCH 1/4 qdev: integrate reset

---
 hw/qdev.c |   11 ++++++++++-
 hw/qdev.h |    3 +++
 2 files changed, 13 insertions(+), 1 deletions(-)
hw/qdev.c +10 -1
index ff2f096..e045968 100644
@@ -211,12 +211,21 @@ DeviceState *qdev_device_add(QemuOpts *opts)
    calling this function.  */
 int qdev_init(DeviceState *dev)
 {
-    return dev->info->init(dev, dev->info);
+    int rc;
+
+    rc = dev->info->init(dev, dev->info);
+    if (rc < 0)
+        return rc;
+    if (dev->info->reset)
+        qemu_register_reset(dev->info->reset, dev);
+    return 0;
 }
 
 /* Unlink device from bus and free the structure.  */
 void qdev_free(DeviceState *dev)
 {
+    if (dev->info->reset)
+        qemu_unregister_reset(dev->info->reset, dev);
     LIST_REMOVE(dev, sibling);
     qemu_free(dev);
 }
hw/qdev.h +3 -0
index af735d7..fde29ea 100644
@@ -110,6 +110,9 @@ struct DeviceInfo {
     Property *props;
     int no_user;
 
+    /* callbacks */
+    QEMUResetHandler *reset;
+
     /* Private to qdev / bus.  */
     qdev_initfn init;
     BusInfo *bus_info;
Signature · 1 line
1.6.2.5
#2 lore raw

Re: [Qemu-devel] [PATCH 1/4] qdev: integrate reset

hw/qdev.h struct DeviceInfo { · line 115

Quoted 7 lines · Gerd Hoffmann
hw/qdev.h +3 -0
@@ -110,6 +110,9 @@ struct DeviceInfo {
     Property *props;
     int no_user;
 
+    /* callbacks */
+    QEMUResetHandler *reset;
+

This would remove the need for registration but I had in my mind a bit more complex solution like VMState structures. Even better, VMState could be enhanced so that the reset value of the fields could be specified (when not zero).

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

[Qemu-devel] Re: [PATCH 1/4] qdev: integrate reset

Quoted 16 lines · Juan Quintela
Quoted 6 lines · Blue Swirl
Quoted 4 lines · Gerd Hoffmann
hw/qdev.h +0 -0
@@ -110,6 +110,9 @@ struct DeviceInfo {
     Property *props;
     int no_user;
 
Quoted 8 lines

hw/qdev.h struct DeviceInfo { · line 115

Quoted 3 lines
hw/qdev.h +3 -0
+    /* callbacks */
+    QEMUResetHandler *reset;
+

This would remove the need for registration but I had in my mind a bit more complex solution like VMState structures. Even better, VMState could be enhanced so that the reset value of the fields could be specified (when not zero).

Quoted 2 lines

That soonds nice, but ... not every field in the structures are used during migration.  Do we want to merge both things?

New flags that tell whether a VMState field is used for savevm or reset?

#5 lore raw

Re: [Qemu-devel] [PATCH 1/4] qdev: integrate reset

In reply to Blue Swirl
Quoted 6 lines · Blue Swirl
Quoted 4 lines · Gerd Hoffmann
hw/qdev.h +0 -0
@@ -110,6 +110,9 @@ struct DeviceInfo {
     Property *props;
     int no_user;
 
Quoted 8 lines

hw/qdev.h struct DeviceInfo { · line 115

Quoted 3 lines
hw/qdev.h +3 -0
+    /* callbacks */
+    QEMUResetHandler *reset;
+

This would remove the need for registration but I had in my mind a bit more complex solution like VMState structures. Even better, VMState could be enhanced so that the reset value of the fields could be specified (when not zero).

Interesting idea. Could work out pretty nicely. Chances are that the overlap of the fields which must be initialized on reset and which must be saved on migration is pretty high. If so the integration into vmstate would indeed make alot of sense.

cheers,
Gerd

#6 lore raw

PATCH 2/4 qdev: convert rtl8139 to reset

In reply to Gerd Hoffmann
---
 hw/rtl8139.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
hw/rtl8139.c +4 -4
index b3542a3..3bd72e5 100644
@@ -3465,7 +3465,6 @@ static int pci_rtl8139_init(PCIDevice *dev)
                            PCI_ADDRESS_SPACE_MEM, rtl8139_mmio_map);
 
     qdev_get_macaddr(&dev->qdev, s->macaddr);
-    qemu_register_reset(rtl8139_reset, s);
     rtl8139_reset(s);
     s->vc = qdev_get_vlan_client(&dev->qdev,
                                  rtl8139_can_receive, rtl8139_receive, NULL,
@@ -3489,9 +3488,10 @@ static int pci_rtl8139_init(PCIDevice *dev)
 }
 
 static PCIDeviceInfo rtl8139_info = {
-    .qdev.name = "rtl8139",
-    .qdev.size = sizeof(RTL8139State),
-    .init      = pci_rtl8139_init,
+    .qdev.name  = "rtl8139",
+    .qdev.size  = sizeof(RTL8139State),
+    .qdev.reset = rtl8139_reset,
+    .init       = pci_rtl8139_init,
 };
 
 static void rtl8139_register_devices(void)
Signature · 1 line
1.6.2.5
#7 lore raw

PATCH 3/4 qdev: integrate vmstate

In reply to Gerd Hoffmann
---
 hw/qdev.c |    6 ++++++
 hw/qdev.h |    3 +++
 2 files changed, 9 insertions(+), 0 deletions(-)
hw/qdev.c +6 -0
index e045968..288f95b 100644
@@ -218,12 +218,18 @@ int qdev_init(DeviceState *dev)
         return rc;
     if (dev->info->reset)
         qemu_register_reset(dev->info->reset, dev);
+    if (dev->info->vmsd)
+        vmstate_register(-1, dev->info->vmsd, dev);
     return 0;
 }
 
 /* Unlink device from bus and free the structure.  */
 void qdev_free(DeviceState *dev)
 {
+#if 0 /* FIXME: need sane vmstate_unregister function */
+    if (dev->info->vmsd)
+        vmstate_unregister(dev->info->vmsd, dev);
+#endif
     if (dev->info->reset)
         qemu_unregister_reset(dev->info->reset, dev);
     LIST_REMOVE(dev, sibling);
hw/qdev.h +3 -0
index fde29ea..103489d 100644
@@ -113,6 +113,9 @@ struct DeviceInfo {
     /* callbacks */
     QEMUResetHandler *reset;
 
+    /* device state */
+    const VMStateDescription *vmsd;
+
     /* Private to qdev / bus.  */
     qdev_initfn init;
     BusInfo *bus_info;
Signature · 1 line
1.6.2.5
#8 lore raw

PATCH 4/4 qdev: convert tcx to reset + vmsd

In reply to Gerd Hoffmann
---
 hw/tcx.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
hw/tcx.c +2 -2
index d1e5851..9996219 100644
@@ -560,8 +560,6 @@ static int tcx_init1(SysBusDevice *dev)
                                      tcx_screen_dump, NULL, s);
     }
 
-    vmstate_register(-1, &vmstate_tcx, s);
-    qemu_register_reset(tcx_reset, s);
     tcx_reset(s);
     qemu_console_resize(s->ds, s->width, s->height);
     return 0;
@@ -634,6 +632,8 @@ static SysBusDeviceInfo tcx_info = {
     .init = tcx_init1,
     .qdev.name  = "SUNW,tcx",
     .qdev.size  = sizeof(TCXState),
+    .qdev.reset = tcx_reset,
+    .qdev.vmsd  = &vmstate_tcx,
     .qdev.props = (Property[]) {
         DEFINE_PROP_TADDR("addr",      TCXState, addr,      -1),
         DEFINE_PROP_HEX32("vram_size", TCXState, vram_size, -1),
Signature · 1 line
1.6.2.5