From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 86D36FA1FCF for ; Wed, 22 Apr 2026 16:15:07 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4g14740v0Dz2yv0; Thu, 23 Apr 2026 02:14:40 +1000 (AEST) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2600:3c0a:e001:78e:0:1991:8:25" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1776874480; cv=none; b=mLNfLDhhKdEwc3uS/yck93DMjfu7nM3jztTocATewmRLAZhMLx5tsRqpI81AdUZCb0Fy0NEAmjl+q5d9CsUSA8+pGeB3qnk+xLSBFYsvhZRY+wjk88ZQzgLGHMfYsUOrcFQ87XWnBVbnImx+aENJjULN7hHhBsyLIZ1MqUgKkX+smWPVRUPNj135OwgXStPGUSjqEGbdwY3iMul+973yiKl290rr6YUBWdSznvhOQRKvVfC0ilgvgR0/juAHGTKlSJPmIK3c8i0mosH2rw/dzALV4UEYSH7K0OaP0EkNMgWVjfX8FrRqYOjM2gVug3+fgdREKr1sUwGm9Xjsmufdeg== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1776874480; c=relaxed/relaxed; bh=Hhotk2SGTPw2eilBkQc5BHfT+QTTKTrH0NaAKmN20sU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QcTosASK2Pzg+oXZSdJJYLRHSFw9U6mSABD1EHtIafqddtSaZeo1CTHBYPxPLLoUvXdUsa8DpXqVbshu+Vk6ZLi2xqW+fEA51egZKtZrH3qAykVbk/V7v3YgXhXaQOq4hpzATJDZ1NkrRuAnEk8NEe8ZJevhFtHU3LyeLUt26JVpsCP5VDDGWZ3CN8DCHvhYB+kB8zM570OUWEFQ/1MgkwaIl989m9KaUonXWrJZkMDttUACVeGgEnAD6EzCQ92mDkM17/ioqTbjuSbGhB3iTabgVau+8XgDIZZ62ij7vAr9B+1wPaSPvQhOEINgn76A8z9uFsPbITdUx+g0AyBrjA== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=ilg+Oq10; dkim-atps=neutral; spf=pass (client-ip=2600:3c0a:e001:78e:0:1991:8:25; helo=sea.source.kernel.org; envelope-from=kwilczynski@kernel.org; receiver=lists.ozlabs.org) smtp.mailfrom=kernel.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=ilg+Oq10; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=kernel.org (client-ip=2600:3c0a:e001:78e:0:1991:8:25; helo=sea.source.kernel.org; envelope-from=kwilczynski@kernel.org; receiver=lists.ozlabs.org) Received: from sea.source.kernel.org (sea.source.kernel.org [IPv6:2600:3c0a:e001:78e:0:1991:8:25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4g146y5SWdz30FF for ; Thu, 23 Apr 2026 02:14:34 +1000 (AEST) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 0DCA1441A3; Wed, 22 Apr 2026 16:14:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BCC2AC19425; Wed, 22 Apr 2026 16:14:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776874472; bh=LOtkYUCu1LOwcksdYu3xBT0nhQ+XZL/mP+1JgYEHv+c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ilg+Oq10qfX0iuzxkWPLITMpd91E2sFl4i/MpoeeI9kFNQCzLzdwrBWxQihLica9T PuH7/Pf88IjEaeRVwPNGzvTVZjq8deYQ7GO3UMIAAPJm9vD0sc/FrM8MKTdbVfWWg3 jvOQ7U+G+kAEyDfvClP3+Hsb3JdpIZ6AiWXG+1Ssr2jX1JBlQJVfkj1JhqjLpngFSH nHs3keCHwDTTFpvf+p8Dy3Nwpz7sRyFZ7GiKP3S23b8rj9ncJNwSnzla+3sCb//h3H ez4CsoxxUiDcfW36t4JAAI90vfCND5+m9Hwemv9sMyVI/HTm1XUKqJoy0iYJ5VqhHe bgHAULoQ44AVQ== 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 06/24] PCI/sysfs: Add static PCI resource attribute macros Date: Wed, 22 Apr 2026 16:13:49 +0000 Message-ID: <20260422161407.118748-7-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> X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , List-Unsubscribe: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add three macros for declaring static binary attributes for PCI resource files: - pci_dev_resource_io_attr(), for I/O BAR resources (read/write) - pci_dev_resource_uc_attr(), for memory BAR resources (mmap uncached) - pci_dev_resource_wc_attr(), for write-combine resources (mmap WC) Each macro only sets the callbacks its resource type needs. The I/O macro conditionally includes mmap support via __PCI_RESOURCE_IO_MMAP_ATTRS on architectures where arch_can_pci_mmap_io() is true at compile time (such as PowerPC, SPARC, and Xtensa). Signed-off-by: Krzysztof WilczyƄski --- drivers/pci/pci-sysfs.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 4f95b336cc34..e7ca83aec3e8 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -1220,6 +1220,47 @@ static ssize_t pci_write_resource_io(struct file *filp, struct kobject *kobj, return pci_resource_io(filp, kobj, attr, buf, off, count, true); } +/* + * generic_file_llseek() consults f_mapping->host to determine + * the file size. As iomem_inode knows nothing about the + * attribute, it's not going to work, so override it as well. + */ +#if arch_can_pci_mmap_io() +# define __PCI_RESOURCE_IO_MMAP_ATTRS \ + .f_mapping = iomem_get_mapping, \ + .llseek = pci_llseek_resource, \ + .mmap = pci_mmap_resource_uc, +#else +# define __PCI_RESOURCE_IO_MMAP_ATTRS +#endif + +#define pci_dev_resource_io_attr(_bar) \ +static const struct bin_attribute dev_resource##_bar##_io_attr = { \ + .attr = { .name = "resource" __stringify(_bar), .mode = 0600 }, \ + .private = (void *)(unsigned long)(_bar), \ + .read = pci_read_resource_io, \ + .write = pci_write_resource_io, \ + __PCI_RESOURCE_IO_MMAP_ATTRS \ +} + +#define pci_dev_resource_uc_attr(_bar) \ +static const struct bin_attribute dev_resource##_bar##_uc_attr = { \ + .attr = { .name = "resource" __stringify(_bar), .mode = 0600 }, \ + .private = (void *)(unsigned long)(_bar), \ + .f_mapping = iomem_get_mapping, \ + .llseek = pci_llseek_resource, \ + .mmap = pci_mmap_resource_uc, \ +} + +#define pci_dev_resource_wc_attr(_bar) \ +static const struct bin_attribute dev_resource##_bar##_wc_attr = { \ + .attr = { .name = "resource" __stringify(_bar) "_wc", .mode = 0600 }, \ + .private = (void *)(unsigned long)(_bar), \ + .f_mapping = iomem_get_mapping, \ + .llseek = pci_llseek_resource, \ + .mmap = pci_mmap_resource_wc, \ +} + /** * pci_remove_resource_files - cleanup resource files * @pdev: dev to cleanup -- 2.54.0