86429d3
From 965e95a91066290f6555546f066a6e2aaba1199e Mon Sep 17 00:00:00 2001
a84c022
From: Peter Robinson <pbrobinson@gmail.com>
a84c022
Date: Tue, 5 Jul 2016 23:49:39 +0100
86429d3
Subject: [PATCH] Some platforms may not be fully compliant with generic set of
86429d3
 PCI config accessors. For these cases we implement the way to overwrite
86429d3
 accessors set. Algorithm traverses available quirk list, matches against
86429d3
 <oem_id, oem_table_id, domain, bus number> tuple and returns corresponding
86429d3
 PCI config ops. oem_id and oem_table_id come from MCFG table standard header.
86429d3
 All quirks can be defined using DECLARE_ACPI_MCFG_FIXUP() macro and kept self
86429d3
 contained. Example:
a84c022
a84c022
/* Custom PCI config ops */
a84c022
static struct pci_generic_ecam_ops foo_pci_ops = {
a84c022
        .bus_shift      = 24,
a84c022
        .pci_ops = {
a84c022
                .map_bus = pci_ecam_map_bus,
a84c022
                .read = foo_ecam_config_read,
a84c022
                .write = foo_ecam_config_write,
a84c022
        }
a84c022
};
a84c022
a84c022
DECLARE_ACPI_MCFG_FIXUP(&foo_pci_ops, <oem_id_str>, <oem_table_id>, <domain_nr>, <bus_nr>);
a84c022
a84c022
Signed-off-by: Tomasz Nowicki <tn@semihalf.com>
a84c022
Signed-off-by: Dongdong Liu <liudongdong3@huawei.com>
a84c022
---
a84c022
 drivers/acpi/pci_mcfg.c           | 41 ++++++++++++++++++++++++++++++++++++---
a84c022
 include/asm-generic/vmlinux.lds.h |  7 +++++++
a84c022
 include/linux/pci-acpi.h          | 20 +++++++++++++++++++
a84c022
 3 files changed, 65 insertions(+), 3 deletions(-)
a84c022
a84c022
diff --git a/drivers/acpi/pci_mcfg.c b/drivers/acpi/pci_mcfg.c
86429d3
index b5b376e..a5c9067 100644
a84c022
--- a/drivers/acpi/pci_mcfg.c
a84c022
+++ b/drivers/acpi/pci_mcfg.c
a84c022
@@ -22,6 +22,10 @@
a84c022
 #include <linux/kernel.h>
a84c022
 #include <linux/pci.h>
a84c022
 #include <linux/pci-acpi.h>
a84c022
+#include <linux/pci-ecam.h>
a84c022
+
a84c022
+/* Root pointer to the mapped MCFG table */
a84c022
+static struct acpi_table_mcfg *mcfg_table;
a84c022
 
a84c022
 /* Structure to hold entries from the MCFG table */
