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 36190CD3436 for ; Fri, 8 May 2026 04:36:42 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4gBbsm75l1z3bcJ; Fri, 08 May 2026 14:36:12 +1000 (AEST) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip=172.234.252.31 ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1778214972; cv=none; b=Oi/9p4k64NbjLWAkbGZ6vdKwK2OQyJcpnizYx2e4g1W6ULzeirH2UFpz5wyiwwyLJyXQ3ei1Ez9d82ex73BLT4pVae/iQ2cm5Iw4pdSBmFPmDP1UqZPvIVPd9mYQKjEv0+/csObJonbvY44uZBHTSV+R89+12v2jmcaeAscFGXDrBJzINw8rRo+rDnh7/nQL1h11s0jOXjQnAbcvpSYXKw+nn0BCu1fQRnFR8uLZxXmUSZIGFFVfa9fjYfumWYa7deitgerihZREuE7AWk+FOhztVKtH07gIEElqXgIjUIX2smhg1HFNI8R1812LYZQZ3TQ+YIvQxAGHCgBeGm0CRA== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1778214972; c=relaxed/relaxed; bh=nKozyMkwC27TarPwoti9Xx8R53AL4hDcrybXf6KF3bY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Kwl/Dcr0Iuw/8X8R4lkBGKcj7JG4+gprOUUxsp+MTAVdkAkLuDxoXtidwINApSQyE6VEZNNx2Hz9rcmD5jMkhu0s0InAB3V4FHWhvzQMH3aCa4nNsBko8e8wWKvPT7NYgqXRzut5cT9/t0WocJKkqNQlPodXD48B3gTovpzFEZqmShdQuhnepIGW5u9KMVrx9dq2duQucOLkZY44gYoyEs9NB/SZVtOZrv24noeosJzV/WWGYUBL1CuiWAfxY9ERgnrus5CvEgBnXAGCPIKM2+5s3Ms3PMAGbvOZSCc6j2HzGSON+Yr2rpKcPfx/u6cI/HRG6kpNhLypyc32z5w0FA== 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=hlTEmQ8G; dkim-atps=neutral; spf=pass (client-ip=172.234.252.31; 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=hlTEmQ8G; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=kernel.org (client-ip=172.234.252.31; helo=sea.source.kernel.org; envelope-from=kwilczynski@kernel.org; receiver=lists.ozlabs.org) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) (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 4gBbsm1pQ4z2xPb for ; Fri, 08 May 2026 14:36:12 +1000 (AEST) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id BA08840DA9; Fri, 8 May 2026 04:36:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 57D30C2BCC9; Fri, 8 May 2026 04:36:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778214970; bh=rv4+pB9OQC2evCt3bYQzktbO90qE0aBLoieVjqeP9lI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hlTEmQ8GefB2+8g5thUTRJ9h9IKt5hXNpfWMbDUA3/iHIttjfhkiPJcevzzS6RvA4 abtg5ZF2NE5Rgdv+e9yj4axGZ5gf2HcPq21ZDQWc1v8r9gjkU2CnK93H9Nnw8ugvdc 99McCThFOu0xFuI0KR4Qz81CcjXT2Gfa200gXE0KBkN6s5F2arIu8j8M7KAYdA3oEK i2l4gdO4RgQysirVMR4DgLdfm6HDUonS1pMvcPhLnvdENfoYh7Uj3VkREmyV0HZIh9 Vta4pAKIUdLSqnD8YRlJcHBLjb4YGBF31Arzc55jH+Lb+FTADebmBfdpj2gasgHppQ VIe4HuJY1aIjg== From: =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= To: Bjorn Helgaas Cc: Bjorn Helgaas , Manivannan Sadhasivam , Lorenzo Pieralisi , Alex Williamson , 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 v7 06/24] PCI/sysfs: Add static PCI resource attribute macros Date: Fri, 8 May 2026 04:35:25 +0000 Message-ID: <20260508043543.217179-7-kwilczynski@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260508043543.217179-1-kwilczynski@kernel.org> References: <20260508043543.217179-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). Tested-by: Shivaprasad G Bhat 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 dac780597727..d50b8fe1498c 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -1197,6 +1197,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