Add support for drivers to decide bridge D3 policy
Subsystems (4)
cover Add support for drivers to decide bridge D3 policy
The policy for whether PCI bridges are allowed to select D3 is dictated by empirical results that are enumerated into pci_bridge_d3_possible().
In Windows this behaves differently in that Windows internal policy is not used for devices when a power engine plugin driver provided by the SOC vendor is installed. This driver is used to decide the policy in those cases.
This series implements a system that lets drivers register such a policy control as well. It isn't activated for any SOCs by default.
This is heavily leveraged from the work in [1]
[1] https://lore.kernel.org/platform-driver-x86/[email protected]/
Mario Limonciello (4):
ACPI: x86: s2idle: Export symbol for fetching constraints for module
use
PCI: Add support for drivers to decide bridge D3 policy
PCI: Check for changes in pci_bridge_d3_possible() when updating D3 platform/x86/amd: pmc: Add support for using constraints to decide D3
policy
drivers/acpi/x86/s2idle.c | 1 + drivers/pci/pci.c | 148 +++++++++++++++++++++++++++-- drivers/platform/x86/amd/pmc/pmc.c | 59 ++++++++++++ include/linux/pci.h | 54 +++++++++++ 4 files changed, 252 insertions(+), 10 deletions(-)
Signature · 1 line
2.34.1
RFC 1/4 ACPI: x86: s2idle: Export symbol for fetching constraints for module use
The amd-pmc driver will be fetching constraints to make decisions at suspend time. This driver can be compiled as a module, so export the symbol for when it is a module.
--- drivers/acpi/x86/s2idle.c | 1 + 1 file changed, 1 insertion(+)
drivers/acpi/x86/s2idle.c +1 -0
@@ -322,6 +322,7 @@ int acpi_get_lps0_constraint(struct acpi_device *adev)return ACPI_STATE_UNKNOWN ; } +EXPORT_SYMBOL_GPL (acpi_get_lps0_constraint);static void lpi_check_constraints (void ) {
Signature · 1 line
2.34.1
RFC 2/4 PCI: Add support for drivers to decide bridge D3 policy
In reply to Mario Limonciellocommit 9d26d3a8f1b0 ("PCI: Put PCIe ports into D3 during suspend") changed pci_bridge_d3_possible() so that any vendor's PCIe ports from modern machines (>=2015) are allowed to be put into D3.
This policy change has worked for most machines, but the behavior is improved with pcie_port_pm=off on some others.
Add support for drivers to register a callback that they can optionally use to decide the policy on supported machines.
A priority is used so that if multiple drivers register a callback and support deciding for a device the highest priority driver will return the value.
--- drivers/pci/pci.c | 119 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/pci.h | 54 ++++++++++++++++++++ 2 files changed, 173 insertions(+)
drivers/pci/pci.c +119 -0
@@ -21,6 +21,7 @@#include <linux/module.h> #include <linux/spinlock.h> #include <linux/string.h> +#include <linux/list_sort.h> #include <linux/log2.h> #include <linux/logic_pio.h> #include <linux/pm_wakeup.h>
@@ -54,6 +55,8 @@ unsigned int pci_pm_d3hot_delay;static void pci_pme_list_scan (struct work_struct *work);static LIST_HEAD (pci_pme_list); +static LIST_HEAD (d3_possible_list); +static DEFINE_MUTEX (d3_possible_list_mutex);static DEFINE_MUTEX (pci_pme_list_mutex); static DECLARE_DELAYED_WORK(pci_pme_work, pci_pme_list_scan);
@@ -3031,6 +3034,16 @@ bool pci_bridge_d3_possible(struct pci_dev *bridge)if (pci_bridge_d3_force)return true; +/* check for any preferences for the bridge */ +switch (bridge->driver_d3) { +case BRIDGE_PREF_DRIVER_D3 : +return true; +case BRIDGE_PREF_DRIVER_D0 : +return false; +default : +break ; + } +/* Even the oldest 2010 Thunderbolt controller supports D3. */ if (bridge->is_thunderbolt)return true;
@@ -3168,6 +3181,112 @@ void pci_d3cold_disable(struct pci_dev *dev) }EXPORT_SYMBOL_GPL (pci_d3cold_disable); +static struct pci_dev *pci_get_upstream_port (struct pci_dev *pci_dev) +{ +struct pci_dev *bridge; + + bridge =pci_upstream_bridge (pci_dev); +if (!bridge) +return NULL ; + +if (!pci_is_pcie (bridge)) +return NULL ; + +switch (pci_pcie_type (bridge)) { +case PCI_EXP_TYPE_ROOT_PORT : +case PCI_EXP_TYPE_UPSTREAM : +case PCI_EXP_TYPE_DOWNSTREAM : +return bridge; +default : +break ; + }; + +return NULL ; +} + +static void pci_refresh_driver_d3 (void ) +{ +struct pci_d3_driver_ops *driver; +struct pci_dev *pci_dev =NULL ; +struct pci_dev *bridge; + +/* 1st pass: unset any preferences set a previous invocation */ +while ((pci_dev =pci_get_device (PCI_ANY_ID ,PCI_ANY_ID , pci_dev))) { + bridge =pci_get_upstream_port (pci_dev); +if (!bridge) +continue ; + +if (bridge->driver_d3 !=BRIDGE_PREF_UNSET ) + bridge->driver_d3 =BRIDGE_PREF_UNSET ; + } + + pci_dev =NULL ; + +/* 2nd pass: update the preference and refresh bridge_d3 */ +while ((pci_dev =pci_get_device (PCI_ANY_ID ,PCI_ANY_ID , pci_dev))) { + bridge =pci_get_upstream_port (pci_dev); +if (!bridge) +continue ; + +/* don't make multiple passes on the same device */ +if (bridge->driver_d3 !=BRIDGE_PREF_UNSET ) +continue ; + +/* the list is pre-sorted by highest priority */ +mutex_lock (&d3_possible_list_mutex); +list_for_each_entry (driver, &d3_possible_list, list_node) { +/* another higher priority driver already set preference */ +if (bridge->driver_d3 !=BRIDGE_PREF_UNSET ) +break ; +if (!driver->check) +continue ; + bridge->driver_d3 = driver->check (bridge); + } +mutex_unlock (&d3_possible_list_mutex); + +/* no driver set a preference */ +if (bridge->driver_d3 ==BRIDGE_PREF_UNSET ) + bridge->driver_d3 =BRIDGE_PREF_NONE ; + +/* update bridge_d3 */ +pci_bridge_d3_update (pci_dev); + } +} + +static int pci_d3_driver_cmp (void *priv,const struct list_head *_a, +const struct list_head *_b) +{ +struct pci_d3_driver_ops *a =container_of (_a,typeof (*a), list_node); +struct pci_d3_driver_ops *b =container_of (_b,typeof (*b), list_node); + +if (a->priority < b->priority) +return -1 ; +else if (a->priority > b->priority) +return 1 ; +return 0 ; +} + +int pci_register_driver_d3_policy_cb (struct pci_d3_driver_ops *arg) +{ +mutex_lock (&d3_possible_list_mutex); +list_add (&arg->list_node, &d3_possible_list); +list_sort (NULL , &d3_possible_list, pci_d3_driver_cmp); +mutex_unlock (&d3_possible_list_mutex); +pci_refresh_driver_d3 (); +return 0 ; +} +EXPORT_SYMBOL_GPL (pci_register_driver_d3_policy_cb); + +void pci_unregister_driver_d3_policy_cb (struct pci_d3_driver_ops *arg) +{ +mutex_lock (&d3_possible_list_mutex); +list_del (&arg->list_node); +list_sort (NULL , &d3_possible_list, pci_d3_driver_cmp); +mutex_unlock (&d3_possible_list_mutex); +pci_refresh_driver_d3 (); +} +EXPORT_SYMBOL_GPL (pci_unregister_driver_d3_policy_cb); +/** * pci_pm_init - Initialize PM functions of given PCI device * @dev: PCI device to handle.
include/linux/pci.h +54 -0
66 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [RFC v1 2/4] PCI: Add support for drivers to decide bridge D3 policy
Quoted 9 lines · Mario Limonciello
commit
9d26d3a8f1b0("PCI: Put PCIe ports into D3 during suspend") changedpci_bridge_d3_possible()so that any vendor's PCIe ports from modern machines (>=2015) are allowed to be put into D3.This policy change has worked for most machines, but the behavior is improved with
pcie_port_pm=offon some others.Add support for drivers to register a callback that they can optionally use to decide the policy on supported machines.
I would assume that drivers can decide the policy already today through pci_d3cold_enable() / pci_d3cold_disable().
Why is this not sufficient and what's the benefit of the more complex approach proposed here?
Thanks,
Lukas
Re: [RFC v1 2/4] PCI: Add support for drivers to decide bridge D3 policy
Quoted 8 lines · Lukas Wunner
Quoted 7 lines · Mario Limonciello
commit
9d26d3a8f1b0("PCI: Put PCIe ports into D3 during suspend") changedpci_bridge_d3_possible()so that any vendor's PCIe ports from modern machines (>=2015) are allowed to be put into D3.This policy change has worked for most machines, but the behavior is improved with
pcie_port_pm=offon some others.
Quoted 9 lines
Quoted 2 lines
Add support for drivers to register a callback that they can optionally use to decide the policy on supported machines.
I would assume that drivers can decide the policy already today through
pci_d3cold_enable()/pci_d3cold_disable().Why is this not sufficient and what's the benefit of the more complex approach proposed here?
This approach allows multiple drivers to participate. Realistically however I don't know "many" drivers will participate in the first place.
From our earlier conversations on the quirk thread I think your proposal will work as well for this, I'll try it. Thanks.
kernel test robot
build botRe: [RFC v1 2/4] PCI: Add support for drivers to decide bridge D3 policy
In reply to Mario Limonciellokernel test robot noticed the following build warnings:
Hi Mario,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:
[auto build test WARNING on pci/next]
[also build test WARNING on pci/for-linus rafael-pm/linux-next linus/master v6.6-rc6 next-20231020] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Mario-Limonciello/ACPI-x86-s2idle-Export-symbol-for-fetching-constraints-for-module-use/20231010-065942 base: https://git.kernel.org/pub/scm/linux/kernel/git/pci/pci.git next patch link: https://lore.kernel.org/r/20231009225653.36030-3-mario.limonciello%40amd.com patch subject: [RFC v1 2/4] PCI: Add support for drivers to decide bridge D3 policy config: x86_64-randconfig-103-20231023 (https://download.01.org/0day-ci/archive/20231023/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce: (https://download.01.org/0day-ci/archive/20231023/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
cocci warnings: (new ones prefixed by >>)
>> drivers/pci/pci.c:3202:2-3: Unneeded semicolon
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
RFC 3/4 PCI: Check for changes in pci_bridge_d3_possible() when updating D3
In reply to Mario LimoncielloAs drivers can report an optin or veto for a given PCI device it's possible that pci_bridge_d3_possible() reports different values while calling pci_bridge_d3_update(). Take these values into account while updating the ability for a bridge to go into D3.
--- drivers/pci/pci.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-)
drivers/pci/pci.c +19 -10
@@ -3094,6 +3094,14 @@ static int pci_dev_check_d3cold(struct pci_dev *dev, void *data)return !*d3cold_ok; } +static void pci_bridge_d3_propagate (struct pci_dev *bridge,bool d3_ok) +{ +if (bridge->bridge_d3 != d3_ok) { + bridge->bridge_d3 = d3_ok; +pci_bridge_d3_propagate (bridge, d3_ok); + } +} +/* * pci_bridge_d3_update - Update bridge D3 capabilities * @dev: PCI device which is changed
@@ -3106,12 +3114,16 @@ void pci_bridge_d3_update(struct pci_dev *dev) {bool remove = !device_is_registered (&dev->dev);struct pci_dev *bridge; -bool d3cold_ok = true; +bool d3_ok = true; bridge =pci_upstream_bridge (dev); -if (!bridge || !pci_bridge_d3_possible (bridge)) +if (!bridge)return ; +/* Propagate change to upstream bridges */ + d3_ok =pci_bridge_d3_possible (bridge); +pci_bridge_d3_propagate (bridge, d3_ok); +/* * If D3 is currently allowed for the bridge, removing one of its * children won't change that.
@@ -3128,7 +3140,7 @@ void pci_bridge_d3_update(struct pci_dev *dev)* first may allow us to skip checking its siblings. */ if (!remove) -pci_dev_check_d3cold (dev, &d3cold_ok); +pci_dev_check_d3cold (dev, &d3_ok);/* * If D3 is currently not allowed for the bridge, this may be caused
@@ -3136,15 +3148,12 @@ void pci_bridge_d3_update(struct pci_dev *dev)* so we need to go through all children to find out if one of them * continues to block D3. */ -if (d3cold_ok && !bridge->bridge_d3) +if (d3_ok && !bridge->bridge_d3)pci_walk_bus (bridge->subordinate, pci_dev_check_d3cold, - &d3cold_ok); + &d3_ok); -if (bridge->bridge_d3 != d3cold_ok) { - bridge->bridge_d3 = d3cold_ok; -/* Propagate change to upstream bridges */ -pci_bridge_d3_update (bridge); - } +/* Propagate change to upstream bridges */ +pci_bridge_d3_propagate (bridge, d3_ok); }/**
Signature · 1 line
2.34.1
RFC 4/4 platform/x86/amd: pmc: Add support for using constraints to decide D3 policy
In reply to Mario LimoncielloThe default kernel policy will allow modern machines to effectively put all PCIe bridges into PCI D3. This policy doesn't match what Windows uses.
In Windows the driver stack includes a "Power Engine Plugin" (uPEP driver) to decide the policy for integrated devices using PEP device constraints.
Device constraints are expressed as a number in the _DSM of the PNP0D80 device and exported by the kernel in acpi_get_lps0_constraint().
Add support for SoCs to use constraints on Linux as well for deciding target state for integrated PCI bridges.
No SoCs are introduced by default with this change, they will be added later on a case by case basis.
--- drivers/platform/x86/amd/pmc/pmc.c | 59 ++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+)
drivers/platform/x86/amd/pmc/pmc.c +59 -0
@@ -570,6 +570,14 @@ static void amd_pmc_dbgfs_unregister(struct amd_pmc_dev *dev)debugfs_remove_recursive (dev->dbgfs_dir); } +static bool amd_pmc_use_acpi_constraints (struct amd_pmc_dev *dev) +{ +switch (dev->cpu_id) { +default : +return false; + } +} +static bool amd_pmc_is_stb_supported (struct amd_pmc_dev *dev) {switch (dev->cpu_id) {
@@ -741,6 +749,41 @@ static int amd_pmc_czn_wa_irq1(struct amd_pmc_dev *pdev)return 0 ; } +/* +* Constraints are specified in the ACPI LPS0 device and specify what the +* platform intended for the device. +* +* If a constraint is present and >= to ACPI_STATE_S3, then enable D3 for the +* device. +* If a constraint is not present or < ACPI_STATE_S3, then disable D3 for the +* device. +*/ +static enum bridge_d3_pref amd_pmc_d3_check (struct pci_dev *pci_dev) +{ +struct acpi_device *adev =ACPI_COMPANION (&pci_dev->dev); +int constraint; + +if (!adev) +return BRIDGE_PREF_UNSET ; + + constraint =acpi_get_lps0_constraint (adev); +dev_dbg (&pci_dev->dev,"constraint is %d\n" , constraint); + +switch (constraint) { +case ACPI_STATE_UNKNOWN : +case ACPI_STATE_S0 : +case ACPI_STATE_S1 : +case ACPI_STATE_S2 : +return BRIDGE_PREF_DRIVER_D0 ; +case ACPI_STATE_S3 : +return BRIDGE_PREF_DRIVER_D3 ; +default : +break ; + } + +return BRIDGE_PREF_UNSET ; +} +static int amd_pmc_verify_czn_rtc (struct amd_pmc_dev *pdev,u32 *arg) {struct rtc_device *rtc_device;
@@ -881,6 +924,11 @@ static struct acpi_s2idle_dev_ops amd_pmc_s2idle_dev_ops = { .restore = amd_pmc_s2idle_restore, }; +static struct pci_d3_driver_ops amd_pmc_d3_ops = { + .check = amd_pmc_d3_check, + .priority =50 , +}; +static int amd_pmc_suspend_handler (struct device *dev) {struct amd_pmc_dev *pdev =dev_get_drvdata (dev);
@@ -1074,10 +1122,19 @@ static int amd_pmc_probe(struct platform_device *pdev)amd_pmc_quirks_init (dev); } +if (amd_pmc_use_acpi_constraints (dev)) { + err =pci_register_driver_d3_policy_cb (&amd_pmc_d3_ops); +if (err) + goto err_register_lps0; + } +amd_pmc_dbgfs_register (dev);pm_report_max_hw_sleep (U64_MAX );return 0 ; +err_register_lps0: +if (IS_ENABLED (CONFIG_SUSPEND )) +acpi_unregister_lps0_dev (&amd_pmc_s2idle_dev_ops); err_pci_dev_put:pci_dev_put (rdev);return err;
@@ -1089,6 +1146,8 @@ static void amd_pmc_remove(struct platform_device *pdev)if (IS_ENABLED (CONFIG_SUSPEND ))acpi_unregister_lps0_dev (&amd_pmc_s2idle_dev_ops); +if (amd_pmc_use_acpi_constraints (dev)) +pci_unregister_driver_d3_policy_cb (&amd_pmc_d3_ops);amd_pmc_dbgfs_unregister (dev);pci_dev_put (dev->rdev);mutex_destroy (&dev->lock);
Signature · 1 line
2.34.1
Re: [RFC v1 4/4] platform/x86/amd: pmc: Add support for using constraints to decide D3 policy
Hi Mario,
Quoted 60 lines · Mario Limonciello
The default kernel policy will allow modern machines to effectively put all PCIe bridges into PCI D3. This policy doesn't match what Windows uses.
In Windows the driver stack includes a "Power Engine Plugin" (uPEP driver) to decide the policy for integrated devices using PEP device constraints.
Device constraints are expressed as a number in the
_DSMof the PNP0D80 device and exported by the kernel inacpi_get_lps0_constraint().Add support for SoCs to use constraints on Linux as well for deciding target state for integrated PCI bridges.
No SoCs are introduced by default with this change, they will be added later on a case by case basis.
Signed-off-by Mario Limonciello <[email protected]>--- drivers/platform/x86/amd/pmc/pmc.c | 59 ++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+)drivers/platform/x86/amd/pmc/pmc.c +23
-0@@ -570,6 +570,14 @@ static void amd_pmc_dbgfs_unregister(struct amd_pmc_dev *dev)debugfs_remove_recursive (dev->dbgfs_dir); } +static bool amd_pmc_use_acpi_constraints (struct amd_pmc_dev *dev) +{ +switch (dev->cpu_id) { +default : +return false; + } +} +static bool amd_pmc_is_stb_supported (struct amd_pmc_dev *dev) {switch (dev->cpu_id) {@@ -741,6 +749,41 @@ static int amd_pmc_czn_wa_irq1(struct amd_pmc_dev *pdev)return 0 ; } +/* +* Constraints are specified in the ACPI LPS0 device and specify what the +* platform intended for the device. +* +* If a constraint is present and >= to ACPI_STATE_S3, then enable D3 for the +* device. +* If a constraint is not present or < ACPI_STATE_S3, then disable D3 for the +* device. +*/ +static enum bridge_d3_pref amd_pmc_d3_check (struct pci_dev *pci_dev) +{ +struct acpi_device *adev =ACPI_COMPANION (&pci_dev->dev); +int constraint; + +if (!adev)
drivers/platform/x86/amd/pmc/pmc.c static int amd_pmc_czn_wa_irq1(struct amd_pmc_dev *pdev) · line 776
Quoted 10 lines
drivers/platform/x86/amd/pmc/pmc.c +10
-0+return BRIDGE_PREF_UNSET ; + + constraint =acpi_get_lps0_constraint (adev); +dev_dbg (&pci_dev->dev,"constraint is %d\n" , constraint); + +switch (constraint) { +case ACPI_STATE_UNKNOWN : +case ACPI_STATE_S0 : +case ACPI_STATE_S1 : +case ACPI_STATE_S2 :
I believe it's a typo?
I think ACPI_STATE_Dx should be used for device state.
drivers/platform/x86/amd/pmc/pmc.c static int amd_pmc_czn_wa_irq1(struct amd_pmc_dev *pdev) · line 779
Quoted 3 lines
drivers/platform/x86/amd/pmc/pmc.c +3
-0+return BRIDGE_PREF_DRIVER_D0 ; +case ACPI_STATE_S3 : +return BRIDGE_PREF_DRIVER_D3 ;
I've seen both 3 (i.e. ACPI_STATE_D3_HOT) and 4 (i.e. ACPI_STATE_D3_COLD) defined in LPI constraint table. Should those two be treated differently?
Quoted 23 lines
drivers/platform/x86/amd/pmc/pmc.c +12
-0+default : +break ; + } + +return BRIDGE_PREF_UNSET ; +} +static int amd_pmc_verify_czn_rtc (struct amd_pmc_dev *pdev,u32 *arg) {struct rtc_device *rtc_device;@@ -881,6 +924,11 @@ static struct acpi_s2idle_dev_ops amd_pmc_s2idle_dev_ops = { .restore = amd_pmc_s2idle_restore, }; +static struct pci_d3_driver_ops amd_pmc_d3_ops = { + .check = amd_pmc_d3_check, + .priority =50 , +}; +static int amd_pmc_suspend_handler (struct device *dev) {struct amd_pmc_dev *pdev =dev_get_drvdata (dev);
drivers/platform/x86/amd/pmc/pmc.c static int amd_pmc_probe(struct platform_device *pdev) · line 1129
Quoted 8 lines
drivers/platform/x86/amd/pmc/pmc.c +5
-0@@ -1074,10 +1122,19 @@ static int amd_pmc_probe(struct platform_device *pdev)amd_pmc_quirks_init (dev); } +if (amd_pmc_use_acpi_constraints (dev)) { + err =pci_register_driver_d3_policy_cb (&amd_pmc_d3_ops); +if (err) + goto err_register_lps0; + }
Does this only apply to PCI? USB can have ACPI companion too.
Kai-Heng
Quoted 23 lines
drivers/platform/x86/amd/pmc/pmc.c +6
-1+amd_pmc_dbgfs_register (dev);pm_report_max_hw_sleep (U64_MAX );return 0 ; +err_register_lps0: +if (IS_ENABLED (CONFIG_SUSPEND )) +acpi_unregister_lps0_dev (&amd_pmc_s2idle_dev_ops); err_pci_dev_put:pci_dev_put (rdev);return err;@@ -1089,6 +1146,8 @@ static void amd_pmc_remove(struct platform_device *pdev)if (IS_ENABLED (CONFIG_SUSPEND ))acpi_unregister_lps0_dev (&amd_pmc_s2idle_dev_ops); +if (amd_pmc_use_acpi_constraints (dev)) +pci_unregister_driver_d3_policy_cb (&amd_pmc_d3_ops);amd_pmc_dbgfs_unregister (dev);pci_dev_put (dev->rdev);mutex_destroy (&dev->lock); --2.34.1
Re: [RFC v1 4/4] platform/x86/amd: pmc: Add support for using constraints to decide D3 policy
Quoted 69 lines · Kai-Heng Feng
Hi Mario,
Quoted 65 lines · Mario Limonciello
The default kernel policy will allow modern machines to effectively put all PCIe bridges into PCI D3. This policy doesn't match what Windows uses.
In Windows the driver stack includes a "Power Engine Plugin" (uPEP driver) to decide the policy for integrated devices using PEP device constraints.
Device constraints are expressed as a number in the
_DSMof the PNP0D80 device and exported by the kernel inacpi_get_lps0_constraint().Add support for SoCs to use constraints on Linux as well for deciding target state for integrated PCI bridges.
No SoCs are introduced by default with this change, they will be added later on a case by case basis.
Signed-off-by Mario Limonciello <[email protected]>--- drivers/platform/x86/amd/pmc/pmc.c | 59 ++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+)drivers/platform/x86/amd/pmc/pmc.c +28
-0@@ -570,6 +570,14 @@ static void amd_pmc_dbgfs_unregister(struct amd_pmc_dev *dev)debugfs_remove_recursive (dev->dbgfs_dir); } +static bool amd_pmc_use_acpi_constraints (struct amd_pmc_dev *dev) +{ +switch (dev->cpu_id) { +default : +return false; + } +} +static bool amd_pmc_is_stb_supported (struct amd_pmc_dev *dev) {switch (dev->cpu_id) {@@ -741,6 +749,41 @@ static int amd_pmc_czn_wa_irq1(struct amd_pmc_dev *pdev)return 0 ; } +/* +* Constraints are specified in the ACPI LPS0 device and specify what the +* platform intended for the device. +* +* If a constraint is present and >= to ACPI_STATE_S3, then enable D3 for the +* device. +* If a constraint is not present or < ACPI_STATE_S3, then disable D3 for the +* device. +*/ +static enum bridge_d3_pref amd_pmc_d3_check (struct pci_dev *pci_dev) +{ +struct acpi_device *adev =ACPI_COMPANION (&pci_dev->dev); +int constraint; + +if (!adev) +return BRIDGE_PREF_UNSET ; + + constraint =acpi_get_lps0_constraint (adev); +dev_dbg (&pci_dev->dev,"constraint is %d\n" , constraint); +
Quoted 8 lines
drivers/platform/x86/amd/pmc/pmc.c static int amd_pmc_czn_wa_irq1(struct amd_pmc_dev *pdev) · line 776
Quoted 5 lines
drivers/platform/x86/amd/pmc/pmc.c +5
-0+switch (constraint) { +case ACPI_STATE_UNKNOWN : +case ACPI_STATE_S0 : +case ACPI_STATE_S1 : +case ACPI_STATE_S2 :I believe it's a typo?
I thinkACPI_STATE_Dxshould be used for device state.
Yes; typo thanks.
Quoted 8 lines
drivers/platform/x86/amd/pmc/pmc.c static int amd_pmc_czn_wa_irq1(struct amd_pmc_dev *pdev) · line 779
Quoted 4 lines
drivers/platform/x86/amd/pmc/pmc.c +3
-0+return BRIDGE_PREF_DRIVER_D0 ; +case ACPI_STATE_S3 : +return BRIDGE_PREF_DRIVER_D3 ;I've seen both 3 (i.e.
ACPI_STATE_D3_HOT) and 4 (i.e.ACPI_STATE_D3_COLD) defined in LPI constraint table. Should those two be treated differently?
Was this AMD system or Intel system? AFAIK AMD doesn't use D3cold in constraints, they are collectively "D3".
Quoted 27 lines
Quoted 27 lines
drivers/platform/x86/amd/pmc/pmc.c +12
-0+default : +break ; + } + +return BRIDGE_PREF_UNSET ; +} +static int amd_pmc_verify_czn_rtc (struct amd_pmc_dev *pdev,u32 *arg) {struct rtc_device *rtc_device;@@ -881,6 +924,11 @@ static struct acpi_s2idle_dev_ops amd_pmc_s2idle_dev_ops = { .restore = amd_pmc_s2idle_restore, }; +static struct pci_d3_driver_ops amd_pmc_d3_ops = { + .check = amd_pmc_d3_check, + .priority =50 , +}; +static int amd_pmc_suspend_handler (struct device *dev) {struct amd_pmc_dev *pdev =dev_get_drvdata (dev);@@ -1074,10 +1122,19 @@ static int amd_pmc_probe(struct platform_device *pdev)amd_pmc_quirks_init (dev); }
Quoted 7 lines
drivers/platform/x86/amd/pmc/pmc.c static int amd_pmc_probe(struct platform_device *pdev) · line 1129
Quoted 5 lines
drivers/platform/x86/amd/pmc/pmc.c +5
-0+if (amd_pmc_use_acpi_constraints (dev)) { + err =pci_register_driver_d3_policy_cb (&amd_pmc_d3_ops); +if (err) + goto err_register_lps0; + }Does this only apply to PCI? USB can have ACPI companion too.
It only applies to things in the constraints, which is only "SOC internal" devices. No internal USB devices.
Quoted 26 lines
Kai-Heng
Quoted 23 lines
drivers/platform/x86/amd/pmc/pmc.c +6
-1+amd_pmc_dbgfs_register (dev);pm_report_max_hw_sleep (U64_MAX );return 0 ; +err_register_lps0: +if (IS_ENABLED (CONFIG_SUSPEND )) +acpi_unregister_lps0_dev (&amd_pmc_s2idle_dev_ops); err_pci_dev_put:pci_dev_put (rdev);return err;@@ -1089,6 +1146,8 @@ static void amd_pmc_remove(struct platform_device *pdev)if (IS_ENABLED (CONFIG_SUSPEND ))acpi_unregister_lps0_dev (&amd_pmc_s2idle_dev_ops); +if (amd_pmc_use_acpi_constraints (dev)) +pci_unregister_driver_d3_policy_cb (&amd_pmc_d3_ops);amd_pmc_dbgfs_unregister (dev);pci_dev_put (dev->rdev);mutex_destroy (&dev->lock); --2.34.1
Re: [RFC v1 4/4] platform/x86/amd: pmc: Add support for using constraints to decide D3 policy
Quoted 87 lines · Mario Limonciello
Quoted 69 lines · Kai-Heng Feng
Hi Mario,
Quoted 65 lines · Mario Limonciello
The default kernel policy will allow modern machines to effectively put all PCIe bridges into PCI D3. This policy doesn't match what Windows uses.
In Windows the driver stack includes a "Power Engine Plugin" (uPEP driver) to decide the policy for integrated devices using PEP device constraints.
Device constraints are expressed as a number in the
_DSMof the PNP0D80 device and exported by the kernel inacpi_get_lps0_constraint().Add support for SoCs to use constraints on Linux as well for deciding target state for integrated PCI bridges.
No SoCs are introduced by default with this change, they will be added later on a case by case basis.
Signed-off-by Mario Limonciello <[email protected]>--- drivers/platform/x86/amd/pmc/pmc.c | 59 ++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+)drivers/platform/x86/amd/pmc/pmc.c +28
-0@@ -570,6 +570,14 @@ static void amd_pmc_dbgfs_unregister(struct amd_pmc_dev *dev)debugfs_remove_recursive (dev->dbgfs_dir); } +static bool amd_pmc_use_acpi_constraints (struct amd_pmc_dev *dev) +{ +switch (dev->cpu_id) { +default : +return false; + } +} +static bool amd_pmc_is_stb_supported (struct amd_pmc_dev *dev) {switch (dev->cpu_id) {@@ -741,6 +749,41 @@ static int amd_pmc_czn_wa_irq1(struct amd_pmc_dev *pdev)return 0 ; } +/* +* Constraints are specified in the ACPI LPS0 device and specify what the +* platform intended for the device. +* +* If a constraint is present and >= to ACPI_STATE_S3, then enable D3 for the +* device. +* If a constraint is not present or < ACPI_STATE_S3, then disable D3 for the +* device. +*/ +static enum bridge_d3_pref amd_pmc_d3_check (struct pci_dev *pci_dev) +{ +struct acpi_device *adev =ACPI_COMPANION (&pci_dev->dev); +int constraint; + +if (!adev) +return BRIDGE_PREF_UNSET ; + + constraint =acpi_get_lps0_constraint (adev); +dev_dbg (&pci_dev->dev,"constraint is %d\n" , constraint); +Quoted 8 lines
drivers/platform/x86/amd/pmc/pmc.c static int amd_pmc_czn_wa_irq1(struct amd_pmc_dev *pdev) · line 776
Quoted 5 lines
drivers/platform/x86/amd/pmc/pmc.c +5
-0+switch (constraint) { +case ACPI_STATE_UNKNOWN : +case ACPI_STATE_S0 : +case ACPI_STATE_S1 : +case ACPI_STATE_S2 :I believe it's a typo?
I thinkACPI_STATE_Dxshould be used for device state.Yes; typo thanks.
Quoted 5 lines
Quoted 4 lines
drivers/platform/x86/amd/pmc/pmc.c +3
-0+return BRIDGE_PREF_DRIVER_D0 ; +case ACPI_STATE_S3 : +return BRIDGE_PREF_DRIVER_D3 ;
Quoted 6 lines
Quoted 3 lines
I've seen both 3 (i.e.
ACPI_STATE_D3_HOT) and 4 (i.e.ACPI_STATE_D3_COLD) defined in LPI constraint table. Should those two be treated differently?Was this AMD system or Intel system? AFAIK AMD doesn't use D3cold in constraints, they are collectively "D3".
Intel based system.
So the final D3 state is decided by the presence of power resources?
Quoted 36 lines
Quoted 28 lines
Quoted 28 lines
drivers/platform/x86/amd/pmc/pmc.c +12
-0+default : +break ; + } + +return BRIDGE_PREF_UNSET ; +} +static int amd_pmc_verify_czn_rtc (struct amd_pmc_dev *pdev,u32 *arg) {struct rtc_device *rtc_device;@@ -881,6 +924,11 @@ static struct acpi_s2idle_dev_ops amd_pmc_s2idle_dev_ops = { .restore = amd_pmc_s2idle_restore, }; +static struct pci_d3_driver_ops amd_pmc_d3_ops = { + .check = amd_pmc_d3_check, + .priority =50 , +}; +static int amd_pmc_suspend_handler (struct device *dev) {struct amd_pmc_dev *pdev =dev_get_drvdata (dev);@@ -1074,10 +1122,19 @@ static int amd_pmc_probe(struct platform_device *pdev)amd_pmc_quirks_init (dev); }Quoted 7 lines
drivers/platform/x86/amd/pmc/pmc.c static int amd_pmc_probe(struct platform_device *pdev) · line 1129
Quoted 5 lines
drivers/platform/x86/amd/pmc/pmc.c +5
-0+if (amd_pmc_use_acpi_constraints (dev)) { + err =pci_register_driver_d3_policy_cb (&amd_pmc_d3_ops); +if (err) + goto err_register_lps0; + }Does this only apply to PCI? USB can have ACPI companion too.
Quoted 2 lines
It only applies to things in the constraints, which is only "SOC internal" devices. No internal USB devices.
So sounds like it only applies to PCI devices?
Kai-Heng
Quoted 28 lines
Quoted 27 lines
Kai-Heng
Quoted 23 lines
drivers/platform/x86/amd/pmc/pmc.c +6
-1+amd_pmc_dbgfs_register (dev);pm_report_max_hw_sleep (U64_MAX );return 0 ; +err_register_lps0: +if (IS_ENABLED (CONFIG_SUSPEND )) +acpi_unregister_lps0_dev (&amd_pmc_s2idle_dev_ops); err_pci_dev_put:pci_dev_put (rdev);return err;@@ -1089,6 +1146,8 @@ static void amd_pmc_remove(struct platform_device *pdev)if (IS_ENABLED (CONFIG_SUSPEND ))acpi_unregister_lps0_dev (&amd_pmc_s2idle_dev_ops); +if (amd_pmc_use_acpi_constraints (dev)) +pci_unregister_driver_d3_policy_cb (&amd_pmc_d3_ops);amd_pmc_dbgfs_unregister (dev);pci_dev_put (dev->rdev);mutex_destroy (&dev->lock); --2.34.1
Re: [RFC v1 4/4] platform/x86/amd: pmc: Add support for using constraints to decide D3 policy
Quoted 11 lines
Quoted 6 lines
Quoted 3 lines
I've seen both 3 (i.e.
ACPI_STATE_D3_HOT) and 4 (i.e.ACPI_STATE_D3_COLD) defined in LPI constraint table. Should those two be treated differently?Was this AMD system or Intel system? AFAIK AMD doesn't use D3cold in constraints, they are collectively "D3".
Intel based system.
So the final D3 state is decided by the presence of power resources?
Right. This is why I've mentioned in some of my series that pci_d3cold_enable() / pci_d3cold_disable() are misnamed and dev->no_d3cold can be misleading.
FYI - I have (slowly) been modifying this series to use pci_d3_cold_enable()/pci_d3_cold_disable() instead of the extra overhead of the policy decision but I have some problems.
I anticipate future version will also modify pci_bridge_d3_update().
Quoted 36 lines
Quoted 36 lines
Quoted 35 lines
Quoted 25 lines
drivers/platform/x86/amd/pmc/pmc.c +12
-0+default : +break ; + } + +return BRIDGE_PREF_UNSET ; +} +static int amd_pmc_verify_czn_rtc (struct amd_pmc_dev *pdev,u32 *arg) {struct rtc_device *rtc_device;@@ -881,6 +924,11 @@ static struct acpi_s2idle_dev_ops amd_pmc_s2idle_dev_ops = { .restore = amd_pmc_s2idle_restore, }; +static struct pci_d3_driver_ops amd_pmc_d3_ops = { + .check = amd_pmc_d3_check, + .priority =50 , +}; +static int amd_pmc_suspend_handler (struct device *dev) {struct amd_pmc_dev *pdev =dev_get_drvdata (dev);drivers/platform/x86/amd/pmc/pmc.c static int amd_pmc_probe(struct platform_device *pdev) · line 1129
Quoted 8 lines
drivers/platform/x86/amd/pmc/pmc.c +5
-0@@ -1074,10 +1122,19 @@ static int amd_pmc_probe(struct platform_device *pdev)amd_pmc_quirks_init (dev); } +if (amd_pmc_use_acpi_constraints (dev)) { + err =pci_register_driver_d3_policy_cb (&amd_pmc_d3_ops); +if (err) + goto err_register_lps0; + }Does this only apply to PCI? USB can have ACPI companion too.
Quoted 4 lines
Quoted 2 lines
It only applies to things in the constraints, which is only "SOC internal" devices. No internal USB devices.
So sounds like it only applies to PCI devices?
Correct.
Quoted 31 lines
Kai-Heng
Quoted 28 lines
Quoted 27 lines
Kai-Heng
Quoted 23 lines
drivers/platform/x86/amd/pmc/pmc.c +6
-1+amd_pmc_dbgfs_register (dev);pm_report_max_hw_sleep (U64_MAX );return 0 ; +err_register_lps0: +if (IS_ENABLED (CONFIG_SUSPEND )) +acpi_unregister_lps0_dev (&amd_pmc_s2idle_dev_ops); err_pci_dev_put:pci_dev_put (rdev);return err;@@ -1089,6 +1146,8 @@ static void amd_pmc_remove(struct platform_device *pdev)if (IS_ENABLED (CONFIG_SUSPEND ))acpi_unregister_lps0_dev (&amd_pmc_s2idle_dev_ops); +if (amd_pmc_use_acpi_constraints (dev)) +pci_unregister_driver_d3_policy_cb (&amd_pmc_d3_ops);amd_pmc_dbgfs_unregister (dev);pci_dev_put (dev->rdev);mutex_destroy (&dev->lock); --2.34.1