[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 16/16] qdev: initialize properties via QOM
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PATCH 16/16] qdev: initialize properties via QOM |
Date: |
Thu, 2 Feb 2012 17:45:42 +0100 |
Similarly, use the object properties also to set the default
values of the qdev properties. This requires reordering
registration and initialization.
Signed-off-by: Paolo Bonzini <address@hidden>
---
hw/qdev-properties.c | 20 +++++++-------------
hw/qdev.c | 4 ++--
hw/qdev.h | 11 +++++++----
3 files changed, 16 insertions(+), 19 deletions(-)
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index d7e5356..760240e 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -26,17 +26,6 @@ static void bit_prop_set(DeviceState *dev, Property *props,
bool val)
*p &= ~mask;
}
-static void qdev_prop_cpy(DeviceState *dev, Property *props, void *src)
-{
- if (props->info->type == PROP_TYPE_BIT) {
- bool *defval = src;
- bit_prop_set(dev, props, *defval);
- } else {
- char *dst = qdev_get_prop_ptr(dev, props);
- memcpy(dst, src, props->info->size);
- }
-}
-
/* Bit */
static int parse_bit(DeviceState *dev, Property *prop, const char *str)
{
@@ -1180,12 +1169,17 @@ void qdev_prop_set_ptr(DeviceState *dev, const char
*name, void *value)
void qdev_prop_set_defaults(DeviceState *dev, Property *props)
{
+ Object *obj = OBJECT(dev);
if (!props)
return;
while (props->name) {
- if (props->defval) {
- qdev_prop_cpy(dev, props, props->defval);
+ Error *errp = NULL;
+ if (props->qtype == QTYPE_QBOOL) {
+ object_property_set_bool(obj, props->defval, props->name, &errp);
+ } else if (props->qtype == QTYPE_QINT) {
+ object_property_set_int(obj, props->defval, props->name, &errp);
}
+ assert(!errp);
props++;
}
}
diff --git a/hw/qdev.c b/hw/qdev.c
index f719f14..dc1d1a1 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -86,11 +86,11 @@ void qdev_set_parent_bus(DeviceState *dev, BusState *bus)
dev->parent_bus = bus;
QTAILQ_INSERT_HEAD(&bus->children, dev, sibling);
- qdev_prop_set_defaults(dev, dev->parent_bus->info->props);
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);
}
+ qdev_prop_set_defaults(dev, dev->parent_bus->info->props);
}
/* Create a new device. This only initializes the device state structure
@@ -612,13 +612,13 @@ static void device_initfn(Object *obj)
dev->instance_id_alias = -1;
dev->state = DEV_STATE_CREATED;
- qdev_prop_set_defaults(dev, qdev_get_props(dev));
for (prop = qdev_get_props(dev); prop && prop->name; prop++) {
qdev_property_add_legacy(dev, prop, NULL);
qdev_property_add_static(dev, prop, NULL);
}
object_property_add_str(OBJECT(dev), "type", qdev_get_type, NULL, NULL);
+ qdev_prop_set_defaults(dev, qdev_get_props(dev));
}
/* Unlink device from bus and free the structure. */
diff --git a/hw/qdev.h b/hw/qdev.h
index c0e5600..60c226b 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -112,8 +112,9 @@ struct Property {
const char *name;
PropertyInfo *info;
int offset;
- int bitnr;
- void *defval;
+ uint8_t bitnr;
+ uint8_t qtype;
+ int64_t defval;
};
enum PropertyType {
@@ -252,7 +253,8 @@ extern PropertyInfo qdev_prop_pci_devfn;
.info = &(_prop), \
.offset = offsetof(_state, _field) \
+ type_check(_type,typeof_field(_state, _field)), \
- .defval = (_type[]) { _defval }, \
+ .qtype = QTYPE_QINT, \
+ .defval = (_type)_defval, \
}
#define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) { \
.name = (_name), \
@@ -260,7 +262,8 @@ extern PropertyInfo qdev_prop_pci_devfn;
.bitnr = (_bit), \
.offset = offsetof(_state, _field) \
+ type_check(uint32_t,typeof_field(_state, _field)), \
- .defval = (bool[]) { (_defval) }, \
+ .qtype = QTYPE_QBOOL, \
+ .defval = (bool)_defval, \
}
#define DEFINE_PROP_UINT8(_n, _s, _f, _d) \
--
1.7.7.6
- Re: [Qemu-devel] [PATCH 10/16] qdev: make the non-legacy pci address property accept an integer, (continued)
- Re: [Qemu-devel] [PATCH 10/16] qdev: make the non-legacy pci address property accept an integer, Paolo Bonzini, 2012/02/03
- Re: [Qemu-devel] [PATCH 10/16] qdev: make the non-legacy pci address property accept an integer, Paolo Bonzini, 2012/02/03
- Re: [Qemu-devel] [PATCH 10/16] qdev: make the non-legacy pci address property accept an integer, Anthony Liguori, 2012/02/03
- Re: [Qemu-devel] [PATCH 10/16] qdev: make the non-legacy pci address property accept an integer, Paolo Bonzini, 2012/02/04
- Re: [Qemu-devel] [PATCH 10/16] qdev: make the non-legacy pci address property accept an integer, Paolo Bonzini, 2012/02/04
[Qemu-devel] [PATCH 12/16] qdev: let QOM free properties, Paolo Bonzini, 2012/02/02
[Qemu-devel] [PATCH 08/16] qdev: remove parse method for string properties, Paolo Bonzini, 2012/02/02
[Qemu-devel] [PATCH 13/16] qdev: fix off-by-one, Paolo Bonzini, 2012/02/02
[Qemu-devel] [PATCH 11/16] qdev: remove parse/print methods for pointer properties, Paolo Bonzini, 2012/02/02
[Qemu-devel] [PATCH 14/16] qdev: access properties via QOM, Paolo Bonzini, 2012/02/02
[Qemu-devel] [PATCH 16/16] qdev: initialize properties via QOM,
Paolo Bonzini <=
[Qemu-devel] [PATCH 15/16] qdev: inline qdev_prop_set into qdev_prop_set_ptr, Paolo Bonzini, 2012/02/02