All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] ACPI / PM: Use register_reboot_notifier() instead of pm_power_off_prepare
@ 2018-03-21 11:30 Baolin Wang
  2018-03-21 11:30 ` [PATCH 2/2] kernel / reboot: Remove the pm_power_off_prepare hook Baolin Wang
  2018-03-21 14:04 ` [PATCH 1/2] ACPI / PM: Use register_reboot_notifier() instead of pm_power_off_prepare Pavel Machek
  0 siblings, 2 replies; 4+ messages in thread
From: Baolin Wang @ 2018-03-21 11:30 UTC (permalink / raw)
  To: rjw, lenb, pavel
  Cc: andrew.smirnov, akpm, broonie, arnd, linux-acpi, linux-kernel,
	linux-pm, baolin.wang

We can register one notifier through register_reboot_notifier() function to
prepare to power off the system, then we can remove the 'pm_power_off_prepare'
hook in following patch.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
Note: Please help to review carefully, since I have no platform to test
this conversion.

I saw there is another reboot notifier in this driver, I am not sure the
orders between them. I can change the priority of notifier to keep their
orders if it is necessary.
---
 drivers/acpi/sleep.c |   22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
index 46cde091..b3de894 100644
--- a/drivers/acpi/sleep.c
+++ b/drivers/acpi/sleep.c
@@ -1229,14 +1229,24 @@ static void acpi_sleep_hibernate_setup(void)
 static inline void acpi_sleep_hibernate_setup(void) {}
 #endif /* !CONFIG_HIBERNATION */
 
-static void acpi_power_off_prepare(void)
+static int acpi_reboot_notify(struct notifier_block *this, unsigned long code,
+			      void *x)
 {
-	/* Prepare to power off the system */
-	acpi_sleep_prepare(ACPI_STATE_S5);
-	acpi_disable_all_gpes();
-	acpi_os_wait_events_complete();
+	if (code == SYSTEM_POWER_OFF) {
+		/* Prepare to power off the system */
+		acpi_sleep_prepare(ACPI_STATE_S5);
+		acpi_disable_all_gpes();
+		acpi_os_wait_events_complete();
+	}
+
+	return NOTIFY_DONE;
 }
 
