Skip to content

Commit 769d996

Browse files
committed
Revert "PCI: update bridge resources to get more big ranges in PCI assign unssigned"
This reverts commit 977d17b, 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>
1 parent 7ac512a commit 769d996

File tree

1 file changed

+2
-112
lines changed

1 file changed

+2
-112
lines changed

drivers/pci/setup-bus.c

Lines changed: 2 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -838,131 +838,21 @@ static void pci_bus_dump_resources(struct pci_bus *bus)
838838
}
839839
}
840840

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-
*/
880841
void __init
881842
pci_assign_unassigned_resources(void)
882843
{
883844
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;
892845

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:
900846
/* Depth first, calculate sizes and alignments of all
901847
subordinate buses. */
902848
list_for_each_entry(bus, &pci_root_buses, node) {
903849
pci_bus_size_bridges(bus);
904850
}
905851
/* Depth last, allocate resources and update the hardware. */
906852
list_for_each_entry(bus, &pci_root_buses, node) {
907-
__pci_bus_assign_resources(bus, &head);
908-
}
909-
tried_times++;
910-
911-
/* any device complain? */
912-
if (!head.next)
913-
goto enable_and_dump;
914-
failed_type = 0;
915-
for (list = head.next; list;) {
916-
failed_type |= list->flags;
917-
list = list->next;
918-
}
919-
/*
920-
* io port are tight, don't try extra
921-
* or if reach the limit, don't want to try more
922-
*/
923-
failed_type &= type_mask;
924-
if ((failed_type == IORESOURCE_IO) || (tried_times >= pci_try_num)) {
925-
free_failed_list(&head);
926-
goto enable_and_dump;
927-
}
928-
929-
printk(KERN_DEBUG "PCI: No. %d try to assign unassigned res\n",
930-
tried_times + 1);
931-
932-
/* third times and later will not check if it is leaf */
933-
if ((tried_times + 1) > 2)
934-
rel_type = whole_subtree;
935-
936-
/*
937-
* Try to release leaf bridge's resources that doesn't fit resource of
938-
* child device under that bridge
939-
*/
940-
for (list = head.next; list;) {
941-
bus = list->dev->bus;
942-
pci_bus_release_bridge_resources(bus, list->flags & type_mask,
943-
rel_type);
944-
list = list->next;
945-
}
946-
/* restore size and flags */
947-
for (list = head.next; list;) {
948-
struct resource *res = list->res;
949-
950-
res->start = list->start;
951-
res->end = list->end;
952-
res->flags = list->flags;
953-
if (list->dev->subordinate)
954-
res->flags = 0;
955-
956-
list = list->next;
957-
}
958-
free_failed_list(&head);
959-
960-
goto again;
961-
962-
enable_and_dump:
963-
/* Depth last, update the hardware. */
964-
list_for_each_entry(bus, &pci_root_buses, node)
853+
pci_bus_assign_resources(bus);
965854
pci_enable_bridges(bus);
855+
}
966856

967857
/* dump the resource on buses */
968858
list_for_each_entry(bus, &pci_root_buses, node) {

0 commit comments

Comments
 (0)