Linux PCI subsystem development
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: "Bjorn Helgaas" <bhelgaas@google.com>,
	"Lorenzo Pieralisi" <lorenzo.pieralisi@arm.com>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Wilczyński" <kw@linux.com>,
	"Alex Deucher" <alexander.deucher@amd.com>,
	"Christian König" <christian.koenig@amd.com>,
	"Jani Nikula" <jani.nikula@linux.intel.com>,
	"Joonas Lahtinen" <joonas.lahtinen@linux.intel.com>,
	"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
	"Tvrtko Ursulin" <tursulin@ursulin.net>,
	"Matthew Brost" <matthew.brost@intel.com>,
	"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
	"Michał Winiarski" <michal.winiarski@intel.com>,
	"Ville Syrjälä" <ville.syrjala@linux.intel.com>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org,
	intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org,
	"Honghui Zhang" <honghui.zhang@mediatek.com>,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>, stable@vger.kernel.org
Subject: [PATCH 04/15] PCI: Consistently use Header Type to detect bridge headers
Date: Tue,  1 Dec 2026 17:58:28 +0200	[thread overview]
Message-ID: <20261201155844.2278-5-ilpo.jarvinen@linux.intel.com> (raw)
In-Reply-To: <20261201155844.2278-1-ilpo.jarvinen@linux.intel.com>

The Header Type decides the layout of the config space. A Type 0 header
is used by endpoints and a Type 1 header by bridges, which have the
bridge window registers. Earlier, Type 2 was also used for CardBus
bridges. The Class Code only describes the function of the device.

Commit b2fb5cc57469 ("PCI: Rely on config space header type, not class
code") converted bridge window sizing and assignment to use the Header
Type, but __pci_bridge_assign_resources(), pci_claim_bridge_resource()
and pci_bus_release_bridge_resources() still use the Class Code to
detect bridges. Using an inconsistent classifier creates corner cases
in programming, claiming, and releasing the bridge windows of Type 1
bridges whose Class Code is not PCI_CLASS_BRIDGE_PCI.

Consistently use the Header Type to detect bridges also in those
functions. If filtering out Type 1 devices with an unexpected Class Code
is desirable, it should be done in pci_setup_device() which already
does similar filtering for the other Header Types.

Fixes: b2fb5cc57469 ("PCI: Rely on config space header type, not class code")
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Cc: stable@vger.kernel.org
---

This patch supercedes the change in the cardbus series:

  https://lore.kernel.org/linux-pci/20261109210714.3862-3-ilpo.jarvinen@linux.intel.com/

 drivers/pci/setup-bus.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index ea0039fb6ad0..c1033191571c 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -948,7 +948,7 @@ int pci_claim_bridge_resource(struct pci_dev *bridge, int i)
 	if (pci_claim_resource(bridge, i) == 0)
 		return 0;	/* Claimed the window */
 
-	if ((bridge->class >> 8) != PCI_CLASS_BRIDGE_PCI)
+	if (bridge->hdr_type != PCI_HEADER_TYPE_BRIDGE)
 		return 0;
 
 	if (i > PCI_BRIDGE_PREF_MEM_WINDOW)
@@ -1636,12 +1636,12 @@ static void __pci_bridge_assign_resources(struct pci_dev *bridge,
 
 	__pci_bus_assign_resources(b, add_list, fail_head);
 
-	switch (bridge->class >> 8) {
-	case PCI_CLASS_BRIDGE_PCI:
+	switch (bridge->hdr_type) {
+	case PCI_HEADER_TYPE_BRIDGE:
 		pci_setup_bridge(b);
 		break;
 
-	case PCI_CLASS_BRIDGE_CARDBUS:
+	case PCI_HEADER_TYPE_CARDBUS:
 		pci_setup_cardbus_bridge(b);
 		break;
 
@@ -1701,7 +1701,7 @@ static void pci_bus_release_bridge_resources(struct pci_bus *bus,
 
 		is_leaf_bridge = false;
 
-		if ((dev->class >> 8) != PCI_CLASS_BRIDGE_PCI)
+		if (dev->hdr_type != PCI_HEADER_TYPE_BRIDGE)
 			continue;
 
 		if (rel_type != whole_subtree)
@@ -1718,7 +1718,7 @@ static void pci_bus_release_bridge_resources(struct pci_bus *bus,
 	if (pci_is_root_bus(bus))
 		return;
 
-	if ((bus->self->class >> 8) != PCI_CLASS_BRIDGE_PCI)
+	if (bus->self->hdr_type != PCI_HEADER_TYPE_BRIDGE)
 		return;
 
 	if ((rel_type == whole_subtree) || is_leaf_bridge)
-- 
2.47.3


  parent reply	other threads:[~2026-12-01 15:59 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20261201155844.2278-1-ilpo.jarvinen@linux.intel.com>
2026-12-01 15:58 ` [PATCH 01/15] PCI: Release all resources before restoring them in BAR resize rollback Ilpo Järvinen
2026-12-01 15:58 ` [PATCH 02/15] PCI: Set new BAR Size only after releasing the BARs for BAR resize Ilpo Järvinen
2026-12-01 15:58 ` [PATCH 03/15] PCI: Abort BAR resize only if saving the resized BAR fails Ilpo Järvinen
2026-12-01 15:58 ` Ilpo Järvinen [this message]
2026-12-01 15:58 ` [PATCH 09/15] PCI: Do not release resources with children in pci_release_resource() Ilpo Järvinen
2026-12-01 15:58 ` [PATCH 13/15] PCI: Split pci_resource_post_release() out of pci_release_resource() Ilpo Järvinen
2026-12-01 15:58 ` [PATCH 14/15] PCI: Add iterators for devices and resources in bus windows Ilpo Järvinen
2026-12-01 15:58 ` [PATCH 15/15] PCI: Release only PCI resources when releasing a resource tree Ilpo Järvinen
2026-12-02  0:22   ` Ilpo Järvinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201155844.2278-5-ilpo.jarvinen@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=airlied@gmail.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=bhelgaas@google.com \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=honghui.zhang@mediatek.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=kw@linux.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=matthew.brost@intel.com \
    --cc=michal.winiarski@intel.com \
    --cc=robh@kernel.org \
    --cc=rodrigo.vivi@intel.com \
    --cc=simona@ffwll.ch \
    --cc=stable@vger.kernel.org \
    --cc=thomas.hellstrom@linux.intel.com \
    --cc=tursulin@ursulin.net \
    --cc=ville.syrjala@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox