blob: 90a722e6c96a24f500c70fb32c1d055ce3fdecdb [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"
Daniel P. Berrange99afc912012-08-20 15:31:38 +010047#include "qmp-commands.h"
Blue Swirlad960902010-03-29 19:23:52 +000048
Orit Wasserman3a697f62012-06-19 18:43:15 +030049#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
Blue Swirlad960902010-03-29 19:23:52 +000057#ifdef TARGET_SPARC
58int graphic_width = 1024;
59int graphic_height = 768;
60int graphic_depth = 8;
61#else
62int graphic_width = 800;
63int graphic_height = 600;
64int graphic_depth = 15;
65#endif
66
Blue Swirlad960902010-03-29 19:23:52 +000067
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
Michael Walle81ea0e12011-02-17 23:45:02 +010078#elif defined(TARGET_LM32)
79#define QEMU_ARCH QEMU_ARCH_LM32
Blue Swirlad960902010-03-29 19:23:52 +000080#elif defined(TARGET_MICROBLAZE)
81#define QEMU_ARCH QEMU_ARCH_MICROBLAZE
82#elif defined(TARGET_MIPS)
83#define QEMU_ARCH QEMU_ARCH_MIPS
Jia Liue67db062012-07-20 15:50:39 +080084#elif defined(TARGET_OPENRISC)
85#define QEMU_ARCH QEMU_ARCH_OPENRISC
Blue Swirlad960902010-03-29 19:23:52 +000086#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
Max Filippov23288262011-09-06 03:55:25 +040094#elif defined(TARGET_XTENSA)
95#define QEMU_ARCH QEMU_ARCH_XTENSA
Guan Xuetao4f23a1e2012-08-10 14:42:21 +080096#elif defined(TARGET_UNICORE32)
97#define QEMU_ARCH QEMU_ARCH_UNICORE32
Blue Swirlad960902010-03-29 19:23:52 +000098#endif
99
100const uint32_t arch_type = QEMU_ARCH;
101
102/***********************************************************/
103/* ram save/restore */
104
Yoshiaki Tamurad20878d2010-08-18 13:30:12 +0900105#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
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300111#define RAM_SAVE_FLAG_XBZRLE 0x40
Blue Swirlad960902010-03-29 19:23:52 +0000112
Paolo Bonzini86003612011-12-23 16:17:26 +0100113#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)
Andreas Färberf283edc2012-05-27 16:21:02 +0200118/* altivec.h may redefine the bool macro as vector type.
119 * Reset it to POSIX semantics. */
120#undef bool
121#define bool _Bool
Paolo Bonzini86003612011-12-23 16:17:26 +0100122#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
Eduardo Habkostb5a8fe52012-05-02 13:07:25 -0300133
Eduardo Habkost756557d2012-05-02 13:07:27 -0300134static struct defconfig_file {
135 const char *filename;
Eduardo Habkostf29a5612012-05-02 13:07:29 -0300136 /* Indicates it is an user config file (disabled by -no-user-config) */
137 bool userconfig;
Eduardo Habkost756557d2012-05-02 13:07:27 -0300138} default_config_files[] = {
Eduardo Habkostf29a5612012-05-02 13:07:29 -0300139 { CONFIG_QEMU_CONFDIR "/qemu.conf", true },
140 { CONFIG_QEMU_CONFDIR "/target-" TARGET_ARCH ".conf", true },
Eduardo Habkost756557d2012-05-02 13:07:27 -0300141 { NULL }, /* end of list */
142};
143
144
Eduardo Habkostf29a5612012-05-02 13:07:29 -0300145int qemu_read_default_config_files(bool userconfig)
Eduardo Habkostb5a8fe52012-05-02 13:07:25 -0300146{
147 int ret;
Eduardo Habkost756557d2012-05-02 13:07:27 -0300148 struct defconfig_file *f;
149
150 for (f = default_config_files; f->filename; f++) {
Eduardo Habkostf29a5612012-05-02 13:07:29 -0300151 if (!userconfig && f->userconfig) {
152 continue;
153 }
Eduardo Habkost756557d2012-05-02 13:07:27 -0300154 ret = qemu_read_config_file(f->filename);
155 if (ret < 0 && ret != -ENOENT) {
156 return ret;
157 }
158 }
Eduardo Habkostb5a8fe52012-05-02 13:07:25 -0300159
Eduardo Habkostb5a8fe52012-05-02 13:07:25 -0300160 return 0;
161}
162
Paolo Bonzini86003612011-12-23 16:17:26 +0100163static int is_dup_page(uint8_t *page)
Blue Swirlad960902010-03-29 19:23:52 +0000164{
Paolo Bonzini86003612011-12-23 16:17:26 +0100165 VECTYPE *p = (VECTYPE *)page;
166 VECTYPE val = SPLAT(page);
Blue Swirlad960902010-03-29 19:23:52 +0000167 int i;
168
Paolo Bonzini86003612011-12-23 16:17:26 +0100169 for (i = 0; i < TARGET_PAGE_SIZE / sizeof(VECTYPE); i++) {
170 if (!ALL_EQ(val, p[i])) {
Blue Swirlad960902010-03-29 19:23:52 +0000171 return 0;
172 }
173 }
174
175 return 1;
176}
177
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300178/* struct contains XBZRLE cache and a static page
179 used by the compression */
180static 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
Orit Wasserman9e1ba4c2012-08-06 21:42:54 +0300196
197int64_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
Orit Wasserman004d4c12012-08-06 21:42:56 +0300206/* accounting for migration statistics */
207typedef struct AccountingInfo {
208 uint64_t dup_pages;
209 uint64_t norm_pages;
210 uint64_t iterations;
Orit Wassermanf36d55a2012-08-06 21:42:57 +0300211 uint64_t xbzrle_bytes;
212 uint64_t xbzrle_pages;
213 uint64_t xbzrle_cache_miss;
214 uint64_t xbzrle_overflows;
Orit Wasserman004d4c12012-08-06 21:42:56 +0300215} AccountingInfo;
216
217static AccountingInfo acct_info;
218
219static void acct_clear(void)
220{
221 memset(&acct_info, 0, sizeof(acct_info));
222}
223
224uint64_t dup_mig_bytes_transferred(void)
225{
226 return acct_info.dup_pages * TARGET_PAGE_SIZE;
227}
228
229uint64_t dup_mig_pages_transferred(void)
230{
231 return acct_info.dup_pages;
232}
233
234uint64_t norm_mig_bytes_transferred(void)
235{
236 return acct_info.norm_pages * TARGET_PAGE_SIZE;
237}
238
239uint64_t norm_mig_pages_transferred(void)
240{
241 return acct_info.norm_pages;
242}
243
Orit Wassermanf36d55a2012-08-06 21:42:57 +0300244uint64_t xbzrle_mig_bytes_transferred(void)
245{
246 return acct_info.xbzrle_bytes;
247}
248
249uint64_t xbzrle_mig_pages_transferred(void)
250{
251 return acct_info.xbzrle_pages;
252}
253
254uint64_t xbzrle_mig_pages_cache_miss(void)
255{
256 return acct_info.xbzrle_cache_miss;
257}
258
259uint64_t xbzrle_mig_pages_overflow(void)
260{
261 return acct_info.xbzrle_overflows;
262}
263
Orit Wasserman0c51f432012-06-19 18:43:14 +0300264static 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
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300276#define ENCODING_FLAG_XBZRLE 0x1
277
278static int save_xbzrle_page(QEMUFile *f, uint8_t *current_data,
279 ram_addr_t current_addr, RAMBlock *block,
Juan Quinteladd051c72012-08-06 21:42:58 +0300280 ram_addr_t offset, int cont, bool last_stage)
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300281{
282 int encoded_len = 0, bytes_sent = -1;
283 uint8_t *prev_cached_page;
284
285 if (!cache_is_cached(XBZRLE.cache, current_addr)) {
Juan Quinteladd051c72012-08-06 21:42:58 +0300286 if (!last_stage) {
287 cache_insert(XBZRLE.cache, current_addr,
288 g_memdup(current_data, TARGET_PAGE_SIZE));
289 }
Orit Wassermanf36d55a2012-08-06 21:42:57 +0300290 acct_info.xbzrle_cache_miss++;
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300291 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");
Orit Wassermanf36d55a2012-08-06 21:42:57 +0300308 acct_info.xbzrle_overflows++;
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300309 /* 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 */
Juan Quinteladd051c72012-08-06 21:42:58 +0300315 if (!last_stage) {
316 memcpy(prev_cached_page, XBZRLE.current_buf, TARGET_PAGE_SIZE);
317 }
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300318
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;
Orit Wassermanf36d55a2012-08-06 21:42:57 +0300325 acct_info.xbzrle_pages++;
326 acct_info.xbzrle_bytes += bytes_sent;
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300327
328 return bytes_sent;
329}
330
Alex Williamson760e77e2010-08-19 10:18:42 -0300331static RAMBlock *last_block;
332static ram_addr_t last_offset;
333
Juan Quintela69268cd2012-07-20 10:36:12 +0200334static 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
Juan Quintelae44d26c2012-07-20 10:16:08 +0200347static 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
Orit Wasserman6c779f22012-07-10 12:37:13 +0300359/*
360 * ram_save_block: Writes a page of memory to the stream f
361 *
362 * Returns: 0: if the page hasn't changed
363 * -1: if there are no more dirty pages
364 * n: the amount of bytes written in other case
365 */
366
Juan Quinteladd051c72012-08-06 21:42:58 +0300367static int ram_save_block(QEMUFile *f, bool last_stage)
Blue Swirlad960902010-03-29 19:23:52 +0000368{
Alex Williamsone44359c2010-06-25 11:09:57 -0600369 RAMBlock *block = last_block;
370 ram_addr_t offset = last_offset;
Orit Wasserman6c779f22012-07-10 12:37:13 +0300371 int bytes_sent = -1;
Avi Kivity71c510e2011-12-21 13:11:22 +0200372 MemoryRegion *mr;
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300373 ram_addr_t current_addr;
Blue Swirlad960902010-03-29 19:23:52 +0000374
Alex Williamsone44359c2010-06-25 11:09:57 -0600375 if (!block)
376 block = QLIST_FIRST(&ram_list.blocks);
377
Alex Williamsone44359c2010-06-25 11:09:57 -0600378 do {
Avi Kivity71c510e2011-12-21 13:11:22 +0200379 mr = block->mr;
Juan Quintela69268cd2012-07-20 10:36:12 +0200380 if (migration_bitmap_test_and_reset_dirty(mr, offset)) {
Blue Swirlad960902010-03-29 19:23:52 +0000381 uint8_t *p;
Alex Williamsona55bbe32010-06-25 11:10:05 -0600382 int cont = (block == last_block) ? RAM_SAVE_FLAG_CONTINUE : 0;
Blue Swirlad960902010-03-29 19:23:52 +0000383
Avi Kivity71c510e2011-12-21 13:11:22 +0200384 p = memory_region_get_ram_ptr(mr) + offset;
Blue Swirlad960902010-03-29 19:23:52 +0000385
Paolo Bonzini86003612011-12-23 16:17:26 +0100386 if (is_dup_page(p)) {
Orit Wasserman004d4c12012-08-06 21:42:56 +0300387 acct_info.dup_pages++;
Orit Wasserman0c51f432012-06-19 18:43:14 +0300388 save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_COMPRESS);
Blue Swirlad960902010-03-29 19:23:52 +0000389 qemu_put_byte(f, *p);
Pierre Riteau3fc250b2010-05-12 15:12:44 +0200390 bytes_sent = 1;
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300391 } else if (migrate_use_xbzrle()) {
392 current_addr = block->offset + offset;
393 bytes_sent = save_xbzrle_page(f, p, current_addr, block,
Juan Quinteladd051c72012-08-06 21:42:58 +0300394 offset, cont, last_stage);
395 if (!last_stage) {
396 p = get_cached_data(XBZRLE.cache, current_addr);
397 }
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300398 }
399
400 /* either we didn't send yet (we may have had XBZRLE overflow) */
401 if (bytes_sent == -1) {
Orit Wasserman0c51f432012-06-19 18:43:14 +0300402 save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_PAGE);
Blue Swirlad960902010-03-29 19:23:52 +0000403 qemu_put_buffer(f, p, TARGET_PAGE_SIZE);
Pierre Riteau3fc250b2010-05-12 15:12:44 +0200404 bytes_sent = TARGET_PAGE_SIZE;
Orit Wasserman004d4c12012-08-06 21:42:56 +0300405 acct_info.norm_pages++;
Blue Swirlad960902010-03-29 19:23:52 +0000406 }
407
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300408 /* if page is unmodified, continue to the next */
409 if (bytes_sent != 0) {
410 break;
411 }
Blue Swirlad960902010-03-29 19:23:52 +0000412 }
Alex Williamsone44359c2010-06-25 11:09:57 -0600413
414 offset += TARGET_PAGE_SIZE;
415 if (offset >= block->length) {
416 offset = 0;
417 block = QLIST_NEXT(block, next);
418 if (!block)
419 block = QLIST_FIRST(&ram_list.blocks);
420 }
Avi Kivity71c510e2011-12-21 13:11:22 +0200421 } while (block != last_block || offset != last_offset);
Alex Williamsone44359c2010-06-25 11:09:57 -0600422
423 last_block = block;
424 last_offset = offset;
Blue Swirlad960902010-03-29 19:23:52 +0000425
Pierre Riteau3fc250b2010-05-12 15:12:44 +0200426 return bytes_sent;
Blue Swirlad960902010-03-29 19:23:52 +0000427}
428
429static uint64_t bytes_transferred;
430
431static ram_addr_t ram_save_remaining(void)
432{
Juan Quintela45f33f02012-06-22 15:21:07 +0200433 return ram_list.dirty_pages;
Blue Swirlad960902010-03-29 19:23:52 +0000434}
435
436uint64_t ram_bytes_remaining(void)
437{
438 return ram_save_remaining() * TARGET_PAGE_SIZE;
439}
440
441uint64_t ram_bytes_transferred(void)
442{
443 return bytes_transferred;
444}
445
446uint64_t ram_bytes_total(void)
447{
Alex Williamsond17b5282010-06-25 11:08:38 -0600448 RAMBlock *block;
449 uint64_t total = 0;
450
451 QLIST_FOREACH(block, &ram_list.blocks, next)
452 total += block->length;
453
454 return total;
Blue Swirlad960902010-03-29 19:23:52 +0000455}
456
Michael S. Tsirkinb2e0a132010-11-22 19:52:34 +0200457static int block_compar(const void *a, const void *b)
458{
459 RAMBlock * const *ablock = a;
460 RAMBlock * const *bblock = b;
Avi Kivity8fec98b2011-12-21 13:22:16 +0200461
462 return strcmp((*ablock)->idstr, (*bblock)->idstr);
Michael S. Tsirkinb2e0a132010-11-22 19:52:34 +0200463}
464
465static void sort_ram_list(void)
466{
467 RAMBlock *block, *nblock, **blocks;
468 int n;
469 n = 0;
470 QLIST_FOREACH(block, &ram_list.blocks, next) {
471 ++n;
472 }
Anthony Liguori7267c092011-08-20 22:09:37 -0500473 blocks = g_malloc(n * sizeof *blocks);
Michael S. Tsirkinb2e0a132010-11-22 19:52:34 +0200474 n = 0;
475 QLIST_FOREACH_SAFE(block, &ram_list.blocks, next, nblock) {
476 blocks[n++] = block;
477 QLIST_REMOVE(block, next);
478 }
479 qsort(blocks, n, sizeof *blocks, block_compar);
480 while (--n >= 0) {
481 QLIST_INSERT_HEAD(&ram_list.blocks, blocks[n], next);
482 }
Anthony Liguori7267c092011-08-20 22:09:37 -0500483 g_free(blocks);
Michael S. Tsirkinb2e0a132010-11-22 19:52:34 +0200484}
485
Orit Wasserman8e21cd32012-06-19 18:43:17 +0300486static void migration_end(void)
487{
488 memory_global_dirty_log_stop();
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300489
490 if (migrate_use_xbzrle()) {
491 cache_fini(XBZRLE.cache);
492 g_free(XBZRLE.cache);
493 g_free(XBZRLE.encoded_buf);
494 g_free(XBZRLE.current_buf);
495 g_free(XBZRLE.decoded_buf);
496 XBZRLE.cache = NULL;
497 }
Orit Wasserman8e21cd32012-06-19 18:43:17 +0300498}
499
Juan Quintela9b5bfab2012-06-26 19:26:41 +0200500static void ram_migration_cancel(void *opaque)
501{
502 migration_end();
503}
504
Juan Quintela5a170772012-07-17 17:02:24 +0200505
506static void reset_ram_globals(void)
507{
508 last_block = NULL;
509 last_offset = 0;
510 sort_ram_list();
511}
512
Juan Quintela4508bd92012-05-22 16:27:59 +0200513#define MAX_WAIT 50 /* ms, half buffered_file limit */
514
Juan Quintelad1315aa2012-06-28 15:11:57 +0200515static int ram_save_setup(QEMUFile *f, void *opaque)
Blue Swirlad960902010-03-29 19:23:52 +0000516{
Juan Quintelad1315aa2012-06-28 15:11:57 +0200517 RAMBlock *block;
Blue Swirlad960902010-03-29 19:23:52 +0000518
Juan Quintelad1315aa2012-06-28 15:11:57 +0200519 bytes_transferred = 0;
Juan Quintela5a170772012-07-17 17:02:24 +0200520 reset_ram_globals();
Blue Swirlad960902010-03-29 19:23:52 +0000521
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300522 if (migrate_use_xbzrle()) {
523 XBZRLE.cache = cache_init(migrate_xbzrle_cache_size() /
524 TARGET_PAGE_SIZE,
525 TARGET_PAGE_SIZE);
526 if (!XBZRLE.cache) {
527 DPRINTF("Error creating cache\n");
528 return -1;
529 }
530 XBZRLE.encoded_buf = g_malloc0(TARGET_PAGE_SIZE);
531 XBZRLE.current_buf = g_malloc(TARGET_PAGE_SIZE);
Orit Wasserman004d4c12012-08-06 21:42:56 +0300532 acct_clear();
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300533 }
534
Juan Quintelad1315aa2012-06-28 15:11:57 +0200535 /* Make sure all dirty bits are set */
536 QLIST_FOREACH(block, &ram_list.blocks, next) {
Juan Quintelae44d26c2012-07-20 10:16:08 +0200537 migration_bitmap_set_dirty(block->mr, block->length);
Blue Swirlad960902010-03-29 19:23:52 +0000538 }
539
Juan Quintelad1315aa2012-06-28 15:11:57 +0200540 memory_global_dirty_log_start();
Juan Quintela79536f42012-08-03 12:58:16 +0200541 memory_global_sync_dirty_bitmap(get_system_memory());
Juan Quintelad1315aa2012-06-28 15:11:57 +0200542
543 qemu_put_be64(f, ram_bytes_total() | RAM_SAVE_FLAG_MEM_SIZE);
544
545 QLIST_FOREACH(block, &ram_list.blocks, next) {
546 qemu_put_byte(f, strlen(block->idstr));
547 qemu_put_buffer(f, (uint8_t *)block->idstr, strlen(block->idstr));
548 qemu_put_be64(f, block->length);
549 }
550
Juan Quintelad1315aa2012-06-28 15:11:57 +0200551 qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
552
553 return 0;
554}
555
Juan Quintela16310a32012-06-28 15:31:37 +0200556static int ram_save_iterate(QEMUFile *f, void *opaque)
Juan Quintelad1315aa2012-06-28 15:11:57 +0200557{
Blue Swirlad960902010-03-29 19:23:52 +0000558 uint64_t bytes_transferred_last;
559 double bwidth = 0;
560 int ret;
561 int i;
Juan Quintelac00012f2012-08-13 09:36:36 +0200562 uint64_t expected_downtime;
Juan Quintela2c52ddf2012-08-13 09:53:12 +0200563 MigrationState *s = migrate_get_current();
Blue Swirlad960902010-03-29 19:23:52 +0000564
565 bytes_transferred_last = bytes_transferred;
566 bwidth = qemu_get_clock_ns(rt_clock);
567
Juan Quintela4508bd92012-05-22 16:27:59 +0200568 i = 0;
Juan Quintela29757252011-10-19 15:22:18 +0200569 while ((ret = qemu_file_rate_limit(f)) == 0) {
Pierre Riteau3fc250b2010-05-12 15:12:44 +0200570 int bytes_sent;
Blue Swirlad960902010-03-29 19:23:52 +0000571
Juan Quinteladd051c72012-08-06 21:42:58 +0300572 bytes_sent = ram_save_block(f, false);
Orit Wasserman6c779f22012-07-10 12:37:13 +0300573 /* no more blocks to sent */
574 if (bytes_sent < 0) {
Blue Swirlad960902010-03-29 19:23:52 +0000575 break;
576 }
Orit Wasserman6c779f22012-07-10 12:37:13 +0300577 bytes_transferred += bytes_sent;
Orit Wasserman004d4c12012-08-06 21:42:56 +0300578 acct_info.iterations++;
Juan Quintela4508bd92012-05-22 16:27:59 +0200579 /* we want to check in the 1st loop, just in case it was the 1st time
580 and we had to sync the dirty bitmap.
581 qemu_get_clock_ns() is a bit expensive, so we only check each some
582 iterations
583 */
584 if ((i & 63) == 0) {
585 uint64_t t1 = (qemu_get_clock_ns(rt_clock) - bwidth) / 1000000;
586 if (t1 > MAX_WAIT) {
Igor Mitsyankoef37a692012-09-05 13:04:56 +0400587 DPRINTF("big wait: %" PRIu64 " milliseconds, %d iterations\n",
Juan Quintela4508bd92012-05-22 16:27:59 +0200588 t1, i);
589 break;
590 }
591 }
592 i++;
Blue Swirlad960902010-03-29 19:23:52 +0000593 }
594
Juan Quintela29757252011-10-19 15:22:18 +0200595 if (ret < 0) {
596 return ret;
597 }
598
Blue Swirlad960902010-03-29 19:23:52 +0000599 bwidth = qemu_get_clock_ns(rt_clock) - bwidth;
600 bwidth = (bytes_transferred - bytes_transferred_last) / bwidth;
601
Juan Quintelac00012f2012-08-13 09:36:36 +0200602 /* if we haven't transferred anything this round, force
603 * expected_downtime to a very high value, but without
604 * crashing */
Blue Swirlad960902010-03-29 19:23:52 +0000605 if (bwidth == 0) {
606 bwidth = 0.000001;
607 }
608
Blue Swirlad960902010-03-29 19:23:52 +0000609 qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
610
Juan Quintelac00012f2012-08-13 09:36:36 +0200611 expected_downtime = ram_save_remaining() * TARGET_PAGE_SIZE / bwidth;
612 DPRINTF("ram_save_live: expected(%" PRIu64 ") <= max(" PRIu64 ")?\n",
613 expected_downtime, migrate_max_downtime());
Blue Swirlad960902010-03-29 19:23:52 +0000614
Juan Quintelac00012f2012-08-13 09:36:36 +0200615 if (expected_downtime <= migrate_max_downtime()) {
Juan Quintela00d94f32012-06-28 19:51:17 +0200616 memory_global_sync_dirty_bitmap(get_system_memory());
Juan Quintelac00012f2012-08-13 09:36:36 +0200617 expected_downtime = ram_save_remaining() * TARGET_PAGE_SIZE / bwidth;
Juan Quintela2c52ddf2012-08-13 09:53:12 +0200618 s->expected_downtime = expected_downtime / 1000000; /* ns -> ms */
Orit Wasserman3a697f62012-06-19 18:43:15 +0300619
Juan Quintelac00012f2012-08-13 09:36:36 +0200620 return expected_downtime <= migrate_max_downtime();
Juan Quintela5b3c9632012-05-22 00:44:24 +0200621 }
622 return 0;
Blue Swirlad960902010-03-29 19:23:52 +0000623}
624
Juan Quintela16310a32012-06-28 15:31:37 +0200625static int ram_save_complete(QEMUFile *f, void *opaque)
626{
Juan Quintela16310a32012-06-28 15:31:37 +0200627 memory_global_sync_dirty_bitmap(get_system_memory());
628
Juan Quintela16310a32012-06-28 15:31:37 +0200629 /* try transferring iterative blocks of memory */
630
631 /* flush all remaining blocks regardless of rate limiting */
Orit Wasserman6c779f22012-07-10 12:37:13 +0300632 while (true) {
633 int bytes_sent;
634
Juan Quinteladd051c72012-08-06 21:42:58 +0300635 bytes_sent = ram_save_block(f, true);
Orit Wasserman6c779f22012-07-10 12:37:13 +0300636 /* no more blocks to sent */
637 if (bytes_sent < 0) {
638 break;
639 }
Juan Quintela16310a32012-06-28 15:31:37 +0200640 bytes_transferred += bytes_sent;
641 }
642 memory_global_dirty_log_stop();
643
Blue Swirlad960902010-03-29 19:23:52 +0000644 qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
645
Alex Williamsona55bbe32010-06-25 11:10:05 -0600646 return 0;
647}
648
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300649static int load_xbzrle(QEMUFile *f, ram_addr_t addr, void *host)
650{
651 int ret, rc = 0;
652 unsigned int xh_len;
653 int xh_flags;
654
655 if (!XBZRLE.decoded_buf) {
656 XBZRLE.decoded_buf = g_malloc(TARGET_PAGE_SIZE);
657 }
658
659 /* extract RLE header */
660 xh_flags = qemu_get_byte(f);
661 xh_len = qemu_get_be16(f);
662
663 if (xh_flags != ENCODING_FLAG_XBZRLE) {
664 fprintf(stderr, "Failed to load XBZRLE page - wrong compression!\n");
665 return -1;
666 }
667
668 if (xh_len > TARGET_PAGE_SIZE) {
669 fprintf(stderr, "Failed to load XBZRLE page - len overflow!\n");
670 return -1;
671 }
672 /* load data and decode */
673 qemu_get_buffer(f, XBZRLE.decoded_buf, xh_len);
674
675 /* decode RLE */
676 ret = xbzrle_decode_buffer(XBZRLE.decoded_buf, xh_len, host,
677 TARGET_PAGE_SIZE);
678 if (ret == -1) {
679 fprintf(stderr, "Failed to load XBZRLE page - decode error!\n");
680 rc = -1;
681 } else if (ret > TARGET_PAGE_SIZE) {
682 fprintf(stderr, "Failed to load XBZRLE page - size %d exceeds %d!\n",
683 ret, TARGET_PAGE_SIZE);
684 abort();
685 }
686
687 return rc;
688}
689
Alex Williamsona55bbe32010-06-25 11:10:05 -0600690static inline void *host_from_stream_offset(QEMUFile *f,
691 ram_addr_t offset,
692 int flags)
693{
694 static RAMBlock *block = NULL;
695 char id[256];
696 uint8_t len;
697
698 if (flags & RAM_SAVE_FLAG_CONTINUE) {
699 if (!block) {
700 fprintf(stderr, "Ack, bad migration stream!\n");
701 return NULL;
702 }
703
Avi Kivitydc94a7e2011-12-21 13:54:33 +0200704 return memory_region_get_ram_ptr(block->mr) + offset;
Alex Williamsona55bbe32010-06-25 11:10:05 -0600705 }
706
707 len = qemu_get_byte(f);
708 qemu_get_buffer(f, (uint8_t *)id, len);
709 id[len] = 0;
710
711 QLIST_FOREACH(block, &ram_list.blocks, next) {
712 if (!strncmp(id, block->idstr, sizeof(id)))
Avi Kivitydc94a7e2011-12-21 13:54:33 +0200713 return memory_region_get_ram_ptr(block->mr) + offset;
Alex Williamsona55bbe32010-06-25 11:10:05 -0600714 }
715
716 fprintf(stderr, "Can't find block %s!\n", id);
717 return NULL;
718}
719
Juan Quintela7908c782012-06-26 18:46:10 +0200720static int ram_load(QEMUFile *f, void *opaque, int version_id)
Blue Swirlad960902010-03-29 19:23:52 +0000721{
722 ram_addr_t addr;
Orit Wasserman3a697f62012-06-19 18:43:15 +0300723 int flags, ret = 0;
Juan Quintela42802d42011-10-05 01:14:46 +0200724 int error;
Orit Wasserman3a697f62012-06-19 18:43:15 +0300725 static uint64_t seq_iter;
726
727 seq_iter++;
Blue Swirlad960902010-03-29 19:23:52 +0000728
Avi Kivityf09f2182011-12-21 13:37:56 +0200729 if (version_id < 4 || version_id > 4) {
Blue Swirlad960902010-03-29 19:23:52 +0000730 return -EINVAL;
731 }
732
733 do {
734 addr = qemu_get_be64(f);
735
736 flags = addr & ~TARGET_PAGE_MASK;
737 addr &= TARGET_PAGE_MASK;
738
739 if (flags & RAM_SAVE_FLAG_MEM_SIZE) {
Avi Kivityf09f2182011-12-21 13:37:56 +0200740 if (version_id == 4) {
Alex Williamson97ab12d2010-06-25 11:09:50 -0600741 /* Synchronize RAM block list */
742 char id[256];
743 ram_addr_t length;
744 ram_addr_t total_ram_bytes = addr;
745
746 while (total_ram_bytes) {
747 RAMBlock *block;
748 uint8_t len;
749
750 len = qemu_get_byte(f);
751 qemu_get_buffer(f, (uint8_t *)id, len);
752 id[len] = 0;
753 length = qemu_get_be64(f);
754
755 QLIST_FOREACH(block, &ram_list.blocks, next) {
756 if (!strncmp(id, block->idstr, sizeof(id))) {
Orit Wasserman3a697f62012-06-19 18:43:15 +0300757 if (block->length != length) {
758 ret = -EINVAL;
759 goto done;
760 }
Alex Williamson97ab12d2010-06-25 11:09:50 -0600761 break;
762 }
763 }
764
765 if (!block) {
Alex Williamsonfb787f82010-07-02 11:13:29 -0600766 fprintf(stderr, "Unknown ramblock \"%s\", cannot "
767 "accept migration\n", id);
Orit Wasserman3a697f62012-06-19 18:43:15 +0300768 ret = -EINVAL;
769 goto done;
Alex Williamson97ab12d2010-06-25 11:09:50 -0600770 }
771
772 total_ram_bytes -= length;
773 }
Blue Swirlad960902010-03-29 19:23:52 +0000774 }
775 }
776
777 if (flags & RAM_SAVE_FLAG_COMPRESS) {
Alex Williamson97ab12d2010-06-25 11:09:50 -0600778 void *host;
779 uint8_t ch;
780
Avi Kivityf09f2182011-12-21 13:37:56 +0200781 host = host_from_stream_offset(f, addr, flags);
Michael S. Tsirkin492fb992010-10-17 20:43:40 +0200782 if (!host) {
783 return -EINVAL;
784 }
Alex Williamson97ab12d2010-06-25 11:09:50 -0600785
Alex Williamson97ab12d2010-06-25 11:09:50 -0600786 ch = qemu_get_byte(f);
787 memset(host, ch, TARGET_PAGE_SIZE);
Blue Swirlad960902010-03-29 19:23:52 +0000788#ifndef _WIN32
789 if (ch == 0 &&
790 (!kvm_enabled() || kvm_has_sync_mmu())) {
Andreas Färbere78815a2010-09-25 11:26:05 +0000791 qemu_madvise(host, TARGET_PAGE_SIZE, QEMU_MADV_DONTNEED);
Blue Swirlad960902010-03-29 19:23:52 +0000792 }
793#endif
794 } else if (flags & RAM_SAVE_FLAG_PAGE) {
Alex Williamson97ab12d2010-06-25 11:09:50 -0600795 void *host;
796
Avi Kivityf09f2182011-12-21 13:37:56 +0200797 host = host_from_stream_offset(f, addr, flags);
Orit Wasserman0ff1f9f2012-06-19 11:51:37 +0300798 if (!host) {
799 return -EINVAL;
800 }
Alex Williamson97ab12d2010-06-25 11:09:50 -0600801
Alex Williamson97ab12d2010-06-25 11:09:50 -0600802 qemu_get_buffer(f, host, TARGET_PAGE_SIZE);
Orit Wasserman17ad9b32012-08-06 21:42:53 +0300803 } else if (flags & RAM_SAVE_FLAG_XBZRLE) {
804 if (!migrate_use_xbzrle()) {
805 return -EINVAL;
806 }
807 void *host = host_from_stream_offset(f, addr, flags);
808 if (!host) {
809 return -EINVAL;
810 }
811
812 if (load_xbzrle(f, addr, host) < 0) {
813 ret = -EINVAL;
814 goto done;
815 }
Blue Swirlad960902010-03-29 19:23:52 +0000816 }
Juan Quintela42802d42011-10-05 01:14:46 +0200817 error = qemu_file_get_error(f);
818 if (error) {
Orit Wasserman3a697f62012-06-19 18:43:15 +0300819 ret = error;
820 goto done;
Blue Swirlad960902010-03-29 19:23:52 +0000821 }
822 } while (!(flags & RAM_SAVE_FLAG_EOS));
823
Orit Wasserman3a697f62012-06-19 18:43:15 +0300824done:
Igor Mitsyankoef37a692012-09-05 13:04:56 +0400825 DPRINTF("Completed load of VM with exit code %d seq iteration "
826 "%" PRIu64 "\n", ret, seq_iter);
Orit Wasserman3a697f62012-06-19 18:43:15 +0300827 return ret;
Blue Swirlad960902010-03-29 19:23:52 +0000828}
829
Juan Quintela7908c782012-06-26 18:46:10 +0200830SaveVMHandlers savevm_ram_handlers = {
Juan Quintelad1315aa2012-06-28 15:11:57 +0200831 .save_live_setup = ram_save_setup,
Juan Quintela16310a32012-06-28 15:31:37 +0200832 .save_live_iterate = ram_save_iterate,
833 .save_live_complete = ram_save_complete,
Juan Quintela7908c782012-06-26 18:46:10 +0200834 .load_state = ram_load,
Juan Quintela9b5bfab2012-06-26 19:26:41 +0200835 .cancel = ram_migration_cancel,
Juan Quintela7908c782012-06-26 18:46:10 +0200836};
837
Blue Swirlad960902010-03-29 19:23:52 +0000838#ifdef HAS_AUDIO
Isaku Yamahata0dfa5ef2011-01-21 19:53:45 +0900839struct soundhw {
840 const char *name;
841 const char *descr;
842 int enabled;
843 int isa;
844 union {
Hervé Poussineau4a0f0312011-12-15 22:10:01 +0100845 int (*init_isa) (ISABus *bus);
Isaku Yamahata0dfa5ef2011-01-21 19:53:45 +0900846 int (*init_pci) (PCIBus *bus);
847 } init;
848};
849
850static struct soundhw soundhw[] = {
Blue Swirlad960902010-03-29 19:23:52 +0000851#ifdef HAS_AUDIO_CHOICE
Hervé Poussineauda128722012-04-14 22:51:33 +0200852#ifdef CONFIG_PCSPK
Blue Swirlad960902010-03-29 19:23:52 +0000853 {
854 "pcspk",
855 "PC speaker",
856 0,
857 1,
858 { .init_isa = pcspk_audio_init }
859 },
860#endif
861
862#ifdef CONFIG_SB16
863 {
864 "sb16",
865 "Creative Sound Blaster 16",
866 0,
867 1,
868 { .init_isa = SB16_init }
869 },
870#endif
871
872#ifdef CONFIG_CS4231A
873 {
874 "cs4231a",
875 "CS4231A",
876 0,
877 1,
878 { .init_isa = cs4231a_init }
879 },
880#endif
881
882#ifdef CONFIG_ADLIB
883 {
884 "adlib",
885#ifdef HAS_YMF262
886 "Yamaha YMF262 (OPL3)",
887#else
888 "Yamaha YM3812 (OPL2)",
889#endif
890 0,
891 1,
892 { .init_isa = Adlib_init }
893 },
894#endif
895
896#ifdef CONFIG_GUS
897 {
898 "gus",
899 "Gravis Ultrasound GF1",
900 0,
901 1,
902 { .init_isa = GUS_init }
903 },
904#endif
905
906#ifdef CONFIG_AC97
907 {
908 "ac97",
909 "Intel 82801AA AC97 Audio",
910 0,
911 0,
912 { .init_pci = ac97_init }
913 },
914#endif
915
916#ifdef CONFIG_ES1370
917 {
918 "es1370",
919 "ENSONIQ AudioPCI ES1370",
920 0,
921 0,
922 { .init_pci = es1370_init }
923 },
924#endif
925
Gerd Hoffmannd61a4ce2010-11-01 13:05:32 +0100926#ifdef CONFIG_HDA
927 {
928 "hda",
929 "Intel HD Audio",
930 0,
931 0,
932 { .init_pci = intel_hda_and_codec_init }
933 },
934#endif
935
Blue Swirlad960902010-03-29 19:23:52 +0000936#endif /* HAS_AUDIO_CHOICE */
937
938 { NULL, NULL, 0, 0, { NULL } }
939};
940
941void select_soundhw(const char *optarg)
942{
943 struct soundhw *c;
944
Peter Maydellc8057f92012-08-02 13:45:54 +0100945 if (is_help_option(optarg)) {
Blue Swirlad960902010-03-29 19:23:52 +0000946 show_valid_cards:
947
Peter Maydell55d4fd32012-09-19 14:51:38 +0100948#ifdef HAS_AUDIO_CHOICE
Blue Swirlad960902010-03-29 19:23:52 +0000949 printf("Valid sound card names (comma separated):\n");
950 for (c = soundhw; c->name; ++c) {
951 printf ("%-11s %s\n", c->name, c->descr);
952 }
953 printf("\n-soundhw all will enable all of the above\n");
Peter Maydell55d4fd32012-09-19 14:51:38 +0100954#else
955 printf("Machine has no user-selectable audio hardware "
956 "(it may or may not have always-present audio hardware).\n");
957#endif
Peter Maydellc8057f92012-08-02 13:45:54 +0100958 exit(!is_help_option(optarg));
Blue Swirlad960902010-03-29 19:23:52 +0000959 }
960 else {
961 size_t l;
962 const char *p;
963 char *e;
964 int bad_card = 0;
965
966 if (!strcmp(optarg, "all")) {
967 for (c = soundhw; c->name; ++c) {
968 c->enabled = 1;
969 }
970 return;
971 }
972
973 p = optarg;
974 while (*p) {
975 e = strchr(p, ',');
976 l = !e ? strlen(p) : (size_t) (e - p);
977
978 for (c = soundhw; c->name; ++c) {
979 if (!strncmp(c->name, p, l) && !c->name[l]) {
980 c->enabled = 1;
981 break;
982 }
983 }
984
985 if (!c->name) {
986 if (l > 80) {
987 fprintf(stderr,
988 "Unknown sound card name (too big to show)\n");
989 }
990 else {
991 fprintf(stderr, "Unknown sound card name `%.*s'\n",
992 (int) l, p);
993 }
994 bad_card = 1;
995 }
996 p += l + (e != NULL);
997 }
998
999 if (bad_card) {
1000 goto show_valid_cards;
1001 }
1002 }
1003}
Isaku Yamahata0dfa5ef2011-01-21 19:53:45 +09001004
Hervé Poussineau4a0f0312011-12-15 22:10:01 +01001005void audio_init(ISABus *isa_bus, PCIBus *pci_bus)
Isaku Yamahata0dfa5ef2011-01-21 19:53:45 +09001006{
1007 struct soundhw *c;
1008
1009 for (c = soundhw; c->name; ++c) {
1010 if (c->enabled) {
1011 if (c->isa) {
Hervé Poussineau4a0f0312011-12-15 22:10:01 +01001012 if (isa_bus) {
1013 c->init.init_isa(isa_bus);
Isaku Yamahata0dfa5ef2011-01-21 19:53:45 +09001014 }
1015 } else {
1016 if (pci_bus) {
1017 c->init.init_pci(pci_bus);
1018 }
1019 }
1020 }
1021 }
1022}
Blue Swirlad960902010-03-29 19:23:52 +00001023#else
1024void select_soundhw(const char *optarg)
1025{
1026}
Hervé Poussineau4a0f0312011-12-15 22:10:01 +01001027void audio_init(ISABus *isa_bus, PCIBus *pci_bus)
Isaku Yamahata0dfa5ef2011-01-21 19:53:45 +09001028{
1029}
Blue Swirlad960902010-03-29 19:23:52 +00001030#endif
1031
1032int qemu_uuid_parse(const char *str, uint8_t *uuid)
1033{
1034 int ret;
1035
1036 if (strlen(str) != 36) {
1037 return -1;
1038 }
1039
1040 ret = sscanf(str, UUID_FMT, &uuid[0], &uuid[1], &uuid[2], &uuid[3],
1041 &uuid[4], &uuid[5], &uuid[6], &uuid[7], &uuid[8], &uuid[9],
1042 &uuid[10], &uuid[11], &uuid[12], &uuid[13], &uuid[14],
1043 &uuid[15]);
1044
1045 if (ret != 16) {
1046 return -1;
1047 }
1048#ifdef TARGET_I386
1049 smbios_add_field(1, offsetof(struct smbios_type_1, uuid), 16, uuid);
1050#endif
1051 return 0;
1052}
1053
1054void do_acpitable_option(const char *optarg)
1055{
1056#ifdef TARGET_I386
1057 if (acpi_table_add(optarg) < 0) {
1058 fprintf(stderr, "Wrong acpi table provided\n");
1059 exit(1);
1060 }
1061#endif
1062}
1063
1064void do_smbios_option(const char *optarg)
1065{
1066#ifdef TARGET_I386
1067 if (smbios_entry_add(optarg) < 0) {
1068 fprintf(stderr, "Wrong smbios provided\n");
1069 exit(1);
1070 }
1071#endif
1072}
1073
1074void cpudef_init(void)
1075{
1076#if defined(cpudef_setup)
1077 cpudef_setup(); /* parse cpu definitions in target config file */
1078#endif
1079}
1080
1081int audio_available(void)
1082{
1083#ifdef HAS_AUDIO
1084 return 1;
1085#else
1086 return 0;
1087#endif
1088}
1089
Anthony PERARD303d4e82010-09-21 20:05:31 +01001090int tcg_available(void)
1091{
1092 return 1;
1093}
1094
Blue Swirlad960902010-03-29 19:23:52 +00001095int kvm_available(void)
1096{
1097#ifdef CONFIG_KVM
1098 return 1;
1099#else
1100 return 0;
1101#endif
1102}
1103
1104int xen_available(void)
1105{
1106#ifdef CONFIG_XEN
1107 return 1;
1108#else
1109 return 0;
1110#endif
1111}
Daniel P. Berrange99afc912012-08-20 15:31:38 +01001112
1113
1114TargetInfo *qmp_query_target(Error **errp)
1115{
1116 TargetInfo *info = g_malloc0(sizeof(*info));
1117
1118 info->arch = TARGET_TYPE;
1119
1120 return info;
1121}