diff options
author | Bjorn Helgaas <bjorn.helgaas@hp.com> | 2010-02-23 12:24:31 -0500 |
---|---|---|
committer | Jesse Barnes <jbarnes@virtuousgeek.org> | 2010-02-23 12:43:31 -0500 |
commit | 89a74ecccd1f78e51faf6287e5c0e93a92ac096e (patch) | |
tree | 6d167d73fb2cf5bb457b0b19145fcbf81cf441ef | |
parent | 2adf75160b10bf3f09ed7d3d04e937f923fc557e (diff) |
PCI: add pci_bus_for_each_resource(), remove direct bus->resource[] refs
No functional change; this converts loops that iterate from 0 to
PCI_BUS_NUM_RESOURCES through pci_bus resource[] table to use the
pci_bus_for_each_resource() iterator instead.
This doesn't change the way resources are stored; it merely removes
dependencies on the fact that they're in a table.
Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
-rw-r--r-- | arch/ia64/pci/pci.c | 5 | ||||
-rw-r--r-- | arch/mn10300/unit-asb2305/pci.c | 6 | ||||
-rw-r--r-- | arch/powerpc/kernel/pci-common.c | 11 | ||||
-rw-r--r-- | arch/powerpc/platforms/fsl_uli1575.c | 12 | ||||
-rw-r--r-- | drivers/pci/bus.c | 4 | ||||
-rw-r--r-- | drivers/pci/hotplug/shpchp_sysfs.c | 9 | ||||
-rw-r--r-- | drivers/pci/pci.c | 5 | ||||
-rw-r--r-- | drivers/pci/setup-bus.c | 10 | ||||
-rw-r--r-- | drivers/pcmcia/rsrc_nonstatic.c | 3 | ||||
-rw-r--r-- | drivers/pcmcia/yenta_socket.c | 5 | ||||
-rw-r--r-- | include/linux/pci.h | 3 |
11 files changed, 32 insertions, 41 deletions
diff --git a/arch/ia64/pci/pci.c b/arch/ia64/pci/pci.c index 783c83bb2b49..89f957ca3eb2 100644 --- a/arch/ia64/pci/pci.c +++ b/arch/ia64/pci/pci.c | |||
@@ -452,13 +452,12 @@ EXPORT_SYMBOL(pcibios_bus_to_resource); | |||
452 | static int __devinit is_valid_resource(struct pci_dev *dev, int idx) | 452 | static int __devinit is_valid_resource(struct pci_dev *dev, int idx) |
453 | { | 453 | { |
454 | unsigned int i, type_mask = IORESOURCE_IO | IORESOURCE_MEM; | 454 | unsigned int i, type_mask = IORESOURCE_IO | IORESOURCE_MEM; |
455 | struct resource *devr = &dev->resource[idx]; | 455 | struct resource *devr = &dev->resource[idx], *busr; |
456 | 456 | ||
457 | if (!dev->bus) | 457 | if (!dev->bus) |
458 | return 0; | 458 | return 0; |
459 | for (i=0; i<PCI_BUS_NUM_RESOURCES; i++) { | ||
460 | struct resource *busr = dev->bus->resource[i]; | ||
461 | 459 | ||
460 | pci_bus_for_each_resource(dev->bus, busr, i) { | ||
462 | if (!busr || ((busr->flags ^ devr->flags) & type_mask)) | 461 | if (!busr || ((busr->flags ^ devr->flags) & type_mask)) |
463 | continue; | 462 | continue; |
464 | if ((devr->start) && (devr->start >= busr->start) && | 463 | if ((devr->start) && (devr->start >= busr->start) && |
diff --git a/arch/mn10300/unit-asb2305/pci.c b/arch/mn10300/unit-asb2305/pci.c index 2cb7e75ba1c0..6d8720a0a599 100644 --- a/arch/mn10300/unit-asb2305/pci.c +++ b/arch/mn10300/unit-asb2305/pci.c | |||
@@ -331,12 +331,10 @@ static int __init pci_check_direct(void) | |||
331 | static int __devinit is_valid_resource(struct pci_dev *dev, int idx) | 331 | static int __devinit is_valid_resource(struct pci_dev *dev, int idx) |
332 | { | 332 | { |
333 | unsigned int i, type_mask = IORESOURCE_IO | IORESOURCE_MEM; | 333 | unsigned int i, type_mask = IORESOURCE_IO | IORESOURCE_MEM; |
334 | struct resource *devr = &dev->resource[idx]; | 334 | struct resource *devr = &dev->resource[idx], *busr; |
335 | 335 | ||
336 | if (dev->bus) { | 336 | if (dev->bus) { |
337 | for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) { | 337 | pci_bus_for_each_resource(dev->bus, busr, i) { |
338 | struct resource *busr = dev->bus->resource[i]; | ||
339 | |||
340 | if (!busr || (busr->flags ^ devr->flags) & type_mask) | 338 | if (!busr || (busr->flags ^ devr->flags) & type_mask) |
341 | continue; | 339 | continue; |
342 | 340 | ||
diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c index e640810e813f..2597f9545d8a 100644 --- a/arch/powerpc/kernel/pci-common.c +++ b/arch/powerpc/kernel/pci-common.c | |||
@@ -1047,10 +1047,8 @@ static void __devinit pcibios_fixup_bridge(struct pci_bus *bus) | |||
1047 | 1047 | ||
1048 | struct pci_dev *dev = bus->self; | 1048 | struct pci_dev *dev = bus->self; |
1049 | 1049 | ||
1050 | for (i = 0; i < PCI_BUS_NUM_RESOURCES; ++i) { | 1050 | pci_bus_for_each_resource(bus, res, i) { |
1051 | if ((res = bus->resource[i]) == NULL) | 1051 | if (!res || !res->flags) |
1052 | continue; | ||
1053 | if (!res->flags) | ||
1054 | continue; | 1052 | continue; |
1055 | if (i >= 3 && bus->self->transparent) | 1053 | if (i >= 3 && bus->self->transparent) |
1056 | continue; | 1054 | continue; |
@@ -1277,9 +1275,8 @@ void pcibios_allocate_bus_resources(struct pci_bus *bus) | |||
1277 | pr_debug("PCI: Allocating bus resources for %04x:%02x...\n", | 1275 | pr_debug("PCI: Allocating bus resources for %04x:%02x...\n", |
1278 | pci_domain_nr(bus), bus->number); | 1276 | pci_domain_nr(bus), bus->number); |
1279 | 1277 | ||
1280 | for (i = 0; i < PCI_BUS_NUM_RESOURCES; ++i) { | 1278 | pci_bus_for_each_resource(bus, res, i) { |
1281 | if ((res = bus->resource[i]) == NULL || !res->flags | 1279 | if (!res || !res->flags || res->start > res->end || res->parent) |
1282 | || res->start > res->end || res->parent) | ||
1283 | continue; | 1280 | continue; |
1284 | if (bus->parent == NULL) | 1281 | if (bus->parent == NULL) |
1285 | pr = (res->flags & IORESOURCE_IO) ? | 1282 | pr = (res->flags & IORESOURCE_IO) ? |
diff --git a/arch/powerpc/platforms/fsl_uli1575.c b/arch/powerpc/platforms/fsl_uli1575.c index fd23a1d4b39d..8b0c2082a783 100644 --- a/arch/powerpc/platforms/fsl_uli1575.c +++ b/arch/powerpc/platforms/fsl_uli1575.c | |||
@@ -222,6 +222,7 @@ static void __devinit quirk_final_uli5249(struct pci_dev *dev) | |||
222 | int i; | 222 | int i; |
223 | u8 *dummy; | 223 | u8 *dummy; |
224 | struct pci_bus *bus = dev->bus; | 224 | struct pci_bus *bus = dev->bus; |
225 | struct resource *res; | ||
225 | resource_size_t end = 0; | 226 | resource_size_t end = 0; |
226 | 227 | ||
227 | for (i = PCI_BRIDGE_RESOURCES; i < PCI_BRIDGE_RESOURCES+3; i++) { | 228 | for (i = PCI_BRIDGE_RESOURCES; i < PCI_BRIDGE_RESOURCES+3; i++) { |
@@ -230,13 +231,12 @@ static void __devinit quirk_final_uli5249(struct pci_dev *dev) | |||
230 | end = pci_resource_end(dev, i); | 231 | end = pci_resource_end(dev, i); |
231 | } | 232 | } |
232 | 233 | ||
233 | for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) { | 234 | pci_bus_for_each_resource(bus, res, i) { |
234 | if ((bus->resource[i]) && | 235 | if (res && res->flags & IORESOURCE_MEM) { |
235 | (bus->resource[i]->flags & IORESOURCE_MEM)) { | 236 | if (res->end == end) |
236 | if (bus->resource[i]->end == end) | 237 | dummy = ioremap(res->start, 0x4); |
237 | dummy = ioremap(bus->resource[i]->start, 0x4); | ||
238 | else | 238 | else |
239 | dummy = ioremap(bus->resource[i]->end - 3, 0x4); | 239 | dummy = ioremap(res->end - 3, 0x4); |
240 | if (dummy) { | 240 | if (dummy) { |
241 | in_8(dummy); | 241 | in_8(dummy); |
242 | iounmap(dummy); | 242 | iounmap(dummy); |
diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c index a26135bb0ffd..e75d219fd107 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c | |||
@@ -43,6 +43,7 @@ pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res, | |||
43 | void *alignf_data) | 43 | void *alignf_data) |
44 | { | 44 | { |
45 | int i, ret = -ENOMEM; | 45 | int i, ret = -ENOMEM; |
46 | struct resource *r; | ||
46 | resource_size_t max = -1; | 47 | resource_size_t max = -1; |
47 | 48 | ||
48 | type_mask |= IORESOURCE_IO | IORESOURCE_MEM; | 49 | type_mask |= IORESOURCE_IO | IORESOURCE_MEM; |
@@ -51,8 +52,7 @@ pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res, | |||
51 | if (!(res->flags & IORESOURCE_MEM_64)) | 52 | if (!(res->flags & IORESOURCE_MEM_64)) |
52 | max = PCIBIOS_MAX_MEM_32; | 53 | max = PCIBIOS_MAX_MEM_32; |
53 | 54 | ||
54 | for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) { | 55 | pci_bus_for_each_resource(bus, r, i) { |
55 | struct resource *r = bus->resource[i]; | ||
56 | if (!r) | 56 | if (!r) |
57 | continue; | 57 | continue; |
58 | 58 | ||
diff --git a/drivers/pci/hotplug/shpchp_sysfs.c b/drivers/pci/hotplug/shpchp_sysfs.c index 29fa9d26adae..071b7dc0094b 100644 --- a/drivers/pci/hotplug/shpchp_sysfs.c +++ b/drivers/pci/hotplug/shpchp_sysfs.c | |||
@@ -47,8 +47,7 @@ static ssize_t show_ctrl (struct device *dev, struct device_attribute *attr, cha | |||
47 | bus = pdev->subordinate; | 47 | bus = pdev->subordinate; |
48 | 48 | ||
49 | out += sprintf(buf, "Free resources: memory\n"); | 49 | out += sprintf(buf, "Free resources: memory\n"); |
50 | for (index = 0; index < PCI_BUS_NUM_RESOURCES; index++) { | 50 | pci_bus_for_each_resource(bus, res, index) { |
51 | res = bus->resource[index]; | ||
52 | if (res && (res->flags & IORESOURCE_MEM) && | 51 | if (res && (res->flags & IORESOURCE_MEM) && |
53 | !(res->flags & IORESOURCE_PREFETCH)) { | 52 | !(res->flags & IORESOURCE_PREFETCH)) { |
54 | out += sprintf(out, "start = %8.8llx, " | 53 | out += sprintf(out, "start = %8.8llx, " |
@@ -58,8 +57,7 @@ static ssize_t show_ctrl (struct device *dev, struct device_attribute *attr, cha | |||
58 | } | 57 | } |
59 | } | 58 | } |
60 | out += sprintf(out, "Free resources: prefetchable memory\n"); | 59 | out += sprintf(out, "Free resources: prefetchable memory\n"); |
61 | for (index = 0; index < PCI_BUS_NUM_RESOURCES; index++) { | 60 | pci_bus_for_each_resource(bus, res, index) { |
62 | res = bus->resource[index]; | ||
63 | if (res && (res->flags & IORESOURCE_MEM) && | 61 | if (res && (res->flags & IORESOURCE_MEM) && |
64 | (res->flags & IORESOURCE_PREFETCH)) { | 62 | (res->flags & IORESOURCE_PREFETCH)) { |
65 | out += sprintf(out, "start = %8.8llx, " | 63 | out += sprintf(out, "start = %8.8llx, " |
@@ -69,8 +67,7 @@ static ssize_t show_ctrl (struct device *dev, struct device_attribute *attr, cha | |||
69 | } | 67 | } |
70 | } | 68 | } |
71 | out += sprintf(out, "Free resources: IO\n"); | 69 | out += sprintf(out, "Free resources: IO\n"); |
72 | for (index = 0; index < PCI_BUS_NUM_RESOURCES; index++) { | 70 | pci_bus_for_each_resource(bus, res, index) { |
73 | res = bus->resource[index]; | ||
74 | if (res && (res->flags & IORESOURCE_IO)) { | 71 | if (res && (res->flags & IORESOURCE_IO)) { |
75 | out += sprintf(out, "start = %8.8llx, " | 72 | out += sprintf(out, "start = %8.8llx, " |
76 | "length = %8.8llx\n", | 73 | "length = %8.8llx\n", |
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index d62a5de81672..f4a2738bf0bf 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c | |||
@@ -386,10 +386,9 @@ pci_find_parent_resource(const struct pci_dev *dev, struct resource *res) | |||
386 | { | 386 | { |
387 | const struct pci_bus *bus = dev->bus; | 387 | const struct pci_bus *bus = dev->bus; |
388 | int i; | 388 | int i; |
389 | struct resource *best = NULL; | 389 | struct resource *best = NULL, *r; |
390 | 390 | ||
391 | for(i = 0; i < PCI_BUS_NUM_RESOURCES; i++) { | 391 | pci_bus_for_each_resource(bus, r, i) { |
392 | struct resource *r = bus->resource[i]; | ||
393 | if (!r) | 392 | if (!r) |
394 | continue; | 393 | continue; |
395 | if (res->start && !(res->start >= r->start && res->end <= r->end)) | 394 | if (res->start && !(res->start >= r->start && res->end <= r->end)) |
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 743ed8c48b9c..bf32f07c4efb 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c | |||
@@ -387,8 +387,7 @@ static struct resource *find_free_bus_resource(struct pci_bus *bus, unsigned lon | |||
387 | unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM | | 387 | unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM | |
388 | IORESOURCE_PREFETCH; | 388 | IORESOURCE_PREFETCH; |
389 | 389 | ||
390 | for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) { | 390 | pci_bus_for_each_resource(bus, r, i) { |
391 | r = bus->resource[i]; | ||
392 | if (r == &ioport_resource || r == &iomem_resource) | 391 | if (r == &ioport_resource || r == &iomem_resource) |
393 | continue; | 392 | continue; |
394 | if (r && (r->flags & type_mask) == type && !r->parent) | 393 | if (r && (r->flags & type_mask) == type && !r->parent) |
@@ -803,11 +802,10 @@ static void __ref pci_bus_release_bridge_resources(struct pci_bus *bus, | |||
803 | 802 | ||
804 | static void pci_bus_dump_res(struct pci_bus *bus) | 803 | static void pci_bus_dump_res(struct pci_bus *bus) |
805 | { | 804 | { |
806 | int i; | 805 | struct resource *res; |
807 | 806 | int i; | |
808 | for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) { | ||
809 | struct resource *res = bus->resource[i]; | ||
810 | 807 | ||
808 | pci_bus_for_each_resource(bus, res, i) { | ||
811 | if (!res || !res->end || !res->flags) | 809 | if (!res || !res->end || !res->flags) |
812 | continue; | 810 | continue; |
813 | 811 | ||
diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c index 45d75dc452f0..c67638fe6914 100644 --- a/drivers/pcmcia/rsrc_nonstatic.c +++ b/drivers/pcmcia/rsrc_nonstatic.c | |||
@@ -803,8 +803,7 @@ static int nonstatic_autoadd_resources(struct pcmcia_socket *s) | |||
803 | return -EINVAL; | 803 | return -EINVAL; |
804 | #endif | 804 | #endif |
805 | 805 | ||
806 | for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) { | 806 | pci_bus_for_each_resource(s->cb_dev->bus, res, i) { |
807 | res = s->cb_dev->bus->resource[i]; | ||
808 | if (!res) | 807 | if (!res) |
809 | continue; | 808 | continue; |
810 | 809 | ||
diff --git a/drivers/pcmcia/yenta_socket.c b/drivers/pcmcia/yenta_socket.c index e4d12acdd525..1f2039d5e966 100644 --- a/drivers/pcmcia/yenta_socket.c +++ b/drivers/pcmcia/yenta_socket.c | |||
@@ -649,9 +649,10 @@ static int yenta_search_one_res(struct resource *root, struct resource *res, | |||
649 | static int yenta_search_res(struct yenta_socket *socket, struct resource *res, | 649 | static int yenta_search_res(struct yenta_socket *socket, struct resource *res, |
650 | u32 min) | 650 | u32 min) |
651 | { | 651 | { |
652 | struct resource *root; | ||
652 | int i; | 653 | int i; |
653 | for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) { | 654 | |
654 | struct resource *root = socket->dev->bus->resource[i]; | 655 | pci_bus_for_each_resource(socket->dev->bus, root, i) { |
655 | if (!root) | 656 | if (!root) |
656 | continue; | 657 | continue; |
657 | 658 | ||
diff --git a/include/linux/pci.h b/include/linux/pci.h index 1a29f9f6b2dc..2ff9d26a078f 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h | |||
@@ -829,6 +829,9 @@ int pci_request_selected_regions_exclusive(struct pci_dev *, int, const char *); | |||
829 | void pci_release_selected_regions(struct pci_dev *, int); | 829 | void pci_release_selected_regions(struct pci_dev *, int); |
830 | 830 | ||
831 | /* drivers/pci/bus.c */ | 831 | /* drivers/pci/bus.c */ |
832 | #define pci_bus_for_each_resource(bus, res, i) \ | ||
833 | for (i = 0; res = bus->resource[i], i < PCI_BUS_NUM_RESOURCES; i++) | ||
834 | |||
832 | int __must_check pci_bus_alloc_resource(struct pci_bus *bus, | 835 | int __must_check pci_bus_alloc_resource(struct pci_bus *bus, |
833 | struct resource *res, resource_size_t size, | 836 | struct resource *res, resource_size_t size, |
834 | resource_size_t align, resource_size_t min, | 837 | resource_size_t align, resource_size_t min, |