blob: dea3ec7592a231052010e4935d85ee1073352c6f [file] [log] [blame]
Bjorn Helgaas8cfab3c2018-01-26 12:50:27 -06001// SPDX-License-Identifier: GPL-2.0
Will Deaconce292992013-11-22 16:14:41 +00002/*
3 * Simple, generic PCI host controller driver targetting firmware-initialised
4 * systems and virtual machines (e.g. the PCI emulation provided by kvmtool).
5 *
Will Deaconce292992013-11-22 16:14:41 +00006 * Copyright (C) 2014 ARM Limited
7 *
8 * Author: Will Deacon <will.deacon@arm.com>
9 */
10
11#include <linux/kernel.h>
Paul Gortmaker99849bf2016-07-22 16:21:38 -050012#include <linux/init.h>
Will Deaconce292992013-11-22 16:14:41 +000013#include <linux/of_address.h>
14#include <linux/of_pci.h>
Jayachandran C80955f92016-06-10 21:55:09 +020015#include <linux/pci-ecam.h>
Will Deaconce292992013-11-22 16:14:41 +000016#include <linux/platform_device.h>
17
Jayachandran C1958e712016-05-11 17:34:46 -050018static struct pci_ecam_ops gen_pci_cfg_cam_bus_ops = {
Will Deaconce292992013-11-22 16:14:41 +000019 .bus_shift = 16,
Jayachandran C1958e712016-05-11 17:34:46 -050020 .pci_ops = {
21 .map_bus = pci_ecam_map_bus,
David Daney9a280332015-10-08 10:15:10 -050022 .read = pci_generic_config_read,
23 .write = pci_generic_config_write,
24 }
Will Deaconce292992013-11-22 16:14:41 +000025};
26
Ard Biesheuvel58fb2072017-10-06 17:39:18 +010027static bool pci_dw_valid_device(struct pci_bus *bus, unsigned int devfn)
28{
29 struct pci_config_window *cfg = bus->sysdata;
30
31 /*
32 * The Synopsys DesignWare PCIe controller in ECAM mode will not filter
33 * type 0 config TLPs sent to devices 1 and up on its downstream port,
34 * resulting in devices appearing multiple times on bus 0 unless we
35 * filter out those accesses here.
36 */
37 if (bus->number == cfg->busr.start && PCI_SLOT(devfn) > 0)
38 return false;
39
40 return true;
41}
42
43static void __iomem *pci_dw_ecam_map_bus(struct pci_bus *bus,
44 unsigned int devfn, int where)
45{
46 if (!pci_dw_valid_device(bus, devfn))
47 return NULL;
48
49 return pci_ecam_map_bus(bus, devfn, where);
50}
51
52static struct pci_ecam_ops pci_dw_ecam_bus_ops = {
53 .bus_shift = 20,
54 .pci_ops = {
55 .map_bus = pci_dw_ecam_map_bus,
56 .read = pci_generic_config_read,
57 .write = pci_generic_config_write,
58 }
59};
60
Will Deaconce292992013-11-22 16:14:41 +000061static const struct of_device_id gen_pci_of_match[] = {
62 { .compatible = "pci-host-cam-generic",
63 .data = &gen_pci_cfg_cam_bus_ops },
64
65 { .compatible = "pci-host-ecam-generic",
Jayachandran C1958e712016-05-11 17:34:46 -050066 .data = &pci_generic_ecam_ops },
Will Deaconce292992013-11-22 16:14:41 +000067
Ard Biesheuvel58fb2072017-10-06 17:39:18 +010068 { .compatible = "marvell,armada8k-pcie-ecam",
69 .data = &pci_dw_ecam_bus_ops },
70
71 { .compatible = "socionext,synquacer-pcie-ecam",
72 .data = &pci_dw_ecam_bus_ops },
73
74 { .compatible = "snps,dw-pcie-ecam",
75 .data = &pci_dw_ecam_bus_ops },
76
Will Deaconce292992013-11-22 16:14:41 +000077 { },
78};
Jayachandran C1958e712016-05-11 17:34:46 -050079
David Daneyd51b37102016-03-11 15:25:13 -060080static int gen_pci_probe(struct platform_device *pdev)
81{
David Daneyd51b37102016-03-11 15:25:13 -060082 const struct of_device_id *of_id;
Jayachandran C1958e712016-05-11 17:34:46 -050083 struct pci_ecam_ops *ops;
David Daneyd51b37102016-03-11 15:25:13 -060084
Jayachandran C1958e712016-05-11 17:34:46 -050085 of_id = of_match_node(gen_pci_of_match, pdev->dev.of_node);
86 ops = (struct pci_ecam_ops *)of_id->data;
David Daneyd51b37102016-03-11 15:25:13 -060087
Jayachandran C1958e712016-05-11 17:34:46 -050088 return pci_host_common_probe(pdev, ops);
David Daneyd51b37102016-03-11 15:25:13 -060089}
90
Will Deaconce292992013-11-22 16:14:41 +000091static struct platform_driver gen_pci_driver = {
92 .driver = {
93 .name = "pci-host-generic",
Will Deaconce292992013-11-22 16:14:41 +000094 .of_match_table = gen_pci_of_match,
Brian Norrisa5f40e82017-04-20 15:36:25 -050095 .suppress_bind_attrs = true,
Will Deaconce292992013-11-22 16:14:41 +000096 },
97 .probe = gen_pci_probe,
Jan Kiszka01fcb7f2018-05-15 11:07:06 +020098 .remove = pci_host_common_remove,
Will Deaconce292992013-11-22 16:14:41 +000099};
Paul Gortmaker99849bf2016-07-22 16:21:38 -0500100builtin_platform_driver(gen_pci_driver);