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 static const struct pci_ecam_ops gen_pci_cfg_cam_bus_ops = { 18 .bus_shift = 16, 19 .pci_ops = { 20 .map_bus = pci_ecam_map_bus, 21 .read = pci_generic_config_read, 22 .write = pci_generic_config_write, 23 } 24 }; 25 26 static bool pci_dw_valid_device(struct pci_bus *bus, unsigned int devfn) 27 { 28 struct pci_config_window *cfg = bus->sysdata; 29 30 /* 31 * The Synopsys DesignWare PCIe controller in ECAM mode will not filter 32 * type 0 config TLPs sent to devices 1 and up on its downstream port, 33 * resulting in devices appearing multiple times on bus 0 unless we 34 * filter out those accesses here. 35 */ 36 if (bus->number == cfg->busr.start && PCI_SLOT(devfn) > 0) 37 return false; 38 39 return true; 40 } 41 42 static void __iomem *pci_dw_ecam_map_bus(struct pci_bus *bus, 43 unsigned int devfn, int where) 44 { 45 if (!pci_dw_valid_device(bus, devfn)) 46 return NULL; 47 48 return pci_ecam_map_bus(bus, devfn, where); 49 } 50 51 static const struct pci_ecam_ops pci_dw_ecam_bus_ops = { 52 .bus_shift = 20, 53 .pci_ops = { 54 .map_bus = pci_dw_ecam_map_bus, 55 .read = pci_generic_config_read, 56 .write = pci_generic_config_write, 57 } 58 }; 59 60 static const struct of_device_id gen_pci_of_match[] = { 61 { .compatible = "pci-host-cam-generic", 62 .data = &gen_pci_cfg_cam_bus_ops }, 63 64 { .compatible = "pci-host-ecam-generic", 65 .data = &pci_generic_ecam_ops }, 66 67 { .compatible = "marvell,armada8k-pcie-ecam", 68 .data = &pci_dw_ecam_bus_ops }, 69 70 { .compatible = "socionext,synquacer-pcie-ecam", 71 .data = &pci_dw_ecam_bus_ops }, 72 73 { .compatible = "snps,dw-pcie-ecam", 74 .data = &pci_dw_ecam_bus_ops }, 75 76 { }, 77 }; 78 MODULE_DEVICE_TABLE(of, gen_pci_of_match); 79 80 static struct platform_driver gen_pci_driver = { 81 .driver = { 82 .name = "pci-host-generic", 83 .of_match_table = gen_pci_of_match, 84 }, 85 .probe = pci_host_common_probe, 86 .remove = pci_host_common_remove, 87 }; 88 module_platform_driver(gen_pci_driver); 89 90 MODULE_LICENSE("GPL v2"); 91