• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef SYSEMU_H
2 #define SYSEMU_H
3 /* Misc. things related to the system emulator.  */
4 
5 #include "qemu-common.h"
6 #include "qemu-option.h"
7 #include "qemu-queue.h"
8 #include "qemu-timer.h"
9 #include "qdict.h"
10 #include "qerror.h"
11 
12 #ifdef _WIN32
13 #include <windows.h>
14 #endif
15 
16 /* vl.c */
17 extern const char *bios_name;
18 
19 #define QEMU_FILE_TYPE_BIOS   0
20 #define QEMU_FILE_TYPE_KEYMAP 1
21 char *qemu_find_file(int type, const char *name);
22 
23 extern int vm_running;
24 extern const char *qemu_name;
25 extern uint8_t qemu_uuid[];
26 int qemu_uuid_parse(const char *str, uint8_t *uuid);
27 #define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
28 
29 typedef struct vm_change_state_entry VMChangeStateEntry;
30 typedef void VMChangeStateHandler(void *opaque, int running, int reason);
31 
32 VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
33                                                      void *opaque);
34 void qemu_del_vm_change_state_handler(VMChangeStateEntry *e);
35 
36 void vm_start(void);
37 void vm_stop(int reason);
38 
39 uint64_t ram_bytes_remaining(void);
40 uint64_t ram_bytes_transferred(void);
41 uint64_t ram_bytes_total(void);
42 
43 int64_t cpu_get_ticks(void);
44 void cpu_enable_ticks(void);
45 void cpu_disable_ticks(void);
46 
47 void qemu_system_reset_request(void);
48 void qemu_system_shutdown_request(void);
49 void qemu_system_powerdown_request(void);
50 int qemu_shutdown_requested(void);
51 int qemu_reset_requested(void);
52 int qemu_powerdown_requested(void);
53 #ifdef NEED_CPU_H
54 #if !defined(TARGET_SPARC) && !defined(TARGET_I386)
55 // Please implement a power failure function to signal the OS
56 #define qemu_system_powerdown() do{}while(0)
57 #else
58 void qemu_system_powerdown(void);
59 #endif
60 #endif
61 void qemu_system_reset(void);
62 
63 void do_savevm(Monitor *mon, const char *name);
64 void do_loadvm(Monitor *mon, const char *name);
65 void do_delvm(Monitor *mon, const char *name);
66 void do_info_snapshots(Monitor *mon);
67 
68 void qemu_announce_self(void);
69 
70 void main_loop_wait(int timeout);
71 
72 int qemu_savevm_state_begin(QEMUFile *f);
73 int qemu_savevm_state_iterate(QEMUFile *f);
74 int qemu_savevm_state_complete(QEMUFile *f);
75 int qemu_savevm_state(QEMUFile *f);
76 int qemu_loadvm_state(QEMUFile *f);
77 
78 void qemu_errors_to_file(FILE *fp);
79 void qemu_errors_to_mon(Monitor *mon);
80 void qemu_errors_to_previous(void);
81 void qemu_error(const char *fmt, ...) __attribute__ ((format(printf, 1, 2)));
82 void qemu_error_internal(const char *file, int linenr, const char *func,
83                          const char *fmt, ...)
84                          __attribute__ ((format(printf, 4, 5)));
85 
86 #define qemu_error_new(fmt, ...) \
87     qemu_error_internal(__FILE__, __LINE__, __func__, fmt, ## __VA_ARGS__)
88 
89 #ifdef _WIN32
90 /* Polling handling */
91 
92 /* return TRUE if no sleep should be done afterwards */
93 typedef int PollingFunc(void *opaque);
94 
95 int qemu_add_polling_cb(PollingFunc *func, void *opaque);
96 void qemu_del_polling_cb(PollingFunc *func, void *opaque);
97 
98 /* Wait objects handling */
99 typedef void WaitObjectFunc(void *opaque);
100 
101 int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
102 void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
103 #endif
104 
105 /* TAP win32 */
106 int tap_win32_init(VLANState *vlan, const char *model,
107                    const char *name, const char *ifname);
108 
109 /* SLIRP */
110 void do_info_slirp(Monitor *mon);
111 
112 typedef enum DisplayType
113 {
114     DT_DEFAULT,
115     DT_CURSES,
116     DT_SDL,
117     DT_VNC,
118     DT_NOGRAPHIC,
119 } DisplayType;
120 
121 extern int bios_size;
122 extern int cirrus_vga_enabled;
123 extern int std_vga_enabled;
124 extern int vmsvga_enabled;
125 extern int xenfb_enabled;
126 extern int graphic_width;
127 extern int graphic_height;
128 extern int graphic_depth;
129 extern DisplayType display_type;
130 extern const char *keyboard_layout;
131 extern int win2k_install_hack;
132 extern int rtc_td_hack;
133 extern int alt_grab;
134 extern int usb_enabled;
135 extern int no_virtio_balloon;
136 extern int smp_cpus;
137 extern int cursor_hide;
138 extern int graphic_rotate;
139 extern int no_quit;
140 extern int semihosting_enabled;
141 extern int old_param;
142 
143 #ifdef CONFIG_KQEMU
144 extern int kqemu_allowed;
145 #endif
146 
147 #define MAX_NODES 64
148 extern int nb_numa_nodes;
149 extern uint64_t node_mem[MAX_NODES];
150 
151 #define MAX_OPTION_ROMS 16
152 extern const char *option_rom[MAX_OPTION_ROMS];
153 extern int nb_option_roms;
154 
155 #ifdef NEED_CPU_H
156 #if defined(TARGET_SPARC) || defined(TARGET_PPC)
157 #define MAX_PROM_ENVS 128
158 extern const char *prom_envs[MAX_PROM_ENVS];
159 extern unsigned int nb_prom_envs;
160 #endif
161 #endif
162 
163 typedef enum {
164     IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH, IF_MTD, IF_SD, IF_VIRTIO, IF_XEN,
165     IF_COUNT
166 } BlockInterfaceType;
167 
168 typedef enum {
169     BLOCK_ERR_REPORT, BLOCK_ERR_IGNORE, BLOCK_ERR_STOP_ENOSPC,
170     BLOCK_ERR_STOP_ANY
171 } BlockInterfaceErrorAction;
172 
173 typedef struct DriveInfo {
174     BlockDriverState *bdrv;
175     BlockInterfaceType type;
176     int bus;
177     int unit;
178     int used;
179     int drive_opt_idx;
180     BlockInterfaceErrorAction onerror;
181     char serial[21];
182 } DriveInfo;
183 
184 #define MAX_IDE_DEVS	2
185 #define MAX_SCSI_DEVS	7
186 #define MAX_DRIVES 32
187 
188 extern int nb_drives;
189 extern DriveInfo drives_table[MAX_DRIVES+1];
190 
191 extern int drive_get_index(BlockInterfaceType type, int bus, int unit);
192 extern int drive_get_max_bus(BlockInterfaceType type);
193 extern void drive_uninit(BlockDriverState *bdrv);
194 extern void drive_remove(int index);
195 extern const char *drive_get_serial(BlockDriverState *bdrv);
196 extern BlockInterfaceErrorAction drive_get_onerror(BlockDriverState *bdrv);
197 
198 BlockDriverState *qdev_init_bdrv(DeviceState *dev, BlockInterfaceType type);
199 
200 struct drive_opt {
201     const char *file;
202     char opt[1024];
203     int used;
204 };
205 
206 extern struct drive_opt drives_opt[MAX_DRIVES];
207 extern int nb_drives_opt;
208 
209 extern int drive_add(const char *file, const char *fmt, ...);
210 extern int drive_init(struct drive_opt *arg, int snapshot, void *machine);
211 
212 /* acpi */
213 void qemu_system_hot_add_init(void);
214 void qemu_system_device_hot_add(int pcibus, int slot, int state);
215 
216 /* device-hotplug */
217 
218 typedef int (dev_match_fn)(void *dev_private, void *arg);
219 
220 int add_init_drive(const char *opts);
221 void destroy_nic(dev_match_fn *match_fn, void *arg);
222 void destroy_bdrvs(dev_match_fn *match_fn, void *arg);
223 
224 /* pci-hotplug */
225 void pci_device_hot_add(Monitor *mon, const char *pci_addr, const char *type,
226                         const char *opts);
227 void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts);
228 void pci_device_hot_remove(Monitor *mon, const char *pci_addr);
229 void pci_device_hot_remove_success(int pcibus, int slot);
230 
231 /* serial ports */
232 
233 #define MAX_SERIAL_PORTS 4
234 
235 extern CharDriverState *serial_hds[MAX_SERIAL_PORTS];
236 
237 /* parallel ports */
238 
239 #define MAX_PARALLEL_PORTS 3
240 
241 extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
242 
243 /* virtio consoles */
244 
245 #define MAX_VIRTIO_CONSOLES 1
246 
247 extern CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
248 
249 #define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
250 
251 #ifdef NEED_CPU_H
252 /* loader.c */
253 int get_image_size(const char *filename);
254 int load_image(const char *filename, uint8_t *addr); /* deprecated */
255 int load_image_targphys(const char *filename, target_phys_addr_t, int max_sz);
256 int load_elf(const char *filename, int64_t address_offset,
257              uint64_t *pentry, uint64_t *lowaddr, uint64_t *highaddr);
258 int load_aout(const char *filename, target_phys_addr_t addr, int max_sz);
259 int load_uimage(const char *filename, target_ulong *ep, target_ulong *loadaddr,
260                 int *is_linux);
261 
262 int fread_targphys(target_phys_addr_t dst_addr, size_t nbytes, FILE *f);
263 int fread_targphys_ok(target_phys_addr_t dst_addr, size_t nbytes, FILE *f);
264 int read_targphys(int fd, target_phys_addr_t dst_addr, size_t nbytes);
265 void pstrcpy_targphys(target_phys_addr_t dest, int buf_size,
266                       const char *source);
267 #endif
268 
269 #ifdef HAS_AUDIO
270 struct soundhw {
271     const char *name;
272     const char *descr;
273     int enabled;
274     int isa;
275     union {
276         int (*init_isa) (qemu_irq *pic);
277         int (*init_pci) (PCIBus *bus);
278     } init;
279 };
280 
281 extern struct soundhw soundhw[];
282 #endif
283 
284 void do_usb_add(Monitor *mon, const char *devname);
285 void do_usb_del(Monitor *mon, const char *devname);
286 void usb_info(Monitor *mon);
287 
288 int get_param_value(char *buf, int buf_size,
289                     const char *tag, const char *str);
290 int check_params(char *buf, int buf_size,
291                  const char * const *params, const char *str);
292 
293 void register_devices(void);
294 
295 #endif
296