From patchwork Fri Aug 17 10:26:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 958737 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arndb.de Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41sKCg3n77z9s4c for ; Fri, 17 Aug 2018 20:27:59 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727181AbeHQNad (ORCPT ); Fri, 17 Aug 2018 09:30:33 -0400 Received: from mout.kundenserver.de ([212.227.17.24]:49229 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726218AbeHQNab (ORCPT ); Fri, 17 Aug 2018 09:30:31 -0400 Received: from wuerfel.lan ([109.193.40.16]) by mrelayeu.kundenserver.de (mreue101 [212.227.15.145]) with ESMTPA (Nemesis) id 0LbrfA-1gFk7r2rG0-00jIgT; Fri, 17 Aug 2018 12:27:15 +0200 From: Arnd Bergmann To: linux-pci@vger.kernel.org, Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, Christoph Hellwig , Lorenzo Pieralisi , Benjamin Herrenschmidt , linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, Arnd Bergmann Subject: [RFC 01/15] PCI: clean up legacy host bridge scan functions Date: Fri, 17 Aug 2018 12:26:31 +0200 Message-Id: <20180817102645.3839621-2-arnd@arndb.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180817102645.3839621-1-arnd@arndb.de> References: <20180817102645.3839621-1-arnd@arndb.de> X-Provags-ID: V03:K1:qDqhbuzSX8z08T2QJlMsg/+ruOlcqG1c6ro78J/5MxdL56nnRad yO5HhKo3efL2siEaAAY7qOiJJ3tKLIqKd6DJd1500VXoRHZnzIU11B5eNkG3bBfbRbiMaOC 7sIxy4pZO0kdRg2lK5a97hD/1JtCLT9+XU9Bhcz8Phl5VVvzt8s/T5OnHN6eXScNldLezo9 2xaQ1mtfde4n2i8BI3gDQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:jfQRhFGulKg=:XukBP/UhVY4BRzkO84yddY qQprVATs/qCyceQTQaz+NSylj38T+4mtihVDs3Lu2LdCa1KYaNdq3gRlgvmqPRcs8HvdHy6Oi 9gEnQJaQJTT28Na47z6gb3ssYaSqkriElVDkOJ6POo3RjjkpCPEf+02/pTfuqK3E4fvzcxwD0 BsvGfrcRv1rBlbcLybB4/WrFXvSLSgbapLU9ENLSsVJRMKh9bgR5IJtNotnR14UkHxxJl3X5k 9pIUmf11wUVON5jlM9WT8wJBOFmcmsKfAxcQ5/dhB8fnzqtofDUYi8ghIisUjtYpusFeyI+lP XCOQ5IRbxIL1Mv+LBQ/O/jqMQ0hJwza3VFRwmrsFihyPai9gybRhVVear1GmMLGvHu1rpMjXP PkfaKh/Nche6GRkGXkltaZsVuMqrlDwFxTWN/qVCg92pRQk1VMSUQLvbWZYhelAs3GKgcKBRm uXLFTlGeXM3t3x6/3HyDjg4GBGEfs7MxcbUlJfhSkI1niAgMYb5TTB6fkbBex2PXKOah0tDE3 NLbO9MPHnbrM88zKxCyN4CziOFndAmJTEH42nME+FcgVqAJc2gJkOGzJL9DwcC+zDTSule+RG lvvEzhnosFOE+1Phg9bv8wgPAmbyGBaoDqUia7FHDe0LutTZgvUruaDaa25nfzFZGGqRV8d4S GnUtdvrrcKhF2BVCA+dU2Gnpmp0a6aap6Q0M8QFyLPMA3HDxd2vt8msowj/dDlKIVlzE= Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Aside from the modern pci_host_bridge based interfaces, we have a couple of interfaces from old times that are still used in a couple of platforms: pci_create_root_bus(), pci_scan_bus() and pci_scan_root_bus(). As a first step towards getting everybody to use the new interfaces, this simplifies the latter two to call the pci_alloc_host_bridge() and pci_register_host_bridge()/pci_scan_root_bus_bridge() interfaces directly. The behavior should be entirely unchanged here, but we can then push down the functions into the individual host implementations. Signed-off-by: Arnd Bergmann --- drivers/pci/probe.c | 86 ++++++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 41 deletions(-) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index ec784009a36b..b0f666271245 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -23,13 +23,6 @@ #define CARDBUS_LATENCY_TIMER 176 /* secondary latency timer */ #define CARDBUS_RESERVE_BUSNR 3 -static struct resource busn_resource = { - .name = "PCI busn", - .start = 0, - .end = 255, - .flags = IORESOURCE_BUS, -}; - /* Ugh. Need to stop exporting this to modules. */ LIST_HEAD(pci_root_buses); EXPORT_SYMBOL(pci_root_buses); @@ -3060,53 +3053,64 @@ EXPORT_SYMBOL(pci_scan_root_bus_bridge); struct pci_bus *pci_scan_root_bus(struct device *parent, int bus, struct pci_ops *ops, void *sysdata, struct list_head *resources) { - struct resource_entry *window; - bool found = false; - struct pci_bus *b; - int max; - - resource_list_for_each_entry(window, resources) - if (window->res->flags & IORESOURCE_BUS) { - found = true; - break; - } + struct pci_host_bridge *bridge; + int error; - b = pci_create_root_bus(parent, bus, ops, sysdata, resources); - if (!b) + bridge = pci_alloc_host_bridge(0); + if (!bridge) return NULL; - if (!found) { - dev_info(&b->dev, - "No busn resource found for root bus, will use [bus %02x-ff]\n", - bus); - pci_bus_insert_busn_res(b, bus, 255); - } + list_splice_init(resources, &bridge->windows); + bridge->dev.parent = parent; + bridge->sysdata = sysdata; + bridge->busnr = bus; + bridge->ops = ops; - max = pci_scan_child_bus(b); + error = pci_scan_root_bus_bridge(bridge); + if (error < 0) + goto err_out; - if (!found) - pci_bus_update_busn_res_end(b, max); + return bridge->bus; - return b; +err_out: + kfree(bridge); + return NULL; } EXPORT_SYMBOL(pci_scan_root_bus); +static struct resource busn_resource = { + .name = "PCI busn", + .start = 0, + .end = 255, + .flags = IORESOURCE_BUS, +}; + struct pci_bus *pci_scan_bus(int bus, struct pci_ops *ops, void *sysdata) { - LIST_HEAD(resources); - struct pci_bus *b; + struct pci_host_bridge *bridge; + int error; - pci_add_resource(&resources, &ioport_resource); - pci_add_resource(&resources, &iomem_resource); - pci_add_resource(&resources, &busn_resource); - b = pci_create_root_bus(NULL, bus, ops, sysdata, &resources); - if (b) { - pci_scan_child_bus(b); - } else { - pci_free_resource_list(&resources); - } - return b; + bridge = pci_alloc_host_bridge(0); + if (!bridge) + goto err; + + pci_add_resource(&bridge->windows, &ioport_resource); + pci_add_resource(&bridge->windows, &iomem_resource); + pci_add_resource(&bridge->windows, &busn_resource); + bridge->sysdata = sysdata; + bridge->busnr = bus; + bridge->ops = ops; + + error = pci_scan_root_bus_bridge(bridge); + if (error < 0) + goto err; + + return bridge->bus; + +err: + pci_free_host_bridge(bridge); + return NULL; } EXPORT_SYMBOL(pci_scan_bus); From patchwork Fri Aug 17 10:26:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 958748 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arndb.de Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41sKKq5XD8z9s3Z for ; Fri, 17 Aug 2018 20:33:19 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725845AbeHQNfb (ORCPT ); Fri, 17 Aug 2018 09:35:31 -0400 Received: from mout.kundenserver.de ([212.227.17.24]:56531 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725992AbeHQNfb (ORCPT ); Fri, 17 Aug 2018 09:35:31 -0400 Received: from wuerfel.lan ([109.193.40.16]) by mrelayeu.kundenserver.de (mreue101 [212.227.15.145]) with ESMTPA (Nemesis) id 0M9oN6-1fjzDA0HrE-00B3KP; Fri, 17 Aug 2018 12:27:16 +0200 From: Arnd Bergmann To: linux-pci@vger.kernel.org, Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, Christoph Hellwig , Lorenzo Pieralisi , Benjamin Herrenschmidt , linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, Arnd Bergmann Subject: [RFC 02/15] PCI: move pci_scan_bus into callers Date: Fri, 17 Aug 2018 12:26:32 +0200 Message-Id: <20180817102645.3839621-3-arnd@arndb.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180817102645.3839621-1-arnd@arndb.de> References: <20180817102645.3839621-1-arnd@arndb.de> X-Provags-ID: V03:K1:LWXnCU+7Z6xUjdeuzFbZ45bQvgVeaaHfbEf3zC3L26Zzk+q2P/M eBqWnJgU7gwLWWrQHzKtQNFZcb0iVWb27FKaSLk3FaYqvRDAS8Fc4O+kVUSdbViQeydnUMw h7NpiAMFG72dNFXfPHSVlJ0LvhHR19fn798oy2WXLztnZxxmtfjsh5iUmx/CcbOiGkUFKfA 9U53X0yWkPqyToR2KeuMw== X-UI-Out-Filterresults: notjunk:1; V01:K0:i52elxbByfA=:zby/nqAY9+e5yB3sPpAwYv XLGsWsbrJP8EnEyYsf7aWdz+YQwQ06Ay+C2xJ5V8q/Z5WbutiLIkDZsmtklPkwbb7VCHQtmNc htBAhFuY5icvQ7ZSlxEM+0cGgKZ6I3KOhTvVIAI1hTJZCc+BkIF9BYnyKn0Yp+PCGgxGDQc9M z2qGTvyaoqU2FTh0gNlCN4py088cSrcuWuOyS7lrUNN+yexf76tAyIai6J/Qpo1nTPKfX4UaC a/AVBf3VrEDHfcR6l+BV8i7N5LVgln2sjTmuo8Yg0ZW5xLMpvJQQ7LDbTff8GLoJHdL/v9vSL l9M5feuoSNoq08gOtnzB7oh0V9yrObBfHyHyzIj2cw4sWC9u++uFOAaRAtFMZN94PM8BJ3wos j9q5FETIOSk9yTticaNzrsQkjVgxSCp0V7yo94oM1lVcK9JZiJ//fG1W8/rU5B2Re2dDyMPqj z8OF1cfeU1Uk4B22sF2AA9+660U331pPJxrV17EIAM6i/2TpX8dlrUBkXabg7pquF9KiJOSFI iLwaWs2BlcB74LMmqnjgmIPZ9LpA2kF2IE9kVlqdkJ3iltoUzxWxMatjJZJTVH4aB0puA0L8Z 3E4j6jwjkz1DogegisuGl2kt9gbdDITkq6aqv9vgGww9e/6hPek/b5d4mHT/kyli11fgFtW4G 2bcIKPNIenX30apnEBsXNGgTE7pq3vgJD97ENKj+H4O9bz1RK2rxVEgLDfx8bQnPwmJE= Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org There are only two remaining callers of the old pci_scan_bus() interface. Since we want to expose the pci_host_bridge structure everywhere and discourage users from calling the old interfaces, let's move the implementation into the respective callsites. While this duplicates the source code, it makes the object code smaller for all users by avoiding the global implementation, and it allows further cleanup of the two callers. Signed-off-by: Arnd Bergmann --- arch/sparc/kernel/pcic.c | 35 ++++++++++++++++++++++++++++++ drivers/pci/hotplug/ibmphp_core.c | 35 ++++++++++++++++++++++++++++++ drivers/pci/probe.c | 36 ------------------------------- include/linux/pci.h | 1 - 4 files changed, 70 insertions(+), 37 deletions(-) diff --git a/arch/sparc/kernel/pcic.c b/arch/sparc/kernel/pcic.c index ee4c9a9a171c..0197b80fe590 100644 --- a/arch/sparc/kernel/pcic.c +++ b/arch/sparc/kernel/pcic.c @@ -387,6 +387,41 @@ int __init pcic_probe(void) return 0; } +static struct resource busn_resource = { + .name = "PCI busn", + .start = 0, + .end = 255, + .flags = IORESOURCE_BUS, +}; + +static struct pci_bus *pci_scan_bus(int bus, struct pci_ops *ops, + void *sysdata) +{ + struct pci_host_bridge *bridge; + int error; + + bridge = pci_alloc_host_bridge(0); + if (!bridge) + return NULL; + + pci_add_resource(&bridge->windows, &ioport_resource); + pci_add_resource(&bridge->windows, &iomem_resource); + pci_add_resource(&bridge->windows, &busn_resource); + bridge->sysdata = sysdata; + bridge->busnr = bus; + bridge->ops = ops; + + error = pci_scan_root_bus_bridge(bridge); + if (error < 0) + goto err; + + return bridge->bus; + +err_res: + pci_free_host_bridge(bridge); + return NULL; +} + static void __init pcic_pbm_scan_bus(struct linux_pcic *pcic) { struct linux_pbm_info *pbm = &pcic->pbm; diff --git a/drivers/pci/hotplug/ibmphp_core.c b/drivers/pci/hotplug/ibmphp_core.c index 4ea57e9019f1..d35463ee96ba 100644 --- a/drivers/pci/hotplug/ibmphp_core.c +++ b/drivers/pci/hotplug/ibmphp_core.c @@ -717,6 +717,41 @@ static void ibm_unconfigure_device(struct pci_func *func) pci_unlock_rescan_remove(); } +static struct resource busn_resource = { + .name = "pci busn", + .start = 0, + .end = 255, + .flags = IORESOURCE_BUS, +}; + +static struct pci_bus *pci_scan_bus(int bus, struct pci_ops *ops, + void *sysdata) +{ + struct pci_host_bridge *bridge; + int error; + + bridge = pci_alloc_host_bridge(0); + if (!bridge) + return NULL; + + pci_add_resource(&bridge->windows, &ioport_resource); + pci_add_resource(&bridge->windows, &iomem_resource); + pci_add_resource(&bridge->windows, &busn_resource); + bridge->sysdata = sysdata; + bridge->busnr = bus; + bridge->ops = ops; + + error = pci_scan_root_bus_bridge(bridge); + if (error < 0) + goto err; + + return bridge->bus; + +err: + pci_free_host_bridge(bridge); + return NULL; +} + /* * The following function is to fix kernel bug regarding * getting bus entries, here we manually add those primary diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index b0f666271245..12c3aa63c34d 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -3078,42 +3078,6 @@ struct pci_bus *pci_scan_root_bus(struct device *parent, int bus, } EXPORT_SYMBOL(pci_scan_root_bus); -static struct resource busn_resource = { - .name = "PCI busn", - .start = 0, - .end = 255, - .flags = IORESOURCE_BUS, -}; - -struct pci_bus *pci_scan_bus(int bus, struct pci_ops *ops, - void *sysdata) -{ - struct pci_host_bridge *bridge; - int error; - - bridge = pci_alloc_host_bridge(0); - if (!bridge) - goto err; - - pci_add_resource(&bridge->windows, &ioport_resource); - pci_add_resource(&bridge->windows, &iomem_resource); - pci_add_resource(&bridge->windows, &busn_resource); - bridge->sysdata = sysdata; - bridge->busnr = bus; - bridge->ops = ops; - - error = pci_scan_root_bus_bridge(bridge); - if (error < 0) - goto err; - - return bridge->bus; - -err: - pci_free_host_bridge(bridge); - return NULL; -} -EXPORT_SYMBOL(pci_scan_bus); - /** * pci_rescan_bus_bridge_resize - Scan a PCI bus for devices * @bridge: PCI bridge for the bus to scan diff --git a/include/linux/pci.h b/include/linux/pci.h index e72ca8dd6241..d77ce35a2b33 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -905,7 +905,6 @@ void pcibios_bus_to_resource(struct pci_bus *bus, struct resource *res, void pcibios_scan_specific_bus(int busn); struct pci_bus *pci_find_bus(int domain, int busnr); void pci_bus_add_devices(const struct pci_bus *bus); -struct pci_bus *pci_scan_bus(int bus, struct pci_ops *ops, void *sysdata); struct pci_bus *pci_create_root_bus(struct device *parent, int bus, struct pci_ops *ops, void *sysdata, struct list_head *resources); From patchwork Fri Aug 17 10:26:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 958744 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arndb.de Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41sKKW3nqgz9s3Z for ; Fri, 17 Aug 2018 20:33:03 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726717AbeHQNfg (ORCPT ); Fri, 17 Aug 2018 09:35:36 -0400 Received: from mout.kundenserver.de ([217.72.192.73]:41337 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726786AbeHQNfg (ORCPT ); Fri, 17 Aug 2018 09:35:36 -0400 Received: from wuerfel.lan ([109.193.40.16]) by mrelayeu.kundenserver.de (mreue101 [212.227.15.145]) with ESMTPA (Nemesis) id 0Mf0OX-1fXBJl1wd7-00OXrw; Fri, 17 Aug 2018 12:27:16 +0200 From: Arnd Bergmann To: linux-pci@vger.kernel.org, Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, Christoph Hellwig , Lorenzo Pieralisi , Benjamin Herrenschmidt , linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, Arnd Bergmann Subject: [RFC 03/15] PCI: move pci_scan_root_bus into callers Date: Fri, 17 Aug 2018 12:26:33 +0200 Message-Id: <20180817102645.3839621-4-arnd@arndb.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180817102645.3839621-1-arnd@arndb.de> References: <20180817102645.3839621-1-arnd@arndb.de> X-Provags-ID: V03:K1:/BkngKF/6b10KWqzjF4LQs6B6MkQtkRFmL6SWbFHT/fR7ZScAD6 PxIPcoQ33neYAd2DVQLD4hSnISy5S+mjTGrPpMPdZPzOGGwcgsdWWFM+AuB+VXQ/Un5aGIY StxePL7nJko2UJ1UZ5SoqMJdCUyytat7rPOFwnoUXMwuQprWGUrja1NmIA1Y28QzLVqWGsL VZPgBGucfp/4ObNhRus3w== X-UI-Out-Filterresults: notjunk:1; V01:K0:yk/2WoKa2Tc=:UZx4Ov030SIXEGCgA89BLa Fo7ZjH7sD3AjG5Olyljg6m0KZNfNxTw4KN4WaBTbdciiJyzE9Nw2OqOnlrR63j7oiDJBVZaOd s9NmiGAJunm6OpoovumSicVPX53M/9bECWo1zLMuDvmT2l55e9ph+zWE3+iWaXg0XqbsA9SnI wQVT1yyBFacJosDoePfbuMw5g2w8UGIfoOJQ3ewVd5qJk9XhbgfK6oJf02f7AoFHoPFSWLZe6 t7vXC3p/uNgZlgxH2zg6f+gAvOfsiuGUU7c03yz7PE5qMswJpjkvnqWRPPXnqG6N02v3QJomV yiCAD2ZrXAnBidZ1nCpHyrI17n7/QvgK86I3h1psOQPsLieFhcawINXKNI1K+WXskW2lhZvrq 2x6KiGWINfBINz6Y9VA4gLZQz1yWKxGglBCKphglpE6HGwLHVIaoki/7fb683+vjKpJv2xRXp YHAxC7s+/XR8lQRoKRCL7FUB4wqjeQ1Gsie8TZriTyMtUdqvMsLU7WjxbiUcgyLsguIw+vXr5 97L4OarAAGrQcjvppO7sHk8eyu12XUuDYmjHgTKfPQBh3c+Af27LbvvIv6Z49ct5uYJUAeqn9 VF2lOMRy5cP4spbAiTVydTZVhP0xQesHqYOwasIPqxePgv5iErX0JTIdpZ+DeuW0jQ8Eyh8t1 Ta6LBxHDivrMsFXmCyrxPnINY+sjfjXqMtfSqpDRJRollpk7d7KE/NzL0a2BFiBtRkQ8= Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org There are only six remaining callers of the old pci_scan_root_bus() interface. Since we want to expose the pci_host_bridge structure everywhere and discourage users from calling the old interfaces, let's move the implementation into the respective callsites. While this duplicates the source code, it makes the object code smaller for almost all users by avoiding the global implementation, and it allows further cleanup of the callers. Signed-off-by: Arnd Bergmann --- arch/ia64/sn/kernel/io_init.c | 27 +++++++++++++++++++++++++++ arch/microblaze/pci/pci-common.c | 27 +++++++++++++++++++++++++++ arch/s390/pci/pci.c | 27 +++++++++++++++++++++++++++ arch/x86/pci/common.c | 27 +++++++++++++++++++++++++++ arch/xtensa/kernel/pci.c | 27 +++++++++++++++++++++++++++ drivers/pci/probe.c | 28 ---------------------------- drivers/pci/xen-pcifront.c | 27 +++++++++++++++++++++++++++ include/linux/pci.h | 3 --- 8 files changed, 162 insertions(+), 31 deletions(-) diff --git a/arch/ia64/sn/kernel/io_init.c b/arch/ia64/sn/kernel/io_init.c index d63809a6adfa..e768702a7b45 100644 --- a/arch/ia64/sn/kernel/io_init.c +++ b/arch/ia64/sn/kernel/io_init.c @@ -213,6 +213,33 @@ sn_io_slot_fixup(struct pci_dev *dev) } EXPORT_SYMBOL(sn_io_slot_fixup); +static struct pci_bus *pci_scan_root_bus(struct device *parent, int bus, + struct pci_ops *ops, void *sysdata, struct list_head *resources) +{ + struct pci_host_bridge *bridge; + int error; + + bridge = pci_alloc_host_bridge(0); + if (!bridge) + return NULL; + + list_splice_init(resources, &bridge->windows); + bridge->dev.parent = parent; + bridge->sysdata = sysdata; + bridge->busnr = bus; + bridge->ops = ops; + + error = pci_scan_root_bus_bridge(bridge); + if (error < 0) + goto err_out; + + return bridge->bus; + +err_out: + kfree(bridge); + return NULL; +} + /* * sn_pci_controller_fixup() - This routine sets up a bus's resources * consistent with the Linux PCI abstraction layer. diff --git a/arch/microblaze/pci/pci-common.c b/arch/microblaze/pci/pci-common.c index f34346d56095..302071385e1b 100644 --- a/arch/microblaze/pci/pci-common.c +++ b/arch/microblaze/pci/pci-common.c @@ -977,6 +977,33 @@ static void pcibios_setup_phb_resources(struct pci_controller *hose, (unsigned long)hose->io_base_virt - _IO_BASE); } +static struct pci_bus *pci_scan_root_bus(struct device *parent, int bus, + struct pci_ops *ops, void *sysdata, struct list_head *resources) +{ + struct pci_host_bridge *bridge; + int error; + + bridge = pci_alloc_host_bridge(0); + if (!bridge) + return NULL; + + list_splice_init(resources, &bridge->windows); + bridge->dev.parent = parent; + bridge->sysdata = sysdata; + bridge->busnr = bus; + bridge->ops = ops; + + error = pci_scan_root_bus_bridge(bridge); + if (error < 0) + goto err_out; + + return bridge->bus; + +err_out: + kfree(bridge); + return NULL; +} + static void pcibios_scan_phb(struct pci_controller *hose) { LIST_HEAD(resources); diff --git a/arch/s390/pci/pci.c b/arch/s390/pci/pci.c index 9f6f392a4461..b21205f131ce 100644 --- a/arch/s390/pci/pci.c +++ b/arch/s390/pci/pci.c @@ -786,6 +786,33 @@ void pcibios_remove_bus(struct pci_bus *bus) kfree(zdev); } +static struct pci_bus *pci_scan_root_bus(struct device *parent, int bus, + struct pci_ops *ops, void *sysdata, struct list_head *resources) +{ + struct pci_host_bridge *bridge; + int error; + + bridge = pci_alloc_host_bridge(0); + if (!bridge) + return NULL; + + list_splice_init(resources, &bridge->windows); + bridge->dev.parent = parent; + bridge->sysdata = sysdata; + bridge->busnr = bus; + bridge->ops = ops; + + error = pci_scan_root_bus_bridge(bridge); + if (error < 0) + goto err_out; + + return bridge->bus; + +err_out: + kfree(bridge); + return NULL; +} + static int zpci_scan_bus(struct zpci_dev *zdev) { LIST_HEAD(resources); diff --git a/arch/x86/pci/common.c b/arch/x86/pci/common.c index d4ec117c1142..e740d9aa4024 100644 --- a/arch/x86/pci/common.c +++ b/arch/x86/pci/common.c @@ -453,6 +453,33 @@ void __init dmi_check_pciprobe(void) dmi_check_system(pciprobe_dmi_table); } +static struct pci_bus *pci_scan_root_bus(struct device *parent, int bus, + struct pci_ops *ops, void *sysdata, struct list_head *resources) +{ + struct pci_host_bridge *bridge; + int error; + + bridge = pci_alloc_host_bridge(0); + if (!bridge) + return NULL; + + list_splice_init(resources, &bridge->windows); + bridge->dev.parent = parent; + bridge->sysdata = sysdata; + bridge->busnr = bus; + bridge->ops = ops; + + error = pci_scan_root_bus_bridge(bridge); + if (error < 0) + goto err_out; + + return bridge->bus; + +err_out: + kfree(bridge); + return NULL; +} + void pcibios_scan_root(int busnum) { struct pci_bus *bus; diff --git a/arch/xtensa/kernel/pci.c b/arch/xtensa/kernel/pci.c index 21f13e9aabe1..5a8fd67e6c5e 100644 --- a/arch/xtensa/kernel/pci.c +++ b/arch/xtensa/kernel/pci.c @@ -116,6 +116,33 @@ static void __init pci_controller_apertures(struct pci_controller *pci_ctrl, } } +static struct pci_bus *pci_scan_root_bus(struct device *parent, int bus, + struct pci_ops *ops, void *sysdata, struct list_head *resources) +{ + struct pci_host_bridge *bridge; + int error; + + bridge = pci_alloc_host_bridge(0); + if (!bridge) + return NULL; + + list_splice_init(resources, &bridge->windows); + bridge->dev.parent = parent; + bridge->sysdata = sysdata; + bridge->busnr = bus; + bridge->ops = ops; + + error = pci_scan_root_bus_bridge(bridge); + if (error < 0) + goto err_out; + + return bridge->bus; + +err_out: + kfree(bridge); + return NULL; +} + static int __init pcibios_init(void) { struct pci_controller *pci_ctrl; diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 12c3aa63c34d..cf169742c03e 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -3050,34 +3050,6 @@ int pci_scan_root_bus_bridge(struct pci_host_bridge *bridge) } EXPORT_SYMBOL(pci_scan_root_bus_bridge); -struct pci_bus *pci_scan_root_bus(struct device *parent, int bus, - struct pci_ops *ops, void *sysdata, struct list_head *resources) -{ - struct pci_host_bridge *bridge; - int error; - - bridge = pci_alloc_host_bridge(0); - if (!bridge) - return NULL; - - list_splice_init(resources, &bridge->windows); - bridge->dev.parent = parent; - bridge->sysdata = sysdata; - bridge->busnr = bus; - bridge->ops = ops; - - error = pci_scan_root_bus_bridge(bridge); - if (error < 0) - goto err_out; - - return bridge->bus; - -err_out: - kfree(bridge); - return NULL; -} -EXPORT_SYMBOL(pci_scan_root_bus); - /** * pci_rescan_bus_bridge_resize - Scan a PCI bus for devices * @bridge: PCI bridge for the bus to scan diff --git a/drivers/pci/xen-pcifront.c b/drivers/pci/xen-pcifront.c index eba6e33147a2..24070e1c5f22 100644 --- a/drivers/pci/xen-pcifront.c +++ b/drivers/pci/xen-pcifront.c @@ -443,6 +443,33 @@ static int pcifront_scan_bus(struct pcifront_device *pdev, return 0; } +static struct pci_bus *pci_scan_root_bus(struct device *parent, int bus, + struct pci_ops *ops, void *sysdata, struct list_head *resources) +{ + struct pci_host_bridge *bridge; + int error; + + bridge = pci_alloc_host_bridge(0); + if (!bridge) + return NULL; + + list_splice_init(resources, &bridge->windows); + bridge->dev.parent = parent; + bridge->sysdata = sysdata; + bridge->busnr = bus; + bridge->ops = ops; + + error = pci_scan_root_bus_bridge(bridge); + if (error < 0) + goto err_out; + + return bridge->bus; + +err_out: + kfree(bridge); + return NULL; +} + static int pcifront_scan_root(struct pcifront_device *pdev, unsigned int domain, unsigned int bus) { diff --git a/include/linux/pci.h b/include/linux/pci.h index d77ce35a2b33..d226e06fb5e5 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -912,9 +912,6 @@ int pci_host_probe(struct pci_host_bridge *bridge); int pci_bus_insert_busn_res(struct pci_bus *b, int bus, int busmax); int pci_bus_update_busn_res_end(struct pci_bus *b, int busmax); void pci_bus_release_busn_res(struct pci_bus *b); -struct pci_bus *pci_scan_root_bus(struct device *parent, int bus, - struct pci_ops *ops, void *sysdata, - struct list_head *resources); int pci_scan_root_bus_bridge(struct pci_host_bridge *bridge); struct pci_bus *pci_add_new_bus(struct pci_bus *parent, struct pci_dev *dev, int busnr); From patchwork Fri Aug 17 10:26:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 958740 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arndb.de Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41sKD20dRmz9s3Z for ; Fri, 17 Aug 2018 20:28:18 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726664AbeHQNbK (ORCPT ); Fri, 17 Aug 2018 09:31:10 -0400 Received: from mout.kundenserver.de ([212.227.17.10]:59335 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727032AbeHQNab (ORCPT ); Fri, 17 Aug 2018 09:30:31 -0400 Received: from wuerfel.lan ([109.193.40.16]) by mrelayeu.kundenserver.de (mreue101 [212.227.15.145]) with ESMTPA (Nemesis) id 0MAdid-1fjhxn3cuR-00BsPO; Fri, 17 Aug 2018 12:27:16 +0200 From: Arnd Bergmann To: linux-pci@vger.kernel.org, Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, Christoph Hellwig , Lorenzo Pieralisi , Benjamin Herrenschmidt , linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, Arnd Bergmann Subject: [RFC 04/15] PCI: export pci_register_host_bridge Date: Fri, 17 Aug 2018 12:26:34 +0200 Message-Id: <20180817102645.3839621-5-arnd@arndb.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180817102645.3839621-1-arnd@arndb.de> References: <20180817102645.3839621-1-arnd@arndb.de> X-Provags-ID: V03:K1:qV+QiFpoLBNDT+pnsfxk7Q12Wr+Zfztf79RikKLfT1kBpbTwKUM iZEEf/AFkASGLvQTzHO6lI+OsNf423ev36D4uMlANybis7iSjomPpFGobYlMVXCwQdTCqSd ugZbMhW+33xetnzQSUdMeicQ786GrhuoT6iTK6eAwaMormNmf16uMK5AaJlveZ1uMEi0UOl d7rj/WjNLBnDisKLuP0zg== X-UI-Out-Filterresults: notjunk:1; V01:K0:6viyPx4Qb74=:ccCWwxVG4h9e67s1aeOEA5 DSD5frqpk3rf+CElY2taeu1iNYf0RDqjWPk1AQkQlRZIT8V6ygBWKhYW8+niK8SPrhzEefQoN MTAzJhGQjUG5mJz4neuPJrfWfvoRyWWno3raPfFD4IBjJzeE+wQ5wSD5PVhe19BsXlubY02g8 5MO+LdODz2tWxlOkI+FGaNMHD3AUyYbfeZFVfCVihpH50sWaTbfhg9dfHCMQlN3Ux8fH+iDcz CzK2NJmTJLXfvDYvkbuBwOQsXeMCOMgWI0S787/Hu3SxiX6sgA0WyOQsvPnufZss/8nagJgzF pmhXqG5ei/dM3MxDDeER5wKJlSfFLLZV9YBysTjF+RyUu0srfhAgAK/0VoLg/xLf8+W+ss8S6 cT6Eop6PKWq7TliAkzqtHUgUqQKfTg63eGJ+bxelz36NgAJhtrdwfjUrvcK8GvIo9n6ofst7f M+ZpnwtofMJalysbiNMd0/U5C+LZvQIDyhBnjN+ztTMX161kKMmQQRMGt9bU5zlGebSHJML9t uxwQ3exwP8EM1g/36YZc/Juqs5Obu3SVHVwOM1GmpgDg6RViN0CBJ9wm0T9fA1B4qvj9y5YX3 okKhgiwMMZCJUT1fjABTxHH38aHmgTpoprIuHZ9tZSVc1oJT/y7nNxmLlGE+AtLIOIUiyAUVu 8M9riaC7jjFCIl60jk8C9N1eE/iRsPX3qGaPVVog7/SbWPtLeyy25TBnk4ZFk760HgD0= Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org There are a couple of users of the old pci_create_root_bus() interface, which calls pci_register_host_bridge() without actually scanning the bus. In order to get those callers a little closer to the current method of separating the allocation and probing of the host bridge, this exports the internal interface to modules. If all the callers can get moved over to pci_host_probe() or pci_scan_root_bus_bridge() later, the export can be removed again. Signed-off-by: Arnd Bergmann --- drivers/pci/probe.c | 25 ++++++++++++++++++++++++- include/linux/pci.h | 1 + 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index cf169742c03e..5ca7d5941ad0 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -762,7 +762,29 @@ static void pci_set_bus_msi_domain(struct pci_bus *bus) dev_set_msi_domain(&bus->dev, d); } -static int pci_register_host_bridge(struct pci_host_bridge *bridge) +/* + * pci_register_host_bridge() - Register a host bridge without scanning + * + * @bridge: a newly allocated host bridge structure + * + * This is the core part of bringing up a new PCI host bridge, + * before we scan for attached devices and register them as + * pci_dev. + * + * For the most part, this is an implementation detail of the + * pci_host_probe() interface, which brings up the entire bus, + * bus some older platforms still call it directly and manually + * scan for devices. + * + * If your driver uses this, try to convert it to using + * pci_host_probe() instead. + * + * Return: zero on suggess, or a negative error code. + * Note: after pci_register_host_bridge() successfully returns, + * the pci_host_bridge device is alive in driver core, and must + * not be freed directly. + */ +int pci_register_host_bridge(struct pci_host_bridge *bridge) { struct device *parent = bridge->dev.parent; struct resource_entry *window, *n; @@ -877,6 +899,7 @@ static int pci_register_host_bridge(struct pci_host_bridge *bridge) kfree(bus); return err; } +EXPORT_SYMBOL_GPL(pci_register_host_bridge); static bool pci_bridge_child_ext_cfg_accessible(struct pci_dev *bridge) { diff --git a/include/linux/pci.h b/include/linux/pci.h index d226e06fb5e5..e1337148cf9f 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -909,6 +909,7 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus, struct pci_ops *ops, void *sysdata, struct list_head *resources); int pci_host_probe(struct pci_host_bridge *bridge); +int pci_register_host_bridge(struct pci_host_bridge *); int pci_bus_insert_busn_res(struct pci_bus *b, int bus, int busmax); int pci_bus_update_busn_res_end(struct pci_bus *b, int busmax); void pci_bus_release_busn_res(struct pci_bus *b); From patchwork Fri Aug 17 10:26:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 958739 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arndb.de Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41sKCx2TnDz9s4c for ; Fri, 17 Aug 2018 20:28:13 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726608AbeHQNax (ORCPT ); Fri, 17 Aug 2018 09:30:53 -0400 Received: from mout.kundenserver.de ([217.72.192.73]:48209 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727058AbeHQNac (ORCPT ); Fri, 17 Aug 2018 09:30:32 -0400 Received: from wuerfel.lan ([109.193.40.16]) by mrelayeu.kundenserver.de (mreue101 [212.227.15.145]) with ESMTPA (Nemesis) id 0M40t0-1g7af110mg-00rZtP; Fri, 17 Aug 2018 12:27:17 +0200 From: Arnd Bergmann To: linux-pci@vger.kernel.org, Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, Christoph Hellwig , Lorenzo Pieralisi , Benjamin Herrenschmidt , linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, Arnd Bergmann Subject: [RFC 05/15] PCI: move pci_create_root_bus into callers Date: Fri, 17 Aug 2018 12:26:35 +0200 Message-Id: <20180817102645.3839621-6-arnd@arndb.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180817102645.3839621-1-arnd@arndb.de> References: <20180817102645.3839621-1-arnd@arndb.de> X-Provags-ID: V03:K1:vNkQe7G80rrJcSh/6xIdR1XKwwCej6w5is+lloFStD924Tqfn0L yGVewaIh1+4Vgki1oP1wIOx6XkkD8GqaEGxmZE/7FaVmqAKP6giye+TP/hkfc6OKPffr61n BKj4FMOs1JjhhEoTVwABpSAUn4IGk9rSZ4N6mT4NrMHQ6maNd+haxnEQ2CqoGVIgcApxPg0 JhwKxIDMDp3jSLLSD7sug== X-UI-Out-Filterresults: notjunk:1; V01:K0:XHSfvXBRCKU=:r58iToc42PeA5q2a7Kt6oq 6VlaRcPJclx97z1Jv6s1RQc7jr29NLhEHSyFjQLdKbtVuTjqprA7cNjLMZoDdmcoTtQ4Jd3/p X2UGiWXAOL8bjI9Aw4JbLcTGFToUMDS6NZ2Fw5+xkVWVAGa7HtXLe48DCTi37wWrTviu8xsIF Won9k1ZcAlTV+3P/X7fdqbWSZYaFVOGVYk3qqZBwMLDHBwggFqHdNJlY8bcBK16BFyHsrxGtk FTw0zLa2JxW7wPKoWg6r2pWPMf+QVeo0TgoYchxwH+2/HEJonT/y81adZr4o29pAQaTTfZlIj TMNzdytb5wtfI8/0wp0GuDNgF6uw8oBDX6O4a3W9s7myMxk8e/xENDdRZ4r+/n+WsTjFo25wg oqltuqbiP5+Y6pWZMVuZ59/FSxAhZSF3gu5GBCtKRFCmduyhdFx6WI88coxOIgxZFLBJCFVfE SWKQOTUBZ8chFX2lO9l862T3zvMwuMno94GC5LJ4d++t+IeIvQmVDy4wWdWv1lbFqJBb6WCzn 0I8O0euMhPFqywJVhFDz3opUkBO9ZE4x2r4sQFp+i2Ywku/1L2PSk5tpnAEUyR5h01v6Zg/P9 hG0vfNQyOfjDgXZiku0to7vkxWcVUSpP/IPE30CLegGuaVIiwKw72RCBmHqvYe4CAXjM5qY9B GKxebiB7ng9TNi2dRfLqd2I0Io9btA2NgJBHrk4eccGwnwzm5ukK5KTUCXkpkHX90ybY= Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org There are only seven remaining callers of the old pci_scan_root_bus() interface. Since we want to expose the pci_host_bridge structure everywhere and discourage users from calling the old interfaces, let's move the implementation into the respective callsites. While this duplicates the source code, it makes the object code smaller for almost all users by avoiding the global implementation, and it allows further cleanup of the callers. Signed-off-by: Arnd Bergmann --- arch/powerpc/kernel/pci-common.c | 28 +++++++++++++++++++++++++++ arch/sparc/kernel/pci.c | 28 +++++++++++++++++++++++++++ drivers/acpi/pci_root.c | 30 ++++++++++++++++++++++++++++- drivers/parisc/dino.c | 28 +++++++++++++++++++++++++++ drivers/parisc/lba_pci.c | 28 +++++++++++++++++++++++++++ drivers/pci/controller/pci-hyperv.c | 28 +++++++++++++++++++++++++++ drivers/pci/controller/vmd.c | 30 ++++++++++++++++++++++++++++- drivers/pci/probe.c | 29 ---------------------------- include/linux/pci.h | 3 --- 9 files changed, 198 insertions(+), 34 deletions(-) diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c index 88e4f69a09e5..57ca621a32f4 100644 --- a/arch/powerpc/kernel/pci-common.c +++ b/arch/powerpc/kernel/pci-common.c @@ -1587,6 +1587,34 @@ struct device_node *pcibios_get_phb_of_node(struct pci_bus *bus) return of_node_get(hose->dn); } +static struct pci_bus *pci_create_root_bus(struct device *parent, int bus, + struct pci_ops *ops, void *sysdata, struct list_head *resources) +{ + int error; + struct pci_host_bridge *bridge; + + bridge = pci_alloc_host_bridge(0); + if (!bridge) + return NULL; + + bridge->dev.parent = parent; + + list_splice_init(resources, &bridge->windows); + bridge->sysdata = sysdata; + bridge->busnr = bus; + bridge->ops = ops; + + error = pci_register_host_bridge(bridge); + if (error < 0) + goto err_out; + + return bridge->bus; + +err_out: + kfree(bridge); + return NULL; +} + /** * pci_scan_phb - Given a pci_controller, setup and scan the PCI bus * @hose: Pointer to the PCI host controller instance structure diff --git a/arch/sparc/kernel/pci.c b/arch/sparc/kernel/pci.c index 17ea16a1337c..afbce59d9231 100644 --- a/arch/sparc/kernel/pci.c +++ b/arch/sparc/kernel/pci.c @@ -691,6 +691,34 @@ static void pci_claim_bus_resources(struct pci_bus *bus) pci_claim_bus_resources(child_bus); } +static struct pci_bus *pci_create_root_bus(struct device *parent, int bus, + struct pci_ops *ops, void *sysdata, struct list_head *resources) +{ + int error; + struct pci_host_bridge *bridge; + + bridge = pci_alloc_host_bridge(0); + if (!bridge) + return NULL; + + bridge->dev.parent = parent; + + list_splice_init(resources, &bridge->windows); + bridge->sysdata = sysdata; + bridge->busnr = bus; + bridge->ops = ops; + + error = pci_register_host_bridge(bridge); + if (error < 0) + goto err_out; + + return bridge->bus; + +err_out: + kfree(bridge); + return NULL; +} + struct pci_bus *pci_scan_one_pbm(struct pci_pbm_info *pbm, struct device *parent) { diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c index 7433035ded95..85dbcf47015b 100644 --- a/drivers/acpi/pci_root.c +++ b/drivers/acpi/pci_root.c @@ -873,6 +873,34 @@ static void acpi_pci_root_release_info(struct pci_host_bridge *bridge) __acpi_pci_root_release_info(bridge->release_data); } +static struct pci_bus *acpi_pci_create_root_bus(struct device *parent, int bus, + struct pci_ops *ops, void *sysdata, struct list_head *resources) +{ + int error; + struct pci_host_bridge *bridge; + + bridge = pci_alloc_host_bridge(0); + if (!bridge) + return NULL; + + bridge->dev.parent = parent; + + list_splice_init(resources, &bridge->windows); + bridge->sysdata = sysdata; + bridge->busnr = bus; + bridge->ops = ops; + + error = pci_register_host_bridge(bridge); + if (error < 0) + goto err_out; + + return bridge->bus; + +err_out: + kfree(bridge); + return NULL; +} + struct pci_bus *acpi_pci_root_create(struct acpi_pci_root *root, struct acpi_pci_root_ops *ops, struct acpi_pci_root_info *info, @@ -902,7 +930,7 @@ struct pci_bus *acpi_pci_root_create(struct acpi_pci_root *root, pci_acpi_root_add_resources(info); pci_add_resource(&info->resources, &root->secondary); - bus = pci_create_root_bus(NULL, busnum, ops->pci_ops, + bus = acpi_pci_create_root_bus(NULL, busnum, ops->pci_ops, sysdata, &info->resources); if (!bus) goto out_release_info; diff --git a/drivers/parisc/dino.c b/drivers/parisc/dino.c index 7390fb8ca9d1..91c837de7616 100644 --- a/drivers/parisc/dino.c +++ b/drivers/parisc/dino.c @@ -882,6 +882,34 @@ static const char *cujo_vers[] = { void ccio_cujo20_fixup(struct parisc_device *dev, u32 iovp); +static struct pci_bus *pci_create_root_bus(struct device *parent, int bus, + struct pci_ops *ops, void *sysdata, struct list_head *resources) +{ + int error; + struct pci_host_bridge *bridge; + + bridge = pci_alloc_host_bridge(0); + if (!bridge) + return NULL; + + bridge->dev.parent = parent; + + list_splice_init(resources, &bridge->windows); + bridge->sysdata = sysdata; + bridge->busnr = bus; + bridge->ops = ops; + + error = pci_register_host_bridge(bridge); + if (error < 0) + goto err_out; + + return bridge->bus; + +err_out: + kfree(bridge); + return NULL; +} + /* ** Determine if dino should claim this chip (return 0) or not (return 1). ** If so, initialize the chip appropriately (card-mode vs bridge mode). diff --git a/drivers/parisc/lba_pci.c b/drivers/parisc/lba_pci.c index 69bd98421eb1..901b7f07fe91 100644 --- a/drivers/parisc/lba_pci.c +++ b/drivers/parisc/lba_pci.c @@ -1464,6 +1464,34 @@ lba_hw_init(struct lba_device *d) */ static unsigned int lba_next_bus = 0; +static struct pci_bus *pci_create_root_bus(struct device *parent, int bus, + struct pci_ops *ops, void *sysdata, struct list_head *resources) +{ + int error; + struct pci_host_bridge *bridge; + + bridge = pci_alloc_host_bridge(0); + if (!bridge) + return NULL; + + bridge->dev.parent = parent; + + list_splice_init(resources, &bridge->windows); + bridge->sysdata = sysdata; + bridge->busnr = bus; + bridge->ops = ops; + + error = pci_register_host_bridge(bridge); + if (error < 0) + goto err_out; + + return bridge->bus; + +err_out: + kfree(bridge); + return NULL; +} + /* * Determine if lba should claim this chip (return 0) or not (return 1). * If so, initialize the chip and tell other partners in crime they diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index c00f82cc54aa..df7cddea8e30 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -1457,6 +1457,34 @@ static void prepopulate_bars(struct hv_pcibus_device *hbus) spin_unlock_irqrestore(&hbus->device_list_lock, flags); } +static struct pci_bus *pci_create_root_bus(struct device *parent, int bus, + struct pci_ops *ops, void *sysdata, struct list_head *resources) +{ + int error; + struct pci_host_bridge *bridge; + + bridge = pci_alloc_host_bridge(0); + if (!bridge) + return NULL; + + bridge->dev.parent = parent; + + list_splice_init(resources, &bridge->windows); + bridge->sysdata = sysdata; + bridge->busnr = bus; + bridge->ops = ops; + + error = pci_register_host_bridge(bridge); + if (error < 0) + goto err_out; + + return bridge->bus; + +err_out: + kfree(bridge); + return NULL; +} + /** * create_root_hv_pci_bus() - Expose a new root PCI bus * @hbus: Root PCI bus, as understood by this driver diff --git a/drivers/pci/controller/vmd.c b/drivers/pci/controller/vmd.c index fd2dbd7eed7b..311c9f6761ae 100644 --- a/drivers/pci/controller/vmd.c +++ b/drivers/pci/controller/vmd.c @@ -579,6 +579,34 @@ static int vmd_find_free_domain(void) return domain + 1; } +static struct pci_bus *vmd_create_root_bus(struct device *parent, int bus, + struct pci_ops *ops, void *sysdata, struct list_head *resources) +{ + int error; + struct pci_host_bridge *bridge; + + bridge = pci_alloc_host_bridge(0); + if (!bridge) + return NULL; + + bridge->dev.parent = parent; + + list_splice_init(resources, &bridge->windows); + bridge->sysdata = sysdata; + bridge->busnr = bus; + bridge->ops = ops; + + error = pci_register_host_bridge(bridge); + if (error < 0) + goto err_out; + + return bridge->bus; + +err_out: + kfree(bridge); + return NULL; +} + static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features) { struct pci_sysdata *sd = &vmd->sysdata; @@ -705,7 +733,7 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features) pci_add_resource_offset(&resources, &vmd->resources[1], offset[0]); pci_add_resource_offset(&resources, &vmd->resources[2], offset[1]); - vmd->bus = pci_create_root_bus(&vmd->dev->dev, busn_start, &vmd_ops, + vmd->bus = vmd_create_root_bus(&vmd->dev->dev, busn_start, &vmd_ops, sd, &resources); if (!vmd->bus) { pci_free_resource_list(&resources); diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 5ca7d5941ad0..eaedb4fe143a 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -2909,35 +2909,6 @@ void __weak pcibios_remove_bus(struct pci_bus *bus) { } -struct pci_bus *pci_create_root_bus(struct device *parent, int bus, - struct pci_ops *ops, void *sysdata, struct list_head *resources) -{ - int error; - struct pci_host_bridge *bridge; - - bridge = pci_alloc_host_bridge(0); - if (!bridge) - return NULL; - - bridge->dev.parent = parent; - - list_splice_init(resources, &bridge->windows); - bridge->sysdata = sysdata; - bridge->busnr = bus; - bridge->ops = ops; - - error = pci_register_host_bridge(bridge); - if (error < 0) - goto err_out; - - return bridge->bus; - -err_out: - kfree(bridge); - return NULL; -} -EXPORT_SYMBOL_GPL(pci_create_root_bus); - int pci_host_probe(struct pci_host_bridge *bridge) { struct pci_bus *bus, *child; diff --git a/include/linux/pci.h b/include/linux/pci.h index e1337148cf9f..1dd8a3ecf753 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -905,9 +905,6 @@ void pcibios_bus_to_resource(struct pci_bus *bus, struct resource *res, void pcibios_scan_specific_bus(int busn); struct pci_bus *pci_find_bus(int domain, int busnr); void pci_bus_add_devices(const struct pci_bus *bus); -struct pci_bus *pci_create_root_bus(struct device *parent, int bus, - struct pci_ops *ops, void *sysdata, - struct list_head *resources); int pci_host_probe(struct pci_host_bridge *bridge); int pci_register_host_bridge(struct pci_host_bridge *); int pci_bus_insert_busn_res(struct pci_bus *b, int bus, int busmax); From patchwork Fri Aug 17 10:26:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 958742 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arndb.de Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41sKFj6pKxz9s4c for ; Fri, 17 Aug 2018 20:29:45 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726497AbeHQNcd (ORCPT ); Fri, 17 Aug 2018 09:32:33 -0400 Received: from mout.kundenserver.de ([217.72.192.75]:55085 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726226AbeHQNcc (ORCPT ); Fri, 17 Aug 2018 09:32:32 -0400 Received: from wuerfel.lan ([109.193.40.16]) by mrelayeu.kundenserver.de (mreue101 [212.227.15.145]) with ESMTPA (Nemesis) id 0LvSJX-1fz1xG2f1H-010giE; Fri, 17 Aug 2018 12:27:17 +0200 From: Arnd Bergmann To: linux-pci@vger.kernel.org, Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, Christoph Hellwig , Lorenzo Pieralisi , Benjamin Herrenschmidt , linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, Arnd Bergmann Subject: [RFC 06/15] powerpc/pci: fold pci_create_root_bus into pcibios_scan_phb Date: Fri, 17 Aug 2018 12:26:36 +0200 Message-Id: <20180817102645.3839621-7-arnd@arndb.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180817102645.3839621-1-arnd@arndb.de> References: <20180817102645.3839621-1-arnd@arndb.de> X-Provags-ID: V03:K1:GixNoySXnYxESLRg71MMIUbdbc//wFh3XcXU1/rjlBZzggqeBtp KPW4mj1HSwQZQBdmqQg5+/P2JSkT5CbRoRegXb4oiClTKfDQh+QKkW5IWPmMGJO014pWS9j rUlg1LOuTJCptgf5uWmttL2Kdz0uSl83sfIu0nv6TbSYcbgDSSGxso8c+NkJc0Hlzvd+op6 I+pz8368UQ08r7uDZiDbw== X-UI-Out-Filterresults: notjunk:1; V01:K0:C2dcC/uIStM=:3Ei2a6aC1/jz/fC6EZFUqw QSvyA2LDGlBHcM8akYCfcsVYAUX9Sn93QVKdDUwUaIjZellX6+Jp08+YoKJ42rZueKfDM8cI2 tdSn7be0cCWBSvAzSDIf3xptp63SGM3UnqcA+eKUfGB14qShFIioNxoGmxuSIa8COAZ+EQb5i E0rHSOoF4RwGk3rOK7VIrz+CtN/TkS13drpbZ1SPK3/aA8JsxLxpaoOp0k6AyTyvDl4KSvKco niiqoWZgL+tQGo9msu0Bwn5FsvgShgOHtZgCgZyKHS3xxzgdEaHZ12WfSziBXQtL2Rvagu1nt 1uzeG9KTgRTMXRjGVHUz3qb6a1PFAxzpUa+dXsUge04dss81ZGpKdNlgzQtoU9Y9/7x24RhsF gDHCBftvOgWxzt/CB0XfsYa/1T2XXoMrEPo60+ctxFFsuzj9Kxkwm1hHaxB9RDjoxvM/qI5hN H702qoml66LVdN8BwvZ2Xxadpq1kfgX3Ek61O9sXCtG8+566F+6hSBca3MOYK4AFD2/1Udli3 JiSNWzt9W0B+4GJ0LnWMxL8u0Rcs9V7BfNODINGNavNtMCB88UzaVBtXx4ccTs0Ne9KlHGixU E3uNjsM9wfOEAiSRYnoGgBGhomF68lw7y7k2g6H7owOaYcPkCS45r5zKAyFPFzGo03HW4zd0K VhnsBhPwJwpyt920c4dup7565tuAwVDIGRIuKedk+ndktXMirehAC/jTBYLdiIGEcXRI= Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org This slightly simplifies the pcibios_scan_phb() implementation, and gives us an easier point to add further fields in the pci_host_bridge structure. I tried removing fields that are duplicated between pci_host_bridge and pci_controller (which really serve the same purpose), but ran into the problem that we can't call pci_alloc_host_bridge() as early as pcibios_alloc_controller(). Some more refactoring is needed for that, but it could noticably clean the powerpc code up more. Signed-off-by: Arnd Bergmann --- arch/powerpc/include/asm/pci-bridge.h | 3 ++ arch/powerpc/kernel/pci-common.c | 72 ++++++++++----------------- 2 files changed, 30 insertions(+), 45 deletions(-) diff --git a/arch/powerpc/include/asm/pci-bridge.h b/arch/powerpc/include/asm/pci-bridge.h index 94d449031b18..42ae567084d9 100644 --- a/arch/powerpc/include/asm/pci-bridge.h +++ b/arch/powerpc/include/asm/pci-bridge.h @@ -51,8 +51,11 @@ struct pci_controller_ops { /* * Structure of a PCI controller (host bridge) + * Some members here are duplicated in struct pci_host_bridge + * and should be moved there. */ struct pci_controller { + struct pci_host_bridge *bridge; struct pci_bus *bus; char is_dynamic; #ifdef CONFIG_PPC64 diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c index 57ca621a32f4..096011ec8670 100644 --- a/arch/powerpc/kernel/pci-common.c +++ b/arch/powerpc/kernel/pci-common.c @@ -1587,81 +1587,63 @@ struct device_node *pcibios_get_phb_of_node(struct pci_bus *bus) return of_node_get(hose->dn); } -static struct pci_bus *pci_create_root_bus(struct device *parent, int bus, - struct pci_ops *ops, void *sysdata, struct list_head *resources) -{ - int error; - struct pci_host_bridge *bridge; - - bridge = pci_alloc_host_bridge(0); - if (!bridge) - return NULL; - - bridge->dev.parent = parent; - - list_splice_init(resources, &bridge->windows); - bridge->sysdata = sysdata; - bridge->busnr = bus; - bridge->ops = ops; - - error = pci_register_host_bridge(bridge); - if (error < 0) - goto err_out; - - return bridge->bus; - -err_out: - kfree(bridge); - return NULL; -} - /** * pci_scan_phb - Given a pci_controller, setup and scan the PCI bus * @hose: Pointer to the PCI host controller instance structure */ void pcibios_scan_phb(struct pci_controller *hose) { - LIST_HEAD(resources); - struct pci_bus *bus; struct device_node *node = hose->dn; int mode; + struct pci_host_bridge *bridge; + int error; pr_debug("PCI: Scanning PHB %pOF\n", node); + /* The allocation should ideally be done in pcibios_alloc_controller(), + * but pci_alloc_host_bridge() requires slab to work first */ + bridge = pci_alloc_host_bridge(0); + if (!bridge) + return; + /* Get some IO space for the new PHB */ pcibios_setup_phb_io_space(hose); /* Wire up PHB bus resources */ - pcibios_setup_phb_resources(hose, &resources); + pcibios_setup_phb_resources(hose, &bridge->windows); hose->busn.start = hose->first_busno; hose->busn.end = hose->last_busno; hose->busn.flags = IORESOURCE_BUS; - pci_add_resource(&resources, &hose->busn); + pci_add_resource(&bridge->windows, &hose->busn); + + bridge->dev.parent = hose->parent; + bridge->sysdata = hose; + bridge->busnr = hose->first_busno; + bridge->ops = hose->ops; - /* Create an empty bus for the toplevel */ - bus = pci_create_root_bus(hose->parent, hose->first_busno, - hose->ops, hose, &resources); - if (bus == NULL) { + error = pci_register_host_bridge(bridge); + if (error < 0) { pr_err("Failed to create bus for PCI domain %04x\n", hose->global_number); - pci_free_resource_list(&resources); + pci_free_host_bridge(bridge); return; } - hose->bus = bus; + hose->bridge = bridge; + hose->bus = bridge->bus; /* Get probe mode and perform scan */ mode = PCI_PROBE_NORMAL; if (node && hose->controller_ops.probe_mode) - mode = hose->controller_ops.probe_mode(bus); + mode = hose->controller_ops.probe_mode(bridge->bus); pr_debug(" probe mode: %d\n", mode); if (mode == PCI_PROBE_DEVTREE) - of_scan_bus(node, bus); + of_scan_bus(node, bridge->bus); if (mode == PCI_PROBE_NORMAL) { - pci_bus_update_busn_res_end(bus, 255); - hose->last_busno = pci_scan_child_bus(bus); - pci_bus_update_busn_res_end(bus, hose->last_busno); + pci_bus_update_busn_res_end(bridge->bus, 255); + hose->last_busno = pci_scan_child_bus(bridge->bus); + pci_bus_update_busn_res_end(bridge->bus, hose->last_busno); } /* Platform gets a chance to do some global fixups before @@ -1671,9 +1653,9 @@ void pcibios_scan_phb(struct pci_controller *hose) ppc_md.pcibios_fixup_phb(hose); /* Configure PCI Express settings */ - if (bus && !pci_has_flag(PCI_PROBE_ONLY)) { + if (bridge->bus && !pci_has_flag(PCI_PROBE_ONLY)) { struct pci_bus *child; - list_for_each_entry(child, &bus->children, node) + list_for_each_entry(child, &bridge->bus->children, node) pcie_bus_configure_settings(child); } } From patchwork Fri Aug 17 10:26:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 958747 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arndb.de Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41sKKn4kfmz9s3Z for ; Fri, 17 Aug 2018 20:33:17 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726800AbeHQNfe (ORCPT ); Fri, 17 Aug 2018 09:35:34 -0400 Received: from mout.kundenserver.de ([212.227.17.10]:32981 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726760AbeHQNfd (ORCPT ); Fri, 17 Aug 2018 09:35:33 -0400 Received: from wuerfel.lan ([109.193.40.16]) by mrelayeu.kundenserver.de (mreue101 [212.227.15.145]) with ESMTPA (Nemesis) id 0M7Knm-1g271607FO-00x44h; Fri, 17 Aug 2018 12:27:18 +0200 From: Arnd Bergmann To: linux-pci@vger.kernel.org, Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, Christoph Hellwig , Lorenzo Pieralisi , Benjamin Herrenschmidt , linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, Arnd Bergmann Subject: [RFC 07/15] PCI/ACPI: clean up acpi_pci_root_create() Date: Fri, 17 Aug 2018 12:26:37 +0200 Message-Id: <20180817102645.3839621-8-arnd@arndb.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180817102645.3839621-1-arnd@arndb.de> References: <20180817102645.3839621-1-arnd@arndb.de> X-Provags-ID: V03:K1:d27yj6uZ03Y8vFzVtfOG4i3FXwc0amjneq2jCzS3uuPksZ77MJw z4AgJqMZ+dms4uVm3++DD8efqm6WoDdC/G6wfOryIsOV1RJ2ZY4ekevcPFE7ZTFqkpdKzEv v8GV2slLum4Zw9yyUZDD4tFjdvfudOKVLZwMAK0sYh5leF4mXZD6qcPYHNKEZHtlwNRN1V2 bRQa6vslOKqjMiXp7VGJw== X-UI-Out-Filterresults: notjunk:1; V01:K0:dQxK7tItEl4=:M58Fmg5hzmIJtGAnJoWRiX lolFQgFa9Bv2Jzomd8ZcKQFhSRZvChrCKG6kMN4eONirFrjiQvLDtv1Xquv0p8/2VpgFiYgcE vCu0/uhbhORMSrGBxJBz9GEKFGYSXOMJHltVdDKPNhxY/pu0C1LrOxCbpRECgS930TbBXtL3g ZO6yChgg5Oj7V4bNhSRjm6LPDmhje4+qCpygbu1ZUEfXWdmc/g5kxL7LCFKZYvr4PJ9Tl6ary FVjhbbXqR3+3VP8ljQ3GY/od8tVN3WyDLhrEU1OPf6mgcaKFbd8oKlTUxlCC8TBCyptLH6Qdm BdOqGgMxGLALN3gKh5ptAWLsfsKYDQsEb75eovdwMEarGTjHUzi94I4LG5tK/b9sexHFELK50 vhN7zaEakHOQlz1Q60WzTb8GplZ+TCR3FflwWKesT2kQ/RInMyyYAHcxQfUUnEAqth6SNIQCb v2Bm0ntVXggdTjsRQ0yMwMuZh287Is44XfttsP7ELxU92jaLQEzRvJgGG45O4xlS1PIpAnsZg 95t2v0gEe2eV60wSpm/mNwHz6hOzcxtNNz2ZGWUo0oOtOioq11nuxSeMHPiVaY1F80O0nHt/t 781UwKEK/tkhs7/WF94ZbLmsgRr346WW+W+KuloOyzmNrgg8GiiWHdNrJyF9nXNGFLfglJV78 eG562zDwpU6+HVPCDRIUAwzjUeH2gxhKMehascMDaXSFSPjKao20exZi9lZwJqyb4tiM= Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The acpi_pci_create_root_bus() can be fully integrated into acpi_pci_root_create(), improving a few things: * We can call pci_scan_root_bus_bridge(), which registers and scans the bridge in one step. * After a failure in pci_register_host_bridge(), we correctly clean up the resources. * The bridge settings (release function, flags, operations etc) can get set up before registering the bridge. * Further cleanup would be possible, removing duplication between pci_host_bridge and some ACPI structures. Signed-off-by: Arnd Bergmann --- drivers/acpi/pci_root.c | 68 +++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 44 deletions(-) diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c index 85dbcf47015b..5f73de3b67c8 100644 --- a/drivers/acpi/pci_root.c +++ b/drivers/acpi/pci_root.c @@ -873,34 +873,6 @@ static void acpi_pci_root_release_info(struct pci_host_bridge *bridge) __acpi_pci_root_release_info(bridge->release_data); } -static struct pci_bus *acpi_pci_create_root_bus(struct device *parent, int bus, - struct pci_ops *ops, void *sysdata, struct list_head *resources) -{ - int error; - struct pci_host_bridge *bridge; - - bridge = pci_alloc_host_bridge(0); - if (!bridge) - return NULL; - - bridge->dev.parent = parent; - - list_splice_init(resources, &bridge->windows); - bridge->sysdata = sysdata; - bridge->busnr = bus; - bridge->ops = ops; - - error = pci_register_host_bridge(bridge); - if (error < 0) - goto err_out; - - return bridge->bus; - -err_out: - kfree(bridge); - return NULL; -} - struct pci_bus *acpi_pci_root_create(struct acpi_pci_root *root, struct acpi_pci_root_ops *ops, struct acpi_pci_root_info *info, @@ -909,8 +881,7 @@ struct pci_bus *acpi_pci_root_create(struct acpi_pci_root *root, int ret, busnum = root->secondary.start; struct acpi_device *device = root->device; int node = acpi_get_node(device->handle); - struct pci_bus *bus; - struct pci_host_bridge *host_bridge; + struct pci_host_bridge *bridge; info->root = root; info->bridge = device; @@ -930,30 +901,39 @@ struct pci_bus *acpi_pci_root_create(struct acpi_pci_root *root, pci_acpi_root_add_resources(info); pci_add_resource(&info->resources, &root->secondary); - bus = acpi_pci_create_root_bus(NULL, busnum, ops->pci_ops, - sysdata, &info->resources); - if (!bus) + + bridge = pci_alloc_host_bridge(0); + if (!bridge) goto out_release_info; - host_bridge = to_pci_host_bridge(bus->bridge); + list_splice_init(&info->resources, &bridge->windows); + bridge->sysdata = sysdata; + bridge->busnr = busnum; + bridge->ops = ops->pci_ops; + pci_set_host_bridge_release(bridge, acpi_pci_root_release_info, + info); + if (!(root->osc_control_set & OSC_PCI_EXPRESS_NATIVE_HP_CONTROL)) - host_bridge->native_pcie_hotplug = 0; + bridge->native_pcie_hotplug = 0; if (!(root->osc_control_set & OSC_PCI_SHPC_NATIVE_HP_CONTROL)) - host_bridge->native_shpc_hotplug = 0; + bridge->native_shpc_hotplug = 0; if (!(root->osc_control_set & OSC_PCI_EXPRESS_AER_CONTROL)) - host_bridge->native_aer = 0; + bridge->native_aer = 0; if (!(root->osc_control_set & OSC_PCI_EXPRESS_PME_CONTROL)) - host_bridge->native_pme = 0; + bridge->native_pme = 0; if (!(root->osc_control_set & OSC_PCI_EXPRESS_LTR_CONTROL)) - host_bridge->native_ltr = 0; + bridge->native_ltr = 0; + + ret = pci_scan_root_bus_bridge(bridge); + if (ret < 0) + goto out_release_bridge; - pci_scan_child_bus(bus); - pci_set_host_bridge_release(host_bridge, acpi_pci_root_release_info, - info); if (node != NUMA_NO_NODE) - dev_printk(KERN_DEBUG, &bus->dev, "on NUMA node %d\n", node); - return bus; + dev_printk(KERN_DEBUG, &bridge->bus->dev, "on NUMA node %d\n", node); + return bridge->bus; +out_release_bridge: + pci_free_host_bridge(bridge); out_release_info: __acpi_pci_root_release_info(info); return NULL; From patchwork Fri Aug 17 10:26:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 958749 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arndb.de Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41sKKx44Jtz9s3x for ; Fri, 17 Aug 2018 20:33:25 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726218AbeHQNfb (ORCPT ); Fri, 17 Aug 2018 09:35:31 -0400 Received: from mout.kundenserver.de ([212.227.17.24]:52961 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725845AbeHQNfb (ORCPT ); Fri, 17 Aug 2018 09:35:31 -0400 Received: from wuerfel.lan ([109.193.40.16]) by mrelayeu.kundenserver.de (mreue101 [212.227.15.145]) with ESMTPA (Nemesis) id 0LgHVU-1gBMPa1mGS-00ngPB; Fri, 17 Aug 2018 12:27:18 +0200 From: Arnd Bergmann To: linux-pci@vger.kernel.org, Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, Christoph Hellwig , Lorenzo Pieralisi , Benjamin Herrenschmidt , linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, Arnd Bergmann Subject: [RFC 08/15] x86: PCI: clean up pcibios_scan_root() Date: Fri, 17 Aug 2018 12:26:38 +0200 Message-Id: <20180817102645.3839621-9-arnd@arndb.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180817102645.3839621-1-arnd@arndb.de> References: <20180817102645.3839621-1-arnd@arndb.de> X-Provags-ID: V03:K1:tlcedIIbu3wiz3zsxlYn2+G+v0etxI3PP6TAmZreLsijFeYR04M h/VODDtc+5SUwz1uyxw71Eq8VwF/rrPeX4Mi73yyRzW86zhOmQypatEJjTmy5UJ8/VTs3si Or6SucrdTdcrzJKrTR3QI43wWqbF1ZN69gr+AUCaoNRbF51vgqmBAbIdS99XUNw57/qq4KP 6/LoQH+SxPzNn6+AMM4rg== X-UI-Out-Filterresults: notjunk:1; V01:K0:weQ6RTKTUsY=:XbEL7s+SkjRfvaO/OBnUBt ht0iALf7RLwZ+Pg4PqsRtLWIZH4P1cYoeJV2Ihh0UQD1qouQ1J3OdYGV47+3L395N4n9voRlw IH4kXgIGHDHCQojbrS3ViJndFx6PJGDA8jk0NkZUSTLdBLzcbHAXrOjmUbSx6xv3rPr1Y86YB OJXCDPtboW5sf4qcQm0weWm/5Knr32PPYh5RgJrZ96UyNL/oNUnxMttcHcBswPlYdETa8AAXh jikLLMG11oGfgI10VBT2eShT/ILBVvB+eQSbge2txFONEJ66ESQjUnT38uBXBC4XvkO3kd+zl k+bscHpGd3QyNeWxs8XZyzPmhNKsXNjOdqUU+7yfMAp0UgSwH7Fn/a9JkbkN21WNBAOLUx6lE u+g4OrVQFBzvcwkmwHY4WKdpYQv3pKzYkKDCNmHQptwy7ynQkXmd2n5dq9hyDTsnkE63eTbWG zCHFSRlEIpUfEdU/YuNCSJJIFcyGYt08H+qwfW9+OxsHZo5qCQSOEqq47OtnyIJANhMhiD+pP YeLmH89ATYf2Ug1E9TPiz3qcV3UGNuP3s3iW7iJjJChA5hN+Hg52TgED0fTWiH/i+nPQ8oUde eSO38j3Y3kkOt93/38VBYsVKkPRXM0J5QLiplQndvAB9Xr3l9hshp9Dopw2tthNxH4X3CDbPP jXxyPaG7Fw9HHSQZMuplcmXPAS09LGPqYRYwgkvq7V313AabwV/yRxpFa3DBpIdTwt+U= Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org pcibios_scan_root() is now just a wrapper around pci_scan_root_bus(), and merging the two into one makes it shorter and more readable. We can also take advantage of pci_alloc_host_bridge() doing the allocation of the sysdata for us, which helps if we ever want to allow hot-unplugging the host bridge itself. We might be able to simplify it further using pci_host_probe(), but I wasn't sure about the resource registration there. Signed-off-by: Arnd Bergmann --- arch/x86/pci/common.c | 53 ++++++++++++++----------------------------- 1 file changed, 17 insertions(+), 36 deletions(-) diff --git a/arch/x86/pci/common.c b/arch/x86/pci/common.c index e740d9aa4024..920d0885434c 100644 --- a/arch/x86/pci/common.c +++ b/arch/x86/pci/common.c @@ -453,54 +453,35 @@ void __init dmi_check_pciprobe(void) dmi_check_system(pciprobe_dmi_table); } -static struct pci_bus *pci_scan_root_bus(struct device *parent, int bus, - struct pci_ops *ops, void *sysdata, struct list_head *resources) +void pcibios_scan_root(int busnum) { + struct pci_sysdata *sd; struct pci_host_bridge *bridge; int error; - bridge = pci_alloc_host_bridge(0); - if (!bridge) - return NULL; + bridge = pci_alloc_host_bridge(sizeof(sd)); + if (!bridge) { + printk(KERN_ERR "PCI: OOM, skipping PCI bus %02x\n", busnum); + return; + } + sd = pci_host_bridge_priv(bridge); - list_splice_init(resources, &bridge->windows); - bridge->dev.parent = parent; - bridge->sysdata = sysdata; - bridge->busnr = bus; - bridge->ops = ops; + sd->node = x86_pci_root_bus_node(busnum); + x86_pci_root_bus_resources(busnum, &bridge->windows); + bridge->sysdata = sd; + bridge->busnr = busnum; + bridge->ops = &pci_root_ops; + printk(KERN_DEBUG "PCI: Probing PCI hardware (bus %02x)\n", busnum); error = pci_scan_root_bus_bridge(bridge); if (error < 0) goto err_out; - return bridge->bus; + pci_bus_add_devices(bridge->bus); + return; err_out: - kfree(bridge); - return NULL; -} - -void pcibios_scan_root(int busnum) -{ - struct pci_bus *bus; - struct pci_sysdata *sd; - LIST_HEAD(resources); - - sd = kzalloc(sizeof(*sd), GFP_KERNEL); - if (!sd) { - printk(KERN_ERR "PCI: OOM, skipping PCI bus %02x\n", busnum); - return; - } - sd->node = x86_pci_root_bus_node(busnum); - x86_pci_root_bus_resources(busnum, &resources); - printk(KERN_DEBUG "PCI: Probing PCI hardware (bus %02x)\n", busnum); - bus = pci_scan_root_bus(NULL, busnum, &pci_root_ops, sd, &resources); - if (!bus) { - pci_free_resource_list(&resources); - kfree(sd); - return; - } - pci_bus_add_devices(bus); + pci_free_host_bridge(bridge); } void __init pcibios_set_cache_line_size(void) From patchwork Fri Aug 17 10:26:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 958738 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arndb.de Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41sKCw1Mfyz9s3Z for ; Fri, 17 Aug 2018 20:28:12 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726760AbeHQNax (ORCPT ); Fri, 17 Aug 2018 09:30:53 -0400 Received: from mout.kundenserver.de ([212.227.17.10]:44097 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727119AbeHQNac (ORCPT ); Fri, 17 Aug 2018 09:30:32 -0400 Received: from wuerfel.lan ([109.193.40.16]) by mrelayeu.kundenserver.de (mreue101 [212.227.15.145]) with ESMTPA (Nemesis) id 0LfAVs-1gEfGg3Ql6-00olnh; Fri, 17 Aug 2018 12:27:18 +0200 From: Arnd Bergmann To: linux-pci@vger.kernel.org, Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, Christoph Hellwig , Lorenzo Pieralisi , Benjamin Herrenschmidt , linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, Arnd Bergmann Subject: [RFC 09/15] PCI: xenfront: clean up pcifront_scan_root() Date: Fri, 17 Aug 2018 12:26:39 +0200 Message-Id: <20180817102645.3839621-10-arnd@arndb.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180817102645.3839621-1-arnd@arndb.de> References: <20180817102645.3839621-1-arnd@arndb.de> X-Provags-ID: V03:K1:imp36udsrO2nyS8JPjqHA5Ds3hFhxVLPHpRGVSWPBGXVbL9/rNV imiE1c81Sfttwp+bT8f8tuK+epvIVP0/tH2n09iCfqvqjLRLlFBwdbr6U+nTVjL+eKbRy82 /29LhtzYPzABNffKaggHUp+zeicohWvtT/S8mD+XO+rHW/DejrjMQq9cGaJyd1HBBEumpqw plfhY45irAx+gsxE+znig== X-UI-Out-Filterresults: notjunk:1; V01:K0:FL2ZqB/032s=:1A5r01tQmTrILHRXQDy23a KFl3ApCPT8sFp2nlafvObwMRHbliIqVL2rMDndnA07kCYvYEizbMGt3o0wJZAFdpNz3kS7ln6 doQt8lxk5AjbiyNPeSPVypLaLKBL+9ecrGYPefgriCFVt9Ddh617MIlRnTb/RM4FjvZzpdzk2 aW8MbQIuJtfC+B2Q15BroI+/75njcF7WXHu6vf9kZu1mYXNPAoq4nS/qN+BBq1q10kF/qZiSB 4ElYO57rst6Jvl7XlbRKy1D9O+uqCHLl1NiZZeWHGuAh7LvkLCBB6sQL1mgERYY1HPInoadrM NaNGhb6gpNJAaJ+aOhqBqZTwSEz905wppbKg8my0ZgosbExtpjhGJBpDrImOpXkrw9Sb85cZT PhYnGbAjh+HxCXfyWW8G3raZzukxI7xGnFVlaaxLXgYduuV7CMu/Qll6tQQCQIGokEipROWKF Zk9BsAVXb5wdT7saIcAAplUs0nccZd6gYsyLcEnHSur1Z6OIsevthXjOvaReUUF1XggWq4Ze/ Q4LljBdzAVS14y6HHjFLmP7+dsqXO6uLSPiicMrc/2jS+mzp4QV3fFuzubU2V1pV+mVeG8DxR iPsP7lfV+geEoBhHreBzfk9KOHzn00fI60UbvvvOEj6R0j3U5WLp2DZV58EHejQqaTxd40NGA nLme5S/oqqT7vNaz8ku8EyO+SZ1KgTzYgkvH3VlEQQaBAxuKnuzI9PXk/u92Ay6Ic9vw= Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Merging pci_scan_root_bus() into pcifront_scan_root() simplifies the implementation and makes it more readable. We can allocate the pcifront_sd structure along with the bridge structure, which helps manage its lifetime rules so we don't free it before the device has been released. There are two small issues that I noticed that could be improved: - It seems we unregister the 'bus' device that is a child of the 'pci_host_bridge' device after we unregister its parent in pcifront_free_roots(), which seems odd. - We probably don't need an extra pci_bus_entry list at all, but could instead walk the children of the pcifront_device, which are all pci_host_bridge devices. Signed-off-by: Arnd Bergmann --- drivers/pci/xen-pcifront.c | 67 ++++++++++++-------------------------- 1 file changed, 21 insertions(+), 46 deletions(-) diff --git a/drivers/pci/xen-pcifront.c b/drivers/pci/xen-pcifront.c index 24070e1c5f22..a5eb6cb02bec 100644 --- a/drivers/pci/xen-pcifront.c +++ b/drivers/pci/xen-pcifront.c @@ -443,40 +443,12 @@ static int pcifront_scan_bus(struct pcifront_device *pdev, return 0; } -static struct pci_bus *pci_scan_root_bus(struct device *parent, int bus, - struct pci_ops *ops, void *sysdata, struct list_head *resources) -{ - struct pci_host_bridge *bridge; - int error; - - bridge = pci_alloc_host_bridge(0); - if (!bridge) - return NULL; - - list_splice_init(resources, &bridge->windows); - bridge->dev.parent = parent; - bridge->sysdata = sysdata; - bridge->busnr = bus; - bridge->ops = ops; - - error = pci_scan_root_bus_bridge(bridge); - if (error < 0) - goto err_out; - - return bridge->bus; - -err_out: - kfree(bridge); - return NULL; -} - static int pcifront_scan_root(struct pcifront_device *pdev, unsigned int domain, unsigned int bus) { - struct pci_bus *b; - LIST_HEAD(resources); struct pcifront_sd *sd = NULL; struct pci_bus_entry *bus_entry = NULL; + struct pci_host_bridge *bridge; int err = 0; static struct resource busn_res = { .start = 0, @@ -498,50 +470,55 @@ static int pcifront_scan_root(struct pcifront_device *pdev, dev_info(&pdev->xdev->dev, "Creating PCI Frontend Bus %04x:%02x\n", domain, bus); + bridge = pci_alloc_host_bridge(sizeof(*sd)); + if (!bridge) + return -ENOMEM; + bus_entry = kzalloc(sizeof(*bus_entry), GFP_KERNEL); - sd = kzalloc(sizeof(*sd), GFP_KERNEL); - if (!bus_entry || !sd) { + sd = pci_host_bridge_priv(bridge); + if (!bus_entry) { err = -ENOMEM; goto err_out; } - pci_add_resource(&resources, &ioport_resource); - pci_add_resource(&resources, &iomem_resource); - pci_add_resource(&resources, &busn_res); + pci_add_resource(&bridge->windows, &ioport_resource); + pci_add_resource(&bridge->windows, &iomem_resource); + pci_add_resource(&bridge->windows, &busn_res); pcifront_init_sd(sd, domain, bus, pdev); + bridge->dev.parent = &pdev->xdev->dev; + bridge->sysdata = sd; + bridge->busnr = bus; + bridge->ops = &pcifront_bus_ops; pci_lock_rescan_remove(); - b = pci_scan_root_bus(&pdev->xdev->dev, bus, - &pcifront_bus_ops, sd, &resources); - if (!b) { + err = pci_scan_root_bus_bridge(bridge); + if (err < 0) { dev_err(&pdev->xdev->dev, "Error creating PCI Frontend Bus!\n"); - err = -ENOMEM; pci_unlock_rescan_remove(); - pci_free_resource_list(&resources); goto err_out; } - bus_entry->bus = b; + bus_entry->bus = bridge->bus; list_add(&bus_entry->list, &pdev->root_buses); /* pci_scan_root_bus skips devices which do not have a * devfn==0. The pcifront_scan_bus enumerates all devfn. */ - err = pcifront_scan_bus(pdev, domain, bus, b); + err = pcifront_scan_bus(pdev, domain, bus, bridge->bus); /* Claim resources before going "live" with our devices */ - pci_walk_bus(b, pcifront_claim_resource, pdev); + pci_walk_bus(bridge->bus, pcifront_claim_resource, pdev); /* Create SysFS and notify udev of the devices. Aka: "going live" */ - pci_bus_add_devices(b); + pci_bus_add_devices(bridge->bus); pci_unlock_rescan_remove(); return err; err_out: + pci_free_host_bridge(bridge); kfree(bus_entry); - kfree(sd); return err; } @@ -605,8 +582,6 @@ static void pcifront_free_roots(struct pcifront_device *pdev) free_root_bus_devs(bus_entry->bus); - kfree(bus_entry->bus->sysdata); - device_unregister(bus_entry->bus->bridge); pci_remove_bus(bus_entry->bus); From patchwork Fri Aug 17 10:26:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 958734 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arndb.de Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41sKCG07TBz9s3Z for ; Fri, 17 Aug 2018 20:27:38 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726370AbeHQNa3 (ORCPT ); Fri, 17 Aug 2018 09:30:29 -0400 Received: from mout.kundenserver.de ([212.227.17.13]:54093 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725845AbeHQNa3 (ORCPT ); Fri, 17 Aug 2018 09:30:29 -0400 Received: from wuerfel.lan ([109.193.40.16]) by mrelayeu.kundenserver.de (mreue101 [212.227.15.145]) with ESMTPA (Nemesis) id 0MF3Yx-1ffKFY0w9b-00GG86; Fri, 17 Aug 2018 12:27:19 +0200 From: Arnd Bergmann To: linux-pci@vger.kernel.org, Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, Christoph Hellwig , Lorenzo Pieralisi , Benjamin Herrenschmidt , linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, Arnd Bergmann Subject: [RFC 10/15] sparc/PCI: simplify pci_scan_one_pbm Date: Fri, 17 Aug 2018 12:26:40 +0200 Message-Id: <20180817102645.3839621-11-arnd@arndb.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180817102645.3839621-1-arnd@arndb.de> References: <20180817102645.3839621-1-arnd@arndb.de> X-Provags-ID: V03:K1:tqfqrJow5W4imcQdki9mGzYbBLDxofa09sQuKVVmcKPe9NKicQu 8BCFKR5x8HHGblInvnpgfM0Om9m61dXNuEzCIJ49sP//cfH3KTR8BqOqORdz4p1h7JROjqJ CiXbMgNkdpblfAYzq1OUFR9CqgorJFNPchgd2Qp4LZRLY2gq8SB2mQD0V3AQBL6R9BKkfBV T5dOLAgJhkzmztez96I5g== X-UI-Out-Filterresults: notjunk:1; V01:K0:HIAfquh0tdI=:0dA2U75J9e6Y7bRAeRLDpU fiYaLHOH0AVd2s9rov8WWEfjDdY97CTXbyas7dLBOmGUy3alOcAjpKpHC23tgOnaVQ+KqEI6h SY9mf4k7l5qaPraBVNvUcijJ5fmnEtBnPKgZ61VULSXOUZB5C/Ae7EZvleU8GoWQOaYqho0Wd uv/8+l54vLvdm+i5rPtjRntUa0wDwIEyviUXWwEMjn2CXS3RUp6te6SkpZAk/YRuhDiuAPAyn qS3vZeDS+n5QC9CSNsDkv/SZ+RjR/eqV5DgKB1PKXzj2nUybL8qQv/RkGazoc04kHmvd+GF6R pTM19Xq8siVJoyeODtmjIkZ0Ttt6uew7BA7y+E4RdhS0D4pgV2L9y4U9V4VxKgU2HjujjxexW Uw6KKZh3BTyN0rov5fERh2p1R5nunp9qffBcEle8v5LH2pInZmdZOMSZzDYRHk29LkoYJ7qFU Ba0xUQlY2OcL9tOKbHMps8HhKxVob6TtX+/MCqIRHQ07673JUS92Fnbu7MYYBBp8JHzjJTE96 xlfE87rK553fEbwQ3WXiwNpYx+zmtNhznqU/mX/rLks1rS4WTfc5rEPfPn1fPOH4+xrf9FvkG OxcDpE4M86hDsuMcxq9q/dlgAfu34AMyTyIXeh0xv2ZFXedd8Z5m7vqzzTxVmz8oOCGMN9HVo /oqizZtfSKo7q+qqQIjvQG9mW/eRsqNid04WKSzays1sWwEwevVrC6W8SHm7Wl9Edo3I= Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org We no longer need a separate pci_create_root_bus() function, and merging it into pci_scan_one_pbm() makes the implementation easier to understand. A possible future cleanup would move the allocation of the pci_host_bridge structure into the callers of pci_scan_one_pbm, and avoid duplication between pci_host_bridge and pci_pbm_info fields. Signed-off-by: Arnd Bergmann --- arch/sparc/kernel/pci.c | 62 ++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 41 deletions(-) diff --git a/arch/sparc/kernel/pci.c b/arch/sparc/kernel/pci.c index afbce59d9231..0d34fb2ac55b 100644 --- a/arch/sparc/kernel/pci.c +++ b/arch/sparc/kernel/pci.c @@ -691,70 +691,50 @@ static void pci_claim_bus_resources(struct pci_bus *bus) pci_claim_bus_resources(child_bus); } -static struct pci_bus *pci_create_root_bus(struct device *parent, int bus, - struct pci_ops *ops, void *sysdata, struct list_head *resources) +struct pci_bus *pci_scan_one_pbm(struct pci_pbm_info *pbm, + struct device *parent) { - int error; + struct device_node *node = pbm->op->dev.of_node; struct pci_host_bridge *bridge; + int ret; bridge = pci_alloc_host_bridge(0); if (!bridge) return NULL; bridge->dev.parent = parent; + bridge->sysdata = pbm; + bridge->busnr = pbm->pci_first_busno; + bridge->ops = pbm->pci_ops; - list_splice_init(resources, &bridge->windows); - bridge->sysdata = sysdata; - bridge->busnr = bus; - bridge->ops = ops; - - error = pci_register_host_bridge(bridge); - if (error < 0) - goto err_out; - - return bridge->bus; - -err_out: - kfree(bridge); - return NULL; -} - -struct pci_bus *pci_scan_one_pbm(struct pci_pbm_info *pbm, - struct device *parent) -{ - LIST_HEAD(resources); - struct device_node *node = pbm->op->dev.of_node; - struct pci_bus *bus; - - printk("PCI: Scanning PBM %s\n", node->full_name); - - pci_add_resource_offset(&resources, &pbm->io_space, + pci_add_resource_offset(&bridge->windows, &pbm->io_space, pbm->io_offset); - pci_add_resource_offset(&resources, &pbm->mem_space, + pci_add_resource_offset(&bridge->windows, &pbm->mem_space, pbm->mem_offset); if (pbm->mem64_space.flags) - pci_add_resource_offset(&resources, &pbm->mem64_space, + pci_add_resource_offset(&bridge->windows, &pbm->mem64_space, pbm->mem64_offset); pbm->busn.start = pbm->pci_first_busno; pbm->busn.end = pbm->pci_last_busno; pbm->busn.flags = IORESOURCE_BUS; - pci_add_resource(&resources, &pbm->busn); - bus = pci_create_root_bus(parent, pbm->pci_first_busno, pbm->pci_ops, - pbm, &resources); - if (!bus) { + pci_add_resource(&bridge->windows, &pbm->busn); + + printk("PCI: Scanning PBM %s\n", node->full_name); + ret = pci_register_host_bridge(bridge); + if (!ret) { printk(KERN_ERR "Failed to create bus for %s\n", node->full_name); - pci_free_resource_list(&resources); + pci_free_host_bridge(bridge); return NULL; } - pci_of_scan_bus(pbm, node, bus); - pci_bus_register_of_sysfs(bus); + pci_of_scan_bus(pbm, node, bridge->bus); + pci_bus_register_of_sysfs(bridge->bus); - pci_claim_bus_resources(bus); + pci_claim_bus_resources(bridge->bus); - pci_bus_add_devices(bus); - return bus; + pci_bus_add_devices(bridge->bus); + return bridge->bus; } int pcibios_enable_device(struct pci_dev *dev, int mask) From patchwork Fri Aug 17 10:26:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 958745 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arndb.de Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41sKKY1l2Mz9s3Z for ; Fri, 17 Aug 2018 20:33:05 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726760AbeHQNfe (ORCPT ); Fri, 17 Aug 2018 09:35:34 -0400 Received: from mout.kundenserver.de ([212.227.17.13]:42823 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725992AbeHQNfd (ORCPT ); Fri, 17 Aug 2018 09:35:33 -0400 Received: from wuerfel.lan ([109.193.40.16]) by mrelayeu.kundenserver.de (mreue101 [212.227.15.145]) with ESMTPA (Nemesis) id 0M2Mj6-1g72xf2n4O-00s8O9; Fri, 17 Aug 2018 12:27:19 +0200 From: Arnd Bergmann To: linux-pci@vger.kernel.org, Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, Christoph Hellwig , Lorenzo Pieralisi , Benjamin Herrenschmidt , linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, Arnd Bergmann Subject: [RFC 11/15] PCI: hyperv: convert to pci_scan_root_bus_bridge Date: Fri, 17 Aug 2018 12:26:41 +0200 Message-Id: <20180817102645.3839621-12-arnd@arndb.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180817102645.3839621-1-arnd@arndb.de> References: <20180817102645.3839621-1-arnd@arndb.de> X-Provags-ID: V03:K1:GawKYPNeblKXqePXMTqVUwJzPp4kDv9XunHKMjoeqmVocUEEVjM lkYgN2PiNwSPbXjS7Dii+2JTCPx/c95lj3gECJvX5IBv4mvtne+6VUdTVunsCr0Y+mlTkfc DGbWBehQ648C/tekyqiyObV6jpd7FXp6y3vcEIFfvC8pa/mnrRfRoZ+Og0ehO+tP6FrDZE9 w8e4yawJshAPLppwwwJWw== X-UI-Out-Filterresults: notjunk:1; V01:K0:fxpVOh8CRvU=:q/r7CREw9q7Zjc/R/UTtzI t09tyN3hj1ulxsUAzwtiN6AP+Rrjag5zkIt+HBEPBbM2Qt/i/TWhW/n8MjB28kbWWFK/MfDk7 gYijMym2nAJA4EMb5oVzsbOB8TnLE9YGisDWuQtl09NvT0bvZWyCA7xZO3NUQVqQ0Gcl/o1sE YKJVPpgo+50TIG2bcPc9h5rl4Y1MLY/J866SsPVzk0buhtSh+ze5U0vDh23BIxCiXbln9ROdP XvD6AbRXd+Ab+OC6ueC6HDkxBTySOCIniSsVcKXivMdEmvxRdOAexM8J1kGzfL1niEItbNFF4 jPnQLewOBUcKHhhbt8ywxxetNSttd2yMQ6g5guRzWrrxs6XkNsjGKcOF102uqXH6L4b33rkWw T7eaXdgQSv9TS+l5E32pKSbHyjQ0bqMdvtJhtjFxBXeg3R2N9QHjzSbXgHUwy8+7/oRgu/ZN/ spJB24Qski3myqmjqhwQUg53lrz2irhiVphDyNLNPOavK116uauw6ZLjBH28xbYVU/3YUPFQl SLFzyR7Bb+XhM0L3GrmWQS9sx/AJgCwXWMUuE+Uv7/jNeORoJkSUNta25Ob6qPNSsHFV6ZsBu J/LvXO995FFGSi53/kmB9DbAj68BzSVuHU0E3BKj5GHm7w/cnTp1m2PGqGA6+/Z8WiiFTsg1N eZOkQdSTxgzBTJDY2e+UDyLrd8axaxN+A7+mMgqRIWYrx6PZtMOS4ps7zz5vqdsoA/VA= Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org create_root_hv_pci_bus() uses a rather generic method of probing the host bridge, which can be simplified by just calling pci_scan_root_bus_bridge() after setting up the pci_host_bridge structure. Since we can no longer assign hbus->pci_bus in the middle, I just remove that member completely and use the pci_host_bridge instead. Ideally we'd convert it to pci_host_probe() for simplicity, but that is a bit different and I could not easily test it. Using pci_scan_root_bus_bridge should not change the behavior at all. Signed-off-by: Arnd Bergmann --- drivers/pci/controller/pci-hyperv.c | 75 +++++++++++------------------ 1 file changed, 28 insertions(+), 47 deletions(-) diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index df7cddea8e30..49586aefa38b 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -443,7 +443,7 @@ struct hv_pcibus_device { struct resource *high_mmio_res; struct completion *survey_event; struct completion remove_event; - struct pci_bus *pci_bus; + struct pci_host_bridge *bridge; spinlock_t config_lock; /* Avoid two threads writing index page */ spinlock_t device_list_lock; /* Protect lists below */ void __iomem *cfg_addr; @@ -1457,34 +1457,6 @@ static void prepopulate_bars(struct hv_pcibus_device *hbus) spin_unlock_irqrestore(&hbus->device_list_lock, flags); } -static struct pci_bus *pci_create_root_bus(struct device *parent, int bus, - struct pci_ops *ops, void *sysdata, struct list_head *resources) -{ - int error; - struct pci_host_bridge *bridge; - - bridge = pci_alloc_host_bridge(0); - if (!bridge) - return NULL; - - bridge->dev.parent = parent; - - list_splice_init(resources, &bridge->windows); - bridge->sysdata = sysdata; - bridge->busnr = bus; - bridge->ops = ops; - - error = pci_register_host_bridge(bridge); - if (error < 0) - goto err_out; - - return bridge->bus; - -err_out: - kfree(bridge); - return NULL; -} - /** * create_root_hv_pci_bus() - Expose a new root PCI bus * @hbus: Root PCI bus, as understood by this driver @@ -1493,25 +1465,34 @@ static struct pci_bus *pci_create_root_bus(struct device *parent, int bus, */ static int create_root_hv_pci_bus(struct hv_pcibus_device *hbus) { - /* Register the device */ - hbus->pci_bus = pci_create_root_bus(&hbus->hdev->device, - 0, /* bus number is always zero */ - &hv_pcifront_ops, - &hbus->sysdata, - &hbus->resources_for_children); - if (!hbus->pci_bus) - return -ENODEV; + struct pci_host_bridge *bridge; + int ret; + + bridge = pci_alloc_host_bridge(0); + if (!bridge) + return -ENOMEM; - hbus->pci_bus->msi = &hbus->msi_chip; - hbus->pci_bus->msi->dev = &hbus->hdev->device; + hbus->bridge = bridge; + bridge->dev.parent = &hbus->hdev->device; + list_splice_init(&hbus->resources_for_children, &bridge->windows); + bridge->sysdata = &hbus->sysdata; + bridge->ops = &hv_pcifront_ops; + bridge->msi = &hbus->msi_chip; + bridge->msi->dev = &hbus->hdev->device; pci_lock_rescan_remove(); - pci_scan_child_bus(hbus->pci_bus); - pci_bus_assign_resources(hbus->pci_bus); - pci_bus_add_devices(hbus->pci_bus); - pci_unlock_rescan_remove(); + /* ideally we should use pci_host_probe here */ + ret = pci_scan_root_bus_bridge(bridge); + if (ret < 0) { + pci_free_host_bridge(bridge); + goto error; + } + pci_bus_assign_resources(bridge->bus); + pci_bus_add_devices(bridge->bus); hbus->state = hv_pcibus_installed; - return 0; +error: + pci_unlock_rescan_remove(); + return ret; } struct q_res_req_compl { @@ -1769,7 +1750,7 @@ static void pci_devices_present_work(struct work_struct *work) * because there may have been changes. */ pci_lock_rescan_remove(); - pci_scan_child_bus(hbus->pci_bus); + pci_scan_child_bus(hbus->bridge->bus); pci_unlock_rescan_remove(); break; @@ -2669,8 +2650,8 @@ static int hv_pci_remove(struct hv_device *hdev) if (hbus->state == hv_pcibus_installed) { /* Remove the bus from PCI's point of view. */ pci_lock_rescan_remove(); - pci_stop_root_bus(hbus->pci_bus); - pci_remove_root_bus(hbus->pci_bus); + pci_stop_root_bus(hbus->bridge->bus); + pci_remove_root_bus(hbus->bridge->bus); pci_unlock_rescan_remove(); hbus->state = hv_pcibus_removed; } From patchwork Fri Aug 17 10:26:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 958736 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arndb.de Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41sKCd0Z02z9s3Z for ; Fri, 17 Aug 2018 20:27:57 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726218AbeHQNam (ORCPT ); Fri, 17 Aug 2018 09:30:42 -0400 Received: from mout.kundenserver.de ([217.72.192.74]:58943 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726623AbeHQNaf (ORCPT ); Fri, 17 Aug 2018 09:30:35 -0400 Received: from wuerfel.lan ([109.193.40.16]) by mrelayeu.kundenserver.de (mreue101 [212.227.15.145]) with ESMTPA (Nemesis) id 0MC1IG-1fhmHo0FzU-008rTJ; Fri, 17 Aug 2018 12:27:20 +0200 From: Arnd Bergmann To: linux-pci@vger.kernel.org, Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, Christoph Hellwig , Lorenzo Pieralisi , Benjamin Herrenschmidt , linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, Arnd Bergmann Subject: [RFC 12/15] PCI: make pcibios_bus_add_device() a callback function Date: Fri, 17 Aug 2018 12:26:42 +0200 Message-Id: <20180817102645.3839621-13-arnd@arndb.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180817102645.3839621-1-arnd@arndb.de> References: <20180817102645.3839621-1-arnd@arndb.de> X-Provags-ID: V03:K1:R1utoXtX1xNh6nDBCTDKYtshx4x5Ad5wYNBJAgXrFk787hWLNDF 5obZ97/w/5En0hskq/pxyK7SOPl4UhPJ2PTwKnGPNKAKwSSdQ44BRgnjAIpA6XYIYn0Er06 Pc2dX6A+UrbraMGwdzGaTIO5CmmDZNbHiidjXfSMXOaA8lWZRiNZ9X5Rk7imkL9cOwKt3Sk D03IBJSMeL9atj01F6mqA== X-UI-Out-Filterresults: notjunk:1; V01:K0:+d5rM4wws+U=:XOOzHLEIzDhldl610OMod6 Zap/qlXbAkH836yGeY/ib2fecXn6x4Y+6uThsJIVQJyn1cS1tX2TZ4owbnjdpC4UEm9ToZpZt QLMMZq8rhF/NIBw7YW1Gprxc5Hng3xGnBj9P/BV/mJoznZWMtHwuSpaGZB/Izug6RIcyqqRvd wUf/G+k24qNuyRjJopb5WPzsOluIBzDSiO5d2e57HCuJBS8iAtlRKCdHhRtghBuztlo8P7ktL fyvt0pz6K/sFh+VMz77tGl9B42B1WlrFRXUZYMSi8U6zq20RGyTFSfjeClcdkGW08EcwR85Q3 GccZApVCV2R3XGaUbH9SfyZ9ip2eyb+Q7DTP7COv8HAyFVquOZsid+9KhPnsBGu7k04/8a1Rv rtVTUu+qgS7Mq/XVDsHemBgXHs0bMKPFYvDwxSLr7TVeUDIkah1OYgh0CqHSEfWTpzrp91vxs g05h5QYibqxZ/EMLEuPJQnSEFQ64U2MljnkMnk1tMqvzNVkOocrGSXWsOgztBl8aN+tm9r1uN B1xw3o2sf/jUMlEHE4njh3nfstIXMdtG2ehg/F4tZU11is8jqyrZGSB5gVmCRzeIyItMc1dlT vkpYm6hS+SoavmhiL98V9H/X0+vW72Llfqsmb5M5AzlIGeJ37cFqN5tRz6j0pTb1QXr1RzIP6 EGr0f7BPgHqn64IaeBC3USy0HuUGf2QxRfTCJE77+kiUQMT+auy//1ddRGoRrYgQP6So= Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Weak functions are confusion, and we can now add callback pointers to pci host bridges for any controller, so let's make this one a callback rather than a __weak global function. Signed-off-by: Arnd Bergmann --- arch/powerpc/kernel/pci-common.c | 7 +------ arch/sh/drivers/pci/pci.c | 1 + arch/sh/drivers/pci/pcie-sh7786.c | 3 ++- arch/sh/include/asm/pci.h | 2 ++ drivers/pci/bus.c | 8 +++++++- include/linux/pci.h | 2 +- 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c index 096011ec8670..afc9598e4349 100644 --- a/arch/powerpc/kernel/pci-common.c +++ b/arch/powerpc/kernel/pci-common.c @@ -270,12 +270,6 @@ int pcibios_sriov_disable(struct pci_dev *pdev) #endif /* CONFIG_PCI_IOV */ -void pcibios_bus_add_device(struct pci_dev *pdev) -{ - if (ppc_md.pcibios_bus_add_device) - ppc_md.pcibios_bus_add_device(pdev); -} - static resource_size_t pcibios_io_size(const struct pci_controller *hose) { #ifdef CONFIG_PPC64 @@ -1617,6 +1611,7 @@ void pcibios_scan_phb(struct pci_controller *hose) hose->busn.flags = IORESOURCE_BUS; pci_add_resource(&bridge->windows, &hose->busn); + bridge->bus_add_device = ppc_md->pcibios_bus_add_device; bridge->dev.parent = hose->parent; bridge->sysdata = hose; bridge->busnr = hose->first_busno; diff --git a/arch/sh/drivers/pci/pci.c b/arch/sh/drivers/pci/pci.c index 8256626bc53c..d5c01a86cde1 100644 --- a/arch/sh/drivers/pci/pci.c +++ b/arch/sh/drivers/pci/pci.c @@ -65,6 +65,7 @@ static void pcibios_scanbus(struct pci_channel *hose) bridge->ops = hose->pci_ops; bridge->swizzle_irq = pci_common_swizzle; bridge->map_irq = pcibios_map_platform_irq; + bridge->bus_add_device = hose->bus_add_device; ret = pci_scan_root_bus_bridge(bridge); if (ret) { diff --git a/arch/sh/drivers/pci/pcie-sh7786.c b/arch/sh/drivers/pci/pcie-sh7786.c index 3d81a8b80942..ab78356681a0 100644 --- a/arch/sh/drivers/pci/pcie-sh7786.c +++ b/arch/sh/drivers/pci/pcie-sh7786.c @@ -122,6 +122,7 @@ extern struct pci_ops sh7786_pci_ops; .reg_base = start, \ .mem_offset = 0, \ .io_offset = 0, \ + .bus_add_device = sh7786_pci_bus_add_device, \ } static struct pci_channel sh7786_pci_channels[] = { @@ -488,7 +489,7 @@ int pcibios_map_platform_irq(const struct pci_dev *pdev, u8 slot, u8 pin) return evt2irq(0xae0); } -void pcibios_bus_add_device(struct pci_dev *pdev) +static void sh7786_pci_bus_add_device(struct pci_dev *pdev) { pdev->dev.dma_pfn_offset = dma_pfn_offset; } diff --git a/arch/sh/include/asm/pci.h b/arch/sh/include/asm/pci.h index 10a36b1cf2ea..e605141cbcbe 100644 --- a/arch/sh/include/asm/pci.h +++ b/arch/sh/include/asm/pci.h @@ -35,6 +35,8 @@ struct pci_channel { /* Optional error handling */ struct timer_list err_timer, serr_timer; unsigned int err_irq, serr_irq; + + void (*bus_add_device)(struct pci_dev *pdev); }; /* arch/sh/drivers/pci/pci.c */ diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c index 5cb40b2518f9..45873ac1a49c 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -299,7 +299,13 @@ bool pci_bus_clip_resource(struct pci_dev *dev, int idx) void __weak pcibios_resource_survey_bus(struct pci_bus *bus) { } -void __weak pcibios_bus_add_device(struct pci_dev *pdev) { } +static void pcibios_bus_add_device(struct pci_dev *pdev) +{ + struct pci_host_bridge *bridge = pci_find_host_bridge(pdev->bus); + + if (bridge->bus_add_device) + bridge->bus_add_device(pdev); +} /** * pci_bus_add_device - start driver for a single device diff --git a/include/linux/pci.h b/include/linux/pci.h index 1dd8a3ecf753..d1072690cb4f 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -475,6 +475,7 @@ struct pci_host_bridge { u8 (*swizzle_irq)(struct pci_dev *, u8 *); /* Platform IRQ swizzler */ int (*map_irq)(const struct pci_dev *, u8, u8); void (*release_fn)(struct pci_host_bridge *); + void (*bus_add_device)(struct pci_dev *pdev); void *release_data; struct msi_controller *msi; unsigned int ignore_reset_delay:1; /* For entire hierarchy */ @@ -880,7 +881,6 @@ extern struct list_head pci_root_buses; /* List of all known PCI buses */ int no_pci_devices(void); void pcibios_resource_survey_bus(struct pci_bus *bus); -void pcibios_bus_add_device(struct pci_dev *pdev); void pcibios_add_bus(struct pci_bus *bus); void pcibios_remove_bus(struct pci_bus *bus); void pcibios_fixup_bus(struct pci_bus *); From patchwork Fri Aug 17 10:26:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 958746 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arndb.de Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41sKKZ5JFyz9s3x for ; Fri, 17 Aug 2018 20:33:06 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727357AbeHQNf7 (ORCPT ); Fri, 17 Aug 2018 09:35:59 -0400 Received: from mout.kundenserver.de ([217.72.192.73]:53879 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726795AbeHQNfe (ORCPT ); Fri, 17 Aug 2018 09:35:34 -0400 Received: from wuerfel.lan ([109.193.40.16]) by mrelayeu.kundenserver.de (mreue101 [212.227.15.145]) with ESMTPA (Nemesis) id 0LopY3-1gNDhj20RX-00glB0; Fri, 17 Aug 2018 12:27:20 +0200 From: Arnd Bergmann To: linux-pci@vger.kernel.org, Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, Christoph Hellwig , Lorenzo Pieralisi , Benjamin Herrenschmidt , linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, Arnd Bergmann Subject: [RFC 13/15] PCI: turn pcibios_alloc_irq into a callback Date: Fri, 17 Aug 2018 12:26:43 +0200 Message-Id: <20180817102645.3839621-14-arnd@arndb.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180817102645.3839621-1-arnd@arndb.de> References: <20180817102645.3839621-1-arnd@arndb.de> X-Provags-ID: V03:K1:vGOxD5cso1fRX7vOFpg6264LHD7qp984mQlv5MPT6s07XrS4K2q Ixzfk8bDO/hDFJUEyLUy4cqBFvWycxqJfqu8myqpu+DeGzm1WHg70Dm0VhCWS3UfXdQMZUh vCVDLDNLy0TIi89lHJhy6GxOzRcS4zgTlQr8KfLRoWv/eaypGIooBRH9J0jTanPDmePlu2G yp3nrpbGuNd8g0mqp4zsg== X-UI-Out-Filterresults: notjunk:1; V01:K0:qiT72hH/I1Q=:9Hqj/v305t7b/4GjgDoN/e Ue8HbedIQ953rUOU4QCIrxtJEmq42LgC1lNOW2wV05FwAP1teCMpuw5EXUnwyVPR5Pst0E2oT yFIfuTQMC0KVvRUuZiHkl2xc8AV844sORxrAHRk2FYS6HDx3zKe98/ZfITQolb0YeyfUWSegv 5kgbJb+UtFGVEoCzgiHqOV1URMwqykKggoFu98N5hGdy4ACiAHfwLtrfjAy3XgMtIp34q95eJ OLTSZTGpJWJCzzZGDuH78sPadMJmvRrWhgD/FQsYl9AZcG5gutbR7vaZK5V7TeNW/hfk/xuuG RoKaH+M4ewI+f7cG9bReKVqfGInD2+FlK4EPmJ8ItQmjzgCNAzALHkB8vlXsXRUVgH2lQ+3dI 03VNLSmbzlhW+aTOur1hTEge9XLP6vHyWg+upyxLGH2zy3BedElcJxWQ1BDWFvux20M1regty +mz5A2Rn/dSr6r2aK2KPpTSr1P8DnlMFYoVGvnDwPULJd89k7o8WU2pnHdzi5deZxVHK//YDJ T7ctzSbG72zxqlW3vMSAAnCsQTbSNWnTU+EfZfiJGEBzfynJhquv+1ZugGcBASOSjn11dcq4C Ih6zebi1/g82y4cGXSIckDdAAjN+79Mv4TOkMu+LqPZnFxUnO4dxJgZtZOe1zrPAncRjTJh8F q3AJPPohH8aOM0jIpA5GNzi4LVgq7xnfVj7gjqc08fgObkjbZr8ajiTOFeLT+ajfY5tE= Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Weak functions are a bit confusing, and we can better deal with this using a callback function. pcibios_free_irq() is actually completely unused, but it seems better to treat it the same way as the allocation, unless we want to remove it completely. Signed-off-by: Arnd Bergmann --- arch/arm64/kernel/pci.c | 16 +++------------- drivers/pci/pci-driver.c | 13 +++++++++++-- include/linux/pci.h | 2 ++ 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/arch/arm64/kernel/pci.c b/arch/arm64/kernel/pci.c index 0e2ea1c78542..3d196c68e362 100644 --- a/arch/arm64/kernel/pci.c +++ b/arch/arm64/kernel/pci.c @@ -22,19 +22,6 @@ #include #include -#ifdef CONFIG_ACPI -/* - * Try to assign the IRQ number when probing a new device - */ -int pcibios_alloc_irq(struct pci_dev *dev) -{ - if (!acpi_disabled) - acpi_pci_irq_enable(dev); - - return 0; -} -#endif - /* * raw_pci_read/write - Platform-specific PCI config space access. */ @@ -93,6 +80,9 @@ int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge) ACPI_COMPANION_SET(&bridge->dev, adev); set_dev_node(bus_dev, acpi_get_node(acpi_device_handle(adev))); + + /* Try to assign the IRQ number when probing a new device */ + bridge->alloc_irq = acpi_pci_irq_enable; } return 0; diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index bef17c3fca67..c96bc7bd56da 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -387,13 +387,22 @@ static int __pci_device_probe(struct pci_driver *drv, struct pci_dev *pci_dev) return error; } -int __weak pcibios_alloc_irq(struct pci_dev *dev) +int pcibios_alloc_irq(struct pci_dev *dev) { + struct pci_host_bridge *bridge = pci_find_host_bridge(dev->bus); + + if (bridge->alloc_irq) + return bridge->alloc_irq(dev); + return 0; } -void __weak pcibios_free_irq(struct pci_dev *dev) +void pcibios_free_irq(struct pci_dev *dev) { + struct pci_host_bridge *bridge = pci_find_host_bridge(dev->bus); + + if (bridge->free_irq) + bridge->free_irq(dev); } #ifdef CONFIG_PCI_IOV diff --git a/include/linux/pci.h b/include/linux/pci.h index d1072690cb4f..1296d9fcc5da 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -476,6 +476,8 @@ struct pci_host_bridge { int (*map_irq)(const struct pci_dev *, u8, u8); void (*release_fn)(struct pci_host_bridge *); void (*bus_add_device)(struct pci_dev *pdev); + int (*alloc_irq)(struct pci_dev *); + int (*free_irq)(struct pci_dev *); void *release_data; struct msi_controller *msi; unsigned int ignore_reset_delay:1; /* For entire hierarchy */ From patchwork Fri Aug 17 10:26:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 958743 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arndb.de Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41sKKF0Hzzz9s3Z for ; Fri, 17 Aug 2018 20:32:49 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727157AbeHQNfg (ORCPT ); Fri, 17 Aug 2018 09:35:36 -0400 Received: from mout.kundenserver.de ([217.72.192.75]:57301 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725992AbeHQNfg (ORCPT ); Fri, 17 Aug 2018 09:35:36 -0400 Received: from wuerfel.lan ([109.193.40.16]) by mrelayeu.kundenserver.de (mreue101 [212.227.15.145]) with ESMTPA (Nemesis) id 0MIe3k-1fsotc3lQO-002Dcj; Fri, 17 Aug 2018 12:27:21 +0200 From: Arnd Bergmann To: linux-pci@vger.kernel.org, Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, Christoph Hellwig , Lorenzo Pieralisi , Benjamin Herrenschmidt , linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, Arnd Bergmann Subject: [RFC 14/15] PCI: make pcibios_root_bridge_prepare a callback Date: Fri, 17 Aug 2018 12:26:44 +0200 Message-Id: <20180817102645.3839621-15-arnd@arndb.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180817102645.3839621-1-arnd@arndb.de> References: <20180817102645.3839621-1-arnd@arndb.de> X-Provags-ID: V03:K1:vZ1tUwmaDYGgBzDuu0lrWWtkxQnlkXj5dtYX8zCbAbjMLPhmXwP t9LwpfD9mkpXEZveH7+fB8uk6X4OjdFYNyOnA1ey8wm+8CsZSfl/mDsjXOrb7MOd2PtYpje OlpTlmfI8HEz2MmVEtEV3Ua7aljIba3990heu2dTAIP1yUOKAYEcf+hRy1ZnQhsCmKw51jI +C4qufrNzYmzj/M0BHZrg== X-UI-Out-Filterresults: notjunk:1; V01:K0:dxliqE4bdUU=:3wNTq0x8GVJJDBiQ3AXqXs G1qv2M9EJ/R9gkV1bKMYZCs8sWmMSWUClGEIkfFaJ2W2G0STrO3wSkWADrlKtkCc9PfdTAoup 3zxFFpGjrFC3KfzxAbZML6rOtKnoEb5e3CksJj+aa1fm6aeQMQTvedb371xxPgfGWKva598XF PUSLvS6C3LcfmUQxzp0qZhcq8yppA5YYztqdY4TGZalE1Y8SY+nXhfKO6wlKvVk8gBAw8bicO EVd+BdFeloh0voA6J06gKNEZYjc6N7/m2U+JDcnX3Ypj9EGMwtWwQMC/6iRinDdnA0fgkwqW4 veqzwD45anZ44l+bkcdHI139spogAFCokqTAoS3lNwGdDFgnCrnv5wpnz92x18JhrHZFSK46h 1ooUzAs76v4ReXOyxEaBYCIkZfLExQcmeFHG/69ANMAnxIAA7Yx8NyY+vmE5/VThcDYmgZXGe 1jKXIZH/4ZFYKwPKIieTXdvXbmbnn+iTnmgndrm+wqozHbn1r61w/IAcy+XYfVEqj5uzXRSMJ 1QxFviL9Dt34LjlL5KMfIJTwrsc9uYg7id2Spp2jrfngo0HnfwR71KrBA6ZNY7a0IAEr+OX4X 030RsyIZnKMH2VTlrWfZhEjRisjQ8d9DdbWD9684DeNYA34N2KYNUgsazhi7hJGNV8xjU9sY+ IW1+wFwF4nHlkdCh9SPWlrphoEsYEnEVQAW5fgWeSJm3dqoevlxFhDJCnasD5iu58MTk= Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org pcibios_root_bridge_prepare() is always used as a per host bridge function, not per architecture. Making it a callback in the pci_host_bridge instead lets the host bridge implementation easily override it, and avoids the checks in the architecture for which host bridge implementation is being used. Alternatively, we could probably just call the pcibios_root_bridge_prepare after alloc_pci_host_bridge() here and get rid of it as a generic interface altogether, but doing that has a slightly higher chance of breaking something subtle. Signed-off-by: Arnd Bergmann --- arch/arm64/kernel/pci.c | 18 ++++++++---------- arch/ia64/pci/pci.c | 15 ++++----------- arch/powerpc/kernel/pci-common.c | 9 +-------- arch/x86/pci/acpi.c | 15 ++++----------- drivers/acpi/pci_root.c | 1 + drivers/pci/probe.c | 28 ++++++++++++++++------------ include/linux/acpi.h | 2 ++ include/linux/pci.h | 3 +-- 8 files changed, 37 insertions(+), 54 deletions(-) diff --git a/arch/arm64/kernel/pci.c b/arch/arm64/kernel/pci.c index 3d196c68e362..8958a7c32a9f 100644 --- a/arch/arm64/kernel/pci.c +++ b/arch/arm64/kernel/pci.c @@ -71,19 +71,17 @@ int acpi_pci_bus_find_domain_nr(struct pci_bus *bus) return root->segment; } -int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge) +int acpi_pci_root_bridge_prepare(struct pci_host_bridge *bridge) { - if (!acpi_disabled) { - struct pci_config_window *cfg = bridge->bus->sysdata; - struct acpi_device *adev = to_acpi_device(cfg->parent); - struct device *bus_dev = &bridge->bus->dev; + struct pci_config_window *cfg = bridge->bus->sysdata; + struct acpi_device *adev = to_acpi_device(cfg->parent); + struct device *bus_dev = &bridge->bus->dev; - ACPI_COMPANION_SET(&bridge->dev, adev); - set_dev_node(bus_dev, acpi_get_node(acpi_device_handle(adev))); + ACPI_COMPANION_SET(&bridge->dev, adev); + set_dev_node(bus_dev, acpi_get_node(acpi_device_handle(adev))); - /* Try to assign the IRQ number when probing a new device */ - bridge->alloc_irq = acpi_pci_irq_enable; - } + /* Try to assign the IRQ number when probing a new device */ + bridge->alloc_irq = acpi_pci_irq_enable; return 0; } diff --git a/arch/ia64/pci/pci.c b/arch/ia64/pci/pci.c index 7ccc64d5fe3e..511b8a058d80 100644 --- a/arch/ia64/pci/pci.c +++ b/arch/ia64/pci/pci.c @@ -308,18 +308,11 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root) &info->common, &info->controller); } -int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge) +int acpi_pci_root_bridge_prepare(struct pci_host_bridge *bridge) { - /* - * We pass NULL as parent to pci_create_root_bus(), so if it is not NULL - * here, pci_create_root_bus() has been called by someone else and - * sysdata is likely to be different from what we expect. Let it go in - * that case. - */ - if (!bridge->dev.parent) { - struct pci_controller *controller = bridge->bus->sysdata; - ACPI_COMPANION_SET(&bridge->dev, controller->companion); - } + struct pci_controller *controller = bridge->bus->sysdata; + ACPI_COMPANION_SET(&bridge->dev, controller->companion); + return 0; } diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c index afc9598e4349..5e5c6dd7ebe8 100644 --- a/arch/powerpc/kernel/pci-common.c +++ b/arch/powerpc/kernel/pci-common.c @@ -771,14 +771,6 @@ int pci_proc_domain(struct pci_bus *bus) return 1; } -int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge) -{ - if (ppc_md.pcibios_root_bridge_prepare) - return ppc_md.pcibios_root_bridge_prepare(bridge); - - return 0; -} - /* This header fixup will do the resource fixup for all devices as they are * probed, but not for bridge ranges */ @@ -1612,6 +1604,7 @@ void pcibios_scan_phb(struct pci_controller *hose) pci_add_resource(&bridge->windows, &hose->busn); bridge->bus_add_device = ppc_md->pcibios_bus_add_device; + bridge->prepare = ppc_md->pcibios_root_bridge_prepare; bridge->dev.parent = hose->parent; bridge->sysdata = hose; bridge->busnr = hose->first_busno; diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c index 5559dcaddd5e..041b2003707c 100644 --- a/arch/x86/pci/acpi.c +++ b/arch/x86/pci/acpi.c @@ -382,18 +382,11 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root) return bus; } -int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge) +int acpi_pci_root_bridge_prepare(struct pci_host_bridge *bridge) { - /* - * We pass NULL as parent to pci_create_root_bus(), so if it is not NULL - * here, pci_create_root_bus() has been called by someone else and - * sysdata is likely to be different from what we expect. Let it go in - * that case. - */ - if (!bridge->dev.parent) { - struct pci_sysdata *sd = bridge->bus->sysdata; - ACPI_COMPANION_SET(&bridge->dev, sd->companion); - } + struct pci_sysdata *sd = bridge->bus->sysdata; + ACPI_COMPANION_SET(&bridge->dev, sd->companion); + return 0; } diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c index 5f73de3b67c8..5da0f70c4e65 100644 --- a/drivers/acpi/pci_root.c +++ b/drivers/acpi/pci_root.c @@ -910,6 +910,7 @@ struct pci_bus *acpi_pci_root_create(struct acpi_pci_root *root, bridge->sysdata = sysdata; bridge->busnr = busnum; bridge->ops = ops->pci_ops; + bridge->prepare = acpi_pci_root_bridge_prepare; pci_set_host_bridge_release(bridge, acpi_pci_root_release_info, info); diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index eaedb4fe143a..f493d7e299e6 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -762,6 +762,22 @@ static void pci_set_bus_msi_domain(struct pci_bus *bus) dev_set_msi_domain(&bus->dev, d); } +/** + * pcibios_root_bridge_prepare - Platform-specific host bridge setup + * @bridge: Host bridge to set up + * + * Host bridge drivers can do some last minute fixups on the bridge + * here. Usually this should be done before calling pci_register_host_bridge + * though, so this hook can be removed. + */ +static int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge) +{ + if (bridge->prepare) + return bridge->prepare(bridge); + + return 0; +} + /* * pci_register_host_bridge() - Register a host bridge without scanning * @@ -2889,18 +2905,6 @@ unsigned int pci_scan_child_bus(struct pci_bus *bus) } EXPORT_SYMBOL_GPL(pci_scan_child_bus); -/** - * pcibios_root_bridge_prepare - Platform-specific host bridge setup - * @bridge: Host bridge to set up - * - * Default empty implementation. Replace with an architecture-specific setup - * routine, if necessary. - */ -int __weak pcibios_root_bridge_prepare(struct pci_host_bridge *bridge) -{ - return 0; -} - void __weak pcibios_add_bus(struct pci_bus *bus) { } diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 9967ba2e0b31..62c0278a7614 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -336,12 +336,14 @@ extern int acpi_get_override_irq(u32 gsi, int *trigger, int *polarity); void acpi_unregister_gsi (u32 gsi); struct pci_dev; +struct pci_host_bridge; int acpi_pci_irq_enable (struct pci_dev *dev); void acpi_penalize_isa_irq(int irq, int active); bool acpi_isa_irq_available(int irq); void acpi_penalize_sci_irq(int irq, int trigger, int polarity); void acpi_pci_irq_disable (struct pci_dev *dev); +int acpi_pci_root_bridge_prepare(struct pci_host_bridge *bridge); extern int ec_read(u8 addr, u8 *val); extern int ec_write(u8 addr, u8 val); diff --git a/include/linux/pci.h b/include/linux/pci.h index 1296d9fcc5da..24216daef6f8 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -472,6 +472,7 @@ struct pci_host_bridge { void *sysdata; int busnr; struct list_head windows; /* resource_entry */ + int (*prepare)(struct pci_host_bridge *bridge); u8 (*swizzle_irq)(struct pci_dev *, u8 *); /* Platform IRQ swizzler */ int (*map_irq)(const struct pci_dev *, u8, u8); void (*release_fn)(struct pci_host_bridge *); @@ -518,8 +519,6 @@ void pci_set_host_bridge_release(struct pci_host_bridge *bridge, void (*release_fn)(struct pci_host_bridge *), void *release_data); -int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge); - /* * The first PCI_BRIDGE_RESOURCE_NUM PCI bus resources (those that correspond * to P2P or CardBus bridge windows) go in a table. Additional ones (for From patchwork Fri Aug 17 10:26:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 958735 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arndb.de Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41sKCN5dxhz9s8k for ; Fri, 17 Aug 2018 20:27:44 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727285AbeHQNag (ORCPT ); Fri, 17 Aug 2018 09:30:36 -0400 Received: from mout.kundenserver.de ([217.72.192.75]:39429 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726218AbeHQNae (ORCPT ); Fri, 17 Aug 2018 09:30:34 -0400 Received: from wuerfel.lan ([109.193.40.16]) by mrelayeu.kundenserver.de (mreue101 [212.227.15.145]) with ESMTPA (Nemesis) id 0LnjcV-1gM7mA1Qsh-00hrda; Fri, 17 Aug 2018 12:27:21 +0200 From: Arnd Bergmann To: linux-pci@vger.kernel.org, Bjorn Helgaas Cc: linux-kernel@vger.kernel.org, Christoph Hellwig , Lorenzo Pieralisi , Benjamin Herrenschmidt , linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, Arnd Bergmann Subject: [RFC 15/15] PCI: make pcibios_add_bus/remove_bus callbacks Date: Fri, 17 Aug 2018 12:26:45 +0200 Message-Id: <20180817102645.3839621-16-arnd@arndb.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180817102645.3839621-1-arnd@arndb.de> References: <20180817102645.3839621-1-arnd@arndb.de> X-Provags-ID: V03:K1:rGoCCDOtdTx0VIyssezT4pFtEqNhxuve6iKaXwJBHf+4WU+8faw Dpu9wq8RQiguXqn4V5akgwPWXgaOy5cgDTJiHcHLT3xv/oOaMtG54uC8vvLQSdW///4q0nw I5RKZeCd07/18v074X+Gqwju9Ri5zhyU1Epl7WlCft+LD22RQMCW/zNHZIYUSLUK+qnJWcB s4jqjjsW1kamBVSX4DlSQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:YniJy3MqZc4=:nm3kiV+WQhPrhRGL9FUae4 i9umo/rybRlnAwRBDrn0Sy3HDXlVnfDLSzZOxABcc41K/uvEt/E68HLmwCmngDQ6OcM+2GNfd 8nnlmOFxxtqtwHEzgVUkPB1fIDgojYiFYkK5qN4pJ6IayqWWxNen8/weDzNMc+qNOYKEBhrfq soau4uR6N3N+Xb1x6JECyrI9/ISINZ9G8yIgpAwed+3qbjZknFJVWrZ7V60urdilBY21F3Qt9 pAr9l0vTc0+QkNtXxB+M/iVR9UgZ2yBhlZkkt5HQnB8NwazdTnh0qN2t5LQtqpL2L9hHypKpA +t/m5IyTJ9YzdRa+uMSX5qW5lv3m9F4ZVeI9fEvlmSRIt2+QzAJdoI99j6UnwvfgE8eSs1eyM ZTao4rMwDbxh2LQ4EpQqOwPxMPlTi+0IRKoGHG6O4AKxrLqiSnnvZseksx43Kn61k9BVDx1Ma ET7i6/K4sTPxQ1AXOAoM7ICrkL8j+hJuCPYMAgaAWZUeDi8fL+fpc25XRHVb/ysqeD2Q9A8mW 8bcQvko0r7dsZGkIPuwyk9EEFPJu+I10wbaZa6GUEdw8HT0zpBa+zUc2ndEZTwlysp6t4h1Fv gshhS1OCrYReZLvwuaXZb11++WnFla0gulPGVHpXg6K4nlAbrbQIAkmTatn3WZC5VP+OL7Wm4 xcoO4RnkSDCOS68WDbU/eGt0VezXnwrW1XiPIAvcYkjf7ZhcwV5SWPWDfCKOHJR3jiO0= Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org These are mostly not architecture specific but are meant for particular PCI host bridge implementations, in particular for the ACPI version. Turn them both into callback functions that are implemented by the APCI PCI implementation as well as the one architecture that overrides pcibios_remove_bus. Signed-off-by: Arnd Bergmann --- arch/arm64/kernel/pci.c | 10 ---------- arch/ia64/pci/pci.c | 10 ---------- arch/s390/pci/pci.c | 3 ++- arch/x86/pci/common.c | 10 ---------- drivers/acpi/pci_root.c | 2 ++ drivers/pci/probe.c | 12 ++++++++++-- include/linux/pci.h | 2 ++ 7 files changed, 16 insertions(+), 33 deletions(-) diff --git a/arch/arm64/kernel/pci.c b/arch/arm64/kernel/pci.c index 8958a7c32a9f..99fac25efe88 100644 --- a/arch/arm64/kernel/pci.c +++ b/arch/arm64/kernel/pci.c @@ -191,14 +191,4 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root) return bus; } -void pcibios_add_bus(struct pci_bus *bus) -{ - acpi_pci_add_bus(bus); -} - -void pcibios_remove_bus(struct pci_bus *bus) -{ - acpi_pci_remove_bus(bus); -} - #endif diff --git a/arch/ia64/pci/pci.c b/arch/ia64/pci/pci.c index 511b8a058d80..f47e0920d308 100644 --- a/arch/ia64/pci/pci.c +++ b/arch/ia64/pci/pci.c @@ -367,16 +367,6 @@ void pcibios_fixup_bus(struct pci_bus *b) platform_pci_fixup_bus(b); } -void pcibios_add_bus(struct pci_bus *bus) -{ - acpi_pci_add_bus(bus); -} - -void pcibios_remove_bus(struct pci_bus *bus) -{ - acpi_pci_remove_bus(bus); -} - void pcibios_set_master (struct pci_dev *dev) { /* No special bus mastering setup handling */ diff --git a/arch/s390/pci/pci.c b/arch/s390/pci/pci.c index b21205f131ce..120beb83b6a5 100644 --- a/arch/s390/pci/pci.c +++ b/arch/s390/pci/pci.c @@ -769,7 +769,7 @@ static void zpci_free_domain(struct zpci_dev *zdev) spin_unlock(&zpci_domain_lock); } -void pcibios_remove_bus(struct pci_bus *bus) +static void zpci_remove_bus(struct pci_bus *bus) { struct zpci_dev *zdev = get_zdev_by_bus(bus); @@ -801,6 +801,7 @@ static struct pci_bus *pci_scan_root_bus(struct device *parent, int bus, bridge->sysdata = sysdata; bridge->busnr = bus; bridge->ops = ops; + bridge->remove_bus = zpci_remove_bus; error = pci_scan_root_bus_bridge(bridge); if (error < 0) diff --git a/arch/x86/pci/common.c b/arch/x86/pci/common.c index 920d0885434c..987e6fefd5d3 100644 --- a/arch/x86/pci/common.c +++ b/arch/x86/pci/common.c @@ -168,16 +168,6 @@ void pcibios_fixup_bus(struct pci_bus *b) pcibios_fixup_device_resources(dev); } -void pcibios_add_bus(struct pci_bus *bus) -{ - acpi_pci_add_bus(bus); -} - -void pcibios_remove_bus(struct pci_bus *bus) -{ - acpi_pci_remove_bus(bus); -} - /* * Only use DMI information to set this if nothing was passed * on the kernel command line (which was parsed earlier). diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c index 5da0f70c4e65..cf7a9a7bf1e7 100644 --- a/drivers/acpi/pci_root.c +++ b/drivers/acpi/pci_root.c @@ -911,6 +911,8 @@ struct pci_bus *acpi_pci_root_create(struct acpi_pci_root *root, bridge->busnr = busnum; bridge->ops = ops->pci_ops; bridge->prepare = acpi_pci_root_bridge_prepare; + bridge->add_bus = acpi_pci_add_bus; + bridge->remove_bus = acpi_pci_remove_bus; pci_set_host_bridge_release(bridge, acpi_pci_root_release_info, info); diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index f493d7e299e6..86a678fa8c13 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -2905,12 +2905,20 @@ unsigned int pci_scan_child_bus(struct pci_bus *bus) } EXPORT_SYMBOL_GPL(pci_scan_child_bus); -void __weak pcibios_add_bus(struct pci_bus *bus) +void pcibios_add_bus(struct pci_bus *bus) { + struct pci_host_bridge *bridge = pci_find_host_bridge(bus); + + if (bridge->add_bus) + bridge->add_bus(bus); } -void __weak pcibios_remove_bus(struct pci_bus *bus) +void pcibios_remove_bus(struct pci_bus *bus) { + struct pci_host_bridge *bridge = pci_find_host_bridge(bus); + + if (bridge->remove_bus) + bridge->remove_bus(bus); } int pci_host_probe(struct pci_host_bridge *bridge) diff --git a/include/linux/pci.h b/include/linux/pci.h index 24216daef6f8..bc9635313747 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -479,6 +479,8 @@ struct pci_host_bridge { void (*bus_add_device)(struct pci_dev *pdev); int (*alloc_irq)(struct pci_dev *); int (*free_irq)(struct pci_dev *); + void (*add_bus)(struct pci_bus *); + void (*remove_bus)(struct pci_bus *); void *release_data; struct msi_controller *msi; unsigned int ignore_reset_delay:1; /* For entire hierarchy */