From 7897e6022761ace7377f0f784fca059da55f5d71 Mon Sep 17 00:00:00 2001 From: Konstantin Khlebnikov Date: Mon, 4 Feb 2013 15:55:58 +0400 Subject: PCI: Disable Bus Master unconditionally in pci_device_shutdown() Commit b566a22c23 ("PCI: disable Bus Master on PCI device shutdown") used pci_disable_device(), but that doesn't disable Bus Mastering unconditionally; we allow nested enable/disable calls, and only the last disable call actually does anything. This uses pci_clear_master() to unconditionally clear the Bus Master bit. Matthew Garrett and Alan Cox said (see LKML link below) that clearing Bus Master for all PCI devices may lead to unpredictable consequences: some devices ignores this bit and continue DMA, some of them hang after that or crash the whole system. But we're already trying to clear Bus Master in general because of b566a22c23; this merely deals with the cases where drivers haven't shut down the device correctly. [bhelgaas: changelog] Link: https://lkml.org/lkml/2012/6/6/278 Signed-off-by: Konstantin Khlebnikov Signed-off-by: Bjorn Helgaas Acked-by: Rafael J. Wysocki --- drivers/pci/pci-driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/pci') diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index f79cbcd3944..dc5bdce63f1 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -392,7 +392,7 @@ static void pci_device_shutdown(struct device *dev) * Turn off Bus Master bit on the device to tell it to not * continue to do DMA */ - pci_disable_device(pci_dev); + pci_clear_master(pci_dev); } #ifdef CONFIG_PM -- cgit v1.2.3 From fd6dceab017e6be6c158dc56ec6dacf817f21a5b Mon Sep 17 00:00:00 2001 From: Konstantin Khlebnikov Date: Mon, 4 Feb 2013 15:56:01 +0400 Subject: PCI: Catch attempts to disable already-disabled devices Warn when disabling a device that has already been disabled. [bhelgaas: message wording] Signed-off-by: Konstantin Khlebnikov Signed-off-by: Bjorn Helgaas Acked-by: Rafael J. Wysocki --- drivers/pci/pci.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'drivers/pci') diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 5cb5820fae4..29a09b705f0 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1401,6 +1401,9 @@ pci_disable_device(struct pci_dev *dev) if (dr) dr->enabled = 0; + dev_WARN_ONCE(&dev->dev, atomic_read(&dev->enable_cnt) <= 0, + "disabling already-disabled device"); + if (atomic_sub_return(1, &dev->enable_cnt) != 0) return; -- cgit v1.2.3 From cc7ba39bab126339d6d525ada07dea5633d71521 Mon Sep 17 00:00:00 2001 From: Bjorn Helgaas Date: Mon, 11 Feb 2013 16:47:01 -0700 Subject: PCI: Use atomic_inc_return() rather than atomic_add_return() No functional change; just use atomic_inc_return() rather than the general-purpose atomic_add_return(). Signed-off-by: Bjorn Helgaas --- drivers/pci/pci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/pci') diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 29a09b705f0..c746b04afd6 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1174,7 +1174,7 @@ static int __pci_enable_device_flags(struct pci_dev *dev, dev->current_state = (pmcsr & PCI_PM_CTRL_STATE_MASK); } - if (atomic_add_return(1, &dev->enable_cnt) > 1) + if (atomic_inc_return(&dev->enable_cnt) > 1) return 0; /* already enabled */ /* only skip sriov related */ @@ -1404,7 +1404,7 @@ pci_disable_device(struct pci_dev *dev) dev_WARN_ONCE(&dev->dev, atomic_read(&dev->enable_cnt) <= 0, "disabling already-disabled device"); - if (atomic_sub_return(1, &dev->enable_cnt) != 0) + if (atomic_dec_return(&dev->enable_cnt) != 0) return; do_pci_disable_device(dev); -- cgit v1.2.3 From 82fee4d67ab86d6fe5eb0f9a9e988ca9d654d765 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Mon, 4 Feb 2013 15:56:05 +0400 Subject: PCI/PM: Clear state_saved during suspend This patch clears pci_dev->state_saved at the beginning of suspending. PCI config state may be saved long before that. Some drivers call pci_save_state() from the ->probe() callback to get snapshot of sane configuration space to use in the ->slot_reset() callback. Signed-off-by: Konstantin Khlebnikov # add comment Signed-off-by: Bjorn Helgaas --- drivers/pci/pci-driver.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'drivers/pci') diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index dc5bdce63f1..f9aa311b9f3 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -628,6 +628,7 @@ static int pci_pm_suspend(struct device *dev) goto Fixup; } + pci_dev->state_saved = false; if (pm->suspend) { pci_power_t prev = pci_dev->current_state; int error; @@ -774,6 +775,7 @@ static int pci_pm_freeze(struct device *dev) return 0; } + pci_dev->state_saved = false; if (pm->freeze) { int error; @@ -862,6 +864,7 @@ static int pci_pm_poweroff(struct device *dev) goto Fixup; } + pci_dev->state_saved = false; if (pm->poweroff) { int error; @@ -987,6 +990,7 @@ static int pci_pm_runtime_suspend(struct device *dev) if (!pm || !pm->runtime_suspend) return -ENOSYS; + pci_dev->state_saved = false; pci_dev->no_d3cold = false; error = pm->runtime_suspend(dev); suspend_report_result(pm->runtime_suspend, error); -- cgit v1.2.3