From patchwork Tue Nov 22 01:12:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 9440407 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D8448600BA for ; Tue, 22 Nov 2016 01:23:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DC3DC28B67 for ; Tue, 22 Nov 2016 01:23:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D035328B7A; Tue, 22 Nov 2016 01:23:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0D44228B67 for ; Tue, 22 Nov 2016 01:23:01 +0000 (UTC) Received: from localhost ([::1]:52663 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c8znZ-0005KX-11 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 21 Nov 2016 20:23:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34242) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c8zeP-00062s-80 for qemu-devel@nongnu.org; Mon, 21 Nov 2016 20:13:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c8zeN-0005Ag-5F for qemu-devel@nongnu.org; Mon, 21 Nov 2016 20:13:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:20038) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c8zeM-00059F-Rt for qemu-devel@nongnu.org; Mon, 21 Nov 2016 20:13:31 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 024C4C05678F for ; Tue, 22 Nov 2016 01:13:30 +0000 (UTC) Received: from localhost (ovpn-116-207.phx2.redhat.com [10.3.116.207]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uAM1DSff028838; Mon, 21 Nov 2016 20:13:29 -0500 From: Eduardo Habkost To: qemu-devel@nongnu.org, Markus Armbruster , Marcel Apfelbaum , "Michael S. Tsirkin" Date: Mon, 21 Nov 2016 23:12:13 -0200 Message-Id: <1479777133-23567-16-git-send-email-ehabkost@redhat.com> In-Reply-To: <1479777133-23567-1-git-send-email-ehabkost@redhat.com> References: <1479777133-23567-1-git-send-email-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 22 Nov 2016 01:13:30 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC 15/15] qdev: Add device_class_set_bus_type() function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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