blob: 1ed2ad033695a34f0c467f1748ce31625f215bfb [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;
Jes Sorensen6b35e7b2009-08-06 16:25:50 +0200116extern uint8_t irq0override;
Anthony Liguori993fbfd2009-05-21 16:54:00 -0500117extern DisplayType display_type;
pbrook87ecb682007-11-17 17:14:51 +0000118extern const char *keyboard_layout;
119extern int win2k_install_hack;
aliguori73822ec2009-01-15 20:11:34 +0000120extern int rtc_td_hack;
pbrook87ecb682007-11-17 17:14:51 +0000121extern int alt_grab;
122extern int usb_enabled;
Markus Armbruster7d4c3d52009-06-26 19:15:14 +0200123extern int virtio_balloon;
124extern const char *virtio_balloon_devaddr;
pbrook87ecb682007-11-17 17:14:51 +0000125extern int smp_cpus;
Jes Sorensen6be68d72009-07-23 17:03:42 +0200126extern int max_cpus;
pbrook87ecb682007-11-17 17:14:51 +0000127extern int cursor_hide;
128extern int graphic_rotate;
129extern int no_quit;
130extern int semihosting_enabled;
pbrook87ecb682007-11-17 17:14:51 +0000131extern int old_param;
Jan Kiszka95387492009-07-02 00:19:02 +0200132extern int boot_menu;
pbrook87ecb682007-11-17 17:14:51 +0000133
blueswir1640f42e2009-04-19 10:18:01 +0000134#ifdef CONFIG_KQEMU
pbrook87ecb682007-11-17 17:14:51 +0000135extern int kqemu_allowed;
136#endif
137
aliguori268a3622009-04-21 22:30:27 +0000138#define MAX_NODES 64
139extern int nb_numa_nodes;
140extern uint64_t node_mem[MAX_NODES];
141
pbrook87ecb682007-11-17 17:14:51 +0000142#define MAX_OPTION_ROMS 16
143extern const char *option_rom[MAX_OPTION_ROMS];
144extern int nb_option_roms;
145
Paul Brook1ad21342009-05-19 16:17:58 +0100146#ifdef NEED_CPU_H
blueswir195efd112008-12-24 20:26:14 +0000147#if defined(TARGET_SPARC) || defined(TARGET_PPC)
pbrook87ecb682007-11-17 17:14:51 +0000148#define MAX_PROM_ENVS 128
149extern const char *prom_envs[MAX_PROM_ENVS];
150extern unsigned int nb_prom_envs;
151#endif
Paul Brook1ad21342009-05-19 16:17:58 +0100152#endif
pbrook87ecb682007-11-17 17:14:51 +0000153
thse4bcb142007-12-02 04:51:10 +0000154typedef enum {
Gerd Hoffmanna8659e92009-07-31 12:25:39 +0200155 IF_NONE,
Paul Brookaae94602009-05-14 22:35:06 +0100156 IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH, IF_MTD, IF_SD, IF_VIRTIO, IF_XEN,
157 IF_COUNT
thse4bcb142007-12-02 04:51:10 +0000158} BlockInterfaceType;
pbrook87ecb682007-11-17 17:14:51 +0000159
aliguori428c5702009-01-21 18:59:04 +0000160typedef enum {
161 BLOCK_ERR_REPORT, BLOCK_ERR_IGNORE, BLOCK_ERR_STOP_ENOSPC,
162 BLOCK_ERR_STOP_ANY
163} BlockInterfaceErrorAction;
164
john cooperbf011292009-06-22 14:26:51 -0400165#define BLOCK_SERIAL_STRLEN 20
166
thse4bcb142007-12-02 04:51:10 +0000167typedef struct DriveInfo {
168 BlockDriverState *bdrv;
Gerd Hoffmann1dae12e2009-07-22 16:42:58 +0200169 char *id;
Markus Armbrusterc2cc47a2009-06-18 15:14:10 +0200170 const char *devaddr;
thsf60d39b2007-12-17 03:55:57 +0000171 BlockInterfaceType type;
thse4bcb142007-12-02 04:51:10 +0000172 int bus;
173 int unit;
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +0200174 QemuOpts *opts;
aliguori428c5702009-01-21 18:59:04 +0000175 BlockInterfaceErrorAction onerror;
john cooperbf011292009-06-22 14:26:51 -0400176 char serial[BLOCK_SERIAL_STRLEN + 1];
Gerd Hoffmann751c6a12009-07-22 16:42:57 +0200177 TAILQ_ENTRY(DriveInfo) next;
thse4bcb142007-12-02 04:51:10 +0000178} DriveInfo;
pbrook87ecb682007-11-17 17:14:51 +0000179
thse4bcb142007-12-02 04:51:10 +0000180#define MAX_IDE_DEVS 2
181#define MAX_SCSI_DEVS 7
182#define MAX_DRIVES 32
183
Gerd Hoffmann751c6a12009-07-22 16:42:57 +0200184extern TAILQ_HEAD(drivelist, DriveInfo) drives;
Gerd Hoffmann3b0ba922009-07-22 16:42:59 +0200185extern TAILQ_HEAD(driveoptlist, DriveOpt) driveopts;
thse4bcb142007-12-02 04:51:10 +0000186
Gerd Hoffmann751c6a12009-07-22 16:42:57 +0200187extern DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit);
Gerd Hoffmann2e810b32009-07-31 12:25:38 +0200188extern DriveInfo *drive_get_by_id(const char *id);
thsf60d39b2007-12-17 03:55:57 +0000189extern int drive_get_max_bus(BlockInterfaceType type);
aliguorib01b1112009-02-11 15:20:20 +0000190extern void drive_uninit(BlockDriverState *bdrv);
aliguorifa879c62009-01-07 17:32:33 +0000191extern const char *drive_get_serial(BlockDriverState *bdrv);
aliguori428c5702009-01-21 18:59:04 +0000192extern BlockInterfaceErrorAction drive_get_onerror(BlockDriverState *bdrv);
pbrook87ecb682007-11-17 17:14:51 +0000193
Paul Brookaae94602009-05-14 22:35:06 +0100194BlockDriverState *qdev_init_bdrv(DeviceState *dev, BlockInterfaceType type);
195
Gerd Hoffmann9dfd7c72009-07-22 16:43:04 +0200196extern QemuOpts *drive_add(const char *file, const char *fmt, ...);
197extern DriveInfo *drive_init(QemuOpts *arg, void *machine, int *fatal_error);
aliguori4d73cd32009-02-11 15:20:46 +0000198
aliguori5e3cb532009-02-11 15:21:35 +0000199/* acpi */
Isaku Yamahata9d5e77a2009-06-18 19:57:00 +0900200typedef void (*qemu_system_device_hot_add_t)(int pcibus, int slot, int state);
201void qemu_system_device_hot_add_register(qemu_system_device_hot_add_t callback);
aliguorica2c72b2009-02-11 15:21:41 +0000202void qemu_system_device_hot_add(int pcibus, int slot, int state);
aliguori5e3cb532009-02-11 15:21:35 +0000203
aliguori6f338c32009-02-11 15:21:54 +0000204/* device-hotplug */
205
206typedef int (dev_match_fn)(void *dev_private, void *arg);
207
Gerd Hoffmann751c6a12009-07-22 16:42:57 +0200208DriveInfo *add_init_drive(const char *opts);
aliguori6f338c32009-02-11 15:21:54 +0000209void destroy_nic(dev_match_fn *match_fn, void *arg);
210void destroy_bdrvs(dev_match_fn *match_fn, void *arg);
211
212/* pci-hotplug */
aliguori376253e2009-03-05 23:01:23 +0000213void pci_device_hot_add(Monitor *mon, const char *pci_addr, const char *type,
214 const char *opts);
215void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts);
216void pci_device_hot_remove(Monitor *mon, const char *pci_addr);
aliguori6f338c32009-02-11 15:21:54 +0000217void pci_device_hot_remove_success(int pcibus, int slot);
218
pbrook87ecb682007-11-17 17:14:51 +0000219/* serial ports */
220
221#define MAX_SERIAL_PORTS 4
222
223extern CharDriverState *serial_hds[MAX_SERIAL_PORTS];
224
225/* parallel ports */
226
227#define MAX_PARALLEL_PORTS 3
228
229extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
230
aliguori9ede2fd2009-01-15 20:05:25 +0000231/* virtio consoles */
232
233#define MAX_VIRTIO_CONSOLES 1
234
235extern CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
236
aliguori0e82f342008-10-31 18:44:40 +0000237#define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
238
pbrook87ecb682007-11-17 17:14:51 +0000239#ifdef NEED_CPU_H
240/* loader.c */
241int get_image_size(const char *filename);
blueswir1293f78b2008-05-12 17:22:13 +0000242int load_image(const char *filename, uint8_t *addr); /* deprecated */
243int load_image_targphys(const char *filename, target_phys_addr_t, int max_sz);
pbrook83c1f872008-10-22 18:20:20 +0000244int load_elf(const char *filename, int64_t address_offset,
pbrook87ecb682007-11-17 17:14:51 +0000245 uint64_t *pentry, uint64_t *lowaddr, uint64_t *highaddr);
blueswir1293f78b2008-05-12 17:22:13 +0000246int load_aout(const char *filename, target_phys_addr_t addr, int max_sz);
aliguori5a9154e2008-11-20 22:14:40 +0000247int load_uimage(const char *filename, target_ulong *ep, target_ulong *loadaddr,
248 int *is_linux);
blueswir1293f78b2008-05-12 17:22:13 +0000249
250int fread_targphys(target_phys_addr_t dst_addr, size_t nbytes, FILE *f);
251int fread_targphys_ok(target_phys_addr_t dst_addr, size_t nbytes, FILE *f);
252int read_targphys(int fd, target_phys_addr_t dst_addr, size_t nbytes);
253void pstrcpy_targphys(target_phys_addr_t dest, int buf_size,
254 const char *source);
pbrook87ecb682007-11-17 17:14:51 +0000255#endif
256
257#ifdef HAS_AUDIO
258struct soundhw {
259 const char *name;
260 const char *descr;
261 int enabled;
262 int isa;
263 union {
Paul Brook22d83b12009-05-12 12:33:04 +0100264 int (*init_isa) (qemu_irq *pic);
265 int (*init_pci) (PCIBus *bus);
pbrook87ecb682007-11-17 17:14:51 +0000266 } init;
267};
268
269extern struct soundhw soundhw[];
270#endif
271
aliguori376253e2009-03-05 23:01:23 +0000272void do_usb_add(Monitor *mon, const char *devname);
273void do_usb_del(Monitor *mon, const char *devname);
274void usb_info(Monitor *mon);
pbrook87ecb682007-11-17 17:14:51 +0000275
Paul Brookaae94602009-05-14 22:35:06 +0100276void register_devices(void);
277
pbrook87ecb682007-11-17 17:14:51 +0000278#endif