diff options
author | Yinghai Lu <yinghai@kernel.org> | 2012-09-17 22:20:30 -0700 |
---|---|---|
committer | Yinghai Lu <yinghai@kernel.org> | 2012-09-17 22:20:30 -0700 |
commit | 0bffcc0679fbf359c8763f5ff91b410e149d9f95 (patch) | |
tree | 1f16634ac258e6c65ed34bdad29edc5378e5d90e | |
parent | 51365ee0803b0b6d612017de89cd6e09f8ca08c7 (diff) | |
download | linux-yinghai-0bffcc0679fbf359c8763f5ff91b410e149d9f95.tar.gz |
PCI: Use for_each_res with pci bar reassign funcs
Replace those open code, and make code more readable.
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
-rw-r--r-- | drivers/pci/setup-bus.c | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 63cb3baac74a0a..cec15c100a4b61 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -106,7 +106,7 @@ static resource_size_t get_res_add_size(struct list_head *head, list_for_each_entry(dev_res, head, list) { if (dev_res->res == res) { - int idx = res - &dev_res->dev->resource[0]; + int idx = pci_dev_resource_idx(dev_res->dev, res); dev_printk(KERN_DEBUG, &dev_res->dev->dev, "res[%d]=%pR get_res_add_size add_size %llx\n", @@ -124,15 +124,13 @@ static resource_size_t get_res_add_size(struct list_head *head, static void pdev_sort_resources(struct pci_dev *dev, struct list_head *head) { int i; + struct resource *r; - for (i = 0; i < PCI_NUM_RESOURCES; i++) { - struct resource *r; + for_each_pci_resource(dev, r, i, PCI_ALL_RES) { struct pci_dev_resource *dev_res, *tmp; resource_size_t r_align; struct list_head *n; - r = &dev->resource[i]; - if (r->flags & IORESOURCE_PCI_FIXED) continue; @@ -237,7 +235,7 @@ static void reassign_resources_sorted(struct list_head *realloc_head, if (!found_match)/* just skip */ continue; - idx = res - &add_res->dev->resource[0]; + idx = pci_dev_resource_idx(add_res->dev, res); add_size = add_res->add_size; if (!resource_size(res)) { res->start = add_res->start; @@ -280,7 +278,7 @@ static void assign_requested_resources_sorted(struct list_head *head, list_for_each_entry(dev_res, head, list) { res = dev_res->res; - idx = res - &dev_res->dev->resource[0]; + idx = pci_dev_resource_idx(dev_res->dev, res); if (resource_size(res) && pci_assign_resource(dev_res->dev, idx)) { if (fail_head) { @@ -757,9 +755,9 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size, io_align = min_align = window_alignment(bus, IORESOURCE_IO); list_for_each_entry(dev, &bus->devices, bus_list) { int i; + struct resource *r; - for (i = 0; i < PCI_NUM_RESOURCES; i++) { - struct resource *r = &dev->resource[i]; + for_each_pci_resource(dev, r, i, PCI_ALL_RES) { unsigned long r_size; if (r->parent || !(r->flags & IORESOURCE_IO)) @@ -870,9 +868,9 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, list_for_each_entry(dev, &bus->devices, bus_list) { int i; + struct resource *r; - for (i = 0; i < PCI_NUM_RESOURCES; i++) { - struct resource *r = &dev->resource[i]; + for_each_pci_resource(dev, r, i, PCI_ALL_RES) { resource_size_t r_size; if (r->parent || (r->flags & mask) != type) @@ -1202,9 +1200,7 @@ static void pci_bridge_release_resources(struct pci_bus *bus, IORESOURCE_PREFETCH; dev = bus->self; - for (idx = PCI_BRIDGE_RESOURCES; idx <= PCI_BRIDGE_RESOURCE_END; - idx++) { - r = &dev->resource[idx]; + for_each_pci_resource(dev, r, idx, PCI_BRIDGE_RES) { if ((r->flags & type_mask) != type) continue; if (!r->parent) @@ -1375,9 +1371,9 @@ static void __init pci_realloc_detect(void) for_each_pci_dev(dev) { int i; + struct resource *r; - for (i = PCI_IOV_RESOURCES; i <= PCI_IOV_RESOURCE_END; i++) { - struct resource *r = &dev->resource[i]; + for_each_pci_resource(dev, r, i, PCI_IOV_RES) { /* Not assigned, or rejected by kernel ? */ if (r->flags && !r->start) { |