From patchwork Wed Feb 1 19:50:44 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 138986 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 28F9CB6EEA for ; Thu, 2 Feb 2012 07:21:58 +1100 (EST) Received: from localhost ([::1]:56551 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RsgDq-0001E2-6x for incoming@patchwork.ozlabs.org; Wed, 01 Feb 2012 14:52:02 -0500 Received: from eggs.gnu.org ([140.186.70.92]:37389) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RsgDI-0007ut-Eb for qemu-devel@nongnu.org; Wed, 01 Feb 2012 14:51:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RsgDF-0005yM-C8 for qemu-devel@nongnu.org; Wed, 01 Feb 2012 14:51:27 -0500 Received: from cpe-70-123-132-139.austin.res.rr.com ([70.123.132.139]:52857 helo=localhost6.localdomain6) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RsgDF-0005y6-5m for qemu-devel@nongnu.org; Wed, 01 Feb 2012 14:51:25 -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 q11JpKcn006323; Wed, 1 Feb 2012 13:51:20 -0600 Received: (from anthony@localhost) by localhost6.localdomain6 (8.14.4/8.14.4/Submit) id q11JpIIM006322; Wed, 1 Feb 2012 13:51:18 -0600 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Wed, 1 Feb 2012 13:50:44 -0600 Message-Id: <1328125863-6203-4-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 03/22] 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 --- 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