xref: /openbmc/qemu/include/sysemu/sysemu.h (revision 1af878e0)
19c17d615SPaolo Bonzini #ifndef SYSEMU_H
29c17d615SPaolo Bonzini #define SYSEMU_H
39c17d615SPaolo Bonzini /* Misc. things related to the system emulator.  */
49c17d615SPaolo Bonzini 
59c17d615SPaolo Bonzini #include "qemu/typedefs.h"
69c17d615SPaolo Bonzini #include "qemu/option.h"
79c17d615SPaolo Bonzini #include "qemu/queue.h"
89c17d615SPaolo Bonzini #include "qemu/timer.h"
99c17d615SPaolo Bonzini #include "qapi-types.h"
109c17d615SPaolo Bonzini #include "qemu/notify.h"
119c17d615SPaolo Bonzini #include "qemu/main-loop.h"
128c85901eSWanlong Gao #include "qemu/bitmap.h"
13dfabb8b9SPaolo Bonzini #include "qom/object.h"
149c17d615SPaolo Bonzini 
159c17d615SPaolo Bonzini /* vl.c */
169c17d615SPaolo Bonzini 
179c17d615SPaolo Bonzini extern const char *bios_name;
189c17d615SPaolo Bonzini 
199c17d615SPaolo Bonzini extern const char *qemu_name;
209c17d615SPaolo Bonzini extern uint8_t qemu_uuid[];
21fc3b3295SMarkus Armbruster extern bool qemu_uuid_set;
229c17d615SPaolo Bonzini int qemu_uuid_parse(const char *str, uint8_t *uuid);
235accc840SPaolo Bonzini 
249c17d615SPaolo Bonzini #define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
255accc840SPaolo Bonzini #define UUID_NONE "00000000-0000-0000-0000-000000000000"
269c17d615SPaolo Bonzini 
279c17d615SPaolo Bonzini bool runstate_check(RunState state);
289c17d615SPaolo Bonzini void runstate_set(RunState new_state);
299c17d615SPaolo Bonzini int runstate_is_running(void);
30ede085b3SHu Tao bool runstate_needs_reset(void);
319c17d615SPaolo Bonzini typedef struct vm_change_state_entry VMChangeStateEntry;
329c17d615SPaolo Bonzini typedef void VMChangeStateHandler(void *opaque, int running, RunState state);
339c17d615SPaolo Bonzini 
349c17d615SPaolo Bonzini VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
359c17d615SPaolo Bonzini                                                      void *opaque);
369c17d615SPaolo Bonzini void qemu_del_vm_change_state_handler(VMChangeStateEntry *e);
379c17d615SPaolo Bonzini void vm_state_notify(int running, RunState state);
389c17d615SPaolo Bonzini 
399c17d615SPaolo Bonzini #define VMRESET_SILENT   false
409c17d615SPaolo Bonzini #define VMRESET_REPORT   true
419c17d615SPaolo Bonzini 
429c17d615SPaolo Bonzini void vm_start(void);
4356983463SKevin Wolf int vm_stop(RunState state);
4456983463SKevin Wolf int vm_stop_force_state(RunState state);
459c17d615SPaolo Bonzini 
469c17d615SPaolo Bonzini typedef enum WakeupReason {
474bc78a87SLiu, Jinsong     /* Always keep QEMU_WAKEUP_REASON_NONE = 0 */
484bc78a87SLiu, Jinsong     QEMU_WAKEUP_REASON_NONE = 0,
499c17d615SPaolo Bonzini     QEMU_WAKEUP_REASON_RTC,
509c17d615SPaolo Bonzini     QEMU_WAKEUP_REASON_PMTIMER,
514bc78a87SLiu, Jinsong     QEMU_WAKEUP_REASON_OTHER,
529c17d615SPaolo Bonzini } WakeupReason;
539c17d615SPaolo Bonzini 
549c17d615SPaolo Bonzini void qemu_system_reset_request(void);
559c17d615SPaolo Bonzini void qemu_system_suspend_request(void);
569c17d615SPaolo Bonzini void qemu_register_suspend_notifier(Notifier *notifier);
579c17d615SPaolo Bonzini void qemu_system_wakeup_request(WakeupReason reason);
589c17d615SPaolo Bonzini void qemu_system_wakeup_enable(WakeupReason reason, bool enabled);
599c17d615SPaolo Bonzini void qemu_register_wakeup_notifier(Notifier *notifier);
609c17d615SPaolo Bonzini void qemu_system_shutdown_request(void);
619c17d615SPaolo Bonzini void qemu_system_powerdown_request(void);
629c17d615SPaolo Bonzini void qemu_register_powerdown_notifier(Notifier *notifier);
639c17d615SPaolo Bonzini void qemu_system_debug_request(void);
649c17d615SPaolo Bonzini void qemu_system_vmstop_request(RunState reason);
6574892d24SPaolo Bonzini void qemu_system_vmstop_request_prepare(void);
669c17d615SPaolo Bonzini int qemu_shutdown_requested_get(void);
679c17d615SPaolo Bonzini int qemu_reset_requested_get(void);
689c17d615SPaolo Bonzini void qemu_system_killed(int signal, pid_t pid);
699c17d615SPaolo Bonzini void qemu_devices_reset(void);
709c17d615SPaolo Bonzini void qemu_system_reset(bool report);
719c17d615SPaolo Bonzini 
729c17d615SPaolo Bonzini void qemu_add_exit_notifier(Notifier *notify);
739c17d615SPaolo Bonzini void qemu_remove_exit_notifier(Notifier *notify);
749c17d615SPaolo Bonzini 
759c17d615SPaolo Bonzini void qemu_add_machine_init_done_notifier(Notifier *notify);
769c17d615SPaolo Bonzini 
779c17d615SPaolo Bonzini void do_savevm(Monitor *mon, const QDict *qdict);
789c17d615SPaolo Bonzini int load_vmstate(const char *name);
799c17d615SPaolo Bonzini void do_delvm(Monitor *mon, const QDict *qdict);
8084f2d0eaSWenchao Xia void do_info_snapshots(Monitor *mon, const QDict *qdict);
819c17d615SPaolo Bonzini 
829c17d615SPaolo Bonzini void qemu_announce_self(void);
839c17d615SPaolo Bonzini 
849c17d615SPaolo Bonzini bool qemu_savevm_state_blocked(Error **errp);
8547c8c17aSPaolo Bonzini void qemu_savevm_state_begin(QEMUFile *f,
869c17d615SPaolo Bonzini                              const MigrationParams *params);
879c17d615SPaolo Bonzini int qemu_savevm_state_iterate(QEMUFile *f);
8847c8c17aSPaolo Bonzini void qemu_savevm_state_complete(QEMUFile *f);
896522773fSJuan Quintela void qemu_savevm_state_cancel(void);
90e4ed1541SJuan Quintela uint64_t qemu_savevm_state_pending(QEMUFile *f, uint64_t max_size);
919c17d615SPaolo Bonzini int qemu_loadvm_state(QEMUFile *f);
929c17d615SPaolo Bonzini 
939c17d615SPaolo Bonzini /* SLIRP */
949c17d615SPaolo Bonzini void do_info_slirp(Monitor *mon);
959c17d615SPaolo Bonzini 
969c17d615SPaolo Bonzini typedef enum DisplayType
979c17d615SPaolo Bonzini {
989c17d615SPaolo Bonzini     DT_DEFAULT,
999c17d615SPaolo Bonzini     DT_CURSES,
1009c17d615SPaolo Bonzini     DT_SDL,
101a4ccabcfSAnthony Liguori     DT_GTK,
1029c17d615SPaolo Bonzini     DT_NOGRAPHIC,
1039c17d615SPaolo Bonzini     DT_NONE,
1049c17d615SPaolo Bonzini } DisplayType;
1059c17d615SPaolo Bonzini 
1069c17d615SPaolo Bonzini extern int autostart;
1079c17d615SPaolo Bonzini 
1089c17d615SPaolo Bonzini typedef enum {
1099c17d615SPaolo Bonzini     VGA_NONE, VGA_STD, VGA_CIRRUS, VGA_VMWARE, VGA_XENFB, VGA_QXL,
110d44229c5SMark Wu     VGA_TCX, VGA_CG3, VGA_DEVICE
1119c17d615SPaolo Bonzini } VGAInterfaceType;
1129c17d615SPaolo Bonzini 
1139c17d615SPaolo Bonzini extern int vga_interface_type;
1149c17d615SPaolo Bonzini #define xenfb_enabled (vga_interface_type == VGA_XENFB)
1159c17d615SPaolo Bonzini 
1169c17d615SPaolo Bonzini extern int graphic_width;
1179c17d615SPaolo Bonzini extern int graphic_height;
1189c17d615SPaolo Bonzini extern int graphic_depth;
1199c17d615SPaolo Bonzini extern DisplayType display_type;
1209c17d615SPaolo Bonzini extern const char *keyboard_layout;
1219c17d615SPaolo Bonzini extern int win2k_install_hack;
1229c17d615SPaolo Bonzini extern int alt_grab;
1239c17d615SPaolo Bonzini extern int ctrl_grab;
1249c17d615SPaolo Bonzini extern int smp_cpus;
1259c17d615SPaolo Bonzini extern int max_cpus;
1269c17d615SPaolo Bonzini extern int cursor_hide;
1279c17d615SPaolo Bonzini extern int graphic_rotate;
1289c17d615SPaolo Bonzini extern int no_quit;
1299c17d615SPaolo Bonzini extern int no_shutdown;
1309c17d615SPaolo Bonzini extern int semihosting_enabled;
1319c17d615SPaolo Bonzini extern int old_param;
1329c17d615SPaolo Bonzini extern int boot_menu;
1339c17d615SPaolo Bonzini extern uint8_t *boot_splash_filedata;
134d09acb9bSMarkus Armbruster extern size_t boot_splash_filedata_size;
1359c17d615SPaolo Bonzini extern uint8_t qemu_extra_params_fw[2];
136884f17c2SAlex Bligh extern QEMUClockType rtc_clock;
137e1c57ab8SPaolo Bonzini extern const char *mem_path;
138e1c57ab8SPaolo Bonzini extern int mem_prealloc;
1399c17d615SPaolo Bonzini 
14045e30bf3SWanlong Gao #define MAX_NODES 128
141d2995916SEduardo Habkost 
142d2995916SEduardo Habkost /* The following shall be true for all CPUs:
143d2995916SEduardo Habkost  *   cpu->cpu_index < max_cpus <= MAX_CPUMASK_BITS
144d2995916SEduardo Habkost  *
145d2995916SEduardo Habkost  * Note that cpu->get_arch_id() may be larger than MAX_CPUMASK_BITS.
146d2995916SEduardo Habkost  */
1479c17d615SPaolo Bonzini #define MAX_CPUMASK_BITS 255
148d2995916SEduardo Habkost 
149*1af878e0SEduardo Habkost extern int nb_numa_nodes;   /* Number of NUMA nodes */
150*1af878e0SEduardo Habkost extern int max_numa_nodeid; /* Highest specified NUMA node ID, plus one.
151*1af878e0SEduardo Habkost                              * For all nodes, nodeid < max_numa_nodeid
152*1af878e0SEduardo Habkost                              */
153*1af878e0SEduardo Habkost 
1548c85901eSWanlong Gao typedef struct node_info {
1558c85901eSWanlong Gao     uint64_t node_mem;
1568c85901eSWanlong Gao     DECLARE_BITMAP(node_cpu, MAX_CPUMASK_BITS);
1577febe36fSPaolo Bonzini     struct HostMemoryBackend *node_memdev;
158*1af878e0SEduardo Habkost     bool present;
1598c85901eSWanlong Gao } NodeInfo;
1608c85901eSWanlong Gao extern NodeInfo numa_info[MAX_NODES];
16196d0e26cSWanlong Gao void set_numa_nodes(void);
16296d0e26cSWanlong Gao void set_numa_modes(void);
1630042109aSWanlong Gao extern QemuOptsList qemu_numa_opts;
1640042109aSWanlong Gao int numa_init_func(QemuOpts *opts, void *opaque);
1659c17d615SPaolo Bonzini 
1669c17d615SPaolo Bonzini #define MAX_OPTION_ROMS 16
1679c17d615SPaolo Bonzini typedef struct QEMUOptionRom {
1689c17d615SPaolo Bonzini     const char *name;
1699c17d615SPaolo Bonzini     int32_t bootindex;
1709c17d615SPaolo Bonzini } QEMUOptionRom;
1719c17d615SPaolo Bonzini extern QEMUOptionRom option_rom[MAX_OPTION_ROMS];
1729c17d615SPaolo Bonzini extern int nb_option_roms;
1739c17d615SPaolo Bonzini 
1749c17d615SPaolo Bonzini #define MAX_PROM_ENVS 128
1759c17d615SPaolo Bonzini extern const char *prom_envs[MAX_PROM_ENVS];
1769c17d615SPaolo Bonzini extern unsigned int nb_prom_envs;
1779c17d615SPaolo Bonzini 
1789c17d615SPaolo Bonzini /* pci-hotplug */
1799c17d615SPaolo Bonzini void pci_device_hot_add(Monitor *mon, const QDict *qdict);
1809c17d615SPaolo Bonzini int pci_drive_hot_add(Monitor *mon, const QDict *qdict, DriveInfo *dinfo);
1819c17d615SPaolo Bonzini void do_pci_device_hot_remove(Monitor *mon, const QDict *qdict);
1829c17d615SPaolo Bonzini 
1839c17d615SPaolo Bonzini /* generic hotplug */
1849c17d615SPaolo Bonzini void drive_hot_add(Monitor *mon, const QDict *qdict);
1859c17d615SPaolo Bonzini 
186066e9b27SIgor Mammedov /* CPU hotplug */
187066e9b27SIgor Mammedov void qemu_register_cpu_added_notifier(Notifier *notifier);
188066e9b27SIgor Mammedov 
1899c17d615SPaolo Bonzini /* pcie aer error injection */
1909c17d615SPaolo Bonzini void pcie_aer_inject_error_print(Monitor *mon, const QObject *data);
1919c17d615SPaolo Bonzini int do_pcie_aer_inject_error(Monitor *mon,
1929c17d615SPaolo Bonzini                              const QDict *qdict, QObject **ret_data);
1939c17d615SPaolo Bonzini 
1949c17d615SPaolo Bonzini /* serial ports */
1959c17d615SPaolo Bonzini 
1969c17d615SPaolo Bonzini #define MAX_SERIAL_PORTS 4
1979c17d615SPaolo Bonzini 
1989c17d615SPaolo Bonzini extern CharDriverState *serial_hds[MAX_SERIAL_PORTS];
1999c17d615SPaolo Bonzini 
2009c17d615SPaolo Bonzini /* parallel ports */
2019c17d615SPaolo Bonzini 
2029c17d615SPaolo Bonzini #define MAX_PARALLEL_PORTS 3
2039c17d615SPaolo Bonzini 
2049c17d615SPaolo Bonzini extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
2059c17d615SPaolo Bonzini 
2069c17d615SPaolo Bonzini void do_usb_add(Monitor *mon, const QDict *qdict);
2079c17d615SPaolo Bonzini void do_usb_del(Monitor *mon, const QDict *qdict);
20884f2d0eaSWenchao Xia void usb_info(Monitor *mon, const QDict *qdict);
2099c17d615SPaolo Bonzini 
2109c17d615SPaolo Bonzini void add_boot_device_path(int32_t bootindex, DeviceState *dev,
2119c17d615SPaolo Bonzini                           const char *suffix);
21230e32af7SAlexey Kardashevskiy char *get_boot_devices_list(size_t *size, bool ignore_suffixes);
2139c17d615SPaolo Bonzini 
2147dc5af55SDominik Dingel DeviceState *get_boot_device(uint32_t position);
2157dc5af55SDominik Dingel 
2167f9d6e54SMarkus Armbruster QemuOpts *qemu_get_machine_opts(void);
2177f9d6e54SMarkus Armbruster 
2189c17d615SPaolo Bonzini bool usb_enabled(bool default_usb);
2199c17d615SPaolo Bonzini 
220968854c8SAmos Kong extern QemuOptsList qemu_legacy_drive_opts;
221968854c8SAmos Kong extern QemuOptsList qemu_common_drive_opts;
2224d454574SPaolo Bonzini extern QemuOptsList qemu_drive_opts;
2234d454574SPaolo Bonzini extern QemuOptsList qemu_chardev_opts;
2244d454574SPaolo Bonzini extern QemuOptsList qemu_device_opts;
2254d454574SPaolo Bonzini extern QemuOptsList qemu_netdev_opts;
2264d454574SPaolo Bonzini extern QemuOptsList qemu_net_opts;
2274d454574SPaolo Bonzini extern QemuOptsList qemu_global_opts;
2284d454574SPaolo Bonzini extern QemuOptsList qemu_mon_opts;
2294d454574SPaolo Bonzini 
2309c17d615SPaolo Bonzini #endif
231