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 ari_enabled_show(struct device *dev,
282 struct device_attribute *attr,
285 struct pci_dev *pci_dev = to_pci_dev(dev);
287 return sprintf(buf, "%u\n", pci_ari_enabled(pci_dev->bus));
289 static DEVICE_ATTR_RO(ari_enabled);
291 static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
294 struct pci_dev *pci_dev = to_pci_dev(dev);
296 return sprintf(buf, "pci:v%08Xd%08Xsv%08Xsd%08Xbc%02Xsc%02Xi%02X\n",
297 pci_dev->vendor, pci_dev->device,
298 pci_dev->subsystem_vendor, pci_dev->subsystem_device,
299 (u8)(pci_dev->class >> 16), (u8)(pci_dev->class >> 8),
300 (u8)(pci_dev->class));
302 static DEVICE_ATTR_RO(modalias);
304 static ssize_t enable_store(struct device *dev, struct device_attribute *attr,
305 const char *buf, size_t count)
307 struct pci_dev *pdev = to_pci_dev(dev);
309 ssize_t result = kstrtoul(buf, 0, &val);
314 /* this can crash the machine when done on the "wrong" device */
315 if (!capable(CAP_SYS_ADMIN))
319 if (pci_is_enabled(pdev))
320 pci_disable_device(pdev);
324 result = pci_enable_device(pdev);
326 return result < 0 ? result : count;
329 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
332 struct pci_dev *pdev;
334 pdev = to_pci_dev(dev);
335 return sprintf(buf, "%u\n", atomic_read(&pdev->enable_cnt));
337 static DEVICE_ATTR_RW(enable);
340 static ssize_t numa_node_store(struct device *dev,
341 struct device_attribute *attr, const char *buf,
344 struct pci_dev *pdev = to_pci_dev(dev);
347 if (!capable(CAP_SYS_ADMIN))
350 ret = kstrtoint(buf, 0, &node);
354 if ((node < 0 && node != NUMA_NO_NODE) || node >= MAX_NUMNODES)
357 if (node != NUMA_NO_NODE && !node_online(node))
360 add_taint(TAINT_FIRMWARE_WORKAROUND, LOCKDEP_STILL_OK);
361 pci_alert(pdev, FW_BUG "Overriding NUMA node to %d. Contact your vendor for updates.",
364 dev->numa_node = node;
368 static ssize_t numa_node_show(struct device *dev, struct device_attribute *attr,
371 return sprintf(buf, "%d\n", dev->numa_node);
373 static DEVICE_ATTR_RW(numa_node);
376 static ssize_t dma_mask_bits_show(struct device *dev,
377 struct device_attribute *attr, char *buf)
379 struct pci_dev *pdev = to_pci_dev(dev);
381 return sprintf(buf, "%d\n", fls64(pdev->dma_mask));
383 static DEVICE_ATTR_RO(dma_mask_bits);
385 static ssize_t consistent_dma_mask_bits_show(struct device *dev,
386 struct device_attribute *attr,
389 return sprintf(buf, "%d\n", fls64(dev->coherent_dma_mask));
391 static DEVICE_ATTR_RO(consistent_dma_mask_bits);
393 static ssize_t msi_bus_show(struct device *dev, struct device_attribute *attr,
396 struct pci_dev *pdev = to_pci_dev(dev);
397 struct pci_bus *subordinate = pdev->subordinate;
399 return sprintf(buf, "%u\n", subordinate ?
400 !(subordinate->bus_flags & PCI_BUS_FLAGS_NO_MSI)
404 static ssize_t msi_bus_store(struct device *dev, struct device_attribute *attr,
405 const char *buf, size_t count)
407 struct pci_dev *pdev = to_pci_dev(dev);
408 struct pci_bus *subordinate = pdev->subordinate;
411 if (kstrtoul(buf, 0, &val) < 0)
414 if (!capable(CAP_SYS_ADMIN))
418 * "no_msi" and "bus_flags" only affect what happens when a driver
419 * requests MSI or MSI-X. They don't affect any drivers that have
420 * already requested MSI or MSI-X.
424 pci_info(pdev, "MSI/MSI-X %s for future drivers\n",
425 val ? "allowed" : "disallowed");
430 subordinate->bus_flags &= ~PCI_BUS_FLAGS_NO_MSI;
432 subordinate->bus_flags |= PCI_BUS_FLAGS_NO_MSI;
434 dev_info(&subordinate->dev, "MSI/MSI-X %s for future drivers of devices on this bus\n",
435 val ? "allowed" : "disallowed");
438 static DEVICE_ATTR_RW(msi_bus);
440 static ssize_t bus_rescan_store(struct bus_type *bus, const char *buf,
444 struct pci_bus *b = NULL;
446 if (kstrtoul(buf, 0, &val) < 0)
450 pci_lock_rescan_remove();
451 while ((b = pci_find_next_bus(b)) != NULL)
453 pci_unlock_rescan_remove();
457 static BUS_ATTR(rescan, (S_IWUSR|S_IWGRP), NULL, bus_rescan_store);
459 static struct attribute *pci_bus_attrs[] = {
460 &bus_attr_rescan.attr,
464 static const struct attribute_group pci_bus_group = {
465 .attrs = pci_bus_attrs,
468 const struct attribute_group *pci_bus_groups[] = {
473 static ssize_t dev_rescan_store(struct device *dev,
474 struct device_attribute *attr, const char *buf,
478 struct pci_dev *pdev = to_pci_dev(dev);
480 if (kstrtoul(buf, 0, &val) < 0)
484 pci_lock_rescan_remove();
485 pci_rescan_bus(pdev->bus);
486 pci_unlock_rescan_remove();
490 static struct device_attribute dev_rescan_attr = __ATTR(rescan,
492 NULL, dev_rescan_store);
494 static ssize_t remove_store(struct device *dev, struct device_attribute *attr,
495 const char *buf, size_t count)
499 if (kstrtoul(buf, 0, &val) < 0)
502 if (val && device_remove_file_self(dev, attr))
503 pci_stop_and_remove_bus_device_locked(to_pci_dev(dev));
506 static struct device_attribute dev_remove_attr = __ATTR(remove,
510 static ssize_t dev_bus_rescan_store(struct device *dev,
511 struct device_attribute *attr,
512 const char *buf, size_t count)
515 struct pci_bus *bus = to_pci_bus(dev);
517 if (kstrtoul(buf, 0, &val) < 0)
521 pci_lock_rescan_remove();
522 if (!pci_is_root_bus(bus) && list_empty(&bus->devices))
523 pci_rescan_bus_bridge_resize(bus->self);
526 pci_unlock_rescan_remove();
530 static DEVICE_ATTR(rescan, (S_IWUSR|S_IWGRP), NULL, dev_bus_rescan_store);
532 #if defined(CONFIG_PM) && defined(CONFIG_ACPI)
533 static ssize_t d3cold_allowed_store(struct device *dev,
534 struct device_attribute *attr,
535 const char *buf, size_t count)
537 struct pci_dev *pdev = to_pci_dev(dev);
540 if (kstrtoul(buf, 0, &val) < 0)
543 pdev->d3cold_allowed = !!val;
544 if (pdev->d3cold_allowed)
545 pci_d3cold_enable(pdev);
547 pci_d3cold_disable(pdev);
549 pm_runtime_resume(dev);
554 static ssize_t d3cold_allowed_show(struct device *dev,
555 struct device_attribute *attr, char *buf)
557 struct pci_dev *pdev = to_pci_dev(dev);
558 return sprintf(buf, "%u\n", pdev->d3cold_allowed);
560 static DEVICE_ATTR_RW(d3cold_allowed);
564 static ssize_t devspec_show(struct device *dev,
565 struct device_attribute *attr, char *buf)
567 struct pci_dev *pdev = to_pci_dev(dev);
568 struct device_node *np = pci_device_to_OF_node(pdev);
572 return sprintf(buf, "%pOF", np);
574 static DEVICE_ATTR_RO(devspec);
577 #ifdef CONFIG_PCI_IOV
578 static ssize_t sriov_totalvfs_show(struct device *dev,
579 struct device_attribute *attr,
582 struct pci_dev *pdev = to_pci_dev(dev);
584 return sprintf(buf, "%u\n", pci_sriov_get_totalvfs(pdev));
588 static ssize_t sriov_numvfs_show(struct device *dev,
589 struct device_attribute *attr,
592 struct pci_dev *pdev = to_pci_dev(dev);
594 return sprintf(buf, "%u\n", pdev->sriov->num_VFs);
598 * num_vfs > 0; number of VFs to enable
599 * num_vfs = 0; disable all VFs
601 * Note: SRIOV spec doesn't allow partial VF
602 * disable, so it's all or none.
604 static ssize_t sriov_numvfs_store(struct device *dev,
605 struct device_attribute *attr,
606 const char *buf, size_t count)
608 struct pci_dev *pdev = to_pci_dev(dev);
612 ret = kstrtou16(buf, 0, &num_vfs);
616 if (num_vfs > pci_sriov_get_totalvfs(pdev))
619 device_lock(&pdev->dev);
621 if (num_vfs == pdev->sriov->num_VFs)
624 /* is PF driver loaded w/callback */
625 if (!pdev->driver || !pdev->driver->sriov_configure) {
626 pci_info(pdev, "Driver doesn't support SRIOV configuration via sysfs\n");
633 ret = pdev->driver->sriov_configure(pdev, 0);
638 if (pdev->sriov->num_VFs) {
639 pci_warn(pdev, "%d VFs already enabled. Disable before enabling %d VFs\n",
640 pdev->sriov->num_VFs, num_vfs);
645 ret = pdev->driver->sriov_configure(pdev, num_vfs);
650 pci_warn(pdev, "%d VFs requested; only %d enabled\n",
654 device_unlock(&pdev->dev);
662 static ssize_t sriov_offset_show(struct device *dev,
663 struct device_attribute *attr,
666 struct pci_dev *pdev = to_pci_dev(dev);
668 return sprintf(buf, "%u\n", pdev->sriov->offset);
671 static ssize_t sriov_stride_show(struct device *dev,
672 struct device_attribute *attr,
675 struct pci_dev *pdev = to_pci_dev(dev);
677 return sprintf(buf, "%u\n", pdev->sriov->stride);
680 static ssize_t sriov_vf_device_show(struct device *dev,
681 struct device_attribute *attr,
684 struct pci_dev *pdev = to_pci_dev(dev);
686 return sprintf(buf, "%x\n", pdev->sriov->vf_device);
689 static ssize_t sriov_drivers_autoprobe_show(struct device *dev,
690 struct device_attribute *attr,
693 struct pci_dev *pdev = to_pci_dev(dev);
695 return sprintf(buf, "%u\n", pdev->sriov->drivers_autoprobe);
698 static ssize_t sriov_drivers_autoprobe_store(struct device *dev,
699 struct device_attribute *attr,
700 const char *buf, size_t count)
702 struct pci_dev *pdev = to_pci_dev(dev);
703 bool drivers_autoprobe;
705 if (kstrtobool(buf, &drivers_autoprobe) < 0)
708 pdev->sriov->drivers_autoprobe = drivers_autoprobe;
713 static struct device_attribute sriov_totalvfs_attr = __ATTR_RO(sriov_totalvfs);
714 static struct device_attribute sriov_numvfs_attr =
715 __ATTR(sriov_numvfs, (S_IRUGO|S_IWUSR|S_IWGRP),
716 sriov_numvfs_show, sriov_numvfs_store);
717 static struct device_attribute sriov_offset_attr = __ATTR_RO(sriov_offset);
718 static struct device_attribute sriov_stride_attr = __ATTR_RO(sriov_stride);
719 static struct device_attribute sriov_vf_device_attr = __ATTR_RO(sriov_vf_device);
720 static struct device_attribute sriov_drivers_autoprobe_attr =
721 __ATTR(sriov_drivers_autoprobe, (S_IRUGO|S_IWUSR|S_IWGRP),
722 sriov_drivers_autoprobe_show, sriov_drivers_autoprobe_store);
723 #endif /* CONFIG_PCI_IOV */
725 static ssize_t driver_override_store(struct device *dev,
726 struct device_attribute *attr,
727 const char *buf, size_t count)
729 struct pci_dev *pdev = to_pci_dev(dev);
730 char *driver_override, *old, *cp;
732 /* We need to keep extra room for a newline */
733 if (count >= (PAGE_SIZE - 1))
736 driver_override = kstrndup(buf, count, GFP_KERNEL);
737 if (!driver_override)
740 cp = strchr(driver_override, '\n');
745 old = pdev->driver_override;
746 if (strlen(driver_override)) {
747 pdev->driver_override = driver_override;
749 kfree(driver_override);
750 pdev->driver_override = NULL;
759 static ssize_t driver_override_show(struct device *dev,
760 struct device_attribute *attr, char *buf)
762 struct pci_dev *pdev = to_pci_dev(dev);
766 len = snprintf(buf, PAGE_SIZE, "%s\n", pdev->driver_override);
770 static DEVICE_ATTR_RW(driver_override);
772 static struct attribute *pci_dev_attrs[] = {
773 &dev_attr_resource.attr,
774 &dev_attr_vendor.attr,
775 &dev_attr_device.attr,
776 &dev_attr_subsystem_vendor.attr,
777 &dev_attr_subsystem_device.attr,
778 &dev_attr_revision.attr,
779 &dev_attr_class.attr,
781 &dev_attr_local_cpus.attr,
782 &dev_attr_local_cpulist.attr,
783 &dev_attr_modalias.attr,
785 &dev_attr_numa_node.attr,
787 &dev_attr_dma_mask_bits.attr,
788 &dev_attr_consistent_dma_mask_bits.attr,
789 &dev_attr_enable.attr,
790 &dev_attr_broken_parity_status.attr,
791 &dev_attr_msi_bus.attr,
792 #if defined(CONFIG_PM) && defined(CONFIG_ACPI)
793 &dev_attr_d3cold_allowed.attr,
796 &dev_attr_devspec.attr,
798 &dev_attr_driver_override.attr,
799 &dev_attr_ari_enabled.attr,
803 static struct attribute *pci_bridge_attrs[] = {
804 &dev_attr_subordinate_bus_number.attr,
805 &dev_attr_secondary_bus_number.attr,
809 static struct attribute *pcie_dev_attrs[] = {
810 &dev_attr_current_link_speed.attr,
811 &dev_attr_current_link_width.attr,
812 &dev_attr_max_link_width.attr,
813 &dev_attr_max_link_speed.attr,
817 static struct attribute *pcibus_attrs[] = {
818 &dev_attr_rescan.attr,
819 &dev_attr_cpuaffinity.attr,
820 &dev_attr_cpulistaffinity.attr,
824 static const struct attribute_group pcibus_group = {
825 .attrs = pcibus_attrs,
828 const struct attribute_group *pcibus_groups[] = {
833 static ssize_t boot_vga_show(struct device *dev, struct device_attribute *attr,
836 struct pci_dev *pdev = to_pci_dev(dev);
837 struct pci_dev *vga_dev = vga_default_device();
840 return sprintf(buf, "%u\n", (pdev == vga_dev));
842 return sprintf(buf, "%u\n",
843 !!(pdev->resource[PCI_ROM_RESOURCE].flags &
844 IORESOURCE_ROM_SHADOW));
846 static struct device_attribute vga_attr = __ATTR_RO(boot_vga);
848 static ssize_t pci_read_config(struct file *filp, struct kobject *kobj,
849 struct bin_attribute *bin_attr, char *buf,
850 loff_t off, size_t count)
852 struct pci_dev *dev = to_pci_dev(kobj_to_dev(kobj));
853 unsigned int size = 64;
854 loff_t init_off = off;
855 u8 *data = (u8 *) buf;
857 /* Several chips lock up trying to read undefined config space */
858 if (file_ns_capable(filp, &init_user_ns, CAP_SYS_ADMIN))
859 size = dev->cfg_size;
860 else if (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
865 if (off + count > size) {
872 pci_config_pm_runtime_get(dev);
874 if ((off & 1) && size) {
876 pci_user_read_config_byte(dev, off, &val);
877 data[off - init_off] = val;
882 if ((off & 3) && size > 2) {
884 pci_user_read_config_word(dev, off, &val);
885 data[off - init_off] = val & 0xff;
886 data[off - init_off + 1] = (val >> 8) & 0xff;
893 pci_user_read_config_dword(dev, off, &val);
894 data[off - init_off] = val & 0xff;
895 data[off - init_off + 1] = (val >> 8) & 0xff;
896 data[off - init_off + 2] = (val >> 16) & 0xff;
897 data[off - init_off + 3] = (val >> 24) & 0xff;
904 pci_user_read_config_word(dev, off, &val);
905 data[off - init_off] = val & 0xff;
906 data[off - init_off + 1] = (val >> 8) & 0xff;
913 pci_user_read_config_byte(dev, off, &val);
914 data[off - init_off] = val;
919 pci_config_pm_runtime_put(dev);
924 static ssize_t pci_write_config(struct file *filp, struct kobject *kobj,
925 struct bin_attribute *bin_attr, char *buf,
926 loff_t off, size_t count)
928 struct pci_dev *dev = to_pci_dev(kobj_to_dev(kobj));
929 unsigned int size = count;
930 loff_t init_off = off;
931 u8 *data = (u8 *) buf;
933 if (off > dev->cfg_size)
935 if (off + count > dev->cfg_size) {
936 size = dev->cfg_size - off;
940 pci_config_pm_runtime_get(dev);
942 if ((off & 1) && size) {
943 pci_user_write_config_byte(dev, off, data[off - init_off]);
948 if ((off & 3) && size > 2) {
949 u16 val = data[off - init_off];
950 val |= (u16) data[off - init_off + 1] << 8;
951 pci_user_write_config_word(dev, off, val);
957 u32 val = data[off - init_off];
958 val |= (u32) data[off - init_off + 1] << 8;
959 val |= (u32) data[off - init_off + 2] << 16;
960 val |= (u32) data[off - init_off + 3] << 24;
961 pci_user_write_config_dword(dev, off, val);
967 u16 val = data[off - init_off];
968 val |= (u16) data[off - init_off + 1] << 8;
969 pci_user_write_config_word(dev, off, val);
975 pci_user_write_config_byte(dev, off, data[off - init_off]);
980 pci_config_pm_runtime_put(dev);
985 #ifdef HAVE_PCI_LEGACY
987 * pci_read_legacy_io - read byte(s) from legacy I/O port space
988 * @filp: open sysfs file
989 * @kobj: kobject corresponding to file to read from
990 * @bin_attr: struct bin_attribute for this file
991 * @buf: buffer to store results
992 * @off: offset into legacy I/O port space
993 * @count: number of bytes to read
995 * Reads 1, 2, or 4 bytes from legacy I/O port space using an arch specific
996 * callback routine (pci_legacy_read).
998 static ssize_t pci_read_legacy_io(struct file *filp, struct kobject *kobj,
999 struct bin_attribute *bin_attr, char *buf,
1000 loff_t off, size_t count)
1002 struct pci_bus *bus = to_pci_bus(kobj_to_dev(kobj));
1004 /* Only support 1, 2 or 4 byte accesses */
1005 if (count != 1 && count != 2 && count != 4)
1008 return pci_legacy_read(bus, off, (u32 *)buf, count);
1012 * pci_write_legacy_io - write byte(s) to legacy I/O port space
1013 * @filp: open sysfs file
1014 * @kobj: kobject corresponding to file to read from
1015 * @bin_attr: struct bin_attribute for this file
1016 * @buf: buffer containing value to be written
1017 * @off: offset into legacy I/O port space
1018 * @count: number of bytes to write
1020 * Writes 1, 2, or 4 bytes from legacy I/O port space using an arch specific
1021 * callback routine (pci_legacy_write).
1023 static ssize_t pci_write_legacy_io(struct file *filp, struct kobject *kobj,
1024 struct bin_attribute *bin_attr, char *buf,
1025 loff_t off, size_t count)
1027 struct pci_bus *bus = to_pci_bus(kobj_to_dev(kobj));
1029 /* Only support 1, 2 or 4 byte accesses */
1030 if (count != 1 && count != 2 && count != 4)
1033 return pci_legacy_write(bus, off, *(u32 *)buf, count);
1037 * pci_mmap_legacy_mem - map legacy PCI memory into user memory space
1038 * @filp: open sysfs file
1039 * @kobj: kobject corresponding to device to be mapped
1040 * @attr: struct bin_attribute for this file
1041 * @vma: struct vm_area_struct passed to mmap
1043 * Uses an arch specific callback, pci_mmap_legacy_mem_page_range, to mmap
1044 * legacy memory space (first meg of bus space) into application virtual
1047 static int pci_mmap_legacy_mem(struct file *filp, struct kobject *kobj,
1048 struct bin_attribute *attr,
1049 struct vm_area_struct *vma)
1051 struct pci_bus *bus = to_pci_bus(kobj_to_dev(kobj));
1053 return pci_mmap_legacy_page_range(bus, vma, pci_mmap_mem);
1057 * pci_mmap_legacy_io - map legacy PCI IO into user memory space
1058 * @filp: open sysfs file
1059 * @kobj: kobject corresponding to device to be mapped
1060 * @attr: struct bin_attribute for this file
1061 * @vma: struct vm_area_struct passed to mmap
1063 * Uses an arch specific callback, pci_mmap_legacy_io_page_range, to mmap
1064 * legacy IO space (first meg of bus space) into application virtual
1065 * memory space. Returns -ENOSYS if the operation isn't supported
1067 static int pci_mmap_legacy_io(struct file *filp, struct kobject *kobj,
1068 struct bin_attribute *attr,
1069 struct vm_area_struct *vma)
1071 struct pci_bus *bus = to_pci_bus(kobj_to_dev(kobj));
1073 return pci_mmap_legacy_page_range(bus, vma, pci_mmap_io);
1077 * pci_adjust_legacy_attr - adjustment of legacy file attributes
1078 * @b: bus to create files under
1079 * @mmap_type: I/O port or memory
1081 * Stub implementation. Can be overridden by arch if necessary.
1083 void __weak pci_adjust_legacy_attr(struct pci_bus *b,
1084 enum pci_mmap_state mmap_type)
1089 * pci_create_legacy_files - create legacy I/O port and memory files
1090 * @b: bus to create files under
1092 * Some platforms allow access to legacy I/O port and ISA memory space on
1093 * a per-bus basis. This routine creates the files and ties them into
1094 * their associated read, write and mmap files from pci-sysfs.c
1096 * On error unwind, but don't propagate the error to the caller
1097 * as it is ok to set up the PCI bus without these files.
1099 void pci_create_legacy_files(struct pci_bus *b)
1103 b->legacy_io = kzalloc(sizeof(struct bin_attribute) * 2,
1108 sysfs_bin_attr_init(b->legacy_io);
1109 b->legacy_io->attr.name = "legacy_io";
1110 b->legacy_io->size = 0xffff;
1111 b->legacy_io->attr.mode = S_IRUSR | S_IWUSR;
1112 b->legacy_io->read = pci_read_legacy_io;
1113 b->legacy_io->write = pci_write_legacy_io;
1114 b->legacy_io->mmap = pci_mmap_legacy_io;
1115 pci_adjust_legacy_attr(b, pci_mmap_io);
1116 error = device_create_bin_file(&b->dev, b->legacy_io);
1120 /* Allocated above after the legacy_io struct */
1121 b->legacy_mem = b->legacy_io + 1;
1122 sysfs_bin_attr_init(b->legacy_mem);
1123 b->legacy_mem->attr.name = "legacy_mem";
1124 b->legacy_mem->size = 1024*1024;
1125 b->legacy_mem->attr.mode = S_IRUSR | S_IWUSR;
1126 b->legacy_mem->mmap = pci_mmap_legacy_mem;
1127 pci_adjust_legacy_attr(b, pci_mmap_mem);
1128 error = device_create_bin_file(&b->dev, b->legacy_mem);
1130 goto legacy_mem_err;
1135 device_remove_bin_file(&b->dev, b->legacy_io);
1137 kfree(b->legacy_io);
1138 b->legacy_io = NULL;
1140 printk(KERN_WARNING "pci: warning: could not create legacy I/O port and ISA memory resources to sysfs\n");
1144 void pci_remove_legacy_files(struct pci_bus *b)
1147 device_remove_bin_file(&b->dev, b->legacy_io);
1148 device_remove_bin_file(&b->dev, b->legacy_mem);
1149 kfree(b->legacy_io); /* both are allocated here */
1152 #endif /* HAVE_PCI_LEGACY */
1154 #if defined(HAVE_PCI_MMAP) || defined(ARCH_GENERIC_PCI_MMAP_RESOURCE)
1156 int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vma,
1157 enum pci_mmap_api mmap_api)
1159 unsigned long nr, start, size;
1160 resource_size_t pci_start = 0, pci_end;
1162 if (pci_resource_len(pdev, resno) == 0)
1164 nr = vma_pages(vma);
1165 start = vma->vm_pgoff;
1166 size = ((pci_resource_len(pdev, resno) - 1) >> PAGE_SHIFT) + 1;
1167 if (mmap_api == PCI_MMAP_PROCFS) {
1168 pci_resource_to_user(pdev, resno, &pdev->resource[resno],
1169 &pci_start, &pci_end);
1170 pci_start >>= PAGE_SHIFT;
1172 if (start >= pci_start && start < pci_start + size &&
1173 start + nr <= pci_start + size)
1179 * pci_mmap_resource - map a PCI resource into user memory space
1180 * @kobj: kobject for mapping
1181 * @attr: struct bin_attribute for the file being mapped
1182 * @vma: struct vm_area_struct passed into the mmap
1183 * @write_combine: 1 for write_combine mapping
1185 * Use the regular PCI mapping routines to map a PCI resource into userspace.
1187 static int pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr,
1188 struct vm_area_struct *vma, int write_combine)
1190 struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj));
1191 int bar = (unsigned long)attr->private;
1192 enum pci_mmap_state mmap_type;
1193 struct resource *res = &pdev->resource[bar];
1195 if (res->flags & IORESOURCE_MEM && iomem_is_exclusive(res->start))
1198 if (!pci_mmap_fits(pdev, bar, vma, PCI_MMAP_SYSFS))
1201 mmap_type = res->flags & IORESOURCE_MEM ? pci_mmap_mem : pci_mmap_io;
1203 return pci_mmap_resource_range(pdev, bar, vma, mmap_type, write_combine);
1206 static int pci_mmap_resource_uc(struct file *filp, struct kobject *kobj,
1207 struct bin_attribute *attr,
1208 struct vm_area_struct *vma)
1210 return pci_mmap_resource(kobj, attr, vma, 0);
1213 static int pci_mmap_resource_wc(struct file *filp, struct kobject *kobj,
1214 struct bin_attribute *attr,
1215 struct vm_area_struct *vma)
1217 return pci_mmap_resource(kobj, attr, vma, 1);
1220 static ssize_t pci_resource_io(struct file *filp, struct kobject *kobj,
1221 struct bin_attribute *attr, char *buf,
1222 loff_t off, size_t count, bool write)
1224 struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj));
1225 int bar = (unsigned long)attr->private;
1226 unsigned long port = off;
1228 port += pci_resource_start(pdev, bar);
1230 if (port > pci_resource_end(pdev, bar))
1233 if (port + count - 1 > pci_resource_end(pdev, bar))
1239 outb(*(u8 *)buf, port);
1241 *(u8 *)buf = inb(port);
1245 outw(*(u16 *)buf, port);
1247 *(u16 *)buf = inw(port);
1251 outl(*(u32 *)buf, port);
1253 *(u32 *)buf = inl(port);
1259 static ssize_t pci_read_resource_io(struct file *filp, struct kobject *kobj,
1260 struct bin_attribute *attr, char *buf,
1261 loff_t off, size_t count)
1263 return pci_resource_io(filp, kobj, attr, buf, off, count, false);
1266 static ssize_t pci_write_resource_io(struct file *filp, struct kobject *kobj,
1267 struct bin_attribute *attr, char *buf,
1268 loff_t off, size_t count)
1270 return pci_resource_io(filp, kobj, attr, buf, off, count, true);
1274 * pci_remove_resource_files - cleanup resource files
1275 * @pdev: dev to cleanup
1277 * If we created resource files for @pdev, remove them from sysfs and
1278 * free their resources.
1280 static void pci_remove_resource_files(struct pci_dev *pdev)
1284 for (i = 0; i < PCI_ROM_RESOURCE; i++) {
1285 struct bin_attribute *res_attr;
1287 res_attr = pdev->res_attr[i];
1289 sysfs_remove_bin_file(&pdev->dev.kobj, res_attr);
1293 res_attr = pdev->res_attr_wc[i];
1295 sysfs_remove_bin_file(&pdev->dev.kobj, res_attr);
1301 static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
1303 /* allocate attribute structure, piggyback attribute name */
1304 int name_len = write_combine ? 13 : 10;
1305 struct bin_attribute *res_attr;
1306 char *res_attr_name;
1309 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
1313 res_attr_name = (char *)(res_attr + 1);
1315 sysfs_bin_attr_init(res_attr);
1316 if (write_combine) {
1317 pdev->res_attr_wc[num] = res_attr;
1318 sprintf(res_attr_name, "resource%d_wc", num);
1319 res_attr->mmap = pci_mmap_resource_wc;
1321 pdev->res_attr[num] = res_attr;
1322 sprintf(res_attr_name, "resource%d", num);
1323 if (pci_resource_flags(pdev, num) & IORESOURCE_IO) {
1324 res_attr->read = pci_read_resource_io;
1325 res_attr->write = pci_write_resource_io;
1326 if (arch_can_pci_mmap_io())
1327 res_attr->mmap = pci_mmap_resource_uc;
1329 res_attr->mmap = pci_mmap_resource_uc;
1332 res_attr->attr.name = res_attr_name;
1333 res_attr->attr.mode = S_IRUSR | S_IWUSR;
1334 res_attr->size = pci_resource_len(pdev, num);
1335 res_attr->private = (void *)(unsigned long)num;
1336 retval = sysfs_create_bin_file(&pdev->dev.kobj, res_attr);
1344 * pci_create_resource_files - create resource files in sysfs for @dev
1345 * @pdev: dev in question
1347 * Walk the resources in @pdev creating files for each resource available.
1349 static int pci_create_resource_files(struct pci_dev *pdev)
1354 /* Expose the PCI resources from this device as files */
1355 for (i = 0; i < PCI_ROM_RESOURCE; i++) {
1357 /* skip empty resources */
1358 if (!pci_resource_len(pdev, i))
1361 retval = pci_create_attr(pdev, i, 0);
1362 /* for prefetchable resources, create a WC mappable file */
1363 if (!retval && arch_can_pci_mmap_wc() &&
1364 pdev->resource[i].flags & IORESOURCE_PREFETCH)
1365 retval = pci_create_attr(pdev, i, 1);
1367 pci_remove_resource_files(pdev);
1373 #else /* !HAVE_PCI_MMAP */
1374 int __weak pci_create_resource_files(struct pci_dev *dev) { return 0; }
1375 void __weak pci_remove_resource_files(struct pci_dev *dev) { return; }
1376 #endif /* HAVE_PCI_MMAP */
1379 * pci_write_rom - used to enable access to the PCI ROM display
1381 * @kobj: kernel object handle
1382 * @bin_attr: struct bin_attribute for this file
1385 * @count: number of byte in input
1387 * writing anything except 0 enables it
1389 static ssize_t pci_write_rom(struct file *filp, struct kobject *kobj,
1390 struct bin_attribute *bin_attr, char *buf,
1391 loff_t off, size_t count)
1393 struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj));
1395 if ((off == 0) && (*buf == '0') && (count == 2))
1396 pdev->rom_attr_enabled = 0;
1398 pdev->rom_attr_enabled = 1;
1404 * pci_read_rom - read a PCI ROM
1406 * @kobj: kernel object handle
1407 * @bin_attr: struct bin_attribute for this file
1408 * @buf: where to put the data we read from the ROM
1410 * @count: number of bytes to read
1412 * Put @count bytes starting at @off into @buf from the ROM in the PCI
1413 * device corresponding to @kobj.
1415 static ssize_t pci_read_rom(struct file *filp, struct kobject *kobj,
1416 struct bin_attribute *bin_attr, char *buf,
1417 loff_t off, size_t count)
1419 struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj));
1423 if (!pdev->rom_attr_enabled)
1426 rom = pci_map_rom(pdev, &size); /* size starts out as PCI window size */
1433 if (off + count > size)
1436 memcpy_fromio(buf, rom + off, count);
1438 pci_unmap_rom(pdev, rom);
1443 static const struct bin_attribute pci_config_attr = {
1446 .mode = S_IRUGO | S_IWUSR,
1448 .size = PCI_CFG_SPACE_SIZE,
1449 .read = pci_read_config,
1450 .write = pci_write_config,
1453 static const struct bin_attribute pcie_config_attr = {
1456 .mode = S_IRUGO | S_IWUSR,
1458 .size = PCI_CFG_SPACE_EXP_SIZE,
1459 .read = pci_read_config,
1460 .write = pci_write_config,
1463 static ssize_t reset_store(struct device *dev, struct device_attribute *attr,
1464 const char *buf, size_t count)
1466 struct pci_dev *pdev = to_pci_dev(dev);
1468 ssize_t result = kstrtoul(buf, 0, &val);
1476 result = pci_reset_function(pdev);
1483 static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_store);
1485 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
1489 pcie_vpd_create_sysfs_dev_files(dev);
1490 pcie_aspm_create_sysfs_dev_files(dev);
1492 if (!pci_probe_reset_function(dev)) {
1493 retval = device_create_file(&dev->dev, &reset_attr);
1501 pcie_aspm_remove_sysfs_dev_files(dev);
1502 pcie_vpd_remove_sysfs_dev_files(dev);
1506 int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev)
1510 struct bin_attribute *attr;
1512 if (!sysfs_initialized)
1515 if (pdev->cfg_size > PCI_CFG_SPACE_SIZE)
1516 retval = sysfs_create_bin_file(&pdev->dev.kobj, &pcie_config_attr);
1518 retval = sysfs_create_bin_file(&pdev->dev.kobj, &pci_config_attr);
1522 retval = pci_create_resource_files(pdev);
1524 goto err_config_file;
1526 /* If the device has a ROM, try to expose it in sysfs. */
1527 rom_size = pci_resource_len(pdev, PCI_ROM_RESOURCE);
1529 attr = kzalloc(sizeof(*attr), GFP_ATOMIC);
1532 goto err_resource_files;
1534 sysfs_bin_attr_init(attr);
1535 attr->size = rom_size;
1536 attr->attr.name = "rom";
1537 attr->attr.mode = S_IRUSR | S_IWUSR;
1538 attr->read = pci_read_rom;
1539 attr->write = pci_write_rom;
1540 retval = sysfs_create_bin_file(&pdev->dev.kobj, attr);
1543 goto err_resource_files;
1545 pdev->rom_attr = attr;
1548 /* add sysfs entries for various capabilities */
1549 retval = pci_create_capabilities_sysfs(pdev);
1553 pci_create_firmware_label_files(pdev);
1558 if (pdev->rom_attr) {
1559 sysfs_remove_bin_file(&pdev->dev.kobj, pdev->rom_attr);
1560 kfree(pdev->rom_attr);
1561 pdev->rom_attr = NULL;
1564 pci_remove_resource_files(pdev);
1566 if (pdev->cfg_size > PCI_CFG_SPACE_SIZE)
1567 sysfs_remove_bin_file(&pdev->dev.kobj, &pcie_config_attr);
1569 sysfs_remove_bin_file(&pdev->dev.kobj, &pci_config_attr);
1574 static void pci_remove_capabilities_sysfs(struct pci_dev *dev)
1576 pcie_vpd_remove_sysfs_dev_files(dev);
1577 pcie_aspm_remove_sysfs_dev_files(dev);
1578 if (dev->reset_fn) {
1579 device_remove_file(&dev->dev, &reset_attr);
1585 * pci_remove_sysfs_dev_files - cleanup PCI specific sysfs files
1586 * @pdev: device whose entries we should free
1588 * Cleanup when @pdev is removed from sysfs.
1590 void pci_remove_sysfs_dev_files(struct pci_dev *pdev)
1592 if (!sysfs_initialized)
1595 pci_remove_capabilities_sysfs(pdev);
1597 if (pdev->cfg_size > PCI_CFG_SPACE_SIZE)
1598 sysfs_remove_bin_file(&pdev->dev.kobj, &pcie_config_attr);
1600 sysfs_remove_bin_file(&pdev->dev.kobj, &pci_config_attr);
1602 pci_remove_resource_files(pdev);
1604 if (pdev->rom_attr) {
1605 sysfs_remove_bin_file(&pdev->dev.kobj, pdev->rom_attr);
1606 kfree(pdev->rom_attr);
1607 pdev->rom_attr = NULL;
1610 pci_remove_firmware_label_files(pdev);
1613 static int __init pci_sysfs_init(void)
1615 struct pci_dev *pdev = NULL;
1618 sysfs_initialized = 1;
1619 for_each_pci_dev(pdev) {
1620 retval = pci_create_sysfs_dev_files(pdev);
1629 late_initcall(pci_sysfs_init);
1631 static struct attribute *pci_dev_dev_attrs[] = {
1636 static umode_t pci_dev_attrs_are_visible(struct kobject *kobj,
1637 struct attribute *a, int n)
1639 struct device *dev = kobj_to_dev(kobj);
1640 struct pci_dev *pdev = to_pci_dev(dev);
1642 if (a == &vga_attr.attr)
1643 if ((pdev->class >> 8) != PCI_CLASS_DISPLAY_VGA)
1649 static struct attribute *pci_dev_hp_attrs[] = {
1650 &dev_remove_attr.attr,
1651 &dev_rescan_attr.attr,
1655 static umode_t pci_dev_hp_attrs_are_visible(struct kobject *kobj,
1656 struct attribute *a, int n)
1658 struct device *dev = kobj_to_dev(kobj);
1659 struct pci_dev *pdev = to_pci_dev(dev);
1661 if (pdev->is_virtfn)
1667 static umode_t pci_bridge_attrs_are_visible(struct kobject *kobj,
1668 struct attribute *a, int n)
1670 struct device *dev = kobj_to_dev(kobj);
1671 struct pci_dev *pdev = to_pci_dev(dev);
1673 if (pci_is_bridge(pdev))
1679 static umode_t pcie_dev_attrs_are_visible(struct kobject *kobj,
1680 struct attribute *a, int n)
1682 struct device *dev = kobj_to_dev(kobj);
1683 struct pci_dev *pdev = to_pci_dev(dev);
1685 if (pci_is_pcie(pdev))
1691 static const struct attribute_group pci_dev_group = {
1692 .attrs = pci_dev_attrs,
1695 const struct attribute_group *pci_dev_groups[] = {
1700 static const struct attribute_group pci_bridge_group = {
1701 .attrs = pci_bridge_attrs,
1704 const struct attribute_group *pci_bridge_groups[] = {
1709 static const struct attribute_group pcie_dev_group = {
1710 .attrs = pcie_dev_attrs,
1713 const struct attribute_group *pcie_dev_groups[] = {
1718 static const struct attribute_group pci_dev_hp_attr_group = {
1719 .attrs = pci_dev_hp_attrs,
1720 .is_visible = pci_dev_hp_attrs_are_visible,
1723 #ifdef CONFIG_PCI_IOV
1724 static struct attribute *sriov_dev_attrs[] = {
1725 &sriov_totalvfs_attr.attr,
1726 &sriov_numvfs_attr.attr,
1727 &sriov_offset_attr.attr,
1728 &sriov_stride_attr.attr,
1729 &sriov_vf_device_attr.attr,
1730 &sriov_drivers_autoprobe_attr.attr,
1734 static umode_t sriov_attrs_are_visible(struct kobject *kobj,
1735 struct attribute *a, int n)
1737 struct device *dev = kobj_to_dev(kobj);
1739 if (!dev_is_pf(dev))
1745 static const struct attribute_group sriov_dev_attr_group = {
1746 .attrs = sriov_dev_attrs,
1747 .is_visible = sriov_attrs_are_visible,
1749 #endif /* CONFIG_PCI_IOV */
1751 static const struct attribute_group pci_dev_attr_group = {
1752 .attrs = pci_dev_dev_attrs,
1753 .is_visible = pci_dev_attrs_are_visible,
1756 static const struct attribute_group pci_bridge_attr_group = {
1757 .attrs = pci_bridge_attrs,
1758 .is_visible = pci_bridge_attrs_are_visible,
1761 static const struct attribute_group pcie_dev_attr_group = {
1762 .attrs = pcie_dev_attrs,
1763 .is_visible = pcie_dev_attrs_are_visible,
1766 static const struct attribute_group *pci_dev_attr_groups[] = {
1767 &pci_dev_attr_group,
1768 &pci_dev_hp_attr_group,
1769 #ifdef CONFIG_PCI_IOV
1770 &sriov_dev_attr_group,
1772 &pci_bridge_attr_group,
1773 &pcie_dev_attr_group,
1777 const struct device_type pci_dev_type = {
1778 .groups = pci_dev_attr_groups,