ACPI / x86: Add support for LPS0 callback handler
Subsystems (2)
PATCH v5 1/4 ACPI / x86: Add support for LPS0 callback handler
Currenty the latest thing run during a suspend to idle attempt is the LPS0 prepare_late callback and the earliest thing is the resume_early callback.
There is a desire for the amd-pmc driver to suspend later in the suspend process (ideally the very last thing), so create a callback that it or any other driver can hook into to do this.
---
changes from v4->v5:
* fix a check for handler->prepare
Reported by Dan Carpenter <[email protected]>
changes from v3->v4:
* drop use of mutex, use lock_system_sleep instead
* don't pass argument of context, driver will maintain this internally
* don't allow failing prepare stage
* don't allow unregistering if sleep_no_lps0 is set
changes from v2->v3:
* Check that callbacks exist before calling
changes from v1->v2:
* Change register/unregister arguments to be struct
drivers/acpi/x86/s2idle.c | 40 +++++++++++++++++++++++++++++++++++++++ include/linux/acpi.h | 10 +++++++++- 2 files changed, 49 insertions(+), 1 deletion(-)
drivers/acpi/x86/s2idle.c +40 -0
@@ -86,6 +86,8 @@ struct lpi_device_constraint_amd {int min_dstate; }; +static LIST_HEAD (lps0_s2idle_devops_head); +static struct lpi_constraints *lpi_constraints_table;static int lpi_constraints_table_size;static int rev_id;
@@ -444,6 +446,8 @@ static struct acpi_scan_handler lps0_handler = {int acpi_s2idle_prepare_late (void ) { +struct acpi_s2idle_dev_ops *handler; +if (!lps0_device_handle || sleep_no_lps0)return 0 ;
@@ -474,14 +478,26 @@ int acpi_s2idle_prepare_late(void)acpi_sleep_run_lps0_dsm (ACPI_LPS0_MS_ENTRY , lps0_dsm_func_mask_microsoft, lps0_dsm_guid_microsoft); } + +list_for_each_entry (handler, &lps0_s2idle_devops_head, list_node) { +if (handler->prepare) + handler->prepare (); + } +return 0 ; }void acpi_s2idle_restore_early (void ) { +struct acpi_s2idle_dev_ops *handler; +if (!lps0_device_handle || sleep_no_lps0)return ; +list_for_each_entry (handler, &lps0_s2idle_devops_head, list_node) +if (handler->restore) + handler->restore (); +/* Modern standby exit */ if (lps0_dsm_func_mask_microsoft >0 ) acpi_sleep_run_lps0_dsm(ACPI_LPS0_MS_EXIT,
@@ -524,4 +540,28 @@ void acpi_s2idle_setup(void) s2idle_set_ops(&acpi_s2idle_ops_lps0); } +int acpi_register_lps0_dev (struct acpi_s2idle_dev_ops *arg) +{ +if (!lps0_device_handle || sleep_no_lps0) +return -ENODEV ; + +lock_system_sleep (); +list_add (&arg->list_node, &lps0_s2idle_devops_head); +unlock_system_sleep (); + +return 0 ; +} +EXPORT_SYMBOL_GPL (acpi_register_lps0_dev); + +void acpi_unregister_lps0_dev (struct acpi_s2idle_dev_ops *arg) +{ +if (!lps0_device_handle || sleep_no_lps0) +return ; + +lock_system_sleep (); +list_del (&arg->list_node); +unlock_system_sleep (); +} +EXPORT_SYMBOL_GPL (acpi_unregister_lps0_dev); +#endif /* CONFIG_SUSPEND */
include/linux/acpi.h +9 -1
@@ -1023,7 +1023,15 @@ void acpi_os_set_prepare_extended_sleep(int (*func)(u8 sleep_state,acpi_status acpi_os_prepare_extended_sleep (u8 sleep_state,u32 val_a,u32 val_b); - +#ifdef CONFIG_X86 +struct acpi_s2idle_dev_ops { +struct list_head list_node; +void (*prepare)(void ); +void (*restore)(void ); +}; +int acpi_register_lps0_dev (struct acpi_s2idle_dev_ops *arg); +void acpi_unregister_lps0_dev (struct acpi_s2idle_dev_ops *arg); +#endif /* CONFIG_X86 */ #ifndef CONFIG_IA64 void arch_reserve_mem_area (acpi_physical_address addr,size_t size);#else
Signature · 1 line
2.34.1
PATCH v5 2/4 platform/x86: amd-pmc: Move to later in the suspend process
The OS_HINT message is supposed to indicate that everything else that is supposed to go into the deepest state has done so.
This assumption is invalid as:
1) The CPUs will still go in and out of the deepest state
2) Other devices may still run their noirq suspend routines
3) The LPS0 ACPI device will still run
To more closely mirror how this works on other operating systems, move the amd-pmc suspend to the very last thing before the s2idle loop via an lps0 callback.
---
changes from v4->v5:
* split into two patches
changes from v3->v4:
* Drop constraints messaging
* Adjust for changes on earlier patches
* Don't fail init if sleep_no_lps0 is set
changes from v2->v3:
* no changes
changes from v1->v2:
* adjust for changes in previous patches
* display a debugging message for constraints
drivers/platform/x86/amd-pmc.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-)
drivers/platform/x86/amd-pmc.c +15 -15
@@ -639,9 +639,9 @@ static int amd_pmc_verify_czn_rtc(struct amd_pmc_dev *pdev, u32 *arg)return rc; } -static int __maybe_unused amd_pmc_suspend (struct device *dev) +static void amd_pmc_s2idle_prepare (void ) { -struct amd_pmc_dev *pdev =dev_get_drvdata (dev); +struct amd_pmc_dev *pdev = &pmc;int rc;u8 msg;u32 arg =1 ;
@@ -658,7 +658,7 @@ static int __maybe_unused amd_pmc_suspend(struct device *dev) }/* Dump the IdleMask before we send hint to SMU */ -amd_pmc_idlemask_read (pdev, dev,NULL ); +amd_pmc_idlemask_read (pdev, pdev->dev,NULL ); msg =amd_pmc_get_os_hint (pdev); rc =amd_pmc_send_cmd (pdev, arg,NULL , msg,0 );if (rc) {
@@ -672,18 +672,16 @@ static int __maybe_unused amd_pmc_suspend(struct device *dev)dev_err (pdev->dev,"error writing to STB\n" ); goto fail; } - -return 0 ; +return ; fail:if (pdev->cpu_id ==AMD_CPU_ID_CZN )cpu_latency_qos_update_request (&pdev->amd_pmc_pm_qos_req,PM_QOS_DEFAULT_VALUE ); -return rc; } -static int __maybe_unused amd_pmc_resume (struct device *dev) +static void amd_pmc_s2idle_restore (void ) { -struct amd_pmc_dev *pdev =dev_get_drvdata (dev); +struct amd_pmc_dev *pdev = &pmc;int rc;u8 msg;
@@ -696,7 +694,7 @@ static int __maybe_unused amd_pmc_resume(struct device *dev)amd_pmc_send_cmd (pdev,0 ,NULL ,SMU_MSG_LOG_DUMP_DATA ,0 );/* Dump the IdleMask to see the blockers */ -amd_pmc_idlemask_read (pdev, dev,NULL ); +amd_pmc_idlemask_read (pdev, pdev->dev,NULL );/* Write data incremented by 1 to distinguish in stb_read */ if (enable_stb)
@@ -711,13 +709,11 @@ static int __maybe_unused amd_pmc_resume(struct device *dev)/* Notify on failed entry */ amd_pmc_validate_deepest (pdev); - -return rc; } -static const struct dev_pm_ops amd_pmc_pm_ops = { - .suspend_noirq = amd_pmc_suspend, - .resume_noirq = amd_pmc_resume, +static struct acpi_s2idle_dev_ops amd_pmc_s2idle_dev_ops = { + .prepare = amd_pmc_s2idle_prepare, + .restore = amd_pmc_s2idle_restore, };static const struct pci_device_id pmc_pci_ids[] = {
@@ -884,6 +880,10 @@ static int amd_pmc_probe(struct platform_device *pdev)amd_pmc_get_smu_version (dev);platform_set_drvdata (pdev, dev); + err =acpi_register_lps0_dev (&amd_pmc_s2idle_dev_ops); +if (err) +dev_warn (dev->dev,"failed to register LPS0 sleep handler, expect increased power consumption\n" ); +amd_pmc_dbgfs_register (dev);cpu_latency_qos_add_request (&dev->amd_pmc_pm_qos_req,PM_QOS_DEFAULT_VALUE );return 0 ;
@@ -897,6 +897,7 @@ static int amd_pmc_remove(struct platform_device *pdev) {struct amd_pmc_dev *dev =platform_get_drvdata (pdev); +acpi_unregister_lps0_dev (&amd_pmc_s2idle_dev_ops);amd_pmc_dbgfs_unregister (dev);pci_dev_put (dev->rdev);mutex_destroy (&dev->lock);
@@ -917,7 +918,6 @@ static struct platform_driver amd_pmc_driver = { .driver = { .name = "amd_pmc", .acpi_match_table = amd_pmc_acpi_ids, - .pm = &amd_pmc_pm_ops, }, .probe = amd_pmc_probe, .remove = amd_pmc_remove,
Signature · 1 line
2.34.1
PATCH v5 3/4 platform/x86: amd-pmc: Output error codes in messages
In reply to Mario LimoncielloThe return type for the s2idle callbacks is 'void', so any errors that occur will no longer be displayed.
Output these error codes in the messages in case of any failures.
---
changes from v4->v5:
* split from previous patch
drivers/platform/x86/amd-pmc.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/platform/x86/amd-pmc.c +7 -5
@@ -653,8 +653,10 @@ static void amd_pmc_s2idle_prepare(void)/* Activate CZN specific RTC functionality */ if (pdev->cpu_id ==AMD_CPU_ID_CZN ) { rc =amd_pmc_verify_czn_rtc (pdev, &arg); -if (rc) +if (rc) { +dev_err (pdev->dev,"failed to set RTC: %d\n" , rc); goto fail; + } }/* Dump the IdleMask before we send hint to SMU */
@@ -662,14 +664,14 @@ static void amd_pmc_s2idle_prepare(void) msg =amd_pmc_get_os_hint (pdev); rc =amd_pmc_send_cmd (pdev, arg,NULL , msg,0 );if (rc) { -dev_err (pdev->dev,"suspend failed\n" ); +dev_err (pdev->dev,"suspend failed: %d\n" , rc); goto fail; }if (enable_stb) rc =amd_pmc_write_stb (pdev,AMD_PMC_STB_PREDEF );if (rc) { -dev_err (pdev->dev,"error writing to STB\n" ); +dev_err (pdev->dev,"error writing to STB: %d\n" , rc); goto fail; }return ;
@@ -688,7 +690,7 @@ static void amd_pmc_s2idle_restore(void) msg =amd_pmc_get_os_hint (pdev); rc =amd_pmc_send_cmd (pdev,0 ,NULL , msg,0 );if (rc) -dev_err (pdev->dev,"resume failed\n" ); +dev_err (pdev->dev,"resume failed: %d\n" , rc);/* Let SMU know that we are looking for stats */ amd_pmc_send_cmd (pdev,0 ,NULL ,SMU_MSG_LOG_DUMP_DATA ,0 );
@@ -700,7 +702,7 @@ static void amd_pmc_s2idle_restore(void)if (enable_stb) rc =amd_pmc_write_stb (pdev,AMD_PMC_STB_PREDEF +1 );if (rc) -dev_err (pdev->dev,"error writing to STB\n" ); +dev_err (pdev->dev,"error writing to STB: %d\n" , rc);/* Restore the QoS request back to defaults if it was set */ if (pdev->cpu_id ==AMD_CPU_ID_CZN )
Signature · 1 line
2.34.1
PATCH v5 4/4 platform/x86: amd-pmc: Drop CPU QoS workaround
In reply to Mario LimoncielloA workaround was previously introduced as part of commit 646f429ec2de ("platform/x86: amd-pmc: Set QOS during suspend on CZN w/ timer wakeup") to prevent CPUs from going into the deepest state during the execution of the noirq stage of amd_pmc. As amd_pmc has been pushed to the last step for suspend on AMD platforms, this workaround is no longer necessary.
---
changes from v4->v5:
* rebase on earlier patches
changes from v3->v4:
* rebase on earlier patches
changes from v2->v3:
* No changes
changes from v1->v2:
* No changes
drivers/platform/x86/amd-pmc.c | 32 +++----------------------------- 1 file changed, 3 insertions(+), 29 deletions(-)
drivers/platform/x86/amd-pmc.c +3 -29
@@ -21,7 +21,6 @@#include <linux/module.h> #include <linux/pci.h> #include <linux/platform_device.h> -#include <linux/pm_qos.h> #include <linux/rtc.h> #include <linux/suspend.h> #include <linux/seq_file.h>
@@ -96,9 +95,6 @@#define PMC_MSG_DELAY_MIN_US 50#define RESPONSE_REGISTER_LOOP_MAX 20000 -/* QoS request for letting CPUs in idle states, but not the deepest */ -#define AMD_PMC_MAX_IDLE_STATE_LATENCY 3 -#define SOC_SUBSYSTEM_IP_MAX 12#define DELAY_MIN_US 2000#define DELAY_MAX_US 3000
@@ -153,7 +149,6 @@ struct amd_pmc_dev {struct device *dev;struct pci_dev *rdev;struct mutex lock;/* generic mutex lock */ -struct pm_qos_request amd_pmc_pm_qos_req;#if IS_ENABLED (CONFIG_DEBUG_FS )struct dentry *dbgfs_dir;#endif /* CONFIG_DEBUG_FS */
@@ -628,14 +623,6 @@ static int amd_pmc_verify_czn_rtc(struct amd_pmc_dev *pdev, u32 *arg) rc =rtc_alarm_irq_enable (rtc_device,0 );dev_dbg (pdev->dev,"wakeup timer programmed for %lld seconds\n" , duration); -/* -* Prevent CPUs from getting into deep idle states while sending OS_HINT -* which is otherwise generally safe to send when at least one of the CPUs -* is not in deep idle states. -*/ -cpu_latency_qos_update_request (&pdev->amd_pmc_pm_qos_req,AMD_PMC_MAX_IDLE_STATE_LATENCY ); -wake_up_all_idle_cpus (); -return rc; }
@@ -655,7 +642,7 @@ static void amd_pmc_s2idle_prepare(void) rc =amd_pmc_verify_czn_rtc (pdev, &arg);if (rc) {dev_err (pdev->dev,"failed to set RTC: %d\n" , rc); - goto fail; +return ; } }
@@ -665,20 +652,13 @@ static void amd_pmc_s2idle_prepare(void) rc =amd_pmc_send_cmd (pdev, arg,NULL , msg,0 );if (rc) {dev_err (pdev->dev,"suspend failed: %d\n" , rc); - goto fail; +return ; }if (enable_stb) rc =amd_pmc_write_stb (pdev,AMD_PMC_STB_PREDEF ); -if (rc) { +if (rc)dev_err (pdev->dev,"error writing to STB: %d\n" , rc); - goto fail; - } -return ; -fail: -if (pdev->cpu_id ==AMD_CPU_ID_CZN ) -cpu_latency_qos_update_request (&pdev->amd_pmc_pm_qos_req, -PM_QOS_DEFAULT_VALUE ); }static void amd_pmc_s2idle_restore (void )
@@ -704,11 +684,6 @@ static void amd_pmc_s2idle_restore(void)if (rc)dev_err (pdev->dev,"error writing to STB: %d\n" , rc); -/* Restore the QoS request back to defaults if it was set */ -if (pdev->cpu_id ==AMD_CPU_ID_CZN ) -cpu_latency_qos_update_request (&pdev->amd_pmc_pm_qos_req, -PM_QOS_DEFAULT_VALUE ); -/* Notify on failed entry */ amd_pmc_validate_deepest (pdev); }
@@ -887,7 +862,6 @@ static int amd_pmc_probe(struct platform_device *pdev)dev_warn (dev->dev,"failed to register LPS0 sleep handler, expect increased power consumption\n" );amd_pmc_dbgfs_register (dev); -cpu_latency_qos_add_request (&dev->amd_pmc_pm_qos_req,PM_QOS_DEFAULT_VALUE );return 0 ; err_pci_dev_put:
Signature · 1 line
2.34.1
Re: [PATCH v5 4/4] platform/x86: amd-pmc: Drop CPU QoS workaround
Hi,
Quoted 80 lines · Mario Limonciello
A workaround was previously introduced as part of commit
646f429ec2de("platform/x86: amd-pmc: Set QOS during suspend on CZN w/ timer wakeup") to prevent CPUs from going into the deepest state during the execution of thenoirqstage ofamd_pmc. Asamd_pmchas been pushed to the last step for suspend on AMD platforms, this workaround is no longer necessary.Signed-off-by Mario Limonciello <[email protected]>---
changes fromv4->v5:
* rebase on earlier patches
changes fromv3->v4:
* rebase on earlier patches
changes fromv2->v3:
* No changes
changes fromv1->v2:
* No changesdrivers/platform/x86/amd-pmc.c | 32 +++----------------------------- 1 file changed, 3 insertions(+), 29 deletions(-)drivers/platform/x86/amd-pmc.c +1
-15@@ -21,7 +21,6 @@#include <linux/module.h> #include <linux/pci.h> #include <linux/platform_device.h> -#include <linux/pm_qos.h> #include <linux/rtc.h> #include <linux/suspend.h> #include <linux/seq_file.h> @@ -96,9 +95,6 @@#define PMC_MSG_DELAY_MIN_US 50#define RESPONSE_REGISTER_LOOP_MAX 20000 -/* QoS request for letting CPUs in idle states, but not the deepest */ -#define AMD_PMC_MAX_IDLE_STATE_LATENCY 3 -#define SOC_SUBSYSTEM_IP_MAX 12#define DELAY_MIN_US 2000#define DELAY_MAX_US 3000@@ -153,7 +149,6 @@ struct amd_pmc_dev {struct device *dev;struct pci_dev *rdev;struct mutex lock;/* generic mutex lock */ -struct pm_qos_request amd_pmc_pm_qos_req;#if IS_ENABLED (CONFIG_DEBUG_FS )struct dentry *dbgfs_dir;#endif /* CONFIG_DEBUG_FS */ @@ -628,14 +623,6 @@ static int amd_pmc_verify_czn_rtc(struct amd_pmc_dev *pdev, u32 *arg) rc =rtc_alarm_irq_enable (rtc_device,0 );dev_dbg (pdev->dev,"wakeup timer programmed for %lld seconds\n" , duration); -/* -* Prevent CPUs from getting into deep idle states while sending OS_HINT -* which is otherwise generally safe to send when at least one of the CPUs -* is not in deep idle states. -*/ -cpu_latency_qos_update_request (&pdev->amd_pmc_pm_qos_req,AMD_PMC_MAX_IDLE_STATE_LATENCY ); -wake_up_all_idle_cpus (); -return rc; }@@ -655,7 +642,7 @@ static void amd_pmc_s2idle_prepare(void) rc =amd_pmc_verify_czn_rtc (pdev, &arg);if (rc) {dev_err (pdev->dev,"failed to set RTC: %d\n" , rc); - goto fail; +return ; } }@@ -665,20 +652,13 @@ static void amd_pmc_s2idle_prepare(void) rc =amd_pmc_send_cmd (pdev, arg,NULL , msg,0 );if (rc) {dev_err (pdev->dev,"suspend failed: %d\n" , rc); - goto fail;
drivers/platform/x86/amd-pmc.c static void amd_pmc_s2idle_prepare(void) · line 676
Quoted 10 lines
drivers/platform/x86/amd-pmc.c +2
-3+return ; }if (enable_stb) rc =amd_pmc_write_stb (pdev,AMD_PMC_STB_PREDEF ); -if (rc) { +if (rc)dev_err (pdev->dev,"error writing to STB: %d\n" , rc); - goto fail; - }
Ok, this entire series has been merged here now:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=for-next
now lets hope none of the various build tests become unhappy because of this.
Mario, one request, the:
if (rc) dev_err(pdev->dev, "error writing to STB: %d\n", rc);
above looks weird, can you do a follow-up patch moving that to inside/under the "if (enable_stb)" check ?
Currently it also rechecks the amd_pmc_verify_czn_rtc() when enable_stb is false, which is weird.
Regards,
Hans
Quoted 31 lines
drivers/platform/x86/amd-pmc.c +0
-11-return ; -fail: -if (pdev->cpu_id ==AMD_CPU_ID_CZN ) -cpu_latency_qos_update_request (&pdev->amd_pmc_pm_qos_req, -PM_QOS_DEFAULT_VALUE ); }static void amd_pmc_s2idle_restore (void )@@ -704,11 +684,6 @@ static void amd_pmc_s2idle_restore(void)if (rc)dev_err (pdev->dev,"error writing to STB: %d\n" , rc); -/* Restore the QoS request back to defaults if it was set */ -if (pdev->cpu_id ==AMD_CPU_ID_CZN ) -cpu_latency_qos_update_request (&pdev->amd_pmc_pm_qos_req, -PM_QOS_DEFAULT_VALUE ); -/* Notify on failed entry */ amd_pmc_validate_deepest (pdev); }@@ -887,7 +862,6 @@ static int amd_pmc_probe(struct platform_device *pdev)dev_warn (dev->dev,"failed to register LPS0 sleep handler, expect increased power consumption\n" );amd_pmc_dbgfs_register (dev); -cpu_latency_qos_add_request (&dev->amd_pmc_pm_qos_req,PM_QOS_DEFAULT_VALUE );return 0 ; err_pci_dev_put:
Quoted 10 lines · Mario Limonciello
Currenty the latest thing run during a suspend to idle attempt is the LPS0
prepare_latecallback and the earliest thing is theresume_earlycallback.There is a desire for the
amd-pmcdriver to suspend later in the suspend process (ideally the very last thing), so create a callback that it or any other driver can hook into to do this.Signed-off-by Mario Limonciello <[email protected]>
This looks good to me, so:
and I don't have any conflicting changes queued up for 5.17, so from my POV it can go in via the x86 platform drivers tree along with the other patches in the series.
Quoted 120 lines
---
changes fromv4->v5:
* fix a check forhandler->prepare
Reported by Dan Carpenter <[email protected]>
changes fromv3->v4:
* drop use of mutex, uselock_system_sleepinstead
* don't pass argument of context, driver will maintain this internally
* don't allow failing prepare stage
* don't allow unregistering ifsleep_no_lps0is set
changes fromv2->v3:
* Check that callbacks exist before calling
changes fromv1->v2:
* Change register/unregister arguments to be structdrivers/acpi/x86/s2idle.c | 40 +++++++++++++++++++++++++++++++++++++++ include/linux/acpi.h | 10 +++++++++- 2 files changed, 49 insertions(+), 1 deletion(-)drivers/acpi/x86/s2idle.c +40
-0@@ -86,6 +86,8 @@ struct lpi_device_constraint_amd {int min_dstate; }; +static LIST_HEAD (lps0_s2idle_devops_head); +static struct lpi_constraints *lpi_constraints_table;static int lpi_constraints_table_size;static int rev_id;@@ -444,6 +446,8 @@ static struct acpi_scan_handler lps0_handler = {int acpi_s2idle_prepare_late (void ) { +struct acpi_s2idle_dev_ops *handler; +if (!lps0_device_handle || sleep_no_lps0)return 0 ;@@ -474,14 +478,26 @@ int acpi_s2idle_prepare_late(void)acpi_sleep_run_lps0_dsm (ACPI_LPS0_MS_ENTRY , lps0_dsm_func_mask_microsoft, lps0_dsm_guid_microsoft); } + +list_for_each_entry (handler, &lps0_s2idle_devops_head, list_node) { +if (handler->prepare) + handler->prepare (); + } +return 0 ; }void acpi_s2idle_restore_early (void ) { +struct acpi_s2idle_dev_ops *handler; +if (!lps0_device_handle || sleep_no_lps0)return ; +list_for_each_entry (handler, &lps0_s2idle_devops_head, list_node) +if (handler->restore) + handler->restore (); +/* Modern standby exit */ if (lps0_dsm_func_mask_microsoft >0 ) acpi_sleep_run_lps0_dsm(ACPI_LPS0_MS_EXIT,@@ -524,4 +540,28 @@ void acpi_s2idle_setup(void) s2idle_set_ops(&acpi_s2idle_ops_lps0); } +int acpi_register_lps0_dev (struct acpi_s2idle_dev_ops *arg) +{ +if (!lps0_device_handle || sleep_no_lps0) +return -ENODEV ; + +lock_system_sleep (); +list_add (&arg->list_node, &lps0_s2idle_devops_head); +unlock_system_sleep (); + +return 0 ; +} +EXPORT_SYMBOL_GPL (acpi_register_lps0_dev); + +void acpi_unregister_lps0_dev (struct acpi_s2idle_dev_ops *arg) +{ +if (!lps0_device_handle || sleep_no_lps0) +return ; + +lock_system_sleep (); +list_del (&arg->list_node); +unlock_system_sleep (); +} +EXPORT_SYMBOL_GPL (acpi_unregister_lps0_dev); +#endif /* CONFIG_SUSPEND */ include/linux/acpi.h +9
-2@@ -1023,7 +1023,15 @@ void acpi_os_set_prepare_extended_sleep(int (*func)(u8 sleep_state,acpi_status acpi_os_prepare_extended_sleep (u8 sleep_state,u32 val_a,u32 val_b); - +#ifdef CONFIG_X86 +struct acpi_s2idle_dev_ops { +struct list_head list_node; +void (*prepare)(void ); +void (*restore)(void ); +}; +int acpi_register_lps0_dev (struct acpi_s2idle_dev_ops *arg); +void acpi_unregister_lps0_dev (struct acpi_s2idle_dev_ops *arg); +#endif /* CONFIG_X86 */ #ifndef CONFIG_IA64 void arch_reserve_mem_area (acpi_physical_address addr,size_t size);#else --2.34.1
[Public]
Quoted 22 lines
-----Original Message-----
From: Rafael J. Wysocki <[email protected]>
Sent: Thursday, March 17, 2022 11:46
To: Limonciello, Mario <[email protected]>
Cc: Hans de Goede <[email protected]>; Mark Gross <[email protected]>; Rafael J . Wysocki <[email protected]>; open list:X86 PLATFORM DRIVERS <[email protected]>; ACPI Devel Maling List <[email protected]>; S-k, Shyam-sundar <Shyam- [email protected]>; Goswami, Sanket <[email protected]>
Subject: Re: [PATCH v5 1/4] ACPI / x86: Add support for LPS0 callback handlerQuoted 9 lines · Mario Limonciello
Currenty the latest thing run during a suspend to idle attempt is the LPS0
prepare_latecallback and the earliest thing is theresume_earlycallback.There is a desire for the
amd-pmcdriver to suspend later in the suspend process (ideally the very last thing), so create a callback that it or any other driver can hook into to do this.
Quoted 6 lines
Quoted 1 line
Signed-off-by Mario Limonciello <[email protected]>This looks good to me, so:
Thanks!
Quoted 3 lines
and I don't have any conflicting changes queued up for 5.17, so from my POV it can go in via the x86 platform drivers tree along with the other patches in the series.
Hans,
FYI the series is based off of platform-x86/for-next also with changes to amd-pmc Rafael doesn't have in his tree, so I also agree it's better to go through x86 platform drivers.
Quoted 124 lines
Quoted 15 lines
---
changes fromv4->v5:
* fix a check forhandler->prepare
Reported by Dan Carpenter <[email protected]>
changes fromv3->v4:
* drop use of mutex, uselock_system_sleepinstead
* don't pass argument of context, driver will maintain this internally
* don't allow failing prepare stage
* don't allow unregistering ifsleep_no_lps0is set
changes fromv2->v3:
* Check that callbacks exist before calling
changes fromv1->v2:
* Change register/unregister arguments to be structQuoted 1 line
drivers/acpi/x86/s2idle.c | 40+++++++++++++++++++++++++++++++++++++++
Quoted 26 lines
include/linux/acpi.h | 10 +++++++++- 2 files changed, 49 insertions(+), 1 deletion(-)drivers/acpi/x86/s2idle.c +4
-0@@ -86,6 +86,8 @@ struct lpi_device_constraint_amd {int min_dstate; }; +static LIST_HEAD (lps0_s2idle_devops_head); +static struct lpi_constraints *lpi_constraints_table;static int lpi_constraints_table_size;static int rev_id;@@ -444,6 +446,8 @@ static struct acpi_scan_handler lps0_handler = {int acpi_s2idle_prepare_late (void ) { +struct acpi_s2idle_dev_ops *handler; +if (!lps0_device_handle || sleep_no_lps0)return 0 ;drivers/acpi/x86/s2idle.c int acpi_s2idle_prepare_late(void) · line 479
Quoted 2 lines
drivers/acpi/x86/s2idle.c +0
-0@@ -474,14 +478,26 @@ int acpi_s2idle_prepare_late(void) acpi_sleep_run_lps0_dsm(ACPI_LPS0_MS_ENTRY, lps0_dsm_func_mask_microsoft,
lps0_dsm_guid_microsoft);include/linux/acpi.h void acpi_os_set_prepare_extended_sleep(int
Quoted 58 lines
drivers/acpi/x86/s2idle.c +36
-0} + +list_for_each_entry (handler, &lps0_s2idle_devops_head, list_node) { +if (handler->prepare) + handler->prepare (); + } +return 0 ; }void acpi_s2idle_restore_early (void ) { +struct acpi_s2idle_dev_ops *handler; +if (!lps0_device_handle || sleep_no_lps0)return ; +list_for_each_entry (handler, &lps0_s2idle_devops_head, list_node) +if (handler->restore) + handler->restore (); +/* Modern standby exit */ if (lps0_dsm_func_mask_microsoft >0 ) acpi_sleep_run_lps0_dsm(ACPI_LPS0_MS_EXIT,@@ -524,4 +540,28 @@ void acpi_s2idle_setup(void) s2idle_set_ops(&acpi_s2idle_ops_lps0); } +int acpi_register_lps0_dev (struct acpi_s2idle_dev_ops *arg) +{ +if (!lps0_device_handle || sleep_no_lps0) +return -ENODEV ; + +lock_system_sleep (); +list_add (&arg->list_node, &lps0_s2idle_devops_head); +unlock_system_sleep (); + +return 0 ; +} +EXPORT_SYMBOL_GPL (acpi_register_lps0_dev); + +void acpi_unregister_lps0_dev (struct acpi_s2idle_dev_ops *arg) +{ +if (!lps0_device_handle || sleep_no_lps0) +return ; + +lock_system_sleep (); +list_del (&arg->list_node); +unlock_system_sleep (); +} +EXPORT_SYMBOL_GPL (acpi_unregister_lps0_dev); +#endif /* CONFIG_SUSPEND */ include/linux/acpi.h +0
-0@@ -1023,7 +1023,15 @@ void acpi_os_set_prepare_extended_sleep(int(*func)(u8
sleep_state,Quoted 19 lines
include/linux/acpi.h +9
-2acpi_status acpi_os_prepare_extended_sleep (u8 sleep_state,u32 val_a,u32 val_b); - +#ifdef CONFIG_X86 +struct acpi_s2idle_dev_ops { +struct list_head list_node; +void (*prepare)(void ); +void (*restore)(void ); +}; +int acpi_register_lps0_dev (struct acpi_s2idle_dev_ops *arg); +void acpi_unregister_lps0_dev (struct acpi_s2idle_dev_ops *arg); +#endif /* CONFIG_X86 */ #ifndef CONFIG_IA64 void arch_reserve_mem_area (acpi_physical_address addr,size_t size);#else --2.34.1
Hans de Goede
Reviewed-byHi All,
Quoted 39 lines · Mario
[Public]
Quoted 22 lines
-----Original Message-----
From: Rafael J. Wysocki <[email protected]>
Sent: Thursday, March 17, 2022 11:46
To: Limonciello, Mario <[email protected]>
Cc: Hans de Goede <[email protected]>; Mark Gross <[email protected]>; Rafael J . Wysocki <[email protected]>; open list:X86 PLATFORM DRIVERS <[email protected]>; ACPI Devel Maling List <[email protected]>; S-k, Shyam-sundar <Shyam- [email protected]>; Goswami, Sanket <[email protected]>
Subject: Re: [PATCH v5 1/4] ACPI / x86: Add support for LPS0 callback handlerQuoted 9 lines · Mario Limonciello
Currenty the latest thing run during a suspend to idle attempt is the LPS0
prepare_latecallback and the earliest thing is theresume_earlycallback.There is a desire for the
amd-pmcdriver to suspend later in the suspend process (ideally the very last thing), so create a callback that it or any other driver can hook into to do this.Quoted 6 lines
Quoted 1 line
Signed-off-by Mario Limonciello <[email protected]>This looks good to me, so:
Thanks!
Quoted 3 lines
and I don't have any conflicting changes queued up for 5.17, so from my POV it can go in via the x86 platform drivers tree along with the other patches in the series.
Quoted 5 lines
Hans,
FYI the series is based off of platform-x86/for-next also with changes to amd-pmc Rafael doesn't have in his tree, so I also agree it's better to go through x86 platform drivers.
Ok, the entire series looks good to me:
So I'll go and merge this into review-hans, do some compile tests and then push this directly to for-next to give it some minimum baking time there before the 5.18 merge-window opens.
Regards,
Hans
Quoted 125 lines
Quoted 125 lines
Quoted 16 lines
---
changes fromv4->v5:
* fix a check forhandler->prepare
Reported by Dan Carpenter <[email protected]>
changes fromv3->v4:
* drop use of mutex, uselock_system_sleepinstead
* don't pass argument of context, driver will maintain this internally
* don't allow failing prepare stage
* don't allow unregistering ifsleep_no_lps0is set
changes fromv2->v3:
* Check that callbacks exist before calling
changes fromv1->v2:
* Change register/unregister arguments to be structQuoted 1 line
drivers/acpi/x86/s2idle.c | 40+++++++++++++++++++++++++++++++++++++++
Quoted 26 lines
include/linux/acpi.h | 10 +++++++++- 2 files changed, 49 insertions(+), 1 deletion(-)drivers/acpi/x86/s2idle.c +4
-0@@ -86,6 +86,8 @@ struct lpi_device_constraint_amd {int min_dstate; }; +static LIST_HEAD (lps0_s2idle_devops_head); +static struct lpi_constraints *lpi_constraints_table;static int lpi_constraints_table_size;static int rev_id;@@ -444,6 +446,8 @@ static struct acpi_scan_handler lps0_handler = {int acpi_s2idle_prepare_late (void ) { +struct acpi_s2idle_dev_ops *handler; +if (!lps0_device_handle || sleep_no_lps0)return 0 ;drivers/acpi/x86/s2idle.c int acpi_s2idle_prepare_late(void) · line 479
Quoted 2 lines
drivers/acpi/x86/s2idle.c +0
-0@@ -474,14 +478,26 @@ int acpi_s2idle_prepare_late(void) acpi_sleep_run_lps0_dsm(ACPI_LPS0_MS_ENTRY, lps0_dsm_func_mask_microsoft,
lps0_dsm_guid_microsoft);include/linux/acpi.h void acpi_os_set_prepare_extended_sleep(int
Quoted 58 lines
drivers/acpi/x86/s2idle.c +36
-0} + +list_for_each_entry (handler, &lps0_s2idle_devops_head, list_node) { +if (handler->prepare) + handler->prepare (); + } +return 0 ; }void acpi_s2idle_restore_early (void ) { +struct acpi_s2idle_dev_ops *handler; +if (!lps0_device_handle || sleep_no_lps0)return ; +list_for_each_entry (handler, &lps0_s2idle_devops_head, list_node) +if (handler->restore) + handler->restore (); +/* Modern standby exit */ if (lps0_dsm_func_mask_microsoft >0 ) acpi_sleep_run_lps0_dsm(ACPI_LPS0_MS_EXIT,@@ -524,4 +540,28 @@ void acpi_s2idle_setup(void) s2idle_set_ops(&acpi_s2idle_ops_lps0); } +int acpi_register_lps0_dev (struct acpi_s2idle_dev_ops *arg) +{ +if (!lps0_device_handle || sleep_no_lps0) +return -ENODEV ; + +lock_system_sleep (); +list_add (&arg->list_node, &lps0_s2idle_devops_head); +unlock_system_sleep (); + +return 0 ; +} +EXPORT_SYMBOL_GPL (acpi_register_lps0_dev); + +void acpi_unregister_lps0_dev (struct acpi_s2idle_dev_ops *arg) +{ +if (!lps0_device_handle || sleep_no_lps0) +return ; + +lock_system_sleep (); +list_del (&arg->list_node); +unlock_system_sleep (); +} +EXPORT_SYMBOL_GPL (acpi_unregister_lps0_dev); +#endif /* CONFIG_SUSPEND */ include/linux/acpi.h +0
-0@@ -1023,7 +1023,15 @@ void acpi_os_set_prepare_extended_sleep(int(*func)(u8
sleep_state,Quoted 19 lines
include/linux/acpi.h +9
-2acpi_status acpi_os_prepare_extended_sleep (u8 sleep_state,u32 val_a,u32 val_b); - +#ifdef CONFIG_X86 +struct acpi_s2idle_dev_ops { +struct list_head list_node; +void (*prepare)(void ); +void (*restore)(void ); +}; +int acpi_register_lps0_dev (struct acpi_s2idle_dev_ops *arg); +void acpi_unregister_lps0_dev (struct acpi_s2idle_dev_ops *arg); +#endif /* CONFIG_X86 */ #ifndef CONFIG_IA64 void arch_reserve_mem_area (acpi_physical_address addr,size_t size);#else --2.34.1