* [Qemu-devel] [PATCH v3 001/197] qom: add a reference count to qdev objects
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
@ 2011-12-12 20:17 ` Anthony Liguori
2011-12-12 20:28 ` Anthony Liguori
2011-12-12 20:17 ` [Qemu-devel] [PATCH v3 002/197] qom: add new dynamic property infrastructure based on Visitors (v2) Anthony Liguori
` (65 subsequent siblings)
66 siblings, 1 reply; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:17 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
To ensure that a device isn't removed from the graph until all of its links are
broken.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
hw/qdev.c | 16 ++++++++++++++++
hw/qdev.h | 26 ++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 0 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index 106407f..fdc9843 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -323,6 +323,11 @@ int qdev_unplug(DeviceState *dev)
}
assert(dev->info->unplug != NULL);
+ if (dev->ref != 0) {
+ qerror_report(QERR_DEVICE_IN_USE, dev->id?:"");
+ return -1;
+ }
+
qdev_hot_removed = true;
return dev->info->unplug(dev);
@@ -962,3 +967,14 @@ char* qdev_get_fw_dev_path(DeviceState *dev)
return strdup(path);
}
+
+void qdev_ref(DeviceState *dev)
+{
+ dev->ref++;
+}
+
+void qdev_unref(DeviceState *dev)
+{
+ g_assert(dev->ref > 0);
+ dev->ref--;
+}
diff --git a/hw/qdev.h b/hw/qdev.h
index 36a4198..2397b4e 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -45,6 +45,12 @@ struct DeviceState {
QTAILQ_ENTRY(DeviceState) sibling;
int instance_id_alias;
int alias_required_for_version;
+
+ /**
+ * This tracks the number of references between devices. See @qdev_ref for
+ * more information.
+ */
+ uint32_t ref;
};
typedef void (*bus_dev_printfn)(Monitor *mon, DeviceState *dev, int indent);
@@ -329,4 +335,24 @@ char *qdev_get_fw_dev_path(DeviceState *dev);
/* This is a nasty hack to allow passing a NULL bus to qdev_create. */
extern struct BusInfo system_bus_info;
+/**
+ * @qdev_ref
+ *
+ * Increase the reference count of a device. A device cannot be freed as long
+ * as its reference count is greater than zero.
+ *
+ * @dev - the device
+ */
+void qdev_ref(DeviceState *dev);
+
+/**
+ * @qdef_unref
+ *
+ * Decrease the reference count of a device. A device cannot be freed as long
+ * as its reference count is greater than zero.
+ *
+ * @dev - the device
+ */
+void qdev_unref(DeviceState *dev);
+
#endif
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* Re: [Qemu-devel] [PATCH v3 001/197] qom: add a reference count to qdev objects
2011-12-12 20:17 ` [Qemu-devel] [PATCH v3 001/197] qom: add a reference count to qdev objects Anthony Liguori
@ 2011-12-12 20:28 ` Anthony Liguori
0 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:28 UTC (permalink / raw)
To: Anthony Liguori
Cc: Kevin Wolf, Peter Maydell, Stefan Hajnoczi, Jan Kiszka,
qemu-devel, Markus Armbruster, Luiz Capitulino
On 12/12/2011 02:17 PM, Anthony Liguori wrote:
> To ensure that a device isn't removed from the graph until all of its links are
> broken.
>
> Signed-off-by: Anthony Liguori<aliguori@us.ibm.com>
Sorry, my mail script went awry :-(
Ignore this series.
Regards,
Anthony Liguori
> ---
> hw/qdev.c | 16 ++++++++++++++++
> hw/qdev.h | 26 ++++++++++++++++++++++++++
> 2 files changed, 42 insertions(+), 0 deletions(-)
>
> diff --git a/hw/qdev.c b/hw/qdev.c
> index 106407f..fdc9843 100644
> --- a/hw/qdev.c
> +++ b/hw/qdev.c
> @@ -323,6 +323,11 @@ int qdev_unplug(DeviceState *dev)
> }
> assert(dev->info->unplug != NULL);
>
> + if (dev->ref != 0) {
> + qerror_report(QERR_DEVICE_IN_USE, dev->id?:"");
> + return -1;
> + }
> +
> qdev_hot_removed = true;
>
> return dev->info->unplug(dev);
> @@ -962,3 +967,14 @@ char* qdev_get_fw_dev_path(DeviceState *dev)
>
> return strdup(path);
> }
> +
> +void qdev_ref(DeviceState *dev)
> +{
> + dev->ref++;
> +}
> +
> +void qdev_unref(DeviceState *dev)
> +{
> + g_assert(dev->ref> 0);
> + dev->ref--;
> +}
> diff --git a/hw/qdev.h b/hw/qdev.h
> index 36a4198..2397b4e 100644
> --- a/hw/qdev.h
> +++ b/hw/qdev.h
> @@ -45,6 +45,12 @@ struct DeviceState {
> QTAILQ_ENTRY(DeviceState) sibling;
> int instance_id_alias;
> int alias_required_for_version;
> +
> + /**
> + * This tracks the number of references between devices. See @qdev_ref for
> + * more information.
> + */
> + uint32_t ref;
> };
>
> typedef void (*bus_dev_printfn)(Monitor *mon, DeviceState *dev, int indent);
> @@ -329,4 +335,24 @@ char *qdev_get_fw_dev_path(DeviceState *dev);
> /* This is a nasty hack to allow passing a NULL bus to qdev_create. */
> extern struct BusInfo system_bus_info;
>
> +/**
> + * @qdev_ref
> + *
> + * Increase the reference count of a device. A device cannot be freed as long
> + * as its reference count is greater than zero.
> + *
> + * @dev - the device
> + */
> +void qdev_ref(DeviceState *dev);
> +
> +/**
> + * @qdef_unref
> + *
> + * Decrease the reference count of a device. A device cannot be freed as long
> + * as its reference count is greater than zero.
> + *
> + * @dev - the device
> + */
> +void qdev_unref(DeviceState *dev);
> +
> #endif
^ permalink raw reply [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 002/197] qom: add new dynamic property infrastructure based on Visitors (v2)
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
2011-12-12 20:17 ` [Qemu-devel] [PATCH v3 001/197] qom: add a reference count to qdev objects Anthony Liguori
@ 2011-12-12 20:17 ` Anthony Liguori
2011-12-12 20:17 ` [Qemu-devel] [PATCH v3 003/197] qom: register legacy properties as new style properties (v2) Anthony Liguori
` (64 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:17 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
qdev properties are settable only during construction and static to classes.
This isn't flexible enough for QOM.
This patch introduces a property interface for qdev that provides dynamic
properties that are tied to objects, instead of classes. These properties are
Visitor based instead of string based too.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
v1 -> v2
- Etter -> Accessor (Stefan)
- spelling mistakes (Stefan)
- switch to qemu-queue (Kevin/Gerd)
---
hw/qdev.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++
hw/qdev.h | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
qerror.c | 4 ++
qerror.h | 3 ++
4 files changed, 224 insertions(+), 0 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index fdc9843..94f14c1 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -98,6 +98,7 @@ static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info)
qdev_hot_added = true;
}
dev->instance_id_alias = -1;
+ QTAILQ_INIT(&dev->properties);
dev->state = DEV_STATE_CREATED;
return dev;
}
@@ -395,12 +396,31 @@ void qdev_init_nofail(DeviceState *dev)
}
}
+static void qdev_property_del_all(DeviceState *dev)
+{
+ while (!QTAILQ_EMPTY(&dev->properties)) {
+ DeviceProperty *prop = QTAILQ_FIRST(&dev->properties);
+
+ QTAILQ_REMOVE(&dev->properties, prop, node);
+
+ if (prop->release) {
+ prop->release(dev, prop->name, prop->opaque);
+ }
+
+ g_free(prop->name);
+ g_free(prop->type);
+ g_free(prop);
+ }
+}
+
/* Unlink device from bus and free the structure. */
void qdev_free(DeviceState *dev)
{
BusState *bus;
Property *prop;
+ qdev_property_del_all(dev);
+
if (dev->state == DEV_STATE_INITIALIZED) {
while (dev->num_child_bus) {
bus = QLIST_FIRST(&dev->child_bus);
@@ -978,3 +998,80 @@ void qdev_unref(DeviceState *dev)
g_assert(dev->ref > 0);
dev->ref--;
}
+
+void qdev_property_add(DeviceState *dev, const char *name, const char *type,
+ DevicePropertyAccessor *get, DevicePropertyAccessor *set,
+ DevicePropertyRelease *release,
+ void *opaque, Error **errp)
+{
+ DeviceProperty *prop = g_malloc0(sizeof(*prop));
+
+ prop->name = g_strdup(name);
+ prop->type = g_strdup(type);
+
+ prop->get = get;
+ prop->set = set;
+ prop->release = release;
+ prop->opaque = opaque;
+
+ QTAILQ_INSERT_TAIL(&dev->properties, prop, node);
+}
+
+static DeviceProperty *qdev_property_find(DeviceState *dev, const char *name)
+{
+ DeviceProperty *prop;
+
+ QTAILQ_FOREACH(prop, &dev->properties, node) {
+ if (strcmp(prop->name, name) == 0) {
+ return prop;
+ }
+ }
+
+ return NULL;
+}
+
+void qdev_property_get(DeviceState *dev, Visitor *v, const char *name,
+ Error **errp)
+{
+ DeviceProperty *prop = qdev_property_find(dev, name);
+
+ if (prop == NULL) {
+ error_set(errp, QERR_PROPERTY_NOT_FOUND, dev->id?:"", name);
+ return;
+ }
+
+ if (!prop->get) {
+ error_set(errp, QERR_PERMISSION_DENIED);
+ } else {
+ prop->get(dev, v, prop->opaque, name, errp);
+ }
+}
+
+void qdev_property_set(DeviceState *dev, Visitor *v, const char *name,
+ Error **errp)
+{
+ DeviceProperty *prop = qdev_property_find(dev, name);
+
+ if (prop == NULL) {
+ error_set(errp, QERR_PROPERTY_NOT_FOUND, dev->id?:"", name);
+ return;
+ }
+
+ if (!prop->set) {
+ error_set(errp, QERR_PERMISSION_DENIED);
+ } else {
+ prop->set(dev, prop->opaque, v, name, errp);
+ }
+}
+
+const char *qdev_property_get_type(DeviceState *dev, const char *name, Error **errp)
+{
+ DeviceProperty *prop = qdev_property_find(dev, name);
+
+ if (prop == NULL) {
+ error_set(errp, QERR_PROPERTY_NOT_FOUND, dev->id?:"", name);
+ return NULL;
+ }
+
+ return prop->type;
+}
diff --git a/hw/qdev.h b/hw/qdev.h
index 2397b4e..2df3bb7 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -5,6 +5,7 @@
#include "qemu-queue.h"
#include "qemu-char.h"
#include "qemu-option.h"
+#include "qapi/qapi-visit-core.h"
typedef struct Property Property;
@@ -27,6 +28,44 @@ enum {
DEV_NVECTORS_UNSPECIFIED = -1,
};
+/**
+ * @DevicePropertyAccessor - called when trying to get/set a property
+ *
+ * @dev the device that owns the property
+ * @v the visitor that contains the property data
+ * @opaque the device property opaque
+ * @name the name of the property
+ * @errp a pointer to an Error that is filled if getting/setting fails.
+ */
+typedef void (DevicePropertyAccessor)(DeviceState *dev,
+ Visitor *v,
+ void *opaque,
+ const char *name,
+ Error **errp);
+
+/**
+ * @DevicePropertyRelease - called when a property is removed from a device
+ *
+ * @dev the device that owns the property
+ * @name the name of the property
+ * @opaque the opaque registered with the property
+ */
+typedef void (DevicePropertyRelease)(DeviceState *dev,
+ const char *name,
+ void *opaque);
+
+typedef struct DeviceProperty
+{
+ gchar *name;
+ gchar *type;
+ DevicePropertyAccessor *get;
+ DevicePropertyAccessor *set;
+ DevicePropertyRelease *release;
+ void *opaque;
+
+ QTAILQ_ENTRY(DeviceProperty) node;
+} DeviceProperty;
+
/* This structure should not be accessed directly. We declare it here
so that it can be embedded in individual device state structures. */
struct DeviceState {
@@ -51,6 +90,8 @@ struct DeviceState {
* more information.
*/
uint32_t ref;
+
+ QTAILQ_HEAD(, DeviceProperty) properties;
};
typedef void (*bus_dev_printfn)(Monitor *mon, DeviceState *dev, int indent);
@@ -355,4 +396,83 @@ void qdev_ref(DeviceState *dev);
*/
void qdev_unref(DeviceState *dev);
+/**
+ * @qdev_property_add - add a new property to a device
+ *
+ * @dev - the device to add a property to
+ *
+ * @name - the name of the property. This can contain any character except for
+ * a forward slash. In general, you should use hyphens '-' instead of
+ * underscores '_' when naming properties.
+ *
+ * @type - the type name of the property. This namespace is pretty loosely
+ * defined. Sub namespaces are constructed by using a prefix and then
+ * to angle brackets. For instance, the type 'virtio-net-pci' in the
+ * 'link' namespace would be 'link<virtio-net-pci>'.
+ *
+ * @get - the getter to be called to read a property. If this is NULL, then
+ * the property cannot be read.
+ *
+ * @set - the setter to be called to write a property. If this is NULL,
+ * then the property cannot be written.
+ *
+ * @release - called when the property is removed from the device. This is
+ * meant to allow a property to free its opaque upon device
+ * destruction. This may be NULL.
+ *
+ * @opaque - an opaque pointer to pass to the callbacks for the property
+ *
+ * @errp - returns an error if this function fails
+ */
+void qdev_property_add(DeviceState *dev, const char *name, const char *type,
+ DevicePropertyAccessor *get, DevicePropertyAccessor *set,
+ DevicePropertyRelease *release,
+ void *opaque, Error **errp);
+
+/**
+ * @qdev_property_get - reads a property from a device
+ *
+ * @dev - the device
+ *
+ * @v - the visitor that will receive the property value. This should be an
+ * Output visitor and the data will be written with @name as the name.
+ *
+ * @name - the name of the property
+ *
+ * @errp - returns an error if this function fails
+ */
+void qdev_property_get(DeviceState *dev, Visitor *v, const char *name,
+ Error **errp);
+
+/**
+ * @qdev_property_set - writes a property to a device
+ *
+ * @dev - the device
+ *
+ * @v - the visitor that will be used to write the property value. This should
+ * be an Input visitor and the data will be first read with @name as the
+ * name and then written as the property value.
+ *
+ * @name - the name of the property
+ *
+ * @errp - returns an error if this function fails
+ */
+void qdev_property_set(DeviceState *dev, Visitor *v, const char *name,
+ Error **errp);
+
+/**
+ * @qdev_property_get_type - returns the type of a property
+ *
+ * @dev - the device
+ *
+ * @name - the name of the property
+ *
+ * @errp - returns an error if this function fails
+ *
+ * Returns:
+ * The type name of the property.
+ */
+const char *qdev_property_get_type(DeviceState *dev, const char *name,
+ Error **errp);
+
#endif
diff --git a/qerror.c b/qerror.c
index fdf62b9..dd0ee76 100644
--- a/qerror.c
+++ b/qerror.c
@@ -178,6 +178,10 @@ static const QErrorStringTable qerror_table[] = {
.desc = "Could not open '%(filename)'",
},
{
+ .error_fmt = QERR_PERMISSION_DENIED,
+ .desc = "Insufficient permission to perform this operation",
+ },
+ {
.error_fmt = QERR_PROPERTY_NOT_FOUND,
.desc = "Property '%(device).%(property)' not found",
},
diff --git a/qerror.h b/qerror.h
index 2d3d43b..2b1d743 100644
--- a/qerror.h
+++ b/qerror.h
@@ -150,6 +150,9 @@ QError *qobject_to_qerror(const QObject *obj);
#define QERR_OPEN_FILE_FAILED \
"{ 'class': 'OpenFileFailed', 'data': { 'filename': %s } }"
+#define QERR_PERMISSION_DENIED \
+ "{ 'class': 'PermissionDenied', 'data': {} }"
+
#define QERR_PROPERTY_NOT_FOUND \
"{ 'class': 'PropertyNotFound', 'data': { 'device': %s, 'property': %s } }"
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 003/197] qom: register legacy properties as new style properties (v2)
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
2011-12-12 20:17 ` [Qemu-devel] [PATCH v3 001/197] qom: add a reference count to qdev objects Anthony Liguori
2011-12-12 20:17 ` [Qemu-devel] [PATCH v3 002/197] qom: add new dynamic property infrastructure based on Visitors (v2) Anthony Liguori
@ 2011-12-12 20:17 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 004/197] qom: introduce root device Anthony Liguori
` (63 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:17 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
Expose all legacy properties through the new QOM property mechanism. The qdev
property types are exposed through the 'legacy<>' namespace. They are always
visited as strings since they do their own string parsing.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
v1 -> v2
- add bus properties (Gerd)
---
hw/qdev.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
hw/qdev.h | 7 +++++
2 files changed, 93 insertions(+), 0 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index 94f14c1..6f77af9 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -83,6 +83,7 @@ static DeviceInfo *qdev_find_info(BusInfo *bus_info, const char *name)
static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info)
{
DeviceState *dev;
+ Property *prop;
assert(bus->info == info->bus_info);
dev = g_malloc0(info->size);
@@ -100,6 +101,15 @@ static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info)
dev->instance_id_alias = -1;
QTAILQ_INIT(&dev->properties);
dev->state = DEV_STATE_CREATED;
+
+ for (prop = dev->info->props; prop && prop->name; prop++) {
+ qdev_property_add_legacy(dev, prop, NULL);
+ }
+
+ for (prop = dev->info->bus_info->props; prop && prop->name; prop++) {
+ qdev_property_add_legacy(dev, prop, NULL);
+ }
+
return dev;
}
@@ -1075,3 +1085,79 @@ const char *qdev_property_get_type(DeviceState *dev, const char *name, Error **e
return prop->type;
}
+
+/**
+ * Legacy property handling
+ */
+
+static void qdev_get_legacy_property(DeviceState *dev, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ Property *prop = opaque;
+
+ if (prop->info->print) {
+ char buffer[1024];
+ char *ptr = buffer;
+
+ prop->info->print(dev, prop, buffer, sizeof(buffer));
+ visit_type_str(v, &ptr, name, errp);
+ } else {
+ error_set(errp, QERR_PERMISSION_DENIED);
+ }
+}
+
+static void qdev_set_legacy_property(DeviceState *dev, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ Property *prop = opaque;
+
+ if (dev->state != DEV_STATE_CREATED) {
+ error_set(errp, QERR_PERMISSION_DENIED);
+ return;
+ }
+
+ if (prop->info->parse) {
+ Error *local_err = NULL;
+ char *ptr = NULL;
+
+ visit_type_str(v, &ptr, name, &local_err);
+ if (!local_err) {
+ int ret;
+ ret = prop->info->parse(dev, prop, ptr);
+ if (ret != 0) {
+ error_set(errp, QERR_INVALID_PARAMETER_VALUE,
+ name, prop->info->name);
+ }
+ g_free(ptr);
+ } else {
+ error_propagate(errp, local_err);
+ }
+ } else {
+ error_set(errp, QERR_PERMISSION_DENIED);
+ }
+}
+
+/**
+ * @qdev_add_legacy_property - adds a legacy property
+ *
+ * Do not use this is new code! Properties added through this interface will
+ * be given types in the "legacy<>" type namespace.
+ *
+ * Legacy properties are always processed as strings. The format of the string
+ * depends on the property type.
+ */
+void qdev_property_add_legacy(DeviceState *dev, Property *prop,
+ Error **errp)
+{
+ gchar *type;
+
+ type = g_strdup_printf("legacy<%s>", prop->info->name);
+
+ qdev_property_add(dev, prop->name, type,
+ qdev_get_legacy_property,
+ qdev_set_legacy_property,
+ NULL,
+ prop, errp);
+
+ g_free(type);
+}
diff --git a/hw/qdev.h b/hw/qdev.h
index 2df3bb7..3b629d4 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -475,4 +475,11 @@ void qdev_property_set(DeviceState *dev, Visitor *v, const char *name,
const char *qdev_property_get_type(DeviceState *dev, const char *name,
Error **errp);
+/**
+ * @qdev_property_add_legacy - add a legacy @Property to a device
+ *
+ * DO NOT USE THIS IN NEW CODE!
+ */
+void qdev_property_add_legacy(DeviceState *dev, Property *prop, Error **errp);
+
#endif
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 004/197] qom: introduce root device
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (2 preceding siblings ...)
2011-12-12 20:17 ` [Qemu-devel] [PATCH v3 003/197] qom: register legacy properties as new style properties (v2) Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 005/197] qdev: provide an interface to return canonical path from root (v2) Anthony Liguori
` (62 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
This is based on Jan's suggestion for how to do unique naming. The root device
is the root of composition. All devices are reachable via child<> links from
this device.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
Makefile.objs | 2 +-
hw/container.c | 20 ++++++++++++++++++++
hw/qdev.c | 12 ++++++++++++
hw/qdev.h | 8 ++++++++
4 files changed, 41 insertions(+), 1 deletions(-)
create mode 100644 hw/container.c
diff --git a/Makefile.objs b/Makefile.objs
index d7a6539..10e794c 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -279,7 +279,7 @@ hw-obj-$(CONFIG_LSI_SCSI_PCI) += lsi53c895a.o
hw-obj-$(CONFIG_ESP) += esp.o
hw-obj-y += dma-helpers.o sysbus.o isa-bus.o
-hw-obj-y += qdev-addr.o
+hw-obj-y += qdev-addr.o container.o
# VGA
hw-obj-$(CONFIG_VGA_PCI) += vga-pci.o
diff --git a/hw/container.c b/hw/container.c
new file mode 100644
index 0000000..9cbf399
--- /dev/null
+++ b/hw/container.c
@@ -0,0 +1,20 @@
+#include "sysbus.h"
+
+static int container_initfn(SysBusDevice *dev)
+{
+ return 0;
+}
+
+static SysBusDeviceInfo container_info = {
+ .init = container_initfn,
+ .qdev.name = "container",
+ .qdev.size = sizeof(SysBusDevice),
+ .qdev.no_user = 1,
+};
+
+static void container_init(void)
+{
+ sysbus_register_withprop(&container_info);
+}
+
+device_init(container_init);
diff --git a/hw/qdev.c b/hw/qdev.c
index 6f77af9..bb0b9f7 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -1161,3 +1161,15 @@ void qdev_property_add_legacy(DeviceState *dev, Property *prop,
g_free(type);
}
+
+DeviceState *qdev_get_root(void)
+{
+ static DeviceState *qdev_root;
+
+ if (!qdev_root) {
+ qdev_root = qdev_create(NULL, "container");
+ qdev_init_nofail(qdev_root);
+ }
+
+ return qdev_root;
+}
diff --git a/hw/qdev.h b/hw/qdev.h
index 3b629d4..52aadd2 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -482,4 +482,12 @@ const char *qdev_property_get_type(DeviceState *dev, const char *name,
*/
void qdev_property_add_legacy(DeviceState *dev, Property *prop, Error **errp);
+/**
+ * @qdev_get_root - returns the root device of the composition tree
+ *
+ * Returns:
+ * The root of the composition tree.
+ */
+DeviceState *qdev_get_root(void);
+
#endif
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 005/197] qdev: provide an interface to return canonical path from root (v2)
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (3 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 004/197] qom: introduce root device Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 006/197] qdev: provide a path resolution (v2) Anthony Liguori
` (61 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
The canonical path is the path in the composition tree from the root to the
device. This is effectively the name of the device.
This is an incredibly unefficient implementation that will be optimized in
a future patch.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
v1 -> v2
- change from gslist to qemu-queue (Kevin/Gerd)
---
hw/qdev.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
hw/qdev.h | 9 +++++++++
2 files changed, 57 insertions(+), 0 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index bb0b9f7..79849c9 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -1173,3 +1173,51 @@ DeviceState *qdev_get_root(void)
return qdev_root;
}
+
+static gchar *qdev_get_path_in(DeviceState *parent, DeviceState *dev)
+{
+ DeviceProperty *prop;
+
+ if (parent == dev) {
+ return g_strdup("");
+ }
+
+ QTAILQ_FOREACH(prop, &parent->properties, node) {
+ gchar *subpath;
+
+ if (!strstart(prop->type, "child<", NULL)) {
+ continue;
+ }
+
+ /* Check to see if the device is one of parent's children */
+ if (prop->opaque == dev) {
+ return g_strdup(prop->name);
+ }
+
+ /* Check to see if the device is a child of our child */
+ subpath = qdev_get_path_in(prop->opaque, dev);
+ if (subpath) {
+ gchar *path;
+
+ path = g_strdup_printf("%s/%s", prop->name, subpath);
+ g_free(subpath);
+
+ return path;
+ }
+ }
+
+ return NULL;
+}
+
+gchar *qdev_get_canonical_path(DeviceState *dev)
+{
+ gchar *path, *newpath;
+
+ path = qdev_get_path_in(qdev_get_root(), dev);
+ g_assert(path != NULL);
+
+ newpath = g_strdup_printf("/%s", path);
+ g_free(path);
+
+ return newpath;
+}
diff --git a/hw/qdev.h b/hw/qdev.h
index 52aadd2..0f00497 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -490,4 +490,13 @@ void qdev_property_add_legacy(DeviceState *dev, Property *prop, Error **errp);
*/
DeviceState *qdev_get_root(void);
+/**
+ * @qdev_get_canonical_path - returns the canonical path for a device. This
+ * is the path within the composition tree starting from the root.
+ *
+ * Returns:
+ * The canonical path in the composition tree.
+ */
+gchar *qdev_get_canonical_path(DeviceState *dev);
+
#endif
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 006/197] qdev: provide a path resolution (v2)
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (4 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 005/197] qdev: provide an interface to return canonical path from root (v2) Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 007/197] qom: add child properties (composition) (v2) Anthony Liguori
` (60 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
There are two types of supported paths--absolute paths and partial paths.
Absolute paths are derived from the root device and can follow child<> or
link<> properties. Since they can follow link<> properties, they can be
arbitrarily long. Absolute paths look like absolute filenames and are prefixed
with a leading slash.
Partial paths are look like relative filenames. They do not begin with a
prefix. The matching rules for partial paths are subtle but designed to make
specifying devices easy. At each level of the composition tree, the partial
path is matched as an absolute path. The first match is not returned. At
least two matches are searched for. A successful result is only returned if
only one match is founded. If more than one match is found, a flag is returned
to indicate that the match was ambiguous.
At the end of the day, partial path support means that if you create a device
called 'ide0', you can just say 'ide0' as the path name and it will Just Work.
If we internally create a device called 'i440fx', you can just say 'i440fx' and
it will Just Work and long as you don't do anything silly.
A management tool should probably always use absolute paths since then they
don't have to deal with the possibility of ambiguity.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
v1 -> v2
- fix comments (Stefan)
- always initialize ambiguous to false (Stefan)
- change from gslist to qemu-queue (Kevin/Gerd)
---
hw/qdev.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
hw/qdev.h | 28 ++++++++++++++++
2 files changed, 131 insertions(+), 0 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index 79849c9..2519f00 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -1221,3 +1221,106 @@ gchar *qdev_get_canonical_path(DeviceState *dev)
return newpath;
}
+
+static DeviceState *qdev_resolve_abs_path(DeviceState *parent,
+ gchar **parts,
+ int index)
+{
+ DeviceProperty *prop;
+ DeviceState *child;
+
+ if (parts[index] == NULL) {
+ return parent;
+ }
+
+ if (strcmp(parts[index], "") == 0) {
+ return qdev_resolve_abs_path(parent, parts, index + 1);
+ }
+
+ prop = qdev_property_find(parent, parts[index]);
+ if (prop == NULL) {
+ return NULL;
+ }
+
+ child = NULL;
+ if (strstart(prop->type, "link<", NULL)) {
+ DeviceState **pchild = prop->opaque;
+ if (*pchild) {
+ child = *pchild;
+ }
+ } else if (strstart(prop->type, "child<", NULL)) {
+ child = prop->opaque;
+ }
+
+ if (!child) {
+ return NULL;
+ }
+
+ return qdev_resolve_abs_path(child, parts, index + 1);
+}
+
+static DeviceState *qdev_resolve_partial_path(DeviceState *parent,
+ gchar **parts,
+ bool *ambiguous)
+{
+ DeviceState *dev;
+ DeviceProperty *prop;
+
+ dev = qdev_resolve_abs_path(parent, parts, 0);
+
+ QTAILQ_FOREACH(prop, &parent->properties, node) {
+ DeviceState *found;
+
+ if (!strstart(prop->type, "child<", NULL)) {
+ continue;
+ }
+
+ found = qdev_resolve_partial_path(prop->opaque, parts, ambiguous);
+ if (found) {
+ if (dev) {
+ if (ambiguous) {
+ *ambiguous = true;
+ }
+ return NULL;
+ }
+ dev = found;
+ }
+
+ if (ambiguous && *ambiguous) {
+ return NULL;
+ }
+ }
+
+ return dev;
+}
+
+DeviceState *qdev_resolve_path(const char *path, bool *ambiguous)
+{
+ bool partial_path = true;
+ DeviceState *dev;
+ gchar **parts;
+
+ parts = g_strsplit(path, "/", 0);
+ if (parts == NULL || parts[0] == NULL) {
+ g_strfreev(parts);
+ return qdev_get_root();
+ }
+
+ if (strcmp(parts[0], "") == 0) {
+ partial_path = false;
+ }
+
+ if (partial_path) {
+ if (ambiguous) {
+ *ambiguous = false;
+ }
+ dev = qdev_resolve_partial_path(qdev_get_root(), parts, ambiguous);
+ } else {
+ dev = qdev_resolve_abs_path(qdev_get_root(), parts, 1);
+ }
+
+ g_strfreev(parts);
+
+ return dev;
+}
+
diff --git a/hw/qdev.h b/hw/qdev.h
index 0f00497..641d134 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -499,4 +499,32 @@ DeviceState *qdev_get_root(void);
*/
gchar *qdev_get_canonical_path(DeviceState *dev);
+/**
+ * @qdev_resolve_path - resolves a path returning a device
+ *
+ * There are two types of supported paths--absolute paths and partial paths.
+ *
+ * Absolute paths are derived from the root device and can follow child<> or
+ * link<> properties. Since they can follow link<> properties, they can be
+ * arbitrarily long. Absolute paths look like absolute filenames and are
+ * prefixed with a leading slash.
+ *
+ * Partial paths look like relative filenames. They do not begin with a
+ * prefix. The matching rules for partial paths are subtle but designed to make
+ * specifying devices easy. At each level of the composition tree, the partial
+ * path is matched as an absolute path. The first match is not returned. At
+ * least two matches are searched for. A successful result is only returned if
+ * only one match is founded. If more than one match is found, a flag is
+ * return to indicate that the match was ambiguous.
+ *
+ * @path - the path to resolve
+ *
+ * @ambiguous - returns true if the path resolution failed because of an
+ * ambiguous match
+ *
+ * Returns:
+ * The matched device or NULL on path lookup failure.
+ */
+DeviceState *qdev_resolve_path(const char *path, bool *ambiguous);
+
#endif
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 007/197] qom: add child properties (composition) (v2)
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (5 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 006/197] qdev: provide a path resolution (v2) Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 008/197] qom: add link properties (v2) Anthony Liguori
` (59 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
Child properties express a relationship of composition.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
v1 -> v2
- fix comments (Kevin)
- add a reference when adding a child property (Kevin)
---
hw/qdev.c | 26 ++++++++++++++++++++++++++
hw/qdev.h | 20 ++++++++++++++++++++
2 files changed, 46 insertions(+), 0 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index 2519f00..fa6b489 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -1174,6 +1174,32 @@ DeviceState *qdev_get_root(void)
return qdev_root;
}
+static void qdev_get_child_property(DeviceState *dev, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ DeviceState *child = opaque;
+ gchar *path;
+
+ path = qdev_get_canonical_path(child);
+ visit_type_str(v, &path, name, errp);
+ g_free(path);
+}
+
+void qdev_property_add_child(DeviceState *dev, const char *name,
+ DeviceState *child, Error **errp)
+{
+ gchar *type;
+
+ type = g_strdup_printf("child<%s>", child->info->name);
+
+ qdev_property_add(dev, name, type, qdev_get_child_property,
+ NULL, NULL, child, errp);
+
+ qdev_ref(dev);
+
+ g_free(type);
+}
+
static gchar *qdev_get_path_in(DeviceState *parent, DeviceState *dev)
{
DeviceProperty *prop;
diff --git a/hw/qdev.h b/hw/qdev.h
index 641d134..38b36e8 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -527,4 +527,24 @@ gchar *qdev_get_canonical_path(DeviceState *dev);
*/
DeviceState *qdev_resolve_path(const char *path, bool *ambiguous);
+/**
+ * @qdev_property_add_child - Add a child property to a device
+ *
+ * Child properties form the composition tree. All devices need to be a child
+ * of another device. Devices can only be a child of one device.
+ *
+ * There is no way for a child to determine what its parent is. It is not
+ * a bidirectional relationship. This is by design.
+ *
+ * @dev - the device to add a property to
+ *
+ * @name - the name of the property
+ *
+ * @child - the child device
+ *
+ * @errp - if an error occurs, a pointer to an area to store the area
+ */
+void qdev_property_add_child(DeviceState *dev, const char *name,
+ DeviceState *child, Error **errp);
+
#endif
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 008/197] qom: add link properties (v2)
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (6 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 007/197] qom: add child properties (composition) (v2) Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 009/197] qapi: allow a 'gen' key to suppress code generation Anthony Liguori
` (58 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
Links represent an ephemeral relationship between devices. They are meant to
replace the qdev concept of busses by allowing more informal relationships
between devices.
Links are fairly limited in their usefulness without implementing QOM-style
subclassing and interfaces.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
v1 -> v2
- comments (Stefan)
- maintain a reference when adding/removing a link property (Kevin)
---
hw/qdev.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
hw/qdev.h | 23 +++++++++++++++++++
2 files changed, 97 insertions(+), 0 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index fa6b489..42430fa 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -1200,6 +1200,80 @@ void qdev_property_add_child(DeviceState *dev, const char *name,
g_free(type);
}
+static void qdev_get_link_property(DeviceState *dev, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ DeviceState **child = opaque;
+ gchar *path;
+
+ if (*child) {
+ path = qdev_get_canonical_path(*child);
+ visit_type_str(v, &path, name, errp);
+ g_free(path);
+ } else {
+ path = (gchar *)"";
+ visit_type_str(v, &path, name, errp);
+ }
+}
+
+static void qdev_set_link_property(DeviceState *dev, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ DeviceState **child = opaque;
+ bool ambiguous = false;
+ const char *type;
+ char *path;
+
+ type = qdev_property_get_type(dev, name, NULL);
+
+ visit_type_str(v, &path, name, errp);
+
+ if (*child) {
+ qdev_unref(*child);
+ }
+
+ if (strcmp(path, "") != 0) {
+ DeviceState *target;
+
+ target = qdev_resolve_path(path, &ambiguous);
+ if (target) {
+ gchar *target_type;
+
+ target_type = g_strdup_printf("link<%s>", target->info->name);
+ if (strcmp(target_type, type) == 0) {
+ *child = target;
+ qdev_ref(target);
+ } else {
+ error_set(errp, QERR_INVALID_PARAMETER_TYPE, name, type);
+ }
+
+ g_free(target_type);
+ } else {
+ error_set(errp, QERR_DEVICE_NOT_FOUND, path);
+ }
+ } else {
+ *child = NULL;
+ }
+
+ g_free(path);
+}
+
+void qdev_property_add_link(DeviceState *dev, const char *name,
+ const char *type, DeviceState **child,
+ Error **errp)
+{
+ gchar *full_type;
+
+ full_type = g_strdup_printf("link<%s>", type);
+
+ qdev_property_add(dev, name, full_type,
+ qdev_get_link_property,
+ qdev_set_link_property,
+ NULL, child, errp);
+
+ g_free(full_type);
+}
+
static gchar *qdev_get_path_in(DeviceState *parent, DeviceState *dev)
{
DeviceProperty *prop;
diff --git a/hw/qdev.h b/hw/qdev.h
index 38b36e8..4351e2e 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -547,4 +547,27 @@ DeviceState *qdev_resolve_path(const char *path, bool *ambiguous);
void qdev_property_add_child(DeviceState *dev, const char *name,
DeviceState *child, Error **errp);
+/**
+ * @qdev_property_add_link - Add a link property to a device
+ *
+ * Links establish relationships between devices. Links are unidirectional
+ * although two links can be combined to form a bidirectional relationship
+ * between devices.
+ *
+ * Links form the graph in the device model.
+ *
+ * @dev - the device to add a property to
+ *
+ * @name - the name of the property
+ *
+ * @type - the qdev type of the link
+ *
+ * @child - a pointer to where the link device reference is stored
+ *
+ * @errp - if an error occurs, a pointer to an area to store the area
+ */
+void qdev_property_add_link(DeviceState *dev, const char *name,
+ const char *type, DeviceState **child,
+ Error **errp);
+
#endif
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 009/197] qapi: allow a 'gen' key to suppress code generation
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (7 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 008/197] qom: add link properties (v2) Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 010/197] qmp: add qom-list command Anthony Liguori
` (57 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
scripts/qapi-commands.py | 1 +
scripts/qapi-types.py | 1 +
2 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
index f7def16..54d1f5d 100644
--- a/scripts/qapi-commands.py
+++ b/scripts/qapi-commands.py
@@ -405,6 +405,7 @@ except os.error, e:
exprs = parse_schema(sys.stdin)
commands = filter(lambda expr: expr.has_key('command'), exprs)
+commands = filter(lambda expr: not expr.has_key('gen'), commands)
if dispatch_type == "sync":
fdecl = open(h_file, 'w')
diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index f64d84c..267cb49 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -238,6 +238,7 @@ fdecl.write(mcgen('''
guard=guardname(h_file)))
exprs = parse_schema(sys.stdin)
+exprs = filter(lambda expr: not expr.has_key('gen'), exprs)
for expr in exprs:
ret = "\n"
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 010/197] qmp: add qom-list command
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (8 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 009/197] qapi: allow a 'gen' key to suppress code generation Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 011/197] qom: qom_{get, set} monitor commands (v2) Anthony Liguori
` (56 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
This can be used to list properties in the device model.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
qapi-schema.json | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
qmp-commands.hx | 6 ++++++
qmp.c | 28 ++++++++++++++++++++++++++++
3 files changed, 82 insertions(+), 0 deletions(-)
diff --git a/qapi-schema.json b/qapi-schema.json
index cb1ba77..276b7c3 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -887,3 +887,51 @@
# Notes: Do not use this command.
##
{ 'command': 'cpu', 'data': {'index': 'int'} }
+
+##
+# @DevicePropertyInfo:
+#
+# @name: the name of the property
+#
+# @type: the type of the property. This will typically come in one of four
+# forms:
+#
+# 1) A primitive type such as 'u8', 'u16', 'bool', 'str', or 'double'.
+# These types are mapped to the appropriate JSON type.
+#
+# 2) A legacy type in the form 'legacy<subtype>' where subtype is the
+# legacy qdev typename. These types are always treated as strings.
+#
+# 3) A child type in the form 'child<subtype>' where subtype is a qdev
+# device type name. Child properties create the composition tree.
+#
+# 4) A link type in the form 'link<subtype>' where subtype is a qdev
+# device type name. Link properties form the device model graph.
+#
+# Since: 1.1
+#
+# Notes: This type is experimental. Its syntax may change in future releases.
+##
+{ 'type': 'DevicePropertyInfo',
+ 'data': { 'name': 'str', 'type': 'str' } }
+
+##
+# @qom-list:
+#
+# This command will list any properties of a device given a path in the device
+# model.
+#
+# @path: the path within the device model. See @qom-get for a description of
+# this parameter.
+#
+# Returns: a list of @DevicePropertyInfo that describe the properties of the
+# device.
+#
+# Since: 1.1
+#
+# Notes: This command is experimental. It's syntax may change in future
+# releases.
+##
+{ 'command': 'qom-list',
+ 'data': { 'path': 'str' },
+ 'returns': [ 'DevicePropertyInfo' ] }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 97975a5..d6ff466 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -2001,3 +2001,9 @@ EQMP
.args_type = "",
.mhandler.cmd_new = qmp_marshal_input_query_balloon,
},
+
+ {
+ .name = "qom-list",
+ .args_type = "path:s",
+ .mhandler.cmd_new = qmp_marshal_input_qom_list,
+ },
diff --git a/qmp.c b/qmp.c
index 511dd62..06ae569 100644
--- a/qmp.c
+++ b/qmp.c
@@ -16,6 +16,7 @@
#include "qmp-commands.h"
#include "kvm.h"
#include "arch_init.h"
+#include "hw/qdev.h"
NameInfo *qmp_query_name(Error **errp)
{
@@ -117,3 +118,30 @@ SpiceInfo *qmp_query_spice(Error **errp)
return NULL;
};
#endif
+
+DevicePropertyInfoList *qmp_qom_list(const char *path, Error **errp)
+{
+ DeviceState *dev;
+ bool ambiguous = false;
+ DevicePropertyInfoList *props = NULL;
+ DeviceProperty *prop;
+
+ dev = qdev_resolve_path(path, &ambiguous);
+ if (dev == NULL) {
+ error_set(errp, QERR_DEVICE_NOT_FOUND, path);
+ return NULL;
+ }
+
+ QTAILQ_FOREACH(prop, &dev->properties, node) {
+ DevicePropertyInfoList *entry = g_malloc0(sizeof(*entry));
+
+ entry->value = g_malloc0(sizeof(DevicePropertyInfo));
+ entry->next = props;
+ props = entry;
+
+ entry->value->name = g_strdup(prop->name);
+ entry->value->type = g_strdup(prop->type);
+ }
+
+ return props;
+}
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 011/197] qom: qom_{get, set} monitor commands (v2)
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (9 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 010/197] qmp: add qom-list command Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 012/197] qdev: add explicitly named devices to the root complex Anthony Liguori
` (55 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
This allows clients to read and write device model properties through QMP. QAPI
doesn't support Visitor types yet and these commands are special in that they
don't work with fixed types.
I've added a documentation stub to qapi-schema.json so we can keep consistency
there.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
v1 -> v2
- comments (Stefan)
---
monitor.h | 4 +++
qapi-schema.json | 59 +++++++++++++++++++++++++++++++++++++++++++++++++
qmp-commands.hx | 12 ++++++++++
qmp.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 140 insertions(+), 0 deletions(-)
diff --git a/monitor.h b/monitor.h
index e76795f..efc76c7 100644
--- a/monitor.h
+++ b/monitor.h
@@ -64,4 +64,8 @@ typedef void (MonitorCompletion)(void *opaque, QObject *ret_data);
void monitor_set_error(Monitor *mon, QError *qerror);
+int qmp_qom_set(Monitor *mon, const QDict *qdict, QObject **ret);
+
+int qmp_qom_get(Monitor *mon, const QDict *qdict, QObject **ret);
+
#endif /* !MONITOR_H */
diff --git a/qapi-schema.json b/qapi-schema.json
index 276b7c3..76a8a53 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -935,3 +935,62 @@
{ 'command': 'qom-list',
'data': { 'path': 'str' },
'returns': [ 'DevicePropertyInfo' ] }
+
+##
+# @qom-get:
+#
+# This command will get a property from a device model path and return the
+# value.
+#
+# @path: The path within the device model. There are two forms of supported
+# paths--absolute and partial paths.
+#
+# Absolute paths are derived from the root device and can follow child<>
+# or link<> properties. Since they can follow link<> properties, they
+# can be arbitrarily long. Absolute paths look like absolute filenames
+# and are prefixed with a leading slash.
+#
+# Partial paths look like relative filenames. They do not begin
+# with a prefix. The matching rules for partial paths are subtle but
+# designed to make specifying devices easy. At each level of the
+# composition tree, the partial path is matched as an absolute path.
+# The first match is not returned. At least two matches are searched
+# for. A successful result is only returned if only one match is
+# found. If more than one match is found, a flag is return to
+# indicate that the match was ambiguous.
+#
+# @property: The property name to read
+#
+# Returns: The property value. The type depends on the property type. legacy<>
+# properties are returned as #str. child<> and link<> properties are
+# returns as #str pathnames. All integer property types (u8, u16, etc)
+# are returned as #int.
+#
+# Since: 1.1
+#
+# Notes: This command is experimental and may change syntax in future releases.
+##
+{ 'command': 'qom-get',
+ 'data': { 'path': 'str', 'property': 'str' },
+ 'returns': 'visitor',
+ 'gen': 'no' }
+
+##
+# @qom-set:
+#
+# This command will set a property from a device model path.
+#
+# @path: see @qom-get for a description of this parameter
+#
+# @property: the property name to set
+#
+# @value: a value who's type is appropriate for the property type. See @qom-get
+# for a description of type mapping.
+#
+# Since: 1.1
+#
+# Notes: This command is experimental and may change syntax in future releases.
+##
+{ 'command': 'qom-set',
+ 'data': { 'path': 'str', 'property': 'str', 'value': 'visitor' },
+ 'gen': 'no' }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index d6ff466..027189a 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -2007,3 +2007,15 @@ EQMP
.args_type = "path:s",
.mhandler.cmd_new = qmp_marshal_input_qom_list,
},
+
+ {
+ .name = "qom-set",
+ .args_type = "path:s,property:s,opts:O",
+ .mhandler.cmd_new = qmp_qom_set,
+ },
+
+ {
+ .name = "qom-get",
+ .args_type = "path:s,property:s",
+ .mhandler.cmd_new = qmp_qom_get,
+ },
diff --git a/qmp.c b/qmp.c
index 06ae569..641761e 100644
--- a/qmp.c
+++ b/qmp.c
@@ -17,6 +17,8 @@
#include "kvm.h"
#include "arch_init.h"
#include "hw/qdev.h"
+#include "qapi/qmp-input-visitor.h"
+#include "qapi/qmp-output-visitor.h"
NameInfo *qmp_query_name(Error **errp)
{
@@ -145,3 +147,66 @@ DevicePropertyInfoList *qmp_qom_list(const char *path, Error **errp)
return props;
}
+
+/* FIXME: teach qapi about how to pass through Visitors */
+int qmp_qom_set(Monitor *mon, const QDict *qdict, QObject **ret)
+{
+ const char *path = qdict_get_str(qdict, "path");
+ const char *property = qdict_get_str(qdict, "property");
+ QObject *value = qdict_get(qdict, "value");
+ Error *local_err = NULL;
+ QmpInputVisitor *mi;
+ DeviceState *dev;
+
+ dev = qdev_resolve_path(path, NULL);
+ if (!dev) {
+ error_set(&local_err, QERR_DEVICE_NOT_FOUND, path);
+ goto out;
+ }
+
+ mi = qmp_input_visitor_new(value);
+ qdev_property_set(dev, qmp_input_get_visitor(mi), property, &local_err);
+
+ qmp_input_visitor_cleanup(mi);
+
+out:
+ if (local_err) {
+ qerror_report_err(local_err);
+ error_free(local_err);
+ return -1;
+ }
+
+ return 0;
+}
+
+int qmp_qom_get(Monitor *mon, const QDict *qdict, QObject **ret)
+{
+ const char *path = qdict_get_str(qdict, "path");
+ const char *property = qdict_get_str(qdict, "property");
+ Error *local_err = NULL;
+ QmpOutputVisitor *mo;
+ DeviceState *dev;
+
+ dev = qdev_resolve_path(path, NULL);
+ if (!dev) {
+ error_set(&local_err, QERR_DEVICE_NOT_FOUND, path);
+ goto out;
+ }
+
+ mo = qmp_output_visitor_new();
+ qdev_property_get(dev, qmp_output_get_visitor(mo), property, &local_err);
+ if (!local_err) {
+ *ret = qmp_output_get_qobject(mo);
+ }
+
+ qmp_output_visitor_cleanup(mo);
+
+out:
+ if (local_err) {
+ qerror_report_err(local_err);
+ error_free(local_err);
+ return -1;
+ }
+
+ return 0;
+}
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 012/197] qdev: add explicitly named devices to the root complex
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (10 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 011/197] qom: qom_{get, set} monitor commands (v2) Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 013/197] dev: add an anonymous peripheral container Anthony Liguori
` (54 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
We first add a 'peripheral' container to the root device that we add user
created devices to. This provides all user created devices with a unique and
isolated namespace.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
hw/qdev.c | 14 ++++++++++++++
1 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index 42430fa..af4c6a2 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -227,6 +227,19 @@ int qdev_device_help(QemuOpts *opts)
return 1;
}
+static DeviceState *qdev_get_peripheral(void)
+{
+ static DeviceState *dev;
+
+ if (dev == NULL) {
+ dev = qdev_create(NULL, "container");
+ qdev_property_add_child(qdev_get_root(), "peripheral", dev, NULL);
+ qdev_init_nofail(dev);
+ }
+
+ return dev;
+}
+
DeviceState *qdev_device_add(QemuOpts *opts)
{
const char *driver, *path, *id;
@@ -278,6 +291,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
id = qemu_opts_id(opts);
if (id) {
qdev->id = id;
+ qdev_property_add_child(qdev_get_peripheral(), qdev->id, qdev, NULL);
}
if (qemu_opt_foreach(opts, set_property, qdev, 1) != 0) {
qdev_free(qdev);
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 013/197] dev: add an anonymous peripheral container
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (11 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 012/197] qdev: add explicitly named devices to the root complex Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 014/197] rtc: make piix3 set the rtc as a child (v2) Anthony Liguori
` (53 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
hw/qdev.c | 21 ++++++++++++++++++++-
1 files changed, 20 insertions(+), 1 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index af4c6a2..5348f26 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -240,6 +240,19 @@ static DeviceState *qdev_get_peripheral(void)
return dev;
}
+static DeviceState *qdev_get_peripheral_anon(void)
+{
+ static DeviceState *dev;
+
+ if (dev == NULL) {
+ dev = qdev_create(NULL, "container");
+ qdev_property_add_child(qdev_get_root(), "peripheral-anon", dev, NULL);
+ qdev_init_nofail(dev);
+ }
+
+ return dev;
+}
+
DeviceState *qdev_device_add(QemuOpts *opts)
{
const char *driver, *path, *id;
@@ -292,7 +305,13 @@ DeviceState *qdev_device_add(QemuOpts *opts)
if (id) {
qdev->id = id;
qdev_property_add_child(qdev_get_peripheral(), qdev->id, qdev, NULL);
- }
+ } else {
+ static int anon_count;
+ gchar *name = g_strdup_printf("device[%d]", anon_count++);
+ qdev_property_add_child(qdev_get_peripheral_anon(), name,
+ qdev, NULL);
+ g_free(name);
+ }
if (qemu_opt_foreach(opts, set_property, qdev, 1) != 0) {
qdev_free(qdev);
return NULL;
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 014/197] rtc: make piix3 set the rtc as a child (v2)
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (12 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 013/197] dev: add an anonymous peripheral container Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 015/197] rtc: add a dynamic property for retrieving the date Anthony Liguori
` (52 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
v1 -> v2
- comments (Stefan)
---
hw/pc_piix.c | 11 +++++++++++
hw/piix_pci.c | 3 +++
2 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/hw/pc_piix.c b/hw/pc_piix.c
index 970f43c..2d5ea2c 100644
--- a/hw/pc_piix.c
+++ b/hw/pc_piix.c
@@ -205,6 +205,17 @@ static void pc_init1(MemoryRegion *system_memory,
}
}
+ /* FIXME there's some major spaghetti here. Somehow we create the devices
+ * on the PIIX before we actually create it. We create the PIIX3 deep in
+ * the recess of the i440fx creation too and then lose the DeviceState.
+ *
+ * For now, let's "fix" this by making judicious use of paths. This is not
+ * generally the right way to do this.
+ */
+
+ qdev_property_add_child(qdev_resolve_path("/i440fx/piix3", NULL),
+ "rtc", (DeviceState *)rtc_state, NULL);
+
audio_init(gsi, pci_enabled ? pci_bus : NULL);
pc_cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device,
diff --git a/hw/piix_pci.c b/hw/piix_pci.c
index d183443..d785d4b 100644
--- a/hw/piix_pci.c
+++ b/hw/piix_pci.c
@@ -288,6 +288,7 @@ static PCIBus *i440fx_common_init(const char *device_name,
address_space_io, 0);
s->bus = b;
qdev_init_nofail(dev);
+ qdev_property_add_child(qdev_get_root(), "i440fx", dev, NULL);
d = pci_create_simple(b, 0, device_name);
*pi440fx_state = DO_UPCAST(PCII440FXState, dev, d);
@@ -323,6 +324,8 @@ static PCIBus *i440fx_common_init(const char *device_name,
pci_create_simple_multifunction(b, -1, true, "PIIX3"));
pci_bus_irqs(b, piix3_set_irq, pci_slot_get_pirq, piix3,
PIIX_NUM_PIRQS);
+
+ qdev_property_add_child(dev, "piix3", &piix3->dev.qdev, NULL);
}
piix3->pic = pic;
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 015/197] rtc: add a dynamic property for retrieving the date
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (13 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 014/197] rtc: make piix3 set the rtc as a child (v2) Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 016/197] qom: optimize qdev_get_canonical_path using a parent link Anthony Liguori
` (51 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
This really shows the power of dynamic object properties compared to qdev
static properties.
This property represents a complex structure who's format is preserved over the
wire. This is enabled by visitors.
It also shows an entirely synthetic property that is not tied to device state.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
hw/mc146818rtc.c | 27 +++++++++++++++++++++++++++
1 files changed, 27 insertions(+), 0 deletions(-)
diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
index 2aaca2f..0c23cb0 100644
--- a/hw/mc146818rtc.c
+++ b/hw/mc146818rtc.c
@@ -614,6 +614,29 @@ static const MemoryRegionOps cmos_ops = {
.old_portio = cmos_portio
};
+// FIXME add int32 visitor
+static void visit_type_int32(Visitor *v, int *value, const char *name, Error **errp)
+{
+ int64_t val = *value;
+ visit_type_int(v, &val, name, errp);
+}
+
+static void rtc_get_date(DeviceState *dev, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ ISADevice *isa = DO_UPCAST(ISADevice, qdev, dev);
+ RTCState *s = DO_UPCAST(RTCState, dev, isa);
+
+ visit_start_struct(v, NULL, "struct tm", name, 0, errp);
+ visit_type_int32(v, &s->current_tm.tm_year, "tm_year", errp);
+ visit_type_int32(v, &s->current_tm.tm_mon, "tm_mon", errp);
+ visit_type_int32(v, &s->current_tm.tm_mday, "tm_mday", errp);
+ visit_type_int32(v, &s->current_tm.tm_hour, "tm_hour", errp);
+ visit_type_int32(v, &s->current_tm.tm_min, "tm_min", errp);
+ visit_type_int32(v, &s->current_tm.tm_sec, "tm_sec", errp);
+ visit_end_struct(v, errp);
+}
+
static int rtc_initfn(ISADevice *dev)
{
RTCState *s = DO_UPCAST(RTCState, dev, dev);
@@ -647,6 +670,10 @@ static int rtc_initfn(ISADevice *dev)
qdev_set_legacy_instance_id(&dev->qdev, base, 2);
qemu_register_reset(rtc_reset, s);
+
+ qdev_property_add(&s->dev.qdev, "date", "struct tm",
+ rtc_get_date, NULL, NULL, s, NULL);
+
return 0;
}
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 016/197] qom: optimize qdev_get_canonical_path using a parent link
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (14 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 015/197] rtc: add a dynamic property for retrieving the date Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 017/197] qmp: make qmp.py easier to use Anthony Liguori
` (50 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
The full tree search was a bit unreasonable.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
hw/qdev.c | 56 ++++++++++++++++++++++++--------------------------------
hw/qdev.h | 4 ++++
2 files changed, 28 insertions(+), 32 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index 5348f26..1102efd 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -1229,6 +1229,8 @@ void qdev_property_add_child(DeviceState *dev, const char *name,
NULL, NULL, child, errp);
qdev_ref(dev);
+ g_assert(child->parent == NULL);
+ child->parent = dev;
g_free(type);
}
@@ -1307,48 +1309,38 @@ void qdev_property_add_link(DeviceState *dev, const char *name,
g_free(full_type);
}
-static gchar *qdev_get_path_in(DeviceState *parent, DeviceState *dev)
+gchar *qdev_get_canonical_path(DeviceState *dev)
{
- DeviceProperty *prop;
+ DeviceState *root = qdev_get_root();
+ char *newpath = NULL, *path = NULL;
- if (parent == dev) {
- return g_strdup("");
- }
+ while (dev != root) {
+ DeviceProperty *prop = NULL;
- QTAILQ_FOREACH(prop, &parent->properties, node) {
- gchar *subpath;
+ g_assert(dev->parent != NULL);
- if (!strstart(prop->type, "child<", NULL)) {
- continue;
- }
+ QTAILQ_FOREACH(prop, &dev->parent->properties, node) {
+ if (!strstart(prop->type, "child<", NULL)) {
+ continue;
+ }
- /* Check to see if the device is one of parent's children */
- if (prop->opaque == dev) {
- return g_strdup(prop->name);
+ if (prop->opaque == dev) {
+ if (path) {
+ newpath = g_strdup_printf("%s/%s", prop->name, path);
+ g_free(path);
+ path = newpath;
+ } else {
+ path = g_strdup(prop->name);
+ }
+ break;
+ }
}
- /* Check to see if the device is a child of our child */
- subpath = qdev_get_path_in(prop->opaque, dev);
- if (subpath) {
- gchar *path;
+ g_assert(prop != NULL);
- path = g_strdup_printf("%s/%s", prop->name, subpath);
- g_free(subpath);
-
- return path;
- }
+ dev = dev->parent;
}
- return NULL;
-}
-
-gchar *qdev_get_canonical_path(DeviceState *dev)
-{
- gchar *path, *newpath;
-
- path = qdev_get_path_in(qdev_get_root(), dev);
- g_assert(path != NULL);
-
newpath = g_strdup_printf("/%s", path);
g_free(path);
diff --git a/hw/qdev.h b/hw/qdev.h
index 4351e2e..fdab848 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -92,6 +92,10 @@ struct DeviceState {
uint32_t ref;
QTAILQ_HEAD(, DeviceProperty) properties;
+
+ /* Do not, under any circumstance, use this parent link below anywhere
+ * outside of qdev.c. You have been warned. */
+ DeviceState *parent;
};
typedef void (*bus_dev_printfn)(Monitor *mon, DeviceState *dev, int indent);
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 017/197] qmp: make qmp.py easier to use
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (15 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 016/197] qom: optimize qdev_get_canonical_path using a parent link Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 018/197] qom: add test tools (v2) Anthony Liguori
` (49 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
QMP/qmp.py | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/QMP/qmp.py b/QMP/qmp.py
index c7dbea0..36ecc1d 100644
--- a/QMP/qmp.py
+++ b/QMP/qmp.py
@@ -128,6 +128,12 @@ class QEMUMonitorProtocol:
qmp_cmd['id'] = id
return self.cmd_obj(qmp_cmd)
+ def command(self, cmd, **kwds):
+ ret = self.cmd(cmd, kwds)
+ if ret.has_key('error'):
+ raise Exception(ret['error']['desc'])
+ return ret['return']
+
def get_events(self, wait=False):
"""
Get a list of available QMP events.
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 018/197] qom: add test tools (v2)
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (16 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 017/197] qmp: make qmp.py easier to use Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 019/197] bug fix spotted by paolo Anthony Liguori
` (48 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
v1 -> v2
- fix comments (Stefan)
---
QMP/qom-get | 26 ++++++++++++++++++++++++++
QMP/qom-list | 30 ++++++++++++++++++++++++++++++
QMP/qom-set | 21 +++++++++++++++++++++
3 files changed, 77 insertions(+), 0 deletions(-)
create mode 100755 QMP/qom-get
create mode 100755 QMP/qom-list
create mode 100755 QMP/qom-set
diff --git a/QMP/qom-get b/QMP/qom-get
new file mode 100755
index 0000000..e6c063a
--- /dev/null
+++ b/QMP/qom-get
@@ -0,0 +1,26 @@
+#!/usr/bin/python
+##
+# QEMU Object Model test tools
+#
+# Copyright IBM, Corp. 2011
+#
+# Authors:
+# Anthony Liguori <aliguori@us.ibm.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or later. See
+# the COPYING file in the top-level directory.
+##
+
+import sys
+from qmp import QEMUMonitorProtocol
+
+srv = QEMUMonitorProtocol('/tmp/server.sock')
+srv.connect()
+
+path, prop = sys.argv[1].rsplit('.', 1)
+rsp = srv.command('qom-get', path=path, property=prop)
+if type(rsp) == dict:
+ for i in rsp.keys():
+ print '%s: %s' % (i, rsp[i])
+else:
+ print rsp
diff --git a/QMP/qom-list b/QMP/qom-list
new file mode 100755
index 0000000..b91f814
--- /dev/null
+++ b/QMP/qom-list
@@ -0,0 +1,30 @@
+#!/usr/bin/python
+##
+# QEMU Object Model test tools
+#
+# Copyright IBM, Corp. 2011
+#
+# Authors:
+# Anthony Liguori <aliguori@us.ibm.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or later. See
+# the COPYING file in the top-level directory.
+##
+
+import sys
+from qmp import QEMUMonitorProtocol
+
+srv = QEMUMonitorProtocol('/tmp/server.sock')
+srv.connect()
+
+if len(sys.argv) == 1:
+ print '/'
+ sys.exit(0)
+
+for item in srv.command('qom-list', path=sys.argv[1]):
+ if item['type'].startswith('child<'):
+ print '%s/' % item['name']
+ elif item['type'].startswith('link<'):
+ print '@%s/' % item['name']
+ else:
+ print '%s' % item['name']
diff --git a/QMP/qom-set b/QMP/qom-set
new file mode 100755
index 0000000..c5589d8
--- /dev/null
+++ b/QMP/qom-set
@@ -0,0 +1,21 @@
+#!/usr/bin/python
+##
+# QEMU Object Model test tools
+#
+# Copyright IBM, Corp. 2011
+#
+# Authors:
+# Anthony Liguori <aliguori@us.ibm.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or later. See
+# the COPYING file in the top-level directory.
+##
+
+import sys
+from qmp import QEMUMonitorProtocol
+
+srv = QEMUMonitorProtocol('/tmp/server.sock')
+srv.connect()
+
+path, prop = sys.argv[1].rsplit('.', 1)
+print srv.command('qom-set', path=path, property=prop, value=sys.argv[2])
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 019/197] bug fix spotted by paolo
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (17 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 018/197] qom: add test tools (v2) Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 020/197] qom: add vga node to the pc composition tree Anthony Liguori
` (47 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/qdev.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index 1102efd..4004860 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -1228,7 +1228,7 @@ void qdev_property_add_child(DeviceState *dev, const char *name,
qdev_property_add(dev, name, type, qdev_get_child_property,
NULL, NULL, child, errp);
- qdev_ref(dev);
+ qdev_ref(child);
g_assert(child->parent == NULL);
child->parent = dev;
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 020/197] qom: add vga node to the pc composition tree
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (18 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 019/197] bug fix spotted by paolo Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 021/197] qom: add string property type Anthony Liguori
` (46 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
hw/cirrus_vga.c | 8 +++++---
hw/pc.c | 26 ++++++++++++++++----------
hw/pc.h | 14 +++++++-------
hw/pc_piix.c | 6 +++++-
hw/vga-pci.c | 5 ++---
hw/vmware_vga.h | 6 +++---
6 files changed, 38 insertions(+), 27 deletions(-)
diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c
index c7e365b..c0db315 100644
--- a/hw/cirrus_vga.c
+++ b/hw/cirrus_vga.c
@@ -2899,7 +2899,7 @@ static void cirrus_init_common(CirrusVGAState * s, int device_id, int is_pci,
*
***************************************/
-void isa_cirrus_vga_init(MemoryRegion *system_memory)
+DeviceState *isa_cirrus_vga_init(MemoryRegion *system_memory)
{
CirrusVGAState *s;
@@ -2913,6 +2913,8 @@ void isa_cirrus_vga_init(MemoryRegion *system_memory)
vmstate_register(NULL, 0, &vmstate_cirrus_vga, s);
rom_add_vga(VGABIOS_CIRRUS_FILENAME);
/* XXX ISA-LFB support */
+ /* FIXME not qdev yet */
+ return NULL;
}
/***************************************
@@ -2955,9 +2957,9 @@ static int pci_cirrus_vga_initfn(PCIDevice *dev)
return 0;
}
-void pci_cirrus_vga_init(PCIBus *bus)
+DeviceState *pci_cirrus_vga_init(PCIBus *bus)
{
- pci_create_simple(bus, -1, "cirrus-vga");
+ return &pci_create_simple(bus, -1, "cirrus-vga")->qdev;
}
static PCIDeviceInfo cirrus_vga_info = {
diff --git a/hw/pc.c b/hw/pc.c
index 33778fe..2fd124a 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -1069,38 +1069,44 @@ qemu_irq *pc_allocate_cpu_irq(void)
return qemu_allocate_irqs(pic_irq_request, NULL, 1);
}
-void pc_vga_init(PCIBus *pci_bus)
+DeviceState *pc_vga_init(PCIBus *pci_bus)
{
+ DeviceState *dev = NULL;
+
if (cirrus_vga_enabled) {
if (pci_bus) {
- pci_cirrus_vga_init(pci_bus);
+ dev = pci_cirrus_vga_init(pci_bus);
} else {
- isa_cirrus_vga_init(get_system_memory());
+ dev = isa_cirrus_vga_init(get_system_memory());
}
} else if (vmsvga_enabled) {
if (pci_bus) {
- if (!pci_vmsvga_init(pci_bus)) {
+ dev = pci_vmsvga_init(pci_bus);
+ if (!dev) {
fprintf(stderr, "Warning: vmware_vga not available,"
" using standard VGA instead\n");
- pci_vga_init(pci_bus);
+ dev = pci_vga_init(pci_bus);
}
} else {
fprintf(stderr, "%s: vmware_vga: no PCI bus\n", __FUNCTION__);
}
#ifdef CONFIG_SPICE
} else if (qxl_enabled) {
- if (pci_bus)
- pci_create_simple(pci_bus, -1, "qxl-vga");
- else
+ if (pci_bus) {
+ dev = &pci_create_simple(pci_bus, -1, "qxl-vga")->qdev;
+ } else {
fprintf(stderr, "%s: qxl: no PCI bus\n", __FUNCTION__);
+ }
#endif
} else if (std_vga_enabled) {
if (pci_bus) {
- pci_vga_init(pci_bus);
+ dev = pci_vga_init(pci_bus);
} else {
- isa_vga_init();
+ dev = isa_vga_init();
}
}
+
+ return dev;
}
static void cpu_request_exit(void *opaque, int irq, int level)
diff --git a/hw/pc.h b/hw/pc.h
index 4515006..8d2e553 100644
--- a/hw/pc.h
+++ b/hw/pc.h
@@ -139,7 +139,7 @@ void pc_memory_init(MemoryRegion *system_memory,
MemoryRegion *rom_memory,
MemoryRegion **ram_memory);
qemu_irq *pc_allocate_cpu_irq(void);
-void pc_vga_init(PCIBus *pci_bus);
+DeviceState *pc_vga_init(PCIBus *pci_bus);
void pc_basic_device_init(qemu_irq *gsi,
ISADevice **rtc_state,
ISADevice **floppy,
@@ -204,27 +204,27 @@ enum vga_retrace_method {
extern enum vga_retrace_method vga_retrace_method;
-static inline int isa_vga_init(void)
+static inline DeviceState *isa_vga_init(void)
{
ISADevice *dev;
dev = isa_try_create("isa-vga");
if (!dev) {
fprintf(stderr, "Warning: isa-vga not available\n");
- return 0;
+ return NULL;
}
qdev_init_nofail(&dev->qdev);
- return 1;
+ return &dev->qdev;
}
-int pci_vga_init(PCIBus *bus);
+DeviceState *pci_vga_init(PCIBus *bus);
int isa_vga_mm_init(target_phys_addr_t vram_base,
target_phys_addr_t ctrl_base, int it_shift,
MemoryRegion *address_space);
/* cirrus_vga.c */
-void pci_cirrus_vga_init(PCIBus *bus);
-void isa_cirrus_vga_init(MemoryRegion *address_space);
+DeviceState *pci_cirrus_vga_init(PCIBus *bus);
+DeviceState *isa_cirrus_vga_init(MemoryRegion *address_space);
/* ne2000.c */
static inline bool isa_ne2000_init(int base, int irq, NICInfo *nd)
diff --git a/hw/pc_piix.c b/hw/pc_piix.c
index 2d5ea2c..166c2fc 100644
--- a/hw/pc_piix.c
+++ b/hw/pc_piix.c
@@ -99,6 +99,7 @@ static void pc_init1(MemoryRegion *system_memory,
MemoryRegion *ram_memory;
MemoryRegion *pci_memory;
MemoryRegion *rom_memory;
+ DeviceState *dev;
pc_cpus_init(cpu_model);
@@ -168,7 +169,10 @@ static void pc_init1(MemoryRegion *system_memory,
pc_register_ferr_irq(gsi[13]);
- pc_vga_init(pci_enabled? pci_bus: NULL);
+ dev = pc_vga_init(pci_enabled? pci_bus: NULL);
+ if (dev) {
+ qdev_property_add_child(qdev_get_root(), "vga", dev, NULL);
+ }
if (xen_enabled()) {
pci_create_simple(pci_bus, -1, "xen-platform");
diff --git a/hw/vga-pci.c b/hw/vga-pci.c
index 14bfadb..a75dbf3 100644
--- a/hw/vga-pci.c
+++ b/hw/vga-pci.c
@@ -70,10 +70,9 @@ static int pci_vga_initfn(PCIDevice *dev)
return 0;
}
-int pci_vga_init(PCIBus *bus)
+DeviceState *pci_vga_init(PCIBus *bus)
{
- pci_create_simple(bus, -1, "VGA");
- return 0;
+ return &pci_create_simple(bus, -1, "VGA")->qdev;
}
static PCIDeviceInfo vga_info = {
diff --git a/hw/vmware_vga.h b/hw/vmware_vga.h
index 5132573..db11cbf 100644
--- a/hw/vmware_vga.h
+++ b/hw/vmware_vga.h
@@ -4,15 +4,15 @@
#include "qemu-common.h"
/* vmware_vga.c */
-static inline bool pci_vmsvga_init(PCIBus *bus)
+static inline DeviceState *pci_vmsvga_init(PCIBus *bus)
{
PCIDevice *dev;
dev = pci_try_create(bus, -1, "vmware-svga");
if (!dev || qdev_init(&dev->qdev) < 0) {
- return false;
+ return NULL;
} else {
- return true;
+ return &dev->qdev;
}
}
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 021/197] qom: add string property type
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (19 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 020/197] qom: add vga node to the pc composition tree Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 022/197] qdev: add a qdev_get_type() function and expose as a 'type' property Anthony Liguori
` (45 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
hw/qdev.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
hw/qdev.h | 22 ++++++++++++++++++++++
2 files changed, 81 insertions(+), 0 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index 4004860..0fc20fc 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -1449,3 +1449,62 @@ DeviceState *qdev_resolve_path(const char *path, bool *ambiguous)
return dev;
}
+typedef struct StringProperty
+{
+ char *(*get)(DeviceState *, Error **);
+ void (*set)(DeviceState *, const char *, Error **);
+} StringProperty;
+
+static void qdev_property_get_str(DeviceState *dev, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ StringProperty *prop = opaque;
+ char *value;
+
+ value = prop->get(dev, errp);
+ if (value) {
+ visit_type_str(v, &value, name, errp);
+ g_free(value);
+ }
+}
+
+static void qdev_property_set_str(DeviceState *dev, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ StringProperty *prop = opaque;
+ char *value;
+ Error *local_err = NULL;
+
+ visit_type_str(v, &value, name, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
+
+ prop->set(dev, value, errp);
+ g_free(value);
+}
+
+static void qdev_property_release_str(DeviceState *dev, const char *name,
+ void *opaque)
+{
+ StringProperty *prop = opaque;
+ g_free(prop);
+}
+
+void qdev_property_add_str(DeviceState *dev, const char *name,
+ char *(*get)(DeviceState *, Error **),
+ void (*set)(DeviceState *, const char *, Error **),
+ Error **errp)
+{
+ StringProperty *prop = g_malloc0(sizeof(*prop));
+
+ prop->get = get;
+ prop->set = set;
+
+ qdev_property_add(dev, name, "string",
+ get ? qdev_property_get_str : NULL,
+ set ? qdev_property_set_str : NULL,
+ qdev_property_release_str,
+ prop, errp);
+}
diff --git a/hw/qdev.h b/hw/qdev.h
index fdab848..9faf2ee 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -574,4 +574,26 @@ void qdev_property_add_link(DeviceState *dev, const char *name,
const char *type, DeviceState **child,
Error **errp);
+/**
+ * @qdev_property_add_str
+ *
+ * Add a string property using getters/setters. This function will add a
+ * property of type 'string'.
+ *
+ * @dev - the device to add a property to
+ *
+ * @name - the name of the property
+ *
+ * @get - the getter or NULL if the property is write-only. This function must
+ * return a string to be freed by @g_free().
+ *
+ * @set - the setter or NULL if the property is read-only
+ *
+ * @errp - if an error occurs, a pointer to an area to store the error
+ */
+void qdev_property_add_str(DeviceState *dev, const char *name,
+ char *(*get)(DeviceState *, Error **),
+ void (*set)(DeviceState *, const char *, Error **),
+ Error **errp);
+
#endif
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 022/197] qdev: add a qdev_get_type() function and expose as a 'type' property
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (20 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 021/197] qom: add string property type Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 023/197] pc: fill out most of the composition tree Anthony Liguori
` (44 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
hw/qdev.c | 7 +++++++
hw/qdev.h | 14 ++++++++++++++
2 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/hw/qdev.c b/hw/qdev.c
index 0fc20fc..83913c7 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -110,6 +110,8 @@ static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info)
qdev_property_add_legacy(dev, prop, NULL);
}
+ qdev_property_add_str(dev, "type", qdev_get_type, NULL, NULL);
+
return dev;
}
@@ -1031,6 +1033,11 @@ char* qdev_get_fw_dev_path(DeviceState *dev)
return strdup(path);
}
+char *qdev_get_type(DeviceState *dev, Error **errp)
+{
+ return g_strdup(dev->info->name);
+}
+
void qdev_ref(DeviceState *dev)
{
dev->ref++;
diff --git a/hw/qdev.h b/hw/qdev.h
index 9faf2ee..6e18427 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -596,4 +596,18 @@ void qdev_property_add_str(DeviceState *dev, const char *name,
void (*set)(DeviceState *, const char *, Error **),
Error **errp);
+/**
+ * @qdev_get_type
+ *
+ * Returns the string representation of the type of this object.
+ *
+ * @dev - the device
+ *
+ * @errp - if an error occurs, a pointer to an area to store the error
+ *
+ * Returns: a string representing the type. This must be freed by the caller
+ * with g_free().
+ */
+char *qdev_get_type(DeviceState *dev, Error **errp);
+
#endif
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 023/197] pc: fill out most of the composition tree
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (21 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 022/197] qdev: add a qdev_get_type() function and expose as a 'type' property Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 024/197] i440fx: split out piix3 device Anthony Liguori
` (43 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
hw/acpi_piix4.c | 7 +++--
hw/ide/pci.c | 11 +++++++-
hw/kvmclock.c | 5 ++-
hw/kvmclock.h | 5 ++-
hw/pc.c | 49 ++++++++++++++++++++++++++++++++-------
hw/pc.h | 37 ++++++++++++++++-------------
hw/pc_piix.c | 68 ++++++++++++++++++++++++++++++++++--------------------
hw/piix_pci.c | 12 +++++++--
hw/usb-uhci.c | 4 +-
hw/usb-uhci.h | 2 +-
10 files changed, 134 insertions(+), 66 deletions(-)
diff --git a/hw/acpi_piix4.c b/hw/acpi_piix4.c
index d9075e6..401baaa 100644
--- a/hw/acpi_piix4.c
+++ b/hw/acpi_piix4.c
@@ -372,14 +372,15 @@ static int piix4_pm_initfn(PCIDevice *dev)
return 0;
}
-i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
- qemu_irq sci_irq, qemu_irq cmos_s3, qemu_irq smi_irq,
- int kvm_enabled)
+i2c_bus *piix4_pm_init(PCIBus *bus, DeviceState **pdev, int devfn,
+ uint32_t smb_io_base, qemu_irq sci_irq,
+ qemu_irq cmos_s3, qemu_irq smi_irq, int kvm_enabled)
{
PCIDevice *dev;
PIIX4PMState *s;
dev = pci_create(bus, devfn, "PIIX4_PM");
+ *pdev = &dev->qdev;
qdev_prop_set_uint32(&dev->qdev, "smb_io_base", smb_io_base);
s = DO_UPCAST(PIIX4PMState, dev, dev);
diff --git a/hw/ide/pci.c b/hw/ide/pci.c
index 49b823d..897bca2 100644
--- a/hw/ide/pci.c
+++ b/hw/ide/pci.c
@@ -498,9 +498,16 @@ void pci_ide_create_devs(PCIDevice *dev, DriveInfo **hd_table)
int i;
for (i = 0; i < 4; i++) {
- if (hd_table[i] == NULL)
+ char name[32];
+ IDEDevice *c;
+
+ if (hd_table[i] == NULL) {
continue;
- ide_create_drive(d->bus+bus[i], unit[i], hd_table[i]);
+ }
+
+ c = ide_create_drive(d->bus+bus[i], unit[i], hd_table[i]);
+ snprintf(name, sizeof(name), "drive[%d]", i);
+ qdev_property_add_child(&dev->qdev, name, &c->qdev, NULL);
}
}
diff --git a/hw/kvmclock.c b/hw/kvmclock.c
index 5388bc4..ddfaf3c 100644
--- a/hw/kvmclock.c
+++ b/hw/kvmclock.c
@@ -99,13 +99,14 @@ static SysBusDeviceInfo kvmclock_info = {
};
/* Note: Must be called after VCPU initialization. */
-void kvmclock_create(void)
+DeviceState *kvmclock_create(void)
{
if (kvm_enabled() &&
first_cpu->cpuid_kvm_features & ((1ULL << KVM_FEATURE_CLOCKSOURCE) |
(1ULL << KVM_FEATURE_CLOCKSOURCE2))) {
- sysbus_create_simple("kvmclock", -1, NULL);
+ return sysbus_create_simple("kvmclock", -1, NULL);
}
+ return NULL;
}
static void kvmclock_register_device(void)
diff --git a/hw/kvmclock.h b/hw/kvmclock.h
index 252ea13..40dda86 100644
--- a/hw/kvmclock.h
+++ b/hw/kvmclock.h
@@ -13,12 +13,13 @@
#ifdef CONFIG_KVM
-void kvmclock_create(void);
+DeviceState *kvmclock_create(void);
#else /* CONFIG_KVM */
-static inline void kvmclock_create(void)
+static inline DeviceState *kvmclock_create(void)
{
+ return NULL;
}
#endif /* !CONFIG_KVM */
diff --git a/hw/pc.c b/hw/pc.c
index 2fd124a..47e6fb9 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -849,15 +849,17 @@ static const int ne2000_irq[NE2000_NB_MAX] = { 9, 10, 11, 3, 4, 5 };
static const int parallel_io[MAX_PARALLEL_PORTS] = { 0x378, 0x278, 0x3bc };
static const int parallel_irq[MAX_PARALLEL_PORTS] = { 7, 7, 7 };
-void pc_init_ne2k_isa(NICInfo *nd)
+DeviceState *pc_init_ne2k_isa(NICInfo *nd)
{
static int nb_ne2k = 0;
+ DeviceState *dev;
if (nb_ne2k == NE2000_NB_MAX)
- return;
- isa_ne2000_init(ne2000_io[nb_ne2k],
- ne2000_irq[nb_ne2k], nd);
+ return NULL;
+ dev = isa_ne2000_init(ne2000_io[nb_ne2k],
+ ne2000_irq[nb_ne2k], nd);
nb_ne2k++;
+ return dev;
}
int cpu_is_bsp(CPUState *env)
@@ -1118,7 +1120,9 @@ static void cpu_request_exit(void *opaque, int irq, int level)
}
}
-void pc_basic_device_init(qemu_irq *gsi,
+void pc_basic_device_init(DeviceState *board,
+ DeviceState *superio,
+ qemu_irq *gsi,
ISADevice **rtc_state,
ISADevice **floppy,
bool no_vmport)
@@ -1142,33 +1146,51 @@ void pc_basic_device_init(qemu_irq *gsi,
sysbus_connect_irq(sysbus_from_qdev(hpet), i, gsi[i]);
}
rtc_irq = qdev_get_gpio_in(hpet, 0);
+
+ qdev_property_add_child(board, "hpet", hpet, NULL);
}
}
*rtc_state = rtc_init(2000, rtc_irq);
+ qdev_property_add_child(superio, "rtc", &(*rtc_state)->qdev, NULL);
qemu_register_boot_set(pc_boot_set, *rtc_state);
pit = pit_init(0x40, 0);
+ qdev_property_add_child(superio, "pit", &pit->qdev, NULL);
+
+ /* FIXME not qdev */
pcspk_init(pit);
for(i = 0; i < MAX_SERIAL_PORTS; i++) {
if (serial_hds[i]) {
- serial_isa_init(i, serial_hds[i]);
+ DeviceState *dev;
+ char name[1024];
+
+ dev = serial_isa_init(i, serial_hds[i]);
+ snprintf(name, sizeof(name), "serial[%d]", i);
+ qdev_property_add_child(board, name, dev, NULL);
}
}
for(i = 0; i < MAX_PARALLEL_PORTS; i++) {
if (parallel_hds[i]) {
- parallel_init(i, parallel_hds[i]);
+ DeviceState *dev;
+ char name[1024];
+
+ dev = parallel_init(i, parallel_hds[i]);
+ snprintf(name, sizeof(name), "parallel[%d]", i);
+ qdev_property_add_child(board, name, dev, NULL);
}
}
a20_line = qemu_allocate_irqs(handle_a20_line_change, first_cpu, 2);
i8042 = isa_create_simple("i8042");
+ qdev_property_add_child(superio, "pckbd", &i8042->qdev, NULL);
i8042_setup_a20_line(i8042, &a20_line[0]);
if (!no_vmport) {
vmport_init();
vmmouse = isa_try_create("vmmouse");
+ qdev_property_add_child(superio, "vmmouse", &vmmouse->qdev, NULL);
} else {
vmmouse = NULL;
}
@@ -1178,23 +1200,32 @@ void pc_basic_device_init(qemu_irq *gsi,
}
port92 = isa_create_simple("port92");
port92_init(port92, &a20_line[1]);
+ qdev_property_add_child(superio, "port92", &port92->qdev, NULL);
cpu_exit_irq = qemu_allocate_irqs(cpu_request_exit, NULL, 1);
+
+ /* FIXME not qdev */
DMA_init(0, cpu_exit_irq);
for(i = 0; i < MAX_FD; i++) {
fd[i] = drive_get(IF_FLOPPY, 0, i);
}
*floppy = fdctrl_init_isa(fd);
+ qdev_property_add_child(superio, "floppy", &(*floppy)->qdev, NULL);
}
-void pc_pci_device_init(PCIBus *pci_bus)
+void pc_pci_device_init(PCIBus *pci_bus, DeviceState *board)
{
int max_bus;
int bus;
max_bus = drive_get_max_bus(IF_SCSI);
for (bus = 0; bus <= max_bus; bus++) {
- pci_create_simple(pci_bus, -1, "lsi53c895a");
+ DeviceState *dev;
+ char name[32];
+
+ snprintf(name, sizeof(name), "scsi[%d]", bus);
+ dev = &pci_create_simple(pci_bus, -1, "lsi53c895a")->qdev;
+ qdev_property_add_child(board, name, dev, NULL);
}
}
diff --git a/hw/pc.h b/hw/pc.h
index 8d2e553..cd64755 100644
--- a/hw/pc.h
+++ b/hw/pc.h
@@ -20,39 +20,39 @@ SerialState *serial_mm_init(MemoryRegion *address_space,
target_phys_addr_t base, int it_shift,
qemu_irq irq, int baudbase,
CharDriverState *chr, enum device_endian);
-static inline bool serial_isa_init(int index, CharDriverState *chr)
+static inline DeviceState *serial_isa_init(int index, CharDriverState *chr)
{
ISADevice *dev;
dev = isa_try_create("isa-serial");
if (!dev) {
- return false;
+ return NULL;
}
qdev_prop_set_uint32(&dev->qdev, "index", index);
qdev_prop_set_chr(&dev->qdev, "chardev", chr);
if (qdev_init(&dev->qdev) < 0) {
- return false;
+ return NULL;
}
- return true;
+ return &dev->qdev;
}
void serial_set_frequency(SerialState *s, uint32_t frequency);
/* parallel.c */
-static inline bool parallel_init(int index, CharDriverState *chr)
+static inline DeviceState *parallel_init(int index, CharDriverState *chr)
{
ISADevice *dev;
dev = isa_try_create("isa-parallel");
if (!dev) {
- return false;
+ return NULL;
}
qdev_prop_set_uint32(&dev->qdev, "index", index);
qdev_prop_set_chr(&dev->qdev, "chardev", chr);
if (qdev_init(&dev->qdev) < 0) {
- return false;
+ return NULL;
}
- return true;
+ return &dev->qdev;
}
bool parallel_mm_init(target_phys_addr_t base, int it_shift, qemu_irq irq,
@@ -140,16 +140,18 @@ void pc_memory_init(MemoryRegion *system_memory,
MemoryRegion **ram_memory);
qemu_irq *pc_allocate_cpu_irq(void);
DeviceState *pc_vga_init(PCIBus *pci_bus);
-void pc_basic_device_init(qemu_irq *gsi,
+void pc_basic_device_init(DeviceState *board,
+ DeviceState *superio,
+ qemu_irq *gsi,
ISADevice **rtc_state,
ISADevice **floppy,
bool no_vmport);
-void pc_init_ne2k_isa(NICInfo *nd);
+DeviceState *pc_init_ne2k_isa(NICInfo *nd);
void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
const char *boot_device,
ISADevice *floppy, BusState *ide0, BusState *ide1,
ISADevice *s);
-void pc_pci_device_init(PCIBus *pci_bus);
+void pc_pci_device_init(PCIBus *pci_bus, DeviceState *board);
typedef void (*cpu_set_smm_t)(int smm, void *arg);
void cpu_smm_register(cpu_set_smm_t callback, void *arg);
@@ -164,9 +166,9 @@ int acpi_table_add(const char *table_desc);
/* acpi_piix.c */
-i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
- qemu_irq sci_irq, qemu_irq cmos_s3, qemu_irq smi_irq,
- int kvm_enabled);
+i2c_bus *piix4_pm_init(PCIBus *bus, DeviceState **pdev, int devfn,
+ uint32_t smb_io_base, qemu_irq sci_irq,
+ qemu_irq cmos_s3, qemu_irq smi_irq, int kvm_enabled);
void piix4_smbus_register_device(SMBusDevice *dev, uint8_t addr);
/* hpet.c */
@@ -181,6 +183,7 @@ struct PCII440FXState;
typedef struct PCII440FXState PCII440FXState;
PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix_devfn,
+ DeviceState **i440fx, DeviceState **piix3,
qemu_irq *pic,
MemoryRegion *address_space_mem,
MemoryRegion *address_space_io,
@@ -227,7 +230,7 @@ DeviceState *pci_cirrus_vga_init(PCIBus *bus);
DeviceState *isa_cirrus_vga_init(MemoryRegion *address_space);
/* ne2000.c */
-static inline bool isa_ne2000_init(int base, int irq, NICInfo *nd)
+static inline DeviceState *isa_ne2000_init(int base, int irq, NICInfo *nd)
{
ISADevice *dev;
@@ -235,13 +238,13 @@ static inline bool isa_ne2000_init(int base, int irq, NICInfo *nd)
dev = isa_try_create("ne2k_isa");
if (!dev) {
- return false;
+ return NULL;
}
qdev_prop_set_uint32(&dev->qdev, "iobase", base);
qdev_prop_set_uint32(&dev->qdev, "irq", irq);
qdev_set_nic_properties(&dev->qdev, nd);
qdev_init_nofail(&dev->qdev);
- return true;
+ return &dev->qdev;
}
/* e820 types */
diff --git a/hw/pc_piix.c b/hw/pc_piix.c
index 166c2fc..e4e2c26 100644
--- a/hw/pc_piix.c
+++ b/hw/pc_piix.c
@@ -53,7 +53,7 @@ static const int ide_iobase[MAX_IDE_BUS] = { 0x1f0, 0x170 };
static const int ide_iobase2[MAX_IDE_BUS] = { 0x3f6, 0x376 };
static const int ide_irq[MAX_IDE_BUS] = { 14, 15 };
-static void ioapic_init(GSIState *gsi_state)
+static DeviceState *ioapic_init(GSIState *gsi_state)
{
DeviceState *dev;
SysBusDevice *d;
@@ -67,6 +67,8 @@ static void ioapic_init(GSIState *gsi_state)
for (i = 0; i < IOAPIC_NUM_PINS; i++) {
gsi_state->ioapic_irq[i] = qdev_get_gpio_in(dev, i);
}
+
+ return dev;
}
/* PC hardware initialisation */
@@ -99,12 +101,18 @@ static void pc_init1(MemoryRegion *system_memory,
MemoryRegion *ram_memory;
MemoryRegion *pci_memory;
MemoryRegion *rom_memory;
+ DeviceState *superio = NULL;
+ DeviceState *board;
DeviceState *dev;
+ board = qdev_create(NULL, "container");
+ qdev_property_add_child(qdev_get_root(), "pc", board, NULL);
+
pc_cpus_init(cpu_model);
if (kvmclock_enabled) {
- kvmclock_create();
+ dev = kvmclock_create();
+ qdev_property_add_child(board, "kvmclock", dev, NULL);
}
if (ram_size >= 0xe0000000 ) {
@@ -136,7 +144,10 @@ static void pc_init1(MemoryRegion *system_memory,
gsi = qemu_allocate_irqs(gsi_handler, gsi_state, GSI_NUM_PINS);
if (pci_enabled) {
- pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, gsi,
+ DeviceState *i440fx, *piix3;
+
+ pci_bus = i440fx_init(&i440fx_state, &piix3_devfn,
+ &i440fx, &piix3, gsi,
system_memory, system_io, ram_size,
below_4g_mem_size,
0x100000000ULL - below_4g_mem_size,
@@ -145,6 +156,9 @@ static void pc_init1(MemoryRegion *system_memory,
? 0
: ((uint64_t)1 << 62)),
pci_memory, ram_memory);
+
+ qdev_property_add_child(board, "host-controller", i440fx, NULL);
+ superio = piix3;
} else {
pci_bus = NULL;
i440fx_state = NULL;
@@ -164,30 +178,39 @@ static void pc_init1(MemoryRegion *system_memory,
gsi_state->i8259_irq[i] = i8259[i];
}
if (pci_enabled) {
- ioapic_init(gsi_state);
+ dev = ioapic_init(gsi_state);
+ qdev_property_add_child(board, "ioapic", dev, NULL);
}
pc_register_ferr_irq(gsi[13]);
dev = pc_vga_init(pci_enabled? pci_bus: NULL);
if (dev) {
- qdev_property_add_child(qdev_get_root(), "vga", dev, NULL);
+ qdev_property_add_child(board, "vga", dev, NULL);
}
if (xen_enabled()) {
- pci_create_simple(pci_bus, -1, "xen-platform");
+ dev = &pci_create_simple(pci_bus, -1, "xen-platform")->qdev;
+ qdev_property_add_child(board, "xen", dev, NULL);
}
/* init basic PC hardware */
- pc_basic_device_init(gsi, &rtc_state, &floppy, xen_enabled());
+ pc_basic_device_init(board, superio, gsi, &rtc_state,
+ &floppy, xen_enabled());
for(i = 0; i < nb_nics; i++) {
NICInfo *nd = &nd_table[i];
+ DeviceState *dev;
+ char buffer[32];
- if (!pci_enabled || (nd->model && strcmp(nd->model, "ne2k_isa") == 0))
- pc_init_ne2k_isa(nd);
- else
- pci_nic_init_nofail(nd, "e1000", NULL);
+ if (!pci_enabled || (nd->model && strcmp(nd->model, "ne2k_isa") == 0)) {
+ dev = pc_init_ne2k_isa(nd);
+ } else {
+ dev = &pci_nic_init_nofail(nd, "e1000", NULL)->qdev;
+ }
+
+ snprintf(buffer, sizeof(buffer), "nic[%d]", i);
+ qdev_property_add_child(board, buffer, dev, NULL);
}
ide_drive_get(hd, MAX_IDE_BUS);
@@ -200,33 +223,27 @@ static void pc_init1(MemoryRegion *system_memory,
}
idebus[0] = qdev_get_child_bus(&dev->qdev, "ide.0");
idebus[1] = qdev_get_child_bus(&dev->qdev, "ide.1");
+ qdev_property_add_child(board, "ide", &dev->qdev, NULL);
} else {
for(i = 0; i < MAX_IDE_BUS; i++) {
ISADevice *dev;
+ char buffer[32];
dev = isa_ide_init(ide_iobase[i], ide_iobase2[i], ide_irq[i],
hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]);
idebus[i] = qdev_get_child_bus(&dev->qdev, "ide.0");
+ snprintf(buffer, sizeof(buffer), "ide[%d]", i);
+ qdev_property_add_child(board, buffer, &dev->qdev, NULL);
}
}
- /* FIXME there's some major spaghetti here. Somehow we create the devices
- * on the PIIX before we actually create it. We create the PIIX3 deep in
- * the recess of the i440fx creation too and then lose the DeviceState.
- *
- * For now, let's "fix" this by making judicious use of paths. This is not
- * generally the right way to do this.
- */
-
- qdev_property_add_child(qdev_resolve_path("/i440fx/piix3", NULL),
- "rtc", (DeviceState *)rtc_state, NULL);
-
audio_init(gsi, pci_enabled ? pci_bus : NULL);
pc_cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device,
floppy, idebus[0], idebus[1], rtc_state);
if (pci_enabled && usb_enabled) {
- usb_uhci_piix3_init(pci_bus, piix3_devfn + 2);
+ dev = usb_uhci_piix3_init(pci_bus, piix3_devfn + 2);
+ qdev_property_add_child(board, "usb-host", dev, NULL);
}
if (pci_enabled && acpi_enabled) {
@@ -239,14 +256,15 @@ static void pc_init1(MemoryRegion *system_memory,
}
smi_irq = qemu_allocate_irqs(pc_acpi_smi_interrupt, first_cpu, 1);
/* TODO: Populate SPD eeprom data. */
- smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
+ smbus = piix4_pm_init(pci_bus, &dev, piix3_devfn + 3, 0xb100,
gsi[9], *cmos_s3, *smi_irq,
kvm_enabled());
+ qdev_property_add_child(superio, "pm", dev, NULL);
smbus_eeprom_init(smbus, 8, NULL, 0);
}
if (pci_enabled) {
- pc_pci_device_init(pci_bus);
+ pc_pci_device_init(pci_bus, board);
}
}
diff --git a/hw/piix_pci.c b/hw/piix_pci.c
index d785d4b..e690ee1 100644
--- a/hw/piix_pci.c
+++ b/hw/piix_pci.c
@@ -262,6 +262,7 @@ static int i440fx_initfn(PCIDevice *dev)
static PCIBus *i440fx_common_init(const char *device_name,
PCII440FXState **pi440fx_state,
+ DeviceState **i440fx,
int *piix3_devfn,
qemu_irq *pic,
MemoryRegion *address_space_mem,
@@ -288,7 +289,7 @@ static PCIBus *i440fx_common_init(const char *device_name,
address_space_io, 0);
s->bus = b;
qdev_init_nofail(dev);
- qdev_property_add_child(qdev_get_root(), "i440fx", dev, NULL);
+ *i440fx = dev;
d = pci_create_simple(b, 0, device_name);
*pi440fx_state = DO_UPCAST(PCII440FXState, dev, d);
@@ -296,6 +297,9 @@ static PCIBus *i440fx_common_init(const char *device_name,
f->system_memory = address_space_mem;
f->pci_address_space = pci_address_space;
f->ram_memory = ram_memory;
+
+ qdev_property_add_child(dev, "i440fx", &d->qdev, NULL);
+
memory_region_init_alias(&f->pci_hole, "pci-hole", f->pci_address_space,
pci_hole_start, pci_hole_size);
memory_region_add_subregion(f->system_memory, pci_hole_start, &f->pci_hole);
@@ -325,7 +329,7 @@ static PCIBus *i440fx_common_init(const char *device_name,
pci_bus_irqs(b, piix3_set_irq, pci_slot_get_pirq, piix3,
PIIX_NUM_PIRQS);
- qdev_property_add_child(dev, "piix3", &piix3->dev.qdev, NULL);
+ qdev_property_add_child(&d->qdev, "piix3", &piix3->dev.qdev, NULL);
}
piix3->pic = pic;
@@ -344,6 +348,7 @@ static PCIBus *i440fx_common_init(const char *device_name,
}
PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix3_devfn,
+ DeviceState **i440fx, DeviceState **piix3,
qemu_irq *pic,
MemoryRegion *address_space_mem,
MemoryRegion *address_space_io,
@@ -357,11 +362,12 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix3_devfn,
{
PCIBus *b;
- b = i440fx_common_init("i440FX", pi440fx_state, piix3_devfn, pic,
+ b = i440fx_common_init("i440FX", pi440fx_state, i440fx, piix3_devfn, pic,
address_space_mem, address_space_io, ram_size,
pci_hole_start, pci_hole_size,
pci_hole64_size, pci_hole64_size,
pci_memory, ram_memory);
+ *piix3 = &(*pi440fx_state)->piix3->dev.qdev;
return b;
}
diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c
index f9e3ea5..3e4456a 100644
--- a/hw/usb-uhci.c
+++ b/hw/usb-uhci.c
@@ -1269,9 +1269,9 @@ static void uhci_register(void)
}
device_init(uhci_register);
-void usb_uhci_piix3_init(PCIBus *bus, int devfn)
+DeviceState *usb_uhci_piix3_init(PCIBus *bus, int devfn)
{
- pci_create_simple(bus, devfn, "piix3-usb-uhci");
+ return &pci_create_simple(bus, devfn, "piix3-usb-uhci")->qdev;
}
void usb_uhci_piix4_init(PCIBus *bus, int devfn)
diff --git a/hw/usb-uhci.h b/hw/usb-uhci.h
index 3e4d377..1fef610 100644
--- a/hw/usb-uhci.h
+++ b/hw/usb-uhci.h
@@ -3,7 +3,7 @@
#include "qemu-common.h"
-void usb_uhci_piix3_init(PCIBus *bus, int devfn);
+DeviceState *usb_uhci_piix3_init(PCIBus *bus, int devfn);
void usb_uhci_piix4_init(PCIBus *bus, int devfn);
void usb_uhci_vt82c686b_init(PCIBus *bus, int devfn);
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 024/197] i440fx: split out piix3 device
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (22 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 023/197] pc: fill out most of the composition tree Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 025/197] i440fx: rename piix_pci -> i440fx Anthony Liguori
` (42 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
Makefile.objs | 3 +
Makefile.target | 2 +-
hw/piix3.c | 181 ++++++++++++++++++++++++++++++++++++++++++
hw/piix3.h | 37 +++++++++
hw/piix_pci.c | 236 +++++--------------------------------------------------
5 files changed, 242 insertions(+), 217 deletions(-)
create mode 100644 hw/piix3.c
create mode 100644 hw/piix3.h
diff --git a/Makefile.objs b/Makefile.objs
index 10e794c..bdc0e42 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -293,6 +293,9 @@ hw-obj-$(CONFIG_DP8393X) += dp8393x.o
hw-obj-$(CONFIG_DS1225Y) += ds1225y.o
hw-obj-$(CONFIG_MIPSNET) += mipsnet.o
+# HW
+hw-obj-y += piix_pci.o piix3.o
+
# Sound
sound-obj-y =
sound-obj-$(CONFIG_SB16) += sb16.o
diff --git a/Makefile.target b/Makefile.target
index a111521..7f9cd30 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -231,7 +231,7 @@ obj-$(CONFIG_IVSHMEM) += ivshmem.o
# Hardware support
obj-i386-y += vga.o
obj-i386-y += mc146818rtc.o pc.o
-obj-i386-y += cirrus_vga.o sga.o apic.o ioapic.o piix_pci.o
+obj-i386-y += cirrus_vga.o sga.o apic.o ioapic.o
obj-i386-y += vmport.o
obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o
obj-i386-y += debugcon.o multiboot.o
diff --git a/hw/piix3.c b/hw/piix3.c
new file mode 100644
index 0000000..8a07259
--- /dev/null
+++ b/hw/piix3.c
@@ -0,0 +1,181 @@
+#include "piix3.h"
+#include "range.h"
+#include "xen.h"
+
+/* PIIX3 PCI to ISA bridge */
+static void piix3_set_irq_pic(PIIX3State *piix3, int pic_irq)
+{
+ qemu_set_irq(piix3->pic[pic_irq],
+ !!(piix3->pic_levels &
+ (((1ULL << PIIX_NUM_PIRQS) - 1) <<
+ (pic_irq * PIIX_NUM_PIRQS))));
+}
+
+void piix3_set_irq_level(PIIX3State *piix3, int pirq, int level)
+{
+ int pic_irq;
+ uint64_t mask;
+
+ pic_irq = piix3->dev.config[PIIX_PIRQC + pirq];
+ if (pic_irq >= PIIX_NUM_PIC_IRQS) {
+ return;
+ }
+
+ mask = 1ULL << ((pic_irq * PIIX_NUM_PIRQS) + pirq);
+ piix3->pic_levels &= ~mask;
+ piix3->pic_levels |= mask * !!level;
+
+ piix3_set_irq_pic(piix3, pic_irq);
+}
+
+/* irq routing is changed. so rebuild bitmap */
+static void piix3_update_irq_levels(PIIX3State *piix3)
+{
+ int pirq;
+
+ piix3->pic_levels = 0;
+ for (pirq = 0; pirq < PIIX_NUM_PIRQS; pirq++) {
+ piix3_set_irq_level(piix3, pirq,
+ pci_bus_get_irq_level(piix3->dev.bus, pirq));
+ }
+}
+
+static void piix3_write_config(PCIDevice *dev,
+ uint32_t address, uint32_t val, int len)
+{
+ pci_default_write_config(dev, address, val, len);
+ if (ranges_overlap(address, len, PIIX_PIRQC, 4)) {
+ PIIX3State *piix3 = DO_UPCAST(PIIX3State, dev, dev);
+ int pic_irq;
+ piix3_update_irq_levels(piix3);
+ for (pic_irq = 0; pic_irq < PIIX_NUM_PIC_IRQS; pic_irq++) {
+ piix3_set_irq_pic(piix3, pic_irq);
+ }
+ }
+}
+
+static void piix3_write_config_xen(PCIDevice *dev,
+ uint32_t address, uint32_t val, int len)
+{
+ xen_piix_pci_write_config_client(address, val, len);
+ piix3_write_config(dev, address, val, len);
+}
+
+static void piix3_reset(void *opaque)
+{
+ PIIX3State *d = opaque;
+ uint8_t *pci_conf = d->dev.config;
+
+ pci_conf[0x04] = 0x07; // master, memory and I/O
+ pci_conf[0x05] = 0x00;
+ pci_conf[0x06] = 0x00;
+ pci_conf[0x07] = 0x02; // PCI_status_devsel_medium
+ pci_conf[0x4c] = 0x4d;
+ pci_conf[0x4e] = 0x03;
+ pci_conf[0x4f] = 0x00;
+ pci_conf[0x60] = 0x80;
+ pci_conf[0x61] = 0x80;
+ pci_conf[0x62] = 0x80;
+ pci_conf[0x63] = 0x80;
+ pci_conf[0x69] = 0x02;
+ pci_conf[0x70] = 0x80;
+ pci_conf[0x76] = 0x0c;
+ pci_conf[0x77] = 0x0c;
+ pci_conf[0x78] = 0x02;
+ pci_conf[0x79] = 0x00;
+ pci_conf[0x80] = 0x00;
+ pci_conf[0x82] = 0x00;
+ pci_conf[0xa0] = 0x08;
+ pci_conf[0xa2] = 0x00;
+ pci_conf[0xa3] = 0x00;
+ pci_conf[0xa4] = 0x00;
+ pci_conf[0xa5] = 0x00;
+ pci_conf[0xa6] = 0x00;
+ pci_conf[0xa7] = 0x00;
+ pci_conf[0xa8] = 0x0f;
+ pci_conf[0xaa] = 0x00;
+ pci_conf[0xab] = 0x00;
+ pci_conf[0xac] = 0x00;
+ pci_conf[0xae] = 0x00;
+
+ d->pic_levels = 0;
+}
+
+static int piix3_post_load(void *opaque, int version_id)
+{
+ PIIX3State *piix3 = opaque;
+ piix3_update_irq_levels(piix3);
+ return 0;
+}
+
+static void piix3_pre_save(void *opaque)
+{
+ int i;
+ PIIX3State *piix3 = opaque;
+
+ for (i = 0; i < ARRAY_SIZE(piix3->pci_irq_levels_vmstate); i++) {
+ piix3->pci_irq_levels_vmstate[i] =
+ pci_bus_get_irq_level(piix3->dev.bus, i);
+ }
+}
+
+static const VMStateDescription vmstate_piix3 = {
+ .name = "PIIX3",
+ .version_id = 3,
+ .minimum_version_id = 2,
+ .minimum_version_id_old = 2,
+ .post_load = piix3_post_load,
+ .pre_save = piix3_pre_save,
+ .fields = (VMStateField []) {
+ VMSTATE_PCI_DEVICE(dev, PIIX3State),
+ VMSTATE_INT32_ARRAY_V(pci_irq_levels_vmstate, PIIX3State,
+ PIIX_NUM_PIRQS, 3),
+ VMSTATE_END_OF_LIST()
+ }
+};
+
+static int piix3_initfn(PCIDevice *dev)
+{
+ PIIX3State *d = DO_UPCAST(PIIX3State, dev, dev);
+
+ isa_bus_new(&d->dev.qdev, pci_address_space_io(dev));
+ qemu_register_reset(piix3_reset, d);
+ return 0;
+}
+
+static PCIDeviceInfo piix3_info[] = {
+ {
+ .qdev.name = "PIIX3",
+ .qdev.desc = "ISA bridge",
+ .qdev.size = sizeof(PIIX3State),
+ .qdev.vmsd = &vmstate_piix3,
+ .qdev.no_user = 1,
+ .no_hotplug = 1,
+ .init = piix3_initfn,
+ .config_write = piix3_write_config,
+ .vendor_id = PCI_VENDOR_ID_INTEL,
+ .device_id = PCI_DEVICE_ID_INTEL_82371SB_0, // 82371SB PIIX3 PCI-to-ISA bridge (Step A1)
+ .class_id = PCI_CLASS_BRIDGE_ISA,
+ },{
+ .qdev.name = "PIIX3-xen",
+ .qdev.desc = "ISA bridge",
+ .qdev.size = sizeof(PIIX3State),
+ .qdev.vmsd = &vmstate_piix3,
+ .qdev.no_user = 1,
+ .no_hotplug = 1,
+ .init = piix3_initfn,
+ .config_write = piix3_write_config_xen,
+ .vendor_id = PCI_VENDOR_ID_INTEL,
+ .device_id = PCI_DEVICE_ID_INTEL_82371SB_0, // 82371SB PIIX3 PCI-to-ISA bridge (Step A1)
+ .class_id = PCI_CLASS_BRIDGE_ISA,
+ },{
+ /* end of list */
+ }
+};
+
+static void piix3_register(void)
+{
+ pci_qdev_register_many(piix3_info);
+}
+
+device_init(piix3_register);
diff --git a/hw/piix3.h b/hw/piix3.h
new file mode 100644
index 0000000..73d4a6f
--- /dev/null
+++ b/hw/piix3.h
@@ -0,0 +1,37 @@
+#ifndef QEMU_PIIX3_H
+#define QEMU_PIIX3_H
+
+#include "hw/hw.h"
+#include "hw/pci.h"
+
+#define PIIX_NUM_PIC_IRQS 16 /* i8259 * 2 */
+#define PIIX_NUM_PIRQS 4ULL /* PIRQ[A-D] */
+#define XEN_PIIX_NUM_PIRQS 128ULL
+#define PIIX_PIRQC 0x60
+
+typedef struct PIIX3State {
+ PCIDevice dev;
+
+ /*
+ * bitmap to track pic levels.
+ * The pic level is the logical OR of all the PCI irqs mapped to it
+ * So one PIC level is tracked by PIIX_NUM_PIRQS bits.
+ *
+ * PIRQ is mapped to PIC pins, we track it by
+ * PIIX_NUM_PIRQS * PIIX_NUM_PIC_IRQS = 64 bits with
+ * pic_irq * PIIX_NUM_PIRQS + pirq
+ */
+#if PIIX_NUM_PIC_IRQS * PIIX_NUM_PIRQS > 64
+#error "unable to encode pic state in 64bit in pic_levels."
+#endif
+ uint64_t pic_levels;
+
+ qemu_irq *pic;
+
+ /* This member isn't used. Just for save/load compatibility */
+ int32_t pci_irq_levels_vmstate[PIIX_NUM_PIRQS];
+} PIIX3State;
+
+void piix3_set_irq_level(PIIX3State *piix3, int pirq, int level);
+
+#endif
diff --git a/hw/piix_pci.c b/hw/piix_pci.c
index e690ee1..e0600dd 100644
--- a/hw/piix_pci.c
+++ b/hw/piix_pci.c
@@ -30,6 +30,7 @@
#include "sysbus.h"
#include "range.h"
#include "xen.h"
+#include "piix3.h"
/*
* I440FX chipset data sheet.
@@ -38,34 +39,6 @@
typedef PCIHostState I440FXState;
-#define PIIX_NUM_PIC_IRQS 16 /* i8259 * 2 */
-#define PIIX_NUM_PIRQS 4ULL /* PIRQ[A-D] */
-#define XEN_PIIX_NUM_PIRQS 128ULL
-#define PIIX_PIRQC 0x60
-
-typedef struct PIIX3State {
- PCIDevice dev;
-
- /*
- * bitmap to track pic levels.
- * The pic level is the logical OR of all the PCI irqs mapped to it
- * So one PIC level is tracked by PIIX_NUM_PIRQS bits.
- *
- * PIRQ is mapped to PIC pins, we track it by
- * PIIX_NUM_PIRQS * PIIX_NUM_PIC_IRQS = 64 bits with
- * pic_irq * PIIX_NUM_PIRQS + pirq
- */
-#if PIIX_NUM_PIC_IRQS * PIIX_NUM_PIRQS > 64
-#error "unable to encode pic state in 64bit in pic_levels."
-#endif
- uint64_t pic_levels;
-
- qemu_irq *pic;
-
- /* This member isn't used. Just for save/load compatibility */
- int32_t pci_irq_levels_vmstate[PIIX_NUM_PIRQS];
-} PIIX3State;
-
typedef struct PAMMemoryRegion {
MemoryRegion mem;
bool initialized;
@@ -85,25 +58,10 @@ struct PCII440FXState {
PIIX3State *piix3;
};
-
#define I440FX_PAM 0x59
#define I440FX_PAM_SIZE 7
#define I440FX_SMRAM 0x72
-static void piix3_set_irq(void *opaque, int pirq, int level);
-static void piix3_write_config_xen(PCIDevice *dev,
- uint32_t address, uint32_t val, int len);
-
-/* return the global irq number corresponding to a given device irq
- pin. We could also use the bus number to have a more precise
- mapping. */
-static int pci_slot_get_pirq(PCIDevice *pci_dev, int pci_intx)
-{
- int slot_addend;
- slot_addend = (pci_dev->devfn >> 3) - 1;
- return (pci_intx + slot_addend) & 3;
-}
-
static void update_pam(PCII440FXState *d, uint32_t start, uint32_t end, int r,
PAMMemoryRegion *mem)
{
@@ -260,6 +218,22 @@ static int i440fx_initfn(PCIDevice *dev)
return 0;
}
+/* return the global irq number corresponding to a given device irq
+ pin. We could also use the bus number to have a more precise
+ mapping. */
+static int pci_slot_get_pirq(PCIDevice *pci_dev, int pci_intx)
+{
+ int slot_addend;
+ slot_addend = (pci_dev->devfn >> 3) - 1;
+ return (pci_intx + slot_addend) & 3;
+}
+
+static void piix3_set_irq(void *opaque, int pirq, int level)
+{
+ PIIX3State *piix3 = opaque;
+ piix3_set_irq_level(piix3, pirq, level);
+}
+
static PCIBus *i440fx_common_init(const char *device_name,
PCII440FXState **pi440fx_state,
DeviceState **i440fx,
@@ -322,12 +296,12 @@ static PCIBus *i440fx_common_init(const char *device_name,
piix3 = DO_UPCAST(PIIX3State, dev,
pci_create_simple_multifunction(b, -1, true, "PIIX3-xen"));
pci_bus_irqs(b, xen_piix3_set_irq, xen_pci_slot_get_pirq,
- piix3, XEN_PIIX_NUM_PIRQS);
+ piix3, XEN_PIIX_NUM_PIRQS);
} else {
piix3 = DO_UPCAST(PIIX3State, dev,
pci_create_simple_multifunction(b, -1, true, "PIIX3"));
pci_bus_irqs(b, piix3_set_irq, pci_slot_get_pirq, piix3,
- PIIX_NUM_PIRQS);
+ PIIX_NUM_PIRQS);
qdev_property_add_child(&d->qdev, "piix3", &piix3->dev.qdev, NULL);
}
@@ -371,153 +345,6 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix3_devfn,
return b;
}
-/* PIIX3 PCI to ISA bridge */
-static void piix3_set_irq_pic(PIIX3State *piix3, int pic_irq)
-{
- qemu_set_irq(piix3->pic[pic_irq],
- !!(piix3->pic_levels &
- (((1ULL << PIIX_NUM_PIRQS) - 1) <<
- (pic_irq * PIIX_NUM_PIRQS))));
-}
-
-static void piix3_set_irq_level(PIIX3State *piix3, int pirq, int level)
-{
- int pic_irq;
- uint64_t mask;
-
- pic_irq = piix3->dev.config[PIIX_PIRQC + pirq];
- if (pic_irq >= PIIX_NUM_PIC_IRQS) {
- return;
- }
-
- mask = 1ULL << ((pic_irq * PIIX_NUM_PIRQS) + pirq);
- piix3->pic_levels &= ~mask;
- piix3->pic_levels |= mask * !!level;
-
- piix3_set_irq_pic(piix3, pic_irq);
-}
-
-static void piix3_set_irq(void *opaque, int pirq, int level)
-{
- PIIX3State *piix3 = opaque;
- piix3_set_irq_level(piix3, pirq, level);
-}
-
-/* irq routing is changed. so rebuild bitmap */
-static void piix3_update_irq_levels(PIIX3State *piix3)
-{
- int pirq;
-
- piix3->pic_levels = 0;
- for (pirq = 0; pirq < PIIX_NUM_PIRQS; pirq++) {
- piix3_set_irq_level(piix3, pirq,
- pci_bus_get_irq_level(piix3->dev.bus, pirq));
- }
-}
-
-static void piix3_write_config(PCIDevice *dev,
- uint32_t address, uint32_t val, int len)
-{
- pci_default_write_config(dev, address, val, len);
- if (ranges_overlap(address, len, PIIX_PIRQC, 4)) {
- PIIX3State *piix3 = DO_UPCAST(PIIX3State, dev, dev);
- int pic_irq;
- piix3_update_irq_levels(piix3);
- for (pic_irq = 0; pic_irq < PIIX_NUM_PIC_IRQS; pic_irq++) {
- piix3_set_irq_pic(piix3, pic_irq);
- }
- }
-}
-
-static void piix3_write_config_xen(PCIDevice *dev,
- uint32_t address, uint32_t val, int len)
-{
- xen_piix_pci_write_config_client(address, val, len);
- piix3_write_config(dev, address, val, len);
-}
-
-static void piix3_reset(void *opaque)
-{
- PIIX3State *d = opaque;
- uint8_t *pci_conf = d->dev.config;
-
- pci_conf[0x04] = 0x07; // master, memory and I/O
- pci_conf[0x05] = 0x00;
- pci_conf[0x06] = 0x00;
- pci_conf[0x07] = 0x02; // PCI_status_devsel_medium
- pci_conf[0x4c] = 0x4d;
- pci_conf[0x4e] = 0x03;
- pci_conf[0x4f] = 0x00;
- pci_conf[0x60] = 0x80;
- pci_conf[0x61] = 0x80;
- pci_conf[0x62] = 0x80;
- pci_conf[0x63] = 0x80;
- pci_conf[0x69] = 0x02;
- pci_conf[0x70] = 0x80;
- pci_conf[0x76] = 0x0c;
- pci_conf[0x77] = 0x0c;
- pci_conf[0x78] = 0x02;
- pci_conf[0x79] = 0x00;
- pci_conf[0x80] = 0x00;
- pci_conf[0x82] = 0x00;
- pci_conf[0xa0] = 0x08;
- pci_conf[0xa2] = 0x00;
- pci_conf[0xa3] = 0x00;
- pci_conf[0xa4] = 0x00;
- pci_conf[0xa5] = 0x00;
- pci_conf[0xa6] = 0x00;
- pci_conf[0xa7] = 0x00;
- pci_conf[0xa8] = 0x0f;
- pci_conf[0xaa] = 0x00;
- pci_conf[0xab] = 0x00;
- pci_conf[0xac] = 0x00;
- pci_conf[0xae] = 0x00;
-
- d->pic_levels = 0;
-}
-
-static int piix3_post_load(void *opaque, int version_id)
-{
- PIIX3State *piix3 = opaque;
- piix3_update_irq_levels(piix3);
- return 0;
-}
-
-static void piix3_pre_save(void *opaque)
-{
- int i;
- PIIX3State *piix3 = opaque;
-
- for (i = 0; i < ARRAY_SIZE(piix3->pci_irq_levels_vmstate); i++) {
- piix3->pci_irq_levels_vmstate[i] =
- pci_bus_get_irq_level(piix3->dev.bus, i);
- }
-}
-
-static const VMStateDescription vmstate_piix3 = {
- .name = "PIIX3",
- .version_id = 3,
- .minimum_version_id = 2,
- .minimum_version_id_old = 2,
- .post_load = piix3_post_load,
- .pre_save = piix3_pre_save,
- .fields = (VMStateField []) {
- VMSTATE_PCI_DEVICE(dev, PIIX3State),
- VMSTATE_INT32_ARRAY_V(pci_irq_levels_vmstate, PIIX3State,
- PIIX_NUM_PIRQS, 3),
- VMSTATE_END_OF_LIST()
- }
-};
-
-static int piix3_initfn(PCIDevice *dev)
-{
- PIIX3State *d = DO_UPCAST(PIIX3State, dev, dev);
-
- isa_bus_new(&d->dev.qdev, pci_address_space_io(dev));
- qemu_register_reset(piix3_reset, d);
- return 0;
-}
-
static PCIDeviceInfo i440fx_info[] = {
{
.qdev.name = "i440FX",
@@ -533,30 +360,6 @@ static PCIDeviceInfo i440fx_info[] = {
.revision = 0x02,
.class_id = PCI_CLASS_BRIDGE_HOST,
},{
- .qdev.name = "PIIX3",
- .qdev.desc = "ISA bridge",
- .qdev.size = sizeof(PIIX3State),
- .qdev.vmsd = &vmstate_piix3,
- .qdev.no_user = 1,
- .no_hotplug = 1,
- .init = piix3_initfn,
- .config_write = piix3_write_config,
- .vendor_id = PCI_VENDOR_ID_INTEL,
- .device_id = PCI_DEVICE_ID_INTEL_82371SB_0, // 82371SB PIIX3 PCI-to-ISA bridge (Step A1)
- .class_id = PCI_CLASS_BRIDGE_ISA,
- },{
- .qdev.name = "PIIX3-xen",
- .qdev.desc = "ISA bridge",
- .qdev.size = sizeof(PIIX3State),
- .qdev.vmsd = &vmstate_piix3,
- .qdev.no_user = 1,
- .no_hotplug = 1,
- .init = piix3_initfn,
- .config_write = piix3_write_config_xen,
- .vendor_id = PCI_VENDOR_ID_INTEL,
- .device_id = PCI_DEVICE_ID_INTEL_82371SB_0, // 82371SB PIIX3 PCI-to-ISA bridge (Step A1)
- .class_id = PCI_CLASS_BRIDGE_ISA,
- },{
/* end of list */
}
};
@@ -574,4 +377,5 @@ static void i440fx_register(void)
sysbus_register_withprop(&i440fx_pcihost_info);
pci_qdev_register_many(i440fx_info);
}
+
device_init(i440fx_register);
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 025/197] i440fx: rename piix_pci -> i440fx
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (23 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 024/197] i440fx: split out piix3 device Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 026/197] qom: add qobject Anthony Liguori
` (41 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
Makefile.objs | 2 +-
hw/i440fx.c | 381 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
hw/piix_pci.c | 381 ---------------------------------------------------------
3 files changed, 382 insertions(+), 382 deletions(-)
create mode 100644 hw/i440fx.c
delete mode 100644 hw/piix_pci.c
diff --git a/Makefile.objs b/Makefile.objs
index bdc0e42..67e1ae5 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -294,7 +294,7 @@ hw-obj-$(CONFIG_DS1225Y) += ds1225y.o
hw-obj-$(CONFIG_MIPSNET) += mipsnet.o
# HW
-hw-obj-y += piix_pci.o piix3.o
+hw-obj-y += i440fx.o piix3.o
# Sound
sound-obj-y =
diff --git a/hw/i440fx.c b/hw/i440fx.c
new file mode 100644
index 0000000..e0600dd
--- /dev/null
+++ b/hw/i440fx.c
@@ -0,0 +1,381 @@
+/*
+ * QEMU i440FX/PIIX3 PCI Bridge Emulation
+ *
+ * Copyright (c) 2006 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "hw.h"
+#include "pc.h"
+#include "pci.h"
+#include "pci_host.h"
+#include "isa.h"
+#include "sysbus.h"
+#include "range.h"
+#include "xen.h"
+#include "piix3.h"
+
+/*
+ * I440FX chipset data sheet.
+ * http://download.intel.com/design/chipsets/datashts/29054901.pdf
+ */
+
+typedef PCIHostState I440FXState;
+
+typedef struct PAMMemoryRegion {
+ MemoryRegion mem;
+ bool initialized;
+} PAMMemoryRegion;
+
+struct PCII440FXState {
+ PCIDevice dev;
+ MemoryRegion *system_memory;
+ MemoryRegion *pci_address_space;
+ MemoryRegion *ram_memory;
+ MemoryRegion pci_hole;
+ MemoryRegion pci_hole_64bit;
+ PAMMemoryRegion pam_regions[13];
+ MemoryRegion smram_region;
+ uint8_t smm_enabled;
+ bool smram_enabled;
+ PIIX3State *piix3;
+};
+
+#define I440FX_PAM 0x59
+#define I440FX_PAM_SIZE 7
+#define I440FX_SMRAM 0x72
+
+static void update_pam(PCII440FXState *d, uint32_t start, uint32_t end, int r,
+ PAMMemoryRegion *mem)
+{
+ if (mem->initialized) {
+ memory_region_del_subregion(d->system_memory, &mem->mem);
+ memory_region_destroy(&mem->mem);
+ }
+
+ // printf("ISA mapping %08x-0x%08x: %d\n", start, end, r);
+ switch(r) {
+ case 3:
+ /* RAM */
+ memory_region_init_alias(&mem->mem, "pam-ram", d->ram_memory,
+ start, end - start);
+ break;
+ case 1:
+ /* ROM (XXX: not quite correct) */
+ memory_region_init_alias(&mem->mem, "pam-rom", d->ram_memory,
+ start, end - start);
+ memory_region_set_readonly(&mem->mem, true);
+ break;
+ case 2:
+ case 0:
+ /* XXX: should distinguish read/write cases */
+ memory_region_init_alias(&mem->mem, "pam-pci", d->pci_address_space,
+ start, end - start);
+ break;
+ }
+ memory_region_add_subregion_overlap(d->system_memory,
+ start, &mem->mem, 1);
+ mem->initialized = true;
+}
+
+static void i440fx_update_memory_mappings(PCII440FXState *d)
+{
+ int i, r;
+ uint32_t smram;
+
+ memory_region_transaction_begin();
+ update_pam(d, 0xf0000, 0x100000, (d->dev.config[I440FX_PAM] >> 4) & 3,
+ &d->pam_regions[0]);
+ for(i = 0; i < 12; i++) {
+ r = (d->dev.config[(i >> 1) + (I440FX_PAM + 1)] >> ((i & 1) * 4)) & 3;
+ update_pam(d, 0xc0000 + 0x4000 * i, 0xc0000 + 0x4000 * (i + 1), r,
+ &d->pam_regions[i+1]);
+ }
+ smram = d->dev.config[I440FX_SMRAM];
+ if ((d->smm_enabled && (smram & 0x08)) || (smram & 0x40)) {
+ if (!d->smram_enabled) {
+ memory_region_del_subregion(d->system_memory, &d->smram_region);
+ d->smram_enabled = true;
+ }
+ } else {
+ if (d->smram_enabled) {
+ memory_region_add_subregion_overlap(d->system_memory, 0xa0000,
+ &d->smram_region, 1);
+ d->smram_enabled = false;
+ }
+ }
+ memory_region_transaction_commit();
+}
+
+static void i440fx_set_smm(int val, void *arg)
+{
+ PCII440FXState *d = arg;
+
+ val = (val != 0);
+ if (d->smm_enabled != val) {
+ d->smm_enabled = val;
+ i440fx_update_memory_mappings(d);
+ }
+}
+
+
+static void i440fx_write_config(PCIDevice *dev,
+ uint32_t address, uint32_t val, int len)
+{
+ PCII440FXState *d = DO_UPCAST(PCII440FXState, dev, dev);
+
+ /* XXX: implement SMRAM.D_LOCK */
+ pci_default_write_config(dev, address, val, len);
+ if (ranges_overlap(address, len, I440FX_PAM, I440FX_PAM_SIZE) ||
+ range_covers_byte(address, len, I440FX_SMRAM)) {
+ i440fx_update_memory_mappings(d);
+ }
+}
+
+static int i440fx_load_old(QEMUFile* f, void *opaque, int version_id)
+{
+ PCII440FXState *d = opaque;
+ int ret, i;
+
+ ret = pci_device_load(&d->dev, f);
+ if (ret < 0)
+ return ret;
+ i440fx_update_memory_mappings(d);
+ qemu_get_8s(f, &d->smm_enabled);
+
+ if (version_id == 2) {
+ for (i = 0; i < PIIX_NUM_PIRQS; i++) {
+ qemu_get_be32(f); /* dummy load for compatibility */
+ }
+ }
+
+ return 0;
+}
+
+static int i440fx_post_load(void *opaque, int version_id)
+{
+ PCII440FXState *d = opaque;
+
+ i440fx_update_memory_mappings(d);
+ return 0;
+}
+
+static const VMStateDescription vmstate_i440fx = {
+ .name = "I440FX",
+ .version_id = 3,
+ .minimum_version_id = 3,
+ .minimum_version_id_old = 1,
+ .load_state_old = i440fx_load_old,
+ .post_load = i440fx_post_load,
+ .fields = (VMStateField []) {
+ VMSTATE_PCI_DEVICE(dev, PCII440FXState),
+ VMSTATE_UINT8(smm_enabled, PCII440FXState),
+ VMSTATE_END_OF_LIST()
+ }
+};
+
+static int i440fx_pcihost_initfn(SysBusDevice *dev)
+{
+ I440FXState *s = FROM_SYSBUS(I440FXState, dev);
+
+ memory_region_init_io(&s->conf_mem, &pci_host_conf_le_ops, s,
+ "pci-conf-idx", 4);
+ sysbus_add_io(dev, 0xcf8, &s->conf_mem);
+ sysbus_init_ioports(&s->busdev, 0xcf8, 4);
+
+ memory_region_init_io(&s->data_mem, &pci_host_data_le_ops, s,
+ "pci-conf-data", 4);
+ sysbus_add_io(dev, 0xcfc, &s->data_mem);
+ sysbus_init_ioports(&s->busdev, 0xcfc, 4);
+
+ return 0;
+}
+
+static int i440fx_initfn(PCIDevice *dev)
+{
+ PCII440FXState *d = DO_UPCAST(PCII440FXState, dev, dev);
+
+ d->dev.config[I440FX_SMRAM] = 0x02;
+
+ cpu_smm_register(&i440fx_set_smm, d);
+ return 0;
+}
+
+/* return the global irq number corresponding to a given device irq
+ pin. We could also use the bus number to have a more precise
+ mapping. */
+static int pci_slot_get_pirq(PCIDevice *pci_dev, int pci_intx)
+{
+ int slot_addend;
+ slot_addend = (pci_dev->devfn >> 3) - 1;
+ return (pci_intx + slot_addend) & 3;
+}
+
+static void piix3_set_irq(void *opaque, int pirq, int level)
+{
+ PIIX3State *piix3 = opaque;
+ piix3_set_irq_level(piix3, pirq, level);
+}
+
+static PCIBus *i440fx_common_init(const char *device_name,
+ PCII440FXState **pi440fx_state,
+ DeviceState **i440fx,
+ int *piix3_devfn,
+ qemu_irq *pic,
+ MemoryRegion *address_space_mem,
+ MemoryRegion *address_space_io,
+ ram_addr_t ram_size,
+ target_phys_addr_t pci_hole_start,
+ target_phys_addr_t pci_hole_size,
+ target_phys_addr_t pci_hole64_start,
+ target_phys_addr_t pci_hole64_size,
+ MemoryRegion *pci_address_space,
+ MemoryRegion *ram_memory)
+{
+ DeviceState *dev;
+ PCIBus *b;
+ PCIDevice *d;
+ I440FXState *s;
+ PIIX3State *piix3;
+ PCII440FXState *f;
+
+ dev = qdev_create(NULL, "i440FX-pcihost");
+ s = FROM_SYSBUS(I440FXState, sysbus_from_qdev(dev));
+ s->address_space = address_space_mem;
+ b = pci_bus_new(&s->busdev.qdev, NULL, pci_address_space,
+ address_space_io, 0);
+ s->bus = b;
+ qdev_init_nofail(dev);
+ *i440fx = dev;
+
+ d = pci_create_simple(b, 0, device_name);
+ *pi440fx_state = DO_UPCAST(PCII440FXState, dev, d);
+ f = *pi440fx_state;
+ f->system_memory = address_space_mem;
+ f->pci_address_space = pci_address_space;
+ f->ram_memory = ram_memory;
+
+ qdev_property_add_child(dev, "i440fx", &d->qdev, NULL);
+
+ memory_region_init_alias(&f->pci_hole, "pci-hole", f->pci_address_space,
+ pci_hole_start, pci_hole_size);
+ memory_region_add_subregion(f->system_memory, pci_hole_start, &f->pci_hole);
+ memory_region_init_alias(&f->pci_hole_64bit, "pci-hole64",
+ f->pci_address_space,
+ pci_hole64_start, pci_hole64_size);
+ if (pci_hole64_size) {
+ memory_region_add_subregion(f->system_memory, pci_hole64_start,
+ &f->pci_hole_64bit);
+ }
+ memory_region_init_alias(&f->smram_region, "smram-region",
+ f->pci_address_space, 0xa0000, 0x20000);
+ f->smram_enabled = true;
+
+ /* Xen supports additional interrupt routes from the PCI devices to
+ * the IOAPIC: the four pins of each PCI device on the bus are also
+ * connected to the IOAPIC directly.
+ * These additional routes can be discovered through ACPI. */
+ if (xen_enabled()) {
+ piix3 = DO_UPCAST(PIIX3State, dev,
+ pci_create_simple_multifunction(b, -1, true, "PIIX3-xen"));
+ pci_bus_irqs(b, xen_piix3_set_irq, xen_pci_slot_get_pirq,
+ piix3, XEN_PIIX_NUM_PIRQS);
+ } else {
+ piix3 = DO_UPCAST(PIIX3State, dev,
+ pci_create_simple_multifunction(b, -1, true, "PIIX3"));
+ pci_bus_irqs(b, piix3_set_irq, pci_slot_get_pirq, piix3,
+ PIIX_NUM_PIRQS);
+
+ qdev_property_add_child(&d->qdev, "piix3", &piix3->dev.qdev, NULL);
+ }
+ piix3->pic = pic;
+
+ (*pi440fx_state)->piix3 = piix3;
+
+ *piix3_devfn = piix3->dev.devfn;
+
+ ram_size = ram_size / 8 / 1024 / 1024;
+ if (ram_size > 255)
+ ram_size = 255;
+ (*pi440fx_state)->dev.config[0x57]=ram_size;
+
+ i440fx_update_memory_mappings(f);
+
+ return b;
+}
+
+PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix3_devfn,
+ DeviceState **i440fx, DeviceState **piix3,
+ qemu_irq *pic,
+ MemoryRegion *address_space_mem,
+ MemoryRegion *address_space_io,
+ ram_addr_t ram_size,
+ target_phys_addr_t pci_hole_start,
+ target_phys_addr_t pci_hole_size,
+ target_phys_addr_t pci_hole64_start,
+ target_phys_addr_t pci_hole64_size,
+ MemoryRegion *pci_memory, MemoryRegion *ram_memory)
+
+{
+ PCIBus *b;
+
+ b = i440fx_common_init("i440FX", pi440fx_state, i440fx, piix3_devfn, pic,
+ address_space_mem, address_space_io, ram_size,
+ pci_hole_start, pci_hole_size,
+ pci_hole64_size, pci_hole64_size,
+ pci_memory, ram_memory);
+ *piix3 = &(*pi440fx_state)->piix3->dev.qdev;
+ return b;
+}
+
+static PCIDeviceInfo i440fx_info[] = {
+ {
+ .qdev.name = "i440FX",
+ .qdev.desc = "Host bridge",
+ .qdev.size = sizeof(PCII440FXState),
+ .qdev.vmsd = &vmstate_i440fx,
+ .qdev.no_user = 1,
+ .no_hotplug = 1,
+ .init = i440fx_initfn,
+ .config_write = i440fx_write_config,
+ .vendor_id = PCI_VENDOR_ID_INTEL,
+ .device_id = PCI_DEVICE_ID_INTEL_82441,
+ .revision = 0x02,
+ .class_id = PCI_CLASS_BRIDGE_HOST,
+ },{
+ /* end of list */
+ }
+};
+
+static SysBusDeviceInfo i440fx_pcihost_info = {
+ .init = i440fx_pcihost_initfn,
+ .qdev.name = "i440FX-pcihost",
+ .qdev.fw_name = "pci",
+ .qdev.size = sizeof(I440FXState),
+ .qdev.no_user = 1,
+};
+
+static void i440fx_register(void)
+{
+ sysbus_register_withprop(&i440fx_pcihost_info);
+ pci_qdev_register_many(i440fx_info);
+}
+
+device_init(i440fx_register);
diff --git a/hw/piix_pci.c b/hw/piix_pci.c
deleted file mode 100644
index e0600dd..0000000
--- a/hw/piix_pci.c
+++ /dev/null
@@ -1,381 +0,0 @@
-/*
- * QEMU i440FX/PIIX3 PCI Bridge Emulation
- *
- * Copyright (c) 2006 Fabrice Bellard
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#include "hw.h"
-#include "pc.h"
-#include "pci.h"
-#include "pci_host.h"
-#include "isa.h"
-#include "sysbus.h"
-#include "range.h"
-#include "xen.h"
-#include "piix3.h"
-
-/*
- * I440FX chipset data sheet.
- * http://download.intel.com/design/chipsets/datashts/29054901.pdf
- */
-
-typedef PCIHostState I440FXState;
-
-typedef struct PAMMemoryRegion {
- MemoryRegion mem;
- bool initialized;
-} PAMMemoryRegion;
-
-struct PCII440FXState {
- PCIDevice dev;
- MemoryRegion *system_memory;
- MemoryRegion *pci_address_space;
- MemoryRegion *ram_memory;
- MemoryRegion pci_hole;
- MemoryRegion pci_hole_64bit;
- PAMMemoryRegion pam_regions[13];
- MemoryRegion smram_region;
- uint8_t smm_enabled;
- bool smram_enabled;
- PIIX3State *piix3;
-};
-
-#define I440FX_PAM 0x59
-#define I440FX_PAM_SIZE 7
-#define I440FX_SMRAM 0x72
-
-static void update_pam(PCII440FXState *d, uint32_t start, uint32_t end, int r,
- PAMMemoryRegion *mem)
-{
- if (mem->initialized) {
- memory_region_del_subregion(d->system_memory, &mem->mem);
- memory_region_destroy(&mem->mem);
- }
-
- // printf("ISA mapping %08x-0x%08x: %d\n", start, end, r);
- switch(r) {
- case 3:
- /* RAM */
- memory_region_init_alias(&mem->mem, "pam-ram", d->ram_memory,
- start, end - start);
- break;
- case 1:
- /* ROM (XXX: not quite correct) */
- memory_region_init_alias(&mem->mem, "pam-rom", d->ram_memory,
- start, end - start);
- memory_region_set_readonly(&mem->mem, true);
- break;
- case 2:
- case 0:
- /* XXX: should distinguish read/write cases */
- memory_region_init_alias(&mem->mem, "pam-pci", d->pci_address_space,
- start, end - start);
- break;
- }
- memory_region_add_subregion_overlap(d->system_memory,
- start, &mem->mem, 1);
- mem->initialized = true;
-}
-
-static void i440fx_update_memory_mappings(PCII440FXState *d)
-{
- int i, r;
- uint32_t smram;
-
- memory_region_transaction_begin();
- update_pam(d, 0xf0000, 0x100000, (d->dev.config[I440FX_PAM] >> 4) & 3,
- &d->pam_regions[0]);
- for(i = 0; i < 12; i++) {
- r = (d->dev.config[(i >> 1) + (I440FX_PAM + 1)] >> ((i & 1) * 4)) & 3;
- update_pam(d, 0xc0000 + 0x4000 * i, 0xc0000 + 0x4000 * (i + 1), r,
- &d->pam_regions[i+1]);
- }
- smram = d->dev.config[I440FX_SMRAM];
- if ((d->smm_enabled && (smram & 0x08)) || (smram & 0x40)) {
- if (!d->smram_enabled) {
- memory_region_del_subregion(d->system_memory, &d->smram_region);
- d->smram_enabled = true;
- }
- } else {
- if (d->smram_enabled) {
- memory_region_add_subregion_overlap(d->system_memory, 0xa0000,
- &d->smram_region, 1);
- d->smram_enabled = false;
- }
- }
- memory_region_transaction_commit();
-}
-
-static void i440fx_set_smm(int val, void *arg)
-{
- PCII440FXState *d = arg;
-
- val = (val != 0);
- if (d->smm_enabled != val) {
- d->smm_enabled = val;
- i440fx_update_memory_mappings(d);
- }
-}
-
-
-static void i440fx_write_config(PCIDevice *dev,
- uint32_t address, uint32_t val, int len)
-{
- PCII440FXState *d = DO_UPCAST(PCII440FXState, dev, dev);
-
- /* XXX: implement SMRAM.D_LOCK */
- pci_default_write_config(dev, address, val, len);
- if (ranges_overlap(address, len, I440FX_PAM, I440FX_PAM_SIZE) ||
- range_covers_byte(address, len, I440FX_SMRAM)) {
- i440fx_update_memory_mappings(d);
- }
-}
-
-static int i440fx_load_old(QEMUFile* f, void *opaque, int version_id)
-{
- PCII440FXState *d = opaque;
- int ret, i;
-
- ret = pci_device_load(&d->dev, f);
- if (ret < 0)
- return ret;
- i440fx_update_memory_mappings(d);
- qemu_get_8s(f, &d->smm_enabled);
-
- if (version_id == 2) {
- for (i = 0; i < PIIX_NUM_PIRQS; i++) {
- qemu_get_be32(f); /* dummy load for compatibility */
- }
- }
-
- return 0;
-}
-
-static int i440fx_post_load(void *opaque, int version_id)
-{
- PCII440FXState *d = opaque;
-
- i440fx_update_memory_mappings(d);
- return 0;
-}
-
-static const VMStateDescription vmstate_i440fx = {
- .name = "I440FX",
- .version_id = 3,
- .minimum_version_id = 3,
- .minimum_version_id_old = 1,
- .load_state_old = i440fx_load_old,
- .post_load = i440fx_post_load,
- .fields = (VMStateField []) {
- VMSTATE_PCI_DEVICE(dev, PCII440FXState),
- VMSTATE_UINT8(smm_enabled, PCII440FXState),
- VMSTATE_END_OF_LIST()
- }
-};
-
-static int i440fx_pcihost_initfn(SysBusDevice *dev)
-{
- I440FXState *s = FROM_SYSBUS(I440FXState, dev);
-
- memory_region_init_io(&s->conf_mem, &pci_host_conf_le_ops, s,
- "pci-conf-idx", 4);
- sysbus_add_io(dev, 0xcf8, &s->conf_mem);
- sysbus_init_ioports(&s->busdev, 0xcf8, 4);
-
- memory_region_init_io(&s->data_mem, &pci_host_data_le_ops, s,
- "pci-conf-data", 4);
- sysbus_add_io(dev, 0xcfc, &s->data_mem);
- sysbus_init_ioports(&s->busdev, 0xcfc, 4);
-
- return 0;
-}
-
-static int i440fx_initfn(PCIDevice *dev)
-{
- PCII440FXState *d = DO_UPCAST(PCII440FXState, dev, dev);
-
- d->dev.config[I440FX_SMRAM] = 0x02;
-
- cpu_smm_register(&i440fx_set_smm, d);
- return 0;
-}
-
-/* return the global irq number corresponding to a given device irq
- pin. We could also use the bus number to have a more precise
- mapping. */
-static int pci_slot_get_pirq(PCIDevice *pci_dev, int pci_intx)
-{
- int slot_addend;
- slot_addend = (pci_dev->devfn >> 3) - 1;
- return (pci_intx + slot_addend) & 3;
-}
-
-static void piix3_set_irq(void *opaque, int pirq, int level)
-{
- PIIX3State *piix3 = opaque;
- piix3_set_irq_level(piix3, pirq, level);
-}
-
-static PCIBus *i440fx_common_init(const char *device_name,
- PCII440FXState **pi440fx_state,
- DeviceState **i440fx,
- int *piix3_devfn,
- qemu_irq *pic,
- MemoryRegion *address_space_mem,
- MemoryRegion *address_space_io,
- ram_addr_t ram_size,
- target_phys_addr_t pci_hole_start,
- target_phys_addr_t pci_hole_size,
- target_phys_addr_t pci_hole64_start,
- target_phys_addr_t pci_hole64_size,
- MemoryRegion *pci_address_space,
- MemoryRegion *ram_memory)
-{
- DeviceState *dev;
- PCIBus *b;
- PCIDevice *d;
- I440FXState *s;
- PIIX3State *piix3;
- PCII440FXState *f;
-
- dev = qdev_create(NULL, "i440FX-pcihost");
- s = FROM_SYSBUS(I440FXState, sysbus_from_qdev(dev));
- s->address_space = address_space_mem;
- b = pci_bus_new(&s->busdev.qdev, NULL, pci_address_space,
- address_space_io, 0);
- s->bus = b;
- qdev_init_nofail(dev);
- *i440fx = dev;
-
- d = pci_create_simple(b, 0, device_name);
- *pi440fx_state = DO_UPCAST(PCII440FXState, dev, d);
- f = *pi440fx_state;
- f->system_memory = address_space_mem;
- f->pci_address_space = pci_address_space;
- f->ram_memory = ram_memory;
-
- qdev_property_add_child(dev, "i440fx", &d->qdev, NULL);
-
- memory_region_init_alias(&f->pci_hole, "pci-hole", f->pci_address_space,
- pci_hole_start, pci_hole_size);
- memory_region_add_subregion(f->system_memory, pci_hole_start, &f->pci_hole);
- memory_region_init_alias(&f->pci_hole_64bit, "pci-hole64",
- f->pci_address_space,
- pci_hole64_start, pci_hole64_size);
- if (pci_hole64_size) {
- memory_region_add_subregion(f->system_memory, pci_hole64_start,
- &f->pci_hole_64bit);
- }
- memory_region_init_alias(&f->smram_region, "smram-region",
- f->pci_address_space, 0xa0000, 0x20000);
- f->smram_enabled = true;
-
- /* Xen supports additional interrupt routes from the PCI devices to
- * the IOAPIC: the four pins of each PCI device on the bus are also
- * connected to the IOAPIC directly.
- * These additional routes can be discovered through ACPI. */
- if (xen_enabled()) {
- piix3 = DO_UPCAST(PIIX3State, dev,
- pci_create_simple_multifunction(b, -1, true, "PIIX3-xen"));
- pci_bus_irqs(b, xen_piix3_set_irq, xen_pci_slot_get_pirq,
- piix3, XEN_PIIX_NUM_PIRQS);
- } else {
- piix3 = DO_UPCAST(PIIX3State, dev,
- pci_create_simple_multifunction(b, -1, true, "PIIX3"));
- pci_bus_irqs(b, piix3_set_irq, pci_slot_get_pirq, piix3,
- PIIX_NUM_PIRQS);
-
- qdev_property_add_child(&d->qdev, "piix3", &piix3->dev.qdev, NULL);
- }
- piix3->pic = pic;
-
- (*pi440fx_state)->piix3 = piix3;
-
- *piix3_devfn = piix3->dev.devfn;
-
- ram_size = ram_size / 8 / 1024 / 1024;
- if (ram_size > 255)
- ram_size = 255;
- (*pi440fx_state)->dev.config[0x57]=ram_size;
-
- i440fx_update_memory_mappings(f);
-
- return b;
-}
-
-PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix3_devfn,
- DeviceState **i440fx, DeviceState **piix3,
- qemu_irq *pic,
- MemoryRegion *address_space_mem,
- MemoryRegion *address_space_io,
- ram_addr_t ram_size,
- target_phys_addr_t pci_hole_start,
- target_phys_addr_t pci_hole_size,
- target_phys_addr_t pci_hole64_start,
- target_phys_addr_t pci_hole64_size,
- MemoryRegion *pci_memory, MemoryRegion *ram_memory)
-
-{
- PCIBus *b;
-
- b = i440fx_common_init("i440FX", pi440fx_state, i440fx, piix3_devfn, pic,
- address_space_mem, address_space_io, ram_size,
- pci_hole_start, pci_hole_size,
- pci_hole64_size, pci_hole64_size,
- pci_memory, ram_memory);
- *piix3 = &(*pi440fx_state)->piix3->dev.qdev;
- return b;
-}
-
-static PCIDeviceInfo i440fx_info[] = {
- {
- .qdev.name = "i440FX",
- .qdev.desc = "Host bridge",
- .qdev.size = sizeof(PCII440FXState),
- .qdev.vmsd = &vmstate_i440fx,
- .qdev.no_user = 1,
- .no_hotplug = 1,
- .init = i440fx_initfn,
- .config_write = i440fx_write_config,
- .vendor_id = PCI_VENDOR_ID_INTEL,
- .device_id = PCI_DEVICE_ID_INTEL_82441,
- .revision = 0x02,
- .class_id = PCI_CLASS_BRIDGE_HOST,
- },{
- /* end of list */
- }
-};
-
-static SysBusDeviceInfo i440fx_pcihost_info = {
- .init = i440fx_pcihost_initfn,
- .qdev.name = "i440FX-pcihost",
- .qdev.fw_name = "pci",
- .qdev.size = sizeof(I440FXState),
- .qdev.no_user = 1,
-};
-
-static void i440fx_register(void)
-{
- sysbus_register_withprop(&i440fx_pcihost_info);
- pci_qdev_register_many(i440fx_info);
-}
-
-device_init(i440fx_register);
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 026/197] qom: add qobject
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (24 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 025/197] i440fx: rename piix_pci -> i440fx Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 027/197] rename qobject -> object Anthony Liguori
` (40 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
Makefile.objs | 2 +
hw/qobject.c | 463 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
hw/qobject.h | 471 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 936 insertions(+), 0 deletions(-)
create mode 100644 hw/qobject.c
create mode 100644 hw/qobject.h
diff --git a/Makefile.objs b/Makefile.objs
index 67e1ae5..8e629f1 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -123,6 +123,8 @@ common-obj-$(CONFIG_WIN32) += version.o
common-obj-$(CONFIG_SPICE) += ui/spice-core.o ui/spice-input.o ui/spice-display.o spice-qemu-char.o
+common-obj-y += qobject.o
+
audio-obj-y = audio.o noaudio.o wavaudio.o mixeng.o
audio-obj-$(CONFIG_SDL) += sdlaudio.o
audio-obj-$(CONFIG_OSS) += ossaudio.o
diff --git a/hw/qobject.c b/hw/qobject.c
new file mode 100644
index 0000000..54398ab
--- /dev/null
+++ b/hw/qobject.c
@@ -0,0 +1,463 @@
+/*
+ * QEMU Object Model
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ * Anthony Liguori <aliguori@us.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qobject.h"
+
+#define MAX_INTERFACES 32
+
+typedef struct QInterfaceImpl
+{
+ const char *parent;
+ void (*interface_initfn)(QObjectClass *class);
+ QType type;
+} QInterfaceImpl;
+
+typedef struct QTypeImpl
+{
+ const char *name;
+ QType type;
+
+ size_t class_size;
+
+ size_t instance_size;
+
+ void (*base_init)(QObjectClass *klass);
+ void (*base_finalize)(QObjectClass *klass);
+
+ void (*class_init)(QObjectClass *klass);
+ void (*class_finalize)(QObjectClass *klass);
+
+ void (*instance_init)(QObject *obj);
+ void (*instance_finalize)(QObject *obj);
+
+ bool abstract;
+
+ const char *parent;
+
+ QObjectClass *class;
+
+ int num_interfaces;
+ QInterfaceImpl interfaces[MAX_INTERFACES];
+} QTypeImpl;
+
+static int num_types = 1;
+static QTypeImpl type_table[1024];
+
+QType qtype_register_static(const QTypeInfo *info)
+{
+ QType type = num_types++;
+ QTypeImpl *ti;
+
+ ti = &type_table[type];
+
+ assert(info->name != NULL);
+
+ ti->name = info->name;
+ ti->parent = info->parent;
+ ti->type = type;
+
+ ti->class_size = info->class_size;
+ ti->instance_size = info->instance_size;
+
+ ti->base_init = info->base_init;
+ ti->base_finalize = info->base_finalize;
+
+ ti->class_init = info->class_init;
+ ti->class_finalize = info->class_finalize;
+
+ ti->instance_init = info->instance_init;
+ ti->instance_finalize = info->instance_finalize;
+
+ ti->abstract = info->abstract;
+
+ if (info->interfaces) {
+ int i;
+
+ for (i = 0; info->interfaces[i].type; i++) {
+ ti->interfaces[i].parent = info->interfaces[i].type;
+ ti->interfaces[i].interface_initfn = info->interfaces[i].interface_initfn;
+ ti->num_interfaces++;
+ }
+ }
+
+ return type;
+}
+
+static QType qtype_register_anonymous(const QTypeInfo *info)
+{
+ QType type = num_types++;
+ QTypeImpl *ti;
+ char buffer[32];
+ static int count;
+
+ ti = &type_table[type];
+
+ snprintf(buffer, sizeof(buffer), "<anonymous-%d>", count++);
+ ti->name = g_strdup(buffer);
+ ti->parent = g_strdup(info->parent);
+ ti->type = type;
+
+ ti->class_size = info->class_size;
+ ti->instance_size = info->instance_size;
+
+ ti->base_init = info->base_init;
+ ti->base_finalize = info->base_finalize;
+
+ ti->class_init = info->class_init;
+ ti->class_finalize = info->class_finalize;
+
+ ti->instance_init = info->instance_init;
+ ti->instance_finalize = info->instance_finalize;
+
+ if (info->interfaces) {
+ int i;
+
+ for (i = 0; info->interfaces[i].type; i++) {
+ ti->interfaces[i].parent = info->interfaces[i].type;
+ ti->interfaces[i].interface_initfn = info->interfaces[i].interface_initfn;
+ ti->num_interfaces++;
+ }
+ }
+
+ return type;
+}
+
+static QTypeImpl *qtype_get_instance(QType type)
+{
+ assert(type != 0);
+ assert(type < num_types);
+
+ return &type_table[type];
+}
+
+QType qtype_get_by_name(const char *name)
+{
+ int i;
+
+ if (name == NULL) {
+ return 0;
+ }
+
+ for (i = 1; i < num_types; i++) {
+ if (strcmp(name, type_table[i].name) == 0) {
+ return i;
+ }
+ }
+
+ return 0;
+}
+
+static void qtype_class_base_init(QTypeImpl *base_ti, const char *typename)
+{
+ QTypeImpl *ti;
+
+ if (!typename) {
+ return;
+ }
+
+ ti = qtype_get_instance(qtype_get_by_name(typename));
+
+ qtype_class_base_init(base_ti, ti->parent);
+
+ if (ti->base_init) {
+ ti->base_init(base_ti->class);
+ }
+}
+
+static size_t qtype_class_get_size(QTypeImpl *ti)
+{
+ if (ti->class_size) {
+ return ti->class_size;
+ }
+
+ if (ti->parent) {
+ return qtype_class_get_size(qtype_get_instance(qtype_get_by_name(ti->parent)));
+ }
+
+ return sizeof(QObjectClass);
+}
+
+static void qtype_class_interface_init(QTypeImpl *ti, QInterfaceImpl *iface)
+{
+ QTypeInfo info = {
+ .instance_size = sizeof(QInterface),
+ .parent = iface->parent,
+ .class_size = sizeof(QInterfaceClass),
+ .class_init = iface->interface_initfn,
+ .abstract = true,
+ };
+
+ iface->type = qtype_register_anonymous(&info);
+}
+
+static void qtype_class_init(QTypeImpl *ti)
+{
+ size_t class_size = sizeof(QObjectClass);
+ int i;
+
+ if (ti->class) {
+ return;
+ }
+
+ ti->class_size = qtype_class_get_size(ti);
+
+ ti->class = g_malloc0(ti->class_size);
+ ti->class->type = ti->type;
+
+ if (ti->parent) {
+ QTypeImpl *ti_parent;
+
+ ti_parent = qtype_get_instance(qtype_get_by_name(ti->parent));
+
+ qtype_class_init(ti_parent);
+
+ class_size = ti_parent->class_size;
+ assert(ti_parent->class_size <= ti->class_size);
+
+ memcpy((void *)ti->class + sizeof(QObjectClass),
+ (void *)ti_parent->class + sizeof(QObjectClass),
+ ti_parent->class_size - sizeof(QObjectClass));
+ }
+
+ memset((void *)ti->class + class_size, 0, ti->class_size - class_size);
+
+ qtype_class_base_init(ti, ti->parent);
+
+ for (i = 0; i < ti->num_interfaces; i++) {
+ qtype_class_interface_init(ti, &ti->interfaces[i]);
+ }
+
+ if (ti->class_init) {
+ ti->class_init(ti->class);
+ }
+}
+
+static void qobject_interface_init(QObject *obj, QInterfaceImpl *iface)
+{
+ QTypeImpl *ti = qtype_get_instance(iface->type);
+ QInterface *iface_obj;
+
+ iface_obj = QINTERFACE(qobject_new(ti->name));
+ iface_obj->obj = obj;
+
+ obj->interfaces = g_slist_prepend(obj->interfaces, iface_obj);
+}
+
+static void qobject_init(QObject *obj, const char *typename)
+{
+ QTypeImpl *ti = qtype_get_instance(qtype_get_by_name(typename));
+ int i;
+
+ if (ti->parent) {
+ qobject_init(obj, ti->parent);
+ }
+
+ for (i = 0; i < ti->num_interfaces; i++) {
+ qobject_interface_init(obj, &ti->interfaces[i]);
+ }
+
+ if (ti->instance_init) {
+ ti->instance_init(obj);
+ }
+}
+
+void qobject_initialize(void *data, const char *typename)
+{
+ QTypeImpl *ti = qtype_get_instance(qtype_get_by_name(typename));
+ QObject *obj = data;
+
+ g_assert(ti->instance_size >= sizeof(QObjectClass));
+
+ qtype_class_init(ti);
+
+ g_assert(ti->abstract == false);
+
+ memset(obj, 0, ti->instance_size);
+
+ obj->class = ti->class;
+
+ qobject_init(obj, typename);
+}
+
+static void qobject_deinit(QObject *obj, const char *typename)
+{
+ QTypeImpl *ti = qtype_get_instance(qtype_get_by_name(typename));
+
+ if (ti->instance_finalize) {
+ ti->instance_finalize(obj);
+ }
+
+ while (obj->interfaces) {
+ QInterface *iface_obj = obj->interfaces->data;
+ obj->interfaces = g_slist_delete_link(obj->interfaces, obj->interfaces);
+ qobject_delete(QOBJECT(iface_obj));
+ }
+
+ if (ti->parent) {
+ qobject_init(obj, ti->parent);
+ }
+}
+
+void qobject_finalize(void *data)
+{
+ QObject *obj = data;
+ QTypeImpl *ti = qtype_get_instance(obj->class->type);
+
+ qobject_deinit(obj, ti->name);
+}
+
+const char *qtype_get_name(QType type)
+{
+ QTypeImpl *ti = qtype_get_instance(type);
+ return ti->name;
+}
+
+QObject *qobject_new(const char *typename)
+{
+ QTypeImpl *ti = qtype_get_instance(qtype_get_by_name(typename));
+ QObject *obj;
+
+ obj = g_malloc(ti->instance_size);
+ qobject_initialize(obj, typename);
+
+ return obj;
+}
+
+void qobject_delete(QObject *obj)
+{
+ qobject_finalize(obj);
+ g_free(obj);
+}
+
+bool qobject_is_type(QObject *obj, const char *typename)
+{
+ QType target_type = qtype_get_by_name(typename);
+ QType type = obj->class->type;
+ GSList *i;
+
+ /* Check if typename is a direct ancestor of type */
+ while (type) {
+ QTypeImpl *ti = qtype_get_instance(type);
+
+ if (ti->type == target_type) {
+ return true;
+ }
+
+ type = qtype_get_by_name(ti->parent);
+ }
+
+ /* Check if obj has an interface of typename */
+ for (i = obj->interfaces; i; i = i->next) {
+ QInterface *iface = i->data;
+
+ if (qobject_is_type(QOBJECT(iface), typename)) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+QObject *qobject_dynamic_cast(QObject *obj, const char *typename)
+{
+ GSList *i;
+
+ /* Check if typename is a direct ancestor */
+ if (qobject_is_type(obj, typename)) {
+ return obj;
+ }
+
+ /* Check if obj has an interface of typename */
+ for (i = obj->interfaces; i; i = i->next) {
+ QInterface *iface = i->data;
+
+ if (qobject_is_type(QOBJECT(iface), typename)) {
+ return QOBJECT(iface);
+ }
+ }
+
+ /* Check if obj is an interface and it's containing object is a direct ancestor of typename */
+ if (qobject_is_type(obj, TYPE_QINTERFACE)) {
+ QInterface *iface = QINTERFACE(obj);
+
+ if (qobject_is_type(iface->obj, typename)) {
+ return iface->obj;
+ }
+ }
+
+ return NULL;
+}
+
+
+static void register_interface(void)
+{
+ static QTypeInfo interface_info = {
+ .name = TYPE_QINTERFACE,
+ .instance_size = sizeof(QInterface),
+ .abstract = true,
+ };
+
+ qtype_register_static(&interface_info);
+}
+
+device_init(register_interface);
+
+QObject *qobject_dynamic_cast_assert(QObject *obj, const char *typename)
+{
+ QObject *inst;
+
+ inst = qobject_dynamic_cast(obj, typename);
+
+ if (!inst) {
+ fprintf(stderr, "Object %p is not an instance of type %s\n", obj, typename);
+ abort();
+ }
+
+ return inst;
+}
+
+QObjectClass *qobject_check_class(QObjectClass *class, const char *typename)
+{
+ QType target_type = qtype_get_by_name(typename);
+ QType type = class->type;
+
+ while (type) {
+ QTypeImpl *ti = qtype_get_instance(type);
+
+ if (ti->type == target_type) {
+ return class;
+ }
+
+ type = qtype_get_by_name(ti->parent);
+ }
+
+ fprintf(stderr, "Object %p is not an instance of type %d\n", class, (int)type);
+ abort();
+
+ return NULL;
+}
+
+const char *qobject_get_type(QObject *obj)
+{
+ return qtype_get_name(obj->class->type);
+}
+
+QObjectClass *qobject_get_class(QObject *obj)
+{
+ return obj->class;
+}
+
+QObjectClass *qobject_get_super(QObject *obj)
+{
+ return qtype_get_instance(qtype_get_by_name(qtype_get_instance(obj->class->type)->parent))->class;
+}
+
diff --git a/hw/qobject.h b/hw/qobject.h
new file mode 100644
index 0000000..f20ed1c
--- /dev/null
+++ b/hw/qobject.h
@@ -0,0 +1,471 @@
+/*
+ * QEMU Object Model
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ * Anthony Liguori <aliguori@us.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef QOBJECT_H
+#define QOBJECT_H
+
+#include "qemu-common.h"
+
+typedef uint64_t QType;
+
+typedef struct QObjectClass QObjectClass;
+typedef struct QObject QObject;
+
+typedef struct QTypeInfo QTypeInfo;
+
+typedef struct QInterfaceClass QInterfaceClass;
+typedef struct QInterface QInterface;
+typedef struct QInterfaceInfo QInterfaceInfo;
+
+/**
+ * @QObjectClass:
+ *
+ * The base for all classes. The only thing that @QObjectClass contains is an
+ * integer type handle.
+ */
+struct QObjectClass
+{
+ /**
+ * @type the handle of the type for a class
+ */
+ QType type;
+};
+
+/**
+ * @QObject:
+ *
+ * The base for all objects. The first member of this object is a pointer to
+ * a @QObjectClass. Since C guarantees that the first member of a structure
+ * always begins at byte 0 of that structure, as long as any sub-object places
+ * its parent as the first member, we can cast directly to a @QObject.
+ *
+ * As a result, @QObject contains a reference to the objects type as its
+ * first member. This allows identification of the real type of the object at
+ * run time.
+ *
+ * @QObject also contains a list of @QInterfaces that this object
+ * implements.
+ */
+struct QObject
+{
+ /**
+ * @class the type of the instantiated object.
+ */
+ QObjectClass *class;
+
+ /**
+ * @interfaces a list of @QInterface objects implemented by this object
+ */
+ GSList *interfaces;
+};
+
+/**
+ * @QTypeInfo:
+ *
+ */
+struct QTypeInfo
+{
+ /**
+ * @name the name of the type
+ */
+ const char *name;
+
+ /**
+ * @parent the name of the parent type
+ */
+ const char *parent;
+
+ /**
+ * Instance Initialization
+ *
+ * This functions manage the instance construction and destruction of a
+ * type.
+ */
+
+ /**
+ * @instance_size the size of the object (derivative of @QObject). If
+ * @instance_size is 0, then the size of the object will be the size of the
+ * parent object.
+ */
+ size_t instance_size;
+
+ /**
+ * @instance_init
+ *
+ * This function is called to initialize an object. The parent class will
+ * have already been initialized so the type is only responsible for
+ * initializing its own members.
+ */
+ void (*instance_init)(QObject *obj);
+
+ /**
+ * @instance_finalize
+ *
+ * This function is called during object destruction. This is called before
+ * the parent @instance_finalize function has been called. An object should
+ * only free the members that are unique to its type in this function.
+ */
+ void (*instance_finalize)(QObject *obj);
+
+ /**
+ * @abstract
+ *
+ * If this field is true, then the class is considered abstract and cannot
+ * be directly instantiated.
+ */
+ bool abstract;
+
+ /**
+ * Class Initialization
+ *
+ * Before an object is initialized, the class for the object must be
+ * initialized. There is only one class object for all instance objects
+ * that is created lazily.
+ *
+ * Classes are initialized by first initializing any parent classes (if
+ * necessary). After the parent class object has initialized, it will be
+ * copied into the current class object and any additional storage in the
+ * class object is zero filled.
+ *
+ * The effect of this is that classes automatically inherit any virtual
+ * function pointers that the parent class has already initialized. All
+ * other fields will be zero filled.
+ *
+ * After this initial copy, @base_init is invoked. This is meant to handle
+ * the case where a class may have a dynamic field that was copied via
+ * a shallow copy but needs to be deep copied. @base_init is called for
+ * each parent class but not for the class being instantiated.
+ *
+ * Once all of the parent classes have been initialized and their @base_init
+ * functions have been called, @class_init is called to let the class being
+ * instantiated provide default initialize for it's virtual functions.
+ */
+
+ /**
+ * @class_size the size of the class object (derivative of @QObjectClass)
+ * for this object. If @class_size is 0, then the size of the class will be
+ * assumed to be the size of the parent class. This allows a type to avoid
+ * implementing an explicit class type if they are not adding additional
+ * virtual functions.
+ */
+ size_t class_size;
+
+ /**
+ * @base_init
+ *
+ * This function is called after memcpy()'ing the base class into the new
+ * class to reinitialize any members that require deep copy.
+ */
+ void (*base_init)(QObjectClass *klass);
+
+ /**
+ * @base_finalize
+ *
+ * This function is called during a class's destruction and is meant to
+ * allow any dynamic parameters allocated by @base_init to be released.
+ */
+ void (*base_finalize)(QObjectClass *klass);
+
+ /**
+ * @class_init
+ *
+ * This function is called after all parent class initialization has occured
+ * to allow a class to set its default virtual method pointers. This is
+ * also the function to use to override virtual methods from a parent class.
+ */
+ void (*class_init)(QObjectClass *klass);
+
+ /**
+ * @class_finalize
+ *
+ * This function is called during class destruction and is meant to release
+ * and dynamic parameters allocated by @class_init.
+ */
+ void (*class_finalize)(QObjectClass *klass);
+
+ /**
+ * QInterfaces
+ *
+ * QInterfaces allow a limited form of multiple inheritance. Instances are
+ * similar to normal types except for the fact that are only defined by
+ * their classes and never carry any state. You can cast an object to one
+ * of its @QInterface types and vice versa.
+ */
+
+ /**
+ * @interfaces the list of interfaces associated with this type. This
+ * should point to a static array that's terminated with a zero filled
+ * element.
+ */
+ QInterfaceInfo *interfaces;
+};
+
+/**
+ * @QOBJECT
+ *
+ * Converts an object to a @QObject. Since all objects are @QObjects,
+ * this function will always succeed.
+ */
+#define QOBJECT(obj) \
+ ((QObject *)(obj))
+
+/**
+ * @QOBJECT_CHECK
+ *
+ * A type safe version of @qobject_dynamic_cast_assert. Typically each class
+ * will define a macro based on this type to perform type safe dynamic_casts to
+ * this object type.
+ *
+ * If an invalid object is passed to this function, a run time assert will be
+ * generated.
+ */
+#define QOBJECT_CHECK(type, obj, name) \
+ ((type *)qobject_dynamic_cast_assert((QObject *)(obj), (name)))
+
+/**
+ * @QOBJECT_CLASS_CHECK
+ *
+ * A type safe version of @qobject_check_class. This macro is typically wrapped
+ * by each type to perform type safe casts of a class to a specific class type.
+ */
+#define QOBJECT_CLASS_CHECK(class, obj, name) \
+ ((class *)qobject_check_class((QObjectClass *)(obj), (name)))
+
+/**
+ * @QOBJECT_GET_CLASS
+ *
+ * This function will return a specific class for a given object. Its generally
+ * used by each type to provide a type safe macro to get a specific class type
+ * from an object.
+ */
+#define QOBJECT_GET_CLASS(class, obj, name) \
+ QOBJECT_CLASS_CHECK(class, qobject_get_class(QOBJECT(obj)), name)
+
+/**
+ * @QQInterface:
+ *
+ * The base for all QInterfaces. This is a subclass of QObject. Subclasses
+ * of @QInterface should never have an instance that contains anything other
+ * than a single @QInterface member.
+ */
+struct QInterface
+{
+ /**
+ * @parent base class
+ */
+ QObject parent;
+
+ /* private */
+
+ /**
+ * @obj a pointer to the object that implements this interface. This is
+ * used to allow casting from an interface to the base object.
+ */
+ QObject *obj;
+};
+
+/**
+ * @QInterfaceClass:
+ *
+ * The class for all interfaces. Subclasses of this class should only add
+ * virtual methods.
+ */
+struct QInterfaceClass
+{
+ /**
+ * @parent_class the base class
+ */
+ QObjectClass parent_class;
+};
+
+/**
+ * @QInterfaceInfo:
+ *
+ * The information associated with an interface.
+ */
+struct QInterfaceInfo
+{
+ /**
+ * @type the name of the interface
+ */
+ const char *type;
+
+ /**
+ * @interface_initfn is called during class initialization and is used to
+ * initialize an interface associated with a class. This function should
+ * initialize any default virtual functions for a class and/or override
+ * virtual functions in a parent class.
+ */
+ void (*interface_initfn)(QObjectClass *class);
+};
+
+#define TYPE_QINTERFACE "interface"
+#define QINTERFACE(obj) QOBJECT_CHECK(QInterface, obj, TYPE_QINTERFACE)
+
+/**
+ * @qobject_new:
+ *
+ * This function will initialize a new object using heap allocated memory. This
+ * function should be paired with @qobject_delete to free the resources
+ * associated with the object.
+ *
+ * @typename: The name of the type of the object to instantiate
+ *
+ * Returns: The newly allocated and instantiated object.
+ *
+ */
+QObject *qobject_new(const char *typename);
+
+/**
+ * @qobject_delete:
+ *
+ * Finalize an object and then free the memory associated with it. This should
+ * be paired with @qobject_new to free the resources associated with an object.
+ *
+ * @obj: The object to free.
+ *
+ */
+void qobject_delete(QObject *obj);
+
+/**
+ * @qobject_initialize:
+ *
+ * This function will initialize an object. The memory for the object should
+ * have already been allocated.
+ *
+ * @obj: A pointer to the memory to be used for the object.
+ *
+ * @typename: The name of the type of the object to instantiate
+ *
+ */
+void qobject_initialize(void *obj, const char *typename);
+
+/**
+ * @qobject_finalize:
+ *
+ * This function destroys and object without freeing the memory associated with
+ * it.
+ *
+ * @obj: The object to finalize.
+ *
+ */
+void qobject_finalize(void *obj);
+
+/**
+ * @qobject_dynamic_cast:
+ *
+ * This function will determine if @obj is-a @typename. @obj can refer to an
+ * object or an interface associated with an object.
+ *
+ * @obj: The object to cast.
+ *
+ * @typename: The @typename
+ *
+ * Returns:
+ *
+ */
+QObject *qobject_dynamic_cast(QObject *obj, const char *typename);
+
+/**
+ * @qobject_dynamic_cast_assert:
+ *
+ * @obj:
+ *
+ * @typename:
+ *
+ * Returns:
+ *
+ */
+QObject *qobject_dynamic_cast_assert(QObject *obj, const char *typename);
+
+/**
+ * @qobject_is_type:
+ *
+ * @obj:
+ *
+ * @typename:
+ *
+ * Returns:
+ *
+ */
+bool qobject_is_type(QObject *obj, const char *typename);
+
+/**
+ * @qobject_get_class:
+ *
+ * @obj:
+ *
+ * Returns:
+ *
+ */
+QObjectClass *qobject_get_class(QObject *obj);
+
+/**
+ * @qobject_get_type:
+ *
+ * @obj:
+ *
+ * Returns:
+ */
+const char *qobject_get_type(QObject *obj);
+
+/**
+ * @qobject_get_super:
+ *
+ * @obj:
+ *
+ * Returns:
+ */
+QObjectClass *qobject_get_super(QObject *obj);
+
+/**/
+
+/**
+ * @qtype_register_static:
+ *
+ * @info:
+ *
+ * Returns:
+ */
+QType qtype_register_static(const QTypeInfo *info);
+
+/**
+ * @qobject_check_class:
+ *
+ * @obj:
+ *
+ * @typename:
+ *
+ * Returns:
+ */
+QObjectClass *qobject_check_class(QObjectClass *obj, const char *typename);
+
+/**
+ * @qtype_get_by_name:
+ *
+ * @name:
+ *
+ * Returns:
+ */
+QType qtype_get_by_name(const char *name);
+
+/**
+ * @qtype_get_name:
+ *
+ * @type:
+ *
+ * Returns:
+ */
+const char *qtype_get_name(QType type);
+
+#endif
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 027/197] rename qobject -> object
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (25 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 026/197] qom: add qobject Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 028/197] more renames Anthony Liguori
` (39 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
Makefile.objs | 2 +-
hw/object.c | 463 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
hw/object.h | 471 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
hw/qdev.h | 7 +
hw/qobject.c | 463 --------------------------------------------------------
hw/qobject.h | 471 ---------------------------------------------------------
6 files changed, 942 insertions(+), 935 deletions(-)
create mode 100644 hw/object.c
create mode 100644 hw/object.h
delete mode 100644 hw/qobject.c
delete mode 100644 hw/qobject.h
diff --git a/Makefile.objs b/Makefile.objs
index 8e629f1..c77c0af 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -123,7 +123,7 @@ common-obj-$(CONFIG_WIN32) += version.o
common-obj-$(CONFIG_SPICE) += ui/spice-core.o ui/spice-input.o ui/spice-display.o spice-qemu-char.o
-common-obj-y += qobject.o
+common-obj-y += object.o
audio-obj-y = audio.o noaudio.o wavaudio.o mixeng.o
audio-obj-$(CONFIG_SDL) += sdlaudio.o
diff --git a/hw/object.c b/hw/object.c
new file mode 100644
index 0000000..be61677
--- /dev/null
+++ b/hw/object.c
@@ -0,0 +1,463 @@
+/*
+ * QEMU Object Model
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ * Anthony Liguori <aliguori@us.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "object.h"
+
+#define MAX_INTERFACES 32
+
+typedef struct InterfaceImpl
+{
+ const char *parent;
+ void (*interface_initfn)(ObjectClass *class);
+ Type type;
+} InterfaceImpl;
+
+typedef struct TypeImpl
+{
+ const char *name;
+ Type type;
+
+ size_t class_size;
+
+ size_t instance_size;
+
+ void (*base_init)(ObjectClass *klass);
+ void (*base_finalize)(ObjectClass *klass);
+
+ void (*class_init)(ObjectClass *klass);
+ void (*class_finalize)(ObjectClass *klass);
+
+ void (*instance_init)(Object *obj);
+ void (*instance_finalize)(Object *obj);
+
+ bool abstract;
+
+ const char *parent;
+
+ ObjectClass *class;
+
+ int num_interfaces;
+ InterfaceImpl interfaces[MAX_INTERFACES];
+} TypeImpl;
+
+static int num_types = 1;
+static TypeImpl type_table[1024];
+
+Type type_register_static(const TypeInfo *info)
+{
+ Type type = num_types++;
+ TypeImpl *ti;
+
+ ti = &type_table[type];
+
+ assert(info->name != NULL);
+
+ ti->name = info->name;
+ ti->parent = info->parent;
+ ti->type = type;
+
+ ti->class_size = info->class_size;
+ ti->instance_size = info->instance_size;
+
+ ti->base_init = info->base_init;
+ ti->base_finalize = info->base_finalize;
+
+ ti->class_init = info->class_init;
+ ti->class_finalize = info->class_finalize;
+
+ ti->instance_init = info->instance_init;
+ ti->instance_finalize = info->instance_finalize;
+
+ ti->abstract = info->abstract;
+
+ if (info->interfaces) {
+ int i;
+
+ for (i = 0; info->interfaces[i].type; i++) {
+ ti->interfaces[i].parent = info->interfaces[i].type;
+ ti->interfaces[i].interface_initfn = info->interfaces[i].interface_initfn;
+ ti->num_interfaces++;
+ }
+ }
+
+ return type;
+}
+
+static Type type_register_anonymous(const TypeInfo *info)
+{
+ Type type = num_types++;
+ TypeImpl *ti;
+ char buffer[32];
+ static int count;
+
+ ti = &type_table[type];
+
+ snprintf(buffer, sizeof(buffer), "<anonymous-%d>", count++);
+ ti->name = g_strdup(buffer);
+ ti->parent = g_strdup(info->parent);
+ ti->type = type;
+
+ ti->class_size = info->class_size;
+ ti->instance_size = info->instance_size;
+
+ ti->base_init = info->base_init;
+ ti->base_finalize = info->base_finalize;
+
+ ti->class_init = info->class_init;
+ ti->class_finalize = info->class_finalize;
+
+ ti->instance_init = info->instance_init;
+ ti->instance_finalize = info->instance_finalize;
+
+ if (info->interfaces) {
+ int i;
+
+ for (i = 0; info->interfaces[i].type; i++) {
+ ti->interfaces[i].parent = info->interfaces[i].type;
+ ti->interfaces[i].interface_initfn = info->interfaces[i].interface_initfn;
+ ti->num_interfaces++;
+ }
+ }
+
+ return type;
+}
+
+static TypeImpl *type_get_instance(Type type)
+{
+ assert(type != 0);
+ assert(type < num_types);
+
+ return &type_table[type];
+}
+
+Type type_get_by_name(const char *name)
+{
+ int i;
+
+ if (name == NULL) {
+ return 0;
+ }
+
+ for (i = 1; i < num_types; i++) {
+ if (strcmp(name, type_table[i].name) == 0) {
+ return i;
+ }
+ }
+
+ return 0;
+}
+
+static void type_class_base_init(TypeImpl *base_ti, const char *typename)
+{
+ TypeImpl *ti;
+
+ if (!typename) {
+ return;
+ }
+
+ ti = type_get_instance(type_get_by_name(typename));
+
+ type_class_base_init(base_ti, ti->parent);
+
+ if (ti->base_init) {
+ ti->base_init(base_ti->class);
+ }
+}
+
+static size_t type_class_get_size(TypeImpl *ti)
+{
+ if (ti->class_size) {
+ return ti->class_size;
+ }
+
+ if (ti->parent) {
+ return type_class_get_size(type_get_instance(type_get_by_name(ti->parent)));
+ }
+
+ return sizeof(ObjectClass);
+}
+
+static void type_class_interface_init(TypeImpl *ti, InterfaceImpl *iface)
+{
+ TypeInfo info = {
+ .instance_size = sizeof(Interface),
+ .parent = iface->parent,
+ .class_size = sizeof(InterfaceClass),
+ .class_init = iface->interface_initfn,
+ .abstract = true,
+ };
+
+ iface->type = type_register_anonymous(&info);
+}
+
+static void type_class_init(TypeImpl *ti)
+{
+ size_t class_size = sizeof(ObjectClass);
+ int i;
+
+ if (ti->class) {
+ return;
+ }
+
+ ti->class_size = type_class_get_size(ti);
+
+ ti->class = g_malloc0(ti->class_size);
+ ti->class->type = ti->type;
+
+ if (ti->parent) {
+ TypeImpl *ti_parent;
+
+ ti_parent = type_get_instance(type_get_by_name(ti->parent));
+
+ type_class_init(ti_parent);
+
+ class_size = ti_parent->class_size;
+ assert(ti_parent->class_size <= ti->class_size);
+
+ memcpy((void *)ti->class + sizeof(ObjectClass),
+ (void *)ti_parent->class + sizeof(ObjectClass),
+ ti_parent->class_size - sizeof(ObjectClass));
+ }
+
+ memset((void *)ti->class + class_size, 0, ti->class_size - class_size);
+
+ type_class_base_init(ti, ti->parent);
+
+ for (i = 0; i < ti->num_interfaces; i++) {
+ type_class_interface_init(ti, &ti->interfaces[i]);
+ }
+
+ if (ti->class_init) {
+ ti->class_init(ti->class);
+ }
+}
+
+static void object_interface_init(Object *obj, InterfaceImpl *iface)
+{
+ TypeImpl *ti = type_get_instance(iface->type);
+ Interface *iface_obj;
+
+ iface_obj = INTERFACE(object_new(ti->name));
+ iface_obj->obj = obj;
+
+ obj->interfaces = g_slist_prepend(obj->interfaces, iface_obj);
+}
+
+static void object_init(Object *obj, const char *typename)
+{
+ TypeImpl *ti = type_get_instance(type_get_by_name(typename));
+ int i;
+
+ if (ti->parent) {
+ object_init(obj, ti->parent);
+ }
+
+ for (i = 0; i < ti->num_interfaces; i++) {
+ object_interface_init(obj, &ti->interfaces[i]);
+ }
+
+ if (ti->instance_init) {
+ ti->instance_init(obj);
+ }
+}
+
+void object_initialize(void *data, const char *typename)
+{
+ TypeImpl *ti = type_get_instance(type_get_by_name(typename));
+ Object *obj = data;
+
+ g_assert(ti->instance_size >= sizeof(ObjectClass));
+
+ type_class_init(ti);
+
+ g_assert(ti->abstract == false);
+
+ memset(obj, 0, ti->instance_size);
+
+ obj->class = ti->class;
+
+ object_init(obj, typename);
+}
+
+static void object_deinit(Object *obj, const char *typename)
+{
+ TypeImpl *ti = type_get_instance(type_get_by_name(typename));
+
+ if (ti->instance_finalize) {
+ ti->instance_finalize(obj);
+ }
+
+ while (obj->interfaces) {
+ Interface *iface_obj = obj->interfaces->data;
+ obj->interfaces = g_slist_delete_link(obj->interfaces, obj->interfaces);
+ object_delete(OBJECT(iface_obj));
+ }
+
+ if (ti->parent) {
+ object_init(obj, ti->parent);
+ }
+}
+
+void object_finalize(void *data)
+{
+ Object *obj = data;
+ TypeImpl *ti = type_get_instance(obj->class->type);
+
+ object_deinit(obj, ti->name);
+}
+
+const char *type_get_name(Type type)
+{
+ TypeImpl *ti = type_get_instance(type);
+ return ti->name;
+}
+
+Object *object_new(const char *typename)
+{
+ TypeImpl *ti = type_get_instance(type_get_by_name(typename));
+ Object *obj;
+
+ obj = g_malloc(ti->instance_size);
+ object_initialize(obj, typename);
+
+ return obj;
+}
+
+void object_delete(Object *obj)
+{
+ object_finalize(obj);
+ g_free(obj);
+}
+
+bool object_is_type(Object *obj, const char *typename)
+{
+ Type target_type = type_get_by_name(typename);
+ Type type = obj->class->type;
+ GSList *i;
+
+ /* Check if typename is a direct ancestor of type */
+ while (type) {
+ TypeImpl *ti = type_get_instance(type);
+
+ if (ti->type == target_type) {
+ return true;
+ }
+
+ type = type_get_by_name(ti->parent);
+ }
+
+ /* Check if obj has an interface of typename */
+ for (i = obj->interfaces; i; i = i->next) {
+ Interface *iface = i->data;
+
+ if (object_is_type(OBJECT(iface), typename)) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+Object *object_dynamic_cast(Object *obj, const char *typename)
+{
+ GSList *i;
+
+ /* Check if typename is a direct ancestor */
+ if (object_is_type(obj, typename)) {
+ return obj;
+ }
+
+ /* Check if obj has an interface of typename */
+ for (i = obj->interfaces; i; i = i->next) {
+ Interface *iface = i->data;
+
+ if (object_is_type(OBJECT(iface), typename)) {
+ return OBJECT(iface);
+ }
+ }
+
+ /* Check if obj is an interface and it's containing object is a direct ancestor of typename */
+ if (object_is_type(obj, TYPE_INTERFACE)) {
+ Interface *iface = INTERFACE(obj);
+
+ if (object_is_type(iface->obj, typename)) {
+ return iface->obj;
+ }
+ }
+
+ return NULL;
+}
+
+
+static void register_interface(void)
+{
+ static TypeInfo interface_info = {
+ .name = TYPE_INTERFACE,
+ .instance_size = sizeof(Interface),
+ .abstract = true,
+ };
+
+ type_register_static(&interface_info);
+}
+
+device_init(register_interface);
+
+Object *object_dynamic_cast_assert(Object *obj, const char *typename)
+{
+ Object *inst;
+
+ inst = object_dynamic_cast(obj, typename);
+
+ if (!inst) {
+ fprintf(stderr, "Object %p is not an instance of type %s\n", obj, typename);
+ abort();
+ }
+
+ return inst;
+}
+
+ObjectClass *object_check_class(ObjectClass *class, const char *typename)
+{
+ Type target_type = type_get_by_name(typename);
+ Type type = class->type;
+
+ while (type) {
+ TypeImpl *ti = type_get_instance(type);
+
+ if (ti->type == target_type) {
+ return class;
+ }
+
+ type = type_get_by_name(ti->parent);
+ }
+
+ fprintf(stderr, "Object %p is not an instance of type %d\n", class, (int)type);
+ abort();
+
+ return NULL;
+}
+
+const char *object_get_type(Object *obj)
+{
+ return type_get_name(obj->class->type);
+}
+
+ObjectClass *object_get_class(Object *obj)
+{
+ return obj->class;
+}
+
+ObjectClass *object_get_super(Object *obj)
+{
+ return type_get_instance(type_get_by_name(type_get_instance(obj->class->type)->parent))->class;
+}
+
diff --git a/hw/object.h b/hw/object.h
new file mode 100644
index 0000000..1ac2f92
--- /dev/null
+++ b/hw/object.h
@@ -0,0 +1,471 @@
+/*
+ * QEMU Object Model
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ * Anthony Liguori <aliguori@us.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef QOBJECT_H
+#define QOBJECT_H
+
+#include "qemu-common.h"
+
+typedef uint64_t Type;
+
+typedef struct ObjectClass ObjectClass;
+typedef struct Object Object;
+
+typedef struct TypeInfo TypeInfo;
+
+typedef struct InterfaceClass InterfaceClass;
+typedef struct Interface Interface;
+typedef struct InterfaceInfo InterfaceInfo;
+
+/**
+ * @ObjectClass:
+ *
+ * The base for all classes. The only thing that @ObjectClass contains is an
+ * integer type handle.
+ */
+struct ObjectClass
+{
+ /**
+ * @type the handle of the type for a class
+ */
+ Type type;
+};
+
+/**
+ * @Object:
+ *
+ * The base for all objects. The first member of this object is a pointer to
+ * a @ObjectClass. Since C guarantees that the first member of a structure
+ * always begins at byte 0 of that structure, as long as any sub-object places
+ * its parent as the first member, we can cast directly to a @Object.
+ *
+ * As a result, @Object contains a reference to the objects type as its
+ * first member. This allows identification of the real type of the object at
+ * run time.
+ *
+ * @Object also contains a list of @Interfaces that this object
+ * implements.
+ */
+struct Object
+{
+ /**
+ * @class the type of the instantiated object.
+ */
+ ObjectClass *class;
+
+ /**
+ * @interfaces a list of @Interface objects implemented by this object
+ */
+ GSList *interfaces;
+};
+
+/**
+ * @TypeInfo:
+ *
+ */
+struct TypeInfo
+{
+ /**
+ * @name the name of the type
+ */
+ const char *name;
+
+ /**
+ * @parent the name of the parent type
+ */
+ const char *parent;
+
+ /**
+ * Instance Initialization
+ *
+ * This functions manage the instance construction and destruction of a
+ * type.
+ */
+
+ /**
+ * @instance_size the size of the object (derivative of @Object). If
+ * @instance_size is 0, then the size of the object will be the size of the
+ * parent object.
+ */
+ size_t instance_size;
+
+ /**
+ * @instance_init
+ *
+ * This function is called to initialize an object. The parent class will
+ * have already been initialized so the type is only responsible for
+ * initializing its own members.
+ */
+ void (*instance_init)(Object *obj);
+
+ /**
+ * @instance_finalize
+ *
+ * This function is called during object destruction. This is called before
+ * the parent @instance_finalize function has been called. An object should
+ * only free the members that are unique to its type in this function.
+ */
+ void (*instance_finalize)(Object *obj);
+
+ /**
+ * @abstract
+ *
+ * If this field is true, then the class is considered abstract and cannot
+ * be directly instantiated.
+ */
+ bool abstract;
+
+ /**
+ * Class Initialization
+ *
+ * Before an object is initialized, the class for the object must be
+ * initialized. There is only one class object for all instance objects
+ * that is created lazily.
+ *
+ * Classes are initialized by first initializing any parent classes (if
+ * necessary). After the parent class object has initialized, it will be
+ * copied into the current class object and any additional storage in the
+ * class object is zero filled.
+ *
+ * The effect of this is that classes automatically inherit any virtual
+ * function pointers that the parent class has already initialized. All
+ * other fields will be zero filled.
+ *
+ * After this initial copy, @base_init is invoked. This is meant to handle
+ * the case where a class may have a dynamic field that was copied via
+ * a shallow copy but needs to be deep copied. @base_init is called for
+ * each parent class but not for the class being instantiated.
+ *
+ * Once all of the parent classes have been initialized and their @base_init
+ * functions have been called, @class_init is called to let the class being
+ * instantiated provide default initialize for it's virtual functions.
+ */
+
+ /**
+ * @class_size the size of the class object (derivative of @ObjectClass)
+ * for this object. If @class_size is 0, then the size of the class will be
+ * assumed to be the size of the parent class. This allows a type to avoid
+ * implementing an explicit class type if they are not adding additional
+ * virtual functions.
+ */
+ size_t class_size;
+
+ /**
+ * @base_init
+ *
+ * This function is called after memcpy()'ing the base class into the new
+ * class to reinitialize any members that require deep copy.
+ */
+ void (*base_init)(ObjectClass *klass);
+
+ /**
+ * @base_finalize
+ *
+ * This function is called during a class's destruction and is meant to
+ * allow any dynamic parameters allocated by @base_init to be released.
+ */
+ void (*base_finalize)(ObjectClass *klass);
+
+ /**
+ * @class_init
+ *
+ * This function is called after all parent class initialization has occured
+ * to allow a class to set its default virtual method pointers. This is
+ * also the function to use to override virtual methods from a parent class.
+ */
+ void (*class_init)(ObjectClass *klass);
+
+ /**
+ * @class_finalize
+ *
+ * This function is called during class destruction and is meant to release
+ * and dynamic parameters allocated by @class_init.
+ */
+ void (*class_finalize)(ObjectClass *klass);
+
+ /**
+ * Interfaces
+ *
+ * Interfaces allow a limited form of multiple inheritance. Instances are
+ * similar to normal types except for the fact that are only defined by
+ * their classes and never carry any state. You can cast an object to one
+ * of its @Interface types and vice versa.
+ */
+
+ /**
+ * @interfaces the list of interfaces associated with this type. This
+ * should point to a static array that's terminated with a zero filled
+ * element.
+ */
+ InterfaceInfo *interfaces;
+};
+
+/**
+ * @OBJECT
+ *
+ * Converts an object to a @Object. Since all objects are @Objects,
+ * this function will always succeed.
+ */
+#define OBJECT(obj) \
+ ((Object *)(obj))
+
+/**
+ * @OBJECT_CHECK
+ *
+ * A type safe version of @object_dynamic_cast_assert. Typically each class
+ * will define a macro based on this type to perform type safe dynamic_casts to
+ * this object type.
+ *
+ * If an invalid object is passed to this function, a run time assert will be
+ * generated.
+ */
+#define OBJECT_CHECK(type, obj, name) \
+ ((type *)object_dynamic_cast_assert((Object *)(obj), (name)))
+
+/**
+ * @OBJECT_CLASS_CHECK
+ *
+ * A type safe version of @object_check_class. This macro is typically wrapped
+ * by each type to perform type safe casts of a class to a specific class type.
+ */
+#define OBJECT_CLASS_CHECK(class, obj, name) \
+ ((class *)object_check_class((ObjectClass *)(obj), (name)))
+
+/**
+ * @OBJECT_GET_CLASS
+ *
+ * This function will return a specific class for a given object. Its generally
+ * used by each type to provide a type safe macro to get a specific class type
+ * from an object.
+ */
+#define OBJECT_GET_CLASS(class, obj, name) \
+ OBJECT_CLASS_CHECK(class, object_get_class(OBJECT(obj)), name)
+
+/**
+ * @Interface:
+ *
+ * The base for all Interfaces. This is a subclass of Object. Subclasses
+ * of @Interface should never have an instance that contains anything other
+ * than a single @Interface member.
+ */
+struct Interface
+{
+ /**
+ * @parent base class
+ */
+ Object parent;
+
+ /* private */
+
+ /**
+ * @obj a pointer to the object that implements this interface. This is
+ * used to allow casting from an interface to the base object.
+ */
+ Object *obj;
+};
+
+/**
+ * @InterfaceClass:
+ *
+ * The class for all interfaces. Subclasses of this class should only add
+ * virtual methods.
+ */
+struct InterfaceClass
+{
+ /**
+ * @parent_class the base class
+ */
+ ObjectClass parent_class;
+};
+
+/**
+ * @InterfaceInfo:
+ *
+ * The information associated with an interface.
+ */
+struct InterfaceInfo
+{
+ /**
+ * @type the name of the interface
+ */
+ const char *type;
+
+ /**
+ * @interface_initfn is called during class initialization and is used to
+ * initialize an interface associated with a class. This function should
+ * initialize any default virtual functions for a class and/or override
+ * virtual functions in a parent class.
+ */
+ void (*interface_initfn)(ObjectClass *class);
+};
+
+#define TYPE_INTERFACE "interface"
+#define INTERFACE(obj) OBJECT_CHECK(Interface, obj, TYPE_INTERFACE)
+
+/**
+ * @object_new:
+ *
+ * This function will initialize a new object using heap allocated memory. This
+ * function should be paired with @object_delete to free the resources
+ * associated with the object.
+ *
+ * @typename: The name of the type of the object to instantiate
+ *
+ * Returns: The newly allocated and instantiated object.
+ *
+ */
+Object *object_new(const char *typename);
+
+/**
+ * @object_delete:
+ *
+ * Finalize an object and then free the memory associated with it. This should
+ * be paired with @object_new to free the resources associated with an object.
+ *
+ * @obj: The object to free.
+ *
+ */
+void object_delete(Object *obj);
+
+/**
+ * @object_initialize:
+ *
+ * This function will initialize an object. The memory for the object should
+ * have already been allocated.
+ *
+ * @obj: A pointer to the memory to be used for the object.
+ *
+ * @typename: The name of the type of the object to instantiate
+ *
+ */
+void object_initialize(void *obj, const char *typename);
+
+/**
+ * @object_finalize:
+ *
+ * This function destroys and object without freeing the memory associated with
+ * it.
+ *
+ * @obj: The object to finalize.
+ *
+ */
+void object_finalize(void *obj);
+
+/**
+ * @object_dynamic_cast:
+ *
+ * This function will determine if @obj is-a @typename. @obj can refer to an
+ * object or an interface associated with an object.
+ *
+ * @obj: The object to cast.
+ *
+ * @typename: The @typename
+ *
+ * Returns:
+ *
+ */
+Object *object_dynamic_cast(Object *obj, const char *typename);
+
+/**
+ * @object_dynamic_cast_assert:
+ *
+ * @obj:
+ *
+ * @typename:
+ *
+ * Returns:
+ *
+ */
+Object *object_dynamic_cast_assert(Object *obj, const char *typename);
+
+/**
+ * @object_is_type:
+ *
+ * @obj:
+ *
+ * @typename:
+ *
+ * Returns:
+ *
+ */
+bool object_is_type(Object *obj, const char *typename);
+
+/**
+ * @object_get_class:
+ *
+ * @obj:
+ *
+ * Returns:
+ *
+ */
+ObjectClass *object_get_class(Object *obj);
+
+/**
+ * @object_get_type:
+ *
+ * @obj:
+ *
+ * Returns:
+ */
+const char *object_get_type(Object *obj);
+
+/**
+ * @object_get_super:
+ *
+ * @obj:
+ *
+ * Returns:
+ */
+ObjectClass *object_get_super(Object *obj);
+
+/**/
+
+/**
+ * @type_register_static:
+ *
+ * @info:
+ *
+ * Returns:
+ */
+Type type_register_static(const TypeInfo *info);
+
+/**
+ * @object_check_class:
+ *
+ * @obj:
+ *
+ * @typename:
+ *
+ * Returns:
+ */
+ObjectClass *object_check_class(ObjectClass *obj, const char *typename);
+
+/**
+ * @type_get_by_name:
+ *
+ * @name:
+ *
+ * Returns:
+ */
+Type type_get_by_name(const char *name);
+
+/**
+ * @type_get_name:
+ *
+ * @type:
+ *
+ * Returns:
+ */
+const char *type_get_name(Type type);
+
+#endif
diff --git a/hw/qdev.h b/hw/qdev.h
index 6e18427..0702b18 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -6,6 +6,7 @@
#include "qemu-char.h"
#include "qemu-option.h"
#include "qapi/qapi-visit-core.h"
+#include "qobject.h"
typedef struct Property Property;
@@ -66,9 +67,15 @@ typedef struct DeviceProperty
QTAILQ_ENTRY(DeviceProperty) node;
} DeviceProperty;
+typedef struct DeviceClass {
+ QObjectClass parent_class;
+} DeviceClass;
+
/* This structure should not be accessed directly. We declare it here
so that it can be embedded in individual device state structures. */
struct DeviceState {
+ QObject parent_obj;
+
const char *id;
enum DevState state;
QemuOpts *opts;
diff --git a/hw/qobject.c b/hw/qobject.c
deleted file mode 100644
index 54398ab..0000000
--- a/hw/qobject.c
+++ /dev/null
@@ -1,463 +0,0 @@
-/*
- * QEMU Object Model
- *
- * Copyright IBM, Corp. 2011
- *
- * Authors:
- * Anthony Liguori <aliguori@us.ibm.com>
- *
- * This work is licensed under the terms of the GNU GPL, version 2 or later.
- * See the COPYING file in the top-level directory.
- */
-
-#include "qobject.h"
-
-#define MAX_INTERFACES 32
-
-typedef struct QInterfaceImpl
-{
- const char *parent;
- void (*interface_initfn)(QObjectClass *class);
- QType type;
-} QInterfaceImpl;
-
-typedef struct QTypeImpl
-{
- const char *name;
- QType type;
-
- size_t class_size;
-
- size_t instance_size;
-
- void (*base_init)(QObjectClass *klass);
- void (*base_finalize)(QObjectClass *klass);
-
- void (*class_init)(QObjectClass *klass);
- void (*class_finalize)(QObjectClass *klass);
-
- void (*instance_init)(QObject *obj);
- void (*instance_finalize)(QObject *obj);
-
- bool abstract;
-
- const char *parent;
-
- QObjectClass *class;
-
- int num_interfaces;
- QInterfaceImpl interfaces[MAX_INTERFACES];
-} QTypeImpl;
-
-static int num_types = 1;
-static QTypeImpl type_table[1024];
-
-QType qtype_register_static(const QTypeInfo *info)
-{
- QType type = num_types++;
- QTypeImpl *ti;
-
- ti = &type_table[type];
-
- assert(info->name != NULL);
-
- ti->name = info->name;
- ti->parent = info->parent;
- ti->type = type;
-
- ti->class_size = info->class_size;
- ti->instance_size = info->instance_size;
-
- ti->base_init = info->base_init;
- ti->base_finalize = info->base_finalize;
-
- ti->class_init = info->class_init;
- ti->class_finalize = info->class_finalize;
-
- ti->instance_init = info->instance_init;
- ti->instance_finalize = info->instance_finalize;
-
- ti->abstract = info->abstract;
-
- if (info->interfaces) {
- int i;
-
- for (i = 0; info->interfaces[i].type; i++) {
- ti->interfaces[i].parent = info->interfaces[i].type;
- ti->interfaces[i].interface_initfn = info->interfaces[i].interface_initfn;
- ti->num_interfaces++;
- }
- }
-
- return type;
-}
-
-static QType qtype_register_anonymous(const QTypeInfo *info)
-{
- QType type = num_types++;
- QTypeImpl *ti;
- char buffer[32];
- static int count;
-
- ti = &type_table[type];
-
- snprintf(buffer, sizeof(buffer), "<anonymous-%d>", count++);
- ti->name = g_strdup(buffer);
- ti->parent = g_strdup(info->parent);
- ti->type = type;
-
- ti->class_size = info->class_size;
- ti->instance_size = info->instance_size;
-
- ti->base_init = info->base_init;
- ti->base_finalize = info->base_finalize;
-
- ti->class_init = info->class_init;
- ti->class_finalize = info->class_finalize;
-
- ti->instance_init = info->instance_init;
- ti->instance_finalize = info->instance_finalize;
-
- if (info->interfaces) {
- int i;
-
- for (i = 0; info->interfaces[i].type; i++) {
- ti->interfaces[i].parent = info->interfaces[i].type;
- ti->interfaces[i].interface_initfn = info->interfaces[i].interface_initfn;
- ti->num_interfaces++;
- }
- }
-
- return type;
-}
-
-static QTypeImpl *qtype_get_instance(QType type)
-{
- assert(type != 0);
- assert(type < num_types);
-
- return &type_table[type];
-}
-
-QType qtype_get_by_name(const char *name)
-{
- int i;
-
- if (name == NULL) {
- return 0;
- }
-
- for (i = 1; i < num_types; i++) {
- if (strcmp(name, type_table[i].name) == 0) {
- return i;
- }
- }
-
- return 0;
-}
-
-static void qtype_class_base_init(QTypeImpl *base_ti, const char *typename)
-{
- QTypeImpl *ti;
-
- if (!typename) {
- return;
- }
-
- ti = qtype_get_instance(qtype_get_by_name(typename));
-
- qtype_class_base_init(base_ti, ti->parent);
-
- if (ti->base_init) {
- ti->base_init(base_ti->class);
- }
-}
-
-static size_t qtype_class_get_size(QTypeImpl *ti)
-{
- if (ti->class_size) {
- return ti->class_size;
- }
-
- if (ti->parent) {
- return qtype_class_get_size(qtype_get_instance(qtype_get_by_name(ti->parent)));
- }
-
- return sizeof(QObjectClass);
-}
-
-static void qtype_class_interface_init(QTypeImpl *ti, QInterfaceImpl *iface)
-{
- QTypeInfo info = {
- .instance_size = sizeof(QInterface),
- .parent = iface->parent,
- .class_size = sizeof(QInterfaceClass),
- .class_init = iface->interface_initfn,
- .abstract = true,
- };
-
- iface->type = qtype_register_anonymous(&info);
-}
-
-static void qtype_class_init(QTypeImpl *ti)
-{
- size_t class_size = sizeof(QObjectClass);
- int i;
-
- if (ti->class) {
- return;
- }
-
- ti->class_size = qtype_class_get_size(ti);
-
- ti->class = g_malloc0(ti->class_size);
- ti->class->type = ti->type;
-
- if (ti->parent) {
- QTypeImpl *ti_parent;
-
- ti_parent = qtype_get_instance(qtype_get_by_name(ti->parent));
-
- qtype_class_init(ti_parent);
-
- class_size = ti_parent->class_size;
- assert(ti_parent->class_size <= ti->class_size);
-
- memcpy((void *)ti->class + sizeof(QObjectClass),
- (void *)ti_parent->class + sizeof(QObjectClass),
- ti_parent->class_size - sizeof(QObjectClass));
- }
-
- memset((void *)ti->class + class_size, 0, ti->class_size - class_size);
-
- qtype_class_base_init(ti, ti->parent);
-
- for (i = 0; i < ti->num_interfaces; i++) {
- qtype_class_interface_init(ti, &ti->interfaces[i]);
- }
-
- if (ti->class_init) {
- ti->class_init(ti->class);
- }
-}
-
-static void qobject_interface_init(QObject *obj, QInterfaceImpl *iface)
-{
- QTypeImpl *ti = qtype_get_instance(iface->type);
- QInterface *iface_obj;
-
- iface_obj = QINTERFACE(qobject_new(ti->name));
- iface_obj->obj = obj;
-
- obj->interfaces = g_slist_prepend(obj->interfaces, iface_obj);
-}
-
-static void qobject_init(QObject *obj, const char *typename)
-{
- QTypeImpl *ti = qtype_get_instance(qtype_get_by_name(typename));
- int i;
-
- if (ti->parent) {
- qobject_init(obj, ti->parent);
- }
-
- for (i = 0; i < ti->num_interfaces; i++) {
- qobject_interface_init(obj, &ti->interfaces[i]);
- }
-
- if (ti->instance_init) {
- ti->instance_init(obj);
- }
-}
-
-void qobject_initialize(void *data, const char *typename)
-{
- QTypeImpl *ti = qtype_get_instance(qtype_get_by_name(typename));
- QObject *obj = data;
-
- g_assert(ti->instance_size >= sizeof(QObjectClass));
-
- qtype_class_init(ti);
-
- g_assert(ti->abstract == false);
-
- memset(obj, 0, ti->instance_size);
-
- obj->class = ti->class;
-
- qobject_init(obj, typename);
-}
-
-static void qobject_deinit(QObject *obj, const char *typename)
-{
- QTypeImpl *ti = qtype_get_instance(qtype_get_by_name(typename));
-
- if (ti->instance_finalize) {
- ti->instance_finalize(obj);
- }
-
- while (obj->interfaces) {
- QInterface *iface_obj = obj->interfaces->data;
- obj->interfaces = g_slist_delete_link(obj->interfaces, obj->interfaces);
- qobject_delete(QOBJECT(iface_obj));
- }
-
- if (ti->parent) {
- qobject_init(obj, ti->parent);
- }
-}
-
-void qobject_finalize(void *data)
-{
- QObject *obj = data;
- QTypeImpl *ti = qtype_get_instance(obj->class->type);
-
- qobject_deinit(obj, ti->name);
-}
-
-const char *qtype_get_name(QType type)
-{
- QTypeImpl *ti = qtype_get_instance(type);
- return ti->name;
-}
-
-QObject *qobject_new(const char *typename)
-{
- QTypeImpl *ti = qtype_get_instance(qtype_get_by_name(typename));
- QObject *obj;
-
- obj = g_malloc(ti->instance_size);
- qobject_initialize(obj, typename);
-
- return obj;
-}
-
-void qobject_delete(QObject *obj)
-{
- qobject_finalize(obj);
- g_free(obj);
-}
-
-bool qobject_is_type(QObject *obj, const char *typename)
-{
- QType target_type = qtype_get_by_name(typename);
- QType type = obj->class->type;
- GSList *i;
-
- /* Check if typename is a direct ancestor of type */
- while (type) {
- QTypeImpl *ti = qtype_get_instance(type);
-
- if (ti->type == target_type) {
- return true;
- }
-
- type = qtype_get_by_name(ti->parent);
- }
-
- /* Check if obj has an interface of typename */
- for (i = obj->interfaces; i; i = i->next) {
- QInterface *iface = i->data;
-
- if (qobject_is_type(QOBJECT(iface), typename)) {
- return true;
- }
- }
-
- return false;
-}
-
-QObject *qobject_dynamic_cast(QObject *obj, const char *typename)
-{
- GSList *i;
-
- /* Check if typename is a direct ancestor */
- if (qobject_is_type(obj, typename)) {
- return obj;
- }
-
- /* Check if obj has an interface of typename */
- for (i = obj->interfaces; i; i = i->next) {
- QInterface *iface = i->data;
-
- if (qobject_is_type(QOBJECT(iface), typename)) {
- return QOBJECT(iface);
- }
- }
-
- /* Check if obj is an interface and it's containing object is a direct ancestor of typename */
- if (qobject_is_type(obj, TYPE_QINTERFACE)) {
- QInterface *iface = QINTERFACE(obj);
-
- if (qobject_is_type(iface->obj, typename)) {
- return iface->obj;
- }
- }
-
- return NULL;
-}
-
-
-static void register_interface(void)
-{
- static QTypeInfo interface_info = {
- .name = TYPE_QINTERFACE,
- .instance_size = sizeof(QInterface),
- .abstract = true,
- };
-
- qtype_register_static(&interface_info);
-}
-
-device_init(register_interface);
-
-QObject *qobject_dynamic_cast_assert(QObject *obj, const char *typename)
-{
- QObject *inst;
-
- inst = qobject_dynamic_cast(obj, typename);
-
- if (!inst) {
- fprintf(stderr, "Object %p is not an instance of type %s\n", obj, typename);
- abort();
- }
-
- return inst;
-}
-
-QObjectClass *qobject_check_class(QObjectClass *class, const char *typename)
-{
- QType target_type = qtype_get_by_name(typename);
- QType type = class->type;
-
- while (type) {
- QTypeImpl *ti = qtype_get_instance(type);
-
- if (ti->type == target_type) {
- return class;
- }
-
- type = qtype_get_by_name(ti->parent);
- }
-
- fprintf(stderr, "Object %p is not an instance of type %d\n", class, (int)type);
- abort();
-
- return NULL;
-}
-
-const char *qobject_get_type(QObject *obj)
-{
- return qtype_get_name(obj->class->type);
-}
-
-QObjectClass *qobject_get_class(QObject *obj)
-{
- return obj->class;
-}
-
-QObjectClass *qobject_get_super(QObject *obj)
-{
- return qtype_get_instance(qtype_get_by_name(qtype_get_instance(obj->class->type)->parent))->class;
-}
-
diff --git a/hw/qobject.h b/hw/qobject.h
deleted file mode 100644
index f20ed1c..0000000
--- a/hw/qobject.h
+++ /dev/null
@@ -1,471 +0,0 @@
-/*
- * QEMU Object Model
- *
- * Copyright IBM, Corp. 2011
- *
- * Authors:
- * Anthony Liguori <aliguori@us.ibm.com>
- *
- * This work is licensed under the terms of the GNU GPL, version 2 or later.
- * See the COPYING file in the top-level directory.
- *
- */
-
-#ifndef QOBJECT_H
-#define QOBJECT_H
-
-#include "qemu-common.h"
-
-typedef uint64_t QType;
-
-typedef struct QObjectClass QObjectClass;
-typedef struct QObject QObject;
-
-typedef struct QTypeInfo QTypeInfo;
-
-typedef struct QInterfaceClass QInterfaceClass;
-typedef struct QInterface QInterface;
-typedef struct QInterfaceInfo QInterfaceInfo;
-
-/**
- * @QObjectClass:
- *
- * The base for all classes. The only thing that @QObjectClass contains is an
- * integer type handle.
- */
-struct QObjectClass
-{
- /**
- * @type the handle of the type for a class
- */
- QType type;
-};
-
-/**
- * @QObject:
- *
- * The base for all objects. The first member of this object is a pointer to
- * a @QObjectClass. Since C guarantees that the first member of a structure
- * always begins at byte 0 of that structure, as long as any sub-object places
- * its parent as the first member, we can cast directly to a @QObject.
- *
- * As a result, @QObject contains a reference to the objects type as its
- * first member. This allows identification of the real type of the object at
- * run time.
- *
- * @QObject also contains a list of @QInterfaces that this object
- * implements.
- */
-struct QObject
-{
- /**
- * @class the type of the instantiated object.
- */
- QObjectClass *class;
-
- /**
- * @interfaces a list of @QInterface objects implemented by this object
- */
- GSList *interfaces;
-};
-
-/**
- * @QTypeInfo:
- *
- */
-struct QTypeInfo
-{
- /**
- * @name the name of the type
- */
- const char *name;
-
- /**
- * @parent the name of the parent type
- */
- const char *parent;
-
- /**
- * Instance Initialization
- *
- * This functions manage the instance construction and destruction of a
- * type.
- */
-
- /**
- * @instance_size the size of the object (derivative of @QObject). If
- * @instance_size is 0, then the size of the object will be the size of the
- * parent object.
- */
- size_t instance_size;
-
- /**
- * @instance_init
- *
- * This function is called to initialize an object. The parent class will
- * have already been initialized so the type is only responsible for
- * initializing its own members.
- */
- void (*instance_init)(QObject *obj);
-
- /**
- * @instance_finalize
- *
- * This function is called during object destruction. This is called before
- * the parent @instance_finalize function has been called. An object should
- * only free the members that are unique to its type in this function.
- */
- void (*instance_finalize)(QObject *obj);
-
- /**
- * @abstract
- *
- * If this field is true, then the class is considered abstract and cannot
- * be directly instantiated.
- */
- bool abstract;
-
- /**
- * Class Initialization
- *
- * Before an object is initialized, the class for the object must be
- * initialized. There is only one class object for all instance objects
- * that is created lazily.
- *
- * Classes are initialized by first initializing any parent classes (if
- * necessary). After the parent class object has initialized, it will be
- * copied into the current class object and any additional storage in the
- * class object is zero filled.
- *
- * The effect of this is that classes automatically inherit any virtual
- * function pointers that the parent class has already initialized. All
- * other fields will be zero filled.
- *
- * After this initial copy, @base_init is invoked. This is meant to handle
- * the case where a class may have a dynamic field that was copied via
- * a shallow copy but needs to be deep copied. @base_init is called for
- * each parent class but not for the class being instantiated.
- *
- * Once all of the parent classes have been initialized and their @base_init
- * functions have been called, @class_init is called to let the class being
- * instantiated provide default initialize for it's virtual functions.
- */
-
- /**
- * @class_size the size of the class object (derivative of @QObjectClass)
- * for this object. If @class_size is 0, then the size of the class will be
- * assumed to be the size of the parent class. This allows a type to avoid
- * implementing an explicit class type if they are not adding additional
- * virtual functions.
- */
- size_t class_size;
-
- /**
- * @base_init
- *
- * This function is called after memcpy()'ing the base class into the new
- * class to reinitialize any members that require deep copy.
- */
- void (*base_init)(QObjectClass *klass);
-
- /**
- * @base_finalize
- *
- * This function is called during a class's destruction and is meant to
- * allow any dynamic parameters allocated by @base_init to be released.
- */
- void (*base_finalize)(QObjectClass *klass);
-
- /**
- * @class_init
- *
- * This function is called after all parent class initialization has occured
- * to allow a class to set its default virtual method pointers. This is
- * also the function to use to override virtual methods from a parent class.
- */
- void (*class_init)(QObjectClass *klass);
-
- /**
- * @class_finalize
- *
- * This function is called during class destruction and is meant to release
- * and dynamic parameters allocated by @class_init.
- */
- void (*class_finalize)(QObjectClass *klass);
-
- /**
- * QInterfaces
- *
- * QInterfaces allow a limited form of multiple inheritance. Instances are
- * similar to normal types except for the fact that are only defined by
- * their classes and never carry any state. You can cast an object to one
- * of its @QInterface types and vice versa.
- */
-
- /**
- * @interfaces the list of interfaces associated with this type. This
- * should point to a static array that's terminated with a zero filled
- * element.
- */
- QInterfaceInfo *interfaces;
-};
-
-/**
- * @QOBJECT
- *
- * Converts an object to a @QObject. Since all objects are @QObjects,
- * this function will always succeed.
- */
-#define QOBJECT(obj) \
- ((QObject *)(obj))
-
-/**
- * @QOBJECT_CHECK
- *
- * A type safe version of @qobject_dynamic_cast_assert. Typically each class
- * will define a macro based on this type to perform type safe dynamic_casts to
- * this object type.
- *
- * If an invalid object is passed to this function, a run time assert will be
- * generated.
- */
-#define QOBJECT_CHECK(type, obj, name) \
- ((type *)qobject_dynamic_cast_assert((QObject *)(obj), (name)))
-
-/**
- * @QOBJECT_CLASS_CHECK
- *
- * A type safe version of @qobject_check_class. This macro is typically wrapped
- * by each type to perform type safe casts of a class to a specific class type.
- */
-#define QOBJECT_CLASS_CHECK(class, obj, name) \
- ((class *)qobject_check_class((QObjectClass *)(obj), (name)))
-
-/**
- * @QOBJECT_GET_CLASS
- *
- * This function will return a specific class for a given object. Its generally
- * used by each type to provide a type safe macro to get a specific class type
- * from an object.
- */
-#define QOBJECT_GET_CLASS(class, obj, name) \
- QOBJECT_CLASS_CHECK(class, qobject_get_class(QOBJECT(obj)), name)
-
-/**
- * @QQInterface:
- *
- * The base for all QInterfaces. This is a subclass of QObject. Subclasses
- * of @QInterface should never have an instance that contains anything other
- * than a single @QInterface member.
- */
-struct QInterface
-{
- /**
- * @parent base class
- */
- QObject parent;
-
- /* private */
-
- /**
- * @obj a pointer to the object that implements this interface. This is
- * used to allow casting from an interface to the base object.
- */
- QObject *obj;
-};
-
-/**
- * @QInterfaceClass:
- *
- * The class for all interfaces. Subclasses of this class should only add
- * virtual methods.
- */
-struct QInterfaceClass
-{
- /**
- * @parent_class the base class
- */
- QObjectClass parent_class;
-};
-
-/**
- * @QInterfaceInfo:
- *
- * The information associated with an interface.
- */
-struct QInterfaceInfo
-{
- /**
- * @type the name of the interface
- */
- const char *type;
-
- /**
- * @interface_initfn is called during class initialization and is used to
- * initialize an interface associated with a class. This function should
- * initialize any default virtual functions for a class and/or override
- * virtual functions in a parent class.
- */
- void (*interface_initfn)(QObjectClass *class);
-};
-
-#define TYPE_QINTERFACE "interface"
-#define QINTERFACE(obj) QOBJECT_CHECK(QInterface, obj, TYPE_QINTERFACE)
-
-/**
- * @qobject_new:
- *
- * This function will initialize a new object using heap allocated memory. This
- * function should be paired with @qobject_delete to free the resources
- * associated with the object.
- *
- * @typename: The name of the type of the object to instantiate
- *
- * Returns: The newly allocated and instantiated object.
- *
- */
-QObject *qobject_new(const char *typename);
-
-/**
- * @qobject_delete:
- *
- * Finalize an object and then free the memory associated with it. This should
- * be paired with @qobject_new to free the resources associated with an object.
- *
- * @obj: The object to free.
- *
- */
-void qobject_delete(QObject *obj);
-
-/**
- * @qobject_initialize:
- *
- * This function will initialize an object. The memory for the object should
- * have already been allocated.
- *
- * @obj: A pointer to the memory to be used for the object.
- *
- * @typename: The name of the type of the object to instantiate
- *
- */
-void qobject_initialize(void *obj, const char *typename);
-
-/**
- * @qobject_finalize:
- *
- * This function destroys and object without freeing the memory associated with
- * it.
- *
- * @obj: The object to finalize.
- *
- */
-void qobject_finalize(void *obj);
-
-/**
- * @qobject_dynamic_cast:
- *
- * This function will determine if @obj is-a @typename. @obj can refer to an
- * object or an interface associated with an object.
- *
- * @obj: The object to cast.
- *
- * @typename: The @typename
- *
- * Returns:
- *
- */
-QObject *qobject_dynamic_cast(QObject *obj, const char *typename);
-
-/**
- * @qobject_dynamic_cast_assert:
- *
- * @obj:
- *
- * @typename:
- *
- * Returns:
- *
- */
-QObject *qobject_dynamic_cast_assert(QObject *obj, const char *typename);
-
-/**
- * @qobject_is_type:
- *
- * @obj:
- *
- * @typename:
- *
- * Returns:
- *
- */
-bool qobject_is_type(QObject *obj, const char *typename);
-
-/**
- * @qobject_get_class:
- *
- * @obj:
- *
- * Returns:
- *
- */
-QObjectClass *qobject_get_class(QObject *obj);
-
-/**
- * @qobject_get_type:
- *
- * @obj:
- *
- * Returns:
- */
-const char *qobject_get_type(QObject *obj);
-
-/**
- * @qobject_get_super:
- *
- * @obj:
- *
- * Returns:
- */
-QObjectClass *qobject_get_super(QObject *obj);
-
-/**/
-
-/**
- * @qtype_register_static:
- *
- * @info:
- *
- * Returns:
- */
-QType qtype_register_static(const QTypeInfo *info);
-
-/**
- * @qobject_check_class:
- *
- * @obj:
- *
- * @typename:
- *
- * Returns:
- */
-QObjectClass *qobject_check_class(QObjectClass *obj, const char *typename);
-
-/**
- * @qtype_get_by_name:
- *
- * @name:
- *
- * Returns:
- */
-QType qtype_get_by_name(const char *name);
-
-/**
- * @qtype_get_name:
- *
- * @type:
- *
- * Returns:
- */
-const char *qtype_get_name(QType type);
-
-#endif
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 028/197] more renames
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (26 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 027/197] rename qobject -> object Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 029/197] Start integration of qom w/qdev Anthony Liguori
` (38 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/object.h | 4 ++--
hw/qdev.h | 6 +++---
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/hw/object.h b/hw/object.h
index 1ac2f92..834e89e 100644
--- a/hw/object.h
+++ b/hw/object.h
@@ -11,8 +11,8 @@
*
*/
-#ifndef QOBJECT_H
-#define QOBJECT_H
+#ifndef QEMU_OBJECT_H
+#define QEMU_OBJECT_H
#include "qemu-common.h"
diff --git a/hw/qdev.h b/hw/qdev.h
index 0702b18..aabaaa3 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -6,7 +6,7 @@
#include "qemu-char.h"
#include "qemu-option.h"
#include "qapi/qapi-visit-core.h"
-#include "qobject.h"
+#include "object.h"
typedef struct Property Property;
@@ -68,13 +68,13 @@ typedef struct DeviceProperty
} DeviceProperty;
typedef struct DeviceClass {
- QObjectClass parent_class;
+ ObjectClass parent_class;
} DeviceClass;
/* This structure should not be accessed directly. We declare it here
so that it can be embedded in individual device state structures. */
struct DeviceState {
- QObject parent_obj;
+ Object parent_obj;
const char *id;
enum DevState state;
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 029/197] Start integration of qom w/qdev.
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (27 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 028/197] more renames Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 030/197] qdev: move qdev->info to class Anthony Liguori
` (37 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/object.c | 14 ++++++++++----
hw/object.h | 16 +++++++++++++---
hw/qdev.c | 30 ++++++++++++++++++++++++++++--
3 files changed, 51 insertions(+), 9 deletions(-)
diff --git a/hw/object.c b/hw/object.c
index be61677..520591a 100644
--- a/hw/object.c
+++ b/hw/object.c
@@ -17,7 +17,7 @@
typedef struct InterfaceImpl
{
const char *parent;
- void (*interface_initfn)(ObjectClass *class);
+ void (*interface_initfn)(ObjectClass *class, void *data);
Type type;
} InterfaceImpl;
@@ -33,8 +33,10 @@ typedef struct TypeImpl
void (*base_init)(ObjectClass *klass);
void (*base_finalize)(ObjectClass *klass);
- void (*class_init)(ObjectClass *klass);
- void (*class_finalize)(ObjectClass *klass);
+ void (*class_init)(ObjectClass *klass, void *data);
+ void (*class_finalize)(ObjectClass *klass, void *data);
+
+ void *class_data;
void (*instance_init)(Object *obj);
void (*instance_finalize)(Object *obj);
@@ -61,6 +63,8 @@ Type type_register_static(const TypeInfo *info)
assert(info->name != NULL);
+ printf("Added type %s -> %s\n", info->name, info->parent);
+
ti->name = info->name;
ti->parent = info->parent;
ti->type = type;
@@ -73,6 +77,7 @@ Type type_register_static(const TypeInfo *info)
ti->class_init = info->class_init;
ti->class_finalize = info->class_finalize;
+ ti->class_data = info->class_data;
ti->instance_init = info->instance_init;
ti->instance_finalize = info->instance_finalize;
@@ -114,6 +119,7 @@ static Type type_register_anonymous(const TypeInfo *info)
ti->class_init = info->class_init;
ti->class_finalize = info->class_finalize;
+ ti->class_data = info->class_data;
ti->instance_init = info->instance_init;
ti->instance_finalize = info->instance_finalize;
@@ -237,7 +243,7 @@ static void type_class_init(TypeImpl *ti)
}
if (ti->class_init) {
- ti->class_init(ti->class);
+ ti->class_init(ti->class, ti->class_data);
}
}
diff --git a/hw/object.h b/hw/object.h
index 834e89e..b02709e 100644
--- a/hw/object.h
+++ b/hw/object.h
@@ -27,6 +27,8 @@ typedef struct InterfaceClass InterfaceClass;
typedef struct Interface Interface;
typedef struct InterfaceInfo InterfaceInfo;
+#define TYPE_OBJECT NULL
+
/**
* @ObjectClass:
*
@@ -183,7 +185,7 @@ struct TypeInfo
* to allow a class to set its default virtual method pointers. This is
* also the function to use to override virtual methods from a parent class.
*/
- void (*class_init)(ObjectClass *klass);
+ void (*class_init)(ObjectClass *klass, void *data);
/**
* @class_finalize
@@ -191,7 +193,15 @@ struct TypeInfo
* This function is called during class destruction and is meant to release
* and dynamic parameters allocated by @class_init.
*/
- void (*class_finalize)(ObjectClass *klass);
+ void (*class_finalize)(ObjectClass *klass, void *data);
+
+ /**
+ * @class_data
+ *
+ * Data to pass to the @class_init and @class_finalize functions. This can
+ * be useful when building dynamic classes.
+ */
+ void *class_data;
/**
* Interfaces
@@ -306,7 +316,7 @@ struct InterfaceInfo
* initialize any default virtual functions for a class and/or override
* virtual functions in a parent class.
*/
- void (*interface_initfn)(ObjectClass *class);
+ void (*interface_initfn)(ObjectClass *class, void *data);
};
#define TYPE_INTERFACE "interface"
diff --git a/hw/qdev.c b/hw/qdev.c
index 83913c7..7a5aa9f 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -44,12 +44,23 @@ static BusState *qbus_find_recursive(BusState *bus, const char *name,
const BusInfo *info);
static BusState *qbus_find(const char *path);
+#define TYPE_DEVICE "device"
+#define DEVICE(obj) OBJECT_CHECK(DeviceState, (obj), TYPE_DEVICE)
+
/* Register a new device type. */
void qdev_register(DeviceInfo *info)
{
+ TypeInfo type_info = {};
+
assert(info->size >= sizeof(DeviceState));
assert(!info->next);
+ type_info.name = info->name;
+ type_info.parent = TYPE_DEVICE;
+ type_info.instance_size = info->size;
+
+ type_register_static(&type_info);
+
info->next = device_info_list;
device_info_list = info;
}
@@ -86,7 +97,7 @@ static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info)
Property *prop;
assert(bus->info == info->bus_info);
- dev = g_malloc0(info->size);
+ dev = DEVICE(object_new(info->name));
dev->info = info;
dev->parent_bus = bus;
qdev_prop_set_defaults(dev, dev->info->props);
@@ -484,7 +495,7 @@ void qdev_free(DeviceState *dev)
prop->info->free(dev, prop);
}
}
- g_free(dev);
+ object_delete(OBJECT(dev));
}
void qdev_machine_creation_done(void)
@@ -1515,3 +1526,18 @@ void qdev_property_add_str(DeviceState *dev, const char *name,
qdev_property_release_str,
prop, errp);
}
+
+static TypeInfo device_type_info = {
+ .name = TYPE_DEVICE,
+ .parent = TYPE_OBJECT,
+ .instance_size = sizeof(DeviceState),
+ .abstract = true,
+ .class_size = sizeof(DeviceClass),
+};
+
+static void init_qdev(void)
+{
+ type_register_static(&device_type_info);
+}
+
+device_init(init_qdev);
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 030/197] qdev: move qdev->info to class
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (28 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 029/197] Start integration of qom w/qdev Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 031/197] qdev: don't access name through info Anthony Liguori
` (36 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
Use an accessor to let clients cope.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
hw/acpi_piix4.c | 4 +-
hw/cirrus_vga.c | 2 +-
hw/e1000.c | 2 +-
hw/eepro100.c | 4 +-
hw/hda-audio.c | 2 +-
hw/ide/piix.c | 6 ++++
hw/intel-hda.c | 6 ++--
hw/lsi53c895a.c | 2 +-
hw/ne2000-isa.c | 2 +-
hw/ne2000.c | 2 +-
hw/pci.c | 14 ++++----
hw/pcnet.c | 2 +-
hw/qdev-properties.c | 20 ++++++------
hw/qdev.c | 72 ++++++++++++++++++++++++++++-------------------
hw/qdev.h | 14 ++++++++-
hw/rtl8139.c | 2 +-
hw/usb-bus.c | 2 +-
hw/usb-ccid.c | 2 +-
hw/usb-net.c | 2 +-
hw/usb-ohci.c | 2 +-
hw/virtio-console.c | 2 +-
hw/virtio-net.c | 2 +-
hw/virtio-serial-bus.c | 8 ++--
23 files changed, 103 insertions(+), 73 deletions(-)
diff --git a/hw/acpi_piix4.c b/hw/acpi_piix4.c
index 401baaa..697f0de 100644
--- a/hw/acpi_piix4.c
+++ b/hw/acpi_piix4.c
@@ -277,7 +277,7 @@ static void piix4_update_hotplug(PIIX4PMState *s)
s->pci0_hotplug_enable = ~0;
QTAILQ_FOREACH_SAFE(qdev, &bus->children, sibling, next) {
- PCIDeviceInfo *info = container_of(qdev->info, PCIDeviceInfo, qdev);
+ PCIDeviceInfo *info = container_of(qdev_get_info(qdev), PCIDeviceInfo, qdev);
PCIDevice *pdev = DO_UPCAST(PCIDevice, qdev, qdev);
int slot = PCI_SLOT(pdev->devfn);
@@ -489,7 +489,7 @@ static void pciej_write(void *opaque, uint32_t addr, uint32_t val)
QTAILQ_FOREACH_SAFE(qdev, &bus->children, sibling, next) {
dev = DO_UPCAST(PCIDevice, qdev, qdev);
- info = container_of(qdev->info, PCIDeviceInfo, qdev);
+ info = container_of(qdev_get_info(qdev), PCIDeviceInfo, qdev);
if (PCI_SLOT(dev->devfn) == slot && !info->no_hotplug) {
qdev_free(qdev);
}
diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c
index c0db315..d6d9d70 100644
--- a/hw/cirrus_vga.c
+++ b/hw/cirrus_vga.c
@@ -2927,7 +2927,7 @@ static int pci_cirrus_vga_initfn(PCIDevice *dev)
{
PCICirrusVGAState *d = DO_UPCAST(PCICirrusVGAState, dev, dev);
CirrusVGAState *s = &d->cirrus_vga;
- PCIDeviceInfo *info = DO_UPCAST(PCIDeviceInfo, qdev, dev->qdev.info);
+ PCIDeviceInfo *info = DO_UPCAST(PCIDeviceInfo, qdev, qdev_get_info(&dev->qdev));
int16_t device_id = info->device_id;
/* setup VGA */
diff --git a/hw/e1000.c b/hw/e1000.c
index 986ed9c..ce30ad8 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -1175,7 +1175,7 @@ static int pci_e1000_init(PCIDevice *pci_dev)
d->eeprom_data[EEPROM_CHECKSUM_REG] = checksum;
d->nic = qemu_new_nic(&net_e1000_info, &d->conf,
- d->dev.qdev.info->name, d->dev.qdev.id, d);
+ qdev_get_info(&d->dev.qdev)->name, d->dev.qdev.id, d);
qemu_format_nic_info_str(&d->nic->nc, macaddr);
diff --git a/hw/eepro100.c b/hw/eepro100.c
index 29ec5b4..287d1f1 100644
--- a/hw/eepro100.c
+++ b/hw/eepro100.c
@@ -1849,7 +1849,7 @@ static int e100_nic_init(PCIDevice *pci_dev)
{
EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, pci_dev);
E100PCIDeviceInfo *e100_device = DO_UPCAST(E100PCIDeviceInfo, pci.qdev,
- pci_dev->qdev.info);
+ qdev_get_info(&pci_dev->qdev));
TRACE(OTHER, logout("\n"));
@@ -1879,7 +1879,7 @@ static int e100_nic_init(PCIDevice *pci_dev)
nic_reset(s);
s->nic = qemu_new_nic(&net_eepro100_info, &s->conf,
- pci_dev->qdev.info->name, pci_dev->qdev.id, s);
+ qdev_get_info(&pci_dev->qdev)->name, pci_dev->qdev.id, s);
qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
TRACE(OTHER, logout("%s\n", s->nic->nc.info_str));
diff --git a/hw/hda-audio.c b/hw/hda-audio.c
index 9b089e6..0bc0a25 100644
--- a/hw/hda-audio.c
+++ b/hw/hda-audio.c
@@ -777,7 +777,7 @@ static int hda_audio_init(HDACodecDevice *hda, const struct desc_codec *desc)
uint32_t i, type;
a->desc = desc;
- a->name = a->hda.qdev.info->name;
+ a->name = qdev_get_info(&a->hda.qdev)->name;
dprint(a, 1, "%s: cad %d\n", __FUNCTION__, a->hda.cad);
AUD_register_card("hda", &a->card);
diff --git a/hw/ide/piix.c b/hw/ide/piix.c
index 08cbbe2..7d8f2c7 100644
--- a/hw/ide/piix.c
+++ b/hw/ide/piix.c
@@ -164,6 +164,7 @@ static int pci_piix_ide_initfn(PCIDevice *dev)
return 0;
}
+#if 0
static int pci_piix3_xen_ide_unplug(DeviceState *dev)
{
PCIDevice *pci_dev;
@@ -189,13 +190,18 @@ static int pci_piix3_xen_ide_unplug(DeviceState *dev)
qdev_reset_all(&(pci_ide->dev.qdev));
return 0;
}
+#endif
PCIDevice *pci_piix3_xen_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn)
{
PCIDevice *dev;
dev = pci_create_simple(bus, devfn, "piix3-ide-xen");
+ /* FIXME: BROKEN! */
+ abort();
+#if 0
dev->qdev.info->unplug = pci_piix3_xen_ide_unplug;
+#endif
pci_ide_create_devs(dev, hd_table);
return dev;
}
diff --git a/hw/intel-hda.c b/hw/intel-hda.c
index 10769e0..12dcc84 100644
--- a/hw/intel-hda.c
+++ b/hw/intel-hda.c
@@ -1116,8 +1116,8 @@ static void intel_hda_reset(DeviceState *dev)
/* reset codecs */
QTAILQ_FOREACH(qdev, &d->codecs.qbus.children, sibling) {
cdev = DO_UPCAST(HDACodecDevice, qdev, qdev);
- if (qdev->info->reset) {
- qdev->info->reset(qdev);
+ if (qdev_get_info(qdev)->reset) {
+ qdev_get_info(qdev)->reset(qdev);
}
d->state_sts |= (1 << cdev->cad);
}
@@ -1129,7 +1129,7 @@ static int intel_hda_init(PCIDevice *pci)
IntelHDAState *d = DO_UPCAST(IntelHDAState, pci, pci);
uint8_t *conf = d->pci.config;
- d->name = d->pci.qdev.info->name;
+ d->name = qdev_get_info(&d->pci.qdev)->name;
pci_config_set_interrupt_pin(conf, 1);
diff --git a/hw/lsi53c895a.c b/hw/lsi53c895a.c
index fcc27d7..b313f83 100644
--- a/hw/lsi53c895a.c
+++ b/hw/lsi53c895a.c
@@ -1681,7 +1681,7 @@ static void lsi_reg_writeb(LSIState *s, int offset, uint8_t val)
DeviceState *dev;
QTAILQ_FOREACH(dev, &s->bus.qbus.children, sibling) {
- dev->info->reset(dev);
+ qdev_get_info(dev)->reset(dev);
}
s->sstat0 |= LSI_SSTAT0_RST;
lsi_script_scsi_interrupt(s, LSI_SIST0_RST, 0);
diff --git a/hw/ne2000-isa.c b/hw/ne2000-isa.c
index 11ffee7..60dc333 100644
--- a/hw/ne2000-isa.c
+++ b/hw/ne2000-isa.c
@@ -76,7 +76,7 @@ static int isa_ne2000_initfn(ISADevice *dev)
ne2000_reset(s);
s->nic = qemu_new_nic(&net_ne2000_isa_info, &s->c,
- dev->qdev.info->name, dev->qdev.id, s);
+ qdev_get_info(&dev->qdev)->name, dev->qdev.id, s);
qemu_format_nic_info_str(&s->nic->nc, s->c.macaddr.a);
return 0;
diff --git a/hw/ne2000.c b/hw/ne2000.c
index 62e082f..d016b8e 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -760,7 +760,7 @@ static int pci_ne2000_init(PCIDevice *pci_dev)
ne2000_reset(s);
s->nic = qemu_new_nic(&net_ne2000_info, &s->c,
- pci_dev->qdev.info->name, pci_dev->qdev.id, s);
+ qdev_get_info(&pci_dev->qdev)->name, pci_dev->qdev.id, s);
qemu_format_nic_info_str(&s->nic->nc, s->c.macaddr.a);
if (!pci_dev->qdev.hotplugged) {
diff --git a/hw/pci.c b/hw/pci.c
index 399227f..46b7dac 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -161,7 +161,7 @@ void pci_device_reset(PCIDevice *dev)
int r;
/* TODO: call the below unconditionally once all pci devices
* are qdevified */
- if (dev->qdev.info) {
+ if (qdev_get_info(&dev->qdev)) {
qdev_reset_all(&dev->qdev);
}
@@ -844,7 +844,7 @@ static void pci_unregister_io_regions(PCIDevice *pci_dev)
static int pci_unregister_device(DeviceState *dev)
{
PCIDevice *pci_dev = DO_UPCAST(PCIDevice, qdev, dev);
- PCIDeviceInfo *info = DO_UPCAST(PCIDeviceInfo, qdev, dev->info);
+ PCIDeviceInfo *info = DO_UPCAST(PCIDeviceInfo, qdev, qdev_get_info(dev));
int ret = 0;
if (info->exit)
@@ -1534,7 +1534,7 @@ static int pci_qdev_init(DeviceState *qdev, DeviceInfo *base)
static int pci_unplug_device(DeviceState *qdev)
{
PCIDevice *dev = DO_UPCAST(PCIDevice, qdev, qdev);
- PCIDeviceInfo *info = container_of(qdev->info, PCIDeviceInfo, qdev);
+ PCIDeviceInfo *info = container_of(qdev_get_info(qdev), PCIDeviceInfo, qdev);
if (info->no_hotplug) {
qerror_report(QERR_DEVICE_NO_HOTPLUG, info->qdev.name);
@@ -1760,10 +1760,10 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)
size = 1 << qemu_fls(size);
}
- if (pdev->qdev.info->vmsd)
- snprintf(name, sizeof(name), "%s.rom", pdev->qdev.info->vmsd->name);
+ if (qdev_get_info(&pdev->qdev)->vmsd)
+ snprintf(name, sizeof(name), "%s.rom", qdev_get_info(&pdev->qdev)->vmsd->name);
else
- snprintf(name, sizeof(name), "%s.rom", pdev->qdev.info->name);
+ snprintf(name, sizeof(name), "%s.rom", qdev_get_info(&pdev->qdev)->name);
pdev->has_rom = true;
memory_region_init_ram(&pdev->rom, &pdev->qdev, name, size);
ptr = memory_region_get_ram_ptr(&pdev->rom);
@@ -2002,7 +2002,7 @@ static int pci_qdev_find_recursive(PCIBus *bus,
}
/* roughly check if given qdev is pci device */
- if (qdev->info->init == &pci_qdev_init &&
+ if (qdev_get_info(qdev)->init == &pci_qdev_init &&
qdev->parent_bus->info == &pci_bus_info) {
*pdev = DO_UPCAST(PCIDevice, qdev, qdev);
return 0;
diff --git a/hw/pcnet.c b/hw/pcnet.c
index cba253b..e58b195 100644
--- a/hw/pcnet.c
+++ b/hw/pcnet.c
@@ -1718,7 +1718,7 @@ int pcnet_common_init(DeviceState *dev, PCNetState *s, NetClientInfo *info)
s->poll_timer = qemu_new_timer_ns(vm_clock, pcnet_poll_timer, s);
qemu_macaddr_default_if_unset(&s->conf.macaddr);
- s->nic = qemu_new_nic(info, &s->conf, dev->info->name, dev->id, s);
+ s->nic = qemu_new_nic(info, &s->conf, qdev_get_info(dev)->name, dev->id, s);
qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
add_boot_device_path(s->conf.bootindex, dev, "/ethernet-phy@0");
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index f0b811c..f235a26 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -597,7 +597,7 @@ static Property *qdev_prop_find(DeviceState *dev, const char *name)
Property *prop;
/* device properties */
- prop = qdev_prop_walk(dev->info->props, name);
+ prop = qdev_prop_walk(qdev_get_info(dev)->props, name);
if (prop)
return prop;
@@ -627,7 +627,7 @@ int qdev_prop_parse(DeviceState *dev, const char *name, const char *value)
* removed along with it.
*/
if (!prop || !prop->info->parse) {
- qerror_report(QERR_PROPERTY_NOT_FOUND, dev->info->name, name);
+ qerror_report(QERR_PROPERTY_NOT_FOUND, qdev_get_info(dev)->name, name);
return -1;
}
ret = prop->info->parse(dev, prop, value);
@@ -635,16 +635,16 @@ int qdev_prop_parse(DeviceState *dev, const char *name, const char *value)
switch (ret) {
case -EEXIST:
qerror_report(QERR_PROPERTY_VALUE_IN_USE,
- dev->info->name, name, value);
+ qdev_get_info(dev)->name, name, value);
break;
default:
case -EINVAL:
qerror_report(QERR_PROPERTY_VALUE_BAD,
- dev->info->name, name, value);
+ qdev_get_info(dev)->name, name, value);
break;
case -ENOENT:
qerror_report(QERR_PROPERTY_VALUE_NOT_FOUND,
- dev->info->name, name, value);
+ qdev_get_info(dev)->name, name, value);
break;
}
return -1;
@@ -659,12 +659,12 @@ void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyT
prop = qdev_prop_find(dev, name);
if (!prop) {
fprintf(stderr, "%s: property \"%s.%s\" not found\n",
- __FUNCTION__, dev->info->name, name);
+ __FUNCTION__, qdev_get_info(dev)->name, name);
abort();
}
if (prop->info->type != type) {
fprintf(stderr, "%s: property \"%s.%s\" type mismatch\n",
- __FUNCTION__, dev->info->name, name);
+ __FUNCTION__, qdev_get_info(dev)->name, name);
abort();
}
qdev_prop_cpy(dev, prop, src);
@@ -713,7 +713,7 @@ int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *va
if (res < 0) {
error_report("Can't attach drive %s to %s.%s: %s",
bdrv_get_device_name(value),
- dev->id ? dev->id : dev->info->name,
+ dev->id ? dev->id : qdev_get_info(dev)->name,
name, strerror(-res));
return -1;
}
@@ -785,8 +785,8 @@ void qdev_prop_set_globals(DeviceState *dev)
GlobalProperty *prop;
QTAILQ_FOREACH(prop, &global_props, next) {
- if (strcmp(dev->info->name, prop->driver) != 0 &&
- strcmp(dev->info->bus_info->name, prop->driver) != 0) {
+ if (strcmp(qdev_get_info(dev)->name, prop->driver) != 0 &&
+ strcmp(qdev_get_info(dev)->bus_info->name, prop->driver) != 0) {
continue;
}
if (qdev_prop_parse(dev, prop->property, prop->value) != 0) {
diff --git a/hw/qdev.c b/hw/qdev.c
index 7a5aa9f..2edbc61 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -46,8 +46,21 @@ static BusState *qbus_find(const char *path);
#define TYPE_DEVICE "device"
#define DEVICE(obj) OBJECT_CHECK(DeviceState, (obj), TYPE_DEVICE)
+#define DEVICE_CLASS(klass) OBJECT_CLASS_CHECK(DeviceClass, (klass), TYPE_DEVICE)
+#define DEVICE_GET_CLASS(obj) OBJECT_GET_CLASS(DeviceClass, (obj), TYPE_DEVICE)
/* Register a new device type. */
+static void qdev_subclass_init(ObjectClass *klass, void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(klass);
+ dc->info = data;
+}
+
+DeviceInfo *qdev_get_info(DeviceState *dev)
+{
+ return DEVICE_GET_CLASS(dev)->info;
+}
+
void qdev_register(DeviceInfo *info)
{
TypeInfo type_info = {};
@@ -58,6 +71,8 @@ void qdev_register(DeviceInfo *info)
type_info.name = info->name;
type_info.parent = TYPE_DEVICE;
type_info.instance_size = info->size;
+ type_info.class_init = qdev_subclass_init;
+ type_info.class_data = info;
type_register_static(&type_info);
@@ -98,9 +113,8 @@ static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info)
assert(bus->info == info->bus_info);
dev = DEVICE(object_new(info->name));
- dev->info = info;
dev->parent_bus = bus;
- qdev_prop_set_defaults(dev, dev->info->props);
+ qdev_prop_set_defaults(dev, qdev_get_info(dev)->props);
qdev_prop_set_defaults(dev, dev->parent_bus->info->props);
qdev_prop_set_globals(dev);
QTAILQ_INSERT_HEAD(&bus->children, dev, sibling);
@@ -113,11 +127,11 @@ static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info)
QTAILQ_INIT(&dev->properties);
dev->state = DEV_STATE_CREATED;
- for (prop = dev->info->props; prop && prop->name; prop++) {
+ for (prop = qdev_get_info(dev)->props; prop && prop->name; prop++) {
qdev_property_add_legacy(dev, prop, NULL);
}
- for (prop = dev->info->bus_info->props; prop && prop->name; prop++) {
+ for (prop = qdev_get_info(dev)->bus_info->props; prop && prop->name; prop++) {
qdev_property_add_legacy(dev, prop, NULL);
}
@@ -347,19 +361,19 @@ int qdev_init(DeviceState *dev)
int rc;
assert(dev->state == DEV_STATE_CREATED);
- rc = dev->info->init(dev, dev->info);
+ rc = qdev_get_info(dev)->init(dev, qdev_get_info(dev));
if (rc < 0) {
qdev_free(dev);
return rc;
}
- if (dev->info->vmsd) {
- vmstate_register_with_alias_id(dev, -1, dev->info->vmsd, dev,
+ if (qdev_get_info(dev)->vmsd) {
+ vmstate_register_with_alias_id(dev, -1, qdev_get_info(dev)->vmsd, dev,
dev->instance_id_alias,
dev->alias_required_for_version);
}
dev->state = DEV_STATE_INITIALIZED;
- if (dev->hotplugged && dev->info->reset) {
- dev->info->reset(dev);
+ if (dev->hotplugged && qdev_get_info(dev)->reset) {
+ qdev_get_info(dev)->reset(dev);
}
return 0;
}
@@ -378,7 +392,7 @@ int qdev_unplug(DeviceState *dev)
qerror_report(QERR_BUS_NO_HOTPLUG, dev->parent_bus->name);
return -1;
}
- assert(dev->info->unplug != NULL);
+ assert(qdev_get_info(dev)->unplug != NULL);
if (dev->ref != 0) {
qerror_report(QERR_DEVICE_IN_USE, dev->id?:"");
@@ -387,13 +401,13 @@ int qdev_unplug(DeviceState *dev)
qdev_hot_removed = true;
- return dev->info->unplug(dev);
+ return qdev_get_info(dev)->unplug(dev);
}
static int qdev_reset_one(DeviceState *dev, void *opaque)
{
- if (dev->info->reset) {
- dev->info->reset(dev);
+ if (qdev_get_info(dev)->reset) {
+ qdev_get_info(dev)->reset(dev);
}
return 0;
@@ -444,7 +458,7 @@ int qdev_simple_unplug_cb(DeviceState *dev)
way is somewhat unclean, and best avoided. */
void qdev_init_nofail(DeviceState *dev)
{
- DeviceInfo *info = dev->info;
+ DeviceInfo *info = qdev_get_info(dev);
if (qdev_init(dev) < 0) {
error_report("Initialization of device %s failed", info->name);
@@ -482,15 +496,15 @@ void qdev_free(DeviceState *dev)
bus = QLIST_FIRST(&dev->child_bus);
qbus_free(bus);
}
- if (dev->info->vmsd)
- vmstate_unregister(dev, dev->info->vmsd, dev);
- if (dev->info->exit)
- dev->info->exit(dev);
+ if (qdev_get_info(dev)->vmsd)
+ vmstate_unregister(dev, qdev_get_info(dev)->vmsd, dev);
+ if (qdev_get_info(dev)->exit)
+ qdev_get_info(dev)->exit(dev);
if (dev->opts)
qemu_opts_del(dev->opts);
}
QTAILQ_REMOVE(&dev->parent_bus->children, dev, sibling);
- for (prop = dev->info->props; prop && prop->name; prop++) {
+ for (prop = qdev_get_info(dev)->props; prop && prop->name; prop++) {
if (prop->info->free) {
prop->info->free(dev, prop);
}
@@ -676,7 +690,7 @@ static void qbus_list_bus(DeviceState *dev)
const char *sep = " ";
error_printf("child busses at \"%s\":",
- dev->id ? dev->id : dev->info->name);
+ dev->id ? dev->id : qdev_get_info(dev)->name);
QLIST_FOREACH(child, &dev->child_bus, sibling) {
error_printf("%s\"%s\"", sep, child->name);
sep = ", ";
@@ -691,7 +705,7 @@ static void qbus_list_dev(BusState *bus)
error_printf("devices at \"%s\":", bus->name);
QTAILQ_FOREACH(dev, &bus->children, sibling) {
- error_printf("%s\"%s\"", sep, dev->info->name);
+ error_printf("%s\"%s\"", sep, qdev_get_info(dev)->name);
if (dev->id)
error_printf("/\"%s\"", dev->id);
sep = ", ";
@@ -727,12 +741,12 @@ static DeviceState *qbus_find_dev(BusState *bus, char *elem)
}
}
QTAILQ_FOREACH(dev, &bus->children, sibling) {
- if (strcmp(dev->info->name, elem) == 0) {
+ if (strcmp(qdev_get_info(dev)->name, elem) == 0) {
return dev;
}
}
QTAILQ_FOREACH(dev, &bus->children, sibling) {
- if (dev->info->alias && strcmp(dev->info->alias, elem) == 0) {
+ if (qdev_get_info(dev)->alias && strcmp(qdev_get_info(dev)->alias, elem) == 0) {
return dev;
}
}
@@ -934,7 +948,7 @@ static void qdev_print_props(Monitor *mon, DeviceState *dev, Property *props,
static void qdev_print(Monitor *mon, DeviceState *dev, int indent)
{
BusState *child;
- qdev_printf("dev: %s, id \"%s\"\n", dev->info->name,
+ qdev_printf("dev: %s, id \"%s\"\n", qdev_get_info(dev)->name,
dev->id ? dev->id : "");
indent += 2;
if (dev->num_gpio_in) {
@@ -943,7 +957,7 @@ 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, dev->info->props, "dev", indent);
+ qdev_print_props(mon, dev, qdev_get_info(dev)->props, "dev", indent);
qdev_print_props(mon, dev, dev->parent_bus->info->props, "bus", indent);
if (dev->parent_bus->info->print_dev)
dev->parent_bus->info->print_dev(mon, dev, indent);
@@ -1024,7 +1038,7 @@ static int qdev_get_fw_dev_path_helper(DeviceState *dev, char *p, int size)
l += snprintf(p + l, size - l, "%s", d);
g_free(d);
} else {
- l += snprintf(p + l, size - l, "%s", dev->info->name);
+ l += snprintf(p + l, size - l, "%s", qdev_get_info(dev)->name);
}
}
l += snprintf(p + l , size - l, "/");
@@ -1046,7 +1060,7 @@ char* qdev_get_fw_dev_path(DeviceState *dev)
char *qdev_get_type(DeviceState *dev, Error **errp)
{
- return g_strdup(dev->info->name);
+ return g_strdup(qdev_get_info(dev)->name);
}
void qdev_ref(DeviceState *dev)
@@ -1241,7 +1255,7 @@ void qdev_property_add_child(DeviceState *dev, const char *name,
{
gchar *type;
- type = g_strdup_printf("child<%s>", child->info->name);
+ type = g_strdup_printf("child<%s>", qdev_get_info(child)->name);
qdev_property_add(dev, name, type, qdev_get_child_property,
NULL, NULL, child, errp);
@@ -1292,7 +1306,7 @@ static void qdev_set_link_property(DeviceState *dev, Visitor *v, void *opaque,
if (target) {
gchar *target_type;
- target_type = g_strdup_printf("link<%s>", target->info->name);
+ target_type = g_strdup_printf("link<%s>", qdev_get_info(target)->name);
if (strcmp(target_type, type) == 0) {
*child = target;
qdev_ref(target);
diff --git a/hw/qdev.h b/hw/qdev.h
index aabaaa3..01dd1d6 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -69,6 +69,7 @@ typedef struct DeviceProperty
typedef struct DeviceClass {
ObjectClass parent_class;
+ DeviceInfo *info;
} DeviceClass;
/* This structure should not be accessed directly. We declare it here
@@ -80,7 +81,6 @@ struct DeviceState {
enum DevState state;
QemuOpts *opts;
int hotplugged;
- DeviceInfo *info;
BusState *parent_bus;
int num_gpio_out;
qemu_irq *gpio_out;
@@ -378,9 +378,19 @@ void qdev_prop_set_defaults(DeviceState *dev, Property *props);
void qdev_prop_register_global_list(GlobalProperty *props);
void qdev_prop_set_globals(DeviceState *dev);
+DeviceInfo *qdev_get_info(DeviceState *dev);
+
static inline const char *qdev_fw_name(DeviceState *dev)
{
- return dev->info->fw_name ? : dev->info->alias ? : dev->info->name;
+ DeviceInfo *info = qdev_get_info(dev);
+
+ if (info->fw_name) {
+ return info->fw_name;
+ } else if (info->alias) {
+ return info->alias;
+ }
+
+ return info->name;
}
char *qdev_get_fw_dev_path(DeviceState *dev);
diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index aa8ed0a..c087506 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -3478,7 +3478,7 @@ static int pci_rtl8139_init(PCIDevice *dev)
s->eeprom.contents[9] = s->conf.macaddr.a[4] | s->conf.macaddr.a[5] << 8;
s->nic = qemu_new_nic(&net_rtl8139_info, &s->conf,
- dev->qdev.info->name, dev->qdev.id, s);
+ qdev_get_info(&dev->qdev)->name, dev->qdev.id, s);
qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
s->cplus_txbuffer = NULL;
diff --git a/hw/usb-bus.c b/hw/usb-bus.c
index 8cafb76..e1bcab1 100644
--- a/hw/usb-bus.c
+++ b/hw/usb-bus.c
@@ -251,7 +251,7 @@ int usb_claim_port(USBDevice *dev)
return -1;
}
} else {
- if (bus->nfree == 1 && strcmp(dev->qdev.info->name, "usb-hub") != 0) {
+ if (bus->nfree == 1 && strcmp(qdev_get_info(&dev->qdev)->name, "usb-hub") != 0) {
/* Create a new hub and chain it on */
usb_create_simple(bus, "usb-hub");
}
diff --git a/hw/usb-ccid.c b/hw/usb-ccid.c
index cd349f3..8a79729 100644
--- a/hw/usb-ccid.c
+++ b/hw/usb-ccid.c
@@ -1122,7 +1122,7 @@ static int ccid_card_exit(DeviceState *qdev)
{
int ret = 0;
CCIDCardState *card = DO_UPCAST(CCIDCardState, qdev, qdev);
- CCIDCardInfo *info = DO_UPCAST(CCIDCardInfo, qdev, qdev->info);
+ CCIDCardInfo *info = DO_UPCAST(CCIDCardInfo, qdev, qdev_get_info(qdev));
USBCCIDState *s =
DO_UPCAST(USBCCIDState, dev.qdev, card->qdev.parent_bus->parent);
diff --git a/hw/usb-net.c b/hw/usb-net.c
index a8b7c8d..5d7bfcf 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -1350,7 +1350,7 @@ static int usb_net_initfn(USBDevice *dev)
qemu_macaddr_default_if_unset(&s->conf.macaddr);
s->nic = qemu_new_nic(&net_usbnet_info, &s->conf,
- s->dev.qdev.info->name, s->dev.qdev.id, s);
+ qdev_get_info(&s->dev.qdev)->name, s->dev.qdev.id, s);
qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
snprintf(s->usbstring_mac, sizeof(s->usbstring_mac),
"%02x%02x%02x%02x%02x%02x",
diff --git a/hw/usb-ohci.c b/hw/usb-ohci.c
index c2981c5..51c96b7 100644
--- a/hw/usb-ohci.c
+++ b/hw/usb-ohci.c
@@ -1775,7 +1775,7 @@ static int usb_ohci_init(OHCIState *ohci, DeviceState *dev,
memory_region_init_io(&ohci->mem, &ohci_mem_ops, ohci, "ohci", 256);
ohci->localmem_base = localmem_base;
- ohci->name = dev->info->name;
+ ohci->name = qdev_get_info(dev)->name;
usb_packet_init(&ohci->usb_packet);
ohci->async_td = 0;
diff --git a/hw/virtio-console.c b/hw/virtio-console.c
index d3351c8..f922400 100644
--- a/hw/virtio-console.c
+++ b/hw/virtio-console.c
@@ -99,7 +99,7 @@ static int virtconsole_initfn(VirtIOSerialPort *port)
{
VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
VirtIOSerialPortInfo *info = DO_UPCAST(VirtIOSerialPortInfo, qdev,
- vcon->port.dev.info);
+ qdev_get_info(&vcon->port.dev));
if (port->id == 0 && !info->is_console) {
error_report("Port number 0 on virtio-serial devices reserved for virtconsole devices for backward compatibility.");
diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 8c2f460..6c785d0 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -1030,7 +1030,7 @@ VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf,
memcpy(&n->mac[0], &conf->macaddr, sizeof(n->mac));
n->status = VIRTIO_NET_S_LINK_UP;
- n->nic = qemu_new_nic(&net_virtio_info, conf, dev->info->name, dev->id, n);
+ n->nic = qemu_new_nic(&net_virtio_info, conf, qdev_get_info(dev)->name, dev->id, n);
qemu_format_nic_info_str(&n->nic->nc, conf->macaddr.a);
diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
index a4825b9..b9c8ca7 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/virtio-serial-bus.c
@@ -135,7 +135,7 @@ static void do_flush_queued_data(VirtIOSerialPort *port, VirtQueue *vq,
assert(port);
assert(virtio_queue_ready(vq));
- info = DO_UPCAST(VirtIOSerialPortInfo, qdev, port->dev.info);
+ info = DO_UPCAST(VirtIOSerialPortInfo, qdev, qdev_get_info(&port->dev));
while (!port->throttled) {
unsigned int i;
@@ -358,7 +358,7 @@ static void handle_control_message(VirtIOSerial *vser, void *buf, size_t len)
trace_virtio_serial_handle_control_message_port(port->id);
- info = DO_UPCAST(VirtIOSerialPortInfo, qdev, port->dev.info);
+ info = DO_UPCAST(VirtIOSerialPortInfo, qdev, qdev_get_info(&port->dev));
switch(cpkt.event) {
case VIRTIO_CONSOLE_PORT_READY:
@@ -470,7 +470,7 @@ static void handle_output(VirtIODevice *vdev, VirtQueue *vq)
vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
port = find_port_by_vq(vser, vq);
- info = port ? DO_UPCAST(VirtIOSerialPortInfo, qdev, port->dev.info) : NULL;
+ info = port ? DO_UPCAST(VirtIOSerialPortInfo, qdev, qdev_get_info(&port->dev)) : NULL;
if (!port || !port->host_connected || !info->have_data) {
discard_vq_data(vq, vdev);
@@ -809,7 +809,7 @@ static int virtser_port_qdev_exit(DeviceState *qdev)
{
VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, qdev);
VirtIOSerialPortInfo *info = DO_UPCAST(VirtIOSerialPortInfo, qdev,
- port->dev.info);
+ qdev_get_info(&port->dev));
VirtIOSerial *vser = port->vser;
qemu_bh_delete(port->bh);
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 031/197] qdev: don't access name through info
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (29 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 030/197] qdev: move qdev->info to class Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 032/197] qdev: user a wrapper to access reset and promote reset to a class method Anthony Liguori
` (35 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
hw/e1000.c | 2 +-
hw/eepro100.c | 2 +-
hw/hda-audio.c | 2 +-
hw/intel-hda.c | 2 +-
hw/ne2000-isa.c | 2 +-
hw/ne2000.c | 2 +-
hw/pci.c | 2 +-
hw/pcnet.c | 2 +-
hw/qdev-properties.c | 16 ++++++++--------
hw/qdev.c | 16 ++++++++--------
hw/rtl8139.c | 2 +-
hw/usb-bus.c | 2 +-
hw/usb-net.c | 2 +-
hw/usb-ohci.c | 2 +-
hw/virtio-net.c | 2 +-
15 files changed, 29 insertions(+), 29 deletions(-)
diff --git a/hw/e1000.c b/hw/e1000.c
index ce30ad8..2f495cd 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -1175,7 +1175,7 @@ static int pci_e1000_init(PCIDevice *pci_dev)
d->eeprom_data[EEPROM_CHECKSUM_REG] = checksum;
d->nic = qemu_new_nic(&net_e1000_info, &d->conf,
- qdev_get_info(&d->dev.qdev)->name, d->dev.qdev.id, d);
+ object_get_type(OBJECT(d)), d->dev.qdev.id, d);
qemu_format_nic_info_str(&d->nic->nc, macaddr);
diff --git a/hw/eepro100.c b/hw/eepro100.c
index 287d1f1..1f9f610 100644
--- a/hw/eepro100.c
+++ b/hw/eepro100.c
@@ -1879,7 +1879,7 @@ static int e100_nic_init(PCIDevice *pci_dev)
nic_reset(s);
s->nic = qemu_new_nic(&net_eepro100_info, &s->conf,
- qdev_get_info(&pci_dev->qdev)->name, pci_dev->qdev.id, s);
+ object_get_type(OBJECT(pci_dev)), pci_dev->qdev.id, s);
qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
TRACE(OTHER, logout("%s\n", s->nic->nc.info_str));
diff --git a/hw/hda-audio.c b/hw/hda-audio.c
index 0bc0a25..ffdd799 100644
--- a/hw/hda-audio.c
+++ b/hw/hda-audio.c
@@ -777,7 +777,7 @@ static int hda_audio_init(HDACodecDevice *hda, const struct desc_codec *desc)
uint32_t i, type;
a->desc = desc;
- a->name = qdev_get_info(&a->hda.qdev)->name;
+ a->name = object_get_type(OBJECT(a));
dprint(a, 1, "%s: cad %d\n", __FUNCTION__, a->hda.cad);
AUD_register_card("hda", &a->card);
diff --git a/hw/intel-hda.c b/hw/intel-hda.c
index 12dcc84..1b42e10 100644
--- a/hw/intel-hda.c
+++ b/hw/intel-hda.c
@@ -1129,7 +1129,7 @@ static int intel_hda_init(PCIDevice *pci)
IntelHDAState *d = DO_UPCAST(IntelHDAState, pci, pci);
uint8_t *conf = d->pci.config;
- d->name = qdev_get_info(&d->pci.qdev)->name;
+ d->name = object_get_type(OBJECT(d));
pci_config_set_interrupt_pin(conf, 1);
diff --git a/hw/ne2000-isa.c b/hw/ne2000-isa.c
index 60dc333..9e89256 100644
--- a/hw/ne2000-isa.c
+++ b/hw/ne2000-isa.c
@@ -76,7 +76,7 @@ static int isa_ne2000_initfn(ISADevice *dev)
ne2000_reset(s);
s->nic = qemu_new_nic(&net_ne2000_isa_info, &s->c,
- qdev_get_info(&dev->qdev)->name, dev->qdev.id, s);
+ object_get_type(OBJECT(dev)), dev->qdev.id, s);
qemu_format_nic_info_str(&s->nic->nc, s->c.macaddr.a);
return 0;
diff --git a/hw/ne2000.c b/hw/ne2000.c
index d016b8e..16dcee2 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -760,7 +760,7 @@ static int pci_ne2000_init(PCIDevice *pci_dev)
ne2000_reset(s);
s->nic = qemu_new_nic(&net_ne2000_info, &s->c,
- qdev_get_info(&pci_dev->qdev)->name, pci_dev->qdev.id, s);
+ object_get_type(OBJECT(pci_dev)), pci_dev->qdev.id, s);
qemu_format_nic_info_str(&s->nic->nc, s->c.macaddr.a);
if (!pci_dev->qdev.hotplugged) {
diff --git a/hw/pci.c b/hw/pci.c
index 46b7dac..dd8aa48 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -1763,7 +1763,7 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)
if (qdev_get_info(&pdev->qdev)->vmsd)
snprintf(name, sizeof(name), "%s.rom", qdev_get_info(&pdev->qdev)->vmsd->name);
else
- snprintf(name, sizeof(name), "%s.rom", qdev_get_info(&pdev->qdev)->name);
+ snprintf(name, sizeof(name), "%s.rom", object_get_type(OBJECT(pdev)));
pdev->has_rom = true;
memory_region_init_ram(&pdev->rom, &pdev->qdev, name, size);
ptr = memory_region_get_ram_ptr(&pdev->rom);
diff --git a/hw/pcnet.c b/hw/pcnet.c
index e58b195..c3bf405 100644
--- a/hw/pcnet.c
+++ b/hw/pcnet.c
@@ -1718,7 +1718,7 @@ int pcnet_common_init(DeviceState *dev, PCNetState *s, NetClientInfo *info)
s->poll_timer = qemu_new_timer_ns(vm_clock, pcnet_poll_timer, s);
qemu_macaddr_default_if_unset(&s->conf.macaddr);
- s->nic = qemu_new_nic(info, &s->conf, qdev_get_info(dev)->name, dev->id, s);
+ s->nic = qemu_new_nic(info, &s->conf, object_get_type(OBJECT(dev)), dev->id, s);
qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
add_boot_device_path(s->conf.bootindex, dev, "/ethernet-phy@0");
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index f235a26..ce8cb7c 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -627,7 +627,7 @@ int qdev_prop_parse(DeviceState *dev, const char *name, const char *value)
* removed along with it.
*/
if (!prop || !prop->info->parse) {
- qerror_report(QERR_PROPERTY_NOT_FOUND, qdev_get_info(dev)->name, name);
+ qerror_report(QERR_PROPERTY_NOT_FOUND, object_get_type(OBJECT(dev)), name);
return -1;
}
ret = prop->info->parse(dev, prop, value);
@@ -635,16 +635,16 @@ int qdev_prop_parse(DeviceState *dev, const char *name, const char *value)
switch (ret) {
case -EEXIST:
qerror_report(QERR_PROPERTY_VALUE_IN_USE,
- qdev_get_info(dev)->name, name, value);
+ object_get_type(OBJECT(dev)), name, value);
break;
default:
case -EINVAL:
qerror_report(QERR_PROPERTY_VALUE_BAD,
- qdev_get_info(dev)->name, name, value);
+ object_get_type(OBJECT(dev)), name, value);
break;
case -ENOENT:
qerror_report(QERR_PROPERTY_VALUE_NOT_FOUND,
- qdev_get_info(dev)->name, name, value);
+ object_get_type(OBJECT(dev)), name, value);
break;
}
return -1;
@@ -659,12 +659,12 @@ void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyT
prop = qdev_prop_find(dev, name);
if (!prop) {
fprintf(stderr, "%s: property \"%s.%s\" not found\n",
- __FUNCTION__, qdev_get_info(dev)->name, name);
+ __FUNCTION__, object_get_type(OBJECT(dev)), name);
abort();
}
if (prop->info->type != type) {
fprintf(stderr, "%s: property \"%s.%s\" type mismatch\n",
- __FUNCTION__, qdev_get_info(dev)->name, name);
+ __FUNCTION__, object_get_type(OBJECT(dev)), name);
abort();
}
qdev_prop_cpy(dev, prop, src);
@@ -713,7 +713,7 @@ int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *va
if (res < 0) {
error_report("Can't attach drive %s to %s.%s: %s",
bdrv_get_device_name(value),
- dev->id ? dev->id : qdev_get_info(dev)->name,
+ dev->id ? dev->id : object_get_type(OBJECT(dev)),
name, strerror(-res));
return -1;
}
@@ -785,7 +785,7 @@ void qdev_prop_set_globals(DeviceState *dev)
GlobalProperty *prop;
QTAILQ_FOREACH(prop, &global_props, next) {
- if (strcmp(qdev_get_info(dev)->name, prop->driver) != 0 &&
+ if (strcmp(object_get_type(OBJECT(dev)), prop->driver) != 0 &&
strcmp(qdev_get_info(dev)->bus_info->name, prop->driver) != 0) {
continue;
}
diff --git a/hw/qdev.c b/hw/qdev.c
index 2edbc61..18ff84e 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -690,7 +690,7 @@ static void qbus_list_bus(DeviceState *dev)
const char *sep = " ";
error_printf("child busses at \"%s\":",
- dev->id ? dev->id : qdev_get_info(dev)->name);
+ dev->id ? dev->id : object_get_type(OBJECT(dev)));
QLIST_FOREACH(child, &dev->child_bus, sibling) {
error_printf("%s\"%s\"", sep, child->name);
sep = ", ";
@@ -705,7 +705,7 @@ static void qbus_list_dev(BusState *bus)
error_printf("devices at \"%s\":", bus->name);
QTAILQ_FOREACH(dev, &bus->children, sibling) {
- error_printf("%s\"%s\"", sep, qdev_get_info(dev)->name);
+ error_printf("%s\"%s\"", sep, object_get_type(OBJECT(dev)));
if (dev->id)
error_printf("/\"%s\"", dev->id);
sep = ", ";
@@ -741,7 +741,7 @@ static DeviceState *qbus_find_dev(BusState *bus, char *elem)
}
}
QTAILQ_FOREACH(dev, &bus->children, sibling) {
- if (strcmp(qdev_get_info(dev)->name, elem) == 0) {
+ if (strcmp(object_get_type(OBJECT(dev)), elem) == 0) {
return dev;
}
}
@@ -948,7 +948,7 @@ static void qdev_print_props(Monitor *mon, DeviceState *dev, Property *props,
static void qdev_print(Monitor *mon, DeviceState *dev, int indent)
{
BusState *child;
- qdev_printf("dev: %s, id \"%s\"\n", qdev_get_info(dev)->name,
+ qdev_printf("dev: %s, id \"%s\"\n", object_get_type(OBJECT(dev)),
dev->id ? dev->id : "");
indent += 2;
if (dev->num_gpio_in) {
@@ -1038,7 +1038,7 @@ static int qdev_get_fw_dev_path_helper(DeviceState *dev, char *p, int size)
l += snprintf(p + l, size - l, "%s", d);
g_free(d);
} else {
- l += snprintf(p + l, size - l, "%s", qdev_get_info(dev)->name);
+ l += snprintf(p + l, size - l, "%s", object_get_type(OBJECT(dev)));
}
}
l += snprintf(p + l , size - l, "/");
@@ -1060,7 +1060,7 @@ char* qdev_get_fw_dev_path(DeviceState *dev)
char *qdev_get_type(DeviceState *dev, Error **errp)
{
- return g_strdup(qdev_get_info(dev)->name);
+ return g_strdup(object_get_type(OBJECT(dev)));
}
void qdev_ref(DeviceState *dev)
@@ -1255,7 +1255,7 @@ void qdev_property_add_child(DeviceState *dev, const char *name,
{
gchar *type;
- type = g_strdup_printf("child<%s>", qdev_get_info(child)->name);
+ type = g_strdup_printf("child<%s>", object_get_type(OBJECT(child)));
qdev_property_add(dev, name, type, qdev_get_child_property,
NULL, NULL, child, errp);
@@ -1306,7 +1306,7 @@ static void qdev_set_link_property(DeviceState *dev, Visitor *v, void *opaque,
if (target) {
gchar *target_type;
- target_type = g_strdup_printf("link<%s>", qdev_get_info(target)->name);
+ target_type = g_strdup_printf("link<%s>", object_get_type(OBJECT(target)));
if (strcmp(target_type, type) == 0) {
*child = target;
qdev_ref(target);
diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index c087506..0143fa2 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -3478,7 +3478,7 @@ static int pci_rtl8139_init(PCIDevice *dev)
s->eeprom.contents[9] = s->conf.macaddr.a[4] | s->conf.macaddr.a[5] << 8;
s->nic = qemu_new_nic(&net_rtl8139_info, &s->conf,
- qdev_get_info(&dev->qdev)->name, dev->qdev.id, s);
+ object_get_type(OBJECT(dev)), dev->qdev.id, s);
qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
s->cplus_txbuffer = NULL;
diff --git a/hw/usb-bus.c b/hw/usb-bus.c
index e1bcab1..fb532ab 100644
--- a/hw/usb-bus.c
+++ b/hw/usb-bus.c
@@ -251,7 +251,7 @@ int usb_claim_port(USBDevice *dev)
return -1;
}
} else {
- if (bus->nfree == 1 && strcmp(qdev_get_info(&dev->qdev)->name, "usb-hub") != 0) {
+ if (bus->nfree == 1 && strcmp(object_get_type(OBJECT(dev)), "usb-hub") != 0) {
/* Create a new hub and chain it on */
usb_create_simple(bus, "usb-hub");
}
diff --git a/hw/usb-net.c b/hw/usb-net.c
index 5d7bfcf..c4b29a9 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -1350,7 +1350,7 @@ static int usb_net_initfn(USBDevice *dev)
qemu_macaddr_default_if_unset(&s->conf.macaddr);
s->nic = qemu_new_nic(&net_usbnet_info, &s->conf,
- qdev_get_info(&s->dev.qdev)->name, s->dev.qdev.id, s);
+ object_get_type(OBJECT(s)), s->dev.qdev.id, s);
qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a);
snprintf(s->usbstring_mac, sizeof(s->usbstring_mac),
"%02x%02x%02x%02x%02x%02x",
diff --git a/hw/usb-ohci.c b/hw/usb-ohci.c
index 51c96b7..194c994 100644
--- a/hw/usb-ohci.c
+++ b/hw/usb-ohci.c
@@ -1775,7 +1775,7 @@ static int usb_ohci_init(OHCIState *ohci, DeviceState *dev,
memory_region_init_io(&ohci->mem, &ohci_mem_ops, ohci, "ohci", 256);
ohci->localmem_base = localmem_base;
- ohci->name = qdev_get_info(dev)->name;
+ ohci->name = object_get_type(OBJECT(dev));
usb_packet_init(&ohci->usb_packet);
ohci->async_td = 0;
diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index 6c785d0..dd5da0b 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -1030,7 +1030,7 @@ VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf,
memcpy(&n->mac[0], &conf->macaddr, sizeof(n->mac));
n->status = VIRTIO_NET_S_LINK_UP;
- n->nic = qemu_new_nic(&net_virtio_info, conf, qdev_get_info(dev)->name, dev->id, n);
+ n->nic = qemu_new_nic(&net_virtio_info, conf, object_get_type(OBJECT(dev)), dev->id, n);
qemu_format_nic_info_str(&n->nic->nc, conf->macaddr.a);
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 032/197] qdev: user a wrapper to access reset and promote reset to a class method
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (30 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 031/197] qdev: don't access name through info Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 033/197] a little better approach to this Anthony Liguori
` (34 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/intel-hda.c | 4 +---
hw/lsi53c895a.c | 2 +-
hw/qdev.c | 27 +++++++++++++++++----------
hw/qdev.h | 10 +++++++++-
4 files changed, 28 insertions(+), 15 deletions(-)
diff --git a/hw/intel-hda.c b/hw/intel-hda.c
index 1b42e10..09459b8 100644
--- a/hw/intel-hda.c
+++ b/hw/intel-hda.c
@@ -1116,9 +1116,7 @@ static void intel_hda_reset(DeviceState *dev)
/* reset codecs */
QTAILQ_FOREACH(qdev, &d->codecs.qbus.children, sibling) {
cdev = DO_UPCAST(HDACodecDevice, qdev, qdev);
- if (qdev_get_info(qdev)->reset) {
- qdev_get_info(qdev)->reset(qdev);
- }
+ device_reset(DEVICE(cdev));
d->state_sts |= (1 << cdev->cad);
}
intel_hda_update_irq(d);
diff --git a/hw/lsi53c895a.c b/hw/lsi53c895a.c
index b313f83..110ca44 100644
--- a/hw/lsi53c895a.c
+++ b/hw/lsi53c895a.c
@@ -1681,7 +1681,7 @@ static void lsi_reg_writeb(LSIState *s, int offset, uint8_t val)
DeviceState *dev;
QTAILQ_FOREACH(dev, &s->bus.qbus.children, sibling) {
- qdev_get_info(dev)->reset(dev);
+ device_reset(dev);
}
s->sstat0 |= LSI_SSTAT0_RST;
lsi_script_scsi_interrupt(s, LSI_SIST0_RST, 0);
diff --git a/hw/qdev.c b/hw/qdev.c
index 18ff84e..fed9848 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -44,16 +44,16 @@ static BusState *qbus_find_recursive(BusState *bus, const char *name,
const BusInfo *info);
static BusState *qbus_find(const char *path);
-#define TYPE_DEVICE "device"
-#define DEVICE(obj) OBJECT_CHECK(DeviceState, (obj), TYPE_DEVICE)
-#define DEVICE_CLASS(klass) OBJECT_CLASS_CHECK(DeviceClass, (klass), TYPE_DEVICE)
-#define DEVICE_GET_CLASS(obj) OBJECT_GET_CLASS(DeviceClass, (obj), TYPE_DEVICE)
-
/* Register a new device type. */
static void qdev_subclass_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
+
dc->info = data;
+ dc->reset = dc->info->reset;
+
+ /* Poison to try to detect future uses */
+ dc->info->reset = NULL;
}
DeviceInfo *qdev_get_info(DeviceState *dev)
@@ -372,8 +372,8 @@ int qdev_init(DeviceState *dev)
dev->alias_required_for_version);
}
dev->state = DEV_STATE_INITIALIZED;
- if (dev->hotplugged && qdev_get_info(dev)->reset) {
- qdev_get_info(dev)->reset(dev);
+ if (dev->hotplugged) {
+ device_reset(dev);
}
return 0;
}
@@ -406,9 +406,7 @@ int qdev_unplug(DeviceState *dev)
static int qdev_reset_one(DeviceState *dev, void *opaque)
{
- if (qdev_get_info(dev)->reset) {
- qdev_get_info(dev)->reset(dev);
- }
+ device_reset(dev);
return 0;
}
@@ -1541,6 +1539,15 @@ void qdev_property_add_str(DeviceState *dev, const char *name,
prop, errp);
}
+void device_reset(DeviceState *dev)
+{
+ DeviceClass *klass = DEVICE_GET_CLASS(dev);
+
+ if (klass->reset) {
+ klass->reset(dev);
+ }
+}
+
static TypeInfo device_type_info = {
.name = TYPE_DEVICE,
.parent = TYPE_OBJECT,
diff --git a/hw/qdev.h b/hw/qdev.h
index 01dd1d6..cd2eaf2 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -67,9 +67,15 @@ typedef struct DeviceProperty
QTAILQ_ENTRY(DeviceProperty) node;
} DeviceProperty;
+#define TYPE_DEVICE "device"
+#define DEVICE(obj) OBJECT_CHECK(DeviceState, (obj), TYPE_DEVICE)
+#define DEVICE_CLASS(klass) OBJECT_CLASS_CHECK(DeviceClass, (klass), TYPE_DEVICE)
+#define DEVICE_GET_CLASS(obj) OBJECT_GET_CLASS(DeviceClass, (obj), TYPE_DEVICE)
+
typedef struct DeviceClass {
ObjectClass parent_class;
DeviceInfo *info;
+ void (*reset)(DeviceState *dev);
} DeviceClass;
/* This structure should not be accessed directly. We declare it here
@@ -390,7 +396,7 @@ static inline const char *qdev_fw_name(DeviceState *dev)
return info->alias;
}
- return info->name;
+ return object_get_type(OBJECT(dev));
}
char *qdev_get_fw_dev_path(DeviceState *dev);
@@ -627,4 +633,6 @@ void qdev_property_add_str(DeviceState *dev, const char *name,
*/
char *qdev_get_type(DeviceState *dev, Error **errp);
+void device_reset(DeviceState *dev);
+
#endif
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 033/197] a little better approach to this
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (31 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 032/197] qdev: user a wrapper to access reset and promote reset to a class method Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 034/197] qdev: add isa-device as a subclass of device Anthony Liguori
` (33 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/pci.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/hw/pci.c b/hw/pci.c
index dd8aa48..16d676d 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -161,8 +161,8 @@ void pci_device_reset(PCIDevice *dev)
int r;
/* TODO: call the below unconditionally once all pci devices
* are qdevified */
- if (qdev_get_info(&dev->qdev)) {
- qdev_reset_all(&dev->qdev);
+ if (OBJECT(dev)->type != 0) {
+ qdev_reset_all(DEVICE(dev));
}
dev->irq_state = 0;
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 034/197] qdev: add isa-device as a subclass of device
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (32 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 033/197] a little better approach to this Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 035/197] isa: more isa stuff Anthony Liguori
` (32 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
hw/isa-bus.c | 11 ++++++++++-
hw/isa.h | 12 ++++++++++++
hw/pci.c | 2 +-
hw/qdev.c | 9 +++++++--
hw/qdev.h | 1 +
5 files changed, 31 insertions(+), 4 deletions(-)
diff --git a/hw/isa-bus.c b/hw/isa-bus.c
index 7c2c261..0beb1bf 100644
--- a/hw/isa-bus.c
+++ b/hw/isa-bus.c
@@ -126,7 +126,7 @@ void isa_qdev_register(ISADeviceInfo *info)
{
info->qdev.init = isa_qdev_init;
info->qdev.bus_info = &isa_bus_info;
- qdev_register(&info->qdev);
+ qdev_register_subclass(&info->qdev, TYPE_ISA_DEVICE);
}
ISADevice *isa_create(const char *name)
@@ -189,9 +189,18 @@ static SysBusDeviceInfo isabus_bridge_info = {
.qdev.no_user = 1,
};
+static TypeInfo isa_device_type_info = {
+ .name = TYPE_ISA_DEVICE,
+ .parent = TYPE_DEVICE,
+ .instance_size = sizeof(ISADevice),
+ .abstract = true,
+ .class_size = sizeof(ISADeviceClass),
+};
+
static void isabus_register_devices(void)
{
sysbus_register_withprop(&isabus_bridge_info);
+ type_register_static(&isa_device_type_info);
}
static char *isabus_get_fw_dev_path(DeviceState *dev)
diff --git a/hw/isa.h b/hw/isa.h
index 5eb9c78..af7e3dc 100644
--- a/hw/isa.h
+++ b/hw/isa.h
@@ -13,6 +13,18 @@ typedef struct ISABus ISABus;
typedef struct ISADevice ISADevice;
typedef struct ISADeviceInfo ISADeviceInfo;
+#define TYPE_ISA_DEVICE "isa-device"
+#define ISA_DEVICE(obj) \
+ OBJECT_CHECK(ISADeviceState, (obj), ISA_TYPE_DEVICE)
+#define ISA_DEVICE_CLASS(klass) \
+ OBJECT_CLASS_CHECK(ISADeviceClass, (klass), ISA_TYPE_DEVICE)
+#define ISA_DEVICE_GET_CLASS(obj) \
+ OBJECT_GET_CLASS(ISADeviceClass, (obj), ISA_TYPE_DEVICE)
+
+typedef struct ISADeviceClass {
+ DeviceClass parent_class;
+} ISADeviceClass;
+
struct ISADevice {
DeviceState qdev;
uint32_t isairq[2];
diff --git a/hw/pci.c b/hw/pci.c
index 16d676d..9992ea2 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -161,7 +161,7 @@ void pci_device_reset(PCIDevice *dev)
int r;
/* TODO: call the below unconditionally once all pci devices
* are qdevified */
- if (OBJECT(dev)->type != 0) {
+ if (OBJECT(dev)->class != NULL) {
qdev_reset_all(DEVICE(dev));
}
diff --git a/hw/qdev.c b/hw/qdev.c
index fed9848..e0c4a40 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -61,7 +61,7 @@ DeviceInfo *qdev_get_info(DeviceState *dev)
return DEVICE_GET_CLASS(dev)->info;
}
-void qdev_register(DeviceInfo *info)
+void qdev_register_subclass(DeviceInfo *info, const char *parent)
{
TypeInfo type_info = {};
@@ -69,7 +69,7 @@ void qdev_register(DeviceInfo *info)
assert(!info->next);
type_info.name = info->name;
- type_info.parent = TYPE_DEVICE;
+ type_info.parent = parent;
type_info.instance_size = info->size;
type_info.class_init = qdev_subclass_init;
type_info.class_data = info;
@@ -80,6 +80,11 @@ void qdev_register(DeviceInfo *info)
device_info_list = info;
}
+void qdev_register(DeviceInfo *info)
+{
+ qdev_register_subclass(info, TYPE_DEVICE);
+}
+
static DeviceInfo *qdev_find_info(BusInfo *bus_info, const char *name)
{
DeviceInfo *info;
diff --git a/hw/qdev.h b/hw/qdev.h
index cd2eaf2..aab8f42 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -235,6 +235,7 @@ struct DeviceInfo {
extern DeviceInfo *device_info_list;
void qdev_register(DeviceInfo *info);
+void qdev_register_subclass(DeviceInfo *info, const char *parent);
/* Register device properties. */
/* GPIO inputs also double as IRQ sinks. */
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 035/197] isa: more isa stuff
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (33 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 034/197] qdev: add isa-device as a subclass of device Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 036/197] qom: make pcidevice part of the hierarchy Anthony Liguori
` (31 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/isa-bus.c | 8 ++++----
hw/isa.h | 6 +++---
hw/mc146818rtc.c | 2 +-
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/hw/isa-bus.c b/hw/isa-bus.c
index 0beb1bf..50131f7 100644
--- a/hw/isa-bus.c
+++ b/hw/isa-bus.c
@@ -113,7 +113,7 @@ void isa_register_portio_list(ISADevice *dev, uint16_t start,
static int isa_qdev_init(DeviceState *qdev, DeviceInfo *base)
{
- ISADevice *dev = DO_UPCAST(ISADevice, qdev, qdev);
+ ISADevice *dev = ISA_DEVICE(qdev);
ISADeviceInfo *info = DO_UPCAST(ISADeviceInfo, qdev, base);
dev->isairq[0] = -1;
@@ -138,7 +138,7 @@ ISADevice *isa_create(const char *name)
name);
}
dev = qdev_create(&isabus->qbus, name);
- return DO_UPCAST(ISADevice, qdev, dev);
+ return ISA_DEVICE(dev);
}
ISADevice *isa_try_create(const char *name)
@@ -150,7 +150,7 @@ ISADevice *isa_try_create(const char *name)
name);
}
dev = qdev_try_create(&isabus->qbus, name);
- return DO_UPCAST(ISADevice, qdev, dev);
+ return ISA_DEVICE(dev);
}
ISADevice *isa_create_simple(const char *name)
@@ -164,7 +164,7 @@ ISADevice *isa_create_simple(const char *name)
static void isabus_dev_print(Monitor *mon, DeviceState *dev, int indent)
{
- ISADevice *d = DO_UPCAST(ISADevice, qdev, dev);
+ ISADevice *d = ISA_DEVICE(dev);
if (d->isairq[1] != -1) {
monitor_printf(mon, "%*sisa irqs %d,%d\n", indent, "",
diff --git a/hw/isa.h b/hw/isa.h
index af7e3dc..d5fd7d7 100644
--- a/hw/isa.h
+++ b/hw/isa.h
@@ -15,11 +15,11 @@ typedef struct ISADeviceInfo ISADeviceInfo;
#define TYPE_ISA_DEVICE "isa-device"
#define ISA_DEVICE(obj) \
- OBJECT_CHECK(ISADeviceState, (obj), ISA_TYPE_DEVICE)
+ OBJECT_CHECK(ISADevice, (obj), TYPE_ISA_DEVICE)
#define ISA_DEVICE_CLASS(klass) \
- OBJECT_CLASS_CHECK(ISADeviceClass, (klass), ISA_TYPE_DEVICE)
+ OBJECT_CLASS_CHECK(ISADeviceClass, (klass), TYPE_ISA_DEVICE)
#define ISA_DEVICE_GET_CLASS(obj) \
- OBJECT_GET_CLASS(ISADeviceClass, (obj), ISA_TYPE_DEVICE)
+ OBJECT_GET_CLASS(ISADeviceClass, (obj), TYPE_ISA_DEVICE)
typedef struct ISADeviceClass {
DeviceClass parent_class;
diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
index 0c23cb0..d5b737a 100644
--- a/hw/mc146818rtc.c
+++ b/hw/mc146818rtc.c
@@ -624,7 +624,7 @@ static void visit_type_int32(Visitor *v, int *value, const char *name, Error **e
static void rtc_get_date(DeviceState *dev, Visitor *v, void *opaque,
const char *name, Error **errp)
{
- ISADevice *isa = DO_UPCAST(ISADevice, qdev, dev);
+ ISADevice *isa = ISA_DEVICE(dev);
RTCState *s = DO_UPCAST(RTCState, dev, isa);
visit_start_struct(v, NULL, "struct tm", name, 0, errp);
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 036/197] qom: make pcidevice part of the hierarchy
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (34 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 035/197] isa: more isa stuff Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 039/197] virtio-serial-port Anthony Liguori
` (30 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/pci.c | 18 ++++++++++++++++--
hw/pci.h | 12 ++++++++++++
hw/qdev.c | 5 +++++
3 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/hw/pci.c b/hw/pci.c
index 9992ea2..04fd95f 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -89,7 +89,6 @@ static const VMStateDescription vmstate_pcibus = {
VMSTATE_END_OF_LIST()
}
};
-
static int pci_bar(PCIDevice *d, int reg)
{
uint8_t type;
@@ -1550,7 +1549,7 @@ void pci_qdev_register(PCIDeviceInfo *info)
info->qdev.unplug = pci_unplug_device;
info->qdev.exit = pci_unregister_device;
info->qdev.bus_info = &pci_bus_info;
- qdev_register(&info->qdev);
+ qdev_register_subclass(&info->qdev, TYPE_PCI_DEVICE);
}
void pci_qdev_register_many(PCIDeviceInfo *info)
@@ -2038,3 +2037,18 @@ MemoryRegion *pci_address_space_io(PCIDevice *dev)
{
return dev->bus->address_space_io;
}
+
+static TypeInfo pci_device_type_info = {
+ .name = TYPE_PCI_DEVICE,
+ .parent = TYPE_DEVICE,
+ .instance_size = sizeof(PCIDevice),
+ .abstract = true,
+ .class_size = sizeof(PCIDeviceClass),
+};
+
+static void pci_register_devices(void)
+{
+ type_register_static(&pci_device_type_info);
+}
+
+device_init(pci_register_devices);
diff --git a/hw/pci.h b/hw/pci.h
index 625e717..00c9897 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -127,6 +127,18 @@ enum {
QEMU_PCI_CAP_SERR = (1 << QEMU_PCI_CAP_SERR_BITNR),
};
+#define TYPE_PCI_DEVICE "pci-device"
+#define PCI_DEVICE(obj) \
+ OBJECT_CHECK(PCIDevice, (obj), TYPE_PCI_DEVICE)
+#define PCI_DEVICE_CLASS(klass) \
+ OBJECT_CLASS_CHECK(PCIDeviceClass, (klass), TYPE_PCI_DEVICE)
+#define PCI_DEVICE_GET_CLASS(obj) \
+ OBJECT_GET_CLASS(PCIDeviceClass, (obj), TYPE_PCI_DEVICE)
+
+typedef struct PCIDeviceClass {
+ DeviceClass parent_class;
+} PCIDeviceClass;
+
struct PCIDevice {
DeviceState qdev;
/* PCI config space */
diff --git a/hw/qdev.c b/hw/qdev.c
index e0c4a40..09f8b4c 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -111,6 +111,11 @@ static DeviceInfo *qdev_find_info(BusInfo *bus_info, const char *name)
return NULL;
}
+/* FIXME: need to figure out somethign to do with bus.
+ *
+ * The general problem is that we don't want to take a bus argument on
+ * create. there's simply no way to pass it to instance init.
+ */
static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info)
{
DeviceState *dev;
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 039/197] virtio-serial-port
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (35 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 036/197] qom: make pcidevice part of the hierarchy Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 040/197] get rid of more DO_UPCAST Anthony Liguori
` (29 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/virtio-serial-bus.c | 17 ++++++++++++++++-
hw/virtio-serial.h | 12 ++++++++++++
2 files changed, 28 insertions(+), 1 deletions(-)
diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
index b9c8ca7..a459e31 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/virtio-serial-bus.c
@@ -829,7 +829,7 @@ void virtio_serial_port_qdev_register(VirtIOSerialPortInfo *info)
info->qdev.bus_info = &virtser_bus_info;
info->qdev.exit = virtser_port_qdev_exit;
info->qdev.unplug = qdev_simple_unplug_cb;
- qdev_register(&info->qdev);
+ qdev_register_subclass(&info->qdev, TYPE_VIRTIO_SERIAL_PORT);
}
VirtIODevice *virtio_serial_init(DeviceState *dev, virtio_serial_conf *conf)
@@ -925,3 +925,18 @@ void virtio_serial_exit(VirtIODevice *vdev)
virtio_cleanup(vdev);
}
+
+static TypeInfo virtio_serial_port_type_info = {
+ .name = TYPE_VIRTIO_SERIAL_PORT,
+ .parent = TYPE_DEVICE,
+ .instance_size = sizeof(VirtIOSerialPort),
+ .abstract = true,
+ .class_size = sizeof(VirtIOSerialPortClass),
+};
+
+static void virtio_serial_register_devices(void)
+{
+ type_register_static(&virtio_serial_port_type_info);
+}
+
+device_init(virtio_serial_register_devices);
diff --git a/hw/virtio-serial.h b/hw/virtio-serial.h
index ab13803..86fae8d 100644
--- a/hw/virtio-serial.h
+++ b/hw/virtio-serial.h
@@ -62,6 +62,18 @@ struct virtio_serial_conf {
/* == In-qemu interface == */
+#define TYPE_VIRTIO_SERIAL_PORT "virtio-serial-port"
+#define VIRTIO_SERIAL_PORT(obj) \
+ OBJECT_CHECK(VirtIOSerialPort, (obj), TYPE_VIRTIO_SERIAL_PORT)
+#define VIRTIO_SERIAL_PORT_CLASS(klass) \
+ OBJECT_CLASS_CHECK(VirtIOSerialPortClass, (klass), TYPE_VIRTIO_SERIAL_PORT)
+#define VIRTIO_SERIAL_PORT_GET_CLASS(obj) \
+ OBJECT_GET_CLASS(VirtIOSerialPortClass, (obj), TYPE_VIRTIO_SERIAL_PORT)
+
+typedef struct VirtIOSerialPortClass {
+ DeviceClass parent_class;
+} VirtIOSerialPortClass;
+
typedef struct VirtIOSerial VirtIOSerial;
typedef struct VirtIOSerialBus VirtIOSerialBus;
typedef struct VirtIOSerialPort VirtIOSerialPort;
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 040/197] get rid of more DO_UPCAST
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (36 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 039/197] virtio-serial-port Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 041/197] add class_init to deviceinfo Anthony Liguori
` (28 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/scsi-bus.c | 14 +++++++-------
hw/scsi-generic.c | 2 +-
hw/usb-bus.c | 12 ++++++------
hw/usb-ccid.c | 4 ++--
4 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
index e8eb521..731c1f3 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi-bus.c
@@ -81,7 +81,7 @@ static void scsi_dma_restart_cb(void *opaque, int running, RunState state)
static int scsi_qdev_init(DeviceState *qdev, DeviceInfo *base)
{
- SCSIDevice *dev = DO_UPCAST(SCSIDevice, qdev, qdev);
+ SCSIDevice *dev = SCSI_DEVICE(qdev);
SCSIDeviceInfo *info = DO_UPCAST(SCSIDeviceInfo, qdev, base);
SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, dev->qdev.parent_bus);
SCSIDevice *d;
@@ -140,7 +140,7 @@ err:
static int scsi_qdev_exit(DeviceState *qdev)
{
- SCSIDevice *dev = DO_UPCAST(SCSIDevice, qdev, qdev);
+ SCSIDevice *dev = SCSI_DEVICE(qdev);
if (dev->vmsentry) {
qemu_del_vm_change_state_handler(dev->vmsentry);
@@ -182,7 +182,7 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
}
if (qdev_init(dev) < 0)
return NULL;
- return DO_UPCAST(SCSIDevice, qdev, dev);
+ return SCSI_DEVICE(dev);
}
int scsi_bus_legacy_handle_cmdline(SCSIBus *bus)
@@ -278,7 +278,7 @@ static bool scsi_target_emulate_report_luns(SCSITargetReq *r)
found_lun0 = false;
n = 0;
QTAILQ_FOREACH(qdev, &r->req.bus->qbus.children, sibling) {
- SCSIDevice *dev = DO_UPCAST(SCSIDevice, qdev, qdev);
+ SCSIDevice *dev = SCSI_DEVICE(qdev);
if (dev->channel == channel && dev->id == id) {
if (dev->lun == 0) {
@@ -300,7 +300,7 @@ static bool scsi_target_emulate_report_luns(SCSITargetReq *r)
stl_be_p(&r->buf, n);
i = found_lun0 ? 8 : 16;
QTAILQ_FOREACH(qdev, &r->req.bus->qbus.children, sibling) {
- SCSIDevice *dev = DO_UPCAST(SCSIDevice, qdev, qdev);
+ SCSIDevice *dev = SCSI_DEVICE(qdev);
if (dev->channel == channel && dev->id == id) {
store_lun(&r->buf[i], dev->lun);
@@ -1367,7 +1367,7 @@ void scsi_device_purge_requests(SCSIDevice *sdev, SCSISense sense)
static char *scsibus_get_fw_dev_path(DeviceState *dev)
{
- SCSIDevice *d = DO_UPCAST(SCSIDevice, qdev, dev);
+ SCSIDevice *d = SCSI_DEVICE(dev);
char path[100];
snprintf(path, sizeof(path), "channel@%x/%s@%x,%x", d->channel,
@@ -1382,7 +1382,7 @@ SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int id, int lun)
SCSIDevice *target_dev = NULL;
QTAILQ_FOREACH_REVERSE(qdev, &bus->qbus.children, ChildrenHead, sibling) {
- SCSIDevice *dev = DO_UPCAST(SCSIDevice, qdev, qdev);
+ SCSIDevice *dev = SCSI_DEVICE(qdev);
if (dev->channel == channel && dev->id == id) {
if (dev->lun == lun) {
diff --git a/hw/scsi-generic.c b/hw/scsi-generic.c
index e62044f..ef76e4b 100644
--- a/hw/scsi-generic.c
+++ b/hw/scsi-generic.c
@@ -361,7 +361,7 @@ static int get_stream_blocksize(BlockDriverState *bdrv)
static void scsi_generic_reset(DeviceState *dev)
{
- SCSIDevice *s = DO_UPCAST(SCSIDevice, qdev, dev);
+ SCSIDevice *s = SCSI_DEVICE(dev);
scsi_device_purge_requests(s, SENSE_CODE(RESET));
}
diff --git a/hw/usb-bus.c b/hw/usb-bus.c
index 80cf560..8924ac3 100644
--- a/hw/usb-bus.c
+++ b/hw/usb-bus.c
@@ -67,7 +67,7 @@ USBBus *usb_bus_find(int busnr)
static int usb_qdev_init(DeviceState *qdev, DeviceInfo *base)
{
- USBDevice *dev = DO_UPCAST(USBDevice, qdev, qdev);
+ USBDevice *dev = USB_DEVICE(qdev);
USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev, base);
int rc;
@@ -98,7 +98,7 @@ err:
static int usb_qdev_exit(DeviceState *qdev)
{
- USBDevice *dev = DO_UPCAST(USBDevice, qdev, qdev);
+ USBDevice *dev = USB_DEVICE(qdev);
if (dev->attached) {
usb_device_detach(dev);
@@ -145,7 +145,7 @@ USBDevice *usb_create(USBBus *bus, const char *name)
#endif
dev = qdev_create(&bus->qbus, name);
- return DO_UPCAST(USBDevice, qdev, dev);
+ return USB_DEVICE(dev);
}
USBDevice *usb_create_simple(USBBus *bus, const char *name)
@@ -366,7 +366,7 @@ static const char *usb_speed(unsigned int speed)
static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent)
{
- USBDevice *dev = DO_UPCAST(USBDevice, qdev, qdev);
+ USBDevice *dev = USB_DEVICE(qdev);
USBBus *bus = usb_bus_from_device(dev);
monitor_printf(mon, "%*saddr %d.%d, port %s, speed %s, name %s%s\n",
@@ -378,13 +378,13 @@ static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent)
static char *usb_get_dev_path(DeviceState *qdev)
{
- USBDevice *dev = DO_UPCAST(USBDevice, qdev, qdev);
+ USBDevice *dev = USB_DEVICE(qdev);
return g_strdup(dev->port->path);
}
static char *usb_get_fw_dev_path(DeviceState *qdev)
{
- USBDevice *dev = DO_UPCAST(USBDevice, qdev, qdev);
+ USBDevice *dev = USB_DEVICE(qdev);
char *fw_path, *in;
ssize_t pos = 0, fw_len;
long nr;
diff --git a/hw/usb-ccid.c b/hw/usb-ccid.c
index 9bbef8c..997ef31 100644
--- a/hw/usb-ccid.c
+++ b/hw/usb-ccid.c
@@ -1121,7 +1121,7 @@ void ccid_card_card_inserted(CCIDCardState *card)
static int ccid_card_exit(DeviceState *qdev)
{
int ret = 0;
- CCIDCardState *card = DO_UPCAST(CCIDCardState, qdev, qdev);
+ CCIDCardState *card = CCID_CARD(qdev);
CCIDCardInfo *info = DO_UPCAST(CCIDCardInfo, qdev, qdev_get_info(qdev));
USBCCIDState *s =
DO_UPCAST(USBCCIDState, dev.qdev, card->qdev.parent_bus->parent);
@@ -1139,7 +1139,7 @@ static int ccid_card_exit(DeviceState *qdev)
static int ccid_card_init(DeviceState *qdev, DeviceInfo *base)
{
- CCIDCardState *card = DO_UPCAST(CCIDCardState, qdev, qdev);
+ CCIDCardState *card = CCID_CARD(qdev);
CCIDCardInfo *info = DO_UPCAST(CCIDCardInfo, qdev, base);
USBCCIDState *s =
DO_UPCAST(USBCCIDState, dev.qdev, card->qdev.parent_bus->parent);
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 041/197] add class_init to deviceinfo
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (37 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 040/197] get rid of more DO_UPCAST Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 042/197] isa: move methods from isadeviceinfo to isadeviceclass Anthony Liguori
` (27 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/ccid.h | 2 +-
hw/qdev.c | 4 ++++
hw/qdev.h | 5 +++++
3 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/hw/ccid.h b/hw/ccid.h
index ad055d3..d8e0485 100644
--- a/hw/ccid.h
+++ b/hw/ccid.h
@@ -17,7 +17,7 @@ typedef struct CCIDCardInfo CCIDCardInfo;
#define TYPE_CCID_CARD "ccid-card"
#define CCID_CARD(obj) \
- OBJECT_CHECK(CCIDCard, (obj), TYPE_CCID_CARD)
+ OBJECT_CHECK(CCIDCardState, (obj), TYPE_CCID_CARD)
#define CCID_CARD_CLASS(klass) \
OBJECT_CLASS_CHECK(CCIDCardClass, (klass), TYPE_CCID_CARD)
#define CCID_CARD_GET_CLASS(obj) \
diff --git a/hw/qdev.c b/hw/qdev.c
index 09f8b4c..d062470 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -54,6 +54,10 @@ static void qdev_subclass_init(ObjectClass *klass, void *data)
/* Poison to try to detect future uses */
dc->info->reset = NULL;
+
+ if (dc->info->class_init) {
+ dc->info->class_init(klass, data);
+ }
}
DeviceInfo *qdev_get_info(DeviceState *dev)
diff --git a/hw/qdev.h b/hw/qdev.h
index aab8f42..6617a2b 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -225,6 +225,11 @@ struct DeviceInfo {
/* device state */
const VMStateDescription *vmsd;
+ /**
+ * See @TypeInfo::class_init()
+ */
+ void (*class_init)(ObjectClass *klass, void *data);
+
/* Private to qdev / bus. */
qdev_initfn init;
qdev_event unplug;
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 042/197] isa: move methods from isadeviceinfo to isadeviceclass
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (38 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 041/197] add class_init to deviceinfo Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 043/197] kill off ISADeviceInfo Anthony Liguori
` (26 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/applesmc.c | 8 +++++++-
hw/cs4231a.c | 8 +++++++-
hw/debugcon.c | 8 +++++++-
hw/fdc.c | 8 +++++++-
hw/gus.c | 8 +++++++-
hw/i8254.c | 8 +++++++-
hw/i8259.c | 8 +++++++-
hw/ide/isa.c | 8 +++++++-
hw/isa-bus.c | 8 ++++++--
hw/isa.h | 3 +--
hw/m48t59.c | 8 +++++++-
hw/mc146818rtc.c | 8 +++++++-
hw/ne2000-isa.c | 8 +++++++-
hw/parallel.c | 8 +++++++-
hw/pc.c | 8 +++++++-
hw/pckbd.c | 8 +++++++-
hw/sb16.c | 8 +++++++-
hw/serial.c | 8 +++++++-
hw/sga.c | 8 +++++++-
hw/vga-isa.c | 8 +++++++-
hw/vmmouse.c | 8 +++++++-
hw/vmport.c | 8 +++++++-
hw/wdt_ib700.c | 8 +++++++-
23 files changed, 154 insertions(+), 25 deletions(-)
diff --git a/hw/applesmc.c b/hw/applesmc.c
index c47b592..279c4d3 100644
--- a/hw/applesmc.c
+++ b/hw/applesmc.c
@@ -220,11 +220,17 @@ static int applesmc_isa_init(ISADevice *dev)
return 0;
}
+static void qdev_applesmc_class_init(ObjectClass *klass, void *data)
+{
+ ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+ ic->init = applesmc_isa_init;
+}
+
static ISADeviceInfo applesmc_isa_info = {
.qdev.name = "isa-applesmc",
.qdev.size = sizeof(struct AppleSMCStatus),
.qdev.reset = qdev_applesmc_isa_reset,
- .init = applesmc_isa_init,
+ .qdev.class_init = qdev_applesmc_class_init,
.qdev.props = (Property[]) {
DEFINE_PROP_HEX32("iobase", struct AppleSMCStatus, iobase,
APPLESMC_DEFAULT_IOBASE),
diff --git a/hw/cs4231a.c b/hw/cs4231a.c
index a7e03a3..25af773 100644
--- a/hw/cs4231a.c
+++ b/hw/cs4231a.c
@@ -665,12 +665,18 @@ int cs4231a_init (qemu_irq *pic)
return 0;
}
+static void cs4231a_class_initfn(ObjectClass *klass, void *data)
+{
+ ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+ ic->init = cs4231a_initfn;
+}
+
static ISADeviceInfo cs4231a_info = {
.qdev.name = "cs4231a",
.qdev.desc = "Crystal Semiconductor CS4231A",
.qdev.size = sizeof (CSState),
.qdev.vmsd = &vmstate_cs4231a,
- .init = cs4231a_initfn,
+ .qdev.class_init = cs4231a_class_initfn,
.qdev.props = (Property[]) {
DEFINE_PROP_HEX32 ("iobase", CSState, port, 0x534),
DEFINE_PROP_UINT32 ("irq", CSState, irq, 9),
diff --git a/hw/debugcon.c b/hw/debugcon.c
index c9ee6d9..1490bfa 100644
--- a/hw/debugcon.c
+++ b/hw/debugcon.c
@@ -87,10 +87,16 @@ static int debugcon_isa_initfn(ISADevice *dev)
return 0;
}
+static void debugcon_isa_class_initfn(ObjectClass *klass, void *data)
+{
+ ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+ ic->init = debugcon_isa_initfn;
+}
+
static ISADeviceInfo debugcon_isa_info = {
.qdev.name = "isa-debugcon",
.qdev.size = sizeof(ISADebugconState),
- .init = debugcon_isa_initfn,
+ .qdev.class_init = debugcon_isa_class_initfn,
.qdev.props = (Property[]) {
DEFINE_PROP_HEX32("iobase", ISADebugconState, iobase, 0xe9),
DEFINE_PROP_CHR("chardev", ISADebugconState, state.chr),
diff --git a/hw/fdc.c b/hw/fdc.c
index ecaad09..dfeb138 100644
--- a/hw/fdc.c
+++ b/hw/fdc.c
@@ -1969,8 +1969,14 @@ static const VMStateDescription vmstate_isa_fdc ={
}
};
+static void isabus_fdc_class_init1(ObjectClass *klass, void *data)
+{
+ ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+ ic->init = isabus_fdc_init1;
+}
+
static ISADeviceInfo isa_fdc_info = {
- .init = isabus_fdc_init1,
+ .qdev.class_init = isabus_fdc_class_init1,
.qdev.name = "isa-fdc",
.qdev.fw_name = "fdc",
.qdev.size = sizeof(FDCtrlISABus),
diff --git a/hw/gus.c b/hw/gus.c
index b5eb548..49e0d16 100644
--- a/hw/gus.c
+++ b/hw/gus.c
@@ -299,12 +299,18 @@ int GUS_init (qemu_irq *pic)
return 0;
}
+static void gus_class_initfn(ObjectClass *klass, void *data)
+{
+ ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+ ic->init = gus_initfn;
+}
+
static ISADeviceInfo gus_info = {
.qdev.name = "gus",
.qdev.desc = "Gravis Ultrasound GF1",
.qdev.size = sizeof (GUSState),
.qdev.vmsd = &vmstate_gus,
- .init = gus_initfn,
+ .qdev.class_init = gus_class_initfn,
.qdev.props = (Property[]) {
DEFINE_PROP_UINT32 ("freq", GUSState, freq, 44100),
DEFINE_PROP_HEX32 ("iobase", GUSState, port, 0x240),
diff --git a/hw/i8254.c b/hw/i8254.c
index 12571ef..5d10206 100644
--- a/hw/i8254.c
+++ b/hw/i8254.c
@@ -535,13 +535,19 @@ static int pit_initfn(ISADevice *dev)
return 0;
}
+static void pit_class_initfn(ObjectClass *klass, void *data)
+{
+ ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+ ic->init = pit_initfn;
+}
+
static ISADeviceInfo pit_info = {
.qdev.name = "isa-pit",
.qdev.size = sizeof(PITState),
.qdev.vmsd = &vmstate_pit,
.qdev.reset = pit_reset,
.qdev.no_user = 1,
- .init = pit_initfn,
+ .qdev.class_init = pit_class_initfn,
.qdev.props = (Property[]) {
DEFINE_PROP_UINT32("irq", PITState, irq, -1),
DEFINE_PROP_HEX32("iobase", PITState, iobase, -1),
diff --git a/hw/i8259.c b/hw/i8259.c
index ab519de..da34f2b 100644
--- a/hw/i8259.c
+++ b/hw/i8259.c
@@ -556,13 +556,19 @@ qemu_irq *i8259_init(qemu_irq parent_irq)
return irq_set;
}
+static void pic_class_initfn(ObjectClass *klass, void *data)
+{
+ ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+ ic->init = pic_initfn;
+}
+
static ISADeviceInfo i8259_info = {
.qdev.name = "isa-i8259",
.qdev.size = sizeof(PicState),
.qdev.vmsd = &vmstate_pic,
.qdev.reset = pic_reset,
.qdev.no_user = 1,
- .init = pic_initfn,
+ .qdev.class_init = pic_class_initfn,
.qdev.props = (Property[]) {
DEFINE_PROP_HEX32("iobase", PicState, iobase, -1),
DEFINE_PROP_HEX32("elcr_addr", PicState, elcr_addr, -1),
diff --git a/hw/ide/isa.c b/hw/ide/isa.c
index 01a9e59..aeca96d 100644
--- a/hw/ide/isa.c
+++ b/hw/ide/isa.c
@@ -94,11 +94,17 @@ ISADevice *isa_ide_init(int iobase, int iobase2, int isairq,
return dev;
}
+static void isa_ide_class_initfn(ObjectClass *klass, void *data)
+{
+ ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+ ic->init = isa_ide_initfn;
+}
+
static ISADeviceInfo isa_ide_info = {
.qdev.name = "isa-ide",
.qdev.fw_name = "ide",
.qdev.size = sizeof(ISAIDEState),
- .init = isa_ide_initfn,
+ .qdev.class_init = isa_ide_class_initfn,
.qdev.reset = isa_ide_reset,
.qdev.props = (Property[]) {
DEFINE_PROP_HEX32("iobase", ISAIDEState, iobase, 0x1f0),
diff --git a/hw/isa-bus.c b/hw/isa-bus.c
index 50131f7..9d02919 100644
--- a/hw/isa-bus.c
+++ b/hw/isa-bus.c
@@ -114,12 +114,16 @@ void isa_register_portio_list(ISADevice *dev, uint16_t start,
static int isa_qdev_init(DeviceState *qdev, DeviceInfo *base)
{
ISADevice *dev = ISA_DEVICE(qdev);
- ISADeviceInfo *info = DO_UPCAST(ISADeviceInfo, qdev, base);
+ ISADeviceClass *klass = ISA_DEVICE_GET_CLASS(dev);
dev->isairq[0] = -1;
dev->isairq[1] = -1;
- return info->init(dev);
+ if (klass->init) {
+ return klass->init(dev);
+ }
+
+ return 0;
}
void isa_qdev_register(ISADeviceInfo *info)
diff --git a/hw/isa.h b/hw/isa.h
index d5fd7d7..a1afc7b 100644
--- a/hw/isa.h
+++ b/hw/isa.h
@@ -23,6 +23,7 @@ typedef struct ISADeviceInfo ISADeviceInfo;
typedef struct ISADeviceClass {
DeviceClass parent_class;
+ int (*init)(ISADevice *dev);
} ISADeviceClass;
struct ISADevice {
@@ -32,10 +33,8 @@ struct ISADevice {
int ioport_id;
};
-typedef int (*isa_qdev_initfn)(ISADevice *dev);
struct ISADeviceInfo {
DeviceInfo qdev;
- isa_qdev_initfn init;
};
ISABus *isa_bus_new(DeviceState *dev, MemoryRegion *address_space_io);
diff --git a/hw/m48t59.c b/hw/m48t59.c
index a77937e..e58b48f 100644
--- a/hw/m48t59.c
+++ b/hw/m48t59.c
@@ -724,8 +724,14 @@ static int m48t59_init1(SysBusDevice *dev)
return 0;
}
+static void m48t59_init_class_isa1(ObjectClass *klass, void *data)
+{
+ ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+ ic->init = m48t59_init_isa1;
+}
+
static ISADeviceInfo m48t59_isa_info = {
- .init = m48t59_init_isa1,
+ .qdev.class_init = m48t59_init_class_isa1,
.qdev.name = "m48t59_isa",
.qdev.size = sizeof(M48t59ISAState),
.qdev.reset = m48t59_reset_isa,
diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
index d5b737a..e2acf12 100644
--- a/hw/mc146818rtc.c
+++ b/hw/mc146818rtc.c
@@ -694,12 +694,18 @@ ISADevice *rtc_init(int base_year, qemu_irq intercept_irq)
return dev;
}
+static void rtc_class_initfn(ObjectClass *klass, void *data)
+{
+ ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+ ic->init = rtc_initfn;
+}
+
static ISADeviceInfo mc146818rtc_info = {
.qdev.name = "mc146818rtc",
.qdev.size = sizeof(RTCState),
.qdev.no_user = 1,
.qdev.vmsd = &vmstate_rtc,
- .init = rtc_initfn,
+ .qdev.class_init = rtc_class_initfn,
.qdev.props = (Property[]) {
DEFINE_PROP_INT32("base_year", RTCState, base_year, 1980),
DEFINE_PROP_END_OF_LIST(),
diff --git a/hw/ne2000-isa.c b/hw/ne2000-isa.c
index 9e89256..da86a61 100644
--- a/hw/ne2000-isa.c
+++ b/hw/ne2000-isa.c
@@ -82,10 +82,16 @@ static int isa_ne2000_initfn(ISADevice *dev)
return 0;
}
+static void isa_ne2000_class_initfn(ObjectClass *klass, void *data)
+{
+ ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+ ic->init = isa_ne2000_initfn;
+}
+
static ISADeviceInfo ne2000_isa_info = {
.qdev.name = "ne2k_isa",
.qdev.size = sizeof(ISANE2000State),
- .init = isa_ne2000_initfn,
+ .qdev.class_init = isa_ne2000_class_initfn,
.qdev.props = (Property[]) {
DEFINE_PROP_HEX32("iobase", ISANE2000State, iobase, 0x300),
DEFINE_PROP_UINT32("irq", ISANE2000State, isairq, 9),
diff --git a/hw/parallel.c b/hw/parallel.c
index 8494d94..ac7dc46 100644
--- a/hw/parallel.c
+++ b/hw/parallel.c
@@ -586,10 +586,16 @@ bool parallel_mm_init(target_phys_addr_t base, int it_shift, qemu_irq irq,
return true;
}
+static void parallel_isa_class_initfn(ObjectClass *klass, void *data)
+{
+ ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+ ic->init = parallel_isa_initfn;
+}
+
static ISADeviceInfo parallel_isa_info = {
.qdev.name = "isa-parallel",
.qdev.size = sizeof(ISAParallelState),
- .init = parallel_isa_initfn,
+ .qdev.class_init = parallel_isa_class_initfn,
.qdev.props = (Property[]) {
DEFINE_PROP_UINT32("index", ISAParallelState, index, -1),
DEFINE_PROP_HEX32("iobase", ISAParallelState, iobase, -1),
diff --git a/hw/pc.c b/hw/pc.c
index 47e6fb9..4e4dc6d 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -496,13 +496,19 @@ static int port92_initfn(ISADevice *dev)
return 0;
}
+static void port92_class_initfn(ObjectClass *klass, void *data)
+{
+ ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+ ic->init = port92_initfn;
+}
+
static ISADeviceInfo port92_info = {
.qdev.name = "port92",
.qdev.size = sizeof(Port92State),
.qdev.vmsd = &vmstate_port92_isa,
.qdev.no_user = 1,
.qdev.reset = port92_reset,
- .init = port92_initfn,
+ .qdev.class_init = port92_class_initfn,
};
static void port92_register(void)
diff --git a/hw/pckbd.c b/hw/pckbd.c
index 06b40c5..fe5cc6e 100644
--- a/hw/pckbd.c
+++ b/hw/pckbd.c
@@ -497,12 +497,18 @@ static int i8042_initfn(ISADevice *dev)
return 0;
}
+static void i8042_class_initfn(ObjectClass *klass, void *data)
+{
+ ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+ ic->init = i8042_initfn;
+}
+
static ISADeviceInfo i8042_info = {
.qdev.name = "i8042",
.qdev.size = sizeof(ISAKBDState),
.qdev.vmsd = &vmstate_kbd_isa,
.qdev.no_user = 1,
- .init = i8042_initfn,
+ .qdev.class_init = i8042_class_initfn,
};
static void i8042_register(void)
diff --git a/hw/sb16.c b/hw/sb16.c
index f0658ac..f7a6b7e 100644
--- a/hw/sb16.c
+++ b/hw/sb16.c
@@ -1391,12 +1391,18 @@ int SB16_init (qemu_irq *pic)
return 0;
}
+static void sb16_class_initfn(ObjectClass *klass, void *data)
+{
+ ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+ ic->init = sb16_initfn;
+}
+
static ISADeviceInfo sb16_info = {
.qdev.name = "sb16",
.qdev.desc = "Creative Sound Blaster 16",
.qdev.size = sizeof (SB16State),
.qdev.vmsd = &vmstate_sb16,
- .init = sb16_initfn,
+ .qdev.class_init = sb16_class_initfn,
.qdev.props = (Property[]) {
DEFINE_PROP_HEX32 ("version", SB16State, ver, 0x0405), /* 4.5 */
DEFINE_PROP_HEX32 ("iobase", SB16State, port, 0x220),
diff --git a/hw/serial.c b/hw/serial.c
index d35c7a9..74ed5fe 100644
--- a/hw/serial.c
+++ b/hw/serial.c
@@ -879,11 +879,17 @@ SerialState *serial_mm_init(MemoryRegion *address_space,
return s;
}
+static void serial_isa_class_initfn(ObjectClass *klass, void *data)
+{
+ ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+ ic->init = serial_isa_initfn;
+}
+
static ISADeviceInfo serial_isa_info = {
.qdev.name = "isa-serial",
.qdev.size = sizeof(ISASerialState),
.qdev.vmsd = &vmstate_isa_serial,
- .init = serial_isa_initfn,
+ .qdev.class_init = serial_isa_class_initfn,
.qdev.props = (Property[]) {
DEFINE_PROP_UINT32("index", ISASerialState, index, -1),
DEFINE_PROP_HEX32("iobase", ISASerialState, iobase, -1),
diff --git a/hw/sga.c b/hw/sga.c
index 7ef750a..6801995 100644
--- a/hw/sga.c
+++ b/hw/sga.c
@@ -41,11 +41,17 @@ static int isa_cirrus_vga_initfn(ISADevice *dev)
return 0;
}
+static void isa_cirrus_vga_class_initfn(ObjectClass *klass, void *data)
+{
+ ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+ ic->init = isa_cirrus_vga_initfn;
+}
+
static ISADeviceInfo sga_info = {
.qdev.name = "sga",
.qdev.desc = "Serial Graphics Adapter",
.qdev.size = sizeof(ISASGAState),
- .init = isa_cirrus_vga_initfn,
+ .qdev.class_init = isa_cirrus_vga_class_initfn,
};
static void sga_register(void)
diff --git a/hw/vga-isa.c b/hw/vga-isa.c
index 4825313..ba7f9bf 100644
--- a/hw/vga-isa.c
+++ b/hw/vga-isa.c
@@ -69,12 +69,18 @@ static int vga_initfn(ISADevice *dev)
return 0;
}
+static void vga_class_initfn(ObjectClass *klass, void *data)
+{
+ ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+ ic->init = vga_initfn;
+}
+
static ISADeviceInfo vga_info = {
.qdev.name = "isa-vga",
.qdev.size = sizeof(ISAVGAState),
.qdev.vmsd = &vmstate_vga_common,
.qdev.reset = vga_reset_isa,
- .init = vga_initfn,
+ .qdev.class_init = vga_class_initfn,
};
static void vga_register(void)
diff --git a/hw/vmmouse.c b/hw/vmmouse.c
index 1113f33..f936089 100644
--- a/hw/vmmouse.c
+++ b/hw/vmmouse.c
@@ -269,8 +269,14 @@ static int vmmouse_initfn(ISADevice *dev)
return 0;
}
+static void vmmouse_class_initfn(ObjectClass *klass, void *data)
+{
+ ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+ ic->init = vmmouse_initfn;
+}
+
static ISADeviceInfo vmmouse_info = {
- .init = vmmouse_initfn,
+ .qdev.class_init = vmmouse_class_initfn,
.qdev.name = "vmmouse",
.qdev.size = sizeof(VMMouseState),
.qdev.vmsd = &vmstate_vmmouse,
diff --git a/hw/vmport.c b/hw/vmport.c
index b5c6fa1..7468812 100644
--- a/hw/vmport.c
+++ b/hw/vmport.c
@@ -144,11 +144,17 @@ static int vmport_initfn(ISADevice *dev)
return 0;
}
+static void vmport_class_initfn(ObjectClass *klass, void *data)
+{
+ ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+ ic->init = vmport_initfn;
+}
+
static ISADeviceInfo vmport_info = {
.qdev.name = "vmport",
.qdev.size = sizeof(VMPortState),
.qdev.no_user = 1,
- .init = vmport_initfn,
+ .qdev.class_init = vmport_class_initfn,
};
static void vmport_dev_register(void)
diff --git a/hw/wdt_ib700.c b/hw/wdt_ib700.c
index 81f22d0..3869e91 100644
--- a/hw/wdt_ib700.c
+++ b/hw/wdt_ib700.c
@@ -120,12 +120,18 @@ static WatchdogTimerModel model = {
.wdt_description = "iBASE 700",
};
+static void wdt_ib700_class_init(ObjectClass *klass, void *data)
+{
+ ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+ ic->init = wdt_ib700_init;
+}
+
static ISADeviceInfo wdt_ib700_info = {
.qdev.name = "ib700",
.qdev.size = sizeof(IB700State),
.qdev.vmsd = &vmstate_ib700,
.qdev.reset = wdt_ib700_reset,
- .init = wdt_ib700_init,
+ .qdev.class_init = wdt_ib700_class_init,
};
static void wdt_ib700_register_devices(void)
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 043/197] kill off ISADeviceInfo
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (39 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 042/197] isa: move methods from isadeviceinfo to isadeviceclass Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 044/197] usb: don't access dev->info directly Anthony Liguori
` (25 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/applesmc.c | 12 ++++++------
hw/cs4231a.c | 14 +++++++-------
hw/debugcon.c | 10 +++++-----
hw/fdc.c | 18 +++++++++---------
hw/gus.c | 14 +++++++-------
hw/i8254.c | 16 ++++++++--------
hw/i8259.c | 16 ++++++++--------
hw/ide/isa.c | 14 +++++++-------
hw/isa-bus.c | 8 ++++----
hw/isa.h | 7 +------
hw/m48t59.c | 14 +++++++-------
hw/mc146818rtc.c | 14 +++++++-------
hw/ne2000-isa.c | 10 +++++-----
hw/parallel.c | 10 +++++-----
hw/pc.c | 14 +++++++-------
hw/pckbd.c | 12 ++++++------
hw/sb16.c | 14 +++++++-------
hw/serial.c | 12 ++++++------
hw/sga.c | 10 +++++-----
hw/vga-isa.c | 12 ++++++------
hw/vmmouse.c | 16 ++++++++--------
hw/vmport.c | 10 +++++-----
hw/wdt_ib700.c | 12 ++++++------
23 files changed, 142 insertions(+), 147 deletions(-)
diff --git a/hw/applesmc.c b/hw/applesmc.c
index 279c4d3..a6e88bc 100644
--- a/hw/applesmc.c
+++ b/hw/applesmc.c
@@ -226,12 +226,12 @@ static void qdev_applesmc_class_init(ObjectClass *klass, void *data)
ic->init = applesmc_isa_init;
}
-static ISADeviceInfo applesmc_isa_info = {
- .qdev.name = "isa-applesmc",
- .qdev.size = sizeof(struct AppleSMCStatus),
- .qdev.reset = qdev_applesmc_isa_reset,
- .qdev.class_init = qdev_applesmc_class_init,
- .qdev.props = (Property[]) {
+static DeviceInfo applesmc_isa_info = {
+ .name = "isa-applesmc",
+ .size = sizeof(struct AppleSMCStatus),
+ .reset = qdev_applesmc_isa_reset,
+ .class_init = qdev_applesmc_class_init,
+ .props = (Property[]) {
DEFINE_PROP_HEX32("iobase", struct AppleSMCStatus, iobase,
APPLESMC_DEFAULT_IOBASE),
DEFINE_PROP_STRING("osk", struct AppleSMCStatus, osk),
diff --git a/hw/cs4231a.c b/hw/cs4231a.c
index 25af773..3474aec 100644
--- a/hw/cs4231a.c
+++ b/hw/cs4231a.c
@@ -671,13 +671,13 @@ static void cs4231a_class_initfn(ObjectClass *klass, void *data)
ic->init = cs4231a_initfn;
}
-static ISADeviceInfo cs4231a_info = {
- .qdev.name = "cs4231a",
- .qdev.desc = "Crystal Semiconductor CS4231A",
- .qdev.size = sizeof (CSState),
- .qdev.vmsd = &vmstate_cs4231a,
- .qdev.class_init = cs4231a_class_initfn,
- .qdev.props = (Property[]) {
+static DeviceInfo cs4231a_info = {
+ .name = "cs4231a",
+ .desc = "Crystal Semiconductor CS4231A",
+ .size = sizeof (CSState),
+ .vmsd = &vmstate_cs4231a,
+ .class_init = cs4231a_class_initfn,
+ .props = (Property[]) {
DEFINE_PROP_HEX32 ("iobase", CSState, port, 0x534),
DEFINE_PROP_UINT32 ("irq", CSState, irq, 9),
DEFINE_PROP_UINT32 ("dma", CSState, dma, 3),
diff --git a/hw/debugcon.c b/hw/debugcon.c
index 1490bfa..f290122 100644
--- a/hw/debugcon.c
+++ b/hw/debugcon.c
@@ -93,11 +93,11 @@ static void debugcon_isa_class_initfn(ObjectClass *klass, void *data)
ic->init = debugcon_isa_initfn;
}
-static ISADeviceInfo debugcon_isa_info = {
- .qdev.name = "isa-debugcon",
- .qdev.size = sizeof(ISADebugconState),
- .qdev.class_init = debugcon_isa_class_initfn,
- .qdev.props = (Property[]) {
+static DeviceInfo debugcon_isa_info = {
+ .name = "isa-debugcon",
+ .size = sizeof(ISADebugconState),
+ .class_init = debugcon_isa_class_initfn,
+ .props = (Property[]) {
DEFINE_PROP_HEX32("iobase", ISADebugconState, iobase, 0xe9),
DEFINE_PROP_CHR("chardev", ISADebugconState, state.chr),
DEFINE_PROP_HEX32("readback", ISADebugconState, state.readback, 0xe9),
diff --git a/hw/fdc.c b/hw/fdc.c
index dfeb138..7223033 100644
--- a/hw/fdc.c
+++ b/hw/fdc.c
@@ -1975,15 +1975,15 @@ static void isabus_fdc_class_init1(ObjectClass *klass, void *data)
ic->init = isabus_fdc_init1;
}
-static ISADeviceInfo isa_fdc_info = {
- .qdev.class_init = isabus_fdc_class_init1,
- .qdev.name = "isa-fdc",
- .qdev.fw_name = "fdc",
- .qdev.size = sizeof(FDCtrlISABus),
- .qdev.no_user = 1,
- .qdev.vmsd = &vmstate_isa_fdc,
- .qdev.reset = fdctrl_external_reset_isa,
- .qdev.props = (Property[]) {
+static DeviceInfo isa_fdc_info = {
+ .class_init = isabus_fdc_class_init1,
+ .name = "isa-fdc",
+ .fw_name = "fdc",
+ .size = sizeof(FDCtrlISABus),
+ .no_user = 1,
+ .vmsd = &vmstate_isa_fdc,
+ .reset = fdctrl_external_reset_isa,
+ .props = (Property[]) {
DEFINE_PROP_DRIVE("driveA", FDCtrlISABus, state.drives[0].bs),
DEFINE_PROP_DRIVE("driveB", FDCtrlISABus, state.drives[1].bs),
DEFINE_PROP_INT32("bootindexA", FDCtrlISABus, bootindexA, -1),
diff --git a/hw/gus.c b/hw/gus.c
index 49e0d16..1675cf5 100644
--- a/hw/gus.c
+++ b/hw/gus.c
@@ -305,13 +305,13 @@ static void gus_class_initfn(ObjectClass *klass, void *data)
ic->init = gus_initfn;
}
-static ISADeviceInfo gus_info = {
- .qdev.name = "gus",
- .qdev.desc = "Gravis Ultrasound GF1",
- .qdev.size = sizeof (GUSState),
- .qdev.vmsd = &vmstate_gus,
- .qdev.class_init = gus_class_initfn,
- .qdev.props = (Property[]) {
+static DeviceInfo gus_info = {
+ .name = "gus",
+ .desc = "Gravis Ultrasound GF1",
+ .size = sizeof (GUSState),
+ .vmsd = &vmstate_gus,
+ .class_init = gus_class_initfn,
+ .props = (Property[]) {
DEFINE_PROP_UINT32 ("freq", GUSState, freq, 44100),
DEFINE_PROP_HEX32 ("iobase", GUSState, port, 0x240),
DEFINE_PROP_UINT32 ("irq", GUSState, emu.gusirq, 7),
diff --git a/hw/i8254.c b/hw/i8254.c
index 5d10206..7766ce2 100644
--- a/hw/i8254.c
+++ b/hw/i8254.c
@@ -541,14 +541,14 @@ static void pit_class_initfn(ObjectClass *klass, void *data)
ic->init = pit_initfn;
}
-static ISADeviceInfo pit_info = {
- .qdev.name = "isa-pit",
- .qdev.size = sizeof(PITState),
- .qdev.vmsd = &vmstate_pit,
- .qdev.reset = pit_reset,
- .qdev.no_user = 1,
- .qdev.class_init = pit_class_initfn,
- .qdev.props = (Property[]) {
+static DeviceInfo pit_info = {
+ .name = "isa-pit",
+ .size = sizeof(PITState),
+ .vmsd = &vmstate_pit,
+ .reset = pit_reset,
+ .no_user = 1,
+ .class_init = pit_class_initfn,
+ .props = (Property[]) {
DEFINE_PROP_UINT32("irq", PITState, irq, -1),
DEFINE_PROP_HEX32("iobase", PITState, iobase, -1),
DEFINE_PROP_END_OF_LIST(),
diff --git a/hw/i8259.c b/hw/i8259.c
index da34f2b..12cd269 100644
--- a/hw/i8259.c
+++ b/hw/i8259.c
@@ -562,14 +562,14 @@ static void pic_class_initfn(ObjectClass *klass, void *data)
ic->init = pic_initfn;
}
-static ISADeviceInfo i8259_info = {
- .qdev.name = "isa-i8259",
- .qdev.size = sizeof(PicState),
- .qdev.vmsd = &vmstate_pic,
- .qdev.reset = pic_reset,
- .qdev.no_user = 1,
- .qdev.class_init = pic_class_initfn,
- .qdev.props = (Property[]) {
+static DeviceInfo i8259_info = {
+ .name = "isa-i8259",
+ .size = sizeof(PicState),
+ .vmsd = &vmstate_pic,
+ .reset = pic_reset,
+ .no_user = 1,
+ .class_init = pic_class_initfn,
+ .props = (Property[]) {
DEFINE_PROP_HEX32("iobase", PicState, iobase, -1),
DEFINE_PROP_HEX32("elcr_addr", PicState, elcr_addr, -1),
DEFINE_PROP_HEX8("elcr_mask", PicState, elcr_mask, -1),
diff --git a/hw/ide/isa.c b/hw/ide/isa.c
index aeca96d..3c1b479 100644
--- a/hw/ide/isa.c
+++ b/hw/ide/isa.c
@@ -100,13 +100,13 @@ static void isa_ide_class_initfn(ObjectClass *klass, void *data)
ic->init = isa_ide_initfn;
}
-static ISADeviceInfo isa_ide_info = {
- .qdev.name = "isa-ide",
- .qdev.fw_name = "ide",
- .qdev.size = sizeof(ISAIDEState),
- .qdev.class_init = isa_ide_class_initfn,
- .qdev.reset = isa_ide_reset,
- .qdev.props = (Property[]) {
+static DeviceInfo isa_ide_info = {
+ .name = "isa-ide",
+ .fw_name = "ide",
+ .size = sizeof(ISAIDEState),
+ .class_init = isa_ide_class_initfn,
+ .reset = isa_ide_reset,
+ .props = (Property[]) {
DEFINE_PROP_HEX32("iobase", ISAIDEState, iobase, 0x1f0),
DEFINE_PROP_HEX32("iobase2", ISAIDEState, iobase2, 0x3f6),
DEFINE_PROP_UINT32("irq", ISAIDEState, isairq, 14),
diff --git a/hw/isa-bus.c b/hw/isa-bus.c
index 9d02919..e3d67fe 100644
--- a/hw/isa-bus.c
+++ b/hw/isa-bus.c
@@ -126,11 +126,11 @@ static int isa_qdev_init(DeviceState *qdev, DeviceInfo *base)
return 0;
}
-void isa_qdev_register(ISADeviceInfo *info)
+void isa_qdev_register(DeviceInfo *info)
{
- info->qdev.init = isa_qdev_init;
- info->qdev.bus_info = &isa_bus_info;
- qdev_register_subclass(&info->qdev, TYPE_ISA_DEVICE);
+ info->init = isa_qdev_init;
+ info->bus_info = &isa_bus_info;
+ qdev_register_subclass(info, TYPE_ISA_DEVICE);
}
ISADevice *isa_create(const char *name)
diff --git a/hw/isa.h b/hw/isa.h
index a1afc7b..08a24da 100644
--- a/hw/isa.h
+++ b/hw/isa.h
@@ -11,7 +11,6 @@
typedef struct ISABus ISABus;
typedef struct ISADevice ISADevice;
-typedef struct ISADeviceInfo ISADeviceInfo;
#define TYPE_ISA_DEVICE "isa-device"
#define ISA_DEVICE(obj) \
@@ -33,15 +32,11 @@ struct ISADevice {
int ioport_id;
};
-struct ISADeviceInfo {
- DeviceInfo qdev;
-};
-
ISABus *isa_bus_new(DeviceState *dev, MemoryRegion *address_space_io);
void isa_bus_irqs(qemu_irq *irqs);
qemu_irq isa_get_irq(int isairq);
void isa_init_irq(ISADevice *dev, qemu_irq *p, int isairq);
-void isa_qdev_register(ISADeviceInfo *info);
+void isa_qdev_register(DeviceInfo *info);
MemoryRegion *isa_address_space(ISADevice *dev);
ISADevice *isa_create(const char *name);
ISADevice *isa_try_create(const char *name);
diff --git a/hw/m48t59.c b/hw/m48t59.c
index e58b48f..760ccdd 100644
--- a/hw/m48t59.c
+++ b/hw/m48t59.c
@@ -730,13 +730,13 @@ static void m48t59_init_class_isa1(ObjectClass *klass, void *data)
ic->init = m48t59_init_isa1;
}
-static ISADeviceInfo m48t59_isa_info = {
- .qdev.class_init = m48t59_init_class_isa1,
- .qdev.name = "m48t59_isa",
- .qdev.size = sizeof(M48t59ISAState),
- .qdev.reset = m48t59_reset_isa,
- .qdev.no_user = 1,
- .qdev.props = (Property[]) {
+static DeviceInfo m48t59_isa_info = {
+ .class_init = m48t59_init_class_isa1,
+ .name = "m48t59_isa",
+ .size = sizeof(M48t59ISAState),
+ .reset = m48t59_reset_isa,
+ .no_user = 1,
+ .props = (Property[]) {
DEFINE_PROP_UINT32("size", M48t59ISAState, state.size, -1),
DEFINE_PROP_UINT32("type", M48t59ISAState, state.type, -1),
DEFINE_PROP_HEX32( "io_base", M48t59ISAState, state.io_base, 0),
diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
index e2acf12..0674e06 100644
--- a/hw/mc146818rtc.c
+++ b/hw/mc146818rtc.c
@@ -700,13 +700,13 @@ static void rtc_class_initfn(ObjectClass *klass, void *data)
ic->init = rtc_initfn;
}
-static ISADeviceInfo mc146818rtc_info = {
- .qdev.name = "mc146818rtc",
- .qdev.size = sizeof(RTCState),
- .qdev.no_user = 1,
- .qdev.vmsd = &vmstate_rtc,
- .qdev.class_init = rtc_class_initfn,
- .qdev.props = (Property[]) {
+static DeviceInfo mc146818rtc_info = {
+ .name = "mc146818rtc",
+ .size = sizeof(RTCState),
+ .no_user = 1,
+ .vmsd = &vmstate_rtc,
+ .class_init = rtc_class_initfn,
+ .props = (Property[]) {
DEFINE_PROP_INT32("base_year", RTCState, base_year, 1980),
DEFINE_PROP_END_OF_LIST(),
}
diff --git a/hw/ne2000-isa.c b/hw/ne2000-isa.c
index da86a61..e1d1603 100644
--- a/hw/ne2000-isa.c
+++ b/hw/ne2000-isa.c
@@ -88,11 +88,11 @@ static void isa_ne2000_class_initfn(ObjectClass *klass, void *data)
ic->init = isa_ne2000_initfn;
}
-static ISADeviceInfo ne2000_isa_info = {
- .qdev.name = "ne2k_isa",
- .qdev.size = sizeof(ISANE2000State),
- .qdev.class_init = isa_ne2000_class_initfn,
- .qdev.props = (Property[]) {
+static DeviceInfo ne2000_isa_info = {
+ .name = "ne2k_isa",
+ .size = sizeof(ISANE2000State),
+ .class_init = isa_ne2000_class_initfn,
+ .props = (Property[]) {
DEFINE_PROP_HEX32("iobase", ISANE2000State, iobase, 0x300),
DEFINE_PROP_UINT32("irq", ISANE2000State, isairq, 9),
DEFINE_NIC_PROPERTIES(ISANE2000State, ne2000.c),
diff --git a/hw/parallel.c b/hw/parallel.c
index ac7dc46..622e4d2 100644
--- a/hw/parallel.c
+++ b/hw/parallel.c
@@ -592,11 +592,11 @@ static void parallel_isa_class_initfn(ObjectClass *klass, void *data)
ic->init = parallel_isa_initfn;
}
-static ISADeviceInfo parallel_isa_info = {
- .qdev.name = "isa-parallel",
- .qdev.size = sizeof(ISAParallelState),
- .qdev.class_init = parallel_isa_class_initfn,
- .qdev.props = (Property[]) {
+static DeviceInfo parallel_isa_info = {
+ .name = "isa-parallel",
+ .size = sizeof(ISAParallelState),
+ .class_init = parallel_isa_class_initfn,
+ .props = (Property[]) {
DEFINE_PROP_UINT32("index", ISAParallelState, index, -1),
DEFINE_PROP_HEX32("iobase", ISAParallelState, iobase, -1),
DEFINE_PROP_UINT32("irq", ISAParallelState, isairq, 7),
diff --git a/hw/pc.c b/hw/pc.c
index 4e4dc6d..2d69208 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -502,13 +502,13 @@ static void port92_class_initfn(ObjectClass *klass, void *data)
ic->init = port92_initfn;
}
-static ISADeviceInfo port92_info = {
- .qdev.name = "port92",
- .qdev.size = sizeof(Port92State),
- .qdev.vmsd = &vmstate_port92_isa,
- .qdev.no_user = 1,
- .qdev.reset = port92_reset,
- .qdev.class_init = port92_class_initfn,
+static DeviceInfo port92_info = {
+ .name = "port92",
+ .size = sizeof(Port92State),
+ .vmsd = &vmstate_port92_isa,
+ .no_user = 1,
+ .reset = port92_reset,
+ .class_init = port92_class_initfn,
};
static void port92_register(void)
diff --git a/hw/pckbd.c b/hw/pckbd.c
index fe5cc6e..2ebe1c5 100644
--- a/hw/pckbd.c
+++ b/hw/pckbd.c
@@ -503,12 +503,12 @@ static void i8042_class_initfn(ObjectClass *klass, void *data)
ic->init = i8042_initfn;
}
-static ISADeviceInfo i8042_info = {
- .qdev.name = "i8042",
- .qdev.size = sizeof(ISAKBDState),
- .qdev.vmsd = &vmstate_kbd_isa,
- .qdev.no_user = 1,
- .qdev.class_init = i8042_class_initfn,
+static DeviceInfo i8042_info = {
+ .name = "i8042",
+ .size = sizeof(ISAKBDState),
+ .vmsd = &vmstate_kbd_isa,
+ .no_user = 1,
+ .class_init = i8042_class_initfn,
};
static void i8042_register(void)
diff --git a/hw/sb16.c b/hw/sb16.c
index f7a6b7e..1e28f66 100644
--- a/hw/sb16.c
+++ b/hw/sb16.c
@@ -1397,13 +1397,13 @@ static void sb16_class_initfn(ObjectClass *klass, void *data)
ic->init = sb16_initfn;
}
-static ISADeviceInfo sb16_info = {
- .qdev.name = "sb16",
- .qdev.desc = "Creative Sound Blaster 16",
- .qdev.size = sizeof (SB16State),
- .qdev.vmsd = &vmstate_sb16,
- .qdev.class_init = sb16_class_initfn,
- .qdev.props = (Property[]) {
+static DeviceInfo sb16_info = {
+ .name = "sb16",
+ .desc = "Creative Sound Blaster 16",
+ .size = sizeof (SB16State),
+ .vmsd = &vmstate_sb16,
+ .class_init = sb16_class_initfn,
+ .props = (Property[]) {
DEFINE_PROP_HEX32 ("version", SB16State, ver, 0x0405), /* 4.5 */
DEFINE_PROP_HEX32 ("iobase", SB16State, port, 0x220),
DEFINE_PROP_UINT32 ("irq", SB16State, irq, 5),
diff --git a/hw/serial.c b/hw/serial.c
index 74ed5fe..2644b13 100644
--- a/hw/serial.c
+++ b/hw/serial.c
@@ -885,12 +885,12 @@ static void serial_isa_class_initfn(ObjectClass *klass, void *data)
ic->init = serial_isa_initfn;
}
-static ISADeviceInfo serial_isa_info = {
- .qdev.name = "isa-serial",
- .qdev.size = sizeof(ISASerialState),
- .qdev.vmsd = &vmstate_isa_serial,
- .qdev.class_init = serial_isa_class_initfn,
- .qdev.props = (Property[]) {
+static DeviceInfo serial_isa_info = {
+ .name = "isa-serial",
+ .size = sizeof(ISASerialState),
+ .vmsd = &vmstate_isa_serial,
+ .class_init = serial_isa_class_initfn,
+ .props = (Property[]) {
DEFINE_PROP_UINT32("index", ISASerialState, index, -1),
DEFINE_PROP_HEX32("iobase", ISASerialState, iobase, -1),
DEFINE_PROP_UINT32("irq", ISASerialState, isairq, -1),
diff --git a/hw/sga.c b/hw/sga.c
index 6801995..07ed2d0 100644
--- a/hw/sga.c
+++ b/hw/sga.c
@@ -47,11 +47,11 @@ static void isa_cirrus_vga_class_initfn(ObjectClass *klass, void *data)
ic->init = isa_cirrus_vga_initfn;
}
-static ISADeviceInfo sga_info = {
- .qdev.name = "sga",
- .qdev.desc = "Serial Graphics Adapter",
- .qdev.size = sizeof(ISASGAState),
- .qdev.class_init = isa_cirrus_vga_class_initfn,
+static DeviceInfo sga_info = {
+ .name = "sga",
+ .desc = "Serial Graphics Adapter",
+ .size = sizeof(ISASGAState),
+ .class_init = isa_cirrus_vga_class_initfn,
};
static void sga_register(void)
diff --git a/hw/vga-isa.c b/hw/vga-isa.c
index ba7f9bf..cb6af91 100644
--- a/hw/vga-isa.c
+++ b/hw/vga-isa.c
@@ -75,12 +75,12 @@ static void vga_class_initfn(ObjectClass *klass, void *data)
ic->init = vga_initfn;
}
-static ISADeviceInfo vga_info = {
- .qdev.name = "isa-vga",
- .qdev.size = sizeof(ISAVGAState),
- .qdev.vmsd = &vmstate_vga_common,
- .qdev.reset = vga_reset_isa,
- .qdev.class_init = vga_class_initfn,
+static DeviceInfo vga_info = {
+ .name = "isa-vga",
+ .size = sizeof(ISAVGAState),
+ .vmsd = &vmstate_vga_common,
+ .reset = vga_reset_isa,
+ .class_init = vga_class_initfn,
};
static void vga_register(void)
diff --git a/hw/vmmouse.c b/hw/vmmouse.c
index f936089..da2ea32 100644
--- a/hw/vmmouse.c
+++ b/hw/vmmouse.c
@@ -275,14 +275,14 @@ static void vmmouse_class_initfn(ObjectClass *klass, void *data)
ic->init = vmmouse_initfn;
}
-static ISADeviceInfo vmmouse_info = {
- .qdev.class_init = vmmouse_class_initfn,
- .qdev.name = "vmmouse",
- .qdev.size = sizeof(VMMouseState),
- .qdev.vmsd = &vmstate_vmmouse,
- .qdev.no_user = 1,
- .qdev.reset = vmmouse_reset,
- .qdev.props = (Property[]) {
+static DeviceInfo vmmouse_info = {
+ .class_init = vmmouse_class_initfn,
+ .name = "vmmouse",
+ .size = sizeof(VMMouseState),
+ .vmsd = &vmstate_vmmouse,
+ .no_user = 1,
+ .reset = vmmouse_reset,
+ .props = (Property[]) {
DEFINE_PROP_PTR("ps2_mouse", VMMouseState, ps2_mouse),
DEFINE_PROP_END_OF_LIST(),
}
diff --git a/hw/vmport.c b/hw/vmport.c
index 7468812..ffea73d 100644
--- a/hw/vmport.c
+++ b/hw/vmport.c
@@ -150,11 +150,11 @@ static void vmport_class_initfn(ObjectClass *klass, void *data)
ic->init = vmport_initfn;
}
-static ISADeviceInfo vmport_info = {
- .qdev.name = "vmport",
- .qdev.size = sizeof(VMPortState),
- .qdev.no_user = 1,
- .qdev.class_init = vmport_class_initfn,
+static DeviceInfo vmport_info = {
+ .name = "vmport",
+ .size = sizeof(VMPortState),
+ .no_user = 1,
+ .class_init = vmport_class_initfn,
};
static void vmport_dev_register(void)
diff --git a/hw/wdt_ib700.c b/hw/wdt_ib700.c
index 3869e91..68965d6 100644
--- a/hw/wdt_ib700.c
+++ b/hw/wdt_ib700.c
@@ -126,12 +126,12 @@ static void wdt_ib700_class_init(ObjectClass *klass, void *data)
ic->init = wdt_ib700_init;
}
-static ISADeviceInfo wdt_ib700_info = {
- .qdev.name = "ib700",
- .qdev.size = sizeof(IB700State),
- .qdev.vmsd = &vmstate_ib700,
- .qdev.reset = wdt_ib700_reset,
- .qdev.class_init = wdt_ib700_class_init,
+static DeviceInfo wdt_ib700_info = {
+ .name = "ib700",
+ .size = sizeof(IB700State),
+ .vmsd = &vmstate_ib700,
+ .reset = wdt_ib700_reset,
+ .class_init = wdt_ib700_class_init,
};
static void wdt_ib700_register_devices(void)
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 044/197] usb: don't access dev->info directly
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (40 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 043/197] kill off ISADeviceInfo Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 045/197] usb: get rid of info pointer Anthony Liguori
` (24 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/usb-bus.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
hw/usb-desc.c | 18 ++++++------
hw/usb.c | 24 +++++++----------
hw/usb.h | 22 +++++++++++++++
4 files changed, 117 insertions(+), 28 deletions(-)
diff --git a/hw/usb-bus.c b/hw/usb-bus.c
index 8924ac3..24a805d 100644
--- a/hw/usb-bus.c
+++ b/hw/usb-bus.c
@@ -65,13 +65,22 @@ USBBus *usb_bus_find(int busnr)
return NULL;
}
+static int usb_device_init(USBDevice *dev)
+{
+ if (dev->info->init) {
+ return dev->info->init(dev);
+ }
+ return 0;
+}
+
static int usb_qdev_init(DeviceState *qdev, DeviceInfo *base)
{
USBDevice *dev = USB_DEVICE(qdev);
USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev, base);
int rc;
- pstrcpy(dev->product_desc, sizeof(dev->product_desc), info->product_desc);
+ pstrcpy(dev->product_desc, sizeof(dev->product_desc),
+ usb_device_get_product_desc(dev));
dev->info = info;
dev->auto_attach = 1;
QLIST_INIT(&dev->strings);
@@ -79,7 +88,7 @@ static int usb_qdev_init(DeviceState *qdev, DeviceInfo *base)
if (rc != 0) {
goto err;
}
- rc = dev->info->init(dev);
+ rc = usb_device_init(dev);
if (rc != 0) {
goto err;
}
@@ -96,6 +105,13 @@ err:
return rc;
}
+static void usb_device_handle_destroy(USBDevice *dev)
+{
+ if (dev->info->handle_destroy) {
+ dev->info->handle_destroy(dev);
+ }
+}
+
static int usb_qdev_exit(DeviceState *qdev)
{
USBDevice *dev = USB_DEVICE(qdev);
@@ -103,9 +119,7 @@ static int usb_qdev_exit(DeviceState *qdev)
if (dev->attached) {
usb_device_detach(dev);
}
- if (dev->info->handle_destroy) {
- dev->info->handle_destroy(dev);
- }
+ usb_device_handle_destroy(dev);
if (dev->port) {
usb_release_port(dev);
}
@@ -481,6 +495,63 @@ USBDevice *usbdevice_create(const char *cmdline)
return usb->usbdevice_init(params);
}
+int usb_device_handle_packet(USBDevice *dev, USBPacket *p)
+{
+ if (dev->info->handle_packet) {
+ return dev->info->handle_packet(dev, p);
+ }
+ return -ENOSYS;
+}
+
+void usb_device_cancel_packet(USBDevice *dev, USBPacket *p)
+{
+ if (dev->info->cancel_packet) {
+ dev->info->cancel_packet(dev, p);
+ }
+}
+
+void usb_device_handle_attach(USBDevice *dev)
+{
+ if (dev->info->handle_attach) {
+ dev->info->handle_attach(dev);
+ }
+}
+
+void usb_device_handle_reset(USBDevice *dev)
+{
+ if (dev->info->handle_reset) {
+ dev->info->handle_reset(dev);
+ }
+}
+
+int usb_device_handle_control(USBDevice *dev, USBPacket *p, int request,
+ int value, int index, int length, uint8_t *data)
+{
+ if (dev->info->handle_control) {
+ return dev->info->handle_control(dev, p, request, value, index, length,
+ data);
+ }
+ return -ENOSYS;
+}
+
+int usb_device_handle_data(USBDevice *dev, USBPacket *p)
+{
+ if (dev->info->handle_data) {
+ return dev->info->handle_data(dev, p);
+ }
+ return -ENOSYS;
+}
+
+const char *usb_device_get_product_desc(USBDevice *dev)
+{
+ return dev->info->product_desc;
+}
+
+const USBDesc *usb_device_get_usb_desc(USBDevice *dev)
+{
+ return dev->info->usb_desc;
+}
+
static TypeInfo usb_device_type_info = {
.name = TYPE_USB_DEVICE,
.parent = TYPE_DEVICE,
diff --git a/hw/usb-desc.c b/hw/usb-desc.c
index ae2d384..1f5fc7a 100644
--- a/hw/usb-desc.c
+++ b/hw/usb-desc.c
@@ -225,7 +225,7 @@ int usb_desc_other(const USBDescOther *desc, uint8_t *dest, size_t len)
static void usb_desc_setdefaults(USBDevice *dev)
{
- const USBDesc *desc = dev->info->usb_desc;
+ const USBDesc *desc = usb_device_get_usb_desc(dev);
assert(desc != NULL);
switch (dev->speed) {
@@ -242,7 +242,7 @@ static void usb_desc_setdefaults(USBDevice *dev)
void usb_desc_init(USBDevice *dev)
{
- const USBDesc *desc = dev->info->usb_desc;
+ const USBDesc *desc = usb_device_get_usb_desc(dev);
assert(desc != NULL);
dev->speed = USB_SPEED_FULL;
@@ -258,7 +258,7 @@ void usb_desc_init(USBDevice *dev)
void usb_desc_attach(USBDevice *dev)
{
- const USBDesc *desc = dev->info->usb_desc;
+ const USBDesc *desc = usb_device_get_usb_desc(dev);
assert(desc != NULL);
if (desc->high && (dev->port->speedmask & USB_SPEED_MASK_HIGH)) {
@@ -267,7 +267,7 @@ void usb_desc_attach(USBDevice *dev)
dev->speed = USB_SPEED_FULL;
} else {
fprintf(stderr, "usb: port/device speed mismatch for \"%s\"\n",
- dev->info->product_desc);
+ usb_device_get_product_desc(dev));
return;
}
usb_desc_setdefaults(dev);
@@ -323,7 +323,7 @@ int usb_desc_string(USBDevice *dev, int index, uint8_t *dest, size_t len)
str = usb_desc_get_string(dev, index);
if (str == NULL) {
- str = dev->info->usb_desc->str[index];
+ str = usb_device_get_usb_desc(dev)->str[index];
if (str == NULL) {
return 0;
}
@@ -342,7 +342,7 @@ int usb_desc_string(USBDevice *dev, int index, uint8_t *dest, size_t len)
int usb_desc_get_descriptor(USBDevice *dev, int value, uint8_t *dest, size_t len)
{
- const USBDesc *desc = dev->info->usb_desc;
+ const USBDesc *desc = usb_device_get_usb_desc(dev);
const USBDescDevice *other_dev;
uint8_t buf[256];
uint8_t type = value >> 8;
@@ -350,9 +350,9 @@ int usb_desc_get_descriptor(USBDevice *dev, int value, uint8_t *dest, size_t len
int ret = -1;
if (dev->speed == USB_SPEED_HIGH) {
- other_dev = dev->info->usb_desc->full;
+ other_dev = usb_device_get_usb_desc(dev)->full;
} else {
- other_dev = dev->info->usb_desc->high;
+ other_dev = usb_device_get_usb_desc(dev)->high;
}
switch(type) {
@@ -407,7 +407,7 @@ int usb_desc_get_descriptor(USBDevice *dev, int value, uint8_t *dest, size_t len
int usb_desc_handle_control(USBDevice *dev, USBPacket *p,
int request, int value, int index, int length, uint8_t *data)
{
- const USBDesc *desc = dev->info->usb_desc;
+ const USBDesc *desc = usb_device_get_usb_desc(dev);
int i, ret = -1;
assert(desc != NULL);
diff --git a/hw/usb.c b/hw/usb.c
index 2216efe..e1cbfec 100644
--- a/hw/usb.c
+++ b/hw/usb.c
@@ -95,8 +95,8 @@ static int do_token_setup(USBDevice *s, USBPacket *p)
index = (s->setup_buf[5] << 8) | s->setup_buf[4];
if (s->setup_buf[0] & USB_DIR_IN) {
- ret = s->info->handle_control(s, p, request, value, index,
- s->setup_len, s->data_buf);
+ ret = usb_device_handle_control(s, p, request, value, index,
+ s->setup_len, s->data_buf);
if (ret == USB_RET_ASYNC) {
s->setup_state = SETUP_STATE_SETUP;
return USB_RET_ASYNC;
@@ -129,7 +129,7 @@ static int do_token_in(USBDevice *s, USBPacket *p)
int ret = 0;
if (p->devep != 0)
- return s->info->handle_data(s, p);
+ return usb_device_handle_data(s, p);
request = (s->setup_buf[0] << 8) | s->setup_buf[1];
value = (s->setup_buf[3] << 8) | s->setup_buf[2];
@@ -138,8 +138,8 @@ static int do_token_in(USBDevice *s, USBPacket *p)
switch(s->setup_state) {
case SETUP_STATE_ACK:
if (!(s->setup_buf[0] & USB_DIR_IN)) {
- ret = s->info->handle_control(s, p, request, value, index,
- s->setup_len, s->data_buf);
+ ret = usb_device_handle_control(s, p, request, value, index,
+ s->setup_len, s->data_buf);
if (ret == USB_RET_ASYNC) {
return USB_RET_ASYNC;
}
@@ -176,7 +176,7 @@ static int do_token_in(USBDevice *s, USBPacket *p)
static int do_token_out(USBDevice *s, USBPacket *p)
{
if (p->devep != 0)
- return s->info->handle_data(s, p);
+ return usb_device_handle_data(s, p);
switch(s->setup_state) {
case SETUP_STATE_ACK:
@@ -220,9 +220,7 @@ int usb_generic_handle_packet(USBDevice *s, USBPacket *p)
switch(p->pid) {
case USB_MSG_ATTACH:
s->state = USB_STATE_ATTACHED;
- if (s->info->handle_attach) {
- s->info->handle_attach(s);
- }
+ usb_device_handle_attach(s);
return 0;
case USB_MSG_DETACH:
@@ -233,9 +231,7 @@ int usb_generic_handle_packet(USBDevice *s, USBPacket *p)
s->remote_wakeup = 0;
s->addr = 0;
s->state = USB_STATE_DEFAULT;
- if (s->info->handle_reset) {
- s->info->handle_reset(s);
- }
+ usb_device_handle_reset(s);
return 0;
}
@@ -326,7 +322,7 @@ int usb_handle_packet(USBDevice *dev, USBPacket *p)
int ret;
assert(p->owner == NULL);
- ret = dev->info->handle_packet(dev, p);
+ ret = usb_device_handle_packet(dev, p);
if (ret == USB_RET_ASYNC) {
if (p->owner == NULL) {
p->owner = dev;
@@ -357,7 +353,7 @@ void usb_packet_complete(USBDevice *dev, USBPacket *p)
void usb_cancel_packet(USBPacket * p)
{
assert(p->owner != NULL);
- p->owner->info->cancel_packet(p->owner, p);
+ usb_device_cancel_packet(p->owner, p);
p->owner = NULL;
}
diff --git a/hw/usb.h b/hw/usb.h
index 5445927..e05c00d 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -1,3 +1,6 @@
+#ifndef QEMU_USB_H
+#define QEMU_USB_H
+
/*
* QEMU USB API
*
@@ -404,3 +407,22 @@ static inline USBBus *usb_bus_from_device(USBDevice *d)
{
return DO_UPCAST(USBBus, qbus, d->qdev.parent_bus);
}
+
+int usb_device_handle_packet(USBDevice *dev, USBPacket *p);
+
+void usb_device_cancel_packet(USBDevice *dev, USBPacket *p);
+
+void usb_device_handle_attach(USBDevice *dev);
+
+void usb_device_handle_reset(USBDevice *dev);
+
+int usb_device_handle_control(USBDevice *dev, USBPacket *p, int request, int value,
+ int index, int length, uint8_t *data);
+
+int usb_device_handle_data(USBDevice *dev, USBPacket *p);
+
+const char *usb_device_get_product_desc(USBDevice *dev);
+
+const USBDesc *usb_device_get_usb_desc(USBDevice *dev);
+
+#endif
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 045/197] usb: get rid of info pointer
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (41 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 044/197] usb: don't access dev->info directly Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 046/197] usb: promote all of the methods for USBDevice to class methods Anthony Liguori
` (23 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/usb-bus.c | 154 ++++++++++++++++++++++++++++++++-------------------------
hw/usb.h | 1 -
2 files changed, 86 insertions(+), 69 deletions(-)
diff --git a/hw/usb-bus.c b/hw/usb-bus.c
index 24a805d..8d9c82d 100644
--- a/hw/usb-bus.c
+++ b/hw/usb-bus.c
@@ -67,21 +67,103 @@ USBBus *usb_bus_find(int busnr)
static int usb_device_init(USBDevice *dev)
{
- if (dev->info->init) {
- return dev->info->init(dev);
+ USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
+ qdev_get_info(DEVICE(dev)));
+ if (info->init) {
+ return info->init(dev);
}
return 0;
}
+static void usb_device_handle_destroy(USBDevice *dev)
+{
+ USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
+ qdev_get_info(DEVICE(dev)));
+ if (info->handle_destroy) {
+ info->handle_destroy(dev);
+ }
+}
+
+int usb_device_handle_packet(USBDevice *dev, USBPacket *p)
+{
+ USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
+ qdev_get_info(DEVICE(dev)));
+ if (info->handle_packet) {
+ return info->handle_packet(dev, p);
+ }
+ return -ENOSYS;
+}
+
+void usb_device_cancel_packet(USBDevice *dev, USBPacket *p)
+{
+ USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
+ qdev_get_info(DEVICE(dev)));
+ if (info->cancel_packet) {
+ info->cancel_packet(dev, p);
+ }
+}
+
+void usb_device_handle_attach(USBDevice *dev)
+{
+ USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
+ qdev_get_info(DEVICE(dev)));
+ if (info->handle_attach) {
+ info->handle_attach(dev);
+ }
+}
+
+void usb_device_handle_reset(USBDevice *dev)
+{
+ USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
+ qdev_get_info(DEVICE(dev)));
+ if (info->handle_reset) {
+ info->handle_reset(dev);
+ }
+}
+
+int usb_device_handle_control(USBDevice *dev, USBPacket *p, int request,
+ int value, int index, int length, uint8_t *data)
+{
+ USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
+ qdev_get_info(DEVICE(dev)));
+ if (info->handle_control) {
+ return info->handle_control(dev, p, request, value, index, length,
+ data);
+ }
+ return -ENOSYS;
+}
+
+int usb_device_handle_data(USBDevice *dev, USBPacket *p)
+{
+ USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
+ qdev_get_info(DEVICE(dev)));
+ if (info->handle_data) {
+ return info->handle_data(dev, p);
+ }
+ return -ENOSYS;
+}
+
+const char *usb_device_get_product_desc(USBDevice *dev)
+{
+ USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
+ qdev_get_info(DEVICE(dev)));
+ return info->product_desc;
+}
+
+const USBDesc *usb_device_get_usb_desc(USBDevice *dev)
+{
+ USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
+ qdev_get_info(DEVICE(dev)));
+ return info->usb_desc;
+}
+
static int usb_qdev_init(DeviceState *qdev, DeviceInfo *base)
{
USBDevice *dev = USB_DEVICE(qdev);
- USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev, base);
int rc;
pstrcpy(dev->product_desc, sizeof(dev->product_desc),
usb_device_get_product_desc(dev));
- dev->info = info;
dev->auto_attach = 1;
QLIST_INIT(&dev->strings);
rc = usb_claim_port(dev);
@@ -105,13 +187,6 @@ err:
return rc;
}
-static void usb_device_handle_destroy(USBDevice *dev)
-{
- if (dev->info->handle_destroy) {
- dev->info->handle_destroy(dev);
- }
-}
-
static int usb_qdev_exit(DeviceState *qdev)
{
USBDevice *dev = USB_DEVICE(qdev);
@@ -495,63 +570,6 @@ USBDevice *usbdevice_create(const char *cmdline)
return usb->usbdevice_init(params);
}
-int usb_device_handle_packet(USBDevice *dev, USBPacket *p)
-{
- if (dev->info->handle_packet) {
- return dev->info->handle_packet(dev, p);
- }
- return -ENOSYS;
-}
-
-void usb_device_cancel_packet(USBDevice *dev, USBPacket *p)
-{
- if (dev->info->cancel_packet) {
- dev->info->cancel_packet(dev, p);
- }
-}
-
-void usb_device_handle_attach(USBDevice *dev)
-{
- if (dev->info->handle_attach) {
- dev->info->handle_attach(dev);
- }
-}
-
-void usb_device_handle_reset(USBDevice *dev)
-{
- if (dev->info->handle_reset) {
- dev->info->handle_reset(dev);
- }
-}
-
-int usb_device_handle_control(USBDevice *dev, USBPacket *p, int request,
- int value, int index, int length, uint8_t *data)
-{
- if (dev->info->handle_control) {
- return dev->info->handle_control(dev, p, request, value, index, length,
- data);
- }
- return -ENOSYS;
-}
-
-int usb_device_handle_data(USBDevice *dev, USBPacket *p)
-{
- if (dev->info->handle_data) {
- return dev->info->handle_data(dev, p);
- }
- return -ENOSYS;
-}
-
-const char *usb_device_get_product_desc(USBDevice *dev)
-{
- return dev->info->product_desc;
-}
-
-const USBDesc *usb_device_get_usb_desc(USBDevice *dev)
-{
- return dev->info->usb_desc;
-}
-
static TypeInfo usb_device_type_info = {
.name = TYPE_USB_DEVICE,
.parent = TYPE_DEVICE,
diff --git a/hw/usb.h b/hw/usb.h
index e05c00d..ee780b0 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -179,7 +179,6 @@ typedef struct USBDeviceClass {
/* definition of a USB device */
struct USBDevice {
DeviceState qdev;
- USBDeviceInfo *info;
USBPort *port;
char *port_path;
void *opaque;
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 046/197] usb: promote all of the methods for USBDevice to class methods
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (42 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 045/197] usb: get rid of info pointer Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 047/197] usb: use a factory instead of doing silly things for legacy Anthony Liguori
` (22 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/usb-bt.c | 23 +++++++++++------
hw/usb-bus.c | 66 ++++++++++++++++++++----------------------------
hw/usb-ccid.c | 27 ++++++++++++-------
hw/usb-hid.c | 75 +++++++++++++++++++++++++++++++++++-------------------
hw/usb-hub.c | 25 +++++++++++------
hw/usb-msd.c | 31 ++++++++++++++---------
hw/usb-net.c | 32 ++++++++++++++---------
hw/usb-serial.c | 55 +++++++++++++++++++++++++--------------
hw/usb-wacom.c | 25 +++++++++++------
hw/usb.h | 64 +++++++++++++++++++++++-----------------------
usb-linux.c | 27 ++++++++++++-------
11 files changed, 263 insertions(+), 187 deletions(-)
diff --git a/hw/usb-bt.c b/hw/usb-bt.c
index f30eec1..fd71f1f 100644
--- a/hw/usb-bt.c
+++ b/hw/usb-bt.c
@@ -549,18 +549,25 @@ static const VMStateDescription vmstate_usb_bt = {
.unmigratable = 1,
};
+static void usb_bt_class_initfn(ObjectClass *klass, void *data)
+{
+ USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+ uc->init = usb_bt_initfn;
+ uc->product_desc = "QEMU BT dongle";
+ uc->usb_desc = &desc_bluetooth;
+ uc->handle_packet = usb_generic_handle_packet;
+ uc->handle_reset = usb_bt_handle_reset;
+ uc->handle_control = usb_bt_handle_control;
+ uc->handle_data = usb_bt_handle_data;
+ uc->handle_destroy = usb_bt_handle_destroy;
+}
+
static struct USBDeviceInfo bt_info = {
- .product_desc = "QEMU BT dongle",
.qdev.name = "usb-bt-dongle",
.qdev.size = sizeof(struct USBBtState),
.qdev.vmsd = &vmstate_usb_bt,
- .usb_desc = &desc_bluetooth,
- .init = usb_bt_initfn,
- .handle_packet = usb_generic_handle_packet,
- .handle_reset = usb_bt_handle_reset,
- .handle_control = usb_bt_handle_control,
- .handle_data = usb_bt_handle_data,
- .handle_destroy = usb_bt_handle_destroy,
+ .qdev.class_init= usb_bt_class_initfn,
};
static void usb_bt_register_devices(void)
diff --git a/hw/usb-bus.c b/hw/usb-bus.c
index 8d9c82d..46426db 100644
--- a/hw/usb-bus.c
+++ b/hw/usb-bus.c
@@ -67,67 +67,60 @@ USBBus *usb_bus_find(int busnr)
static int usb_device_init(USBDevice *dev)
{
- USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
- qdev_get_info(DEVICE(dev)));
- if (info->init) {
- return info->init(dev);
+ USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+ if (klass->init) {
+ return klass->init(dev);
}
return 0;
}
static void usb_device_handle_destroy(USBDevice *dev)
{
- USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
- qdev_get_info(DEVICE(dev)));
- if (info->handle_destroy) {
- info->handle_destroy(dev);
+ USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+ if (klass->handle_destroy) {
+ klass->handle_destroy(dev);
}
}
int usb_device_handle_packet(USBDevice *dev, USBPacket *p)
{
- USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
- qdev_get_info(DEVICE(dev)));
- if (info->handle_packet) {
- return info->handle_packet(dev, p);
+ USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+ if (klass->handle_packet) {
+ return klass->handle_packet(dev, p);
}
return -ENOSYS;
}
void usb_device_cancel_packet(USBDevice *dev, USBPacket *p)
{
- USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
- qdev_get_info(DEVICE(dev)));
- if (info->cancel_packet) {
- info->cancel_packet(dev, p);
+ USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+ if (klass->cancel_packet) {
+ klass->cancel_packet(dev, p);
}
}
void usb_device_handle_attach(USBDevice *dev)
{
- USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
- qdev_get_info(DEVICE(dev)));
- if (info->handle_attach) {
- info->handle_attach(dev);
+ USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+ if (klass->handle_attach) {
+ klass->handle_attach(dev);
}
}
void usb_device_handle_reset(USBDevice *dev)
{
- USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
- qdev_get_info(DEVICE(dev)));
- if (info->handle_reset) {
- info->handle_reset(dev);
+ USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+ if (klass->handle_reset) {
+ klass->handle_reset(dev);
}
}
int usb_device_handle_control(USBDevice *dev, USBPacket *p, int request,
int value, int index, int length, uint8_t *data)
{
- USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
- qdev_get_info(DEVICE(dev)));
- if (info->handle_control) {
- return info->handle_control(dev, p, request, value, index, length,
+ USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+ if (klass->handle_control) {
+ return klass->handle_control(dev, p, request, value, index, length,
data);
}
return -ENOSYS;
@@ -135,26 +128,23 @@ int usb_device_handle_control(USBDevice *dev, USBPacket *p, int request,
int usb_device_handle_data(USBDevice *dev, USBPacket *p)
{
- USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
- qdev_get_info(DEVICE(dev)));
- if (info->handle_data) {
- return info->handle_data(dev, p);
+ USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+ if (klass->handle_data) {
+ return klass->handle_data(dev, p);
}
return -ENOSYS;
}
const char *usb_device_get_product_desc(USBDevice *dev)
{
- USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
- qdev_get_info(DEVICE(dev)));
- return info->product_desc;
+ USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+ return klass->product_desc;
}
const USBDesc *usb_device_get_usb_desc(USBDevice *dev)
{
- USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev,
- qdev_get_info(DEVICE(dev)));
- return info->usb_desc;
+ USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+ return klass->usb_desc;
}
static int usb_qdev_init(DeviceState *qdev, DeviceInfo *base)
diff --git a/hw/usb-ccid.c b/hw/usb-ccid.c
index 997ef31..db67837 100644
--- a/hw/usb-ccid.c
+++ b/hw/usb-ccid.c
@@ -1294,24 +1294,31 @@ static VMStateDescription ccid_vmstate = {
}
};
+static void ccid_class_initfn(ObjectClass *klass, void *data)
+{
+ USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+ uc->init = ccid_initfn;
+ uc->product_desc = "QEMU USB CCID";
+ uc->usb_desc = &desc_ccid;
+ uc->handle_packet = usb_generic_handle_packet;
+ uc->handle_reset = ccid_handle_reset;
+ uc->handle_control = ccid_handle_control;
+ uc->handle_data = ccid_handle_data;
+ uc->handle_destroy = ccid_handle_destroy;
+}
+
static struct USBDeviceInfo ccid_info = {
- .product_desc = "QEMU USB CCID",
.qdev.name = CCID_DEV_NAME,
.qdev.desc = "CCID Rev 1.1 smartcard reader",
.qdev.size = sizeof(USBCCIDState),
- .init = ccid_initfn,
- .usb_desc = &desc_ccid,
- .handle_packet = usb_generic_handle_packet,
- .handle_reset = ccid_handle_reset,
- .handle_control = ccid_handle_control,
- .handle_data = ccid_handle_data,
- .handle_destroy = ccid_handle_destroy,
- .usbdevice_name = "ccid",
+ .qdev.class_init= ccid_class_initfn,
+ .qdev.vmsd = &ccid_vmstate,
.qdev.props = (Property[]) {
DEFINE_PROP_UINT8("debug", USBCCIDState, debug, 0),
DEFINE_PROP_END_OF_LIST(),
},
- .qdev.vmsd = &ccid_vmstate,
+ .usbdevice_name = "ccid",
};
static TypeInfo ccid_card_type_info = {
diff --git a/hw/usb-hid.c b/hw/usb-hid.c
index a110c74..dc6bc78 100644
--- a/hw/usb-hid.c
+++ b/hw/usb-hid.c
@@ -560,46 +560,67 @@ static const VMStateDescription vmstate_usb_kbd = {
}
};
+static void usb_tablet_class_initfn(ObjectClass *klass, void *data)
+{
+ USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+ uc->init = usb_tablet_initfn;
+ uc->product_desc = "QEMU USB Tablet";
+ uc->usb_desc = &desc_tablet;
+ uc->handle_packet = usb_generic_handle_packet;
+ uc->handle_reset = usb_hid_handle_reset;
+ uc->handle_control = usb_hid_handle_control;
+ uc->handle_data = usb_hid_handle_data;
+ uc->handle_destroy = usb_hid_handle_destroy;
+}
+
+static void usb_mouse_class_initfn(ObjectClass *klass, void *data)
+{
+ USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+ uc->init = usb_mouse_initfn;
+ uc->product_desc = "QEMU USB Mouse";
+ uc->usb_desc = &desc_mouse;
+ uc->handle_packet = usb_generic_handle_packet;
+ uc->handle_reset = usb_hid_handle_reset;
+ uc->handle_control = usb_hid_handle_control;
+ uc->handle_data = usb_hid_handle_data;
+ uc->handle_destroy = usb_hid_handle_destroy;
+}
+
+static void usb_keyboard_class_initfn(ObjectClass *klass, void *data)
+{
+ USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+ uc->init = usb_keyboard_initfn;
+ uc->product_desc = "QEMU USB Keyboard";
+ uc->usb_desc = &desc_keyboard;
+ uc->handle_packet = usb_generic_handle_packet;
+ uc->handle_reset = usb_hid_handle_reset;
+ uc->handle_control = usb_hid_handle_control;
+ uc->handle_data = usb_hid_handle_data;
+ uc->handle_destroy = usb_hid_handle_destroy;
+}
+
static struct USBDeviceInfo hid_info[] = {
{
- .product_desc = "QEMU USB Tablet",
.qdev.name = "usb-tablet",
- .usbdevice_name = "tablet",
.qdev.size = sizeof(USBHIDState),
.qdev.vmsd = &vmstate_usb_ptr,
- .usb_desc = &desc_tablet,
- .init = usb_tablet_initfn,
- .handle_packet = usb_generic_handle_packet,
- .handle_reset = usb_hid_handle_reset,
- .handle_control = usb_hid_handle_control,
- .handle_data = usb_hid_handle_data,
- .handle_destroy = usb_hid_handle_destroy,
+ .qdev.class_init= usb_tablet_class_initfn,
+ .usbdevice_name = "tablet",
},{
- .product_desc = "QEMU USB Mouse",
.qdev.name = "usb-mouse",
- .usbdevice_name = "mouse",
.qdev.size = sizeof(USBHIDState),
.qdev.vmsd = &vmstate_usb_ptr,
- .usb_desc = &desc_mouse,
- .init = usb_mouse_initfn,
- .handle_packet = usb_generic_handle_packet,
- .handle_reset = usb_hid_handle_reset,
- .handle_control = usb_hid_handle_control,
- .handle_data = usb_hid_handle_data,
- .handle_destroy = usb_hid_handle_destroy,
+ .qdev.class_init= usb_mouse_class_initfn,
+ .usbdevice_name = "mouse",
},{
- .product_desc = "QEMU USB Keyboard",
.qdev.name = "usb-kbd",
- .usbdevice_name = "keyboard",
.qdev.size = sizeof(USBHIDState),
.qdev.vmsd = &vmstate_usb_kbd,
- .usb_desc = &desc_keyboard,
- .init = usb_keyboard_initfn,
- .handle_packet = usb_generic_handle_packet,
- .handle_reset = usb_hid_handle_reset,
- .handle_control = usb_hid_handle_control,
- .handle_data = usb_hid_handle_data,
- .handle_destroy = usb_hid_handle_destroy,
+ .qdev.class_init= usb_keyboard_class_initfn,
+ .usbdevice_name = "keyboard",
},{
/* end of list */
}
diff --git a/hw/usb-hub.c b/hw/usb-hub.c
index e195937..5a52964 100644
--- a/hw/usb-hub.c
+++ b/hw/usb-hub.c
@@ -540,19 +540,26 @@ static const VMStateDescription vmstate_usb_hub = {
}
};
+static void usb_hub_class_initfn(ObjectClass *klass, void *data)
+{
+ USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+ uc->init = usb_hub_initfn;
+ uc->product_desc = "QEMU USB Hub";
+ uc->usb_desc = &desc_hub;
+ uc->handle_packet = usb_hub_handle_packet;
+ uc->handle_reset = usb_hub_handle_reset;
+ uc->handle_control = usb_hub_handle_control;
+ uc->handle_data = usb_hub_handle_data;
+ uc->handle_destroy = usb_hub_handle_destroy;
+}
+
static struct USBDeviceInfo hub_info = {
- .product_desc = "QEMU USB Hub",
.qdev.name = "usb-hub",
- .qdev.fw_name = "hub",
+ .qdev.fw_name = "hub",
.qdev.size = sizeof(USBHubState),
.qdev.vmsd = &vmstate_usb_hub,
- .usb_desc = &desc_hub,
- .init = usb_hub_initfn,
- .handle_packet = usb_hub_handle_packet,
- .handle_reset = usb_hub_handle_reset,
- .handle_control = usb_hub_handle_control,
- .handle_data = usb_hub_handle_data,
- .handle_destroy = usb_hub_handle_destroy,
+ .qdev.class_init= usb_hub_class_initfn,
};
static void usb_hub_register_devices(void)
diff --git a/hw/usb-msd.c b/hw/usb-msd.c
index 4c06950..bb63a6a 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -634,28 +634,35 @@ static const VMStateDescription vmstate_usb_msd = {
}
};
+static void usb_msd_class_initfn(ObjectClass *klass, void *data)
+{
+ USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+ uc->init = usb_msd_initfn;
+ uc->product_desc = "QEMU USB MSD";
+ uc->usb_desc = &desc;
+ uc->handle_packet = usb_generic_handle_packet;
+ uc->cancel_packet = usb_msd_cancel_io;
+ uc->handle_attach = usb_desc_attach;
+ uc->handle_reset = usb_msd_handle_reset;
+ uc->handle_control = usb_msd_handle_control;
+ uc->handle_data = usb_msd_handle_data;
+}
+
static struct USBDeviceInfo msd_info = {
- .product_desc = "QEMU USB MSD",
.qdev.name = "usb-storage",
- .qdev.fw_name = "storage",
+ .qdev.fw_name = "storage",
.qdev.size = sizeof(MSDState),
.qdev.vmsd = &vmstate_usb_msd,
- .usb_desc = &desc,
- .init = usb_msd_initfn,
- .handle_packet = usb_generic_handle_packet,
- .cancel_packet = usb_msd_cancel_io,
- .handle_attach = usb_desc_attach,
- .handle_reset = usb_msd_handle_reset,
- .handle_control = usb_msd_handle_control,
- .handle_data = usb_msd_handle_data,
- .usbdevice_name = "disk",
- .usbdevice_init = usb_msd_init,
+ .qdev.class_init= usb_msd_class_initfn,
.qdev.props = (Property[]) {
DEFINE_BLOCK_PROPERTIES(MSDState, conf),
DEFINE_PROP_STRING("serial", MSDState, serial),
DEFINE_PROP_BIT("removable", MSDState, removable, 0, false),
DEFINE_PROP_END_OF_LIST(),
},
+ .usbdevice_name = "disk",
+ .usbdevice_init = usb_msd_init,
};
static void usb_msd_register_devices(void)
diff --git a/hw/usb-net.c b/hw/usb-net.c
index c4b29a9..50c66d7 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -1398,25 +1398,33 @@ static const VMStateDescription vmstate_usb_net = {
.unmigratable = 1,
};
+static void usb_net_class_initfn(ObjectClass *klass, void *data)
+{
+ USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+ uc->init = usb_net_initfn;
+ uc->product_desc = "QEMU USB Network Interface";
+ uc->usb_desc = &desc_net;
+ uc->handle_packet = usb_generic_handle_packet;
+ uc->handle_reset = usb_net_handle_reset;
+ uc->handle_control = usb_net_handle_control;
+ uc->handle_data = usb_net_handle_data;
+ uc->handle_destroy = usb_net_handle_destroy;
+}
+
static struct USBDeviceInfo net_info = {
- .product_desc = "QEMU USB Network Interface",
.qdev.name = "usb-net",
- .qdev.fw_name = "network",
+ .qdev.fw_name = "network",
.qdev.size = sizeof(USBNetState),
.qdev.vmsd = &vmstate_usb_net,
- .usb_desc = &desc_net,
- .init = usb_net_initfn,
- .handle_packet = usb_generic_handle_packet,
- .handle_reset = usb_net_handle_reset,
- .handle_control = usb_net_handle_control,
- .handle_data = usb_net_handle_data,
- .handle_destroy = usb_net_handle_destroy,
- .usbdevice_name = "net",
- .usbdevice_init = usb_net_init,
+ .qdev.class_init= usb_net_class_initfn,
.qdev.props = (Property[]) {
DEFINE_NIC_PROPERTIES(USBNetState, conf),
DEFINE_PROP_END_OF_LIST(),
- }
+ },
+
+ .usbdevice_name = "net",
+ .usbdevice_init = usb_net_init,
};
static void usb_net_register_devices(void)
diff --git a/hw/usb-serial.c b/hw/usb-serial.c
index 7dbf6df..33d6163 100644
--- a/hw/usb-serial.c
+++ b/hw/usb-serial.c
@@ -577,44 +577,59 @@ static const VMStateDescription vmstate_usb_serial = {
.unmigratable = 1,
};
+static void usb_serial_class_initfn(ObjectClass *klass, void *data)
+{
+ USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+ uc->init = usb_serial_initfn;
+ uc->product_desc = "QEMU USB Serial";
+ uc->usb_desc = &desc_serial;
+ uc->handle_packet = usb_generic_handle_packet;
+ uc->handle_reset = usb_serial_handle_reset;
+ uc->handle_control = usb_serial_handle_control;
+ uc->handle_data = usb_serial_handle_data;
+ uc->handle_destroy = usb_serial_handle_destroy;
+}
+
static struct USBDeviceInfo serial_info = {
- .product_desc = "QEMU USB Serial",
.qdev.name = "usb-serial",
.qdev.size = sizeof(USBSerialState),
.qdev.vmsd = &vmstate_usb_serial,
- .usb_desc = &desc_serial,
- .init = usb_serial_initfn,
- .handle_packet = usb_generic_handle_packet,
- .handle_reset = usb_serial_handle_reset,
- .handle_control = usb_serial_handle_control,
- .handle_data = usb_serial_handle_data,
- .handle_destroy = usb_serial_handle_destroy,
- .usbdevice_name = "serial",
- .usbdevice_init = usb_serial_init,
+ .qdev.class_init= usb_serial_class_initfn,
.qdev.props = (Property[]) {
DEFINE_PROP_CHR("chardev", USBSerialState, cs),
DEFINE_PROP_END_OF_LIST(),
},
+
+ .usbdevice_name = "serial",
+ .usbdevice_init = usb_serial_init,
};
+static void usb_braille_class_initfn(ObjectClass *klass, void *data)
+{
+ USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+ uc->init = usb_serial_initfn;
+ uc->product_desc = "QEMU USB Braille";
+ uc->usb_desc = &desc_braille;
+ uc->handle_packet = usb_generic_handle_packet;
+ uc->handle_reset = usb_serial_handle_reset;
+ uc->handle_control = usb_serial_handle_control;
+ uc->handle_data = usb_serial_handle_data;
+ uc->handle_destroy = usb_serial_handle_destroy;
+}
+
static struct USBDeviceInfo braille_info = {
- .product_desc = "QEMU USB Braille",
.qdev.name = "usb-braille",
.qdev.size = sizeof(USBSerialState),
.qdev.vmsd = &vmstate_usb_serial,
- .usb_desc = &desc_braille,
- .init = usb_serial_initfn,
- .handle_packet = usb_generic_handle_packet,
- .handle_reset = usb_serial_handle_reset,
- .handle_control = usb_serial_handle_control,
- .handle_data = usb_serial_handle_data,
- .handle_destroy = usb_serial_handle_destroy,
- .usbdevice_name = "braille",
- .usbdevice_init = usb_braille_init,
+ .qdev.class_init= usb_braille_class_initfn,
.qdev.props = (Property[]) {
DEFINE_PROP_CHR("chardev", USBSerialState, cs),
DEFINE_PROP_END_OF_LIST(),
},
+ .usbdevice_name = "braille",
+ .usbdevice_init = usb_braille_init,
};
static void usb_serial_register_devices(void)
diff --git a/hw/usb-wacom.c b/hw/usb-wacom.c
index 2558006..448b8f2 100644
--- a/hw/usb-wacom.c
+++ b/hw/usb-wacom.c
@@ -356,20 +356,27 @@ static const VMStateDescription vmstate_usb_wacom = {
.unmigratable = 1,
};
+static void usb_wacom_class_init(ObjectClass *class, void *data)
+{
+ USBDeviceClass *uc = USB_DEVICE_CLASS(class);
+
+ uc->product_desc = "QEMU PenPartner Tablet";
+ uc->usb_desc = &desc_wacom;
+ uc->init = usb_wacom_initfn;
+ uc->handle_packet = usb_generic_handle_packet;
+ uc->handle_reset = usb_wacom_handle_reset;
+ uc->handle_control = usb_wacom_handle_control;
+ uc->handle_data = usb_wacom_handle_data;
+ uc->handle_destroy = usb_wacom_handle_destroy;
+}
+
static struct USBDeviceInfo wacom_info = {
- .product_desc = "QEMU PenPartner Tablet",
.qdev.name = "usb-wacom-tablet",
.qdev.desc = "QEMU PenPartner Tablet",
- .usbdevice_name = "wacom-tablet",
- .usb_desc = &desc_wacom,
.qdev.size = sizeof(USBWacomState),
.qdev.vmsd = &vmstate_usb_wacom,
- .init = usb_wacom_initfn,
- .handle_packet = usb_generic_handle_packet,
- .handle_reset = usb_wacom_handle_reset,
- .handle_control = usb_wacom_handle_control,
- .handle_data = usb_wacom_handle_data,
- .handle_destroy = usb_wacom_handle_destroy,
+ .qdev.class_init= usb_wacom_class_init,
+ .usbdevice_name = "wacom-tablet",
};
static void usb_wacom_register_devices(void)
diff --git a/hw/usb.h b/hw/usb.h
index ee780b0..602ddb9 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -174,39 +174,7 @@ struct USBDescString {
typedef struct USBDeviceClass {
DeviceClass parent_class;
-} USBDeviceClass;
-
-/* definition of a USB device */
-struct USBDevice {
- DeviceState qdev;
- USBPort *port;
- char *port_path;
- void *opaque;
-
- /* Actual connected speed */
- int speed;
- /* Supported speeds, not in info because it may be variable (hostdevs) */
- int speedmask;
- uint8_t addr;
- char product_desc[32];
- int auto_attach;
- int attached;
-
- int32_t state;
- uint8_t setup_buf[8];
- uint8_t data_buf[4096];
- int32_t remote_wakeup;
- int32_t setup_state;
- int32_t setup_len;
- int32_t setup_index;
-
- QLIST_HEAD(, USBDescString) strings;
- const USBDescDevice *device;
- const USBDescConfig *config;
-};
-struct USBDeviceInfo {
- DeviceInfo qdev;
int (*init)(USBDevice *dev);
/*
@@ -257,7 +225,39 @@ struct USBDeviceInfo {
const char *product_desc;
const USBDesc *usb_desc;
+} USBDeviceClass;
+
+/* definition of a USB device */
+struct USBDevice {
+ DeviceState qdev;
+ USBPort *port;
+ char *port_path;
+ void *opaque;
+
+ /* Actual connected speed */
+ int speed;
+ /* Supported speeds, not in info because it may be variable (hostdevs) */
+ int speedmask;
+ uint8_t addr;
+ char product_desc[32];
+ int auto_attach;
+ int attached;
+
+ int32_t state;
+ uint8_t setup_buf[8];
+ uint8_t data_buf[4096];
+ int32_t remote_wakeup;
+ int32_t setup_state;
+ int32_t setup_len;
+ int32_t setup_index;
+
+ QLIST_HEAD(, USBDescString) strings;
+ const USBDescDevice *device;
+ const USBDescConfig *config;
+};
+struct USBDeviceInfo {
+ DeviceInfo qdev;
/* handle legacy -usbdevice command line options */
const char *usbdevice_name;
USBDevice *(*usbdevice_init)(const char *params);
diff --git a/usb-linux.c b/usb-linux.c
index ab4c693..15e3d5e 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -1428,20 +1428,25 @@ static const VMStateDescription vmstate_usb_host = {
.unmigratable = 1,
};
+static void usb_host_class_initfn(ObjectClass *klass, void *data)
+{
+ USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+ uc->init = usb_host_initfn;
+ uc->product_desc = "USB Host Device";
+ uc->handle_packet = usb_generic_handle_packet;
+ uc->cancel_packet = usb_host_async_cancel;
+ uc->handle_data = usb_host_handle_data;
+ uc->handle_control = usb_host_handle_control;
+ uc->handle_reset = usb_host_handle_reset;
+ uc->handle_destroy = usb_host_handle_destroy;
+}
+
static struct USBDeviceInfo usb_host_dev_info = {
- .product_desc = "USB Host Device",
.qdev.name = "usb-host",
.qdev.size = sizeof(USBHostDevice),
.qdev.vmsd = &vmstate_usb_host,
- .init = usb_host_initfn,
- .handle_packet = usb_generic_handle_packet,
- .cancel_packet = usb_host_async_cancel,
- .handle_data = usb_host_handle_data,
- .handle_control = usb_host_handle_control,
- .handle_reset = usb_host_handle_reset,
- .handle_destroy = usb_host_handle_destroy,
- .usbdevice_name = "host",
- .usbdevice_init = usb_host_device_open,
+ .qdev.class_init= usb_host_class_initfn,
.qdev.props = (Property[]) {
DEFINE_PROP_UINT32("hostbus", USBHostDevice, match.bus_num, 0),
DEFINE_PROP_UINT32("hostaddr", USBHostDevice, match.addr, 0),
@@ -1451,6 +1456,8 @@ static struct USBDeviceInfo usb_host_dev_info = {
DEFINE_PROP_UINT32("isobufs", USBHostDevice, iso_urb_count, 4),
DEFINE_PROP_END_OF_LIST(),
},
+ .usbdevice_name = "host",
+ .usbdevice_init = usb_host_device_open,
};
static void usb_host_register_devices(void)
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 047/197] usb: use a factory instead of doing silly things for legacy
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (43 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 046/197] usb: promote all of the methods for USBDevice to class methods Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 048/197] usb: kill USBDeviceInfo Anthony Liguori
` (21 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/usb-bt.c | 2 +-
hw/usb-bus.c | 51 +++++++++++++++++++++++++++++----------------------
hw/usb-ccid.c | 3 +--
hw/usb-hid.c | 45 ++++++++++++++++++++++-----------------------
hw/usb-hub.c | 2 +-
hw/usb-msd.c | 4 +---
hw/usb-net.c | 5 +----
hw/usb-serial.c | 9 ++-------
hw/usb-wacom.c | 3 +--
hw/usb.h | 8 +++-----
usb-bsd.c | 23 +++++++++++++++--------
usb-linux.c | 4 +---
usb-redir.c | 25 ++++++++++++++++---------
13 files changed, 94 insertions(+), 90 deletions(-)
diff --git a/hw/usb-bt.c b/hw/usb-bt.c
index fd71f1f..8dea574 100644
--- a/hw/usb-bt.c
+++ b/hw/usb-bt.c
@@ -572,6 +572,6 @@ static struct USBDeviceInfo bt_info = {
static void usb_bt_register_devices(void)
{
- usb_qdev_register(&bt_info);
+ usb_qdev_register(&bt_info, NULL, NULL);
}
device_init(usb_bt_register_devices)
diff --git a/hw/usb-bus.c b/hw/usb-bus.c
index 46426db..b86d6c8 100644
--- a/hw/usb-bus.c
+++ b/hw/usb-bus.c
@@ -191,20 +191,31 @@ static int usb_qdev_exit(DeviceState *qdev)
return 0;
}
-void usb_qdev_register(USBDeviceInfo *info)
+typedef struct LegacyUSBFactory
+{
+ const char *name;
+ const char *usbdevice_name;
+ USBDevice *(*usbdevice_init)(const char *params);
+} LegacyUSBFactory;
+
+static GSList *legacy_usb_factory;
+
+void usb_qdev_register(USBDeviceInfo *info,
+ const char *usbdevice_name,
+ USBDevice *(*usbdevice_init)(const char *params))
{
info->qdev.bus_info = &usb_bus_info;
info->qdev.init = usb_qdev_init;
info->qdev.unplug = qdev_simple_unplug_cb;
info->qdev.exit = usb_qdev_exit;
qdev_register_subclass(&info->qdev, TYPE_USB_DEVICE);
-}
-void usb_qdev_register_many(USBDeviceInfo *info)
-{
- while (info->qdev.name) {
- usb_qdev_register(info);
- info++;
+ if (usbdevice_name) {
+ LegacyUSBFactory *f = g_malloc0(sizeof(*f));
+ f->name = info->qdev.name;
+ f->usbdevice_name = usbdevice_name;
+ f->usbdevice_init = usbdevice_init;
+ legacy_usb_factory = g_slist_append(legacy_usb_factory, f);
}
}
@@ -514,8 +525,8 @@ void usb_info(Monitor *mon)
USBDevice *usbdevice_create(const char *cmdline)
{
USBBus *bus = usb_bus_find(-1 /* any */);
- DeviceInfo *info;
- USBDeviceInfo *usb;
+ LegacyUSBFactory *f = NULL;
+ GSList *i;
char driver[32];
const char *params;
int len;
@@ -532,17 +543,13 @@ USBDevice *usbdevice_create(const char *cmdline)
pstrcpy(driver, sizeof(driver), cmdline);
}
- for (info = device_info_list; info != NULL; info = info->next) {
- if (info->bus_info != &usb_bus_info)
- continue;
- usb = DO_UPCAST(USBDeviceInfo, qdev, info);
- if (usb->usbdevice_name == NULL)
- continue;
- if (strcmp(usb->usbdevice_name, driver) != 0)
- continue;
- break;
+ for (i = legacy_usb_factory; i; i = i->next) {
+ f = i->data;
+ if (strcmp(f->usbdevice_name, driver) == 0) {
+ break;
+ }
}
- if (info == NULL) {
+ if (i == NULL) {
#if 0
/* no error because some drivers are not converted (yet) */
error_report("usbdevice %s not found", driver);
@@ -550,14 +557,14 @@ USBDevice *usbdevice_create(const char *cmdline)
return NULL;
}
- if (!usb->usbdevice_init) {
+ if (!f->usbdevice_init) {
if (*params) {
error_report("usbdevice %s accepts no params", driver);
return NULL;
}
- return usb_create_simple(bus, usb->qdev.name);
+ return usb_create_simple(bus, f->name);
}
- return usb->usbdevice_init(params);
+ return f->usbdevice_init(params);
}
static TypeInfo usb_device_type_info = {
diff --git a/hw/usb-ccid.c b/hw/usb-ccid.c
index db67837..24b1a1f 100644
--- a/hw/usb-ccid.c
+++ b/hw/usb-ccid.c
@@ -1318,7 +1318,6 @@ static struct USBDeviceInfo ccid_info = {
DEFINE_PROP_UINT8("debug", USBCCIDState, debug, 0),
DEFINE_PROP_END_OF_LIST(),
},
- .usbdevice_name = "ccid",
};
static TypeInfo ccid_card_type_info = {
@@ -1332,6 +1331,6 @@ static TypeInfo ccid_card_type_info = {
static void ccid_register_devices(void)
{
type_register_static(&ccid_card_type_info);
- usb_qdev_register(&ccid_info);
+ usb_qdev_register(&ccid_info, "ccid", NULL);
}
device_init(ccid_register_devices)
diff --git a/hw/usb-hid.c b/hw/usb-hid.c
index dc6bc78..75642cf 100644
--- a/hw/usb-hid.c
+++ b/hw/usb-hid.c
@@ -574,6 +574,13 @@ static void usb_tablet_class_initfn(ObjectClass *klass, void *data)
uc->handle_destroy = usb_hid_handle_destroy;
}
+static struct USBDeviceInfo usb_tablet_info = {
+ .qdev.name = "usb-tablet",
+ .qdev.size = sizeof(USBHIDState),
+ .qdev.vmsd = &vmstate_usb_ptr,
+ .qdev.class_init= usb_tablet_class_initfn,
+};
+
static void usb_mouse_class_initfn(ObjectClass *klass, void *data)
{
USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
@@ -588,6 +595,13 @@ static void usb_mouse_class_initfn(ObjectClass *klass, void *data)
uc->handle_destroy = usb_hid_handle_destroy;
}
+static struct USBDeviceInfo usb_mouse_info = {
+ .qdev.name = "usb-mouse",
+ .qdev.size = sizeof(USBHIDState),
+ .qdev.vmsd = &vmstate_usb_ptr,
+ .qdev.class_init= usb_mouse_class_initfn,
+};
+
static void usb_keyboard_class_initfn(ObjectClass *klass, void *data)
{
USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
@@ -602,32 +616,17 @@ static void usb_keyboard_class_initfn(ObjectClass *klass, void *data)
uc->handle_destroy = usb_hid_handle_destroy;
}
-static struct USBDeviceInfo hid_info[] = {
- {
- .qdev.name = "usb-tablet",
- .qdev.size = sizeof(USBHIDState),
- .qdev.vmsd = &vmstate_usb_ptr,
- .qdev.class_init= usb_tablet_class_initfn,
- .usbdevice_name = "tablet",
- },{
- .qdev.name = "usb-mouse",
- .qdev.size = sizeof(USBHIDState),
- .qdev.vmsd = &vmstate_usb_ptr,
- .qdev.class_init= usb_mouse_class_initfn,
- .usbdevice_name = "mouse",
- },{
- .qdev.name = "usb-kbd",
- .qdev.size = sizeof(USBHIDState),
- .qdev.vmsd = &vmstate_usb_kbd,
- .qdev.class_init= usb_keyboard_class_initfn,
- .usbdevice_name = "keyboard",
- },{
- /* end of list */
- }
+static struct USBDeviceInfo usb_keyboard_info = {
+ .qdev.name = "usb-kbd",
+ .qdev.size = sizeof(USBHIDState),
+ .qdev.vmsd = &vmstate_usb_kbd,
+ .qdev.class_init= usb_keyboard_class_initfn,
};
static void usb_hid_register_devices(void)
{
- usb_qdev_register_many(hid_info);
+ usb_qdev_register(&usb_tablet_info, "tablet", NULL);
+ usb_qdev_register(&usb_mouse_info, "mouse", NULL);
+ usb_qdev_register(&usb_keyboard_info, "keyboard", NULL);
}
device_init(usb_hid_register_devices)
diff --git a/hw/usb-hub.c b/hw/usb-hub.c
index 5a52964..b5114dd 100644
--- a/hw/usb-hub.c
+++ b/hw/usb-hub.c
@@ -564,6 +564,6 @@ static struct USBDeviceInfo hub_info = {
static void usb_hub_register_devices(void)
{
- usb_qdev_register(&hub_info);
+ usb_qdev_register(&hub_info, NULL, NULL);
}
device_init(usb_hub_register_devices)
diff --git a/hw/usb-msd.c b/hw/usb-msd.c
index bb63a6a..a6226b4 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -661,12 +661,10 @@ static struct USBDeviceInfo msd_info = {
DEFINE_PROP_BIT("removable", MSDState, removable, 0, false),
DEFINE_PROP_END_OF_LIST(),
},
- .usbdevice_name = "disk",
- .usbdevice_init = usb_msd_init,
};
static void usb_msd_register_devices(void)
{
- usb_qdev_register(&msd_info);
+ usb_qdev_register(&msd_info, "disk", usb_msd_init);
}
device_init(usb_msd_register_devices)
diff --git a/hw/usb-net.c b/hw/usb-net.c
index 50c66d7..1f14b27 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -1422,13 +1422,10 @@ static struct USBDeviceInfo net_info = {
DEFINE_NIC_PROPERTIES(USBNetState, conf),
DEFINE_PROP_END_OF_LIST(),
},
-
- .usbdevice_name = "net",
- .usbdevice_init = usb_net_init,
};
static void usb_net_register_devices(void)
{
- usb_qdev_register(&net_info);
+ usb_qdev_register(&net_info, "net", usb_net_init);
}
device_init(usb_net_register_devices)
diff --git a/hw/usb-serial.c b/hw/usb-serial.c
index 33d6163..407ca72 100644
--- a/hw/usb-serial.c
+++ b/hw/usb-serial.c
@@ -600,9 +600,6 @@ static struct USBDeviceInfo serial_info = {
DEFINE_PROP_CHR("chardev", USBSerialState, cs),
DEFINE_PROP_END_OF_LIST(),
},
-
- .usbdevice_name = "serial",
- .usbdevice_init = usb_serial_init,
};
static void usb_braille_class_initfn(ObjectClass *klass, void *data)
@@ -628,13 +625,11 @@ static struct USBDeviceInfo braille_info = {
DEFINE_PROP_CHR("chardev", USBSerialState, cs),
DEFINE_PROP_END_OF_LIST(),
},
- .usbdevice_name = "braille",
- .usbdevice_init = usb_braille_init,
};
static void usb_serial_register_devices(void)
{
- usb_qdev_register(&serial_info);
- usb_qdev_register(&braille_info);
+ usb_qdev_register(&serial_info, "serial", usb_serial_init);
+ usb_qdev_register(&braille_info, "braille", usb_braille_init);
}
device_init(usb_serial_register_devices)
diff --git a/hw/usb-wacom.c b/hw/usb-wacom.c
index 448b8f2..4a671ef 100644
--- a/hw/usb-wacom.c
+++ b/hw/usb-wacom.c
@@ -376,11 +376,10 @@ static struct USBDeviceInfo wacom_info = {
.qdev.size = sizeof(USBWacomState),
.qdev.vmsd = &vmstate_usb_wacom,
.qdev.class_init= usb_wacom_class_init,
- .usbdevice_name = "wacom-tablet",
};
static void usb_wacom_register_devices(void)
{
- usb_qdev_register(&wacom_info);
+ usb_qdev_register(&wacom_info, "wacom-tablet", NULL);
}
device_init(usb_wacom_register_devices)
diff --git a/hw/usb.h b/hw/usb.h
index 602ddb9..eac0bf5 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -258,9 +258,6 @@ struct USBDevice {
struct USBDeviceInfo {
DeviceInfo qdev;
- /* handle legacy -usbdevice command line options */
- const char *usbdevice_name;
- USBDevice *(*usbdevice_init)(const char *params);
};
typedef struct USBPortOps {
@@ -384,8 +381,9 @@ struct USBBusOps {
void usb_bus_new(USBBus *bus, USBBusOps *ops, DeviceState *host);
USBBus *usb_bus_find(int busnr);
-void usb_qdev_register(USBDeviceInfo *info);
-void usb_qdev_register_many(USBDeviceInfo *info);
+void usb_qdev_register(USBDeviceInfo *info,
+ const char *usbdevice_name,
+ USBDevice *(*usbdevice_init)(const char *params));
USBDevice *usb_create(USBBus *bus, const char *name);
USBDevice *usb_create_simple(USBBus *bus, const char *name);
USBDevice *usbdevice_create(const char *cmdline);
diff --git a/usb-bsd.c b/usb-bsd.c
index 1187552..8637c77 100644
--- a/usb-bsd.c
+++ b/usb-bsd.c
@@ -397,21 +397,28 @@ fail:
return ret;
}
+static void usb_host_class_initfn(ObjectClass *klass, void *data)
+{
+ USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+ uc->product_desc = "USB Host Device";
+ uc->init = usb_host_initfn;
+ uc->handle_packet = usb_generic_handle_packet;
+ uc->handle_reset = usb_host_handle_reset;
+ uc->handle_control = usb_host_handle_control;
+ uc->handle_data = usb_host_handle_data;
+ uc->handle_destroy = usb_host_handle_destroy;
+}
+
static struct USBDeviceInfo usb_host_dev_info = {
- .product_desc = "USB Host Device",
.qdev.name = "usb-host",
.qdev.size = sizeof(USBHostDevice),
- .init = usb_host_initfn,
- .handle_packet = usb_generic_handle_packet,
- .handle_reset = usb_host_handle_reset,
- .handle_control = usb_host_handle_control,
- .handle_data = usb_host_handle_data,
- .handle_destroy = usb_host_handle_destroy,
+ .qdev.class_init= usb_host_initfn,
};
static void usb_host_register_devices(void)
{
- usb_qdev_register(&usb_host_dev_info);
+ usb_qdev_register(&usb_host_dev_info, NULL, NULL);
}
device_init(usb_host_register_devices)
diff --git a/usb-linux.c b/usb-linux.c
index 15e3d5e..6dbcf2a 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -1456,13 +1456,11 @@ static struct USBDeviceInfo usb_host_dev_info = {
DEFINE_PROP_UINT32("isobufs", USBHostDevice, iso_urb_count, 4),
DEFINE_PROP_END_OF_LIST(),
},
- .usbdevice_name = "host",
- .usbdevice_init = usb_host_device_open,
};
static void usb_host_register_devices(void)
{
- usb_qdev_register(&usb_host_dev_info);
+ usb_qdev_register(&usb_host_dev_info, "host", usb_host_device_open);
}
device_init(usb_host_register_devices)
diff --git a/usb-redir.c b/usb-redir.c
index fb91c92..a297501 100644
--- a/usb-redir.c
+++ b/usb-redir.c
@@ -1227,17 +1227,24 @@ static void usbredir_interrupt_packet(void *priv, uint32_t id,
}
}
+static void usbredir_class_initfn(ObjectClass *klass, void *data)
+{
+ USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+ uc->init = usbredir_initfn;
+ uc->product_desc = "USB Redirection Device";
+ uc->handle_destroy = usbredir_handle_destroy;
+ uc->handle_packet = usb_generic_handle_packet;
+ uc->cancel_packet = usbredir_cancel_packet;
+ uc->handle_reset = usbredir_handle_reset;
+ uc->handle_data = usbredir_handle_data;
+ uc->handle_control = usbredir_handle_control;
+}
+
static struct USBDeviceInfo usbredir_dev_info = {
- .product_desc = "USB Redirection Device",
.qdev.name = "usb-redir",
.qdev.size = sizeof(USBRedirDevice),
- .init = usbredir_initfn,
- .handle_destroy = usbredir_handle_destroy,
- .handle_packet = usb_generic_handle_packet,
- .cancel_packet = usbredir_cancel_packet,
- .handle_reset = usbredir_handle_reset,
- .handle_data = usbredir_handle_data,
- .handle_control = usbredir_handle_control,
+ .qdev.class_init= usbredir_class_initfn,
.qdev.props = (Property[]) {
DEFINE_PROP_CHR("chardev", USBRedirDevice, cs),
DEFINE_PROP_UINT8("debug", USBRedirDevice, debug, 0),
@@ -1247,6 +1254,6 @@ static struct USBDeviceInfo usbredir_dev_info = {
static void usbredir_register_devices(void)
{
- usb_qdev_register(&usbredir_dev_info);
+ usb_qdev_register(&usbredir_dev_info, NULL, NULL);
}
device_init(usbredir_register_devices);
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 048/197] usb: kill USBDeviceInfo
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (44 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 047/197] usb: use a factory instead of doing silly things for legacy Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 049/197] usb-hid: simply class initialization a bit Anthony Liguori
` (20 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/usb-bt.c | 10 +++++-----
hw/usb-bus.c | 14 +++++++-------
hw/usb-ccid.c | 14 +++++++-------
hw/usb-hid.c | 30 +++++++++++++++---------------
hw/usb-hub.c | 12 ++++++------
hw/usb-msd.c | 14 +++++++-------
hw/usb-net.c | 14 +++++++-------
hw/usb-serial.c | 24 ++++++++++++------------
hw/usb-wacom.c | 12 ++++++------
hw/usb.h | 7 +------
usb-bsd.c | 8 ++++----
usb-linux.c | 12 ++++++------
usb-redir.c | 10 +++++-----
13 files changed, 88 insertions(+), 93 deletions(-)
diff --git a/hw/usb-bt.c b/hw/usb-bt.c
index 8dea574..6e210ac 100644
--- a/hw/usb-bt.c
+++ b/hw/usb-bt.c
@@ -563,11 +563,11 @@ static void usb_bt_class_initfn(ObjectClass *klass, void *data)
uc->handle_destroy = usb_bt_handle_destroy;
}
-static struct USBDeviceInfo bt_info = {
- .qdev.name = "usb-bt-dongle",
- .qdev.size = sizeof(struct USBBtState),
- .qdev.vmsd = &vmstate_usb_bt,
- .qdev.class_init= usb_bt_class_initfn,
+static struct DeviceInfo bt_info = {
+ .name = "usb-bt-dongle",
+ .size = sizeof(struct USBBtState),
+ .vmsd = &vmstate_usb_bt,
+ .class_init= usb_bt_class_initfn,
};
static void usb_bt_register_devices(void)
diff --git a/hw/usb-bus.c b/hw/usb-bus.c
index b86d6c8..0e635c2 100644
--- a/hw/usb-bus.c
+++ b/hw/usb-bus.c
@@ -200,19 +200,19 @@ typedef struct LegacyUSBFactory
static GSList *legacy_usb_factory;
-void usb_qdev_register(USBDeviceInfo *info,
+void usb_qdev_register(DeviceInfo *info,
const char *usbdevice_name,
USBDevice *(*usbdevice_init)(const char *params))
{
- info->qdev.bus_info = &usb_bus_info;
- info->qdev.init = usb_qdev_init;
- info->qdev.unplug = qdev_simple_unplug_cb;
- info->qdev.exit = usb_qdev_exit;
- qdev_register_subclass(&info->qdev, TYPE_USB_DEVICE);
+ info->bus_info = &usb_bus_info;
+ info->init = usb_qdev_init;
+ info->unplug = qdev_simple_unplug_cb;
+ info->exit = usb_qdev_exit;
+ qdev_register_subclass(info, TYPE_USB_DEVICE);
if (usbdevice_name) {
LegacyUSBFactory *f = g_malloc0(sizeof(*f));
- f->name = info->qdev.name;
+ f->name = info->name;
f->usbdevice_name = usbdevice_name;
f->usbdevice_init = usbdevice_init;
legacy_usb_factory = g_slist_append(legacy_usb_factory, f);
diff --git a/hw/usb-ccid.c b/hw/usb-ccid.c
index 24b1a1f..41a53aa 100644
--- a/hw/usb-ccid.c
+++ b/hw/usb-ccid.c
@@ -1308,13 +1308,13 @@ static void ccid_class_initfn(ObjectClass *klass, void *data)
uc->handle_destroy = ccid_handle_destroy;
}
-static struct USBDeviceInfo ccid_info = {
- .qdev.name = CCID_DEV_NAME,
- .qdev.desc = "CCID Rev 1.1 smartcard reader",
- .qdev.size = sizeof(USBCCIDState),
- .qdev.class_init= ccid_class_initfn,
- .qdev.vmsd = &ccid_vmstate,
- .qdev.props = (Property[]) {
+static struct DeviceInfo ccid_info = {
+ .name = CCID_DEV_NAME,
+ .desc = "CCID Rev 1.1 smartcard reader",
+ .size = sizeof(USBCCIDState),
+ .class_init= ccid_class_initfn,
+ .vmsd = &ccid_vmstate,
+ .props = (Property[]) {
DEFINE_PROP_UINT8("debug", USBCCIDState, debug, 0),
DEFINE_PROP_END_OF_LIST(),
},
diff --git a/hw/usb-hid.c b/hw/usb-hid.c
index 75642cf..2538b9c 100644
--- a/hw/usb-hid.c
+++ b/hw/usb-hid.c
@@ -574,11 +574,11 @@ static void usb_tablet_class_initfn(ObjectClass *klass, void *data)
uc->handle_destroy = usb_hid_handle_destroy;
}
-static struct USBDeviceInfo usb_tablet_info = {
- .qdev.name = "usb-tablet",
- .qdev.size = sizeof(USBHIDState),
- .qdev.vmsd = &vmstate_usb_ptr,
- .qdev.class_init= usb_tablet_class_initfn,
+static struct DeviceInfo usb_tablet_info = {
+ .name = "usb-tablet",
+ .size = sizeof(USBHIDState),
+ .vmsd = &vmstate_usb_ptr,
+ .class_init= usb_tablet_class_initfn,
};
static void usb_mouse_class_initfn(ObjectClass *klass, void *data)
@@ -595,11 +595,11 @@ static void usb_mouse_class_initfn(ObjectClass *klass, void *data)
uc->handle_destroy = usb_hid_handle_destroy;
}
-static struct USBDeviceInfo usb_mouse_info = {
- .qdev.name = "usb-mouse",
- .qdev.size = sizeof(USBHIDState),
- .qdev.vmsd = &vmstate_usb_ptr,
- .qdev.class_init= usb_mouse_class_initfn,
+static struct DeviceInfo usb_mouse_info = {
+ .name = "usb-mouse",
+ .size = sizeof(USBHIDState),
+ .vmsd = &vmstate_usb_ptr,
+ .class_init= usb_mouse_class_initfn,
};
static void usb_keyboard_class_initfn(ObjectClass *klass, void *data)
@@ -616,11 +616,11 @@ static void usb_keyboard_class_initfn(ObjectClass *klass, void *data)
uc->handle_destroy = usb_hid_handle_destroy;
}
-static struct USBDeviceInfo usb_keyboard_info = {
- .qdev.name = "usb-kbd",
- .qdev.size = sizeof(USBHIDState),
- .qdev.vmsd = &vmstate_usb_kbd,
- .qdev.class_init= usb_keyboard_class_initfn,
+static struct DeviceInfo usb_keyboard_info = {
+ .name = "usb-kbd",
+ .size = sizeof(USBHIDState),
+ .vmsd = &vmstate_usb_kbd,
+ .class_init= usb_keyboard_class_initfn,
};
static void usb_hid_register_devices(void)
diff --git a/hw/usb-hub.c b/hw/usb-hub.c
index b5114dd..f997152 100644
--- a/hw/usb-hub.c
+++ b/hw/usb-hub.c
@@ -554,12 +554,12 @@ static void usb_hub_class_initfn(ObjectClass *klass, void *data)
uc->handle_destroy = usb_hub_handle_destroy;
}
-static struct USBDeviceInfo hub_info = {
- .qdev.name = "usb-hub",
- .qdev.fw_name = "hub",
- .qdev.size = sizeof(USBHubState),
- .qdev.vmsd = &vmstate_usb_hub,
- .qdev.class_init= usb_hub_class_initfn,
+static struct DeviceInfo hub_info = {
+ .name = "usb-hub",
+ .fw_name = "hub",
+ .size = sizeof(USBHubState),
+ .vmsd = &vmstate_usb_hub,
+ .class_init= usb_hub_class_initfn,
};
static void usb_hub_register_devices(void)
diff --git a/hw/usb-msd.c b/hw/usb-msd.c
index a6226b4..e4a1e4e 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -649,13 +649,13 @@ static void usb_msd_class_initfn(ObjectClass *klass, void *data)
uc->handle_data = usb_msd_handle_data;
}
-static struct USBDeviceInfo msd_info = {
- .qdev.name = "usb-storage",
- .qdev.fw_name = "storage",
- .qdev.size = sizeof(MSDState),
- .qdev.vmsd = &vmstate_usb_msd,
- .qdev.class_init= usb_msd_class_initfn,
- .qdev.props = (Property[]) {
+static struct DeviceInfo msd_info = {
+ .name = "usb-storage",
+ .fw_name = "storage",
+ .size = sizeof(MSDState),
+ .vmsd = &vmstate_usb_msd,
+ .class_init= usb_msd_class_initfn,
+ .props = (Property[]) {
DEFINE_BLOCK_PROPERTIES(MSDState, conf),
DEFINE_PROP_STRING("serial", MSDState, serial),
DEFINE_PROP_BIT("removable", MSDState, removable, 0, false),
diff --git a/hw/usb-net.c b/hw/usb-net.c
index 1f14b27..61a8e86 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -1412,13 +1412,13 @@ static void usb_net_class_initfn(ObjectClass *klass, void *data)
uc->handle_destroy = usb_net_handle_destroy;
}
-static struct USBDeviceInfo net_info = {
- .qdev.name = "usb-net",
- .qdev.fw_name = "network",
- .qdev.size = sizeof(USBNetState),
- .qdev.vmsd = &vmstate_usb_net,
- .qdev.class_init= usb_net_class_initfn,
- .qdev.props = (Property[]) {
+static struct DeviceInfo net_info = {
+ .name = "usb-net",
+ .fw_name = "network",
+ .size = sizeof(USBNetState),
+ .vmsd = &vmstate_usb_net,
+ .class_init= usb_net_class_initfn,
+ .props = (Property[]) {
DEFINE_NIC_PROPERTIES(USBNetState, conf),
DEFINE_PROP_END_OF_LIST(),
},
diff --git a/hw/usb-serial.c b/hw/usb-serial.c
index 407ca72..73bb80b 100644
--- a/hw/usb-serial.c
+++ b/hw/usb-serial.c
@@ -591,12 +591,12 @@ static void usb_serial_class_initfn(ObjectClass *klass, void *data)
uc->handle_destroy = usb_serial_handle_destroy;
}
-static struct USBDeviceInfo serial_info = {
- .qdev.name = "usb-serial",
- .qdev.size = sizeof(USBSerialState),
- .qdev.vmsd = &vmstate_usb_serial,
- .qdev.class_init= usb_serial_class_initfn,
- .qdev.props = (Property[]) {
+static struct DeviceInfo serial_info = {
+ .name = "usb-serial",
+ .size = sizeof(USBSerialState),
+ .vmsd = &vmstate_usb_serial,
+ .class_init= usb_serial_class_initfn,
+ .props = (Property[]) {
DEFINE_PROP_CHR("chardev", USBSerialState, cs),
DEFINE_PROP_END_OF_LIST(),
},
@@ -616,12 +616,12 @@ static void usb_braille_class_initfn(ObjectClass *klass, void *data)
uc->handle_destroy = usb_serial_handle_destroy;
}
-static struct USBDeviceInfo braille_info = {
- .qdev.name = "usb-braille",
- .qdev.size = sizeof(USBSerialState),
- .qdev.vmsd = &vmstate_usb_serial,
- .qdev.class_init= usb_braille_class_initfn,
- .qdev.props = (Property[]) {
+static struct DeviceInfo braille_info = {
+ .name = "usb-braille",
+ .size = sizeof(USBSerialState),
+ .vmsd = &vmstate_usb_serial,
+ .class_init= usb_braille_class_initfn,
+ .props = (Property[]) {
DEFINE_PROP_CHR("chardev", USBSerialState, cs),
DEFINE_PROP_END_OF_LIST(),
},
diff --git a/hw/usb-wacom.c b/hw/usb-wacom.c
index 4a671ef..12c949f 100644
--- a/hw/usb-wacom.c
+++ b/hw/usb-wacom.c
@@ -370,12 +370,12 @@ static void usb_wacom_class_init(ObjectClass *class, void *data)
uc->handle_destroy = usb_wacom_handle_destroy;
}
-static struct USBDeviceInfo wacom_info = {
- .qdev.name = "usb-wacom-tablet",
- .qdev.desc = "QEMU PenPartner Tablet",
- .qdev.size = sizeof(USBWacomState),
- .qdev.vmsd = &vmstate_usb_wacom,
- .qdev.class_init= usb_wacom_class_init,
+static struct DeviceInfo wacom_info = {
+ .name = "usb-wacom-tablet",
+ .desc = "QEMU PenPartner Tablet",
+ .size = sizeof(USBWacomState),
+ .vmsd = &vmstate_usb_wacom,
+ .class_init= usb_wacom_class_init,
};
static void usb_wacom_register_devices(void)
diff --git a/hw/usb.h b/hw/usb.h
index eac0bf5..2bbfb0a 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -145,7 +145,6 @@ typedef struct USBBus USBBus;
typedef struct USBBusOps USBBusOps;
typedef struct USBPort USBPort;
typedef struct USBDevice USBDevice;
-typedef struct USBDeviceInfo USBDeviceInfo;
typedef struct USBPacket USBPacket;
typedef struct USBDesc USBDesc;
@@ -256,10 +255,6 @@ struct USBDevice {
const USBDescConfig *config;
};
-struct USBDeviceInfo {
- DeviceInfo qdev;
-};
-
typedef struct USBPortOps {
void (*attach)(USBPort *port);
void (*detach)(USBPort *port);
@@ -381,7 +376,7 @@ struct USBBusOps {
void usb_bus_new(USBBus *bus, USBBusOps *ops, DeviceState *host);
USBBus *usb_bus_find(int busnr);
-void usb_qdev_register(USBDeviceInfo *info,
+void usb_qdev_register(DeviceInfo *info,
const char *usbdevice_name,
USBDevice *(*usbdevice_init)(const char *params));
USBDevice *usb_create(USBBus *bus, const char *name);
diff --git a/usb-bsd.c b/usb-bsd.c
index 8637c77..2c6afc8 100644
--- a/usb-bsd.c
+++ b/usb-bsd.c
@@ -410,10 +410,10 @@ static void usb_host_class_initfn(ObjectClass *klass, void *data)
uc->handle_destroy = usb_host_handle_destroy;
}
-static struct USBDeviceInfo usb_host_dev_info = {
- .qdev.name = "usb-host",
- .qdev.size = sizeof(USBHostDevice),
- .qdev.class_init= usb_host_initfn,
+static struct DeviceInfo usb_host_dev_info = {
+ .name = "usb-host",
+ .size = sizeof(USBHostDevice),
+ .class_init= usb_host_initfn,
};
static void usb_host_register_devices(void)
diff --git a/usb-linux.c b/usb-linux.c
index 6dbcf2a..82d7e7e 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -1442,12 +1442,12 @@ static void usb_host_class_initfn(ObjectClass *klass, void *data)
uc->handle_destroy = usb_host_handle_destroy;
}
-static struct USBDeviceInfo usb_host_dev_info = {
- .qdev.name = "usb-host",
- .qdev.size = sizeof(USBHostDevice),
- .qdev.vmsd = &vmstate_usb_host,
- .qdev.class_init= usb_host_class_initfn,
- .qdev.props = (Property[]) {
+static struct DeviceInfo usb_host_dev_info = {
+ .name = "usb-host",
+ .size = sizeof(USBHostDevice),
+ .vmsd = &vmstate_usb_host,
+ .class_init= usb_host_class_initfn,
+ .props = (Property[]) {
DEFINE_PROP_UINT32("hostbus", USBHostDevice, match.bus_num, 0),
DEFINE_PROP_UINT32("hostaddr", USBHostDevice, match.addr, 0),
DEFINE_PROP_STRING("hostport", USBHostDevice, match.port),
diff --git a/usb-redir.c b/usb-redir.c
index a297501..09dc7e6 100644
--- a/usb-redir.c
+++ b/usb-redir.c
@@ -1241,11 +1241,11 @@ static void usbredir_class_initfn(ObjectClass *klass, void *data)
uc->handle_control = usbredir_handle_control;
}
-static struct USBDeviceInfo usbredir_dev_info = {
- .qdev.name = "usb-redir",
- .qdev.size = sizeof(USBRedirDevice),
- .qdev.class_init= usbredir_class_initfn,
- .qdev.props = (Property[]) {
+static struct DeviceInfo usbredir_dev_info = {
+ .name = "usb-redir",
+ .size = sizeof(USBRedirDevice),
+ .class_init= usbredir_class_initfn,
+ .props = (Property[]) {
DEFINE_PROP_CHR("chardev", USBRedirDevice, cs),
DEFINE_PROP_UINT8("debug", USBRedirDevice, debug, 0),
DEFINE_PROP_END_OF_LIST(),
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 049/197] usb-hid: simply class initialization a bit
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (45 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 048/197] usb: kill USBDeviceInfo Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 050/197] accessors for scsideviceinfo Anthony Liguori
` (19 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/usb-hid.c | 27 +++++++++++++--------------
1 files changed, 13 insertions(+), 14 deletions(-)
diff --git a/hw/usb-hid.c b/hw/usb-hid.c
index 2538b9c..3a587c4 100644
--- a/hw/usb-hid.c
+++ b/hw/usb-hid.c
@@ -560,13 +560,10 @@ static const VMStateDescription vmstate_usb_kbd = {
}
};
-static void usb_tablet_class_initfn(ObjectClass *klass, void *data)
+static void usb_hid_class_initfn(ObjectClass *klass, void *data)
{
USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
- uc->init = usb_tablet_initfn;
- uc->product_desc = "QEMU USB Tablet";
- uc->usb_desc = &desc_tablet;
uc->handle_packet = usb_generic_handle_packet;
uc->handle_reset = usb_hid_handle_reset;
uc->handle_control = usb_hid_handle_control;
@@ -574,6 +571,16 @@ static void usb_tablet_class_initfn(ObjectClass *klass, void *data)
uc->handle_destroy = usb_hid_handle_destroy;
}
+static void usb_tablet_class_initfn(ObjectClass *klass, void *data)
+{
+ USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+
+ usb_hid_class_initfn(klass, data);
+ uc->init = usb_tablet_initfn;
+ uc->product_desc = "QEMU USB Tablet";
+ uc->usb_desc = &desc_tablet;
+}
+
static struct DeviceInfo usb_tablet_info = {
.name = "usb-tablet",
.size = sizeof(USBHIDState),
@@ -585,14 +592,10 @@ static void usb_mouse_class_initfn(ObjectClass *klass, void *data)
{
USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+ usb_hid_class_initfn(klass, data);
uc->init = usb_mouse_initfn;
uc->product_desc = "QEMU USB Mouse";
uc->usb_desc = &desc_mouse;
- uc->handle_packet = usb_generic_handle_packet;
- uc->handle_reset = usb_hid_handle_reset;
- uc->handle_control = usb_hid_handle_control;
- uc->handle_data = usb_hid_handle_data;
- uc->handle_destroy = usb_hid_handle_destroy;
}
static struct DeviceInfo usb_mouse_info = {
@@ -606,14 +609,10 @@ static void usb_keyboard_class_initfn(ObjectClass *klass, void *data)
{
USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
+ usb_hid_class_initfn(klass, data);
uc->init = usb_keyboard_initfn;
uc->product_desc = "QEMU USB Keyboard";
uc->usb_desc = &desc_keyboard;
- uc->handle_packet = usb_generic_handle_packet;
- uc->handle_reset = usb_hid_handle_reset;
- uc->handle_control = usb_hid_handle_control;
- uc->handle_data = usb_hid_handle_data;
- uc->handle_destroy = usb_hid_handle_destroy;
}
static struct DeviceInfo usb_keyboard_info = {
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 050/197] accessors for scsideviceinfo
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (46 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 049/197] usb-hid: simply class initialization a bit Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 051/197] drop info link in SCSIDeviceInfo Anthony Liguori
` (18 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/scsi-bus.c | 48 +++++++++++++++++++++++++++++++++++++-----------
1 files changed, 37 insertions(+), 11 deletions(-)
diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
index 731c1f3..a054324 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi-bus.c
@@ -23,6 +23,38 @@ static struct BusInfo scsi_bus_info = {
};
static int next_scsi_bus;
+static int scsi_device_init(SCSIDevice *dev)
+{
+ if (dev->info->init) {
+ return dev->info->init(dev);
+ }
+ return 0;
+}
+
+static void scsi_device_destroy(SCSIDevice *s)
+{
+ if (s->info->destroy) {
+ s->info->destroy(s);
+ }
+}
+
+static SCSIRequest *scsi_device_alloc_req(SCSIDevice *s, uint32_t tag, uint32_t lun,
+ uint8_t *buf, void *hba_private)
+{
+ if (s->info->alloc_req) {
+ return s->info->alloc_req(s, tag, lun, buf, hba_private);
+ }
+
+ return NULL;
+}
+
+static void scsi_device_unit_attention_reported(SCSIDevice *s)
+{
+ if (s->info->unit_attention_reported) {
+ s->info->unit_attention_reported(s);
+ }
+}
+
/* Create a scsi bus, and attach devices to it. */
void scsi_bus_new(SCSIBus *bus, DeviceState *host, const SCSIBusInfo *info)
{
@@ -128,7 +160,7 @@ static int scsi_qdev_init(DeviceState *qdev, DeviceInfo *base)
dev->info = info;
QTAILQ_INIT(&dev->requests);
- rc = dev->info->init(dev);
+ rc = scsi_device_init(dev);
if (rc == 0) {
dev->vmsentry = qemu_add_vm_change_state_handler(scsi_dma_restart_cb,
dev);
@@ -145,9 +177,7 @@ static int scsi_qdev_exit(DeviceState *qdev)
if (dev->vmsentry) {
qemu_del_vm_change_state_handler(dev->vmsentry);
}
- if (dev->info->destroy) {
- dev->info->destroy(dev);
- }
+ scsi_device_destroy(dev);
return 0;
}
@@ -398,9 +428,7 @@ static int32_t scsi_target_send_command(SCSIRequest *req, uint8_t *buf)
MIN(req->cmd.xfer, sizeof r->buf),
(req->cmd.buf[1] & 1) == 0);
if (r->req.dev->sense_is_ua) {
- if (r->req.dev->info->unit_attention_reported) {
- r->req.dev->info->unit_attention_reported(req->dev);
- }
+ scsi_device_unit_attention_reported(req->dev);
r->req.dev->sense_len = 0;
r->req.dev->sense_is_ua = false;
}
@@ -507,7 +535,7 @@ SCSIRequest *scsi_req_new(SCSIDevice *d, uint32_t tag, uint32_t lun,
req = scsi_req_alloc(&reqops_target_command, d, tag, lun,
hba_private);
} else {
- req = d->info->alloc_req(d, tag, lun, buf, hba_private);
+ req = scsi_device_alloc_req(d, tag, lun, buf, hba_private);
}
}
@@ -597,9 +625,7 @@ int scsi_req_get_sense(SCSIRequest *req, uint8_t *buf, int len)
* Here we handle unit attention clearing for UA_INTLCK_CTRL == 00b.
*/
if (req->dev->sense_is_ua) {
- if (req->dev->info->unit_attention_reported) {
- req->dev->info->unit_attention_reported(req->dev);
- }
+ scsi_device_unit_attention_reported(req->dev);
req->dev->sense_len = 0;
req->dev->sense_is_ua = false;
}
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 051/197] drop info link in SCSIDeviceInfo
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (47 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 050/197] accessors for scsideviceinfo Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 052/197] move methods out of SCSIDeviceInfo into SCSIDeviceClass Anthony Liguori
` (17 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/scsi-bus.c | 26 ++++++++++++++++----------
hw/scsi.h | 1 -
2 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
index a054324..8f0d7e6 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi-bus.c
@@ -25,24 +25,30 @@ static int next_scsi_bus;
static int scsi_device_init(SCSIDevice *dev)
{
- if (dev->info->init) {
- return dev->info->init(dev);
+ SCSIDeviceInfo *info = DO_UPCAST(SCSIDeviceInfo, qdev,
+ qdev_get_info(DEVICE(dev)));
+ if (info->init) {
+ return info->init(dev);
}
return 0;
}
static void scsi_device_destroy(SCSIDevice *s)
{
- if (s->info->destroy) {
- s->info->destroy(s);
+ SCSIDeviceInfo *info = DO_UPCAST(SCSIDeviceInfo, qdev,
+ qdev_get_info(DEVICE(s)));
+ if (info->destroy) {
+ info->destroy(s);
}
}
static SCSIRequest *scsi_device_alloc_req(SCSIDevice *s, uint32_t tag, uint32_t lun,
uint8_t *buf, void *hba_private)
{
- if (s->info->alloc_req) {
- return s->info->alloc_req(s, tag, lun, buf, hba_private);
+ SCSIDeviceInfo *info = DO_UPCAST(SCSIDeviceInfo, qdev,
+ qdev_get_info(DEVICE(s)));
+ if (info->alloc_req) {
+ return info->alloc_req(s, tag, lun, buf, hba_private);
}
return NULL;
@@ -50,8 +56,10 @@ static SCSIRequest *scsi_device_alloc_req(SCSIDevice *s, uint32_t tag, uint32_t
static void scsi_device_unit_attention_reported(SCSIDevice *s)
{
- if (s->info->unit_attention_reported) {
- s->info->unit_attention_reported(s);
+ SCSIDeviceInfo *info = DO_UPCAST(SCSIDeviceInfo, qdev,
+ qdev_get_info(DEVICE(s)));
+ if (info->unit_attention_reported) {
+ info->unit_attention_reported(s);
}
}
@@ -114,7 +122,6 @@ static void scsi_dma_restart_cb(void *opaque, int running, RunState state)
static int scsi_qdev_init(DeviceState *qdev, DeviceInfo *base)
{
SCSIDevice *dev = SCSI_DEVICE(qdev);
- SCSIDeviceInfo *info = DO_UPCAST(SCSIDeviceInfo, qdev, base);
SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, dev->qdev.parent_bus);
SCSIDevice *d;
int rc = -1;
@@ -158,7 +165,6 @@ static int scsi_qdev_init(DeviceState *qdev, DeviceInfo *base)
}
}
- dev->info = info;
QTAILQ_INIT(&dev->requests);
rc = scsi_device_init(dev);
if (rc == 0) {
diff --git a/hw/scsi.h b/hw/scsi.h
index 282cebd..0d24d41 100644
--- a/hw/scsi.h
+++ b/hw/scsi.h
@@ -77,7 +77,6 @@ struct SCSIDevice
QEMUBH *bh;
uint32_t id;
BlockConf conf;
- SCSIDeviceInfo *info;
SCSISense unit_attention;
bool sense_is_ua;
uint8_t sense[SCSI_SENSE_BUF_SIZE];
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 052/197] move methods out of SCSIDeviceInfo into SCSIDeviceClass
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (48 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 051/197] drop info link in SCSIDeviceInfo Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 053/197] kill off SCSIDeviceInfo Anthony Liguori
` (16 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/scsi-bus.c | 30 ++++------
hw/scsi-disk.c | 159 ++++++++++++++++++++++++++++++++---------------------
hw/scsi-generic.c | 13 +++-
hw/scsi.h | 11 ++--
4 files changed, 124 insertions(+), 89 deletions(-)
diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
index 8f0d7e6..cabdb3c 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi-bus.c
@@ -23,32 +23,29 @@ static struct BusInfo scsi_bus_info = {
};
static int next_scsi_bus;
-static int scsi_device_init(SCSIDevice *dev)
+static int scsi_device_init(SCSIDevice *s)
{
- SCSIDeviceInfo *info = DO_UPCAST(SCSIDeviceInfo, qdev,
- qdev_get_info(DEVICE(dev)));
- if (info->init) {
- return info->init(dev);
+ SCSIDeviceClass *sc = SCSI_DEVICE_GET_CLASS(s);
+ if (sc->init) {
+ return sc->init(s);
}
return 0;
}
static void scsi_device_destroy(SCSIDevice *s)
{
- SCSIDeviceInfo *info = DO_UPCAST(SCSIDeviceInfo, qdev,
- qdev_get_info(DEVICE(s)));
- if (info->destroy) {
- info->destroy(s);
+ SCSIDeviceClass *sc = SCSI_DEVICE_GET_CLASS(s);
+ if (sc->destroy) {
+ sc->destroy(s);
}
}
static SCSIRequest *scsi_device_alloc_req(SCSIDevice *s, uint32_t tag, uint32_t lun,
uint8_t *buf, void *hba_private)
{
- SCSIDeviceInfo *info = DO_UPCAST(SCSIDeviceInfo, qdev,
- qdev_get_info(DEVICE(s)));
- if (info->alloc_req) {
- return info->alloc_req(s, tag, lun, buf, hba_private);
+ SCSIDeviceClass *sc = SCSI_DEVICE_GET_CLASS(s);
+ if (sc->alloc_req) {
+ return sc->alloc_req(s, tag, lun, buf, hba_private);
}
return NULL;
@@ -56,10 +53,9 @@ static SCSIRequest *scsi_device_alloc_req(SCSIDevice *s, uint32_t tag, uint32_t
static void scsi_device_unit_attention_reported(SCSIDevice *s)
{
- SCSIDeviceInfo *info = DO_UPCAST(SCSIDeviceInfo, qdev,
- qdev_get_info(DEVICE(s)));
- if (info->unit_attention_reported) {
- info->unit_attention_reported(s);
+ SCSIDeviceClass *sc = SCSI_DEVICE_GET_CLASS(s);
+ if (sc->unit_attention_reported) {
+ sc->unit_attention_reported(s);
}
}
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 673948c..9944d69 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1729,75 +1729,108 @@ static SCSIRequest *scsi_block_new_request(SCSIDevice *d, uint32_t tag,
DEFINE_PROP_STRING("ver", SCSIDiskState, version), \
DEFINE_PROP_STRING("serial", SCSIDiskState, serial)
-static SCSIDeviceInfo scsi_disk_info[] = {
- {
- .qdev.name = "scsi-hd",
- .qdev.fw_name = "disk",
- .qdev.desc = "virtual SCSI disk",
- .qdev.size = sizeof(SCSIDiskState),
- .qdev.reset = scsi_disk_reset,
- .init = scsi_hd_initfn,
- .destroy = scsi_destroy,
- .alloc_req = scsi_new_request,
- .unit_attention_reported = scsi_disk_unit_attention_reported,
- .qdev.props = (Property[]) {
- DEFINE_SCSI_DISK_PROPERTIES(),
- DEFINE_PROP_BIT("removable", SCSIDiskState, removable, 0, false),
- DEFINE_PROP_END_OF_LIST(),
- }
- },{
- .qdev.name = "scsi-cd",
- .qdev.fw_name = "disk",
- .qdev.desc = "virtual SCSI CD-ROM",
- .qdev.size = sizeof(SCSIDiskState),
- .qdev.reset = scsi_disk_reset,
- .init = scsi_cd_initfn,
- .destroy = scsi_destroy,
- .alloc_req = scsi_new_request,
- .unit_attention_reported = scsi_disk_unit_attention_reported,
- .qdev.props = (Property[]) {
- DEFINE_SCSI_DISK_PROPERTIES(),
- DEFINE_PROP_END_OF_LIST(),
- },
+static void scsi_hd_class_initfn(ObjectClass *klass, void *data)
+{
+ SCSIDeviceClass *sc = SCSI_DEVICE_CLASS(klass);
+
+ sc->init = scsi_hd_initfn;
+ sc->destroy = scsi_destroy;
+ sc->alloc_req = scsi_new_request;
+ sc->unit_attention_reported = scsi_disk_unit_attention_reported;
+}
+
+static SCSIDeviceInfo scsi_hd_info = {
+ .qdev.name = "scsi-hd",
+ .qdev.fw_name = "disk",
+ .qdev.desc = "virtual SCSI disk",
+ .qdev.size = sizeof(SCSIDiskState),
+ .qdev.reset = scsi_disk_reset,
+ .qdev.class_init = scsi_hd_class_initfn,
+ .qdev.props = (Property[]) {
+ DEFINE_SCSI_DISK_PROPERTIES(),
+ DEFINE_PROP_BIT("removable", SCSIDiskState, removable, 0, false),
+ DEFINE_PROP_END_OF_LIST(),
+ },
+};
+
+static void scsi_cd_class_initfn(ObjectClass *klass, void *data)
+{
+ SCSIDeviceClass *sc = SCSI_DEVICE_CLASS(klass);
+
+ sc->init = scsi_cd_initfn;
+ sc->destroy = scsi_destroy;
+ sc->alloc_req = scsi_new_request;
+ sc->unit_attention_reported = scsi_disk_unit_attention_reported;
+}
+
+static SCSIDeviceInfo scsi_cd_info = {
+ .qdev.name = "scsi-cd",
+ .qdev.fw_name = "disk",
+ .qdev.desc = "virtual SCSI CD-ROM",
+ .qdev.size = sizeof(SCSIDiskState),
+ .qdev.reset = scsi_disk_reset,
+ .qdev.class_init = scsi_cd_class_initfn,
+ .qdev.props = (Property[]) {
+ DEFINE_SCSI_DISK_PROPERTIES(),
+ DEFINE_PROP_END_OF_LIST(),
+ },
+};
+
#ifdef __linux__
- },{
- .qdev.name = "scsi-block",
- .qdev.fw_name = "disk",
- .qdev.desc = "SCSI block device passthrough",
- .qdev.size = sizeof(SCSIDiskState),
- .qdev.reset = scsi_disk_reset,
- .init = scsi_block_initfn,
- .destroy = scsi_destroy,
- .alloc_req = scsi_block_new_request,
- .qdev.props = (Property[]) {
- DEFINE_SCSI_DISK_PROPERTIES(),
- DEFINE_PROP_END_OF_LIST(),
- },
+static void scsi_block_class_initfn(ObjectClass *klass, void *data)
+{
+ SCSIDeviceClass *sc = SCSI_DEVICE_CLASS(klass);
+
+ sc->init = scsi_block_initfn;
+ sc->destroy = scsi_destroy;
+ sc->alloc_req = scsi_block_new_request;
+}
+
+static SCSIDeviceInfo scsi_block_info = {
+ .qdev.name = "scsi-block",
+ .qdev.fw_name = "disk",
+ .qdev.desc = "SCSI block device passthrough",
+ .qdev.size = sizeof(SCSIDiskState),
+ .qdev.reset = scsi_disk_reset,
+ .qdev.class_init = scsi_block_class_initfn,
+ .qdev.props = (Property[]) {
+ DEFINE_SCSI_DISK_PROPERTIES(),
+ DEFINE_PROP_END_OF_LIST(),
+ },
+};
#endif
- },{
- .qdev.name = "scsi-disk", /* legacy -device scsi-disk */
- .qdev.fw_name = "disk",
- .qdev.desc = "virtual SCSI disk or CD-ROM (legacy)",
- .qdev.size = sizeof(SCSIDiskState),
- .qdev.reset = scsi_disk_reset,
- .init = scsi_disk_initfn,
- .destroy = scsi_destroy,
- .alloc_req = scsi_new_request,
- .unit_attention_reported = scsi_disk_unit_attention_reported,
- .qdev.props = (Property[]) {
- DEFINE_SCSI_DISK_PROPERTIES(),
- DEFINE_PROP_BIT("removable", SCSIDiskState, removable, 0, false),
- DEFINE_PROP_END_OF_LIST(),
- }
+
+static void scsi_disk_class_initfn(ObjectClass *klass, void *data)
+{
+ SCSIDeviceClass *sc = SCSI_DEVICE_CLASS(klass);
+
+ sc->init = scsi_disk_initfn;
+ sc->destroy = scsi_destroy;
+ sc->alloc_req = scsi_new_request;
+ sc->unit_attention_reported = scsi_disk_unit_attention_reported;
+}
+
+static SCSIDeviceInfo scsi_disk_info = {
+ .qdev.name = "scsi-disk", /* legacy -device scsi-disk */
+ .qdev.fw_name = "disk",
+ .qdev.desc = "virtual SCSI disk or CD-ROM (legacy)",
+ .qdev.size = sizeof(SCSIDiskState),
+ .qdev.reset = scsi_disk_reset,
+ .qdev.class_init = scsi_disk_class_initfn,
+ .qdev.props = (Property[]) {
+ DEFINE_SCSI_DISK_PROPERTIES(),
+ DEFINE_PROP_BIT("removable", SCSIDiskState, removable, 0, false),
+ DEFINE_PROP_END_OF_LIST(),
}
};
static void scsi_disk_register_devices(void)
{
- int i;
-
- for (i = 0; i < ARRAY_SIZE(scsi_disk_info); i++) {
- scsi_qdev_register(&scsi_disk_info[i]);
- }
+ scsi_qdev_register(&scsi_hd_info);
+ scsi_qdev_register(&scsi_cd_info);
+#ifdef __linux__
+ scsi_qdev_register(&scsi_block_info);
+#endif
+ scsi_qdev_register(&scsi_disk_info);
}
device_init(scsi_disk_register_devices)
diff --git a/hw/scsi-generic.c b/hw/scsi-generic.c
index ef76e4b..9fb2a09 100644
--- a/hw/scsi-generic.c
+++ b/hw/scsi-generic.c
@@ -461,15 +461,22 @@ static SCSIRequest *scsi_new_request(SCSIDevice *d, uint32_t tag, uint32_t lun,
return req;
}
+static void scsi_generic_class_initfn(ObjectClass *klass, void *data)
+{
+ SCSIDeviceClass *sc = SCSI_DEVICE_CLASS(klass);
+
+ sc->init = scsi_generic_initfn;
+ sc->destroy = scsi_destroy;
+ sc->alloc_req = scsi_new_request;
+}
+
static SCSIDeviceInfo scsi_generic_info = {
.qdev.name = "scsi-generic",
.qdev.fw_name = "disk",
.qdev.desc = "pass through generic scsi device (/dev/sg*)",
.qdev.size = sizeof(SCSIDevice),
.qdev.reset = scsi_generic_reset,
- .init = scsi_generic_initfn,
- .destroy = scsi_destroy,
- .alloc_req = scsi_new_request,
+ .qdev.class_init = scsi_generic_class_initfn,
.qdev.props = (Property[]) {
DEFINE_BLOCK_PROPERTIES(SCSIDevice, conf),
DEFINE_PROP_END_OF_LIST(),
diff --git a/hw/scsi.h b/hw/scsi.h
index 0d24d41..41501f2 100644
--- a/hw/scsi.h
+++ b/hw/scsi.h
@@ -68,6 +68,11 @@ struct SCSIRequest {
typedef struct SCSIDeviceClass {
DeviceClass parent_class;
+ int (*init)(SCSIDevice *dev);
+ void (*destroy)(SCSIDevice *s);
+ SCSIRequest *(*alloc_req)(SCSIDevice *s, uint32_t tag, uint32_t lun,
+ uint8_t *buf, void *hba_private);
+ void (*unit_attention_reported)(SCSIDevice *s);
} SCSIDeviceClass;
struct SCSIDevice
@@ -104,14 +109,8 @@ struct SCSIReqOps {
uint8_t *(*get_buf)(SCSIRequest *req);
};
-typedef int (*scsi_qdev_initfn)(SCSIDevice *dev);
struct SCSIDeviceInfo {
DeviceInfo qdev;
- scsi_qdev_initfn init;
- void (*destroy)(SCSIDevice *s);
- SCSIRequest *(*alloc_req)(SCSIDevice *s, uint32_t tag, uint32_t lun,
- uint8_t *buf, void *hba_private);
- void (*unit_attention_reported)(SCSIDevice *s);
};
struct SCSIBusInfo {
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 053/197] kill off SCSIDeviceInfo
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (49 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 052/197] move methods out of SCSIDeviceInfo into SCSIDeviceClass Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 054/197] get rid of CCIDCardInfo Anthony Liguori
` (15 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/scsi-bus.c | 12 +++++-----
hw/scsi-disk.c | 64 ++++++++++++++++++++++++++--------------------------
hw/scsi-generic.c | 16 ++++++------
hw/scsi.h | 7 +-----
4 files changed, 47 insertions(+), 52 deletions(-)
diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
index cabdb3c..d017ece 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi-bus.c
@@ -183,13 +183,13 @@ static int scsi_qdev_exit(DeviceState *qdev)
return 0;
}
-void scsi_qdev_register(SCSIDeviceInfo *info)
+void scsi_qdev_register(DeviceInfo *info)
{
- info->qdev.bus_info = &scsi_bus_info;
- info->qdev.init = scsi_qdev_init;
- info->qdev.unplug = qdev_simple_unplug_cb;
- info->qdev.exit = scsi_qdev_exit;
- qdev_register_subclass(&info->qdev, TYPE_SCSI_DEVICE);
+ info->bus_info = &scsi_bus_info;
+ info->init = scsi_qdev_init;
+ info->unplug = qdev_simple_unplug_cb;
+ info->exit = scsi_qdev_exit;
+ qdev_register_subclass(info, TYPE_SCSI_DEVICE);
}
/* handle legacy '-drive if=scsi,...' cmd line args */
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 9944d69..4c4cc75 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1739,14 +1739,14 @@ static void scsi_hd_class_initfn(ObjectClass *klass, void *data)
sc->unit_attention_reported = scsi_disk_unit_attention_reported;
}
-static SCSIDeviceInfo scsi_hd_info = {
- .qdev.name = "scsi-hd",
- .qdev.fw_name = "disk",
- .qdev.desc = "virtual SCSI disk",
- .qdev.size = sizeof(SCSIDiskState),
- .qdev.reset = scsi_disk_reset,
- .qdev.class_init = scsi_hd_class_initfn,
- .qdev.props = (Property[]) {
+static DeviceInfo scsi_hd_info = {
+ .name = "scsi-hd",
+ .fw_name = "disk",
+ .desc = "virtual SCSI disk",
+ .size = sizeof(SCSIDiskState),
+ .reset = scsi_disk_reset,
+ .class_init = scsi_hd_class_initfn,
+ .props = (Property[]) {
DEFINE_SCSI_DISK_PROPERTIES(),
DEFINE_PROP_BIT("removable", SCSIDiskState, removable, 0, false),
DEFINE_PROP_END_OF_LIST(),
@@ -1763,14 +1763,14 @@ static void scsi_cd_class_initfn(ObjectClass *klass, void *data)
sc->unit_attention_reported = scsi_disk_unit_attention_reported;
}
-static SCSIDeviceInfo scsi_cd_info = {
- .qdev.name = "scsi-cd",
- .qdev.fw_name = "disk",
- .qdev.desc = "virtual SCSI CD-ROM",
- .qdev.size = sizeof(SCSIDiskState),
- .qdev.reset = scsi_disk_reset,
- .qdev.class_init = scsi_cd_class_initfn,
- .qdev.props = (Property[]) {
+static DeviceInfo scsi_cd_info = {
+ .name = "scsi-cd",
+ .fw_name = "disk",
+ .desc = "virtual SCSI CD-ROM",
+ .size = sizeof(SCSIDiskState),
+ .reset = scsi_disk_reset,
+ .class_init = scsi_cd_class_initfn,
+ .props = (Property[]) {
DEFINE_SCSI_DISK_PROPERTIES(),
DEFINE_PROP_END_OF_LIST(),
},
@@ -1786,14 +1786,14 @@ static void scsi_block_class_initfn(ObjectClass *klass, void *data)
sc->alloc_req = scsi_block_new_request;
}
-static SCSIDeviceInfo scsi_block_info = {
- .qdev.name = "scsi-block",
- .qdev.fw_name = "disk",
- .qdev.desc = "SCSI block device passthrough",
- .qdev.size = sizeof(SCSIDiskState),
- .qdev.reset = scsi_disk_reset,
- .qdev.class_init = scsi_block_class_initfn,
- .qdev.props = (Property[]) {
+static DeviceInfo scsi_block_info = {
+ .name = "scsi-block",
+ .fw_name = "disk",
+ .desc = "SCSI block device passthrough",
+ .size = sizeof(SCSIDiskState),
+ .reset = scsi_disk_reset,
+ .class_init = scsi_block_class_initfn,
+ .props = (Property[]) {
DEFINE_SCSI_DISK_PROPERTIES(),
DEFINE_PROP_END_OF_LIST(),
},
@@ -1810,14 +1810,14 @@ static void scsi_disk_class_initfn(ObjectClass *klass, void *data)
sc->unit_attention_reported = scsi_disk_unit_attention_reported;
}
-static SCSIDeviceInfo scsi_disk_info = {
- .qdev.name = "scsi-disk", /* legacy -device scsi-disk */
- .qdev.fw_name = "disk",
- .qdev.desc = "virtual SCSI disk or CD-ROM (legacy)",
- .qdev.size = sizeof(SCSIDiskState),
- .qdev.reset = scsi_disk_reset,
- .qdev.class_init = scsi_disk_class_initfn,
- .qdev.props = (Property[]) {
+static DeviceInfo scsi_disk_info = {
+ .name = "scsi-disk", /* legacy -device scsi-disk */
+ .fw_name = "disk",
+ .desc = "virtual SCSI disk or CD-ROM (legacy)",
+ .size = sizeof(SCSIDiskState),
+ .reset = scsi_disk_reset,
+ .class_init = scsi_disk_class_initfn,
+ .props = (Property[]) {
DEFINE_SCSI_DISK_PROPERTIES(),
DEFINE_PROP_BIT("removable", SCSIDiskState, removable, 0, false),
DEFINE_PROP_END_OF_LIST(),
diff --git a/hw/scsi-generic.c b/hw/scsi-generic.c
index 9fb2a09..8d7a8f3 100644
--- a/hw/scsi-generic.c
+++ b/hw/scsi-generic.c
@@ -470,14 +470,14 @@ static void scsi_generic_class_initfn(ObjectClass *klass, void *data)
sc->alloc_req = scsi_new_request;
}
-static SCSIDeviceInfo scsi_generic_info = {
- .qdev.name = "scsi-generic",
- .qdev.fw_name = "disk",
- .qdev.desc = "pass through generic scsi device (/dev/sg*)",
- .qdev.size = sizeof(SCSIDevice),
- .qdev.reset = scsi_generic_reset,
- .qdev.class_init = scsi_generic_class_initfn,
- .qdev.props = (Property[]) {
+static DeviceInfo scsi_generic_info = {
+ .name = "scsi-generic",
+ .fw_name = "disk",
+ .desc = "pass through generic scsi device (/dev/sg*)",
+ .size = sizeof(SCSIDevice),
+ .reset = scsi_generic_reset,
+ .class_init = scsi_generic_class_initfn,
+ .props = (Property[]) {
DEFINE_BLOCK_PROPERTIES(SCSIDevice, conf),
DEFINE_PROP_END_OF_LIST(),
},
diff --git a/hw/scsi.h b/hw/scsi.h
index 41501f2..4290b20 100644
--- a/hw/scsi.h
+++ b/hw/scsi.h
@@ -13,7 +13,6 @@ typedef struct SCSIBus SCSIBus;
typedef struct SCSIBusInfo SCSIBusInfo;
typedef struct SCSICommand SCSICommand;
typedef struct SCSIDevice SCSIDevice;
-typedef struct SCSIDeviceInfo SCSIDeviceInfo;
typedef struct SCSIRequest SCSIRequest;
typedef struct SCSIReqOps SCSIReqOps;
@@ -109,10 +108,6 @@ struct SCSIReqOps {
uint8_t *(*get_buf)(SCSIRequest *req);
};
-struct SCSIDeviceInfo {
- DeviceInfo qdev;
-};
-
struct SCSIBusInfo {
int tcq;
int max_channel, max_target, max_lun;
@@ -130,7 +125,7 @@ struct SCSIBus {
};
void scsi_bus_new(SCSIBus *bus, DeviceState *host, const SCSIBusInfo *info);
-void scsi_qdev_register(SCSIDeviceInfo *info);
+void scsi_qdev_register(DeviceInfo *info);
static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d)
{
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 054/197] get rid of CCIDCardInfo
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (50 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 053/197] kill off SCSIDeviceInfo Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 055/197] rename i2c_slave -> I2CSlave Anthony Liguori
` (14 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/ccid-card-emulated.c | 27 ++++++++++++-------
hw/ccid-card-passthru.c | 27 ++++++++++++-------
hw/ccid.h | 26 ++++++++-----------
hw/usb-ccid.c | 63 ++++++++++++++++++++++++++++++++++------------
4 files changed, 91 insertions(+), 52 deletions(-)
diff --git a/hw/ccid-card-emulated.c b/hw/ccid-card-emulated.c
index 092301b..2748fd8 100644
--- a/hw/ccid-card-emulated.c
+++ b/hw/ccid-card-emulated.c
@@ -567,16 +567,23 @@ static int emulated_exitfn(CCIDCardState *base)
return 0;
}
-static CCIDCardInfo emulated_card_info = {
- .qdev.name = EMULATED_DEV_NAME,
- .qdev.desc = "emulated smartcard",
- .qdev.size = sizeof(EmulatedState),
- .initfn = emulated_initfn,
- .exitfn = emulated_exitfn,
- .get_atr = emulated_get_atr,
- .apdu_from_guest = emulated_apdu_from_guest,
- .qdev.unplug = qdev_simple_unplug_cb,
- .qdev.props = (Property[]) {
+static void emulated_class_initfn(ObjectClass *klass, void *data)
+{
+ CCIDCardClass *cc = CCID_CARD_CLASS(klass);
+
+ cc->initfn = emulated_initfn;
+ cc->exitfn = emulated_exitfn;
+ cc->get_atr = emulated_get_atr;
+ cc->apdu_from_guest = emulated_apdu_from_guest;
+}
+
+static DeviceInfo emulated_card_info = {
+ .name = EMULATED_DEV_NAME,
+ .desc = "emulated smartcard",
+ .size = sizeof(EmulatedState),
+ .unplug = qdev_simple_unplug_cb,
+ .class_init = emulated_class_initfn,
+ .props = (Property[]) {
DEFINE_PROP_STRING("backend", EmulatedState, backend_str),
DEFINE_PROP_STRING("cert1", EmulatedState, cert1),
DEFINE_PROP_STRING("cert2", EmulatedState, cert2),
diff --git a/hw/ccid-card-passthru.c b/hw/ccid-card-passthru.c
index 9f51c6c..f563d97 100644
--- a/hw/ccid-card-passthru.c
+++ b/hw/ccid-card-passthru.c
@@ -316,16 +316,23 @@ static VMStateDescription passthru_vmstate = {
}
};
-static CCIDCardInfo passthru_card_info = {
- .qdev.name = PASSTHRU_DEV_NAME,
- .qdev.desc = "passthrough smartcard",
- .qdev.size = sizeof(PassthruState),
- .qdev.vmsd = &passthru_vmstate,
- .initfn = passthru_initfn,
- .exitfn = passthru_exitfn,
- .get_atr = passthru_get_atr,
- .apdu_from_guest = passthru_apdu_from_guest,
- .qdev.props = (Property[]) {
+static void passthru_class_initfn(ObjectClass *klass, void *data)
+{
+ CCIDCardClass *cc = CCID_CARD_CLASS(klass);
+
+ cc->initfn = passthru_initfn;
+ cc->exitfn = passthru_exitfn;
+ cc->get_atr = passthru_get_atr;
+ cc->apdu_from_guest = passthru_apdu_from_guest;
+}
+
+static DeviceInfo passthru_card_info = {
+ .name = PASSTHRU_DEV_NAME,
+ .desc = "passthrough smartcard",
+ .size = sizeof(PassthruState),
+ .vmsd = &passthru_vmstate,
+ .class_init = passthru_class_initfn,
+ .props = (Property[]) {
DEFINE_PROP_CHR("chardev", PassthruState, cs),
DEFINE_PROP_UINT8("debug", PassthruState, debug, 0),
DEFINE_PROP_END_OF_LIST(),
diff --git a/hw/ccid.h b/hw/ccid.h
index d8e0485..9e4979c 100644
--- a/hw/ccid.h
+++ b/hw/ccid.h
@@ -23,30 +23,26 @@ typedef struct CCIDCardInfo CCIDCardInfo;
#define CCID_CARD_GET_CLASS(obj) \
OBJECT_GET_CLASS(CCIDCardClass, (obj), TYPE_CCID_CARD)
-typedef struct CCIDCardClass {
- DeviceClass parent_class;
-} CCIDCardClass;
-
-/*
- * state of the CCID Card device (i.e. hw/ccid-card-*.c)
- */
-struct CCIDCardState {
- DeviceState qdev;
- uint32_t slot; /* For future use with multiple slot reader. */
-};
-
/*
* callbacks to be used by the CCID device (hw/usb-ccid.c) to call
* into the smartcard device (hw/ccid-card-*.c)
*/
-struct CCIDCardInfo {
- DeviceInfo qdev;
+typedef struct CCIDCardClass {
+ DeviceClass parent_class;
const uint8_t *(*get_atr)(CCIDCardState *card, uint32_t *len);
void (*apdu_from_guest)(CCIDCardState *card,
const uint8_t *apdu,
uint32_t len);
int (*exitfn)(CCIDCardState *card);
int (*initfn)(CCIDCardState *card);
+} CCIDCardClass;
+
+/*
+ * state of the CCID Card device (i.e. hw/ccid-card-*.c)
+ */
+struct CCIDCardState {
+ DeviceState qdev;
+ uint32_t slot; /* For future use with multiple slot reader. */
};
/*
@@ -58,7 +54,7 @@ void ccid_card_send_apdu_to_guest(CCIDCardState *card,
void ccid_card_card_removed(CCIDCardState *card);
void ccid_card_card_inserted(CCIDCardState *card);
void ccid_card_card_error(CCIDCardState *card, uint64_t error);
-void ccid_card_qdev_register(CCIDCardInfo *card);
+void ccid_card_qdev_register(DeviceInfo *card);
/*
* support guest visible insertion/removal of ccid devices based on actual
diff --git a/hw/usb-ccid.c b/hw/usb-ccid.c
index 41a53aa..a803c71 100644
--- a/hw/usb-ccid.c
+++ b/hw/usb-ccid.c
@@ -269,7 +269,6 @@ typedef struct USBCCIDState {
USBDevice dev;
CCIDBus bus;
CCIDCardState *card;
- CCIDCardInfo *cardinfo; /* caching the info pointer */
BulkIn bulk_in_pending[BULK_IN_PENDING_NUM]; /* circular */
uint32_t bulk_in_pending_start;
uint32_t bulk_in_pending_end; /* first free */
@@ -468,6 +467,43 @@ static const USBDesc desc_ccid = {
.str = desc_strings,
};
+static const uint8_t *ccid_card_get_atr(CCIDCardState *card, uint32_t *len)
+{
+ CCIDCardClass *cc = CCID_CARD_GET_CLASS(card);
+ if (cc->get_atr) {
+ return cc->get_atr(card, len);
+ }
+ return NULL;
+}
+
+static void ccid_card_apdu_from_guest(CCIDCardState *card,
+ const uint8_t *apdu,
+ uint32_t len)
+{
+ CCIDCardClass *cc = CCID_CARD_GET_CLASS(card);
+ if (cc->apdu_from_guest) {
+ cc->apdu_from_guest(card, apdu, len);
+ }
+}
+
+static int ccid_card_exitfn(CCIDCardState *card)
+{
+ CCIDCardClass *cc = CCID_CARD_GET_CLASS(card);
+ if (cc->exitfn) {
+ return cc->exitfn(card);
+ }
+ return 0;
+}
+
+static int ccid_card_initfn(CCIDCardState *card)
+{
+ CCIDCardClass *cc = CCID_CARD_GET_CLASS(card);
+ if (cc->initfn) {
+ return cc->initfn(card);
+ }
+ return 0;
+}
+
static bool ccid_has_pending_answers(USBCCIDState *s)
{
return s->pending_answers_num > 0;
@@ -749,7 +785,7 @@ static void ccid_write_data_block_atr(USBCCIDState *s, CCID_Header *recv)
uint32_t len = 0;
if (s->card) {
- atr = s->cardinfo->get_atr(s->card, &len);
+ atr = ccid_card_get_atr(s->card, &len);
}
ccid_write_data_block(s, recv->bSlot, recv->bSeq, atr, len);
}
@@ -835,7 +871,7 @@ static void ccid_on_apdu_from_guest(USBCCIDState *s, CCID_XferBlock *recv)
recv->hdr.bSeq, len);
ccid_add_pending_answer(s, (CCID_Header *)recv);
if (s->card) {
- s->cardinfo->apdu_from_guest(s->card, recv->abData, len);
+ ccid_card_apdu_from_guest(s->card, recv->abData, len);
} else {
DPRINTF(s, D_WARN, "warning: discarded apdu\n");
}
@@ -1122,25 +1158,20 @@ static int ccid_card_exit(DeviceState *qdev)
{
int ret = 0;
CCIDCardState *card = CCID_CARD(qdev);
- CCIDCardInfo *info = DO_UPCAST(CCIDCardInfo, qdev, qdev_get_info(qdev));
USBCCIDState *s =
DO_UPCAST(USBCCIDState, dev.qdev, card->qdev.parent_bus->parent);
if (ccid_card_inserted(s)) {
ccid_card_card_removed(card);
}
- if (info->exitfn) {
- ret = info->exitfn(card);
- }
+ ret = ccid_card_exitfn(card);
s->card = NULL;
- s->cardinfo = NULL;
return ret;
}
static int ccid_card_init(DeviceState *qdev, DeviceInfo *base)
{
CCIDCardState *card = CCID_CARD(qdev);
- CCIDCardInfo *info = DO_UPCAST(CCIDCardInfo, qdev, base);
USBCCIDState *s =
DO_UPCAST(USBCCIDState, dev.qdev, card->qdev.parent_bus->parent);
int ret = 0;
@@ -1154,20 +1185,19 @@ static int ccid_card_init(DeviceState *qdev, DeviceInfo *base)
error_report("Warning: usb-ccid card already full, not adding");
return -1;
}
- ret = info->initfn ? info->initfn(card) : ret;
+ ret = ccid_card_initfn(card);
if (ret == 0) {
s->card = card;
- s->cardinfo = info;
}
return ret;
}
-void ccid_card_qdev_register(CCIDCardInfo *card)
+void ccid_card_qdev_register(DeviceInfo *info)
{
- card->qdev.bus_info = &ccid_bus_info;
- card->qdev.init = ccid_card_init;
- card->qdev.exit = ccid_card_exit;
- qdev_register_subclass(&card->qdev, TYPE_CCID_CARD);
+ info->bus_info = &ccid_bus_info;
+ info->init = ccid_card_init;
+ info->exit = ccid_card_exit;
+ qdev_register_subclass(info, TYPE_CCID_CARD);
}
static int ccid_initfn(USBDevice *dev)
@@ -1178,7 +1208,6 @@ static int ccid_initfn(USBDevice *dev)
qbus_create_inplace(&s->bus.qbus, &ccid_bus_info, &dev->qdev, NULL);
s->bus.qbus.allow_hotplug = 1;
s->card = NULL;
- s->cardinfo = NULL;
s->migration_state = MIGRATION_NONE;
s->migration_target_ip = 0;
s->migration_target_port = 0;
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 055/197] rename i2c_slave -> I2CSlave
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (51 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 054/197] get rid of CCIDCardInfo Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 056/197] add I2CSlave to the type hierarchy Anthony Liguori
` (13 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/ds1338.c | 10 +++++-----
hw/hw.h | 4 ++--
hw/i2c.c | 30 +++++++++++++++---------------
hw/i2c.h | 18 ++++++++++--------
hw/lm832x.c | 10 +++++-----
hw/max7310.c | 10 +++++-----
hw/pxa2xx.c | 10 +++++-----
hw/smbus.c | 8 ++++----
hw/smbus.h | 2 +-
hw/spitz.c | 2 +-
hw/ssd0303.c | 10 +++++-----
hw/tmp105.c | 14 +++++++-------
hw/tosa.c | 10 +++++-----
hw/twl92230.c | 12 ++++++------
hw/wm8750.c | 14 +++++++-------
hw/z2.c | 10 +++++-----
16 files changed, 88 insertions(+), 86 deletions(-)
diff --git a/hw/ds1338.c b/hw/ds1338.c
index 3522af5..88d6d18 100644
--- a/hw/ds1338.c
+++ b/hw/ds1338.c
@@ -10,7 +10,7 @@
#include "i2c.h"
typedef struct {
- i2c_slave i2c;
+ I2CSlave i2c;
time_t offset;
struct tm now;
uint8_t nvram[56];
@@ -18,7 +18,7 @@ typedef struct {
int addr_byte;
} DS1338State;
-static void ds1338_event(i2c_slave *i2c, enum i2c_event event)
+static void ds1338_event(I2CSlave *i2c, enum i2c_event event)
{
DS1338State *s = FROM_I2C_SLAVE(DS1338State, i2c);
@@ -48,7 +48,7 @@ static void ds1338_event(i2c_slave *i2c, enum i2c_event event)
}
}
-static int ds1338_recv(i2c_slave *i2c)
+static int ds1338_recv(I2CSlave *i2c)
{
DS1338State *s = FROM_I2C_SLAVE(DS1338State, i2c);
uint8_t res;
@@ -58,7 +58,7 @@ static int ds1338_recv(i2c_slave *i2c)
return res;
}
-static int ds1338_send(i2c_slave *i2c, uint8_t data)
+static int ds1338_send(I2CSlave *i2c, uint8_t data)
{
DS1338State *s = FROM_I2C_SLAVE(DS1338State, i2c);
if (s->addr_byte) {
@@ -110,7 +110,7 @@ static int ds1338_send(i2c_slave *i2c, uint8_t data)
return 0;
}
-static int ds1338_init(i2c_slave *i2c)
+static int ds1338_init(I2CSlave *i2c)
{
return 0;
}
diff --git a/hw/hw.h b/hw/hw.h
index ed20f5a..545eed3 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -662,10 +662,10 @@ extern const VMStateDescription vmstate_i2c_slave;
#define VMSTATE_I2C_SLAVE(_field, _state) { \
.name = (stringify(_field)), \
- .size = sizeof(i2c_slave), \
+ .size = sizeof(I2CSlave), \
.vmsd = &vmstate_i2c_slave, \
.flags = VMS_STRUCT, \
- .offset = vmstate_offset_value(_state, _field, i2c_slave), \
+ .offset = vmstate_offset_value(_state, _field, I2CSlave), \
}
extern const VMStateDescription vmstate_usb_device;
diff --git a/hw/i2c.c b/hw/i2c.c
index 9bcf3e1..9efe70c 100644
--- a/hw/i2c.c
+++ b/hw/i2c.c
@@ -12,8 +12,8 @@
struct i2c_bus
{
BusState qbus;
- i2c_slave *current_dev;
- i2c_slave *dev;
+ I2CSlave *current_dev;
+ I2CSlave *dev;
uint8_t saved_address;
};
@@ -21,7 +21,7 @@ static struct BusInfo i2c_bus_info = {
.name = "I2C",
.size = sizeof(i2c_bus),
.props = (Property[]) {
- DEFINE_PROP_UINT8("address", struct i2c_slave, address, 0),
+ DEFINE_PROP_UINT8("address", struct I2CSlave, address, 0),
DEFINE_PROP_END_OF_LIST(),
}
};
@@ -66,7 +66,7 @@ i2c_bus *i2c_init_bus(DeviceState *parent, const char *name)
return bus;
}
-void i2c_set_slave_address(i2c_slave *dev, uint8_t address)
+void i2c_set_slave_address(I2CSlave *dev, uint8_t address)
{
dev->address = address;
}
@@ -82,10 +82,10 @@ int i2c_bus_busy(i2c_bus *bus)
int i2c_start_transfer(i2c_bus *bus, uint8_t address, int recv)
{
DeviceState *qdev;
- i2c_slave *slave = NULL;
+ I2CSlave *slave = NULL;
QTAILQ_FOREACH(qdev, &bus->qbus.children, sibling) {
- i2c_slave *candidate = I2C_SLAVE_FROM_QDEV(qdev);
+ I2CSlave *candidate = I2C_SLAVE_FROM_QDEV(qdev);
if (candidate->address == address) {
slave = candidate;
break;
@@ -104,7 +104,7 @@ int i2c_start_transfer(i2c_bus *bus, uint8_t address, int recv)
void i2c_end_transfer(i2c_bus *bus)
{
- i2c_slave *dev = bus->current_dev;
+ I2CSlave *dev = bus->current_dev;
if (!dev)
return;
@@ -116,7 +116,7 @@ void i2c_end_transfer(i2c_bus *bus)
int i2c_send(i2c_bus *bus, uint8_t data)
{
- i2c_slave *dev = bus->current_dev;
+ I2CSlave *dev = bus->current_dev;
if (!dev)
return -1;
@@ -126,7 +126,7 @@ int i2c_send(i2c_bus *bus, uint8_t data)
int i2c_recv(i2c_bus *bus)
{
- i2c_slave *dev = bus->current_dev;
+ I2CSlave *dev = bus->current_dev;
if (!dev)
return -1;
@@ -136,7 +136,7 @@ int i2c_recv(i2c_bus *bus)
void i2c_nack(i2c_bus *bus)
{
- i2c_slave *dev = bus->current_dev;
+ I2CSlave *dev = bus->current_dev;
if (!dev)
return;
@@ -146,7 +146,7 @@ void i2c_nack(i2c_bus *bus)
static int i2c_slave_post_load(void *opaque, int version_id)
{
- i2c_slave *dev = opaque;
+ I2CSlave *dev = opaque;
i2c_bus *bus;
bus = FROM_QBUS(i2c_bus, qdev_get_parent_bus(&dev->qdev));
if (bus->saved_address == dev->address) {
@@ -156,13 +156,13 @@ static int i2c_slave_post_load(void *opaque, int version_id)
}
const VMStateDescription vmstate_i2c_slave = {
- .name = "i2c_slave",
+ .name = "I2CSlave",
.version_id = 1,
.minimum_version_id = 1,
.minimum_version_id_old = 1,
.post_load = i2c_slave_post_load,
.fields = (VMStateField []) {
- VMSTATE_UINT8(address, i2c_slave),
+ VMSTATE_UINT8(address, I2CSlave),
VMSTATE_END_OF_LIST()
}
};
@@ -170,7 +170,7 @@ const VMStateDescription vmstate_i2c_slave = {
static int i2c_slave_qdev_init(DeviceState *dev, DeviceInfo *base)
{
I2CSlaveInfo *info = container_of(base, I2CSlaveInfo, qdev);
- i2c_slave *s = I2C_SLAVE_FROM_QDEV(dev);
+ I2CSlave *s = I2C_SLAVE_FROM_QDEV(dev);
s->info = info;
@@ -179,7 +179,7 @@ static int i2c_slave_qdev_init(DeviceState *dev, DeviceInfo *base)
void i2c_register_slave(I2CSlaveInfo *info)
{
- assert(info->qdev.size >= sizeof(i2c_slave));
+ assert(info->qdev.size >= sizeof(I2CSlave));
info->qdev.init = i2c_slave_qdev_init;
info->qdev.bus_info = &i2c_bus_info;
qdev_register(&info->qdev);
diff --git a/hw/i2c.h b/hw/i2c.h
index 9381d01..28401f0 100644
--- a/hw/i2c.h
+++ b/hw/i2c.h
@@ -15,14 +15,16 @@ enum i2c_event {
I2C_NACK /* Masker NACKed a receive byte. */
};
+typedef struct I2CSlave I2CSlave;
+
/* Master to slave. */
-typedef int (*i2c_send_cb)(i2c_slave *s, uint8_t data);
+typedef int (*i2c_send_cb)(I2CSlave *s, uint8_t data);
/* Slave to master. */
-typedef int (*i2c_recv_cb)(i2c_slave *s);
+typedef int (*i2c_recv_cb)(I2CSlave *s);
/* Notify the slave of a bus state change. */
-typedef void (*i2c_event_cb)(i2c_slave *s, enum i2c_event event);
+typedef void (*i2c_event_cb)(I2CSlave *s, enum i2c_event event);
-typedef int (*i2c_slave_initfn)(i2c_slave *dev);
+typedef int (*i2c_slave_initfn)(I2CSlave *dev);
typedef struct {
DeviceInfo qdev;
@@ -34,7 +36,7 @@ typedef struct {
i2c_send_cb send;
} I2CSlaveInfo;
-struct i2c_slave
+struct I2CSlave
{
DeviceState qdev;
I2CSlaveInfo *info;
@@ -44,7 +46,7 @@ struct i2c_slave
};
i2c_bus *i2c_init_bus(DeviceState *parent, const char *name);
-void i2c_set_slave_address(i2c_slave *dev, uint8_t address);
+void i2c_set_slave_address(I2CSlave *dev, uint8_t address);
int i2c_bus_busy(i2c_bus *bus);
int i2c_start_transfer(i2c_bus *bus, uint8_t address, int recv);
void i2c_end_transfer(i2c_bus *bus);
@@ -52,7 +54,7 @@ void i2c_nack(i2c_bus *bus);
int i2c_send(i2c_bus *bus, uint8_t data);
int i2c_recv(i2c_bus *bus);
-#define I2C_SLAVE_FROM_QDEV(dev) DO_UPCAST(i2c_slave, qdev, dev)
+#define I2C_SLAVE_FROM_QDEV(dev) DO_UPCAST(I2CSlave, qdev, dev)
#define FROM_I2C_SLAVE(type, dev) DO_UPCAST(type, i2c, dev)
void i2c_register_slave(I2CSlaveInfo *type);
@@ -69,7 +71,7 @@ void wm8750_dac_commit(void *opaque);
void wm8750_set_bclk_in(void *opaque, int new_hz);
/* tmp105.c */
-void tmp105_set(i2c_slave *i2c, int temp);
+void tmp105_set(I2CSlave *i2c, int temp);
/* lm832x.c */
void lm832x_key_event(DeviceState *dev, int key, int state);
diff --git a/hw/lm832x.c b/hw/lm832x.c
index 992ce49..9e53cb3 100644
--- a/hw/lm832x.c
+++ b/hw/lm832x.c
@@ -24,7 +24,7 @@
#include "console.h"
typedef struct {
- i2c_slave i2c;
+ I2CSlave i2c;
uint8_t i2c_dir;
uint8_t i2c_cycle;
uint8_t reg;
@@ -378,7 +378,7 @@ static void lm_kbd_write(LM823KbdState *s, int reg, int byte, uint8_t value)
}
}
-static void lm_i2c_event(i2c_slave *i2c, enum i2c_event event)
+static void lm_i2c_event(I2CSlave *i2c, enum i2c_event event)
{
LM823KbdState *s = FROM_I2C_SLAVE(LM823KbdState, i2c);
@@ -394,14 +394,14 @@ static void lm_i2c_event(i2c_slave *i2c, enum i2c_event event)
}
}
-static int lm_i2c_rx(i2c_slave *i2c)
+static int lm_i2c_rx(I2CSlave *i2c)
{
LM823KbdState *s = FROM_I2C_SLAVE(LM823KbdState, i2c);
return lm_kbd_read(s, s->reg, s->i2c_cycle ++);
}
-static int lm_i2c_tx(i2c_slave *i2c, uint8_t data)
+static int lm_i2c_tx(I2CSlave *i2c, uint8_t data)
{
LM823KbdState *s = (LM823KbdState *) i2c;
@@ -458,7 +458,7 @@ static const VMStateDescription vmstate_lm_kbd = {
};
-static int lm8323_init(i2c_slave *i2c)
+static int lm8323_init(I2CSlave *i2c)
{
LM823KbdState *s = FROM_I2C_SLAVE(LM823KbdState, i2c);
diff --git a/hw/max7310.c b/hw/max7310.c
index c1bdb2e..a955236 100644
--- a/hw/max7310.c
+++ b/hw/max7310.c
@@ -10,7 +10,7 @@
#include "i2c.h"
typedef struct {
- i2c_slave i2c;
+ I2CSlave i2c;
int i2c_command_byte;
int len;
@@ -33,7 +33,7 @@ static void max7310_reset(DeviceState *dev)
s->command = 0x00;
}
-static int max7310_rx(i2c_slave *i2c)
+static int max7310_rx(I2CSlave *i2c)
{
MAX7310State *s = (MAX7310State *) i2c;
@@ -68,7 +68,7 @@ static int max7310_rx(i2c_slave *i2c)
return 0xff;
}
-static int max7310_tx(i2c_slave *i2c, uint8_t data)
+static int max7310_tx(I2CSlave *i2c, uint8_t data)
{
MAX7310State *s = (MAX7310State *) i2c;
uint8_t diff;
@@ -123,7 +123,7 @@ static int max7310_tx(i2c_slave *i2c, uint8_t data)
return 0;
}
-static void max7310_event(i2c_slave *i2c, enum i2c_event event)
+static void max7310_event(I2CSlave *i2c, enum i2c_event event)
{
MAX7310State *s = (MAX7310State *) i2c;
s->len = 0;
@@ -175,7 +175,7 @@ static void max7310_gpio_set(void *opaque, int line, int level)
/* MAX7310 is SMBus-compatible (can be used with only SMBus protocols),
* but also accepts sequences that are not SMBus so return an I2C device. */
-static int max7310_init(i2c_slave *i2c)
+static int max7310_init(I2CSlave *i2c)
{
MAX7310State *s = FROM_I2C_SLAVE(MAX7310State, i2c);
diff --git a/hw/pxa2xx.c b/hw/pxa2xx.c
index e9a507e..d18eb04 100644
--- a/hw/pxa2xx.c
+++ b/hw/pxa2xx.c
@@ -1243,7 +1243,7 @@ static SysBusDeviceInfo pxa2xx_rtc_sysbus_info = {
/* I2C Interface */
typedef struct {
- i2c_slave i2c;
+ I2CSlave i2c;
PXA2xxI2CState *host;
} PXA2xxI2CSlaveState;
@@ -1279,7 +1279,7 @@ static void pxa2xx_i2c_update(PXA2xxI2CState *s)
}
/* These are only stubs now. */
-static void pxa2xx_i2c_event(i2c_slave *i2c, enum i2c_event event)
+static void pxa2xx_i2c_event(I2CSlave *i2c, enum i2c_event event)
{
PXA2xxI2CSlaveState *slave = FROM_I2C_SLAVE(PXA2xxI2CSlaveState, i2c);
PXA2xxI2CState *s = slave->host;
@@ -1303,7 +1303,7 @@ static void pxa2xx_i2c_event(i2c_slave *i2c, enum i2c_event event)
pxa2xx_i2c_update(s);
}
-static int pxa2xx_i2c_rx(i2c_slave *i2c)
+static int pxa2xx_i2c_rx(I2CSlave *i2c)
{
PXA2xxI2CSlaveState *slave = FROM_I2C_SLAVE(PXA2xxI2CSlaveState, i2c);
PXA2xxI2CState *s = slave->host;
@@ -1318,7 +1318,7 @@ static int pxa2xx_i2c_rx(i2c_slave *i2c)
return s->data;
}
-static int pxa2xx_i2c_tx(i2c_slave *i2c, uint8_t data)
+static int pxa2xx_i2c_tx(I2CSlave *i2c, uint8_t data)
{
PXA2xxI2CSlaveState *slave = FROM_I2C_SLAVE(PXA2xxI2CSlaveState, i2c);
PXA2xxI2CState *s = slave->host;
@@ -1466,7 +1466,7 @@ static const VMStateDescription vmstate_pxa2xx_i2c = {
}
};
-static int pxa2xx_i2c_slave_init(i2c_slave *i2c)
+static int pxa2xx_i2c_slave_init(I2CSlave *i2c)
{
/* Nothing to do. */
return 0;
diff --git a/hw/smbus.c b/hw/smbus.c
index ff027c8..0cb3566 100644
--- a/hw/smbus.c
+++ b/hw/smbus.c
@@ -65,7 +65,7 @@ static void smbus_do_write(SMBusDevice *dev)
}
}
-static void smbus_i2c_event(i2c_slave *s, enum i2c_event event)
+static void smbus_i2c_event(I2CSlave *s, enum i2c_event event)
{
SMBusDevice *dev = FROM_I2C_SLAVE(SMBusDevice, s);
@@ -148,7 +148,7 @@ static void smbus_i2c_event(i2c_slave *s, enum i2c_event event)
}
}
-static int smbus_i2c_recv(i2c_slave *s)
+static int smbus_i2c_recv(I2CSlave *s)
{
SMBusDeviceInfo *t = container_of(s->info, SMBusDeviceInfo, i2c);
SMBusDevice *dev = FROM_I2C_SLAVE(SMBusDevice, s);
@@ -182,7 +182,7 @@ static int smbus_i2c_recv(i2c_slave *s)
return ret;
}
-static int smbus_i2c_send(i2c_slave *s, uint8_t data)
+static int smbus_i2c_send(I2CSlave *s, uint8_t data)
{
SMBusDevice *dev = FROM_I2C_SLAVE(SMBusDevice, s);
@@ -198,7 +198,7 @@ static int smbus_i2c_send(i2c_slave *s, uint8_t data)
return 0;
}
-static int smbus_device_init(i2c_slave *i2c)
+static int smbus_device_init(I2CSlave *i2c)
{
SMBusDeviceInfo *t = container_of(i2c->info, SMBusDeviceInfo, i2c);
SMBusDevice *dev = FROM_I2C_SLAVE(SMBusDevice, i2c);
diff --git a/hw/smbus.h b/hw/smbus.h
index a398715..2f2d49e 100644
--- a/hw/smbus.h
+++ b/hw/smbus.h
@@ -26,7 +26,7 @@
struct SMBusDevice {
/* The SMBus protocol is implemented on top of I2C. */
- i2c_slave i2c;
+ I2CSlave i2c;
/* Remaining fields for internal use only. */
int mode;
diff --git a/hw/spitz.c b/hw/spitz.c
index 23f9d41..31d17f2 100644
--- a/hw/spitz.c
+++ b/hw/spitz.c
@@ -714,7 +714,7 @@ static void spitz_microdrive_attach(PXA2xxState *cpu, int slot)
static void spitz_wm8750_addr(void *opaque, int line, int level)
{
- i2c_slave *wm = (i2c_slave *) opaque;
+ I2CSlave *wm = (I2CSlave *) opaque;
if (level)
i2c_set_slave_address(wm, SPITZ_WM_ADDRH);
else
diff --git a/hw/ssd0303.c b/hw/ssd0303.c
index 401fdf5..45ae513 100644
--- a/hw/ssd0303.c
+++ b/hw/ssd0303.c
@@ -42,7 +42,7 @@ enum ssd0303_cmd {
};
typedef struct {
- i2c_slave i2c;
+ I2CSlave i2c;
DisplayState *ds;
int row;
int col;
@@ -57,13 +57,13 @@ typedef struct {
uint8_t framebuffer[132*8];
} ssd0303_state;
-static int ssd0303_recv(i2c_slave *i2c)
+static int ssd0303_recv(I2CSlave *i2c)
{
BADF("Reads not implemented\n");
return -1;
}
-static int ssd0303_send(i2c_slave *i2c, uint8_t data)
+static int ssd0303_send(I2CSlave *i2c, uint8_t data)
{
ssd0303_state *s = (ssd0303_state *)i2c;
enum ssd0303_cmd old_cmd_state;
@@ -173,7 +173,7 @@ static int ssd0303_send(i2c_slave *i2c, uint8_t data)
return 0;
}
-static void ssd0303_event(i2c_slave *i2c, enum i2c_event event)
+static void ssd0303_event(I2CSlave *i2c, enum i2c_event event)
{
ssd0303_state *s = (ssd0303_state *)i2c;
switch (event) {
@@ -283,7 +283,7 @@ static const VMStateDescription vmstate_ssd0303 = {
}
};
-static int ssd0303_init(i2c_slave *i2c)
+static int ssd0303_init(I2CSlave *i2c)
{
ssd0303_state *s = FROM_I2C_SLAVE(ssd0303_state, i2c);
diff --git a/hw/tmp105.c b/hw/tmp105.c
index f7e6f2b..ed8a0f3 100644
--- a/hw/tmp105.c
+++ b/hw/tmp105.c
@@ -22,7 +22,7 @@
#include "i2c.h"
typedef struct {
- i2c_slave i2c;
+ I2CSlave i2c;
uint8_t len;
uint8_t buf[2];
qemu_irq pin;
@@ -65,7 +65,7 @@ static void tmp105_alarm_update(TMP105State *s)
}
/* Units are 0.001 centigrades relative to 0 C. */
-void tmp105_set(i2c_slave *i2c, int temp)
+void tmp105_set(I2CSlave *i2c, int temp)
{
TMP105State *s = (TMP105State *) i2c;
@@ -138,7 +138,7 @@ static void tmp105_write(TMP105State *s)
}
}
-static int tmp105_rx(i2c_slave *i2c)
+static int tmp105_rx(I2CSlave *i2c)
{
TMP105State *s = (TMP105State *) i2c;
@@ -148,7 +148,7 @@ static int tmp105_rx(i2c_slave *i2c)
return 0xff;
}
-static int tmp105_tx(i2c_slave *i2c, uint8_t data)
+static int tmp105_tx(I2CSlave *i2c, uint8_t data)
{
TMP105State *s = (TMP105State *) i2c;
@@ -163,7 +163,7 @@ static int tmp105_tx(i2c_slave *i2c, uint8_t data)
return 0;
}
-static void tmp105_event(i2c_slave *i2c, enum i2c_event event)
+static void tmp105_event(I2CSlave *i2c, enum i2c_event event)
{
TMP105State *s = (TMP105State *) i2c;
@@ -202,7 +202,7 @@ static const VMStateDescription vmstate_tmp105 = {
}
};
-static void tmp105_reset(i2c_slave *i2c)
+static void tmp105_reset(I2CSlave *i2c)
{
TMP105State *s = (TMP105State *) i2c;
@@ -215,7 +215,7 @@ static void tmp105_reset(i2c_slave *i2c)
tmp105_interrupt_update(s);
}
-static int tmp105_init(i2c_slave *i2c)
+static int tmp105_init(I2CSlave *i2c)
{
TMP105State *s = FROM_I2C_SLAVE(TMP105State, i2c);
diff --git a/hw/tosa.c b/hw/tosa.c
index b992b99..76c8629 100644
--- a/hw/tosa.c
+++ b/hw/tosa.c
@@ -130,12 +130,12 @@ static int tosa_ssp_init(SSISlave *dev)
}
typedef struct {
- i2c_slave i2c;
+ I2CSlave i2c;
int len;
char buf[3];
} TosaDACState;
-static int tosa_dac_send(i2c_slave *i2c, uint8_t data)
+static int tosa_dac_send(I2CSlave *i2c, uint8_t data)
{
TosaDACState *s = FROM_I2C_SLAVE(TosaDACState, i2c);
s->buf[s->len] = data;
@@ -154,7 +154,7 @@ static int tosa_dac_send(i2c_slave *i2c, uint8_t data)
return 0;
}
-static void tosa_dac_event(i2c_slave *i2c, enum i2c_event event)
+static void tosa_dac_event(I2CSlave *i2c, enum i2c_event event)
{
TosaDACState *s = FROM_I2C_SLAVE(TosaDACState, i2c);
s->len = 0;
@@ -177,13 +177,13 @@ static void tosa_dac_event(i2c_slave *i2c, enum i2c_event event)
}
}
-static int tosa_dac_recv(i2c_slave *s)
+static int tosa_dac_recv(I2CSlave *s)
{
printf("%s: recv not supported!!!\n", __FUNCTION__);
return -1;
}
-static int tosa_dac_init(i2c_slave *i2c)
+static int tosa_dac_init(I2CSlave *i2c)
{
/* Nothing to do. */
return 0;
diff --git a/hw/twl92230.c b/hw/twl92230.c
index a75448f..ced705c 100644
--- a/hw/twl92230.c
+++ b/hw/twl92230.c
@@ -27,7 +27,7 @@
#define VERBOSE 1
typedef struct {
- i2c_slave i2c;
+ I2CSlave i2c;
int firstbyte;
uint8_t reg;
@@ -126,7 +126,7 @@ static void menelaus_rtc_hz(void *opaque)
menelaus_update(s);
}
-static void menelaus_reset(i2c_slave *i2c)
+static void menelaus_reset(I2CSlave *i2c)
{
MenelausState *s = (MenelausState *) i2c;
s->reg = 0x00;
@@ -709,7 +709,7 @@ static void menelaus_write(void *opaque, uint8_t addr, uint8_t value)
}
}
-static void menelaus_event(i2c_slave *i2c, enum i2c_event event)
+static void menelaus_event(I2CSlave *i2c, enum i2c_event event)
{
MenelausState *s = (MenelausState *) i2c;
@@ -717,7 +717,7 @@ static void menelaus_event(i2c_slave *i2c, enum i2c_event event)
s->firstbyte = 1;
}
-static int menelaus_tx(i2c_slave *i2c, uint8_t data)
+static int menelaus_tx(I2CSlave *i2c, uint8_t data)
{
MenelausState *s = (MenelausState *) i2c;
/* Interpret register address byte */
@@ -730,7 +730,7 @@ static int menelaus_tx(i2c_slave *i2c, uint8_t data)
return 0;
}
-static int menelaus_rx(i2c_slave *i2c)
+static int menelaus_rx(I2CSlave *i2c)
{
MenelausState *s = (MenelausState *) i2c;
@@ -842,7 +842,7 @@ static const VMStateDescription vmstate_menelaus = {
}
};
-static int twl92230_init(i2c_slave *i2c)
+static int twl92230_init(I2CSlave *i2c)
{
MenelausState *s = FROM_I2C_SLAVE(MenelausState, i2c);
diff --git a/hw/wm8750.c b/hw/wm8750.c
index 39383f4..edb7dbf 100644
--- a/hw/wm8750.c
+++ b/hw/wm8750.c
@@ -24,7 +24,7 @@ typedef struct {
} WMRate;
typedef struct {
- i2c_slave i2c;
+ I2CSlave i2c;
uint8_t i2c_data[2];
int i2c_len;
QEMUSoundCard card;
@@ -254,7 +254,7 @@ static void wm8750_clk_update(WM8750State *s, int ext)
}
}
-static void wm8750_reset(i2c_slave *i2c)
+static void wm8750_reset(I2CSlave *i2c)
{
WM8750State *s = (WM8750State *) i2c;
s->rate = &wm_rate_table[0];
@@ -297,7 +297,7 @@ static void wm8750_reset(i2c_slave *i2c)
s->i2c_len = 0;
}
-static void wm8750_event(i2c_slave *i2c, enum i2c_event event)
+static void wm8750_event(I2CSlave *i2c, enum i2c_event event)
{
WM8750State *s = (WM8750State *) i2c;
@@ -354,7 +354,7 @@ static void wm8750_event(i2c_slave *i2c, enum i2c_event event)
#define WM8750_ROUT2V 0x29
#define WM8750_MOUTV 0x2a
-static int wm8750_tx(i2c_slave *i2c, uint8_t data)
+static int wm8750_tx(I2CSlave *i2c, uint8_t data)
{
WM8750State *s = (WM8750State *) i2c;
uint8_t cmd;
@@ -554,7 +554,7 @@ static int wm8750_tx(i2c_slave *i2c, uint8_t data)
return 0;
}
-static int wm8750_rx(i2c_slave *i2c)
+static int wm8750_rx(I2CSlave *i2c)
{
return 0x00;
}
@@ -609,7 +609,7 @@ static const VMStateDescription vmstate_wm8750 = {
}
};
-static int wm8750_init(i2c_slave *i2c)
+static int wm8750_init(I2CSlave *i2c)
{
WM8750State *s = FROM_I2C_SLAVE(WM8750State, i2c);
@@ -620,7 +620,7 @@ static int wm8750_init(i2c_slave *i2c)
}
#if 0
-static void wm8750_fini(i2c_slave *i2c)
+static void wm8750_fini(I2CSlave *i2c)
{
WM8750State *s = (WM8750State *) i2c;
wm8750_reset(&s->i2c);
diff --git a/hw/z2.c b/hw/z2.c
index a03bb33..5a70307 100644
--- a/hw/z2.c
+++ b/hw/z2.c
@@ -180,12 +180,12 @@ static SSISlaveInfo zipit_lcd_info = {
};
typedef struct {
- i2c_slave i2c;
+ I2CSlave i2c;
int len;
uint8_t buf[3];
} AER915State;
-static int aer915_send(i2c_slave *i2c, uint8_t data)
+static int aer915_send(I2CSlave *i2c, uint8_t data)
{
AER915State *s = FROM_I2C_SLAVE(AER915State, i2c);
s->buf[s->len] = data;
@@ -203,7 +203,7 @@ static int aer915_send(i2c_slave *i2c, uint8_t data)
return 0;
}
-static void aer915_event(i2c_slave *i2c, enum i2c_event event)
+static void aer915_event(I2CSlave *i2c, enum i2c_event event)
{
AER915State *s = FROM_I2C_SLAVE(AER915State, i2c);
switch (event) {
@@ -222,7 +222,7 @@ static void aer915_event(i2c_slave *i2c, enum i2c_event event)
}
}
-static int aer915_recv(i2c_slave *slave)
+static int aer915_recv(I2CSlave *slave)
{
int retval = 0x00;
AER915State *s = FROM_I2C_SLAVE(AER915State, slave);
@@ -245,7 +245,7 @@ static int aer915_recv(i2c_slave *slave)
return retval;
}
-static int aer915_init(i2c_slave *i2c)
+static int aer915_init(I2CSlave *i2c)
{
/* Nothing to do. */
return 0;
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 056/197] add I2CSlave to the type hierarchy
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (52 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 055/197] rename i2c_slave -> I2CSlave Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 057/197] add SMBusDevice to the type hiearchy Anthony Liguori
` (12 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/i2c.c | 15 +++++++++++++++
hw/i2c.h | 13 +++++++++++++
2 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/hw/i2c.c b/hw/i2c.c
index 9efe70c..cdf88f2 100644
--- a/hw/i2c.c
+++ b/hw/i2c.c
@@ -194,3 +194,18 @@ DeviceState *i2c_create_slave(i2c_bus *bus, const char *name, uint8_t addr)
qdev_init_nofail(dev);
return dev;
}
+
+static TypeInfo i2c_slave_type_info = {
+ .name = TYPE_I2C_SLAVE,
+ .parent = TYPE_DEVICE,
+ .instance_size = sizeof(I2CSlave),
+ .abstract = true,
+ .class_size = sizeof(I2CSlaveClass),
+};
+
+static void i2c_slave_register_devices(void)
+{
+ type_register_static(&i2c_slave_type_info);
+}
+
+device_init(i2c_slave_register_devices);
diff --git a/hw/i2c.h b/hw/i2c.h
index 28401f0..cc4d76b 100644
--- a/hw/i2c.h
+++ b/hw/i2c.h
@@ -26,6 +26,19 @@ typedef void (*i2c_event_cb)(I2CSlave *s, enum i2c_event event);
typedef int (*i2c_slave_initfn)(I2CSlave *dev);
+#define TYPE_I2C_SLAVE "i2c-slave"
+#define I2C_SLAVE(obj) \
+ OBJECT_CHECK(I2CSlave, (obj), TYPE_I2C_SLAVE)
+#define I2C_SLAVE_CLASS(klass) \
+ OBJECT_CLASS_CHECK(I2CSlaveClass, (klass), TYPE_I2C_SLAVE)
+#define I2C_SLAVE_GET_CLASS(obj) \
+ OBJECT_GET_CLASS(I2CSlaveClass, (obj), TYPE_I2C_SLAVE)
+
+typedef struct I2CSlaveClass
+{
+ DeviceClass parent_class;
+} I2CSlaveClass;
+
typedef struct {
DeviceInfo qdev;
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 057/197] add SMBusDevice to the type hiearchy
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (53 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 056/197] add I2CSlave to the type hierarchy Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 058/197] fixup type registration Anthony Liguori
` (11 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/smbus.c | 15 +++++++++++++++
hw/smbus.h | 13 +++++++++++++
2 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/hw/smbus.c b/hw/smbus.c
index 0cb3566..a75d404 100644
--- a/hw/smbus.c
+++ b/hw/smbus.c
@@ -316,3 +316,18 @@ void smbus_write_block(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t *dat
i2c_send(bus, data[i]);
i2c_end_transfer(bus);
}
+
+static TypeInfo smbus_device_type_info = {
+ .name = TYPE_SMBUS_DEVICE,
+ .parent = TYPE_I2C_SLAVE,
+ .instance_size = sizeof(SMBusDevice),
+ .abstract = true,
+ .class_size = sizeof(SMBusDeviceClass),
+};
+
+static void smbus_device_register_devices(void)
+{
+ type_register_static(&smbus_device_type_info);
+}
+
+device_init(smbus_device_register_devices);
diff --git a/hw/smbus.h b/hw/smbus.h
index 2f2d49e..9dd055c 100644
--- a/hw/smbus.h
+++ b/hw/smbus.h
@@ -24,6 +24,19 @@
#include "i2c.h"
+#define TYPE_SMBUS_DEVICE "smbus-device"
+#define SMBUS_DEVICE(obj) \
+ OBJECT_CHECK(SMBUSDevice, (obj), TYPE_SMBUS_DEVICE)
+#define SMBUS_DEVICE_CLASS(klass) \
+ OBJECT_CLASS_CHECK(SMBUSDeviceClass, (klass), TYPE_SMBUS_DEVICE)
+#define SMBUS_DEVICE_GET_CLASS(obj) \
+ OBJECT_GET_CLASS(SMBUSDeviceClass, (obj), TYPE_SMBUS_DEVICE)
+
+typedef struct SMBusDeviceClass
+{
+ I2CSlaveClass parent_class;
+} SMBusDeviceClass;
+
struct SMBusDevice {
/* The SMBus protocol is implemented on top of I2C. */
I2CSlave i2c;
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 058/197] fixup type registration
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (54 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 057/197] add SMBusDevice to the type hiearchy Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 059/197] kill off SMBusDeviceInfo Anthony Liguori
` (10 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/i2c.c | 9 +++++++--
hw/i2c.h | 1 +
hw/smbus.c | 2 +-
3 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/hw/i2c.c b/hw/i2c.c
index cdf88f2..fcb7269 100644
--- a/hw/i2c.c
+++ b/hw/i2c.c
@@ -177,12 +177,17 @@ static int i2c_slave_qdev_init(DeviceState *dev, DeviceInfo *base)
return info->init(s);
}
-void i2c_register_slave(I2CSlaveInfo *info)
+void i2c_register_slave_subclass(I2CSlaveInfo *info, const char *parent)
{
assert(info->qdev.size >= sizeof(I2CSlave));
info->qdev.init = i2c_slave_qdev_init;
info->qdev.bus_info = &i2c_bus_info;
- qdev_register(&info->qdev);
+ qdev_register_subclass(&info->qdev, parent);
+}
+
+void i2c_register_slave(I2CSlaveInfo *info)
+{
+ i2c_register_slave_subclass(info, TYPE_I2C_SLAVE);
}
DeviceState *i2c_create_slave(i2c_bus *bus, const char *name, uint8_t addr)
diff --git a/hw/i2c.h b/hw/i2c.h
index cc4d76b..0c6f2ac 100644
--- a/hw/i2c.h
+++ b/hw/i2c.h
@@ -71,6 +71,7 @@ int i2c_recv(i2c_bus *bus);
#define FROM_I2C_SLAVE(type, dev) DO_UPCAST(type, i2c, dev)
void i2c_register_slave(I2CSlaveInfo *type);
+void i2c_register_slave_subclass(I2CSlaveInfo *info, const char *parent);
DeviceState *i2c_create_slave(i2c_bus *bus, const char *name, uint8_t addr);
diff --git a/hw/smbus.c b/hw/smbus.c
index a75d404..2711229 100644
--- a/hw/smbus.c
+++ b/hw/smbus.c
@@ -213,7 +213,7 @@ void smbus_register_device(SMBusDeviceInfo *info)
info->i2c.event = smbus_i2c_event;
info->i2c.recv = smbus_i2c_recv;
info->i2c.send = smbus_i2c_send;
- i2c_register_slave(&info->i2c);
+ i2c_register_slave_subclass(&info->i2c, TYPE_SMBUS_DEVICE);
}
/* Master device commands. */
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 059/197] kill off SMBusDeviceInfo
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (55 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 058/197] fixup type registration Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 060/197] add guards Anthony Liguori
` (9 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/smbus.c | 55 +++++++++++++++++++++++++++--------------------------
hw/smbus.h | 35 +++++++++++++++------------------
hw/smbus_eeprom.c | 27 ++++++++++++++++---------
3 files changed, 61 insertions(+), 56 deletions(-)
diff --git a/hw/smbus.c b/hw/smbus.c
index 2711229..3f2d1f4 100644
--- a/hw/smbus.c
+++ b/hw/smbus.c
@@ -37,37 +37,38 @@ enum {
static void smbus_do_quick_cmd(SMBusDevice *dev, int recv)
{
- SMBusDeviceInfo *t = container_of(dev->i2c.info, SMBusDeviceInfo, i2c);
+ SMBusDeviceClass *sc = SMBUS_DEVICE_GET_CLASS(dev);
DPRINTF("Quick Command %d\n", recv);
- if (t->quick_cmd)
- t->quick_cmd(dev, recv);
+ if (sc->quick_cmd) {
+ sc->quick_cmd(dev, recv);
+ }
}
static void smbus_do_write(SMBusDevice *dev)
{
- SMBusDeviceInfo *t = container_of(dev->i2c.info, SMBusDeviceInfo, i2c);
+ SMBusDeviceClass *sc = SMBUS_DEVICE_GET_CLASS(dev);
if (dev->data_len == 0) {
smbus_do_quick_cmd(dev, 0);
} else if (dev->data_len == 1) {
DPRINTF("Send Byte\n");
- if (t->send_byte) {
- t->send_byte(dev, dev->data_buf[0]);
+ if (sc->send_byte) {
+ sc->send_byte(dev, dev->data_buf[0]);
}
} else {
dev->command = dev->data_buf[0];
DPRINTF("Command %d len %d\n", dev->command, dev->data_len - 1);
- if (t->write_data) {
- t->write_data(dev, dev->command, dev->data_buf + 1,
- dev->data_len - 1);
+ if (sc->write_data) {
+ sc->write_data(dev, dev->command, dev->data_buf + 1,
+ dev->data_len - 1);
}
}
}
static void smbus_i2c_event(I2CSlave *s, enum i2c_event event)
{
- SMBusDevice *dev = FROM_I2C_SLAVE(SMBusDevice, s);
+ SMBusDevice *dev = SMBUS_DEVICE(s);
switch (event) {
case I2C_START_SEND:
@@ -150,14 +151,14 @@ static void smbus_i2c_event(I2CSlave *s, enum i2c_event event)
static int smbus_i2c_recv(I2CSlave *s)
{
- SMBusDeviceInfo *t = container_of(s->info, SMBusDeviceInfo, i2c);
- SMBusDevice *dev = FROM_I2C_SLAVE(SMBusDevice, s);
+ SMBusDevice *dev = SMBUS_DEVICE(s);
+ SMBusDeviceClass *sc = SMBUS_DEVICE_GET_CLASS(dev);
int ret;
switch (dev->mode) {
case SMBUS_RECV_BYTE:
- if (t->receive_byte) {
- ret = t->receive_byte(dev);
+ if (sc->receive_byte) {
+ ret = sc->receive_byte(dev);
} else {
ret = 0;
}
@@ -165,8 +166,8 @@ static int smbus_i2c_recv(I2CSlave *s)
dev->mode = SMBUS_DONE;
break;
case SMBUS_READ_DATA:
- if (t->read_data) {
- ret = t->read_data(dev, dev->command, dev->data_len);
+ if (sc->read_data) {
+ ret = sc->read_data(dev, dev->command, dev->data_len);
dev->data_len++;
} else {
ret = 0;
@@ -184,7 +185,7 @@ static int smbus_i2c_recv(I2CSlave *s)
static int smbus_i2c_send(I2CSlave *s, uint8_t data)
{
- SMBusDevice *dev = FROM_I2C_SLAVE(SMBusDevice, s);
+ SMBusDevice *dev = SMBUS_DEVICE(s);
switch (dev->mode) {
case SMBUS_WRITE_DATA:
@@ -200,20 +201,20 @@ static int smbus_i2c_send(I2CSlave *s, uint8_t data)
static int smbus_device_init(I2CSlave *i2c)
{
- SMBusDeviceInfo *t = container_of(i2c->info, SMBusDeviceInfo, i2c);
- SMBusDevice *dev = FROM_I2C_SLAVE(SMBusDevice, i2c);
+ SMBusDevice *dev = SMBUS_DEVICE(i2c);
+ SMBusDeviceClass *sc = SMBUS_DEVICE_GET_CLASS(dev);
- return t->init(dev);
+ return sc->init(dev);
}
-void smbus_register_device(SMBusDeviceInfo *info)
+void smbus_register_device(I2CSlaveInfo *info)
{
- assert(info->i2c.qdev.size >= sizeof(SMBusDevice));
- info->i2c.init = smbus_device_init;
- info->i2c.event = smbus_i2c_event;
- info->i2c.recv = smbus_i2c_recv;
- info->i2c.send = smbus_i2c_send;
- i2c_register_slave_subclass(&info->i2c, TYPE_SMBUS_DEVICE);
+ assert(info->qdev.size >= sizeof(SMBusDevice));
+ info->init = smbus_device_init;
+ info->event = smbus_i2c_event;
+ info->recv = smbus_i2c_recv;
+ info->send = smbus_i2c_send;
+ i2c_register_slave_subclass(info, TYPE_SMBUS_DEVICE);
}
/* Master device commands. */
diff --git a/hw/smbus.h b/hw/smbus.h
index 9dd055c..fa9088a 100644
--- a/hw/smbus.h
+++ b/hw/smbus.h
@@ -26,30 +26,16 @@
#define TYPE_SMBUS_DEVICE "smbus-device"
#define SMBUS_DEVICE(obj) \
- OBJECT_CHECK(SMBUSDevice, (obj), TYPE_SMBUS_DEVICE)
+ OBJECT_CHECK(SMBusDevice, (obj), TYPE_SMBUS_DEVICE)
#define SMBUS_DEVICE_CLASS(klass) \
- OBJECT_CLASS_CHECK(SMBUSDeviceClass, (klass), TYPE_SMBUS_DEVICE)
+ OBJECT_CLASS_CHECK(SMBusDeviceClass, (klass), TYPE_SMBUS_DEVICE)
#define SMBUS_DEVICE_GET_CLASS(obj) \
- OBJECT_GET_CLASS(SMBUSDeviceClass, (obj), TYPE_SMBUS_DEVICE)
+ OBJECT_GET_CLASS(SMBusDeviceClass, (obj), TYPE_SMBUS_DEVICE)
typedef struct SMBusDeviceClass
{
I2CSlaveClass parent_class;
-} SMBusDeviceClass;
-
-struct SMBusDevice {
- /* The SMBus protocol is implemented on top of I2C. */
- I2CSlave i2c;
-
- /* Remaining fields for internal use only. */
- int mode;
- int data_len;
- uint8_t data_buf[34]; /* command + len + 32 bytes of data. */
- uint8_t command;
-};
-typedef struct {
- I2CSlaveInfo i2c;
int (*init)(SMBusDevice *dev);
void (*quick_cmd)(SMBusDevice *dev, uint8_t read);
void (*send_byte)(SMBusDevice *dev, uint8_t val);
@@ -64,9 +50,20 @@ typedef struct {
byte at a time. The device is responsible for adding the length
byte on block reads. */
uint8_t (*read_data)(SMBusDevice *dev, uint8_t cmd, int n);
-} SMBusDeviceInfo;
+} SMBusDeviceClass;
+
+struct SMBusDevice {
+ /* The SMBus protocol is implemented on top of I2C. */
+ I2CSlave i2c;
+
+ /* Remaining fields for internal use only. */
+ int mode;
+ int data_len;
+ uint8_t data_buf[34]; /* command + len + 32 bytes of data. */
+ uint8_t command;
+};
-void smbus_register_device(SMBusDeviceInfo *info);
+void smbus_register_device(I2CSlaveInfo *info);
/* Master device commands. */
void smbus_quick_command(i2c_bus *bus, uint8_t addr, int read);
diff --git a/hw/smbus_eeprom.c b/hw/smbus_eeprom.c
index 5d080ab..2e8329f 100644
--- a/hw/smbus_eeprom.c
+++ b/hw/smbus_eeprom.c
@@ -104,19 +104,26 @@ static int smbus_eeprom_initfn(SMBusDevice *dev)
return 0;
}
-static SMBusDeviceInfo smbus_eeprom_info = {
- .i2c.qdev.name = "smbus-eeprom",
- .i2c.qdev.size = sizeof(SMBusEEPROMDevice),
- .i2c.qdev.props = (Property[]) {
+static void smbus_eeprom_class_initfn(ObjectClass *klass, void *data)
+{
+ SMBusDeviceClass *sc = SMBUS_DEVICE_CLASS(klass);
+
+ sc->init = smbus_eeprom_initfn;
+ sc->quick_cmd = eeprom_quick_cmd;
+ sc->send_byte = eeprom_send_byte;
+ sc->receive_byte = eeprom_receive_byte;
+ sc->write_data = eeprom_write_data;
+ sc->read_data = eeprom_read_data;
+}
+
+static I2CSlaveInfo smbus_eeprom_info = {
+ .qdev.name = "smbus-eeprom",
+ .qdev.size = sizeof(SMBusEEPROMDevice),
+ .qdev.class_init = smbus_eeprom_class_initfn,
+ .qdev.props = (Property[]) {
DEFINE_PROP_PTR("data", SMBusEEPROMDevice, data),
DEFINE_PROP_END_OF_LIST(),
},
- .init = smbus_eeprom_initfn,
- .quick_cmd = eeprom_quick_cmd,
- .send_byte = eeprom_send_byte,
- .receive_byte = eeprom_receive_byte,
- .write_data = eeprom_write_data,
- .read_data = eeprom_read_data
};
static void smbus_eeprom_register_devices(void)
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 060/197] add guards
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (56 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 059/197] kill off SMBusDeviceInfo Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 061/197] killall I2CSlaveInfo Anthony Liguori
` (8 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/smbus.h | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/hw/smbus.h b/hw/smbus.h
index fa9088a..7fa63f9 100644
--- a/hw/smbus.h
+++ b/hw/smbus.h
@@ -1,3 +1,6 @@
+#ifndef QEMU_SMBUS_H
+#define QEMU_SMBUS_H
+
/*
* QEMU SMBus API
*
@@ -79,3 +82,5 @@ void smbus_write_block(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t *dat
void smbus_eeprom_init(i2c_bus *smbus, int nb_eeprom,
const uint8_t *eeprom_spd, int size);
+
+#endif
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 061/197] killall I2CSlaveInfo
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (57 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 060/197] add guards Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 062/197] killall HDACodecDeviceInfo Anthony Liguori
` (7 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
This was partially written by the Patch Monkey.
---
hw/ds1338.c | 21 +++++++++++-----
hw/i2c.c | 67 +++++++++++++++++++++++++++++++++++++---------------
hw/i2c.h | 34 ++++++++++----------------
hw/lm832x.c | 23 ++++++++++++------
hw/max7310.c | 25 ++++++++++++-------
hw/pxa2xx.c | 21 +++++++++++-----
hw/smbus.c | 19 ++++++++++----
hw/smbus.h | 2 +-
hw/smbus_eeprom.c | 10 ++++----
hw/ssd0303.c | 23 ++++++++++++------
hw/tmp105.c | 23 ++++++++++++------
hw/tosa.c | 21 +++++++++++-----
hw/twl92230.c | 23 ++++++++++++------
hw/wm8750.c | 23 ++++++++++++------
hw/z2.c | 23 ++++++++++++------
15 files changed, 227 insertions(+), 131 deletions(-)
diff --git a/hw/ds1338.c b/hw/ds1338.c
index 88d6d18..d604f82 100644
--- a/hw/ds1338.c
+++ b/hw/ds1338.c
@@ -115,13 +115,20 @@ static int ds1338_init(I2CSlave *i2c)
return 0;
}
-static I2CSlaveInfo ds1338_info = {
- .qdev.name = "ds1338",
- .qdev.size = sizeof(DS1338State),
- .init = ds1338_init,
- .event = ds1338_event,
- .recv = ds1338_recv,
- .send = ds1338_send,
+static void ds1338_class_init(ObjectClass *klass, void *data)
+{
+ I2CSlaveClass *k = I2C_SLAVE_INFO(klass);
+
+ k->init = ds1338_init;
+ k->event = ds1338_event;
+ k->recv = ds1338_recv;
+ k->send = ds1338_send;
+}
+
+static DeviceInfo ds1338_info = {
+ .name = "ds1338",
+ .size = sizeof(DS1338State),
+ .class_init = ds1338_class_init,
};
static void ds1338_register_devices(void)
diff --git a/hw/i2c.c b/hw/i2c.c
index fcb7269..9e5d3df 100644
--- a/hw/i2c.c
+++ b/hw/i2c.c
@@ -83,6 +83,7 @@ int i2c_start_transfer(i2c_bus *bus, uint8_t address, int recv)
{
DeviceState *qdev;
I2CSlave *slave = NULL;
+ I2CSlaveClass *sc;
QTAILQ_FOREACH(qdev, &bus->qbus.children, sibling) {
I2CSlave *candidate = I2C_SLAVE_FROM_QDEV(qdev);
@@ -92,24 +93,33 @@ int i2c_start_transfer(i2c_bus *bus, uint8_t address, int recv)
}
}
- if (!slave)
+ if (!slave) {
return 1;
+ }
+ sc = I2C_SLAVE_GET_CLASS(slave);
/* If the bus is already busy, assume this is a repeated
start condition. */
bus->current_dev = slave;
- slave->info->event(slave, recv ? I2C_START_RECV : I2C_START_SEND);
+ if (sc->event) {
+ sc->event(slave, recv ? I2C_START_RECV : I2C_START_SEND);
+ }
return 0;
}
void i2c_end_transfer(i2c_bus *bus)
{
I2CSlave *dev = bus->current_dev;
+ I2CSlaveClass *sc;
- if (!dev)
+ if (!dev) {
return;
+ }
- dev->info->event(dev, I2C_FINISH);
+ sc = I2C_SLAVE_GET_CLASS(dev);
+ if (sc->event) {
+ sc->event(dev, I2C_FINISH);
+ }
bus->current_dev = NULL;
}
@@ -117,31 +127,50 @@ void i2c_end_transfer(i2c_bus *bus)
int i2c_send(i2c_bus *bus, uint8_t data)
{
I2CSlave *dev = bus->current_dev;
+ I2CSlaveClass *sc;
- if (!dev)
+ if (!dev) {
return -1;
+ }
+
+ sc = I2C_SLAVE_GET_CLASS(dev);
+ if (sc->send) {
+ return sc->send(dev, data);
+ }
- return dev->info->send(dev, data);
+ return -1;
}
int i2c_recv(i2c_bus *bus)
{
I2CSlave *dev = bus->current_dev;
+ I2CSlaveClass *sc;
- if (!dev)
+ if (!dev) {
return -1;
+ }
+
+ sc = I2C_SLAVE_GET_CLASS(dev);
+ if (sc->recv) {
+ return sc->recv(dev);
+ }
- return dev->info->recv(dev);
+ return -1;
}
void i2c_nack(i2c_bus *bus)
{
I2CSlave *dev = bus->current_dev;
+ I2CSlaveClass *sc;
- if (!dev)
+ if (!dev) {
return;
+ }
- dev->info->event(dev, I2C_NACK);
+ sc = I2C_SLAVE_GET_CLASS(dev);
+ if (sc->event) {
+ sc->event(dev, I2C_NACK);
+ }
}
static int i2c_slave_post_load(void *opaque, int version_id)
@@ -169,23 +198,21 @@ const VMStateDescription vmstate_i2c_slave = {
static int i2c_slave_qdev_init(DeviceState *dev, DeviceInfo *base)
{
- I2CSlaveInfo *info = container_of(base, I2CSlaveInfo, qdev);
I2CSlave *s = I2C_SLAVE_FROM_QDEV(dev);
+ I2CSlaveClass *sc = I2C_SLAVE_GET_CLASS(s);
- s->info = info;
-
- return info->init(s);
+ return sc->init(s);
}
-void i2c_register_slave_subclass(I2CSlaveInfo *info, const char *parent)
+void i2c_register_slave_subclass(DeviceInfo *info, const char *parent)
{
- assert(info->qdev.size >= sizeof(I2CSlave));
- info->qdev.init = i2c_slave_qdev_init;
- info->qdev.bus_info = &i2c_bus_info;
- qdev_register_subclass(&info->qdev, parent);
+ assert(info->size >= sizeof(I2CSlave));
+ info->init = i2c_slave_qdev_init;
+ info->bus_info = &i2c_bus_info;
+ qdev_register_subclass(info, parent);
}
-void i2c_register_slave(I2CSlaveInfo *info)
+void i2c_register_slave(DeviceInfo *info)
{
i2c_register_slave_subclass(info, TYPE_I2C_SLAVE);
}
diff --git a/hw/i2c.h b/hw/i2c.h
index 0c6f2ac..178351a 100644
--- a/hw/i2c.h
+++ b/hw/i2c.h
@@ -17,15 +17,6 @@ enum i2c_event {
typedef struct I2CSlave I2CSlave;
-/* Master to slave. */
-typedef int (*i2c_send_cb)(I2CSlave *s, uint8_t data);
-/* Slave to master. */
-typedef int (*i2c_recv_cb)(I2CSlave *s);
-/* Notify the slave of a bus state change. */
-typedef void (*i2c_event_cb)(I2CSlave *s, enum i2c_event event);
-
-typedef int (*i2c_slave_initfn)(I2CSlave *dev);
-
#define TYPE_I2C_SLAVE "i2c-slave"
#define I2C_SLAVE(obj) \
OBJECT_CHECK(I2CSlave, (obj), TYPE_I2C_SLAVE)
@@ -37,22 +28,23 @@ typedef int (*i2c_slave_initfn)(I2CSlave *dev);
typedef struct I2CSlaveClass
{
DeviceClass parent_class;
-} I2CSlaveClass;
-
-typedef struct {
- DeviceInfo qdev;
/* Callbacks provided by the device. */
- i2c_slave_initfn init;
- i2c_event_cb event;
- i2c_recv_cb recv;
- i2c_send_cb send;
-} I2CSlaveInfo;
+ int (*init)(I2CSlave *dev);
+
+ /* Master to slave. */
+ int (*send)(I2CSlave *s, uint8_t data);
+
+ /* Slave to master. */
+ int (*recv)(I2CSlave *s);
+
+ /* Notify the slave of a bus state change. */
+ void (*event)(I2CSlave *s, enum i2c_event event);
+} I2CSlaveClass;
struct I2CSlave
{
DeviceState qdev;
- I2CSlaveInfo *info;
/* Remaining fields for internal use by the I2C code. */
uint8_t address;
@@ -70,8 +62,8 @@ int i2c_recv(i2c_bus *bus);
#define I2C_SLAVE_FROM_QDEV(dev) DO_UPCAST(I2CSlave, qdev, dev)
#define FROM_I2C_SLAVE(type, dev) DO_UPCAST(type, i2c, dev)
-void i2c_register_slave(I2CSlaveInfo *type);
-void i2c_register_slave_subclass(I2CSlaveInfo *info, const char *parent);
+void i2c_register_slave(DeviceInfo *type);
+void i2c_register_slave_subclass(DeviceInfo *info, const char *parent);
DeviceState *i2c_create_slave(i2c_bus *bus, const char *name, uint8_t addr);
diff --git a/hw/lm832x.c b/hw/lm832x.c
index 9e53cb3..49a0873 100644
--- a/hw/lm832x.c
+++ b/hw/lm832x.c
@@ -494,14 +494,21 @@ void lm832x_key_event(DeviceState *dev, int key, int state)
lm_kbd_irq_update(s);
}
-static I2CSlaveInfo lm8323_info = {
- .qdev.name = "lm8323",
- .qdev.size = sizeof(LM823KbdState),
- .qdev.vmsd = &vmstate_lm_kbd,
- .init = lm8323_init,
- .event = lm_i2c_event,
- .recv = lm_i2c_rx,
- .send = lm_i2c_tx
+static void lm8323_class_init(ObjectClass *klass, void *data)
+{
+ I2CSlaveClass *k = I2C_SLAVE_INFO(klass);
+
+ k->init = lm8323_init;
+ k->event = lm_i2c_event;
+ k->recv = lm_i2c_rx;
+ k->send = lm_i2c_tx;
+}
+
+static DeviceInfo lm8323_info = {
+ .name = "lm8323",
+ .size = sizeof(LM823KbdState),
+ .vmsd = &vmstate_lm_kbd,
+ .class_init = lm8323_class_init,
};
static void lm832x_register_devices(void)
diff --git a/hw/max7310.c b/hw/max7310.c
index a955236..2615c77 100644
--- a/hw/max7310.c
+++ b/hw/max7310.c
@@ -185,15 +185,22 @@ static int max7310_init(I2CSlave *i2c)
return 0;
}
-static I2CSlaveInfo max7310_info = {
- .qdev.name = "max7310",
- .qdev.size = sizeof(MAX7310State),
- .qdev.vmsd = &vmstate_max7310,
- .qdev.reset = max7310_reset,
- .init = max7310_init,
- .event = max7310_event,
- .recv = max7310_rx,
- .send = max7310_tx
+static void max7310_class_init(ObjectClass *klass, void *data)
+{
+ I2CSlaveClass *k = I2C_SLAVE_INFO(klass);
+
+ k->init = max7310_init;
+ k->event = max7310_event;
+ k->recv = max7310_rx;
+ k->send = max7310_tx;
+}
+
+static DeviceInfo max7310_info = {
+ .name = "max7310",
+ .size = sizeof(MAX7310State),
+ .vmsd = &vmstate_max7310,
+ .reset = max7310_reset,
+ .class_init = max7310_class_init,
};
static void max7310_register_devices(void)
diff --git a/hw/pxa2xx.c b/hw/pxa2xx.c
index d18eb04..903f798 100644
--- a/hw/pxa2xx.c
+++ b/hw/pxa2xx.c
@@ -1472,13 +1472,20 @@ static int pxa2xx_i2c_slave_init(I2CSlave *i2c)
return 0;
}
-static I2CSlaveInfo pxa2xx_i2c_slave_info = {
- .qdev.name = "pxa2xx-i2c-slave",
- .qdev.size = sizeof(PXA2xxI2CSlaveState),
- .init = pxa2xx_i2c_slave_init,
- .event = pxa2xx_i2c_event,
- .recv = pxa2xx_i2c_rx,
- .send = pxa2xx_i2c_tx
+static void pxa2xx_i2c_slave_class_init(ObjectClass *klass, void *data)
+{
+ I2CSlaveClass *k = I2C_SLAVE_INFO(klass);
+
+ k->init = pxa2xx_i2c_slave_init;
+ k->event = pxa2xx_i2c_event;
+ k->recv = pxa2xx_i2c_rx;
+ k->send = pxa2xx_i2c_tx;
+}
+
+static DeviceInfo pxa2xx_i2c_slave_info = {
+ .name = "pxa2xx-i2c-slave",
+ .size = sizeof(PXA2xxI2CSlaveState),
+ .class_init = pxa2xx_i2c_slave_class_init,
};
PXA2xxI2CState *pxa2xx_i2c_init(target_phys_addr_t base,
diff --git a/hw/smbus.c b/hw/smbus.c
index 3f2d1f4..ed31a59 100644
--- a/hw/smbus.c
+++ b/hw/smbus.c
@@ -207,13 +207,9 @@ static int smbus_device_init(I2CSlave *i2c)
return sc->init(dev);
}
-void smbus_register_device(I2CSlaveInfo *info)
+void smbus_register_device(DeviceInfo *info)
{
- assert(info->qdev.size >= sizeof(SMBusDevice));
- info->init = smbus_device_init;
- info->event = smbus_i2c_event;
- info->recv = smbus_i2c_recv;
- info->send = smbus_i2c_send;
+ assert(info->size >= sizeof(SMBusDevice));
i2c_register_slave_subclass(info, TYPE_SMBUS_DEVICE);
}
@@ -318,12 +314,23 @@ void smbus_write_block(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t *dat
i2c_end_transfer(bus);
}
+static void smbus_device_class_init(ObjectClass *klass, void *data)
+{
+ I2CSlaveClass *sc = I2C_SLAVE_CLASS(klass);
+
+ sc->init = smbus_device_init;
+ sc->event = smbus_i2c_event;
+ sc->recv = smbus_i2c_recv;
+ sc->send = smbus_i2c_send;
+}
+
static TypeInfo smbus_device_type_info = {
.name = TYPE_SMBUS_DEVICE,
.parent = TYPE_I2C_SLAVE,
.instance_size = sizeof(SMBusDevice),
.abstract = true,
.class_size = sizeof(SMBusDeviceClass),
+ .class_init = smbus_device_class_init,
};
static void smbus_device_register_devices(void)
diff --git a/hw/smbus.h b/hw/smbus.h
index 7fa63f9..5f01f5d 100644
--- a/hw/smbus.h
+++ b/hw/smbus.h
@@ -66,7 +66,7 @@ struct SMBusDevice {
uint8_t command;
};
-void smbus_register_device(I2CSlaveInfo *info);
+void smbus_register_device(DeviceInfo *info);
/* Master device commands. */
void smbus_quick_command(i2c_bus *bus, uint8_t addr, int read);
diff --git a/hw/smbus_eeprom.c b/hw/smbus_eeprom.c
index 2e8329f..401dff5 100644
--- a/hw/smbus_eeprom.c
+++ b/hw/smbus_eeprom.c
@@ -116,11 +116,11 @@ static void smbus_eeprom_class_initfn(ObjectClass *klass, void *data)
sc->read_data = eeprom_read_data;
}
-static I2CSlaveInfo smbus_eeprom_info = {
- .qdev.name = "smbus-eeprom",
- .qdev.size = sizeof(SMBusEEPROMDevice),
- .qdev.class_init = smbus_eeprom_class_initfn,
- .qdev.props = (Property[]) {
+static DeviceInfo smbus_eeprom_info = {
+ .name = "smbus-eeprom",
+ .size = sizeof(SMBusEEPROMDevice),
+ .class_init = smbus_eeprom_class_initfn,
+ .props = (Property[]) {
DEFINE_PROP_PTR("data", SMBusEEPROMDevice, data),
DEFINE_PROP_END_OF_LIST(),
},
diff --git a/hw/ssd0303.c b/hw/ssd0303.c
index 45ae513..ec77978 100644
--- a/hw/ssd0303.c
+++ b/hw/ssd0303.c
@@ -294,14 +294,21 @@ static int ssd0303_init(I2CSlave *i2c)
return 0;
}
-static I2CSlaveInfo ssd0303_info = {
- .qdev.name = "ssd0303",
- .qdev.size = sizeof(ssd0303_state),
- .qdev.vmsd = &vmstate_ssd0303,
- .init = ssd0303_init,
- .event = ssd0303_event,
- .recv = ssd0303_recv,
- .send = ssd0303_send
+static void ssd0303_class_init(ObjectClass *klass, void *data)
+{
+ I2CSlaveClass *k = I2C_SLAVE_INFO(klass);
+
+ k->init = ssd0303_init;
+ k->event = ssd0303_event;
+ k->recv = ssd0303_recv;
+ k->send = ssd0303_send;
+}
+
+static DeviceInfo ssd0303_info = {
+ .name = "ssd0303",
+ .size = sizeof(ssd0303_state),
+ .vmsd = &vmstate_ssd0303,
+ .class_init = ssd0303_class_init,
};
static void ssd0303_register_devices(void)
diff --git a/hw/tmp105.c b/hw/tmp105.c
index ed8a0f3..a9181bd 100644
--- a/hw/tmp105.c
+++ b/hw/tmp105.c
@@ -226,14 +226,21 @@ static int tmp105_init(I2CSlave *i2c)
return 0;
}
-static I2CSlaveInfo tmp105_info = {
- .qdev.name = "tmp105",
- .qdev.size = sizeof(TMP105State),
- .qdev.vmsd = &vmstate_tmp105,
- .init = tmp105_init,
- .event = tmp105_event,
- .recv = tmp105_rx,
- .send = tmp105_tx
+static void tmp105_class_init(ObjectClass *klass, void *data)
+{
+ I2CSlaveClass *k = I2C_SLAVE_INFO(klass);
+
+ k->init = tmp105_init;
+ k->event = tmp105_event;
+ k->recv = tmp105_rx;
+ k->send = tmp105_tx;
+}
+
+static DeviceInfo tmp105_info = {
+ .name = "tmp105",
+ .size = sizeof(TMP105State),
+ .vmsd = &vmstate_tmp105,
+ .class_init = tmp105_class_init,
};
static void tmp105_register_devices(void)
diff --git a/hw/tosa.c b/hw/tosa.c
index 76c8629..2a305cf 100644
--- a/hw/tosa.c
+++ b/hw/tosa.c
@@ -253,13 +253,20 @@ static void tosapda_machine_init(void)
machine_init(tosapda_machine_init);
-static I2CSlaveInfo tosa_dac_info = {
- .qdev.name = "tosa_dac",
- .qdev.size = sizeof(TosaDACState),
- .init = tosa_dac_init,
- .event = tosa_dac_event,
- .recv = tosa_dac_recv,
- .send = tosa_dac_send
+static void tosa_dac_class_init(ObjectClass *klass, void *data)
+{
+ I2CSlaveClass *k = I2C_SLAVE_INFO(klass);
+
+ k->init = tosa_dac_init;
+ k->event = tosa_dac_event;
+ k->recv = tosa_dac_recv;
+ k->send = tosa_dac_send;
+}
+
+static DeviceInfo tosa_dac_info = {
+ .name = "tosa_dac",
+ .size = sizeof(TosaDACState),
+ .class_init = tosa_dac_class_init,
};
static SSISlaveInfo tosa_ssp_info = {
diff --git a/hw/twl92230.c b/hw/twl92230.c
index ced705c..ba4f8aa 100644
--- a/hw/twl92230.c
+++ b/hw/twl92230.c
@@ -857,14 +857,21 @@ static int twl92230_init(I2CSlave *i2c)
return 0;
}
-static I2CSlaveInfo twl92230_info = {
- .qdev.name ="twl92230",
- .qdev.size = sizeof(MenelausState),
- .qdev.vmsd = &vmstate_menelaus,
- .init = twl92230_init,
- .event = menelaus_event,
- .recv = menelaus_rx,
- .send = menelaus_tx
+static void twl92230_class_init(ObjectClass *klass, void *data)
+{
+ I2CSlaveClass *sc = I2C_SLAVE_CLASS(klass);
+
+ sc->init = twl92230_init;
+ sc->event = menelaus_event;
+ sc->recv = menelaus_rx;
+ sc->send = menelaus_tx;
+}
+
+static DeviceInfo twl92230_info = {
+ .name ="twl92230",
+ .size = sizeof(MenelausState),
+ .vmsd = &vmstate_menelaus,
+ .class_init = twl92230_class_init,
};
static void twl92230_register_devices(void)
diff --git a/hw/wm8750.c b/hw/wm8750.c
index edb7dbf..31e48f3 100644
--- a/hw/wm8750.c
+++ b/hw/wm8750.c
@@ -689,14 +689,21 @@ void wm8750_set_bclk_in(void *opaque, int new_hz)
wm8750_clk_update(s, 1);
}
-static I2CSlaveInfo wm8750_info = {
- .qdev.name = "wm8750",
- .qdev.size = sizeof(WM8750State),
- .qdev.vmsd = &vmstate_wm8750,
- .init = wm8750_init,
- .event = wm8750_event,
- .recv = wm8750_rx,
- .send = wm8750_tx
+static void wm8750_class_init(ObjectClass *klass, void *data)
+{
+ I2CSlaveClass *sc = I2C_SLAVE_CLASS(klass);
+
+ sc->init = wm8750_init;
+ sc->event = wm8750_event;
+ sc->recv = wm8750_rx;
+ sc->send = wm8750_tx;
+}
+
+static DeviceInfo wm8750_info = {
+ .name = "wm8750",
+ .size = sizeof(WM8750State),
+ .vmsd = &vmstate_wm8750,
+ .class_init = wm8750_class_init,
};
static void wm8750_register_devices(void)
diff --git a/hw/z2.c b/hw/z2.c
index 5a70307..10f929a 100644
--- a/hw/z2.c
+++ b/hw/z2.c
@@ -263,14 +263,21 @@ static VMStateDescription vmstate_aer915_state = {
}
};
-static I2CSlaveInfo aer915_info = {
- .qdev.name = "aer915",
- .qdev.size = sizeof(AER915State),
- .qdev.vmsd = &vmstate_aer915_state,
- .init = aer915_init,
- .event = aer915_event,
- .recv = aer915_recv,
- .send = aer915_send
+static void aer915_class_init(ObjectClass *klass, void *data)
+{
+ I2CSlaveClass *sc = I2C_SLAVE_CLASS(klass);
+
+ sc->init = aer915_init;
+ sc->event = aer915_event;
+ sc->recv = aer915_recv;
+ sc->send = aer915_send;
+}
+
+static DeviceInfo aer915_info = {
+ .name = "aer915",
+ .size = sizeof(AER915State),
+ .vmsd = &vmstate_aer915_state,
+ .class_init = aer915_class_init,
};
static void z2_init(ram_addr_t ram_size,
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 062/197] killall HDACodecDeviceInfo
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (58 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 061/197] killall I2CSlaveInfo Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 063/197] make spapr a bit more patch monkey friendly Anthony Liguori
` (6 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/hda-audio.c | 58 ++++++++++++++++++++++++++++++++++---------------------
hw/intel-hda.c | 43 +++++++++++++++++++++++++++--------------
hw/intel-hda.h | 26 ++++++++++++++++--------
3 files changed, 81 insertions(+), 46 deletions(-)
diff --git a/hw/hda-audio.c b/hw/hda-audio.c
index ffdd799..71831a3 100644
--- a/hw/hda-audio.c
+++ b/hw/hda-audio.c
@@ -906,33 +906,47 @@ static int hda_audio_init_duplex(HDACodecDevice *hda)
return hda_audio_init(hda, &duplex);
}
-static HDACodecDeviceInfo hda_audio_info_output = {
- .qdev.name = "hda-output",
- .qdev.desc = "HDA Audio Codec, output-only",
- .qdev.size = sizeof(HDAAudioState),
- .qdev.vmsd = &vmstate_hda_audio,
- .qdev.props = hda_audio_properties,
- .init = hda_audio_init_output,
- .exit = hda_audio_exit,
- .command = hda_audio_command,
- .stream = hda_audio_stream,
+static void hda_audio_output_class_init(ObjectClass *klass, void *data)
+{
+ HDACodecDeviceClass *k = HDA_CODEC_DEVICE_CLASS(klass);
+
+ k->init = hda_audio_init_output;
+ k->exit = hda_audio_exit;
+ k->command = hda_audio_command;
+ k->stream = hda_audio_stream;
+}
+
+static DeviceInfo hda_audio_output_info = {
+ .name = "hda-output",
+ .desc = "HDA Audio Codec, output-only",
+ .size = sizeof(HDAAudioState),
+ .vmsd = &vmstate_hda_audio,
+ .props = hda_audio_properties,
+ .class_init = hda_audio_output_class_init,
};
-static HDACodecDeviceInfo hda_audio_info_duplex = {
- .qdev.name = "hda-duplex",
- .qdev.desc = "HDA Audio Codec, duplex",
- .qdev.size = sizeof(HDAAudioState),
- .qdev.vmsd = &vmstate_hda_audio,
- .qdev.props = hda_audio_properties,
- .init = hda_audio_init_duplex,
- .exit = hda_audio_exit,
- .command = hda_audio_command,
- .stream = hda_audio_stream,
+static void hda_audio_duplex_class_init(ObjectClass *klass, void *data)
+{
+ HDACodecDeviceClass *k = HDA_CODEC_DEVICE_CLASS(klass);
+
+ k->init = hda_audio_init_duplex;
+ k->exit = hda_audio_exit;
+ k->command = hda_audio_command;
+ k->stream = hda_audio_stream;
+}
+
+static DeviceInfo hda_audio_duplex_info = {
+ .name = "hda-duplex",
+ .desc = "HDA Audio Codec, duplex",
+ .size = sizeof(HDAAudioState),
+ .vmsd = &vmstate_hda_audio,
+ .props = hda_audio_properties,
+ .class_init = hda_audio_duplex_class_init,
};
static void hda_audio_register(void)
{
- hda_codec_register(&hda_audio_info_output);
- hda_codec_register(&hda_audio_info_duplex);
+ hda_codec_register(&hda_audio_output_info);
+ hda_codec_register(&hda_audio_duplex_info);
}
device_init(hda_audio_register);
diff --git a/hw/intel-hda.c b/hw/intel-hda.c
index 09459b8..97a6216 100644
--- a/hw/intel-hda.c
+++ b/hw/intel-hda.c
@@ -50,10 +50,9 @@ void hda_codec_bus_init(DeviceState *dev, HDACodecBus *bus,
static int hda_codec_dev_init(DeviceState *qdev, DeviceInfo *base)
{
HDACodecBus *bus = DO_UPCAST(HDACodecBus, qbus, qdev->parent_bus);
- HDACodecDevice *dev = DO_UPCAST(HDACodecDevice, qdev, qdev);
- HDACodecDeviceInfo *info = DO_UPCAST(HDACodecDeviceInfo, qdev, base);
+ HDACodecDevice *dev = HDA_CODEC_DEVICE(qdev);
+ HDACodecDeviceClass *hcc = HDA_CODEC_DEVICE_GET_CLASS(dev);
- dev->info = info;
if (dev->cad == -1) {
dev->cad = bus->next_cad;
}
@@ -61,25 +60,26 @@ static int hda_codec_dev_init(DeviceState *qdev, DeviceInfo *base)
return -1;
}
bus->next_cad = dev->cad + 1;
- return info->init(dev);
+ return hcc->init(dev);
}
static int hda_codec_dev_exit(DeviceState *qdev)
{
- HDACodecDevice *dev = DO_UPCAST(HDACodecDevice, qdev, qdev);
+ HDACodecDevice *dev = HDA_CODEC_DEVICE(qdev);
+ HDACodecDeviceClass *hcc = HDA_CODEC_DEVICE_GET_CLASS(dev);
- if (dev->info->exit) {
- dev->info->exit(dev);
+ if (hcc->exit) {
+ hcc->exit(dev);
}
return 0;
}
-void hda_codec_register(HDACodecDeviceInfo *info)
+void hda_codec_register(DeviceInfo *info)
{
- info->qdev.init = hda_codec_dev_init;
- info->qdev.exit = hda_codec_dev_exit;
- info->qdev.bus_info = &hda_codec_bus_info;
- qdev_register(&info->qdev);
+ info->init = hda_codec_dev_init;
+ info->exit = hda_codec_dev_exit;
+ info->bus_info = &hda_codec_bus_info;
+ qdev_register_subclass(info, TYPE_HDA_CODEC_DEVICE);
}
HDACodecDevice *hda_codec_find(HDACodecBus *bus, uint32_t cad)
@@ -283,6 +283,7 @@ static int intel_hda_send_command(IntelHDAState *d, uint32_t verb)
{
uint32_t cad, nid, data;
HDACodecDevice *codec;
+ HDACodecDeviceClass *hcc;
cad = (verb >> 28) & 0x0f;
if (verb & (1 << 27)) {
@@ -298,7 +299,8 @@ static int intel_hda_send_command(IntelHDAState *d, uint32_t verb)
dprint(d, 1, "%s: addressed non-existing codec\n", __FUNCTION__);
return -1;
}
- codec->info->command(codec, nid, data);
+ hcc = HDA_CODEC_DEVICE_GET_CLASS(codec);
+ hcc->command(codec, nid, data);
return 0;
}
@@ -491,9 +493,11 @@ static void intel_hda_notify_codecs(IntelHDAState *d, uint32_t stream, bool runn
HDACodecDevice *cdev;
QTAILQ_FOREACH(qdev, &d->codecs.qbus.children, sibling) {
+ HDACodecDeviceClass *hcc;
cdev = DO_UPCAST(HDACodecDevice, qdev, qdev);
- if (cdev->info->stream) {
- cdev->info->stream(cdev, stream, running, output);
+ hcc = HDA_CODEC_DEVICE_GET_CLASS(cdev);
+ if (hcc->stream) {
+ hcc->stream(cdev, stream, running, output);
}
}
}
@@ -1262,9 +1266,18 @@ static PCIDeviceInfo intel_hda_info = {
}
};
+static TypeInfo hda_codec_device_type_info = {
+ .name = TYPE_HDA_CODEC_DEVICE,
+ .parent = TYPE_DEVICE,
+ .instance_size = sizeof(HDACodecDevice),
+ .abstract = true,
+ .class_size = sizeof(HDACodecDeviceClass),
+};
+
static void intel_hda_register(void)
{
pci_qdev_register(&intel_hda_info);
+ type_register_static(&hda_codec_device_type_info);
}
device_init(intel_hda_register);
diff --git a/hw/intel-hda.h b/hw/intel-hda.h
index 65fd2a8..f523587 100644
--- a/hw/intel-hda.h
+++ b/hw/intel-hda.h
@@ -6,9 +6,16 @@
/* --------------------------------------------------------------------- */
/* hda bus */
+#define TYPE_HDA_CODEC_DEVICE "hda-codec"
+#define HDA_CODEC_DEVICE(obj) \
+ OBJECT_CHECK(HDACodecDevice, (obj), TYPE_HDA_CODEC_DEVICE)
+#define HDA_CODEC_DEVICE_CLASS(klass) \
+ OBJECT_CLASS_CHECK(HDACodecDeviceClass, (klass), TYPE_HDA_CODEC_DEVICE)
+#define HDA_CODEC_DEVICE_GET_CLASS(obj) \
+ OBJECT_GET_CLASS(HDACodecDeviceClass, (obj), TYPE_HDA_CODEC_DEVICE)
+
typedef struct HDACodecBus HDACodecBus;
typedef struct HDACodecDevice HDACodecDevice;
-typedef struct HDACodecDeviceInfo HDACodecDeviceInfo;
typedef void (*hda_codec_response_func)(HDACodecDevice *dev,
bool solicited, uint32_t response);
@@ -23,24 +30,25 @@ struct HDACodecBus {
hda_codec_xfer_func xfer;
};
-struct HDACodecDevice {
- DeviceState qdev;
- HDACodecDeviceInfo *info;
- uint32_t cad; /* codec address */
-};
+typedef struct HDACodecDeviceClass
+{
+ DeviceClass parent_class;
-struct HDACodecDeviceInfo {
- DeviceInfo qdev;
int (*init)(HDACodecDevice *dev);
int (*exit)(HDACodecDevice *dev);
void (*command)(HDACodecDevice *dev, uint32_t nid, uint32_t data);
void (*stream)(HDACodecDevice *dev, uint32_t stnr, bool running, bool output);
+} HDACodecDeviceClass;
+
+struct HDACodecDevice {
+ DeviceState qdev;
+ uint32_t cad; /* codec address */
};
void hda_codec_bus_init(DeviceState *dev, HDACodecBus *bus,
hda_codec_response_func response,
hda_codec_xfer_func xfer);
-void hda_codec_register(HDACodecDeviceInfo *info);
+void hda_codec_register(DeviceInfo *info);
HDACodecDevice *hda_codec_find(HDACodecBus *bus, uint32_t cad);
void hda_codec_response(HDACodecDevice *dev, bool solicited, uint32_t response);
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 063/197] make spapr a bit more patch monkey friendly
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (59 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 062/197] killall HDACodecDeviceInfo Anthony Liguori
@ 2011-12-12 20:18 ` Anthony Liguori
2011-12-12 20:19 ` [Qemu-devel] [PATCH v3 064/197] killall VIOsPAPRDeviceInfo Anthony Liguori
` (5 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:18 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/spapr_llan.c | 4 ++--
hw/spapr_vscsi.c | 4 ++--
hw/spapr_vty.c | 4 ++--
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/hw/spapr_llan.c b/hw/spapr_llan.c
index abe1297..958702c 100644
--- a/hw/spapr_llan.c
+++ b/hw/spapr_llan.c
@@ -484,7 +484,7 @@ static void vlan_hcalls(VIOsPAPRBus *bus)
spapr_register_hypercall(H_MULTICAST_CTRL, h_multicast_ctrl);
}
-static VIOsPAPRDeviceInfo spapr_vlan = {
+static VIOsPAPRDeviceInfo spapr_vlan_info = {
.init = spapr_vlan_init,
.devnode = spapr_vlan_devnode,
.dt_name = "l-lan",
@@ -503,6 +503,6 @@ static VIOsPAPRDeviceInfo spapr_vlan = {
static void spapr_vlan_register(void)
{
- spapr_vio_bus_register_withprop(&spapr_vlan);
+ spapr_vio_bus_register_withprop(&spapr_vlan_info);
}
device_init(spapr_vlan_register);
diff --git a/hw/spapr_vscsi.c b/hw/spapr_vscsi.c
index 00e2d2d..21d946e 100644
--- a/hw/spapr_vscsi.c
+++ b/hw/spapr_vscsi.c
@@ -947,7 +947,7 @@ static int spapr_vscsi_devnode(VIOsPAPRDevice *dev, void *fdt, int node_off)
return 0;
}
-static VIOsPAPRDeviceInfo spapr_vscsi = {
+static VIOsPAPRDeviceInfo spapr_vscsi_info = {
.init = spapr_vscsi_init,
.devnode = spapr_vscsi_devnode,
.dt_name = "v-scsi",
@@ -964,6 +964,6 @@ static VIOsPAPRDeviceInfo spapr_vscsi = {
static void spapr_vscsi_register(void)
{
- spapr_vio_bus_register_withprop(&spapr_vscsi);
+ spapr_vio_bus_register_withprop(&spapr_vscsi_info);
}
device_init(spapr_vscsi_register);
diff --git a/hw/spapr_vty.c b/hw/spapr_vty.c
index f23cc36..fddecd8 100644
--- a/hw/spapr_vty.c
+++ b/hw/spapr_vty.c
@@ -141,7 +141,7 @@ static void vty_hcalls(VIOsPAPRBus *bus)
spapr_register_hypercall(H_GET_TERM_CHAR, h_get_term_char);
}
-static VIOsPAPRDeviceInfo spapr_vty = {
+static VIOsPAPRDeviceInfo spapr_vty_info = {
.init = spapr_vty_init,
.dt_name = "vty",
.dt_type = "serial",
@@ -181,6 +181,6 @@ static VIOsPAPRDevice *vty_lookup(sPAPREnvironment *spapr, target_ulong reg)
static void spapr_vty_register(void)
{
- spapr_vio_bus_register_withprop(&spapr_vty);
+ spapr_vio_bus_register_withprop(&spapr_vty_info);
}
device_init(spapr_vty_register);
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 064/197] killall VIOsPAPRDeviceInfo
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (60 preceding siblings ...)
2011-12-12 20:18 ` [Qemu-devel] [PATCH v3 063/197] make spapr a bit more patch monkey friendly Anthony Liguori
@ 2011-12-12 20:19 ` Anthony Liguori
2011-12-13 2:04 ` Michael Ellerman
2011-12-12 20:19 ` [Qemu-devel] [PATCH v3 065/197] qxl: be more patch monkey friendly Anthony Liguori
` (4 subsequent siblings)
66 siblings, 1 reply; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:19 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
This was doing something evil building a dt tree so we broke the device.
---
hw/spapr_llan.c | 39 ++++++++++++++++++++++++---------------
hw/spapr_vio.c | 52 +++++++++++++++++++++++++++++++++-------------------
hw/spapr_vio.h | 29 +++++++++++++++++++----------
hw/spapr_vscsi.c | 35 ++++++++++++++++++++++-------------
hw/spapr_vty.c | 35 ++++++++++++++++++++++-------------
5 files changed, 120 insertions(+), 70 deletions(-)
diff --git a/hw/spapr_llan.c b/hw/spapr_llan.c
index 958702c..b06b274 100644
--- a/hw/spapr_llan.c
+++ b/hw/spapr_llan.c
@@ -484,21 +484,30 @@ static void vlan_hcalls(VIOsPAPRBus *bus)
spapr_register_hypercall(H_MULTICAST_CTRL, h_multicast_ctrl);
}
-static VIOsPAPRDeviceInfo spapr_vlan_info = {
- .init = spapr_vlan_init,
- .devnode = spapr_vlan_devnode,
- .dt_name = "l-lan",
- .dt_type = "network",
- .dt_compatible = "IBM,l-lan",
- .signal_mask = 0x1,
- .hcalls = vlan_hcalls,
- .qdev.name = "spapr-vlan",
- .qdev.size = sizeof(VIOsPAPRVLANDevice),
- .qdev.props = (Property[]) {
- DEFINE_SPAPR_PROPERTIES(VIOsPAPRVLANDevice, sdev, 0x1000, 0x10000000),
- DEFINE_NIC_PROPERTIES(VIOsPAPRVLANDevice, nicconf),
- DEFINE_PROP_END_OF_LIST(),
- },
+static Property spapr_vlan_properties[] = {
+ DEFINE_SPAPR_PROPERTIES(VIOsPAPRVLANDevice, sdev, 0x1000, 0x10000000),
+ DEFINE_NIC_PROPERTIES(VIOsPAPRVLANDevice, nicconf),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void spapr_vlan_class_init(ObjectClass *klass, void *data)
+{
+ VIOsPAPRDeviceClass *k = VIO_SPAPR_DEVICE_CLASS(klass);
+
+ k->init = spapr_vlan_init;
+ k->devnode = spapr_vlan_devnode;
+ k->dt_name = "l-lan";
+ k->dt_type = "network";
+ k->dt_compatible = "IBM,l-lan";
+ k->signal_mask = 0x1;
+ k->hcalls = vlan_hcalls;
+}
+
+static DeviceInfo spapr_vlan_info = {
+ .name = "spapr-vlan",
+ .size = sizeof(VIOsPAPRVLANDevice),
+ .props = spapr_vlan_properties,
+ .class_init = spapr_vlan_class_init,
};
static void spapr_vlan_register(void)
diff --git a/hw/spapr_vio.c b/hw/spapr_vio.c
index 2dcc036..4761bf9 100644
--- a/hw/spapr_vio.c
+++ b/hw/spapr_vio.c
@@ -75,11 +75,11 @@ VIOsPAPRDevice *spapr_vio_find_by_reg(VIOsPAPRBus *bus, uint32_t reg)
static char *vio_format_dev_name(VIOsPAPRDevice *dev)
{
- VIOsPAPRDeviceInfo *info = (VIOsPAPRDeviceInfo *)dev->qdev.info;
+ VIOsPAPRDeviceClass *pc = VIO_SPAPR_DEVICE_GET_CLASS(dev);
char *name;
/* Device tree style name device@reg */
- if (asprintf(&name, "%s@%x", info->dt_name, dev->reg) < 0) {
+ if (asprintf(&name, "%s@%x", pc->dt_name, dev->reg) < 0) {
return NULL;
}
@@ -90,7 +90,7 @@ static char *vio_format_dev_name(VIOsPAPRDevice *dev)
static int vio_make_devnode(VIOsPAPRDevice *dev,
void *fdt)
{
- VIOsPAPRDeviceInfo *info = (VIOsPAPRDeviceInfo *)dev->qdev.info;
+ VIOsPAPRDeviceClass *pc = VIO_SPAPR_DEVICE_GET_CLASS(dev);
int vdevice_off, node_off, ret;
char *dt_name;
@@ -115,17 +115,17 @@ static int vio_make_devnode(VIOsPAPRDevice *dev,
return ret;
}
- if (info->dt_type) {
+ if (pc->dt_type) {
ret = fdt_setprop_string(fdt, node_off, "device_type",
- info->dt_type);
+ pc->dt_type);
if (ret < 0) {
return ret;
}
}
- if (info->dt_compatible) {
+ if (pc->dt_compatible) {
ret = fdt_setprop_string(fdt, node_off, "compatible",
- info->dt_compatible);
+ pc->dt_compatible);
if (ret < 0) {
return ret;
}
@@ -163,8 +163,8 @@ static int vio_make_devnode(VIOsPAPRDevice *dev,
}
}
- if (info->devnode) {
- ret = (info->devnode)(dev, fdt, node_off);
+ if (pc->devnode) {
+ ret = (pc->devnode)(dev, fdt, node_off);
if (ret < 0) {
return ret;
}
@@ -623,8 +623,8 @@ static void rtas_quiesce(sPAPREnvironment *spapr, uint32_t token,
static int spapr_vio_busdev_init(DeviceState *qdev, DeviceInfo *qinfo)
{
- VIOsPAPRDeviceInfo *info = (VIOsPAPRDeviceInfo *)qinfo;
VIOsPAPRDevice *dev = (VIOsPAPRDevice *)qdev;
+ VIOsPAPRDeviceClass *pc = VIO_SPAPR_DEVICE_GET_CLASS(dev);
char *id;
/* Don't overwrite ids assigned on the command line */
@@ -643,16 +643,16 @@ static int spapr_vio_busdev_init(DeviceState *qdev, DeviceInfo *qinfo)
rtce_init(dev);
- return info->init(dev);
+ return pc->init(dev);
}
-void spapr_vio_bus_register_withprop(VIOsPAPRDeviceInfo *info)
+void spapr_vio_bus_register_withprop(DeviceInfo *info)
{
- info->qdev.init = spapr_vio_busdev_init;
- info->qdev.bus_info = &spapr_vio_bus_info;
+ info->init = spapr_vio_busdev_init;
+ info->bus_info = &spapr_vio_bus_info;
- assert(info->qdev.size >= sizeof(VIOsPAPRDevice));
- qdev_register(&info->qdev);
+ assert(info->size >= sizeof(VIOsPAPRDevice));
+ qdev_register_subclass(info, TYPE_VIO_SPAPR_DEVICE);
}
static target_ulong h_vio_signal(CPUState *env, sPAPREnvironment *spapr,
@@ -662,15 +662,15 @@ static target_ulong h_vio_signal(CPUState *env, sPAPREnvironment *spapr,
target_ulong reg = args[0];
target_ulong mode = args[1];
VIOsPAPRDevice *dev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
- VIOsPAPRDeviceInfo *info;
+ VIOsPAPRDeviceClass *pc;
if (!dev) {
return H_PARAMETER;
}
- info = (VIOsPAPRDeviceInfo *)dev->qdev.info;
+ pc = VIO_SPAPR_DEVICE_GET_CLASS(dev);
- if (mode & ~info->signal_mask) {
+ if (mode & ~pc->signal_mask) {
return H_PARAMETER;
}
@@ -711,8 +711,12 @@ VIOsPAPRBus *spapr_vio_bus_init(void)
spapr_rtas_register("ibm,set-tce-bypass", rtas_set_tce_bypass);
spapr_rtas_register("quiesce", rtas_quiesce);
+#if 0
+ /* Evil and broken */
+
for (qinfo = device_info_list; qinfo; qinfo = qinfo->next) {
VIOsPAPRDeviceInfo *info = (VIOsPAPRDeviceInfo *)qinfo;
+ VIOsPAPRDeviceClass *pc = VIO_SPAPR_DEVICE_GET_CLASS(dev);
if (qinfo->bus_info != &spapr_vio_bus_info) {
continue;
@@ -722,6 +726,7 @@ VIOsPAPRBus *spapr_vio_bus_init(void)
info->hcalls(bus);
}
}
+#endif
return bus;
}
@@ -741,9 +746,18 @@ static SysBusDeviceInfo spapr_vio_bridge_info = {
.qdev.no_user = 1,
};
+static TypeInfo spapr_vio_type_info = {
+ .name = TYPE_VIO_SPAPR_DEVICE,
+ .parent = TYPE_DEVICE,
+ .instance_size = sizeof(VIOsPAPRDevice),
+ .abstract = true,
+ .class_size = sizeof(VIOsPAPRDeviceClass),
+};
+
static void spapr_vio_register_devices(void)
{
sysbus_register_withprop(&spapr_vio_bridge_info);
+ type_register_static(&spapr_vio_type_info);
}
device_init(spapr_vio_register_devices)
diff --git a/hw/spapr_vio.h b/hw/spapr_vio.h
index a325a5f..89438a2 100644
--- a/hw/spapr_vio.h
+++ b/hw/spapr_vio.h
@@ -34,6 +34,14 @@ enum VIOsPAPR_TCEAccess {
#define SPAPR_VTY_BASE_ADDRESS 0x30000000
+#define TYPE_VIO_SPAPR_DEVICE "vio-spapr-device"
+#define VIO_SPAPR_DEVICE(obj) \
+ OBJECT_CHECK(VIOsPAPRDevice, (obj), TYPE_VIO_SPAPR_DEVICE)
+#define VIO_SPAPR_DEVICE_CLASS(klass) \
+ OBJECT_CLASS_CHECK(VIOsPAPRDeviceClass, (klass), TYPE_VIO_SPAPR_DEVICE)
+#define VIO_SPAPR_DEVICE_GET_CLASS(obj) \
+ OBJECT_GET_CLASS(VIOsPAPRDeviceClass, (obj), TYPE_VIO_SPAPR_DEVICE)
+
struct VIOsPAPRDevice;
typedef struct VIOsPAPR_RTCE {
@@ -47,6 +55,16 @@ typedef struct VIOsPAPR_CRQ {
int(*SendFunc)(struct VIOsPAPRDevice *vdev, uint8_t *crq);
} VIOsPAPR_CRQ;
+typedef struct VIOsPAPRDeviceClass {
+ DeviceClass parent_class;
+
+ const char *dt_name, *dt_type, *dt_compatible;
+ target_ulong signal_mask;
+ int (*init)(VIOsPAPRDevice *dev);
+ void (*hcalls)(VIOsPAPRBus *bus);
+ int (*devnode)(VIOsPAPRDevice *dev, void *fdt, int node_off);
+} VIOsPAPRDeviceClass;
+
typedef struct VIOsPAPRDevice {
DeviceState qdev;
uint32_t reg;
@@ -70,18 +88,9 @@ typedef struct VIOsPAPRBus {
BusState bus;
} VIOsPAPRBus;
-typedef struct {
- DeviceInfo qdev;
- const char *dt_name, *dt_type, *dt_compatible;
- target_ulong signal_mask;
- int (*init)(VIOsPAPRDevice *dev);
- void (*hcalls)(VIOsPAPRBus *bus);
- int (*devnode)(VIOsPAPRDevice *dev, void *fdt, int node_off);
-} VIOsPAPRDeviceInfo;
-
extern VIOsPAPRBus *spapr_vio_bus_init(void);
extern VIOsPAPRDevice *spapr_vio_find_by_reg(VIOsPAPRBus *bus, uint32_t reg);
-extern void spapr_vio_bus_register_withprop(VIOsPAPRDeviceInfo *info);
+extern void spapr_vio_bus_register_withprop(DeviceInfo *info);
extern int spapr_populate_vdevice(VIOsPAPRBus *bus, void *fdt);
extern int spapr_vio_signal(VIOsPAPRDevice *dev, target_ulong mode);
diff --git a/hw/spapr_vscsi.c b/hw/spapr_vscsi.c
index 21d946e..b83bb7f 100644
--- a/hw/spapr_vscsi.c
+++ b/hw/spapr_vscsi.c
@@ -947,19 +947,28 @@ static int spapr_vscsi_devnode(VIOsPAPRDevice *dev, void *fdt, int node_off)
return 0;
}
-static VIOsPAPRDeviceInfo spapr_vscsi_info = {
- .init = spapr_vscsi_init,
- .devnode = spapr_vscsi_devnode,
- .dt_name = "v-scsi",
- .dt_type = "vscsi",
- .dt_compatible = "IBM,v-scsi",
- .signal_mask = 0x00000001,
- .qdev.name = "spapr-vscsi",
- .qdev.size = sizeof(VSCSIState),
- .qdev.props = (Property[]) {
- DEFINE_SPAPR_PROPERTIES(VSCSIState, vdev, 0x2000, 0x10000000),
- DEFINE_PROP_END_OF_LIST(),
- },
+static Property spapr_vscsi_properties[] = {
+ DEFINE_SPAPR_PROPERTIES(VSCSIState, vdev, 0x2000, 0x10000000),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void spapr_vscsi_class_init(ObjectClass *klass, void *data)
+{
+ VIOsPAPRDeviceClass *k = VIO_SPAPR_DEVICE_CLASS(klass);
+
+ k->init = spapr_vscsi_init;
+ k->devnode = spapr_vscsi_devnode;
+ k->dt_name = "v-scsi";
+ k->dt_type = "vscsi";
+ k->dt_compatible = "IBM,v-scsi";
+ k->signal_mask = 0x00000001;
+}
+
+static DeviceInfo spapr_vscsi_info = {
+ .name = "spapr-vscsi",
+ .size = sizeof(VSCSIState),
+ .props = spapr_vscsi_properties,
+ .class_init = spapr_vscsi_class_init,
};
static void spapr_vscsi_register(void)
diff --git a/hw/spapr_vty.c b/hw/spapr_vty.c
index fddecd8..466c4f0 100644
--- a/hw/spapr_vty.c
+++ b/hw/spapr_vty.c
@@ -141,19 +141,28 @@ static void vty_hcalls(VIOsPAPRBus *bus)
spapr_register_hypercall(H_GET_TERM_CHAR, h_get_term_char);
}
-static VIOsPAPRDeviceInfo spapr_vty_info = {
- .init = spapr_vty_init,
- .dt_name = "vty",
- .dt_type = "serial",
- .dt_compatible = "hvterm1",
- .hcalls = vty_hcalls,
- .qdev.name = "spapr-vty",
- .qdev.size = sizeof(VIOsPAPRVTYDevice),
- .qdev.props = (Property[]) {
- DEFINE_SPAPR_PROPERTIES(VIOsPAPRVTYDevice, sdev, SPAPR_VTY_BASE_ADDRESS, 0),
- DEFINE_PROP_CHR("chardev", VIOsPAPRVTYDevice, chardev),
- DEFINE_PROP_END_OF_LIST(),
- },
+static Property spapr_vty_properties[] = {
+ DEFINE_SPAPR_PROPERTIES(VIOsPAPRVTYDevice, sdev, SPAPR_VTY_BASE_ADDRESS, 0),
+ DEFINE_PROP_CHR("chardev", VIOsPAPRVTYDevice, chardev),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void spapr_vty_class_init(ObjectClass *klass, void *data)
+{
+ VIOsPAPRDeviceClass *k = VIO_SPAPR_DEVICE_CLASS(klass);
+
+ k->init = spapr_vty_init;
+ k->dt_name = "vty";
+ k->dt_type = "serial";
+ k->dt_compatible = "hvterm1";
+ k->hcalls = vty_hcalls;
+}
+
+static DeviceInfo spapr_vty_info = {
+ .name = "spapr-vty",
+ .size = sizeof(VIOsPAPRVTYDevice),
+ .props = spapr_vty_properties,
+ .class_init = spapr_vty_class_init,
};
static VIOsPAPRDevice *vty_lookup(sPAPREnvironment *spapr, target_ulong reg)
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* Re: [Qemu-devel] [PATCH v3 064/197] killall VIOsPAPRDeviceInfo
2011-12-12 20:19 ` [Qemu-devel] [PATCH v3 064/197] killall VIOsPAPRDeviceInfo Anthony Liguori
@ 2011-12-13 2:04 ` Michael Ellerman
2011-12-13 2:10 ` Anthony Liguori
0 siblings, 1 reply; 74+ messages in thread
From: Michael Ellerman @ 2011-12-13 2:04 UTC (permalink / raw)
To: Anthony Liguori
Cc: Kevin Wolf, Peter Maydell, Stefan Hajnoczi, Jan Kiszka,
qemu-devel, Markus Armbruster, Luiz Capitulino, David Gibson
[-- Attachment #1: Type: text/plain, Size: 1035 bytes --]
On Mon, 2011-12-12 at 14:19 -0600, Anthony Liguori wrote:
> This was doing something evil building a dt tree so we broke the device.
> @@ -711,8 +711,12 @@ VIOsPAPRBus *spapr_vio_bus_init(void)
> spapr_rtas_register("ibm,set-tce-bypass", rtas_set_tce_bypass);
> spapr_rtas_register("quiesce", rtas_quiesce);
>
> +#if 0
> + /* Evil and broken */
By which you mean: works fine, broken by your patch?
> +
> for (qinfo = device_info_list; qinfo; qinfo = qinfo->next) {
> VIOsPAPRDeviceInfo *info = (VIOsPAPRDeviceInfo *)qinfo;
> + VIOsPAPRDeviceClass *pc = VIO_SPAPR_DEVICE_GET_CLASS(dev);
>
> if (qinfo->bus_info != &spapr_vio_bus_info) {
> continue;
> @@ -722,6 +726,7 @@ VIOsPAPRBus *spapr_vio_bus_init(void)
> info->hcalls(bus);
> }
> }
> +#endif
It's registering hcalls for each class of device we find on the spapr
vio bus. I don't understand why that is evil, but what do you suggest we
do instead?
cheers
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 74+ messages in thread
* Re: [Qemu-devel] [PATCH v3 064/197] killall VIOsPAPRDeviceInfo
2011-12-13 2:04 ` Michael Ellerman
@ 2011-12-13 2:10 ` Anthony Liguori
2011-12-13 2:22 ` Michael Ellerman
0 siblings, 1 reply; 74+ messages in thread
From: Anthony Liguori @ 2011-12-13 2:10 UTC (permalink / raw)
To: michael
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, qemu-devel, Markus Armbruster, Luiz Capitulino,
David Gibson
On 12/12/2011 08:04 PM, Michael Ellerman wrote:
> On Mon, 2011-12-12 at 14:19 -0600, Anthony Liguori wrote:
>> This was doing something evil building a dt tree so we broke the device.
>
>> @@ -711,8 +711,12 @@ VIOsPAPRBus *spapr_vio_bus_init(void)
>> spapr_rtas_register("ibm,set-tce-bypass", rtas_set_tce_bypass);
>> spapr_rtas_register("quiesce", rtas_quiesce);
>>
>> +#if 0
>> + /* Evil and broken */
>
> By which you mean: works fine, broken by your patch?
These patches were never supposed to go out. Ignore this series entirely.
>
>> +
>> for (qinfo = device_info_list; qinfo; qinfo = qinfo->next) {
>> VIOsPAPRDeviceInfo *info = (VIOsPAPRDeviceInfo *)qinfo;
>> + VIOsPAPRDeviceClass *pc = VIO_SPAPR_DEVICE_GET_CLASS(dev);
>>
>> if (qinfo->bus_info !=&spapr_vio_bus_info) {
>> continue;
>> @@ -722,6 +726,7 @@ VIOsPAPRBus *spapr_vio_bus_init(void)
>> info->hcalls(bus);
>> }
>> }
>> +#endif
>
> It's registering hcalls for each class of device we find on the spapr
> vio bus. I don't understand why that is evil, but what do you suggest we
> do instead?
I talked to David about this, the hcalls can just be registered as part the
device_init entry points.
If you must initialize them via a per-device callback, then you should walk it
from the bus's children, not by walking the entire device model. That was the
bit that I was referring to as evil. It's a layering violation.
Regards,
Anthony Liguori
> cheers
>
>
^ permalink raw reply [flat|nested] 74+ messages in thread
* Re: [Qemu-devel] [PATCH v3 064/197] killall VIOsPAPRDeviceInfo
2011-12-13 2:10 ` Anthony Liguori
@ 2011-12-13 2:22 ` Michael Ellerman
2011-12-13 2:25 ` Anthony Liguori
0 siblings, 1 reply; 74+ messages in thread
From: Michael Ellerman @ 2011-12-13 2:22 UTC (permalink / raw)
To: Anthony Liguori
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, qemu-devel, Markus Armbruster, Luiz Capitulino,
David Gibson
[-- Attachment #1: Type: text/plain, Size: 1662 bytes --]
On Mon, 2011-12-12 at 20:10 -0600, Anthony Liguori wrote:
> On 12/12/2011 08:04 PM, Michael Ellerman wrote:
> > On Mon, 2011-12-12 at 14:19 -0600, Anthony Liguori wrote:
> >> This was doing something evil building a dt tree so we broke the device.
> >
> >> @@ -711,8 +711,12 @@ VIOsPAPRBus *spapr_vio_bus_init(void)
> >> spapr_rtas_register("ibm,set-tce-bypass", rtas_set_tce_bypass);
> >> spapr_rtas_register("quiesce", rtas_quiesce);
> >>
> >> +#if 0
> >> + /* Evil and broken */
> >
> > By which you mean: works fine, broken by your patch?
>
> These patches were never supposed to go out. Ignore this series entirely.
But I just read all 197 of them ! ;)
> >> for (qinfo = device_info_list; qinfo; qinfo = qinfo->next) {
> >> VIOsPAPRDeviceInfo *info = (VIOsPAPRDeviceInfo *)qinfo;
> >> + VIOsPAPRDeviceClass *pc = VIO_SPAPR_DEVICE_GET_CLASS(dev);
> >>
> >> if (qinfo->bus_info !=&spapr_vio_bus_info) {
> >> continue;
> >> @@ -722,6 +726,7 @@ VIOsPAPRBus *spapr_vio_bus_init(void)
> >> info->hcalls(bus);
> >> }
> >> }
> >> +#endif
> >
> > It's registering hcalls for each class of device we find on the spapr
> > vio bus. I don't understand why that is evil, but what do you suggest we
> > do instead?
>
> I talked to David about this, the hcalls can just be registered as part the
> device_init entry points.
OK I'll talk to him about it. I don't think device_init() works, because
we only want to register the hcalls if an instance of the device is
instantiated. But I guess we'll come up with something.
cheers
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 74+ messages in thread
* Re: [Qemu-devel] [PATCH v3 064/197] killall VIOsPAPRDeviceInfo
2011-12-13 2:22 ` Michael Ellerman
@ 2011-12-13 2:25 ` Anthony Liguori
2011-12-13 3:26 ` David Gibson
0 siblings, 1 reply; 74+ messages in thread
From: Anthony Liguori @ 2011-12-13 2:25 UTC (permalink / raw)
To: michael
Cc: Kevin Wolf, Peter Maydell, Stefan Hajnoczi, Jan Kiszka,
qemu-devel, Markus Armbruster, Luiz Capitulino, David Gibson
On 12/12/2011 08:22 PM, Michael Ellerman wrote:
> On Mon, 2011-12-12 at 20:10 -0600, Anthony Liguori wrote:
>> On 12/12/2011 08:04 PM, Michael Ellerman wrote:
>>> On Mon, 2011-12-12 at 14:19 -0600, Anthony Liguori wrote:
>>>> This was doing something evil building a dt tree so we broke the device.
>>>
>>>> @@ -711,8 +711,12 @@ VIOsPAPRBus *spapr_vio_bus_init(void)
>>>> spapr_rtas_register("ibm,set-tce-bypass", rtas_set_tce_bypass);
>>>> spapr_rtas_register("quiesce", rtas_quiesce);
>>>>
>>>> +#if 0
>>>> + /* Evil and broken */
>>>
>>> By which you mean: works fine, broken by your patch?
>>
>> These patches were never supposed to go out. Ignore this series entirely.
>
> But I just read all 197 of them ! ;)
>
>>>> for (qinfo = device_info_list; qinfo; qinfo = qinfo->next) {
>>>> VIOsPAPRDeviceInfo *info = (VIOsPAPRDeviceInfo *)qinfo;
>>>> + VIOsPAPRDeviceClass *pc = VIO_SPAPR_DEVICE_GET_CLASS(dev);
>>>>
>>>> if (qinfo->bus_info !=&spapr_vio_bus_info) {
>>>> continue;
>>>> @@ -722,6 +726,7 @@ VIOsPAPRBus *spapr_vio_bus_init(void)
>>>> info->hcalls(bus);
>>>> }
>>>> }
>>>> +#endif
>>>
>>> It's registering hcalls for each class of device we find on the spapr
>>> vio bus. I don't understand why that is evil, but what do you suggest we
>>> do instead?
>>
>> I talked to David about this, the hcalls can just be registered as part the
>> device_init entry points.
>
> OK I'll talk to him about it. I don't think device_init() works, because
> we only want to register the hcalls if an instance of the device is
> instantiated. But I guess we'll come up with something.
Since the hcalls are well known and CPUState doesn't get touched at all, why not
register all of the possible hcalls in the VIO bus and then use a higher level
interface to dispatch to devices? I think that conceptionally makes more sense
than the devices directly registering hcalls themselves.
I know you're dealing with an existing virtual I/O model, but it's strange to
have an hcall dispatched directly to a device without going through any type of
controller/bus hierarchy. It doesn't fit how hardware works very well.
Regards,
Anthony Liguori
>
> cheers
>
^ permalink raw reply [flat|nested] 74+ messages in thread
* Re: [Qemu-devel] [PATCH v3 064/197] killall VIOsPAPRDeviceInfo
2011-12-13 2:25 ` Anthony Liguori
@ 2011-12-13 3:26 ` David Gibson
0 siblings, 0 replies; 74+ messages in thread
From: David Gibson @ 2011-12-13 3:26 UTC (permalink / raw)
To: Anthony Liguori
Cc: Kevin Wolf, Peter Maydell, Stefan Hajnoczi, Jan Kiszka,
qemu-devel, Markus Armbruster, michael, Luiz Capitulino
On Mon, Dec 12, 2011 at 08:25:51PM -0600, Anthony Liguori wrote:
> On 12/12/2011 08:22 PM, Michael Ellerman wrote:
> >On Mon, 2011-12-12 at 20:10 -0600, Anthony Liguori wrote:
> >>On 12/12/2011 08:04 PM, Michael Ellerman wrote:
> >>>On Mon, 2011-12-12 at 14:19 -0600, Anthony Liguori wrote:
> >>>>This was doing something evil building a dt tree so we broke the device.
> >>>
> >>>>@@ -711,8 +711,12 @@ VIOsPAPRBus *spapr_vio_bus_init(void)
> >>>> spapr_rtas_register("ibm,set-tce-bypass", rtas_set_tce_bypass);
> >>>> spapr_rtas_register("quiesce", rtas_quiesce);
> >>>>
> >>>>+#if 0
> >>>>+ /* Evil and broken */
> >>>
> >>>By which you mean: works fine, broken by your patch?
Um, yeah. It may have been evil, but it wasn't broken, whereas it
certainly is broken by this patch.
> >>These patches were never supposed to go out. Ignore this series entirely.
Phew.
> >But I just read all 197 of them ! ;)
> >
> >>>> for (qinfo = device_info_list; qinfo; qinfo = qinfo->next) {
> >>>> VIOsPAPRDeviceInfo *info = (VIOsPAPRDeviceInfo *)qinfo;
> >>>>+ VIOsPAPRDeviceClass *pc = VIO_SPAPR_DEVICE_GET_CLASS(dev);
> >>>>
> >>>> if (qinfo->bus_info !=&spapr_vio_bus_info) {
> >>>> continue;
> >>>>@@ -722,6 +726,7 @@ VIOsPAPRBus *spapr_vio_bus_init(void)
> >>>> info->hcalls(bus);
> >>>> }
> >>>> }
> >>>>+#endif
> >>>
> >>>It's registering hcalls for each class of device we find on the spapr
> >>>vio bus. I don't understand why that is evil, but what do you suggest we
> >>>do instead?
> >>
> >>I talked to David about this, the hcalls can just be registered as part the
> >>device_init entry points.
> >
> >OK I'll talk to him about it. I don't think device_init() works, because
> >we only want to register the hcalls if an instance of the device is
> >instantiated. But I guess we'll come up with something.
Hm, no, actually. The reason we're stepping through the device infos
rather than vio devices is so that hcalls are registered per device
type rather than per device instance.
> Since the hcalls are well known and CPUState doesn't get touched at
> all, why not register all of the possible hcalls in the VIO bus and
> then use a higher level interface to dispatch to devices? I think
> that conceptionally makes more sense than the devices directly
> registering hcalls themselves.
No, not really. It means spapr_vio.c has to contain knowledge of
every possible VIO device.
> I know you're dealing with an existing virtual I/O model, but it's
> strange to have an hcall dispatched directly to a device without
> going through any type of controller/bus hierarchy. It doesn't fit
> how hardware works very well.
But VIO devices don't work much like real hardware. Other than the
CRQ and a few other hcalls, which are already handled at the bus
level, there is *no* common processing we can do for the device
specific hcalls. Routing them through spapr_vio.c would just be
pointless redirection.
Anyway, I'll make a [atch to move the hypercall registrations to
device_init functions.
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
^ permalink raw reply [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 065/197] qxl: be more patch monkey friendly
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (61 preceding siblings ...)
2011-12-12 20:19 ` [Qemu-devel] [PATCH v3 064/197] killall VIOsPAPRDeviceInfo Anthony Liguori
@ 2011-12-12 20:19 ` Anthony Liguori
2011-12-12 20:19 ` [Qemu-devel] [PATCH v3 066/197] make es1370 more script " Anthony Liguori
` (3 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:19 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/qxl.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/hw/qxl.c b/hw/qxl.c
index 41500e9..5f30525 100644
--- a/hw/qxl.c
+++ b/hw/qxl.c
@@ -1827,7 +1827,7 @@ static Property qxl_properties[] = {
DEFINE_PROP_END_OF_LIST(),
};
-static PCIDeviceInfo qxl_info_primary = {
+static PCIDeviceInfo qxl_primary_info = {
.qdev.name = "qxl-vga",
.qdev.desc = "Spice QXL GPU (primary, vga compatible)",
.qdev.size = sizeof(PCIQXLDevice),
@@ -1842,7 +1842,7 @@ static PCIDeviceInfo qxl_info_primary = {
.qdev.props = qxl_properties,
};
-static PCIDeviceInfo qxl_info_secondary = {
+static PCIDeviceInfo qxl_secondary_info = {
.qdev.name = "qxl",
.qdev.desc = "Spice QXL GPU (secondary)",
.qdev.size = sizeof(PCIQXLDevice),
@@ -1857,8 +1857,8 @@ static PCIDeviceInfo qxl_info_secondary = {
static void qxl_register(void)
{
- pci_qdev_register(&qxl_info_primary);
- pci_qdev_register(&qxl_info_secondary);
+ pci_qdev_register(&qxl_primary_info);
+ pci_qdev_register(&qxl_secondary_info);
}
device_init(qxl_register);
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 066/197] make es1370 more script monkey friendly
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (62 preceding siblings ...)
2011-12-12 20:19 ` [Qemu-devel] [PATCH v3 065/197] qxl: be more patch monkey friendly Anthony Liguori
@ 2011-12-12 20:19 ` Anthony Liguori
2011-12-12 20:19 ` [Qemu-devel] [PATCH v3 067/197] remove arrays of PCIDeviceInfo Anthony Liguori
` (2 subsequent siblings)
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:19 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/es1370.c | 5 -----
1 files changed, 0 insertions(+), 5 deletions(-)
diff --git a/hw/es1370.c b/hw/es1370.c
index c5c16b0..8a7ca65 100644
--- a/hw/es1370.c
+++ b/hw/es1370.c
@@ -1041,13 +1041,8 @@ static PCIDeviceInfo es1370_info = {
.vendor_id = PCI_VENDOR_ID_ENSONIQ,
.device_id = PCI_DEVICE_ID_ENSONIQ_ES1370,
.class_id = PCI_CLASS_MULTIMEDIA_AUDIO,
-#if 1
.subsystem_vendor_id = 0x4942,
.subsystem_id = 0x4c4c,
-#else
- .subsystem_vendor_id = 0x1274,
- .subsystem_id = 0x1371,
-#endif
};
static void es1370_register (void)
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 067/197] remove arrays of PCIDeviceInfo
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (63 preceding siblings ...)
2011-12-12 20:19 ` [Qemu-devel] [PATCH v3 066/197] make es1370 more script " Anthony Liguori
@ 2011-12-12 20:19 ` Anthony Liguori
2011-12-12 20:19 ` [Qemu-devel] [PATCH v3 068/197] Patch monkey PCIDeviceInfo conversion Anthony Liguori
2011-12-12 20:19 ` [Qemu-devel] [PATCH v3 069/197] patch monkey, that funky monkey Anthony Liguori
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:19 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/i440fx.c | 32 +++++------
hw/piix4.c | 29 ++++-----
hw/usb-ehci.c | 49 ++++++++--------
hw/usb-uhci.c | 107 +++++++++++++++++++---------------
hw/virtio-pci.c | 174 +++++++++++++++++++++++++++----------------------------
5 files changed, 196 insertions(+), 195 deletions(-)
diff --git a/hw/i440fx.c b/hw/i440fx.c
index e0600dd..db15ce8 100644
--- a/hw/i440fx.c
+++ b/hw/i440fx.c
@@ -345,23 +345,19 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix3_devfn,
return b;
}
-static PCIDeviceInfo i440fx_info[] = {
- {
- .qdev.name = "i440FX",
- .qdev.desc = "Host bridge",
- .qdev.size = sizeof(PCII440FXState),
- .qdev.vmsd = &vmstate_i440fx,
- .qdev.no_user = 1,
- .no_hotplug = 1,
- .init = i440fx_initfn,
- .config_write = i440fx_write_config,
- .vendor_id = PCI_VENDOR_ID_INTEL,
- .device_id = PCI_DEVICE_ID_INTEL_82441,
- .revision = 0x02,
- .class_id = PCI_CLASS_BRIDGE_HOST,
- },{
- /* end of list */
- }
+static PCIDeviceInfo i440fx_info = {
+ .qdev.name = "i440FX",
+ .qdev.desc = "Host bridge",
+ .qdev.size = sizeof(PCII440FXState),
+ .qdev.vmsd = &vmstate_i440fx,
+ .qdev.no_user = 1,
+ .no_hotplug = 1,
+ .init = i440fx_initfn,
+ .config_write = i440fx_write_config,
+ .vendor_id = PCI_VENDOR_ID_INTEL,
+ .device_id = PCI_DEVICE_ID_INTEL_82441,
+ .revision = 0x02,
+ .class_id = PCI_CLASS_BRIDGE_HOST,
};
static SysBusDeviceInfo i440fx_pcihost_info = {
@@ -375,7 +371,7 @@ static SysBusDeviceInfo i440fx_pcihost_info = {
static void i440fx_register(void)
{
sysbus_register_withprop(&i440fx_pcihost_info);
- pci_qdev_register_many(i440fx_info);
+ pci_qdev_register(i440fx_info);
}
device_init(i440fx_register);
diff --git a/hw/piix4.c b/hw/piix4.c
index 2fd1171..1e959c6 100644
--- a/hw/piix4.c
+++ b/hw/piix4.c
@@ -101,25 +101,22 @@ int piix4_init(PCIBus *bus, int devfn)
return d->devfn;
}
-static PCIDeviceInfo piix4_info[] = {
- {
- .qdev.name = "PIIX4",
- .qdev.desc = "ISA bridge",
- .qdev.size = sizeof(PIIX4State),
- .qdev.vmsd = &vmstate_piix4,
- .qdev.no_user = 1,
- .no_hotplug = 1,
- .init = piix4_initfn,
- .vendor_id = PCI_VENDOR_ID_INTEL,
- .device_id = PCI_DEVICE_ID_INTEL_82371AB_0, // 82371AB/EB/MB PIIX4 PCI-to-ISA bridge
- .class_id = PCI_CLASS_BRIDGE_ISA,
- },{
- /* end of list */
- }
+static PCIDeviceInfo piix4_info = {
+ .qdev.name = "PIIX4",
+ .qdev.desc = "ISA bridge",
+ .qdev.size = sizeof(PIIX4State),
+ .qdev.vmsd = &vmstate_piix4,
+ .qdev.no_user = 1,
+ .no_hotplug = 1,
+ .init = piix4_initfn,
+ .vendor_id = PCI_VENDOR_ID_INTEL,
+ /* 82371AB/EB/MB PIIX4 PCI-to-ISA bridge */
+ .device_id = PCI_DEVICE_ID_INTEL_82371AB_0,
+ .class_id = PCI_CLASS_BRIDGE_ISA,
};
static void piix4_register(void)
{
- pci_qdev_register_many(piix4_info);
+ pci_qdev_register(&piix4_info);
}
device_init(piix4_register);
diff --git a/hw/usb-ehci.c b/hw/usb-ehci.c
index a946e1d..15f0c7d 100644
--- a/hw/usb-ehci.c
+++ b/hw/usb-ehci.c
@@ -2262,30 +2262,28 @@ static Property ehci_properties[] = {
DEFINE_PROP_END_OF_LIST(),
};
-static PCIDeviceInfo ehci_info[] = {
- {
- .qdev.name = "usb-ehci",
- .qdev.size = sizeof(EHCIState),
- .qdev.vmsd = &vmstate_ehci,
- .init = usb_ehci_initfn,
- .vendor_id = PCI_VENDOR_ID_INTEL,
- .device_id = PCI_DEVICE_ID_INTEL_82801D, /* ich4 */
- .revision = 0x10,
- .class_id = PCI_CLASS_SERIAL_USB,
- .qdev.props = ehci_properties,
- },{
- .qdev.name = "ich9-usb-ehci1",
- .qdev.size = sizeof(EHCIState),
- .qdev.vmsd = &vmstate_ehci,
- .init = usb_ehci_initfn,
- .vendor_id = PCI_VENDOR_ID_INTEL,
- .device_id = PCI_DEVICE_ID_INTEL_82801I_EHCI1,
- .revision = 0x03,
- .class_id = PCI_CLASS_SERIAL_USB,
- .qdev.props = ehci_properties,
- },{
- /* end of list */
- }
+static PCIDeviceInfo ehci_info = {
+ .qdev.name = "usb-ehci",
+ .qdev.size = sizeof(EHCIState),
+ .qdev.vmsd = &vmstate_ehci,
+ .init = usb_ehci_initfn,
+ .vendor_id = PCI_VENDOR_ID_INTEL,
+ .device_id = PCI_DEVICE_ID_INTEL_82801D, /* ich4 */
+ .revision = 0x10,
+ .class_id = PCI_CLASS_SERIAL_USB,
+ .qdev.props = ehci_properties,
+};
+
+static PCIDeviceInfo ich9_ehci_info = {
+ .qdev.name = "ich9-usb-ehci1",
+ .qdev.size = sizeof(EHCIState),
+ .qdev.vmsd = &vmstate_ehci,
+ .init = usb_ehci_initfn,
+ .vendor_id = PCI_VENDOR_ID_INTEL,
+ .device_id = PCI_DEVICE_ID_INTEL_82801I_EHCI1,
+ .revision = 0x03,
+ .class_id = PCI_CLASS_SERIAL_USB,
+ .qdev.props = ehci_properties,
};
static int usb_ehci_initfn(PCIDevice *dev)
@@ -2361,7 +2359,8 @@ static int usb_ehci_initfn(PCIDevice *dev)
static void ehci_register(void)
{
- pci_qdev_register_many(ehci_info);
+ pci_qdev_register(ehci_info);
+ pci_qdev_register(ich9_ehci_info);
}
device_init(ehci_register);
diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c
index 3e4456a..9b10501 100644
--- a/hw/usb-uhci.c
+++ b/hw/usb-uhci.c
@@ -1194,8 +1194,7 @@ static Property uhci_properties[] = {
DEFINE_PROP_END_OF_LIST(),
};
-static PCIDeviceInfo uhci_info[] = {
- {
+static PCIDeviceInfo piix3_uhci_info = {
.qdev.name = "piix3-usb-uhci",
.qdev.size = sizeof(UHCIState),
.qdev.vmsd = &vmstate_uhci,
@@ -1206,7 +1205,9 @@ static PCIDeviceInfo uhci_info[] = {
.revision = 0x01,
.class_id = PCI_CLASS_SERIAL_USB,
.qdev.props = uhci_properties,
- },{
+};
+
+static PCIDeviceInfo piix4_uhci_info = {
.qdev.name = "piix4-usb-uhci",
.qdev.size = sizeof(UHCIState),
.qdev.vmsd = &vmstate_uhci,
@@ -1217,55 +1218,65 @@ static PCIDeviceInfo uhci_info[] = {
.revision = 0x01,
.class_id = PCI_CLASS_SERIAL_USB,
.qdev.props = uhci_properties,
- },{
- .qdev.name = "vt82c686b-usb-uhci",
- .qdev.size = sizeof(UHCIState),
- .qdev.vmsd = &vmstate_uhci,
- .init = usb_uhci_vt82c686b_initfn,
- .exit = usb_uhci_exit,
- .vendor_id = PCI_VENDOR_ID_VIA,
- .device_id = PCI_DEVICE_ID_VIA_UHCI,
- .revision = 0x01,
- .class_id = PCI_CLASS_SERIAL_USB,
- .qdev.props = uhci_properties,
- },{
- .qdev.name = "ich9-usb-uhci1",
- .qdev.size = sizeof(UHCIState),
- .qdev.vmsd = &vmstate_uhci,
- .init = usb_uhci_common_initfn,
- .vendor_id = PCI_VENDOR_ID_INTEL,
- .device_id = PCI_DEVICE_ID_INTEL_82801I_UHCI1,
- .revision = 0x03,
- .class_id = PCI_CLASS_SERIAL_USB,
- .qdev.props = uhci_properties,
- },{
- .qdev.name = "ich9-usb-uhci2",
- .qdev.size = sizeof(UHCIState),
- .qdev.vmsd = &vmstate_uhci,
- .init = usb_uhci_common_initfn,
- .vendor_id = PCI_VENDOR_ID_INTEL,
- .device_id = PCI_DEVICE_ID_INTEL_82801I_UHCI2,
- .revision = 0x03,
- .class_id = PCI_CLASS_SERIAL_USB,
- .qdev.props = uhci_properties,
- },{
- .qdev.name = "ich9-usb-uhci3",
- .qdev.size = sizeof(UHCIState),
- .qdev.vmsd = &vmstate_uhci,
- .init = usb_uhci_common_initfn,
- .vendor_id = PCI_VENDOR_ID_INTEL,
- .device_id = PCI_DEVICE_ID_INTEL_82801I_UHCI3,
- .revision = 0x03,
- .class_id = PCI_CLASS_SERIAL_USB,
- .qdev.props = uhci_properties,
- },{
- /* end of list */
- }
+};
+
+static PCIDeviceInfo vt82c686b_uhci_info = {
+ .qdev.name = "vt82c686b-usb-uhci",
+ .qdev.size = sizeof(UHCIState),
+ .qdev.vmsd = &vmstate_uhci,
+ .init = usb_uhci_vt82c686b_initfn,
+ .exit = usb_uhci_exit,
+ .vendor_id = PCI_VENDOR_ID_VIA,
+ .device_id = PCI_DEVICE_ID_VIA_UHCI,
+ .revision = 0x01,
+ .class_id = PCI_CLASS_SERIAL_USB,
+ .qdev.props = uhci_properties,
+};
+
+static PCIDeviceInfo ich9_uhci1_info = {
+ .qdev.name = "ich9-usb-uhci1",
+ .qdev.size = sizeof(UHCIState),
+ .qdev.vmsd = &vmstate_uhci,
+ .init = usb_uhci_common_initfn,
+ .vendor_id = PCI_VENDOR_ID_INTEL,
+ .device_id = PCI_DEVICE_ID_INTEL_82801I_UHCI1,
+ .revision = 0x03,
+ .class_id = PCI_CLASS_SERIAL_USB,
+ .qdev.props = uhci_properties,
+};
+
+static PCIDeviceInfo ich9_uhci2_info = {
+ .qdev.name = "ich9-usb-uhci2",
+ .qdev.size = sizeof(UHCIState),
+ .qdev.vmsd = &vmstate_uhci,
+ .init = usb_uhci_common_initfn,
+ .vendor_id = PCI_VENDOR_ID_INTEL,
+ .device_id = PCI_DEVICE_ID_INTEL_82801I_UHCI2,
+ .revision = 0x03,
+ .class_id = PCI_CLASS_SERIAL_USB,
+ .qdev.props = uhci_properties,
+};
+
+static PCIDeviceInfo ich9_uhci3_info = {
+ .qdev.name = "ich9-usb-uhci3",
+ .qdev.size = sizeof(UHCIState),
+ .qdev.vmsd = &vmstate_uhci,
+ .init = usb_uhci_common_initfn,
+ .vendor_id = PCI_VENDOR_ID_INTEL,
+ .device_id = PCI_DEVICE_ID_INTEL_82801I_UHCI3,
+ .revision = 0x03,
+ .class_id = PCI_CLASS_SERIAL_USB,
+ .qdev.props = uhci_properties,
};
static void uhci_register(void)
{
- pci_qdev_register_many(uhci_info);
+ pci_qdev_register(&piix3_uhci_info);
+ pci_qdev_register(&piix4_uhci_info);
+ pci_qdev_register(&vt82c686b_uhci_info);
+ pci_qdev_register(&ich9_uhci1_info);
+ pci_qdev_register(&ich9_uhci2_info);
+ pci_qdev_register(&ich9_uhci3_info);
}
device_init(uhci_register);
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 64c6a94..885d990 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -779,98 +779,96 @@ static int virtio_balloon_exit_pci(PCIDevice *pci_dev)
return virtio_exit_pci(pci_dev);
}
-static PCIDeviceInfo virtio_info[] = {
- {
- .qdev.name = "virtio-blk-pci",
- .qdev.alias = "virtio-blk",
- .qdev.size = sizeof(VirtIOPCIProxy),
- .init = virtio_blk_init_pci,
- .exit = virtio_blk_exit_pci,
- .vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET,
- .device_id = PCI_DEVICE_ID_VIRTIO_BLOCK,
- .revision = VIRTIO_PCI_ABI_VERSION,
- .class_id = PCI_CLASS_STORAGE_SCSI,
- .qdev.props = (Property[]) {
- DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
- DEFINE_BLOCK_PROPERTIES(VirtIOPCIProxy, block),
- DEFINE_PROP_STRING("serial", VirtIOPCIProxy, block_serial),
- DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
- VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
- DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
- DEFINE_VIRTIO_BLK_FEATURES(VirtIOPCIProxy, host_features),
- DEFINE_PROP_END_OF_LIST(),
- },
- .qdev.reset = virtio_pci_reset,
- },{
- .qdev.name = "virtio-net-pci",
- .qdev.alias = "virtio-net",
- .qdev.size = sizeof(VirtIOPCIProxy),
- .init = virtio_net_init_pci,
- .exit = virtio_net_exit_pci,
- .romfile = "pxe-virtio.rom",
- .vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET,
- .device_id = PCI_DEVICE_ID_VIRTIO_NET,
- .revision = VIRTIO_PCI_ABI_VERSION,
- .class_id = PCI_CLASS_NETWORK_ETHERNET,
- .qdev.props = (Property[]) {
- DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
- VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, false),
- DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
- DEFINE_VIRTIO_NET_FEATURES(VirtIOPCIProxy, host_features),
- DEFINE_NIC_PROPERTIES(VirtIOPCIProxy, nic),
- DEFINE_PROP_UINT32("x-txtimer", VirtIOPCIProxy,
- net.txtimer, TX_TIMER_INTERVAL),
- DEFINE_PROP_INT32("x-txburst", VirtIOPCIProxy,
- net.txburst, TX_BURST),
- DEFINE_PROP_STRING("tx", VirtIOPCIProxy, net.tx),
- DEFINE_PROP_END_OF_LIST(),
- },
- .qdev.reset = virtio_pci_reset,
- },{
- .qdev.name = "virtio-serial-pci",
- .qdev.alias = "virtio-serial",
- .qdev.size = sizeof(VirtIOPCIProxy),
- .init = virtio_serial_init_pci,
- .exit = virtio_serial_exit_pci,
- .vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET,
- .device_id = PCI_DEVICE_ID_VIRTIO_CONSOLE,
- .revision = VIRTIO_PCI_ABI_VERSION,
- .class_id = PCI_CLASS_COMMUNICATION_OTHER,
- .qdev.props = (Property[]) {
- DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
- VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
- DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors,
- DEV_NVECTORS_UNSPECIFIED),
- DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
- DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
- DEFINE_PROP_UINT32("max_ports", VirtIOPCIProxy,
- serial.max_virtserial_ports, 31),
- DEFINE_PROP_END_OF_LIST(),
- },
- .qdev.reset = virtio_pci_reset,
- },{
- .qdev.name = "virtio-balloon-pci",
- .qdev.alias = "virtio-balloon",
- .qdev.size = sizeof(VirtIOPCIProxy),
- .init = virtio_balloon_init_pci,
- .exit = virtio_balloon_exit_pci,
- .vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET,
- .device_id = PCI_DEVICE_ID_VIRTIO_BALLOON,
- .revision = VIRTIO_PCI_ABI_VERSION,
- .class_id = PCI_CLASS_MEMORY_RAM,
- .qdev.props = (Property[]) {
- DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
- DEFINE_PROP_END_OF_LIST(),
- },
- .qdev.reset = virtio_pci_reset,
- },{
- /* end of list */
- }
+static PCIDeviceInfo virtio_blk_info = {
+ .qdev.name = "virtio-blk-pci",
+ .qdev.alias = "virtio-blk",
+ .qdev.size = sizeof(VirtIOPCIProxy),
+ .init = virtio_blk_init_pci,
+ .exit = virtio_blk_exit_pci,
+ .vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET,
+ .device_id = PCI_DEVICE_ID_VIRTIO_BLOCK,
+ .revision = VIRTIO_PCI_ABI_VERSION,
+ .class_id = PCI_CLASS_STORAGE_SCSI,
+ .qdev.props = (Property[]) {
+ DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
+ DEFINE_BLOCK_PROPERTIES(VirtIOPCIProxy, block),
+ DEFINE_PROP_STRING("serial", VirtIOPCIProxy, block_serial),
+ DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
+ DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
+ DEFINE_VIRTIO_BLK_FEATURES(VirtIOPCIProxy, host_features),
+ DEFINE_PROP_END_OF_LIST(),
+ },
+ .qdev.reset = virtio_pci_reset,
+};
+
+static PCIDeviceInfo virtio_net_info = {
+ .qdev.name = "virtio-net-pci",
+ .qdev.alias = "virtio-net",
+ .qdev.size = sizeof(VirtIOPCIProxy),
+ .init = virtio_net_init_pci,
+ .exit = virtio_net_exit_pci,
+ .romfile = "pxe-virtio.rom",
+ .vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET,
+ .device_id = PCI_DEVICE_ID_VIRTIO_NET,
+ .revision = VIRTIO_PCI_ABI_VERSION,
+ .class_id = PCI_CLASS_NETWORK_ETHERNET,
+ .qdev.props = (Property[]) {
+ DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, false),
+ DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
+ DEFINE_VIRTIO_NET_FEATURES(VirtIOPCIProxy, host_features),
+ DEFINE_NIC_PROPERTIES(VirtIOPCIProxy, nic),
+ DEFINE_PROP_UINT32("x-txtimer", VirtIOPCIProxy, net.txtimer, TX_TIMER_INTERVAL),
+ DEFINE_PROP_INT32("x-txburst", VirtIOPCIProxy, net.txburst, TX_BURST),
+ DEFINE_PROP_STRING("tx", VirtIOPCIProxy, net.tx),
+ DEFINE_PROP_END_OF_LIST(),
+ },
+ .qdev.reset = virtio_pci_reset,
+};
+
+static PCIDeviceInfo virtio_serial_info = {
+ .qdev.name = "virtio-serial-pci",
+ .qdev.alias = "virtio-serial",
+ .qdev.size = sizeof(VirtIOPCIProxy),
+ .init = virtio_serial_init_pci,
+ .exit = virtio_serial_exit_pci,
+ .vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET,
+ .device_id = PCI_DEVICE_ID_VIRTIO_CONSOLE,
+ .revision = VIRTIO_PCI_ABI_VERSION,
+ .class_id = PCI_CLASS_COMMUNICATION_OTHER,
+ .qdev.props = (Property[]) {
+ DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
+ DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, DEV_NVECTORS_UNSPECIFIED),
+ DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
+ DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
+ DEFINE_PROP_UINT32("max_ports", VirtIOPCIProxy, serial.max_virtserial_ports, 31),
+ DEFINE_PROP_END_OF_LIST(),
+ },
+ .qdev.reset = virtio_pci_reset,
+};
+
+static PCIDeviceInfo virtio_balloon_info = {
+ .qdev.name = "virtio-balloon-pci",
+ .qdev.alias = "virtio-balloon",
+ .qdev.size = sizeof(VirtIOPCIProxy),
+ .init = virtio_balloon_init_pci,
+ .exit = virtio_balloon_exit_pci,
+ .vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET,
+ .device_id = PCI_DEVICE_ID_VIRTIO_BALLOON,
+ .revision = VIRTIO_PCI_ABI_VERSION,
+ .class_id = PCI_CLASS_MEMORY_RAM,
+ .qdev.props = (Property[]) {
+ DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
+ DEFINE_PROP_END_OF_LIST(),
+ },
+ .qdev.reset = virtio_pci_reset,
};
static void virtio_pci_register_devices(void)
{
- pci_qdev_register_many(virtio_info);
+ pci_qdev_register(virtio_blk_info);
+ pci_qdev_register(virtio_net_info);
+ pci_qdev_register(virtio_serial_info);
+ pci_qdev_register(virtio_balloon_info);
}
device_init(virtio_pci_register_devices)
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 068/197] Patch monkey PCIDeviceInfo conversion
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (64 preceding siblings ...)
2011-12-12 20:19 ` [Qemu-devel] [PATCH v3 067/197] remove arrays of PCIDeviceInfo Anthony Liguori
@ 2011-12-12 20:19 ` Anthony Liguori
2011-12-12 20:19 ` [Qemu-devel] [PATCH v3 069/197] patch monkey, that funky monkey Anthony Liguori
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:19 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/ac97.c | 39 +++++++++------
hw/acpi_piix4.c | 43 ++++++++++-------
hw/apb_pci.c | 54 +++++++++++++--------
hw/bonito.c | 30 +++++++-----
hw/cirrus_vga.c | 29 +++++++----
hw/dec_pci.c | 56 ++++++++++++++--------
hw/e1000.c | 43 ++++++++++-------
hw/es1370.c | 31 +++++++-----
hw/grackle_pci.c | 23 ++++++---
hw/gt64xxx.c | 23 ++++++---
hw/intel-hda.c | 45 +++++++++++-------
hw/ioh3420.c | 57 ++++++++++++----------
hw/ivshmem.c | 47 +++++++++++-------
hw/lsi53c895a.c | 31 +++++++-----
hw/ne2000.c | 35 +++++++++-----
hw/pcnet-pci.c | 39 +++++++++------
hw/ppce500_pci.c | 21 ++++++---
hw/qxl.c | 62 +++++++++++++++---------
hw/rtl8139.c | 41 ++++++++++------
hw/sh_pci.c | 19 +++++--
hw/spapr_pci.c | 15 ++++--
hw/sun4u.c | 23 ++++++---
hw/unin_pci.c | 92 +++++++++++++++++++++++------------
hw/usb-ohci.c | 37 +++++++++------
hw/versatile_pci.c | 22 ++++++---
hw/vga-pci.c | 27 ++++++----
hw/vmware_vga.c | 34 ++++++++------
hw/vt82c686.c | 120 +++++++++++++++++++++++++++++------------------
hw/wdt_i6300esb.c | 31 +++++++-----
hw/xen_platform.c | 34 ++++++++------
hw/xio3130_downstream.c | 57 ++++++++++++----------
hw/xio3130_upstream.c | 51 +++++++++++---------
32 files changed, 806 insertions(+), 505 deletions(-)
diff --git a/hw/ac97.c b/hw/ac97.c
index 0dbba3b..3f8075a 100644
--- a/hw/ac97.c
+++ b/hw/ac97.c
@@ -1341,21 +1341,30 @@ int ac97_init (PCIBus *bus)
return 0;
}
-static PCIDeviceInfo ac97_info = {
- .qdev.name = "AC97",
- .qdev.desc = "Intel 82801AA AC97 Audio",
- .qdev.size = sizeof (AC97LinkState),
- .qdev.vmsd = &vmstate_ac97,
- .init = ac97_initfn,
- .exit = ac97_exitfn,
- .vendor_id = PCI_VENDOR_ID_INTEL,
- .device_id = PCI_DEVICE_ID_INTEL_82801AA_5,
- .revision = 0x01,
- .class_id = PCI_CLASS_MULTIMEDIA_AUDIO,
- .qdev.props = (Property[]) {
- DEFINE_PROP_UINT32("use_broken_id", AC97LinkState, use_broken_id, 0),
- DEFINE_PROP_END_OF_LIST(),
- }
+static Property ac97_properties[] = {
+ DEFINE_PROP_UINT32("use_broken_id", AC97LinkState, use_broken_id, 0),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void ac97_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = ac97_initfn;
+ k->exit = ac97_exitfn;
+ k->vendor_id = PCI_VENDOR_ID_INTEL;
+ k->device_id = PCI_DEVICE_ID_INTEL_82801AA_5;
+ k->revision = 0x01;
+ k->class_id = PCI_CLASS_MULTIMEDIA_AUDIO;
+}
+
+static DeviceInfo ac97_info = {
+ .name = "AC97",
+ .desc = "Intel 82801AA AC97 Audio",
+ .size = sizeof (AC97LinkState),
+ .vmsd = &vmstate_ac97,
+ .props = ac97_properties,
+ .class_init = ac97_class_init,
};
static void ac97_register (void)
diff --git a/hw/acpi_piix4.c b/hw/acpi_piix4.c
index ce7135b..c62f03a 100644
--- a/hw/acpi_piix4.c
+++ b/hw/acpi_piix4.c
@@ -394,23 +394,32 @@ i2c_bus *piix4_pm_init(PCIBus *bus, DeviceState **pdev, int devfn,
return s->smb.smbus;
}
-static PCIDeviceInfo piix4_pm_info = {
- .qdev.name = "PIIX4_PM",
- .qdev.desc = "PM",
- .qdev.size = sizeof(PIIX4PMState),
- .qdev.vmsd = &vmstate_acpi,
- .qdev.no_user = 1,
- .no_hotplug = 1,
- .init = piix4_pm_initfn,
- .config_write = pm_write_config,
- .vendor_id = PCI_VENDOR_ID_INTEL,
- .device_id = PCI_DEVICE_ID_INTEL_82371AB_3,
- .revision = 0x03,
- .class_id = PCI_CLASS_BRIDGE_OTHER,
- .qdev.props = (Property[]) {
- DEFINE_PROP_UINT32("smb_io_base", PIIX4PMState, smb_io_base, 0),
- DEFINE_PROP_END_OF_LIST(),
- }
+static Property piix4_pm_properties[] = {
+ DEFINE_PROP_UINT32("smb_io_base", PIIX4PMState, smb_io_base, 0),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void piix4_pm_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->no_hotplug = 1;
+ k->init = piix4_pm_initfn;
+ k->config_write = pm_write_config;
+ k->vendor_id = PCI_VENDOR_ID_INTEL;
+ k->device_id = PCI_DEVICE_ID_INTEL_82371AB_3;
+ k->revision = 0x03;
+ k->class_id = PCI_CLASS_BRIDGE_OTHER;
+}
+
+static DeviceInfo piix4_pm_info = {
+ .name = "PIIX4_PM",
+ .desc = "PM",
+ .size = sizeof(PIIX4PMState),
+ .vmsd = &vmstate_acpi,
+ .no_user = 1,
+ .props = piix4_pm_properties,
+ .class_init = piix4_pm_class_init,
};
static void piix4_pm_register(void)
diff --git a/hw/apb_pci.c b/hw/apb_pci.c
index c232946..7442e26 100644
--- a/hw/apb_pci.c
+++ b/hw/apb_pci.c
@@ -436,14 +436,21 @@ static int pbm_pci_host_init(PCIDevice *d)
return 0;
}
-static PCIDeviceInfo pbm_pci_host_info = {
- .qdev.name = "pbm",
- .qdev.size = sizeof(PCIDevice),
- .init = pbm_pci_host_init,
- .vendor_id = PCI_VENDOR_ID_SUN,
- .device_id = PCI_DEVICE_ID_SUN_SABRE,
- .class_id = PCI_CLASS_BRIDGE_HOST,
- .is_bridge = 1,
+static void pbm_pci_host_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = pbm_pci_host_init;
+ k->vendor_id = PCI_VENDOR_ID_SUN;
+ k->device_id = PCI_DEVICE_ID_SUN_SABRE;
+ k->class_id = PCI_CLASS_BRIDGE_HOST;
+ k->is_bridge = 1;
+}
+
+static DeviceInfo pbm_pci_host_info = {
+ .name = "pbm",
+ .size = sizeof(PCIDevice),
+ .class_init = pbm_pci_host_class_init,
};
static SysBusDeviceInfo pbm_host_info = {
@@ -453,18 +460,25 @@ static SysBusDeviceInfo pbm_host_info = {
.init = pci_pbm_init_device,
};
-static PCIDeviceInfo pbm_pci_bridge_info = {
- .qdev.name = "pbm-bridge",
- .qdev.size = sizeof(PCIBridge),
- .qdev.vmsd = &vmstate_pci_device,
- .qdev.reset = pci_bridge_reset,
- .init = apb_pci_bridge_initfn,
- .exit = pci_bridge_exitfn,
- .vendor_id = PCI_VENDOR_ID_SUN,
- .device_id = PCI_DEVICE_ID_SUN_SIMBA,
- .revision = 0x11,
- .config_write = pci_bridge_write_config,
- .is_bridge = 1,
+static void pbm_pci_bridge_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = apb_pci_bridge_initfn;
+ k->exit = pci_bridge_exitfn;
+ k->vendor_id = PCI_VENDOR_ID_SUN;
+ k->device_id = PCI_DEVICE_ID_SUN_SIMBA;
+ k->revision = 0x11;
+ k->config_write = pci_bridge_write_config;
+ k->is_bridge = 1;
+}
+
+static DeviceInfo pbm_pci_bridge_info = {
+ .name = "pbm-bridge",
+ .size = sizeof(PCIBridge),
+ .vmsd = &vmstate_pci_device,
+ .reset = pci_bridge_reset,
+ .class_init = pbm_pci_bridge_class_init,
};
static void pbm_register_devices(void)
diff --git a/hw/bonito.c b/hw/bonito.c
index fdb8198..a23182d 100644
--- a/hw/bonito.c
+++ b/hw/bonito.c
@@ -788,18 +788,24 @@ PCIBus *bonito_init(qemu_irq *pic)
return b;
}
-static PCIDeviceInfo bonito_info = {
- .qdev.name = "Bonito",
- .qdev.desc = "Host bridge",
- .qdev.size = sizeof(PCIBonitoState),
- .qdev.vmsd = &vmstate_bonito,
- .qdev.no_user = 1,
- .init = bonito_initfn,
- /*Bonito North Bridge, built on FPGA, VENDOR_ID/DEVICE_ID are "undefined"*/
- .vendor_id = 0xdf53,
- .device_id = 0x00d5,
- .revision = 0x01,
- .class_id = PCI_CLASS_BRIDGE_HOST,
+static void bonito_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = bonito_initfn;
+ k->vendor_id = 0xdf53;
+ k->device_id = 0x00d5;
+ k->revision = 0x01;
+ k->class_id = PCI_CLASS_BRIDGE_HOST;
+}
+
+static DeviceInfo bonito_info = {
+ .name = "Bonito",
+ .desc = "Host bridge",
+ .size = sizeof(PCIBonitoState),
+ .vmsd = &vmstate_bonito,
+ .no_user = 1,
+ .class_init = bonito_class_init,
};
static SysBusDeviceInfo bonito_pcihost_info = {
diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c
index d6d9d70..5718ba7 100644
--- a/hw/cirrus_vga.c
+++ b/hw/cirrus_vga.c
@@ -2962,17 +2962,24 @@ DeviceState *pci_cirrus_vga_init(PCIBus *bus)
return &pci_create_simple(bus, -1, "cirrus-vga")->qdev;
}
-static PCIDeviceInfo cirrus_vga_info = {
- .qdev.name = "cirrus-vga",
- .qdev.desc = "Cirrus CLGD 54xx VGA",
- .qdev.size = sizeof(PCICirrusVGAState),
- .qdev.vmsd = &vmstate_pci_cirrus_vga,
- .no_hotplug = 1,
- .init = pci_cirrus_vga_initfn,
- .romfile = VGABIOS_CIRRUS_FILENAME,
- .vendor_id = PCI_VENDOR_ID_CIRRUS,
- .device_id = CIRRUS_ID_CLGD5446,
- .class_id = PCI_CLASS_DISPLAY_VGA,
+static void cirrus_vga_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->no_hotplug = 1;
+ k->init = pci_cirrus_vga_initfn;
+ k->romfile = VGABIOS_CIRRUS_FILENAME;
+ k->vendor_id = PCI_VENDOR_ID_CIRRUS;
+ k->device_id = CIRRUS_ID_CLGD5446;
+ k->class_id = PCI_CLASS_DISPLAY_VGA;
+}
+
+static DeviceInfo cirrus_vga_info = {
+ .name = "cirrus-vga",
+ .desc = "Cirrus CLGD 54xx VGA",
+ .size = sizeof(PCICirrusVGAState),
+ .vmsd = &vmstate_pci_cirrus_vga,
+ .class_init = cirrus_vga_class_init,
};
static void cirrus_vga_register(void)
diff --git a/hw/dec_pci.c b/hw/dec_pci.c
index 1aec066..0dd940c 100644
--- a/hw/dec_pci.c
+++ b/hw/dec_pci.c
@@ -50,18 +50,25 @@ static int dec_map_irq(PCIDevice *pci_dev, int irq_num)
return irq_num;
}
-static PCIDeviceInfo dec_21154_pci_bridge_info = {
- .qdev.name = "dec-21154-p2p-bridge",
- .qdev.desc = "DEC 21154 PCI-PCI bridge",
- .qdev.size = sizeof(PCIBridge),
- .qdev.vmsd = &vmstate_pci_device,
- .qdev.reset = pci_bridge_reset,
- .init = pci_bridge_initfn,
- .exit = pci_bridge_exitfn,
- .vendor_id = PCI_VENDOR_ID_DEC,
- .device_id = PCI_DEVICE_ID_DEC_21154,
- .config_write = pci_bridge_write_config,
- .is_bridge = 1,
+static void dec_21154_pci_bridge_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = pci_bridge_initfn;
+ k->exit = pci_bridge_exitfn;
+ k->vendor_id = PCI_VENDOR_ID_DEC;
+ k->device_id = PCI_DEVICE_ID_DEC_21154;
+ k->config_write = pci_bridge_write_config;
+ k->is_bridge = 1;
+}
+
+static DeviceInfo dec_21154_pci_bridge_info = {
+ .name = "dec-21154-p2p-bridge",
+ .desc = "DEC 21154 PCI-PCI bridge",
+ .size = sizeof(PCIBridge),
+ .vmsd = &vmstate_pci_device,
+ .reset = pci_bridge_reset,
+ .class_init = dec_21154_pci_bridge_class_init,
};
PCIBus *pci_dec_21154_init(PCIBus *parent_bus, int devfn)
@@ -98,15 +105,22 @@ static int dec_21154_pci_host_init(PCIDevice *d)
return 0;
}
-static PCIDeviceInfo dec_21154_pci_host_info = {
- .qdev.name = "dec-21154",
- .qdev.size = sizeof(PCIDevice),
- .init = dec_21154_pci_host_init,
- .vendor_id = PCI_VENDOR_ID_DEC,
- .device_id = PCI_DEVICE_ID_DEC_21154,
- .revision = 0x02,
- .class_id = PCI_CLASS_BRIDGE_PCI,
- .is_bridge = 1,
+static void dec_21154_pci_host_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = dec_21154_pci_host_init;
+ k->vendor_id = PCI_VENDOR_ID_DEC;
+ k->device_id = PCI_DEVICE_ID_DEC_21154;
+ k->revision = 0x02;
+ k->class_id = PCI_CLASS_BRIDGE_PCI;
+ k->is_bridge = 1;
+}
+
+static DeviceInfo dec_21154_pci_host_info = {
+ .name = "dec-21154",
+ .size = sizeof(PCIDevice),
+ .class_init = dec_21154_pci_host_class_init,
};
static void dec_register_devices(void)
diff --git a/hw/e1000.c b/hw/e1000.c
index 2f495cd..de346e6 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -1190,23 +1190,32 @@ static void qdev_e1000_reset(DeviceState *dev)
e1000_reset(d);
}
-static PCIDeviceInfo e1000_info = {
- .qdev.name = "e1000",
- .qdev.desc = "Intel Gigabit Ethernet",
- .qdev.size = sizeof(E1000State),
- .qdev.reset = qdev_e1000_reset,
- .qdev.vmsd = &vmstate_e1000,
- .init = pci_e1000_init,
- .exit = pci_e1000_uninit,
- .romfile = "pxe-e1000.rom",
- .vendor_id = PCI_VENDOR_ID_INTEL,
- .device_id = E1000_DEVID,
- .revision = 0x03,
- .class_id = PCI_CLASS_NETWORK_ETHERNET,
- .qdev.props = (Property[]) {
- DEFINE_NIC_PROPERTIES(E1000State, conf),
- DEFINE_PROP_END_OF_LIST(),
- }
+static Property e1000_properties[] = {
+ DEFINE_NIC_PROPERTIES(E1000State, conf),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void e1000_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = pci_e1000_init;
+ k->exit = pci_e1000_uninit;
+ k->romfile = "pxe-e1000.rom";
+ k->vendor_id = PCI_VENDOR_ID_INTEL;
+ k->device_id = E1000_DEVID;
+ k->revision = 0x03;
+ k->class_id = PCI_CLASS_NETWORK_ETHERNET;
+}
+
+static DeviceInfo e1000_info = {
+ .name = "e1000",
+ .desc = "Intel Gigabit Ethernet",
+ .size = sizeof(E1000State),
+ .reset = qdev_e1000_reset,
+ .vmsd = &vmstate_e1000,
+ .props = e1000_properties,
+ .class_init = e1000_class_init,
};
static void e1000_register_devices(void)
diff --git a/hw/es1370.c b/hw/es1370.c
index 8a7ca65..32a9b8e 100644
--- a/hw/es1370.c
+++ b/hw/es1370.c
@@ -1031,18 +1031,25 @@ int es1370_init (PCIBus *bus)
return 0;
}
-static PCIDeviceInfo es1370_info = {
- .qdev.name = "ES1370",
- .qdev.desc = "ENSONIQ AudioPCI ES1370",
- .qdev.size = sizeof (ES1370State),
- .qdev.vmsd = &vmstate_es1370,
- .init = es1370_initfn,
- .exit = es1370_exitfn,
- .vendor_id = PCI_VENDOR_ID_ENSONIQ,
- .device_id = PCI_DEVICE_ID_ENSONIQ_ES1370,
- .class_id = PCI_CLASS_MULTIMEDIA_AUDIO,
- .subsystem_vendor_id = 0x4942,
- .subsystem_id = 0x4c4c,
+static void es1370_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = es1370_initfn;
+ k->exit = es1370_exitfn;
+ k->vendor_id = PCI_VENDOR_ID_ENSONIQ;
+ k->device_id = PCI_DEVICE_ID_ENSONIQ_ES1370;
+ k->class_id = PCI_CLASS_MULTIMEDIA_AUDIO;
+ k->subsystem_vendor_id = 0x4942;
+ k->subsystem_id = 0x4c4c;
+}
+
+static DeviceInfo es1370_info = {
+ .name = "ES1370",
+ .desc = "ENSONIQ AudioPCI ES1370",
+ .size = sizeof (ES1370State),
+ .vmsd = &vmstate_es1370,
+ .class_init = es1370_class_init,
};
static void es1370_register (void)
diff --git a/hw/grackle_pci.c b/hw/grackle_pci.c
index 94a608e..0d6a71c 100644
--- a/hw/grackle_pci.c
+++ b/hw/grackle_pci.c
@@ -121,14 +121,21 @@ static int grackle_pci_host_init(PCIDevice *d)
return 0;
}
-static PCIDeviceInfo grackle_pci_host_info = {
- .qdev.name = "grackle",
- .qdev.size = sizeof(PCIDevice),
- .init = grackle_pci_host_init,
- .vendor_id = PCI_VENDOR_ID_MOTOROLA,
- .device_id = PCI_DEVICE_ID_MOTOROLA_MPC106,
- .revision = 0x00,
- .class_id = PCI_CLASS_BRIDGE_HOST,
+static void grackle_pci_host_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = grackle_pci_host_init;
+ k->vendor_id = PCI_VENDOR_ID_MOTOROLA;
+ k->device_id = PCI_DEVICE_ID_MOTOROLA_MPC106;
+ k->revision = 0x00;
+ k->class_id = PCI_CLASS_BRIDGE_HOST;
+}
+
+static DeviceInfo grackle_pci_host_info = {
+ .name = "grackle",
+ .size = sizeof(PCIDevice),
+ .class_init = grackle_pci_host_class_init,
};
static void grackle_register_devices(void)
diff --git a/hw/gt64xxx.c b/hw/gt64xxx.c
index 432683a..9fc51f2 100644
--- a/hw/gt64xxx.c
+++ b/hw/gt64xxx.c
@@ -1136,14 +1136,21 @@ static int gt64120_pci_init(PCIDevice *d)
return 0;
}
-static PCIDeviceInfo gt64120_pci_info = {
- .qdev.name = "gt64120_pci",
- .qdev.size = sizeof(PCIDevice),
- .init = gt64120_pci_init,
- .vendor_id = PCI_VENDOR_ID_MARVELL,
- .device_id = PCI_DEVICE_ID_MARVELL_GT6412X,
- .revision = 0x10,
- .class_id = PCI_CLASS_BRIDGE_HOST,
+static void gt64120_pci_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = gt64120_pci_init;
+ k->vendor_id = PCI_VENDOR_ID_MARVELL;
+ k->device_id = PCI_DEVICE_ID_MARVELL_GT6412X;
+ k->revision = 0x10;
+ k->class_id = PCI_CLASS_BRIDGE_HOST;
+}
+
+static DeviceInfo gt64120_pci_info = {
+ .name = "gt64120_pci",
+ .size = sizeof(PCIDevice),
+ .class_init = gt64120_pci_class_init,
};
static void gt64120_pci_register_devices(void)
diff --git a/hw/intel-hda.c b/hw/intel-hda.c
index 97a6216..7d7b7c9 100644
--- a/hw/intel-hda.c
+++ b/hw/intel-hda.c
@@ -1246,24 +1246,33 @@ static const VMStateDescription vmstate_intel_hda = {
}
};
-static PCIDeviceInfo intel_hda_info = {
- .qdev.name = "intel-hda",
- .qdev.desc = "Intel HD Audio Controller",
- .qdev.size = sizeof(IntelHDAState),
- .qdev.vmsd = &vmstate_intel_hda,
- .qdev.reset = intel_hda_reset,
- .init = intel_hda_init,
- .exit = intel_hda_exit,
- .config_write = intel_hda_write_config,
- .vendor_id = PCI_VENDOR_ID_INTEL,
- .device_id = 0x2668,
- .revision = 1,
- .class_id = PCI_CLASS_MULTIMEDIA_HD_AUDIO,
- .qdev.props = (Property[]) {
- DEFINE_PROP_UINT32("debug", IntelHDAState, debug, 0),
- DEFINE_PROP_UINT32("msi", IntelHDAState, msi, 1),
- DEFINE_PROP_END_OF_LIST(),
- }
+static Property intel_hda_properties[] = {
+ DEFINE_PROP_UINT32("debug", IntelHDAState, debug, 0),
+ DEFINE_PROP_UINT32("msi", IntelHDAState, msi, 1),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void intel_hda_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = intel_hda_init;
+ k->exit = intel_hda_exit;
+ k->config_write = intel_hda_write_config;
+ k->vendor_id = PCI_VENDOR_ID_INTEL;
+ k->device_id = 0x2668;
+ k->revision = 1;
+ k->class_id = PCI_CLASS_MULTIMEDIA_HD_AUDIO;
+}
+
+static DeviceInfo intel_hda_info = {
+ .name = "intel-hda",
+ .desc = "Intel HD Audio Controller",
+ .size = sizeof(IntelHDAState),
+ .vmsd = &vmstate_intel_hda,
+ .reset = intel_hda_reset,
+ .props = intel_hda_properties,
+ .class_init = intel_hda_class_init,
};
static TypeInfo hda_codec_device_type_info = {
diff --git a/hw/ioh3420.c b/hw/ioh3420.c
index 93f53dd..6cfafb3 100644
--- a/hw/ioh3420.c
+++ b/hw/ioh3420.c
@@ -201,31 +201,38 @@ static const VMStateDescription vmstate_ioh3420 = {
}
};
-static PCIDeviceInfo ioh3420_info = {
- .qdev.name = "ioh3420",
- .qdev.desc = "Intel IOH device id 3420 PCIE Root Port",
- .qdev.size = sizeof(PCIESlot),
- .qdev.reset = ioh3420_reset,
- .qdev.vmsd = &vmstate_ioh3420,
-
- .is_express = 1,
- .is_bridge = 1,
- .config_write = ioh3420_write_config,
- .init = ioh3420_initfn,
- .exit = ioh3420_exitfn,
- .vendor_id = PCI_VENDOR_ID_INTEL,
- .device_id = PCI_DEVICE_ID_IOH_EPORT,
- .revision = PCI_DEVICE_ID_IOH_REV,
-
- .qdev.props = (Property[]) {
- DEFINE_PROP_UINT8("port", PCIESlot, port.port, 0),
- DEFINE_PROP_UINT8("chassis", PCIESlot, chassis, 0),
- DEFINE_PROP_UINT16("slot", PCIESlot, slot, 0),
- DEFINE_PROP_UINT16("aer_log_max", PCIESlot,
- port.br.dev.exp.aer_log.log_max,
- PCIE_AER_LOG_MAX_DEFAULT),
- DEFINE_PROP_END_OF_LIST(),
- }
+static Property ioh3420_properties[] = {
+ DEFINE_PROP_UINT8("port", PCIESlot, port.port, 0),
+ DEFINE_PROP_UINT8("chassis", PCIESlot, chassis, 0),
+ DEFINE_PROP_UINT16("slot", PCIESlot, slot, 0),
+ DEFINE_PROP_UINT16("aer_log_max", PCIESlot,
+ port.br.dev.exp.aer_log.log_max,
+ PCIE_AER_LOG_MAX_DEFAULT),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void ioh3420_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->is_express = 1;
+ k->is_bridge = 1;
+ k->config_write = ioh3420_write_config;
+ k->init = ioh3420_initfn;
+ k->exit = ioh3420_exitfn;
+ k->vendor_id = PCI_VENDOR_ID_INTEL;
+ k->device_id = PCI_DEVICE_ID_IOH_EPORT;
+ k->revision = PCI_DEVICE_ID_IOH_REV;
+}
+
+static DeviceInfo ioh3420_info = {
+ .name = "ioh3420",
+ .desc = "Intel IOH device id 3420 PCIE Root Port",
+ .size = sizeof(PCIESlot),
+ .reset = ioh3420_reset,
+ .vmsd = &vmstate_ioh3420,
+ .props = ioh3420_properties,
+ .class_init = ioh3420_class_init,
};
static void ioh3420_register(void)
diff --git a/hw/ivshmem.c b/hw/ivshmem.c
index 7b4dbf6..cddbf21 100644
--- a/hw/ivshmem.c
+++ b/hw/ivshmem.c
@@ -760,25 +760,34 @@ static int pci_ivshmem_uninit(PCIDevice *dev)
return 0;
}
-static PCIDeviceInfo ivshmem_info = {
- .qdev.name = "ivshmem",
- .qdev.size = sizeof(IVShmemState),
- .qdev.reset = ivshmem_reset,
- .init = pci_ivshmem_init,
- .exit = pci_ivshmem_uninit,
- .vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET,
- .device_id = 0x1110,
- .class_id = PCI_CLASS_MEMORY_RAM,
- .qdev.props = (Property[]) {
- DEFINE_PROP_CHR("chardev", IVShmemState, server_chr),
- DEFINE_PROP_STRING("size", IVShmemState, sizearg),
- DEFINE_PROP_UINT32("vectors", IVShmemState, vectors, 1),
- DEFINE_PROP_BIT("ioeventfd", IVShmemState, features, IVSHMEM_IOEVENTFD, false),
- DEFINE_PROP_BIT("msi", IVShmemState, features, IVSHMEM_MSI, true),
- DEFINE_PROP_STRING("shm", IVShmemState, shmobj),
- DEFINE_PROP_STRING("role", IVShmemState, role),
- DEFINE_PROP_END_OF_LIST(),
- }
+static Property ivshmem_properties[] = {
+ DEFINE_PROP_CHR("chardev", IVShmemState, server_chr),
+ DEFINE_PROP_STRING("size", IVShmemState, sizearg),
+ DEFINE_PROP_UINT32("vectors", IVShmemState, vectors, 1),
+ DEFINE_PROP_BIT("ioeventfd", IVShmemState, features, IVSHMEM_IOEVENTFD, false),
+ DEFINE_PROP_BIT("msi", IVShmemState, features, IVSHMEM_MSI, true),
+ DEFINE_PROP_STRING("shm", IVShmemState, shmobj),
+ DEFINE_PROP_STRING("role", IVShmemState, role),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void ivshmem_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = pci_ivshmem_init;
+ k->exit = pci_ivshmem_uninit;
+ k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
+ k->device_id = 0x1110;
+ k->class_id = PCI_CLASS_MEMORY_RAM;
+}
+
+static DeviceInfo ivshmem_info = {
+ .name = "ivshmem",
+ .size = sizeof(IVShmemState),
+ .reset = ivshmem_reset,
+ .props = ivshmem_properties,
+ .class_init = ivshmem_class_init,
};
static void ivshmem_register_devices(void)
diff --git a/hw/lsi53c895a.c b/hw/lsi53c895a.c
index 110ca44..025c85b 100644
--- a/hw/lsi53c895a.c
+++ b/hw/lsi53c895a.c
@@ -2120,18 +2120,25 @@ static int lsi_scsi_init(PCIDevice *dev)
return 0;
}
-static PCIDeviceInfo lsi_info = {
- .qdev.name = "lsi53c895a",
- .qdev.alias = "lsi",
- .qdev.size = sizeof(LSIState),
- .qdev.reset = lsi_scsi_reset,
- .qdev.vmsd = &vmstate_lsi_scsi,
- .init = lsi_scsi_init,
- .exit = lsi_scsi_uninit,
- .vendor_id = PCI_VENDOR_ID_LSI_LOGIC,
- .device_id = PCI_DEVICE_ID_LSI_53C895A,
- .class_id = PCI_CLASS_STORAGE_SCSI,
- .subsystem_id = 0x1000,
+static void lsi_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = lsi_scsi_init;
+ k->exit = lsi_scsi_uninit;
+ k->vendor_id = PCI_VENDOR_ID_LSI_LOGIC;
+ k->device_id = PCI_DEVICE_ID_LSI_53C895A;
+ k->class_id = PCI_CLASS_STORAGE_SCSI;
+ k->subsystem_id = 0x1000;
+}
+
+static DeviceInfo lsi_info = {
+ .name = "lsi53c895a",
+ .alias = "lsi",
+ .size = sizeof(LSIState),
+ .reset = lsi_scsi_reset,
+ .vmsd = &vmstate_lsi_scsi,
+ .class_init = lsi_class_init,
};
static void lsi53c895a_register_devices(void)
diff --git a/hw/ne2000.c b/hw/ne2000.c
index 16dcee2..6484aef 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -786,19 +786,28 @@ static int pci_ne2000_exit(PCIDevice *pci_dev)
return 0;
}
-static PCIDeviceInfo ne2000_info = {
- .qdev.name = "ne2k_pci",
- .qdev.size = sizeof(PCINE2000State),
- .qdev.vmsd = &vmstate_pci_ne2000,
- .init = pci_ne2000_init,
- .exit = pci_ne2000_exit,
- .vendor_id = PCI_VENDOR_ID_REALTEK,
- .device_id = PCI_DEVICE_ID_REALTEK_8029,
- .class_id = PCI_CLASS_NETWORK_ETHERNET,
- .qdev.props = (Property[]) {
- DEFINE_NIC_PROPERTIES(PCINE2000State, ne2000.c),
- DEFINE_PROP_END_OF_LIST(),
- }
+static Property ne2000_properties[] = {
+ DEFINE_NIC_PROPERTIES(PCINE2000State, ne2000.c),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void ne2000_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = pci_ne2000_init;
+ k->exit = pci_ne2000_exit;
+ k->vendor_id = PCI_VENDOR_ID_REALTEK;
+ k->device_id = PCI_DEVICE_ID_REALTEK_8029;
+ k->class_id = PCI_CLASS_NETWORK_ETHERNET;
+}
+
+static DeviceInfo ne2000_info = {
+ .name = "ne2k_pci",
+ .size = sizeof(PCINE2000State),
+ .vmsd = &vmstate_pci_ne2000,
+ .props = ne2000_properties,
+ .class_init = ne2000_class_init,
};
static void ne2000_register_devices(void)
diff --git a/hw/pcnet-pci.c b/hw/pcnet-pci.c
index 4e164da..be3bd79 100644
--- a/hw/pcnet-pci.c
+++ b/hw/pcnet-pci.c
@@ -348,21 +348,30 @@ static void pci_reset(DeviceState *dev)
pcnet_h_reset(&d->state);
}
-static PCIDeviceInfo pcnet_info = {
- .qdev.name = "pcnet",
- .qdev.size = sizeof(PCIPCNetState),
- .qdev.reset = pci_reset,
- .qdev.vmsd = &vmstate_pci_pcnet,
- .init = pci_pcnet_init,
- .exit = pci_pcnet_uninit,
- .vendor_id = PCI_VENDOR_ID_AMD,
- .device_id = PCI_DEVICE_ID_AMD_LANCE,
- .revision = 0x10,
- .class_id = PCI_CLASS_NETWORK_ETHERNET,
- .qdev.props = (Property[]) {
- DEFINE_NIC_PROPERTIES(PCIPCNetState, state.conf),
- DEFINE_PROP_END_OF_LIST(),
- }
+static Property pcnet_properties[] = {
+ DEFINE_NIC_PROPERTIES(PCIPCNetState, state.conf),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void pcnet_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = pci_pcnet_init;
+ k->exit = pci_pcnet_uninit;
+ k->vendor_id = PCI_VENDOR_ID_AMD;
+ k->device_id = PCI_DEVICE_ID_AMD_LANCE;
+ k->revision = 0x10;
+ k->class_id = PCI_CLASS_NETWORK_ETHERNET;
+}
+
+static DeviceInfo pcnet_info = {
+ .name = "pcnet",
+ .size = sizeof(PCIPCNetState),
+ .reset = pci_reset,
+ .vmsd = &vmstate_pci_pcnet,
+ .props = pcnet_properties,
+ .class_init = pcnet_class_init,
};
static void pci_pcnet_register_devices(void)
diff --git a/hw/ppce500_pci.c b/hw/ppce500_pci.c
index 960a5d0..622cd72 100644
--- a/hw/ppce500_pci.c
+++ b/hw/ppce500_pci.c
@@ -360,13 +360,20 @@ static int e500_pcihost_initfn(SysBusDevice *dev)
return 0;
}
-static PCIDeviceInfo e500_host_bridge_info = {
- .qdev.name = "e500-host-bridge",
- .qdev.desc = "Host bridge",
- .qdev.size = sizeof(PCIDevice),
- .vendor_id = PCI_VENDOR_ID_FREESCALE,
- .device_id = PCI_DEVICE_ID_MPC8533E,
- .class_id = PCI_CLASS_PROCESSOR_POWERPC,
+static void e500_host_bridge_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->vendor_id = PCI_VENDOR_ID_FREESCALE;
+ k->device_id = PCI_DEVICE_ID_MPC8533E;
+ k->class_id = PCI_CLASS_PROCESSOR_POWERPC;
+}
+
+static DeviceInfo e500_host_bridge_info = {
+ .name = "e500-host-bridge",
+ .desc = "Host bridge",
+ .size = sizeof(PCIDevice),
+ .class_init = e500_host_bridge_class_init,
};
static SysBusDeviceInfo e500_pcihost_info = {
diff --git a/hw/qxl.c b/hw/qxl.c
index 5f30525..3e2653d 100644
--- a/hw/qxl.c
+++ b/hw/qxl.c
@@ -1827,32 +1827,46 @@ static Property qxl_properties[] = {
DEFINE_PROP_END_OF_LIST(),
};
-static PCIDeviceInfo qxl_primary_info = {
- .qdev.name = "qxl-vga",
- .qdev.desc = "Spice QXL GPU (primary, vga compatible)",
- .qdev.size = sizeof(PCIQXLDevice),
- .qdev.reset = qxl_reset_handler,
- .qdev.vmsd = &qxl_vmstate,
- .no_hotplug = 1,
- .init = qxl_init_primary,
- .romfile = "vgabios-qxl.bin",
- .vendor_id = REDHAT_PCI_VENDOR_ID,
- .device_id = QXL_DEVICE_ID_STABLE,
- .class_id = PCI_CLASS_DISPLAY_VGA,
- .qdev.props = qxl_properties,
+static void qxl_primary_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->no_hotplug = 1;
+ k->init = qxl_init_primary;
+ k->romfile = "vgabios-qxl.bin";
+ k->vendor_id = REDHAT_PCI_VENDOR_ID;
+ k->device_id = QXL_DEVICE_ID_STABLE;
+ k->class_id = PCI_CLASS_DISPLAY_VGA;
+}
+
+static DeviceInfo qxl_primary_info = {
+ .name = "qxl-vga",
+ .desc = "Spice QXL GPU (primary, vga compatible)",
+ .size = sizeof(PCIQXLDevice),
+ .reset = qxl_reset_handler,
+ .vmsd = &qxl_vmstate,
+ .props = qxl_properties,
+ .class_init = qxl_primary_class_init,
};
-static PCIDeviceInfo qxl_secondary_info = {
- .qdev.name = "qxl",
- .qdev.desc = "Spice QXL GPU (secondary)",
- .qdev.size = sizeof(PCIQXLDevice),
- .qdev.reset = qxl_reset_handler,
- .qdev.vmsd = &qxl_vmstate,
- .init = qxl_init_secondary,
- .vendor_id = REDHAT_PCI_VENDOR_ID,
- .device_id = QXL_DEVICE_ID_STABLE,
- .class_id = PCI_CLASS_DISPLAY_OTHER,
- .qdev.props = qxl_properties,
+static void qxl_secondary_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = qxl_init_secondary;
+ k->vendor_id = REDHAT_PCI_VENDOR_ID;
+ k->device_id = QXL_DEVICE_ID_STABLE;
+ k->class_id = PCI_CLASS_DISPLAY_OTHER;
+}
+
+static DeviceInfo qxl_secondary_info = {
+ .name = "qxl",
+ .desc = "Spice QXL GPU (secondary)",
+ .size = sizeof(PCIQXLDevice),
+ .reset = qxl_reset_handler,
+ .vmsd = &qxl_vmstate,
+ .props = qxl_properties,
+ .class_init = qxl_secondary_class_init,
};
static void qxl_register(void)
diff --git a/hw/rtl8139.c b/hw/rtl8139.c
index 0143fa2..7ceabe6 100644
--- a/hw/rtl8139.c
+++ b/hw/rtl8139.c
@@ -3494,22 +3494,31 @@ static int pci_rtl8139_init(PCIDevice *dev)
return 0;
}
-static PCIDeviceInfo rtl8139_info = {
- .qdev.name = "rtl8139",
- .qdev.size = sizeof(RTL8139State),
- .qdev.reset = rtl8139_reset,
- .qdev.vmsd = &vmstate_rtl8139,
- .init = pci_rtl8139_init,
- .exit = pci_rtl8139_uninit,
- .romfile = "pxe-rtl8139.rom",
- .vendor_id = PCI_VENDOR_ID_REALTEK,
- .device_id = PCI_DEVICE_ID_REALTEK_8139,
- .revision = RTL8139_PCI_REVID, /* >=0x20 is for 8139C+ */
- .class_id = PCI_CLASS_NETWORK_ETHERNET,
- .qdev.props = (Property[]) {
- DEFINE_NIC_PROPERTIES(RTL8139State, conf),
- DEFINE_PROP_END_OF_LIST(),
- }
+static Property rtl8139_properties[] = {
+ DEFINE_NIC_PROPERTIES(RTL8139State, conf),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void rtl8139_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = pci_rtl8139_init;
+ k->exit = pci_rtl8139_uninit;
+ k->romfile = "pxe-rtl8139.rom";
+ k->vendor_id = PCI_VENDOR_ID_REALTEK;
+ k->device_id = PCI_DEVICE_ID_REALTEK_8139;
+ k->revision = RTL8139_PCI_REVID, /* >=0x20 is for 8139C+ */;
+ k->class_id = PCI_CLASS_NETWORK_ETHERNET;
+}
+
+static DeviceInfo rtl8139_info = {
+ .name = "rtl8139",
+ .size = sizeof(RTL8139State),
+ .reset = rtl8139_reset,
+ .vmsd = &vmstate_rtl8139,
+ .props = rtl8139_properties,
+ .class_init = rtl8139_class_init,
};
static void rtl8139_register_devices(void)
diff --git a/hw/sh_pci.c b/hw/sh_pci.c
index 36f3930..d2a4130 100644
--- a/hw/sh_pci.c
+++ b/hw/sh_pci.c
@@ -168,12 +168,19 @@ static int sh_pci_host_init(PCIDevice *d)
return 0;
}
-static PCIDeviceInfo sh_pci_host_info = {
- .qdev.name = "sh_pci_host",
- .qdev.size = sizeof(PCIDevice),
- .init = sh_pci_host_init,
- .vendor_id = PCI_VENDOR_ID_HITACHI,
- .device_id = PCI_DEVICE_ID_HITACHI_SH7751R,
+static void sh_pci_host_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = sh_pci_host_init;
+ k->vendor_id = PCI_VENDOR_ID_HITACHI;
+ k->device_id = PCI_DEVICE_ID_HITACHI_SH7751R;
+}
+
+static DeviceInfo sh_pci_host_info = {
+ .name = "sh_pci_host",
+ .size = sizeof(PCIDevice),
+ .class_init = sh_pci_host_class_init,
};
static void sh_pci_register_devices(void)
diff --git a/hw/spapr_pci.c b/hw/spapr_pci.c
index f456501..a5bddda 100644
--- a/hw/spapr_pci.c
+++ b/hw/spapr_pci.c
@@ -190,10 +190,17 @@ static int spapr_main_pci_host_init(PCIDevice *d)
return 0;
}
-static PCIDeviceInfo spapr_main_pci_host_info = {
- .qdev.name = "spapr-pci-host-bridge",
- .qdev.size = sizeof(PCIDevice),
- .init = spapr_main_pci_host_init,
+static void spapr_main_pci_host_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = spapr_main_pci_host_init;
+}
+
+static DeviceInfo spapr_main_pci_host_info = {
+ .name = "spapr-pci-host-bridge",
+ .size = sizeof(PCIDevice),
+ .class_init = spapr_main_pci_host_class_init,
};
static void spapr_register_devices(void)
diff --git a/hw/sun4u.c b/hw/sun4u.c
index eaaefe3..f3240a6 100644
--- a/hw/sun4u.c
+++ b/hw/sun4u.c
@@ -557,14 +557,21 @@ pci_ebus_init1(PCIDevice *pci_dev)
return 0;
}
-static PCIDeviceInfo ebus_info = {
- .qdev.name = "ebus",
- .qdev.size = sizeof(EbusState),
- .init = pci_ebus_init1,
- .vendor_id = PCI_VENDOR_ID_SUN,
- .device_id = PCI_DEVICE_ID_SUN_EBUS,
- .revision = 0x01,
- .class_id = PCI_CLASS_BRIDGE_OTHER,
+static void ebus_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = pci_ebus_init1;
+ k->vendor_id = PCI_VENDOR_ID_SUN;
+ k->device_id = PCI_DEVICE_ID_SUN_EBUS;
+ k->revision = 0x01;
+ k->class_id = PCI_CLASS_BRIDGE_OTHER;
+}
+
+static DeviceInfo ebus_info = {
+ .name = "ebus",
+ .size = sizeof(EbusState),
+ .class_init = ebus_class_init,
};
static void pci_ebus_register(void)
diff --git a/hw/unin_pci.c b/hw/unin_pci.c
index 4299052..ac443a2 100644
--- a/hw/unin_pci.c
+++ b/hw/unin_pci.c
@@ -334,44 +334,72 @@ static int unin_internal_pci_host_init(PCIDevice *d)
return 0;
}
-static PCIDeviceInfo unin_main_pci_host_info = {
- .qdev.name = "uni-north",
- .qdev.size = sizeof(PCIDevice),
- .init = unin_main_pci_host_init,
- .vendor_id = PCI_VENDOR_ID_APPLE,
- .device_id = PCI_DEVICE_ID_APPLE_UNI_N_PCI,
- .revision = 0x00,
- .class_id = PCI_CLASS_BRIDGE_HOST,
+static void unin_main_pci_host_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = unin_main_pci_host_init;
+ k->vendor_id = PCI_VENDOR_ID_APPLE;
+ k->device_id = PCI_DEVICE_ID_APPLE_UNI_N_PCI;
+ k->revision = 0x00;
+ k->class_id = PCI_CLASS_BRIDGE_HOST;
+}
+
+static DeviceInfo unin_main_pci_host_info = {
+ .name = "uni-north",
+ .size = sizeof(PCIDevice),
+ .class_init = unin_main_pci_host_class_init,
};
-static PCIDeviceInfo u3_agp_pci_host_info = {
- .qdev.name = "u3-agp",
- .qdev.size = sizeof(PCIDevice),
- .init = u3_agp_pci_host_init,
- .vendor_id = PCI_VENDOR_ID_APPLE,
- .device_id = PCI_DEVICE_ID_APPLE_U3_AGP,
- .revision = 0x00,
- .class_id = PCI_CLASS_BRIDGE_HOST,
+static void u3_agp_pci_host_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = u3_agp_pci_host_init;
+ k->vendor_id = PCI_VENDOR_ID_APPLE;
+ k->device_id = PCI_DEVICE_ID_APPLE_U3_AGP;
+ k->revision = 0x00;
+ k->class_id = PCI_CLASS_BRIDGE_HOST;
+}
+
+static DeviceInfo u3_agp_pci_host_info = {
+ .name = "u3-agp",
+ .size = sizeof(PCIDevice),
+ .class_init = u3_agp_pci_host_class_init,
};
-static PCIDeviceInfo unin_agp_pci_host_info = {
- .qdev.name = "uni-north-agp",
- .qdev.size = sizeof(PCIDevice),
- .init = unin_agp_pci_host_init,
- .vendor_id = PCI_VENDOR_ID_APPLE,
- .device_id = PCI_DEVICE_ID_APPLE_UNI_N_AGP,
- .revision = 0x00,
- .class_id = PCI_CLASS_BRIDGE_HOST,
+static void unin_agp_pci_host_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = unin_agp_pci_host_init;
+ k->vendor_id = PCI_VENDOR_ID_APPLE;
+ k->device_id = PCI_DEVICE_ID_APPLE_UNI_N_AGP;
+ k->revision = 0x00;
+ k->class_id = PCI_CLASS_BRIDGE_HOST;
+}
+
+static DeviceInfo unin_agp_pci_host_info = {
+ .name = "uni-north-agp",
+ .size = sizeof(PCIDevice),
+ .class_init = unin_agp_pci_host_class_init,
};
-static PCIDeviceInfo unin_internal_pci_host_info = {
- .qdev.name = "uni-north-pci",
- .qdev.size = sizeof(PCIDevice),
- .init = unin_internal_pci_host_init,
- .vendor_id = PCI_VENDOR_ID_APPLE,
- .device_id = PCI_DEVICE_ID_APPLE_UNI_N_I_PCI,
- .revision = 0x00,
- .class_id = PCI_CLASS_BRIDGE_HOST,
+static void unin_internal_pci_host_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = unin_internal_pci_host_init;
+ k->vendor_id = PCI_VENDOR_ID_APPLE;
+ k->device_id = PCI_DEVICE_ID_APPLE_UNI_N_I_PCI;
+ k->revision = 0x00;
+ k->class_id = PCI_CLASS_BRIDGE_HOST;
+}
+
+static DeviceInfo unin_internal_pci_host_info = {
+ .name = "uni-north-pci",
+ .size = sizeof(PCIDevice),
+ .class_init = unin_internal_pci_host_class_init,
};
static void unin_register_devices(void)
diff --git a/hw/usb-ohci.c b/hw/usb-ohci.c
index 194c994..3378fc0 100644
--- a/hw/usb-ohci.c
+++ b/hw/usb-ohci.c
@@ -1834,20 +1834,29 @@ static int ohci_init_pxa(SysBusDevice *dev)
return 0;
}
-static PCIDeviceInfo ohci_pci_info = {
- .qdev.name = "pci-ohci",
- .qdev.desc = "Apple USB Controller",
- .qdev.size = sizeof(OHCIPCIState),
- .init = usb_ohci_initfn_pci,
- .vendor_id = PCI_VENDOR_ID_APPLE,
- .device_id = PCI_DEVICE_ID_APPLE_IPID_USB,
- .class_id = PCI_CLASS_SERIAL_USB,
- .qdev.props = (Property[]) {
- DEFINE_PROP_STRING("masterbus", OHCIPCIState, masterbus),
- DEFINE_PROP_UINT32("num-ports", OHCIPCIState, num_ports, 3),
- DEFINE_PROP_UINT32("firstport", OHCIPCIState, firstport, 0),
- DEFINE_PROP_END_OF_LIST(),
- },
+static Property ohci_pci_properties[] = {
+ DEFINE_PROP_STRING("masterbus", OHCIPCIState, masterbus),
+ DEFINE_PROP_UINT32("num-ports", OHCIPCIState, num_ports, 3),
+ DEFINE_PROP_UINT32("firstport", OHCIPCIState, firstport, 0),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void ohci_pci_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = usb_ohci_initfn_pci;
+ k->vendor_id = PCI_VENDOR_ID_APPLE;
+ k->device_id = PCI_DEVICE_ID_APPLE_IPID_USB;
+ k->class_id = PCI_CLASS_SERIAL_USB;
+}
+
+static DeviceInfo ohci_pci_info = {
+ .name = "pci-ohci",
+ .desc = "Apple USB Controller",
+ .size = sizeof(OHCIPCIState),
+ .props = ohci_pci_properties,
+ .class_init = ohci_pci_class_init,
};
static SysBusDeviceInfo ohci_sysbus_info = {
diff --git a/hw/versatile_pci.c b/hw/versatile_pci.c
index 8a88696..5710177 100644
--- a/hw/versatile_pci.c
+++ b/hw/versatile_pci.c
@@ -109,14 +109,20 @@ static int versatile_pci_host_init(PCIDevice *d)
return 0;
}
-static PCIDeviceInfo versatile_pci_host_info = {
- .qdev.name = "versatile_pci_host",
- .qdev.size = sizeof(PCIDevice),
- .init = versatile_pci_host_init,
- .vendor_id = PCI_VENDOR_ID_XILINX,
- /* Both boards have the same device ID. Oh well. */
- .device_id = PCI_DEVICE_ID_XILINX_XC2VP30,
- .class_id = PCI_CLASS_PROCESSOR_CO,
+static void versatile_pci_host_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = versatile_pci_host_init;
+ k->vendor_id = PCI_VENDOR_ID_XILINX;
+ k->device_id = PCI_DEVICE_ID_XILINX_XC2VP30;
+ k->class_id = PCI_CLASS_PROCESSOR_CO;
+}
+
+static DeviceInfo versatile_pci_host_info = {
+ .name = "versatile_pci_host",
+ .size = sizeof(PCIDevice),
+ .class_init = versatile_pci_host_class_init,
};
static void versatile_pci_register_devices(void)
diff --git a/hw/vga-pci.c b/hw/vga-pci.c
index a75dbf3..ef9f8a5 100644
--- a/hw/vga-pci.c
+++ b/hw/vga-pci.c
@@ -75,18 +75,23 @@ DeviceState *pci_vga_init(PCIBus *bus)
return &pci_create_simple(bus, -1, "VGA")->qdev;
}
-static PCIDeviceInfo vga_info = {
- .qdev.name = "VGA",
- .qdev.size = sizeof(PCIVGAState),
- .qdev.vmsd = &vmstate_vga_pci,
- .no_hotplug = 1,
- .init = pci_vga_initfn,
- .romfile = "vgabios-stdvga.bin",
+static void vga_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->no_hotplug = 1;
+ k->init = pci_vga_initfn;
+ k->romfile = "vgabios-stdvga.bin";
+ k->vendor_id = PCI_VENDOR_ID_QEMU;
+ k->device_id = PCI_DEVICE_ID_QEMU_VGA;
+ k->class_id = PCI_CLASS_DISPLAY_VGA;
+}
- /* dummy VGA (same as Bochs ID) */
- .vendor_id = PCI_VENDOR_ID_QEMU,
- .device_id = PCI_DEVICE_ID_QEMU_VGA,
- .class_id = PCI_CLASS_DISPLAY_VGA,
+static DeviceInfo vga_info = {
+ .name = "VGA",
+ .size = sizeof(PCIVGAState),
+ .vmsd = &vmstate_vga_pci,
+ .class_init = vga_class_init,
};
static void vga_register(void)
diff --git a/hw/vmware_vga.c b/hw/vmware_vga.c
index af70bde..e2791cb 100644
--- a/hw/vmware_vga.c
+++ b/hw/vmware_vga.c
@@ -1198,20 +1198,26 @@ static int pci_vmsvga_initfn(PCIDevice *dev)
return 0;
}
-static PCIDeviceInfo vmsvga_info = {
- .qdev.name = "vmware-svga",
- .qdev.size = sizeof(struct pci_vmsvga_state_s),
- .qdev.vmsd = &vmstate_vmware_vga,
- .qdev.reset = vmsvga_reset,
- .no_hotplug = 1,
- .init = pci_vmsvga_initfn,
- .romfile = "vgabios-vmware.bin",
-
- .vendor_id = PCI_VENDOR_ID_VMWARE,
- .device_id = SVGA_PCI_DEVICE_ID,
- .class_id = PCI_CLASS_DISPLAY_VGA,
- .subsystem_vendor_id = PCI_VENDOR_ID_VMWARE,
- .subsystem_id = SVGA_PCI_DEVICE_ID,
+static void vmsvga_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->no_hotplug = 1;
+ k->init = pci_vmsvga_initfn;
+ k->romfile = "vgabios-vmware.bin";
+ k->vendor_id = PCI_VENDOR_ID_VMWARE;
+ k->device_id = SVGA_PCI_DEVICE_ID;
+ k->class_id = PCI_CLASS_DISPLAY_VGA;
+ k->subsystem_vendor_id = PCI_VENDOR_ID_VMWARE;
+ k->subsystem_id = SVGA_PCI_DEVICE_ID;
+}
+
+static DeviceInfo vmsvga_info = {
+ .name = "vmware-svga",
+ .size = sizeof(struct pci_vmsvga_state_s),
+ .vmsd = &vmstate_vmware_vga,
+ .reset = vmsvga_reset,
+ .class_init = vmsvga_class_init,
};
static void vmsvga_register(void)
diff --git a/hw/vt82c686.c b/hw/vt82c686.c
index 2845959..e3f677b 100644
--- a/hw/vt82c686.c
+++ b/hw/vt82c686.c
@@ -343,15 +343,22 @@ void vt82c686b_ac97_init(PCIBus *bus, int devfn)
qdev_init_nofail(&dev->qdev);
}
-static PCIDeviceInfo via_ac97_info = {
- .qdev.name = "VT82C686B_AC97",
- .qdev.desc = "AC97",
- .qdev.size = sizeof(VT686AC97State),
- .init = vt82c686b_ac97_initfn,
- .vendor_id = PCI_VENDOR_ID_VIA,
- .device_id = PCI_DEVICE_ID_VIA_AC97,
- .revision = 0x50,
- .class_id = PCI_CLASS_MULTIMEDIA_AUDIO,
+static void via_ac97_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = vt82c686b_ac97_initfn;
+ k->vendor_id = PCI_VENDOR_ID_VIA;
+ k->device_id = PCI_DEVICE_ID_VIA_AC97;
+ k->revision = 0x50;
+ k->class_id = PCI_CLASS_MULTIMEDIA_AUDIO;
+}
+
+static DeviceInfo via_ac97_info = {
+ .name = "VT82C686B_AC97",
+ .desc = "AC97",
+ .size = sizeof(VT686AC97State),
+ .class_init = via_ac97_class_init,
};
static void vt82c686b_ac97_register(void)
@@ -382,15 +389,22 @@ void vt82c686b_mc97_init(PCIBus *bus, int devfn)
qdev_init_nofail(&dev->qdev);
}
-static PCIDeviceInfo via_mc97_info = {
- .qdev.name = "VT82C686B_MC97",
- .qdev.desc = "MC97",
- .qdev.size = sizeof(VT686MC97State),
- .init = vt82c686b_mc97_initfn,
- .vendor_id = PCI_VENDOR_ID_VIA,
- .device_id = PCI_DEVICE_ID_VIA_MC97,
- .class_id = PCI_CLASS_COMMUNICATION_OTHER,
- .revision = 0x30,
+static void via_mc97_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = vt82c686b_mc97_initfn;
+ k->vendor_id = PCI_VENDOR_ID_VIA;
+ k->device_id = PCI_DEVICE_ID_VIA_MC97;
+ k->class_id = PCI_CLASS_COMMUNICATION_OTHER;
+ k->revision = 0x30;
+}
+
+static DeviceInfo via_mc97_info = {
+ .name = "VT82C686B_MC97",
+ .desc = "MC97",
+ .size = sizeof(VT686MC97State),
+ .class_init = via_mc97_class_init,
};
static void vt82c686b_mc97_register(void)
@@ -448,21 +462,30 @@ i2c_bus *vt82c686b_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
return s->smb.smbus;
}
-static PCIDeviceInfo via_pm_info = {
- .qdev.name = "VT82C686B_PM",
- .qdev.desc = "PM",
- .qdev.size = sizeof(VT686PMState),
- .qdev.vmsd = &vmstate_acpi,
- .init = vt82c686b_pm_initfn,
- .config_write = pm_write_config,
- .vendor_id = PCI_VENDOR_ID_VIA,
- .device_id = PCI_DEVICE_ID_VIA_ACPI,
- .class_id = PCI_CLASS_BRIDGE_OTHER,
- .revision = 0x40,
- .qdev.props = (Property[]) {
- DEFINE_PROP_UINT32("smb_io_base", VT686PMState, smb_io_base, 0),
- DEFINE_PROP_END_OF_LIST(),
- }
+static Property via_pm_properties[] = {
+ DEFINE_PROP_UINT32("smb_io_base", VT686PMState, smb_io_base, 0),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void via_pm_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = vt82c686b_pm_initfn;
+ k->config_write = pm_write_config;
+ k->vendor_id = PCI_VENDOR_ID_VIA;
+ k->device_id = PCI_DEVICE_ID_VIA_ACPI;
+ k->class_id = PCI_CLASS_BRIDGE_OTHER;
+ k->revision = 0x40;
+}
+
+static DeviceInfo via_pm_info = {
+ .name = "VT82C686B_PM",
+ .desc = "PM",
+ .size = sizeof(VT686PMState),
+ .vmsd = &vmstate_acpi,
+ .props = via_pm_properties,
+ .class_init = via_pm_class_init,
};
static void vt82c686b_pm_register(void)
@@ -516,18 +539,25 @@ int vt82c686b_init(PCIBus *bus, int devfn)
return d->devfn;
}
-static PCIDeviceInfo via_info = {
- .qdev.name = "VT82C686B",
- .qdev.desc = "ISA bridge",
- .qdev.size = sizeof(VT82C686BState),
- .qdev.vmsd = &vmstate_via,
- .qdev.no_user = 1,
- .init = vt82c686b_initfn,
- .config_write = vt82c686b_write_config,
- .vendor_id = PCI_VENDOR_ID_VIA,
- .device_id = PCI_DEVICE_ID_VIA_ISA_BRIDGE,
- .class_id = PCI_CLASS_BRIDGE_ISA,
- .revision = 0x40,
+static void via_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = vt82c686b_initfn;
+ k->config_write = vt82c686b_write_config;
+ k->vendor_id = PCI_VENDOR_ID_VIA;
+ k->device_id = PCI_DEVICE_ID_VIA_ISA_BRIDGE;
+ k->class_id = PCI_CLASS_BRIDGE_ISA;
+ k->revision = 0x40;
+}
+
+static DeviceInfo via_info = {
+ .name = "VT82C686B",
+ .desc = "ISA bridge",
+ .size = sizeof(VT82C686BState),
+ .vmsd = &vmstate_via,
+ .no_user = 1,
+ .class_init = via_class_init,
};
static void vt82c686b_register(void)
diff --git a/hw/wdt_i6300esb.c b/hw/wdt_i6300esb.c
index 205c32b..a6ceff8 100644
--- a/hw/wdt_i6300esb.c
+++ b/hw/wdt_i6300esb.c
@@ -425,18 +425,25 @@ static WatchdogTimerModel model = {
.wdt_description = "Intel 6300ESB",
};
-static PCIDeviceInfo i6300esb_info = {
- .qdev.name = "i6300esb",
- .qdev.size = sizeof(I6300State),
- .qdev.vmsd = &vmstate_i6300esb,
- .qdev.reset = i6300esb_reset,
- .config_read = i6300esb_config_read,
- .config_write = i6300esb_config_write,
- .init = i6300esb_init,
- .exit = i6300esb_exit,
- .vendor_id = PCI_VENDOR_ID_INTEL,
- .device_id = PCI_DEVICE_ID_INTEL_ESB_9,
- .class_id = PCI_CLASS_SYSTEM_OTHER,
+static void i6300esb_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->config_read = i6300esb_config_read;
+ k->config_write = i6300esb_config_write;
+ k->init = i6300esb_init;
+ k->exit = i6300esb_exit;
+ k->vendor_id = PCI_VENDOR_ID_INTEL;
+ k->device_id = PCI_DEVICE_ID_INTEL_ESB_9;
+ k->class_id = PCI_CLASS_SYSTEM_OTHER;
+}
+
+static DeviceInfo i6300esb_info = {
+ .name = "i6300esb",
+ .size = sizeof(I6300State),
+ .vmsd = &vmstate_i6300esb,
+ .reset = i6300esb_reset,
+ .class_init = i6300esb_class_init,
};
static void i6300esb_register_devices(void)
diff --git a/hw/xen_platform.c b/hw/xen_platform.c
index 5e792f5..6535c1b 100644
--- a/hw/xen_platform.c
+++ b/hw/xen_platform.c
@@ -372,20 +372,26 @@ static void platform_reset(DeviceState *dev)
platform_fixed_ioport_reset(s);
}
-static PCIDeviceInfo xen_platform_info = {
- .init = xen_platform_initfn,
- .qdev.name = "xen-platform",
- .qdev.desc = "XEN platform pci device",
- .qdev.size = sizeof(PCIXenPlatformState),
- .qdev.vmsd = &vmstate_xen_platform,
- .qdev.reset = platform_reset,
-
- .vendor_id = PCI_VENDOR_ID_XEN,
- .device_id = PCI_DEVICE_ID_XEN_PLATFORM,
- .class_id = PCI_CLASS_OTHERS << 8 | 0x80,
- .subsystem_vendor_id = PCI_VENDOR_ID_XEN,
- .subsystem_id = PCI_DEVICE_ID_XEN_PLATFORM,
- .revision = 1,
+static void xen_platform_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = xen_platform_initfn;
+ k->vendor_id = PCI_VENDOR_ID_XEN;
+ k->device_id = PCI_DEVICE_ID_XEN_PLATFORM;
+ k->class_id = PCI_CLASS_OTHERS << 8 | 0x80;
+ k->subsystem_vendor_id = PCI_VENDOR_ID_XEN;
+ k->subsystem_id = PCI_DEVICE_ID_XEN_PLATFORM;
+ k->revision = 1;
+}
+
+static DeviceInfo xen_platform_info = {
+ .name = "xen-platform",
+ .desc = "XEN platform pci device",
+ .size = sizeof(PCIXenPlatformState),
+ .vmsd = &vmstate_xen_platform,
+ .reset = platform_reset,
+ .class_init = xen_platform_class_init,
};
static void xen_platform_register(void)
diff --git a/hw/xio3130_downstream.c b/hw/xio3130_downstream.c
index cb34c6f..6d625cb 100644
--- a/hw/xio3130_downstream.c
+++ b/hw/xio3130_downstream.c
@@ -167,31 +167,38 @@ static const VMStateDescription vmstate_xio3130_downstream = {
}
};
-static PCIDeviceInfo xio3130_downstream_info = {
- .qdev.name = "xio3130-downstream",
- .qdev.desc = "TI X3130 Downstream Port of PCI Express Switch",
- .qdev.size = sizeof(PCIESlot),
- .qdev.reset = xio3130_downstream_reset,
- .qdev.vmsd = &vmstate_xio3130_downstream,
-
- .is_express = 1,
- .is_bridge = 1,
- .config_write = xio3130_downstream_write_config,
- .init = xio3130_downstream_initfn,
- .exit = xio3130_downstream_exitfn,
- .vendor_id = PCI_VENDOR_ID_TI,
- .device_id = PCI_DEVICE_ID_TI_XIO3130D,
- .revision = XIO3130_REVISION,
-
- .qdev.props = (Property[]) {
- DEFINE_PROP_UINT8("port", PCIESlot, port.port, 0),
- DEFINE_PROP_UINT8("chassis", PCIESlot, chassis, 0),
- DEFINE_PROP_UINT16("slot", PCIESlot, slot, 0),
- DEFINE_PROP_UINT16("aer_log_max", PCIESlot,
- port.br.dev.exp.aer_log.log_max,
- PCIE_AER_LOG_MAX_DEFAULT),
- DEFINE_PROP_END_OF_LIST(),
- }
+static Property xio3130_downstream_properties[] = {
+ DEFINE_PROP_UINT8("port", PCIESlot, port.port, 0),
+ DEFINE_PROP_UINT8("chassis", PCIESlot, chassis, 0),
+ DEFINE_PROP_UINT16("slot", PCIESlot, slot, 0),
+ DEFINE_PROP_UINT16("aer_log_max", PCIESlot,
+ port.br.dev.exp.aer_log.log_max,
+ PCIE_AER_LOG_MAX_DEFAULT),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void xio3130_downstream_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->is_express = 1;
+ k->is_bridge = 1;
+ k->config_write = xio3130_downstream_write_config;
+ k->init = xio3130_downstream_initfn;
+ k->exit = xio3130_downstream_exitfn;
+ k->vendor_id = PCI_VENDOR_ID_TI;
+ k->device_id = PCI_DEVICE_ID_TI_XIO3130D;
+ k->revision = XIO3130_REVISION;
+}
+
+static DeviceInfo xio3130_downstream_info = {
+ .name = "xio3130-downstream",
+ .desc = "TI X3130 Downstream Port of PCI Express Switch",
+ .size = sizeof(PCIESlot),
+ .reset = xio3130_downstream_reset,
+ .vmsd = &vmstate_xio3130_downstream,
+ .props = xio3130_downstream_properties,
+ .class_init = xio3130_downstream_class_init,
};
static void xio3130_downstream_register(void)
diff --git a/hw/xio3130_upstream.c b/hw/xio3130_upstream.c
index 9c16ef2..ec4c5e3 100644
--- a/hw/xio3130_upstream.c
+++ b/hw/xio3130_upstream.c
@@ -144,28 +144,35 @@ static const VMStateDescription vmstate_xio3130_upstream = {
}
};
-static PCIDeviceInfo xio3130_upstream_info = {
- .qdev.name = "x3130-upstream",
- .qdev.desc = "TI X3130 Upstream Port of PCI Express Switch",
- .qdev.size = sizeof(PCIEPort),
- .qdev.reset = xio3130_upstream_reset,
- .qdev.vmsd = &vmstate_xio3130_upstream,
-
- .is_express = 1,
- .is_bridge = 1,
- .config_write = xio3130_upstream_write_config,
- .init = xio3130_upstream_initfn,
- .exit = xio3130_upstream_exitfn,
- .vendor_id = PCI_VENDOR_ID_TI,
- .device_id = PCI_DEVICE_ID_TI_XIO3130U,
- .revision = XIO3130_REVISION,
-
- .qdev.props = (Property[]) {
- DEFINE_PROP_UINT8("port", PCIEPort, port, 0),
- DEFINE_PROP_UINT16("aer_log_max", PCIEPort, br.dev.exp.aer_log.log_max,
- PCIE_AER_LOG_MAX_DEFAULT),
- DEFINE_PROP_END_OF_LIST(),
- }
+static Property xio3130_upstream_properties[] = {
+ DEFINE_PROP_UINT8("port", PCIEPort, port, 0),
+ DEFINE_PROP_UINT16("aer_log_max", PCIEPort, br.dev.exp.aer_log.log_max,
+ PCIE_AER_LOG_MAX_DEFAULT),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void xio3130_upstream_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->is_express = 1;
+ k->is_bridge = 1;
+ k->config_write = xio3130_upstream_write_config;
+ k->init = xio3130_upstream_initfn;
+ k->exit = xio3130_upstream_exitfn;
+ k->vendor_id = PCI_VENDOR_ID_TI;
+ k->device_id = PCI_DEVICE_ID_TI_XIO3130U;
+ k->revision = XIO3130_REVISION;
+}
+
+static DeviceInfo xio3130_upstream_info = {
+ .name = "x3130-upstream",
+ .desc = "TI X3130 Upstream Port of PCI Express Switch",
+ .size = sizeof(PCIEPort),
+ .reset = xio3130_upstream_reset,
+ .vmsd = &vmstate_xio3130_upstream,
+ .props = xio3130_upstream_properties,
+ .class_init = xio3130_upstream_class_init,
};
static void xio3130_upstream_register(void)
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread
* [Qemu-devel] [PATCH v3 069/197] patch monkey, that funky monkey
2011-12-12 20:17 [Qemu-devel] [PATCH v3 000/197] qom: dynamic properties and composition tree (v2) Anthony Liguori
` (65 preceding siblings ...)
2011-12-12 20:19 ` [Qemu-devel] [PATCH v3 068/197] Patch monkey PCIDeviceInfo conversion Anthony Liguori
@ 2011-12-12 20:19 ` Anthony Liguori
66 siblings, 0 replies; 74+ messages in thread
From: Anthony Liguori @ 2011-12-12 20:19 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Peter Maydell, Anthony Liguori, Stefan Hajnoczi,
Jan Kiszka, Markus Armbruster, Luiz Capitulino
---
hw/i440fx.c | 33 ++++++----
hw/piix3.c | 71 ++++++++++++---------
hw/piix4.c | 30 +++++----
hw/usb-ehci.c | 54 ++++++++++------
hw/usb-uhci.c | 168 +++++++++++++++++++++++++++++++------------------
hw/virtio-pci.c | 188 +++++++++++++++++++++++++++++++++----------------------
6 files changed, 331 insertions(+), 213 deletions(-)
diff --git a/hw/i440fx.c b/hw/i440fx.c
index db15ce8..2910ef6 100644
--- a/hw/i440fx.c
+++ b/hw/i440fx.c
@@ -345,19 +345,26 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix3_devfn,
return b;
}
-static PCIDeviceInfo i440fx_info = {
- .qdev.name = "i440FX",
- .qdev.desc = "Host bridge",
- .qdev.size = sizeof(PCII440FXState),
- .qdev.vmsd = &vmstate_i440fx,
- .qdev.no_user = 1,
- .no_hotplug = 1,
- .init = i440fx_initfn,
- .config_write = i440fx_write_config,
- .vendor_id = PCI_VENDOR_ID_INTEL,
- .device_id = PCI_DEVICE_ID_INTEL_82441,
- .revision = 0x02,
- .class_id = PCI_CLASS_BRIDGE_HOST,
+static void i440fx_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->no_hotplug = 1;
+ k->init = i440fx_initfn;
+ k->config_write = i440fx_write_config;
+ k->vendor_id = PCI_VENDOR_ID_INTEL;
+ k->device_id = PCI_DEVICE_ID_INTEL_82441;
+ k->revision = 0x02;
+ k->class_id = PCI_CLASS_BRIDGE_HOST;
+}
+
+static DeviceInfo i440fx_info = {
+ .name = "i440FX",
+ .desc = "Host bridge",
+ .size = sizeof(PCII440FXState),
+ .vmsd = &vmstate_i440fx,
+ .no_user = 1,
+ .class_init = i440fx_class_init,
};
static SysBusDeviceInfo i440fx_pcihost_info = {
diff --git a/hw/piix3.c b/hw/piix3.c
index 8a07259..e3bba25 100644
--- a/hw/piix3.c
+++ b/hw/piix3.c
@@ -143,39 +143,52 @@ static int piix3_initfn(PCIDevice *dev)
return 0;
}
-static PCIDeviceInfo piix3_info[] = {
- {
- .qdev.name = "PIIX3",
- .qdev.desc = "ISA bridge",
- .qdev.size = sizeof(PIIX3State),
- .qdev.vmsd = &vmstate_piix3,
- .qdev.no_user = 1,
- .no_hotplug = 1,
- .init = piix3_initfn,
- .config_write = piix3_write_config,
- .vendor_id = PCI_VENDOR_ID_INTEL,
- .device_id = PCI_DEVICE_ID_INTEL_82371SB_0, // 82371SB PIIX3 PCI-to-ISA bridge (Step A1)
- .class_id = PCI_CLASS_BRIDGE_ISA,
- },{
- .qdev.name = "PIIX3-xen",
- .qdev.desc = "ISA bridge",
- .qdev.size = sizeof(PIIX3State),
- .qdev.vmsd = &vmstate_piix3,
- .qdev.no_user = 1,
- .no_hotplug = 1,
- .init = piix3_initfn,
- .config_write = piix3_write_config_xen,
- .vendor_id = PCI_VENDOR_ID_INTEL,
- .device_id = PCI_DEVICE_ID_INTEL_82371SB_0, // 82371SB PIIX3 PCI-to-ISA bridge (Step A1)
- .class_id = PCI_CLASS_BRIDGE_ISA,
- },{
- /* end of list */
- }
+static void piix3_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->no_hotplug = 1;
+ k->init = piix3_initfn;
+ k->config_write = piix3_write_config;
+ k->vendor_id = PCI_VENDOR_ID_INTEL;
+ k->device_id = PCI_DEVICE_ID_INTEL_82371SB_0;
+ k->class_id = PCI_CLASS_BRIDGE_ISA;
+}
+
+static DeviceInfo piix3_info = {
+ .name = "PIIX3",
+ .desc = "ISA bridge",
+ .size = sizeof(PIIX3State),
+ .vmsd = &vmstate_piix3,
+ .no_user = 1,
+ .class_init = piix3_class_init,
+};
+
+static void piix3_xen_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->no_hotplug = 1;
+ k->init = piix3_initfn;
+ k->config_write = piix3_write_config_xen;
+ k->vendor_id = PCI_VENDOR_ID_INTEL;
+ k->device_id = PCI_DEVICE_ID_INTEL_82371SB_0;
+ k->class_id = PCI_CLASS_BRIDGE_ISA;
+}
+
+static DeviceInfo piix3_xen_info = {
+ .name = "PIIX3-xen",
+ .desc = "ISA bridge",
+ .size = sizeof(PIIX3State),
+ .vmsd = &vmstate_piix3,
+ .no_user = 1,
+ .class_init = piix3_xen_class_init,
};
static void piix3_register(void)
{
- pci_qdev_register_many(piix3_info);
+ pci_qdev_register(piix3_info);
+ pci_qdev_register(piix3_xen_info);
}
device_init(piix3_register);
diff --git a/hw/piix4.c b/hw/piix4.c
index 1e959c6..dd76123 100644
--- a/hw/piix4.c
+++ b/hw/piix4.c
@@ -101,18 +101,24 @@ int piix4_init(PCIBus *bus, int devfn)
return d->devfn;
}
-static PCIDeviceInfo piix4_info = {
- .qdev.name = "PIIX4",
- .qdev.desc = "ISA bridge",
- .qdev.size = sizeof(PIIX4State),
- .qdev.vmsd = &vmstate_piix4,
- .qdev.no_user = 1,
- .no_hotplug = 1,
- .init = piix4_initfn,
- .vendor_id = PCI_VENDOR_ID_INTEL,
- /* 82371AB/EB/MB PIIX4 PCI-to-ISA bridge */
- .device_id = PCI_DEVICE_ID_INTEL_82371AB_0,
- .class_id = PCI_CLASS_BRIDGE_ISA,
+static void piix4_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->no_hotplug = 1;
+ k->init = piix4_initfn;
+ k->vendor_id = PCI_VENDOR_ID_INTEL;
+ k->device_id = PCI_DEVICE_ID_INTEL_82371AB_0;
+ k->class_id = PCI_CLASS_BRIDGE_ISA;
+}
+
+static DeviceInfo piix4_info = {
+ .name = "PIIX4",
+ .desc = "ISA bridge",
+ .size = sizeof(PIIX4State),
+ .vmsd = &vmstate_piix4,
+ .no_user = 1,
+ .class_init = piix4_class_init,
};
static void piix4_register(void)
diff --git a/hw/usb-ehci.c b/hw/usb-ehci.c
index 15f0c7d..e14c412 100644
--- a/hw/usb-ehci.c
+++ b/hw/usb-ehci.c
@@ -2262,28 +2262,42 @@ static Property ehci_properties[] = {
DEFINE_PROP_END_OF_LIST(),
};
-static PCIDeviceInfo ehci_info = {
- .qdev.name = "usb-ehci",
- .qdev.size = sizeof(EHCIState),
- .qdev.vmsd = &vmstate_ehci,
- .init = usb_ehci_initfn,
- .vendor_id = PCI_VENDOR_ID_INTEL,
- .device_id = PCI_DEVICE_ID_INTEL_82801D, /* ich4 */
- .revision = 0x10,
- .class_id = PCI_CLASS_SERIAL_USB,
- .qdev.props = ehci_properties,
+static void ehci_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = usb_ehci_initfn;
+ k->vendor_id = PCI_VENDOR_ID_INTEL;
+ k->device_id = PCI_DEVICE_ID_INTEL_82801D, /* ich4 */;
+ k->revision = 0x10;
+ k->class_id = PCI_CLASS_SERIAL_USB;
+}
+
+static DeviceInfo ehci_info = {
+ .name = "usb-ehci",
+ .size = sizeof(EHCIState),
+ .vmsd = &vmstate_ehci,
+ .props = ehci_properties,
+ .class_init = ehci_class_init,
};
-static PCIDeviceInfo ich9_ehci_info = {
- .qdev.name = "ich9-usb-ehci1",
- .qdev.size = sizeof(EHCIState),
- .qdev.vmsd = &vmstate_ehci,
- .init = usb_ehci_initfn,
- .vendor_id = PCI_VENDOR_ID_INTEL,
- .device_id = PCI_DEVICE_ID_INTEL_82801I_EHCI1,
- .revision = 0x03,
- .class_id = PCI_CLASS_SERIAL_USB,
- .qdev.props = ehci_properties,
+static void ich9_ehci_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = usb_ehci_initfn;
+ k->vendor_id = PCI_VENDOR_ID_INTEL;
+ k->device_id = PCI_DEVICE_ID_INTEL_82801I_EHCI1;
+ k->revision = 0x03;
+ k->class_id = PCI_CLASS_SERIAL_USB;
+}
+
+static DeviceInfo ich9_ehci_info = {
+ .name = "ich9-usb-ehci1",
+ .size = sizeof(EHCIState),
+ .vmsd = &vmstate_ehci,
+ .props = ehci_properties,
+ .class_init = ich9_ehci_class_init,
};
static int usb_ehci_initfn(PCIDevice *dev)
diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c
index 9b10501..ad360d3 100644
--- a/hw/usb-uhci.c
+++ b/hw/usb-uhci.c
@@ -1194,79 +1194,121 @@ static Property uhci_properties[] = {
DEFINE_PROP_END_OF_LIST(),
};
-static PCIDeviceInfo piix3_uhci_info = {
- .qdev.name = "piix3-usb-uhci",
- .qdev.size = sizeof(UHCIState),
- .qdev.vmsd = &vmstate_uhci,
- .init = usb_uhci_common_initfn,
- .exit = usb_uhci_exit,
- .vendor_id = PCI_VENDOR_ID_INTEL,
- .device_id = PCI_DEVICE_ID_INTEL_82371SB_2,
- .revision = 0x01,
- .class_id = PCI_CLASS_SERIAL_USB,
- .qdev.props = uhci_properties,
+static void piix3_uhci_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = usb_uhci_common_initfn;
+ k->exit = usb_uhci_exit;
+ k->vendor_id = PCI_VENDOR_ID_INTEL;
+ k->device_id = PCI_DEVICE_ID_INTEL_82371SB_2;
+ k->revision = 0x01;
+ k->class_id = PCI_CLASS_SERIAL_USB;
+}
+
+static DeviceInfo piix3_uhci_info = {
+ .name = "piix3-usb-uhci",
+ .size = sizeof(UHCIState),
+ .vmsd = &vmstate_uhci,
+ .props = uhci_properties,
+ .class_init = piix3_uhci_class_init,
};
-static PCIDeviceInfo piix4_uhci_info = {
- .qdev.name = "piix4-usb-uhci",
- .qdev.size = sizeof(UHCIState),
- .qdev.vmsd = &vmstate_uhci,
- .init = usb_uhci_common_initfn,
- .exit = usb_uhci_exit,
- .vendor_id = PCI_VENDOR_ID_INTEL,
- .device_id = PCI_DEVICE_ID_INTEL_82371AB_2,
- .revision = 0x01,
- .class_id = PCI_CLASS_SERIAL_USB,
- .qdev.props = uhci_properties,
+static void piix4_uhci_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = usb_uhci_common_initfn;
+ k->exit = usb_uhci_exit;
+ k->vendor_id = PCI_VENDOR_ID_INTEL;
+ k->device_id = PCI_DEVICE_ID_INTEL_82371AB_2;
+ k->revision = 0x01;
+ k->class_id = PCI_CLASS_SERIAL_USB;
+}
+
+static DeviceInfo piix4_uhci_info = {
+ .name = "piix4-usb-uhci",
+ .size = sizeof(UHCIState),
+ .vmsd = &vmstate_uhci,
+ .props = uhci_properties,
+ .class_init = piix4_uhci_class_init,
};
-static PCIDeviceInfo vt82c686b_uhci_info = {
- .qdev.name = "vt82c686b-usb-uhci",
- .qdev.size = sizeof(UHCIState),
- .qdev.vmsd = &vmstate_uhci,
- .init = usb_uhci_vt82c686b_initfn,
- .exit = usb_uhci_exit,
- .vendor_id = PCI_VENDOR_ID_VIA,
- .device_id = PCI_DEVICE_ID_VIA_UHCI,
- .revision = 0x01,
- .class_id = PCI_CLASS_SERIAL_USB,
- .qdev.props = uhci_properties,
+static void vt82c686b_uhci_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = usb_uhci_vt82c686b_initfn;
+ k->exit = usb_uhci_exit;
+ k->vendor_id = PCI_VENDOR_ID_VIA;
+ k->device_id = PCI_DEVICE_ID_VIA_UHCI;
+ k->revision = 0x01;
+ k->class_id = PCI_CLASS_SERIAL_USB;
+}
+
+static DeviceInfo vt82c686b_uhci_info = {
+ .name = "vt82c686b-usb-uhci",
+ .size = sizeof(UHCIState),
+ .vmsd = &vmstate_uhci,
+ .props = uhci_properties,
+ .class_init = vt82c686b_uhci_class_init,
};
-static PCIDeviceInfo ich9_uhci1_info = {
- .qdev.name = "ich9-usb-uhci1",
- .qdev.size = sizeof(UHCIState),
- .qdev.vmsd = &vmstate_uhci,
- .init = usb_uhci_common_initfn,
- .vendor_id = PCI_VENDOR_ID_INTEL,
- .device_id = PCI_DEVICE_ID_INTEL_82801I_UHCI1,
- .revision = 0x03,
- .class_id = PCI_CLASS_SERIAL_USB,
- .qdev.props = uhci_properties,
+static void ich9_uhci1_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = usb_uhci_common_initfn;
+ k->vendor_id = PCI_VENDOR_ID_INTEL;
+ k->device_id = PCI_DEVICE_ID_INTEL_82801I_UHCI1;
+ k->revision = 0x03;
+ k->class_id = PCI_CLASS_SERIAL_USB;
+}
+
+static DeviceInfo ich9_uhci1_info = {
+ .name = "ich9-usb-uhci1",
+ .size = sizeof(UHCIState),
+ .vmsd = &vmstate_uhci,
+ .props = uhci_properties,
+ .class_init = ich9_uhci1_class_init,
};
-static PCIDeviceInfo ich9_uhci2_info = {
- .qdev.name = "ich9-usb-uhci2",
- .qdev.size = sizeof(UHCIState),
- .qdev.vmsd = &vmstate_uhci,
- .init = usb_uhci_common_initfn,
- .vendor_id = PCI_VENDOR_ID_INTEL,
- .device_id = PCI_DEVICE_ID_INTEL_82801I_UHCI2,
- .revision = 0x03,
- .class_id = PCI_CLASS_SERIAL_USB,
- .qdev.props = uhci_properties,
+static void ich9_uhci2_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = usb_uhci_common_initfn;
+ k->vendor_id = PCI_VENDOR_ID_INTEL;
+ k->device_id = PCI_DEVICE_ID_INTEL_82801I_UHCI2;
+ k->revision = 0x03;
+ k->class_id = PCI_CLASS_SERIAL_USB;
+}
+
+static DeviceInfo ich9_uhci2_info = {
+ .name = "ich9-usb-uhci2",
+ .size = sizeof(UHCIState),
+ .vmsd = &vmstate_uhci,
+ .props = uhci_properties,
+ .class_init = ich9_uhci2_class_init,
};
-static PCIDeviceInfo ich9_uhci3_info = {
- .qdev.name = "ich9-usb-uhci3",
- .qdev.size = sizeof(UHCIState),
- .qdev.vmsd = &vmstate_uhci,
- .init = usb_uhci_common_initfn,
- .vendor_id = PCI_VENDOR_ID_INTEL,
- .device_id = PCI_DEVICE_ID_INTEL_82801I_UHCI3,
- .revision = 0x03,
- .class_id = PCI_CLASS_SERIAL_USB,
- .qdev.props = uhci_properties,
+static void ich9_uhci3_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = usb_uhci_common_initfn;
+ k->vendor_id = PCI_VENDOR_ID_INTEL;
+ k->device_id = PCI_DEVICE_ID_INTEL_82801I_UHCI3;
+ k->revision = 0x03;
+ k->class_id = PCI_CLASS_SERIAL_USB;
+}
+
+static DeviceInfo ich9_uhci3_info = {
+ .name = "ich9-usb-uhci3",
+ .size = sizeof(UHCIState),
+ .vmsd = &vmstate_uhci,
+ .props = uhci_properties,
+ .class_init = ich9_uhci3_class_init,
};
static void uhci_register(void)
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 885d990..8f7e424 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -779,88 +779,124 @@ static int virtio_balloon_exit_pci(PCIDevice *pci_dev)
return virtio_exit_pci(pci_dev);
}
-static PCIDeviceInfo virtio_blk_info = {
- .qdev.name = "virtio-blk-pci",
- .qdev.alias = "virtio-blk",
- .qdev.size = sizeof(VirtIOPCIProxy),
- .init = virtio_blk_init_pci,
- .exit = virtio_blk_exit_pci,
- .vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET,
- .device_id = PCI_DEVICE_ID_VIRTIO_BLOCK,
- .revision = VIRTIO_PCI_ABI_VERSION,
- .class_id = PCI_CLASS_STORAGE_SCSI,
- .qdev.props = (Property[]) {
- DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
- DEFINE_BLOCK_PROPERTIES(VirtIOPCIProxy, block),
- DEFINE_PROP_STRING("serial", VirtIOPCIProxy, block_serial),
- DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
- DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
- DEFINE_VIRTIO_BLK_FEATURES(VirtIOPCIProxy, host_features),
- DEFINE_PROP_END_OF_LIST(),
- },
- .qdev.reset = virtio_pci_reset,
+static Property virtio_blk_properties[] = {
+ DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
+ DEFINE_BLOCK_PROPERTIES(VirtIOPCIProxy, block),
+ DEFINE_PROP_STRING("serial", VirtIOPCIProxy, block_serial),
+ DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
+ DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
+ DEFINE_VIRTIO_BLK_FEATURES(VirtIOPCIProxy, host_features),
+ DEFINE_PROP_END_OF_LIST(),
};
-static PCIDeviceInfo virtio_net_info = {
- .qdev.name = "virtio-net-pci",
- .qdev.alias = "virtio-net",
- .qdev.size = sizeof(VirtIOPCIProxy),
- .init = virtio_net_init_pci,
- .exit = virtio_net_exit_pci,
- .romfile = "pxe-virtio.rom",
- .vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET,
- .device_id = PCI_DEVICE_ID_VIRTIO_NET,
- .revision = VIRTIO_PCI_ABI_VERSION,
- .class_id = PCI_CLASS_NETWORK_ETHERNET,
- .qdev.props = (Property[]) {
- DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, false),
- DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
- DEFINE_VIRTIO_NET_FEATURES(VirtIOPCIProxy, host_features),
- DEFINE_NIC_PROPERTIES(VirtIOPCIProxy, nic),
- DEFINE_PROP_UINT32("x-txtimer", VirtIOPCIProxy, net.txtimer, TX_TIMER_INTERVAL),
- DEFINE_PROP_INT32("x-txburst", VirtIOPCIProxy, net.txburst, TX_BURST),
- DEFINE_PROP_STRING("tx", VirtIOPCIProxy, net.tx),
- DEFINE_PROP_END_OF_LIST(),
- },
- .qdev.reset = virtio_pci_reset,
+static void virtio_blk_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = virtio_blk_init_pci;
+ k->exit = virtio_blk_exit_pci;
+ k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
+ k->device_id = PCI_DEVICE_ID_VIRTIO_BLOCK;
+ k->revision = VIRTIO_PCI_ABI_VERSION;
+ k->class_id = PCI_CLASS_STORAGE_SCSI;
+}
+
+static DeviceInfo virtio_blk_info = {
+ .name = "virtio-blk-pci",
+ .alias = "virtio-blk",
+ .size = sizeof(VirtIOPCIProxy),
+ .props = virtio_blk_properties,
+ .reset = virtio_pci_reset,
+ .class_init = virtio_blk_class_init,
+};
+
+static Property virtio_net_properties[] = {
+ DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, false),
+ DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
+ DEFINE_VIRTIO_NET_FEATURES(VirtIOPCIProxy, host_features),
+ DEFINE_NIC_PROPERTIES(VirtIOPCIProxy, nic),
+ DEFINE_PROP_UINT32("x-txtimer", VirtIOPCIProxy, net.txtimer, TX_TIMER_INTERVAL),
+ DEFINE_PROP_INT32("x-txburst", VirtIOPCIProxy, net.txburst, TX_BURST),
+ DEFINE_PROP_STRING("tx", VirtIOPCIProxy, net.tx),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_net_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = virtio_net_init_pci;
+ k->exit = virtio_net_exit_pci;
+ k->romfile = "pxe-virtio.rom";
+ k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
+ k->device_id = PCI_DEVICE_ID_VIRTIO_NET;
+ k->revision = VIRTIO_PCI_ABI_VERSION;
+ k->class_id = PCI_CLASS_NETWORK_ETHERNET;
+}
+
+static DeviceInfo virtio_net_info = {
+ .name = "virtio-net-pci",
+ .alias = "virtio-net",
+ .size = sizeof(VirtIOPCIProxy),
+ .props = virtio_net_properties,
+ .reset = virtio_pci_reset,
+ .class_init = virtio_net_class_init,
};
-static PCIDeviceInfo virtio_serial_info = {
- .qdev.name = "virtio-serial-pci",
- .qdev.alias = "virtio-serial",
- .qdev.size = sizeof(VirtIOPCIProxy),
- .init = virtio_serial_init_pci,
- .exit = virtio_serial_exit_pci,
- .vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET,
- .device_id = PCI_DEVICE_ID_VIRTIO_CONSOLE,
- .revision = VIRTIO_PCI_ABI_VERSION,
- .class_id = PCI_CLASS_COMMUNICATION_OTHER,
- .qdev.props = (Property[]) {
- DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
- DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, DEV_NVECTORS_UNSPECIFIED),
- DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
- DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
- DEFINE_PROP_UINT32("max_ports", VirtIOPCIProxy, serial.max_virtserial_ports, 31),
- DEFINE_PROP_END_OF_LIST(),
- },
- .qdev.reset = virtio_pci_reset,
+static Property virtio_serial_properties[] = {
+ DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
+ DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, DEV_NVECTORS_UNSPECIFIED),
+ DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
+ DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
+ DEFINE_PROP_UINT32("max_ports", VirtIOPCIProxy, serial.max_virtserial_ports, 31),
+ DEFINE_PROP_END_OF_LIST(),
};
-static PCIDeviceInfo virtio_balloon_info = {
- .qdev.name = "virtio-balloon-pci",
- .qdev.alias = "virtio-balloon",
- .qdev.size = sizeof(VirtIOPCIProxy),
- .init = virtio_balloon_init_pci,
- .exit = virtio_balloon_exit_pci,
- .vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET,
- .device_id = PCI_DEVICE_ID_VIRTIO_BALLOON,
- .revision = VIRTIO_PCI_ABI_VERSION,
- .class_id = PCI_CLASS_MEMORY_RAM,
- .qdev.props = (Property[]) {
- DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
- DEFINE_PROP_END_OF_LIST(),
- },
- .qdev.reset = virtio_pci_reset,
+static void virtio_serial_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = virtio_serial_init_pci;
+ k->exit = virtio_serial_exit_pci;
+ k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
+ k->device_id = PCI_DEVICE_ID_VIRTIO_CONSOLE;
+ k->revision = VIRTIO_PCI_ABI_VERSION;
+ k->class_id = PCI_CLASS_COMMUNICATION_OTHER;
+}
+
+static DeviceInfo virtio_serial_info = {
+ .name = "virtio-serial-pci",
+ .alias = "virtio-serial",
+ .size = sizeof(VirtIOPCIProxy),
+ .props = virtio_serial_properties,
+ .reset = virtio_pci_reset,
+ .class_init = virtio_serial_class_init,
+};
+
+static Property virtio_balloon_properties[] = {
+ DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_balloon_class_init(ObjectClass *klass, void *data)
+{
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = virtio_balloon_init_pci;
+ k->exit = virtio_balloon_exit_pci;
+ k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
+ k->device_id = PCI_DEVICE_ID_VIRTIO_BALLOON;
+ k->revision = VIRTIO_PCI_ABI_VERSION;
+ k->class_id = PCI_CLASS_MEMORY_RAM;
+}
+
+static DeviceInfo virtio_balloon_info = {
+ .name = "virtio-balloon-pci",
+ .alias = "virtio-balloon",
+ .size = sizeof(VirtIOPCIProxy),
+ .props = virtio_balloon_properties,
+ .reset = virtio_pci_reset,
+ .class_init = virtio_balloon_class_init,
};
static void virtio_pci_register_devices(void)
--
1.7.4.1
^ permalink raw reply related [flat|nested] 74+ messages in thread