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);
63 if (strict_strtoul(buf, 0, &val) < 0)
66 pdev->broken_parity_status = !!val;
71 static ssize_t local_cpus_show(struct device *dev,
72 struct device_attribute *attr, char *buf)
77 mask = pcibus_to_cpumask(to_pci_dev(dev)->bus);
78 len = cpumask_scnprintf(buf, PAGE_SIZE-2, &mask);
85 static ssize_t local_cpulist_show(struct device *dev,
86 struct device_attribute *attr, char *buf)
91 mask = pcibus_to_cpumask(to_pci_dev(dev)->bus);
92 len = cpulist_scnprintf(buf, PAGE_SIZE-2, &mask);
100 resource_show(struct device * dev, struct device_attribute *attr, char * buf)
102 struct pci_dev * pci_dev = to_pci_dev(dev);
106 resource_size_t start, end;
108 if (pci_dev->subordinate)
109 max = DEVICE_COUNT_RESOURCE;
111 for (i = 0; i < max; i++) {
112 struct resource *res = &pci_dev->resource[i];
113 pci_resource_to_user(pci_dev, i, res, &start, &end);
114 str += sprintf(str,"0x%016llx 0x%016llx 0x%016llx\n",
115 (unsigned long long)start,
116 (unsigned long long)end,
117 (unsigned long long)res->flags);
122 static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf)
124 struct pci_dev *pci_dev = to_pci_dev(dev);
126 return sprintf(buf, "pci:v%08Xd%08Xsv%08Xsd%08Xbc%02Xsc%02Xi%02x\n",
127 pci_dev->vendor, pci_dev->device,
128 pci_dev->subsystem_vendor, pci_dev->subsystem_device,
129 (u8)(pci_dev->class >> 16), (u8)(pci_dev->class >> 8),
130 (u8)(pci_dev->class));
133 static ssize_t is_enabled_store(struct device *dev,
134 struct device_attribute *attr, const char *buf,
137 struct pci_dev *pdev = to_pci_dev(dev);
139 ssize_t result = strict_strtoul(buf, 0, &val);
144 /* this can crash the machine when done on the "wrong" device */
145 if (!capable(CAP_SYS_ADMIN))
149 if (atomic_read(&pdev->enable_cnt) != 0)
150 pci_disable_device(pdev);
154 result = pci_enable_device(pdev);
156 return result < 0 ? result : count;
159 static ssize_t is_enabled_show(struct device *dev,
160 struct device_attribute *attr, char *buf)
162 struct pci_dev *pdev;
164 pdev = to_pci_dev (dev);
165 return sprintf (buf, "%u\n", atomic_read(&pdev->enable_cnt));
170 numa_node_show(struct device *dev, struct device_attribute *attr, char *buf)
172 return sprintf (buf, "%d\n", dev->numa_node);
177 msi_bus_show(struct device *dev, struct device_attribute *attr, char *buf)
179 struct pci_dev *pdev = to_pci_dev(dev);
181 if (!pdev->subordinate)
184 return sprintf (buf, "%u\n",
185 !(pdev->subordinate->bus_flags & PCI_BUS_FLAGS_NO_MSI));
189 msi_bus_store(struct device *dev, struct device_attribute *attr,
190 const char *buf, size_t count)
192 struct pci_dev *pdev = to_pci_dev(dev);
195 if (strict_strtoul(buf, 0, &val) < 0)
198 /* bad things may happen if the no_msi flag is changed
199 * while some drivers are loaded */
200 if (!capable(CAP_SYS_ADMIN))
203 /* Maybe pci devices without subordinate busses shouldn't even have this
204 * attribute in the first place? */
205 if (!pdev->subordinate)
208 /* Is the flag going to change, or keep the value it already had? */
209 if (!(pdev->subordinate->bus_flags & PCI_BUS_FLAGS_NO_MSI) ^
211 pdev->subordinate->bus_flags ^= PCI_BUS_FLAGS_NO_MSI;
213 dev_warn(&pdev->dev, "forced subordinate bus to%s support MSI,"
214 " bad things could happen\n", val ? "" : " not");
220 struct device_attribute pci_dev_attrs[] = {
224 __ATTR_RO(subsystem_vendor),
225 __ATTR_RO(subsystem_device),
228 __ATTR_RO(local_cpus),
229 __ATTR_RO(local_cpulist),
232 __ATTR_RO(numa_node),
234 __ATTR(enable, 0600, is_enabled_show, is_enabled_store),
235 __ATTR(broken_parity_status,(S_IRUGO|S_IWUSR),
236 broken_parity_status_show,broken_parity_status_store),
237 __ATTR(msi_bus, 0644, msi_bus_show, msi_bus_store),
242 pci_read_config(struct kobject *kobj, struct bin_attribute *bin_attr,
243 char *buf, loff_t off, size_t count)
245 struct pci_dev *dev = to_pci_dev(container_of(kobj,struct device,kobj));
246 unsigned int size = 64;
247 loff_t init_off = off;
248 u8 *data = (u8*) buf;
250 /* Several chips lock up trying to read undefined config space */
251 if (capable(CAP_SYS_ADMIN)) {
252 size = dev->cfg_size;
253 } else if (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) {
259 if (off + count > size) {
266 if ((off & 1) && size) {
268 pci_user_read_config_byte(dev, off, &val);
269 data[off - init_off] = val;
274 if ((off & 3) && size > 2) {
276 pci_user_read_config_word(dev, off, &val);
277 data[off - init_off] = val & 0xff;
278 data[off - init_off + 1] = (val >> 8) & 0xff;
285 pci_user_read_config_dword(dev, off, &val);
286 data[off - init_off] = val & 0xff;
287 data[off - init_off + 1] = (val >> 8) & 0xff;
288 data[off - init_off + 2] = (val >> 16) & 0xff;
289 data[off - init_off + 3] = (val >> 24) & 0xff;
296 pci_user_read_config_word(dev, off, &val);
297 data[off - init_off] = val & 0xff;
298 data[off - init_off + 1] = (val >> 8) & 0xff;
305 pci_user_read_config_byte(dev, off, &val);
306 data[off - init_off] = val;
315 pci_write_config(struct kobject *kobj, struct bin_attribute *bin_attr,
316 char *buf, loff_t off, size_t count)
318 struct pci_dev *dev = to_pci_dev(container_of(kobj,struct device,kobj));
319 unsigned int size = count;
320 loff_t init_off = off;
321 u8 *data = (u8*) buf;
323 if (off > dev->cfg_size)
325 if (off + count > dev->cfg_size) {
326 size = dev->cfg_size - off;
330 if ((off & 1) && size) {
331 pci_user_write_config_byte(dev, off, data[off - init_off]);
336 if ((off & 3) && size > 2) {
337 u16 val = data[off - init_off];
338 val |= (u16) data[off - init_off + 1] << 8;
339 pci_user_write_config_word(dev, off, val);
345 u32 val = data[off - init_off];
346 val |= (u32) data[off - init_off + 1] << 8;
347 val |= (u32) data[off - init_off + 2] << 16;
348 val |= (u32) data[off - init_off + 3] << 24;
349 pci_user_write_config_dword(dev, off, val);
355 u16 val = data[off - init_off];
356 val |= (u16) data[off - init_off + 1] << 8;
357 pci_user_write_config_word(dev, off, val);
363 pci_user_write_config_byte(dev, off, data[off - init_off]);
372 pci_read_vpd(struct kobject *kobj, struct bin_attribute *bin_attr,
373 char *buf, loff_t off, size_t count)
375 struct pci_dev *dev =
376 to_pci_dev(container_of(kobj, struct device, kobj));
380 if (off > bin_attr->size)
382 else if (count > bin_attr->size - off)
383 count = bin_attr->size - off;
387 ret = dev->vpd->ops->read(dev, off, end - off, buf);
398 pci_write_vpd(struct kobject *kobj, struct bin_attribute *bin_attr,
399 char *buf, loff_t off, size_t count)
401 struct pci_dev *dev =
402 to_pci_dev(container_of(kobj, struct device, kobj));
406 if (off > bin_attr->size)
408 else if (count > bin_attr->size - off)
409 count = bin_attr->size - off;
413 ret = dev->vpd->ops->write(dev, off, end - off, buf);
423 #ifdef HAVE_PCI_LEGACY
425 * pci_read_legacy_io - read byte(s) from legacy I/O port space
426 * @kobj: kobject corresponding to file to read from
427 * @buf: buffer to store results
428 * @off: offset into legacy I/O port space
429 * @count: number of bytes to read
431 * Reads 1, 2, or 4 bytes from legacy I/O port space using an arch specific
432 * callback routine (pci_legacy_read).
435 pci_read_legacy_io(struct kobject *kobj, struct bin_attribute *bin_attr,
436 char *buf, loff_t off, size_t count)
438 struct pci_bus *bus = to_pci_bus(container_of(kobj,
442 /* Only support 1, 2 or 4 byte accesses */
443 if (count != 1 && count != 2 && count != 4)
446 return pci_legacy_read(bus, off, (u32 *)buf, count);
450 * pci_write_legacy_io - write byte(s) to legacy I/O port space
451 * @kobj: kobject corresponding to file to read from
452 * @buf: buffer containing value to be written
453 * @off: offset into legacy I/O port space
454 * @count: number of bytes to write
456 * Writes 1, 2, or 4 bytes from legacy I/O port space using an arch specific
457 * callback routine (pci_legacy_write).
460 pci_write_legacy_io(struct kobject *kobj, struct bin_attribute *bin_attr,
461 char *buf, loff_t off, size_t count)
463 struct pci_bus *bus = to_pci_bus(container_of(kobj,
466 /* Only support 1, 2 or 4 byte accesses */
467 if (count != 1 && count != 2 && count != 4)
470 return pci_legacy_write(bus, off, *(u32 *)buf, count);
474 * pci_mmap_legacy_mem - map legacy PCI memory into user memory space
475 * @kobj: kobject corresponding to device to be mapped
476 * @attr: struct bin_attribute for this file
477 * @vma: struct vm_area_struct passed to mmap
479 * Uses an arch specific callback, pci_mmap_legacy_mem_page_range, to mmap
480 * legacy memory space (first meg of bus space) into application virtual
484 pci_mmap_legacy_mem(struct kobject *kobj, struct bin_attribute *attr,
485 struct vm_area_struct *vma)
487 struct pci_bus *bus = to_pci_bus(container_of(kobj,
491 return pci_mmap_legacy_page_range(bus, vma, pci_mmap_mem);
495 * pci_mmap_legacy_io - map legacy PCI IO into user memory space
496 * @kobj: kobject corresponding to device to be mapped
497 * @attr: struct bin_attribute for this file
498 * @vma: struct vm_area_struct passed to mmap
500 * Uses an arch specific callback, pci_mmap_legacy_io_page_range, to mmap
501 * legacy IO space (first meg of bus space) into application virtual
502 * memory space. Returns -ENOSYS if the operation isn't supported
505 pci_mmap_legacy_io(struct kobject *kobj, struct bin_attribute *attr,
506 struct vm_area_struct *vma)
508 struct pci_bus *bus = to_pci_bus(container_of(kobj,
512 return pci_mmap_legacy_page_range(bus, vma, pci_mmap_io);
516 * pci_create_legacy_files - create legacy I/O port and memory files
517 * @b: bus to create files under
519 * Some platforms allow access to legacy I/O port and ISA memory space on
520 * a per-bus basis. This routine creates the files and ties them into
521 * their associated read, write and mmap files from pci-sysfs.c
523 * On error unwind, but don't propogate the error to the caller
524 * as it is ok to set up the PCI bus without these files.
526 void pci_create_legacy_files(struct pci_bus *b)
530 b->legacy_io = kzalloc(sizeof(struct bin_attribute) * 2,
535 b->legacy_io->attr.name = "legacy_io";
536 b->legacy_io->size = 0xffff;
537 b->legacy_io->attr.mode = S_IRUSR | S_IWUSR;
538 b->legacy_io->read = pci_read_legacy_io;
539 b->legacy_io->write = pci_write_legacy_io;
540 b->legacy_io->mmap = pci_mmap_legacy_io;
541 error = device_create_bin_file(&b->dev, b->legacy_io);
545 /* Allocated above after the legacy_io struct */
546 b->legacy_mem = b->legacy_io + 1;
547 b->legacy_mem->attr.name = "legacy_mem";
548 b->legacy_mem->size = 1024*1024;
549 b->legacy_mem->attr.mode = S_IRUSR | S_IWUSR;
550 b->legacy_mem->mmap = pci_mmap_legacy_mem;
551 error = device_create_bin_file(&b->dev, b->legacy_mem);
558 device_remove_bin_file(&b->dev, b->legacy_io);
563 printk(KERN_WARNING "pci: warning: could not create legacy I/O port "
564 "and ISA memory resources to sysfs\n");
568 void pci_remove_legacy_files(struct pci_bus *b)
571 device_remove_bin_file(&b->dev, b->legacy_io);
572 device_remove_bin_file(&b->dev, b->legacy_mem);
573 kfree(b->legacy_io); /* both are allocated here */
576 #endif /* HAVE_PCI_LEGACY */
580 int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vma)
582 unsigned long nr, start, size;
584 nr = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
585 start = vma->vm_pgoff;
586 size = ((pci_resource_len(pdev, resno) - 1) >> PAGE_SHIFT) + 1;
587 if (start < size && size - start >= nr)
589 WARN(1, "process \"%s\" tried to map 0x%08lx-0x%08lx on %s BAR %d (size 0x%08lx)\n",
590 current->comm, start, start+nr, pci_name(pdev), resno, size);
595 * pci_mmap_resource - map a PCI resource into user memory space
596 * @kobj: kobject for mapping
597 * @attr: struct bin_attribute for the file being mapped
598 * @vma: struct vm_area_struct passed into the mmap
599 * @write_combine: 1 for write_combine mapping
601 * Use the regular PCI mapping routines to map a PCI resource into userspace.
604 pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr,
605 struct vm_area_struct *vma, int write_combine)
607 struct pci_dev *pdev = to_pci_dev(container_of(kobj,
608 struct device, kobj));
609 struct resource *res = (struct resource *)attr->private;
610 enum pci_mmap_state mmap_type;
611 resource_size_t start, end;
614 for (i = 0; i < PCI_ROM_RESOURCE; i++)
615 if (res == &pdev->resource[i])
617 if (i >= PCI_ROM_RESOURCE)
620 if (!pci_mmap_fits(pdev, i, vma))
623 /* pci_mmap_page_range() expects the same kind of entry as coming
624 * from /proc/bus/pci/ which is a "user visible" value. If this is
625 * different from the resource itself, arch will do necessary fixup.
627 pci_resource_to_user(pdev, i, res, &start, &end);
628 vma->vm_pgoff += start >> PAGE_SHIFT;
629 mmap_type = res->flags & IORESOURCE_MEM ? pci_mmap_mem : pci_mmap_io;
631 if (res->flags & IORESOURCE_MEM && iomem_is_exclusive(start))
634 return pci_mmap_page_range(pdev, vma, mmap_type, write_combine);
638 pci_mmap_resource_uc(struct kobject *kobj, struct bin_attribute *attr,
639 struct vm_area_struct *vma)
641 return pci_mmap_resource(kobj, attr, vma, 0);
645 pci_mmap_resource_wc(struct kobject *kobj, struct bin_attribute *attr,
646 struct vm_area_struct *vma)
648 return pci_mmap_resource(kobj, attr, vma, 1);
652 * pci_remove_resource_files - cleanup resource files
653 * @dev: dev to cleanup
655 * If we created resource files for @dev, remove them from sysfs and
656 * free their resources.
659 pci_remove_resource_files(struct pci_dev *pdev)
663 for (i = 0; i < PCI_ROM_RESOURCE; i++) {
664 struct bin_attribute *res_attr;
666 res_attr = pdev->res_attr[i];
668 sysfs_remove_bin_file(&pdev->dev.kobj, res_attr);
672 res_attr = pdev->res_attr_wc[i];
674 sysfs_remove_bin_file(&pdev->dev.kobj, res_attr);
680 static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
682 /* allocate attribute structure, piggyback attribute name */
683 int name_len = write_combine ? 13 : 10;
684 struct bin_attribute *res_attr;
687 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
689 char *res_attr_name = (char *)(res_attr + 1);
692 pdev->res_attr_wc[num] = res_attr;
693 sprintf(res_attr_name, "resource%d_wc", num);
694 res_attr->mmap = pci_mmap_resource_wc;
696 pdev->res_attr[num] = res_attr;
697 sprintf(res_attr_name, "resource%d", num);
698 res_attr->mmap = pci_mmap_resource_uc;
700 res_attr->attr.name = res_attr_name;
701 res_attr->attr.mode = S_IRUSR | S_IWUSR;
702 res_attr->size = pci_resource_len(pdev, num);
703 res_attr->private = &pdev->resource[num];
704 retval = sysfs_create_bin_file(&pdev->dev.kobj, res_attr);
712 * pci_create_resource_files - create resource files in sysfs for @dev
713 * @dev: dev in question
715 * Walk the resources in @dev creating files for each resource available.
717 static int pci_create_resource_files(struct pci_dev *pdev)
722 /* Expose the PCI resources from this device as files */
723 for (i = 0; i < PCI_ROM_RESOURCE; i++) {
725 /* skip empty resources */
726 if (!pci_resource_len(pdev, i))
729 retval = pci_create_attr(pdev, i, 0);
730 /* for prefetchable resources, create a WC mappable file */
731 if (!retval && pdev->resource[i].flags & IORESOURCE_PREFETCH)
732 retval = pci_create_attr(pdev, i, 1);
735 pci_remove_resource_files(pdev);
741 #else /* !HAVE_PCI_MMAP */
742 static inline int pci_create_resource_files(struct pci_dev *dev) { return 0; }
743 static inline void pci_remove_resource_files(struct pci_dev *dev) { return; }
744 #endif /* HAVE_PCI_MMAP */
747 * pci_write_rom - used to enable access to the PCI ROM display
748 * @kobj: kernel object handle
751 * @count: number of byte in input
753 * writing anything except 0 enables it
756 pci_write_rom(struct kobject *kobj, struct bin_attribute *bin_attr,
757 char *buf, loff_t off, size_t count)
759 struct pci_dev *pdev = to_pci_dev(container_of(kobj, struct device, kobj));
761 if ((off == 0) && (*buf == '0') && (count == 2))
762 pdev->rom_attr_enabled = 0;
764 pdev->rom_attr_enabled = 1;
770 * pci_read_rom - read a PCI ROM
771 * @kobj: kernel object handle
772 * @buf: where to put the data we read from the ROM
774 * @count: number of bytes to read
776 * Put @count bytes starting at @off into @buf from the ROM in the PCI
777 * device corresponding to @kobj.
780 pci_read_rom(struct kobject *kobj, struct bin_attribute *bin_attr,
781 char *buf, loff_t off, size_t count)
783 struct pci_dev *pdev = to_pci_dev(container_of(kobj, struct device, kobj));
787 if (!pdev->rom_attr_enabled)
790 rom = pci_map_rom(pdev, &size); /* size starts out as PCI window size */
797 if (off + count > size)
800 memcpy_fromio(buf, rom + off, count);
802 pci_unmap_rom(pdev, rom);
807 static struct bin_attribute pci_config_attr = {
810 .mode = S_IRUGO | S_IWUSR,
812 .size = PCI_CFG_SPACE_SIZE,
813 .read = pci_read_config,
814 .write = pci_write_config,
817 static struct bin_attribute pcie_config_attr = {
820 .mode = S_IRUGO | S_IWUSR,
822 .size = PCI_CFG_SPACE_EXP_SIZE,
823 .read = pci_read_config,
824 .write = pci_write_config,
827 int __attribute__ ((weak)) pcibios_add_platform_entries(struct pci_dev *dev)
832 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
835 struct bin_attribute *attr;
837 /* If the device has VPD, try to expose it in sysfs. */
839 attr = kzalloc(sizeof(*attr), GFP_ATOMIC);
843 attr->size = dev->vpd->len;
844 attr->attr.name = "vpd";
845 attr->attr.mode = S_IRUSR | S_IWUSR;
846 attr->read = pci_read_vpd;
847 attr->write = pci_write_vpd;
848 retval = sysfs_create_bin_file(&dev->dev.kobj, attr);
850 kfree(dev->vpd->attr);
853 dev->vpd->attr = attr;
856 /* Active State Power Management */
857 pcie_aspm_create_sysfs_dev_files(dev);
862 int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
866 struct bin_attribute *attr;
868 if (!sysfs_initialized)
871 if (pdev->cfg_size < PCI_CFG_SPACE_EXP_SIZE)
872 retval = sysfs_create_bin_file(&pdev->dev.kobj, &pci_config_attr);
874 retval = sysfs_create_bin_file(&pdev->dev.kobj, &pcie_config_attr);
878 retval = pci_create_resource_files(pdev);
880 goto err_config_file;
882 if (pci_resource_len(pdev, PCI_ROM_RESOURCE))
883 rom_size = pci_resource_len(pdev, PCI_ROM_RESOURCE);
884 else if (pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW)
887 /* If the device has a ROM, try to expose it in sysfs. */
889 attr = kzalloc(sizeof(*attr), GFP_ATOMIC);
892 goto err_resource_files;
894 attr->size = rom_size;
895 attr->attr.name = "rom";
896 attr->attr.mode = S_IRUSR;
897 attr->read = pci_read_rom;
898 attr->write = pci_write_rom;
899 retval = sysfs_create_bin_file(&pdev->dev.kobj, attr);
902 goto err_resource_files;
904 pdev->rom_attr = attr;
907 /* add platform-specific attributes */
908 retval = pcibios_add_platform_entries(pdev);
912 /* add sysfs entries for various capabilities */
913 retval = pci_create_capabilities_sysfs(pdev);
921 sysfs_remove_bin_file(&pdev->dev.kobj, pdev->rom_attr);
922 kfree(pdev->rom_attr);
923 pdev->rom_attr = NULL;
926 pci_remove_resource_files(pdev);
928 if (pdev->cfg_size < PCI_CFG_SPACE_EXP_SIZE)
929 sysfs_remove_bin_file(&pdev->dev.kobj, &pci_config_attr);
931 sysfs_remove_bin_file(&pdev->dev.kobj, &pcie_config_attr);
936 static void pci_remove_capabilities_sysfs(struct pci_dev *dev)
938 if (dev->vpd && dev->vpd->attr) {
939 sysfs_remove_bin_file(&dev->dev.kobj, dev->vpd->attr);
940 kfree(dev->vpd->attr);
943 pcie_aspm_remove_sysfs_dev_files(dev);
947 * pci_remove_sysfs_dev_files - cleanup PCI specific sysfs files
948 * @pdev: device whose entries we should free
950 * Cleanup when @pdev is removed from sysfs.
952 void pci_remove_sysfs_dev_files(struct pci_dev *pdev)
956 if (!sysfs_initialized)
959 pci_remove_capabilities_sysfs(pdev);
961 if (pdev->cfg_size < PCI_CFG_SPACE_EXP_SIZE)
962 sysfs_remove_bin_file(&pdev->dev.kobj, &pci_config_attr);
964 sysfs_remove_bin_file(&pdev->dev.kobj, &pcie_config_attr);
966 pci_remove_resource_files(pdev);
968 if (pci_resource_len(pdev, PCI_ROM_RESOURCE))
969 rom_size = pci_resource_len(pdev, PCI_ROM_RESOURCE);
970 else if (pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW)
973 if (rom_size && pdev->rom_attr) {
974 sysfs_remove_bin_file(&pdev->dev.kobj, pdev->rom_attr);
975 kfree(pdev->rom_attr);
979 static int __init pci_sysfs_init(void)
981 struct pci_dev *pdev = NULL;
984 sysfs_initialized = 1;
985 for_each_pci_dev(pdev) {
986 retval = pci_create_sysfs_dev_files(pdev);
996 late_initcall(pci_sysfs_init);