From patchwork Tue Oct 27 08:10:11 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinghai Lu X-Patchwork-Id: 56053 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n9R8Amph002647 for ; Tue, 27 Oct 2009 08:10:48 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932108AbZJ0IKm (ORCPT ); Tue, 27 Oct 2009 04:10:42 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S932103AbZJ0IKm (ORCPT ); Tue, 27 Oct 2009 04:10:42 -0400 Received: from hera.kernel.org ([140.211.167.34]:37976 "EHLO hera.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932098AbZJ0IKk (ORCPT ); Tue, 27 Oct 2009 04:10:40 -0400 Received: from [192.168.101.9] (adsl-75-36-253-177.dsl.pltn13.sbcglobal.net [75.36.253.177]) (authenticated bits=0) by hera.kernel.org (8.14.3/8.14.3) with ESMTP id n9R8AQED010918 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 27 Oct 2009 08:10:27 GMT X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.95.2 at hera.kernel.org Message-ID: <4AE6AAE3.6000509@kernel.org> Date: Tue, 27 Oct 2009 01:10:11 -0700 From: Yinghai Lu User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: Kenji Kaneshige , Jesse Barnes , Alex Chiang CC: "linux-kernel@vger.kernel.org" , "linux-pci@vger.kernel.org" , Ivan Kokshaysky , Bjorn Helgaas , "Eric W. Biederman" , Ingo Molnar Subject: [PATCH 3/4] pci: only release that resource index is less than 3 -v3 References: <4ADEB601.8020200@kernel.org> <4AE52B68.3070501@jp.fujitsu.com> <4AE53883.3070709@kernel.org> <4AE5545E.1020900@jp.fujitsu.com> <4AE55D72.7080202@kernel.org> <4AE6A9CA.4060106@kernel.org> In-Reply-To: <4AE6A9CA.4060106@kernel.org> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Index: linux-2.6/drivers/pci/setup-bus.c =================================================================== --- linux-2.6.orig/drivers/pci/setup-bus.c +++ linux-2.6/drivers/pci/setup-bus.c @@ -319,6 +319,37 @@ static void pci_bridge_check_ranges(stru } } +void pci_bridge_release_not_used_res(struct pci_bus *bus) +{ + int i; + struct resource *r; + unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM | + IORESOURCE_PREFETCH; + + /* for pci bridges res only */ + for (i = 0; i < 3; i++) { + r = bus->resource[i]; + if (r && (r->flags & type_mask)) { + if (!r->parent) + continue; + /* + * if there is no child under that, we should release + * and use it. don't need to reset it, pbus_size_* will + * set it again + */ + if (!r->child && !release_resource(r)) { + r->flags = 0; + dev_printk(KERN_DEBUG, &bus->dev, + "resource %d %pRt released\n", + i, r); + } + } + } + + pci_setup_bridge(bus); +} +EXPORT_SYMBOL(pci_bridge_release_not_used_res); + /* Helper function for sizing routines: find first available bus resource of a given type. Note: we intentionally skip the bus resources which have already been assigned (that is, @@ -576,6 +607,42 @@ void __ref pci_bus_size_bridges(struct p } EXPORT_SYMBOL(pci_bus_size_bridges); +void __ref pci_bus_release_bridges_not_used_res(struct pci_bus *bus) +{ + struct pci_dev *dev; + + list_for_each_entry(dev, &bus->devices, bus_list) { + struct pci_bus *b = dev->subordinate; + if (!b) + continue; + + switch (dev->class >> 8) { + case PCI_CLASS_BRIDGE_CARDBUS: + break; + + case PCI_CLASS_BRIDGE_PCI: + default: + pci_bus_release_bridges_not_used_res(b); + break; + } + } + + /* The root bus? */ + if (!bus->self) + return; + + switch (bus->self->class >> 8) { + case PCI_CLASS_BRIDGE_CARDBUS: + break; + + case PCI_CLASS_BRIDGE_PCI: + default: + pci_bridge_release_not_used_res(bus); + break; + } +} +EXPORT_SYMBOL(pci_bus_release_bridges_not_used_res); + void __ref pci_bridge_assign_resources(const struct pci_dev *bridge) { struct pci_bus *b; @@ -644,7 +711,7 @@ static void pci_bus_dump_res(struct pci_ for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) { struct resource *res = bus->resource[i]; - if (!res || !res->end) + if (!res || !res->end || !res->flags) continue; dev_printk(KERN_DEBUG, &bus->dev, "resource %d %pRt\n", i, res); Index: linux-2.6/drivers/pci/hotplug/pciehp_pci.c =================================================================== --- linux-2.6.orig/drivers/pci/hotplug/pciehp_pci.c +++ linux-2.6/drivers/pci/hotplug/pciehp_pci.c @@ -171,6 +171,7 @@ int pciehp_unconfigure_device(struct slo } pci_dev_put(temp); } + pci_bridge_release_not_used_res(parent); return rc; } Index: linux-2.6/include/linux/pci.h =================================================================== --- linux-2.6.orig/include/linux/pci.h +++ linux-2.6/include/linux/pci.h @@ -759,6 +759,8 @@ int pci_vpd_truncate(struct pci_dev *dev void pci_bridge_assign_resources(const struct pci_dev *bridge); void pci_bus_assign_resources(const struct pci_bus *bus); void pci_bus_size_bridges(struct pci_bus *bus); +void pci_bus_release_bridges_not_used_res(struct pci_bus *bus); +void pci_bridge_release_not_used_res(struct pci_bus *bus); int pci_claim_resource(struct pci_dev *, int); void pci_assign_unassigned_resources(void); void pdev_enable_device(struct pci_dev *); Index: linux-2.6/arch/x86/pci/i386.c =================================================================== --- linux-2.6.orig/arch/x86/pci/i386.c +++ linux-2.6/arch/x86/pci/i386.c @@ -194,6 +194,7 @@ static void __init pcibios_allocate_reso static int __init pcibios_assign_resources(void) { struct pci_dev *dev = NULL; + struct pci_bus *bus; struct resource *r; if (!(pci_probe & PCI_ASSIGN_ROMS)) { @@ -213,6 +214,11 @@ static int __init pcibios_assign_resourc } } + /* Try to release bridge resources, that there is not child under it */ + list_for_each_entry(bus, &pci_root_buses, node) { + pci_bus_release_bridges_not_used_res(bus); + } + pci_assign_unassigned_resources(); return 0;