summaryrefslogtreecommitdiff
path: root/drivers/pci/controller/pci-host-generic.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-06-12 15:05:02 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2018-06-12 15:05:02 -0700
commit38da0d6888a6bccd3ae93227aa9f29537f8bd5f9 (patch)
tree64c7c1d008460f05b579110a7e40b6c796fb1578 /drivers/pci/controller/pci-host-generic.c
parent19785cf93b6c4252981894394f2dbd35c5e5d1ec (diff)
parentce4c7b241227ed49c0b6f0f1867653e1ee0007ef (diff)
Merge tag 'pci-v4.18-changes-2' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci
Pull more PCI updates from Bjorn Helgaas: - squash AER directory into drivers/pci/pcie/aer.c (Bjorn Helgaas) - collect all native hardware drivers under drivers/pci/controller/ (Shawn Lin) * tag 'pci-v4.18-changes-2' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci: PCI/AER: Use "PCI Express" consistently in Kconfig text PCI/AER: Hoist aerdrv.c, aer_inject.c up to drivers/pci/pcie/ PCI/AER: Squash Kconfig.debug into Kconfig PCI/AER: Move private AER things to aerdrv.c PCI/AER: Move aer_irq() declaration to portdrv.h PCI/AER: Move pcie_aer_get_firmware_first() to portdrv.h PCI/AER: Remove duplicate pcie_port_bus_type declaration PCI/AER: Squash ecrc.c into aerdrv.c PCI/AER: Squash aerdrv_acpi.c into aerdrv.c PCI/AER: Squash aerdrv_errprint.c into aerdrv.c PCI/AER: Squash aerdrv_core.c into aerdrv.c PCI/AER: Reorder code to group probe/remove stuff together PCI/AER: Remove forward declarations PCI: Collect all native drivers under drivers/pci/controller/
Diffstat (limited to 'drivers/pci/controller/pci-host-generic.c')
-rw-r--r--drivers/pci/controller/pci-host-generic.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/drivers/pci/controller/pci-host-generic.c b/drivers/pci/controller/pci-host-generic.c
new file mode 100644
index 000000000000..dea3ec7592a2
--- /dev/null
+++ b/drivers/pci/controller/pci-host-generic.c
@@ -0,0 +1,100 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Simple, generic PCI host controller driver targetting firmware-initialised
+ * systems and virtual machines (e.g. the PCI emulation provided by kvmtool).
+ *
+ * Copyright (C) 2014 ARM Limited
+ *
+ * Author: Will Deacon <will.deacon@arm.com>
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/of_address.h>
+#include <linux/of_pci.h>
+#include <linux/pci-ecam.h>
+#include <linux/platform_device.h>
+
+static struct pci_ecam_ops gen_pci_cfg_cam_bus_ops = {
+ .bus_shift = 16,
+ .pci_ops = {
+ .map_bus = pci_ecam_map_bus,
+ .read = pci_generic_config_read,
+ .write = pci_generic_config_write,
+ }
+};
+
+static bool pci_dw_valid_device(struct pci_bus *bus, unsigned int devfn)
+{
+ struct pci_config_window *cfg = bus->sysdata;
+
+ /*
+ * The Synopsys DesignWare PCIe controller in ECAM mode will not filter
+ * type 0 config TLPs sent to devices 1 and up on its downstream port,
+ * resulting in devices appearing multiple times on bus 0 unless we
+ * filter out those accesses here.
+ */
+ if (bus->number == cfg->busr.start && PCI_SLOT(devfn) > 0)
+ return false;
+
+ return true;
+}
+
+static void __iomem *pci_dw_ecam_map_bus(struct pci_bus *bus,
+ unsigned int devfn, int where)
+{
+ if (!pci_dw_valid_device(bus, devfn))
+ return NULL;
+
+ return pci_ecam_map_bus(bus, devfn, where);
+}
+
+static struct pci_ecam_ops pci_dw_ecam_bus_ops = {
+ .bus_shift = 20,
+ .pci_ops = {
+ .map_bus = pci_dw_ecam_map_bus,
+ .read = pci_generic_config_read,
+ .write = pci_generic_config_write,
+ }
+};
+
+static const struct of_device_id gen_pci_of_match[] = {
+ { .compatible = "pci-host-cam-generic",
+ .data = &gen_pci_cfg_cam_bus_ops },
+
+ { .compatible = "pci-host-ecam-generic",
+ .data = &pci_generic_ecam_ops },
+
+ { .compatible = "marvell,armada8k-pcie-ecam",
+ .data = &pci_dw_ecam_bus_ops },
+
+ { .compatible = "socionext,synquacer-pcie-ecam",
+ .data = &pci_dw_ecam_bus_ops },
+
+ { .compatible = "snps,dw-pcie-ecam",
+ .data = &pci_dw_ecam_bus_ops },
+
+ { },
+};
+
+static int gen_pci_probe(struct platform_device *pdev)
+{
+ const struct of_device_id *of_id;
+ struct pci_ecam_ops *ops;
+
+ of_id = of_match_node(gen_pci_of_match, pdev->dev.of_node);
+ ops = (struct pci_ecam_ops *)of_id->data;
+
+ return pci_host_common_probe(pdev, ops);
+}
+
+static struct platform_driver gen_pci_driver = {
+ .driver = {
+ .name = "pci-host-generic",
+ .of_match_table = gen_pci_of_match,
+ .suppress_bind_attrs = true,
+ },
+ .probe = gen_pci_probe,
+ .remove = pci_host_common_remove,
+};
+builtin_platform_driver(gen_pci_driver);