diff options
author | Paul Brook <paul@codesourcery.com> | 2009-06-05 15:52:04 +0100 |
---|---|---|
committer | Paul Brook <paul@codesourcery.com> | 2009-06-05 15:52:04 +0100 |
commit | 1431b6a17e6546569e09bcf8fb7773c925658d8f (patch) | |
tree | 83669665d82278a27b12d34d2fc1847944e784de /hw/qdev.c | |
parent | fd93a79999c728dd1f30bb2e726ce12bdf704e6d (diff) | |
download | qemu-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.c | 39 |
1 files changed, 32 insertions, 7 deletions
@@ -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); |