1 #ifndef SYSEMU_H 2 #define SYSEMU_H 3 /* Misc. things related to the system emulator. */ 4 5 #include "qemu-common.h" 6 #include "qemu/option.h" 7 #include "qemu/queue.h" 8 #include "qemu/timer.h" 9 #include "qapi/qmp/qdict.h" 10 #include "qapi/qmp/qerror.h" 11 12 #include "exec/hwaddr.h" 13 14 #ifdef _WIN32 15 #include <windows.h> 16 #endif 17 18 /* vl.c */ 19 extern const char *bios_name; 20 21 extern const char* savevm_on_exit; 22 extern int no_shutdown; 23 extern int vm_running; 24 extern int vm_can_run(void); 25 extern int qemu_debug_requested(void); 26 extern const char *qemu_name; 27 extern uint8_t qemu_uuid[]; 28 int qemu_uuid_parse(const char *str, uint8_t *uuid); 29 #define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx" 30 31 typedef struct vm_change_state_entry VMChangeStateEntry; 32 typedef void VMChangeStateHandler(void *opaque, int running, int reason); 33 34 VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb, 35 void *opaque); 36 void qemu_del_vm_change_state_handler(VMChangeStateEntry *e); 37 38 void vm_start(void); 39 void vm_stop(int reason); 40 41 uint64_t ram_bytes_remaining(void); 42 uint64_t ram_bytes_transferred(void); 43 uint64_t ram_bytes_total(void); 44 45 int64_t cpu_get_ticks(void); 46 void cpu_enable_ticks(void); 47 void cpu_disable_ticks(void); 48 49 void configure_icount(const char* opts); 50 void configure_alarms(const char* opts); 51 int init_timer_alarm(void); 52 int qemu_timer_alarm_pending(void); 53 void quit_timers(void); 54 55 int64_t qemu_icount; 56 int64_t qemu_icount_bias; 57 int icount_time_shift; 58 59 int tcg_has_work(void); 60 61 void qemu_system_reset_request(void); 62 void qemu_system_shutdown_request(void); 63 void qemu_system_powerdown_request(void); 64 int qemu_shutdown_requested(void); 65 int qemu_reset_requested(void); 66 int qemu_vmstop_requested(void); 67 int qemu_powerdown_requested(void); 68 void qemu_system_killed(int signal, pid_t pid); 69 #ifdef NEED_CPU_H 70 #if !defined(TARGET_SPARC) 71 // Please implement a power failure function to signal the OS 72 #define qemu_system_powerdown() do{}while(0) 73 #else 74 void qemu_system_powerdown(void); 75 #endif 76 #endif 77 void qemu_system_reset(void); 78 79 void do_savevm(Monitor *mon, const char *name); 80 void do_loadvm(Monitor *mon, const char *name); 81 void do_delvm(Monitor *mon, const char *name); 82 void do_info_snapshots(Monitor *mon, Monitor* err); 83 84 void qemu_announce_self(void); 85 86 void main_loop_wait(int timeout); 87 88 int qemu_savevm_state_begin(QEMUFile *f); 89 int qemu_savevm_state_iterate(QEMUFile *f); 90 int qemu_savevm_state_complete(QEMUFile *f); 91 int qemu_savevm_state(QEMUFile *f); 92 int qemu_loadvm_state(QEMUFile *f); 93 94 void qemu_errors_to_file(FILE *fp); 95 void qemu_errors_to_mon(Monitor *mon); 96 void qemu_errors_to_previous(void); 97 void qemu_error(const char *fmt, ...) __attribute__ ((format(printf, 1, 2))); 98 void qemu_error_internal(const char *file, int linenr, const char *func, 99 const char *fmt, ...) 100 __attribute__ ((format(printf, 4, 5))); 101 102 #define qemu_error_new(fmt, ...) \ 103 qemu_error_internal(__FILE__, __LINE__, __func__, fmt, ## __VA_ARGS__) 104 105 /* TAP win32 */ 106 int tap_win32_init(VLANState *vlan, const char *model, 107 const char *name, const char *ifname); 108 109 /* SLIRP */ 110 void do_info_slirp(Monitor *mon); 111 112 typedef enum DisplayType 113 { 114 DT_DEFAULT, 115 DT_CURSES, 116 DT_SDL, 117 DT_GTK, 118 DT_VNC, 119 DT_NOGRAPHIC, 120 DT_NONE, 121 } DisplayType; 122 123 extern int autostart; 124 extern int bios_size; 125 extern int cirrus_vga_enabled; 126 extern int std_vga_enabled; 127 extern int vmsvga_enabled; 128 extern int xenfb_enabled; 129 extern int graphic_width; 130 extern int graphic_height; 131 extern int graphic_depth; 132 extern DisplayType display_type; 133 extern const char *keyboard_layout; 134 extern int win2k_install_hack; 135 extern int rtc_td_hack; 136 extern int alt_grab; 137 extern int usb_enabled; 138 extern int no_virtio_balloon; 139 extern int smp_cpus; 140 extern int cursor_hide; 141 extern int graphic_rotate; 142 extern int no_quit; 143 extern int semihosting_enabled; 144 extern int old_param; 145 146 const char* dns_log_filename; 147 const char* drop_log_filename; 148 149 #define MAX_NODES 64 150 extern int nb_numa_nodes; 151 extern uint64_t node_mem[MAX_NODES]; 152 153 #define MAX_OPTION_ROMS 16 154 extern const char *option_rom[MAX_OPTION_ROMS]; 155 extern int nb_option_roms; 156 157 #ifdef NEED_CPU_H 158 #if defined(TARGET_SPARC) || defined(TARGET_PPC) 159 #define MAX_PROM_ENVS 128 160 extern const char *prom_envs[MAX_PROM_ENVS]; 161 extern unsigned int nb_prom_envs; 162 #endif 163 #endif 164 165 #if 0 166 typedef enum { 167 BLOCK_ERR_REPORT, BLOCK_ERR_IGNORE, BLOCK_ERR_STOP_ENOSPC, 168 BLOCK_ERR_STOP_ANY 169 } BlockInterfaceErrorAction; 170 171 struct DriveInfo { 172 BlockDriverState *bdrv; 173 BlockInterfaceType type; 174 int bus; 175 int unit; 176 int used; 177 int drive_opt_idx; 178 BlockInterfaceErrorAction onerror; 179 char serial[21]; 180 }; 181 182 #define MAX_IDE_DEVS 2 183 #define MAX_SCSI_DEVS 7 184 #define MAX_DRIVES 32 185 186 extern int nb_drives; 187 extern DriveInfo drives_table[MAX_DRIVES+1]; 188 189 extern int drive_get_index(BlockInterfaceType type, int bus, int unit); 190 extern int drive_get_max_bus(BlockInterfaceType type); 191 extern void drive_uninit(BlockDriverState *bdrv); 192 extern void drive_remove(int index); 193 extern const char *drive_get_serial(BlockDriverState *bdrv); 194 extern BlockInterfaceErrorAction drive_get_onerror(BlockDriverState *bdrv); 195 196 BlockDriverState *qdev_init_bdrv(DeviceState *dev, BlockInterfaceType type); 197 198 struct drive_opt { 199 const char *file; 200 char opt[1024]; 201 int used; 202 }; 203 204 extern struct drive_opt drives_opt[MAX_DRIVES]; 205 extern int nb_drives_opt; 206 207 extern int drive_add(const char *file, const char *fmt, ...); 208 extern int drive_init(struct drive_opt *arg, int snapshot, void *machine); 209 int add_init_drive(const char *opts); 210 #endif 211 212 /* acpi */ 213 void qemu_system_hot_add_init(void); 214 void qemu_system_device_hot_add(int pcibus, int slot, int state); 215 216 /* device-hotplug */ 217 218 typedef int (dev_match_fn)(void *dev_private, void *arg); 219 220 void destroy_nic(dev_match_fn *match_fn, void *arg); 221 void destroy_bdrvs(dev_match_fn *match_fn, void *arg); 222 223 #ifndef CONFIG_ANDROID 224 /* pci-hotplug */ 225 void pci_device_hot_add(Monitor *mon, const char *pci_addr, const char *type, 226 const char *opts); 227 void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts); 228 void pci_device_hot_remove(Monitor *mon, const char *pci_addr); 229 void pci_device_hot_remove_success(int pcibus, int slot); 230 #endif 231 232 /* serial ports */ 233 234 #define MAX_SERIAL_PORTS 4 235 236 extern CharDriverState *serial_hds[MAX_SERIAL_PORTS]; 237 238 /* parallel ports */ 239 240 #define MAX_PARALLEL_PORTS 3 241 242 extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS]; 243 244 /* virtio consoles */ 245 246 #define MAX_VIRTIO_CONSOLES 1 247 248 extern CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES]; 249 250 #define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR) 251 252 void do_usb_add(Monitor *mon, const char *devname); 253 void do_usb_del(Monitor *mon, const char *devname); 254 void usb_info(Monitor *mon); 255 256 int get_param_value(char *buf, int buf_size, 257 const char *tag, const char *str); 258 int check_params(char *buf, int buf_size, 259 const char * const *params, const char *str); 260 261 void register_devices(void); 262 263 #endif 264