Skip to content

Commit ae88d0b

Browse files
ij-intelbjorn-helgaas
authored andcommitted
PCI: Use pbus_select_window_for_type() during mem window sizing
__pci_bus_size_bridges() goes to great lengths of helping pbus_size_mem() in which types it should put into a particular bridge window, requiring passing up to three resource type into pbus_size_mem(). Instead of having complex logic in __pci_bus_size_bridges() and a non-straightforward interface between those functions, use pbus_select_window_for_type() and pbus_select_window() to find the correct bridge window and compare if the resources belong to that window. Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Link: https://patch.msgid.link/20250829131113.36754-20-ilpo.jarvinen@linux.intel.com
1 parent 13016e1 commit ae88d0b

1 file changed

Lines changed: 24 additions & 87 deletions

File tree

drivers/pci/setup-bus.c

Lines changed: 24 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,44 +1284,41 @@ static bool pbus_upstream_space_available(struct pci_bus *bus,
12841284
* pbus_size_mem() - Size the memory window of a given bus
12851285
*
12861286
* @bus: The bus
1287-
* @mask: Mask the resource flag, then compare it with type
1288-
* @type: The type of free resource from bridge
1289-
* @type2: Second match type
1290-
* @type3: Third match type
1287+
* @type: The type of bridge resource
12911288
* @min_size: The minimum memory window that must be allocated
12921289
* @add_size: Additional optional memory window
12931290
* @realloc_head: Track the additional memory window on this list
12941291
*
1295-
* Calculate the size of the bus and minimal alignment which guarantees
1296-
* that all child resources fit in this size.
1292+
* Calculate the size of the bus resource for @type and minimal alignment
1293+
* which guarantees that all child resources fit in this size.
12971294
*
1298-
* Return -ENOSPC if there's no available bus resource of the desired
1299-
* type. Otherwise, set the bus resource start/end to indicate the
1300-
* required size, add things to realloc_head (if supplied), and return 0.
1295+
* Set the bus resource start/end to indicate the required size if there an
1296+
* available unassigned bus resource of the desired @type.
1297+
*
1298+
* Add optional resource requests to the @realloc_head list if it is
1299+
* supplied.
13011300
*/
1302-
static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
1303-
unsigned long type, unsigned long type2,
1304-
unsigned long type3, resource_size_t min_size,
1301+
static void pbus_size_mem(struct pci_bus *bus, unsigned long type,
1302+
resource_size_t min_size,
13051303
resource_size_t add_size,
13061304
struct list_head *realloc_head)
13071305
{
13081306
struct pci_dev *dev;
13091307
resource_size_t min_align, win_align, align, size, size0, size1 = 0;
13101308
resource_size_t aligns[28]; /* Alignments from 1MB to 128TB */
13111309
int order, max_order;
1312-
struct resource *b_res = find_bus_resource_of_type(bus,
1313-
mask | IORESOURCE_PREFETCH, type);
1310+
struct resource *b_res = pbus_select_window_for_type(bus, type);
13141311
resource_size_t children_add_size = 0;
13151312
resource_size_t children_add_align = 0;
13161313
resource_size_t add_align = 0;
13171314
resource_size_t relaxed_align;
13181315

13191316
if (!b_res)
1320-
return -ENOSPC;
1317+
return;
13211318

13221319
/* If resource is already assigned, nothing more to do */
13231320
if (b_res->parent)
1324-
return 0;
1321+
return;
13251322

13261323
memset(aligns, 0, sizeof(aligns));
13271324
max_order = 0;
@@ -1338,11 +1335,9 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
13381335
if (!pdev_resources_assignable(dev) ||
13391336
!pdev_resource_should_fit(dev, r))
13401337
continue;
1341-
1342-
if ((r->flags & mask) != type &&
1343-
(r->flags & mask) != type2 &&
1344-
(r->flags & mask) != type3)
1338+
if (b_res != pbus_select_window(bus, r))
13451339
continue;
1340+
13461341
r_size = resource_size(r);
13471342

13481343
/* Put SRIOV requested res to the optional list */
@@ -1428,7 +1423,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
14281423
pci_info(bus->self, "disabling bridge window %pR to %pR (unused)\n",
14291424
b_res, &bus->busn_res);
14301425
b_res->flags |= IORESOURCE_DISABLED;
1431-
return 0;
1426+
return;
14321427
}
14331428

14341429
resource_set_range(b_res, min_align, size0);
@@ -1441,7 +1436,6 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
14411436
(unsigned long long) (size1 - size0),
14421437
(unsigned long long) add_align);
14431438
}
1444-
return 0;
14451439
}
14461440

