diff options
author | Bjorn Helgaas <bhelgaas@google.com> | 2014-02-14 16:37:09 -0500 |
---|---|---|
committer | Bjorn Helgaas <bhelgaas@google.com> | 2014-02-14 16:37:09 -0500 |
commit | 25a712a49fade142b78a1c55166ad8a19cb53aba (patch) | |
tree | 19f2736c2ae797d3dabd86f0edf906470f55c538 | |
parent | 17f2d86f5d53d61b12085812a650ae12a76eaa69 (diff) | |
parent | fc1b253141b360f9c669d391b4ff663b984ef0c9 (diff) |
Merge branch 'pci/scan-bridge' into next
* pci/scan-bridge:
PCI: Don't scan random busses in pci_scan_bridge()
PCI: Check for child busses which use more bus numbers than allocated
PCI: Remove pci_fixup_parent_subordinate_busnr()
PCI: Make sure bus number resources stay within their parents bounds
PCI: Use request_resource_conflict() instead of insert_ for bus numbers
PCI: Assign CardBus bus number only during the second pass
PCI: Clarify the "scan anyway" comment in pci_scan_bridge()
PCI: Increment max correctly in pci_scan_bridge()
-rw-r--r-- | drivers/pci/probe.c | 76 |
1 files changed, 29 insertions, 47 deletions
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 6e34498ec9f0..509494381a7a 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c | |||
@@ -731,22 +731,6 @@ struct pci_bus *__ref pci_add_new_bus(struct pci_bus *parent, struct pci_dev *de | |||
731 | return child; | 731 | return child; |
732 | } | 732 | } |
733 | 733 | ||
734 | static void pci_fixup_parent_subordinate_busnr(struct pci_bus *child, int max) | ||
735 | { | ||
736 | struct pci_bus *parent = child->parent; | ||
737 | |||
738 | /* Attempts to fix that up are really dangerous unless | ||
739 | we're going to re-assign all bus numbers. */ | ||
740 | if (!pcibios_assign_all_busses()) | ||
741 | return; | ||
742 | |||
743 | while (parent->parent && parent->busn_res.end < max) { | ||
744 | parent->busn_res.end = max; | ||
745 | pci_write_config_byte(parent->self, PCI_SUBORDINATE_BUS, max); | ||
746 | parent = parent->parent; | ||
747 | } | ||
748 | } | ||
749 | |||
750 | /* | 734 | /* |
751 | * If it's a bridge, configure it and scan the bus behind it. | 735 | * If it's a bridge, configure it and scan the bus behind it. |
752 | * For CardBus bridges, we don't scan behind as the devices will | 736 | * For CardBus bridges, we don't scan behind as the devices will |
@@ -782,7 +766,7 @@ int pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max, int pass) | |||
782 | /* Check if setup is sensible at all */ | 766 | /* Check if setup is sensible at all */ |
783 | if (!pass && | 767 | if (!pass && |
784 | (primary != bus->number || secondary <= bus->number || | 768 | (primary != bus->number || secondary <= bus->number || |
785 | secondary > subordinate)) { | 769 | secondary > subordinate || subordinate > bus->busn_res.end)) { |
786 | dev_info(&dev->dev, "bridge configuration invalid ([bus %02x-%02x]), reconfiguring\n", | 770 | dev_info(&dev->dev, "bridge configuration invalid ([bus %02x-%02x]), reconfiguring\n", |
787 | secondary, subordinate); | 771 | secondary, subordinate); |
788 | broken = 1; | 772 | broken = 1; |
@@ -805,11 +789,10 @@ int pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max, int pass) | |||
805 | goto out; | 789 | goto out; |
806 | 790 | ||
807 | /* | 791 | /* |
808 | * If we already got to this bus through a different bridge, | 792 | * The bus might already exist for two reasons: Either we are |
809 | * don't re-add it. This can happen with the i450NX chipset. | 793 | * rescanning the bus or the bus is reachable through more than |
810 | * | 794 | * one bridge. The second case can happen with the i450NX |
811 | * However, we continue to descend down the hierarchy and | 795 | * chipset. |
812 | * scan remaining child buses. | ||
813 | */ | 796 | */ |
814 | child = pci_find_bus(pci_domain_nr(bus), secondary); | 797 | child = pci_find_bus(pci_domain_nr(bus), secondary); |
815 | if (!child) { | 798 | if (!child) { |
@@ -822,17 +805,19 @@ int pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max, int pass) | |||
822 | } | 805 | } |
823 | 806 | ||
824 | cmax = pci_scan_child_bus(child); | 807 | cmax = pci_scan_child_bus(child); |
825 | if (cmax > max) | 808 | if (cmax > subordinate) |
826 | max = cmax; | 809 | dev_warn(&dev->dev, "bridge has subordinate %02x but max busn %02x\n", |
827 | if (child->busn_res.end > max) | 810 | subordinate, cmax); |
828 | max = child->busn_res.end; | 811 | /* subordinate should equal child->busn_res.end */ |
812 | if (subordinate > max) | ||
813 | max = subordinate; | ||
829 | } else { | 814 | } else { |
830 | /* | 815 | /* |
831 | * We need to assign a number to this bus which we always | 816 | * We need to assign a number to this bus which we always |
832 | * do in the second pass. | 817 | * do in the second pass. |
833 | */ | 818 | */ |
834 | if (!pass) { | 819 | if (!pass) { |
835 | if (pcibios_assign_all_busses() || broken) | 820 | if (pcibios_assign_all_busses() || broken || is_cardbus) |
836 | /* Temporarily disable forwarding of the | 821 | /* Temporarily disable forwarding of the |
837 | configuration cycles on all bridges in | 822 | configuration cycles on all bridges in |
838 | this bus segment to avoid possible | 823 | this bus segment to avoid possible |
@@ -844,19 +829,25 @@ int pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max, int pass) | |||
844 | goto out; | 829 | goto out; |
845 | } | 830 | } |
846 | 831 | ||
832 | if (max >= bus->busn_res.end) { | ||
833 | dev_warn(&dev->dev, "can't allocate child bus %02x from %pR\n", | ||
834 | max, &bus->busn_res); | ||
835 | goto out; | ||
836 | } | ||
837 | |||
847 | /* Clear errors */ | 838 | /* Clear errors */ |
848 | pci_write_config_word(dev, PCI_STATUS, 0xffff); | 839 | pci_write_config_word(dev, PCI_STATUS, 0xffff); |
849 | 840 | ||
850 | /* Prevent assigning a bus number that already exists. | 841 | /* The bus will already exist if we are rescanning */ |
851 | * This can happen when a bridge is hot-plugged, so in | ||
852 | * this case we only re-scan this bus. */ | ||
853 | child = pci_find_bus(pci_domain_nr(bus), max+1); | 842 | child = pci_find_bus(pci_domain_nr(bus), max+1); |
854 | if (!child) { | 843 | if (!child) { |
855 | child = pci_add_new_bus(bus, dev, ++max); | 844 | child = pci_add_new_bus(bus, dev, max+1); |
856 | if (!child) | 845 | if (!child) |
857 | goto out; | 846 | goto out; |
858 | pci_bus_insert_busn_res(child, max, 0xff); | 847 | pci_bus_insert_busn_res(child, max+1, |
848 | bus->busn_res.end); | ||
859 | } | 849 | } |
850 | max++; | ||
860 | buses = (buses & 0xff000000) | 851 | buses = (buses & 0xff000000) |
861 | | ((unsigned int)(child->primary) << 0) | 852 | | ((unsigned int)(child->primary) << 0) |
862 | | ((unsigned int)(child->busn_res.start) << 8) | 853 | | ((unsigned int)(child->busn_res.start) << 8) |
@@ -878,20 +869,7 @@ int pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max, int pass) | |||
878 | 869 | ||
879 | if (!is_cardbus) { | 870 | if (!is_cardbus) { |
880 | child->bridge_ctl = bctl; | 871 | child->bridge_ctl = bctl; |
881 | /* | ||
882 | * Adjust subordinate busnr in parent buses. | ||
883 | * We do this before scanning for children because | ||
884 | * some devices may not be detected if the bios | ||
885 | * was lazy. | ||
886 | */ | ||
887 | pci_fixup_parent_subordinate_busnr(child, max); | ||
888 | /* Now we can scan all subordinate buses... */ | ||
889 | max = pci_scan_child_bus(child); | 872 | max = pci_scan_child_bus(child); |
890 | /* | ||
891 | * now fix it up again since we have found | ||
892 | * the real value of max. | ||
893 | */ | ||
894 | pci_fixup_parent_subordinate_busnr(child, max); | ||
895 | } else { | 873 | } else { |
896 | /* | 874 | /* |
897 | * For CardBus bridges, we leave 4 bus numbers | 875 | * For CardBus bridges, we leave 4 bus numbers |
@@ -922,11 +900,15 @@ int pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max, int pass) | |||
922 | } | 900 | } |
923 | } | 901 | } |
924 | max += i; | 902 | max += i; |
925 | pci_fixup_parent_subordinate_busnr(child, max); | ||
926 | } | 903 | } |
927 | /* | 904 | /* |
928 | * Set the subordinate bus number to its real value. | 905 | * Set the subordinate bus number to its real value. |
929 | */ | 906 | */ |
907 | if (max > bus->busn_res.end) { | ||
908 | dev_warn(&dev->dev, "max busn %02x is outside %pR\n", | ||
909 | max, &bus->busn_res); | ||
910 | max = bus->busn_res.end; | ||
911 | } | ||
930 | pci_bus_update_busn_res_end(child, max); | 912 | pci_bus_update_busn_res_end(child, max); |
931 | pci_write_config_byte(dev, PCI_SUBORDINATE_BUS, max); | 913 | pci_write_config_byte(dev, PCI_SUBORDINATE_BUS, max); |
932 | } | 914 | } |
@@ -1835,7 +1817,7 @@ int pci_bus_insert_busn_res(struct pci_bus *b, int bus, int bus_max) | |||
1835 | res->flags |= IORESOURCE_PCI_FIXED; | 1817 | res->flags |= IORESOURCE_PCI_FIXED; |
1836 | } | 1818 | } |
1837 | 1819 | ||
1838 | conflict = insert_resource_conflict(parent_res, res); | 1820 | conflict = request_resource_conflict(parent_res, res); |
1839 | 1821 | ||
1840 | if (conflict) | 1822 | if (conflict) |
1841 | dev_printk(KERN_DEBUG, &b->dev, | 1823 | dev_printk(KERN_DEBUG, &b->dev, |