From patchwork Thu Jun 20 13:11:21 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 252919 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 20FF12C0099 for ; Thu, 20 Jun 2013 23:15:31 +1000 (EST) Received: from localhost ([::1]:52753 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Upei0-0000IH-Sh for incoming@patchwork.ozlabs.org; Thu, 20 Jun 2013 09:15:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38912) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpedQ-0001Op-6O for qemu-devel@nongnu.org; Thu, 20 Jun 2013 09:10:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UpedK-00005g-9U for qemu-devel@nongnu.org; Thu, 20 Jun 2013 09:10:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:24500) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpedJ-00005c-QI for qemu-devel@nongnu.org; Thu, 20 Jun 2013 09:10:37 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r5KDAa50015758 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 20 Jun 2013 09:10:36 -0400 Received: from redhat.com (vpn-200-33.tlv.redhat.com [10.35.200.33]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id r5KDAXor027910; Thu, 20 Jun 2013 09:10:34 -0400 Date: Thu, 20 Jun 2013 16:11:21 +0300 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <1371730033-5554-16-git-send-email-mst@redhat.com> References: <1371730033-5554-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1371730033-5554-1-git-send-email-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: David Gibson Subject: [Qemu-devel] [PULL 15/21] pci: Use helper to find device's root bus in pci_find_domain() 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 From: David Gibson Currently pci_find_domain() performs two functions - it locates the PCI root bus above the given bus, then looks up that root bus's domain number. This patch adds a helper function to perform the first task, finding the root bus for a given PCI device. This is then used in pci_find_domain(). This changes pci_find_domain()'s signature slightly, taking a PCIDevice instead of a PCIBus - since all callers passed something of the form dev->bus, this simplifies things slightly. Signed-off-by: David Gibson Signed-off-by: Michael S. Tsirkin --- hw/pci/pci-hotplug-old.c | 2 +- hw/pci/pci.c | 20 +++++++++++++------- hw/pci/pcie_aer.c | 3 +-- include/hw/pci/pci.h | 3 ++- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/hw/pci/pci-hotplug-old.c b/hw/pci/pci-hotplug-old.c index 7a47d6b..37e0720 100644 --- a/hw/pci/pci-hotplug-old.c +++ b/hw/pci/pci-hotplug-old.c @@ -276,7 +276,7 @@ void pci_device_hot_add(Monitor *mon, const QDict *qdict) if (dev) { monitor_printf(mon, "OK domain %d, bus %d, slot %d, function %d\n", - pci_find_domain(dev->bus), + pci_find_domain(dev), pci_bus_num(dev->bus), PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn)); } else diff --git a/hw/pci/pci.c b/hw/pci/pci.c index b8c6140..bab992d 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -259,18 +259,24 @@ PCIBus *pci_find_primary_bus(void) return NULL; } -int pci_find_domain(const PCIBus *bus) +PCIBus *pci_device_root_bus(const PCIDevice *d) { - PCIDevice *d; - struct PCIHostBus *host; + PCIBus *bus = d->bus; - /* obtain root bus */ while ((d = bus->parent_dev) != NULL) { bus = d->bus; } + return bus; +} + +int pci_find_domain(const PCIDevice *dev) +{ + const PCIBus *rootbus = pci_device_root_bus(dev); + struct PCIHostBus *host; + QLIST_FOREACH(host, &host_buses, next) { - if (host->bus == bus) { + if (host->bus == rootbus) { return host->domain; } } @@ -2000,7 +2006,7 @@ int pci_add_capability(PCIDevice *pdev, uint8_t cap_id, fprintf(stderr, "ERROR: %04x:%02x:%02x.%x " "Attempt to add PCI capability %x at offset " "%x overlaps existing capability %x at offset %x\n", - pci_find_domain(pdev->bus), pci_bus_num(pdev->bus), + pci_find_domain(pdev), pci_bus_num(pdev->bus), PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), cap_id, offset, overlapping_cap, i); return -EINVAL; @@ -2155,7 +2161,7 @@ static char *pcibus_get_dev_path(DeviceState *dev) path[path_len] = '\0'; /* First field is the domain. */ - s = snprintf(domain, sizeof domain, "%04x:00", pci_find_domain(d->bus)); + s = snprintf(domain, sizeof domain, "%04x:00", pci_find_domain(d)); assert(s == domain_len); memcpy(path, domain, domain_len); diff --git a/hw/pci/pcie_aer.c b/hw/pci/pcie_aer.c index 1ce72ce..06f77ac 100644 --- a/hw/pci/pcie_aer.c +++ b/hw/pci/pcie_aer.c @@ -1022,8 +1022,7 @@ int do_pcie_aer_inject_error(Monitor *mon, *ret_data = qobject_from_jsonf("{'id': %s, " "'domain': %d, 'bus': %d, 'devfn': %d, " "'ret': %d}", - id, - pci_find_domain(dev->bus), + id, pci_find_domain(dev), pci_bus_num(dev->bus), dev->devfn, ret); assert(*ret_data); diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index c26d704..7376b9e 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -391,7 +391,8 @@ void pci_for_each_device(PCIBus *bus, int bus_num, void (*fn)(PCIBus *bus, PCIDevice *d, void *opaque), void *opaque); PCIBus *pci_find_primary_bus(void); -int pci_find_domain(const PCIBus *bus); +PCIBus *pci_device_root_bus(const PCIDevice *d); +int pci_find_domain(const PCIDevice *dev); PCIDevice *pci_find_device(PCIBus *bus, int bus_num, uint8_t devfn); int pci_qdev_find_device(const char *id, PCIDevice **pdev); PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr);