qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: qemu-devel@nongnu.org, Markus Armbruster <armbru@redhat.com>,
	Marcel Apfelbaum <marcel@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>
Subject: [Qemu-devel] [RFC 15/15] qdev: Add device_class_set_bus_type() function
Date: Mon, 21 Nov 2016 23:12:13 -0200	[thread overview]
Message-ID: <1479777133-23567-16-git-send-email-ehabkost@redhat.com> (raw)
In-Reply-To: <1479777133-23567-1-git-send-email-ehabkost@redhat.com>

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(-)

diff --git a/hw/audio/intel-hda.c b/hw/audio/intel-hda.c
index a363993..5f18595 100644
--- a/hw/audio/intel-hda.c
+++ b/hw/audio/intel-hda.c
@@ -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;
 }
 
diff --git a/hw/block/fdc.c b/hw/block/fdc.c
index 09bfdda..da655a6 100644
--- a/hw/block/fdc.c
+++ b/hw/block/fdc.c
@@ -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";
 }
diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index 215e180..ec0906a 100644
--- a/hw/char/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -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;
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 5783442..65ed738 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -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);
diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
index c065eb8..ee3b768 100644
--- a/hw/core/sysbus.c
+++ b/hw/core/sysbus.c
@@ -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 = {
diff --git a/hw/i2c/core.c b/hw/i2c/core.c
index 81b6ae4..66254ae 100644
--- a/hw/i2c/core.c
+++ b/hw/i2c/core.c
@@ -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;
 }
 
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index b526f85..35a65a0 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -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;
 }
diff --git a/hw/input/adb.c b/hw/input/adb.c
index c6a2b31..0e64b1c 100644
--- a/hw/input/adb.c
+++ b/hw/input/adb.c
@@ -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 = {
diff --git a/hw/ipack/ipack.c b/hw/ipack/ipack.c
index f22c504..8a7fb63 100644
--- a/hw/ipack/ipack.c
+++ b/hw/ipack/ipack.c
@@ -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;
diff --git a/hw/isa/isa-bus.c b/hw/isa/isa-bus.c
index aad7669..f97fe52 100644
--- a/hw/isa/isa-bus.c
+++ b/hw/isa/isa-bus.c
@@ -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 = {
diff --git a/hw/misc/auxbus.c b/hw/misc/auxbus.c
index 4b0d565..b310dc4 100644
--- a/hw/misc/auxbus.c
+++ b/hw/misc/auxbus.c
@@ -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 = {
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 1b0b7d3..be8ed2e 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -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;
 }
diff --git a/hw/ppc/spapr_vio.c b/hw/ppc/spapr_vio.c
index c70b9b9..53cb87c 100644
--- a/hw/ppc/spapr_vio.c
+++ b/hw/ppc/spapr_vio.c
@@ -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;
 }
 
diff --git a/hw/s390x/event-facility.c b/hw/s390x/event-facility.c
index f2562ce..527ba36 100644
--- a/hw/s390x/event-facility.c
+++ b/hw/s390x/event-facility.c
@@ -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;
 }
diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
index 7470fdd..a29c729 100644
--- a/hw/s390x/s390-pci-bus.c
+++ b/hw/s390x/s390-pci-bus.c
@@ -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;
 }
diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
index f5c1d98..b4ce290 100644
--- a/hw/s390x/virtio-ccw.c
+++ b/hw/s390x/virtio-ccw.c
@@ -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 = {
diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c
index 9faf45f..b60079a 100644
--- a/hw/scsi/scsi-bus.c
+++ b/hw/scsi/scsi-bus.c
@@ -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;
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 8e88e83..b1e5bc6 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -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;
diff --git a/hw/ssi/ssi.c b/hw/ssi/ssi.c
index c48920d..b97d726 100644
--- a/hw/ssi/ssi.c
+++ b/hw/ssi/ssi.c
@@ -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;
     }
