Loading...
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
17static 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
26static 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
42static 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
51static const struct pci_ecam_ops pci_dw_ecam_bus_ops = {
52 .pci_ops = {
53 .map_bus = pci_dw_ecam_map_bus,
54 .read = pci_generic_config_read,
55 .write = pci_generic_config_write,
56 }
57};
58
59static const struct of_device_id gen_pci_of_match[] = {
60 { .compatible = "pci-host-cam-generic",
61 .data = &gen_pci_cfg_cam_bus_ops },
62
63 { .compatible = "pci-host-ecam-generic",
64 .data = &pci_generic_ecam_ops },
65
66 { .compatible = "marvell,armada8k-pcie-ecam",
67 .data = &pci_dw_ecam_bus_ops },
68
69 { .compatible = "socionext,synquacer-pcie-ecam",
70 .data = &pci_dw_ecam_bus_ops },
71
72 { .compatible = "snps,dw-pcie-ecam",
73 .data = &pci_dw_ecam_bus_ops },
74
75 { },
76};
77MODULE_DEVICE_TABLE(of, gen_pci_of_match);
78
79static struct platform_driver gen_pci_driver = {
80 .driver = {
81 .name = "pci-host-generic",
82 .of_match_table = gen_pci_of_match,
83 },
84 .probe = pci_host_common_probe,
85 .remove_new = pci_host_common_remove,
86};
87module_platform_driver(gen_pci_driver);
88
89MODULE_LICENSE("GPL v2");
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/of_address.h>
14#include <linux/of_pci.h>
15#include <linux/pci-ecam.h>
16#include <linux/platform_device.h>
17
18static struct pci_ecam_ops gen_pci_cfg_cam_bus_ops = {
19 .bus_shift = 16,
20 .pci_ops = {
21 .map_bus = pci_ecam_map_bus,
22 .read = pci_generic_config_read,
23 .write = pci_generic_config_write,
24 }
25};
26
27static 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
61static 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",
66 .data = &pci_generic_ecam_ops },
67
68 { .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
77 { },
78};
79
80static int gen_pci_probe(struct platform_device *pdev)
81{
82 const struct of_device_id *of_id;
83 struct pci_ecam_ops *ops;
84
85 of_id = of_match_node(gen_pci_of_match, pdev->dev.of_node);
86 ops = (struct pci_ecam_ops *)of_id->data;
87
88 return pci_host_common_probe(pdev, ops);
89}
90
91static struct platform_driver gen_pci_driver = {
92 .driver = {
93 .name = "pci-host-generic",
94 .of_match_table = gen_pci_of_match,
95 .suppress_bind_attrs = true,
96 },
97 .probe = gen_pci_probe,
98 .remove = pci_host_common_remove,
99};
100builtin_platform_driver(gen_pci_driver);