2 * host bridge related code
5 #include <linux/kernel.h>
7 #include <linux/module.h>
11 static struct pci_bus
*find_pci_root_bus(struct pci_bus
*bus
)
19 static struct pci_host_bridge
*find_pci_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 void pci_set_host_bridge_release(struct pci_host_bridge
*bridge
,
27 void (*release_fn
)(struct pci_host_bridge
*),
30 bridge
->release_fn
= release_fn
;
31 bridge
->release_data
= release_data
;
34 void pcibios_resource_to_bus(struct pci_bus
*bus
, struct pci_bus_region
*region
,
37 struct pci_host_bridge
*bridge
= find_pci_host_bridge(bus
);
38 struct pci_host_bridge_window
*window
;
39 resource_size_t offset
= 0;
41 list_for_each_entry(window
, &bridge
->windows
, list
) {
42 if (resource_contains(window
->res
, res
)) {
43 offset
= window
->offset
;
48 region
->start
= res
->start
- offset
;
49 region
->end
= res
->end
- offset
;
51 EXPORT_SYMBOL(pcibios_resource_to_bus
);
53 static bool region_contains(struct pci_bus_region
*region1
,
54 struct pci_bus_region
*region2
)
56 return region1
->start
<= region2
->start
&& region1
->end
>= region2
->end
;
59 void pcibios_bus_to_resource(struct pci_bus
*bus
, struct resource
*res
,
60 struct pci_bus_region
*region
)
62 struct pci_host_bridge
*bridge
= find_pci_host_bridge(bus
);
63 struct pci_host_bridge_window
*window
;
64 resource_size_t offset
= 0;
66 list_for_each_entry(window
, &bridge
->windows
, list
) {
67 struct pci_bus_region bus_region
;
69 if (resource_type(res
) != resource_type(window
->res
))
72 bus_region
.start
= window
->res
->start
- window
->offset
;
73 bus_region
.end
= window
->res
->end
- window
->offset
;
75 if (region_contains(&bus_region
, region
)) {
76 offset
= window
->offset
;
81 res
->start
= region
->start
+ offset
;
82 res
->end
= region
->end
+ offset
;
84 EXPORT_SYMBOL(pcibios_bus_to_resource
);