From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.17 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796431395; b=VAy7LoL5sWCnPoPtihef6z+AqxCXxKOana2u8U2Btt81U7iC5TXNu4p9+20g5Z7YLZ6t 7uwWNTs/aOuvyV3CWgdru+8ZgyK8VpwYWmtX183TLA270OwJFMhYnzyUnSr/U9Y/40SwF QkSYniGRlsl5QxKXQHFlbOK7y2x6wJl4he89fOd2mZ50LM0Pdc3C8I9B8Yq1QY9JL1jsD khLZR+twxnR8ZZCXtfsesFCimVyY+6nCqaBHvWSVjcjHK9UIi6N6eDPdYLqL59FagRM0u VD5S0vUKY8qqOn0HaJ5rWk6IMGUmX3kvWPfl4a9fEVDGoOz8RZsbEstp1BcMIoWVI3A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796431395; 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=a39uC/ReZr6hEJJZy48Hawbz9+sY0ydaAjFIVH4v1KK+3nCQT8Dj2ds7wLDpOicuVAI0 i8u9ZwpmaWSFVd9OVjSXqDsjFXOiDgxHRVOzwt28/pALE3opczEo6fvdhJwmIk0jfmNob Uw0pxKiu/SbtCAgAyydKVdCRw2sE/ZsjE1Ps3GumuCy6uV+cHZQm9r0clo08B5nJpamKl dREpZ3nBK0AobYkBFBO3rndbhPdyyNNtdX29BGCac3vNno2DhUJcStMYD/sqlfcjQ/hmw sbcxxc1mppVvXkt5sFtNlzn53ar0W9KDJpyTXyhEsFBa+CPnrbc6iWYjOX5dL0Iluiw== 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=YcMkOpIq; arc=none smtp.remote-ip=198.175.65.17 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) (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 BDE02606A32F; Sat, 5 Dec 2026 00:43:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BDE02606A32F 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=YcMkOpIq DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796431395; x=1827967395; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XefjdUqHihzNcBZ6/A1xfh5gYFKKi6O91VnDncgmVO8=; b=YcMkOpIqtJOf8j/TTcB8VBVf+kewKuRDYwbVewZr5ByXVU+ItxPXfzef h4BKPrMGDBtE6coDHWoDqnhuhxKYHR4x7hfh1b0el1dGmWJa3HIuLGIQo nvC3pOjVmaa1wtYIrPiADcJVyJUnjDXiuVsFa/OrF+HrBdaqj8k2lkBLI RSMO0Ko0HT1wj0dq3mF7rkPgoGFSTJ9llqr9yeMk/pV4R5ZXFunYKanBb zSZsurCPiINszI9nAJ8zDVA7qWjM8y5jhTsuQUlVVG3DDlUnERkHjBgDX Zw/97BbDLVihLeVOhWDhhk6KCZmeIy0Wsb9RBxisc3qvFCqie1dn4D1Ed g==; X-CSE-ConnectionGUID: 1tCD1rpmQpG5gSwCjy33Kw== X-CSE-MsgGUID: gmMxAa1RSF6XVj2/Vo96fQ== X-IronPort-AV: E=McAfee;i="6800,10657,11986"; a="5432824" X-IronPort-AV: E=Sophos;i="6.29,79,1794902400"; d="scan'208";a="5432824" Received: from fmviesa013.fm.intel.com ([10.60.135.153]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 16:43:14 -0800 X-CSE-ConnectionGUID: uKr1og0fSg6QNj9T45JT9w== X-CSE-MsgGUID: XKyxO/jqSoOCMBPnsKSj+g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,79,1794902400"; d="scan'208";a="16181087" Received: from ijarvine-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.245.47]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2026 16:43:06 -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, Anthony Pighin , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH v2 14/16] PCI: Add iterators for devices and resources in bus windows Date: Sat, 5 Dec 2026 02:39:49 +0200 Message-ID: <20261205003957.3304-15-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261205003957.3304-1-ilpo.jarvinen@linux.intel.com> References: <20261205003957.3304-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