Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/kernel.h> |
Linus Torvalds | b5ff7df | 2008-10-02 18:52:51 -0700 | [diff] [blame] | 19 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/pci.h> |
| 21 | #include <linux/stat.h> |
| 22 | #include <linux/topology.h> |
| 23 | #include <linux/mm.h> |
Alexey Dobriyan | aa0ac36 | 2007-07-15 23:40:39 -0700 | [diff] [blame] | 24 | #include <linux/capability.h> |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 25 | #include <linux/pci-aspm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include "pci.h" |
| 27 | |
| 28 | static int sysfs_initialized; /* = 0 */ |
| 29 | |
| 30 | /* show configuration fields */ |
| 31 | #define pci_config_attr(field, format_string) \ |
| 32 | static ssize_t \ |
Yani Ioannou | e404e27 | 2005-05-17 06:42:58 -0400 | [diff] [blame] | 33 | field##_show(struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | { \ |
| 35 | struct pci_dev *pdev; \ |
| 36 | \ |
| 37 | pdev = to_pci_dev (dev); \ |
| 38 | return sprintf (buf, format_string, pdev->field); \ |
| 39 | } |
| 40 | |
| 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"); |
| 47 | |
Doug Thompson | bdee9d9 | 2006-06-14 16:59:48 -0700 | [diff] [blame] | 48 | static ssize_t broken_parity_status_show(struct device *dev, |
| 49 | struct device_attribute *attr, |
| 50 | char *buf) |
| 51 | { |
| 52 | struct pci_dev *pdev = to_pci_dev(dev); |
| 53 | return sprintf (buf, "%u\n", pdev->broken_parity_status); |
| 54 | } |
| 55 | |
| 56 | static ssize_t broken_parity_status_store(struct device *dev, |
| 57 | struct device_attribute *attr, |
| 58 | const char *buf, size_t count) |
| 59 | { |
| 60 | struct pci_dev *pdev = to_pci_dev(dev); |
Trent Piepho | 92425a4 | 2008-11-30 17:10:12 -0800 | [diff] [blame] | 61 | unsigned long val; |
Doug Thompson | bdee9d9 | 2006-06-14 16:59:48 -0700 | [diff] [blame] | 62 | |
Trent Piepho | 92425a4 | 2008-11-30 17:10:12 -0800 | [diff] [blame] | 63 | if (strict_strtoul(buf, 0, &val) < 0) |
| 64 | return -EINVAL; |
| 65 | |
| 66 | pdev->broken_parity_status = !!val; |
| 67 | |
| 68 | return count; |
Doug Thompson | bdee9d9 | 2006-06-14 16:59:48 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Alan Cox | 4327edf | 2005-09-10 00:25:49 -0700 | [diff] [blame] | 71 | static ssize_t local_cpus_show(struct device *dev, |
| 72 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | { |
Mike Travis | 3be8305 | 2009-01-04 05:18:01 -0800 | [diff] [blame] | 74 | const struct cpumask *mask; |
Alan Cox | 4327edf | 2005-09-10 00:25:49 -0700 | [diff] [blame] | 75 | int len; |
| 76 | |
Mike Travis | 3be8305 | 2009-01-04 05:18:01 -0800 | [diff] [blame] | 77 | mask = cpumask_of_pcibus(to_pci_dev(dev)->bus); |
| 78 | len = cpumask_scnprintf(buf, PAGE_SIZE-2, mask); |
Mike Travis | 39106dc | 2008-04-08 11:43:03 -0700 | [diff] [blame] | 79 | buf[len++] = '\n'; |
| 80 | buf[len] = '\0'; |
| 81 | return len; |
| 82 | } |
| 83 | |
| 84 | |
| 85 | static ssize_t local_cpulist_show(struct device *dev, |
| 86 | struct device_attribute *attr, char *buf) |
| 87 | { |
Mike Travis | 3be8305 | 2009-01-04 05:18:01 -0800 | [diff] [blame] | 88 | const struct cpumask *mask; |
Mike Travis | 39106dc | 2008-04-08 11:43:03 -0700 | [diff] [blame] | 89 | int len; |
| 90 | |
Mike Travis | 3be8305 | 2009-01-04 05:18:01 -0800 | [diff] [blame] | 91 | mask = cpumask_of_pcibus(to_pci_dev(dev)->bus); |
| 92 | len = cpulist_scnprintf(buf, PAGE_SIZE-2, mask); |
Mike Travis | 39106dc | 2008-04-08 11:43:03 -0700 | [diff] [blame] | 93 | buf[len++] = '\n'; |
| 94 | buf[len] = '\0'; |
| 95 | return len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | /* show resources */ |
| 99 | static ssize_t |
Yani Ioannou | e404e27 | 2005-05-17 06:42:58 -0400 | [diff] [blame] | 100 | resource_show(struct device * dev, struct device_attribute *attr, char * buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | { |
| 102 | struct pci_dev * pci_dev = to_pci_dev(dev); |
| 103 | char * str = buf; |
| 104 | int i; |
Yu Zhao | fde09c6 | 2008-11-22 02:39:32 +0800 | [diff] [blame] | 105 | int max; |
Greg Kroah-Hartman | e31dd6e | 2006-06-12 17:06:02 -0700 | [diff] [blame] | 106 | resource_size_t start, end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
| 108 | if (pci_dev->subordinate) |
| 109 | max = DEVICE_COUNT_RESOURCE; |
Yu Zhao | fde09c6 | 2008-11-22 02:39:32 +0800 | [diff] [blame] | 110 | else |
| 111 | max = PCI_BRIDGE_RESOURCES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
| 113 | for (i = 0; i < max; i++) { |
Michael Ellerman | 2311b1f | 2005-05-13 17:44:10 +1000 | [diff] [blame] | 114 | struct resource *res = &pci_dev->resource[i]; |
| 115 | pci_resource_to_user(pci_dev, i, res, &start, &end); |
| 116 | str += sprintf(str,"0x%016llx 0x%016llx 0x%016llx\n", |
| 117 | (unsigned long long)start, |
| 118 | (unsigned long long)end, |
| 119 | (unsigned long long)res->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | } |
| 121 | return (str - buf); |
| 122 | } |
| 123 | |
Greg Kroah-Hartman | 87c8a44 | 2005-06-19 12:21:43 +0200 | [diff] [blame] | 124 | static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf) |
Greg KH | 9888549 | 2005-05-05 11:57:25 -0700 | [diff] [blame] | 125 | { |
| 126 | struct pci_dev *pci_dev = to_pci_dev(dev); |
| 127 | |
| 128 | return sprintf(buf, "pci:v%08Xd%08Xsv%08Xsd%08Xbc%02Xsc%02Xi%02x\n", |
| 129 | pci_dev->vendor, pci_dev->device, |
| 130 | pci_dev->subsystem_vendor, pci_dev->subsystem_device, |
| 131 | (u8)(pci_dev->class >> 16), (u8)(pci_dev->class >> 8), |
| 132 | (u8)(pci_dev->class)); |
| 133 | } |
Inaky Perez-Gonzalez | bae94d0 | 2006-11-22 12:40:31 -0800 | [diff] [blame] | 134 | |
| 135 | static ssize_t is_enabled_store(struct device *dev, |
| 136 | struct device_attribute *attr, const char *buf, |
| 137 | size_t count) |
Arjan van de Ven | 9f125d3 | 2006-04-29 10:59:08 +0200 | [diff] [blame] | 138 | { |
| 139 | struct pci_dev *pdev = to_pci_dev(dev); |
Trent Piepho | 92425a4 | 2008-11-30 17:10:12 -0800 | [diff] [blame] | 140 | unsigned long val; |
| 141 | ssize_t result = strict_strtoul(buf, 0, &val); |
| 142 | |
| 143 | if (result < 0) |
| 144 | return result; |
Arjan van de Ven | 9f125d3 | 2006-04-29 10:59:08 +0200 | [diff] [blame] | 145 | |
| 146 | /* this can crash the machine when done on the "wrong" device */ |
| 147 | if (!capable(CAP_SYS_ADMIN)) |
Trent Piepho | 92425a4 | 2008-11-30 17:10:12 -0800 | [diff] [blame] | 148 | return -EPERM; |
Arjan van de Ven | 9f125d3 | 2006-04-29 10:59:08 +0200 | [diff] [blame] | 149 | |
Trent Piepho | 92425a4 | 2008-11-30 17:10:12 -0800 | [diff] [blame] | 150 | if (!val) { |
Inaky Perez-Gonzalez | bae94d0 | 2006-11-22 12:40:31 -0800 | [diff] [blame] | 151 | if (atomic_read(&pdev->enable_cnt) != 0) |
| 152 | pci_disable_device(pdev); |
| 153 | else |
| 154 | result = -EIO; |
Trent Piepho | 92425a4 | 2008-11-30 17:10:12 -0800 | [diff] [blame] | 155 | } else |
Inaky Perez-Gonzalez | bae94d0 | 2006-11-22 12:40:31 -0800 | [diff] [blame] | 156 | result = pci_enable_device(pdev); |
Arjan van de Ven | 9f125d3 | 2006-04-29 10:59:08 +0200 | [diff] [blame] | 157 | |
Inaky Perez-Gonzalez | bae94d0 | 2006-11-22 12:40:31 -0800 | [diff] [blame] | 158 | return result < 0 ? result : count; |
| 159 | } |
Arjan van de Ven | 9f125d3 | 2006-04-29 10:59:08 +0200 | [diff] [blame] | 160 | |
Inaky Perez-Gonzalez | bae94d0 | 2006-11-22 12:40:31 -0800 | [diff] [blame] | 161 | static ssize_t is_enabled_show(struct device *dev, |
| 162 | struct device_attribute *attr, char *buf) |
| 163 | { |
| 164 | struct pci_dev *pdev; |
| 165 | |
| 166 | pdev = to_pci_dev (dev); |
| 167 | return sprintf (buf, "%u\n", atomic_read(&pdev->enable_cnt)); |
Arjan van de Ven | 9f125d3 | 2006-04-29 10:59:08 +0200 | [diff] [blame] | 168 | } |
| 169 | |
Brice Goglin | 81bb0e1 | 2007-01-28 10:53:40 +0100 | [diff] [blame] | 170 | #ifdef CONFIG_NUMA |
| 171 | static ssize_t |
| 172 | numa_node_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 173 | { |
| 174 | return sprintf (buf, "%d\n", dev->numa_node); |
| 175 | } |
| 176 | #endif |
| 177 | |
Brice Goglin | fe97064 | 2006-08-31 01:55:15 -0400 | [diff] [blame] | 178 | static ssize_t |
| 179 | msi_bus_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 180 | { |
| 181 | struct pci_dev *pdev = to_pci_dev(dev); |
| 182 | |
| 183 | if (!pdev->subordinate) |
| 184 | return 0; |
| 185 | |
| 186 | return sprintf (buf, "%u\n", |
| 187 | !(pdev->subordinate->bus_flags & PCI_BUS_FLAGS_NO_MSI)); |
| 188 | } |
| 189 | |
| 190 | static ssize_t |
| 191 | msi_bus_store(struct device *dev, struct device_attribute *attr, |
| 192 | const char *buf, size_t count) |
| 193 | { |
| 194 | struct pci_dev *pdev = to_pci_dev(dev); |
Trent Piepho | 92425a4 | 2008-11-30 17:10:12 -0800 | [diff] [blame] | 195 | unsigned long val; |
| 196 | |
| 197 | if (strict_strtoul(buf, 0, &val) < 0) |
| 198 | return -EINVAL; |
Brice Goglin | fe97064 | 2006-08-31 01:55:15 -0400 | [diff] [blame] | 199 | |
| 200 | /* bad things may happen if the no_msi flag is changed |
| 201 | * while some drivers are loaded */ |
| 202 | if (!capable(CAP_SYS_ADMIN)) |
Trent Piepho | 92425a4 | 2008-11-30 17:10:12 -0800 | [diff] [blame] | 203 | return -EPERM; |
Brice Goglin | fe97064 | 2006-08-31 01:55:15 -0400 | [diff] [blame] | 204 | |
Trent Piepho | 92425a4 | 2008-11-30 17:10:12 -0800 | [diff] [blame] | 205 | /* Maybe pci devices without subordinate busses shouldn't even have this |
| 206 | * attribute in the first place? */ |
Brice Goglin | fe97064 | 2006-08-31 01:55:15 -0400 | [diff] [blame] | 207 | if (!pdev->subordinate) |
| 208 | return count; |
| 209 | |
Trent Piepho | 92425a4 | 2008-11-30 17:10:12 -0800 | [diff] [blame] | 210 | /* Is the flag going to change, or keep the value it already had? */ |
| 211 | if (!(pdev->subordinate->bus_flags & PCI_BUS_FLAGS_NO_MSI) ^ |
| 212 | !!val) { |
| 213 | pdev->subordinate->bus_flags ^= PCI_BUS_FLAGS_NO_MSI; |
Brice Goglin | fe97064 | 2006-08-31 01:55:15 -0400 | [diff] [blame] | 214 | |
Trent Piepho | 92425a4 | 2008-11-30 17:10:12 -0800 | [diff] [blame] | 215 | dev_warn(&pdev->dev, "forced subordinate bus to%s support MSI," |
| 216 | " bad things could happen\n", val ? "" : " not"); |
Brice Goglin | fe97064 | 2006-08-31 01:55:15 -0400 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | return count; |
| 220 | } |
Greg KH | 9888549 | 2005-05-05 11:57:25 -0700 | [diff] [blame] | 221 | |
Alex Chiang | 705b1aa | 2009-03-20 14:56:31 -0600 | [diff] [blame^] | 222 | #ifdef CONFIG_HOTPLUG |
| 223 | static DEFINE_MUTEX(pci_remove_rescan_mutex); |
| 224 | static ssize_t bus_rescan_store(struct bus_type *bus, const char *buf, |
| 225 | size_t count) |
| 226 | { |
| 227 | unsigned long val; |
| 228 | struct pci_bus *b = NULL; |
| 229 | |
| 230 | if (strict_strtoul(buf, 0, &val) < 0) |
| 231 | return -EINVAL; |
| 232 | |
| 233 | if (val) { |
| 234 | mutex_lock(&pci_remove_rescan_mutex); |
| 235 | while ((b = pci_find_next_bus(b)) != NULL) |
| 236 | pci_rescan_bus(b); |
| 237 | mutex_unlock(&pci_remove_rescan_mutex); |
| 238 | } |
| 239 | return count; |
| 240 | } |
| 241 | |
| 242 | struct bus_attribute pci_bus_attrs[] = { |
| 243 | __ATTR(rescan, (S_IWUSR|S_IWGRP), NULL, bus_rescan_store), |
| 244 | __ATTR_NULL |
| 245 | }; |
| 246 | #endif |
| 247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | struct device_attribute pci_dev_attrs[] = { |
| 249 | __ATTR_RO(resource), |
| 250 | __ATTR_RO(vendor), |
| 251 | __ATTR_RO(device), |
| 252 | __ATTR_RO(subsystem_vendor), |
| 253 | __ATTR_RO(subsystem_device), |
| 254 | __ATTR_RO(class), |
| 255 | __ATTR_RO(irq), |
| 256 | __ATTR_RO(local_cpus), |
Mike Travis | 39106dc | 2008-04-08 11:43:03 -0700 | [diff] [blame] | 257 | __ATTR_RO(local_cpulist), |
Greg KH | 9888549 | 2005-05-05 11:57:25 -0700 | [diff] [blame] | 258 | __ATTR_RO(modalias), |
Brice Goglin | 81bb0e1 | 2007-01-28 10:53:40 +0100 | [diff] [blame] | 259 | #ifdef CONFIG_NUMA |
| 260 | __ATTR_RO(numa_node), |
| 261 | #endif |
Arjan van de Ven | 9f125d3 | 2006-04-29 10:59:08 +0200 | [diff] [blame] | 262 | __ATTR(enable, 0600, is_enabled_show, is_enabled_store), |
Doug Thompson | bdee9d9 | 2006-06-14 16:59:48 -0700 | [diff] [blame] | 263 | __ATTR(broken_parity_status,(S_IRUGO|S_IWUSR), |
| 264 | broken_parity_status_show,broken_parity_status_store), |
Brice Goglin | fe97064 | 2006-08-31 01:55:15 -0400 | [diff] [blame] | 265 | __ATTR(msi_bus, 0644, msi_bus_show, msi_bus_store), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | __ATTR_NULL, |
| 267 | }; |
| 268 | |
| 269 | static ssize_t |
Dave Airlie | 217f45d | 2009-03-04 05:57:05 +0000 | [diff] [blame] | 270 | boot_vga_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 271 | { |
| 272 | struct pci_dev *pdev = to_pci_dev(dev); |
| 273 | |
| 274 | return sprintf(buf, "%u\n", |
| 275 | !!(pdev->resource[PCI_ROM_RESOURCE].flags & |
| 276 | IORESOURCE_ROM_SHADOW)); |
| 277 | } |
| 278 | struct device_attribute vga_attr = __ATTR_RO(boot_vga); |
| 279 | |
| 280 | static ssize_t |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 281 | pci_read_config(struct kobject *kobj, struct bin_attribute *bin_attr, |
| 282 | char *buf, loff_t off, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | { |
| 284 | struct pci_dev *dev = to_pci_dev(container_of(kobj,struct device,kobj)); |
| 285 | unsigned int size = 64; |
| 286 | loff_t init_off = off; |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 287 | u8 *data = (u8*) buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | |
| 289 | /* Several chips lock up trying to read undefined config space */ |
| 290 | if (capable(CAP_SYS_ADMIN)) { |
| 291 | size = dev->cfg_size; |
| 292 | } else if (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) { |
| 293 | size = 128; |
| 294 | } |
| 295 | |
| 296 | if (off > size) |
| 297 | return 0; |
| 298 | if (off + count > size) { |
| 299 | size -= off; |
| 300 | count = size; |
| 301 | } else { |
| 302 | size = count; |
| 303 | } |
| 304 | |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 305 | if ((off & 1) && size) { |
| 306 | u8 val; |
Brian King | e04b0ea | 2005-09-27 01:21:55 -0700 | [diff] [blame] | 307 | pci_user_read_config_byte(dev, off, &val); |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 308 | data[off - init_off] = val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | off++; |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 310 | size--; |
| 311 | } |
| 312 | |
| 313 | if ((off & 3) && size > 2) { |
| 314 | u16 val; |
Brian King | e04b0ea | 2005-09-27 01:21:55 -0700 | [diff] [blame] | 315 | pci_user_read_config_word(dev, off, &val); |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 316 | data[off - init_off] = val & 0xff; |
| 317 | data[off - init_off + 1] = (val >> 8) & 0xff; |
| 318 | off += 2; |
| 319 | size -= 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | while (size > 3) { |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 323 | u32 val; |
Brian King | e04b0ea | 2005-09-27 01:21:55 -0700 | [diff] [blame] | 324 | pci_user_read_config_dword(dev, off, &val); |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 325 | data[off - init_off] = val & 0xff; |
| 326 | data[off - init_off + 1] = (val >> 8) & 0xff; |
| 327 | data[off - init_off + 2] = (val >> 16) & 0xff; |
| 328 | data[off - init_off + 3] = (val >> 24) & 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | off += 4; |
| 330 | size -= 4; |
| 331 | } |
| 332 | |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 333 | if (size >= 2) { |
| 334 | u16 val; |
Brian King | e04b0ea | 2005-09-27 01:21:55 -0700 | [diff] [blame] | 335 | pci_user_read_config_word(dev, off, &val); |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 336 | data[off - init_off] = val & 0xff; |
| 337 | data[off - init_off + 1] = (val >> 8) & 0xff; |
| 338 | off += 2; |
| 339 | size -= 2; |
| 340 | } |
| 341 | |
| 342 | if (size > 0) { |
| 343 | u8 val; |
Brian King | e04b0ea | 2005-09-27 01:21:55 -0700 | [diff] [blame] | 344 | pci_user_read_config_byte(dev, off, &val); |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 345 | data[off - init_off] = val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | off++; |
| 347 | --size; |
| 348 | } |
| 349 | |
| 350 | return count; |
| 351 | } |
| 352 | |
| 353 | static ssize_t |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 354 | pci_write_config(struct kobject *kobj, struct bin_attribute *bin_attr, |
| 355 | char *buf, loff_t off, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | { |
| 357 | struct pci_dev *dev = to_pci_dev(container_of(kobj,struct device,kobj)); |
| 358 | unsigned int size = count; |
| 359 | loff_t init_off = off; |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 360 | u8 *data = (u8*) buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | |
| 362 | if (off > dev->cfg_size) |
| 363 | return 0; |
| 364 | if (off + count > dev->cfg_size) { |
| 365 | size = dev->cfg_size - off; |
| 366 | count = size; |
| 367 | } |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 368 | |
| 369 | if ((off & 1) && size) { |
Brian King | e04b0ea | 2005-09-27 01:21:55 -0700 | [diff] [blame] | 370 | pci_user_write_config_byte(dev, off, data[off - init_off]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | off++; |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 372 | size--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | } |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 374 | |
| 375 | if ((off & 3) && size > 2) { |
| 376 | u16 val = data[off - init_off]; |
| 377 | val |= (u16) data[off - init_off + 1] << 8; |
Brian King | e04b0ea | 2005-09-27 01:21:55 -0700 | [diff] [blame] | 378 | pci_user_write_config_word(dev, off, val); |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 379 | off += 2; |
| 380 | size -= 2; |
| 381 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | |
| 383 | while (size > 3) { |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 384 | u32 val = data[off - init_off]; |
| 385 | val |= (u32) data[off - init_off + 1] << 8; |
| 386 | val |= (u32) data[off - init_off + 2] << 16; |
| 387 | val |= (u32) data[off - init_off + 3] << 24; |
Brian King | e04b0ea | 2005-09-27 01:21:55 -0700 | [diff] [blame] | 388 | pci_user_write_config_dword(dev, off, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | off += 4; |
| 390 | size -= 4; |
| 391 | } |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 392 | |
| 393 | if (size >= 2) { |
| 394 | u16 val = data[off - init_off]; |
| 395 | val |= (u16) data[off - init_off + 1] << 8; |
Brian King | e04b0ea | 2005-09-27 01:21:55 -0700 | [diff] [blame] | 396 | pci_user_write_config_word(dev, off, val); |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 397 | off += 2; |
| 398 | size -= 2; |
| 399 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 401 | if (size) { |
Brian King | e04b0ea | 2005-09-27 01:21:55 -0700 | [diff] [blame] | 402 | pci_user_write_config_byte(dev, off, data[off - init_off]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | off++; |
| 404 | --size; |
| 405 | } |
| 406 | |
| 407 | return count; |
| 408 | } |
| 409 | |
Ben Hutchings | 94e6108 | 2008-03-05 16:52:39 +0000 | [diff] [blame] | 410 | static ssize_t |
Stephen Hemminger | 287d19c | 2008-12-18 09:17:16 -0800 | [diff] [blame] | 411 | read_vpd_attr(struct kobject *kobj, struct bin_attribute *bin_attr, |
Ben Hutchings | 94e6108 | 2008-03-05 16:52:39 +0000 | [diff] [blame] | 412 | char *buf, loff_t off, size_t count) |
| 413 | { |
| 414 | struct pci_dev *dev = |
| 415 | to_pci_dev(container_of(kobj, struct device, kobj)); |
Ben Hutchings | 94e6108 | 2008-03-05 16:52:39 +0000 | [diff] [blame] | 416 | |
| 417 | if (off > bin_attr->size) |
| 418 | count = 0; |
| 419 | else if (count > bin_attr->size - off) |
| 420 | count = bin_attr->size - off; |
Ben Hutchings | 94e6108 | 2008-03-05 16:52:39 +0000 | [diff] [blame] | 421 | |
Stephen Hemminger | 287d19c | 2008-12-18 09:17:16 -0800 | [diff] [blame] | 422 | return pci_read_vpd(dev, off, count, buf); |
| 423 | } |
Ben Hutchings | 94e6108 | 2008-03-05 16:52:39 +0000 | [diff] [blame] | 424 | |
Stephen Hemminger | 287d19c | 2008-12-18 09:17:16 -0800 | [diff] [blame] | 425 | static ssize_t |
| 426 | write_vpd_attr(struct kobject *kobj, struct bin_attribute *bin_attr, |
| 427 | char *buf, loff_t off, size_t count) |
| 428 | { |
| 429 | struct pci_dev *dev = |
| 430 | to_pci_dev(container_of(kobj, struct device, kobj)); |
| 431 | |
| 432 | if (off > bin_attr->size) |
| 433 | count = 0; |
| 434 | else if (count > bin_attr->size - off) |
| 435 | count = bin_attr->size - off; |
| 436 | |
| 437 | return pci_write_vpd(dev, off, count, buf); |
Ben Hutchings | 94e6108 | 2008-03-05 16:52:39 +0000 | [diff] [blame] | 438 | } |
| 439 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | #ifdef HAVE_PCI_LEGACY |
| 441 | /** |
| 442 | * pci_read_legacy_io - read byte(s) from legacy I/O port space |
| 443 | * @kobj: kobject corresponding to file to read from |
| 444 | * @buf: buffer to store results |
| 445 | * @off: offset into legacy I/O port space |
| 446 | * @count: number of bytes to read |
| 447 | * |
| 448 | * Reads 1, 2, or 4 bytes from legacy I/O port space using an arch specific |
| 449 | * callback routine (pci_legacy_read). |
| 450 | */ |
Benjamin Herrenschmidt | f19aeb1 | 2008-10-03 19:49:32 +1000 | [diff] [blame] | 451 | static ssize_t |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 452 | pci_read_legacy_io(struct kobject *kobj, struct bin_attribute *bin_attr, |
| 453 | char *buf, loff_t off, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | { |
| 455 | struct pci_bus *bus = to_pci_bus(container_of(kobj, |
Greg Kroah-Hartman | fd7d1ce | 2007-05-22 22:47:54 -0400 | [diff] [blame] | 456 | struct device, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | kobj)); |
| 458 | |
| 459 | /* Only support 1, 2 or 4 byte accesses */ |
| 460 | if (count != 1 && count != 2 && count != 4) |
| 461 | return -EINVAL; |
| 462 | |
| 463 | return pci_legacy_read(bus, off, (u32 *)buf, count); |
| 464 | } |
| 465 | |
| 466 | /** |
| 467 | * pci_write_legacy_io - write byte(s) to legacy I/O port space |
| 468 | * @kobj: kobject corresponding to file to read from |
| 469 | * @buf: buffer containing value to be written |
| 470 | * @off: offset into legacy I/O port space |
| 471 | * @count: number of bytes to write |
| 472 | * |
| 473 | * Writes 1, 2, or 4 bytes from legacy I/O port space using an arch specific |
| 474 | * callback routine (pci_legacy_write). |
| 475 | */ |
Benjamin Herrenschmidt | f19aeb1 | 2008-10-03 19:49:32 +1000 | [diff] [blame] | 476 | static ssize_t |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 477 | pci_write_legacy_io(struct kobject *kobj, struct bin_attribute *bin_attr, |
| 478 | char *buf, loff_t off, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | { |
| 480 | struct pci_bus *bus = to_pci_bus(container_of(kobj, |
Greg Kroah-Hartman | fd7d1ce | 2007-05-22 22:47:54 -0400 | [diff] [blame] | 481 | struct device, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | kobj)); |
| 483 | /* Only support 1, 2 or 4 byte accesses */ |
| 484 | if (count != 1 && count != 2 && count != 4) |
| 485 | return -EINVAL; |
| 486 | |
| 487 | return pci_legacy_write(bus, off, *(u32 *)buf, count); |
| 488 | } |
| 489 | |
| 490 | /** |
| 491 | * pci_mmap_legacy_mem - map legacy PCI memory into user memory space |
| 492 | * @kobj: kobject corresponding to device to be mapped |
| 493 | * @attr: struct bin_attribute for this file |
| 494 | * @vma: struct vm_area_struct passed to mmap |
| 495 | * |
Benjamin Herrenschmidt | f19aeb1 | 2008-10-03 19:49:32 +1000 | [diff] [blame] | 496 | * Uses an arch specific callback, pci_mmap_legacy_mem_page_range, to mmap |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | * legacy memory space (first meg of bus space) into application virtual |
| 498 | * memory space. |
| 499 | */ |
Benjamin Herrenschmidt | f19aeb1 | 2008-10-03 19:49:32 +1000 | [diff] [blame] | 500 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | pci_mmap_legacy_mem(struct kobject *kobj, struct bin_attribute *attr, |
| 502 | struct vm_area_struct *vma) |
| 503 | { |
| 504 | struct pci_bus *bus = to_pci_bus(container_of(kobj, |
Greg Kroah-Hartman | fd7d1ce | 2007-05-22 22:47:54 -0400 | [diff] [blame] | 505 | struct device, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | kobj)); |
| 507 | |
Benjamin Herrenschmidt | f19aeb1 | 2008-10-03 19:49:32 +1000 | [diff] [blame] | 508 | return pci_mmap_legacy_page_range(bus, vma, pci_mmap_mem); |
| 509 | } |
| 510 | |
| 511 | /** |
| 512 | * pci_mmap_legacy_io - map legacy PCI IO into user memory space |
| 513 | * @kobj: kobject corresponding to device to be mapped |
| 514 | * @attr: struct bin_attribute for this file |
| 515 | * @vma: struct vm_area_struct passed to mmap |
| 516 | * |
| 517 | * Uses an arch specific callback, pci_mmap_legacy_io_page_range, to mmap |
| 518 | * legacy IO space (first meg of bus space) into application virtual |
| 519 | * memory space. Returns -ENOSYS if the operation isn't supported |
| 520 | */ |
| 521 | static int |
| 522 | pci_mmap_legacy_io(struct kobject *kobj, struct bin_attribute *attr, |
| 523 | struct vm_area_struct *vma) |
| 524 | { |
| 525 | struct pci_bus *bus = to_pci_bus(container_of(kobj, |
| 526 | struct device, |
| 527 | kobj)); |
| 528 | |
| 529 | return pci_mmap_legacy_page_range(bus, vma, pci_mmap_io); |
| 530 | } |
| 531 | |
| 532 | /** |
Ivan Kokshaysky | 10a0ef3 | 2009-02-17 13:46:53 +0300 | [diff] [blame] | 533 | * pci_adjust_legacy_attr - adjustment of legacy file attributes |
| 534 | * @b: bus to create files under |
| 535 | * @mmap_type: I/O port or memory |
| 536 | * |
| 537 | * Stub implementation. Can be overridden by arch if necessary. |
| 538 | */ |
| 539 | void __weak |
| 540 | pci_adjust_legacy_attr(struct pci_bus *b, enum pci_mmap_state mmap_type) |
| 541 | { |
| 542 | return; |
| 543 | } |
| 544 | |
| 545 | /** |
Benjamin Herrenschmidt | f19aeb1 | 2008-10-03 19:49:32 +1000 | [diff] [blame] | 546 | * pci_create_legacy_files - create legacy I/O port and memory files |
| 547 | * @b: bus to create files under |
| 548 | * |
| 549 | * Some platforms allow access to legacy I/O port and ISA memory space on |
| 550 | * a per-bus basis. This routine creates the files and ties them into |
| 551 | * their associated read, write and mmap files from pci-sysfs.c |
| 552 | * |
| 553 | * On error unwind, but don't propogate the error to the caller |
| 554 | * as it is ok to set up the PCI bus without these files. |
| 555 | */ |
| 556 | void pci_create_legacy_files(struct pci_bus *b) |
| 557 | { |
| 558 | int error; |
| 559 | |
| 560 | b->legacy_io = kzalloc(sizeof(struct bin_attribute) * 2, |
| 561 | GFP_ATOMIC); |
| 562 | if (!b->legacy_io) |
| 563 | goto kzalloc_err; |
| 564 | |
| 565 | b->legacy_io->attr.name = "legacy_io"; |
| 566 | b->legacy_io->size = 0xffff; |
| 567 | b->legacy_io->attr.mode = S_IRUSR | S_IWUSR; |
| 568 | b->legacy_io->read = pci_read_legacy_io; |
| 569 | b->legacy_io->write = pci_write_legacy_io; |
| 570 | b->legacy_io->mmap = pci_mmap_legacy_io; |
Ivan Kokshaysky | 10a0ef3 | 2009-02-17 13:46:53 +0300 | [diff] [blame] | 571 | pci_adjust_legacy_attr(b, pci_mmap_io); |
Benjamin Herrenschmidt | f19aeb1 | 2008-10-03 19:49:32 +1000 | [diff] [blame] | 572 | error = device_create_bin_file(&b->dev, b->legacy_io); |
| 573 | if (error) |
| 574 | goto legacy_io_err; |
| 575 | |
| 576 | /* Allocated above after the legacy_io struct */ |
| 577 | b->legacy_mem = b->legacy_io + 1; |
| 578 | b->legacy_mem->attr.name = "legacy_mem"; |
| 579 | b->legacy_mem->size = 1024*1024; |
| 580 | b->legacy_mem->attr.mode = S_IRUSR | S_IWUSR; |
| 581 | b->legacy_mem->mmap = pci_mmap_legacy_mem; |
Ivan Kokshaysky | 10a0ef3 | 2009-02-17 13:46:53 +0300 | [diff] [blame] | 582 | pci_adjust_legacy_attr(b, pci_mmap_mem); |
Benjamin Herrenschmidt | f19aeb1 | 2008-10-03 19:49:32 +1000 | [diff] [blame] | 583 | error = device_create_bin_file(&b->dev, b->legacy_mem); |
| 584 | if (error) |
| 585 | goto legacy_mem_err; |
| 586 | |
| 587 | return; |
| 588 | |
| 589 | legacy_mem_err: |
| 590 | device_remove_bin_file(&b->dev, b->legacy_io); |
| 591 | legacy_io_err: |
| 592 | kfree(b->legacy_io); |
| 593 | b->legacy_io = NULL; |
| 594 | kzalloc_err: |
| 595 | printk(KERN_WARNING "pci: warning: could not create legacy I/O port " |
| 596 | "and ISA memory resources to sysfs\n"); |
| 597 | return; |
| 598 | } |
| 599 | |
| 600 | void pci_remove_legacy_files(struct pci_bus *b) |
| 601 | { |
| 602 | if (b->legacy_io) { |
| 603 | device_remove_bin_file(&b->dev, b->legacy_io); |
| 604 | device_remove_bin_file(&b->dev, b->legacy_mem); |
| 605 | kfree(b->legacy_io); /* both are allocated here */ |
| 606 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | } |
| 608 | #endif /* HAVE_PCI_LEGACY */ |
| 609 | |
| 610 | #ifdef HAVE_PCI_MMAP |
Linus Torvalds | b5ff7df | 2008-10-02 18:52:51 -0700 | [diff] [blame] | 611 | |
Jesse Barnes | 9eff02e | 2008-10-24 10:32:33 -0700 | [diff] [blame] | 612 | int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vma) |
Linus Torvalds | b5ff7df | 2008-10-02 18:52:51 -0700 | [diff] [blame] | 613 | { |
| 614 | unsigned long nr, start, size; |
| 615 | |
| 616 | nr = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT; |
| 617 | start = vma->vm_pgoff; |
Ed Swierk | 88e7df0 | 2008-11-03 14:41:16 -0800 | [diff] [blame] | 618 | size = ((pci_resource_len(pdev, resno) - 1) >> PAGE_SHIFT) + 1; |
Linus Torvalds | b5ff7df | 2008-10-02 18:52:51 -0700 | [diff] [blame] | 619 | if (start < size && size - start >= nr) |
| 620 | return 1; |
| 621 | WARN(1, "process \"%s\" tried to map 0x%08lx-0x%08lx on %s BAR %d (size 0x%08lx)\n", |
| 622 | current->comm, start, start+nr, pci_name(pdev), resno, size); |
| 623 | return 0; |
| 624 | } |
| 625 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | /** |
| 627 | * pci_mmap_resource - map a PCI resource into user memory space |
| 628 | * @kobj: kobject for mapping |
| 629 | * @attr: struct bin_attribute for the file being mapped |
| 630 | * @vma: struct vm_area_struct passed into the mmap |
venkatesh.pallipadi@intel.com | 45aec1a | 2008-03-18 17:00:22 -0700 | [diff] [blame] | 631 | * @write_combine: 1 for write_combine mapping |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | * |
| 633 | * Use the regular PCI mapping routines to map a PCI resource into userspace. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | */ |
| 635 | static int |
| 636 | pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr, |
venkatesh.pallipadi@intel.com | 45aec1a | 2008-03-18 17:00:22 -0700 | [diff] [blame] | 637 | struct vm_area_struct *vma, int write_combine) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | { |
| 639 | struct pci_dev *pdev = to_pci_dev(container_of(kobj, |
| 640 | struct device, kobj)); |
| 641 | struct resource *res = (struct resource *)attr->private; |
| 642 | enum pci_mmap_state mmap_type; |
Greg Kroah-Hartman | e31dd6e | 2006-06-12 17:06:02 -0700 | [diff] [blame] | 643 | resource_size_t start, end; |
Michael Ellerman | 2311b1f | 2005-05-13 17:44:10 +1000 | [diff] [blame] | 644 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | |
Michael Ellerman | 2311b1f | 2005-05-13 17:44:10 +1000 | [diff] [blame] | 646 | for (i = 0; i < PCI_ROM_RESOURCE; i++) |
| 647 | if (res == &pdev->resource[i]) |
| 648 | break; |
| 649 | if (i >= PCI_ROM_RESOURCE) |
| 650 | return -ENODEV; |
| 651 | |
Linus Torvalds | b5ff7df | 2008-10-02 18:52:51 -0700 | [diff] [blame] | 652 | if (!pci_mmap_fits(pdev, i, vma)) |
| 653 | return -EINVAL; |
| 654 | |
Michael Ellerman | 2311b1f | 2005-05-13 17:44:10 +1000 | [diff] [blame] | 655 | /* pci_mmap_page_range() expects the same kind of entry as coming |
| 656 | * from /proc/bus/pci/ which is a "user visible" value. If this is |
| 657 | * different from the resource itself, arch will do necessary fixup. |
| 658 | */ |
| 659 | pci_resource_to_user(pdev, i, res, &start, &end); |
| 660 | vma->vm_pgoff += start >> PAGE_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | mmap_type = res->flags & IORESOURCE_MEM ? pci_mmap_mem : pci_mmap_io; |
| 662 | |
Arjan van de Ven | e8de148 | 2008-10-22 19:55:31 -0700 | [diff] [blame] | 663 | if (res->flags & IORESOURCE_MEM && iomem_is_exclusive(start)) |
| 664 | return -EINVAL; |
| 665 | |
venkatesh.pallipadi@intel.com | 45aec1a | 2008-03-18 17:00:22 -0700 | [diff] [blame] | 666 | return pci_mmap_page_range(pdev, vma, mmap_type, write_combine); |
| 667 | } |
| 668 | |
| 669 | static int |
| 670 | pci_mmap_resource_uc(struct kobject *kobj, struct bin_attribute *attr, |
| 671 | struct vm_area_struct *vma) |
| 672 | { |
| 673 | return pci_mmap_resource(kobj, attr, vma, 0); |
| 674 | } |
| 675 | |
| 676 | static int |
| 677 | pci_mmap_resource_wc(struct kobject *kobj, struct bin_attribute *attr, |
| 678 | struct vm_area_struct *vma) |
| 679 | { |
| 680 | return pci_mmap_resource(kobj, attr, vma, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | /** |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 684 | * pci_remove_resource_files - cleanup resource files |
| 685 | * @dev: dev to cleanup |
| 686 | * |
| 687 | * If we created resource files for @dev, remove them from sysfs and |
| 688 | * free their resources. |
| 689 | */ |
| 690 | static void |
| 691 | pci_remove_resource_files(struct pci_dev *pdev) |
| 692 | { |
| 693 | int i; |
| 694 | |
| 695 | for (i = 0; i < PCI_ROM_RESOURCE; i++) { |
| 696 | struct bin_attribute *res_attr; |
| 697 | |
| 698 | res_attr = pdev->res_attr[i]; |
| 699 | if (res_attr) { |
| 700 | sysfs_remove_bin_file(&pdev->dev.kobj, res_attr); |
| 701 | kfree(res_attr); |
| 702 | } |
venkatesh.pallipadi@intel.com | 45aec1a | 2008-03-18 17:00:22 -0700 | [diff] [blame] | 703 | |
| 704 | res_attr = pdev->res_attr_wc[i]; |
| 705 | if (res_attr) { |
| 706 | sysfs_remove_bin_file(&pdev->dev.kobj, res_attr); |
| 707 | kfree(res_attr); |
| 708 | } |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 709 | } |
| 710 | } |
| 711 | |
venkatesh.pallipadi@intel.com | 45aec1a | 2008-03-18 17:00:22 -0700 | [diff] [blame] | 712 | static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine) |
| 713 | { |
| 714 | /* allocate attribute structure, piggyback attribute name */ |
| 715 | int name_len = write_combine ? 13 : 10; |
| 716 | struct bin_attribute *res_attr; |
| 717 | int retval; |
| 718 | |
| 719 | res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC); |
| 720 | if (res_attr) { |
| 721 | char *res_attr_name = (char *)(res_attr + 1); |
| 722 | |
| 723 | if (write_combine) { |
| 724 | pdev->res_attr_wc[num] = res_attr; |
| 725 | sprintf(res_attr_name, "resource%d_wc", num); |
| 726 | res_attr->mmap = pci_mmap_resource_wc; |
| 727 | } else { |
| 728 | pdev->res_attr[num] = res_attr; |
| 729 | sprintf(res_attr_name, "resource%d", num); |
| 730 | res_attr->mmap = pci_mmap_resource_uc; |
| 731 | } |
| 732 | res_attr->attr.name = res_attr_name; |
| 733 | res_attr->attr.mode = S_IRUSR | S_IWUSR; |
| 734 | res_attr->size = pci_resource_len(pdev, num); |
| 735 | res_attr->private = &pdev->resource[num]; |
| 736 | retval = sysfs_create_bin_file(&pdev->dev.kobj, res_attr); |
| 737 | } else |
| 738 | retval = -ENOMEM; |
| 739 | |
| 740 | return retval; |
| 741 | } |
| 742 | |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 743 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | * pci_create_resource_files - create resource files in sysfs for @dev |
| 745 | * @dev: dev in question |
| 746 | * |
| 747 | * Walk the resources in @dev creating files for each resource available. |
| 748 | */ |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 749 | static int pci_create_resource_files(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | { |
| 751 | int i; |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 752 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | |
| 754 | /* Expose the PCI resources from this device as files */ |
| 755 | for (i = 0; i < PCI_ROM_RESOURCE; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | |
| 757 | /* skip empty resources */ |
| 758 | if (!pci_resource_len(pdev, i)) |
| 759 | continue; |
| 760 | |
venkatesh.pallipadi@intel.com | 45aec1a | 2008-03-18 17:00:22 -0700 | [diff] [blame] | 761 | retval = pci_create_attr(pdev, i, 0); |
| 762 | /* for prefetchable resources, create a WC mappable file */ |
| 763 | if (!retval && pdev->resource[i].flags & IORESOURCE_PREFETCH) |
| 764 | retval = pci_create_attr(pdev, i, 1); |
Dmitry Torokhov | d48593b | 2005-04-29 00:58:46 -0500 | [diff] [blame] | 765 | |
venkatesh.pallipadi@intel.com | 45aec1a | 2008-03-18 17:00:22 -0700 | [diff] [blame] | 766 | if (retval) { |
| 767 | pci_remove_resource_files(pdev); |
| 768 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | } |
| 770 | } |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 771 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | } |
| 773 | #else /* !HAVE_PCI_MMAP */ |
Ivan Kokshaysky | 10a0ef3 | 2009-02-17 13:46:53 +0300 | [diff] [blame] | 774 | int __weak pci_create_resource_files(struct pci_dev *dev) { return 0; } |
| 775 | void __weak pci_remove_resource_files(struct pci_dev *dev) { return; } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | #endif /* HAVE_PCI_MMAP */ |
| 777 | |
| 778 | /** |
| 779 | * pci_write_rom - used to enable access to the PCI ROM display |
| 780 | * @kobj: kernel object handle |
| 781 | * @buf: user input |
| 782 | * @off: file offset |
| 783 | * @count: number of byte in input |
| 784 | * |
| 785 | * writing anything except 0 enables it |
| 786 | */ |
| 787 | static ssize_t |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 788 | pci_write_rom(struct kobject *kobj, struct bin_attribute *bin_attr, |
| 789 | char *buf, loff_t off, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | { |
| 791 | struct pci_dev *pdev = to_pci_dev(container_of(kobj, struct device, kobj)); |
| 792 | |
| 793 | if ((off == 0) && (*buf == '0') && (count == 2)) |
| 794 | pdev->rom_attr_enabled = 0; |
| 795 | else |
| 796 | pdev->rom_attr_enabled = 1; |
| 797 | |
| 798 | return count; |
| 799 | } |
| 800 | |
| 801 | /** |
| 802 | * pci_read_rom - read a PCI ROM |
| 803 | * @kobj: kernel object handle |
| 804 | * @buf: where to put the data we read from the ROM |
| 805 | * @off: file offset |
| 806 | * @count: number of bytes to read |
| 807 | * |
| 808 | * Put @count bytes starting at @off into @buf from the ROM in the PCI |
| 809 | * device corresponding to @kobj. |
| 810 | */ |
| 811 | static ssize_t |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 812 | pci_read_rom(struct kobject *kobj, struct bin_attribute *bin_attr, |
| 813 | char *buf, loff_t off, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | { |
| 815 | struct pci_dev *pdev = to_pci_dev(container_of(kobj, struct device, kobj)); |
| 816 | void __iomem *rom; |
| 817 | size_t size; |
| 818 | |
| 819 | if (!pdev->rom_attr_enabled) |
| 820 | return -EINVAL; |
| 821 | |
| 822 | rom = pci_map_rom(pdev, &size); /* size starts out as PCI window size */ |
Timothy S. Nelson | 97c4483 | 2009-01-30 06:12:47 +1100 | [diff] [blame] | 823 | if (!rom || !size) |
| 824 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | |
| 826 | if (off >= size) |
| 827 | count = 0; |
| 828 | else { |
| 829 | if (off + count > size) |
| 830 | count = size - off; |
| 831 | |
| 832 | memcpy_fromio(buf, rom + off, count); |
| 833 | } |
| 834 | pci_unmap_rom(pdev, rom); |
| 835 | |
| 836 | return count; |
| 837 | } |
| 838 | |
| 839 | static struct bin_attribute pci_config_attr = { |
| 840 | .attr = { |
| 841 | .name = "config", |
| 842 | .mode = S_IRUGO | S_IWUSR, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | }, |
Zhao, Yu | 557848c | 2008-10-13 19:18:07 +0800 | [diff] [blame] | 844 | .size = PCI_CFG_SPACE_SIZE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | .read = pci_read_config, |
| 846 | .write = pci_write_config, |
| 847 | }; |
| 848 | |
| 849 | static struct bin_attribute pcie_config_attr = { |
| 850 | .attr = { |
| 851 | .name = "config", |
| 852 | .mode = S_IRUGO | S_IWUSR, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | }, |
Zhao, Yu | 557848c | 2008-10-13 19:18:07 +0800 | [diff] [blame] | 854 | .size = PCI_CFG_SPACE_EXP_SIZE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | .read = pci_read_config, |
| 856 | .write = pci_write_config, |
| 857 | }; |
| 858 | |
Michael Ellerman | a2cd52c | 2007-05-08 12:03:08 +1000 | [diff] [blame] | 859 | int __attribute__ ((weak)) pcibios_add_platform_entries(struct pci_dev *dev) |
Michael Ellerman | 575e334 | 2007-05-08 12:03:07 +1000 | [diff] [blame] | 860 | { |
Michael Ellerman | a2cd52c | 2007-05-08 12:03:08 +1000 | [diff] [blame] | 861 | return 0; |
Michael Ellerman | 575e334 | 2007-05-08 12:03:07 +1000 | [diff] [blame] | 862 | } |
| 863 | |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 864 | static int pci_create_capabilities_sysfs(struct pci_dev *dev) |
| 865 | { |
| 866 | int retval; |
| 867 | struct bin_attribute *attr; |
| 868 | |
| 869 | /* If the device has VPD, try to expose it in sysfs. */ |
| 870 | if (dev->vpd) { |
| 871 | attr = kzalloc(sizeof(*attr), GFP_ATOMIC); |
| 872 | if (!attr) |
| 873 | return -ENOMEM; |
| 874 | |
| 875 | attr->size = dev->vpd->len; |
| 876 | attr->attr.name = "vpd"; |
| 877 | attr->attr.mode = S_IRUSR | S_IWUSR; |
Stephen Hemminger | 287d19c | 2008-12-18 09:17:16 -0800 | [diff] [blame] | 878 | attr->read = read_vpd_attr; |
| 879 | attr->write = write_vpd_attr; |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 880 | retval = sysfs_create_bin_file(&dev->dev.kobj, attr); |
| 881 | if (retval) { |
| 882 | kfree(dev->vpd->attr); |
| 883 | return retval; |
| 884 | } |
| 885 | dev->vpd->attr = attr; |
| 886 | } |
| 887 | |
| 888 | /* Active State Power Management */ |
| 889 | pcie_aspm_create_sysfs_dev_files(dev); |
| 890 | |
| 891 | return 0; |
| 892 | } |
| 893 | |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 894 | int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | { |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 896 | int retval; |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 897 | int rom_size = 0; |
| 898 | struct bin_attribute *attr; |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 899 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | if (!sysfs_initialized) |
| 901 | return -EACCES; |
| 902 | |
Zhao, Yu | 557848c | 2008-10-13 19:18:07 +0800 | [diff] [blame] | 903 | if (pdev->cfg_size < PCI_CFG_SPACE_EXP_SIZE) |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 904 | retval = sysfs_create_bin_file(&pdev->dev.kobj, &pci_config_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | else |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 906 | retval = sysfs_create_bin_file(&pdev->dev.kobj, &pcie_config_attr); |
| 907 | if (retval) |
| 908 | goto err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 910 | retval = pci_create_resource_files(pdev); |
| 911 | if (retval) |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 912 | goto err_config_file; |
| 913 | |
| 914 | if (pci_resource_len(pdev, PCI_ROM_RESOURCE)) |
| 915 | rom_size = pci_resource_len(pdev, PCI_ROM_RESOURCE); |
| 916 | else if (pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW) |
| 917 | rom_size = 0x20000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | |
| 919 | /* If the device has a ROM, try to expose it in sysfs. */ |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 920 | if (rom_size) { |
Ben Hutchings | 94e6108 | 2008-03-05 16:52:39 +0000 | [diff] [blame] | 921 | attr = kzalloc(sizeof(*attr), GFP_ATOMIC); |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 922 | if (!attr) { |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 923 | retval = -ENOMEM; |
Michael Ellerman | 9890b12 | 2007-04-18 13:34:12 +1000 | [diff] [blame] | 924 | goto err_resource_files; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | } |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 926 | attr->size = rom_size; |
| 927 | attr->attr.name = "rom"; |
| 928 | attr->attr.mode = S_IRUSR; |
| 929 | attr->read = pci_read_rom; |
| 930 | attr->write = pci_write_rom; |
| 931 | retval = sysfs_create_bin_file(&pdev->dev.kobj, attr); |
| 932 | if (retval) { |
| 933 | kfree(attr); |
| 934 | goto err_resource_files; |
| 935 | } |
| 936 | pdev->rom_attr = attr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | } |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 938 | |
Dave Airlie | 217f45d | 2009-03-04 05:57:05 +0000 | [diff] [blame] | 939 | if ((pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA) { |
| 940 | retval = device_create_file(&pdev->dev, &vga_attr); |
| 941 | if (retval) |
| 942 | goto err_rom_file; |
| 943 | } |
| 944 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | /* add platform-specific attributes */ |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 946 | retval = pcibios_add_platform_entries(pdev); |
| 947 | if (retval) |
Dave Airlie | 217f45d | 2009-03-04 05:57:05 +0000 | [diff] [blame] | 948 | goto err_vga_file; |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 949 | |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 950 | /* add sysfs entries for various capabilities */ |
| 951 | retval = pci_create_capabilities_sysfs(pdev); |
| 952 | if (retval) |
Dave Airlie | 217f45d | 2009-03-04 05:57:05 +0000 | [diff] [blame] | 953 | goto err_vga_file; |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 954 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | return 0; |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 956 | |
Dave Airlie | 217f45d | 2009-03-04 05:57:05 +0000 | [diff] [blame] | 957 | err_vga_file: |
| 958 | if ((pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA) |
| 959 | device_remove_file(&pdev->dev, &vga_attr); |
Michael Ellerman | a2cd52c | 2007-05-08 12:03:08 +1000 | [diff] [blame] | 960 | err_rom_file: |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 961 | if (rom_size) { |
Ben Hutchings | 94e6108 | 2008-03-05 16:52:39 +0000 | [diff] [blame] | 962 | sysfs_remove_bin_file(&pdev->dev.kobj, pdev->rom_attr); |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 963 | kfree(pdev->rom_attr); |
| 964 | pdev->rom_attr = NULL; |
| 965 | } |
Michael Ellerman | 9890b12 | 2007-04-18 13:34:12 +1000 | [diff] [blame] | 966 | err_resource_files: |
| 967 | pci_remove_resource_files(pdev); |
Ben Hutchings | 94e6108 | 2008-03-05 16:52:39 +0000 | [diff] [blame] | 968 | err_config_file: |
Zhao, Yu | 557848c | 2008-10-13 19:18:07 +0800 | [diff] [blame] | 969 | if (pdev->cfg_size < PCI_CFG_SPACE_EXP_SIZE) |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 970 | sysfs_remove_bin_file(&pdev->dev.kobj, &pci_config_attr); |
| 971 | else |
| 972 | sysfs_remove_bin_file(&pdev->dev.kobj, &pcie_config_attr); |
| 973 | err: |
| 974 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | } |
| 976 | |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 977 | static void pci_remove_capabilities_sysfs(struct pci_dev *dev) |
| 978 | { |
| 979 | if (dev->vpd && dev->vpd->attr) { |
| 980 | sysfs_remove_bin_file(&dev->dev.kobj, dev->vpd->attr); |
| 981 | kfree(dev->vpd->attr); |
| 982 | } |
| 983 | |
| 984 | pcie_aspm_remove_sysfs_dev_files(dev); |
| 985 | } |
| 986 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | /** |
| 988 | * pci_remove_sysfs_dev_files - cleanup PCI specific sysfs files |
| 989 | * @pdev: device whose entries we should free |
| 990 | * |
| 991 | * Cleanup when @pdev is removed from sysfs. |
| 992 | */ |
| 993 | void pci_remove_sysfs_dev_files(struct pci_dev *pdev) |
| 994 | { |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 995 | int rom_size = 0; |
| 996 | |
David Miller | d67afe5 | 2006-11-10 12:27:48 -0800 | [diff] [blame] | 997 | if (!sysfs_initialized) |
| 998 | return; |
| 999 | |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 1000 | pci_remove_capabilities_sysfs(pdev); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 1001 | |
Zhao, Yu | 557848c | 2008-10-13 19:18:07 +0800 | [diff] [blame] | 1002 | if (pdev->cfg_size < PCI_CFG_SPACE_EXP_SIZE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | sysfs_remove_bin_file(&pdev->dev.kobj, &pci_config_attr); |
| 1004 | else |
| 1005 | sysfs_remove_bin_file(&pdev->dev.kobj, &pcie_config_attr); |
| 1006 | |
| 1007 | pci_remove_resource_files(pdev); |
| 1008 | |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 1009 | if (pci_resource_len(pdev, PCI_ROM_RESOURCE)) |
| 1010 | rom_size = pci_resource_len(pdev, PCI_ROM_RESOURCE); |
| 1011 | else if (pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW) |
| 1012 | rom_size = 0x20000; |
| 1013 | |
| 1014 | if (rom_size && pdev->rom_attr) { |
| 1015 | sysfs_remove_bin_file(&pdev->dev.kobj, pdev->rom_attr); |
| 1016 | kfree(pdev->rom_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | } |
| 1018 | } |
| 1019 | |
| 1020 | static int __init pci_sysfs_init(void) |
| 1021 | { |
| 1022 | struct pci_dev *pdev = NULL; |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 1023 | int retval; |
| 1024 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | sysfs_initialized = 1; |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 1026 | for_each_pci_dev(pdev) { |
| 1027 | retval = pci_create_sysfs_dev_files(pdev); |
Julia Lawall | 151fc5d | 2007-11-20 08:41:16 +0100 | [diff] [blame] | 1028 | if (retval) { |
| 1029 | pci_dev_put(pdev); |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 1030 | return retval; |
Julia Lawall | 151fc5d | 2007-11-20 08:41:16 +0100 | [diff] [blame] | 1031 | } |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 1032 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | |
| 1034 | return 0; |
| 1035 | } |
| 1036 | |
Jesse Barnes | 40ee9e9 | 2007-03-24 11:03:32 -0700 | [diff] [blame] | 1037 | late_initcall(pci_sysfs_init); |