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/idle.h> 17 #include <asm/loongarch.h> 18 19 void (*pm_power_off)(void); 20 EXPORT_SYMBOL(pm_power_off); 21 machine_halt(void)22void machine_halt(void) 23 { 24 #ifdef CONFIG_SMP 25 preempt_disable(); 26 smp_send_stop(); 27 #endif 28 local_irq_disable(); 29 clear_csr_ecfg(ECFG0_IM); 30 31 pr_notice("\n\n** You can safely turn off the power now **\n\n"); 32 console_flush_on_panic(CONSOLE_FLUSH_PENDING); 33 34 while (true) { 35 __arch_cpu_idle(); 36 } 37 } 38 machine_power_off(void)39void machine_power_off(void) 40 { 41 #ifdef CONFIG_SMP 42 preempt_disable(); 43 smp_send_stop(); 44 #endif 45 do_kernel_power_off(); 46 #ifdef CONFIG_EFI 47 efi.reset_system(EFI_RESET_SHUTDOWN, EFI_SUCCESS, 0, NULL); 48 #endif 49 50 while (true) { 51 __arch_cpu_idle(); 52 } 53 } 54 machine_restart(char * command)55void machine_restart(char *command) 56 { 57 #ifdef CONFIG_SMP 58 preempt_disable(); 59 smp_send_stop(); 60 #endif 61 do_kernel_restart(command); 62 #ifdef CONFIG_EFI 63 if (efi_capsule_pending(NULL)) 64 efi_reboot(REBOOT_WARM, NULL); 65 else 66 efi_reboot(REBOOT_COLD, NULL); 67 #endif 68 if (!acpi_disabled) 69 acpi_reboot(); 70 71 while (true) { 72 __arch_cpu_idle(); 73 } 74 } 75