From patchwork Wed Feb 1 19:50:55 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 138997 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 E2369104791 for ; Thu, 2 Feb 2012 07:55:00 +1100 (EST) Received: from localhost ([::1]:50353 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RshCl-00086A-2s for incoming@patchwork.ozlabs.org; Wed, 01 Feb 2012 15:54:59 -0500 Received: from eggs.gnu.org ([140.186.70.92]:37712) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RsgEB-0001zJ-Hd for qemu-devel@nongnu.org; Wed, 01 Feb 2012 14:52:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RsgDt-0006BF-W6 for qemu-devel@nongnu.org; Wed, 01 Feb 2012 14:52:14 -0500 Received: from cpe-70-123-132-139.austin.res.rr.com ([70.123.132.139]:52930 helo=localhost6.localdomain6) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RsgDt-0006Ah-Pc for qemu-devel@nongnu.org; Wed, 01 Feb 2012 14:52:05 -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 q11JpxXX006394; Wed, 1 Feb 2012 13:51:59 -0600 Received: (from anthony@localhost) by localhost6.localdomain6 (8.14.4/8.14.4/Submit) id q11JpvJN006393; Wed, 1 Feb 2012 13:51:57 -0600 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Wed, 1 Feb 2012 13:50:55 -0600 Message-Id: <1328125863-6203-15-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1328125863-6203-1-git-send-email-aliguori@us.ibm.com> References: <1328125863-6203-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 , Andreas Faerber , Peter Maydell Subject: [Qemu-devel] [PATCH 14/22] qdev: refactor away qdev_create_from_info 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 Note that the FIXME gets fixed in series 4/4. We need to convert BusState to QOM before we can make parent_bus a link. Signed-off-by: Anthony Liguori --- hw/qdev.c | 35 ++++++++++++++++++++++------------- hw/qdev.h | 3 +++ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index 9933ea2..e2263cb 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -124,30 +124,22 @@ bool qdev_exists(const char *name) static void qdev_property_add_legacy(DeviceState *dev, Property *prop, Error **errp); -static DeviceState *qdev_create_from_info(BusState *bus, const char *typename) +void qdev_set_parent_bus(DeviceState *dev, BusState *bus) { - DeviceState *dev; Property *prop; - dev = DEVICE(object_new(typename)); - - dev->parent_bus = bus; - qdev_prop_set_defaults(dev, dev->parent_bus->info->props); - if (qdev_hotplug) { assert(bus->allow_hotplug); } + dev->parent_bus = bus; QTAILQ_INSERT_HEAD(&bus->children, dev, sibling); + qdev_prop_set_defaults(dev, dev->parent_bus->info->props); 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_prop_set_globals(dev); - - return dev; } /* Create a new device. This only initializes the device state structure @@ -172,11 +164,21 @@ DeviceState *qdev_create(BusState *bus, const char *name) DeviceState *qdev_try_create(BusState *bus, const char *name) { + DeviceState *dev; + + dev = DEVICE(object_new(name)); + if (!dev) { + return NULL; + } + if (!bus) { bus = sysbus_get_default(); } - return qdev_create_from_info(bus, name); + qdev_set_parent_bus(dev, bus); + qdev_prop_set_globals(dev); + + return dev; } static void qdev_print_devinfo(ObjectClass *klass, void *opaque) @@ -373,8 +375,15 @@ DeviceState *qdev_device_add(QemuOpts *opts) return NULL; } + if (!bus) { + bus = sysbus_get_default(); + } + /* create device, set properties */ - qdev = qdev_create_from_info(bus, driver); + qdev = DEVICE(object_new(driver)); + qdev_set_parent_bus(qdev, bus); + qdev_prop_set_globals(qdev); + id = qemu_opts_id(opts); if (id) { qdev->id = id; diff --git a/hw/qdev.h b/hw/qdev.h index 5aea4bf..e611804 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -636,4 +636,7 @@ BusInfo *qdev_get_bus_info(DeviceState *dev); Property *qdev_get_props(DeviceState *dev); +/* FIXME: make this a link<> */ +void qdev_set_parent_bus(DeviceState *dev, BusState *bus); + #endif