diff --git a/hw/usb/bus.c b/hw/usb/bus.c
index 2cb7fa4..978d9d5 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -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;
diff --git a/hw/usb/dev-smartcard-reader.c b/hw/usb/dev-smartcard-reader.c
index 2721f0c..a7cf0f9 100644
--- a/hw/usb/dev-smartcard-reader.c
+++ b/hw/usb/dev-smartcard-reader.c
@@ -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;
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 1af2de2..9dfab8a 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -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;
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 7c34f14..2f82950 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -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
-- 
2.7.4

  parent reply	other threads:[~2016-11-22  1:13 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-22  1:11 [Qemu-devel] [RFC 00/15] qmp: Report supported device types on 'query-machines' Eduardo Habkost
2016-11-22  1:11 ` [Qemu-devel] [RFC 01/15] qemu.py: Make logging optional Eduardo Habkost
2016-11-22  1:12 ` [Qemu-devel] [RFC 02/15] qtest.py: Support QTEST_LOG environment variable Eduardo Habkost
2016-11-22  1:12 ` [Qemu-devel] [RFC 03/15] qtest.py: make logging optional Eduardo Habkost
2016-11-22  1:12 ` [Qemu-devel] [RFC 04/15] qtest.py: Make 'binary' parameter optional Eduardo Habkost
2016-11-22  1:12 ` [Qemu-devel] [RFC 05/15] tests: Add rules to non-gtester qtest test cases Eduardo Habkost
2016-11-22 13:34   ` Eduardo Habkost
2016-11-22  1:12 ` [Qemu-devel] [RFC 06/15] qdev: Add device_type field to BusClass Eduardo Habkost
2016-11-24 16:48   ` Cornelia Huck
2016-11-24 17:37     ` Eduardo Habkost
2016-11-22  1:12 ` [Qemu-devel] [RFC 07/15] machine: Add MachineClass::default_buses field Eduardo Habkost
2016-11-22  1:12 ` [Qemu-devel] [RFC 08/15] qmp: Add 'supported-device-types' field to 'query-machines' Eduardo Habkost
2016-11-22  1:12 ` [Qemu-devel] [RFC 09/15] pci: Introduce INTERFACE_PCIE_DEVICE interface name Eduardo Habkost
2016-11-22  1:12 ` [Qemu-devel] [RFC 10/15] pc: Initialize default bus lists Eduardo Habkost
2016-11-22  1:12 ` [Qemu-devel] [RFC 11/15] s390x: " Eduardo Habkost
2016-12-05 15:24   ` David Hildenbrand
2016-12-05 16:03     ` Cornelia Huck
2016-12-05 16:38       ` Eduardo Habkost
2016-11-22  1:12 ` [Qemu-devel] [RFC 12/15] arm: " Eduardo Habkost
2016-11-22  1:12 ` [Qemu-devel] [RFC 13/15] mips: " Eduardo Habkost
2016-11-22  1:12 ` [Qemu-devel] [RFC 14/15] ppc: " Eduardo Habkost
2016-11-23  3:42   ` Alexey Kardashevskiy
2016-11-22  1:12 ` Eduardo Habkost [this message]
2016-11-22  1:34 ` [Qemu-devel] [RFC 00/15] qmp: Report supported device types on 'query-machines' no-reply
2016-11-22  1:36 ` no-reply
2016-11-22  8:18 ` David Hildenbrand
2016-11-22 13:09   ` Eduardo Habkost
2016-11-22 22:34 ` Eduardo Habkost
2016-11-23 17:10   ` [Qemu-devel] -nodefaults and available buses (was Re: [RFC 00/15] qmp: Report supported device types on 'query-machines') Eduardo Habkost
2016-11-24  1:51     ` David Gibson
2016-11-24 16:30       ` Cornelia Huck
2016-11-24 17:42         ` Eduardo Habkost
2016-11-24 13:39     ` Markus Armbruster
2016-11-23 16:43 ` [Qemu-devel] [RFC 00/15] qmp: Report supported device types on 'query-machines' Marcel Apfelbaum
2016-11-23 17:35   ` Eduardo Habkost
2016-11-24  9:34     ` Marcel Apfelbaum
2016-11-24 13:34     ` Markus Armbruster
2016-11-24 14:12       ` Eduardo Habkost
2016-11-24 14:55         ` Markus Armbruster
2016-11-24 14:22       ` Marcel Apfelbaum
2016-11-24 15:41         ` Markus Armbruster
2016-11-24 16:31           ` Marcel Apfelbaum
2016-11-25  8:03             ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1479777133-23567-16-git-send-email-ehabkost@redhat.com \
    --to=ehabkost@redhat.com \
    --cc=armbru@redhat.com \
    --cc=marcel@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).