From patchwork Wed Feb 1 19:50:45 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 138994 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 C59611007D2 for ; Thu, 2 Feb 2012 07:47:57 +1100 (EST) Received: from localhost ([::1]:57442 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RsgE3-0001hY-Km for incoming@patchwork.ozlabs.org; Wed, 01 Feb 2012 14:52:15 -0500 Received: from eggs.gnu.org ([140.186.70.92]:37411) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RsgDK-00088b-ND for qemu-devel@nongnu.org; Wed, 01 Feb 2012 14:51:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RsgDJ-0005zP-6j for qemu-devel@nongnu.org; Wed, 01 Feb 2012 14:51:30 -0500 Received: from cpe-70-123-132-139.austin.res.rr.com ([70.123.132.139]:52864 helo=localhost6.localdomain6) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RsgDI-0005zI-JI for qemu-devel@nongnu.org; Wed, 01 Feb 2012 14:51:29 -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 q11JpNIv006328; Wed, 1 Feb 2012 13:51:24 -0600 Received: (from anthony@localhost) by localhost6.localdomain6 (8.14.4/8.14.4/Submit) id q11JpM5Q006326; Wed, 1 Feb 2012 13:51:22 -0600 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Wed, 1 Feb 2012 13:50:45 -0600 Message-Id: <1328125863-6203-5-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 04/22] qdev: remove info from class 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 Now DeviceInfo is no longer used after object construction. All of the relevant members have been moved to DeviceClass. Signed-off-by: Anthony Liguori --- hw/pci.c | 4 ++- hw/qdev.c | 94 ++++++++++++++++++++++++++++++++++++------------------------ hw/qdev.h | 26 +++++++++++++--- 3 files changed, 80 insertions(+), 44 deletions(-) diff --git a/hw/pci.c b/hw/pci.c index 235ea00..43dc1fb 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -1467,7 +1467,9 @@ static int pci_qdev_init(DeviceState *qdev, DeviceInfo *base) } bus = FROM_QBUS(PCIBus, qdev_get_parent_bus(qdev)); - pci_dev = do_pci_register_device(pci_dev, bus, base->name, pci_dev->devfn); + pci_dev = do_pci_register_device(pci_dev, bus, + object_get_typename(OBJECT(qdev)), + pci_dev->devfn); if (pci_dev == NULL) return -1; if (qdev->hotplugged && pc->no_hotplug) { diff --git a/hw/qdev.c b/hw/qdev.c index 18c5876..b273cd2 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -48,46 +48,54 @@ static BusState *qbus_find(const char *path); static void qdev_subclass_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); + DeviceInfo *info = data; - dc->info = data; - dc->reset = dc->info->reset; + dc->fw_name = info->fw_name; + dc->alias = info->alias; + dc->desc = info->desc; + dc->props = info->props; + dc->no_user = info->no_user; - /* Poison to try to detect future uses */ - dc->info->reset = NULL; + dc->reset = info->reset; - if (dc->info->class_init) { - dc->info->class_init(klass, data); - } -} + dc->vmsd = info->vmsd; -static DeviceInfo *qdev_get_info(DeviceState *dev) -{ - return DEVICE_GET_CLASS(dev)->info; + dc->init = info->init; + dc->unplug = info->unplug; + dc->exit = info->exit; + dc->bus_info = info->bus_info; + + if (info->class_init) { + info->class_init(klass, data); + } } const VMStateDescription *qdev_get_vmsd(DeviceState *dev) { - return qdev_get_info(dev)->vmsd; + DeviceClass *dc = DEVICE_GET_CLASS(dev); + return dc->vmsd; } BusInfo *qdev_get_bus_info(DeviceState *dev) { - return qdev_get_info(dev)->bus_info; + DeviceClass *dc = DEVICE_GET_CLASS(dev); + return dc->bus_info; } Property *qdev_get_props(DeviceState *dev) { - return qdev_get_info(dev)->props; + DeviceClass *dc = DEVICE_GET_CLASS(dev); + return dc->props; } const char *qdev_fw_name(DeviceState *dev) { - DeviceInfo *info = qdev_get_info(dev); + DeviceClass *dc = DEVICE_GET_CLASS(dev); - if (info->fw_name) { - return info->fw_name; - } else if (info->alias) { - return info->alias; + if (dc->fw_name) { + return dc->fw_name; + } else if (dc->alias) { + return dc->alias; } return object_get_typename(OBJECT(dev)); @@ -159,7 +167,7 @@ static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info) assert(bus->info == info->bus_info); dev = DEVICE(object_new(info->name)); dev->parent_bus = bus; - qdev_prop_set_defaults(dev, qdev_get_info(dev)->props); + 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); @@ -172,12 +180,12 @@ static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info) QTAILQ_INIT(&dev->properties); dev->state = DEV_STATE_CREATED; - for (prop = qdev_get_info(dev)->props; prop && prop->name; prop++) { + for (prop = qdev_get_props(dev); prop && prop->name; prop++) { qdev_property_add_legacy(dev, prop, NULL); qdev_property_add_static(dev, prop, NULL); } - for (prop = qdev_get_info(dev)->bus_info->props; prop && prop->name; prop++) { + 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); } @@ -407,16 +415,19 @@ DeviceState *qdev_device_add(QemuOpts *opts) Return 0 on success. */ int qdev_init(DeviceState *dev) { + DeviceClass *dc = DEVICE_GET_CLASS(dev); int rc; assert(dev->state == DEV_STATE_CREATED); - rc = qdev_get_info(dev)->init(dev, qdev_get_info(dev)); + + /* FIXME hopefully this doesn't break anything */ + rc = dc->init(dev, NULL); if (rc < 0) { qdev_free(dev); return rc; } - if (qdev_get_info(dev)->vmsd) { - vmstate_register_with_alias_id(dev, -1, qdev_get_info(dev)->vmsd, dev, + if (qdev_get_vmsd(dev)) { + vmstate_register_with_alias_id(dev, -1, qdev_get_vmsd(dev), dev, dev->instance_id_alias, dev->alias_required_for_version); } @@ -437,15 +448,17 @@ void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id, int qdev_unplug(DeviceState *dev) { + DeviceClass *dc = DEVICE_GET_CLASS(dev); + if (!dev->parent_bus->allow_hotplug) { qerror_report(QERR_BUS_NO_HOTPLUG, dev->parent_bus->name); return -1; } - assert(qdev_get_info(dev)->unplug != NULL); + assert(dc->unplug != NULL); qdev_hot_removed = true; - return qdev_get_info(dev)->unplug(dev); + return dc->unplug(dev); } static int qdev_reset_one(DeviceState *dev, void *opaque) @@ -500,10 +513,9 @@ int qdev_simple_unplug_cb(DeviceState *dev) way is somewhat unclean, and best avoided. */ void qdev_init_nofail(DeviceState *dev) { - DeviceInfo *info = qdev_get_info(dev); - if (qdev_init(dev) < 0) { - error_report("Initialization of device %s failed", info->name); + error_report("Initialization of device %s failed", + object_get_typename(OBJECT(dev))); exit(1); } } @@ -553,6 +565,7 @@ void qdev_free(DeviceState *dev) { BusState *bus; Property *prop; + DeviceClass *dc = DEVICE_GET_CLASS(dev); qdev_property_del_all(dev); @@ -561,15 +574,18 @@ void qdev_free(DeviceState *dev) bus = QLIST_FIRST(&dev->child_bus); qbus_free(bus); } - if (qdev_get_info(dev)->vmsd) - vmstate_unregister(dev, qdev_get_info(dev)->vmsd, dev); - if (qdev_get_info(dev)->exit) - qdev_get_info(dev)->exit(dev); - if (dev->opts) + if (qdev_get_vmsd(dev)) { + vmstate_unregister(dev, qdev_get_vmsd(dev), dev); + } + if (dc->exit) { + dc->exit(dev); + } + if (dev->opts) { qemu_opts_del(dev->opts); + } } QTAILQ_REMOVE(&dev->parent_bus->children, dev, sibling); - for (prop = qdev_get_info(dev)->props; prop && prop->name; prop++) { + for (prop = qdev_get_props(dev); prop && prop->name; prop++) { if (prop->info->free) { prop->info->free(dev, prop); } @@ -817,7 +833,9 @@ static DeviceState *qbus_find_dev(BusState *bus, char *elem) } } QTAILQ_FOREACH(dev, &bus->children, sibling) { - if (qdev_get_info(dev)->alias && strcmp(qdev_get_info(dev)->alias, elem) == 0) { + DeviceClass *dc = DEVICE_GET_CLASS(dev); + + if (dc->alias && strcmp(dc->alias, elem) == 0) { return dev; } } @@ -1028,7 +1046,7 @@ static void qdev_print(Monitor *mon, DeviceState *dev, int indent) if (dev->num_gpio_out) { qdev_printf("gpio-out %d\n", dev->num_gpio_out); } - qdev_print_props(mon, dev, qdev_get_info(dev)->props, "dev", indent); + qdev_print_props(mon, dev, qdev_get_props(dev), "dev", indent); qdev_print_props(mon, dev, dev->parent_bus->info->props, "bus", indent); if (dev->parent_bus->info->print_dev) dev->parent_bus->info->print_dev(mon, dev, indent); diff --git a/hw/qdev.h b/hw/qdev.h index dc6a6fe..7e4c632 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -72,10 +72,30 @@ typedef struct DeviceProperty #define DEVICE_CLASS(klass) OBJECT_CLASS_CHECK(DeviceClass, (klass), TYPE_DEVICE) #define DEVICE_GET_CLASS(obj) OBJECT_GET_CLASS(DeviceClass, (obj), TYPE_DEVICE) +typedef int (*qdev_initfn)(DeviceState *dev, DeviceInfo *info); +typedef int (*qdev_event)(DeviceState *dev); +typedef void (*qdev_resetfn)(DeviceState *dev); + typedef struct DeviceClass { ObjectClass parent_class; - DeviceInfo *info; + + const char *fw_name; + const char *alias; + const char *desc; + Property *props; + int no_user; + + /* callbacks */ void (*reset)(DeviceState *dev); + + /* device state */ + const VMStateDescription *vmsd; + + /* Private to qdev / bus. */ + qdev_initfn init; + qdev_event unplug; + qdev_event exit; + BusInfo *bus_info; } DeviceClass; /* This structure should not be accessed directly. We declare it here @@ -212,10 +232,6 @@ BusState *qdev_get_child_bus(DeviceState *dev, const char *name); /*** Device API. ***/ -typedef int (*qdev_initfn)(DeviceState *dev, DeviceInfo *info); -typedef int (*qdev_event)(DeviceState *dev); -typedef void (*qdev_resetfn)(DeviceState *dev); - struct DeviceInfo { const char *name; const char *fw_name;