From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: aliguori@us.ibm.com, afaerber@suse.de
Subject: [Qemu-devel] [PATCH 13/25] qdev: replace bus properties with superclass properties
Date: Tue, 3 Apr 2012 13:15:41 +0200 [thread overview]
Message-ID: <1333451753-3550-14-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1333451753-3550-1-git-send-email-pbonzini@redhat.com>
After the previous patch, this one changes all bus property walks to
look along the class hierarchy instead. Bus properties are moved to
abstract classes.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/i2c.c | 2 +-
hw/ide/qdev.c | 2 +-
hw/intel-hda.c | 2 +-
hw/pci.c | 2 +-
hw/qdev-monitor.c | 41 ++++++++++++++++++-----------------------
hw/qdev-properties.c | 17 +++++++++--------
hw/qdev.c | 32 +++++++++-----------------------
hw/qdev.h | 5 -----
hw/scsi-bus.c | 2 +-
hw/spapr_vio.c | 2 +-
hw/usb/bus.c | 2 +-
hw/usb/dev-smartcard-reader.c | 2 +-
hw/virtio-serial-bus.c | 2 +-
13 files changed, 45 insertions(+), 68 deletions(-)
diff --git a/hw/i2c.c b/hw/i2c.c
index cb10b1d..af5979e 100644
--- a/hw/i2c.c
+++ b/hw/i2c.c
@@ -25,7 +25,6 @@ static Property i2c_props[] = {
static struct BusInfo i2c_bus_info = {
.name = "I2C",
.size = sizeof(i2c_bus),
- .props = i2c_props,
};
static void i2c_bus_pre_save(void *opaque)
@@ -221,6 +220,7 @@ static void i2c_slave_class_init(ObjectClass *klass, void *data)
DeviceClass *k = DEVICE_CLASS(klass);
k->init = i2c_slave_qdev_init;
k->bus_info = &i2c_bus_info;
+ k->props = i2c_props;
}
static TypeInfo i2c_slave_type_info = {
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index 4d372f8..27ff47c 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -36,7 +36,6 @@ static struct BusInfo ide_bus_info = {
.name = "IDE",
.size = sizeof(IDEBus),
.get_fw_dev_path = idebus_get_fw_dev_path,
- .props = ide_props,
};
void ide_bus_new(IDEBus *idebus, DeviceState *dev, int bus_id)
@@ -248,6 +247,7 @@ static void ide_device_class_init(ObjectClass *klass, void *data)
DeviceClass *k = DEVICE_CLASS(klass);
k->init = ide_qdev_init;
k->bus_info = &ide_bus_info;
+ k->props = ide_props;
}
static TypeInfo ide_device_type_info = {
diff --git a/hw/intel-hda.c b/hw/intel-hda.c
index 0994f6b..e2bd41e 100644
--- a/hw/intel-hda.c
+++ b/hw/intel-hda.c
@@ -37,7 +37,6 @@ static Property hda_props[] = {
static struct BusInfo hda_codec_bus_info = {
.name = "HDA",
.size = sizeof(HDACodecBus),
- .props = hda_props,
};
void hda_codec_bus_init(DeviceState *dev, HDACodecBus *bus,
@@ -1278,6 +1277,7 @@ static void hda_codec_device_class_init(ObjectClass *klass, void *data)
k->init = hda_codec_dev_init;
k->exit = hda_codec_dev_exit;
k->bus_info = &hda_codec_bus_info;
+ k->props = hda_props;
}
static TypeInfo hda_codec_device_type_info = {
diff --git a/hw/pci.c b/hw/pci.c
index fff4c4a..4e8e726 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -62,7 +62,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 = pci_props,
};
static void pci_update_mappings(PCIDevice *d);
@@ -2004,6 +2003,7 @@ static void pci_device_class_init(ObjectClass *klass, void *data)
k->unplug = pci_unplug_device;
k->exit = pci_unregister_device;
k->bus_info = &pci_bus_info;
+ k->props = pci_props;
}
static TypeInfo pci_device_type_info = {
diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
index 3d95940..d4fc843 100644
--- a/hw/qdev-monitor.c
+++ b/hw/qdev-monitor.c
@@ -122,7 +122,6 @@ int qdev_device_help(QemuOpts *opts)
const char *driver;
Property *prop;
ObjectClass *klass;
- DeviceClass *info;
driver = qemu_opt_get(opts, "driver");
if (driver && !strcmp(driver, "?")) {
@@ -148,30 +147,22 @@ int qdev_device_help(QemuOpts *opts)
if (!klass) {
return 0;
}
- info = DEVICE_CLASS(klass);
-
- for (prop = info->props; prop && prop->name; prop++) {
- /*
- * TODO Properties without a parser are just for dirty hacks.
- * qdev_prop_ptr is the only such PropertyInfo. It's marked
- * for removal. This conditional should be removed along with
- * it.
- */
- if (!prop->info->set) {
- continue; /* no way to set it, don't show */
- }
- error_printf("%s.%s=%s\n", driver, prop->name,
- prop->info->legacy_name ?: prop->info->name);
- }
- if (info->bus_info) {
- for (prop = info->bus_info->props; prop && prop->name; prop++) {
+ do {
+ for (prop = DEVICE_CLASS(klass)->props; prop && prop->name; prop++) {
+ /*
+ * TODO Properties without a parser are just for dirty hacks.
+ * qdev_prop_ptr is the only such PropertyInfo. It's marked
+ * for removal. This conditional should be removed along with
+ * it.
+ */
if (!prop->info->set) {
continue; /* no way to set it, don't show */
}
error_printf("%s.%s=%s\n", driver, prop->name,
prop->info->legacy_name ?: prop->info->name);
}
- }
+ klass = object_class_get_parent(klass);
+ } while (klass != object_class_by_name(TYPE_DEVICE));
return 1;
}
@@ -480,7 +471,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
static void qbus_print(Monitor *mon, BusState *bus, int indent);
static void qdev_print_props(Monitor *mon, DeviceState *dev, Property *props,
- const char *prefix, int indent)
+ int indent)
{
if (!props)
return;
@@ -499,7 +490,7 @@ static void qdev_print_props(Monitor *mon, DeviceState *dev, Property *props,
error_free(err);
continue;
}
- qdev_printf("%s-prop: %s = %s\n", prefix, props->name,
+ qdev_printf("%s = %s\n", props->name,
value && *value ? value : "<null>");
g_free(value);
}
@@ -507,6 +498,7 @@ static void qdev_print_props(Monitor *mon, DeviceState *dev, Property *props,
static void qdev_print(Monitor *mon, DeviceState *dev, int indent)
{
+ ObjectClass *class;
BusState *child;
qdev_printf("dev: %s, id \"%s\"\n", object_get_typename(OBJECT(dev)),
dev->id ? dev->id : "");
@@ -517,8 +509,11 @@ static void qdev_print(Monitor *mon, DeviceState *dev, int indent)
if (dev->num_gpio_out) {
qdev_printf("gpio-out %d\n", dev->num_gpio_out);
}
- qdev_print_props(mon, dev, qdev_get_props(dev), "dev", indent);
- qdev_print_props(mon, dev, dev->parent_bus->info->props, "bus", indent);
+ class = object_get_class(OBJECT(dev));
+ do {
+ qdev_print_props(mon, dev, DEVICE_CLASS(class)->props, indent);
+ class = object_class_get_parent(class);
+ } while (class != object_class_by_name(TYPE_DEVICE));
if (dev->parent_bus->info->print_dev)
dev->parent_bus->info->print_dev(mon, dev, indent);
QLIST_FOREACH(child, &dev->child_bus, sibling) {
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index a9276f9..60fef9a 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -893,17 +893,18 @@ static Property *qdev_prop_walk(Property *props, const char *name)
static Property *qdev_prop_find(DeviceState *dev, const char *name)
{
+ ObjectClass *class;
Property *prop;
/* device properties */
- prop = qdev_prop_walk(qdev_get_props(dev), name);
- if (prop)
- return prop;
-
- /* bus properties */
- prop = qdev_prop_walk(dev->parent_bus->info->props, name);
- if (prop)
- return prop;
+ class = object_get_class(OBJECT(dev));
+ do {
+ prop = qdev_prop_walk(DEVICE_CLASS(class)->props, name);
+ if (prop) {
+ return prop;
+ }
+ class = object_class_get_parent(class);
+ } while (class != object_class_by_name(TYPE_DEVICE));
return NULL;
}
diff --git a/hw/qdev.c b/hw/qdev.c
index adef566..aeebb86 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -44,18 +44,6 @@ const VMStateDescription *qdev_get_vmsd(DeviceState *dev)
return dc->vmsd;
}
-BusInfo *qdev_get_bus_info(DeviceState *dev)
-{
- DeviceClass *dc = DEVICE_GET_CLASS(dev);
- return dc->bus_info;
-}
-
-Property *qdev_get_props(DeviceState *dev)
-{
- DeviceClass *dc = DEVICE_GET_CLASS(dev);
- return dc->props;
-}
-
const char *qdev_fw_name(DeviceState *dev)
{
DeviceClass *dc = DEVICE_GET_CLASS(dev);
@@ -77,19 +65,12 @@ static void qdev_property_add_legacy(DeviceState *dev, Property *prop,
void qdev_set_parent_bus(DeviceState *dev, BusState *bus)
{
- Property *prop;
-
if (qdev_hotplug) {
assert(bus->allow_hotplug);
}
dev->parent_bus = bus;
QTAILQ_INSERT_HEAD(&bus->children, dev, sibling);
-
- for (prop = qdev_get_bus_info(dev)->props; prop && prop->name; prop++) {
- qdev_property_add_legacy(dev, prop, NULL);
- qdev_property_add_static(dev, prop, NULL);
- }
}
/* Create a new device. This only initializes the device state structure
@@ -629,6 +610,7 @@ void qdev_property_add_static(DeviceState *dev, Property *prop,
static void device_initfn(Object *obj)
{
DeviceState *dev = DEVICE(obj);
+ ObjectClass *class;
Property *prop;
if (qdev_hotplug) {
@@ -639,10 +621,14 @@ static void device_initfn(Object *obj)
dev->instance_id_alias = -1;
dev->state = DEV_STATE_CREATED;
- for (prop = qdev_get_props(dev); prop && prop->name; prop++) {
- qdev_property_add_legacy(dev, prop, NULL);
- qdev_property_add_static(dev, prop, NULL);
- }
+ class = object_get_class(OBJECT(dev));
+ do {
+ for (prop = DEVICE_CLASS(class)->props; prop && prop->name; prop++) {
+ qdev_property_add_legacy(dev, prop, NULL);
+ qdev_property_add_static(dev, prop, NULL);
+ }
+ class = object_class_get_parent(class);
+ } while (class != object_class_by_name(TYPE_DEVICE));
qdev_prop_set_globals(dev);
}
diff --git a/hw/qdev.h b/hw/qdev.h
index 12de112..aea53c8 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -95,7 +95,6 @@ struct BusInfo {
bus_get_dev_path get_dev_path;
bus_get_fw_dev_path get_fw_dev_path;
qbus_resetfn *reset;
- Property *props;
};
struct BusState {
@@ -344,10 +343,6 @@ const VMStateDescription *qdev_get_vmsd(DeviceState *dev);
const char *qdev_fw_name(DeviceState *dev);
-BusInfo *qdev_get_bus_info(DeviceState *dev);
-
-Property *qdev_get_props(DeviceState *dev);
-
Object *qdev_get_machine(void);
/* FIXME: make this a link<> */
diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
index 0352c59..10f9c63 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi-bus.c
@@ -24,7 +24,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 = scsi_props,
};
static int next_scsi_bus;
@@ -1575,6 +1574,7 @@ static void scsi_device_class_init(ObjectClass *klass, void *data)
k->init = scsi_qdev_init;
k->unplug = qdev_simple_unplug_cb;
k->exit = scsi_qdev_exit;
+ k->props = scsi_props;
}
static TypeInfo scsi_device_type_info = {
diff --git a/hw/spapr_vio.c b/hw/spapr_vio.c
index 941a013..897c057 100644
--- a/hw/spapr_vio.c
+++ b/hw/spapr_vio.c
@@ -57,7 +57,6 @@ static Property spapr_vio_props[] = {
static struct BusInfo spapr_vio_bus_info = {
.name = "spapr-vio",
.size = sizeof(VIOsPAPRBus),
- .props = spapr_vio_props,
};
VIOsPAPRDevice *spapr_vio_find_by_reg(VIOsPAPRBus *bus, uint32_t reg)
@@ -769,6 +768,7 @@ static void vio_spapr_device_class_init(ObjectClass *klass, void *data)
DeviceClass *k = DEVICE_CLASS(klass);
k->init = spapr_vio_busdev_init;
k->bus_info = &spapr_vio_bus_info;
+ k->props = spapr_vio_props;
}
static TypeInfo spapr_vio_type_info = {
diff --git a/hw/usb/bus.c b/hw/usb/bus.c
index 0271bc0..12d1be0 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -22,7 +22,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 = usb_props,
};
static int next_usb_bus = 0;
@@ -568,6 +567,7 @@ static void usb_device_class_init(ObjectClass *klass, void *data)
k->init = usb_qdev_init;
k->unplug = qdev_simple_unplug_cb;
k->exit = usb_qdev_exit;
+ k->props = usb_props;
}
static TypeInfo usb_device_type_info = {
diff --git a/hw/usb/dev-smartcard-reader.c b/hw/usb/dev-smartcard-reader.c
index 4a9cc16..a38a948 100644
--- a/hw/usb/dev-smartcard-reader.c
+++ b/hw/usb/dev-smartcard-reader.c
@@ -1063,7 +1063,6 @@ static Property ccid_props[] = {
static struct BusInfo ccid_bus_info = {
.name = "ccid-bus",
.size = sizeof(CCIDBus),
- .props = ccid_props,
};
void ccid_card_send_apdu_to_guest(CCIDCardState *card,
@@ -1346,6 +1345,7 @@ static void ccid_card_class_init(ObjectClass *klass, void *data)
k->bus_info = &ccid_bus_info;
k->init = ccid_card_init;
k->exit = ccid_card_exit;
+ k->props = ccid_props;
}
static TypeInfo ccid_card_type_info = {
diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
index 703c08d..6d49ad6 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/virtio-serial-bus.c
@@ -687,7 +687,6 @@ static struct BusInfo virtser_bus_info = {
.name = "virtio-serial-bus",
.size = sizeof(VirtIOSerialBus),
.print_dev = virtser_bus_dev_print,
- .props = virtser_props,
};
static void virtser_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent)
@@ -940,6 +939,7 @@ static void virtio_serial_port_class_init(ObjectClass *klass, void *data)
k->bus_info = &virtser_bus_info;
k->exit = virtser_port_qdev_exit;
k->unplug = qdev_simple_unplug_cb;
+ k->props = virtser_props;
}
static TypeInfo virtio_serial_port_type_info = {
--
1.7.9.3
next prev parent reply other threads:[~2012-04-03 11:17 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-03 11:15 [Qemu-devel] [PATCH 00/25] qdev properties final installment: push, push! Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 01/25] qom: add object_class_get_parent Paolo Bonzini
2012-04-03 20:50 ` Anthony Liguori
2012-04-03 11:15 ` [Qemu-devel] [PATCH 02/25] qom: add object_child_foreach Paolo Bonzini
2012-04-03 20:51 ` Anthony Liguori
2012-04-03 11:15 ` [Qemu-devel] [PATCH 03/25] qom: add class_base_init Paolo Bonzini
2012-04-03 20:51 ` Anthony Liguori
2012-04-03 11:15 ` [Qemu-devel] [PATCH 04/25] qom: make Object a type Paolo Bonzini
2012-04-03 12:30 ` Andreas Färber
2012-04-03 13:06 ` Paolo Bonzini
2012-04-03 20:52 ` Anthony Liguori
2012-04-03 11:15 ` [Qemu-devel] [PATCH 05/25] qom: push type up to Object Paolo Bonzini
2012-04-03 12:33 ` Andreas Färber
2012-04-03 20:55 ` Anthony Liguori
2012-04-03 11:15 ` [Qemu-devel] [PATCH 06/25] qdev: fix -device foo,? Paolo Bonzini
2012-04-03 20:59 ` Anthony Liguori
2012-04-03 11:15 ` [Qemu-devel] [PATCH 07/25] qdev: use object_property_print in info qtree Paolo Bonzini
2012-04-03 12:28 ` Jan Kiszka
2012-04-03 13:05 ` Paolo Bonzini
2012-05-11 14:10 ` Andreas Färber
2012-05-16 7:40 ` Paolo Bonzini
2012-05-16 7:43 ` Paolo Bonzini
2012-04-03 21:06 ` Anthony Liguori
2012-05-10 20:58 ` Jan Kiszka
2012-05-11 11:28 ` Paolo Bonzini
2012-05-11 11:38 ` Andreas Färber
2012-04-03 11:15 ` [Qemu-devel] [PATCH 08/25] qdev: remove qdev_prop_set_defaults Paolo Bonzini
2012-04-03 21:09 ` Anthony Liguori
2012-04-03 21:43 ` Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 09/25] qdev: move bus properties to a separate global Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 10/25] qdev: do not propagate properties to subclasses Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 11/25] qdev: pick global properties from superclasses Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 12/25] qdev: factor setting of global properties Paolo Bonzini
2012-04-03 11:15 ` Paolo Bonzini [this message]
2012-04-03 11:15 ` [Qemu-devel] [PATCH 14/25] qapi: add Visitor interfaces for uint*_t and int*_t Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 15/25] qdev: use int32_t container for devfn property Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 16/25] qdev: switch property accessors to fixed-width visitor interfaces Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 17/25] qdev: remove PropertyInfo range checking Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 18/25] qdev: remove qdev_prop_exists Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 19/25] qom: push state up to Object Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 20/25] qdev: generalize properties to Objects Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 21/25] qdev: move bulk of qdev-properties.c to qom/object.c Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 22/25] qom: push static properties to Object Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 23/25] qom: add realized property Paolo Bonzini
2012-04-03 12:11 ` Andreas Färber
2012-04-03 13:03 ` Paolo Bonzini
2012-04-05 12:04 ` Andreas Färber
2012-04-05 12:36 ` Paolo Bonzini
2012-04-05 13:31 ` Andreas Färber
2012-04-05 14:16 ` Paolo Bonzini
2012-04-05 15:13 ` Anthony Liguori
2012-05-09 20:01 ` Igor Mammedov
2012-05-10 7:05 ` Paolo Bonzini
2012-05-10 10:01 ` Andreas Färber
2012-05-10 12:19 ` Anthony Liguori
2012-04-03 11:15 ` [Qemu-devel] [PATCH 24/25] qdev: implement qdev_init on top of realize Paolo Bonzini
2012-04-03 11:15 ` [Qemu-devel] [PATCH 25/25] qdev: split part of device_finalize to device_unrealize Paolo Bonzini
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=1333451753-3550-14-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=afaerber@suse.de \
--cc=aliguori@us.ibm.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).