From nobody Sat Oct 4 00:21:56 2025 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8151D2C0262; Fri, 22 Aug 2025 14:59:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874747; cv=none; b=fVxL8hLBeSkH/v6QShTXX9lI5u4H9L3LkzE8n7rqxR9GtLwIvoB718+q6VqWyaowcIzYWxek2g0ecPMVH4Ja9w7sFiKWCNh8uJNDRQMFoMsfgO5wuLNiCh3Vytva+q7WtZvLWDQTN1jTlNoYbSEF2oeAyRsP9wawlLeMG0pS9P8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874747; c=relaxed/simple; bh=zEebpfWhIu4kEBCI6/4Upo0OygKQhbBhWc3ZzCti864=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=SpCIKS1EvuLxTduOrEqLW2mOTlyRPsyj+4XZOjFjoAjOX+DYy4QxFjxODHfeFOWh/ynLiR6Co8KIkPanwk9HYXbqnCZouqgwiwpm51uA9Ucye0jJTYBNBuE+UOsOdK/K3YNnYEWkbWzTqzsxycFsRyvDhR0MMUGG2CkeZmlIQs8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=FkMyLw+5; arc=none smtp.client-ip=192.198.163.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="FkMyLw+5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1755874745; x=1787410745; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zEebpfWhIu4kEBCI6/4Upo0OygKQhbBhWc3ZzCti864=; b=FkMyLw+5zCjD5Decux8++2EVPLw/YL7Cbdo5UR6PS5g8SXaXKwhUfO+C VtxEqDY2T2dTI9VLMxJTnYarMwyDzuIM00FeNLiJdCBnG9kW24fpYlOY9 xASSqaNM0ehx2kiwMFbuBquLerWjWOrShltQVbYziYleDOiCmdl7UEyPT hbzto9R6ovkGCWXaq7Em+qRlV/x7OXX7R599Wm2+OuhzbhzwF5xgEZ+BG 9n9En9AG29PvIfho602oYo/65/6C7GfmoEZQvPyxhu4U1bIOb5wyL/urM 3mSu6TIy8BYy8vkQ2c7sJIblp6NWHUfafsR3t7v/sahulY0hIT/kocXBj g==; X-CSE-ConnectionGUID: sl+xw+4rRzagvPUAeuL4Yg== X-CSE-MsgGUID: pE2HYdhMR6CuY5aTlh8Ulg== X-IronPort-AV: E=McAfee;i="6800,10657,11529"; a="57201554" X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="57201554" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:59:04 -0700 X-CSE-ConnectionGUID: LJ5O817yQ/6u/ta8++jQNg== X-CSE-MsgGUID: DLoNXUW9R/asIEjMWY+u8A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="199695276" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.244.115]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:58:59 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: Andreas Larsson , Bjorn Helgaas , "David S. Miller" , Geert Uytterhoeven , linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-pci@vger.kernel.org, sparclinux@vger.kernel.org, Thomas Bogendoerfer , =?UTF-8?q?Christian=20K=C3=B6nig?= , Yinghai Lu , Igor Mammedov , "Rafael J . Wysocki" , Jonathan Cameron , Lorenzo Pieralisi , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Micha=C5=82=20Winiarski?= , linuxppc-dev@lists.ozlabs.org, =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH 18/24] PCI: Use pbus_select_window() in space available checker Date: Fri, 22 Aug 2025 17:55:59 +0300 Message-Id: <20250822145605.18172-19-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250822145605.18172-1-ilpo.jarvinen@linux.intel.com> References: <20250822145605.18172-1-ilpo.jarvinen@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=C3=A4rvinen --- drivers/pci/setup-bus.c | 63 ++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index dac0f0f0360b..281ca5c73c97 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1221,19 +1221,20 @@ static inline resource_size_t calculate_mem_align(r= esource_size_t *aligns, /** * pbus_upstream_space_available - Check no upstream resource limits alloc= ation * @bus: The bus - * @mask: Mask the resource flag, then compare it with type - * @type: The type of resource from bridge + * @res: The resource to help to pick the correct bridge window * @size: The size required from the bridge window * @align: Required alignment for the resource * * Checks that @size can fit inside the upstream bridge resources that are - * already assigned. + * already assigned. @res (its type) is used to select to correct upstream + * bridge window. * * Return: %true if enough space is available on all assigned upstream * resources. */ -static bool pbus_upstream_space_available(struct pci_bus *bus, unsigned lo= ng mask, - unsigned long type, resource_size_t size, +static bool pbus_upstream_space_available(struct pci_bus *bus, + struct resource *res, + resource_size_t size, resource_size_t align) { struct resource_constraint constraint =3D { @@ -1241,39 +1242,39 @@ static bool pbus_upstream_space_available(struct pc= i_bus *bus, unsigned long mas .align =3D align, }; struct pci_bus *downstream =3D bus; - struct resource *res; =20 while ((bus =3D bus->parent)) { if (pci_is_root_bus(bus)) break; =20 - pci_bus_for_each_resource(bus, res) { - if (!res || !res->parent || (res->flags & mask) !=3D type) - continue; - - if (resource_size(res) >=3D size) { - struct resource gap =3D {}; + res =3D pbus_select_window(bus, res); + if (!res) + return false; + if (!res->parent) + continue; =20 - if (find_resource_space(res, &gap, size, &constraint) =3D=3D 0) { - gap.flags =3D type; - pci_dbg(bus->self, - "Assigned bridge window %pR to %pR free space at %pR\n", - res, &bus->busn_res, &gap); - return true; - } - } + if (resource_size(res) >=3D size) { + struct resource gap =3D {}; =20 - if (bus->self) { - pci_info(bus->self, - "Assigned bridge window %pR to %pR cannot fit 0x%llx required for %s= bridging to %pR\n", - res, &bus->busn_res, - (unsigned long long)size, - pci_name(downstream->self), - &downstream->busn_res); + if (find_resource_space(res, &gap, size, &constraint) =3D=3D 0) { + gap.flags =3D res->flags; + pci_dbg(bus->self, + "Assigned bridge window %pR to %pR free space at %pR\n", + res, &bus->busn_res, &gap); + return true; } + } =20 - return false; + if (bus->self) { + pci_info(bus->self, + "Assigned bridge window %pR to %pR cannot fit 0x%llx required for %s = bridging to %pR\n", + res, &bus->busn_res, + (unsigned long long)size, + pci_name(downstream->self), + &downstream->busn_res); } + + return false; } =20 return true; @@ -1395,8 +1396,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigne= d long mask, b_res->flags &=3D ~IORESOURCE_DISABLED; =20 if (bus->self && size0 && - !pbus_upstream_space_available(bus, mask | IORESOURCE_PREFETCH, type, - size0, min_align)) { + !pbus_upstream_space_available(bus, b_res, size0, min_align)) { relaxed_align =3D 1ULL << (max_order + __ffs(SZ_1M)); relaxed_align =3D max(relaxed_align, win_align); min_align =3D min(min_align, relaxed_align); @@ -1411,8 +1411,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigne= d long mask, resource_size(b_res), add_align); =20 if (bus->self && size1 && - !pbus_upstream_space_available(bus, mask | IORESOURCE_PREFETCH, type, - size1, add_align)) { + !pbus_upstream_space_available(bus, b_res, size1, add_align)) { relaxed_align =3D 1ULL << (max_order + __ffs(SZ_1M)); relaxed_align =3D max(relaxed_align, win_align); min_align =3D min(min_align, relaxed_align); --=20 2.39.5