.. | .. |
---|
8 | 8 | */ |
---|
9 | 9 | |
---|
10 | 10 | #include <linux/kernel.h> |
---|
| 11 | +#include <linux/module.h> |
---|
11 | 12 | #include <linux/of_address.h> |
---|
| 13 | +#include <linux/of_device.h> |
---|
12 | 14 | #include <linux/of_pci.h> |
---|
13 | 15 | #include <linux/pci-ecam.h> |
---|
14 | 16 | #include <linux/platform_device.h> |
---|
.. | .. |
---|
19 | 21 | } |
---|
20 | 22 | |
---|
21 | 23 | static struct pci_config_window *gen_pci_init(struct device *dev, |
---|
22 | | - struct list_head *resources, struct pci_ecam_ops *ops) |
---|
| 24 | + struct pci_host_bridge *bridge, const struct pci_ecam_ops *ops) |
---|
23 | 25 | { |
---|
24 | 26 | int err; |
---|
25 | 27 | struct resource cfgres; |
---|
26 | | - struct resource *bus_range = NULL; |
---|
| 28 | + struct resource_entry *bus; |
---|
27 | 29 | struct pci_config_window *cfg; |
---|
28 | | - |
---|
29 | | - /* Parse our PCI ranges and request their resources */ |
---|
30 | | - err = pci_parse_request_of_pci_ranges(dev, resources, &bus_range); |
---|
31 | | - if (err) |
---|
32 | | - return ERR_PTR(err); |
---|
33 | 30 | |
---|
34 | 31 | err = of_address_to_resource(dev->of_node, 0, &cfgres); |
---|
35 | 32 | if (err) { |
---|
36 | 33 | dev_err(dev, "missing \"reg\" property\n"); |
---|
37 | | - goto err_out; |
---|
| 34 | + return ERR_PTR(err); |
---|
38 | 35 | } |
---|
39 | 36 | |
---|
40 | | - cfg = pci_ecam_create(dev, &cfgres, bus_range, ops); |
---|
41 | | - if (IS_ERR(cfg)) { |
---|
42 | | - err = PTR_ERR(cfg); |
---|
43 | | - goto err_out; |
---|
44 | | - } |
---|
| 37 | + bus = resource_list_first_type(&bridge->windows, IORESOURCE_BUS); |
---|
| 38 | + if (!bus) |
---|
| 39 | + return ERR_PTR(-ENODEV); |
---|
45 | 40 | |
---|
46 | | - err = devm_add_action(dev, gen_pci_unmap_cfg, cfg); |
---|
47 | | - if (err) { |
---|
48 | | - gen_pci_unmap_cfg(cfg); |
---|
49 | | - goto err_out; |
---|
50 | | - } |
---|
| 41 | + cfg = pci_ecam_create(dev, &cfgres, bus->res, ops); |
---|
| 42 | + if (IS_ERR(cfg)) |
---|
| 43 | + return cfg; |
---|
| 44 | + |
---|
| 45 | + err = devm_add_action_or_reset(dev, gen_pci_unmap_cfg, cfg); |
---|
| 46 | + if (err) |
---|
| 47 | + return ERR_PTR(err); |
---|
| 48 | + |
---|
51 | 49 | return cfg; |
---|
52 | | - |
---|
53 | | -err_out: |
---|
54 | | - pci_free_resource_list(resources); |
---|
55 | | - return ERR_PTR(err); |
---|
56 | 50 | } |
---|
57 | 51 | |
---|
58 | | -int pci_host_common_probe(struct platform_device *pdev, |
---|
59 | | - struct pci_ecam_ops *ops) |
---|
| 52 | +int pci_host_common_probe(struct platform_device *pdev) |
---|
60 | 53 | { |
---|
61 | | - const char *type; |
---|
62 | 54 | struct device *dev = &pdev->dev; |
---|
63 | | - struct device_node *np = dev->of_node; |
---|
64 | 55 | struct pci_host_bridge *bridge; |
---|
65 | 56 | struct pci_config_window *cfg; |
---|
66 | | - struct list_head resources; |
---|
67 | | - int ret; |
---|
| 57 | + const struct pci_ecam_ops *ops; |
---|
| 58 | + |
---|
| 59 | + ops = of_device_get_match_data(&pdev->dev); |
---|
| 60 | + if (!ops) |
---|
| 61 | + return -ENODEV; |
---|
68 | 62 | |
---|
69 | 63 | bridge = devm_pci_alloc_host_bridge(dev, 0); |
---|
70 | 64 | if (!bridge) |
---|
71 | 65 | return -ENOMEM; |
---|
72 | 66 | |
---|
73 | | - type = of_get_property(np, "device_type", NULL); |
---|
74 | | - if (!type || strcmp(type, "pci")) { |
---|
75 | | - dev_err(dev, "invalid \"device_type\" %s\n", type); |
---|
76 | | - return -EINVAL; |
---|
77 | | - } |
---|
78 | | - |
---|
79 | 67 | of_pci_check_probe_only(); |
---|
80 | 68 | |
---|
81 | 69 | /* Parse and map our Configuration Space windows */ |
---|
82 | | - cfg = gen_pci_init(dev, &resources, ops); |
---|
| 70 | + cfg = gen_pci_init(dev, bridge, ops); |
---|
83 | 71 | if (IS_ERR(cfg)) |
---|
84 | 72 | return PTR_ERR(cfg); |
---|
85 | 73 | |
---|
.. | .. |
---|
87 | 75 | if (!pci_has_flag(PCI_PROBE_ONLY)) |
---|
88 | 76 | pci_add_flags(PCI_REASSIGN_ALL_BUS); |
---|
89 | 77 | |
---|
90 | | - list_splice_init(&resources, &bridge->windows); |
---|
91 | | - bridge->dev.parent = dev; |
---|
92 | 78 | bridge->sysdata = cfg; |
---|
93 | | - bridge->busnr = cfg->busr.start; |
---|
94 | | - bridge->ops = &ops->pci_ops; |
---|
95 | | - bridge->map_irq = of_irq_parse_and_map_pci; |
---|
96 | | - bridge->swizzle_irq = pci_common_swizzle; |
---|
| 79 | + bridge->ops = (struct pci_ops *)&ops->pci_ops; |
---|
97 | 80 | |
---|
98 | | - ret = pci_host_probe(bridge); |
---|
99 | | - if (ret < 0) { |
---|
100 | | - pci_free_resource_list(&resources); |
---|
101 | | - return ret; |
---|
102 | | - } |
---|
| 81 | + platform_set_drvdata(pdev, bridge); |
---|
103 | 82 | |
---|
104 | | - platform_set_drvdata(pdev, bridge->bus); |
---|
105 | | - return 0; |
---|
| 83 | + return pci_host_probe(bridge); |
---|
106 | 84 | } |
---|
| 85 | +EXPORT_SYMBOL_GPL(pci_host_common_probe); |
---|
107 | 86 | |
---|
108 | 87 | int pci_host_common_remove(struct platform_device *pdev) |
---|
109 | 88 | { |
---|
110 | | - struct pci_bus *bus = platform_get_drvdata(pdev); |
---|
| 89 | + struct pci_host_bridge *bridge = platform_get_drvdata(pdev); |
---|
111 | 90 | |
---|
112 | 91 | pci_lock_rescan_remove(); |
---|
113 | | - pci_stop_root_bus(bus); |
---|
114 | | - pci_remove_root_bus(bus); |
---|
| 92 | + pci_stop_root_bus(bridge->bus); |
---|
| 93 | + pci_remove_root_bus(bridge->bus); |
---|
115 | 94 | pci_unlock_rescan_remove(); |
---|
116 | 95 | |
---|
117 | 96 | return 0; |
---|
118 | 97 | } |
---|
| 98 | +EXPORT_SYMBOL_GPL(pci_host_common_remove); |
---|
| 99 | + |
---|
| 100 | +MODULE_LICENSE("GPL v2"); |
---|