@@ -1327,7 +1327,7 @@ static void hda_codec_device_class_init(ObjectClass *klass, void *data)
k->realize = hda_codec_dev_realize;
k->exit = hda_codec_dev_exit;
set_bit(DEVICE_CATEGORY_SOUND, k->categories);
- k->bus_type = TYPE_HDA_BUS;
+ device_class_set_bus_type(k, TYPE_HDA_BUS);
k->props = hda_props;
}
@@ -593,7 +593,7 @@ static void floppy_drive_class_init(ObjectClass *klass, void *data)
DeviceClass *k = DEVICE_CLASS(klass);
k->init = floppy_drive_init;
set_bit(DEVICE_CATEGORY_STORAGE, k->categories);
- k->bus_type = TYPE_FLOPPY_BUS;
+ device_class_set_bus_type(k, TYPE_FLOPPY_BUS);
k->props = floppy_drive_properties;
k->desc = "virtual floppy drive";
}
@@ -1089,7 +1089,7 @@ static void virtio_serial_port_class_init(ObjectClass *klass, void *data)
DeviceClass *k = DEVICE_CLASS(klass);
set_bit(DEVICE_CATEGORY_INPUT, k->categories);
- k->bus_type = TYPE_VIRTIO_SERIAL_BUS;
+ device_class_set_bus_type(k, TYPE_VIRTIO_SERIAL_BUS);
k->realize = virtser_port_device_realize;
k->unrealize = virtser_port_device_unrealize;
k->props = virtser_props;
@@ -1080,6 +1080,14 @@ static void device_finalize(Object *obj)
}
}
+void device_class_set_bus_type(DeviceClass *dc, const char *bus_type)
+{
+ BusClass *bc = BUS_CLASS(object_class_by_name(bus_type));
+
+ assert(object_class_dynamic_cast(OBJECT_CLASS(dc), bc->device_type));
+ dc->bus_type = bus_type;
+}
+
static void device_class_base_init(ObjectClass *class, void *data)
{
DeviceClass *klass = DEVICE_CLASS(class);
@@ -326,7 +326,7 @@ static void sysbus_device_class_init(ObjectClass *klass, void *data)
{
DeviceClass *k = DEVICE_CLASS(klass);
k->init = sysbus_device_init;
- k->bus_type = TYPE_SYSTEM_BUS;
+ device_class_set_bus_type(k, TYPE_SYSTEM_BUS);
}
static const TypeInfo sysbus_device_type_info = {
@@ -285,7 +285,7 @@ static void i2c_slave_class_init(ObjectClass *klass, void *data)
DeviceClass *k = DEVICE_CLASS(klass);
k->init = i2c_slave_qdev_init;
set_bit(DEVICE_CATEGORY_MISC, k->categories);
- k->bus_type = TYPE_I2C_BUS;
+ device_class_set_bus_type(k, TYPE_I2C_BUS);
k->props = i2c_props;
}
@@ -365,7 +365,7 @@ static void ide_device_class_init(ObjectClass *klass, void *data)
DeviceClass *k = DEVICE_CLASS(klass);
k->init = ide_qdev_init;
set_bit(DEVICE_CATEGORY_STORAGE, k->categories);
- k->bus_type = TYPE_IDE_BUS;
+ device_class_set_bus_type(k, TYPE_IDE_BUS);
k->unrealize = idebus_unrealize;
k->props = ide_props;
}
@@ -162,7 +162,7 @@ static void adb_device_class_init(ObjectClass *oc, void *data)
DeviceClass *dc = DEVICE_CLASS(oc);
dc->realize = adb_device_realizefn;
- dc->bus_type = TYPE_ADB_BUS;
+ device_class_set_bus_type(dc, TYPE_ADB_BUS);
}
static const TypeInfo adb_device_type_info = {
@@ -81,7 +81,7 @@ static void ipack_device_class_init(ObjectClass *klass, void *data)
DeviceClass *k = DEVICE_CLASS(klass);
set_bit(DEVICE_CATEGORY_INPUT, k->categories);
- k->bus_type = TYPE_IPACK_BUS;
+ device_class_set_bus_type(k, TYPE_IPACK_BUS);
k->realize = ipack_device_realize;
k->unrealize = ipack_device_unrealize;
k->props = ipack_device_props;
@@ -233,7 +233,7 @@ static const TypeInfo isabus_bridge_info = {
static void isa_device_class_init(ObjectClass *klass, void *data)
{
DeviceClass *k = DEVICE_CLASS(klass);
- k->bus_type = TYPE_ISA_BUS;
+ device_class_set_bus_type(k, TYPE_ISA_BUS);
}
static const TypeInfo isa_device_type_info = {
@@ -272,7 +272,7 @@ static void aux_slave_class_init(ObjectClass *klass, void *data)
DeviceClass *k = DEVICE_CLASS(klass);
set_bit(DEVICE_CATEGORY_MISC, k->categories);
- k->bus_type = TYPE_AUX_BUS;
+ device_class_set_bus_type(k, TYPE_AUX_BUS);
}
static const TypeInfo aux_slave_type_info = {
@@ -2504,7 +2504,7 @@ static void pci_device_class_init(ObjectClass *klass, void *data)
k->realize = pci_qdev_realize;
k->unrealize = pci_qdev_unrealize;
- k->bus_type = TYPE_PCI_BUS;
+ device_class_set_bus_type(k, TYPE_PCI_BUS);
k->props = pci_props;
pc->realize = pci_default_realize;
}
@@ -586,7 +586,7 @@ static void vio_spapr_device_class_init(ObjectClass *klass, void *data)
DeviceClass *k = DEVICE_CLASS(klass);
k->realize = spapr_vio_busdev_realize;
k->reset = spapr_vio_busdev_reset;
- k->bus_type = TYPE_SPAPR_VIO_BUS;
+ device_class_set_bus_type(k, TYPE_SPAPR_VIO_BUS);
k->props = spapr_vio_props;
}
@@ -426,7 +426,7 @@ static void event_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
- dc->bus_type = TYPE_SCLP_EVENTS_BUS;
+ device_class_set_bus_type(dc, TYPE_SCLP_EVENTS_BUS);
dc->realize = event_realize;
dc->unrealize = event_unrealize;
}
@@ -939,7 +939,7 @@ static void s390_pci_device_class_init(ObjectClass *klass, void *data)
dc->desc = "zpci device";
dc->reset = s390_pci_device_reset;
- dc->bus_type = TYPE_S390_PCI_BUS;
+ device_class_set_bus_type(dc, TYPE_S390_PCI_BUS);
dc->realize = s390_pci_device_realize;
dc->props = s390_pci_device_properties;
}
@@ -1550,7 +1550,7 @@ static void virtio_ccw_device_class_init(ObjectClass *klass, void *data)
k->unplug = virtio_ccw_busdev_unplug;
dc->realize = virtio_ccw_busdev_realize;
dc->exit = virtio_ccw_busdev_exit;
- dc->bus_type = TYPE_VIRTUAL_CSS_BUS;
+ device_class_set_bus_type(dc, TYPE_VIRTUAL_CSS_BUS);
}
static const TypeInfo virtio_ccw_device_info = {
@@ -2067,7 +2067,7 @@ static void scsi_device_class_init(ObjectClass *klass, void *data)
{
DeviceClass *k = DEVICE_CLASS(klass);
set_bit(DEVICE_CATEGORY_STORAGE, k->categories);
- k->bus_type = TYPE_SCSI_BUS;
+ device_class_set_bus_type(k, TYPE_SCSI_BUS);
k->realize = scsi_qdev_realize;
k->unrealize = scsi_qdev_unrealize;
k->props = scsi_props;
@@ -1917,7 +1917,7 @@ static void sd_class_init(ObjectClass *klass, void *data)
dc->props = sd_properties;
dc->vmsd = &sd_vmstate;
dc->reset = sd_reset;
- dc->bus_type = TYPE_SD_BUS;
+ device_class_set_bus_type(dc, TYPE_SD_BUS);
sc->do_command = sd_do_command;
sc->write_data = sd_write_data;
@@ -80,7 +80,7 @@ static void ssi_slave_class_init(ObjectClass *klass, void *data)
DeviceClass *dc = DEVICE_CLASS(klass);
dc->realize = ssi_slave_realize;
- dc->bus_type = TYPE_SSI_BUS;
+ device_class_set_bus_type(dc, TYPE_SSI_BUS);
if (!ssc->transfer_raw) {
ssc->transfer_raw = ssi_transfer_raw_default;
}
@@ -789,7 +789,7 @@ static void usb_device_instance_init(Object *obj)
static void usb_device_class_init(ObjectClass *klass, void *data)
{
DeviceClass *k = DEVICE_CLASS(klass);
- k->bus_type = TYPE_USB_BUS;
+ device_class_set_bus_type(k, TYPE_USB_BUS);
k->realize = usb_qdev_realize;
k->unrealize = usb_qdev_unrealize;
k->props = usb_props;
@@ -1487,7 +1487,7 @@ static const TypeInfo ccid_info = {
static void ccid_card_class_init(ObjectClass *klass, void *data)
{
DeviceClass *k = DEVICE_CLASS(klass);
- k->bus_type = TYPE_CCID_BUS;
+ device_class_set_bus_type(k, TYPE_CCID_BUS);
k->init = ccid_card_init;
k->exit = ccid_card_exit;
k->props = ccid_props;
@@ -2247,7 +2247,7 @@ static void virtio_device_class_init(ObjectClass *klass, void *data)
dc->realize = virtio_device_realize;
dc->unrealize = virtio_device_unrealize;
- dc->bus_type = TYPE_VIRTIO_BUS;
+ device_class_set_bus_type(dc, TYPE_VIRTIO_BUS);
dc->props = virtio_properties;
vdc->start_ioeventfd = virtio_device_start_ioeventfd_impl;
vdc->stop_ioeventfd = virtio_device_stop_ioeventfd_impl;
@@ -406,4 +406,6 @@ static inline bool qbus_is_hotpluggable(BusState *bus)
void device_listener_register(DeviceListener *listener);
void device_listener_unregister(DeviceListener *listener);
+void device_class_set_bus_type(DeviceClass *dc, const char *bus_type);
+
#endif
Add a function set BusClass::bus_type, so we can perform extra validation of the field, to ensure the corresponding bus class has supported_device_types set propertly. Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> --- hw/audio/intel-hda.c | 2 +- hw/block/fdc.c | 2 +- hw/char/virtio-serial-bus.c | 2 +- hw/core/qdev.c | 8 ++++++++ hw/core/sysbus.c | 2 +- hw/i2c/core.c | 2 +- hw/ide/qdev.c | 2 +- hw/input/adb.c | 2 +- hw/ipack/ipack.c | 2 +- hw/isa/isa-bus.c | 2 +- hw/misc/auxbus.c | 2 +- hw/pci/pci.c | 2 +- hw/ppc/spapr_vio.c | 2 +- hw/s390x/event-facility.c | 2 +- hw/s390x/s390-pci-bus.c | 2 +- hw/s390x/virtio-ccw.c | 2 +- hw/scsi/scsi-bus.c | 2 +- hw/sd/sd.c | 2 +- hw/ssi/ssi.c | 2 +- hw/usb/bus.c | 2 +- hw/usb/dev-smartcard-reader.c | 2 +- hw/virtio/virtio.c | 2 +- include/hw/qdev-core.h | 2 ++ 23 files changed, 31 insertions(+), 21 deletions(-)