blob: 25a7c32a72d764ed5f61dbc6307cb85c7b9e863f [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);
41#if !defined(TARGET_SPARC) && !defined(TARGET_I386)
pbrook87ecb682007-11-17 17:14:51 +000042// Please implement a power failure function to signal the OS
43#define qemu_system_powerdown() do{}while(0)
44#else
45void qemu_system_powerdown(void);
46#endif
aurel32cf7a2fe2008-03-18 06:53:05 +000047void qemu_system_reset(void);
pbrook87ecb682007-11-17 17:14:51 +000048
aliguori376253e2009-03-05 23:01:23 +000049void do_savevm(Monitor *mon, const char *name);
50void do_loadvm(Monitor *mon, const char *name);
51void do_delvm(Monitor *mon, const char *name);
52void do_info_snapshots(Monitor *mon);
pbrook87ecb682007-11-17 17:14:51 +000053
aliguori210f41b2008-10-13 03:13:12 +000054void qemu_announce_self(void);
55
pbrook87ecb682007-11-17 17:14:51 +000056void main_loop_wait(int timeout);
57
aliguori9366f412008-10-06 14:53:52 +000058int qemu_savevm_state_begin(QEMUFile *f);
59int qemu_savevm_state_iterate(QEMUFile *f);
60int qemu_savevm_state_complete(QEMUFile *f);
61int qemu_savevm_state(QEMUFile *f);
62int qemu_loadvm_state(QEMUFile *f);
63
aliguori56f3a5d2008-10-31 18:07:17 +000064#ifdef _WIN32
pbrook87ecb682007-11-17 17:14:51 +000065/* Polling handling */
66
67/* return TRUE if no sleep should be done afterwards */
68typedef int PollingFunc(void *opaque);
69
70int qemu_add_polling_cb(PollingFunc *func, void *opaque);
71void qemu_del_polling_cb(PollingFunc *func, void *opaque);
72
pbrook87ecb682007-11-17 17:14:51 +000073/* Wait objects handling */
74typedef void WaitObjectFunc(void *opaque);
75
76int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
77void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
78#endif
79
80/* TAP win32 */
aliguori7a9f6e42009-01-07 17:48:51 +000081int tap_win32_init(VLANState *vlan, const char *model,
82 const char *name, const char *ifname);
pbrook87ecb682007-11-17 17:14:51 +000083
84/* SLIRP */
aliguori376253e2009-03-05 23:01:23 +000085void do_info_slirp(Monitor *mon);
pbrook87ecb682007-11-17 17:14:51 +000086
pbrook87ecb682007-11-17 17:14:51 +000087extern int bios_size;
pbrook87ecb682007-11-17 17:14:51 +000088extern int cirrus_vga_enabled;
aliguoric2b3b412009-01-15 20:37:28 +000089extern int std_vga_enabled;
pbrook87ecb682007-11-17 17:14:51 +000090extern int vmsvga_enabled;
aliguori94909d92009-04-22 15:19:53 +000091extern int xenfb_enabled;
pbrook87ecb682007-11-17 17:14:51 +000092extern int graphic_width;
93extern int graphic_height;
94extern int graphic_depth;
blueswir12bfdab62008-10-04 07:22:29 +000095extern int nographic;
pbrook87ecb682007-11-17 17:14:51 +000096extern const char *keyboard_layout;
97extern int win2k_install_hack;
aliguori73822ec2009-01-15 20:11:34 +000098extern int rtc_td_hack;
pbrook87ecb682007-11-17 17:14:51 +000099extern int alt_grab;
100extern int usb_enabled;
101extern int smp_cpus;
102extern int cursor_hide;
103extern int graphic_rotate;
104extern int no_quit;
105extern int semihosting_enabled;
pbrook87ecb682007-11-17 17:14:51 +0000106extern int old_param;
pbrook87ecb682007-11-17 17:14:51 +0000107
blueswir1640f42e2009-04-19 10:18:01 +0000108#ifdef CONFIG_KQEMU
pbrook87ecb682007-11-17 17:14:51 +0000109extern int kqemu_allowed;
110#endif
111
aliguori268a3622009-04-21 22:30:27 +0000112#define MAX_NODES 64
113extern int nb_numa_nodes;
114extern uint64_t node_mem[MAX_NODES];
115
pbrook87ecb682007-11-17 17:14:51 +0000116#define MAX_OPTION_ROMS 16
117extern const char *option_rom[MAX_OPTION_ROMS];
118extern int nb_option_roms;
119
blueswir195efd112008-12-24 20:26:14 +0000120#if defined(TARGET_SPARC) || defined(TARGET_PPC)
pbrook87ecb682007-11-17 17:14:51 +0000121#define MAX_PROM_ENVS 128
122extern const char *prom_envs[MAX_PROM_ENVS];
123extern unsigned int nb_prom_envs;
124#endif
125
pbrook87ecb682007-11-17 17:14:51 +0000126#if defined (TARGET_PPC)
127#define BIOS_SIZE (1024 * 1024)
128#elif defined (TARGET_SPARC64)
129#define BIOS_SIZE ((512 + 32) * 1024)
130#elif defined(TARGET_MIPS)
131#define BIOS_SIZE (4 * 1024 * 1024)
132#endif
133
thse4bcb142007-12-02 04:51:10 +0000134typedef enum {
aliguori62d23ef2009-04-22 15:19:30 +0000135 IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH, IF_MTD, IF_SD, IF_VIRTIO, IF_XEN
thse4bcb142007-12-02 04:51:10 +0000136} BlockInterfaceType;
pbrook87ecb682007-11-17 17:14:51 +0000137
aliguori428c5702009-01-21 18:59:04 +0000138typedef enum {
139 BLOCK_ERR_REPORT, BLOCK_ERR_IGNORE, BLOCK_ERR_STOP_ENOSPC,
140 BLOCK_ERR_STOP_ANY
141} BlockInterfaceErrorAction;
142
thse4bcb142007-12-02 04:51:10 +0000143typedef struct DriveInfo {
144 BlockDriverState *bdrv;
thsf60d39b2007-12-17 03:55:57 +0000145 BlockInterfaceType type;
thse4bcb142007-12-02 04:51:10 +0000146 int bus;
147 int unit;
aliguori7d5aca92009-02-11 15:19:58 +0000148 int used;
aliguorib01b1112009-02-11 15:20:20 +0000149 int drive_opt_idx;
aliguori428c5702009-01-21 18:59:04 +0000150 BlockInterfaceErrorAction onerror;
aliguorifa879c62009-01-07 17:32:33 +0000151 char serial[21];
thse4bcb142007-12-02 04:51:10 +0000152} DriveInfo;
pbrook87ecb682007-11-17 17:14:51 +0000153
thse4bcb142007-12-02 04:51:10 +0000154#define MAX_IDE_DEVS 2
155#define MAX_SCSI_DEVS 7
156#define MAX_DRIVES 32
157
blueswir14d7a0882008-05-10 10:14:22 +0000158extern int nb_drives;
159extern DriveInfo drives_table[MAX_DRIVES+1];
thse4bcb142007-12-02 04:51:10 +0000160
thsf60d39b2007-12-17 03:55:57 +0000161extern int drive_get_index(BlockInterfaceType type, int bus, int unit);
162extern int drive_get_max_bus(BlockInterfaceType type);
aliguorib01b1112009-02-11 15:20:20 +0000163extern void drive_uninit(BlockDriverState *bdrv);
164extern void drive_remove(int index);
aliguorifa879c62009-01-07 17:32:33 +0000165extern const char *drive_get_serial(BlockDriverState *bdrv);
aliguori428c5702009-01-21 18:59:04 +0000166extern BlockInterfaceErrorAction drive_get_onerror(BlockDriverState *bdrv);
pbrook87ecb682007-11-17 17:14:51 +0000167
aliguoriec691c82009-02-11 15:20:37 +0000168struct drive_opt {
169 const char *file;
170 char opt[1024];
171 int used;
172};
173
174extern struct drive_opt drives_opt[MAX_DRIVES];
175extern int nb_drives_opt;
176
aliguori4d73cd32009-02-11 15:20:46 +0000177extern int drive_add(const char *file, const char *fmt, ...);
178extern int drive_init(struct drive_opt *arg, int snapshot, void *machine);
179
aliguori5e3cb532009-02-11 15:21:35 +0000180/* acpi */
181void qemu_system_hot_add_init(void);
aliguorica2c72b2009-02-11 15:21:41 +0000182void qemu_system_device_hot_add(int pcibus, int slot, int state);
aliguori5e3cb532009-02-11 15:21:35 +0000183
aliguori6f338c32009-02-11 15:21:54 +0000184/* device-hotplug */
185
186typedef int (dev_match_fn)(void *dev_private, void *arg);
187
188int add_init_drive(const char *opts);
189void destroy_nic(dev_match_fn *match_fn, void *arg);
190void destroy_bdrvs(dev_match_fn *match_fn, void *arg);
191
192/* pci-hotplug */
aliguori376253e2009-03-05 23:01:23 +0000193void pci_device_hot_add(Monitor *mon, const char *pci_addr, const char *type,
194 const char *opts);
195void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts);
196void pci_device_hot_remove(Monitor *mon, const char *pci_addr);
aliguori6f338c32009-02-11 15:21:54 +0000197void pci_device_hot_remove_success(int pcibus, int slot);
198
pbrook87ecb682007-11-17 17:14:51 +0000199/* serial ports */
200
201#define MAX_SERIAL_PORTS 4
202
203extern CharDriverState *serial_hds[MAX_SERIAL_PORTS];
204
205/* parallel ports */
206
207#define MAX_PARALLEL_PORTS 3
208
209extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
210
aliguori9ede2fd2009-01-15 20:05:25 +0000211/* virtio consoles */
212
213#define MAX_VIRTIO_CONSOLES 1
214
215extern CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
216
aliguori0e82f342008-10-31 18:44:40 +0000217#define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
218
pbrook87ecb682007-11-17 17:14:51 +0000219#ifdef NEED_CPU_H
220/* loader.c */
221int get_image_size(const char *filename);
blueswir1293f78b2008-05-12 17:22:13 +0000222int load_image(const char *filename, uint8_t *addr); /* deprecated */
223int load_image_targphys(const char *filename, target_phys_addr_t, int max_sz);
pbrook83c1f872008-10-22 18:20:20 +0000224int load_elf(const char *filename, int64_t address_offset,
pbrook87ecb682007-11-17 17:14:51 +0000225 uint64_t *pentry, uint64_t *lowaddr, uint64_t *highaddr);
blueswir1293f78b2008-05-12 17:22:13 +0000226int load_aout(const char *filename, target_phys_addr_t addr, int max_sz);
aliguori5a9154e2008-11-20 22:14:40 +0000227int load_uimage(const char *filename, target_ulong *ep, target_ulong *loadaddr,
228 int *is_linux);
blueswir1293f78b2008-05-12 17:22:13 +0000229
230int fread_targphys(target_phys_addr_t dst_addr, size_t nbytes, FILE *f);
231int fread_targphys_ok(target_phys_addr_t dst_addr, size_t nbytes, FILE *f);
232int read_targphys(int fd, target_phys_addr_t dst_addr, size_t nbytes);
233void pstrcpy_targphys(target_phys_addr_t dest, int buf_size,
234 const char *source);
pbrook87ecb682007-11-17 17:14:51 +0000235#endif
236
237#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
aliguori376253e2009-03-05 23:01:23 +0000252void do_usb_add(Monitor *mon, const char *devname);
253void do_usb_del(Monitor *mon, const char *devname);
254void usb_info(Monitor *mon);
pbrook87ecb682007-11-17 17:14:51 +0000255
aliguori268a3622009-04-21 22:30:27 +0000256const char *get_opt_name(char *buf, int buf_size, const char *p, char delim);
aliguori63a01ef2008-10-31 19:10:00 +0000257const char *get_opt_value(char *buf, int buf_size, const char *p);
258int get_param_value(char *buf, int buf_size,
259 const char *tag, const char *str);
Jan Kiszkaffad4112009-04-26 18:53:42 +0200260int check_params(const char * const *params, const char *str);
aliguori63a01ef2008-10-31 19:10:00 +0000261
pbrook87ecb682007-11-17 17:14:51 +0000262#endif