• 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 void qemu_system_killed(int signal, pid_t pid);
54 #ifdef NEED_CPU_H
55 #if !defined(TARGET_SPARC)
56 // Please implement a power failure function to signal the OS
57 #define qemu_system_powerdown() do{}while(0)
58 #else
59 void qemu_system_powerdown(void);
60 #endif
61 #endif
62 void qemu_system_reset(void);
63 
64 void do_savevm(Monitor *mon, const char *name);
65 void do_loadvm(Monitor *mon, const char *name);
66 void do_delvm(Monitor *mon, const char *name);
67 void do_info_snapshots(Monitor *mon, Monitor* err);
68 
69 void qemu_announce_self(void);
70 
71 void main_loop_wait(int timeout);
72 
73 int qemu_savevm_state_begin(QEMUFile *f);
74 int qemu_savevm_state_iterate(QEMUFile *f);
75 int qemu_savevm_state_complete(QEMUFile *f);
76 int qemu_savevm_state(QEMUFile *f);
77 int qemu_loadvm_state(QEMUFile *f);
78 
79 void qemu_errors_to_file(FILE *fp);
80 void qemu_errors_to_mon(Monitor *mon);
81 void qemu_errors_to_previous(void);
82 void qemu_error(const char *fmt, ...) __attribute__ ((format(printf, 1, 2)));
83 void qemu_error_internal(const char *file, int linenr, const char *func,
84                          const char *fmt, ...)
85                          __attribute__ ((format(printf, 4, 5)));
86 
87 #define qemu_error_new(fmt, ...) \
88     qemu_error_internal(__FILE__, __LINE__, __func__, fmt, ## __VA_ARGS__)
89 
90 /* TAP win32 */
91 int tap_win32_init(VLANState *vlan, const char *model,
92                    const char *name, const char *ifname);
93 
94 /* SLIRP */
95 void do_info_slirp(Monitor *mon);
96 
97 extern int autostart;
98 extern int bios_size;
99 extern int cirrus_vga_enabled;
100 extern int std_vga_enabled;
101 extern int vmsvga_enabled;
102 extern int xenfb_enabled;
103 extern int graphic_width;
104 extern int graphic_height;
105 extern int graphic_depth;
106 extern DisplayType display_type;
107 extern const char *keyboard_layout;
108 extern int win2k_install_hack;
109 extern int rtc_td_hack;
110 extern int alt_grab;
111 extern int usb_enabled;
112 extern int no_virtio_balloon;
113 extern int smp_cpus;
114 extern int cursor_hide;
115 extern int graphic_rotate;
116 extern int no_quit;
117 extern int semihosting_enabled;
118 extern int old_param;
119 extern QEMUClock *rtc_clock;
120 
121 #define MAX_NODES 64
122 extern int nb_numa_nodes;
123 extern uint64_t node_mem[MAX_NODES];
124 
125 #define MAX_OPTION_ROMS 16
126 extern const char *option_rom[MAX_OPTION_ROMS];
127 extern int nb_option_roms;
128 
129 #ifdef NEED_CPU_H
130 #if defined(TARGET_SPARC) || defined(TARGET_PPC)
131 #define MAX_PROM_ENVS 128
132 extern const char *prom_envs[MAX_PROM_ENVS];
133 extern unsigned int nb_prom_envs;
134 #endif
135 #endif
136 
137 #if 0
138 typedef enum {
139     BLOCK_ERR_REPORT, BLOCK_ERR_IGNORE, BLOCK_ERR_STOP_ENOSPC,
140     BLOCK_ERR_STOP_ANY
141 } BlockInterfaceErrorAction;
142 
143 struct DriveInfo {
144     BlockDriverState *bdrv;
145     BlockInterfaceType type;
146     int bus;
147     int unit;
148     int used;
149     int drive_opt_idx;
150     BlockInterfaceErrorAction onerror;
151     char serial[21];
152 };
153 
154 #define MAX_IDE_DEVS	2
155 #define MAX_SCSI_DEVS	7
156 #define MAX_DRIVES 32
157 
158 extern int nb_drives;
159 extern DriveInfo drives_table[MAX_DRIVES+1];
160 
161 extern int drive_get_index(BlockInterfaceType type, int bus, int unit);
162 extern int drive_get_max_bus(BlockInterfaceType type);
163 extern void drive_uninit(BlockDriverState *bdrv);
164 extern void drive_remove(int index);
165 extern const char *drive_get_serial(BlockDriverState *bdrv);
166 extern BlockInterfaceErrorAction drive_get_onerror(BlockDriverState *bdrv);
167 
168 BlockDriverState *qdev_init_bdrv(DeviceState *dev, BlockInterfaceType type);
169 
170 struct drive_opt {
171     const char *file;
172     char opt[1024];
173     int used;
174 };
175 
176 extern struct drive_opt drives_opt[MAX_DRIVES];
177 extern int nb_drives_opt;
178 
179 extern int drive_add(const char *file, const char *fmt, ...);
180 extern int drive_init(struct drive_opt *arg, int snapshot, void *machine);
181 int add_init_drive(const char *opts);
182 #endif
183 
184 /* acpi */
185 void qemu_system_hot_add_init(void);
186 void qemu_system_device_hot_add(int pcibus, int slot, int state);
187 
188 /* device-hotplug */
189 
190 typedef int (dev_match_fn)(void *dev_private, void *arg);
191 
192 void destroy_nic(dev_match_fn *match_fn, void *arg);
193 void destroy_bdrvs(dev_match_fn *match_fn, void *arg);
194 
195 #ifndef CONFIG_ANDROID
196 /* pci-hotplug */
197 void pci_device_hot_add(Monitor *mon, const char *pci_addr, const char *type,
198                         const char *opts);
199 void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts);
200 void pci_device_hot_remove(Monitor *mon, const char *pci_addr);
201 void pci_device_hot_remove_success(int pcibus, int slot);
202 #endif
203 
204 /* serial ports */
205 
206 #define MAX_SERIAL_PORTS 4
207 
208 extern CharDriverState *serial_hds[MAX_SERIAL_PORTS];
209 
210 /* parallel ports */
211 
212 #define MAX_PARALLEL_PORTS 3
213 
214 extern CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
215 
216 /* virtio consoles */
217 
218 #define MAX_VIRTIO_CONSOLES 1
219 
220 extern CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
221 
222 #define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
223 
224 #ifdef NEED_CPU_H
225 /* loader.c */
226 int get_image_size(const char *filename);
227 int load_image(const char *filename, uint8_t *addr); /* deprecated */
228 int load_image_targphys(const char *filename, target_phys_addr_t, int max_sz);
229 int load_elf(const char *filename, int64_t address_offset,
230              uint64_t *pentry, uint64_t *lowaddr, uint64_t *highaddr);
231 int load_aout(const char *filename, target_phys_addr_t addr, int max_sz);
232 int load_uimage(const char *filename, target_ulong *ep, target_ulong *loadaddr,
233                 int *is_linux);
234 
235 int fread_targphys(target_phys_addr_t dst_addr, size_t nbytes, FILE *f);
236 int fread_targphys_ok(target_phys_addr_t dst_addr, size_t nbytes, FILE *f);
237 int read_targphys(int fd, target_phys_addr_t dst_addr, size_t nbytes);
238 void pstrcpy_targphys(target_phys_addr_t dest, int buf_size,
239                       const char *source);
240 #endif
241 
242 void do_usb_add(Monitor *mon, const char *devname);
243 void do_usb_del(Monitor *mon, const char *devname);
244 void usb_info(Monitor *mon);
245 
246 int get_param_value(char *buf, int buf_size,
247                     const char *tag, const char *str);
248 int check_params(char *buf, int buf_size,
249                  const char * const *params, const char *str);
250 
251 void register_devices(void);
252 
253 #endif
254