Skip to content

Commit 7180c1d

Browse files
westeribjorn-helgaas
authored andcommitted
PCI: Distribute available resources for root buses, too
Previously we distributed spare resources only upon hot-add, so if the initial root bus scan found devices that had not been fully configured by the BIOS, we allocated only enough resources to cover what was then present. If some of those devices were hotplug bridges, we did not leave any additional resource space for future expansion. Distribute the available resources for root buses, too, to make this work the same way as the normal hotplug case. A previous commit to do this was reverted due to a regression reported by Jonathan Cameron: e96e27f ("PCI: Distribute available resources for root buses, too") 5632e2b ("Revert "PCI: Distribute available resources for root buses, too"") This commit changes pci_bridge_resources_not_assigned() to work with bridges that do not have all the resource windows programmed by the boot firmware (previously we expected all I/O, memory and prefetchable memory were programmed). Link: https://bugzilla.kernel.org/show_bug.cgi?id=216000 Link: https://lore.kernel.org/r/20220905080232.36087-5-mika.westerberg@linux.intel.com Link: https://lore.kernel.org/r/20230131092405.29121-4-mika.westerberg@linux.intel.com Reported-by: Chris Chiu <chris.chiu@canonical.com> Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
1 parent 9db0b9b commit 7180c1d

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

drivers/pci/setup-bus.c

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1770,7 +1770,10 @@ static void adjust_bridge_window(struct pci_dev *bridge, struct resource *res,
17701770
}
17711771

17721772
res->end = res->start + new_size - 1;
1773-
remove_from_list(add_list, res);
1773+
1774+
/* If the resource is part of the add_list, remove it now */
1775+
if (add_list)
1776+
remove_from_list(add_list, res);
17741777
}
17751778

17761779
static void remove_dev_resource(struct resource *avail, struct pci_dev *dev,
@@ -1972,6 +1975,8 @@ static void pci_bridge_distribute_available_resources(struct pci_dev *bridge,
19721975
if (!bridge->is_hotplug_bridge)
19731976
return;
19741977

1978+
pci_dbg(bridge, "distributing available resources\n");
1979+
19751980
/* Take the initial extra resources from the hotplug port */
19761981
available_io = bridge->resource[PCI_BRIDGE_IO_WINDOW];
19771982
available_mmio = bridge->resource[PCI_BRIDGE_MEM_WINDOW];
@@ -1983,6 +1988,54 @@ static void pci_bridge_distribute_available_resources(struct pci_dev *bridge,
19831988
available_mmio_pref);
19841989
}
19851990

1991+
static bool pci_bridge_resources_not_assigned(struct pci_dev *dev)
1992+
{
1993+
const struct resource *r;
1994+
1995+
/*
1996+
* If the child device's resources are not yet assigned it means we
1997+
* are configuring them (not the boot firmware), so we should be
1998+
* able to extend the upstream bridge resources in the same way we
1999+
* do with the normal hotplug case.
2000+
*/
2001+
r = &dev->resource[PCI_BRIDGE_IO_WINDOW];
2002+
if (r->flags && !(r->flags & IORESOURCE_STARTALIGN))
2003+
return false;
2004+
r = &dev->resource[PCI_BRIDGE_MEM_WINDOW];
2005+
if (r->flags && !(r->flags & IORESOURCE_STARTALIGN))
2006+
return false;
2007+
r = &dev->resource[PCI_BRIDGE_PREF_MEM_WINDOW];
2008+
if (r->flags && !(r->flags & IORESOURCE_STARTALIGN))
2009+
return false;
2010+
2011+
return true;
2012+
}
2013+
2014+
static void
2015+
pci_root_bus_distribute_available_resources(struct pci_bus *bus,
2016+
struct list_head *add_list)
2017+
{
2018+
struct pci_dev *dev, *bridge = bus->self;
2019+
2020+
for_each_pci_bridge(dev, bus) {
2021+
struct pci_bus *b;
2022+
2023+
b = dev->subordinate;
2024+
if (!b)
2025+
continue;
2026+
2027+
/*
2028+
* Need to check "bridge" here too because it is NULL
2029+
* in case of root bus.
2030+
*/
2031+
if (bridge && pci_bridge_resources_not_assigned(dev))
2032+
pci_bridge_distribute_available_resources(bridge,
2033+
add_list);
2034+
else
2035+
pci_root_bus_distribute_available_resources(b, add_list);
2036+
}
2037+
}
2038+
19862039
/*
19872040
* First try will not touch PCI bridge res.
19882041
* Second and later try will clear small leaf bridge res.
@@ -2022,6 +2075,8 @@ void pci_assign_unassigned_root_bus_resources(struct pci_bus *bus)
20222075
*/
20232076
__pci_bus_size_bridges(bus, add_list);
20242077

2078+
pci_root_bus_distribute_available_resources(bus, add_list);
2079+
20252080
/* Depth last, allocate resources and update the hardware. */
20262081
__pci_bus_assign_resources(bus, add_list, &fail_head);
20272082
if (add_list)

0 commit comments

Comments
 (0)