Skip to contentSkip to conversation

QOM realize, device-only plus ISA conversion

RFC In review Andreas Färber 4 participants 46 messages Nov 26, 2012 – Apr 22, 2013

lore
Share & tools
lore
#0 lore raw

cover QOM realize, device-only plus ISA conversion

Hello Anthony and Paolo,

As announced at KVM Forum, I have been preparing a new approach to incrementally get us Anthony's QOM realizefn concept. A previous attempt by Paolo and me had been turned down for making this available at Object-level and over questions whether BlockDriverState may need its own three-stage realization model.

So here's an all-new patchset doing it at DeviceState-level only, adapting the signature to void realize(DeviceState *, Error **).
CPUState is on a good way to get derived from DeviceState, so in the future will benefit from this approach as well.

I've picked ISADevice as an example to showcase what semantic effects the switch to QOM realizefn has (in the hopes the number of devices would be small):
As requested by Anthony for QOM CPUState reset and as seen with virtual methods in object-oriented programming languages, it becomes the derived method's responsibility to decide when and whether to call the parent class' method. In lack of real vtables this requires to save the parent's method in case we want to call it; classes and matching macros may need to be added for that. Another point to note is that we should carefully distinguish what goes into the qdev initfn / QOM realizefn and what can already go into a QOM initfn.

This series is rebased onto Julien's ioport cleanups (touching on ISA devices).

It starts by preparing the "realized" property, wrapping qdev's initfn (04). This means setting realized to true will not yet affect its children, as seen in Paolo's previous patches. That can be implemented later when the realizefns have been reviewed not to create new devices that would mess with recursive child realization. (In the previous series we had recursive realization but on my request dropped the hook-up of qdev due to the aforementioned quirks.)

At that point there is a coexistence of QOM device realizefn and qdev initfn. For the first time now I have set out to actually eliminate some qdev initfns, that's what I chose ISA for. This consists of three parts, introducing realizefns for ISADevices (28) and recursively for PITs (31) and for PICs (34). As seen for the PCI host bridge series, I've extracted general QOM cleanups from the main conversion patch to arrive at a clean QOM'ish state while hopefully keeping the main patches readable.

This series also highlights an interesting find: Beyond the to-be-solved CPUState, there is also a "realize" function for BusState (02), which is not derived from DeviceState. :-)
With the device-centric approach taken here it would still be possible to add "realized" properties to other types using their own infrastructure (e.g., a hardcoded setter rather than a realizefn hook).

Posted as an RFC to encourage bikeshedding, in particular about the type names and macros introduced. Adding new header files to move them out of the source files for, e.g., vl.c is left for a follow-up, but for instance I was unsure about TYPE_ISA_FDC (should this be TYPE_ISA_FLOPPY_DRIVE_CONTROLLER as with PCI_HOST_BRIDGE rather than PHB?), and naming of type names and functions is highly inconsistent (e.g., isa_vga vs. vga_isa, or pic vs. i8259).

Available for viewing/testing at:
https://github.com/afaerber/qemu-cpu/commits/realize-qdev
git://github.com/afaerber/qemu-cpu.git realize-qdev

Regards,
Andreas

Cc Anthony Liguori <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Julien Grall <[email protected]>
Cc Frederic Konrad <[email protected]>
Cc Peter Maydell <[email protected]>
Cc Cornelia Huck <[email protected]>
Cc Kevin Wolf <[email protected]>
Cc Stefan Hajnoczi <[email protected]>
Cc Markus Armbruster <[email protected]>
Cc Eduardo Habkost <[email protected]>
Cc Igor Mammedov <[email protected]>

Andreas Färber (34):
qdev: Eliminate qdev_free() in favor of QOM
qbus: QOM'ify qbus_realize()
qdev: Fold state enum into bool realized
qdev: Prepare "realized" property
isa: Split off instance_init for ISADevice
applesmc: QOM'ify
cirrus_vga: QOM'ify ISA Cirrus VGA
debugcon: QOM'ify ISA debug console
fdc: QOM'ify ISA floppy controller
i82374: QOM'ify
i8259: Fix PIC_COMMON() macro
i8259: QOM cleanups
ide: QOM'ify ISA IDE
m48t59: QOM'ify ISA M48T59 NVRAM
mc146818rtc: QOM'ify
ne2000-isa: QOM'ify
parallel: QOM'ify
pc: QOM'ify port 92
pckbd: QOM'ify
pcspk: QOM'ify
sb16: QOM'ify
serial: QOM'ify ISA serial
sga: QOM'ify
vga-isa: QOM'ify ISA VGA
vmmouse: QOM'ify
vmport: QOM'ify
wdt_ib700: QOM'ify
isa: Use realizefn for ISADevice
i8254: QOM'ify
kvm/i8254: QOM'ify some more
i8254: Convert PITCommonState to QOM realizefn
i8259: QOM'ify some more
kvm/i8259: QOM'ify some more
i8259: Convert PICCommonState to use QOM realizefn

 hw/acpi_piix4.c      |    2 +-
 hw/applesmc.c        |   45 +++++++++---------
 hw/cirrus_vga.c      |   27 ++++++-----
 hw/debugcon.c        |   34 +++++++++-----
 hw/fdc.c             |   45 ++++++++++--------
 hw/fdc.h             |    2 +
 hw/i82374.c          |   25 +++++-----
 hw/i8254.c           |   26 +++++++---
 hw/i8254.h           |    7 ++-
 hw/i8254_common.c    |   19 ++------
 hw/i8254_internal.h  |    1 -
 hw/i8259.c           |   64 +++++++++++++++++--------
 hw/i8259_common.c    |   20 +++-----
 hw/i8259_internal.h  |    7 +--
 hw/ide/isa.c         |   55 +++++++++++++---------
 hw/isa-bus.c         |   15 ++----
 hw/isa.h             |    1 -
 hw/kvm/i8254.c       |   59 +++++++++++++++--------
 hw/kvm/i8259.c       |   38 ++++++++++++---
 hw/m48t59.c          |   54 +++++++++++----------
 hw/mc146818rtc.c     |   56 ++++++++++++----------
 hw/mc146818rtc.h     |    2 +
 hw/ne2000-isa.c      |   27 ++++++-----
 hw/parallel.c        |   42 ++++++++++-------
 hw/pc.c              |   26 +++++-----
 hw/pc_piix.c         |    2 +-
 hw/pci-hotplug.c     |    2 +-
 hw/pci_bridge.c      |    2 +-
 hw/pcie.c            |    2 +-
 hw/pckbd.c           |   34 ++++++++------
 hw/pcspk.c           |   21 +++++----
 hw/pcspk.h           |    4 +-
 hw/qdev-addr.c       |    2 +-
 hw/qdev-core.h       |   12 ++---
 hw/qdev-monitor.c    |    2 +-
 hw/qdev-properties.c |   28 +++++------
 hw/qdev.c            |  128 ++++++++++++++++++++++++++++++++++----------------
 hw/sb16.c            |   35 +++++++++-----
 hw/scsi-bus.c        |    4 +-
 hw/serial-isa.c      |   33 +++++++------
 hw/serial-pci.c      |    4 +-
 hw/serial.c          |    6 +--
 hw/serial.h          |    3 +-
 hw/sga.c             |   19 ++++----
 hw/shpc.c            |    2 +-
 hw/usb/bus.c         |    7 +--
 hw/usb/dev-storage.c |    2 +-
 hw/usb/host-linux.c  |    2 +-
 hw/vga-isa.c         |   46 +++++++++---------
 hw/vmmouse.c         |   24 +++++-----
 hw/vmport.c          |   24 ++++++----
 hw/wdt_ib700.c       |   22 +++++----
 hw/xen_platform.c    |    2 +-

53 Dateien geändert, 692 Zeilen hinzugefügt(+), 481 Zeilen entfernt(-)

Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/34 qdev: Eliminate qdev_free() in favor of QOM

qdev_free() was trivially wrapping object_delete(). Inline it and drop the wrapper as a further step to QOM'ify qdev.

---
 hw/acpi_piix4.c      |    2 +-
 hw/pci-hotplug.c     |    2 +-
 hw/pci_bridge.c      |    2 +-
 hw/pcie.c            |    2 +-
 hw/qdev-core.h       |    1 -
 hw/qdev-monitor.c    |    2 +-
 hw/qdev.c            |   12 +++---------
 hw/scsi-bus.c        |    4 ++--
 hw/shpc.c            |    2 +-
 hw/usb/bus.c         |    7 ++++---
 hw/usb/dev-storage.c |    2 +-
 hw/usb/host-linux.c  |    2 +-
 hw/xen_platform.c    |    2 +-

13 Dateien geändert, 18 Zeilen hinzugefügt(+), 24 Zeilen entfernt(-)

hw/acpi_piix4.c +1 -1
index 0fa4c98..e6d09be 100644
@@ -361,7 +361,7 @@ static void acpi_piix_eject_slot(PIIX4PMState *s, unsigned slots)
             if (pc->no_hotplug) {
                 slot_free = false;
             } else {
-                qdev_free(qdev);
+                object_delete(OBJECT(qdev));
             }
         }
     }
hw/pci-hotplug.c +1 -1
index e7fb780..d766eab 100644
@@ -204,7 +204,7 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
         }
         dev = pci_create(bus, devfn, "virtio-blk-pci");
         if (qdev_prop_set_drive(&dev->qdev, "drive", dinfo->bdrv) < 0) {
-            qdev_free(&dev->qdev);
+            object_delete(OBJECT(dev));
             dev = NULL;
             break;
         }
hw/pci_bridge.c +1 -1
index 4680501..3689502 100644
@@ -347,7 +347,7 @@ void pci_bridge_exitfn(PCIDevice *pci_dev)
     pci_bridge_region_cleanup(s, s->windows);
     memory_region_destroy(&s->address_space_mem);
     memory_region_destroy(&s->address_space_io);
-    /* qbus_free() is called automatically by qdev_free() */
+    /* qbus_free() is called automatically by object_delete() */
 }
 
 /*
hw/pcie.c +1 -1
index 7c92f19..24bfc95 100644
@@ -235,7 +235,7 @@ static int pcie_cap_slot_hotplug(DeviceState *qdev,
                                    PCI_EXP_SLTSTA_PDS);
         pcie_cap_slot_event(d, PCI_EXP_HP_EV_PDC);
     } else {
-        qdev_free(&pci_dev->qdev);
+        object_delete(OBJECT(pci_dev));
         pci_word_test_and_clear_mask(exp_cap + PCI_EXP_SLTSTA,
                                      PCI_EXP_SLTSTA_PDS);
         pcie_cap_slot_event(d, PCI_EXP_HP_EV_PDC);
hw/qdev-core.h +0 -1
index fce9e22..36191e9 100644
@@ -158,7 +158,6 @@ void qdev_init_nofail(DeviceState *dev);
 void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
                                  int required_for_version);
 void qdev_unplug(DeviceState *dev, Error **errp);
-void qdev_free(DeviceState *dev);
 int qdev_simple_unplug_cb(DeviceState *dev);
 void qdev_machine_creation_done(void);
 bool qdev_machine_modified(void);
hw/qdev-monitor.c +1 -1
index 479eecd..d534b9d 100644
@@ -466,7 +466,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
         qdev->id = id;
     }
     if (qemu_opt_foreach(opts, set_property, qdev, 1) != 0) {
-        qdev_free(qdev);
+        object_delete(OBJECT(qdev));
         return NULL;
     }
     if (qdev->id) {
hw/qdev.c +3 -9
index 7ddcd24..c2d9b48 100644
@@ -154,7 +154,7 @@ int qdev_init(DeviceState *dev)
 
     rc = dc->init(dev);
     if (rc < 0) {
-        qdev_free(dev);
+        object_delete(OBJECT(dev));
         return rc;
     }
 
@@ -237,7 +237,7 @@ void qbus_reset_all_fn(void *opaque)
 int qdev_simple_unplug_cb(DeviceState *dev)
 {
     /* just zap it */
-    qdev_free(dev);
+    object_delete(OBJECT(dev));
     return 0;
 }
 
@@ -259,12 +259,6 @@ void qdev_init_nofail(DeviceState *dev)
     }
 }
 
-/* Unlink device from bus and free the structure.  */
-void qdev_free(DeviceState *dev)
-{
-    object_delete(OBJECT(dev));
-}
-
 void qdev_machine_creation_done(void)
 {
     /*
@@ -765,7 +759,7 @@ static void qbus_finalize(Object *obj)
 
     while ((kid = QTAILQ_FIRST(&bus->children)) != NULL) {
         DeviceState *dev = kid->child;
-        qdev_free(dev);
+        object_delete(OBJECT(dev));
     }
     if (bus->parent) {
         QLIST_REMOVE(bus, sibling);
hw/scsi-bus.c +2 -2
index dfb2631..68a27eb 100644
@@ -175,7 +175,7 @@ static int scsi_qdev_init(DeviceState *qdev)
         d = scsi_device_find(bus, dev->channel, dev->id, dev->lun);
         assert(d);
         if (d->lun == dev->lun && dev != d) {
-            qdev_free(&d->qdev);
+            object_delete(OBJECT(d));
         }
     }
 
@@ -222,7 +222,7 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
         qdev_prop_set_bit(dev, "removable", removable);
     }
     if (qdev_prop_set_drive(dev, "drive", bdrv) < 0) {
-        qdev_free(dev);
+        object_delete(OBJECT(dev));
         return NULL;
     }
     if (qdev_init(dev) < 0)
hw/shpc.c +1 -1
index 4597bbd..24bdfb8 100644
@@ -253,7 +253,7 @@ static void shpc_free_devices_in_slot(SHPCDevice *shpc, int slot)
          ++devfn) {
         PCIDevice *affected_dev = shpc->sec_bus->devices[devfn];
         if (affected_dev) {
-            qdev_free(&affected_dev->qdev);
+            object_delete(OBJECT(affected_dev));
         }
     }
 }
hw/usb/bus.c +4 -3
index 99aac7a..1675798 100644
@@ -337,8 +337,9 @@ void usb_port_location(USBPort *downstream, USBPort *upstream, int portnr)
 
 void usb_unregister_port(USBBus *bus, USBPort *port)
 {
-    if (port->dev)
-        qdev_free(&port->dev->qdev);
+    if (port->dev) {
+        object_delete(OBJECT(port->dev));
+    }
     QTAILQ_REMOVE(&bus->free, port, next);
     bus->nfree--;
 }
@@ -458,7 +459,7 @@ int usb_device_delete_addr(int busnr, int addr)
         return -1;
     dev = port->dev;
 
-    qdev_free(&dev->qdev);
+    object_delete(OBJECT(dev));
     return 0;
 }
 
hw/usb/dev-storage.c +1 -1
index 50af971..2efb4d5 100644
@@ -664,7 +664,7 @@ static USBDevice *usb_msd_init(USBBus *bus, const char *filename)
         return NULL;
     }
     if (qdev_prop_set_drive(&dev->qdev, "drive", dinfo->bdrv) < 0) {
-        qdev_free(&dev->qdev);
+        object_delete(OBJECT(dev));
         return NULL;
     }
     if (qdev_init(&dev->qdev) < 0)
hw/usb/host-linux.c +1 -1
index aa77b77..a0417fc 100644
@@ -1584,7 +1584,7 @@ USBDevice *usb_host_device_open(USBBus *bus, const char *devname)
     return dev;
 
 fail:
-    qdev_free(&dev->qdev);
+    object_delete(OBJECT(dev));
     return NULL;
 }
 
hw/xen_platform.c +1 -1
index a54e7a2..d56f3e5 100644
@@ -89,7 +89,7 @@ static void unplug_nic(PCIBus *b, PCIDevice *d, void *o)
     if (pci_get_word(d->config + PCI_CLASS_DEVICE) ==
             PCI_CLASS_NETWORK_ETHERNET
             && strcmp(d->name, "xen-pci-passthrough") != 0) {
-        qdev_free(&d->qdev);
+        object_delete(OBJECT(d));
     }
 }
 
Signature · 7 lines
1.7.10.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#2 lore raw

Re: [Qemu-devel] [PATCH 01/34] qdev: Eliminate qdev_free() in favor of QOM

Il 26/11/2012 01:12, Andreas Färber ha scritto:

Quoted 2 lines

qdev_free() was trivially wrapping object_delete(). Inline it and drop the wrapper as a further step to QOM'ify qdev.

The reference counts of devices and buses are completely disconnected from reality, and that's why object_delete() works.

I'd prefer this patch not to be applied until this is straightened out...

Paolo

Quoted 239 lines
---
 hw/acpi_piix4.c      |    2 +-
 hw/pci-hotplug.c     |    2 +-
 hw/pci_bridge.c      |    2 +-
 hw/pcie.c            |    2 +-
 hw/qdev-core.h       |    1 -
 hw/qdev-monitor.c    |    2 +-
 hw/qdev.c            |   12 +++---------
 hw/scsi-bus.c        |    4 ++--
 hw/shpc.c            |    2 +-
 hw/usb/bus.c         |    7 ++++---
 hw/usb/dev-storage.c |    2 +-
 hw/usb/host-linux.c  |    2 +-
 hw/xen_platform.c    |    2 +-

13 Dateien geändert, 18 Zeilen hinzugefügt(+), 24 Zeilen entfernt(-)

hw/acpi_piix4.c +1 -1
index 0fa4c98..e6d09be 100644
@@ -361,7 +361,7 @@ static void acpi_piix_eject_slot(PIIX4PMState *s, unsigned slots)
             if (pc->no_hotplug) {
                 slot_free = false;
             } else {
-                qdev_free(qdev);
+                object_delete(OBJECT(qdev));
             }
         }
     }
hw/pci-hotplug.c +1 -1
index e7fb780..d766eab 100644
@@ -204,7 +204,7 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
         }
         dev = pci_create(bus, devfn, "virtio-blk-pci");
         if (qdev_prop_set_drive(&dev->qdev, "drive", dinfo->bdrv) < 0) {
-            qdev_free(&dev->qdev);
+            object_delete(OBJECT(dev));
             dev = NULL;
             break;
         }
hw/pci_bridge.c +1 -1
index 4680501..3689502 100644
@@ -347,7 +347,7 @@ void pci_bridge_exitfn(PCIDevice *pci_dev)
     pci_bridge_region_cleanup(s, s->windows);
     memory_region_destroy(&s->address_space_mem);
     memory_region_destroy(&s->address_space_io);
-    /* qbus_free() is called automatically by qdev_free() */
+    /* qbus_free() is called automatically by object_delete() */
 }
 
 /*
hw/pcie.c +1 -1
index 7c92f19..24bfc95 100644
@@ -235,7 +235,7 @@ static int pcie_cap_slot_hotplug(DeviceState *qdev,
                                    PCI_EXP_SLTSTA_PDS);
         pcie_cap_slot_event(d, PCI_EXP_HP_EV_PDC);
     } else {
-        qdev_free(&pci_dev->qdev);
+        object_delete(OBJECT(pci_dev));
         pci_word_test_and_clear_mask(exp_cap + PCI_EXP_SLTSTA,
                                      PCI_EXP_SLTSTA_PDS);
         pcie_cap_slot_event(d, PCI_EXP_HP_EV_PDC);
hw/qdev-core.h +0 -1
index fce9e22..36191e9 100644
@@ -158,7 +158,6 @@ void qdev_init_nofail(DeviceState *dev);
 void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
                                  int required_for_version);
 void qdev_unplug(DeviceState *dev, Error **errp);
-void qdev_free(DeviceState *dev);
 int qdev_simple_unplug_cb(DeviceState *dev);
 void qdev_machine_creation_done(void);
 bool qdev_machine_modified(void);
hw/qdev-monitor.c +1 -1
index 479eecd..d534b9d 100644
@@ -466,7 +466,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
         qdev->id = id;
     }
     if (qemu_opt_foreach(opts, set_property, qdev, 1) != 0) {
-        qdev_free(qdev);
+        object_delete(OBJECT(qdev));
         return NULL;
     }
     if (qdev->id) {
hw/qdev.c +3 -9
index 7ddcd24..c2d9b48 100644
@@ -154,7 +154,7 @@ int qdev_init(DeviceState *dev)
 
     rc = dc->init(dev);
     if (rc < 0) {
-        qdev_free(dev);
+        object_delete(OBJECT(dev));
         return rc;
     }
 
@@ -237,7 +237,7 @@ void qbus_reset_all_fn(void *opaque)
 int qdev_simple_unplug_cb(DeviceState *dev)
 {
     /* just zap it */
-    qdev_free(dev);
+    object_delete(OBJECT(dev));
     return 0;
 }
 
@@ -259,12 +259,6 @@ void qdev_init_nofail(DeviceState *dev)
     }
 }
 
