xref: /openbmc/qemu/include/sysemu/sysemu.h (revision 047f7038)
19c17d615SPaolo Bonzini #ifndef SYSEMU_H
29c17d615SPaolo Bonzini #define SYSEMU_H
39c17d615SPaolo Bonzini /* Misc. things related to the system emulator.  */
49c17d615SPaolo Bonzini 
59af23989SMarkus Armbruster #include "qapi/qapi-types-run-state.h"
69c17d615SPaolo Bonzini #include "qemu/queue.h"
79c17d615SPaolo Bonzini #include "qemu/timer.h"
89c17d615SPaolo Bonzini #include "qemu/notify.h"
99c17d615SPaolo Bonzini #include "qemu/main-loop.h"
108c85901eSWanlong Gao #include "qemu/bitmap.h"
119c5ce8dbSFam Zheng #include "qemu/uuid.h"
12dfabb8b9SPaolo Bonzini #include "qom/object.h"
139c17d615SPaolo Bonzini 
149c17d615SPaolo Bonzini /* vl.c */
159c17d615SPaolo Bonzini 
169c17d615SPaolo Bonzini extern const char *bios_name;
179c17d615SPaolo Bonzini extern const char *qemu_name;
189c5ce8dbSFam Zheng extern QemuUUID qemu_uuid;
19fc3b3295SMarkus Armbruster extern bool qemu_uuid_set;
209c17d615SPaolo Bonzini 
219c17d615SPaolo Bonzini bool runstate_check(RunState state);
229c17d615SPaolo Bonzini void runstate_set(RunState new_state);
239c17d615SPaolo Bonzini int runstate_is_running(void);
24ede085b3SHu Tao bool runstate_needs_reset(void);
255e0f1940SJuan Quintela bool runstate_store(char *str, size_t size);
269c17d615SPaolo Bonzini typedef struct vm_change_state_entry VMChangeStateEntry;
279c17d615SPaolo Bonzini typedef void VMChangeStateHandler(void *opaque, int running, RunState state);
289c17d615SPaolo Bonzini 
299c17d615SPaolo Bonzini VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
309c17d615SPaolo Bonzini                                                      void *opaque);
319c17d615SPaolo Bonzini void qemu_del_vm_change_state_handler(VMChangeStateEntry *e);
329c17d615SPaolo Bonzini void vm_state_notify(int running, RunState state);
339c17d615SPaolo Bonzini 
34aedbe192SEric Blake /* Enumeration of various causes for shutdown. */
35aedbe192SEric Blake typedef enum ShutdownCause {
36aedbe192SEric Blake     SHUTDOWN_CAUSE_NONE,          /* No shutdown request pending */
37aedbe192SEric Blake     SHUTDOWN_CAUSE_HOST_ERROR,    /* An error prevents further use of guest */
38aedbe192SEric Blake     SHUTDOWN_CAUSE_HOST_QMP,      /* Reaction to a QMP command, like 'quit' */
39aedbe192SEric Blake     SHUTDOWN_CAUSE_HOST_SIGNAL,   /* Reaction to a signal, such as SIGINT */
40aedbe192SEric Blake     SHUTDOWN_CAUSE_HOST_UI,       /* Reaction to UI event, like window close */
41aedbe192SEric Blake     SHUTDOWN_CAUSE_GUEST_SHUTDOWN,/* Guest shutdown/suspend request, via
42aedbe192SEric Blake                                      ACPI or other hardware-specific means */
43aedbe192SEric Blake     SHUTDOWN_CAUSE_GUEST_RESET,   /* Guest reset request, and command line
44aedbe192SEric Blake                                      turns that into a shutdown */
45aedbe192SEric Blake     SHUTDOWN_CAUSE_GUEST_PANIC,   /* Guest panicked, and command line turns
46aedbe192SEric Blake                                      that into a shutdown */
47aedbe192SEric Blake     SHUTDOWN_CAUSE__MAX,
48aedbe192SEric Blake } ShutdownCause;
499c17d615SPaolo Bonzini 
5008fba7acSEric Blake static inline bool shutdown_caused_by_guest(ShutdownCause cause)
5108fba7acSEric Blake {
5208fba7acSEric Blake     return cause >= SHUTDOWN_CAUSE_GUEST_SHUTDOWN;
5308fba7acSEric Blake }
549c17d615SPaolo Bonzini 
559c17d615SPaolo Bonzini void vm_start(void);
562d76e823SClaudio Imbrenda int vm_prepare_start(void);
5756983463SKevin Wolf int vm_stop(RunState state);
5856983463SKevin Wolf int vm_stop_force_state(RunState state);
594486e89cSStefan Hajnoczi int vm_shutdown(void);
609c17d615SPaolo Bonzini 
619c17d615SPaolo Bonzini typedef enum WakeupReason {
624bc78a87SLiu, Jinsong     /* Always keep QEMU_WAKEUP_REASON_NONE = 0 */
634bc78a87SLiu, Jinsong     QEMU_WAKEUP_REASON_NONE = 0,
649c17d615SPaolo Bonzini     QEMU_WAKEUP_REASON_RTC,
659c17d615SPaolo Bonzini     QEMU_WAKEUP_REASON_PMTIMER,
664bc78a87SLiu, Jinsong     QEMU_WAKEUP_REASON_OTHER,
679c17d615SPaolo Bonzini } WakeupReason;
689c17d615SPaolo Bonzini 
69*047f7038SIgor Mammedov void qemu_exit_preconfig_request(void);
70cf83f140SEric Blake void qemu_system_reset_request(ShutdownCause reason);
719c17d615SPaolo Bonzini void qemu_system_suspend_request(void);
729c17d615SPaolo Bonzini void qemu_register_suspend_notifier(Notifier *notifier);
739c17d615SPaolo Bonzini void qemu_system_wakeup_request(WakeupReason reason);
749c17d615SPaolo Bonzini void qemu_system_wakeup_enable(WakeupReason reason, bool enabled);
759c17d615SPaolo Bonzini void qemu_register_wakeup_notifier(Notifier *notifier);
76cf83f140SEric Blake void qemu_system_shutdown_request(ShutdownCause reason);
779c17d615SPaolo Bonzini void qemu_system_powerdown_request(void);
789c17d615SPaolo Bonzini void qemu_register_powerdown_notifier(Notifier *notifier);
799c17d615SPaolo Bonzini void qemu_system_debug_request(void);
809c17d615SPaolo Bonzini void qemu_system_vmstop_request(RunState reason);
8174892d24SPaolo Bonzini void qemu_system_vmstop_request_prepare(void);
822d76e823SClaudio Imbrenda bool qemu_vmstop_requested(RunState *r);
83aedbe192SEric Blake ShutdownCause qemu_shutdown_requested_get(void);
84aedbe192SEric Blake ShutdownCause qemu_reset_requested_get(void);
859c17d615SPaolo Bonzini void qemu_system_killed(int signal, pid_t pid);
86aedbe192SEric Blake void qemu_system_reset(ShutdownCause reason);
87c86f106bSAnton Nefedov void qemu_system_guest_panicked(GuestPanicInformation *info);
889c17d615SPaolo Bonzini 
899c17d615SPaolo Bonzini void qemu_add_exit_notifier(Notifier *notify);
909c17d615SPaolo Bonzini void qemu_remove_exit_notifier(Notifier *notify);
919c17d615SPaolo Bonzini 
92c8ca2a23SPeter Xu extern bool machine_init_done;
93c8ca2a23SPeter Xu 
949c17d615SPaolo Bonzini void qemu_add_machine_init_done_notifier(Notifier *notify);
95b86eacb8SMarcel Apfelbaum void qemu_remove_machine_init_done_notifier(Notifier *notify);
969c17d615SPaolo Bonzini 
979c17d615SPaolo Bonzini void qemu_announce_self(void);
989c17d615SPaolo Bonzini 
999c17d615SPaolo Bonzini extern int autostart;
1009c17d615SPaolo Bonzini 
1019c17d615SPaolo Bonzini typedef enum {
1029c17d615SPaolo Bonzini     VGA_NONE, VGA_STD, VGA_CIRRUS, VGA_VMWARE, VGA_XENFB, VGA_QXL,
103a94f0c5cSGerd Hoffmann     VGA_TCX, VGA_CG3, VGA_DEVICE, VGA_VIRTIO,
1048c9a2b71SEduardo Habkost     VGA_TYPE_MAX,
1059c17d615SPaolo Bonzini } VGAInterfaceType;
1069c17d615SPaolo Bonzini 
1079c17d615SPaolo Bonzini extern int vga_interface_type;
1089c17d615SPaolo Bonzini #define xenfb_enabled (vga_interface_type == VGA_XENFB)
1099c17d615SPaolo Bonzini 
1109c17d615SPaolo Bonzini extern int graphic_width;
1119c17d615SPaolo Bonzini extern int graphic_height;
1129c17d615SPaolo Bonzini extern int graphic_depth;
113da076ffeSGerd Hoffmann extern int display_opengl;
1149c17d615SPaolo Bonzini extern const char *keyboard_layout;
1159c17d615SPaolo Bonzini extern int win2k_install_hack;
1169c17d615SPaolo Bonzini extern int alt_grab;
1179c17d615SPaolo Bonzini extern int ctrl_grab;
11804ff1a39SGerd Hoffmann extern int no_frame;
1199c17d615SPaolo Bonzini extern int smp_cpus;
120c0dd1099SSeeteena Thoufeek extern unsigned int max_cpus;
1219c17d615SPaolo Bonzini extern int cursor_hide;
1229c17d615SPaolo Bonzini extern int graphic_rotate;
1239c17d615SPaolo Bonzini extern int no_quit;
1249c17d615SPaolo Bonzini extern int no_shutdown;
1259c17d615SPaolo Bonzini extern int old_param;
1269c17d615SPaolo Bonzini extern int boot_menu;
127bc74112fSGonglei extern bool boot_strict;
1289c17d615SPaolo Bonzini extern uint8_t *boot_splash_filedata;
129d09acb9bSMarkus Armbruster extern size_t boot_splash_filedata_size;
13058b7c17eSDr. David Alan Gilbert extern bool enable_mlock;
1319c17d615SPaolo Bonzini extern uint8_t qemu_extra_params_fw[2];
132884f17c2SAlex Bligh extern QEMUClockType rtc_clock;
133e1c57ab8SPaolo Bonzini extern const char *mem_path;
134e1c57ab8SPaolo Bonzini extern int mem_prealloc;
1359c17d615SPaolo Bonzini 
13645e30bf3SWanlong Gao #define MAX_NODES 128
1376a3042b2SMarcel Apfelbaum #define NUMA_NODE_UNASSIGNED MAX_NODES
1380f203430SHe Chen #define NUMA_DISTANCE_MIN         10
1390f203430SHe Chen #define NUMA_DISTANCE_DEFAULT     20
1400f203430SHe Chen #define NUMA_DISTANCE_MAX         254
1410f203430SHe Chen #define NUMA_DISTANCE_UNREACHABLE 255
142d2995916SEduardo Habkost 
1439c17d615SPaolo Bonzini #define MAX_OPTION_ROMS 16
1449c17d615SPaolo Bonzini typedef struct QEMUOptionRom {
1459c17d615SPaolo Bonzini     const char *name;
1469c17d615SPaolo Bonzini     int32_t bootindex;
1479c17d615SPaolo Bonzini } QEMUOptionRom;
1489c17d615SPaolo Bonzini extern QEMUOptionRom option_rom[MAX_OPTION_ROMS];
1499c17d615SPaolo Bonzini extern int nb_option_roms;
1509c17d615SPaolo Bonzini 
1519c17d615SPaolo Bonzini #define MAX_PROM_ENVS 128
1529c17d615SPaolo Bonzini extern const char *prom_envs[MAX_PROM_ENVS];
1539c17d615SPaolo Bonzini extern unsigned int nb_prom_envs;
1549c17d615SPaolo Bonzini 
1559c17d615SPaolo Bonzini /* generic hotplug */
1563e5a50d6SMarkus Armbruster void hmp_drive_add(Monitor *mon, const QDict *qdict);
1579c17d615SPaolo Bonzini 
1589c17d615SPaolo Bonzini /* pcie aer error injection */
15904e00c92SMarkus Armbruster void hmp_pcie_aer_inject_error(Monitor *mon, const QDict *qdict);
1609c17d615SPaolo Bonzini 
1619c17d615SPaolo Bonzini /* serial ports */
1629c17d615SPaolo Bonzini 
163a8d78cd0SPeter Maydell /* Return the Chardev for serial port i, or NULL if none */
164a8d78cd0SPeter Maydell Chardev *serial_hd(int i);
165b8846a4dSPeter Maydell /* return the number of serial ports defined by the user. serial_hd(i)
166b8846a4dSPeter Maydell  * will always return NULL for any i which is greater than or equal to this.
167b8846a4dSPeter Maydell  */
168b8846a4dSPeter Maydell int serial_max_hds(void);
169a8d78cd0SPeter Maydell 
1709c17d615SPaolo Bonzini /* parallel ports */
1719c17d615SPaolo Bonzini 
1729c17d615SPaolo Bonzini #define MAX_PARALLEL_PORTS 3
1739c17d615SPaolo Bonzini 
1740ec7b3e7SMarc-André Lureau extern Chardev *parallel_hds[MAX_PARALLEL_PORTS];
1759c17d615SPaolo Bonzini 
1761ce6be24SMarkus Armbruster void hmp_info_usb(Monitor *mon, const QDict *qdict);
1779c17d615SPaolo Bonzini 
1789c17d615SPaolo Bonzini void add_boot_device_path(int32_t bootindex, DeviceState *dev,
1799c17d615SPaolo Bonzini                           const char *suffix);
18030e32af7SAlexey Kardashevskiy char *get_boot_devices_list(size_t *size, bool ignore_suffixes);
1819c17d615SPaolo Bonzini 
1827dc5af55SDominik Dingel DeviceState *get_boot_device(uint32_t position);
183694fb857SGonglei void check_boot_index(int32_t bootindex, Error **errp);
1849d27572dSGonglei void del_boot_device_path(DeviceState *dev, const char *suffix);
18512da3097SGonglei void device_add_bootindex_property(Object *obj, int32_t *bootindex,
18612da3097SGonglei                                    const char *name, const char *suffix,
18712da3097SGonglei                                    DeviceState *dev, Error **errp);
1889816833dSGonglei void restore_boot_order(void *opaque);
189703008e8SGonglei void validate_bootdevices(const char *devices, Error **errp);
1909816833dSGonglei 
1913b53e45fSEduardo Habkost /* handler to set the boot_device order for a specific type of MachineClass */
192ddcd5531SGonglei typedef void QEMUBootSetHandler(void *opaque, const char *boot_order,
193ddcd5531SGonglei                                 Error **errp);
1949816833dSGonglei void qemu_register_boot_set(QEMUBootSetHandler *func, void *opaque);
195f1839938SGonglei void qemu_boot_set(const char *boot_order, Error **errp);
1967dc5af55SDominik Dingel 
1977f9d6e54SMarkus Armbruster QemuOpts *qemu_get_machine_opts(void);
1987f9d6e54SMarkus Armbruster 
199f8b6f8edSMarcel Apfelbaum bool defaults_enabled(void);
2009c17d615SPaolo Bonzini 
201968854c8SAmos Kong extern QemuOptsList qemu_legacy_drive_opts;
202968854c8SAmos Kong extern QemuOptsList qemu_common_drive_opts;
2034d454574SPaolo Bonzini extern QemuOptsList qemu_drive_opts;
204c5f3014bSKevin Wolf extern QemuOptsList bdrv_runtime_opts;
2054d454574SPaolo Bonzini extern QemuOptsList qemu_chardev_opts;
2064d454574SPaolo Bonzini extern QemuOptsList qemu_device_opts;
2074d454574SPaolo Bonzini extern QemuOptsList qemu_netdev_opts;
20878cd6f7bSThomas Huth extern QemuOptsList qemu_nic_opts;
2094d454574SPaolo Bonzini extern QemuOptsList qemu_net_opts;
2104d454574SPaolo Bonzini extern QemuOptsList qemu_global_opts;
2114d454574SPaolo Bonzini extern QemuOptsList qemu_mon_opts;
2124d454574SPaolo Bonzini 
2139c17d615SPaolo Bonzini #endif
214