xref: /openbmc/qemu/include/sysemu/sysemu.h (revision fcf5ef2a)
1 #ifndef SYSEMU_H
2 #define SYSEMU_H
3 /* Misc. things related to the system emulator.  */
4 
5 #include "qemu/option.h"
6 #include "qemu/queue.h"
7 #include "qemu/timer.h"
8 #include "qapi-types.h"
9 #include "qemu/notify.h"
10 #include "qemu/main-loop.h"
11 #include "qemu/bitmap.h"
12 #include "qemu/uuid.h"
13 #include "qom/object.h"
14 
15 /* vl.c */
16 
17 extern const char *bios_name;
18 
19 extern const char *qemu_name;
20 extern QemuUUID qemu_uuid;
21 extern bool qemu_uuid_set;
22 
23 bool runstate_check(RunState state);
24 void runstate_set(RunState new_state);
25 int runstate_is_running(void);
26 bool runstate_needs_reset(void);
27 bool runstate_store(char *str, size_t size);
28 typedef struct vm_change_state_entry VMChangeStateEntry;
29 typedef void VMChangeStateHandler(void *opaque, int running, RunState state);
30 
31 VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
32                                                      void *opaque);
33 void qemu_del_vm_change_state_handler(VMChangeStateEntry *e);
34 void vm_state_notify(int running, RunState state);
35 
36 #define VMRESET_SILENT   false
37 #define VMRESET_REPORT   true
38 
39 void vm_start(void);
40 int vm_stop(RunState state);
41 int vm_stop_force_state(RunState state);
42 
43 typedef enum WakeupReason {
44     /* Always keep QEMU_WAKEUP_REASON_NONE = 0 */
45     QEMU_WAKEUP_REASON_NONE = 0,
46     QEMU_WAKEUP_REASON_RTC,
47     QEMU_WAKEUP_REASON_PMTIMER,
48     QEMU_WAKEUP_REASON_OTHER,
49 } WakeupReason;
50 
51 void qemu_system_reset_request(void);
52 void qemu_system_suspend_request(void);
53 void qemu_register_suspend_notifier(Notifier *notifier);
54 void qemu_system_wakeup_request(WakeupReason reason);
55 void qemu_system_wakeup_enable(WakeupReason reason, bool enabled);
56 void qemu_register_wakeup_notifier(Notifier *notifier);
57 void qemu_system_shutdown_request(void);
58 void qemu_system_powerdown_request(void);
59 void qemu_register_powerdown_notifier(Notifier *notifier);
60 void qemu_system_debug_request(void);
61 void qemu_system_vmstop_request(RunState reason);
62 void qemu_system_vmstop_request_prepare(void);
63 int qemu_shutdown_requested_get(void);
64 int qemu_reset_requested_get(void);
65 void qemu_system_killed(int signal, pid_t pid);
66 void qemu_devices_reset(void);
67 void qemu_system_reset(bool report);
68 void qemu_system_guest_panicked(void);
69 size_t qemu_target_page_bits(void);
70 
71 void qemu_add_exit_notifier(Notifier *notify);
72 void qemu_remove_exit_notifier(Notifier *notify);
73 
74 void qemu_add_machine_init_done_notifier(Notifier *notify);
75 void qemu_remove_machine_init_done_notifier(Notifier *notify);
76 
77 void hmp_savevm(Monitor *mon, const QDict *qdict);
78 int load_vmstate(const char *name);
79 void hmp_delvm(Monitor *mon, const QDict *qdict);
80 void hmp_info_snapshots(Monitor *mon, const QDict *qdict);
81 
82 void qemu_announce_self(void);
83 
84 /* Subcommands for QEMU_VM_COMMAND */
85 enum qemu_vm_cmd {
86     MIG_CMD_INVALID = 0,   /* Must be 0 */
87     MIG_CMD_OPEN_RETURN_PATH,  /* Tell the dest to open the Return path */
88     MIG_CMD_PING,              /* Request a PONG on the RP */
89 
90     MIG_CMD_POSTCOPY_ADVISE,       /* Prior to any page transfers, just
91                                       warn we might want to do PC */
92     MIG_CMD_POSTCOPY_LISTEN,       /* Start listening for incoming
93                                       pages as it's running. */
94     MIG_CMD_POSTCOPY_RUN,          /* Start execution */
95 
96     MIG_CMD_POSTCOPY_RAM_DISCARD,  /* A list of pages to discard that
97                                       were previously sent during
98                                       precopy but are dirty. */
99     MIG_CMD_PACKAGED,          /* Send a wrapped stream within this stream */
100     MIG_CMD_MAX
101 };
102 
103 #define MAX_VM_CMD_PACKAGED_SIZE (1ul << 24)
104 
105 bool qemu_savevm_state_blocked(Error **errp);
106 void qemu_savevm_state_begin(QEMUFile *f,
107                              const MigrationParams *params);
108 void qemu_savevm_state_header(QEMUFile *f);
109 int qemu_savevm_state_iterate(QEMUFile *f, bool postcopy);
110 void qemu_savevm_state_cleanup(void);
111 void qemu_savevm_state_complete_postcopy(QEMUFile *f);
112 void qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only);
113 void qemu_savevm_state_pending(QEMUFile *f, uint64_t max_size,
114                                uint64_t *res_non_postcopiable,
115                                uint64_t *res_postcopiable);
116 void qemu_savevm_command_send(QEMUFile *f, enum qemu_vm_cmd command,
117                               uint16_t len, uint8_t *data);
118 void qemu_savevm_send_ping(QEMUFile *f, uint32_t value);
119 void qemu_savevm_send_open_return_path(QEMUFile *f);
120 int qemu_savevm_send_packaged(QEMUFile *f, const uint8_t *buf, size_t len);
121 void qemu_savevm_send_postcopy_advise(QEMUFile *f);
122 void qemu_savevm_send_postcopy_listen(QEMUFile *f);
123 void qemu_savevm_send_postcopy_run(QEMUFile *f);
124 
125 void qemu_savevm_send_postcopy_ram_discard(QEMUFile *f, const char *name,
126                                            uint16_t len,
127                                            uint64_t *start_list,
128                                            uint64_t *length_list);
129 
130 int qemu_loadvm_state(QEMUFile *f);
131 
132 extern int autostart;
133 
134 typedef enum {
135     VGA_NONE, VGA_STD, VGA_CIRRUS, VGA_VMWARE, VGA_XENFB, VGA_QXL,
136     VGA_TCX, VGA_CG3, VGA_DEVICE, VGA_VIRTIO,
137     VGA_TYPE_MAX,
138 } VGAInterfaceType;
139 
140 extern int vga_interface_type;
141 #define xenfb_enabled (vga_interface_type == VGA_XENFB)
142 
143 extern int graphic_width;
144 extern int graphic_height;
145 extern int graphic_depth;
146 extern int display_opengl;
147 extern const char *keyboard_layout;
148 extern int win2k_install_hack;
149 extern int alt_grab;
150 extern int ctrl_grab;
151 extern int smp_cpus;
152 extern int max_cpus;
153 extern int cursor_hide;
154 extern int graphic_rotate;
155 extern int no_quit;
156 extern int no_shutdown;
157 extern int old_param;
158 extern int boot_menu;
159 extern bool boot_strict;
160 extern uint8_t *boot_splash_filedata;
161 extern size_t boot_splash_filedata_size;
162 extern bool enable_mlock;
163 extern uint8_t qemu_extra_params_fw[2];
164 extern QEMUClockType rtc_clock;
165 extern const char *mem_path;
166 extern int mem_prealloc;
167 
168 #define MAX_NODES 128
169 #define NUMA_NODE_UNASSIGNED MAX_NODES
170 
171 /* The following shall be true for all CPUs:
172  *   cpu->cpu_index < max_cpus <= MAX_CPUMASK_BITS
173  *
174  * Note that cpu->get_arch_id() may be larger than MAX_CPUMASK_BITS.
175  */
176 #define MAX_CPUMASK_BITS 288
177 
178 #define MAX_OPTION_ROMS 16
179 typedef struct QEMUOptionRom {
180     const char *name;
181     int32_t bootindex;
182 } QEMUOptionRom;
183 extern QEMUOptionRom option_rom[MAX_OPTION_ROMS];
184 extern int nb_option_roms;
185 
186 #define MAX_PROM_ENVS 128
187 extern const char *prom_envs[MAX_PROM_ENVS];
188 extern unsigned int nb_prom_envs;
189 
190 /* generic hotplug */
191 void hmp_drive_add(Monitor *mon, const QDict *qdict);
192 
193 /* pcie aer error injection */
194 void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict);
195 
196 /* serial ports */
197 
198 #define MAX_SERIAL_PORTS 4
199 
200 extern CharDriverState *serial_hds[MAX_SERIAL_PORTS];
201 
202 /* parallel ports */
203 
204 #define MAX_PARALLEL_PORTS 3
205 
206 extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
207 
208 void hmp_usb_add(Monitor *mon, const QDict *qdict);
209 void hmp_usb_del(Monitor *mon, const QDict *qdict);
210 void hmp_info_usb(Monitor *mon, const QDict *qdict);
211 
212 void add_boot_device_path(int32_t bootindex, DeviceState *dev,
213                           const char *suffix);
214 char *get_boot_devices_list(size_t *size, bool ignore_suffixes);
215 
216 DeviceState *get_boot_device(uint32_t position);
217 void check_boot_index(int32_t bootindex, Error **errp);
218 void del_boot_device_path(DeviceState *dev, const char *suffix);
219 void device_add_bootindex_property(Object *obj, int32_t *bootindex,
220                                    const char *name, const char *suffix,
221                                    DeviceState *dev, Error **errp);
222 void restore_boot_order(void *opaque);
223 void validate_bootdevices(const char *devices, Error **errp);
224 
225 /* handler to set the boot_device order for a specific type of MachineClass */
226 typedef void QEMUBootSetHandler(void *opaque, const char *boot_order,
227                                 Error **errp);
228 void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque);
229 void qemu_boot_set(const char *boot_order, Error **errp);
230 
231 QemuOpts *qemu_get_machine_opts(void);
232 
233 bool defaults_enabled(void);
234 
235 extern QemuOptsList qemu_legacy_drive_opts;
236 extern QemuOptsList qemu_common_drive_opts;
237 extern QemuOptsList qemu_drive_opts;
238 extern QemuOptsList bdrv_runtime_opts;
239 extern QemuOptsList qemu_chardev_opts;
240 extern QemuOptsList qemu_device_opts;
241 extern QemuOptsList qemu_netdev_opts;
242 extern QemuOptsList qemu_net_opts;
243 extern QemuOptsList qemu_global_opts;
244 extern QemuOptsList qemu_mon_opts;
245 
246 #endif
247