From nobody Fri Oct 3 23:02:05 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (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 BB15F3126B6; Fri, 22 Aug 2025 14:56:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874588; cv=none; b=ufwjt/Xe1XMhr9jdF3l8vX49nhlDn8ojHKgTmbN9B98rYUhqCT05HsVVs5Gor1EKIdnmR4aS8DNR1OHGouYDe1q1QtATZZbU/XbYpu2MDr0d+XQ4DIVk0HyKKM7ULzditAwUv81DgOnI3xN+IGVpVVEA7TU0e6zjnsjxqDITuXo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874588; c=relaxed/simple; bh=x5WvhX4O8xfwMKYkjxN13ooXO03C+az2T3Yal0pKgnU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=AEt7cnqStQY3ULmOAWQjoeldvT4gKoXbXdbfYvWcT7iugZVCxyhXc5BdCNQQ1TMsdiuyuj2IuZPTyBH+RAqoWm8SbhdIXSd4pnbM1VwFaLSVzzXwJRLQB7qQAdCsr2cRQt6KIvmmyGpnlthpbLUxiB+/cwRIJQKzeOa6qYUmmXs= 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=U6jabSQ/; arc=none smtp.client-ip=198.175.65.14 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="U6jabSQ/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1755874587; x=1787410587; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=x5WvhX4O8xfwMKYkjxN13ooXO03C+az2T3Yal0pKgnU=; b=U6jabSQ/xIydUyZnlKHC5iKUIqDl1FRvpV7bkE8nW/B2ta2Zlolmzw7F kS+pv9V67Vu5fOZzHPbcjyZgVLnbC7XDlMtCbqPiVAw+LvM/ulsFsTk7A ukundmK1XZ0LAecegGcJyw0V5BJqbPIJAxatQfwBkYXwtcIYfFzRVcrR2 KzxDagZDWVQxjI4jeQ4Gs//NfYHHroS/1swrS9FGM1SU8kQ669ml4Gzax 0RDM/hO608xFPcwKaEURiEjVT8cNprOANWnhtfDCREsOse/h5qoZa8K0F QzK/J/khWaZWu63ba7oeZdaphdDtKehIHi5abOZUtwfacEtuhIMjwoQ3s g==; X-CSE-ConnectionGUID: cgFgg7F9QZmnQA/gumBr2w== X-CSE-MsgGUID: 2axb+LHZSqqg9Das9lvB4A== X-IronPort-AV: E=McAfee;i="6800,10657,11529"; a="62015713" X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="62015713" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:56:26 -0700 X-CSE-ConnectionGUID: 0i+eI+8LQqmInl7HncQ8ZQ== X-CSE-MsgGUID: YUBpK2JcQ7ytQJraYVvkOw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="173994430" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.244.115]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:56:21 -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 01/24] m68k/PCI: Use pci_enable_resources() in pcibios_enable_device() Date: Fri, 22 Aug 2025 17:55:42 +0300 Message-Id: <20250822145605.18172-2-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 m68k has a resource enable (check) loop in its pcibios_enable_device() which for some reason differs from pci_enable_resources(). This could lead to inconsistencies in behavior, especially now as pci_enable_resources() and the bridge window resource flags behavior are going to be altered by upcoming changes. The check for !r->start && r->end is already covered by the more generic checks done in pci_enable_resources(). The entire pcibios_enable_device() suspiciously looks copy-paste from some other arch as also indicated by the preceding comment. However, it also enables PCI_COMMAND_IO | PCI_COMMAND_MEMORY always for bridges, it is not clear why that is being done as the commit e93a6bbeb5a5 ("m68k: common PCI support definitions and code") introducing this code states: "Nothing specific to any PCI implementation in any m68k class CPU hardware yet". Replace the resource enable loop with a call to pci_enable_resources() and adjust the Command Register afterwards as it's unclear if that is necessary or not so keep it for now. Signed-off-by: Ilpo J=C3=A4rvinen --- arch/m68k/kernel/pcibios.c | 39 +++++++++++--------------------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/arch/m68k/kernel/pcibios.c b/arch/m68k/kernel/pcibios.c index 9504eb19d73a..e6ab3f9ff5d8 100644 --- a/arch/m68k/kernel/pcibios.c +++ b/arch/m68k/kernel/pcibios.c @@ -44,41 +44,24 @@ resource_size_t pcibios_align_resource(void *data, cons= t struct resource *res, */ int pcibios_enable_device(struct pci_dev *dev, int mask) { - struct resource *r; u16 cmd, newcmd; - int idx; + int ret; =20 - pci_read_config_word(dev, PCI_COMMAND, &cmd); - newcmd =3D cmd; - - for (idx =3D 0; idx < 6; idx++) { - /* Only set up the requested stuff */ - if (!(mask & (1 << idx))) - continue; - - r =3D dev->resource + idx; - if (!r->start && r->end) { - pr_err("PCI: Device %s not available because of resource collisions\n", - pci_name(dev)); - return -EINVAL; - } - if (r->flags & IORESOURCE_IO) - newcmd |=3D PCI_COMMAND_IO; - if (r->flags & IORESOURCE_MEM) - newcmd |=3D PCI_COMMAND_MEMORY; - } + ret =3D pci_enable_resources(dev, mask); + if (ret < 0) + return ret; =20 /* * Bridges (eg, cardbus bridges) need to be fully enabled */ - if ((dev->class >> 16) =3D=3D PCI_BASE_CLASS_BRIDGE) + if ((dev->class >> 16) =3D=3D PCI_BASE_CLASS_BRIDGE) { + pci_read_config_word(dev, PCI_COMMAND, &cmd); newcmd |=3D PCI_COMMAND_IO | PCI_COMMAND_MEMORY; - - - if (newcmd !=3D cmd) { - pr_info("PCI: enabling device %s (0x%04x -> 0x%04x)\n", - pci_name(dev), cmd, newcmd); - pci_write_config_word(dev, PCI_COMMAND, newcmd); + if (newcmd !=3D cmd) { + pr_info("PCI: enabling bridge %s (0x%04x -> 0x%04x)\n", + pci_name(dev), cmd, newcmd); + pci_write_config_word(dev, PCI_COMMAND, newcmd); + } } return 0; } --=20 2.39.5 From nobody Fri Oct 3 23:02:05 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (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 12E6D3128B1; Fri, 22 Aug 2025 14:56:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874597; cv=none; b=ojI7V7pryhLHOE62FtDMhapBEYNgzGUyCvACgCgK7WUJS3AbRH3HkZmvntoHDPyqr5uCQF0KR/v5a5rjzyi/K8vtDRH1uv5ikpD1lJqdZMNgXrov1ycYloBk8f0vo1R0rUddrCWUzkL1XrLl00hVovIps+uiyYb8yeZJ93Xwih8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874597; c=relaxed/simple; bh=bSxDSi61ISCt6N4ERv3jPARPEFvmoSF1OZejWsVVizA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=UrLeSAorqesuZQqVHR94odBO06cvT+7BcV/tSk3V1OAc7n8h9sdhDhrpFcowiMaDdFRxOtksRqgU+SKCe7a2VybQjgGA5BjuUUR6jMFHm9r6R5tmN/ldaaLrjwqJr8tEatJwLIcyx+ToxKjnZL7Wt379qhXfrg6y+AGGX7Ws5t8= 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=I0maB8j7; arc=none smtp.client-ip=198.175.65.14 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="I0maB8j7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1755874596; x=1787410596; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bSxDSi61ISCt6N4ERv3jPARPEFvmoSF1OZejWsVVizA=; b=I0maB8j7RkFHtTLUh3OUedsyWICC4kWaBB759JYbY/HzYbr/jYjSC675 YMUSGUpHKEPOl3e01WhSDBdnwHz+j4pfWzrysnGnUbVeXFS1q2v9e3/nZ zmmnafb/utzophjpWhrkaMZiUoOrTVDPXMkS9sWGtsOA9JJQjCd0x15AU z8jwFbenuZdj12sVLL2jbZlEtFaaHG0IfWJBHPziHV8vwpVLO85hKVnau Durm63DoRYMRPjRMVTd6wiSABCmarRIcukOLbSNgjnatmXEaUVQeI1I5c i0lo+3lmlmYT82BVRi+2vAemkVhNsJ8t9CfUmcLHkmXz8ubdZKuLiZJZO g==; X-CSE-ConnectionGUID: 4TaXzFmcREKF5MioTy5jsg== X-CSE-MsgGUID: oLmIHuFnQD6MoqC7/exafA== X-IronPort-AV: E=McAfee;i="6800,10657,11529"; a="62015739" X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="62015739" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:56:35 -0700 X-CSE-ConnectionGUID: x91kP381TK+YfIUNtqcyDg== X-CSE-MsgGUID: q2j8ygTuTqiZ23lnI0XmWA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="173994475" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.244.115]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:56:30 -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 02/24] sparc/PCI: Remove pcibios_enable_device() as they do nothing extra Date: Fri, 22 Aug 2025 17:55:43 +0300 Message-Id: <20250822145605.18172-3-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 Under arch/sparc/ there are multiple copies of pcibios_enable_device() but none of those seem to do anything extra beyond what pci_enable_resources() is supposed to do. These functions could lead to inconsistencies in behavior, especially now as pci_enable_resources() and the bridge window resource flags behavior are going to be altered by upcoming changes. Remove all pcibios_enable_device() from arch/sparc/ so that PCI core can simply call into pci_enable_resources() instead using it's __weak version of pcibios_enable_device(). Signed-off-by: Ilpo J=C3=A4rvinen --- arch/sparc/kernel/leon_pci.c | 27 --------------------------- arch/sparc/kernel/pci.c | 27 --------------------------- arch/sparc/kernel/pcic.c | 27 --------------------------- 3 files changed, 81 deletions(-) diff --git a/arch/sparc/kernel/leon_pci.c b/arch/sparc/kernel/leon_pci.c index 8de6646e9ce8..10934dfa987a 100644 --- a/arch/sparc/kernel/leon_pci.c +++ b/arch/sparc/kernel/leon_pci.c @@ -60,30 +60,3 @@ void leon_pci_init(struct platform_device *ofdev, struct= leon_pci_info *info) pci_assign_unassigned_resources(); pci_bus_add_devices(root_bus); } - -int pcibios_enable_device(struct pci_dev *dev, int mask) -{ - struct resource *res; - u16 cmd, oldcmd; - int i; - - pci_read_config_word(dev, PCI_COMMAND, &cmd); - oldcmd =3D cmd; - - pci_dev_for_each_resource(dev, res, i) { - /* Only set up the requested stuff */ - if (!(mask & (1<flags & IORESOURCE_IO) - cmd |=3D PCI_COMMAND_IO; - if (res->flags & IORESOURCE_MEM) - cmd |=3D PCI_COMMAND_MEMORY; - } - - if (cmd !=3D oldcmd) { - pci_info(dev, "enabling device (%04x -> %04x)\n", oldcmd, cmd); - pci_write_config_word(dev, PCI_COMMAND, cmd); - } - return 0; -} diff --git a/arch/sparc/kernel/pci.c b/arch/sparc/kernel/pci.c index ddac216a2aff..a9448088e762 100644 --- a/arch/sparc/kernel/pci.c +++ b/arch/sparc/kernel/pci.c @@ -722,33 +722,6 @@ struct pci_bus *pci_scan_one_pbm(struct pci_pbm_info *= pbm, return bus; } =20 -int pcibios_enable_device(struct pci_dev *dev, int mask) -{ - struct resource *res; - u16 cmd, oldcmd; - int i; - - pci_read_config_word(dev, PCI_COMMAND, &cmd); - oldcmd =3D cmd; - - pci_dev_for_each_resource(dev, res, i) { - /* Only set up the requested stuff */ - if (!(mask & (1<flags & IORESOURCE_IO) - cmd |=3D PCI_COMMAND_IO; - if (res->flags & IORESOURCE_MEM) - cmd |=3D PCI_COMMAND_MEMORY; - } - - if (cmd !=3D oldcmd) { - pci_info(dev, "enabling device (%04x -> %04x)\n", oldcmd, cmd); - pci_write_config_word(dev, PCI_COMMAND, cmd); - } - return 0; -} - /* Platform support for /proc/bus/pci/X/Y mmap()s. */ int pci_iobar_pfn(struct pci_dev *pdev, int bar, struct vm_area_struct *vm= a) { diff --git a/arch/sparc/kernel/pcic.c b/arch/sparc/kernel/pcic.c index 25fe0a061732..3d54ad5656a4 100644 --- a/arch/sparc/kernel/pcic.c +++ b/arch/sparc/kernel/pcic.c @@ -641,33 +641,6 @@ void pcibios_fixup_bus(struct pci_bus *bus) } } =20 -int pcibios_enable_device(struct pci_dev *dev, int mask) -{ - struct resource *res; - u16 cmd, oldcmd; - int i; - - pci_read_config_word(dev, PCI_COMMAND, &cmd); - oldcmd =3D cmd; - - pci_dev_for_each_resource(dev, res, i) { - /* Only set up the requested stuff */ - if (!(mask & (1<flags & IORESOURCE_IO) - cmd |=3D PCI_COMMAND_IO; - if (res->flags & IORESOURCE_MEM) - cmd |=3D PCI_COMMAND_MEMORY; - } - - if (cmd !=3D oldcmd) { - pci_info(dev, "enabling device (%04x -> %04x)\n", oldcmd, cmd); - pci_write_config_word(dev, PCI_COMMAND, cmd); - } - return 0; -} - /* Makes compiler happy */ static volatile int pcic_timer_dummy; =20 --=20 2.39.5 From nobody Fri Oct 3 23:02:05 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (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 3B9C4296BBA; Fri, 22 Aug 2025 14:56:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874606; cv=none; b=lBBBw3eCxYH2ramkyp50RqherEV6H4BD3QDykNcs+0Q7RfqHjR3u49rzxTu+umgy/IuRwAaqC7TWtau14TtHy/0/ehnlUZ48UMSUebsR2N2+8cwJNvVKQCOLgwFU6WEarSUtXp4C/HNvddI++Tk7/AKy1+Vl3FVqXenz4q5e0l0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874606; c=relaxed/simple; bh=jBXSW/HvE/oTFKPyIiL0xTmEeLPgXFT+lohCoGdRapA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=S50rr7pmcqdn6LBWeLq1Fx4hf+08J49YoGt8RaVtIUE49Dz5XvA6WNa5JZsOJv3IdFf7VKElZB6qT1v+mdCqw0BifhndP+M2MD83dItXkAQrbkFPYcDmlhMUJgNHuocDuiRHINkgjPch7GzgeRflmQK9y/H/pJTMXm9UibFylNg= 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=QLSl+Rxb; arc=none smtp.client-ip=198.175.65.14 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="QLSl+Rxb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1755874605; x=1787410605; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jBXSW/HvE/oTFKPyIiL0xTmEeLPgXFT+lohCoGdRapA=; b=QLSl+RxbnrFjAbYJPYO6BN5GS7HWHQtGTgm7y4cGWGwUl0t9ef9txcL1 O7iu8qzKZX5g47lPqc19GcNM+LsCfdGRmHnvtJZTYKA3J6wu4Fu4z8kCs oPPhJkD0NmZ0Kc7zzR4sbMY35GRpq89/grwafHQaRotBYHEuZIiPo+/2M lhF1aMsGg0jTA4GC0BlJJveBeWxDnsq0WBd9kBZw5aEBs4lnYXr2GNEMF 011M/g5k+SkWxHQhSTpQyl8ft7ZjxGb2kInSwoEc6ewCE91VDgauDFkyk T7DVuW1JLbYVG7t+hFzodKCgsU3uIZsQEGCWZwmnV0W3sBGh3jjXHiAPo Q==; X-CSE-ConnectionGUID: oCnHBOs6QBWq+NesGVlJkw== X-CSE-MsgGUID: cjFlEEcUQgmSYmgCAa4Yrg== X-IronPort-AV: E=McAfee;i="6800,10657,11529"; a="62015777" X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="62015777" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:56:45 -0700 X-CSE-ConnectionGUID: ixYcXxcpSP2pUy6rUGsbsQ== X-CSE-MsgGUID: FOhRjr0IQkSfd3SUorEZlw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="173994552" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.244.115]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:56:39 -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 03/24] MIPS: PCI: Use pci_enable_resources() Date: Fri, 22 Aug 2025 17:55:44 +0300 Message-Id: <20250822145605.18172-4-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 pci-legacy.c under MIPS has a copy of pci_enable_resources() named as pcibios_enable_resources(). Having own copy of same functionality could lead to inconsistencies in behavior, especially now as pci_enable_resources() and the bridge window resource flags behavior are going to be altered by upcoming changes. The check for !r->start && r->end is already covered by the more generic checks done in pci_enable_resources(). Call pci_enable_resources() from MIPS's pcibios_enable_device() and remove pcibios_enable_resources(). Signed-off-by: Ilpo J=C3=A4rvinen Acked-by: Thomas Bogendoerfer --- arch/mips/pci/pci-legacy.c | 38 ++------------------------------------ 1 file changed, 2 insertions(+), 36 deletions(-) diff --git a/arch/mips/pci/pci-legacy.c b/arch/mips/pci/pci-legacy.c index 66898fd182dc..d04b7c1294b6 100644 --- a/arch/mips/pci/pci-legacy.c +++ b/arch/mips/pci/pci-legacy.c @@ -249,45 +249,11 @@ static int __init pcibios_init(void) =20 subsys_initcall(pcibios_init); =20 -static int pcibios_enable_resources(struct pci_dev *dev, int mask) -{ - u16 cmd, old_cmd; - int idx; - struct resource *r; - - pci_read_config_word(dev, PCI_COMMAND, &cmd); - old_cmd =3D cmd; - pci_dev_for_each_resource(dev, r, idx) { - /* Only set up the requested stuff */ - if (!(mask & (1<flags & (IORESOURCE_IO | IORESOURCE_MEM))) - continue; - if ((idx =3D=3D PCI_ROM_RESOURCE) && - (!(r->flags & IORESOURCE_ROM_ENABLE))) - continue; - if (!r->start && r->end) { - pci_err(dev, - "can't enable device: resource collisions\n"); - return -EINVAL; - } - if (r->flags & IORESOURCE_IO) - cmd |=3D PCI_COMMAND_IO; - if (r->flags & IORESOURCE_MEM) - cmd |=3D PCI_COMMAND_MEMORY; - } - if (cmd !=3D old_cmd) { - pci_info(dev, "enabling device (%04x -> %04x)\n", old_cmd, cmd); - pci_write_config_word(dev, PCI_COMMAND, cmd); - } - return 0; -} - int pcibios_enable_device(struct pci_dev *dev, int mask) { - int err =3D pcibios_enable_resources(dev, mask); + int err; =20 + err =3D pci_enable_resources(dev, mask); if (err < 0) return err; =20 --=20 2.39.5 From nobody Fri Oct 3 23:02:05 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (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 2BBF827932D; Fri, 22 Aug 2025 14:56:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874615; cv=none; b=d0aWPrZNJHzKTtt79ooQkGAYtMm6TPCCby5OWGc3SAwNdmn6z3OQxdxv85wC7hfKNp7m/DUaFNc+GcvuGgqToFxlE5x+/tCXeACZs9S/W0pecfmTyZlPWC8o1ncAlpLbAHhlhG4yioYHI1bOlcvY1GAFnJKHpo4p7aZeys0HxEE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874615; c=relaxed/simple; bh=qAXdsDQW9N/Uavlh8yIRORIBMsvqG965+7HiERcw2Bc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=eIuGbbjmD9hiTc8oPixgXzSximDGQcNI9Oe8qXdjL+/lzEKF/1Xtio1dEOwo/EMnEh7EfyRnouJwAhhmtZNzhuTVEbVgYeiWsSz6K3X0RZI1d6Ezmzk7kkrQlze/xu9UXfSEeB2SD3VOvrZe5Vt1vWIBbDb0kTFzPFEB64CzU5I= 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=YnyEMerB; arc=none smtp.client-ip=198.175.65.14 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="YnyEMerB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1755874614; x=1787410614; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qAXdsDQW9N/Uavlh8yIRORIBMsvqG965+7HiERcw2Bc=; b=YnyEMerBNyD/4gckm2MVWTFOs5AMuXXv8Wau9F73CAahRlt35PDeHx9I Px3AM4ocW9tA/3qjyNU9bd95lhG2+Vh2jhOmHhkfhpQkrW8VgkVAcykRw nsxV3ILroXjzFmmkX2ZeRfGmNTNaA5sXN2oTEpY2wpgpKLk/5iVCJcBmq eh+VJDApefXCQUjbJddmcJJIrN8WgcGEdtPb4zwNfJEk1wHPdXAoeCVgz faMXYBI99DilYEojClYM9IYT/TcM6lXZtfiyk0Q8wWxO61tjdob0+mNlh 3vMIW/RYF1agdstDSjTZGkahsftBGQRMCuA2UYmbjosJVBD+wPhqbxzX8 A==; X-CSE-ConnectionGUID: rIEsbMO6S62om6g/4qIuQQ== X-CSE-MsgGUID: 5mKEKGASTRSbz241p1wslg== X-IronPort-AV: E=McAfee;i="6800,10657,11529"; a="62015793" X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="62015793" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:56:54 -0700 X-CSE-ConnectionGUID: lzEm3K2FR72KwstWyYHG9Q== X-CSE-MsgGUID: TakxZF6vRGWLwfxTYMc+bA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="173994571" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.244.115]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:56:49 -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 04/24] PCI: Move find_bus_resource_of_type() earlier Date: Fri, 22 Aug 2025 17:55:45 +0300 Message-Id: <20250822145605.18172-5-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 Move find_bus_resource_of_type() earlier in setup-bus.c to be able to call it in upcoming changes. Signed-off-by: Ilpo J=C3=A4rvinen --- drivers/pci/setup-bus.c | 56 ++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index def29506700e..4097d8703b8f 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -140,6 +140,34 @@ static void restore_dev_resource(struct pci_dev_resour= ce *dev_res) res->flags =3D dev_res->flags; } =20 +/* + * Helper function for sizing routines. Assigned resources have non-NULL + * parent resource. + * + * Return first unassigned resource of the correct type. If there is none, + * return first assigned resource of the correct type. If none of the + * above, return NULL. + * + * Returning an assigned resource of the correct type allows the caller to + * distinguish between already assigned and no resource of the correct typ= e. + */ +static struct resource *find_bus_resource_of_type(struct pci_bus *bus, + unsigned long type_mask, + unsigned long type) +{ + struct resource *r, *r_assigned =3D NULL; + + pci_bus_for_each_resource(bus, r) { + if (r =3D=3D &ioport_resource || r =3D=3D &iomem_resource) + continue; + if (r && (r->flags & type_mask) =3D=3D type && !r->parent) + return r; + if (r && (r->flags & type_mask) =3D=3D type && !r_assigned) + r_assigned =3D r; + } + return r_assigned; +} + static bool pdev_resources_assignable(struct pci_dev *dev) { u16 class =3D dev->class >> 8, command; @@ -876,34 +904,6 @@ static void pci_bridge_check_ranges(struct pci_bus *bu= s) } } =20 -/* - * Helper function for sizing routines. Assigned resources have non-NULL - * parent resource. - * - * Return first unassigned resource of the correct type. If there is none, - * return first assigned resource of the correct type. If none of the - * above, return NULL. - * - * Returning an assigned resource of the correct type allows the caller to - * distinguish between already assigned and no resource of the correct typ= e. - */ -static struct resource *find_bus_resource_of_type(struct pci_bus *bus, - unsigned long type_mask, - unsigned long type) -{ - struct resource *r, *r_assigned =3D NULL; - - pci_bus_for_each_resource(bus, r) { - if (r =3D=3D &ioport_resource || r =3D=3D &iomem_resource) - continue; - if (r && (r->flags & type_mask) =3D=3D type && !r->parent) - return r; - if (r && (r->flags & type_mask) =3D=3D type && !r_assigned) - r_assigned =3D r; - } - return r_assigned; -} - static resource_size_t calculate_iosize(resource_size_t size, resource_size_t min_size, resource_size_t size1, --=20 2.39.5 From nobody Fri Oct 3 23:02:05 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (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 5B9CD239E88; Fri, 22 Aug 2025 14:57:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874624; cv=none; b=MagKWGPRUqoc/LFpnaBOhAdiNA2+UsSsTu8PJQ0D/Eor8dWAj2R6IUoBUVF67gvL+bqXuo83mAYjlTJZyd/MG/p0Lm/yTHCjLzHFAOPBsfr4+ESxMJ9FXZ0NH1xldsMiC+HGUr+5bG0jM5lEsv+8z7xDK/7/j4+yJ4RbnC3sxUE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874624; c=relaxed/simple; bh=wPDvnWZ5n/ZzruRde5Pq3zT/XPnm5sbjNx2qOymBYfE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=j8EKpllvKm0543kTpfOq+ZWdBd9iVLKI8EWjvOEMNbpecJG0ivHYrF/P1uqaQk7N0iCxyuX7RM3j22jv+vdI3Uq/YnUOltBnfX0hhoU6Mfv3wrrNa29Nw32ZD/SQr2Ls/mEPJGuUjUBy4LfwkDBG8PEV1QMvIiBNDBaXqctx9qw= 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=Ho0rXgx2; arc=none smtp.client-ip=198.175.65.13 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="Ho0rXgx2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1755874623; x=1787410623; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wPDvnWZ5n/ZzruRde5Pq3zT/XPnm5sbjNx2qOymBYfE=; b=Ho0rXgx25tzf4cple4tEoHtQOM2hSyWpyVbRQ7QhnDZUbiActgyHRhwl lc49e0x+wFkNsZJZgbxf9GquJ2z6nAheXIGKMPQ3etnZw5Aiy1QhMXlt9 i5sJd9IqC5c8PSGFxBQ4gd5i4w6fDUlUdEdrqWhWunE/Y3tRlNQUIRHmD GMsk646mAkZpJpoEshakqHWYXl6kppnP3t0hyoTIlhscNgoXwPLQvXnom nbCCFoYTaKduFnZoE9Q6O/vA4qY5GxO249Asu5l8NHt5PK9gZzwzZrXI1 hn0SfO3G0pUBJFxTTQaRhMyid68KOpzf0cz5GYnpAGMWg5nq7vla272JK A==; X-CSE-ConnectionGUID: o7rmB9oBR7STnKGbiilYiA== X-CSE-MsgGUID: DeGJ2uogTMKkI0IedVuMhg== X-IronPort-AV: E=McAfee;i="6800,10657,11529"; a="69283117" X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="69283117" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:57:03 -0700 X-CSE-ConnectionGUID: qiJ59XlaQtqa4e+Z9uM3dw== X-CSE-MsgGUID: tW3R/pfDT4eAbXWbFFh3og== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="169547004" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.244.115]) by fmviesa010-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:56:58 -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 05/24] PCI: Refactor find_bus_resource_of_type() logic checks Date: Fri, 22 Aug 2025 17:55:46 +0300 Message-Id: <20250822145605.18172-6-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 The logic checks can be simplified in find_bus_resource_of_type() by reordering them. Signed-off-by: Ilpo J=C3=A4rvinen --- drivers/pci/setup-bus.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 4097d8703b8f..c5fc4e2825be 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -158,11 +158,15 @@ static struct resource *find_bus_resource_of_type(str= uct pci_bus *bus, struct resource *r, *r_assigned =3D NULL; =20 pci_bus_for_each_resource(bus, r) { - if (r =3D=3D &ioport_resource || r =3D=3D &iomem_resource) + if (!r || r =3D=3D &ioport_resource || r =3D=3D &iomem_resource) continue; - if (r && (r->flags & type_mask) =3D=3D type && !r->parent) + + if ((r->flags & type_mask) !=3D type) + continue; + + if (!r->parent) return r; - if (r && (r->flags & type_mask) =3D=3D type && !r_assigned) + if (!r_assigned) r_assigned =3D r; } return r_assigned; --=20 2.39.5 From nobody Fri Oct 3 23:02:05 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (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 CAF96310624; Fri, 22 Aug 2025 14:57:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874633; cv=none; b=REHjdP8TASU1rIw7VXvQqw1PMNrI8U4M626/bC/wgAICloouxDcdnjLaR/4jI3fBMN8cfSH7AZjNxwzVR8LQZRtY3vcZCYeyYivplx3A9+/cdf1v4e/EAYqbYlAXOyhsUG2o/WVv+LmIFmzNZCiLGC2bKceIxJU0rvRuwX8OsIE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874633; c=relaxed/simple; bh=ee6ivqpcnefQPqKlLb6mSNrXVqSqgxwUEWQuLhjZ8qY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=fbRQcbWtNaG0MKx1CKS9g3OmW/Ws70hy/wMZWMJ4vdCKTGdXZgsmq/wGkk4PWgVNFr/ogs9VXB6OAZ90leN1GBHjLi9Cw3r0CBLIdM/fwOIYsiav86wquIBE4aaSUEyGgHCy+7klj9L3rI0ABcuUB9TFa2eiMhX2skWL9vZmEag= 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=WhByaq4c; arc=none smtp.client-ip=198.175.65.13 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="WhByaq4c" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1755874632; x=1787410632; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ee6ivqpcnefQPqKlLb6mSNrXVqSqgxwUEWQuLhjZ8qY=; b=WhByaq4clo2Ag+fGhbswuzOUD1SweoCiYjGVJ6ewtS+LOoxJ/U7bWbpQ BLkvwuJ9FgQO/+0yKaE2Cq7bR+MJ5DrsKX47oyf6S2yhDMeHq1FB5vhs/ pjNxYxQ/vfDyaVwTj26OCD/eTLiMlK2WWUqk9fKLBjajZf88xM3mfql2S vTILsE8QPx8ROBxYzaTNTP0V1DgR0NFtVys0Q/FbKgRXbj/Zff2hTJEq8 T3sl/3Bjff0neiFUA33iXDaNpLuQwf7JsYv8ZCuGkVc+FA0y0I3URnWSf KZRp/PtC0MGqaFRa6dT/KVi/ja8iY+0eg21oy5G5o7h8rWc2vDj+7B4iO A==; X-CSE-ConnectionGUID: c1CqQ8IzTwO5CEeJCP4HNA== X-CSE-MsgGUID: ocHR2MOMTpGS3i3XfamfqQ== X-IronPort-AV: E=McAfee;i="6800,10657,11529"; a="69283127" X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="69283127" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:57:11 -0700 X-CSE-ConnectionGUID: MCHsPL/ZRuqfR30RXNcprQ== X-CSE-MsgGUID: LlCQKywETQWGsfuL1uTiAQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="169547072" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.244.115]) by fmviesa010-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:57:07 -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 06/24] PCI: Always claim bridge window before its setup Date: Fri, 22 Aug 2025 17:55:47 +0300 Message-Id: <20250822145605.18172-7-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 When the claim of a resource fails for the full range in pci_claim_bridge_resource(), clipping the resource to a smaller size is attempted. If the clipping successful, the new bridge window is programmed and only as the last step the code attempts to claim the resource again. The order of the last two steps is slightly illogical and inconsistent with the assignment call chains. If claiming the bridge window after clipping fails, the bridge window that was setup is left in place. Rework the logic such that the bridge window is claimed before calling the relevant bridge setup function. This make the behavior consistent with resource fitting call chains that always assign the bridge window before programming it. If claiming the bridge window fails, the clipped bridge window is no longer setup but pci_claim_bridge_resource() returns without writing the bridge window at all. Signed-off-by: Ilpo J=C3=A4rvinen --- drivers/pci/setup-bus.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index c5fc4e2825be..b477f68b236c 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -857,9 +857,16 @@ int pci_claim_bridge_resource(struct pci_dev *bridge, = int i) if ((bridge->class >> 8) !=3D PCI_CLASS_BRIDGE_PCI) return 0; =20 + if (i > PCI_BRIDGE_PREF_MEM_WINDOW) + return -EINVAL; + + /* Try to clip the resource and claim the smaller window */ if (!pci_bus_clip_resource(bridge, i)) return -EINVAL; /* Clipping didn't change anything */ =20 + if (!pci_claim_resource(bridge, i)) + return -EINVAL; + switch (i) { case PCI_BRIDGE_IO_WINDOW: pci_setup_bridge_io(bridge); @@ -874,10 +881,7 @@ int pci_claim_bridge_resource(struct pci_dev *bridge, = int i) return -EINVAL; } =20 - if (pci_claim_resource(bridge, i) =3D=3D 0) - return 0; /* Claimed a smaller window */ - - return -EINVAL; + return 0; } =20 /* --=20 2.39.5 From nobody Fri Oct 3 23:02:05 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (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 29EE2321F4A; Fri, 22 Aug 2025 14:57:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874642; cv=none; b=P9EQBGAvwfhNhc+9+t98b1xTJwlTkFpp/qifX6cF85EKYiYvxSeoeQkapUnifEBgHy3FzpqcKwuRdGY8u5BGNy8j2dLwyOnCgD04D71Iip7ZX8VpsObfUSNpkfB7B1K8VEC1hbUawb434YDGae5Oa0hFK97nZBUU9i8jhICbYuY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874642; c=relaxed/simple; bh=gchIaEGGMd1rP3k9+ZAelZgSdhp5C6iJlv32uxG+nxU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=PLuNyDdLY7654w7wv+uUsvXk34OFzPfuKp3uYf38BxgFhI0qc/p6CuvWI3drnfQi9q6uWRFV30L/wAVEbXXanfxTE7RELWy3cVP21tFuYwia3hJ0f+bR9D3s+WwoSPSI/5+QhvwllliWvg6yYUwQDNVEOoMUcZ4VY0xfmr2yiEA= 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=mDV1WeRD; arc=none smtp.client-ip=198.175.65.13 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="mDV1WeRD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1755874641; x=1787410641; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gchIaEGGMd1rP3k9+ZAelZgSdhp5C6iJlv32uxG+nxU=; b=mDV1WeRDiJGu333qJ6WfQe1jipzw53tuRmMiLBM4WHTSOVk/W3V1QpZL 5kmFKErxyEjgEVx9hec54svhAZ2mEgkkt9V8gCUDztUXpHHJMaq/faimZ AENbXrWfOqTgodi6sGRBM1dmn+YWVRHp1uhKvJcKBaYwWstx9mUeZ4RjP YfyYjYlwKXyZapFX8udV8/uu5gAYIBCIgtJGwjiPHMCbiiVIyn4pPXMtG F7Ja4Tcsf7rE516443/Xi2VPRzZeung16EVitiYK80y8PnBNddHBA2aAY YvoIvYO/i+ARkkQ2MQaqoS4BAS0xhfucHkVyDemwyImPjDofsUEO9zeJG w==; X-CSE-ConnectionGUID: xyfnfbsdQYa5D76wjzJgaA== X-CSE-MsgGUID: WuhRvz78QjW7Z0xKyq4iVw== X-IronPort-AV: E=McAfee;i="6800,10657,11529"; a="69283146" X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="69283146" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:57:21 -0700 X-CSE-ConnectionGUID: ypkw906bTXqIvRPHTHdqxg== X-CSE-MsgGUID: VaLoVjPPS6WX/H2vbHvugw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="169547108" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.244.115]) by fmviesa010-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:57:16 -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 07/24] PCI: Disable non-claimed bridge window Date: Fri, 22 Aug 2025 17:55:48 +0300 Message-Id: <20250822145605.18172-8-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 If clipping or claiming the bridge window fails, the bridge window is left into a state that does not match with the kernel's view on what the bridge window is. Disable the bridge window by writing the magic disable value into the Base and Limit Registers if clipping or claiming failed. To detect if claiming the resource was successful, add res->parent checks into the bridge setup functions. Signed-off-by: Ilpo J=C3=A4rvinen --- drivers/pci/setup-bus.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index b477f68b236c..6bdc1af887da 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -660,7 +660,7 @@ void pci_setup_cardbus(struct pci_bus *bus) =20 res =3D bus->resource[0]; pcibios_resource_to_bus(bridge->bus, ®ion, res); - if (res->flags & IORESOURCE_IO) { + if (res->parent && res->flags & IORESOURCE_IO) { /* * The IO resource is allocated a range twice as large as it * would normally need. This allows us to set both IO regs. @@ -674,7 +674,7 @@ void pci_setup_cardbus(struct pci_bus *bus) =20 res =3D bus->resource[1]; pcibios_resource_to_bus(bridge->bus, ®ion, res); - if (res->flags & IORESOURCE_IO) { + if (res->parent && res->flags & IORESOURCE_IO) { pci_info(bridge, " bridge window %pR\n", res); pci_write_config_dword(bridge, PCI_CB_IO_BASE_1, region.start); @@ -684,7 +684,7 @@ void pci_setup_cardbus(struct pci_bus *bus) =20 res =3D bus->resource[2]; pcibios_resource_to_bus(bridge->bus, ®ion, res); - if (res->flags & IORESOURCE_MEM) { + if (res->parent && res->flags & IORESOURCE_MEM) { pci_info(bridge, " bridge window %pR\n", res); pci_write_config_dword(bridge, PCI_CB_MEMORY_BASE_0, region.start); @@ -694,7 +694,7 @@ void pci_setup_cardbus(struct pci_bus *bus) =20 res =3D bus->resource[3]; pcibios_resource_to_bus(bridge->bus, ®ion, res); - if (res->flags & IORESOURCE_MEM) { + if (res->parent && res->flags & IORESOURCE_MEM) { pci_info(bridge, " bridge window %pR\n", res); pci_write_config_dword(bridge, PCI_CB_MEMORY_BASE_1, region.start); @@ -735,7 +735,7 @@ static void pci_setup_bridge_io(struct pci_dev *bridge) res =3D &bridge->resource[PCI_BRIDGE_IO_WINDOW]; res_name =3D pci_resource_name(bridge, PCI_BRIDGE_IO_WINDOW); pcibios_resource_to_bus(bridge->bus, ®ion, res); - if (res->flags & IORESOURCE_IO) { + if (res->parent && res->flags & IORESOURCE_IO) { pci_read_config_word(bridge, PCI_IO_BASE, &l); io_base_lo =3D (region.start >> 8) & io_mask; io_limit_lo =3D (region.end >> 8) & io_mask; @@ -767,7 +767,7 @@ static void pci_setup_bridge_mmio(struct pci_dev *bridg= e) res =3D &bridge->resource[PCI_BRIDGE_MEM_WINDOW]; res_name =3D pci_resource_name(bridge, PCI_BRIDGE_MEM_WINDOW); pcibios_resource_to_bus(bridge->bus, ®ion, res); - if (res->flags & IORESOURCE_MEM) { + if (res->parent && res->flags & IORESOURCE_MEM) { l =3D (region.start >> 16) & 0xfff0; l |=3D region.end & 0xfff00000; pci_info(bridge, " %s %pR\n", res_name, res); @@ -796,7 +796,7 @@ static void pci_setup_bridge_mmio_pref(struct pci_dev *= bridge) res =3D &bridge->resource[PCI_BRIDGE_PREF_MEM_WINDOW]; res_name =3D pci_resource_name(bridge, PCI_BRIDGE_PREF_MEM_WINDOW); pcibios_resource_to_bus(bridge->bus, ®ion, res); - if (res->flags & IORESOURCE_PREFETCH) { + if (res->parent && res->flags & IORESOURCE_PREFETCH) { l =3D (region.start >> 16) & 0xfff0; l |=3D region.end & 0xfff00000; if (res->flags & IORESOURCE_MEM_64) { @@ -848,6 +848,8 @@ static void pci_setup_bridge(struct pci_bus *bus) =20 int pci_claim_bridge_resource(struct pci_dev *bridge, int i) { + int ret =3D -EINVAL; + if (i < PCI_BRIDGE_RESOURCES || i > PCI_BRIDGE_RESOURCE_END) return 0; =20 @@ -861,11 +863,8 @@ int pci_claim_bridge_resource(struct pci_dev *bridge, = int i) return -EINVAL; =20 /* Try to clip the resource and claim the smaller window */ - if (!pci_bus_clip_resource(bridge, i)) - return -EINVAL; /* Clipping didn't change anything */ - - if (!pci_claim_resource(bridge, i)) - return -EINVAL; + if (pci_bus_clip_resource(bridge, i)) + ret =3D pci_claim_resource(bridge, i); =20 switch (i) { case PCI_BRIDGE_IO_WINDOW: @@ -881,7 +880,7 @@ int pci_claim_bridge_resource(struct pci_dev *bridge, i= nt i) return -EINVAL; } =20 - return 0; + return ret; } =20 /* --=20 2.39.5 From nobody Fri Oct 3 23:02:05 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 51D582ED16D; Fri, 22 Aug 2025 14:57:31 +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=1755874653; cv=none; b=F0662uHGdph9rNegv/PXBZx6KEvUQtPQQ20TKrKQ6Q4jb9Jv8vuBQCi7TtPgjjiMGL75O6w/20wUu/alQnPBbZwCSq5iiE15JOVTtByJgDH8f5zIlmtQMh7w2F2AAnjHlAvrbLTjzjetOWvZqoMdBdg9Ps6IW7O1LP3r/4x4bRI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874653; c=relaxed/simple; bh=h9rOaKJ78cwvTMGhAeaZehjm2lm9CqbJUu56YHFbep4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=WIPNrCoKAVh/TClcIMlJQhskmqOA0ZrUhVoj+3VViTSiBlyQ4EQV7AHDu5FSbYH98InGXcT+igqRMlHE7jEVWj07fzs+RG/7FGOseMnHqy9gGGNaOLlUEHVbiPCbsFtTkd7GirknuhywUiJc+NehB0EaGZMBk3l66GmSEunK7tA= 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=cwCDtz23; 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="cwCDtz23" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1755874651; x=1787410651; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=h9rOaKJ78cwvTMGhAeaZehjm2lm9CqbJUu56YHFbep4=; b=cwCDtz23B2HsGWC0bZSi5BP4sm9veq7h1ZmYvkeiPlE4Vxqxp6jRtmtc flKYv7XIfiY95eIefy6KmaLg+sA8ltGRSHCDOSiPtVfNnKNecIaLCf22B N4gCYe9JqGvFQs1qtuqgJL9fkWjD9heEAaZG0hx78b4g/e+R3EHsbU+jS aIiMDDfDJR9I45T873ttaOw+1HDrYoqjBZYpGMr9ZtV9oSWIg6sBAMb5e wrV3BpJaNFaRjaiCb+ojIKnC1K/aS0P8DLJedf5JuGjyQ2Oapp2ECFz8t 1VG/pjmFaDszMkizIFSwqzQn+Ntz1Gfnh5+JlZ/MVtpLsU4U9owvjOEaa A==; X-CSE-ConnectionGUID: aR5OBHtlRdyV/cqjr8rjQw== X-CSE-MsgGUID: I7pMgB7cTC6ix7xKIEoOeQ== X-IronPort-AV: E=McAfee;i="6800,10657,11529"; a="57201334" X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="57201334" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:57:30 -0700 X-CSE-ConnectionGUID: DvVLJoVkQxS29oGAHEDBlA== X-CSE-MsgGUID: Ujk0XRTPSUO4HfTmYVIn9Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="168920472" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.244.115]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:57:25 -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 08/24] PCI: Use pci_release_resource() instead of release_resource() Date: Fri, 22 Aug 2025 17:55:49 +0300 Message-Id: <20250822145605.18172-9-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 A few places in setup-bus.c call release_resource() directly and end up duplicating functionality from pci_release_resource() such as parent check, logging, and clearing the resource. Worse yet, the way the resource is cleared is inconsistent between different sites. Convert release_resource() calls into pci_release_resource() to remove code duplication. The will also make the resource start, end, and flags behavior consistent, ie., start address is cleared, and only IORESOURCE_UNSET is asserted for the resource. While at it, eliminate the unnecessary initialization of idx variable in pci_bridge_release_resources(). Signed-off-by: Ilpo J=C3=A4rvinen --- drivers/pci/setup-bus.c | 46 +++++++++++++---------------------------- drivers/pci/setup-res.c | 11 +++++++--- include/linux/pci.h | 2 +- 3 files changed, 23 insertions(+), 36 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 6bdc1af887da..b62465665abc 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -473,8 +473,6 @@ static void __assign_resources_sorted(struct list_head = *head, struct pci_dev_resource *dev_res, *tmp_res, *dev_res2; struct resource *res; struct pci_dev *dev; - const char *res_name; - int idx; unsigned long fail_type; resource_size_t add_align, align; =20 @@ -582,14 +580,7 @@ static void __assign_resources_sorted(struct list_head= *head, res =3D dev_res->res; dev =3D dev_res->dev; =20 - if (!res->parent) - continue; - - idx =3D pci_resource_num(dev, res); - res_name =3D pci_resource_name(dev, idx); - pci_dbg(dev, "%s %pR: releasing\n", res_name, res); - - release_resource(res); + pci_release_resource(dev, pci_resource_num(dev, res)); restore_dev_resource(dev_res); } /* Restore start/end/flags from saved list */ @@ -1732,7 +1723,7 @@ static void pci_bridge_release_resources(struct pci_b= us *bus, struct resource *r; unsigned int old_flags; struct resource *b_res; - int idx =3D 1; + int idx, ret; =20 b_res =3D &dev->resource[PCI_BRIDGE_RESOURCES]; =20 @@ -1766,21 +1757,18 @@ static void pci_bridge_release_resources(struct pci= _bus *bus, =20 /* If there are children, release them all */ release_child_resources(r); - if (!release_resource(r)) { - type =3D old_flags =3D r->flags & PCI_RES_TYPE_MASK; - pci_info(dev, "resource %d %pR released\n", - PCI_BRIDGE_RESOURCES + idx, r); - /* Keep the old size */ - resource_set_range(r, 0, resource_size(r)); - r->flags =3D 0; =20 - /* Avoiding touch the one without PREF */ - if (type & IORESOURCE_PREFETCH) - type =3D IORESOURCE_PREFETCH; - __pci_setup_bridge(bus, type); - /* For next child res under same bridge */ - r->flags =3D old_flags; - } + type =3D old_flags =3D r->flags & PCI_RES_TYPE_MASK; + ret =3D pci_release_resource(dev, PCI_BRIDGE_RESOURCES + idx); + if (ret) + return; + + /* Avoiding touch the one without PREF */ + if (type & IORESOURCE_PREFETCH) + type =3D IORESOURCE_PREFETCH; + __pci_setup_bridge(bus, type); + /* For next child res under same bridge */ + r->flags =3D old_flags; } =20 enum release_type { @@ -2425,7 +2413,6 @@ int pci_reassign_bridge_resources(struct pci_dev *bri= dge, unsigned long type) for (i =3D PCI_BRIDGE_RESOURCES; i < PCI_BRIDGE_RESOURCE_END; i++) { struct resource *res =3D &bridge->resource[i]; - const char *res_name =3D pci_resource_name(bridge, i); =20 if ((res->flags ^ type) & PCI_RES_TYPE_MASK) continue; @@ -2438,12 +2425,7 @@ int pci_reassign_bridge_resources(struct pci_dev *br= idge, unsigned long type) if (ret) goto cleanup; =20 - pci_info(bridge, "%s %pR: releasing\n", res_name, res); - - if (res->parent) - release_resource(res); - res->start =3D 0; - res->end =3D 0; + pci_release_resource(bridge, i); break; } if (i =3D=3D PCI_BRIDGE_RESOURCE_END) diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c index d2b3ed51e880..0468c058b598 100644 --- a/drivers/pci/setup-res.c +++ b/drivers/pci/setup-res.c @@ -406,20 +406,25 @@ int pci_reassign_resource(struct pci_dev *dev, int re= sno, return 0; } =20 -void pci_release_resource(struct pci_dev *dev, int resno) +int pci_release_resource(struct pci_dev *dev, int resno) { struct resource *res =3D pci_resource_n(dev, resno); const char *res_name =3D pci_resource_name(dev, resno); + int ret; =20 if (!res->parent) - return; + return 0; =20 pci_info(dev, "%s %pR: releasing\n", res_name, res); =20 - release_resource(res); + ret =3D release_resource(res); + if (ret) + return ret; res->end =3D resource_size(res) - 1; res->start =3D 0; res->flags |=3D IORESOURCE_UNSET; + + return 0; } EXPORT_SYMBOL(pci_release_resource); =20 diff --git a/include/linux/pci.h b/include/linux/pci.h index 59876de13860..275df4058767 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1417,7 +1417,7 @@ void pci_reset_secondary_bus(struct pci_dev *dev); void pcibios_reset_secondary_bus(struct pci_dev *dev); void pci_update_resource(struct pci_dev *dev, int resno); int __must_check pci_assign_resource(struct pci_dev *dev, int i); -void pci_release_resource(struct pci_dev *dev, int resno); +int pci_release_resource(struct pci_dev *dev, int resno); static inline int pci_rebar_bytes_to_size(u64 bytes) { bytes =3D roundup_pow_of_two(bytes); --=20 2.39.5 From nobody Fri Oct 3 23:02:05 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 B85882ED16D; Fri, 22 Aug 2025 14:57:40 +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=1755874662; cv=none; b=Q9qd9tkNoUd3NK9q6pd0XxlQFkbotnX8gzN4a6k7xg+Lt3d/mdbpkNVYoUtTZF3yIF8tm3gfUc3ii1ySB4L4wrWBxhqn96vNzhE5M1Iu+8yx6DoOPmyce4DvwwwXP3pa12e4R/yyQj4Fh0T/tjpzM5pP9RNjj12vNERn846toG4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874662; c=relaxed/simple; bh=F2R5lm6B0zlfTPYSGNsRRvyNW/8MTuBWGQgTQj1Brew=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=ZYaH2isDi79af8Of+dUUOgXQqXy3SuMz61oY7ajM48rpiq0NPpjXeIhWq4UeiEFPssr2WZq4Vv/dg0skDA11lmtaNgdJSCQRX9FVPiEejNDnOv+AuogfP6tELgnH5Ds29RcuGT1I9DpRmpT5e/IFbGnbmEQuw4WtmQvQix0Z86o= 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=buEQ7sMt; 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="buEQ7sMt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1755874660; x=1787410660; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=F2R5lm6B0zlfTPYSGNsRRvyNW/8MTuBWGQgTQj1Brew=; b=buEQ7sMtIV/r84bq81VEFcsJ7J2TTlMpMBQmGF4R+zvhiPVY/dCOYTJ0 Tm72AlPmo0d4wjokc439/4DHA5jxuaH2EbTRhDoMxZgc3wPdU3iJo8ABf e1AnYWKp3dhOSnjONTh7q19PBmKqW0z1RQf2Mel2jNtN0vGIHIvMVYkSF wH26eUZvl6gZ6EjTN28zweDlg+d8jqSZF2+PJ7C8m0lXk6hWa+6fSk5r2 EAtMY6wufAuwoUuHBrBOc+uenf1KZ3JI51FJFgCDYLbr9MRd3f+3jsSLP +j3sX5lEhD//AfuaagKMH/lodnj1ZrRXUcBrjJ51tPmpda1XBOjdmuQO9 w==; X-CSE-ConnectionGUID: PSCsNVHoShiTP/NO8DTxng== X-CSE-MsgGUID: GXbMmo6PTV2vt9XNrZCuxQ== X-IronPort-AV: E=McAfee;i="6800,10657,11529"; a="57201364" X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="57201364" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:57:40 -0700 X-CSE-ConnectionGUID: dUvSFF9VS1qy+pJdy3UIkw== X-CSE-MsgGUID: wzKVwqaETQWyVrIJW+JaKQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="168920509" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.244.115]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:57:35 -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 09/24] PCI: Enable bridge even if bridge window fails to assign Date: Fri, 22 Aug 2025 17:55:50 +0300 Message-Id: <20250822145605.18172-10-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 A normal PCI bridge has multiple bridge windows and not all of them are always required by devices underneath the bridge. If Root Port or bridge does not have a device underneath, no bridge windows get assigned. Yet, pci_enable_resources() is set to fail indiscriminantly on any resource assignment failure if the resource is not known to be optional. In practice, the code in pci_enable_resources() is currently largely dormant. The kernel sets resource flags to zero for any unused bridge window and resets flags to zero in case of an resource assignment failure, which short-circuits pci_enable_resources() because of this check: if (!(r->flags & (IORESOURCE_IO | IORESOURCE_MEM))) continue; However, an upcoming change to resource flags will alter how bridge window flags resource flags behave activating these long dormants checks in pci_enable_resources(). While complex logic could be built to selectively enable a bridge only under some conditions, a few versions of such logic were tried during development of this change and none of them worked satisfactorily. Thus, I just gave up and decided to enable any bridge regardless of the bridge windows as there seems to be no clear benefit from not enabling it but a major downside as pcieport will not be probed for the bridge if it's not enabled. Therefore, change pci_enable_resources() to not check if bridge window resources remain unassigned. Resource assignment failures are pretty noisy already so there is no need to log that for bridge windows in pci_enable_resources(). Ignoring bridge window failures hopefully prevents an obvious sources of regressions when the upcoming change that no longer clears resource flags for bridge windows is enacted. I've hit this problem even during my own testing on multiple occassions so I expect it to be a quite common problem. This can always be revisited later if somebody thinks the enable check for bridges is not strict enough, but expect a mind-boggling number of regressions from such a change. Signed-off-by: Ilpo J=C3=A4rvinen --- drivers/pci/setup-res.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c index 0468c058b598..4e0e60256f04 100644 --- a/drivers/pci/setup-res.c +++ b/drivers/pci/setup-res.c @@ -527,22 +527,26 @@ int pci_enable_resources(struct pci_dev *dev, int mas= k) if (pci_resource_is_optional(dev, i)) continue; =20 - if (r->flags & IORESOURCE_UNSET) { - pci_err(dev, "%s %pR: not assigned; can't enable device\n", - r_name, r); - return -EINVAL; + if (i < PCI_BRIDGE_RESOURCES) { + if (r->flags & IORESOURCE_UNSET) { + pci_err(dev, "%s %pR: not assigned; can't enable device\n", + r_name, r); + return -EINVAL; + } + + if (!r->parent) { + pci_err(dev, "%s %pR: not claimed; can't enable device\n", + r_name, r); + return -EINVAL; + } } =20 - if (!r->parent) { - pci_err(dev, "%s %pR: not claimed; can't enable device\n", - r_name, r); - return -EINVAL; + if (r->parent) { + if (r->flags & IORESOURCE_IO) + cmd |=3D PCI_COMMAND_IO; + if (r->flags & IORESOURCE_MEM) + cmd |=3D PCI_COMMAND_MEMORY; } - - if (r->flags & IORESOURCE_IO) - cmd |=3D PCI_COMMAND_IO; - if (r->flags & IORESOURCE_MEM) - cmd |=3D PCI_COMMAND_MEMORY; } =20 if (cmd !=3D old_cmd) { --=20 2.39.5 From nobody Fri Oct 3 23:02:05 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 CB36824CEE8; Fri, 22 Aug 2025 14:57:50 +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=1755874672; cv=none; b=PejVQWYQEAtUIJObAhYM0IC63AM+THDULzFhJwDp2ctJQqsKtjKzS0KOCqDq7TaE0wI23n30elbCQm2DEIu0J+lajsQO+Zh91ESlWO1VIZgR+GPQztSV92IKPrSbAlw2HYwBNDEOhc99xpnR7BuKfgOaHYhbuqQbhcYkWEyXTFg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874672; c=relaxed/simple; bh=3x4mEhP7iBLX8hi8m0JxlOf943qi7QpjreCSkVJG+/4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=M6ADzZNcq4mVk5hu7rX6hUPlqI/GB2pFxRXJbOk5y4FChwD4/U3jSnkqbpPtpxmFxKfPU9fTUMm9leRQoOMMkBq65zvrJApAXVKqDWCKfVeVr7kw2A8JljNjEax1YY7ikKF6IpB6CNfN+6xlVZ1bI23C53QRI1aILoaUzMuTejw= 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=WyL8qphz; 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="WyL8qphz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1755874671; x=1787410671; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3x4mEhP7iBLX8hi8m0JxlOf943qi7QpjreCSkVJG+/4=; b=WyL8qphzB3U3rwcz05jNbMBe6yhT3vJ7eEm1GUcUeHmCadkXI9/3dCmA 8/OYKe5AoKueJJ2+5uEmqsVbzMqBDT3io8FYFyhjWTVxzcnabpc4rYJlj viuIr5nNxoqBC6q9alrHMMaO+jdDCcTfhfOoHridbSET6l6VlPjOtMbZj fXpx/i/K/qtUClu1YnnhTxqps5LIbV5qeEcNEQwAaCRmJrfTDRuxK+l3r G/PhxmZEPZLvrYDVHffsxQd6FYzaG1HG8jp5dy+aZAmvDqQ768mu4CCj3 v6A2RZbwUcg+EL2zEVs8erjWL/MmKrfFMDkqFi5ji7tX4D9eoW+M2ObCv w==; X-CSE-ConnectionGUID: F5bMZ8hgQp6epOn65BfnYw== X-CSE-MsgGUID: gwxkHQQ5TX+091u3zxY32Q== X-IronPort-AV: E=McAfee;i="6800,10657,11529"; a="57201393" X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="57201393" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:57:50 -0700 X-CSE-ConnectionGUID: zqR0JlJ6TWKcZThoCrOuJQ== X-CSE-MsgGUID: SFOmFw8hRJy5G5g3zRargQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="168920538" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.244.115]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:57:45 -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 10/24] PCI: Preserve bridge window resource type flags Date: Fri, 22 Aug 2025 17:55:51 +0300 Message-Id: <20250822145605.18172-11-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 When a bridge window is found unused or fails to assign, the flags of the associated resource are cleared. Clearing flags is problematic as it also removes the type information of the resource which is needed later. Thus, always preserve the bridge window type flags and use IORESOURCE_UNSET and IORESOURCE_DISABLED to indicate the status of the bridge window. Also, when initializing resources, make sure all valid bridge windows do get their type flags set. Change various places that relied on resource flags being cleared to check for IORESOURCE_UNSET and IORESOURCE_DISABLED to allow bridge window resource to retain their type flags. Add pdev_resource_assignable() and pdev_resource_should_fit() helpers to filter out disabled bridge windows during resource fitting, the latter combines more common checks into the helper. When reading the bridge windows from the registers, instead of leaving the resource flags cleared for bridge windows that are not enabled, always setup the flags and set IORESOURCE_UNSET | IORESOURCE_DISABLED as needed. When resource fitting or assignment fails for a bridge window resource, or the bridge window is not needed, mark the resource with IORESOURCE_UNSET or IORESOURCE_DISABLED, respectively. Use dummy zero resource in resource_show() for backwards compatibility as lspci will otherwise misrepresent disabled bridge windows. This change ended up fixing an issue which too highlights the importance of keeping the resource type flags intact: At the end of __assign_resources_sorted(), reset_resource() is called, previously clearing the flags. Later, pci_prepare_next_assign_round() attempted to release bridge resources using pci_bus_release_bridge_resources() that calls into pci_bridge_release_resources() that assumes type flags are still present. As type flags were cleared, IORESOURCE_MEM_64 was not set leading to resources under an incorrect bridge window to be released (idx =3D 1 instead of idx =3D 2). While the assignments performed later covered this problem so that the wrongly released resources got assigned in the end, it was still causing extra release+assign pairs. There are other reasons why the resource flags should be retained in upcoming changes too. Removing the flag reset for non-bridge window resource is left as future work, in part because it has a much higher regression potential due to pci_enable_resources() that will start to work also for those resources then and due to what endpoint drivers might assume about resources. Despite the Fixes tag, backporting this (at least any time soon) is highly discouraged. The issue fixed is borderline cosmetic as the later assignments normally cover the problem entirely. Also there might be non-obvious dependencies. Fixes: 5b28541552ef ("PCI: Restrict 64-bit prefetchable bridge windows to 6= 4-bit resources") Signed-off-by: Ilpo J=C3=A4rvinen --- drivers/pci/bus.c | 3 ++ drivers/pci/pci-sysfs.c | 7 ++++ drivers/pci/probe.c | 25 +++++++++--- drivers/pci/setup-bus.c | 88 ++++++++++++++++++++++++++--------------- drivers/pci/setup-res.c | 3 ++ 5 files changed, 89 insertions(+), 37 deletions(-) diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c index b77fd30bbfd9..58b5388423ee 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -204,6 +204,9 @@ static int pci_bus_alloc_from_region(struct pci_bus *bu= s, struct resource *res, if (!r) continue; =20 + if (r->flags & (IORESOURCE_UNSET|IORESOURCE_DISABLED)) + continue; + /* type_mask must match */ if ((res->flags ^ r->flags) & type_mask) continue; diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 5eea14c1f7f5..162a5241c7f7 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -177,6 +177,13 @@ static ssize_t resource_show(struct device *dev, struc= t device_attribute *attr, =20 for (i =3D 0; i < max; i++) { struct resource *res =3D &pci_dev->resource[i]; + struct resource zerores =3D {}; + + /* For backwards compatibility */ + if (i >=3D PCI_BRIDGE_RESOURCES && i <=3D PCI_BRIDGE_RESOURCE_END && + res->flags & (IORESOURCE_UNSET | IORESOURCE_DISABLED)) + res =3D &zerores; + pci_resource_to_user(pci_dev, i, res, &start, &end); len +=3D sysfs_emit_at(buf, len, "0x%016llx 0x%016llx 0x%016llx\n", (unsigned long long)start, diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index f41128f91ca7..f31d27c7708a 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -419,13 +419,17 @@ static void pci_read_bridge_io(struct pci_dev *dev, s= truct resource *res, limit |=3D ((unsigned long) io_limit_hi << 16); } =20 + res->flags =3D (io_base_lo & PCI_IO_RANGE_TYPE_MASK) | IORESOURCE_IO; + if (base <=3D limit) { - res->flags =3D (io_base_lo & PCI_IO_RANGE_TYPE_MASK) | IORESOURCE_IO; region.start =3D base; region.end =3D limit + io_granularity - 1; pcibios_bus_to_resource(dev->bus, res, ®ion); if (log) pci_info(dev, " bridge window %pR\n", res); + } else { + resource_set_range(res, 0, 0); + res->flags |=3D IORESOURCE_UNSET | IORESOURCE_DISABLED; } } =20 @@ -440,13 +444,18 @@ static void pci_read_bridge_mmio(struct pci_dev *dev,= struct resource *res, pci_read_config_word(dev, PCI_MEMORY_LIMIT, &mem_limit_lo); base =3D ((unsigned long) mem_base_lo & PCI_MEMORY_RANGE_MASK) << 16; limit =3D ((unsigned long) mem_limit_lo & PCI_MEMORY_RANGE_MASK) << 16; + + res->flags =3D (mem_base_lo & PCI_MEMORY_RANGE_TYPE_MASK) | IORESOURCE_ME= M; + if (base <=3D limit) { - res->flags =3D (mem_base_lo & PCI_MEMORY_RANGE_TYPE_MASK) | IORESOURCE_M= EM; region.start =3D base; region.end =3D limit + 0xfffff; pcibios_bus_to_resource(dev->bus, res, ®ion); if (log) pci_info(dev, " bridge window %pR\n", res); + } else { + resource_set_range(res, 0, 0); + res->flags |=3D IORESOURCE_UNSET | IORESOURCE_DISABLED; } } =20 @@ -489,16 +498,20 @@ static void pci_read_bridge_mmio_pref(struct pci_dev = *dev, struct resource *res, return; } =20 + res->flags =3D (mem_base_lo & PCI_PREF_RANGE_TYPE_MASK) | IORESOURCE_MEM | + IORESOURCE_PREFETCH; + if (res->flags & PCI_PREF_RANGE_TYPE_64) + res->flags |=3D IORESOURCE_MEM_64; + if (base <=3D limit) { - res->flags =3D (mem_base_lo & PCI_PREF_RANGE_TYPE_MASK) | - IORESOURCE_MEM | IORESOURCE_PREFETCH; - if (res->flags & PCI_PREF_RANGE_TYPE_64) - res->flags |=3D IORESOURCE_MEM_64; region.start =3D base; region.end =3D limit + 0xfffff; pcibios_bus_to_resource(dev->bus, res, ®ion); if (log) pci_info(dev, " bridge window %pR\n", res); + } else { + resource_set_range(res, 0, 0); + res->flags |=3D IORESOURCE_UNSET | IORESOURCE_DISABLED; } } =20 diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index b62465665abc..223f0e025407 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -190,6 +190,31 @@ static bool pdev_resources_assignable(struct pci_dev *= dev) return true; } =20 +static bool pdev_resource_assignable(struct pci_dev *dev, struct resource = *res) +{ + int idx =3D pci_resource_num(dev, res); + + if (!res->flags) + return false; + + if (idx >=3D PCI_BRIDGE_RESOURCES && idx <=3D PCI_BRIDGE_RESOURCE_END && + res->flags & IORESOURCE_DISABLED) + return false; + + return true; +} + +static bool pdev_resource_should_fit(struct pci_dev *dev, struct resource = *res) +{ + if (res->parent) + return false; + + if (res->flags & IORESOURCE_PCI_FIXED) + return false; + + return pdev_resource_assignable(dev, res); +} + /* Sort resources by alignment */ static void pdev_sort_resources(struct pci_dev *dev, struct list_head *hea= d) { @@ -205,10 +230,7 @@ static void pdev_sort_resources(struct pci_dev *dev, s= truct list_head *head) resource_size_t r_align; struct list_head *n; =20 - if (r->flags & IORESOURCE_PCI_FIXED) - continue; - - if (!(r->flags) || r->parent) + if (!pdev_resource_should_fit(dev, r)) continue; =20 r_align =3D pci_resource_alignment(dev, r); @@ -257,8 +279,15 @@ bool pci_resource_is_optional(const struct pci_dev *de= v, int resno) return false; } =20 -static inline void reset_resource(struct resource *res) +static inline void reset_resource(struct pci_dev *dev, struct resource *re= s) { + int idx =3D pci_resource_num(dev, res); + + if (idx >=3D PCI_BRIDGE_RESOURCES && idx <=3D PCI_BRIDGE_RESOURCE_END) { + res->flags |=3D IORESOURCE_UNSET; + return; + } + res->start =3D 0; res->end =3D 0; res->flags =3D 0; @@ -610,7 +639,7 @@ static void __assign_resources_sorted(struct list_head = *head, 0 /* don't care */); } =20 - reset_resource(res); + reset_resource(dev, res); } =20 free_list(head); @@ -1014,8 +1043,11 @@ static void pbus_size_io(struct pci_bus *bus, resour= ce_size_t min_size, =20 if (r->parent || !(r->flags & IORESOURCE_IO)) continue; - r_size =3D resource_size(r); =20 + if (!pdev_resource_assignable(dev, r)) + continue; + + r_size =3D resource_size(r); if (r_size < SZ_1K) /* Might be re-aligned for ISA */ size +=3D r_size; @@ -1034,6 +1066,9 @@ static void pbus_size_io(struct pci_bus *bus, resourc= e_size_t min_size, size0 =3D calculate_iosize(size, min_size, size1, 0, 0, resource_size(b_res), min_align); =20 + if (size0) + b_res->flags &=3D ~IORESOURCE_DISABLED; + size1 =3D size0; if (realloc_head && (add_size > 0 || children_add_size > 0)) { size1 =3D calculate_iosize(size, min_size, size1, add_size, @@ -1045,13 +1080,14 @@ static void pbus_size_io(struct pci_bus *bus, resou= rce_size_t min_size, if (bus->self && (b_res->start || b_res->end)) pci_info(bus->self, "disabling bridge window %pR to %pR (unused)\n", b_res, &bus->busn_res); - b_res->flags =3D 0; + b_res->flags |=3D IORESOURCE_DISABLED; return; } =20 resource_set_range(b_res, min_align, size0); b_res->flags |=3D IORESOURCE_STARTALIGN; if (bus->self && size1 > size0 && realloc_head) { + b_res->flags &=3D ~IORESOURCE_DISABLED; add_to_list(realloc_head, bus->self, b_res, size1-size0, min_align); pci_info(bus->self, "bridge window %pR to %pR add_size %llx\n", @@ -1198,11 +1234,13 @@ static int pbus_size_mem(struct pci_bus *bus, unsig= ned long mask, const char *r_name =3D pci_resource_name(dev, i); resource_size_t r_size; =20 - if (r->parent || (r->flags & IORESOURCE_PCI_FIXED) || - !pdev_resources_assignable(dev) || - ((r->flags & mask) !=3D type && - (r->flags & mask) !=3D type2 && - (r->flags & mask) !=3D type3)) + if (!pdev_resources_assignable(dev) || + !pdev_resource_should_fit(dev, r)) + continue; + + if ((r->flags & mask) !=3D type && + (r->flags & mask) !=3D type2 && + (r->flags & mask) !=3D type3) continue; r_size =3D resource_size(r); =20 @@ -1253,6 +1291,9 @@ static int pbus_size_mem(struct pci_bus *bus, unsigne= d long mask, min_align =3D max(min_align, win_align); size0 =3D calculate_memsize(size, min_size, 0, 0, resource_size(b_res), m= in_align); =20 + if (size0) + b_res->flags &=3D ~IORESOURCE_DISABLED; + if (bus->self && size0 && !pbus_upstream_space_available(bus, mask | IORESOURCE_PREFETCH, type, size0, min_align)) { @@ -1287,13 +1328,14 @@ static int pbus_size_mem(struct pci_bus *bus, unsig= ned long mask, if (bus->self && (b_res->start || b_res->end)) pci_info(bus->self, "disabling bridge window %pR to %pR (unused)\n", b_res, &bus->busn_res); - b_res->flags =3D 0; + b_res->flags |=3D IORESOURCE_DISABLED; return 0; } =20 resource_set_range(b_res, min_align, size0); b_res->flags |=3D IORESOURCE_STARTALIGN; if (bus->self && size1 > size0 && realloc_head) { + b_res->flags &=3D ~IORESOURCE_DISABLED; add_to_list(realloc_head, bus->self, b_res, size1-size0, add_align); pci_info(bus->self, "bridge window %pR to %pR add_size %llx add_align %l= lx\n", b_res, &bus->busn_res, @@ -1721,7 +1763,6 @@ static void pci_bridge_release_resources(struct pci_b= us *bus, { struct pci_dev *dev =3D bus->self; struct resource *r; - unsigned int old_flags; struct resource *b_res; int idx, ret; =20 @@ -1758,7 +1799,6 @@ static void pci_bridge_release_resources(struct pci_b= us *bus, /* If there are children, release them all */ release_child_resources(r); =20 - type =3D old_flags =3D r->flags & PCI_RES_TYPE_MASK; ret =3D pci_release_resource(dev, PCI_BRIDGE_RESOURCES + idx); if (ret) return; @@ -1767,8 +1807,6 @@ static void pci_bridge_release_resources(struct pci_b= us *bus, if (type & IORESOURCE_PREFETCH) type =3D IORESOURCE_PREFETCH; __pci_setup_bridge(bus, type); - /* For next child res under same bridge */ - r->flags =3D old_flags; } =20 enum release_type { @@ -2246,21 +2284,9 @@ static void pci_prepare_next_assign_round(struct lis= t_head *fail_head, } =20 /* Restore size and flags */ - list_for_each_entry(fail_res, fail_head, list) { - struct resource *res =3D fail_res->res; - struct pci_dev *dev =3D fail_res->dev; - int idx =3D pci_resource_num(dev, res); - + list_for_each_entry(fail_res, fail_head, list) restore_dev_resource(fail_res); =20 - if (!pci_is_bridge(dev)) - continue; - - if (idx >=3D PCI_BRIDGE_RESOURCES && - idx <=3D PCI_BRIDGE_RESOURCE_END) - res->flags =3D 0; - } - free_list(fail_head); } =20 diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c index 4e0e60256f04..21f77e5c647c 100644 --- a/drivers/pci/setup-res.c +++ b/drivers/pci/setup-res.c @@ -359,6 +359,9 @@ int pci_assign_resource(struct pci_dev *dev, int resno) =20 res->flags &=3D ~IORESOURCE_UNSET; res->flags &=3D ~IORESOURCE_STARTALIGN; + if (resno >=3D PCI_BRIDGE_RESOURCES && resno <=3D PCI_BRIDGE_RESOURCE_END) + res->flags &=3D ~IORESOURCE_DISABLED; + pci_info(dev, "%s %pR: assigned\n", res_name, res); if (resno < PCI_BRIDGE_RESOURCES) pci_update_resource(dev, resno); --=20 2.39.5 From nobody Fri Oct 3 23:02:05 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 89FC1313552; Fri, 22 Aug 2025 14:58:00 +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=1755874683; cv=none; b=Id5OKt8jSzP5hNS1SAuLytu9rRpE4rDvkTIRHczqbe0RRCQ/rCugR0Y/ZveCrzalw8o0F2lYGnvdiIGHHiDtHDWL4NQSkNkGbL44MLmYyDPf/FWsEYTBMfhm1jbhnBlthjZwzwhG3B88JNQOy/PImPdv/99FLuTIpjFITRcluDg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874683; c=relaxed/simple; bh=nKDUWjSDj08uKyvTX9DBKESYugIunl4wAuN3dhOg4bY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=u+B+mc6h+oBNOu6FxQGFgNUT5gJ2i3WLBPjqCIMUqXfJCYR19+ICCWvk87y02zzJqtrSyWjanVjaLiuLqE5pB+wvXS0yu6w3BsqfnnrZ9jila5kEdyht0YcaVIjhBu76q7IOMhXDJNYNBvJ6+uSSbMS8cwIqtDu9NZn0lsfBQnY= 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=LTStVWHs; 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="LTStVWHs" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1755874681; x=1787410681; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nKDUWjSDj08uKyvTX9DBKESYugIunl4wAuN3dhOg4bY=; b=LTStVWHs5GQ1Du/aFIIuUItNXjuhalqPmF9OSkY8L6tYx08A9VnULVcJ 9T+HFEsccIQutkLf//B+dmJMZ7w7v9YJbTkh9elZiG2wjH56DYFAbYrWi cvIsqNP0mmsNIr76O2WErXfXljsWtGK0wj5RNT58cYwZjIhR3H9WImfu6 DkkP6Y4EPECYoLDTOm8Z9GKiDqpj9lfOHNq5a1oJ9P6CyC4Qeg1knWv0p z+hxM+JSLZbnvfFuNSheehv56UlaEZgbxPJW5emU4+x06l8mF4O+cf7Kk Tf31223tAgOGize9ZlGbo0ZGPrnVxCB3YiD/3oCYkyysI7np5ok9vaht3 w==; X-CSE-ConnectionGUID: u/oUO8feRRW8tJQUY1kA8w== X-CSE-MsgGUID: 8A+jIZkrRUKOnpEwqldvQg== X-IronPort-AV: E=McAfee;i="6800,10657,11529"; a="57201412" X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="57201412" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:57:59 -0700 X-CSE-ConnectionGUID: C0xJ1+zrQqykpRB+mZXlLg== X-CSE-MsgGUID: wUiykzbVSkaqn73XadpgDQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="168920545" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.244.115]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:57:54 -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 11/24] PCI: Add defines for bridge window indexing Date: Fri, 22 Aug 2025 17:55:52 +0300 Message-Id: <20250822145605.18172-12-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 include/linux/pci.h provides PCI_BRIDGE_{IO,MEM,PREF_MEM}_WINDOW defines, however, they're based on the resource array indexing in the pci_dev struct. The struct pci_bus also has pointers to those same resource but they start from zeroth index. Add PCI_BUS_BRIDGE_{IO,MEM,PREF_MEM}_WINDOW defines to get rid of literal indexing. Signed-off-by: Ilpo J=C3=A4rvinen --- drivers/pci/pci.h | 4 ++++ drivers/pci/probe.c | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 34f65d69662e..1dc8a8066761 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -81,6 +81,10 @@ struct pcie_tlp_log; #define PCIE_MSG_CODE_DEASSERT_INTC 0x26 #define PCIE_MSG_CODE_DEASSERT_INTD 0x27 =20 +#define PCI_BUS_BRIDGE_IO_WINDOW 0 +#define PCI_BUS_BRIDGE_MEM_WINDOW 1 +#define PCI_BUS_BRIDGE_PREF_MEM_WINDOW 2 + extern const unsigned char pcie_link_speed[]; extern bool pci_early_dump; =20 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index f31d27c7708a..eaeb66bec433 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -598,9 +598,13 @@ void pci_read_bridge_bases(struct pci_bus *child) for (i =3D 0; i < PCI_BRIDGE_RESOURCE_NUM; i++) child->resource[i] =3D &dev->resource[PCI_BRIDGE_RESOURCES+i]; =20 - pci_read_bridge_io(child->self, child->resource[0], false); - pci_read_bridge_mmio(child->self, child->resource[1], false); - pci_read_bridge_mmio_pref(child->self, child->resource[2], false); + pci_read_bridge_io(child->self, + child->resource[PCI_BUS_BRIDGE_IO_WINDOW], false); + pci_read_bridge_mmio(child->self, + child->resource[PCI_BUS_BRIDGE_MEM_WINDOW], false); + pci_read_bridge_mmio_pref(child->self, + child->resource[PCI_BUS_BRIDGE_PREF_MEM_WINDOW], + false); =20 if (!dev->transparent) return; --=20 2.39.5 From nobody Fri Oct 3 23:02:05 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (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 897F02E611B; Fri, 22 Aug 2025 14:58:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874691; cv=none; b=iLOxOjbsDf+cp/C54WDR8bD/n2g9Gf5DwFB7do1VeayG4vCeAoTjU8d7/w3DKEAueld9vuSic+SeSwLL5LladAD4Y9hU4/9aLImnbCK1InVcGRo7xtn4Tut+lzXSm1IVuTz3JkZFl6VRCMgVI4BJvb1FJzFK3PmIFujeHZjGG1k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874691; c=relaxed/simple; bh=HvowNzzh/OD6cGrbG0ubHIxVA4Lk6Q820KCMwB+uzto=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=ZtgYrHgmNnB7JKbTykdrjC2ELb1fEFwSnlqmWyotSIrKO43FlNgqtuPZ/AiOgq8DbJ5jf4Jp/OTWP5Khpo0QGC0B89lomdnp6ev9lzer+SiXR6siagUZ407UivDyTI9A46tsgPAvln67rF2kntkpNCxDwRZPmGZG0q61i6TcMhY= 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=hBpMbgiF; arc=none smtp.client-ip=198.175.65.9 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="hBpMbgiF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1755874690; x=1787410690; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HvowNzzh/OD6cGrbG0ubHIxVA4Lk6Q820KCMwB+uzto=; b=hBpMbgiFltyZDFtoRu85exQHvYgheKm4OkCHJ7zbr81BrBbjsdADYDOb 7liHLA8H6+MA52TLi6s8uV9vkD9JdKo+b2geK7eWz3WCcPbCqdoJduGBV kpM9iFw2/o9Zs9BtLzlDvgjpTWJDF5uizHnzu+9sYG3cFJTxvJgsUw5LR hpz2exdO2UFLWMmYYCDmuCINmiCE2fsMOUDff3i+q/gACkKZ7Z2E+WShR dOhb93Q+gvwoYjikFWgM0daZueJBR8PzjrjpWmuxODqAelgMZoRIHmSd4 Wml9/fVGlz0GACk0XYTEjhdrcP80j6WHkdXDDWoP9P9Gr21QRQxoQ/kYM g==; X-CSE-ConnectionGUID: OnTuXDQnQzCAaf/ZMHES/Q== X-CSE-MsgGUID: tpd9cpTNROS7sbE1mGlP9Q== X-IronPort-AV: E=McAfee;i="6800,10657,11529"; a="80780518" X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="80780518" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:58:09 -0700 X-CSE-ConnectionGUID: vlviQhsgTCG2Kd8H61AzWw== X-CSE-MsgGUID: h4VZ9g4tQ6e8L99bQN0BOA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="168232306" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.244.115]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:58:04 -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 12/24] PCI: Add bridge window selection functions Date: Fri, 22 Aug 2025 17:55:53 +0300 Message-Id: <20250822145605.18172-13-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 Various places in the PCI core code make independently a decision into which bridge window a child resource should be placed to. It is hard to see whether these decisions always end up into agreement, especially in the corner cases, and in some places it requires complex logic to pass multiple resource types and/or bridge windows around. Add pbus_select_window() and pbus_select_window_for_type() for case where the former cannot be used so that eventually the same helper can be used to select the bridge window everywhere. Using the same function ensures the selected bridge window remains always the same and it can be easily recalculated in-situ allowing simplifying the interfaces between internal functions in upcoming changes. Signed-off-by: Ilpo J=C3=A4rvinen --- drivers/pci/pci.h | 2 + drivers/pci/setup-bus.c | 101 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 1dc8a8066761..cbd40f05c39c 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -385,6 +385,8 @@ static inline int pci_resource_num(const struct pci_dev= *dev, return resno; } =20 +struct resource *pbus_select_window(struct pci_bus *bus, + const struct resource *res); void pci_reassigndev_resource_alignment(struct pci_dev *dev); void pci_disable_bridge_window(struct pci_dev *dev); struct pci_bus *pci_bus_get(struct pci_bus *bus); diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 223f0e025407..0c0872b85762 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -172,6 +172,107 @@ static struct resource *find_bus_resource_of_type(str= uct pci_bus *bus, return r_assigned; } =20 +/** + * pbus_select_window_for_type - Select bridge window for a resource type + * @bus: PCI bus + * @type: Resource type (resource flags can be passed as is) + * + * Selects the bridge window based on a resource @type. + * + * For memory resources, the selection is done as follows: + * + * Any non-prefetchable resource is put into the non-prefetchable window. + * + * If there is no prefetchable MMIO window, put all memory resources into = the + * non-prefetchable window. + * + * If there's a 64-bit prefetchable MMIO window, put all 64-bit prefetchab= le + * resources into it and place 32-bit prefetchable memory into the + * non-prefetchable window. + * + * Otherwise, put all prefetchable resources into the prefetchable window. + * + * Return: the bridge window resource or NULL if no bridge window is found. + */ +static struct resource *pbus_select_window_for_type(struct pci_bus *bus, + unsigned long type) +{ + int iores_type =3D type & IORESOURCE_TYPE_BITS; /* w/o 64bit & pref */ + struct resource *mmio, *mmio_pref, *win; + + type &=3D PCI_RES_TYPE_MASK; /* with 64bit & pref */ + + if ((iores_type !=3D IORESOURCE_IO) && (iores_type !=3D IORESOURCE_MEM)) + return NULL; + + if (pci_is_root_bus(bus)) { + win =3D find_bus_resource_of_type(bus, type, type); + if (win) + return win; + + type &=3D ~IORESOURCE_MEM_64; + win =3D find_bus_resource_of_type(bus, type, type); + if (win) + return win; + + type &=3D ~IORESOURCE_PREFETCH; + return find_bus_resource_of_type(bus, type, type); + } + + switch (iores_type) { + case IORESOURCE_IO: + return pci_bus_resource_n(bus, PCI_BUS_BRIDGE_IO_WINDOW); + + case IORESOURCE_MEM: + mmio =3D pci_bus_resource_n(bus, PCI_BUS_BRIDGE_MEM_WINDOW); + mmio_pref =3D pci_bus_resource_n(bus, PCI_BUS_BRIDGE_PREF_MEM_WINDOW); + + if (!(type & IORESOURCE_PREFETCH) || + !(mmio_pref->flags & IORESOURCE_MEM)) + return mmio; + + if ((type & IORESOURCE_MEM_64) || + !(mmio_pref->flags & IORESOURCE_MEM_64)) + return mmio_pref; + + return mmio; + default: + return NULL; + } +} + +/** + * pbus_select_window - Select bridge window for a resource + * @bus: PCI bus + * @res: Resource + * + * Selects the bridge window for @res. If the resource is already assigned, + * the current bridge window is returned. + * + * For memory resources, the selection is done as follows: + * + * Any non-prefetchable resource is put into the non-prefetchable window. + * + * If there is no prefetchable MMIO window, put all memory resources into = the + * non-prefetchable window. + * + * If there's a 64-bit prefetchable MMIO window, put all 64-bit prefetchab= le + * resources into it and place 32-bit prefetchable memory into the + * non-prefetchable window. + * + * Otherwise, put all prefetchable resources into the prefetchable window. + * + * Return: the bridge window resource or NULL if no bridge window is found. + */ +struct resource *pbus_select_window(struct pci_bus *bus, + const struct resource *res) +{ + if (res->parent) + return res->parent; + + return pbus_select_window_for_type(bus, res->flags); +} + static bool pdev_resources_assignable(struct pci_dev *dev) { u16 class =3D dev->class >> 8, command; --=20 2.39.5 From nobody Fri Oct 3 23:02:05 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (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 D37DB2E611B; Fri, 22 Aug 2025 14:58:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874700; cv=none; b=oV7IYFCBrtqtDgUeJiCJL9Dy0EDHGWlJxWSSPu+i6nhqFfZmWcY1Yl/i2+eEQTc0BtXjSjxSnYrbltxVfuwtTqcwVqAvN6demcoae1+h+hiaek5edUsu18t91i2L+qpSV1MO6kMW+sYZvI/JCaseLZNjXofkZtJhliBvFU7mTBM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874700; c=relaxed/simple; bh=9B/2/rkIoDBIm4IVMedT6yw/8fy5XFXgmUft891BmJg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=DPQDKbnD8aF0g80SSc0AQepbTYdz5S812iAt89Gp/ZJRtVbgWK5s8T2OWVzsTQ33QRSy/ZRKIiY2XbBB2s3q9d6tL0VaFQGsn1HFMK6WkWZMJ5ZuLFYdjdM0oShAezQYaU9N+hqYwXmwJsXtgQ3YaCNjLTd/JZbKnwFIgQyVB8g= 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=OMZkx94f; arc=none smtp.client-ip=198.175.65.9 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="OMZkx94f" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1755874699; x=1787410699; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9B/2/rkIoDBIm4IVMedT6yw/8fy5XFXgmUft891BmJg=; b=OMZkx94fJB9ypdyn02w5C2Fx8y7jx0hu6K6WQmq+3XXcVxPGy7uQ1WnE PIZZJ/G9yoEoKhIUszCu51PSs0QgzqugNFoj+0wpRNaMeBa9ycH0qNq2U vlSwcmGH/5uYrvzbPOcvaXtwfVyBbyiLhnGvnC5I0nw8AaCgjZ+shAUsZ JvF0qEeZCzsKn0cRZxTIMc3rqS8ivwT6KTu7nsHAf9gkT7ch9JkS7Igop 4TNAvWkyy2oe4/9cH7Wz3QQwMPl7gSApjyNZgGq5m1jzIAH75EjGu3h5p SWR/eOsl47YEO1qkHqaAVbVG+AbNIJxkHtULSHabNcSFkE0g+ThBml2gN g==; X-CSE-ConnectionGUID: UR79IiTET8eJq50oEGpj9A== X-CSE-MsgGUID: VFuzZDyOTzSQxV03XJjZlA== X-IronPort-AV: E=McAfee;i="6800,10657,11529"; a="80780548" X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="80780548" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:58:19 -0700 X-CSE-ConnectionGUID: wIvH4dl9SZ6yJbAG3Hjt8Q== X-CSE-MsgGUID: w6Fs+Ad5RZ62WfjHUtvaog== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="168232369" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.244.115]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:58:13 -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 13/24] PCI: Fix finding bridge window in pci_reassign_bridge_resources() Date: Fri, 22 Aug 2025 17:55:54 +0300 Message-Id: <20250822145605.18172-14-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 pci_reassign_bridge_resources() walks upwards in the PCI bus hierarchy, locates the relevant bridge window on each level using flags check, and attempts to release the bridge window. The flags-based check is fragile due to various fallbacks bridge window selection logic might use. As such, the algorithm might not locate the correct bridge window. Refactor pci_reassign_bridge_resources() to determine the correct bridge window using pbus_select_window() that contains logic to handle all fallback cases correctly. Change function prefix to pbus as it now inputs struct bus and resource for which to locate the bridge window. The main purpose of this change is to make bridge window selection logic consistent across the entire PCI core (one step at a time). While this technically also fixes the commit 8bb705e3e79d ("PCI: Add pci_resize_resource() for resizing BARs") making the bridge window walk algorithm more robust, The normal setup having a 64-bit resizable BAR underneath bridge(s) with 64-bit prefetchable windows does not need to use any fallbacks. As such, the practical impact is low (requiring BAR resize use case and a non-typical bridge device). The way to detect if unrelated resource failed again is left to use the type based approximation which should not behave worse than before. Fixes: 8bb705e3e79d ("PCI: Add pci_resize_resource() for resizing BARs") Signed-off-by: Ilpo J=C3=A4rvinen --- drivers/pci/pci.h | 2 +- drivers/pci/setup-bus.c | 40 ++++++++++++++++++++-------------------- drivers/pci/setup-res.c | 2 +- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index cbd40f05c39c..0d96a9141227 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -334,7 +334,7 @@ struct device *pci_get_host_bridge_device(struct pci_de= v *dev); void pci_put_host_bridge_device(struct device *dev); =20 unsigned int pci_rescan_bus_bridge_resize(struct pci_dev *bridge); -int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long ty= pe); +int pbus_reassign_bridge_resources(struct pci_bus *bus, struct resource *r= es); int __must_check pci_reassign_resource(struct pci_dev *dev, int i, resourc= e_size_t add_size, resource_size_t align); =20 int pci_configure_extended_tags(struct pci_dev *dev, void *ign); diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 0c0872b85762..5ef6362b5166 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -2521,10 +2521,17 @@ void pci_assign_unassigned_bridge_resources(struct = pci_dev *bridge) } EXPORT_SYMBOL_GPL(pci_assign_unassigned_bridge_resources); =20 -int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long ty= pe) +/* + * Walk to the root hub, find the bridge window relevant for @res and + * releasing it when possible. If the bridge window contains assigned + * resources, it cannot be released. + */ +int pbus_reassign_bridge_resources(struct pci_bus *bus, struct resource *r= es) { + unsigned long type =3D res->flags; struct pci_dev_resource *dev_res; - struct pci_dev *next; + struct pci_dev *bridge; + const char *res_name; LIST_HEAD(saved); LIST_HEAD(added); LIST_HEAD(failed); @@ -2533,33 +2540,26 @@ int pci_reassign_bridge_resources(struct pci_dev *b= ridge, unsigned long type) =20 down_read(&pci_bus_sem); =20 - /* Walk to the root hub, releasing bridge BARs when possible */ - next =3D bridge; - do { - bridge =3D next; - for (i =3D PCI_BRIDGE_RESOURCES; i < PCI_BRIDGE_RESOURCE_END; - i++) { - struct resource *res =3D &bridge->resource[i]; - - if ((res->flags ^ type) & PCI_RES_TYPE_MASK) - continue; + while (!pci_is_root_bus(bus)) { + bridge =3D bus->self; + res =3D pbus_select_window(bus, res); + if (!res) + break; =20 - /* Ignore BARs which are still in use */ - if (res->child) - continue; + i =3D pci_resource_num(bridge, res); + res_name =3D pci_resource_name(bridge, i); =20 + /* Ignore BARs which are still in use */ + if (!res->child) { ret =3D add_to_list(&saved, bridge, res, 0, 0); if (ret) goto cleanup; =20 pci_release_resource(bridge, i); - break; } - if (i =3D=3D PCI_BRIDGE_RESOURCE_END) - break; =20 - next =3D bridge->bus ? bridge->bus->self : NULL; - } while (next); + bus =3D bus->parent; + } =20 if (list_empty(&saved)) { up_read(&pci_bus_sem); diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c index 21f77e5c647c..c3ba4ccecd43 100644 --- a/drivers/pci/setup-res.c +++ b/drivers/pci/setup-res.c @@ -496,7 +496,7 @@ int pci_resize_resource(struct pci_dev *dev, int resno,= int size) =20 /* Check if the new config works by trying to assign everything. */ if (dev->bus->self) { - ret =3D pci_reassign_bridge_resources(dev->bus->self, res->flags); + ret =3D pbus_reassign_bridge_resources(dev->bus, res); if (ret) goto error_resize; } --=20 2.39.5 From nobody Fri Oct 3 23:02:05 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (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 AC6C33126DE; Fri, 22 Aug 2025 14:58:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874709; cv=none; b=fCaeHFYBplAN/FHuvzXb0t7A44JBkblYV8vN+8j1apup+MdGqHnxS7tu/AvegL5jQQIDlJOUR2iNFyr7UiTlPl3NJVIaguxWbVJ60VGPqMnAa4Pn/n8a/jJO9KXG+grf3mY4g+3+Y4Eku+jLJ+w6Ir6VDL9X2CRG8xtPVLxPzDU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874709; c=relaxed/simple; bh=lNB4OF2Frswq8A/Spc0itCO+i13cv1R1+OiD+b5mXBM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=BqrW6ivImuT8bgHlANePOsALKF3Dbgq+TID5Ye9im0FhGELIX1ZO/Ohmv8/j2qE60kP7PqxzyqtVRADzVC3EmHV+TuIcxkKiAU8GQix0S47ThmwjHqQ0beTrBe8f2dZNHK6ntk4ND+mM0fcIxxZIBpmAEpc/MGIqg07U8q3Y7hM= 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=UQ2g3OI5; arc=none smtp.client-ip=198.175.65.9 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="UQ2g3OI5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1755874708; x=1787410708; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lNB4OF2Frswq8A/Spc0itCO+i13cv1R1+OiD+b5mXBM=; b=UQ2g3OI5t76WN3qsCf5N0NN99laqOKpV5M3XIgB6KZXm26GOYD/Ahz3t SQvUdHkB9sWsLInZPHHXWTHRTublYnvWnLs33DnbKgicWdnJIDD0sD6jv TAlwAfyw96s+N+SeowWFikS7O/TZJjjUUaDsFXzy6XnO1EK9C5LWiU5VN OEL0B5HDS/q4dggcg0b2ScB8bNuFMtqSifeFlT8KZCpy6v6otB0hMb6Em uSRT36Bzj4GHXO9lUx0Fxk/9F/h4fzDESesp+sLkcM8C9FPZJxrHr6MpS oelgT6okg7D4quKofrucH3MibdMEp29VD1o12MrcNBXYPYU3ktUYpk9Fg Q==; X-CSE-ConnectionGUID: ICnAE8LERrm9gILT8tswDQ== X-CSE-MsgGUID: 27ze0+0QTVS8G9NNKGsjfg== X-IronPort-AV: E=McAfee;i="6800,10657,11529"; a="80780578" X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="80780578" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:58:28 -0700 X-CSE-ConnectionGUID: QdpNvnJ4TxqlKStF+Xcarg== X-CSE-MsgGUID: dx1mT04YSL+qjkrIT85xOA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="168232435" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.244.115]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:58:22 -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 14/24] PCI: Warn if bridge window cannot be released when resizing BAR Date: Fri, 22 Aug 2025 17:55:55 +0300 Message-Id: <20250822145605.18172-15-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 BAR resizing calls to pci_reassign_bridge_resources() that attempts to release any upstream bridge window to allow them to accommodate the new BAR size. The release can only be performed if there are no other child resources for the bridge window. The code just silently continues when this condition is detects. Add pci_warn() to inform user that a bridge window could not be released because of child resources. As too small bridge window is often the reason why the BAR resize cannot succeed, this warning will help to pinpoint to the cause. Signed-off-by: Ilpo J=C3=A4rvinen --- drivers/pci/setup-bus.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 5ef6362b5166..55289cd58e2c 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -2556,6 +2556,10 @@ int pbus_reassign_bridge_resources(struct pci_bus *b= us, struct resource *res) goto cleanup; =20 pci_release_resource(bridge, i); + } else { + pci_warn(bridge, + "%s %pR: was not released (still contains assigned resources)\n", + res_name, res); } =20 bus =3D bus->parent; --=20 2.39.5 From nobody Fri Oct 3 23:02:05 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (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 9259C3126C9; Fri, 22 Aug 2025 14:58:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874717; cv=none; b=kx/iOU2Vsg5WrZchUamWrupZasO5RvGH69kFjbDJqXDg6V51dGlZQ38fEjSHWA8rsVvuFus2eyPaApbfDrlA3w/iv6CMwZj4WZmXGBmtnq6OvZetpo+n4gdawhouLpi3gvN956Ll/J9S4DCz/fCdavK74NS40+krCZL7zc7wgq8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874717; c=relaxed/simple; bh=IncNjxzu3JkPyYz1f41Ws3Cm/NTK625NvqtomTkiAzw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=SUHfS8q5/gzkCJ1AUw+tPrptshVeW90ALlqzYVtzIL8RpxA4vJLN0DeKcimIUppglnSpVavG6YUSos/MzeBmJZBYMj8rsROeUPhNeTImKl1cH+SRlTqobcoBru8YMLa8+xHa91NM+67aLCfCoHdjoSNevmHskOkHOASjQ5bfyWQ= 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=isnvKhcU; arc=none smtp.client-ip=198.175.65.9 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="isnvKhcU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1755874717; x=1787410717; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IncNjxzu3JkPyYz1f41Ws3Cm/NTK625NvqtomTkiAzw=; b=isnvKhcUy384TPisv/q68ZMEMFs77PsNtIHUlr8qtLqUqv52yX1ojwNr zIAHqy9kXsNt/yMNf5xBIRYlCyqTSlQvGot0yHx2oNnZ7oD3568J62jPP 3Y6HpYArwmYhVug25MhVLC0cKrUEhcKn+iWFYRM6enzeF+J6ZLfQ2PIeK to3PdZp+8pDq65UAmwk1dzCmgXJcAEtqbAgpFMf4fBR+vRgcO418xBYUb 7GidZyxu6KW1HmIZwT2emvQf/pXAL0w2FmBClpd6XQDuB3q7XbagmUBnn WRXiar3YBDs38WBvJJddS/a2WxGEPqshAU8chfuM4aWbX48EBK3tGtJYS g==; X-CSE-ConnectionGUID: oQYqj0rJQ7OBL4d5qq4FKg== X-CSE-MsgGUID: 8GuXesa1RLSFjWmeRm0dOQ== X-IronPort-AV: E=McAfee;i="6800,10657,11529"; a="80780595" X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="80780595" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:58:37 -0700 X-CSE-ConnectionGUID: e71T9w9/S8qvdwNwD4fkug== X-CSE-MsgGUID: syw70RfbT6SQFg/yaKO71w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="168232478" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.244.115]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:58:31 -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 15/24] PCI: Use pbus_select_window() during BAR resize Date: Fri, 22 Aug 2025 17:55:56 +0300 Message-Id: <20250822145605.18172-16-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 Prior to a BAR resize, __resource_resize_store() loops through the normal resources of the PCI device and releases those that match to the flags of the BAR to be resized. This is necessary to allow resizing also the upstream bridge window as only childless bridge windows can be resized. While the flags check (mostly) works (if corner cases are ignored), the more straightforward way is to check if the resources share the bridge window. Change __resource_resize_store() to do the check using pbus_select_window(). Signed-off-by: Ilpo J=C3=A4rvinen --- drivers/pci/pci-sysfs.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 162a5241c7f7..ce3923c4aa80 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -1562,13 +1562,19 @@ static ssize_t __resource_resize_store(struct devic= e *dev, int n, const char *buf, size_t count) { struct pci_dev *pdev =3D to_pci_dev(dev); - unsigned long size, flags; + struct pci_bus *bus =3D pdev->bus; + struct resource *b_win, *res; + unsigned long size; int ret, i; u16 cmd; =20 if (kstrtoul(buf, 0, &size) < 0) return -EINVAL; =20 + b_win =3D pbus_select_window(bus, pci_resource_n(pdev, n)); + if (!b_win) + return -EINVAL; + device_lock(dev); if (dev->driver || pci_num_vf(pdev)) { ret =3D -EBUSY; @@ -1588,19 +1594,19 @@ static ssize_t __resource_resize_store(struct devic= e *dev, int n, pci_write_config_word(pdev, PCI_COMMAND, cmd & ~PCI_COMMAND_MEMORY); =20 - flags =3D pci_resource_flags(pdev, n); - pci_remove_resource_files(pdev); =20 - for (i =3D 0; i < PCI_BRIDGE_RESOURCES; i++) { - if (pci_resource_len(pdev, i) && - pci_resource_flags(pdev, i) =3D=3D flags) + pci_dev_for_each_resource(pdev, res, i) { + if (i >=3D PCI_BRIDGE_RESOURCES) + break; + + if (b_win =3D=3D pbus_select_window(bus, res)) pci_release_resource(pdev, i); } =20 ret =3D pci_resize_resource(pdev, n, size); =20 - pci_assign_unassigned_bus_resources(pdev->bus); + pci_assign_unassigned_bus_resources(bus); =20 if (pci_create_resource_files(pdev)) pci_warn(pdev, "Failed to recreate resource files after BAR resizing\n"); --=20 2.39.5 From nobody Fri Oct 3 23:02:05 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 4912A23ABBF; Fri, 22 Aug 2025 14:58:46 +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=1755874728; cv=none; b=AhzAv5sb5xXXkuArtpGTukSLhUJomlzSpH+rNMR7J5SczUgypanZ5e7Z+MSG3RV6RNfeyH/caMpVF80jYIUqEx7IydiPNEiF76PT/5jS66RRuKEOzle06eWWKBgZSQ9JzwpR1vbx6c8Pk5sHsqkubEHbtYBwS2eBqC4kdLB4jhk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874728; c=relaxed/simple; bh=hKKkyDwuMgQSuHsgEQCnHOBtmnEIBd1H4fruJqqsGtc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=l2g5ba8uZf1x/z8covKjrIzdE7/oTpvjSlHu90ZX/U6ZejmNqOJwsTvizoSw1ssEkKmHlMG70dOsmkhpB55xemLyJOafSVucBouqMEK7Yno3OSwHQu5QRvuLzxLpBFF/BbZVM7WK2bTx3CRA4rvqFgLuhZicap4uMDflTqHkGJc= 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=oB2jR3Yl; 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="oB2jR3Yl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1755874726; x=1787410726; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hKKkyDwuMgQSuHsgEQCnHOBtmnEIBd1H4fruJqqsGtc=; b=oB2jR3Yly6iZar15hvXG6H4104C/22UAS5cqR3tmnbhuJ87wnDpZky0Z TUcZvuMeNd6mkqWuJlOcjiCdTO1ElE3+YBh5eI9cHecOIHiyxH4EW1B+N IlzzV5GwGQt3mesx8/QnVvmXobcKtHNma6b/iOJAX1Y66RQrgWo8UBCnZ uZKBmVMk0D3vjN8UrmNpxGwvyuqGcEFaRrP+cnEdp4dZCCubE9vbFA9kS xaf0B8VQRxi0mwQr8L8KMpF+w8buLjzUr9KWu80/41hp73F5Fkba8mDUY /xaxh3oisFqmbrSPcyS+g6hwL4MDPxbd4wjmc8cH6wuXj4H4veXsju8y9 g==; X-CSE-ConnectionGUID: 6T7UJMQiQ4uX4s1mUbV/Cw== X-CSE-MsgGUID: yr9p7X2cQ3G58o0+AAM6pA== X-IronPort-AV: E=McAfee;i="6800,10657,11529"; a="57201505" X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="57201505" 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:58:45 -0700 X-CSE-ConnectionGUID: oPGWRSQbROyBWCGWWqNJgg== X-CSE-MsgGUID: SJBAxeC5SDOdrWApIXnu9g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="199695252" 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:40 -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 16/24] PCI: Use pbus_select_window_for_type() during IO window sizing Date: Fri, 22 Aug 2025 17:55:57 +0300 Message-Id: <20250822145605.18172-17-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 Convert pbus_size_io() to use pbus_select_window_for_type(). Signed-off-by: Ilpo J=C3=A4rvinen --- drivers/pci/setup-bus.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 55289cd58e2c..3f2776f7a1b2 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1122,8 +1122,7 @@ static void pbus_size_io(struct pci_bus *bus, resourc= e_size_t min_size, struct list_head *realloc_head) { struct pci_dev *dev; - struct resource *b_res =3D find_bus_resource_of_type(bus, IORESOURCE_IO, - IORESOURCE_IO); + struct resource *b_res =3D pbus_select_window_for_type(bus, IORESOURCE_IO= ); resource_size_t size =3D 0, size0 =3D 0, size1 =3D 0; resource_size_t children_add_size =3D 0; resource_size_t min_align, align; --=20 2.39.5 From nobody Fri Oct 3 23:02:05 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 BAD12322A0C; Fri, 22 Aug 2025 14:58:55 +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=1755874737; cv=none; b=mE7GAPccMUt87mkBv0r9UeARzTRorUEZ/tvAfPP3D3ROpiXkNvj9K7FvGGPMFR9snbda1/lqmWigtlBRMOxXIJ912accw7yWykym2rQnFqWYCLth8B+TPIh+YP6Rig/SNZMENKig8BYfw2BFOsKwmLo3NTIL9lEuKpvnajy6cXE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874737; c=relaxed/simple; bh=X8NhfOVVPeUuaZ7xzX5xjJ3Kbd+6Ye2qksEkgXo7VC8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=EnGH6QkrvjpCooR58a4bY2DMRZDKx6ukCu72a+LH9r1p4+Iy05cBWTVtT/VK6X2Xu4PeqvvaqhebZK3X6ot14rQO4iOYBbM3KWr0Le9lFrsJny2mVnTFpB/EBURhQXxa2bjB125NWLSrn2ZW2pL8InVwNxTLq9XJm3EHZy8bvu4= 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=ljkyL/av; 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="ljkyL/av" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1755874735; x=1787410735; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=X8NhfOVVPeUuaZ7xzX5xjJ3Kbd+6Ye2qksEkgXo7VC8=; b=ljkyL/avL3bBDEWsQSQkqYlBk+MznR03gTl1/KttzBonuMXdqhRbT/k1 eyOrv4bQRtHiPJ+Qb5+IGmNFOzItX6EnDw5rbUbkKo2ZA+LyiNojRGjZt rDVp3xaQuqOqsMfX28qwutZu/e1K2sd+lVrSwYeKqSFio3wDaRAMGvSOb FpvkpPTdZW8q+opDQ11gWyaGuJ7e1o5OPLaa/TSXG6RMmCyo1R04bJvWk XtfwLAm+MQyOnC6Eu10B5blf3UPybOaJQUL+NjJyhBRKaTwWlPcE/en/Y Qrw1kctucEpLeSw0WKpFQLUsjwbhh32gx4s0QcAFoJWHWowSa1rfjThKQ Q==; X-CSE-ConnectionGUID: ayN0EGOqQwSyjkFQsSc+2g== X-CSE-MsgGUID: +Sahd3PtTbiL7EIqPcdzXA== X-IronPort-AV: E=McAfee;i="6800,10657,11529"; a="57201519" X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="57201519" 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:58:55 -0700 X-CSE-ConnectionGUID: czktQPQuQrqYykt9N0PyQQ== X-CSE-MsgGUID: P1NLfDMUSq2nPtJmAVVs0g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="199695258" 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:50 -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 17/24] PCI: Rename resource variable from r to res Date: Fri, 22 Aug 2025 17:55:58 +0300 Message-Id: <20250822145605.18172-18-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 Resource is going to be passed in as argument aften an upcoming change. Rename the struct resource variable from "r" to "res" to avoid using one letter variable name in a function argument. This rename is made separately to reduce churn in the upcoming change. Signed-off-by: Ilpo J=C3=A4rvinen --- drivers/pci/setup-bus.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 3f2776f7a1b2..dac0f0f0360b 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1241,24 +1241,24 @@ 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 *r; + struct resource *res; =20 while ((bus =3D bus->parent)) { if (pci_is_root_bus(bus)) break; =20 - pci_bus_for_each_resource(bus, r) { - if (!r || !r->parent || (r->flags & mask) !=3D type) + pci_bus_for_each_resource(bus, res) { + if (!res || !res->parent || (res->flags & mask) !=3D type) continue; =20 - if (resource_size(r) >=3D size) { + if (resource_size(res) >=3D size) { struct resource gap =3D {}; =20 - if (find_resource_space(r, &gap, size, &constraint) =3D=3D 0) { + 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", - r, &bus->busn_res, &gap); + res, &bus->busn_res, &gap); return true; } } @@ -1266,7 +1266,7 @@ static bool pbus_upstream_space_available(struct pci_= bus *bus, unsigned long mas if (bus->self) { pci_info(bus->self, "Assigned bridge window %pR to %pR cannot fit 0x%llx required for %s= bridging to %pR\n", - r, &bus->busn_res, + res, &bus->busn_res, (unsigned long long)size, pci_name(downstream->self), &downstream->busn_res); --=20 2.39.5 From nobody Fri Oct 3 23:02:05 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 From nobody Fri Oct 3 23:02:05 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 79D912FFDD2; Fri, 22 Aug 2025 14:59:17 +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=1755874759; cv=none; b=gfMAtSCiruzH5wIb7eoncVOTpAEQFY3nCL7oTq+41BQUqZfkYYgGoHDpQax4zYvTGMzKXvt3rSouN/5b9jTJ1GPFLK0Q1E9rL3c93oTxjKvC0Xs4kVVc3Fg9JAMJlMm5y4skVVJBLe4DqwPZEsGmMmy5cRaAAHnSEzzrz63EDNE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874759; c=relaxed/simple; bh=Woq5i6B7u1BorPfYsOyd3IhFrLH3KrP16o8bmzdNAgc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=sx//KdvwUaWj4kJIMwotgw25FvHmpy/GrkW0Pq23Q9nHbdrML4HJNo9iQp18WmpeUtM05cxiycxj9xt5jpk6ZTiEwskF7nW5PXvWt6gObXm1CTNYCu/uyylw7iFHtSdOEANLvVychfTcSOkJw5k4OTvqoyUY5/e9Etl/Zds/zdg= 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=T5cus/ZX; 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="T5cus/ZX" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1755874757; x=1787410757; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Woq5i6B7u1BorPfYsOyd3IhFrLH3KrP16o8bmzdNAgc=; b=T5cus/ZXtVl3Lu/wTe3Mxri6ufqRGgHITRossUh7LIsmTGk+UJcUn4fD 2RMwoZFWWOsQbMbrNBJxtYyExsDJ4b5SW8E8e6sBw+TxgDQEGEB34xNqA k5flQMaadVvzeU1wpduFcLddTAmWr/5pkd8hWm7O33xWsFz4NWp5Bn3Hp sOewq4DgDiCQPSGQCV8SRtlDwjl/MRbe0QrNrd7wETpFFfx4eM10n6dKo ALL44wLf5tIoPa9A52ep8BfpPSw+yrOae2+yEm2ZR4byDSO+Devtw2cp9 5vlI9psgUtIdHJmDoMxxTAUlCC8r16NPdy6wUJmlPk9E3x5gRMe/+ORHs w==; X-CSE-ConnectionGUID: 2JONFelPQAOX/4evrXgUsw== X-CSE-MsgGUID: xohRjbklQ72b10VABym81w== X-IronPort-AV: E=McAfee;i="6800,10657,11529"; a="57201604" X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="57201604" 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:17 -0700 X-CSE-ConnectionGUID: 2CZi8veKRJ6pf21LAS/Ivg== X-CSE-MsgGUID: U31QFJe4TCKDYDvfFz/SHQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="199695308" 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:59:09 -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 19/24] PCI: Use pbus_select_window_for_type() during mem window sizing Date: Fri, 22 Aug 2025 17:56:00 +0300 Message-Id: <20250822145605.18172-20-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 __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 __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=C3=A4rvinen --- drivers/pci/setup-bus.c | 111 +++++++++------------------------------- 1 file changed, 24 insertions(+), 87 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 281ca5c73c97..28133a9c5f51 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1284,24 +1284,22 @@ static bool pbus_upstream_space_available(struct pc= i_bus *bus, * pbus_size_mem() - Size the memory window of a given bus * * @bus: The bus - * @mask: Mask the resource flag, then compare it with type - * @type: The type of free resource from bridge - * @type2: Second match type - * @type3: Third match type + * @type: The type of bridge resource * @min_size: The minimum memory window that must be allocated * @add_size: Additional optional memory window * @realloc_head: Track the additional memory window on this list * - * Calculate the size of the bus and minimal alignment which guarantees - * that all child resources fit in this size. + * Calculate the size of the bus resource for @type and minimal alignment + * which guarantees that all child resources fit in this size. * - * Return -ENOSPC if there's no available bus resource of the desired - * type. Otherwise, set the bus resource start/end to indicate the - * required size, add things to realloc_head (if supplied), and return 0. + * Sets the bus resource start/end to indicate the required size if there = an + * available unassigned bus resource of the desired @type. + * + * Adds optional resource requests to the @realloc_head list if it is + * supplied. */ -static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, - unsigned long type, unsigned long type2, - unsigned long type3, resource_size_t min_size, +static void pbus_size_mem(struct pci_bus *bus, unsigned long type, + resource_size_t min_size, resource_size_t add_size, struct list_head *realloc_head) { @@ -1309,19 +1307,18 @@ static int pbus_size_mem(struct pci_bus *bus, unsig= ned long mask, resource_size_t min_align, win_align, align, size, size0, size1 =3D 0; resource_size_t aligns[28]; /* Alignments from 1MB to 128TB */ int order, max_order; - struct resource *b_res =3D find_bus_resource_of_type(bus, - mask | IORESOURCE_PREFETCH, type); + struct resource *b_res =3D pbus_select_window_for_type(bus, type); resource_size_t children_add_size =3D 0; resource_size_t children_add_align =3D 0; resource_size_t add_align =3D 0; resource_size_t relaxed_align; =20 if (!b_res) - return -ENOSPC; + return; =20 /* If resource is already assigned, nothing more to do */ if (b_res->parent) - return 0; + return; =20 memset(aligns, 0, sizeof(aligns)); max_order =3D 0; @@ -1338,11 +1335,9 @@ static int pbus_size_mem(struct pci_bus *bus, unsign= ed long mask, if (!pdev_resources_assignable(dev) || !pdev_resource_should_fit(dev, r)) continue; - - if ((r->flags & mask) !=3D type && - (r->flags & mask) !=3D type2 && - (r->flags & mask) !=3D type3) + if (b_res !=3D pbus_select_window(bus, r)) continue; + r_size =3D resource_size(r); =20 /* Put SRIOV requested res to the optional list */ @@ -1428,7 +1423,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigne= d long mask, pci_info(bus->self, "disabling bridge window %pR to %pR (unused)\n", b_res, &bus->busn_res); b_res->flags |=3D IORESOURCE_DISABLED; - return 0; + return; } =20 resource_set_range(b_res, min_align, size0); @@ -1441,7 +1436,6 @@ static int pbus_size_mem(struct pci_bus *bus, unsigne= d long mask, (unsigned long long) (size1 - size0), (unsigned long long) add_align); } - return 0; } =20 unsigned long pci_cardbus_resource_alignment(struct resource *res) @@ -1546,12 +1540,11 @@ static void pci_bus_size_cardbus(struct pci_bus *bu= s, void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc= _head) { struct pci_dev *dev; - unsigned long mask, prefmask, type2 =3D 0, type3 =3D 0; resource_size_t additional_io_size =3D 0, additional_mmio_size =3D 0, additional_mmio_pref_size =3D 0; struct resource *pref; struct pci_host_bridge *host; - int hdr_type, ret; + int hdr_type; =20 list_for_each_entry(dev, &bus->devices, bus_list) { struct pci_bus *b =3D dev->subordinate; @@ -1601,71 +1594,15 @@ void __pci_bus_size_bridges(struct pci_bus *bus, st= ruct list_head *realloc_head) pbus_size_io(bus, realloc_head ? 0 : additional_io_size, additional_io_size, realloc_head); =20 - /* - * If there's a 64-bit prefetchable MMIO window, compute - * the size required to put all 64-bit prefetchable - * resources in it. - */ - mask =3D IORESOURCE_MEM; - prefmask =3D IORESOURCE_MEM | IORESOURCE_PREFETCH; - if (pref && (pref->flags & IORESOURCE_MEM_64)) { - prefmask |=3D IORESOURCE_MEM_64; - ret =3D pbus_size_mem(bus, prefmask, prefmask, - prefmask, prefmask, - realloc_head ? 0 : additional_mmio_pref_size, - additional_mmio_pref_size, realloc_head); - - /* - * If successful, all non-prefetchable resources - * and any 32-bit prefetchable resources will go in - * the non-prefetchable window. - */ - if (ret =3D=3D 0) { - mask =3D prefmask; - type2 =3D prefmask & ~IORESOURCE_MEM_64; - type3 =3D prefmask & ~IORESOURCE_PREFETCH; - } - } - - /* - * If there is no 64-bit prefetchable window, compute the - * size required to put all prefetchable resources in the - * 32-bit prefetchable window (if there is one). - */ - if (!type2) { - prefmask &=3D ~IORESOURCE_MEM_64; - ret =3D pbus_size_mem(bus, prefmask, prefmask, - prefmask, prefmask, - realloc_head ? 0 : additional_mmio_pref_size, - additional_mmio_pref_size, realloc_head); - - /* - * If successful, only non-prefetchable resources - * will go in the non-prefetchable window. - */ - if (ret =3D=3D 0) - mask =3D prefmask; - else - additional_mmio_size +=3D additional_mmio_pref_size; - - type2 =3D type3 =3D IORESOURCE_MEM; + if (pref) { + pbus_size_mem(bus, + IORESOURCE_MEM | IORESOURCE_PREFETCH | + (pref->flags & IORESOURCE_MEM_64), + realloc_head ? 0 : additional_mmio_pref_size, + additional_mmio_pref_size, realloc_head); } =20 - /* - * Compute the size required to put everything else in the - * non-prefetchable window. This includes: - * - * - all non-prefetchable resources - * - 32-bit prefetchable resources if there's a 64-bit - * prefetchable window or no prefetchable window at all - * - 64-bit prefetchable resources if there's no prefetchable - * window at all - * - * Note that the strategy in __pci_assign_resource() must match - * that used here. Specifically, we cannot put a 32-bit - * prefetchable resource in a 64-bit prefetchable window. - */ - pbus_size_mem(bus, mask, IORESOURCE_MEM, type2, type3, + pbus_size_mem(bus, IORESOURCE_MEM, realloc_head ? 0 : additional_mmio_size, additional_mmio_size, realloc_head); break; --=20 2.39.5 From nobody Fri Oct 3 23:02:05 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (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 4012F2FDC29; Fri, 22 Aug 2025 14:59:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874766; cv=none; b=au1NoFKZEldOsDAaEjbu+gIJGsEcRR42TxRHdgiZ7J+avn1Zu2mfg9xv7AIyp4YCLlJd6lzdpCcZ2pgt5lX+f06BL1/Cqi+guP7DUpMhrV0go35YfBDyXuNu9goBHWYiOFrscinO4P8wj9EfUtjWGA1ZSYXCPHkbECmnhnG0SLk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874766; c=relaxed/simple; bh=pzFN1L+PgZhbcDMgKU8nIsMBCPH3C7anPGuUjcc/28Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=QtNpQ8jmosUT1sGzDzXpwvngM8TYnUWUgABW3UIqlapUjPDJr/fCzxi1hF6lqkF4IpHD0pAR6TIrRthGggc9Qnq/QTnDQ+XgHdyTln5Tk/rwz7PXMWeHU2Rr/inCXFHx5MR/SToS8CUDW83X3iQBuGqRAvqUNtT7A747kW2xkUY= 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=PKvxp8Jj; arc=none smtp.client-ip=198.175.65.10 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="PKvxp8Jj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1755874766; x=1787410766; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pzFN1L+PgZhbcDMgKU8nIsMBCPH3C7anPGuUjcc/28Q=; b=PKvxp8JjHsf3Nh7TiKyTCf5F0MmU+SpaxIsNy5HQM+djjeuUi2X8ZEux KZhH2px6/rjIFnT5Tz2zQ8e3bOsm27FojEzAMOV1SA+bFyOdZD77qthDU aeirMqiTRFJqNkluryg7kzilL2AFFIcvqgnlDGP0/iSn/U6w2p/+hs7CF zWrwfm7xKM/VWZepIlKxLWbSlF1tbmp0xYcevmWNM17lGYsGvvUaCxPCo ne5XBC8UcYnFKovcsO1innn1OqMxYpoNiSMaGhN2jvRso/a0YPp7Jt/o0 oEQJ0dYro2cwOGqhT2fCnsb2fwzY56eC43D7pZUlTFwkC8EDsv8E8dgwJ Q==; X-CSE-ConnectionGUID: 3H6jygopQymm29ge5yQkUQ== X-CSE-MsgGUID: FHPKXFWiTDakjXvnakrVvQ== X-IronPort-AV: E=McAfee;i="6800,10657,11529"; a="75640684" X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="75640684" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:59:25 -0700 X-CSE-ConnectionGUID: PdsNClpKQ1GOlh1GNHlBYA== X-CSE-MsgGUID: GjCk9XCyTF+WMLWYvp1tTw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="172986930" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.244.115]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:59:20 -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 20/24] PCI: Refactor distributing available memory to use loops Date: Fri, 22 Aug 2025 17:56:01 +0300 Message-Id: <20250822145605.18172-21-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 pci_bus_distribute_available_resources() and pci_bridge_distribute_available_resources() retain bridge window resources and related data needed for distributing the available window in independent variables for io, memory, and prefetchable memory windows. The code is essentially the same for all of them and therefore repeated three times with different variable names. Refactor pci_bus_distribute_available_resources() to take an array. This is complicated slightly by the function taking advantage of passing the struct as value, which cannot be done for arrays in C. Therefore, copy the data into a local array in the stack in the first loop. Variable names are (hopefully) improved slightly as well. Signed-off-by: Ilpo J=C3=A4rvinen --- drivers/pci/setup-bus.c | 162 ++++++++++++++++++---------------------- include/linux/pci.h | 3 +- 2 files changed, 74 insertions(+), 91 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 28133a9c5f51..ee2f2c78d8c9 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -2058,15 +2058,16 @@ static void remove_dev_resource(struct resource *av= ail, struct pci_dev *dev, avail->start =3D min(avail->start + tmp, avail->end + 1); } =20 -static void remove_dev_resources(struct pci_dev *dev, struct resource *io, - struct resource *mmio, - struct resource *mmio_pref) +static void remove_dev_resources(struct pci_dev *dev, + struct resource available[PCI_P2P_BRIDGE_RESOURCE_NUM]) { + struct resource *mmio_pref =3D &available[PCI_BUS_BRIDGE_PREF_MEM_WINDOW]; struct resource *res; =20 pci_dev_for_each_resource(dev, res) { if (resource_type(res) =3D=3D IORESOURCE_IO) { - remove_dev_resource(io, dev, res); + remove_dev_resource(&available[PCI_BUS_BRIDGE_IO_WINDOW], + dev, res); } else if (resource_type(res) =3D=3D IORESOURCE_MEM) { =20 /* @@ -2080,10 +2081,13 @@ static void remove_dev_resources(struct pci_dev *de= v, struct resource *io, */ if ((res->flags & IORESOURCE_PREFETCH) && ((res->flags & IORESOURCE_MEM_64) =3D=3D - (mmio_pref->flags & IORESOURCE_MEM_64))) - remove_dev_resource(mmio_pref, dev, res); - else - remove_dev_resource(mmio, dev, res); + (mmio_pref->flags & IORESOURCE_MEM_64))) { + remove_dev_resource(&available[PCI_BUS_BRIDGE_PREF_MEM_WINDOW], + dev, res); + } else { + remove_dev_resource(&available[PCI_BUS_BRIDGE_MEM_WINDOW], + dev, res); + } } } } @@ -2098,45 +2102,39 @@ static void remove_dev_resources(struct pci_dev *de= v, struct resource *io, * shared with the bridges. */ static void pci_bus_distribute_available_resources(struct pci_bus *bus, - struct list_head *add_list, - struct resource io, - struct resource mmio, - struct resource mmio_pref) + struct list_head *add_list, + struct resource available_in[PCI_P2P_BRIDGE_RESOURCE_NUM]) { + struct resource available[PCI_P2P_BRIDGE_RESOURCE_NUM]; unsigned int normal_bridges =3D 0, hotplug_bridges =3D 0; - struct resource *io_res, *mmio_res, *mmio_pref_res; struct pci_dev *dev, *bridge =3D bus->self; - resource_size_t io_per_b, mmio_per_b, mmio_pref_per_b, align; + resource_size_t per_bridge[PCI_P2P_BRIDGE_RESOURCE_NUM]; + resource_size_t align; + int i; =20 - io_res =3D &bridge->resource[PCI_BRIDGE_IO_WINDOW]; - mmio_res =3D &bridge->resource[PCI_BRIDGE_MEM_WINDOW]; - mmio_pref_res =3D &bridge->resource[PCI_BRIDGE_PREF_MEM_WINDOW]; + for (i =3D 0; i < PCI_P2P_BRIDGE_RESOURCE_NUM; i++) { + struct resource *res =3D pci_bus_resource_n(bus, i); =20 - /* - * The alignment of this bridge is yet to be considered, hence it must - * be done now before extending its bridge window. - */ - align =3D pci_resource_alignment(bridge, io_res); - if (!io_res->parent && align) - io.start =3D min(ALIGN(io.start, align), io.end + 1); - - align =3D pci_resource_alignment(bridge, mmio_res); - if (!mmio_res->parent && align) - mmio.start =3D min(ALIGN(mmio.start, align), mmio.end + 1); + available[i] =3D available_in[i]; =20 - align =3D pci_resource_alignment(bridge, mmio_pref_res); - if (!mmio_pref_res->parent && align) - mmio_pref.start =3D min(ALIGN(mmio_pref.start, align), - mmio_pref.end + 1); + /* + * The alignment of this bridge is yet to be considered, + * hence it must be done now before extending its bridge + * window. + */ + align =3D pci_resource_alignment(bridge, res); + if (!res->parent && align) + available[i].start =3D min(ALIGN(available[i].start, align), + available[i].end + 1); =20 - /* - * Now that we have adjusted for alignment, update the bridge window - * resources to fill as much remaining resource space as possible. - */ - adjust_bridge_window(bridge, io_res, add_list, resource_size(&io)); - adjust_bridge_window(bridge, mmio_res, add_list, resource_size(&mmio)); - adjust_bridge_window(bridge, mmio_pref_res, add_list, - resource_size(&mmio_pref)); + /* + * Now that we have adjusted for alignment, update the + * bridge window resources to fill as much remaining + * resource space as possible. + */ + adjust_bridge_window(bridge, res, add_list, + resource_size(&available[i])); + } =20 /* * Calculate how many hotplug bridges and normal bridges there @@ -2160,7 +2158,7 @@ static void pci_bus_distribute_available_resources(st= ruct pci_bus *bus, */ list_for_each_entry(dev, &bus->devices, bus_list) { if (!dev->is_virtfn) - remove_dev_resources(dev, &io, &mmio, &mmio_pref); + remove_dev_resources(dev, available); } =20 /* @@ -2172,16 +2170,9 @@ static void pci_bus_distribute_available_resources(s= truct pci_bus *bus, * split between non-hotplug bridges. This is to allow possible * hotplug bridges below them to get the extra space as well. */ - if (hotplug_bridges) { - io_per_b =3D div64_ul(resource_size(&io), hotplug_bridges); - mmio_per_b =3D div64_ul(resource_size(&mmio), hotplug_bridges); - mmio_pref_per_b =3D div64_ul(resource_size(&mmio_pref), - hotplug_bridges); - } else { - io_per_b =3D div64_ul(resource_size(&io), normal_bridges); - mmio_per_b =3D div64_ul(resource_size(&mmio), normal_bridges); - mmio_pref_per_b =3D div64_ul(resource_size(&mmio_pref), - normal_bridges); + for (i =3D 0; i < PCI_P2P_BRIDGE_RESOURCE_NUM; i++) { + per_bridge[i] =3D div64_ul(resource_size(&available[i]), + hotplug_bridges ?: normal_bridges); } =20 for_each_pci_bridge(dev, bus) { @@ -2194,49 +2185,41 @@ static void pci_bus_distribute_available_resources(= struct pci_bus *bus, if (hotplug_bridges && !dev->is_hotplug_bridge) continue; =20 - res =3D &dev->resource[PCI_BRIDGE_IO_WINDOW]; + for (i =3D 0; i < PCI_P2P_BRIDGE_RESOURCE_NUM; i++) { + res =3D pci_bus_resource_n(bus, i); =20 - /* - * Make sure the split resource space is properly aligned - * for bridge windows (align it down to avoid going above - * what is available). - */ - align =3D pci_resource_alignment(dev, res); - resource_set_size(&io, ALIGN_DOWN_IF_NONZERO(io_per_b, align)); - - /* - * The x_per_b holds the extra resource space that can be - * added for each bridge but there is the minimal already - * reserved as well so adjust x.start down accordingly to - * cover the whole space. - */ - io.start -=3D resource_size(res); - - res =3D &dev->resource[PCI_BRIDGE_MEM_WINDOW]; - align =3D pci_resource_alignment(dev, res); - resource_set_size(&mmio, - ALIGN_DOWN_IF_NONZERO(mmio_per_b,align)); - mmio.start -=3D resource_size(res); + /* + * Make sure the split resource space is properly + * aligned for bridge windows (align it down to + * avoid going above what is available). + */ + align =3D pci_resource_alignment(dev, res); + resource_set_size(&available[i], + ALIGN_DOWN_IF_NONZERO(per_bridge[i], + align)); =20 - res =3D &dev->resource[PCI_BRIDGE_PREF_MEM_WINDOW]; - align =3D pci_resource_alignment(dev, res); - resource_set_size(&mmio_pref, - ALIGN_DOWN_IF_NONZERO(mmio_pref_per_b, align)); - mmio_pref.start -=3D resource_size(res); + /* + * The per_bridge holds the extra resource space + * that can be added for each bridge but there is + * the minimal already reserved as well so adjust + * x.start down accordingly to cover the whole + * space. + */ + available[i].start -=3D resource_size(res); + } =20 - pci_bus_distribute_available_resources(b, add_list, io, mmio, - mmio_pref); + pci_bus_distribute_available_resources(b, add_list, available); =20 - io.start +=3D io.end + 1; - mmio.start +=3D mmio.end + 1; - mmio_pref.start +=3D mmio_pref.end + 1; + for (i =3D 0; i < PCI_P2P_BRIDGE_RESOURCE_NUM; i++) + available[i].start +=3D available[i].end + 1; } } =20 static void pci_bridge_distribute_available_resources(struct pci_dev *brid= ge, struct list_head *add_list) { - struct resource available_io, available_mmio, available_mmio_pref; + struct resource *res, available[PCI_P2P_BRIDGE_RESOURCE_NUM]; + unsigned int i; =20 if (!bridge->is_hotplug_bridge) return; @@ -2244,14 +2227,13 @@ static void pci_bridge_distribute_available_resourc= es(struct pci_dev *bridge, pci_dbg(bridge, "distributing available resources\n"); =20 /* Take the initial extra resources from the hotplug port */ - available_io =3D bridge->resource[PCI_BRIDGE_IO_WINDOW]; - available_mmio =3D bridge->resource[PCI_BRIDGE_MEM_WINDOW]; - available_mmio_pref =3D bridge->resource[PCI_BRIDGE_PREF_MEM_WINDOW]; + for (i =3D 0; i < PCI_P2P_BRIDGE_RESOURCE_NUM; i++) { + res =3D pci_resource_n(bridge, PCI_BRIDGE_RESOURCES + i); + available[i] =3D *res; + } =20 pci_bus_distribute_available_resources(bridge->subordinate, - add_list, available_io, - available_mmio, - available_mmio_pref); + add_list, available); } =20 static bool pci_bridge_resources_not_assigned(struct pci_dev *dev) diff --git a/include/linux/pci.h b/include/linux/pci.h index 275df4058767..723e9cede69d 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -119,7 +119,8 @@ enum { #define PCI_CB_BRIDGE_MEM_1_WINDOW (PCI_BRIDGE_RESOURCES + 3) =20 /* Total number of bridge resources for P2P and CardBus */ -#define PCI_BRIDGE_RESOURCE_NUM 4 +#define PCI_P2P_BRIDGE_RESOURCE_NUM 3 +#define PCI_BRIDGE_RESOURCE_NUM 4 =20 /* Resources assigned to buses behind the bridge */ PCI_BRIDGE_RESOURCES, --=20 2.39.5 From nobody Fri Oct 3 23:02:05 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (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 643C6227B88; Fri, 22 Aug 2025 14:59:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874775; cv=none; b=K5L9xVdx52KL7ay9Zv4PC5AUHrB1emlDYZn+itEBytnx8k5PVIId40TPhei0aWWpTqGBGUGIsudmsIZ+S4zm508AxTdh3ZWCJ5i6dAvFiuspmPa6qSrwPVHDspiOJM2oPTklppLD3NDig25G8hdMdrvwBEYwTVdGm9HBY1j/rH0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874775; c=relaxed/simple; bh=FRfssbwFVOeTRuS2nCD7Ynmj6Ps7cVzti/WfWUW/SwQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=aTbPv6pf8xFymJ03NCybLB5s5J13inMX1+WeI7xBLcXqfkOTpVdm3umrXnnv2UeiHfOFOR+2nUZPMCboG0ztql1hZvhGRXVwRhnlrDdQcaUmFK3Fbs1/CAoj1KyyqGtgHPRPzmW5tvYpSphf5OiAIPxIcCt6LF37+/Ip40u1I88= 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=KLi+cj+2; arc=none smtp.client-ip=198.175.65.10 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="KLi+cj+2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1755874775; x=1787410775; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FRfssbwFVOeTRuS2nCD7Ynmj6Ps7cVzti/WfWUW/SwQ=; b=KLi+cj+2Gw4b84vymRsQP+iuUjqInzEzez8ucpAI/eBk3ZKWjfn6A53b bg3/VRF0S5bD7AEBJ/r2Q08oztXiUGjlEvsnvVaec0+ZVKJmbavryX+3I U60SwC5668IS05r6Zrsxw4JNTI8MLTMjDmIcs1B2lAAJx0PhPsyYOJ41f dO+ynnPKuaZy7MrmEGIjG3lspkpmxnKkWkXf8G954ZQ8rmODNPebHTZFU 2ufIs5+Ko6gjwtYv88nKFtsdatjO6YJGOztgiDSeFrDgLNtemDa8DN5TP NdM3zq2gzZzAJChGAwzRf+0XXDgDFgdSz6E4xm46oOvMOhclVDf7a0yAa w==; X-CSE-ConnectionGUID: Lul5mvyQQ0GQDhSRgJYezA== X-CSE-MsgGUID: sr8csa7zRP+a/n/2Bs9bCA== X-IronPort-AV: E=McAfee;i="6800,10657,11529"; a="75640712" X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="75640712" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:59:34 -0700 X-CSE-ConnectionGUID: 7HgkGi3zQqKRPBeZCM3JIw== X-CSE-MsgGUID: FNeyO842RAq2qXrusEvxbg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="172986945" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.244.115]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:59:29 -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 21/24] PCI: Refactor remove_dev_resources() to use pbus_select_window() Date: Fri, 22 Aug 2025 17:56:02 +0300 Message-Id: <20250822145605.18172-22-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 Convert remove_dev_resources() to use pbus_select_window(). As 'available' is not the real resources, the index has to be adjusted as only bridge resource counterparts are present in the 'available' array. Signed-off-by: Ilpo J=C3=A4rvinen --- drivers/pci/setup-bus.c | 34 +++++++++------------------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index ee2f2c78d8c9..ece533181ff1 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -2061,34 +2061,18 @@ static void remove_dev_resource(struct resource *av= ail, struct pci_dev *dev, static void remove_dev_resources(struct pci_dev *dev, struct resource available[PCI_P2P_BRIDGE_RESOURCE_NUM]) { - struct resource *mmio_pref =3D &available[PCI_BUS_BRIDGE_PREF_MEM_WINDOW]; - struct resource *res; + struct resource *res, *b_win; + int idx; =20 pci_dev_for_each_resource(dev, res) { - if (resource_type(res) =3D=3D IORESOURCE_IO) { - remove_dev_resource(&available[PCI_BUS_BRIDGE_IO_WINDOW], - dev, res); - } else if (resource_type(res) =3D=3D IORESOURCE_MEM) { + b_win =3D pbus_select_window(dev->bus, res); + if (!b_win) + continue; =20 - /* - * Make sure prefetchable memory is reduced from - * the correct resource. Specifically we put 32-bit - * prefetchable memory in non-prefetchable window - * if there is a 64-bit prefetchable window. - * - * See comments in __pci_bus_size_bridges() for - * more information. - */ - if ((res->flags & IORESOURCE_PREFETCH) && - ((res->flags & IORESOURCE_MEM_64) =3D=3D - (mmio_pref->flags & IORESOURCE_MEM_64))) { - remove_dev_resource(&available[PCI_BUS_BRIDGE_PREF_MEM_WINDOW], - dev, res); - } else { - remove_dev_resource(&available[PCI_BUS_BRIDGE_MEM_WINDOW], - dev, res); - } - } + idx =3D pci_resource_num(dev->bus->self, b_win); + idx -=3D PCI_BRIDGE_RESOURCES; + + remove_dev_resource(&available[idx], dev, res); } } =20 --=20 2.39.5 From nobody Fri Oct 3 23:02:05 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (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 76405343D98; Fri, 22 Aug 2025 14:59:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874784; cv=none; b=IjJs9DKyXbYFKWvQjzzEIcdQhBOdlEqknTsHv/1/138VqA/Sc6zt4/HiR/JPgGkrkiWCKUkZxhwN8yhw2qdzhHZteZieQhjGQizG4yNu5y+zT39H1wJOYVmlVI4DULKbuOJS53PgiI6eDF8EDI/yR4rGSLq9oTt8bhF9b1InF/M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874784; c=relaxed/simple; bh=HTxHAiNuvyuD34kLb+03Rz07JtALaQ3E9pcuMeDZoEE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=sLz/8dUF4NmDoiM26s6SIkADUKJMr+wMPn5sZr7aBSLY8+POhRGCd8c79Y6/ZVJ6cIdwXp4mFA9x9fVgRkHJX9FCmtSww2StBI9cFsd+PQ7Zcjcly9fZ1RnG9ROlefk7D36EwjBc3Vjv6iSWi7kwYpFQZo0K2bt0m6hpIVWRlKI= 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=egxSwexT; arc=none smtp.client-ip=198.175.65.10 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="egxSwexT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1755874784; x=1787410784; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HTxHAiNuvyuD34kLb+03Rz07JtALaQ3E9pcuMeDZoEE=; b=egxSwexTshS15NVuSKQ7h9aupKsw6nWFFQyvpaV2ADiF721uWhW3NI7l nnUmZdPwBUe0MjVbuB7I+vDIc/6fJO++WvqC/pTLczr4G+UO/N9gcUTBv Vc3Rm/WvKOPdWoOP6xoSaEnx5ckH2AjfcjGTZ51NZdbQDy9lW++PkOwTN XX5NS23RLkWSmZJkXhRwhJM+aD8iBZ3EqQT3Md/dagwqSmViwzPDhyU99 aYwTiXrYI4PD2mFYIBBAqlub/QH1/oufYpgJoqV4xxAgFt/BSs3EEgv+x 3GpFl3UyN+VeWlBvAGa+NZynjzQm71nC+cVmzNePdAcAp9SNqiyFwNUYc A==; X-CSE-ConnectionGUID: eGRF8F5DQ6WqOVMbGfPwJg== X-CSE-MsgGUID: raz9YQbWQiyr5TYICPpJcw== X-IronPort-AV: E=McAfee;i="6800,10657,11529"; a="75640737" X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="75640737" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:59:44 -0700 X-CSE-ConnectionGUID: iZNsZnZnSe2zaHcSW5F1PA== X-CSE-MsgGUID: s8iZ9QfNSsyPmEDxoDG8qA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="172986954" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.244.115]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:59:38 -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 22/24] PCI: Add pci_setup_one_bridge_window() Date: Fri, 22 Aug 2025 17:56:03 +0300 Message-Id: <20250822145605.18172-23-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 pci_bridge_release_resources() contains a resource type hack to work around the unsuitable __pci_setup_bridge() interface. Extract the switch statement that picks the correct bridge window setup function from pci_claim_bridge_resource() into pci_setup_one_bridge_window() and use it also in pci_bridge_release_resources(). Signed-off-by: Ilpo J=C3=A4rvinen --- drivers/pci/setup-bus.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index ece533181ff1..f5b0274bde0a 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -953,6 +953,23 @@ static void __pci_setup_bridge(struct pci_bus *bus, un= signed long type) pci_write_config_word(bridge, PCI_BRIDGE_CONTROL, bus->bridge_ctl); } =20 +static void pci_setup_one_bridge_window(struct pci_dev *bridge, int resno) +{ + switch (resno) { + case PCI_BRIDGE_IO_WINDOW: + pci_setup_bridge_io(bridge); + break; + case PCI_BRIDGE_MEM_WINDOW: + pci_setup_bridge_mmio(bridge); + break; + case PCI_BRIDGE_PREF_MEM_WINDOW: + pci_setup_bridge_mmio_pref(bridge); + break; + default: + return; + } +} + void __weak pcibios_setup_bridge(struct pci_bus *bus, unsigned long type) { } @@ -987,19 +1004,7 @@ int pci_claim_bridge_resource(struct pci_dev *bridge,= int i) if (pci_bus_clip_resource(bridge, i)) ret =3D pci_claim_resource(bridge, i); =20 - switch (i) { - case PCI_BRIDGE_IO_WINDOW: - pci_setup_bridge_io(bridge); - break; - case PCI_BRIDGE_MEM_WINDOW: - pci_setup_bridge_mmio(bridge); - break; - case PCI_BRIDGE_PREF_MEM_WINDOW: - pci_setup_bridge_mmio_pref(bridge); - break; - default: - return -EINVAL; - } + pci_setup_one_bridge_window(bridge, i); =20 return ret; } @@ -1839,10 +1844,7 @@ static void pci_bridge_release_resources(struct pci_= bus *bus, if (ret) return; =20 - /* Avoiding touch the one without PREF */ - if (type & IORESOURCE_PREFETCH) - type =3D IORESOURCE_PREFETCH; - __pci_setup_bridge(bus, type); + pci_setup_one_bridge_window(dev, PCI_BRIDGE_RESOURCES + idx); } =20 enum release_type { --=20 2.39.5 From nobody Fri Oct 3 23:02:05 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (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 7B757307AEF; Fri, 22 Aug 2025 14:59:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874794; cv=none; b=Hk7Ow6qpMSvifWxz2gU04DbTSOdGvUreEV6IwNJdIiXkZwbts0VhaEWObgWncL7CyyE8A4SQbRCW4Y0xlYRrEhb+CGENwNW1eo3NAmqLnSmjCmwGfSHWJg8lRTFnE7gf2yI3+Tjy1S+s2akIkKMZ6ZHGTz1oOoLqRUAZ0TdVB/c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874794; c=relaxed/simple; bh=LA/Wi//KofVB6JuAktPoP6oeJFceP9LDqmAtl8M/Pho=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=cJviYQCVpQadi4mZmkbtniFmfIRwYqtAzOzZ7dQDYxifa3btJGgQL76eRZwtlBn1GfcXsXt1T8I1nDue+uJ44lNkxmP/UFPmcOlSKyjWsJ0IAl/lYiDBg7t37l4ifI5D66XrY9jioVrUJbMsi3d0P+qNDp1Cgt1LH8eeM5Owufg= 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=eDAg9NE3; arc=none smtp.client-ip=198.175.65.10 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="eDAg9NE3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1755874793; x=1787410793; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LA/Wi//KofVB6JuAktPoP6oeJFceP9LDqmAtl8M/Pho=; b=eDAg9NE3S0uS146e4DRuCRMgZGo8gzaWTriStjEduHP+pv+boUfNZ4fM rGz/jGktYD1kKcHDE/U0GzhrCZV63gX5YortI2cQaXfi2pIT7iCMJMvvf LUjYAmePjzQroDbUIMHJ8sQk1d4uwCsHmFrZB65IjISCEz5lYOh7JkPjI XcRqhSKLI+6F2LgZXlHdaY9W6eCmqmtz91UXEJVPeTTur17Z9Tja6ivBT ckL0GuwncdOWxHpFQh1WZEoPu51dfXTOoI7Inxu0FuaUvCXX6cObnRoT8 TI8ZKIJbc4J2XKk2SGiQosr2XXp99L01ppkjT5B/6yJFzpI0+DdxZp2W2 A==; X-CSE-ConnectionGUID: ZaCLv8SARESeW1NaUwvOfA== X-CSE-MsgGUID: g1ytS3B2Q+O0xp8xfID2Tw== X-IronPort-AV: E=McAfee;i="6800,10657,11529"; a="75640759" X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="75640759" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:59:53 -0700 X-CSE-ConnectionGUID: XUYJVNexT5mA6fsjbzP14w== X-CSE-MsgGUID: V9nZCPRqR/aPpyAtr6/8sw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="172986963" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.244.115]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:59:47 -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 23/24] PCI: Pass bridge window to pci_bus_release_bridge_resources() Date: Fri, 22 Aug 2025 17:56:04 +0300 Message-Id: <20250822145605.18172-24-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 pci_bus_release_bridge_resources() takes type, which is converted into a bridge window resource in pci_bridge_release_resources(). Find out the correct bridge window for resource whose assignment failed. Pass that bridge window to pci_bus_release_bridge_resources() instead of passing the type. When recursing to subordinate, check which bridge windows have to be released and recurse for each. For now, use pbus_select_window_for_type() instead of pbus_select_window() because non-bridge window resources still have their flags reset which destroys the type information from the struct resource. The struct pci_dev_resource holds a copy of the flags which are used instead. Signed-off-by: Ilpo J=C3=A4rvinen --- drivers/pci/setup-bus.c | 69 ++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 42 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index f5b0274bde0a..9c69a84f2b23 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1800,51 +1800,24 @@ static void __pci_bridge_assign_resources(const str= uct pci_dev *bridge, } =20 static void pci_bridge_release_resources(struct pci_bus *bus, - unsigned long type) + struct resource *b_win) { struct pci_dev *dev =3D bus->self; - struct resource *r; - struct resource *b_res; int idx, ret; =20 - b_res =3D &dev->resource[PCI_BRIDGE_RESOURCES]; - - /* - * 1. If IO port assignment fails, release bridge IO port. - * 2. If non pref MMIO assignment fails, release bridge nonpref MMIO. - * 3. If 64bit pref MMIO assignment fails, and bridge pref is 64bit, - * release bridge pref MMIO. - * 4. If pref MMIO assignment fails, and bridge pref is 32bit, - * release bridge pref MMIO. - * 5. If pref MMIO assignment fails, and bridge pref is not - * assigned, release bridge nonpref MMIO. - */ - if (type & IORESOURCE_IO) - idx =3D 0; - else if (!(type & IORESOURCE_PREFETCH)) - idx =3D 1; - else if ((type & IORESOURCE_MEM_64) && - (b_res[2].flags & IORESOURCE_MEM_64)) - idx =3D 2; - else if (!(b_res[2].flags & IORESOURCE_MEM_64) && - (b_res[2].flags & IORESOURCE_PREFETCH)) - idx =3D 2; - else - idx =3D 1; - - r =3D &b_res[idx]; - - if (!r->parent) + if (!b_win->parent) return; =20 + idx =3D pci_resource_num(dev, b_win); + /* If there are children, release them all */ - release_child_resources(r); + release_child_resources(b_win); =20 - ret =3D pci_release_resource(dev, PCI_BRIDGE_RESOURCES + idx); + ret =3D pci_release_resource(dev, idx); if (ret) return; =20 - pci_setup_one_bridge_window(dev, PCI_BRIDGE_RESOURCES + idx); + pci_setup_one_bridge_window(dev, idx); } =20 enum release_type { @@ -1857,7 +1830,7 @@ enum release_type { * a larger window later. */ static void pci_bus_release_bridge_resources(struct pci_bus *bus, - unsigned long type, + struct resource *b_win, enum release_type rel_type) { struct pci_dev *dev; @@ -1865,6 +1838,8 @@ static void pci_bus_release_bridge_resources(struct p= ci_bus *bus, =20 list_for_each_entry(dev, &bus->devices, bus_list) { struct pci_bus *b =3D dev->subordinate; + struct resource *res; + if (!b) continue; =20 @@ -1873,9 +1848,15 @@ static void pci_bus_release_bridge_resources(struct = pci_bus *bus, if ((dev->class >> 8) !=3D PCI_CLASS_BRIDGE_PCI) continue; =20 - if (rel_type =3D=3D whole_subtree) - pci_bus_release_bridge_resources(b, type, - whole_subtree); + if (rel_type !=3D whole_subtree) + continue; + + pci_bus_for_each_resource(b, res) { + if (res->parent !=3D b_win) + continue; + + pci_bus_release_bridge_resources(b, res, whole_subtree); + } } =20 if (pci_is_root_bus(bus)) @@ -1885,7 +1866,7 @@ static void pci_bus_release_bridge_resources(struct p= ci_bus *bus, return; =20 if ((rel_type =3D=3D whole_subtree) || is_leaf_bridge) - pci_bridge_release_resources(bus, type); + pci_bridge_release_resources(bus, b_win); } =20 static void pci_bus_dump_res(struct pci_bus *bus) @@ -2282,9 +2263,13 @@ static void pci_prepare_next_assign_round(struct lis= t_head *fail_head, * enough to contain child device resources. */ list_for_each_entry(fail_res, fail_head, list) { - pci_bus_release_bridge_resources(fail_res->dev->bus, - fail_res->flags & PCI_RES_TYPE_MASK, - rel_type); + struct pci_bus *bus =3D fail_res->dev->bus; + struct resource *b_win; + + b_win =3D pbus_select_window_for_type(bus, fail_res->flags); + if (!b_win) + continue; + pci_bus_release_bridge_resources(bus, b_win, rel_type); } =20 /* Restore size and flags */ --=20 2.39.5 From nobody Fri Oct 3 23:02:05 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (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 D1DFE3128C8; Fri, 22 Aug 2025 15:00:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874803; cv=none; b=XJO7VsT7QCvw8LU47muFonKpeTdCWABTfpNG/YFp7vK1Yw1+64Wf01My0eEhiO8FZTBF+/2OGqk67V1o9ZZB4YLxzQzGf4R8bRLN668ORvZu5fzz/B1+UT0KK5LVG/xD/0Pl7pJfTGyDSrsyfuT2TCiRbFYrB1lt8+hptLlvfMU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755874803; c=relaxed/simple; bh=EK5M2izVE5p40XIaVUFrZSmUkgoozndw/itQ2SrR1Ew=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=mf5eLJXaG3+w9NO19gIvsqx+KOfy8g0wGF1pz3lN4p5de2lhX22T7UNZwHw7zb9ZIba+SidQhYLkkKVUrERvJp1msVOc7Lixt62zXgQq3a3wP0gyhDXTwiTXWzfQc953xxFWKN+Ezp5MfRULqy6qvZ2GgSxAKPWRFwilup82nWs= 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=R91WdgkA; arc=none smtp.client-ip=198.175.65.14 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="R91WdgkA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1755874802; x=1787410802; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EK5M2izVE5p40XIaVUFrZSmUkgoozndw/itQ2SrR1Ew=; b=R91WdgkAOa9/1Jz1EiE36E4dJCmMDFBS0vs3jEHAc5IZ6AJwlO/faiT6 vVT+suVhEBrwrsk17pBfPVXFiJJX7Lh5XRrlz2lrZLdZFOfmF9GpLaZrq /m6ut+U/wsE94lrZhwNPtyi64z/w37LgKf7Z7XUwXW5HtnWAYksl+q0CE VHgAMqS3FVFyvYtnxdfxC9dGEpgggMZvPmun7P/O9jPgWIDdn/AB13iuM x20b/NnmmVZSlW18tYNW7fxSiurOzCbIJJNtScfH8vk4HTU1HRL5uguKU 0ltxq25C7ryQ+0qL7pYFTmwYLOGm1VBQwj5VX8Civwuw110x3WSQnyMih A==; X-CSE-ConnectionGUID: h/wuobybT0+ycmdCzmCUGQ== X-CSE-MsgGUID: xu8tuuBTS8WERaScdsV3cw== X-IronPort-AV: E=McAfee;i="6800,10657,11529"; a="62016122" X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="62016122" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 08:00:01 -0700 X-CSE-ConnectionGUID: SF7XkM7uRzyQinj/cT/aBA== X-CSE-MsgGUID: 4p1p4yJ2RJyg+8Th6VhtFg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.17,309,1747724400"; d="scan'208";a="173994924" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.244.115]) by fmviesa004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Aug 2025 07:59:56 -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 24/24] PCI: Alter misleading recursion to pci_bus_release_bridge_resources() Date: Fri, 22 Aug 2025 17:56:05 +0300 Message-Id: <20250822145605.18172-25-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 Recursing into pci_bus_release_bridge_resources() should not alter rel_type because it makes no sense to change the release type within the recursion call chain. A literal "whole_subtree" is passed into the recursion instead of "rel_type" parameter which is misleading as the release type should remain the same throughout the entire operation. This is not a correctness issue because of the preceding if () that only allows the recursion to happen if rel_type is "whole_subtree". Still, replace the non-intuitive parameter with direct passing of "rel_type". Signed-off-by: Ilpo J=C3=A4rvinen --- drivers/pci/setup-bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 9c69a84f2b23..0fbdb031bc3d 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -1855,7 +1855,7 @@ static void pci_bus_release_bridge_resources(struct p= ci_bus *bus, if (res->parent !=3D b_win) continue; =20 - pci_bus_release_bridge_resources(b, res, whole_subtree); + pci_bus_release_bridge_resources(b, res, rel_type); } } =20 --=20 2.39.5