Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jbarnes/pci-2.6

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jbarnes/pci-2.6:
PCI hotplug: fix lock imbalance in pciehp
PCI PM: Restore standard config registers of all devices early
PCI/MSI: bugfix/utilize for msi_capability_init()

+105 -80
+3 -1
drivers/pci/hotplug/pciehp_core.c
··· 126 mutex_lock(&slot->ctrl->crit_sect); 127 128 /* has it been >1 sec since our last toggle? */ 129 - if ((get_seconds() - slot->last_emi_toggle) < 1) 130 return -EINVAL; 131 132 /* see what our current state is */ 133 retval = get_lock_status(hotplug_slot, &value);
··· 126 mutex_lock(&slot->ctrl->crit_sect); 127 128 /* has it been >1 sec since our last toggle? */ 129 + if ((get_seconds() - slot->last_emi_toggle) < 1) { 130 + mutex_unlock(&slot->ctrl->crit_sect); 131 return -EINVAL; 132 + } 133 134 /* see what our current state is */ 135 retval = get_lock_status(hotplug_slot, &value);
+7 -9
drivers/pci/msi.c
··· 398 entry->msi_attrib.masked = 1; 399 entry->msi_attrib.default_irq = dev->irq; /* Save IOAPIC IRQ */ 400 entry->msi_attrib.pos = pos; 401 - if (entry->msi_attrib.maskbit) { 402 - entry->mask_base = (void __iomem *)(long)msi_mask_bits_reg(pos, 403 - entry->msi_attrib.is_64); 404 - } 405 entry->dev = dev; 406 if (entry->msi_attrib.maskbit) { 407 - unsigned int maskbits, temp; 408 /* All MSIs are unmasked by default, Mask them all */ 409 - pci_read_config_dword(dev, 410 - msi_mask_bits_reg(pos, entry->msi_attrib.is_64), 411 - &maskbits); 412 temp = (1 << multi_msi_capable(control)); 413 temp = ((temp - 1) & ~temp); 414 maskbits |= temp; 415 - pci_write_config_dword(dev, entry->msi_attrib.is_64, maskbits); 416 entry->msi_attrib.maskbits_mask = temp; 417 } 418 list_add_tail(&entry->list, &dev->msi_list);
··· 398 entry->msi_attrib.masked = 1; 399 entry->msi_attrib.default_irq = dev->irq; /* Save IOAPIC IRQ */ 400 entry->msi_attrib.pos = pos; 401 entry->dev = dev; 402 if (entry->msi_attrib.maskbit) { 403 + unsigned int base, maskbits, temp; 404 + 405 + base = msi_mask_bits_reg(pos, entry->msi_attrib.is_64); 406 + entry->mask_base = (void __iomem *)(long)base; 407 + 408 /* All MSIs are unmasked by default, Mask them all */ 409 + pci_read_config_dword(dev, base, &maskbits); 410 temp = (1 << multi_msi_capable(control)); 411 temp = ((temp - 1) & ~temp); 412 maskbits |= temp; 413 + pci_write_config_dword(dev, base, maskbits); 414 entry->msi_attrib.maskbits_mask = temp; 415 } 416 list_add_tail(&entry->list, &dev->msi_list);
+27 -64
drivers/pci/pci-driver.c
··· 355 int i = 0; 356 357 if (drv && drv->suspend) { 358 i = drv->suspend(pci_dev, state); 359 suspend_report_result(drv->suspend, i); 360 - } else { 361 - pci_save_state(pci_dev); 362 - /* 363 - * This is for compatibility with existing code with legacy PM 364 - * support. 365 - */ 366 - pci_pm_set_unknown_state(pci_dev); 367 } 368 369 pci_fixup_device(pci_fixup_suspend, pci_dev); 370 371 return i; ··· 396 397 static int pci_legacy_resume_early(struct device *dev) 398 { 399 - int error = 0; 400 struct pci_dev * pci_dev = to_pci_dev(dev); 401 struct pci_driver * drv = pci_dev->driver; 402 403 - pci_fixup_device(pci_fixup_resume_early, pci_dev); 404 - 405 - if (drv && drv->resume_early) 406 - error = drv->resume_early(pci_dev); 407 - return error; 408 } 409 410 static int pci_legacy_resume(struct device *dev) 411 { 412 - int error; 413 struct pci_dev * pci_dev = to_pci_dev(dev); 414 struct pci_driver * drv = pci_dev->driver; 415 416 pci_fixup_device(pci_fixup_resume, pci_dev); 417 418 - if (drv && drv->resume) { 419 - error = drv->resume(pci_dev); 420 - } else { 421 - /* restore the PCI config space */ 422 - pci_restore_state(pci_dev); 423 - error = pci_pm_reenable_device(pci_dev); 424 - } 425 - return error; 426 } 427 428 /* Auxiliary functions used by the new power management framework */ 429 430 - static int pci_restore_standard_config(struct pci_dev *pci_dev) 431 - { 432 - struct pci_dev *parent = pci_dev->bus->self; 433 - int error = 0; 434 - 435 - /* Check if the device's bus is operational */ 436 - if (!parent || parent->current_state == PCI_D0) { 437 - pci_restore_state(pci_dev); 438 - pci_update_current_state(pci_dev, PCI_D0); 439 - } else { 440 - dev_warn(&pci_dev->dev, "unable to restore config, " 441 - "bridge %s in low power state D%d\n", pci_name(parent), 442 - parent->current_state); 443 - pci_dev->current_state = PCI_UNKNOWN; 444 - error = -EAGAIN; 445 - } 446 - 447 - return error; 448 - } 449 - 450 - static bool pci_is_bridge(struct pci_dev *pci_dev) 451 - { 452 - return !!(pci_dev->subordinate); 453 - } 454 - 455 static void pci_pm_default_resume_noirq(struct pci_dev *pci_dev) 456 { 457 - if (pci_restore_standard_config(pci_dev)) 458 - pci_fixup_device(pci_fixup_resume_early, pci_dev); 459 } 460 461 static int pci_pm_default_resume(struct pci_dev *pci_dev) 462 { 463 - /* 464 - * pci_restore_standard_config() should have been called once already, 465 - * but it would have failed if the device's parent bridge had not been 466 - * in power state D0 at that time. Check it and try again if necessary. 467 - */ 468 - if (pci_dev->current_state == PCI_UNKNOWN) { 469 - int error = pci_restore_standard_config(pci_dev); 470 - if (error) 471 - return error; 472 - } 473 - 474 pci_fixup_device(pci_fixup_resume, pci_dev); 475 476 if (!pci_is_bridge(pci_dev)) ··· 538 struct device_driver *drv = dev->driver; 539 int error = 0; 540 541 if (pci_has_legacy_pm_support(pci_dev)) 542 return pci_legacy_resume_early(dev); 543 - 544 - pci_pm_default_resume_noirq(pci_dev); 545 546 if (drv && drv->pm && drv->pm->resume_noirq) 547 error = drv->pm->resume_noirq(dev); ··· 693 struct device_driver *drv = dev->driver; 694 int error = 0; 695 696 if (pci_has_legacy_pm_support(pci_dev)) 697 return pci_legacy_resume_early(dev); 698 - 699 - pci_pm_default_resume_noirq(pci_dev); 700 701 if (drv && drv->pm && drv->pm->restore_noirq) 702 error = drv->pm->restore_noirq(dev);
··· 355 int i = 0; 356 357 if (drv && drv->suspend) { 358 + pci_dev->state_saved = false; 359 + 360 i = drv->suspend(pci_dev, state); 361 suspend_report_result(drv->suspend, i); 362 + if (i) 363 + return i; 364 + 365 + if (pci_dev->state_saved) 366 + goto Fixup; 367 + 368 + if (WARN_ON_ONCE(pci_dev->current_state != PCI_D0)) 369 + goto Fixup; 370 } 371 372 + pci_save_state(pci_dev); 373 + /* 374 + * This is for compatibility with existing code with legacy PM support. 375 + */ 376 + pci_pm_set_unknown_state(pci_dev); 377 + 378 + Fixup: 379 pci_fixup_device(pci_fixup_suspend, pci_dev); 380 381 return i; ··· 386 387 static int pci_legacy_resume_early(struct device *dev) 388 { 389 struct pci_dev * pci_dev = to_pci_dev(dev); 390 struct pci_driver * drv = pci_dev->driver; 391 392 + return drv && drv->resume_early ? 393 + drv->resume_early(pci_dev) : 0; 394 } 395 396 static int pci_legacy_resume(struct device *dev) 397 { 398 struct pci_dev * pci_dev = to_pci_dev(dev); 399 struct pci_driver * drv = pci_dev->driver; 400 401 pci_fixup_device(pci_fixup_resume, pci_dev); 402 403 + return drv && drv->resume ? 404 + drv->resume(pci_dev) : pci_pm_reenable_device(pci_dev); 405 } 406 407 /* Auxiliary functions used by the new power management framework */ 408 409 static void pci_pm_default_resume_noirq(struct pci_dev *pci_dev) 410 { 411 + pci_restore_standard_config(pci_dev); 412 + pci_fixup_device(pci_fixup_resume_early, pci_dev); 413 } 414 415 static int pci_pm_default_resume(struct pci_dev *pci_dev) 416 { 417 pci_fixup_device(pci_fixup_resume, pci_dev); 418 419 if (!pci_is_bridge(pci_dev)) ··· 575 struct device_driver *drv = dev->driver; 576 int error = 0; 577 578 + pci_pm_default_resume_noirq(pci_dev); 579 + 580 if (pci_has_legacy_pm_support(pci_dev)) 581 return pci_legacy_resume_early(dev); 582 583 if (drv && drv->pm && drv->pm->resume_noirq) 584 error = drv->pm->resume_noirq(dev); ··· 730 struct device_driver *drv = dev->driver; 731 int error = 0; 732 733 + pci_pm_default_resume_noirq(pci_dev); 734 + 735 if (pci_has_legacy_pm_support(pci_dev)) 736 return pci_legacy_resume_early(dev); 737 738 if (drv && drv->pm && drv->pm->restore_noirq) 739 error = drv->pm->restore_noirq(dev);
+57 -6
drivers/pci/pci.c
··· 22 #include <asm/dma.h> /* isa_dma_bridge_buggy */ 23 #include "pci.h" 24 25 - unsigned int pci_pm_d3_delay = 10; 26 27 #ifdef CONFIG_PCI_DOMAINS 28 int pci_domains_supported = 1; ··· 426 * given PCI device 427 * @dev: PCI device to handle. 428 * @state: PCI power state (D0, D1, D2, D3hot) to put the device into. 429 * 430 * RETURN VALUE: 431 * -EINVAL if the requested state is invalid. ··· 436 * 0 if device's power state has been successfully changed. 437 */ 438 static int 439 - pci_raw_set_power_state(struct pci_dev *dev, pci_power_t state) 440 { 441 u16 pmcsr; 442 bool need_restore = false; ··· 481 break; 482 case PCI_UNKNOWN: /* Boot-up */ 483 if ((pmcsr & PCI_PM_CTRL_STATE_MASK) == PCI_D3hot 484 - && !(pmcsr & PCI_PM_CTRL_NO_SOFT_RESET)) 485 need_restore = true; 486 /* Fall-through: force to D0 */ 487 default: 488 pmcsr = 0; ··· 494 /* enter specified state */ 495 pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, pmcsr); 496 497 /* Mandatory power management transition delays */ 498 /* see PCI PM 1.1 5.6.1 table 18 */ 499 if (state == PCI_D3hot || dev->current_state == PCI_D3hot) 500 msleep(pci_pm_d3_delay); 501 else if (state == PCI_D2 || dev->current_state == PCI_D2) 502 - udelay(200); 503 504 dev->current_state = state; 505 ··· 521 if (need_restore) 522 pci_restore_bars(dev); 523 524 - if (dev->bus->self) 525 pcie_aspm_pm_state_change(dev->bus->self); 526 527 return 0; ··· 591 if (state == PCI_D3hot && (dev->dev_flags & PCI_DEV_FLAGS_NO_D3)) 592 return 0; 593 594 - error = pci_raw_set_power_state(dev, state); 595 596 if (state > PCI_D0 && platform_pci_power_manageable(dev)) { 597 /* Allow the platform to finalize the transition */ ··· 736 /* XXX: 100% dword access ok here? */ 737 for (i = 0; i < 16; i++) 738 pci_read_config_dword(dev, i * 4,&dev->saved_config_space[i]); 739 if ((i = pci_save_pcie_state(dev)) != 0) 740 return i; 741 if ((i = pci_save_pcix_state(dev)) != 0) ··· 1378 if (error) 1379 dev_err(&dev->dev, 1380 "unable to preallocate PCI-X save buffer\n"); 1381 } 1382 1383 /**
··· 22 #include <asm/dma.h> /* isa_dma_bridge_buggy */ 23 #include "pci.h" 24 25 + unsigned int pci_pm_d3_delay = PCI_PM_D3_WAIT; 26 27 #ifdef CONFIG_PCI_DOMAINS 28 int pci_domains_supported = 1; ··· 426 * given PCI device 427 * @dev: PCI device to handle. 428 * @state: PCI power state (D0, D1, D2, D3hot) to put the device into. 429 + * @wait: If 'true', wait for the device to change its power state 430 * 431 * RETURN VALUE: 432 * -EINVAL if the requested state is invalid. ··· 435 * 0 if device's power state has been successfully changed. 436 */ 437 static int 438 + pci_raw_set_power_state(struct pci_dev *dev, pci_power_t state, bool wait) 439 { 440 u16 pmcsr; 441 bool need_restore = false; ··· 480 break; 481 case PCI_UNKNOWN: /* Boot-up */ 482 if ((pmcsr & PCI_PM_CTRL_STATE_MASK) == PCI_D3hot 483 + && !(pmcsr & PCI_PM_CTRL_NO_SOFT_RESET)) { 484 need_restore = true; 485 + wait = true; 486 + } 487 /* Fall-through: force to D0 */ 488 default: 489 pmcsr = 0; ··· 491 /* enter specified state */ 492 pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, pmcsr); 493 494 + if (!wait) 495 + return 0; 496 + 497 /* Mandatory power management transition delays */ 498 /* see PCI PM 1.1 5.6.1 table 18 */ 499 if (state == PCI_D3hot || dev->current_state == PCI_D3hot) 500 msleep(pci_pm_d3_delay); 501 else if (state == PCI_D2 || dev->current_state == PCI_D2) 502 + udelay(PCI_PM_D2_DELAY); 503 504 dev->current_state = state; 505 ··· 515 if (need_restore) 516 pci_restore_bars(dev); 517 518 + if (wait && dev->bus->self) 519 pcie_aspm_pm_state_change(dev->bus->self); 520 521 return 0; ··· 585 if (state == PCI_D3hot && (dev->dev_flags & PCI_DEV_FLAGS_NO_D3)) 586 return 0; 587 588 + error = pci_raw_set_power_state(dev, state, true); 589 590 if (state > PCI_D0 && platform_pci_power_manageable(dev)) { 591 /* Allow the platform to finalize the transition */ ··· 730 /* XXX: 100% dword access ok here? */ 731 for (i = 0; i < 16; i++) 732 pci_read_config_dword(dev, i * 4,&dev->saved_config_space[i]); 733 + dev->state_saved = true; 734 if ((i = pci_save_pcie_state(dev)) != 0) 735 return i; 736 if ((i = pci_save_pcix_state(dev)) != 0) ··· 1371 if (error) 1372 dev_err(&dev->dev, 1373 "unable to preallocate PCI-X save buffer\n"); 1374 + } 1375 + 1376 + /** 1377 + * pci_restore_standard_config - restore standard config registers of PCI device 1378 + * @dev: PCI device to handle 1379 + * 1380 + * This function assumes that the device's configuration space is accessible. 1381 + * If the device needs to be powered up, the function will wait for it to 1382 + * change the state. 1383 + */ 1384 + int pci_restore_standard_config(struct pci_dev *dev) 1385 + { 1386 + pci_power_t prev_state; 1387 + int error; 1388 + 1389 + pci_restore_state(dev); 1390 + pci_update_current_state(dev, PCI_D0); 1391 + 1392 + prev_state = dev->current_state; 1393 + if (prev_state == PCI_D0) 1394 + return 0; 1395 + 1396 + error = pci_raw_set_power_state(dev, PCI_D0, false); 1397 + if (error) 1398 + return error; 1399 + 1400 + if (pci_is_bridge(dev)) { 1401 + if (prev_state > PCI_D1) 1402 + mdelay(PCI_PM_BUS_WAIT); 1403 + } else { 1404 + switch(prev_state) { 1405 + case PCI_D3cold: 1406 + case PCI_D3hot: 1407 + mdelay(pci_pm_d3_delay); 1408 + break; 1409 + case PCI_D2: 1410 + udelay(PCI_PM_D2_DELAY); 1411 + break; 1412 + } 1413 + } 1414 + 1415 + dev->current_state = PCI_D0; 1416 + 1417 + return 0; 1418 } 1419 1420 /**
+6
drivers/pci/pci.h
··· 49 extern void pci_pm_init(struct pci_dev *dev); 50 extern void platform_pci_wakeup_init(struct pci_dev *dev); 51 extern void pci_allocate_cap_save_buffers(struct pci_dev *dev); 52 53 extern int pci_user_read_config_byte(struct pci_dev *dev, int where, u8 *val); 54 extern int pci_user_read_config_word(struct pci_dev *dev, int where, u16 *val);
··· 49 extern void pci_pm_init(struct pci_dev *dev); 50 extern void platform_pci_wakeup_init(struct pci_dev *dev); 51 extern void pci_allocate_cap_save_buffers(struct pci_dev *dev); 52 + extern int pci_restore_standard_config(struct pci_dev *dev); 53 + 54 + static inline bool pci_is_bridge(struct pci_dev *pci_dev) 55 + { 56 + return !!(pci_dev->subordinate); 57 + } 58 59 extern int pci_user_read_config_byte(struct pci_dev *dev, int where, u8 *val); 60 extern int pci_user_read_config_word(struct pci_dev *dev, int where, u16 *val);
+5
include/linux/pci.h
··· 117 #define PCI_UNKNOWN ((pci_power_t __force) 5) 118 #define PCI_POWER_ERROR ((pci_power_t __force) -1) 119 120 /** The pci_channel state describes connectivity between the CPU and 121 * the pci device. If some PCI bus between here and the pci device 122 * has crashed or locked up, this info is reflected here. ··· 256 unsigned int ari_enabled:1; /* ARI forwarding */ 257 unsigned int is_managed:1; 258 unsigned int is_pcie:1; 259 pci_dev_flags_t dev_flags; 260 atomic_t enable_cnt; /* pci_enable_device has been called */ 261
··· 117 #define PCI_UNKNOWN ((pci_power_t __force) 5) 118 #define PCI_POWER_ERROR ((pci_power_t __force) -1) 119 120 + #define PCI_PM_D2_DELAY 200 121 + #define PCI_PM_D3_WAIT 10 122 + #define PCI_PM_BUS_WAIT 50 123 + 124 /** The pci_channel state describes connectivity between the CPU and 125 * the pci device. If some PCI bus between here and the pci device 126 * has crashed or locked up, this info is reflected here. ··· 252 unsigned int ari_enabled:1; /* ARI forwarding */ 253 unsigned int is_managed:1; 254 unsigned int is_pcie:1; 255 + unsigned int state_saved:1; 256 pci_dev_flags_t dev_flags; 257 atomic_t enable_cnt; /* pci_enable_device has been called */ 258