From patchwork Fri Dec 24 03:14:13 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 76584 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 7B5F3B70CC for ; Fri, 24 Dec 2010 14:25:05 +1100 (EST) Received: from localhost ([127.0.0.1]:48968 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PVyFV-0004yh-Fl for incoming@patchwork.ozlabs.org; Thu, 23 Dec 2010 22:23:21 -0500 Received: from [140.186.70.92] (port=55516 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PVy6q-0008VK-7x for qemu-devel@nongnu.org; Thu, 23 Dec 2010 22:14:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PVy6m-0001pL-8s for qemu-devel@nongnu.org; Thu, 23 Dec 2010 22:14:24 -0500 Received: from mail.valinux.co.jp ([210.128.90.3]:41203) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PVy6l-0001oi-On for qemu-devel@nongnu.org; Thu, 23 Dec 2010 22:14:20 -0500 Received: from ps.local.valinux.co.jp (vagw.valinux.co.jp [210.128.90.14]) by mail.valinux.co.jp (Postfix) with SMTP id AA2DC28046; Fri, 24 Dec 2010 12:14:17 +0900 (JST) Received: (nullmailer pid 8326 invoked by uid 1000); Fri, 24 Dec 2010 03:14:16 -0000 From: Isaku Yamahata To: qemu-devel@nongnu.org Date: Fri, 24 Dec 2010 12:14:13 +0900 Message-Id: <78274d7348c6cdf4bed43d1de51cd9966a3c666b.1293160345.git.yamahata@valinux.co.jp> X-Mailer: git-send-email 1.7.1.1 In-Reply-To: References: In-Reply-To: References: X-Virus-Scanned: clamav-milter 0.95.2 at va-mail.local.valinux.co.jp X-Virus-Status: Clean X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: yamahata@valinux.co.jp, mst@redhat.com Subject: [Qemu-devel] [PATCH v11 2/5] pci: introduce a helper function to convert qdev id to PCIDevice X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch introduce a helper function to get PCIDevice from qdev id. This function will be used later. Signed-off-by: Isaku Yamahata --- hw/pci.c | 35 +++++++++++++++++++++++++++++++++++ hw/pci.h | 1 + 2 files changed, 36 insertions(+), 0 deletions(-) diff --git a/hw/pci.c b/hw/pci.c index eb21848..44bb3b9 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -2027,3 +2027,38 @@ static char *pcibus_get_dev_path(DeviceState *dev) return strdup(path); } +static int pci_qdev_find_recursive(PCIBus *bus, + const char *id, PCIDevice **pdev) +{ + DeviceState *qdev = qdev_find_recursive(&bus->qbus, id); + if (!qdev) { + return -ENODEV; + } + + /* roughly check if given qdev is pci device */ + if (qdev->info->init == &pci_qdev_init && + qdev->parent_bus->info == &pci_bus_info) { + *pdev = DO_UPCAST(PCIDevice, qdev, qdev); + return 0; + } + return -EINVAL; +} + +int pci_qdev_find_device(const char *id, PCIDevice **pdev) +{ + struct PCIHostBus *host; + int rc = -ENODEV; + + QLIST_FOREACH(host, &host_buses, next) { + int tmp = pci_qdev_find_recursive(host->bus, id, pdev); + if (!tmp) { + rc = 0; + break; + } + if (tmp != -ENODEV) { + rc = tmp; + } + } + + return rc; +} diff --git a/hw/pci.h b/hw/pci.h index 6e80b08..052960e 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -252,6 +252,7 @@ PCIBus *pci_find_root_bus(int domain); int pci_find_domain(const PCIBus *bus); PCIBus *pci_find_bus(PCIBus *bus, int bus_num); PCIDevice *pci_find_device(PCIBus *bus, int bus_num, int slot, int function); +int pci_qdev_find_device(const char *id, PCIDevice **pdev); PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr); int pci_parse_devaddr(const char *addr, int *domp, int *busp,