x86/PCI: Use host bridge _CRS info on Foxconn K8M890-8237A
[deliverable/linux.git] / arch / x86 / pci / acpi.c
1 #include <linux/pci.h>
2 #include <linux/acpi.h>
3 #include <linux/init.h>
4 #include <linux/irq.h>
5 #include <linux/dmi.h>
6 #include <linux/slab.h>
7 #include <asm/numa.h>
8 #include <asm/pci_x86.h>
9
10 struct pci_root_info {
11 struct acpi_device *bridge;
12 char name[16];
13 struct pci_sysdata sd;
14 #ifdef CONFIG_PCI_MMCONFIG
15 bool mcfg_added;
16 u16 segment;
17 u8 start_bus;
18 u8 end_bus;
19 #endif
20 };
21
22 static bool pci_use_crs = true;
23 static bool pci_ignore_seg = false;
24
25 static int __init set_use_crs(const struct dmi_system_id *id)
26 {
27 pci_use_crs = true;
28 return 0;
29 }
30
31 static int __init set_nouse_crs(const struct dmi_system_id *id)
32 {
33 pci_use_crs = false;
34 return 0;
35 }
36
37 static int __init set_ignore_seg(const struct dmi_system_id *id)
38 {
39 printk(KERN_INFO "PCI: %s detected: ignoring ACPI _SEG\n", id->ident);
40 pci_ignore_seg = true;
41 return 0;
42 }
43
44 static const struct dmi_system_id pci_crs_quirks[] __initconst = {
45 /* http://bugzilla.kernel.org/show_bug.cgi?id=14183 */
46 {
47 .callback = set_use_crs,
48 .ident = "IBM System x3800",
49 .matches = {
50 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
51 DMI_MATCH(DMI_PRODUCT_NAME, "x3800"),
52 },
53 },
54 /* https://bugzilla.kernel.org/show_bug.cgi?id=16007 */
55 /* 2006 AMD HT/VIA system with two host bridges */
56 {
57 .callback = set_use_crs,
58 .ident = "ASRock ALiveSATA2-GLAN",
59 .matches = {
60 DMI_MATCH(DMI_PRODUCT_NAME, "ALiveSATA2-GLAN"),
61 },
62 },
63 /* https://bugzilla.kernel.org/show_bug.cgi?id=30552 */
64 /* 2006 AMD HT/VIA system with two host bridges */
65 {
66 .callback = set_use_crs,
67 .ident = "ASUS M2V-MX SE",
68 .matches = {
69 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
70 DMI_MATCH(DMI_BOARD_NAME, "M2V-MX SE"),
71 DMI_MATCH(DMI_BIOS_VENDOR, "American Megatrends Inc."),
72 },
73 },
74 /* https://bugzilla.kernel.org/show_bug.cgi?id=42619 */
75 {
76 .callback = set_use_crs,
77 .ident = "MSI MS-7253",
78 .matches = {
79 DMI_MATCH(DMI_BOARD_VENDOR, "MICRO-STAR INTERNATIONAL CO., LTD"),
80 DMI_MATCH(DMI_BOARD_NAME, "MS-7253"),
81 DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies, LTD"),
82 },
83 },
84 /* https://bugs.launchpad.net/ubuntu/+source/alsa-driver/+bug/931368 */
85 /* https://bugs.launchpad.net/ubuntu/+source/alsa-driver/+bug/1033299 */
86 {
87 .callback = set_use_crs,
88 .ident = "Foxconn K8M890-8237A",
89 .matches = {
90 DMI_MATCH(DMI_BOARD_VENDOR, "Foxconn"),
91 DMI_MATCH(DMI_BOARD_NAME, "K8M890-8237A"),
92 DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies, LTD"),
93 },
94 },
95
96 /* Now for the blacklist.. */
97
98 /* https://bugzilla.redhat.com/show_bug.cgi?id=769657 */
99 {
100 .callback = set_nouse_crs,
101 .ident = "Dell Studio 1557",
102 .matches = {
103 DMI_MATCH(DMI_BOARD_VENDOR, "Dell Inc."),
104 DMI_MATCH(DMI_PRODUCT_NAME, "Studio 1557"),
105 DMI_MATCH(DMI_BIOS_VERSION, "A09"),
106 },
107 },
108 /* https://bugzilla.redhat.com/show_bug.cgi?id=769657 */
109 {
110 .callback = set_nouse_crs,
111 .ident = "Thinkpad SL510",
112 .matches = {
113 DMI_MATCH(DMI_BOARD_VENDOR, "LENOVO"),
114 DMI_MATCH(DMI_BOARD_NAME, "2847DFG"),
115 DMI_MATCH(DMI_BIOS_VERSION, "6JET85WW (1.43 )"),
116 },
117 },
118
119 /* https://bugzilla.kernel.org/show_bug.cgi?id=15362 */
120 {
121 .callback = set_ignore_seg,
122 .ident = "HP xw9300",
123 .matches = {
124 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
125 DMI_MATCH(DMI_PRODUCT_NAME, "HP xw9300 Workstation"),
126 },
127 },
128 {}
129 };
130
131 void __init pci_acpi_crs_quirks(void)
132 {
133 int year;
134
135 if (dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL) && year < 2008)
136 pci_use_crs = false;
137
138 dmi_check_system(pci_crs_quirks);
139
140 /*
141 * If the user specifies "pci=use_crs" or "pci=nocrs" explicitly, that
142 * takes precedence over anything we figured out above.
143 */
144 if (pci_probe & PCI_ROOT_NO_CRS)
145 pci_use_crs = false;
146 else if (pci_probe & PCI_USE__CRS)
147 pci_use_crs = true;
148
149 printk(KERN_INFO "PCI: %s host bridge windows from ACPI; "
150 "if necessary, use \"pci=%s\" and report a bug\n",
151 pci_use_crs ? "Using" : "Ignoring",
152 pci_use_crs ? "nocrs" : "use_crs");
153 }
154
155 #ifdef CONFIG_PCI_MMCONFIG
156 static int check_segment(u16 seg, struct device *dev, char *estr)
157 {
158 if (seg) {
159 dev_err(dev,
160 "%s can't access PCI configuration "
161 "space under this host bridge.\n",
162 estr);
163 return -EIO;
164 }
165
166 /*
167 * Failure in adding MMCFG information is not fatal,
168 * just can't access extended configuration space of
169 * devices under this host bridge.
170 */
171 dev_warn(dev,
172 "%s can't access extended PCI configuration "
173 "space under this bridge.\n",
174 estr);
175
176 return 0;
177 }
178
179 static int setup_mcfg_map(struct pci_root_info *info, u16 seg, u8 start,
180 u8 end, phys_addr_t addr)
181 {
182 int result;
183 struct device *dev = &info->bridge->dev;
184
185 info->start_bus = start;
186 info->end_bus = end;
187 info->mcfg_added = false;
188
189 /* return success if MMCFG is not in use */
190 if (raw_pci_ext_ops && raw_pci_ext_ops != &pci_mmcfg)
191 return 0;
192
193 if (!(pci_probe & PCI_PROBE_MMCONF))
194 return check_segment(seg, dev, "MMCONFIG is disabled,");
195
196 result = pci_mmconfig_insert(dev, seg, start, end, addr);
197 if (result == 0) {
198 /* enable MMCFG if it hasn't been enabled yet */
199 if (raw_pci_ext_ops == NULL)
200 raw_pci_ext_ops = &pci_mmcfg;
201 info->mcfg_added = true;
202 } else if (result != -EEXIST)
203 return check_segment(seg, dev,
204 "fail to add MMCONFIG information,");
205
206 return 0;
207 }
208
209 static void teardown_mcfg_map(struct pci_root_info *info)
210 {
211 if (info->mcfg_added) {
212 pci_mmconfig_delete(info->segment, info->start_bus,
213 info->end_bus);
214 info->mcfg_added = false;
215 }
216 }
217 #else
218 static int setup_mcfg_map(struct pci_root_info *info,
219 u16 seg, u8 start, u8 end,
220 phys_addr_t addr)
221 {
222 return 0;
223 }
224 static void teardown_mcfg_map(struct pci_root_info *info)
225 {
226 }
227 #endif
228
229 static void validate_resources(struct device *dev, struct list_head *crs_res,
230 unsigned long type)
231 {
232 LIST_HEAD(list);
233 struct resource *res1, *res2, *root = NULL;
234 struct resource_entry *tmp, *entry, *entry2;
235
236 BUG_ON((type & (IORESOURCE_MEM | IORESOURCE_IO)) == 0);
237 root = (type & IORESOURCE_MEM) ? &iomem_resource : &ioport_resource;
238
239 list_splice_init(crs_res, &list);
240 resource_list_for_each_entry_safe(entry, tmp, &list) {
241 bool free = false;
242 resource_size_t end;
243
244 res1 = entry->res;
245 if (!(res1->flags & type))
246 goto next;
247
248 /* Exclude non-addressable range or non-addressable portion */
249 end = min(res1->end, root->end);
250 if (end <= res1->start) {
251 dev_info(dev, "host bridge window %pR (ignored, not CPU addressable)\n",
252 res1);
253 free = true;
254 goto next;
255 } else if (res1->end != end) {
256 dev_info(dev, "host bridge window %pR ([%#llx-%#llx] ignored, not CPU addressable)\n",
257 res1, (unsigned long long)end + 1,
258 (unsigned long long)res1->end);
259 res1->end = end;
260 }
261
262 resource_list_for_each_entry(entry2, crs_res) {
263 res2 = entry2->res;
264 if (!(res2->flags & type))
265 continue;
266
267 /*
268 * I don't like throwing away windows because then
269 * our resources no longer match the ACPI _CRS, but
270 * the kernel resource tree doesn't allow overlaps.
271 */
272 if (resource_overlaps(res1, res2)) {
273 res2->start = min(res1->start, res2->start);
274 res2->end = max(res1->end, res2->end);
275 dev_info(dev, "host bridge window expanded to %pR; %pR ignored\n",
276 res2, res1);
277 free = true;
278 goto next;
279 }
280 }
281
282 next:
283 resource_list_del(entry);
284 if (free)
285 resource_list_free_entry(entry);
286 else
287 resource_list_add_tail(entry, crs_res);
288 }
289 }
290
291 static void add_resources(struct pci_root_info *info,
292 struct list_head *resources,
293 struct list_head *crs_res)
294 {
295 struct resource_entry *entry, *tmp;
296 struct resource *res, *conflict, *root = NULL;
297
298 validate_resources(&info->bridge->dev, crs_res, IORESOURCE_MEM);
299 validate_resources(&info->bridge->dev, crs_res, IORESOURCE_IO);
300
301 resource_list_for_each_entry_safe(entry, tmp, crs_res) {
302 res = entry->res;
303 if (res->flags & IORESOURCE_MEM)
304 root = &iomem_resource;
305 else if (res->flags & IORESOURCE_IO)
306 root = &ioport_resource;
307 else
308 BUG_ON(res);
309
310 conflict = insert_resource_conflict(root, res);
311 if (conflict) {
312 dev_info(&info->bridge->dev,
313 "ignoring host bridge window %pR (conflicts with %s %pR)\n",
314 res, conflict->name, conflict);
315 resource_list_destroy_entry(entry);
316 }
317 }
318
319 list_splice_tail(crs_res, resources);
320 }
321
322 static void release_pci_root_info(struct pci_host_bridge *bridge)
323 {
324 struct resource *res;
325 struct resource_entry *entry;
326 struct pci_root_info *info = bridge->release_data;
327
328 resource_list_for_each_entry(entry, &bridge->windows) {
329 res = entry->res;
330 if (res->parent &&
331 (res->flags & (IORESOURCE_MEM | IORESOURCE_IO)))
332 release_resource(res);
333 }
334
335 teardown_mcfg_map(info);
336 kfree(info);
337 }
338
339 static void probe_pci_root_info(struct pci_root_info *info,
340 struct acpi_device *device,
341 int busnum, int domain,
342 struct list_head *list)
343 {
344 int ret;
345 struct resource_entry *entry, *tmp;
346
347 sprintf(info->name, "PCI Bus %04x:%02x", domain, busnum);
348 info->bridge = device;
349 ret = acpi_dev_get_resources(device, list,
350 acpi_dev_filter_resource_type_cb,
351 (void *)(IORESOURCE_IO | IORESOURCE_MEM));
352 if (ret < 0)
353 dev_warn(&device->dev,
354 "failed to parse _CRS method, error code %d\n", ret);
355 else if (ret == 0)
356 dev_dbg(&device->dev,
357 "no IO and memory resources present in _CRS\n");
358 else
359 resource_list_for_each_entry_safe(entry, tmp, list) {
360 if ((entry->res->flags & IORESOURCE_WINDOW) == 0 ||
361 (entry->res->flags & IORESOURCE_DISABLED))
362 resource_list_destroy_entry(entry);
363 else
364 entry->res->name = info->name;
365 }
366 }
367
368 struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
369 {
370 struct acpi_device *device = root->device;
371 struct pci_root_info *info;
372 int domain = root->segment;
373 int busnum = root->secondary.start;
374 struct resource_entry *res_entry;
375 LIST_HEAD(crs_res);
376 LIST_HEAD(resources);
377 struct pci_bus *bus;
378 struct pci_sysdata *sd;
379 int node;
380
381 if (pci_ignore_seg)
382 domain = 0;
383
384 if (domain && !pci_domains_supported) {
385 printk(KERN_WARNING "pci_bus %04x:%02x: "
386 "ignored (multiple domains not supported)\n",
387 domain, busnum);
388 return NULL;
389 }
390
391 node = acpi_get_node(device->handle);
392 if (node == NUMA_NO_NODE) {
393 node = x86_pci_root_bus_node(busnum);
394 if (node != 0 && node != NUMA_NO_NODE)
395 dev_info(&device->dev, FW_BUG "no _PXM; falling back to node %d from hardware (may be inconsistent with ACPI node numbers)\n",
396 node);
397 }
398
399 if (node != NUMA_NO_NODE && !node_online(node))
400 node = NUMA_NO_NODE;
401
402 info = kzalloc_node(sizeof(*info), GFP_KERNEL, node);
403 if (!info) {
404 printk(KERN_WARNING "pci_bus %04x:%02x: "
405 "ignored (out of memory)\n", domain, busnum);
406 return NULL;
407 }
408
409 sd = &info->sd;
410 sd->domain = domain;
411 sd->node = node;
412 sd->companion = device;
413
414 bus = pci_find_bus(domain, busnum);
415 if (bus) {
416 /*
417 * If the desired bus has been scanned already, replace
418 * its bus->sysdata.
419 */
420 memcpy(bus->sysdata, sd, sizeof(*sd));
421 kfree(info);
422 } else {
423 /* insert busn res at first */
424 pci_add_resource(&resources, &root->secondary);
425
426 /*
427 * _CRS with no apertures is normal, so only fall back to
428 * defaults or native bridge info if we're ignoring _CRS.
429 */
430 probe_pci_root_info(info, device, busnum, domain, &crs_res);
431 if (pci_use_crs) {
432 add_resources(info, &resources, &crs_res);
433 } else {
434 resource_list_for_each_entry(res_entry, &crs_res)
435 dev_printk(KERN_DEBUG, &device->dev,
436 "host bridge window %pR (ignored)\n",
437 res_entry->res);
438 resource_list_free(&crs_res);
439 x86_pci_root_bus_resources(busnum, &resources);
440 }
441
442 if (!setup_mcfg_map(info, domain, (u8)root->secondary.start,
443 (u8)root->secondary.end, root->mcfg_addr))
444 bus = pci_create_root_bus(NULL, busnum, &pci_root_ops,
445 sd, &resources);
446
447 if (bus) {
448 pci_scan_child_bus(bus);
449 pci_set_host_bridge_release(
450 to_pci_host_bridge(bus->bridge),
451 release_pci_root_info, info);
452 } else {
453 resource_list_free(&resources);
454 teardown_mcfg_map(info);
455 kfree(info);
456 }
457 }
458
459 /* After the PCI-E bus has been walked and all devices discovered,
460 * configure any settings of the fabric that might be necessary.
461 */
462 if (bus) {
463 struct pci_bus *child;
464 list_for_each_entry(child, &bus->children, node)
465 pcie_bus_configure_settings(child);
466 }
467
468 if (bus && node != NUMA_NO_NODE)
469 dev_printk(KERN_DEBUG, &bus->dev, "on NUMA node %d\n", node);
470
471 return bus;
472 }
473
474 int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge)
475 {
476 struct pci_sysdata *sd = bridge->bus->sysdata;
477
478 ACPI_COMPANION_SET(&bridge->dev, sd->companion);
479 return 0;
480 }
481
482 int __init pci_acpi_init(void)
483 {
484 struct pci_dev *dev = NULL;
485
486 if (acpi_noirq)
487 return -ENODEV;
488
489 printk(KERN_INFO "PCI: Using ACPI for IRQ routing\n");
490 acpi_irq_penalty_init();
491 pcibios_enable_irq = acpi_pci_irq_enable;
492 pcibios_disable_irq = acpi_pci_irq_disable;
493 x86_init.pci.init_irq = x86_init_noop;
494
495 if (pci_routeirq) {
496 /*
497 * PCI IRQ routing is set up by pci_enable_device(), but we
498 * also do it here in case there are still broken drivers that
499 * don't use pci_enable_device().
500 */
501 printk(KERN_INFO "PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n");
502 for_each_pci_dev(dev)
503 acpi_pci_irq_enable(dev);
504 }
505
506 return 0;
507 }
This page took 0.069679 seconds and 5 git commands to generate.