1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Simple, generic PCI host controller driver targeting firmware-initialised 4 * systems and virtual machines (e.g. the PCI emulation provided by kvmtool). 5 * 6 * Copyright (C) 2014 ARM Limited 7 * 8 * Author: Will Deacon <will.deacon@arm.com> 9 */ 10 11 #include <linux/kernel.h> 12 #include <linux/init.h> 13 #include <linux/module.h> 14 #include <linux/pci-ecam.h> 15 #include <linux/platform_device.h> 16 17 #include "pci-host-common.h" 18 19 static bool pci_dw_valid_device(struct pci_bus *bus, unsigned int devfn) 20 { 21 struct pci_config_window *cfg = bus->sysdata; 22 23 /* 24 * The Synopsys DesignWare PCIe controller in ECAM mode will not filter 25 * type 0 config TLPs sent to devices 1 and up on its downstream port, 26 * resulting in devices appearing multiple times on bus 0 unless we 27 * filter out those accesses here. 28 */ 29 if (bus->number == cfg->busr.start && PCI_SLOT(devfn) > 0) 30 return false; 31 32 return true; 33 } 34 35 static void __iomem *pci_dw_ecam_map_bus(struct pci_bus *bus, 36 unsigned int devfn, int where) 37 { 38 if (!pci_dw_valid_device(bus, devfn)) 39 return NULL; 40 41 return pci_ecam_map_bus(bus, devfn, where); 42 } 43 44 static const struct pci_ecam_ops pci_dw_ecam_bus_ops = { 45 .pci_ops = { 46 .map_bus = pci_dw_ecam_map_bus, 47 .read = pci_generic_config_read, 48 .write = pci_generic_config_write, 49 } 50 }; 51 52 static const struct of_device_id gen_pci_of_match[] = { 53 { .compatible = "pci-host-cam-generic", 54 .data = &pci_generic_cam_ops }, 55 56 { .compatible = "pci-host-ecam-generic", 57 .data = &pci_generic_ecam_ops }, 58 59 { .compatible = "marvell,armada8k-pcie-ecam", 60 .data = &pci_dw_ecam_bus_ops }, 61 62 { .compatible = "socionext,synquacer-pcie-ecam", 63 .data = &pci_dw_ecam_bus_ops }, 64 65 { .compatible = "snps,dw-pcie-ecam", 66 .data = &pci_dw_ecam_bus_ops }, 67 68 { }, 69 }; 70 MODULE_DEVICE_TABLE(of, gen_pci_of_match); 71 72 static struct platform_driver gen_pci_driver = { 73 .driver = { 74 .name = "pci-host-generic", 75 .of_match_table = gen_pci_of_match, 76 }, 77 .probe = pci_host_common_probe, 78 .remove = pci_host_common_remove, 79 }; 80 module_platform_driver(gen_pci_driver); 81 82 MODULE_DESCRIPTION("Generic PCI host controller driver"); 83 MODULE_LICENSE("GPL v2"); 84