Skip to content

Commit 45ca9e9

Browse files
bjorn-helgaasjbarnes993
authored andcommitted
PCI: add helpers for building PCI bus resource lists
We'd like to supply a list of resources when we create a new PCI bus, e.g., the root bus under a PCI host bridge. These are helpers for constructing that list. These are exported because the plan is to replace this exported interface: pci_scan_bus_parented() with this one: pci_add_resource(resources, ...) pci_scan_root_bus(..., resources) Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
1 parent afd24ec commit 45ca9e9

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

‎drivers/pci/bus.c‎

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,32 @@
1818

1919
#include "pci.h"
2020

21+
void pci_add_resource(struct list_head *resources, struct resource *res)
22+
{
23+
struct pci_bus_resource *bus_res;
24+
25+
bus_res = kzalloc(sizeof(struct pci_bus_resource), GFP_KERNEL);
26+
if (!bus_res) {
27+
printk(KERN_ERR "PCI: can't add bus resource %pR\n", res);
28+
return;
29+
}
30+
31+
bus_res->res = res;
32+
list_add_tail(&bus_res->list, resources);
33+
}
34+
EXPORT_SYMBOL(pci_add_resource);
35+
36+
void pci_free_resource_list(struct list_head *resources)
37+
{
38+
struct pci_bus_resource *bus_res, *tmp;
39+
40+
list_for_each_entry_safe(bus_res, tmp, resources, list) {
41+
list_del(&bus_res->list);
42+
kfree(bus_res);
43+
}
44+
}
45+
EXPORT_SYMBOL(pci_free_resource_list);
46+
2147
void pci_bus_add_resource(struct pci_bus *bus, struct resource *res,
2248
unsigned int flags)
2349
{
@@ -52,16 +78,12 @@ EXPORT_SYMBOL_GPL(pci_bus_resource_n);
5278

5379
void pci_bus_remove_resources(struct pci_bus *bus)
5480
{
55-
struct pci_bus_resource *bus_res, *tmp;
5681
int i;
5782

5883
for (i = 0; i < PCI_BRIDGE_RESOURCE_NUM; i++)
5984
bus->resource[i] = NULL;
6085

61-
list_for_each_entry_safe(bus_res, tmp, &bus->resources, list) {
62-
list_del(&bus_res->list);
63-
kfree(bus_res);
64-
}
86+
pci_free_resource_list(&bus->resources);
6587
}
6688

6789
/**

‎include/linux/pci.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,8 @@ int pci_request_selected_regions_exclusive(struct pci_dev *, int, const char *);
917917
void pci_release_selected_regions(struct pci_dev *, int);
918918

919919
/* drivers/pci/bus.c */
920+
void pci_add_resource(struct list_head *resources, struct resource *res);
921+
void pci_free_resource_list(struct list_head *resources);
920922
void pci_bus_add_resource(struct pci_bus *bus, struct resource *res, unsigned int flags);
921923
struct resource *pci_bus_resource_n(const struct pci_bus *bus, int n);
922924
void pci_bus_remove_resources(struct pci_bus *bus);

0 commit comments

Comments
 (0)