blob: 2f05511ce718c147736927a0c3f76dae8c999140 [file] [log] [blame]
Will Deaconce292992013-11-22 16:14:41 +00001/*
2 * Simple, generic PCI host controller driver targetting firmware-initialised
3 * systems and virtual machines (e.g. the PCI emulation provided by kvmtool).
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Copyright (C) 2014 ARM Limited
18 *
19 * Author: Will Deacon <will.deacon@arm.com>
20 */
21
22#include <linux/kernel.h>
Paul Gortmaker99849bf2016-07-22 16:21:38 -050023#include <linux/init.h>
Will Deaconce292992013-11-22 16:14:41 +000024#include <linux/of_address.h>
25#include <linux/of_pci.h>
Jayachandran C80955f92016-06-10 21:55:09 +020026#include <linux/pci-ecam.h>
Will Deaconce292992013-11-22 16:14:41 +000027#include <linux/platform_device.h>
28
Jayachandran C1958e712016-05-11 17:34:46 -050029static struct pci_ecam_ops gen_pci_cfg_cam_bus_ops = {
Will Deaconce292992013-11-22 16:14:41 +000030 .bus_shift = 16,
Jayachandran C1958e712016-05-11 17:34:46 -050031 .pci_ops = {
32 .map_bus = pci_ecam_map_bus,
David Daney9a280332015-10-08 10:15:10 -050033 .read = pci_generic_config_read,
34 .write = pci_generic_config_write,
35 }
Will Deaconce292992013-11-22 16:14:41 +000036};
37
Ard Biesheuvel58fb2072017-10-06 17:39:18 +010038static bool pci_dw_valid_device(struct pci_bus *bus, unsigned int devfn)
39{
40 struct pci_config_window *cfg = bus->sysdata;
41
42 /*
43 * The Synopsys DesignWare PCIe controller in ECAM mode will not filter
44 * type 0 config TLPs sent to devices 1 and up on its downstream port,
45 * resulting in devices appearing multiple times on bus 0 unless we
46 * filter out those accesses here.
47 */
48 if (bus->number == cfg->busr.start && PCI_SLOT(devfn) > 0)
49 return false;
50
51 return true;
52}
53
54static void __iomem *pci_dw_ecam_map_bus(struct pci_bus *bus,
55 unsigned int devfn, int where)
56{
57 if (!pci_dw_valid_device(bus, devfn))
58 return NULL;
59
60 return pci_ecam_map_bus(bus, devfn, where);
61}
62
63static struct pci_ecam_ops pci_dw_ecam_bus_ops = {
64 .bus_shift = 20,
65 .pci_ops = {
66 .map_bus = pci_dw_ecam_map_bus,
67 .read = pci_generic_config_read,
68 .write = pci_generic_config_write,
69 }
70};
71
Will Deaconce292992013-11-22 16:14:41 +000072static const struct of_device_id gen_pci_of_match[] = {
73 { .compatible = "pci-host-cam-generic",
74 .data = &gen_pci_cfg_cam_bus_ops },
75
76 { .compatible = "pci-host-ecam-generic",
Jayachandran C1958e712016-05-11 17:34:46 -050077 .data = &pci_generic_ecam_ops },
Will Deaconce292992013-11-22 16:14:41 +000078
Ard Biesheuvel58fb2072017-10-06 17:39:18 +010079 { .compatible = "marvell,armada8k-pcie-ecam",
80 .data = &pci_dw_ecam_bus_ops },
81
82 { .compatible = "socionext,synquacer-pcie-ecam",
83 .data = &pci_dw_ecam_bus_ops },
84
85 { .compatible = "snps,dw-pcie-ecam",
86 .data = &pci_dw_ecam_bus_ops },
87
Will Deaconce292992013-11-22 16:14:41 +000088 { },
89};
Jayachandran C1958e712016-05-11 17:34:46 -050090
David Daneyd51b37102016-03-11 15:25:13 -060091static int gen_pci_probe(struct platform_device *pdev)
92{
David Daneyd51b37102016-03-11 15:25:13 -060093 const struct of_device_id *of_id;
Jayachandran C1958e712016-05-11 17:34:46 -050094 struct pci_ecam_ops *ops;
David Daneyd51b37102016-03-11 15:25:13 -060095
Jayachandran C1958e712016-05-11 17:34:46 -050096 of_id = of_match_node(gen_pci_of_match, pdev->dev.of_node);
97 ops = (struct pci_ecam_ops *)of_id->data;
David Daneyd51b37102016-03-11 15:25:13 -060098
Jayachandran C1958e712016-05-11 17:34:46 -050099 return pci_host_common_probe(pdev, ops);
David Daneyd51b37102016-03-11 15:25:13 -0600100}
101
Will Deaconce292992013-11-22 16:14:41 +0000102static struct platform_driver gen_pci_driver = {
103 .driver = {
104 .name = "pci-host-generic",
Will Deaconce292992013-11-22 16:14:41 +0000105 .of_match_table = gen_pci_of_match,
Brian Norrisa5f40e82017-04-20 15:36:25 -0500106 .suppress_bind_attrs = true,
Will Deaconce292992013-11-22 16:14:41 +0000107 },
108 .probe = gen_pci_probe,
109};
Paul Gortmaker99849bf2016-07-22 16:21:38 -0500110builtin_platform_driver(gen_pci_driver);