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> |
Paul Gortmaker | 363c75d | 2011-05-27 09:37:25 -0400 | [diff] [blame] | 22 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/topology.h> |
| 24 | #include <linux/mm.h> |
Chris Wright | de139a3 | 2010-05-13 10:43:07 -0700 | [diff] [blame] | 25 | #include <linux/fs.h> |
Alexey Dobriyan | aa0ac36 | 2007-07-15 23:40:39 -0700 | [diff] [blame] | 26 | #include <linux/capability.h> |
Chris Wright | a628e7b | 2011-02-14 17:21:49 -0800 | [diff] [blame] | 27 | #include <linux/security.h> |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 28 | #include <linux/pci-aspm.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 29 | #include <linux/slab.h> |
Matthew Garrett | 1a39b31 | 2012-04-16 16:26:02 -0400 | [diff] [blame] | 30 | #include <linux/vgaarb.h> |
Huang Ying | 448bd85 | 2012-06-23 10:23:51 +0800 | [diff] [blame] | 31 | #include <linux/pm_runtime.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include "pci.h" |
| 33 | |
| 34 | static int sysfs_initialized; /* = 0 */ |
| 35 | |
| 36 | /* show configuration fields */ |
| 37 | #define pci_config_attr(field, format_string) \ |
| 38 | static ssize_t \ |
Yani Ioannou | e404e27 | 2005-05-17 06:42:58 -0400 | [diff] [blame] | 39 | field##_show(struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | { \ |
| 41 | struct pci_dev *pdev; \ |
| 42 | \ |
| 43 | pdev = to_pci_dev (dev); \ |
| 44 | return sprintf (buf, format_string, pdev->field); \ |
Greg Kroah-Hartman | 5136b2d | 2013-10-06 23:55:40 -0700 | [diff] [blame] | 45 | } \ |
| 46 | static DEVICE_ATTR_RO(field) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
| 48 | pci_config_attr(vendor, "0x%04x\n"); |
| 49 | pci_config_attr(device, "0x%04x\n"); |
| 50 | pci_config_attr(subsystem_vendor, "0x%04x\n"); |
| 51 | pci_config_attr(subsystem_device, "0x%04x\n"); |
| 52 | pci_config_attr(class, "0x%06x\n"); |
| 53 | pci_config_attr(irq, "%u\n"); |
| 54 | |
Doug Thompson | bdee9d9 | 2006-06-14 16:59:48 -0700 | [diff] [blame] | 55 | static ssize_t broken_parity_status_show(struct device *dev, |
| 56 | struct device_attribute *attr, |
| 57 | char *buf) |
| 58 | { |
| 59 | struct pci_dev *pdev = to_pci_dev(dev); |
| 60 | return sprintf (buf, "%u\n", pdev->broken_parity_status); |
| 61 | } |
| 62 | |
| 63 | static ssize_t broken_parity_status_store(struct device *dev, |
| 64 | struct device_attribute *attr, |
| 65 | const char *buf, size_t count) |
| 66 | { |
| 67 | struct pci_dev *pdev = to_pci_dev(dev); |
Trent Piepho | 92425a4 | 2008-11-30 17:10:12 -0800 | [diff] [blame] | 68 | unsigned long val; |
Doug Thompson | bdee9d9 | 2006-06-14 16:59:48 -0700 | [diff] [blame] | 69 | |
Jingoo Han | 9a994e8 | 2013-06-01 16:25:25 +0900 | [diff] [blame] | 70 | if (kstrtoul(buf, 0, &val) < 0) |
Trent Piepho | 92425a4 | 2008-11-30 17:10:12 -0800 | [diff] [blame] | 71 | return -EINVAL; |
| 72 | |
| 73 | pdev->broken_parity_status = !!val; |
| 74 | |
| 75 | return count; |
Doug Thompson | bdee9d9 | 2006-06-14 16:59:48 -0700 | [diff] [blame] | 76 | } |
Greg Kroah-Hartman | 5136b2d | 2013-10-06 23:55:40 -0700 | [diff] [blame] | 77 | static DEVICE_ATTR_RW(broken_parity_status); |
Doug Thompson | bdee9d9 | 2006-06-14 16:59:48 -0700 | [diff] [blame] | 78 | |
Alan Cox | 4327edf | 2005-09-10 00:25:49 -0700 | [diff] [blame] | 79 | static ssize_t local_cpus_show(struct device *dev, |
| 80 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | { |
Mike Travis | 3be8305 | 2009-01-04 05:18:01 -0800 | [diff] [blame] | 82 | const struct cpumask *mask; |
Alan Cox | 4327edf | 2005-09-10 00:25:49 -0700 | [diff] [blame] | 83 | int len; |
| 84 | |
Andreas Herrmann | e0cd516 | 2009-04-17 12:01:55 +0200 | [diff] [blame] | 85 | #ifdef CONFIG_NUMA |
David John | 6be954d | 2010-01-04 20:28:57 +0530 | [diff] [blame] | 86 | mask = (dev_to_node(dev) == -1) ? cpu_online_mask : |
| 87 | cpumask_of_node(dev_to_node(dev)); |
Andreas Herrmann | e0cd516 | 2009-04-17 12:01:55 +0200 | [diff] [blame] | 88 | #else |
Mike Travis | 3be8305 | 2009-01-04 05:18:01 -0800 | [diff] [blame] | 89 | mask = cpumask_of_pcibus(to_pci_dev(dev)->bus); |
Andreas Herrmann | e0cd516 | 2009-04-17 12:01:55 +0200 | [diff] [blame] | 90 | #endif |
Mike Travis | 3be8305 | 2009-01-04 05:18:01 -0800 | [diff] [blame] | 91 | len = cpumask_scnprintf(buf, PAGE_SIZE-2, mask); |
Mike Travis | 39106dc | 2008-04-08 11:43:03 -0700 | [diff] [blame] | 92 | buf[len++] = '\n'; |
| 93 | buf[len] = '\0'; |
| 94 | return len; |
| 95 | } |
Greg Kroah-Hartman | 5136b2d | 2013-10-06 23:55:40 -0700 | [diff] [blame] | 96 | static DEVICE_ATTR_RO(local_cpus); |
Mike Travis | 39106dc | 2008-04-08 11:43:03 -0700 | [diff] [blame] | 97 | |
| 98 | static ssize_t local_cpulist_show(struct device *dev, |
| 99 | struct device_attribute *attr, char *buf) |
| 100 | { |
Mike Travis | 3be8305 | 2009-01-04 05:18:01 -0800 | [diff] [blame] | 101 | const struct cpumask *mask; |
Mike Travis | 39106dc | 2008-04-08 11:43:03 -0700 | [diff] [blame] | 102 | int len; |
| 103 | |
Andreas Herrmann | e0cd516 | 2009-04-17 12:01:55 +0200 | [diff] [blame] | 104 | #ifdef CONFIG_NUMA |
David John | 6be954d | 2010-01-04 20:28:57 +0530 | [diff] [blame] | 105 | mask = (dev_to_node(dev) == -1) ? cpu_online_mask : |
| 106 | cpumask_of_node(dev_to_node(dev)); |
Andreas Herrmann | e0cd516 | 2009-04-17 12:01:55 +0200 | [diff] [blame] | 107 | #else |
Mike Travis | 3be8305 | 2009-01-04 05:18:01 -0800 | [diff] [blame] | 108 | mask = cpumask_of_pcibus(to_pci_dev(dev)->bus); |
Andreas Herrmann | e0cd516 | 2009-04-17 12:01:55 +0200 | [diff] [blame] | 109 | #endif |
Mike Travis | 3be8305 | 2009-01-04 05:18:01 -0800 | [diff] [blame] | 110 | len = cpulist_scnprintf(buf, PAGE_SIZE-2, mask); |
Mike Travis | 39106dc | 2008-04-08 11:43:03 -0700 | [diff] [blame] | 111 | buf[len++] = '\n'; |
| 112 | buf[len] = '\0'; |
| 113 | return len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | } |
Greg Kroah-Hartman | 5136b2d | 2013-10-06 23:55:40 -0700 | [diff] [blame] | 115 | static DEVICE_ATTR_RO(local_cpulist); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
Yinghai Lu | dc2c2c9 | 2011-05-12 17:11:40 -0700 | [diff] [blame] | 117 | /* |
| 118 | * PCI Bus Class Devices |
| 119 | */ |
| 120 | static ssize_t pci_bus_show_cpuaffinity(struct device *dev, |
| 121 | int type, |
| 122 | struct device_attribute *attr, |
| 123 | char *buf) |
| 124 | { |
| 125 | int ret; |
| 126 | const struct cpumask *cpumask; |
| 127 | |
| 128 | cpumask = cpumask_of_pcibus(to_pci_bus(dev)); |
| 129 | ret = type ? |
| 130 | cpulist_scnprintf(buf, PAGE_SIZE-2, cpumask) : |
| 131 | cpumask_scnprintf(buf, PAGE_SIZE-2, cpumask); |
| 132 | buf[ret++] = '\n'; |
| 133 | buf[ret] = '\0'; |
| 134 | return ret; |
| 135 | } |
| 136 | |
Greg Kroah-Hartman | 56039e6 | 2013-07-24 15:05:17 -0700 | [diff] [blame] | 137 | static ssize_t cpuaffinity_show(struct device *dev, |
| 138 | struct device_attribute *attr, char *buf) |
Yinghai Lu | dc2c2c9 | 2011-05-12 17:11:40 -0700 | [diff] [blame] | 139 | { |
| 140 | return pci_bus_show_cpuaffinity(dev, 0, attr, buf); |
| 141 | } |
Greg Kroah-Hartman | 56039e6 | 2013-07-24 15:05:17 -0700 | [diff] [blame] | 142 | static DEVICE_ATTR_RO(cpuaffinity); |
Yinghai Lu | dc2c2c9 | 2011-05-12 17:11:40 -0700 | [diff] [blame] | 143 | |
Greg Kroah-Hartman | 56039e6 | 2013-07-24 15:05:17 -0700 | [diff] [blame] | 144 | static ssize_t cpulistaffinity_show(struct device *dev, |
| 145 | struct device_attribute *attr, char *buf) |
Yinghai Lu | dc2c2c9 | 2011-05-12 17:11:40 -0700 | [diff] [blame] | 146 | { |
| 147 | return pci_bus_show_cpuaffinity(dev, 1, attr, buf); |
| 148 | } |
Greg Kroah-Hartman | 56039e6 | 2013-07-24 15:05:17 -0700 | [diff] [blame] | 149 | static DEVICE_ATTR_RO(cpulistaffinity); |
Yinghai Lu | dc2c2c9 | 2011-05-12 17:11:40 -0700 | [diff] [blame] | 150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | /* show resources */ |
| 152 | static ssize_t |
Yani Ioannou | e404e27 | 2005-05-17 06:42:58 -0400 | [diff] [blame] | 153 | resource_show(struct device * dev, struct device_attribute *attr, char * buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | { |
| 155 | struct pci_dev * pci_dev = to_pci_dev(dev); |
| 156 | char * str = buf; |
| 157 | int i; |
Yu Zhao | fde09c6 | 2008-11-22 02:39:32 +0800 | [diff] [blame] | 158 | int max; |
Greg Kroah-Hartman | e31dd6e | 2006-06-12 17:06:02 -0700 | [diff] [blame] | 159 | resource_size_t start, end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | |
| 161 | if (pci_dev->subordinate) |
| 162 | max = DEVICE_COUNT_RESOURCE; |
Yu Zhao | fde09c6 | 2008-11-22 02:39:32 +0800 | [diff] [blame] | 163 | else |
| 164 | max = PCI_BRIDGE_RESOURCES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
| 166 | for (i = 0; i < max; i++) { |
Michael Ellerman | 2311b1f | 2005-05-13 17:44:10 +1000 | [diff] [blame] | 167 | struct resource *res = &pci_dev->resource[i]; |
| 168 | pci_resource_to_user(pci_dev, i, res, &start, &end); |
| 169 | str += sprintf(str,"0x%016llx 0x%016llx 0x%016llx\n", |
| 170 | (unsigned long long)start, |
| 171 | (unsigned long long)end, |
| 172 | (unsigned long long)res->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | } |
| 174 | return (str - buf); |
| 175 | } |
Greg Kroah-Hartman | 5136b2d | 2013-10-06 23:55:40 -0700 | [diff] [blame] | 176 | static DEVICE_ATTR_RO(resource); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
Greg Kroah-Hartman | 87c8a44 | 2005-06-19 12:21:43 +0200 | [diff] [blame] | 178 | 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] | 179 | { |
| 180 | struct pci_dev *pci_dev = to_pci_dev(dev); |
| 181 | |
| 182 | return sprintf(buf, "pci:v%08Xd%08Xsv%08Xsd%08Xbc%02Xsc%02Xi%02x\n", |
| 183 | pci_dev->vendor, pci_dev->device, |
| 184 | pci_dev->subsystem_vendor, pci_dev->subsystem_device, |
| 185 | (u8)(pci_dev->class >> 16), (u8)(pci_dev->class >> 8), |
| 186 | (u8)(pci_dev->class)); |
| 187 | } |
Greg Kroah-Hartman | 5136b2d | 2013-10-06 23:55:40 -0700 | [diff] [blame] | 188 | static DEVICE_ATTR_RO(modalias); |
Inaky Perez-Gonzalez | bae94d0 | 2006-11-22 12:40:31 -0800 | [diff] [blame] | 189 | |
Greg Kroah-Hartman | 5136b2d | 2013-10-06 23:55:40 -0700 | [diff] [blame] | 190 | static ssize_t enabled_store(struct device *dev, |
| 191 | struct device_attribute *attr, const char *buf, |
| 192 | size_t count) |
Arjan van de Ven | 9f125d3 | 2006-04-29 10:59:08 +0200 | [diff] [blame] | 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; |
Jingoo Han | 9a994e8 | 2013-06-01 16:25:25 +0900 | [diff] [blame] | 196 | ssize_t result = kstrtoul(buf, 0, &val); |
Trent Piepho | 92425a4 | 2008-11-30 17:10:12 -0800 | [diff] [blame] | 197 | |
| 198 | if (result < 0) |
| 199 | return result; |
Arjan van de Ven | 9f125d3 | 2006-04-29 10:59:08 +0200 | [diff] [blame] | 200 | |
| 201 | /* this can crash the machine when done on the "wrong" device */ |
| 202 | if (!capable(CAP_SYS_ADMIN)) |
Trent Piepho | 92425a4 | 2008-11-30 17:10:12 -0800 | [diff] [blame] | 203 | return -EPERM; |
Arjan van de Ven | 9f125d3 | 2006-04-29 10:59:08 +0200 | [diff] [blame] | 204 | |
Trent Piepho | 92425a4 | 2008-11-30 17:10:12 -0800 | [diff] [blame] | 205 | if (!val) { |
Yuji Shimada | 296ccb0 | 2009-04-03 16:41:46 +0900 | [diff] [blame] | 206 | if (pci_is_enabled(pdev)) |
Inaky Perez-Gonzalez | bae94d0 | 2006-11-22 12:40:31 -0800 | [diff] [blame] | 207 | pci_disable_device(pdev); |
| 208 | else |
| 209 | result = -EIO; |
Trent Piepho | 92425a4 | 2008-11-30 17:10:12 -0800 | [diff] [blame] | 210 | } else |
Inaky Perez-Gonzalez | bae94d0 | 2006-11-22 12:40:31 -0800 | [diff] [blame] | 211 | result = pci_enable_device(pdev); |
Arjan van de Ven | 9f125d3 | 2006-04-29 10:59:08 +0200 | [diff] [blame] | 212 | |
Inaky Perez-Gonzalez | bae94d0 | 2006-11-22 12:40:31 -0800 | [diff] [blame] | 213 | return result < 0 ? result : count; |
| 214 | } |
Arjan van de Ven | 9f125d3 | 2006-04-29 10:59:08 +0200 | [diff] [blame] | 215 | |
Greg Kroah-Hartman | 5136b2d | 2013-10-06 23:55:40 -0700 | [diff] [blame] | 216 | static ssize_t enabled_show(struct device *dev, |
| 217 | struct device_attribute *attr, char *buf) |
Inaky Perez-Gonzalez | bae94d0 | 2006-11-22 12:40:31 -0800 | [diff] [blame] | 218 | { |
| 219 | struct pci_dev *pdev; |
| 220 | |
| 221 | pdev = to_pci_dev (dev); |
| 222 | return sprintf (buf, "%u\n", atomic_read(&pdev->enable_cnt)); |
Arjan van de Ven | 9f125d3 | 2006-04-29 10:59:08 +0200 | [diff] [blame] | 223 | } |
Greg Kroah-Hartman | 5136b2d | 2013-10-06 23:55:40 -0700 | [diff] [blame] | 224 | static DEVICE_ATTR_RW(enabled); |
Arjan van de Ven | 9f125d3 | 2006-04-29 10:59:08 +0200 | [diff] [blame] | 225 | |
Brice Goglin | 81bb0e1 | 2007-01-28 10:53:40 +0100 | [diff] [blame] | 226 | #ifdef CONFIG_NUMA |
| 227 | static ssize_t |
| 228 | numa_node_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 229 | { |
| 230 | return sprintf (buf, "%d\n", dev->numa_node); |
| 231 | } |
Greg Kroah-Hartman | 5136b2d | 2013-10-06 23:55:40 -0700 | [diff] [blame] | 232 | static DEVICE_ATTR_RO(numa_node); |
Brice Goglin | 81bb0e1 | 2007-01-28 10:53:40 +0100 | [diff] [blame] | 233 | #endif |
| 234 | |
Brice Goglin | fe97064 | 2006-08-31 01:55:15 -0400 | [diff] [blame] | 235 | static ssize_t |
Yinghai Lu | bb96540 | 2009-11-24 18:21:21 -0800 | [diff] [blame] | 236 | dma_mask_bits_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 237 | { |
| 238 | struct pci_dev *pdev = to_pci_dev(dev); |
| 239 | |
| 240 | return sprintf (buf, "%d\n", fls64(pdev->dma_mask)); |
| 241 | } |
Greg Kroah-Hartman | 5136b2d | 2013-10-06 23:55:40 -0700 | [diff] [blame] | 242 | static DEVICE_ATTR_RO(dma_mask_bits); |
Yinghai Lu | bb96540 | 2009-11-24 18:21:21 -0800 | [diff] [blame] | 243 | |
| 244 | static ssize_t |
| 245 | consistent_dma_mask_bits_show(struct device *dev, struct device_attribute *attr, |
| 246 | char *buf) |
| 247 | { |
| 248 | return sprintf (buf, "%d\n", fls64(dev->coherent_dma_mask)); |
| 249 | } |
Greg Kroah-Hartman | 5136b2d | 2013-10-06 23:55:40 -0700 | [diff] [blame] | 250 | static DEVICE_ATTR_RO(consistent_dma_mask_bits); |
Yinghai Lu | bb96540 | 2009-11-24 18:21:21 -0800 | [diff] [blame] | 251 | |
| 252 | static ssize_t |
Brice Goglin | fe97064 | 2006-08-31 01:55:15 -0400 | [diff] [blame] | 253 | msi_bus_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 254 | { |
| 255 | struct pci_dev *pdev = to_pci_dev(dev); |
| 256 | |
| 257 | if (!pdev->subordinate) |
| 258 | return 0; |
| 259 | |
| 260 | return sprintf (buf, "%u\n", |
| 261 | !(pdev->subordinate->bus_flags & PCI_BUS_FLAGS_NO_MSI)); |
| 262 | } |
| 263 | |
| 264 | static ssize_t |
| 265 | msi_bus_store(struct device *dev, struct device_attribute *attr, |
| 266 | const char *buf, size_t count) |
| 267 | { |
| 268 | struct pci_dev *pdev = to_pci_dev(dev); |
Trent Piepho | 92425a4 | 2008-11-30 17:10:12 -0800 | [diff] [blame] | 269 | unsigned long val; |
| 270 | |
Jingoo Han | 9a994e8 | 2013-06-01 16:25:25 +0900 | [diff] [blame] | 271 | if (kstrtoul(buf, 0, &val) < 0) |
Trent Piepho | 92425a4 | 2008-11-30 17:10:12 -0800 | [diff] [blame] | 272 | return -EINVAL; |
Brice Goglin | fe97064 | 2006-08-31 01:55:15 -0400 | [diff] [blame] | 273 | |
| 274 | /* bad things may happen if the no_msi flag is changed |
| 275 | * while some drivers are loaded */ |
| 276 | if (!capable(CAP_SYS_ADMIN)) |
Trent Piepho | 92425a4 | 2008-11-30 17:10:12 -0800 | [diff] [blame] | 277 | return -EPERM; |
Brice Goglin | fe97064 | 2006-08-31 01:55:15 -0400 | [diff] [blame] | 278 | |
Trent Piepho | 92425a4 | 2008-11-30 17:10:12 -0800 | [diff] [blame] | 279 | /* Maybe pci devices without subordinate busses shouldn't even have this |
| 280 | * attribute in the first place? */ |
Brice Goglin | fe97064 | 2006-08-31 01:55:15 -0400 | [diff] [blame] | 281 | if (!pdev->subordinate) |
| 282 | return count; |
| 283 | |
Trent Piepho | 92425a4 | 2008-11-30 17:10:12 -0800 | [diff] [blame] | 284 | /* Is the flag going to change, or keep the value it already had? */ |
| 285 | if (!(pdev->subordinate->bus_flags & PCI_BUS_FLAGS_NO_MSI) ^ |
| 286 | !!val) { |
| 287 | pdev->subordinate->bus_flags ^= PCI_BUS_FLAGS_NO_MSI; |
Brice Goglin | fe97064 | 2006-08-31 01:55:15 -0400 | [diff] [blame] | 288 | |
Trent Piepho | 92425a4 | 2008-11-30 17:10:12 -0800 | [diff] [blame] | 289 | dev_warn(&pdev->dev, "forced subordinate bus to%s support MSI," |
| 290 | " bad things could happen\n", val ? "" : " not"); |
Brice Goglin | fe97064 | 2006-08-31 01:55:15 -0400 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | return count; |
| 294 | } |
Greg Kroah-Hartman | 5136b2d | 2013-10-06 23:55:40 -0700 | [diff] [blame] | 295 | static DEVICE_ATTR_RW(msi_bus); |
Greg KH | 9888549 | 2005-05-05 11:57:25 -0700 | [diff] [blame] | 296 | |
Alex Chiang | 705b1aa | 2009-03-20 14:56:31 -0600 | [diff] [blame] | 297 | static DEFINE_MUTEX(pci_remove_rescan_mutex); |
| 298 | static ssize_t bus_rescan_store(struct bus_type *bus, const char *buf, |
| 299 | size_t count) |
| 300 | { |
| 301 | unsigned long val; |
| 302 | struct pci_bus *b = NULL; |
| 303 | |
Jingoo Han | 9a994e8 | 2013-06-01 16:25:25 +0900 | [diff] [blame] | 304 | if (kstrtoul(buf, 0, &val) < 0) |
Alex Chiang | 705b1aa | 2009-03-20 14:56:31 -0600 | [diff] [blame] | 305 | return -EINVAL; |
| 306 | |
| 307 | if (val) { |
| 308 | mutex_lock(&pci_remove_rescan_mutex); |
| 309 | while ((b = pci_find_next_bus(b)) != NULL) |
| 310 | pci_rescan_bus(b); |
| 311 | mutex_unlock(&pci_remove_rescan_mutex); |
| 312 | } |
| 313 | return count; |
| 314 | } |
Greg Kroah-Hartman | 0f49ba5 | 2013-10-07 14:51:02 -0600 | [diff] [blame] | 315 | static BUS_ATTR(rescan, (S_IWUSR|S_IWGRP), NULL, bus_rescan_store); |
Alex Chiang | 705b1aa | 2009-03-20 14:56:31 -0600 | [diff] [blame] | 316 | |
Sachin Kamat | bf22c90 | 2013-09-28 15:42:00 +0530 | [diff] [blame^] | 317 | static struct attribute *pci_bus_attrs[] = { |
Greg Kroah-Hartman | 0f49ba5 | 2013-10-07 14:51:02 -0600 | [diff] [blame] | 318 | &bus_attr_rescan.attr, |
| 319 | NULL, |
| 320 | }; |
| 321 | |
| 322 | static const struct attribute_group pci_bus_group = { |
| 323 | .attrs = pci_bus_attrs, |
| 324 | }; |
| 325 | |
| 326 | const struct attribute_group *pci_bus_groups[] = { |
| 327 | &pci_bus_group, |
| 328 | NULL, |
Alex Chiang | 705b1aa | 2009-03-20 14:56:31 -0600 | [diff] [blame] | 329 | }; |
Alex Chiang | 77c27c7 | 2009-03-20 14:56:36 -0600 | [diff] [blame] | 330 | |
Alex Chiang | 738a639 | 2009-03-20 14:56:41 -0600 | [diff] [blame] | 331 | static ssize_t |
| 332 | dev_rescan_store(struct device *dev, struct device_attribute *attr, |
| 333 | const char *buf, size_t count) |
| 334 | { |
| 335 | unsigned long val; |
| 336 | struct pci_dev *pdev = to_pci_dev(dev); |
| 337 | |
Jingoo Han | 9a994e8 | 2013-06-01 16:25:25 +0900 | [diff] [blame] | 338 | if (kstrtoul(buf, 0, &val) < 0) |
Alex Chiang | 738a639 | 2009-03-20 14:56:41 -0600 | [diff] [blame] | 339 | return -EINVAL; |
| 340 | |
| 341 | if (val) { |
| 342 | mutex_lock(&pci_remove_rescan_mutex); |
| 343 | pci_rescan_bus(pdev->bus); |
| 344 | mutex_unlock(&pci_remove_rescan_mutex); |
| 345 | } |
| 346 | return count; |
| 347 | } |
Sachin Kamat | bf22c90 | 2013-09-28 15:42:00 +0530 | [diff] [blame^] | 348 | static struct device_attribute dev_rescan_attr = __ATTR(rescan, |
| 349 | (S_IWUSR|S_IWGRP), |
| 350 | NULL, dev_rescan_store); |
Alex Chiang | 738a639 | 2009-03-20 14:56:41 -0600 | [diff] [blame] | 351 | |
Alex Chiang | 77c27c7 | 2009-03-20 14:56:36 -0600 | [diff] [blame] | 352 | static void remove_callback(struct device *dev) |
| 353 | { |
| 354 | struct pci_dev *pdev = to_pci_dev(dev); |
| 355 | |
| 356 | mutex_lock(&pci_remove_rescan_mutex); |
Yinghai Lu | 210647a | 2012-02-25 13:54:20 -0800 | [diff] [blame] | 357 | pci_stop_and_remove_bus_device(pdev); |
Alex Chiang | 77c27c7 | 2009-03-20 14:56:36 -0600 | [diff] [blame] | 358 | mutex_unlock(&pci_remove_rescan_mutex); |
| 359 | } |
| 360 | |
| 361 | static ssize_t |
| 362 | remove_store(struct device *dev, struct device_attribute *dummy, |
| 363 | const char *buf, size_t count) |
| 364 | { |
| 365 | int ret = 0; |
| 366 | unsigned long val; |
Alex Chiang | 77c27c7 | 2009-03-20 14:56:36 -0600 | [diff] [blame] | 367 | |
Jingoo Han | 9a994e8 | 2013-06-01 16:25:25 +0900 | [diff] [blame] | 368 | if (kstrtoul(buf, 0, &val) < 0) |
Alex Chiang | 77c27c7 | 2009-03-20 14:56:36 -0600 | [diff] [blame] | 369 | return -EINVAL; |
| 370 | |
Alex Chiang | 77c27c7 | 2009-03-20 14:56:36 -0600 | [diff] [blame] | 371 | /* An attribute cannot be unregistered by one of its own methods, |
| 372 | * so we have to use this roundabout approach. |
| 373 | */ |
| 374 | if (val) |
| 375 | ret = device_schedule_callback(dev, remove_callback); |
| 376 | if (ret) |
| 377 | count = ret; |
| 378 | return count; |
| 379 | } |
Sachin Kamat | bf22c90 | 2013-09-28 15:42:00 +0530 | [diff] [blame^] | 380 | static struct device_attribute dev_remove_attr = __ATTR(remove, |
| 381 | (S_IWUSR|S_IWGRP), |
| 382 | NULL, remove_store); |
Yinghai Lu | b9d320f | 2011-05-12 17:11:39 -0700 | [diff] [blame] | 383 | |
| 384 | static ssize_t |
| 385 | dev_bus_rescan_store(struct device *dev, struct device_attribute *attr, |
| 386 | const char *buf, size_t count) |
| 387 | { |
| 388 | unsigned long val; |
| 389 | struct pci_bus *bus = to_pci_bus(dev); |
| 390 | |
Jingoo Han | 9a994e8 | 2013-06-01 16:25:25 +0900 | [diff] [blame] | 391 | if (kstrtoul(buf, 0, &val) < 0) |
Yinghai Lu | b9d320f | 2011-05-12 17:11:39 -0700 | [diff] [blame] | 392 | return -EINVAL; |
| 393 | |
| 394 | if (val) { |
| 395 | mutex_lock(&pci_remove_rescan_mutex); |
Yinghai Lu | 2f32052 | 2012-01-21 02:08:22 -0800 | [diff] [blame] | 396 | if (!pci_is_root_bus(bus) && list_empty(&bus->devices)) |
| 397 | pci_rescan_bus_bridge_resize(bus->self); |
| 398 | else |
| 399 | pci_rescan_bus(bus); |
Yinghai Lu | b9d320f | 2011-05-12 17:11:39 -0700 | [diff] [blame] | 400 | mutex_unlock(&pci_remove_rescan_mutex); |
| 401 | } |
| 402 | return count; |
| 403 | } |
Greg Kroah-Hartman | 56039e6 | 2013-07-24 15:05:17 -0700 | [diff] [blame] | 404 | static DEVICE_ATTR(rescan, (S_IWUSR|S_IWGRP), NULL, dev_bus_rescan_store); |
Yinghai Lu | b9d320f | 2011-05-12 17:11:39 -0700 | [diff] [blame] | 405 | |
Huang Ying | 448bd85 | 2012-06-23 10:23:51 +0800 | [diff] [blame] | 406 | #if defined(CONFIG_PM_RUNTIME) && defined(CONFIG_ACPI) |
| 407 | static ssize_t d3cold_allowed_store(struct device *dev, |
| 408 | struct device_attribute *attr, |
| 409 | const char *buf, size_t count) |
| 410 | { |
| 411 | struct pci_dev *pdev = to_pci_dev(dev); |
| 412 | unsigned long val; |
| 413 | |
Jingoo Han | 9a994e8 | 2013-06-01 16:25:25 +0900 | [diff] [blame] | 414 | if (kstrtoul(buf, 0, &val) < 0) |
Huang Ying | 448bd85 | 2012-06-23 10:23:51 +0800 | [diff] [blame] | 415 | return -EINVAL; |
| 416 | |
| 417 | pdev->d3cold_allowed = !!val; |
| 418 | pm_runtime_resume(dev); |
| 419 | |
| 420 | return count; |
| 421 | } |
| 422 | |
| 423 | static ssize_t d3cold_allowed_show(struct device *dev, |
| 424 | struct device_attribute *attr, char *buf) |
| 425 | { |
| 426 | struct pci_dev *pdev = to_pci_dev(dev); |
| 427 | return sprintf (buf, "%u\n", pdev->d3cold_allowed); |
| 428 | } |
Greg Kroah-Hartman | 5136b2d | 2013-10-06 23:55:40 -0700 | [diff] [blame] | 429 | static DEVICE_ATTR_RW(d3cold_allowed); |
Huang Ying | 448bd85 | 2012-06-23 10:23:51 +0800 | [diff] [blame] | 430 | #endif |
| 431 | |
Donald Dutile | 1789382 | 2012-11-05 15:20:36 -0500 | [diff] [blame] | 432 | #ifdef CONFIG_PCI_IOV |
| 433 | static ssize_t sriov_totalvfs_show(struct device *dev, |
| 434 | struct device_attribute *attr, |
| 435 | char *buf) |
| 436 | { |
| 437 | struct pci_dev *pdev = to_pci_dev(dev); |
| 438 | |
Donald Dutile | bff7315 | 2012-11-05 15:20:37 -0500 | [diff] [blame] | 439 | return sprintf(buf, "%u\n", pci_sriov_get_totalvfs(pdev)); |
Donald Dutile | 1789382 | 2012-11-05 15:20:36 -0500 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | |
| 443 | static ssize_t sriov_numvfs_show(struct device *dev, |
| 444 | struct device_attribute *attr, |
| 445 | char *buf) |
| 446 | { |
| 447 | struct pci_dev *pdev = to_pci_dev(dev); |
| 448 | |
Bjorn Helgaas | 6b13672 | 2012-11-09 20:27:53 -0700 | [diff] [blame] | 449 | return sprintf(buf, "%u\n", pdev->sriov->num_VFs); |
Donald Dutile | 1789382 | 2012-11-05 15:20:36 -0500 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | /* |
Bjorn Helgaas | faa48a5 | 2012-12-26 10:39:22 -0700 | [diff] [blame] | 453 | * num_vfs > 0; number of VFs to enable |
| 454 | * num_vfs = 0; disable all VFs |
Donald Dutile | 1789382 | 2012-11-05 15:20:36 -0500 | [diff] [blame] | 455 | * |
| 456 | * Note: SRIOV spec doesn't allow partial VF |
Bjorn Helgaas | faa48a5 | 2012-12-26 10:39:22 -0700 | [diff] [blame] | 457 | * disable, so it's all or none. |
Donald Dutile | 1789382 | 2012-11-05 15:20:36 -0500 | [diff] [blame] | 458 | */ |
| 459 | static ssize_t sriov_numvfs_store(struct device *dev, |
| 460 | struct device_attribute *attr, |
| 461 | const char *buf, size_t count) |
| 462 | { |
| 463 | struct pci_dev *pdev = to_pci_dev(dev); |
Bjorn Helgaas | faa48a5 | 2012-12-26 10:39:22 -0700 | [diff] [blame] | 464 | int ret; |
| 465 | u16 num_vfs; |
Donald Dutile | 1789382 | 2012-11-05 15:20:36 -0500 | [diff] [blame] | 466 | |
Bjorn Helgaas | faa48a5 | 2012-12-26 10:39:22 -0700 | [diff] [blame] | 467 | ret = kstrtou16(buf, 0, &num_vfs); |
| 468 | if (ret < 0) |
| 469 | return ret; |
| 470 | |
| 471 | if (num_vfs > pci_sriov_get_totalvfs(pdev)) |
| 472 | return -ERANGE; |
| 473 | |
| 474 | if (num_vfs == pdev->sriov->num_VFs) |
| 475 | return count; /* no change */ |
Donald Dutile | 1789382 | 2012-11-05 15:20:36 -0500 | [diff] [blame] | 476 | |
| 477 | /* is PF driver loaded w/callback */ |
| 478 | if (!pdev->driver || !pdev->driver->sriov_configure) { |
Bjorn Helgaas | faa48a5 | 2012-12-26 10:39:22 -0700 | [diff] [blame] | 479 | dev_info(&pdev->dev, "Driver doesn't support SRIOV configuration via sysfs\n"); |
Donald Dutile | 1789382 | 2012-11-05 15:20:36 -0500 | [diff] [blame] | 480 | return -ENOSYS; |
| 481 | } |
| 482 | |
Donald Dutile | 1789382 | 2012-11-05 15:20:36 -0500 | [diff] [blame] | 483 | if (num_vfs == 0) { |
Bjorn Helgaas | faa48a5 | 2012-12-26 10:39:22 -0700 | [diff] [blame] | 484 | /* disable VFs */ |
| 485 | ret = pdev->driver->sriov_configure(pdev, 0); |
| 486 | if (ret < 0) |
| 487 | return ret; |
| 488 | return count; |
Donald Dutile | 1789382 | 2012-11-05 15:20:36 -0500 | [diff] [blame] | 489 | } |
| 490 | |
Bjorn Helgaas | faa48a5 | 2012-12-26 10:39:22 -0700 | [diff] [blame] | 491 | /* enable VFs */ |
| 492 | if (pdev->sriov->num_VFs) { |
| 493 | dev_warn(&pdev->dev, "%d VFs already enabled. Disable before enabling %d VFs\n", |
| 494 | pdev->sriov->num_VFs, num_vfs); |
| 495 | return -EBUSY; |
| 496 | } |
Donald Dutile | 1789382 | 2012-11-05 15:20:36 -0500 | [diff] [blame] | 497 | |
Bjorn Helgaas | faa48a5 | 2012-12-26 10:39:22 -0700 | [diff] [blame] | 498 | ret = pdev->driver->sriov_configure(pdev, num_vfs); |
| 499 | if (ret < 0) |
| 500 | return ret; |
| 501 | |
| 502 | if (ret != num_vfs) |
| 503 | dev_warn(&pdev->dev, "%d VFs requested; only %d enabled\n", |
| 504 | num_vfs, ret); |
| 505 | |
| 506 | return count; |
Donald Dutile | 1789382 | 2012-11-05 15:20:36 -0500 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | static struct device_attribute sriov_totalvfs_attr = __ATTR_RO(sriov_totalvfs); |
| 510 | static struct device_attribute sriov_numvfs_attr = |
| 511 | __ATTR(sriov_numvfs, (S_IRUGO|S_IWUSR|S_IWGRP), |
| 512 | sriov_numvfs_show, sriov_numvfs_store); |
| 513 | #endif /* CONFIG_PCI_IOV */ |
| 514 | |
Sachin Kamat | bf22c90 | 2013-09-28 15:42:00 +0530 | [diff] [blame^] | 515 | static struct attribute *pci_dev_attrs[] = { |
Greg Kroah-Hartman | 5136b2d | 2013-10-06 23:55:40 -0700 | [diff] [blame] | 516 | &dev_attr_resource.attr, |
| 517 | &dev_attr_vendor.attr, |
| 518 | &dev_attr_device.attr, |
| 519 | &dev_attr_subsystem_vendor.attr, |
| 520 | &dev_attr_subsystem_device.attr, |
| 521 | &dev_attr_class.attr, |
| 522 | &dev_attr_irq.attr, |
| 523 | &dev_attr_local_cpus.attr, |
| 524 | &dev_attr_local_cpulist.attr, |
| 525 | &dev_attr_modalias.attr, |
Brice Goglin | 81bb0e1 | 2007-01-28 10:53:40 +0100 | [diff] [blame] | 526 | #ifdef CONFIG_NUMA |
Greg Kroah-Hartman | 5136b2d | 2013-10-06 23:55:40 -0700 | [diff] [blame] | 527 | &dev_attr_numa_node.attr, |
Brice Goglin | 81bb0e1 | 2007-01-28 10:53:40 +0100 | [diff] [blame] | 528 | #endif |
Greg Kroah-Hartman | 5136b2d | 2013-10-06 23:55:40 -0700 | [diff] [blame] | 529 | &dev_attr_dma_mask_bits.attr, |
| 530 | &dev_attr_consistent_dma_mask_bits.attr, |
| 531 | &dev_attr_enabled.attr, |
| 532 | &dev_attr_broken_parity_status.attr, |
| 533 | &dev_attr_msi_bus.attr, |
Huang Ying | 448bd85 | 2012-06-23 10:23:51 +0800 | [diff] [blame] | 534 | #if defined(CONFIG_PM_RUNTIME) && defined(CONFIG_ACPI) |
Greg Kroah-Hartman | 5136b2d | 2013-10-06 23:55:40 -0700 | [diff] [blame] | 535 | &dev_attr_d3cold_allowed.attr, |
Huang Ying | 448bd85 | 2012-06-23 10:23:51 +0800 | [diff] [blame] | 536 | #endif |
Greg Kroah-Hartman | 5136b2d | 2013-10-06 23:55:40 -0700 | [diff] [blame] | 537 | NULL, |
| 538 | }; |
| 539 | |
| 540 | static const struct attribute_group pci_dev_group = { |
| 541 | .attrs = pci_dev_attrs, |
| 542 | }; |
| 543 | |
| 544 | const struct attribute_group *pci_dev_groups[] = { |
| 545 | &pci_dev_group, |
| 546 | NULL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | }; |
| 548 | |
Greg Kroah-Hartman | 56039e6 | 2013-07-24 15:05:17 -0700 | [diff] [blame] | 549 | static struct attribute *pcibus_attrs[] = { |
| 550 | &dev_attr_rescan.attr, |
| 551 | &dev_attr_cpuaffinity.attr, |
| 552 | &dev_attr_cpulistaffinity.attr, |
| 553 | NULL, |
| 554 | }; |
| 555 | |
| 556 | static const struct attribute_group pcibus_group = { |
| 557 | .attrs = pcibus_attrs, |
| 558 | }; |
| 559 | |
| 560 | const struct attribute_group *pcibus_groups[] = { |
| 561 | &pcibus_group, |
| 562 | NULL, |
Yinghai Lu | b9d320f | 2011-05-12 17:11:39 -0700 | [diff] [blame] | 563 | }; |
| 564 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | static ssize_t |
Dave Airlie | 217f45d | 2009-03-04 05:57:05 +0000 | [diff] [blame] | 566 | boot_vga_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 567 | { |
| 568 | struct pci_dev *pdev = to_pci_dev(dev); |
Matthew Garrett | 1a39b31 | 2012-04-16 16:26:02 -0400 | [diff] [blame] | 569 | struct pci_dev *vga_dev = vga_default_device(); |
| 570 | |
| 571 | if (vga_dev) |
| 572 | return sprintf(buf, "%u\n", (pdev == vga_dev)); |
Dave Airlie | 217f45d | 2009-03-04 05:57:05 +0000 | [diff] [blame] | 573 | |
| 574 | return sprintf(buf, "%u\n", |
| 575 | !!(pdev->resource[PCI_ROM_RESOURCE].flags & |
| 576 | IORESOURCE_ROM_SHADOW)); |
| 577 | } |
Sachin Kamat | bf22c90 | 2013-09-28 15:42:00 +0530 | [diff] [blame^] | 578 | static struct device_attribute vga_attr = __ATTR_RO(boot_vga); |
Dave Airlie | 217f45d | 2009-03-04 05:57:05 +0000 | [diff] [blame] | 579 | |
| 580 | static ssize_t |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 581 | pci_read_config(struct file *filp, struct kobject *kobj, |
| 582 | struct bin_attribute *bin_attr, |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 583 | char *buf, loff_t off, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | { |
| 585 | struct pci_dev *dev = to_pci_dev(container_of(kobj,struct device,kobj)); |
| 586 | unsigned int size = 64; |
| 587 | loff_t init_off = off; |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 588 | u8 *data = (u8*) buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | |
| 590 | /* Several chips lock up trying to read undefined config space */ |
Eric Paris | b7e724d | 2012-01-03 12:25:15 -0500 | [diff] [blame] | 591 | if (security_capable(filp->f_cred, &init_user_ns, CAP_SYS_ADMIN) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | size = dev->cfg_size; |
| 593 | } else if (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) { |
| 594 | size = 128; |
| 595 | } |
| 596 | |
| 597 | if (off > size) |
| 598 | return 0; |
| 599 | if (off + count > size) { |
| 600 | size -= off; |
| 601 | count = size; |
| 602 | } else { |
| 603 | size = count; |
| 604 | } |
| 605 | |
Huang Ying | 3d8387e | 2012-08-15 09:43:03 +0800 | [diff] [blame] | 606 | pci_config_pm_runtime_get(dev); |
| 607 | |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 608 | if ((off & 1) && size) { |
| 609 | u8 val; |
Brian King | e04b0ea | 2005-09-27 01:21:55 -0700 | [diff] [blame] | 610 | pci_user_read_config_byte(dev, off, &val); |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 611 | data[off - init_off] = val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | off++; |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 613 | size--; |
| 614 | } |
| 615 | |
| 616 | if ((off & 3) && size > 2) { |
| 617 | u16 val; |
Brian King | e04b0ea | 2005-09-27 01:21:55 -0700 | [diff] [blame] | 618 | pci_user_read_config_word(dev, off, &val); |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 619 | data[off - init_off] = val & 0xff; |
| 620 | data[off - init_off + 1] = (val >> 8) & 0xff; |
| 621 | off += 2; |
| 622 | size -= 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | while (size > 3) { |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 626 | u32 val; |
Brian King | e04b0ea | 2005-09-27 01:21:55 -0700 | [diff] [blame] | 627 | pci_user_read_config_dword(dev, off, &val); |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 628 | data[off - init_off] = val & 0xff; |
| 629 | data[off - init_off + 1] = (val >> 8) & 0xff; |
| 630 | data[off - init_off + 2] = (val >> 16) & 0xff; |
| 631 | data[off - init_off + 3] = (val >> 24) & 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | off += 4; |
| 633 | size -= 4; |
| 634 | } |
| 635 | |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 636 | if (size >= 2) { |
| 637 | u16 val; |
Brian King | e04b0ea | 2005-09-27 01:21:55 -0700 | [diff] [blame] | 638 | pci_user_read_config_word(dev, off, &val); |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 639 | data[off - init_off] = val & 0xff; |
| 640 | data[off - init_off + 1] = (val >> 8) & 0xff; |
| 641 | off += 2; |
| 642 | size -= 2; |
| 643 | } |
| 644 | |
| 645 | if (size > 0) { |
| 646 | u8 val; |
Brian King | e04b0ea | 2005-09-27 01:21:55 -0700 | [diff] [blame] | 647 | pci_user_read_config_byte(dev, off, &val); |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 648 | data[off - init_off] = val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | off++; |
| 650 | --size; |
| 651 | } |
| 652 | |
Huang Ying | 3d8387e | 2012-08-15 09:43:03 +0800 | [diff] [blame] | 653 | pci_config_pm_runtime_put(dev); |
| 654 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | return count; |
| 656 | } |
| 657 | |
| 658 | static ssize_t |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 659 | pci_write_config(struct file* filp, struct kobject *kobj, |
| 660 | struct bin_attribute *bin_attr, |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 661 | char *buf, loff_t off, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | { |
| 663 | struct pci_dev *dev = to_pci_dev(container_of(kobj,struct device,kobj)); |
| 664 | unsigned int size = count; |
| 665 | loff_t init_off = off; |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 666 | u8 *data = (u8*) buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | |
| 668 | if (off > dev->cfg_size) |
| 669 | return 0; |
| 670 | if (off + count > dev->cfg_size) { |
| 671 | size = dev->cfg_size - off; |
| 672 | count = size; |
| 673 | } |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 674 | |
Huang Ying | 3d8387e | 2012-08-15 09:43:03 +0800 | [diff] [blame] | 675 | pci_config_pm_runtime_get(dev); |
| 676 | |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 677 | if ((off & 1) && size) { |
Brian King | e04b0ea | 2005-09-27 01:21:55 -0700 | [diff] [blame] | 678 | pci_user_write_config_byte(dev, off, data[off - init_off]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | off++; |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 680 | size--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | } |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 682 | |
| 683 | if ((off & 3) && size > 2) { |
| 684 | u16 val = data[off - init_off]; |
| 685 | val |= (u16) data[off - init_off + 1] << 8; |
Brian King | e04b0ea | 2005-09-27 01:21:55 -0700 | [diff] [blame] | 686 | pci_user_write_config_word(dev, off, val); |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 687 | off += 2; |
| 688 | size -= 2; |
| 689 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | |
| 691 | while (size > 3) { |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 692 | u32 val = data[off - init_off]; |
| 693 | val |= (u32) data[off - init_off + 1] << 8; |
| 694 | val |= (u32) data[off - init_off + 2] << 16; |
| 695 | val |= (u32) data[off - init_off + 3] << 24; |
Brian King | e04b0ea | 2005-09-27 01:21:55 -0700 | [diff] [blame] | 696 | pci_user_write_config_dword(dev, off, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | off += 4; |
| 698 | size -= 4; |
| 699 | } |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 700 | |
| 701 | if (size >= 2) { |
| 702 | u16 val = data[off - init_off]; |
| 703 | val |= (u16) data[off - init_off + 1] << 8; |
Brian King | e04b0ea | 2005-09-27 01:21:55 -0700 | [diff] [blame] | 704 | pci_user_write_config_word(dev, off, val); |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 705 | off += 2; |
| 706 | size -= 2; |
| 707 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | |
ssant@in.ibm.com | 4c0619a | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 709 | if (size) { |
Brian King | e04b0ea | 2005-09-27 01:21:55 -0700 | [diff] [blame] | 710 | pci_user_write_config_byte(dev, off, data[off - init_off]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | off++; |
| 712 | --size; |
| 713 | } |
| 714 | |
Huang Ying | 3d8387e | 2012-08-15 09:43:03 +0800 | [diff] [blame] | 715 | pci_config_pm_runtime_put(dev); |
| 716 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | return count; |
| 718 | } |
| 719 | |
Ben Hutchings | 94e6108 | 2008-03-05 16:52:39 +0000 | [diff] [blame] | 720 | static ssize_t |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 721 | read_vpd_attr(struct file *filp, struct kobject *kobj, |
| 722 | struct bin_attribute *bin_attr, |
Ben Hutchings | 94e6108 | 2008-03-05 16:52:39 +0000 | [diff] [blame] | 723 | char *buf, loff_t off, size_t count) |
| 724 | { |
| 725 | struct pci_dev *dev = |
| 726 | to_pci_dev(container_of(kobj, struct device, kobj)); |
Ben Hutchings | 94e6108 | 2008-03-05 16:52:39 +0000 | [diff] [blame] | 727 | |
| 728 | if (off > bin_attr->size) |
| 729 | count = 0; |
| 730 | else if (count > bin_attr->size - off) |
| 731 | count = bin_attr->size - off; |
Ben Hutchings | 94e6108 | 2008-03-05 16:52:39 +0000 | [diff] [blame] | 732 | |
Stephen Hemminger | 287d19c | 2008-12-18 09:17:16 -0800 | [diff] [blame] | 733 | return pci_read_vpd(dev, off, count, buf); |
| 734 | } |
Ben Hutchings | 94e6108 | 2008-03-05 16:52:39 +0000 | [diff] [blame] | 735 | |
Stephen Hemminger | 287d19c | 2008-12-18 09:17:16 -0800 | [diff] [blame] | 736 | static ssize_t |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 737 | write_vpd_attr(struct file *filp, struct kobject *kobj, |
| 738 | struct bin_attribute *bin_attr, |
Stephen Hemminger | 287d19c | 2008-12-18 09:17:16 -0800 | [diff] [blame] | 739 | char *buf, loff_t off, size_t count) |
| 740 | { |
| 741 | struct pci_dev *dev = |
| 742 | to_pci_dev(container_of(kobj, struct device, kobj)); |
| 743 | |
| 744 | if (off > bin_attr->size) |
| 745 | count = 0; |
| 746 | else if (count > bin_attr->size - off) |
| 747 | count = bin_attr->size - off; |
| 748 | |
| 749 | return pci_write_vpd(dev, off, count, buf); |
Ben Hutchings | 94e6108 | 2008-03-05 16:52:39 +0000 | [diff] [blame] | 750 | } |
| 751 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | #ifdef HAVE_PCI_LEGACY |
| 753 | /** |
| 754 | * pci_read_legacy_io - read byte(s) from legacy I/O port space |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 755 | * @filp: open sysfs file |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | * @kobj: kobject corresponding to file to read from |
Randy Dunlap | cffb2fa | 2009-04-10 15:17:50 -0700 | [diff] [blame] | 757 | * @bin_attr: struct bin_attribute for this file |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | * @buf: buffer to store results |
| 759 | * @off: offset into legacy I/O port space |
| 760 | * @count: number of bytes to read |
| 761 | * |
| 762 | * Reads 1, 2, or 4 bytes from legacy I/O port space using an arch specific |
| 763 | * callback routine (pci_legacy_read). |
| 764 | */ |
Benjamin Herrenschmidt | f19aeb1 | 2008-10-03 19:49:32 +1000 | [diff] [blame] | 765 | static ssize_t |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 766 | pci_read_legacy_io(struct file *filp, struct kobject *kobj, |
| 767 | struct bin_attribute *bin_attr, |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 768 | char *buf, loff_t off, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | { |
| 770 | struct pci_bus *bus = to_pci_bus(container_of(kobj, |
Greg Kroah-Hartman | fd7d1ce | 2007-05-22 22:47:54 -0400 | [diff] [blame] | 771 | struct device, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | kobj)); |
| 773 | |
| 774 | /* Only support 1, 2 or 4 byte accesses */ |
| 775 | if (count != 1 && count != 2 && count != 4) |
| 776 | return -EINVAL; |
| 777 | |
| 778 | return pci_legacy_read(bus, off, (u32 *)buf, count); |
| 779 | } |
| 780 | |
| 781 | /** |
| 782 | * pci_write_legacy_io - write byte(s) to legacy I/O port space |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 783 | * @filp: open sysfs file |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | * @kobj: kobject corresponding to file to read from |
Randy Dunlap | cffb2fa | 2009-04-10 15:17:50 -0700 | [diff] [blame] | 785 | * @bin_attr: struct bin_attribute for this file |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | * @buf: buffer containing value to be written |
| 787 | * @off: offset into legacy I/O port space |
| 788 | * @count: number of bytes to write |
| 789 | * |
| 790 | * Writes 1, 2, or 4 bytes from legacy I/O port space using an arch specific |
| 791 | * callback routine (pci_legacy_write). |
| 792 | */ |
Benjamin Herrenschmidt | f19aeb1 | 2008-10-03 19:49:32 +1000 | [diff] [blame] | 793 | static ssize_t |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 794 | pci_write_legacy_io(struct file *filp, struct kobject *kobj, |
| 795 | struct bin_attribute *bin_attr, |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 796 | char *buf, loff_t off, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | { |
| 798 | struct pci_bus *bus = to_pci_bus(container_of(kobj, |
Greg Kroah-Hartman | fd7d1ce | 2007-05-22 22:47:54 -0400 | [diff] [blame] | 799 | struct device, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | kobj)); |
| 801 | /* Only support 1, 2 or 4 byte accesses */ |
| 802 | if (count != 1 && count != 2 && count != 4) |
| 803 | return -EINVAL; |
| 804 | |
| 805 | return pci_legacy_write(bus, off, *(u32 *)buf, count); |
| 806 | } |
| 807 | |
| 808 | /** |
| 809 | * pci_mmap_legacy_mem - map legacy PCI memory into user memory space |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 810 | * @filp: open sysfs file |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | * @kobj: kobject corresponding to device to be mapped |
| 812 | * @attr: struct bin_attribute for this file |
| 813 | * @vma: struct vm_area_struct passed to mmap |
| 814 | * |
Benjamin Herrenschmidt | f19aeb1 | 2008-10-03 19:49:32 +1000 | [diff] [blame] | 815 | * 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] | 816 | * legacy memory space (first meg of bus space) into application virtual |
| 817 | * memory space. |
| 818 | */ |
Benjamin Herrenschmidt | f19aeb1 | 2008-10-03 19:49:32 +1000 | [diff] [blame] | 819 | static int |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 820 | pci_mmap_legacy_mem(struct file *filp, struct kobject *kobj, |
| 821 | struct bin_attribute *attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | struct vm_area_struct *vma) |
| 823 | { |
| 824 | struct pci_bus *bus = to_pci_bus(container_of(kobj, |
Greg Kroah-Hartman | fd7d1ce | 2007-05-22 22:47:54 -0400 | [diff] [blame] | 825 | struct device, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | kobj)); |
| 827 | |
Benjamin Herrenschmidt | f19aeb1 | 2008-10-03 19:49:32 +1000 | [diff] [blame] | 828 | return pci_mmap_legacy_page_range(bus, vma, pci_mmap_mem); |
| 829 | } |
| 830 | |
| 831 | /** |
| 832 | * pci_mmap_legacy_io - map legacy PCI IO into user memory space |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 833 | * @filp: open sysfs file |
Benjamin Herrenschmidt | f19aeb1 | 2008-10-03 19:49:32 +1000 | [diff] [blame] | 834 | * @kobj: kobject corresponding to device to be mapped |
| 835 | * @attr: struct bin_attribute for this file |
| 836 | * @vma: struct vm_area_struct passed to mmap |
| 837 | * |
| 838 | * Uses an arch specific callback, pci_mmap_legacy_io_page_range, to mmap |
| 839 | * legacy IO space (first meg of bus space) into application virtual |
| 840 | * memory space. Returns -ENOSYS if the operation isn't supported |
| 841 | */ |
| 842 | static int |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 843 | pci_mmap_legacy_io(struct file *filp, struct kobject *kobj, |
| 844 | struct bin_attribute *attr, |
Benjamin Herrenschmidt | f19aeb1 | 2008-10-03 19:49:32 +1000 | [diff] [blame] | 845 | struct vm_area_struct *vma) |
| 846 | { |
| 847 | struct pci_bus *bus = to_pci_bus(container_of(kobj, |
| 848 | struct device, |
| 849 | kobj)); |
| 850 | |
| 851 | return pci_mmap_legacy_page_range(bus, vma, pci_mmap_io); |
| 852 | } |
| 853 | |
| 854 | /** |
Ivan Kokshaysky | 10a0ef3 | 2009-02-17 13:46:53 +0300 | [diff] [blame] | 855 | * pci_adjust_legacy_attr - adjustment of legacy file attributes |
| 856 | * @b: bus to create files under |
| 857 | * @mmap_type: I/O port or memory |
| 858 | * |
| 859 | * Stub implementation. Can be overridden by arch if necessary. |
| 860 | */ |
| 861 | void __weak |
| 862 | pci_adjust_legacy_attr(struct pci_bus *b, enum pci_mmap_state mmap_type) |
| 863 | { |
| 864 | return; |
| 865 | } |
| 866 | |
| 867 | /** |
Benjamin Herrenschmidt | f19aeb1 | 2008-10-03 19:49:32 +1000 | [diff] [blame] | 868 | * pci_create_legacy_files - create legacy I/O port and memory files |
| 869 | * @b: bus to create files under |
| 870 | * |
| 871 | * Some platforms allow access to legacy I/O port and ISA memory space on |
| 872 | * a per-bus basis. This routine creates the files and ties them into |
| 873 | * their associated read, write and mmap files from pci-sysfs.c |
| 874 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 875 | * On error unwind, but don't propagate the error to the caller |
Benjamin Herrenschmidt | f19aeb1 | 2008-10-03 19:49:32 +1000 | [diff] [blame] | 876 | * as it is ok to set up the PCI bus without these files. |
| 877 | */ |
| 878 | void pci_create_legacy_files(struct pci_bus *b) |
| 879 | { |
| 880 | int error; |
| 881 | |
| 882 | b->legacy_io = kzalloc(sizeof(struct bin_attribute) * 2, |
| 883 | GFP_ATOMIC); |
| 884 | if (!b->legacy_io) |
| 885 | goto kzalloc_err; |
| 886 | |
Stephen Rothwell | 62e877b8 | 2010-03-01 20:38:36 +1100 | [diff] [blame] | 887 | sysfs_bin_attr_init(b->legacy_io); |
Benjamin Herrenschmidt | f19aeb1 | 2008-10-03 19:49:32 +1000 | [diff] [blame] | 888 | b->legacy_io->attr.name = "legacy_io"; |
| 889 | b->legacy_io->size = 0xffff; |
| 890 | b->legacy_io->attr.mode = S_IRUSR | S_IWUSR; |
| 891 | b->legacy_io->read = pci_read_legacy_io; |
| 892 | b->legacy_io->write = pci_write_legacy_io; |
| 893 | b->legacy_io->mmap = pci_mmap_legacy_io; |
Ivan Kokshaysky | 10a0ef3 | 2009-02-17 13:46:53 +0300 | [diff] [blame] | 894 | pci_adjust_legacy_attr(b, pci_mmap_io); |
Benjamin Herrenschmidt | f19aeb1 | 2008-10-03 19:49:32 +1000 | [diff] [blame] | 895 | error = device_create_bin_file(&b->dev, b->legacy_io); |
| 896 | if (error) |
| 897 | goto legacy_io_err; |
| 898 | |
| 899 | /* Allocated above after the legacy_io struct */ |
| 900 | b->legacy_mem = b->legacy_io + 1; |
Mel Gorman | 6757eca3 | 2010-03-10 22:48:34 +0000 | [diff] [blame] | 901 | sysfs_bin_attr_init(b->legacy_mem); |
Benjamin Herrenschmidt | f19aeb1 | 2008-10-03 19:49:32 +1000 | [diff] [blame] | 902 | b->legacy_mem->attr.name = "legacy_mem"; |
| 903 | b->legacy_mem->size = 1024*1024; |
| 904 | b->legacy_mem->attr.mode = S_IRUSR | S_IWUSR; |
| 905 | b->legacy_mem->mmap = pci_mmap_legacy_mem; |
Ivan Kokshaysky | 10a0ef3 | 2009-02-17 13:46:53 +0300 | [diff] [blame] | 906 | pci_adjust_legacy_attr(b, pci_mmap_mem); |
Benjamin Herrenschmidt | f19aeb1 | 2008-10-03 19:49:32 +1000 | [diff] [blame] | 907 | error = device_create_bin_file(&b->dev, b->legacy_mem); |
| 908 | if (error) |
| 909 | goto legacy_mem_err; |
| 910 | |
| 911 | return; |
| 912 | |
| 913 | legacy_mem_err: |
| 914 | device_remove_bin_file(&b->dev, b->legacy_io); |
| 915 | legacy_io_err: |
| 916 | kfree(b->legacy_io); |
| 917 | b->legacy_io = NULL; |
| 918 | kzalloc_err: |
| 919 | printk(KERN_WARNING "pci: warning: could not create legacy I/O port " |
| 920 | "and ISA memory resources to sysfs\n"); |
| 921 | return; |
| 922 | } |
| 923 | |
| 924 | void pci_remove_legacy_files(struct pci_bus *b) |
| 925 | { |
| 926 | if (b->legacy_io) { |
| 927 | device_remove_bin_file(&b->dev, b->legacy_io); |
| 928 | device_remove_bin_file(&b->dev, b->legacy_mem); |
| 929 | kfree(b->legacy_io); /* both are allocated here */ |
| 930 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | } |
| 932 | #endif /* HAVE_PCI_LEGACY */ |
| 933 | |
| 934 | #ifdef HAVE_PCI_MMAP |
Linus Torvalds | b5ff7df | 2008-10-02 18:52:51 -0700 | [diff] [blame] | 935 | |
Martin Wilck | 3b519e4 | 2010-11-10 11:03:21 +0100 | [diff] [blame] | 936 | int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vma, |
| 937 | enum pci_mmap_api mmap_api) |
Linus Torvalds | b5ff7df | 2008-10-02 18:52:51 -0700 | [diff] [blame] | 938 | { |
Martin Wilck | 3b519e4 | 2010-11-10 11:03:21 +0100 | [diff] [blame] | 939 | unsigned long nr, start, size, pci_start; |
Linus Torvalds | b5ff7df | 2008-10-02 18:52:51 -0700 | [diff] [blame] | 940 | |
Martin Wilck | 3b519e4 | 2010-11-10 11:03:21 +0100 | [diff] [blame] | 941 | if (pci_resource_len(pdev, resno) == 0) |
| 942 | return 0; |
Libin | 64b0017 | 2013-04-15 02:48:54 +0000 | [diff] [blame] | 943 | nr = vma_pages(vma); |
Linus Torvalds | b5ff7df | 2008-10-02 18:52:51 -0700 | [diff] [blame] | 944 | start = vma->vm_pgoff; |
Ed Swierk | 88e7df0 | 2008-11-03 14:41:16 -0800 | [diff] [blame] | 945 | size = ((pci_resource_len(pdev, resno) - 1) >> PAGE_SHIFT) + 1; |
Darrick J. Wong | 8c05cd0 | 2010-11-16 09:13:41 -0800 | [diff] [blame] | 946 | pci_start = (mmap_api == PCI_MMAP_PROCFS) ? |
Martin Wilck | 3b519e4 | 2010-11-10 11:03:21 +0100 | [diff] [blame] | 947 | pci_resource_start(pdev, resno) >> PAGE_SHIFT : 0; |
| 948 | if (start >= pci_start && start < pci_start + size && |
| 949 | start + nr <= pci_start + size) |
Linus Torvalds | b5ff7df | 2008-10-02 18:52:51 -0700 | [diff] [blame] | 950 | return 1; |
Linus Torvalds | b5ff7df | 2008-10-02 18:52:51 -0700 | [diff] [blame] | 951 | return 0; |
| 952 | } |
| 953 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | /** |
| 955 | * pci_mmap_resource - map a PCI resource into user memory space |
| 956 | * @kobj: kobject for mapping |
| 957 | * @attr: struct bin_attribute for the file being mapped |
| 958 | * @vma: struct vm_area_struct passed into the mmap |
venkatesh.pallipadi@intel.com | 45aec1ae | 2008-03-18 17:00:22 -0700 | [diff] [blame] | 959 | * @write_combine: 1 for write_combine mapping |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | * |
| 961 | * 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] | 962 | */ |
| 963 | static int |
| 964 | pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr, |
venkatesh.pallipadi@intel.com | 45aec1ae | 2008-03-18 17:00:22 -0700 | [diff] [blame] | 965 | struct vm_area_struct *vma, int write_combine) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | { |
| 967 | struct pci_dev *pdev = to_pci_dev(container_of(kobj, |
| 968 | struct device, kobj)); |
Kulikov Vasiliy | a3f5835 | 2010-06-29 14:15:28 +0400 | [diff] [blame] | 969 | struct resource *res = attr->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | enum pci_mmap_state mmap_type; |
Greg Kroah-Hartman | e31dd6e | 2006-06-12 17:06:02 -0700 | [diff] [blame] | 971 | resource_size_t start, end; |
Michael Ellerman | 2311b1f | 2005-05-13 17:44:10 +1000 | [diff] [blame] | 972 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | |
Michael Ellerman | 2311b1f | 2005-05-13 17:44:10 +1000 | [diff] [blame] | 974 | for (i = 0; i < PCI_ROM_RESOURCE; i++) |
| 975 | if (res == &pdev->resource[i]) |
| 976 | break; |
| 977 | if (i >= PCI_ROM_RESOURCE) |
| 978 | return -ENODEV; |
| 979 | |
Martin Wilck | 3b519e4 | 2010-11-10 11:03:21 +0100 | [diff] [blame] | 980 | if (!pci_mmap_fits(pdev, i, vma, PCI_MMAP_SYSFS)) { |
| 981 | WARN(1, "process \"%s\" tried to map 0x%08lx bytes " |
| 982 | "at page 0x%08lx on %s BAR %d (start 0x%16Lx, size 0x%16Lx)\n", |
| 983 | current->comm, vma->vm_end-vma->vm_start, vma->vm_pgoff, |
| 984 | pci_name(pdev), i, |
Randy Dunlap | e25cd06 | 2010-11-13 08:44:33 -0800 | [diff] [blame] | 985 | (u64)pci_resource_start(pdev, i), |
| 986 | (u64)pci_resource_len(pdev, i)); |
Linus Torvalds | b5ff7df | 2008-10-02 18:52:51 -0700 | [diff] [blame] | 987 | return -EINVAL; |
Martin Wilck | 3b519e4 | 2010-11-10 11:03:21 +0100 | [diff] [blame] | 988 | } |
Linus Torvalds | b5ff7df | 2008-10-02 18:52:51 -0700 | [diff] [blame] | 989 | |
Michael Ellerman | 2311b1f | 2005-05-13 17:44:10 +1000 | [diff] [blame] | 990 | /* pci_mmap_page_range() expects the same kind of entry as coming |
| 991 | * from /proc/bus/pci/ which is a "user visible" value. If this is |
| 992 | * different from the resource itself, arch will do necessary fixup. |
| 993 | */ |
| 994 | pci_resource_to_user(pdev, i, res, &start, &end); |
| 995 | vma->vm_pgoff += start >> PAGE_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | mmap_type = res->flags & IORESOURCE_MEM ? pci_mmap_mem : pci_mmap_io; |
| 997 | |
Arjan van de Ven | e8de148 | 2008-10-22 19:55:31 -0700 | [diff] [blame] | 998 | if (res->flags & IORESOURCE_MEM && iomem_is_exclusive(start)) |
| 999 | return -EINVAL; |
| 1000 | |
venkatesh.pallipadi@intel.com | 45aec1ae | 2008-03-18 17:00:22 -0700 | [diff] [blame] | 1001 | return pci_mmap_page_range(pdev, vma, mmap_type, write_combine); |
| 1002 | } |
| 1003 | |
| 1004 | static int |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 1005 | pci_mmap_resource_uc(struct file *filp, struct kobject *kobj, |
| 1006 | struct bin_attribute *attr, |
venkatesh.pallipadi@intel.com | 45aec1ae | 2008-03-18 17:00:22 -0700 | [diff] [blame] | 1007 | struct vm_area_struct *vma) |
| 1008 | { |
| 1009 | return pci_mmap_resource(kobj, attr, vma, 0); |
| 1010 | } |
| 1011 | |
| 1012 | static int |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 1013 | pci_mmap_resource_wc(struct file *filp, struct kobject *kobj, |
| 1014 | struct bin_attribute *attr, |
venkatesh.pallipadi@intel.com | 45aec1ae | 2008-03-18 17:00:22 -0700 | [diff] [blame] | 1015 | struct vm_area_struct *vma) |
| 1016 | { |
| 1017 | return pci_mmap_resource(kobj, attr, vma, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | } |
| 1019 | |
Alex Williamson | 8633328 | 2010-07-19 09:45:34 -0600 | [diff] [blame] | 1020 | static ssize_t |
| 1021 | pci_resource_io(struct file *filp, struct kobject *kobj, |
| 1022 | struct bin_attribute *attr, char *buf, |
| 1023 | loff_t off, size_t count, bool write) |
| 1024 | { |
| 1025 | struct pci_dev *pdev = to_pci_dev(container_of(kobj, |
| 1026 | struct device, kobj)); |
| 1027 | struct resource *res = attr->private; |
| 1028 | unsigned long port = off; |
| 1029 | int i; |
| 1030 | |
| 1031 | for (i = 0; i < PCI_ROM_RESOURCE; i++) |
| 1032 | if (res == &pdev->resource[i]) |
| 1033 | break; |
| 1034 | if (i >= PCI_ROM_RESOURCE) |
| 1035 | return -ENODEV; |
| 1036 | |
| 1037 | port += pci_resource_start(pdev, i); |
| 1038 | |
| 1039 | if (port > pci_resource_end(pdev, i)) |
| 1040 | return 0; |
| 1041 | |
| 1042 | if (port + count - 1 > pci_resource_end(pdev, i)) |
| 1043 | return -EINVAL; |
| 1044 | |
| 1045 | switch (count) { |
| 1046 | case 1: |
| 1047 | if (write) |
| 1048 | outb(*(u8 *)buf, port); |
| 1049 | else |
| 1050 | *(u8 *)buf = inb(port); |
| 1051 | return 1; |
| 1052 | case 2: |
| 1053 | if (write) |
| 1054 | outw(*(u16 *)buf, port); |
| 1055 | else |
| 1056 | *(u16 *)buf = inw(port); |
| 1057 | return 2; |
| 1058 | case 4: |
| 1059 | if (write) |
| 1060 | outl(*(u32 *)buf, port); |
| 1061 | else |
| 1062 | *(u32 *)buf = inl(port); |
| 1063 | return 4; |
| 1064 | } |
| 1065 | return -EINVAL; |
| 1066 | } |
| 1067 | |
| 1068 | static ssize_t |
| 1069 | pci_read_resource_io(struct file *filp, struct kobject *kobj, |
| 1070 | struct bin_attribute *attr, char *buf, |
| 1071 | loff_t off, size_t count) |
| 1072 | { |
| 1073 | return pci_resource_io(filp, kobj, attr, buf, off, count, false); |
| 1074 | } |
| 1075 | |
| 1076 | static ssize_t |
| 1077 | pci_write_resource_io(struct file *filp, struct kobject *kobj, |
| 1078 | struct bin_attribute *attr, char *buf, |
| 1079 | loff_t off, size_t count) |
| 1080 | { |
| 1081 | return pci_resource_io(filp, kobj, attr, buf, off, count, true); |
| 1082 | } |
| 1083 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | /** |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 1085 | * pci_remove_resource_files - cleanup resource files |
Randy Dunlap | cffb2fa | 2009-04-10 15:17:50 -0700 | [diff] [blame] | 1086 | * @pdev: dev to cleanup |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 1087 | * |
Randy Dunlap | cffb2fa | 2009-04-10 15:17:50 -0700 | [diff] [blame] | 1088 | * If we created resource files for @pdev, remove them from sysfs and |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 1089 | * free their resources. |
| 1090 | */ |
| 1091 | static void |
| 1092 | pci_remove_resource_files(struct pci_dev *pdev) |
| 1093 | { |
| 1094 | int i; |
| 1095 | |
| 1096 | for (i = 0; i < PCI_ROM_RESOURCE; i++) { |
| 1097 | struct bin_attribute *res_attr; |
| 1098 | |
| 1099 | res_attr = pdev->res_attr[i]; |
| 1100 | if (res_attr) { |
| 1101 | sysfs_remove_bin_file(&pdev->dev.kobj, res_attr); |
| 1102 | kfree(res_attr); |
| 1103 | } |
venkatesh.pallipadi@intel.com | 45aec1ae | 2008-03-18 17:00:22 -0700 | [diff] [blame] | 1104 | |
| 1105 | res_attr = pdev->res_attr_wc[i]; |
| 1106 | if (res_attr) { |
| 1107 | sysfs_remove_bin_file(&pdev->dev.kobj, res_attr); |
| 1108 | kfree(res_attr); |
| 1109 | } |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 1110 | } |
| 1111 | } |
| 1112 | |
venkatesh.pallipadi@intel.com | 45aec1ae | 2008-03-18 17:00:22 -0700 | [diff] [blame] | 1113 | static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine) |
| 1114 | { |
| 1115 | /* allocate attribute structure, piggyback attribute name */ |
| 1116 | int name_len = write_combine ? 13 : 10; |
| 1117 | struct bin_attribute *res_attr; |
| 1118 | int retval; |
| 1119 | |
| 1120 | res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC); |
| 1121 | if (res_attr) { |
| 1122 | char *res_attr_name = (char *)(res_attr + 1); |
| 1123 | |
Eric W. Biederman | a07e415 | 2010-02-11 15:23:05 -0800 | [diff] [blame] | 1124 | sysfs_bin_attr_init(res_attr); |
venkatesh.pallipadi@intel.com | 45aec1ae | 2008-03-18 17:00:22 -0700 | [diff] [blame] | 1125 | if (write_combine) { |
| 1126 | pdev->res_attr_wc[num] = res_attr; |
| 1127 | sprintf(res_attr_name, "resource%d_wc", num); |
| 1128 | res_attr->mmap = pci_mmap_resource_wc; |
| 1129 | } else { |
| 1130 | pdev->res_attr[num] = res_attr; |
| 1131 | sprintf(res_attr_name, "resource%d", num); |
| 1132 | res_attr->mmap = pci_mmap_resource_uc; |
| 1133 | } |
Alex Williamson | 8633328 | 2010-07-19 09:45:34 -0600 | [diff] [blame] | 1134 | if (pci_resource_flags(pdev, num) & IORESOURCE_IO) { |
| 1135 | res_attr->read = pci_read_resource_io; |
| 1136 | res_attr->write = pci_write_resource_io; |
| 1137 | } |
venkatesh.pallipadi@intel.com | 45aec1ae | 2008-03-18 17:00:22 -0700 | [diff] [blame] | 1138 | res_attr->attr.name = res_attr_name; |
| 1139 | res_attr->attr.mode = S_IRUSR | S_IWUSR; |
| 1140 | res_attr->size = pci_resource_len(pdev, num); |
| 1141 | res_attr->private = &pdev->resource[num]; |
| 1142 | retval = sysfs_create_bin_file(&pdev->dev.kobj, res_attr); |
| 1143 | } else |
| 1144 | retval = -ENOMEM; |
| 1145 | |
| 1146 | return retval; |
| 1147 | } |
| 1148 | |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 1149 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | * pci_create_resource_files - create resource files in sysfs for @dev |
Randy Dunlap | cffb2fa | 2009-04-10 15:17:50 -0700 | [diff] [blame] | 1151 | * @pdev: dev in question |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | * |
Randy Dunlap | cffb2fa | 2009-04-10 15:17:50 -0700 | [diff] [blame] | 1153 | * Walk the resources in @pdev creating files for each resource available. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | */ |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 1155 | static int pci_create_resource_files(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | { |
| 1157 | int i; |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 1158 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | |
| 1160 | /* Expose the PCI resources from this device as files */ |
| 1161 | for (i = 0; i < PCI_ROM_RESOURCE; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | |
| 1163 | /* skip empty resources */ |
| 1164 | if (!pci_resource_len(pdev, i)) |
| 1165 | continue; |
| 1166 | |
venkatesh.pallipadi@intel.com | 45aec1ae | 2008-03-18 17:00:22 -0700 | [diff] [blame] | 1167 | retval = pci_create_attr(pdev, i, 0); |
| 1168 | /* for prefetchable resources, create a WC mappable file */ |
| 1169 | if (!retval && pdev->resource[i].flags & IORESOURCE_PREFETCH) |
| 1170 | retval = pci_create_attr(pdev, i, 1); |
Dmitry Torokhov | d48593b | 2005-04-29 00:58:46 -0500 | [diff] [blame] | 1171 | |
venkatesh.pallipadi@intel.com | 45aec1ae | 2008-03-18 17:00:22 -0700 | [diff] [blame] | 1172 | if (retval) { |
| 1173 | pci_remove_resource_files(pdev); |
| 1174 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | } |
| 1176 | } |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 1177 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | } |
| 1179 | #else /* !HAVE_PCI_MMAP */ |
Ivan Kokshaysky | 10a0ef3 | 2009-02-17 13:46:53 +0300 | [diff] [blame] | 1180 | int __weak pci_create_resource_files(struct pci_dev *dev) { return 0; } |
| 1181 | void __weak pci_remove_resource_files(struct pci_dev *dev) { return; } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | #endif /* HAVE_PCI_MMAP */ |
| 1183 | |
| 1184 | /** |
| 1185 | * pci_write_rom - used to enable access to the PCI ROM display |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 1186 | * @filp: sysfs file |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | * @kobj: kernel object handle |
Randy Dunlap | cffb2fa | 2009-04-10 15:17:50 -0700 | [diff] [blame] | 1188 | * @bin_attr: struct bin_attribute for this file |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | * @buf: user input |
| 1190 | * @off: file offset |
| 1191 | * @count: number of byte in input |
| 1192 | * |
| 1193 | * writing anything except 0 enables it |
| 1194 | */ |
| 1195 | static ssize_t |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 1196 | pci_write_rom(struct file *filp, struct kobject *kobj, |
| 1197 | struct bin_attribute *bin_attr, |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 1198 | char *buf, loff_t off, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | { |
| 1200 | struct pci_dev *pdev = to_pci_dev(container_of(kobj, struct device, kobj)); |
| 1201 | |
| 1202 | if ((off == 0) && (*buf == '0') && (count == 2)) |
| 1203 | pdev->rom_attr_enabled = 0; |
| 1204 | else |
| 1205 | pdev->rom_attr_enabled = 1; |
| 1206 | |
| 1207 | return count; |
| 1208 | } |
| 1209 | |
| 1210 | /** |
| 1211 | * pci_read_rom - read a PCI ROM |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 1212 | * @filp: sysfs file |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | * @kobj: kernel object handle |
Randy Dunlap | cffb2fa | 2009-04-10 15:17:50 -0700 | [diff] [blame] | 1214 | * @bin_attr: struct bin_attribute for this file |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | * @buf: where to put the data we read from the ROM |
| 1216 | * @off: file offset |
| 1217 | * @count: number of bytes to read |
| 1218 | * |
| 1219 | * Put @count bytes starting at @off into @buf from the ROM in the PCI |
| 1220 | * device corresponding to @kobj. |
| 1221 | */ |
| 1222 | static ssize_t |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 1223 | pci_read_rom(struct file *filp, struct kobject *kobj, |
| 1224 | struct bin_attribute *bin_attr, |
Zhang Rui | 91a6902 | 2007-06-09 13:57:22 +0800 | [diff] [blame] | 1225 | char *buf, loff_t off, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | { |
| 1227 | struct pci_dev *pdev = to_pci_dev(container_of(kobj, struct device, kobj)); |
| 1228 | void __iomem *rom; |
| 1229 | size_t size; |
| 1230 | |
| 1231 | if (!pdev->rom_attr_enabled) |
| 1232 | return -EINVAL; |
| 1233 | |
| 1234 | 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] | 1235 | if (!rom || !size) |
| 1236 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | |
| 1238 | if (off >= size) |
| 1239 | count = 0; |
| 1240 | else { |
| 1241 | if (off + count > size) |
| 1242 | count = size - off; |
| 1243 | |
| 1244 | memcpy_fromio(buf, rom + off, count); |
| 1245 | } |
| 1246 | pci_unmap_rom(pdev, rom); |
| 1247 | |
| 1248 | return count; |
| 1249 | } |
| 1250 | |
| 1251 | static struct bin_attribute pci_config_attr = { |
| 1252 | .attr = { |
| 1253 | .name = "config", |
| 1254 | .mode = S_IRUGO | S_IWUSR, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | }, |
Zhao, Yu | 557848c | 2008-10-13 19:18:07 +0800 | [diff] [blame] | 1256 | .size = PCI_CFG_SPACE_SIZE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | .read = pci_read_config, |
| 1258 | .write = pci_write_config, |
| 1259 | }; |
| 1260 | |
| 1261 | static struct bin_attribute pcie_config_attr = { |
| 1262 | .attr = { |
| 1263 | .name = "config", |
| 1264 | .mode = S_IRUGO | S_IWUSR, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | }, |
Zhao, Yu | 557848c | 2008-10-13 19:18:07 +0800 | [diff] [blame] | 1266 | .size = PCI_CFG_SPACE_EXP_SIZE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | .read = pci_read_config, |
| 1268 | .write = pci_write_config, |
| 1269 | }; |
| 1270 | |
Bjorn Helgaas | d6d88c8 | 2012-06-19 06:54:49 -0600 | [diff] [blame] | 1271 | int __weak pcibios_add_platform_entries(struct pci_dev *dev) |
Michael Ellerman | 575e334 | 2007-05-08 12:03:07 +1000 | [diff] [blame] | 1272 | { |
Michael Ellerman | a2cd52c | 2007-05-08 12:03:08 +1000 | [diff] [blame] | 1273 | return 0; |
Michael Ellerman | 575e334 | 2007-05-08 12:03:07 +1000 | [diff] [blame] | 1274 | } |
| 1275 | |
Michael S. Tsirkin | 711d577 | 2009-07-27 23:37:48 +0300 | [diff] [blame] | 1276 | static ssize_t reset_store(struct device *dev, |
| 1277 | struct device_attribute *attr, const char *buf, |
| 1278 | size_t count) |
| 1279 | { |
| 1280 | struct pci_dev *pdev = to_pci_dev(dev); |
| 1281 | unsigned long val; |
Jingoo Han | 9a994e8 | 2013-06-01 16:25:25 +0900 | [diff] [blame] | 1282 | ssize_t result = kstrtoul(buf, 0, &val); |
Michael S. Tsirkin | 711d577 | 2009-07-27 23:37:48 +0300 | [diff] [blame] | 1283 | |
| 1284 | if (result < 0) |
| 1285 | return result; |
| 1286 | |
| 1287 | if (val != 1) |
| 1288 | return -EINVAL; |
Michal Schmidt | 447c5dd | 2010-05-11 11:44:54 +0200 | [diff] [blame] | 1289 | |
| 1290 | result = pci_reset_function(pdev); |
| 1291 | if (result < 0) |
| 1292 | return result; |
| 1293 | |
| 1294 | return count; |
Michael S. Tsirkin | 711d577 | 2009-07-27 23:37:48 +0300 | [diff] [blame] | 1295 | } |
| 1296 | |
| 1297 | static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_store); |
| 1298 | |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 1299 | static int pci_create_capabilities_sysfs(struct pci_dev *dev) |
| 1300 | { |
| 1301 | int retval; |
| 1302 | struct bin_attribute *attr; |
| 1303 | |
| 1304 | /* If the device has VPD, try to expose it in sysfs. */ |
| 1305 | if (dev->vpd) { |
| 1306 | attr = kzalloc(sizeof(*attr), GFP_ATOMIC); |
| 1307 | if (!attr) |
| 1308 | return -ENOMEM; |
| 1309 | |
Eric W. Biederman | a07e415 | 2010-02-11 15:23:05 -0800 | [diff] [blame] | 1310 | sysfs_bin_attr_init(attr); |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 1311 | attr->size = dev->vpd->len; |
| 1312 | attr->attr.name = "vpd"; |
| 1313 | attr->attr.mode = S_IRUSR | S_IWUSR; |
Stephen Hemminger | 287d19c | 2008-12-18 09:17:16 -0800 | [diff] [blame] | 1314 | attr->read = read_vpd_attr; |
| 1315 | attr->write = write_vpd_attr; |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 1316 | retval = sysfs_create_bin_file(&dev->dev.kobj, attr); |
| 1317 | if (retval) { |
Ben Hutchings | 0f12a4e | 2011-01-13 19:47:56 +0000 | [diff] [blame] | 1318 | kfree(attr); |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 1319 | return retval; |
| 1320 | } |
| 1321 | dev->vpd->attr = attr; |
| 1322 | } |
| 1323 | |
| 1324 | /* Active State Power Management */ |
| 1325 | pcie_aspm_create_sysfs_dev_files(dev); |
| 1326 | |
Michael S. Tsirkin | 711d577 | 2009-07-27 23:37:48 +0300 | [diff] [blame] | 1327 | if (!pci_probe_reset_function(dev)) { |
| 1328 | retval = device_create_file(&dev->dev, &reset_attr); |
| 1329 | if (retval) |
| 1330 | goto error; |
| 1331 | dev->reset_fn = 1; |
| 1332 | } |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 1333 | return 0; |
Michael S. Tsirkin | 711d577 | 2009-07-27 23:37:48 +0300 | [diff] [blame] | 1334 | |
| 1335 | error: |
| 1336 | pcie_aspm_remove_sysfs_dev_files(dev); |
| 1337 | if (dev->vpd && dev->vpd->attr) { |
| 1338 | sysfs_remove_bin_file(&dev->dev.kobj, dev->vpd->attr); |
| 1339 | kfree(dev->vpd->attr); |
| 1340 | } |
| 1341 | |
| 1342 | return retval; |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 1343 | } |
| 1344 | |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 1345 | int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | { |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 1347 | int retval; |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 1348 | int rom_size = 0; |
| 1349 | struct bin_attribute *attr; |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 1350 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | if (!sysfs_initialized) |
| 1352 | return -EACCES; |
| 1353 | |
Zhao, Yu | 557848c | 2008-10-13 19:18:07 +0800 | [diff] [blame] | 1354 | if (pdev->cfg_size < PCI_CFG_SPACE_EXP_SIZE) |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 1355 | retval = sysfs_create_bin_file(&pdev->dev.kobj, &pci_config_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | else |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 1357 | retval = sysfs_create_bin_file(&pdev->dev.kobj, &pcie_config_attr); |
| 1358 | if (retval) |
| 1359 | goto err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 1361 | retval = pci_create_resource_files(pdev); |
| 1362 | if (retval) |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 1363 | goto err_config_file; |
| 1364 | |
| 1365 | if (pci_resource_len(pdev, PCI_ROM_RESOURCE)) |
| 1366 | rom_size = pci_resource_len(pdev, PCI_ROM_RESOURCE); |
| 1367 | else if (pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW) |
| 1368 | rom_size = 0x20000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | |
| 1370 | /* If the device has a ROM, try to expose it in sysfs. */ |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 1371 | if (rom_size) { |
Ben Hutchings | 94e6108 | 2008-03-05 16:52:39 +0000 | [diff] [blame] | 1372 | attr = kzalloc(sizeof(*attr), GFP_ATOMIC); |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 1373 | if (!attr) { |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 1374 | retval = -ENOMEM; |
Michael Ellerman | 9890b12 | 2007-04-18 13:34:12 +1000 | [diff] [blame] | 1375 | goto err_resource_files; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1376 | } |
Eric W. Biederman | a07e415 | 2010-02-11 15:23:05 -0800 | [diff] [blame] | 1377 | sysfs_bin_attr_init(attr); |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 1378 | attr->size = rom_size; |
| 1379 | attr->attr.name = "rom"; |
Alex Williamson | ff29530 | 2011-01-05 10:26:41 -0700 | [diff] [blame] | 1380 | attr->attr.mode = S_IRUSR | S_IWUSR; |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 1381 | attr->read = pci_read_rom; |
| 1382 | attr->write = pci_write_rom; |
| 1383 | retval = sysfs_create_bin_file(&pdev->dev.kobj, attr); |
| 1384 | if (retval) { |
| 1385 | kfree(attr); |
| 1386 | goto err_resource_files; |
| 1387 | } |
| 1388 | pdev->rom_attr = attr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | } |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 1390 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1391 | /* add platform-specific attributes */ |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 1392 | retval = pcibios_add_platform_entries(pdev); |
| 1393 | if (retval) |
Yinghai Lu | 625e1d5 | 2012-11-05 15:20:35 -0500 | [diff] [blame] | 1394 | goto err_rom_file; |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 1395 | |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 1396 | /* add sysfs entries for various capabilities */ |
| 1397 | retval = pci_create_capabilities_sysfs(pdev); |
| 1398 | if (retval) |
Yinghai Lu | 625e1d5 | 2012-11-05 15:20:35 -0500 | [diff] [blame] | 1399 | goto err_rom_file; |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 1400 | |
Narendra K | 911e1c9 | 2010-07-26 05:56:50 -0500 | [diff] [blame] | 1401 | pci_create_firmware_label_files(pdev); |
| 1402 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | return 0; |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 1404 | |
Michael Ellerman | a2cd52c | 2007-05-08 12:03:08 +1000 | [diff] [blame] | 1405 | err_rom_file: |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 1406 | if (rom_size) { |
Ben Hutchings | 94e6108 | 2008-03-05 16:52:39 +0000 | [diff] [blame] | 1407 | sysfs_remove_bin_file(&pdev->dev.kobj, pdev->rom_attr); |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 1408 | kfree(pdev->rom_attr); |
| 1409 | pdev->rom_attr = NULL; |
| 1410 | } |
Michael Ellerman | 9890b12 | 2007-04-18 13:34:12 +1000 | [diff] [blame] | 1411 | err_resource_files: |
| 1412 | pci_remove_resource_files(pdev); |
Ben Hutchings | 94e6108 | 2008-03-05 16:52:39 +0000 | [diff] [blame] | 1413 | err_config_file: |
Zhao, Yu | 557848c | 2008-10-13 19:18:07 +0800 | [diff] [blame] | 1414 | if (pdev->cfg_size < PCI_CFG_SPACE_EXP_SIZE) |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 1415 | sysfs_remove_bin_file(&pdev->dev.kobj, &pci_config_attr); |
| 1416 | else |
| 1417 | sysfs_remove_bin_file(&pdev->dev.kobj, &pcie_config_attr); |
| 1418 | err: |
| 1419 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | } |
| 1421 | |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 1422 | static void pci_remove_capabilities_sysfs(struct pci_dev *dev) |
| 1423 | { |
| 1424 | if (dev->vpd && dev->vpd->attr) { |
| 1425 | sysfs_remove_bin_file(&dev->dev.kobj, dev->vpd->attr); |
| 1426 | kfree(dev->vpd->attr); |
| 1427 | } |
| 1428 | |
| 1429 | pcie_aspm_remove_sysfs_dev_files(dev); |
Michael S. Tsirkin | 711d577 | 2009-07-27 23:37:48 +0300 | [diff] [blame] | 1430 | if (dev->reset_fn) { |
| 1431 | device_remove_file(&dev->dev, &reset_attr); |
| 1432 | dev->reset_fn = 0; |
| 1433 | } |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 1434 | } |
| 1435 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | /** |
| 1437 | * pci_remove_sysfs_dev_files - cleanup PCI specific sysfs files |
| 1438 | * @pdev: device whose entries we should free |
| 1439 | * |
| 1440 | * Cleanup when @pdev is removed from sysfs. |
| 1441 | */ |
| 1442 | void pci_remove_sysfs_dev_files(struct pci_dev *pdev) |
| 1443 | { |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 1444 | int rom_size = 0; |
| 1445 | |
David Miller | d67afe5 | 2006-11-10 12:27:48 -0800 | [diff] [blame] | 1446 | if (!sysfs_initialized) |
| 1447 | return; |
| 1448 | |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 1449 | pci_remove_capabilities_sysfs(pdev); |
Shaohua Li | 7d715a6 | 2008-02-25 09:46:41 +0800 | [diff] [blame] | 1450 | |
Zhao, Yu | 557848c | 2008-10-13 19:18:07 +0800 | [diff] [blame] | 1451 | if (pdev->cfg_size < PCI_CFG_SPACE_EXP_SIZE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | sysfs_remove_bin_file(&pdev->dev.kobj, &pci_config_attr); |
| 1453 | else |
| 1454 | sysfs_remove_bin_file(&pdev->dev.kobj, &pcie_config_attr); |
| 1455 | |
| 1456 | pci_remove_resource_files(pdev); |
| 1457 | |
Zhao, Yu | 280c73d | 2008-10-13 20:01:00 +0800 | [diff] [blame] | 1458 | if (pci_resource_len(pdev, PCI_ROM_RESOURCE)) |
| 1459 | rom_size = pci_resource_len(pdev, PCI_ROM_RESOURCE); |
| 1460 | else if (pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW) |
| 1461 | rom_size = 0x20000; |
| 1462 | |
| 1463 | if (rom_size && pdev->rom_attr) { |
| 1464 | sysfs_remove_bin_file(&pdev->dev.kobj, pdev->rom_attr); |
| 1465 | kfree(pdev->rom_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1466 | } |
Narendra K | 911e1c9 | 2010-07-26 05:56:50 -0500 | [diff] [blame] | 1467 | |
| 1468 | pci_remove_firmware_label_files(pdev); |
| 1469 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | static int __init pci_sysfs_init(void) |
| 1473 | { |
| 1474 | struct pci_dev *pdev = NULL; |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 1475 | int retval; |
| 1476 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1477 | sysfs_initialized = 1; |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 1478 | for_each_pci_dev(pdev) { |
| 1479 | retval = pci_create_sysfs_dev_files(pdev); |
Julia Lawall | 151fc5d | 2007-11-20 08:41:16 +0100 | [diff] [blame] | 1480 | if (retval) { |
| 1481 | pci_dev_put(pdev); |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 1482 | return retval; |
Julia Lawall | 151fc5d | 2007-11-20 08:41:16 +0100 | [diff] [blame] | 1483 | } |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 1484 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | |
| 1486 | return 0; |
| 1487 | } |
| 1488 | |
Jesse Barnes | 40ee9e9 | 2007-03-24 11:03:32 -0700 | [diff] [blame] | 1489 | late_initcall(pci_sysfs_init); |
Yinghai Lu | 4e15c46 | 2012-11-05 15:20:34 -0500 | [diff] [blame] | 1490 | |
| 1491 | static struct attribute *pci_dev_dev_attrs[] = { |
Yinghai Lu | 625e1d5 | 2012-11-05 15:20:35 -0500 | [diff] [blame] | 1492 | &vga_attr.attr, |
Yinghai Lu | 4e15c46 | 2012-11-05 15:20:34 -0500 | [diff] [blame] | 1493 | NULL, |
| 1494 | }; |
| 1495 | |
| 1496 | static umode_t pci_dev_attrs_are_visible(struct kobject *kobj, |
| 1497 | struct attribute *a, int n) |
| 1498 | { |
Yinghai Lu | 625e1d5 | 2012-11-05 15:20:35 -0500 | [diff] [blame] | 1499 | struct device *dev = container_of(kobj, struct device, kobj); |
| 1500 | struct pci_dev *pdev = to_pci_dev(dev); |
| 1501 | |
| 1502 | if (a == &vga_attr.attr) |
| 1503 | if ((pdev->class >> 8) != PCI_CLASS_DISPLAY_VGA) |
| 1504 | return 0; |
| 1505 | |
Yinghai Lu | 4e15c46 | 2012-11-05 15:20:34 -0500 | [diff] [blame] | 1506 | return a->mode; |
| 1507 | } |
| 1508 | |
Jiang Liu | dfab88b | 2013-05-31 12:21:31 +0800 | [diff] [blame] | 1509 | static struct attribute *pci_dev_hp_attrs[] = { |
| 1510 | &dev_remove_attr.attr, |
| 1511 | &dev_rescan_attr.attr, |
| 1512 | NULL, |
| 1513 | }; |
| 1514 | |
| 1515 | static umode_t pci_dev_hp_attrs_are_visible(struct kobject *kobj, |
| 1516 | struct attribute *a, int n) |
| 1517 | { |
| 1518 | struct device *dev = container_of(kobj, struct device, kobj); |
| 1519 | struct pci_dev *pdev = to_pci_dev(dev); |
| 1520 | |
| 1521 | if (pdev->is_virtfn) |
| 1522 | return 0; |
| 1523 | |
| 1524 | return a->mode; |
| 1525 | } |
| 1526 | |
| 1527 | static struct attribute_group pci_dev_hp_attr_group = { |
| 1528 | .attrs = pci_dev_hp_attrs, |
| 1529 | .is_visible = pci_dev_hp_attrs_are_visible, |
| 1530 | }; |
| 1531 | |
Donald Dutile | 1789382 | 2012-11-05 15:20:36 -0500 | [diff] [blame] | 1532 | #ifdef CONFIG_PCI_IOV |
| 1533 | static struct attribute *sriov_dev_attrs[] = { |
| 1534 | &sriov_totalvfs_attr.attr, |
| 1535 | &sriov_numvfs_attr.attr, |
| 1536 | NULL, |
| 1537 | }; |
| 1538 | |
| 1539 | static umode_t sriov_attrs_are_visible(struct kobject *kobj, |
| 1540 | struct attribute *a, int n) |
| 1541 | { |
| 1542 | struct device *dev = container_of(kobj, struct device, kobj); |
| 1543 | |
| 1544 | if (!dev_is_pf(dev)) |
| 1545 | return 0; |
| 1546 | |
| 1547 | return a->mode; |
| 1548 | } |
| 1549 | |
| 1550 | static struct attribute_group sriov_dev_attr_group = { |
| 1551 | .attrs = sriov_dev_attrs, |
| 1552 | .is_visible = sriov_attrs_are_visible, |
| 1553 | }; |
| 1554 | #endif /* CONFIG_PCI_IOV */ |
| 1555 | |
Yinghai Lu | 4e15c46 | 2012-11-05 15:20:34 -0500 | [diff] [blame] | 1556 | static struct attribute_group pci_dev_attr_group = { |
| 1557 | .attrs = pci_dev_dev_attrs, |
| 1558 | .is_visible = pci_dev_attrs_are_visible, |
| 1559 | }; |
| 1560 | |
| 1561 | static const struct attribute_group *pci_dev_attr_groups[] = { |
| 1562 | &pci_dev_attr_group, |
Jiang Liu | dfab88b | 2013-05-31 12:21:31 +0800 | [diff] [blame] | 1563 | &pci_dev_hp_attr_group, |
Donald Dutile | 1789382 | 2012-11-05 15:20:36 -0500 | [diff] [blame] | 1564 | #ifdef CONFIG_PCI_IOV |
| 1565 | &sriov_dev_attr_group, |
| 1566 | #endif |
Yinghai Lu | 4e15c46 | 2012-11-05 15:20:34 -0500 | [diff] [blame] | 1567 | NULL, |
| 1568 | }; |
| 1569 | |
| 1570 | struct device_type pci_dev_type = { |
| 1571 | .groups = pci_dev_attr_groups, |
| 1572 | }; |