]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
MIPS: Loongson64: reset: Prioritise firmware service
authorJiaxun Yang <jiaxun.yang@flygoat.com>
Fri, 14 Jun 2024 15:40:16 +0000 (16:40 +0100)
committerThomas Bogendoerfer <tsbogend@alpha.franken.de>
Fri, 21 Jun 2024 08:22:10 +0000 (10:22 +0200)
We should always use firmware's poweroff & reboot service
if it's available as firmware may need to perform more task
than platform's syscon etc.

However _machine_restart & poweroff hooks are registered at
low priority, which means platform reboot driver can override
them.

Register firmware based reboot/poweroff implementation with
register_sys_off_handler with appropriate priority so that
they will be prioritised. Remove _machine_halt hook as it's
deemed to be unnecessary.

Cc: stable@vger.kernel.org
Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
arch/mips/loongson64/reset.c

index e01c8d4a805a91586e9ba09a686fa1ca89672280..3e20ade0503ad78956f2d2056799945a00da612a 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/init.h>
 #include <linux/kexec.h>
 #include <linux/pm.h>
+#include <linux/reboot.h>
 #include <linux/slab.h>
 
 #include <asm/bootinfo.h>
 #include <loongson.h>
 #include <boot_param.h>
 
-static void loongson_restart(char *command)
+static int firmware_restart(struct sys_off_data *unusedd)
 {
 
        void (*fw_restart)(void) = (void *)loongson_sysconf.restart_addr;
 
        fw_restart();
-       while (1) {
-               if (cpu_wait)
-                       cpu_wait();
-       }
+       return NOTIFY_DONE;
 }
 
-static void loongson_poweroff(void)
+static int firmware_poweroff(struct sys_off_data *unused)
 {
        void (*fw_poweroff)(void) = (void *)loongson_sysconf.poweroff_addr;
 
        fw_poweroff();
-       while (1) {
-               if (cpu_wait)
-                       cpu_wait();
-       }
-}
-
-static void loongson_halt(void)
-{
-       pr_notice("\n\n** You can safely turn off the power now **\n\n");
-       while (1) {
-               if (cpu_wait)
-                       cpu_wait();
-       }
+       return NOTIFY_DONE;
 }
 
 #ifdef CONFIG_KEXEC_CORE
@@ -154,9 +140,17 @@ static void loongson_crash_shutdown(struct pt_regs *regs)
 
 static int __init mips_reboot_setup(void)
 {
-       _machine_restart = loongson_restart;
-       _machine_halt = loongson_halt;
-       pm_power_off = loongson_poweroff;
+       if (loongson_sysconf.restart_addr) {
+               register_sys_off_handler(SYS_OFF_MODE_RESTART,
+                                SYS_OFF_PRIO_FIRMWARE,
+                                firmware_restart, NULL);
+       }
+
+       if (loongson_sysconf.poweroff_addr) {
+               register_sys_off_handler(SYS_OFF_MODE_POWER_OFF,
+                                SYS_OFF_PRIO_FIRMWARE,
+                                firmware_poweroff, NULL);
+       }
 
 #ifdef CONFIG_KEXEC_CORE
        kexec_argv = kmalloc(KEXEC_ARGV_SIZE, GFP_KERNEL);