aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-12-13 15:14:47 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2012-12-13 15:14:47 -0500
commit193c0d682525987db59ac3a24531a77e4947aa95 (patch)
tree7b58346171c4d07e2c2ee6c3c469c325495149a4 /drivers/pci
parent8b0cab14951fbf8126795ab301835a8f8126a988 (diff)
parent1cb73f8c479e66541fefd3f7fa547b1fa56cdc54 (diff)
Merge tag 'for-3.8' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci
Pull PCI update from Bjorn Helgaas: "Host bridge hotplug: - Untangle _PRT from struct pci_bus (Bjorn Helgaas) - Request _OSC control before scanning root bus (Taku Izumi) - Assign resources when adding host bridge (Yinghai Lu) - Remove root bus when removing host bridge (Yinghai Lu) - Remove _PRT during hot remove (Yinghai Lu) SRIOV - Add sysfs knobs to control numVFs (Don Dutile) Power management - Notify devices when power resource turned on (Huang Ying) Bug fixes - Work around broken _SEG on HP xw9300 (Bjorn Helgaas) - Keep runtime PM enabled for unbound PCI devices (Huang Ying) - Fix Optimus dual-GPU runtime D3 suspend issue (Dave Airlie) - Fix xen frontend shutdown issue (David Vrabel) - Work around PLX PCI 9050 BAR alignment erratum (Ian Abbott) Miscellaneous - Add GPL license for drivers/pci/ioapic (Andrew Cooks) - Add standard PCI-X, PCIe ASPM register #defines (Bjorn Helgaas) - NumaChip remote PCI support (Daniel Blueman) - Fix PCIe Link Capabilities Supported Link Speed definition (Jingoo Han) - Convert dev_printk() to dev_info(), etc (Joe Perches) - Add support for non PCI BAR ROM data (Matthew Garrett) - Add x86 support for host bridge translation offset (Mike Yoknis) - Report success only when every driver supports AER (Vijay Pandarathil)" Fix up trivial conflicts. * tag 'for-3.8' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci: (48 commits) PCI: Use phys_addr_t for physical ROM address x86/PCI: Add NumaChip remote PCI support ath9k: Use standard #defines for PCIe Capability ASPM fields iwlwifi: Use standard #defines for PCIe Capability ASPM fields iwlwifi: collapse wrapper for pcie_capability_read_word() iwlegacy: Use standard #defines for PCIe Capability ASPM fields iwlegacy: collapse wrapper for pcie_capability_read_word() cxgb3: Use standard #defines for PCIe Capability ASPM fields PCI: Add standard PCIe Capability Link ASPM field names PCI/portdrv: Use PCI Express Capability accessors PCI: Use standard PCIe Capability Link register field names x86: Use PCI setup data PCI: Add support for non-BAR ROMs PCI: Add pcibios_add_device EFI: Stash ROMs if they're not in the PCI BAR PCI: Add and use standard PCI-X Capability register names PCI/PM: Keep runtime PM enabled for unbound PCI devices xen-pcifront: Handle backend CLOSED without CLOSING PCI: SRIOV control and status via sysfs (documentation) PCI/AER: Report success only when every device has AER-aware driver ...
Diffstat (limited to 'drivers/pci')
-rw-r--r--drivers/pci/bus.c5
-rw-r--r--drivers/pci/ioapic.c2
-rw-r--r--drivers/pci/iov.c87
-rw-r--r--drivers/pci/irq.c10
-rw-r--r--drivers/pci/pci-driver.c73
-rw-r--r--drivers/pci/pci-stub.c2
-rw-r--r--drivers/pci/pci-sysfs.c172
-rw-r--r--drivers/pci/pci.c48
-rw-r--r--drivers/pci/pci.h8
-rw-r--r--drivers/pci/pcie/aer/aerdrv.h5
-rw-r--r--drivers/pci/pcie/aer/aerdrv_core.c22
-rw-r--r--drivers/pci/pcie/aspm.c18
-rw-r--r--drivers/pci/pcie/portdrv_core.c3
-rw-r--r--drivers/pci/probe.c42
-rw-r--r--drivers/pci/quirks.c39
-rw-r--r--drivers/pci/remove.c36
-rw-r--r--drivers/pci/rom.c11
-rw-r--r--drivers/pci/setup-bus.c22
-rw-r--r--drivers/pci/xen-pcifront.c5
19 files changed, 479 insertions, 131 deletions
diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index a543746fb354..ad6a8b635692 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -170,6 +170,11 @@ int pci_bus_add_device(struct pci_dev *dev)
170 int retval; 170 int retval;
171 171
172 pci_fixup_device(pci_fixup_final, dev); 172 pci_fixup_device(pci_fixup_final, dev);
173
174 retval = pcibios_add_device(dev);
175 if (retval)
176 return retval;
177
173 retval = device_add(&dev->dev); 178 retval = device_add(&dev->dev);
174 if (retval) 179 if (retval)
175 return retval; 180 return retval;
diff --git a/drivers/pci/ioapic.c b/drivers/pci/ioapic.c
index 2eca902a4283..3c6bbdd059a4 100644
--- a/drivers/pci/ioapic.c
+++ b/drivers/pci/ioapic.c
@@ -125,3 +125,5 @@ static void __exit ioapic_exit(void)
125 125
126module_init(ioapic_init); 126module_init(ioapic_init);
127module_exit(ioapic_exit); 127module_exit(ioapic_exit);
128
129MODULE_LICENSE("GPL");
diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index aeccc911abb8..bafd2bbcaf65 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -106,7 +106,7 @@ static int virtfn_add(struct pci_dev *dev, int id, int reset)
106 virtfn->resource[i].name = pci_name(virtfn); 106 virtfn->resource[i].name = pci_name(virtfn);
107 virtfn->resource[i].flags = res->flags; 107 virtfn->resource[i].flags = res->flags;
108 size = resource_size(res); 108 size = resource_size(res);
109 do_div(size, iov->total); 109 do_div(size, iov->total_VFs);
110 virtfn->resource[i].start = res->start + size * id; 110 virtfn->resource[i].start = res->start + size * id;
111 virtfn->resource[i].end = virtfn->resource[i].start + size - 1; 111 virtfn->resource[i].end = virtfn->resource[i].start + size - 1;
112 rc = request_resource(res, &virtfn->resource[i]); 112 rc = request_resource(res, &virtfn->resource[i]);
@@ -194,7 +194,7 @@ static int sriov_migration(struct pci_dev *dev)
194 u16 status; 194 u16 status;
195 struct pci_sriov *iov = dev->sriov; 195 struct pci_sriov *iov = dev->sriov;
196 196
197 if (!iov->nr_virtfn) 197 if (!iov->num_VFs)
198 return 0; 198 return 0;
199 199
200 if (!(iov->cap & PCI_SRIOV_CAP_VFM)) 200 if (!(iov->cap & PCI_SRIOV_CAP_VFM))
@@ -216,7 +216,7 @@ static void sriov_migration_task(struct work_struct *work)
216 u16 status; 216 u16 status;
217 struct pci_sriov *iov = container_of(work, struct pci_sriov, mtask); 217 struct pci_sriov *iov = container_of(work, struct pci_sriov, mtask);
218 218
219 for (i = iov->initial; i < iov->nr_virtfn; i++) { 219 for (i = iov->initial_VFs; i < iov->num_VFs; i++) {
220 state = readb(iov->mstate + i); 220 state = readb(iov->mstate + i);
221 if (state == PCI_SRIOV_VFM_MI) { 221 if (state == PCI_SRIOV_VFM_MI) {
222 writeb(PCI_SRIOV_VFM_AV, iov->mstate + i); 222 writeb(PCI_SRIOV_VFM_AV, iov->mstate + i);
@@ -244,7 +244,7 @@ static int sriov_enable_migration(struct pci_dev *dev, int nr_virtfn)
244 resource_size_t pa; 244 resource_size_t pa;
245 struct pci_sriov *iov = dev->sriov; 245 struct pci_sriov *iov = dev->sriov;
246 246
247 if (nr_virtfn <= iov->initial) 247 if (nr_virtfn <= iov->initial_VFs)
248 return 0; 248 return 0;
249 249
250 pci_read_config_dword(dev, iov->pos + PCI_SRIOV_VFM, &table); 250 pci_read_config_dword(dev, iov->pos + PCI_SRIOV_VFM, &table);
@@ -294,15 +294,15 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
294 if (!nr_virtfn) 294 if (!nr_virtfn)
295 return 0; 295 return 0;
296 296
297 if (iov->nr_virtfn) 297 if (iov->num_VFs)
298 return -EINVAL; 298 return -EINVAL;
299 299
300 pci_read_config_word(dev, iov->pos + PCI_SRIOV_INITIAL_VF, &initial); 300 pci_read_config_word(dev, iov->pos + PCI_SRIOV_INITIAL_VF, &initial);
301 if (initial > iov->total || 301 if (initial > iov->total_VFs ||
302 (!(iov->cap & PCI_SRIOV_CAP_VFM) && (initial != iov->total))) 302 (!(iov->cap & PCI_SRIOV_CAP_VFM) && (initial != iov->total_VFs)))
303 return -EIO; 303 return -EIO;
304 304
305 if (nr_virtfn < 0 || nr_virtfn > iov->total || 305 if (nr_virtfn < 0 || nr_virtfn > iov->total_VFs ||
306 (!(iov->cap & PCI_SRIOV_CAP_VFM) && (nr_virtfn > initial))) 306 (!(iov->cap & PCI_SRIOV_CAP_VFM) && (nr_virtfn > initial)))
307 return -EINVAL; 307 return -EINVAL;
308 308
@@ -359,7 +359,7 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
359 msleep(100); 359 msleep(100);
360 pci_cfg_access_unlock(dev); 360 pci_cfg_access_unlock(dev);
361 361
362 iov->initial = initial; 362 iov->initial_VFs = initial;
363 if (nr_virtfn < initial) 363 if (nr_virtfn < initial)
364 initial = nr_virtfn; 364 initial = nr_virtfn;
365 365
@@ -376,7 +376,7 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
376 } 376 }
377 377
378 kobject_uevent(&dev->dev.kobj, KOBJ_CHANGE); 378 kobject_uevent(&dev->dev.kobj, KOBJ_CHANGE);
379 iov->nr_virtfn = nr_virtfn; 379 iov->num_VFs = nr_virtfn;
380 380
381 return 0; 381 return 0;
382 382
@@ -401,13 +401,13 @@ static void sriov_disable(struct pci_dev *dev)
401 int i; 401 int i;
402 struct pci_sriov *iov = dev->sriov; 402 struct pci_sriov *iov = dev->sriov;
403 403
404 if (!iov->nr_virtfn) 404 if (!iov->num_VFs)
405 return; 405 return;
406 406
407 if (iov->cap & PCI_SRIOV_CAP_VFM) 407 if (iov->cap & PCI_SRIOV_CAP_VFM)
408 sriov_disable_migration(dev); 408 sriov_disable_migration(dev);
409 409
410 for (i = 0; i < iov->nr_virtfn; i++) 410 for (i = 0; i < iov->num_VFs; i++)
411 virtfn_remove(dev, i, 0); 411 virtfn_remove(dev, i, 0);
412 412
413 iov->ctrl &= ~(PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE); 413 iov->ctrl &= ~(PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE);
@@ -419,7 +419,7 @@ static void sriov_disable(struct pci_dev *dev)
419 if (iov->link != dev->devfn) 419 if (iov->link != dev->devfn)
420 sysfs_remove_link(&dev->dev.kobj, "dep_link"); 420 sysfs_remove_link(&dev->dev.kobj, "dep_link");
421 421
422 iov->nr_virtfn = 0; 422 iov->num_VFs = 0;
423} 423}
424 424
425static int sriov_init(struct pci_dev *dev, int pos) 425static int sriov_init(struct pci_dev *dev, int pos)
@@ -496,7 +496,7 @@ found:
496 iov->pos = pos; 496 iov->pos = pos;
497 iov->nres = nres; 497 iov->nres = nres;
498 iov->ctrl = ctrl; 498 iov->ctrl = ctrl;
499 iov->total = total; 499 iov->total_VFs = total;
500 iov->offset = offset; 500 iov->offset = offset;
501 iov->stride = stride; 501 iov->stride = stride;
502 iov->pgsz = pgsz; 502 iov->pgsz = pgsz;
@@ -529,7 +529,7 @@ failed:
529 529
530static void sriov_release(struct pci_dev *dev) 530static void sriov_release(struct pci_dev *dev)
531{ 531{
532 BUG_ON(dev->sriov->nr_virtfn); 532 BUG_ON(dev->sriov->num_VFs);
533 533
534 if (dev != dev->sriov->dev) 534 if (dev != dev->sriov->dev)
535 pci_dev_put(dev->sriov->dev); 535 pci_dev_put(dev->sriov->dev);
@@ -554,7 +554,7 @@ static void sriov_restore_state(struct pci_dev *dev)
554 pci_update_resource(dev, i); 554 pci_update_resource(dev, i);
555 555
556 pci_write_config_dword(dev, iov->pos + PCI_SRIOV_SYS_PGSIZE, iov->pgsz); 556 pci_write_config_dword(dev, iov->pos + PCI_SRIOV_SYS_PGSIZE, iov->pgsz);
557 pci_write_config_word(dev, iov->pos + PCI_SRIOV_NUM_VF, iov->nr_virtfn); 557 pci_write_config_word(dev, iov->pos + PCI_SRIOV_NUM_VF, iov->num_VFs);
558 pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, iov->ctrl); 558 pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, iov->ctrl);
559 if (iov->ctrl & PCI_SRIOV_CTRL_VFE) 559 if (iov->ctrl & PCI_SRIOV_CTRL_VFE)
560 msleep(100); 560 msleep(100);
@@ -661,7 +661,7 @@ int pci_iov_bus_range(struct pci_bus *bus)
661 list_for_each_entry(dev, &bus->devices, bus_list) { 661 list_for_each_entry(dev, &bus->devices, bus_list) {
662 if (!dev->is_physfn) 662 if (!dev->is_physfn)
663 continue; 663 continue;
664 busnr = virtfn_bus(dev, dev->sriov->total - 1); 664 busnr = virtfn_bus(dev, dev->sriov->total_VFs - 1);
665 if (busnr > max) 665 if (busnr > max)
666 max = busnr; 666 max = busnr;
667 } 667 }
@@ -729,9 +729,56 @@ EXPORT_SYMBOL_GPL(pci_sriov_migration);
729 */ 729 */
730int pci_num_vf(struct pci_dev *dev) 730int pci_num_vf(struct pci_dev *dev)
731{ 731{
732 if (!dev || !dev->is_physfn) 732 if (!dev->is_physfn)
733 return 0; 733 return 0;
734 else 734
735 return dev->sriov->nr_virtfn; 735 return dev->sriov->num_VFs;
736} 736}
737EXPORT_SYMBOL_GPL(pci_num_vf); 737EXPORT_SYMBOL_GPL(pci_num_vf);
738
739/**
740 * pci_sriov_set_totalvfs -- reduce the TotalVFs available
741 * @dev: the PCI PF device
742 * numvfs: number that should be used for TotalVFs supported
743 *
744 * Should be called from PF driver's probe routine with
745 * device's mutex held.
746 *
747 * Returns 0 if PF is an SRIOV-capable device and
748 * value of numvfs valid. If not a PF with VFS, return -EINVAL;
749 * if VFs already enabled, return -EBUSY.
750 */
751int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs)
752{
753 if (!dev->is_physfn || (numvfs > dev->sriov->total_VFs))
754 return -EINVAL;
755
756 /* Shouldn't change if VFs already enabled */
757 if (dev->sriov->ctrl & PCI_SRIOV_CTRL_VFE)
758 return -EBUSY;
759 else
760 dev->sriov->driver_max_VFs = numvfs;
761
762 return 0;
763}
764EXPORT_SYMBOL_GPL(pci_sriov_set_totalvfs);
765
766/**
767 * pci_sriov_get_totalvfs -- get total VFs supported on this devic3
768 * @dev: the PCI PF device
769 *
770 * For a PCIe device with SRIOV support, return the PCIe
771 * SRIOV capability value of TotalVFs or the value of driver_max_VFs
772 * if the driver reduced it. Otherwise, -EINVAL.
773 */
774int pci_sriov_get_totalvfs(struct pci_dev *dev)
775{
776 if (!dev->is_physfn)
777 return -EINVAL;
778
779 if (dev->sriov->driver_max_VFs)
780 return dev->sriov->driver_max_VFs;
781
782 return dev->sriov->total_VFs;
783}
784EXPORT_SYMBOL_GPL(pci_sriov_get_totalvfs);
diff --git a/drivers/pci/irq.c b/drivers/pci/irq.c
index e5f69a43b1b1..b008cf86b9c3 100644
--- a/drivers/pci/irq.c
+++ b/drivers/pci/irq.c
@@ -14,11 +14,11 @@ static void pci_note_irq_problem(struct pci_dev *pdev, const char *reason)
14{ 14{
15 struct pci_dev *parent = to_pci_dev(pdev->dev.parent); 15 struct pci_dev *parent = to_pci_dev(pdev->dev.parent);
16 16
17 dev_printk(KERN_ERR, &pdev->dev, 17 dev_err(&pdev->dev,
18 "Potentially misrouted IRQ (Bridge %s %04x:%04x)\n", 18 "Potentially misrouted IRQ (Bridge %s %04x:%04x)\n",
19 dev_name(&parent->dev), parent->vendor, parent->device); 19 dev_name(&parent->dev), parent->vendor, parent->device);
20 dev_printk(KERN_ERR, &pdev->dev, "%s\n", reason); 20 dev_err(&pdev->dev, "%s\n", reason);
21 dev_printk(KERN_ERR, &pdev->dev, "Please report to linux-kernel@vger.kernel.org\n"); 21 dev_err(&pdev->dev, "Please report to linux-kernel@vger.kernel.org\n");
22 WARN_ON(1); 22 WARN_ON(1);
23} 23}
24 24
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 1dc78c5cabf8..f79cbcd3944b 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -248,31 +248,26 @@ struct drv_dev_and_id {
248static long local_pci_probe(void *_ddi) 248static long local_pci_probe(void *_ddi)
249{ 249{
250 struct drv_dev_and_id *ddi = _ddi; 250 struct drv_dev_and_id *ddi = _ddi;
251 struct device *dev = &ddi->dev->dev; 251 struct pci_dev *pci_dev = ddi->dev;
252 struct device *parent = dev->parent; 252 struct pci_driver *pci_drv = ddi->drv;
253 struct device *dev = &pci_dev->dev;
253 int rc; 254 int rc;
254 255
255 /* The parent bridge must be in active state when probing */ 256 /*
256 if (parent) 257 * Unbound PCI devices are always put in D0, regardless of
257 pm_runtime_get_sync(parent); 258 * runtime PM status. During probe, the device is set to
258 /* Unbound PCI devices are always set to disabled and suspended. 259 * active and the usage count is incremented. If the driver
259 * During probe, the device is set to enabled and active and the 260 * supports runtime PM, it should call pm_runtime_put_noidle()
260 * usage count is incremented. If the driver supports runtime PM, 261 * in its probe routine and pm_runtime_get_noresume() in its
261 * it should call pm_runtime_put_noidle() in its probe routine and 262 * remove routine.
262 * pm_runtime_get_noresume() in its remove routine.
263 */ 263 */
264 pm_runtime_get_noresume(dev); 264 pm_runtime_get_sync(dev);
265 pm_runtime_set_active(dev); 265 pci_dev->driver = pci_drv;
266 pm_runtime_enable(dev); 266 rc = pci_drv->probe(pci_dev, ddi->id);
267
268 rc = ddi->drv->probe(ddi->dev, ddi->id);
269 if (rc) { 267 if (rc) {
270 pm_runtime_disable(dev); 268 pci_dev->driver = NULL;
271 pm_runtime_set_suspended(dev); 269 pm_runtime_put_sync(dev);
272 pm_runtime_put_noidle(dev);
273 } 270 }
274 if (parent)
275 pm_runtime_put(parent);
276 return rc; 271 return rc;
277} 272}
278 273
@@ -322,10 +317,8 @@ __pci_device_probe(struct pci_driver *drv, struct pci_dev *pci_dev)
322 id = pci_match_device(drv, pci_dev); 317 id = pci_match_device(drv, pci_dev);
323 if (id) 318 if (id)
324 error = pci_call_probe(drv, pci_dev, id); 319 error = pci_call_probe(drv, pci_dev, id);
325 if (error >= 0) { 320 if (error >= 0)
326 pci_dev->driver = drv;
327 error = 0; 321 error = 0;
328 }
329 } 322 }
330 return error; 323 return error;
331} 324}
@@ -361,9 +354,7 @@ static int pci_device_remove(struct device * dev)
361 } 354 }
362 355
363 /* Undo the runtime PM settings in local_pci_probe() */ 356 /* Undo the runtime PM settings in local_pci_probe() */
364 pm_runtime_disable(dev); 357 pm_runtime_put_sync(dev);
365 pm_runtime_set_suspended(dev);
366 pm_runtime_put_noidle(dev);
367 358
368 /* 359 /*
369 * If the device is still on, set the power state as "unknown", 360 * If the device is still on, set the power state as "unknown",
@@ -986,6 +977,13 @@ static int pci_pm_runtime_suspend(struct device *dev)
986 pci_power_t prev = pci_dev->current_state; 977 pci_power_t prev = pci_dev->current_state;
987 int error; 978 int error;
988 979
980 /*
981 * If pci_dev->driver is not set (unbound), the device should
982 * always remain in D0 regardless of the runtime PM status
983 */
984 if (!pci_dev->driver)
985 return 0;
986
989 if (!pm || !pm->runtime_suspend) 987 if (!pm || !pm->runtime_suspend)
990 return -ENOSYS; 988 return -ENOSYS;
991 989
@@ -1007,10 +1005,10 @@ static int pci_pm_runtime_suspend(struct device *dev)
1007 return 0; 1005 return 0;
1008 } 1006 }
1009 1007
1010 if (!pci_dev->state_saved) 1008 if (!pci_dev->state_saved) {
1011 pci_save_state(pci_dev); 1009 pci_save_state(pci_dev);
1012 1010 pci_finish_runtime_suspend(pci_dev);
1013 pci_finish_runtime_suspend(pci_dev); 1011 }
1014 1012
1015 return 0; 1013 return 0;
1016} 1014}
@@ -1021,6 +1019,13 @@ static int pci_pm_runtime_resume(struct device *dev)
1021 struct pci_dev *pci_dev = to_pci_dev(dev); 1019 struct pci_dev *pci_dev = to_pci_dev(dev);
1022 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; 1020 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
1023 1021
1022 /*
1023 * If pci_dev->driver is not set (unbound), the device should
1024 * always remain in D0 regardless of the runtime PM status
1025 */
1026 if (!pci_dev->driver)
1027 return 0;
1028
1024 if (!pm || !pm->runtime_resume) 1029 if (!pm || !pm->runtime_resume)
1025 return -ENOSYS; 1030 return -ENOSYS;
1026 1031
@@ -1038,8 +1043,16 @@ static int pci_pm_runtime_resume(struct device *dev)
1038 1043
1039static int pci_pm_runtime_idle(struct device *dev) 1044static int pci_pm_runtime_idle(struct device *dev)
1040{ 1045{
1046 struct pci_dev *pci_dev = to_pci_dev(dev);
1041 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; 1047 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
1042 1048
1049 /*
1050 * If pci_dev->driver is not set (unbound), the device should
1051 * always remain in D0 regardless of the runtime PM status
1052 */
1053 if (!pci_dev->driver)
1054 goto out;
1055
1043 if (!pm) 1056 if (!pm)
1044 return -ENOSYS; 1057 return -ENOSYS;
1045 1058
@@ -1049,8 +1062,8 @@ static int pci_pm_runtime_idle(struct device *dev)
1049 return ret; 1062 return ret;
1050 } 1063 }
1051 1064
1065out:
1052 pm_runtime_suspend(dev); 1066 pm_runtime_suspend(dev);
1053
1054 return 0; 1067 return 0;
1055} 1068}
1056 1069
diff --git a/drivers/pci/pci-stub.c b/drivers/pci/pci-stub.c
index 775e933c2225..6e47c519c510 100644
--- a/drivers/pci/pci-stub.c
+++ b/drivers/pci/pci-stub.c
@@ -28,7 +28,7 @@ MODULE_PARM_DESC(ids, "Initial PCI IDs to add to the stub driver, format is "
28 28
29static int pci_stub_probe(struct pci_dev *dev, const struct pci_device_id *id) 29static int pci_stub_probe(struct pci_dev *dev, const struct pci_device_id *id)
30{ 30{
31 dev_printk(KERN_INFO, &dev->dev, "claimed by stub\n"); 31 dev_info(&dev->dev, "claimed by stub\n");
32 return 0; 32 return 0;
33} 33}
34 34
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 68d56f02e721..05b78b16d20b 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -401,6 +401,106 @@ static ssize_t d3cold_allowed_show(struct device *dev,
401} 401}
402#endif 402#endif
403 403
404#ifdef CONFIG_PCI_IOV
405static ssize_t sriov_totalvfs_show(struct device *dev,
406 struct device_attribute *attr,
407 char *buf)
408{
409 struct pci_dev *pdev = to_pci_dev(dev);
410
411 return sprintf(buf, "%u\n", pci_sriov_get_totalvfs(pdev));
412}
413
414
415static ssize_t sriov_numvfs_show(struct device *dev,
416 struct device_attribute *attr,
417 char *buf)
418{
419 struct pci_dev *pdev = to_pci_dev(dev);
420
421 return sprintf(buf, "%u\n", pdev->sriov->num_VFs);
422}
423
424/*
425 * num_vfs > 0; number of vfs to enable
426 * num_vfs = 0; disable all vfs
427 *
428 * Note: SRIOV spec doesn't allow partial VF
429 * disable, so its all or none.
430 */
431static ssize_t sriov_numvfs_store(struct device *dev,
432 struct device_attribute *attr,
433 const char *buf, size_t count)
434{
435 struct pci_dev *pdev = to_pci_dev(dev);
436 int num_vfs_enabled = 0;
437 int num_vfs;
438 int ret = 0;
439 u16 total;
440
441 if (kstrtoint(buf, 0, &num_vfs) < 0)
442 return -EINVAL;
443
444 /* is PF driver loaded w/callback */
445 if (!pdev->driver || !pdev->driver->sriov_configure) {
446 dev_info(&pdev->dev,
447 "Driver doesn't support SRIOV configuration via sysfs\n");
448 return -ENOSYS;
449 }
450
451 /* if enabling vf's ... */
452 total = pci_sriov_get_totalvfs(pdev);
453 /* Requested VFs to enable < totalvfs and none enabled already */
454 if ((num_vfs > 0) && (num_vfs <= total)) {
455 if (pdev->sriov->num_VFs == 0) {
456 num_vfs_enabled =
457 pdev->driver->sriov_configure(pdev, num_vfs);
458 if ((num_vfs_enabled >= 0) &&
459 (num_vfs_enabled != num_vfs)) {
460 dev_warn(&pdev->dev,
461 "Only %d VFs enabled\n",
462 num_vfs_enabled);
463 return count;
464 } else if (num_vfs_enabled < 0)
465 /* error code from driver callback */
466 return num_vfs_enabled;
467 } else if (num_vfs == pdev->sriov->num_VFs) {
468 dev_warn(&pdev->dev,
469 "%d VFs already enabled; no enable action taken\n",
470 num_vfs);
471 return count;
472 } else {
473 dev_warn(&pdev->dev,
474 "%d VFs already enabled. Disable before enabling %d VFs\n",
475 pdev->sriov->num_VFs, num_vfs);
476 return -EINVAL;
477 }
478 }
479
480 /* disable vfs */
481 if (num_vfs == 0) {
482 if (pdev->sriov->num_VFs != 0) {
483 ret = pdev->driver->sriov_configure(pdev, 0);
484 return ret ? ret : count;
485 } else {
486 dev_warn(&pdev->dev,
487 "All VFs disabled; no disable action taken\n");
488 return count;
489 }
490 }
491
492 dev_err(&pdev->dev,
493 "Invalid value for number of VFs to enable: %d\n", num_vfs);
494
495 return -EINVAL;
496}
497
498static struct device_attribute sriov_totalvfs_attr = __ATTR_RO(sriov_totalvfs);
499static struct device_attribute sriov_numvfs_attr =
500 __ATTR(sriov_numvfs, (S_IRUGO|S_IWUSR|S_IWGRP),
501 sriov_numvfs_show, sriov_numvfs_store);
502#endif /* CONFIG_PCI_IOV */
503
404struct device_attribute pci_dev_attrs[] = { 504struct device_attribute pci_dev_attrs[] = {
405 __ATTR_RO(resource), 505 __ATTR_RO(resource),
406 __ATTR_RO(vendor), 506 __ATTR_RO(vendor),
@@ -1262,29 +1362,20 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
1262 pdev->rom_attr = attr; 1362 pdev->rom_attr = attr;
1263 } 1363 }
1264 1364
1265 if ((pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA) {
1266 retval = device_create_file(&pdev->dev, &vga_attr);
1267 if (retval)
1268 goto err_rom_file;
1269 }
1270
1271 /* add platform-specific attributes */ 1365 /* add platform-specific attributes */
1272 retval = pcibios_add_platform_entries(pdev); 1366 retval = pcibios_add_platform_entries(pdev);
1273 if (retval) 1367 if (retval)
1274 goto err_vga_file; 1368 goto err_rom_file;
1275 1369
1276 /* add sysfs entries for various capabilities */ 1370 /* add sysfs entries for various capabilities */
1277 retval = pci_create_capabilities_sysfs(pdev); 1371 retval = pci_create_capabilities_sysfs(pdev);
1278 if (retval) 1372 if (retval)
1279 goto err_vga_file; 1373 goto err_rom_file;
1280 1374
1281 pci_create_firmware_label_files(pdev); 1375 pci_create_firmware_label_files(pdev);
1282 1376
1283 return 0; 1377 return 0;
1284 1378
1285err_vga_file:
1286 if ((pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA)
1287 device_remove_file(&pdev->dev, &vga_attr);
1288err_rom_file: 1379err_rom_file:
1289 if (rom_size) { 1380 if (rom_size) {
1290 sysfs_remove_bin_file(&pdev->dev.kobj, pdev->rom_attr); 1381 sysfs_remove_bin_file(&pdev->dev.kobj, pdev->rom_attr);
@@ -1370,3 +1461,62 @@ static int __init pci_sysfs_init(void)
1370} 1461}
1371 1462
1372late_initcall(pci_sysfs_init); 1463late_initcall(pci_sysfs_init);
1464
1465static struct attribute *pci_dev_dev_attrs[] = {
1466 &vga_attr.attr,
1467 NULL,
1468};
1469
1470static umode_t pci_dev_attrs_are_visible(struct kobject *kobj,
1471 struct attribute *a, int n)
1472{
1473 struct device *dev = container_of(kobj, struct device, kobj);
1474 struct pci_dev *pdev = to_pci_dev(dev);
1475
1476 if (a == &vga_attr.attr)
1477 if ((pdev->class >> 8) != PCI_CLASS_DISPLAY_VGA)
1478 return 0;
1479
1480 return a->mode;
1481}
1482
1483#ifdef CONFIG_PCI_IOV
1484static struct attribute *sriov_dev_attrs[] = {
1485 &sriov_totalvfs_attr.attr,
1486 &sriov_numvfs_attr.attr,
1487 NULL,
1488};
1489
1490static umode_t sriov_attrs_are_visible(struct kobject *kobj,
1491 struct attribute *a, int n)
1492{
1493 struct device *dev = container_of(kobj, struct device, kobj);
1494
1495 if (!dev_is_pf(dev))
1496 return 0;
1497
1498 return a->mode;
1499}
1500
1501static struct attribute_group sriov_dev_attr_group = {
1502 .attrs = sriov_dev_attrs,
1503 .is_visible = sriov_attrs_are_visible,
1504};
1505#endif /* CONFIG_PCI_IOV */
1506
1507static struct attribute_group pci_dev_attr_group = {
1508 .attrs = pci_dev_dev_attrs,
1509 .is_visible = pci_dev_attrs_are_visible,
1510};
1511
1512static const struct attribute_group *pci_dev_attr_groups[] = {
1513 &pci_dev_attr_group,
1514#ifdef CONFIG_PCI_IOV
1515 &sriov_dev_attr_group,
1516#endif
1517 NULL,
1518};
1519
1520struct device_type pci_dev_type = {
1521 .groups = pci_dev_attr_groups,
1522};
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index bdf66b500f22..5cb5820fae40 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1333,6 +1333,19 @@ void pcim_pin_device(struct pci_dev *pdev)
1333 dr->pinned = 1; 1333 dr->pinned = 1;
1334} 1334}
1335 1335
1336/*
1337 * pcibios_add_device - provide arch specific hooks when adding device dev
1338 * @dev: the PCI device being added
1339 *
1340 * Permits the platform to provide architecture specific functionality when
1341 * devices are added. This is the default implementation. Architecture
1342 * implementations can override this.
1343 */
1344int __weak pcibios_add_device (struct pci_dev *dev)
1345{
1346 return 0;
1347}
1348
1336/** 1349/**
1337 * pcibios_disable_device - disable arch specific PCI resources for device dev 1350 * pcibios_disable_device - disable arch specific PCI resources for device dev
1338 * @dev: the PCI device to disable 1351 * @dev: the PCI device to disable
@@ -1578,15 +1591,25 @@ void pci_pme_active(struct pci_dev *dev, bool enable)
1578 1591
1579 pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, pmcsr); 1592 pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, pmcsr);
1580 1593
1581 /* PCI (as opposed to PCIe) PME requires that the device have 1594 /*
1582 its PME# line hooked up correctly. Not all hardware vendors 1595 * PCI (as opposed to PCIe) PME requires that the device have
1583 do this, so the PME never gets delivered and the device 1596 * its PME# line hooked up correctly. Not all hardware vendors
1584 remains asleep. The easiest way around this is to 1597 * do this, so the PME never gets delivered and the device
1585 periodically walk the list of suspended devices and check 1598 * remains asleep. The easiest way around this is to
1586 whether any have their PME flag set. The assumption is that 1599 * periodically walk the list of suspended devices and check
1587 we'll wake up often enough anyway that this won't be a huge 1600 * whether any have their PME flag set. The assumption is that
1588 hit, and the power savings from the devices will still be a 1601 * we'll wake up often enough anyway that this won't be a huge
1589 win. */ 1602 * hit, and the power savings from the devices will still be a
1603 * win.
1604 *
1605 * Although PCIe uses in-band PME message instead of PME# line
1606 * to report PME, PME does not work for some PCIe devices in
1607 * reality. For example, there are devices that set their PME
1608 * status bits, but don't really bother to send a PME message;
1609 * there are PCI Express Root Ports that don't bother to
1610 * trigger interrupts when they receive PME messages from the
1611 * devices below. So PME poll is used for PCIe devices too.
1612 */
1590 1613
1591 if (dev->pme_poll) { 1614 if (dev->pme_poll) {
1592 struct pci_pme_device *pme_dev; 1615 struct pci_pme_device *pme_dev;
@@ -1900,6 +1923,8 @@ void pci_pm_init(struct pci_dev *dev)
1900 u16 pmc; 1923 u16 pmc;
1901 1924
1902 pm_runtime_forbid(&dev->dev); 1925 pm_runtime_forbid(&dev->dev);
1926 pm_runtime_set_active(&dev->dev);
1927 pm_runtime_enable(&dev->dev);
1903 device_enable_async_suspend(&dev->dev); 1928 device_enable_async_suspend(&dev->dev);
1904 dev->wakeup_prepared = false; 1929 dev->wakeup_prepared = false;
1905 1930
@@ -3865,14 +3890,13 @@ static void pci_no_domains(void)
3865} 3890}
3866 3891
3867/** 3892/**
3868 * pci_ext_cfg_enabled - can we access extended PCI config space? 3893 * pci_ext_cfg_avail - can we access extended PCI config space?
3869 * @dev: The PCI device of the root bridge.
3870 * 3894 *
3871 * Returns 1 if we can access PCI extended config space (offsets 3895 * Returns 1 if we can access PCI extended config space (offsets
3872 * greater than 0xff). This is the default implementation. Architecture 3896 * greater than 0xff). This is the default implementation. Architecture
3873 * implementations can override this. 3897 * implementations can override this.
3874 */ 3898 */
3875int __weak pci_ext_cfg_avail(struct pci_dev *dev) 3899int __weak pci_ext_cfg_avail(void)
3876{ 3900{
3877 return 1; 3901 return 1;
3878} 3902}
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index e253881c4275..e8518292826f 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -158,6 +158,7 @@ static inline int pci_no_d1d2(struct pci_dev *dev)
158} 158}
159extern struct device_attribute pci_dev_attrs[]; 159extern struct device_attribute pci_dev_attrs[];
160extern struct device_attribute pcibus_dev_attrs[]; 160extern struct device_attribute pcibus_dev_attrs[];
161extern struct device_type pci_dev_type;
161extern struct bus_attribute pci_bus_attrs[]; 162extern struct bus_attribute pci_bus_attrs[];
162 163
163 164
@@ -229,13 +230,14 @@ struct pci_sriov {
229 int nres; /* number of resources */ 230 int nres; /* number of resources */
230 u32 cap; /* SR-IOV Capabilities */ 231 u32 cap; /* SR-IOV Capabilities */
231 u16 ctrl; /* SR-IOV Control */ 232 u16 ctrl; /* SR-IOV Control */
232 u16 total; /* total VFs associated with the PF */ 233 u16 total_VFs; /* total VFs associated with the PF */
233 u16 initial; /* initial VFs associated with the PF */ 234 u16 initial_VFs; /* initial VFs associated with the PF */
234 u16 nr_virtfn; /* number of VFs available */ 235 u16 num_VFs; /* number of VFs available */
235 u16 offset; /* first VF Routing ID offset */ 236 u16 offset; /* first VF Routing ID offset */
236 u16 stride; /* following VF stride */ 237 u16 stride; /* following VF stride */
237 u32 pgsz; /* page size for BAR alignment */ 238 u32 pgsz; /* page size for BAR alignment */
238 u8 link; /* Function Dependency Link */ 239 u8 link; /* Function Dependency Link */
240 u16 driver_max_VFs; /* max num VFs driver supports */
239 struct pci_dev *dev; /* lowest numbered PF */ 241 struct pci_dev *dev; /* lowest numbered PF */
240 struct pci_dev *self; /* this PF */ 242 struct pci_dev *self; /* this PF */
241 struct mutex lock; /* lock for VF bus */ 243 struct mutex lock; /* lock for VF bus */
diff --git a/drivers/pci/pcie/aer/aerdrv.h b/drivers/pci/pcie/aer/aerdrv.h
index 94a7598eb262..22f840f4dda1 100644
--- a/drivers/pci/pcie/aer/aerdrv.h
+++ b/drivers/pci/pcie/aer/aerdrv.h
@@ -87,6 +87,9 @@ struct aer_broadcast_data {
87static inline pci_ers_result_t merge_result(enum pci_ers_result orig, 87static inline pci_ers_result_t merge_result(enum pci_ers_result orig,
88 enum pci_ers_result new) 88 enum pci_ers_result new)
89{ 89{
90 if (new == PCI_ERS_RESULT_NO_AER_DRIVER)
91 return PCI_ERS_RESULT_NO_AER_DRIVER;
92
90 if (new == PCI_ERS_RESULT_NONE) 93 if (new == PCI_ERS_RESULT_NONE)
91 return orig; 94 return orig;
92 95
@@ -97,7 +100,7 @@ static inline pci_ers_result_t merge_result(enum pci_ers_result orig,
97 break; 100 break;
98 case PCI_ERS_RESULT_DISCONNECT: 101 case PCI_ERS_RESULT_DISCONNECT:
99 if (new == PCI_ERS_RESULT_NEED_RESET) 102 if (new == PCI_ERS_RESULT_NEED_RESET)
100 orig = new; 103 orig = PCI_ERS_RESULT_NEED_RESET;
101 break; 104 break;
102 default: 105 default:
103 break; 106 break;
diff --git a/drivers/pci/pcie/aer/aerdrv_core.c b/drivers/pci/pcie/aer/aerdrv_core.c
index af4e31cd3a3b..421bbc5fee32 100644
--- a/drivers/pci/pcie/aer/aerdrv_core.c
+++ b/drivers/pci/pcie/aer/aerdrv_core.c
@@ -232,13 +232,27 @@ static int report_error_detected(struct pci_dev *dev, void *data)
232 dev->driver ? 232 dev->driver ?
233 "no AER-aware driver" : "no driver"); 233 "no AER-aware driver" : "no driver");
234 } 234 }
235 goto out; 235
236 /*
237 * If there's any device in the subtree that does not
238 * have an error_detected callback, returning
239 * PCI_ERS_RESULT_NO_AER_DRIVER prevents calling of
240 * the subsequent mmio_enabled/slot_reset/resume
241 * callbacks of "any" device in the subtree. All the
242 * devices in the subtree are left in the error state
243 * without recovery.
244 */
245
246 if (!(dev->hdr_type & PCI_HEADER_TYPE_BRIDGE))
247 vote = PCI_ERS_RESULT_NO_AER_DRIVER;
248 else
249 vote = PCI_ERS_RESULT_NONE;
250 } else {
251 err_handler = dev->driver->err_handler;
252 vote = err_handler->error_detected(dev, result_data->state);
236 } 253 }
237 254
238 err_handler = dev->driver->err_handler;
239 vote = err_handler->error_detected(dev, result_data->state);
240 result_data->result = merge_result(result_data->result, vote); 255 result_data->result = merge_result(result_data->result, vote);
241out:
242 device_unlock(&dev->dev); 256 device_unlock(&dev->dev);
243 return 0; 257 return 0;
244} 258}
diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index 213753b283a6..b52630b8eada 100644
--- a/drivers/pci/pcie/aspm.c
+++ b/drivers/pci/pcie/aspm.c
@@ -242,8 +242,7 @@ static void pcie_aspm_configure_common_clock(struct pcie_link_state *link)
242 return; 242 return;
243 243
244 /* Training failed. Restore common clock configurations */ 244 /* Training failed. Restore common clock configurations */
245 dev_printk(KERN_ERR, &parent->dev, 245 dev_err(&parent->dev, "ASPM: Could not configure common clock\n");
246 "ASPM: Could not configure common clock\n");
247 list_for_each_entry(child, &linkbus->devices, bus_list) 246 list_for_each_entry(child, &linkbus->devices, bus_list)
248 pcie_capability_write_word(child, PCI_EXP_LNKCTL, 247 pcie_capability_write_word(child, PCI_EXP_LNKCTL,
249 child_reg[PCI_FUNC(child->devfn)]); 248 child_reg[PCI_FUNC(child->devfn)]);
@@ -427,7 +426,8 @@ static void pcie_aspm_cap_init(struct pcie_link_state *link, int blacklist)
427 426
428static void pcie_config_aspm_dev(struct pci_dev *pdev, u32 val) 427static void pcie_config_aspm_dev(struct pci_dev *pdev, u32 val)
429{ 428{
430 pcie_capability_clear_and_set_word(pdev, PCI_EXP_LNKCTL, 0x3, val); 429 pcie_capability_clear_and_set_word(pdev, PCI_EXP_LNKCTL,
430 PCI_EXP_LNKCTL_ASPMC, val);
431} 431}
432 432
433static void pcie_config_aspm_link(struct pcie_link_state *link, u32 state) 433static void pcie_config_aspm_link(struct pcie_link_state *link, u32 state)
@@ -442,12 +442,12 @@ static void pcie_config_aspm_link(struct pcie_link_state *link, u32 state)
442 return; 442 return;
443 /* Convert ASPM state to upstream/downstream ASPM register state */ 443 /* Convert ASPM state to upstream/downstream ASPM register state */
444 if (state & ASPM_STATE_L0S_UP) 444 if (state & ASPM_STATE_L0S_UP)
445 dwstream |= PCIE_LINK_STATE_L0S; 445 dwstream |= PCI_EXP_LNKCTL_ASPM_L0S;
446 if (state & ASPM_STATE_L0S_DW) 446 if (state & ASPM_STATE_L0S_DW)
447 upstream |= PCIE_LINK_STATE_L0S; 447 upstream |= PCI_EXP_LNKCTL_ASPM_L0S;
448 if (state & ASPM_STATE_L1) { 448 if (state & ASPM_STATE_L1) {
449 upstream |= PCIE_LINK_STATE_L1; 449 upstream |= PCI_EXP_LNKCTL_ASPM_L1;
450 dwstream |= PCIE_LINK_STATE_L1; 450 dwstream |= PCI_EXP_LNKCTL_ASPM_L1;
451 } 451 }
452 /* 452 /*
453 * Spec 2.0 suggests all functions should be configured the 453 * Spec 2.0 suggests all functions should be configured the
@@ -507,9 +507,7 @@ static int pcie_aspm_sanity_check(struct pci_dev *pdev)
507 */ 507 */
508 pcie_capability_read_dword(child, PCI_EXP_DEVCAP, &reg32); 508 pcie_capability_read_dword(child, PCI_EXP_DEVCAP, &reg32);
509 if (!(reg32 & PCI_EXP_DEVCAP_RBER) && !aspm_force) { 509 if (!(reg32 & PCI_EXP_DEVCAP_RBER) && !aspm_force) {
510 dev_printk(KERN_INFO, &child->dev, "disabling ASPM" 510 dev_info(&child->dev, "disabling ASPM on pre-1.1 PCIe device. You can enable it with 'pcie_aspm=force'\n");
511 " on pre-1.1 PCIe device. You can enable it"
512 " with 'pcie_aspm=force'\n");
513 return -EINVAL; 511 return -EINVAL;
514 } 512 }
515 } 513 }
diff --git a/drivers/pci/pcie/portdrv_core.c b/drivers/pci/pcie/portdrv_core.c
index ed129b414624..b42133afca98 100644
--- a/drivers/pci/pcie/portdrv_core.c
+++ b/drivers/pci/pcie/portdrv_core.c
@@ -120,8 +120,7 @@ static int pcie_port_enable_msix(struct pci_dev *dev, int *vectors, int mask)
120 * the value in this field indicates which MSI-X Table entry is 120 * the value in this field indicates which MSI-X Table entry is
121 * used to generate the interrupt message." 121 * used to generate the interrupt message."
122 */ 122 */
123 pos = pci_pcie_cap(dev); 123 pcie_capability_read_word(dev, PCI_EXP_FLAGS, &reg16);
124 pci_read_config_word(dev, pos + PCI_EXP_FLAGS, &reg16);
125 entry = (reg16 & PCI_EXP_FLAGS_IRQ) >> 9; 124 entry = (reg16 & PCI_EXP_FLAGS_IRQ) >> 9;
126 if (entry >= nr_entries) 125 if (entry >= nr_entries)
127 goto Error; 126 goto Error;
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 3683f6094e3f..6186f03d84f3 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -521,7 +521,7 @@ static unsigned char pcie_link_speed[] = {
521 521
522void pcie_update_link_speed(struct pci_bus *bus, u16 linksta) 522void pcie_update_link_speed(struct pci_bus *bus, u16 linksta)
523{ 523{
524 bus->cur_bus_speed = pcie_link_speed[linksta & 0xf]; 524 bus->cur_bus_speed = pcie_link_speed[linksta & PCI_EXP_LNKSTA_CLS];
525} 525}
526EXPORT_SYMBOL_GPL(pcie_update_link_speed); 526EXPORT_SYMBOL_GPL(pcie_update_link_speed);
527 527
@@ -579,14 +579,16 @@ static void pci_set_bus_speed(struct pci_bus *bus)
579 if (pos) { 579 if (pos) {
580 u16 status; 580 u16 status;
581 enum pci_bus_speed max; 581 enum pci_bus_speed max;
582 pci_read_config_word(bridge, pos + 2, &status);
583 582
584 if (status & 0x8000) { 583 pci_read_config_word(bridge, pos + PCI_X_BRIDGE_SSTATUS,
584 &status);
585
586 if (status & PCI_X_SSTATUS_533MHZ) {
585 max = PCI_SPEED_133MHz_PCIX_533; 587 max = PCI_SPEED_133MHz_PCIX_533;
586 } else if (status & 0x4000) { 588 } else if (status & PCI_X_SSTATUS_266MHZ) {
587 max = PCI_SPEED_133MHz_PCIX_266; 589 max = PCI_SPEED_133MHz_PCIX_266;
588 } else if (status & 0x0002) { 590 } else if (status & PCI_X_SSTATUS_133MHZ) {
589 if (((status >> 12) & 0x3) == 2) { 591 if ((status & PCI_X_SSTATUS_VERS) == PCI_X_SSTATUS_V2) {
590 max = PCI_SPEED_133MHz_PCIX_ECC; 592 max = PCI_SPEED_133MHz_PCIX_ECC;
591 } else { 593 } else {
592 max = PCI_SPEED_133MHz_PCIX; 594 max = PCI_SPEED_133MHz_PCIX;
@@ -596,7 +598,8 @@ static void pci_set_bus_speed(struct pci_bus *bus)
596 } 598 }
597 599
598 bus->max_bus_speed = max; 600 bus->max_bus_speed = max;
599 bus->cur_bus_speed = pcix_bus_speed[(status >> 6) & 0xf]; 601 bus->cur_bus_speed = pcix_bus_speed[
602 (status & PCI_X_SSTATUS_FREQ) >> 6];
600 603
601 return; 604 return;
602 } 605 }
@@ -607,7 +610,7 @@ static void pci_set_bus_speed(struct pci_bus *bus)
607 u16 linksta; 610 u16 linksta;
608 611
609 pcie_capability_read_dword(bridge, PCI_EXP_LNKCAP, &linkcap); 612 pcie_capability_read_dword(bridge, PCI_EXP_LNKCAP, &linkcap);
610 bus->max_bus_speed = pcie_link_speed[linkcap & 0xf]; 613 bus->max_bus_speed = pcie_link_speed[linkcap & PCI_EXP_LNKCAP_SLS];
611 614
612 pcie_capability_read_word(bridge, PCI_EXP_LNKSTA, &linksta); 615 pcie_capability_read_word(bridge, PCI_EXP_LNKSTA, &linksta);
613 pcie_update_link_speed(bus, linksta); 616 pcie_update_link_speed(bus, linksta);
@@ -975,6 +978,7 @@ int pci_setup_device(struct pci_dev *dev)
975 dev->sysdata = dev->bus->sysdata; 978 dev->sysdata = dev->bus->sysdata;
976 dev->dev.parent = dev->bus->bridge; 979 dev->dev.parent = dev->bus->bridge;
977 dev->dev.bus = &pci_bus_type; 980 dev->dev.bus = &pci_bus_type;
981 dev->dev.type = &pci_dev_type;
978 dev->hdr_type = hdr_type & 0x7f; 982 dev->hdr_type = hdr_type & 0x7f;
979 dev->multifunction = !!(hdr_type & 0x80); 983 dev->multifunction = !!(hdr_type & 0x80);
980 dev->error_state = pci_channel_io_normal; 984 dev->error_state = pci_channel_io_normal;
@@ -1889,6 +1893,28 @@ unsigned int __ref pci_rescan_bus_bridge_resize(struct pci_dev *bridge)
1889 return max; 1893 return max;
1890} 1894}
1891 1895
1896/**
1897 * pci_rescan_bus - scan a PCI bus for devices.
1898 * @bus: PCI bus to scan
1899 *
1900 * Scan a PCI bus and child buses for new devices, adds them,
1901 * and enables them.
1902 *
1903 * Returns the max number of subordinate bus discovered.
1904 */
1905unsigned int __ref pci_rescan_bus(struct pci_bus *bus)
1906{
1907 unsigned int max;
1908
1909 max = pci_scan_child_bus(bus);
1910 pci_assign_unassigned_bus_resources(bus);
1911 pci_enable_bridges(bus);
1912 pci_bus_add_devices(bus);
1913
1914 return max;
1915}
1916EXPORT_SYMBOL_GPL(pci_rescan_bus);
1917
1892EXPORT_SYMBOL(pci_add_new_bus); 1918EXPORT_SYMBOL(pci_add_new_bus);
1893EXPORT_SYMBOL(pci_scan_slot); 1919EXPORT_SYMBOL(pci_scan_slot);
1894EXPORT_SYMBOL(pci_scan_bridge); 1920EXPORT_SYMBOL(pci_scan_bridge);
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 22ad3ee0cf0b..8f7a6344e79e 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -1790,6 +1790,45 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_TOSHIBA_2,
1790 PCI_DEVICE_ID_TOSHIBA_TC86C001_IDE, 1790 PCI_DEVICE_ID_TOSHIBA_TC86C001_IDE,
1791 quirk_tc86c001_ide); 1791 quirk_tc86c001_ide);
1792 1792
1793/*
1794 * PLX PCI 9050 PCI Target bridge controller has an errata that prevents the
1795 * local configuration registers accessible via BAR0 (memory) or BAR1 (i/o)
1796 * being read correctly if bit 7 of the base address is set.
1797 * The BAR0 or BAR1 region may be disabled (size 0) or enabled (size 128).
1798 * Re-allocate the regions to a 256-byte boundary if necessary.
1799 */
1800static void quirk_plx_pci9050(struct pci_dev *dev)
1801{
1802 unsigned int bar;
1803
1804 /* Fixed in revision 2 (PCI 9052). */
1805 if (dev->revision >= 2)
1806 return;
1807 for (bar = 0; bar <= 1; bar++)
1808 if (pci_resource_len(dev, bar) == 0x80 &&
1809 (pci_resource_start(dev, bar) & 0x80)) {
1810 struct resource *r = &dev->resource[bar];
1811 dev_info(&dev->dev,
1812 "Re-allocating PLX PCI 9050 BAR %u to length 256 to avoid bit 7 bug\n",
1813 bar);
1814 r->start = 0;
1815 r->end = 0xff;
1816 }
1817}
1818DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
1819 quirk_plx_pci9050);
1820/*
1821 * The following Meilhaus (vendor ID 0x1402) device IDs (amongst others)
1822 * may be using the PLX PCI 9050: 0x0630, 0x0940, 0x0950, 0x0960, 0x100b,
1823 * 0x1400, 0x140a, 0x140b, 0x14e0, 0x14ea, 0x14eb, 0x1604, 0x1608, 0x160c,
1824 * 0x168f, 0x2000, 0x2600, 0x3000, 0x810a, 0x810b.
1825 *
1826 * Currently, device IDs 0x2000 and 0x2600 are used by the Comedi "me_daq"
1827 * driver.
1828 */
1829DECLARE_PCI_FIXUP_HEADER(0x1402, 0x2000, quirk_plx_pci9050);
1830DECLARE_PCI_FIXUP_HEADER(0x1402, 0x2600, quirk_plx_pci9050);
1831
1793static void quirk_netmos(struct pci_dev *dev) 1832static void quirk_netmos(struct pci_dev *dev)
1794{ 1833{
1795 unsigned int num_parallel = (dev->subsystem_device & 0xf0) >> 4; 1834 unsigned int num_parallel = (dev->subsystem_device & 0xf0) >> 4;
diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c
index 513972f3ed13..7c0fd9252e6f 100644
--- a/drivers/pci/remove.c
+++ b/drivers/pci/remove.c
@@ -111,3 +111,39 @@ void pci_stop_and_remove_bus_device(struct pci_dev *dev)
111 pci_remove_bus_device(dev); 111 pci_remove_bus_device(dev);
112} 112}
113EXPORT_SYMBOL(pci_stop_and_remove_bus_device); 113EXPORT_SYMBOL(pci_stop_and_remove_bus_device);
114
115void pci_stop_root_bus(struct pci_bus *bus)
116{
117 struct pci_dev *child, *tmp;
118 struct pci_host_bridge *host_bridge;
119
120 if (!pci_is_root_bus(bus))
121 return;
122
123 host_bridge = to_pci_host_bridge(bus->bridge);
124 list_for_each_entry_safe_reverse(child, tmp,
125 &bus->devices, bus_list)
126 pci_stop_bus_device(child);
127
128 /* stop the host bridge */
129 device_del(&host_bridge->dev);
130}
131
132void pci_remove_root_bus(struct pci_bus *bus)
133{
134 struct pci_dev *child, *tmp;
135 struct pci_host_bridge *host_bridge;
136
137 if (!pci_is_root_bus(bus))
138 return;
139
140 host_bridge = to_pci_host_bridge(bus->bridge);
141 list_for_each_entry_safe(child, tmp,
142 &bus->devices, bus_list)
143 pci_remove_bus_device(child);
144 pci_remove_bus(bus);
145 host_bridge->bus = NULL;
146
147 /* remove the host bridge */
148 put_device(&host_bridge->dev);
149}
diff --git a/drivers/pci/rom.c b/drivers/pci/rom.c
index 0b3037ab8b93..ab886b7ee327 100644
--- a/drivers/pci/rom.c
+++ b/drivers/pci/rom.c
@@ -118,11 +118,17 @@ void __iomem *pci_map_rom(struct pci_dev *pdev, size_t *size)
118 void __iomem *rom; 118 void __iomem *rom;
119 119
120 /* 120 /*
121 * Some devices may provide ROMs via a source other than the BAR
122 */
123 if (pdev->rom && pdev->romlen) {
124 *size = pdev->romlen;
125 return phys_to_virt(pdev->rom);
126 /*
121 * IORESOURCE_ROM_SHADOW set on x86, x86_64 and IA64 supports legacy 127 * IORESOURCE_ROM_SHADOW set on x86, x86_64 and IA64 supports legacy
122 * memory map if the VGA enable bit of the Bridge Control register is 128 * memory map if the VGA enable bit of the Bridge Control register is
123 * set for embedded VGA. 129 * set for embedded VGA.
124 */ 130 */
125 if (res->flags & IORESOURCE_ROM_SHADOW) { 131 } else if (res->flags & IORESOURCE_ROM_SHADOW) {
126 /* primary video rom always starts here */ 132 /* primary video rom always starts here */
127 start = (loff_t)0xC0000; 133 start = (loff_t)0xC0000;
128 *size = 0x20000; /* cover C000:0 through E000:0 */ 134 *size = 0x20000; /* cover C000:0 through E000:0 */
@@ -181,7 +187,8 @@ void pci_unmap_rom(struct pci_dev *pdev, void __iomem *rom)
181 if (res->flags & (IORESOURCE_ROM_COPY | IORESOURCE_ROM_BIOS_COPY)) 187 if (res->flags & (IORESOURCE_ROM_COPY | IORESOURCE_ROM_BIOS_COPY))
182 return; 188 return;
183 189
184 iounmap(rom); 190 if (!pdev->rom || !pdev->romlen)
191 iounmap(rom);
185 192
186 /* Disable again before continuing, leave enabled if pci=rom */ 193 /* Disable again before continuing, leave enabled if pci=rom */
187 if (!(res->flags & (IORESOURCE_ROM_ENABLE | IORESOURCE_ROM_SHADOW))) 194 if (!(res->flags & (IORESOURCE_ROM_ENABLE | IORESOURCE_ROM_SHADOW)))
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 1e808ca338f8..6d3591d57ea0 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -1550,25 +1550,12 @@ enable_all:
1550} 1550}
1551EXPORT_SYMBOL_GPL(pci_assign_unassigned_bridge_resources); 1551EXPORT_SYMBOL_GPL(pci_assign_unassigned_bridge_resources);
1552 1552
1553#ifdef CONFIG_HOTPLUG 1553void pci_assign_unassigned_bus_resources(struct pci_bus *bus)
1554/**
1555 * pci_rescan_bus - scan a PCI bus for devices.
1556 * @bus: PCI bus to scan
1557 *
1558 * Scan a PCI bus and child buses for new devices, adds them,
1559 * and enables them.
1560 *
1561 * Returns the max number of subordinate bus discovered.
1562 */
1563unsigned int __ref pci_rescan_bus(struct pci_bus *bus)
1564{ 1554{
1565 unsigned int max;
1566 struct pci_dev *dev; 1555 struct pci_dev *dev;
1567 LIST_HEAD(add_list); /* list of resources that 1556 LIST_HEAD(add_list); /* list of resources that
1568 want additional resources */ 1557 want additional resources */
1569 1558
1570 max = pci_scan_child_bus(bus);
1571
1572 down_read(&pci_bus_sem); 1559 down_read(&pci_bus_sem);
1573 list_for_each_entry(dev, &bus->devices, bus_list) 1560 list_for_each_entry(dev, &bus->devices, bus_list)
1574 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE || 1561 if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
@@ -1579,11 +1566,4 @@ unsigned int __ref pci_rescan_bus(struct pci_bus *bus)
1579 up_read(&pci_bus_sem); 1566 up_read(&pci_bus_sem);
1580 __pci_bus_assign_resources(bus, &add_list, NULL); 1567 __pci_bus_assign_resources(bus, &add_list, NULL);
1581 BUG_ON(!list_empty(&add_list)); 1568 BUG_ON(!list_empty(&add_list));
1582
1583 pci_enable_bridges(bus);
1584 pci_bus_add_devices(bus);
1585
1586 return max;
1587} 1569}
1588EXPORT_SYMBOL_GPL(pci_rescan_bus);
1589#endif
diff --git a/drivers/pci/xen-pcifront.c b/drivers/pci/xen-pcifront.c
index db542f4196a4..966abc6054d7 100644
--- a/drivers/pci/xen-pcifront.c
+++ b/drivers/pci/xen-pcifront.c
@@ -1068,13 +1068,16 @@ static void __init_refok pcifront_backend_changed(struct xenbus_device *xdev,
1068 case XenbusStateInitialising: 1068 case XenbusStateInitialising:
1069 case XenbusStateInitWait: 1069 case XenbusStateInitWait:
1070 case XenbusStateInitialised: 1070 case XenbusStateInitialised:
1071 case XenbusStateClosed:
1072 break; 1071 break;
1073 1072
1074 case XenbusStateConnected: 1073 case XenbusStateConnected:
1075 pcifront_try_connect(pdev); 1074 pcifront_try_connect(pdev);
1076 break; 1075 break;
1077 1076
1077 case XenbusStateClosed:
1078 if (xdev->state == XenbusStateClosed)
1079 break;
1080 /* Missed the backend's CLOSING state -- fallthrough */
1078 case XenbusStateClosing: 1081 case XenbusStateClosing:
1079 dev_warn(&xdev->dev, "backend going away!\n"); 1082 dev_warn(&xdev->dev, "backend going away!\n");
1080 pcifront_try_disconnect(pdev); 1083 pcifront_try_disconnect(pdev);