2 * host bridge related code
5 #include <linux/kernel.h>
6 #include <linux/init.h>
8 #include <linux/module.h>
12 static struct pci_bus *find_pci_root_bus(struct pci_dev *dev)
23 static struct pci_host_bridge *find_pci_host_bridge(struct pci_dev *dev)
25 struct pci_bus *bus = find_pci_root_bus(dev);
27 return to_pci_host_bridge(bus->bridge);
30 void pci_set_host_bridge_release(struct pci_host_bridge *bridge,
31 void (*release_fn)(struct pci_host_bridge *),
34 bridge->release_fn = release_fn;
35 bridge->release_data = release_data;
38 static bool resource_contains(struct resource *res1, struct resource *res2)
40 return res1->start <= res2->start && res1->end >= res2->end;
43 void pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region,
46 struct pci_host_bridge *bridge = find_pci_host_bridge(dev);
47 struct pci_host_bridge_window *window;
48 resource_size_t offset = 0;
50 list_for_each_entry(window, &bridge->windows, list) {
51 if (resource_type(res) != resource_type(window->res))
54 if (resource_contains(window->res, res)) {
55 offset = window->offset;
60 region->start = res->start - offset;
61 region->end = res->end - offset;
63 EXPORT_SYMBOL(pcibios_resource_to_bus);
65 static bool region_contains(struct pci_bus_region *region1,
66 struct pci_bus_region *region2)
68 return region1->start <= region2->start && region1->end >= region2->end;
71 void pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res,
72 struct pci_bus_region *region)
74 struct pci_host_bridge *bridge = find_pci_host_bridge(dev);
75 struct pci_host_bridge_window *window;
76 resource_size_t offset = 0;
78 list_for_each_entry(window, &bridge->windows, list) {
79 struct pci_bus_region bus_region;
81 if (resource_type(res) != resource_type(window->res))
84 bus_region.start = window->res->start - window->offset;
85 bus_region.end = window->res->end - window->offset;
87 if (region_contains(&bus_region, region)) {
88 offset = window->offset;
93 res->start = region->start + offset;
94 res->end = region->end + offset;
96 EXPORT_SYMBOL(pcibios_bus_to_resource);