From patchwork Tue Aug 16 10:07:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Westerberg X-Patchwork-Id: 12944614 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC522C32771 for ; Tue, 16 Aug 2022 10:48:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235072AbiHPKsm (ORCPT ); Tue, 16 Aug 2022 06:48:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235112AbiHPKsM (ORCPT ); Tue, 16 Aug 2022 06:48:12 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1297B56F3 for ; Tue, 16 Aug 2022 03:07:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660644450; x=1692180450; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PVlToHjzUmkOUyIQDLygwOdsJ9kHXBehWSrPCXAaSw0=; b=I00YbTDRO+SsWg1q1eKblZVFE9DJLcXOaJKFK7jHkBXhLryAKdH/JI3z UKLgHymoyO3hv+mEC2+oDBYXOmh1NozRKaIy/8G+y4Z/f+ZRIytpokidk 90yuRrPQSDGxWcdYPj6k6MMI6I1bwRE4g7JKC0fzh+ubHvkZ+WcpD75X/ ImprqB/UTqBJsRI/nfLtxEuYcHPt3Ordvpg3D43yV2bJKccx+lBVXMXDY 3megb/A8RA9dwe0rmHgolpsxbjJ//YDGPeksyoz3gMuFnIVv00ANel2Bg 7teZVpEtaTLoKJoUlkBnQMtH0WPeSNVdqu8wAipfkiUZyvMawOk5VXlly g==; X-IronPort-AV: E=McAfee;i="6400,9594,10440"; a="292175643" X-IronPort-AV: E=Sophos;i="5.93,240,1654585200"; d="scan'208";a="292175643" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2022 03:07:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,240,1654585200"; d="scan'208";a="782969817" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga005.jf.intel.com with ESMTP; 16 Aug 2022 03:07:28 -0700 Received: by black.fi.intel.com (Postfix, from userid 1001) id 1C94A235; Tue, 16 Aug 2022 13:07:41 +0300 (EEST) From: Mika Westerberg To: Bjorn Helgaas Cc: "Rafael J. Wysocki" , Andy Shevchenko , Lukas Wunner , Chris Chiu , Mika Westerberg , linux-pci@vger.kernel.org Subject: [PATCH 1/6] PCI: Fix used_buses calculation in pci_scan_child_bus_extend() Date: Tue, 16 Aug 2022 13:07:35 +0300 Message-Id: <20220816100740.68667-2-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220816100740.68667-1-mika.westerberg@linux.intel.com> References: <20220816100740.68667-1-mika.westerberg@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The 'cmax' and 'max' are in wrong order and that might cause the used_buses to become negative in certain cases. It should be the same as we do in the block following this one. Fix this. Link: https://bugzilla.kernel.org/show_bug.cgi?id=216000 Fixes: 3374c545c27c ("PCI: Account for all bridges on bus when distributing bus numbers") Reported-by: Chris Chiu Signed-off-by: Mika Westerberg --- drivers/pci/probe.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index c5286b027f00..4f940dcd102c 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -2920,8 +2920,8 @@ static unsigned int pci_scan_child_bus_extend(struct pci_bus *bus, * hotplug bridges too much during the second scan below. */ used_buses++; - if (cmax - max > 1) - used_buses += cmax - max - 1; + if (max - cmax > 1) + used_buses += max - cmax - 1; } /* Scan bridges that need to be reconfigured */ From patchwork Tue Aug 16 10:07:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Westerberg X-Patchwork-Id: 12944617 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2586C2BB41 for ; Tue, 16 Aug 2022 10:48:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235117AbiHPKsr (ORCPT ); Tue, 16 Aug 2022 06:48:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235079AbiHPKsW (ORCPT ); Tue, 16 Aug 2022 06:48:22 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85129B95AD for ; Tue, 16 Aug 2022 03:07:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660644452; x=1692180452; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8sJn5Wuc4HEXnk04lBc87C+RBz30csC0Dle0JOGbx7o=; b=FPx+lx6owyFtnhTkhx3SPjmHCc0C3fJ9usynLHNWuzcCzh9D5oypA+j/ hQ2UI6/WTRmWYxxniefhjN147qdhaOKOJFb54SVl/jpSp5mX0sibBPlY8 I7iy3t3o2SO/I5c19Yhj7SzYYXmEQJWVbpi4MBTmTyzCaluqSvstTpj49 vJ3d5QdBc9XeDFxMKOiIxkLkbXrM/9QSJGjJ0z7rS+IKi19ug7uV8dG4j Zy/cdEQK1/Rq4nHhSCc6L/K9Dr17lZJFI4SxkD+rmufh6aLAppa1H+rvQ fRndwm2AF69XJ14wd52Wi0S3rQDrsJuE0JDzbZBrcY3ze0RHtbGHYzlGU w==; X-IronPort-AV: E=McAfee;i="6400,9594,10440"; a="318171489" X-IronPort-AV: E=Sophos;i="5.93,240,1654585200"; d="scan'208";a="318171489" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2022 03:07:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,240,1654585200"; d="scan'208";a="675157369" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga004.fm.intel.com with ESMTP; 16 Aug 2022 03:07:28 -0700 Received: by black.fi.intel.com (Postfix, from userid 1001) id 2676B2F6; Tue, 16 Aug 2022 13:07:41 +0300 (EEST) From: Mika Westerberg To: Bjorn Helgaas Cc: "Rafael J. Wysocki" , Andy Shevchenko , Lukas Wunner , Chris Chiu , Mika Westerberg , linux-pci@vger.kernel.org Subject: [PATCH 2/6] PCI: Pass available buses also when the bridge is already configured Date: Tue, 16 Aug 2022 13:07:36 +0300 Message-Id: <20220816100740.68667-3-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220816100740.68667-1-mika.westerberg@linux.intel.com> References: <20220816100740.68667-1-mika.westerberg@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org If some part of the PCI topology is already configured (by the boot firmware) but not all, and it includes hotplug bridges, we may need to extend the bus resources of those bridges to accommondate any future hotplugs too - in the same way we already do with normal hotplug case. For this reason pass the available busses to pci_scan_child_bus_extend() even when the bridge in question is already configured. This allows the bus allocation code to use these available buses to extend the possible hotplug bridges below. Link: https://bugzilla.kernel.org/show_bug.cgi?id=216000 Reported-by: Chris Chiu Signed-off-by: Mika Westerberg --- drivers/pci/probe.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 4f940dcd102c..86130926a74f 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1297,7 +1297,7 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev, if ((secondary || subordinate) && !pcibios_assign_all_busses() && !is_cardbus && !broken) { - unsigned int cmax; + unsigned int cmax, buses; /* * Bus already configured by firmware, process it in the @@ -1322,7 +1322,8 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev, child->bridge_ctl = bctl; } - cmax = pci_scan_child_bus(child); + buses = subordinate - secondary; + cmax = pci_scan_child_bus_extend(child, buses); if (cmax > subordinate) pci_warn(dev, "bridge has subordinate %02x but max busn %02x\n", subordinate, cmax); From patchwork Tue Aug 16 10:07:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Westerberg X-Patchwork-Id: 12944616 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D88EC32772 for ; Tue, 16 Aug 2022 10:48:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233990AbiHPKsn (ORCPT ); Tue, 16 Aug 2022 06:48:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232469AbiHPKsT (ORCPT ); Tue, 16 Aug 2022 06:48:19 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD8E9B24B7 for ; Tue, 16 Aug 2022 03:07:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660644450; x=1692180450; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8MJ4dSvsrNn3RMNzqNeyobxHJuyQw2M91GQhuo05OH4=; b=h7Oqm5KYdjocVmSBtvYFChGnLikHm/ZTxugQfnOb4zFf/G061xZrRDXW eFhg7CdKusdRwkYSziwvaTzMrAoh5e/JHo/oxAUv+9JGla27KjZk8zZeA 8rXknse+juZKY7kEZlVlK//PWKS2HuqjzhU0Ytbe2m4Qg3rKJUJotE3wT m/itrf6TOFMHpxaDQPENx998lCsIPwCcRha4p6zOqTKxWi9Z3lwqH0Gth 7IdZsL4cTVLga6YbNs/DLbrvk6jsSRqn20gc0jzk0L/Zyqqk6DluAHTac lOru+L6A/FJzDcAw9PiuObQDzI0wnvx7gHLccZtG/BH8tL6pfQTdlkVZC g==; X-IronPort-AV: E=McAfee;i="6400,9594,10440"; a="356180007" X-IronPort-AV: E=Sophos;i="5.93,240,1654585200"; d="scan'208";a="356180007" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2022 03:07:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,240,1654585200"; d="scan'208";a="606976869" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga002.jf.intel.com with ESMTP; 16 Aug 2022 03:07:28 -0700 Received: by black.fi.intel.com (Postfix, from userid 1001) id 3435D3F5; Tue, 16 Aug 2022 13:07:41 +0300 (EEST) From: Mika Westerberg To: Bjorn Helgaas Cc: "Rafael J. Wysocki" , Andy Shevchenko , Lukas Wunner , Chris Chiu , Mika Westerberg , linux-pci@vger.kernel.org Subject: [PATCH 3/6] PCI: Distribute available resources for root buses too Date: Tue, 16 Aug 2022 13:07:37 +0300 Message-Id: <20220816100740.68667-4-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220816100740.68667-1-mika.westerberg@linux.intel.com> References: <20220816100740.68667-1-mika.westerberg@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Currently we distribute the spare resources only upon hot-add so if there are PCI devices connected already when the initial root bus scan is done, and they have not been fully configured by the BIOS, we may end up allocating resources just enough to cover only what is currently there. If some of those devices are hotplug bridges themselves we do not leave any additional resource space for future expansion. For this reason distribute the available resources for root buses too to make this work the same way we do in the normal hotplug case. Link: https://bugzilla.kernel.org/show_bug.cgi?id=216000 Reported-by: Chris Chiu Signed-off-by: Mika Westerberg --- The diffstat is quite big here but this is due the fact that we move the pci_assign_unassigned_root_bus_resources() below pci_bridge_distribute_available_resources() so we can call it without adding forward declaration. drivers/pci/setup-bus.c | 288 ++++++++++++++++++++++++---------------- 1 file changed, 174 insertions(+), 114 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 8cb68e6f6ef9..df9fc974b313 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1745,119 +1745,6 @@ static enum enable_type pci_realloc_detect(struct pci_bus *bus, } #endif -/* - * First try will not touch PCI bridge res. - * Second and later try will clear small leaf bridge res. - * Will stop till to the max depth if can not find good one. - */ -void pci_assign_unassigned_root_bus_resources(struct pci_bus *bus) -{ - LIST_HEAD(realloc_head); - /* List of resources that want additional resources */ - struct list_head *add_list = NULL; - int tried_times = 0; - enum release_type rel_type = leaf_only; - LIST_HEAD(fail_head); - struct pci_dev_resource *fail_res; - int pci_try_num = 1; - enum enable_type enable_local; - - /* Don't realloc if asked to do so */ - enable_local = pci_realloc_detect(bus, pci_realloc_enable); - if (pci_realloc_enabled(enable_local)) { - int max_depth = pci_bus_get_depth(bus); - - pci_try_num = max_depth + 1; - dev_info(&bus->dev, "max bus depth: %d pci_try_num: %d\n", - max_depth, pci_try_num); - } - -again: - /* - * Last try will use add_list, otherwise will try good to have as must - * have, so can realloc parent bridge resource - */ - if (tried_times + 1 == pci_try_num) - add_list = &realloc_head; - /* - * Depth first, calculate sizes and alignments of all subordinate buses. - */ - __pci_bus_size_bridges(bus, add_list); - - /* Depth last, allocate resources and update the hardware. */ - __pci_bus_assign_resources(bus, add_list, &fail_head); - if (add_list) - BUG_ON(!list_empty(add_list)); - tried_times++; - - /* Any device complain? */ - if (list_empty(&fail_head)) - goto dump; - - if (tried_times >= pci_try_num) { - if (enable_local == undefined) - dev_info(&bus->dev, "Some PCI device resources are unassigned, try booting with pci=realloc\n"); - else if (enable_local == auto_enabled) - dev_info(&bus->dev, "Automatically enabled pci realloc, if you have problem, try booting with pci=realloc=off\n"); - - free_list(&fail_head); - goto dump; - } - - dev_info(&bus->dev, "No. %d try to assign unassigned res\n", - tried_times + 1); - - /* Third times and later will not check if it is leaf */ - if ((tried_times + 1) > 2) - rel_type = whole_subtree; - - /* - * Try to release leaf bridge's resources that doesn't fit resource of - * child device under that bridge. - */ - list_for_each_entry(fail_res, &fail_head, list) - pci_bus_release_bridge_resources(fail_res->dev->bus, - fail_res->flags & PCI_RES_TYPE_MASK, - rel_type); - - /* Restore size and flags */ - list_for_each_entry(fail_res, &fail_head, list) { - struct resource *res = fail_res->res; - int idx; - - res->start = fail_res->start; - res->end = fail_res->end; - res->flags = fail_res->flags; - - if (pci_is_bridge(fail_res->dev)) { - idx = res - &fail_res->dev->resource[0]; - if (idx >= PCI_BRIDGE_RESOURCES && - idx <= PCI_BRIDGE_RESOURCE_END) - res->flags = 0; - } - } - free_list(&fail_head); - - goto again; - -dump: - /* Dump the resource on buses */ - pci_bus_dump_resources(bus); -} - -void __init pci_assign_unassigned_resources(void) -{ - struct pci_bus *root_bus; - - list_for_each_entry(root_bus, &pci_root_buses, node) { - pci_assign_unassigned_root_bus_resources(root_bus); - - /* Make sure the root bridge has a companion ACPI device */ - if (ACPI_HANDLE(root_bus->bridge)) - acpi_ioapic_add(ACPI_HANDLE(root_bus->bridge)); - } -} - static void adjust_bridge_window(struct pci_dev *bridge, struct resource *res, struct list_head *add_list, resource_size_t new_size) @@ -1881,7 +1768,10 @@ static void adjust_bridge_window(struct pci_dev *bridge, struct resource *res, } res->end = res->start + new_size - 1; - remove_from_list(add_list, res); + + /* If the resource is part of the add_list remove it now */ + if (add_list) + remove_from_list(add_list, res); } static void pci_bus_distribute_available_resources(struct pci_bus *bus, @@ -2036,6 +1926,8 @@ static void pci_bridge_distribute_available_resources(struct pci_dev *bridge, if (!bridge->is_hotplug_bridge) return; + pci_dbg(bridge, "distributing available resources\n"); + /* Take the initial extra resources from the hotplug port */ available_io = bridge->resource[PCI_BRIDGE_IO_WINDOW]; available_mmio = bridge->resource[PCI_BRIDGE_MEM_WINDOW]; @@ -2047,6 +1939,174 @@ static void pci_bridge_distribute_available_resources(struct pci_dev *bridge, available_mmio_pref); } +static bool pci_bridge_resources_not_assigned(struct pci_dev *dev) +{ + const struct resource *r; + + /* + * Check the child device's resources and if they are not yet + * assigned it means we are configuring them (not the boot + * firmware) so we should be able to extend the upstream + * bridge's (that's the hotplug downstream PCIe port) resources + * in the same way we do with the normal hotplug case. + */ + r = &dev->resource[PCI_BRIDGE_IO_WINDOW]; + if (!r->flags || !(r->flags & IORESOURCE_STARTALIGN)) + return false; + r = &dev->resource[PCI_BRIDGE_MEM_WINDOW]; + if (!r->flags || !(r->flags & IORESOURCE_STARTALIGN)) + return false; + r = &dev->resource[PCI_BRIDGE_PREF_MEM_WINDOW]; + if (!r->flags || !(r->flags & IORESOURCE_STARTALIGN)) + return false; + + return true; +} + +static void pci_root_bus_distribute_available_resources(struct pci_bus *bus, + struct list_head *add_list) +{ + struct pci_dev *dev, *bridge = bus->self; + + for_each_pci_bridge(dev, bus) { + struct pci_bus *b; + + b = dev->subordinate; + if (!b) + continue; + + /* + * Need to check "bridge" here too because it is NULL + * in case of root bus. + */ + if (bridge && pci_bridge_resources_not_assigned(dev)) { + pci_bridge_distribute_available_resources(bridge, add_list); + /* + * There is only PCIe upstream port on the bus + * so we don't need to go futher. + */ + return; + } + + pci_root_bus_distribute_available_resources(b, add_list); + } +} + +/* + * First try will not touch PCI bridge res. + * Second and later try will clear small leaf bridge res. + * Will stop till to the max depth if can not find good one. + */ +void pci_assign_unassigned_root_bus_resources(struct pci_bus *bus) +{ + LIST_HEAD(realloc_head); + /* List of resources that want additional resources */ + struct list_head *add_list = NULL; + int tried_times = 0; + enum release_type rel_type = leaf_only; + LIST_HEAD(fail_head); + struct pci_dev_resource *fail_res; + int pci_try_num = 1; + enum enable_type enable_local; + + /* Don't realloc if asked to do so */ + enable_local = pci_realloc_detect(bus, pci_realloc_enable); + if (pci_realloc_enabled(enable_local)) { + int max_depth = pci_bus_get_depth(bus); + + pci_try_num = max_depth + 1; + dev_info(&bus->dev, "max bus depth: %d pci_try_num: %d\n", + max_depth, pci_try_num); + } + +again: + /* + * Last try will use add_list, otherwise will try good to have as must + * have, so can realloc parent bridge resource + */ + if (tried_times + 1 == pci_try_num) + add_list = &realloc_head; + /* + * Depth first, calculate sizes and alignments of all subordinate buses. + */ + __pci_bus_size_bridges(bus, add_list); + + pci_root_bus_distribute_available_resources(bus, add_list); + + /* Depth last, allocate resources and update the hardware. */ + __pci_bus_assign_resources(bus, add_list, &fail_head); + if (add_list) + BUG_ON(!list_empty(add_list)); + tried_times++; + + /* Any device complain? */ + if (list_empty(&fail_head)) + goto dump; + + if (tried_times >= pci_try_num) { + if (enable_local == undefined) + dev_info(&bus->dev, "Some PCI device resources are unassigned, try booting with pci=realloc\n"); + else if (enable_local == auto_enabled) + dev_info(&bus->dev, "Automatically enabled pci realloc, if you have problem, try booting with pci=realloc=off\n"); + + free_list(&fail_head); + goto dump; + } + + dev_info(&bus->dev, "No. %d try to assign unassigned res\n", + tried_times + 1); + + /* Third times and later will not check if it is leaf */ + if ((tried_times + 1) > 2) + rel_type = whole_subtree; + + /* + * Try to release leaf bridge's resources that doesn't fit resource of + * child device under that bridge. + */ + list_for_each_entry(fail_res, &fail_head, list) + pci_bus_release_bridge_resources(fail_res->dev->bus, + fail_res->flags & PCI_RES_TYPE_MASK, + rel_type); + + /* Restore size and flags */ + list_for_each_entry(fail_res, &fail_head, list) { + struct resource *res = fail_res->res; + int idx; + + res->start = fail_res->start; + res->end = fail_res->end; + res->flags = fail_res->flags; + + if (pci_is_bridge(fail_res->dev)) { + idx = res - &fail_res->dev->resource[0]; + if (idx >= PCI_BRIDGE_RESOURCES && + idx <= PCI_BRIDGE_RESOURCE_END) + res->flags = 0; + } + } + free_list(&fail_head); + + goto again; + +dump: + /* Dump the resource on buses */ + pci_bus_dump_resources(bus); +} + +void __init pci_assign_unassigned_resources(void) +{ + struct pci_bus *root_bus; + + list_for_each_entry(root_bus, &pci_root_buses, node) { + pci_assign_unassigned_root_bus_resources(root_bus); + + /* Make sure the root bridge has a companion ACPI device */ + if (ACPI_HANDLE(root_bus->bridge)) + acpi_ioapic_add(ACPI_HANDLE(root_bus->bridge)); + } +} + void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge) { struct pci_bus *parent = bridge->subordinate; From patchwork Tue Aug 16 10:07:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Westerberg X-Patchwork-Id: 12944615 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB032C2BB41 for ; Tue, 16 Aug 2022 10:48:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233500AbiHPKsn (ORCPT ); Tue, 16 Aug 2022 06:48:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233990AbiHPKsN (ORCPT ); Tue, 16 Aug 2022 06:48:13 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 642D2B5E6A for ; Tue, 16 Aug 2022 03:07:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660644451; x=1692180451; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eKdwuHUEQ5iHdLeGzFWnZZ5OboFsdjjgUwuIZdCP/JM=; b=fnRoeZI1CDq9YsR/mhfKtNCC8LBwgttRnvZ0Gg/m56DLjYWuK3Mp7DSK kVkwFU5EbOTWrK+H5WWnytFX1ojc18bLiLmID7vUtDKmTeueL92CJuH4b ZeWqxbtg9Xc93EeEaxh8zWquZi/bprFADLcCwf7rke+T6SeL3taVgevF0 KkclNJxvbf/ZgOMMgRxtNBEWi4BNq8EmUS+/ABSqHYjC5GRohP7gTYGww UeEzjlMqWcW3T1sRaFLrRKySMdJY3Ier1n8kiZ5KQNkyCFDl+hmkzE2Up zMXsm//rM/SmgBwpZrmVojOz+7aFpKcmoYj55T1NINmUAPqKsY3ZrvdhI w==; X-IronPort-AV: E=McAfee;i="6400,9594,10440"; a="318171486" X-IronPort-AV: E=Sophos;i="5.93,240,1654585200"; d="scan'208";a="318171486" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2022 03:07:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,240,1654585200"; d="scan'208";a="852588681" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga006.fm.intel.com with ESMTP; 16 Aug 2022 03:07:28 -0700 Received: by black.fi.intel.com (Postfix, from userid 1001) id 398A7363; Tue, 16 Aug 2022 13:07:41 +0300 (EEST) From: Mika Westerberg To: Bjorn Helgaas Cc: "Rafael J. Wysocki" , Andy Shevchenko , Lukas Wunner , Chris Chiu , Mika Westerberg , linux-pci@vger.kernel.org Subject: [PATCH 4/6] PCI: Remove two unnecessary empty lines in pci_scan_child_bus_extend() Date: Tue, 16 Aug 2022 13:07:38 +0300 Message-Id: <20220816100740.68667-5-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220816100740.68667-1-mika.westerberg@linux.intel.com> References: <20220816100740.68667-1-mika.westerberg@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org These are not needed and are against the normal coding style anyway. Signed-off-by: Mika Westerberg --- drivers/pci/probe.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 86130926a74f..8f25deb6b763 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -2930,7 +2930,6 @@ static unsigned int pci_scan_child_bus_extend(struct pci_bus *bus, unsigned int buses = 0; if (!hotplug_bridges && normal_bridges == 1) { - /* * There is only one bridge on the bus (upstream * port) so it gets all available buses which it @@ -2939,7 +2938,6 @@ static unsigned int pci_scan_child_bus_extend(struct pci_bus *bus, */ buses = available_buses; } else if (dev->is_hotplug_bridge) { - /* * Distribute the extra buses between hotplug * bridges if any. From patchwork Tue Aug 16 10:07:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Westerberg X-Patchwork-Id: 12944619 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B075DC32771 for ; Tue, 16 Aug 2022 10:48:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234973AbiHPKst (ORCPT ); Tue, 16 Aug 2022 06:48:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235082AbiHPKsX (ORCPT ); Tue, 16 Aug 2022 06:48:23 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29461BA160 for ; Tue, 16 Aug 2022 03:07:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660644453; x=1692180453; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=K5UNXhzXw1ZtirG/F3j1naO3htxk4w0EKIpItJ4JuUY=; b=WAG8RbuRyAkAGuEai3Q05Zlpx31hsqC39BxNIglhHJFVtnHlpN6+Hid/ yvcHjfbuJClbx1+BlLjjYodWDuBs6vf74Mrzdwtvg5DmwiWe77iqV0y5Q gsGYQR3CfgVdJUJ7wbxMCC5tK0frOviRjwy1qT1ckj2JpunBfBVrc6cRR izUcOGoX0Gto05IKJWEsihwTYlTQChevEczA8yTW/P34mgrwx/f9zc0O9 VJdQ/5xBRaEzOvxMANo1UQ50O5G7rBw07UyeycnG1u7zwg6YmBuTPMsEN dzNjq9SpI2I5T2qzpMkwc1dpn4MVMvsEIdffhxxQsaMQCBhqHckjAc0Zp g==; X-IronPort-AV: E=McAfee;i="6400,9594,10440"; a="292974309" X-IronPort-AV: E=Sophos;i="5.93,240,1654585200"; d="scan'208";a="292974309" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2022 03:07:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,240,1654585200"; d="scan'208";a="710082641" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga002.fm.intel.com with ESMTP; 16 Aug 2022 03:07:30 -0700 Received: by black.fi.intel.com (Postfix, from userid 1001) id 42C5345C; Tue, 16 Aug 2022 13:07:41 +0300 (EEST) From: Mika Westerberg To: Bjorn Helgaas Cc: "Rafael J. Wysocki" , Andy Shevchenko , Lukas Wunner , Chris Chiu , Mika Westerberg , linux-pci@vger.kernel.org Subject: [PATCH 5/6] PCI: Fix typo in pci_scan_child_bus_extend() Date: Tue, 16 Aug 2022 13:07:39 +0300 Message-Id: <20220816100740.68667-6-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220816100740.68667-1-mika.westerberg@linux.intel.com> References: <20220816100740.68667-1-mika.westerberg@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Should be 'if' not 'of'. Fix this. Signed-off-by: Mika Westerberg --- drivers/pci/probe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 8f25deb6b763..b66fa42c4b1f 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -2956,7 +2956,7 @@ static unsigned int pci_scan_child_bus_extend(struct pci_bus *bus, /* * Make sure a hotplug bridge has at least the minimum requested * number of buses but allow it to grow up to the maximum available - * bus number of there is room. + * bus number if there is room. */ if (bus->self && bus->self->is_hotplug_bridge) { used_buses = max_t(unsigned int, available_buses, From patchwork Tue Aug 16 10:07:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Westerberg X-Patchwork-Id: 12944618 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D9C9C32772 for ; Tue, 16 Aug 2022 10:48:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234949AbiHPKss (ORCPT ); Tue, 16 Aug 2022 06:48:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234945AbiHPKsX (ORCPT ); Tue, 16 Aug 2022 06:48:23 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60681BA9DB for ; Tue, 16 Aug 2022 03:07:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660644453; x=1692180453; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YCQLidEJM0K7+j8DIvbZtOAx9fB9psFBgizZszFCegc=; b=INYqIDhn+RR5sCHg9OCg7oH9w71ngpgk4GpttDqOhlDS/m3VXW2fh3kV jCgqDE1/Jl1E4nR4vVJNfABBaHi7jggXHTxL71OaDtvH/V//uxxXMqctE pm5AVYP1uj69QuVk8K0MbRLakJiTrQFU/fc2kkO0Q/D86I7q/n2ksptyD i9vrYDgUtj1OQ9sdePl7ESOvhXm0OxAMOT+CUr65Es+Kg5VgfliISJX4m x6HqPPsWmMOzbT8FqG1lBmzfbaBBH7HzKbxr4L0oD8M0Ls6P9CHzbht1/ qqaZJp1tX016r0VN8ToM0WQMOe4klNzPr1AYXh1Eiv0Mra8X26taRXizk Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10440"; a="318171494" X-IronPort-AV: E=Sophos;i="5.93,240,1654585200"; d="scan'208";a="318171494" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Aug 2022 03:07:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,240,1654585200"; d="scan'208";a="603467763" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga007.jf.intel.com with ESMTP; 16 Aug 2022 03:07:30 -0700 Received: by black.fi.intel.com (Postfix, from userid 1001) id 4C011540; Tue, 16 Aug 2022 13:07:41 +0300 (EEST) From: Mika Westerberg To: Bjorn Helgaas Cc: "Rafael J. Wysocki" , Andy Shevchenko , Lukas Wunner , Chris Chiu , Mika Westerberg , linux-pci@vger.kernel.org Subject: [PATCH 6/6] PCI: Fix indentation in pci_bridge_distribute_available_resources() Date: Tue, 16 Aug 2022 13:07:40 +0300 Message-Id: <20220816100740.68667-7-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220816100740.68667-1-mika.westerberg@linux.intel.com> References: <20220816100740.68667-1-mika.westerberg@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Correct the indentation according the coding style. Signed-off-by: Mika Westerberg --- drivers/pci/setup-bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index df9fc974b313..dc6a30ee6edf 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1919,7 +1919,7 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus, } static void pci_bridge_distribute_available_resources(struct pci_dev *bridge, - struct list_head *add_list) + struct list_head *add_list) { struct resource available_io, available_mmio, available_mmio_pref;