xref: /openbmc/qemu/include/sysemu/runstate.h (revision 784155cdcb02ffaae44afecab93861070e7d652d)
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  void vm_start(void);
44  
45  /**
46   * vm_prepare_start: Prepare for starting/resuming the VM
47   *
48   * @step_pending: whether any of the CPUs is about to be single-stepped by gdb
49   */
50  int vm_prepare_start(bool step_pending);
51  int vm_stop(RunState state);
52  int vm_stop_force_state(RunState state);
53  int vm_shutdown(void);
54  
55  typedef enum WakeupReason {
56      /* Always keep QEMU_WAKEUP_REASON_NONE = 0 */
57      QEMU_WAKEUP_REASON_NONE = 0,
58      QEMU_WAKEUP_REASON_RTC,
59      QEMU_WAKEUP_REASON_PMTIMER,
60      QEMU_WAKEUP_REASON_OTHER,
61  } WakeupReason;
62  
63  void qemu_system_reset_request(ShutdownCause reason);
64  void qemu_system_suspend_request(void);
65  void qemu_register_suspend_notifier(Notifier *notifier);
66  bool qemu_wakeup_suspend_enabled(void);
67  void qemu_system_wakeup_request(WakeupReason reason, Error **errp);
68  void qemu_system_wakeup_enable(WakeupReason reason, bool enabled);
69  void qemu_register_wakeup_notifier(Notifier *notifier);
70  void qemu_register_wakeup_support(void);
71  void qemu_system_shutdown_request(ShutdownCause reason);
72  void qemu_system_powerdown_request(void);
73  void qemu_register_powerdown_notifier(Notifier *notifier);
74  void qemu_register_shutdown_notifier(Notifier *notifier);
75  void qemu_system_debug_request(void);
76  void qemu_system_vmstop_request(RunState reason);
77  void qemu_system_vmstop_request_prepare(void);
78  bool qemu_vmstop_requested(RunState *r);
79  ShutdownCause qemu_shutdown_requested_get(void);
80  ShutdownCause qemu_reset_requested_get(void);
81  void qemu_system_killed(int signal, pid_t pid);
82  void qemu_system_reset(ShutdownCause reason);
83  void qemu_system_guest_panicked(GuestPanicInformation *info);
84  void qemu_system_guest_crashloaded(GuestPanicInformation *info);
85  bool qemu_system_dump_in_progress(void);
86  
87  #endif
88  
89