ACPI / x86: Add support for LPS0 callback handler
Subsystems (2)
PATCH 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.
--- drivers/acpi/x86/s2idle.c | 76 ++++++++++++++++++++++++++++++++++++++- include/linux/acpi.h | 9 ++++- 2 files changed, 83 insertions(+), 2 deletions(-)
drivers/acpi/x86/s2idle.c +75 -1
@@ -86,6 +86,16 @@ struct lpi_device_constraint_amd {int min_dstate; }; +struct lps0_callback_handler { +struct list_head list_node; +int (*prepare_late_callback)(void *context); +void (*restore_early_callback)(void *context); +void *context; +}; + +static LIST_HEAD (lps0_callback_handler_head); +static DEFINE_MUTEX (lps0_callback_handler_mutex); +static struct lpi_constraints *lpi_constraints_table;static int lpi_constraints_table_size;static int rev_id;
@@ -444,6 +454,9 @@ static struct acpi_scan_handler lps0_handler = {int acpi_s2idle_prepare_late (void ) { +struct lps0_callback_handler *handler; +int rc =0 ; +if (!lps0_device_handle || sleep_no_lps0)return 0 ;
@@ -474,14 +487,31 @@ int acpi_s2idle_prepare_late(void)acpi_sleep_run_lps0_dsm (ACPI_LPS0_MS_ENTRY , lps0_dsm_func_mask_microsoft, lps0_dsm_guid_microsoft); } -return 0 ; + +mutex_lock (&lps0_callback_handler_mutex); +list_for_each_entry (handler, &lps0_callback_handler_head, list_node) { + rc = handler->prepare_late_callback (handler->context); +if (rc) + goto out; + } +out: +mutex_unlock (&lps0_callback_handler_mutex); + +return rc; }void acpi_s2idle_restore_early (void ) { +struct lps0_callback_handler *handler; +if (!lps0_device_handle || sleep_no_lps0)return ; +mutex_lock (&lps0_callback_handler_mutex); +list_for_each_entry (handler, &lps0_callback_handler_head, list_node) + handler->restore_early_callback (handler->context); +mutex_unlock (&lps0_callback_handler_mutex); +/* Modern standby exit */ if (lps0_dsm_func_mask_microsoft >0 ) acpi_sleep_run_lps0_dsm(ACPI_LPS0_MS_EXIT,
@@ -524,4 +554,48 @@ void acpi_s2idle_setup(void)s2idle_set_ops (&acpi_s2idle_ops_lps0); } +int acpi_register_lps0_callbacks (int (*prepare_late)(void *context), +void (*restore_early)(void *context), +void *context) +{ +struct lps0_callback_handler *handler; + +if (!lps0_device_handle || sleep_no_lps0) +return -ENODEV ; + + handler =kmalloc (sizeof (*handler),GFP_KERNEL ); +if (!handler) +return -ENOMEM ; + handler->prepare_late_callback = prepare_late; + handler->restore_early_callback = restore_early; + handler->context = context; + +mutex_lock (&lps0_callback_handler_mutex); +list_add (&handler->list_node, &lps0_callback_handler_head); +mutex_unlock (&lps0_callback_handler_mutex); + +return 0 ; +} +EXPORT_SYMBOL_GPL (acpi_register_lps0_callbacks); + +void acpi_unregister_lps0_callbacks (int (*prepare_late)(void *context), +void (*restore_early)(void *context), +void *context) +{ +struct lps0_callback_handler *handler; + +mutex_lock (&lps0_callback_handler_mutex); +list_for_each_entry (handler, &lps0_callback_handler_head, list_node) { +if (handler->prepare_late_callback == prepare_late && + handler->restore_early_callback == restore_early && + handler->context == context) { +list_del (&handler->list_node); +kfree (handler); +break ; + } + } +mutex_unlock (&lps0_callback_handler_mutex); +} +EXPORT_SYMBOL_GPL (acpi_unregister_lps0_callbacks); +#endif /* CONFIG_SUSPEND */
include/linux/acpi.h +8 -1
@@ -1023,7 +1023,14 @@ 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 +int acpi_register_lps0_callbacks (int (*prepare_late)(void *context), +void (*restore_early)(void *context), +void *context); +void acpi_unregister_lps0_callbacks (int (*prepare_late)(void *context), +void (*restore_early)(void *context), +void *context); +#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 2/4 ACPI / x86: Pass the constraints checking result to LPS0 callback
If constraints checking has been enabled by the LPS0 code, it may also be useful for drivers using the callback to make a decision what to do.
For example this may in the future allow a failing constraints check preventing another driver from notifying firmware that all required devices have entered the deepest state.
--- drivers/acpi/x86/s2idle.c | 17 ++++++++++------- include/linux/acpi.h | 4 ++-- 2 files changed, 12 insertions(+), 9 deletions(-)
drivers/acpi/x86/s2idle.c +10 -7
@@ -88,7 +88,7 @@ struct lpi_device_constraint_amd {struct lps0_callback_handler {struct list_head list_node; -int (*prepare_late_callback)(void *context); +int (*prepare_late_callback)(void *context,bool constraints);void (*restore_early_callback)(void *context);void *context; };
@@ -297,7 +297,7 @@ static void lpi_device_get_constraints(void)ACPI_FREE (out_obj); } -static void lpi_check_constraints (void ) +static void lpi_check_constraints (bool *met) {int i;
@@ -319,11 +319,13 @@ static void lpi_check_constraints(void)continue ; } -if (adev->power.state < lpi_constraints_table[i].min_dstate) +if (adev->power.state < lpi_constraints_table[i].min_dstate) {acpi_handle_info (handle,"LPI: Constraint not met; min power state:%s current power state:%s\n" ,acpi_power_state_string (lpi_constraints_table[i].min_dstate),acpi_power_state_string (adev->power.state)); + *met = false; + } } }
@@ -455,13 +457,14 @@ static struct acpi_scan_handler lps0_handler = {int acpi_s2idle_prepare_late (void ) {struct lps0_callback_handler *handler; +bool constraints_met = true;int rc =0 ;if (!lps0_device_handle || sleep_no_lps0)return 0 ;if (pm_debug_messages_on) -lpi_check_constraints (); +lpi_check_constraints (&constraints_met);/* Screen off */ if (lps0_dsm_func_mask >0 )
@@ -490,7 +493,7 @@ int acpi_s2idle_prepare_late(void)mutex_lock (&lps0_callback_handler_mutex);list_for_each_entry (handler, &lps0_callback_handler_head, list_node) { - rc = handler->prepare_late_callback (handler->context); + rc = handler->prepare_late_callback (handler->context, constraints_met);if (rc) goto out; }
@@ -554,7 +557,7 @@ void acpi_s2idle_setup(void)s2idle_set_ops (&acpi_s2idle_ops_lps0); } -int acpi_register_lps0_callbacks (int (*prepare_late)(void *context), +int acpi_register_lps0_callbacks (int (*prepare_late)(void *context,bool constraints),void (*restore_early)(void *context),void *context) {
@@ -578,7 +581,7 @@ int acpi_register_lps0_callbacks(int (*prepare_late)(void *context), }EXPORT_SYMBOL_GPL (acpi_register_lps0_callbacks); -void acpi_unregister_lps0_callbacks (int (*prepare_late)(void *context), +void acpi_unregister_lps0_callbacks (int (*prepare_late)(void *context,bool constraints),void (*restore_early)(void *context),void *context) {
include/linux/acpi.h +2 -2
@@ -1024,10 +1024,10 @@ 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 -int acpi_register_lps0_callbacks (int (*prepare_late)(void *context), +int acpi_register_lps0_callbacks (int (*prepare_late)(void *context,bool constraints),void (*restore_early)(void *context),void *context); -void acpi_unregister_lps0_callbacks (int (*prepare_late)(void *context), +void acpi_unregister_lps0_callbacks (int (*prepare_late)(void *context,bool constraints),void (*restore_early)(void *context),void *context);#endif /* CONFIG_X86 */
Signature · 1 line
2.34.1
Re: [PATCH 2/4] ACPI / x86: Pass the constraints checking result to LPS0 callback
Quoted 56 lines · Mario Limonciello
If constraints checking has been enabled by the LPS0 code, it may also be useful for drivers using the callback to make a decision what to do.
For example this may in the future allow a failing constraints check preventing another driver from notifying firmware that all required devices have entered the deepest state.
Signed-off-by Mario Limonciello <[email protected]>--- drivers/acpi/x86/s2idle.c | 17 ++++++++++------- include/linux/acpi.h | 4 ++-- 2 files changed, 12 insertions(+), 9 deletions(-)drivers/acpi/x86/s2idle.c +5
-3@@ -88,7 +88,7 @@ struct lpi_device_constraint_amd {struct lps0_callback_handler {struct list_head list_node; -int (*prepare_late_callback)(void *context); +int (*prepare_late_callback)(void *context,bool constraints);void (*restore_early_callback)(void *context);void *context; };@@ -297,7 +297,7 @@ static void lpi_device_get_constraints(void)ACPI_FREE (out_obj); } -static void lpi_check_constraints (void ) +static void lpi_check_constraints (bool *met) {int i;@@ -319,11 +319,13 @@ static void lpi_check_constraints(void)continue ; } -if (adev->power.state < lpi_constraints_table[i].min_dstate) +if (adev->power.state < lpi_constraints_table[i].min_dstate) {acpi_handle_info (handle, "LPI: Constraint not met; min power state:%s current power state:%s\n", acpi_power_state_string(lpi_constraints_table[i] .min_dstate),acpi_power_state_string (adev->power.state)); + *met = false; + } }}
drivers/acpi/x86/s2idle.c +0
-0@@ -455,13 +457,14 @@ static struct acpi_scan_handler lps0_handler = {int acpi_s2idle_prepare_late (void ) {
drivers/acpi/x86/s2idle.c static struct acpi_scan_handler lps0_handler = { · line 467
Quoted 10 lines
drivers/acpi/x86/s2idle.c +2
-1struct lps0_callback_handler *handler; +bool constraints_met = true;int rc =0 ;if (!lps0_device_handle || sleep_no_lps0)return 0 ;if (pm_debug_messages_on) -lpi_check_constraints (); +lpi_check_constraints (&constraints_met);
lpi_check_constraints() was only used for dumping information to dmesg. If you want to make a decision based on whether a constraint was met then you probably want to run it all the time. You could use pm_debug_messages_on inside of lpi_check_contraints() to decide whether to print to the log.
drivers/acpi/x86/s2idle.c int acpi_s2idle_prepare_late(void) · line 497
Quoted 10 lines
drivers/acpi/x86/s2idle.c +1
-1/* Screen off */ if (lps0_dsm_func_mask >0 )@@ -490,7 +493,7 @@ int acpi_s2idle_prepare_late(void)mutex_lock (&lps0_callback_handler_mutex);list_for_each_entry (handler, &lps0_callback_handler_head, list_node) { - rc = handler->prepare_late_callback (handler->context); + rc = handler->prepare_late_callback (handler->context, constraints_met);
Otherwise, is it okay that constraints_met will always be true if pm_debug_messages_on isn't?
David
Quoted 44 lines
drivers/acpi/x86/s2idle.c +0
-0if (rc) goto out;drivers/acpi/x86/s2idle.c +1
-1}@@ -554,7 +557,7 @@ void acpi_s2idle_setup(void)s2idle_set_ops (&acpi_s2idle_ops_lps0); } -int acpi_register_lps0_callbacks (int (*prepare_late)(void *context), +int acpi_register_lps0_callbacks (int (*prepare_late)(void *context,bool constraints),void (*restore_early)(void *context),void *context){
drivers/acpi/x86/s2idle.c +1
-1@@ -578,7 +581,7 @@ int acpi_register_lps0_callbacks(int (*prepare_late)(void *context), }EXPORT_SYMBOL_GPL (acpi_register_lps0_callbacks); -void acpi_unregister_lps0_callbacks (int (*prepare_late)(void *context), +void acpi_unregister_lps0_callbacks(int (*prepare_late)(void *context, bool constraints), void (*restore_early)(void *context),drivers/acpi/x86/s2idle.c +0
-0void *context) {include/linux/acpi.h +2
-2@@ -1024,10 +1024,10 @@ 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 -int acpi_register_lps0_callbacks (int (*prepare_late)(void *context), +int acpi_register_lps0_callbacks (int (*prepare_late)(void *context,bool constraints),void (*restore_early)(void *context),void *context); -void acpi_unregister_lps0_callbacks (int (*prepare_late)(void *context), +void acpi_unregister_lps0_callbacks(int (*prepare_late)(void *context, bool constraints),include/linux/acpi.h +0
-0void (*restore_early)(void *context), void *context);#endif /* CONFIG_X86 */
RE: [PATCH 2/4] ACPI / x86: Pass the constraints checking result to LPS0 callback
[Public]
Quoted 78 lines
-----Original Message-----
From: David E. Box <[email protected]>
Sent: Thursday, March 10, 2022 10:26
To: Limonciello, Mario <[email protected]>; Hans de Goede <[email protected]>; Mark Gross <[email protected]>; Rafael J . Wysocki <[email protected]>
Cc: open list:X86 PLATFORM DRIVERS <platform-driver- [email protected]>; [email protected]
Subject: Re: [PATCH 2/4] ACPI / x86: Pass the constraints checking result to LPS0 callbackQuoted 37 lines · Mario Limonciello
If constraints checking has been enabled by the LPS0 code, it may also be useful for drivers using the callback to make a decision what to do.
For example this may in the future allow a failing constraints check preventing another driver from notifying firmware that all required devices have entered the deepest state.
Signed-off-by Mario Limonciello <[email protected]>--- drivers/acpi/x86/s2idle.c | 17 ++++++++++------- include/linux/acpi.h | 4 ++-- 2 files changed, 12 insertions(+), 9 deletions(-)drivers/acpi/x86/s2idle.c +2
-2@@ -88,7 +88,7 @@ struct lpi_device_constraint_amd {struct lps0_callback_handler {struct list_head list_node; -int (*prepare_late_callback)(void *context); +int (*prepare_late_callback)(void *context,bool constraints);void (*restore_early_callback)(void *context);void *context; };@@ -297,7 +297,7 @@ static void lpi_device_get_constraints(void)ACPI_FREE (out_obj); } -static void lpi_check_constraints (void ) +static void lpi_check_constraints (bool *met) {int i;drivers/acpi/x86/s2idle.c static void lpi_check_constraints(void) · line 322
Quoted 5 lines
drivers/acpi/x86/s2idle.c +1
-1@@ -319,11 +319,13 @@ static void lpi_check_constraints(void)continue ; } -if (adev->power.state < lpi_constraints_table[i].min_dstate) +if (adev->power.state < lpi_constraints_table[i].min_dstate){
drivers/acpi/x86/s2idle.c static void lpi_check_constraints(void) · line 331
Quoted 4 lines
drivers/acpi/x86/s2idle.c +0
-0acpi_handle_info (handle, "LPI: Constraint not met; min power state:%s current power state:%s\n",acpi_power_state_string(lpi_constraints_table[i]
Quoted 18 lines
drivers/acpi/x86/s2idle.c +2
-0.min_dstate),acpi_power_state_string (adev- power.state)); + *met = false; + }drivers/acpi/x86/s2idle.c +1
-0} }@@ -455,13 +457,14 @@ static struct acpi_scan_handler lps0_handler = {int acpi_s2idle_prepare_late (void ) {struct lps0_callback_handler *handler; +bool constraints_met = true;int rc =0 ;if (!lps0_device_handle || sleep_no_lps0)return 0 ;
Quoted 10 lines
drivers/acpi/x86/s2idle.c static struct acpi_scan_handler lps0_handler = { · line 467
Quoted 3 lines
drivers/acpi/x86/s2idle.c +1
-1if (pm_debug_messages_on) -lpi_check_constraints (); +lpi_check_constraints (&constraints_met);
lpi_check_constraints()was only used for dumping information to dmesg. If you
want to make a decision based on whether a constraint was met then you probably
want to run it all the time. You could usepm_debug_messages_oninside oflpi_check_contraints()to decide whether to print to the log.
That's a good idea.
Quoted 9 lines
drivers/acpi/x86/s2idle.c int acpi_s2idle_prepare_late(void) · line 495
Quoted 8 lines
drivers/acpi/x86/s2idle.c +0
-0/* Screen off */ if (lps0_dsm_func_mask >0 )@@ -490,7 +493,7 @@ int acpi_s2idle_prepare_late(void)mutex_lock (&lps0_callback_handler_mutex); list_for_each_entry(handler, &lps0_callback_handler_head,
list_node) {
Quoted 6 lines
drivers/acpi/x86/s2idle.c int acpi_s2idle_prepare_late(void) · line 497
Quoted 3 lines
drivers/acpi/x86/s2idle.c +1
-1- rc = handler->prepare_late_callback (handler->context); + rc = handler->prepare_late_callback (handler->context, constraints_met);Otherwise, is it okay that
constraints_metwill always be true ifpm_debug_messages_onisn't?
I wasn't ready to make decisions based on it, but you're right at least running it all the time and showing the impactful messages when debugging on is a good start.
Thanks!
Quoted 51 lines
David
drivers/acpi/x86/s2idle.c int acpi_register_lps0_callbacks(int
Quoted 14 lines
drivers/acpi/x86/s2idle.c +0
-0if (rc) goto out;drivers/acpi/x86/s2idle.c +1
-1}@@ -554,7 +557,7 @@ void acpi_s2idle_setup(void)s2idle_set_ops (&acpi_s2idle_ops_lps0); } -int acpi_register_lps0_callbacks (int (*prepare_late)(void *context), +int acpi_register_lps0_callbacks (int (*prepare_late)(void *context,bool constraints),void (*restore_early)(void *context),void *context){
drivers/acpi/x86/s2idle.c +0
-0@@ -578,7 +581,7 @@ int acpi_register_lps0_callbacks(int(*prepare_late)(void
drivers/acpi/x86/s2idle.c int acpi_register_lps0_callbacks(int (*prepare_late)(void *context),
Quoted 6 lines
drivers/acpi/x86/s2idle.c +1
-1*context), }EXPORT_SYMBOL_GPL (acpi_register_lps0_callbacks); -void acpi_unregister_lps0_callbacks(int (*prepare_late)(void *context), +void acpi_unregister_lps0_callbacks(int (*prepare_late)(void *context,bool
include/linux/acpi.h void acpi_os_set_prepare_extended_sleep(int
Quoted 9 lines
drivers/acpi/x86/s2idle.c +0
-0constraints), void (*restore_early)(void *context),drivers/acpi/x86/s2idle.c +0
-0void *context) {include/linux/acpi.h +0
-0@@ -1024,10 +1024,10 @@ void acpi_os_set_prepare_extended_sleep(int(*func)(u8
include/linux/acpi.h void acpi_os_set_prepare_extended_sleep(int (*func)(u8 sleep_state,
Quoted 11 lines
include/linux/acpi.h +2
-2sleep_state, acpi_status acpi_os_prepare_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b);#ifdef CONFIG_X86 -int acpi_register_lps0_callbacks (int (*prepare_late)(void *context), +int acpi_register_lps0_callbacks (int (*prepare_late)(void *context,bool constraints),void (*restore_early)(void *context),void *context); -void acpi_unregister_lps0_callbacks(int (*prepare_late)(void *context), +void acpi_unregister_lps0_callbacks(int (*prepare_late)(void *context,bool
Quoted 4 lines
include/linux/acpi.h +0
-0constraints),include/linux/acpi.h +0
-0void (*restore_early)(void *context), void *context);#endif /* CONFIG_X86 */
PATCH 3/4 platform/x86: amd-pmc: Move to later in the suspend process
In reply to Mario LimoncielloThe 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.
--- drivers/platform/x86/amd-pmc.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-)
drivers/platform/x86/amd-pmc.c +17 -16
@@ -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 int amd_pmc_suspend (void *context,bool constraints_met) { -struct amd_pmc_dev *pdev =dev_get_drvdata (dev); +struct amd_pmc_dev *pdev =dev_get_drvdata ((struct device *)context);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) {
@@ -681,28 +681,28 @@ static int __maybe_unused amd_pmc_suspend(struct device *dev)return rc; } -static int __maybe_unused amd_pmc_resume (struct device *dev) +static void amd_pmc_resume (void *context) { -struct amd_pmc_dev *pdev =dev_get_drvdata (dev); +struct amd_pmc_dev *pdev =dev_get_drvdata ((struct device *)context);int rc;u8 msg; 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 );/* 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) 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 )
@@ -711,15 +711,8 @@ 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 const struct pci_device_id pmc_pci_ids[] = { {PCI_DEVICE (PCI_VENDOR_ID_AMD ,AMD_CPU_ID_YC ) }, {PCI_DEVICE (PCI_VENDOR_ID_AMD ,AMD_CPU_ID_CZN ) },
@@ -884,6 +877,12 @@ static int amd_pmc_probe(struct platform_device *pdev)amd_pmc_get_smu_version (dev);platform_set_drvdata (pdev, dev); + err =acpi_register_lps0_callbacks (amd_pmc_suspend, + amd_pmc_resume, + &pdev->dev); +if (err) + goto err_pci_dev_put; +amd_pmc_dbgfs_register (dev);cpu_latency_qos_add_request (&dev->amd_pmc_pm_qos_req,PM_QOS_DEFAULT_VALUE );return 0 ;
@@ -897,6 +896,9 @@ static int amd_pmc_remove(struct platform_device *pdev) {struct amd_pmc_dev *dev =platform_get_drvdata (pdev); +acpi_unregister_lps0_callbacks (amd_pmc_suspend, + amd_pmc_resume, + &pdev->dev);amd_pmc_dbgfs_unregister (dev);pci_dev_put (dev->rdev);mutex_destroy (&dev->lock);
@@ -917,7 +919,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
Re: [PATCH 3/4] platform/x86: amd-pmc: Move to later in the suspend process
Quoted 7 lines · Mario Limonciello
The
OS_HINTmessage 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 theirnoirqsuspend routines
3) The LPS0 ACPI device will still run
Yep. We had looked at adding a notifier to address this.
David
Quoted 123 lines
To more closely mirror how this works on other operating systems, move the
amd-pmcsuspend to the very last thing before the s2idle loop via an lps0 callback.Fixes 8d89835b0467 ("PM: suspend: Do not pause cpuidle in the suspend-to-idlepath")
Signed-off-by Mario Limonciello <[email protected]>--- drivers/platform/x86/amd-pmc.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-)drivers/platform/x86/amd-pmc.c +2
-2@@ -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 int amd_pmc_suspend (void *context,bool constraints_met) { -struct amd_pmc_dev *pdev =dev_get_drvdata (dev); +struct amd_pmc_dev *pdev =dev_get_drvdata ((struct device *)context);int rc;u8 msg;drivers/platform/x86/amd-pmc.c +1
-1u32 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 );drivers/platform/x86/amd-pmc.c +5
-5if (rc) {@@ -681,28 +681,28 @@ static int __maybe_unused amd_pmc_suspend(struct device *dev)return rc; } -static int __maybe_unused amd_pmc_resume (struct device *dev) +static void amd_pmc_resume (void *context) { -struct amd_pmc_dev *pdev =dev_get_drvdata (dev); +struct amd_pmc_dev *pdev =dev_get_drvdata ((struct device *)context);int rc;u8 msg; 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 );/* 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) 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 */ drivers/platform/x86/amd-pmc.c +0
-7if (pdev->cpu_id ==AMD_CPU_ID_CZN )@@ -711,15 +711,8 @@ 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 const struct pci_device_id pmc_pci_ids[] = { {PCI_DEVICE (PCI_VENDOR_ID_AMD ,AMD_CPU_ID_YC ) },drivers/platform/x86/amd-pmc.c +6
-0{ PCI_DEVICE(PCI_VENDOR_ID_AMD, AMD_CPU_ID_CZN) },@@ -884,6 +877,12 @@ static int amd_pmc_probe(struct platform_device *pdev)amd_pmc_get_smu_version (dev);platform_set_drvdata (pdev, dev); + err =acpi_register_lps0_callbacks (amd_pmc_suspend, + amd_pmc_resume, + &pdev->dev); +if (err) + goto err_pci_dev_put; +amd_pmc_dbgfs_register (dev);cpu_latency_qos_add_request (&dev->amd_pmc_pm_qos_req,PM_QOS_DEFAULT_VALUE );drivers/platform/x86/amd-pmc.c +3
-1return 0 ;@@ -897,6 +896,9 @@ static int amd_pmc_remove(struct platform_device *pdev) {struct amd_pmc_dev *dev =platform_get_drvdata (pdev); +acpi_unregister_lps0_callbacks (amd_pmc_suspend, + amd_pmc_resume, + &pdev->dev);amd_pmc_dbgfs_unregister (dev);pci_dev_put (dev->rdev);mutex_destroy (&dev->lock);@@ -917,7 +919,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,
PATCH 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.
--- drivers/platform/x86/amd-pmc.c | 22 ---------------------- 1 file changed, 22 deletions(-)
drivers/platform/x86/amd-pmc.c +0 -22
@@ -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; }
@@ -675,9 +662,6 @@ static int amd_pmc_suspend(void *context, bool constraints_met)return 0 ; 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; }
@@ -704,11 +688,6 @@ static void amd_pmc_resume(void *context)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); }
@@ -884,7 +863,6 @@ static int amd_pmc_probe(struct platform_device *pdev) goto err_pci_dev_put;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
Hi Mario,
Quoted 19 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]>--- drivers/acpi/x86/s2idle.c | 76 ++++++++++++++++++++++++++++++++++++++- include/linux/acpi.h | 9 ++++- 2 files changed, 83 insertions(+), 2 deletions(-)drivers/acpi/x86/s2idle.c +0
-0
drivers/acpi/x86/s2idle.c struct lpi_device_constraint_amd { · line 94
Quoted 9 lines
drivers/acpi/x86/s2idle.c +6
-0@@ -86,6 +86,16 @@ struct lpi_device_constraint_amd {int min_dstate; }; +struct lps0_callback_handler { +struct list_head list_node; +int (*prepare_late_callback)(void *context); +void (*restore_early_callback)(void *context); +void *context; +};
Maybe put this in acpi.h
...
Quoted 52 lines
drivers/acpi/x86/s2idle.c +25
-1+ +static LIST_HEAD (lps0_callback_handler_head); +static DEFINE_MUTEX (lps0_callback_handler_mutex); +static struct lpi_constraints *lpi_constraints_table;static int lpi_constraints_table_size;static int rev_id;@@ -444,6 +454,9 @@ static struct acpi_scan_handler lps0_handler = {int acpi_s2idle_prepare_late (void ) { +struct lps0_callback_handler *handler; +int rc =0 ; +if (!lps0_device_handle || sleep_no_lps0)return 0 ;@@ -474,14 +487,31 @@ int acpi_s2idle_prepare_late(void)acpi_sleep_run_lps0_dsm (ACPI_LPS0_MS_ENTRY , lps0_dsm_func_mask_microsoft, lps0_dsm_guid_microsoft); } -return 0 ; + +mutex_lock (&lps0_callback_handler_mutex); +list_for_each_entry (handler, &lps0_callback_handler_head, list_node) { + rc = handler->prepare_late_callback (handler->context); +if (rc) + goto out; + } +out: +mutex_unlock (&lps0_callback_handler_mutex); + +return rc; }void acpi_s2idle_restore_early (void ) { +struct lps0_callback_handler *handler; +if (!lps0_device_handle || sleep_no_lps0)return ; +mutex_lock (&lps0_callback_handler_mutex); +list_for_each_entry (handler, &lps0_callback_handler_head, list_node) + handler->restore_early_callback (handler->context); +mutex_unlock (&lps0_callback_handler_mutex); +/* Modern standby exit */ if (lps0_dsm_func_mask_microsoft >0 )drivers/acpi/x86/s2idle.c +0
-0acpi_sleep_run_lps0_dsm(ACPI_LPS0_MS_EXIT,
drivers/acpi/x86/s2idle.c void acpi_s2idle_setup(void) · line 559
Quoted 6 lines
drivers/acpi/x86/s2idle.c +3
-0@@ -524,4 +554,48 @@ void acpi_s2idle_setup(void)s2idle_set_ops (&acpi_s2idle_ops_lps0); } +int acpi_register_lps0_callbacks (int (*prepare_late)(void *context), +void (*restore_early)(void *context), +void *context)
... and just have "struct lps0_callback_handler *handler" be the argument here.
David
Quoted 63 lines
drivers/acpi/x86/s2idle.c +41
-0+{ +struct lps0_callback_handler *handler; + +if (!lps0_device_handle || sleep_no_lps0) +return -ENODEV ; + + handler =kmalloc (sizeof (*handler),GFP_KERNEL ); +if (!handler) +return -ENOMEM ; + handler->prepare_late_callback = prepare_late; + handler->restore_early_callback = restore_early; + handler->context = context; + +mutex_lock (&lps0_callback_handler_mutex); +list_add (&handler->list_node, &lps0_callback_handler_head); +mutex_unlock (&lps0_callback_handler_mutex); + +return 0 ; +} +EXPORT_SYMBOL_GPL (acpi_register_lps0_callbacks); + +void acpi_unregister_lps0_callbacks (int (*prepare_late)(void *context), +void (*restore_early)(void *context), +void *context) +{ +struct lps0_callback_handler *handler; + +mutex_lock (&lps0_callback_handler_mutex); +list_for_each_entry (handler, &lps0_callback_handler_head, list_node) { +if (handler->prepare_late_callback == prepare_late && + handler->restore_early_callback == restore_early && + handler->context == context) { +list_del (&handler->list_node); +kfree (handler); +break ; + } + } +mutex_unlock (&lps0_callback_handler_mutex); +} +EXPORT_SYMBOL_GPL (acpi_unregister_lps0_callbacks); +#endif /* CONFIG_SUSPEND */ include/linux/acpi.h +8
-1@@ -1023,7 +1023,14 @@ 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 +int acpi_register_lps0_callbacks (int (*prepare_late)(void *context), +void (*restore_early)(void *context), +void *context); +void acpi_unregister_lps0_callbacks (int (*prepare_late)(void *context), +void (*restore_early)(void *context), +void *context); +#endif /* CONFIG_X86 */ #ifndef CONFIG_IA64 void arch_reserve_mem_area (acpi_physical_address addr,size_t size);#else
[Public]
Quoted 24 lines · Mario Limonciello
Quoted 11 lines
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]>--- drivers/acpi/x86/s2idle.c | 76++++++++++++++++++++++++++++++++++++++-
Quoted 11 lines
include/linux/acpi.h | 9 ++++- 2 files changed, 83 insertions(+), 2 deletions(-)drivers/acpi/x86/s2idle.c +0
-0@@ -86,6 +86,16 @@ struct lpi_device_constraint_amd {int min_dstate; };
Quoted 8 lines
drivers/acpi/x86/s2idle.c struct lpi_device_constraint_amd { · line 94
Quoted 6 lines
drivers/acpi/x86/s2idle.c +6
-0+struct lps0_callback_handler { +struct list_head list_node; +int (*prepare_late_callback)(void *context); +void (*restore_early_callback)(void *context); +void *context; +};Maybe put this in
acpi.h
Wonderful suggestion, thanks!
I'll adopt this for v2 after some other feedback comes in on the approach.
Quoted 135 lines
...
Quoted 18 lines
drivers/acpi/x86/s2idle.c +7
-0+ +static LIST_HEAD (lps0_callback_handler_head); +static DEFINE_MUTEX (lps0_callback_handler_mutex); +static struct lpi_constraints *lpi_constraints_table;static int lpi_constraints_table_size;static int rev_id;@@ -444,6 +454,9 @@ static struct acpi_scan_handler lps0_handler = {int acpi_s2idle_prepare_late (void ) { +struct lps0_callback_handler *handler; +int rc =0 ; +if (!lps0_device_handle || sleep_no_lps0)return 0 ;drivers/acpi/x86/s2idle.c int acpi_s2idle_prepare_late(void) · line 493
Quoted 8 lines
drivers/acpi/x86/s2idle.c +3
-1@@ -474,14 +487,31 @@ int acpi_s2idle_prepare_late(void)acpi_sleep_run_lps0_dsm (ACPI_LPS0_MS_ENTRY , lps0_dsm_func_mask_microsoft, lps0_dsm_guid_microsoft); } -return 0 ; + +mutex_lock (&lps0_callback_handler_mutex); + list_for_each_entry(handler, &lps0_callback_handler_head,
list_node) {Quoted 9 lines
drivers/acpi/x86/s2idle.c +8
-0+ rc = handler->prepare_late_callback (handler->context); +if (rc) + goto out; + } +out: +mutex_unlock (&lps0_callback_handler_mutex); + +return rc; }drivers/acpi/x86/s2idle.c int acpi_s2idle_prepare_late(void)
Quoted 10 lines
drivers/acpi/x86/s2idle.c +4
-0void acpi_s2idle_restore_early (void ) { +struct lps0_callback_handler *handler; +if (!lps0_device_handle || sleep_no_lps0)return ; +mutex_lock (&lps0_callback_handler_mutex); + list_for_each_entry(handler, &lps0_callback_handler_head,
list_node)drivers/acpi/x86/s2idle.c void acpi_s2idle_setup(void) · line 559
Quoted 13 lines
drivers/acpi/x86/s2idle.c +3
-0+ handler->restore_early_callback (handler->context); +mutex_unlock (&lps0_callback_handler_mutex); +/* Modern standby exit */ if (lps0_dsm_func_mask_microsoft >0 )drivers/acpi/x86/s2idle.c +3
-0acpi_sleep_run_lps0_dsm(ACPI_LPS0_MS_EXIT,@@ -524,4 +554,48 @@ void acpi_s2idle_setup(void)s2idle_set_ops (&acpi_s2idle_ops_lps0); } +int acpi_register_lps0_callbacks (int (*prepare_late)(void *context), +void (*restore_early)(void *context), +void *context)... and just have "struct
lps0_callback_handler*handler" be the argument here.David
Quoted 19 lines
drivers/acpi/x86/s2idle.c +19
-0+{ +struct lps0_callback_handler *handler; + +if (!lps0_device_handle || sleep_no_lps0) +return -ENODEV ; + + handler =kmalloc (sizeof (*handler),GFP_KERNEL ); +if (!handler) +return -ENOMEM ; + handler->prepare_late_callback = prepare_late; + handler->restore_early_callback = restore_early; + handler->context = context; + +mutex_lock (&lps0_callback_handler_mutex); +list_add (&handler->list_node, &lps0_callback_handler_head); +mutex_unlock (&lps0_callback_handler_mutex); + +return 0 ; +}drivers/acpi/x86/s2idle.c void acpi_s2idle_setup(void)
Quoted 10 lines
drivers/acpi/x86/s2idle.c +10
-0+EXPORT_SYMBOL_GPL (acpi_register_lps0_callbacks); + +void acpi_unregister_lps0_callbacks (int (*prepare_late)(void *context), +void (*restore_early)(void *context), +void *context) +{ +struct lps0_callback_handler *handler; + +mutex_lock (&lps0_callback_handler_mutex); + list_for_each_entry(handler, &lps0_callback_handler_head,
list_node) {include/linux/acpi.h void acpi_os_set_prepare_extended_sleep(int
Quoted 18 lines
drivers/acpi/x86/s2idle.c +12
-0+if (handler->prepare_late_callback == prepare_late && + handler->restore_early_callback == restore_early && + handler->context == context) { +list_del (&handler->list_node); +kfree (handler); +break ; + } + } +mutex_unlock (&lps0_callback_handler_mutex); +} +EXPORT_SYMBOL_GPL (acpi_unregister_lps0_callbacks); +#endif /* CONFIG_SUSPEND */ include/linux/acpi.h +0
-0@@ -1023,7 +1023,14 @@ void acpi_os_set_prepare_extended_sleep(int(*func)(u8
Quoted 16 lines
include/linux/acpi.h +8
-1sleep_state, acpi_status acpi_os_prepare_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b); - +#ifdef CONFIG_X86 +int acpi_register_lps0_callbacks (int (*prepare_late)(void *context), +void (*restore_early)(void *context), +void *context); +void acpi_unregister_lps0_callbacks (int (*prepare_late)(void *context), +void (*restore_early)(void *context), +void *context); +#endif /* CONFIG_X86 */ #ifndef CONFIG_IA64 void arch_reserve_mem_area (acpi_physical_address addr,size_t size);#else