From patchwork Mon Jan 30 21:08:51 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 138656 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 DF76AB6EFF for ; Tue, 31 Jan 2012 08:59:57 +1100 (EST) Received: from localhost ([::1]:34444 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RrzGW-0004fr-4Y for incoming@patchwork.ozlabs.org; Mon, 30 Jan 2012 16:59:56 -0500 Received: from eggs.gnu.org ([140.186.70.92]:41717) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RryTi-0002Ek-Ip for qemu-devel@nongnu.org; Mon, 30 Jan 2012 16:09:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RryTg-00054i-Qw for qemu-devel@nongnu.org; Mon, 30 Jan 2012 16:09:30 -0500 Received: from cpe-70-123-132-139.austin.res.rr.com ([70.123.132.139]:34331 helo=localhost6.localdomain6) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RryTg-00054c-IC for qemu-devel@nongnu.org; Mon, 30 Jan 2012 16:09:28 -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 q0UL9OYD006059; Mon, 30 Jan 2012 15:09:24 -0600 Received: (from anthony@localhost) by localhost6.localdomain6 (8.14.4/8.14.4/Submit) id q0UL9N3f006057; Mon, 30 Jan 2012 15:09:23 -0600 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Mon, 30 Jan 2012 15:08:51 -0600 Message-Id: <1327957741-5842-13-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1327957741-5842-1-git-send-email-aliguori@us.ibm.com> References: <1327957741-5842-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 , Andreas Faerber , Anthony Liguori , Peter Maydell Subject: [Qemu-devel] [PATCH 13/23] qdev: split out common init to instance_init 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 This gets us closer to being able to object_new() a qdev type and have a functioning object verses having to call qdev_create(). Signed-off-by: Anthony Liguori --- hw/qdev.c | 41 ++++++++++++++++++++++++++++------------- 1 files changed, 28 insertions(+), 13 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index a7980c5..491f45e 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -124,31 +124,22 @@ static DeviceState *qdev_create_from_info(BusState *bus, const char *typename) Property *prop; dev = DEVICE(object_new(typename)); + dev->parent_bus = bus; - qdev_prop_set_defaults(dev, qdev_get_props(dev)); qdev_prop_set_defaults(dev, dev->parent_bus->info->props); - qdev_prop_set_globals(dev); - QTAILQ_INSERT_HEAD(&bus->children, dev, sibling); + if (qdev_hotplug) { assert(bus->allow_hotplug); - dev->hotplugged = 1; - qdev_hot_added = true; } - dev->instance_id_alias = -1; - QTAILQ_INIT(&dev->properties); - dev->state = DEV_STATE_CREATED; - for (prop = qdev_get_props(dev); prop && prop->name; prop++) { - qdev_property_add_legacy(dev, prop, NULL); - qdev_property_add_static(dev, prop, NULL); - } + QTAILQ_INSERT_HEAD(&bus->children, dev, sibling); for (prop = qdev_get_bus_info(dev)->props; prop && prop->name; prop++) { qdev_property_add_legacy(dev, prop, NULL); qdev_property_add_static(dev, prop, NULL); } - qdev_property_add_str(dev, "type", qdev_get_type, NULL, NULL); + qdev_prop_set_globals(dev); return dev; } @@ -1649,6 +1640,29 @@ void qdev_machine_init(void) qdev_get_peripheral(); } +static void device_initfn(Object *obj) +{ + DeviceState *dev = DEVICE(obj); + Property *prop; + + if (qdev_hotplug) { + dev->hotplugged = 1; + qdev_hot_added = true; + } + + dev->instance_id_alias = -1; + QTAILQ_INIT(&dev->properties); + dev->state = DEV_STATE_CREATED; + + qdev_prop_set_defaults(dev, qdev_get_props(dev)); + for (prop = qdev_get_props(dev); prop && prop->name; prop++) { + qdev_property_add_legacy(dev, prop, NULL); + qdev_property_add_static(dev, prop, NULL); + } + + qdev_property_add_str(dev, "type", qdev_get_type, NULL, NULL); +} + void device_reset(DeviceState *dev) { DeviceClass *klass = DEVICE_GET_CLASS(dev); @@ -1662,6 +1676,7 @@ static TypeInfo device_type_info = { .name = TYPE_DEVICE, .parent = TYPE_OBJECT, .instance_size = sizeof(DeviceState), + .instance_init = device_initfn, .abstract = true, .class_size = sizeof(DeviceClass), };