From patchwork Mon Apr 15 17:09:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Johnson X-Patchwork-Id: 10901263 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 996891390 for ; Mon, 15 Apr 2019 17:09:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 78B312892B for ; Mon, 15 Apr 2019 17:09:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6CBD728931; Mon, 15 Apr 2019 17:09:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F28D2892B for ; Mon, 15 Apr 2019 17:09:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727413AbfDORJY convert rfc822-to-8bit (ORCPT ); Mon, 15 Apr 2019 13:09:24 -0400 Received: from mail-oln040092253105.outbound.protection.outlook.com ([40.92.253.105]:29024 "EHLO APC01-SG2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726348AbfDORJY (ORCPT ); Mon, 15 Apr 2019 13:09:24 -0400 Received: from HK2APC01FT059.eop-APC01.prod.protection.outlook.com (10.152.248.57) by HK2APC01HT211.eop-APC01.prod.protection.outlook.com (10.152.248.239) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1771.16; Mon, 15 Apr 2019 17:09:16 +0000 Received: from PS2P216MB0642.KORP216.PROD.OUTLOOK.COM (10.152.248.52) by HK2APC01FT059.mail.protection.outlook.com (10.152.249.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1771.16 via Frontend Transport; Mon, 15 Apr 2019 17:09:16 +0000 Received: from PS2P216MB0642.KORP216.PROD.OUTLOOK.COM ([fe80::50ee:2afa:f5b:9647]) by PS2P216MB0642.KORP216.PROD.OUTLOOK.COM ([fe80::50ee:2afa:f5b:9647%6]) with mapi id 15.20.1792.018; Mon, 15 Apr 2019 17:09:16 +0000 From: Nicholas Johnson To: "linux-kernel@vger.kernel.org" CC: "linux-pci@vger.kernel.org" , "bhelgaas@google.com" , "mika.westerberg@linux.intel.com" , "corbet@lwn.net" , Nicholas Johnson Subject: [PATCH v3 1/5] PCI: Consider alignment of hot-added bridges when distributing available resources Thread-Topic: [PATCH v3 1/5] PCI: Consider alignment of hot-added bridges when distributing available resources Thread-Index: AQHU8630UVJocl3sDU+Wtpjo0sKjJg== Date: Mon, 15 Apr 2019 17:09:16 +0000 Message-ID: References: <20190416010756.31313-1-nicholas.johnson-opensource@outlook.com.au> In-Reply-To: <20190416010756.31313-1-nicholas.johnson-opensource@outlook.com.au> Accept-Language: en-AU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SG2PR04CA0155.apcprd04.prod.outlook.com (2603:1096:4::17) To PS2P216MB0642.KORP216.PROD.OUTLOOK.COM (2603:1096:300:1c::16) x-incomingtopheadermarker: OriginalChecksum:90F67B416BBA77ED9BC10525D65C1195AF03544308BA15E1D3BA1574F83364E0;UpperCasedChecksum:8F632E6066989AE5BCF026A9D74A0E9694D66E3EA2CEC942C0820C292ACE0442;SizeAsReceived:7935;Count:50 x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.19.1 x-tmn: [u1El33Fub6p46w1DAvRw1+M2Stu9RohPumqOwwXD5uDla4ZX+GUyGlcHyA05T7XuUL5vcWYuqSs=] x-microsoft-original-message-id: <20190416010756.31313-3-nicholas.johnson-opensource@outlook.com.au> x-ms-publictraffictype: Email x-incomingheadercount: 50 x-eopattributedmessage: 0 x-ms-exchange-slblob-mailprops: mBy7Mai7yE4ToL4gNTPdRpfskE+PVEk3kj0wRVii2+08bQWUBm7jFb5sVtqkStCBOfIPOqS8OIdLudjZZfGlnQtY6hAL4sBtD5yAjq4e3CBxOcibRnN2QxHA71osbzZYUgjTHDwXeB2yf1Zjz1TF1yauq1YQcy5/jRafmQrip3PKsTVVzn0jqPgXa+eFUVrgQ6FORWkM1DuZ22rwaUJWjKyQF42N93HRzSqSgD5tCVYN354peBZMXVOl/Yb9fr7MtIdsA6kYdklz5opJzgsNWqIuVPdh5YgfrVN3h+XFVFT5UaHLOkaeamNPScDtFb39elYTu3OP8zgrw9TUHbL2zcvxvbm8V2XcSl6C/4NKFdkZWNnNT7QB3jpiBgxVCu/oBzOnszrw+nwGdSpXv2eCfY0OPS0BssNJU9X7tlrwYCcNpTXNG4ek69hDzId4KK9WTzr0VKXGCgRyKtkHYp9Gy8+D6Cr10LU5bmsTyjhe6hUY+dvsOzaS5m7hPeQV5qLFSY7ggHJmFBwjCVo27aRjeYg+aaCtm7V0yW1ubf4D2eIrPJF5HDtSlL1VEQKE1CbVp1yP8UfZxtlLIkxRg/Khl60Vs+Ypco2dFsDZaae7yWD4y9bxRpbAxUttcybutHIXJVJSzKBGcE3ngbM4hP27Fb87qyBcZOlANSgkQQuZidWW74QMe+EByrhMgaX/VyHhyuK4TiWHQ8LGvS8Q/k+g2xJ/4FSzJlAO x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(20181119110)(201702061078)(5061506573)(5061507331)(1603103135)(2017031320274)(201702181274)(2017031323274)(2017031324274)(2017031322404)(1601125500)(1603101475)(1701031045);SRVR:HK2APC01HT211; x-ms-traffictypediagnostic: HK2APC01HT211: x-microsoft-antispam-message-info: NQ65xeSB2T77zcLokLVbiqYaGe9w1AD8+mqVVDGArAzBBAH25j5CIAGuqEZSvXnz8XbiomlqdyW+zOhtqe2y7MImLvU7ZTG3o3/+DrdZ8++Y1fPWNcZOfv7Xl8Ul/4ueScUCDmMjqs2epolT8f2Dj6QqXt6D+i10dAGShNcFUD1FALjt7WvaY2FrPaqURQ2q MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: ede007f2-6813-4d12-05f8-08d6c1c516fd X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Apr 2019 17:09:16.1615 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: HK2APC01HT211 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Rewrite pci_bus_distribute_available_resources to better handle bridges with different resource alignment requirements. Pass more details arguments recursively to track the resource start and end addresses relative to the initial hotplug bridge. This is especially useful for Thunderbolt with native PCI enumeration, enabling external graphics cards and other devices with bridge alignment higher than 0x100000 bytes. Change extend_bridge_window to resize the actual resource, rather than using add_list and dev_res->add_size. If an additional resource entry exists for the given resource, zero out the add_size field to avoid it interfering. Because add_size is considered optional when allocating, using add_size could cause issues in some cases, because successful resource distribution requires sizes to be guaranteed. Such cases include hot-adding nested hotplug bridges in one enumeration, and potentially others which are yet to be encountered. Signed-off-by: Nicholas Johnson --- drivers/pci/setup-bus.c | 203 ++++++++++++++++++++++------------------ 1 file changed, 110 insertions(+), 93 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index ed960436d..75827fb06 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1852,34 +1852,48 @@ void __init pci_assign_unassigned_resources(void) } static void extend_bridge_window(struct pci_dev *bridge, struct resource *res, - struct list_head *add_list, resource_size_t available) + struct list_head *add_list, resource_size_t new_size) { struct pci_dev_resource *dev_res; + resource_size_t add_size; if (res->parent) return; - if (resource_size(res) >= available) - return; - - dev_res = res_to_dev_res(add_list, res); - if (!dev_res) - return; + /* + * Resources requested using add_size in additional resource lists are + * considered optional when allocated. Guaranteed size of allocation + * is required to guarantee successful resource distribution. Hence, + * the size of the actual resource must be adjusted. + */ + if (new_size >= resource_size(res)) { + add_size = new_size - resource_size(res); + pci_dbg(bridge, "bridge window %pR extended by %pa\n", res, + &add_size); + } else { + add_size = resource_size(res) - new_size; + pci_dbg(bridge, "bridge window %pR shrunken by %pa\n", res, + &add_size); + } - /* Is there room to extend the window? */ - if (available - resource_size(res) <= dev_res->add_size) - return; + res->end = res->start + new_size - 1; - dev_res->add_size = available - resource_size(res); - pci_dbg(bridge, "bridge window %pR extended by %pa\n", res, - &dev_res->add_size); + /* + * If a list entry exists, we need to remove any additional size + * requested because that could interfere with the alignment and + * sizing done when distributing resources, causing resources to + * fail to allocate later on. + */ + dev_res = res_to_dev_res(add_list, res); + if (dev_res) + dev_res->add_size = 0; } static void pci_bus_distribute_available_resources(struct pci_bus *bus, - struct list_head *add_list, resource_size_t available_io, - resource_size_t available_mmio, resource_size_t available_mmio_pref) + struct list_head *add_list, struct resource io, + struct resource mmio, struct resource mmio_pref) { - resource_size_t remaining_io, remaining_mmio, remaining_mmio_pref; + resource_size_t io_per_hp, mmio_per_hp, mmio_pref_per_hp, align; unsigned int normal_bridges = 0, hotplug_bridges = 0; struct resource *io_res, *mmio_res, *mmio_pref_res; struct pci_dev *dev, *bridge = bus->self; @@ -1889,25 +1903,32 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus, mmio_pref_res = &bridge->resource[PCI_BRIDGE_RESOURCES + 2]; /* - * Update additional resource list (add_list) to fill all the - * extra resource space available for this port except the space - * calculated in __pci_bus_size_bridges() which covers all the - * devices currently connected to the port and below. + * The alignment of this bridge is yet to be considered, hence it must + * be done now before extending its bridge window. A single bridge + * might not be able to occupy the whole parent region if the alignment + * differs - for example, an external GPU at the end of a Thunderbolt + * daisy chain. */ - extend_bridge_window(bridge, io_res, add_list, available_io); - extend_bridge_window(bridge, mmio_res, add_list, available_mmio); - extend_bridge_window(bridge, mmio_pref_res, add_list, - available_mmio_pref); + align = pci_resource_alignment(bridge, io_res); + if (!io_res->parent && align) + io.start = ALIGN(io.start, align); + + align = pci_resource_alignment(bridge, mmio_res); + if (!mmio_res->parent && align) + mmio.start = ALIGN(mmio.start, align); + + align = pci_resource_alignment(bridge, mmio_pref_res); + if (!mmio_pref_res->parent && align) + mmio_pref.start = ALIGN(mmio_pref.start, align); /* - * Calculate the total amount of extra resource space we can - * pass to bridges below this one. This is basically the - * extra space reduced by the minimal required space for the - * non-hotplug bridges. + * Update the resources to fill as much remaining resource space in the + * parent bridge as possible, while considering alignment. */ - remaining_io = available_io; - remaining_mmio = available_mmio; - remaining_mmio_pref = available_mmio_pref; + extend_bridge_window(bridge, io_res, add_list, resource_size(&io)); + extend_bridge_window(bridge, mmio_res, add_list, resource_size(&mmio)); + extend_bridge_window(bridge, mmio_pref_res, add_list, + resource_size(&mmio_pref)); /* * Calculate how many hotplug bridges and normal bridges there @@ -1921,80 +1942,79 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus, normal_bridges++; } + /* + * There is only one bridge on the bus so it gets all possible + * resources which it can then distribute to the possible + * hotplug bridges below. + */ + if (hotplug_bridges + normal_bridges == 1) { + dev = list_first_entry(&bus->devices, struct pci_dev, bus_list); + if (dev->subordinate) + pci_bus_distribute_available_resources(dev->subordinate, + add_list, io, mmio, mmio_pref); + return; + } + + /* + * Reduce the available resource space by what the + * bridge and devices below it occupy. + */ for_each_pci_bridge(dev, bus) { - const struct resource *res; + struct resource *res; + resource_size_t used_size; if (dev->is_hotplug_bridge) continue; - /* - * Reduce the available resource space by what the - * bridge and devices below it occupy. - */ res = &dev->resource[PCI_BRIDGE_RESOURCES + 0]; - if (!res->parent && available_io > resource_size(res)) - remaining_io -= resource_size(res); + align = pci_resource_alignment(dev, res); + align = align ? ALIGN(io.start, align) - io.start : 0; + used_size = align + resource_size(res); + if (!res->parent && used_size <= resource_size(&io)) + io.start += used_size; res = &dev->resource[PCI_BRIDGE_RESOURCES + 1]; - if (!res->parent && available_mmio > resource_size(res)) - remaining_mmio -= resource_size(res); + align = pci_resource_alignment(dev, res); + align = align ? ALIGN(mmio.start, align) - mmio.start : 0; + used_size = align + resource_size(res); + if (!res->parent && used_size <= resource_size(&mmio)) + mmio.start += used_size; res = &dev->resource[PCI_BRIDGE_RESOURCES + 2]; - if (!res->parent && available_mmio_pref > resource_size(res)) - remaining_mmio_pref -= resource_size(res); + align = pci_resource_alignment(dev, res); + align = align ? ALIGN(mmio_pref.start, align) - + mmio_pref.start : 0; + used_size = align + resource_size(res); + if (!res->parent && used_size <= resource_size(&mmio_pref)) + mmio_pref.start += used_size; } - /* - * There is only one bridge on the bus so it gets all available - * resources which it can then distribute to the possible - * hotplug bridges below. - */ - if (hotplug_bridges + normal_bridges == 1) { - dev = list_first_entry(&bus->devices, struct pci_dev, bus_list); - if (dev->subordinate) { - pci_bus_distribute_available_resources(dev->subordinate, - add_list, available_io, available_mmio, - available_mmio_pref); - } + if (!hotplug_bridges) return; - } /* - * Go over devices on this bus and distribute the remaining - * resource space between hotplug bridges. + * Distribute any remaining resources equally between + * the hotplug-capable downstream ports. */ - for_each_pci_bridge(dev, bus) { - resource_size_t align, io, mmio, mmio_pref; - struct pci_bus *b; + io_per_hp = div64_ul(resource_size(&io), hotplug_bridges); + mmio_per_hp = div64_ul(resource_size(&mmio), hotplug_bridges); + mmio_pref_per_hp = div64_ul(resource_size(&mmio_pref), + hotplug_bridges); - b = dev->subordinate; - if (!b || !dev->is_hotplug_bridge) + for_each_pci_bridge(dev, bus) { + if (!dev->subordinate || !dev->is_hotplug_bridge) continue; - /* - * Distribute available extra resources equally between - * hotplug-capable downstream ports taking alignment into - * account. - * - * Here hotplug_bridges is always != 0. - */ - align = pci_resource_alignment(bridge, io_res); - io = div64_ul(available_io, hotplug_bridges); - io = min(ALIGN(io, align), remaining_io); - remaining_io -= io; - - align = pci_resource_alignment(bridge, mmio_res); - mmio = div64_ul(available_mmio, hotplug_bridges); - mmio = min(ALIGN(mmio, align), remaining_mmio); - remaining_mmio -= mmio; + io.end = io.start + io_per_hp - 1; + mmio.end = mmio.start + mmio_per_hp - 1; + mmio_pref.end = mmio_pref.start + mmio_pref_per_hp - 1; - align = pci_resource_alignment(bridge, mmio_pref_res); - mmio_pref = div64_ul(available_mmio_pref, hotplug_bridges); - mmio_pref = min(ALIGN(mmio_pref, align), remaining_mmio_pref); - remaining_mmio_pref -= mmio_pref; + pci_bus_distribute_available_resources(dev->subordinate, + add_list, io, mmio, mmio_pref); - pci_bus_distribute_available_resources(b, add_list, io, mmio, - mmio_pref); + io.start = io.end + 1; + mmio.start = mmio.end + 1; + mmio_pref.start = mmio_pref.end + 1; } } @@ -2002,22 +2022,19 @@ static void pci_bridge_distribute_available_resources(struct pci_dev *bridge, struct list_head *add_list) { - resource_size_t available_io, available_mmio, available_mmio_pref; - const struct resource *res; + struct resource io_res, mmio_res, mmio_pref_res; if (!bridge->is_hotplug_bridge) return; + io_res = bridge->resource[PCI_BRIDGE_RESOURCES + 0]; + mmio_res = bridge->resource[PCI_BRIDGE_RESOURCES + 1]; + mmio_pref_res = bridge->resource[PCI_BRIDGE_RESOURCES + 2]; + /* Take the initial extra resources from the hotplug port */ - res = &bridge->resource[PCI_BRIDGE_RESOURCES + 0]; - available_io = resource_size(res); - res = &bridge->resource[PCI_BRIDGE_RESOURCES + 1]; - available_mmio = resource_size(res); - res = &bridge->resource[PCI_BRIDGE_RESOURCES + 2]; - available_mmio_pref = resource_size(res); pci_bus_distribute_available_resources(bridge->subordinate, - add_list, available_io, available_mmio, available_mmio_pref); + add_list, io_res, mmio_res, mmio_pref_res); } void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge) From patchwork Mon Apr 15 17:09:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Johnson X-Patchwork-Id: 10901265 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0EA6D1390 for ; Mon, 15 Apr 2019 17:09:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E198E284E4 for ; Mon, 15 Apr 2019 17:09:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D2D502852A; Mon, 15 Apr 2019 17:09:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 52AEA284E4 for ; Mon, 15 Apr 2019 17:09:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727796AbfDORJk convert rfc822-to-8bit (ORCPT ); Mon, 15 Apr 2019 13:09:40 -0400 Received: from mail-oln040092255027.outbound.protection.outlook.com ([40.92.255.27]:50784 "EHLO APC01-HK2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726348AbfDORJk (ORCPT ); Mon, 15 Apr 2019 13:09:40 -0400 Received: from HK2APC01FT059.eop-APC01.prod.protection.outlook.com (10.152.248.60) by HK2APC01HT217.eop-APC01.prod.protection.outlook.com (10.152.249.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1771.16; Mon, 15 Apr 2019 17:09:27 +0000 Received: from PS2P216MB0642.KORP216.PROD.OUTLOOK.COM (10.152.248.52) by HK2APC01FT059.mail.protection.outlook.com (10.152.249.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1771.16 via Frontend Transport; Mon, 15 Apr 2019 17:09:27 +0000 Received: from PS2P216MB0642.KORP216.PROD.OUTLOOK.COM ([fe80::50ee:2afa:f5b:9647]) by PS2P216MB0642.KORP216.PROD.OUTLOOK.COM ([fe80::50ee:2afa:f5b:9647%6]) with mapi id 15.20.1792.018; Mon, 15 Apr 2019 17:09:27 +0000 From: Nicholas Johnson To: "linux-kernel@vger.kernel.org" CC: "linux-pci@vger.kernel.org" , "bhelgaas@google.com" , "mika.westerberg@linux.intel.com" , "corbet@lwn.net" , Nicholas Johnson Subject: [PATCH v3 2/5] PCI: Cleanup comments in setup-bus.c to meet kernel coding style guidelines Thread-Topic: [PATCH v3 2/5] PCI: Cleanup comments in setup-bus.c to meet kernel coding style guidelines Thread-Index: AQHU8637VzvZe+R9yke1gPblleS47Q== Date: Mon, 15 Apr 2019 17:09:27 +0000 Message-ID: References: <20190416010756.31313-1-nicholas.johnson-opensource@outlook.com.au> In-Reply-To: <20190416010756.31313-1-nicholas.johnson-opensource@outlook.com.au> Accept-Language: en-AU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SG2PR01CA0088.apcprd01.prod.exchangelabs.com (2603:1096:3:15::14) To PS2P216MB0642.KORP216.PROD.OUTLOOK.COM (2603:1096:300:1c::16) x-incomingtopheadermarker: OriginalChecksum:2EDAF77BFE25357A776420C4C7BBA9A194E590E12DC06444AD46B482EE3AC4C0;UpperCasedChecksum:F75CE9345441C52C8D89D02B95F53F4384D31DC60D1B2692CC3CCC115917C483;SizeAsReceived:7957;Count:50 x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.19.1 x-tmn: [EeUdszISIB5iFkOoQ72PsyVusDXA6Xq6/pa91sTSIM6Xgmd3IgXy1Zup3h+YHLlugjtBdPE/xNc=] x-microsoft-original-message-id: <20190416010756.31313-4-nicholas.johnson-opensource@outlook.com.au> x-ms-publictraffictype: Email x-incomingheadercount: 50 x-eopattributedmessage: 0 x-ms-exchange-slblob-mailprops: zswcL9HXbeXjLSNNcQpvuD9Rx3UxByW7jXpCLV4S3pPSZ8KQNRYKi7IQoG1UDYw9h7VZJDsJ8R5LVZuP63k4e/OpeRj6mV659qD74RJCX8gnq8oUAjZugJ55crh6ijc6AnK96DYL9p5oPEcEL6XjTPgOo7jXhmhDtLfeGtwy0x6o/HzsxRPj8Yx7ZByqtIlqmWX42bIOOSR9k5rTKkWtuhwX9p+/BkYEsybwdy861ygEnK3nvST96ZUYh5wqsZvIrI9moF4yHNcDXenDo5PElYovT6FsANMYHiJYrZ1Nb1c5DAWPX4zx9zpWB0EdoCinLy3NY7+xvMfUP0g8J/i+D56LoI+sGmbWOHNDQ6VJ6bL+pmxFod/g++mYwIOGRcuWq6LEC6N7eVRilhwULfvoo5Wvh6kpWeLKupENqaMflF1+Gl0X5Fc/ox+9rBbCjTdSGmreubs5Hg8T4BrOc0NzwOCVzphOOGIIJV1VIsJ8UbZpd1fnV4EKkqfwBEItpVznmibnDrYNHsEO6K+EnFscy9w/3wuLyqgZqMoprM60UNqdR0VNV68ujYcN22x28e/slg/xR1rZoaiUIpeb4FwUMAkY2W3+/YivRedaBm75KmBZZbLgUtZp6dTALh2WzR2Zuffro/4BsW3WwzCK/rjk/pqU2gNr0/SL5sP9lMgIlJg8m3WGP3DOcAyv9PZyEHs8LmFIpActTX61zEpY40xhybAmHSKVB2pMX+Xw6JTBWkjaqldCRSDPL1z0fx7zkJDA x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(20181119110)(201702061078)(5061506573)(5061507331)(1603103135)(2017031320274)(201702181274)(2017031323274)(2017031324274)(2017031322404)(1601125500)(1603101475)(1701031045);SRVR:HK2APC01HT217; x-ms-traffictypediagnostic: HK2APC01HT217: x-microsoft-antispam-message-info: XYf4nKcgMLjzSO/jK9pVdlfd7coCFXzkgVLCP3i3CNi1q7PGO+MeUylkCOlE4AofrlYwet33Pn1Pl7drbHDCztPztFZhnm/kE5a3aoNZdM/KFUviU14cAov71xomODdlZdX4m/8416TRO6HdR3MnSZ9dqplzAw8OIrrfC4iNqyNSk6W4fam2Z3PyKNU82seL MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 98711f67-b985-439d-4f4e-08d6c1c51da9 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Apr 2019 17:09:27.3560 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: HK2APC01HT217 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Change block comments to accepted style with asterisks on each line. Justify block comments to 80-character limit to reduce the number of lines where possible. Signed-off-by: Nicholas Johnson --- drivers/pci/setup-bus.c | 265 ++++++++++++++++++++-------------------- 1 file changed, 130 insertions(+), 135 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 75827fb06..0ce641282 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -51,11 +51,9 @@ static void free_list(struct list_head *head) /** * add_to_list() - add a new resource tracker to the list * @head: Head of the list - * @dev: device corresponding to which the resource - * belongs + * @dev: device corresponding to which the resource belongs * @res: The resource to be tracked - * @add_size: additional size to be optionally added - * to the resource + * @add_size: additional size to be optionally added to the resource */ static int add_to_list(struct list_head *head, struct pci_dev *dev, struct resource *res, @@ -158,7 +156,7 @@ static void pdev_sort_resources(struct pci_dev *dev, struct list_head *head) tmp->res = r; tmp->dev = dev; - /* fallback is smallest one or list is empty*/ + /* fallback is smallest one or list is empty */ n = head; list_for_each_entry(dev_res, head, list) { resource_size_t align; @@ -171,7 +169,7 @@ static void pdev_sort_resources(struct pci_dev *dev, struct list_head *head) break; } } - /* Insert it just before n*/ + /* Insert it just before n */ list_add_tail(&tmp->list, n); } } @@ -181,7 +179,7 @@ static void __dev_sort_resources(struct pci_dev *dev, { u16 class = dev->class >> 8; - /* Don't touch classless devices or host bridges or ioapics. */ + /* Don't touch classless devices or host bridges or ioapics */ if (class == PCI_CLASS_NOT_DEFINED || class == PCI_CLASS_BRIDGE_HOST) return; @@ -208,12 +206,10 @@ static inline void reset_resource(struct resource *res) * * @realloc_head : head of the list tracking requests requiring additional * resources - * @head : head of the list tracking requests with allocated - * resources + * @head : head of the list tracking requests with allocated resources * - * Walk through each element of the realloc_head and try to procure - * additional resources for the element, provided the element - * is in the head list. + * Walk through each element of the realloc_head and try to procure additional + * resources for the element, provided the element is in the head list. */ static void reassign_resources_sorted(struct list_head *realloc_head, struct list_head *head) @@ -315,10 +311,9 @@ static unsigned long pci_fail_res_type_mask(struct list_head *fail_head) mask |= fail_res->flags; /* - * one pref failed resource will set IORESOURCE_MEM, - * as we can allocate pref in non-pref range. - * Will release all assigned non-pref sibling resources - * according to that bit. + * one pref failed resource will set IORESOURCE_MEM, as we can allocate + * pref in non-pref range. Will release all assigned non-pref sibling + * resources according to that bit. */ return mask & (IORESOURCE_IO | IORESOURCE_MEM | IORESOURCE_PREFETCH); } @@ -351,25 +346,24 @@ static void __assign_resources_sorted(struct list_head *head, struct list_head *fail_head) { /* - * Should not assign requested resources at first. - * they could be adjacent, so later reassign can not reallocate - * them one by one in parent resource window. - * Try to assign requested + add_size at beginning - * if could do that, could get out early. - * if could not do that, we still try to assign requested at first, - * then try to reassign add_size for some resources. + * Should not assign requested resources at first. They could be + * adjacent, so later reassign can not reallocate them one by one in + * parent resource window. + * + * Try to assign requested + add_size at beginning. If could do that, + * could get out early. If could not do that, we still try to assign + * requested at first, then try to reassign add_size for some resources. * * Separate three resource type checking if we need to release * assigned resource after requested + add_size try. - * 1. if there is io port assign fail, will release assigned - * io port. - * 2. if there is pref mmio assign fail, release assigned - * pref mmio. - * if assigned pref mmio's parent is non-pref mmio and there - * is non-pref mmio assign fail, will release that assigned - * pref mmio. - * 3. if there is non-pref mmio assign fail or pref mmio - * assigned fail, will release assigned non-pref mmio. + * 1. if there is io port assign fail, will release assigned io + * port. + * 2. if there is pref mmio assign fail, release assigned pref + * mmio. If assigned pref mmio's parent is non-pref mmio + * and there is non-pref mmio assign fail, will release that + * assigned pref mmio. + * 3. if there is non-pref mmio assign fail or pref mmio assigned + * fail, will release assigned non-pref mmio. */ LIST_HEAD(save_head); LIST_HEAD(local_fail_head); @@ -398,7 +392,7 @@ static void __assign_resources_sorted(struct list_head *head, /* * There are two kinds of additional resources in the list: * 1. bridge resource -- IORESOURCE_STARTALIGN - * 2. SR-IOV resource -- IORESOURCE_SIZEALIGN + * 2. SR-IOV resource -- IORESOURCE_SIZEALIGN * Here just fix the additional alignment for bridge */ if (!(dev_res->res->flags & IORESOURCE_STARTALIGN)) @@ -477,8 +471,7 @@ static void __assign_resources_sorted(struct list_head *head, /* Satisfy the must-have resource requests */ assign_requested_resources_sorted(head, fail_head); - /* Try to satisfy any additional optional resource - requests */ + /* Try to satisfy any additional optional resource requests */ if (realloc_head) reassign_resources_sorted(realloc_head, head); free_list(head); @@ -563,17 +556,19 @@ void pci_setup_cardbus(struct pci_bus *bus) } EXPORT_SYMBOL(pci_setup_cardbus); -/* Initialize bridges with base/limit values we have collected. - PCI-to-PCI Bridge Architecture Specification rev. 1.1 (1998) - requires that if there is no I/O ports or memory behind the - bridge, corresponding range must be turned off by writing base - value greater than limit to the bridge's base/limit registers. - - Note: care must be taken when updating I/O base/limit registers - of bridges which support 32-bit I/O. This update requires two - config space writes, so it's quite possible that an I/O window of - the bridge will have some undesirable address (e.g. 0) after the - first write. Ditto 64-bit prefetchable MMIO. */ +/* + * Initialize bridges with base/limit values we have collected. PCI-to-PCI + * Bridge Architecture Specification rev. 1.1 (1998) requires that if there is + * no I/O ports or memory behind the bridge, corresponding range must be turned + * off by writing base value greater than limit to the bridge's base/limit + * registers. + * + * Note: care must be taken when updating I/O base/limit registers of bridges + * which support 32-bit I/O. This update requires two config space writes, so + * it's quite possible that an I/O window of the bridge will have some + * undesirable address (e.g. 0) after the first write. Ditto 64-bit prefetchable + * MMIO. + */ static void pci_setup_bridge_io(struct pci_dev *bridge) { struct resource *res; @@ -636,9 +631,11 @@ static void pci_setup_bridge_mmio_pref(struct pci_dev *bridge) struct pci_bus_region region; u32 l, bu, lu; - /* Clear out the upper 32 bits of PREF limit. - If PCI_PREF_BASE_UPPER32 was non-zero, this temporarily - disables PREF range, which is ok. */ + /* + * Clear out the upper 32 bits of PREF limit. + * If PCI_PREF_BASE_UPPER32 was non-zero, this temporarily + * disables PREF range, which is ok. + */ pci_write_config_dword(bridge, PCI_PREF_LIMIT_UPPER32, 0); /* Set up PREF base/limit. */ @@ -730,9 +727,11 @@ int pci_claim_bridge_resource(struct pci_dev *bridge, int i) return -EINVAL; } -/* Check whether the bridge supports optional I/O and - prefetchable memory ranges. If not, the respective - base/limit registers must be read-only and read as 0. */ +/* + * Check whether the bridge supports optional I/O and prefetchable memory + * ranges. If not, the respective base/limit registers must be read-only and + * read as 0. + */ static void pci_bridge_check_ranges(struct pci_bus *bus) { u16 io; @@ -752,9 +751,11 @@ static void pci_bridge_check_ranges(struct pci_bus *bus) if (io) b_res[0].flags |= IORESOURCE_IO; - /* DECchip 21050 pass 2 errata: the bridge may miss an address - disconnect boundary by one PCI data phase. - Workaround: do not use prefetching on this device. */ + /* + * DECchip 21050 pass 2 errata: the bridge may miss an address + * disconnect boundary by one PCI data phase. Workaround: do not use + * prefetching on this device. + */ if (bridge->vendor == PCI_VENDOR_ID_DEC && bridge->device == 0x0001) return; @@ -789,10 +790,11 @@ static void pci_bridge_check_ranges(struct pci_bus *bus) } } -/* 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, - have non-NULL parent resource). */ +/* + * 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, have non-NULL parent resource). + */ static struct resource *find_free_bus_resource(struct pci_bus *bus, unsigned long type_mask, unsigned long type) { @@ -820,8 +822,10 @@ static resource_size_t calculate_iosize(resource_size_t size, size = min_size; if (old_size == 1) old_size = 0; - /* To be fixed in 2.5: we should have sort of HAVE_ISA - flag in the struct pci_bus. */ + /* + * To be fixed in 2.5: we should have sort of HAVE_ISA flag in the + * struct pci_bus. + */ #if defined(CONFIG_ISA) || defined(CONFIG_EISA) size = (size & 0xff) + ((size & ~0xffUL) << 2); #endif @@ -870,8 +874,8 @@ static resource_size_t window_alignment(struct pci_bus *bus, align = PCI_P2P_DEFAULT_MEM_ALIGN; else if (type & IORESOURCE_IO) { /* - * Per spec, I/O windows are 4K-aligned, but some - * bridges have an extension to support 1K alignment. + * Per spec, I/O windows are 4K-aligned, but some bridges have + * an extension to support 1K alignment. */ if (bus->self->io_window_1k) align = PCI_P2P_DEFAULT_IO_ALIGN_1K; @@ -891,10 +895,9 @@ static resource_size_t window_alignment(struct pci_bus *bus, * @add_size : additional optional io window * @realloc_head : track the additional io window on this list * - * Sizing the IO windows of the PCI-PCI bridge is trivial, - * since these windows have 1K or 4K granularity and the IO ranges - * of non-bridge PCI devices are limited to 256 bytes. - * We must be careful with the ISA aliasing though. + * Sizing the IO windows of the PCI-PCI bridge is trivial, since these windows + * have 1K or 4K granularity and the IO ranges of non-bridge PCI devices are + * limited to 256 bytes. We must be careful with the ISA aliasing though. */ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size, resource_size_t add_size, struct list_head *realloc_head) @@ -995,12 +998,12 @@ static inline resource_size_t calculate_mem_align(resource_size_t *aligns, * @add_size : additional optional memory window * @realloc_head : track the additional memory window on this list * - * Calculate the size of the bus and minimal alignment which - * guarantees that all child resources fit in this size. + * Calculate the size of the bus and minimal alignment which guarantees that all + * child resources fit in this size. * * Returns -ENOSPC if there's no available bus resource of the desired type. - * Otherwise, sets the bus resource start/end to indicate the required - * size, adds things to realloc_head (if supplied), and returns 0. + * Otherwise, sets the bus resource start/end to indicate the required size, + * adds things to realloc_head (if supplied), and returns 0. */ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, unsigned long type, unsigned long type2, @@ -1010,7 +1013,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, { struct pci_dev *dev; resource_size_t min_align, align, size, size0, size1; - resource_size_t aligns[18]; /* Alignments from 1Mb to 128Gb */ + resource_size_t aligns[18]; /* Alignments from 1Mb to 128Gb */ int order, max_order; struct resource *b_res = find_free_bus_resource(bus, mask | IORESOURCE_PREFETCH, type); @@ -1050,10 +1053,9 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, } #endif /* - * aligns[0] is for 1MB (since bridge memory - * windows are always at least 1MB aligned), so - * keep "order" from being negative for smaller - * resources. + * aligns[0] is for 1MB (since bridge memory windows are + * always at least 1MB aligned), so keep "order" from + * being negative for smaller resources. */ align = pci_resource_alignment(dev, r); order = __ffs(align) - 20; @@ -1066,8 +1068,10 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, continue; } size += max(r_size, align); - /* Exclude ranges with size > align from - calculation of the alignment. */ + /* + * Exclude ranges with size > align from calculation of + * the alignment. + */ if (r_size <= align) aligns[order] += align; if (order > max_order) @@ -1128,8 +1132,8 @@ static void pci_bus_size_cardbus(struct pci_bus *bus, if (b_res[0].parent) goto handle_b_res_1; /* - * Reserve some resources for CardBus. We reserve - * a fixed amount of bus space for CardBus bridges. + * Reserve some resources for CardBus. We reserve a fixed amount of bus + * space for CardBus bridges. */ b_res[0].start = pci_cardbus_io_size; b_res[0].end = b_res[0].start + pci_cardbus_io_size - 1; @@ -1161,10 +1165,7 @@ static void pci_bus_size_cardbus(struct pci_bus *bus, pci_read_config_word(bridge, PCI_CB_BRIDGE_CONTROL, &ctrl); } - /* - * Check whether prefetchable memory is supported - * by this bridge. - */ + /* Check whether prefetchable memory is supported by this bridge. */ pci_read_config_word(bridge, PCI_CB_BRIDGE_CONTROL, &ctrl); if (!(ctrl & PCI_CB_BRIDGE_CTL_PREFETCH_MEM0)) { ctrl |= PCI_CB_BRIDGE_CTL_PREFETCH_MEM0; @@ -1175,9 +1176,8 @@ static void pci_bus_size_cardbus(struct pci_bus *bus, if (b_res[2].parent) goto handle_b_res_3; /* - * If we have prefetchable memory support, allocate - * two regions. Otherwise, allocate one region of - * twice the size. + * If we have prefetchable memory support, allocate two regions. + * Otherwise, allocate one region of twice the size. */ if (ctrl & PCI_CB_BRIDGE_CTL_PREFETCH_MEM0) { b_res[2].start = pci_cardbus_mem_size; @@ -1256,9 +1256,8 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head) additional_io_size, realloc_head); /* - * If there's a 64-bit prefetchable MMIO window, compute - * the size required to put all 64-bit prefetchable - * resources in it. + * If there's a 64-bit prefetchable MMIO window, compute the + * size required to put all 64-bit prefetchable resources in it. */ b_res = &bus->self->resource[PCI_BRIDGE_RESOURCES]; mask = IORESOURCE_MEM; @@ -1271,9 +1270,9 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head) additional_mem_size, realloc_head); /* - * If successful, all non-prefetchable resources - * and any 32-bit prefetchable resources will go in - * the non-prefetchable window. + * If successful, all non-prefetchable resources and any + * 32-bit prefetchable resources will go in the + * non-prefetchable window. */ if (ret == 0) { mask = prefmask; @@ -1308,18 +1307,17 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head) /* * Compute the size required to put everything else in the - * non-prefetchable window. This includes: + * non-prefetchable window. This includes: * * - all non-prefetchable resources * - 32-bit prefetchable resources if there's a 64-bit * prefetchable window or no prefetchable window at all - * - 64-bit prefetchable resources if there's no - * prefetchable window at all + * - 64-bit prefetchable resources if there's no prefetchable + * window at all * - * Note that the strategy in __pci_assign_resource() must - * match that used here. Specifically, we cannot put a - * 32-bit prefetchable resource in a 64-bit prefetchable - * window. + * Note that the strategy in __pci_assign_resource() must match + * that used here. Specifically, we cannot put a 32-bit + * prefetchable resource in a 64-bit prefetchable window. */ pbus_size_mem(bus, mask, IORESOURCE_MEM, type2, type3, realloc_head ? 0 : additional_mem_size, @@ -1352,8 +1350,8 @@ static void assign_fixed_resource_on_bus(struct pci_bus *b, struct resource *r) } /* - * Try to assign any resources marked as IORESOURCE_PCI_FIXED, as they - * are skipped by pbus_assign_resources_sorted(). + * Try to assign any resources marked as IORESOURCE_PCI_FIXED, as they are + * skipped by pbus_assign_resources_sorted(). */ static void pdev_assign_fixed_resources(struct pci_dev *dev) { @@ -1464,10 +1462,9 @@ static void pci_bus_allocate_resources(struct pci_bus *b) struct pci_bus *child; /* - * Carry out a depth-first search on the PCI bus - * tree to allocate bridge apertures. Read the - * programmed bridge bases and recursively claim - * the respective bridge resources. + * Carry out a depth-first search on the PCI bus tree to allocate bridge + * apertures. Read the programmed bridge bases and recursively claim the + * respective bridge resources. */ if (b->self) { pci_read_bridge_bases(b); @@ -1532,16 +1529,15 @@ static void pci_bridge_release_resources(struct pci_bus *bus, b_res = &dev->resource[PCI_BRIDGE_RESOURCES]; /* - * 1. if there is io port assign fail, will release bridge - * io port. - * 2. if there is non pref mmio assign fail, release bridge - * nonpref mmio. - * 3. if there is 64bit pref mmio assign fail, and bridge pref - * is 64bit, release bridge pref mmio. - * 4. if there is pref mmio assign fail, and bridge pref is - * 32bit mmio, release bridge pref mmio - * 5. if there is pref mmio assign fail, and bridge pref is not - * assigned, release bridge nonpref mmio. + * 1. if there is io port assign fail, will release bridge io port. + * 2. if there is non pref mmio assign fail, release bridge nonpref + * mmio. + * 3. if there is 64bit pref mmio assign fail, and bridge pref is 64bit, + * release bridge pref mmio. + * 4. if there is pref mmio assign fail, and bridge pref is 32bit mmio, + * release bridge pref mmio + * 5. if there is pref mmio assign fail, and bridge pref is not + * assigned, release bridge nonpref mmio. */ if (type & IORESOURCE_IO) idx = 0; @@ -1561,10 +1557,7 @@ static void pci_bridge_release_resources(struct pci_bus *bus, if (!r->parent) return; - /* - * if there are children under that, we should release them - * all - */ + /* if there are children under that, we should release them all */ release_child_resources(r); if (!release_resource(r)) { type = old_flags = r->flags & PCI_RES_TYPE_MASK; @@ -1589,8 +1582,8 @@ enum release_type { whole_subtree, }; /* - * try to release pci bridge resources that is from leaf bridge, - * so we can allocate big new one later + * try to release pci bridge resources that is from leaf bridge, so we can + * allocate big new one later */ static void pci_bus_release_bridge_resources(struct pci_bus *bus, unsigned long type, @@ -1751,8 +1744,8 @@ static enum enable_type pci_realloc_detect(struct pci_bus *bus, */ void pci_assign_unassigned_root_bus_resources(struct pci_bus *bus) { - LIST_HEAD(realloc_head); /* list of resources that - want additional resources */ + 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; @@ -1774,13 +1767,14 @@ void pci_assign_unassigned_root_bus_resources(struct pci_bus *bus) again: /* - * last try will use add_list, otherwise will try good to have as - * must have, so can realloc parent bridge resource + * 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. */ + /* + * 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. */ @@ -2040,8 +2034,9 @@ pci_bridge_distribute_available_resources(struct pci_dev *bridge, void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge) { struct pci_bus *parent = bridge->subordinate; - LIST_HEAD(add_list); /* list of resources that - want additional resources */ + /* list of resources that want additional resources */ + LIST_HEAD(add_list); + int tried_times = 0; LIST_HEAD(fail_head); struct pci_dev_resource *fail_res; @@ -2051,9 +2046,9 @@ void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge) __pci_bus_size_bridges(parent, &add_list); /* - * Distribute remaining resources (if any) equally between - * hotplug bridges below. This makes it possible to extend the - * hierarchy later without running out of resources. + * Distribute remaining resources (if any) equally between hotplug + * bridges below. This makes it possible to extend the hierarchy + * later without running out of resources. */ pci_bridge_distribute_available_resources(bridge, &add_list); @@ -2205,8 +2200,8 @@ int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long type) void pci_assign_unassigned_bus_resources(struct pci_bus *bus) { struct pci_dev *dev; - LIST_HEAD(add_list); /* list of resources that - want additional resources */ + /* list of resources that want additional resources */ + LIST_HEAD(add_list); down_read(&pci_bus_sem); for_each_pci_bridge(dev, bus) From patchwork Mon Apr 15 17:09:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Johnson X-Patchwork-Id: 10901267 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DD0A51390 for ; Mon, 15 Apr 2019 17:09:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE36D284E4 for ; Mon, 15 Apr 2019 17:09:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B29072852A; Mon, 15 Apr 2019 17:09:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 43346284E4 for ; Mon, 15 Apr 2019 17:09:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727841AbfDORJs convert rfc822-to-8bit (ORCPT ); Mon, 15 Apr 2019 13:09:48 -0400 Received: from mail-oln040092255044.outbound.protection.outlook.com ([40.92.255.44]:20160 "EHLO APC01-HK2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727186AbfDORJr (ORCPT ); Mon, 15 Apr 2019 13:09:47 -0400 Received: from HK2APC01FT059.eop-APC01.prod.protection.outlook.com (10.152.248.54) by HK2APC01HT128.eop-APC01.prod.protection.outlook.com (10.152.248.253) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1771.16; Mon, 15 Apr 2019 17:09:43 +0000 Received: from PS2P216MB0642.KORP216.PROD.OUTLOOK.COM (10.152.248.52) by HK2APC01FT059.mail.protection.outlook.com (10.152.249.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1771.16 via Frontend Transport; Mon, 15 Apr 2019 17:09:43 +0000 Received: from PS2P216MB0642.KORP216.PROD.OUTLOOK.COM ([fe80::50ee:2afa:f5b:9647]) by PS2P216MB0642.KORP216.PROD.OUTLOOK.COM ([fe80::50ee:2afa:f5b:9647%6]) with mapi id 15.20.1792.018; Mon, 15 Apr 2019 17:09:43 +0000 From: Nicholas Johnson To: "linux-kernel@vger.kernel.org" CC: "linux-pci@vger.kernel.org" , "bhelgaas@google.com" , "mika.westerberg@linux.intel.com" , "corbet@lwn.net" , Nicholas Johnson Subject: [PATCH v3 3/5] PCI: Fix serious bug when sizing bridges with additional size Thread-Topic: [PATCH v3 3/5] PCI: Fix serious bug when sizing bridges with additional size Thread-Index: AQHU864E3j6/X6V0I02rUqV0pT1uVQ== Date: Mon, 15 Apr 2019 17:09:43 +0000 Message-ID: References: <20190416010756.31313-1-nicholas.johnson-opensource@outlook.com.au> In-Reply-To: <20190416010756.31313-1-nicholas.johnson-opensource@outlook.com.au> Accept-Language: en-AU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SG2PR01CA0087.apcprd01.prod.exchangelabs.com (2603:1096:3:15::13) To PS2P216MB0642.KORP216.PROD.OUTLOOK.COM (2603:1096:300:1c::16) x-incomingtopheadermarker: OriginalChecksum:32BC4E01E12A65BA0C8BBA66BB9B68C76039A0E5D8ABA35F8B997F1AAE072661;UpperCasedChecksum:2B51B0981655019053F7BF6B263E04904DF05A21351C744AD0BC449702E6F68E;SizeAsReceived:7914;Count:50 x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.19.1 x-tmn: [jYtfQpo7npJGBpPrVC+jJaa0tnRwWz9vU3Bjjd5UNpA/cNpBhr6iK0Rd22y6UPow0ZVwXQXUUT0=] x-microsoft-original-message-id: <20190416010756.31313-5-nicholas.johnson-opensource@outlook.com.au> x-ms-publictraffictype: Email x-incomingheadercount: 50 x-eopattributedmessage: 0 x-ms-exchange-slblob-mailprops: zswcL9HXbeXjLSNNcQpvuD9Rx3UxByW7VdAOpjuRFXPDNWJrwm9JHt/igX1n5n2+0ujgTnH+Mu1wHkr1P+PXy6emq9MKrKvTAPCo3aOZBEh6MMzTJ/00GpymEgJcCW830CClkVUyIrJc8/KVvaNxkQnlDqhIsu6+DQh96YFX+TV5fUIQePeqnZKcFkD4ZrORZ0nXhWiRpqF8m104UCLpCxwatW1nMnOs8OhVAV3JFBO9X7eKbxl39e53M8G/cInqbFht2b23PaBjp1Snezd87UjX2b85VaRixnDpqRVEP+4w9RgsRhWFNTaFX6ujoiDHk2YSz1KeS/ZQyXyyyXyqglY7op5WGUG5mhCAr9WgsIg+cGp1y3JpvDYTzxlzL6JbcMqZ6CrdLFbNb9oQmIx/WTBhcRrGDJVy53wJ+rPH1viah1AgssyKAmEdtwOvfl4tux47nQLe62e69grPfJ60l5whSJ1HnJFJ/LzJBFM0tsgLe3WcH/ko2FpoDViNElecxFuh8JmqmEXZ2EesmNLW9GwKnOdEZed6/cRbUdIy4Rx8u/q5Gxrx5HAt9t3CAa8cavU8RaegUnGZiX9m7qD3+E3mMUM4bZrEBLbXDWOlRN5LDk11UhMPWCl3Aj5Wao/al+wGSERmm3QFWu0lQQ86s/odGIGuQ2aVcp1nn2Busas8qYSuJPAPfaCDtx+87D85vdZCepYqBWcLq7eIuMJnWZgi8hLRGKfAajqK6rpJwErTy2WWpWZj4jVYOYKPYQUj x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(20181119110)(201702061078)(5061506573)(5061507331)(1603103135)(2017031320274)(201702181274)(2017031323274)(2017031324274)(2017031322404)(1601125500)(1603101475)(1701031045);SRVR:HK2APC01HT128; x-ms-traffictypediagnostic: HK2APC01HT128: x-microsoft-antispam-message-info: tbMpUnSA6G8N1MV+hqt+bQ6I2CQY0+gDbtATXtgtnumP+BOiF+gzDUzkM8wKyPJYoN6XW1h/AjoXd0/vlTEtaOVDpsDTORxeaJhvAzn9ruj0SoUCppoR3uU6Ll4r/FMrF+yCjJTHhVnBTRS80hAj+YWn8kBpJKZO0/t1NfsqVtkKNe84COLHFzpgGQma2n/a MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: de425663-1755-4725-8323-08d6c1c5272e X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Apr 2019 17:09:43.3234 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: HK2APC01HT128 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Change find_free_bus_resource function to not skip assigned resources with non-null parent. Add checks in pbus_size_io and pbus_size_mem to return success if resource returned from find_free_bus_resource is already allocated. This avoids pbus_size_io and pbus_size_mem returning error code to __pci_bus_size_bridges when a resource has been successfully assigned in a previous pass. This fixes the existing behaviour where space for a resource could be reserved multiple times in different parent bridge windows. This also greatly reduces the number of failed BAR messages in dmesg when Linux assigns resources. Signed-off-by: Nicholas Johnson --- drivers/pci/setup-bus.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 0ce641282..efe899b02 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -791,11 +791,16 @@ static void pci_bridge_check_ranges(struct pci_bus *bus) } /* - * 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, have non-NULL parent resource). + * Helper function for sizing routines: find first bus resource of a + * given type. Note: we do not skip the bus resources which have already + * been assigned (r->parent != NULL). This is because a resource that is + * already assigned (nothing more to be done) will be indistinguishable + * from one that failed due to lack of space if we skip assigned + * resources. If the caller function cannot tell the difference then it + * might try to place the resources in a different window, doubling up on + * resources or causing unforeseeable issues. */ -static struct resource *find_free_bus_resource(struct pci_bus *bus, +static struct resource *find_bus_resource_of_type(struct pci_bus *bus, unsigned long type_mask, unsigned long type) { int i; @@ -804,7 +809,7 @@ static struct resource *find_free_bus_resource(struct pci_bus *bus, pci_bus_for_each_resource(bus, r, i) { if (r == &ioport_resource || r == &iomem_resource) continue; - if (r && (r->flags & type_mask) == type && !r->parent) + if (r && (r->flags & type_mask) == type) return r; } return NULL; @@ -903,14 +908,16 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size, resource_size_t add_size, struct list_head *realloc_head) { struct pci_dev *dev; - struct resource *b_res = find_free_bus_resource(bus, IORESOURCE_IO, - IORESOURCE_IO); + struct resource *b_res = find_bus_resource_of_type(bus, IORESOURCE_IO, + IORESOURCE_IO); resource_size_t size = 0, size0 = 0, size1 = 0; resource_size_t children_add_size = 0; resource_size_t min_align, align; if (!b_res) return; + if (b_res->parent) + return; min_align = window_alignment(bus, IORESOURCE_IO); list_for_each_entry(dev, &bus->devices, bus_list) { @@ -1015,7 +1022,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, resource_size_t min_align, align, size, size0, size1; resource_size_t aligns[18]; /* Alignments from 1Mb to 128Gb */ int order, max_order; - struct resource *b_res = find_free_bus_resource(bus, + struct resource *b_res = find_bus_resource_of_type(bus, mask | IORESOURCE_PREFETCH, type); resource_size_t children_add_size = 0; resource_size_t children_add_align = 0; @@ -1023,6 +1030,8 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, if (!b_res) return -ENOSPC; + if (b_res->parent) + return 0; memset(aligns, 0, sizeof(aligns)); max_order = 0; From patchwork Mon Apr 15 17:09:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Johnson X-Patchwork-Id: 10901269 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4AB7114DB for ; Mon, 15 Apr 2019 17:10:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2BF272850F for ; Mon, 15 Apr 2019 17:10:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 203E028644; Mon, 15 Apr 2019 17:10:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 756652850F for ; Mon, 15 Apr 2019 17:10:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727911AbfDORKA convert rfc822-to-8bit (ORCPT ); Mon, 15 Apr 2019 13:10:00 -0400 Received: from mail-oln040092253031.outbound.protection.outlook.com ([40.92.253.31]:6106 "EHLO APC01-SG2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727908AbfDORKA (ORCPT ); Mon, 15 Apr 2019 13:10:00 -0400 Received: from HK2APC01FT059.eop-APC01.prod.protection.outlook.com (10.152.248.60) by HK2APC01HT172.eop-APC01.prod.protection.outlook.com (10.152.249.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1771.16; Mon, 15 Apr 2019 17:09:54 +0000 Received: from PS2P216MB0642.KORP216.PROD.OUTLOOK.COM (10.152.248.52) by HK2APC01FT059.mail.protection.outlook.com (10.152.249.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1771.16 via Frontend Transport; Mon, 15 Apr 2019 17:09:54 +0000 Received: from PS2P216MB0642.KORP216.PROD.OUTLOOK.COM ([fe80::50ee:2afa:f5b:9647]) by PS2P216MB0642.KORP216.PROD.OUTLOOK.COM ([fe80::50ee:2afa:f5b:9647%6]) with mapi id 15.20.1792.018; Mon, 15 Apr 2019 17:09:54 +0000 From: Nicholas Johnson To: "linux-kernel@vger.kernel.org" CC: "linux-pci@vger.kernel.org" , "bhelgaas@google.com" , "mika.westerberg@linux.intel.com" , "corbet@lwn.net" , Nicholas Johnson Subject: [PATCH v3 4/5] PCI: modify kernel parameters to differentiate between MMIO and MMIO_PREF sizes Thread-Topic: [PATCH v3 4/5] PCI: modify kernel parameters to differentiate between MMIO and MMIO_PREF sizes Thread-Index: AQHU864LL3OGeK6GSU6lojrdSk0U0A== Date: Mon, 15 Apr 2019 17:09:54 +0000 Message-ID: References: <20190416010756.31313-1-nicholas.johnson-opensource@outlook.com.au> In-Reply-To: <20190416010756.31313-1-nicholas.johnson-opensource@outlook.com.au> Accept-Language: en-AU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SG2PR01CA0085.apcprd01.prod.exchangelabs.com (2603:1096:3:15::11) To PS2P216MB0642.KORP216.PROD.OUTLOOK.COM (2603:1096:300:1c::16) x-incomingtopheadermarker: OriginalChecksum:E0663390A8087AA0D5AC55D127C3F718FC01BC7971ECE70E4C3F576791501A47;UpperCasedChecksum:9D39C671F839B369109ABD8EA32AAFDC16A0D8AC7EFBFB37448919222B990774;SizeAsReceived:7964;Count:50 x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.19.1 x-tmn: [XBrXi9mH+s6yqVGTW7Qa2t7XKQKxoqjhubl1zMEth4PdugitjMthwNTN6b/YUuqtU+KLomnk1ck=] x-microsoft-original-message-id: <20190416010756.31313-6-nicholas.johnson-opensource@outlook.com.au> x-ms-publictraffictype: Email x-incomingheadercount: 50 x-eopattributedmessage: 0 x-ms-exchange-slblob-mailprops: LtmIgUwM0qQW+fxQnmb0JSczgOqcUbt16rkAtHivjjgvmywNfw791VYVUIGI8HXTZbci1sNqi3rS3henGUlrImrwtyfxiVZCCt4tr3mB6G4xCM02jOwDnR2L4FJxx1+rL0axGk8VG2yJG4nl9J+NdBvPWmMUDE3ikV0V+kNb9kMaePF/O9J6PlF12VF6cfuL7C0bLcduttVa4cUAdUm0zeSNGKmyDpoQVjlAENZl8BPL0lrKm1n40dK9Vzjs/qDR4WszK55YMEYtChDAHgxrSU/hQkea/y8qlKnEu3FrDI+TRCbonfNqsvnYKCr0kIYiOuBdEhs06StAa11dkFrkGIOOmXqIdqHS/h+Dncp3WSXfdIrcggQnoNiVMbbfM5uWec4QxPR0tpUbNk5qDjLPEii+psSvUYAdNI4U9sW7Ejaq4YHKAJRWirbdvG1yif0nfqnMbf5+vla+9sRQ5Ug2D4BLjen4lx1+HbnNjbK9dZs/9KbS/DsLbyTT2nePqoVo6wDuXK0ueYS2GPByuuL6HUHJVycXDnksmRkfIxp5oeZTtWrbqfX/pcqParukRTSstZ+x2tLE3QjlE5+koTbi2nkwHm7Om9TZTB1Px9Hqkih6JV+fgAEOj/Wy5dX9taBP4RMcnEHATWK2i2u8/6FNkQuQq7iRn+dlEFczCA1MYh4gE5wtjE523IWm2La56OqABCljsQ9UL4bk7dMxtEvvPZSfHf7TseX93i/QpVTbEhjLAeOepp7cIMj0AU8DTJ2KELtavUImAxhOqaLuQwYFZA== x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(20181119110)(201702061078)(5061506573)(5061507331)(1603103135)(2017031320274)(201702181274)(2017031323274)(2017031324274)(2017031322404)(1601125500)(1603101475)(1701031045);SRVR:HK2APC01HT172; x-ms-traffictypediagnostic: HK2APC01HT172: x-microsoft-antispam-message-info: 3Iw56PzN4tPN67i2NHRB9RRvEFnLIAJVJOcSk4gT2zLm2xdlR5ljWFTHRPbd5xxZ7oWDGEzLRwbsuzMK0Fv/9QiT8EYzg1Wtk4g0Uu25QkPTW6Apyww5EfFH/6j56pSzeQ/lJEObT0BdojwxeSmM0N948BXyHP2qZbVZ22XdEoYXUDh8OHO1C5PdpqxKM+RU MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: f448f143-1384-4d3b-fa0b-08d6c1c52de1 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Apr 2019 17:09:54.6810 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: HK2APC01HT172 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add kernel parameter pci=hpmemprefsize=nn[KMG] to control MMIO_PREF size. Change behaviour of pci=hpmemsize=nn[KMG] to only control MMIO size, rather than controlling both MMIO and MMIO_PREF sizes. Update kernel-parameters documentation to reflect the above changes. Signed-off-by: Nicholas Johnson --- .../admin-guide/kernel-parameters.txt | 3 +++ drivers/pci/pci.c | 5 +++++ drivers/pci/setup-bus.c | 22 ++++++++++--------- include/linux/pci.h | 1 + 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 858b6c0b9..908d01027 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -3332,6 +3332,9 @@ hpmemsize=nn[KMG] The fixed amount of bus space which is reserved for hotplug bridge's memory window. Default size is 2 megabytes. + hpmemprefsize=nn[KMG] The fixed amount of bus space which is + reserved for hotplug bridge's MMIO_PREF window. + Default size is 2 megabytes. hpbussize=nn The minimum amount of additional bus numbers reserved for buses below a hotplug bridge. Default is 1. diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index c25acace7..c36c92118 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -86,9 +86,11 @@ unsigned long pci_cardbus_mem_size = DEFAULT_CARDBUS_MEM_SIZE; #define DEFAULT_HOTPLUG_IO_SIZE (256) #define DEFAULT_HOTPLUG_MEM_SIZE (2*1024*1024) +#define DEFAULT_HOTPLUG_MEM_PREF_SIZE (2*1024*1024) /* pci=hpmemsize=nnM,hpiosize=nn can override this */ unsigned long pci_hotplug_io_size = DEFAULT_HOTPLUG_IO_SIZE; unsigned long pci_hotplug_mem_size = DEFAULT_HOTPLUG_MEM_SIZE; +unsigned long pci_hotplug_mem_pref_size = DEFAULT_HOTPLUG_MEM_PREF_SIZE; #define DEFAULT_HOTPLUG_BUS_SIZE 1 unsigned long pci_hotplug_bus_size = DEFAULT_HOTPLUG_BUS_SIZE; @@ -6179,6 +6181,9 @@ static int __init pci_setup(char *str) pci_hotplug_io_size = memparse(str + 9, &str); } else if (!strncmp(str, "hpmemsize=", 10)) { pci_hotplug_mem_size = memparse(str + 10, &str); + } else if (!strncmp(str, "hpmemprefsize=", 14)) { + pci_hotplug_mem_pref_size = + memparse(str + 14, &str); } else if (!strncmp(str, "hpbussize=", 10)) { pci_hotplug_bus_size = simple_strtoul(str + 10, &str, 0); diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index efe899b02..3806c9ff0 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1223,7 +1223,8 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head) { struct pci_dev *dev; unsigned long mask, prefmask, type2 = 0, type3 = 0; - resource_size_t additional_mem_size = 0, additional_io_size = 0; + resource_size_t additional_io_size = 0, additional_mem_size = 0, + additional_mem_pref_size = 0; struct resource *b_res; int ret; @@ -1258,6 +1259,7 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head) if (bus->self->is_hotplug_bridge) { additional_io_size = pci_hotplug_io_size; additional_mem_size = pci_hotplug_mem_size; + additional_mem_pref_size = pci_hotplug_mem_pref_size; } /* Fall through */ default: @@ -1274,9 +1276,9 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head) if (b_res[2].flags & IORESOURCE_MEM_64) { prefmask |= IORESOURCE_MEM_64; ret = pbus_size_mem(bus, prefmask, prefmask, - prefmask, prefmask, - realloc_head ? 0 : additional_mem_size, - additional_mem_size, realloc_head); + prefmask, prefmask, + realloc_head ? 0 : additional_mem_pref_size, + additional_mem_pref_size, realloc_head); /* * If successful, all non-prefetchable resources and any @@ -1298,9 +1300,9 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head) if (!type2) { prefmask &= ~IORESOURCE_MEM_64; ret = pbus_size_mem(bus, prefmask, prefmask, - prefmask, prefmask, - realloc_head ? 0 : additional_mem_size, - additional_mem_size, realloc_head); + prefmask, prefmask, + realloc_head ? 0 : additional_mem_pref_size, + additional_mem_pref_size, realloc_head); /* * If successful, only non-prefetchable resources @@ -1309,7 +1311,7 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head) if (ret == 0) mask = prefmask; else - additional_mem_size += additional_mem_size; + additional_mem_size += additional_mem_pref_size; type2 = type3 = IORESOURCE_MEM; } @@ -1329,8 +1331,8 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head) * prefetchable resource in a 64-bit prefetchable window. */ pbus_size_mem(bus, mask, IORESOURCE_MEM, type2, type3, - realloc_head ? 0 : additional_mem_size, - additional_mem_size, realloc_head); + realloc_head ? 0 : additional_mem_size, + additional_mem_size, realloc_head); break; } } diff --git a/include/linux/pci.h b/include/linux/pci.h index 65f1d8c2f..a179856bf 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1960,6 +1960,7 @@ extern u8 pci_cache_line_size; extern unsigned long pci_hotplug_io_size; extern unsigned long pci_hotplug_mem_size; +extern unsigned long pci_hotplug_mem_pref_size; extern unsigned long pci_hotplug_bus_size; /* Architecture-specific versions may override these (weak) */ From patchwork Mon Apr 15 17:10:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Johnson X-Patchwork-Id: 10901271 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B72F214DB for ; Mon, 15 Apr 2019 17:10:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 962881FFFE for ; Mon, 15 Apr 2019 17:10:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 88A2C2852A; Mon, 15 Apr 2019 17:10:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D51301FFFE for ; Mon, 15 Apr 2019 17:10:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726313AbfDORKQ convert rfc822-to-8bit (ORCPT ); Mon, 15 Apr 2019 13:10:16 -0400 Received: from mail-oln040092253057.outbound.protection.outlook.com ([40.92.253.57]:6149 "EHLO APC01-SG2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727823AbfDORKP (ORCPT ); Mon, 15 Apr 2019 13:10:15 -0400 Received: from HK2APC01FT059.eop-APC01.prod.protection.outlook.com (10.152.248.57) by HK2APC01HT211.eop-APC01.prod.protection.outlook.com (10.152.248.239) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1771.16; Mon, 15 Apr 2019 17:10:06 +0000 Received: from PS2P216MB0642.KORP216.PROD.OUTLOOK.COM (10.152.248.52) by HK2APC01FT059.mail.protection.outlook.com (10.152.249.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.1771.16 via Frontend Transport; Mon, 15 Apr 2019 17:10:06 +0000 Received: from PS2P216MB0642.KORP216.PROD.OUTLOOK.COM ([fe80::50ee:2afa:f5b:9647]) by PS2P216MB0642.KORP216.PROD.OUTLOOK.COM ([fe80::50ee:2afa:f5b:9647%6]) with mapi id 15.20.1792.018; Mon, 15 Apr 2019 17:10:06 +0000 From: Nicholas Johnson To: "linux-kernel@vger.kernel.org" CC: "linux-pci@vger.kernel.org" , "bhelgaas@google.com" , "mika.westerberg@linux.intel.com" , "corbet@lwn.net" , Nicholas Johnson Subject: [PATCH v3 5/5] PCI: Rename pci=hpiosize,hpmemsize,hpmemprefsize to be more readable Thread-Topic: [PATCH v3 5/5] PCI: Rename pci=hpiosize,hpmemsize,hpmemprefsize to be more readable Thread-Index: AQHU864SgCv+jL/MfUmgojl7SYfKWg== Date: Mon, 15 Apr 2019 17:10:06 +0000 Message-ID: References: <20190416010756.31313-1-nicholas.johnson-opensource@outlook.com.au> In-Reply-To: <20190416010756.31313-1-nicholas.johnson-opensource@outlook.com.au> Accept-Language: en-AU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: SG2PR06CA0204.apcprd06.prod.outlook.com (2603:1096:4:1::36) To PS2P216MB0642.KORP216.PROD.OUTLOOK.COM (2603:1096:300:1c::16) x-incomingtopheadermarker: OriginalChecksum:41B27CDB15EDF625192568104422A995B892526F72DBF5D0E82EA6725CB2939F;UpperCasedChecksum:06A2C20392A602F1FBE9C3EA872953F4584430D848FE7D0E1AAA5FF0B16F6753;SizeAsReceived:7903;Count:50 x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.19.1 x-tmn: [ouYyZVYQGcfIEtRsFRil38YYS1TNnV7G+T9w6Iw4OrMQKtLKjmfL8ZZriuKdzrcPIIpi88GnwFY=] x-microsoft-original-message-id: <20190416010756.31313-7-nicholas.johnson-opensource@outlook.com.au> x-ms-publictraffictype: Email x-incomingheadercount: 50 x-eopattributedmessage: 0 x-ms-exchange-slblob-mailprops: zswcL9HXbeXjLSNNcQpvuD9Rx3UxByW78hxIPClDJZbFKk5FGFmJ1JbptZVMjiTvI5SQgO0HqFhd4f20X/RXQhfJqPrhpwDpDDwbd33Z4TNLBqsL7qRiP3+2EU/fQChANEq92wjTEvdmk0AJhJpSqi9Sl1pHr2fyQNiFbGPWROrvgabA14BPcvNvbMBsFM6nK0e0Rf3pK+wVAd7xU2byfKj/IOX9EQ9IsxjAQUDQT/ljxRfafcrtGmWYPAeC7xGeY9ksoN41+F5XCkm2I/p3knJ8wc4JF8hhhkcxRH4KiAaAdt6SRoLtSDG2S5f9JDoTUw+KHn8OV445DhBm7x3cYy9PWL8VaUu0Oh3KgH7Sc3U4ukWjjx8pX5L5SXUa0Akl3T1Q2sl2bbDd+mUy7v7X34K6GsltP6Z8fv1qHInAi7Ae6enZJPulVJ/lhMPKLIih4UANYgLfMxisVSuJYkjfFJJIwGXuVsno8Ed6NPcdat+yC9TXu1CRzKuwyVQ32gXC2jC0EtS3VTWvB5S9N5A75zcCLqdTh8aJ2oQru/qxcjpADnSFXPft2HBnp4GfuD5GCDUSE9OcvlCdH0QwLwdlLtAJbCSQosQoHl/LzFhiiO1f8nv0QD7rS8esLi9vysrNaj0rzGlnDc+d5R/i5X1YfKzp3IRI0xbicj9BgSHb3oK5WEU1TuArzDKRXY0byOEBzDRq9G9+ufuHZqe7CrZ+EA3/gbkvyjizsaepvttIGtmuVqwwhiUKLJVhop6cBX87 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(20181119110)(201702061078)(5061506573)(5061507331)(1603103135)(2017031320274)(201702181274)(2017031323274)(2017031324274)(2017031322404)(1601125500)(1603101475)(1701031045);SRVR:HK2APC01HT211; x-ms-traffictypediagnostic: HK2APC01HT211: x-microsoft-antispam-message-info: eknX8bv0bI4XQOL2Gtpi4YssnjhxLB5vlhNFrfUZZACSW9/vJIeWgXT/2BGAIeER3U2Jho9ll1/j4PrJG0DAyEz8djZ31ZAVF/mD5tQryoBhmQjAYfFeQQ+cD9Ny0kpSlF5vIamk4WLEM2WH3nsEFfd+kr+sRH7c5spkFUE6vWz7OBsf9sEv+V3YLDpRWx3Q MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 13a8d906-eccb-43a4-ed61-08d6c1c534da X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Apr 2019 17:10:06.3528 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: HK2APC01HT211 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Rename pci=hpiosize=nn[KMG] to pci=hp_io_size=nn[KMG] Rename pci=hpmemsize=nn[KMG] to pci=hp_mmio_size=nn[KMG] Rename pci=hpmemprefsize=nn[KMG] to pci=hp_mmio_pref_size=nn[KMG] Update Documentation/admin-guide/kernel-parameters.txt to reflect the above changes. Update variable names in code to reflect the naming changes and become more readable. Signed-off-by: Nicholas Johnson --- .../admin-guide/kernel-parameters.txt | 10 ++++---- drivers/pci/pci.c | 23 ++++++++++--------- drivers/pci/setup-bus.c | 23 ++++++++++--------- include/linux/pci.h | 4 ++-- 4 files changed, 31 insertions(+), 29 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 908d01027..66ffc0e7d 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -3326,15 +3326,15 @@ the default. off: Turn ECRC off on: Turn ECRC on. - hpiosize=nn[KMG] The fixed amount of bus space which is + hp_io_size=nn[KMG] The fixed amount of bus space which is reserved for hotplug bridge's IO window. Default size is 256 bytes. - hpmemsize=nn[KMG] The fixed amount of bus space which is + hp_mmio_size=nn[KMG] The fixed amount of bus space which is reserved for hotplug bridge's memory window. Default size is 2 megabytes. - hpmemprefsize=nn[KMG] The fixed amount of bus space which is - reserved for hotplug bridge's MMIO_PREF window. - Default size is 2 megabytes. + hp_mmio_pref_size=nn[KMG] The fixed amount of bus space + which is reserved for hotplug bridge's MMIO_PREF + window. Default size is 2 megabytes. hpbussize=nn The minimum amount of additional bus numbers reserved for buses below a hotplug bridge. Default is 1. diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index c36c92118..5ecc432a5 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -85,12 +85,12 @@ unsigned long pci_cardbus_io_size = DEFAULT_CARDBUS_IO_SIZE; unsigned long pci_cardbus_mem_size = DEFAULT_CARDBUS_MEM_SIZE; #define DEFAULT_HOTPLUG_IO_SIZE (256) -#define DEFAULT_HOTPLUG_MEM_SIZE (2*1024*1024) -#define DEFAULT_HOTPLUG_MEM_PREF_SIZE (2*1024*1024) +#define DEFAULT_HOTPLUG_MMIO_SIZE (2*1024*1024) +#define DEFAULT_HOTPLUG_MMIO_PREF_SIZE (2*1024*1024) /* pci=hpmemsize=nnM,hpiosize=nn can override this */ unsigned long pci_hotplug_io_size = DEFAULT_HOTPLUG_IO_SIZE; -unsigned long pci_hotplug_mem_size = DEFAULT_HOTPLUG_MEM_SIZE; -unsigned long pci_hotplug_mem_pref_size = DEFAULT_HOTPLUG_MEM_PREF_SIZE; +unsigned long pci_hotplug_mmio_size = DEFAULT_HOTPLUG_MMIO_SIZE; +unsigned long pci_hotplug_mmio_pref_size = DEFAULT_HOTPLUG_MMIO_PREF_SIZE; #define DEFAULT_HOTPLUG_BUS_SIZE 1 unsigned long pci_hotplug_bus_size = DEFAULT_HOTPLUG_BUS_SIZE; @@ -6177,13 +6177,14 @@ static int __init pci_setup(char *str) strlen(str + 19)); } else if (!strncmp(str, "ecrc=", 5)) { pcie_ecrc_get_policy(str + 5); - } else if (!strncmp(str, "hpiosize=", 9)) { - pci_hotplug_io_size = memparse(str + 9, &str); - } else if (!strncmp(str, "hpmemsize=", 10)) { - pci_hotplug_mem_size = memparse(str + 10, &str); - } else if (!strncmp(str, "hpmemprefsize=", 14)) { - pci_hotplug_mem_pref_size = - memparse(str + 14, &str); + } else if (!strncmp(str, "hp_io_size=", 11)) { + pci_hotplug_io_size = memparse(str + 11, &str); + } else if (!strncmp(str, "hp_mmio_size=", 13)) { + pci_hotplug_mmio_size = memparse(str + 13, + &str); + } else if (!strncmp(str, "hp_mmio_pref_size=", 18)) { + pci_hotplug_mmio_pref_size = + memparse(str + 18, &str); } else if (!strncmp(str, "hpbussize=", 10)) { pci_hotplug_bus_size = simple_strtoul(str + 10, &str, 0); diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 3806c9ff0..d2df8908f 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1223,8 +1223,8 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head) { struct pci_dev *dev; unsigned long mask, prefmask, type2 = 0, type3 = 0; - resource_size_t additional_io_size = 0, additional_mem_size = 0, - additional_mem_pref_size = 0; + resource_size_t additional_io_size = 0, additional_mmio_size = 0, + additional_mmio_pref_size = 0; struct resource *b_res; int ret; @@ -1258,8 +1258,8 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head) pci_bridge_check_ranges(bus); if (bus->self->is_hotplug_bridge) { additional_io_size = pci_hotplug_io_size; - additional_mem_size = pci_hotplug_mem_size; - additional_mem_pref_size = pci_hotplug_mem_pref_size; + additional_mmio_size = pci_hotplug_mmio_size; + additional_mmio_pref_size = pci_hotplug_mmio_pref_size; } /* Fall through */ default: @@ -1277,8 +1277,8 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head) prefmask |= IORESOURCE_MEM_64; ret = pbus_size_mem(bus, prefmask, prefmask, prefmask, prefmask, - realloc_head ? 0 : additional_mem_pref_size, - additional_mem_pref_size, realloc_head); + realloc_head ? 0 : additional_mmio_pref_size, + additional_mmio_pref_size, realloc_head); /* * If successful, all non-prefetchable resources and any @@ -1301,8 +1301,8 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head) prefmask &= ~IORESOURCE_MEM_64; ret = pbus_size_mem(bus, prefmask, prefmask, prefmask, prefmask, - realloc_head ? 0 : additional_mem_pref_size, - additional_mem_pref_size, realloc_head); + realloc_head ? 0 : additional_mmio_pref_size, + additional_mmio_pref_size, realloc_head); /* * If successful, only non-prefetchable resources @@ -1311,7 +1311,8 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head) if (ret == 0) mask = prefmask; else - additional_mem_size += additional_mem_pref_size; + additional_mmio_size += + additional_mmio_pref_size; type2 = type3 = IORESOURCE_MEM; } @@ -1331,8 +1332,8 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head) * prefetchable resource in a 64-bit prefetchable window. */ pbus_size_mem(bus, mask, IORESOURCE_MEM, type2, type3, - realloc_head ? 0 : additional_mem_size, - additional_mem_size, realloc_head); + realloc_head ? 0 : additional_mmio_size, + additional_mmio_size, realloc_head); break; } } diff --git a/include/linux/pci.h b/include/linux/pci.h index a179856bf..b30d55697 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1959,8 +1959,8 @@ extern u8 pci_dfl_cache_line_size; extern u8 pci_cache_line_size; extern unsigned long pci_hotplug_io_size; -extern unsigned long pci_hotplug_mem_size; -extern unsigned long pci_hotplug_mem_pref_size; +extern unsigned long pci_hotplug_mmio_size; +extern unsigned long pci_hotplug_mmio_pref_size; extern unsigned long pci_hotplug_bus_size; /* Architecture-specific versions may override these (weak) */