2 * Simple, generic PCI host controller driver targetting firmware-initialised
3 * systems and virtual machines (e.g. the PCI emulation provided by kvmtool).
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.
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.
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/>.
17 * Copyright (C) 2014 ARM Limited
19 * Author: Will Deacon <will.deacon@arm.com>
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>
28 #include "pci-host-common.h"
30 static void __iomem
*gen_pci_map_cfg_bus_cam(struct pci_bus
*bus
,
34 struct gen_pci
*pci
= bus
->sysdata
;
35 resource_size_t idx
= bus
->number
- pci
->cfg
.bus_range
->start
;
37 return pci
->cfg
.win
[idx
] + ((devfn
<< 8) | where
);
40 static struct gen_pci_cfg_bus_ops gen_pci_cfg_cam_bus_ops
= {
43 .map_bus
= gen_pci_map_cfg_bus_cam
,
44 .read
= pci_generic_config_read
,
45 .write
= pci_generic_config_write
,
49 static void __iomem
*gen_pci_map_cfg_bus_ecam(struct pci_bus
*bus
,
53 struct gen_pci
*pci
= bus
->sysdata
;
54 resource_size_t idx
= bus
->number
- pci
->cfg
.bus_range
->start
;
56 return pci
->cfg
.win
[idx
] + ((devfn
<< 12) | where
);
59 static struct gen_pci_cfg_bus_ops gen_pci_cfg_ecam_bus_ops
= {
62 .map_bus
= gen_pci_map_cfg_bus_ecam
,
63 .read
= pci_generic_config_read
,
64 .write
= pci_generic_config_write
,
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
},
72 { .compatible
= "pci-host-ecam-generic",
73 .data
= &gen_pci_cfg_ecam_bus_ops
},
77 MODULE_DEVICE_TABLE(of
, gen_pci_of_match
);
79 static int gen_pci_probe(struct platform_device
*pdev
)
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
);
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
;
91 return pci_host_common_probe(pdev
, pci
);
94 static struct platform_driver gen_pci_driver
= {
96 .name
= "pci-host-generic",
97 .of_match_table
= gen_pci_of_match
,
99 .probe
= gen_pci_probe
,
101 module_platform_driver(gen_pci_driver
);
103 MODULE_DESCRIPTION("Generic PCI host driver");
104 MODULE_AUTHOR("Will Deacon <will.deacon@arm.com>");
105 MODULE_LICENSE("GPL v2");