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 126 mutex_lock(&slot->ctrl->crit_sect); 127 127 128 128 /* has it been >1 sec since our last toggle? */ 129 - if ((get_seconds() - slot->last_emi_toggle) < 1) 129 + if ((get_seconds() - slot->last_emi_toggle) < 1) { 130 + mutex_unlock(&slot->ctrl->crit_sect); 130 131 return -EINVAL; 132 + } 131 133 132 134 /* see what our current state is */ 133 135 retval = get_lock_status(hotplug_slot, &value);
+7 -9
drivers/pci/msi.c
··· 398 398 entry->msi_attrib.masked = 1; 399 399 entry->msi_attrib.default_irq = dev->irq; /* Save IOAPIC IRQ */ 400 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 401 entry->dev = dev; 406 402 if (entry->msi_attrib.maskbit) { 407 - unsigned int maskbits, temp; 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 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); 409 + pci_read_config_dword(dev, base, &maskbits); 412 410 temp = (1 << multi_msi_capable(control)); 413 411 temp = ((temp - 1) & ~temp); 414 412 maskbits |= temp; 415 - pci_write_config_dword(dev, entry->msi_attrib.is_64, maskbits); 413 + pci_write_config_dword(dev, base, maskbits); 416 414 entry->msi_attrib.maskbits_mask = temp; 417 415 } 418 416 list_add_tail(&entry->list, &dev->msi_list);
+27 -64
drivers/pci/pci-driver.c
··· 355 355 int i = 0; 356 356 357 357 if (drv && drv->suspend) { 358 + pci_dev->state_saved = false; 359 + 358 360 i = drv->suspend(pci_dev, state); 359 361 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); 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; 367 370 } 368 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: 369 379 pci_fixup_device(pci_fixup_suspend, pci_dev); 370 380 371 381 return i; ··· 396 386 397 387 static int pci_legacy_resume_early(struct device *dev) 398 388 { 399 - int error = 0; 400 389 struct pci_dev * pci_dev = to_pci_dev(dev); 401 390 struct pci_driver * drv = pci_dev->driver; 402 391 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; 392 + return drv && drv->resume_early ? 393 + drv->resume_early(pci_dev) : 0; 408 394 } 409 395 410 396 static int pci_legacy_resume(struct device *dev) 411 397 { 412 - int error; 413 398 struct pci_dev * pci_dev = to_pci_dev(dev); 414 399 struct pci_driver * drv = pci_dev->driver; 415 400 416 401 pci_fixup_device(pci_fixup_resume, pci_dev); 417 402 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; 403 + return drv && drv->resume ? 404 + drv->resume(pci_dev) : pci_pm_reenable_device(pci_dev); 426 405 } 427 406 428 407 /* Auxiliary functions used by the new power management framework */ 429 408 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 409 static void pci_pm_default_resume_noirq(struct pci_dev *pci_dev) 456 410 { 457 - if (pci_restore_standard_config(pci_dev)) 458 - pci_fixup_device(pci_fixup_resume_early, pci_dev); 411 + pci_restore_standard_config(pci_dev); 412 + pci_fixup_device(pci_fixup_resume_early, pci_dev); 459 413 } 460 414 461 415 static int pci_pm_default_resume(struct pci_dev *pci_dev) 462 416 { 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 417 pci_fixup_device(pci_fixup_resume, pci_dev); 475 418 476 419 if (!pci_is_bridge(pci_dev)) ··· 538 575 struct device_driver *drv = dev->driver; 539 576 int error = 0; 540 577 578 + pci_pm_default_resume_noirq(pci_dev); 579 + 541 580 if (pci_has_legacy_pm_support(pci_dev)) 542 581 return pci_legacy_resume_early(dev); 543 - 544 - pci_pm_default_resume_noirq(pci_dev); 545 582 546 583 if (drv && drv->pm && drv->pm->resume_noirq) 547 584 error = drv->pm->resume_noirq(dev); ··· 693 730 struct device_driver *drv = dev->driver; 694 731 int error = 0; 695 732 733 + pci_pm_default_resume_noirq(pci_dev); 734 + 696 735 if (pci_has_legacy_pm_support(pci_dev)) 697 736 return pci_legacy_resume_early(dev); 698 - 699 - pci_pm_default_resume_noirq(pci_dev); 700 737 701 738 if (drv && drv->pm && drv->pm->restore_noirq) 702 739 error = drv->pm->restore_noirq(dev);
+57 -6
drivers/pci/pci.c
··· 22 22 #include <asm/dma.h> /* isa_dma_bridge_buggy */ 23 23 #include "pci.h" 24 24 25 - unsigned int pci_pm_d3_delay = 10; 25 + unsigned int pci_pm_d3_delay = PCI_PM_D3_WAIT; 26 26 27 27 #ifdef CONFIG_PCI_DOMAINS 28 28 int pci_domains_supported = 1; ··· 426 426 * given PCI device 427 427 * @dev: PCI device to handle. 428 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 429 430 * 430 431 * RETURN VALUE: 431 432 * -EINVAL if the requested state is invalid. ··· 436 435 * 0 if device's power state has been successfully changed. 437 436 */ 438 437 static int 439 - pci_raw_set_power_state(struct pci_dev *dev, pci_power_t state) 438 + pci_raw_set_power_state(struct pci_dev *dev, pci_power_t state, bool wait) 440 439 { 441 440 u16 pmcsr; 442 441 bool need_restore = false; ··· 481 480 break; 482 481 case PCI_UNKNOWN: /* Boot-up */ 483 482 if ((pmcsr & PCI_PM_CTRL_STATE_MASK) == PCI_D3hot 484 - && !(pmcsr & PCI_PM_CTRL_NO_SOFT_RESET)) 483 + && !(pmcsr & PCI_PM_CTRL_NO_SOFT_RESET)) { 485 484 need_restore = true; 485 + wait = true; 486 + } 486 487 /* Fall-through: force to D0 */ 487 488 default: 488 489 pmcsr = 0; ··· 494 491 /* enter specified state */ 495 492 pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, pmcsr); 496 493 494 + if (!wait) 495 + return 0; 496 + 497 497 /* Mandatory power management transition delays */ 498 498 /* see PCI PM 1.1 5.6.1 table 18 */ 499 499 if (state == PCI_D3hot || dev->current_state == PCI_D3hot) 500 500 msleep(pci_pm_d3_delay); 501 501 else if (state == PCI_D2 || dev->current_state == PCI_D2) 502 - udelay(200); 502 + udelay(PCI_PM_D2_DELAY); 503 503 504 504 dev->current_state = state; 505 505 ··· 521 515 if (need_restore) 522 516 pci_restore_bars(dev); 523 517 524 - if (dev->bus->self) 518 + if (wait && dev->bus->self) 525 519 pcie_aspm_pm_state_change(dev->bus->self); 526 520 527 521 return 0; ··· 591 585 if (state == PCI_D3hot && (dev->dev_flags & PCI_DEV_FLAGS_NO_D3)) 592 586 return 0; 593 587 594 - error = pci_raw_set_power_state(dev, state); 588 + error = pci_raw_set_power_state(dev, state, true); 595 589 596 590 if (state > PCI_D0 && platform_pci_power_manageable(dev)) { 597 591 /* Allow the platform to finalize the transition */ ··· 736 730 /* XXX: 100% dword access ok here? */ 737 731 for (i = 0; i < 16; i++) 738 732 pci_read_config_dword(dev, i * 4,&dev->saved_config_space[i]); 733 + dev->state_saved = true; 739 734 if ((i = pci_save_pcie_state(dev)) != 0) 740 735 return i; 741 736 if ((i = pci_save_pcix_state(dev)) != 0) ··· 1378 1371 if (error) 1379 1372 dev_err(&dev->dev, 1380 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; 1381 1418 } 1382 1419 1383 1420 /**
+6
drivers/pci/pci.h
··· 49 49 extern void pci_pm_init(struct pci_dev *dev); 50 50 extern void platform_pci_wakeup_init(struct pci_dev *dev); 51 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 + } 52 58 53 59 extern int pci_user_read_config_byte(struct pci_dev *dev, int where, u8 *val); 54 60 extern int pci_user_read_config_word(struct pci_dev *dev, int where, u16 *val);
+5
include/linux/pci.h
··· 117 117 #define PCI_UNKNOWN ((pci_power_t __force) 5) 118 118 #define PCI_POWER_ERROR ((pci_power_t __force) -1) 119 119 120 + #define PCI_PM_D2_DELAY 200 121 + #define PCI_PM_D3_WAIT 10 122 + #define PCI_PM_BUS_WAIT 50 123 + 120 124 /** The pci_channel state describes connectivity between the CPU and 121 125 * the pci device. If some PCI bus between here and the pci device 122 126 * has crashed or locked up, this info is reflected here. ··· 256 252 unsigned int ari_enabled:1; /* ARI forwarding */ 257 253 unsigned int is_managed:1; 258 254 unsigned int is_pcie:1; 255 + unsigned int state_saved:1; 259 256 pci_dev_flags_t dev_flags; 260 257 atomic_t enable_cnt; /* pci_enable_device has been called */ 261 258