From patchwork Fri Sep 9 19:24:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Nowicki X-Patchwork-Id: 9324213 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 A3BED607D3 for ; Fri, 9 Sep 2016 19:26:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 91AD629871 for ; Fri, 9 Sep 2016 19:26:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 863B329FC9; Fri, 9 Sep 2016 19:26:22 +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=unavailable 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 1C25029871 for ; Fri, 9 Sep 2016 19:26:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753356AbcIIT0G (ORCPT ); Fri, 9 Sep 2016 15:26:06 -0400 Received: from mail-lf0-f50.google.com ([209.85.215.50]:36180 "EHLO mail-lf0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754344AbcIITYw (ORCPT ); Fri, 9 Sep 2016 15:24:52 -0400 Received: by mail-lf0-f50.google.com with SMTP id g62so50746405lfe.3 for ; Fri, 09 Sep 2016 12:24:46 -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=hlIsfqbA/fJaYgObmdvPMeSxbI7Ti/cT0OpkOo0Vs6E=; b=HyIu0GCSCXCt1VPhu6vneG8BLdgxxRYsmLANsFjiGvmN/w1Lpkb6wnxJEjGozcm1bv M8uLX1AjxU+kYFY7rbY/fx7winGn1pcTReJ5GRcK/EGpu5539M40ER3Ac7ZndEk4cFJg Z0gpfVMLWI3jMwNifttkX/AEQcd4Rhx9rO44K0p34V0l4V/oUDH/SvPT65vHXWl7mOYf 4JBKxsMQQ0tWOJ8dLJQfhy/MIEuZzYhxoXv252M64QY0kdQkbWaimoVKLYCh8WLq2i5J KZq/uY1mCazJr5W8BUwVGGjzSDwC8+4ud1Q6fk3j9fHXb4CvkN0EbUE1NljwN15OsEWk ZayA== 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=hlIsfqbA/fJaYgObmdvPMeSxbI7Ti/cT0OpkOo0Vs6E=; b=G0HmmP2kFtyHz+iPahen02AovUwUaCysl9iEzcrH5TTj5MtB0S6K5YxxEtQ2LfqiNN oT3OzN/MwDUZRORHUVJU8OxaCJ0U8X2q7cI6OYrRf5AXhO1DLxvelBl0YARAiJwKYItF hHzdrhFXekGra7KuDJU9HKrXuoMMLBl67B4Hv6R/l1Dqf6aLnPw7pgr6+nYYAmmg6SdF oYwKIlhfvFxuS3BNYQszLA0IzSN3ucsbheFHmB1QIBddJeO247CrEt3rUR+wVfh849vg V3d5qfAm8fpNF/dubyPtjseMDuIl96TFfDklvbIGXUmQSHJEMKaE6qkZ7wz7hGign2E1 /fqA== X-Gm-Message-State: AE9vXwPi8GtOGOJcRa5OGEdfrK1BagxQbwwCmx+UkLxLhj3vf//mGUbQSVwW7EmRf5Y+lQ== X-Received: by 10.46.1.66 with SMTP id 63mr1794043ljb.54.1473449085772; Fri, 09 Sep 2016 12:24:45 -0700 (PDT) Received: from localhost.localdomain (bbservice74.mmpnet215.tnp.pl. [87.116.215.74]) by smtp.gmail.com with ESMTPSA id 143sm846673ljj.2.2016.09.09.12.24.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Sep 2016 12:24:45 -0700 (PDT) From: Tomasz Nowicki To: helgaas@kernel.org, will.deacon@arm.com, catalin.marinas@arm.com, rafael@kernel.org, Lorenzo.Pieralisi@arm.com Cc: arnd@arndb.de, 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: [PATCH V6 1/5] PCI/ACPI: Extend pci_mcfg_lookup() responsibilities Date: Fri, 9 Sep 2016 21:24:03 +0200 Message-Id: <1473449047-10499-2-git-send-email-tn@semihalf.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1473449047-10499-1-git-send-email-tn@semihalf.com> References: <1473449047-10499-1-git-send-email-tn@semihalf.com> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In preparation for adding MCFG platform specific quirk handling move CFG resource calculation and ECAM ops assignment to pci_mcfg_lookup(). It becomes the gate for further ops and CFG resource manipulation in arch-agnostic code (drivers/acpi/pci_mcfg.c). No functionality changes in this patch. Signed-off-by: Tomasz Nowicki --- arch/arm64/kernel/pci.c | 17 +++++------------ drivers/acpi/pci_mcfg.c | 28 +++++++++++++++++++++++++--- include/linux/pci-acpi.h | 4 +++- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/arch/arm64/kernel/pci.c b/arch/arm64/kernel/pci.c index acf3872..fb439c7 100644 --- a/arch/arm64/kernel/pci.c +++ b/arch/arm64/kernel/pci.c @@ -125,24 +125,17 @@ pci_acpi_setup_ecam_mapping(struct acpi_pci_root *root) u16 seg = root->segment; struct pci_config_window *cfg; struct resource cfgres; - unsigned int bsz; + struct pci_ecam_ops *ecam_ops; + int ret; - /* 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) { + ret = pci_mcfg_lookup(root, &cfgres, &ecam_ops); + if (ret) { 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); + 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)); diff --git a/drivers/acpi/pci_mcfg.c b/drivers/acpi/pci_mcfg.c index b5b376e..ffcc651 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 { @@ -35,9 +36,18 @@ struct mcfg_entry { /* List to save MCFG entries */ static LIST_HEAD(pci_mcfg_list); -phys_addr_t pci_mcfg_lookup(u16 seg, struct resource *bus_res) +int pci_mcfg_lookup(struct acpi_pci_root *root, struct resource *cfgres, + struct pci_ecam_ops **ecam_ops) { + struct pci_ecam_ops *ops = &pci_generic_ecam_ops; + struct resource *bus_res = &root->secondary; + u16 seg = root->segment; struct mcfg_entry *e; + struct resource res; + + /* Use address from _CBA if present, otherwise lookup MCFG */ + if (root->mcfg_addr) + goto skip_lookup; /* * We expect exact match, unless MCFG entry end bus covers more than @@ -45,10 +55,22 @@ phys_addr_t pci_mcfg_lookup(u16 seg, struct resource *bus_res) */ list_for_each_entry(e, &pci_mcfg_list, list) { if (e->segment == seg && e->bus_start == bus_res->start && - e->bus_end >= bus_res->end) - return e->addr; + e->bus_end >= bus_res->end) { + root->mcfg_addr = e->addr; + } + } + if (!root->mcfg_addr) + return -ENXIO; + +skip_lookup: + memset(&res, 0, sizeof(res)); + res.start = root->mcfg_addr + (bus_res->start << 20); + res.end = res.start + (resource_size(bus_res) << 20) - 1; + res.flags = IORESOURCE_MEM; + *cfgres = res; + *ecam_ops = ops; return 0; } diff --git a/include/linux/pci-acpi.h b/include/linux/pci-acpi.h index 7d63a66..7a4e83a 100644 --- a/include/linux/pci-acpi.h +++ b/include/linux/pci-acpi.h @@ -24,7 +24,9 @@ static inline acpi_status pci_acpi_remove_pm_notifier(struct acpi_device *dev) } 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); +struct pci_ecam_ops; +extern int pci_mcfg_lookup(struct acpi_pci_root *root, struct resource *cfgres, + struct pci_ecam_ops **ecam_ops); static inline acpi_handle acpi_find_root_bridge_handle(struct pci_dev *pdev) {