blob: c7065ac038a8606238d08aba2e6d76a8a710bb31 [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;
pbrook87ecb682007-11-17 17:14:51 +0000102extern int cirrus_vga_enabled;
aliguoric2b3b412009-01-15 20:37:28 +0000103extern int std_vga_enabled;
pbrook87ecb682007-11-17 17:14:51 +0000104extern int vmsvga_enabled;
aliguori94909d92009-04-22 15:19:53 +0000105extern int xenfb_enabled;
pbrook87ecb682007-11-17 17:14:51 +0000106extern int graphic_width;
107extern int graphic_height;
108extern int graphic_depth;
Anthony Liguori993fbfd2009-05-21 16:54:00 -0500109extern DisplayType display_type;
pbrook87ecb682007-11-17 17:14:51 +0000110extern const char *keyboard_layout;
111extern int win2k_install_hack;
aliguori73822ec2009-01-15 20:11:34 +0000112extern int rtc_td_hack;
pbrook87ecb682007-11-17 17:14:51 +0000113extern int alt_grab;
114extern int usb_enabled;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +0200115extern int virtio_balloon;
116extern const char *virtio_balloon_devaddr;
pbrook87ecb682007-11-17 17:14:51 +0000117extern int smp_cpus;
Jes Sorensen6be68d72009-07-23 17:03:42 +0200118extern int max_cpus;
pbrook87ecb682007-11-17 17:14:51 +0000119extern int cursor_hide;
120extern int graphic_rotate;
121extern int no_quit;
122extern int semihosting_enabled;
pbrook87ecb682007-11-17 17:14:51 +0000123extern int old_param;
Jan Kiszka95387492009-07-02 00:19:02 +0200124extern int boot_menu;
pbrook87ecb682007-11-17 17:14:51 +0000125
blueswir1640f42e2009-04-19 10:18:01 +0000126#ifdef CONFIG_KQEMU
pbrook87ecb682007-11-17 17:14:51 +0000127extern int kqemu_allowed;
128#endif
129
aliguori268a3622009-04-21 22:30:27 +0000130#define MAX_NODES 64
131extern int nb_numa_nodes;
132extern uint64_t node_mem[MAX_NODES];
133
pbrook87ecb682007-11-17 17:14:51 +0000134#define MAX_OPTION_ROMS 16
135extern const char *option_rom[MAX_OPTION_ROMS];
136extern int nb_option_roms;
137
Paul Brook1ad21342009-05-19 16:17:58 +0100138#ifdef NEED_CPU_H
blueswir195efd112008-12-24 20:26:14 +0000139#if defined(TARGET_SPARC) || defined(TARGET_PPC)
pbrook87ecb682007-11-17 17:14:51 +0000140#define MAX_PROM_ENVS 128
141extern const char *prom_envs[MAX_PROM_ENVS];
142extern unsigned int nb_prom_envs;
143#endif
Paul Brook1ad21342009-05-19 16:17:58 +0100144#endif
pbrook87ecb682007-11-17 17:14:51 +0000145
thse4bcb142007-12-02 04:51:10 +0000146typedef enum {
Paul Brookaae94602009-05-14 22:35:06 +0100147 IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH, IF_MTD, IF_SD, IF_VIRTIO, IF_XEN,
148 IF_COUNT
thse4bcb142007-12-02 04:51:10 +0000149} BlockInterfaceType;
pbrook87ecb682007-11-17 17:14:51 +0000150
aliguori428c5702009-01-21 18:59:04 +0000151typedef enum {
152 BLOCK_ERR_REPORT, BLOCK_ERR_IGNORE, BLOCK_ERR_STOP_ENOSPC,
153 BLOCK_ERR_STOP_ANY
154} BlockInterfaceErrorAction;
155
john cooperbf011292009-06-22 14:26:51 -0400156#define BLOCK_SERIAL_STRLEN 20
157
thse4bcb142007-12-02 04:51:10 +0000158typedef struct DriveInfo {
159 BlockDriverState *bdrv;
Gerd Hoffmann1dae12e2009-07-22 16:42:58 +0200160 char *id;
Markus Armbrusterc2cc47a2009-06-18 15:14:10 +0200161 const char *devaddr;
thsf60d39b2007-12-17 03:55:57 +0000162 BlockInterfaceType type;
thse4bcb142007-12-02 04:51:10 +0000163 int bus;
164 int unit;
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +0200165 QemuOpts *opts;
aliguori428c5702009-01-21 18:59:04 +0000166 BlockInterfaceErrorAction onerror;
john cooperbf011292009-06-22 14:26:51 -0400167 char serial[BLOCK_SERIAL_STRLEN + 1];
Gerd Hoffmann751c6a12009-07-22 16:42:57 +0200168 TAILQ_ENTRY(DriveInfo) next;
thse4bcb142007-12-02 04:51:10 +0000169} DriveInfo;
pbrook87ecb682007-11-17 17:14:51 +0000170
thse4bcb142007-12-02 04:51:10 +0000171#define MAX_IDE_DEVS 2
172#define MAX_SCSI_DEVS 7
173#define MAX_DRIVES 32
174
Gerd Hoffmann751c6a12009-07-22 16:42:57 +0200175extern TAILQ_HEAD(drivelist, DriveInfo) drives;
Gerd Hoffmann3b0ba922009-07-22 16:42:59 +0200176extern TAILQ_HEAD(driveoptlist, DriveOpt) driveopts;
thse4bcb142007-12-02 04:51:10 +0000177
Gerd Hoffmann751c6a12009-07-22 16:42:57 +0200178extern DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit);
Gerd Hoffmann1dae12e2009-07-22 16:42:58 +0200179extern DriveInfo *drive_get_by_id(char *id);
thsf60d39b2007-12-17 03:55:57 +0000180extern int drive_get_max_bus(BlockInterfaceType type);
aliguorib01b1112009-02-11 15:20:20 +0000181extern void drive_uninit(BlockDriverState *bdrv);
aliguorifa879c62009-01-07 17:32:33 +0000182extern const char *drive_get_serial(BlockDriverState *bdrv);
aliguori428c5702009-01-21 18:59:04 +0000183extern BlockInterfaceErrorAction drive_get_onerror(BlockDriverState *bdrv);
pbrook87ecb682007-11-17 17:14:51 +0000184
Paul Brookaae94602009-05-14 22:35:06 +0100185BlockDriverState *qdev_init_bdrv(DeviceState *dev, BlockInterfaceType type);
186
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +0200187extern QemuOpts *drive_add(const char *file, const char *fmt, ...);
188extern DriveInfo *drive_init(QemuOpts *arg, void *machine, int *fatal_error);
aliguori4d73cd32009-02-11 15:20:46 +0000189
aliguori5e3cb532009-02-11 15:21:35 +0000190/* acpi */
Isaku Yamahata9d5e77a2009-06-18 19:57:00 +0900191typedef void (*qemu_system_device_hot_add_t)(int pcibus, int slot, int state);
192void qemu_system_device_hot_add_register(qemu_system_device_hot_add_t callback);
aliguorica2c72b2009-02-11 15:21:41 +0000193void qemu_system_device_hot_add(int pcibus, int slot, int state);
aliguori5e3cb532009-02-11 15:21:35 +0000194
aliguori6f338c32009-02-11 15:21:54 +0000195/* device-hotplug */
196
197typedef int (dev_match_fn)(void *dev_private, void *arg);
198
Gerd Hoffmann751c6a12009-07-22 16:42:57 +0200199DriveInfo *add_init_drive(const char *opts);
aliguori6f338c32009-02-11 15:21:54 +0000200void destroy_nic(dev_match_fn *match_fn, void *arg);
201void destroy_bdrvs(dev_match_fn *match_fn, void *arg);
202
203/* pci-hotplug */
aliguori376253e2009-03-05 23:01:23 +0000204void pci_device_hot_add(Monitor *mon, const char *pci_addr, const char *type,
205 const char *opts);
206void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts);
207void pci_device_hot_remove(Monitor *mon, const char *pci_addr);
aliguori6f338c32009-02-11 15:21:54 +0000208void pci_device_hot_remove_success(int pcibus, int slot);
209
pbrook87ecb682007-11-17 17:14:51 +0000210/* serial ports */
211
212#define MAX_SERIAL_PORTS 4
213
214extern CharDriverState *serial_hds[MAX_SERIAL_PORTS];
215
216/* parallel ports */
217
218#define MAX_PARALLEL_PORTS 3
219
220extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
221
aliguori9ede2fd2009-01-15 20:05:25 +0000222/* virtio consoles */
223
224#define MAX_VIRTIO_CONSOLES 1
225
226extern CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
227
aliguori0e82f342008-10-31 18:44:40 +0000228#define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
229
pbrook87ecb682007-11-17 17:14:51 +0000230#ifdef NEED_CPU_H
231/* loader.c */
232int get_image_size(const char *filename);
blueswir1293f78b2008-05-12 17:22:13 +0000233int load_image(const char *filename, uint8_t *addr); /* deprecated */
234int load_image_targphys(const char *filename, target_phys_addr_t, int max_sz);
pbrook83c1f872008-10-22 18:20:20 +0000235int load_elf(const char *filename, int64_t address_offset,
pbrook87ecb682007-11-17 17:14:51 +0000236 uint64_t *pentry, uint64_t *lowaddr, uint64_t *highaddr);
blueswir1293f78b2008-05-12 17:22:13 +0000237int load_aout(const char *filename, target_phys_addr_t addr, int max_sz);
aliguori5a9154e2008-11-20 22:14:40 +0000238int load_uimage(const char *filename, target_ulong *ep, target_ulong *loadaddr,
239 int *is_linux);
blueswir1293f78b2008-05-12 17:22:13 +0000240
241int fread_targphys(target_phys_addr_t dst_addr, size_t nbytes, FILE *f);
242int fread_targphys_ok(target_phys_addr_t dst_addr, size_t nbytes, FILE *f);
243int read_targphys(int fd, target_phys_addr_t dst_addr, size_t nbytes);
244void pstrcpy_targphys(target_phys_addr_t dest, int buf_size,
245 const char *source);
pbrook87ecb682007-11-17 17:14:51 +0000246#endif
247
248#ifdef HAS_AUDIO
249struct soundhw {
250 const char *name;
251 const char *descr;
252 int enabled;
253 int isa;
254 union {
Paul Brook22d83b12009-05-12 12:33:04 +0100255 int (*init_isa) (qemu_irq *pic);
256 int (*init_pci) (PCIBus *bus);
pbrook87ecb682007-11-17 17:14:51 +0000257 } init;
258};
259
260extern struct soundhw soundhw[];
261#endif
262
aliguori376253e2009-03-05 23:01:23 +0000263void do_usb_add(Monitor *mon, const char *devname);
264void do_usb_del(Monitor *mon, const char *devname);
265void usb_info(Monitor *mon);
pbrook87ecb682007-11-17 17:14:51 +0000266
Paul Brookaae94602009-05-14 22:35:06 +0100267void register_devices(void);
268
pbrook87ecb682007-11-17 17:14:51 +0000269#endif