a84c022
 struct mcfg_entry {
a84c022
@@ -35,6 +39,38 @@ struct mcfg_entry {
86429d3
 /* List to save MCFG entries */
a84c022
 static LIST_HEAD(pci_mcfg_list);
a84c022
 
a84c022
+extern struct pci_cfg_fixup __start_acpi_mcfg_fixups[];
a84c022
+extern struct pci_cfg_fixup __end_acpi_mcfg_fixups[];
a84c022
+
a84c022
+struct pci_ecam_ops *pci_mcfg_get_ops(struct acpi_pci_root *root)
a84c022
+{
a84c022
+       int bus_num = root->secondary.start;
a84c022
+       int domain = root->segment;
a84c022
+       struct pci_cfg_fixup *f;
a84c022
+
a84c022
+       if (!mcfg_table)
a84c022
+               return &pci_generic_ecam_ops;
a84c022
+
a84c022
+       /*
a84c022
+        * Match against platform specific quirks and return corresponding
a84c022
+        * CAM ops.
a84c022
+        *
a84c022
+        * First match against PCI topology <domain:bus> then use OEM ID and
a84c022
+        * OEM revision from MCFG table standard header.
a84c022
+        */
a84c022
+       for (f = __start_acpi_mcfg_fixups; f < __end_acpi_mcfg_fixups; f++) {
a84c022
+               if ((f->domain == domain || f->domain == PCI_MCFG_DOMAIN_ANY) &&
a84c022
+                   (f->bus_num == bus_num || f->bus_num == PCI_MCFG_BUS_ANY) &&
a84c022
+                   (!strncmp(f->oem_id, mcfg_table->header.oem_id,
a84c022
+                             ACPI_OEM_ID_SIZE)) &&
a84c022
+                   (!strncmp(f->oem_table_id, mcfg_table->header.oem_table_id,
a84c022
+                             ACPI_OEM_TABLE_ID_SIZE)))
a84c022
+                       return f->ops;
a84c022
+       }
a84c022
+       /* No quirks, use ECAM */
a84c022
+       return &pci_generic_ecam_ops;
a84c022
+}
a84c022
+
a84c022
 phys_addr_t pci_mcfg_lookup(u16 seg, struct resource *bus_res)
a84c022
 {
a84c022
 	struct mcfg_entry *e;
a84c022
@@ -54,7 +90,6 @@ phys_addr_t pci_mcfg_lookup(u16 seg, struct resource *bus_res)
a84c022
 
a84c022
 static __init int pci_mcfg_parse(struct acpi_table_header *header)
a84c022
 {
a84c022
-	struct acpi_table_mcfg *mcfg;
a84c022
 	struct acpi_mcfg_allocation *mptr;
a84c022
 	struct mcfg_entry *e, *arr;
a84c022
 	int i, n;
a84c022
@@ -64,8 +99,8 @@ static __init int pci_mcfg_parse(struct acpi_table_header *header)
a84c022
 
a84c022
 	n = (header->length - sizeof(struct acpi_table_mcfg)) /
a84c022
 					sizeof(struct acpi_mcfg_allocation);
a84c022
-	mcfg = (struct acpi_table_mcfg *)header;
a84c022
-	mptr = (struct acpi_mcfg_allocation *) &mcfg[1];
a84c022
+	mcfg_table = (struct acpi_table_mcfg *)header;
a84c022
+	mptr = (struct acpi_mcfg_allocation *) &mcfg_table[1];
a84c022
 
a84c022
 	arr = kcalloc(n, sizeof(*arr), GFP_KERNEL);
a84c022
 	if (!arr)
a84c022
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
86429d3
index 2456397..c49bd36 100644
a84c022
--- a/include/asm-generic/vmlinux.lds.h
a84c022
+++ b/include/asm-generic/vmlinux.lds.h
86429d3
@@ -308,6 +308,13 @@
a84c022
 		VMLINUX_SYMBOL(__end_pci_fixups_suspend_late) = .;	\
a84c022
 	}								\
a84c022
 									\
a84c022
+	/* ACPI MCFG quirks */						\
a84c022
+	.acpi_fixup        : AT(ADDR(.acpi_fixup) - LOAD_OFFSET) {	\
a84c022
+		VMLINUX_SYMBOL(__start_acpi_mcfg_fixups) = .;		\
a84c022
+		*(.acpi_fixup_mcfg)					\
a84c022
+		VMLINUX_SYMBOL(__end_acpi_mcfg_fixups) = .;		\
a84c022
+	}								\
a84c022
+									\
a84c022
 	/* Built-in firmware blobs */					\
a84c022
 	.builtin_fw        : AT(ADDR(.builtin_fw) - LOAD_OFFSET) {	\
a84c022
 		VMLINUX_SYMBOL(__start_builtin_fw) = .;			\
a84c022
diff --git a/include/linux/pci-acpi.h b/include/linux/pci-acpi.h
a84c022
index 7d63a66..c8a6559 100644
a84c022
--- a/include/linux/pci-acpi.h
a84c022
+++ b/include/linux/pci-acpi.h
a84c022
@@ -25,6 +25,7 @@ static inline acpi_status pci_acpi_remove_pm_notifier(struct acpi_device *dev)
a84c022
 extern phys_addr_t acpi_pci_root_get_mcfg_addr(acpi_handle handle);
a84c022
 
a84c022
 extern phys_addr_t pci_mcfg_lookup(u16 domain, struct resource *bus_res);
a84c022
+extern struct pci_ecam_ops *pci_mcfg_get_ops(struct acpi_pci_root *root);
a84c022
 
a84c022
 static inline acpi_handle acpi_find_root_bridge_handle(struct pci_dev *pdev)
a84c022
 {
a84c022
@@ -72,6 +73,25 @@ struct acpi_pci_root_ops {
a84c022
 	int (*prepare_resources)(struct acpi_pci_root_info *info);
a84c022
 };
a84c022
 
a84c022
+struct pci_cfg_fixup {
a84c022
+       struct pci_ecam_ops *ops;
a84c022
+       char *oem_id;
a84c022
+       char *oem_table_id;
a84c022
+       int domain;
a84c022
+       int bus_num;
a84c022
+};
a84c022
+
a84c022
+#define PCI_MCFG_DOMAIN_ANY    -1
a84c022
+#define PCI_MCFG_BUS_ANY       -1
a84c022
+
a84c022
+/* Designate a routine to fix up buggy MCFG */
a84c022
+#define DECLARE_ACPI_MCFG_FIXUP(ops, oem_id, oem_table_id, dom, bus)   \
a84c022
+       static const struct pci_cfg_fixup                               \
a84c022
+       __mcfg_fixup_##oem_id##oem_table_id##dom##bus                   \
a84c022
+       __used  __attribute__((__section__(".acpi_fixup_mcfg"),         \
a84c022
+                               aligned((sizeof(void *))))) =           \
a84c022
+       { ops, oem_id, oem_table_id, dom, bus };
a84c022
+
a84c022
 extern int acpi_pci_probe_root_resources(struct acpi_pci_root_info *info);
a84c022
 extern struct pci_bus *acpi_pci_root_create(struct acpi_pci_root *root,
a84c022
 					    struct acpi_pci_root_ops *ops,
a84c022
-- 
86429d3
2.9.2
a84c022
86429d3
From 817d09d7650319a827f00bd3b4c9b407d3977ba0 Mon Sep 17 00:00:00 2001
a84c022
From: Peter Robinson <pbrobinson@gmail.com>
a84c022
Date: Tue, 5 Jul 2016 23:52:46 +0100
86429d3
Subject: [PATCH] pci_generic_ecam_ops is used by default. Since there are
a84c022
 platforms which have non-compliant ECAM space we need to overwrite these
a84c022
 accessors prior to PCI buses enumeration. In order to do that we call
a84c022
 pci_mcfg_get_ops to retrieve pci_ecam_ops structure so that we can use proper
a84c022
 PCI config space accessors and bus_shift.
a84c022
a84c022
pci_generic_ecam_ops is still used for platforms free from quirks.
a84c022
a84c022
Signed-off-by: Tomasz Nowicki <tn@semihalf.com>
a84c022
---
a84c022
 arch/arm64/kernel/pci.c | 7 ++++---
a84c022
 1 file changed, 4 insertions(+), 3 deletions(-)
a84c022
a84c022
diff --git a/arch/arm64/kernel/pci.c b/arch/arm64/kernel/pci.c
86429d3
index acf3872..ec513f1 100644
a84c022
--- a/arch/arm64/kernel/pci.c
a84c022
+++ b/arch/arm64/kernel/pci.c
86429d3
@@ -126,6 +126,7 @@ pci_acpi_setup_ecam_mapping(struct acpi_pci_root *root)
a84c022
 	struct pci_config_window *cfg;
a84c022
 	struct resource cfgres;
a84c022
 	unsigned int bsz;
a84c022
+	struct pci_ecam_ops *ops;
a84c022
 
a84c022
 	/* Use address from _CBA if present, otherwise lookup MCFG */
a84c022
 	if (!root->mcfg_addr)
86429d3
@@ -137,12 +138,12 @@ pci_acpi_setup_ecam_mapping(struct acpi_pci_root *root)
a84c022
 		return NULL;
a84c022
 	}
a84c022
 
a84c022
-	bsz = 1 << pci_generic_ecam_ops.bus_shift;
a84c022
+	ops = pci_mcfg_get_ops(root);
a84c022
+	bsz = 1 << ops->bus_shift;
a84c022
 	cfgres.start = root->mcfg_addr + bus_res->start * bsz;
a84c022
 	cfgres.end = cfgres.start + resource_size(bus_res) * bsz - 1;
a84c022
 	cfgres.flags = IORESOURCE_MEM;
a84c022
-	cfg = pci_ecam_create(&root->device->dev, &cfgres, bus_res,
a84c022
-			      &pci_generic_ecam_ops);
a84c022
+	cfg = pci_ecam_create(&root->device->dev, &cfgres, bus_res, ops);
a84c022
 	if (IS_ERR(cfg)) {
a84c022
 		dev_err(&root->device->dev, "%04x:%pR error %ld mapping ECAM\n",
a84c022
 			seg, bus_res, PTR_ERR(cfg));
a84c022
-- 
86429d3
2.9.2
a84c022
86429d3
From ac5cff2e2304a1969e39e967567aa41cade1839f Mon Sep 17 00:00:00 2001
a84c022
From: Peter Robinson <pbrobinson@gmail.com>
a84c022
Date: Tue, 5 Jul 2016 23:53:59 +0100
86429d3
Subject: [PATCH] The ECAM quirk matching criteria per the discussion on
a84c022
 https://lkml.org/lkml/2016/6/13/944 includes: OEM ID, OEM Table ID and OEM
a84c022
 Revision. So this patch adds OEM Table ID into the check to match platform
a84c022
 specific ECAM quirks as well.
a84c022
a84c022
This patch also improve strncmp check using strlen and
a84c022
min_t to ignore the padding spaces in OEM ID and OEM
a84c022
Table ID.
a84c022
a84c022
Signed-off-by: Duc Dang <dhdang@apm.com>
a84c022
---
a84c022
 drivers/acpi/pci_mcfg.c  | 7 +++++--
a84c022
 include/linux/pci-acpi.h | 7 ++++---
a84c022
 2 files changed, 9 insertions(+), 5 deletions(-)
a84c022
a84c022
diff --git a/drivers/acpi/pci_mcfg.c b/drivers/acpi/pci_mcfg.c
86429d3
index a5c9067..5137d16 100644
a84c022
--- a/drivers/acpi/pci_mcfg.c
a84c022
+++ b/drivers/acpi/pci_mcfg.c
a84c022
@@ -62,9 +62,12 @@ struct pci_ecam_ops *pci_mcfg_get_ops(struct acpi_pci_root *root)
a84c022
                if ((f->domain == domain || f->domain == PCI_MCFG_DOMAIN_ANY) &&
a84c022
                    (f->bus_num == bus_num || f->bus_num == PCI_MCFG_BUS_ANY) &&
a84c022
                    (!strncmp(f->oem_id, mcfg_table->header.oem_id,
a84c022
-                             ACPI_OEM_ID_SIZE)) &&
a84c022
+                             min_t(size_t, strlen(f->oem_id),
a84c022
+                                   ACPI_OEM_ID_SIZE))) &&
a84c022
                    (!strncmp(f->oem_table_id, mcfg_table->header.oem_table_id,
a84c022
-                             ACPI_OEM_TABLE_ID_SIZE)))
a84c022
+                             min_t(size_t, strlen(f->oem_table_id),
a84c022
+                                   ACPI_OEM_TABLE_ID_SIZE))) &&
a84c022
+                   (f->oem_revision == mcfg_table->header.oem_revision))
a84c022
                        return f->ops;
a84c022
        }
