blob: 4063533f2b209f31848d0cbf3d26730c2c6e9771 [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"
6
aliguori49dc7682009-03-08 16:26:59 +00007#ifdef _WIN32
8#include <windows.h>
9#endif
10
pbrook87ecb682007-11-17 17:14:51 +000011/* vl.c */
12extern const char *bios_name;
13extern const char *bios_dir;
14
15extern int vm_running;
16extern const char *qemu_name;
blueswir18fcb1b92008-09-18 18:29:08 +000017extern uint8_t qemu_uuid[];
aliguoric4be29f2009-04-17 18:58:14 +000018int qemu_uuid_parse(const char *str, uint8_t *uuid);
blueswir18fcb1b92008-09-18 18:29:08 +000019#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 +000020
21typedef struct vm_change_state_entry VMChangeStateEntry;
aliguori9781e042009-01-22 17:15:29 +000022typedef void VMChangeStateHandler(void *opaque, int running, int reason);
pbrook87ecb682007-11-17 17:14:51 +000023
24VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
25 void *opaque);
26void qemu_del_vm_change_state_handler(VMChangeStateEntry *e);
27
pbrook87ecb682007-11-17 17:14:51 +000028void vm_start(void);
29void vm_stop(int reason);
30
31int64_t cpu_get_ticks(void);
32void cpu_enable_ticks(void);
33void cpu_disable_ticks(void);
34
35void qemu_system_reset_request(void);
36void qemu_system_shutdown_request(void);
37void qemu_system_powerdown_request(void);
aurel32cf7a2fe2008-03-18 06:53:05 +000038int qemu_shutdown_requested(void);
39int qemu_reset_requested(void);
40int qemu_powerdown_requested(void);
Paul Brook1ad21342009-05-19 16:17:58 +010041#ifdef NEED_CPU_H
aurel32cf7a2fe2008-03-18 06:53:05 +000042#if !defined(TARGET_SPARC) && !defined(TARGET_I386)
pbrook87ecb682007-11-17 17:14:51 +000043// Please implement a power failure function to signal the OS
44#define qemu_system_powerdown() do{}while(0)
45#else
46void qemu_system_powerdown(void);
47#endif
Paul Brook1ad21342009-05-19 16:17:58 +010048#endif
aurel32cf7a2fe2008-03-18 06:53:05 +000049void qemu_system_reset(void);
pbrook87ecb682007-11-17 17:14:51 +000050
aliguori376253e2009-03-05 23:01:23 +000051void do_savevm(Monitor *mon, const char *name);
52void do_loadvm(Monitor *mon, const char *name);
53void do_delvm(Monitor *mon, const char *name);
54void do_info_snapshots(Monitor *mon);
pbrook87ecb682007-11-17 17:14:51 +000055
aliguori210f41b2008-10-13 03:13:12 +000056void qemu_announce_self(void);
57
pbrook87ecb682007-11-17 17:14:51 +000058void main_loop_wait(int timeout);
59
aliguori9366f412008-10-06 14:53:52 +000060int qemu_savevm_state_begin(QEMUFile *f);
61int qemu_savevm_state_iterate(QEMUFile *f);
62int qemu_savevm_state_complete(QEMUFile *f);
63int qemu_savevm_state(QEMUFile *f);
64int qemu_loadvm_state(QEMUFile *f);
65
aliguori56f3a5d2008-10-31 18:07:17 +000066#ifdef _WIN32
pbrook87ecb682007-11-17 17:14:51 +000067/* Polling handling */
68
69/* return TRUE if no sleep should be done afterwards */
70typedef int PollingFunc(void *opaque);
71
72int qemu_add_polling_cb(PollingFunc *func, void *opaque);
73void qemu_del_polling_cb(PollingFunc *func, void *opaque);
74
pbrook87ecb682007-11-17 17:14:51 +000075/* Wait objects handling */
76typedef void WaitObjectFunc(void *opaque);
77
78int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
79void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
80#endif
81
82/* TAP win32 */
aliguori7a9f6e42009-01-07 17:48:51 +000083int tap_win32_init(VLANState *vlan, const char *model,
84 const char *name, const char *ifname);
pbrook87ecb682007-11-17 17:14:51 +000085
86/* SLIRP */
aliguori376253e2009-03-05 23:01:23 +000087void do_info_slirp(Monitor *mon);
pbrook87ecb682007-11-17 17:14:51 +000088
Anthony Liguori993fbfd2009-05-21 16:54:00 -050089typedef enum DisplayType
90{
91 DT_DEFAULT,
92 DT_CURSES,
93 DT_SDL,
94 DT_VNC,
95 DT_NOGRAPHIC,
96} DisplayType;
97
pbrook87ecb682007-11-17 17:14:51 +000098extern int bios_size;
pbrook87ecb682007-11-17 17:14:51 +000099extern int cirrus_vga_enabled;
aliguoric2b3b412009-01-15 20:37:28 +0000100extern int std_vga_enabled;
pbrook87ecb682007-11-17 17:14:51 +0000101extern int vmsvga_enabled;
aliguori94909d92009-04-22 15:19:53 +0000102extern int xenfb_enabled;
pbrook87ecb682007-11-17 17:14:51 +0000103extern int graphic_width;
104extern int graphic_height;
105extern int graphic_depth;
Anthony Liguori993fbfd2009-05-21 16:54:00 -0500106extern DisplayType display_type;
pbrook87ecb682007-11-17 17:14:51 +0000107extern const char *keyboard_layout;
108extern int win2k_install_hack;
aliguori73822ec2009-01-15 20:11:34 +0000109extern int rtc_td_hack;
pbrook87ecb682007-11-17 17:14:51 +0000110extern int alt_grab;
111extern int usb_enabled;
112extern int smp_cpus;
113extern int cursor_hide;
114extern int graphic_rotate;
115extern int no_quit;
116extern int semihosting_enabled;
pbrook87ecb682007-11-17 17:14:51 +0000117extern int old_param;
pbrook87ecb682007-11-17 17:14:51 +0000118
blueswir1640f42e2009-04-19 10:18:01 +0000119#ifdef CONFIG_KQEMU
pbrook87ecb682007-11-17 17:14:51 +0000120extern int kqemu_allowed;
121#endif
122
aliguori268a3622009-04-21 22:30:27 +0000123#define MAX_NODES 64
124extern int nb_numa_nodes;
125extern uint64_t node_mem[MAX_NODES];
126
pbrook87ecb682007-11-17 17:14:51 +0000127#define MAX_OPTION_ROMS 16
128extern const char *option_rom[MAX_OPTION_ROMS];
129extern int nb_option_roms;
130
Paul Brook1ad21342009-05-19 16:17:58 +0100131#ifdef NEED_CPU_H
blueswir195efd112008-12-24 20:26:14 +0000132#if defined(TARGET_SPARC) || defined(TARGET_PPC)
pbrook87ecb682007-11-17 17:14:51 +0000133#define MAX_PROM_ENVS 128
134extern const char *prom_envs[MAX_PROM_ENVS];
135extern unsigned int nb_prom_envs;
136#endif
Paul Brook1ad21342009-05-19 16:17:58 +0100137#endif
pbrook87ecb682007-11-17 17:14:51 +0000138
thse4bcb142007-12-02 04:51:10 +0000139typedef enum {
Paul Brookaae94602009-05-14 22:35:06 +0100140 IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH, IF_MTD, IF_SD, IF_VIRTIO, IF_XEN,
141 IF_COUNT
thse4bcb142007-12-02 04:51:10 +0000142} BlockInterfaceType;
pbrook87ecb682007-11-17 17:14:51 +0000143
aliguori428c5702009-01-21 18:59:04 +0000144typedef enum {
145 BLOCK_ERR_REPORT, BLOCK_ERR_IGNORE, BLOCK_ERR_STOP_ENOSPC,
146 BLOCK_ERR_STOP_ANY
147} BlockInterfaceErrorAction;
148
thse4bcb142007-12-02 04:51:10 +0000149typedef struct DriveInfo {
150 BlockDriverState *bdrv;
thsf60d39b2007-12-17 03:55:57 +0000151 BlockInterfaceType type;
thse4bcb142007-12-02 04:51:10 +0000152 int bus;
153 int unit;
aliguori7d5aca92009-02-11 15:19:58 +0000154 int used;
aliguorib01b1112009-02-11 15:20:20 +0000155 int drive_opt_idx;
aliguori428c5702009-01-21 18:59:04 +0000156 BlockInterfaceErrorAction onerror;
aliguorifa879c62009-01-07 17:32:33 +0000157 char serial[21];
thse4bcb142007-12-02 04:51:10 +0000158} DriveInfo;
pbrook87ecb682007-11-17 17:14:51 +0000159
thse4bcb142007-12-02 04:51:10 +0000160#define MAX_IDE_DEVS 2
161#define MAX_SCSI_DEVS 7
162#define MAX_DRIVES 32
163
blueswir14d7a0882008-05-10 10:14:22 +0000164extern int nb_drives;
165extern DriveInfo drives_table[MAX_DRIVES+1];
thse4bcb142007-12-02 04:51:10 +0000166
thsf60d39b2007-12-17 03:55:57 +0000167extern int drive_get_index(BlockInterfaceType type, int bus, int unit);
168extern int drive_get_max_bus(BlockInterfaceType type);
aliguorib01b1112009-02-11 15:20:20 +0000169extern void drive_uninit(BlockDriverState *bdrv);
170extern void drive_remove(int index);
aliguorifa879c62009-01-07 17:32:33 +0000171extern const char *drive_get_serial(BlockDriverState *bdrv);
aliguori428c5702009-01-21 18:59:04 +0000172extern BlockInterfaceErrorAction drive_get_onerror(BlockDriverState *bdrv);
pbrook87ecb682007-11-17 17:14:51 +0000173
Paul Brookaae94602009-05-14 22:35:06 +0100174BlockDriverState *qdev_init_bdrv(DeviceState *dev, BlockInterfaceType type);
175
aliguoriec691c82009-02-11 15:20:37 +0000176struct drive_opt {
177 const char *file;
178 char opt[1024];
179 int used;
180};
181
182extern struct drive_opt drives_opt[MAX_DRIVES];
183extern int nb_drives_opt;
184
aliguori4d73cd32009-02-11 15:20:46 +0000185extern int drive_add(const char *file, const char *fmt, ...);
186extern int drive_init(struct drive_opt *arg, int snapshot, void *machine);
187
aliguori5e3cb532009-02-11 15:21:35 +0000188/* acpi */
189void qemu_system_hot_add_init(void);
aliguorica2c72b2009-02-11 15:21:41 +0000190void qemu_system_device_hot_add(int pcibus, int slot, int state);
aliguori5e3cb532009-02-11 15:21:35 +0000191
aliguori6f338c32009-02-11 15:21:54 +0000192/* device-hotplug */
193
194typedef int (dev_match_fn)(void *dev_private, void *arg);
195
196int add_init_drive(const char *opts);
197void destroy_nic(dev_match_fn *match_fn, void *arg);
198void destroy_bdrvs(dev_match_fn *match_fn, void *arg);
199
200/* pci-hotplug */
aliguori376253e2009-03-05 23:01:23 +0000201void pci_device_hot_add(Monitor *mon, const char *pci_addr, const char *type,
202 const char *opts);
203void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts);
204void pci_device_hot_remove(Monitor *mon, const char *pci_addr);
aliguori6f338c32009-02-11 15:21:54 +0000205void pci_device_hot_remove_success(int pcibus, int slot);
206
pbrook87ecb682007-11-17 17:14:51 +0000207/* serial ports */
208
209#define MAX_SERIAL_PORTS 4
210
211extern CharDriverState *serial_hds[MAX_SERIAL_PORTS];
212
213/* parallel ports */
214
215#define MAX_PARALLEL_PORTS 3
216
217extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
218
aliguori9ede2fd2009-01-15 20:05:25 +0000219/* virtio consoles */
220
221#define MAX_VIRTIO_CONSOLES 1
222
223extern CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
224
aliguori0e82f342008-10-31 18:44:40 +0000225#define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
226
pbrook87ecb682007-11-17 17:14:51 +0000227#ifdef NEED_CPU_H
228/* loader.c */
229int get_image_size(const char *filename);
blueswir1293f78b2008-05-12 17:22:13 +0000230int load_image(const char *filename, uint8_t *addr); /* deprecated */
231int load_image_targphys(const char *filename, target_phys_addr_t, int max_sz);
pbrook83c1f872008-10-22 18:20:20 +0000232int load_elf(const char *filename, int64_t address_offset,
pbrook87ecb682007-11-17 17:14:51 +0000233 uint64_t *pentry, uint64_t *lowaddr, uint64_t *highaddr);
blueswir1293f78b2008-05-12 17:22:13 +0000234int load_aout(const char *filename, target_phys_addr_t addr, int max_sz);
aliguori5a9154e2008-11-20 22:14:40 +0000235int load_uimage(const char *filename, target_ulong *ep, target_ulong *loadaddr,
236 int *is_linux);
blueswir1293f78b2008-05-12 17:22:13 +0000237
238int fread_targphys(target_phys_addr_t dst_addr, size_t nbytes, FILE *f);
239int fread_targphys_ok(target_phys_addr_t dst_addr, size_t nbytes, FILE *f);
240int read_targphys(int fd, target_phys_addr_t dst_addr, size_t nbytes);
241void pstrcpy_targphys(target_phys_addr_t dest, int buf_size,
242 const char *source);
pbrook87ecb682007-11-17 17:14:51 +0000243#endif
244
245#ifdef HAS_AUDIO
246struct soundhw {
247 const char *name;
248 const char *descr;
249 int enabled;
250 int isa;
251 union {
Paul Brook22d83b12009-05-12 12:33:04 +0100252 int (*init_isa) (qemu_irq *pic);
253 int (*init_pci) (PCIBus *bus);
pbrook87ecb682007-11-17 17:14:51 +0000254 } init;
255};
256
257extern struct soundhw soundhw[];
258#endif
259
aliguori376253e2009-03-05 23:01:23 +0000260void do_usb_add(Monitor *mon, const char *devname);
261void do_usb_del(Monitor *mon, const char *devname);
262void usb_info(Monitor *mon);
pbrook87ecb682007-11-17 17:14:51 +0000263
aliguori268a3622009-04-21 22:30:27 +0000264const char *get_opt_name(char *buf, int buf_size, const char *p, char delim);
aliguori63a01ef2008-10-31 19:10:00 +0000265const char *get_opt_value(char *buf, int buf_size, const char *p);
266int get_param_value(char *buf, int buf_size,
267 const char *tag, const char *str);
Jan Kiszkaffad4112009-04-26 18:53:42 +0200268int check_params(const char * const *params, const char *str);
aliguori63a01ef2008-10-31 19:10:00 +0000269
Paul Brookaae94602009-05-14 22:35:06 +0100270void register_devices(void);
271
pbrook87ecb682007-11-17 17:14:51 +0000272#endif