Merge branch 'irq-cleanups-upstream' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6] / drivers / pci / pci-sysfs.c
1 /*
2  * drivers/pci/pci-sysfs.c
3  *
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>
10  *
11  * File attributes for PCI devices
12  *
13  * Modeled after usb's driverfs.c 
14  *
15  */
16
17
18 #include <linux/kernel.h>
19 #include <linux/pci.h>
20 #include <linux/stat.h>
21 #include <linux/topology.h>
22 #include <linux/mm.h>
23 #include <linux/capability.h>
24 #include "pci.h"
25
26 static int sysfs_initialized;   /* = 0 */
27
28 /* show configuration fields */
29 #define pci_config_attr(field, format_string)                           \
30 static ssize_t                                                          \
31 field##_show(struct device *dev, struct device_attribute *attr, char *buf)                              \
32 {                                                                       \
33         struct pci_dev *pdev;                                           \
34                                                                         \
35         pdev = to_pci_dev (dev);                                        \
36         return sprintf (buf, format_string, pdev->field);               \
37 }
38
39 pci_config_attr(vendor, "0x%04x\n");
40 pci_config_attr(device, "0x%04x\n");
41 pci_config_attr(subsystem_vendor, "0x%04x\n");
42 pci_config_attr(subsystem_device, "0x%04x\n");
43 pci_config_attr(class, "0x%06x\n");
44 pci_config_attr(irq, "%u\n");
45
46 static ssize_t broken_parity_status_show(struct device *dev,
47                                          struct device_attribute *attr,
48                                          char *buf)
49 {
50         struct pci_dev *pdev = to_pci_dev(dev);
51         return sprintf (buf, "%u\n", pdev->broken_parity_status);
52 }
53
54 static ssize_t broken_parity_status_store(struct device *dev,
55                                           struct device_attribute *attr,
56                                           const char *buf, size_t count)
57 {
58         struct pci_dev *pdev = to_pci_dev(dev);
59         ssize_t consumed = -EINVAL;
60
61         if ((count > 0) && (*buf == '0' || *buf == '1')) {
62                 pdev->broken_parity_status = *buf == '1' ? 1 : 0;
63                 consumed = count;
64         }
65         return consumed;
66 }
67
68 static ssize_t local_cpus_show(struct device *dev,
69                         struct device_attribute *attr, char *buf)
70 {               
71         cpumask_t mask;
72         int len;
73
74         mask = pcibus_to_cpumask(to_pci_dev(dev)->bus);
75         len = cpumask_scnprintf(buf, PAGE_SIZE-2, mask);
76         buf[len++] = '\n';
77         buf[len] = '\0';
78         return len;
79 }
80
81
82 static ssize_t local_cpulist_show(struct device *dev,
83                         struct device_attribute *attr, char *buf)
84 {
85         cpumask_t mask;
86         int len;
87
88         mask = pcibus_to_cpumask(to_pci_dev(dev)->bus);
89         len = cpulist_scnprintf(buf, PAGE_SIZE-2, mask);
90         buf[len++] = '\n';
91         buf[len] = '\0';
92         return len;
93 }
94
95 /* show resources */
96 static ssize_t
97 resource_show(struct device * dev, struct device_attribute *attr, char * buf)
98 {
99         struct pci_dev * pci_dev = to_pci_dev(dev);
100         char * str = buf;
101         int i;
102         int max = 7;
103         resource_size_t start, end;
104
105         if (pci_dev->subordinate)
106                 max = DEVICE_COUNT_RESOURCE;
107
108         for (i = 0; i < max; i++) {
109                 struct resource *res =  &pci_dev->resource[i];
110                 pci_resource_to_user(pci_dev, i, res, &start, &end);
111                 str += sprintf(str,"0x%016llx 0x%016llx 0x%016llx\n",
112                                (unsigned long long)start,
113                                (unsigned long long)end,
114                                (unsigned long long)res->flags);
115         }
116         return (str - buf);
117 }
118
119 static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf)
120 {
121         struct pci_dev *pci_dev = to_pci_dev(dev);
122
123         return sprintf(buf, "pci:v%08Xd%08Xsv%08Xsd%08Xbc%02Xsc%02Xi%02x\n",
124                        pci_dev->vendor, pci_dev->device,
125                        pci_dev->subsystem_vendor, pci_dev->subsystem_device,
126                        (u8)(pci_dev->class >> 16), (u8)(pci_dev->class >> 8),
127                        (u8)(pci_dev->class));
128 }
129
130 static ssize_t is_enabled_store(struct device *dev,
131                                 struct device_attribute *attr, const char *buf,
132                                 size_t count)
133 {
134         ssize_t result = -EINVAL;
135         struct pci_dev *pdev = to_pci_dev(dev);
136
137         /* this can crash the machine when done on the "wrong" device */
138         if (!capable(CAP_SYS_ADMIN))
139                 return count;
140
141         if (*buf == '0') {
142                 if (atomic_read(&pdev->enable_cnt) != 0)
143                         pci_disable_device(pdev);
144                 else
145                         result = -EIO;
146         } else if (*buf == '1')
147                 result = pci_enable_device(pdev);
148
149         return result < 0 ? result : count;
150 }
151
152 static ssize_t is_enabled_show(struct device *dev,
153                                struct device_attribute *attr, char *buf)
154 {
155         struct pci_dev *pdev;
156
157         pdev = to_pci_dev (dev);
158         return sprintf (buf, "%u\n", atomic_read(&pdev->enable_cnt));
159 }
160
161 #ifdef CONFIG_NUMA
162 static ssize_t
163 numa_node_show(struct device *dev, struct device_attribute *attr, char *buf)
164 {
165         return sprintf (buf, "%d\n", dev->numa_node);
166 }
167 #endif
168
169 static ssize_t
170 msi_bus_show(struct device *dev, struct device_attribute *attr, char *buf)
171 {
172         struct pci_dev *pdev = to_pci_dev(dev);
173
174         if (!pdev->subordinate)
175                 return 0;
176
177         return sprintf (buf, "%u\n",
178                         !(pdev->subordinate->bus_flags & PCI_BUS_FLAGS_NO_MSI));
179 }
180
181 static ssize_t
182 msi_bus_store(struct device *dev, struct device_attribute *attr,
183               const char *buf, size_t count)
184 {
185         struct pci_dev *pdev = to_pci_dev(dev);
186
187         /* bad things may happen if the no_msi flag is changed
188          * while some drivers are loaded */
189         if (!capable(CAP_SYS_ADMIN))
190                 return count;
191
192         if (!pdev->subordinate)
193                 return count;
194
195         if (*buf == '0') {
196                 pdev->subordinate->bus_flags |= PCI_BUS_FLAGS_NO_MSI;
197                 dev_warn(&pdev->dev, "forced subordinate bus to not support MSI,"
198                          " bad things could happen.\n");
199         }
200
201         if (*buf == '1') {
202                 pdev->subordinate->bus_flags &= ~PCI_BUS_FLAGS_NO_MSI;
203                 dev_warn(&pdev->dev, "forced subordinate bus to support MSI,"
204                          " bad things could happen.\n");
205         }
206
207         return count;
208 }
209
210 struct device_attribute pci_dev_attrs[] = {
211         __ATTR_RO(resource),
212         __ATTR_RO(vendor),
213         __ATTR_RO(device),
214         __ATTR_RO(subsystem_vendor),
215         __ATTR_RO(subsystem_device),
216         __ATTR_RO(class),
217         __ATTR_RO(irq),
218         __ATTR_RO(local_cpus),
219         __ATTR_RO(local_cpulist),
220         __ATTR_RO(modalias),
221 #ifdef CONFIG_NUMA
222         __ATTR_RO(numa_node),
223 #endif
224         __ATTR(enable, 0600, is_enabled_show, is_enabled_store),
225         __ATTR(broken_parity_status,(S_IRUGO|S_IWUSR),
226                 broken_parity_status_show,broken_parity_status_store),
227         __ATTR(msi_bus, 0644, msi_bus_show, msi_bus_store),
228         __ATTR_NULL,
229 };
230
231 static ssize_t
232 pci_read_config(struct kobject *kobj, struct bin_attribute *bin_attr,
233                 char *buf, loff_t off, size_t count)
234 {
235         struct pci_dev *dev = to_pci_dev(container_of(kobj,struct device,kobj));
236         unsigned int size = 64;
237         loff_t init_off = off;
238         u8 *data = (u8*) buf;
239
240         /* Several chips lock up trying to read undefined config space */
241         if (capable(CAP_SYS_ADMIN)) {
242                 size = dev->cfg_size;
243         } else if (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) {
244                 size = 128;
245         }
246
247         if (off > size)
248                 return 0;
249         if (off + count > size) {
250                 size -= off;
251                 count = size;
252         } else {
253                 size = count;
254         }
255
256         if ((off & 1) && size) {
257                 u8 val;
258                 pci_user_read_config_byte(dev, off, &val);
259                 data[off - init_off] = val;
260                 off++;
261                 size--;
262         }
263
264         if ((off & 3) && size > 2) {
265                 u16 val;
266                 pci_user_read_config_word(dev, off, &val);
267                 data[off - init_off] = val & 0xff;
268                 data[off - init_off + 1] = (val >> 8) & 0xff;
269                 off += 2;
270                 size -= 2;
271         }
272
273         while (size > 3) {
274                 u32 val;
275                 pci_user_read_config_dword(dev, off, &val);
276                 data[off - init_off] = val & 0xff;
277                 data[off - init_off + 1] = (val >> 8) & 0xff;
278                 data[off - init_off + 2] = (val >> 16) & 0xff;
279                 data[off - init_off + 3] = (val >> 24) & 0xff;
280                 off += 4;
281                 size -= 4;
282         }
283
284         if (size >= 2) {
285                 u16 val;
286                 pci_user_read_config_word(dev, off, &val);
287                 data[off - init_off] = val & 0xff;
288                 data[off - init_off + 1] = (val >> 8) & 0xff;
289                 off += 2;
290                 size -= 2;
291         }
292
293         if (size > 0) {
294                 u8 val;
295                 pci_user_read_config_byte(dev, off, &val);
296                 data[off - init_off] = val;
297                 off++;
298                 --size;
299         }
300
301         return count;
302 }
303
304 static ssize_t
305 pci_write_config(struct kobject *kobj, struct bin_attribute *bin_attr,
306                  char *buf, loff_t off, size_t count)
307 {
308         struct pci_dev *dev = to_pci_dev(container_of(kobj,struct device,kobj));
309         unsigned int size = count;
310         loff_t init_off = off;
311         u8 *data = (u8*) buf;
312
313         if (off > dev->cfg_size)
314                 return 0;
315         if (off + count > dev->cfg_size) {
316                 size = dev->cfg_size - off;
317                 count = size;
318         }
319         
320         if ((off & 1) && size) {
321                 pci_user_write_config_byte(dev, off, data[off - init_off]);
322                 off++;
323                 size--;
324         }
325         
326         if ((off & 3) && size > 2) {
327                 u16 val = data[off - init_off];
328                 val |= (u16) data[off - init_off + 1] << 8;
329                 pci_user_write_config_word(dev, off, val);
330                 off += 2;
331                 size -= 2;
332         }
333
334         while (size > 3) {
335                 u32 val = data[off - init_off];
336                 val |= (u32) data[off - init_off + 1] << 8;
337                 val |= (u32) data[off - init_off + 2] << 16;
338                 val |= (u32) data[off - init_off + 3] << 24;
339                 pci_user_write_config_dword(dev, off, val);
340                 off += 4;
341                 size -= 4;
342         }
343         
344         if (size >= 2) {
345                 u16 val = data[off - init_off];
346                 val |= (u16) data[off - init_off + 1] << 8;
347                 pci_user_write_config_word(dev, off, val);
348                 off += 2;
349                 size -= 2;
350         }
351
352         if (size) {
353                 pci_user_write_config_byte(dev, off, data[off - init_off]);
354                 off++;
355                 --size;
356         }
357
358         return count;
359 }
360
361 #ifdef HAVE_PCI_LEGACY
362 /**
363  * pci_read_legacy_io - read byte(s) from legacy I/O port space
364  * @kobj: kobject corresponding to file to read from
365  * @buf: buffer to store results
366  * @off: offset into legacy I/O port space
367  * @count: number of bytes to read
368  *
369  * Reads 1, 2, or 4 bytes from legacy I/O port space using an arch specific
370  * callback routine (pci_legacy_read).
371  */
372 ssize_t
373 pci_read_legacy_io(struct kobject *kobj, struct bin_attribute *bin_attr,
374                    char *buf, loff_t off, size_t count)
375 {
376         struct pci_bus *bus = to_pci_bus(container_of(kobj,
377                                                       struct device,
378                                                       kobj));
379
380         /* Only support 1, 2 or 4 byte accesses */
381         if (count != 1 && count != 2 && count != 4)
382                 return -EINVAL;
383
384         return pci_legacy_read(bus, off, (u32 *)buf, count);
385 }
386
387 /**
388  * pci_write_legacy_io - write byte(s) to legacy I/O port space
389  * @kobj: kobject corresponding to file to read from
390  * @buf: buffer containing value to be written
391  * @off: offset into legacy I/O port space
392  * @count: number of bytes to write
393  *
394  * Writes 1, 2, or 4 bytes from legacy I/O port space using an arch specific
395  * callback routine (pci_legacy_write).
396  */
397 ssize_t
398 pci_write_legacy_io(struct kobject *kobj, struct bin_attribute *bin_attr,
399                     char *buf, loff_t off, size_t count)
400 {
401         struct pci_bus *bus = to_pci_bus(container_of(kobj,
402                                                       struct device,
403                                                       kobj));
404         /* Only support 1, 2 or 4 byte accesses */
405         if (count != 1 && count != 2 && count != 4)
406                 return -EINVAL;
407
408         return pci_legacy_write(bus, off, *(u32 *)buf, count);
409 }
410
411 /**
412  * pci_mmap_legacy_mem - map legacy PCI memory into user memory space
413  * @kobj: kobject corresponding to device to be mapped
414  * @attr: struct bin_attribute for this file
415  * @vma: struct vm_area_struct passed to mmap
416  *
417  * Uses an arch specific callback, pci_mmap_legacy_page_range, to mmap
418  * legacy memory space (first meg of bus space) into application virtual
419  * memory space.
420  */
421 int
422 pci_mmap_legacy_mem(struct kobject *kobj, struct bin_attribute *attr,
423                     struct vm_area_struct *vma)
424 {
425         struct pci_bus *bus = to_pci_bus(container_of(kobj,
426                                                       struct device,
427                                                       kobj));
428
429         return pci_mmap_legacy_page_range(bus, vma);
430 }
431 #endif /* HAVE_PCI_LEGACY */
432
433 #ifdef HAVE_PCI_MMAP
434 /**
435  * pci_mmap_resource - map a PCI resource into user memory space
436  * @kobj: kobject for mapping
437  * @attr: struct bin_attribute for the file being mapped
438  * @vma: struct vm_area_struct passed into the mmap
439  *
440  * Use the regular PCI mapping routines to map a PCI resource into userspace.
441  * FIXME: write combining?  maybe automatic for prefetchable regions?
442  */
443 static int
444 pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr,
445                   struct vm_area_struct *vma)
446 {
447         struct pci_dev *pdev = to_pci_dev(container_of(kobj,
448                                                        struct device, kobj));
449         struct resource *res = (struct resource *)attr->private;
450         enum pci_mmap_state mmap_type;
451         resource_size_t start, end;
452         int i;
453
454         for (i = 0; i < PCI_ROM_RESOURCE; i++)
455                 if (res == &pdev->resource[i])
456                         break;
457         if (i >= PCI_ROM_RESOURCE)
458                 return -ENODEV;
459
460         /* pci_mmap_page_range() expects the same kind of entry as coming
461          * from /proc/bus/pci/ which is a "user visible" value. If this is
462          * different from the resource itself, arch will do necessary fixup.
463          */
464         pci_resource_to_user(pdev, i, res, &start, &end);
465         vma->vm_pgoff += start >> PAGE_SHIFT;
466         mmap_type = res->flags & IORESOURCE_MEM ? pci_mmap_mem : pci_mmap_io;
467
468         return pci_mmap_page_range(pdev, vma, mmap_type, 0);
469 }
470
471 /**
472  * pci_remove_resource_files - cleanup resource files
473  * @dev: dev to cleanup
474  *
475  * If we created resource files for @dev, remove them from sysfs and
476  * free their resources.
477  */
478 static void
479 pci_remove_resource_files(struct pci_dev *pdev)
480 {
481         int i;
482
483         for (i = 0; i < PCI_ROM_RESOURCE; i++) {
484                 struct bin_attribute *res_attr;
485
486                 res_attr = pdev->res_attr[i];
487                 if (res_attr) {
488                         sysfs_remove_bin_file(&pdev->dev.kobj, res_attr);
489                         kfree(res_attr);
490                 }
491         }
492 }
493
494 /**
495  * pci_create_resource_files - create resource files in sysfs for @dev
496  * @dev: dev in question
497  *
498  * Walk the resources in @dev creating files for each resource available.
499  */
500 static int pci_create_resource_files(struct pci_dev *pdev)
501 {
502         int i;
503         int retval;
504
505         /* Expose the PCI resources from this device as files */
506         for (i = 0; i < PCI_ROM_RESOURCE; i++) {
507                 struct bin_attribute *res_attr;
508
509                 /* skip empty resources */
510                 if (!pci_resource_len(pdev, i))
511                         continue;
512
513                 /* allocate attribute structure, piggyback attribute name */
514                 res_attr = kzalloc(sizeof(*res_attr) + 10, GFP_ATOMIC);
515                 if (res_attr) {
516                         char *res_attr_name = (char *)(res_attr + 1);
517
518                         pdev->res_attr[i] = res_attr;
519                         sprintf(res_attr_name, "resource%d", i);
520                         res_attr->attr.name = res_attr_name;
521                         res_attr->attr.mode = S_IRUSR | S_IWUSR;
522                         res_attr->size = pci_resource_len(pdev, i);
523                         res_attr->mmap = pci_mmap_resource;
524                         res_attr->private = &pdev->resource[i];
525                         retval = sysfs_create_bin_file(&pdev->dev.kobj, res_attr);
526                         if (retval) {
527                                 pci_remove_resource_files(pdev);
528                                 return retval;
529                         }
530                 } else {
531                         return -ENOMEM;
532                 }
533         }
534         return 0;
535 }
536 #else /* !HAVE_PCI_MMAP */
537 static inline int pci_create_resource_files(struct pci_dev *dev) { return 0; }
538 static inline void pci_remove_resource_files(struct pci_dev *dev) { return; }
539 #endif /* HAVE_PCI_MMAP */
540
541 /**
542  * pci_write_rom - used to enable access to the PCI ROM display
543  * @kobj: kernel object handle
544  * @buf: user input
545  * @off: file offset
546  * @count: number of byte in input
547  *
548  * writing anything except 0 enables it
549  */
550 static ssize_t
551 pci_write_rom(struct kobject *kobj, struct bin_attribute *bin_attr,
552               char *buf, loff_t off, size_t count)
553 {
554         struct pci_dev *pdev = to_pci_dev(container_of(kobj, struct device, kobj));
555
556         if ((off ==  0) && (*buf == '0') && (count == 2))
557                 pdev->rom_attr_enabled = 0;
558         else
559                 pdev->rom_attr_enabled = 1;
560
561         return count;
562 }
563
564 /**
565  * pci_read_rom - read a PCI ROM
566  * @kobj: kernel object handle
567  * @buf: where to put the data we read from the ROM
568  * @off: file offset
569  * @count: number of bytes to read
570  *
571  * Put @count bytes starting at @off into @buf from the ROM in the PCI
572  * device corresponding to @kobj.
573  */
574 static ssize_t
575 pci_read_rom(struct kobject *kobj, struct bin_attribute *bin_attr,
576              char *buf, loff_t off, size_t count)
577 {
578         struct pci_dev *pdev = to_pci_dev(container_of(kobj, struct device, kobj));
579         void __iomem *rom;
580         size_t size;
581
582         if (!pdev->rom_attr_enabled)
583                 return -EINVAL;
584         
585         rom = pci_map_rom(pdev, &size); /* size starts out as PCI window size */
586         if (!rom)
587                 return 0;
588                 
589         if (off >= size)
590                 count = 0;
591         else {
592                 if (off + count > size)
593                         count = size - off;
594                 
595                 memcpy_fromio(buf, rom + off, count);
596         }
597         pci_unmap_rom(pdev, rom);
598                 
599         return count;
600 }
601
602 static struct bin_attribute pci_config_attr = {
603         .attr = {
604                 .name = "config",
605                 .mode = S_IRUGO | S_IWUSR,
606         },
607         .size = 256,
608         .read = pci_read_config,
609         .write = pci_write_config,
610 };
611
612 static struct bin_attribute pcie_config_attr = {
613         .attr = {
614                 .name = "config",
615                 .mode = S_IRUGO | S_IWUSR,
616         },
617         .size = 4096,
618         .read = pci_read_config,
619         .write = pci_write_config,
620 };
621
622 int __attribute__ ((weak)) pcibios_add_platform_entries(struct pci_dev *dev)
623 {
624         return 0;
625 }
626
627 int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
628 {
629         struct bin_attribute *rom_attr = NULL;
630         int retval;
631
632         if (!sysfs_initialized)
633                 return -EACCES;
634
635         if (pdev->cfg_size < 4096)
636                 retval = sysfs_create_bin_file(&pdev->dev.kobj, &pci_config_attr);
637         else
638                 retval = sysfs_create_bin_file(&pdev->dev.kobj, &pcie_config_attr);
639         if (retval)
640                 goto err;
641
642         retval = pci_create_resource_files(pdev);
643         if (retval)
644                 goto err_bin_file;
645
646         /* If the device has a ROM, try to expose it in sysfs. */
647         if (pci_resource_len(pdev, PCI_ROM_RESOURCE) ||
648             (pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW)) {
649                 rom_attr = kzalloc(sizeof(*rom_attr), GFP_ATOMIC);
650                 if (rom_attr) {
651                         pdev->rom_attr = rom_attr;
652                         rom_attr->size = pci_resource_len(pdev, PCI_ROM_RESOURCE);
653                         rom_attr->attr.name = "rom";
654                         rom_attr->attr.mode = S_IRUSR;
655                         rom_attr->read = pci_read_rom;
656                         rom_attr->write = pci_write_rom;
657                         retval = sysfs_create_bin_file(&pdev->dev.kobj, rom_attr);
658                         if (retval)
659                                 goto err_rom;
660                 } else {
661                         retval = -ENOMEM;
662                         goto err_resource_files;
663                 }
664         }
665         /* add platform-specific attributes */
666         if (pcibios_add_platform_entries(pdev))
667                 goto err_rom_file;
668
669         return 0;
670
671 err_rom_file:
672         if (pci_resource_len(pdev, PCI_ROM_RESOURCE))
673                 sysfs_remove_bin_file(&pdev->dev.kobj, rom_attr);
674 err_rom:
675         kfree(rom_attr);
676 err_resource_files:
677         pci_remove_resource_files(pdev);
678 err_bin_file:
679         if (pdev->cfg_size < 4096)
680                 sysfs_remove_bin_file(&pdev->dev.kobj, &pci_config_attr);
681         else
682                 sysfs_remove_bin_file(&pdev->dev.kobj, &pcie_config_attr);
683 err:
684         return retval;
685 }
686
687 /**
688  * pci_remove_sysfs_dev_files - cleanup PCI specific sysfs files
689  * @pdev: device whose entries we should free
690  *
691  * Cleanup when @pdev is removed from sysfs.
692  */
693 void pci_remove_sysfs_dev_files(struct pci_dev *pdev)
694 {
695         if (!sysfs_initialized)
696                 return;
697
698         if (pdev->cfg_size < 4096)
699                 sysfs_remove_bin_file(&pdev->dev.kobj, &pci_config_attr);
700         else
701                 sysfs_remove_bin_file(&pdev->dev.kobj, &pcie_config_attr);
702
703         pci_remove_resource_files(pdev);
704
705         if (pci_resource_len(pdev, PCI_ROM_RESOURCE)) {
706                 if (pdev->rom_attr) {
707                         sysfs_remove_bin_file(&pdev->dev.kobj, pdev->rom_attr);
708                         kfree(pdev->rom_attr);
709                 }
710         }
711 }
712
713 static int __init pci_sysfs_init(void)
714 {
715         struct pci_dev *pdev = NULL;
716         int retval;
717
718         sysfs_initialized = 1;
719         for_each_pci_dev(pdev) {
720                 retval = pci_create_sysfs_dev_files(pdev);
721                 if (retval) {
722                         pci_dev_put(pdev);
723                         return retval;
724                 }
725         }
726
727         return 0;
728 }
729
730 late_initcall(pci_sysfs_init);