x86/boot: Rename overlapping memcpy() to memmove()
[linux/fpc-iii.git] / drivers / pci / host-bridge.c
blob5f4a2e04c8d7cf237535d0cafb0274ba4df904e5
1 /*
2 * host bridge related code
3 */
5 #include <linux/kernel.h>
6 #include <linux/pci.h>
7 #include <linux/module.h>
9 #include "pci.h"
11 static struct pci_bus *find_pci_root_bus(struct pci_bus *bus)
13 while (bus->parent)
14 bus = bus->parent;
16 return bus;
19 struct pci_host_bridge *pci_find_host_bridge(struct pci_bus *bus)
21 struct pci_bus *root_bus = find_pci_root_bus(bus);
23 return to_pci_host_bridge(root_bus->bridge);
26 struct device *pci_get_host_bridge_device(struct pci_dev *dev)
28 struct pci_bus *root_bus = find_pci_root_bus(dev->bus);
29 struct device *bridge = root_bus->bridge;
31 kobject_get(&bridge->kobj);
32 return bridge;
35 void pci_put_host_bridge_device(struct device *dev)
37 kobject_put(&dev->kobj);
40 void pci_set_host_bridge_release(struct pci_host_bridge *bridge,
41 void (*release_fn)(struct pci_host_bridge *),
42 void *release_data)
44 bridge->release_fn = release_fn;
45 bridge->release_data = release_data;
48 void pcibios_resource_to_bus(struct pci_bus *bus, struct pci_bus_region *region,
49 struct resource *res)
51 struct pci_host_bridge *bridge = pci_find_host_bridge(bus);
52 struct resource_entry *window;
53 resource_size_t offset = 0;
55 resource_list_for_each_entry(window, &bridge->windows) {
56 if (resource_contains(window->res, res)) {
57 offset = window->offset;
58 break;
62 region->start = res->start - offset;
63 region->end = res->end - offset;
65 EXPORT_SYMBOL(pcibios_resource_to_bus);
67 static bool region_contains(struct pci_bus_region *region1,
68 struct pci_bus_region *region2)
70 return region1->start <= region2->start && region1->end >= region2->end;
73 void pcibios_bus_to_resource(struct pci_bus *bus, struct resource *res,
74 struct pci_bus_region *region)
76 struct pci_host_bridge *bridge = pci_find_host_bridge(bus);
77 struct resource_entry *window;
78 resource_size_t offset = 0;
80 resource_list_for_each_entry(window, &bridge->windows) {
81 struct pci_bus_region bus_region;
83 if (resource_type(res) != resource_type(window->res))
84 continue;
86 bus_region.start = window->res->start - window->offset;
87 bus_region.end = window->res->end - window->offset;
89 if (region_contains(&bus_region, region)) {
90 offset = window->offset;
91 break;
95 res->start = region->start + offset;
96 res->end = region->end + offset;
98 EXPORT_SYMBOL(pcibios_bus_to_resource);