[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 032/197] qdev: user a wrapper to access reset and
From: |
Anthony Liguori |
Subject: |
[Qemu-devel] [PATCH v3 032/197] qdev: user a wrapper to access reset and promote reset to a class method |
Date: |
Mon, 12 Dec 2011 14:18:28 -0600 |
---
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
- [Qemu-devel] [PATCH v3 065/197] qxl: be more patch monkey friendly, (continued)
- [Qemu-devel] [PATCH v3 065/197] qxl: be more patch monkey friendly, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 066/197] make es1370 more script monkey friendly, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 067/197] remove arrays of PCIDeviceInfo, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 050/197] accessors for scsideviceinfo, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 012/197] qdev: add explicitly named devices to the root complex, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 043/197] kill off ISADeviceInfo, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 013/197] dev: add an anonymous peripheral container, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 041/197] add class_init to deviceinfo, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 069/197] patch monkey, that funky monkey, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 030/197] qdev: move qdev->info to class, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 032/197] qdev: user a wrapper to access reset and promote reset to a class method,
Anthony Liguori <=
- [Qemu-devel] [PATCH v3 027/197] rename qobject -> object, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 057/197] add SMBusDevice to the type hiearchy, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 029/197] Start integration of qom w/qdev., Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 062/197] killall HDACodecDeviceInfo, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 028/197] more renames, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 053/197] kill off SCSIDeviceInfo, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 019/197] bug fix spotted by paolo, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 014/197] rtc: make piix3 set the rtc as a child (v2), Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 031/197] qdev: don't access name through info, Anthony Liguori, 2011/12/12
- [Qemu-devel] [PATCH v3 063/197] make spapr a bit more patch monkey friendly, Anthony Liguori, 2011/12/12