xref: /openbmc/qemu/include/sysemu/runstate.h (revision 1faa437d)
1 #ifndef SYSEMU_RUNSTATE_H
2 #define SYSEMU_RUNSTATE_H
3 
4 #include "qapi/qapi-types-run-state.h"
5 #include "qemu/notify.h"
6 
7 bool runstate_check(RunState state);
8 void runstate_set(RunState new_state);
9 RunState runstate_get(void);
10 bool runstate_is_running(void);
11 bool runstate_needs_reset(void);
12 void runstate_replay_enable(void);
13 
14 typedef void VMChangeStateHandler(void *opaque, bool running, RunState state);
15 
16 VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
17                                                      void *opaque);
18 VMChangeStateEntry *qemu_add_vm_change_state_handler_prio(
19         VMChangeStateHandler *cb, void *opaque, int priority);
20 VMChangeStateEntry *
21 qemu_add_vm_change_state_handler_prio_full(VMChangeStateHandler *cb,
22                                            VMChangeStateHandler *prepare_cb,
23                                            void *opaque, int priority);
24 VMChangeStateEntry *qdev_add_vm_change_state_handler(DeviceState *dev,
25                                                      VMChangeStateHandler *cb,
26                                                      void *opaque);
27 VMChangeStateEntry *qdev_add_vm_change_state_handler_full(
28     DeviceState *dev, VMChangeStateHandler *cb,
29     VMChangeStateHandler *prepare_cb, void *opaque);
30 void qemu_del_vm_change_state_handler(VMChangeStateEntry *e);
31 /**
32  * vm_state_notify: Notify the state of the VM
33  *
34  * @running: whether the VM is running or not.
35  * @state: the #RunState of the VM.
36  */
37 void vm_state_notify(bool running, RunState state);
38 
39 static inline bool shutdown_caused_by_guest(ShutdownCause cause)
40 {
41     return cause >= SHUTDOWN_CAUSE_GUEST_SHUTDOWN;
42 }
43 
44 /*
45  * In a "live" state, the vcpu clock is ticking, and the runstate notifiers
46  * think we are running.
47  */
48 static inline bool runstate_is_live(RunState state)
49 {
50     return state == RUN_STATE_RUNNING || state == RUN_STATE_SUSPENDED;
51 }
52 
53 void vm_start(void);
54 
55 /**
56  * vm_prepare_start: Prepare for starting/resuming the VM
57  *
58  * @step_pending: whether any of the CPUs is about to be single-stepped by gdb
59  */
60 int vm_prepare_start(bool step_pending);
61 
62 /**
63  * vm_resume: If @state is a live state, start the vm and set the state,
64  * else just set the state.
65  *
66  * @state: the state to restore
67  */
68 void vm_resume(RunState state);
69 
70 int vm_stop(RunState state);
71 int vm_stop_force_state(RunState state);
72 int vm_shutdown(void);
73 void vm_set_suspended(bool suspended);
74 bool vm_get_suspended(void);
75 
76 typedef enum WakeupReason {
77     /* Always keep QEMU_WAKEUP_REASON_NONE = 0 */
78     QEMU_WAKEUP_REASON_NONE = 0,
79     QEMU_WAKEUP_REASON_RTC,
80     QEMU_WAKEUP_REASON_PMTIMER,
81     QEMU_WAKEUP_REASON_OTHER,
82 } WakeupReason;
83 
84 void qemu_system_reset_request(ShutdownCause reason);
85 void qemu_system_suspend_request(void);
86 void qemu_register_suspend_notifier(Notifier *notifier);
87 bool qemu_wakeup_suspend_enabled(void);
88 void qemu_system_wakeup_request(WakeupReason reason, Error **errp);
89 void qemu_system_wakeup_enable(WakeupReason reason, bool enabled);
90 void qemu_register_wakeup_notifier(Notifier *notifier);
91 void qemu_register_wakeup_support(void);
92 void qemu_system_shutdown_request_with_code(ShutdownCause reason,
93                                             int exit_code);
94 void qemu_system_shutdown_request(ShutdownCause reason);
95 void qemu_system_powerdown_request(void);
96 void qemu_register_powerdown_notifier(Notifier *notifier);
97 void qemu_register_shutdown_notifier(Notifier *notifier);
98 void qemu_system_debug_request(void);
99 void qemu_system_vmstop_request(RunState reason);
100 void qemu_system_vmstop_request_prepare(void);
101 bool qemu_vmstop_requested(RunState *r);
102 ShutdownCause qemu_shutdown_requested_get(void);
103 ShutdownCause qemu_reset_requested_get(void);
104 void qemu_system_killed(int signal, pid_t pid);
105 void qemu_system_reset(ShutdownCause reason);
106 void qemu_system_guest_panicked(GuestPanicInformation *info);
107 void qemu_system_guest_crashloaded(GuestPanicInformation *info);
108 void qemu_system_guest_pvshutdown(void);
109 bool qemu_system_dump_in_progress(void);
110 
111 #endif
112 
113