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