Patchwork [06/14] qdev: move properties from businfo to base class instance init

login
register
mail settings
Submitter Anthony Liguori
Date May 1, 2012, 6:18 p.m.
Message ID <1335896294-9530-7-git-send-email-aliguori@us.ibm.com>
Download mbox | patch
Permalink /patch/156182/
State New
Headers show

Comments

Anthony Liguori - May 1, 2012, 6:18 p.m.
This removes knowledge of specific DeviceState subclasses from BusInfos.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
 hw/i2c.c                      |   15 +++++++++++----
 hw/ide/qdev.c                 |   15 +++++++++++----
 hw/intel-hda.c                |   15 +++++++++++----
 hw/pci.c                      |   27 +++++++++++++++++----------
 hw/scsi-bus.c                 |   19 +++++++++++++------
 hw/spapr_vio.c                |   15 +++++++++++----
 hw/usb/bus.c                  |   19 +++++++++++++------
 hw/usb/dev-smartcard-reader.c |   15 +++++++++++----
 hw/virtio-serial-bus.c        |   17 ++++++++++++-----
 9 files changed, 110 insertions(+), 47 deletions(-)

Patch

diff --git a/hw/i2c.c b/hw/i2c.c
index 23dfccb..6d9a7be 100644
--- a/hw/i2c.c
+++ b/hw/i2c.c
@@ -20,10 +20,6 @@  struct i2c_bus
 static struct BusInfo i2c_bus_info = {
     .name = "I2C",
     .size = sizeof(i2c_bus),
-    .props = (Property[]) {
-        DEFINE_PROP_UINT8("address", struct I2CSlave, address, 0),
-        DEFINE_PROP_END_OF_LIST(),
-    }
 };
 
 static void i2c_bus_pre_save(void *opaque)
@@ -221,10 +217,21 @@  static void i2c_slave_class_init(ObjectClass *klass, void *data)
     k->bus_info = &i2c_bus_info;
 }
 
