Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Revert "PCI: PM: Do not read power state in pci_enable_device_flags()"

Revert commit 4514d991d992 ("PCI: PM: Do not read power state in
pci_enable_device_flags()") that is reported to cause PCI device
initialization issues on some systems.

BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=213481
Link: https://lore.kernel.org/linux-acpi/YNDoGICcg0V8HhpQ@eldamar.lan
Reported-by: Michael <phyre@rogers.com>
Reported-by: Salvatore Bonaccorso <carnil@debian.org>
Fixes: 4514d991d992 ("PCI: PM: Do not read power state in pci_enable_device_flags()")
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

+13 -3
+13 -3
drivers/pci/pci.c
··· 1900 1900 int err; 1901 1901 int i, bars = 0; 1902 1902 1903 - if (atomic_inc_return(&dev->enable_cnt) > 1) { 1904 - pci_update_current_state(dev, dev->current_state); 1905 - return 0; /* already enabled */ 1903 + /* 1904 + * Power state could be unknown at this point, either due to a fresh 1905 + * boot or a device removal call. So get the current power state 1906 + * so that things like MSI message writing will behave as expected 1907 + * (e.g. if the device really is in D0 at enable time). 1908 + */ 1909 + if (dev->pm_cap) { 1910 + u16 pmcsr; 1911 + pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr); 1912 + dev->current_state = (pmcsr & PCI_PM_CTRL_STATE_MASK); 1906 1913 } 1914 + 1915 + if (atomic_inc_return(&dev->enable_cnt) > 1) 1916 + return 0; /* already enabled */ 1907 1917 1908 1918 bridge = pci_upstream_bridge(dev); 1909 1919 if (bridge)