Skip to content

Commit 13016e1

Browse files
ij-intelbjorn-helgaas
authored andcommitted
PCI: Use pbus_select_window() in space available checker
pbus_upstream_space_available() figures out the upstream bridge window resources on its own. Migrate it to use pbus_select_window(). Note: pbus_select_window() -> pbus_select_window_for_type() calls find_bus_resource_of_type() for root bus, which does not do parent check similar to what pbus_upstream_space_available() did earlier, but the difference does not matter because pbus_upstream_space_available() itself stops when it encounters the root bus. 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-19-ilpo.jarvinen@linux.intel.com
1 parent da07881 commit 13016e1

1 file changed

Lines changed: 32 additions & 33 deletions

File tree

drivers/pci/setup-bus.c

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,59 +1221,60 @@ static inline resource_size_t calculate_mem_align(resource_size_t *aligns,
12211221
/**
12221222
* pbus_upstream_space_available - Check no upstream resource limits allocation
12231223
* @bus: The bus
1224-
* @mask: Mask the resource flag, then compare it with type
1225-
* @type: The type of resource from bridge
1224+
* @res: The resource to help select the correct bridge window
12261225
* @size: The size required from the bridge window
12271226
* @align: Required alignment for the resource
12281227
*
1229-
* Checks that @size can fit inside the upstream bridge resources that are
1230-
* already assigned.
1228+
* Check that @size can fit inside the upstream bridge resources that are
1229+
* already assigned. Select the upstream bridge window based on the type of
1230+
* @res.
12311231
*
12321232
* Return: %true if enough space is available on all assigned upstream
12331233
* resources.
12341234
*/
1235-
static bool pbus_upstream_space_available(struct pci_bus *bus, unsigned long mask,
1236-
unsigned long type, resource_size_t size,
1235+
static bool pbus_upstream_space_available(struct pci_bus *bus,
1236+
struct resource *res,
1237+
resource_size_t size,
12371238
resource_size_t align)
12381239
{
12391240
struct resource_constraint constraint = {
12401241
.max = RESOURCE_SIZE_MAX,
12411242
.align = align,
12421243
};
12431244
struct pci_bus *downstream = bus;
1244-
struct resource *res;
12451245

12461246
while ((bus = bus->parent)) {
12471247
if (pci_is_root_bus(bus))
12481248
break;
12491249

1250-
pci_bus_for_each_resource(bus, res) {
1251-
if (!res || !res->parent || (res->flags & mask) != type)
1252-
continue;
1253-
1254-
if (resource_size(res) >= size) {
1255-
struct resource gap = {};
1250+
res = pbus_select_window(bus, res);
1251+
if (!res)
1252+
return false;
1253+
if (!res->parent)
1254+
continue;
12561255

1257-
if (find_resource_space(res, &gap, size, &constraint) == 0) {
1258-
gap.flags = type;
1259-
pci_dbg(bus->self,
1260-
"Assigned bridge window %pR to %pR free space at %pR\n",
1261-
res, &bus->busn_res, &gap);
1262-
return true;
1263-
}
1264-
}
1256+
if (resource_size(res) >= size) {
1257+
struct resource gap = {};
12651258

1266-
if (bus->self) {
1267-
pci_info(bus->self,
1268-
"Assigned bridge window %pR to %pR cannot fit 0x%llx required for %s bridging to %pR\n",
1269-
res, &bus->busn_res,
1270-
(unsigned long long)size,
1271-
pci_name(downstream->self),
1272-
&downstream->busn_res);
1259+
if (find_resource_space(res, &gap, size, &constraint) == 0) {
1260+
gap.flags = res->flags;
1261+
pci_dbg(bus->self,
1262+
"Assigned bridge window %pR to %pR free space at %pR\n",
1263+
res, &bus->busn_res, &gap);
1264+
return true;
12731265
}
1266+
}
12741267

1275-
return false;
1268+
if (bus->self) {
1269+
pci_info(bus->self,
1270+
"Assigned bridge window %pR to %pR cannot fit 0x%llx required for %s bridging to %pR\n",
1271+
res, &bus->busn_res,
1272+
(unsigned long long)size,
1273+
pci_name(downstream->self),
1274+
&downstream->busn_res);
12761275
}
1276+
1277+
return false;
12771278
}
12781279

12791280
return true;
@@ -1395,8 +1396,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
13951396
b_res->flags &= ~IORESOURCE_DISABLED;
13961397

13971398
if (bus->self && size0 &&
1398-
!pbus_upstream_space_available(bus, mask | IORESOURCE_PREFETCH, type,
1399-
size0, min_align)) {
1399+
!pbus_upstream_space_available(bus, b_res, size0, min_align)) {
14001400
relaxed_align = 1ULL << (max_order + __ffs(SZ_1M));
14011401
relaxed_align = max(relaxed_align, win_align);
14021402
min_align = min(min_align, relaxed_align);
@@ -1411,8 +1411,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
14111411
resource_size(b_res), add_align);
14121412

14131413
if (bus->self && size1 &&
1414-
!pbus_upstream_space_available(bus, mask | IORESOURCE_PREFETCH, type,
1415-
size1, add_align)) {
1414+
!pbus_upstream_space_available(bus, b_res, size1, add_align)) {
14161415
relaxed_align = 1ULL << (max_order + __ffs(SZ_1M));
14171416
relaxed_align = max(relaxed_align, win_align);
14181417
min_align = min(min_align, relaxed_align);

0 commit comments

Comments
 (0)