blob: 47975b573ef00f360b791a707cd2d50c95a21154 [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"
aliguori376253e2009-03-05 23:01:23 +00009
aliguori49dc7682009-03-08 16:26:59 +000010#ifdef _WIN32
11#include <windows.h>
12#endif
13
pbrook87ecb682007-11-17 17:14:51 +000014/* vl.c */
15extern const char *bios_name;
Paul Brook5cea8592009-05-30 00:52:44 +010016
17#define QEMU_FILE_TYPE_BIOS 0
18#define QEMU_FILE_TYPE_KEYMAP 1
19char *qemu_find_file(int type, const char *name);
pbrook87ecb682007-11-17 17:14:51 +000020
21extern int vm_running;
22extern const char *qemu_name;
blueswir18fcb1b92008-09-18 18:29:08 +000023extern uint8_t qemu_uuid[];
aliguoric4be29f2009-04-17 18:58:14 +000024int qemu_uuid_parse(const char *str, uint8_t *uuid);
blueswir18fcb1b92008-09-18 18:29:08 +000025#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 +000026
27typedef struct vm_change_state_entry VMChangeStateEntry;
aliguori9781e042009-01-22 17:15:29 +000028typedef void VMChangeStateHandler(void *opaque, int running, int reason);
pbrook87ecb682007-11-17 17:14:51 +000029
30VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
31 void *opaque);
32void qemu_del_vm_change_state_handler(VMChangeStateEntry *e);
33
pbrook87ecb682007-11-17 17:14:51 +000034void vm_start(void);
35void vm_stop(int reason);
36
Glauber Costa9f9e28c2009-05-21 17:38:01 -040037uint64_t ram_bytes_remaining(void);
38uint64_t ram_bytes_transferred(void);
39uint64_t ram_bytes_total(void);
40
pbrook87ecb682007-11-17 17:14:51 +000041int64_t cpu_get_ticks(void);
42void cpu_enable_ticks(void);
43void cpu_disable_ticks(void);
44
45void qemu_system_reset_request(void);
46void qemu_system_shutdown_request(void);
47void qemu_system_powerdown_request(void);
Luiz Capitulino0e8d2b52010-04-06 18:55:54 -030048void qemu_system_exit_request(void);
aurel32cf7a2fe2008-03-18 06:53:05 +000049int qemu_shutdown_requested(void);
50int qemu_reset_requested(void);
51int qemu_powerdown_requested(void);
Luiz Capitulino0e8d2b52010-04-06 18:55:54 -030052int qemu_exit_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);
Markus Armbruster03cd4652010-02-17 16:24:10 +010057int load_vmstate(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
Jan Kiszkaea375f92010-03-01 19:10:30 +010061void cpu_synchronize_all_states(void);
62void cpu_synchronize_all_post_reset(void);
63void cpu_synchronize_all_post_init(void);
64
aliguori210f41b2008-10-13 03:13:12 +000065void qemu_announce_self(void);
66
Paolo Bonzinid6f4ade2010-03-10 11:38:54 +010067void main_loop_wait(int nonblocking);
pbrook87ecb682007-11-17 17:14:51 +000068
Jan Kiszkaf327aa02009-11-30 18:21:21 +010069int qemu_savevm_state_begin(Monitor *mon, QEMUFile *f, int blk_enable,
70 int shared);
71int qemu_savevm_state_iterate(Monitor *mon, QEMUFile *f);
72int qemu_savevm_state_complete(Monitor *mon, QEMUFile *f);
73void qemu_savevm_state_cancel(Monitor *mon, QEMUFile *f);
aliguori9366f412008-10-06 14:53:52 +000074int qemu_loadvm_state(QEMUFile *f);
75
aliguori56f3a5d2008-10-31 18:07:17 +000076#ifdef _WIN32
pbrook87ecb682007-11-17 17:14:51 +000077/* Polling handling */
78
79/* return TRUE if no sleep should be done afterwards */
80typedef int PollingFunc(void *opaque);
81
82int qemu_add_polling_cb(PollingFunc *func, void *opaque);
83void qemu_del_polling_cb(PollingFunc *func, void *opaque);
84
pbrook87ecb682007-11-17 17:14:51 +000085/* Wait objects handling */
86typedef void WaitObjectFunc(void *opaque);
87
88int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
89void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
90#endif
91
pbrook87ecb682007-11-17 17:14:51 +000092/* SLIRP */
aliguori376253e2009-03-05 23:01:23 +000093void do_info_slirp(Monitor *mon);
pbrook87ecb682007-11-17 17:14:51 +000094
Anthony Liguori993fbfd2009-05-21 16:54:00 -050095typedef enum DisplayType
96{
97 DT_DEFAULT,
98 DT_CURSES,
99 DT_SDL,
100 DT_VNC,
101 DT_NOGRAPHIC,
102} DisplayType;
103
Paolo Bonzinid399f672009-07-27 23:17:51 +0200104extern int autostart;
pbrook87ecb682007-11-17 17:14:51 +0000105extern int bios_size;
Zachary Amsden86176752009-07-30 00:15:02 -1000106
107typedef enum {
108 VGA_NONE, VGA_STD, VGA_CIRRUS, VGA_VMWARE, VGA_XENFB
109} VGAInterfaceType;
110
111extern int vga_interface_type;
112#define cirrus_vga_enabled (vga_interface_type == VGA_CIRRUS)
113#define std_vga_enabled (vga_interface_type == VGA_STD)
114#define xenfb_enabled (vga_interface_type == VGA_XENFB)
115#define vmsvga_enabled (vga_interface_type == VGA_VMWARE)
116
pbrook87ecb682007-11-17 17:14:51 +0000117extern int graphic_width;
118extern int graphic_height;
119extern int graphic_depth;
Jes Sorensen6b35e7b2009-08-06 16:25:50 +0200120extern uint8_t irq0override;
Anthony Liguori993fbfd2009-05-21 16:54:00 -0500121extern DisplayType display_type;
pbrook87ecb682007-11-17 17:14:51 +0000122extern const char *keyboard_layout;
123extern int win2k_install_hack;
aliguori73822ec2009-01-15 20:11:34 +0000124extern int rtc_td_hack;
pbrook87ecb682007-11-17 17:14:51 +0000125extern int alt_grab;
Dustin Kirkland0ca9f8a2009-09-17 15:48:04 -0500126extern int ctrl_grab;
pbrook87ecb682007-11-17 17:14:51 +0000127extern int usb_enabled;
128extern int smp_cpus;
Jes Sorensen6be68d72009-07-23 17:03:42 +0200129extern int max_cpus;
pbrook87ecb682007-11-17 17:14:51 +0000130extern int cursor_hide;
131extern int graphic_rotate;
132extern int no_quit;
133extern int semihosting_enabled;
pbrook87ecb682007-11-17 17:14:51 +0000134extern int old_param;
Jan Kiszka95387492009-07-02 00:19:02 +0200135extern int boot_menu;
Jan Kiszka68752042009-09-15 13:36:04 +0200136extern QEMUClock *rtc_clock;
pbrook87ecb682007-11-17 17:14:51 +0000137
aliguori268a3622009-04-21 22:30:27 +0000138#define MAX_NODES 64
139extern int nb_numa_nodes;
140extern uint64_t node_mem[MAX_NODES];
Blue Swirl075cd322009-09-13 08:32:39 +0000141extern uint64_t node_cpumask[MAX_NODES];
aliguori268a3622009-04-21 22:30:27 +0000142
pbrook87ecb682007-11-17 17:14:51 +0000143#define MAX_OPTION_ROMS 16
144extern const char *option_rom[MAX_OPTION_ROMS];
145extern int nb_option_roms;
146
pbrook87ecb682007-11-17 17:14:51 +0000147#define MAX_PROM_ENVS 128
148extern const char *prom_envs[MAX_PROM_ENVS];
149extern unsigned int nb_prom_envs;
pbrook87ecb682007-11-17 17:14:51 +0000150
thse4bcb142007-12-02 04:51:10 +0000151typedef enum {
Gerd Hoffmanna8659e92009-07-31 12:25:39 +0200152 IF_NONE,
Paul Brookaae94602009-05-14 22:35:06 +0100153 IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH, IF_MTD, IF_SD, IF_VIRTIO, IF_XEN,
154 IF_COUNT
thse4bcb142007-12-02 04:51:10 +0000155} BlockInterfaceType;
pbrook87ecb682007-11-17 17:14:51 +0000156
aliguori428c5702009-01-21 18:59:04 +0000157typedef enum {
158 BLOCK_ERR_REPORT, BLOCK_ERR_IGNORE, BLOCK_ERR_STOP_ENOSPC,
159 BLOCK_ERR_STOP_ANY
160} BlockInterfaceErrorAction;
161
john cooperbf011292009-06-22 14:26:51 -0400162#define BLOCK_SERIAL_STRLEN 20
163
thse4bcb142007-12-02 04:51:10 +0000164typedef struct DriveInfo {
165 BlockDriverState *bdrv;
Gerd Hoffmann1dae12e2009-07-22 16:42:58 +0200166 char *id;
Markus Armbrusterc2cc47a2009-06-18 15:14:10 +0200167 const char *devaddr;
thsf60d39b2007-12-17 03:55:57 +0000168 BlockInterfaceType type;
thse4bcb142007-12-02 04:51:10 +0000169 int bus;
170 int unit;
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +0200171 QemuOpts *opts;
Kevin Wolfe9b2e812009-11-27 13:25:37 +0100172 BlockInterfaceErrorAction on_read_error;
Kevin Wolff7850092009-11-27 13:25:36 +0100173 BlockInterfaceErrorAction on_write_error;
john cooperbf011292009-06-22 14:26:51 -0400174 char serial[BLOCK_SERIAL_STRLEN + 1];
Blue Swirl72cf2d42009-09-12 07:36:22 +0000175 QTAILQ_ENTRY(DriveInfo) next;
thse4bcb142007-12-02 04:51:10 +0000176} DriveInfo;
pbrook87ecb682007-11-17 17:14:51 +0000177
thse4bcb142007-12-02 04:51:10 +0000178#define MAX_IDE_DEVS 2
179#define MAX_SCSI_DEVS 7
180#define MAX_DRIVES 32
181
Blue Swirl72cf2d42009-09-12 07:36:22 +0000182extern QTAILQ_HEAD(drivelist, DriveInfo) drives;
183extern QTAILQ_HEAD(driveoptlist, DriveOpt) driveopts;
thse4bcb142007-12-02 04:51:10 +0000184
Gerd Hoffmann751c6a12009-07-22 16:42:57 +0200185extern DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit);
Gerd Hoffmann2e810b32009-07-31 12:25:38 +0200186extern DriveInfo *drive_get_by_id(const char *id);
thsf60d39b2007-12-17 03:55:57 +0000187extern int drive_get_max_bus(BlockInterfaceType type);
Gerd Hoffmann56a14932009-09-25 21:42:46 +0200188extern void drive_uninit(DriveInfo *dinfo);
aliguorifa879c62009-01-07 17:32:33 +0000189extern const char *drive_get_serial(BlockDriverState *bdrv);
Kevin Wolff7850092009-11-27 13:25:36 +0100190
191extern BlockInterfaceErrorAction drive_get_on_error(
192 BlockDriverState *bdrv, int is_read);
pbrook87ecb682007-11-17 17:14:51 +0000193
Paul Brookaae94602009-05-14 22:35:06 +0100194BlockDriverState *qdev_init_bdrv(DeviceState *dev, BlockInterfaceType type);
195
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +0200196extern QemuOpts *drive_add(const char *file, const char *fmt, ...);
197extern DriveInfo *drive_init(QemuOpts *arg, void *machine, int *fatal_error);
aliguori4d73cd32009-02-11 15:20:46 +0000198
aliguori6f338c32009-02-11 15:21:54 +0000199/* device-hotplug */
200
Gerd Hoffmann751c6a12009-07-22 16:42:57 +0200201DriveInfo *add_init_drive(const char *opts);
aliguori6f338c32009-02-11 15:21:54 +0000202
203/* pci-hotplug */
Markus Armbruster6c6a58a2010-05-12 10:53:00 +0200204void pci_device_hot_add(Monitor *mon, const QDict *qdict);
Luiz Capitulinof18c16d2009-08-28 15:27:14 -0300205void drive_hot_add(Monitor *mon, const QDict *qdict);
Luiz Capitulino053801b2010-02-10 23:49:56 -0200206int pci_device_hot_remove(Monitor *mon, const char *pci_addr);
207int do_pci_device_hot_remove(Monitor *mon, const QDict *qdict,
208 QObject **ret_data);
aliguori6f338c32009-02-11 15:21:54 +0000209
pbrook87ecb682007-11-17 17:14:51 +0000210/* serial ports */
211
212#define MAX_SERIAL_PORTS 4
213
214extern CharDriverState *serial_hds[MAX_SERIAL_PORTS];
215
216/* parallel ports */
217
218#define MAX_PARALLEL_PORTS 3
219
220extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
221
aliguori0e82f342008-10-31 18:44:40 +0000222#define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
223
pbrook87ecb682007-11-17 17:14:51 +0000224#ifdef HAS_AUDIO
225struct soundhw {
226 const char *name;
227 const char *descr;
228 int enabled;
229 int isa;
230 union {
Paul Brook22d83b12009-05-12 12:33:04 +0100231 int (*init_isa) (qemu_irq *pic);
232 int (*init_pci) (PCIBus *bus);
pbrook87ecb682007-11-17 17:14:51 +0000233 } init;
234};
235
236extern struct soundhw soundhw[];
237#endif
238
Luiz Capitulinod54908a2009-08-28 15:27:13 -0300239void do_usb_add(Monitor *mon, const QDict *qdict);
240void do_usb_del(Monitor *mon, const QDict *qdict);
aliguori376253e2009-03-05 23:01:23 +0000241void usb_info(Monitor *mon);
pbrook87ecb682007-11-17 17:14:51 +0000242
Luiz Capitulino80cd3472010-02-25 12:11:44 -0300243void rtc_change_mon_event(struct tm *tm);
244
Paul Brookaae94602009-05-14 22:35:06 +0100245void register_devices(void);
246
pbrook87ecb682007-11-17 17:14:51 +0000247#endif