1 #include <xen/init.h>
2 #include <xen/lib.h>
3 #include <xen/sched.h>
4 #include <xen/domain.h>
5 #include <xen/delay.h>
6 #include <xen/watchdog.h>
7 #include <xen/shutdown.h>
8 #include <xen/console.h>
9 #ifdef CONFIG_KEXEC
10 #include <xen/kexec.h>
11 #endif
12 #include <asm/debugger.h>
13 #include <public/sched.h>
14 
15 /* opt_noreboot: If true, machine will need manual reset on error. */
16 bool_t __read_mostly opt_noreboot;
17 boolean_param("noreboot", opt_noreboot);
18 
maybe_reboot(void)19 static void noreturn maybe_reboot(void)
20 {
21     if ( opt_noreboot )
22     {
23         printk("'noreboot' set - not rebooting.\n");
24         machine_halt();
25     }
26     else
27     {
28         printk("rebooting machine in 5 seconds.\n");
29         watchdog_disable();
30         machine_restart(5000);
31     }
32 }
33 
hwdom_shutdown(u8 reason)34 void hwdom_shutdown(u8 reason)
35 {
36     switch ( reason )
37     {
38     case SHUTDOWN_poweroff:
39         printk("Hardware Dom%u halted: halting machine\n",
40                hardware_domain->domain_id);
41         machine_halt();
42         break; /* not reached */
43 
44     case SHUTDOWN_crash:
45         debugger_trap_immediate();
46         printk("Hardware Dom%u crashed: ", hardware_domain->domain_id);
47 #ifdef CONFIG_KEXEC
48         kexec_crash();
49 #endif
50         maybe_reboot();
51         break; /* not reached */
52 
53     case SHUTDOWN_reboot:
54         printk("Hardware Dom%u shutdown: rebooting machine\n",
55                hardware_domain->domain_id);
56         machine_restart(0);
57         break; /* not reached */
58 
59     case SHUTDOWN_watchdog:
60         printk("Hardware Dom%u shutdown: watchdog rebooting machine\n",
61                hardware_domain->domain_id);
62 #ifdef CONFIG_KEXEC
63         kexec_crash();
64 #endif
65         machine_restart(0);
66         break; /* not reached */
67 
68     case SHUTDOWN_soft_reset:
69         printk("Hardware domain %d did unsupported soft reset, rebooting.\n",
70                hardware_domain->domain_id);
71         machine_restart(0);
72         break; /* not reached */
73 
74     default:
75         printk("Hardware Dom%u shutdown (unknown reason %u): ",
76                hardware_domain->domain_id, reason);
77         maybe_reboot();
78         break; /* not reached */
79     }
80 }
81 
82