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