From patchwork Wed Aug 8 02:10:35 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 175851 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 343D42C00B1 for ; Wed, 8 Aug 2012 12:59:59 +1000 (EST) Received: from localhost ([::1]:40771 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SyvkM-0002cR-1F for incoming@patchwork.ozlabs.org; Tue, 07 Aug 2012 22:11:42 -0400 Received: from eggs.gnu.org ([208.118.235.92]:34785) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Syvje-0001BP-W7 for qemu-devel@nongnu.org; Tue, 07 Aug 2012 22:10:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SyvjZ-0005Ie-Dz for qemu-devel@nongnu.org; Tue, 07 Aug 2012 22:10:58 -0400 Received: from ozlabs.org ([203.10.76.45]:54960) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SyvjZ-0005Ho-2P; Tue, 07 Aug 2012 22:10:53 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id A5D9C2C00BF; Wed, 8 Aug 2012 12:10:49 +1000 (EST) From: David Gibson To: agraf@suse.de, qemu-ppc@nongnu.org Date: Wed, 8 Aug 2012 12:10:35 +1000 Message-Id: <1344391839-2006-7-git-send-email-david@gibson.dropbear.id.au> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1344391839-2006-1-git-send-email-david@gibson.dropbear.id.au> References: <1344391839-2006-1-git-send-email-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 203.10.76.45 Cc: Alexey Kardashevskiy , aliguori@us.ibm.com, qemu-devel@nongnu.org, David Gibson Subject: [Qemu-devel] [PATCH 06/10] pseries: Export find_phb() utility function for PCI code 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: Alexey Kardashevskiy The pseries PCI code makes use of an internal find_dev() function which locates a PCIDevice * given a (platform specific) bus ID and device address. Internally this needs to first locate the host bridge on which the device resides based on the bus ID. This patch exposes that host bridge lookup as a separate function, which we will need later in the MSI and VFIO code. Signed-off-by: Alexey Kardashevskiy Signed-off-by: David Gibson --- hw/spapr_pci.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/hw/spapr_pci.c b/hw/spapr_pci.c index fcc358e..842068f 100644 --- a/hw/spapr_pci.c +++ b/hw/spapr_pci.c @@ -29,27 +29,39 @@ #include "hw/spapr_pci.h" #include "exec-memory.h" #include +#include "trace.h" #include "hw/pci_internals.h" -static PCIDevice *find_dev(sPAPREnvironment *spapr, - uint64_t buid, uint32_t config_addr) +static sPAPRPHBState *find_phb(sPAPREnvironment *spapr, uint64_t buid) { - int devfn = (config_addr >> 8) & 0xFF; sPAPRPHBState *phb; QLIST_FOREACH(phb, &spapr->phbs, list) { - BusChild *kid; - if (phb->buid != buid) { continue; } + return phb; + } + + return NULL; +} + +static PCIDevice *find_dev(sPAPREnvironment *spapr, uint64_t buid, + uint32_t config_addr) +{ + sPAPRPHBState *phb = find_phb(spapr, buid); + BusChild *kid; + int devfn = (config_addr >> 8) & 0xFF; + + if (!phb) { + return NULL; + } - QTAILQ_FOREACH(kid, &phb->host_state.bus->qbus.children, sibling) { - PCIDevice *dev = (PCIDevice *)kid->child; - if (dev->devfn == devfn) { - return dev; - } + QTAILQ_FOREACH(kid, &phb->host_state.bus->qbus.children, sibling) { + PCIDevice *dev = (PCIDevice *)kid->child; + if (dev->devfn == devfn) { + return dev; } }