Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'pci/resource'

- Add pci_dev_for_each_resource() and pci_bus_for_each_resource() iterators
to simplify loops (Andy Shevchenko)

* pci/resource:
EISA: Drop unused pci_bus_for_each_resource() index argument
PCI: Make pci_bus_for_each_resource() index optional
PCI: Document pci_bus_for_each_resource()
PCI: Introduce pci_dev_for_each_resource()
PCI: Introduce pci_resource_n()

+171 -163
+1
.clang-format
··· 520 520 - 'of_property_for_each_string' 521 521 - 'of_property_for_each_u32' 522 522 - 'pci_bus_for_each_resource' 523 + - 'pci_dev_for_each_resource' 523 524 - 'pci_doe_for_each_off' 524 525 - 'pcl_for_each_chunk' 525 526 - 'pcl_for_each_segment'
+2 -3
arch/alpha/kernel/pci.c
··· 288 288 struct pci_bus *child_bus; 289 289 290 290 list_for_each_entry(dev, &b->devices, bus_list) { 291 + struct resource *r; 291 292 int i; 292 293 293 - for (i = 0; i < PCI_NUM_RESOURCES; i++) { 294 - struct resource *r = &dev->resource[i]; 295 - 294 + pci_dev_for_each_resource(dev, r, i) { 296 295 if (r->parent || !r->start || !r->flags) 297 296 continue; 298 297 if (pci_has_flag(PCI_PROBE_ONLY) ||
+7 -9
arch/arm/kernel/bios32.c
··· 142 142 */ 143 143 static void pci_fixup_dec21285(struct pci_dev *dev) 144 144 { 145 - int i; 146 - 147 145 if (dev->devfn == 0) { 146 + struct resource *r; 147 + 148 148 dev->class &= 0xff; 149 149 dev->class |= PCI_CLASS_BRIDGE_HOST << 8; 150 - for (i = 0; i < PCI_NUM_RESOURCES; i++) { 151 - dev->resource[i].start = 0; 152 - dev->resource[i].end = 0; 153 - dev->resource[i].flags = 0; 150 + pci_dev_for_each_resource(dev, r) { 151 + r->start = 0; 152 + r->end = 0; 153 + r->flags = 0; 154 154 } 155 155 } 156 156 } ··· 162 162 static void pci_fixup_ide_bases(struct pci_dev *dev) 163 163 { 164 164 struct resource *r; 165 - int i; 166 165 167 166 if ((dev->class >> 8) != PCI_CLASS_STORAGE_IDE) 168 167 return; 169 168 170 - for (i = 0; i < PCI_NUM_RESOURCES; i++) { 171 - r = dev->resource + i; 169 + pci_dev_for_each_resource(dev, r) { 172 170 if ((r->start & ~0x80) == 0x374) { 173 171 r->start |= 2; 174 172 r->end = r->start;
+5 -5
arch/arm/mach-dove/pcie.c
··· 142 142 static void rc_pci_fixup(struct pci_dev *dev) 143 143 { 144 144 if (dev->bus->parent == NULL && dev->devfn == 0) { 145 - int i; 145 + struct resource *r; 146 146 147 147 dev->class &= 0xff; 148 148 dev->class |= PCI_CLASS_BRIDGE_HOST << 8; 149 - for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { 150 - dev->resource[i].start = 0; 151 - dev->resource[i].end = 0; 152 - dev->resource[i].flags = 0; 149 + pci_dev_for_each_resource(dev, r) { 150 + r->start = 0; 151 + r->end = 0; 152 + r->flags = 0; 153 153 } 154 154 } 155 155 }
+5 -5
arch/arm/mach-mv78xx0/pcie.c
··· 186 186 static void rc_pci_fixup(struct pci_dev *dev) 187 187 { 188 188 if (dev->bus->parent == NULL && dev->devfn == 0) { 189 - int i; 189 + struct resource *r; 190 190 191 191 dev->class &= 0xff; 192 192 dev->class |= PCI_CLASS_BRIDGE_HOST << 8; 193 - for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { 194 - dev->resource[i].start = 0; 195 - dev->resource[i].end = 0; 196 - dev->resource[i].flags = 0; 193 + pci_dev_for_each_resource(dev, r) { 194 + r->start = 0; 195 + r->end = 0; 196 + r->flags = 0; 197 197 } 198 198 } 199 199 }
+5 -5
arch/arm/mach-orion5x/pci.c
··· 522 522 static void rc_pci_fixup(struct pci_dev *dev) 523 523 { 524 524 if (dev->bus->parent == NULL && dev->devfn == 0) { 525 - int i; 525 + struct resource *r; 526 526 527 527 dev->class &= 0xff; 528 528 dev->class |= PCI_CLASS_BRIDGE_HOST << 8; 529 - for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { 530 - dev->resource[i].start = 0; 531 - dev->resource[i].end = 0; 532 - dev->resource[i].flags = 0; 529 + pci_dev_for_each_resource(dev, r) { 530 + r->start = 0; 531 + r->end = 0; 532 + r->flags = 0; 533 533 } 534 534 } 535 535 }
+4 -4
arch/mips/pci/ops-bcm63xx.c
··· 413 413 static void bcm63xx_fixup(struct pci_dev *dev) 414 414 { 415 415 static int io_window = -1; 416 - int i, found, new_io_window; 416 + int found, new_io_window; 417 + struct resource *r; 417 418 u32 val; 418 419 419 420 /* look for any io resource */ 420 421 found = 0; 421 - for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { 422 - if (pci_resource_flags(dev, i) & IORESOURCE_IO) { 422 + pci_dev_for_each_resource(dev, r) { 423 + if (resource_type(r) == IORESOURCE_IO) { 423 424 found = 1; 424 425 break; 425 426 } 426 427 } 427 - 428 428 if (!found) 429 429 return; 430 430
+1 -2
arch/mips/pci/pci-legacy.c
··· 249 249 250 250 pci_read_config_word(dev, PCI_COMMAND, &cmd); 251 251 old_cmd = cmd; 252 - for (idx = 0; idx < PCI_NUM_RESOURCES; idx++) { 252 + pci_dev_for_each_resource(dev, r, idx) { 253 253 /* Only set up the requested stuff */ 254 254 if (!(mask & (1<<idx))) 255 255 continue; 256 256 257 - r = &dev->resource[idx]; 258 257 if (!(r->flags & (IORESOURCE_IO | IORESOURCE_MEM))) 259 258 continue; 260 259 if ((idx == PCI_ROM_RESOURCE) &&
+11 -10
arch/powerpc/kernel/pci-common.c
··· 880 880 static void pcibios_fixup_resources(struct pci_dev *dev) 881 881 { 882 882 struct pci_controller *hose = pci_bus_to_host(dev->bus); 883 + struct resource *res; 883 884 int i; 884 885 885 886 if (!hose) { ··· 892 891 if (dev->is_virtfn) 893 892 return; 894 893 895 - for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { 896 - struct resource *res = dev->resource + i; 894 + pci_dev_for_each_resource(dev, res, i) { 897 895 struct pci_bus_region reg; 896 + 898 897 if (!res->flags) 899 898 continue; 900 899 ··· 1453 1452 struct pci_bus *child_bus; 1454 1453 1455 1454 list_for_each_entry(dev, &bus->devices, bus_list) { 1455 + struct resource *r; 1456 1456 int i; 1457 1457 1458 - for (i = 0; i < PCI_NUM_RESOURCES; i++) { 1459 - struct resource *r = &dev->resource[i]; 1460 - 1458 + pci_dev_for_each_resource(dev, r, i) { 1461 1459 if (r->parent || !r->start || !r->flags) 1462 1460 continue; 1463 1461 ··· 1705 1705 1706 1706 static void fixup_hide_host_resource_fsl(struct pci_dev *dev) 1707 1707 { 1708 - int i, class = dev->class >> 8; 1708 + int class = dev->class >> 8; 1709 1709 /* When configured as agent, programming interface = 1 */ 1710 1710 int prog_if = dev->class & 0xf; 1711 + struct resource *r; 1711 1712 1712 1713 if ((class == PCI_CLASS_PROCESSOR_POWERPC || 1713 1714 class == PCI_CLASS_BRIDGE_OTHER) && 1714 1715 (dev->hdr_type == PCI_HEADER_TYPE_NORMAL) && 1715 1716 (prog_if == 0) && 1716 1717 (dev->bus->parent == NULL)) { 1717 - for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { 1718 - dev->resource[i].start = 0; 1719 - dev->resource[i].end = 0; 1720 - dev->resource[i].flags = 0; 1718 + pci_dev_for_each_resource(dev, r) { 1719 + r->start = 0; 1720 + r->end = 0; 1721 + r->flags = 0; 1721 1722 } 1722 1723 } 1723 1724 }
+4 -4
arch/powerpc/platforms/4xx/pci.c
··· 57 57 static void fixup_ppc4xx_pci_bridge(struct pci_dev *dev) 58 58 { 59 59 struct pci_controller *hose; 60 - int i; 60 + struct resource *r; 61 61 62 62 if (dev->devfn != 0 || dev->bus->self != NULL) 63 63 return; ··· 79 79 /* Hide the PCI host BARs from the kernel as their content doesn't 80 80 * fit well in the resource management 81 81 */ 82 - for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { 83 - dev->resource[i].start = dev->resource[i].end = 0; 84 - dev->resource[i].flags = 0; 82 + pci_dev_for_each_resource(dev, r) { 83 + r->start = r->end = 0; 84 + r->flags = 0; 85 85 } 86 86 87 87 printk(KERN_INFO "PCI: Hiding 4xx host bridge resources %s\n",
+2 -3
arch/powerpc/platforms/52xx/mpc52xx_pci.c
··· 327 327 static void 328 328 mpc52xx_pci_fixup_resources(struct pci_dev *dev) 329 329 { 330 - int i; 330 + struct resource *res; 331 331 332 332 pr_debug("%s() %.4x:%.4x\n", __func__, dev->vendor, dev->device); 333 333 334 334 /* We don't rely on boot loader for PCI and resets all 335 335 devices */ 336 - for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { 337 - struct resource *res = &dev->resource[i]; 336 + pci_dev_for_each_resource(dev, res) { 338 337 if (res->end > res->start) { /* Only valid resources */ 339 338 res->end -= res->start; 340 339 res->start = 0;
+8 -8
arch/powerpc/platforms/pseries/pci.c
··· 240 240 */ 241 241 static void fixup_winbond_82c105(struct pci_dev* dev) 242 242 { 243 - int i; 243 + struct resource *r; 244 244 unsigned int reg; 245 245 246 246 if (!machine_is(pseries)) ··· 251 251 /* Enable LEGIRQ to use INTC instead of ISA interrupts */ 252 252 pci_write_config_dword(dev, 0x40, reg | (1<<11)); 253 253 254 - for (i = 0; i < DEVICE_COUNT_RESOURCE; ++i) { 254 + pci_dev_for_each_resource(dev, r) { 255 255 /* zap the 2nd function of the winbond chip */ 256 - if (dev->resource[i].flags & IORESOURCE_IO 257 - && dev->bus->number == 0 && dev->devfn == 0x81) 258 - dev->resource[i].flags &= ~IORESOURCE_IO; 259 - if (dev->resource[i].start == 0 && dev->resource[i].end) { 260 - dev->resource[i].flags = 0; 261 - dev->resource[i].end = 0; 256 + if (dev->bus->number == 0 && dev->devfn == 0x81 && 257 + r->flags & IORESOURCE_IO) 258 + r->flags &= ~IORESOURCE_IO; 259 + if (r->start == 0 && r->end) { 260 + r->flags = 0; 261 + r->end = 0; 262 262 } 263 263 } 264 264 }
+5 -5
arch/sh/drivers/pci/pcie-sh7786.c
··· 140 140 * Prevent enumeration of root complex resources. 141 141 */ 142 142 if (pci_is_root_bus(dev->bus) && dev->devfn == 0) { 143 - int i; 143 + struct resource *r; 144 144 145 - for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { 146 - dev->resource[i].start = 0; 147 - dev->resource[i].end = 0; 148 - dev->resource[i].flags = 0; 145 + pci_dev_for_each_resource(dev, r) { 146 + r->start = 0; 147 + r->end = 0; 148 + r->flags = 0; 149 149 } 150 150 } 151 151 }
+2 -3
arch/sparc/kernel/leon_pci.c
··· 62 62 63 63 int pcibios_enable_device(struct pci_dev *dev, int mask) 64 64 { 65 + struct resource *res; 65 66 u16 cmd, oldcmd; 66 67 int i; 67 68 68 69 pci_read_config_word(dev, PCI_COMMAND, &cmd); 69 70 oldcmd = cmd; 70 71 71 - for (i = 0; i < PCI_NUM_RESOURCES; i++) { 72 - struct resource *res = &dev->resource[i]; 73 - 72 + pci_dev_for_each_resource(dev, res, i) { 74 73 /* Only set up the requested stuff */ 75 74 if (!(mask & (1<<i))) 76 75 continue;
+4 -6
arch/sparc/kernel/pci.c
··· 663 663 struct pci_dev *dev; 664 664 665 665 list_for_each_entry(dev, &bus->devices, bus_list) { 666 + struct resource *r; 666 667 int i; 667 668 668 - for (i = 0; i < PCI_NUM_RESOURCES; i++) { 669 - struct resource *r = &dev->resource[i]; 670 - 669 + pci_dev_for_each_resource(dev, r, i) { 671 670 if (r->parent || !r->start || !r->flags) 672 671 continue; 673 672 ··· 723 724 724 725 int pcibios_enable_device(struct pci_dev *dev, int mask) 725 726 { 727 + struct resource *res; 726 728 u16 cmd, oldcmd; 727 729 int i; 728 730 729 731 pci_read_config_word(dev, PCI_COMMAND, &cmd); 730 732 oldcmd = cmd; 731 733 732 - for (i = 0; i < PCI_NUM_RESOURCES; i++) { 733 - struct resource *res = &dev->resource[i]; 734 - 734 + pci_dev_for_each_resource(dev, res, i) { 735 735 /* Only set up the requested stuff */ 736 736 if (!(mask & (1<<i))) 737 737 continue;
+2 -3
arch/sparc/kernel/pcic.c
··· 643 643 644 644 int pcibios_enable_device(struct pci_dev *dev, int mask) 645 645 { 646 + struct resource *res; 646 647 u16 cmd, oldcmd; 647 648 int i; 648 649 649 650 pci_read_config_word(dev, PCI_COMMAND, &cmd); 650 651 oldcmd = cmd; 651 652 652 - for (i = 0; i < PCI_NUM_RESOURCES; i++) { 653 - struct resource *res = &dev->resource[i]; 654 - 653 + pci_dev_for_each_resource(dev, res, i) { 655 654 /* Only set up the requested stuff */ 656 655 if (!(mask & (1<<i))) 657 656 continue;
+2 -2
drivers/eisa/pci_eisa.c
··· 20 20 21 21 static int __init pci_eisa_init(struct pci_dev *pdev) 22 22 { 23 - int rc, i; 24 23 struct resource *res, *bus_res = NULL; 24 + int rc; 25 25 26 26 if ((rc = pci_enable_device (pdev))) { 27 27 dev_err(&pdev->dev, "Could not enable device\n"); ··· 38 38 * eisa_root_register() can only deal with a single io port resource, 39 39 * so we use the first valid io port resource. 40 40 */ 41 - pci_bus_for_each_resource(pdev->bus, res, i) 41 + pci_bus_for_each_resource(pdev->bus, res) 42 42 if (res && (res->flags & IORESOURCE_IO)) { 43 43 bus_res = res; 44 44 break;
+3 -4
drivers/pci/bus.c
··· 161 161 void *alignf_data, 162 162 struct pci_bus_region *region) 163 163 { 164 - int i, ret; 165 164 struct resource *r, avail; 166 165 resource_size_t max; 166 + int ret; 167 167 168 168 type_mask |= IORESOURCE_TYPE_BITS; 169 169 170 - pci_bus_for_each_resource(bus, r, i) { 170 + pci_bus_for_each_resource(bus, r) { 171 171 resource_size_t min_used = min; 172 172 173 173 if (!r) ··· 268 268 struct resource *res = &dev->resource[idx]; 269 269 struct resource orig_res = *res; 270 270 struct resource *r; 271 - int i; 272 271 273 - pci_bus_for_each_resource(bus, r, i) { 272 + pci_bus_for_each_resource(bus, r) { 274 273 resource_size_t start, end; 275 274 276 275 if (!r)
+4 -4
drivers/pci/hotplug/shpchp_sysfs.c
··· 24 24 static ssize_t show_ctrl(struct device *dev, struct device_attribute *attr, char *buf) 25 25 { 26 26 struct pci_dev *pdev; 27 - int index, busnr; 28 27 struct resource *res; 29 28 struct pci_bus *bus; 30 29 size_t len = 0; 30 + int busnr; 31 31 32 32 pdev = to_pci_dev(dev); 33 33 bus = pdev->subordinate; 34 34 35 35 len += sysfs_emit_at(buf, len, "Free resources: memory\n"); 36 - pci_bus_for_each_resource(bus, res, index) { 36 + pci_bus_for_each_resource(bus, res) { 37 37 if (res && (res->flags & IORESOURCE_MEM) && 38 38 !(res->flags & IORESOURCE_PREFETCH)) { 39 39 len += sysfs_emit_at(buf, len, ··· 43 43 } 44 44 } 45 45 len += sysfs_emit_at(buf, len, "Free resources: prefetchable memory\n"); 46 - pci_bus_for_each_resource(bus, res, index) { 46 + pci_bus_for_each_resource(bus, res) { 47 47 if (res && (res->flags & IORESOURCE_MEM) && 48 48 (res->flags & IORESOURCE_PREFETCH)) { 49 49 len += sysfs_emit_at(buf, len, ··· 53 53 } 54 54 } 55 55 len += sysfs_emit_at(buf, len, "Free resources: IO\n"); 56 - pci_bus_for_each_resource(bus, res, index) { 56 + pci_bus_for_each_resource(bus, res) { 57 57 if (res && (res->flags & IORESOURCE_IO)) { 58 58 len += sysfs_emit_at(buf, len, 59 59 "start = %8.8llx, length = %8.8llx\n",
+1 -2
drivers/pci/pci.c
··· 787 787 { 788 788 const struct pci_bus *bus = dev->bus; 789 789 struct resource *r; 790 - int i; 791 790 792 - pci_bus_for_each_resource(bus, r, i) { 791 + pci_bus_for_each_resource(bus, r) { 793 792 if (!r) 794 793 continue; 795 794 if (resource_contains(r, res)) {
+1 -1
drivers/pci/probe.c
··· 533 533 pci_read_bridge_mmio_pref(child); 534 534 535 535 if (dev->transparent) { 536 - pci_bus_for_each_resource(child->parent, res, i) { 536 + pci_bus_for_each_resource(child->parent, res) { 537 537 if (res && res->flags) { 538 538 pci_bus_add_resource(child, res, 539 539 PCI_SUBTRACTIVE_DECODE);
+2 -3
drivers/pci/remove.c
··· 5 5 6 6 static void pci_free_resources(struct pci_dev *dev) 7 7 { 8 - int i; 8 + struct resource *res; 9 9 10 - for (i = 0; i < PCI_NUM_RESOURCES; i++) { 11 - struct resource *res = dev->resource + i; 10 + pci_dev_for_each_resource(dev, res) { 12 11 if (res->parent) 13 12 release_resource(res); 14 13 }
+14 -23
drivers/pci/setup-bus.c
··· 124 124 return dev_res ? dev_res->min_align : 0; 125 125 } 126 126 127 - 128 127 /* Sort resources by alignment */ 129 128 static void pdev_sort_resources(struct pci_dev *dev, struct list_head *head) 130 129 { 130 + struct resource *r; 131 131 int i; 132 132 133 - for (i = 0; i < PCI_NUM_RESOURCES; i++) { 134 - struct resource *r; 133 + pci_dev_for_each_resource(dev, r, i) { 135 134 struct pci_dev_resource *dev_res, *tmp; 136 135 resource_size_t r_align; 137 136 struct list_head *n; 138 - 139 - r = &dev->resource[i]; 140 137 141 138 if (r->flags & IORESOURCE_PCI_FIXED) 142 139 continue; ··· 770 773 unsigned long type) 771 774 { 772 775 struct resource *r, *r_assigned = NULL; 773 - int i; 774 776 775 - pci_bus_for_each_resource(bus, r, i) { 777 + pci_bus_for_each_resource(bus, r) { 776 778 if (r == &ioport_resource || r == &iomem_resource) 777 779 continue; 778 780 if (r && (r->flags & type_mask) == type && !r->parent) ··· 891 895 892 896 min_align = window_alignment(bus, IORESOURCE_IO); 893 897 list_for_each_entry(dev, &bus->devices, bus_list) { 894 - int i; 898 + struct resource *r; 895 899 896 - for (i = 0; i < PCI_NUM_RESOURCES; i++) { 897 - struct resource *r = &dev->resource[i]; 900 + pci_dev_for_each_resource(dev, r) { 898 901 unsigned long r_size; 899 902 900 903 if (r->parent || !(r->flags & IORESOURCE_IO)) ··· 1009 1014 size = 0; 1010 1015 1011 1016 list_for_each_entry(dev, &bus->devices, bus_list) { 1017 + struct resource *r; 1012 1018 int i; 1013 1019 1014 - for (i = 0; i < PCI_NUM_RESOURCES; i++) { 1015 - struct resource *r = &dev->resource[i]; 1020 + pci_dev_for_each_resource(dev, r, i) { 1016 1021 resource_size_t r_size; 1017 1022 1018 1023 if (r->parent || (r->flags & IORESOURCE_PCI_FIXED) || ··· 1203 1208 additional_mmio_pref_size = 0; 1204 1209 struct resource *pref; 1205 1210 struct pci_host_bridge *host; 1206 - int hdr_type, i, ret; 1211 + int hdr_type, ret; 1207 1212 1208 1213 list_for_each_entry(dev, &bus->devices, bus_list) { 1209 1214 struct pci_bus *b = dev->subordinate; ··· 1227 1232 host = to_pci_host_bridge(bus->bridge); 1228 1233 if (!host->size_windows) 1229 1234 return; 1230 - pci_bus_for_each_resource(bus, pref, i) 1235 + pci_bus_for_each_resource(bus, pref) 1231 1236 if (pref && (pref->flags & IORESOURCE_PREFETCH)) 1232 1237 break; 1233 1238 hdr_type = -1; /* Intentionally invalid - not a PCI device. */ ··· 1332 1337 1333 1338 static void assign_fixed_resource_on_bus(struct pci_bus *b, struct resource *r) 1334 1339 { 1335 - int i; 1336 1340 struct resource *parent_r; 1337 1341 unsigned long mask = IORESOURCE_IO | IORESOURCE_MEM | 1338 1342 IORESOURCE_PREFETCH; 1339 1343 1340 - pci_bus_for_each_resource(b, parent_r, i) { 1344 + pci_bus_for_each_resource(b, parent_r) { 1341 1345 if (!parent_r) 1342 1346 continue; 1343 1347 ··· 1352 1358 */ 1353 1359 static void pdev_assign_fixed_resources(struct pci_dev *dev) 1354 1360 { 1355 - int i; 1361 + struct resource *r; 1356 1362 1357 - for (i = 0; i < PCI_NUM_RESOURCES; i++) { 1363 + pci_dev_for_each_resource(dev, r) { 1358 1364 struct pci_bus *b; 1359 - struct resource *r = &dev->resource[i]; 1360 1365 1361 1366 if (r->parent || !(r->flags & IORESOURCE_PCI_FIXED) || 1362 1367 !(r->flags & (IORESOURCE_IO | IORESOURCE_MEM))) ··· 1788 1795 struct resource *mmio, 1789 1796 struct resource *mmio_pref) 1790 1797 { 1791 - int i; 1798 + struct resource *res; 1792 1799 1793 - for (i = 0; i < PCI_NUM_RESOURCES; i++) { 1794 - struct resource *res = &dev->resource[i]; 1795 - 1800 + pci_dev_for_each_resource(dev, res) { 1796 1801 if (resource_type(res) == IORESOURCE_IO) { 1797 1802 remove_dev_resource(io, dev, res); 1798 1803 } else if (resource_type(res) == IORESOURCE_MEM) {
+1 -3
drivers/pci/setup-res.c
··· 484 484 pci_read_config_word(dev, PCI_COMMAND, &cmd); 485 485 old_cmd = cmd; 486 486 487 - for (i = 0; i < PCI_NUM_RESOURCES; i++) { 487 + pci_dev_for_each_resource(dev, r, i) { 488 488 if (!(mask & (1 << i))) 489 489 continue; 490 - 491 - r = &dev->resource[i]; 492 490 493 491 if (!(r->flags & (IORESOURCE_IO | IORESOURCE_MEM))) 494 492 continue;
+5 -12
drivers/pci/vgaarb.c
··· 548 548 #if defined(CONFIG_X86) || defined(CONFIG_IA64) 549 549 u64 base = screen_info.lfb_base; 550 550 u64 size = screen_info.lfb_size; 551 + struct resource *r; 551 552 u64 limit; 552 - resource_size_t start, end; 553 - unsigned long flags; 554 - int i; 555 553 556 554 /* Select the device owning the boot framebuffer if there is one */ 557 555 ··· 559 561 limit = base + size; 560 562 561 563 /* Does firmware framebuffer belong to us? */ 562 - for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { 563 - flags = pci_resource_flags(pdev, i); 564 - 565 - if ((flags & IORESOURCE_MEM) == 0) 564 + pci_dev_for_each_resource(pdev, r) { 565 + if (resource_type(r) != IORESOURCE_MEM) 566 566 continue; 567 567 568 - start = pci_resource_start(pdev, i); 569 - end = pci_resource_end(pdev, i); 570 - 571 - if (!start || !end) 568 + if (!r->start || !r->end) 572 569 continue; 573 570 574 - if (base < start || limit >= end) 571 + if (base < r->start || limit >= r->end) 575 572 continue; 576 573 577 574 return true;
+1 -3
drivers/pci/xen-pcifront.c
··· 390 390 int i; 391 391 struct resource *r; 392 392 393 - for (i = 0; i < PCI_NUM_RESOURCES; i++) { 394 - r = &dev->resource[i]; 395 - 393 + pci_dev_for_each_resource(dev, r, i) { 396 394 if (!r->parent && r->start && r->flags) { 397 395 dev_info(&pdev->xdev->dev, "claiming resource %s/%d\n", 398 396 pci_name(dev), i);
+10 -19
drivers/pnp/quirks.c
··· 229 229 static void quirk_system_pci_resources(struct pnp_dev *dev) 230 230 { 231 231 struct pci_dev *pdev = NULL; 232 - struct resource *res; 233 - resource_size_t pnp_start, pnp_end, pci_start, pci_end; 232 + struct resource *res, *r; 234 233 int i, j; 235 234 236 235 /* ··· 242 243 * so they won't be claimed by the PNP system driver. 243 244 */ 244 245 for_each_pci_dev(pdev) { 245 - for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { 246 - unsigned long flags, type; 246 + pci_dev_for_each_resource(pdev, r, i) { 247 + unsigned long type = resource_type(r); 247 248 248 - flags = pci_resource_flags(pdev, i); 249 - type = flags & (IORESOURCE_IO | IORESOURCE_MEM); 250 - if (!type || pci_resource_len(pdev, i) == 0) 249 + if (!(type == IORESOURCE_IO || type == IORESOURCE_MEM) || 250 + resource_size(r) == 0) 251 251 continue; 252 252 253 - if (flags & IORESOURCE_UNSET) 253 + if (r->flags & IORESOURCE_UNSET) 254 254 continue; 255 255 256 - pci_start = pci_resource_start(pdev, i); 257 - pci_end = pci_resource_end(pdev, i); 258 256 for (j = 0; 259 257 (res = pnp_get_resource(dev, type, j)); j++) { 260 258 if (res->start == 0 && res->end == 0) 261 259 continue; 262 260 263 - pnp_start = res->start; 264 - pnp_end = res->end; 265 - 266 261 /* 267 262 * If the PNP region doesn't overlap the PCI 268 263 * region at all, there's no problem. 269 264 */ 270 - if (pnp_end < pci_start || pnp_start > pci_end) 265 + if (!resource_overlaps(res, r)) 271 266 continue; 272 267 273 268 /* ··· 271 278 * PNP device describes a bridge with PCI 272 279 * behind it. 273 280 */ 274 - if (pnp_start <= pci_start && 275 - pnp_end >= pci_end) 281 + if (res->start <= r->start && res->end >= r->end) 276 282 continue; 277 283 278 284 /* ··· 280 288 * driver from requesting its resources. 281 289 */ 282 290 dev_warn(&dev->dev, 283 - "disabling %pR because it overlaps " 284 - "%s BAR %d %pR\n", res, 285 - pci_name(pdev), i, &pdev->resource[i]); 291 + "disabling %pR because it overlaps %s BAR %d %pR\n", 292 + res, pci_name(pdev), i, r); 286 293 res->flags |= IORESOURCE_DISABLED; 287 294 } 288 295 }
+59 -12
include/linux/pci.h
··· 1444 1444 /* Temporary until new and working PCI SBR API in place */ 1445 1445 int pci_bridge_secondary_bus_reset(struct pci_dev *dev); 1446 1446 1447 - #define pci_bus_for_each_resource(bus, res, i) \ 1448 - for (i = 0; \ 1449 - (res = pci_bus_resource_n(bus, i)) || i < PCI_BRIDGE_RESOURCE_NUM; \ 1450 - i++) 1447 + #define __pci_bus_for_each_res0(bus, res, ...) \ 1448 + for (unsigned int __b = 0; \ 1449 + (res = pci_bus_resource_n(bus, __b)) || __b < PCI_BRIDGE_RESOURCE_NUM; \ 1450 + __b++) 1451 + 1452 + #define __pci_bus_for_each_res1(bus, res, __b) \ 1453 + for (__b = 0; \ 1454 + (res = pci_bus_resource_n(bus, __b)) || __b < PCI_BRIDGE_RESOURCE_NUM; \ 1455 + __b++) 1456 + 1457 + /** 1458 + * pci_bus_for_each_resource - iterate over PCI bus resources 1459 + * @bus: the PCI bus 1460 + * @res: pointer to the current resource 1461 + * @...: optional index of the current resource 1462 + * 1463 + * Iterate over PCI bus resources. The first part is to go over PCI bus 1464 + * resource array, which has at most the %PCI_BRIDGE_RESOURCE_NUM entries. 1465 + * After that continue with the separate list of the additional resources, 1466 + * if not empty. That's why the Logical OR is being used. 1467 + * 1468 + * Possible usage: 1469 + * 1470 + * struct pci_bus *bus = ...; 1471 + * struct resource *res; 1472 + * unsigned int i; 1473 + * 1474 + * // With optional index 1475 + * pci_bus_for_each_resource(bus, res, i) 1476 + * pr_info("PCI bus resource[%u]: %pR\n", i, res); 1477 + * 1478 + * // Without index 1479 + * pci_bus_for_each_resource(bus, res) 1480 + * _do_something_(res); 1481 + */ 1482 + #define pci_bus_for_each_resource(bus, res, ...) \ 1483 + CONCATENATE(__pci_bus_for_each_res, COUNT_ARGS(__VA_ARGS__)) \ 1484 + (bus, res, __VA_ARGS__) 1451 1485 1452 1486 int __must_check pci_bus_alloc_resource(struct pci_bus *bus, 1453 1487 struct resource *res, resource_size_t size, ··· 2028 1994 * These helpers provide future and backwards compatibility 2029 1995 * for accessing popular PCI BAR info 2030 1996 */ 2031 - #define pci_resource_start(dev, bar) ((dev)->resource[(bar)].start) 2032 - #define pci_resource_end(dev, bar) ((dev)->resource[(bar)].end) 2033 - #define pci_resource_flags(dev, bar) ((dev)->resource[(bar)].flags) 2034 - #define pci_resource_len(dev,bar) \ 2035 - ((pci_resource_end((dev), (bar)) == 0) ? 0 : \ 2036 - \ 2037 - (pci_resource_end((dev), (bar)) - \ 2038 - pci_resource_start((dev), (bar)) + 1)) 1997 + #define pci_resource_n(dev, bar) (&(dev)->resource[(bar)]) 1998 + #define pci_resource_start(dev, bar) (pci_resource_n(dev, bar)->start) 1999 + #define pci_resource_end(dev, bar) (pci_resource_n(dev, bar)->end) 2000 + #define pci_resource_flags(dev, bar) (pci_resource_n(dev, bar)->flags) 2001 + #define pci_resource_len(dev,bar) \ 2002 + (pci_resource_end((dev), (bar)) ? \ 2003 + resource_size(pci_resource_n((dev), (bar))) : 0) 2004 + 2005 + #define __pci_dev_for_each_res0(dev, res, ...) \ 2006 + for (unsigned int __b = 0; \ 2007 + res = pci_resource_n(dev, __b), __b < PCI_NUM_RESOURCES; \ 2008 + __b++) 2009 + 2010 + #define __pci_dev_for_each_res1(dev, res, __b) \ 2011 + for (__b = 0; \ 2012 + res = pci_resource_n(dev, __b), __b < PCI_NUM_RESOURCES; \ 2013 + __b++) 2014 + 2015 + #define pci_dev_for_each_resource(dev, res, ...) \ 2016 + CONCATENATE(__pci_dev_for_each_res, COUNT_ARGS(__VA_ARGS__)) \ 2017 + (dev, res, __VA_ARGS__) 2039 2018 2040 2019 /* 2041 2020 * Similar to the helpers above, these manipulate per-pci_dev