^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * License. See the file "COPYING" in the main directory of this archive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2001, 06 by Ralf Baechle (ralf@linux-mips.org)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 2001 MIPS Technologies, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/pm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <asm/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <asm/idle.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <asm/mipsregs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <asm/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * Urgs ... Too many MIPS machines to handle this in a generic way.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * So handle all using function pointers to machine specific
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) void (*_machine_restart)(char *command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) void (*_machine_halt)(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) void (*pm_power_off)(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) EXPORT_SYMBOL(pm_power_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static void machine_hang(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * We're hanging the system so we don't want to be interrupted anymore.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * Any interrupt handlers that ran would at best be useless & at worst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * go awry because the system isn't in a functional state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) local_irq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * Mask all interrupts, giving us a better chance of remaining in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * low power wait state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) clear_c0_status(ST0_IM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) while (true) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) if (cpu_has_mips_r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * We know that the wait instruction is supported so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * make use of it directly, leaving interrupts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * disabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) asm volatile(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) ".set push\n\t"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) ".set " MIPS_ISA_ARCH_LEVEL "\n\t"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) "wait\n\t"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) ".set pop");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) } else if (cpu_wait) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * Try the cpu_wait() callback. This isn't ideal since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * it'll re-enable interrupts, but that ought to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * harmless given that they're all masked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) cpu_wait();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) local_irq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * We're going to burn some power running round the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * loop, but we don't really have a choice. This isn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * a path we should expect to run for long during
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * typical use anyway.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * In most modern MIPS CPUs interrupts will cause the wait
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * instruction to graduate even when disabled, and in some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * cases even when masked. In order to prevent a timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * interrupt from continuously taking us out of the low power
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * wait state, we clear any pending timer interrupt here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) if (cpu_has_counter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) write_c0_compare(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) void machine_restart(char *command)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (_machine_restart)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) _machine_restart(command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) preempt_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) smp_send_stop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) do_kernel_restart(command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) mdelay(1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) pr_emerg("Reboot failed -- System halted\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) machine_hang();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) void machine_halt(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (_machine_halt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) _machine_halt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) preempt_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) smp_send_stop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) machine_hang();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) void machine_power_off(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (pm_power_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) pm_power_off();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) preempt_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) smp_send_stop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) machine_hang();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }