Commit 89a74ecc authored by Bjorn Helgaas's avatar Bjorn Helgaas Committed by Jesse Barnes

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: default avatarBjorn Helgaas <bjorn.helgaas@hp.com>
Signed-off-by: default avatarJesse Barnes <jbarnes@virtuousgeek.org>
parent 2adf7516
...@@ -452,13 +452,12 @@ EXPORT_SYMBOL(pcibios_bus_to_resource); ...@@ -452,13 +452,12 @@ EXPORT_SYMBOL(pcibios_bus_to_resource);
static int __devinit is_valid_resource(struct pci_dev *dev, int idx) static int __devinit is_valid_resource(struct pci_dev *dev, int idx)
{ {
unsigned int i, type_mask = IORESOURCE_IO | IORESOURCE_MEM; 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) if (!dev->bus)
return 0; 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)) if (!busr || ((busr->flags ^ devr->flags) & type_mask))
continue; continue;
if ((devr->start) && (devr->start >= busr->start) && if ((devr->start) && (devr->start >= busr->start) &&
......
...@@ -331,12 +331,10 @@ static int __init pci_check_direct(void) ...@@ -331,12 +331,10 @@ static int __init pci_check_direct(void)
static int __devinit is_valid_resource(struct pci_dev *dev, int idx) static int __devinit is_valid_resource(struct pci_dev *dev, int idx)
{ {
unsigned int i, type_mask = IORESOURCE_IO | IORESOURCE_MEM; 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) { if (dev->bus) {
for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) { pci_bus_for_each_resource(dev->bus, busr, i) {
struct resource *busr = dev->bus->resource[i];
if (!busr || (busr->flags ^ devr->flags) & type_mask) if (!busr || (busr->flags ^ devr->flags) & type_mask)
continue; continue;
......
...@@ -1047,10 +1047,8 @@ static void __devinit pcibios_fixup_bridge(struct pci_bus *bus) ...@@ -1047,10 +1047,8 @@ static void __devinit pcibios_fixup_bridge(struct pci_bus *bus)
struct pci_dev *dev = bus->self; struct pci_dev *dev = bus->self;
for (i = 0; i < PCI_BUS_NUM_RESOURCES; ++i) { pci_bus_for_each_resource(bus, res, i) {
if ((res = bus->resource[i]) == NULL) if (!res || !res->flags)
continue;
if (!res->flags)
continue; continue;
if (i >= 3 && bus->self->transparent) if (i >= 3 && bus->self->transparent)
continue; continue;
...@@ -1277,9 +1275,8 @@ void pcibios_allocate_bus_resources(struct pci_bus *bus) ...@@ -1277,9 +1275,8 @@ void pcibios_allocate_bus_resources(struct pci_bus *bus)
pr_debug("PCI: Allocating bus resources for %04x:%02x...\n", pr_debug("PCI: Allocating bus resources for %04x:%02x...\n",
pci_domain_nr(bus), bus->number); pci_domain_nr(bus), bus->number);
for (i = 0; i < PCI_BUS_NUM_RESOURCES; ++i) { pci_bus_for_each_resource(bus, res, i) {
if ((res = bus->resource[i]) == NULL || !res->flags if (!res || !res->flags || res->start > res->end || res->parent)
|| res->start > res->end || res->parent)
continue; continue;
if (bus->parent == NULL) if (bus->parent == NULL)
pr = (res->flags & IORESOURCE_IO) ? pr = (res->flags & IORESOURCE_IO) ?
......
...@@ -222,6 +222,7 @@ static void __devinit quirk_final_uli5249(struct pci_dev *dev) ...@@ -222,6 +222,7 @@ static void __devinit quirk_final_uli5249(struct pci_dev *dev)
int i; int i;
u8 *dummy; u8 *dummy;
struct pci_bus *bus = dev->bus; struct pci_bus *bus = dev->bus;
struct resource *res;
resource_size_t end = 0; resource_size_t end = 0;
for (i = PCI_BRIDGE_RESOURCES; i < PCI_BRIDGE_RESOURCES+3; i++) { 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,13 +231,12 @@ static void __devinit quirk_final_uli5249(struct pci_dev *dev)
end = pci_resource_end(dev, i); end = pci_resource_end(dev, i);
} }
for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) { pci_bus_for_each_resource(bus, res, i) {
if ((bus->resource[i]) && if (res && res->flags & IORESOURCE_MEM) {
(bus->resource[i]->flags & IORESOURCE_MEM)) { if (res->end == end)
if (bus->resource[i]->end == end) dummy = ioremap(res->start, 0x4);
dummy = ioremap(bus->resource[i]->start, 0x4);
else else
dummy = ioremap(bus->resource[i]->end - 3, 0x4); dummy = ioremap(res->end - 3, 0x4);
if (dummy) { if (dummy) {
in_8(dummy); in_8(dummy);
iounmap(dummy); iounmap(dummy);
......
...@@ -43,6 +43,7 @@ pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res, ...@@ -43,6 +43,7 @@ pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
void *alignf_data) void *alignf_data)
{ {
int i, ret = -ENOMEM; int i, ret = -ENOMEM;
struct resource *r;
resource_size_t max = -1; resource_size_t max = -1;
type_mask |= IORESOURCE_IO | IORESOURCE_MEM; type_mask |= IORESOURCE_IO | IORESOURCE_MEM;
...@@ -51,8 +52,7 @@ pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res, ...@@ -51,8 +52,7 @@ pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
if (!(res->flags & IORESOURCE_MEM_64)) if (!(res->flags & IORESOURCE_MEM_64))
max = PCIBIOS_MAX_MEM_32; max = PCIBIOS_MAX_MEM_32;
for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) { pci_bus_for_each_resource(bus, r, i) {
struct resource *r = bus->resource[i];
if (!r) if (!r)
continue; continue;
......
...@@ -47,8 +47,7 @@ static ssize_t show_ctrl (struct device *dev, struct device_attribute *attr, cha ...@@ -47,8 +47,7 @@ static ssize_t show_ctrl (struct device *dev, struct device_attribute *attr, cha
bus = pdev->subordinate; bus = pdev->subordinate;
out += sprintf(buf, "Free resources: memory\n"); out += sprintf(buf, "Free resources: memory\n");
for (index = 0; index < PCI_BUS_NUM_RESOURCES; index++) { pci_bus_for_each_resource(bus, res, index) {
res = bus->resource[index];
if (res && (res->flags & IORESOURCE_MEM) && if (res && (res->flags & IORESOURCE_MEM) &&
!(res->flags & IORESOURCE_PREFETCH)) { !(res->flags & IORESOURCE_PREFETCH)) {
out += sprintf(out, "start = %8.8llx, " out += sprintf(out, "start = %8.8llx, "
...@@ -58,8 +57,7 @@ static ssize_t show_ctrl (struct device *dev, struct device_attribute *attr, cha ...@@ -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"); out += sprintf(out, "Free resources: prefetchable memory\n");
for (index = 0; index < PCI_BUS_NUM_RESOURCES; index++) { pci_bus_for_each_resource(bus, res, index) {
res = bus->resource[index];
if (res && (res->flags & IORESOURCE_MEM) && if (res && (res->flags & IORESOURCE_MEM) &&
(res->flags & IORESOURCE_PREFETCH)) { (res->flags & IORESOURCE_PREFETCH)) {
out += sprintf(out, "start = %8.8llx, " out += sprintf(out, "start = %8.8llx, "
...@@ -69,8 +67,7 @@ static ssize_t show_ctrl (struct device *dev, struct device_attribute *attr, cha ...@@ -69,8 +67,7 @@ static ssize_t show_ctrl (struct device *dev, struct device_attribute *attr, cha
} }
} }
out += sprintf(out, "Free resources: IO\n"); out += sprintf(out, "Free resources: IO\n");
for (index = 0; index < PCI_BUS_NUM_RESOURCES; index++) { pci_bus_for_each_resource(bus, res, index) {
res = bus->resource[index];
if (res && (res->flags & IORESOURCE_IO)) { if (res && (res->flags & IORESOURCE_IO)) {
out += sprintf(out, "start = %8.8llx, " out += sprintf(out, "start = %8.8llx, "
"length = %8.8llx\n", "length = %8.8llx\n",
......
...@@ -386,10 +386,9 @@ pci_find_parent_resource(const struct pci_dev *dev, struct resource *res) ...@@ -386,10 +386,9 @@ pci_find_parent_resource(const struct pci_dev *dev, struct resource *res)
{ {
const struct pci_bus *bus = dev->bus; const struct pci_bus *bus = dev->bus;
int i; int i;
struct resource *best = NULL; struct resource *best = NULL, *r;
for(i = 0; i < PCI_BUS_NUM_RESOURCES; i++) { pci_bus_for_each_resource(bus, r, i) {
struct resource *r = bus->resource[i];
if (!r) if (!r)
continue; continue;
if (res->start && !(res->start >= r->start && res->end <= r->end)) if (res->start && !(res->start >= r->start && res->end <= r->end))
......
...@@ -387,8 +387,7 @@ static struct resource *find_free_bus_resource(struct pci_bus *bus, unsigned lon ...@@ -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 | unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM |
IORESOURCE_PREFETCH; IORESOURCE_PREFETCH;
for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) { pci_bus_for_each_resource(bus, r, i) {
r = bus->resource[i];
if (r == &ioport_resource || r == &iomem_resource) if (r == &ioport_resource || r == &iomem_resource)
continue; continue;
if (r && (r->flags & type_mask) == type && !r->parent) 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,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) static void pci_bus_dump_res(struct pci_bus *bus)
{ {
int i; struct resource *res;
int i;
for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) {
struct resource *res = bus->resource[i];
pci_bus_for_each_resource(bus, res, i) {
if (!res || !res->end || !res->flags) if (!res || !res->end || !res->flags)
continue; continue;
......
...@@ -803,8 +803,7 @@ static int nonstatic_autoadd_resources(struct pcmcia_socket *s) ...@@ -803,8 +803,7 @@ static int nonstatic_autoadd_resources(struct pcmcia_socket *s)
return -EINVAL; return -EINVAL;
#endif #endif
for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) { pci_bus_for_each_resource(s->cb_dev->bus, res, i) {
res = s->cb_dev->bus->resource[i];
if (!res) if (!res)
continue; continue;
......
...@@ -649,9 +649,10 @@ static int yenta_search_one_res(struct resource *root, struct resource *res, ...@@ -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, static int yenta_search_res(struct yenta_socket *socket, struct resource *res,
u32 min) u32 min)
{ {
struct resource *root;
int i; 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) if (!root)
continue; continue;
......
...@@ -829,6 +829,9 @@ int pci_request_selected_regions_exclusive(struct pci_dev *, int, const char *); ...@@ -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); void pci_release_selected_regions(struct pci_dev *, int);
/* drivers/pci/bus.c */ /* 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, int __must_check pci_bus_alloc_resource(struct pci_bus *bus,
struct resource *res, resource_size_t size, struct resource *res, resource_size_t size,
resource_size_t align, resource_size_t min, resource_size_t align, resource_size_t min,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment