Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * drivers/pci/pci-driver.c |
| 3 | * |
Greg Kroah-Hartman | 2b93730 | 2007-11-28 12:23:18 -0800 | [diff] [blame] | 4 | * (C) Copyright 2002-2004, 2007 Greg Kroah-Hartman <greg@kroah.com> |
| 5 | * (C) Copyright 2007 Novell Inc. |
| 6 | * |
| 7 | * Released under the GPL v2 only. |
| 8 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <linux/pci.h> |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/device.h> |
Andi Kleen | d42c699 | 2005-07-06 19:56:03 +0200 | [diff] [blame] | 15 | #include <linux/mempolicy.h> |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 16 | #include <linux/string.h> |
| 17 | #include <linux/slab.h> |
Tim Schmielau | 8c65b4a | 2005-11-07 00:59:43 -0800 | [diff] [blame] | 18 | #include <linux/sched.h> |
Rusty Russell | 873392c | 2008-12-31 23:54:56 +1030 | [diff] [blame] | 19 | #include <linux/cpu.h> |
Rafael J. Wysocki | 6cbf821 | 2010-02-17 23:44:58 +0100 | [diff] [blame] | 20 | #include <linux/pm_runtime.h> |
Rafael J. Wysocki | eea3fc03 | 2011-07-06 10:51:40 +0200 | [diff] [blame] | 21 | #include <linux/suspend.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include "pci.h" |
| 23 | |
Greg Kroah-Hartman | 7586585 | 2005-06-30 02:18:12 -0700 | [diff] [blame] | 24 | struct pci_dynid { |
| 25 | struct list_head node; |
| 26 | struct pci_device_id id; |
| 27 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
| 29 | /** |
Tejun Heo | 9dba910 | 2009-09-03 15:26:36 +0900 | [diff] [blame] | 30 | * pci_add_dynid - add a new PCI device ID to this driver and re-probe devices |
| 31 | * @drv: target pci driver |
| 32 | * @vendor: PCI vendor ID |
| 33 | * @device: PCI device ID |
| 34 | * @subvendor: PCI subvendor ID |
| 35 | * @subdevice: PCI subdevice ID |
| 36 | * @class: PCI class |
| 37 | * @class_mask: PCI class mask |
| 38 | * @driver_data: private driver data |
| 39 | * |
| 40 | * Adds a new dynamic pci device ID to this driver and causes the |
| 41 | * driver to probe for all devices again. @drv must have been |
| 42 | * registered prior to calling this function. |
| 43 | * |
| 44 | * CONTEXT: |
| 45 | * Does GFP_KERNEL allocation. |
| 46 | * |
| 47 | * RETURNS: |
| 48 | * 0 on success, -errno on failure. |
| 49 | */ |
| 50 | int pci_add_dynid(struct pci_driver *drv, |
| 51 | unsigned int vendor, unsigned int device, |
| 52 | unsigned int subvendor, unsigned int subdevice, |
| 53 | unsigned int class, unsigned int class_mask, |
| 54 | unsigned long driver_data) |
| 55 | { |
| 56 | struct pci_dynid *dynid; |
| 57 | int retval; |
| 58 | |
| 59 | dynid = kzalloc(sizeof(*dynid), GFP_KERNEL); |
| 60 | if (!dynid) |
| 61 | return -ENOMEM; |
| 62 | |
| 63 | dynid->id.vendor = vendor; |
| 64 | dynid->id.device = device; |
| 65 | dynid->id.subvendor = subvendor; |
| 66 | dynid->id.subdevice = subdevice; |
| 67 | dynid->id.class = class; |
| 68 | dynid->id.class_mask = class_mask; |
| 69 | dynid->id.driver_data = driver_data; |
| 70 | |
| 71 | spin_lock(&drv->dynids.lock); |
| 72 | list_add_tail(&dynid->node, &drv->dynids.list); |
| 73 | spin_unlock(&drv->dynids.lock); |
| 74 | |
Tejun Heo | 9dba910 | 2009-09-03 15:26:36 +0900 | [diff] [blame] | 75 | retval = driver_attach(&drv->driver); |
Tejun Heo | 9dba910 | 2009-09-03 15:26:36 +0900 | [diff] [blame] | 76 | |
| 77 | return retval; |
| 78 | } |
| 79 | |
| 80 | static void pci_free_dynids(struct pci_driver *drv) |
| 81 | { |
| 82 | struct pci_dynid *dynid, *n; |
| 83 | |
| 84 | spin_lock(&drv->dynids.lock); |
| 85 | list_for_each_entry_safe(dynid, n, &drv->dynids.list, node) { |
| 86 | list_del(&dynid->node); |
| 87 | kfree(dynid); |
| 88 | } |
| 89 | spin_unlock(&drv->dynids.lock); |
| 90 | } |
| 91 | |
| 92 | /* |
| 93 | * Dynamic device ID manipulation via sysfs is disabled for !CONFIG_HOTPLUG |
| 94 | */ |
| 95 | #ifdef CONFIG_HOTPLUG |
| 96 | /** |
| 97 | * store_new_id - sysfs frontend to pci_add_dynid() |
Randy Dunlap | 8f7020d | 2005-10-23 11:57:38 -0700 | [diff] [blame] | 98 | * @driver: target device driver |
| 99 | * @buf: buffer for scanning device ID data |
| 100 | * @count: input size |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | * |
Tejun Heo | 9dba910 | 2009-09-03 15:26:36 +0900 | [diff] [blame] | 102 | * Allow PCI IDs to be added to an existing driver via sysfs. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | */ |
Randy Dunlap | f8eb100 | 2005-10-28 20:36:51 -0700 | [diff] [blame] | 104 | static ssize_t |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | store_new_id(struct device_driver *driver, const char *buf, size_t count) |
| 106 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | struct pci_driver *pdrv = to_pci_driver(driver); |
Jean Delvare | b41d6cf | 2008-08-17 21:06:59 +0200 | [diff] [blame] | 108 | const struct pci_device_id *ids = pdrv->id_table; |
Jean Delvare | 6ba1863 | 2007-04-07 17:21:28 +0200 | [diff] [blame] | 109 | __u32 vendor, device, subvendor=PCI_ANY_ID, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | subdevice=PCI_ANY_ID, class=0, class_mask=0; |
| 111 | unsigned long driver_data=0; |
| 112 | int fields=0; |
Tejun Heo | 9dba910 | 2009-09-03 15:26:36 +0900 | [diff] [blame] | 113 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
Jean Delvare | b41d6cf | 2008-08-17 21:06:59 +0200 | [diff] [blame] | 115 | fields = sscanf(buf, "%x %x %x %x %x %x %lx", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | &vendor, &device, &subvendor, &subdevice, |
| 117 | &class, &class_mask, &driver_data); |
Jean Delvare | 6ba1863 | 2007-04-07 17:21:28 +0200 | [diff] [blame] | 118 | if (fields < 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | return -EINVAL; |
| 120 | |
Jean Delvare | b41d6cf | 2008-08-17 21:06:59 +0200 | [diff] [blame] | 121 | /* Only accept driver_data values that match an existing id_table |
| 122 | entry */ |
Chris Wright | 2debb4d | 2008-11-25 19:36:10 -0800 | [diff] [blame] | 123 | if (ids) { |
| 124 | retval = -EINVAL; |
| 125 | while (ids->vendor || ids->subvendor || ids->class_mask) { |
| 126 | if (driver_data == ids->driver_data) { |
| 127 | retval = 0; |
| 128 | break; |
| 129 | } |
| 130 | ids++; |
Jean Delvare | b41d6cf | 2008-08-17 21:06:59 +0200 | [diff] [blame] | 131 | } |
Chris Wright | 2debb4d | 2008-11-25 19:36:10 -0800 | [diff] [blame] | 132 | if (retval) /* No match */ |
| 133 | return retval; |
Jean Delvare | b41d6cf | 2008-08-17 21:06:59 +0200 | [diff] [blame] | 134 | } |
Jean Delvare | b41d6cf | 2008-08-17 21:06:59 +0200 | [diff] [blame] | 135 | |
Tejun Heo | 9dba910 | 2009-09-03 15:26:36 +0900 | [diff] [blame] | 136 | retval = pci_add_dynid(pdrv, vendor, device, subvendor, subdevice, |
| 137 | class, class_mask, driver_data); |
Greg Kroah-Hartman | b19441a | 2006-08-28 11:43:25 -0700 | [diff] [blame] | 138 | if (retval) |
| 139 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | return count; |
| 141 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
Chris Wright | 0994375 | 2009-02-23 21:52:23 -0800 | [diff] [blame] | 143 | /** |
| 144 | * store_remove_id - remove a PCI device ID from this driver |
| 145 | * @driver: target device driver |
| 146 | * @buf: buffer for scanning device ID data |
| 147 | * @count: input size |
| 148 | * |
| 149 | * Removes a dynamic pci device ID to this driver. |
| 150 | */ |
| 151 | static ssize_t |
| 152 | store_remove_id(struct device_driver *driver, const char *buf, size_t count) |
| 153 | { |
| 154 | struct pci_dynid *dynid, *n; |
| 155 | struct pci_driver *pdrv = to_pci_driver(driver); |
| 156 | __u32 vendor, device, subvendor = PCI_ANY_ID, |
| 157 | subdevice = PCI_ANY_ID, class = 0, class_mask = 0; |
| 158 | int fields = 0; |
| 159 | int retval = -ENODEV; |
| 160 | |
| 161 | fields = sscanf(buf, "%x %x %x %x %x %x", |
| 162 | &vendor, &device, &subvendor, &subdevice, |
| 163 | &class, &class_mask); |
| 164 | if (fields < 2) |
| 165 | return -EINVAL; |
| 166 | |
| 167 | spin_lock(&pdrv->dynids.lock); |
| 168 | list_for_each_entry_safe(dynid, n, &pdrv->dynids.list, node) { |
| 169 | struct pci_device_id *id = &dynid->id; |
| 170 | if ((id->vendor == vendor) && |
| 171 | (id->device == device) && |
| 172 | (subvendor == PCI_ANY_ID || id->subvendor == subvendor) && |
| 173 | (subdevice == PCI_ANY_ID || id->subdevice == subdevice) && |
| 174 | !((id->class ^ class) & class_mask)) { |
| 175 | list_del(&dynid->node); |
| 176 | kfree(dynid); |
| 177 | retval = 0; |
| 178 | break; |
| 179 | } |
| 180 | } |
| 181 | spin_unlock(&pdrv->dynids.lock); |
| 182 | |
| 183 | if (retval) |
| 184 | return retval; |
| 185 | return count; |
| 186 | } |
Chris Wright | 0994375 | 2009-02-23 21:52:23 -0800 | [diff] [blame] | 187 | |
Konstantin Khlebnikov | bfb09a8 | 2012-08-08 14:47:51 +0400 | [diff] [blame] | 188 | static struct driver_attribute pci_drv_attrs[] = { |
| 189 | __ATTR(new_id, S_IWUSR, NULL, store_new_id), |
| 190 | __ATTR(remove_id, S_IWUSR, NULL, store_remove_id), |
| 191 | __ATTR_NULL, |
| 192 | }; |
Alan Stern | ed283e9 | 2012-01-24 14:35:13 -0500 | [diff] [blame] | 193 | |
Konstantin Khlebnikov | bfb09a8 | 2012-08-08 14:47:51 +0400 | [diff] [blame] | 194 | #else |
| 195 | #define pci_drv_attrs NULL |
| 196 | #endif /* CONFIG_HOTPLUG */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
| 198 | /** |
Greg Kroah-Hartman | 7586585 | 2005-06-30 02:18:12 -0700 | [diff] [blame] | 199 | * pci_match_id - See if a pci device matches a given pci_id table |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | * @ids: array of PCI device id structures to search in |
Greg Kroah-Hartman | 7586585 | 2005-06-30 02:18:12 -0700 | [diff] [blame] | 201 | * @dev: the PCI device structure to match against. |
| 202 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | * Used by a driver to check whether a PCI device present in the |
Greg Kroah-Hartman | 7586585 | 2005-06-30 02:18:12 -0700 | [diff] [blame] | 204 | * system is in its list of supported devices. Returns the matching |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | * pci_device_id structure or %NULL if there is no match. |
Greg Kroah-Hartman | 7586585 | 2005-06-30 02:18:12 -0700 | [diff] [blame] | 206 | * |
Randy Dunlap | 8b60756 | 2007-05-09 07:19:14 +0200 | [diff] [blame] | 207 | * Deprecated, don't use this as it will not catch any dynamic ids |
Greg Kroah-Hartman | 7586585 | 2005-06-30 02:18:12 -0700 | [diff] [blame] | 208 | * that a driver might want to check for. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | */ |
Greg Kroah-Hartman | 7586585 | 2005-06-30 02:18:12 -0700 | [diff] [blame] | 210 | const struct pci_device_id *pci_match_id(const struct pci_device_id *ids, |
| 211 | struct pci_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | { |
Greg Kroah-Hartman | 7586585 | 2005-06-30 02:18:12 -0700 | [diff] [blame] | 213 | if (ids) { |
| 214 | while (ids->vendor || ids->subvendor || ids->class_mask) { |
| 215 | if (pci_match_one_device(ids, dev)) |
| 216 | return ids; |
| 217 | ids++; |
| 218 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | } |
| 220 | return NULL; |
| 221 | } |
| 222 | |
| 223 | /** |
Randy Dunlap | ae9608a | 2007-01-09 21:41:01 -0800 | [diff] [blame] | 224 | * pci_match_device - Tell if a PCI device structure has a matching PCI device id structure |
Greg Kroah-Hartman | 7586585 | 2005-06-30 02:18:12 -0700 | [diff] [blame] | 225 | * @drv: the PCI driver to match against |
Henrik Kretzschmar | 39ba487 | 2006-08-15 10:57:16 +0200 | [diff] [blame] | 226 | * @dev: the PCI device structure to match against |
Greg Kroah-Hartman | 7586585 | 2005-06-30 02:18:12 -0700 | [diff] [blame] | 227 | * |
| 228 | * Used by a driver to check whether a PCI device present in the |
| 229 | * system is in its list of supported devices. Returns the matching |
| 230 | * pci_device_id structure or %NULL if there is no match. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | */ |
Adrian Bunk | d73460d | 2007-10-24 18:27:18 +0200 | [diff] [blame] | 232 | static const struct pci_device_id *pci_match_device(struct pci_driver *drv, |
| 233 | struct pci_dev *dev) |
Greg Kroah-Hartman | 7586585 | 2005-06-30 02:18:12 -0700 | [diff] [blame] | 234 | { |
Greg Kroah-Hartman | 7586585 | 2005-06-30 02:18:12 -0700 | [diff] [blame] | 235 | struct pci_dynid *dynid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
Russell King | 7461b60 | 2006-11-29 21:18:04 +0000 | [diff] [blame] | 237 | /* Look at the dynamic ids first, before the static ones */ |
Greg Kroah-Hartman | 7586585 | 2005-06-30 02:18:12 -0700 | [diff] [blame] | 238 | spin_lock(&drv->dynids.lock); |
| 239 | list_for_each_entry(dynid, &drv->dynids.list, node) { |
| 240 | if (pci_match_one_device(&dynid->id, dev)) { |
| 241 | spin_unlock(&drv->dynids.lock); |
| 242 | return &dynid->id; |
| 243 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | } |
Greg Kroah-Hartman | 7586585 | 2005-06-30 02:18:12 -0700 | [diff] [blame] | 245 | spin_unlock(&drv->dynids.lock); |
Russell King | 7461b60 | 2006-11-29 21:18:04 +0000 | [diff] [blame] | 246 | |
| 247 | return pci_match_id(drv->id_table, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | } |
| 249 | |
Rusty Russell | 873392c | 2008-12-31 23:54:56 +1030 | [diff] [blame] | 250 | struct drv_dev_and_id { |
| 251 | struct pci_driver *drv; |
| 252 | struct pci_dev *dev; |
| 253 | const struct pci_device_id *id; |
| 254 | }; |
| 255 | |
| 256 | static long local_pci_probe(void *_ddi) |
| 257 | { |
| 258 | struct drv_dev_and_id *ddi = _ddi; |
Huang Ying | 967577b | 2012-11-20 16:08:22 +0800 | [diff] [blame^] | 259 | struct pci_dev *pci_dev = ddi->dev; |
| 260 | struct pci_driver *pci_drv = ddi->drv; |
| 261 | struct device *dev = &pci_dev->dev; |
Alan Stern | f3ec4f8 | 2010-06-08 15:23:51 -0400 | [diff] [blame] | 262 | int rc; |
Rusty Russell | 873392c | 2008-12-31 23:54:56 +1030 | [diff] [blame] | 263 | |
Huang Ying | 967577b | 2012-11-20 16:08:22 +0800 | [diff] [blame^] | 264 | /* |
| 265 | * Unbound PCI devices are always put in D0, regardless of |
| 266 | * runtime PM status. During probe, the device is set to |
| 267 | * active and the usage count is incremented. If the driver |
| 268 | * supports runtime PM, it should call pm_runtime_put_noidle() |
| 269 | * in its probe routine and pm_runtime_get_noresume() in its |
| 270 | * remove routine. |
Alan Stern | f3ec4f8 | 2010-06-08 15:23:51 -0400 | [diff] [blame] | 271 | */ |
Huang Ying | 967577b | 2012-11-20 16:08:22 +0800 | [diff] [blame^] | 272 | pm_runtime_get_sync(dev); |
| 273 | pci_dev->driver = pci_drv; |
| 274 | rc = pci_drv->probe(pci_dev, ddi->id); |
Alan Stern | f3ec4f8 | 2010-06-08 15:23:51 -0400 | [diff] [blame] | 275 | if (rc) { |
Huang Ying | 967577b | 2012-11-20 16:08:22 +0800 | [diff] [blame^] | 276 | pci_dev->driver = NULL; |
| 277 | pm_runtime_put_sync(dev); |
Alan Stern | f3ec4f8 | 2010-06-08 15:23:51 -0400 | [diff] [blame] | 278 | } |
| 279 | return rc; |
Rusty Russell | 873392c | 2008-12-31 23:54:56 +1030 | [diff] [blame] | 280 | } |
| 281 | |
Andi Kleen | d42c699 | 2005-07-06 19:56:03 +0200 | [diff] [blame] | 282 | static int pci_call_probe(struct pci_driver *drv, struct pci_dev *dev, |
| 283 | const struct pci_device_id *id) |
| 284 | { |
Rusty Russell | 873392c | 2008-12-31 23:54:56 +1030 | [diff] [blame] | 285 | int error, node; |
| 286 | struct drv_dev_and_id ddi = { drv, dev, id }; |
Mike Travis | f70316d | 2008-04-04 18:11:06 -0700 | [diff] [blame] | 287 | |
Rusty Russell | 873392c | 2008-12-31 23:54:56 +1030 | [diff] [blame] | 288 | /* Execute driver initialization on node where the device's |
| 289 | bus is attached to. This way the driver likely allocates |
| 290 | its local memory on the right node without any need to |
| 291 | change it. */ |
| 292 | node = dev_to_node(&dev->dev); |
Mike Travis | f70316d | 2008-04-04 18:11:06 -0700 | [diff] [blame] | 293 | if (node >= 0) { |
Rusty Russell | 873392c | 2008-12-31 23:54:56 +1030 | [diff] [blame] | 294 | int cpu; |
Rusty Russell | 873392c | 2008-12-31 23:54:56 +1030 | [diff] [blame] | 295 | |
| 296 | get_online_cpus(); |
Rusty Russell | a70f730 | 2009-03-13 14:49:46 +1030 | [diff] [blame] | 297 | cpu = cpumask_any_and(cpumask_of_node(node), cpu_online_mask); |
Rusty Russell | 873392c | 2008-12-31 23:54:56 +1030 | [diff] [blame] | 298 | if (cpu < nr_cpu_ids) |
| 299 | error = work_on_cpu(cpu, local_pci_probe, &ddi); |
| 300 | else |
| 301 | error = local_pci_probe(&ddi); |
| 302 | put_online_cpus(); |
| 303 | } else |
| 304 | error = local_pci_probe(&ddi); |
Andi Kleen | d42c699 | 2005-07-06 19:56:03 +0200 | [diff] [blame] | 305 | return error; |
| 306 | } |
| 307 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | /** |
Randy Dunlap | 23ea379 | 2010-11-18 15:02:31 -0800 | [diff] [blame] | 309 | * __pci_device_probe - check if a driver wants to claim a specific PCI device |
Randy Dunlap | 8f7020d | 2005-10-23 11:57:38 -0700 | [diff] [blame] | 310 | * @drv: driver to call to check if it wants the PCI device |
| 311 | * @pci_dev: PCI device being probed |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | * |
Randy Dunlap | 8f7020d | 2005-10-23 11:57:38 -0700 | [diff] [blame] | 313 | * returns 0 on success, else error. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | * side-effect: pci_dev->driver is set to drv when drv claims pci_dev. |
| 315 | */ |
| 316 | static int |
| 317 | __pci_device_probe(struct pci_driver *drv, struct pci_dev *pci_dev) |
Greg Kroah-Hartman | 7586585 | 2005-06-30 02:18:12 -0700 | [diff] [blame] | 318 | { |
| 319 | const struct pci_device_id *id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | int error = 0; |
| 321 | |
| 322 | if (!pci_dev->driver && drv->probe) { |
Greg Kroah-Hartman | 7586585 | 2005-06-30 02:18:12 -0700 | [diff] [blame] | 323 | error = -ENODEV; |
| 324 | |
| 325 | id = pci_match_device(drv, pci_dev); |
| 326 | if (id) |
Andi Kleen | d42c699 | 2005-07-06 19:56:03 +0200 | [diff] [blame] | 327 | error = pci_call_probe(drv, pci_dev, id); |
Huang Ying | 967577b | 2012-11-20 16:08:22 +0800 | [diff] [blame^] | 328 | if (error >= 0) |
Greg Kroah-Hartman | 7586585 | 2005-06-30 02:18:12 -0700 | [diff] [blame] | 329 | error = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | } |
| 331 | return error; |
| 332 | } |
| 333 | |
| 334 | static int pci_device_probe(struct device * dev) |
| 335 | { |
| 336 | int error = 0; |
| 337 | struct pci_driver *drv; |
| 338 | struct pci_dev *pci_dev; |
| 339 | |
| 340 | drv = to_pci_driver(dev->driver); |
| 341 | pci_dev = to_pci_dev(dev); |
| 342 | pci_dev_get(pci_dev); |
| 343 | error = __pci_device_probe(drv, pci_dev); |
| 344 | if (error) |
| 345 | pci_dev_put(pci_dev); |
| 346 | |
| 347 | return error; |
| 348 | } |
| 349 | |
| 350 | static int pci_device_remove(struct device * dev) |
| 351 | { |
| 352 | struct pci_dev * pci_dev = to_pci_dev(dev); |
| 353 | struct pci_driver * drv = pci_dev->driver; |
| 354 | |
| 355 | if (drv) { |
Alan Stern | f3ec4f8 | 2010-06-08 15:23:51 -0400 | [diff] [blame] | 356 | if (drv->remove) { |
| 357 | pm_runtime_get_sync(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | drv->remove(pci_dev); |
Alan Stern | f3ec4f8 | 2010-06-08 15:23:51 -0400 | [diff] [blame] | 359 | pm_runtime_put_noidle(dev); |
| 360 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | pci_dev->driver = NULL; |
| 362 | } |
| 363 | |
Alan Stern | f3ec4f8 | 2010-06-08 15:23:51 -0400 | [diff] [blame] | 364 | /* Undo the runtime PM settings in local_pci_probe() */ |
Huang Ying | 967577b | 2012-11-20 16:08:22 +0800 | [diff] [blame^] | 365 | pm_runtime_put_sync(dev); |
Alan Stern | f3ec4f8 | 2010-06-08 15:23:51 -0400 | [diff] [blame] | 366 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | /* |
Shaohua Li | 2449e06 | 2006-10-20 14:45:32 -0700 | [diff] [blame] | 368 | * If the device is still on, set the power state as "unknown", |
| 369 | * since it might change by the next time we load the driver. |
| 370 | */ |
| 371 | if (pci_dev->current_state == PCI_D0) |
| 372 | pci_dev->current_state = PCI_UNKNOWN; |
| 373 | |
| 374 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | * We would love to complain here if pci_dev->is_enabled is set, that |
| 376 | * the driver should have called pci_disable_device(), but the |
| 377 | * unfortunate fact is there are too many odd BIOS and bridge setups |
| 378 | * that don't like drivers doing that all of the time. |
| 379 | * Oh well, we can dream of sane hardware when we sleep, no matter how |
| 380 | * horrible the crap we have to deal with is when we are awake... |
| 381 | */ |
| 382 | |
| 383 | pci_dev_put(pci_dev); |
| 384 | return 0; |
| 385 | } |
| 386 | |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 387 | static void pci_device_shutdown(struct device *dev) |
| 388 | { |
| 389 | struct pci_dev *pci_dev = to_pci_dev(dev); |
| 390 | struct pci_driver *drv = pci_dev->driver; |
| 391 | |
Huang Ying | 3ff2de9 | 2012-10-24 14:54:14 +0800 | [diff] [blame] | 392 | pm_runtime_resume(dev); |
| 393 | |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 394 | if (drv && drv->shutdown) |
| 395 | drv->shutdown(pci_dev); |
| 396 | pci_msi_shutdown(pci_dev); |
| 397 | pci_msix_shutdown(pci_dev); |
Rafael J. Wysocki | 5b415f1 | 2012-02-07 00:50:35 +0100 | [diff] [blame] | 398 | |
| 399 | /* |
Khalid Aziz | b566a22 | 2012-04-27 13:00:33 -0600 | [diff] [blame] | 400 | * Turn off Bus Master bit on the device to tell it to not |
| 401 | * continue to do DMA |
| 402 | */ |
| 403 | pci_disable_device(pci_dev); |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 404 | } |
| 405 | |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 406 | #ifdef CONFIG_PM |
Rafael J. Wysocki | 6cbf821 | 2010-02-17 23:44:58 +0100 | [diff] [blame] | 407 | |
| 408 | /* Auxiliary functions used for system resume and run-time resume. */ |
| 409 | |
| 410 | /** |
| 411 | * pci_restore_standard_config - restore standard config registers of PCI device |
| 412 | * @pci_dev: PCI device to handle |
| 413 | */ |
| 414 | static int pci_restore_standard_config(struct pci_dev *pci_dev) |
| 415 | { |
| 416 | pci_update_current_state(pci_dev, PCI_UNKNOWN); |
| 417 | |
| 418 | if (pci_dev->current_state != PCI_D0) { |
| 419 | int error = pci_set_power_state(pci_dev, PCI_D0); |
| 420 | if (error) |
| 421 | return error; |
| 422 | } |
| 423 | |
Jon Mason | 1d3c16a | 2010-11-30 17:43:26 -0600 | [diff] [blame] | 424 | pci_restore_state(pci_dev); |
| 425 | return 0; |
Rafael J. Wysocki | 6cbf821 | 2010-02-17 23:44:58 +0100 | [diff] [blame] | 426 | } |
| 427 | |
Rafael J. Wysocki | 6cbf821 | 2010-02-17 23:44:58 +0100 | [diff] [blame] | 428 | #endif |
| 429 | |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 430 | #ifdef CONFIG_PM_SLEEP |
| 431 | |
Rafael J. Wysocki | db288c9 | 2012-07-05 15:20:00 -0600 | [diff] [blame] | 432 | static void pci_pm_default_resume_early(struct pci_dev *pci_dev) |
| 433 | { |
| 434 | pci_power_up(pci_dev); |
| 435 | pci_restore_state(pci_dev); |
| 436 | pci_fixup_device(pci_fixup_resume_early, pci_dev); |
| 437 | } |
| 438 | |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 439 | /* |
| 440 | * Default "suspend" method for devices that have no driver provided suspend, |
Rafael J. Wysocki | fa58d30 | 2009-01-07 13:03:42 +0100 | [diff] [blame] | 441 | * or not even a driver at all (second part). |
| 442 | */ |
Rafael J. Wysocki | bb80894 | 2009-01-07 14:15:17 +0100 | [diff] [blame] | 443 | static void pci_pm_set_unknown_state(struct pci_dev *pci_dev) |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 444 | { |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 445 | /* |
| 446 | * mark its power state as "unknown", since we don't know if |
| 447 | * e.g. the BIOS will change its device state when we suspend. |
| 448 | */ |
| 449 | if (pci_dev->current_state == PCI_D0) |
| 450 | pci_dev->current_state = PCI_UNKNOWN; |
| 451 | } |
| 452 | |
| 453 | /* |
| 454 | * Default "resume" method for devices that have no driver provided resume, |
Rafael J. Wysocki | 355a72d | 2008-12-08 00:34:57 +0100 | [diff] [blame] | 455 | * or not even a driver at all (second part). |
| 456 | */ |
Rafael J. Wysocki | bb80894 | 2009-01-07 14:15:17 +0100 | [diff] [blame] | 457 | static int pci_pm_reenable_device(struct pci_dev *pci_dev) |
Rafael J. Wysocki | 355a72d | 2008-12-08 00:34:57 +0100 | [diff] [blame] | 458 | { |
| 459 | int retval; |
| 460 | |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 461 | /* if the device was enabled before suspend, reenable */ |
| 462 | retval = pci_reenable_device(pci_dev); |
| 463 | /* |
| 464 | * if the device was busmaster before the suspend, make it busmaster |
| 465 | * again |
| 466 | */ |
| 467 | if (pci_dev->is_busmaster) |
| 468 | pci_set_master(pci_dev); |
| 469 | |
| 470 | return retval; |
| 471 | } |
| 472 | |
| 473 | static int pci_legacy_suspend(struct device *dev, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | { |
| 475 | struct pci_dev * pci_dev = to_pci_dev(dev); |
| 476 | struct pci_driver * drv = pci_dev->driver; |
Rafael J. Wysocki | 46939f8 | 2009-03-16 22:40:26 +0100 | [diff] [blame] | 477 | |
Andrew Morton | 0266949 | 2006-03-23 01:38:34 -0800 | [diff] [blame] | 478 | if (drv && drv->suspend) { |
Rafael J. Wysocki | 99dadce | 2009-02-04 01:59:09 +0100 | [diff] [blame] | 479 | pci_power_t prev = pci_dev->current_state; |
Rafael J. Wysocki | 46939f8 | 2009-03-16 22:40:26 +0100 | [diff] [blame] | 480 | int error; |
Rafael J. Wysocki | aa8c6c9 | 2009-01-16 21:54:43 +0100 | [diff] [blame] | 481 | |
Frans Pop | 57ef802 | 2009-03-16 22:39:56 +0100 | [diff] [blame] | 482 | error = drv->suspend(pci_dev, state); |
| 483 | suspend_report_result(drv->suspend, error); |
| 484 | if (error) |
| 485 | return error; |
Rafael J. Wysocki | aa8c6c9 | 2009-01-16 21:54:43 +0100 | [diff] [blame] | 486 | |
Rafael J. Wysocki | 46939f8 | 2009-03-16 22:40:26 +0100 | [diff] [blame] | 487 | if (!pci_dev->state_saved && pci_dev->current_state != PCI_D0 |
Rafael J. Wysocki | 99dadce | 2009-02-04 01:59:09 +0100 | [diff] [blame] | 488 | && pci_dev->current_state != PCI_UNKNOWN) { |
| 489 | WARN_ONCE(pci_dev->current_state != prev, |
| 490 | "PCI PM: Device state not saved by %pF\n", |
| 491 | drv->suspend); |
Rafael J. Wysocki | 99dadce | 2009-02-04 01:59:09 +0100 | [diff] [blame] | 492 | } |
Andrew Morton | 0266949 | 2006-03-23 01:38:34 -0800 | [diff] [blame] | 493 | } |
Rafael J. Wysocki | ad8cfa1 | 2009-01-07 13:09:37 +0100 | [diff] [blame] | 494 | |
| 495 | pci_fixup_device(pci_fixup_suspend, pci_dev); |
| 496 | |
Rafael J. Wysocki | 46939f8 | 2009-03-16 22:40:26 +0100 | [diff] [blame] | 497 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | } |
| 499 | |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 500 | static int pci_legacy_suspend_late(struct device *dev, pm_message_t state) |
Linus Torvalds | cbd69db | 2006-06-24 14:50:29 -0700 | [diff] [blame] | 501 | { |
| 502 | struct pci_dev * pci_dev = to_pci_dev(dev); |
| 503 | struct pci_driver * drv = pci_dev->driver; |
Linus Torvalds | cbd69db | 2006-06-24 14:50:29 -0700 | [diff] [blame] | 504 | |
| 505 | if (drv && drv->suspend_late) { |
Rafael J. Wysocki | 46939f8 | 2009-03-16 22:40:26 +0100 | [diff] [blame] | 506 | pci_power_t prev = pci_dev->current_state; |
| 507 | int error; |
| 508 | |
Frans Pop | 57ef802 | 2009-03-16 22:39:56 +0100 | [diff] [blame] | 509 | error = drv->suspend_late(pci_dev, state); |
| 510 | suspend_report_result(drv->suspend_late, error); |
Rafael J. Wysocki | 46939f8 | 2009-03-16 22:40:26 +0100 | [diff] [blame] | 511 | if (error) |
| 512 | return error; |
| 513 | |
| 514 | if (!pci_dev->state_saved && pci_dev->current_state != PCI_D0 |
| 515 | && pci_dev->current_state != PCI_UNKNOWN) { |
| 516 | WARN_ONCE(pci_dev->current_state != prev, |
| 517 | "PCI PM: Device state not saved by %pF\n", |
| 518 | drv->suspend_late); |
| 519 | return 0; |
| 520 | } |
Linus Torvalds | cbd69db | 2006-06-24 14:50:29 -0700 | [diff] [blame] | 521 | } |
Rafael J. Wysocki | 46939f8 | 2009-03-16 22:40:26 +0100 | [diff] [blame] | 522 | |
| 523 | if (!pci_dev->state_saved) |
| 524 | pci_save_state(pci_dev); |
| 525 | |
| 526 | pci_pm_set_unknown_state(pci_dev); |
| 527 | |
| 528 | return 0; |
Linus Torvalds | cbd69db | 2006-06-24 14:50:29 -0700 | [diff] [blame] | 529 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | |
Rafael J. Wysocki | f6dc1e5 | 2009-01-07 13:12:22 +0100 | [diff] [blame] | 531 | static int pci_legacy_resume_early(struct device *dev) |
| 532 | { |
Rafael J. Wysocki | f6dc1e5 | 2009-01-07 13:12:22 +0100 | [diff] [blame] | 533 | struct pci_dev * pci_dev = to_pci_dev(dev); |
| 534 | struct pci_driver * drv = pci_dev->driver; |
| 535 | |
Rafael J. Wysocki | aa8c6c9 | 2009-01-16 21:54:43 +0100 | [diff] [blame] | 536 | return drv && drv->resume_early ? |
| 537 | drv->resume_early(pci_dev) : 0; |
Rafael J. Wysocki | f6dc1e5 | 2009-01-07 13:12:22 +0100 | [diff] [blame] | 538 | } |
| 539 | |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 540 | static int pci_legacy_resume(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | { |
| 542 | struct pci_dev * pci_dev = to_pci_dev(dev); |
| 543 | struct pci_driver * drv = pci_dev->driver; |
| 544 | |
Rafael J. Wysocki | ad8cfa1 | 2009-01-07 13:09:37 +0100 | [diff] [blame] | 545 | pci_fixup_device(pci_fixup_resume, pci_dev); |
| 546 | |
Rafael J. Wysocki | aa8c6c9 | 2009-01-16 21:54:43 +0100 | [diff] [blame] | 547 | return drv && drv->resume ? |
| 548 | drv->resume(pci_dev) : pci_pm_reenable_device(pci_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | } |
| 550 | |
Rafael J. Wysocki | 571ff75 | 2009-01-07 13:05:05 +0100 | [diff] [blame] | 551 | /* Auxiliary functions used by the new power management framework */ |
| 552 | |
Rafael J. Wysocki | 5294e25 | 2009-02-04 02:09:07 +0100 | [diff] [blame] | 553 | static void pci_pm_default_resume(struct pci_dev *pci_dev) |
Rafael J. Wysocki | 571ff75 | 2009-01-07 13:05:05 +0100 | [diff] [blame] | 554 | { |
Rafael J. Wysocki | 73410429 | 2009-01-07 13:07:15 +0100 | [diff] [blame] | 555 | pci_fixup_device(pci_fixup_resume, pci_dev); |
| 556 | |
Rafael J. Wysocki | 5294e25 | 2009-02-04 02:09:07 +0100 | [diff] [blame] | 557 | if (!pci_is_bridge(pci_dev)) |
| 558 | pci_enable_wake(pci_dev, PCI_D0, false); |
Rafael J. Wysocki | 571ff75 | 2009-01-07 13:05:05 +0100 | [diff] [blame] | 559 | } |
| 560 | |
Rafael J. Wysocki | 5294e25 | 2009-02-04 02:09:07 +0100 | [diff] [blame] | 561 | static void pci_pm_default_suspend(struct pci_dev *pci_dev) |
Rafael J. Wysocki | 73410429 | 2009-01-07 13:07:15 +0100 | [diff] [blame] | 562 | { |
Rafael J. Wysocki | 5294e25 | 2009-02-04 02:09:07 +0100 | [diff] [blame] | 563 | /* Disable non-bridge devices without PM support */ |
Rafael J. Wysocki | cbbc2f6 | 2009-02-04 02:01:15 +0100 | [diff] [blame] | 564 | if (!pci_is_bridge(pci_dev)) |
| 565 | pci_disable_enabled_device(pci_dev); |
Rafael J. Wysocki | 73410429 | 2009-01-07 13:07:15 +0100 | [diff] [blame] | 566 | } |
| 567 | |
Rafael J. Wysocki | 07e836e | 2009-01-07 13:06:10 +0100 | [diff] [blame] | 568 | static bool pci_has_legacy_pm_support(struct pci_dev *pci_dev) |
| 569 | { |
| 570 | struct pci_driver *drv = pci_dev->driver; |
Rafael J. Wysocki | bb80894 | 2009-01-07 14:15:17 +0100 | [diff] [blame] | 571 | bool ret = drv && (drv->suspend || drv->suspend_late || drv->resume |
Rafael J. Wysocki | 07e836e | 2009-01-07 13:06:10 +0100 | [diff] [blame] | 572 | || drv->resume_early); |
Rafael J. Wysocki | bb80894 | 2009-01-07 14:15:17 +0100 | [diff] [blame] | 573 | |
| 574 | /* |
| 575 | * Legacy PM support is used by default, so warn if the new framework is |
| 576 | * supported as well. Drivers are supposed to support either the |
| 577 | * former, or the latter, but not both at the same time. |
| 578 | */ |
David Fries | 82440a8 | 2011-11-20 15:29:46 -0600 | [diff] [blame] | 579 | WARN(ret && drv->driver.pm, "driver %s device %04x:%04x\n", |
| 580 | drv->name, pci_dev->vendor, pci_dev->device); |
Rafael J. Wysocki | bb80894 | 2009-01-07 14:15:17 +0100 | [diff] [blame] | 581 | |
| 582 | return ret; |
Rafael J. Wysocki | 07e836e | 2009-01-07 13:06:10 +0100 | [diff] [blame] | 583 | } |
| 584 | |
Rafael J. Wysocki | 571ff75 | 2009-01-07 13:05:05 +0100 | [diff] [blame] | 585 | /* New power management framework */ |
| 586 | |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 587 | static int pci_pm_prepare(struct device *dev) |
| 588 | { |
| 589 | struct device_driver *drv = dev->driver; |
| 590 | int error = 0; |
| 591 | |
Rafael J. Wysocki | 6cbf821 | 2010-02-17 23:44:58 +0100 | [diff] [blame] | 592 | /* |
| 593 | * PCI devices suspended at run time need to be resumed at this |
| 594 | * point, because in general it is necessary to reconfigure them for |
| 595 | * system suspend. Namely, if the device is supposed to wake up the |
| 596 | * system from the sleep state, we may need to reconfigure it for this |
| 597 | * purpose. In turn, if the device is not supposed to wake up the |
| 598 | * system from the sleep state, we'll have to prevent it from signaling |
| 599 | * wake-up. |
| 600 | */ |
Rafael J. Wysocki | eea3fc03 | 2011-07-06 10:51:40 +0200 | [diff] [blame] | 601 | pm_runtime_resume(dev); |
Rafael J. Wysocki | 6cbf821 | 2010-02-17 23:44:58 +0100 | [diff] [blame] | 602 | |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 603 | if (drv && drv->pm && drv->pm->prepare) |
| 604 | error = drv->pm->prepare(dev); |
| 605 | |
| 606 | return error; |
| 607 | } |
| 608 | |
| 609 | static void pci_pm_complete(struct device *dev) |
| 610 | { |
| 611 | struct device_driver *drv = dev->driver; |
| 612 | |
| 613 | if (drv && drv->pm && drv->pm->complete) |
| 614 | drv->pm->complete(dev); |
| 615 | } |
| 616 | |
Rafael J. Wysocki | 6cbf821 | 2010-02-17 23:44:58 +0100 | [diff] [blame] | 617 | #else /* !CONFIG_PM_SLEEP */ |
| 618 | |
| 619 | #define pci_pm_prepare NULL |
| 620 | #define pci_pm_complete NULL |
| 621 | |
| 622 | #endif /* !CONFIG_PM_SLEEP */ |
| 623 | |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 624 | #ifdef CONFIG_SUSPEND |
| 625 | |
| 626 | static int pci_pm_suspend(struct device *dev) |
| 627 | { |
| 628 | struct pci_dev *pci_dev = to_pci_dev(dev); |
Dmitry Torokhov | 8150f32 | 2009-07-24 22:11:32 -0700 | [diff] [blame] | 629 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 630 | |
Rafael J. Wysocki | ad8cfa1 | 2009-01-07 13:09:37 +0100 | [diff] [blame] | 631 | if (pci_has_legacy_pm_support(pci_dev)) |
| 632 | return pci_legacy_suspend(dev, PMSG_SUSPEND); |
Rafael J. Wysocki | bb80894 | 2009-01-07 14:15:17 +0100 | [diff] [blame] | 633 | |
Rafael J. Wysocki | 5294e25 | 2009-02-04 02:09:07 +0100 | [diff] [blame] | 634 | if (!pm) { |
| 635 | pci_pm_default_suspend(pci_dev); |
| 636 | goto Fixup; |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 637 | } |
Rafael J. Wysocki | fa58d30 | 2009-01-07 13:03:42 +0100 | [diff] [blame] | 638 | |
Rafael J. Wysocki | 5294e25 | 2009-02-04 02:09:07 +0100 | [diff] [blame] | 639 | if (pm->suspend) { |
| 640 | pci_power_t prev = pci_dev->current_state; |
| 641 | int error; |
| 642 | |
| 643 | error = pm->suspend(dev); |
| 644 | suspend_report_result(pm->suspend, error); |
| 645 | if (error) |
| 646 | return error; |
| 647 | |
Rafael J. Wysocki | 46939f8 | 2009-03-16 22:40:26 +0100 | [diff] [blame] | 648 | if (!pci_dev->state_saved && pci_dev->current_state != PCI_D0 |
Rafael J. Wysocki | 5294e25 | 2009-02-04 02:09:07 +0100 | [diff] [blame] | 649 | && pci_dev->current_state != PCI_UNKNOWN) { |
| 650 | WARN_ONCE(pci_dev->current_state != prev, |
| 651 | "PCI PM: State of device not saved by %pF\n", |
| 652 | pm->suspend); |
Rafael J. Wysocki | 5294e25 | 2009-02-04 02:09:07 +0100 | [diff] [blame] | 653 | } |
| 654 | } |
| 655 | |
Rafael J. Wysocki | 5294e25 | 2009-02-04 02:09:07 +0100 | [diff] [blame] | 656 | Fixup: |
| 657 | pci_fixup_device(pci_fixup_suspend, pci_dev); |
| 658 | |
| 659 | return 0; |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | static int pci_pm_suspend_noirq(struct device *dev) |
Greg KH | c895817 | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 663 | { |
Rafael J. Wysocki | 355a72d | 2008-12-08 00:34:57 +0100 | [diff] [blame] | 664 | struct pci_dev *pci_dev = to_pci_dev(dev); |
Dmitry Torokhov | 8150f32 | 2009-07-24 22:11:32 -0700 | [diff] [blame] | 665 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; |
Greg KH | c895817 | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 666 | |
Rafael J. Wysocki | bb80894 | 2009-01-07 14:15:17 +0100 | [diff] [blame] | 667 | if (pci_has_legacy_pm_support(pci_dev)) |
| 668 | return pci_legacy_suspend_late(dev, PMSG_SUSPEND); |
| 669 | |
Rafael J. Wysocki | 931ff68 | 2009-03-16 22:40:50 +0100 | [diff] [blame] | 670 | if (!pm) { |
| 671 | pci_save_state(pci_dev); |
Rafael J. Wysocki | 46939f8 | 2009-03-16 22:40:26 +0100 | [diff] [blame] | 672 | return 0; |
Rafael J. Wysocki | 931ff68 | 2009-03-16 22:40:50 +0100 | [diff] [blame] | 673 | } |
Rafael J. Wysocki | 46939f8 | 2009-03-16 22:40:26 +0100 | [diff] [blame] | 674 | |
| 675 | if (pm->suspend_noirq) { |
| 676 | pci_power_t prev = pci_dev->current_state; |
| 677 | int error; |
| 678 | |
| 679 | error = pm->suspend_noirq(dev); |
| 680 | suspend_report_result(pm->suspend_noirq, error); |
| 681 | if (error) |
| 682 | return error; |
| 683 | |
| 684 | if (!pci_dev->state_saved && pci_dev->current_state != PCI_D0 |
| 685 | && pci_dev->current_state != PCI_UNKNOWN) { |
| 686 | WARN_ONCE(pci_dev->current_state != prev, |
| 687 | "PCI PM: State of device not saved by %pF\n", |
| 688 | pm->suspend_noirq); |
| 689 | return 0; |
| 690 | } |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 691 | } |
| 692 | |
Rafael J. Wysocki | 46939f8 | 2009-03-16 22:40:26 +0100 | [diff] [blame] | 693 | if (!pci_dev->state_saved) { |
| 694 | pci_save_state(pci_dev); |
| 695 | if (!pci_is_bridge(pci_dev)) |
| 696 | pci_prepare_to_sleep(pci_dev); |
| 697 | } |
Rafael J. Wysocki | d67e37d | 2009-01-07 13:11:28 +0100 | [diff] [blame] | 698 | |
Rafael J. Wysocki | 46939f8 | 2009-03-16 22:40:26 +0100 | [diff] [blame] | 699 | pci_pm_set_unknown_state(pci_dev); |
| 700 | |
Alan Stern | dbf0e4c | 2012-07-09 11:09:21 -0400 | [diff] [blame] | 701 | /* |
| 702 | * Some BIOSes from ASUS have a bug: If a USB EHCI host controller's |
| 703 | * PCI COMMAND register isn't 0, the BIOS assumes that the controller |
| 704 | * hasn't been quiesced and tries to turn it off. If the controller |
| 705 | * is already in D3, this can hang or cause memory corruption. |
| 706 | * |
| 707 | * Since the value of the COMMAND register doesn't matter once the |
| 708 | * device has been suspended, we can safely set it to 0 here. |
| 709 | */ |
| 710 | if (pci_dev->class == PCI_CLASS_SERIAL_USB_EHCI) |
| 711 | pci_write_config_word(pci_dev, PCI_COMMAND, 0); |
| 712 | |
Rafael J. Wysocki | 46939f8 | 2009-03-16 22:40:26 +0100 | [diff] [blame] | 713 | return 0; |
Greg KH | c895817 | 2005-04-08 14:53:31 +0900 | [diff] [blame] | 714 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 716 | static int pci_pm_resume_noirq(struct device *dev) |
| 717 | { |
Rafael J. Wysocki | 355a72d | 2008-12-08 00:34:57 +0100 | [diff] [blame] | 718 | struct pci_dev *pci_dev = to_pci_dev(dev); |
Rafael J. Wysocki | adf0949 | 2008-10-06 22:46:05 +0200 | [diff] [blame] | 719 | struct device_driver *drv = dev->driver; |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 720 | int error = 0; |
| 721 | |
Rafael J. Wysocki | 6cbf821 | 2010-02-17 23:44:58 +0100 | [diff] [blame] | 722 | pci_pm_default_resume_early(pci_dev); |
Rafael J. Wysocki | aa8c6c9 | 2009-01-16 21:54:43 +0100 | [diff] [blame] | 723 | |
Rafael J. Wysocki | ad8cfa1 | 2009-01-07 13:09:37 +0100 | [diff] [blame] | 724 | if (pci_has_legacy_pm_support(pci_dev)) |
Rafael J. Wysocki | bb80894 | 2009-01-07 14:15:17 +0100 | [diff] [blame] | 725 | return pci_legacy_resume_early(dev); |
Rafael J. Wysocki | bb80894 | 2009-01-07 14:15:17 +0100 | [diff] [blame] | 726 | |
Rafael J. Wysocki | d67e37d | 2009-01-07 13:11:28 +0100 | [diff] [blame] | 727 | if (drv && drv->pm && drv->pm->resume_noirq) |
| 728 | error = drv->pm->resume_noirq(dev); |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 729 | |
| 730 | return error; |
| 731 | } |
| 732 | |
Rafael J. Wysocki | f6dc1e5 | 2009-01-07 13:12:22 +0100 | [diff] [blame] | 733 | static int pci_pm_resume(struct device *dev) |
| 734 | { |
| 735 | struct pci_dev *pci_dev = to_pci_dev(dev); |
Dmitry Torokhov | 8150f32 | 2009-07-24 22:11:32 -0700 | [diff] [blame] | 736 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; |
Rafael J. Wysocki | f6dc1e5 | 2009-01-07 13:12:22 +0100 | [diff] [blame] | 737 | int error = 0; |
| 738 | |
Rafael J. Wysocki | 418e4da | 2009-01-26 21:43:08 +0100 | [diff] [blame] | 739 | /* |
| 740 | * This is necessary for the suspend error path in which resume is |
| 741 | * called without restoring the standard config registers of the device. |
| 742 | */ |
| 743 | if (pci_dev->state_saved) |
| 744 | pci_restore_standard_config(pci_dev); |
| 745 | |
Rafael J. Wysocki | f6dc1e5 | 2009-01-07 13:12:22 +0100 | [diff] [blame] | 746 | if (pci_has_legacy_pm_support(pci_dev)) |
| 747 | return pci_legacy_resume(dev); |
| 748 | |
Rafael J. Wysocki | 5294e25 | 2009-02-04 02:09:07 +0100 | [diff] [blame] | 749 | pci_pm_default_resume(pci_dev); |
Rafael J. Wysocki | f6dc1e5 | 2009-01-07 13:12:22 +0100 | [diff] [blame] | 750 | |
Rafael J. Wysocki | 5294e25 | 2009-02-04 02:09:07 +0100 | [diff] [blame] | 751 | if (pm) { |
| 752 | if (pm->resume) |
| 753 | error = pm->resume(dev); |
| 754 | } else { |
| 755 | pci_pm_reenable_device(pci_dev); |
| 756 | } |
Rafael J. Wysocki | f6dc1e5 | 2009-01-07 13:12:22 +0100 | [diff] [blame] | 757 | |
Rafael J. Wysocki | 999cce4 | 2009-09-09 23:51:27 +0200 | [diff] [blame] | 758 | return error; |
Rafael J. Wysocki | f6dc1e5 | 2009-01-07 13:12:22 +0100 | [diff] [blame] | 759 | } |
| 760 | |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 761 | #else /* !CONFIG_SUSPEND */ |
| 762 | |
| 763 | #define pci_pm_suspend NULL |
| 764 | #define pci_pm_suspend_noirq NULL |
| 765 | #define pci_pm_resume NULL |
| 766 | #define pci_pm_resume_noirq NULL |
| 767 | |
| 768 | #endif /* !CONFIG_SUSPEND */ |
| 769 | |
Rafael J. Wysocki | 1f112ce | 2011-04-11 22:54:42 +0200 | [diff] [blame] | 770 | #ifdef CONFIG_HIBERNATE_CALLBACKS |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 771 | |
| 772 | static int pci_pm_freeze(struct device *dev) |
| 773 | { |
| 774 | struct pci_dev *pci_dev = to_pci_dev(dev); |
Dmitry Torokhov | 8150f32 | 2009-07-24 22:11:32 -0700 | [diff] [blame] | 775 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 776 | |
Rafael J. Wysocki | ad8cfa1 | 2009-01-07 13:09:37 +0100 | [diff] [blame] | 777 | if (pci_has_legacy_pm_support(pci_dev)) |
| 778 | return pci_legacy_suspend(dev, PMSG_FREEZE); |
Rafael J. Wysocki | bb80894 | 2009-01-07 14:15:17 +0100 | [diff] [blame] | 779 | |
Rafael J. Wysocki | 5294e25 | 2009-02-04 02:09:07 +0100 | [diff] [blame] | 780 | if (!pm) { |
| 781 | pci_pm_default_suspend(pci_dev); |
| 782 | return 0; |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 783 | } |
| 784 | |
Rafael J. Wysocki | 5294e25 | 2009-02-04 02:09:07 +0100 | [diff] [blame] | 785 | if (pm->freeze) { |
| 786 | int error; |
| 787 | |
| 788 | error = pm->freeze(dev); |
| 789 | suspend_report_result(pm->freeze, error); |
| 790 | if (error) |
| 791 | return error; |
| 792 | } |
| 793 | |
Rafael J. Wysocki | 5294e25 | 2009-02-04 02:09:07 +0100 | [diff] [blame] | 794 | return 0; |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | static int pci_pm_freeze_noirq(struct device *dev) |
| 798 | { |
Rafael J. Wysocki | 355a72d | 2008-12-08 00:34:57 +0100 | [diff] [blame] | 799 | struct pci_dev *pci_dev = to_pci_dev(dev); |
Rafael J. Wysocki | adf0949 | 2008-10-06 22:46:05 +0200 | [diff] [blame] | 800 | struct device_driver *drv = dev->driver; |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 801 | |
Rafael J. Wysocki | bb80894 | 2009-01-07 14:15:17 +0100 | [diff] [blame] | 802 | if (pci_has_legacy_pm_support(pci_dev)) |
| 803 | return pci_legacy_suspend_late(dev, PMSG_FREEZE); |
| 804 | |
Rafael J. Wysocki | d67e37d | 2009-01-07 13:11:28 +0100 | [diff] [blame] | 805 | if (drv && drv->pm && drv->pm->freeze_noirq) { |
Rafael J. Wysocki | 46939f8 | 2009-03-16 22:40:26 +0100 | [diff] [blame] | 806 | int error; |
| 807 | |
Rafael J. Wysocki | d67e37d | 2009-01-07 13:11:28 +0100 | [diff] [blame] | 808 | error = drv->pm->freeze_noirq(dev); |
| 809 | suspend_report_result(drv->pm->freeze_noirq, error); |
Rafael J. Wysocki | 46939f8 | 2009-03-16 22:40:26 +0100 | [diff] [blame] | 810 | if (error) |
| 811 | return error; |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 812 | } |
| 813 | |
Rafael J. Wysocki | 46939f8 | 2009-03-16 22:40:26 +0100 | [diff] [blame] | 814 | if (!pci_dev->state_saved) |
| 815 | pci_save_state(pci_dev); |
Rafael J. Wysocki | d67e37d | 2009-01-07 13:11:28 +0100 | [diff] [blame] | 816 | |
Rafael J. Wysocki | 46939f8 | 2009-03-16 22:40:26 +0100 | [diff] [blame] | 817 | pci_pm_set_unknown_state(pci_dev); |
| 818 | |
| 819 | return 0; |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 820 | } |
| 821 | |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 822 | static int pci_pm_thaw_noirq(struct device *dev) |
| 823 | { |
Rafael J. Wysocki | 355a72d | 2008-12-08 00:34:57 +0100 | [diff] [blame] | 824 | struct pci_dev *pci_dev = to_pci_dev(dev); |
Rafael J. Wysocki | adf0949 | 2008-10-06 22:46:05 +0200 | [diff] [blame] | 825 | struct device_driver *drv = dev->driver; |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 826 | int error = 0; |
| 827 | |
Rafael J. Wysocki | ad8cfa1 | 2009-01-07 13:09:37 +0100 | [diff] [blame] | 828 | if (pci_has_legacy_pm_support(pci_dev)) |
Rafael J. Wysocki | bb80894 | 2009-01-07 14:15:17 +0100 | [diff] [blame] | 829 | return pci_legacy_resume_early(dev); |
Rafael J. Wysocki | bb80894 | 2009-01-07 14:15:17 +0100 | [diff] [blame] | 830 | |
Rafael J. Wysocki | d67e37d | 2009-01-07 13:11:28 +0100 | [diff] [blame] | 831 | pci_update_current_state(pci_dev, PCI_D0); |
| 832 | |
| 833 | if (drv && drv->pm && drv->pm->thaw_noirq) |
| 834 | error = drv->pm->thaw_noirq(dev); |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 835 | |
| 836 | return error; |
| 837 | } |
| 838 | |
Rafael J. Wysocki | f6dc1e5 | 2009-01-07 13:12:22 +0100 | [diff] [blame] | 839 | static int pci_pm_thaw(struct device *dev) |
| 840 | { |
| 841 | struct pci_dev *pci_dev = to_pci_dev(dev); |
Dmitry Torokhov | 8150f32 | 2009-07-24 22:11:32 -0700 | [diff] [blame] | 842 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; |
Rafael J. Wysocki | f6dc1e5 | 2009-01-07 13:12:22 +0100 | [diff] [blame] | 843 | int error = 0; |
| 844 | |
| 845 | if (pci_has_legacy_pm_support(pci_dev)) |
| 846 | return pci_legacy_resume(dev); |
| 847 | |
Rafael J. Wysocki | 5294e25 | 2009-02-04 02:09:07 +0100 | [diff] [blame] | 848 | if (pm) { |
| 849 | if (pm->thaw) |
| 850 | error = pm->thaw(dev); |
| 851 | } else { |
| 852 | pci_pm_reenable_device(pci_dev); |
| 853 | } |
Rafael J. Wysocki | f6dc1e5 | 2009-01-07 13:12:22 +0100 | [diff] [blame] | 854 | |
Rafael J. Wysocki | 4b77b0a | 2009-09-09 23:49:59 +0200 | [diff] [blame] | 855 | pci_dev->state_saved = false; |
| 856 | |
Rafael J. Wysocki | f6dc1e5 | 2009-01-07 13:12:22 +0100 | [diff] [blame] | 857 | return error; |
| 858 | } |
| 859 | |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 860 | static int pci_pm_poweroff(struct device *dev) |
| 861 | { |
Rafael J. Wysocki | 355a72d | 2008-12-08 00:34:57 +0100 | [diff] [blame] | 862 | struct pci_dev *pci_dev = to_pci_dev(dev); |
Dmitry Torokhov | 8150f32 | 2009-07-24 22:11:32 -0700 | [diff] [blame] | 863 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 864 | |
Rafael J. Wysocki | ad8cfa1 | 2009-01-07 13:09:37 +0100 | [diff] [blame] | 865 | if (pci_has_legacy_pm_support(pci_dev)) |
| 866 | return pci_legacy_suspend(dev, PMSG_HIBERNATE); |
Rafael J. Wysocki | bb80894 | 2009-01-07 14:15:17 +0100 | [diff] [blame] | 867 | |
Rafael J. Wysocki | 5294e25 | 2009-02-04 02:09:07 +0100 | [diff] [blame] | 868 | if (!pm) { |
| 869 | pci_pm_default_suspend(pci_dev); |
| 870 | goto Fixup; |
| 871 | } |
| 872 | |
Rafael J. Wysocki | 5294e25 | 2009-02-04 02:09:07 +0100 | [diff] [blame] | 873 | if (pm->poweroff) { |
Rafael J. Wysocki | 46939f8 | 2009-03-16 22:40:26 +0100 | [diff] [blame] | 874 | int error; |
| 875 | |
Rafael J. Wysocki | ddb7c9d | 2009-02-04 01:56:14 +0100 | [diff] [blame] | 876 | error = pm->poweroff(dev); |
| 877 | suspend_report_result(pm->poweroff, error); |
Rafael J. Wysocki | 46939f8 | 2009-03-16 22:40:26 +0100 | [diff] [blame] | 878 | if (error) |
| 879 | return error; |
| 880 | } |
| 881 | |
| 882 | Fixup: |
| 883 | pci_fixup_device(pci_fixup_suspend, pci_dev); |
| 884 | |
| 885 | return 0; |
| 886 | } |
| 887 | |
| 888 | static int pci_pm_poweroff_noirq(struct device *dev) |
| 889 | { |
| 890 | struct pci_dev *pci_dev = to_pci_dev(dev); |
| 891 | struct device_driver *drv = dev->driver; |
| 892 | |
| 893 | if (pci_has_legacy_pm_support(to_pci_dev(dev))) |
| 894 | return pci_legacy_suspend_late(dev, PMSG_HIBERNATE); |
| 895 | |
| 896 | if (!drv || !drv->pm) |
| 897 | return 0; |
| 898 | |
| 899 | if (drv->pm->poweroff_noirq) { |
| 900 | int error; |
| 901 | |
| 902 | error = drv->pm->poweroff_noirq(dev); |
| 903 | suspend_report_result(drv->pm->poweroff_noirq, error); |
| 904 | if (error) |
| 905 | return error; |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 906 | } |
| 907 | |
Rafael J. Wysocki | 5294e25 | 2009-02-04 02:09:07 +0100 | [diff] [blame] | 908 | if (!pci_dev->state_saved && !pci_is_bridge(pci_dev)) |
| 909 | pci_prepare_to_sleep(pci_dev); |
| 910 | |
Rafael J. Wysocki | 0b68c8e | 2012-08-12 23:26:07 +0200 | [diff] [blame] | 911 | /* |
| 912 | * The reason for doing this here is the same as for the analogous code |
| 913 | * in pci_pm_suspend_noirq(). |
| 914 | */ |
| 915 | if (pci_dev->class == PCI_CLASS_SERIAL_USB_EHCI) |
| 916 | pci_write_config_word(pci_dev, PCI_COMMAND, 0); |
| 917 | |
Rafael J. Wysocki | 46939f8 | 2009-03-16 22:40:26 +0100 | [diff] [blame] | 918 | return 0; |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 919 | } |
| 920 | |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 921 | static int pci_pm_restore_noirq(struct device *dev) |
| 922 | { |
| 923 | struct pci_dev *pci_dev = to_pci_dev(dev); |
Rafael J. Wysocki | adf0949 | 2008-10-06 22:46:05 +0200 | [diff] [blame] | 924 | struct device_driver *drv = dev->driver; |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 925 | int error = 0; |
| 926 | |
Rafael J. Wysocki | 6cbf821 | 2010-02-17 23:44:58 +0100 | [diff] [blame] | 927 | pci_pm_default_resume_early(pci_dev); |
Rafael J. Wysocki | aa8c6c9 | 2009-01-16 21:54:43 +0100 | [diff] [blame] | 928 | |
Rafael J. Wysocki | ad8cfa1 | 2009-01-07 13:09:37 +0100 | [diff] [blame] | 929 | if (pci_has_legacy_pm_support(pci_dev)) |
Rafael J. Wysocki | bb80894 | 2009-01-07 14:15:17 +0100 | [diff] [blame] | 930 | return pci_legacy_resume_early(dev); |
Rafael J. Wysocki | bb80894 | 2009-01-07 14:15:17 +0100 | [diff] [blame] | 931 | |
Rafael J. Wysocki | d67e37d | 2009-01-07 13:11:28 +0100 | [diff] [blame] | 932 | if (drv && drv->pm && drv->pm->restore_noirq) |
| 933 | error = drv->pm->restore_noirq(dev); |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 934 | |
| 935 | return error; |
| 936 | } |
| 937 | |
Rafael J. Wysocki | f6dc1e5 | 2009-01-07 13:12:22 +0100 | [diff] [blame] | 938 | static int pci_pm_restore(struct device *dev) |
| 939 | { |
| 940 | struct pci_dev *pci_dev = to_pci_dev(dev); |
Dmitry Torokhov | 8150f32 | 2009-07-24 22:11:32 -0700 | [diff] [blame] | 941 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; |
Rafael J. Wysocki | f6dc1e5 | 2009-01-07 13:12:22 +0100 | [diff] [blame] | 942 | int error = 0; |
| 943 | |
Rafael J. Wysocki | 418e4da | 2009-01-26 21:43:08 +0100 | [diff] [blame] | 944 | /* |
| 945 | * This is necessary for the hibernation error path in which restore is |
| 946 | * called without restoring the standard config registers of the device. |
| 947 | */ |
| 948 | if (pci_dev->state_saved) |
| 949 | pci_restore_standard_config(pci_dev); |
| 950 | |
Rafael J. Wysocki | f6dc1e5 | 2009-01-07 13:12:22 +0100 | [diff] [blame] | 951 | if (pci_has_legacy_pm_support(pci_dev)) |
| 952 | return pci_legacy_resume(dev); |
| 953 | |
Rafael J. Wysocki | 5294e25 | 2009-02-04 02:09:07 +0100 | [diff] [blame] | 954 | pci_pm_default_resume(pci_dev); |
Rafael J. Wysocki | f6dc1e5 | 2009-01-07 13:12:22 +0100 | [diff] [blame] | 955 | |
Rafael J. Wysocki | 5294e25 | 2009-02-04 02:09:07 +0100 | [diff] [blame] | 956 | if (pm) { |
| 957 | if (pm->restore) |
| 958 | error = pm->restore(dev); |
| 959 | } else { |
| 960 | pci_pm_reenable_device(pci_dev); |
| 961 | } |
Rafael J. Wysocki | f6dc1e5 | 2009-01-07 13:12:22 +0100 | [diff] [blame] | 962 | |
| 963 | return error; |
| 964 | } |
| 965 | |
Rafael J. Wysocki | 1f112ce | 2011-04-11 22:54:42 +0200 | [diff] [blame] | 966 | #else /* !CONFIG_HIBERNATE_CALLBACKS */ |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 967 | |
| 968 | #define pci_pm_freeze NULL |
| 969 | #define pci_pm_freeze_noirq NULL |
| 970 | #define pci_pm_thaw NULL |
| 971 | #define pci_pm_thaw_noirq NULL |
| 972 | #define pci_pm_poweroff NULL |
| 973 | #define pci_pm_poweroff_noirq NULL |
| 974 | #define pci_pm_restore NULL |
| 975 | #define pci_pm_restore_noirq NULL |
| 976 | |
Rafael J. Wysocki | 1f112ce | 2011-04-11 22:54:42 +0200 | [diff] [blame] | 977 | #endif /* !CONFIG_HIBERNATE_CALLBACKS */ |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 978 | |
Rafael J. Wysocki | 6cbf821 | 2010-02-17 23:44:58 +0100 | [diff] [blame] | 979 | #ifdef CONFIG_PM_RUNTIME |
| 980 | |
| 981 | static int pci_pm_runtime_suspend(struct device *dev) |
| 982 | { |
| 983 | struct pci_dev *pci_dev = to_pci_dev(dev); |
| 984 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; |
| 985 | pci_power_t prev = pci_dev->current_state; |
| 986 | int error; |
| 987 | |
Huang Ying | 967577b | 2012-11-20 16:08:22 +0800 | [diff] [blame^] | 988 | /* |
| 989 | * If pci_dev->driver is not set (unbound), the device should |
| 990 | * always remain in D0 regardless of the runtime PM status |
| 991 | */ |
| 992 | if (!pci_dev->driver) |
| 993 | return 0; |
| 994 | |
Rafael J. Wysocki | 6cbf821 | 2010-02-17 23:44:58 +0100 | [diff] [blame] | 995 | if (!pm || !pm->runtime_suspend) |
| 996 | return -ENOSYS; |
| 997 | |
Huang Ying | 448bd85 | 2012-06-23 10:23:51 +0800 | [diff] [blame] | 998 | pci_dev->no_d3cold = false; |
Rafael J. Wysocki | 6cbf821 | 2010-02-17 23:44:58 +0100 | [diff] [blame] | 999 | error = pm->runtime_suspend(dev); |
| 1000 | suspend_report_result(pm->runtime_suspend, error); |
| 1001 | if (error) |
| 1002 | return error; |
Huang Ying | 448bd85 | 2012-06-23 10:23:51 +0800 | [diff] [blame] | 1003 | if (!pci_dev->d3cold_allowed) |
| 1004 | pci_dev->no_d3cold = true; |
Rafael J. Wysocki | 6cbf821 | 2010-02-17 23:44:58 +0100 | [diff] [blame] | 1005 | |
| 1006 | pci_fixup_device(pci_fixup_suspend, pci_dev); |
| 1007 | |
| 1008 | if (!pci_dev->state_saved && pci_dev->current_state != PCI_D0 |
| 1009 | && pci_dev->current_state != PCI_UNKNOWN) { |
| 1010 | WARN_ONCE(pci_dev->current_state != prev, |
| 1011 | "PCI PM: State of device not saved by %pF\n", |
| 1012 | pm->runtime_suspend); |
| 1013 | return 0; |
| 1014 | } |
| 1015 | |
| 1016 | if (!pci_dev->state_saved) |
| 1017 | pci_save_state(pci_dev); |
| 1018 | |
| 1019 | pci_finish_runtime_suspend(pci_dev); |
| 1020 | |
| 1021 | return 0; |
| 1022 | } |
| 1023 | |
| 1024 | static int pci_pm_runtime_resume(struct device *dev) |
| 1025 | { |
Huang Ying | 448bd85 | 2012-06-23 10:23:51 +0800 | [diff] [blame] | 1026 | int rc; |
Rafael J. Wysocki | 6cbf821 | 2010-02-17 23:44:58 +0100 | [diff] [blame] | 1027 | struct pci_dev *pci_dev = to_pci_dev(dev); |
| 1028 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; |
| 1029 | |
Huang Ying | 967577b | 2012-11-20 16:08:22 +0800 | [diff] [blame^] | 1030 | /* |
| 1031 | * If pci_dev->driver is not set (unbound), the device should |
| 1032 | * always remain in D0 regardless of the runtime PM status |
| 1033 | */ |
| 1034 | if (!pci_dev->driver) |
| 1035 | return 0; |
| 1036 | |
Rafael J. Wysocki | 6cbf821 | 2010-02-17 23:44:58 +0100 | [diff] [blame] | 1037 | if (!pm || !pm->runtime_resume) |
| 1038 | return -ENOSYS; |
| 1039 | |
Rafael J. Wysocki | db288c9 | 2012-07-05 15:20:00 -0600 | [diff] [blame] | 1040 | pci_restore_standard_config(pci_dev); |
| 1041 | pci_fixup_device(pci_fixup_resume_early, pci_dev); |
Rafael J. Wysocki | 6cbf821 | 2010-02-17 23:44:58 +0100 | [diff] [blame] | 1042 | __pci_enable_wake(pci_dev, PCI_D0, true, false); |
| 1043 | pci_fixup_device(pci_fixup_resume, pci_dev); |
| 1044 | |
Huang Ying | 448bd85 | 2012-06-23 10:23:51 +0800 | [diff] [blame] | 1045 | rc = pm->runtime_resume(dev); |
| 1046 | |
| 1047 | pci_dev->runtime_d3cold = false; |
| 1048 | |
| 1049 | return rc; |
Rafael J. Wysocki | 6cbf821 | 2010-02-17 23:44:58 +0100 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | static int pci_pm_runtime_idle(struct device *dev) |
| 1053 | { |
Huang Ying | 967577b | 2012-11-20 16:08:22 +0800 | [diff] [blame^] | 1054 | struct pci_dev *pci_dev = to_pci_dev(dev); |
Rafael J. Wysocki | 6cbf821 | 2010-02-17 23:44:58 +0100 | [diff] [blame] | 1055 | const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; |
| 1056 | |
Huang Ying | 967577b | 2012-11-20 16:08:22 +0800 | [diff] [blame^] | 1057 | /* |
| 1058 | * If pci_dev->driver is not set (unbound), the device should |
| 1059 | * always remain in D0 regardless of the runtime PM status |
| 1060 | */ |
| 1061 | if (!pci_dev->driver) |
| 1062 | goto out; |
| 1063 | |
Rafael J. Wysocki | 6cbf821 | 2010-02-17 23:44:58 +0100 | [diff] [blame] | 1064 | if (!pm) |
| 1065 | return -ENOSYS; |
| 1066 | |
| 1067 | if (pm->runtime_idle) { |
| 1068 | int ret = pm->runtime_idle(dev); |
| 1069 | if (ret) |
| 1070 | return ret; |
| 1071 | } |
| 1072 | |
Huang Ying | 967577b | 2012-11-20 16:08:22 +0800 | [diff] [blame^] | 1073 | out: |
Rafael J. Wysocki | 6cbf821 | 2010-02-17 23:44:58 +0100 | [diff] [blame] | 1074 | pm_runtime_suspend(dev); |
Rafael J. Wysocki | 6cbf821 | 2010-02-17 23:44:58 +0100 | [diff] [blame] | 1075 | return 0; |
| 1076 | } |
| 1077 | |
| 1078 | #else /* !CONFIG_PM_RUNTIME */ |
| 1079 | |
| 1080 | #define pci_pm_runtime_suspend NULL |
| 1081 | #define pci_pm_runtime_resume NULL |
| 1082 | #define pci_pm_runtime_idle NULL |
| 1083 | |
| 1084 | #endif /* !CONFIG_PM_RUNTIME */ |
| 1085 | |
Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 1086 | #ifdef CONFIG_PM |
Rafael J. Wysocki | 6cbf821 | 2010-02-17 23:44:58 +0100 | [diff] [blame] | 1087 | |
Dmitry Torokhov | 8150f32 | 2009-07-24 22:11:32 -0700 | [diff] [blame] | 1088 | const struct dev_pm_ops pci_dev_pm_ops = { |
Rafael J. Wysocki | adf0949 | 2008-10-06 22:46:05 +0200 | [diff] [blame] | 1089 | .prepare = pci_pm_prepare, |
| 1090 | .complete = pci_pm_complete, |
| 1091 | .suspend = pci_pm_suspend, |
| 1092 | .resume = pci_pm_resume, |
| 1093 | .freeze = pci_pm_freeze, |
| 1094 | .thaw = pci_pm_thaw, |
| 1095 | .poweroff = pci_pm_poweroff, |
| 1096 | .restore = pci_pm_restore, |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 1097 | .suspend_noirq = pci_pm_suspend_noirq, |
| 1098 | .resume_noirq = pci_pm_resume_noirq, |
| 1099 | .freeze_noirq = pci_pm_freeze_noirq, |
| 1100 | .thaw_noirq = pci_pm_thaw_noirq, |
| 1101 | .poweroff_noirq = pci_pm_poweroff_noirq, |
| 1102 | .restore_noirq = pci_pm_restore_noirq, |
Rafael J. Wysocki | 6cbf821 | 2010-02-17 23:44:58 +0100 | [diff] [blame] | 1103 | .runtime_suspend = pci_pm_runtime_suspend, |
| 1104 | .runtime_resume = pci_pm_runtime_resume, |
| 1105 | .runtime_idle = pci_pm_runtime_idle, |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 1106 | }; |
| 1107 | |
Rafael J. Wysocki | adf0949 | 2008-10-06 22:46:05 +0200 | [diff] [blame] | 1108 | #define PCI_PM_OPS_PTR (&pci_dev_pm_ops) |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 1109 | |
Rafael J. Wysocki | 6cbf821 | 2010-02-17 23:44:58 +0100 | [diff] [blame] | 1110 | #else /* !COMFIG_PM_OPS */ |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 1111 | |
| 1112 | #define PCI_PM_OPS_PTR NULL |
| 1113 | |
Rafael J. Wysocki | 6cbf821 | 2010-02-17 23:44:58 +0100 | [diff] [blame] | 1114 | #endif /* !COMFIG_PM_OPS */ |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 1115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | /** |
Laurent riffard | 863b18f | 2005-10-27 23:12:54 +0200 | [diff] [blame] | 1117 | * __pci_register_driver - register a new pci driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | * @drv: the driver structure to register |
Laurent riffard | 863b18f | 2005-10-27 23:12:54 +0200 | [diff] [blame] | 1119 | * @owner: owner module of drv |
Randy Dunlap | f95d882 | 2007-02-10 14:41:56 -0800 | [diff] [blame] | 1120 | * @mod_name: module name string |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | * |
| 1122 | * Adds the driver structure to the list of registered drivers. |
| 1123 | * Returns a negative value on error, otherwise 0. |
Steven Cole | eaae4b3 | 2005-05-03 18:38:30 -0600 | [diff] [blame] | 1124 | * If no error occurred, the driver remains registered even if |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | * no device was claimed during registration. |
| 1126 | */ |
Greg Kroah-Hartman | 725522b | 2007-01-15 11:50:02 -0800 | [diff] [blame] | 1127 | int __pci_register_driver(struct pci_driver *drv, struct module *owner, |
| 1128 | const char *mod_name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | /* initialize common driver fields */ |
| 1131 | drv->driver.name = drv->name; |
| 1132 | drv->driver.bus = &pci_bus_type; |
Laurent riffard | 863b18f | 2005-10-27 23:12:54 +0200 | [diff] [blame] | 1133 | drv->driver.owner = owner; |
Greg Kroah-Hartman | 725522b | 2007-01-15 11:50:02 -0800 | [diff] [blame] | 1134 | drv->driver.mod_name = mod_name; |
Alan Cox | 50b0075 | 2006-08-16 17:42:18 +0100 | [diff] [blame] | 1135 | |
Greg Kroah-Hartman | 7586585 | 2005-06-30 02:18:12 -0700 | [diff] [blame] | 1136 | spin_lock_init(&drv->dynids.lock); |
| 1137 | INIT_LIST_HEAD(&drv->dynids.list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | |
| 1139 | /* register with core */ |
Konstantin Khlebnikov | bfb09a8 | 2012-08-08 14:47:51 +0400 | [diff] [blame] | 1140 | return driver_register(&drv->driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | } |
| 1142 | |
| 1143 | /** |
| 1144 | * pci_unregister_driver - unregister a pci driver |
| 1145 | * @drv: the driver structure to unregister |
| 1146 | * |
| 1147 | * Deletes the driver structure from the list of registered PCI drivers, |
| 1148 | * gives it a chance to clean up by calling its remove() function for |
| 1149 | * each device it was responsible for, and marks those devices as |
| 1150 | * driverless. |
| 1151 | */ |
| 1152 | |
| 1153 | void |
| 1154 | pci_unregister_driver(struct pci_driver *drv) |
| 1155 | { |
| 1156 | driver_unregister(&drv->driver); |
| 1157 | pci_free_dynids(drv); |
| 1158 | } |
| 1159 | |
| 1160 | static struct pci_driver pci_compat_driver = { |
| 1161 | .name = "compat" |
| 1162 | }; |
| 1163 | |
| 1164 | /** |
| 1165 | * pci_dev_driver - get the pci_driver of a device |
| 1166 | * @dev: the device to query |
| 1167 | * |
| 1168 | * Returns the appropriate pci_driver structure or %NULL if there is no |
| 1169 | * registered driver for the device. |
| 1170 | */ |
| 1171 | struct pci_driver * |
| 1172 | pci_dev_driver(const struct pci_dev *dev) |
| 1173 | { |
| 1174 | if (dev->driver) |
| 1175 | return dev->driver; |
| 1176 | else { |
| 1177 | int i; |
| 1178 | for(i=0; i<=PCI_ROM_RESOURCE; i++) |
| 1179 | if (dev->resource[i].flags & IORESOURCE_BUSY) |
| 1180 | return &pci_compat_driver; |
| 1181 | } |
| 1182 | return NULL; |
| 1183 | } |
| 1184 | |
| 1185 | /** |
| 1186 | * pci_bus_match - Tell if a PCI device structure has a matching PCI device id structure |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | * @dev: the PCI device structure to match against |
Randy Dunlap | 8f7020d | 2005-10-23 11:57:38 -0700 | [diff] [blame] | 1188 | * @drv: the device driver to search for matching PCI device id structures |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | * |
| 1190 | * Used by a driver to check whether a PCI device present in the |
Randy Dunlap | 8f7020d | 2005-10-23 11:57:38 -0700 | [diff] [blame] | 1191 | * system is in its list of supported devices. Returns the matching |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | * pci_device_id structure or %NULL if there is no match. |
| 1193 | */ |
Greg Kroah-Hartman | 7586585 | 2005-06-30 02:18:12 -0700 | [diff] [blame] | 1194 | static int pci_bus_match(struct device *dev, struct device_driver *drv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | { |
Greg Kroah-Hartman | 7586585 | 2005-06-30 02:18:12 -0700 | [diff] [blame] | 1196 | struct pci_dev *pci_dev = to_pci_dev(dev); |
| 1197 | struct pci_driver *pci_drv = to_pci_driver(drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | const struct pci_device_id *found_id; |
| 1199 | |
Greg Kroah-Hartman | 7586585 | 2005-06-30 02:18:12 -0700 | [diff] [blame] | 1200 | found_id = pci_match_device(pci_drv, pci_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | if (found_id) |
| 1202 | return 1; |
| 1203 | |
Greg Kroah-Hartman | 7586585 | 2005-06-30 02:18:12 -0700 | [diff] [blame] | 1204 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | } |
| 1206 | |
| 1207 | /** |
| 1208 | * pci_dev_get - increments the reference count of the pci device structure |
| 1209 | * @dev: the device being referenced |
| 1210 | * |
| 1211 | * Each live reference to a device should be refcounted. |
| 1212 | * |
| 1213 | * Drivers for PCI devices should normally record such references in |
| 1214 | * their probe() methods, when they bind to a device, and release |
| 1215 | * them by calling pci_dev_put(), in their disconnect() methods. |
| 1216 | * |
| 1217 | * A pointer to the device with the incremented reference counter is returned. |
| 1218 | */ |
| 1219 | struct pci_dev *pci_dev_get(struct pci_dev *dev) |
| 1220 | { |
| 1221 | if (dev) |
| 1222 | get_device(&dev->dev); |
| 1223 | return dev; |
| 1224 | } |
| 1225 | |
| 1226 | /** |
| 1227 | * pci_dev_put - release a use of the pci device structure |
| 1228 | * @dev: device that's been disconnected |
| 1229 | * |
| 1230 | * Must be called when a user of a device is finished with it. When the last |
| 1231 | * user of the device calls this function, the memory of the device is freed. |
| 1232 | */ |
| 1233 | void pci_dev_put(struct pci_dev *dev) |
| 1234 | { |
| 1235 | if (dev) |
| 1236 | put_device(&dev->dev); |
| 1237 | } |
| 1238 | |
| 1239 | #ifndef CONFIG_HOTPLUG |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 1240 | int pci_uevent(struct device *dev, struct kobj_uevent_env *env) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | { |
| 1242 | return -ENODEV; |
| 1243 | } |
| 1244 | #endif |
| 1245 | |
| 1246 | struct bus_type pci_bus_type = { |
| 1247 | .name = "pci", |
| 1248 | .match = pci_bus_match, |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 1249 | .uevent = pci_uevent, |
Russell King | b15d686 | 2006-01-05 14:30:22 +0000 | [diff] [blame] | 1250 | .probe = pci_device_probe, |
| 1251 | .remove = pci_device_remove, |
Linus Torvalds | cbd69db | 2006-06-24 14:50:29 -0700 | [diff] [blame] | 1252 | .shutdown = pci_device_shutdown, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1253 | .dev_attrs = pci_dev_attrs, |
Alex Chiang | 705b1aa | 2009-03-20 14:56:31 -0600 | [diff] [blame] | 1254 | .bus_attrs = pci_bus_attrs, |
Konstantin Khlebnikov | bfb09a8 | 2012-08-08 14:47:51 +0400 | [diff] [blame] | 1255 | .drv_attrs = pci_drv_attrs, |
Rafael J. Wysocki | bbb44d9 | 2008-05-20 00:49:04 +0200 | [diff] [blame] | 1256 | .pm = PCI_PM_OPS_PTR, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | }; |
| 1258 | |
| 1259 | static int __init pci_driver_init(void) |
| 1260 | { |
| 1261 | return bus_register(&pci_bus_type); |
| 1262 | } |
| 1263 | |
| 1264 | postcore_initcall(pci_driver_init); |
| 1265 | |
Tejun Heo | 9dba910 | 2009-09-03 15:26:36 +0900 | [diff] [blame] | 1266 | EXPORT_SYMBOL_GPL(pci_add_dynid); |
Greg Kroah-Hartman | 7586585 | 2005-06-30 02:18:12 -0700 | [diff] [blame] | 1267 | EXPORT_SYMBOL(pci_match_id); |
Laurent riffard | 863b18f | 2005-10-27 23:12:54 +0200 | [diff] [blame] | 1268 | EXPORT_SYMBOL(__pci_register_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | EXPORT_SYMBOL(pci_unregister_driver); |
| 1270 | EXPORT_SYMBOL(pci_dev_driver); |
| 1271 | EXPORT_SYMBOL(pci_bus_type); |
| 1272 | EXPORT_SYMBOL(pci_dev_get); |
| 1273 | EXPORT_SYMBOL(pci_dev_put); |