summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKrzysztof Wilczyński <kwilczynski@kernel.org>2026-07-21 02:04:26 +0000
committerBjorn Helgaas <bhelgaas@google.com>2026-08-04 17:11:15 -0500
commit1b7c9855bb686f271f4e356cc01dab788957c5fb (patch)
treea71a15ccf26ba5c85d349ced8df636868e92eb59
parentee2ca844570a7aa6eba48cea29da24455a5f0288 (diff)
downloadlinux-1b7c9855bb686f271f4e356cc01dab788957c5fb.tar.gz
linux-1b7c9855bb686f271f4e356cc01dab788957c5fb.zip
PCI/sysfs: Add legacy I/O and memory attribute macros
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. 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> [bhelgaas: shorten macros to fit in 80 columns] Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Link: https://patch.msgid.link/20260721020427.1541197-4-kwilczynski@kernel.org
-rw-r--r--drivers/pci/pci-sysfs.c59
1 files changed, 25 insertions, 34 deletions
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 91f8f15beaa5..204980026f97 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
@@ -1059,41 +1080,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,