From patchwork Mon Jan 30 21:08:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 138638 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 C6B57B6F71 for ; Tue, 31 Jan 2012 08:09:29 +1100 (EST) Received: from localhost ([::1]:55183 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RryTe-0001h2-AO for incoming@patchwork.ozlabs.org; Mon, 30 Jan 2012 16:09:26 -0500 Received: from eggs.gnu.org ([140.186.70.92]:53430) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RryTQ-0001b4-Ej for qemu-devel@nongnu.org; Mon, 30 Jan 2012 16:09:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RryTL-00050S-U7 for qemu-devel@nongnu.org; Mon, 30 Jan 2012 16:09:12 -0500 Received: from cpe-70-123-132-139.austin.res.rr.com ([70.123.132.139]:34254 helo=localhost6.localdomain6) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RryTL-00050G-MY for qemu-devel@nongnu.org; Mon, 30 Jan 2012 16:09:07 -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 q0UL95Xo005965; Mon, 30 Jan 2012 15:09:05 -0600 Received: (from anthony@localhost) by localhost6.localdomain6 (8.14.4/8.14.4/Submit) id q0UL94EC005959; Mon, 30 Jan 2012 15:09:04 -0600 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Mon, 30 Jan 2012 15:08:41 -0600 Message-Id: <1327957741-5842-3-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 03/23] qdev: make DeviceInfo private 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 Introduce accessors and remove any code that directly accesses DeviceInfo members. Signed-off-by: Anthony Liguori Reviewed-by: Andreas Färber --- hw/pci.c | 13 ++++++++----- hw/qdev-properties.c | 4 ++-- hw/qdev.c | 30 +++++++++++++++++++++++++++++- hw/qdev.h | 24 +++++++++--------------- 4 files changed, 48 insertions(+), 23 deletions(-) diff --git a/hw/pci.c b/hw/pci.c index 6a0b1f5..235ea00 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -1673,6 +1673,7 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom) char *path; void *ptr; char name[32]; + const VMStateDescription *vmsd; if (!pdev->romfile) return 0; @@ -1709,10 +1710,13 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom) size = 1 << qemu_fls(size); } - if (qdev_get_info(&pdev->qdev)->vmsd) - snprintf(name, sizeof(name), "%s.rom", qdev_get_info(&pdev->qdev)->vmsd->name); - else + vmsd = qdev_get_vmsd(DEVICE(pdev)); + + if (vmsd) { + snprintf(name, sizeof(name), "%s.rom", vmsd->name); + } else { snprintf(name, sizeof(name), "%s.rom", object_get_typename(OBJECT(pdev))); + } pdev->has_rom = true; memory_region_init_ram(&pdev->rom, name, size); vmstate_register_ram(&pdev->rom, &pdev->qdev); @@ -1953,8 +1957,7 @@ static int pci_qdev_find_recursive(PCIBus *bus, } /* roughly check if given qdev is pci device */ - if (qdev_get_info(qdev)->init == &pci_qdev_init && - qdev->parent_bus->info == &pci_bus_info) { + if (object_dynamic_cast(OBJECT(qdev), TYPE_PCI_DEVICE)) { *pdev = PCI_DEVICE(qdev); return 0; } diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c index c98219a..724dce5 100644 --- a/hw/qdev-properties.c +++ b/hw/qdev-properties.c @@ -966,7 +966,7 @@ static Property *qdev_prop_find(DeviceState *dev, const char *name) Property *prop; /* device properties */ - prop = qdev_prop_walk(qdev_get_info(dev)->props, name); + prop = qdev_prop_walk(qdev_get_props(dev), name); if (prop) return prop; @@ -1166,7 +1166,7 @@ void qdev_prop_set_globals(DeviceState *dev) QTAILQ_FOREACH(prop, &global_props, next) { if (strcmp(object_get_typename(OBJECT(dev)), prop->driver) != 0 && - strcmp(qdev_get_info(dev)->bus_info->name, prop->driver) != 0) { + strcmp(qdev_get_bus_info(dev)->name, prop->driver) != 0) { continue; } if (qdev_prop_parse(dev, prop->property, prop->value) != 0) { diff --git a/hw/qdev.c b/hw/qdev.c index a8c24de..18c5876 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -60,11 +60,39 @@ static void qdev_subclass_init(ObjectClass *klass, void *data) } } -DeviceInfo *qdev_get_info(DeviceState *dev) +static DeviceInfo *qdev_get_info(DeviceState *dev) { return DEVICE_GET_CLASS(dev)->info; } +const VMStateDescription *qdev_get_vmsd(DeviceState *dev) +{ + return qdev_get_info(dev)->vmsd; +} + +BusInfo *qdev_get_bus_info(DeviceState *dev) +{ + return qdev_get_info(dev)->bus_info; +} + +Property *qdev_get_props(DeviceState *dev) +{ + return qdev_get_info(dev)->props; +} + +const char *qdev_fw_name(DeviceState *dev) +{ + DeviceInfo *info = qdev_get_info(dev); + + if (info->fw_name) { + return info->fw_name; + } else if (info->alias) { + return info->alias; + } + + return object_get_typename(OBJECT(dev)); +} + void qdev_register_subclass(DeviceInfo *info, const char *parent) { TypeInfo type_info = {}; diff --git a/hw/qdev.h b/hw/qdev.h index c9572a5..dc6a6fe 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -398,22 +398,8 @@ void qdev_prop_set_globals(DeviceState *dev); void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev, Property *prop, const char *value); -DeviceInfo *qdev_get_info(DeviceState *dev); - -static inline const char *qdev_fw_name(DeviceState *dev) -{ - DeviceInfo *info = qdev_get_info(dev); - - if (info->fw_name) { - return info->fw_name; - } else if (info->alias) { - return info->alias; - } - - return object_get_typename(OBJECT(dev)); -} - char *qdev_get_fw_dev_path(DeviceState *dev); + /* This is a nasty hack to allow passing a NULL bus to qdev_create. */ extern struct BusInfo system_bus_info; @@ -661,4 +647,12 @@ void qdev_machine_init(void); */ void device_reset(DeviceState *dev); +const VMStateDescription *qdev_get_vmsd(DeviceState *dev); + +const char *qdev_fw_name(DeviceState *dev); + +BusInfo *qdev_get_bus_info(DeviceState *dev); + +Property *qdev_get_props(DeviceState *dev); + #endif