blob: a7c09870a13e47d1d47d5fa97970cfd7d08505dc [file] [log] [blame]
Blue Swirlad960902010-03-29 19:23:52 +00001/*
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>
Michael S. Tsirkinb2e0a132010-11-22 19:52:34 +020026#include <stdlib.h>
Blue Swirlad960902010-03-29 19:23:52 +000027#ifndef _WIN32
Blue Swirl1c47cb12010-03-30 19:27:34 +000028#include <sys/types.h>
Blue Swirlad960902010-03-29 19:23:52 +000029#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"
Avi Kivity86e775c2011-12-15 16:24:49 +020044#include "exec-memory.h"
Jan Kiszka302fe512012-02-17 11:24:34 +010045#include "hw/pcspk.h"
Orit Wasserman17ad9b32012-08-06 21:42:53 +030046#include "qemu/page_cache.h"
Blue Swirlad960902010-03-29 19:23:52 +000047
Orit Wasserman3a697f62012-06-19 18:43:15 +030048#ifdef DEBUG_ARCH_INIT
49#define DPRINTF(fmt, ...) \
50 do { fprintf(stdout, "arch_init: " fmt, ## __VA_ARGS__); } while (0)
51#else
52#define DPRINTF(fmt, ...) \
53 do { } while (0)
54#endif
55
Blue Swirlad960902010-03-29 19:23:52 +000056#ifdef TARGET_SPARC
57int graphic_width = 1024;
58int graphic_height = 768;
59int graphic_depth = 8;
60#else
61int graphic_width = 800;
62int graphic_height = 600;
63int graphic_depth = 15;
64#endif
65
Blue Swirlad960902010-03-29 19:23:52 +000066
67#if defined(TARGET_ALPHA)
68#define QEMU_ARCH QEMU_ARCH_ALPHA
69#elif defined(TARGET_ARM)
70#define QEMU_ARCH QEMU_ARCH_ARM
71#elif defined(TARGET_CRIS)
72#define QEMU_ARCH QEMU_ARCH_CRIS
73#elif defined(TARGET_I386)
74#define QEMU_ARCH QEMU_ARCH_I386
75#elif defined(TARGET_M68K)
76#define QEMU_ARCH QEMU_ARCH_M68K
Michael Walle81ea0e12011-02-17 23:45:02 +010077#elif defined(TARGET_LM32)
78#define QEMU_ARCH QEMU_ARCH_LM32
Blue Swirlad960902010-03-29 19:23:52 +000079#elif defined(TARGET_MICROBLAZE)
80#define QEMU_ARCH QEMU_ARCH_MICROBLAZE
81#elif defined(TARGET_MIPS)
82#define QEMU_ARCH QEMU_ARCH_MIPS
Jia Liue67db062012-07-20 15:50:39 +080083#elif defined(TARGET_OPENRISC)
84#define QEMU_ARCH QEMU_ARCH_OPENRISC
Blue Swirlad960902010-03-29 19:23:52 +000085#elif defined(TARGET_PPC)
86#define QEMU_ARCH QEMU_ARCH_PPC
87#elif defined(TARGET_S390X)
88#define QEMU_ARCH QEMU_ARCH_S390X
89#elif defined(TARGET_SH4)
90#define QEMU_ARCH QEMU_ARCH_SH4
91#elif defined(TARGET_SPARC)
92#define QEMU_ARCH QEMU_ARCH_SPARC
Max Filippov23288262011-09-06 03:55:25 +040093#elif defined(TARGET_XTENSA)
94#define QEMU_ARCH QEMU_ARCH_XTENSA
Blue Swirlad960902010-03-29 19:23:52 +000095#endif
96
97const uint32_t arch_type = QEMU_ARCH;
98
99/***********************************************************/
100/* ram save/restore */
101
Yoshiaki Tamurad20878d2010-08-18 13:30:12 +0900102#define RAM_SAVE_FLAG_FULL 0x01 /* Obsolete, not used anymore */
103#define RAM_SAVE_FLAG_COMPRESS 0x02
104#define RAM_SAVE_FLAG_MEM_SIZE 0x04
105#define RAM_SAVE_FLAG_PAGE 0x08
106#define RAM_SAVE_FLAG_EOS 0x10
107#define RAM_SAVE_FLAG_CONTINUE 0x20
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300108#define RAM_SAVE_FLAG_XBZRLE 0x40
Blue Swirlad960902010-03-29 19:23:52 +0000109
Paolo Bonzini86003612011-12-23 16:17:26 +0100110#ifdef __ALTIVEC__
111#include <altivec.h>
112#define VECTYPE vector unsigned char
113#define SPLAT(p) vec_splat(vec_ld(0, p), 0)
114#define ALL_EQ(v1, v2) vec_all_eq(v1, v2)
Andreas Färberf283edc2012-05-27 16:21:02 +0200115/* altivec.h may redefine the bool macro as vector type.
116 * Reset it to POSIX semantics. */
117#undef bool
118#define bool _Bool
Paolo Bonzini86003612011-12-23 16:17:26 +0100119#elif defined __SSE2__
120#include <emmintrin.h>
121#define VECTYPE __m128i
122#define SPLAT(p) _mm_set1_epi8(*(p))
123#define ALL_EQ(v1, v2) (_mm_movemask_epi8(_mm_cmpeq_epi8(v1, v2)) == 0xFFFF)
124#else
125#define VECTYPE unsigned long
126#define SPLAT(p) (*(p) * (~0UL / 255))
127#define ALL_EQ(v1, v2) ((v1) == (v2))
128#endif
129
Eduardo Habkostb5a8fe52012-05-02 13:07:25 -0300130
Eduardo Habkost756557d2012-05-02 13:07:27 -0300131static struct defconfig_file {
132 const char *filename;
Eduardo Habkostf29a5612012-05-02 13:07:29 -0300133 /* Indicates it is an user config file (disabled by -no-user-config) */
134 bool userconfig;
Eduardo Habkost756557d2012-05-02 13:07:27 -0300135} default_config_files[] = {
Eduardo Habkoste2d87bf2012-05-02 13:07:30 -0300136 { CONFIG_QEMU_DATADIR "/cpus-" TARGET_ARCH ".conf", false },
Eduardo Habkostf29a5612012-05-02 13:07:29 -0300137 { CONFIG_QEMU_CONFDIR "/qemu.conf", true },
138 { CONFIG_QEMU_CONFDIR "/target-" TARGET_ARCH ".conf", true },
Eduardo Habkost756557d2012-05-02 13:07:27 -0300139 { NULL }, /* end of list */
140};
141
142
Eduardo Habkostf29a5612012-05-02 13:07:29 -0300143int qemu_read_default_config_files(bool userconfig)
Eduardo Habkostb5a8fe52012-05-02 13:07:25 -0300144{
145 int ret;
Eduardo Habkost756557d2012-05-02 13:07:27 -0300146 struct defconfig_file *f;
147
148 for (f = default_config_files; f->filename; f++) {
Eduardo Habkostf29a5612012-05-02 13:07:29 -0300149 if (!userconfig && f->userconfig) {
150 continue;
151 }
Eduardo Habkost756557d2012-05-02 13:07:27 -0300152 ret = qemu_read_config_file(f->filename);
153 if (ret < 0 && ret != -ENOENT) {
154 return ret;
155 }
156 }
Eduardo Habkostb5a8fe52012-05-02 13:07:25 -0300157
Eduardo Habkostb5a8fe52012-05-02 13:07:25 -0300158 return 0;
159}
160
Paolo Bonzini86003612011-12-23 16:17:26 +0100161static int is_dup_page(uint8_t *page)
Blue Swirlad960902010-03-29 19:23:52 +0000162{
Paolo Bonzini86003612011-12-23 16:17:26 +0100163 VECTYPE *p = (VECTYPE *)page;
164 VECTYPE val = SPLAT(page);
Blue Swirlad960902010-03-29 19:23:52 +0000165 int i;
166
Paolo Bonzini86003612011-12-23 16:17:26 +0100167 for (i = 0; i < TARGET_PAGE_SIZE / sizeof(VECTYPE); i++) {
168 if (!ALL_EQ(val, p[i])) {
Blue Swirlad960902010-03-29 19:23:52 +0000169 return 0;
170 }
171 }
172
173 return 1;
174}
175
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300176/* struct contains XBZRLE cache and a static page
177 used by the compression */
178static struct {
179 /* buffer used for XBZRLE encoding */
180 uint8_t *encoded_buf;
181 /* buffer for storing page content */
182 uint8_t *current_buf;
183 /* buffer used for XBZRLE decoding */
184 uint8_t *decoded_buf;
185 /* Cache for XBZRLE */
186 PageCache *cache;
187} XBZRLE = {
188 .encoded_buf = NULL,
189 .current_buf = NULL,
190 .decoded_buf = NULL,
191 .cache = NULL,
192};
193
Orit Wasserman9e1ba4c2012-08-06 21:42:54 +0300194
195int64_t xbzrle_cache_resize(int64_t new_size)
196{
197 if (XBZRLE.cache != NULL) {
198 return cache_resize(XBZRLE.cache, new_size / TARGET_PAGE_SIZE) *
199 TARGET_PAGE_SIZE;
200 }
201 return pow2floor(new_size);
202}
203
Orit Wasserman004d4c12012-08-06 21:42:56 +0300204/* accounting for migration statistics */
205typedef struct AccountingInfo {
206 uint64_t dup_pages;
207 uint64_t norm_pages;
208 uint64_t iterations;
Orit Wassermanf36d55a2012-08-06 21:42:57 +0300209 uint64_t xbzrle_bytes;
210 uint64_t xbzrle_pages;
211 uint64_t xbzrle_cache_miss;
212 uint64_t xbzrle_overflows;
Orit Wasserman004d4c12012-08-06 21:42:56 +0300213} AccountingInfo;
214
215static AccountingInfo acct_info;
216
217static void acct_clear(void)
218{
219 memset(&acct_info, 0, sizeof(acct_info));
220}
221
222uint64_t dup_mig_bytes_transferred(void)
223{
224 return acct_info.dup_pages * TARGET_PAGE_SIZE;
225}
226
227uint64_t dup_mig_pages_transferred(void)
228{
229 return acct_info.dup_pages;
230}
231
232uint64_t norm_mig_bytes_transferred(void)
233{
234 return acct_info.norm_pages * TARGET_PAGE_SIZE;
235}
236
237uint64_t norm_mig_pages_transferred(void)
238{
239 return acct_info.norm_pages;
240}
241
Orit Wassermanf36d55a2012-08-06 21:42:57 +0300242uint64_t xbzrle_mig_bytes_transferred(void)
243{
244 return acct_info.xbzrle_bytes;
245}
246
247uint64_t xbzrle_mig_pages_transferred(void)
248{
249 return acct_info.xbzrle_pages;
250}
251
252uint64_t xbzrle_mig_pages_cache_miss(void)
253{
254 return acct_info.xbzrle_cache_miss;
255}
256
257uint64_t xbzrle_mig_pages_overflow(void)
258{
259 return acct_info.xbzrle_overflows;
260}
261
Orit Wasserman0c51f432012-06-19 18:43:14 +0300262static void save_block_hdr(QEMUFile *f, RAMBlock *block, ram_addr_t offset,
263 int cont, int flag)
264{
265 qemu_put_be64(f, offset | cont | flag);
266 if (!cont) {
267 qemu_put_byte(f, strlen(block->idstr));
268 qemu_put_buffer(f, (uint8_t *)block->idstr,
269 strlen(block->idstr));
270 }
271
272}
273
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300274#define ENCODING_FLAG_XBZRLE 0x1
275
276static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data,
277 ram_addr_t current_addr, RAMBlock *block,
Juan Quinteladd051c72012-08-06 21:42:58 +0300278 ram_addr_t offset, int cont, bool last_stage)
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300279{
280 int encoded_len = 0, bytes_sent = -1;
281 uint8_t *prev_cached_page;
282
283 if (!cache_is_cached(XBZRLE.cache, current_addr)) {
Juan Quinteladd051c72012-08-06 21:42:58 +0300284 if (!last_stage) {
285 cache_insert(XBZRLE.cache, current_addr,
286 g_memdup(current_data, TARGET_PAGE_SIZE));
287 }
Orit Wassermanf36d55a2012-08-06 21:42:57 +0300288 acct_info.xbzrle_cache_miss++;
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300289 return -1;
290 }
291
292 prev_cached_page = get_cached_data(XBZRLE.cache, current_addr);
293
294 /* save current buffer into memory */
295 memcpy(XBZRLE.current_buf, current_data, TARGET_PAGE_SIZE);
296
297 /* XBZRLE encoding (if there is no overflow) */
298 encoded_len = xbzrle_encode_buffer(prev_cached_page, XBZRLE.current_buf,
299 TARGET_PAGE_SIZE, XBZRLE.encoded_buf,
300 TARGET_PAGE_SIZE);
301 if (encoded_len == 0) {
302 DPRINTF("Skipping unmodified page\n");
303 return 0;
304 } else if (encoded_len == -1) {
305 DPRINTF("Overflow\n");
Orit Wassermanf36d55a2012-08-06 21:42:57 +0300306 acct_info.xbzrle_overflows++;
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300307 /* update data in the cache */
308 memcpy(prev_cached_page, current_data, TARGET_PAGE_SIZE);
309 return -1;
310 }
311
312 /* we need to update the data in the cache, in order to get the same data */
Juan Quinteladd051c72012-08-06 21:42:58 +0300313 if (!last_stage) {
314 memcpy(prev_cached_page, XBZRLE.current_buf, TARGET_PAGE_SIZE);
315 }
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300316
317 /* Send XBZRLE based compressed page */
318 save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_XBZRLE);
319 qemu_put_byte(f, ENCODING_FLAG_XBZRLE);
320 qemu_put_be16(f, encoded_len);
321 qemu_put_buffer(f, XBZRLE.encoded_buf, encoded_len);
322 bytes_sent = encoded_len + 1 + 2;
Orit Wassermanf36d55a2012-08-06 21:42:57 +0300323 acct_info.xbzrle_pages++;
324 acct_info.xbzrle_bytes += bytes_sent;
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300325
326 return bytes_sent;
327}
328
Alex Williamson760e77e2010-08-19 10:18:42 -0300329static RAMBlock *last_block;
330static ram_addr_t last_offset;
331
Orit Wasserman6c779f22012-07-10 12:37:13 +0300332/*
333 * ram_save_block: Writes a page of memory to the stream f
334 *
335 * Returns: 0: if the page hasn't changed
336 * -1: if there are no more dirty pages
337 * n: the amount of bytes written in other case
338 */
339
Juan Quinteladd051c72012-08-06 21:42:58 +0300340static int ram_save_block(QEMUFile *f, bool last_stage)
Blue Swirlad960902010-03-29 19:23:52 +0000341{
Alex Williamsone44359c2010-06-25 11:09:57 -0600342 RAMBlock *block = last_block;
343 ram_addr_t offset = last_offset;
Orit Wasserman6c779f22012-07-10 12:37:13 +0300344 int bytes_sent = -1;
Avi Kivity71c510e2011-12-21 13:11:22 +0200345 MemoryRegion *mr;
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300346 ram_addr_t current_addr;
Blue Swirlad960902010-03-29 19:23:52 +0000347
Alex Williamsone44359c2010-06-25 11:09:57 -0600348 if (!block)
349 block = QLIST_FIRST(&ram_list.blocks);
350
Alex Williamsone44359c2010-06-25 11:09:57 -0600351 do {
Avi Kivity71c510e2011-12-21 13:11:22 +0200352 mr = block->mr;
Blue Swirlcd7a45c2012-01-22 16:38:21 +0000353 if (memory_region_get_dirty(mr, offset, TARGET_PAGE_SIZE,
354 DIRTY_MEMORY_MIGRATION)) {
Blue Swirlad960902010-03-29 19:23:52 +0000355 uint8_t *p;
Alex Williamsona55bbe32010-06-25 11:10:05 -0600356 int cont = (block == last_block) ? RAM_SAVE_FLAG_CONTINUE : 0;
Blue Swirlad960902010-03-29 19:23:52 +0000357
Avi Kivity71c510e2011-12-21 13:11:22 +0200358 memory_region_reset_dirty(mr, offset, TARGET_PAGE_SIZE,
359 DIRTY_MEMORY_MIGRATION);
Blue Swirlad960902010-03-29 19:23:52 +0000360
Avi Kivity71c510e2011-12-21 13:11:22 +0200361 p = memory_region_get_ram_ptr(mr) + offset;
Blue Swirlad960902010-03-29 19:23:52 +0000362
Paolo Bonzini86003612011-12-23 16:17:26 +0100363 if (is_dup_page(p)) {
Orit Wasserman004d4c12012-08-06 21:42:56 +0300364 acct_info.dup_pages++;
Orit Wasserman0c51f432012-06-19 18:43:14 +0300365 save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_COMPRESS);
Blue Swirlad960902010-03-29 19:23:52 +0000366 qemu_put_byte(f, *p);
Pierre Riteau3fc250b2010-05-12 15:12:44 +0200367 bytes_sent = 1;
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300368 } else if (migrate_use_xbzrle()) {
369 current_addr = block->offset + offset;
370 bytes_sent = save_xbzrle_page(f, p, current_addr, block,
Juan Quinteladd051c72012-08-06 21:42:58 +0300371 offset, cont, last_stage);
372 if (!last_stage) {
373 p = get_cached_data(XBZRLE.cache, current_addr);
374 }
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300375 }
376
377 /* either we didn't send yet (we may have had XBZRLE overflow) */
378 if (bytes_sent == -1) {
Orit Wasserman0c51f432012-06-19 18:43:14 +0300379 save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_PAGE);
Blue Swirlad960902010-03-29 19:23:52 +0000380 qemu_put_buffer(f, p, TARGET_PAGE_SIZE);
Pierre Riteau3fc250b2010-05-12 15:12:44 +0200381 bytes_sent = TARGET_PAGE_SIZE;
Orit Wasserman004d4c12012-08-06 21:42:56 +0300382 acct_info.norm_pages++;
Blue Swirlad960902010-03-29 19:23:52 +0000383 }
384
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300385 /* if page is unmodified, continue to the next */
386 if (bytes_sent != 0) {
387 break;
388 }
Blue Swirlad960902010-03-29 19:23:52 +0000389 }
Alex Williamsone44359c2010-06-25 11:09:57 -0600390
391 offset += TARGET_PAGE_SIZE;
392 if (offset >= block->length) {
393 offset = 0;
394 block = QLIST_NEXT(block, next);
395 if (!block)
396 block = QLIST_FIRST(&ram_list.blocks);
397 }
Avi Kivity71c510e2011-12-21 13:11:22 +0200398 } while (block != last_block || offset != last_offset);
Alex Williamsone44359c2010-06-25 11:09:57 -0600399
400 last_block = block;
401 last_offset = offset;
Blue Swirlad960902010-03-29 19:23:52 +0000402
Pierre Riteau3fc250b2010-05-12 15:12:44 +0200403 return bytes_sent;
Blue Swirlad960902010-03-29 19:23:52 +0000404}
405
406static uint64_t bytes_transferred;
407
408static ram_addr_t ram_save_remaining(void)
409{
Juan Quintela45f33f02012-06-22 15:21:07 +0200410 return ram_list.dirty_pages;
Blue Swirlad960902010-03-29 19:23:52 +0000411}
412
413uint64_t ram_bytes_remaining(void)
414{
415 return ram_save_remaining() * TARGET_PAGE_SIZE;
416}
417
418uint64_t ram_bytes_transferred(void)
419{
420 return bytes_transferred;
421}
422
423uint64_t ram_bytes_total(void)
424{
Alex Williamsond17b5282010-06-25 11:08:38 -0600425 RAMBlock *block;
426 uint64_t total = 0;
427
428 QLIST_FOREACH(block, &ram_list.blocks, next)
429 total += block->length;
430
431 return total;
Blue Swirlad960902010-03-29 19:23:52 +0000432}
433
Michael S. Tsirkinb2e0a132010-11-22 19:52:34 +0200434static int block_compar(const void *a, const void *b)
435{
436 RAMBlock * const *ablock = a;
437 RAMBlock * const *bblock = b;
Avi Kivity8fec98b2011-12-21 13:22:16 +0200438
439 return strcmp((*ablock)->idstr, (*bblock)->idstr);
Michael S. Tsirkinb2e0a132010-11-22 19:52:34 +0200440}
441
442static void sort_ram_list(void)
443{
444 RAMBlock *block, *nblock, **blocks;
445 int n;
446 n = 0;
447 QLIST_FOREACH(block, &ram_list.blocks, next) {
448 ++n;
449 }
Anthony Liguori7267c092011-08-20 22:09:37 -0500450 blocks = g_malloc(n * sizeof *blocks);
Michael S. Tsirkinb2e0a132010-11-22 19:52:34 +0200451 n = 0;
452 QLIST_FOREACH_SAFE(block, &ram_list.blocks, next, nblock) {
453 blocks[n++] = block;
454 QLIST_REMOVE(block, next);
455 }
456 qsort(blocks, n, sizeof *blocks, block_compar);
457 while (--n >= 0) {
458 QLIST_INSERT_HEAD(&ram_list.blocks, blocks[n], next);
459 }
Anthony Liguori7267c092011-08-20 22:09:37 -0500460 g_free(blocks);
Michael S. Tsirkinb2e0a132010-11-22 19:52:34 +0200461}
462
Orit Wasserman8e21cd32012-06-19 18:43:17 +0300463static void migration_end(void)
464{
465 memory_global_dirty_log_stop();
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300466
467 if (migrate_use_xbzrle()) {
468 cache_fini(XBZRLE.cache);
469 g_free(XBZRLE.cache);
470 g_free(XBZRLE.encoded_buf);
471 g_free(XBZRLE.current_buf);
472 g_free(XBZRLE.decoded_buf);
473 XBZRLE.cache = NULL;
474 }
Orit Wasserman8e21cd32012-06-19 18:43:17 +0300475}
476
Juan Quintela9b5bfab2012-06-26 19:26:41 +0200477static void ram_migration_cancel(void *opaque)
478{
479 migration_end();
480}
481
Juan Quintela4508bd92012-05-22 16:27:59 +0200482#define MAX_WAIT 50 /* ms, half buffered_file limit */
483
Juan Quintelad1315aa2012-06-28 15:11:57 +0200484static int ram_save_setup(QEMUFile *f, void *opaque)
Blue Swirlad960902010-03-29 19:23:52 +0000485{
486 ram_addr_t addr;
Juan Quintelad1315aa2012-06-28 15:11:57 +0200487 RAMBlock *block;
Blue Swirlad960902010-03-29 19:23:52 +0000488
Juan Quintelad1315aa2012-06-28 15:11:57 +0200489 bytes_transferred = 0;
490 last_block = NULL;
491 last_offset = 0;
492 sort_ram_list();
Blue Swirlad960902010-03-29 19:23:52 +0000493
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300494 if (migrate_use_xbzrle()) {
495 XBZRLE.cache = cache_init(migrate_xbzrle_cache_size() /
496 TARGET_PAGE_SIZE,
497 TARGET_PAGE_SIZE);
498 if (!XBZRLE.cache) {
499 DPRINTF("Error creating cache\n");
500 return -1;
501 }
502 XBZRLE.encoded_buf = g_malloc0(TARGET_PAGE_SIZE);
503 XBZRLE.current_buf = g_malloc(TARGET_PAGE_SIZE);
Orit Wasserman004d4c12012-08-06 21:42:56 +0300504 acct_clear();
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300505 }
506
Juan Quintelad1315aa2012-06-28 15:11:57 +0200507 /* Make sure all dirty bits are set */
508 QLIST_FOREACH(block, &ram_list.blocks, next) {
509 for (addr = 0; addr < block->length; addr += TARGET_PAGE_SIZE) {
510 if (!memory_region_get_dirty(block->mr, addr, TARGET_PAGE_SIZE,
511 DIRTY_MEMORY_MIGRATION)) {
512 memory_region_set_dirty(block->mr, addr, TARGET_PAGE_SIZE);
Blue Swirlad960902010-03-29 19:23:52 +0000513 }
514 }
Blue Swirlad960902010-03-29 19:23:52 +0000515 }
516
Juan Quintelad1315aa2012-06-28 15:11:57 +0200517 memory_global_dirty_log_start();
518
519 qemu_put_be64(f, ram_bytes_total() | RAM_SAVE_FLAG_MEM_SIZE);
520
521 QLIST_FOREACH(block, &ram_list.blocks, next) {
522 qemu_put_byte(f, strlen(block->idstr));
523 qemu_put_buffer(f, (uint8_t *)block->idstr, strlen(block->idstr));
524 qemu_put_be64(f, block->length);
525 }
526
Juan Quintelad1315aa2012-06-28 15:11:57 +0200527 qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
528
529 return 0;
530}
531
Juan Quintela16310a32012-06-28 15:31:37 +0200532static int ram_save_iterate(QEMUFile *f, void *opaque)
Juan Quintelad1315aa2012-06-28 15:11:57 +0200533{
Blue Swirlad960902010-03-29 19:23:52 +0000534 uint64_t bytes_transferred_last;
535 double bwidth = 0;
536 int ret;
537 int i;
Juan Quintela16310a32012-06-28 15:31:37 +0200538 uint64_t expected_time;
Blue Swirlad960902010-03-29 19:23:52 +0000539
540 bytes_transferred_last = bytes_transferred;
541 bwidth = qemu_get_clock_ns(rt_clock);
542
Juan Quintela4508bd92012-05-22 16:27:59 +0200543 i = 0;
Juan Quintela29757252011-10-19 15:22:18 +0200544 while ((ret = qemu_file_rate_limit(f)) == 0) {
Pierre Riteau3fc250b2010-05-12 15:12:44 +0200545 int bytes_sent;
Blue Swirlad960902010-03-29 19:23:52 +0000546
Juan Quinteladd051c72012-08-06 21:42:58 +0300547 bytes_sent = ram_save_block(f, false);
Orit Wasserman6c779f22012-07-10 12:37:13 +0300548 /* no more blocks to sent */
549 if (bytes_sent < 0) {
Blue Swirlad960902010-03-29 19:23:52 +0000550 break;
551 }
Orit Wasserman6c779f22012-07-10 12:37:13 +0300552 bytes_transferred += bytes_sent;
Orit Wasserman004d4c12012-08-06 21:42:56 +0300553 acct_info.iterations++;
Juan Quintela4508bd92012-05-22 16:27:59 +0200554 /* we want to check in the 1st loop, just in case it was the 1st time
555 and we had to sync the dirty bitmap.
556 qemu_get_clock_ns() is a bit expensive, so we only check each some
557 iterations
558 */
559 if ((i & 63) == 0) {
560 uint64_t t1 = (qemu_get_clock_ns(rt_clock) - bwidth) / 1000000;
561 if (t1 > MAX_WAIT) {
562 DPRINTF("big wait: " PRIu64 " milliseconds, %d iterations\n",
563 t1, i);
564 break;
565 }
566 }
567 i++;
Blue Swirlad960902010-03-29 19:23:52 +0000568 }
569
Juan Quintela29757252011-10-19 15:22:18 +0200570 if (ret < 0) {
571 return ret;
572 }
573
Blue Swirlad960902010-03-29 19:23:52 +0000574 bwidth = qemu_get_clock_ns(rt_clock) - bwidth;
575 bwidth = (bytes_transferred - bytes_transferred_last) / bwidth;
576
577 /* if we haven't transferred anything this round, force expected_time to a
578 * a very high value, but without crashing */
579 if (bwidth == 0) {
580 bwidth = 0.000001;
581 }
582
Blue Swirlad960902010-03-29 19:23:52 +0000583 qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
584
Juan Quintela16310a32012-06-28 15:31:37 +0200585 expected_time = ram_save_remaining() * TARGET_PAGE_SIZE / bwidth;
Blue Swirlad960902010-03-29 19:23:52 +0000586
Juan Quintela16310a32012-06-28 15:31:37 +0200587 DPRINTF("ram_save_live: expected(" PRIu64 ") <= max(" PRIu64 ")?\n",
588 expected_time, migrate_max_downtime());
589
Juan Quintela00d94f32012-06-28 19:51:17 +0200590 if (expected_time <= migrate_max_downtime()) {
591 memory_global_sync_dirty_bitmap(get_system_memory());
592 expected_time = ram_save_remaining() * TARGET_PAGE_SIZE / bwidth;
Orit Wasserman3a697f62012-06-19 18:43:15 +0300593
Juan Quintela5b3c9632012-05-22 00:44:24 +0200594 return expected_time <= migrate_max_downtime();
595 }
596 return 0;
Blue Swirlad960902010-03-29 19:23:52 +0000597}
598
Juan Quintela16310a32012-06-28 15:31:37 +0200599static int ram_save_complete(QEMUFile *f, void *opaque)
600{
Juan Quintela16310a32012-06-28 15:31:37 +0200601 memory_global_sync_dirty_bitmap(get_system_memory());
602
Juan Quintela16310a32012-06-28 15:31:37 +0200603 /* try transferring iterative blocks of memory */
604
605 /* flush all remaining blocks regardless of rate limiting */
Orit Wasserman6c779f22012-07-10 12:37:13 +0300606 while (true) {
607 int bytes_sent;
608
Juan Quinteladd051c72012-08-06 21:42:58 +0300609 bytes_sent = ram_save_block(f, true);
Orit Wasserman6c779f22012-07-10 12:37:13 +0300610 /* no more blocks to sent */
611 if (bytes_sent < 0) {
612 break;
613 }
Juan Quintela16310a32012-06-28 15:31:37 +0200614 bytes_transferred += bytes_sent;
615 }
616 memory_global_dirty_log_stop();
617
Blue Swirlad960902010-03-29 19:23:52 +0000618 qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
619
Alex Williamsona55bbe32010-06-25 11:10:05 -0600620 return 0;
621}
622
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300623static int load_xbzrle(QEMUFile *f, ram_addr_t addr, void *host)
624{
625 int ret, rc = 0;
626 unsigned int xh_len;
627 int xh_flags;
628
629 if (!XBZRLE.decoded_buf) {
630 XBZRLE.decoded_buf = g_malloc(TARGET_PAGE_SIZE);
631 }
632
633 /* extract RLE header */
634 xh_flags = qemu_get_byte(f);
635 xh_len = qemu_get_be16(f);
636
637 if (xh_flags != ENCODING_FLAG_XBZRLE) {
638 fprintf(stderr, "Failed to load XBZRLE page - wrong compression!\n");
639 return -1;
640 }
641
642 if (xh_len > TARGET_PAGE_SIZE) {
643 fprintf(stderr, "Failed to load XBZRLE page - len overflow!\n");
644 return -1;
645 }
646 /* load data and decode */
647 qemu_get_buffer(f, XBZRLE.decoded_buf, xh_len);
648
649 /* decode RLE */
650 ret = xbzrle_decode_buffer(XBZRLE.decoded_buf, xh_len, host,
651 TARGET_PAGE_SIZE);
652 if (ret == -1) {
653 fprintf(stderr, "Failed to load XBZRLE page - decode error!\n");
654 rc = -1;
655 } else if (ret > TARGET_PAGE_SIZE) {
656 fprintf(stderr, "Failed to load XBZRLE page - size %d exceeds %d!\n",
657 ret, TARGET_PAGE_SIZE);
658 abort();
659 }
660
661 return rc;
662}
663
Alex Williamsona55bbe32010-06-25 11:10:05 -0600664static inline void *host_from_stream_offset(QEMUFile *f,
665 ram_addr_t offset,
666 int flags)
667{
668 static RAMBlock *block = NULL;
669 char id[256];
670 uint8_t len;
671
672 if (flags & RAM_SAVE_FLAG_CONTINUE) {
673 if (!block) {
674 fprintf(stderr, "Ack, bad migration stream!\n");
675 return NULL;
676 }
677
Avi Kivitydc94a7e2011-12-21 13:54:33 +0200678 return memory_region_get_ram_ptr(block->mr) + offset;
Alex Williamsona55bbe32010-06-25 11:10:05 -0600679 }
680
681 len = qemu_get_byte(f);
682 qemu_get_buffer(f, (uint8_t *)id, len);
683 id[len] = 0;
684
685 QLIST_FOREACH(block, &ram_list.blocks, next) {
686 if (!strncmp(id, block->idstr, sizeof(id)))
Avi Kivitydc94a7e2011-12-21 13:54:33 +0200687 return memory_region_get_ram_ptr(block->mr) + offset;
Alex Williamsona55bbe32010-06-25 11:10:05 -0600688 }
689
690 fprintf(stderr, "Can't find block %s!\n", id);
691 return NULL;
692}
693
Juan Quintela7908c782012-06-26 18:46:10 +0200694static int ram_load(QEMUFile *f, void *opaque, int version_id)
Blue Swirlad960902010-03-29 19:23:52 +0000695{
696 ram_addr_t addr;
Orit Wasserman3a697f62012-06-19 18:43:15 +0300697 int flags, ret = 0;
Juan Quintela42802d42011-10-05 01:14:46 +0200698 int error;
Orit Wasserman3a697f62012-06-19 18:43:15 +0300699 static uint64_t seq_iter;
700
701 seq_iter++;
Blue Swirlad960902010-03-29 19:23:52 +0000702
Avi Kivityf09f2182011-12-21 13:37:56 +0200703 if (version_id < 4 || version_id > 4) {
Blue Swirlad960902010-03-29 19:23:52 +0000704 return -EINVAL;
705 }
706
707 do {
708 addr = qemu_get_be64(f);
709
710 flags = addr & ~TARGET_PAGE_MASK;
711 addr &= TARGET_PAGE_MASK;
712
713 if (flags & RAM_SAVE_FLAG_MEM_SIZE) {
Avi Kivityf09f2182011-12-21 13:37:56 +0200714 if (version_id == 4) {
Alex Williamson97ab12d2010-06-25 11:09:50 -0600715 /* Synchronize RAM block list */
716 char id[256];
717 ram_addr_t length;
718 ram_addr_t total_ram_bytes = addr;
719
720 while (total_ram_bytes) {
721 RAMBlock *block;
722 uint8_t len;
723
724 len = qemu_get_byte(f);
725 qemu_get_buffer(f, (uint8_t *)id, len);
726 id[len] = 0;
727 length = qemu_get_be64(f);
728
729 QLIST_FOREACH(block, &ram_list.blocks, next) {
730 if (!strncmp(id, block->idstr, sizeof(id))) {
Orit Wasserman3a697f62012-06-19 18:43:15 +0300731 if (block->length != length) {
732 ret = -EINVAL;
733 goto done;
734 }
Alex Williamson97ab12d2010-06-25 11:09:50 -0600735 break;
736 }
737 }
738
739 if (!block) {
Alex Williamsonfb787f82010-07-02 11:13:29 -0600740 fprintf(stderr, "Unknown ramblock \"%s\", cannot "
741 "accept migration\n", id);
Orit Wasserman3a697f62012-06-19 18:43:15 +0300742 ret = -EINVAL;
743 goto done;
Alex Williamson97ab12d2010-06-25 11:09:50 -0600744 }
745
746 total_ram_bytes -= length;
747 }
Blue Swirlad960902010-03-29 19:23:52 +0000748 }
749 }
750
751 if (flags & RAM_SAVE_FLAG_COMPRESS) {
Alex Williamson97ab12d2010-06-25 11:09:50 -0600752 void *host;
753 uint8_t ch;
754
Avi Kivityf09f2182011-12-21 13:37:56 +0200755 host = host_from_stream_offset(f, addr, flags);
Michael S. Tsirkin492fb992010-10-17 20:43:40 +0200756 if (!host) {
757 return -EINVAL;
758 }
Alex Williamson97ab12d2010-06-25 11:09:50 -0600759
Alex Williamson97ab12d2010-06-25 11:09:50 -0600760 ch = qemu_get_byte(f);
761 memset(host, ch, TARGET_PAGE_SIZE);
Blue Swirlad960902010-03-29 19:23:52 +0000762#ifndef _WIN32
763 if (ch == 0 &&
764 (!kvm_enabled() || kvm_has_sync_mmu())) {
Andreas Färbere78815a2010-09-25 11:26:05 +0000765 qemu_madvise(host, TARGET_PAGE_SIZE, QEMU_MADV_DONTNEED);
Blue Swirlad960902010-03-29 19:23:52 +0000766 }
767#endif
768 } else if (flags & RAM_SAVE_FLAG_PAGE) {
Alex Williamson97ab12d2010-06-25 11:09:50 -0600769 void *host;
770
Avi Kivityf09f2182011-12-21 13:37:56 +0200771 host = host_from_stream_offset(f, addr, flags);
Orit Wasserman0ff1f9f2012-06-19 11:51:37 +0300772 if (!host) {
773 return -EINVAL;
774 }
Alex Williamson97ab12d2010-06-25 11:09:50 -0600775
Alex Williamson97ab12d2010-06-25 11:09:50 -0600776 qemu_get_buffer(f, host, TARGET_PAGE_SIZE);
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300777 } else if (flags & RAM_SAVE_FLAG_XBZRLE) {
778 if (!migrate_use_xbzrle()) {
779 return -EINVAL;
780 }
781 void *host = host_from_stream_offset(f, addr, flags);
782 if (!host) {
783 return -EINVAL;
784 }
785
786 if (load_xbzrle(f, addr, host) < 0) {
787 ret = -EINVAL;
788 goto done;
789 }
Blue Swirlad960902010-03-29 19:23:52 +0000790 }
Juan Quintela42802d42011-10-05 01:14:46 +0200791 error = qemu_file_get_error(f);
792 if (error) {
Orit Wasserman3a697f62012-06-19 18:43:15 +0300793 ret = error;
794 goto done;
Blue Swirlad960902010-03-29 19:23:52 +0000795 }
796 } while (!(flags & RAM_SAVE_FLAG_EOS));
797
Orit Wasserman3a697f62012-06-19 18:43:15 +0300798done:
799 DPRINTF("Completed load of VM with exit code %d seq iteration " PRIu64 "\n",
800 ret, seq_iter);
801 return ret;
Blue Swirlad960902010-03-29 19:23:52 +0000802}
803
Juan Quintela7908c782012-06-26 18:46:10 +0200804SaveVMHandlers savevm_ram_handlers = {
Juan Quintelad1315aa2012-06-28 15:11:57 +0200805 .save_live_setup = ram_save_setup,
Juan Quintela16310a32012-06-28 15:31:37 +0200806 .save_live_iterate = ram_save_iterate,
807 .save_live_complete = ram_save_complete,
Juan Quintela7908c782012-06-26 18:46:10 +0200808 .load_state = ram_load,
Juan Quintela9b5bfab2012-06-26 19:26:41 +0200809 .cancel = ram_migration_cancel,
Juan Quintela7908c782012-06-26 18:46:10 +0200810};
811
Blue Swirlad960902010-03-29 19:23:52 +0000812#ifdef HAS_AUDIO
Isaku Yamahata0dfa5ef2011-01-21 19:53:45 +0900813struct soundhw {
814 const char *name;
815 const char *descr;
816 int enabled;
817 int isa;
818 union {
Hervé Poussineau4a0f0312011-12-15 22:10:01 +0100819 int (*init_isa) (ISABus *bus);
Isaku Yamahata0dfa5ef2011-01-21 19:53:45 +0900820 int (*init_pci) (PCIBus *bus);
821 } init;
822};
823
824static struct soundhw soundhw[] = {
Blue Swirlad960902010-03-29 19:23:52 +0000825#ifdef HAS_AUDIO_CHOICE
Hervé Poussineauda128722012-04-14 22:51:33 +0200826#ifdef CONFIG_PCSPK
Blue Swirlad960902010-03-29 19:23:52 +0000827 {
828 "pcspk",
829 "PC speaker",
830 0,
831 1,
832 { .init_isa = pcspk_audio_init }
833 },
834#endif
835
836#ifdef CONFIG_SB16
837 {
838 "sb16",
839 "Creative Sound Blaster 16",
840 0,
841 1,
842 { .init_isa = SB16_init }
843 },
844#endif
845
846#ifdef CONFIG_CS4231A
847 {
848 "cs4231a",
849 "CS4231A",
850 0,
851 1,
852 { .init_isa = cs4231a_init }
853 },
854#endif
855
856#ifdef CONFIG_ADLIB
857 {
858 "adlib",
859#ifdef HAS_YMF262
860 "Yamaha YMF262 (OPL3)",
861#else
862 "Yamaha YM3812 (OPL2)",
863#endif
864 0,
865 1,
866 { .init_isa = Adlib_init }
867 },
868#endif
869
870#ifdef CONFIG_GUS
871 {
872 "gus",
873 "Gravis Ultrasound GF1",
874 0,
875 1,
876 { .init_isa = GUS_init }
877 },
878#endif
879
880#ifdef CONFIG_AC97
881 {
882 "ac97",
883 "Intel 82801AA AC97 Audio",
884 0,
885 0,
886 { .init_pci = ac97_init }
887 },
888#endif
889
890#ifdef CONFIG_ES1370
891 {
892 "es1370",
893 "ENSONIQ AudioPCI ES1370",
894 0,
895 0,
896 { .init_pci = es1370_init }
897 },
898#endif
899
Gerd Hoffmannd61a4ce2010-11-01 13:05:32 +0100900#ifdef CONFIG_HDA
901 {
902 "hda",
903 "Intel HD Audio",
904 0,
905 0,
906 { .init_pci = intel_hda_and_codec_init }
907 },
908#endif
909
Blue Swirlad960902010-03-29 19:23:52 +0000910#endif /* HAS_AUDIO_CHOICE */
911
912 { NULL, NULL, 0, 0, { NULL } }
913};
914
915void select_soundhw(const char *optarg)
916{
917 struct soundhw *c;
918
Peter Maydellc8057f92012-08-02 13:45:54 +0100919 if (is_help_option(optarg)) {
Blue Swirlad960902010-03-29 19:23:52 +0000920 show_valid_cards:
921
922 printf("Valid sound card names (comma separated):\n");
923 for (c = soundhw; c->name; ++c) {
924 printf ("%-11s %s\n", c->name, c->descr);
925 }
926 printf("\n-soundhw all will enable all of the above\n");
Peter Maydellc8057f92012-08-02 13:45:54 +0100927 exit(!is_help_option(optarg));
Blue Swirlad960902010-03-29 19:23:52 +0000928 }
929 else {
930 size_t l;
931 const char *p;
932 char *e;
933 int bad_card = 0;
934
935 if (!strcmp(optarg, "all")) {
936 for (c = soundhw; c->name; ++c) {
937 c->enabled = 1;
938 }
939 return;
940 }
941
942 p = optarg;
943 while (*p) {
944 e = strchr(p, ',');
945 l = !e ? strlen(p) : (size_t) (e - p);
946
947 for (c = soundhw; c->name; ++c) {
948 if (!strncmp(c->name, p, l) && !c->name[l]) {
949 c->enabled = 1;
950 break;
951 }
952 }
953
954 if (!c->name) {
955 if (l > 80) {
956 fprintf(stderr,
957 "Unknown sound card name (too big to show)\n");
958 }
959 else {
960 fprintf(stderr, "Unknown sound card name `%.*s'\n",
961 (int) l, p);
962 }
963 bad_card = 1;
964 }
965 p += l + (e != NULL);
966 }
967
968 if (bad_card) {
969 goto show_valid_cards;
970 }
971 }
972}
Isaku Yamahata0dfa5ef2011-01-21 19:53:45 +0900973
Hervé Poussineau4a0f0312011-12-15 22:10:01 +0100974void audio_init(ISABus *isa_bus, PCIBus *pci_bus)
Isaku Yamahata0dfa5ef2011-01-21 19:53:45 +0900975{
976 struct soundhw *c;
977
978 for (c = soundhw; c->name; ++c) {
979 if (c->enabled) {
980 if (c->isa) {
Hervé Poussineau4a0f0312011-12-15 22:10:01 +0100981 if (isa_bus) {
982 c->init.init_isa(isa_bus);
Isaku Yamahata0dfa5ef2011-01-21 19:53:45 +0900983 }
984 } else {
985 if (pci_bus) {
986 c->init.init_pci(pci_bus);
987 }
988 }
989 }
990 }
991}
Blue Swirlad960902010-03-29 19:23:52 +0000992#else
993void select_soundhw(const char *optarg)
994{
995}
Hervé Poussineau4a0f0312011-12-15 22:10:01 +0100996void audio_init(ISABus *isa_bus, PCIBus *pci_bus)
Isaku Yamahata0dfa5ef2011-01-21 19:53:45 +0900997{
998}
Blue Swirlad960902010-03-29 19:23:52 +0000999#endif
1000
1001int qemu_uuid_parse(const char *str, uint8_t *uuid)
1002{
1003 int ret;
1004
1005 if (strlen(str) != 36) {
1006 return -1;
1007 }
1008
1009 ret = sscanf(str, UUID_FMT, &uuid[0], &uuid[1], &uuid[2], &uuid[3],
1010 &uuid[4], &uuid[5], &uuid[6], &uuid[7], &uuid[8], &uuid[9],
1011 &uuid[10], &uuid[11], &uuid[12], &uuid[13], &uuid[14],
1012 &uuid[15]);
1013
1014 if (ret != 16) {
1015 return -1;
1016 }
1017#ifdef TARGET_I386
1018 smbios_add_field(1, offsetof(struct smbios_type_1, uuid), 16, uuid);
1019#endif
1020 return 0;
1021}
1022
1023void do_acpitable_option(const char *optarg)
1024{
1025#ifdef TARGET_I386
1026 if (acpi_table_add(optarg) < 0) {
1027 fprintf(stderr, "Wrong acpi table provided\n");
1028 exit(1);
1029 }
1030#endif
1031}
1032
1033void do_smbios_option(const char *optarg)
1034{
1035#ifdef TARGET_I386
1036 if (smbios_entry_add(optarg) < 0) {
1037 fprintf(stderr, "Wrong smbios provided\n");
1038 exit(1);
1039 }
1040#endif
1041}
1042
1043void cpudef_init(void)
1044{
1045#if defined(cpudef_setup)
1046 cpudef_setup(); /* parse cpu definitions in target config file */
1047#endif
1048}
1049
1050int audio_available(void)
1051{
1052#ifdef HAS_AUDIO
1053 return 1;
1054#else
1055 return 0;
1056#endif
1057}
1058
Anthony PERARD303d4e82010-09-21 20:05:31 +01001059int tcg_available(void)
1060{
1061 return 1;
1062}
1063
Blue Swirlad960902010-03-29 19:23:52 +00001064int kvm_available(void)
1065{
1066#ifdef CONFIG_KVM
1067 return 1;
1068#else
1069 return 0;
1070#endif
1071}
1072
1073int xen_available(void)
1074{
1075#ifdef CONFIG_XEN
1076 return 1;
1077#else
1078 return 0;
1079#endif
1080}