ECAM quirks handling for ARM64 platforms
v5 cover ECAM quirks handling for ARM64 platforms
Quirk handling relies on an idea of matching MCFG OEM ID, TABLE ID and revision (the ones from standard header of MCFG table).
Static array is used to keep quirk entries. Each entry consists of mentioned MCFG IDs along with custom pci_ops structure and initialization call.
As an example, the last patch presents quirk handling mechanism usage for ThunderX PEM driver.
v4 -> v5
- rebase against v4.8-rc1
- rework to exact MCFG OEM ID, TABLE ID, rev match
- use memcmp instead of strncmp
- no substring match
- fix typos and dmesg message
Tomasz Nowicki (5):
PCI: Embed pci_ecam_ops in pci_config_window structure PCI/ACPI: Move ACPI ECAM mapping to generic MCFG driver
PCI: Check platform specific ECAM quirks
ARM64/PCI: Start using quirks handling for ACPI based PCI host
controller
PCI: thunder-pem: Support quirky configuration space access for ACPI
based PCI host controller
arch/arm64/kernel/pci.c | 42 +---------------- drivers/acpi/pci_mcfg.c | 40 ++++++++++++++++ drivers/pci/ecam.c | 6 +-- drivers/pci/host/Makefile | 1 + drivers/pci/host/mcfg-quirks.c | 93 ++++++++++++++++++++++++++++++++++++ drivers/pci/host/mcfg-quirks.h | 24 ++++++++++ drivers/pci/host/pci-thunder-pem.c | 96 ++++++++++++++++++++++++++++++++------ include/linux/pci-acpi.h | 5 ++ include/linux/pci-ecam.h | 2 +- 9 files changed, 252 insertions(+), 57 deletions(-) create mode 100644 drivers/pci/host/mcfg-quirks.c create mode 100644 drivers/pci/host/mcfg-quirks.h
Signature · 1 line
1.9.1
RFC PATCH v5 1/5 PCI: Embed pci_ecam_ops in pci_config_window structure
pci_config_window keeps pointer to pci_ecam_ops and every time we want to deallocate pci_config_window (pci_ecam_free()) we need to make sure to free pci_ecam_ops in case it was dynamically allocated prior to pci_ecam_create() call.
To avoid that extra effort, embed pci_ecam_ops in pci_config_window, instead of just a pointer.
To: Jayachandran C <[email protected]>
--- arch/arm64/kernel/pci.c | 2 +- drivers/pci/ecam.c | 6 +++--- include/linux/pci-ecam.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
arch/arm64/kernel/pci.c +1 -1
@@ -183,7 +183,7 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)return NULL ; } - acpi_pci_root_ops.pci_ops = &ri->cfg->ops->pci_ops; + acpi_pci_root_ops.pci_ops = &ri->cfg->ops.pci_ops; bus =acpi_pci_root_create (root, &acpi_pci_root_ops, &ri->common, ri->cfg);if (!bus)
drivers/pci/ecam.c +3 -3
@@ -52,7 +52,7 @@ struct pci_config_window *pci_ecam_create(struct device *dev,return ERR_PTR (-ENOMEM ); cfg->parent = dev; - cfg->ops = ops; + cfg->ops = *ops; cfg->busr.start = busr->start; cfg->busr.end = busr->end; cfg->busr.flags =IORESOURCE_BUS ;
@@ -138,7 +138,7 @@ void __iomem *pci_ecam_map_bus(struct pci_bus *bus, unsigned int devfn, int where) {struct pci_config_window *cfg = bus->sysdata; -unsigned int devfn_shift = cfg->ops->bus_shift -8 ; +unsigned int devfn_shift = cfg->ops.bus_shift -8 ;unsigned int busn = bus->number;void __iomem *base;
@@ -149,7 +149,7 @@ void __iomem *pci_ecam_map_bus(struct pci_bus *bus, unsigned int devfn,if (per_bus_mapping) base = cfg->winp[busn];else - base = cfg->win + (busn << cfg->ops->bus_shift); + base = cfg->win + (busn << cfg->ops.bus_shift);return base + (devfn << devfn_shift) + where; }
include/linux/pci-ecam.h +1 -1
@@ -39,7 +39,7 @@ struct pci_config_window {struct resource res;struct resource busr;void *priv; -struct pci_ecam_ops *ops; +struct pci_ecam_ops ops;union {void __iomem *win;/* 64-bit single mapping */ void __iomem **winp;/* 32-bit per-bus mapping */
Signature · 1 line
1.9.1
RFC PATCH v5 2/5 PCI/ACPI: Move ACPI ECAM mapping to generic MCFG driver
In reply to Tomasz Nowickipci_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.
--- 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(-)
arch/arm64/kernel/pci.c +2 -39
@@ -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 ;
drivers/acpi/pci_mcfg.c +40 -0
@@ -22,6 +22,7 @@#include <linux/kernel.h> #include <linux/pci.h> #include <linux/pci-acpi.h> +#include <linux/pci-ecam.h> /* 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;
include/linux/pci-acpi.h +3 -0
@@ -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;
Signature · 1 line
1.9.1
RFC PATCH v5 3/5 PCI: Check platform specific ECAM quirks
In reply to Tomasz NowickiSome platforms may not be fully compliant with generic set of PCI config accessors. For these cases we implement the way to overwrite accessors set. Algorithm traverses available quirk list (static array), matches against <oem_id, oem_table_id, rev, domain, bus number range> and returns pci_config_window structure with fancy PCI config ops. oem_id, oem_table_id and rev come from MCFG table standard header.
It is possible to define custom init call which is responsible for setting up PCI configuration access accordingly to quirk requirements. If custom init call is not defined, use standard pci_acpi_setup_ecam_mapping().
pci_generic_ecam_ops will be used for platforms free from quirks.
--- drivers/pci/host/Makefile | 1 + drivers/pci/host/mcfg-quirks.c | 86 ++++++++++++++++++++++++++++++++++++++++++ drivers/pci/host/mcfg-quirks.h | 20 ++++++++++ include/linux/pci-acpi.h | 2 + 4 files changed, 109 insertions(+) create mode 100644 drivers/pci/host/mcfg-quirks.c create mode 100644 drivers/pci/host/mcfg-quirks.h
drivers/pci/host/Makefile +1 -0
@@ -31,3 +31,4 @@ obj-$(CONFIG_PCI_HOST_THUNDER_ECAM) += pci-thunder-ecam.o obj-$(CONFIG_PCI_HOST_THUNDER_PEM) += pci-thunder-pem.o obj-$(CONFIG_PCIE_ARMADA_8K) += pcie-armada8k.o obj-$(CONFIG_PCIE_ARTPEC6) += pcie-artpec6.o +obj-$(CONFIG_ACPI_MCFG) += mcfg-quirks.o
drivers/pci/host/mcfg-quirks.c new file +86 -0
86 lines not on this page · raw message
drivers/pci/host/mcfg-quirks.h new file +20 -0
@@ -0,0 +1,20 @@ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License, version 2, as +* published by the Free Software Foundation (the "GPL"). +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License version 2 (GPLv2) for more details. +* +* You should have received a copy of the GNU General Public License +* version 2 (GPLv2) along with this source code. +*/ + +#ifndef __MCFG_QUIRKS_H__ +#define __MCFG_QUIRKS_H__ + +/* MCFG quirks initialize call list */ + +#endif /* __MCFG_QUIRKS_H__ */
include/linux/pci-acpi.h +2 -0
@@ -25,6 +25,8 @@ 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); +extern struct pci_config_window * +pci_mcfg_match_quirks (struct acpi_pci_root *root);extern struct pci_config_window *pci_acpi_setup_ecam_mapping (struct acpi_pci_root *root,struct pci_ops *ops);
Signature · 1 line
1.9.1
RFC PATCH v5 4/5 ARM64/PCI: Start using quirks handling for ACPI based PCI host controller
In reply to Tomasz NowickiSince there are platforms which have non-compliant ECAM space we need to override these accessors prior to PCI buses enumeration. In order to do that we call pci_mcfg_match_quirks() to retrieve custom pci_config_window structure. If no correlated quirk on list, use fully ECAM compliant generic PCI config accessors.
--- arch/arm64/kernel/pci.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/arm64/kernel/pci.c +1 -2
@@ -139,8 +139,7 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)if (!ri)return NULL ; - ri->cfg =pci_acpi_setup_ecam_mapping (root, - &pci_generic_ecam_ops.pci_ops); + ri->cfg =pci_mcfg_match_quirks (root);if (!ri->cfg) {kfree (ri);return NULL ;
Signature · 1 line
1.9.1
RFC PATCH v5 5/5 PCI: thunder-pem: Support quirky configuration space access for ACPI based PCI host controller
In reply to Tomasz NowickiAdd infrastructure to support ThunderX PEM specific PCI configuration space access for ACPI based PCI host controller. This involves:
1. New initialization call thunder_pem_cfg_init() to create configuration space mapping based on hardcoded range addresses
2. thunder_pem_init() ACPI extension to obtain hardcoded addresses for PEM specific register ranges
3. New quirk entry (for common quirk array) which identifies platform and calls thunder_pem_cfg_init() from [1]
--- drivers/pci/host/mcfg-quirks.c | 7 +++ drivers/pci/host/mcfg-quirks.h | 4 ++ drivers/pci/host/pci-thunder-pem.c | 96 ++++++++++++++++++++++++++++++++------ 3 files changed, 94 insertions(+), 13 deletions(-)
drivers/pci/host/mcfg-quirks.c +7 -0
@@ -44,6 +44,13 @@ struct pci_cfg_fixup {static struct pci_cfg_fixup mcfg_quirks[]__initconst = {/* { OEM_ID, OEM_TABLE_ID, REV, DOMAIN, BUS_RANGE, pci_ops, init_hook }, */ +#ifdef CONFIG_PCI_HOST_THUNDER_PEM +/* Pass2.0 */ + {"CAVIUM" ,"THUNDERX" ,1 ,MCFG_DOM_RANGE (4 ,9 ),MCFG_BUS_ANY ,NULL , + thunder_pem_cfg_init }, + {"CAVIUM" ,"THUNDERX" ,1 ,MCFG_DOM_RANGE (14 ,19 ),MCFG_BUS_ANY ,NULL , + thunder_pem_cfg_init }, +#endif }; static bool pci_mcfg_fixup_match(struct pci_cfg_fixup *f,
drivers/pci/host/mcfg-quirks.h +4 -0
@@ -16,5 +16,9 @@#define __MCFG_QUIRKS_H__/* MCFG quirks initialize call list */ +#ifdef CONFIG_PCI_HOST_THUNDER_PEM +struct pci_config_window * +thunder_pem_cfg_init (struct acpi_pci_root *root,struct pci_ops *ops); +#endif #endif /* __MCFG_QUIRKS_H__ */
drivers/pci/host/pci-thunder-pem.c +83 -13
125 lines not on this page · raw message
Signature · 1 line
1.9.1
v5 cover ECAM quirks handling for ARM64 platforms
In reply to Tomasz NowickiPlease disregard this series since I missed ACPI mailing list on CC. Sorry for noise.
Regards,
Tomasz
Quoted 38 lines · Tomasz Nowicki
Quirk handling relies on an idea of matching MCFG OEM ID, TABLE ID and revision (the ones from standard header of MCFG table).
Static array is used to keep quirk entries. Each entry consists of mentioned MCFG IDs along with custom
pci_opsstructure and initialization call.As an example, the last patch presents quirk handling mechanism usage for ThunderX PEM driver.
v4 -> v5
- rebase against v4.8-rc1
- rework to exact MCFG OEM ID, TABLE ID, rev match
- use memcmp instead of strncmp
- no substring match
- fix typos and dmesg messageTomasz Nowicki (5):
PCI: Embedpci_ecam_opsinpci_config_windowstructure PCI/ACPI: Move ACPI ECAM mapping to generic MCFG driver
PCI: Check platform specific ECAM quirks
ARM64/PCI: Start using quirks handling for ACPI based PCI host
controller
PCI: thunder-pem: Support quirky configuration space access for ACPI
based PCI host controllerarch/arm64/kernel/pci.c | 42 +---------------- drivers/acpi/pci_mcfg.c | 40 ++++++++++++++++ drivers/pci/ecam.c | 6 +-- drivers/pci/host/Makefile | 1 + drivers/pci/host/mcfg-quirks.c | 93 ++++++++++++++++++++++++++++++++++++ drivers/pci/host/mcfg-quirks.h | 24 ++++++++++ drivers/pci/host/pci-thunder-pem.c | 96 ++++++++++++++++++++++++++++++++------ include/linux/pci-acpi.h | 5 ++ include/linux/pci-ecam.h | 2 +- 9 files changed, 252 insertions(+), 57 deletions(-) create mode 100644 drivers/pci/host/mcfg-quirks.c create mode 100644 drivers/pci/host/mcfg-quirks.h
v5 cover ECAM quirks handling for ARM64 platforms
In reply to Tomasz NowickiQuoted 9 lines · Tomasz Nowicki
Quirk handling relies on an idea of matching MCFG OEM ID, TABLE ID and revision (the ones from standard header of MCFG table).
Static array is used to keep quirk entries. Each entry consists of mentioned MCFG IDs along with custom
pci_opsstructure and initialization call.As an example, the last patch presents quirk handling mechanism usage for ThunderX PEM driver.
Hi Tomasz,
Are you planning to change this series into a real one (not RFC) any time soon?
Quoted 30 lines
v4 -> v5
- rebase against v4.8-rc1
- rework to exact MCFG OEM ID, TABLE ID, rev match
- use memcmp instead of strncmp
- no substring match
- fix typos and dmesg messageTomasz Nowicki (5):
PCI: Embedpci_ecam_opsinpci_config_windowstructure PCI/ACPI: Move ACPI ECAM mapping to generic MCFG driver
PCI: Check platform specific ECAM quirks
ARM64/PCI: Start using quirks handling for ACPI based PCI host
controller
PCI: thunder-pem: Support quirky configuration space access for ACPI
based PCI host controllerarch/arm64/kernel/pci.c | 42 +---------------- drivers/acpi/pci_mcfg.c | 40 ++++++++++++++++ drivers/pci/ecam.c | 6 +-- drivers/pci/host/Makefile | 1 + drivers/pci/host/mcfg-quirks.c | 93 ++++++++++++++++++++++++++++++++++++ drivers/pci/host/mcfg-quirks.h | 24 ++++++++++ drivers/pci/host/pci-thunder-pem.c | 96 ++++++++++++++++++++++++++++++++------ include/linux/pci-acpi.h | 5 ++ include/linux/pci-ecam.h | 2 +- 9 files changed, 252 insertions(+), 57 deletions(-) create mode 100644 drivers/pci/host/mcfg-quirks.c create mode 100644 drivers/pci/host/mcfg-quirks.h
Quoted 3 lines
--
1.9.1
Regards,
Duc Dang.
v5 cover ECAM quirks handling for ARM64 platforms
Quoted 8 lines · Duc Dang
Quoted 7 lines · Tomasz Nowicki
Quirk handling relies on an idea of matching MCFG OEM ID, TABLE ID and revision (the ones from standard header of MCFG table).
Static array is used to keep quirk entries. Each entry consists of mentioned MCFG IDs along with custom
pci_opsstructure and initialization call.
Quoted 6 lines
Quoted 2 lines
As an example, the last patch presents quirk handling mechanism usage for ThunderX PEM driver.
Hi Tomasz,
Are you planning to change this series into a real one (not RFC) any time soon?
Yes, but first I would like to collect more feedback.
BTW please respond to https://lkml.org/lkml/2016/8/8/273
This series misses ACPI mailing list so I decided to resend it.
Tomasz