linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] riscv: set default pm_power_off to NULL
@ 2021-09-07  0:28 Dimitri John Ledkov
  2021-09-07  3:36 ` Anup Patel
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Dimitri John Ledkov @ 2021-09-07  0:28 UTC (permalink / raw)
  To: linux-riscv; +Cc: paul.walmsley, palmer, aou, linux-kernel

Set pm_power_off to NULL like on all other architectures, check if it
is set in machine_halt() and machine_power_off() and fallback to
default_power_off if no other power driver got registered.

This brings riscv architecture inline with all other architectures,
and allows to reuse exiting power drivers unmodified.

Kernels without legacy SBI v0.1 extensions (CONFIG_RISCV_SBI_V01 is
not set), do not set pm_power_off to sbi_shutdown(). There is no
support for SBI v0.3 system reset extension either. This prevents
using gpio_poweroff on SiFive HiFive Unmatched.

Tested on SiFive HiFive unmatched, with a dtb specifying gpio-poweroff
node and kernel complied without CONFIG_RISCV_SBI_V01.

BugLink: https://bugs.launchpad.net/bugs/1942806
Signed-off-by: Dimitri John Ledkov <dimitri.ledkov@canonical.com>
---
 arch/riscv/kernel/reset.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/arch/riscv/kernel/reset.c b/arch/riscv/kernel/reset.c
index ee5878d968..9c842c4168 100644
--- a/arch/riscv/kernel/reset.c
+++ b/arch/riscv/kernel/reset.c
@@ -12,7 +12,7 @@ static void default_power_off(void)
 		wait_for_interrupt();
 }
 
-void (*pm_power_off)(void) = default_power_off;
+void (*pm_power_off)(void) = NULL;
 EXPORT_SYMBOL(pm_power_off);
 
 void machine_restart(char *cmd)
@@ -23,10 +23,16 @@ void machine_restart(char *cmd)
 
 void machine_halt(void)
 {
-	pm_power_off();
+	if (pm_power_off != NULL)
+		pm_power_off();
+	else
+		default_power_off();
 }
 
 void machine_power_off(void)
 {
-	pm_power_off();
+	if (pm_power_off != NULL)
+		pm_power_off();
+	else
+		default_power_off();
 }
-- 
2.30.2


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

* Re: [PATCH] riscv: set default pm_power_off to NULL
  2021-09-07  0:28 [PATCH] riscv: set default pm_power_off to NULL Dimitri John Ledkov
@ 2021-09-07  3:36 ` Anup Patel
  2021-09-09  5:11 ` Ron Economos
  2021-10-03 17:10 ` Palmer Dabbelt
  2 siblings, 0 replies; 4+ messages in thread
From: Anup Patel @ 2021-09-07  3:36 UTC (permalink / raw)
  To: Dimitri John Ledkov
  Cc: linux-riscv, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	linux-kernel@vger.kernel.org List

On Tue, Sep 7, 2021 at 5:59 AM Dimitri John Ledkov
<dimitri.ledkov@canonical.com> wrote:
>
> Set pm_power_off to NULL like on all other architectures, check if it
> is set in machine_halt() and machine_power_off() and fallback to
> default_power_off if no other power driver got registered.
>
> This brings riscv architecture inline with all other architectures,
> and allows to reuse exiting power drivers unmodified.
>
> Kernels without legacy SBI v0.1 extensions (CONFIG_RISCV_SBI_V01 is
> not set), do not set pm_power_off to sbi_shutdown(). There is no
> support for SBI v0.3 system reset extension either. This prevents
> using gpio_poweroff on SiFive HiFive Unmatched.
>
> Tested on SiFive HiFive unmatched, with a dtb specifying gpio-poweroff
> node and kernel complied without CONFIG_RISCV_SBI_V01.
>
> BugLink: https://bugs.launchpad.net/bugs/1942806
> Signed-off-by: Dimitri John Ledkov <dimitri.ledkov@canonical.com>

Looks good to me.

Reviewed-by: Anup Patel <anup@brainfault.org>

BTW, SBI v0.3 system reset patch can be merged any day
because SBI v0.3 spec is already released.

Regards,
Anup

> ---
>  arch/riscv/kernel/reset.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/arch/riscv/kernel/reset.c b/arch/riscv/kernel/reset.c
> index ee5878d968..9c842c4168 100644
> --- a/arch/riscv/kernel/reset.c
> +++ b/arch/riscv/kernel/reset.c
> @@ -12,7 +12,7 @@ static void default_power_off(void)
>                 wait_for_interrupt();
>  }
>
> -void (*pm_power_off)(void) = default_power_off;
> +void (*pm_power_off)(void) = NULL;
>  EXPORT_SYMBOL(pm_power_off);
>
>  void machine_restart(char *cmd)
> @@ -23,10 +23,16 @@ void machine_restart(char *cmd)
>
>  void machine_halt(void)
>  {
> -       pm_power_off();
> +       if (pm_power_off != NULL)
> +               pm_power_off();
> +       else
> +               default_power_off();
>  }
>
>  void machine_power_off(void)
>  {
> -       pm_power_off();
> +       if (pm_power_off != NULL)
> +               pm_power_off();
> +       else
> +               default_power_off();
>  }
> --
> 2.30.2
>

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

