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 77*3e5a50d6SMarkus Armbruster void hmp_savevm(Monitor *mon, const QDict *qdict); 789c17d615SPaolo Bonzini int load_vmstate(const char *name); 79*3e5a50d6SMarkus Armbruster void hmp_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 typedef enum DisplayType 949c17d615SPaolo Bonzini { 959c17d615SPaolo Bonzini DT_DEFAULT, 969c17d615SPaolo Bonzini DT_CURSES, 979c17d615SPaolo Bonzini DT_SDL, 98a4ccabcfSAnthony Liguori DT_GTK, 999c17d615SPaolo Bonzini DT_NOGRAPHIC, 1009c17d615SPaolo Bonzini DT_NONE, 1019c17d615SPaolo Bonzini } DisplayType; 1029c17d615SPaolo Bonzini 1039c17d615SPaolo Bonzini extern int autostart; 1049c17d615SPaolo Bonzini 1059c17d615SPaolo Bonzini typedef enum { 1069c17d615SPaolo Bonzini VGA_NONE, VGA_STD, VGA_CIRRUS, VGA_VMWARE, VGA_XENFB, VGA_QXL, 107d44229c5SMark Wu VGA_TCX, VGA_CG3, VGA_DEVICE 1089c17d615SPaolo Bonzini } VGAInterfaceType; 1099c17d615SPaolo Bonzini 1109c17d615SPaolo Bonzini extern int vga_interface_type; 1119c17d615SPaolo Bonzini #define xenfb_enabled (vga_interface_type == VGA_XENFB) 1129c17d615SPaolo Bonzini 1139c17d615SPaolo Bonzini extern int graphic_width; 1149c17d615SPaolo Bonzini extern int graphic_height; 1159c17d615SPaolo Bonzini extern int graphic_depth; 1169c17d615SPaolo Bonzini extern DisplayType display_type; 1179c17d615SPaolo Bonzini extern const char *keyboard_layout; 1189c17d615SPaolo Bonzini extern int win2k_install_hack; 1199c17d615SPaolo Bonzini extern int alt_grab; 1209c17d615SPaolo Bonzini extern int ctrl_grab; 1219c17d615SPaolo Bonzini extern int smp_cpus; 1229c17d615SPaolo Bonzini extern int max_cpus; 1239c17d615SPaolo Bonzini extern int cursor_hide; 1249c17d615SPaolo Bonzini extern int graphic_rotate; 1259c17d615SPaolo Bonzini extern int no_quit; 1269c17d615SPaolo Bonzini extern int no_shutdown; 1279c17d615SPaolo Bonzini extern int semihosting_enabled; 1289c17d615SPaolo Bonzini extern int old_param; 1299c17d615SPaolo Bonzini extern int boot_menu; 130bc74112fSGonglei extern bool boot_strict; 1319c17d615SPaolo Bonzini extern uint8_t *boot_splash_filedata; 132d09acb9bSMarkus Armbruster extern size_t boot_splash_filedata_size; 1339c17d615SPaolo Bonzini extern uint8_t qemu_extra_params_fw[2]; 134884f17c2SAlex Bligh extern QEMUClockType rtc_clock; 135e1c57ab8SPaolo Bonzini extern const char *mem_path; 136e1c57ab8SPaolo Bonzini extern int mem_prealloc; 1379c17d615SPaolo Bonzini 13845e30bf3SWanlong Gao #define MAX_NODES 128 139d2995916SEduardo Habkost 140d2995916SEduardo Habkost /* The following shall be true for all CPUs: 141d2995916SEduardo Habkost * cpu->cpu_index < max_cpus <= MAX_CPUMASK_BITS 142d2995916SEduardo Habkost * 143d2995916SEduardo Habkost * Note that cpu->get_arch_id() may be larger than MAX_CPUMASK_BITS. 144d2995916SEduardo Habkost */ 1459c17d615SPaolo Bonzini #define MAX_CPUMASK_BITS 255 146d2995916SEduardo Habkost 1471af878e0SEduardo Habkost extern int nb_numa_nodes; /* Number of NUMA nodes */ 1481af878e0SEduardo Habkost extern int max_numa_nodeid; /* Highest specified NUMA node ID, plus one. 1491af878e0SEduardo Habkost * For all nodes, nodeid < max_numa_nodeid 1501af878e0SEduardo Habkost */ 1511af878e0SEduardo Habkost 1528c85901eSWanlong Gao typedef struct node_info { 1538c85901eSWanlong Gao uint64_t node_mem; 1548c85901eSWanlong Gao DECLARE_BITMAP(node_cpu, MAX_CPUMASK_BITS); 1557febe36fSPaolo Bonzini struct HostMemoryBackend *node_memdev; 1561af878e0SEduardo Habkost bool present; 1578c85901eSWanlong Gao } NodeInfo; 1588c85901eSWanlong Gao extern NodeInfo numa_info[MAX_NODES]; 15996d0e26cSWanlong Gao void set_numa_nodes(void); 16096d0e26cSWanlong Gao void set_numa_modes(void); 1615b009e40Szhanghailiang void query_numa_node_mem(uint64_t node_mem[]); 1620042109aSWanlong Gao extern QemuOptsList qemu_numa_opts; 1630042109aSWanlong Gao int numa_init_func(QemuOpts *opts, void *opaque); 1649c17d615SPaolo Bonzini 1659c17d615SPaolo Bonzini #define MAX_OPTION_ROMS 16 1669c17d615SPaolo Bonzini typedef struct QEMUOptionRom { 1679c17d615SPaolo Bonzini const char *name; 1689c17d615SPaolo Bonzini int32_t bootindex; 1699c17d615SPaolo Bonzini } QEMUOptionRom; 1709c17d615SPaolo Bonzini extern QEMUOptionRom option_rom[MAX_OPTION_ROMS]; 1719c17d615SPaolo Bonzini extern int nb_option_roms; 1729c17d615SPaolo Bonzini 1739c17d615SPaolo Bonzini #define MAX_PROM_ENVS 128 1749c17d615SPaolo Bonzini extern const char *prom_envs[MAX_PROM_ENVS]; 1759c17d615SPaolo Bonzini extern unsigned int nb_prom_envs; 1769c17d615SPaolo Bonzini 1779c17d615SPaolo Bonzini /* pci-hotplug */ 178*3e5a50d6SMarkus Armbruster void hmp_pci_add(Monitor *mon, const QDict *qdict); 1799c17d615SPaolo Bonzini int pci_drive_hot_add(Monitor *mon, const QDict *qdict, DriveInfo *dinfo); 180*3e5a50d6SMarkus Armbruster void hmp_pci_del(Monitor *mon, const QDict *qdict); 1819c17d615SPaolo Bonzini 1829c17d615SPaolo Bonzini /* generic hotplug */ 183*3e5a50d6SMarkus Armbruster void hmp_drive_add(Monitor *mon, const QDict *qdict); 1849c17d615SPaolo Bonzini 1859c17d615SPaolo Bonzini /* pcie aer error injection */ 1869c17d615SPaolo Bonzini void pcie_aer_inject_error_print(Monitor *mon, const QObject *data); 187*3e5a50d6SMarkus Armbruster int hmp_pcie_aer_inject_error(Monitor *mon, 1889c17d615SPaolo Bonzini const QDict *qdict, QObject **ret_data); 1899c17d615SPaolo Bonzini 1909c17d615SPaolo Bonzini /* serial ports */ 1919c17d615SPaolo Bonzini 1929c17d615SPaolo Bonzini #define MAX_SERIAL_PORTS 4 1939c17d615SPaolo Bonzini 1949c17d615SPaolo Bonzini extern CharDriverState *serial_hds[MAX_SERIAL_PORTS]; 1959c17d615SPaolo Bonzini 1969c17d615SPaolo Bonzini /* parallel ports */ 1979c17d615SPaolo Bonzini 1989c17d615SPaolo Bonzini #define MAX_PARALLEL_PORTS 3 1999c17d615SPaolo Bonzini 2009c17d615SPaolo Bonzini extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS]; 2019c17d615SPaolo Bonzini 202*3e5a50d6SMarkus Armbruster void hmp_usb_add(Monitor *mon, const QDict *qdict); 203*3e5a50d6SMarkus Armbruster void hmp_usb_del(Monitor *mon, const QDict *qdict); 20484f2d0eaSWenchao Xia void usb_info(Monitor *mon, const QDict *qdict); 2059c17d615SPaolo Bonzini 2069c17d615SPaolo Bonzini void add_boot_device_path(int32_t bootindex, DeviceState *dev, 2079c17d615SPaolo Bonzini const char *suffix); 20830e32af7SAlexey Kardashevskiy char *get_boot_devices_list(size_t *size, bool ignore_suffixes); 2099c17d615SPaolo Bonzini 2107dc5af55SDominik Dingel DeviceState *get_boot_device(uint32_t position); 211694fb857SGonglei void check_boot_index(int32_t bootindex, Error **errp); 2129d27572dSGonglei void del_boot_device_path(DeviceState *dev, const char *suffix); 21312da3097SGonglei void device_add_bootindex_property(Object *obj, int32_t *bootindex, 21412da3097SGonglei const char *name, const char *suffix, 21512da3097SGonglei DeviceState *dev, Error **errp); 2169816833dSGonglei void restore_boot_order(void *opaque); 217703008e8SGonglei void validate_bootdevices(const char *devices, Error **errp); 2189816833dSGonglei 2199816833dSGonglei /* handler to set the boot_device order for a specific type of QEMUMachine */ 220ddcd5531SGonglei typedef void QEMUBootSetHandler(void *opaque, const char *boot_order, 221ddcd5531SGonglei Error **errp); 2229816833dSGonglei void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque); 223f1839938SGonglei void qemu_boot_set(const char *boot_order, Error **errp); 2247dc5af55SDominik Dingel 2257f9d6e54SMarkus Armbruster QemuOpts *qemu_get_machine_opts(void); 2267f9d6e54SMarkus Armbruster 227f8b6f8edSMarcel Apfelbaum bool defaults_enabled(void); 228de77a243SMarcel Apfelbaum bool usb_enabled(void); 2299c17d615SPaolo Bonzini 230968854c8SAmos Kong extern QemuOptsList qemu_legacy_drive_opts; 231968854c8SAmos Kong extern QemuOptsList qemu_common_drive_opts; 2324d454574SPaolo Bonzini extern QemuOptsList qemu_drive_opts; 2334d454574SPaolo Bonzini extern QemuOptsList qemu_chardev_opts; 2344d454574SPaolo Bonzini extern QemuOptsList qemu_device_opts; 2354d454574SPaolo Bonzini extern QemuOptsList qemu_netdev_opts; 2364d454574SPaolo Bonzini extern QemuOptsList qemu_net_opts; 2374d454574SPaolo Bonzini extern QemuOptsList qemu_global_opts; 2384d454574SPaolo Bonzini extern QemuOptsList qemu_mon_opts; 2394d454574SPaolo Bonzini 2409c17d615SPaolo Bonzini #endif 241