aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci
diff options
context:
space:
mode:
authorYinghai Lu <yinghai@kernel.org>2013-12-10 01:54:40 -0500
committerBjorn Helgaas <bhelgaas@google.com>2013-12-21 12:06:10 -0500
commitfc2798502f860b18f3c7121e4dc659d3d9d28d74 (patch)
treed15d6addb41d305e33c6f6d8e363b7272dc29a38 /drivers/pci
parent0a5ef7b914be91dd257ae4f35223dd822dd3703a (diff)
PCI: Convert pcibios_resource_to_bus() to take a pci_bus, not a pci_dev
These interfaces: pcibios_resource_to_bus(struct pci_dev *dev, *bus_region, *resource) pcibios_bus_to_resource(struct pci_dev *dev, *resource, *bus_region) took a pci_dev, but they really depend only on the pci_bus. And we want to use them in resource allocation paths where we have the bus but not a device, so this patch converts them to take the pci_bus instead of the pci_dev: pcibios_resource_to_bus(struct pci_bus *bus, *bus_region, *resource) pcibios_bus_to_resource(struct pci_bus *bus, *resource, *bus_region) In fact, with standard PCI-PCI bridges, they only depend on the host bridge, because that's the only place address translation occurs, but we aren't going that far yet. [bhelgaas: changelog] Signed-off-by: Yinghai Lu <yinghai@kernel.org> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Diffstat (limited to 'drivers/pci')
-rw-r--r--drivers/pci/host-bridge.c19
-rw-r--r--drivers/pci/probe.c18
-rw-r--r--drivers/pci/quirks.c2
-rw-r--r--drivers/pci/rom.c2
-rw-r--r--drivers/pci/setup-bus.c16
-rw-r--r--drivers/pci/setup-res.c2
6 files changed, 28 insertions, 31 deletions
diff --git a/drivers/pci/host-bridge.c b/drivers/pci/host-bridge.c
index a68dc613a5be..06ace6248c61 100644
--- a/drivers/pci/host-bridge.c
+++ b/drivers/pci/host-bridge.c
@@ -9,22 +9,19 @@
9 9
10#include "pci.h" 10#include "pci.h"
11 11
12static struct pci_bus *find_pci_root_bus(struct pci_dev *dev) 12static struct pci_bus *find_pci_root_bus(struct pci_bus *bus)
13{ 13{
14 struct pci_bus *bus;
15
16 bus = dev->bus;
17 while (bus->parent) 14 while (bus->parent)
18 bus = bus->parent; 15 bus = bus->parent;
19 16
20 return bus; 17 return bus;
21} 18}
22 19
23static struct pci_host_bridge *find_pci_host_bridge(struct pci_dev *dev) 20static struct pci_host_bridge *find_pci_host_bridge(struct pci_bus *bus)
24{ 21{
25 struct pci_bus *bus = find_pci_root_bus(dev); 22 struct pci_bus *root_bus = find_pci_root_bus(bus);
26 23
27 return to_pci_host_bridge(bus->bridge); 24 return to_pci_host_bridge(root_bus->bridge);
28} 25}
29 26
30void pci_set_host_bridge_release(struct pci_host_bridge *bridge, 27void pci_set_host_bridge_release(struct pci_host_bridge *bridge,
@@ -40,10 +37,10 @@ static bool resource_contains(struct resource *res1, struct resource *res2)
40 return res1->start <= res2->start && res1->end >= res2->end; 37 return res1->start <= res2->start && res1->end >= res2->end;
41} 38}
42 39
43void pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region, 40void pcibios_resource_to_bus(struct pci_bus *bus, struct pci_bus_region *region,
44 struct resource *res) 41 struct resource *res)
45{ 42{
46 struct pci_host_bridge *bridge = find_pci_host_bridge(dev); 43 struct pci_host_bridge *bridge = find_pci_host_bridge(bus);
47 struct pci_host_bridge_window *window; 44 struct pci_host_bridge_window *window;
48 resource_size_t offset = 0; 45 resource_size_t offset = 0;
49 46
@@ -68,10 +65,10 @@ static bool region_contains(struct pci_bus_region *region1,
68 return region1->start <= region2->start && region1->end >= region2->end; 65 return region1->start <= region2->start && region1->end >= region2->end;
69} 66}
70 67
71void pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res, 68void pcibios_bus_to_resource(struct pci_bus *bus, struct resource *res,
72 struct pci_bus_region *region) 69 struct pci_bus_region *region)
73{ 70{
74 struct pci_host_bridge *bridge = find_pci_host_bridge(dev); 71 struct pci_host_bridge *bridge = find_pci_host_bridge(bus);
75 struct pci_host_bridge_window *window; 72 struct pci_host_bridge_window *window;
76 resource_size_t offset = 0; 73 resource_size_t offset = 0;
77 74
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 38e403dddf6e..f049e3f53fcc 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -269,8 +269,8 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
269 region.end = l + sz; 269 region.end = l + sz;
270 } 270 }
271 271
272 pcibios_bus_to_resource(dev, res, &region); 272 pcibios_bus_to_resource(dev->bus, res, &region);
273 pcibios_resource_to_bus(dev, &inverted_region, res); 273 pcibios_resource_to_bus(dev->bus, &inverted_region, res);
274 274
275 /* 275 /*
276 * If "A" is a BAR value (a bus address), "bus_to_resource(A)" is 276 * If "A" is a BAR value (a bus address), "bus_to_resource(A)" is
@@ -364,7 +364,7 @@ static void pci_read_bridge_io(struct pci_bus *child)
364 res->flags = (io_base_lo & PCI_IO_RANGE_TYPE_MASK) | IORESOURCE_IO; 364 res->flags = (io_base_lo & PCI_IO_RANGE_TYPE_MASK) | IORESOURCE_IO;
365 region.start = base; 365 region.start = base;
366 region.end = limit + io_granularity - 1; 366 region.end = limit + io_granularity - 1;
367 pcibios_bus_to_resource(dev, res, &region); 367 pcibios_bus_to_resource(dev->bus, res, &region);
368 dev_printk(KERN_DEBUG, &dev->dev, " bridge window %pR\n", res); 368 dev_printk(KERN_DEBUG, &dev->dev, " bridge window %pR\n", res);
369 } 369 }
370} 370}
@@ -386,7 +386,7 @@ static void pci_read_bridge_mmio(struct pci_bus *child)
386 res->flags = (mem_base_lo & PCI_MEMORY_RANGE_TYPE_MASK) | IORESOURCE_MEM; 386 res->flags = (mem_base_lo & PCI_MEMORY_RANGE_TYPE_MASK) | IORESOURCE_MEM;
387 region.start = base; 387 region.start = base;
388 region.end = limit + 0xfffff; 388 region.end = limit + 0xfffff;
389 pcibios_bus_to_resource(dev, res, &region); 389 pcibios_bus_to_resource(dev->bus, res, &region);
390 dev_printk(KERN_DEBUG, &dev->dev, " bridge window %pR\n", res); 390 dev_printk(KERN_DEBUG, &dev->dev, " bridge window %pR\n", res);
391 } 391 }
392} 392}
@@ -436,7 +436,7 @@ static void pci_read_bridge_mmio_pref(struct pci_bus *child)
436 res->flags |= IORESOURCE_MEM_64; 436 res->flags |= IORESOURCE_MEM_64;
437 region.start = base; 437 region.start = base;
438 region.end = limit + 0xfffff; 438 region.end = limit + 0xfffff;
439 pcibios_bus_to_resource(dev, res, &region); 439 pcibios_bus_to_resource(dev->bus, res, &region);
440 dev_printk(KERN_DEBUG, &dev->dev, " bridge window %pR\n", res); 440 dev_printk(KERN_DEBUG, &dev->dev, " bridge window %pR\n", res);
441 } 441 }
442} 442}
@@ -1084,24 +1084,24 @@ int pci_setup_device(struct pci_dev *dev)
1084 region.end = 0x1F7; 1084 region.end = 0x1F7;
1085 res = &dev->resource[0]; 1085 res = &dev->resource[0];
1086 res->flags = LEGACY_IO_RESOURCE; 1086 res->flags = LEGACY_IO_RESOURCE;
1087 pcibios_bus_to_resource(dev, res, &region); 1087 pcibios_bus_to_resource(dev->bus, res, &region);
1088 region.start = 0x3F6; 1088 region.start = 0x3F6;
1089 region.end = 0x3F6; 1089 region.end = 0x3F6;
1090 res = &dev->resource[1]; 1090 res = &dev->resource[1];
1091 res->flags = LEGACY_IO_RESOURCE; 1091 res->flags = LEGACY_IO_RESOURCE;
1092 pcibios_bus_to_resource(dev, res, &region); 1092 pcibios_bus_to_resource(dev->bus, res, &region);
1093 } 1093 }
1094 if ((progif & 4) == 0) { 1094 if ((progif & 4) == 0) {
1095 region.start = 0x170; 1095 region.start = 0x170;
1096 region.end = 0x177; 1096 region.end = 0x177;
1097 res = &dev->resource[2]; 1097 res = &dev->resource[2];
1098 res->flags = LEGACY_IO_RESOURCE; 1098 res->flags = LEGACY_IO_RESOURCE;
1099 pcibios_bus_to_resource(dev, res, &region); 1099 pcibios_bus_to_resource(dev->bus, res, &region);
1100 region.start = 0x376; 1100 region.start = 0x376;
1101 region.end = 0x376; 1101 region.end = 0x376;
1102 res = &dev->resource[3]; 1102 res = &dev->resource[3];
1103 res->flags = LEGACY_IO_RESOURCE; 1103 res->flags = LEGACY_IO_RESOURCE;
1104 pcibios_bus_to_resource(dev, res, &region); 1104 pcibios_bus_to_resource(dev->bus, res, &region);
1105 } 1105 }
1106 } 1106 }
1107 break; 1107 break;
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index b3b1b9aa8863..4ad6bf6c107b 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -343,7 +343,7 @@ static void quirk_io_region(struct pci_dev *dev, int port,
343 /* Convert from PCI bus to resource space */ 343 /* Convert from PCI bus to resource space */
344 bus_region.start = region; 344 bus_region.start = region;
345 bus_region.end = region + size - 1; 345 bus_region.end = region + size - 1;
346 pcibios_bus_to_resource(dev, res, &bus_region); 346 pcibios_bus_to_resource(dev->bus, res, &bus_region);
347 347
348 if (!pci_claim_resource(dev, nr)) 348 if (!pci_claim_resource(dev, nr))
349 dev_info(&dev->dev, "quirk: %pR claimed by %s\n", res, name); 349 dev_info(&dev->dev, "quirk: %pR claimed by %s\n", res, name);
diff --git a/drivers/pci/rom.c b/drivers/pci/rom.c
index c5d0a08a8747..5d595724e5f4 100644
--- a/drivers/pci/rom.c
+++ b/drivers/pci/rom.c
@@ -31,7 +31,7 @@ int pci_enable_rom(struct pci_dev *pdev)
31 if (!res->flags) 31 if (!res->flags)
32 return -1; 32 return -1;
33 33
34 pcibios_resource_to_bus(pdev, &region, res); 34 pcibios_resource_to_bus(pdev->bus, &region, res);
35 pci_read_config_dword(pdev, pdev->rom_base_reg, &rom_addr); 35 pci_read_config_dword(pdev, pdev->rom_base_reg, &rom_addr);
36 rom_addr &= ~PCI_ROM_ADDRESS_MASK; 36 rom_addr &= ~PCI_ROM_ADDRESS_MASK;
37 rom_addr |= region.start | PCI_ROM_ADDRESS_ENABLE; 37 rom_addr |= region.start | PCI_ROM_ADDRESS_ENABLE;
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 219a4106480a..79339822d80e 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -475,7 +475,7 @@ void pci_setup_cardbus(struct pci_bus *bus)
475 &bus->busn_res); 475 &bus->busn_res);
476 476
477 res = bus->resource[0]; 477 res = bus->resource[0];
478 pcibios_resource_to_bus(bridge, &region, res); 478 pcibios_resource_to_bus(bridge->bus, &region, res);
479 if (res->flags & IORESOURCE_IO) { 479 if (res->flags & IORESOURCE_IO) {
480 /* 480 /*
481 * The IO resource is allocated a range twice as large as it 481 * The IO resource is allocated a range twice as large as it
@@ -489,7 +489,7 @@ void pci_setup_cardbus(struct pci_bus *bus)
489 } 489 }
490 490
491 res = bus->resource[1]; 491 res = bus->resource[1];
492 pcibios_resource_to_bus(bridge, &region, res); 492 pcibios_resource_to_bus(bridge->bus, &region, res);
493 if (res->flags & IORESOURCE_IO) { 493 if (res->flags & IORESOURCE_IO) {
494 dev_info(&bridge->dev, " bridge window %pR\n", res); 494 dev_info(&bridge->dev, " bridge window %pR\n", res);
495 pci_write_config_dword(bridge, PCI_CB_IO_BASE_1, 495 pci_write_config_dword(bridge, PCI_CB_IO_BASE_1,
@@ -499,7 +499,7 @@ void pci_setup_cardbus(struct pci_bus *bus)
499 } 499 }
500 500
501 res = bus->resource[2]; 501 res = bus->resource[2];
502 pcibios_resource_to_bus(bridge, &region, res); 502 pcibios_resource_to_bus(bridge->bus, &region, res);
503 if (res->flags & IORESOURCE_MEM) { 503 if (res->flags & IORESOURCE_MEM) {
504 dev_info(&bridge->dev, " bridge window %pR\n", res); 504 dev_info(&bridge->dev, " bridge window %pR\n", res);
505 pci_write_config_dword(bridge, PCI_CB_MEMORY_BASE_0, 505 pci_write_config_dword(bridge, PCI_CB_MEMORY_BASE_0,
@@ -509,7 +509,7 @@ void pci_setup_cardbus(struct pci_bus *bus)
509 } 509 }
510 510
511 res = bus->resource[3]; 511 res = bus->resource[3];
512 pcibios_resource_to_bus(bridge, &region, res); 512 pcibios_resource_to_bus(bridge->bus, &region, res);
513 if (res->flags & IORESOURCE_MEM) { 513 if (res->flags & IORESOURCE_MEM) {
514 dev_info(&bridge->dev, " bridge window %pR\n", res); 514 dev_info(&bridge->dev, " bridge window %pR\n", res);
515 pci_write_config_dword(bridge, PCI_CB_MEMORY_BASE_1, 515 pci_write_config_dword(bridge, PCI_CB_MEMORY_BASE_1,
@@ -546,7 +546,7 @@ static void pci_setup_bridge_io(struct pci_bus *bus)
546 546
547 /* Set up the top and bottom of the PCI I/O segment for this bus. */ 547 /* Set up the top and bottom of the PCI I/O segment for this bus. */
548 res = bus->resource[0]; 548 res = bus->resource[0];
549 pcibios_resource_to_bus(bridge, &region, res); 549 pcibios_resource_to_bus(bridge->bus, &region, res);
550 if (res->flags & IORESOURCE_IO) { 550 if (res->flags & IORESOURCE_IO) {
551 pci_read_config_dword(bridge, PCI_IO_BASE, &l); 551 pci_read_config_dword(bridge, PCI_IO_BASE, &l);
552 l &= 0xffff0000; 552 l &= 0xffff0000;
@@ -578,7 +578,7 @@ static void pci_setup_bridge_mmio(struct pci_bus *bus)
578 578
579 /* Set up the top and bottom of the PCI Memory segment for this bus. */ 579 /* Set up the top and bottom of the PCI Memory segment for this bus. */
580 res = bus->resource[1]; 580 res = bus->resource[1];
581 pcibios_resource_to_bus(bridge, &region, res); 581 pcibios_resource_to_bus(bridge->bus, &region, res);
582 if (res->flags & IORESOURCE_MEM) { 582 if (res->flags & IORESOURCE_MEM) {
583 l = (region.start >> 16) & 0xfff0; 583 l = (region.start >> 16) & 0xfff0;
584 l |= region.end & 0xfff00000; 584 l |= region.end & 0xfff00000;
@@ -604,7 +604,7 @@ static void pci_setup_bridge_mmio_pref(struct pci_bus *bus)
604 /* Set up PREF base/limit. */ 604 /* Set up PREF base/limit. */
605 bu = lu = 0; 605 bu = lu = 0;
606 res = bus->resource[2]; 606 res = bus->resource[2];
607 pcibios_resource_to_bus(bridge, &region, res); 607 pcibios_resource_to_bus(bridge->bus, &region, res);
608 if (res->flags & IORESOURCE_PREFETCH) { 608 if (res->flags & IORESOURCE_PREFETCH) {
609 l = (region.start >> 16) & 0xfff0; 609 l = (region.start >> 16) & 0xfff0;
610 l |= region.end & 0xfff00000; 610 l |= region.end & 0xfff00000;
@@ -1422,7 +1422,7 @@ static int iov_resources_unassigned(struct pci_dev *dev, void *data)
1422 if (!r->flags) 1422 if (!r->flags)
1423 continue; 1423 continue;
1424 1424
1425 pcibios_resource_to_bus(dev, &region, r); 1425 pcibios_resource_to_bus(dev->bus, &region, r);
1426 if (!region.start) { 1426 if (!region.start) {
1427 *unassigned = true; 1427 *unassigned = true;
1428 return 1; /* return early from pci_walk_bus() */ 1428 return 1; /* return early from pci_walk_bus() */
diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
index 83c4d3bc47ab..5c060b152ce6 100644
--- a/drivers/pci/setup-res.c
+++ b/drivers/pci/setup-res.c
@@ -52,7 +52,7 @@ void pci_update_resource(struct pci_dev *dev, int resno)
52 if (res->flags & IORESOURCE_PCI_FIXED) 52 if (res->flags & IORESOURCE_PCI_FIXED)
53 return; 53 return;
54 54
55 pcibios_resource_to_bus(dev, &region, res); 55 pcibios_resource_to_bus(dev->bus, &region, res);
56 56
57 new = region.start | (res->flags & PCI_REGION_FLAG_MASK); 57 new = region.start | (res->flags & PCI_REGION_FLAG_MASK);
58 if (res->flags & IORESOURCE_IO) 58 if (res->flags & IORESOURCE_IO)