Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
David S. Miller | cdb3592 | 2008-09-01 19:31:16 -0700 | [diff] [blame] | 2 | /* reboot.c: reboot/shutdown/halt/poweroff handling |
| 3 | * |
| 4 | * Copyright (C) 2008 David S. Miller <davem@davemloft.net> |
| 5 | */ |
| 6 | #include <linux/kernel.h> |
| 7 | #include <linux/reboot.h> |
Paul Gortmaker | 066bcac | 2011-07-22 13:18:16 -0400 | [diff] [blame] | 8 | #include <linux/export.h> |
David S. Miller | cdb3592 | 2008-09-01 19:31:16 -0700 | [diff] [blame] | 9 | #include <linux/pm.h> |
Rob Herring | 88ca055 | 2018-11-16 15:06:59 -0600 | [diff] [blame] | 10 | #include <linux/of.h> |
David S. Miller | cdb3592 | 2008-09-01 19:31:16 -0700 | [diff] [blame] | 11 | |
David S. Miller | cdb3592 | 2008-09-01 19:31:16 -0700 | [diff] [blame] | 12 | #include <asm/oplib.h> |
| 13 | #include <asm/prom.h> |
David Howells | d550bbd | 2012-03-28 18:30:03 +0100 | [diff] [blame] | 14 | #include <asm/setup.h> |
David S. Miller | cdb3592 | 2008-09-01 19:31:16 -0700 | [diff] [blame] | 15 | |
| 16 | /* sysctl - toggle power-off restriction for serial console |
| 17 | * systems in machine_power_off() |
| 18 | */ |
| 19 | int scons_pwroff = 1; |
| 20 | |
| 21 | /* This isn't actually used, it exists merely to satisfy the |
| 22 | * reference in kernel/sys.c |
| 23 | */ |
| 24 | void (*pm_power_off)(void) = machine_power_off; |
| 25 | EXPORT_SYMBOL(pm_power_off); |
| 26 | |
| 27 | void machine_power_off(void) |
| 28 | { |
Rob Herring | 88ca055 | 2018-11-16 15:06:59 -0600 | [diff] [blame] | 29 | if (!of_node_is_type(of_console_device, "serial") || scons_pwroff) |
David S. Miller | cdb3592 | 2008-09-01 19:31:16 -0700 | [diff] [blame] | 30 | prom_halt_power_off(); |
| 31 | |
| 32 | prom_halt(); |
| 33 | } |
| 34 | |
| 35 | void machine_halt(void) |
| 36 | { |
David S. Miller | cdb3592 | 2008-09-01 19:31:16 -0700 | [diff] [blame] | 37 | prom_halt(); |
| 38 | panic("Halt failed!"); |
| 39 | } |
| 40 | |
| 41 | void machine_restart(char *cmd) |
| 42 | { |
| 43 | char *p; |
| 44 | |
David S. Miller | cdb3592 | 2008-09-01 19:31:16 -0700 | [diff] [blame] | 45 | p = strchr(reboot_command, '\n'); |
| 46 | if (p) |
| 47 | *p = 0; |
| 48 | if (cmd) |
| 49 | prom_reboot(cmd); |
| 50 | if (*reboot_command) |
| 51 | prom_reboot(reboot_command); |
| 52 | prom_reboot(""); |
| 53 | panic("Reboot failed!"); |
| 54 | } |
| 55 | |