From 1431b6a17e6546569e09bcf8fb7773c925658d8f Mon Sep 17 00:00:00 2001 From: Paul Brook Date: Fri, 5 Jun 2009 15:52:04 +0100 Subject: 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 --- hw/qdev.c | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) (limited to 'hw/qdev.c') 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); -- cgit v1.2.3