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