From patchwork Fri Apr 29 23:01:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 102404 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp1044468qge; Fri, 29 Apr 2016 16:02:30 -0700 (PDT) X-Received: by 10.98.95.4 with SMTP id t4mr10611796pfb.162.1461970950786; Fri, 29 Apr 2016 16:02:30 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id fn8si20385687pab.197.2016.04.29.16.02.30; Fri, 29 Apr 2016 16:02:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752703AbcD2XCX (ORCPT + 29 others); Fri, 29 Apr 2016 19:02:23 -0400 Received: from mout.kundenserver.de ([212.227.17.10]:64840 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752412AbcD2XCT (ORCPT ); Fri, 29 Apr 2016 19:02:19 -0400 Received: from wuerfel.lan. ([78.42.132.4]) by mrelayeu.kundenserver.de (mreue101) with ESMTPA (Nemesis) id 0LZvrB-1bPXAP1fGn-00llvC; Sat, 30 Apr 2016 01:01:48 +0200 From: Arnd Bergmann To: Bjorn Helgaas Cc: catalin.marinas@arm.com, linux-pci@vger.kernel.org, will.deacon@arm.com, Lorenzo Pieralisi , Tomasz Nowicki , ddaney@caviumnetworks.com, robert.richter@caviumnetworks.com, msalter@redhat.com, Liviu.Dudau@arm.com, jchandra@broadcom.com, linux-kernel@vger.kernel.org, hanjun.guo@linaro.org, Suravee.Suthikulpanit@amd.com, Thierry Reding , Arnd Bergmann Subject: [PATCH 2/3] [RFC] pci: host-common: use new pci_register_host interface Date: Sat, 30 Apr 2016 01:01:38 +0200 Message-Id: <1461970899-4150603-3-git-send-email-arnd@arndb.de> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1461970899-4150603-1-git-send-email-arnd@arndb.de> References: <1461970899-4150603-1-git-send-email-arnd@arndb.de> X-Provags-ID: V03:K0:iokEKVOf003atV7SMYlCDb9jaWhccatyO56JnpwXj+hlA24AE/l vmS95VSaUwPc54iLM3ut4BNqfDUb7QJI46ZB1qrEq1AHKoVIzAMLsMJiXt3ezP6LaB3NQQu Md4FpWYEdlE1T/I52MhENYq6sGI+JmHrIEKStJNNsnU7nzKF8SCeY0W8ZkHNhvJyr7RRLeH uWSj75azb2JS7TW6qh6iw== X-UI-Out-Filterresults: notjunk:1; V01:K0:XwfGaV5isbY=:w9K5eZDv2xIg11bvPzt5zt EzUDUq+LYFj5u9ZwYw5B2dqJAaVCckEalTmbLlkoHHtmLv7ccjOdjRsslmLqHY1d32Gagxeo9 djJW6WaWs3QkGKlScM+dz0s9YByS3EiNo7MHwUd4NqYCATqylN+I8px01QfnoyufuU4gh38FQ hCe/ucXw9kWpe0kZ6FZxNNIFL37R18k9iEQHHtJ4bhWdIf/K9TeZXCNUoAS6R++9q459/SVZa jk5eyp9hLNZ12XNJtC1lhHuzN5H/oiphiLVH4rq7v7OMkM55DuVTKGk7Ad1QGGSSoHmZZdGD1 8mez+I2sPlfmldOAKB/+7IOxm8jIZAckTKFcz/zwUw64/rXiyydPxoK9TkZ5gmjcMw5VSXV1C 3yoh8q0xGsmNko0utLVFrxVaRE6NTSyt5oo4lfHDuWv+CXP1fiCjbEmChghqCZ8QhciSzkEKK eqwn8dRX/W4laethQsuLJBCH++4r/BC00bHTx6sFv58LFEpn4UV7Jd0ELgYn7zL4TyXV/Qu87 fah+8GQ9C3LnK1aZ0qhewX6zXq+kWnvf6VgdbYJ2EpDP74eHh/QHGfS3xEWflXCWGUs+XllqY Os7uNjEufNVcYKS6ikEFCN8WdwbRBoEhp0TFKp2HIqVxwntNHxy3Px6RIpTNbgJejJKggfxXP lTIp94I1t6YVGxjgIL3iji23W38HuJblCwbP40w5XKHCZIYIr2CBzctKgpa+fHzMrcxo= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This changes the pci-host-common implementation to call the new pci_register_host() interface instead of pci_scan_root_bus(). As a result, we get to share the pci_host_bridge structure as it was originally intended anyway: We ended up having two copies of pci_host_bridge here because we never got it done until now. We can also remove the now unused "resources" list_head, as we add the resources to the pci_host_bridge directly. On top of this, further generalizations are possible to shrink the pci-host-common.c file, in particular requesting the resources and scanning for child devices can be moved into pci_register_host(). Signed-off-by: Arnd Bergmann --- drivers/pci/host/pci-host-common.c | 38 ++++++++++++++++++++++++-------------- drivers/pci/host/pci-host-common.h | 1 - 2 files changed, 24 insertions(+), 15 deletions(-) -- 2.7.0 diff --git a/drivers/pci/host/pci-host-common.c b/drivers/pci/host/pci-host-common.c index e9f850f07968..3fc529f0297e 100644 --- a/drivers/pci/host/pci-host-common.c +++ b/drivers/pci/host/pci-host-common.c @@ -26,7 +26,7 @@ static void gen_pci_release_of_pci_ranges(struct gen_pci *pci) { - pci_free_resource_list(&pci->resources); + pci_free_resource_list(&pci->host.windows); } static int gen_pci_parse_request_of_pci_ranges(struct gen_pci *pci) @@ -37,12 +37,12 @@ static int gen_pci_parse_request_of_pci_ranges(struct gen_pci *pci) resource_size_t iobase; struct resource_entry *win; - err = of_pci_get_host_bridge_resources(np, 0, 0xff, &pci->resources, + err = of_pci_get_host_bridge_resources(np, 0, 0xff, &pci->host.windows, &iobase); if (err) return err; - resource_list_for_each_entry(win, &pci->resources) { + resource_list_for_each_entry(win, &pci->host.windows) { struct resource *parent, *res = win->res; switch (resource_type(res)) { @@ -130,6 +130,14 @@ static int gen_pci_parse_map_cfg_windows(struct gen_pci *pci) return 0; } +static void gen_pci_release(struct device *dev) +{ + struct gen_pci *pci = container_of(dev, struct gen_pci, host.dev); + + gen_pci_release_of_pci_ranges(pci); + kfree(pci); +} + int pci_host_common_probe(struct platform_device *pdev, struct gen_pci *pci) { @@ -137,7 +145,7 @@ int pci_host_common_probe(struct platform_device *pdev, const char *type; struct device *dev = &pdev->dev; struct device_node *np = dev->of_node; - struct pci_bus *bus, *child; + struct pci_bus *child; type = of_get_property(np, "device_type", NULL); if (!type || strcmp(type, "pci")) { @@ -148,8 +156,8 @@ int pci_host_common_probe(struct platform_device *pdev, of_pci_check_probe_only(); pci->host.dev.parent = dev; + pci->host.dev.release = gen_pci_release; INIT_LIST_HEAD(&pci->host.windows); - INIT_LIST_HEAD(&pci->resources); /* Parse our PCI ranges and request their resources */ err = gen_pci_parse_request_of_pci_ranges(pci); @@ -168,24 +176,26 @@ int pci_host_common_probe(struct platform_device *pdev, pci_add_flags(PCI_REASSIGN_ALL_RSRC | PCI_REASSIGN_ALL_BUS); - bus = pci_scan_root_bus(dev, pci->cfg.bus_range->start, - &pci->cfg.ops->ops, pci, &pci->resources); - if (!bus) { - dev_err(dev, "Scanning rootbus failed"); - return -ENODEV; + pci->host.ops = &pci->cfg.ops->ops; + pci->host.sysdata = pci; + pci->host.busnr = pci->cfg.bus_range->start; + err = pci_register_host(&pci->host); + if (!err) { + dev_err(dev, "registering host failed"); + return err; } pci_fixup_irqs(pci_common_swizzle, of_irq_parse_and_map_pci); if (!pci_has_flag(PCI_PROBE_ONLY)) { - pci_bus_size_bridges(bus); - pci_bus_assign_resources(bus); + pci_bus_size_bridges(pci->host.bus); + pci_bus_assign_resources(pci->host.bus); - list_for_each_entry(child, &bus->children, node) + list_for_each_entry(child, &pci->host.bus->children, node) pcie_bus_configure_settings(child); } - pci_bus_add_devices(bus); + pci_bus_add_devices(pci->host.bus); return 0; } diff --git a/drivers/pci/host/pci-host-common.h b/drivers/pci/host/pci-host-common.h index 09f3fa0a55d7..c89a756420ee 100644 --- a/drivers/pci/host/pci-host-common.h +++ b/drivers/pci/host/pci-host-common.h @@ -38,7 +38,6 @@ struct gen_pci_cfg_windows { struct gen_pci { struct pci_host_bridge host; struct gen_pci_cfg_windows cfg; - struct list_head resources; }; int pci_host_common_probe(struct platform_device *pdev,