From patchwork Mon Aug 8 13:05:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Nowicki X-Patchwork-Id: 9268299 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C775C607D6 for ; Mon, 8 Aug 2016 13:06:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA5C1283E4 for ; Mon, 8 Aug 2016 13:06:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AF293283EE; Mon, 8 Aug 2016 13:06:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 21761283E4 for ; Mon, 8 Aug 2016 13:06:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932164AbcHHNGB (ORCPT ); Mon, 8 Aug 2016 09:06:01 -0400 Received: from mail-wm0-f45.google.com ([74.125.82.45]:35925 "EHLO mail-wm0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752437AbcHHNF7 (ORCPT ); Mon, 8 Aug 2016 09:05:59 -0400 Received: by mail-wm0-f45.google.com with SMTP id q128so118043539wma.1 for ; Mon, 08 Aug 2016 06:05:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1od3GHGtU8Jb9Rgbdlpf0/L8IdoBpBLOIkBVgy7lIqE=; b=iZRym1sQBiAlzJQv0EOdswUDhbYveCinD16+wxW7sr+FFfEObIBAt75STKm5wIPL/L xzOemEivhMTomQSERRFYlQ4zzyUrUiW9gDiFXc4nZTDjFjGzPuo3k/0QeaUJnsdmDt8u AkOauQvSDgAwxk1BeSjoFa2Ln2TPpV7I+vQwBkzJm0sdn2NzDBbFYmMqgjlFyby7CPbF IvaIZk5ddKxJ5c9aUFmVuKB+jmhvrlrx3qGzVHd6ardNoiOoeEqwDxer2+DVgXzLfwaw rmItIsJCBpBWUtsCtPE0okVj+vNtAJdt1KL7mllCjqmdylxK1K1n243qlyczDdStahMT cygw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=1od3GHGtU8Jb9Rgbdlpf0/L8IdoBpBLOIkBVgy7lIqE=; b=XD+udA5VUEgCdvn1G3pJBJy3xIG63nTWpOxAssl07Bm9shNyuoBgvXqhI8I/ewL28u j9zzixBN20CsEhZ5re68nieX15dJCPw0iaIKF8O6BVsdjaYkZPJhZB6s//gA4BI+mBSw kFA0vveo4h8GZEs2trtovFUCOCpHk1tX9luzTetVswpvGYFlBJsyKFjT2679+U+5yQa7 bbcGwBlfykqbRpabmaYpJEbEjhNLdfaX8QE6mF4mb0P0Zus2DfRuwWWF4hctekYe7pH2 9oCmLrMA1+cBbXRJsfh3OcW00tmW8WwPyApDcyQqQelwcBwf0KwppNvp6Db9l7/Rr0i6 fGnA== X-Gm-Message-State: AEkoouu452WZFm+g16pRmb+LqAbbp+LAQGmmA7JZSwfDfybVDMJD24hyAEyGBp5gfk74RA== X-Received: by 10.25.127.214 with SMTP id a205mr28286826lfd.142.1470661557264; Mon, 08 Aug 2016 06:05:57 -0700 (PDT) Received: from tn-HP-4.semihalf.local (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id g11sm5644098lji.25.2016.08.08.06.05.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 Aug 2016 06:05:56 -0700 (PDT) From: Tomasz Nowicki To: helgaas@kernel.org, arnd@arndb.de, will.deacon@arm.com, catalin.marinas@arm.com, rafael@kernel.org, Lorenzo.Pieralisi@arm.com Cc: hanjun.guo@linaro.org, okaya@codeaurora.org, jchandra@broadcom.com, cov@codeaurora.org, dhdang@apm.com, ard.biesheuvel@linaro.org, robert.richter@caviumnetworks.com, mw@semihalf.com, Liviu.Dudau@arm.com, ddaney@caviumnetworks.com, wangyijing@huawei.com, msalter@redhat.com, linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linaro-acpi@lists.linaro.org, jcm@redhat.com, andrea.gallo@linaro.org, jeremy.linton@arm.com, liudongdong3@huawei.com, gabriele.paoloni@huawei.com, jhugo@codeaurora.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, Tomasz Nowicki Subject: [RFC PATCH V5 2/5] PCI/ACPI: Move ACPI ECAM mapping to generic MCFG driver Date: Mon, 8 Aug 2016 15:05:38 +0200 Message-Id: <1470661541-26270-3-git-send-email-tn@semihalf.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1470661541-26270-1-git-send-email-tn@semihalf.com> References: <1470661541-26270-1-git-send-email-tn@semihalf.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP pci_acpi_setup_ecam_mapping() is not really ARM64 specific so move it out of arch/arm64/ directory. In preparation for adding MCFG quirk handling extend pci_acpi_setup_ecam_mapping() functionality to accept custom PCI config accessors (function's argument). For ARM64 ACPI based PCI host controller we still use pci_generic_ecam_ops. Signed-off-by: Tomasz Nowicki --- arch/arm64/kernel/pci.c | 41 ++--------------------------------------- drivers/acpi/pci_mcfg.c | 40 ++++++++++++++++++++++++++++++++++++++++ include/linux/pci-acpi.h | 3 +++ 3 files changed, 45 insertions(+), 39 deletions(-) diff --git a/arch/arm64/kernel/pci.c b/arch/arm64/kernel/pci.c index 981e828..2e7bed4 100644 --- a/arch/arm64/kernel/pci.c +++ b/arch/arm64/kernel/pci.c @@ -114,44 +114,6 @@ int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge) return 0; } -/* - * Lookup the bus range for the domain in MCFG, and set up config space - * mapping. - */ -static struct pci_config_window * -pci_acpi_setup_ecam_mapping(struct acpi_pci_root *root) -{ - struct resource *bus_res = &root->secondary; - u16 seg = root->segment; - struct pci_config_window *cfg; - struct resource cfgres; - unsigned int bsz; - - /* Use address from _CBA if present, otherwise lookup MCFG */ - if (!root->mcfg_addr) - root->mcfg_addr = pci_mcfg_lookup(seg, bus_res); - - if (!root->mcfg_addr) { - dev_err(&root->device->dev, "%04x:%pR ECAM region not found\n", - seg, bus_res); - return NULL; - } - - bsz = 1 << pci_generic_ecam_ops.bus_shift; - cfgres.start = root->mcfg_addr + bus_res->start * bsz; - cfgres.end = cfgres.start + resource_size(bus_res) * bsz - 1; - cfgres.flags = IORESOURCE_MEM; - cfg = pci_ecam_create(&root->device->dev, &cfgres, bus_res, - &pci_generic_ecam_ops); - if (IS_ERR(cfg)) { - dev_err(&root->device->dev, "%04x:%pR error %ld mapping ECAM\n", - seg, bus_res, PTR_ERR(cfg)); - return NULL; - } - - return cfg; -} - /* release_info: free resources allocated by init_info */ static void pci_acpi_generic_release_info(struct acpi_pci_root_info *ci) { @@ -177,7 +139,8 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root) if (!ri) return NULL; - ri->cfg = pci_acpi_setup_ecam_mapping(root); + ri->cfg = pci_acpi_setup_ecam_mapping(root, + &pci_generic_ecam_ops.pci_ops); if (!ri->cfg) { kfree(ri); return NULL; diff --git a/drivers/acpi/pci_mcfg.c b/drivers/acpi/pci_mcfg.c index b5b376e..331b560 100644 --- a/drivers/acpi/pci_mcfg.c +++ b/drivers/acpi/pci_mcfg.c @@ -22,6 +22,7 @@ #include #include #include +#include /* Structure to hold entries from the MCFG table */ struct mcfg_entry { @@ -52,6 +53,45 @@ phys_addr_t pci_mcfg_lookup(u16 seg, struct resource *bus_res) return 0; } +/* + * Lookup the bus range for the domain in MCFG, and set up config space + * mapping. + */ +struct pci_config_window * +pci_acpi_setup_ecam_mapping(struct acpi_pci_root *root, struct pci_ops *ops) +{ + struct resource *bus_res = &root->secondary; + u16 seg = root->segment; + struct pci_config_window *cfg; + struct resource cfgres; + struct pci_ecam_ops ecam_ops = { + .bus_shift = 20, + .pci_ops = *ops, + }; + + /* Use address from _CBA if present, otherwise lookup MCFG */ + if (!root->mcfg_addr) + root->mcfg_addr = pci_mcfg_lookup(seg, bus_res); + + if (!root->mcfg_addr) { + dev_err(&root->device->dev, "%04x:%pR ECAM region not found\n", + seg, bus_res); + return NULL; + } + + cfgres.start = root->mcfg_addr + (bus_res->start << 20); + cfgres.end = cfgres.start + (resource_size(bus_res) << 20) - 1; + cfgres.flags = IORESOURCE_MEM; + cfg = pci_ecam_create(&root->device->dev, &cfgres, bus_res, &ecam_ops); + if (IS_ERR(cfg)) { + dev_err(&root->device->dev, "%04x:%pR error %ld mapping ECAM\n", + seg, bus_res, PTR_ERR(cfg)); + return NULL; + } + + return cfg; +} + static __init int pci_mcfg_parse(struct acpi_table_header *header) { struct acpi_table_mcfg *mcfg; diff --git a/include/linux/pci-acpi.h b/include/linux/pci-acpi.h index 7d63a66..e9bfe00 100644 --- a/include/linux/pci-acpi.h +++ b/include/linux/pci-acpi.h @@ -26,6 +26,9 @@ extern phys_addr_t acpi_pci_root_get_mcfg_addr(acpi_handle handle); extern phys_addr_t pci_mcfg_lookup(u16 domain, struct resource *bus_res); +extern struct pci_config_window * +pci_acpi_setup_ecam_mapping(struct acpi_pci_root *root, struct pci_ops *ops); + static inline acpi_handle acpi_find_root_bridge_handle(struct pci_dev *pdev) { struct pci_bus *pbus = pdev->bus;