blob: 30e5e783d5add93888a8bf67f72019ec1242173f [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"
Gerd Hoffmann751c6a12009-07-22 16:42:57 +02007#include "sys-queue.h"
aliguori376253e2009-03-05 23:01:23 +00008
aliguori49dc7682009-03-08 16:26:59 +00009#ifdef _WIN32
10#include <windows.h>
11#endif
12
pbrook87ecb682007-11-17 17:14:51 +000013/* vl.c */
14extern const char *bios_name;
Paul Brook5cea8592009-05-30 00:52:44 +010015
16#define QEMU_FILE_TYPE_BIOS 0
17#define QEMU_FILE_TYPE_KEYMAP 1
18char *qemu_find_file(int type, const char *name);
pbrook87ecb682007-11-17 17:14:51 +000019
20extern int vm_running;
21extern const char *qemu_name;
blueswir18fcb1b92008-09-18 18:29:08 +000022extern uint8_t qemu_uuid[];
aliguoric4be29f2009-04-17 18:58:14 +000023int qemu_uuid_parse(const char *str, uint8_t *uuid);
blueswir18fcb1b92008-09-18 18:29:08 +000024#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 +000025
26typedef struct vm_change_state_entry VMChangeStateEntry;
aliguori9781e042009-01-22 17:15:29 +000027typedef void VMChangeStateHandler(void *opaque, int running, int reason);
pbrook87ecb682007-11-17 17:14:51 +000028
29VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
30 void *opaque);
31void qemu_del_vm_change_state_handler(VMChangeStateEntry *e);
32
pbrook87ecb682007-11-17 17:14:51 +000033void vm_start(void);
34void vm_stop(int reason);
35
Glauber Costa9f9e28c2009-05-21 17:38:01 -040036uint64_t ram_bytes_remaining(void);
37uint64_t ram_bytes_transferred(void);
38uint64_t ram_bytes_total(void);
39
pbrook87ecb682007-11-17 17:14:51 +000040int64_t cpu_get_ticks(void);
41void cpu_enable_ticks(void);
42void cpu_disable_ticks(void);
43
44void qemu_system_reset_request(void);
45void qemu_system_shutdown_request(void);
46void qemu_system_powerdown_request(void);
aurel32cf7a2fe2008-03-18 06:53:05 +000047int qemu_shutdown_requested(void);
48int qemu_reset_requested(void);
49int qemu_powerdown_requested(void);
Blue Swirld9c32312009-08-09 08:42:19 +000050extern qemu_irq qemu_system_powerdown;
aurel32cf7a2fe2008-03-18 06:53:05 +000051void qemu_system_reset(void);
pbrook87ecb682007-11-17 17:14:51 +000052
aliguori376253e2009-03-05 23:01:23 +000053void do_savevm(Monitor *mon, const char *name);
54void do_loadvm(Monitor *mon, const char *name);
55void do_delvm(Monitor *mon, const char *name);
56void do_info_snapshots(Monitor *mon);
pbrook87ecb682007-11-17 17:14:51 +000057
aliguori210f41b2008-10-13 03:13:12 +000058void qemu_announce_self(void);
59
pbrook87ecb682007-11-17 17:14:51 +000060void main_loop_wait(int timeout);
61
aliguori9366f412008-10-06 14:53:52 +000062int qemu_savevm_state_begin(QEMUFile *f);
63int qemu_savevm_state_iterate(QEMUFile *f);
64int qemu_savevm_state_complete(QEMUFile *f);
65int qemu_savevm_state(QEMUFile *f);
66int qemu_loadvm_state(QEMUFile *f);
67
aliguori56f3a5d2008-10-31 18:07:17 +000068#ifdef _WIN32
pbrook87ecb682007-11-17 17:14:51 +000069/* Polling handling */
70
71/* return TRUE if no sleep should be done afterwards */
72typedef int PollingFunc(void *opaque);
73
74int qemu_add_polling_cb(PollingFunc *func, void *opaque);
75void qemu_del_polling_cb(PollingFunc *func, void *opaque);
76
pbrook87ecb682007-11-17 17:14:51 +000077/* Wait objects handling */
78typedef void WaitObjectFunc(void *opaque);
79
80int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
81void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
82#endif
83
84/* TAP win32 */
aliguori7a9f6e42009-01-07 17:48:51 +000085int tap_win32_init(VLANState *vlan, const char *model,
86 const char *name, const char *ifname);
pbrook87ecb682007-11-17 17:14:51 +000087
88/* SLIRP */
aliguori376253e2009-03-05 23:01:23 +000089void do_info_slirp(Monitor *mon);
pbrook87ecb682007-11-17 17:14:51 +000090
Anthony Liguori993fbfd2009-05-21 16:54:00 -050091typedef enum DisplayType
92{
93 DT_DEFAULT,
94 DT_CURSES,
95 DT_SDL,
96 DT_VNC,
97 DT_NOGRAPHIC,
98} DisplayType;
99
Paolo Bonzinid399f672009-07-27 23:17:51 +0200100extern int autostart;
pbrook87ecb682007-11-17 17:14:51 +0000101extern int bios_size;
Zachary Amsden86176752009-07-30 00:15:02 -1000102
103typedef enum {
104 VGA_NONE, VGA_STD, VGA_CIRRUS, VGA_VMWARE, VGA_XENFB
105} VGAInterfaceType;
106
107extern int vga_interface_type;
108#define cirrus_vga_enabled (vga_interface_type == VGA_CIRRUS)
109#define std_vga_enabled (vga_interface_type == VGA_STD)
110#define xenfb_enabled (vga_interface_type == VGA_XENFB)
111#define vmsvga_enabled (vga_interface_type == VGA_VMWARE)
112
pbrook87ecb682007-11-17 17:14:51 +0000113extern int graphic_width;
114extern int graphic_height;
115extern int graphic_depth;
Anthony Liguori993fbfd2009-05-21 16:54:00 -0500116extern DisplayType display_type;
pbrook87ecb682007-11-17 17:14:51 +0000117extern const char *keyboard_layout;
118extern int win2k_install_hack;
aliguori73822ec2009-01-15 20:11:34 +0000119extern int rtc_td_hack;
pbrook87ecb682007-11-17 17:14:51 +0000120extern int alt_grab;
121extern int usb_enabled;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +0200122extern int virtio_balloon;
123extern const char *virtio_balloon_devaddr;
pbrook87ecb682007-11-17 17:14:51 +0000124extern int smp_cpus;
Jes Sorensen6be68d72009-07-23 17:03:42 +0200125extern int max_cpus;
pbrook87ecb682007-11-17 17:14:51 +0000126extern int cursor_hide;
127extern int graphic_rotate;
128extern int no_quit;
129extern int semihosting_enabled;
pbrook87ecb682007-11-17 17:14:51 +0000130extern int old_param;
Jan Kiszka95387492009-07-02 00:19:02 +0200131extern int boot_menu;
pbrook87ecb682007-11-17 17:14:51 +0000132
blueswir1640f42e2009-04-19 10:18:01 +0000133#ifdef CONFIG_KQEMU
pbrook87ecb682007-11-17 17:14:51 +0000134extern int kqemu_allowed;
135#endif
136
aliguori268a3622009-04-21 22:30:27 +0000137#define MAX_NODES 64
138extern int nb_numa_nodes;
139extern uint64_t node_mem[MAX_NODES];
140
pbrook87ecb682007-11-17 17:14:51 +0000141#define MAX_OPTION_ROMS 16
142extern const char *option_rom[MAX_OPTION_ROMS];
143extern int nb_option_roms;
144
Paul Brook1ad21342009-05-19 16:17:58 +0100145#ifdef NEED_CPU_H
blueswir195efd112008-12-24 20:26:14 +0000146#if defined(TARGET_SPARC) || defined(TARGET_PPC)
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;
150#endif
Paul Brook1ad21342009-05-19 16:17:58 +0100151#endif
pbrook87ecb682007-11-17 17:14:51 +0000152
thse4bcb142007-12-02 04:51:10 +0000153typedef enum {
Gerd Hoffmanna8659e92009-07-31 12:25:39 +0200154 IF_NONE,
Paul Brookaae94602009-05-14 22:35:06 +0100155 IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH, IF_MTD, IF_SD, IF_VIRTIO, IF_XEN,
156 IF_COUNT
thse4bcb142007-12-02 04:51:10 +0000157} BlockInterfaceType;
pbrook87ecb682007-11-17 17:14:51 +0000158
aliguori428c5702009-01-21 18:59:04 +0000159typedef enum {
160 BLOCK_ERR_REPORT, BLOCK_ERR_IGNORE, BLOCK_ERR_STOP_ENOSPC,
161 BLOCK_ERR_STOP_ANY
162} BlockInterfaceErrorAction;
163
john cooperbf011292009-06-22 14:26:51 -0400164#define BLOCK_SERIAL_STRLEN 20
165
thse4bcb142007-12-02 04:51:10 +0000166typedef struct DriveInfo {
167 BlockDriverState *bdrv;
Gerd Hoffmann1dae12e2009-07-22 16:42:58 +0200168 char *id;
Markus Armbrusterc2cc47a2009-06-18 15:14:10 +0200169 const char *devaddr;
thsf60d39b2007-12-17 03:55:57 +0000170 BlockInterfaceType type;
thse4bcb142007-12-02 04:51:10 +0000171 int bus;
172 int unit;
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +0200173 QemuOpts *opts;
aliguori428c5702009-01-21 18:59:04 +0000174 BlockInterfaceErrorAction onerror;
john cooperbf011292009-06-22 14:26:51 -0400175 char serial[BLOCK_SERIAL_STRLEN + 1];
Gerd Hoffmann751c6a12009-07-22 16:42:57 +0200176 TAILQ_ENTRY(DriveInfo) next;
thse4bcb142007-12-02 04:51:10 +0000177} DriveInfo;
pbrook87ecb682007-11-17 17:14:51 +0000178
thse4bcb142007-12-02 04:51:10 +0000179#define MAX_IDE_DEVS 2
180#define MAX_SCSI_DEVS 7
181#define MAX_DRIVES 32
182
Gerd Hoffmann751c6a12009-07-22 16:42:57 +0200183extern TAILQ_HEAD(drivelist, DriveInfo) drives;
Gerd Hoffmann3b0ba922009-07-22 16:42:59 +0200184extern TAILQ_HEAD(driveoptlist, DriveOpt) driveopts;
thse4bcb142007-12-02 04:51:10 +0000185
Gerd Hoffmann751c6a12009-07-22 16:42:57 +0200186extern DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit);
Gerd Hoffmann2e810b32009-07-31 12:25:38 +0200187extern DriveInfo *drive_get_by_id(const char *id);
thsf60d39b2007-12-17 03:55:57 +0000188extern int drive_get_max_bus(BlockInterfaceType type);
aliguorib01b1112009-02-11 15:20:20 +0000189extern void drive_uninit(BlockDriverState *bdrv);
aliguorifa879c62009-01-07 17:32:33 +0000190extern const char *drive_get_serial(BlockDriverState *bdrv);
aliguori428c5702009-01-21 18:59:04 +0000191extern BlockInterfaceErrorAction drive_get_onerror(BlockDriverState *bdrv);
pbrook87ecb682007-11-17 17:14:51 +0000192
Paul Brookaae94602009-05-14 22:35:06 +0100193BlockDriverState *qdev_init_bdrv(DeviceState *dev, BlockInterfaceType type);
194
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +0200195extern QemuOpts *drive_add(const char *file, const char *fmt, ...);
196extern DriveInfo *drive_init(QemuOpts *arg, void *machine, int *fatal_error);
aliguori4d73cd32009-02-11 15:20:46 +0000197
aliguori5e3cb532009-02-11 15:21:35 +0000198/* acpi */
Isaku Yamahata9d5e77a2009-06-18 19:57:00 +0900199typedef void (*qemu_system_device_hot_add_t)(int pcibus, int slot, int state);
200void qemu_system_device_hot_add_register(qemu_system_device_hot_add_t callback);
aliguorica2c72b2009-02-11 15:21:41 +0000201void qemu_system_device_hot_add(int pcibus, int slot, int state);
aliguori5e3cb532009-02-11 15:21:35 +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);
209void destroy_bdrvs(dev_match_fn *match_fn, void *arg);
210
211/* pci-hotplug */
aliguori376253e2009-03-05 23:01:23 +0000212void pci_device_hot_add(Monitor *mon, const char *pci_addr, const char *type,
213 const char *opts);
214void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts);
215void pci_device_hot_remove(Monitor *mon, const char *pci_addr);
aliguori6f338c32009-02-11 15:21:54 +0000216void pci_device_hot_remove_success(int pcibus, int slot);
217
pbrook87ecb682007-11-17 17:14:51 +0000218/* serial ports */
219
220#define MAX_SERIAL_PORTS 4
221
222extern CharDriverState *serial_hds[MAX_SERIAL_PORTS];
223
224/* parallel ports */
225
226#define MAX_PARALLEL_PORTS 3
227
228extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
229
aliguori9ede2fd2009-01-15 20:05:25 +0000230/* virtio consoles */
231
232#define MAX_VIRTIO_CONSOLES 1
233
234extern CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
235
aliguori0e82f342008-10-31 18:44:40 +0000236#define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
237
pbrook87ecb682007-11-17 17:14:51 +0000238#ifdef NEED_CPU_H
239/* loader.c */
240int get_image_size(const char *filename);
blueswir1293f78b2008-05-12 17:22:13 +0000241int load_image(const char *filename, uint8_t *addr); /* deprecated */
242int load_image_targphys(const char *filename, target_phys_addr_t, int max_sz);
pbrook83c1f872008-10-22 18:20:20 +0000243int load_elf(const char *filename, int64_t address_offset,
pbrook87ecb682007-11-17 17:14:51 +0000244 uint64_t *pentry, uint64_t *lowaddr, uint64_t *highaddr);
blueswir1293f78b2008-05-12 17:22:13 +0000245int load_aout(const char *filename, target_phys_addr_t addr, int max_sz);
aliguori5a9154e2008-11-20 22:14:40 +0000246int load_uimage(const char *filename, target_ulong *ep, target_ulong *loadaddr,
247 int *is_linux);
blueswir1293f78b2008-05-12 17:22:13 +0000248
249int fread_targphys(target_phys_addr_t dst_addr, size_t nbytes, FILE *f);
250int fread_targphys_ok(target_phys_addr_t dst_addr, size_t nbytes, FILE *f);
251int read_targphys(int fd, target_phys_addr_t dst_addr, size_t nbytes);
252void pstrcpy_targphys(target_phys_addr_t dest, int buf_size,
253 const char *source);
pbrook87ecb682007-11-17 17:14:51 +0000254#endif
255
256#ifdef HAS_AUDIO
257struct soundhw {
258 const char *name;
259 const char *descr;
260 int enabled;
261 int isa;
262 union {
Paul Brook22d83b12009-05-12 12:33:04 +0100263 int (*init_isa) (qemu_irq *pic);
264 int (*init_pci) (PCIBus *bus);
pbrook87ecb682007-11-17 17:14:51 +0000265 } init;
266};
267
268extern struct soundhw soundhw[];
269#endif
270
aliguori376253e2009-03-05 23:01:23 +0000271void do_usb_add(Monitor *mon, const char *devname);
272void do_usb_del(Monitor *mon, const char *devname);
273void usb_info(Monitor *mon);
pbrook87ecb682007-11-17 17:14:51 +0000274
Paul Brookaae94602009-05-14 22:35:06 +0100275void register_devices(void);
276
pbrook87ecb682007-11-17 17:14:51 +0000277#endif