blob: 9d80bb20273895aa9fb19ea3ebd4def727bb6298 [file] [log] [blame]
pbrook87ecb682007-11-17 17:14:51 +00001#ifndef SYSEMU_H
2#define SYSEMU_H
3/* Misc. things related to the system emulator. */
4
aliguori376253e2009-03-05 23:01:23 +00005#include "qemu-common.h"
Gerd Hoffmann62c58022009-07-22 16:43:00 +02006#include "qemu-option.h"
Blue Swirl72cf2d42009-09-12 07:36:22 +00007#include "qemu-queue.h"
Jan Kiszka68752042009-09-15 13:36:04 +02008#include "qemu-timer.h"
Luiz Capitulinod54908a2009-08-28 15:27:13 -03009#include "qdict.h"
Luiz Capitulino8204a912009-11-18 23:05:31 -020010#include "qerror.h"
aliguori376253e2009-03-05 23:01:23 +000011
aliguori49dc7682009-03-08 16:26:59 +000012#ifdef _WIN32
13#include <windows.h>
14#endif
15
pbrook87ecb682007-11-17 17:14:51 +000016/* vl.c */
17extern const char *bios_name;
Paul Brook5cea8592009-05-30 00:52:44 +010018
19#define QEMU_FILE_TYPE_BIOS 0
20#define QEMU_FILE_TYPE_KEYMAP 1
21char *qemu_find_file(int type, const char *name);
pbrook87ecb682007-11-17 17:14:51 +000022
23extern int vm_running;
24extern const char *qemu_name;
blueswir18fcb1b92008-09-18 18:29:08 +000025extern uint8_t qemu_uuid[];
aliguoric4be29f2009-04-17 18:58:14 +000026int qemu_uuid_parse(const char *str, uint8_t *uuid);
blueswir18fcb1b92008-09-18 18:29:08 +000027#define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
pbrook87ecb682007-11-17 17:14:51 +000028
29typedef struct vm_change_state_entry VMChangeStateEntry;
aliguori9781e042009-01-22 17:15:29 +000030typedef void VMChangeStateHandler(void *opaque, int running, int reason);
pbrook87ecb682007-11-17 17:14:51 +000031
32VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
33 void *opaque);
34void qemu_del_vm_change_state_handler(VMChangeStateEntry *e);
35
pbrook87ecb682007-11-17 17:14:51 +000036void vm_start(void);
37void vm_stop(int reason);
38
Glauber Costa9f9e28c2009-05-21 17:38:01 -040039uint64_t ram_bytes_remaining(void);
40uint64_t ram_bytes_transferred(void);
41uint64_t ram_bytes_total(void);
42
pbrook87ecb682007-11-17 17:14:51 +000043int64_t cpu_get_ticks(void);
44void cpu_enable_ticks(void);
45void cpu_disable_ticks(void);
46
47void qemu_system_reset_request(void);
48void qemu_system_shutdown_request(void);
49void qemu_system_powerdown_request(void);
aurel32cf7a2fe2008-03-18 06:53:05 +000050int qemu_shutdown_requested(void);
51int qemu_reset_requested(void);
52int qemu_powerdown_requested(void);
Blue Swirld9c32312009-08-09 08:42:19 +000053extern qemu_irq qemu_system_powerdown;
aurel32cf7a2fe2008-03-18 06:53:05 +000054void qemu_system_reset(void);
pbrook87ecb682007-11-17 17:14:51 +000055
Luiz Capitulinod54908a2009-08-28 15:27:13 -030056void do_savevm(Monitor *mon, const QDict *qdict);
Juan Quintela05f24012009-08-20 19:42:22 +020057int load_vmstate(Monitor *mon, const char *name);
Luiz Capitulinod54908a2009-08-28 15:27:13 -030058void do_delvm(Monitor *mon, const QDict *qdict);
aliguori376253e2009-03-05 23:01:23 +000059void do_info_snapshots(Monitor *mon);
pbrook87ecb682007-11-17 17:14:51 +000060
aliguori210f41b2008-10-13 03:13:12 +000061void qemu_announce_self(void);
62
pbrook87ecb682007-11-17 17:14:51 +000063void main_loop_wait(int timeout);
64
Jan Kiszkaf327aa02009-11-30 18:21:21 +010065int qemu_savevm_state_begin(Monitor *mon, QEMUFile *f, int blk_enable,
66 int shared);
67int qemu_savevm_state_iterate(Monitor *mon, QEMUFile *f);
68int qemu_savevm_state_complete(Monitor *mon, QEMUFile *f);
69void qemu_savevm_state_cancel(Monitor *mon, QEMUFile *f);
aliguori9366f412008-10-06 14:53:52 +000070int qemu_loadvm_state(QEMUFile *f);
71
Gerd Hoffmannac7531e2009-08-14 10:36:06 +020072void qemu_errors_to_file(FILE *fp);
73void qemu_errors_to_mon(Monitor *mon);
74void qemu_errors_to_previous(void);
75void qemu_error(const char *fmt, ...) __attribute__ ((format(printf, 1, 2)));
Luiz Capitulino8204a912009-11-18 23:05:31 -020076void qemu_error_internal(const char *file, int linenr, const char *func,
77 const char *fmt, ...)
78 __attribute__ ((format(printf, 4, 5)));
79
80#define qemu_error_new(fmt, ...) \
81 qemu_error_internal(__FILE__, __LINE__, __func__, fmt, ## __VA_ARGS__)
Gerd Hoffmannac7531e2009-08-14 10:36:06 +020082
aliguori56f3a5d2008-10-31 18:07:17 +000083#ifdef _WIN32
pbrook87ecb682007-11-17 17:14:51 +000084/* Polling handling */
85
86/* return TRUE if no sleep should be done afterwards */
87typedef int PollingFunc(void *opaque);
88
89int qemu_add_polling_cb(PollingFunc *func, void *opaque);
90void qemu_del_polling_cb(PollingFunc *func, void *opaque);
91
pbrook87ecb682007-11-17 17:14:51 +000092/* Wait objects handling */
93typedef void WaitObjectFunc(void *opaque);
94
95int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
96void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
97#endif
98
pbrook87ecb682007-11-17 17:14:51 +000099/* SLIRP */
aliguori376253e2009-03-05 23:01:23 +0000100void do_info_slirp(Monitor *mon);
pbrook87ecb682007-11-17 17:14:51 +0000101
Anthony Liguori993fbfd2009-05-21 16:54:00 -0500102typedef enum DisplayType
103{
104 DT_DEFAULT,
105 DT_CURSES,
106 DT_SDL,
107 DT_VNC,
108 DT_NOGRAPHIC,
109} DisplayType;
110
Paolo Bonzinid399f672009-07-27 23:17:51 +0200111extern int autostart;
pbrook87ecb682007-11-17 17:14:51 +0000112extern int bios_size;
Zachary Amsden86176752009-07-30 00:15:02 -1000113
114typedef enum {
115 VGA_NONE, VGA_STD, VGA_CIRRUS, VGA_VMWARE, VGA_XENFB
116} VGAInterfaceType;
117
118extern int vga_interface_type;
119#define cirrus_vga_enabled (vga_interface_type == VGA_CIRRUS)
120#define std_vga_enabled (vga_interface_type == VGA_STD)
121#define xenfb_enabled (vga_interface_type == VGA_XENFB)
122#define vmsvga_enabled (vga_interface_type == VGA_VMWARE)
123
pbrook87ecb682007-11-17 17:14:51 +0000124extern int graphic_width;
125extern int graphic_height;
126extern int graphic_depth;
Jes Sorensen6b35e7b2009-08-06 16:25:50 +0200127extern uint8_t irq0override;
Anthony Liguori993fbfd2009-05-21 16:54:00 -0500128extern DisplayType display_type;
pbrook87ecb682007-11-17 17:14:51 +0000129extern const char *keyboard_layout;
130extern int win2k_install_hack;
aliguori73822ec2009-01-15 20:11:34 +0000131extern int rtc_td_hack;
pbrook87ecb682007-11-17 17:14:51 +0000132extern int alt_grab;
Dustin Kirkland0ca9f8a2009-09-17 15:48:04 -0500133extern int ctrl_grab;
pbrook87ecb682007-11-17 17:14:51 +0000134extern int usb_enabled;
135extern int smp_cpus;
Jes Sorensen6be68d72009-07-23 17:03:42 +0200136extern int max_cpus;
pbrook87ecb682007-11-17 17:14:51 +0000137extern int cursor_hide;
138extern int graphic_rotate;
139extern int no_quit;
140extern int semihosting_enabled;
pbrook87ecb682007-11-17 17:14:51 +0000141extern int old_param;
Jan Kiszka95387492009-07-02 00:19:02 +0200142extern int boot_menu;
Jan Kiszka68752042009-09-15 13:36:04 +0200143extern QEMUClock *rtc_clock;
pbrook87ecb682007-11-17 17:14:51 +0000144
aliguori268a3622009-04-21 22:30:27 +0000145#define MAX_NODES 64
146extern int nb_numa_nodes;
147extern uint64_t node_mem[MAX_NODES];
Blue Swirl075cd322009-09-13 08:32:39 +0000148extern uint64_t node_cpumask[MAX_NODES];
aliguori268a3622009-04-21 22:30:27 +0000149
pbrook87ecb682007-11-17 17:14:51 +0000150#define MAX_OPTION_ROMS 16
151extern const char *option_rom[MAX_OPTION_ROMS];
152extern int nb_option_roms;
153
Paul Brook1ad21342009-05-19 16:17:58 +0100154#ifdef NEED_CPU_H
blueswir195efd112008-12-24 20:26:14 +0000155#if defined(TARGET_SPARC) || defined(TARGET_PPC)
pbrook87ecb682007-11-17 17:14:51 +0000156#define MAX_PROM_ENVS 128
157extern const char *prom_envs[MAX_PROM_ENVS];
158extern unsigned int nb_prom_envs;
159#endif
Paul Brook1ad21342009-05-19 16:17:58 +0100160#endif
pbrook87ecb682007-11-17 17:14:51 +0000161
thse4bcb142007-12-02 04:51:10 +0000162typedef enum {
Gerd Hoffmanna8659e92009-07-31 12:25:39 +0200163 IF_NONE,
Paul Brookaae94602009-05-14 22:35:06 +0100164 IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH, IF_MTD, IF_SD, IF_VIRTIO, IF_XEN,
165 IF_COUNT
thse4bcb142007-12-02 04:51:10 +0000166} BlockInterfaceType;
pbrook87ecb682007-11-17 17:14:51 +0000167
aliguori428c5702009-01-21 18:59:04 +0000168typedef enum {
169 BLOCK_ERR_REPORT, BLOCK_ERR_IGNORE, BLOCK_ERR_STOP_ENOSPC,
170 BLOCK_ERR_STOP_ANY
171} BlockInterfaceErrorAction;
172
john cooperbf011292009-06-22 14:26:51 -0400173#define BLOCK_SERIAL_STRLEN 20
174
thse4bcb142007-12-02 04:51:10 +0000175typedef struct DriveInfo {
176 BlockDriverState *bdrv;
Gerd Hoffmann1dae12e2009-07-22 16:42:58 +0200177 char *id;
Markus Armbrusterc2cc47a2009-06-18 15:14:10 +0200178 const char *devaddr;
thsf60d39b2007-12-17 03:55:57 +0000179 BlockInterfaceType type;
thse4bcb142007-12-02 04:51:10 +0000180 int bus;
181 int unit;
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +0200182 QemuOpts *opts;
Kevin Wolfe9b2e812009-11-27 13:25:37 +0100183 BlockInterfaceErrorAction on_read_error;
Kevin Wolff7850092009-11-27 13:25:36 +0100184 BlockInterfaceErrorAction on_write_error;
john cooperbf011292009-06-22 14:26:51 -0400185 char serial[BLOCK_SERIAL_STRLEN + 1];
Blue Swirl72cf2d42009-09-12 07:36:22 +0000186 QTAILQ_ENTRY(DriveInfo) next;
thse4bcb142007-12-02 04:51:10 +0000187} DriveInfo;
pbrook87ecb682007-11-17 17:14:51 +0000188
thse4bcb142007-12-02 04:51:10 +0000189#define MAX_IDE_DEVS 2
190#define MAX_SCSI_DEVS 7
191#define MAX_DRIVES 32
192
Blue Swirl72cf2d42009-09-12 07:36:22 +0000193extern QTAILQ_HEAD(drivelist, DriveInfo) drives;
194extern QTAILQ_HEAD(driveoptlist, DriveOpt) driveopts;
thse4bcb142007-12-02 04:51:10 +0000195
Gerd Hoffmann751c6a12009-07-22 16:42:57 +0200196extern DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit);
Gerd Hoffmann2e810b32009-07-31 12:25:38 +0200197extern DriveInfo *drive_get_by_id(const char *id);
thsf60d39b2007-12-17 03:55:57 +0000198extern int drive_get_max_bus(BlockInterfaceType type);
Gerd Hoffmann56a14932009-09-25 21:42:46 +0200199extern void drive_uninit(DriveInfo *dinfo);
aliguorifa879c62009-01-07 17:32:33 +0000200extern const char *drive_get_serial(BlockDriverState *bdrv);
Kevin Wolff7850092009-11-27 13:25:36 +0100201
202extern BlockInterfaceErrorAction drive_get_on_error(
203 BlockDriverState *bdrv, int is_read);
pbrook87ecb682007-11-17 17:14:51 +0000204
Paul Brookaae94602009-05-14 22:35:06 +0100205BlockDriverState *qdev_init_bdrv(DeviceState *dev, BlockInterfaceType type);
206
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +0200207extern QemuOpts *drive_add(const char *file, const char *fmt, ...);
208extern DriveInfo *drive_init(QemuOpts *arg, void *machine, int *fatal_error);
aliguori4d73cd32009-02-11 15:20:46 +0000209
aliguori6f338c32009-02-11 15:21:54 +0000210/* device-hotplug */
211
Gerd Hoffmann751c6a12009-07-22 16:42:57 +0200212DriveInfo *add_init_drive(const char *opts);
aliguori6f338c32009-02-11 15:21:54 +0000213
214/* pci-hotplug */
Luiz Capitulino7a344f72009-12-10 17:16:09 -0200215void pci_device_hot_add_print(Monitor *mon, const QObject *data);
216void pci_device_hot_add(Monitor *mon, const QDict *qdict, QObject **ret_data);
Luiz Capitulinof18c16d2009-08-28 15:27:14 -0300217void drive_hot_add(Monitor *mon, const QDict *qdict);
aliguori376253e2009-03-05 23:01:23 +0000218void pci_device_hot_remove(Monitor *mon, const char *pci_addr);
Luiz Capitulino6848d822009-10-16 12:23:48 -0300219void do_pci_device_hot_remove(Monitor *mon, const QDict *qdict,
220 QObject **ret_data);
aliguori6f338c32009-02-11 15:21:54 +0000221
pbrook87ecb682007-11-17 17:14:51 +0000222/* serial ports */
223
224#define MAX_SERIAL_PORTS 4
225
226extern CharDriverState *serial_hds[MAX_SERIAL_PORTS];
227
228/* parallel ports */
229
230#define MAX_PARALLEL_PORTS 3
231
232extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
233
aliguori9ede2fd2009-01-15 20:05:25 +0000234/* virtio consoles */
235
236#define MAX_VIRTIO_CONSOLES 1
237
238extern CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
239
aliguori0e82f342008-10-31 18:44:40 +0000240#define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
241
pbrook87ecb682007-11-17 17:14:51 +0000242#ifdef HAS_AUDIO
243struct soundhw {
244 const char *name;
245 const char *descr;
246 int enabled;
247 int isa;
248 union {
Paul Brook22d83b12009-05-12 12:33:04 +0100249 int (*init_isa) (qemu_irq *pic);
250 int (*init_pci) (PCIBus *bus);
pbrook87ecb682007-11-17 17:14:51 +0000251 } init;
252};
253
254extern struct soundhw soundhw[];
255#endif
256
Luiz Capitulinod54908a2009-08-28 15:27:13 -0300257void do_usb_add(Monitor *mon, const QDict *qdict);
258void do_usb_del(Monitor *mon, const QDict *qdict);
aliguori376253e2009-03-05 23:01:23 +0000259void usb_info(Monitor *mon);
pbrook87ecb682007-11-17 17:14:51 +0000260
Paul Brookaae94602009-05-14 22:35:06 +0100261void register_devices(void);
262
pbrook87ecb682007-11-17 17:14:51 +0000263#endif