summaryrefslogtreecommitdiff
path: root/hw/qdev.c
diff options
context:
space:
mode:
authorPaul Brook <paul@codesourcery.com>2009-06-05 15:52:04 +0100
committerPaul Brook <paul@codesourcery.com>2009-06-05 15:52:04 +0100
commit1431b6a17e6546569e09bcf8fb7773c925658d8f (patch)
tree83669665d82278a27b12d34d2fc1847944e784de /hw/qdev.c
parentfd93a79999c728dd1f30bb2e726ce12bdf704e6d (diff)
downloadqemu-1431b6a17e6546569e09bcf8fb7773c925658d8f.tar.gz
qemu-1431b6a17e6546569e09bcf8fb7773c925658d8f.tar.bz2
qemu-1431b6a17e6546569e09bcf8fb7773c925658d8f.zip
Record device property types
Record device property types, and provide a list of properties at device registration time. Add a "device" property type that holds a reference to annother device. Signed-off-by: Paul Brook <paul@codesourcery.com>
Diffstat (limited to 'hw/qdev.c')
-rw-r--r--hw/qdev.c39
1 files changed, 32 insertions, 7 deletions
diff --git a/hw/qdev.c b/hw/qdev.c
index cedb7728a9..a7025da9a7 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -32,6 +32,7 @@
struct DeviceProperty {
const char *name;
+ DevicePropType type;
union {
uint64_t i;
void *ptr;
@@ -119,13 +120,15 @@ void qdev_free(DeviceState *dev)
free(dev);
}
-static DeviceProperty *create_prop(DeviceState *dev, const char *name)
+static DeviceProperty *create_prop(DeviceState *dev, const char *name,
+ DevicePropType type)
{
DeviceProperty *prop;
/* TODO: Check for duplicate properties. */
prop = qemu_mallocz(sizeof(*prop));
prop->name = qemu_strdup(name);
+ prop->type = type;
prop->next = dev->props;
dev->props = prop;
@@ -136,15 +139,23 @@ void qdev_set_prop_int(DeviceState *dev, const char *name, uint64_t value)
{
DeviceProperty *prop;
- prop = create_prop(dev, name);
+ prop = create_prop(dev, name, PROP_TYPE_INT);
prop->value.i = value;
}
+void qdev_set_prop_dev(DeviceState *dev, const char *name, DeviceState *value)
+{
+ DeviceProperty *prop;
+
+ prop = create_prop(dev, name, PROP_TYPE_DEV);
+ prop->value.ptr = value;
+}
+
void qdev_set_prop_ptr(DeviceState *dev, const char *name, void *value)
{
DeviceProperty *prop;
- prop = create_prop(dev, name);
+ prop = create_prop(dev, name, PROP_TYPE_INT);
prop->value.ptr = value;
}
@@ -173,12 +184,14 @@ BusState *qdev_get_parent_bus(DeviceState *dev)
return dev->parent_bus;
}
-static DeviceProperty *find_prop(DeviceState *dev, const char *name)
+static DeviceProperty *find_prop(DeviceState *dev, const char *name,
+ DevicePropType type)
{
DeviceProperty *prop;
for (prop = dev->props; prop; prop = prop->next) {
if (strcmp(prop->name, name) == 0) {
+ assert (prop->type == type);
return prop;
}
}
@@ -189,9 +202,10 @@ uint64_t qdev_get_prop_int(DeviceState *dev, const char *name, uint64_t def)
{
DeviceProperty *prop;
- prop = find_prop(dev, name);
- if (!prop)
+ prop = find_prop(dev, name, PROP_TYPE_INT);
+ if (!prop) {
return def;
+ }
return prop->value.i;
}
@@ -200,11 +214,22 @@ void *qdev_get_prop_ptr(DeviceState *dev, const char *name)
{
DeviceProperty *prop;
- prop = find_prop(dev, name);
+ prop = find_prop(dev, name, PROP_TYPE_PTR);
assert(prop);
return prop->value.ptr;
}
+DeviceState *qdev_get_prop_dev(DeviceState *dev, const char *name)
+{
+ DeviceProperty *prop;
+
+ prop = find_prop(dev, name, PROP_TYPE_DEV);
+ if (!prop) {
+ return NULL;
+ }
+ return prop->value.ptr;
+}
+
void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n)
{
assert(dev->num_gpio_in == 0);