From patchwork Mon May 2 23:14:56 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinghai Lu X-Patchwork-Id: 748712 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p42NEgcF005567 for ; Mon, 2 May 2011 23:15:04 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753545Ab1EBXPE (ORCPT ); Mon, 2 May 2011 19:15:04 -0400 Received: from rcsinet10.oracle.com ([148.87.113.121]:22163 "EHLO rcsinet10.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752389Ab1EBXPC (ORCPT ); Mon, 2 May 2011 19:15:02 -0400 Received: from acsinet15.oracle.com (acsinet15.oracle.com [141.146.126.227]) by rcsinet10.oracle.com (Switch-3.4.2/Switch-3.4.2) with ESMTP id p42NEwln001689 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 2 May 2011 23:15:00 GMT Received: from acsmt358.oracle.com (acsmt358.oracle.com [141.146.40.158]) by acsinet15.oracle.com (Switch-3.4.2/Switch-3.4.1) with ESMTP id p42NEvEs030939 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 2 May 2011 23:14:57 GMT Received: from abhmt016.oracle.com (abhmt016.oracle.com [141.146.116.25]) by acsmt358.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id p42NEuLO004643; Mon, 2 May 2011 18:14:56 -0500 Received: from linux-siqj.site (/10.6.76.16) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 02 May 2011 16:14:56 -0700 Message-ID: <4DBF3AF0.4000804@kernel.org> Date: Mon, 02 May 2011 16:14:56 -0700 From: Yinghai Lu User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.14) Gecko/20110221 SUSE/3.1.8 Thunderbird/3.1.8 MIME-Version: 1.0 To: Jesse Barnes , "linux-pci@vger.kernel.org" Subject: [PATCH 3/3] pci: Make rescan bus could increase bridge resource size if needed References: <4DBF35CB.5010600@kernel.org> In-Reply-To: <4DBF35CB.5010600@kernel.org> X-Source-IP: acsinet15.oracle.com [141.146.126.227] X-Auth-Type: Internal IP X-CT-RefId: str=0001.0A090204.4DBF3AF6.007B,ss=1,fgs=0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 02 May 2011 23:15:04 +0000 (UTC) Current rescan will not touch bridge MMIO and IO. Try to reuse pci_assign_unassigned_bridge_resources(bridge) to update bridge resource, if child devices need more resource. only do that for bridges that all children get removed before. So do not release resources that could already be used by drivers of child devices. Signed-off-by: Yinghai Lu --- drivers/pci/pci-sysfs.c | 5 ++++- drivers/pci/probe.c | 24 ++++++++++++++++++++++++ include/linux/pci.h | 1 + 3 files changed, 29 insertions(+), 1 deletion(-) -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: linux-2.6/drivers/pci/pci-sysfs.c =================================================================== --- linux-2.6.orig/drivers/pci/pci-sysfs.c +++ linux-2.6/drivers/pci/pci-sysfs.c @@ -313,7 +313,10 @@ dev_bus_rescan_store(struct device *dev, if (val) { mutex_lock(&pci_remove_rescan_mutex); - pci_rescan_bus(bus); + if (!pci_is_root_bus(bus) && list_empty(&bus->devices)) + pci_rescan_bus_bridge_resize(bus->self); + else + pci_rescan_bus(bus); mutex_unlock(&pci_remove_rescan_mutex); } return count; Index: linux-2.6/drivers/pci/probe.c =================================================================== --- linux-2.6.orig/drivers/pci/probe.c +++ linux-2.6/drivers/pci/probe.c @@ -1518,6 +1518,30 @@ EXPORT_SYMBOL(pci_scan_bus_parented); #ifdef CONFIG_HOTPLUG /** + * pci_rescan_bus_bridge_resize - scan a PCI bus for devices. + * @bridge: PCI bridge for the bus to scan + * + * Scan a PCI bus and child buses for new devices, adds them, + * and enables them, it will resize bridge mmio/io resource if it is possible + * for safe, caller should make sure that children get removed already. + * + * Returns the max number of subordinate bus discovered. + */ +unsigned int __ref pci_rescan_bus_bridge_resize(struct pci_dev *bridge) +{ + unsigned int max; + struct pci_bus *bus = bridge->subordinate; + + max = pci_scan_child_bus(bus); + + pci_assign_unassigned_bridge_resources(bridge); + + pci_bus_add_devices(bus); + + return max; +} + +/** * pci_rescan_bus - scan a PCI bus for devices. * @bus: PCI bus to scan * Index: linux-2.6/include/linux/pci.h =================================================================== --- linux-2.6.orig/include/linux/pci.h +++ linux-2.6/include/linux/pci.h @@ -835,6 +835,7 @@ void set_pcie_hotplug_bridge(struct pci_ /* Functions for PCI Hotplug drivers to use */ int pci_bus_find_capability(struct pci_bus *bus, unsigned int devfn, int cap); #ifdef CONFIG_HOTPLUG +unsigned int pci_rescan_bus_bridge_resize(struct pci_dev *bridge); unsigned int pci_rescan_bus(struct pci_bus *bus); #endif