blob: cbfbb8e6d1da9db1d9e7920e05171e37972106c4 [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;
91extern int graphic_width;
92extern int graphic_height;
93extern int graphic_depth;
blueswir12bfdab62008-10-04 07:22:29 +000094extern int nographic;
pbrook87ecb682007-11-17 17:14:51 +000095extern const char *keyboard_layout;
96extern int win2k_install_hack;
aliguori73822ec2009-01-15 20:11:34 +000097extern int rtc_td_hack;
pbrook87ecb682007-11-17 17:14:51 +000098extern int alt_grab;
99extern int usb_enabled;
100extern int smp_cpus;
101extern int cursor_hide;
102extern int graphic_rotate;
103extern int no_quit;
104extern int semihosting_enabled;
pbrook87ecb682007-11-17 17:14:51 +0000105extern int old_param;
pbrook87ecb682007-11-17 17:14:51 +0000106
blueswir1640f42e2009-04-19 10:18:01 +0000107#ifdef CONFIG_KQEMU
pbrook87ecb682007-11-17 17:14:51 +0000108extern int kqemu_allowed;
109#endif
110
aliguori268a3622009-04-21 22:30:27 +0000111#define MAX_NODES 64
112extern int nb_numa_nodes;
113extern uint64_t node_mem[MAX_NODES];
114
pbrook87ecb682007-11-17 17:14:51 +0000115#define MAX_OPTION_ROMS 16
116extern const char *option_rom[MAX_OPTION_ROMS];
117extern int nb_option_roms;
118
blueswir195efd112008-12-24 20:26:14 +0000119#if defined(TARGET_SPARC) || defined(TARGET_PPC)
pbrook87ecb682007-11-17 17:14:51 +0000120#define MAX_PROM_ENVS 128
121extern const char *prom_envs[MAX_PROM_ENVS];
122extern unsigned int nb_prom_envs;
123#endif
124
pbrook87ecb682007-11-17 17:14:51 +0000125#if defined (TARGET_PPC)
126#define BIOS_SIZE (1024 * 1024)
127#elif defined (TARGET_SPARC64)
128#define BIOS_SIZE ((512 + 32) * 1024)
129#elif defined(TARGET_MIPS)
130#define BIOS_SIZE (4 * 1024 * 1024)
131#endif
132
thse4bcb142007-12-02 04:51:10 +0000133typedef enum {
aliguori6e02c382008-12-04 19:52:44 +0000134 IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH, IF_MTD, IF_SD, IF_VIRTIO
thse4bcb142007-12-02 04:51:10 +0000135} BlockInterfaceType;
pbrook87ecb682007-11-17 17:14:51 +0000136
aliguori428c5702009-01-21 18:59:04 +0000137typedef enum {
138 BLOCK_ERR_REPORT, BLOCK_ERR_IGNORE, BLOCK_ERR_STOP_ENOSPC,
139 BLOCK_ERR_STOP_ANY
140} BlockInterfaceErrorAction;
141
thse4bcb142007-12-02 04:51:10 +0000142typedef struct DriveInfo {
143 BlockDriverState *bdrv;
thsf60d39b2007-12-17 03:55:57 +0000144 BlockInterfaceType type;
thse4bcb142007-12-02 04:51:10 +0000145 int bus;
146 int unit;
aliguori7d5aca92009-02-11 15:19:58 +0000147 int used;
aliguorib01b1112009-02-11 15:20:20 +0000148 int drive_opt_idx;
aliguori428c5702009-01-21 18:59:04 +0000149 BlockInterfaceErrorAction onerror;
aliguorifa879c62009-01-07 17:32:33 +0000150 char serial[21];
thse4bcb142007-12-02 04:51:10 +0000151} DriveInfo;
pbrook87ecb682007-11-17 17:14:51 +0000152
thse4bcb142007-12-02 04:51:10 +0000153#define MAX_IDE_DEVS 2
154#define MAX_SCSI_DEVS 7
155#define MAX_DRIVES 32
156
blueswir14d7a0882008-05-10 10:14:22 +0000157extern int nb_drives;
158extern DriveInfo drives_table[MAX_DRIVES+1];
thse4bcb142007-12-02 04:51:10 +0000159
thsf60d39b2007-12-17 03:55:57 +0000160extern int drive_get_index(BlockInterfaceType type, int bus, int unit);
161extern int drive_get_max_bus(BlockInterfaceType type);
aliguorib01b1112009-02-11 15:20:20 +0000162extern void drive_uninit(BlockDriverState *bdrv);
163extern void drive_remove(int index);
aliguorifa879c62009-01-07 17:32:33 +0000164extern const char *drive_get_serial(BlockDriverState *bdrv);
aliguori428c5702009-01-21 18:59:04 +0000165extern BlockInterfaceErrorAction drive_get_onerror(BlockDriverState *bdrv);
pbrook87ecb682007-11-17 17:14:51 +0000166
aliguoriec691c82009-02-11 15:20:37 +0000167struct drive_opt {
168 const char *file;
169 char opt[1024];
170 int used;
171};
172
173extern struct drive_opt drives_opt[MAX_DRIVES];
174extern int nb_drives_opt;
175
aliguori4d73cd32009-02-11 15:20:46 +0000176extern int drive_add(const char *file, const char *fmt, ...);
177extern int drive_init(struct drive_opt *arg, int snapshot, void *machine);
178
aliguori5e3cb532009-02-11 15:21:35 +0000179/* acpi */
180void qemu_system_hot_add_init(void);
aliguorica2c72b2009-02-11 15:21:41 +0000181void qemu_system_device_hot_add(int pcibus, int slot, int state);
aliguori5e3cb532009-02-11 15:21:35 +0000182
aliguori6f338c32009-02-11 15:21:54 +0000183/* device-hotplug */
184
185typedef int (dev_match_fn)(void *dev_private, void *arg);
186
187int add_init_drive(const char *opts);
188void destroy_nic(dev_match_fn *match_fn, void *arg);
189void destroy_bdrvs(dev_match_fn *match_fn, void *arg);
190
191/* pci-hotplug */
aliguori376253e2009-03-05 23:01:23 +0000192void pci_device_hot_add(Monitor *mon, const char *pci_addr, const char *type,
193 const char *opts);
194void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts);
195void pci_device_hot_remove(Monitor *mon, const char *pci_addr);
aliguori6f338c32009-02-11 15:21:54 +0000196void pci_device_hot_remove_success(int pcibus, int slot);
197
pbrook87ecb682007-11-17 17:14:51 +0000198/* serial ports */
199
200#define MAX_SERIAL_PORTS 4
201
202extern CharDriverState *serial_hds[MAX_SERIAL_PORTS];
203
204/* parallel ports */
205
206#define MAX_PARALLEL_PORTS 3
207
208extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
209
aliguori9ede2fd2009-01-15 20:05:25 +0000210/* virtio consoles */
211
212#define MAX_VIRTIO_CONSOLES 1
213
214extern CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
215
aliguori0e82f342008-10-31 18:44:40 +0000216#define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
217
pbrook87ecb682007-11-17 17:14:51 +0000218#ifdef NEED_CPU_H
219/* loader.c */
220int get_image_size(const char *filename);
blueswir1293f78b2008-05-12 17:22:13 +0000221int load_image(const char *filename, uint8_t *addr); /* deprecated */
222int load_image_targphys(const char *filename, target_phys_addr_t, int max_sz);
pbrook83c1f872008-10-22 18:20:20 +0000223int load_elf(const char *filename, int64_t address_offset,
pbrook87ecb682007-11-17 17:14:51 +0000224 uint64_t *pentry, uint64_t *lowaddr, uint64_t *highaddr);
blueswir1293f78b2008-05-12 17:22:13 +0000225int load_aout(const char *filename, target_phys_addr_t addr, int max_sz);
aliguori5a9154e2008-11-20 22:14:40 +0000226int load_uimage(const char *filename, target_ulong *ep, target_ulong *loadaddr,
227 int *is_linux);
blueswir1293f78b2008-05-12 17:22:13 +0000228
229int fread_targphys(target_phys_addr_t dst_addr, size_t nbytes, FILE *f);
230int fread_targphys_ok(target_phys_addr_t dst_addr, size_t nbytes, FILE *f);
231int read_targphys(int fd, target_phys_addr_t dst_addr, size_t nbytes);
232void pstrcpy_targphys(target_phys_addr_t dest, int buf_size,
233 const char *source);
pbrook87ecb682007-11-17 17:14:51 +0000234#endif
235
236#ifdef HAS_AUDIO
237struct soundhw {
238 const char *name;
239 const char *descr;
240 int enabled;
241 int isa;
242 union {
243 int (*init_isa) (AudioState *s, qemu_irq *pic);
244 int (*init_pci) (PCIBus *bus, AudioState *s);
245 } init;
246};
247
248extern struct soundhw soundhw[];
249#endif
250
aliguori376253e2009-03-05 23:01:23 +0000251void do_usb_add(Monitor *mon, const char *devname);
252void do_usb_del(Monitor *mon, const char *devname);
253void usb_info(Monitor *mon);
pbrook87ecb682007-11-17 17:14:51 +0000254
aliguori268a3622009-04-21 22:30:27 +0000255const char *get_opt_name(char *buf, int buf_size, const char *p, char delim);
aliguori63a01ef2008-10-31 19:10:00 +0000256const char *get_opt_value(char *buf, int buf_size, const char *p);
257int get_param_value(char *buf, int buf_size,
258 const char *tag, const char *str);
259int check_params(char *buf, int buf_size,
260 const char * const *params, const char *str);
261
pbrook87ecb682007-11-17 17:14:51 +0000262#endif