2 * drivers/pci/pci-sysfs.c
4 * (C) Copyright 2002-2004 Greg Kroah-Hartman <greg@kroah.com>
5 * (C) Copyright 2002-2004 IBM Corp.
6 * (C) Copyright 2003 Matthew Wilcox
7 * (C) Copyright 2003 Hewlett-Packard
8 * (C) Copyright 2004 Jon Smirl <jonsmirl@yahoo.com>
9 * (C) Copyright 2004 Silicon Graphics, Inc. Jesse Barnes <jbarnes@sgi.com>
11 * File attributes for PCI devices
13 * Modeled after usb's driverfs.c
18 #include <linux/kernel.h>
19 #include <linux/sched.h>
20 #include <linux/pci.h>
21 #include <linux/stat.h>
22 #include <linux/topology.h>
24 #include <linux/capability.h>
25 #include <linux/pci-aspm.h>
28 static int sysfs_initialized; /* = 0 */
30 /* show configuration fields */
31 #define pci_config_attr(field, format_string) \
33 field##_show(struct device *dev, struct device_attribute *attr, char *buf) \
35 struct pci_dev *pdev; \
37 pdev = to_pci_dev (dev); \
38 return sprintf (buf, format_string, pdev->field); \
41 pci_config_attr(vendor, "0x%04x\n");
42 pci_config_attr(device, "0x%04x\n");
43 pci_config_attr(subsystem_vendor, "0x%04x\n");
44 pci_config_attr(subsystem_device, "0x%04x\n");
45 pci_config_attr(class, "0x%06x\n");
46 pci_config_attr(irq, "%u\n");
48 static ssize_t broken_parity_status_show(struct device *dev,
49 struct device_attribute *attr,
52 struct pci_dev *pdev = to_pci_dev(dev);
53 return sprintf (buf, "%u\n", pdev->broken_parity_status);
56 static ssize_t broken_parity_status_store(struct device *dev,
57 struct device_attribute *attr,
58 const char *buf, size_t count)
60 struct pci_dev *pdev = to_pci_dev(dev);
61 ssize_t consumed = -EINVAL;
63 if ((count > 0) && (*buf == '0' || *buf == '1')) {
64 pdev->broken_parity_status = *buf == '1' ? 1 : 0;
70 static ssize_t local_cpus_show(struct device *dev,
71 struct device_attribute *attr, char *buf)
76 mask = pcibus_to_cpumask(to_pci_dev(dev)->bus);
77 len = cpumask_scnprintf(buf, PAGE_SIZE-2, &mask);
84 static ssize_t local_cpulist_show(struct device *dev,
85 struct device_attribute *attr, char *buf)
90 mask = pcibus_to_cpumask(to_pci_dev(dev)->bus);
91 len = cpulist_scnprintf(buf, PAGE_SIZE-2, &mask);
99 resource_show(struct device * dev, struct device_attribute *attr, char * buf)
101 struct pci_dev * pci_dev = to_pci_dev(dev);
105 resource_size_t start, end;
107 if (pci_dev->subordinate)
108 max = DEVICE_COUNT_RESOURCE;
110 for (i = 0; i < max; i++) {
111 struct resource *res = &pci_dev->resource[i];
112 pci_resource_to_user(pci_dev, i, res, &start, &end);
113 str += sprintf(str,"0x%016llx 0x%016llx 0x%016llx\n",
114 (unsigned long long)start,
115 (unsigned long long)end,
116 (unsigned long long)res->flags);
121 static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf)
123 struct pci_dev *pci_dev = to_pci_dev(dev);
125 return sprintf(buf, "pci:v%08Xd%08Xsv%08Xsd%08Xbc%02Xsc%02Xi%02x\n",
126 pci_dev->vendor, pci_dev->device,
127 pci_dev->subsystem_vendor, pci_dev->subsystem_device,
128 (u8)(pci_dev->class >> 16), (u8)(pci_dev->class >> 8),
129 (u8)(pci_dev->class));
132 static ssize_t is_enabled_store(struct device *dev,
133 struct device_attribute *attr, const char *buf,
136 ssize_t result = -EINVAL;
137 struct pci_dev *pdev = to_pci_dev(dev);
139 /* this can crash the machine when done on the "wrong" device */
140 if (!capable(CAP_SYS_ADMIN))
144 if (atomic_read(&pdev->enable_cnt) != 0)
145 pci_disable_device(pdev);
148 } else if (*buf == '1')
149 result = pci_enable_device(pdev);
151 return result < 0 ? result : count;
154 static ssize_t is_enabled_show(struct device *dev,
155 struct device_attribute *attr, char *buf)
157 struct pci_dev *pdev;
159 pdev = to_pci_dev (dev);
160 return sprintf (buf, "%u\n", atomic_read(&pdev->enable_cnt));
165 numa_node_show(struct device *dev, struct device_attribute *attr, char *buf)
167 return sprintf (buf, "%d\n", dev->numa_node);
172 msi_bus_show(struct device *dev, struct device_attribute *attr, char *buf)
174 struct pci_dev *pdev = to_pci_dev(dev);
176 if (!pdev->subordinate)
179 return sprintf (buf, "%u\n",
180 !(pdev->subordinate->bus_flags & PCI_BUS_FLAGS_NO_MSI));
184 msi_bus_store(struct device *dev, struct device_attribute *attr,
185 const char *buf, size_t count)
187 struct pci_dev *pdev = to_pci_dev(dev);
189 /* bad things may happen if the no_msi flag is changed
190 * while some drivers are loaded */
191 if (!capable(CAP_SYS_ADMIN))
194 if (!pdev->subordinate)
198 pdev->subordinate->bus_flags |= PCI_BUS_FLAGS_NO_MSI;
199 dev_warn(&pdev->dev, "forced subordinate bus to not support MSI,"
200 " bad things could happen.\n");
204 pdev->subordinate->bus_flags &= ~PCI_BUS_FLAGS_NO_MSI;
205 dev_warn(&pdev->dev, "forced subordinate bus to support MSI,"
206 " bad things could happen.\n");
212 struct device_attribute pci_dev_attrs[] = {
216 __ATTR_RO(subsystem_vendor),
217 __ATTR_RO(subsystem_device),
220 __ATTR_RO(local_cpus),
221 __ATTR_RO(local_cpulist),
224 __ATTR_RO(numa_node),
226 __ATTR(enable, 0600, is_enabled_show, is_enabled_store),
227 __ATTR(broken_parity_status,(S_IRUGO|S_IWUSR),
228 broken_parity_status_show,broken_parity_status_store),
229 __ATTR(msi_bus, 0644, msi_bus_show, msi_bus_store),
234 pci_read_config(struct kobject *kobj, struct bin_attribute *bin_attr,
235 char *buf, loff_t off, size_t count)
237 struct pci_dev *dev = to_pci_dev(container_of(kobj,struct device,kobj));
238 unsigned int size = 64;
239 loff_t init_off = off;
240 u8 *data = (u8*) buf;
242 /* Several chips lock up trying to read undefined config space */
243 if (capable(CAP_SYS_ADMIN)) {
244 size = dev->cfg_size;
245 } else if (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) {
251 if (off + count > size) {
258 if ((off & 1) && size) {
260 pci_user_read_config_byte(dev, off, &val);
261 data[off - init_off] = val;
266 if ((off & 3) && size > 2) {
268 pci_user_read_config_word(dev, off, &val);
269 data[off - init_off] = val & 0xff;
270 data[off - init_off + 1] = (val >> 8) & 0xff;
277 pci_user_read_config_dword(dev, off, &val);
278 data[off - init_off] = val & 0xff;
279 data[off - init_off + 1] = (val >> 8) & 0xff;
280 data[off - init_off + 2] = (val >> 16) & 0xff;
281 data[off - init_off + 3] = (val >> 24) & 0xff;
288 pci_user_read_config_word(dev, off, &val);
289 data[off - init_off] = val & 0xff;
290 data[off - init_off + 1] = (val >> 8) & 0xff;
297 pci_user_read_config_byte(dev, off, &val);
298 data[off - init_off] = val;
307 pci_write_config(struct kobject *kobj, struct bin_attribute *bin_attr,
308 char *buf, loff_t off, size_t count)
310 struct pci_dev *dev = to_pci_dev(container_of(kobj,struct device,kobj));
311 unsigned int size = count;
312 loff_t init_off = off;
313 u8 *data = (u8*) buf;
315 if (off > dev->cfg_size)
317 if (off + count > dev->cfg_size) {
318 size = dev->cfg_size - off;
322 if ((off & 1) && size) {
323 pci_user_write_config_byte(dev, off, data[off - init_off]);
328 if ((off & 3) && size > 2) {
329 u16 val = data[off - init_off];
330 val |= (u16) data[off - init_off + 1] << 8;
331 pci_user_write_config_word(dev, off, val);
337 u32 val = data[off - init_off];
338 val |= (u32) data[off - init_off + 1] << 8;
339 val |= (u32) data[off - init_off + 2] << 16;
340 val |= (u32) data[off - init_off + 3] << 24;
341 pci_user_write_config_dword(dev, off, val);
347 u16 val = data[off - init_off];
348 val |= (u16) data[off - init_off + 1] << 8;
349 pci_user_write_config_word(dev, off, val);
355 pci_user_write_config_byte(dev, off, data[off - init_off]);
364 pci_read_vpd(struct kobject *kobj, struct bin_attribute *bin_attr,
365 char *buf, loff_t off, size_t count)
367 struct pci_dev *dev =
368 to_pci_dev(container_of(kobj, struct device, kobj));
372 if (off > bin_attr->size)
374 else if (count > bin_attr->size - off)
375 count = bin_attr->size - off;
379 ret = dev->vpd->ops->read(dev, off, end - off, buf);
390 pci_write_vpd(struct kobject *kobj, struct bin_attribute *bin_attr,
391 char *buf, loff_t off, size_t count)
393 struct pci_dev *dev =
394 to_pci_dev(container_of(kobj, struct device, kobj));
398 if (off > bin_attr->size)
400 else if (count > bin_attr->size - off)
401 count = bin_attr->size - off;
405 ret = dev->vpd->ops->write(dev, off, end - off, buf);
415 #ifdef HAVE_PCI_LEGACY
417 * pci_read_legacy_io - read byte(s) from legacy I/O port space
418 * @kobj: kobject corresponding to file to read from
419 * @buf: buffer to store results
420 * @off: offset into legacy I/O port space
421 * @count: number of bytes to read
423 * Reads 1, 2, or 4 bytes from legacy I/O port space using an arch specific
424 * callback routine (pci_legacy_read).
427 pci_read_legacy_io(struct kobject *kobj, struct bin_attribute *bin_attr,
428 char *buf, loff_t off, size_t count)
430 struct pci_bus *bus = to_pci_bus(container_of(kobj,
434 /* Only support 1, 2 or 4 byte accesses */
435 if (count != 1 && count != 2 && count != 4)
438 return pci_legacy_read(bus, off, (u32 *)buf, count);
442 * pci_write_legacy_io - write byte(s) to legacy I/O port space
443 * @kobj: kobject corresponding to file to read from
444 * @buf: buffer containing value to be written
445 * @off: offset into legacy I/O port space
446 * @count: number of bytes to write
448 * Writes 1, 2, or 4 bytes from legacy I/O port space using an arch specific
449 * callback routine (pci_legacy_write).
452 pci_write_legacy_io(struct kobject *kobj, struct bin_attribute *bin_attr,
453 char *buf, loff_t off, size_t count)
455 struct pci_bus *bus = to_pci_bus(container_of(kobj,
458 /* Only support 1, 2 or 4 byte accesses */
459 if (count != 1 && count != 2 && count != 4)
462 return pci_legacy_write(bus, off, *(u32 *)buf, count);
466 * pci_mmap_legacy_mem - map legacy PCI memory into user memory space
467 * @kobj: kobject corresponding to device to be mapped
468 * @attr: struct bin_attribute for this file
469 * @vma: struct vm_area_struct passed to mmap
471 * Uses an arch specific callback, pci_mmap_legacy_mem_page_range, to mmap
472 * legacy memory space (first meg of bus space) into application virtual
476 pci_mmap_legacy_mem(struct kobject *kobj, struct bin_attribute *attr,
477 struct vm_area_struct *vma)
479 struct pci_bus *bus = to_pci_bus(container_of(kobj,
483 return pci_mmap_legacy_page_range(bus, vma, pci_mmap_mem);
487 * pci_mmap_legacy_io - map legacy PCI IO into user memory space
488 * @kobj: kobject corresponding to device to be mapped
489 * @attr: struct bin_attribute for this file
490 * @vma: struct vm_area_struct passed to mmap
492 * Uses an arch specific callback, pci_mmap_legacy_io_page_range, to mmap
493 * legacy IO space (first meg of bus space) into application virtual
494 * memory space. Returns -ENOSYS if the operation isn't supported
497 pci_mmap_legacy_io(struct kobject *kobj, struct bin_attribute *attr,
498 struct vm_area_struct *vma)
500 struct pci_bus *bus = to_pci_bus(container_of(kobj,
504 return pci_mmap_legacy_page_range(bus, vma, pci_mmap_io);
508 * pci_create_legacy_files - create legacy I/O port and memory files
509 * @b: bus to create files under
511 * Some platforms allow access to legacy I/O port and ISA memory space on
512 * a per-bus basis. This routine creates the files and ties them into
513 * their associated read, write and mmap files from pci-sysfs.c
515 * On error unwind, but don't propogate the error to the caller
516 * as it is ok to set up the PCI bus without these files.
518 void pci_create_legacy_files(struct pci_bus *b)
522 b->legacy_io = kzalloc(sizeof(struct bin_attribute) * 2,
527 b->legacy_io->attr.name = "legacy_io";
528 b->legacy_io->size = 0xffff;
529 b->legacy_io->attr.mode = S_IRUSR | S_IWUSR;
530 b->legacy_io->read = pci_read_legacy_io;
531 b->legacy_io->write = pci_write_legacy_io;
532 b->legacy_io->mmap = pci_mmap_legacy_io;
533 error = device_create_bin_file(&b->dev, b->legacy_io);
537 /* Allocated above after the legacy_io struct */
538 b->legacy_mem = b->legacy_io + 1;
539 b->legacy_mem->attr.name = "legacy_mem";
540 b->legacy_mem->size = 1024*1024;
541 b->legacy_mem->attr.mode = S_IRUSR | S_IWUSR;
542 b->legacy_mem->mmap = pci_mmap_legacy_mem;
543 error = device_create_bin_file(&b->dev, b->legacy_mem);
550 device_remove_bin_file(&b->dev, b->legacy_io);
555 printk(KERN_WARNING "pci: warning: could not create legacy I/O port "
556 "and ISA memory resources to sysfs\n");
560 void pci_remove_legacy_files(struct pci_bus *b)
563 device_remove_bin_file(&b->dev, b->legacy_io);
564 device_remove_bin_file(&b->dev, b->legacy_mem);
565 kfree(b->legacy_io); /* both are allocated here */
568 #endif /* HAVE_PCI_LEGACY */
572 int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vma)
574 unsigned long nr, start, size;
576 nr = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
577 start = vma->vm_pgoff;
578 size = ((pci_resource_len(pdev, resno) - 1) >> PAGE_SHIFT) + 1;
579 if (start < size && size - start >= nr)
581 WARN(1, "process \"%s\" tried to map 0x%08lx-0x%08lx on %s BAR %d (size 0x%08lx)\n",
582 current->comm, start, start+nr, pci_name(pdev), resno, size);
587 * pci_mmap_resource - map a PCI resource into user memory space
588 * @kobj: kobject for mapping
589 * @attr: struct bin_attribute for the file being mapped
590 * @vma: struct vm_area_struct passed into the mmap
591 * @write_combine: 1 for write_combine mapping
593 * Use the regular PCI mapping routines to map a PCI resource into userspace.
596 pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr,
597 struct vm_area_struct *vma, int write_combine)
599 struct pci_dev *pdev = to_pci_dev(container_of(kobj,
600 struct device, kobj));
601 struct resource *res = (struct resource *)attr->private;
602 enum pci_mmap_state mmap_type;
603 resource_size_t start, end;
606 for (i = 0; i < PCI_ROM_RESOURCE; i++)
607 if (res == &pdev->resource[i])
609 if (i >= PCI_ROM_RESOURCE)
612 if (!pci_mmap_fits(pdev, i, vma))
615 /* pci_mmap_page_range() expects the same kind of entry as coming
616 * from /proc/bus/pci/ which is a "user visible" value. If this is
617 * different from the resource itself, arch will do necessary fixup.
619 pci_resource_to_user(pdev, i, res, &start, &end);
620 vma->vm_pgoff += start >> PAGE_SHIFT;
621 mmap_type = res->flags & IORESOURCE_MEM ? pci_mmap_mem : pci_mmap_io;
623 if (res->flags & IORESOURCE_MEM && iomem_is_exclusive(start))
626 return pci_mmap_page_range(pdev, vma, mmap_type, write_combine);
630 pci_mmap_resource_uc(struct kobject *kobj, struct bin_attribute *attr,
631 struct vm_area_struct *vma)
633 return pci_mmap_resource(kobj, attr, vma, 0);
637 pci_mmap_resource_wc(struct kobject *kobj, struct bin_attribute *attr,
638 struct vm_area_struct *vma)
640 return pci_mmap_resource(kobj, attr, vma, 1);
644 * pci_remove_resource_files - cleanup resource files
645 * @dev: dev to cleanup
647 * If we created resource files for @dev, remove them from sysfs and
648 * free their resources.
651 pci_remove_resource_files(struct pci_dev *pdev)
655 for (i = 0; i < PCI_ROM_RESOURCE; i++) {
656 struct bin_attribute *res_attr;
658 res_attr = pdev->res_attr[i];
660 sysfs_remove_bin_file(&pdev->dev.kobj, res_attr);
664 res_attr = pdev->res_attr_wc[i];
666 sysfs_remove_bin_file(&pdev->dev.kobj, res_attr);
672 static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
674 /* allocate attribute structure, piggyback attribute name */
675 int name_len = write_combine ? 13 : 10;
676 struct bin_attribute *res_attr;
679 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
681 char *res_attr_name = (char *)(res_attr + 1);
684 pdev->res_attr_wc[num] = res_attr;
685 sprintf(res_attr_name, "resource%d_wc", num);
686 res_attr->mmap = pci_mmap_resource_wc;
688 pdev->res_attr[num] = res_attr;
689 sprintf(res_attr_name, "resource%d", num);
690 res_attr->mmap = pci_mmap_resource_uc;
692 res_attr->attr.name = res_attr_name;
693 res_attr->attr.mode = S_IRUSR | S_IWUSR;
694 res_attr->size = pci_resource_len(pdev, num);
695 res_attr->private = &pdev->resource[num];
696 retval = sysfs_create_bin_file(&pdev->dev.kobj, res_attr);
704 * pci_create_resource_files - create resource files in sysfs for @dev
705 * @dev: dev in question
707 * Walk the resources in @dev creating files for each resource available.
709 static int pci_create_resource_files(struct pci_dev *pdev)
714 /* Expose the PCI resources from this device as files */
715 for (i = 0; i < PCI_ROM_RESOURCE; i++) {
717 /* skip empty resources */
718 if (!pci_resource_len(pdev, i))
721 retval = pci_create_attr(pdev, i, 0);
722 /* for prefetchable resources, create a WC mappable file */
723 if (!retval && pdev->resource[i].flags & IORESOURCE_PREFETCH)
724 retval = pci_create_attr(pdev, i, 1);
727 pci_remove_resource_files(pdev);
733 #else /* !HAVE_PCI_MMAP */
734 static inline int pci_create_resource_files(struct pci_dev *dev) { return 0; }
735 static inline void pci_remove_resource_files(struct pci_dev *dev) { return; }
736 #endif /* HAVE_PCI_MMAP */
739 * pci_write_rom - used to enable access to the PCI ROM display
740 * @kobj: kernel object handle
743 * @count: number of byte in input
745 * writing anything except 0 enables it
748 pci_write_rom(struct kobject *kobj, struct bin_attribute *bin_attr,
749 char *buf, loff_t off, size_t count)
751 struct pci_dev *pdev = to_pci_dev(container_of(kobj, struct device, kobj));
753 if ((off == 0) && (*buf == '0') && (count == 2))
754 pdev->rom_attr_enabled = 0;
756 pdev->rom_attr_enabled = 1;
762 * pci_read_rom - read a PCI ROM
763 * @kobj: kernel object handle
764 * @buf: where to put the data we read from the ROM
766 * @count: number of bytes to read
768 * Put @count bytes starting at @off into @buf from the ROM in the PCI
769 * device corresponding to @kobj.
772 pci_read_rom(struct kobject *kobj, struct bin_attribute *bin_attr,
773 char *buf, loff_t off, size_t count)
775 struct pci_dev *pdev = to_pci_dev(container_of(kobj, struct device, kobj));
779 if (!pdev->rom_attr_enabled)
782 rom = pci_map_rom(pdev, &size); /* size starts out as PCI window size */
789 if (off + count > size)
792 memcpy_fromio(buf, rom + off, count);
794 pci_unmap_rom(pdev, rom);
799 static struct bin_attribute pci_config_attr = {
802 .mode = S_IRUGO | S_IWUSR,
804 .size = PCI_CFG_SPACE_SIZE,
805 .read = pci_read_config,
806 .write = pci_write_config,
809 static struct bin_attribute pcie_config_attr = {
812 .mode = S_IRUGO | S_IWUSR,
814 .size = PCI_CFG_SPACE_EXP_SIZE,
815 .read = pci_read_config,
816 .write = pci_write_config,
819 int __attribute__ ((weak)) pcibios_add_platform_entries(struct pci_dev *dev)
824 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
827 struct bin_attribute *attr;
829 /* If the device has VPD, try to expose it in sysfs. */
831 attr = kzalloc(sizeof(*attr), GFP_ATOMIC);
835 attr->size = dev->vpd->len;
836 attr->attr.name = "vpd";
837 attr->attr.mode = S_IRUSR | S_IWUSR;
838 attr->read = pci_read_vpd;
839 attr->write = pci_write_vpd;
840 retval = sysfs_create_bin_file(&dev->dev.kobj, attr);
842 kfree(dev->vpd->attr);
845 dev->vpd->attr = attr;
848 /* Active State Power Management */
849 pcie_aspm_create_sysfs_dev_files(dev);
854 int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
858 struct bin_attribute *attr;
860 if (!sysfs_initialized)
863 if (pdev->cfg_size < PCI_CFG_SPACE_EXP_SIZE)
864 retval = sysfs_create_bin_file(&pdev->dev.kobj, &pci_config_attr);
866 retval = sysfs_create_bin_file(&pdev->dev.kobj, &pcie_config_attr);
870 retval = pci_create_resource_files(pdev);
872 goto err_config_file;
874 if (pci_resource_len(pdev, PCI_ROM_RESOURCE))
875 rom_size = pci_resource_len(pdev, PCI_ROM_RESOURCE);
876 else if (pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW)
879 /* If the device has a ROM, try to expose it in sysfs. */
881 attr = kzalloc(sizeof(*attr), GFP_ATOMIC);
884 goto err_resource_files;
886 attr->size = rom_size;
887 attr->attr.name = "rom";
888 attr->attr.mode = S_IRUSR;
889 attr->read = pci_read_rom;
890 attr->write = pci_write_rom;
891 retval = sysfs_create_bin_file(&pdev->dev.kobj, attr);
894 goto err_resource_files;
896 pdev->rom_attr = attr;
899 /* add platform-specific attributes */
900 retval = pcibios_add_platform_entries(pdev);
904 /* add sysfs entries for various capabilities */
905 retval = pci_create_capabilities_sysfs(pdev);
913 sysfs_remove_bin_file(&pdev->dev.kobj, pdev->rom_attr);
914 kfree(pdev->rom_attr);
915 pdev->rom_attr = NULL;
918 pci_remove_resource_files(pdev);
920 if (pdev->cfg_size < PCI_CFG_SPACE_EXP_SIZE)
921 sysfs_remove_bin_file(&pdev->dev.kobj, &pci_config_attr);
923 sysfs_remove_bin_file(&pdev->dev.kobj, &pcie_config_attr);
928 static void pci_remove_capabilities_sysfs(struct pci_dev *dev)
930 if (dev->vpd && dev->vpd->attr) {
931 sysfs_remove_bin_file(&dev->dev.kobj, dev->vpd->attr);
932 kfree(dev->vpd->attr);
935 pcie_aspm_remove_sysfs_dev_files(dev);
939 * pci_remove_sysfs_dev_files - cleanup PCI specific sysfs files
940 * @pdev: device whose entries we should free
942 * Cleanup when @pdev is removed from sysfs.
944 void pci_remove_sysfs_dev_files(struct pci_dev *pdev)
948 if (!sysfs_initialized)
951 pci_remove_capabilities_sysfs(pdev);
953 if (pdev->cfg_size < PCI_CFG_SPACE_EXP_SIZE)
954 sysfs_remove_bin_file(&pdev->dev.kobj, &pci_config_attr);
956 sysfs_remove_bin_file(&pdev->dev.kobj, &pcie_config_attr);
958 pci_remove_resource_files(pdev);
960 if (pci_resource_len(pdev, PCI_ROM_RESOURCE))
961 rom_size = pci_resource_len(pdev, PCI_ROM_RESOURCE);
962 else if (pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW)
965 if (rom_size && pdev->rom_attr) {
966 sysfs_remove_bin_file(&pdev->dev.kobj, pdev->rom_attr);
967 kfree(pdev->rom_attr);
971 static int __init pci_sysfs_init(void)
973 struct pci_dev *pdev = NULL;
976 sysfs_initialized = 1;
977 for_each_pci_dev(pdev) {
978 retval = pci_create_sysfs_dev_files(pdev);
988 late_initcall(pci_sysfs_init);