-/* Unlink device from bus and free the structure.  */
-void qdev_free(DeviceState *dev)
-{
-    object_delete(OBJECT(dev));
-}
-
 void qdev_machine_creation_done(void)
 {
     /*
@@ -765,7 +759,7 @@ static void qbus_finalize(Object *obj)
 
     while ((kid = QTAILQ_FIRST(&bus->children)) != NULL) {
         DeviceState *dev = kid->child;
-        qdev_free(dev);
+        object_delete(OBJECT(dev));
     }
     if (bus->parent) {
         QLIST_REMOVE(bus, sibling);
hw/scsi-bus.c +2 -2
index dfb2631..68a27eb 100644
@@ -175,7 +175,7 @@ static int scsi_qdev_init(DeviceState *qdev)
         d = scsi_device_find(bus, dev->channel, dev->id, dev->lun);
         assert(d);
         if (d->lun == dev->lun && dev != d) {
-            qdev_free(&d->qdev);
+            object_delete(OBJECT(d));
         }
     }
 
@@ -222,7 +222,7 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
         qdev_prop_set_bit(dev, "removable", removable);
     }
     if (qdev_prop_set_drive(dev, "drive", bdrv) < 0) {
-        qdev_free(dev);
+        object_delete(OBJECT(dev));
         return NULL;
     }
     if (qdev_init(dev) < 0)
hw/shpc.c +1 -1
index 4597bbd..24bdfb8 100644
@@ -253,7 +253,7 @@ static void shpc_free_devices_in_slot(SHPCDevice *shpc, int slot)
          ++devfn) {
         PCIDevice *affected_dev = shpc->sec_bus->devices[devfn];
         if (affected_dev) {
-            qdev_free(&affected_dev->qdev);
+            object_delete(OBJECT(affected_dev));
         }
     }
 }
hw/usb/bus.c +4 -3
index 99aac7a..1675798 100644
@@ -337,8 +337,9 @@ void usb_port_location(USBPort *downstream, USBPort *upstream, int portnr)
 
 void usb_unregister_port(USBBus *bus, USBPort *port)
 {
-    if (port->dev)
-        qdev_free(&port->dev->qdev);
+    if (port->dev) {
+        object_delete(OBJECT(port->dev));
+    }
     QTAILQ_REMOVE(&bus->free, port, next);
     bus->nfree--;
 }
@@ -458,7 +459,7 @@ int usb_device_delete_addr(int busnr, int addr)
         return -1;
     dev = port->dev;
 
-    qdev_free(&dev->qdev);
+    object_delete(OBJECT(dev));
     return 0;
 }
 
hw/usb/dev-storage.c +1 -1
index 50af971..2efb4d5 100644
@@ -664,7 +664,7 @@ static USBDevice *usb_msd_init(USBBus *bus, const char *filename)
         return NULL;
     }
     if (qdev_prop_set_drive(&dev->qdev, "drive", dinfo->bdrv) < 0) {
-        qdev_free(&dev->qdev);
+        object_delete(OBJECT(dev));
         return NULL;
     }
     if (qdev_init(&dev->qdev) < 0)
hw/usb/host-linux.c +1 -1
index aa77b77..a0417fc 100644
@@ -1584,7 +1584,7 @@ USBDevice *usb_host_device_open(USBBus *bus, const char *devname)
     return dev;
 
 fail:
-    qdev_free(&dev->qdev);
+    object_delete(OBJECT(dev));
     return NULL;
 }
 
hw/xen_platform.c +1 -1
index a54e7a2..d56f3e5 100644
@@ -89,7 +89,7 @@ static void unplug_nic(PCIBus *b, PCIDevice *d, void *o)
     if (pci_get_word(d->config + PCI_CLASS_DEVICE) ==
             PCI_CLASS_NETWORK_ETHERNET
             && strcmp(d->name, "xen-pci-passthrough") != 0) {
-        qdev_free(&d->qdev);
+        object_delete(OBJECT(d));
     }
 }
 
#3 lore raw

Re: [Qemu-devel] [PATCH 01/34] qdev: Eliminate qdev_free() in favor of QOM

Am 26.11.2012 08:20, schrieb Paolo Bonzini:

Quoted 8 lines

Il 26/11/2012 01:12, Andreas Färber ha scritto:

Quoted 2 lines

qdev_free() was trivially wrapping object_delete(). Inline it and drop the wrapper as a further step to QOM'ify qdev.

The reference counts of devices and buses are completely disconnected from reality, and that's why object_delete() works.

I'd prefer this patch not to be applied until this is straightened out...

Your series is marked for-1.3 whereas this is for 1.4, so no obvious problem there - wanted to mention the overlap in the cover letter but apparently forgot.

My quest was to kill obsolete things with old "qdev" in the name. :) I don't really mind if this becomes object_delete() or object_unref() or anything else as long as it's not such a trivial qdev_* wrapper calling one QOM object_* function.

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#4 lore raw

Re: [Qemu-devel] [PATCH 01/34] qdev: Eliminate qdev_free() in favor of QOM

Il 26/11/2012 12:52, Andreas Färber ha scritto:

Quoted 5 lines

Am 26.11.2012 08:20, schrieb Paolo Bonzini:

Quoted 4 lines

Il 26/11/2012 01:12, Andreas Färber ha scritto:

Quoted 2 lines

qdev_free() was trivially wrapping object_delete(). Inline it and drop the wrapper as a further step to QOM'ify qdev.

Quoted 8 lines
Quoted 4 lines

The reference counts of devices and buses are completely disconnected from reality, and that's why object_delete() works.

I'd prefer this patch not to be applied until this is straightened out...

Your series is marked for-1.3 whereas this is for 1.4, so no obvious problem there - wanted to mention the overlap in the cover letter but apparently forgot.

I have a more complete series for 1.4 (needs a bit more testing, but I guess I can send out an RFC). The one I posted for 1.3 is a subset.

Quoted 4 lines

My quest was to kill obsolete things with old "qdev" in the name. :) I don't really mind if this becomes object_delete() or object_unref() or anything else as long as it's not such a trivial qdev_* wrapper calling one QOM object_* function.

Ok, that's fine.

Paolo

#5 lore raw

RFC 2/34 qbus: QOM'ify qbus_realize()

In reply to Andreas Färber

Add the designated Error-reporting argument, even if currently unused.

---
 hw/qdev.c |    6 +++---

1 Datei geändert, 3 Zeilen hinzugefügt(+), 3 Zeilen entfernt(-)

hw/qdev.c +3 -3
index c2d9b48..e7c9493 100644
@@ -397,7 +397,7 @@ DeviceState *qdev_find_recursive(BusState *bus, const char *id)
     return NULL;
 }
 
-static void qbus_realize(BusState *bus)
+static void qbus_realize(BusState *bus, Error **err)
 {
     const char *typename = object_get_typename(OBJECT(bus));
     char *buf;
@@ -440,7 +440,7 @@ void qbus_create_inplace(BusState *bus, const char *typename,
 
     bus->parent = parent;
     bus->name = name ? g_strdup(name) : NULL;
-    qbus_realize(bus);
+    qbus_realize(bus, NULL);
 }
 
 BusState *qbus_create(const char *typename, DeviceState *parent, const char *name)
@@ -452,7 +452,7 @@ BusState *qbus_create(const char *typename, DeviceState *parent, const char *nam
 
     bus->parent = parent;
     bus->name = name ? g_strdup(name) : NULL;
-    qbus_realize(bus);
+    qbus_realize(bus, NULL);
 
     return bus;
 }
Signature · 1 line
1.7.10.4
#6 lore raw

RFC 3/34 qdev: Fold state enum into bool realized

In reply to Andreas Färber

Whether the device was initialized or not is QOM-level information and currently unused. Drop it from qdev. This leaves the boolean state of whether or not DeviceClass::init was called or not, a.k.a. "realized".

---
 hw/qdev-addr.c       |    2 +-
 hw/qdev-core.h       |    7 +------
 hw/qdev-properties.c |   28 ++++++++++++++--------------
 hw/qdev.c            |   12 ++++++------

4 Dateien geändert, 22 Zeilen hinzugefügt(+), 27 Zeilen entfernt(-)

hw/qdev-addr.c +1 -1
index ea32c31..fb95798 100644
@@ -40,7 +40,7 @@ static void set_taddr(Object *obj, Visitor *v, void *opaque,
     Error *local_err = NULL;
     int64_t value;
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (dev->realized) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
hw/qdev-core.h +1 -6
index 36191e9..f0d3a5e 100644
@@ -17,11 +17,6 @@ typedef struct BusState BusState;
 
 typedef struct BusClass BusClass;
 
-enum DevState {
-    DEV_STATE_CREATED = 1,
-    DEV_STATE_INITIALIZED,
-};
-
 enum {
     DEV_NVECTORS_UNSPECIFIED = -1,
 };
@@ -64,7 +59,7 @@ struct DeviceState {
     Object parent_obj;
 
     const char *id;
-    enum DevState state;
+    bool realized;
     QemuOpts *opts;
     int hotplugged;
     BusState *parent_bus;
hw/qdev-properties.c +14 -14
index 81d901c..773547b 100644
@@ -36,7 +36,7 @@ static void set_pointer(Object *obj, Visitor *v, Property *prop,
     char *str;
     int ret;
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (dev->realized) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -74,7 +74,7 @@ static void set_enum(Object *obj, Visitor *v, void *opaque,
     Property *prop = opaque;
     int *ptr = qdev_get_prop_ptr(dev, prop);
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (dev->realized) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -126,7 +126,7 @@ static void set_bit(Object *obj, Visitor *v, void *opaque,
     Error *local_err = NULL;
     bool value;
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (dev->realized) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -166,7 +166,7 @@ static void set_uint8(Object *obj, Visitor *v, void *opaque,
     Property *prop = opaque;
     uint8_t *ptr = qdev_get_prop_ptr(dev, prop);
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (dev->realized) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -233,7 +233,7 @@ static void set_uint16(Object *obj, Visitor *v, void *opaque,
     Property *prop = opaque;
     uint16_t *ptr = qdev_get_prop_ptr(dev, prop);
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (dev->realized) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -266,7 +266,7 @@ static void set_uint32(Object *obj, Visitor *v, void *opaque,
     Property *prop = opaque;
     uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (dev->realized) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -291,7 +291,7 @@ static void set_int32(Object *obj, Visitor *v, void *opaque,
     Property *prop = opaque;
     int32_t *ptr = qdev_get_prop_ptr(dev, prop);
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (dev->realized) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -364,7 +364,7 @@ static void set_uint64(Object *obj, Visitor *v, void *opaque,
     Property *prop = opaque;
     uint64_t *ptr = qdev_get_prop_ptr(dev, prop);
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (dev->realized) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -452,7 +452,7 @@ static void set_string(Object *obj, Visitor *v, void *opaque,
     Error *local_err = NULL;
     char *str;
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (dev->realized) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -666,7 +666,7 @@ static void set_vlan(Object *obj, Visitor *v, void *opaque,
     int32_t id;
     NetClientState *hubport;
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (dev->realized) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -737,7 +737,7 @@ static void set_mac(Object *obj, Visitor *v, void *opaque,
     int i, pos;
     char *str, *p;
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (dev->realized) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -825,7 +825,7 @@ static void set_pci_devfn(Object *obj, Visitor *v, void *opaque,
     Error *local_err = NULL;
     char *str;
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (dev->realized) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -895,7 +895,7 @@ static void set_blocksize(Object *obj, Visitor *v, void *opaque,
     const int64_t min = 512;
     const int64_t max = 32768;
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (dev->realized) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -963,7 +963,7 @@ static void set_pci_host_devaddr(Object *obj, Visitor *v, void *opaque,
     unsigned long dom = 0, bus = 0;
     unsigned int slot = 0, func = 0;
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (dev->realized) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
hw/qdev.c +6 -6
index e7c9493..bce6ad5 100644
@@ -150,7 +150,7 @@ int qdev_init(DeviceState *dev)
     DeviceClass *dc = DEVICE_GET_CLASS(dev);
     int rc;
 
-    assert(dev->state == DEV_STATE_CREATED);
+    assert(!dev->realized);
 
     rc = dc->init(dev);
     if (rc < 0) {
@@ -173,7 +173,7 @@ int qdev_init(DeviceState *dev)
                                        dev->instance_id_alias,
                                        dev->alias_required_for_version);
     }
-    dev->state = DEV_STATE_INITIALIZED;
+    dev->realized = true;
     if (dev->hotplugged) {
         device_reset(dev);
     }
@@ -183,7 +183,7 @@ int qdev_init(DeviceState *dev)
 void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
                                  int required_for_version)
 {
-    assert(dev->state == DEV_STATE_CREATED);
+    assert(!dev->realized);
     dev->instance_id_alias = alias_id;
     dev->alias_required_for_version = required_for_version;
 }
@@ -554,7 +554,7 @@ static void qdev_set_legacy_property(Object *obj, Visitor *v, void *opaque,
     char *ptr = NULL;
     int ret;
 
-    if (dev->state != DEV_STATE_CREATED) {
+    if (dev->realized) {
         error_set(errp, QERR_PERMISSION_DENIED);
         return;
     }
@@ -661,7 +661,7 @@ static void device_initfn(Object *obj)
     }
 
     dev->instance_id_alias = -1;
-    dev->state = DEV_STATE_CREATED;
+    dev->realized = false;
 
     class = object_get_class(OBJECT(dev));
     do {
@@ -684,7 +684,7 @@ static void device_finalize(Object *obj)
     BusState *bus;
     DeviceClass *dc = DEVICE_GET_CLASS(dev);
 
-    if (dev->state == DEV_STATE_INITIALIZED) {
+    if (dev->realized) {
         while (dev->num_child_bus) {
             bus = QLIST_FIRST(&dev->child_bus);
             qbus_free(bus);
Signature · 1 line
1.7.10.4
#7 lore raw

RFC 4/34 qdev: Prepare "realized" property

In reply to Andreas Färber

Based on earlier patches by Paolo and me, introduce the QOM realizefn at device level only, as requested by Anthony.

For now this just wraps the qdev initfn.

---
 hw/qdev-core.h |    4 +++
 hw/qdev.c      |  100 ++++++++++++++++++++++++++++++++++++++++++--------------

2 Dateien geändert, 80 Zeilen hinzugefügt(+), 24 Zeilen entfernt(-)

hw/qdev-core.h +4 -0
index f0d3a5e..580a811 100644
@@ -29,6 +29,8 @@ enum {
 typedef int (*qdev_initfn)(DeviceState *dev);
 typedef int (*qdev_event)(DeviceState *dev);
 typedef void (*qdev_resetfn)(DeviceState *dev);
+typedef void (*DeviceRealize)(DeviceState *dev, Error **err);
+typedef void (*DeviceUnrealize)(DeviceState *dev, Error **err);
 
 struct VMStateDescription;
 
@@ -47,6 +49,8 @@ typedef struct DeviceClass {
     const struct VMStateDescription *vmsd;
 
     /* Private to qdev / bus.  */
+    DeviceRealize realize;
+    DeviceUnrealize unrealize;
     qdev_initfn init;
     qdev_event unplug;
     qdev_event exit;
hw/qdev.c +76 -24

144 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#8 lore raw

Re: [Qemu-devel] [RFC 04/34] qdev: Prepare "realized" property

Quoted 91 lines · Andreas Färber

Based on earlier patches by Paolo and me, introduce the QOM realizefn at device level only, as requested by Anthony.

For now this just wraps the qdev initfn.

---
 hw/qdev-core.h |    4 +++
 hw/qdev.c      |  100 ++++++++++++++++++++++++++++++++++++++++++--------------

2 Dateien geändert, 80 Zeilen hinzugefügt(+), 24 Zeilen entfernt(-)

hw/qdev-core.h +4 -0
index f0d3a5e..580a811 100644
@@ -29,6 +29,8 @@ enum {
 typedef int (*qdev_initfn)(DeviceState *dev);
 typedef int (*qdev_event)(DeviceState *dev);
 typedef void (*qdev_resetfn)(DeviceState *dev);
+typedef void (*DeviceRealize)(DeviceState *dev, Error **err);
+typedef void (*DeviceUnrealize)(DeviceState *dev, Error **err);
 
 struct VMStateDescription;
 
@@ -47,6 +49,8 @@ typedef struct DeviceClass {
     const struct VMStateDescription *vmsd;
 
     /* Private to qdev / bus.  */
+    DeviceRealize realize;
+    DeviceUnrealize unrealize;
     qdev_initfn init;
     qdev_event unplug;
     qdev_event exit;
hw/qdev.c +16 -23
index bce6ad5..d7b6320 100644
@@ -147,37 +147,30 @@ DeviceState *qdev_try_create(BusState *bus, const char *type)
    Return 0 on success.  */
 int qdev_init(DeviceState *dev)
 {
-    DeviceClass *dc = DEVICE_GET_CLASS(dev);
-    int rc;
+    Error *local_err = NULL;
 
     assert(!dev->realized);
 
-    rc = dc->init(dev);
-    if (rc < 0) {
+    object_property_set_bool(OBJECT(dev), true, "realized", &local_err);
+    if (local_err != NULL) {
+        error_free(local_err);
         object_delete(OBJECT(dev));
-        return rc;
+        return -1;
     }
+    return 0;
+}
 
-    if (!OBJECT(dev)->parent) {
-        static int unattached_count = 0;
-        gchar *name = g_strdup_printf("device[%d]", unattached_count++);
-
-        object_property_add_child(container_get(qdev_get_machine(),
-                                                "/unattached"),
-                                  name, OBJECT(dev), NULL);
-        g_free(name);
-    }
+static void device_realize(DeviceState *dev, Error **err)
+{
+    DeviceClass *dc = DEVICE_GET_CLASS(dev);
 
-    if (qdev_get_vmsd(dev)) {
-        vmstate_register_with_alias_id(dev, -1, qdev_get_vmsd(dev), dev,
-                                       dev->instance_id_alias,
-                                       dev->alias_required_for_version);
-    }
-    dev->realized = true;
-    if (dev->hotplugged) {
-        device_reset(dev);
+    if (dc->init) {
+        int rc = dc->init(dev);
+        if (rc < 0) {
+            error_setg(err, "Device initialization failed.");
+            return;
+        }
     }
-    return 0;
 }

[...]

hw/qdev.c static void device_class_base_init(ObjectClass *class, void *data) · line 767

Quoted 6 lines
hw/qdev.c +6 -0
+static void device_class_init(ObjectClass *oc, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(oc);
+    dc->realize = device_realize;
+}
+

[...]

Stupid question: what exactly is the difference in capabilities and semantics between DeviceClass.init() and DeviceClass.realize()? They look exactly the same to me, from a first look. On which cases would somebody use the former instead of the latter, and why?

Signature · 1 line
Eduardo
#9 lore raw

Re: [Qemu-devel] [RFC 04/34] qdev: Prepare "realized" property

Am 12.12.2012 15:29, schrieb Eduardo Habkost:

Quoted 5 lines · Andreas Färber
Quoted 4 lines

Based on earlier patches by Paolo and me, introduce the QOM realizefn at device level only, as requested by Anthony.

For now this just wraps the qdev initfn.

...which it deprecates.

Quoted 96 lines
Quoted 87 lines
---
 hw/qdev-core.h |    4 +++
 hw/qdev.c      |  100 ++++++++++++++++++++++++++++++++++++++++++--------------

2 Dateien geändert, 80 Zeilen hinzugefügt(+), 24 Zeilen entfernt(-)

hw/qdev-core.h +4 -0
index f0d3a5e..580a811 100644
@@ -29,6 +29,8 @@ enum {
 typedef int (*qdev_initfn)(DeviceState *dev);
 typedef int (*qdev_event)(DeviceState *dev);
 typedef void (*qdev_resetfn)(DeviceState *dev);
+typedef void (*DeviceRealize)(DeviceState *dev, Error **err);
+typedef void (*DeviceUnrealize)(DeviceState *dev, Error **err);
 
 struct VMStateDescription;
 
@@ -47,6 +49,8 @@ typedef struct DeviceClass {
     const struct VMStateDescription *vmsd;
 
     /* Private to qdev / bus.  */
+    DeviceRealize realize;
+    DeviceUnrealize unrealize;
     qdev_initfn init;
     qdev_event unplug;
     qdev_event exit;
hw/qdev.c +16 -23
index bce6ad5..d7b6320 100644
@@ -147,37 +147,30 @@ DeviceState *qdev_try_create(BusState *bus, const char *type)
    Return 0 on success.  */
 int qdev_init(DeviceState *dev)
 {
-    DeviceClass *dc = DEVICE_GET_CLASS(dev);
-    int rc;
+    Error *local_err = NULL;
 
     assert(!dev->realized);
 
-    rc = dc->init(dev);
-    if (rc < 0) {
+    object_property_set_bool(OBJECT(dev), true, "realized", &local_err);
+    if (local_err != NULL) {
+        error_free(local_err);
         object_delete(OBJECT(dev));
-        return rc;
+        return -1;
     }
+    return 0;
+}
 
-    if (!OBJECT(dev)->parent) {
-        static int unattached_count = 0;
-        gchar *name = g_strdup_printf("device[%d]", unattached_count++);
-
-        object_property_add_child(container_get(qdev_get_machine(),
-                                                "/unattached"),
-                                  name, OBJECT(dev), NULL);
-        g_free(name);
-    }
+static void device_realize(DeviceState *dev, Error **err)
+{
+    DeviceClass *dc = DEVICE_GET_CLASS(dev);
 
-    if (qdev_get_vmsd(dev)) {
-        vmstate_register_with_alias_id(dev, -1, qdev_get_vmsd(dev), dev,
-                                       dev->instance_id_alias,
-                                       dev->alias_required_for_version);
-    }
-    dev->realized = true;
-    if (dev->hotplugged) {
-        device_reset(dev);
+    if (dc->init) {
+        int rc = dc->init(dev);
+        if (rc < 0) {
+            error_setg(err, "Device initialization failed.");
+            return;
+        }
     }
-    return 0;
 }

[...]

Quoted 6 lines
hw/qdev.c +6 -0
+static void device_class_init(ObjectClass *oc, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(oc);
+    dc->realize = device_realize;
+}
+

[...]

Quoted 4 lines

Stupid question: what exactly is the difference in capabilities and semantics between DeviceClass.init() and DeviceClass.realize()? They look exactly the same to me, from a first look. On which cases would somebody use the former instead of the latter, and why?

Wherever possible, users should use the new DeviceClass::realize.

"init" or "initfn" clashes with QOM's instance_init name-wise. As shown in this series, instance_init can be used in devices today already, without having realize.

The distinction between instance_init and realize is that the former initializes simple variables, sets up properties and anything the user may want to modify, then realize processes these variables and is able to fail and report the cause of failure (unlike DeviceClass::init).

In the isa patch after all the boring QOM'ish preparations, isa-device's class_init overwrites DeviceClass:realize, thereby no longer invoking any DeviceClass::init callback for the ISA devices. I2C, PCI, SysBus, etc. would need to be done in further steps, but a) this is work, b) the series shouldn't get too long for review/merge and c) it all depends on in which class and thereby with which signature we want to have realize
- DeviceClass::realize(DeviceState *, Error **) or ObjectClass::realize(Object *, Error **).

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#10 lore raw

Re: [Qemu-devel] [RFC 04/34] qdev: Prepare "realized" property

Quoted 8 lines · Andreas Färber

Am 12.12.2012 15:29, schrieb Eduardo Habkost:

Quoted 5 lines · Andreas Färber
Quoted 4 lines

Based on earlier patches by Paolo and me, introduce the QOM realizefn at device level only, as requested by Anthony.

For now this just wraps the qdev initfn.

...which it deprecates.

Good to know. I thought they had different purposes and I was missing something.

[...]

Quoted 35 lines
Quoted 30 lines
Quoted 21 lines
hw/qdev.c +9 -9
+static void device_realize(DeviceState *dev, Error **err)
+{
+    DeviceClass *dc = DEVICE_GET_CLASS(dev);
 
-    if (qdev_get_vmsd(dev)) {
-        vmstate_register_with_alias_id(dev, -1, qdev_get_vmsd(dev), dev,
-                                       dev->instance_id_alias,
-                                       dev->alias_required_for_version);
-    }
-    dev->realized = true;
-    if (dev->hotplugged) {
-        device_reset(dev);
+    if (dc->init) {
+        int rc = dc->init(dev);
+        if (rc < 0) {
+            error_setg(err, "Device initialization failed.");
+            return;
+        }
     }
-    return 0;
 }

[...]

Quoted 6 lines
hw/qdev.c +6 -0
+static void device_class_init(ObjectClass *oc, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(oc);
+    dc->realize = device_realize;
+}
+

[...]

Quoted 4 lines

Stupid question: what exactly is the difference in capabilities and semantics between DeviceClass.init() and DeviceClass.realize()? They look exactly the same to me, from a first look. On which cases would somebody use the former instead of the latter, and why?

Quoted 5 lines

Wherever possible, users should use the new DeviceClass::realize.

"init" or "initfn" clashes with QOM's instance_init name-wise. As shown in this series, instance_init can be used in devices today already, without having realize.

True. That's something I like in the new name. :-)

Quoted 5 lines

The distinction between instance_init and realize is that the former initializes simple variables, sets up properties and anything the user may want to modify, then realize processes these variables and is able to fail and report the cause of failure (unlike DeviceClass::init).

I understood the difference between ObjectClass.instance_init() and DeviceClass.init() (now called realize()), already. My question was about the difference between DeviceClass.init() and DeviceClass.realize().

Quoted 9 lines

In the isa patch after all the boring QOM'ish preparations, isa-device's class_init overwrites DeviceClass:realize, thereby no longer invoking any DeviceClass::init callback for the ISA devices. I2C, PCI, SysBus, etc. would need to be done in further steps, but a) this is work, b) the series shouldn't get too long for review/merge and c) it all depends on in which class and thereby with which signature we want to have realize
- DeviceClass::realize(DeviceState *, Error **) or ObjectClass::realize(Object *, Error **).

So, just to check if I understood all correctly:

DeviceClass.init() is just the old and deprecated version of DeviceClass.realize() (just because the former has no Error parameter), but both have exactly the same semantics/purpose, and devices should now use DeviceClass.realize() instead. Correct?

Signature · 1 line
Eduardo
#11 lore raw

Re: [Qemu-devel] [RFC 04/34] qdev: Prepare "realized" property

Am 12.12.2012 19:16, schrieb Eduardo Habkost:

Quoted 6 lines

So, just to check if I understood all correctly:

DeviceClass.init() is just the old and deprecated version of DeviceClass.realize() (just because the former has no Error parameter), but both have exactly the same semantics/purpose, and devices should now use DeviceClass.realize() instead. Correct?

Almost! Some qdev initfns today do things that instance_init should do and realizefn shouldn't. Creating child devices in qdev initfn tampers with our future ability to set realized = true recursively.

The other difference that I see (RFC) is that qdev uses an only-the-instance's-class-sets-init approach, whereas with QOM any class in the hierarchy can set/override the "virtual" method but needs to take care of storing and (if desired) calling the parent's version itself, i.e. an inversion of control towards child classes.

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#12 lore raw

Re: [Qemu-devel] [RFC 04/34] qdev: Prepare "realized" property

Quoted 11 lines · Andreas Färber

Am 12.12.2012 19:16, schrieb Eduardo Habkost:

Quoted 6 lines

So, just to check if I understood all correctly:

DeviceClass.init() is just the old and deprecated version of DeviceClass.realize() (just because the former has no Error parameter), but both have exactly the same semantics/purpose, and devices should now use DeviceClass.realize() instead. Correct?

Almost! Some qdev initfns today do things that instance_init should do and realizefn shouldn't. Creating child devices in qdev initfn tampers with our future ability to set realized = true recursively.

In those cases, where should the child device cration be moved to?

Whatever the answer is, can we have those subtle differences documented inside DeviceClass?

I specifically mean documenting the purpose of the init/realize/unrealize function pointers and their semantics/requirements for subclasses, not just documenting the semantics of the "realized" property and device_set_realized(). Knowing what device_set_realize() and qdev_init() are supposed to do when all classes already do what they are supposed to is easy. Knowing what exactly subclasses can/can't to do when setting init/realize/unrealize functions is a bit more complicated.

Quoted 6 lines

The other difference that I see (RFC) is that qdev uses an only-the-instance's-class-sets-init approach, whereas with QOM any class in the hierarchy can set/override the "virtual" method but needs to take care of storing and (if desired) calling the parent's version itself, i.e. an inversion of control towards child classes.

I see. In theory we could change DeviceClass.init() to have the same requirements/semantic, but then we would need to change every class to save the parent's init() function and call it.

Signature · 1 line
Eduardo
#13 lore raw

RFC 5/34 isa: Split off instance_init for ISADevice

In reply to Andreas Färber
---
 hw/isa-bus.c |   14 ++++++++++----

1 Datei geändert, 10 Zeilen hinzugefügt(+), 4 Zeilen entfernt(-)

hw/isa-bus.c +10 -4
index 144a88e..2b1fc40 100644
@@ -124,9 +124,6 @@ static int isa_qdev_init(DeviceState *qdev)
     ISADevice *dev = ISA_DEVICE(qdev);
     ISADeviceClass *klass = ISA_DEVICE_GET_CLASS(dev);
 
-    dev->isairq[0] = -1;
-    dev->isairq[1] = -1;
-
     if (klass->init) {
         return klass->init(dev);
     }
@@ -134,6 +131,14 @@ static int isa_qdev_init(DeviceState *qdev)
     return 0;
 }
 
+static void isa_device_init(Object *obj)
+{
+    ISADevice *dev = ISA_DEVICE(obj);
+
+    dev->isairq[0] = -1;
+    dev->isairq[1] = -1;
+}
+
 ISADevice *isa_create(ISABus *bus, const char *name)
 {
     DeviceState *dev;
@@ -229,10 +234,11 @@ static void isa_device_class_init(ObjectClass *klass, void *data)
     k->bus_type = TYPE_ISA_BUS;
 }
 
-static TypeInfo isa_device_type_info = {
+static const TypeInfo isa_device_type_info = {
     .name = TYPE_ISA_DEVICE,
     .parent = TYPE_DEVICE,
     .instance_size = sizeof(ISADevice),
+    .instance_init = isa_device_init,
     .abstract = true,
     .class_size = sizeof(ISADeviceClass),
     .class_init = isa_device_class_init,
Signature · 1 line
1.7.10.4
#14 lore raw

RFC 6/34 applesmc: QOM'ify

In reply to Andreas Färber

Add a typedef for the state struct and rename from Status to State. Add type constant and cast macro to obsolete DO_UPCAST().

Prepares for ISA realizefn.

---
 hw/applesmc.c |   35 ++++++++++++++++++++---------------

1 Datei geändert, 20 Zeilen hinzugefügt(+), 15 Zeilen entfernt(-)

hw/applesmc.c +20 -15
index 8bedaad..d6e556b 100644
@@ -66,8 +66,13 @@ struct AppleSMCData {
     QLIST_ENTRY(AppleSMCData) node;
 };
 
-struct AppleSMCStatus {
-    ISADevice dev;
+#define TYPE_APPLE_SMC "isa-applesmc"
+#define APPLE_SMC(obj) OBJECT_CHECK(AppleSMCState, (obj), TYPE_APPLE_SMC)
+
+typedef struct AppleSMCState AppleSMCState;
+struct AppleSMCState {
+    ISADevice parent_obj;
+
     uint32_t iobase;
     uint8_t cmd;
     uint8_t status;
@@ -83,7 +88,7 @@ struct AppleSMCStatus {
 
 static void applesmc_io_cmd_writeb(void *opaque, uint32_t addr, uint32_t val)
 {
-    struct AppleSMCStatus *s = opaque;
+    AppleSMCState *s = opaque;
 
     smc_debug("CMD Write B: %#x = %#x\n", addr, val);
     switch(val) {
@@ -96,7 +101,7 @@ static void applesmc_io_cmd_writeb(void *opaque, uint32_t addr, uint32_t val)
     s->data_pos = 0;
 }
 
-static void applesmc_fill_data(struct AppleSMCStatus *s)
+static void applesmc_fill_data(AppleSMCState *s)
 {
     struct AppleSMCData *d;
 
@@ -112,7 +117,7 @@ static void applesmc_fill_data(struct AppleSMCStatus *s)
 
 static void applesmc_io_data_writeb(void *opaque, uint32_t addr, uint32_t val)
 {
-    struct AppleSMCStatus *s = opaque;
+    AppleSMCState *s = opaque;
 
     smc_debug("DATA Write B: %#x = %#x\n", addr, val);
     switch(s->cmd) {
@@ -135,7 +140,7 @@ static void applesmc_io_data_writeb(void *opaque, uint32_t addr, uint32_t val)
 
 static uint32_t applesmc_io_data_readb(void *opaque, uint32_t addr1)
 {
-    struct AppleSMCStatus *s = opaque;
+    AppleSMCState *s = opaque;
     uint8_t retval = 0;
 
     switch(s->cmd) {
@@ -159,13 +164,13 @@ static uint32_t applesmc_io_data_readb(void *opaque, uint32_t addr1)
 
 static uint32_t applesmc_io_cmd_readb(void *opaque, uint32_t addr1)
 {
-    struct AppleSMCStatus *s = opaque;
+    AppleSMCState *s = opaque;
 
     smc_debug("CMD Read B: %#x\n", addr1);
     return s->status;
 }
 
-static void applesmc_add_key(struct AppleSMCStatus *s, const char *key,
+static void applesmc_add_key(AppleSMCState *s, const char *key,
                              int len, const char *data)
 {
     struct AppleSMCData *def;
@@ -180,7 +185,7 @@ static void applesmc_add_key(struct AppleSMCStatus *s, const char *key,
 
 static void qdev_applesmc_isa_reset(DeviceState *dev)
 {
-    struct AppleSMCStatus *s = DO_UPCAST(struct AppleSMCStatus, dev.qdev, dev);
+    AppleSMCState *s = APPLE_SMC(dev);
     struct AppleSMCData *d, *next;
 
     /* Remove existing entries */
@@ -198,7 +203,7 @@ static void qdev_applesmc_isa_reset(DeviceState *dev)
 
 static int applesmc_isa_init(ISADevice *dev)
 {
-    struct AppleSMCStatus *s = DO_UPCAST(struct AppleSMCStatus, dev, dev);
+    AppleSMCState *s = APPLE_SMC(dev);
 
     register_ioport_read(s->iobase + APPLESMC_DATA_PORT, 4, 1,
                          applesmc_io_data_readb, s);
@@ -221,9 +226,9 @@ static int applesmc_isa_init(ISADevice *dev)
 }
 
 static Property applesmc_isa_properties[] = {
-    DEFINE_PROP_HEX32("iobase", struct AppleSMCStatus, iobase,
+    DEFINE_PROP_HEX32("iobase", AppleSMCState, iobase,
                       APPLESMC_DEFAULT_IOBASE),
-    DEFINE_PROP_STRING("osk", struct AppleSMCStatus, osk),
+    DEFINE_PROP_STRING("osk", AppleSMCState, osk),
     DEFINE_PROP_END_OF_LIST(),
 };
 
@@ -236,10 +241,10 @@ static void qdev_applesmc_class_init(ObjectClass *klass, void *data)
     dc->props = applesmc_isa_properties;
 }
 
-static TypeInfo applesmc_isa_info = {
-    .name          = "isa-applesmc",
+static const TypeInfo applesmc_isa_info = {
+    .name          = TYPE_APPLE_SMC,
     .parent        = TYPE_ISA_DEVICE,
-    .instance_size = sizeof(struct AppleSMCStatus),
+    .instance_size = sizeof(AppleSMCState),
     .class_init    = qdev_applesmc_class_init,
 };
 
Signature · 1 line
1.7.10.4
#15 lore raw

RFC 7/34 cirrus_vga: QOM'ify ISA Cirrus VGA

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST().

Prepares for ISA realizefn.

---
 hw/cirrus_vga.c |   17 +++++++++++------

1 Datei geändert, 11 Zeilen hinzugefügt(+), 6 Zeilen entfernt(-)

hw/cirrus_vga.c +11 -6
index 40efa8a..9687b6b 100644
@@ -250,8 +250,13 @@ typedef struct PCICirrusVGAState {
     CirrusVGAState cirrus_vga;
 } PCICirrusVGAState;
 
+#define TYPE_ISA_CIRRUS_VGA "isa-cirrus-vga"
+#define ISA_CIRRUS_VGA(obj) \
+    OBJECT_CHECK(ISACirrusVGAState, (obj), TYPE_ISA_CIRRUS_VGA)
+
 typedef struct ISACirrusVGAState {
-    ISADevice dev;
+    ISADevice parent_obj;
+
     CirrusVGAState cirrus_vga;
 } ISACirrusVGAState;
 
@@ -2902,7 +2907,7 @@ static void cirrus_init_common(CirrusVGAState * s, int device_id, int is_pci,
 
 static int vga_initfn(ISADevice *dev)
 {
-    ISACirrusVGAState *d = DO_UPCAST(ISACirrusVGAState, dev, dev);
+    ISACirrusVGAState *d = ISA_CIRRUS_VGA(dev);
     VGACommonState *s = &d->cirrus_vga.vga;
 
     vga_common_init(s);
@@ -2917,7 +2922,7 @@ static int vga_initfn(ISADevice *dev)
     return 0;
 }
 
-static Property isa_vga_cirrus_properties[] = {
+static Property isa_cirrus_vga_properties[] = {
     DEFINE_PROP_UINT32("vgamem_mb", struct ISACirrusVGAState,
                        cirrus_vga.vga.vram_size_mb, 8),
     DEFINE_PROP_END_OF_LIST(),
@@ -2930,11 +2935,11 @@ static void isa_cirrus_vga_class_init(ObjectClass *klass, void *data)
 
     dc->vmsd  = &vmstate_cirrus_vga;
     k->init   = vga_initfn;
-    dc->props = isa_vga_cirrus_properties;
+    dc->props = isa_cirrus_vga_properties;
 }
 
-static TypeInfo isa_cirrus_vga_info = {
-    .name          = "isa-cirrus-vga",
+static const TypeInfo isa_cirrus_vga_info = {
+    .name          = TYPE_ISA_CIRRUS_VGA,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof(ISACirrusVGAState),
     .class_init = isa_cirrus_vga_class_init,
Signature · 1 line
1.7.10.4
#16 lore raw

RFC 8/34 debugcon: QOM'ify ISA debug console

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST().

Prepares for ISA realizefn.

---
 hw/debugcon.c |   13 +++++++++----

1 Datei geändert, 9 Zeilen hinzugefügt(+), 4 Zeilen entfernt(-)

hw/debugcon.c +9 -4
index 14ab326..02846ed 100644
@@ -36,8 +36,13 @@ typedef struct DebugconState {
     uint32_t readback;
 } DebugconState;
 
+#define TYPE_ISA_DEBUG_CONSOLE "isa-debugcon"
+#define ISA_DEBUG_CONSOLE(obj) \
+    OBJECT_CHECK(ISADebugconState, (obj), TYPE_ISA_DEBUG_CONSOLE)
+
 typedef struct ISADebugconState {
-    ISADevice dev;
+    ISADevice parent_obj;
+
     uint32_t iobase;
     DebugconState state;
 } ISADebugconState;
@@ -78,7 +83,7 @@ static void debugcon_init_core(DebugconState *s)
 
 static int debugcon_isa_initfn(ISADevice *dev)
 {
-    ISADebugconState *isa = DO_UPCAST(ISADebugconState, dev, dev);
+    ISADebugconState *isa = ISA_DEBUG_CONSOLE(dev);
     DebugconState *s = &isa->state;
 
     debugcon_init_core(s);
@@ -102,8 +107,8 @@ static void debugcon_isa_class_initfn(ObjectClass *klass, void *data)
     dc->props = debugcon_isa_properties;
 }
 
-static TypeInfo debugcon_isa_info = {
-    .name          = "isa-debugcon",
+static const TypeInfo debugcon_isa_info = {
+    .name          = TYPE_ISA_DEBUG_CONSOLE,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof(ISADebugconState),
     .class_init    = debugcon_isa_class_initfn,
Signature · 1 line
1.7.10.4
#17 lore raw

RFC 9/34 fdc: QOM'ify ISA floppy controller

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST(). Reuse type constant for PC machine compatibility settings.

Prepares for ISA realizefn.

Cc Markus Armbruster <[email protected]>
---
 hw/fdc.c     |   23 +++++++++++++----------
 hw/fdc.h     |    2 ++
 hw/pc_piix.c |    2 +-

3 Dateien geändert, 16 Zeilen hinzugefügt(+), 11 Zeilen entfernt(-)

hw/fdc.c +13 -10
index 29b5449..edd7483 100644
@@ -550,8 +550,11 @@ typedef struct FDCtrlSysBus {
     struct FDCtrl state;
 } FDCtrlSysBus;
 
+#define ISA_FDC(obj) OBJECT_CHECK(FDCtrlISABus, (obj), TYPE_ISA_FDC)
+
 typedef struct FDCtrlISABus {
-    ISADevice busdev;
+    ISADevice parent_obj;
+
     uint32_t iobase;
     uint32_t irq;
     uint32_t dma;
@@ -779,7 +782,7 @@ static void fdctrl_external_reset_sysbus(DeviceState *d)
 
 static void fdctrl_external_reset_isa(DeviceState *d)
 {
-    FDCtrlISABus *isa = container_of(d, FDCtrlISABus, busdev.qdev);
+    FDCtrlISABus *isa = ISA_FDC(d);
     FDCtrl *s = &isa->state;
 
     fdctrl_reset(s, 0);
@@ -2022,7 +2025,7 @@ ISADevice *fdctrl_init_isa(ISABus *bus, DriveInfo **fds)
 {
     ISADevice *dev;
 
-    dev = isa_try_create(bus, "isa-fdc");
+    dev = isa_try_create(bus, TYPE_ISA_FDC);
     if (!dev) {
         return NULL;
     }
@@ -2117,13 +2120,13 @@ static const MemoryRegionPortio fdc_portio_list[] = {
 
 static int isabus_fdc_init1(ISADevice *dev)
 {
-    FDCtrlISABus *isa = DO_UPCAST(FDCtrlISABus, busdev, dev);
+    FDCtrlISABus *isa = ISA_FDC(dev);
     FDCtrl *fdctrl = &isa->state;
     int ret;
 
     isa_register_portio_list(dev, isa->iobase, fdc_portio_list, fdctrl, "fdc");
 
-    isa_init_irq(&isa->busdev, &fdctrl->irq, isa->irq);
+    isa_init_irq(dev, &fdctrl->irq, isa->irq);
     fdctrl->dma_chann = isa->dma;
 
     qdev_set_legacy_instance_id(&dev->qdev, isa->iobase, 2);
@@ -2170,7 +2173,7 @@ static int sun4m_fdc_init1(SysBusDevice *dev)
 
 FDriveType isa_fdc_get_drive_type(ISADevice *fdc, int i)
 {
-    FDCtrlISABus *isa = DO_UPCAST(FDCtrlISABus, busdev, fdc);
+    FDCtrlISABus *isa = ISA_FDC(fdc);
 
     return isa->state.drives[i].drive;
 }
@@ -2198,7 +2201,7 @@ static Property isa_fdc_properties[] = {
     DEFINE_PROP_END_OF_LIST(),
 };
 
-static void isabus_fdc_class_init1(ObjectClass *klass, void *data)
+static void isabus_fdc_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
@@ -2210,11 +2213,11 @@ static void isabus_fdc_class_init1(ObjectClass *klass, void *data)
     dc->props = isa_fdc_properties;
 }
 
-static TypeInfo isa_fdc_info = {
-    .name          = "isa-fdc",
+static const TypeInfo isa_fdc_info = {
+    .name          = TYPE_ISA_FDC,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof(FDCtrlISABus),
-    .class_init    = isabus_fdc_class_init1,
+    .class_init    = isabus_fdc_class_init,
 };
 
 static const VMStateDescription vmstate_sysbus_fdc ={
hw/fdc.h +2 -0
index a8f6f7c..d48b2f8 100644
@@ -13,6 +13,8 @@ typedef enum FDriveType {
     FDRIVE_DRV_NONE = 0x03,   /* No drive connected     */
 } FDriveType;
 
+#define TYPE_ISA_FDC "isa-fdc"
+
 ISADevice *fdctrl_init_isa(ISABus *bus, DriveInfo **fds);
 void fdctrl_init_sysbus(qemu_irq irq, int dma_chann,
                         hwaddr mmio_base, DriveInfo **fds);
hw/pc_piix.c +1 -1
index cfa839c..7791e4a 100644
@@ -449,7 +449,7 @@ static QEMUMachine pc_machine_v1_1 = {
             .property = "rom_only",\
             .value    = stringify(1),\
         }, {\
-            .driver   = "isa-fdc",\
+            .driver   = TYPE_ISA_FDC,\
             .property = "check_media_rate",\
             .value    = "off",\
         }, {\
Signature · 1 line
1.7.10.4
#18 lore raw

RFC 10/34 i82374: QOM'ify

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST().

Prepares for ISA realizefn.

---
 hw/i82374.c |   12 ++++++++----

1 Datei geändert, 8 Zeilen hinzugefügt(+), 4 Zeilen entfernt(-)

hw/i82374.c +8 -4
index 4a922c3..82de0b0 100644
@@ -104,8 +104,12 @@ static void i82374_init(I82374State *s)
     memset(s->commands, 0, sizeof(s->commands));
 }
 
+#define TYPE_I82374 "i82374"
+#define I82374(obj) OBJECT_CHECK(ISAi82374State, (obj), TYPE_I82374)
+
 typedef struct ISAi82374State {
-    ISADevice dev;
+    ISADevice parent_obj;
+
     uint32_t iobase;
     I82374State state;
 } ISAi82374State;
@@ -122,7 +126,7 @@ static const VMStateDescription vmstate_isa_i82374 = {
 
 static int i82374_isa_init(ISADevice *dev)
 {
-    ISAi82374State *isa = DO_UPCAST(ISAi82374State, dev, dev);
+    ISAi82374State *isa = I82374(dev);
     I82374State *s = &isa->state;
 
     register_ioport_read(isa->iobase + 0x0A, 1, 1, i82374_read_isr, s);
@@ -153,8 +157,8 @@ static void i82374_class_init(ObjectClass *klass, void *data)
     dc->props = i82374_properties;
 }
 
-static TypeInfo i82374_isa_info = {
-    .name  = "i82374",
+static const TypeInfo i82374_isa_info = {
+    .name  = TYPE_I82374,
     .parent = TYPE_ISA_DEVICE,
     .instance_size  = sizeof(ISAi82374State),
     .class_init = i82374_class_init,
Signature · 1 line
1.7.10.4
#19 lore raw

PATCH 11/34 i8259: Fix PIC_COMMON() macro

In reply to Andreas Färber

It used a wrong struct type name since its introduction in 8f04ee0882aec9fe91fb70f767edf5dacff59835 (isa: pic: convert to QEMU Object Model), apparently it is unused so far.

---
 hw/i8259_internal.h |    2 +-

1 Datei geändert, 1 Zeile hinzugefügt(+), 1 Zeile entfernt(-)

hw/i8259_internal.h +1 -1
index 4137b61..8785b1d 100644
@@ -33,7 +33,7 @@ typedef struct PICCommonState PICCommonState;
 
 #define TYPE_PIC_COMMON "pic-common"
 #define PIC_COMMON(obj) \
-     OBJECT_CHECK(PICCommon, (obj), TYPE_PIC_COMMON)
+     OBJECT_CHECK(PICCommonState, (obj), TYPE_PIC_COMMON)
 #define PIC_COMMON_CLASS(klass) \
      OBJECT_CLASS_CHECK(PICCommonClass, (klass), TYPE_PIC_COMMON)
 #define PIC_COMMON_GET_CLASS(obj) \
Signature · 1 line
1.7.10.4
#20 lore raw

RFC 12/34 i8259: QOM cleanups

In reply to Andreas Färber

Eliminate DO_UPCAST() for PICCommonState. Prepares for ISA realizefn.

Also give the i8259_common type registration functions unique names while at it.

---
 hw/i8259.c          |   18 ++++++++++--------
 hw/i8259_common.c   |   10 +++++-----
 hw/i8259_internal.h |    3 ++-
 hw/kvm/i8259.c      |    4 ++--

4 Dateien geändert, 19 Zeilen hinzugefügt(+), 16 Zeilen entfernt(-)

hw/i8259.c +10 -8
index af0ba4d..55c2cb9 100644
@@ -182,7 +182,7 @@ static void pic_intack(PICCommonState *s, int irq)
 
 int pic_read_irq(DeviceState *d)
 {
-    PICCommonState *s = DO_UPCAST(PICCommonState, dev.qdev, d);
+    PICCommonState *s = PIC_COMMON(d);
     int irq, irq2, intno;
 
     irq = pic_get_irq(s);
@@ -229,7 +229,7 @@ static void pic_init_reset(PICCommonState *s)
 
 static void pic_reset(DeviceState *dev)
 {
-    PICCommonState *s = DO_UPCAST(PICCommonState, dev.qdev, dev);
+    PICCommonState *s = PIC_COMMON(dev);
 
     s->elcr = 0;
     pic_init_reset(s);
@@ -361,7 +361,7 @@ static uint64_t pic_ioport_read(void *opaque, hwaddr addr,
 
 int pic_get_output(DeviceState *d)
 {
-    PICCommonState *s = DO_UPCAST(PICCommonState, dev.qdev, d);
+    PICCommonState *s = PIC_COMMON(d);
 
     return (pic_get_irq(s) >= 0);
 }
@@ -400,11 +400,13 @@ static const MemoryRegionOps pic_elcr_ioport_ops = {
 
 static void pic_init(PICCommonState *s)
 {
+    DeviceState *dev = DEVICE(s);
+
     memory_region_init_io(&s->base_io, &pic_base_ioport_ops, s, "pic", 2);
     memory_region_init_io(&s->elcr_io, &pic_elcr_ioport_ops, s, "elcr", 1);
 
-    qdev_init_gpio_out(&s->dev.qdev, s->int_out, ARRAY_SIZE(s->int_out));
-    qdev_init_gpio_in(&s->dev.qdev, pic_set_irq, 8);
+    qdev_init_gpio_out(dev, s->int_out, ARRAY_SIZE(s->int_out));
+    qdev_init_gpio_in(dev, pic_set_irq, 8);
 }
 
 void pic_info(Monitor *mon)
@@ -416,7 +418,7 @@ void pic_info(Monitor *mon)
         return;
     }
     for (i = 0; i < 2; i++) {
-        s = i == 0 ? DO_UPCAST(PICCommonState, dev.qdev, isa_pic) : slave_pic;
+        s = i == 0 ? PIC_COMMON(isa_pic) : slave_pic;
         monitor_printf(mon, "pic%d: irr=%02x imr=%02x isr=%02x hprio=%d "
                        "irq_base=%02x rr_sel=%d elcr=%02x fnm=%d\n",
                        i, s->irr, s->imr, s->isr, s->priority_add,
@@ -467,7 +469,7 @@ qemu_irq *i8259_init(ISABus *bus, qemu_irq parent_irq)
         irq_set[i + 8] = qdev_get_gpio_in(&dev->qdev, i);
     }
 
-    slave_pic = DO_UPCAST(PICCommonState, dev, dev);
+    slave_pic = PIC_COMMON(dev);
 
     return irq_set;
 }
@@ -481,7 +483,7 @@ static void i8259_class_init(ObjectClass *klass, void *data)
     dc->reset = pic_reset;
 }
 
-static TypeInfo i8259_info = {
+static const TypeInfo i8259_info = {
     .name       = "isa-i8259",
     .instance_size = sizeof(PICCommonState),
     .parent     = TYPE_PIC_COMMON,
hw/i8259_common.c +5 -5
index ab3d98b..418c485 100644
@@ -68,7 +68,7 @@ static int pic_dispatch_post_load(void *opaque, int version_id)
 
 static int pic_init_common(ISADevice *dev)
 {
-    PICCommonState *s = DO_UPCAST(PICCommonState, dev, dev);
+    PICCommonState *s = PIC_COMMON(dev);
     PICCommonClass *info = PIC_COMMON_GET_CLASS(s);
 
     info->init(s);
@@ -78,7 +78,7 @@ static int pic_init_common(ISADevice *dev)
         isa_register_ioport(NULL, &s->elcr_io, s->elcr_addr);
     }
 
-    qdev_set_legacy_instance_id(&s->dev.qdev, s->iobase, 1);
+    qdev_set_legacy_instance_id(DEVICE(dev), s->iobase, 1);
 
     return 0;
 }
@@ -144,7 +144,7 @@ static void pic_common_class_init(ObjectClass *klass, void *data)
     ic->init = pic_init_common;
 }
 
-static TypeInfo pic_common_type = {
+static const TypeInfo pic_common_type = {
     .name = TYPE_PIC_COMMON,
     .parent = TYPE_ISA_DEVICE,
     .instance_size = sizeof(PICCommonState),
@@ -153,9 +153,9 @@ static TypeInfo pic_common_type = {
     .abstract = true,
 };
 
-static void register_types(void)
+static void pic_common_register_types(void)
 {
     type_register_static(&pic_common_type);
 }
 
-type_init(register_types);
+type_init(pic_common_register_types);
hw/i8259_internal.h +2 -1
index 8785b1d..32e48c3 100644
@@ -48,7 +48,8 @@ typedef struct PICCommonClass
 } PICCommonClass;
 
 struct PICCommonState {
-    ISADevice dev;
+    ISADevice parent_obj;
+
     uint8_t last_irr; /* edge detection */
     uint8_t irr; /* interrupt request register */
     uint8_t imr; /* interrupt mask register */
hw/kvm/i8259.c +2 -2
index 1e24cd4..2aaf14a 100644
@@ -82,7 +82,7 @@ static void kvm_pic_put(PICCommonState *s)
 
 static void kvm_pic_reset(DeviceState *dev)
 {
-    PICCommonState *s = DO_UPCAST(PICCommonState, dev.qdev, dev);
+    PICCommonState *s = PIC_COMMON(dev);
 
     s->elcr = 0;
     pic_reset_common(s);
@@ -123,7 +123,7 @@ static void kvm_i8259_class_init(ObjectClass *klass, void *data)
     k->post_load  = kvm_pic_put;
 }
 
-static TypeInfo kvm_i8259_info = {
+static const TypeInfo kvm_i8259_info = {
     .name  = "kvm-i8259",
     .parent = TYPE_PIC_COMMON,
     .instance_size = sizeof(PICCommonState),
Signature · 1 line
1.7.10.4
#21 lore raw

RFC 13/34 ide: QOM'ify ISA IDE

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST(). Add missing braces.

Prepares for ISA realizefn.

---
 hw/ide/isa.c |   41 +++++++++++++++++++++++++----------------

1 Datei geändert, 25 Zeilen hinzugefügt(+), 16 Zeilen entfernt(-)

hw/ide/isa.c +25 -16
index 8ab2718..4d55885 100644
@@ -33,8 +33,12 @@
 /***********************************************************/
 /* ISA IDE definitions */
 
+#define TYPE_ISA_IDE "isa-ide"
+#define ISA_IDE(obj) OBJECT_CHECK(ISAIDEState, (obj), TYPE_ISA_IDE)
+
 typedef struct ISAIDEState {
-    ISADevice dev;
+    ISADevice parent_obj;
+
     IDEBus    bus;
     uint32_t  iobase;
     uint32_t  iobase2;
@@ -44,7 +48,7 @@ typedef struct ISAIDEState {
 
 static void isa_ide_reset(DeviceState *d)
 {
-    ISAIDEState *s = container_of(d, ISAIDEState, dev.qdev);
+    ISAIDEState *s = ISA_IDE(d);
 
     ide_bus_reset(&s->bus);
 }
@@ -63,9 +67,9 @@ static const VMStateDescription vmstate_ide_isa = {
 
 static int isa_ide_initfn(ISADevice *dev)
 {
-    ISAIDEState *s = DO_UPCAST(ISAIDEState, dev, dev);
+    ISAIDEState *s = ISA_IDE(dev);
 
-    ide_bus_new(&s->bus, &s->dev.qdev, 0);
+    ide_bus_new(&s->bus, DEVICE(dev), 0);
     ide_init_ioport(&s->bus, dev, s->iobase, s->iobase2);
     isa_init_irq(dev, &s->irq, s->isairq);
     ide_init2(&s->bus, s->irq);
@@ -76,22 +80,27 @@ static int isa_ide_initfn(ISADevice *dev)
 ISADevice *isa_ide_init(ISABus *bus, int iobase, int iobase2, int isairq,
                         DriveInfo *hd0, DriveInfo *hd1)
 {
-    ISADevice *dev;
+    DeviceState *dev;
+    ISADevice *isadev;
     ISAIDEState *s;
 
-    dev = isa_create(bus, "isa-ide");
-    qdev_prop_set_uint32(&dev->qdev, "iobase",  iobase);
-    qdev_prop_set_uint32(&dev->qdev, "iobase2", iobase2);
-    qdev_prop_set_uint32(&dev->qdev, "irq",     isairq);
-    if (qdev_init(&dev->qdev) < 0)
+    isadev = isa_create(bus, TYPE_ISA_IDE);
+    dev = DEVICE(isadev);
+    qdev_prop_set_uint32(dev, "iobase",  iobase);
+    qdev_prop_set_uint32(dev, "iobase2", iobase2);
+    qdev_prop_set_uint32(dev, "irq",     isairq);
+    if (qdev_init(dev) < 0) {
         return NULL;
+    }
 
-    s = DO_UPCAST(ISAIDEState, dev, dev);
-    if (hd0)
+    s = ISA_IDE(dev);
+    if (hd0) {
         ide_create_drive(&s->bus, 0, hd0);
-    if (hd1)
+    }
+    if (hd1) {
         ide_create_drive(&s->bus, 1, hd1);
-    return dev;
+    }
+    return isadev;
 }
 
 static Property isa_ide_properties[] = {
@@ -111,8 +120,8 @@ static void isa_ide_class_initfn(ObjectClass *klass, void *data)
     dc->props = isa_ide_properties;
 }
 
-static TypeInfo isa_ide_info = {
-    .name          = "isa-ide",
+static const TypeInfo isa_ide_info = {
+    .name          = TYPE_ISA_IDE,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof(ISAIDEState),
     .class_init    = isa_ide_class_initfn,
Signature · 1 line
1.7.10.4
#22 lore raw

RFC 14/34 m48t59: QOM'ify ISA M48T59 NVRAM

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST() and container_of().

Prepares for ISA realizefn.

---
 hw/m48t59.c |   37 ++++++++++++++++++++++---------------

1 Datei geändert, 22 Zeilen hinzugefügt(+), 15 Zeilen entfernt(-)

hw/m48t59.c +22 -15
index 7da7e7c..6d2f9cf 100644
@@ -72,8 +72,13 @@ struct M48t59State {
     uint8_t  lock;
 };
 
+#define TYPE_ISA_M48T59 "m48t59_isa"
+#define M48T59_ISA(obj) \
+    OBJECT_CHECK(M48t59ISAState, (obj), TYPE_ISA_M48T59)
+
 typedef struct M48t59ISAState {
-    ISADevice busdev;
+    ISADevice parent_obj;
+
     M48t59State state;
     MemoryRegion io;
 } M48t59ISAState;
@@ -608,7 +613,7 @@ static void m48t59_reset_common(M48t59State *NVRAM)
 
 static void m48t59_reset_isa(DeviceState *d)
 {
-    M48t59ISAState *isa = container_of(d, M48t59ISAState, busdev.qdev);
+    M48t59ISAState *isa = M48T59_ISA(d);
     M48t59State *NVRAM = &isa->state;
 
     m48t59_reset_common(NVRAM);
@@ -665,20 +670,22 @@ M48t59State *m48t59_init_isa(ISABus *bus, uint32_t io_base, uint16_t size,
                              int model)
 {
     M48t59ISAState *d;
-    ISADevice *dev;
+    ISADevice *isadev;
+    DeviceState *dev;
     M48t59State *s;
 
-    dev = isa_create(bus, "m48t59_isa");
-    qdev_prop_set_uint32(&dev->qdev, "model", model);
-    qdev_prop_set_uint32(&dev->qdev, "size", size);
-    qdev_prop_set_uint32(&dev->qdev, "io_base", io_base);
-    qdev_init_nofail(&dev->qdev);
-    d = DO_UPCAST(M48t59ISAState, busdev, dev);
+    isadev = isa_create(bus, TYPE_ISA_M48T59);
+    dev = DEVICE(isadev);
+    qdev_prop_set_uint32(dev, "model", model);
+    qdev_prop_set_uint32(dev, "size", size);
+    qdev_prop_set_uint32(dev, "io_base", io_base);
+    qdev_init_nofail(dev);
+    d = M48T59_ISA(isadev);
     s = &d->state;
 
     memory_region_init_io(&d->io, &m48t59_io_ops, s, "m48t59", 4);
     if (io_base != 0) {
-        isa_register_ioport(dev, &d->io, io_base);
+        isa_register_ioport(isadev, &d->io, io_base);
     }
 
     return s;
@@ -698,7 +705,7 @@ static void m48t59_init_common(M48t59State *s)
 
 static int m48t59_init_isa1(ISADevice *dev)
 {
-    M48t59ISAState *d = DO_UPCAST(M48t59ISAState, busdev, dev);
+    M48t59ISAState *d = M48T59_ISA(dev);
     M48t59State *s = &d->state;
 
     isa_init_irq(dev, &s->IRQ, 8);
@@ -728,7 +735,7 @@ static Property m48t59_isa_properties[] = {
     DEFINE_PROP_END_OF_LIST(),
 };
 
-static void m48t59_init_class_isa1(ObjectClass *klass, void *data)
+static void m48t59_isa_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
@@ -738,11 +745,11 @@ static void m48t59_init_class_isa1(ObjectClass *klass, void *data)
     dc->props = m48t59_isa_properties;
 }
 
-static TypeInfo m48t59_isa_info = {
-    .name          = "m48t59_isa",
+static const TypeInfo m48t59_isa_info = {
+    .name          = TYPE_ISA_M48T59,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof(M48t59ISAState),
-    .class_init    = m48t59_init_class_isa1,
+    .class_init    = m48t59_isa_class_init,
 };
 
 static Property m48t59_properties[] = {
Signature · 1 line
1.7.10.4
#23 lore raw

RFC 15/34 mc146818rtc: QOM'ify

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST().

Prepares for ISA realizefn.

---
 hw/mc146818rtc.c |   38 +++++++++++++++++++++-----------------
 hw/mc146818rtc.h |    2 ++

2 Dateien geändert, 23 Zeilen hinzugefügt(+), 17 Zeilen entfernt(-)

hw/mc146818rtc.c +21 -17
index 7d84ce3..c87b7f6 100644
@@ -57,8 +57,11 @@
 #define RTC_CLOCK_RATE            32768
 #define UIP_HOLD_LENGTH           (8 * NSEC_PER_SEC / 32768)
 
+#define MC146818_RTC(obj) OBJECT_CHECK(RTCState, (obj), TYPE_MC146818_RTC)
+
 typedef struct RTCState {
-    ISADevice dev;
+    ISADevice parent_obj;
+
     MemoryRegion io;
     uint8_t cmos_data[128];
     uint8_t cmos_index;
@@ -668,14 +671,14 @@ static uint64_t cmos_ioport_read(void *opaque, hwaddr addr,
 
 void rtc_set_memory(ISADevice *dev, int addr, int val)
 {
-    RTCState *s = DO_UPCAST(RTCState, dev, dev);
+    RTCState *s = MC146818_RTC(dev);
     if (addr >= 0 && addr <= 127)
         s->cmos_data[addr] = val;
 }
 
 static void rtc_set_date_from_host(ISADevice *dev)
 {
-    RTCState *s = DO_UPCAST(RTCState, dev, dev);
+    RTCState *s = MC146818_RTC(dev);
     struct tm tm;
 
     qemu_get_timedate(&tm, 0);
@@ -737,7 +740,7 @@ static void rtc_notify_clock_reset(Notifier *notifier, void *data)
     RTCState *s = container_of(notifier, RTCState, clock_reset_notifier);
     int64_t now = *(int64_t *)data;
 
-    rtc_set_date_from_host(&s->dev);
+    rtc_set_date_from_host(ISA_DEVICE(s));
     periodic_timer_update(s, now);
     check_update_timer(s);
 #ifdef TARGET_I386
@@ -752,7 +755,7 @@ static void rtc_notify_clock_reset(Notifier *notifier, void *data)
 static void rtc_notify_suspend(Notifier *notifier, void *data)
 {
     RTCState *s = container_of(notifier, RTCState, suspend_notifier);
-    rtc_set_memory(&s->dev, 0xF, 0xFE);
+    rtc_set_memory(ISA_DEVICE(s), 0xF, 0xFE);
 }
 
 static void rtc_reset(void *opaque)
@@ -785,8 +788,7 @@ static const MemoryRegionOps cmos_ops = {
 static void rtc_get_date(Object *obj, Visitor *v, void *opaque,
                          const char *name, Error **errp)
 {
-    ISADevice *isa = ISA_DEVICE(obj);
-    RTCState *s = DO_UPCAST(RTCState, dev, isa);
+    RTCState *s = MC146818_RTC(obj);
     struct tm current_tm;
 
     rtc_update_time(s);
@@ -803,7 +805,7 @@ static void rtc_get_date(Object *obj, Visitor *v, void *opaque,
 
 static int rtc_initfn(ISADevice *dev)
 {
-    RTCState *s = DO_UPCAST(RTCState, dev, dev);
+    RTCState *s = MC146818_RTC(dev);
     int base = 0x70;
 
     s->cmos_data[RTC_REG_A] = 0x26;
@@ -862,19 +864,21 @@ static int rtc_initfn(ISADevice *dev)
 
 ISADevice *rtc_init(ISABus *bus, int base_year, qemu_irq intercept_irq)
 {
-    ISADevice *dev;
+    DeviceState *dev;
+    ISADevice *isadev;
     RTCState *s;
 
-    dev = isa_create(bus, "mc146818rtc");
-    s = DO_UPCAST(RTCState, dev, dev);
-    qdev_prop_set_int32(&dev->qdev, "base_year", base_year);
-    qdev_init_nofail(&dev->qdev);
+    isadev = isa_create(bus, TYPE_MC146818_RTC);
+    dev = DEVICE(isadev);
+    s = MC146818_RTC(isadev);
+    qdev_prop_set_int32(dev, "base_year", base_year);
+    qdev_init_nofail(dev);
     if (intercept_irq) {
         s->irq = intercept_irq;
     } else {
-        isa_init_irq(dev, &s->irq, RTC_ISA_IRQ);
+        isa_init_irq(isadev, &s->irq, RTC_ISA_IRQ);
     }
-    return dev;
+    return isadev;
 }
 
 static Property mc146818rtc_properties[] = {
@@ -894,8 +898,8 @@ static void rtc_class_initfn(ObjectClass *klass, void *data)
     dc->props = mc146818rtc_properties;
 }
 
-static TypeInfo mc146818rtc_info = {
-    .name          = "mc146818rtc",
+static const TypeInfo mc146818rtc_info = {
+    .name          = TYPE_MC146818_RTC,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof(RTCState),
     .class_init    = rtc_class_initfn,
hw/mc146818rtc.h +2 -0
index f286b6a..b00c794 100644
@@ -4,6 +4,8 @@
 #include "isa.h"
 #include "mc146818rtc_regs.h"
 
+#define TYPE_MC146818_RTC "mc146818rtc"
+
 ISADevice *rtc_init(ISABus *bus, int base_year, qemu_irq intercept_irq);
 void rtc_set_memory(ISADevice *dev, int addr, int val);
 void rtc_set_date(ISADevice *dev, const struct tm *tm);
Signature · 1 line
1.7.10.4
#24 lore raw

Re: [Qemu-devel] [RFC 15/34] mc146818rtc: QOM'ify

Am 26.11.2012 01:12, schrieb Andreas Färber:

Quoted 9 lines

Introduce type constant and cast macro to obsolete DO_UPCAST().

Prepares for ISA realizefn.

---
 hw/mc146818rtc.c |   38 +++++++++++++++++++++-----------------
 hw/mc146818rtc.h |    2 ++

2 Dateien geändert, 23 Zeilen hinzugefügt(+), 17 Zeilen entfernt(-)

Applied rebased version to qom-cpu-next (static const was applied throughout the tree, file locations changed; no new conversions):

https://github.com/afaerber/qemu-cpu/commits/qom-cpu-next

Andreas

Quoted 126 lines
hw/mc146818rtc.c +21 -17
index 7d84ce3..c87b7f6 100644
@@ -57,8 +57,11 @@
 #define RTC_CLOCK_RATE            32768
 #define UIP_HOLD_LENGTH           (8 * NSEC_PER_SEC / 32768)
 
+#define MC146818_RTC(obj) OBJECT_CHECK(RTCState, (obj), TYPE_MC146818_RTC)
+
 typedef struct RTCState {
-    ISADevice dev;
+    ISADevice parent_obj;
+
     MemoryRegion io;
     uint8_t cmos_data[128];
     uint8_t cmos_index;
@@ -668,14 +671,14 @@ static uint64_t cmos_ioport_read(void *opaque, hwaddr addr,
 
 void rtc_set_memory(ISADevice *dev, int addr, int val)
 {
-    RTCState *s = DO_UPCAST(RTCState, dev, dev);
+    RTCState *s = MC146818_RTC(dev);
     if (addr >= 0 && addr <= 127)
         s->cmos_data[addr] = val;
 }
 
 static void rtc_set_date_from_host(ISADevice *dev)
 {
-    RTCState *s = DO_UPCAST(RTCState, dev, dev);
+    RTCState *s = MC146818_RTC(dev);
     struct tm tm;
 
     qemu_get_timedate(&tm, 0);
@@ -737,7 +740,7 @@ static void rtc_notify_clock_reset(Notifier *notifier, void *data)
     RTCState *s = container_of(notifier, RTCState, clock_reset_notifier);
     int64_t now = *(int64_t *)data;
 
-    rtc_set_date_from_host(&s->dev);
+    rtc_set_date_from_host(ISA_DEVICE(s));
     periodic_timer_update(s, now);
     check_update_timer(s);
 #ifdef TARGET_I386
@@ -752,7 +755,7 @@ static void rtc_notify_clock_reset(Notifier *notifier, void *data)
 static void rtc_notify_suspend(Notifier *notifier, void *data)
 {
     RTCState *s = container_of(notifier, RTCState, suspend_notifier);
-    rtc_set_memory(&s->dev, 0xF, 0xFE);
+    rtc_set_memory(ISA_DEVICE(s), 0xF, 0xFE);
 }
 
 static void rtc_reset(void *opaque)
@@ -785,8 +788,7 @@ static const MemoryRegionOps cmos_ops = {
 static void rtc_get_date(Object *obj, Visitor *v, void *opaque,
                          const char *name, Error **errp)
 {
-    ISADevice *isa = ISA_DEVICE(obj);
-    RTCState *s = DO_UPCAST(RTCState, dev, isa);
+    RTCState *s = MC146818_RTC(obj);
     struct tm current_tm;
 
     rtc_update_time(s);
@@ -803,7 +805,7 @@ static void rtc_get_date(Object *obj, Visitor *v, void *opaque,
 
 static int rtc_initfn(ISADevice *dev)
 {
-    RTCState *s = DO_UPCAST(RTCState, dev, dev);
+    RTCState *s = MC146818_RTC(dev);
     int base = 0x70;
 
     s->cmos_data[RTC_REG_A] = 0x26;
@@ -862,19 +864,21 @@ static int rtc_initfn(ISADevice *dev)
 
 ISADevice *rtc_init(ISABus *bus, int base_year, qemu_irq intercept_irq)
 {
-    ISADevice *dev;
+    DeviceState *dev;
+    ISADevice *isadev;
     RTCState *s;
 
-    dev = isa_create(bus, "mc146818rtc");
-    s = DO_UPCAST(RTCState, dev, dev);
-    qdev_prop_set_int32(&dev->qdev, "base_year", base_year);
-    qdev_init_nofail(&dev->qdev);
+    isadev = isa_create(bus, TYPE_MC146818_RTC);
+    dev = DEVICE(isadev);
+    s = MC146818_RTC(isadev);
+    qdev_prop_set_int32(dev, "base_year", base_year);
+    qdev_init_nofail(dev);
     if (intercept_irq) {
         s->irq = intercept_irq;
     } else {
-        isa_init_irq(dev, &s->irq, RTC_ISA_IRQ);
+        isa_init_irq(isadev, &s->irq, RTC_ISA_IRQ);
     }
-    return dev;
+    return isadev;
 }
 
 static Property mc146818rtc_properties[] = {
@@ -894,8 +898,8 @@ static void rtc_class_initfn(ObjectClass *klass, void *data)
     dc->props = mc146818rtc_properties;
 }
 
-static TypeInfo mc146818rtc_info = {
-    .name          = "mc146818rtc",
+static const TypeInfo mc146818rtc_info = {
+    .name          = TYPE_MC146818_RTC,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof(RTCState),
     .class_init    = rtc_class_initfn,
hw/mc146818rtc.h +2 -0
index f286b6a..b00c794 100644
@@ -4,6 +4,8 @@
 #include "isa.h"
 #include "mc146818rtc_regs.h"
 
+#define TYPE_MC146818_RTC "mc146818rtc"
+
 ISADevice *rtc_init(ISABus *bus, int base_year, qemu_irq intercept_irq);
 void rtc_set_memory(ISADevice *dev, int addr, int val);
 void rtc_set_date(ISADevice *dev, const struct tm *tm);
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#25 lore raw

RFC 16/34 ne2000-isa: QOM'ify

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST().

Prepares for ISA realizefn.

---
 hw/ne2000-isa.c |   12 ++++++++----

1 Datei geändert, 8 Zeilen hinzugefügt(+), 4 Zeilen entfernt(-)

hw/ne2000-isa.c +8 -4
index 69982a9..5aabe7c 100644
@@ -29,8 +29,12 @@
 #include "ne2000.h"
 #include "exec-memory.h"
 
+#define TYPE_ISA_NE2000 "ne2k_isa"
+#define ISA_NE2000(obj) OBJECT_CHECK(ISANE2000State, (obj), TYPE_ISA_NE2000)
+
 typedef struct ISANE2000State {
-    ISADevice dev;
+    ISADevice parent_obj;
+
     uint32_t iobase;
     uint32_t isairq;
     NE2000State ne2000;
@@ -64,7 +68,7 @@ static const VMStateDescription vmstate_isa_ne2000 = {
 
 static int isa_ne2000_initfn(ISADevice *dev)
 {
-    ISANE2000State *isa = DO_UPCAST(ISANE2000State, dev, dev);
+    ISANE2000State *isa = ISA_NE2000(dev);
     NE2000State *s = &isa->ne2000;
 
     ne2000_setup_io(s, 0x20);
@@ -97,8 +101,8 @@ static void isa_ne2000_class_initfn(ObjectClass *klass, void *data)
     dc->props = ne2000_isa_properties;
 }
 
-static TypeInfo ne2000_isa_info = {
-    .name          = "ne2k_isa",
+static const TypeInfo ne2000_isa_info = {
+    .name          = TYPE_ISA_NE2000,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof(ISANE2000State),
     .class_init    = isa_ne2000_class_initfn,
Signature · 1 line
1.7.10.4
#26 lore raw

RFC 17/34 parallel: QOM'ify

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST().

Prepares for ISA realizefn.

---
 hw/parallel.c |   13 +++++++++----

1 Datei geändert, 9 Zeilen hinzugefügt(+), 4 Zeilen entfernt(-)

hw/parallel.c +9 -4
index c4705bc..65447d3 100644
@@ -80,8 +80,13 @@ typedef struct ParallelState {
     int it_shift;
 } ParallelState;
 
+#define TYPE_ISA_PARALLEL "isa-parallel"
+#define ISA_PARALLEL(obj) \
+    OBJECT_CHECK(ISAParallelState, (obj), TYPE_ISA_PARALLEL)
+
 typedef struct ISAParallelState {
-    ISADevice dev;
+    ISADevice parent_obj;
+
     uint32_t index;
     uint32_t iobase;
     uint32_t isairq;
@@ -475,7 +480,7 @@ static const MemoryRegionPortio isa_parallel_portio_sw_list[] = {
 static int parallel_isa_initfn(ISADevice *dev)
 {
     static int index;
-    ISAParallelState *isa = DO_UPCAST(ISAParallelState, dev, dev);
+    ISAParallelState *isa = ISA_PARALLEL(dev);
     ParallelState *s = &isa->state;
     int base;
     uint8_t dummy;
@@ -599,8 +604,8 @@ static void parallel_isa_class_initfn(ObjectClass *klass, void *data)
     dc->props = parallel_isa_properties;
 }
 
-static TypeInfo parallel_isa_info = {
-    .name          = "isa-parallel",
+static const TypeInfo parallel_isa_info = {
+    .name          = TYPE_ISA_PARALLEL,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof(ISAParallelState),
     .class_init    = parallel_isa_class_initfn,
Signature · 1 line
1.7.10.4
#27 lore raw

RFC 18/34 pc: QOM'ify port 92

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST().

Prepares for ISA realizefn.

---
 hw/pc.c |   16 ++++++++++------

1 Datei geändert, 10 Zeilen hinzugefügt(+), 6 Zeilen entfernt(-)

hw/pc.c +10 -6
index 5fc2076..e878106 100644
@@ -413,9 +413,13 @@ void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
     qemu_register_reset(pc_cmos_init_late, &arg);
 }
 
+#define TYPE_PORT92 "port92"
+#define PORT92(obj) OBJECT_CHECK(Port92State, (obj), TYPE_PORT92)
+
 /* port 92 stuff: could be split off */
 typedef struct Port92State {
-    ISADevice dev;
+    ISADevice parent_obj;
+
     MemoryRegion io;
     uint8_t outport;
     qemu_irq *a20_out;
@@ -447,7 +451,7 @@ static uint64_t port92_read(void *opaque, hwaddr addr,
 
 static void port92_init(ISADevice *dev, qemu_irq *a20_out)
 {
-    Port92State *s = DO_UPCAST(Port92State, dev, dev);
+    Port92State *s = PORT92(dev);
 
     s->a20_out = a20_out;
 }
@@ -465,7 +469,7 @@ static const VMStateDescription vmstate_port92_isa = {
 
 static void port92_reset(DeviceState *d)
 {
-    Port92State *s = container_of(d, Port92State, dev.qdev);
+    Port92State *s = PORT92(d);
 
     s->outport &= ~1;
 }
@@ -482,7 +486,7 @@ static const MemoryRegionOps port92_ops = {
 
 static int port92_initfn(ISADevice *dev)
 {
-    Port92State *s = DO_UPCAST(Port92State, dev, dev);
+    Port92State *s = PORT92(dev);
 
     memory_region_init_io(&s->io, &port92_ops, s, "port92", 1);
     isa_register_ioport(dev, &s->io, 0x92);
@@ -501,8 +505,8 @@ static void port92_class_initfn(ObjectClass *klass, void *data)
     dc->vmsd = &vmstate_port92_isa;
 }
 
-static TypeInfo port92_info = {
-    .name          = "port92",
+static const TypeInfo port92_info = {
+    .name          = TYPE_PORT92,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof(Port92State),
     .class_init    = port92_class_initfn,
Signature · 1 line
1.7.10.4
#28 lore raw

RFC 19/34 pckbd: QOM'ify

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST().

Prepares for ISA realizefn.

---
 hw/pckbd.c |   18 ++++++++++++------

1 Datei geändert, 12 Zeilen hinzugefügt(+), 6 Zeilen entfernt(-)

hw/pckbd.c +12 -6
index 5bb3e0a..a3291ec 100644
@@ -431,8 +431,12 @@ void i8042_mm_init(qemu_irq kbd_irq, qemu_irq mouse_irq,
     qemu_register_reset(kbd_reset, s);
 }
 
+#define TYPE_I8042 "i8042"
+#define I8042(obj) OBJECT_CHECK(ISAKBDState, (obj), TYPE_I8042)
+
 typedef struct ISAKBDState {
-    ISADevice dev;
+    ISADevice parent_obj;
+
     KBDState kbd;
     MemoryRegion io[2];
 } ISAKBDState;
@@ -440,14 +444,16 @@ typedef struct ISAKBDState {
 void i8042_isa_mouse_fake_event(void *opaque)
 {
     ISADevice *dev = opaque;
-    KBDState *s = &(DO_UPCAST(ISAKBDState, dev, dev)->kbd);
+    ISAKBDState *isa = I8042(dev);
+    KBDState *s = &isa->kbd;
 
     ps2_mouse_fake_event(s->mouse);
 }
 
 void i8042_setup_a20_line(ISADevice *dev, qemu_irq *a20_out)
 {
-    KBDState *s = &(DO_UPCAST(ISAKBDState, dev, dev)->kbd);
+    ISAKBDState *isa = I8042(dev);
+    KBDState *s = &isa->kbd;
 
     s->a20_out = a20_out;
 }
@@ -485,7 +491,7 @@ static const MemoryRegionOps i8042_cmd_ops = {
 
 static int i8042_initfn(ISADevice *dev)
 {
-    ISAKBDState *isa_s = DO_UPCAST(ISAKBDState, dev, dev);
+    ISAKBDState *isa_s = I8042(dev);
     KBDState *s = &isa_s->kbd;
 
     isa_init_irq(dev, &s->irq_kbd, 1);
@@ -512,8 +518,8 @@ static void i8042_class_initfn(ObjectClass *klass, void *data)
     dc->vmsd = &vmstate_kbd_isa;
 }
 
-static TypeInfo i8042_info = {
-    .name          = "i8042",
+static const TypeInfo i8042_info = {
+    .name          = TYPE_I8042,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof(ISAKBDState),
     .class_init    = i8042_class_initfn,
Signature · 1 line
1.7.10.4
#29 lore raw

RFC 20/34 pcspk: QOM'ify

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST().

Prepares for ISA realizefn.

---
 hw/pcspk.c |   11 +++++++----
 hw/pcspk.h |    4 +++-

2 Dateien geändert, 10 Zeilen hinzugefügt(+), 5 Zeilen entfernt(-)

hw/pcspk.c +7 -4
index ad6491b..f800962 100644
@@ -35,8 +35,11 @@
 #define PCSPK_MAX_FREQ (PCSPK_SAMPLE_RATE >> 1)
 #define PCSPK_MIN_COUNT ((PIT_FREQ + PCSPK_MAX_FREQ - 1) / PCSPK_MAX_FREQ)
 
+#define PC_SPEAKER(obj) OBJECT_CHECK(PCSpkState, (obj), TYPE_PC_SPEAKER)
+
 typedef struct {
-    ISADevice dev;
+    ISADevice parent_obj;
+
     MemoryRegion ioport;
     uint32_t iobase;
     uint8_t sample_buf[PCSPK_BUF_LEN];
@@ -161,7 +164,7 @@ static const MemoryRegionOps pcspk_io_ops = {
 
 static int pcspk_initfn(ISADevice *dev)
 {
-    PCSpkState *s = DO_UPCAST(PCSpkState, dev, dev);
+    PCSpkState *s = PC_SPEAKER(dev);
 
     memory_region_init_io(&s->ioport, &pcspk_io_ops, s, "elcr", 1);
     isa_register_ioport(dev, &s->ioport, s->iobase);
@@ -187,8 +190,8 @@ static void pcspk_class_initfn(ObjectClass *klass, void *data)
     dc->props = pcspk_properties;
 }
 
-static TypeInfo pcspk_info = {
-    .name           = "isa-pcspk",
+static const TypeInfo pcspk_info = {
+    .name           = TYPE_PC_SPEAKER,
     .parent         = TYPE_ISA_DEVICE,
     .instance_size  = sizeof(PCSpkState),
     .class_init     = pcspk_class_initfn,
hw/pcspk.h +3 -1
index 7f42bac..1ec7c41 100644
@@ -28,11 +28,13 @@
 #include "hw.h"
 #include "isa.h"
 
+#define TYPE_PC_SPEAKER "isa-pcspk"
+
 static inline ISADevice *pcspk_init(ISABus *bus, ISADevice *pit)
 {
     ISADevice *dev;
 
-    dev = isa_create(bus, "isa-pcspk");
+    dev = isa_create(bus, TYPE_PC_SPEAKER);
     qdev_prop_set_uint32(&dev->qdev, "iobase", 0x61);
     qdev_prop_set_ptr(&dev->qdev, "pit", pit);
     qdev_init_nofail(&dev->qdev);
Signature · 1 line
1.7.10.4
#30 lore raw

RFC 21/34 sb16: QOM'ify

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST().

Prepares for ISA realizefn.

---
 hw/sb16.c |   16 +++++++++-------

1 Datei geändert, 9 Zeilen hinzugefügt(+), 7 Zeilen entfernt(-)

hw/sb16.c +9 -7
index 523ab0d..b7e93a4 100644
@@ -47,8 +47,12 @@
 
 static const char e3[] = "COPYRIGHT (C) CREATIVE TECHNOLOGY LTD, 1992.";
 
+#define TYPE_SB16 "sb16"
+#define SB16(obj) OBJECT_CHECK (SB16State, (obj), TYPE_SB16)
+
 typedef struct SB16State {
-    ISADevice dev;
+    ISADevice parent_obj;
+
     QEMUSoundCard card;
     qemu_irq pic;
     uint32_t irq;
@@ -1354,9 +1358,7 @@ static const MemoryRegionPortio sb16_ioport_list[] = {
 
 static int sb16_initfn (ISADevice *dev)
 {
-    SB16State *s;
-
-    s = DO_UPCAST (SB16State, dev, dev);
+    SB16State *s = SB16 (dev);
 
     s->cmd = -1;
     isa_init_irq (dev, &s->pic, s->irq);
@@ -1386,7 +1388,7 @@ static int sb16_initfn (ISADevice *dev)
 
 int SB16_init (ISABus *bus)
 {
-    isa_create_simple (bus, "sb16");
+    isa_create_simple (bus, TYPE_SB16);
     return 0;
 }
 
@@ -1409,8 +1411,8 @@ static void sb16_class_initfn (ObjectClass *klass, void *data)
     dc->props = sb16_properties;
 }
 
-static TypeInfo sb16_info = {
-    .name          = "sb16",
+static const TypeInfo sb16_info = {
+    .name          = TYPE_SB16,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof (SB16State),
     .class_init    = sb16_class_initfn,
Signature · 1 line
1.7.10.4
#31 lore raw

RFC 22/34 serial: QOM'ify ISA serial

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST().

Prepares for ISA realizefn.

---
 hw/serial-isa.c |   13 ++++++++-----
 hw/serial.h     |    1 +

2 Dateien geändert, 9 Zeilen hinzugefügt(+), 5 Zeilen entfernt(-)

hw/serial-isa.c +8 -5
index 96c78f7..904cc41 100644
@@ -26,8 +26,11 @@
 #include "serial.h"
 #include "isa.h"
 
+#define ISA_SERIAL(obj) OBJECT_CHECK(ISASerialState, (obj), TYPE_ISA_SERIAL)
+
 typedef struct ISASerialState {
-    ISADevice dev;
+    ISADevice parent_obj;
+
     uint32_t index;
     uint32_t iobase;
     uint32_t isairq;
@@ -44,7 +47,7 @@ static const int isa_serial_irq[MAX_SERIAL_PORTS] = {
 static int serial_isa_initfn(ISADevice *dev)
 {
     static int index;
-    ISASerialState *isa = DO_UPCAST(ISASerialState, dev, dev);
+    ISASerialState *isa = ISA_SERIAL(dev);
     SerialState *s = &isa->state;
 
     if (isa->index == -1) {
@@ -99,8 +102,8 @@ static void serial_isa_class_initfn(ObjectClass *klass, void *data)
     dc->props = serial_isa_properties;
 }
 
-static TypeInfo serial_isa_info = {
-    .name          = "isa-serial",
+static const TypeInfo serial_isa_info = {
+    .name          = TYPE_ISA_SERIAL,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof(ISASerialState),
     .class_init    = serial_isa_class_initfn,
@@ -117,7 +120,7 @@ bool serial_isa_init(ISABus *bus, int index, CharDriverState *chr)
 {
     ISADevice *dev;
 
-    dev = isa_try_create(bus, "isa-serial");
+    dev = isa_try_create(bus, TYPE_ISA_SERIAL);
     if (!dev) {
         return false;
     }
hw/serial.h +1 -0
index ed1a5cd..bb06366 100644
@@ -96,4 +96,5 @@ SerialState *serial_mm_init(MemoryRegion *address_space,
                             CharDriverState *chr, enum device_endian end);
 
 /* serial-isa.c */
+#define TYPE_ISA_SERIAL "isa-serial"
 bool serial_isa_init(ISABus *bus, int index, CharDriverState *chr);
Signature · 1 line
1.7.10.4
#32 lore raw

RFC 23/34 sga: QOM'ify

In reply to Andreas Färber

Introduce type constant and cast macro.

Prepares for ISA realizefn.

---
 hw/sga.c |   12 ++++++++----

1 Datei geändert, 8 Zeilen hinzugefügt(+), 4 Zeilen entfernt(-)

hw/sga.c +8 -4
index a666349..d828f45 100644
@@ -31,8 +31,11 @@
 
 #define SGABIOS_FILENAME "sgabios.bin"
 
-typedef struct ISAGAState {
-    ISADevice dev;
+#define TYPE_SGA "sga"
+#define SGA(obj) OBJECT_CHECK(ISASGAState, (obj), TYPE_SGA)
+
+typedef struct ISASGAState {
+    ISADevice parent_obj;
 } ISASGAState;
 
 static int sga_initfn(ISADevice *dev)
@@ -40,6 +43,7 @@ static int sga_initfn(ISADevice *dev)
     rom_add_vga(SGABIOS_FILENAME);
     return 0;
 }
+
 static void sga_class_initfn(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -48,8 +52,8 @@ static void sga_class_initfn(ObjectClass *klass, void *data)
     dc->desc = "Serial Graphics Adapter";
 }
 
-static TypeInfo sga_info = {
-    .name          = "sga",
+static const TypeInfo sga_info = {
+    .name          = TYPE_SGA,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof(ISASGAState),
     .class_init    = sga_class_initfn,
Signature · 1 line
1.7.10.4
#33 lore raw

RFC 24/34 vga-isa: QOM'ify ISA VGA

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST() and container_of(). Prepares for ISA realizefn.

Unify function naming scheme while at it.

---
 hw/vga-isa.c |   29 +++++++++++++++++------------

1 Datei geändert, 17 Zeilen hinzugefügt(+), 12 Zeilen entfernt(-)

hw/vga-isa.c +17 -12
index 046602b..f177c48 100644
@@ -31,14 +31,18 @@
 #include "qemu-timer.h"
 #include "loader.h"
 
+#define TYPE_ISA_VGA "isa-vga"
+#define ISA_VGA(obj) OBJECT_CHECK(ISAVGAState, (obj), TYPE_ISA_VGA)
+
 typedef struct ISAVGAState {
-    ISADevice dev;
+    ISADevice parent_obj;
+
     struct VGACommonState state;
 } ISAVGAState;
 
-static void vga_reset_isa(DeviceState *dev)
+static void vga_isa_reset(DeviceState *dev)
 {
-    ISAVGAState *d = container_of(dev, ISAVGAState, dev.qdev);
+    ISAVGAState *d = ISA_VGA(dev);
     VGACommonState *s = &d->state;
 
     vga_common_reset(s);
@@ -46,7 +50,7 @@ static void vga_reset_isa(DeviceState *dev)
 
 static int vga_initfn(ISADevice *dev)
 {
-    ISAVGAState *d = DO_UPCAST(ISAVGAState, dev, dev);
+    ISAVGAState *d = ISA_VGA(dev);
     VGACommonState *s = &d->state;
     MemoryRegion *vga_io_memory;
     const MemoryRegionPortio *vga_ports, *vbe_ports;
@@ -76,26 +80,27 @@ static Property vga_isa_properties[] = {
     DEFINE_PROP_END_OF_LIST(),
 };
 
-static void vga_class_initfn(ObjectClass *klass, void *data)
+static void vga_isa_class_initfn(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+
     ic->init = vga_initfn;
-    dc->reset = vga_reset_isa;
+    dc->reset = vga_isa_reset;
     dc->vmsd = &vmstate_vga_common;
     dc->props = vga_isa_properties;
 }
 
-static TypeInfo vga_info = {
-    .name          = "isa-vga",
+static const TypeInfo vga_isa_info = {
+    .name          = TYPE_ISA_VGA,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof(ISAVGAState),
-    .class_init    = vga_class_initfn,
+    .class_init    = vga_isa_class_initfn,
 };
 
-static void vga_register_types(void)
+static void vga_isa_register_types(void)
 {
-    type_register_static(&vga_info);
+    type_register_static(&vga_isa_info);
 }
 
-type_init(vga_register_types)
+type_init(vga_isa_register_types)
Signature · 1 line
1.7.10.4
#34 lore raw

RFC 25/34 vmmouse: QOM'ify

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST() and container_of(). Prepares for ISA realizefn.

Remove reserved underscore from struct name while at it.

---
 hw/vmmouse.c |   16 ++++++++++------

1 Datei geändert, 10 Zeilen hinzugefügt(+), 6 Zeilen entfernt(-)

hw/vmmouse.c +10 -6
index 6338efa..7c7c4e4 100644
@@ -51,9 +51,13 @@
 #define DPRINTF(fmt, ...) do { } while (0)
 #endif
 
-typedef struct _VMMouseState
+#define TYPE_VMMOUSE "vmmouse"
+#define VMMOUSE(obj) OBJECT_CHECK(VMMouseState, (obj), TYPE_VMMOUSE)
+
+typedef struct VMMouseState
 {
-    ISADevice dev;
+    ISADevice parent_obj;
+
     uint32_t queue[VMMOUSE_QUEUE_SIZE];
     int32_t queue_size;
     uint16_t nb_queue;
@@ -250,7 +254,7 @@ static const VMStateDescription vmstate_vmmouse = {
 
 static void vmmouse_reset(DeviceState *d)
 {
-    VMMouseState *s = container_of(d, VMMouseState, dev.qdev);
+    VMMouseState *s = VMMOUSE(d);
 
     s->status = 0xffff;
     s->queue_size = VMMOUSE_QUEUE_SIZE;
@@ -260,7 +264,7 @@ static void vmmouse_reset(DeviceState *d)
 
 static int vmmouse_initfn(ISADevice *dev)
 {
-    VMMouseState *s = DO_UPCAST(VMMouseState, dev, dev);
+    VMMouseState *s = VMMOUSE(dev);
 
     DPRINTF("vmmouse_init\n");
 
@@ -287,8 +291,8 @@ static void vmmouse_class_initfn(ObjectClass *klass, void *data)
     dc->props = vmmouse_properties;
 }
 
-static TypeInfo vmmouse_info = {
-    .name          = "vmmouse",
+static const TypeInfo vmmouse_info = {
+    .name          = TYPE_VMMOUSE,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof(VMMouseState),
     .class_init    = vmmouse_class_initfn,
Signature · 1 line
1.7.10.4
#35 lore raw

RFC 26/34 vmport: QOM'ify

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST(). Prepares for ISA realizefn.

Drop reserved underscore from struct name while at it.

---
 hw/vmport.c |   14 +++++++++-----

1 Datei geändert, 9 Zeilen hinzugefügt(+), 5 Zeilen entfernt(-)

hw/vmport.c +9 -5
index 3ab3a14..ec36d47 100644
@@ -35,9 +35,13 @@
 #define VMPORT_ENTRIES 0x2c
 #define VMPORT_MAGIC   0x564D5868
 
-typedef struct _VMPortState
+#define TYPE_VMPORT "vmport"
+#define VMPORT(obj) OBJECT_CHECK(VMPortState, (obj), TYPE_VMPORT)
+
+typedef struct VMPortState
 {
-    ISADevice dev;
+    ISADevice parent_obj;
+
     MemoryRegion io;
     IOPortReadFunc *func[VMPORT_ENTRIES];
     void *opaque[VMPORT_ENTRIES];
@@ -135,7 +139,7 @@ static const MemoryRegionOps vmport_ops = {
 
 static int vmport_initfn(ISADevice *dev)
 {
-    VMPortState *s = DO_UPCAST(VMPortState, dev, dev);
+    VMPortState *s = VMPORT(dev);
 
     memory_region_init_io(&s->io, &vmport_ops, s, "vmport", 1);
     isa_register_ioport(dev, &s->io, 0x5658);
@@ -155,8 +159,8 @@ static void vmport_class_initfn(ObjectClass *klass, void *data)
     dc->no_user = 1;
 }
 
-static TypeInfo vmport_info = {
-    .name          = "vmport",
+static const TypeInfo vmport_info = {
+    .name          = TYPE_VMPORT,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof(VMPortState),
     .class_init    = vmport_class_initfn,
Signature · 1 line
1.7.10.4
#36 lore raw

RFC 27/34 wdt_ib700: QOM'ify

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST().

Prepares for ISA realizefn.

---
 hw/wdt_ib700.c |   14 +++++++++-----

1 Datei geändert, 9 Zeilen hinzugefügt(+), 5 Zeilen entfernt(-)

hw/wdt_ib700.c +9 -5
index 7f6c21d..1365898 100644
@@ -35,8 +35,12 @@
 #define ib700_debug(fs,...)
 #endif
 
+#define TYPE_IB700 "ib700"
+#define IB700(obj) OBJECT_CHECK(IB700State, (obj), TYPE_IB700)
+
 typedef struct IB700state {
-    ISADevice dev;
+    ISADevice parent_obj;
+
     QEMUTimer *timer;
 } IB700State;
 
@@ -95,7 +99,7 @@ static const VMStateDescription vmstate_ib700 = {
 
 static int wdt_ib700_init(ISADevice *dev)
 {
-    IB700State *s = DO_UPCAST(IB700State, dev, dev);
+    IB700State *s = IB700(dev);
 
     ib700_debug("watchdog init\n");
 
@@ -108,7 +112,7 @@ static int wdt_ib700_init(ISADevice *dev)
 
 static void wdt_ib700_reset(DeviceState *dev)
 {
-    IB700State *s = DO_UPCAST(IB700State, dev.qdev, dev);
+    IB700State *s = IB700(dev);
 
     ib700_debug("watchdog reset\n");
 
@@ -129,8 +133,8 @@ static void wdt_ib700_class_init(ObjectClass *klass, void *data)
     dc->vmsd = &vmstate_ib700;
 }
 
-static TypeInfo wdt_ib700_info = {
-    .name          = "ib700",
+static const TypeInfo wdt_ib700_info = {
+    .name          = TYPE_IB700,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof(IB700State),
     .class_init    = wdt_ib700_class_init,
Signature · 1 line
1.7.10.4
#37 lore raw

RFC 28/34 isa: Use realizefn for ISADevice

In reply to Andreas Färber

Drop ISADeviceClass::init and the resulting no-op initfn and let children implement their own realizefn. Adapt error handling.

---
 hw/applesmc.c     |   10 ++++------
 hw/cirrus_vga.c   |   10 +++++-----
 hw/debugcon.c     |   21 +++++++++++++--------
 hw/fdc.c          |   24 ++++++++++++++----------
 hw/i82374.c       |   13 +++++--------
 hw/i8254_common.c |   15 +++++++--------
 hw/i8259_common.c |    9 +++------
 hw/ide/isa.c      |   16 ++++++++--------
 hw/isa-bus.c      |   13 -------------
 hw/isa.h          |    1 -
 hw/m48t59.c       |   17 ++++++++---------
 hw/mc146818rtc.c  |   18 +++++++++---------
 hw/ne2000-isa.c   |   15 +++++++--------
 hw/parallel.c     |   29 +++++++++++++++++------------
 hw/pc.c           |   10 +++++-----
 hw/pckbd.c        |   16 ++++++++--------
 hw/pcspk.c        |   10 ++++------
 hw/sb16.c         |   21 ++++++++++++++-------
 hw/serial-isa.c   |   20 +++++++++++---------
 hw/serial-pci.c   |    4 ++--
 hw/serial.c       |    6 +++---
 hw/serial.h       |    2 +-
 hw/sga.c          |    7 +++----
 hw/vga-isa.c      |   17 ++++++++---------
 hw/vmmouse.c      |    8 +++-----
 hw/vmport.c       |   10 +++++-----
 hw/wdt_ib700.c    |    8 +++-----

27 Dateien geändert, 170 Zeilen hinzugefügt(+), 180 Zeilen entfernt(-)

hw/applesmc.c +4 -6
index d6e556b..b7b32f2 100644
@@ -201,7 +201,7 @@ static void qdev_applesmc_isa_reset(DeviceState *dev)
     applesmc_add_key(s, "MSSD", 1, "\0x3");
 }
 
-static int applesmc_isa_init(ISADevice *dev)
+static void applesmc_isa_realize(DeviceState *dev, Error **err)
 {
     AppleSMCState *s = APPLE_SMC(dev);
 
@@ -220,9 +220,7 @@ static int applesmc_isa_init(ISADevice *dev)
     }
 
     QLIST_INIT(&s->data_def);
-    qdev_applesmc_isa_reset(&dev->qdev);
-
-    return 0;
+    qdev_applesmc_isa_reset(dev);
 }
 
 static Property applesmc_isa_properties[] = {
@@ -235,8 +233,8 @@ static Property applesmc_isa_properties[] = {
 static void qdev_applesmc_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
-    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
-    ic->init = applesmc_isa_init;
+
+    dc->realize = applesmc_isa_realize;
     dc->reset = qdev_applesmc_isa_reset;
     dc->props = applesmc_isa_properties;
 }
hw/cirrus_vga.c +5 -5
index 9687b6b..d4128ce 100644
@@ -2905,21 +2905,22 @@ static void cirrus_init_common(CirrusVGAState * s, int device_id, int is_pci,
  *
  ***************************************/
 
-static int vga_initfn(ISADevice *dev)
+static void isa_cirrus_vga_realizefn(DeviceState *dev, Error **err)
 {
+    ISADevice *isadev = ISA_DEVICE(dev);
     ISACirrusVGAState *d = ISA_CIRRUS_VGA(dev);
     VGACommonState *s = &d->cirrus_vga.vga;
 
     vga_common_init(s);
     cirrus_init_common(&d->cirrus_vga, CIRRUS_ID_CLGD5430, 0,
-                       isa_address_space(dev), isa_address_space_io(dev));
+                       isa_address_space(isadev),
+                       isa_address_space_io(isadev));
     s->ds = graphic_console_init(s->update, s->invalidate,
                                  s->screen_dump, s->text_update,
                                  s);
     rom_add_vga(VGABIOS_CIRRUS_FILENAME);
     /* XXX ISA-LFB support */
     /* FIXME not qdev yet */
-    return 0;
 }
 
 static Property isa_cirrus_vga_properties[] = {
@@ -2930,11 +2931,10 @@ static Property isa_cirrus_vga_properties[] = {
 
 static void isa_cirrus_vga_class_init(ObjectClass *klass, void *data)
 {
-    ISADeviceClass *k = ISA_DEVICE_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
 
     dc->vmsd  = &vmstate_cirrus_vga;
-    k->init   = vga_initfn;
+    dc->realize = isa_cirrus_vga_realizefn;
     dc->props = isa_cirrus_vga_properties;
 }
 
hw/debugcon.c +13 -8
index 02846ed..4cfc96e 100644
@@ -71,25 +71,30 @@ static uint32_t debugcon_ioport_read(void *opaque, uint32_t addr)
     return s->readback;
 }
 
-static void debugcon_init_core(DebugconState *s)
+static void debugcon_realize_core(DebugconState *s, Error **err)
 {
     if (!s->chr) {
-        fprintf(stderr, "Can't create debugcon device, empty char device\n");
-        exit(1);
+        error_setg(err, "Can't create debugcon device, empty char device\n");
+        return;
     }
 
     qemu_chr_add_handlers(s->chr, NULL, NULL, NULL, s);
 }
 
-static int debugcon_isa_initfn(ISADevice *dev)
+static void debugcon_isa_realizefn(DeviceState *dev, Error **err)
 {
     ISADebugconState *isa = ISA_DEBUG_CONSOLE(dev);
     DebugconState *s = &isa->state;
+    Error *local_err = NULL;
 
-    debugcon_init_core(s);
+    debugcon_realize_core(s, &local_err);
+    if (local_err != NULL) {
+        qerror_report_err(local_err);
+        error_propagate(err, local_err);
+        return;
+    }
     register_ioport_write(isa->iobase, 1, 1, debugcon_ioport_write, s);
     register_ioport_read(isa->iobase, 1, 1, debugcon_ioport_read, s);
-    return 0;
 }
 
 static Property debugcon_isa_properties[] = {
@@ -102,8 +107,8 @@ static Property debugcon_isa_properties[] = {
 static void debugcon_isa_class_initfn(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
-    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
-    ic->init = debugcon_isa_initfn;
+
+    dc->realize = debugcon_isa_realizefn;
     dc->props = debugcon_isa_properties;
 }
 
hw/fdc.c +14 -10
index edd7483..3ab3671 100644
@@ -2118,24 +2118,28 @@ static const MemoryRegionPortio fdc_portio_list[] = {
     PORTIO_END_OF_LIST(),
 };
 
-static int isabus_fdc_init1(ISADevice *dev)
+static void isabus_fdc_realize(DeviceState *dev, Error **err)
 {
+    ISADevice *isadev = ISA_DEVICE(dev);
     FDCtrlISABus *isa = ISA_FDC(dev);
     FDCtrl *fdctrl = &isa->state;
     int ret;
 
-    isa_register_portio_list(dev, isa->iobase, fdc_portio_list, fdctrl, "fdc");
+    isa_register_portio_list(isadev, isa->iobase, fdc_portio_list, fdctrl,
+                             "fdc");
 
-    isa_init_irq(dev, &fdctrl->irq, isa->irq);
+    isa_init_irq(isadev, &fdctrl->irq, isa->irq);
     fdctrl->dma_chann = isa->dma;
 
-    qdev_set_legacy_instance_id(&dev->qdev, isa->iobase, 2);
+    qdev_set_legacy_instance_id(dev, isa->iobase, 2);
     ret = fdctrl_init_common(fdctrl);
+    if (ret < 0) {
+        error_setg(err, "Floppy init failed.");
+        return;
+    }
 
-    add_boot_device_path(isa->bootindexA, &dev->qdev, "/floppy@0");
-    add_boot_device_path(isa->bootindexB, &dev->qdev, "/floppy@1");
-
-    return ret;
+    add_boot_device_path(isa->bootindexA, dev, "/floppy@0");
+    add_boot_device_path(isa->bootindexB, dev, "/floppy@1");
 }
 
 static int sysbus_fdc_init1(SysBusDevice *dev)
@@ -2204,8 +2208,8 @@ static Property isa_fdc_properties[] = {
 static void isabus_fdc_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
-    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
-    ic->init = isabus_fdc_init1;
+
+    dc->realize = isabus_fdc_realize;
     dc->fw_name = "fdc";
     dc->no_user = 1;
     dc->reset = fdctrl_external_reset_isa;
hw/i82374.c +5 -8
index 82de0b0..bf8b574 100644
@@ -98,7 +98,7 @@ static uint32_t i82374_read_descriptor(void *opaque, uint32_t nport)
     return val;
 }
 
-static void i82374_init(I82374State *s)
+static void i82374_realize(I82374State *s, Error **err)
 {
     DMA_init(1, &s->out);
     memset(s->commands, 0, sizeof(s->commands));
@@ -124,7 +124,7 @@ static const VMStateDescription vmstate_isa_i82374 = {
     },
 };
 
-static int i82374_isa_init(ISADevice *dev)
+static void i82374_isa_realize(DeviceState *dev, Error **err)
 {
     ISAi82374State *isa = I82374(dev);
     I82374State *s = &isa->state;
@@ -135,11 +135,9 @@ static int i82374_isa_init(ISADevice *dev)
     register_ioport_write(isa->iobase + 0x20, 0x20, 1, i82374_write_descriptor, s);
     register_ioport_read(isa->iobase + 0x20, 0x20, 1, i82374_read_descriptor, s);
 
-    i82374_init(s);
+    i82374_realize(s, err);
 
-    qdev_init_gpio_out(&dev->qdev, &s->out, 1);
-
-    return 0;
+    qdev_init_gpio_out(dev, &s->out, 1);
 }
 
 static Property i82374_properties[] = {
@@ -149,10 +147,9 @@ static Property i82374_properties[] = {
 
 static void i82374_class_init(ObjectClass *klass, void *data)
 {
-    ISADeviceClass *k = ISA_DEVICE_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
     
-    k->init  = i82374_isa_init;
+    dc->realize = i82374_isa_realize;
     dc->vmsd = &vmstate_isa_i82374;
     dc->props = i82374_properties;
 }
hw/i8254_common.c +7 -8
index a03d7cd..1883405 100644
@@ -166,22 +166,22 @@ void pit_reset_common(PITCommonState *pit)
     }
 }
 
-static int pit_init_common(ISADevice *dev)
+static void pit_common_realize(DeviceState *dev, Error **err)
 {
+    ISADevice *isadev = ISA_DEVICE(dev);
     PITCommonState *pit = PIT_COMMON(dev);
     PITCommonClass *c = PIT_COMMON_GET_CLASS(pit);
     int ret;
 
     ret = c->init(pit);
     if (ret < 0) {
-        return ret;
+        error_setg(err, "PIT init failed.");
+        return;
     }
 
-    isa_register_ioport(dev, &pit->ioports, pit->iobase);
+    isa_register_ioport(isadev, &pit->ioports, pit->iobase);
 
-    qdev_set_legacy_instance_id(&dev->qdev, pit->iobase, 2);
-
-    return 0;
+    qdev_set_legacy_instance_id(dev, pit->iobase, 2);
 }
 
 static const VMStateDescription vmstate_pit_channel = {
@@ -286,10 +286,9 @@ static const VMStateDescription vmstate_pit_common = {
 
 static void pit_common_class_init(ObjectClass *klass, void *data)
 {
-    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
 
-    ic->init = pit_init_common;
+    dc->realize = pit_common_realize;
     dc->vmsd = &vmstate_pit_common;
     dc->no_user = 1;
 }
hw/i8259_common.c +3 -6
index 418c485..0b8aae1 100644
@@ -66,7 +66,7 @@ static int pic_dispatch_post_load(void *opaque, int version_id)
     return 0;
 }
 
-static int pic_init_common(ISADevice *dev)
+static void pic_common_realize(DeviceState *dev, Error **err)
 {
     PICCommonState *s = PIC_COMMON(dev);
     PICCommonClass *info = PIC_COMMON_GET_CLASS(s);
@@ -78,9 +78,7 @@ static int pic_init_common(ISADevice *dev)
         isa_register_ioport(NULL, &s->elcr_io, s->elcr_addr);
     }
 
-    qdev_set_legacy_instance_id(DEVICE(dev), s->iobase, 1);
-
-    return 0;
+    qdev_set_legacy_instance_id(dev, s->iobase, 1);
 }
 
 ISADevice *i8259_init_chip(const char *name, ISABus *bus, bool master)
@@ -135,13 +133,12 @@ static Property pic_properties_common[] = {
 
 static void pic_common_class_init(ObjectClass *klass, void *data)
 {
-    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
 
     dc->vmsd = &vmstate_pic_common;
     dc->no_user = 1;
     dc->props = pic_properties_common;
-    ic->init = pic_init_common;
+    dc->realize = pic_common_realize;
 }
 
 static const TypeInfo pic_common_type = {
hw/ide/isa.c +8 -8
index 4d55885..9e12a91 100644
@@ -65,16 +65,16 @@ static const VMStateDescription vmstate_ide_isa = {
     }
 };
 
-static int isa_ide_initfn(ISADevice *dev)
+static void isa_ide_realizefn(DeviceState *dev, Error **err)
 {
+    ISADevice *isadev = ISA_DEVICE(dev);
     ISAIDEState *s = ISA_IDE(dev);
 
-    ide_bus_new(&s->bus, DEVICE(dev), 0);
-    ide_init_ioport(&s->bus, dev, s->iobase, s->iobase2);
-    isa_init_irq(dev, &s->irq, s->isairq);
+    ide_bus_new(&s->bus, dev, 0);
+    ide_init_ioport(&s->bus, isadev, s->iobase, s->iobase2);
+    isa_init_irq(isadev, &s->irq, s->isairq);
     ide_init2(&s->bus, s->irq);
-    vmstate_register(&dev->qdev, 0, &vmstate_ide_isa, s);
-    return 0;
+    vmstate_register(dev, 0, &vmstate_ide_isa, s);
 };
 
 ISADevice *isa_ide_init(ISABus *bus, int iobase, int iobase2, int isairq,
@@ -113,8 +113,8 @@ static Property isa_ide_properties[] = {
 static void isa_ide_class_initfn(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
-    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
-    ic->init = isa_ide_initfn;
+
+    dc->realize = isa_ide_realizefn;
     dc->fw_name = "ide";
     dc->reset = isa_ide_reset;
     dc->props = isa_ide_properties;
hw/isa-bus.c +0 -13
index 2b1fc40..bad0d05 100644
@@ -119,18 +119,6 @@ void isa_register_portio_list(ISADevice *dev, uint16_t start,
     portio_list_add(piolist, isabus->address_space_io, start);
 }
 
-static int isa_qdev_init(DeviceState *qdev)
-{
-    ISADevice *dev = ISA_DEVICE(qdev);
-    ISADeviceClass *klass = ISA_DEVICE_GET_CLASS(dev);
-
-    if (klass->init) {
-        return klass->init(dev);
-    }
-
-    return 0;
-}
-
 static void isa_device_init(Object *obj)
 {
     ISADevice *dev = ISA_DEVICE(obj);
@@ -230,7 +218,6 @@ static TypeInfo isabus_bridge_info = {
 static void isa_device_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *k = DEVICE_CLASS(klass);
-    k->init = isa_qdev_init;
     k->bus_type = TYPE_ISA_BUS;
 }
 
hw/isa.h +0 -1
index 9d719fa..04f3939 100644
@@ -22,7 +22,6 @@
 
 typedef struct ISADeviceClass {
     DeviceClass parent_class;
-    int (*init)(ISADevice *dev);
 } ISADeviceClass;
 
 struct ISABus {
hw/m48t59.c +8 -9
index 6d2f9cf..7dbff94 100644
@@ -691,7 +691,7 @@ M48t59State *m48t59_init_isa(ISABus *bus, uint32_t io_base, uint16_t size,
     return s;
 }
 
-static void m48t59_init_common(M48t59State *s)
+static void m48t59_realize_common(M48t59State *s, Error **err)
 {
     s->buffer = g_malloc0(s->size);
     if (s->model == 59) {
@@ -703,15 +703,14 @@ static void m48t59_init_common(M48t59State *s)
     vmstate_register(NULL, -1, &vmstate_m48t59, s);
 }
 
-static int m48t59_init_isa1(ISADevice *dev)
+static void m48t59_isa_realize(DeviceState *dev, Error **err)
 {
+    ISADevice *isadev = ISA_DEVICE(dev);
     M48t59ISAState *d = M48T59_ISA(dev);
     M48t59State *s = &d->state;
 
-    isa_init_irq(dev, &s->IRQ, 8);
-    m48t59_init_common(s);
-
-    return 0;
+    isa_init_irq(isadev, &s->IRQ, 8);
+    m48t59_realize_common(s, err);
 }
 
 static int m48t59_init1(SysBusDevice *dev)
@@ -723,7 +722,7 @@ static int m48t59_init1(SysBusDevice *dev)
 
     memory_region_init_io(&s->iomem, &nvram_ops, s, "m48t59.nvram", s->size);
     sysbus_init_mmio(dev, &s->iomem);
-    m48t59_init_common(s);
+    m48t59_realize_common(s, NULL);
 
     return 0;
 }
@@ -738,8 +737,8 @@ static Property m48t59_isa_properties[] = {
 static void m48t59_isa_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
-    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
-    ic->init = m48t59_init_isa1;
+
+    dc->realize = m48t59_isa_realize;
     dc->no_user = 1;
     dc->reset = m48t59_reset_isa;
     dc->props = m48t59_isa_properties;
hw/mc146818rtc.c +9 -9
index c87b7f6..fa9c8ac 100644
@@ -803,8 +803,9 @@ static void rtc_get_date(Object *obj, Visitor *v, void *opaque,
     visit_end_struct(v, errp);
 }
 
-static int rtc_initfn(ISADevice *dev)
+static void rtc_realizefn(DeviceState *dev, Error **err)
 {
+    ISADevice *isadev = ISA_DEVICE(dev);
     RTCState *s = MC146818_RTC(dev);
     int base = 0x70;
 
@@ -825,7 +826,7 @@ static int rtc_initfn(ISADevice *dev)
         s->base_year = 0;
     }
 
-    rtc_set_date_from_host(dev);
+    rtc_set_date_from_host(isadev);
 
 #ifdef TARGET_I386
     switch (s->lost_tick_policy) {
@@ -836,7 +837,8 @@ static int rtc_initfn(ISADevice *dev)
     case LOST_TICK_DISCARD:
         break;
     default:
-        return -EINVAL;
+        error_setg(err, "Invalid lost tick policy.");
+        return;
     }
 #endif
 
@@ -851,15 +853,13 @@ static int rtc_initfn(ISADevice *dev)
     qemu_register_suspend_notifier(&s->suspend_notifier);
 
     memory_region_init_io(&s->io, &cmos_ops, s, "rtc", 2);
-    isa_register_ioport(dev, &s->io, base);
+    isa_register_ioport(isadev, &s->io, base);
 
-    qdev_set_legacy_instance_id(&dev->qdev, base, 3);
+    qdev_set_legacy_instance_id(dev, base, 3);
     qemu_register_reset(rtc_reset, s);
 
     object_property_add(OBJECT(s), "date", "struct tm",
                         rtc_get_date, NULL, NULL, s, NULL);
-
-    return 0;
 }
 
 ISADevice *rtc_init(ISABus *bus, int base_year, qemu_irq intercept_irq)
@@ -891,8 +891,8 @@ static Property mc146818rtc_properties[] = {
 static void rtc_class_initfn(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
-    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
-    ic->init = rtc_initfn;
+
+    dc->realize = rtc_realizefn;
     dc->no_user = 1;
     dc->vmsd = &vmstate_rtc;
     dc->props = mc146818rtc_properties;
hw/ne2000-isa.c +7 -8
index 5aabe7c..5fbf3cf 100644
@@ -66,24 +66,23 @@ static const VMStateDescription vmstate_isa_ne2000 = {
     }
 };
 
-static int isa_ne2000_initfn(ISADevice *dev)
+static void isa_ne2000_realizefn(DeviceState *dev, Error **err)
 {
+    ISADevice *isadev = ISA_DEVICE(dev);
     ISANE2000State *isa = ISA_NE2000(dev);
     NE2000State *s = &isa->ne2000;
 
     ne2000_setup_io(s, 0x20);
-    isa_register_ioport(dev, &s->io, isa->iobase);
+    isa_register_ioport(isadev, &s->io, isa->iobase);
 
-    isa_init_irq(dev, &s->irq, isa->isairq);
+    isa_init_irq(isadev, &s->irq, isa->isairq);
 
     qemu_macaddr_default_if_unset(&s->c.macaddr);
     ne2000_reset(s);
 
     s->nic = qemu_new_nic(&net_ne2000_isa_info, &s->c,
-                          object_get_typename(OBJECT(dev)), dev->qdev.id, s);
+                          object_get_typename(OBJECT(dev)), dev->id, s);
     qemu_format_nic_info_str(&s->nic->nc, s->c.macaddr.a);
-
-    return 0;
 }
 
 static Property ne2000_isa_properties[] = {
@@ -96,8 +95,8 @@ static Property ne2000_isa_properties[] = {
 static void isa_ne2000_class_initfn(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
-    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
-    ic->init = isa_ne2000_initfn;
+
+    dc->realize = isa_ne2000_realizefn;
     dc->props = ne2000_isa_properties;
 }
 
hw/parallel.c +17 -12
index 65447d3..a01f6e5 100644
@@ -477,29 +477,35 @@ static const MemoryRegionPortio isa_parallel_portio_sw_list[] = {
     PORTIO_END_OF_LIST(),
 };
 
-static int parallel_isa_initfn(ISADevice *dev)
+static void parallel_isa_realizefn(DeviceState *dev, Error **err)
 {
     static int index;
+    ISADevice *isadev = ISA_DEVICE(dev);
     ISAParallelState *isa = ISA_PARALLEL(dev);
     ParallelState *s = &isa->state;
     int base;
     uint8_t dummy;
 
     if (!s->chr) {
-        fprintf(stderr, "Can't create parallel device, empty char device\n");
-        exit(1);
+        error_setg(err, "Can't create parallel device, empty char device\n");
+        return;
     }
 
-    if (isa->index == -1)
+    if (isa->index == -1) {
         isa->index = index;
-    if (isa->index >= MAX_PARALLEL_PORTS)
-        return -1;
-    if (isa->iobase == -1)
+    }
+    if (isa->index >= MAX_PARALLEL_PORTS) {
+        error_setg(err, "Max. supported number of parallel ports is %d.",
+                   MAX_PARALLEL_PORTS);
+        return;
+    }
+    if (isa->iobase == -1) {
         isa->iobase = isa_parallel_io[isa->index];
+    }
     index++;
 
     base = isa->iobase;
-    isa_init_irq(dev, &s->irq, isa->isairq);
+    isa_init_irq(isadev, &s->irq, isa->isairq);
     qemu_register_reset(parallel_reset, s);
 
     if (qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_PP_READ_STATUS, &dummy) == 0) {
@@ -507,12 +513,11 @@ static int parallel_isa_initfn(ISADevice *dev)
         s->status = dummy;
     }
 
-    isa_register_portio_list(dev, base,
+    isa_register_portio_list(isadev, base,
                              (s->hw_driver
                               ? &isa_parallel_portio_hw_list[0]
                               : &isa_parallel_portio_sw_list[0]),
                              s, "parallel");
-    return 0;
 }
 
 /* Memory mapped interface */
@@ -599,8 +604,8 @@ static Property parallel_isa_properties[] = {
 static void parallel_isa_class_initfn(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
-    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
-    ic->init = parallel_isa_initfn;
+
+    dc->realize = parallel_isa_realizefn;
     dc->props = parallel_isa_properties;
 }
 
hw/pc.c +5 -5
index e878106..90915a7 100644
@@ -484,22 +484,22 @@ static const MemoryRegionOps port92_ops = {
     .endianness = DEVICE_LITTLE_ENDIAN,
 };
 
-static int port92_initfn(ISADevice *dev)
+static void port92_realizefn(DeviceState *dev, Error **err)
 {
+    ISADevice *isadev = ISA_DEVICE(dev);
     Port92State *s = PORT92(dev);
 
     memory_region_init_io(&s->io, &port92_ops, s, "port92", 1);
-    isa_register_ioport(dev, &s->io, 0x92);
+    isa_register_ioport(isadev, &s->io, 0x92);
 
     s->outport = 0;
-    return 0;
 }
 
 static void port92_class_initfn(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
-    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
-    ic->init = port92_initfn;
+
+    dc->realize = port92_realizefn;
     dc->no_user = 1;
     dc->reset = port92_reset;
     dc->vmsd = &vmstate_port92_isa;
hw/pckbd.c +8 -8
index a3291ec..4b2b67b 100644
@@ -489,31 +489,31 @@ static const MemoryRegionOps i8042_cmd_ops = {
     .endianness = DEVICE_LITTLE_ENDIAN,
 };
 
-static int i8042_initfn(ISADevice *dev)
+static void i8042_realizefn(DeviceState *dev, Error **err)
 {
+    ISADevice *isadev = ISA_DEVICE(dev);
     ISAKBDState *isa_s = I8042(dev);
     KBDState *s = &isa_s->kbd;
 
-    isa_init_irq(dev, &s->irq_kbd, 1);
-    isa_init_irq(dev, &s->irq_mouse, 12);
+    isa_init_irq(isadev, &s->irq_kbd, 1);
+    isa_init_irq(isadev, &s->irq_mouse, 12);
 
     memory_region_init_io(isa_s->io + 0, &i8042_data_ops, s, "i8042-data", 1);
-    isa_register_ioport(dev, isa_s->io + 0, 0x60);
+    isa_register_ioport(isadev, isa_s->io + 0, 0x60);
 
     memory_region_init_io(isa_s->io + 1, &i8042_cmd_ops, s, "i8042-cmd", 1);
-    isa_register_ioport(dev, isa_s->io + 1, 0x64);
+    isa_register_ioport(isadev, isa_s->io + 1, 0x64);
 
     s->kbd = ps2_kbd_init(kbd_update_kbd_irq, s);
     s->mouse = ps2_mouse_init(kbd_update_aux_irq, s);
     qemu_register_reset(kbd_reset, s);
-    return 0;
 }
 
 static void i8042_class_initfn(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
-    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
-    ic->init = i8042_initfn;
+
+    dc->realize = i8042_realizefn;
     dc->no_user = 1;
     dc->vmsd = &vmstate_kbd_isa;
 }
hw/pcspk.c +4 -6
index f800962..abc72be 100644
@@ -162,16 +162,15 @@ static const MemoryRegionOps pcspk_io_ops = {
     },
 };
 
-static int pcspk_initfn(ISADevice *dev)
+static void pcspk_realizefn(DeviceState *dev, Error **err)
 {
+    ISADevice *isadev = ISA_DEVICE(dev);
     PCSpkState *s = PC_SPEAKER(dev);
 
     memory_region_init_io(&s->ioport, &pcspk_io_ops, s, "elcr", 1);
-    isa_register_ioport(dev, &s->ioport, s->iobase);
+    isa_register_ioport(isadev, &s->ioport, s->iobase);
 
     pcspk_state = s;
-
-    return 0;
 }
 
 static Property pcspk_properties[] = {
@@ -183,9 +182,8 @@ static Property pcspk_properties[] = {
 static void pcspk_class_initfn(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
-    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
 
-    ic->init = pcspk_initfn;
+    dc->realize = pcspk_realizefn;
     dc->no_user = 1;
     dc->props = pcspk_properties;
 }
hw/sb16.c +14 -7
index b7e93a4..c72bbcb 100644
@@ -1356,12 +1356,19 @@ static const MemoryRegionPortio sb16_ioport_list[] = {
 };
 
 
-static int sb16_initfn (ISADevice *dev)
+static void sb16_initfn (Object *obj)
 {
-    SB16State *s = SB16 (dev);
+    SB16State *s = SB16 (obj);
 
     s->cmd = -1;
-    isa_init_irq (dev, &s->pic, s->irq);
+}
+
+static void sb16_realizefn (DeviceState *dev, Error **err)
+{
+    ISADevice *isadev = ISA_DEVICE (dev);
+    SB16State *s = SB16 (dev);
+
+    isa_init_irq (isadev, &s->pic, s->irq);
 
     s->mixer_regs[0x80] = magic_of_irq (s->irq);
     s->mixer_regs[0x81] = (1 << s->dma) | (1 << s->hdma);
@@ -1376,14 +1383,13 @@ static int sb16_initfn (ISADevice *dev)
         dolog ("warning: Could not create auxiliary timer\n");
     }
 
-    isa_register_portio_list (dev, s->port, sb16_ioport_list, s, "sb16");
+    isa_register_portio_list (isadev, s->port, sb16_ioport_list, s, "sb16");
 
     DMA_register_channel (s->hdma, SB_read_DMA, s);
     DMA_register_channel (s->dma, SB_read_DMA, s);
     s->can_write = 1;
 
     AUD_register_card ("sb16", &s->card);
-    return 0;
 }
 
 int SB16_init (ISABus *bus)
@@ -1404,8 +1410,8 @@ static Property sb16_properties[] = {
 static void sb16_class_initfn (ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS (klass);
-    ISADeviceClass *ic = ISA_DEVICE_CLASS (klass);
-    ic->init = sb16_initfn;
+
+    dc->realize = sb16_realizefn;
     dc->desc = "Creative Sound Blaster 16";
     dc->vmsd = &vmstate_sb16;
     dc->props = sb16_properties;
@@ -1415,6 +1421,7 @@ static const TypeInfo sb16_info = {
     .name          = TYPE_SB16,
     .parent        = TYPE_ISA_DEVICE,
     .instance_size = sizeof (SB16State),
+    .instance_init = sb16_initfn,
     .class_init    = sb16_class_initfn,
 };
 
hw/serial-isa.c +11 -9
index 904cc41..455f07b 100644
@@ -44,9 +44,10 @@ static const int isa_serial_irq[MAX_SERIAL_PORTS] = {
     4, 3, 4, 3
 };
 
-static int serial_isa_initfn(ISADevice *dev)
+static void serial_isa_realizefn(DeviceState *dev, Error **err)
 {
     static int index;
+    ISADevice *isadev = ISA_DEVICE(dev);
     ISASerialState *isa = ISA_SERIAL(dev);
     SerialState *s = &isa->state;
 
@@ -54,7 +55,9 @@ static int serial_isa_initfn(ISADevice *dev)
         isa->index = index;
     }
     if (isa->index >= MAX_SERIAL_PORTS) {
-        return -1;
+        error_setg(err, "Max. supported number of ISA serial ports is %d.",
+                   MAX_SERIAL_PORTS);
+        return;
     }
     if (isa->iobase == -1) {
         isa->iobase = isa_serial_io[isa->index];
@@ -65,13 +68,12 @@ static int serial_isa_initfn(ISADevice *dev)
     index++;
 
     s->baudbase = 115200;
-    isa_init_irq(dev, &s->irq, isa->isairq);
-    serial_init_core(s);
-    qdev_set_legacy_instance_id(&dev->qdev, isa->iobase, 3);
+    isa_init_irq(isadev, &s->irq, isa->isairq);
+    serial_realize_core(s, err);
+    qdev_set_legacy_instance_id(dev, isa->iobase, 3);
 
     memory_region_init_io(&s->io, &serial_io_ops, s, "serial", 8);
-    isa_register_ioport(dev, &s->io, isa->iobase);
-    return 0;
+    isa_register_ioport(isadev, &s->io, isa->iobase);
 }
 
 static const VMStateDescription vmstate_isa_serial = {
@@ -96,8 +98,8 @@ static Property serial_isa_properties[] = {
 static void serial_isa_class_initfn(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
-    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
-    ic->init = serial_isa_initfn;
+
+    dc->realize = serial_isa_realizefn;
     dc->vmsd = &vmstate_isa_serial;
     dc->props = serial_isa_properties;
 }
hw/serial-pci.c +2 -2
index 95dc5c8..25b4126 100644
@@ -51,7 +51,7 @@ static int serial_pci_init(PCIDevice *dev)
     SerialState *s = &pci->state;
 
     s->baudbase = 115200;
-    serial_init_core(s);
+    serial_realize_core(s, NULL);
 
     pci->dev.config[PCI_INTERRUPT_PIN] = 0x01;
     s->irq = pci->dev.irq[0];
@@ -102,7 +102,7 @@ static int multi_serial_pci_init(PCIDevice *dev)
     for (i = 0; i < pci->ports; i++) {
         s = pci->state + i;
         s->baudbase = 115200;
-        serial_init_core(s);
+        serial_realize_core(s, NULL);
         s->irq = pci->irqs[i];
         pci->name[i] = g_strdup_printf("uart #%d", i+1);
         memory_region_init_io(&s->io, &serial_io_ops, s, pci->name[i], 8);
hw/serial.c +3 -3
index 07a2a11..0b30b99 100644
@@ -676,7 +676,7 @@ static void serial_reset(void *opaque)
     qemu_irq_lower(s->irq);
 }
 
-void serial_init_core(SerialState *s)
+void serial_realize_core(SerialState *s, Error **err)
 {
     if (!s->chr) {
         fprintf(stderr, "Can't create serial device, empty char device\n");
@@ -727,7 +727,7 @@ SerialState *serial_init(int base, qemu_irq irq, int baudbase,
     s->irq = irq;
     s->baudbase = baudbase;
     s->chr = chr;
-    serial_init_core(s);
+    serial_realize_core(s, NULL);
 
     vmstate_register(NULL, base, &vmstate_serial, s);
 
@@ -785,7 +785,7 @@ SerialState *serial_mm_init(MemoryRegion *address_space,
     s->baudbase = baudbase;
     s->chr = chr;
 
-    serial_init_core(s);
+    serial_realize_core(s, NULL);
     vmstate_register(NULL, base, &vmstate_serial, s);
 
     memory_region_init_io(&s->io, &serial_mm_ops[end], s,
hw/serial.h +1 -1
index bb06366..2d00554 100644
@@ -83,7 +83,7 @@ struct SerialState {
 extern const VMStateDescription vmstate_serial;
 extern const MemoryRegionOps serial_io_ops;
 
-void serial_init_core(SerialState *s);
+void serial_realize_core(SerialState *s, Error **err);
 void serial_exit_core(SerialState *s);
 void serial_set_frequency(SerialState *s, uint32_t frequency);
 
hw/sga.c +3 -4
index d828f45..2f488d9 100644
@@ -38,17 +38,16 @@ typedef struct ISASGAState {
     ISADevice parent_obj;
 } ISASGAState;
 
-static int sga_initfn(ISADevice *dev)
+static void sga_realizefn(DeviceState *dev, Error **err)
 {
     rom_add_vga(SGABIOS_FILENAME);
-    return 0;
 }
 
 static void sga_class_initfn(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
-    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
-    ic->init = sga_initfn;
+
+    dc->realize = sga_realizefn;
     dc->desc = "Serial Graphics Adapter";
 }
 
hw/vga-isa.c +8 -9
index f177c48..19d6e99 100644
@@ -48,31 +48,31 @@ static void vga_isa_reset(DeviceState *dev)
     vga_common_reset(s);
 }
 
-static int vga_initfn(ISADevice *dev)
+static void vga_isa_realizefn(DeviceState *dev, Error **err)
 {
+    ISADevice *isadev = ISA_DEVICE(dev);
     ISAVGAState *d = ISA_VGA(dev);
     VGACommonState *s = &d->state;
     MemoryRegion *vga_io_memory;
     const MemoryRegionPortio *vga_ports, *vbe_ports;
 
     vga_common_init(s);
-    s->legacy_address_space = isa_address_space(dev);
+    s->legacy_address_space = isa_address_space(isadev);
     vga_io_memory = vga_init_io(s, &vga_ports, &vbe_ports);
-    isa_register_portio_list(dev, 0x3b0, vga_ports, s, "vga");
+    isa_register_portio_list(isadev, 0x3b0, vga_ports, s, "vga");
     if (vbe_ports) {
-        isa_register_portio_list(dev, 0x1ce, vbe_ports, s, "vbe");
+        isa_register_portio_list(isadev, 0x1ce, vbe_ports, s, "vbe");
     }
-    memory_region_add_subregion_overlap(isa_address_space(dev),
+    memory_region_add_subregion_overlap(isa_address_space(isadev),
                                         isa_mem_base + 0x000a0000,
                                         vga_io_memory, 1);
     memory_region_set_coalescing(vga_io_memory);
     s->ds = graphic_console_init(s->update, s->invalidate,
                                  s->screen_dump, s->text_update, s);
 
-    vga_init_vbe(s, isa_address_space(dev));
+    vga_init_vbe(s, isa_address_space(isadev));
     /* ROM BIOS */
     rom_add_vga(VGABIOS_FILENAME);
-    return 0;
 }
 
 static Property vga_isa_properties[] = {
@@ -83,9 +83,8 @@ static Property vga_isa_properties[] = {
 static void vga_isa_class_initfn(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
-    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
 
-    ic->init = vga_initfn;
+    dc->realize = vga_isa_realizefn;
     dc->reset = vga_isa_reset;
     dc->vmsd = &vmstate_vga_common;
     dc->props = vga_isa_properties;
hw/vmmouse.c +3 -5
index 7c7c4e4..2e05ccb 100644
@@ -262,7 +262,7 @@ static void vmmouse_reset(DeviceState *d)
     vmmouse_disable(s);
 }
 
-static int vmmouse_initfn(ISADevice *dev)
+static void vmmouse_realizefn(DeviceState *dev, Error **err)
 {
     VMMouseState *s = VMMOUSE(dev);
 
@@ -271,8 +271,6 @@ static int vmmouse_initfn(ISADevice *dev)
     vmport_register(VMMOUSE_STATUS, vmmouse_ioport_read, s);
     vmport_register(VMMOUSE_COMMAND, vmmouse_ioport_read, s);
     vmport_register(VMMOUSE_DATA, vmmouse_ioport_read, s);
-
-    return 0;
 }
 
 static Property vmmouse_properties[] = {
@@ -283,8 +281,8 @@ static Property vmmouse_properties[] = {
 static void vmmouse_class_initfn(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
-    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
-    ic->init = vmmouse_initfn;
+
+    dc->realize = vmmouse_realizefn;
     dc->no_user = 1;
     dc->reset = vmmouse_reset;
     dc->vmsd = &vmstate_vmmouse;
hw/vmport.c +5 -5
index ec36d47..70daffa 100644
@@ -137,25 +137,25 @@ static const MemoryRegionOps vmport_ops = {
     .endianness = DEVICE_LITTLE_ENDIAN,
 };
 
-static int vmport_initfn(ISADevice *dev)
+static void vmport_realizefn(DeviceState *dev, Error **err)
 {
+    ISADevice *isadev = ISA_DEVICE(dev);
     VMPortState *s = VMPORT(dev);
 
     memory_region_init_io(&s->io, &vmport_ops, s, "vmport", 1);
-    isa_register_ioport(dev, &s->io, 0x5658);
+    isa_register_ioport(isadev, &s->io, 0x5658);
 
     port_state = s;
     /* Register some generic port commands */
     vmport_register(VMPORT_CMD_GETVERSION, vmport_cmd_get_version, NULL);
     vmport_register(VMPORT_CMD_GETRAMSIZE, vmport_cmd_ram_size, NULL);
-    return 0;
 }
 
 static void vmport_class_initfn(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
-    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
-    ic->init = vmport_initfn;
+
+    dc->realize = vmport_realizefn;
     dc->no_user = 1;
 }
 
hw/wdt_ib700.c +3 -5
index 1365898..9209307 100644
@@ -97,7 +97,7 @@ static const VMStateDescription vmstate_ib700 = {
     }
 };
 
-static int wdt_ib700_init(ISADevice *dev)
+static void wdt_ib700_realize(DeviceState *dev, Error **err)
 {
     IB700State *s = IB700(dev);
 
@@ -106,8 +106,6 @@ static int wdt_ib700_init(ISADevice *dev)
     s->timer = qemu_new_timer_ns(vm_clock, ib700_timer_expired, s);
     register_ioport_write(0x441, 2, 1, ib700_write_disable_reg, s);
     register_ioport_write(0x443, 2, 1, ib700_write_enable_reg, s);
-
-    return 0;
 }
 
 static void wdt_ib700_reset(DeviceState *dev)
@@ -127,8 +125,8 @@ static WatchdogTimerModel model = {
 static void wdt_ib700_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
-    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
-    ic->init = wdt_ib700_init;
+
+    dc->realize = wdt_ib700_realize;
     dc->reset = wdt_ib700_reset;
     dc->vmsd = &vmstate_ib700;
 }
Signature · 1 line
1.7.10.4
#38 lore raw

RFC 29/34 i8254: QOM'ify

In reply to Andreas Färber

Introduce type constant and avoid DO_UPCAST().

Prepares for PIT realizefn.

---
 hw/i8254.c |    6 +++---
 hw/i8254.h |    4 +++-

2 Dateien geändert, 6 Zeilen hinzugefügt(+), 4 Zeilen entfernt(-)

hw/i8254.c +3 -3
index bea5f92..2a01217 100644
@@ -265,7 +265,7 @@ static void pit_irq_timer(void *opaque)
 
 static void pit_reset(DeviceState *dev)
 {
-    PITCommonState *pit = DO_UPCAST(PITCommonState, dev.qdev, dev);
+    PITCommonState *pit = PIT_COMMON(dev);
     PITChannelState *s;
 
     pit_reset_common(pit);
@@ -347,8 +347,8 @@ static void pit_class_initfn(ObjectClass *klass, void *data)
     dc->props = pit_properties;
 }
 
-static TypeInfo pit_info = {
-    .name          = "isa-pit",
+static const TypeInfo pit_info = {
+    .name          = TYPE_I8254,
     .parent        = TYPE_PIT_COMMON,
     .instance_size = sizeof(PITCommonState),
     .class_init    = pit_class_initfn,
hw/i8254.h +3 -1
index ba6b598..2566bac 100644
@@ -37,12 +37,14 @@ typedef struct PITChannelInfo {
     int out;
 } PITChannelInfo;
 
+#define TYPE_I8254 "isa-pit"
+
 static inline ISADevice *pit_init(ISABus *bus, int base, int isa_irq,
                                   qemu_irq alt_irq)
 {
     ISADevice *dev;
 
-    dev = isa_create(bus, "isa-pit");
+    dev = isa_create(bus, TYPE_I8254);
     qdev_prop_set_uint32(&dev->qdev, "iobase", base);
     qdev_init_nofail(&dev->qdev);
     qdev_connect_gpio_out(&dev->qdev, 0,
Signature · 1 line
1.7.10.4
#39 lore raw

RFC 30/34 kvm/i8254: QOM'ify some more

In reply to Andreas Färber

Introduce type constant and cast macro to obsolete DO_UPCAST().

Prepares for PIT realizefn.

---
 hw/i8254.h     |    3 ++-
 hw/kvm/i8254.c |   21 ++++++++++++---------

2 Dateien geändert, 14 Zeilen hinzugefügt(+), 10 Zeilen entfernt(-)

hw/i8254.h +2 -1
index 2566bac..cfa8dc9 100644
@@ -38,6 +38,7 @@ typedef struct PITChannelInfo {
 } PITChannelInfo;
 
 #define TYPE_I8254 "isa-pit"
+#define TYPE_KVM_I8254 "kvm-pit"
 
 static inline ISADevice *pit_init(ISABus *bus, int base, int isa_irq,
                                   qemu_irq alt_irq)
@@ -57,7 +58,7 @@ static inline ISADevice *kvm_pit_init(ISABus *bus, int base)
 {
     ISADevice *dev;
 
-    dev = isa_create(bus, "kvm-pit");
+    dev = isa_create(bus, TYPE_KVM_I8254);
     qdev_prop_set_uint32(&dev->qdev, "iobase", base);
     qdev_init_nofail(&dev->qdev);
 
hw/kvm/i8254.c +12 -9
index 53d13e3..420d5ad 100644
@@ -32,8 +32,11 @@
 
 #define CALIBRATION_ROUNDS   3
 
+#define KVM_PIT(obj) OBJECT_CHECK(KVMPITState, (obj), TYPE_KVM_I8254)
+
 typedef struct KVMPITState {
-    PITCommonState pit;
+    PITCommonState parent_obj;
+
     LostTickPolicy lost_tick_policy;
     bool vm_stopped;
     int64_t kernel_clock_offset;
@@ -70,7 +73,7 @@ static void kvm_pit_update_clock_offset(KVMPITState *s)
 
 static void kvm_pit_get(PITCommonState *pit)
 {
-    KVMPITState *s = DO_UPCAST(KVMPITState, pit, pit);
+    KVMPITState *s = KVM_PIT(pit);
     struct kvm_pit_state2 kpit;
     struct kvm_pit_channel_state *kchan;
     struct PITChannelState *sc;
@@ -124,7 +127,7 @@ static void kvm_pit_get(PITCommonState *pit)
 
 static void kvm_pit_put(PITCommonState *pit)
 {
-    KVMPITState *s = DO_UPCAST(KVMPITState, pit, pit);
+    KVMPITState *s = KVM_PIT(pit);
     struct kvm_pit_state2 kpit;
     struct kvm_pit_channel_state *kchan;
     struct PITChannelState *sc;
@@ -200,7 +203,7 @@ static void kvm_pit_get_channel_info(PITCommonState *s, PITChannelState *sc,
 
 static void kvm_pit_reset(DeviceState *dev)
 {
-    PITCommonState *s = DO_UPCAST(PITCommonState, dev.qdev, dev);
+    PITCommonState *s = PIT_COMMON(dev);
 
     pit_reset_common(s);
 
@@ -229,14 +232,14 @@ static void kvm_pit_vm_state_change(void *opaque, int running,
         s->vm_stopped = false;
     } else {
         kvm_pit_update_clock_offset(s);
-        kvm_pit_get(&s->pit);
+        kvm_pit_get(PIT_COMMON(s));
         s->vm_stopped = true;
     }
 }
 
 static int kvm_pit_initfn(PITCommonState *pit)
 {
-    KVMPITState *s = DO_UPCAST(KVMPITState, pit, pit);
+    KVMPITState *s = KVM_PIT(pit);
     struct kvm_pit_config config = {
         .flags = 0,
     };
@@ -282,7 +285,7 @@ static int kvm_pit_initfn(PITCommonState *pit)
 }
 
 static Property kvm_pit_properties[] = {
-    DEFINE_PROP_HEX32("iobase", KVMPITState, pit.iobase,  -1),
+    DEFINE_PROP_HEX32("iobase", PITCommonState, iobase,  -1),
     DEFINE_PROP_LOSTTICKPOLICY("lost_tick_policy", KVMPITState,
                                lost_tick_policy, LOST_TICK_DELAY),
     DEFINE_PROP_END_OF_LIST(),
@@ -302,8 +305,8 @@ static void kvm_pit_class_init(ObjectClass *klass, void *data)
     dc->props = kvm_pit_properties;
 }
 
-static TypeInfo kvm_pit_info = {
-    .name          = "kvm-pit",
+static const TypeInfo kvm_pit_info = {
+    .name          = TYPE_KVM_I8254,
     .parent        = TYPE_PIT_COMMON,
     .instance_size = sizeof(KVMPITState),
     .class_init = kvm_pit_class_init,
Signature · 1 line
1.7.10.4
#40 lore raw

RFC 31/34 i8254: Convert PITCommonState to QOM realizefn

In reply to Andreas Färber

Instead of having the parent provide PITCommonClass::init, let the children override DeviceClass::realize themselves. This pushes the responsibility for saving and calling the parent's realizefn to the children.

---
 hw/i8254.c          |   20 +++++++++++++++++---
 hw/i8254_common.c   |    8 --------
 hw/i8254_internal.h |    1 -
 hw/kvm/i8254.c      |   38 +++++++++++++++++++++++++++-----------

4 Dateien geändert, 44 Zeilen hinzugefügt(+), 23 Zeilen entfernt(-)

hw/i8254.c +17 -3
index 2a01217..6fa4825 100644
@@ -35,6 +35,15 @@
 #define RW_STATE_WORD0 3
 #define RW_STATE_WORD1 4
 
+#define PIT_CLASS(class) OBJECT_CLASS_CHECK(PITClass, (class), TYPE_I8254)
+#define PIT_GET_CLASS(obj) OBJECT_GET_CLASS(PITClass, (obj), TYPE_I8254)
+
+typedef struct PITClass {
+    PITCommonClass parent_class;
+
+    DeviceRealize parent_realize;
+} PITClass;
+
 static void pit_irq_timer_update(PITChannelState *s, int64_t current_time);
 
 static int pit_get_count(PITChannelState *s)
@@ -313,8 +322,10 @@ static void pit_post_load(PITCommonState *s)
     }
 }
 
-static int pit_initfn(PITCommonState *pit)
+static void pit_realizefn(DeviceState *dev, Error **err)
 {
+    PITCommonState *pit = PIT_COMMON(dev);
+    PITClass *pc = PIT_GET_CLASS(dev);
     PITChannelState *s;
 
     s = &pit->channels[0];
@@ -326,7 +337,7 @@ static int pit_initfn(PITCommonState *pit)
 
     qdev_init_gpio_in(&pit->dev.qdev, pit_irq_control, 1);
 
-    return 0;
+    pc->parent_realize(dev, err);
 }
 
 static Property pit_properties[] = {
@@ -336,10 +347,12 @@ static Property pit_properties[] = {
 
 static void pit_class_initfn(ObjectClass *klass, void *data)
 {
+    PITClass *pc = PIT_CLASS(klass);
     PITCommonClass *k = PIT_COMMON_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
 
-    k->init = pit_initfn;
+    pc->parent_realize = dc->realize;
+    dc->realize = pit_realizefn;
     k->set_channel_gate = pit_set_channel_gate;
     k->get_channel_info = pit_get_channel_info_common;
     k->post_load = pit_post_load;
@@ -352,6 +365,7 @@ static const TypeInfo pit_info = {
     .parent        = TYPE_PIT_COMMON,
     .instance_size = sizeof(PITCommonState),
     .class_init    = pit_class_initfn,
+    .class_size    = sizeof(PITClass),
 };
 
 static void pit_register_types(void)
hw/i8254_common.c +0 -8
index 1883405..3beb2cd 100644
@@ -170,14 +170,6 @@ static void pit_common_realize(DeviceState *dev, Error **err)
 {
     ISADevice *isadev = ISA_DEVICE(dev);
     PITCommonState *pit = PIT_COMMON(dev);
-    PITCommonClass *c = PIT_COMMON_GET_CLASS(pit);
-    int ret;
-
-    ret = c->init(pit);
-    if (ret < 0) {
-        error_setg(err, "PIT init failed.");
-        return;
-    }
 
     isa_register_ioport(isadev, &pit->ioports, pit->iobase);
 
hw/i8254_internal.h +0 -1
index 686f0c2..8cd4faa 100644
@@ -68,7 +68,6 @@ typedef struct PITCommonState {
 typedef struct PITCommonClass {
     ISADeviceClass parent_class;
 
-    int (*init)(PITCommonState *s);
     void (*set_channel_gate)(PITCommonState *s, PITChannelState *sc, int val);
     void (*get_channel_info)(PITCommonState *s, PITChannelState *sc,
                              PITChannelInfo *info);
hw/kvm/i8254.c +27 -11
index 420d5ad..72d84e8 100644
@@ -33,6 +33,10 @@
 #define CALIBRATION_ROUNDS   3
 
 #define KVM_PIT(obj) OBJECT_CHECK(KVMPITState, (obj), TYPE_KVM_I8254)
+#define KVM_PIT_CLASS(class) \
+    OBJECT_CLASS_CHECK(KVMPITClass, (class), TYPE_KVM_I8254)
+#define KVM_PIT_GET_CLASS(obj) \
+    OBJECT_GET_CLASS(KVMPITClass, (obj), TYPE_KVM_I8254)
 
 typedef struct KVMPITState {
     PITCommonState parent_obj;
@@ -42,6 +46,12 @@ typedef struct KVMPITState {
     int64_t kernel_clock_offset;
 } KVMPITState;
 
+typedef struct KVMPITClass {
+    PITCommonClass parent_class;
+
+    DeviceRealize parent_realize;
+} KVMPITClass;
+
 static int64_t abs64(int64_t v)
 {
     return v < 0 ? -v : v;
@@ -237,8 +247,10 @@ static void kvm_pit_vm_state_change(void *opaque, int running,
     }
 }
 
-static int kvm_pit_initfn(PITCommonState *pit)
+static void kvm_pit_realizefn(DeviceState *dev, Error **err)
 {
+    PITCommonState *pit = PIT_COMMON(dev);
+    KVMPITClass *kpc = KVM_PIT_GET_CLASS(dev);
     KVMPITState *s = KVM_PIT(pit);
     struct kvm_pit_config config = {
         .flags = 0,
@@ -251,9 +263,9 @@ static int kvm_pit_initfn(PITCommonState *pit)
         ret = kvm_vm_ioctl(kvm_state, KVM_CREATE_PIT);
     }
     if (ret < 0) {
-        fprintf(stderr, "Create kernel PIC irqchip failed: %s\n",
-                strerror(ret));
-        return ret;
+        error_setg(err, "Create kernel PIC irqchip failed: %s\n",
+                   strerror(ret));
+        return;
     }
     switch (s->lost_tick_policy) {
     case LOST_TICK_DELAY:
@@ -264,15 +276,16 @@ static int kvm_pit_initfn(PITCommonState *pit)
 
             ret = kvm_vm_ioctl(kvm_state, KVM_REINJECT_CONTROL, &control);
             if (ret < 0) {
-                fprintf(stderr,
-                        "Can't disable in-kernel PIT reinjection: %s\n",
-                        strerror(ret));
-                return ret;
+                error_setg(err,
+                           "Can't disable in-kernel PIT reinjection: %s\n",
+                           strerror(ret));
+                return;
             }
         }
         break;
     default:
-        return -EINVAL;
+        error_setg(err, "Lost tick policy not supported.");
+        return;
     }
 
     memory_region_init_reservation(&pit->ioports, "kvm-pit", 4);
@@ -281,7 +294,7 @@ static int kvm_pit_initfn(PITCommonState *pit)
 
     qemu_add_vm_change_state_handler(kvm_pit_vm_state_change, s);
 
-    return 0;
+    kpc->parent_realize(dev, err);
 }
 
 static Property kvm_pit_properties[] = {
@@ -293,10 +306,12 @@ static Property kvm_pit_properties[] = {
 
 static void kvm_pit_class_init(ObjectClass *klass, void *data)
 {
+    KVMPITClass *kpc = KVM_PIT_CLASS(klass);
     PITCommonClass *k = PIT_COMMON_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
 
-    k->init = kvm_pit_initfn;
+    kpc->parent_realize = dc->realize;
+    dc->realize = kvm_pit_realizefn;
     k->set_channel_gate = kvm_pit_set_gate;
     k->get_channel_info = kvm_pit_get_channel_info;
     k->pre_save = kvm_pit_get;
@@ -310,6 +325,7 @@ static const TypeInfo kvm_pit_info = {
     .parent        = TYPE_PIT_COMMON,
     .instance_size = sizeof(KVMPITState),
     .class_init = kvm_pit_class_init,
+    .class_size = sizeof(KVMPITClass),
 };
 
 static void kvm_pit_register(void)
Signature · 1 line
1.7.10.4
#41 lore raw

RFC 32/34 i8259: QOM'ify some more

In reply to Andreas Färber

Introduce type constant.

Prepares for PIC realizefn.

---
 hw/i8259.c |   23 ++++++++++++++---------

1 Datei geändert, 14 Zeilen hinzugefügt(+), 9 Zeilen entfernt(-)

hw/i8259.c +14 -9
index 55c2cb9..e03db77 100644
@@ -41,6 +41,8 @@
 //#define DEBUG_IRQ_LATENCY
 //#define DEBUG_IRQ_COUNT
 
+#define TYPE_I8259 "isa-i8259"
+
 #if defined(DEBUG_PIC) || defined(DEBUG_IRQ_COUNT)
 static int irq_level[16];
 #endif
@@ -448,25 +450,28 @@ void irq_info(Monitor *mon)
 qemu_irq *i8259_init(ISABus *bus, qemu_irq parent_irq)
 {
     qemu_irq *irq_set;
-    ISADevice *dev;
+    DeviceState *dev;
+    ISADevice *isadev;
     int i;
 
     irq_set = g_malloc(ISA_NUM_IRQS * sizeof(qemu_irq));
 
-    dev = i8259_init_chip("isa-i8259", bus, true);
+    isadev = i8259_init_chip(TYPE_I8259, bus, true);
+    dev = DEVICE(isadev);
 
-    qdev_connect_gpio_out(&dev->qdev, 0, parent_irq);
+    qdev_connect_gpio_out(dev, 0, parent_irq);
     for (i = 0 ; i < 8; i++) {
-        irq_set[i] = qdev_get_gpio_in(&dev->qdev, i);
+        irq_set[i] = qdev_get_gpio_in(dev, i);
     }
 
-    isa_pic = &dev->qdev;
+    isa_pic = dev;
 
-    dev = i8259_init_chip("isa-i8259", bus, false);
+    isadev = i8259_init_chip(TYPE_I8259, bus, false);
+    dev = DEVICE(isadev);
 
-    qdev_connect_gpio_out(&dev->qdev, 0, irq_set[2]);
+    qdev_connect_gpio_out(dev, 0, irq_set[2]);
     for (i = 0 ; i < 8; i++) {
-        irq_set[i + 8] = qdev_get_gpio_in(&dev->qdev, i);
+        irq_set[i + 8] = qdev_get_gpio_in(dev, i);
     }
 
     slave_pic = PIC_COMMON(dev);
@@ -484,7 +489,7 @@ static void i8259_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo i8259_info = {
-    .name       = "isa-i8259",
+    .name       = TYPE_I8259,
     .instance_size = sizeof(PICCommonState),
     .parent     = TYPE_PIC_COMMON,
     .class_init = i8259_class_init,
Signature · 1 line
1.7.10.4
#42 lore raw

RFC 33/34 kvm/i8259: QOM'ify some more

In reply to Andreas Färber

Introduce type constant.

Prepares for PIC realizefn.

---
 hw/kvm/i8259.c |    8 +++++---

1 Datei geändert, 5 Zeilen hinzugefügt(+), 3 Zeilen entfernt(-)

hw/kvm/i8259.c +5 -3
index 2aaf14a..973cc08 100644
@@ -13,6 +13,8 @@
 #include "hw/apic_internal.h"
 #include "kvm.h"
 
+#define TYPE_KVM_I8259 "kvm-i8259"
+
 static void kvm_pic_get(PICCommonState *s)
 {
     struct kvm_irqchip chip;
@@ -106,8 +108,8 @@ static void kvm_pic_init(PICCommonState *s)
 
 qemu_irq *kvm_i8259_init(ISABus *bus)
 {
-    i8259_init_chip("kvm-i8259", bus, true);
-    i8259_init_chip("kvm-i8259", bus, false);
+    i8259_init_chip(TYPE_KVM_I8259, bus, true);
+    i8259_init_chip(TYPE_KVM_I8259, bus, false);
 
     return qemu_allocate_irqs(kvm_pic_set_irq, NULL, ISA_NUM_IRQS);
 }
@@ -124,7 +126,7 @@ static void kvm_i8259_class_init(ObjectClass *klass, void *data)
 }
 
 static const TypeInfo kvm_i8259_info = {
-    .name  = "kvm-i8259",
+    .name = TYPE_KVM_I8259,
     .parent = TYPE_PIC_COMMON,
     .instance_size = sizeof(PICCommonState),
     .class_init = kvm_i8259_class_init,
Signature · 1 line
1.7.10.4
#43 lore raw

RFC 34/34 i8259: Convert PICCommonState to use QOM realizefn

In reply to Andreas Färber

Instead of having the parent provide PICCommonClass::init, let the children override DeviceClass::realize themselves. This pushes the responsibility of saving and calling the parent's realizefn to the children.

---
 hw/i8259.c          |   25 +++++++++++++++++++++----
 hw/i8259_common.c   |    3 ---
 hw/i8259_internal.h |    2 +-
 hw/kvm/i8259.c      |   26 ++++++++++++++++++++++++--

4 Dateien geändert, 46 Zeilen hinzugefügt(+), 10 Zeilen entfernt(-)

hw/i8259.c +21 -4
index e03db77..95b79dc 100644
@@ -42,6 +42,18 @@
 //#define DEBUG_IRQ_COUNT
 
 #define TYPE_I8259 "isa-i8259"
+#define PIC_CLASS(class) OBJECT_CLASS_CHECK(PICClass, (class), TYPE_I8259)
+#define PIC_GET_CLASS(obj) OBJECT_GET_CLASS(PICClass, (obj), TYPE_I8259)
+
+/**
+ * PICClass:
+ * @parent_realize: The parent's realizefn.
+ */
+typedef struct PICClass {
+    PICCommonClass parent_class;
+
+    DeviceRealize parent_realize;
+} PICClass;
 
 #if defined(DEBUG_PIC) || defined(DEBUG_IRQ_COUNT)
 static int irq_level[16];
@@ -400,15 +412,18 @@ static const MemoryRegionOps pic_elcr_ioport_ops = {
     },
 };
 
-static void pic_init(PICCommonState *s)
+static void pic_realize(DeviceState *dev, Error **err)
 {
-    DeviceState *dev = DEVICE(s);
+    PICCommonState *s = PIC_COMMON(dev);
+    PICClass *pc = PIC_GET_CLASS(dev);
 
     memory_region_init_io(&s->base_io, &pic_base_ioport_ops, s, "pic", 2);
     memory_region_init_io(&s->elcr_io, &pic_elcr_ioport_ops, s, "elcr", 1);
 
     qdev_init_gpio_out(dev, s->int_out, ARRAY_SIZE(s->int_out));
     qdev_init_gpio_in(dev, pic_set_irq, 8);
+
+    pc->parent_realize(dev, err);
 }
 
 void pic_info(Monitor *mon)
@@ -481,10 +496,11 @@ qemu_irq *i8259_init(ISABus *bus, qemu_irq parent_irq)
 
 static void i8259_class_init(ObjectClass *klass, void *data)
 {
-    PICCommonClass *k = PIC_COMMON_CLASS(klass);
+    PICClass *k = PIC_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
 
-    k->init = pic_init;
+    k->parent_realize = dc->realize;
+    dc->realize = pic_realize;
     dc->reset = pic_reset;
 }
 
@@ -493,6 +509,7 @@ static const TypeInfo i8259_info = {
     .instance_size = sizeof(PICCommonState),
     .parent     = TYPE_PIC_COMMON,
     .class_init = i8259_class_init,
+    .class_size = sizeof(PICClass),
 };
 
 static void pic_register_types(void)
hw/i8259_common.c +0 -3
index 0b8aae1..1dae6a8 100644
@@ -69,9 +69,6 @@ static int pic_dispatch_post_load(void *opaque, int version_id)
 static void pic_common_realize(DeviceState *dev, Error **err)
 {
     PICCommonState *s = PIC_COMMON(dev);
-    PICCommonClass *info = PIC_COMMON_GET_CLASS(s);
-
-    info->init(s);
 
     isa_register_ioport(NULL, &s->base_io, s->iobase);
     if (s->elcr_addr != -1) {
hw/i8259_internal.h +1 -1
index 32e48c3..e94ab6f 100644
@@ -42,7 +42,7 @@ typedef struct PICCommonState PICCommonState;
 typedef struct PICCommonClass
 {
     ISADeviceClass parent_class;
-    void (*init)(PICCommonState *s);
+
     void (*pre_save)(PICCommonState *s);
     void (*post_load)(PICCommonState *s);
 } PICCommonClass;
hw/kvm/i8259.c +24 -2
index 973cc08..e1e99aa 100644
@@ -14,6 +14,20 @@
 #include "kvm.h"
 
 #define TYPE_KVM_I8259 "kvm-i8259"
+#define KVM_PIC_CLASS(class) \
+    OBJECT_CLASS_CHECK(KVMPICClass, (class), TYPE_KVM_I8259)
+#define KVM_PIC_GET_CLASS(obj) \
+    OBJECT_GET_CLASS(KVMPICClass, (obj), TYPE_KVM_I8259)
+
+/**
+ * KVMPICClass:
+ * @parent_realize: The parent's realizefn.
+ */
+typedef struct KVMPICClass {
+    PICCommonClass parent_class;
+
+    DeviceRealize parent_realize;
+} KVMPICClass;
 
 static void kvm_pic_get(PICCommonState *s)
 {
@@ -100,10 +114,15 @@ static void kvm_pic_set_irq(void *opaque, int irq, int level)
     apic_report_irq_delivered(delivered);
 }
 
-static void kvm_pic_init(PICCommonState *s)
+static void kvm_pic_realize(DeviceState *dev, Error **err)
 {
+    PICCommonState *s = PIC_COMMON(dev);
+    KVMPICClass *kpc = KVM_PIC_GET_CLASS(dev);
+
     memory_region_init_reservation(&s->base_io, "kvm-pic", 2);
     memory_region_init_reservation(&s->elcr_io, "kvm-elcr", 1);
+
+    kpc->parent_realize(dev, err);
 }
 
 qemu_irq *kvm_i8259_init(ISABus *bus)
@@ -116,11 +135,13 @@ qemu_irq *kvm_i8259_init(ISABus *bus)
 
 static void kvm_i8259_class_init(ObjectClass *klass, void *data)
 {
+    KVMPICClass *kpc = KVM_PIC_CLASS(klass);
     PICCommonClass *k = PIC_COMMON_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
 
     dc->reset     = kvm_pic_reset;
-    k->init       = kvm_pic_init;
+    kpc->parent_realize = dc->realize;
+    dc->realize   = kvm_pic_realize;
     k->pre_save   = kvm_pic_get;
     k->post_load  = kvm_pic_put;
 }
@@ -130,6 +151,7 @@ static const TypeInfo kvm_i8259_info = {
     .parent = TYPE_PIC_COMMON,
     .instance_size = sizeof(PICCommonState),
     .class_init = kvm_i8259_class_init,
+    .class_size = sizeof(KVMPICClass),
 };
 
 static void kvm_pic_register_types(void)
Signature · 1 line
1.7.10.4
#44 lore raw
In reply to Andreas Färber

Ping,

Am 26.11.2012 01:12, schrieb Andreas Färber:

Quoted 46 lines

Hello Anthony and Paolo,

As announced at KVM Forum, I have been preparing a new approach to incrementally get us Anthony's QOM realizefn concept. A previous attempt by Paolo and me had been turned down for making this available at Object-level and over questions whether BlockDriverState may need its own three-stage realization model.

So here's an all-new patchset doing it at DeviceState-level only, adapting the signature to void realize(DeviceState *, Error **).
CPUState is on a good way to get derived from DeviceState, so in the future will benefit from this approach as well.

I've picked ISADevice as an example to showcase what semantic effects the switch to QOM realizefn has (in the hopes the number of devices would be small):
As requested by Anthony for QOM CPUState reset and as seen with virtual methods in object-oriented programming languages, it becomes the derived method's responsibility to decide when and whether to call the parent class' method. In lack of real vtables this requires to save the parent's method in case we want to call it; classes and matching macros may need to be added for that. Another point to note is that we should carefully distinguish what goes into the qdev initfn / QOM realizefn and what can already go into a QOM initfn.

This series is rebased onto Julien's ioport cleanups (touching on ISA devices).

It starts by preparing the "realized" property, wrapping qdev's initfn (04). This means setting realized to true will not yet affect its children, as seen in Paolo's previous patches. That can be implemented later when the realizefns have been reviewed not to create new devices that would mess with recursive child realization. (In the previous series we had recursive realization but on my request dropped the hook-up of qdev due to the aforementioned quirks.)

At that point there is a coexistence of QOM device realizefn and qdev initfn. For the first time now I have set out to actually eliminate some qdev initfns, that's what I chose ISA for. This consists of three parts, introducing realizefns for ISADevices (28) and recursively for PITs (31) and for PICs (34). As seen for the PCI host bridge series, I've extracted general QOM cleanups from the main conversion patch to arrive at a clean QOM'ish state while hopefully keeping the main patches readable.

This series also highlights an interesting find: Beyond the to-be-solved CPUState, there is also a "realize" function for BusState (02), which is not derived from DeviceState. :-)
With the device-centric approach taken here it would still be possible to add "realized" properties to other types using their own infrastructure (e.g., a hardcoded setter rather than a realizefn hook).

Quoted 6 lines

Posted as an RFC to encourage bikeshedding, in particular about the type names and macros introduced. Adding new header files to move them out of the source files for, e.g., vl.c is left for a follow-up, but for instance I was unsure about TYPE_ISA_FDC (should this be TYPE_ISA_FLOPPY_DRIVE_CONTROLLER as with PCI_HOST_BRIDGE rather than PHB?), and naming of type names and functions is highly inconsistent (e.g., isa_vga vs. vga_isa, or pic vs. i8259).

So far I've heard no comments on the main QOM/ISA part of the series...

Anthony, did I understand you correctly wrt the method overriding? (PIC/PIT) Or did you have this differently in mind?

Anyone any suggestions for improvement? If not, I'll send out a v2 this week, with qdev_free() either rebased onto Paolo or removal dropped. qbus was not further touched in the series, so I'd probably defer the qbus_realize() change.

Branch below is rebased to match v1.3.0 + memory-ioport pull request.

Regards,
Andreas

Quoted 4 lines

Available for viewing/testing at:
https://github.com/afaerber/qemu-cpu/commits/realize-qdev
git://github.com/afaerber/qemu-cpu.git realize-qdev

[...]

Quoted 2 lines

Andreas Färber (34):
qdev: Eliminate qdev_free() in favor of QOM

(depends on what we want to replace qdev_free() with)

Quoted 1 line

qbus: QOM'ify qbus_realize()

(unrelated since qbus did not get a "realized" property in this series)

Quoted 10 lines

qdev: Fold state enum into bool realized
qdev: Prepare "realized" property
isa: Split off instance_init for ISADevice
applesmc: QOM'ify
cirrus_vga: QOM'ify ISA Cirrus VGA
debugcon: QOM'ify ISA debug console
fdc: QOM'ify ISA floppy controller
i82374: QOM'ify

i8259: Fix PIC_COMMON() macro

(applied already)

Quoted 23 lines

i8259: QOM cleanups
ide: QOM'ify ISA IDE
m48t59: QOM'ify ISA M48T59 NVRAM
mc146818rtc: QOM'ify
ne2000-isa: QOM'ify
parallel: QOM'ify
pc: QOM'ify port 92
pckbd: QOM'ify
pcspk: QOM'ify
sb16: QOM'ify
serial: QOM'ify ISA serial
sga: QOM'ify
vga-isa: QOM'ify ISA VGA
vmmouse: QOM'ify
vmport: QOM'ify
wdt_ib700: QOM'ify
isa: Use realizefn for ISADevice
i8254: QOM'ify
kvm/i8254: QOM'ify some more
i8254: Convert PITCommonState to QOM realizefn
i8259: QOM'ify some more
kvm/i8259: QOM'ify some more
i8259: Convert PICCommonState to use QOM realizefn

[snip]

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#45 lore raw
In reply to Andreas Färber

So there are 3-4 different series in here all rolled into one. This makes review a bit tedious.

I'd suggest:

1) Pull out all of the QOMification stuff into a separate series.
2) Pull out the style cleanups into another series
3) Pull out the introduction of realize/unrealize into a series
4) Pull out the ISA use of realize into another series.

Individually, each series looks very easy to merge. The general approach is right along what I was hoping for.

Regards,

Anthony Liguori

Quoted 166 lines · Andreas Färber

Hello Anthony and Paolo,

As announced at KVM Forum, I have been preparing a new approach to incrementally get us Anthony's QOM realizefn concept. A previous attempt by Paolo and me had been turned down for making this available at Object-level and over questions whether BlockDriverState may need its own three-stage realization model.

So here's an all-new patchset doing it at DeviceState-level only, adapting the signature to void realize(DeviceState *, Error **).
CPUState is on a good way to get derived from DeviceState, so in the future will benefit from this approach as well.

I've picked ISADevice as an example to showcase what semantic effects the switch to QOM realizefn has (in the hopes the number of devices would be small):
As requested by Anthony for QOM CPUState reset and as seen with virtual methods in object-oriented programming languages, it becomes the derived method's responsibility to decide when and whether to call the parent class' method. In lack of real vtables this requires to save the parent's method in case we want to call it; classes and matching macros may need to be added for that. Another point to note is that we should carefully distinguish what goes into the qdev initfn / QOM realizefn and what can already go into a QOM initfn.

This series is rebased onto Julien's ioport cleanups (touching on ISA devices).

It starts by preparing the "realized" property, wrapping qdev's initfn (04). This means setting realized to true will not yet affect its children, as seen in Paolo's previous patches. That can be implemented later when the realizefns have been reviewed not to create new devices that would mess with recursive child realization. (In the previous series we had recursive realization but on my request dropped the hook-up of qdev due to the aforementioned quirks.)

At that point there is a coexistence of QOM device realizefn and qdev initfn. For the first time now I have set out to actually eliminate some qdev initfns, that's what I chose ISA for. This consists of three parts, introducing realizefns for ISADevices (28) and recursively for PITs (31) and for PICs (34). As seen for the PCI host bridge series, I've extracted general QOM cleanups from the main conversion patch to arrive at a clean QOM'ish state while hopefully keeping the main patches readable.

This series also highlights an interesting find: Beyond the to-be-solved CPUState, there is also a "realize" function for BusState (02), which is not derived from DeviceState. :-)
With the device-centric approach taken here it would still be possible to add "realized" properties to other types using their own infrastructure (e.g., a hardcoded setter rather than a realizefn hook).

Posted as an RFC to encourage bikeshedding, in particular about the type names and macros introduced. Adding new header files to move them out of the source files for, e.g., vl.c is left for a follow-up, but for instance I was unsure about TYPE_ISA_FDC (should this be TYPE_ISA_FLOPPY_DRIVE_CONTROLLER as with PCI_HOST_BRIDGE rather than PHB?), and naming of type names and functions is highly inconsistent (e.g., isa_vga vs. vga_isa, or pic vs. i8259).

Available for viewing/testing at:
https://github.com/afaerber/qemu-cpu/commits/realize-qdev
git://github.com/afaerber/qemu-cpu.git realize-qdev

Regards,
Andreas

Cc Anthony Liguori <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Julien Grall <[email protected]>
Cc Frederic Konrad <[email protected]>
Cc Peter Maydell <[email protected]>
Cc Cornelia Huck <[email protected]>
Cc Kevin Wolf <[email protected]>
Cc Stefan Hajnoczi <[email protected]>
Cc Markus Armbruster <[email protected]>
Cc Eduardo Habkost <[email protected]>
Cc Igor Mammedov <[email protected]>

Andreas Färber (34):
qdev: Eliminate qdev_free() in favor of QOM
qbus: QOM'ify qbus_realize()
qdev: Fold state enum into bool realized
qdev: Prepare "realized" property
isa: Split off instance_init for ISADevice
applesmc: QOM'ify
cirrus_vga: QOM'ify ISA Cirrus VGA
debugcon: QOM'ify ISA debug console
fdc: QOM'ify ISA floppy controller
i82374: QOM'ify
i8259: Fix PIC_COMMON() macro
i8259: QOM cleanups
ide: QOM'ify ISA IDE
m48t59: QOM'ify ISA M48T59 NVRAM
mc146818rtc: QOM'ify
ne2000-isa: QOM'ify
parallel: QOM'ify
pc: QOM'ify port 92
pckbd: QOM'ify
pcspk: QOM'ify
sb16: QOM'ify
serial: QOM'ify ISA serial
sga: QOM'ify
vga-isa: QOM'ify ISA VGA
vmmouse: QOM'ify
vmport: QOM'ify
wdt_ib700: QOM'ify
isa: Use realizefn for ISADevice
i8254: QOM'ify
kvm/i8254: QOM'ify some more
i8254: Convert PITCommonState to QOM realizefn
i8259: QOM'ify some more
kvm/i8259: QOM'ify some more
i8259: Convert PICCommonState to use QOM realizefn

 hw/acpi_piix4.c      |    2 +-
 hw/applesmc.c        |   45 +++++++++---------
 hw/cirrus_vga.c      |   27 ++++++-----
 hw/debugcon.c        |   34 +++++++++-----
 hw/fdc.c             |   45 ++++++++++--------
 hw/fdc.h             |    2 +
 hw/i82374.c          |   25 +++++-----
 hw/i8254.c           |   26 +++++++---
 hw/i8254.h           |    7 ++-
 hw/i8254_common.c    |   19 ++------
 hw/i8254_internal.h  |    1 -
 hw/i8259.c           |   64 +++++++++++++++++--------
 hw/i8259_common.c    |   20 +++-----
 hw/i8259_internal.h  |    7 +--
 hw/ide/isa.c         |   55 +++++++++++++---------
 hw/isa-bus.c         |   15 ++----
 hw/isa.h             |    1 -
 hw/kvm/i8254.c       |   59 +++++++++++++++--------
 hw/kvm/i8259.c       |   38 ++++++++++++---
 hw/m48t59.c          |   54 +++++++++++----------
 hw/mc146818rtc.c     |   56 ++++++++++++----------
 hw/mc146818rtc.h     |    2 +
 hw/ne2000-isa.c      |   27 ++++++-----
 hw/parallel.c        |   42 ++++++++++-------
 hw/pc.c              |   26 +++++-----
 hw/pc_piix.c         |    2 +-
 hw/pci-hotplug.c     |    2 +-
 hw/pci_bridge.c      |    2 +-
 hw/pcie.c            |    2 +-
 hw/pckbd.c           |   34 ++++++++------
 hw/pcspk.c           |   21 +++++----
 hw/pcspk.h           |    4 +-
 hw/qdev-addr.c       |    2 +-
 hw/qdev-core.h       |   12 ++---
 hw/qdev-monitor.c    |    2 +-
 hw/qdev-properties.c |   28 +++++------
 hw/qdev.c            |  128 ++++++++++++++++++++++++++++++++++----------------
 hw/sb16.c            |   35 +++++++++-----
 hw/scsi-bus.c        |    4 +-
 hw/serial-isa.c      |   33 +++++++------
 hw/serial-pci.c      |    4 +-
 hw/serial.c          |    6 +--
 hw/serial.h          |    3 +-
 hw/sga.c             |   19 ++++----
 hw/shpc.c            |    2 +-
 hw/usb/bus.c         |    7 +--
 hw/usb/dev-storage.c |    2 +-
 hw/usb/host-linux.c  |    2 +-
 hw/vga-isa.c         |   46 +++++++++---------
 hw/vmmouse.c         |   24 +++++-----
 hw/vmport.c          |   24 ++++++----
 hw/wdt_ib700.c       |   22 +++++----
 hw/xen_platform.c    |    2 +-

53 Dateien geändert, 692 Zeilen hinzugefügt(+), 481 Zeilen entfernt(-)

Signature · 1 line
1.7.10.4