aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/pci-sysfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/pci/pci-sysfs.c')
-rw-r--r--drivers/pci/pci-sysfs.c118
1 files changed, 69 insertions, 49 deletions
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index d8eb880bd1fc..2aaa83c85a4e 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -42,7 +42,8 @@ field##_show(struct device *dev, struct device_attribute *attr, char *buf) \
42 \ 42 \
43 pdev = to_pci_dev (dev); \ 43 pdev = to_pci_dev (dev); \
44 return sprintf (buf, format_string, pdev->field); \ 44 return sprintf (buf, format_string, pdev->field); \
45} 45} \
46static DEVICE_ATTR_RO(field)
46 47
47pci_config_attr(vendor, "0x%04x\n"); 48pci_config_attr(vendor, "0x%04x\n");
48pci_config_attr(device, "0x%04x\n"); 49pci_config_attr(device, "0x%04x\n");
@@ -73,10 +74,13 @@ static ssize_t broken_parity_status_store(struct device *dev,
73 74
74 return count; 75 return count;
75} 76}
77static DEVICE_ATTR_RW(broken_parity_status);
76 78
77static ssize_t local_cpus_show(struct device *dev, 79static ssize_t pci_dev_show_local_cpu(struct device *dev,
78 struct device_attribute *attr, char *buf) 80 int type,
79{ 81 struct device_attribute *attr,
82 char *buf)
83{
80 const struct cpumask *mask; 84 const struct cpumask *mask;
81 int len; 85 int len;
82 86
@@ -86,30 +90,28 @@ static ssize_t local_cpus_show(struct device *dev,
86#else 90#else
87 mask = cpumask_of_pcibus(to_pci_dev(dev)->bus); 91 mask = cpumask_of_pcibus(to_pci_dev(dev)->bus);
88#endif 92#endif
89 len = cpumask_scnprintf(buf, PAGE_SIZE-2, mask); 93 len = type ?
94 cpumask_scnprintf(buf, PAGE_SIZE-2, mask) :
95 cpulist_scnprintf(buf, PAGE_SIZE-2, mask);
96
90 buf[len++] = '\n'; 97 buf[len++] = '\n';
91 buf[len] = '\0'; 98 buf[len] = '\0';
92 return len; 99 return len;
93} 100}
94 101
102static ssize_t local_cpus_show(struct device *dev,
103 struct device_attribute *attr, char *buf)
104{
105 return pci_dev_show_local_cpu(dev, 1, attr, buf);
106}
107static DEVICE_ATTR_RO(local_cpus);
95 108
96static ssize_t local_cpulist_show(struct device *dev, 109static ssize_t local_cpulist_show(struct device *dev,
97 struct device_attribute *attr, char *buf) 110 struct device_attribute *attr, char *buf)
98{ 111{
99 const struct cpumask *mask; 112 return pci_dev_show_local_cpu(dev, 0, attr, buf);
100 int len;
101
102#ifdef CONFIG_NUMA
103 mask = (dev_to_node(dev) == -1) ? cpu_online_mask :
104 cpumask_of_node(dev_to_node(dev));
105#else
106 mask = cpumask_of_pcibus(to_pci_dev(dev)->bus);
107#endif
108 len = cpulist_scnprintf(buf, PAGE_SIZE-2, mask);
109 buf[len++] = '\n';
110 buf[len] = '\0';
111 return len;
112} 113}
114static DEVICE_ATTR_RO(local_cpulist);
113 115
114/* 116/*
115 * PCI Bus Class Devices 117 * PCI Bus Class Devices
@@ -170,6 +172,7 @@ resource_show(struct device * dev, struct device_attribute *attr, char * buf)
170 } 172 }
171 return (str - buf); 173 return (str - buf);
172} 174}
175static DEVICE_ATTR_RO(resource);
173 176
174static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf) 177static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf)
175{ 178{
@@ -181,10 +184,11 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
181 (u8)(pci_dev->class >> 16), (u8)(pci_dev->class >> 8), 184 (u8)(pci_dev->class >> 16), (u8)(pci_dev->class >> 8),
182 (u8)(pci_dev->class)); 185 (u8)(pci_dev->class));
183} 186}
187static DEVICE_ATTR_RO(modalias);
184 188
185static ssize_t is_enabled_store(struct device *dev, 189static ssize_t enabled_store(struct device *dev,
186 struct device_attribute *attr, const char *buf, 190 struct device_attribute *attr, const char *buf,
187 size_t count) 191 size_t count)
188{ 192{
189 struct pci_dev *pdev = to_pci_dev(dev); 193 struct pci_dev *pdev = to_pci_dev(dev);
190 unsigned long val; 194 unsigned long val;
@@ -208,14 +212,15 @@ static ssize_t is_enabled_store(struct device *dev,
208 return result < 0 ? result : count; 212 return result < 0 ? result : count;
209} 213}
210 214
211static ssize_t is_enabled_show(struct device *dev, 215static ssize_t enabled_show(struct device *dev,
212 struct device_attribute *attr, char *buf) 216 struct device_attribute *attr, char *buf)
213{ 217{
214 struct pci_dev *pdev; 218 struct pci_dev *pdev;
215 219
216 pdev = to_pci_dev (dev); 220 pdev = to_pci_dev (dev);
217 return sprintf (buf, "%u\n", atomic_read(&pdev->enable_cnt)); 221 return sprintf (buf, "%u\n", atomic_read(&pdev->enable_cnt));
218} 222}
223static DEVICE_ATTR_RW(enabled);
219 224
220#ifdef CONFIG_NUMA 225#ifdef CONFIG_NUMA
221static ssize_t 226static ssize_t
@@ -223,6 +228,7 @@ numa_node_show(struct device *dev, struct device_attribute *attr, char *buf)
223{ 228{
224 return sprintf (buf, "%d\n", dev->numa_node); 229 return sprintf (buf, "%d\n", dev->numa_node);
225} 230}
231static DEVICE_ATTR_RO(numa_node);
226#endif 232#endif
227 233
228static ssize_t 234static ssize_t
@@ -232,6 +238,7 @@ dma_mask_bits_show(struct device *dev, struct device_attribute *attr, char *buf)
232 238
233 return sprintf (buf, "%d\n", fls64(pdev->dma_mask)); 239 return sprintf (buf, "%d\n", fls64(pdev->dma_mask));
234} 240}
241static DEVICE_ATTR_RO(dma_mask_bits);
235 242
236static ssize_t 243static ssize_t
237consistent_dma_mask_bits_show(struct device *dev, struct device_attribute *attr, 244consistent_dma_mask_bits_show(struct device *dev, struct device_attribute *attr,
@@ -239,6 +246,7 @@ consistent_dma_mask_bits_show(struct device *dev, struct device_attribute *attr,
239{ 246{
240 return sprintf (buf, "%d\n", fls64(dev->coherent_dma_mask)); 247 return sprintf (buf, "%d\n", fls64(dev->coherent_dma_mask));
241} 248}
249static DEVICE_ATTR_RO(consistent_dma_mask_bits);
242 250
243static ssize_t 251static ssize_t
244msi_bus_show(struct device *dev, struct device_attribute *attr, char *buf) 252msi_bus_show(struct device *dev, struct device_attribute *attr, char *buf)
@@ -283,6 +291,7 @@ msi_bus_store(struct device *dev, struct device_attribute *attr,
283 291
284 return count; 292 return count;
285} 293}
294static DEVICE_ATTR_RW(msi_bus);
286 295
287static DEFINE_MUTEX(pci_remove_rescan_mutex); 296static DEFINE_MUTEX(pci_remove_rescan_mutex);
288static ssize_t bus_rescan_store(struct bus_type *bus, const char *buf, 297static ssize_t bus_rescan_store(struct bus_type *bus, const char *buf,
@@ -304,7 +313,7 @@ static ssize_t bus_rescan_store(struct bus_type *bus, const char *buf,
304} 313}
305static BUS_ATTR(rescan, (S_IWUSR|S_IWGRP), NULL, bus_rescan_store); 314static BUS_ATTR(rescan, (S_IWUSR|S_IWGRP), NULL, bus_rescan_store);
306 315
307struct attribute *pci_bus_attrs[] = { 316static struct attribute *pci_bus_attrs[] = {
308 &bus_attr_rescan.attr, 317 &bus_attr_rescan.attr,
309 NULL, 318 NULL,
310}; 319};
@@ -335,8 +344,9 @@ dev_rescan_store(struct device *dev, struct device_attribute *attr,
335 } 344 }
336 return count; 345 return count;
337} 346}
338struct device_attribute dev_rescan_attr = __ATTR(rescan, (S_IWUSR|S_IWGRP), 347static struct device_attribute dev_rescan_attr = __ATTR(rescan,
339 NULL, dev_rescan_store); 348 (S_IWUSR|S_IWGRP),
349 NULL, dev_rescan_store);
340 350
341static void remove_callback(struct device *dev) 351static void remove_callback(struct device *dev)
342{ 352{
@@ -366,8 +376,9 @@ remove_store(struct device *dev, struct device_attribute *dummy,
366 count = ret; 376 count = ret;
367 return count; 377 return count;
368} 378}
369struct device_attribute dev_remove_attr = __ATTR(remove, (S_IWUSR|S_IWGRP), 379static struct device_attribute dev_remove_attr = __ATTR(remove,
370 NULL, remove_store); 380 (S_IWUSR|S_IWGRP),
381 NULL, remove_store);
371 382
372static ssize_t 383static ssize_t
373dev_bus_rescan_store(struct device *dev, struct device_attribute *attr, 384dev_bus_rescan_store(struct device *dev, struct device_attribute *attr,
@@ -414,6 +425,7 @@ static ssize_t d3cold_allowed_show(struct device *dev,
414 struct pci_dev *pdev = to_pci_dev(dev); 425 struct pci_dev *pdev = to_pci_dev(dev);
415 return sprintf (buf, "%u\n", pdev->d3cold_allowed); 426 return sprintf (buf, "%u\n", pdev->d3cold_allowed);
416} 427}
428static DEVICE_ATTR_RW(d3cold_allowed);
417#endif 429#endif
418 430
419#ifdef CONFIG_PCI_IOV 431#ifdef CONFIG_PCI_IOV
@@ -499,30 +511,38 @@ static struct device_attribute sriov_numvfs_attr =
499 sriov_numvfs_show, sriov_numvfs_store); 511 sriov_numvfs_show, sriov_numvfs_store);
500#endif /* CONFIG_PCI_IOV */ 512#endif /* CONFIG_PCI_IOV */
501 513
502struct device_attribute pci_dev_attrs[] = { 514static struct attribute *pci_dev_attrs[] = {
503 __ATTR_RO(resource), 515 &dev_attr_resource.attr,
504 __ATTR_RO(vendor), 516 &dev_attr_vendor.attr,
505 __ATTR_RO(device), 517 &dev_attr_device.attr,
506 __ATTR_RO(subsystem_vendor), 518 &dev_attr_subsystem_vendor.attr,
507 __ATTR_RO(subsystem_device), 519 &dev_attr_subsystem_device.attr,
508 __ATTR_RO(class), 520 &dev_attr_class.attr,
509 __ATTR_RO(irq), 521 &dev_attr_irq.attr,
510 __ATTR_RO(local_cpus), 522 &dev_attr_local_cpus.attr,
511 __ATTR_RO(local_cpulist), 523 &dev_attr_local_cpulist.attr,
512 __ATTR_RO(modalias), 524 &dev_attr_modalias.attr,
513#ifdef CONFIG_NUMA 525#ifdef CONFIG_NUMA
514 __ATTR_RO(numa_node), 526 &dev_attr_numa_node.attr,
515#endif 527#endif
516 __ATTR_RO(dma_mask_bits), 528 &dev_attr_dma_mask_bits.attr,
517 __ATTR_RO(consistent_dma_mask_bits), 529 &dev_attr_consistent_dma_mask_bits.attr,
518 __ATTR(enable, 0600, is_enabled_show, is_enabled_store), 530 &dev_attr_enabled.attr,
519 __ATTR(broken_parity_status,(S_IRUGO|S_IWUSR), 531 &dev_attr_broken_parity_status.attr,
520 broken_parity_status_show,broken_parity_status_store), 532 &dev_attr_msi_bus.attr,
521 __ATTR(msi_bus, 0644, msi_bus_show, msi_bus_store),
522#if defined(CONFIG_PM_RUNTIME) && defined(CONFIG_ACPI) 533#if defined(CONFIG_PM_RUNTIME) && defined(CONFIG_ACPI)
523 __ATTR(d3cold_allowed, 0644, d3cold_allowed_show, d3cold_allowed_store), 534 &dev_attr_d3cold_allowed.attr,
524#endif 535#endif
525 __ATTR_NULL, 536 NULL,
537};
538
539static const struct attribute_group pci_dev_group = {
540 .attrs = pci_dev_attrs,
541};
542
543const struct attribute_group *pci_dev_groups[] = {
544 &pci_dev_group,
545 NULL,
526}; 546};
527 547
528static struct attribute *pcibus_attrs[] = { 548static struct attribute *pcibus_attrs[] = {
@@ -554,7 +574,7 @@ boot_vga_show(struct device *dev, struct device_attribute *attr, char *buf)
554 !!(pdev->resource[PCI_ROM_RESOURCE].flags & 574 !!(pdev->resource[PCI_ROM_RESOURCE].flags &
555 IORESOURCE_ROM_SHADOW)); 575 IORESOURCE_ROM_SHADOW));
556} 576}
557struct device_attribute vga_attr = __ATTR_RO(boot_vga); 577static struct device_attribute vga_attr = __ATTR_RO(boot_vga);
558 578
559static ssize_t 579static ssize_t
560pci_read_config(struct file *filp, struct kobject *kobj, 580pci_read_config(struct file *filp, struct kobject *kobj,