Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751942AbdF1UvO (ORCPT ); Wed, 28 Jun 2017 16:51:14 -0400 Received: from terminus.zytor.com ([65.50.211.136]:55383 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751574AbdF1UvH (ORCPT ); Wed, 28 Jun 2017 16:51:07 -0400 Date: Wed, 28 Jun 2017 13:46:31 -0700 From: tip-bot for Thomas Gleixner Message-ID: Cc: bp@alien8.de, linux-kernel@vger.kernel.org, eranian@google.com, hpa@zytor.com, mingo@kernel.org, helgaas@kernel.org, ak@linux.intel.com, tglx@linutronix.de, peterz@infradead.org Reply-To: helgaas@kernel.org, mingo@kernel.org, hpa@zytor.com, linux-kernel@vger.kernel.org, eranian@google.com, bp@alien8.de, tglx@linutronix.de, peterz@infradead.org, ak@linux.intel.com In-Reply-To: <20170316215057.452220163@linutronix.de> References: <20170316215057.452220163@linutronix.de> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/platform] x86/PCI/mmcfg: Switch to ECAM config mode if possible Git-Commit-ID: 5d381c2e053918bd67c2d1cc50fc73c35bd547f7 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5436 Lines: 169 Commit-ID: 5d381c2e053918bd67c2d1cc50fc73c35bd547f7 Gitweb: http://git.kernel.org/tip/5d381c2e053918bd67c2d1cc50fc73c35bd547f7 Author: Thomas Gleixner AuthorDate: Thu, 16 Mar 2017 22:50:09 +0100 Committer: Thomas Gleixner CommitDate: Wed, 28 Jun 2017 22:32:57 +0200 x86/PCI/mmcfg: Switch to ECAM config mode if possible To allow lockless access to the whole PCI configuration space the mmconfig based accessor functions need to be propagated to the pci_root_ops. Unfortunatly this cannot be done before the PCI subsystem initialization happens even if mmconfig access is already available. The reason is that some of the special platform PCI implementations must be able to overrule that setting before further accesses happen. The earliest possible point is after x86_init.pci.init() has been run. This is at a point in the boot process where nothing actually uses the PCI devices so the accessor function pointers can be updated lockless w/o risk. The switch to full ECAM mode depends on the availability of mmconfig and unchanged default accessors. Signed-off-by: Thomas Gleixner Acked-by: Bjorn Helgaas Cc: Andi Kleen Cc: Peter Zijlstra Cc: Stephane Eranian Cc: Borislav Petkov Cc: linux-pci@vger.kernel.org Link: http://lkml.kernel.org/r/20170316215057.452220163@linutronix.de Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/pci_x86.h | 15 +++++++-------- arch/x86/pci/common.c | 16 ++++++++++++++++ arch/x86/pci/legacy.c | 1 + arch/x86/pci/mmconfig-shared.c | 30 ++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/pci_x86.h b/arch/x86/include/asm/pci_x86.h index 9f1b21f..ad518a9 100644 --- a/arch/x86/include/asm/pci_x86.h +++ b/arch/x86/include/asm/pci_x86.h @@ -48,20 +48,14 @@ enum pci_bf_sort_state { pci_dmi_bf, }; -/* pci-i386.c */ - void pcibios_resource_survey(void); void pcibios_set_cache_line_size(void); -/* pci-pc.c */ - extern int pcibios_last_bus; extern struct pci_ops pci_root_ops; void pcibios_scan_specific_bus(int busn); -/* pci-irq.c */ - struct irq_info { u8 bus, devfn; /* Bus, device and function */ struct { @@ -122,11 +116,10 @@ extern void __init dmi_check_skip_isa_align(void); extern int __init pci_acpi_init(void); extern void __init pcibios_irq_init(void); extern int __init pcibios_init(void); +extern void __init pcibios_select_ops(void); extern int pci_legacy_init(void); extern void pcibios_fixup_irqs(void); -/* pci-mmconfig.c */ - /* "PCI MMCONFIG %04x [bus %02x-%02x]" */ #define PCI_MMCFG_RESOURCE_NAME_LEN (22 + 4 + 2 + 2) @@ -141,6 +134,12 @@ struct pci_mmcfg_region { char name[PCI_MMCFG_RESOURCE_NAME_LEN]; }; +#ifdef CONFIG_PCI_MMCONFIG +extern void __init pci_mmcfg_select_ops(void); +#else +static inline void pci_mmcfg_select_ops(void) { } +#endif + extern int __init pci_mmcfg_arch_init(void); extern void __init pci_mmcfg_arch_free(void); extern int pci_mmcfg_arch_map(struct pci_mmcfg_region *cfg); diff --git a/arch/x86/pci/common.c b/arch/x86/pci/common.c index cfd1a89..81e4d21 100644 --- a/arch/x86/pci/common.c +++ b/arch/x86/pci/common.c @@ -157,6 +157,22 @@ static void pcibios_fixup_device_resources(struct pci_dev *dev) } /* + * Called after the last possible modification to raw_pci_[ext_]ops. + * + * Verify that root_pci_ops have not been overwritten by any implementation + * of x86_init.pci.arch_init() and x86_init.pci.init(). + * + * If not, let the mmconfig code decide whether the ops can be switched + * over to the ECAM accessor functions. + */ +void __init pcibios_select_ops(void) +{ + if (pci_root_ops.read != pci_read || pci_root_ops.write != pci_write) + return; + pci_mmcfg_select_ops(); +} + +/* * Called after each bus is probed, but before its children * are examined. */ diff --git a/arch/x86/pci/legacy.c b/arch/x86/pci/legacy.c index 1cb01ab..80ea40e 100644 --- a/arch/x86/pci/legacy.c +++ b/arch/x86/pci/legacy.c @@ -65,6 +65,7 @@ static int __init pci_subsys_init(void) } } + pcibios_select_ops(); pcibios_fixup_peer_bridges(); x86_init.pci.init_irq(); pcibios_init(); diff --git a/arch/x86/pci/mmconfig-shared.c b/arch/x86/pci/mmconfig-shared.c index d1b47d5..6af6351 100644 --- a/arch/x86/pci/mmconfig-shared.c +++ b/arch/x86/pci/mmconfig-shared.c @@ -816,3 +816,33 @@ int pci_mmconfig_delete(u16 seg, u8 start, u8 end) return -ENOENT; } + +static int pci_ecam_read(struct pci_bus *bus, unsigned int devfn, int reg, + int size, u32 *value) +{ + return pci_mmcfg_read(pci_domain_nr(bus), bus->number, devfn, reg, + size, value); +} + +static int pci_ecam_write(struct pci_bus *bus, unsigned int devfn, int reg, + int size, u32 value) +{ + return pci_mmcfg_write(pci_domain_nr(bus), bus->number, devfn, reg, + size, value); +} + +void __init pci_mmcfg_select_ops(void) +{ + if (raw_pci_ext_ops != &pci_mmcfg) + return; + + /* + * The pointer to root_pci_ops has been handed in to ACPI already + * and is already set in the busses. + * + * Switch the functions over to ECAM for all config space accesses. + */ + pci_root_ops.read = pci_ecam_read; + pci_root_ops.write = pci_ecam_write; + pr_info("PCI: Switch to ECAM configuration mode\n"); +}