From patchwork Sat Jun 1 06:03:08 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinghai Lu X-Patchwork-Id: 248055 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id AC3F12C00AC for ; Sat, 1 Jun 2013 16:04:28 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758506Ab3FAGE1 (ORCPT ); Sat, 1 Jun 2013 02:04:27 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:25660 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758238Ab3FAGDe (ORCPT ); Sat, 1 Jun 2013 02:03:34 -0400 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r5163QDn015328 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 1 Jun 2013 06:03:26 GMT Received: from userz7022.oracle.com (userz7022.oracle.com [156.151.31.86]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r5163PvS003903 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 1 Jun 2013 06:03:27 GMT Received: from abhmt105.oracle.com (abhmt105.oracle.com [141.146.116.57]) by userz7022.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r5163PXs005153; Sat, 1 Jun 2013 06:03:25 GMT Received: from linux-siqj.site (/75.36.240.39) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 31 May 2013 23:03:24 -0700 From: Yinghai Lu To: Bjorn Helgaas , Benjamin Herrenschmidt , Gavin Shan Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Yinghai Lu Subject: [PATCH v5 3/7] PCI: Use pci_walk_bus to detect unassigned resources Date: Fri, 31 May 2013 23:03:08 -0700 Message-Id: <1370066593-22736-3-git-send-email-yinghai@kernel.org> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1370066593-22736-1-git-send-email-yinghai@kernel.org> References: <1370066593-22736-1-git-send-email-yinghai@kernel.org> X-Source-IP: acsinet22.oracle.com [141.146.126.238] Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Per Bjorn, use pci_walk_bus instead of for_each_pci_dev or calling pci_realloc_detect() recursively, that will make code more readable. Per Bjorn, separate it from big patch that handing assign_unssigned per root bus. Signed-off-by: Yinghai Lu --- drivers/pci/setup-bus.c | 46 +++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) -- 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/setup-bus.c =================================================================== --- linux-2.6.orig/drivers/pci/setup-bus.c +++ linux-2.6/drivers/pci/setup-bus.c @@ -1427,30 +1427,46 @@ static bool __init pci_realloc_enabled(v return pci_realloc_enable >= user_enabled; } -static void __init pci_realloc_detect(void) -{ #if defined(CONFIG_PCI_IOV) && defined(CONFIG_PCI_REALLOC_ENABLE_AUTO) - struct pci_dev *dev = NULL; +static int __init check_unassigned_resources(struct pci_dev *dev, void *data) +{ + int i; + int *unassigned = data; - if (pci_realloc_enable != undefined) - return; + for (i = PCI_IOV_RESOURCES; i <= PCI_IOV_RESOURCE_END; i++) { + struct resource *r = &dev->resource[i]; - for_each_pci_dev(dev) { - int i; + /* Not assigned, or rejected by kernel ? */ + if (r->flags && !r->start) { + (*unassigned)++; + return 1; /* return early from pci_walk_bus */ + } + } - for (i = PCI_IOV_RESOURCES; i <= PCI_IOV_RESOURCE_END; i++) { - struct resource *r = &dev->resource[i]; + return 0; +} - /* Not assigned, or rejected by kernel ? */ - if (r->flags && !r->start) { - pci_realloc_enable = auto_enabled; +static void __init pci_realloc_detect(void) +{ + int unassigned = 0; + struct pci_bus *bus; - return; - } + if (pci_realloc_enable != undefined) + return; + + list_for_each_entry(bus, &pci_root_buses, node) { + pci_walk_bus(bus, check_unassigned_resources, &unassigned); + if (unassigned) { + pci_realloc_enable = auto_enabled; + return; } } -#endif } +#else +static void __init pci_realloc_detect(void) +{ +} +#endif /* * first try will not touch pci bridge res