+static struct notifier_block acpi_reboot_notifier = {
+	.notifier_call	= acpi_reboot_notify,
+	.priority	= 0,
+};
+
 static void acpi_power_off(void)
 {
 	/* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
@@ -1261,7 +1271,7 @@ int __init acpi_sleep_init(void)
 
 	if (acpi_sleep_state_supported(ACPI_STATE_S5)) {
 		sleep_states[ACPI_STATE_S5] = 1;
-		pm_power_off_prepare = acpi_power_off_prepare;
+		register_reboot_notifier(&acpi_reboot_notifier);
 		pm_power_off = acpi_power_off;
 	} else {
 		acpi_no_s5 = true;
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] kernel / reboot: Remove the pm_power_off_prepare hook
  2018-03-21 11:30 [PATCH 1/2] ACPI / PM: Use register_reboot_notifier() instead of pm_power_off_prepare Baolin Wang
@ 2018-03-21 11:30 ` Baolin Wang
  2018-03-21 14:04 ` [PATCH 1/2] ACPI / PM: Use register_reboot_notifier() instead of pm_power_off_prepare Pavel Machek
  1 sibling, 0 replies; 4+ messages in thread
From: Baolin Wang @ 2018-03-21 11:30 UTC (permalink / raw)
  To: rjw, lenb, pavel
  Cc: andrew.smirnov, akpm, broonie, arnd, linux-acpi, linux-kernel,
	linux-pm, baolin.wang

There are no users will prepare to power off system by 'pm_power_off_prepare'
hook, thus we can remove it now.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
 include/linux/pm.h |    1 -
 kernel/reboot.c    |    8 --------
 2 files changed, 9 deletions(-)

diff --git a/include/linux/pm.h b/include/linux/pm.h
index e723b78..cff7668 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -32,7 +32,6 @@
  * Callbacks for platform drivers to implement.
  */
 extern void (*pm_power_off)(void);
-extern void (*pm_power_off_prepare)(void);
 
 struct device; /* we have a circular dep with device.h */
 #ifdef CONFIG_VT_CONSOLE_SLEEP
diff --git a/kernel/reboot.c b/kernel/reboot.c
index e4ced88..6667b63 100644
--- a/kernel/reboot.c
+++ b/kernel/reboot.c
@@ -44,12 +44,6 @@
 enum reboot_type reboot_type = BOOT_ACPI;
 int reboot_force;
 
-/*
- * If set, this is used for preparing the system to power off.
- */
-
-void (*pm_power_off_prepare)(void);
-
 /**
  *	emergency_restart - reboot the system
  *
@@ -284,8 +278,6 @@ void kernel_halt(void)
 void kernel_power_off(void)
 {
 	kernel_shutdown_prepare(SYSTEM_POWER_OFF);
-	if (pm_power_off_prepare)
-		pm_power_off_prepare();
 	migrate_to_reboot_cpu();
 	syscore_shutdown();
 	pr_emerg("Power down\n");
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] ACPI / PM: Use register_reboot_notifier() instead of pm_power_off_prepare
  2018-03-21 11:30 [PATCH 1/2] ACPI / PM: Use register_reboot_notifier() instead of pm_power_off_prepare Baolin Wang
  2018-03-21 11:30 ` [PATCH 2/2] kernel / reboot: Remove the pm_power_off_prepare hook Baolin Wang
@ 2018-03-21 14:04 ` Pavel Machek
  2018-03-22  2:23   ` Baolin Wang
  1 sibling, 1 reply; 4+ messages in thread
From: Pavel Machek @ 2018-03-21 14:04 UTC (permalink / raw)
  To: Baolin Wang
  Cc: rjw, lenb, andrew.smirnov, akpm, broonie, arnd, linux-acpi,
	linux-kernel, linux-pm

[-- Attachment #1: Type: text/plain, Size: 2447 bytes --]

On Wed 2018-03-21 19:30:16, Baolin Wang wrote:
> We can register one notifier through register_reboot_notifier() function to
> prepare to power off the system, then we can remove the 'pm_power_off_prepare'
> hook in following patch.
> 
> Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
> ---
> Note: Please help to review carefully, since I have no platform to test
> this conversion.
> 
> I saw there is another reboot notifier in this driver, I am not sure the
> orders between them. I can change the priority of notifier to keep their
> orders if it is necessary.

I don't understand why this is good idea... and you should really test
it. I'm sure you can find PC or notebook somewhere...
								Pavel

>  drivers/acpi/sleep.c |   22 ++++++++++++++++------
>  1 file changed, 16 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
> index 46cde091..b3de894 100644
> --- a/drivers/acpi/sleep.c
> +++ b/drivers/acpi/sleep.c
> @@ -1229,14 +1229,24 @@ static void acpi_sleep_hibernate_setup(void)
>  static inline void acpi_sleep_hibernate_setup(void) {}
>  #endif /* !CONFIG_HIBERNATION */
>  
> -static void acpi_power_off_prepare(void)
> +static int acpi_reboot_notify(struct notifier_block *this, unsigned long code,
> +			      void *x)
>  {
> -	/* Prepare to power off the system */
> -	acpi_sleep_prepare(ACPI_STATE_S5);
> -	acpi_disable_all_gpes();
> -	acpi_os_wait_events_complete();
> +	if (code == SYSTEM_POWER_OFF) {
> +		/* Prepare to power off the system */
> +		acpi_sleep_prepare(ACPI_STATE_S5);
> +		acpi_disable_all_gpes();
> +		acpi_os_wait_events_complete();
> +	}
> +
> +	return NOTIFY_DONE;
>  }
>  
> +static struct notifier_block acpi_reboot_notifier = {
> +	.notifier_call	= acpi_reboot_notify,
> +	.priority	= 0,
> +};
> +
>  static void acpi_power_off(void)
>  {
>  	/* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
> @@ -1261,7 +1271,7 @@ int __init acpi_sleep_init(void)
>  
>  	if (acpi_sleep_state_supported(ACPI_STATE_S5)) {
>  		sleep_states[ACPI_STATE_S5] = 1;
> -		pm_power_off_prepare = acpi_power_off_prepare;
> +		register_reboot_notifier(&acpi_reboot_notifier);
>  		pm_power_off = acpi_power_off;
>  	} else {
>  		acpi_no_s5 = true;

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] ACPI / PM: Use register_reboot_notifier() instead of pm_power_off_prepare
  2018-03-21 14:04 ` [PATCH 1/2] ACPI / PM: Use register_reboot_notifier() instead of pm_power_off_prepare Pavel Machek
@ 2018-03-22  2:23   ` Baolin Wang
  0 siblings, 0 replies; 4+ messages in thread
From: Baolin Wang @ 2018-03-22  2:23 UTC (permalink / raw)
  To: Pavel Machek
  Cc: rjw, Len Brown, Andrey Smirnov, Andrew Morton, Mark Brown,
	Arnd Bergmann, linux-acpi, LKML, Linux PM list

Hi Pavel,

On 21 March 2018 at 22:04, Pavel Machek <pavel@ucw.cz> wrote:
> On Wed 2018-03-21 19:30:16, Baolin Wang wrote:
>> We can register one notifier through register_reboot_notifier() function to
>> prepare to power off the system, then we can remove the 'pm_power_off_prepare'
>> hook in following patch.
>>
>> Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
>> ---
>> Note: Please help to review carefully, since I have no platform to test
>> this conversion.
>>
>> I saw there is another reboot notifier in this driver, I am not sure the
>> orders between them. I can change the priority of notifier to keep their
>> orders if it is necessary.
>
> I don't understand why this is good idea... and you should really test
> it. I'm sure you can find PC or notebook somewhere...

I want to test it, but I have no opensource board with x86
architecture. But I will try to find one or ask other guys to help to
test it. Thanks for your comments.

>>  drivers/acpi/sleep.c |   22 ++++++++++++++++------
>>  1 file changed, 16 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
>> index 46cde091..b3de894 100644
>> --- a/drivers/acpi/sleep.c
>> +++ b/drivers/acpi/sleep.c
>> @@ -1229,14 +1229,24 @@ static void acpi_sleep_hibernate_setup(void)
>>  static inline void acpi_sleep_hibernate_setup(void) {}
>>  #endif /* !CONFIG_HIBERNATION */
>>
>> -static void acpi_power_off_prepare(void)
>> +static int acpi_reboot_notify(struct notifier_block *this, unsigned long code,
>> +                           void *x)
>>  {
>> -     /* Prepare to power off the system */
>> -     acpi_sleep_prepare(ACPI_STATE_S5);
>> -     acpi_disable_all_gpes();
>> -     acpi_os_wait_events_complete();
>> +     if (code == SYSTEM_POWER_OFF) {
>> +             /* Prepare to power off the system */
>> +             acpi_sleep_prepare(ACPI_STATE_S5);
>> +             acpi_disable_all_gpes();
>> +             acpi_os_wait_events_complete();
>> +     }
>> +
>> +     return NOTIFY_DONE;
>>  }
>>
>> +static struct notifier_block acpi_reboot_notifier = {
>> +     .notifier_call  = acpi_reboot_notify,
>> +     .priority       = 0,
>> +};
>> +
>>  static void acpi_power_off(void)
>>  {
>>       /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
>> @@ -1261,7 +1271,7 @@ int __init acpi_sleep_init(void)
>>
>>       if (acpi_sleep_state_supported(ACPI_STATE_S5)) {
>>               sleep_states[ACPI_STATE_S5] = 1;
>> -             pm_power_off_prepare = acpi_power_off_prepare;
>> +             register_reboot_notifier(&acpi_reboot_notifier);
>>               pm_power_off = acpi_power_off;
>>       } else {
>>               acpi_no_s5 = true;
>
> --
> (english) http://www.livejournal.com/~pavelmachek
> (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html



-- 
Baolin.wang
Best Regards

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-03-22  2:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-21 11:30 [PATCH 1/2] ACPI / PM: Use register_reboot_notifier() instead of pm_power_off_prepare Baolin Wang
2018-03-21 11:30 ` [PATCH 2/2] kernel / reboot: Remove the pm_power_off_prepare hook Baolin Wang
2018-03-21 14:04 ` [PATCH 1/2] ACPI / PM: Use register_reboot_notifier() instead of pm_power_off_prepare Pavel Machek
2018-03-22  2:23   ` Baolin Wang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.