From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.19 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796140924; b=yOqX+i/8KR9NSjBQnSgShLqj0pNH/9hR2yeuwTfQOwLyE4v5mfGvyaZZMryevQjOrVUF l54ePv713AMiVTZWxUB/uY4FXD2oV46zarDOnAvmHHtRsjiDPmxKHY/lvUpNSwjCEeqfF GDl+BlYUWYIaBiBpC9MqehliVkXbXh2EHqlysNM5BV7NmFIn7E905fpt9bfyQXcIr7S0L jAuzy5eu4kqICC2dhWJRS3RGdTsQrDsh+ndgBTntnH4jpq05GfWzSwiv7bQW1y8j9w6ZN 61HbnIy7cvI1ofCBmRg77ybFpACrnBlKGKHfCER7mQ1uVvlkMjMApWAvCVA3UToioKA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796140924; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Type:Content-Transfer-Encoding; bh=XefjdUqHihzNcBZ6/A1xfh5gYFKKi6O91VnDncgmVO8=; b=l+IMYkOWYjLRUvqieA90yQYHYS2rNizKqJfsiI8lblJtNh4GTZZ3H952jMVi/qqiGncf kZarmb1XQtnE5c5G0Msf479pkJKwWkzMoPGvu1GCvI9SBj2Dh98J8MnOH/EOBEIojtpUX rvBsGJMWwBNM4ae8OlMsM63AxzuvF1ITO8ZuROFR4rYM3WKCGV2kKYLo19kpsYYz/DuMw aseFwgSE7/Xkhg2kcQnkMSNO2fzPk1OpychBUIjbVvOZHKmTErmgz1jZHeB1Yg/27M0uQ 0xU3rlKx9+HaGJP0hmjeRsDhg+uVxgKZYd1kBZbmz2pKwVUAxh6dK1NyOuXVlG6/9hg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b="n09N/IRn"; arc=none smtp.remote-ip=198.175.65.19 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 341E9606A320; Tue, 1 Dec 2026 16:02:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 341E9606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass 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.a=rsa-sha256 header.s=Intel header.b=n09N/IRn DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796140923; x=1827676923; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XefjdUqHihzNcBZ6/A1xfh5gYFKKi6O91VnDncgmVO8=; b=n09N/IRn4gIk76kwVzlniVHlS/fVG4+3AdVlHaffc3a4oPjN/HwauPLd pdYR9L8bFWbbbfeLVEDU7D3MqDl95M0paOseL+8IqzK+oOhv8zulMKV1k s+yuuJ7nqxYT9TGFZKEBINj8YaJBGToUgCQYLL98jfL6FmKN5gMCMUeIn RwK7Qm8xDiXmHvs02oj1lIMlNtUtCIzDSibCIAKtyP2oLfUJekhpoGqAA 8ynszwYknFyMWmnUfaW+bh0Jvjeda1WU53LjFu+DJgjn6U8pEIyJzAb4H 1goRiGL3pDP7hN8eWua886fCEv1xLPuWZq3DG1ynHT7MwRSgcOh1QZWBE g==; X-CSE-ConnectionGUID: t/kxy1B4SvayguExYUEe9w== X-CSE-MsgGUID: /Px+bVfhQgy32Pp67Hc7RA== X-IronPort-AV: E=McAfee;i="6800,10657,11983"; a="5098492" X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="5098492" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 08:02:03 -0800 X-CSE-ConnectionGUID: khLiCo8DSRSkCa9cZtHvwQ== X-CSE-MsgGUID: izkgMgedRQeQNySr6WSqUA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="13399727" Received: from pgcooper-mobl3.ger.corp.intel.com (HELO localhost) ([10.245.245.21]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 08:01:55 -0800 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: Bjorn Helgaas , Lorenzo Pieralisi , Rob Herring , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Alex Deucher , =?UTF-8?q?Christian=20K=C3=B6nig?= , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , Matthew Brost , =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , =?UTF-8?q?Micha=C5=82=20Winiarski?= , =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= , David Airlie , Simona Vetter , dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH 14/15] PCI: Add iterators for devices and resources in bus windows Date: Tue, 1 Dec 2026 17:58:38 +0200 Message-ID: <20261201155844.2278-15-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261201155844.2278-1-ilpo.jarvinen@linux.intel.com> References: <20261201155844.2278-1-ilpo.jarvinen@linux.intel.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A transparent (subtractive decode) bridge also forwards addresses that fall outside of its own windows, so the resources of the devices behind it may reside directly in the windows of the bus the bridge is on. Code that looks for the resources within the windows of a bus has to walk the devices behind transparent bridges too. Add pci_bus_for_each_window_dev() that walks the devices on a bus and on the buses below its transparent bridges, and pci_bus_for_each_window_resource() that walks the resources of those devices that reside directly in a given window of the bus. Signed-off-by: Ilpo Järvinen --- drivers/pci/bus.c | 33 +++++++++++++++++++++++++++++++++ drivers/pci/pci.h | 22 ++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c index 655ed53436d3..f70b4cfc07bf 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -490,6 +490,39 @@ void pci_walk_bus_locked(struct pci_bus *top, int (*cb)(struct pci_dev *, void * __pci_walk_bus(top, cb, userdata); } +/* Return the device after @dev for pci_bus_for_each_window_dev() */ +struct pci_dev *pci_bus_next_window_dev(struct pci_bus *bus, + struct pci_dev *dev) +{ + struct pci_dev *child; + struct pci_bus *b; + + if (!dev) + return list_first_entry_or_null(&bus->devices, struct pci_dev, + bus_list); + + if (dev->transparent && dev->subordinate) { + child = list_first_entry_or_null(&dev->subordinate->devices, + struct pci_dev, bus_list); + if (child) + return child; + } + + /* + * Ascend back from transparent buses, but no higher than the original + * bus. + */ + b = dev->bus; + while (list_is_last(&dev->bus_list, &b->devices)) { + if (b == bus) + return NULL; + dev = b->self; + b = dev->bus; + } + + return list_next_entry(dev, bus_list); +} + struct pci_bus *pci_bus_get(struct pci_bus *bus) { if (bus) diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 77efa4c5c960..9d0cbe6c8991 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -6,6 +6,7 @@ #include #include #include +#include #include struct pcie_tlp_log; @@ -546,6 +547,27 @@ bool pci_bus_clip_resource(struct pci_dev *dev, int idx); void pci_walk_bus_locked(struct pci_bus *top, int (*cb)(struct pci_dev *, void *), void *userdata); +struct pci_dev *pci_bus_next_window_dev(struct pci_bus *bus, + struct pci_dev *dev); + +/* + * Iterate over the devices whose resources may reside directly in the + * windows of @bus: the devices on @bus and, recursively, the devices + * below its transparent bridges. A transparent bridge also forwards + * accesses outside of its own windows. + */ +#define pci_bus_for_each_window_dev(bus, dev) \ + for (dev = pci_bus_next_window_dev(bus, NULL); dev; \ + dev = pci_bus_next_window_dev(bus, dev)) + +/* + * Iterate over the resources of the devices of + * pci_bus_for_each_window_dev() that reside directly in window @win. + */ +#define pci_bus_for_each_window_resource(bus, win, dev, res) \ + pci_bus_for_each_window_dev(bus, dev) \ + pci_dev_for_each_resource(dev, res) \ + for_each_if((res)->parent == (win)) const char *pci_resource_name(struct pci_dev *dev, unsigned int i); bool pci_resource_is_optional(const struct pci_dev *dev, int resno); -- 2.47.3