Skip to content

Commit 0efd5aa

Browse files
committed
PCI: add struct pci_host_bridge_window with CPU/bus address offset
Some PCI host bridges apply an address offset, so bus addresses on PCI are different from CPU addresses. This patch adds a way for architectures to tell the PCI core about this offset. For example: LIST_HEAD(resources); pci_add_resource_offset(&resources, host->io_space, host->io_offset); pci_add_resource_offset(&resources, host->mem_space, host->mem_offset); pci_scan_root_bus(parent, bus, ops, sysdata, &resources); Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
1 parent 5a21d70 commit 0efd5aa

3 files changed

Lines changed: 51 additions & 20 deletions

File tree

‎drivers/pci/bus.c‎

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,36 @@
1818

1919
#include "pci.h"
2020

21-
void pci_add_resource(struct list_head *resources, struct resource *res)
21+
void pci_add_resource_offset(struct list_head *resources, struct resource *res,
22+
resource_size_t offset)
2223
{
23-
struct pci_bus_resource *bus_res;
24+
struct pci_host_bridge_window *window;
2425

25-
bus_res = kzalloc(sizeof(struct pci_bus_resource), GFP_KERNEL);
26-
if (!bus_res) {
27-
printk(KERN_ERR "PCI: can't add bus resource %pR\n", res);
26+
window = kzalloc(sizeof(struct pci_host_bridge_window), GFP_KERNEL);
27+
if (!window) {
28+
printk(KERN_ERR "PCI: can't add host bridge window %pR\n", res);
2829
return;
2930
}
3031

31-
bus_res->res = res;
32-
list_add_tail(&bus_res->list, resources);
32+
window->res = res;
33+
window->offset = offset;
34+
list_add_tail(&window->list, resources);
35+
}
36+
EXPORT_SYMBOL(pci_add_resource_offset);
37+
38+
void pci_add_resource(struct list_head *resources, struct resource *res)
39+
{
40+
pci_add_resource_offset(resources, res, 0);
3341
}
3442
EXPORT_SYMBOL(pci_add_resource);
3543

3644
void pci_free_resource_list(struct list_head *resources)
3745
{
38-
struct pci_bus_resource *bus_res, *tmp;
46+
struct pci_host_bridge_window *window, *tmp;
3947

40-
list_for_each_entry_safe(bus_res, tmp, resources, list) {
41-
list_del(&bus_res->list);
42-
kfree(bus_res);
48+
list_for_each_entry_safe(window, tmp, resources, list) {
49+
list_del(&window->list);
50+
kfree(window);
4351
}
4452
}
4553
EXPORT_SYMBOL(pci_free_resource_list);

‎drivers/pci/probe.c‎

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,12 +1562,15 @@ unsigned int __devinit pci_scan_child_bus(struct pci_bus *bus)
15621562
struct pci_bus *pci_create_root_bus(struct device *parent, int bus,
15631563
struct pci_ops *ops, void *sysdata, struct list_head *resources)
15641564
{
1565-
int error, i;
1565+
int error;
15661566
struct pci_host_bridge *bridge;
15671567
struct pci_bus *b, *b2;
15681568
struct device *dev;
1569-
struct pci_bus_resource *bus_res, *n;
1569+
struct pci_host_bridge_window *window, *n;
15701570
struct resource *res;
1571+
resource_size_t offset;
1572+
char bus_addr[64];
1573+
char *fmt;
15711574

15721575
bridge = kzalloc(sizeof(*bridge), GFP_KERNEL);
15731576
if (!bridge)
@@ -1617,19 +1620,30 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus,
16171620
b->number = b->secondary = bus;
16181621

16191622
bridge->bus = b;
1620-
1621-
/* Add initial resources to the bus */
1622-
list_for_each_entry_safe(bus_res, n, resources, list)
1623-
list_move_tail(&bus_res->list, &b->resources);
1623+
INIT_LIST_HEAD(&bridge->windows);
16241624

16251625
if (parent)
16261626
dev_info(parent, "PCI host bridge to bus %s\n", dev_name(&b->dev));
16271627
else
16281628
printk(KERN_INFO "PCI host bridge to bus %s\n", dev_name(&b->dev));
16291629

1630-
pci_bus_for_each_resource(b, res, i) {
1631-
if (res)
1632-
dev_info(&b->dev, "root bus resource %pR\n", res);
1630+
/* Add initial resources to the bus */
1631+
list_for_each_entry_safe(window, n, resources, list) {
1632+
list_move_tail(&window->list, &bridge->windows);
1633+
res = window->res;
1634+
offset = window->offset;
1635+
pci_bus_add_resource(b, res, 0);
1636+
if (offset) {
1637+
if (resource_type(res) == IORESOURCE_IO)
1638+
fmt = " (bus address [%#06llx-%#06llx])";
1639+
else
1640+
fmt = " (bus address [%#010llx-%#010llx])";
1641+
snprintf(bus_addr, sizeof(bus_addr), fmt,
1642+
(unsigned long long) (res->start - offset),
1643+
(unsigned long long) (res->end - offset));
1644+
} else
1645+
bus_addr[0] = '\0';
1646+
dev_info(&b->dev, "root bus resource %pR%s\n", res, bus_addr);
16331647
}
16341648

16351649
down_write(&pci_bus_sem);

‎include/linux/pci.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,16 @@ static inline int pci_channel_offline(struct pci_dev *pdev)
368368
return (pdev->error_state != pci_channel_io_normal);
369369
}
370370

371+
struct pci_host_bridge_window {
372+
struct list_head list;
373+
struct resource *res; /* host bridge aperture (CPU address) */
374+
resource_size_t offset; /* bus address + offset = CPU address */
375+
};
376+
371377
struct pci_host_bridge {
372378
struct list_head list;
373379
struct pci_bus *bus; /* root bus */
380+
struct list_head windows; /* pci_host_bridge_windows */
374381
};
375382

376383
/*
@@ -901,6 +908,8 @@ void pci_release_selected_regions(struct pci_dev *, int);
901908

902909
/* drivers/pci/bus.c */
903910
void pci_add_resource(struct list_head *resources, struct resource *res);
911+
void pci_add_resource_offset(struct list_head *resources, struct resource *res,
912+
resource_size_t offset);
904913
void pci_free_resource_list(struct list_head *resources);
905914
void pci_bus_add_resource(struct pci_bus *bus, struct resource *res, unsigned int flags);
906915
struct resource *pci_bus_resource_n(const struct pci_bus *bus, int n);

0 commit comments

Comments
 (0)