.. | .. |
---|
7 | 7 | #include <linux/delay.h> |
---|
8 | 8 | #include <linux/init.h> |
---|
9 | 9 | #include <linux/pci.h> |
---|
| 10 | +#include <linux/msi.h> |
---|
10 | 11 | #include <linux/of_device.h> |
---|
11 | 12 | #include <linux/of_pci.h> |
---|
12 | 13 | #include <linux/pci_hotplug.h> |
---|
.. | .. |
---|
64 | 65 | return &r->res; |
---|
65 | 66 | } |
---|
66 | 67 | |
---|
67 | | -static int find_anything(struct device *dev, void *data) |
---|
68 | | -{ |
---|
69 | | - return 1; |
---|
70 | | -} |
---|
71 | | - |
---|
72 | 68 | /* |
---|
73 | 69 | * Some device drivers need know if PCI is initiated. |
---|
74 | 70 | * Basically, we think PCI is not initiated when there |
---|
.. | .. |
---|
79 | 75 | struct device *dev; |
---|
80 | 76 | int no_devices; |
---|
81 | 77 | |
---|
82 | | - dev = bus_find_device(&pci_bus_type, NULL, NULL, find_anything); |
---|
| 78 | + dev = bus_find_next_device(&pci_bus_type, NULL); |
---|
83 | 79 | no_devices = (dev == NULL); |
---|
84 | 80 | put_device(dev); |
---|
85 | 81 | return no_devices; |
---|
.. | .. |
---|
121 | 117 | * Get the lowest of them to find the decode size, and from that |
---|
122 | 118 | * the extent. |
---|
123 | 119 | */ |
---|
124 | | - size = (size & ~(size-1)) - 1; |
---|
| 120 | + size = size & ~(size-1); |
---|
125 | 121 | |
---|
126 | 122 | /* |
---|
127 | 123 | * base == maxbase can be valid only if the BAR has already been |
---|
128 | 124 | * programmed with all 1s. |
---|
129 | 125 | */ |
---|
130 | | - if (base == maxbase && ((base | size) & mask) != mask) |
---|
| 126 | + if (base == maxbase && ((base | (size - 1)) & mask) != mask) |
---|
131 | 127 | return 0; |
---|
132 | 128 | |
---|
133 | 129 | return size; |
---|
.. | .. |
---|
278 | 274 | /* Above 32-bit boundary; try to reallocate */ |
---|
279 | 275 | res->flags |= IORESOURCE_UNSET; |
---|
280 | 276 | res->start = 0; |
---|
281 | | - res->end = sz64; |
---|
| 277 | + res->end = sz64 - 1; |
---|
282 | 278 | pci_info(dev, "reg 0x%x: can't handle BAR above 4GB (bus address %#010llx)\n", |
---|
283 | 279 | pos, (unsigned long long)l64); |
---|
284 | 280 | goto out; |
---|
.. | .. |
---|
286 | 282 | } |
---|
287 | 283 | |
---|
288 | 284 | region.start = l64; |
---|
289 | | - region.end = l64 + sz64; |
---|
| 285 | + region.end = l64 + sz64 - 1; |
---|
290 | 286 | |
---|
291 | 287 | pcibios_bus_to_resource(dev->bus, res, ®ion); |
---|
292 | 288 | pcibios_resource_to_bus(dev->bus, &inverted_region, res); |
---|
.. | .. |
---|
317 | 313 | res->flags = 0; |
---|
318 | 314 | out: |
---|
319 | 315 | if (res->flags) |
---|
320 | | - pci_printk(KERN_DEBUG, dev, "reg 0x%x: %pR\n", pos, res); |
---|
| 316 | + pci_info(dev, "reg 0x%x: %pR\n", pos, res); |
---|
321 | 317 | |
---|
322 | 318 | return (res->flags & IORESOURCE_MEM_64) ? 1 : 0; |
---|
323 | 319 | } |
---|
.. | .. |
---|
345 | 341 | res->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH | |
---|
346 | 342 | IORESOURCE_READONLY | IORESOURCE_SIZEALIGN; |
---|
347 | 343 | __pci_read_base(dev, pci_bar_mem32, res, rom); |
---|
| 344 | + } |
---|
| 345 | +} |
---|
| 346 | + |
---|
| 347 | +static void pci_read_bridge_windows(struct pci_dev *bridge) |
---|
| 348 | +{ |
---|
| 349 | + u16 io; |
---|
| 350 | + u32 pmem, tmp; |
---|
| 351 | + |
---|
| 352 | + pci_read_config_word(bridge, PCI_IO_BASE, &io); |
---|
| 353 | + if (!io) { |
---|
| 354 | + pci_write_config_word(bridge, PCI_IO_BASE, 0xe0f0); |
---|
| 355 | + pci_read_config_word(bridge, PCI_IO_BASE, &io); |
---|
| 356 | + pci_write_config_word(bridge, PCI_IO_BASE, 0x0); |
---|
| 357 | + } |
---|
| 358 | + if (io) |
---|
| 359 | + bridge->io_window = 1; |
---|
| 360 | + |
---|
| 361 | + /* |
---|
| 362 | + * DECchip 21050 pass 2 errata: the bridge may miss an address |
---|
| 363 | + * disconnect boundary by one PCI data phase. Workaround: do not |
---|
| 364 | + * use prefetching on this device. |
---|
| 365 | + */ |
---|
| 366 | + if (bridge->vendor == PCI_VENDOR_ID_DEC && bridge->device == 0x0001) |
---|
| 367 | + return; |
---|
| 368 | + |
---|
| 369 | + pci_read_config_dword(bridge, PCI_PREF_MEMORY_BASE, &pmem); |
---|
| 370 | + if (!pmem) { |
---|
| 371 | + pci_write_config_dword(bridge, PCI_PREF_MEMORY_BASE, |
---|
| 372 | + 0xffe0fff0); |
---|
| 373 | + pci_read_config_dword(bridge, PCI_PREF_MEMORY_BASE, &pmem); |
---|
| 374 | + pci_write_config_dword(bridge, PCI_PREF_MEMORY_BASE, 0x0); |
---|
| 375 | + } |
---|
| 376 | + if (!pmem) |
---|
| 377 | + return; |
---|
| 378 | + |
---|
| 379 | + bridge->pref_window = 1; |
---|
| 380 | + |
---|
| 381 | + if ((pmem & PCI_PREF_RANGE_TYPE_MASK) == PCI_PREF_RANGE_TYPE_64) { |
---|
| 382 | + |
---|
| 383 | + /* |
---|
| 384 | + * Bridge claims to have a 64-bit prefetchable memory |
---|
| 385 | + * window; verify that the upper bits are actually |
---|
| 386 | + * writable. |
---|
| 387 | + */ |
---|
| 388 | + pci_read_config_dword(bridge, PCI_PREF_BASE_UPPER32, &pmem); |
---|
| 389 | + pci_write_config_dword(bridge, PCI_PREF_BASE_UPPER32, |
---|
| 390 | + 0xffffffff); |
---|
| 391 | + pci_read_config_dword(bridge, PCI_PREF_BASE_UPPER32, &tmp); |
---|
| 392 | + pci_write_config_dword(bridge, PCI_PREF_BASE_UPPER32, pmem); |
---|
| 393 | + if (tmp) |
---|
| 394 | + bridge->pref_64_window = 1; |
---|
348 | 395 | } |
---|
349 | 396 | } |
---|
350 | 397 | |
---|
.. | .. |
---|
384 | 431 | region.start = base; |
---|
385 | 432 | region.end = limit + io_granularity - 1; |
---|
386 | 433 | pcibios_bus_to_resource(dev->bus, res, ®ion); |
---|
387 | | - pci_printk(KERN_DEBUG, dev, " bridge window %pR\n", res); |
---|
| 434 | + pci_info(dev, " bridge window %pR\n", res); |
---|
388 | 435 | } |
---|
389 | 436 | } |
---|
390 | 437 | |
---|
.. | .. |
---|
406 | 453 | region.start = base; |
---|
407 | 454 | region.end = limit + 0xfffff; |
---|
408 | 455 | pcibios_bus_to_resource(dev->bus, res, ®ion); |
---|
409 | | - pci_printk(KERN_DEBUG, dev, " bridge window %pR\n", res); |
---|
| 456 | + pci_info(dev, " bridge window %pR\n", res); |
---|
410 | 457 | } |
---|
411 | 458 | } |
---|
412 | 459 | |
---|
.. | .. |
---|
459 | 506 | region.start = base; |
---|
460 | 507 | region.end = limit + 0xfffff; |
---|
461 | 508 | pcibios_bus_to_resource(dev->bus, res, ®ion); |
---|
462 | | - pci_printk(KERN_DEBUG, dev, " bridge window %pR\n", res); |
---|
| 509 | + pci_info(dev, " bridge window %pR\n", res); |
---|
463 | 510 | } |
---|
464 | 511 | } |
---|
465 | 512 | |
---|
.. | .. |
---|
489 | 536 | if (res && res->flags) { |
---|
490 | 537 | pci_bus_add_resource(child, res, |
---|
491 | 538 | PCI_SUBTRACTIVE_DECODE); |
---|
492 | | - pci_printk(KERN_DEBUG, dev, |
---|
493 | | - " bridge window %pR (subtractive decode)\n", |
---|
| 539 | + pci_info(dev, " bridge window %pR (subtractive decode)\n", |
---|
494 | 540 | res); |
---|
495 | 541 | } |
---|
496 | 542 | } |
---|
.. | .. |
---|
519 | 565 | return b; |
---|
520 | 566 | } |
---|
521 | 567 | |
---|
522 | | -static void devm_pci_release_host_bridge_dev(struct device *dev) |
---|
| 568 | +static void pci_release_host_bridge_dev(struct device *dev) |
---|
523 | 569 | { |
---|
524 | 570 | struct pci_host_bridge *bridge = to_pci_host_bridge(dev); |
---|
525 | 571 | |
---|
.. | .. |
---|
527 | 573 | bridge->release_fn(bridge); |
---|
528 | 574 | |
---|
529 | 575 | pci_free_resource_list(&bridge->windows); |
---|
530 | | -} |
---|
531 | | - |
---|
532 | | -static void pci_release_host_bridge_dev(struct device *dev) |
---|
533 | | -{ |
---|
534 | | - devm_pci_release_host_bridge_dev(dev); |
---|
535 | | - kfree(to_pci_host_bridge(dev)); |
---|
| 576 | + pci_free_resource_list(&bridge->dma_ranges); |
---|
| 577 | + kfree(bridge); |
---|
536 | 578 | } |
---|
537 | 579 | |
---|
538 | 580 | static void pci_init_host_bridge(struct pci_host_bridge *bridge) |
---|
539 | 581 | { |
---|
540 | 582 | INIT_LIST_HEAD(&bridge->windows); |
---|
| 583 | + INIT_LIST_HEAD(&bridge->dma_ranges); |
---|
541 | 584 | |
---|
542 | 585 | /* |
---|
543 | 586 | * We assume we can manage these PCIe features. Some systems may |
---|
.. | .. |
---|
550 | 593 | bridge->native_shpc_hotplug = 1; |
---|
551 | 594 | bridge->native_pme = 1; |
---|
552 | 595 | bridge->native_ltr = 1; |
---|
| 596 | + bridge->native_dpc = 1; |
---|
| 597 | + |
---|
| 598 | + device_initialize(&bridge->dev); |
---|
553 | 599 | } |
---|
554 | 600 | |
---|
555 | 601 | struct pci_host_bridge *pci_alloc_host_bridge(size_t priv) |
---|
.. | .. |
---|
567 | 613 | } |
---|
568 | 614 | EXPORT_SYMBOL(pci_alloc_host_bridge); |
---|
569 | 615 | |
---|
| 616 | +static void devm_pci_alloc_host_bridge_release(void *data) |
---|
| 617 | +{ |
---|
| 618 | + pci_free_host_bridge(data); |
---|
| 619 | +} |
---|
| 620 | + |
---|
570 | 621 | struct pci_host_bridge *devm_pci_alloc_host_bridge(struct device *dev, |
---|
571 | 622 | size_t priv) |
---|
572 | 623 | { |
---|
| 624 | + int ret; |
---|
573 | 625 | struct pci_host_bridge *bridge; |
---|
574 | 626 | |
---|
575 | | - bridge = devm_kzalloc(dev, sizeof(*bridge) + priv, GFP_KERNEL); |
---|
| 627 | + bridge = pci_alloc_host_bridge(priv); |
---|
576 | 628 | if (!bridge) |
---|
577 | 629 | return NULL; |
---|
578 | 630 | |
---|
579 | | - pci_init_host_bridge(bridge); |
---|
580 | | - bridge->dev.release = devm_pci_release_host_bridge_dev; |
---|
| 631 | + bridge->dev.parent = dev; |
---|
| 632 | + |
---|
| 633 | + ret = devm_add_action_or_reset(dev, devm_pci_alloc_host_bridge_release, |
---|
| 634 | + bridge); |
---|
| 635 | + if (ret) |
---|
| 636 | + return NULL; |
---|
| 637 | + |
---|
| 638 | + ret = devm_of_pci_bridge_init(dev, bridge); |
---|
| 639 | + if (ret) |
---|
| 640 | + return NULL; |
---|
581 | 641 | |
---|
582 | 642 | return bridge; |
---|
583 | 643 | } |
---|
.. | .. |
---|
585 | 645 | |
---|
586 | 646 | void pci_free_host_bridge(struct pci_host_bridge *bridge) |
---|
587 | 647 | { |
---|
588 | | - pci_free_resource_list(&bridge->windows); |
---|
589 | | - |
---|
590 | | - kfree(bridge); |
---|
| 648 | + put_device(&bridge->dev); |
---|
591 | 649 | } |
---|
592 | 650 | EXPORT_SYMBOL(pci_free_host_bridge); |
---|
593 | 651 | |
---|
| 652 | +/* Indexed by PCI_X_SSTATUS_FREQ (secondary bus mode and frequency) */ |
---|
594 | 653 | static const unsigned char pcix_bus_speed[] = { |
---|
595 | 654 | PCI_SPEED_UNKNOWN, /* 0 */ |
---|
596 | 655 | PCI_SPEED_66MHz_PCIX, /* 1 */ |
---|
.. | .. |
---|
610 | 669 | PCI_SPEED_133MHz_PCIX_533 /* F */ |
---|
611 | 670 | }; |
---|
612 | 671 | |
---|
| 672 | +/* Indexed by PCI_EXP_LNKCAP_SLS, PCI_EXP_LNKSTA_CLS */ |
---|
613 | 673 | const unsigned char pcie_link_speed[] = { |
---|
614 | 674 | PCI_SPEED_UNKNOWN, /* 0 */ |
---|
615 | 675 | PCIE_SPEED_2_5GT, /* 1 */ |
---|
616 | 676 | PCIE_SPEED_5_0GT, /* 2 */ |
---|
617 | 677 | PCIE_SPEED_8_0GT, /* 3 */ |
---|
618 | 678 | PCIE_SPEED_16_0GT, /* 4 */ |
---|
619 | | - PCI_SPEED_UNKNOWN, /* 5 */ |
---|
| 679 | + PCIE_SPEED_32_0GT, /* 5 */ |
---|
620 | 680 | PCI_SPEED_UNKNOWN, /* 6 */ |
---|
621 | 681 | PCI_SPEED_UNKNOWN, /* 7 */ |
---|
622 | 682 | PCI_SPEED_UNKNOWN, /* 8 */ |
---|
.. | .. |
---|
628 | 688 | PCI_SPEED_UNKNOWN, /* E */ |
---|
629 | 689 | PCI_SPEED_UNKNOWN /* F */ |
---|
630 | 690 | }; |
---|
| 691 | +EXPORT_SYMBOL_GPL(pcie_link_speed); |
---|
| 692 | + |
---|
| 693 | +const char *pci_speed_string(enum pci_bus_speed speed) |
---|
| 694 | +{ |
---|
| 695 | + /* Indexed by the pci_bus_speed enum */ |
---|
| 696 | + static const char *speed_strings[] = { |
---|
| 697 | + "33 MHz PCI", /* 0x00 */ |
---|
| 698 | + "66 MHz PCI", /* 0x01 */ |
---|
| 699 | + "66 MHz PCI-X", /* 0x02 */ |
---|
| 700 | + "100 MHz PCI-X", /* 0x03 */ |
---|
| 701 | + "133 MHz PCI-X", /* 0x04 */ |
---|
| 702 | + NULL, /* 0x05 */ |
---|
| 703 | + NULL, /* 0x06 */ |
---|
| 704 | + NULL, /* 0x07 */ |
---|
| 705 | + NULL, /* 0x08 */ |
---|
| 706 | + "66 MHz PCI-X 266", /* 0x09 */ |
---|
| 707 | + "100 MHz PCI-X 266", /* 0x0a */ |
---|
| 708 | + "133 MHz PCI-X 266", /* 0x0b */ |
---|
| 709 | + "Unknown AGP", /* 0x0c */ |
---|
| 710 | + "1x AGP", /* 0x0d */ |
---|
| 711 | + "2x AGP", /* 0x0e */ |
---|
| 712 | + "4x AGP", /* 0x0f */ |
---|
| 713 | + "8x AGP", /* 0x10 */ |
---|
| 714 | + "66 MHz PCI-X 533", /* 0x11 */ |
---|
| 715 | + "100 MHz PCI-X 533", /* 0x12 */ |
---|
| 716 | + "133 MHz PCI-X 533", /* 0x13 */ |
---|
| 717 | + "2.5 GT/s PCIe", /* 0x14 */ |
---|
| 718 | + "5.0 GT/s PCIe", /* 0x15 */ |
---|
| 719 | + "8.0 GT/s PCIe", /* 0x16 */ |
---|
| 720 | + "16.0 GT/s PCIe", /* 0x17 */ |
---|
| 721 | + "32.0 GT/s PCIe", /* 0x18 */ |
---|
| 722 | + }; |
---|
| 723 | + |
---|
| 724 | + if (speed < ARRAY_SIZE(speed_strings)) |
---|
| 725 | + return speed_strings[speed]; |
---|
| 726 | + return "Unknown"; |
---|
| 727 | +} |
---|
| 728 | +EXPORT_SYMBOL_GPL(pci_speed_string); |
---|
631 | 729 | |
---|
632 | 730 | void pcie_update_link_speed(struct pci_bus *bus, u16 linksta) |
---|
633 | 731 | { |
---|
.. | .. |
---|
718 | 816 | |
---|
719 | 817 | pcie_capability_read_dword(bridge, PCI_EXP_LNKCAP, &linkcap); |
---|
720 | 818 | bus->max_bus_speed = pcie_link_speed[linkcap & PCI_EXP_LNKCAP_SLS]; |
---|
| 819 | + bridge->link_active_reporting = !!(linkcap & PCI_EXP_LNKCAP_DLLLARC); |
---|
721 | 820 | |
---|
722 | 821 | pcie_capability_read_word(bridge, PCI_EXP_LNKSTA, &linksta); |
---|
723 | 822 | pcie_update_link_speed(bus, linksta); |
---|
.. | .. |
---|
817 | 916 | if (err) |
---|
818 | 917 | goto free; |
---|
819 | 918 | |
---|
820 | | - err = device_register(&bridge->dev); |
---|
| 919 | + err = device_add(&bridge->dev); |
---|
821 | 920 | if (err) { |
---|
822 | 921 | put_device(&bridge->dev); |
---|
823 | 922 | goto free; |
---|
.. | .. |
---|
842 | 941 | |
---|
843 | 942 | pcibios_add_bus(bus); |
---|
844 | 943 | |
---|
| 944 | + if (bus->ops->add_bus) { |
---|
| 945 | + err = bus->ops->add_bus(bus); |
---|
| 946 | + if (WARN_ON(err < 0)) |
---|
| 947 | + dev_err(&bus->dev, "failed to add bus: %d\n", err); |
---|
| 948 | + } |
---|
| 949 | + |
---|
845 | 950 | /* Create legacy_io and legacy_mem files for this bus */ |
---|
846 | 951 | pci_create_legacy_files(bus); |
---|
847 | 952 | |
---|
.. | .. |
---|
849 | 954 | dev_info(parent, "PCI host bridge to bus %s\n", name); |
---|
850 | 955 | else |
---|
851 | 956 | pr_info("PCI host bridge to bus %s\n", name); |
---|
| 957 | + |
---|
| 958 | + if (nr_node_ids > 1 && pcibus_to_node(bus) == NUMA_NO_NODE) |
---|
| 959 | + dev_warn(&bus->dev, "Unknown NUMA node; performance will be reduced\n"); |
---|
852 | 960 | |
---|
853 | 961 | /* Add initial resources to the bus */ |
---|
854 | 962 | resource_list_for_each_entry_safe(window, n, &resources) { |
---|
.. | .. |
---|
884 | 992 | |
---|
885 | 993 | unregister: |
---|
886 | 994 | put_device(&bridge->dev); |
---|
887 | | - device_unregister(&bridge->dev); |
---|
| 995 | + device_del(&bridge->dev); |
---|
888 | 996 | |
---|
889 | 997 | free: |
---|
890 | 998 | kfree(bus); |
---|
.. | .. |
---|
934 | 1042 | struct pci_dev *bridge, int busnr) |
---|
935 | 1043 | { |
---|
936 | 1044 | struct pci_bus *child; |
---|
| 1045 | + struct pci_host_bridge *host; |
---|
937 | 1046 | int i; |
---|
938 | 1047 | int ret; |
---|
939 | 1048 | |
---|
.. | .. |
---|
943 | 1052 | return NULL; |
---|
944 | 1053 | |
---|
945 | 1054 | child->parent = parent; |
---|
946 | | - child->ops = parent->ops; |
---|
947 | 1055 | child->msi = parent->msi; |
---|
948 | 1056 | child->sysdata = parent->sysdata; |
---|
949 | 1057 | child->bus_flags = parent->bus_flags; |
---|
| 1058 | + |
---|
| 1059 | + host = pci_find_host_bridge(parent); |
---|
| 1060 | + if (host->child_ops) |
---|
| 1061 | + child->ops = host->child_ops; |
---|
| 1062 | + else |
---|
| 1063 | + child->ops = parent->ops; |
---|
950 | 1064 | |
---|
951 | 1065 | /* |
---|
952 | 1066 | * Initialize some portions of the bus device, but don't register |
---|
.. | .. |
---|
1035 | 1149 | |
---|
1036 | 1150 | static unsigned int pci_scan_child_bus_extend(struct pci_bus *bus, |
---|
1037 | 1151 | unsigned int available_buses); |
---|
| 1152 | +/** |
---|
| 1153 | + * pci_ea_fixed_busnrs() - Read fixed Secondary and Subordinate bus |
---|
| 1154 | + * numbers from EA capability. |
---|
| 1155 | + * @dev: Bridge |
---|
| 1156 | + * @sec: updated with secondary bus number from EA |
---|
| 1157 | + * @sub: updated with subordinate bus number from EA |
---|
| 1158 | + * |
---|
| 1159 | + * If @dev is a bridge with EA capability that specifies valid secondary |
---|
| 1160 | + * and subordinate bus numbers, return true with the bus numbers in @sec |
---|
| 1161 | + * and @sub. Otherwise return false. |
---|
| 1162 | + */ |
---|
| 1163 | +static bool pci_ea_fixed_busnrs(struct pci_dev *dev, u8 *sec, u8 *sub) |
---|
| 1164 | +{ |
---|
| 1165 | + int ea, offset; |
---|
| 1166 | + u32 dw; |
---|
| 1167 | + u8 ea_sec, ea_sub; |
---|
| 1168 | + |
---|
| 1169 | + if (dev->hdr_type != PCI_HEADER_TYPE_BRIDGE) |
---|
| 1170 | + return false; |
---|
| 1171 | + |
---|
| 1172 | + /* find PCI EA capability in list */ |
---|
| 1173 | + ea = pci_find_capability(dev, PCI_CAP_ID_EA); |
---|
| 1174 | + if (!ea) |
---|
| 1175 | + return false; |
---|
| 1176 | + |
---|
| 1177 | + offset = ea + PCI_EA_FIRST_ENT; |
---|
| 1178 | + pci_read_config_dword(dev, offset, &dw); |
---|
| 1179 | + ea_sec = dw & PCI_EA_SEC_BUS_MASK; |
---|
| 1180 | + ea_sub = (dw & PCI_EA_SUB_BUS_MASK) >> PCI_EA_SUB_BUS_SHIFT; |
---|
| 1181 | + if (ea_sec == 0 || ea_sub < ea_sec) |
---|
| 1182 | + return false; |
---|
| 1183 | + |
---|
| 1184 | + *sec = ea_sec; |
---|
| 1185 | + *sub = ea_sub; |
---|
| 1186 | + return true; |
---|
| 1187 | +} |
---|
1038 | 1188 | |
---|
1039 | 1189 | /* |
---|
1040 | 1190 | * pci_scan_bridge_extend() - Scan buses behind a bridge |
---|
.. | .. |
---|
1069 | 1219 | u16 bctl; |
---|
1070 | 1220 | u8 primary, secondary, subordinate; |
---|
1071 | 1221 | int broken = 0; |
---|
| 1222 | + bool fixed_buses; |
---|
| 1223 | + u8 fixed_sec, fixed_sub; |
---|
| 1224 | + int next_busnr; |
---|
1072 | 1225 | |
---|
1073 | 1226 | /* |
---|
1074 | 1227 | * Make sure the bridge is powered on to be able to access config |
---|
.. | .. |
---|
1168 | 1321 | /* Clear errors */ |
---|
1169 | 1322 | pci_write_config_word(dev, PCI_STATUS, 0xffff); |
---|
1170 | 1323 | |
---|
| 1324 | + /* Read bus numbers from EA Capability (if present) */ |
---|
| 1325 | + fixed_buses = pci_ea_fixed_busnrs(dev, &fixed_sec, &fixed_sub); |
---|
| 1326 | + if (fixed_buses) |
---|
| 1327 | + next_busnr = fixed_sec; |
---|
| 1328 | + else |
---|
| 1329 | + next_busnr = max + 1; |
---|
| 1330 | + |
---|
1171 | 1331 | /* |
---|
1172 | 1332 | * Prevent assigning a bus number that already exists. |
---|
1173 | 1333 | * This can happen when a bridge is hot-plugged, so in this |
---|
1174 | 1334 | * case we only re-scan this bus. |
---|
1175 | 1335 | */ |
---|
1176 | | - child = pci_find_bus(pci_domain_nr(bus), max+1); |
---|
| 1336 | + child = pci_find_bus(pci_domain_nr(bus), next_busnr); |
---|
1177 | 1337 | if (!child) { |
---|
1178 | | - child = pci_add_new_bus(bus, dev, max+1); |
---|
| 1338 | + child = pci_add_new_bus(bus, dev, next_busnr); |
---|
1179 | 1339 | if (!child) |
---|
1180 | 1340 | goto out; |
---|
1181 | | - pci_bus_insert_busn_res(child, max+1, |
---|
| 1341 | + pci_bus_insert_busn_res(child, next_busnr, |
---|
1182 | 1342 | bus->busn_res.end); |
---|
1183 | 1343 | } |
---|
1184 | 1344 | max++; |
---|
.. | .. |
---|
1239 | 1399 | max += i; |
---|
1240 | 1400 | } |
---|
1241 | 1401 | |
---|
1242 | | - /* Set subordinate bus number to its real value */ |
---|
| 1402 | + /* |
---|
| 1403 | + * Set subordinate bus number to its real value. |
---|
| 1404 | + * If fixed subordinate bus number exists from EA |
---|
| 1405 | + * capability then use it. |
---|
| 1406 | + */ |
---|
| 1407 | + if (fixed_buses) |
---|
| 1408 | + max = fixed_sub; |
---|
1243 | 1409 | pci_bus_update_busn_res_end(child, max); |
---|
1244 | 1410 | pci_write_config_byte(dev, PCI_SUBORDINATE_BUS, max); |
---|
1245 | 1411 | } |
---|
.. | .. |
---|
1333 | 1499 | pci_read_config_word(pdev, pos + PCI_EXP_DEVCAP, ®16); |
---|
1334 | 1500 | pdev->pcie_mpss = reg16 & PCI_EXP_DEVCAP_PAYLOAD; |
---|
1335 | 1501 | |
---|
| 1502 | + parent = pci_upstream_bridge(pdev); |
---|
| 1503 | + if (!parent) |
---|
| 1504 | + return; |
---|
| 1505 | + |
---|
1336 | 1506 | /* |
---|
1337 | | - * A Root Port or a PCI-to-PCIe bridge is always the upstream end |
---|
1338 | | - * of a Link. No PCIe component has two Links. Two Links are |
---|
1339 | | - * connected by a Switch that has a Port on each Link and internal |
---|
1340 | | - * logic to connect the two Ports. |
---|
| 1507 | + * Some systems do not identify their upstream/downstream ports |
---|
| 1508 | + * correctly so detect impossible configurations here and correct |
---|
| 1509 | + * the port type accordingly. |
---|
1341 | 1510 | */ |
---|
1342 | 1511 | type = pci_pcie_type(pdev); |
---|
1343 | | - if (type == PCI_EXP_TYPE_ROOT_PORT || |
---|
1344 | | - type == PCI_EXP_TYPE_PCIE_BRIDGE) |
---|
1345 | | - pdev->has_secondary_link = 1; |
---|
1346 | | - else if (type == PCI_EXP_TYPE_UPSTREAM || |
---|
1347 | | - type == PCI_EXP_TYPE_DOWNSTREAM) { |
---|
1348 | | - parent = pci_upstream_bridge(pdev); |
---|
1349 | | - |
---|
| 1512 | + if (type == PCI_EXP_TYPE_DOWNSTREAM) { |
---|
1350 | 1513 | /* |
---|
1351 | | - * Usually there's an upstream device (Root Port or Switch |
---|
1352 | | - * Downstream Port), but we can't assume one exists. |
---|
| 1514 | + * If pdev claims to be downstream port but the parent |
---|
| 1515 | + * device is also downstream port assume pdev is actually |
---|
| 1516 | + * upstream port. |
---|
1353 | 1517 | */ |
---|
1354 | | - if (parent && !parent->has_secondary_link) |
---|
1355 | | - pdev->has_secondary_link = 1; |
---|
| 1518 | + if (pcie_downstream_port(parent)) { |
---|
| 1519 | + pci_info(pdev, "claims to be downstream port but is acting as upstream port, correcting type\n"); |
---|
| 1520 | + pdev->pcie_flags_reg &= ~PCI_EXP_FLAGS_TYPE; |
---|
| 1521 | + pdev->pcie_flags_reg |= PCI_EXP_TYPE_UPSTREAM; |
---|
| 1522 | + } |
---|
| 1523 | + } else if (type == PCI_EXP_TYPE_UPSTREAM) { |
---|
| 1524 | + /* |
---|
| 1525 | + * If pdev claims to be upstream port but the parent |
---|
| 1526 | + * device is also upstream port assume pdev is actually |
---|
| 1527 | + * downstream port. |
---|
| 1528 | + */ |
---|
| 1529 | + if (pci_pcie_type(parent) == PCI_EXP_TYPE_UPSTREAM) { |
---|
| 1530 | + pci_info(pdev, "claims to be upstream port but is acting as downstream port, correcting type\n"); |
---|
| 1531 | + pdev->pcie_flags_reg &= ~PCI_EXP_FLAGS_TYPE; |
---|
| 1532 | + pdev->pcie_flags_reg |= PCI_EXP_TYPE_DOWNSTREAM; |
---|
| 1533 | + } |
---|
1356 | 1534 | } |
---|
1357 | 1535 | } |
---|
1358 | 1536 | |
---|
.. | .. |
---|
1381 | 1559 | return; |
---|
1382 | 1560 | } |
---|
1383 | 1561 | } |
---|
| 1562 | +} |
---|
| 1563 | + |
---|
| 1564 | +static void set_pcie_untrusted(struct pci_dev *dev) |
---|
| 1565 | +{ |
---|
| 1566 | + struct pci_dev *parent; |
---|
| 1567 | + |
---|
| 1568 | + /* |
---|
| 1569 | + * If the upstream bridge is untrusted we treat this device |
---|
| 1570 | + * untrusted as well. |
---|
| 1571 | + */ |
---|
| 1572 | + parent = pci_upstream_bridge(dev); |
---|
| 1573 | + if (parent && (parent->untrusted || parent->external_facing)) |
---|
| 1574 | + dev->untrusted = true; |
---|
1384 | 1575 | } |
---|
1385 | 1576 | |
---|
1386 | 1577 | /** |
---|
.. | .. |
---|
1449 | 1640 | int pos; |
---|
1450 | 1641 | u32 status; |
---|
1451 | 1642 | u16 class; |
---|
| 1643 | + |
---|
| 1644 | +#ifdef CONFIG_PCI_IOV |
---|
| 1645 | + /* |
---|
| 1646 | + * Per the SR-IOV specification (rev 1.1, sec 3.5), VFs are required to |
---|
| 1647 | + * implement a PCIe capability and therefore must implement extended |
---|
| 1648 | + * config space. We can skip the NO_EXTCFG test below and the |
---|
| 1649 | + * reachability/aliasing test in pci_cfg_space_size_ext() by virtue of |
---|
| 1650 | + * the fact that the SR-IOV capability on the PF resides in extended |
---|
| 1651 | + * config space and must be accessible and non-aliased to have enabled |
---|
| 1652 | + * support for this VF. This is a micro performance optimization for |
---|
| 1653 | + * systems supporting many VFs. |
---|
| 1654 | + */ |
---|
| 1655 | + if (dev->is_virtfn) |
---|
| 1656 | + return PCI_CFG_SPACE_EXP_SIZE; |
---|
| 1657 | +#endif |
---|
1452 | 1658 | |
---|
1453 | 1659 | if (dev->bus->bus_flags & PCI_BUS_FLAGS_NO_EXTCFG) |
---|
1454 | 1660 | return PCI_CFG_SPACE_SIZE; |
---|
.. | .. |
---|
1614 | 1820 | dev->revision = class & 0xff; |
---|
1615 | 1821 | dev->class = class >> 8; /* upper 3 bytes */ |
---|
1616 | 1822 | |
---|
1617 | | - pci_printk(KERN_DEBUG, dev, "[%04x:%04x] type %02x class %#08x\n", |
---|
1618 | | - dev->vendor, dev->device, dev->hdr_type, dev->class); |
---|
1619 | | - |
---|
1620 | 1823 | if (pci_early_dump) |
---|
1621 | 1824 | early_dump_pci_device(dev); |
---|
1622 | 1825 | |
---|
.. | .. |
---|
1626 | 1829 | /* Need to have dev->cfg_size ready */ |
---|
1627 | 1830 | set_pcie_thunderbolt(dev); |
---|
1628 | 1831 | |
---|
| 1832 | + set_pcie_untrusted(dev); |
---|
| 1833 | + |
---|
1629 | 1834 | /* "Unknown power state" */ |
---|
1630 | 1835 | dev->current_state = PCI_UNKNOWN; |
---|
1631 | 1836 | |
---|
1632 | 1837 | /* Early fixups, before probing the BARs */ |
---|
1633 | 1838 | pci_fixup_device(pci_fixup_early, dev); |
---|
| 1839 | + |
---|
| 1840 | + pci_info(dev, "[%04x:%04x] type %02x class %#08x\n", |
---|
| 1841 | + dev->vendor, dev->device, dev->hdr_type, dev->class); |
---|
1634 | 1842 | |
---|
1635 | 1843 | /* Device class may be changed after fixup */ |
---|
1636 | 1844 | class = dev->class >> 8; |
---|
.. | .. |
---|
1701 | 1909 | break; |
---|
1702 | 1910 | |
---|
1703 | 1911 | case PCI_HEADER_TYPE_BRIDGE: /* bridge header */ |
---|
1704 | | - if (class != PCI_CLASS_BRIDGE_PCI) |
---|
1705 | | - goto bad; |
---|
1706 | | - |
---|
1707 | 1912 | /* |
---|
1708 | 1913 | * The PCI-to-PCI bridge spec requires that subtractive |
---|
1709 | 1914 | * decoding (i.e. transparent) bridge must have programming |
---|
.. | .. |
---|
1712 | 1917 | pci_read_irq(dev); |
---|
1713 | 1918 | dev->transparent = ((dev->class & 0xff) == 1); |
---|
1714 | 1919 | pci_read_bases(dev, 2, PCI_ROM_ADDRESS1); |
---|
| 1920 | + pci_read_bridge_windows(dev); |
---|
1715 | 1921 | set_pcie_hotplug_bridge(dev); |
---|
1716 | 1922 | pos = pci_find_capability(dev, PCI_CAP_ID_SSVID); |
---|
1717 | 1923 | if (pos) { |
---|
.. | .. |
---|
1814 | 2020 | p_mps, mps, mpss); |
---|
1815 | 2021 | } |
---|
1816 | 2022 | |
---|
1817 | | -static struct hpp_type0 pci_default_type0 = { |
---|
1818 | | - .revision = 1, |
---|
1819 | | - .cache_line_size = 8, |
---|
1820 | | - .latency_timer = 0x40, |
---|
1821 | | - .enable_serr = 0, |
---|
1822 | | - .enable_perr = 0, |
---|
1823 | | -}; |
---|
1824 | | - |
---|
1825 | | -static void program_hpp_type0(struct pci_dev *dev, struct hpp_type0 *hpp) |
---|
1826 | | -{ |
---|
1827 | | - u16 pci_cmd, pci_bctl; |
---|
1828 | | - |
---|
1829 | | - if (!hpp) |
---|
1830 | | - hpp = &pci_default_type0; |
---|
1831 | | - |
---|
1832 | | - if (hpp->revision > 1) { |
---|
1833 | | - pci_warn(dev, "PCI settings rev %d not supported; using defaults\n", |
---|
1834 | | - hpp->revision); |
---|
1835 | | - hpp = &pci_default_type0; |
---|
1836 | | - } |
---|
1837 | | - |
---|
1838 | | - pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, hpp->cache_line_size); |
---|
1839 | | - pci_write_config_byte(dev, PCI_LATENCY_TIMER, hpp->latency_timer); |
---|
1840 | | - pci_read_config_word(dev, PCI_COMMAND, &pci_cmd); |
---|
1841 | | - if (hpp->enable_serr) |
---|
1842 | | - pci_cmd |= PCI_COMMAND_SERR; |
---|
1843 | | - if (hpp->enable_perr) |
---|
1844 | | - pci_cmd |= PCI_COMMAND_PARITY; |
---|
1845 | | - pci_write_config_word(dev, PCI_COMMAND, pci_cmd); |
---|
1846 | | - |
---|
1847 | | - /* Program bridge control value */ |
---|
1848 | | - if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) { |
---|
1849 | | - pci_write_config_byte(dev, PCI_SEC_LATENCY_TIMER, |
---|
1850 | | - hpp->latency_timer); |
---|
1851 | | - pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &pci_bctl); |
---|
1852 | | - if (hpp->enable_serr) |
---|
1853 | | - pci_bctl |= PCI_BRIDGE_CTL_SERR; |
---|
1854 | | - if (hpp->enable_perr) |
---|
1855 | | - pci_bctl |= PCI_BRIDGE_CTL_PARITY; |
---|
1856 | | - pci_write_config_word(dev, PCI_BRIDGE_CONTROL, pci_bctl); |
---|
1857 | | - } |
---|
1858 | | -} |
---|
1859 | | - |
---|
1860 | | -static void program_hpp_type1(struct pci_dev *dev, struct hpp_type1 *hpp) |
---|
1861 | | -{ |
---|
1862 | | - int pos; |
---|
1863 | | - |
---|
1864 | | - if (!hpp) |
---|
1865 | | - return; |
---|
1866 | | - |
---|
1867 | | - pos = pci_find_capability(dev, PCI_CAP_ID_PCIX); |
---|
1868 | | - if (!pos) |
---|
1869 | | - return; |
---|
1870 | | - |
---|
1871 | | - pci_warn(dev, "PCI-X settings not supported\n"); |
---|
1872 | | -} |
---|
1873 | | - |
---|
1874 | | -static bool pcie_root_rcb_set(struct pci_dev *dev) |
---|
1875 | | -{ |
---|
1876 | | - struct pci_dev *rp = pcie_find_root_port(dev); |
---|
1877 | | - u16 lnkctl; |
---|
1878 | | - |
---|
1879 | | - if (!rp) |
---|
1880 | | - return false; |
---|
1881 | | - |
---|
1882 | | - pcie_capability_read_word(rp, PCI_EXP_LNKCTL, &lnkctl); |
---|
1883 | | - if (lnkctl & PCI_EXP_LNKCTL_RCB) |
---|
1884 | | - return true; |
---|
1885 | | - |
---|
1886 | | - return false; |
---|
1887 | | -} |
---|
1888 | | - |
---|
1889 | | -static void program_hpp_type2(struct pci_dev *dev, struct hpp_type2 *hpp) |
---|
1890 | | -{ |
---|
1891 | | - int pos; |
---|
1892 | | - u32 reg32; |
---|
1893 | | - |
---|
1894 | | - if (!hpp) |
---|
1895 | | - return; |
---|
1896 | | - |
---|
1897 | | - if (!pci_is_pcie(dev)) |
---|
1898 | | - return; |
---|
1899 | | - |
---|
1900 | | - if (hpp->revision > 1) { |
---|
1901 | | - pci_warn(dev, "PCIe settings rev %d not supported\n", |
---|
1902 | | - hpp->revision); |
---|
1903 | | - return; |
---|
1904 | | - } |
---|
1905 | | - |
---|
1906 | | - /* |
---|
1907 | | - * Don't allow _HPX to change MPS or MRRS settings. We manage |
---|
1908 | | - * those to make sure they're consistent with the rest of the |
---|
1909 | | - * platform. |
---|
1910 | | - */ |
---|
1911 | | - hpp->pci_exp_devctl_and |= PCI_EXP_DEVCTL_PAYLOAD | |
---|
1912 | | - PCI_EXP_DEVCTL_READRQ; |
---|
1913 | | - hpp->pci_exp_devctl_or &= ~(PCI_EXP_DEVCTL_PAYLOAD | |
---|
1914 | | - PCI_EXP_DEVCTL_READRQ); |
---|
1915 | | - |
---|
1916 | | - /* Initialize Device Control Register */ |
---|
1917 | | - pcie_capability_clear_and_set_word(dev, PCI_EXP_DEVCTL, |
---|
1918 | | - ~hpp->pci_exp_devctl_and, hpp->pci_exp_devctl_or); |
---|
1919 | | - |
---|
1920 | | - /* Initialize Link Control Register */ |
---|
1921 | | - if (pcie_cap_has_lnkctl(dev)) { |
---|
1922 | | - |
---|
1923 | | - /* |
---|
1924 | | - * If the Root Port supports Read Completion Boundary of |
---|
1925 | | - * 128, set RCB to 128. Otherwise, clear it. |
---|
1926 | | - */ |
---|
1927 | | - hpp->pci_exp_lnkctl_and |= PCI_EXP_LNKCTL_RCB; |
---|
1928 | | - hpp->pci_exp_lnkctl_or &= ~PCI_EXP_LNKCTL_RCB; |
---|
1929 | | - if (pcie_root_rcb_set(dev)) |
---|
1930 | | - hpp->pci_exp_lnkctl_or |= PCI_EXP_LNKCTL_RCB; |
---|
1931 | | - |
---|
1932 | | - pcie_capability_clear_and_set_word(dev, PCI_EXP_LNKCTL, |
---|
1933 | | - ~hpp->pci_exp_lnkctl_and, hpp->pci_exp_lnkctl_or); |
---|
1934 | | - } |
---|
1935 | | - |
---|
1936 | | - /* Find Advanced Error Reporting Enhanced Capability */ |
---|
1937 | | - pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR); |
---|
1938 | | - if (!pos) |
---|
1939 | | - return; |
---|
1940 | | - |
---|
1941 | | - /* Initialize Uncorrectable Error Mask Register */ |
---|
1942 | | - pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_MASK, ®32); |
---|
1943 | | - reg32 = (reg32 & hpp->unc_err_mask_and) | hpp->unc_err_mask_or; |
---|
1944 | | - pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_MASK, reg32); |
---|
1945 | | - |
---|
1946 | | - /* Initialize Uncorrectable Error Severity Register */ |
---|
1947 | | - pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_SEVER, ®32); |
---|
1948 | | - reg32 = (reg32 & hpp->unc_err_sever_and) | hpp->unc_err_sever_or; |
---|
1949 | | - pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_SEVER, reg32); |
---|
1950 | | - |
---|
1951 | | - /* Initialize Correctable Error Mask Register */ |
---|
1952 | | - pci_read_config_dword(dev, pos + PCI_ERR_COR_MASK, ®32); |
---|
1953 | | - reg32 = (reg32 & hpp->cor_err_mask_and) | hpp->cor_err_mask_or; |
---|
1954 | | - pci_write_config_dword(dev, pos + PCI_ERR_COR_MASK, reg32); |
---|
1955 | | - |
---|
1956 | | - /* Initialize Advanced Error Capabilities and Control Register */ |
---|
1957 | | - pci_read_config_dword(dev, pos + PCI_ERR_CAP, ®32); |
---|
1958 | | - reg32 = (reg32 & hpp->adv_err_cap_and) | hpp->adv_err_cap_or; |
---|
1959 | | - |
---|
1960 | | - /* Don't enable ECRC generation or checking if unsupported */ |
---|
1961 | | - if (!(reg32 & PCI_ERR_CAP_ECRC_GENC)) |
---|
1962 | | - reg32 &= ~PCI_ERR_CAP_ECRC_GENE; |
---|
1963 | | - if (!(reg32 & PCI_ERR_CAP_ECRC_CHKC)) |
---|
1964 | | - reg32 &= ~PCI_ERR_CAP_ECRC_CHKE; |
---|
1965 | | - pci_write_config_dword(dev, pos + PCI_ERR_CAP, reg32); |
---|
1966 | | - |
---|
1967 | | - /* |
---|
1968 | | - * FIXME: The following two registers are not supported yet. |
---|
1969 | | - * |
---|
1970 | | - * o Secondary Uncorrectable Error Severity Register |
---|
1971 | | - * o Secondary Uncorrectable Error Mask Register |
---|
1972 | | - */ |
---|
1973 | | -} |
---|
1974 | | - |
---|
1975 | 2023 | int pci_configure_extended_tags(struct pci_dev *dev, void *ign) |
---|
1976 | 2024 | { |
---|
1977 | 2025 | struct pci_host_bridge *host; |
---|
.. | .. |
---|
2049 | 2097 | * For now, we only deal with Relaxed Ordering issues with Root |
---|
2050 | 2098 | * Ports. Peer-to-Peer DMA is another can of worms. |
---|
2051 | 2099 | */ |
---|
2052 | | - root = pci_find_pcie_root_port(dev); |
---|
| 2100 | + root = pcie_find_root_port(dev); |
---|
2053 | 2101 | if (!root) |
---|
2054 | 2102 | return; |
---|
2055 | 2103 | |
---|
.. | .. |
---|
2069 | 2117 | |
---|
2070 | 2118 | if (!pci_is_pcie(dev)) |
---|
2071 | 2119 | return; |
---|
| 2120 | + |
---|
| 2121 | + /* Read L1 PM substate capabilities */ |
---|
| 2122 | + dev->l1ss = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_L1SS); |
---|
2072 | 2123 | |
---|
2073 | 2124 | pcie_capability_read_dword(dev, PCI_EXP_DEVCAP2, &cap); |
---|
2074 | 2125 | if (!(cap & PCI_EXP_DEVCAP2_LTR)) |
---|
.. | .. |
---|
2132 | 2183 | #endif |
---|
2133 | 2184 | } |
---|
2134 | 2185 | |
---|
| 2186 | +static void pci_configure_serr(struct pci_dev *dev) |
---|
| 2187 | +{ |
---|
| 2188 | + u16 control; |
---|
| 2189 | + |
---|
| 2190 | + if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) { |
---|
| 2191 | + |
---|
| 2192 | + /* |
---|
| 2193 | + * A bridge will not forward ERR_ messages coming from an |
---|
| 2194 | + * endpoint unless SERR# forwarding is enabled. |
---|
| 2195 | + */ |
---|
| 2196 | + pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &control); |
---|
| 2197 | + if (!(control & PCI_BRIDGE_CTL_SERR)) { |
---|
| 2198 | + control |= PCI_BRIDGE_CTL_SERR; |
---|
| 2199 | + pci_write_config_word(dev, PCI_BRIDGE_CONTROL, control); |
---|
| 2200 | + } |
---|
| 2201 | + } |
---|
| 2202 | +} |
---|
| 2203 | + |
---|
2135 | 2204 | static void pci_configure_device(struct pci_dev *dev) |
---|
2136 | 2205 | { |
---|
2137 | | - struct hotplug_params hpp; |
---|
2138 | | - int ret; |
---|
2139 | | - |
---|
2140 | 2206 | pci_configure_mps(dev); |
---|
2141 | 2207 | pci_configure_extended_tags(dev, NULL); |
---|
2142 | 2208 | pci_configure_relaxed_ordering(dev); |
---|
2143 | 2209 | pci_configure_ltr(dev); |
---|
2144 | 2210 | pci_configure_eetlp_prefix(dev); |
---|
| 2211 | + pci_configure_serr(dev); |
---|
2145 | 2212 | |
---|
2146 | | - memset(&hpp, 0, sizeof(hpp)); |
---|
2147 | | - ret = pci_get_hp_params(dev, &hpp); |
---|
2148 | | - if (ret) |
---|
2149 | | - return; |
---|
2150 | | - |
---|
2151 | | - program_hpp_type2(dev, hpp.t2); |
---|
2152 | | - program_hpp_type1(dev, hpp.t1); |
---|
2153 | | - program_hpp_type0(dev, hpp.t0); |
---|
| 2213 | + pci_acpi_program_hp_params(dev); |
---|
2154 | 2214 | } |
---|
2155 | 2215 | |
---|
2156 | 2216 | static void pci_release_capabilities(struct pci_dev *dev) |
---|
.. | .. |
---|
2179 | 2239 | pcibios_release_device(pci_dev); |
---|
2180 | 2240 | pci_bus_put(pci_dev->bus); |
---|
2181 | 2241 | kfree(pci_dev->driver_override); |
---|
2182 | | - kfree(pci_dev->dma_alias_mask); |
---|
| 2242 | + bitmap_free(pci_dev->dma_alias_mask); |
---|
2183 | 2243 | kfree(pci_dev); |
---|
2184 | 2244 | } |
---|
2185 | 2245 | |
---|
.. | .. |
---|
2316 | 2376 | return dev; |
---|
2317 | 2377 | } |
---|
2318 | 2378 | |
---|
2319 | | -static void pcie_report_downtraining(struct pci_dev *dev) |
---|
| 2379 | +void pcie_report_downtraining(struct pci_dev *dev) |
---|
2320 | 2380 | { |
---|
2321 | 2381 | if (!pci_is_pcie(dev)) |
---|
2322 | 2382 | return; |
---|
.. | .. |
---|
2337 | 2397 | |
---|
2338 | 2398 | static void pci_init_capabilities(struct pci_dev *dev) |
---|
2339 | 2399 | { |
---|
2340 | | - /* Enhanced Allocation */ |
---|
2341 | | - pci_ea_init(dev); |
---|
| 2400 | + pci_ea_init(dev); /* Enhanced Allocation */ |
---|
2342 | 2401 | |
---|
2343 | 2402 | /* Setup MSI caps & disable MSI/MSI-X interrupts */ |
---|
2344 | 2403 | pci_msi_setup_pci_dev(dev); |
---|
.. | .. |
---|
2346 | 2405 | /* Buffers for saving PCIe and PCI-X capabilities */ |
---|
2347 | 2406 | pci_allocate_cap_save_buffers(dev); |
---|
2348 | 2407 | |
---|
2349 | | - /* Power Management */ |
---|
2350 | | - pci_pm_init(dev); |
---|
2351 | | - |
---|
2352 | | - /* Vital Product Data */ |
---|
2353 | | - pci_vpd_init(dev); |
---|
2354 | | - |
---|
2355 | | - /* Alternative Routing-ID Forwarding */ |
---|
2356 | | - pci_configure_ari(dev); |
---|
2357 | | - |
---|
2358 | | - /* Single Root I/O Virtualization */ |
---|
2359 | | - pci_iov_init(dev); |
---|
2360 | | - |
---|
2361 | | - /* Address Translation Services */ |
---|
2362 | | - pci_ats_init(dev); |
---|
2363 | | - |
---|
2364 | | - /* Enable ACS P2P upstream forwarding */ |
---|
2365 | | - pci_enable_acs(dev); |
---|
2366 | | - |
---|
2367 | | - /* Precision Time Measurement */ |
---|
2368 | | - pci_ptm_init(dev); |
---|
2369 | | - |
---|
2370 | | - /* Advanced Error Reporting */ |
---|
2371 | | - pci_aer_init(dev); |
---|
| 2408 | + pci_pm_init(dev); /* Power Management */ |
---|
| 2409 | + pci_vpd_init(dev); /* Vital Product Data */ |
---|
| 2410 | + pci_configure_ari(dev); /* Alternative Routing-ID Forwarding */ |
---|
| 2411 | + pci_iov_init(dev); /* Single Root I/O Virtualization */ |
---|
| 2412 | + pci_ats_init(dev); /* Address Translation Services */ |
---|
| 2413 | + pci_pri_init(dev); /* Page Request Interface */ |
---|
| 2414 | + pci_pasid_init(dev); /* Process Address Space ID */ |
---|
| 2415 | + pci_acs_init(dev); /* Access Control Services */ |
---|
| 2416 | + pci_ptm_init(dev); /* Precision Time Measurement */ |
---|
| 2417 | + pci_aer_init(dev); /* Advanced Error Reporting */ |
---|
| 2418 | + pci_dpc_init(dev); /* Downstream Port Containment */ |
---|
2372 | 2419 | |
---|
2373 | 2420 | pcie_report_downtraining(dev); |
---|
2374 | 2421 | |
---|
.. | .. |
---|
2434 | 2481 | dev->dev.dma_parms = &dev->dma_parms; |
---|
2435 | 2482 | dev->dev.coherent_dma_mask = 0xffffffffull; |
---|
2436 | 2483 | |
---|
2437 | | - pci_set_dma_max_seg_size(dev, 65536); |
---|
2438 | | - pci_set_dma_seg_boundary(dev, 0xffffffff); |
---|
| 2484 | + dma_set_max_seg_size(&dev->dev, 65536); |
---|
| 2485 | + dma_set_seg_boundary(&dev->dev, 0xffffffff); |
---|
2439 | 2486 | |
---|
2440 | 2487 | /* Fix up broken headers */ |
---|
2441 | 2488 | pci_fixup_device(pci_fixup_header, dev); |
---|
2442 | 2489 | |
---|
2443 | | - /* Moved out from quirk header fixup code */ |
---|
2444 | 2490 | pci_reassigndev_resource_alignment(dev); |
---|
2445 | 2491 | |
---|
2446 | | - /* Clear the state_saved flag */ |
---|
2447 | 2492 | dev->state_saved = false; |
---|
2448 | 2493 | |
---|
2449 | | - /* Initialize various capabilities */ |
---|
2450 | 2494 | pci_init_capabilities(dev); |
---|
2451 | 2495 | |
---|
2452 | 2496 | /* |
---|
.. | .. |
---|
2532 | 2576 | * A PCIe Downstream Port normally leads to a Link with only Device |
---|
2533 | 2577 | * 0 on it (PCIe spec r3.1, sec 7.3.1). As an optimization, scan |
---|
2534 | 2578 | * only for Device 0 in that situation. |
---|
2535 | | - * |
---|
2536 | | - * Checking has_secondary_link is a hack to identify Downstream |
---|
2537 | | - * Ports because sometimes Switches are configured such that the |
---|
2538 | | - * PCIe Port Type labels are backwards. |
---|
2539 | 2579 | */ |
---|
2540 | | - if (bridge && pci_is_pcie(bridge) && bridge->has_secondary_link) |
---|
| 2580 | + if (bridge && pci_is_pcie(bridge) && pcie_downstream_port(bridge)) |
---|
2541 | 2581 | return 1; |
---|
2542 | 2582 | |
---|
2543 | 2583 | return 0; |
---|
.. | .. |
---|
2957 | 2997 | return bridge->bus; |
---|
2958 | 2998 | |
---|
2959 | 2999 | err_out: |
---|
2960 | | - kfree(bridge); |
---|
| 3000 | + put_device(&bridge->dev); |
---|
2961 | 3001 | return NULL; |
---|
2962 | 3002 | } |
---|
2963 | 3003 | EXPORT_SYMBOL_GPL(pci_create_root_bus); |
---|
.. | .. |
---|
3014 | 3054 | conflict = request_resource_conflict(parent_res, res); |
---|
3015 | 3055 | |
---|
3016 | 3056 | if (conflict) |
---|
3017 | | - dev_printk(KERN_DEBUG, &b->dev, |
---|
| 3057 | + dev_info(&b->dev, |
---|
3018 | 3058 | "busn_res: can not insert %pR under %s%pR (conflicts with %s %pR)\n", |
---|
3019 | 3059 | res, pci_is_root_bus(b) ? "domain " : "", |
---|
3020 | 3060 | parent_res, conflict->name, conflict); |
---|
.. | .. |
---|
3034 | 3074 | |
---|
3035 | 3075 | size = bus_max - res->start + 1; |
---|
3036 | 3076 | ret = adjust_resource(res, res->start, size); |
---|
3037 | | - dev_printk(KERN_DEBUG, &b->dev, |
---|
3038 | | - "busn_res: %pR end %s updated to %02x\n", |
---|
| 3077 | + dev_info(&b->dev, "busn_res: %pR end %s updated to %02x\n", |
---|
3039 | 3078 | &old_res, ret ? "can not be" : "is", bus_max); |
---|
3040 | 3079 | |
---|
3041 | 3080 | if (!ret && !res->parent) |
---|
.. | .. |
---|
3053 | 3092 | return; |
---|
3054 | 3093 | |
---|
3055 | 3094 | ret = release_resource(res); |
---|
3056 | | - dev_printk(KERN_DEBUG, &b->dev, |
---|
3057 | | - "busn_res: %pR %s released\n", |
---|
| 3095 | + dev_info(&b->dev, "busn_res: %pR %s released\n", |
---|
3058 | 3096 | res, ret ? "can not be" : "is"); |
---|
3059 | 3097 | } |
---|
3060 | 3098 | |
---|
.. | .. |
---|
3070 | 3108 | |
---|
3071 | 3109 | resource_list_for_each_entry(window, &bridge->windows) |
---|
3072 | 3110 | if (window->res->flags & IORESOURCE_BUS) { |
---|
| 3111 | + bridge->busnr = window->res->start; |
---|
3073 | 3112 | found = true; |
---|
3074 | 3113 | break; |
---|
3075 | 3114 | } |
---|