1 // SPDX-License-Identifier: GPL-2.0
3 * drivers/pci/pci-sysfs.c
5 * (C) Copyright 2002-2004 Greg Kroah-Hartman <greg@kroah.com>
6 * (C) Copyright 2002-2004 IBM Corp.
7 * (C) Copyright 2003 Matthew Wilcox
8 * (C) Copyright 2003 Hewlett-Packard
9 * (C) Copyright 2004 Jon Smirl <jonsmirl@yahoo.com>
10 * (C) Copyright 2004 Silicon Graphics, Inc. Jesse Barnes <jbarnes@sgi.com>
12 * File attributes for PCI devices
14 * Modeled after usb's driverfs.c
19 #include <linux/kernel.h>
20 #include <linux/sched.h>
21 #include <linux/pci.h>
22 #include <linux/stat.h>
23 #include <linux/export.h>
24 #include <linux/topology.h>
27 #include <linux/capability.h>
28 #include <linux/security.h>
29 #include <linux/pci-aspm.h>
30 #include <linux/slab.h>
31 #include <linux/vgaarb.h>
32 #include <linux/pm_runtime.h>
36 static int sysfs_initialized; /* = 0 */
38 /* show configuration fields */
39 #define pci_config_attr(field, format_string) \
41 field##_show(struct device *dev, struct device_attribute *attr, char *buf) \
43 struct pci_dev *pdev; \
45 pdev = to_pci_dev(dev); \
46 return sprintf(buf, format_string, pdev->field); \
48 static DEVICE_ATTR_RO(field)
50 pci_config_attr(vendor, "0x%04x\n");
51 pci_config_attr(device, "0x%04x\n");
52 pci_config_attr(subsystem_vendor, "0x%04x\n");
53 pci_config_attr(subsystem_device, "0x%04x\n");
54 pci_config_attr(revision, "0x%02x\n");
55 pci_config_attr(class, "0x%06x\n");
56 pci_config_attr(irq, "%u\n");
58 static ssize_t broken_parity_status_show(struct device *dev,
59 struct device_attribute *attr,
62 struct pci_dev *pdev = to_pci_dev(dev);
63 return sprintf(buf, "%u\n", pdev->broken_parity_status);
66 static ssize_t broken_parity_status_store(struct device *dev,
67 struct device_attribute *attr,
68 const char *buf, size_t count)
70 struct pci_dev *pdev = to_pci_dev(dev);
73 if (kstrtoul(buf, 0, &val) < 0)
76 pdev->broken_parity_status = !!val;
80 static DEVICE_ATTR_RW(broken_parity_status);
82 static ssize_t pci_dev_show_local_cpu(struct device *dev, bool list,
83 struct device_attribute *attr, char *buf)
85 const struct cpumask *mask;
88 mask = (dev_to_node(dev) == -1) ? cpu_online_mask :
89 cpumask_of_node(dev_to_node(dev));
91 mask = cpumask_of_pcibus(to_pci_dev(dev)->bus);
93 return cpumap_print_to_pagebuf(list, buf, mask);
96 static ssize_t local_cpus_show(struct device *dev,
97 struct device_attribute *attr, char *buf)
99 return pci_dev_show_local_cpu(dev, false, attr, buf);
101 static DEVICE_ATTR_RO(local_cpus);
103 static ssize_t local_cpulist_show(struct device *dev,
104 struct device_attribute *attr, char *buf)
106 return pci_dev_show_local_cpu(dev, true, attr, buf);
108 static DEVICE_ATTR_RO(local_cpulist);
111 * PCI Bus Class Devices
113 static ssize_t cpuaffinity_show(struct device *dev,
114 struct device_attribute *attr, char *buf)
116 const struct cpumask *cpumask = cpumask_of_pcibus(to_pci_bus(dev));
118 return cpumap_print_to_pagebuf(false, buf, cpumask);
120 static DEVICE_ATTR_RO(cpuaffinity);
122 static ssize_t cpulistaffinity_show(struct device *dev,
123 struct device_attribute *attr, char *buf)
125 const struct cpumask *cpumask = cpumask_of_pcibus(to_pci_bus(dev));
127 return cpumap_print_to_pagebuf(true, buf, cpumask);
129 static DEVICE_ATTR_RO(cpulistaffinity);
132 static ssize_t resource_show(struct device *dev, struct device_attribute *attr,
135 struct pci_dev *pci_dev = to_pci_dev(dev);
139 resource_size_t start, end;
141 if (pci_dev->subordinate)
142 max = DEVICE_COUNT_RESOURCE;
144 max = PCI_BRIDGE_RESOURCES;
146 for (i = 0; i < max; i++) {
147 struct resource *res = &pci_dev->resource[i];
148 pci_resource_to_user(pci_dev, i, res, &start, &end);
149 str += sprintf(str, "0x%016llx 0x%016llx 0x%016llx\n",
150 (unsigned long long)start,
151 (unsigned long long)end,
152 (unsigned long long)res->flags);
156 static DEVICE_ATTR_RO(resource);
158 static ssize_t max_link_speed_show(struct device *dev,
159 struct device_attribute *attr, char *buf)
161 struct pci_dev *pci_dev = to_pci_dev(dev);
166 err = pcie_capability_read_dword(pci_dev, PCI_EXP_LNKCAP, &linkcap);
170 switch (linkcap & PCI_EXP_LNKCAP_SLS) {
171 case PCI_EXP_LNKCAP_SLS_8_0GB:
174 case PCI_EXP_LNKCAP_SLS_5_0GB:
177 case PCI_EXP_LNKCAP_SLS_2_5GB:
181 speed = "Unknown speed";
184 return sprintf(buf, "%s\n", speed);
186 static DEVICE_ATTR_RO(max_link_speed);
188 static ssize_t max_link_width_show(struct device *dev,
189 struct device_attribute *attr, char *buf)
191 struct pci_dev *pci_dev = to_pci_dev(dev);
195 err = pcie_capability_read_dword(pci_dev, PCI_EXP_LNKCAP, &linkcap);
199 return sprintf(buf, "%u\n", (linkcap & PCI_EXP_LNKCAP_MLW) >> 4);
201 static DEVICE_ATTR_RO(max_link_width);
203 static ssize_t current_link_speed_show(struct device *dev,
204 struct device_attribute *attr, char *buf)
206 struct pci_dev *pci_dev = to_pci_dev(dev);
211 err = pcie_capability_read_word(pci_dev, PCI_EXP_LNKSTA, &linkstat);
215 switch (linkstat & PCI_EXP_LNKSTA_CLS) {
216 case PCI_EXP_LNKSTA_CLS_8_0GB:
219 case PCI_EXP_LNKSTA_CLS_5_0GB:
222 case PCI_EXP_LNKSTA_CLS_2_5GB:
226 speed = "Unknown speed";
229 return sprintf(buf, "%s\n", speed);
231 static DEVICE_ATTR_RO(current_link_speed);
233 static ssize_t current_link_width_show(struct device *dev,
234 struct device_attribute *attr, char *buf)
236 struct pci_dev *pci_dev = to_pci_dev(dev);
240 err = pcie_capability_read_word(pci_dev, PCI_EXP_LNKSTA, &linkstat);
244 return sprintf(buf, "%u\n",
245 (linkstat & PCI_EXP_LNKSTA_NLW) >> PCI_EXP_LNKSTA_NLW_SHIFT);
247 static DEVICE_ATTR_RO(current_link_width);
249 static ssize_t secondary_bus_number_show(struct device *dev,
250 struct device_attribute *attr,
253 struct pci_dev *pci_dev = to_pci_dev(dev);
257 err = pci_read_config_byte(pci_dev, PCI_SECONDARY_BUS, &sec_bus);
261 return sprintf(buf, "%u\n", sec_bus);
263 static DEVICE_ATTR_RO(secondary_bus_number);
265 static ssize_t subordinate_bus_number_show(struct device *dev,
266 struct device_attribute *attr,
269 struct pci_dev *pci_dev = to_pci_dev(dev);
273 err = pci_read_config_byte(pci_dev, PCI_SUBORDINATE_BUS, &sub_bus);
277 return sprintf(buf, "%u\n", sub_bus);
279 static DEVICE_ATTR_RO(subordinate_bus_number);
281 static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
284 struct pci_dev *pci_dev = to_pci_dev(dev);
286 return sprintf(buf, "pci:v%08Xd%08Xsv%08Xsd%08Xbc%02Xsc%02Xi%02X\n",
287 pci_dev->vendor, pci_dev->device,
288 pci_dev->subsystem_vendor, pci_dev->subsystem_device,
289 (u8)(pci_dev->class >> 16), (u8)(pci_dev->class >> 8),
290 (u8)(pci_dev->class));
292 static DEVICE_ATTR_RO(modalias);
294 static ssize_t enable_store(struct device *dev, struct device_attribute *attr,
295 const char *buf, size_t count)
297 struct pci_dev *pdev = to_pci_dev(dev);
299 ssize_t result = kstrtoul(buf, 0, &val);
304 /* this can crash the machine when done on the "wrong" device */
305 if (!capable(CAP_SYS_ADMIN))
312 result = pci_enable_device(pdev);
313 else if (pci_is_enabled(pdev))
314 pci_disable_device(pdev);
319 return result < 0 ? result : count;
322 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
325 struct pci_dev *pdev;
327 pdev = to_pci_dev(dev);
328 return sprintf(buf, "%u\n", atomic_read(&pdev->enable_cnt));
330 static DEVICE_ATTR_RW(enable);
333 static ssize_t numa_node_store(struct device *dev,
334 struct device_attribute *attr, const char *buf,
337 struct pci_dev *pdev = to_pci_dev(dev);
340 if (!capable(CAP_SYS_ADMIN))
343 ret = kstrtoint(buf, 0, &node);
347 if ((node < 0 && node != NUMA_NO_NODE) || node >= MAX_NUMNODES)
350 if (node != NUMA_NO_NODE && !node_online(node))
353 add_taint(TAINT_FIRMWARE_WORKAROUND, LOCKDEP_STILL_OK);
354 dev_alert(&pdev->dev, FW_BUG "Overriding NUMA node to %d. Contact your vendor for updates.",
357 dev->numa_node = node;
361 static ssize_t numa_node_show(struct device *dev, struct device_attribute *attr,
364 return sprintf(buf, "%d\n", dev->numa_node);
366 static DEVICE_ATTR_RW(numa_node);
369 static ssize_t dma_mask_bits_show(struct device *dev,
370 struct device_attribute *attr, char *buf)
372 struct pci_dev *pdev = to_pci_dev(dev);
374 return sprintf(buf, "%d\n", fls64(pdev->dma_mask));
376 static DEVICE_ATTR_RO(dma_mask_bits);
378 static ssize_t consistent_dma_mask_bits_show(struct device *dev,
379 struct device_attribute *attr,
382 return sprintf(buf, "%d\n", fls64(dev->coherent_dma_mask));
384 static DEVICE_ATTR_RO(consistent_dma_mask_bits);
386 static ssize_t msi_bus_show(struct device *dev, struct device_attribute *attr,
389 struct pci_dev *pdev = to_pci_dev(dev);
390 struct pci_bus *subordinate = pdev->subordinate;
392 return sprintf(buf, "%u\n", subordinate ?
393 !(subordinate->bus_flags & PCI_BUS_FLAGS_NO_MSI)
397 static ssize_t msi_bus_store(struct device *dev, struct device_attribute *attr,
398 const char *buf, size_t count)
400 struct pci_dev *pdev = to_pci_dev(dev);
401 struct pci_bus *subordinate = pdev->subordinate;
404 if (kstrtoul(buf, 0, &val) < 0)
407 if (!capable(CAP_SYS_ADMIN))
411 * "no_msi" and "bus_flags" only affect what happens when a driver
412 * requests MSI or MSI-X. They don't affect any drivers that have
413 * already requested MSI or MSI-X.
417 dev_info(&pdev->dev, "MSI/MSI-X %s for future drivers\n",
418 val ? "allowed" : "disallowed");
423 subordinate->bus_flags &= ~PCI_BUS_FLAGS_NO_MSI;
425 subordinate->bus_flags |= PCI_BUS_FLAGS_NO_MSI;
427 dev_info(&subordinate->dev, "MSI/MSI-X %s for future drivers of devices on this bus\n",
428 val ? "allowed" : "disallowed");
431 static DEVICE_ATTR_RW(msi_bus);
433 static ssize_t bus_rescan_store(struct bus_type *bus, const char *buf,
437 struct pci_bus *b = NULL;
439 if (kstrtoul(buf, 0, &val) < 0)
443 pci_lock_rescan_remove();
444 while ((b = pci_find_next_bus(b)) != NULL)
446 pci_unlock_rescan_remove();
450 static BUS_ATTR(rescan, (S_IWUSR|S_IWGRP), NULL, bus_rescan_store);
452 static struct attribute *pci_bus_attrs[] = {
453 &bus_attr_rescan.attr,
457 static const struct attribute_group pci_bus_group = {
458 .attrs = pci_bus_attrs,
461 const struct attribute_group *pci_bus_groups[] = {
466 static ssize_t dev_rescan_store(struct device *dev,
467 struct device_attribute *attr, const char *buf,
471 struct pci_dev *pdev = to_pci_dev(dev);
473 if (kstrtoul(buf, 0, &val) < 0)
477 pci_lock_rescan_remove();
478 pci_rescan_bus(pdev->bus);
479 pci_unlock_rescan_remove();
483 static struct device_attribute dev_rescan_attr = __ATTR(rescan,
485 NULL, dev_rescan_store);
487 static ssize_t remove_store(struct device *dev, struct device_attribute *attr,
488 const char *buf, size_t count)
492 if (kstrtoul(buf, 0, &val) < 0)
495 if (val && device_remove_file_self(dev, attr))
496 pci_stop_and_remove_bus_device_locked(to_pci_dev(dev));
499 static struct device_attribute dev_remove_attr = __ATTR_IGNORE_LOCKDEP(remove,
503 static ssize_t dev_bus_rescan_store(struct device *dev,
504 struct device_attribute *attr,
505 const char *buf, size_t count)
508 struct pci_bus *bus = to_pci_bus(dev);
510 if (kstrtoul(buf, 0, &val) < 0)
514 pci_lock_rescan_remove();
515 if (!pci_is_root_bus(bus) && list_empty(&bus->devices))
516 pci_rescan_bus_bridge_resize(bus->self);
519 pci_unlock_rescan_remove();
523 static DEVICE_ATTR(rescan, (S_IWUSR|S_IWGRP), NULL, dev_bus_rescan_store);
525 #if defined(CONFIG_PM) && defined(CONFIG_ACPI)
526 static ssize_t d3cold_allowed_store(struct device *dev,
527 struct device_attribute *attr,
528 const char *buf, size_t count)
530 struct pci_dev *pdev = to_pci_dev(dev);
533 if (kstrtoul(buf, 0, &val) < 0)
536 pdev->d3cold_allowed = !!val;
537 if (pdev->d3cold_allowed)
538 pci_d3cold_enable(pdev);
540 pci_d3cold_disable(pdev);
542 pm_runtime_resume(dev);
547 static ssize_t d3cold_allowed_show(struct device *dev,
548 struct device_attribute *attr, char *buf)
550 struct pci_dev *pdev = to_pci_dev(dev);
551 return sprintf(buf, "%u\n", pdev->d3cold_allowed);
553 static DEVICE_ATTR_RW(d3cold_allowed);
557 static ssize_t devspec_show(struct device *dev,
558 struct device_attribute *attr, char *buf)
560 struct pci_dev *pdev = to_pci_dev(dev);
561 struct device_node *np = pci_device_to_OF_node(pdev);
565 return sprintf(buf, "%pOF", np);
567 static DEVICE_ATTR_RO(devspec);
570 #ifdef CONFIG_PCI_IOV
571 static ssize_t sriov_totalvfs_show(struct device *dev,
572 struct device_attribute *attr,
575 struct pci_dev *pdev = to_pci_dev(dev);
577 return sprintf(buf, "%u\n", pci_sriov_get_totalvfs(pdev));
581 static ssize_t sriov_numvfs_show(struct device *dev,
582 struct device_attribute *attr,
585 struct pci_dev *pdev = to_pci_dev(dev);
587 return sprintf(buf, "%u\n", pdev->sriov->num_VFs);
591 * num_vfs > 0; number of VFs to enable
592 * num_vfs = 0; disable all VFs
594 * Note: SRIOV spec doesn't allow partial VF
595 * disable, so it's all or none.
597 static ssize_t sriov_numvfs_store(struct device *dev,
598 struct device_attribute *attr,
599 const char *buf, size_t count)
601 struct pci_dev *pdev = to_pci_dev(dev);
605 ret = kstrtou16(buf, 0, &num_vfs);
609 if (num_vfs > pci_sriov_get_totalvfs(pdev))
612 device_lock(&pdev->dev);
614 if (num_vfs == pdev->sriov->num_VFs)
617 /* is PF driver loaded w/callback */
618 if (!pdev->driver || !pdev->driver->sriov_configure) {
619 dev_info(&pdev->dev, "Driver doesn't support SRIOV configuration via sysfs\n");
626 ret = pdev->driver->sriov_configure(pdev, 0);
631 if (pdev->sriov->num_VFs) {
632 dev_warn(&pdev->dev, "%d VFs already enabled. Disable before enabling %d VFs\n",
633 pdev->sriov->num_VFs, num_vfs);
638 ret = pdev->driver->sriov_configure(pdev, num_vfs);
643 dev_warn(&pdev->dev, "%d VFs requested; only %d enabled\n",
647 device_unlock(&pdev->dev);
655 static ssize_t sriov_drivers_autoprobe_show(struct device *dev,
656 struct device_attribute *attr,
659 struct pci_dev *pdev = to_pci_dev(dev);
661 return sprintf(buf, "%u\n", pdev->sriov->drivers_autoprobe);
664 static ssize_t sriov_drivers_autoprobe_store(struct device *dev,
665 struct device_attribute *attr,
666 const char *buf, size_t count)
668 struct pci_dev *pdev = to_pci_dev(dev);
669 bool drivers_autoprobe;
671 if (kstrtobool(buf, &drivers_autoprobe) < 0)
674 pdev->sriov->drivers_autoprobe = drivers_autoprobe;
679 static struct device_attribute sriov_totalvfs_attr = __ATTR_RO(sriov_totalvfs);
680 static struct device_attribute sriov_numvfs_attr =
681 __ATTR(sriov_numvfs, (S_IRUGO|S_IWUSR|S_IWGRP),
682 sriov_numvfs_show, sriov_numvfs_store);
683 static struct device_attribute sriov_drivers_autoprobe_attr =
684 __ATTR(sriov_drivers_autoprobe, (S_IRUGO|S_IWUSR|S_IWGRP),
685 sriov_drivers_autoprobe_show, sriov_drivers_autoprobe_store);
686 #endif /* CONFIG_PCI_IOV */
688 static ssize_t driver_override_store(struct device *dev,
689 struct device_attribute *attr,
690 const char *buf, size_t count)
692 struct pci_dev *pdev = to_pci_dev(dev);
693 char *driver_override, *old, *cp;
695 /* We need to keep extra room for a newline */
696 if (count >= (PAGE_SIZE - 1))
699 driver_override = kstrndup(buf, count, GFP_KERNEL);
700 if (!driver_override)
703 cp = strchr(driver_override, '\n');
708 old = pdev->driver_override;
709 if (strlen(driver_override)) {
710 pdev->driver_override = driver_override;
712 kfree(driver_override);
713 pdev->driver_override = NULL;
722 static ssize_t driver_override_show(struct device *dev,
723 struct device_attribute *attr, char *buf)
725 struct pci_dev *pdev = to_pci_dev(dev);
729 len = snprintf(buf, PAGE_SIZE, "%s\n", pdev->driver_override);
733 static DEVICE_ATTR_RW(driver_override);
735 static struct attribute *pci_dev_attrs[] = {
736 &dev_attr_resource.attr,
737 &dev_attr_vendor.attr,
738 &dev_attr_device.attr,
739 &dev_attr_subsystem_vendor.attr,
740 &dev_attr_subsystem_device.attr,
741 &dev_attr_revision.attr,
742 &dev_attr_class.attr,
744 &dev_attr_local_cpus.attr,
745 &dev_attr_local_cpulist.attr,
746 &dev_attr_modalias.attr,
748 &dev_attr_numa_node.attr,
750 &dev_attr_dma_mask_bits.attr,
751 &dev_attr_consistent_dma_mask_bits.attr,
752 &dev_attr_enable.attr,
753 &dev_attr_broken_parity_status.attr,
754 &dev_attr_msi_bus.attr,
755 #if defined(CONFIG_PM) && defined(CONFIG_ACPI)
756 &dev_attr_d3cold_allowed.attr,
759 &dev_attr_devspec.attr,
761 &dev_attr_driver_override.attr,
765 static struct attribute *pci_bridge_attrs[] = {
766 &dev_attr_subordinate_bus_number.attr,
767 &dev_attr_secondary_bus_number.attr,
771 static struct attribute *pcie_dev_attrs[] = {
772 &dev_attr_current_link_speed.attr,
773 &dev_attr_current_link_width.attr,
774 &dev_attr_max_link_width.attr,
775 &dev_attr_max_link_speed.attr,
779 static struct attribute *pcibus_attrs[] = {
780 &dev_attr_rescan.attr,
781 &dev_attr_cpuaffinity.attr,
782 &dev_attr_cpulistaffinity.attr,
786 static const struct attribute_group pcibus_group = {
787 .attrs = pcibus_attrs,
790 const struct attribute_group *pcibus_groups[] = {
795 static ssize_t boot_vga_show(struct device *dev, struct device_attribute *attr,
798 struct pci_dev *pdev = to_pci_dev(dev);
799 struct pci_dev *vga_dev = vga_default_device();
802 return sprintf(buf, "%u\n", (pdev == vga_dev));
804 return sprintf(buf, "%u\n",
805 !!(pdev->resource[PCI_ROM_RESOURCE].flags &
806 IORESOURCE_ROM_SHADOW));
808 static struct device_attribute vga_attr = __ATTR_RO(boot_vga);
810 static ssize_t pci_read_config(struct file *filp, struct kobject *kobj,
811 struct bin_attribute *bin_attr, char *buf,
812 loff_t off, size_t count)
814 struct pci_dev *dev = to_pci_dev(kobj_to_dev(kobj));
815 unsigned int size = 64;
816 loff_t init_off = off;
817 u8 *data = (u8 *) buf;
819 /* Several chips lock up trying to read undefined config space */
820 if (file_ns_capable(filp, &init_user_ns, CAP_SYS_ADMIN))
821 size = dev->cfg_size;
822 else if (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
827 if (off + count > size) {
834 pci_config_pm_runtime_get(dev);
836 if ((off & 1) && size) {
838 pci_user_read_config_byte(dev, off, &val);
839 data[off - init_off] = val;
844 if ((off & 3) && size > 2) {
846 pci_user_read_config_word(dev, off, &val);
847 data[off - init_off] = val & 0xff;
848 data[off - init_off + 1] = (val >> 8) & 0xff;
855 pci_user_read_config_dword(dev, off, &val);
856 data[off - init_off] = val & 0xff;
857 data[off - init_off + 1] = (val >> 8) & 0xff;
858 data[off - init_off + 2] = (val >> 16) & 0xff;
859 data[off - init_off + 3] = (val >> 24) & 0xff;
866 pci_user_read_config_word(dev, off, &val);
867 data[off - init_off] = val & 0xff;
868 data[off - init_off + 1] = (val >> 8) & 0xff;
875 pci_user_read_config_byte(dev, off, &val);
876 data[off - init_off] = val;
881 pci_config_pm_runtime_put(dev);
886 static ssize_t pci_write_config(struct file *filp, struct kobject *kobj,
887 struct bin_attribute *bin_attr, char *buf,
888 loff_t off, size_t count)
890 struct pci_dev *dev = to_pci_dev(kobj_to_dev(kobj));
891 unsigned int size = count;
892 loff_t init_off = off;
893 u8 *data = (u8 *) buf;
895 if (off > dev->cfg_size)
897 if (off + count > dev->cfg_size) {
898 size = dev->cfg_size - off;
902 pci_config_pm_runtime_get(dev);
904 if ((off & 1) && size) {
905 pci_user_write_config_byte(dev, off, data[off - init_off]);
910 if ((off & 3) && size > 2) {
911 u16 val = data[off - init_off];
912 val |= (u16) data[off - init_off + 1] << 8;
913 pci_user_write_config_word(dev, off, val);
919 u32 val = data[off - init_off];
920 val |= (u32) data[off - init_off + 1] << 8;
921 val |= (u32) data[off - init_off + 2] << 16;
922 val |= (u32) data[off - init_off + 3] << 24;
923 pci_user_write_config_dword(dev, off, val);
929 u16 val = data[off - init_off];
930 val |= (u16) data[off - init_off + 1] << 8;
931 pci_user_write_config_word(dev, off, val);
937 pci_user_write_config_byte(dev, off, data[off - init_off]);
942 pci_config_pm_runtime_put(dev);
947 static ssize_t read_vpd_attr(struct file *filp, struct kobject *kobj,
948 struct bin_attribute *bin_attr, char *buf,
949 loff_t off, size_t count)
951 struct pci_dev *dev = to_pci_dev(kobj_to_dev(kobj));
953 if (bin_attr->size > 0) {
954 if (off > bin_attr->size)
956 else if (count > bin_attr->size - off)
957 count = bin_attr->size - off;
960 return pci_read_vpd(dev, off, count, buf);
963 static ssize_t write_vpd_attr(struct file *filp, struct kobject *kobj,
964 struct bin_attribute *bin_attr, char *buf,
965 loff_t off, size_t count)
967 struct pci_dev *dev = to_pci_dev(kobj_to_dev(kobj));
969 if (bin_attr->size > 0) {
970 if (off > bin_attr->size)
972 else if (count > bin_attr->size - off)
973 count = bin_attr->size - off;
976 return pci_write_vpd(dev, off, count, buf);
979 #ifdef HAVE_PCI_LEGACY
981 * pci_read_legacy_io - read byte(s) from legacy I/O port space
982 * @filp: open sysfs file
983 * @kobj: kobject corresponding to file to read from
984 * @bin_attr: struct bin_attribute for this file
985 * @buf: buffer to store results
986 * @off: offset into legacy I/O port space
987 * @count: number of bytes to read
989 * Reads 1, 2, or 4 bytes from legacy I/O port space using an arch specific
990 * callback routine (pci_legacy_read).
992 static ssize_t pci_read_legacy_io(struct file *filp, struct kobject *kobj,
993 struct bin_attribute *bin_attr, char *buf,
994 loff_t off, size_t count)
996 struct pci_bus *bus = to_pci_bus(kobj_to_dev(kobj));
998 /* Only support 1, 2 or 4 byte accesses */
999 if (count != 1 && count != 2 && count != 4)
1002 return pci_legacy_read(bus, off, (u32 *)buf, count);
1006 * pci_write_legacy_io - write byte(s) to legacy I/O port space
1007 * @filp: open sysfs file
1008 * @kobj: kobject corresponding to file to read from
1009 * @bin_attr: struct bin_attribute for this file
1010 * @buf: buffer containing value to be written
1011 * @off: offset into legacy I/O port space
1012 * @count: number of bytes to write
1014 * Writes 1, 2, or 4 bytes from legacy I/O port space using an arch specific
1015 * callback routine (pci_legacy_write).
1017 static ssize_t pci_write_legacy_io(struct file *filp, struct kobject *kobj,
1018 struct bin_attribute *bin_attr, char *buf,
1019 loff_t off, size_t count)
1021 struct pci_bus *bus = to_pci_bus(kobj_to_dev(kobj));
1023 /* Only support 1, 2 or 4 byte accesses */
1024 if (count != 1 && count != 2 && count != 4)
1027 return pci_legacy_write(bus, off, *(u32 *)buf, count);
1031 * pci_mmap_legacy_mem - map legacy PCI memory into user memory space
1032 * @filp: open sysfs file
1033 * @kobj: kobject corresponding to device to be mapped
1034 * @attr: struct bin_attribute for this file
1035 * @vma: struct vm_area_struct passed to mmap
1037 * Uses an arch specific callback, pci_mmap_legacy_mem_page_range, to mmap
1038 * legacy memory space (first meg of bus space) into application virtual
1041 static int pci_mmap_legacy_mem(struct file *filp, struct kobject *kobj,
1042 struct bin_attribute *attr,
1043 struct vm_area_struct *vma)
1045 struct pci_bus *bus = to_pci_bus(kobj_to_dev(kobj));
1047 return pci_mmap_legacy_page_range(bus, vma, pci_mmap_mem);
1051 * pci_mmap_legacy_io - map legacy PCI IO into user memory space
1052 * @filp: open sysfs file
1053 * @kobj: kobject corresponding to device to be mapped
1054 * @attr: struct bin_attribute for this file
1055 * @vma: struct vm_area_struct passed to mmap
1057 * Uses an arch specific callback, pci_mmap_legacy_io_page_range, to mmap
1058 * legacy IO space (first meg of bus space) into application virtual
1059 * memory space. Returns -ENOSYS if the operation isn't supported
1061 static int pci_mmap_legacy_io(struct file *filp, struct kobject *kobj,
1062 struct bin_attribute *attr,
1063 struct vm_area_struct *vma)
1065 struct pci_bus *bus = to_pci_bus(kobj_to_dev(kobj));
1067 return pci_mmap_legacy_page_range(bus, vma, pci_mmap_io);
1071 * pci_adjust_legacy_attr - adjustment of legacy file attributes
1072 * @b: bus to create files under
1073 * @mmap_type: I/O port or memory
1075 * Stub implementation. Can be overridden by arch if necessary.
1077 void __weak pci_adjust_legacy_attr(struct pci_bus *b,
1078 enum pci_mmap_state mmap_type)
1083 * pci_create_legacy_files - create legacy I/O port and memory files
1084 * @b: bus to create files under
1086 * Some platforms allow access to legacy I/O port and ISA memory space on
1087 * a per-bus basis. This routine creates the files and ties them into
1088 * their associated read, write and mmap files from pci-sysfs.c
1090 * On error unwind, but don't propagate the error to the caller
1091 * as it is ok to set up the PCI bus without these files.
1093 void pci_create_legacy_files(struct pci_bus *b)
1097 b->legacy_io = kzalloc(sizeof(struct bin_attribute) * 2,
1102 sysfs_bin_attr_init(b->legacy_io);
1103 b->legacy_io->attr.name = "legacy_io";
1104 b->legacy_io->size = 0xffff;
1105 b->legacy_io->attr.mode = S_IRUSR | S_IWUSR;
1106 b->legacy_io->read = pci_read_legacy_io;
1107 b->legacy_io->write = pci_write_legacy_io;
1108 b->legacy_io->mmap = pci_mmap_legacy_io;
1109 pci_adjust_legacy_attr(b, pci_mmap_io);
1110 error = device_create_bin_file(&b->dev, b->legacy_io);
1114 /* Allocated above after the legacy_io struct */
1115 b->legacy_mem = b->legacy_io + 1;
1116 sysfs_bin_attr_init(b->legacy_mem);
1117 b->legacy_mem->attr.name = "legacy_mem";
1118 b->legacy_mem->size = 1024*1024;
1119 b->legacy_mem->attr.mode = S_IRUSR | S_IWUSR;
1120 b->legacy_mem->mmap = pci_mmap_legacy_mem;
1121 pci_adjust_legacy_attr(b, pci_mmap_mem);
1122 error = device_create_bin_file(&b->dev, b->legacy_mem);
1124 goto legacy_mem_err;
1129 device_remove_bin_file(&b->dev, b->legacy_io);
1131 kfree(b->legacy_io);
1132 b->legacy_io = NULL;
1134 printk(KERN_WARNING "pci: warning: could not create legacy I/O port and ISA memory resources to sysfs\n");
1138 void pci_remove_legacy_files(struct pci_bus *b)
1141 device_remove_bin_file(&b->dev, b->legacy_io);
1142 device_remove_bin_file(&b->dev, b->legacy_mem);
1143 kfree(b->legacy_io); /* both are allocated here */
1146 #endif /* HAVE_PCI_LEGACY */
1148 #if defined(HAVE_PCI_MMAP) || defined(ARCH_GENERIC_PCI_MMAP_RESOURCE)
1150 int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vma,
1151 enum pci_mmap_api mmap_api)
1153 unsigned long nr, start, size;
1154 resource_size_t pci_start = 0, pci_end;
1156 if (pci_resource_len(pdev, resno) == 0)
1158 nr = vma_pages(vma);
1159 start = vma->vm_pgoff;
1160 size = ((pci_resource_len(pdev, resno) - 1) >> PAGE_SHIFT) + 1;
1161 if (mmap_api == PCI_MMAP_PROCFS) {
1162 pci_resource_to_user(pdev, resno, &pdev->resource[resno],
1163 &pci_start, &pci_end);
1164 pci_start >>= PAGE_SHIFT;
1166 if (start >= pci_start && start < pci_start + size &&
1167 start + nr <= pci_start + size)
1173 * pci_mmap_resource - map a PCI resource into user memory space
1174 * @kobj: kobject for mapping
1175 * @attr: struct bin_attribute for the file being mapped
1176 * @vma: struct vm_area_struct passed into the mmap
1177 * @write_combine: 1 for write_combine mapping
1179 * Use the regular PCI mapping routines to map a PCI resource into userspace.
1181 static int pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr,
1182 struct vm_area_struct *vma, int write_combine)
1184 struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj));
1185 int bar = (unsigned long)attr->private;
1186 enum pci_mmap_state mmap_type;
1187 struct resource *res = &pdev->resource[bar];
1189 if (res->flags & IORESOURCE_MEM && iomem_is_exclusive(res->start))
1192 if (!pci_mmap_fits(pdev, bar, vma, PCI_MMAP_SYSFS)) {
1193 WARN(1, "process \"%s\" tried to map 0x%08lx bytes at page 0x%08lx on %s BAR %d (start 0x%16Lx, size 0x%16Lx)\n",
1194 current->comm, vma->vm_end-vma->vm_start, vma->vm_pgoff,
1195 pci_name(pdev), bar,
1196 (u64)pci_resource_start(pdev, bar),
1197 (u64)pci_resource_len(pdev, bar));
1200 mmap_type = res->flags & IORESOURCE_MEM ? pci_mmap_mem : pci_mmap_io;
1202 return pci_mmap_resource_range(pdev, bar, vma, mmap_type, write_combine);
1205 static int pci_mmap_resource_uc(struct file *filp, struct kobject *kobj,
1206 struct bin_attribute *attr,
1207 struct vm_area_struct *vma)
1209 return pci_mmap_resource(kobj, attr, vma, 0);
1212 static int pci_mmap_resource_wc(struct file *filp, struct kobject *kobj,
1213 struct bin_attribute *attr,
1214 struct vm_area_struct *vma)
1216 return pci_mmap_resource(kobj, attr, vma, 1);
1219 static ssize_t pci_resource_io(struct file *filp, struct kobject *kobj,
1220 struct bin_attribute *attr, char *buf,
1221 loff_t off, size_t count, bool write)
1223 struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj));
1224 int bar = (unsigned long)attr->private;
1225 unsigned long port = off;
1227 port += pci_resource_start(pdev, bar);
1229 if (port > pci_resource_end(pdev, bar))
1232 if (port + count - 1 > pci_resource_end(pdev, bar))
1238 outb(*(u8 *)buf, port);
1240 *(u8 *)buf = inb(port);
1244 outw(*(u16 *)buf, port);
1246 *(u16 *)buf = inw(port);
1250 outl(*(u32 *)buf, port);
1252 *(u32 *)buf = inl(port);
1258 static ssize_t pci_read_resource_io(struct file *filp, struct kobject *kobj,
1259 struct bin_attribute *attr, char *buf,
1260 loff_t off, size_t count)
1262 return pci_resource_io(filp, kobj, attr, buf, off, count, false);
1265 static ssize_t pci_write_resource_io(struct file *filp, struct kobject *kobj,
1266 struct bin_attribute *attr, char *buf,
1267 loff_t off, size_t count)
1269 return pci_resource_io(filp, kobj, attr, buf, off, count, true);
1273 * pci_remove_resource_files - cleanup resource files
1274 * @pdev: dev to cleanup
1276 * If we created resource files for @pdev, remove them from sysfs and
1277 * free their resources.
1279 static void pci_remove_resource_files(struct pci_dev *pdev)
1283 for (i = 0; i < PCI_ROM_RESOURCE; i++) {
1284 struct bin_attribute *res_attr;
1286 res_attr = pdev->res_attr[i];
1288 sysfs_remove_bin_file(&pdev->dev.kobj, res_attr);
1292 res_attr = pdev->res_attr_wc[i];
1294 sysfs_remove_bin_file(&pdev->dev.kobj, res_attr);
1300 static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
1302 /* allocate attribute structure, piggyback attribute name */
1303 int name_len = write_combine ? 13 : 10;
1304 struct bin_attribute *res_attr;
1305 char *res_attr_name;
1308 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
1312 res_attr_name = (char *)(res_attr + 1);
1314 sysfs_bin_attr_init(res_attr);
1315 if (write_combine) {
1316 pdev->res_attr_wc[num] = res_attr;
1317 sprintf(res_attr_name, "resource%d_wc", num);
1318 res_attr->mmap = pci_mmap_resource_wc;
1320 pdev->res_attr[num] = res_attr;
1321 sprintf(res_attr_name, "resource%d", num);
1322 if (pci_resource_flags(pdev, num) & IORESOURCE_IO) {
1323 res_attr->read = pci_read_resource_io;
1324 res_attr->write = pci_write_resource_io;
1325 if (arch_can_pci_mmap_io())
1326 res_attr->mmap = pci_mmap_resource_uc;
1328 res_attr->mmap = pci_mmap_resource_uc;
1331 res_attr->attr.name = res_attr_name;
1332 res_attr->attr.mode = S_IRUSR | S_IWUSR;
1333 res_attr->size = pci_resource_len(pdev, num);
1334 res_attr->private = (void *)(unsigned long)num;
1335 retval = sysfs_create_bin_file(&pdev->dev.kobj, res_attr);
1343 * pci_create_resource_files - create resource files in sysfs for @dev
1344 * @pdev: dev in question
1346 * Walk the resources in @pdev creating files for each resource available.
1348 static int pci_create_resource_files(struct pci_dev *pdev)
1353 /* Expose the PCI resources from this device as files */
1354 for (i = 0; i < PCI_ROM_RESOURCE; i++) {
1356 /* skip empty resources */
1357 if (!pci_resource_len(pdev, i))
1360 retval = pci_create_attr(pdev, i, 0);
1361 /* for prefetchable resources, create a WC mappable file */
1362 if (!retval && arch_can_pci_mmap_wc() &&
1363 pdev->resource[i].flags & IORESOURCE_PREFETCH)
1364 retval = pci_create_attr(pdev, i, 1);
1366 pci_remove_resource_files(pdev);
1372 #else /* !HAVE_PCI_MMAP */
1373 int __weak pci_create_resource_files(struct pci_dev *dev) { return 0; }
1374 void __weak pci_remove_resource_files(struct pci_dev *dev) { return; }
1375 #endif /* HAVE_PCI_MMAP */
1378 * pci_write_rom - used to enable access to the PCI ROM display
1380 * @kobj: kernel object handle
1381 * @bin_attr: struct bin_attribute for this file
1384 * @count: number of byte in input
1386 * writing anything except 0 enables it
1388 static ssize_t pci_write_rom(struct file *filp, struct kobject *kobj,
1389 struct bin_attribute *bin_attr, char *buf,
1390 loff_t off, size_t count)
1392 struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj));
1394 if ((off == 0) && (*buf == '0') && (count == 2))
1395 pdev->rom_attr_enabled = 0;
1397 pdev->rom_attr_enabled = 1;
1403 * pci_read_rom - read a PCI ROM
1405 * @kobj: kernel object handle
1406 * @bin_attr: struct bin_attribute for this file
1407 * @buf: where to put the data we read from the ROM
1409 * @count: number of bytes to read
1411 * Put @count bytes starting at @off into @buf from the ROM in the PCI
1412 * device corresponding to @kobj.
1414 static ssize_t pci_read_rom(struct file *filp, struct kobject *kobj,
1415 struct bin_attribute *bin_attr, char *buf,
1416 loff_t off, size_t count)
1418 struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj));
1422 if (!pdev->rom_attr_enabled)
1425 rom = pci_map_rom(pdev, &size); /* size starts out as PCI window size */
1432 if (off + count > size)
1435 memcpy_fromio(buf, rom + off, count);
1437 pci_unmap_rom(pdev, rom);
1442 static const struct bin_attribute pci_config_attr = {
1445 .mode = S_IRUGO | S_IWUSR,
1447 .size = PCI_CFG_SPACE_SIZE,
1448 .read = pci_read_config,
1449 .write = pci_write_config,
1452 static const struct bin_attribute pcie_config_attr = {
1455 .mode = S_IRUGO | S_IWUSR,
1457 .size = PCI_CFG_SPACE_EXP_SIZE,
1458 .read = pci_read_config,
1459 .write = pci_write_config,
1462 static ssize_t reset_store(struct device *dev, struct device_attribute *attr,
1463 const char *buf, size_t count)
1465 struct pci_dev *pdev = to_pci_dev(dev);
1467 ssize_t result = kstrtoul(buf, 0, &val);
1475 result = pci_reset_function(pdev);
1482 static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_store);
1484 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
1487 struct bin_attribute *attr;
1489 /* If the device has VPD, try to expose it in sysfs. */
1491 attr = kzalloc(sizeof(*attr), GFP_ATOMIC);
1495 sysfs_bin_attr_init(attr);
1497 attr->attr.name = "vpd";
1498 attr->attr.mode = S_IRUSR | S_IWUSR;
1499 attr->read = read_vpd_attr;
1500 attr->write = write_vpd_attr;
1501 retval = sysfs_create_bin_file(&dev->dev.kobj, attr);
1506 dev->vpd->attr = attr;
1509 /* Active State Power Management */
1510 pcie_aspm_create_sysfs_dev_files(dev);
1512 if (!pci_probe_reset_function(dev)) {
1513 retval = device_create_file(&dev->dev, &reset_attr);
1521 pcie_aspm_remove_sysfs_dev_files(dev);
1522 if (dev->vpd && dev->vpd->attr) {
1523 sysfs_remove_bin_file(&dev->dev.kobj, dev->vpd->attr);
1524 kfree(dev->vpd->attr);
1530 int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev)
1534 struct bin_attribute *attr;
1536 if (!sysfs_initialized)
1539 if (pdev->cfg_size > PCI_CFG_SPACE_SIZE)
1540 retval = sysfs_create_bin_file(&pdev->dev.kobj, &pcie_config_attr);
1542 retval = sysfs_create_bin_file(&pdev->dev.kobj, &pci_config_attr);
1546 retval = pci_create_resource_files(pdev);
1548 goto err_config_file;
1550 /* If the device has a ROM, try to expose it in sysfs. */
1551 rom_size = pci_resource_len(pdev, PCI_ROM_RESOURCE);
1553 attr = kzalloc(sizeof(*attr), GFP_ATOMIC);
1556 goto err_resource_files;
1558 sysfs_bin_attr_init(attr);
1559 attr->size = rom_size;
1560 attr->attr.name = "rom";
1561 attr->attr.mode = S_IRUSR | S_IWUSR;
1562 attr->read = pci_read_rom;
1563 attr->write = pci_write_rom;
1564 retval = sysfs_create_bin_file(&pdev->dev.kobj, attr);
1567 goto err_resource_files;
1569 pdev->rom_attr = attr;
1572 /* add sysfs entries for various capabilities */
1573 retval = pci_create_capabilities_sysfs(pdev);
1577 pci_create_firmware_label_files(pdev);
1582 if (pdev->rom_attr) {
1583 sysfs_remove_bin_file(&pdev->dev.kobj, pdev->rom_attr);
1584 kfree(pdev->rom_attr);
1585 pdev->rom_attr = NULL;
1588 pci_remove_resource_files(pdev);
1590 if (pdev->cfg_size > PCI_CFG_SPACE_SIZE)
1591 sysfs_remove_bin_file(&pdev->dev.kobj, &pcie_config_attr);
1593 sysfs_remove_bin_file(&pdev->dev.kobj, &pci_config_attr);
1598 static void pci_remove_capabilities_sysfs(struct pci_dev *dev)
1600 if (dev->vpd && dev->vpd->attr) {
1601 sysfs_remove_bin_file(&dev->dev.kobj, dev->vpd->attr);
1602 kfree(dev->vpd->attr);
1605 pcie_aspm_remove_sysfs_dev_files(dev);
1606 if (dev->reset_fn) {
1607 device_remove_file(&dev->dev, &reset_attr);
1613 * pci_remove_sysfs_dev_files - cleanup PCI specific sysfs files
1614 * @pdev: device whose entries we should free
1616 * Cleanup when @pdev is removed from sysfs.
1618 void pci_remove_sysfs_dev_files(struct pci_dev *pdev)
1620 if (!sysfs_initialized)
1623 pci_remove_capabilities_sysfs(pdev);
1625 if (pdev->cfg_size > PCI_CFG_SPACE_SIZE)
1626 sysfs_remove_bin_file(&pdev->dev.kobj, &pcie_config_attr);
1628 sysfs_remove_bin_file(&pdev->dev.kobj, &pci_config_attr);
1630 pci_remove_resource_files(pdev);
1632 if (pdev->rom_attr) {
1633 sysfs_remove_bin_file(&pdev->dev.kobj, pdev->rom_attr);
1634 kfree(pdev->rom_attr);
1635 pdev->rom_attr = NULL;
1638 pci_remove_firmware_label_files(pdev);
1641 static int __init pci_sysfs_init(void)
1643 struct pci_dev *pdev = NULL;
1646 sysfs_initialized = 1;
1647 for_each_pci_dev(pdev) {
1648 retval = pci_create_sysfs_dev_files(pdev);
1657 late_initcall(pci_sysfs_init);
1659 static struct attribute *pci_dev_dev_attrs[] = {
1664 static umode_t pci_dev_attrs_are_visible(struct kobject *kobj,
1665 struct attribute *a, int n)
1667 struct device *dev = kobj_to_dev(kobj);
1668 struct pci_dev *pdev = to_pci_dev(dev);
1670 if (a == &vga_attr.attr)
1671 if ((pdev->class >> 8) != PCI_CLASS_DISPLAY_VGA)
1677 static struct attribute *pci_dev_hp_attrs[] = {
1678 &dev_remove_attr.attr,
1679 &dev_rescan_attr.attr,
1683 static umode_t pci_dev_hp_attrs_are_visible(struct kobject *kobj,
1684 struct attribute *a, int n)
1686 struct device *dev = kobj_to_dev(kobj);
1687 struct pci_dev *pdev = to_pci_dev(dev);
1689 if (pdev->is_virtfn)
1695 static umode_t pci_bridge_attrs_are_visible(struct kobject *kobj,
1696 struct attribute *a, int n)
1698 struct device *dev = kobj_to_dev(kobj);
1699 struct pci_dev *pdev = to_pci_dev(dev);
1701 if (pci_is_bridge(pdev))
1707 static umode_t pcie_dev_attrs_are_visible(struct kobject *kobj,
1708 struct attribute *a, int n)
1710 struct device *dev = kobj_to_dev(kobj);
1711 struct pci_dev *pdev = to_pci_dev(dev);
1713 if (pci_is_pcie(pdev))
1719 static const struct attribute_group pci_dev_group = {
1720 .attrs = pci_dev_attrs,
1723 const struct attribute_group *pci_dev_groups[] = {
1728 static const struct attribute_group pci_bridge_group = {
1729 .attrs = pci_bridge_attrs,
1732 const struct attribute_group *pci_bridge_groups[] = {
1737 static const struct attribute_group pcie_dev_group = {
1738 .attrs = pcie_dev_attrs,
1741 const struct attribute_group *pcie_dev_groups[] = {
1746 static const struct attribute_group pci_dev_hp_attr_group = {
1747 .attrs = pci_dev_hp_attrs,
1748 .is_visible = pci_dev_hp_attrs_are_visible,
1751 #ifdef CONFIG_PCI_IOV
1752 static struct attribute *sriov_dev_attrs[] = {
1753 &sriov_totalvfs_attr.attr,
1754 &sriov_numvfs_attr.attr,
1755 &sriov_drivers_autoprobe_attr.attr,
1759 static umode_t sriov_attrs_are_visible(struct kobject *kobj,
1760 struct attribute *a, int n)
1762 struct device *dev = kobj_to_dev(kobj);
1764 if (!dev_is_pf(dev))
1770 static const struct attribute_group sriov_dev_attr_group = {
1771 .attrs = sriov_dev_attrs,
1772 .is_visible = sriov_attrs_are_visible,
1774 #endif /* CONFIG_PCI_IOV */
1776 static const struct attribute_group pci_dev_attr_group = {
1777 .attrs = pci_dev_dev_attrs,
1778 .is_visible = pci_dev_attrs_are_visible,
1781 static const struct attribute_group pci_bridge_attr_group = {
1782 .attrs = pci_bridge_attrs,
1783 .is_visible = pci_bridge_attrs_are_visible,
1786 static const struct attribute_group pcie_dev_attr_group = {
1787 .attrs = pcie_dev_attrs,
1788 .is_visible = pcie_dev_attrs_are_visible,
1791 static const struct attribute_group *pci_dev_attr_groups[] = {
1792 &pci_dev_attr_group,
1793 &pci_dev_hp_attr_group,
1794 #ifdef CONFIG_PCI_IOV
1795 &sriov_dev_attr_group,
1797 &pci_bridge_attr_group,
1798 &pcie_dev_attr_group,
1802 struct device_type pci_dev_type = {
1803 .groups = pci_dev_attr_groups,