Skip to contentSkip to conversation

riscv: set default pm_power_off to NULL

PATCH In review Dimitri John Ledkov 4 participants 4 messages Sep 7, 2021 – Oct 3, 2021 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 riscv: set default pm_power_off to NULL

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.

---
 arch/riscv/kernel/reset.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
arch/riscv/kernel/reset.c +9 -3
index ee5878d968..9c842c4168 100644
@@ -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();
 }
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Dimitri John Ledkov

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.

Quoted 5 lines

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

Looks good to me.

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

Regards,
Anup

Quoted 39 lines
---
 arch/riscv/kernel/reset.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
arch/riscv/kernel/reset.c +9 -4
index ee5878d968..9c842c4168 100644
@@ -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

Tested-by on v1 1/1
#2 lore raw
In reply to Dimitri John Ledkov
Quoted 43 lines · Dimitri John Ledkov

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.

---
  arch/riscv/kernel/reset.c | 12 +++++++++---
  1 file changed, 9 insertions(+), 3 deletions(-)
arch/riscv/kernel/reset.c +5 -2
index ee5878d968..9c842c4168 100644
@@ -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();

arch/riscv/kernel/reset.c void machine_restart(char *cmd) · line 38

Quoted 10 lines
arch/riscv/kernel/reset.c +4 -1
  }
 
  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

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

maintainer
#3 lore raw
In reply to Dimitri John Ledkov
Quoted 43 lines · On Mon, 06 Sep 2021 17:28:47 PDT (-0700), [email protected] 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.

---
 arch/riscv/kernel/reset.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
arch/riscv/kernel/reset.c +5 -2
index ee5878d968..9c842c4168 100644
@@ -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();

arch/riscv/kernel/reset.c void machine_restart(char *cmd) · line 38

Quoted 10 lines
arch/riscv/kernel/reset.c +4 -1
 }
 
 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.