From: "Krzysztof Wilczyński" <kwilczynski@kernel.org>
To: Bjorn Helgaas <bhelgaas@google.com>
Cc: Bjorn Helgaas <helgaas@kernel.org>,
Manivannan Sadhasivam <mani@kernel.org>,
Lorenzo Pieralisi <lpieralisi@kernel.org>,
linux-pci@vger.kernel.org
Subject: [PATCH 3/3] PCI/sysfs: Add legacy I/O and memory attribute macros
Date: Tue, 21 Jul 2026 02:04:26 +0000 [thread overview]
Message-ID: <20260721020427.1541197-4-kwilczynski@kernel.org> (raw)
In-Reply-To: <20260721020427.1541197-1-kwilczynski@kernel.org>
Currently, the static binary attributes for the PCI legacy I/O port
and ISA memory space files (legacy_io, legacy_io_sparse, legacy_mem and
legacy_mem_sparse) are open-coded, with each definition repeating the
same set of properties and callbacks.
Thus, add two macros for declaring such attributes:
- pci_legacy_resource_io_attr(), for legacy I/O port space (read/write)
- pci_legacy_resource_mem_attr(), for legacy memory space (mmap)
Each macro takes the fixed attribute size as a parameter.
Then, replace the open-coded definitions with the newly added macros.
No functional changes intended.
Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org>
---
drivers/pci/pci-sysfs.c | 59 +++++++++++++++++------------------------
1 file changed, 25 insertions(+), 34 deletions(-)
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index cb7a121e5988..26a10984a843 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -871,6 +871,27 @@ static const struct attribute_group pci_dev_config_attr_group = {
};
#ifdef HAVE_PCI_LEGACY
+
+#define pci_legacy_resource_io_attr(_suffix, _size) \
+static const struct bin_attribute pci_legacy_io##_suffix##_attr = { \
+ .attr = { .name = "legacy_io" __stringify(_suffix), .mode = 0600 }, \
+ .size = (_size), \
+ .read = pci_read_legacy_io, \
+ .write = pci_write_legacy_io, \
+ .f_mapping = iomem_get_mapping, \
+ .llseek = pci_llseek_resource_legacy, \
+ .mmap = pci_mmap_legacy_io, \
+}
+
+#define pci_legacy_resource_mem_attr(_suffix, _size) \
+static const struct bin_attribute pci_legacy_mem##_suffix##_attr = { \
+ .attr = { .name = "legacy_mem" __stringify(_suffix), .mode = 0600 }, \
+ .size = (_size), \
+ .f_mapping = iomem_get_mapping, \
+ .llseek = pci_llseek_resource_legacy, \
+ .mmap = pci_mmap_legacy_mem, \
+}
+
/**
* pci_read_legacy_io - read byte(s) from legacy I/O port space
* @filp: open sysfs file
@@ -1014,41 +1035,11 @@ static loff_t pci_llseek_resource_legacy(struct file *filep,
return fixed_size_llseek(filep, offset, whence, attr->size);
}
-static const struct bin_attribute pci_legacy_io_attr = {
- .attr = { .name = "legacy_io", .mode = 0600 },
- .size = PCI_LEGACY_IO_SIZE,
- .read = pci_read_legacy_io,
- .write = pci_write_legacy_io,
- .mmap = pci_mmap_legacy_io,
- .llseek = pci_llseek_resource_legacy,
- .f_mapping = iomem_get_mapping,
-};
+pci_legacy_resource_io_attr(, PCI_LEGACY_IO_SIZE);
+pci_legacy_resource_io_attr(_sparse, PCI_LEGACY_IO_SIZE << 5);
-static const struct bin_attribute pci_legacy_io_sparse_attr = {
- .attr = { .name = "legacy_io_sparse", .mode = 0600 },
- .size = PCI_LEGACY_IO_SIZE << 5,
- .read = pci_read_legacy_io,
- .write = pci_write_legacy_io,
- .mmap = pci_mmap_legacy_io,
- .llseek = pci_llseek_resource_legacy,
- .f_mapping = iomem_get_mapping,
-};
-
-static const struct bin_attribute pci_legacy_mem_attr = {
- .attr = { .name = "legacy_mem", .mode = 0600 },
- .size = PCI_LEGACY_MEM_SIZE,
- .mmap = pci_mmap_legacy_mem,
- .llseek = pci_llseek_resource_legacy,
- .f_mapping = iomem_get_mapping,
-};
-
-static const struct bin_attribute pci_legacy_mem_sparse_attr = {
- .attr = { .name = "legacy_mem_sparse", .mode = 0600 },
- .size = PCI_LEGACY_MEM_SIZE << 5,
- .mmap = pci_mmap_legacy_mem,
- .llseek = pci_llseek_resource_legacy,
- .f_mapping = iomem_get_mapping,
-};
+pci_legacy_resource_mem_attr(, PCI_LEGACY_MEM_SIZE);
+pci_legacy_resource_mem_attr(_sparse, PCI_LEGACY_MEM_SIZE << 5);
static const struct bin_attribute *const pci_legacy_io_attrs[] = {
&pci_legacy_io_attr,
--
2.55.0
next prev parent reply other threads:[~2026-07-21 2:04 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-21 2:04 [PATCH 0/3] PCI/sysfs: Follow-up to the static attribute conversion Krzysztof Wilczyński
2026-07-21 2:04 ` [PATCH 1/3] PCI/sysfs: Add pci_ prefix to static PCI resource attribute names Krzysztof Wilczyński
2026-07-21 2:07 ` sashiko-bot
2026-07-21 2:04 ` [PATCH 2/3] alpha/PCI: Make the suffix the first __pci_dev_resource_attr() parameter Krzysztof Wilczyński
2026-07-21 2:07 ` sashiko-bot
2026-07-21 2:04 ` Krzysztof Wilczyński [this message]
2026-07-21 2:11 ` [PATCH 3/3] PCI/sysfs: Add legacy I/O and memory attribute macros sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260721020427.1541197-4-kwilczynski@kernel.org \
--to=kwilczynski@kernel.org \
--cc=bhelgaas@google.com \
--cc=helgaas@kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=mani@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox