aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/probe.c
diff options
context:
space:
mode:
authorAndrea Bastoni <bastoni@cs.unc.edu>2010-05-30 19:16:45 -0400
committerAndrea Bastoni <bastoni@cs.unc.edu>2010-05-30 19:16:45 -0400
commitada47b5fe13d89735805b566185f4885f5a3f750 (patch)
tree644b88f8a71896307d71438e9b3af49126ffb22b /drivers/pci/probe.c
parent43e98717ad40a4ae64545b5ba047c7b86aa44f4f (diff)
parent3280f21d43ee541f97f8cda5792150d2dbec20d5 (diff)
Merge branch 'wip-2.6.34' into old-private-masterarchived-private-master
Diffstat (limited to 'drivers/pci/probe.c')
-rw-r--r--drivers/pci/probe.c396
1 files changed, 325 insertions, 71 deletions
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 8105e32117f6..c82548afcd5c 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -10,6 +10,7 @@
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 <acpi/acpi_hest.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 */
@@ -88,6 +89,7 @@ static void release_pcibus_dev(struct device *dev)
88 89
89 if (pci_bus->bridge) 90 if (pci_bus->bridge)
90 put_device(pci_bus->bridge); 91 put_device(pci_bus->bridge);
92 pci_bus_remove_resources(pci_bus);
91 kfree(pci_bus); 93 kfree(pci_bus);
92} 94}
93 95
@@ -163,12 +165,12 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
163{ 165{
164 u32 l, sz, mask; 166 u32 l, sz, mask;
165 167
166 mask = type ? ~PCI_ROM_ADDRESS_ENABLE : ~0; 168 mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
167 169
168 res->name = pci_name(dev); 170 res->name = pci_name(dev);
169 171
170 pci_read_config_dword(dev, pos, &l); 172 pci_read_config_dword(dev, pos, &l);
171 pci_write_config_dword(dev, pos, mask); 173 pci_write_config_dword(dev, pos, l | mask);
172 pci_read_config_dword(dev, pos, &sz); 174 pci_read_config_dword(dev, pos, &sz);
173 pci_write_config_dword(dev, pos, l); 175 pci_write_config_dword(dev, pos, l);
174 176
@@ -223,9 +225,13 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
223 goto fail; 225 goto fail;
224 226
225 if ((sizeof(resource_size_t) < 8) && (sz64 > 0x100000000ULL)) { 227 if ((sizeof(resource_size_t) < 8) && (sz64 > 0x100000000ULL)) {
226 dev_err(&dev->dev, "can't handle 64-bit BAR\n"); 228 dev_err(&dev->dev, "reg %x: can't handle 64-bit BAR\n",
229 pos);
227 goto fail; 230 goto fail;
228 } else if ((sizeof(resource_size_t) < 8) && l) { 231 }
232
233 res->flags |= IORESOURCE_MEM_64;
234 if ((sizeof(resource_size_t) < 8) && l) {
229 /* Address above 32-bit boundary; disable the BAR */ 235 /* Address above 32-bit boundary; disable the BAR */
230 pci_write_config_dword(dev, pos, 0); 236 pci_write_config_dword(dev, pos, 0);
231 pci_write_config_dword(dev, pos + 4, 0); 237 pci_write_config_dword(dev, pos + 4, 0);
@@ -234,14 +240,9 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
234 } else { 240 } else {
235 res->start = l64; 241 res->start = l64;
236 res->end = l64 + sz64; 242 res->end = l64 + sz64;
237 dev_printk(KERN_DEBUG, &dev->dev, 243 dev_printk(KERN_DEBUG, &dev->dev, "reg %x: %pR\n",
238 "reg %x %s: %pR\n", pos, 244 pos, res);
239 (res->flags & IORESOURCE_PREFETCH) ?
240 "64bit mmio pref" : "64bit mmio",
241 res);
242 } 245 }
243
244 res->flags |= IORESOURCE_MEM_64;
245 } else { 246 } else {
246 sz = pci_size(l, sz, mask); 247 sz = pci_size(l, sz, mask);
247 248
@@ -251,11 +252,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
251 res->start = l; 252 res->start = l;
252 res->end = l + sz; 253 res->end = l + sz;
253 254
254 dev_printk(KERN_DEBUG, &dev->dev, "reg %x %s: %pR\n", pos, 255 dev_printk(KERN_DEBUG, &dev->dev, "reg %x: %pR\n", pos, res);
255 (res->flags & IORESOURCE_IO) ? "io port" :
256 ((res->flags & IORESOURCE_PREFETCH) ?
257 "32bit mmio pref" : "32bit mmio"),
258 res);
259 } 256 }
260 257
261 out: 258 out:
@@ -285,23 +282,12 @@ static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom)
285 } 282 }
286} 283}
287 284
288void __devinit pci_read_bridge_bases(struct pci_bus *child) 285static void __devinit pci_read_bridge_io(struct pci_bus *child)
289{ 286{
290 struct pci_dev *dev = child->self; 287 struct pci_dev *dev = child->self;
291 u8 io_base_lo, io_limit_lo; 288 u8 io_base_lo, io_limit_lo;
292 u16 mem_base_lo, mem_limit_lo;
293 unsigned long base, limit; 289 unsigned long base, limit;
294 struct resource *res; 290 struct resource *res;
295 int i;
296
297 if (pci_is_root_bus(child)) /* It's a host bus, nothing to read */
298 return;
299
300 if (dev->transparent) {
301 dev_info(&dev->dev, "transparent bridge\n");
302 for(i = 3; i < PCI_BUS_NUM_RESOURCES; i++)
303 child->resource[i] = child->parent->resource[i - 3];
304 }
305 291
306 res = child->resource[0]; 292 res = child->resource[0];
307 pci_read_config_byte(dev, PCI_IO_BASE, &io_base_lo); 293 pci_read_config_byte(dev, PCI_IO_BASE, &io_base_lo);
@@ -317,27 +303,50 @@ void __devinit pci_read_bridge_bases(struct pci_bus *child)
317 limit |= (io_limit_hi << 16); 303 limit |= (io_limit_hi << 16);
318 } 304 }
319 305
320 if (base <= limit) { 306 if (base && base <= limit) {
321 res->flags = (io_base_lo & PCI_IO_RANGE_TYPE_MASK) | IORESOURCE_IO; 307 res->flags = (io_base_lo & PCI_IO_RANGE_TYPE_MASK) | IORESOURCE_IO;
322 if (!res->start) 308 if (!res->start)
323 res->start = base; 309 res->start = base;
324 if (!res->end) 310 if (!res->end)
325 res->end = limit + 0xfff; 311 res->end = limit + 0xfff;
326 dev_printk(KERN_DEBUG, &dev->dev, "bridge io port: %pR\n", res); 312 dev_printk(KERN_DEBUG, &dev->dev, " bridge window %pR\n", res);
313 } else {
314 dev_printk(KERN_DEBUG, &dev->dev,
315 " bridge window [io %#06lx-%#06lx] (disabled)\n",
316 base, limit);
327 } 317 }
318}
319
320static void __devinit pci_read_bridge_mmio(struct pci_bus *child)
321{
322 struct pci_dev *dev = child->self;
323 u16 mem_base_lo, mem_limit_lo;
324 unsigned long base, limit;
325 struct resource *res;
328 326
329 res = child->resource[1]; 327 res = child->resource[1];
330 pci_read_config_word(dev, PCI_MEMORY_BASE, &mem_base_lo); 328 pci_read_config_word(dev, PCI_MEMORY_BASE, &mem_base_lo);
331 pci_read_config_word(dev, PCI_MEMORY_LIMIT, &mem_limit_lo); 329 pci_read_config_word(dev, PCI_MEMORY_LIMIT, &mem_limit_lo);
332 base = (mem_base_lo & PCI_MEMORY_RANGE_MASK) << 16; 330 base = (mem_base_lo & PCI_MEMORY_RANGE_MASK) << 16;
333 limit = (mem_limit_lo & PCI_MEMORY_RANGE_MASK) << 16; 331 limit = (mem_limit_lo & PCI_MEMORY_RANGE_MASK) << 16;
334 if (base <= limit) { 332 if (base && base <= limit) {
335 res->flags = (mem_base_lo & PCI_MEMORY_RANGE_TYPE_MASK) | IORESOURCE_MEM; 333 res->flags = (mem_base_lo & PCI_MEMORY_RANGE_TYPE_MASK) | IORESOURCE_MEM;
336 res->start = base; 334 res->start = base;
337 res->end = limit + 0xfffff; 335 res->end = limit + 0xfffff;
338 dev_printk(KERN_DEBUG, &dev->dev, "bridge 32bit mmio: %pR\n", 336 dev_printk(KERN_DEBUG, &dev->dev, " bridge window %pR\n", res);
339 res); 337 } else {
338 dev_printk(KERN_DEBUG, &dev->dev,
339 " bridge window [mem %#010lx-%#010lx] (disabled)\n",
340 base, limit + 0xfffff);
340 } 341 }
342}
343
344static void __devinit pci_read_bridge_mmio_pref(struct pci_bus *child)
345{
346 struct pci_dev *dev = child->self;
347 u16 mem_base_lo, mem_limit_lo;
348 unsigned long base, limit;
349 struct resource *res;
341 350
342 res = child->resource[2]; 351 res = child->resource[2];
343 pci_read_config_word(dev, PCI_PREF_MEMORY_BASE, &mem_base_lo); 352 pci_read_config_word(dev, PCI_PREF_MEMORY_BASE, &mem_base_lo);
@@ -368,16 +377,52 @@ void __devinit pci_read_bridge_bases(struct pci_bus *child)
368#endif 377#endif
369 } 378 }
370 } 379 }
371 if (base <= limit) { 380 if (base && base <= limit) {
372 res->flags = (mem_base_lo & PCI_PREF_RANGE_TYPE_MASK) | 381 res->flags = (mem_base_lo & PCI_PREF_RANGE_TYPE_MASK) |
373 IORESOURCE_MEM | IORESOURCE_PREFETCH; 382 IORESOURCE_MEM | IORESOURCE_PREFETCH;
374 if (res->flags & PCI_PREF_RANGE_TYPE_64) 383 if (res->flags & PCI_PREF_RANGE_TYPE_64)
375 res->flags |= IORESOURCE_MEM_64; 384 res->flags |= IORESOURCE_MEM_64;
376 res->start = base; 385 res->start = base;
377 res->end = limit + 0xfffff; 386 res->end = limit + 0xfffff;
378 dev_printk(KERN_DEBUG, &dev->dev, "bridge %sbit mmio pref: %pR\n", 387 dev_printk(KERN_DEBUG, &dev->dev, " bridge window %pR\n", res);
379 (res->flags & PCI_PREF_RANGE_TYPE_64) ? "64" : "32", 388 } else {
380 res); 389 dev_printk(KERN_DEBUG, &dev->dev,
390 " bridge window [mem %#010lx-%#010lx pref] (disabled)\n",
391 base, limit + 0xfffff);
392 }
393}
394
395void __devinit pci_read_bridge_bases(struct pci_bus *child)
396{
397 struct pci_dev *dev = child->self;
398 struct resource *res;
399 int i;
400
401 if (pci_is_root_bus(child)) /* It's a host bus, nothing to read */
402 return;
403
404 dev_info(&dev->dev, "PCI bridge to [bus %02x-%02x]%s\n",
405 child->secondary, child->subordinate,
406 dev->transparent ? " (subtractive decode)" : "");
407
408 pci_bus_remove_resources(child);
409 for (i = 0; i < PCI_BRIDGE_RESOURCE_NUM; i++)
410 child->resource[i] = &dev->resource[PCI_BRIDGE_RESOURCES+i];
411
412 pci_read_bridge_io(child);
413 pci_read_bridge_mmio(child);
414 pci_read_bridge_mmio_pref(child);
415
416 if (dev->transparent) {
417 pci_bus_for_each_resource(child->parent, res, i) {
418 if (res) {
419 pci_bus_add_resource(child, res,
420 PCI_SUBTRACTIVE_DECODE);
421 dev_printk(KERN_DEBUG, &dev->dev,
422 " bridge window %pR (subtractive decode)\n",
423 res);
424 }
425 }
381 } 426 }
382} 427}
383 428
@@ -391,10 +436,147 @@ static struct pci_bus * pci_alloc_bus(void)
391 INIT_LIST_HEAD(&b->children); 436 INIT_LIST_HEAD(&b->children);
392 INIT_LIST_HEAD(&b->devices); 437 INIT_LIST_HEAD(&b->devices);
393 INIT_LIST_HEAD(&b->slots); 438 INIT_LIST_HEAD(&b->slots);
439 INIT_LIST_HEAD(&b->resources);
440 b->max_bus_speed = PCI_SPEED_UNKNOWN;
441 b->cur_bus_speed = PCI_SPEED_UNKNOWN;
394 } 442 }
395 return b; 443 return b;
396} 444}
397 445
446static unsigned char pcix_bus_speed[] = {
447 PCI_SPEED_UNKNOWN, /* 0 */
448 PCI_SPEED_66MHz_PCIX, /* 1 */
449 PCI_SPEED_100MHz_PCIX, /* 2 */
450 PCI_SPEED_133MHz_PCIX, /* 3 */
451 PCI_SPEED_UNKNOWN, /* 4 */
452 PCI_SPEED_66MHz_PCIX_ECC, /* 5 */
453 PCI_SPEED_100MHz_PCIX_ECC, /* 6 */
454 PCI_SPEED_133MHz_PCIX_ECC, /* 7 */
455 PCI_SPEED_UNKNOWN, /* 8 */
456 PCI_SPEED_66MHz_PCIX_266, /* 9 */
457 PCI_SPEED_100MHz_PCIX_266, /* A */
458 PCI_SPEED_133MHz_PCIX_266, /* B */
459 PCI_SPEED_UNKNOWN, /* C */
460 PCI_SPEED_66MHz_PCIX_533, /* D */
461 PCI_SPEED_100MHz_PCIX_533, /* E */
462 PCI_SPEED_133MHz_PCIX_533 /* F */
463};
464
465static unsigned char pcie_link_speed[] = {
466 PCI_SPEED_UNKNOWN, /* 0 */
467 PCIE_SPEED_2_5GT, /* 1 */
468 PCIE_SPEED_5_0GT, /* 2 */
469 PCIE_SPEED_8_0GT, /* 3 */
470 PCI_SPEED_UNKNOWN, /* 4 */
471 PCI_SPEED_UNKNOWN, /* 5 */
472 PCI_SPEED_UNKNOWN, /* 6 */
473 PCI_SPEED_UNKNOWN, /* 7 */
474 PCI_SPEED_UNKNOWN, /* 8 */
475 PCI_SPEED_UNKNOWN, /* 9 */
476 PCI_SPEED_UNKNOWN, /* A */
477 PCI_SPEED_UNKNOWN, /* B */
478 PCI_SPEED_UNKNOWN, /* C */
479 PCI_SPEED_UNKNOWN, /* D */
480 PCI_SPEED_UNKNOWN, /* E */
481 PCI_SPEED_UNKNOWN /* F */
482};
483
484void pcie_update_link_speed(struct pci_bus *bus, u16 linksta)
485{
486 bus->cur_bus_speed = pcie_link_speed[linksta & 0xf];
487}
488EXPORT_SYMBOL_GPL(pcie_update_link_speed);
489
490static unsigned char agp_speeds[] = {
491 AGP_UNKNOWN,
492 AGP_1X,
493 AGP_2X,
494 AGP_4X,
495 AGP_8X
496};
497
498static enum pci_bus_speed agp_speed(int agp3, int agpstat)
499{
500 int index = 0;
501
502 if (agpstat & 4)
503 index = 3;
504 else if (agpstat & 2)
505 index = 2;
506 else if (agpstat & 1)
507 index = 1;
508 else
509 goto out;
510
511 if (agp3) {
512 index += 2;
513 if (index == 5)
514 index = 0;
515 }
516
517 out:
518 return agp_speeds[index];
519}
520
521
522static void pci_set_bus_speed(struct pci_bus *bus)
523{
524 struct pci_dev *bridge = bus->self;
525 int pos;
526
527 pos = pci_find_capability(bridge, PCI_CAP_ID_AGP);
528 if (!pos)
529 pos = pci_find_capability(bridge, PCI_CAP_ID_AGP3);
530 if (pos) {
531 u32 agpstat, agpcmd;
532
533 pci_read_config_dword(bridge, pos + PCI_AGP_STATUS, &agpstat);
534 bus->max_bus_speed = agp_speed(agpstat & 8, agpstat & 7);
535
536 pci_read_config_dword(bridge, pos + PCI_AGP_COMMAND, &agpcmd);
537 bus->cur_bus_speed = agp_speed(agpstat & 8, agpcmd & 7);
538 }
539
540 pos = pci_find_capability(bridge, PCI_CAP_ID_PCIX);
541 if (pos) {
542 u16 status;
543 enum pci_bus_speed max;
544 pci_read_config_word(bridge, pos + 2, &status);
545
546 if (status & 0x8000) {
547 max = PCI_SPEED_133MHz_PCIX_533;
548 } else if (status & 0x4000) {
549 max = PCI_SPEED_133MHz_PCIX_266;
550 } else if (status & 0x0002) {
551 if (((status >> 12) & 0x3) == 2) {
552 max = PCI_SPEED_133MHz_PCIX_ECC;
553 } else {
554 max = PCI_SPEED_133MHz_PCIX;
555 }
556 } else {
557 max = PCI_SPEED_66MHz_PCIX;
558 }
559
560 bus->max_bus_speed = max;
561 bus->cur_bus_speed = pcix_bus_speed[(status >> 6) & 0xf];
562
563 return;
564 }
565
566 pos = pci_find_capability(bridge, PCI_CAP_ID_EXP);
567 if (pos) {
568 u32 linkcap;
569 u16 linksta;
570
571 pci_read_config_dword(bridge, pos + PCI_EXP_LNKCAP, &linkcap);
572 bus->max_bus_speed = pcie_link_speed[linkcap & 0xf];
573
574 pci_read_config_word(bridge, pos + PCI_EXP_LNKSTA, &linksta);
575 pcie_update_link_speed(bus, linksta);
576 }
577}
578
579
398static struct pci_bus *pci_alloc_child_bus(struct pci_bus *parent, 580static struct pci_bus *pci_alloc_child_bus(struct pci_bus *parent,
399 struct pci_dev *bridge, int busnr) 581 struct pci_dev *bridge, int busnr)
400{ 582{
@@ -434,6 +616,8 @@ static struct pci_bus *pci_alloc_child_bus(struct pci_bus *parent,
434 child->self = bridge; 616 child->self = bridge;
435 child->bridge = get_device(&bridge->dev); 617 child->bridge = get_device(&bridge->dev);
436 618
619 pci_set_bus_speed(child);
620
437 /* Set up default resource pointers and names.. */ 621 /* Set up default resource pointers and names.. */
438 for (i = 0; i < PCI_BRIDGE_RESOURCE_NUM; i++) { 622 for (i = 0; i < PCI_BRIDGE_RESOURCE_NUM; i++) {
439 child->resource[i] = &bridge->resource[PCI_BRIDGE_RESOURCES+i]; 623 child->resource[i] = &bridge->resource[PCI_BRIDGE_RESOURCES+i];
@@ -489,16 +673,20 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max,
489 int is_cardbus = (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS); 673 int is_cardbus = (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS);
490 u32 buses, i, j = 0; 674 u32 buses, i, j = 0;
491 u16 bctl; 675 u16 bctl;
676 u8 primary, secondary, subordinate;
492 int broken = 0; 677 int broken = 0;
493 678
494 pci_read_config_dword(dev, PCI_PRIMARY_BUS, &buses); 679 pci_read_config_dword(dev, PCI_PRIMARY_BUS, &buses);
680 primary = buses & 0xFF;
681 secondary = (buses >> 8) & 0xFF;
682 subordinate = (buses >> 16) & 0xFF;
495 683
496 dev_dbg(&dev->dev, "scanning behind bridge, config %06x, pass %d\n", 684 dev_dbg(&dev->dev, "scanning [bus %02x-%02x] behind bridge, pass %d\n",
497 buses & 0xffffff, pass); 685 secondary, subordinate, pass);
498 686
499 /* Check if setup is sensible at all */ 687 /* Check if setup is sensible at all */
500 if (!pass && 688 if (!pass &&
501 ((buses & 0xff) != bus->number || ((buses >> 8) & 0xff) <= bus->number)) { 689 (primary != bus->number || secondary <= bus->number)) {
502 dev_dbg(&dev->dev, "bus configuration invalid, reconfiguring\n"); 690 dev_dbg(&dev->dev, "bus configuration invalid, reconfiguring\n");
503 broken = 1; 691 broken = 1;
504 } 692 }
@@ -509,15 +697,15 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max,
509 pci_write_config_word(dev, PCI_BRIDGE_CONTROL, 697 pci_write_config_word(dev, PCI_BRIDGE_CONTROL,
510 bctl & ~PCI_BRIDGE_CTL_MASTER_ABORT); 698 bctl & ~PCI_BRIDGE_CTL_MASTER_ABORT);
511 699
512 if ((buses & 0xffff00) && !pcibios_assign_all_busses() && !is_cardbus && !broken) { 700 if ((secondary || subordinate) && !pcibios_assign_all_busses() &&
513 unsigned int cmax, busnr; 701 !is_cardbus && !broken) {
702 unsigned int cmax;
514 /* 703 /*
515 * Bus already configured by firmware, process it in the first 704 * Bus already configured by firmware, process it in the first
516 * pass and just note the configuration. 705 * pass and just note the configuration.
517 */ 706 */
518 if (pass) 707 if (pass)
519 goto out; 708 goto out;
520 busnr = (buses >> 8) & 0xFF;
521 709
522 /* 710 /*
523 * If we already got to this bus through a different bridge, 711 * If we already got to this bus through a different bridge,
@@ -526,13 +714,13 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max,
526 * However, we continue to descend down the hierarchy and 714 * However, we continue to descend down the hierarchy and
527 * scan remaining child buses. 715 * scan remaining child buses.
528 */ 716 */
529 child = pci_find_bus(pci_domain_nr(bus), busnr); 717 child = pci_find_bus(pci_domain_nr(bus), secondary);
530 if (!child) { 718 if (!child) {
531 child = pci_add_new_bus(bus, dev, busnr); 719 child = pci_add_new_bus(bus, dev, secondary);
532 if (!child) 720 if (!child)
533 goto out; 721 goto out;
534 child->primary = buses & 0xFF; 722 child->primary = primary;
535 child->subordinate = (buses >> 16) & 0xFF; 723 child->subordinate = subordinate;
536 child->bridge_ctl = bctl; 724 child->bridge_ctl = bctl;
537 } 725 }
538 726
@@ -651,13 +839,14 @@ int __devinit pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max,
651 (child->number > bus->subordinate) || 839 (child->number > bus->subordinate) ||
652 (child->number < bus->number) || 840 (child->number < bus->number) ||
653 (child->subordinate < bus->number)) { 841 (child->subordinate < bus->number)) {
654 pr_debug("PCI: Bus #%02x (-#%02x) is %s " 842 dev_info(&child->dev, "[bus %02x-%02x] %s "
655 "hidden behind%s bridge #%02x (-#%02x)\n", 843 "hidden behind%s bridge %s [bus %02x-%02x]\n",
656 child->number, child->subordinate, 844 child->number, child->subordinate,
657 (bus->number > child->subordinate && 845 (bus->number > child->subordinate &&
658 bus->subordinate < child->number) ? 846 bus->subordinate < child->number) ?
659 "wholly" : "partially", 847 "wholly" : "partially",
660 bus->self->transparent ? " transparent" : "", 848 bus->self->transparent ? " transparent" : "",
849 dev_name(&bus->dev),
661 bus->number, bus->subordinate); 850 bus->number, bus->subordinate);
662 } 851 }
663 bus = bus->parent; 852 bus = bus->parent;
@@ -684,7 +873,7 @@ static void pci_read_irq(struct pci_dev *dev)
684 dev->irq = irq; 873 dev->irq = irq;
685} 874}
686 875
687static void set_pcie_port_type(struct pci_dev *pdev) 876void set_pcie_port_type(struct pci_dev *pdev)
688{ 877{
689 int pos; 878 int pos;
690 u16 reg16; 879 u16 reg16;
@@ -693,17 +882,18 @@ static void set_pcie_port_type(struct pci_dev *pdev)
693 if (!pos) 882 if (!pos)
694 return; 883 return;
695 pdev->is_pcie = 1; 884 pdev->is_pcie = 1;
885 pdev->pcie_cap = pos;
696 pci_read_config_word(pdev, pos + PCI_EXP_FLAGS, &reg16); 886 pci_read_config_word(pdev, pos + PCI_EXP_FLAGS, &reg16);
697 pdev->pcie_type = (reg16 & PCI_EXP_FLAGS_TYPE) >> 4; 887 pdev->pcie_type = (reg16 & PCI_EXP_FLAGS_TYPE) >> 4;
698} 888}
699 889
700static void set_pcie_hotplug_bridge(struct pci_dev *pdev) 890void set_pcie_hotplug_bridge(struct pci_dev *pdev)
701{ 891{
702 int pos; 892 int pos;
703 u16 reg16; 893 u16 reg16;
704 u32 reg32; 894 u32 reg32;
705 895
706 pos = pci_find_capability(pdev, PCI_CAP_ID_EXP); 896 pos = pci_pcie_cap(pdev);
707 if (!pos) 897 if (!pos)
708 return; 898 return;
709 pci_read_config_word(pdev, pos + PCI_EXP_FLAGS, &reg16); 899 pci_read_config_word(pdev, pos + PCI_EXP_FLAGS, &reg16);
@@ -714,6 +904,12 @@ static void set_pcie_hotplug_bridge(struct pci_dev *pdev)
714 pdev->is_hotplug_bridge = 1; 904 pdev->is_hotplug_bridge = 1;
715} 905}
716 906
907static void set_pci_aer_firmware_first(struct pci_dev *pdev)
908{
909 if (acpi_hest_firmware_first_pci(pdev))
910 pdev->aer_firmware_first = 1;
911}
912
717#define LEGACY_IO_RESOURCE (IORESOURCE_IO | IORESOURCE_PCI_FIXED) 913#define LEGACY_IO_RESOURCE (IORESOURCE_IO | IORESOURCE_PCI_FIXED)
718 914
719/** 915/**
@@ -731,6 +927,7 @@ int pci_setup_device(struct pci_dev *dev)
731 u32 class; 927 u32 class;
732 u8 hdr_type; 928 u8 hdr_type;
733 struct pci_slot *slot; 929 struct pci_slot *slot;
930 int pos = 0;
734 931
735 if (pci_read_config_byte(dev, PCI_HEADER_TYPE, &hdr_type)) 932 if (pci_read_config_byte(dev, PCI_HEADER_TYPE, &hdr_type))
736 return -EIO; 933 return -EIO;
@@ -742,6 +939,7 @@ int pci_setup_device(struct pci_dev *dev)
742 dev->multifunction = !!(hdr_type & 0x80); 939 dev->multifunction = !!(hdr_type & 0x80);
743 dev->error_state = pci_channel_io_normal; 940 dev->error_state = pci_channel_io_normal;
744 set_pcie_port_type(dev); 941 set_pcie_port_type(dev);
942 set_pci_aer_firmware_first(dev);
745 943
746 list_for_each_entry(slot, &dev->bus->slots, list) 944 list_for_each_entry(slot, &dev->bus->slots, list)
747 if (PCI_SLOT(dev->devfn) == slot->number) 945 if (PCI_SLOT(dev->devfn) == slot->number)
@@ -822,6 +1020,11 @@ int pci_setup_device(struct pci_dev *dev)
822 dev->transparent = ((dev->class & 0xff) == 1); 1020 dev->transparent = ((dev->class & 0xff) == 1);
823 pci_read_bases(dev, 2, PCI_ROM_ADDRESS1); 1021 pci_read_bases(dev, 2, PCI_ROM_ADDRESS1);
824 set_pcie_hotplug_bridge(dev); 1022 set_pcie_hotplug_bridge(dev);
1023 pos = pci_find_capability(dev, PCI_CAP_ID_SSVID);
1024 if (pos) {
1025 pci_read_config_word(dev, pos + PCI_SSVID_VENDOR_ID, &dev->subsystem_vendor);
1026 pci_read_config_word(dev, pos + PCI_SSVID_DEVICE_ID, &dev->subsystem_device);
1027 }
825 break; 1028 break;
826 1029
827 case PCI_HEADER_TYPE_CARDBUS: /* CardBus bridge header */ 1030 case PCI_HEADER_TYPE_CARDBUS: /* CardBus bridge header */
@@ -907,7 +1110,7 @@ int pci_cfg_space_size(struct pci_dev *dev)
907 if (class == PCI_CLASS_BRIDGE_HOST) 1110 if (class == PCI_CLASS_BRIDGE_HOST)
908 return pci_cfg_space_size_ext(dev); 1111 return pci_cfg_space_size_ext(dev);
909 1112
910 pos = pci_find_capability(dev, PCI_CAP_ID_EXP); 1113 pos = pci_pcie_cap(dev);
911 if (!pos) { 1114 if (!pos) {
912 pos = pci_find_capability(dev, PCI_CAP_ID_PCIX); 1115 pos = pci_find_capability(dev, PCI_CAP_ID_PCIX);
913 if (!pos) 1116 if (!pos)
@@ -1014,6 +1217,9 @@ static void pci_init_capabilities(struct pci_dev *dev)
1014 1217
1015 /* Single Root I/O Virtualization */ 1218 /* Single Root I/O Virtualization */
1016 pci_iov_init(dev); 1219 pci_iov_init(dev);
1220
1221 /* Enable ACS P2P upstream forwarding */
1222 pci_enable_acs(dev);
1017} 1223}
1018 1224
1019void pci_device_add(struct pci_dev *dev, struct pci_bus *bus) 1225void pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
@@ -1067,6 +1273,45 @@ struct pci_dev *__ref pci_scan_single_device(struct pci_bus *bus, int devfn)
1067} 1273}
1068EXPORT_SYMBOL(pci_scan_single_device); 1274EXPORT_SYMBOL(pci_scan_single_device);
1069 1275
1276static unsigned next_ari_fn(struct pci_dev *dev, unsigned fn)
1277{
1278 u16 cap;
1279 unsigned pos, next_fn;
1280
1281 if (!dev)
1282 return 0;
1283
1284 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ARI);
1285 if (!pos)
1286 return 0;
1287 pci_read_config_word(dev, pos + 4, &cap);
1288 next_fn = cap >> 8;
1289 if (next_fn <= fn)
1290 return 0;
1291 return next_fn;
1292}
1293
1294static unsigned next_trad_fn(struct pci_dev *dev, unsigned fn)
1295{
1296 return (fn + 1) % 8;
1297}
1298
1299static unsigned no_next_fn(struct pci_dev *dev, unsigned fn)
1300{
1301 return 0;
1302}
1303
1304static int only_one_child(struct pci_bus *bus)
1305{
1306 struct pci_dev *parent = bus->self;
1307 if (!parent || !pci_is_pcie(parent))
1308 return 0;
1309 if (parent->pcie_type == PCI_EXP_TYPE_ROOT_PORT ||
1310 parent->pcie_type == PCI_EXP_TYPE_DOWNSTREAM)
1311 return 1;
1312 return 0;
1313}
1314
1070/** 1315/**
1071 * pci_scan_slot - scan a PCI slot on a bus for devices. 1316 * pci_scan_slot - scan a PCI slot on a bus for devices.
1072 * @bus: PCI bus to scan 1317 * @bus: PCI bus to scan
@@ -1080,21 +1325,30 @@ EXPORT_SYMBOL(pci_scan_single_device);
1080 */ 1325 */
1081int pci_scan_slot(struct pci_bus *bus, int devfn) 1326int pci_scan_slot(struct pci_bus *bus, int devfn)
1082{ 1327{
1083 int fn, nr = 0; 1328 unsigned fn, nr = 0;
1084 struct pci_dev *dev; 1329 struct pci_dev *dev;
1330 unsigned (*next_fn)(struct pci_dev *, unsigned) = no_next_fn;
1331
1332 if (only_one_child(bus) && (devfn > 0))
1333 return 0; /* Already scanned the entire slot */
1085 1334
1086 dev = pci_scan_single_device(bus, devfn); 1335 dev = pci_scan_single_device(bus, devfn);
1087 if (dev && !dev->is_added) /* new device? */ 1336 if (!dev)
1337 return 0;
1338 if (!dev->is_added)
1088 nr++; 1339 nr++;
1089 1340
1090 if (dev && dev->multifunction) { 1341 if (pci_ari_enabled(bus))
1091 for (fn = 1; fn < 8; fn++) { 1342 next_fn = next_ari_fn;
1092 dev = pci_scan_single_device(bus, devfn + fn); 1343 else if (dev->multifunction)
1093 if (dev) { 1344 next_fn = next_trad_fn;
1094 if (!dev->is_added) 1345
1095 nr++; 1346 for (fn = next_fn(dev, 0); fn > 0; fn = next_fn(dev, fn)) {
1096 dev->multifunction = 1; 1347 dev = pci_scan_single_device(bus, devfn + fn);
1097 } 1348 if (dev) {
1349 if (!dev->is_added)
1350 nr++;
1351 dev->multifunction = 1;
1098 } 1352 }
1099 } 1353 }
1100 1354
@@ -1110,7 +1364,7 @@ unsigned int __devinit pci_scan_child_bus(struct pci_bus *bus)
1110 unsigned int devfn, pass, max = bus->secondary; 1364 unsigned int devfn, pass, max = bus->secondary;
1111 struct pci_dev *dev; 1365 struct pci_dev *dev;
1112 1366
1113 pr_debug("PCI: Scanning bus %04x:%02x\n", pci_domain_nr(bus), bus->number); 1367 dev_dbg(&bus->dev, "scanning bus\n");
1114 1368
1115 /* Go find them, Rover! */ 1369 /* Go find them, Rover! */
1116 for (devfn = 0; devfn < 0x100; devfn += 8) 1370 for (devfn = 0; devfn < 0x100; devfn += 8)
@@ -1124,8 +1378,7 @@ unsigned int __devinit pci_scan_child_bus(struct pci_bus *bus)
1124 * all PCI-to-PCI bridges on this bus. 1378 * all PCI-to-PCI bridges on this bus.
1125 */ 1379 */
1126 if (!bus->is_added) { 1380 if (!bus->is_added) {
1127 pr_debug("PCI: Fixups for bus %04x:%02x\n", 1381 dev_dbg(&bus->dev, "fixups for bus\n");
1128 pci_domain_nr(bus), bus->number);
1129 pcibios_fixup_bus(bus); 1382 pcibios_fixup_bus(bus);
1130 if (pci_is_root_bus(bus)) 1383 if (pci_is_root_bus(bus))
1131 bus->is_added = 1; 1384 bus->is_added = 1;
@@ -1145,8 +1398,7 @@ unsigned int __devinit pci_scan_child_bus(struct pci_bus *bus)
1145 * 1398 *
1146 * Return how far we've got finding sub-buses. 1399 * Return how far we've got finding sub-buses.
1147 */ 1400 */
1148 pr_debug("PCI: Bus scan for %04x:%02x returning with max=%02x\n", 1401 dev_dbg(&bus->dev, "bus scan returning with max=%02x\n", max);
1149 pci_domain_nr(bus), bus->number, max);
1150 return max; 1402 return max;
1151} 1403}
1152 1404
@@ -1154,7 +1406,7 @@ struct pci_bus * pci_create_bus(struct device *parent,
1154 int bus, struct pci_ops *ops, void *sysdata) 1406 int bus, struct pci_ops *ops, void *sysdata)
1155{ 1407{
1156 int error; 1408 int error;
1157 struct pci_bus *b; 1409 struct pci_bus *b, *b2;
1158 struct device *dev; 1410 struct device *dev;
1159 1411
1160 b = pci_alloc_bus(); 1412 b = pci_alloc_bus();
@@ -1170,9 +1422,10 @@ struct pci_bus * pci_create_bus(struct device *parent,
1170 b->sysdata = sysdata; 1422 b->sysdata = sysdata;
1171 b->ops = ops; 1423 b->ops = ops;
1172 1424
1173 if (pci_find_bus(pci_domain_nr(b), bus)) { 1425 b2 = pci_find_bus(pci_domain_nr(b), bus);
1426 if (b2) {
1174 /* If we already got to this bus through a different bridge, ignore it */ 1427 /* If we already got to this bus through a different bridge, ignore it */
1175 pr_debug("PCI: Bus %04x:%02x already known\n", pci_domain_nr(b), bus); 1428 dev_dbg(&b2->dev, "bus already known\n");
1176 goto err_out; 1429 goto err_out;
1177 } 1430 }
1178 1431
@@ -1187,6 +1440,7 @@ struct pci_bus * pci_create_bus(struct device *parent,
1187 if (error) 1440 if (error)
1188 goto dev_reg_err; 1441 goto dev_reg_err;
1189 b->bridge = get_device(dev); 1442 b->bridge = get_device(dev);
1443 device_enable_async_suspend(b->bridge);
1190 1444
1191 if (!parent) 1445 if (!parent)
1192 set_dev_node(b->bridge, pcibus_to_node(b)); 1446 set_dev_node(b->bridge, pcibus_to_node(b));