aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/probe.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/pci/probe.c')
-rw-r--r--drivers/pci/probe.c154
1 files changed, 42 insertions, 112 deletions
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 5e1ca3c58a7d..658ac977cb56 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -10,18 +10,16 @@
10#include <linux/module.h> 10#include <linux/module.h>
11#include <linux/cpumask.h> 11#include <linux/cpumask.h>
12#include <linux/pci-aspm.h> 12#include <linux/pci-aspm.h>
13#include <asm-generic/pci-bridge.h>
13#include "pci.h" 14#include "pci.h"
14 15
15#define CARDBUS_LATENCY_TIMER 176 /* secondary latency timer */ 16#define CARDBUS_LATENCY_TIMER 176 /* secondary latency timer */
16#define CARDBUS_RESERVE_BUSNR 3 17#define CARDBUS_RESERVE_BUSNR 3
17 18
18static LIST_HEAD(pci_host_bridges);
19
20/* Ugh. Need to stop exporting this to modules. */ 19/* Ugh. Need to stop exporting this to modules. */
21LIST_HEAD(pci_root_buses); 20LIST_HEAD(pci_root_buses);
22EXPORT_SYMBOL(pci_root_buses); 21EXPORT_SYMBOL(pci_root_buses);
23 22
24
25static int find_anything(struct device *dev, void *data) 23static int find_anything(struct device *dev, void *data)
26{ 24{
27 return 1; 25 return 1;
@@ -44,82 +42,6 @@ int no_pci_devices(void)
44} 42}
45EXPORT_SYMBOL(no_pci_devices); 43EXPORT_SYMBOL(no_pci_devices);
46 44
47static struct pci_host_bridge *pci_host_bridge(struct pci_dev *dev)
48{
49 struct pci_bus *bus;
50 struct pci_host_bridge *bridge;
51
52 bus = dev->bus;
53 while (bus->parent)
54 bus = bus->parent;
55
56 list_for_each_entry(bridge, &pci_host_bridges, list) {
57 if (bridge->bus == bus)
58 return bridge;
59 }
60
61 return NULL;
62}
63
64static bool resource_contains(struct resource *res1, struct resource *res2)
65{
66 return res1->start <= res2->start && res1->end >= res2->end;
67}
68
69void pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region,
70 struct resource *res)
71{
72 struct pci_host_bridge *bridge = pci_host_bridge(dev);
73 struct pci_host_bridge_window *window;
74 resource_size_t offset = 0;
75
76 list_for_each_entry(window, &bridge->windows, list) {
77 if (resource_type(res) != resource_type(window->res))
78 continue;
79
80 if (resource_contains(window->res, res)) {
81 offset = window->offset;
82 break;
83 }
84 }
85
86 region->start = res->start - offset;
87 region->end = res->end - offset;
88}
89EXPORT_SYMBOL(pcibios_resource_to_bus);
90
91static bool region_contains(struct pci_bus_region *region1,
92 struct pci_bus_region *region2)
93{
94 return region1->start <= region2->start && region1->end >= region2->end;
95}
96
97void pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res,
98 struct pci_bus_region *region)
99{
100 struct pci_host_bridge *bridge = pci_host_bridge(dev);
101 struct pci_host_bridge_window *window;
102 struct pci_bus_region bus_region;
103 resource_size_t offset = 0;
104
105 list_for_each_entry(window, &bridge->windows, list) {
106 if (resource_type(res) != resource_type(window->res))
107 continue;
108
109 bus_region.start = window->res->start - window->offset;
110 bus_region.end = window->res->end - window->offset;
111
112 if (region_contains(&bus_region, region)) {
113 offset = window->offset;
114 break;
115 }
116 }
117
118 res->start = region->start + offset;
119 res->end = region->end + offset;
120}
121EXPORT_SYMBOL(pcibios_bus_to_resource);
122
123/* 45/*
124 * PCI Bus Class 46 * PCI Bus Class
125 */ 47 */
@@ -501,6 +423,19 @@ static struct pci_bus * pci_alloc_bus(void)
501 return b; 423 return b;
502} 424}
503 425
426static struct pci_host_bridge *pci_alloc_host_bridge(struct pci_bus *b)
427{
428 struct pci_host_bridge *bridge;
429
430 bridge = kzalloc(sizeof(*bridge), GFP_KERNEL);
431 if (bridge) {
432 INIT_LIST_HEAD(&bridge->windows);
433 bridge->bus = b;
434 }
435
436 return bridge;
437}
438
504static unsigned char pcix_bus_speed[] = { 439static unsigned char pcix_bus_speed[] = {
505 PCI_SPEED_UNKNOWN, /* 0 */ 440 PCI_SPEED_UNKNOWN, /* 0 */
506 PCI_SPEED_66MHz_PCIX, /* 1 */ 441 PCI_SPEED_66MHz_PCIX, /* 1 */
@@ -1201,7 +1136,14 @@ int pci_cfg_space_size(struct pci_dev *dev)
1201 1136
1202static void pci_release_bus_bridge_dev(struct device *dev) 1137static void pci_release_bus_bridge_dev(struct device *dev)
1203{ 1138{
1204 kfree(dev); 1139 struct pci_host_bridge *bridge = to_pci_host_bridge(dev);
1140
1141 if (bridge->release_fn)
1142 bridge->release_fn(bridge);
1143
1144 pci_free_resource_list(&bridge->windows);
1145
1146 kfree(bridge);
1205} 1147}
1206 1148
1207struct pci_dev *alloc_pci_dev(void) 1149struct pci_dev *alloc_pci_dev(void)
@@ -1395,10 +1337,13 @@ static unsigned no_next_fn(struct pci_dev *dev, unsigned fn)
1395static int only_one_child(struct pci_bus *bus) 1337static int only_one_child(struct pci_bus *bus)
1396{ 1338{
1397 struct pci_dev *parent = bus->self; 1339 struct pci_dev *parent = bus->self;
1340
1398 if (!parent || !pci_is_pcie(parent)) 1341 if (!parent || !pci_is_pcie(parent))
1399 return 0; 1342 return 0;
1400 if (parent->pcie_type == PCI_EXP_TYPE_ROOT_PORT || 1343 if (parent->pcie_type == PCI_EXP_TYPE_ROOT_PORT)
1401 parent->pcie_type == PCI_EXP_TYPE_DOWNSTREAM) 1344 return 1;
1345 if (parent->pcie_type == PCI_EXP_TYPE_DOWNSTREAM &&
1346 !pci_has_flag(PCI_SCAN_ALL_PCIE_DEVS))
1402 return 1; 1347 return 1;
1403 return 0; 1348 return 0;
1404} 1349}
@@ -1650,28 +1595,19 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus,
1650 int error; 1595 int error;
1651 struct pci_host_bridge *bridge; 1596 struct pci_host_bridge *bridge;
1652 struct pci_bus *b, *b2; 1597 struct pci_bus *b, *b2;
1653 struct device *dev;
1654 struct pci_host_bridge_window *window, *n; 1598 struct pci_host_bridge_window *window, *n;
1655 struct resource *res; 1599 struct resource *res;
1656 resource_size_t offset; 1600 resource_size_t offset;
1657 char bus_addr[64]; 1601 char bus_addr[64];
1658 char *fmt; 1602 char *fmt;
1659 1603
1660 bridge = kzalloc(sizeof(*bridge), GFP_KERNEL);
1661 if (!bridge)
1662 return NULL;
1663 1604
1664 b = pci_alloc_bus(); 1605 b = pci_alloc_bus();
1665 if (!b) 1606 if (!b)
1666 goto err_bus; 1607 return NULL;
1667
1668 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1669 if (!dev)
1670 goto err_dev;
1671 1608
1672 b->sysdata = sysdata; 1609 b->sysdata = sysdata;
1673 b->ops = ops; 1610 b->ops = ops;
1674
1675 b2 = pci_find_bus(pci_domain_nr(b), bus); 1611 b2 = pci_find_bus(pci_domain_nr(b), bus);
1676 if (b2) { 1612 if (b2) {
1677 /* If we already got to this bus through a different bridge, ignore it */ 1613 /* If we already got to this bus through a different bridge, ignore it */
@@ -1679,13 +1615,17 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus,
1679 goto err_out; 1615 goto err_out;
1680 } 1616 }
1681 1617
1682 dev->parent = parent; 1618 bridge = pci_alloc_host_bridge(b);
1683 dev->release = pci_release_bus_bridge_dev; 1619 if (!bridge)
1684 dev_set_name(dev, "pci%04x:%02x", pci_domain_nr(b), bus); 1620 goto err_out;
1685 error = device_register(dev); 1621
1622 bridge->dev.parent = parent;
1623 bridge->dev.release = pci_release_bus_bridge_dev;
1624 dev_set_name(&bridge->dev, "pci%04x:%02x", pci_domain_nr(b), bus);
1625 error = device_register(&bridge->dev);
1686 if (error) 1626 if (error)
1687 goto dev_reg_err; 1627 goto bridge_dev_reg_err;
1688 b->bridge = get_device(dev); 1628 b->bridge = get_device(&bridge->dev);
1689 device_enable_async_suspend(b->bridge); 1629 device_enable_async_suspend(b->bridge);
1690 pci_set_bus_of_node(b); 1630 pci_set_bus_of_node(b);
1691 1631
@@ -1704,9 +1644,6 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus,
1704 1644
1705 b->number = b->secondary = bus; 1645 b->number = b->secondary = bus;
1706 1646
1707 bridge->bus = b;
1708 INIT_LIST_HEAD(&bridge->windows);
1709
1710 if (parent) 1647 if (parent)
1711 dev_info(parent, "PCI host bridge to bus %s\n", dev_name(&b->dev)); 1648 dev_info(parent, "PCI host bridge to bus %s\n", dev_name(&b->dev));
1712 else 1649 else
@@ -1732,25 +1669,18 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus,
1732 } 1669 }
1733 1670
1734 down_write(&pci_bus_sem); 1671 down_write(&pci_bus_sem);
1735 list_add_tail(&bridge->list, &pci_host_bridges);
1736 list_add_tail(&b->node, &pci_root_buses); 1672 list_add_tail(&b->node, &pci_root_buses);
1737 up_write(&pci_bus_sem); 1673 up_write(&pci_bus_sem);
1738 1674
1739 return b; 1675 return b;
1740 1676
1741class_dev_reg_err: 1677class_dev_reg_err:
1742 device_unregister(dev); 1678 put_device(&bridge->dev);
1743dev_reg_err: 1679 device_unregister(&bridge->dev);
1744 down_write(&pci_bus_sem); 1680bridge_dev_reg_err:
1745 list_del(&bridge->list); 1681 kfree(bridge);
1746 list_del(&b->node);
1747 up_write(&pci_bus_sem);
1748err_out: 1682err_out:
1749 kfree(dev);
1750err_dev:
1751 kfree(b); 1683 kfree(b);
1752err_bus:
1753 kfree(bridge);
1754 return NULL; 1684 return NULL;
1755} 1685}
1756 1686