History

PCI/sysfs: Convert legacy I/O and memory attributes to static definitions

Currently, legacy_io and legacy_mem are dynamically allocated and created by pci_create_legacy_files(), with pci_adjust_legacy_attr() updating the attributes at runtime on Alpha to rename them and shift the size for sparse addressing. Convert to four static const attributes (legacy_io, legacy_io_sparse, legacy_mem, legacy_mem_sparse) with .is_bin_visible() callbacks that use pci_legacy_has_sparse() to select the appropriate variant per bus. The sizes are compile-time constants and .size is set directly on each attribute. Register the groups in pcibus_groups[] under a HAVE_PCI_LEGACY guard so the driver model handles creation and removal automatically. Stub out pci_create_legacy_files() and pci_remove_legacy_files() as the dynamic creation is no longer needed. Remove the __weak pci_adjust_legacy_attr(), Alpha's override, and its declaration from both Alpha and PowerPC asm/pci.h headers.

Krzysztof Wilczyński committed 6 months ago

Commit 4e14b961 parent 574b5474 files · +139 −132Browse files

Unified · Split

4 files
  1. arch/alpha/include/asm/pci.h +0 −2
  2. arch/alpha/kernel/pci-sysfs.c +7 −31
  3. arch/powerpc/include/asm/pci.h +0 −2
  4. drivers/pci/pci-sysfs.c +132 −97
