aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/pci')
-rw-r--r--drivers/pci/pci-driver.c35
-rw-r--r--drivers/pci/pci.c36
-rw-r--r--drivers/pci/pci.h1
3 files changed, 59 insertions, 13 deletions
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 23bdf64411e5..57cb0015a470 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -324,9 +324,19 @@ static bool pci_has_legacy_pm_support(struct pci_dev *pci_dev)
324 324
325/* 325/*
326 * Default "suspend" method for devices that have no driver provided suspend, 326 * Default "suspend" method for devices that have no driver provided suspend,
327 * or not even a driver at all. 327 * or not even a driver at all (first part).
328 */
329static void pci_default_pm_suspend_early(struct pci_dev *pci_dev)
330{
331 /* If device is enabled at this point, disable it */
332 pci_disable_enabled_device(pci_dev);
333}
334
335/*
336 * Default "suspend" method for devices that have no driver provided suspend,
337 * or not even a driver at all (second part).
328 */ 338 */
329static void pci_default_pm_suspend(struct pci_dev *pci_dev) 339static void pci_default_pm_suspend_late(struct pci_dev *pci_dev)
330{ 340{
331 pci_save_state(pci_dev); 341 pci_save_state(pci_dev);
332 /* 342 /*
@@ -377,7 +387,11 @@ static int pci_legacy_suspend(struct device *dev, pm_message_t state)
377 i = drv->suspend(pci_dev, state); 387 i = drv->suspend(pci_dev, state);
378 suspend_report_result(drv->suspend, i); 388 suspend_report_result(drv->suspend, i);
379 } else { 389 } else {
380 pci_default_pm_suspend(pci_dev); 390 /*
391 * For compatibility with existing code with legacy PM support
392 * don't call pci_default_pm_suspend_early() here.
393 */
394 pci_default_pm_suspend_late(pci_dev);
381 } 395 }
382 return i; 396 return i;
383} 397}
@@ -455,7 +469,10 @@ static int pci_pm_suspend(struct device *dev)
455 } 469 }
456 } else if (pci_has_legacy_pm_support(pci_dev)) { 470 } else if (pci_has_legacy_pm_support(pci_dev)) {
457 error = pci_legacy_suspend(dev, PMSG_SUSPEND); 471 error = pci_legacy_suspend(dev, PMSG_SUSPEND);
472 } else {
473 pci_default_pm_suspend_early(pci_dev);
458 } 474 }
475
459 pci_fixup_device(pci_fixup_suspend, pci_dev); 476 pci_fixup_device(pci_fixup_suspend, pci_dev);
460 477
461 return error; 478 return error;
@@ -475,7 +492,7 @@ static int pci_pm_suspend_noirq(struct device *dev)
475 } else if (pci_has_legacy_pm_support(pci_dev)) { 492 } else if (pci_has_legacy_pm_support(pci_dev)) {
476 error = pci_legacy_suspend_late(dev, PMSG_SUSPEND); 493 error = pci_legacy_suspend_late(dev, PMSG_SUSPEND);
477 } else { 494 } else {
478 pci_default_pm_suspend(pci_dev); 495 pci_default_pm_suspend_late(pci_dev);
479 } 496 }
480 497
481 return error; 498 return error;
@@ -546,6 +563,8 @@ static int pci_pm_freeze(struct device *dev)
546 } else if (pci_has_legacy_pm_support(pci_dev)) { 563 } else if (pci_has_legacy_pm_support(pci_dev)) {
547 error = pci_legacy_suspend(dev, PMSG_FREEZE); 564 error = pci_legacy_suspend(dev, PMSG_FREEZE);
548 pci_fixup_device(pci_fixup_suspend, pci_dev); 565 pci_fixup_device(pci_fixup_suspend, pci_dev);
566 } else {
567 pci_default_pm_suspend_early(pci_dev);
549 } 568 }
550 569
551 return error; 570 return error;
@@ -565,7 +584,7 @@ static int pci_pm_freeze_noirq(struct device *dev)
565 } else if (pci_has_legacy_pm_support(pci_dev)) { 584 } else if (pci_has_legacy_pm_support(pci_dev)) {
566 error = pci_legacy_suspend_late(dev, PMSG_FREEZE); 585 error = pci_legacy_suspend_late(dev, PMSG_FREEZE);
567 } else { 586 } else {
568 pci_default_pm_suspend(pci_dev); 587 pci_default_pm_suspend_late(pci_dev);
569 } 588 }
570 589
571 return error; 590 return error;
@@ -583,6 +602,8 @@ static int pci_pm_thaw(struct device *dev)
583 } else if (pci_has_legacy_pm_support(pci_dev)) { 602 } else if (pci_has_legacy_pm_support(pci_dev)) {
584 pci_fixup_device(pci_fixup_resume, pci_dev); 603 pci_fixup_device(pci_fixup_resume, pci_dev);
585 error = pci_legacy_resume(dev); 604 error = pci_legacy_resume(dev);
605 } else {
606 pci_default_pm_resume_late(pci_dev);
586 } 607 }
587 608
588 return error; 609 return error;
@@ -600,6 +621,8 @@ static int pci_pm_thaw_noirq(struct device *dev)
600 } else if (pci_has_legacy_pm_support(pci_dev)) { 621 } else if (pci_has_legacy_pm_support(pci_dev)) {
601 pci_fixup_device(pci_fixup_resume_early, to_pci_dev(dev)); 622 pci_fixup_device(pci_fixup_resume_early, to_pci_dev(dev));
602 error = pci_legacy_resume_early(dev); 623 error = pci_legacy_resume_early(dev);
624 } else {
625 pci_default_pm_resume_early(pci_dev);
603 } 626 }
604 627
605 return error; 628 return error;
@@ -618,6 +641,8 @@ static int pci_pm_poweroff(struct device *dev)
618 } 641 }
619 } else if (pci_has_legacy_pm_support(pci_dev)) { 642 } else if (pci_has_legacy_pm_support(pci_dev)) {
620 error = pci_legacy_suspend(dev, PMSG_HIBERNATE); 643 error = pci_legacy_suspend(dev, PMSG_HIBERNATE);
644 } else {
645 pci_default_pm_suspend_early(pci_dev);
621 } 646 }
622 647
623 pci_fixup_device(pci_fixup_suspend, pci_dev); 648 pci_fixup_device(pci_fixup_suspend, pci_dev);
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index f3fd55df67db..6e309c8b47df 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -970,6 +970,32 @@ void pcim_pin_device(struct pci_dev *pdev)
970 */ 970 */
971void __attribute__ ((weak)) pcibios_disable_device (struct pci_dev *dev) {} 971void __attribute__ ((weak)) pcibios_disable_device (struct pci_dev *dev) {}
972 972
973static void do_pci_disable_device(struct pci_dev *dev)
974{
975 u16 pci_command;
976
977 pci_read_config_word(dev, PCI_COMMAND, &pci_command);
978 if (pci_command & PCI_COMMAND_MASTER) {
979 pci_command &= ~PCI_COMMAND_MASTER;
980 pci_write_config_word(dev, PCI_COMMAND, pci_command);
981 }
982
983 pcibios_disable_device(dev);
984}
985
986/**
987 * pci_disable_enabled_device - Disable device without updating enable_cnt
988 * @dev: PCI device to disable
989 *
990 * NOTE: This function is a backend of PCI power management routines and is
991 * not supposed to be called drivers.
992 */
993void pci_disable_enabled_device(struct pci_dev *dev)
994{
995 if (atomic_read(&dev->enable_cnt))
996 do_pci_disable_device(dev);
997}
998
973/** 999/**
974 * pci_disable_device - Disable PCI device after use 1000 * pci_disable_device - Disable PCI device after use
975 * @dev: PCI device to be disabled 1001 * @dev: PCI device to be disabled
@@ -984,7 +1010,6 @@ void
984pci_disable_device(struct pci_dev *dev) 1010pci_disable_device(struct pci_dev *dev)
985{ 1011{
986 struct pci_devres *dr; 1012 struct pci_devres *dr;
987 u16 pci_command;
988 1013
989 dr = find_pci_dr(dev); 1014 dr = find_pci_dr(dev);
990 if (dr) 1015 if (dr)
@@ -993,14 +1018,9 @@ pci_disable_device(struct pci_dev *dev)
993 if (atomic_sub_return(1, &dev->enable_cnt) != 0) 1018 if (atomic_sub_return(1, &dev->enable_cnt) != 0)
994 return; 1019 return;
995 1020
996 pci_read_config_word(dev, PCI_COMMAND, &pci_command); 1021 do_pci_disable_device(dev);
997 if (pci_command & PCI_COMMAND_MASTER) {
998 pci_command &= ~PCI_COMMAND_MASTER;
999 pci_write_config_word(dev, PCI_COMMAND, pci_command);
1000 }
1001 dev->is_busmaster = 0;
1002 1022
1003 pcibios_disable_device(dev); 1023 dev->is_busmaster = 0;
1004} 1024}
1005 1025
1006/** 1026/**
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 211fd418f48f..881dc15f8efd 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -44,6 +44,7 @@ struct pci_platform_pm_ops {
44}; 44};
45 45
46extern int pci_set_platform_pm(struct pci_platform_pm_ops *ops); 46extern int pci_set_platform_pm(struct pci_platform_pm_ops *ops);
47extern void pci_disable_enabled_device(struct pci_dev *dev);
47extern void pci_pm_init(struct pci_dev *dev); 48extern void pci_pm_init(struct pci_dev *dev);
48extern void platform_pci_wakeup_init(struct pci_dev *dev); 49extern void platform_pci_wakeup_init(struct pci_dev *dev);
49extern void pci_allocate_cap_save_buffers(struct pci_dev *dev); 50extern void pci_allocate_cap_save_buffers(struct pci_dev *dev);