From patchwork Mon May 31 02:52:16 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 54065 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 B6AEEB7D59 for ; Mon, 31 May 2010 12:57:14 +1000 (EST) Received: from localhost ([127.0.0.1]:48711 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OIvBe-0008LX-Ub for incoming@patchwork.ozlabs.org; Sun, 30 May 2010 22:57:10 -0400 Received: from [140.186.70.92] (port=51491 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OIvAK-0007fT-7f for qemu-devel@nongnu.org; Sun, 30 May 2010 22:55:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OIvAH-0007Z2-Sf for qemu-devel@nongnu.org; Sun, 30 May 2010 22:55:48 -0400 Received: from mail.valinux.co.jp ([210.128.90.3]:55122) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OIvAH-0007YF-BI for qemu-devel@nongnu.org; Sun, 30 May 2010 22:55:45 -0400 Received: from ps.local.valinux.co.jp (vagw.valinux.co.jp [210.128.90.14]) by mail.valinux.co.jp (Postfix) with SMTP id E48BB1869E; Mon, 31 May 2010 11:55:40 +0900 (JST) Received: (nullmailer pid 21359 invoked by uid 1000); Mon, 31 May 2010 02:52:16 -0000 Date: Mon, 31 May 2010 11:52:16 +0900 From: Isaku Yamahata To: "Michael S\. Tsirkin" Subject: Re: [Qemu-devel] Re: [PATCH v2] pci-hotplug: make them aware of pci domain. Message-ID: <20100531025216.GG13840@valinux.co.jp> References: <20100528093046.GB13840@valinux.co.jp> <20100530154803.GA30048@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20100530154803.GA30048@redhat.com> User-Agent: Mutt/1.5.19 (2009-01-05) 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: qemu-devel@nongnu.org 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 On Sun, May 30, 2010 at 06:48:03PM +0300, Michael S. Tsirkin wrote: > On Fri, May 28, 2010 at 06:30:46PM +0900, Isaku Yamahata wrote: > > add helper function which converts root bus to pci domain. > > make them aware of pci domain. > > > > Signed-off-by: Isaku Yamahata > > Doesn't seem to apply to master. Do you mean master == pci branch of git://git.kernel.org/pub/scm/linux/kernel/git/mst/qemu.git Here is the version rebased to 4cecb52f3370d9c1a4251eef7c9331253c9f9719 of the branch. The previous one applies to the change set of aa6f63fff62faf2fe9ffba5a789675d49293614d in qemu.org main branch which does include 6c6a58aee425338bf67ec8faffdcda56b0b82090, but the pci branch doesn't include it. From 389ec34a80d2630ff4ad3e491328c2e1fb53be6f Mon Sep 17 00:00:00 2001 Message-Id: <389ec34a80d2630ff4ad3e491328c2e1fb53be6f.1275273565.git.yamahata@valinux.co.jp> In-Reply-To: References: From: Isaku Yamahata Date: Mon, 31 May 2010 11:32:52 +0900 Subject: [PATCH] pci-hotplug: make them aware of pci domain. add helper function which converts root bus to pci domain. make them aware of pci domain. Signed-off-by: Isaku Yamahata --- Changes: V1 -> V2 - removed pci_find_bus() - renamed pci_find_bus_by_bus() to pci_find_bus() - add abort() --- hw/pci-hotplug.c | 9 +++++---- hw/pci.c | 22 +++++++++++++++++++++- hw/pci.h | 1 + 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c index cc45c50..9c7161b 100644 --- a/hw/pci-hotplug.c +++ b/hw/pci-hotplug.c @@ -125,7 +125,7 @@ void drive_hot_add(Monitor *mon, const QDict *qdict) if (pci_read_devaddr(mon, pci_addr, &dom, &pci_bus, &slot)) { goto err; } - dev = pci_find_device(pci_find_root_bus(0), pci_bus, slot, 0); + dev = pci_find_device(pci_find_root_bus(dom), pci_bus, slot, 0); if (!dev) { monitor_printf(mon, "no pci device with address %s\n", pci_addr); goto err; @@ -283,8 +283,9 @@ int pci_device_hot_add(Monitor *mon, const QDict *qdict, QObject **ret_data) if (dev) { *ret_data = - qobject_from_jsonf("{ 'domain': 0, 'bus': %d, 'slot': %d, " - "'function': %d }", pci_bus_num(dev->bus), + qobject_from_jsonf("{ 'domain': %d, 'bus': %d, 'slot': %d, " + "'function': %d }", + pci_find_domain(dev->bus), pci_bus_num(dev->bus), PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn)); } else { monitor_printf(mon, "failed to add %s\n", opts); @@ -305,7 +306,7 @@ int pci_device_hot_remove(Monitor *mon, const char *pci_addr) return -1; } - d = pci_find_device(pci_find_root_bus(0), bus, slot, 0); + d = pci_find_device(pci_find_root_bus(dom), bus, slot, 0); if (!d) { monitor_printf(mon, "slot %d empty\n", slot); return -1; diff --git a/hw/pci.c b/hw/pci.c index 3362842..f084cc0 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -200,6 +200,26 @@ PCIBus *pci_find_root_bus(int domain) return NULL; } +int pci_find_domain(const PCIBus *bus) +{ + PCIDevice *d; + struct PCIHostBus *host; + + /* obtain root bus */ + while ((d = bus->parent_dev) != NULL) { + bus = d->bus; + } + + QLIST_FOREACH(host, &host_buses, next) { + if (host->bus == bus) { + return host->domain; + } + } + + abort(); /* should not be reached */ + return -1; +} + void pci_bus_new_inplace(PCIBus *bus, DeviceState *parent, const char *name, int devfn_min) { @@ -505,7 +525,7 @@ PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr) } *devfnp = slot << 3; - return pci_find_bus(pci_find_root_bus(0), bus); + return pci_find_bus(pci_find_root_bus(dom), bus); } static void pci_init_cmask(PCIDevice *dev) diff --git a/hw/pci.h b/hw/pci.h index b803593..3a15bd4 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -218,6 +218,7 @@ PCIDevice *pci_nic_init_nofail(NICInfo *nd, const char *default_model, int pci_bus_num(PCIBus *s); void pci_for_each_device(PCIBus *bus, int bus_num, void (*fn)(PCIBus *bus, PCIDevice *d)); 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); PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr);