Commit | Line | Data |
---|---|---|
ce292991 WD |
1 | /* |
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> | |
23 | #include <linux/module.h> | |
24 | #include <linux/of_address.h> | |
25 | #include <linux/of_pci.h> | |
26 | #include <linux/platform_device.h> | |
27 | ||
7149b9fd | 28 | #include "pci-host-common.h" |
ce292991 WD |
29 | |
30 | static void __iomem *gen_pci_map_cfg_bus_cam(struct pci_bus *bus, | |
31 | unsigned int devfn, | |
32 | int where) | |
33 | { | |
499733e0 | 34 | struct gen_pci *pci = bus->sysdata; |
dbf9826d | 35 | resource_size_t idx = bus->number - pci->cfg.bus_range->start; |
ce292991 WD |
36 | |
37 | return pci->cfg.win[idx] + ((devfn << 8) | where); | |
38 | } | |
39 | ||
40 | static struct gen_pci_cfg_bus_ops gen_pci_cfg_cam_bus_ops = { | |
41 | .bus_shift = 16, | |
9a280337 DD |
42 | .ops = { |
43 | .map_bus = gen_pci_map_cfg_bus_cam, | |
44 | .read = pci_generic_config_read, | |
45 | .write = pci_generic_config_write, | |
46 | } | |
ce292991 WD |
47 | }; |
48 | ||
49 | static void __iomem *gen_pci_map_cfg_bus_ecam(struct pci_bus *bus, | |
50 | unsigned int devfn, | |
51 | int where) | |
52 | { | |
499733e0 | 53 | struct gen_pci *pci = bus->sysdata; |
dbf9826d | 54 | resource_size_t idx = bus->number - pci->cfg.bus_range->start; |
ce292991 WD |
55 | |
56 | return pci->cfg.win[idx] + ((devfn << 12) | where); | |
57 | } | |
58 | ||
59 | static struct gen_pci_cfg_bus_ops gen_pci_cfg_ecam_bus_ops = { | |
60 | .bus_shift = 20, | |
9a280337 DD |
61 | .ops = { |
62 | .map_bus = gen_pci_map_cfg_bus_ecam, | |
63 | .read = pci_generic_config_read, | |
64 | .write = pci_generic_config_write, | |
65 | } | |
ce292991 WD |
66 | }; |
67 | ||
68 | static const struct of_device_id gen_pci_of_match[] = { | |
69 | { .compatible = "pci-host-cam-generic", | |
70 | .data = &gen_pci_cfg_cam_bus_ops }, | |
71 | ||
72 | { .compatible = "pci-host-ecam-generic", | |
73 | .data = &gen_pci_cfg_ecam_bus_ops }, | |
74 | ||
75 | { }, | |
76 | }; | |
77 | MODULE_DEVICE_TABLE(of, gen_pci_of_match); | |
78 | ||
d51b3710 DD |
79 | static int gen_pci_probe(struct platform_device *pdev) |
80 | { | |
81 | struct device *dev = &pdev->dev; | |
82 | const struct of_device_id *of_id; | |
83 | struct gen_pci *pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL); | |
84 | ||
85 | if (!pci) | |
86 | return -ENOMEM; | |
87 | ||
88 | of_id = of_match_node(gen_pci_of_match, dev->of_node); | |
89 | pci->cfg.ops = (struct gen_pci_cfg_bus_ops *)of_id->data; | |
90 | ||
91 | return pci_host_common_probe(pdev, pci); | |
92 | } | |
93 | ||
ce292991 WD |
94 | static struct platform_driver gen_pci_driver = { |
95 | .driver = { | |
96 | .name = "pci-host-generic", | |
ce292991 WD |
97 | .of_match_table = gen_pci_of_match, |
98 | }, | |
99 | .probe = gen_pci_probe, | |
100 | }; | |
101 | module_platform_driver(gen_pci_driver); | |
102 | ||
103 | MODULE_DESCRIPTION("Generic PCI host driver"); | |
104 | MODULE_AUTHOR("Will Deacon <will.deacon@arm.com>"); | |
eed6542d | 105 | MODULE_LICENSE("GPL v2"); |