+static Property i2c_bus_properties[] = {
+    DEFINE_PROP_UINT8("address", struct I2CSlave, address, 0),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void i2c_slave_initfn(Object *obj)
+{
+    qdev_add_properties(DEVICE(obj), i2c_bus_properties);
+}
+
 static TypeInfo i2c_slave_type_info = {
     .name = TYPE_I2C_SLAVE,
     .parent = TYPE_DEVICE,
     .instance_size = sizeof(I2CSlave),
+    .instance_init = i2c_slave_initfn,
     .abstract = true,
     .class_size = sizeof(I2CSlaveClass),
     .class_init = i2c_slave_class_init,
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index a46578d..020207a 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -31,10 +31,6 @@  static struct BusInfo ide_bus_info = {
     .name  = "IDE",
     .size  = sizeof(IDEBus),
     .get_fw_dev_path = idebus_get_fw_dev_path,
-    .props = (Property[]) {
-        DEFINE_PROP_UINT32("unit", IDEDevice, unit, -1),
-        DEFINE_PROP_END_OF_LIST(),
-    },
 };
 
 void ide_bus_new(IDEBus *idebus, DeviceState *dev, int bus_id)
@@ -251,10 +247,21 @@  static void ide_device_class_init(ObjectClass *klass, void *data)
     k->bus_info = &ide_bus_info;
 }
 
+static Property ide_bus_properties[] = {
+    DEFINE_PROP_UINT32("unit", IDEDevice, unit, -1),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void ide_device_initfn(Object *obj)
+{
+    qdev_add_properties(DEVICE(obj), ide_bus_properties);
+}
+
 static TypeInfo ide_device_type_info = {
     .name = TYPE_IDE_DEVICE,
     .parent = TYPE_DEVICE,
     .instance_size = sizeof(IDEDevice),
+    .instance_init = ide_device_initfn,
     .abstract = true,
     .class_size = sizeof(IDEDeviceClass),
     .class_init = ide_device_class_init,
diff --git a/hw/intel-hda.c b/hw/intel-hda.c
index bb11af2..9405f54 100644
--- a/hw/intel-hda.c
+++ b/hw/intel-hda.c
@@ -32,10 +32,6 @@ 
 static struct BusInfo hda_codec_bus_info = {
     .name      = "HDA",
     .size      = sizeof(HDACodecBus),
-    .props     = (Property[]) {
-        DEFINE_PROP_UINT32("cad", HDACodecDevice, cad, -1),
-        DEFINE_PROP_END_OF_LIST()
-    }
 };
 
 void hda_codec_bus_init(DeviceState *dev, HDACodecBus *bus,
@@ -1278,10 +1274,21 @@  static void hda_codec_device_class_init(ObjectClass *klass, void *data)
     k->bus_info = &hda_codec_bus_info;
 }
 
+static Property hda_codec_bus_properties[] = {
+    DEFINE_PROP_UINT32("cad", HDACodecDevice, cad, -1),
+    DEFINE_PROP_END_OF_LIST()
+};
+
+static void hda_codec_device_initfn(Object *obj)
+{
+    qdev_add_properties(DEVICE(obj), hda_codec_bus_properties);
+}
+
 static TypeInfo hda_codec_device_type_info = {
     .name = TYPE_HDA_CODEC_DEVICE,
     .parent = TYPE_DEVICE,
     .instance_size = sizeof(HDACodecDevice),
+    .instance_init = hda_codec_device_initfn,
     .abstract = true,
     .class_size = sizeof(HDACodecDeviceClass),
     .class_init = hda_codec_device_class_init,
diff --git a/hw/pci.c b/hw/pci.c
index b706e69..0a77025 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -51,16 +51,6 @@  struct BusInfo pci_bus_info = {
     .get_dev_path = pcibus_get_dev_path,
     .get_fw_dev_path = pcibus_get_fw_dev_path,
     .reset      = pcibus_reset,
-    .props      = (Property[]) {
-        DEFINE_PROP_PCI_DEVFN("addr", PCIDevice, devfn, -1),
-        DEFINE_PROP_STRING("romfile", PCIDevice, romfile),
-        DEFINE_PROP_UINT32("rombar",  PCIDevice, rom_bar, 1),
-        DEFINE_PROP_BIT("multifunction", PCIDevice, cap_present,
-                        QEMU_PCI_CAP_MULTIFUNCTION_BITNR, false),
-        DEFINE_PROP_BIT("command_serr_enable", PCIDevice, cap_present,
-                        QEMU_PCI_CAP_SERR_BITNR, true),
-        DEFINE_PROP_END_OF_LIST()
-    }
 };
 
 static PCIBus *pci_find_bus_nr(PCIBus *bus, int bus_num);
@@ -2004,10 +1994,27 @@  static void pci_device_class_init(ObjectClass *klass, void *data)
     k->bus_info = &pci_bus_info;
 }
 
+static Property pci_bus_properties[] = {
+    DEFINE_PROP_PCI_DEVFN("addr", PCIDevice, devfn, -1),
+    DEFINE_PROP_STRING("romfile", PCIDevice, romfile),
+    DEFINE_PROP_UINT32("rombar",  PCIDevice, rom_bar, 1),
+    DEFINE_PROP_BIT("multifunction", PCIDevice, cap_present,
+                    QEMU_PCI_CAP_MULTIFUNCTION_BITNR, false),
+    DEFINE_PROP_BIT("command_serr_enable", PCIDevice, cap_present,
+                    QEMU_PCI_CAP_SERR_BITNR, true),
+    DEFINE_PROP_END_OF_LIST()
+};
+
+static void pci_device_initfn(Object *obj)
+{
+    qdev_add_properties(DEVICE(obj), pci_bus_properties);
+}
+
 static TypeInfo pci_device_type_info = {
     .name = TYPE_PCI_DEVICE,
     .parent = TYPE_DEVICE,
     .instance_size = sizeof(PCIDevice),
+    .instance_init = pci_device_initfn,
     .abstract = true,
     .class_size = sizeof(PCIDeviceClass),
     .class_init = pci_device_class_init,
diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
index dbdb99c..8071b1c 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi-bus.c
@@ -17,12 +17,6 @@  static struct BusInfo scsi_bus_info = {
     .size  = sizeof(SCSIBus),
     .get_dev_path = scsibus_get_dev_path,
     .get_fw_dev_path = scsibus_get_fw_dev_path,
-    .props = (Property[]) {
-        DEFINE_PROP_UINT32("channel", SCSIDevice, channel, 0),
-        DEFINE_PROP_UINT32("scsi-id", SCSIDevice, id, -1),
-        DEFINE_PROP_UINT32("lun", SCSIDevice, lun, -1),
-        DEFINE_PROP_END_OF_LIST(),
-    },
 };
 static int next_scsi_bus;
 
@@ -1579,10 +1573,23 @@  static void scsi_device_class_init(ObjectClass *klass, void *data)
     k->exit     = scsi_qdev_exit;
 }
 
+static Property scsi_bus_properties[] = {
+    DEFINE_PROP_UINT32("channel", SCSIDevice, channel, 0),
+    DEFINE_PROP_UINT32("scsi-id", SCSIDevice, id, -1),
+    DEFINE_PROP_UINT32("lun", SCSIDevice, lun, -1),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void scsi_device_initfn(Object *obj)
+{
+    qdev_add_properties(DEVICE(obj), scsi_bus_properties);
+}
+
 static TypeInfo scsi_device_type_info = {
     .name = TYPE_SCSI_DEVICE,
     .parent = TYPE_DEVICE,
     .instance_size = sizeof(SCSIDevice),
+    .instance_init = scsi_device_initfn,
     .abstract = true,
     .class_size = sizeof(SCSIDeviceClass),
     .class_init = scsi_device_class_init,
diff --git a/hw/spapr_vio.c b/hw/spapr_vio.c
index fccf48b..2529e09 100644
--- a/hw/spapr_vio.c
+++ b/hw/spapr_vio.c
@@ -52,10 +52,6 @@ 
 static struct BusInfo spapr_vio_bus_info = {
     .name       = "spapr-vio",
     .size       = sizeof(VIOsPAPRBus),
-    .props = (Property[]) {
-        DEFINE_PROP_UINT32("irq", VIOsPAPRDevice, vio_irq_num, 0), \
-        DEFINE_PROP_END_OF_LIST(),
-    },
 };
 
 VIOsPAPRDevice *spapr_vio_find_by_reg(VIOsPAPRBus *bus, uint32_t reg)
@@ -783,10 +779,21 @@  static void vio_spapr_device_class_init(ObjectClass *klass, void *data)
     k->bus_info = &spapr_vio_bus_info;
 }
 
+static Property spapr_vio_bus_properties[] = {
+    DEFINE_PROP_UINT32("irq", VIOsPAPRDevice, vio_irq_num, 0),  \
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void vio_spapr_device_initfn(Object *obj)
+{
+    qdev_add_properties(DEVICE(obj), spapr_vio_bus_properties);
+}
+
 static TypeInfo spapr_vio_type_info = {
     .name = TYPE_VIO_SPAPR_DEVICE,
     .parent = TYPE_DEVICE,
     .instance_size = sizeof(VIOsPAPRDevice),
+    .instance_init = vio_spapr_device_initfn,
     .abstract = true,
     .class_size = sizeof(VIOsPAPRDeviceClass),
     .class_init = vio_spapr_device_class_init,
diff --git a/hw/usb/bus.c b/hw/usb/bus.c
index 2068640..8f1eae0 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -17,12 +17,6 @@  static struct BusInfo usb_bus_info = {
     .print_dev = usb_bus_dev_print,
     .get_dev_path = usb_get_dev_path,
     .get_fw_dev_path = usb_get_fw_dev_path,
-    .props      = (Property[]) {
-        DEFINE_PROP_STRING("port", USBDevice, port_path),
-        DEFINE_PROP_BIT("full-path", USBDevice, flags,
-                        USB_DEV_FLAG_FULL_PATH, true),
-        DEFINE_PROP_END_OF_LIST()
-    },
 };
 static int next_usb_bus = 0;
 static QTAILQ_HEAD(, USBBus) busses = QTAILQ_HEAD_INITIALIZER(busses);
@@ -582,10 +576,23 @@  static void usb_device_class_init(ObjectClass *klass, void *data)
     k->exit     = usb_qdev_exit;
 }
 
+static Property usb_bus_properties[] = {
+    DEFINE_PROP_STRING("port", USBDevice, port_path),
+    DEFINE_PROP_BIT("full-path", USBDevice, flags,
+                    USB_DEV_FLAG_FULL_PATH, true),
+    DEFINE_PROP_END_OF_LIST()
+};
+
+static void usb_device_initfn(Object *obj)
+{
+    qdev_add_properties(DEVICE(obj), usb_bus_properties);
+}
+
 static TypeInfo usb_device_type_info = {
     .name = TYPE_USB_DEVICE,
     .parent = TYPE_DEVICE,
     .instance_size = sizeof(USBDevice),
+    .instance_init = usb_device_initfn,
     .abstract = true,
     .class_size = sizeof(USBDeviceClass),
     .class_init = usb_device_class_init,
diff --git a/hw/usb/dev-smartcard-reader.c b/hw/usb/dev-smartcard-reader.c
index 3b7604e..e64e5c9 100644
--- a/hw/usb/dev-smartcard-reader.c
+++ b/hw/usb/dev-smartcard-reader.c
@@ -1058,10 +1058,6 @@  static Answer *ccid_peek_next_answer(USBCCIDState *s)
 static struct BusInfo ccid_bus_info = {
     .name = "ccid-bus",
     .size = sizeof(CCIDBus),
-    .props = (Property[]) {
-        DEFINE_PROP_UINT32("slot", struct CCIDCardState, slot, 0),
-        DEFINE_PROP_END_OF_LIST(),
-    }
 };
 
 void ccid_card_send_apdu_to_guest(CCIDCardState *card,
@@ -1347,10 +1343,21 @@  static void ccid_card_class_init(ObjectClass *klass, void *data)
     k->exit = ccid_card_exit;
 }
 
+static Property ccid_bus_properties[] = {
+    DEFINE_PROP_UINT32("slot", struct CCIDCardState, slot, 0),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void ccid_card_instance_initfn(Object *obj)
+{
+    qdev_add_properties(DEVICE(obj), ccid_bus_properties);
+}
+
 static TypeInfo ccid_card_type_info = {
     .name = TYPE_CCID_CARD,
     .parent = TYPE_DEVICE,
     .instance_size = sizeof(CCIDCardState),
+    .instance_init = ccid_card_instance_initfn,
     .abstract = true,
     .class_size = sizeof(CCIDCardClass),
     .class_init = ccid_card_class_init,
diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
index ffbdfc2..ca480dd 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/virtio-serial-bus.c
@@ -728,11 +728,6 @@  static struct BusInfo virtser_bus_info = {
     .name      = "virtio-serial-bus",
     .size      = sizeof(VirtIOSerialBus),
     .print_dev = virtser_bus_dev_print,
-    .props      = (Property[]) {
-        DEFINE_PROP_UINT32("nr", VirtIOSerialPort, id, VIRTIO_CONSOLE_BAD_ID),
-        DEFINE_PROP_STRING("name", VirtIOSerialPort, name),
-        DEFINE_PROP_END_OF_LIST()
-    }
 };
 
 static void virtser_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent)
@@ -981,10 +976,22 @@  static void virtio_serial_port_class_init(ObjectClass *klass, void *data)
     k->unplug = qdev_simple_unplug_cb;
 }
 
+static Property virtser_bus_properties[] = {
+    DEFINE_PROP_UINT32("nr", VirtIOSerialPort, id, VIRTIO_CONSOLE_BAD_ID),
+    DEFINE_PROP_STRING("name", VirtIOSerialPort, name),
+    DEFINE_PROP_END_OF_LIST()
+};
+
+static void virtio_serial_port_initfn(Object *obj)
+{
+    qdev_add_properties(DEVICE(obj), virtser_bus_properties);
+}
+
 static TypeInfo virtio_serial_port_type_info = {
     .name = TYPE_VIRTIO_SERIAL_PORT,
     .parent = TYPE_DEVICE,
     .instance_size = sizeof(VirtIOSerialPort),
+    .instance_init = virtio_serial_port_initfn,
     .abstract = true,
     .class_size = sizeof(VirtIOSerialPortClass),
     .class_init = virtio_serial_port_class_init,