arch/alpha/include/asm/pci.h+0−2
@@ -84,8 +84,6 @@ extern int pci_legacy_write(struct pci_bus *bus, loff_t port, u32 val, · 83 unmodified lines
84extern int pci_mmap_legacy_page_range(struct pci_bus *bus,84extern int pci_mmap_legacy_page_range(struct pci_bus *bus,
85 struct vm_area_struct *vma,85 struct vm_area_struct *vma,
86 enum pci_mmap_state mmap_state);86 enum pci_mmap_state mmap_state);
87extern void pci_adjust_legacy_attr(struct pci_bus *bus,
88 enum pci_mmap_state mmap_type);
89extern bool pci_legacy_has_sparse(struct pci_bus *bus,87extern bool pci_legacy_has_sparse(struct pci_bus *bus,
90 enum pci_mmap_state type);88 enum pci_mmap_state type);
91#define HAVE_PCI_LEGACY 189#define HAVE_PCI_LEGACY 1
arch/alpha/kernel/pci-sysfs.c+7−31
@@ -191,30 +191,6 @@ bool pci_legacy_has_sparse(struct pci_bus *bus, enum pci_mmap_state type) · 190 unmodified lines
191 return has_sparse(hose, type);191 return has_sparse(hose, type);
192}192}
193 193
194/**
195 * pci_adjust_legacy_attr - adjustment of legacy file attributes
196 * @bus: bus to create files under
197 * @mmap_type: I/O port or memory
198 *
199 * Adjust file name and size for sparse mappings.
200 */
201void pci_adjust_legacy_attr(struct pci_bus *bus, enum pci_mmap_state mmap_type)
202{
203 struct pci_controller *hose = bus->sysdata;
204
205 if (!has_sparse(hose, mmap_type))
206 return;
207
208 if (mmap_type == pci_mmap_mem) {
209 bus->legacy_mem->attr.name = "legacy_mem_sparse";
210 bus->legacy_mem->size <<= 5;
211 } else {
212 bus->legacy_io->attr.name = "legacy_io_sparse";
213 bus->legacy_io->size <<= 5;
214 }
215 return;
216}
217
218/* Legacy I/O bus read/write functions */194/* Legacy I/O bus read/write functions */
219int pci_legacy_read(struct pci_bus *bus, loff_t port, u32 *val, size_t size)195int pci_legacy_read(struct pci_bus *bus, loff_t port, u32 *val, size_t size)
220{196{
@@ -291,9 +267,9 @@ static inline enum pci_mmap_state pci_bar_mmap_type(struct pci_dev *pdev, · 70 unmodified lines
291 return pci_resource_is_mem(pdev, bar) ? pci_mmap_mem : pci_mmap_io;267 return pci_resource_is_mem(pdev, bar) ? pci_mmap_mem : pci_mmap_io;
292}268}
293 269
294static inline umode_t __pci_dev_resource_is_visible(struct kobject *kobj,270static inline umode_t __pci_resource_attr_is_visible(struct kobject *kobj,
295 const struct bin_attribute *a,271 const struct bin_attribute *a,
296 int bar)272 int bar)
297{273{
298 struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj));274 struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj));
299 275
@@ -313,7 +289,7 @@ static umode_t pci_dev_resource_is_visible(struct kobject *kobj, · 13 unmodified lines
313 if (has_sparse(hose, pci_bar_mmap_type(pdev, bar)))289 if (has_sparse(hose, pci_bar_mmap_type(pdev, bar)))
314 return 0;290 return 0;
315 291
316 return __pci_dev_resource_is_visible(kobj, a, bar);292 return __pci_resource_attr_is_visible(kobj, a, bar);
317}293}
318 294
319static umode_t pci_dev_resource_sparse_is_visible(struct kobject *kobj,295static umode_t pci_dev_resource_sparse_is_visible(struct kobject *kobj,
@@ -330,7 +306,7 @@ static umode_t pci_dev_resource_sparse_is_visible(struct kobject *kobj, · 10 unmodified lines
330 if (type == pci_mmap_mem && !sparse_mem_mmap_fits(pdev, bar))306 if (type == pci_mmap_mem && !sparse_mem_mmap_fits(pdev, bar))
331 return 0;307 return 0;
332 308
333 return __pci_dev_resource_is_visible(kobj, a, bar);309 return __pci_resource_attr_is_visible(kobj, a, bar);
334}310}
335 311
336static umode_t pci_dev_resource_dense_is_visible(struct kobject *kobj,312static umode_t pci_dev_resource_dense_is_visible(struct kobject *kobj,
@@ -346,14 +322,14 @@ static umode_t pci_dev_resource_dense_is_visible(struct kobject *kobj, · 9 unmodified lines
346 return 0;322 return 0;
347 323
348 if (type == pci_mmap_mem && !sparse_mem_mmap_fits(pdev, bar))324 if (type == pci_mmap_mem && !sparse_mem_mmap_fits(pdev, bar))
349 return __pci_dev_resource_is_visible(kobj, a, bar);325 return __pci_resource_attr_is_visible(kobj, a, bar);
350 326
351 dense_base = (type == pci_mmap_mem) ? hose->dense_mem_base :327 dense_base = (type == pci_mmap_mem) ? hose->dense_mem_base :
352 hose->dense_io_base;328 hose->dense_io_base;
353 if (!dense_base)329 if (!dense_base)
354 return 0;330 return 0;
355 331
356 return __pci_dev_resource_is_visible(kobj, a, bar);332 return __pci_resource_attr_is_visible(kobj, a, bar);
357}333}
358 334
359static inline size_t __pci_dev_resource_bin_size(struct kobject *kobj,335static inline size_t __pci_dev_resource_bin_size(struct kobject *kobj,
arch/powerpc/include/asm/pci.h+0−2
@@ -82,8 +82,6 @@ extern int pci_legacy_write(struct pci_bus *bus, loff_t port, u32 val, · 81 unmodified lines
82extern int pci_mmap_legacy_page_range(struct pci_bus *bus,82extern int pci_mmap_legacy_page_range(struct pci_bus *bus,
83 struct vm_area_struct *vma,83 struct vm_area_struct *vma,
84 enum pci_mmap_state mmap_state);84 enum pci_mmap_state mmap_state);
85extern void pci_adjust_legacy_attr(struct pci_bus *bus,
86 enum pci_mmap_state mmap_type);
87#define HAVE_PCI_LEGACY 185#define HAVE_PCI_LEGACY 1
88 86
89extern void pcibios_claim_one_bus(struct pci_bus *b);87extern void pcibios_claim_one_bus(struct pci_bus *b);
drivers/pci/pci-sysfs.c+132−97
@@ -676,11 +676,6 @@ static const struct attribute_group pcibus_group = { · 675 unmodified lines
676 .attrs = pcibus_attrs,676 .attrs = pcibus_attrs,
677};677};
678 678
679const struct attribute_group *pcibus_groups[] = {
680 &pcibus_group,
681 NULL,
682};
683
684static ssize_t boot_vga_show(struct device *dev, struct device_attribute *attr,679static ssize_t boot_vga_show(struct device *dev, struct device_attribute *attr,
685 char *buf)680 char *buf)
686{681{
@@ -879,19 +874,6 @@ static const struct attribute_group pci_dev_config_attr_group = { · 192 unmodified lines
879 .bin_size = pci_dev_config_attr_bin_size,874 .bin_size = pci_dev_config_attr_bin_size,
880};875};
881 876
882/*
883 * llseek operation for mmappable PCI resources.
884 * May be left unused if the arch doesn't provide them.
885 */
886static __maybe_unused loff_t
887pci_llseek_resource_legacy(struct file *filep,
888 struct kobject *kobj __always_unused,
889 const struct bin_attribute *attr,
890 loff_t offset, int whence)
891{
892 return fixed_size_llseek(filep, offset, whence, attr->size);
893}
894
895#ifdef HAVE_PCI_LEGACY877#ifdef HAVE_PCI_LEGACY
896/**878/**
897 * pci_read_legacy_io - read byte(s) from legacy I/O port space879 * pci_read_legacy_io - read byte(s) from legacy I/O port space
@@ -989,91 +971,144 @@ bool __weak pci_legacy_has_sparse(struct pci_bus *bus, · 91 unmodified lines
989 return false;971 return false;
990}972}
991 973
992/**974static inline umode_t __pci_legacy_is_visible(struct kobject *kobj,
993 * pci_adjust_legacy_attr - adjustment of legacy file attributes975 const struct bin_attribute *a,
994 * @b: bus to create files under976 enum pci_mmap_state type,
995 * @mmap_type: I/O port or memory977 bool sparse)
996 *978{
997 * Stub implementation. Can be overridden by arch if necessary.979 struct pci_bus *bus = to_pci_bus(kobj_to_dev(kobj));
998 */980
999void __weak pci_adjust_legacy_attr(struct pci_bus *b,981 if (pci_legacy_has_sparse(bus, type) != sparse)
1000 enum pci_mmap_state mmap_type)982 return 0;
983
984 return a->attr.mode;
985}
986
987static umode_t pci_legacy_io_is_visible(struct kobject *kobj,
988 const struct bin_attribute *a, int n)
1001{989{
990 return __pci_legacy_is_visible(kobj, a, pci_mmap_io, false);
1002}991}
1003 992
1004/**993static umode_t pci_legacy_io_sparse_is_visible(struct kobject *kobj,
1005 * pci_create_legacy_files - create legacy I/O port and memory files994 const struct bin_attribute *a,
1006 * @b: bus to create files under995 int n)
1007 *996{
1008 * Some platforms allow access to legacy I/O port and ISA memory space on997 return __pci_legacy_is_visible(kobj, a, pci_mmap_io, true);
1009 * a per-bus basis. This routine creates the files and ties them into998}
1010 * their associated read, write and mmap files from pci-sysfs.c999
1011 *1000static umode_t pci_legacy_mem_is_visible(struct kobject *kobj,
1012 * On error unwind, but don't propagate the error to the caller1001 const struct bin_attribute *a, int n)
1013 * as it is ok to set up the PCI bus without these files.1002{
1014 */1003 return __pci_legacy_is_visible(kobj, a, pci_mmap_mem, false);
1015void pci_create_legacy_files(struct pci_bus *b)1004}
1016{1005
1017 int error;1006static umode_t pci_legacy_mem_sparse_is_visible(struct kobject *kobj,
1018 1007 const struct bin_attribute *a,
1019 if (!sysfs_initialized)1008 int n)
1020 return;1009{
1021 1010 return __pci_legacy_is_visible(kobj, a, pci_mmap_mem, true);
1022 b->legacy_io = kzalloc_objs(struct bin_attribute, 2, GFP_ATOMIC);1011}
1023 if (!b->legacy_io)1012
1024 goto kzalloc_err;1013static loff_t pci_llseek_resource_legacy(struct file *filep,
1025 1014 struct kobject *kobj __always_unused,
1026 sysfs_bin_attr_init(b->legacy_io);1015 const struct bin_attribute *attr,
1027 b->legacy_io->attr.name = "legacy_io";1016 loff_t offset, int whence)
1028 b->legacy_io->size = PCI_LEGACY_IO_SIZE;1017{
1029 b->legacy_io->attr.mode = 0600;1018 return fixed_size_llseek(filep, offset, whence, attr->size);
1030 b->legacy_io->read = pci_read_legacy_io;
1031 b->legacy_io->write = pci_write_legacy_io;
1032 /* See pci_create_attr() for motivation */
1033 b->legacy_io->llseek = pci_llseek_resource_legacy;
1034 b->legacy_io->mmap = pci_mmap_legacy_io;
1035 b->legacy_io->f_mapping = iomem_get_mapping;
1036 pci_adjust_legacy_attr(b, pci_mmap_io);
1037 error = device_create_bin_file(&b->dev, b->legacy_io);
1038 if (error)
1039 goto legacy_io_err;
1040
1041 /* Allocated above after the legacy_io struct */
1042 b->legacy_mem = b->legacy_io + 1;
1043 sysfs_bin_attr_init(b->legacy_mem);
1044 b->legacy_mem->attr.name = "legacy_mem";
1045 b->legacy_mem->size = PCI_LEGACY_MEM_SIZE;
1046 b->legacy_mem->attr.mode = 0600;
1047 b->legacy_mem->mmap = pci_mmap_legacy_mem;
1048 /* See pci_create_attr() for motivation */
1049 b->legacy_mem->llseek = pci_llseek_resource_legacy;
1050 b->legacy_mem->f_mapping = iomem_get_mapping;
1051 pci_adjust_legacy_attr(b, pci_mmap_mem);
1052 error = device_create_bin_file(&b->dev, b->legacy_mem);
1053 if (error)
1054 goto legacy_mem_err;
1055
1056 return;
1057
1058legacy_mem_err:
1059 device_remove_bin_file(&b->dev, b->legacy_io);
1060legacy_io_err:
1061 kfree(b->legacy_io);
1062 b->legacy_io = NULL;
1063kzalloc_err:
1064 dev_warn(&b->dev, "could not create legacy I/O port and ISA memory resources in sysfs\n");
1065}
1066
1067void pci_remove_legacy_files(struct pci_bus *b)
1068{
1069 if (b->legacy_io) {
1070 device_remove_bin_file(&b->dev, b->legacy_io);
1071 device_remove_bin_file(&b->dev, b->legacy_mem);
1072 kfree(b->legacy_io); /* both are allocated here */
1073 }
1074}1019}
1020
1021static const struct bin_attribute pci_legacy_io_attr = {
1022 .attr = { .name = "legacy_io", .mode = 0600 },
1023 .size = PCI_LEGACY_IO_SIZE,
1024 .read = pci_read_legacy_io,
1025 .write = pci_write_legacy_io,
1026 .mmap = pci_mmap_legacy_io,
1027 .llseek = pci_llseek_resource_legacy,
1028 .f_mapping = iomem_get_mapping,
1029};
1030
1031static const struct bin_attribute pci_legacy_io_sparse_attr = {
1032 .attr = { .name = "legacy_io_sparse", .mode = 0600 },
1033 .size = PCI_LEGACY_IO_SIZE << 5,
1034 .read = pci_read_legacy_io,
1035 .write = pci_write_legacy_io,
1036 .mmap = pci_mmap_legacy_io,
1037 .llseek = pci_llseek_resource_legacy,
1038 .f_mapping = iomem_get_mapping,
1039};
1040
1041static const struct bin_attribute pci_legacy_mem_attr = {
1042 .attr = { .name = "legacy_mem", .mode = 0600 },
1043 .size = PCI_LEGACY_MEM_SIZE,
1044 .mmap = pci_mmap_legacy_mem,
1045 .llseek = pci_llseek_resource_legacy,
1046 .f_mapping = iomem_get_mapping,
1047};
1048
1049static const struct bin_attribute pci_legacy_mem_sparse_attr = {
1050 .attr = { .name = "legacy_mem_sparse", .mode = 0600 },
1051 .size = PCI_LEGACY_MEM_SIZE << 5,
1052 .mmap = pci_mmap_legacy_mem,
1053 .llseek = pci_llseek_resource_legacy,
1054 .f_mapping = iomem_get_mapping,
1055};
1056
1057static const struct bin_attribute *const pci_legacy_io_attrs[] = {
1058 &pci_legacy_io_attr,
1059 NULL,
1060};
1061
1062static const struct bin_attribute *const pci_legacy_io_sparse_attrs[] = {
1063 &pci_legacy_io_sparse_attr,
1064 NULL,
1065};
1066
1067static const struct bin_attribute *const pci_legacy_mem_attrs[] = {
1068 &pci_legacy_mem_attr,
1069 NULL,
1070};
1071
1072static const struct bin_attribute *const pci_legacy_mem_sparse_attrs[] = {
1073 &pci_legacy_mem_sparse_attr,
1074 NULL,
1075};
1076
1077static const struct attribute_group pci_legacy_io_group = {
1078 .bin_attrs = pci_legacy_io_attrs,
1079 .is_bin_visible = pci_legacy_io_is_visible,
1080};
1081
1082static const struct attribute_group pci_legacy_io_sparse_group = {
1083 .bin_attrs = pci_legacy_io_sparse_attrs,
1084 .is_bin_visible = pci_legacy_io_sparse_is_visible,
1085};
1086
1087static const struct attribute_group pci_legacy_mem_group = {
1088 .bin_attrs = pci_legacy_mem_attrs,
1089 .is_bin_visible = pci_legacy_mem_is_visible,
1090};
1091
1092static const struct attribute_group pci_legacy_mem_sparse_group = {
1093 .bin_attrs = pci_legacy_mem_sparse_attrs,
1094 .is_bin_visible = pci_legacy_mem_sparse_is_visible,
1095};
1096
1097void pci_create_legacy_files(struct pci_bus *b) { }
1098void pci_remove_legacy_files(struct pci_bus *b) { }
1075#endif /* HAVE_PCI_LEGACY */1099#endif /* HAVE_PCI_LEGACY */
1076 1100
1101const struct attribute_group *pcibus_groups[] = {
1102 &pcibus_group,
1103#ifdef HAVE_PCI_LEGACY
1104 &pci_legacy_io_group,
1105 &pci_legacy_io_sparse_group,
1106 &pci_legacy_mem_group,
1107 &pci_legacy_mem_sparse_group,
1108#endif
1109 NULL,
1110};
1111
1077#if defined(HAVE_PCI_MMAP) || defined(ARCH_GENERIC_PCI_MMAP_RESOURCE)1112#if defined(HAVE_PCI_MMAP) || defined(ARCH_GENERIC_PCI_MMAP_RESOURCE)
1078/**1113/**
1079 * pci_mmap_resource - map a PCI resource into user memory space1114 * pci_mmap_resource - map a PCI resource into user memory space

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t