Skip to content

Commit fc27985

Browse files
Yinghai Lubjorn-helgaas
authored andcommitted
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>
1 parent 0a5ef7b commit fc27985

File tree

17 files changed

+49
-51
lines changed

17 files changed

+49
-51
lines changed

arch/alpha/kernel/pci-sysfs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static int pci_mmap_resource(struct kobject *kobj,
8383
if (iomem_is_exclusive(res->start))
8484
return -EINVAL;
8585

86-
pcibios_resource_to_bus(pdev, &bar, res);
86+
pcibios_resource_to_bus(pdev->bus, &bar, res);
8787
vma->vm_pgoff += bar.start >> (PAGE_SHIFT - (sparse ? 5 : 0));
8888
mmap_type = res->flags & IORESOURCE_MEM ? pci_mmap_mem : pci_mmap_io;
8989

@@ -139,7 +139,7 @@ static int sparse_mem_mmap_fits(struct pci_dev *pdev, int num)
139139
long dense_offset;
140140
unsigned long sparse_size;
141141

142-
pcibios_resource_to_bus(pdev, &bar, &pdev->resource[num]);
142+
pcibios_resource_to_bus(pdev->bus, &bar, &pdev->resource[num]);
143143

144144
/* All core logic chips have 4G sparse address space, except
145145
CIA which has 16G (see xxx_SPARSE_MEM and xxx_DENSE_MEM

arch/powerpc/kernel/pci-common.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ static void pcibios_fixup_resources(struct pci_dev *dev)
835835
* at 0 as unset as well, except if PCI_PROBE_ONLY is also set
836836
* since in that case, we don't want to re-assign anything
837837
*/
838-
pcibios_resource_to_bus(dev, &reg, res);
838+
pcibios_resource_to_bus(dev->bus, &reg, res);
839839
if (pci_has_flag(PCI_REASSIGN_ALL_RSRC) ||
840840
(reg.start == 0 && !pci_has_flag(PCI_PROBE_ONLY))) {
841841
/* Only print message if not re-assigning */
@@ -886,7 +886,7 @@ static int pcibios_uninitialized_bridge_resource(struct pci_bus *bus,
886886

887887
/* Job is a bit different between memory and IO */
888888
if (res->flags & IORESOURCE_MEM) {
889-
pcibios_resource_to_bus(dev, &region, res);
889+
pcibios_resource_to_bus(dev->bus, &region, res);
890890

891891
/* If the BAR is non-0 then it's probably been initialized */
892892
if (region.start != 0)

arch/powerpc/kernel/pci_of_scan.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ static void of_pci_parse_addrs(struct device_node *node, struct pci_dev *dev)
111111
res->name = pci_name(dev);
112112
region.start = base;
113113
region.end = base + size - 1;
114-
pcibios_bus_to_resource(dev, res, &region);
114+
pcibios_bus_to_resource(dev->bus, res, &region);
115115
}
116116
}
117117

@@ -280,7 +280,7 @@ void of_scan_pci_bridge(struct pci_dev *dev)
280280
res->flags = flags;
281281
region.start = of_read_number(&ranges[1], 2);
282282
region.end = region.start + size - 1;
283-
pcibios_bus_to_resource(dev, res, &region);
283+
pcibios_bus_to_resource(dev->bus, res, &region);
284284
}
285285
sprintf(bus->name, "PCI Bus %04x:%02x", pci_domain_nr(bus),
286286
bus->number);

arch/sparc/kernel/pci.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,15 +392,15 @@ static void apb_fake_ranges(struct pci_dev *dev,
392392
res->flags = IORESOURCE_IO;
393393
region.start = (first << 21);
394394
region.end = (last << 21) + ((1 << 21) - 1);
395-
pcibios_bus_to_resource(dev, res, &region);
395+
pcibios_bus_to_resource(dev->bus, res, &region);
396396

397397
pci_read_config_byte(dev, APB_MEM_ADDRESS_MAP, &map);
398398
apb_calc_first_last(map, &first, &last);
399399
res = bus->resource[1];
400400
res->flags = IORESOURCE_MEM;
401401
region.start = (first << 29);
402402
region.end = (last << 29) + ((1 << 29) - 1);
403-
pcibios_bus_to_resource(dev, res, &region);
403+
pcibios_bus_to_resource(dev->bus, res, &region);
404404
}
405405

406406
static void pci_of_scan_bus(struct pci_pbm_info *pbm,
@@ -491,7 +491,7 @@ static void of_scan_pci_bridge(struct pci_pbm_info *pbm,
491491
res->flags = flags;
492492
region.start = GET_64BIT(ranges, 1);
493493
region.end = region.start + size - 1;
494-
pcibios_bus_to_resource(dev, res, &region);
494+
pcibios_bus_to_resource(dev->bus, res, &region);
495495
}
496496
after_ranges:
497497
sprintf(bus->name, "PCI Bus %04x:%02x", pci_domain_nr(bus),

drivers/pci/host-bridge.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,19 @@
99

1010
#include "pci.h"
1111

12-
static struct pci_bus *find_pci_root_bus(struct pci_dev *dev)
12+
static struct pci_bus *find_pci_root_bus(struct pci_bus *bus)
1313
{
14-
struct pci_bus *bus;
15-
16-
bus = dev->bus;
1714
while (bus->parent)
1815
bus = bus->parent;
1916

2017
return bus;
2118
}
2219

23-
static struct pci_host_bridge *find_pci_host_bridge(struct pci_dev *dev)
20+
static struct pci_host_bridge *find_pci_host_bridge(struct pci_bus *bus)
2421
{
25-
struct pci_bus *bus = find_pci_root_bus(dev);
22+
struct pci_bus *root_bus = find_pci_root_bus(bus);
2623

27-
return to_pci_host_bridge(bus->bridge);
24+
return to_pci_host_bridge(root_bus->bridge);
2825
}
2926

3027
void pci_set_host_bridge_release(struct pci_host_bridge *bridge,
@@ -40,10 +37,10 @@ static bool resource_contains(struct resource *res1, struct resource *res2)
4037
return res1->start <= res2->start && res1->end >= res2->end;
4138
}
4239

43-
void pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region,
40+
void pcibios_resource_to_bus(struct pci_bus *bus, struct pci_bus_region *region,
4441
struct resource *res)
4542
{
46-
struct pci_host_bridge *bridge = find_pci_host_bridge(dev);
43+
struct pci_host_bridge *bridge = find_pci_host_bridge(bus);
4744
struct pci_host_bridge_window *window;
4845
resource_size_t offset = 0;
4946

@@ -68,10 +65,10 @@ static bool region_contains(struct pci_bus_region *region1,
6865
return region1->start <= region2->start && region1->end >= region2->end;
6966
}
7067

71-
void pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res,
68+
void pcibios_bus_to_resource(struct pci_bus *bus, struct resource *res,
7269
struct pci_bus_region *region)
7370
{
74-
struct pci_host_bridge *bridge = find_pci_host_bridge(dev);
71+
struct pci_host_bridge *bridge = find_pci_host_bridge(bus);
7572
struct pci_host_bridge_window *window;
7673
resource_size_t offset = 0;
7774

drivers/pci/probe.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
269269
region.end = l + sz;
270270
}
271271

272-
pcibios_bus_to_resource(dev, res, &region);
273-
pcibios_resource_to_bus(dev, &inverted_region, res);
272+
pcibios_bus_to_resource(dev->bus, res, &region);
273+
pcibios_resource_to_bus(dev->bus, &inverted_region, res);
274274

275275
/*
276276
* 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)
364364
res->flags = (io_base_lo & PCI_IO_RANGE_TYPE_MASK) | IORESOURCE_IO;
365365
region.start = base;
366366
region.end = limit + io_granularity - 1;
367-
pcibios_bus_to_resource(dev, res, &region);
367+
pcibios_bus_to_resource(dev->bus, res, &region);
368368
dev_printk(KERN_DEBUG, &dev->dev, " bridge window %pR\n", res);
369369
}
370370
}
@@ -386,7 +386,7 @@ static void pci_read_bridge_mmio(struct pci_bus *child)
386386
res->flags = (mem_base_lo & PCI_MEMORY_RANGE_TYPE_MASK) | IORESOURCE_MEM;
387387
region.start = base;
388388
region.end = limit + 0xfffff;
389-
pcibios_bus_to_resource(dev, res, &region);
389+
pcibios_bus_to_resource(dev->bus, res, &region);
390390
dev_printk(KERN_DEBUG, &dev->dev, " bridge window %pR\n", res);
391391
}
392392
}
@@ -436,7 +436,7 @@ static void pci_read_bridge_mmio_pref(struct pci_bus *child)
436436
res->flags |= IORESOURCE_MEM_64;
437437
region.start = base;
438438
region.end = limit + 0xfffff;
439-
pcibios_bus_to_resource(dev, res, &region);
439+
pcibios_bus_to_resource(dev->bus, res, &region);
440440
dev_printk(KERN_DEBUG, &dev->dev, " bridge window %pR\n", res);
441441
}
442442
}
@@ -1084,24 +1084,24 @@ int pci_setup_device(struct pci_dev *dev)
10841084
region.end = 0x1F7;
10851085
res = &dev->resource[0];
10861086
res->flags = LEGACY_IO_RESOURCE;
1087-
pcibios_bus_to_resource(dev, res, &region);
1087+
pcibios_bus_to_resource(dev->bus, res, &region);
10881088
region.start = 0x3F6;
10891089
region.end = 0x3F6;
10901090
res = &dev->resource[1];
10911091
res->flags = LEGACY_IO_RESOURCE;
1092-
pcibios_bus_to_resource(dev, res, &region);
1092+
pcibios_bus_to_resource(dev->bus, res, &region);
10931093
}
10941094
if ((progif & 4) == 0) {
10951095
region.start = 0x170;
10961096
region.end = 0x177;
10971097
res = &dev->resource[2];
10981098
res->flags = LEGACY_IO_RESOURCE;
1099-
pcibios_bus_to_resource(dev, res, &region);
1099+
pcibios_bus_to_resource(dev->bus, res, &region);
11001100
region.start = 0x376;
11011101
region.end = 0x376;
11021102
res = &dev->resource[3];
11031103
res->flags = LEGACY_IO_RESOURCE;
1104-
pcibios_bus_to_resource(dev, res, &region);
1104+
pcibios_bus_to_resource(dev->bus, res, &region);
11051105
}
11061106
}
11071107
break;

drivers/pci/quirks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ static void quirk_io_region(struct pci_dev *dev, int port,
343343
/* Convert from PCI bus to resource space */
344344
bus_region.start = region;
345345
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);
347347

348348
if (!pci_claim_resource(dev, nr))
349349
dev_info(&dev->dev, "quirk: %pR claimed by %s\n", res, name);

drivers/pci/rom.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ int pci_enable_rom(struct pci_dev *pdev)
3131
if (!res->flags)
3232
return -1;
3333

34-
pcibios_resource_to_bus(pdev, &region, res);
34+
pcibios_resource_to_bus(pdev->bus, &region, res);
3535
pci_read_config_dword(pdev, pdev->rom_base_reg, &rom_addr);
3636
rom_addr &= ~PCI_ROM_ADDRESS_MASK;
3737
rom_addr |= region.start | PCI_ROM_ADDRESS_ENABLE;

drivers/pci/setup-bus.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ void pci_setup_cardbus(struct pci_bus *bus)
475475
&bus->busn_res);
476476

477477
res = bus->resource[0];
478-
pcibios_resource_to_bus(bridge, &region, res);
478+
pcibios_resource_to_bus(bridge->bus, &region, res);
479479
if (res->flags & IORESOURCE_IO) {
480480
/*
481481
* The IO resource is allocated a range twice as large as it
@@ -489,7 +489,7 @@ void pci_setup_cardbus(struct pci_bus *bus)
489489
}
490490

491491
res = bus->resource[1];
492-
pcibios_resource_to_bus(bridge, &region, res);
492+
pcibios_resource_to_bus(bridge->bus, &region, res);
493493
if (res->flags & IORESOURCE_IO) {
494494
dev_info(&bridge->dev, " bridge window %pR\n", res);
495495
pci_write_config_dword(bridge, PCI_CB_IO_BASE_1,
@@ -499,7 +499,7 @@ void pci_setup_cardbus(struct pci_bus *bus)
499499
}
500500

501501
res = bus->resource[2];
502-
pcibios_resource_to_bus(bridge, &region, res);
502+
pcibios_resource_to_bus(bridge->bus, &region, res);
503503
if (res->flags & IORESOURCE_MEM) {
504504
dev_info(&bridge->dev, " bridge window %pR\n", res);
505505
pci_write_config_dword(bridge, PCI_CB_MEMORY_BASE_0,
@@ -509,7 +509,7 @@ void pci_setup_cardbus(struct pci_bus *bus)
509509
}
510510

511511
res = bus->resource[3];
512-
pcibios_resource_to_bus(bridge, &region, res);
512+
pcibios_resource_to_bus(bridge->bus, &region, res);
513513
if (res->flags & IORESOURCE_MEM) {
514514
dev_info(&bridge->dev, " bridge window %pR\n", res);
515515
pci_write_config_dword(bridge, PCI_CB_MEMORY_BASE_1,
@@ -546,7 +546,7 @@ static void pci_setup_bridge_io(struct pci_bus *bus)
546546

547547
/* Set up the top and bottom of the PCI I/O segment for this bus. */
548548
res = bus->resource[0];
549-
pcibios_resource_to_bus(bridge, &region, res);
549+
pcibios_resource_to_bus(bridge->bus, &region, res);
550550
if (res->flags & IORESOURCE_IO) {
551551
pci_read_config_dword(bridge, PCI_IO_BASE, &l);
552552
l &= 0xffff0000;
@@ -578,7 +578,7 @@ static void pci_setup_bridge_mmio(struct pci_bus *bus)
578578

579579
/* Set up the top and bottom of the PCI Memory segment for this bus. */
580580
res = bus->resource[1];
581-
pcibios_resource_to_bus(bridge, &region, res);
581+
pcibios_resource_to_bus(bridge->bus, &region, res);
582582
if (res->flags & IORESOURCE_MEM) {
583583
l = (region.start >> 16) & 0xfff0;
584584
l |= region.end & 0xfff00000;
@@ -604,7 +604,7 @@ static void pci_setup_bridge_mmio_pref(struct pci_bus *bus)
604604
/* Set up PREF base/limit. */
605605
bu = lu = 0;
606606
res = bus->resource[2];
607-
pcibios_resource_to_bus(bridge, &region, res);
607+
pcibios_resource_to_bus(bridge->bus, &region, res);
608608
if (res->flags & IORESOURCE_PREFETCH) {
609609
l = (region.start >> 16) & 0xfff0;
610610
l |= region.end & 0xfff00000;
@@ -1422,7 +1422,7 @@ static int iov_resources_unassigned(struct pci_dev *dev, void *data)
14221422
if (!r->flags)
14231423
continue;
14241424

1425-
pcibios_resource_to_bus(dev, &region, r);
1425+
pcibios_resource_to_bus(dev->bus, &region, r);
14261426
if (!region.start) {
14271427
*unassigned = true;
14281428
return 1; /* return early from pci_walk_bus() */

drivers/pci/setup-res.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void pci_update_resource(struct pci_dev *dev, int resno)
5252
if (res->flags & IORESOURCE_PCI_FIXED)
5353
return;
5454

55-
pcibios_resource_to_bus(dev, &region, res);
55+
pcibios_resource_to_bus(dev->bus, &region, res);
5656

5757
new = region.start | (res->flags & PCI_REGION_FLAG_MASK);
5858
if (res->flags & IORESOURCE_IO)

drivers/pcmcia/i82092.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ static int i82092aa_set_mem_map(struct pcmcia_socket *socket, struct pccard_mem_
608608

609609
enter("i82092aa_set_mem_map");
610610

611-
pcibios_resource_to_bus(sock_info->dev, &region, mem->res);
611+
pcibios_resource_to_bus(sock_info->dev->bus, &region, mem->res);
612612

613613
map = mem->map;
614614
if (map > 4) {

drivers/pcmcia/yenta_socket.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ static int yenta_set_mem_map(struct pcmcia_socket *sock, struct pccard_mem_map *
445445
unsigned int start, stop, card_start;
446446
unsigned short word;
447447

448-
pcibios_resource_to_bus(socket->dev, &region, mem->res);
448+
pcibios_resource_to_bus(socket->dev->bus, &region, mem->res);
449449

450450
map = mem->map;
451451
start = region.start;
@@ -709,7 +709,7 @@ static int yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned type
709709
region.start = config_readl(socket, addr_start) & mask;
710710
region.end = config_readl(socket, addr_end) | ~mask;
711711
if (region.start && region.end > region.start && !override_bios) {
712-
pcibios_bus_to_resource(dev, res, &region);
712+
pcibios_bus_to_resource(dev->bus, res, &region);
713713
if (pci_claim_resource(dev, PCI_BRIDGE_RESOURCES + nr) == 0)
714714
return 0;
715715
dev_printk(KERN_INFO, &dev->dev,
@@ -1033,7 +1033,7 @@ static void yenta_config_init(struct yenta_socket *socket)
10331033
struct pci_dev *dev = socket->dev;
10341034
struct pci_bus_region region;
10351035

1036-
pcibios_resource_to_bus(socket->dev, &region, &dev->resource[0]);
1036+
pcibios_resource_to_bus(socket->dev->bus, &region, &dev->resource[0]);
10371037

10381038
config_writel(socket, CB_LEGACY_MODE_BASE, 0);
10391039
config_writel(socket, PCI_BASE_ADDRESS_0, region.start);

drivers/scsi/sym53c8xx_2/sym_glue.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,7 +1531,7 @@ static int sym_iomap_device(struct sym_device *device)
15311531
struct pci_bus_region bus_addr;
15321532
int i = 2;
15331533

1534-
pcibios_resource_to_bus(pdev, &bus_addr, &pdev->resource[1]);
1534+
pcibios_resource_to_bus(pdev->bus, &bus_addr, &pdev->resource[1]);
15351535
device->mmio_base = bus_addr.start;
15361536

15371537
if (device->chip.features & FE_RAM) {
@@ -1541,7 +1541,8 @@ static int sym_iomap_device(struct sym_device *device)
15411541
*/
15421542
if (!pdev->resource[i].flags)
15431543
i++;
1544-
pcibios_resource_to_bus(pdev, &bus_addr, &pdev->resource[i]);
1544+
pcibios_resource_to_bus(pdev->bus, &bus_addr,
1545+
&pdev->resource[i]);
15451546
device->ram_base = bus_addr.start;
15461547
}
15471548

drivers/video/arkfb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ static int ark_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
10141014

10151015
vga_res.flags = IORESOURCE_IO;
10161016

1017-
pcibios_bus_to_resource(dev, &vga_res, &bus_reg);
1017+
pcibios_bus_to_resource(dev->bus, &vga_res, &bus_reg);
10181018

10191019
par->state.vgabase = (void __iomem *) vga_res.start;
10201020

drivers/video/s3fb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,7 @@ static int s3_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
11801180

11811181
vga_res.flags = IORESOURCE_IO;
11821182

1183-
pcibios_bus_to_resource(dev, &vga_res, &bus_reg);
1183+
pcibios_bus_to_resource(dev->bus, &vga_res, &bus_reg);
11841184

11851185
par->state.vgabase = (void __iomem *) vga_res.start;
11861186

drivers/video/vt8623fb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ static int vt8623_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
729729

730730
vga_res.flags = IORESOURCE_IO;
731731

732-
pcibios_bus_to_resource(dev, &vga_res, &bus_reg);
732+
pcibios_bus_to_resource(dev->bus, &vga_res, &bus_reg);
733733

734734
par->state.vgabase = (void __iomem *) vga_res.start;
735735

include/linux/pci.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,9 +737,9 @@ void pci_fixup_cardbus(struct pci_bus *);
737737

738738
/* Generic PCI functions used internally */
739739

740-
void pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region,
740+
void pcibios_resource_to_bus(struct pci_bus *bus, struct pci_bus_region *region,
741741
struct resource *res);
742-
void pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res,
742+
void pcibios_bus_to_resource(struct pci_bus *bus, struct resource *res,
743743
struct pci_bus_region *region);
744744
void pcibios_scan_specific_bus(int busn);
745745
struct pci_bus *pci_find_bus(int domain, int busnr);

0 commit comments

Comments
 (0)