14471441
unsigned long pci_cardbus_resource_alignment(struct resource *res)
@@ -1546,12 +1540,11 @@ static void pci_bus_size_cardbus(struct pci_bus *bus,
15461540
void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head)
15471541
{
15481542
struct pci_dev *dev;
1549-
unsigned long mask, prefmask, type2 = 0, type3 = 0;
15501543
resource_size_t additional_io_size = 0, additional_mmio_size = 0,
15511544
additional_mmio_pref_size = 0;
15521545
struct resource *pref;
15531546
struct pci_host_bridge *host;
1554-
int hdr_type, ret;
1547+
int hdr_type;
15551548

15561549
list_for_each_entry(dev, &bus->devices, bus_list) {
15571550
struct pci_bus *b = dev->subordinate;
@@ -1601,71 +1594,15 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head)
16011594
pbus_size_io(bus, realloc_head ? 0 : additional_io_size,
16021595
additional_io_size, realloc_head);
16031596

1604-
/*
1605-
* If there's a 64-bit prefetchable MMIO window, compute
1606-
* the size required to put all 64-bit prefetchable
1607-
* resources in it.
1608-
*/
1609-
mask = IORESOURCE_MEM;
1610-
prefmask = IORESOURCE_MEM | IORESOURCE_PREFETCH;
1611-
if (pref && (pref->flags & IORESOURCE_MEM_64)) {
1612-
prefmask |= IORESOURCE_MEM_64;
1613-
ret = pbus_size_mem(bus, prefmask, prefmask,
1614-
prefmask, prefmask,
1615-
realloc_head ? 0 : additional_mmio_pref_size,
1616-
additional_mmio_pref_size, realloc_head);
1617-
1618-
/*
1619-
* If successful, all non-prefetchable resources
1620-
* and any 32-bit prefetchable resources will go in
1621-
* the non-prefetchable window.
1622-
*/
1623-
if (ret == 0) {
1624-
mask = prefmask;
1625-
type2 = prefmask & ~IORESOURCE_MEM_64;
1626-
type3 = prefmask & ~IORESOURCE_PREFETCH;
1627-
}
1628-
}
1629-
1630-
/*
1631-
* If there is no 64-bit prefetchable window, compute the
1632-
* size required to put all prefetchable resources in the
1633-
* 32-bit prefetchable window (if there is one).
1634-
*/
1635-
if (!type2) {
1636-
prefmask &= ~IORESOURCE_MEM_64;
1637-
ret = pbus_size_mem(bus, prefmask, prefmask,
1638-
prefmask, prefmask,
1639-
realloc_head ? 0 : additional_mmio_pref_size,
1640-
additional_mmio_pref_size, realloc_head);
1641-
1642-
/*
1643-
* If successful, only non-prefetchable resources
1644-
* will go in the non-prefetchable window.
1645-
*/
1646-
if (ret == 0)
1647-
mask = prefmask;
1648-
else
1649-
additional_mmio_size += additional_mmio_pref_size;
1650-
1651-
type2 = type3 = IORESOURCE_MEM;
1597+
if (pref) {
1598+
pbus_size_mem(bus,
1599+
IORESOURCE_MEM | IORESOURCE_PREFETCH |
1600+
(pref->flags & IORESOURCE_MEM_64),
1601+
realloc_head ? 0 : additional_mmio_pref_size,
1602+
additional_mmio_pref_size, realloc_head);
16521603
}
16531604

1654-
/*
1655-
* Compute the size required to put everything else in the
1656-
* non-prefetchable window. This includes:
1657-
*
1658-
* - all non-prefetchable resources
1659-
* - 32-bit prefetchable resources if there's a 64-bit
1660-
* prefetchable window or no prefetchable window at all
1661-
* - 64-bit prefetchable resources if there's no prefetchable
1662-
* window at all
1663-
*
1664-
* Note that the strategy in __pci_assign_resource() must match
1665-
* that used here. Specifically, we cannot put a 32-bit
1666-
* prefetchable resource in a 64-bit prefetchable window.
1667-
*/
1668-
pbus_size_mem(bus, mask, IORESOURCE_MEM, type2, type3,
1605+
pbus_size_mem(bus, IORESOURCE_MEM,
16691606
realloc_head ? 0 : additional_mmio_size,
16701607
additional_mmio_size, realloc_head);
16711608
break;

0 commit comments

Comments
 (0)