From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from omzsmtpe03.verizonbusiness.com ([199.249.25.208]:19767 "EHLO omzsmtpe03.verizonbusiness.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753683AbdDDTcr (ORCPT ); Tue, 4 Apr 2017 15:32:47 -0400 From: alexander.levin@verizon.com To: "gregkh@linuxfoundation.org" CC: "stable@vger.kernel.org" Subject: [PATCH for 4.9 21/98] PCI/ACPI: Extend pci_mcfg_lookup() to return ECAM config accessors Date: Tue, 4 Apr 2017 19:32:09 +0000 Message-ID: <20170404193158.19041-22-alexander.levin@verizon.com> References: <20170404193158.19041-1-alexander.levin@verizon.com> In-Reply-To: <20170404193158.19041-1-alexander.levin@verizon.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Tomasz Nowicki [ Upstream commit 13983eb89d5afaa65acd4479fad151cbd4de5509 ] pci_mcfg_lookup() is the external interface to the generic MCFG code. Previously it merely looked up the ECAM base address for a given domain and bus range. We want a way to add MCFG quirks, some of which may require special config accessors and adjustments to the ECAM address range. Extend pci_mcfg_lookup() so it can return a pointer to a pci_ecam_ops structure and a struct resource for the ECAM address space. For now, it always returns &pci_generic_ecam_ops (the standard accessor) and the resource described by the MCFG. No functional changes intended. [bhelgaas: changelog] Signed-off-by: Tomasz Nowicki Signed-off-by: Bjorn Helgaas Signed-off-by: Sasha Levin --- 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 ac4509d..b1bd3d0 100644 --- a/arch/arm64/kernel/pci.c +++ b/arch/arm64/kernel/pci.c @@ -124,25 +124,18 @@ pci_acpi_setup_ecam_mapping(struct acpi_pci_root *roo= t) struct device *dev =3D &root->device->dev; struct resource *bus_res =3D &root->secondary; u16 seg =3D root->segment; + struct pci_ecam_ops *ecam_ops; struct resource cfgres; struct acpi_device *adev; struct pci_config_window *cfg; - unsigned int bsz; + int ret; =20 - /* Use address from _CBA if present, otherwise lookup MCFG */ - if (!root->mcfg_addr) - root->mcfg_addr =3D pci_mcfg_lookup(seg, bus_res); - - if (!root->mcfg_addr) { + ret =3D pci_mcfg_lookup(root, &cfgres, &ecam_ops); + if (ret) { dev_err(dev, "%04x:%pR ECAM region not found\n", seg, bus_res); return NULL; } =20 - bsz =3D 1 << pci_generic_ecam_ops.bus_shift; - cfgres.start =3D root->mcfg_addr + bus_res->start * bsz; - cfgres.end =3D cfgres.start + resource_size(bus_res) * bsz - 1; - cfgres.flags =3D IORESOURCE_MEM; - adev =3D acpi_resource_consumer(&cfgres); if (adev) dev_info(dev, "ECAM area %pR reserved by %s\n", &cfgres, @@ -151,7 +144,7 @@ pci_acpi_setup_ecam_mapping(struct acpi_pci_root *root) dev_warn(dev, FW_BUG "ECAM area %pR not reserved in ACPI namespace\n", &cfgres); =20 - cfg =3D pci_ecam_create(dev, &cfgres, bus_res, &pci_generic_ecam_ops); + cfg =3D pci_ecam_create(dev, &cfgres, bus_res, ecam_ops); if (IS_ERR(cfg)) { dev_err(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 =20 /* 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); =20 -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 =3D &pci_generic_ecam_ops; + struct resource *bus_res =3D &root->secondary; + u16 seg =3D 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; =20 /* * 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 *b= us_res) */ list_for_each_entry(e, &pci_mcfg_list, list) { if (e->segment =3D=3D seg && e->bus_start =3D=3D bus_res->start && - e->bus_end >=3D bus_res->end) - return e->addr; + e->bus_end >=3D bus_res->end) { + root->mcfg_addr =3D e->addr; + } + } =20 + if (!root->mcfg_addr) + return -ENXIO; + +skip_lookup: + memset(&res, 0, sizeof(res)); + res.start =3D root->mcfg_addr + (bus_res->start << 20); + res.end =3D res.start + (resource_size(bus_res) << 20) - 1; + res.flags =3D IORESOURCE_MEM; + *cfgres =3D res; + *ecam_ops =3D ops; return 0; } =20 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(str= uct acpi_device *dev) } extern phys_addr_t acpi_pci_root_get_mcfg_addr(acpi_handle handle); =20 -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 *cf= gres, + struct pci_ecam_ops **ecam_ops); =20 static inline acpi_handle acpi_find_root_bridge_handle(struct pci_dev *pde= v) { --=20 2.9.3