]> rtime.felk.cvut.cz Git - linux-imx.git/commitdiff
PCI: add pci_bus_for_each_resource(), remove direct bus->resource[] refs
authorBjorn Helgaas <bjorn.helgaas@hp.com>
Tue, 23 Feb 2010 17:24:31 +0000 (10:24 -0700)
committerJesse Barnes <jbarnes@virtuousgeek.org>
Tue, 23 Feb 2010 17:43:31 +0000 (09:43 -0800)
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>
arch/ia64/pci/pci.c
arch/mn10300/unit-asb2305/pci.c
arch/powerpc/kernel/pci-common.c
arch/powerpc/platforms/fsl_uli1575.c
drivers/pci/bus.c
drivers/pci/hotplug/shpchp_sysfs.c
drivers/pci/pci.c
drivers/pci/setup-bus.c
drivers/pcmcia/rsrc_nonstatic.c
drivers/pcmcia/yenta_socket.c
include/linux/pci.h

index 783c83bb2b49b46d9ce1d763d98a91b8e36eb68b..89f957ca3eb2ece2b31d466740e05f7589f5afeb 100644 (file)
@@ -452,13 +452,12 @@ EXPORT_SYMBOL(pcibios_bus_to_resource);
 static int __devinit is_valid_resource(struct pci_dev *dev, int idx)
 {
        unsigned int i, type_mask = IORESOURCE_IO | IORESOURCE_MEM;
-       struct resource *devr = &dev->resource[idx];
+       struct resource *devr = &dev->resource[idx], *busr;
 
        if (!dev->bus)
                return 0;
-       for (i=0; i<PCI_BUS_NUM_RESOURCES; i++) {
-               struct resource *busr = dev->bus->resource[i];
 
+       pci_bus_for_each_resource(dev->bus, busr, i) {
                if (!busr || ((busr->flags ^ devr->flags) & type_mask))
                        continue;
                if ((devr->start) && (devr->start >= busr->start) &&
index 2cb7e75ba1c0164bf34a0174adc67b136a847e08..6d8720a0a59945bfa4b3c60d70c4d2ceb48c8a12 100644 (file)
@@ -331,12 +331,10 @@ static int __init pci_check_direct(void)
 static int __devinit is_valid_resource(struct pci_dev *dev, int idx)
 {
        unsigned int i, type_mask = IORESOURCE_IO | IORESOURCE_MEM;
-       struct resource *devr = &dev->resource[idx];
+       struct resource *devr = &dev->resource[idx], *busr;
 
        if (dev->bus) {
-               for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) {
-                       struct resource *busr = dev->bus->resource[i];
-
+               pci_bus_for_each_resource(dev->bus, busr, i) {
                        if (!busr || (busr->flags ^ devr->flags) & type_mask)
                                continue;
 
index e640810e813f33c32475e7e62b789d31bceeddea..2597f9545d8ae61522a9d18226c807831c752955 100644 (file)
@@ -1047,10 +1047,8 @@ static void __devinit pcibios_fixup_bridge(struct pci_bus *bus)
 
        struct pci_dev *dev = bus->self;
 
-       for (i = 0; i < PCI_BUS_NUM_RESOURCES; ++i) {
-               if ((res = bus->resource[i]) == NULL)
-                       continue;
-               if (!res->flags)
+       pci_bus_for_each_resource(bus, res, i) {
+               if (!res || !res->flags)
                        continue;
                if (i >= 3 && bus->self->transparent)
                        continue;
@@ -1277,9 +1275,8 @@ void pcibios_allocate_bus_resources(struct pci_bus *bus)
        pr_debug("PCI: Allocating bus resources for %04x:%02x...\n",
                 pci_domain_nr(bus), bus->number);
 
-       for (i = 0; i < PCI_BUS_NUM_RESOURCES; ++i) {
-               if ((res = bus->resource[i]) == NULL || !res->flags
-                   || res->start > res->end || res->parent)
+       pci_bus_for_each_resource(bus, res, i) {
+               if (!res || !res->flags || res->start > res->end || res->parent)
                        continue;
                if (bus->parent == NULL)
                        pr = (res->flags & IORESOURCE_IO) ?
index fd23a1d4b39d28458bca7cc3322085e3975b0314..8b0c2082a78305967c2f05089add88a2a6d3965b 100644 (file)
@@ -222,6 +222,7 @@ static void __devinit quirk_final_uli5249(struct pci_dev *dev)
        int i;
        u8 *dummy;
        struct pci_bus *bus = dev->bus;
+       struct resource *res;
        resource_size_t end = 0;
 
        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)
                        end = pci_resource_end(dev, i);
        }
 
-       for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) {
-               if ((bus->resource[i]) &&
-                       (bus->resource[i]->flags & IORESOURCE_MEM)) {
-                       if (bus->resource[i]->end == end)
-                               dummy = ioremap(bus->resource[i]->start, 0x4);
+       pci_bus_for_each_resource(bus, res, i) {
+               if (res && res->flags & IORESOURCE_MEM) {
+                       if (res->end == end)
+                               dummy = ioremap(res->start, 0x4);
                        else
-                               dummy = ioremap(bus->resource[i]->end - 3, 0x4);
+                               dummy = ioremap(res->end - 3, 0x4);
                        if (dummy) {
                                in_8(dummy);
                                iounmap(dummy);
index a26135bb0ffd050929d52e33302b522398f24244..e75d219fd107a4c727ce1219d28559fc300e53c0 100644 (file)
@@ -43,6 +43,7 @@ pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
                void *alignf_data)
 {
        int i, ret = -ENOMEM;
+       struct resource *r;
        resource_size_t max = -1;
 
        type_mask |= IORESOURCE_IO | IORESOURCE_MEM;
@@ -51,8 +52,7 @@ pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
        if (!(res->flags & IORESOURCE_MEM_64))
                max = PCIBIOS_MAX_MEM_32;
 
-       for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) {
-               struct resource *r = bus->resource[i];
+       pci_bus_for_each_resource(bus, r, i) {
                if (!r)
                        continue;
 
index 29fa9d26adae28b0e49e0a39e16796439f1c4b4f..071b7dc0094b5eeab56f32ef2c2a13d357334a27 100644 (file)
@@ -47,8 +47,7 @@ static ssize_t show_ctrl (struct device *dev, struct device_attribute *attr, cha
        bus = pdev->subordinate;
 
        out += sprintf(buf, "Free resources: memory\n");
-       for (index = 0; index < PCI_BUS_NUM_RESOURCES; index++) {
-               res = bus->resource[index];
+       pci_bus_for_each_resource(bus, res, index) {
                if (res && (res->flags & IORESOURCE_MEM) &&
                                !(res->flags & IORESOURCE_PREFETCH)) {
                        out += sprintf(out, "start = %8.8llx, "
@@ -58,8 +57,7 @@ static ssize_t show_ctrl (struct device *dev, struct device_attribute *attr, cha
                }
        }
        out += sprintf(out, "Free resources: prefetchable memory\n");
-       for (index = 0; index < PCI_BUS_NUM_RESOURCES; index++) {
-               res = bus->resource[index];
+       pci_bus_for_each_resource(bus, res, index) {
                if (res && (res->flags & IORESOURCE_MEM) &&
                               (res->flags & IORESOURCE_PREFETCH)) {
                        out += sprintf(out, "start = %8.8llx, "
@@ -69,8 +67,7 @@ static ssize_t show_ctrl (struct device *dev, struct device_attribute *attr, cha
                }
        }
        out += sprintf(out, "Free resources: IO\n");
-       for (index = 0; index < PCI_BUS_NUM_RESOURCES; index++) {
-               res = bus->resource[index];
+       pci_bus_for_each_resource(bus, res, index) {
                if (res && (res->flags & IORESOURCE_IO)) {
                        out += sprintf(out, "start = %8.8llx, "
                                        "length = %8.8llx\n",
index d62a5de81672637002bfeb79a30e7ee73a39db96..f4a2738bf0bf740ed96dd54b9efce8eea2c19a74 100644 (file)
@@ -386,10 +386,9 @@ pci_find_parent_resource(const struct pci_dev *dev, struct resource *res)
 {
        const struct pci_bus *bus = dev->bus;
        int i;
-       struct resource *best = NULL;
+       struct resource *best = NULL, *r;
 
-       for(i = 0; i < PCI_BUS_NUM_RESOURCES; i++) {
-               struct resource *r = bus->resource[i];
+       pci_bus_for_each_resource(bus, r, i) {
                if (!r)
                        continue;
                if (res->start && !(res->start >= r->start && res->end <= r->end))
index 743ed8c48b9c674105b08a321d7089beb77a1e57..bf32f07c4efb7a68504c5348eb9b908281665894 100644 (file)
@@ -387,8 +387,7 @@ static struct resource *find_free_bus_resource(struct pci_bus *bus, unsigned lon
        unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM |
                                  IORESOURCE_PREFETCH;
 
-       for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) {
-               r = bus->resource[i];
+       pci_bus_for_each_resource(bus, r, i) {
                if (r == &ioport_resource || r == &iomem_resource)
                        continue;
                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,
 
 static void pci_bus_dump_res(struct pci_bus *bus)
 {
-        int i;
-
-        for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) {
-                struct resource *res = bus->resource[i];
+       struct resource *res;
+       int i;
 
+       pci_bus_for_each_resource(bus, res, i) {
                if (!res || !res->end || !res->flags)
                         continue;
 
index 45d75dc452f0e395e5f59a7de5c95d1676fd7550..c67638fe69146b05656187f94a41f76a06de32ad 100644 (file)
@@ -803,8 +803,7 @@ static int nonstatic_autoadd_resources(struct pcmcia_socket *s)
                return -EINVAL;
 #endif
 
-       for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) {
-               res = s->cb_dev->bus->resource[i];
+       pci_bus_for_each_resource(s->cb_dev->bus, res, i) {
                if (!res)
                        continue;
 
index e4d12acdd525d2a5acb1337f52d2c3a2fc441c9e..1f2039d5e9661069bcd12e885551d921db66881c 100644 (file)
@@ -649,9 +649,10 @@ static int yenta_search_one_res(struct resource *root, struct resource *res,
 static int yenta_search_res(struct yenta_socket *socket, struct resource *res,
                            u32 min)
 {
+       struct resource *root;
        int i;
-       for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) {
-               struct resource *root = socket->dev->bus->resource[i];
+
+       pci_bus_for_each_resource(socket->dev->bus, root, i) {
                if (!root)
                        continue;
 
index 1a29f9f6b2dcb9b4aecdf1ef907c83705a3f3c65..2ff9d26a078f47cf068b72aae45affe1acc62c9a 100644 (file)
@@ -829,6 +829,9 @@ int pci_request_selected_regions_exclusive(struct pci_dev *, int, const char *);
 void pci_release_selected_regions(struct pci_dev *, int);
 
 /* drivers/pci/bus.c */
+#define pci_bus_for_each_resource(bus, res, i)                         \
+       for (i = 0; res = bus->resource[i], i < PCI_BUS_NUM_RESOURCES; i++)
+
 int __must_check pci_bus_alloc_resource(struct pci_bus *bus,
                        struct resource *res, resource_size_t size,
                        resource_size_t align, resource_size_t min,