| @@ -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 | |
| 679 | const struct attribute_group *pcibus_groups[] = { | | |
| 680 | &pcibus_group, | | |
| 681 | NULL, | | |
| 682 | }; | | |
| 683 | | | |
| 684 | static ssize_t boot_vga_show(struct device *dev, struct device_attribute *attr, | 679 | static 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 | */ | | |
| 886 | static __maybe_unused loff_t | | |
| 887 | pci_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_LEGACY | 877 | #ifdef HAVE_PCI_LEGACY |
| 896 | /** | 878 | /** |
| 897 | * pci_read_legacy_io - read byte(s) from legacy I/O port space | 879 | * 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 | /** | 974 | static inline umode_t __pci_legacy_is_visible(struct kobject *kobj, |
| 993 | * pci_adjust_legacy_attr - adjustment of legacy file attributes | 975 | const struct bin_attribute *a, |
| 994 | * @b: bus to create files under | 976 | enum pci_mmap_state type, |
| 995 | * @mmap_type: I/O port or memory | 977 | 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 | |
| 999 | void __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 | |
| | 987 | static 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 | /** | 993 | static umode_t pci_legacy_io_sparse_is_visible(struct kobject *kobj, |
| 1005 | * pci_create_legacy_files - create legacy I/O port and memory files | 994 | const struct bin_attribute *a, |
| 1006 | * @b: bus to create files under | 995 | int n) |
| 1007 | * | 996 | { |
| 1008 | * Some platforms allow access to legacy I/O port and ISA memory space on | 997 | return __pci_legacy_is_visible(kobj, a, pci_mmap_io, true); |
| 1009 | * a per-bus basis. This routine creates the files and ties them into | 998 | } |
| 1010 | * their associated read, write and mmap files from pci-sysfs.c | 999 | |
| 1011 | * | 1000 | static umode_t pci_legacy_mem_is_visible(struct kobject *kobj, |
| 1012 | * On error unwind, but don't propagate the error to the caller | 1001 | 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); |
| 1015 | void pci_create_legacy_files(struct pci_bus *b) | 1004 | } |
| 1016 | { | 1005 | |
| 1017 | int error; | 1006 | static 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; | 1013 | static 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 | | | |
| 1058 | legacy_mem_err: | | |
| 1059 | device_remove_bin_file(&b->dev, b->legacy_io); | | |
| 1060 | legacy_io_err: | | |
| 1061 | kfree(b->legacy_io); | | |
| 1062 | b->legacy_io = NULL; | | |
| 1063 | kzalloc_err: | | |
| 1064 | dev_warn(&b->dev, "could not create legacy I/O port and ISA memory resources in sysfs\n"); | | |
| 1065 | } | | |
| 1066 | | | |
| 1067 | void 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 | |
| | 1021 | static 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 | |
| | 1031 | static 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 | |
| | 1041 | static 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 | |
| | 1049 | static 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 | |
| | 1057 | static const struct bin_attribute *const pci_legacy_io_attrs[] = { |
| | 1058 | &pci_legacy_io_attr, |
| | 1059 | NULL, |
| | 1060 | }; |
| | 1061 | |
| | 1062 | static const struct bin_attribute *const pci_legacy_io_sparse_attrs[] = { |
| | 1063 | &pci_legacy_io_sparse_attr, |
| | 1064 | NULL, |
| | 1065 | }; |
| | 1066 | |
| | 1067 | static const struct bin_attribute *const pci_legacy_mem_attrs[] = { |
| | 1068 | &pci_legacy_mem_attr, |
| | 1069 | NULL, |
| | 1070 | }; |
| | 1071 | |
| | 1072 | static const struct bin_attribute *const pci_legacy_mem_sparse_attrs[] = { |
| | 1073 | &pci_legacy_mem_sparse_attr, |
| | 1074 | NULL, |
| | 1075 | }; |
| | 1076 | |
| | 1077 | static 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 | |
| | 1082 | static 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 | |
| | 1087 | static 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 | |
| | 1092 | static 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 | |
| | 1097 | void pci_create_legacy_files(struct pci_bus *b) { } |
| | 1098 | void pci_remove_legacy_files(struct pci_bus *b) { } |
| 1075 | #endif /* HAVE_PCI_LEGACY */ | 1099 | #endif /* HAVE_PCI_LEGACY */ |
| 1076 | | 1100 | |
| | 1101 | const 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 space | 1114 | * pci_mmap_resource - map a PCI resource into user memory space |