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