blob: 763861ded56c1095325e9dbee19939530b064dfd [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"
aliguori376253e2009-03-05 23:01:23 +000010
aliguori49dc7682009-03-08 16:26:59 +000011#ifdef _WIN32
12#include <windows.h>
13#endif
14
pbrook87ecb682007-11-17 17:14:51 +000015/* vl.c */
16extern const char *bios_name;
Paul Brook5cea8592009-05-30 00:52:44 +010017
18#define QEMU_FILE_TYPE_BIOS 0
19#define QEMU_FILE_TYPE_KEYMAP 1
20char *qemu_find_file(int type, const char *name);
pbrook87ecb682007-11-17 17:14:51 +000021
22extern int vm_running;
23extern const char *qemu_name;
blueswir18fcb1b92008-09-18 18:29:08 +000024extern uint8_t qemu_uuid[];
aliguoric4be29f2009-04-17 18:58:14 +000025int qemu_uuid_parse(const char *str, uint8_t *uuid);
blueswir18fcb1b92008-09-18 18:29:08 +000026#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 +000027
28typedef struct vm_change_state_entry VMChangeStateEntry;
aliguori9781e042009-01-22 17:15:29 +000029typedef void VMChangeStateHandler(void *opaque, int running, int reason);
pbrook87ecb682007-11-17 17:14:51 +000030
31VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
32 void *opaque);
33void qemu_del_vm_change_state_handler(VMChangeStateEntry *e);
34
pbrook87ecb682007-11-17 17:14:51 +000035void vm_start(void);
36void vm_stop(int reason);
37
Glauber Costa9f9e28c2009-05-21 17:38:01 -040038uint64_t ram_bytes_remaining(void);
39uint64_t ram_bytes_transferred(void);
40uint64_t ram_bytes_total(void);
41
pbrook87ecb682007-11-17 17:14:51 +000042int64_t cpu_get_ticks(void);
43void cpu_enable_ticks(void);
44void cpu_disable_ticks(void);
45
46void qemu_system_reset_request(void);
47void qemu_system_shutdown_request(void);
48void qemu_system_powerdown_request(void);
aurel32cf7a2fe2008-03-18 06:53:05 +000049int qemu_shutdown_requested(void);
50int qemu_reset_requested(void);
51int qemu_powerdown_requested(void);
Blue Swirld9c32312009-08-09 08:42:19 +000052extern qemu_irq qemu_system_powerdown;
aurel32cf7a2fe2008-03-18 06:53:05 +000053void qemu_system_reset(void);
pbrook87ecb682007-11-17 17:14:51 +000054
Luiz Capitulinod54908a2009-08-28 15:27:13 -030055void do_savevm(Monitor *mon, const QDict *qdict);
Juan Quintela05f24012009-08-20 19:42:22 +020056int load_vmstate(Monitor *mon, const char *name);
Luiz Capitulinod54908a2009-08-28 15:27:13 -030057void do_delvm(Monitor *mon, const QDict *qdict);
aliguori376253e2009-03-05 23:01:23 +000058void do_info_snapshots(Monitor *mon);
pbrook87ecb682007-11-17 17:14:51 +000059
aliguori210f41b2008-10-13 03:13:12 +000060void qemu_announce_self(void);
61
pbrook87ecb682007-11-17 17:14:51 +000062void main_loop_wait(int timeout);
63
aliguori9366f412008-10-06 14:53:52 +000064int qemu_savevm_state_begin(QEMUFile *f);
65int qemu_savevm_state_iterate(QEMUFile *f);
66int qemu_savevm_state_complete(QEMUFile *f);
67int qemu_savevm_state(QEMUFile *f);
68int qemu_loadvm_state(QEMUFile *f);
69
Gerd Hoffmannac7531e2009-08-14 10:36:06 +020070void qemu_errors_to_file(FILE *fp);
71void qemu_errors_to_mon(Monitor *mon);
72void qemu_errors_to_previous(void);
73void qemu_error(const char *fmt, ...) __attribute__ ((format(printf, 1, 2)));
74
aliguori56f3a5d2008-10-31 18:07:17 +000075#ifdef _WIN32
pbrook87ecb682007-11-17 17:14:51 +000076/* Polling handling */
77
78/* return TRUE if no sleep should be done afterwards */
79typedef int PollingFunc(void *opaque);
80
81int qemu_add_polling_cb(PollingFunc *func, void *opaque);
82void qemu_del_polling_cb(PollingFunc *func, void *opaque);
83
pbrook87ecb682007-11-17 17:14:51 +000084/* Wait objects handling */
85typedef void WaitObjectFunc(void *opaque);
86
87int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
88void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
89#endif
90
91/* TAP win32 */
aliguori7a9f6e42009-01-07 17:48:51 +000092int tap_win32_init(VLANState *vlan, const char *model,
93 const char *name, const char *ifname);
pbrook87ecb682007-11-17 17:14:51 +000094
95/* SLIRP */
aliguori376253e2009-03-05 23:01:23 +000096void do_info_slirp(Monitor *mon);
pbrook87ecb682007-11-17 17:14:51 +000097
Anthony Liguori993fbfd2009-05-21 16:54:00 -050098typedef enum DisplayType
99{
100 DT_DEFAULT,
101 DT_CURSES,
102 DT_SDL,
103 DT_VNC,
104 DT_NOGRAPHIC,
105} DisplayType;
106
Paolo Bonzinid399f672009-07-27 23:17:51 +0200107extern int autostart;
pbrook87ecb682007-11-17 17:14:51 +0000108extern int bios_size;
Zachary Amsden86176752009-07-30 00:15:02 -1000109
110typedef enum {
111 VGA_NONE, VGA_STD, VGA_CIRRUS, VGA_VMWARE, VGA_XENFB
112} VGAInterfaceType;
113
114extern int vga_interface_type;
115#define cirrus_vga_enabled (vga_interface_type == VGA_CIRRUS)
116#define std_vga_enabled (vga_interface_type == VGA_STD)
117#define xenfb_enabled (vga_interface_type == VGA_XENFB)
118#define vmsvga_enabled (vga_interface_type == VGA_VMWARE)
119
pbrook87ecb682007-11-17 17:14:51 +0000120extern int graphic_width;
121extern int graphic_height;
122extern int graphic_depth;
Jes Sorensen6b35e7b2009-08-06 16:25:50 +0200123extern uint8_t irq0override;
Anthony Liguori993fbfd2009-05-21 16:54:00 -0500124extern DisplayType display_type;
pbrook87ecb682007-11-17 17:14:51 +0000125extern const char *keyboard_layout;
126extern int win2k_install_hack;
aliguori73822ec2009-01-15 20:11:34 +0000127extern int rtc_td_hack;
pbrook87ecb682007-11-17 17:14:51 +0000128extern int alt_grab;
Dustin Kirkland0ca9f8a2009-09-17 15:48:04 -0500129extern int ctrl_grab;
pbrook87ecb682007-11-17 17:14:51 +0000130extern int usb_enabled;
131extern int smp_cpus;
Jes Sorensen6be68d72009-07-23 17:03:42 +0200132extern int max_cpus;
pbrook87ecb682007-11-17 17:14:51 +0000133extern int cursor_hide;
134extern int graphic_rotate;
135extern int no_quit;
136extern int semihosting_enabled;
pbrook87ecb682007-11-17 17:14:51 +0000137extern int old_param;
Jan Kiszka95387492009-07-02 00:19:02 +0200138extern int boot_menu;
Jan Kiszka68752042009-09-15 13:36:04 +0200139extern QEMUClock *rtc_clock;
pbrook87ecb682007-11-17 17:14:51 +0000140
aliguori268a3622009-04-21 22:30:27 +0000141#define MAX_NODES 64
142extern int nb_numa_nodes;
143extern uint64_t node_mem[MAX_NODES];
Blue Swirl075cd322009-09-13 08:32:39 +0000144extern uint64_t node_cpumask[MAX_NODES];
aliguori268a3622009-04-21 22:30:27 +0000145
pbrook87ecb682007-11-17 17:14:51 +0000146#define MAX_OPTION_ROMS 16
147extern const char *option_rom[MAX_OPTION_ROMS];
148extern int nb_option_roms;
149
Paul Brook1ad21342009-05-19 16:17:58 +0100150#ifdef NEED_CPU_H
blueswir195efd112008-12-24 20:26:14 +0000151#if defined(TARGET_SPARC) || defined(TARGET_PPC)
pbrook87ecb682007-11-17 17:14:51 +0000152#define MAX_PROM_ENVS 128
153extern const char *prom_envs[MAX_PROM_ENVS];
154extern unsigned int nb_prom_envs;
155#endif
Paul Brook1ad21342009-05-19 16:17:58 +0100156#endif
pbrook87ecb682007-11-17 17:14:51 +0000157
thse4bcb142007-12-02 04:51:10 +0000158typedef enum {
Gerd Hoffmanna8659e92009-07-31 12:25:39 +0200159 IF_NONE,
Paul Brookaae94602009-05-14 22:35:06 +0100160 IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH, IF_MTD, IF_SD, IF_VIRTIO, IF_XEN,
161 IF_COUNT
thse4bcb142007-12-02 04:51:10 +0000162} BlockInterfaceType;
pbrook87ecb682007-11-17 17:14:51 +0000163
aliguori428c5702009-01-21 18:59:04 +0000164typedef enum {
165 BLOCK_ERR_REPORT, BLOCK_ERR_IGNORE, BLOCK_ERR_STOP_ENOSPC,
166 BLOCK_ERR_STOP_ANY
167} BlockInterfaceErrorAction;
168
john cooperbf011292009-06-22 14:26:51 -0400169#define BLOCK_SERIAL_STRLEN 20
170
thse4bcb142007-12-02 04:51:10 +0000171typedef struct DriveInfo {
172 BlockDriverState *bdrv;
Gerd Hoffmann1dae12e2009-07-22 16:42:58 +0200173 char *id;
Markus Armbrusterc2cc47a2009-06-18 15:14:10 +0200174 const char *devaddr;
thsf60d39b2007-12-17 03:55:57 +0000175 BlockInterfaceType type;
thse4bcb142007-12-02 04:51:10 +0000176 int bus;
177 int unit;
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +0200178 QemuOpts *opts;
aliguori428c5702009-01-21 18:59:04 +0000179 BlockInterfaceErrorAction onerror;
john cooperbf011292009-06-22 14:26:51 -0400180 char serial[BLOCK_SERIAL_STRLEN + 1];
Blue Swirl72cf2d42009-09-12 07:36:22 +0000181 QTAILQ_ENTRY(DriveInfo) next;
thse4bcb142007-12-02 04:51:10 +0000182} DriveInfo;
pbrook87ecb682007-11-17 17:14:51 +0000183
thse4bcb142007-12-02 04:51:10 +0000184#define MAX_IDE_DEVS 2
185#define MAX_SCSI_DEVS 7
186#define MAX_DRIVES 32
187
Blue Swirl72cf2d42009-09-12 07:36:22 +0000188extern QTAILQ_HEAD(drivelist, DriveInfo) drives;
189extern QTAILQ_HEAD(driveoptlist, DriveOpt) driveopts;
thse4bcb142007-12-02 04:51:10 +0000190
Gerd Hoffmann751c6a12009-07-22 16:42:57 +0200191extern DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit);
Gerd Hoffmann2e810b32009-07-31 12:25:38 +0200192extern DriveInfo *drive_get_by_id(const char *id);
thsf60d39b2007-12-17 03:55:57 +0000193extern int drive_get_max_bus(BlockInterfaceType type);
Gerd Hoffmann56a14932009-09-25 21:42:46 +0200194extern void drive_uninit(DriveInfo *dinfo);
aliguorifa879c62009-01-07 17:32:33 +0000195extern const char *drive_get_serial(BlockDriverState *bdrv);
aliguori428c5702009-01-21 18:59:04 +0000196extern BlockInterfaceErrorAction drive_get_onerror(BlockDriverState *bdrv);
pbrook87ecb682007-11-17 17:14:51 +0000197
Paul Brookaae94602009-05-14 22:35:06 +0100198BlockDriverState *qdev_init_bdrv(DeviceState *dev, BlockInterfaceType type);
199
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +0200200extern QemuOpts *drive_add(const char *file, const char *fmt, ...);
201extern DriveInfo *drive_init(QemuOpts *arg, void *machine, int *fatal_error);
aliguori4d73cd32009-02-11 15:20:46 +0000202
aliguori6f338c32009-02-11 15:21:54 +0000203/* device-hotplug */
204
205typedef int (dev_match_fn)(void *dev_private, void *arg);
206
Gerd Hoffmann751c6a12009-07-22 16:42:57 +0200207DriveInfo *add_init_drive(const char *opts);
aliguori6f338c32009-02-11 15:21:54 +0000208void destroy_nic(dev_match_fn *match_fn, void *arg);
aliguori6f338c32009-02-11 15:21:54 +0000209
210/* pci-hotplug */
Luiz Capitulino1d4daa92009-08-28 15:27:15 -0300211void pci_device_hot_add(Monitor *mon, const QDict *qdict);
Luiz Capitulinof18c16d2009-08-28 15:27:14 -0300212void drive_hot_add(Monitor *mon, const QDict *qdict);
aliguori376253e2009-03-05 23:01:23 +0000213void pci_device_hot_remove(Monitor *mon, const char *pci_addr);
Luiz Capitulinod54908a2009-08-28 15:27:13 -0300214void do_pci_device_hot_remove(Monitor *mon, const QDict *qdict);
Gerd Hoffmann3f848652009-09-25 21:42:45 +0200215void pci_device_hot_remove_success(PCIDevice *dev);
aliguori6f338c32009-02-11 15:21:54 +0000216
pbrook87ecb682007-11-17 17:14:51 +0000217/* serial ports */
218
219#define MAX_SERIAL_PORTS 4
220
221extern CharDriverState *serial_hds[MAX_SERIAL_PORTS];
222
223/* parallel ports */
224
225#define MAX_PARALLEL_PORTS 3
226
227extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
228
aliguori9ede2fd2009-01-15 20:05:25 +0000229/* virtio consoles */
230
231#define MAX_VIRTIO_CONSOLES 1
232
233extern CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
234
aliguori0e82f342008-10-31 18:44:40 +0000235#define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
236
pbrook87ecb682007-11-17 17:14:51 +0000237#ifdef HAS_AUDIO
238struct soundhw {
239 const char *name;
240 const char *descr;
241 int enabled;
242 int isa;
243 union {
Paul Brook22d83b12009-05-12 12:33:04 +0100244 int (*init_isa) (qemu_irq *pic);
245 int (*init_pci) (PCIBus *bus);
pbrook87ecb682007-11-17 17:14:51 +0000246 } init;
247};
248
249extern struct soundhw soundhw[];
250#endif
251
Luiz Capitulinod54908a2009-08-28 15:27:13 -0300252void do_usb_add(Monitor *mon, const QDict *qdict);
253void do_usb_del(Monitor *mon, const QDict *qdict);
aliguori376253e2009-03-05 23:01:23 +0000254void usb_info(Monitor *mon);
pbrook87ecb682007-11-17 17:14:51 +0000255
Paul Brookaae94602009-05-14 22:35:06 +0100256void register_devices(void);
257
pbrook87ecb682007-11-17 17:14:51 +0000258#endif