Skip to content

Commit

Permalink
MIPS: Loongson64: reset: Prioritise firmware service
Browse files Browse the repository at this point in the history
commit 4e7ca0b upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
FlyGoat authored and gregkh committed Aug 3, 2024
1 parent 690d62d commit 6c695c3
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions arch/mips/loongson64/reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -21,36 +22,21 @@
#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
Expand Down Expand Up @@ -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
kexec_argv = kmalloc(KEXEC_ARGV_SIZE, GFP_KERNEL);
Expand Down

0 comments on commit 6c695c3

Please sign in to comment.