qdev: use a wrapper to access reset and promote reset to a class method

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Anthony Liguori 2011-12-04 11:36:01 -06:00
parent f79f2bfc6a
commit 94afdadcb3
4 changed files with 27 additions and 9 deletions

View File

@ -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);

View File

@ -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);

View File

@ -48,7 +48,12 @@ static BusState *qbus_find(const char *path);
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)
@ -378,8 +383,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;
}
@ -407,9 +412,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;
}
@ -1593,6 +1596,15 @@ void qdev_machine_init(void)
qdev_get_peripheral();
}
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,

View File

@ -75,6 +75,7 @@ typedef struct DeviceProperty
typedef struct DeviceClass {
ObjectClass parent_class;
DeviceInfo *info;
void (*reset)(DeviceState *dev);
} DeviceClass;
/* This structure should not be accessed directly. We declare it here
@ -647,4 +648,11 @@ char *qdev_get_type(DeviceState *dev, Error **errp);
*/
void qdev_machine_init(void);
/**
* @device_reset
*
* Reset a single device (by calling the reset method).
*/
void device_reset(DeviceState *dev);
#endif