* Re: [PATCH] riscv: set default pm_power_off to NULL
  2021-09-07  0:28 [PATCH] riscv: set default pm_power_off to NULL Dimitri John Ledkov
  2021-09-07  3:36 ` Anup Patel
@ 2021-09-09  5:11 ` Ron Economos
  2021-10-03 17:10 ` Palmer Dabbelt
  2 siblings, 0 replies; 4+ messages in thread
From: Ron Economos @ 2021-09-09  5:11 UTC (permalink / raw)
  To: Dimitri John Ledkov, linux-riscv; +Cc: paul.walmsley, palmer, aou, linux-kernel

On 9/6/21 5:28 PM, Dimitri John Ledkov wrote:

> Set pm_power_off to NULL like on all other architectures, check if it
> is set in machine_halt() and machine_power_off() and fallback to
> default_power_off if no other power driver got registered.
>
> This brings riscv architecture inline with all other architectures,
> and allows to reuse exiting power drivers unmodified.
>
> Kernels without legacy SBI v0.1 extensions (CONFIG_RISCV_SBI_V01 is
> not set), do not set pm_power_off to sbi_shutdown(). There is no
> support for SBI v0.3 system reset extension either. This prevents
> using gpio_poweroff on SiFive HiFive Unmatched.
>
> Tested on SiFive HiFive unmatched, with a dtb specifying gpio-poweroff
> node and kernel complied without CONFIG_RISCV_SBI_V01.
>
> BugLink: https://bugs.launchpad.net/bugs/1942806
> Signed-off-by: Dimitri John Ledkov <dimitri.ledkov@canonical.com>
> ---
>   arch/riscv/kernel/reset.c | 12 +++++++++---
>   1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/arch/riscv/kernel/reset.c b/arch/riscv/kernel/reset.c
> index ee5878d968..9c842c4168 100644
> --- a/arch/riscv/kernel/reset.c
> +++ b/arch/riscv/kernel/reset.c
> @@ -12,7 +12,7 @@ static void default_power_off(void)
>   		wait_for_interrupt();
>   }
>   
> -void (*pm_power_off)(void) = default_power_off;
> +void (*pm_power_off)(void) = NULL;
>   EXPORT_SYMBOL(pm_power_off);
>   
>   void machine_restart(char *cmd)
> @@ -23,10 +23,16 @@ void machine_restart(char *cmd)
>   
>   void machine_halt(void)
>   {
> -	pm_power_off();
> +	if (pm_power_off != NULL)
> +		pm_power_off();
> +	else
> +		default_power_off();
>   }
>   
>   void machine_power_off(void)
>   {
> -	pm_power_off();
> +	if (pm_power_off != NULL)
> +		pm_power_off();
> +	else
> +		default_power_off();
>   }

Works good here. Tested on HiFive Unmatched, Ubuntu 21.04 and kernel 5.14.2

Tested-by: Ron Economos <w6rz@comcast.net>



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

* Re: [PATCH] riscv: set default pm_power_off to NULL
  2021-09-07  0:28 [PATCH] riscv: set default pm_power_off to NULL Dimitri John Ledkov
  2021-09-07  3:36 ` Anup Patel
  2021-09-09  5:11 ` Ron Economos
@ 2021-10-03 17:10 ` Palmer Dabbelt
  2 siblings, 0 replies; 4+ messages in thread
From: Palmer Dabbelt @ 2021-10-03 17:10 UTC (permalink / raw)
  To: dimitri.ledkov; +Cc: linux-riscv, Paul Walmsley, aou, linux-kernel

On Mon, 06 Sep 2021 17:28:47 PDT (-0700), dimitri.ledkov@canonical.com wrote:
> Set pm_power_off to NULL like on all other architectures, check if it
> is set in machine_halt() and machine_power_off() and fallback to
> default_power_off if no other power driver got registered.
>
> This brings riscv architecture inline with all other architectures,
> and allows to reuse exiting power drivers unmodified.
>
> Kernels without legacy SBI v0.1 extensions (CONFIG_RISCV_SBI_V01 is
> not set), do not set pm_power_off to sbi_shutdown(). There is no
> support for SBI v0.3 system reset extension either. This prevents
> using gpio_poweroff on SiFive HiFive Unmatched.
>
> Tested on SiFive HiFive unmatched, with a dtb specifying gpio-poweroff
> node and kernel complied without CONFIG_RISCV_SBI_V01.
>
> BugLink: https://bugs.launchpad.net/bugs/1942806
> Signed-off-by: Dimitri John Ledkov <dimitri.ledkov@canonical.com>
> ---
>  arch/riscv/kernel/reset.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/arch/riscv/kernel/reset.c b/arch/riscv/kernel/reset.c
> index ee5878d968..9c842c4168 100644
> --- a/arch/riscv/kernel/reset.c
> +++ b/arch/riscv/kernel/reset.c
> @@ -12,7 +12,7 @@ static void default_power_off(void)
>  		wait_for_interrupt();
>  }
>
> -void (*pm_power_off)(void) = default_power_off;
> +void (*pm_power_off)(void) = NULL;
>  EXPORT_SYMBOL(pm_power_off);
>
>  void machine_restart(char *cmd)
> @@ -23,10 +23,16 @@ void machine_restart(char *cmd)
>
>  void machine_halt(void)
>  {
> -	pm_power_off();
> +	if (pm_power_off != NULL)
> +		pm_power_off();
> +	else
> +		default_power_off();
>  }
>
>  void machine_power_off(void)
>  {
> -	pm_power_off();
> +	if (pm_power_off != NULL)
> +		pm_power_off();
> +	else
> +		default_power_off();
>  }

Thanks, this is on for-next.

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

end of thread, other threads:[~2021-10-03 17:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-07  0:28 [PATCH] riscv: set default pm_power_off to NULL Dimitri John Ledkov
2021-09-07  3:36 ` Anup Patel
2021-09-09  5:11 ` Ron Economos
2021-10-03 17:10 ` Palmer Dabbelt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).