aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomasz Nowicki <tn@semihalf.com>2016-05-30 17:14:20 +0200
committerGraeme Gregory <graeme.gregory@linaro.org>2016-06-07 14:09:23 +0100
commit9f3bc5b2029bc74cd10b02664adf7caf212f7153 (patch)
tree74a1312e9b800a635f39bdac05de2a8204ad0ce4
parent871dcc50a87a683a61c591aa9f3759bf2da2a2b7 (diff)
downloadleg-kernel-9f3bc5b2029bc74cd10b02664adf7caf212f7153.tar.gz
acpi: Add generic MCFG table handling
In order to handle PCI config space regions properly in ACPI, new MCFG interface is defined which does sanity checks on MCFG table and keeps its root pointer. The user is able to lookup MCFG regions based on host bridge root structure and domain:bus_start:bus_end touple. Use pci_mmcfg_late_init old prototype to avoid another function name. Signed-off-by: Tomasz Nowicki <tn@semihalf.com> Signed-off-by: Jayachandran C <jchandra@broadcom.com>
-rw-r--r--drivers/acpi/Kconfig3
-rw-r--r--drivers/acpi/Makefile1
-rw-r--r--drivers/acpi/pci_mcfg.c94
-rw-r--r--include/linux/pci-acpi.h2
-rw-r--r--include/linux/pci.h2
5 files changed, 101 insertions, 1 deletions
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index b7e2e776397d..f98c3287256e 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -217,6 +217,9 @@ config ACPI_PROCESSOR_IDLE
bool
select CPU_IDLE
+config ACPI_MCFG
+ bool
+
config ACPI_CPPC_LIB
bool
depends on ACPI_PROCESSOR
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index 251ce85a66fb..632e81feef69 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -40,6 +40,7 @@ acpi-$(CONFIG_ARCH_MIGHT_HAVE_ACPI_PDC) += processor_pdc.o
acpi-y += ec.o
acpi-$(CONFIG_ACPI_DOCK) += dock.o
acpi-y += pci_root.o pci_link.o pci_irq.o
+obj-$(CONFIG_ACPI_MCFG) += pci_mcfg.o
acpi-y += acpi_lpss.o acpi_apd.o
acpi-y += acpi_platform.o
acpi-y += acpi_pnp.o
diff --git a/drivers/acpi/pci_mcfg.c b/drivers/acpi/pci_mcfg.c
new file mode 100644
index 000000000000..1847f74833a3
--- /dev/null
+++ b/drivers/acpi/pci_mcfg.c
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2016 Broadcom
+ * Author: Jayachandran C <jchandra@broadcom.com>
+ * Copyright (C) 2016 Semihalf
+ * Author: Tomasz Nowicki <tn@semihalf.com>
+ *
+ * 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.
+ */
+
+#define pr_fmt(fmt) "ACPI: " fmt
+
+#include <linux/kernel.h>
+#include <linux/pci.h>
+#include <linux/pci-acpi.h>
+
+/* Root pointer to the mapped MCFG table */
+static struct acpi_table_mcfg *mcfg_table;
+static int mcfg_entries;
+
+int pci_mcfg_lookup(struct acpi_pci_root *root)
+{
+ struct acpi_mcfg_allocation *mptr, *entry = NULL;
+ struct resource *bus_res = &root->secondary;
+ int i;
+
+ if (mcfg_table) {
+ mptr = (struct acpi_mcfg_allocation *) &mcfg_table[1];
+ for (i = 0; i < mcfg_entries && !entry; i++, mptr++)
+ if (mptr->pci_segment == root->segment &&
+ mptr->start_bus_number == bus_res->start)
+ entry = mptr;
+ }
+
+ /* not found, use _CBA if available, else error */
+ if (!entry) {
+ if (root->mcfg_addr)
+ return root->mcfg_addr;
+ pr_err("%04x:%pR MCFG lookup failed\n", root->segment, bus_res);
+ return -ENOENT;
+ } else if (root->mcfg_addr && entry->address != root->mcfg_addr) {
+ pr_warn("%04x:%pR CBA %pa != MCFG %lx, using CBA\n",
+ root->segment, bus_res, &root->mcfg_addr,
+ (unsigned long)entry->address);
+ return 0;
+ }
+
+ /* found matching entry, bus range check */
+ if (entry->end_bus_number != bus_res->end) {
+ resource_size_t bus_end = min_t(resource_size_t,
+ entry->end_bus_number, bus_res->end);
+ pr_warn("%04x:%pR bus end mismatch, using %02lx\n",
+ root->segment, bus_res, (unsigned long)bus_end);
+ bus_res->end = bus_end;
+ }
+
+ if (!root->mcfg_addr)
+ root->mcfg_addr = entry->address;
+ return 0;
+}
+
+static __init int pci_mcfg_parse(struct acpi_table_header *header)
+{
+ if (header->length < sizeof(struct acpi_table_mcfg))
+ return -EINVAL;
+
+ mcfg_entries = (header->length - sizeof(struct acpi_table_mcfg)) /
+ sizeof(struct acpi_mcfg_allocation);
+ if (mcfg_entries == 0) {
+ pr_err("MCFG has no entries\n");
+ return -EINVAL;
+ }
+
+ mcfg_table = (struct acpi_table_mcfg *)header;
+ pr_info("MCFG table detected, %d entries\n", mcfg_entries);
+ return 0;
+}
+
+/* Interface called by ACPI - parse and save MCFG table */
+void __init pci_mmcfg_late_init(void)
+{
+ int err = acpi_table_parse(ACPI_SIG_MCFG, pci_mcfg_parse);
+ if (err)
+ pr_err("Failed to parse MCFG (%d)\n", err);
+}
diff --git a/include/linux/pci-acpi.h b/include/linux/pci-acpi.h
index 89ab0572dbc6..e0e6dfc9f94c 100644
--- a/include/linux/pci-acpi.h
+++ b/include/linux/pci-acpi.h
@@ -24,6 +24,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 int pci_mcfg_lookup(struct acpi_pci_root *root);
+
static inline acpi_handle acpi_find_root_bridge_handle(struct pci_dev *pdev)
{
struct pci_bus *pbus = pdev->bus;
diff --git a/include/linux/pci.h b/include/linux/pci.h
index bba4053a75e0..9661c8572d21 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1724,7 +1724,7 @@ void pcibios_free_irq(struct pci_dev *dev);
extern struct dev_pm_ops pcibios_pm_ops;
#endif
-#ifdef CONFIG_PCI_MMCONFIG
+#if defined(CONFIG_PCI_MMCONFIG) || defined(CONFIG_ACPI_MCFG)
void __init pci_mmcfg_early_init(void);
void __init pci_mmcfg_late_init(void);
#else