]>
Commit | Line | Data |
---|---|---|
ad96090a BS |
1 | /* |
2 | * QEMU System Emulator | |
3 | * | |
4 | * Copyright (c) 2003-2008 Fabrice Bellard | |
5 | * | |
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
7 | * of this software and associated documentation files (the "Software"), to deal | |
8 | * in the Software without restriction, including without limitation the rights | |
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
10 | * copies of the Software, and to permit persons to whom the Software is | |
11 | * furnished to do so, subject to the following conditions: | |
12 | * | |
13 | * The above copyright notice and this permission notice shall be included in | |
14 | * all copies or substantial portions of the Software. | |
15 | * | |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
22 | * THE SOFTWARE. | |
23 | */ | |
24 | #include <stdint.h> | |
25 | #include <stdarg.h> | |
b2e0a138 | 26 | #include <stdlib.h> |
ad96090a | 27 | #ifndef _WIN32 |
1c47cb16 | 28 | #include <sys/types.h> |
ad96090a BS |
29 | #include <sys/mman.h> |
30 | #endif | |
31 | #include "config.h" | |
32 | #include "monitor.h" | |
33 | #include "sysemu.h" | |
34 | #include "arch_init.h" | |
35 | #include "audio/audio.h" | |
36 | #include "hw/pc.h" | |
37 | #include "hw/pci.h" | |
38 | #include "hw/audiodev.h" | |
39 | #include "kvm.h" | |
40 | #include "migration.h" | |
41 | #include "net.h" | |
42 | #include "gdbstub.h" | |
43 | #include "hw/smbios.h" | |
86e775c6 | 44 | #include "exec-memory.h" |
302fe51b | 45 | #include "hw/pcspk.h" |
17ad9b35 | 46 | #include "qemu/page_cache.h" |
99afc91d | 47 | #include "qmp-commands.h" |
ad96090a | 48 | |
3a697f69 OW |
49 | #ifdef DEBUG_ARCH_INIT |
50 | #define DPRINTF(fmt, ...) \ | |
51 | do { fprintf(stdout, "arch_init: " fmt, ## __VA_ARGS__); } while (0) | |
52 | #else | |
53 | #define DPRINTF(fmt, ...) \ | |
54 | do { } while (0) | |
55 | #endif | |
56 | ||
ad96090a BS |
57 | #ifdef TARGET_SPARC |
58 | int graphic_width = 1024; | |
59 | int graphic_height = 768; | |
60 | int graphic_depth = 8; | |
61 | #else | |
62 | int graphic_width = 800; | |
63 | int graphic_height = 600; | |
64 | int graphic_depth = 15; | |
65 | #endif | |
66 | ||
ad96090a BS |
67 | |
68 | #if defined(TARGET_ALPHA) | |
69 | #define QEMU_ARCH QEMU_ARCH_ALPHA | |
70 | #elif defined(TARGET_ARM) | |
71 | #define QEMU_ARCH QEMU_ARCH_ARM | |
72 | #elif defined(TARGET_CRIS) | |
73 | #define QEMU_ARCH QEMU_ARCH_CRIS | |
74 | #elif defined(TARGET_I386) | |
75 | #define QEMU_ARCH QEMU_ARCH_I386 | |
76 | #elif defined(TARGET_M68K) | |
77 | #define QEMU_ARCH QEMU_ARCH_M68K | |
81ea0e13 MW |
78 | #elif defined(TARGET_LM32) |
79 | #define QEMU_ARCH QEMU_ARCH_LM32 | |
ad96090a BS |
80 | #elif defined(TARGET_MICROBLAZE) |
81 | #define QEMU_ARCH QEMU_ARCH_MICROBLAZE | |
82 | #elif defined(TARGET_MIPS) | |
83 | #define QEMU_ARCH QEMU_ARCH_MIPS | |
e67db06e JL |
84 | #elif defined(TARGET_OPENRISC) |
85 | #define QEMU_ARCH QEMU_ARCH_OPENRISC | |
ad96090a BS |
86 | #elif defined(TARGET_PPC) |
87 | #define QEMU_ARCH QEMU_ARCH_PPC | |
88 | #elif defined(TARGET_S390X) | |
89 | #define QEMU_ARCH QEMU_ARCH_S390X | |
90 | #elif defined(TARGET_SH4) | |
91 | #define QEMU_ARCH QEMU_ARCH_SH4 | |
92 | #elif defined(TARGET_SPARC) | |
93 | #define QEMU_ARCH QEMU_ARCH_SPARC | |
2328826b MF |
94 | #elif defined(TARGET_XTENSA) |
95 | #define QEMU_ARCH QEMU_ARCH_XTENSA | |
4f23a1e6 GX |
96 | #elif defined(TARGET_UNICORE32) |
97 | #define QEMU_ARCH QEMU_ARCH_UNICORE32 | |
ad96090a BS |
98 | #endif |
99 | ||
100 | const uint32_t arch_type = QEMU_ARCH; | |
101 | ||
102 | /***********************************************************/ | |
103 | /* ram save/restore */ | |
104 | ||
d20878d2 YT |
105 | #define RAM_SAVE_FLAG_FULL 0x01 /* Obsolete, not used anymore */ |
106 | #define RAM_SAVE_FLAG_COMPRESS 0x02 | |
107 | #define RAM_SAVE_FLAG_MEM_SIZE 0x04 | |
108 | #define RAM_SAVE_FLAG_PAGE 0x08 | |
109 | #define RAM_SAVE_FLAG_EOS 0x10 | |
110 | #define RAM_SAVE_FLAG_CONTINUE 0x20 | |
17ad9b35 | 111 | #define RAM_SAVE_FLAG_XBZRLE 0x40 |
ad96090a | 112 | |
86003615 PB |
113 | #ifdef __ALTIVEC__ |
114 | #include <altivec.h> | |
115 | #define VECTYPE vector unsigned char | |
116 | #define SPLAT(p) vec_splat(vec_ld(0, p), 0) | |
117 | #define ALL_EQ(v1, v2) vec_all_eq(v1, v2) | |
f283edc4 AF |
118 | /* altivec.h may redefine the bool macro as vector type. |
119 | * Reset it to POSIX semantics. */ | |
120 | #undef bool | |
121 | #define bool _Bool | |
86003615 PB |
122 | #elif defined __SSE2__ |
123 | #include <emmintrin.h> | |
124 | #define VECTYPE __m128i | |
125 | #define SPLAT(p) _mm_set1_epi8(*(p)) | |
126 | #define ALL_EQ(v1, v2) (_mm_movemask_epi8(_mm_cmpeq_epi8(v1, v2)) == 0xFFFF) | |
127 | #else | |
128 | #define VECTYPE unsigned long | |
129 | #define SPLAT(p) (*(p) * (~0UL / 255)) | |
130 | #define ALL_EQ(v1, v2) ((v1) == (v2)) | |
131 | #endif | |
132 | ||
b5a8fe5e | 133 | |
756557de EH |
134 | static struct defconfig_file { |
135 | const char *filename; | |
f29a5614 EH |
136 | /* Indicates it is an user config file (disabled by -no-user-config) */ |
137 | bool userconfig; | |
756557de | 138 | } default_config_files[] = { |
f29a5614 EH |
139 | { CONFIG_QEMU_CONFDIR "/qemu.conf", true }, |
140 | { CONFIG_QEMU_CONFDIR "/target-" TARGET_ARCH ".conf", true }, | |
756557de EH |
141 | { NULL }, /* end of list */ |
142 | }; | |
143 | ||
144 | ||
f29a5614 | 145 | int qemu_read_default_config_files(bool userconfig) |
b5a8fe5e EH |
146 | { |
147 | int ret; | |
756557de | 148 | struct defconfig_file *f; |
b5a8fe5e | 149 | |
756557de | 150 | for (f = default_config_files; f->filename; f++) { |
f29a5614 EH |
151 | if (!userconfig && f->userconfig) { |
152 | continue; | |
153 | } | |
756557de EH |
154 | ret = qemu_read_config_file(f->filename); |
155 | if (ret < 0 && ret != -ENOENT) { | |
156 | return ret; | |
157 | } | |
b5a8fe5e | 158 | } |
756557de | 159 | |
b5a8fe5e EH |
160 | return 0; |
161 | } | |
162 | ||
86003615 | 163 | static int is_dup_page(uint8_t *page) |
ad96090a | 164 | { |
86003615 PB |
165 | VECTYPE *p = (VECTYPE *)page; |
166 | VECTYPE val = SPLAT(page); | |
ad96090a BS |
167 | int i; |
168 | ||
86003615 PB |
169 | for (i = 0; i < TARGET_PAGE_SIZE / sizeof(VECTYPE); i++) { |
170 | if (!ALL_EQ(val, p[i])) { | |
ad96090a BS |
171 | return 0; |
172 | } | |
173 | } | |
174 | ||
175 | return 1; | |
176 | } | |
177 | ||
17ad9b35 OW |
178 | /* struct contains XBZRLE cache and a static page |
179 | used by the compression */ | |
180 | static struct { | |
181 | /* buffer used for XBZRLE encoding */ | |
182 | uint8_t *encoded_buf; | |
183 | /* buffer for storing page content */ | |
184 | uint8_t *current_buf; | |
185 | /* buffer used for XBZRLE decoding */ | |
186 | uint8_t *decoded_buf; | |
187 | /* Cache for XBZRLE */ | |
188 | PageCache *cache; | |
189 | } XBZRLE = { | |
190 | .encoded_buf = NULL, | |
191 | .current_buf = NULL, | |
192 | .decoded_buf = NULL, | |
193 | .cache = NULL, | |
194 | }; | |
195 | ||
9e1ba4cc OW |
196 | |
197 | int64_t xbzrle_cache_resize(int64_t new_size) | |
198 | { | |
199 | if (XBZRLE.cache != NULL) { | |
200 | return cache_resize(XBZRLE.cache, new_size / TARGET_PAGE_SIZE) * | |
201 | TARGET_PAGE_SIZE; | |
202 | } | |
203 | return pow2floor(new_size); | |
204 | } | |
205 | ||
004d4c10 OW |
206 | /* accounting for migration statistics */ |
207 | typedef struct AccountingInfo { | |
208 | uint64_t dup_pages; | |
209 | uint64_t norm_pages; | |
210 | uint64_t iterations; | |
f36d55af OW |
211 | uint64_t xbzrle_bytes; |
212 | uint64_t xbzrle_pages; | |
213 | uint64_t xbzrle_cache_miss; | |
214 | uint64_t xbzrle_overflows; | |
004d4c10 OW |
215 | } AccountingInfo; |
216 | ||
217 | static AccountingInfo acct_info; | |
218 | ||
219 | static void acct_clear(void) | |
220 | { | |
221 | memset(&acct_info, 0, sizeof(acct_info)); | |
222 | } | |
223 | ||
224 | uint64_t dup_mig_bytes_transferred(void) | |
225 | { | |
226 | return acct_info.dup_pages * TARGET_PAGE_SIZE; | |
227 | } | |
228 | ||
229 | uint64_t dup_mig_pages_transferred(void) | |
230 | { | |
231 | return acct_info.dup_pages; | |
232 | } | |
233 | ||
234 | uint64_t norm_mig_bytes_transferred(void) | |
235 | { | |
236 | return acct_info.norm_pages * TARGET_PAGE_SIZE; | |
237 | } | |
238 | ||
239 | uint64_t norm_mig_pages_transferred(void) | |
240 | { | |
241 | return acct_info.norm_pages; | |
242 | } | |
243 | ||
f36d55af OW |
244 | uint64_t xbzrle_mig_bytes_transferred(void) |
245 | { | |
246 | return acct_info.xbzrle_bytes; | |
247 | } | |
248 | ||
249 | uint64_t xbzrle_mig_pages_transferred(void) | |
250 | { | |
251 | return acct_info.xbzrle_pages; | |
252 | } | |
253 | ||
254 | uint64_t xbzrle_mig_pages_cache_miss(void) | |
255 | { | |
256 | return acct_info.xbzrle_cache_miss; | |
257 | } | |
258 | ||
259 | uint64_t xbzrle_mig_pages_overflow(void) | |
260 | { | |
261 | return acct_info.xbzrle_overflows; | |
262 | } | |
263 | ||
0c51f43d OW |
264 | static void save_block_hdr(QEMUFile *f, RAMBlock *block, ram_addr_t offset, |
265 | int cont, int flag) | |
266 | { | |
267 | qemu_put_be64(f, offset | cont | flag); | |
268 | if (!cont) { | |
269 | qemu_put_byte(f, strlen(block->idstr)); | |
270 | qemu_put_buffer(f, (uint8_t *)block->idstr, | |
271 | strlen(block->idstr)); | |
272 | } | |
273 | ||
274 | } | |
275 | ||
17ad9b35 OW |
276 | #define ENCODING_FLAG_XBZRLE 0x1 |
277 | ||
278 | static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data, | |
279 | ram_addr_t current_addr, RAMBlock *block, | |
dd051c72 | 280 | ram_addr_t offset, int cont, bool last_stage) |
17ad9b35 OW |
281 | { |
282 | int encoded_len = 0, bytes_sent = -1; | |
283 | uint8_t *prev_cached_page; | |
284 | ||
285 | if (!cache_is_cached(XBZRLE.cache, current_addr)) { | |
dd051c72 JQ |
286 | if (!last_stage) { |
287 | cache_insert(XBZRLE.cache, current_addr, | |
288 | g_memdup(current_data, TARGET_PAGE_SIZE)); | |
289 | } | |
f36d55af | 290 | acct_info.xbzrle_cache_miss++; |
17ad9b35 OW |
291 | return -1; |
292 | } | |
293 | ||
294 | prev_cached_page = get_cached_data(XBZRLE.cache, current_addr); | |
295 | ||
296 | /* save current buffer into memory */ | |
297 | memcpy(XBZRLE.current_buf, current_data, TARGET_PAGE_SIZE); | |
298 | ||
299 | /* XBZRLE encoding (if there is no overflow) */ | |
300 | encoded_len = xbzrle_encode_buffer(prev_cached_page, XBZRLE.current_buf, | |
301 | TARGET_PAGE_SIZE, XBZRLE.encoded_buf, | |
302 | TARGET_PAGE_SIZE); | |
303 | if (encoded_len == 0) { | |
304 | DPRINTF("Skipping unmodified page\n"); | |
305 | return 0; | |
306 | } else if (encoded_len == -1) { | |
307 | DPRINTF("Overflow\n"); | |
f36d55af | 308 | acct_info.xbzrle_overflows++; |
17ad9b35 OW |
309 | /* update data in the cache */ |
310 | memcpy(prev_cached_page, current_data, TARGET_PAGE_SIZE); | |
311 | return -1; | |
312 | } | |
313 | ||
314 | /* we need to update the data in the cache, in order to get the same data */ | |
dd051c72 JQ |
315 | if (!last_stage) { |
316 | memcpy(prev_cached_page, XBZRLE.current_buf, TARGET_PAGE_SIZE); | |
317 | } | |
17ad9b35 OW |
318 | |
319 | /* Send XBZRLE based compressed page */ | |
320 | save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_XBZRLE); | |
321 | qemu_put_byte(f, ENCODING_FLAG_XBZRLE); | |
322 | qemu_put_be16(f, encoded_len); | |
323 | qemu_put_buffer(f, XBZRLE.encoded_buf, encoded_len); | |
324 | bytes_sent = encoded_len + 1 + 2; | |
f36d55af OW |
325 | acct_info.xbzrle_pages++; |
326 | acct_info.xbzrle_bytes += bytes_sent; | |
17ad9b35 OW |
327 | |
328 | return bytes_sent; | |
329 | } | |
330 | ||
760e77ea AW |
331 | static RAMBlock *last_block; |
332 | static ram_addr_t last_offset; | |
333 | ||
69268cde JQ |
334 | static inline bool migration_bitmap_test_and_reset_dirty(MemoryRegion *mr, |
335 | ram_addr_t offset) | |
336 | { | |
337 | bool ret = memory_region_get_dirty(mr, offset, TARGET_PAGE_SIZE, | |
338 | DIRTY_MEMORY_MIGRATION); | |
339 | ||
340 | if (ret) { | |
341 | memory_region_reset_dirty(mr, offset, TARGET_PAGE_SIZE, | |
342 | DIRTY_MEMORY_MIGRATION); | |
343 | } | |
344 | return ret; | |
345 | } | |
346 | ||
e44d26c8 JQ |
347 | static inline void migration_bitmap_set_dirty(MemoryRegion *mr, int length) |
348 | { | |
349 | ram_addr_t addr; | |
350 | ||
351 | for (addr = 0; addr < length; addr += TARGET_PAGE_SIZE) { | |
352 | if (!memory_region_get_dirty(mr, addr, TARGET_PAGE_SIZE, | |
353 | DIRTY_MEMORY_MIGRATION)) { | |
354 | memory_region_set_dirty(mr, addr, TARGET_PAGE_SIZE); | |
355 | } | |
356 | } | |
357 | } | |
358 | ||
dd2df737 JQ |
359 | static void migration_bitmap_sync(void) |
360 | { | |
361 | memory_global_sync_dirty_bitmap(get_system_memory()); | |
362 | } | |
363 | ||
364 | ||
6c779f22 OW |
365 | /* |
366 | * ram_save_block: Writes a page of memory to the stream f | |
367 | * | |
368 | * Returns: 0: if the page hasn't changed | |
369 | * -1: if there are no more dirty pages | |
370 | * n: the amount of bytes written in other case | |
371 | */ | |
372 | ||
dd051c72 | 373 | static int ram_save_block(QEMUFile *f, bool last_stage) |
ad96090a | 374 | { |
e44359c3 AW |
375 | RAMBlock *block = last_block; |
376 | ram_addr_t offset = last_offset; | |
6c779f22 | 377 | int bytes_sent = -1; |
71c510e2 | 378 | MemoryRegion *mr; |
17ad9b35 | 379 | ram_addr_t current_addr; |
ad96090a | 380 | |
e44359c3 AW |
381 | if (!block) |
382 | block = QLIST_FIRST(&ram_list.blocks); | |
383 | ||
e44359c3 | 384 | do { |
71c510e2 | 385 | mr = block->mr; |
69268cde | 386 | if (migration_bitmap_test_and_reset_dirty(mr, offset)) { |
ad96090a | 387 | uint8_t *p; |
a55bbe31 | 388 | int cont = (block == last_block) ? RAM_SAVE_FLAG_CONTINUE : 0; |
ad96090a | 389 | |
71c510e2 | 390 | p = memory_region_get_ram_ptr(mr) + offset; |
ad96090a | 391 | |
86003615 | 392 | if (is_dup_page(p)) { |
004d4c10 | 393 | acct_info.dup_pages++; |
0c51f43d | 394 | save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_COMPRESS); |
ad96090a | 395 | qemu_put_byte(f, *p); |
3fc250b4 | 396 | bytes_sent = 1; |
17ad9b35 OW |
397 | } else if (migrate_use_xbzrle()) { |
398 | current_addr = block->offset + offset; | |
399 | bytes_sent = save_xbzrle_page(f, p, current_addr, block, | |
dd051c72 JQ |
400 | offset, cont, last_stage); |
401 | if (!last_stage) { | |
402 | p = get_cached_data(XBZRLE.cache, current_addr); | |
403 | } | |
17ad9b35 OW |
404 | } |
405 | ||
406 | /* either we didn't send yet (we may have had XBZRLE overflow) */ | |
407 | if (bytes_sent == -1) { | |
0c51f43d | 408 | save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_PAGE); |
ad96090a | 409 | qemu_put_buffer(f, p, TARGET_PAGE_SIZE); |
3fc250b4 | 410 | bytes_sent = TARGET_PAGE_SIZE; |
004d4c10 | 411 | acct_info.norm_pages++; |
ad96090a BS |
412 | } |
413 | ||
17ad9b35 OW |
414 | /* if page is unmodified, continue to the next */ |
415 | if (bytes_sent != 0) { | |
416 | break; | |
417 | } | |
ad96090a | 418 | } |
e44359c3 AW |
419 | |
420 | offset += TARGET_PAGE_SIZE; | |
421 | if (offset >= block->length) { | |
422 | offset = 0; | |
423 | block = QLIST_NEXT(block, next); | |
424 | if (!block) | |
425 | block = QLIST_FIRST(&ram_list.blocks); | |
426 | } | |
71c510e2 | 427 | } while (block != last_block || offset != last_offset); |
e44359c3 AW |
428 | |
429 | last_block = block; | |
430 | last_offset = offset; | |
ad96090a | 431 | |
3fc250b4 | 432 | return bytes_sent; |
ad96090a BS |
433 | } |
434 | ||
435 | static uint64_t bytes_transferred; | |
436 | ||
437 | static ram_addr_t ram_save_remaining(void) | |
438 | { | |
45f33f01 | 439 | return ram_list.dirty_pages; |
ad96090a BS |
440 | } |
441 | ||
442 | uint64_t ram_bytes_remaining(void) | |
443 | { | |
444 | return ram_save_remaining() * TARGET_PAGE_SIZE; | |
445 | } | |
446 | ||
447 | uint64_t ram_bytes_transferred(void) | |
448 | { | |
449 | return bytes_transferred; | |
450 | } | |
451 | ||
452 | uint64_t ram_bytes_total(void) | |
453 | { | |
d17b5288 AW |
454 | RAMBlock *block; |
455 | uint64_t total = 0; | |
456 | ||
457 | QLIST_FOREACH(block, &ram_list.blocks, next) | |
458 | total += block->length; | |
459 | ||
460 | return total; | |
ad96090a BS |
461 | } |
462 | ||
b2e0a138 MT |
463 | static int block_compar(const void *a, const void *b) |
464 | { | |
465 | RAMBlock * const *ablock = a; | |
466 | RAMBlock * const *bblock = b; | |
8fec98b4 AK |
467 | |
468 | return strcmp((*ablock)->idstr, (*bblock)->idstr); | |
b2e0a138 MT |
469 | } |
470 | ||
471 | static void sort_ram_list(void) | |
472 | { | |
473 | RAMBlock *block, *nblock, **blocks; | |
474 | int n; | |
475 | n = 0; | |
476 | QLIST_FOREACH(block, &ram_list.blocks, next) { | |
477 | ++n; | |
478 | } | |
7267c094 | 479 | blocks = g_malloc(n * sizeof *blocks); |
b2e0a138 MT |
480 | n = 0; |
481 | QLIST_FOREACH_SAFE(block, &ram_list.blocks, next, nblock) { | |
482 | blocks[n++] = block; | |
483 | QLIST_REMOVE(block, next); | |
484 | } | |
485 | qsort(blocks, n, sizeof *blocks, block_compar); | |
486 | while (--n >= 0) { | |
487 | QLIST_INSERT_HEAD(&ram_list.blocks, blocks[n], next); | |
488 | } | |
7267c094 | 489 | g_free(blocks); |
b2e0a138 MT |
490 | } |
491 | ||
8e21cd32 OW |
492 | static void migration_end(void) |
493 | { | |
494 | memory_global_dirty_log_stop(); | |
17ad9b35 OW |
495 | |
496 | if (migrate_use_xbzrle()) { | |
497 | cache_fini(XBZRLE.cache); | |
498 | g_free(XBZRLE.cache); | |
499 | g_free(XBZRLE.encoded_buf); | |
500 | g_free(XBZRLE.current_buf); | |
501 | g_free(XBZRLE.decoded_buf); | |
502 | XBZRLE.cache = NULL; | |
503 | } | |
8e21cd32 OW |
504 | } |
505 | ||
9b5bfab0 JQ |
506 | static void ram_migration_cancel(void *opaque) |
507 | { | |
508 | migration_end(); | |
509 | } | |
510 | ||
5a170775 JQ |
511 | |
512 | static void reset_ram_globals(void) | |
513 | { | |
514 | last_block = NULL; | |
515 | last_offset = 0; | |
516 | sort_ram_list(); | |
517 | } | |
518 | ||
4508bd9e JQ |
519 | #define MAX_WAIT 50 /* ms, half buffered_file limit */ |
520 | ||
d1315aac | 521 | static int ram_save_setup(QEMUFile *f, void *opaque) |
ad96090a | 522 | { |
d1315aac | 523 | RAMBlock *block; |
ad96090a | 524 | |
d1315aac | 525 | bytes_transferred = 0; |
5a170775 | 526 | reset_ram_globals(); |
ad96090a | 527 | |
17ad9b35 OW |
528 | if (migrate_use_xbzrle()) { |
529 | XBZRLE.cache = cache_init(migrate_xbzrle_cache_size() / | |
530 | TARGET_PAGE_SIZE, | |
531 | TARGET_PAGE_SIZE); | |
532 | if (!XBZRLE.cache) { | |
533 | DPRINTF("Error creating cache\n"); | |
534 | return -1; | |
535 | } | |
536 | XBZRLE.encoded_buf = g_malloc0(TARGET_PAGE_SIZE); | |
537 | XBZRLE.current_buf = g_malloc(TARGET_PAGE_SIZE); | |
004d4c10 | 538 | acct_clear(); |
17ad9b35 OW |
539 | } |
540 | ||
d1315aac JQ |
541 | /* Make sure all dirty bits are set */ |
542 | QLIST_FOREACH(block, &ram_list.blocks, next) { | |
e44d26c8 | 543 | migration_bitmap_set_dirty(block->mr, block->length); |
d1315aac | 544 | } |
ad96090a | 545 | |
d1315aac | 546 | memory_global_dirty_log_start(); |
79536f4f | 547 | memory_global_sync_dirty_bitmap(get_system_memory()); |
ad96090a | 548 | |
d1315aac | 549 | qemu_put_be64(f, ram_bytes_total() | RAM_SAVE_FLAG_MEM_SIZE); |
97ab12d4 | 550 | |
d1315aac JQ |
551 | QLIST_FOREACH(block, &ram_list.blocks, next) { |
552 | qemu_put_byte(f, strlen(block->idstr)); | |
553 | qemu_put_buffer(f, (uint8_t *)block->idstr, strlen(block->idstr)); | |
554 | qemu_put_be64(f, block->length); | |
ad96090a BS |
555 | } |
556 | ||
d1315aac JQ |
557 | qemu_put_be64(f, RAM_SAVE_FLAG_EOS); |
558 | ||
559 | return 0; | |
560 | } | |
561 | ||
16310a3c | 562 | static int ram_save_iterate(QEMUFile *f, void *opaque) |
d1315aac JQ |
563 | { |
564 | uint64_t bytes_transferred_last; | |
565 | double bwidth = 0; | |
566 | int ret; | |
567 | int i; | |
c00012f6 | 568 | uint64_t expected_downtime; |
2c52ddf1 | 569 | MigrationState *s = migrate_get_current(); |
d1315aac | 570 | |
ad96090a BS |
571 | bytes_transferred_last = bytes_transferred; |
572 | bwidth = qemu_get_clock_ns(rt_clock); | |
573 | ||
4508bd9e | 574 | i = 0; |
2975725f | 575 | while ((ret = qemu_file_rate_limit(f)) == 0) { |
3fc250b4 | 576 | int bytes_sent; |
ad96090a | 577 | |
dd051c72 | 578 | bytes_sent = ram_save_block(f, false); |
6c779f22 OW |
579 | /* no more blocks to sent */ |
580 | if (bytes_sent < 0) { | |
ad96090a BS |
581 | break; |
582 | } | |
6c779f22 | 583 | bytes_transferred += bytes_sent; |
004d4c10 | 584 | acct_info.iterations++; |
4508bd9e JQ |
585 | /* we want to check in the 1st loop, just in case it was the 1st time |
586 | and we had to sync the dirty bitmap. | |
587 | qemu_get_clock_ns() is a bit expensive, so we only check each some | |
588 | iterations | |
589 | */ | |
590 | if ((i & 63) == 0) { | |
591 | uint64_t t1 = (qemu_get_clock_ns(rt_clock) - bwidth) / 1000000; | |
592 | if (t1 > MAX_WAIT) { | |
ef37a699 | 593 | DPRINTF("big wait: %" PRIu64 " milliseconds, %d iterations\n", |
4508bd9e JQ |
594 | t1, i); |
595 | break; | |
596 | } | |
597 | } | |
598 | i++; | |
ad96090a BS |
599 | } |
600 | ||
2975725f JQ |
601 | if (ret < 0) { |
602 | return ret; | |
603 | } | |
604 | ||
ad96090a BS |
605 | bwidth = qemu_get_clock_ns(rt_clock) - bwidth; |
606 | bwidth = (bytes_transferred - bytes_transferred_last) / bwidth; | |
607 | ||
c00012f6 JQ |
608 | /* if we haven't transferred anything this round, force |
609 | * expected_downtime to a very high value, but without | |
610 | * crashing */ | |
ad96090a BS |
611 | if (bwidth == 0) { |
612 | bwidth = 0.000001; | |
613 | } | |
614 | ||
16310a3c JQ |
615 | qemu_put_be64(f, RAM_SAVE_FLAG_EOS); |
616 | ||
c00012f6 JQ |
617 | expected_downtime = ram_save_remaining() * TARGET_PAGE_SIZE / bwidth; |
618 | DPRINTF("ram_save_live: expected(%" PRIu64 ") <= max(" PRIu64 ")?\n", | |
619 | expected_downtime, migrate_max_downtime()); | |
16310a3c | 620 | |
c00012f6 | 621 | if (expected_downtime <= migrate_max_downtime()) { |
dd2df737 | 622 | migration_bitmap_sync(); |
c00012f6 | 623 | expected_downtime = ram_save_remaining() * TARGET_PAGE_SIZE / bwidth; |
2c52ddf1 | 624 | s->expected_downtime = expected_downtime / 1000000; /* ns -> ms */ |
00d94f3f | 625 | |
c00012f6 | 626 | return expected_downtime <= migrate_max_downtime(); |
00d94f3f JQ |
627 | } |
628 | return 0; | |
16310a3c JQ |
629 | } |
630 | ||
631 | static int ram_save_complete(QEMUFile *f, void *opaque) | |
632 | { | |
dd2df737 | 633 | migration_bitmap_sync(); |
16310a3c | 634 | |
ad96090a | 635 | /* try transferring iterative blocks of memory */ |
3a697f69 | 636 | |
16310a3c | 637 | /* flush all remaining blocks regardless of rate limiting */ |
6c779f22 | 638 | while (true) { |
3fc250b4 PR |
639 | int bytes_sent; |
640 | ||
dd051c72 | 641 | bytes_sent = ram_save_block(f, true); |
6c779f22 OW |
642 | /* no more blocks to sent */ |
643 | if (bytes_sent < 0) { | |
644 | break; | |
ad96090a | 645 | } |
16310a3c | 646 | bytes_transferred += bytes_sent; |
ad96090a | 647 | } |
16310a3c | 648 | memory_global_dirty_log_stop(); |
ad96090a BS |
649 | |
650 | qemu_put_be64(f, RAM_SAVE_FLAG_EOS); | |
651 | ||
5b3c9638 | 652 | return 0; |
ad96090a BS |
653 | } |
654 | ||
17ad9b35 OW |
655 | static int load_xbzrle(QEMUFile *f, ram_addr_t addr, void *host) |
656 | { | |
657 | int ret, rc = 0; | |
658 | unsigned int xh_len; | |
659 | int xh_flags; | |
660 | ||
661 | if (!XBZRLE.decoded_buf) { | |
662 | XBZRLE.decoded_buf = g_malloc(TARGET_PAGE_SIZE); | |
663 | } | |
664 | ||
665 | /* extract RLE header */ | |
666 | xh_flags = qemu_get_byte(f); | |
667 | xh_len = qemu_get_be16(f); | |
668 | ||
669 | if (xh_flags != ENCODING_FLAG_XBZRLE) { | |
670 | fprintf(stderr, "Failed to load XBZRLE page - wrong compression!\n"); | |
671 | return -1; | |
672 | } | |
673 | ||
674 | if (xh_len > TARGET_PAGE_SIZE) { | |
675 | fprintf(stderr, "Failed to load XBZRLE page - len overflow!\n"); | |
676 | return -1; | |
677 | } | |
678 | /* load data and decode */ | |
679 | qemu_get_buffer(f, XBZRLE.decoded_buf, xh_len); | |
680 | ||
681 | /* decode RLE */ | |
682 | ret = xbzrle_decode_buffer(XBZRLE.decoded_buf, xh_len, host, | |
683 | TARGET_PAGE_SIZE); | |
684 | if (ret == -1) { | |
685 | fprintf(stderr, "Failed to load XBZRLE page - decode error!\n"); | |
686 | rc = -1; | |
687 | } else if (ret > TARGET_PAGE_SIZE) { | |
688 | fprintf(stderr, "Failed to load XBZRLE page - size %d exceeds %d!\n", | |
689 | ret, TARGET_PAGE_SIZE); | |
690 | abort(); | |
691 | } | |
692 | ||
693 | return rc; | |
694 | } | |
695 | ||
a55bbe31 AW |
696 | static inline void *host_from_stream_offset(QEMUFile *f, |
697 | ram_addr_t offset, | |
698 | int flags) | |
699 | { | |
700 | static RAMBlock *block = NULL; | |
701 | char id[256]; | |
702 | uint8_t len; | |
703 | ||
704 | if (flags & RAM_SAVE_FLAG_CONTINUE) { | |
705 | if (!block) { | |
706 | fprintf(stderr, "Ack, bad migration stream!\n"); | |
707 | return NULL; | |
708 | } | |
709 | ||
dc94a7ed | 710 | return memory_region_get_ram_ptr(block->mr) + offset; |
a55bbe31 AW |
711 | } |
712 | ||
713 | len = qemu_get_byte(f); | |
714 | qemu_get_buffer(f, (uint8_t *)id, len); | |
715 | id[len] = 0; | |
716 | ||
717 | QLIST_FOREACH(block, &ram_list.blocks, next) { | |
718 | if (!strncmp(id, block->idstr, sizeof(id))) | |
dc94a7ed | 719 | return memory_region_get_ram_ptr(block->mr) + offset; |
a55bbe31 AW |
720 | } |
721 | ||
722 | fprintf(stderr, "Can't find block %s!\n", id); | |
723 | return NULL; | |
724 | } | |
725 | ||
7908c78d | 726 | static int ram_load(QEMUFile *f, void *opaque, int version_id) |
ad96090a BS |
727 | { |
728 | ram_addr_t addr; | |
3a697f69 | 729 | int flags, ret = 0; |
42802d47 | 730 | int error; |
3a697f69 OW |
731 | static uint64_t seq_iter; |
732 | ||
733 | seq_iter++; | |
ad96090a | 734 | |
f09f2189 | 735 | if (version_id < 4 || version_id > 4) { |
ad96090a BS |
736 | return -EINVAL; |
737 | } | |
738 | ||
739 | do { | |
740 | addr = qemu_get_be64(f); | |
741 | ||
742 | flags = addr & ~TARGET_PAGE_MASK; | |
743 | addr &= TARGET_PAGE_MASK; | |
744 | ||
745 | if (flags & RAM_SAVE_FLAG_MEM_SIZE) { | |
f09f2189 | 746 | if (version_id == 4) { |
97ab12d4 AW |
747 | /* Synchronize RAM block list */ |
748 | char id[256]; | |
749 | ram_addr_t length; | |
750 | ram_addr_t total_ram_bytes = addr; | |
751 | ||
752 | while (total_ram_bytes) { | |
753 | RAMBlock *block; | |
754 | uint8_t len; | |
755 | ||
756 | len = qemu_get_byte(f); | |
757 | qemu_get_buffer(f, (uint8_t *)id, len); | |
758 | id[len] = 0; | |
759 | length = qemu_get_be64(f); | |
760 | ||
761 | QLIST_FOREACH(block, &ram_list.blocks, next) { | |
762 | if (!strncmp(id, block->idstr, sizeof(id))) { | |
3a697f69 OW |
763 | if (block->length != length) { |
764 | ret = -EINVAL; | |
765 | goto done; | |
766 | } | |
97ab12d4 AW |
767 | break; |
768 | } | |
769 | } | |
770 | ||
771 | if (!block) { | |
fb787f81 AW |
772 | fprintf(stderr, "Unknown ramblock \"%s\", cannot " |
773 | "accept migration\n", id); | |
3a697f69 OW |
774 | ret = -EINVAL; |
775 | goto done; | |
97ab12d4 AW |
776 | } |
777 | ||
778 | total_ram_bytes -= length; | |
779 | } | |
ad96090a BS |
780 | } |
781 | } | |
782 | ||
783 | if (flags & RAM_SAVE_FLAG_COMPRESS) { | |
97ab12d4 AW |
784 | void *host; |
785 | uint8_t ch; | |
786 | ||
f09f2189 | 787 | host = host_from_stream_offset(f, addr, flags); |
492fb99c MT |
788 | if (!host) { |
789 | return -EINVAL; | |
790 | } | |
97ab12d4 | 791 | |
97ab12d4 AW |
792 | ch = qemu_get_byte(f); |
793 | memset(host, ch, TARGET_PAGE_SIZE); | |
ad96090a BS |
794 | #ifndef _WIN32 |
795 | if (ch == 0 && | |
796 | (!kvm_enabled() || kvm_has_sync_mmu())) { | |
e78815a5 | 797 | qemu_madvise(host, TARGET_PAGE_SIZE, QEMU_MADV_DONTNEED); |
ad96090a BS |
798 | } |
799 | #endif | |
800 | } else if (flags & RAM_SAVE_FLAG_PAGE) { | |
97ab12d4 AW |
801 | void *host; |
802 | ||
f09f2189 | 803 | host = host_from_stream_offset(f, addr, flags); |
0ff1f9f5 OW |
804 | if (!host) { |
805 | return -EINVAL; | |
806 | } | |
97ab12d4 | 807 | |
97ab12d4 | 808 | qemu_get_buffer(f, host, TARGET_PAGE_SIZE); |
17ad9b35 OW |
809 | } else if (flags & RAM_SAVE_FLAG_XBZRLE) { |
810 | if (!migrate_use_xbzrle()) { | |
811 | return -EINVAL; | |
812 | } | |
813 | void *host = host_from_stream_offset(f, addr, flags); | |
814 | if (!host) { | |
815 | return -EINVAL; | |
816 | } | |
817 | ||
818 | if (load_xbzrle(f, addr, host) < 0) { | |
819 | ret = -EINVAL; | |
820 | goto done; | |
821 | } | |
ad96090a | 822 | } |
42802d47 JQ |
823 | error = qemu_file_get_error(f); |
824 | if (error) { | |
3a697f69 OW |
825 | ret = error; |
826 | goto done; | |
ad96090a BS |
827 | } |
828 | } while (!(flags & RAM_SAVE_FLAG_EOS)); | |
829 | ||
3a697f69 | 830 | done: |
ef37a699 IM |
831 | DPRINTF("Completed load of VM with exit code %d seq iteration " |
832 | "%" PRIu64 "\n", ret, seq_iter); | |
3a697f69 | 833 | return ret; |
ad96090a BS |
834 | } |
835 | ||
7908c78d | 836 | SaveVMHandlers savevm_ram_handlers = { |
d1315aac | 837 | .save_live_setup = ram_save_setup, |
16310a3c JQ |
838 | .save_live_iterate = ram_save_iterate, |
839 | .save_live_complete = ram_save_complete, | |
7908c78d | 840 | .load_state = ram_load, |
9b5bfab0 | 841 | .cancel = ram_migration_cancel, |
7908c78d JQ |
842 | }; |
843 | ||
ad96090a | 844 | #ifdef HAS_AUDIO |
0dfa5ef9 IY |
845 | struct soundhw { |
846 | const char *name; | |
847 | const char *descr; | |
848 | int enabled; | |
849 | int isa; | |
850 | union { | |
4a0f031d | 851 | int (*init_isa) (ISABus *bus); |
0dfa5ef9 IY |
852 | int (*init_pci) (PCIBus *bus); |
853 | } init; | |
854 | }; | |
855 | ||
856 | static struct soundhw soundhw[] = { | |
ad96090a | 857 | #ifdef HAS_AUDIO_CHOICE |
da12872a | 858 | #ifdef CONFIG_PCSPK |
ad96090a BS |
859 | { |
860 | "pcspk", | |
861 | "PC speaker", | |
862 | 0, | |
863 | 1, | |
864 | { .init_isa = pcspk_audio_init } | |
865 | }, | |
866 | #endif | |
867 | ||
868 | #ifdef CONFIG_SB16 | |
869 | { | |
870 | "sb16", | |
871 | "Creative Sound Blaster 16", | |
872 | 0, | |
873 | 1, | |
874 | { .init_isa = SB16_init } | |
875 | }, | |
876 | #endif | |
877 | ||
878 | #ifdef CONFIG_CS4231A | |
879 | { | |
880 | "cs4231a", | |
881 | "CS4231A", | |
882 | 0, | |
883 | 1, | |
884 | { .init_isa = cs4231a_init } | |
885 | }, | |
886 | #endif | |
887 | ||
888 | #ifdef CONFIG_ADLIB | |
889 | { | |
890 | "adlib", | |
891 | #ifdef HAS_YMF262 | |
892 | "Yamaha YMF262 (OPL3)", | |
893 | #else | |
894 | "Yamaha YM3812 (OPL2)", | |
895 | #endif | |
896 | 0, | |
897 | 1, | |
898 | { .init_isa = Adlib_init } | |
899 | }, | |
900 | #endif | |
901 | ||
902 | #ifdef CONFIG_GUS | |
903 | { | |
904 | "gus", | |
905 | "Gravis Ultrasound GF1", | |
906 | 0, | |
907 | 1, | |
908 | { .init_isa = GUS_init } | |
909 | }, | |
910 | #endif | |
911 | ||
912 | #ifdef CONFIG_AC97 | |
913 | { | |
914 | "ac97", | |
915 | "Intel 82801AA AC97 Audio", | |
916 | 0, | |
917 | 0, | |
918 | { .init_pci = ac97_init } | |
919 | }, | |
920 | #endif | |
921 | ||
922 | #ifdef CONFIG_ES1370 | |
923 | { | |
924 | "es1370", | |
925 | "ENSONIQ AudioPCI ES1370", | |
926 | 0, | |
927 | 0, | |
928 | { .init_pci = es1370_init } | |
929 | }, | |
930 | #endif | |
931 | ||
d61a4ce8 GH |
932 | #ifdef CONFIG_HDA |
933 | { | |
934 | "hda", | |
935 | "Intel HD Audio", | |
936 | 0, | |
937 | 0, | |
938 | { .init_pci = intel_hda_and_codec_init } | |
939 | }, | |
940 | #endif | |
941 | ||
ad96090a BS |
942 | #endif /* HAS_AUDIO_CHOICE */ |
943 | ||
944 | { NULL, NULL, 0, 0, { NULL } } | |
945 | }; | |
946 | ||
947 | void select_soundhw(const char *optarg) | |
948 | { | |
949 | struct soundhw *c; | |
950 | ||
c8057f95 | 951 | if (is_help_option(optarg)) { |
ad96090a BS |
952 | show_valid_cards: |
953 | ||
55d4fd3c | 954 | #ifdef HAS_AUDIO_CHOICE |
ad96090a BS |
955 | printf("Valid sound card names (comma separated):\n"); |
956 | for (c = soundhw; c->name; ++c) { | |
957 | printf ("%-11s %s\n", c->name, c->descr); | |
958 | } | |
959 | printf("\n-soundhw all will enable all of the above\n"); | |
55d4fd3c PM |
960 | #else |
961 | printf("Machine has no user-selectable audio hardware " | |
962 | "(it may or may not have always-present audio hardware).\n"); | |
963 | #endif | |
c8057f95 | 964 | exit(!is_help_option(optarg)); |
ad96090a BS |
965 | } |
966 | else { | |
967 | size_t l; | |
968 | const char *p; | |
969 | char *e; | |
970 | int bad_card = 0; | |
971 | ||
972 | if (!strcmp(optarg, "all")) { | |
973 | for (c = soundhw; c->name; ++c) { | |
974 | c->enabled = 1; | |
975 | } | |
976 | return; | |
977 | } | |
978 | ||
979 | p = optarg; | |
980 | while (*p) { | |
981 | e = strchr(p, ','); | |
982 | l = !e ? strlen(p) : (size_t) (e - p); | |
983 | ||
984 | for (c = soundhw; c->name; ++c) { | |
985 | if (!strncmp(c->name, p, l) && !c->name[l]) { | |
986 | c->enabled = 1; | |
987 | break; | |
988 | } | |
989 | } | |
990 | ||
991 | if (!c->name) { | |
992 | if (l > 80) { | |
993 | fprintf(stderr, | |
994 | "Unknown sound card name (too big to show)\n"); | |
995 | } | |
996 | else { | |
997 | fprintf(stderr, "Unknown sound card name `%.*s'\n", | |
998 | (int) l, p); | |
999 | } | |
1000 | bad_card = 1; | |
1001 | } | |
1002 | p += l + (e != NULL); | |
1003 | } | |
1004 | ||
1005 | if (bad_card) { | |
1006 | goto show_valid_cards; | |
1007 | } | |
1008 | } | |
1009 | } | |
0dfa5ef9 | 1010 | |
4a0f031d | 1011 | void audio_init(ISABus *isa_bus, PCIBus *pci_bus) |
0dfa5ef9 IY |
1012 | { |
1013 | struct soundhw *c; | |
1014 | ||
1015 | for (c = soundhw; c->name; ++c) { | |
1016 | if (c->enabled) { | |
1017 | if (c->isa) { | |
4a0f031d HP |
1018 | if (isa_bus) { |
1019 | c->init.init_isa(isa_bus); | |
0dfa5ef9 IY |
1020 | } |
1021 | } else { | |
1022 | if (pci_bus) { | |
1023 | c->init.init_pci(pci_bus); | |
1024 | } | |
1025 | } | |
1026 | } | |
1027 | } | |
1028 | } | |
ad96090a BS |
1029 | #else |
1030 | void select_soundhw(const char *optarg) | |
1031 | { | |
1032 | } | |
4a0f031d | 1033 | void audio_init(ISABus *isa_bus, PCIBus *pci_bus) |
0dfa5ef9 IY |
1034 | { |
1035 | } | |
ad96090a BS |
1036 | #endif |
1037 | ||
1038 | int qemu_uuid_parse(const char *str, uint8_t *uuid) | |
1039 | { | |
1040 | int ret; | |
1041 | ||
1042 | if (strlen(str) != 36) { | |
1043 | return -1; | |
1044 | } | |
1045 | ||
1046 | ret = sscanf(str, UUID_FMT, &uuid[0], &uuid[1], &uuid[2], &uuid[3], | |
1047 | &uuid[4], &uuid[5], &uuid[6], &uuid[7], &uuid[8], &uuid[9], | |
1048 | &uuid[10], &uuid[11], &uuid[12], &uuid[13], &uuid[14], | |
1049 | &uuid[15]); | |
1050 | ||
1051 | if (ret != 16) { | |
1052 | return -1; | |
1053 | } | |
1054 | #ifdef TARGET_I386 | |
1055 | smbios_add_field(1, offsetof(struct smbios_type_1, uuid), 16, uuid); | |
1056 | #endif | |
1057 | return 0; | |
1058 | } | |
1059 | ||
1060 | void do_acpitable_option(const char *optarg) | |
1061 | { | |
1062 | #ifdef TARGET_I386 | |
1063 | if (acpi_table_add(optarg) < 0) { | |
1064 | fprintf(stderr, "Wrong acpi table provided\n"); | |
1065 | exit(1); | |
1066 | } | |
1067 | #endif | |
1068 | } | |
1069 | ||
1070 | void do_smbios_option(const char *optarg) | |
1071 | { | |
1072 | #ifdef TARGET_I386 | |
1073 | if (smbios_entry_add(optarg) < 0) { | |
1074 | fprintf(stderr, "Wrong smbios provided\n"); | |
1075 | exit(1); | |
1076 | } | |
1077 | #endif | |
1078 | } | |
1079 | ||
1080 | void cpudef_init(void) | |
1081 | { | |
1082 | #if defined(cpudef_setup) | |
1083 | cpudef_setup(); /* parse cpu definitions in target config file */ | |
1084 | #endif | |
1085 | } | |
1086 | ||
1087 | int audio_available(void) | |
1088 | { | |
1089 | #ifdef HAS_AUDIO | |
1090 | return 1; | |
1091 | #else | |
1092 | return 0; | |
1093 | #endif | |
1094 | } | |
1095 | ||
303d4e86 AP |
1096 | int tcg_available(void) |
1097 | { | |
1098 | return 1; | |
1099 | } | |
1100 | ||
ad96090a BS |
1101 | int kvm_available(void) |
1102 | { | |
1103 | #ifdef CONFIG_KVM | |
1104 | return 1; | |
1105 | #else | |
1106 | return 0; | |
1107 | #endif | |
1108 | } | |
1109 | ||
1110 | int xen_available(void) | |
1111 | { | |
1112 | #ifdef CONFIG_XEN | |
1113 | return 1; | |
1114 | #else | |
1115 | return 0; | |
1116 | #endif | |
1117 | } | |
99afc91d DB |
1118 | |
1119 | ||
1120 | TargetInfo *qmp_query_target(Error **errp) | |
1121 | { | |
1122 | TargetInfo *info = g_malloc0(sizeof(*info)); | |
1123 | ||
1124 | info->arch = TARGET_TYPE; | |
1125 | ||
1126 | return info; | |
1127 | } |