]>
Commit | Line | Data |
---|---|---|
610929e1 YL |
1 | /* |
2 | * host bridge related code | |
3 | */ | |
4 | ||
5 | #include <linux/kernel.h> | |
610929e1 YL |
6 | #include <linux/pci.h> |
7 | #include <linux/module.h> | |
8 | ||
9 | #include "pci.h" | |
10 | ||
fc279850 | 11 | static struct pci_bus *find_pci_root_bus(struct pci_bus *bus) |
610929e1 | 12 | { |
610929e1 YL |
13 | while (bus->parent) |
14 | bus = bus->parent; | |
15 | ||
459f58ce YL |
16 | return bus; |
17 | } | |
18 | ||
fc279850 | 19 | static struct pci_host_bridge *find_pci_host_bridge(struct pci_bus *bus) |
459f58ce | 20 | { |
fc279850 | 21 | struct pci_bus *root_bus = find_pci_root_bus(bus); |
610929e1 | 22 | |
fc279850 | 23 | return to_pci_host_bridge(root_bus->bridge); |
610929e1 YL |
24 | } |
25 | ||
4fa2649a YL |
26 | void pci_set_host_bridge_release(struct pci_host_bridge *bridge, |
27 | void (*release_fn)(struct pci_host_bridge *), | |
28 | void *release_data) | |
29 | { | |
30 | bridge->release_fn = release_fn; | |
31 | bridge->release_data = release_data; | |
32 | } | |
33 | ||
fc279850 | 34 | void pcibios_resource_to_bus(struct pci_bus *bus, struct pci_bus_region *region, |
610929e1 YL |
35 | struct resource *res) |
36 | { | |
fc279850 | 37 | struct pci_host_bridge *bridge = find_pci_host_bridge(bus); |
610929e1 YL |
38 | struct pci_host_bridge_window *window; |
39 | resource_size_t offset = 0; | |
40 | ||
41 | list_for_each_entry(window, &bridge->windows, list) { | |
610929e1 YL |
42 | if (resource_contains(window->res, res)) { |
43 | offset = window->offset; | |
44 | break; | |
45 | } | |
46 | } | |
47 | ||
48 | region->start = res->start - offset; | |
49 | region->end = res->end - offset; | |
50 | } | |
51 | EXPORT_SYMBOL(pcibios_resource_to_bus); | |
52 | ||
53 | static bool region_contains(struct pci_bus_region *region1, | |
54 | struct pci_bus_region *region2) | |
55 | { | |
56 | return region1->start <= region2->start && region1->end >= region2->end; | |
57 | } | |
58 | ||
fc279850 | 59 | void pcibios_bus_to_resource(struct pci_bus *bus, struct resource *res, |
610929e1 YL |
60 | struct pci_bus_region *region) |
61 | { | |
fc279850 | 62 | struct pci_host_bridge *bridge = find_pci_host_bridge(bus); |
610929e1 | 63 | struct pci_host_bridge_window *window; |
610929e1 YL |
64 | resource_size_t offset = 0; |
65 | ||
66 | list_for_each_entry(window, &bridge->windows, list) { | |
459f58ce YL |
67 | struct pci_bus_region bus_region; |
68 | ||
610929e1 YL |
69 | if (resource_type(res) != resource_type(window->res)) |
70 | continue; | |
71 | ||
72 | bus_region.start = window->res->start - window->offset; | |
73 | bus_region.end = window->res->end - window->offset; | |
74 | ||
75 | if (region_contains(&bus_region, region)) { | |
76 | offset = window->offset; | |
77 | break; | |
78 | } | |
79 | } | |
80 | ||
81 | res->start = region->start + offset; | |
82 | res->end = region->end + offset; | |
83 | } | |
84 | EXPORT_SYMBOL(pcibios_bus_to_resource); |