Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Revert "PCI: update bridge resources to get more big ranges in PCI assign unssigned"

This reverts commit 977d17bb1749517b353874ccdc9b85abc7a58c2a, because it
can cause problems with some devices not getting any resources at all
when the resource tree is re-allocated.

For an example of this, see

https://bugzilla.kernel.org/show_bug.cgi?id=15960
(originally https://bugtrack.alsa-project.org/alsa-bug/view.php?id=4982)
(lkml thread: http://lkml.org/lkml/2010/4/19/20)

where Peter Henriksson reported his Xonar DX sound card gone, because
the IO port region was no longer allocated.

Reported-bisected-and-tested-by: Peter Henriksson <peter.henriksson@gmail.com>
Requested-by: Andrew Morton <akpm@linux-foundation.org>
Requested-by: Clemens Ladisch <clemens@ladisch.de>
Acked-by: Jesse Barnes <jbarnes@virtuousgeek.org>
Cc: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

+2 -112
+2 -112
drivers/pci/setup-bus.c
··· 838 838 } 839 839 } 840 840 841 - static int __init pci_bus_get_depth(struct pci_bus *bus) 842 - { 843 - int depth = 0; 844 - struct pci_dev *dev; 845 - 846 - list_for_each_entry(dev, &bus->devices, bus_list) { 847 - int ret; 848 - struct pci_bus *b = dev->subordinate; 849 - if (!b) 850 - continue; 851 - 852 - ret = pci_bus_get_depth(b); 853 - if (ret + 1 > depth) 854 - depth = ret + 1; 855 - } 856 - 857 - return depth; 858 - } 859 - static int __init pci_get_max_depth(void) 860 - { 861 - int depth = 0; 862 - struct pci_bus *bus; 863 - 864 - list_for_each_entry(bus, &pci_root_buses, node) { 865 - int ret; 866 - 867 - ret = pci_bus_get_depth(bus); 868 - if (ret > depth) 869 - depth = ret; 870 - } 871 - 872 - return depth; 873 - } 874 - 875 - /* 876 - * first try will not touch pci bridge res 877 - * second and later try will clear small leaf bridge res 878 - * will stop till to the max deepth if can not find good one 879 - */ 880 841 void __init 881 842 pci_assign_unassigned_resources(void) 882 843 { 883 844 struct pci_bus *bus; 884 - int tried_times = 0; 885 - enum release_type rel_type = leaf_only; 886 - struct resource_list_x head, *list; 887 - unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM | 888 - IORESOURCE_PREFETCH; 889 - unsigned long failed_type; 890 - int max_depth = pci_get_max_depth(); 891 - int pci_try_num; 892 845 893 - head.next = NULL; 894 - 895 - pci_try_num = max_depth + 1; 896 - printk(KERN_DEBUG "PCI: max bus depth: %d pci_try_num: %d\n", 897 - max_depth, pci_try_num); 898 - 899 - again: 900 846 /* Depth first, calculate sizes and alignments of all 901 847 subordinate buses. */ 902 848 list_for_each_entry(bus, &pci_root_buses, node) { ··· 850 904 } 851 905 /* Depth last, allocate resources and update the hardware. */ 852 906 list_for_each_entry(bus, &pci_root_buses, node) { 853 - __pci_bus_assign_resources(bus, &head); 854 - } 855 - tried_times++; 856 - 857 - /* any device complain? */ 858 - if (!head.next) 859 - goto enable_and_dump; 860 - failed_type = 0; 861 - for (list = head.next; list;) { 862 - failed_type |= list->flags; 863 - list = list->next; 864 - } 865 - /* 866 - * io port are tight, don't try extra 867 - * or if reach the limit, don't want to try more 868 - */ 869 - failed_type &= type_mask; 870 - if ((failed_type == IORESOURCE_IO) || (tried_times >= pci_try_num)) { 871 - free_failed_list(&head); 872 - goto enable_and_dump; 873 - } 874 - 875 - printk(KERN_DEBUG "PCI: No. %d try to assign unassigned res\n", 876 - tried_times + 1); 877 - 878 - /* third times and later will not check if it is leaf */ 879 - if ((tried_times + 1) > 2) 880 - rel_type = whole_subtree; 881 - 882 - /* 883 - * Try to release leaf bridge's resources that doesn't fit resource of 884 - * child device under that bridge 885 - */ 886 - for (list = head.next; list;) { 887 - bus = list->dev->bus; 888 - pci_bus_release_bridge_resources(bus, list->flags & type_mask, 889 - rel_type); 890 - list = list->next; 891 - } 892 - /* restore size and flags */ 893 - for (list = head.next; list;) { 894 - struct resource *res = list->res; 895 - 896 - res->start = list->start; 897 - res->end = list->end; 898 - res->flags = list->flags; 899 - if (list->dev->subordinate) 900 - res->flags = 0; 901 - 902 - list = list->next; 903 - } 904 - free_failed_list(&head); 905 - 906 - goto again; 907 - 908 - enable_and_dump: 909 - /* Depth last, update the hardware. */ 910 - list_for_each_entry(bus, &pci_root_buses, node) 907 + pci_bus_assign_resources(bus); 911 908 pci_enable_bridges(bus); 909 + } 912 910 913 911 /* dump the resource on buses */ 914 912 list_for_each_entry(bus, &pci_root_buses, node) {