From patchwork Tue Dec 20 16:51:34 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 132449 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 88AFBB704B for ; Wed, 21 Dec 2011 03:52:34 +1100 (EST) Received: from localhost ([::1]:34462 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rd2vQ-0005J8-RT for incoming@patchwork.ozlabs.org; Tue, 20 Dec 2011 11:52:24 -0500 Received: from eggs.gnu.org ([140.186.70.92]:35334) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rd2vF-00057Q-9V for qemu-devel@nongnu.org; Tue, 20 Dec 2011 11:52:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rd2vE-0006Ta-4l for qemu-devel@nongnu.org; Tue, 20 Dec 2011 11:52:13 -0500 Received: from cpe-70-123-132-139.austin.res.rr.com ([70.123.132.139]:41609 helo=localhost6.localdomain6) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rd2vD-0006TQ-Oi for qemu-devel@nongnu.org; Tue, 20 Dec 2011 11:52:12 -0500 Received: from localhost6.localdomain6 (localhost.localdomain [127.0.0.1]) by localhost6.localdomain6 (8.14.4/8.14.4/Debian-2ubuntu1) with ESMTP id pBKGq8Ga021502; Tue, 20 Dec 2011 10:52:09 -0600 Received: (from anthony@localhost) by localhost6.localdomain6 (8.14.4/8.14.4/Submit) id pBKGq7EZ021496; Tue, 20 Dec 2011 10:52:07 -0600 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Tue, 20 Dec 2011 10:51:34 -0600 Message-Id: <1324399916-21315-6-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1324399916-21315-1-git-send-email-aliguori@us.ibm.com> References: <1324399916-21315-1-git-send-email-aliguori@us.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 70.123.132.139 Cc: Paolo Bonzini , Anthony Liguori , Markus Armbruster Subject: [Qemu-devel] [PATCH 05/27] qdev: use a wrapper to access reset and promote reset to a class method X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Anthony Liguori --- hw/intel-hda.c | 4 +--- hw/lsi53c895a.c | 2 +- hw/qdev.c | 22 +++++++++++++++++----- hw/qdev.h | 10 +++++++++- 4 files changed, 28 insertions(+), 10 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 9f475e0..3a87171 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 5d63c10..3a7c98f 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -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) @@ -374,8 +379,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; } @@ -408,9 +413,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; } @@ -1556,6 +1559,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, diff --git a/hw/qdev.h b/hw/qdev.h index a29ee94..c1fcf28 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -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 @@ -402,7 +403,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); @@ -646,4 +647,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