From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6D12E3264F7; Wed, 22 Apr 2026 16:14:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776874459; cv=none; b=lKL3vk1z2k7jhexHWlfQYKR5/Flr81MEYuwotSNocEPfH+KrLaWCa5PT4yzV0Puf1tSDBaEskNFJfwwDFr9ZrrD8i8+KB1LbBYoJYJFKKs03ZzWkissGoFX7BYkIfDOr93I+S3aSDJuK7Vxre9tw+kL4ohDt/O9ZkLZ5l34VABk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776874459; c=relaxed/simple; bh=O8CncpOJK/HEBS5SYT1UON/nV1bsCDfLQepqxgK+Uww=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pfDKkNfuklL//MOtEnAqqWpJd9litdh+yewvYQLyKQbbiDzfZytBwXSdAhf5G70tVpv5gPShRBKGBn/Qh+LBVcmzCry3xAwwI0qiaJoYYmY1QUUhVpWmDF3lnZGrstFhG7JHoHOIR+HoOzlu8z9673FJLiYtQpgrq1mLifk4mYQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=k9viRKS6; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="k9viRKS6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D1E09C2BCB7; Wed, 22 Apr 2026 16:14:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776874459; bh=O8CncpOJK/HEBS5SYT1UON/nV1bsCDfLQepqxgK+Uww=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k9viRKS6BQTK2BLg0soUC2j+wByHK5EaixTiZUg0Pf15vY5LH7YVo3wMhaxRPz0sa UoZt4y9z/67I7pCDd6LV6JfLgeBc4kMwMsVFOS0wDrTLdpwIDKOUyIvNKQYvmzwvN9 HVGck6uprDbL9SUB/Nv8NbQCeQFONGP4SnVrK6st/5Vakhz/miRs7VJgEjxCmi8mX1 9Y3P0jhwwWcXhJlBVxBvjQ4jr04kNNX70xO4ckgKTyARp/whyGdLh/ZoXn4Y3SmcB5 0pkOWgx/RUa1hAsA2IfXFMEKzDoIHxA0WUotSGR2Ije1bLphywGsrpvgMbZwSmtnIZ hTDVu0RxWsesw== From: =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= To: Bjorn Helgaas Cc: Bjorn Helgaas , Manivannan Sadhasivam , Lorenzo Pieralisi , Magnus Lindholm , Matt Turner , Richard Henderson , Christophe Leroy , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Dexuan Cui , =?UTF-8?q?Krzysztof=20Ha=C5=82asa?= , Lukas Wunner , "Oliver O'Halloran" , Saurabh Singh Sengar , Shuan He , Srivatsa Bhat , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , linux-pci@vger.kernel.org, linux-alpha@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v6 02/24] PCI: Add pci_resource_is_io() and pci_resource_is_mem() helpers Date: Wed, 22 Apr 2026 16:13:45 +0000 Message-ID: <20260422161407.118748-3-kwilczynski@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260422161407.118748-1-kwilczynski@kernel.org> References: <20260422161407.118748-1-kwilczynski@kernel.org> Precedence: bulk X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add helpers to check whether a PCI resource is of I/O port or memory type. These replace the open-coded pci_resource_flags() with IORESOURCE_IO and IORESOURCE_MEM pattern used across the tree. Suggested-by: Ilpo Järvinen Reviewed-by: Ilpo Järvinen Signed-off-by: Krzysztof Wilczyński --- include/linux/pci.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/linux/pci.h b/include/linux/pci.h index 1c270f1d5123..05aceb7f1f37 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -2295,6 +2295,31 @@ int pci_iobar_pfn(struct pci_dev *pdev, int bar, struct vm_area_struct *vma); CONCATENATE(__pci_dev_for_each_res, COUNT_ARGS(__VA_ARGS__)) \ (dev, res, __VA_ARGS__) +/** + * pci_resource_is_io - check if a PCI resource is of I/O port type. + * @dev: PCI device to check. + * @resno: The resource number (BAR index) to check. + * + * Returns true if the resource type is I/O port. + */ +static inline bool pci_resource_is_io(const struct pci_dev *dev, int resno) +{ + return resource_type(pci_resource_n(dev, resno)) == IORESOURCE_IO; +} + +/** + * pci_resource_is_mem - check if a PCI resource is of memory type. + * @dev: PCI device to check. + * @resno: The resource number (BAR index) to check. + * + * Returns true if the resource type is memory, including + * prefetchable memory. + */ +static inline bool pci_resource_is_mem(const struct pci_dev *dev, int resno) +{ + return resource_type(pci_resource_n(dev, resno)) == IORESOURCE_MEM; +} + /* * Similar to the helpers above, these manipulate per-pci_dev * driver-specific data. They are really just a wrapper around -- 2.54.0