]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | #include <linux/pci.h> |
2 | #include <linux/acpi.h> | |
3 | #include <linux/init.h> | |
b33fa1f3 | 4 | #include <linux/irq.h> |
036fff4c | 5 | #include <linux/dmi.h> |
69e1a33f | 6 | #include <asm/numa.h> |
82487711 | 7 | #include <asm/pci_x86.h> |
1da177e4 | 8 | |
62f420f8 | 9 | struct pci_root_info { |
42887b29 | 10 | struct acpi_device *bridge; |
62f420f8 GH |
11 | char *name; |
12 | unsigned int res_num; | |
13 | struct resource *res; | |
14 | struct pci_bus *bus; | |
15 | int busnum; | |
16 | }; | |
17 | ||
18 | static acpi_status | |
19 | resource_to_addr(struct acpi_resource *resource, | |
20 | struct acpi_resource_address64 *addr) | |
21 | { | |
22 | acpi_status status; | |
23 | ||
24 | status = acpi_resource_to_address64(resource, addr); | |
25 | if (ACPI_SUCCESS(status) && | |
26 | (addr->resource_type == ACPI_MEMORY_RANGE || | |
27 | addr->resource_type == ACPI_IO_RANGE) && | |
28 | addr->address_length > 0 && | |
29 | addr->producer_consumer == ACPI_PRODUCER) { | |
30 | return AE_OK; | |
31 | } | |
32 | return AE_ERROR; | |
33 | } | |
34 | ||
35 | static acpi_status | |
36 | count_resource(struct acpi_resource *acpi_res, void *data) | |
37 | { | |
38 | struct pci_root_info *info = data; | |
39 | struct acpi_resource_address64 addr; | |
40 | acpi_status status; | |
41 | ||
42 | status = resource_to_addr(acpi_res, &addr); | |
43 | if (ACPI_SUCCESS(status)) | |
44 | info->res_num++; | |
45 | return AE_OK; | |
46 | } | |
47 | ||
f9cde5ff GH |
48 | static int |
49 | bus_has_transparent_bridge(struct pci_bus *bus) | |
50 | { | |
51 | struct pci_dev *dev; | |
52 | ||
53 | list_for_each_entry(dev, &bus->devices, bus_list) { | |
54 | u16 class = dev->class >> 8; | |
55 | ||
56 | if (class == PCI_CLASS_BRIDGE_PCI && dev->transparent) | |
57 | return true; | |
58 | } | |
59 | return false; | |
60 | } | |
61 | ||
62f420f8 GH |
62 | static acpi_status |
63 | setup_resource(struct acpi_resource *acpi_res, void *data) | |
64 | { | |
65 | struct pci_root_info *info = data; | |
66 | struct resource *res; | |
67 | struct acpi_resource_address64 addr; | |
68 | acpi_status status; | |
69 | unsigned long flags; | |
70 | struct resource *root; | |
f9cde5ff | 71 | int max_root_bus_resources = PCI_BUS_NUM_RESOURCES; |
2cdb3f1d YL |
72 | u64 start, end; |
73 | ||
74 | if (bus_has_transparent_bridge(info->bus)) | |
75 | max_root_bus_resources -= 3; | |
3d9befd2 | 76 | |
62f420f8 GH |
77 | status = resource_to_addr(acpi_res, &addr); |
78 | if (!ACPI_SUCCESS(status)) | |
79 | return AE_OK; | |
80 | ||
81 | if (addr.resource_type == ACPI_MEMORY_RANGE) { | |
82 | root = &iomem_resource; | |
83 | flags = IORESOURCE_MEM; | |
84 | if (addr.info.mem.caching == ACPI_PREFETCHABLE_MEMORY) | |
85 | flags |= IORESOURCE_PREFETCH; | |
86 | } else if (addr.resource_type == ACPI_IO_RANGE) { | |
87 | root = &ioport_resource; | |
88 | flags = IORESOURCE_IO; | |
89 | } else | |
90 | return AE_OK; | |
91 | ||
2cdb3f1d YL |
92 | start = addr.minimum + addr.translation_offset; |
93 | end = start + addr.address_length - 1; | |
f9cde5ff GH |
94 | if (info->res_num >= max_root_bus_resources) { |
95 | printk(KERN_WARNING "PCI: Failed to allocate 0x%lx-0x%lx " | |
96 | "from %s for %s due to _CRS returning more than " | |
2cdb3f1d YL |
97 | "%d resource descriptors\n", (unsigned long) start, |
98 | (unsigned long) end, root->name, info->name, | |
f9cde5ff | 99 | max_root_bus_resources); |
f9cde5ff GH |
100 | return AE_OK; |
101 | } | |
102 | ||
2cdb3f1d YL |
103 | res = &info->res[info->res_num]; |
104 | res->name = info->name; | |
105 | res->flags = flags; | |
106 | res->start = start; | |
107 | res->end = end; | |
108 | res->child = NULL; | |
109 | ||
62f420f8 | 110 | if (insert_resource(root, res)) { |
c7dabef8 BH |
111 | dev_err(&info->bridge->dev, |
112 | "can't allocate host bridge window %pR\n", res); | |
62f420f8 GH |
113 | } else { |
114 | info->bus->resource[info->res_num] = res; | |
115 | info->res_num++; | |
42887b29 | 116 | if (addr.translation_offset) |
c7dabef8 | 117 | dev_info(&info->bridge->dev, "host bridge window %pR " |
42887b29 BH |
118 | "(PCI address [%#llx-%#llx])\n", |
119 | res, res->start - addr.translation_offset, | |
120 | res->end - addr.translation_offset); | |
121 | else | |
122 | dev_info(&info->bridge->dev, | |
c7dabef8 | 123 | "host bridge window %pR\n", res); |
62f420f8 GH |
124 | } |
125 | return AE_OK; | |
126 | } | |
127 | ||
62f420f8 GH |
128 | static void |
129 | get_current_resources(struct acpi_device *device, int busnum, | |
cb3576fa | 130 | int domain, struct pci_bus *bus) |
62f420f8 GH |
131 | { |
132 | struct pci_root_info info; | |
133 | size_t size; | |
134 | ||
42887b29 | 135 | info.bridge = device; |
62f420f8 GH |
136 | info.bus = bus; |
137 | info.res_num = 0; | |
138 | acpi_walk_resources(device->handle, METHOD_NAME__CRS, count_resource, | |
139 | &info); | |
140 | if (!info.res_num) | |
141 | return; | |
142 | ||
143 | size = sizeof(*info.res) * info.res_num; | |
144 | info.res = kmalloc(size, GFP_KERNEL); | |
145 | if (!info.res) | |
146 | goto res_alloc_fail; | |
147 | ||
cb3576fa | 148 | info.name = kmalloc(16, GFP_KERNEL); |
62f420f8 GH |
149 | if (!info.name) |
150 | goto name_alloc_fail; | |
cb3576fa | 151 | sprintf(info.name, "PCI Bus %04x:%02x", domain, busnum); |
62f420f8 GH |
152 | |
153 | info.res_num = 0; | |
154 | acpi_walk_resources(device->handle, METHOD_NAME__CRS, setup_resource, | |
155 | &info); | |
62f420f8 GH |
156 | |
157 | return; | |
158 | ||
159 | name_alloc_fail: | |
160 | kfree(info.res); | |
161 | res_alloc_fail: | |
162 | return; | |
163 | } | |
164 | ||
1da177e4 LT |
165 | struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_device *device, int domain, int busnum) |
166 | { | |
69e1a33f | 167 | struct pci_bus *bus; |
08f1c192 | 168 | struct pci_sysdata *sd; |
871d5f8d YL |
169 | int node; |
170 | #ifdef CONFIG_ACPI_NUMA | |
08f1c192 | 171 | int pxm; |
871d5f8d | 172 | #endif |
08f1c192 | 173 | |
a79e4198 JG |
174 | if (domain && !pci_domains_supported) { |
175 | printk(KERN_WARNING "PCI: Multiple domains not supported " | |
176 | "(dom %d, bus %d)\n", domain, busnum); | |
177 | return NULL; | |
178 | } | |
179 | ||
871d5f8d YL |
180 | node = -1; |
181 | #ifdef CONFIG_ACPI_NUMA | |
182 | pxm = acpi_get_pxm(device->handle); | |
183 | if (pxm >= 0) | |
184 | node = pxm_to_node(pxm); | |
185 | if (node != -1) | |
186 | set_mp_bus_to_node(busnum, node); | |
187 | else | |
871d5f8d | 188 | #endif |
871d5f8d | 189 | node = get_mp_bus_to_node(busnum); |
b755de8d YL |
190 | |
191 | if (node != -1 && !node_online(node)) | |
192 | node = -1; | |
871d5f8d | 193 | |
08f1c192 MBY |
194 | /* Allocate per-root-bus (not per bus) arch-specific data. |
195 | * TODO: leak; this memory is never freed. | |
196 | * It's arguable whether it's worth the trouble to care. | |
197 | */ | |
198 | sd = kzalloc(sizeof(*sd), GFP_KERNEL); | |
199 | if (!sd) { | |
200 | printk(KERN_ERR "PCI: OOM, not probing PCI bus %02x\n", busnum); | |
201 | return NULL; | |
202 | } | |
69e1a33f | 203 | |
a79e4198 | 204 | sd->domain = domain; |
871d5f8d | 205 | sd->node = node; |
b87e81e5 | 206 | /* |
207 | * Maybe the desired pci bus has been already scanned. In such case | |
208 | * it is unnecessary to scan the pci bus with the given domain,busnum. | |
209 | */ | |
210 | bus = pci_find_bus(domain, busnum); | |
211 | if (bus) { | |
212 | /* | |
213 | * If the desired bus exits, the content of bus->sysdata will | |
214 | * be replaced by sd. | |
215 | */ | |
216 | memcpy(bus->sysdata, sd, sizeof(*sd)); | |
217 | kfree(sd); | |
626fdfec YL |
218 | } else { |
219 | bus = pci_create_bus(NULL, busnum, &pci_root_ops, sd); | |
220 | if (bus) { | |
221 | if (pci_probe & PCI_USE__CRS) | |
222 | get_current_resources(device, busnum, domain, | |
223 | bus); | |
224 | bus->subordinate = pci_scan_child_bus(bus); | |
225 | } | |
226 | } | |
08f1c192 | 227 | |
08f1c192 MBY |
228 | if (!bus) |
229 | kfree(sd); | |
230 | ||
dbb6152e | 231 | if (bus && node != -1) { |
69e1a33f | 232 | #ifdef CONFIG_ACPI_NUMA |
dbb6152e | 233 | if (pxm >= 0) |
2b8c2efe BH |
234 | dev_printk(KERN_DEBUG, &bus->dev, |
235 | "on NUMA node %d (pxm %d)\n", node, pxm); | |
dbb6152e | 236 | #else |
2b8c2efe | 237 | dev_printk(KERN_DEBUG, &bus->dev, "on NUMA node %d\n", node); |
69e1a33f | 238 | #endif |
dbb6152e | 239 | } |
62f420f8 | 240 | |
69e1a33f | 241 | return bus; |
1da177e4 LT |
242 | } |
243 | ||
8dd779b1 | 244 | int __init pci_acpi_init(void) |
1da177e4 LT |
245 | { |
246 | struct pci_dev *dev = NULL; | |
247 | ||
248 | if (pcibios_scanned) | |
249 | return 0; | |
250 | ||
251 | if (acpi_noirq) | |
252 | return 0; | |
253 | ||
254 | printk(KERN_INFO "PCI: Using ACPI for IRQ routing\n"); | |
255 | acpi_irq_penalty_init(); | |
256 | pcibios_scanned++; | |
257 | pcibios_enable_irq = acpi_pci_irq_enable; | |
87bec66b | 258 | pcibios_disable_irq = acpi_pci_irq_disable; |
1da177e4 LT |
259 | |
260 | if (pci_routeirq) { | |
261 | /* | |
262 | * PCI IRQ routing is set up by pci_enable_device(), but we | |
263 | * also do it here in case there are still broken drivers that | |
264 | * don't use pci_enable_device(). | |
265 | */ | |
266 | printk(KERN_INFO "PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n"); | |
fb37fb96 | 267 | for_each_pci_dev(dev) |
1da177e4 | 268 | acpi_pci_irq_enable(dev); |
657472e9 | 269 | } |
1da177e4 | 270 | |
1da177e4 LT |
271 | return 0; |
272 | } |