All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Bjorn Helgaas <helgaas@kernel.org>,
	x86@kernel.org, Peter Anvin <hpa@zytor.com>,
	Borislav Petkov <bp@alien8.de>,
	Peter Zijlstra <peterz@infradead.org>,
	Stephane Eranian <eranian@google.com>,
	Andi Kleen <ak@linux.intel.com>
Subject: [patch 7/7] x86/pci/mmcfg: Switch to ECAM config mode if possible
Date: Thu, 16 Mar 2017 22:50:09 +0100	[thread overview]
Message-ID: <20170316215057.452220163@linutronix.de> (raw)
In-Reply-To: 20170316215002.726697858@linutronix.de

[-- Attachment #1: x86-pci-mmcfg--Switch-to-ECAM-config-mode-if-possible.patch --]
[-- Type: text/plain, Size: 4282 bytes --]

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 <tglx@linutronix.de>
---
 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(-)

--- a/arch/x86/include/asm/pci_x86.h
+++ b/arch/x86/include/asm/pci_x86.h
@@ -46,20 +46,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 {
@@ -120,11 +114,10 @@ extern void __init dmi_check_skip_isa_al
 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)
 
@@ -139,6 +132,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);
--- a/arch/x86/pci/common.c
+++ b/arch/x86/pci/common.c
@@ -157,6 +157,22 @@ static void pcibios_fixup_device_resourc
 }
 
 /*
+ * 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.
  */
--- 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();
--- a/arch/x86/pci/mmconfig-shared.c
+++ b/arch/x86/pci/mmconfig-shared.c
@@ -822,3 +822,33 @@ int pci_mmconfig_delete(u16 seg, u8 star
 
 	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");
+}

  parent reply	other threads:[~2017-03-16 23:12 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-16 21:50 [patch 0/7] x86/pci: Switch to lockless ECAM configuration mode Thomas Gleixner
2017-03-16 21:50 ` [patch 1/7] x86/pci: Remove duplicate defines Thomas Gleixner
2017-06-27 20:57   ` Bjorn Helgaas
2017-06-28 20:43   ` [tip:x86/platform] x86/PCI: " tip-bot for Thomas Gleixner
2017-03-16 21:50 ` [patch 2/7] x86/pci: Abort if legacy init fails Thomas Gleixner
2017-06-27 20:59   ` Bjorn Helgaas
2017-06-28 20:44   ` [tip:x86/platform] x86/PCI: " tip-bot for Thomas Gleixner
2017-03-16 21:50 ` [patch 3/7] x86/pci/ce4100: Properly lock accessor functions Thomas Gleixner
2017-03-17  0:28   ` Andi Kleen
2017-06-27 21:00   ` Bjorn Helgaas
2017-06-28 20:44   ` [tip:x86/platform] x86/PCI/ce4100: " tip-bot for Thomas Gleixner
2017-03-16 21:50 ` [patch 4/7] PCI: Provide Kconfig option for lockless config space accessors Thomas Gleixner
2017-06-27 21:11   ` Bjorn Helgaas
2017-06-28 20:31     ` Thomas Gleixner
2017-06-28 20:45   ` [tip:x86/platform] " tip-bot for Thomas Gleixner
2017-03-16 21:50 ` [patch 5/7] x86/pci: Select CONFIG_PCI_LOCKLESS_CONFIG Thomas Gleixner
2017-06-28 20:45   ` [tip:x86/platform] x86/PCI: " tip-bot for Thomas Gleixner
2017-03-16 21:50 ` [patch 6/7] x86/pci/mmcfg: Include 32/64 bit code into shared code Thomas Gleixner
2017-03-17  0:25   ` Andi Kleen
2017-03-17  8:41     ` Thomas Gleixner
2017-03-16 21:50 ` Thomas Gleixner [this message]
2017-03-17  0:26   ` [patch 7/7] x86/pci/mmcfg: Switch to ECAM config mode if possible Andi Kleen
2017-03-17  6:15     ` Thomas Gleixner
2017-06-27 21:31       ` Bjorn Helgaas
2017-06-28 20:46   ` [tip:x86/platform] x86/PCI/mmcfg: " tip-bot for Thomas Gleixner
2017-06-29  6:45   ` tip-bot for Thomas Gleixner
2017-06-29 23:26     ` Yinghai Lu
2017-06-30  3:18       ` Andi Kleen
2017-06-30 14:30         ` Thomas Gleixner
2017-06-30 17:16           ` Linus Torvalds
2017-06-30 18:30             ` Ivan Kokshaysky
2017-06-30 18:46             ` Thomas Gleixner
2017-06-13  0:25 ` [patch 0/7] x86/pci: Switch to lockless ECAM configuration mode Andi Kleen
2017-06-21 22:28   ` Thomas Gleixner
2017-06-27 20:55     ` Bjorn Helgaas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170316215057.452220163@linutronix.de \
    --to=tglx@linutronix.de \
    --cc=ak@linux.intel.com \
    --cc=bp@alien8.de \
    --cc=eranian@google.com \
    --cc=helgaas@kernel.org \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.