From patchwork Wed Jan 15 17:55:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Johnson X-Patchwork-Id: 11335501 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3373892A for ; Wed, 15 Jan 2020 17:55:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 121BB214AF for ; Wed, 15 Jan 2020 17:55:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729067AbgAORzl convert rfc822-to-8bit (ORCPT ); Wed, 15 Jan 2020 12:55:41 -0500 Received: from mail-oln040092253099.outbound.protection.outlook.com ([40.92.253.99]:62544 "EHLO APC01-SG2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726418AbgAORzl (ORCPT ); Wed, 15 Jan 2020 12:55:41 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ehj5yglgyc8wkXGfFw2CxYRxkPES0nygaDLGuF+6Q4ugpzIQzoq6foqs5Bmp/5qGgrQFksye5xyC4b0LhOJzTEbB0cUeNPqf6mv5KmiFJEm7srZXHPgyc8u+q1hIeJXLakGobA7Y2PZYCPgK1fKefg2ECbhunXxuNpV+f7vj3rSrsrwUzd1+qLHbO2iiDJUts1nsMRywhCqQKWDKRyfdnAxLId7LoPv1uDvga2bdeU/N8nBh+P97M39gGsq5PKb5j1sgn/puVB1LIzs6yrBjj3fOSkppJMn2OzQ/xAlFvhtHk/Ea71aquMsiPRk9rs5z8Jc+Wi00mfhTT/4kwuDc1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PaWrRiUlxqKC/gKwrQ6i+Mwd0PrSM1EXI3p/EN1u1OU=; b=nMDFtwan/FjN/psUmPH2HfpvNaBBfxy4Ya2W6SHrdIzITQBzngBd4JBbQ5yYYd9xe3PAB2n5kvdsnGVHjlgyBQuaV7mAdFsshGCMysC1pMy0ml6n3ghczHhCdX2EIT4v6NIlBKRabLCLPUTjwFnFL+GTTJw+x1x8cdhMV0vJ7fV2vcN7eGjzCrhKqOkvnB18/Llt99mXDErD3jHgG9ophp8x89dG7/lc95XtLd4ctXtr95Lg7EpBy4Y6jeCnremFJMhHjgMfOdbXPtGJNNy2sn9FXPRr5HmHc3qQ+XHDOesJC+dHH7CLY0mUFJjLa+RKu3SQ5XthGwjaTXltqecmXQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from PU1APC01FT115.eop-APC01.prod.protection.outlook.com (10.152.252.54) by PU1APC01HT069.eop-APC01.prod.protection.outlook.com (10.152.253.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2602.11; Wed, 15 Jan 2020 17:55:36 +0000 Received: from PSXP216MB0438.KORP216.PROD.OUTLOOK.COM (10.152.252.57) by PU1APC01FT115.mail.protection.outlook.com (10.152.252.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2602.11 via Frontend Transport; Wed, 15 Jan 2020 17:55:36 +0000 Received: from PSXP216MB0438.KORP216.PROD.OUTLOOK.COM ([fe80::20ad:6646:5bcd:63c9]) by PSXP216MB0438.KORP216.PROD.OUTLOOK.COM ([fe80::20ad:6646:5bcd:63c9%11]) with mapi id 15.20.2623.018; Wed, 15 Jan 2020 17:55:36 +0000 Received: from nicholas-dell-linux (61.69.138.108) by ME2PR01CA0059.ausprd01.prod.outlook.com (2603:10c6:201:2b::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.19 via Frontend Transport; Wed, 15 Jan 2020 17:55:33 +0000 From: Nicholas Johnson To: "linux-kernel@vger.kernel.org" CC: "linux-pci@vger.kernel.org" , Bjorn Helgaas , Mika Westerberg , Benjamin Herrenschmidt , Logan Gunthorpe , Nicholas Johnson Subject: [PATCH v2 1/3] PCI: Remove redundant brackets in pci_bus_distribute_available_resources() Thread-Topic: [PATCH v2 1/3] PCI: Remove redundant brackets in pci_bus_distribute_available_resources() Thread-Index: AQHVy8z9Ar1BXjAzu02TW9NgPGJS+w== Date: Wed, 15 Jan 2020 17:55:35 +0000 Message-ID: Accept-Language: en-AU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: ME2PR01CA0059.ausprd01.prod.outlook.com (2603:10c6:201:2b::23) To PSXP216MB0438.KORP216.PROD.OUTLOOK.COM (2603:1096:300:d::20) x-incomingtopheadermarker: OriginalChecksum:A77651BFBE56B22DE675C464AECA7AD6224C5B8F6FA06847F6A0524CC330A123;UpperCasedChecksum:119053F4C44AFB5D7071DF8C9D9019510F6A007824BE182D5106C05F9C68EC58;SizeAsReceived:7828;Count:48 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [+cZ8q41Eg7q3G2XpRomHGhh7FZvLmmQL] x-microsoft-original-message-id: <20200115175528.GA4505@nicholas-dell-linux> x-ms-publictraffictype: Email x-incomingheadercount: 48 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: 7b203514-f05d-4236-63ac-08d799e41f8e x-ms-exchange-slblob-mailprops: Zv/SX2iM+5VJNhHB98CBUJCpDp+U+pvxxmPlOs7EevofASLKSzltoElL1zmS5cefwn8lmMZPKG3nlQsxJkBf+uX2luHuwMHJTkQsLmGtiH7r1GVkjM0EERHfi8uPoRjbLNzgK6UpNFB4d9Y/Q3o89bdFpg6Nmyt6NuuiIDkbPtwUc9EGn9c8SZ92IIuJMPhXiQxOda0BdqoblD2LYEJqArdHNS8y58NBT25uROApJoX93KKf7qKgFgsDqmaHH9MeLSdsmDcrXRM5a4QleyaqvV+/v5kFM++1lmghtoKfSUbg+CmGh5GQraj0v6ZQ6sTIDjgiOdLASfSHWkWJjDZb4Y0wF61jR3iO/2J8bPdxPxRyDB5DlNpkB+iZ9y/ow+VmgFkRnM1Q28Ev3bVfz6TfyNNe6KtJKDO7Uaj/Xjvf/4hhN1p0LdGoc997Aysv5VDK9lqxfuve/N+BT8hHusma/brH6X16Xhw8tncACLzuPJJFQn/eHhuJsEhj1b+AgHJGSvGLFvMxry+4EpupFIyzOJvtJ0JnKFrNbhpO7Hc8D0HC1b6mbr4+Q06Fj0mPSpEDvpXV6u/+s5DFj+aItC0+F1c31CM/ruot9WdxvXbUk1xhw1N19DFZSIsJaSVRuQlSwjxDdmj18aYYPP1V+Hytb4bCbNjvJ85vnjvAjhdZ7iX3tVie9+3R1TTxohyeYmarjuIK/SyOAEM= x-ms-traffictypediagnostic: PU1APC01HT069: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: ylJBPrzEq6HFbSkZHrBj/AcCFKlNjjWETxPjWXtxR5Jvm2eqvPQdaVf4CAyAZh3jgZEMUb/JoZcZtMVFANqO1MiO9R0dotv9eMFeTu5VEMyEum/+fYmEueBZ8G3Aw4lJBTVe5VMWKxc3ar0Pd5Kb4s/MifmlR2hD7QF7Sa8rDumLO7c+L6hKp6AIkZsWpa5z x-ms-exchange-transport-forked: True Content-ID: <7A58F04F1A923040A8900979CECFEFC9@KORP216.PROD.OUTLOOK.COM> 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: 7b203514-f05d-4236-63ac-08d799e41f8e X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Jan 2020 17:55:36.2280 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PU1APC01HT069 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Remove redundant brackets in pci_bus_distribute_available_resources(). No functional changes. Signed-off-by: Nicholas Johnson Reviewed-by: Mika Westerberg --- drivers/pci/setup-bus.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index f27982620..465a8b565 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1902,11 +1902,10 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus, */ if (hotplug_bridges + normal_bridges == 1) { dev = list_first_entry(&bus->devices, struct pci_dev, bus_list); - if (dev->subordinate) { + if (dev->subordinate) pci_bus_distribute_available_resources(dev->subordinate, add_list, available_io, available_mmio, available_mmio_pref); - } return; } From patchwork Wed Jan 15 17:55:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Johnson X-Patchwork-Id: 11335503 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 956C5138D for ; Wed, 15 Jan 2020 17:56:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 68CAD24671 for ; Wed, 15 Jan 2020 17:56:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726587AbgAOR4B convert rfc822-to-8bit (ORCPT ); Wed, 15 Jan 2020 12:56:01 -0500 Received: from mail-oln040092255017.outbound.protection.outlook.com ([40.92.255.17]:27756 "EHLO APC01-HK2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726418AbgAOR4B (ORCPT ); Wed, 15 Jan 2020 12:56:01 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=idvfxJ6xN8v7SDGb+LeCdOKhtPah8B0S37JxJ/9I/mIvKAHrudfhZ/GVfasww8gvyleENpWe0y8VGkAecHbvdImFxLuhb5ap0Im1lgSXz5purN28X9YpMW4WcQLoVg+kfvDYXah6kBPPXCIdTG8QDlP4s8+BP/MwToNmxsIQSLoFJZnv1LrRRMniCM/MshzPwGMaQHNbjsXmfKbgkmX81ZkxFW76HhQuK+l1EDBYABtn2gn7HabsQoSpMHK0j9/sEkJzhdlAKpaO6+7Y0IyxHlEfWH+OHJEDpVwiR3EEhgN9NR5bdyUFZfAalmEf0CW2HUtTRQKS7AjTtswHz4fJTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hf+Z2yJIOrqjXisRPyrcNWYECIr0LzUvlXlsAKaB2RU=; b=bY0BV4qRZnswwycXDeYANt03cx4nTjXyZqrGwRkNjd3zrGD8EVEvQStPb2XAm+5HgC9CeJFxIfALKDFyxvLTGYnYAflZW1Xn8LHHp7ysEzyqApkCDO9lAIVr2jgTG9oHtFIAodfL+O90C1IjvQ6m9qJOfqSn73JjR3BTgRHIjbAFtSQ2ljaiSHwdmGPTwFJWISfbwzyFSsNyncQfWwFg5l9g7mIR33MkIOuXFfr1VBwGSm44q3FVnsa7a9uvkB6LBgW0z3dn+FdWv1zHIIkbebXOkfdTpbaw/au0hrUXsb+c9y0B7gp7dycObW2nVZc1T6tGS6tR+x0TxiQLvF7LjA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from PU1APC01FT115.eop-APC01.prod.protection.outlook.com (10.152.252.54) by PU1APC01HT074.eop-APC01.prod.protection.outlook.com (10.152.253.113) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2602.11; Wed, 15 Jan 2020 17:55:55 +0000 Received: from PSXP216MB0438.KORP216.PROD.OUTLOOK.COM (10.152.252.57) by PU1APC01FT115.mail.protection.outlook.com (10.152.252.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2602.11 via Frontend Transport; Wed, 15 Jan 2020 17:55:55 +0000 Received: from PSXP216MB0438.KORP216.PROD.OUTLOOK.COM ([fe80::20ad:6646:5bcd:63c9]) by PSXP216MB0438.KORP216.PROD.OUTLOOK.COM ([fe80::20ad:6646:5bcd:63c9%11]) with mapi id 15.20.2623.018; Wed, 15 Jan 2020 17:55:55 +0000 Received: from nicholas-dell-linux (61.69.138.108) by MEXPR01CA0144.ausprd01.prod.outlook.com (2603:10c6:200:2e::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2623.10 via Frontend Transport; Wed, 15 Jan 2020 17:55:53 +0000 From: Nicholas Johnson To: "linux-kernel@vger.kernel.org" CC: "linux-pci@vger.kernel.org" , Bjorn Helgaas , Mika Westerberg , Benjamin Herrenschmidt , Logan Gunthorpe , Nicholas Johnson Subject: [PATCH v2 2/3] PCI: Change pci_bus_distribute_available_resources() args to struct resource Thread-Topic: [PATCH v2 2/3] PCI: Change pci_bus_distribute_available_resources() args to struct resource Thread-Index: AQHVy80IJ28WXgSE4ESOni8G7RXQsQ== Date: Wed, 15 Jan 2020 17:55:55 +0000 Message-ID: Accept-Language: en-AU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MEXPR01CA0144.ausprd01.prod.outlook.com (2603:10c6:200:2e::29) To PSXP216MB0438.KORP216.PROD.OUTLOOK.COM (2603:1096:300:d::20) x-incomingtopheadermarker: OriginalChecksum:9DB488DE1FD4DF8E01F847FC82BEA236620588B11ED82E0AD6D2BAAE033BCC23;UpperCasedChecksum:B2C4B0F2921317CB80EDA8A56CB2707C830B10B6E01973529CC5B6A283D964CC;SizeAsReceived:7817;Count:48 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [fQZ4ODuM3IkQlLUkzYB/3aNzoG0nc73N] x-microsoft-original-message-id: <20200115175547.GA4507@nicholas-dell-linux> x-ms-publictraffictype: Email x-incomingheadercount: 48 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: bac1b8c7-48f5-438f-5140-08d799e42aec x-ms-exchange-slblob-mailprops: zswcL9HXbeVV5DRQNiFD0ULmQNyfwccSqUhyOR+Ebg+10hJ0JFYV70ZTCmDUqM8ILZbgpCh0Xyw8yJuBBHUZIjAxygT8pfjgRa4lGgBlSqKPOXi02hIO4YE71Bn2xCpXiibPvG1OwIsIQkbAqZUjTRhJvTOL1UznmQUCp/Y6W2IURk4d7vOT21a0+/AT4BNfq0mOHT4SAanmgh9bDr6lfw7i8obwuxADBfAxIkz+e6q2X6BgQ4kHMm0DHDKS4YV48hdjgRZhLvoSpoGU+LzFb3utA+UOKT5DjuZXnOZP/TkUMq8I+SR55u+Hko1p9md7Rpa2W2PAlN4Bz3Wq/MM/jWgujw0O5wmbCDgAs3DP6paDnOJ557iyRLFU1s7l3/rXzaqso6VUSFp9AUf1VjTjTGwqVSgDsFNM6YnvNqJYiNSkMuR2O0NT1HcKDkWu7hzn0O4YBENj5N3nxAeEhwUF8719h1x/S9ccPMIMyhzouiz5bHKFELtG4l7gwYjxoyw7rCVbAZoqBXLCZfQzWWv8NWf2GJ9hPwwozaSDX62X4JgMRDtbXab9O3Vv2B8R5VoL893SnJGaOEDz/7A8j1/11kGEESsmlxrjTDSls4/9NKRpZXHu2bP5/qx/RgwhevGZdMH7pntIm4WBUxduypvIKjkbS28xM/cCMptPTK3bhtEXhMkzLRR5eo+URIRiFZv++cdS1bQWHsv7FYtQzARLygL5PfFi+r5n9NPI643qeib3tZMon73H61ZOLOgyJF3q x-ms-traffictypediagnostic: PU1APC01HT074: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: AkmBM5ORe8qFEXC9RAc4BvQGJr+mSeVsBpmrdIK6CMqI9ICD3aPqUb7u9RpPkW4wRT0Xgqc9RaJeg6meuQX7UJIHcbFbNTrlkEARNMkkovnHWZWW4jbYyjbX4/IBsoxN79DG6lVsIo//AcNTGpZDIzR5Y1d5rUDXYsDZgN2zqZ3Fv4sauLty1oY/YS3hS67t x-ms-exchange-transport-forked: True Content-ID: 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: bac1b8c7-48f5-438f-5140-08d799e42aec X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Jan 2020 17:55:55.3285 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PU1APC01HT074 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Change pci_bus_distribute_available_resources() arguments from resource_size_t to struct resource to add more information required to get the alignment correct for bridge windows with alignment >1M. This is in preparation for the following patch: "PCI: Consider alignment of hot-added bridges when distributing available resources" We require (size, alignment), instead of just (size) which is what is currently available. The change from resource_size_t to struct resource does just that. Note that the struct resource arguments are passed by value and not by reference. We do not want to pass by reference and change the resource size of the parent bridge window. We only want the size information. No functional changes. Signed-off-by: Nicholas Johnson Reviewed-by: Mika Westerberg --- drivers/pci/setup-bus.c | 66 +++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 465a8b565..269082261 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1859,11 +1859,13 @@ static void extend_bridge_window(struct pci_dev *bridge, struct resource *res, 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 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; + resource_size_t avail_io, avail_mmio, avail_mmio_pref; unsigned int normal_bridges = 0, hotplug_bridges = 0; struct resource *io_res, *mmio_res, *mmio_pref_res; struct pci_dev *dev, *bridge = bus->self; @@ -1878,10 +1880,10 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus, * calculated in __pci_bus_size_bridges() which covers all the * devices currently connected to the port and below. */ - extend_bridge_window(bridge, io_res, add_list, available_io); - extend_bridge_window(bridge, mmio_res, add_list, available_mmio); + 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, - available_mmio_pref); + resource_size(&mmio_pref)); /* * Calculate how many hotplug bridges and normal bridges there @@ -1904,8 +1906,7 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus, 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); + add_list, io, mmio, mmio_pref); return; } @@ -1918,9 +1919,9 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus, * extra space reduced by the minimal required space for the * non-hotplug bridges. */ - remaining_io = available_io; - remaining_mmio = available_mmio; - remaining_mmio_pref = available_mmio_pref; + remaining_io = avail_io = resource_size(&io); + remaining_mmio = avail_mmio = resource_size(&mmio); + remaining_mmio_pref = avail_mmio_pref = resource_size(&mmio_pref); for_each_pci_bridge(dev, bus) { const struct resource *res; @@ -1933,15 +1934,15 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus, * bridge and devices below it occupy. */ res = &dev->resource[PCI_BRIDGE_RESOURCES + 0]; - if (!res->parent && available_io > resource_size(res)) + if (!res->parent && avail_io > resource_size(res)) remaining_io -= resource_size(res); res = &dev->resource[PCI_BRIDGE_RESOURCES + 1]; - if (!res->parent && available_mmio > resource_size(res)) + if (!res->parent && avail_mmio > resource_size(res)) remaining_mmio -= resource_size(res); res = &dev->resource[PCI_BRIDGE_RESOURCES + 2]; - if (!res->parent && available_mmio_pref > resource_size(res)) + if (!res->parent && avail_mmio_pref > resource_size(res)) remaining_mmio_pref -= resource_size(res); } @@ -1950,7 +1951,7 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus, * resource space between hotplug bridges. */ for_each_pci_bridge(dev, bus) { - resource_size_t align, io, mmio, mmio_pref; + resource_size_t align; struct pci_bus *b; b = dev->subordinate; @@ -1963,19 +1964,24 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus, * account. */ align = pci_resource_alignment(bridge, io_res); - io = div64_ul(available_io, hotplug_bridges); - io = min(ALIGN(io, align), remaining_io); - remaining_io -= io; + io_per_hp = div64_ul(avail_io, hotplug_bridges); + io_per_hp = min(ALIGN(io_per_hp, align), remaining_io); + remaining_io -= io_per_hp; align = pci_resource_alignment(bridge, mmio_res); - mmio = div64_ul(available_mmio, hotplug_bridges); - mmio = min(ALIGN(mmio, align), remaining_mmio); - remaining_mmio -= mmio; + mmio_per_hp = div64_ul(avail_mmio, hotplug_bridges); + mmio_per_hp = min(ALIGN(mmio_per_hp, align), remaining_mmio); + remaining_mmio -= mmio_per_hp; 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; + mmio_pref_per_hp = div64_ul(avail_mmio_pref, hotplug_bridges); + mmio_pref_per_hp = min(ALIGN(mmio_pref_per_hp, align), + remaining_mmio_pref); + remaining_mmio_pref -= mmio_pref_per_hp; + + 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; pci_bus_distribute_available_resources(b, add_list, io, mmio, mmio_pref); @@ -1985,19 +1991,15 @@ 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) { - resource_size_t available_io, available_mmio, available_mmio_pref; - const struct resource *res; + struct resource available_io, available_mmio, available_mmio_pref; if (!bridge->is_hotplug_bridge) return; /* 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); + available_io = bridge->resource[PCI_BRIDGE_RESOURCES + 0]; + available_mmio = bridge->resource[PCI_BRIDGE_RESOURCES + 1]; + available_mmio_pref = bridge->resource[PCI_BRIDGE_RESOURCES + 2]; pci_bus_distribute_available_resources(bridge->subordinate, add_list, available_io, From patchwork Wed Jan 15 17:56:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Johnson X-Patchwork-Id: 11335505 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EF8E5138D for ; Wed, 15 Jan 2020 17:56:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C474C214AF for ; Wed, 15 Jan 2020 17:56:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729012AbgAOR4U convert rfc822-to-8bit (ORCPT ); Wed, 15 Jan 2020 12:56:20 -0500 Received: from mail-oln040092253041.outbound.protection.outlook.com ([40.92.253.41]:35765 "EHLO APC01-SG2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728998AbgAOR4U (ORCPT ); Wed, 15 Jan 2020 12:56:20 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fJmwvtZ/WucwBU3mchGlmJTe1Ctcna5om0E8TiKEiJXj33pUSJXLWSPwzKHJgYyjZjlDcMmbk4z25IoAxna05YGv4yUjW3IukZ3Bo0I265l45ZiGZ9aBlzNFd3Fdsm0bIEYs4TzlWLt8i19pxgcYGI3xu2GLI3eagHiMtMzFlpGPJdZggqex63pW89/ZmNAuvB8ShHRiHDrqUyDx8GOCyIpP32bg9/Gj0jKuwoResmOarh/R5VhvO7z9MgvWuMxr+fOHrcCnV/LHsRe21XMjuAuVwXOtXRCJ5hJ3hpMTAi2KiQBt5onzESCK7ynqMNpYG5y8L3+B2TRAl5zcssIS8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iEQe7Iih79GnSXeJEsBmkJIAY/cL4JwPgrFmrbpT5lc=; b=Qgutj72eaR+60yhSRxlleB58F59JM3YeXfVT4UzMymcMPGvRzmtSbKb3zqFO1h0cuqRLrpbl+yo+L1aUrFjGSM/PqLE3tZ4+sP0zwdH+GgyDWq3Kqfgxkjrp7IMq9FbeG2Qlrc1otH9k/Zys7hRKZQmFZdJqZcHYuDT7lwPlzb68QW6OUtJUqHD4dRnoAXTTzoHIDsX9Gh1DCE6t0MTEiKcimT/dhxjLBNOmx13ZVjxBJN+Zr9C8XzHYuaW26n8yDAnoycxzm+2295zWwvhmhLzxxeMNSsZ3j074A6iG0UkYlWDCGjRQKiRRNmum0tY/t8mW4CPObWD5PLbHlAq/CA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from PU1APC01FT115.eop-APC01.prod.protection.outlook.com (10.152.252.59) by PU1APC01HT127.eop-APC01.prod.protection.outlook.com (10.152.253.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2602.11; Wed, 15 Jan 2020 17:56:14 +0000 Received: from PSXP216MB0438.KORP216.PROD.OUTLOOK.COM (10.152.252.57) by PU1APC01FT115.mail.protection.outlook.com (10.152.252.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2602.11 via Frontend Transport; Wed, 15 Jan 2020 17:56:14 +0000 Received: from PSXP216MB0438.KORP216.PROD.OUTLOOK.COM ([fe80::20ad:6646:5bcd:63c9]) by PSXP216MB0438.KORP216.PROD.OUTLOOK.COM ([fe80::20ad:6646:5bcd:63c9%11]) with mapi id 15.20.2623.018; Wed, 15 Jan 2020 17:56:14 +0000 Received: from nicholas-dell-linux (61.69.138.108) by ME4P282CA0001.AUSP282.PROD.OUTLOOK.COM (2603:10c6:220:90::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2623.10 via Frontend Transport; Wed, 15 Jan 2020 17:56:12 +0000 From: Nicholas Johnson To: "linux-kernel@vger.kernel.org" CC: "linux-pci@vger.kernel.org" , Bjorn Helgaas , Mika Westerberg , Benjamin Herrenschmidt , Logan Gunthorpe , Nicholas Johnson Subject: [PATCH v2 3/3] PCI: Consider alignment of hot-added bridges when distributing available resources Thread-Topic: [PATCH v2 3/3] PCI: Consider alignment of hot-added bridges when distributing available resources Thread-Index: AQHVy80UqszJ0J6vUkOxHSiku/VLiw== Date: Wed, 15 Jan 2020 17:56:14 +0000 Message-ID: Accept-Language: en-AU, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: ME4P282CA0001.AUSP282.PROD.OUTLOOK.COM (2603:10c6:220:90::11) To PSXP216MB0438.KORP216.PROD.OUTLOOK.COM (2603:1096:300:d::20) x-incomingtopheadermarker: OriginalChecksum:00C797530CBEBAF3A516F16B31241C14F0153178C8D1502DCAC6CB8E110CC6E9;UpperCasedChecksum:08E9F82DD3841E2349353B6D5BE7EB87FD170E346DD0CC696F53397E3AE901D7;SizeAsReceived:7826;Count:48 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [ux6msHsNw4nbVPHXSk46Po4f4nRwWDAt] x-microsoft-original-message-id: <20200115175606.GA4509@nicholas-dell-linux> x-ms-publictraffictype: Email x-incomingheadercount: 48 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: f47a197f-3f31-4d4a-4e23-08d799e43652 x-ms-exchange-slblob-mailprops: Xo9mRxKQURQLKonzPJ6/VvFsyF9p9aaO1jrIKmQss9FvRHjhTo3YyBr4oUjXOFNkdWz0S/b3aza7CCbNDOfHmZPcNsDNtB2f6KafbeOkjDs8cpsdfG6cc/Supjkd1udFoC4vJVsBDKPmUjJVVfCh4zjJu2vyeCZ0JIINWT3W031w3S2O3dhirErB80lCF0BQ3cak8YZB5xcEoF0Ow1OGlRx/N5PhLUtUWLApKABNsqyY4UcbSisXAmI1Oxf3r+hdu+KQd/zVh4cXvEVo78z7VI4SClythyftW1FfgUF3ghpQsT+vKf9QZLfHlbBq8jVDqMyNZACV9hnGT/bBlXZ0BIPJq7kwnD6Ji991G6OKPwYgD7MW0eqToenyJlLV11QgsiGJJCPgEfE0CxwXedjDHtS6OriktGqzGM61e4RxQq+uqZxxNgDNYYpFwLEASAdpuWiPTPx1U0y+tfuzvMR0Rhoo6AgNWsKWGsqMrYnBDM48JcoVtdGfunCuhcmPhMGmYEQSNORpt0u7bp5qsORFvN1HfFyoPVYyBz54p7biCyccCiZESRp5q+B5U6md7ezUQaMK9ZfVbifCnIbe/Sev3DHRuDbQ+Rim7Tfx3TWLfoqQCQlDXH1P/gQ5vZ3xrGLasqHIJr9kHlMhDQefad7tX2vHBTDAJMvGFxRyKh09No2YhKVigCTzrpbJzPtcMwgsWLo8Gcq1LE9QAmAA4tVVe9Fo2z80nlKvzVHhnEy05wQ10sYY2v7afjc+IWdTX0jn1FY9QK/8r+SThHIA1PPAfTQk+KqhZvfGj8+vyrEg5vEaQN0Pg7SNzdngz1q/sRJANNcDAQ6jwfrBgYylJbL3/9WXVnwEA+7IJ9NIyyjStgBRa+CN447LUHTuWxpOYjExy1cNc4mU66CfDstbQfUOf9Sq5LfC1T0YOoSj/l+bu1mWGn07DFLU+g== x-ms-traffictypediagnostic: PU1APC01HT127: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: gZxTq7qMYeE9eexjuDicOMtukXIu+U4BTrCiUa9UpNC9DBRPnDum14EPTrvo58ENCdDsM0wi9tJuiUZJKeTPJCNOx9lqiZvluWCmBZomPYbvic5RWGSRuX3AlNteGVGJcQBxCMqVEc4hmtwNI3yqgXggB7ZdlViCGeTJAlebe3rARBwG05Z+CAF9QqxGpAbYqbMs7jCRc64AY51Uahk0ROBdpsWlj1ox8SvUFfskMzU= x-ms-exchange-transport-forked: True Content-ID: <1010D0DAD21C9E49ACA3165AB5525DE4@KORP216.PROD.OUTLOOK.COM> 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: f47a197f-3f31-4d4a-4e23-08d799e43652 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Jan 2020 17:56:14.2209 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PU1APC01HT127 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Change pci_bus_distribute_available_resources() to better handle bridges with different resource alignment requirements. The arguments io, mmio and mmio_pref represent the start and end addresses of resource, in which we must fit the current bridge window. The steps taken by pci_bus_distribute_available_resources(): - For io, mmio and mmio_pref, increase .start to align with the alignment of the current bridge window (otherwise the current bridge window may not fit within the available range). - For io, mmio and mmio_pref, adjust the current bridge window to the size after the above. - Count the number of hotplug bridges and normal bridges on this bus. - If the total number of bridges is one, give that bridge all of the resources and return. - If there are no hotplug bridges, return. - For io, mmio and mmio_pref, increase .start by the amount required for each bridge resource on the bus for non hotplug bridges, giving extra room to make up for alignment of those resources. - For io, mmio and mmio_pref, calculate the resource size per hotplug bridge which is available after the previous steps. - For io, mmio and mmio_pref, distribute the resources to each hotplug bridge, with the sizes calculated above. The motivation for fixing this is Thunderbolt with native PCI enumeration, enabling external graphics cards and other devices with bridge alignment higher than 1MB. This fixes the use case where the user hot-adds Thunderbolt devices containing PCI devices with BAR alignment >1M and having the resources fail to assign. Link: https://bugzilla.kernel.org/show_bug.cgi?id=199581 Reported-by: Mika Westerberg Signed-off-by: Nicholas Johnson Tested-by: Mika Westerberg Reviewed-by: Mika Westerberg --- drivers/pci/setup-bus.c | 77 ++++++++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 31 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 269082261..8b39b9ebb 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1863,9 +1863,7 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus, 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; - resource_size_t avail_io, avail_mmio, avail_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; @@ -1874,6 +1872,23 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus, mmio_res = &bridge->resource[PCI_BRIDGE_RESOURCES + 1]; mmio_pref_res = &bridge->resource[PCI_BRIDGE_RESOURCES + 2]; + /* + * The alignment of this bridge is yet to be considered, hence it must + * be done now before extending its bridge window. + */ + align = pci_resource_alignment(bridge, io_res); + if (!io_res->parent && align) + io.start = min(ALIGN(io.start, align), io.end + 1); + + align = pci_resource_alignment(bridge, mmio_res); + if (!mmio_res->parent && align) + mmio.start = min(ALIGN(mmio.start, align), mmio.end + 1); + + align = pci_resource_alignment(bridge, mmio_pref_res); + if (!mmio_pref_res->parent && align) + mmio_pref.start = min(ALIGN(mmio_pref.start, align), + mmio_pref.end + 1); + /* * Update additional resource list (add_list) to fill all the * extra resource space available for this port except the space @@ -1919,12 +1934,9 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus, * extra space reduced by the minimal required space for the * non-hotplug bridges. */ - remaining_io = avail_io = resource_size(&io); - remaining_mmio = avail_mmio = resource_size(&mmio); - remaining_mmio_pref = avail_mmio_pref = resource_size(&mmio_pref); - for_each_pci_bridge(dev, bus) { - const struct resource *res; + resource_size_t used_size; + struct resource *res; if (dev->is_hotplug_bridge) continue; @@ -1934,24 +1946,39 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus, * bridge and devices below it occupy. */ res = &dev->resource[PCI_BRIDGE_RESOURCES + 0]; - if (!res->parent && avail_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) + io.start = min(io.start + used_size, io.end + 1); res = &dev->resource[PCI_BRIDGE_RESOURCES + 1]; - if (!res->parent && avail_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) + mmio.start = min(mmio.start + used_size, mmio.end + 1); res = &dev->resource[PCI_BRIDGE_RESOURCES + 2]; - if (!res->parent && avail_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) + mmio_pref.start = min(mmio_pref.start + used_size, + mmio_pref.end + 1); } + 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); + /* * Go over devices on this bus and distribute the remaining * resource space between hotplug bridges. */ for_each_pci_bridge(dev, bus) { - resource_size_t align; struct pci_bus *b; b = dev->subordinate; @@ -1963,28 +1990,16 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus, * hotplug-capable downstream ports taking alignment into * account. */ - align = pci_resource_alignment(bridge, io_res); - io_per_hp = div64_ul(avail_io, hotplug_bridges); - io_per_hp = min(ALIGN(io_per_hp, align), remaining_io); - remaining_io -= io_per_hp; - - align = pci_resource_alignment(bridge, mmio_res); - mmio_per_hp = div64_ul(avail_mmio, hotplug_bridges); - mmio_per_hp = min(ALIGN(mmio_per_hp, align), remaining_mmio); - remaining_mmio -= mmio_per_hp; - - align = pci_resource_alignment(bridge, mmio_pref_res); - mmio_pref_per_hp = div64_ul(avail_mmio_pref, hotplug_bridges); - mmio_pref_per_hp = min(ALIGN(mmio_pref_per_hp, align), - remaining_mmio_pref); - remaining_mmio_pref -= mmio_pref_per_hp; - 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; pci_bus_distribute_available_resources(b, add_list, io, mmio, mmio_pref); + + io.start += io_per_hp; + mmio.start += mmio_per_hp; + mmio_pref.start += mmio_pref_per_hp; } }