PCI: Add save/restore of Precision Time Measurement capability
PATCH 1/2 PCI: Add save/restore of Precision Time Measurement capability
The PCI subsystem does not currently save and restore the configuration space for the Precision Time Measurement (PTM) PCIe extended capability leading to the feature returning disabled on S3 resume. This has been observed on Intel Coffee Lake desktops. Add save/restore of the PTM control register. This saves the PTM Enable, Root Select, and Effective Granularity bits.
--- drivers/pci/pci.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)
drivers/pci/pci.c +44 -0
@@ -1539,6 +1539,44 @@ static void pci_restore_ltr_state(struct pci_dev *dev)pci_write_config_word (dev, ltr +PCI_LTR_MAX_NOSNOOP_LAT , *cap++); } +static void pci_save_ptm_state (struct pci_dev *dev) +{ +int ptm; +struct pci_cap_saved_state *save_state; +u16 *cap; + +if (!pci_is_pcie (dev)) +return ; + + ptm =pci_find_ext_capability (dev,PCI_EXT_CAP_ID_PTM ); +if (!ptm) +return ; + + save_state =pci_find_saved_ext_cap (dev,PCI_EXT_CAP_ID_PTM ); +if (!save_state) { +pci_err (dev,"no suspend buffer for PTM\n" ); +return ; + } + + cap = (u16 *)&save_state->cap.data[0 ]; +pci_read_config_word (dev, ptm +PCI_PTM_CTRL , cap); +} + +static void pci_restore_ptm_state (struct pci_dev *dev) +{ +struct pci_cap_saved_state *save_state; +int ptm; +u16 *cap; + + save_state =pci_find_saved_ext_cap (dev,PCI_EXT_CAP_ID_PTM ); + ptm =pci_find_ext_capability (dev,PCI_EXT_CAP_ID_PTM ); +if (!save_state || !ptm) +return ; + + cap = (u16 *)&save_state->cap.data[0 ]; +pci_write_config_word (dev, ptm +PCI_PTM_CTRL , *cap); +} +/** * pci_save_state - save the PCI configuration space of a device before * suspending
@@ -1566,6 +1604,7 @@ int pci_save_state(struct pci_dev *dev)pci_save_ltr_state (dev);pci_save_dpc_state (dev);pci_save_aer_state (dev); +pci_save_ptm_state (dev);return pci_save_vc_state (dev); }EXPORT_SYMBOL (pci_save_state);
@@ -1677,6 +1716,7 @@ void pci_restore_state(struct pci_dev *dev)pci_restore_vc_state (dev);pci_restore_rebar_state (dev);pci_restore_dpc_state (dev); +pci_restore_ptm_state (dev);pci_aer_clear_status (dev);pci_restore_aer_state (dev);
@@ -3332,6 +3372,10 @@ void pci_allocate_cap_save_buffers(struct pci_dev *dev)if (error)pci_err (dev,"unable to allocate suspend buffer for LTR\n" ); + error =pci_add_ext_cap_save_buffer (dev,PCI_EXT_CAP_ID_PTM ,sizeof (u16)); +if (error) +pci_err (dev,"unable to allocate suspend buffer for PTM\n" ); +pci_allocate_vc_save_buffers (dev); }
Signature · 1 line
2.20.1
PATCH 2/2 PCI: Disable Precision Time Measurement during suspend
On Intel client platforms that support suspend-to-idle, like Ice Lake, root ports that have Precision Time Management (PTM) enabled can prevent the port from being fully power gated, causing higher power consumption while suspended. To prevent this, after saving the PTM control register, disable the feature. The feature will be returned to its previous state during restore.
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=209361
--- drivers/pci/pci.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/pci/pci.c +13 -1
@@ -21,6 +21,7 @@#include <linux/module.h> #include <linux/spinlock.h> #include <linux/string.h> +#include <linux/suspend.h> #include <linux/log2.h> #include <linux/logic_pio.h> #include <linux/pm_wakeup.h>
@@ -1543,7 +1544,7 @@ static void pci_save_ptm_state(struct pci_dev *dev) {int ptm;struct pci_cap_saved_state *save_state; -u16 *cap; +u16 *cap, ctrl;if (!pci_is_pcie (dev))return ;
@@ -1560,6 +1561,17 @@ static void pci_save_ptm_state(struct pci_dev *dev) cap = (u16 *)&save_state->cap.data[0 ];pci_read_config_word (dev, ptm +PCI_PTM_CTRL , cap); + +/* +* On Intel systems that support suspend-to-idle, additional +* power savings can be gained by disabling PTM on root ports, +* as this allows the port to enter a deeper pm state. +*/ +if (pm_suspend_target_state ==PM_SUSPEND_TO_IDLE && +pci_pcie_type (dev) ==PCI_EXP_TYPE_ROOT_PORT ) { + ctrl = *cap & ~(PCI_PTM_CTRL_ENABLE |PCI_PTM_CTRL_ROOT ); +pci_write_config_word (dev, ptm +PCI_PTM_CTRL , ctrl); + } }static void pci_restore_ptm_state (struct pci_dev *dev)
Signature · 1 line
2.20.1
Re: [PATCH 2/2] PCI: Disable Precision Time Measurement during suspend
Quoted 38 lines · David E. Box
On Intel client platforms that support suspend-to-idle, like Ice Lake, root ports that have Precision Time Management (PTM) enabled can prevent the port from being fully power gated, causing higher power consumption while suspended. To prevent this, after saving the PTM control register, disable the feature. The feature will be returned to its previous state during restore.
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=209361
Reported-by Len Brown <[email protected]>Suggested-by Rafael J. Wysocki <[email protected]>Signed-off-by David E. Box <[email protected]>--- drivers/pci/pci.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)drivers/pci/pci.c +2
-1@@ -21,6 +21,7 @@#include <linux/module.h> #include <linux/spinlock.h> #include <linux/string.h> +#include <linux/suspend.h> #include <linux/log2.h> #include <linux/logic_pio.h> #include <linux/pm_wakeup.h> @@ -1543,7 +1544,7 @@ static void pci_save_ptm_state(struct pci_dev *dev) {int ptm;struct pci_cap_saved_state *save_state; -u16 *cap; +u16 *cap, ctrl;if (!pci_is_pcie (dev))return ;
drivers/pci/pci.c static void pci_save_ptm_state(struct pci_dev *dev) · line 1568
Quoted 8 lines
drivers/pci/pci.c +5
-0@@ -1560,6 +1561,17 @@ static void pci_save_ptm_state(struct pci_dev *dev) cap = (u16 *)&save_state->cap.data[0 ];pci_read_config_word (dev, ptm +PCI_PTM_CTRL , cap); + +/* +* On Intel systems that support suspend-to-idle, additional +* power savings can be gained by disabling PTM on root ports, +* as this allows the port to enter a deeper pm state.
I would say "There are systems (for example, ...) where the power drawn while suspended can be significantly reduced by disabling PTM on PCIe root ports, as this allows the port to enter a lower-power PM state and the SoC to reach a lower-power idle state as a whole".
drivers/pci/pci.c static void pci_save_ptm_state(struct pci_dev *dev) · line 1570
Quoted 2 lines
drivers/pci/pci.c +2
-0+*/ + if (pm_suspend_target_state == PM_SUSPEND_TO_IDLE &&
AFAICS the target sleep state doesn't matter here, so I'd skip the check above, but otherwise it LGTM.
Quoted 8 lines
drivers/pci/pci.c +4
-1+ pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT) { + ctrl = *cap & ~(PCI_PTM_CTRL_ENABLE |PCI_PTM_CTRL_ROOT ); +pci_write_config_word (dev, ptm +PCI_PTM_CTRL , ctrl); + } }static void pci_restore_ptm_state (struct pci_dev *dev) --
Re: [PATCH 2/2] PCI: Disable Precision Time Measurement during suspend
Quoted 47 lines · Rafael J. Wysocki
Quoted 45 lines · David E. Box
On Intel client platforms that support suspend-to-idle, like Ice Lake,
root ports that have Precision Time Management (PTM) enabled can prevent
the port from being fully power gated, causing higher power consumption
while suspended. To prevent this, after saving the PTM control register,
disable the feature. The feature will be returned to its previous state
during restore.Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=209361
Reported-by Len Brown <[email protected]>Suggested-by Rafael J. Wysocki <[email protected]>Signed-off-by David E. Box <[email protected]>--- drivers/pci/pci.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)drivers/pci/pci.c +2
-1@@ -21,6 +21,7 @@#include <linux/module.h> #include <linux/spinlock.h> #include <linux/string.h> +#include <linux/suspend.h> #include <linux/log2.h> #include <linux/logic_pio.h> #include <linux/pm_wakeup.h> @@ -1543,7 +1544,7 @@ static void pci_save_ptm_state(struct pci_dev *dev) {int ptm;struct pci_cap_saved_state *save_state; -u16 *cap; +u16 *cap, ctrl;if (!pci_is_pcie (dev))return;drivers/pci/pci.c +0
-0@@ -1560,6 +1561,17 @@ static void pci_save_ptm_state(struct pci_dev *dev)
Quoted 15 lines
Quoted 9 lines
drivers/pci/pci.c +3
-0cap = (u16 *)&save_state->cap.data[0 ];pci_read_config_word (dev, ptm +PCI_PTM_CTRL , cap); + +/* +* On Intel systems that support suspend-to-idle, additional
+ * power savings can be gained by disabling PTM on root
ports,
+ * as this allows the port to enter a deeper pm state.I would say "There are systems (for example, ...) where the power drawn while suspended can be significantly reduced by disabling PTM on
PCIe root ports, as this allows the port to enter a lower-power PM state and the SoC to reach a lower-power idle state as a whole".
Okay.
Quoted 6 lines
drivers/pci/pci.c static void pci_save_ptm_state(struct pci_dev *dev) · line 1570
Quoted 3 lines
drivers/pci/pci.c +2
-0+*/ + if (pm_suspend_target_state == PM_SUSPEND_TO_IDLE &&AFAICS the target sleep state doesn't matter here, so I'd skip the check above, but otherwise it LGTM.
The target sleep state doesn't matter so much but that it's suspending does. pci_save_state() is called during probe for the root ports (and many other pci devices - I'm curious as to why). So without this check the capability gets disabled on boot.
Quoted 11 lines
Quoted 11 lines
drivers/pci/pci.c +2
-0+ pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT) { + ctrl = *cap & ~(PCI_PTM_CTRL_ENABLE |
PCI_PTM_CTRL_ROOT);
+ pci_write_config_word(dev, ptm +PCI_PTM_CTRL,
ctrl);
+ }
}static void
pci_restore_ptm_state(struct pci_dev *dev)
--
David
Re: [PATCH 2/2] PCI: Disable Precision Time Measurement during suspend
Quoted 71 lines · David E. Box
Quoted 47 lines · Rafael J. Wysocki
Quoted 45 lines · David E. Box
On Intel client platforms that support suspend-to-idle, like Ice Lake,
root ports that have Precision Time Management (PTM) enabled can prevent
the port from being fully power gated, causing higher power consumption
while suspended. To prevent this, after saving the PTM control register,
disable the feature. The feature will be returned to its previous state
during restore.Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=209361
Reported-by Len Brown <[email protected]>Suggested-by Rafael J. Wysocki <[email protected]>Signed-off-by David E. Box <[email protected]>--- drivers/pci/pci.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)drivers/pci/pci.c +2
-1@@ -21,6 +21,7 @@#include <linux/module.h> #include <linux/spinlock.h> #include <linux/string.h> +#include <linux/suspend.h> #include <linux/log2.h> #include <linux/logic_pio.h> #include <linux/pm_wakeup.h> @@ -1543,7 +1544,7 @@ static void pci_save_ptm_state(struct pci_dev *dev) {int ptm;struct pci_cap_saved_state *save_state; -u16 *cap; +u16 *cap, ctrl;if (!pci_is_pcie (dev))return;drivers/pci/pci.c +0
-0@@ -1560,6 +1561,17 @@ static void pci_save_ptm_state(struct pci_dev *dev)Quoted 15 lines
Quoted 9 lines
drivers/pci/pci.c +3
-0cap = (u16 *)&save_state->cap.data[0 ];pci_read_config_word (dev, ptm +PCI_PTM_CTRL , cap); + +/* +* On Intel systems that support suspend-to-idle, additional
+ * power savings can be gained by disabling PTM on root
ports,
+ * as this allows the port to enter a deeper pm state.I would say "There are systems (for example, ...) where the power drawn while suspended can be significantly reduced by disabling PTM on
PCIe root ports, as this allows the port to enter a lower-power PM state and the SoC to reach a lower-power idle state as a whole".Okay.
Quoted 4 lines
Quoted 3 lines
drivers/pci/pci.c +2
-0+*/ + if (pm_suspend_target_state == PM_SUSPEND_TO_IDLE &&
Quoted 6 lines
Quoted 2 lines
AFAICS the target sleep state doesn't matter here, so I'd skip the check above, but otherwise it LGTM.
The target sleep state doesn't matter so much but that it's suspending does.
pci_save_state()is called during probe for the root ports (and many other pci devices - I'm curious as to why).
I tend to forget about this, sorry.
Quoted 2 lines
So without this check the capability gets disabled on boot.
So instead of calling this from here, why don't we invoke the code below from pci_prepare_to_sleep() and pci_finish_runtime_suspend(), before enabling wakeup (and it needs to be re-done on failures, eg. by restoring the cap from the saved copy)?
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/pci/pci.c +2
-0+ pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT) { + ctrl = *cap & ~(PCI_PTM_CTRL_ENABLE |
PCI_PTM_CTRL_ROOT);
+ pci_write_config_word(dev, ptm +PCI_PTM_CTRL,
ctrl);
+ }
}static void
pci_restore_ptm_state(struct pci_dev *dev)
--
Re: [PATCH 2/2] PCI: Disable Precision Time Measurement during suspend
Quoted 5 lines · Rafael J. Wysocki
Quoted 3 lines · David E. Box
Quoted 2 lines · Rafael J. Wysocki
On Thu, Nov 19, 2020 at 1:17 AM David E. Box
<[email protected]> wrote:
...
Quoted 16 lines
Quoted 8 lines
Quoted 7 lines
drivers/pci/pci.c static void pci_save_ptm_state(struct pci_dev *dev) · line 1570
Quoted 3 lines
drivers/pci/pci.c +2
-0+*/ + if (pm_suspend_target_state == PM_SUSPEND_TO_IDLE &&AFAICS the target sleep state doesn't matter here, so I'd skip the
check above, but otherwise it LGTM.Quoted 5 lines
The target sleep state doesn't matter so much but that it's suspending
does.pci_save_state()is called during probe for the root ports (and
many other pci devices - I'm curious as to why).I tend to forget about this, sorry.
Quoted 8 lines
Quoted 2 lines
So without this check the capability gets disabled on boot.
So instead of calling this from here, why don't we invoke the code below from
pci_prepare_to_sleep()andpci_finish_runtime_suspend(), before enabling wakeup (and it needs to be re-done on failures, eg. by
restoring the cap from the saved copy)?
Ok.