xref: /linux/arch/loongarch/kernel/reset.c (revision 24bce201d79807b668bf9d9e0aca801c5c0d5f78)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
4  */
5 #include <linux/kernel.h>
6 #include <linux/acpi.h>
7 #include <linux/efi.h>
8 #include <linux/export.h>
9 #include <linux/pm.h>
10 #include <linux/types.h>
11 #include <linux/reboot.h>
12 #include <linux/delay.h>
13 #include <linux/console.h>
14 
15 #include <acpi/reboot.h>
16 #include <asm/compiler.h>
17 #include <asm/idle.h>
18 #include <asm/loongarch.h>
19 #include <asm/reboot.h>
20 
21 static void default_halt(void)
22 {
23 	local_irq_disable();
24 	clear_csr_ecfg(ECFG0_IM);
25 
26 	pr_notice("\n\n** You can safely turn off the power now **\n\n");
27 	console_flush_on_panic(CONSOLE_FLUSH_PENDING);
28 
29 	while (true) {
30 		__arch_cpu_idle();
31 	}
32 }
33 
34 static void default_poweroff(void)
35 {
36 #ifdef CONFIG_EFI
37 	efi.reset_system(EFI_RESET_SHUTDOWN, EFI_SUCCESS, 0, NULL);
38 #endif
39 	while (true) {
40 		__arch_cpu_idle();
41 	}
42 }
43 
44 static void default_restart(void)
45 {
46 #ifdef CONFIG_EFI
47 	if (efi_capsule_pending(NULL))
48 		efi_reboot(REBOOT_WARM, NULL);
49 	else
50 		efi_reboot(REBOOT_COLD, NULL);
51 #endif
52 	if (!acpi_disabled)
53 		acpi_reboot();
54 
55 	while (true) {
56 		__arch_cpu_idle();
57 	}
58 }
59 
60 void (*pm_restart)(void);
61 EXPORT_SYMBOL(pm_restart);
62 
63 void (*pm_power_off)(void);
64 EXPORT_SYMBOL(pm_power_off);
65 
66 void machine_halt(void)
67 {
68 #ifdef CONFIG_SMP
69 	preempt_disable();
70 	smp_send_stop();
71 #endif
72 	default_halt();
73 }
74 
75 void machine_power_off(void)
76 {
77 #ifdef CONFIG_SMP
78 	preempt_disable();
79 	smp_send_stop();
80 #endif
81 	pm_power_off();
82 }
83 
84 void machine_restart(char *command)
85 {
86 #ifdef CONFIG_SMP
87 	preempt_disable();
88 	smp_send_stop();
89 #endif
90 	do_kernel_restart(command);
91 	pm_restart();
92 }
93 
94 static int __init loongarch_reboot_setup(void)
95 {
96 	pm_restart = default_restart;
97 	pm_power_off = default_poweroff;
98 
99 	return 0;
100 }
101 
102 arch_initcall(loongarch_reboot_setup);
103