a84c022
        /* No quirks, use ECAM */
a84c022
diff --git a/include/linux/pci-acpi.h b/include/linux/pci-acpi.h
a84c022
index c8a6559..5148c8d 100644
a84c022
--- a/include/linux/pci-acpi.h
a84c022
+++ b/include/linux/pci-acpi.h
a84c022
@@ -77,6 +77,7 @@ struct pci_cfg_fixup {
a84c022
        struct pci_ecam_ops *ops;
a84c022
        char *oem_id;
a84c022
        char *oem_table_id;
a84c022
+       u32 oem_revision;
a84c022
        int domain;
a84c022
        int bus_num;
a84c022
 };
a84c022
@@ -85,12 +86,12 @@ struct pci_cfg_fixup {
a84c022
 #define PCI_MCFG_BUS_ANY       -1
a84c022
 
a84c022
 /* Designate a routine to fix up buggy MCFG */
a84c022
-#define DECLARE_ACPI_MCFG_FIXUP(ops, oem_id, oem_table_id, dom, bus)   \
a84c022
+#define DECLARE_ACPI_MCFG_FIXUP(ops, oem_id, oem_table_id, rev, dom, bus) \
a84c022
        static const struct pci_cfg_fixup                               \
a84c022
-       __mcfg_fixup_##oem_id##oem_table_id##dom##bus                   \
a84c022
+       __mcfg_fixup_##oem_id##oem_table_id##rev##dom##bus              \
a84c022
        __used  __attribute__((__section__(".acpi_fixup_mcfg"),         \
a84c022
                                aligned((sizeof(void *))))) =           \
a84c022
-       { ops, oem_id, oem_table_id, dom, bus };
a84c022
+       { ops, oem_id, oem_table_id, rev, dom, bus };
a84c022
 
a84c022
 extern int acpi_pci_probe_root_resources(struct acpi_pci_root_info *info);
a84c022
 extern struct pci_bus *acpi_pci_root_create(struct acpi_pci_root *root,
a84c022
-- 
86429d3
2.9.2
a84c022
86429d3
From b9c1592c6b615da0c26168c5c3e0f8fc256a23ca Mon Sep 17 00:00:00 2001
a84c022
From: Peter Robinson <pbrobinson@gmail.com>
a84c022
Date: Tue, 5 Jul 2016 23:55:11 +0100
86429d3
Subject: [PATCH] X-Gene PCIe controller does not fully support ECAM. This
a84c022
 patch adds required ECAM fixup to allow X-Gene PCIe controller to be
a84c022
 functional in ACPI boot mode.
a84c022
a84c022
Signed-off-by: Duc Dang <dhdang@apm.com>
a84c022
---
a84c022
 drivers/pci/host/Makefile         |   2 +-
a84c022
 drivers/pci/host/pci-xgene-ecam.c | 194 ++++++++++++++++++++++++++++++++++++++
a84c022
 2 files changed, 195 insertions(+), 1 deletion(-)
a84c022
 create mode 100644 drivers/pci/host/pci-xgene-ecam.c
a84c022
a84c022
diff --git a/drivers/pci/host/Makefile b/drivers/pci/host/Makefile
86429d3
index 8843410..af4f505 100644
a84c022
--- a/drivers/pci/host/Makefile
a84c022
+++ b/drivers/pci/host/Makefile
86429d3
@@ -15,7 +15,7 @@ obj-$(CONFIG_PCIE_SPEAR13XX) += pcie-spear13xx.o
a84c022
 obj-$(CONFIG_PCI_KEYSTONE) += pci-keystone-dw.o pci-keystone.o
a84c022
 obj-$(CONFIG_PCIE_XILINX) += pcie-xilinx.o
a84c022
 obj-$(CONFIG_PCIE_XILINX_NWL) += pcie-xilinx-nwl.o
a84c022
-obj-$(CONFIG_PCI_XGENE) += pci-xgene.o
a84c022
+obj-$(CONFIG_PCI_XGENE) += pci-xgene.o pci-xgene-ecam.o
a84c022
 obj-$(CONFIG_PCI_XGENE_MSI) += pci-xgene-msi.o
a84c022
 obj-$(CONFIG_PCI_LAYERSCAPE) += pci-layerscape.o
a84c022
 obj-$(CONFIG_PCI_VERSATILE) += pci-versatile.o
a84c022
diff --git a/drivers/pci/host/pci-xgene-ecam.c b/drivers/pci/host/pci-xgene-ecam.c
a84c022
new file mode 100644
a84c022
index 0000000..1bea63f
a84c022
--- /dev/null
a84c022
+++ b/drivers/pci/host/pci-xgene-ecam.c
a84c022
@@ -0,0 +1,194 @@
a84c022
+/*
a84c022
+ * APM X-Gene PCIe ECAM fixup driver
a84c022
+ *
a84c022
+ * Copyright (c) 2016, Applied Micro Circuits Corporation
a84c022
+ * Author:
a84c022
+ *     Duc Dang <dhdang@apm.com>
a84c022
+ *
a84c022
+ * This program is free software; you can redistribute it and/or modify
a84c022
+ * it under the terms of the GNU General Public License version 2 as
a84c022
+ * published by the Free Software Foundation.
a84c022
+ *
a84c022
+ * This program is distributed in the hope that it will be useful,
a84c022
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
a84c022
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
a84c022
+ * GNU General Public License for more details.
a84c022
+ *
a84c022
+ * You should have received a copy of the GNU General Public License
a84c022
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
a84c022
+ */
a84c022
+
a84c022
+#include <linux/kernel.h>
a84c022
+#include <linux/module.h>
a84c022
+#include <linux/of_address.h>
a84c022
+#include <linux/of_pci.h>
a84c022
+#include <linux/pci-acpi.h>
a84c022
+#include <linux/platform_device.h>
a84c022
+#include <linux/pci-ecam.h>
a84c022
+
a84c022
+#ifdef CONFIG_ACPI
a84c022
+#define RTDID                  0x160
a84c022
+#define ROOT_CAP_AND_CTRL      0x5C
a84c022
+
a84c022
+/* PCIe IP version */
a84c022
+#define XGENE_PCIE_IP_VER_UNKN 0
a84c022
+#define XGENE_PCIE_IP_VER_1    1
a84c022
+
a84c022
+#define APM_OEM_ID             "APM"
a84c022
+#define APM_XGENE_OEM_TABLE_ID "XGENE"
a84c022
+#define APM_XGENE_OEM_REV      0x00000002
a84c022
+
a84c022
+struct xgene_pcie_acpi_root {
a84c022
+       void __iomem *csr_base;
a84c022
+       u32 version;
a84c022
+};
a84c022
+
a84c022
+static acpi_status xgene_pcie_find_csr_base(struct acpi_resource *acpi_res,
a84c022
+                                           void *data)
a84c022
+{
a84c022
+       struct xgene_pcie_acpi_root *root = data;
a84c022
+       struct acpi_resource_fixed_memory32 *fixed32;
a84c022
+
a84c022
+       if (acpi_res->type == ACPI_RESOURCE_TYPE_FIXED_MEMORY32) {
a84c022
+               fixed32 = &acpi_res->data.fixed_memory32;
a84c022
+               root->csr_base = ioremap(fixed32->address,
a84c022
+                                        fixed32->address_length);
a84c022
+               return AE_CTRL_TERMINATE;
a84c022
+       }
a84c022
+
a84c022
+       return AE_OK;
a84c022
+}
a84c022
+
a84c022
+static int xgene_pcie_ecam_init(struct pci_config_window *cfg)
a84c022
+{
a84c022
+       struct xgene_pcie_acpi_root *xgene_root;
a84c022
+       struct device *dev = cfg->parent;
a84c022
+       struct acpi_device *adev = to_acpi_device(dev);
a84c022
+       acpi_handle handle = acpi_device_handle(adev);
a84c022
+
a84c022
+       xgene_root = devm_kzalloc(dev, sizeof(*xgene_root), GFP_KERNEL);
a84c022
+       if (!xgene_root)
a84c022
+               return -ENOMEM;
a84c022
+
a84c022
+       acpi_walk_resources(handle, METHOD_NAME__CRS,
a84c022
+                           xgene_pcie_find_csr_base, xgene_root);
a84c022
+
a84c022
+       if (!xgene_root->csr_base) {
a84c022
+               kfree(xgene_root);
a84c022
+               return -ENODEV;
a84c022
+       }
a84c022
+
a84c022
+       xgene_root->version = XGENE_PCIE_IP_VER_1;
a84c022
+
a84c022
+       cfg->priv = xgene_root;
a84c022
+
a84c022
+       return 0;
a84c022
+}
a84c022
+
a84c022
+/*
a84c022
+ * For Configuration request, RTDID register is used as Bus Number,
a84c022
+ * Device Number and Function number of the header fields.
a84c022
+ */
a84c022
+static void xgene_pcie_set_rtdid_reg(struct pci_bus *bus, uint devfn)
a84c022
+{
a84c022
+       struct pci_config_window *cfg = bus->sysdata;
a84c022
+       struct xgene_pcie_acpi_root *port = cfg->priv;
a84c022
+       unsigned int b, d, f;
a84c022
+       u32 rtdid_val = 0;
a84c022
+
a84c022
+       b = bus->number;
a84c022
+       d = PCI_SLOT(devfn);
a84c022
+       f = PCI_FUNC(devfn);
a84c022
+
a84c022
+       if (!pci_is_root_bus(bus))
a84c022
+               rtdid_val = (b << 8) | (d << 3) | f;
a84c022
+
a84c022
+       writel(rtdid_val, port->csr_base + RTDID);
a84c022
+       /* read the register back to ensure flush */
a84c022
+       readl(port->csr_base + RTDID);
a84c022
+}
a84c022
+
a84c022
+/*
a84c022
+ * X-Gene PCIe port uses BAR0-BAR1 of RC's configuration space as
a84c022
+ * the translation from PCI bus to native BUS.  Entire DDR region
a84c022
+ * is mapped into PCIe space using these registers, so it can be
a84c022
+ * reached by DMA from EP devices.  The BAR0/1 of bridge should be
a84c022
+ * hidden during enumeration to avoid the sizing and resource allocation
a84c022
+ * by PCIe core.
a84c022
+ */
a84c022
+static bool xgene_pcie_hide_rc_bars(struct pci_bus *bus, int offset)
a84c022
+{
a84c022
+       if (pci_is_root_bus(bus) && ((offset == PCI_BASE_ADDRESS_0) ||
a84c022
+                                    (offset == PCI_BASE_ADDRESS_1)))
a84c022
+               return true;
a84c022
+
a84c022
+       return false;
a84c022
+}
a84c022
+
a84c022
+void __iomem *xgene_pcie_ecam_map_bus(struct pci_bus *bus,
a84c022
+                                     unsigned int devfn, int where)
a84c022
+{
a84c022
+       struct pci_config_window *cfg = bus->sysdata;
a84c022
+       unsigned int busn = bus->number;
a84c022
+       void __iomem *base;
a84c022
+
a84c022
+       if (busn < cfg->busr.start || busn > cfg->busr.end)
a84c022
+               return NULL;
a84c022
+
a84c022
+       if ((pci_is_root_bus(bus) && devfn != 0) ||
a84c022
+           xgene_pcie_hide_rc_bars(bus, where))
a84c022
+               return NULL;
a84c022
+
a84c022
+       xgene_pcie_set_rtdid_reg(bus, devfn);
a84c022
+
a84c022
+       if (busn > cfg->busr.start)
a84c022
+               base = cfg->win + (1 << cfg->ops->bus_shift);
a84c022
+       else
a84c022
+               base = cfg->win;
a84c022
+
a84c022
+       return base + where;
a84c022
+}
a84c022
+
a84c022
+static int xgene_pcie_config_read32(struct pci_bus *bus, unsigned int devfn,
a84c022
+                                   int where, int size, u32 *val)
a84c022
+{
a84c022
+       struct pci_config_window *cfg = bus->sysdata;
a84c022
+       struct xgene_pcie_acpi_root *port = cfg->priv;
a84c022
+
a84c022
+       if (pci_generic_config_read32(bus, devfn, where & ~0x3, 4, val) !=
a84c022
+           PCIBIOS_SUCCESSFUL)
a84c022
+               return PCIBIOS_DEVICE_NOT_FOUND;
a84c022
+
a84c022
+       /*
a84c022
+       * The v1 controller has a bug in its Configuration Request
a84c022
+       * Retry Status (CRS) logic: when CRS is enabled and we read the
a84c022
+       * Vendor and Device ID of a non-existent device, the controller
a84c022
+       * fabricates return data of 0xFFFF0001 ("device exists but is not
a84c022
+       * ready") instead of 0xFFFFFFFF ("device does not exist").  This
a84c022
+       * causes the PCI core to retry the read until it times out.
a84c022
+       * Avoid this by not claiming to support CRS.
a84c022
+       */
a84c022
+       if (pci_is_root_bus(bus) && (port->version == XGENE_PCIE_IP_VER_1) &&
a84c022
+           ((where & ~0x3) == ROOT_CAP_AND_CTRL))
a84c022
+               *val &= ~(PCI_EXP_RTCAP_CRSVIS << 16);
a84c022
+
a84c022
+       if (size <= 2)
a84c022
+               *val = (*val >> (8 * (where & 3))) & ((1 << (size * 8)) - 1);
a84c022
+
a84c022
+       return PCIBIOS_SUCCESSFUL;
a84c022
+}
a84c022
+
a84c022
+static struct pci_ecam_ops xgene_pcie_ecam_ops = {
a84c022
+       .bus_shift      = 16,
a84c022
+       .init           = xgene_pcie_ecam_init,
a84c022
+       .pci_ops        = {
a84c022
+               .map_bus        = xgene_pcie_ecam_map_bus,
a84c022
+               .read           = xgene_pcie_config_read32,
a84c022
+               .write          = pci_generic_config_write,
a84c022
+       }
a84c022
+};
a84c022
+
a84c022
+DECLARE_ACPI_MCFG_FIXUP(&xgene_pcie_ecam_ops, APM_OEM_ID,
a84c022
+                       APM_XGENE_OEM_TABLE_ID, APM_XGENE_OEM_REV,
a84c022
+                       PCI_MCFG_DOMAIN_ANY, PCI_MCFG_BUS_ANY);
a84c022
+#endif
a84c022
-- 
86429d3
2.9.2
a84c022