Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 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> |
Michael S. Tsirkin | b2e0a13 | 2010-11-22 19:52:34 +0200 | [diff] [blame] | 26 | #include <stdlib.h> |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 27 | #ifndef _WIN32 |
Blue Swirl | 1c47cb1 | 2010-03-30 19:27:34 +0000 | [diff] [blame] | 28 | #include <sys/types.h> |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 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" |
Avi Kivity | 86e775c | 2011-12-15 16:24:49 +0200 | [diff] [blame] | 44 | #include "exec-memory.h" |
Jan Kiszka | 302fe51 | 2012-02-17 11:24:34 +0100 | [diff] [blame] | 45 | #include "hw/pcspk.h" |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 46 | |
Orit Wasserman | 3a697f6 | 2012-06-19 18:43:15 +0300 | [diff] [blame] | 47 | #ifdef DEBUG_ARCH_INIT |
| 48 | #define DPRINTF(fmt, ...) \ |
| 49 | do { fprintf(stdout, "arch_init: " fmt, ## __VA_ARGS__); } while (0) |
| 50 | #else |
| 51 | #define DPRINTF(fmt, ...) \ |
| 52 | do { } while (0) |
| 53 | #endif |
| 54 | |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 55 | #ifdef TARGET_SPARC |
| 56 | int graphic_width = 1024; |
| 57 | int graphic_height = 768; |
| 58 | int graphic_depth = 8; |
| 59 | #else |
| 60 | int graphic_width = 800; |
| 61 | int graphic_height = 600; |
| 62 | int graphic_depth = 15; |
| 63 | #endif |
| 64 | |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 65 | |
| 66 | #if defined(TARGET_ALPHA) |
| 67 | #define QEMU_ARCH QEMU_ARCH_ALPHA |
| 68 | #elif defined(TARGET_ARM) |
| 69 | #define QEMU_ARCH QEMU_ARCH_ARM |
| 70 | #elif defined(TARGET_CRIS) |
| 71 | #define QEMU_ARCH QEMU_ARCH_CRIS |
| 72 | #elif defined(TARGET_I386) |
| 73 | #define QEMU_ARCH QEMU_ARCH_I386 |
| 74 | #elif defined(TARGET_M68K) |
| 75 | #define QEMU_ARCH QEMU_ARCH_M68K |
Michael Walle | 81ea0e1 | 2011-02-17 23:45:02 +0100 | [diff] [blame] | 76 | #elif defined(TARGET_LM32) |
| 77 | #define QEMU_ARCH QEMU_ARCH_LM32 |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 78 | #elif defined(TARGET_MICROBLAZE) |
| 79 | #define QEMU_ARCH QEMU_ARCH_MICROBLAZE |
| 80 | #elif defined(TARGET_MIPS) |
| 81 | #define QEMU_ARCH QEMU_ARCH_MIPS |
| 82 | #elif defined(TARGET_PPC) |
| 83 | #define QEMU_ARCH QEMU_ARCH_PPC |
| 84 | #elif defined(TARGET_S390X) |
| 85 | #define QEMU_ARCH QEMU_ARCH_S390X |
| 86 | #elif defined(TARGET_SH4) |
| 87 | #define QEMU_ARCH QEMU_ARCH_SH4 |
| 88 | #elif defined(TARGET_SPARC) |
| 89 | #define QEMU_ARCH QEMU_ARCH_SPARC |
Max Filippov | 2328826 | 2011-09-06 03:55:25 +0400 | [diff] [blame] | 90 | #elif defined(TARGET_XTENSA) |
| 91 | #define QEMU_ARCH QEMU_ARCH_XTENSA |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 92 | #endif |
| 93 | |
| 94 | const uint32_t arch_type = QEMU_ARCH; |
| 95 | |
| 96 | /***********************************************************/ |
| 97 | /* ram save/restore */ |
| 98 | |
Yoshiaki Tamura | d20878d | 2010-08-18 13:30:12 +0900 | [diff] [blame] | 99 | #define RAM_SAVE_FLAG_FULL 0x01 /* Obsolete, not used anymore */ |
| 100 | #define RAM_SAVE_FLAG_COMPRESS 0x02 |
| 101 | #define RAM_SAVE_FLAG_MEM_SIZE 0x04 |
| 102 | #define RAM_SAVE_FLAG_PAGE 0x08 |
| 103 | #define RAM_SAVE_FLAG_EOS 0x10 |
| 104 | #define RAM_SAVE_FLAG_CONTINUE 0x20 |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 105 | |
Paolo Bonzini | 8600361 | 2011-12-23 16:17:26 +0100 | [diff] [blame] | 106 | #ifdef __ALTIVEC__ |
| 107 | #include <altivec.h> |
| 108 | #define VECTYPE vector unsigned char |
| 109 | #define SPLAT(p) vec_splat(vec_ld(0, p), 0) |
| 110 | #define ALL_EQ(v1, v2) vec_all_eq(v1, v2) |
Andreas Färber | f283edc | 2012-05-27 16:21:02 +0200 | [diff] [blame] | 111 | /* altivec.h may redefine the bool macro as vector type. |
| 112 | * Reset it to POSIX semantics. */ |
| 113 | #undef bool |
| 114 | #define bool _Bool |
Paolo Bonzini | 8600361 | 2011-12-23 16:17:26 +0100 | [diff] [blame] | 115 | #elif defined __SSE2__ |
| 116 | #include <emmintrin.h> |
| 117 | #define VECTYPE __m128i |
| 118 | #define SPLAT(p) _mm_set1_epi8(*(p)) |
| 119 | #define ALL_EQ(v1, v2) (_mm_movemask_epi8(_mm_cmpeq_epi8(v1, v2)) == 0xFFFF) |
| 120 | #else |
| 121 | #define VECTYPE unsigned long |
| 122 | #define SPLAT(p) (*(p) * (~0UL / 255)) |
| 123 | #define ALL_EQ(v1, v2) ((v1) == (v2)) |
| 124 | #endif |
| 125 | |
Eduardo Habkost | b5a8fe5 | 2012-05-02 13:07:25 -0300 | [diff] [blame] | 126 | |
Eduardo Habkost | 756557d | 2012-05-02 13:07:27 -0300 | [diff] [blame] | 127 | static struct defconfig_file { |
| 128 | const char *filename; |
Eduardo Habkost | f29a561 | 2012-05-02 13:07:29 -0300 | [diff] [blame] | 129 | /* Indicates it is an user config file (disabled by -no-user-config) */ |
| 130 | bool userconfig; |
Eduardo Habkost | 756557d | 2012-05-02 13:07:27 -0300 | [diff] [blame] | 131 | } default_config_files[] = { |
Eduardo Habkost | e2d87bf | 2012-05-02 13:07:30 -0300 | [diff] [blame] | 132 | { CONFIG_QEMU_DATADIR "/cpus-" TARGET_ARCH ".conf", false }, |
Eduardo Habkost | f29a561 | 2012-05-02 13:07:29 -0300 | [diff] [blame] | 133 | { CONFIG_QEMU_CONFDIR "/qemu.conf", true }, |
| 134 | { CONFIG_QEMU_CONFDIR "/target-" TARGET_ARCH ".conf", true }, |
Eduardo Habkost | 756557d | 2012-05-02 13:07:27 -0300 | [diff] [blame] | 135 | { NULL }, /* end of list */ |
| 136 | }; |
| 137 | |
| 138 | |
Eduardo Habkost | f29a561 | 2012-05-02 13:07:29 -0300 | [diff] [blame] | 139 | int qemu_read_default_config_files(bool userconfig) |
Eduardo Habkost | b5a8fe5 | 2012-05-02 13:07:25 -0300 | [diff] [blame] | 140 | { |
| 141 | int ret; |
Eduardo Habkost | 756557d | 2012-05-02 13:07:27 -0300 | [diff] [blame] | 142 | struct defconfig_file *f; |
| 143 | |
| 144 | for (f = default_config_files; f->filename; f++) { |
Eduardo Habkost | f29a561 | 2012-05-02 13:07:29 -0300 | [diff] [blame] | 145 | if (!userconfig && f->userconfig) { |
| 146 | continue; |
| 147 | } |
Eduardo Habkost | 756557d | 2012-05-02 13:07:27 -0300 | [diff] [blame] | 148 | ret = qemu_read_config_file(f->filename); |
| 149 | if (ret < 0 && ret != -ENOENT) { |
| 150 | return ret; |
| 151 | } |
| 152 | } |
Eduardo Habkost | b5a8fe5 | 2012-05-02 13:07:25 -0300 | [diff] [blame] | 153 | |
Eduardo Habkost | b5a8fe5 | 2012-05-02 13:07:25 -0300 | [diff] [blame] | 154 | return 0; |
| 155 | } |
| 156 | |
Paolo Bonzini | 8600361 | 2011-12-23 16:17:26 +0100 | [diff] [blame] | 157 | static int is_dup_page(uint8_t *page) |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 158 | { |
Paolo Bonzini | 8600361 | 2011-12-23 16:17:26 +0100 | [diff] [blame] | 159 | VECTYPE *p = (VECTYPE *)page; |
| 160 | VECTYPE val = SPLAT(page); |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 161 | int i; |
| 162 | |
Paolo Bonzini | 8600361 | 2011-12-23 16:17:26 +0100 | [diff] [blame] | 163 | for (i = 0; i < TARGET_PAGE_SIZE / sizeof(VECTYPE); i++) { |
| 164 | if (!ALL_EQ(val, p[i])) { |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 165 | return 0; |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | return 1; |
| 170 | } |
| 171 | |
Orit Wasserman | 0c51f43 | 2012-06-19 18:43:14 +0300 | [diff] [blame] | 172 | static void save_block_hdr(QEMUFile *f, RAMBlock *block, ram_addr_t offset, |
| 173 | int cont, int flag) |
| 174 | { |
| 175 | qemu_put_be64(f, offset | cont | flag); |
| 176 | if (!cont) { |
| 177 | qemu_put_byte(f, strlen(block->idstr)); |
| 178 | qemu_put_buffer(f, (uint8_t *)block->idstr, |
| 179 | strlen(block->idstr)); |
| 180 | } |
| 181 | |
| 182 | } |
| 183 | |
Alex Williamson | 760e77e | 2010-08-19 10:18:42 -0300 | [diff] [blame] | 184 | static RAMBlock *last_block; |
| 185 | static ram_addr_t last_offset; |
| 186 | |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 187 | static int ram_save_block(QEMUFile *f) |
| 188 | { |
Alex Williamson | e44359c | 2010-06-25 11:09:57 -0600 | [diff] [blame] | 189 | RAMBlock *block = last_block; |
| 190 | ram_addr_t offset = last_offset; |
Pierre Riteau | 3fc250b | 2010-05-12 15:12:44 +0200 | [diff] [blame] | 191 | int bytes_sent = 0; |
Avi Kivity | 71c510e | 2011-12-21 13:11:22 +0200 | [diff] [blame] | 192 | MemoryRegion *mr; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 193 | |
Alex Williamson | e44359c | 2010-06-25 11:09:57 -0600 | [diff] [blame] | 194 | if (!block) |
| 195 | block = QLIST_FIRST(&ram_list.blocks); |
| 196 | |
Alex Williamson | e44359c | 2010-06-25 11:09:57 -0600 | [diff] [blame] | 197 | do { |
Avi Kivity | 71c510e | 2011-12-21 13:11:22 +0200 | [diff] [blame] | 198 | mr = block->mr; |
Blue Swirl | cd7a45c | 2012-01-22 16:38:21 +0000 | [diff] [blame] | 199 | if (memory_region_get_dirty(mr, offset, TARGET_PAGE_SIZE, |
| 200 | DIRTY_MEMORY_MIGRATION)) { |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 201 | uint8_t *p; |
Alex Williamson | a55bbe3 | 2010-06-25 11:10:05 -0600 | [diff] [blame] | 202 | int cont = (block == last_block) ? RAM_SAVE_FLAG_CONTINUE : 0; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 203 | |
Avi Kivity | 71c510e | 2011-12-21 13:11:22 +0200 | [diff] [blame] | 204 | memory_region_reset_dirty(mr, offset, TARGET_PAGE_SIZE, |
| 205 | DIRTY_MEMORY_MIGRATION); |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 206 | |
Avi Kivity | 71c510e | 2011-12-21 13:11:22 +0200 | [diff] [blame] | 207 | p = memory_region_get_ram_ptr(mr) + offset; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 208 | |
Paolo Bonzini | 8600361 | 2011-12-23 16:17:26 +0100 | [diff] [blame] | 209 | if (is_dup_page(p)) { |
Orit Wasserman | 0c51f43 | 2012-06-19 18:43:14 +0300 | [diff] [blame] | 210 | save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_COMPRESS); |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 211 | qemu_put_byte(f, *p); |
Pierre Riteau | 3fc250b | 2010-05-12 15:12:44 +0200 | [diff] [blame] | 212 | bytes_sent = 1; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 213 | } else { |
Orit Wasserman | 0c51f43 | 2012-06-19 18:43:14 +0300 | [diff] [blame] | 214 | save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_PAGE); |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 215 | qemu_put_buffer(f, p, TARGET_PAGE_SIZE); |
Pierre Riteau | 3fc250b | 2010-05-12 15:12:44 +0200 | [diff] [blame] | 216 | bytes_sent = TARGET_PAGE_SIZE; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 217 | } |
| 218 | |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 219 | break; |
| 220 | } |
Alex Williamson | e44359c | 2010-06-25 11:09:57 -0600 | [diff] [blame] | 221 | |
| 222 | offset += TARGET_PAGE_SIZE; |
| 223 | if (offset >= block->length) { |
| 224 | offset = 0; |
| 225 | block = QLIST_NEXT(block, next); |
| 226 | if (!block) |
| 227 | block = QLIST_FIRST(&ram_list.blocks); |
| 228 | } |
Avi Kivity | 71c510e | 2011-12-21 13:11:22 +0200 | [diff] [blame] | 229 | } while (block != last_block || offset != last_offset); |
Alex Williamson | e44359c | 2010-06-25 11:09:57 -0600 | [diff] [blame] | 230 | |
| 231 | last_block = block; |
| 232 | last_offset = offset; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 233 | |
Pierre Riteau | 3fc250b | 2010-05-12 15:12:44 +0200 | [diff] [blame] | 234 | return bytes_sent; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | static uint64_t bytes_transferred; |
| 238 | |
| 239 | static ram_addr_t ram_save_remaining(void) |
| 240 | { |
Juan Quintela | 45f33f0 | 2012-06-22 15:21:07 +0200 | [diff] [blame] | 241 | return ram_list.dirty_pages; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | uint64_t ram_bytes_remaining(void) |
| 245 | { |
| 246 | return ram_save_remaining() * TARGET_PAGE_SIZE; |
| 247 | } |
| 248 | |
| 249 | uint64_t ram_bytes_transferred(void) |
| 250 | { |
| 251 | return bytes_transferred; |
| 252 | } |
| 253 | |
| 254 | uint64_t ram_bytes_total(void) |
| 255 | { |
Alex Williamson | d17b528 | 2010-06-25 11:08:38 -0600 | [diff] [blame] | 256 | RAMBlock *block; |
| 257 | uint64_t total = 0; |
| 258 | |
| 259 | QLIST_FOREACH(block, &ram_list.blocks, next) |
| 260 | total += block->length; |
| 261 | |
| 262 | return total; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 263 | } |
| 264 | |
Michael S. Tsirkin | b2e0a13 | 2010-11-22 19:52:34 +0200 | [diff] [blame] | 265 | static int block_compar(const void *a, const void *b) |
| 266 | { |
| 267 | RAMBlock * const *ablock = a; |
| 268 | RAMBlock * const *bblock = b; |
Avi Kivity | 8fec98b | 2011-12-21 13:22:16 +0200 | [diff] [blame] | 269 | |
| 270 | return strcmp((*ablock)->idstr, (*bblock)->idstr); |
Michael S. Tsirkin | b2e0a13 | 2010-11-22 19:52:34 +0200 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | static void sort_ram_list(void) |
| 274 | { |
| 275 | RAMBlock *block, *nblock, **blocks; |
| 276 | int n; |
| 277 | n = 0; |
| 278 | QLIST_FOREACH(block, &ram_list.blocks, next) { |
| 279 | ++n; |
| 280 | } |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 281 | blocks = g_malloc(n * sizeof *blocks); |
Michael S. Tsirkin | b2e0a13 | 2010-11-22 19:52:34 +0200 | [diff] [blame] | 282 | n = 0; |
| 283 | QLIST_FOREACH_SAFE(block, &ram_list.blocks, next, nblock) { |
| 284 | blocks[n++] = block; |
| 285 | QLIST_REMOVE(block, next); |
| 286 | } |
| 287 | qsort(blocks, n, sizeof *blocks, block_compar); |
| 288 | while (--n >= 0) { |
| 289 | QLIST_INSERT_HEAD(&ram_list.blocks, blocks[n], next); |
| 290 | } |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 291 | g_free(blocks); |
Michael S. Tsirkin | b2e0a13 | 2010-11-22 19:52:34 +0200 | [diff] [blame] | 292 | } |
| 293 | |
Orit Wasserman | 8e21cd3 | 2012-06-19 18:43:17 +0300 | [diff] [blame] | 294 | static void migration_end(void) |
| 295 | { |
| 296 | memory_global_dirty_log_stop(); |
| 297 | } |
| 298 | |
Juan Quintela | 9b5bfab | 2012-06-26 19:26:41 +0200 | [diff] [blame] | 299 | static void ram_migration_cancel(void *opaque) |
| 300 | { |
| 301 | migration_end(); |
| 302 | } |
| 303 | |
Juan Quintela | 4508bd9 | 2012-05-22 16:27:59 +0200 | [diff] [blame] | 304 | #define MAX_WAIT 50 /* ms, half buffered_file limit */ |
| 305 | |
Juan Quintela | d1315aa | 2012-06-28 15:11:57 +0200 | [diff] [blame] | 306 | static int ram_save_setup(QEMUFile *f, void *opaque) |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 307 | { |
| 308 | ram_addr_t addr; |
Juan Quintela | d1315aa | 2012-06-28 15:11:57 +0200 | [diff] [blame] | 309 | RAMBlock *block; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 310 | double bwidth = 0; |
Juan Quintela | 2975725 | 2011-10-19 15:22:18 +0200 | [diff] [blame] | 311 | int ret; |
Juan Quintela | 4508bd9 | 2012-05-22 16:27:59 +0200 | [diff] [blame] | 312 | int i; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 313 | |
Avi Kivity | 86e775c | 2011-12-15 16:24:49 +0200 | [diff] [blame] | 314 | memory_global_sync_dirty_bitmap(get_system_memory()); |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 315 | |
Juan Quintela | d1315aa | 2012-06-28 15:11:57 +0200 | [diff] [blame] | 316 | bytes_transferred = 0; |
| 317 | last_block = NULL; |
| 318 | last_offset = 0; |
| 319 | sort_ram_list(); |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 320 | |
Juan Quintela | d1315aa | 2012-06-28 15:11:57 +0200 | [diff] [blame] | 321 | /* Make sure all dirty bits are set */ |
| 322 | QLIST_FOREACH(block, &ram_list.blocks, next) { |
| 323 | for (addr = 0; addr < block->length; addr += TARGET_PAGE_SIZE) { |
| 324 | if (!memory_region_get_dirty(block->mr, addr, TARGET_PAGE_SIZE, |
| 325 | DIRTY_MEMORY_MIGRATION)) { |
| 326 | memory_region_set_dirty(block->mr, addr, TARGET_PAGE_SIZE); |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 327 | } |
| 328 | } |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 329 | } |
| 330 | |
Juan Quintela | d1315aa | 2012-06-28 15:11:57 +0200 | [diff] [blame] | 331 | memory_global_dirty_log_start(); |
| 332 | |
| 333 | qemu_put_be64(f, ram_bytes_total() | RAM_SAVE_FLAG_MEM_SIZE); |
| 334 | |
| 335 | QLIST_FOREACH(block, &ram_list.blocks, next) { |
| 336 | qemu_put_byte(f, strlen(block->idstr)); |
| 337 | qemu_put_buffer(f, (uint8_t *)block->idstr, strlen(block->idstr)); |
| 338 | qemu_put_be64(f, block->length); |
| 339 | } |
| 340 | |
| 341 | bwidth = qemu_get_clock_ns(rt_clock); |
| 342 | |
| 343 | i = 0; |
| 344 | while ((ret = qemu_file_rate_limit(f)) == 0) { |
| 345 | int bytes_sent; |
| 346 | |
| 347 | bytes_sent = ram_save_block(f); |
| 348 | bytes_transferred += bytes_sent; |
| 349 | if (bytes_sent == 0) { /* no more blocks */ |
| 350 | break; |
| 351 | } |
| 352 | /* we want to check in the 1st loop, just in case it was the 1st time |
| 353 | and we had to sync the dirty bitmap. |
| 354 | qemu_get_clock_ns() is a bit expensive, so we only check each some |
| 355 | iterations |
| 356 | */ |
| 357 | if ((i & 63) == 0) { |
| 358 | uint64_t t1 = (qemu_get_clock_ns(rt_clock) - bwidth) / 1000000; |
| 359 | if (t1 > MAX_WAIT) { |
| 360 | DPRINTF("big wait: " PRIu64 " milliseconds, %d iterations\n", |
| 361 | t1, i); |
| 362 | break; |
| 363 | } |
| 364 | } |
| 365 | i++; |
| 366 | } |
| 367 | |
| 368 | if (ret < 0) { |
| 369 | return ret; |
| 370 | } |
| 371 | |
| 372 | qemu_put_be64(f, RAM_SAVE_FLAG_EOS); |
| 373 | |
| 374 | return 0; |
| 375 | } |
| 376 | |
Juan Quintela | 16310a3 | 2012-06-28 15:31:37 +0200 | [diff] [blame^] | 377 | static int ram_save_iterate(QEMUFile *f, void *opaque) |
Juan Quintela | d1315aa | 2012-06-28 15:11:57 +0200 | [diff] [blame] | 378 | { |
| 379 | uint64_t bytes_transferred_last; |
| 380 | double bwidth = 0; |
| 381 | int ret; |
| 382 | int i; |
Juan Quintela | 16310a3 | 2012-06-28 15:31:37 +0200 | [diff] [blame^] | 383 | uint64_t expected_time; |
Juan Quintela | d1315aa | 2012-06-28 15:11:57 +0200 | [diff] [blame] | 384 | |
| 385 | memory_global_sync_dirty_bitmap(get_system_memory()); |
| 386 | |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 387 | bytes_transferred_last = bytes_transferred; |
| 388 | bwidth = qemu_get_clock_ns(rt_clock); |
| 389 | |
Juan Quintela | 4508bd9 | 2012-05-22 16:27:59 +0200 | [diff] [blame] | 390 | i = 0; |
Juan Quintela | 2975725 | 2011-10-19 15:22:18 +0200 | [diff] [blame] | 391 | while ((ret = qemu_file_rate_limit(f)) == 0) { |
Pierre Riteau | 3fc250b | 2010-05-12 15:12:44 +0200 | [diff] [blame] | 392 | int bytes_sent; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 393 | |
Pierre Riteau | 3fc250b | 2010-05-12 15:12:44 +0200 | [diff] [blame] | 394 | bytes_sent = ram_save_block(f); |
| 395 | bytes_transferred += bytes_sent; |
| 396 | if (bytes_sent == 0) { /* no more blocks */ |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 397 | break; |
| 398 | } |
Juan Quintela | 4508bd9 | 2012-05-22 16:27:59 +0200 | [diff] [blame] | 399 | /* we want to check in the 1st loop, just in case it was the 1st time |
| 400 | and we had to sync the dirty bitmap. |
| 401 | qemu_get_clock_ns() is a bit expensive, so we only check each some |
| 402 | iterations |
| 403 | */ |
| 404 | if ((i & 63) == 0) { |
| 405 | uint64_t t1 = (qemu_get_clock_ns(rt_clock) - bwidth) / 1000000; |
| 406 | if (t1 > MAX_WAIT) { |
| 407 | DPRINTF("big wait: " PRIu64 " milliseconds, %d iterations\n", |
| 408 | t1, i); |
| 409 | break; |
| 410 | } |
| 411 | } |
| 412 | i++; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 413 | } |
| 414 | |
Juan Quintela | 2975725 | 2011-10-19 15:22:18 +0200 | [diff] [blame] | 415 | if (ret < 0) { |
| 416 | return ret; |
| 417 | } |
| 418 | |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 419 | bwidth = qemu_get_clock_ns(rt_clock) - bwidth; |
| 420 | bwidth = (bytes_transferred - bytes_transferred_last) / bwidth; |
| 421 | |
| 422 | /* if we haven't transferred anything this round, force expected_time to a |
| 423 | * a very high value, but without crashing */ |
| 424 | if (bwidth == 0) { |
| 425 | bwidth = 0.000001; |
| 426 | } |
| 427 | |
Juan Quintela | 16310a3 | 2012-06-28 15:31:37 +0200 | [diff] [blame^] | 428 | qemu_put_be64(f, RAM_SAVE_FLAG_EOS); |
Pierre Riteau | 3fc250b | 2010-05-12 15:12:44 +0200 | [diff] [blame] | 429 | |
Juan Quintela | 16310a3 | 2012-06-28 15:31:37 +0200 | [diff] [blame^] | 430 | expected_time = ram_save_remaining() * TARGET_PAGE_SIZE / bwidth; |
| 431 | |
| 432 | DPRINTF("ram_save_live: expected(" PRIu64 ") <= max(" PRIu64 ")?\n", |
| 433 | expected_time, migrate_max_downtime()); |
| 434 | |
| 435 | return expected_time <= migrate_max_downtime(); |
| 436 | } |
| 437 | |
| 438 | static int ram_save_complete(QEMUFile *f, void *opaque) |
| 439 | { |
| 440 | double bwidth = 0; |
| 441 | int ret; |
| 442 | int i; |
| 443 | int bytes_sent; |
| 444 | |
| 445 | memory_global_sync_dirty_bitmap(get_system_memory()); |
| 446 | |
| 447 | bwidth = qemu_get_clock_ns(rt_clock); |
| 448 | |
| 449 | i = 0; |
| 450 | while ((ret = qemu_file_rate_limit(f)) == 0) { |
| 451 | bytes_sent = ram_save_block(f); |
| 452 | bytes_transferred += bytes_sent; |
| 453 | if (bytes_sent == 0) { /* no more blocks */ |
| 454 | break; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 455 | } |
Juan Quintela | 16310a3 | 2012-06-28 15:31:37 +0200 | [diff] [blame^] | 456 | /* we want to check in the 1st loop, just in case it was the 1st time |
| 457 | and we had to sync the dirty bitmap. |
| 458 | qemu_get_clock_ns() is a bit expensive, so we only check each some |
| 459 | iterations |
| 460 | */ |
| 461 | if ((i & 63) == 0) { |
| 462 | uint64_t t1 = (qemu_get_clock_ns(rt_clock) - bwidth) / 1000000; |
| 463 | if (t1 > MAX_WAIT) { |
| 464 | DPRINTF("big wait: " PRIu64 " milliseconds, %d iterations\n", |
| 465 | t1, i); |
| 466 | break; |
| 467 | } |
| 468 | } |
| 469 | i++; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 470 | } |
| 471 | |
Juan Quintela | 16310a3 | 2012-06-28 15:31:37 +0200 | [diff] [blame^] | 472 | if (ret < 0) { |
| 473 | return ret; |
| 474 | } |
| 475 | |
| 476 | /* try transferring iterative blocks of memory */ |
| 477 | |
| 478 | /* flush all remaining blocks regardless of rate limiting */ |
| 479 | while ((bytes_sent = ram_save_block(f)) != 0) { |
| 480 | bytes_transferred += bytes_sent; |
| 481 | } |
| 482 | memory_global_dirty_log_stop(); |
| 483 | |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 484 | qemu_put_be64(f, RAM_SAVE_FLAG_EOS); |
| 485 | |
Juan Quintela | 5b3c963 | 2012-05-22 00:44:24 +0200 | [diff] [blame] | 486 | return 0; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 487 | } |
| 488 | |
Alex Williamson | a55bbe3 | 2010-06-25 11:10:05 -0600 | [diff] [blame] | 489 | static inline void *host_from_stream_offset(QEMUFile *f, |
| 490 | ram_addr_t offset, |
| 491 | int flags) |
| 492 | { |
| 493 | static RAMBlock *block = NULL; |
| 494 | char id[256]; |
| 495 | uint8_t len; |
| 496 | |
| 497 | if (flags & RAM_SAVE_FLAG_CONTINUE) { |
| 498 | if (!block) { |
| 499 | fprintf(stderr, "Ack, bad migration stream!\n"); |
| 500 | return NULL; |
| 501 | } |
| 502 | |
Avi Kivity | dc94a7e | 2011-12-21 13:54:33 +0200 | [diff] [blame] | 503 | return memory_region_get_ram_ptr(block->mr) + offset; |
Alex Williamson | a55bbe3 | 2010-06-25 11:10:05 -0600 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | len = qemu_get_byte(f); |
| 507 | qemu_get_buffer(f, (uint8_t *)id, len); |
| 508 | id[len] = 0; |
| 509 | |
| 510 | QLIST_FOREACH(block, &ram_list.blocks, next) { |
| 511 | if (!strncmp(id, block->idstr, sizeof(id))) |
Avi Kivity | dc94a7e | 2011-12-21 13:54:33 +0200 | [diff] [blame] | 512 | return memory_region_get_ram_ptr(block->mr) + offset; |
Alex Williamson | a55bbe3 | 2010-06-25 11:10:05 -0600 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | fprintf(stderr, "Can't find block %s!\n", id); |
| 516 | return NULL; |
| 517 | } |
| 518 | |
Juan Quintela | 7908c78 | 2012-06-26 18:46:10 +0200 | [diff] [blame] | 519 | static int ram_load(QEMUFile *f, void *opaque, int version_id) |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 520 | { |
| 521 | ram_addr_t addr; |
Orit Wasserman | 3a697f6 | 2012-06-19 18:43:15 +0300 | [diff] [blame] | 522 | int flags, ret = 0; |
Juan Quintela | 42802d4 | 2011-10-05 01:14:46 +0200 | [diff] [blame] | 523 | int error; |
Orit Wasserman | 3a697f6 | 2012-06-19 18:43:15 +0300 | [diff] [blame] | 524 | static uint64_t seq_iter; |
| 525 | |
| 526 | seq_iter++; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 527 | |
Avi Kivity | f09f218 | 2011-12-21 13:37:56 +0200 | [diff] [blame] | 528 | if (version_id < 4 || version_id > 4) { |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 529 | return -EINVAL; |
| 530 | } |
| 531 | |
| 532 | do { |
| 533 | addr = qemu_get_be64(f); |
| 534 | |
| 535 | flags = addr & ~TARGET_PAGE_MASK; |
| 536 | addr &= TARGET_PAGE_MASK; |
| 537 | |
| 538 | if (flags & RAM_SAVE_FLAG_MEM_SIZE) { |
Avi Kivity | f09f218 | 2011-12-21 13:37:56 +0200 | [diff] [blame] | 539 | if (version_id == 4) { |
Alex Williamson | 97ab12d | 2010-06-25 11:09:50 -0600 | [diff] [blame] | 540 | /* Synchronize RAM block list */ |
| 541 | char id[256]; |
| 542 | ram_addr_t length; |
| 543 | ram_addr_t total_ram_bytes = addr; |
| 544 | |
| 545 | while (total_ram_bytes) { |
| 546 | RAMBlock *block; |
| 547 | uint8_t len; |
| 548 | |
| 549 | len = qemu_get_byte(f); |
| 550 | qemu_get_buffer(f, (uint8_t *)id, len); |
| 551 | id[len] = 0; |
| 552 | length = qemu_get_be64(f); |
| 553 | |
| 554 | QLIST_FOREACH(block, &ram_list.blocks, next) { |
| 555 | if (!strncmp(id, block->idstr, sizeof(id))) { |
Orit Wasserman | 3a697f6 | 2012-06-19 18:43:15 +0300 | [diff] [blame] | 556 | if (block->length != length) { |
| 557 | ret = -EINVAL; |
| 558 | goto done; |
| 559 | } |
Alex Williamson | 97ab12d | 2010-06-25 11:09:50 -0600 | [diff] [blame] | 560 | break; |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | if (!block) { |
Alex Williamson | fb787f8 | 2010-07-02 11:13:29 -0600 | [diff] [blame] | 565 | fprintf(stderr, "Unknown ramblock \"%s\", cannot " |
| 566 | "accept migration\n", id); |
Orit Wasserman | 3a697f6 | 2012-06-19 18:43:15 +0300 | [diff] [blame] | 567 | ret = -EINVAL; |
| 568 | goto done; |
Alex Williamson | 97ab12d | 2010-06-25 11:09:50 -0600 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | total_ram_bytes -= length; |
| 572 | } |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 573 | } |
| 574 | } |
| 575 | |
| 576 | if (flags & RAM_SAVE_FLAG_COMPRESS) { |
Alex Williamson | 97ab12d | 2010-06-25 11:09:50 -0600 | [diff] [blame] | 577 | void *host; |
| 578 | uint8_t ch; |
| 579 | |
Avi Kivity | f09f218 | 2011-12-21 13:37:56 +0200 | [diff] [blame] | 580 | host = host_from_stream_offset(f, addr, flags); |
Michael S. Tsirkin | 492fb99 | 2010-10-17 20:43:40 +0200 | [diff] [blame] | 581 | if (!host) { |
| 582 | return -EINVAL; |
| 583 | } |
Alex Williamson | 97ab12d | 2010-06-25 11:09:50 -0600 | [diff] [blame] | 584 | |
Alex Williamson | 97ab12d | 2010-06-25 11:09:50 -0600 | [diff] [blame] | 585 | ch = qemu_get_byte(f); |
| 586 | memset(host, ch, TARGET_PAGE_SIZE); |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 587 | #ifndef _WIN32 |
| 588 | if (ch == 0 && |
| 589 | (!kvm_enabled() || kvm_has_sync_mmu())) { |
Andreas Färber | e78815a | 2010-09-25 11:26:05 +0000 | [diff] [blame] | 590 | qemu_madvise(host, TARGET_PAGE_SIZE, QEMU_MADV_DONTNEED); |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 591 | } |
| 592 | #endif |
| 593 | } else if (flags & RAM_SAVE_FLAG_PAGE) { |
Alex Williamson | 97ab12d | 2010-06-25 11:09:50 -0600 | [diff] [blame] | 594 | void *host; |
| 595 | |
Avi Kivity | f09f218 | 2011-12-21 13:37:56 +0200 | [diff] [blame] | 596 | host = host_from_stream_offset(f, addr, flags); |
Orit Wasserman | 0ff1f9f | 2012-06-19 11:51:37 +0300 | [diff] [blame] | 597 | if (!host) { |
| 598 | return -EINVAL; |
| 599 | } |
Alex Williamson | 97ab12d | 2010-06-25 11:09:50 -0600 | [diff] [blame] | 600 | |
Alex Williamson | 97ab12d | 2010-06-25 11:09:50 -0600 | [diff] [blame] | 601 | qemu_get_buffer(f, host, TARGET_PAGE_SIZE); |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 602 | } |
Juan Quintela | 42802d4 | 2011-10-05 01:14:46 +0200 | [diff] [blame] | 603 | error = qemu_file_get_error(f); |
| 604 | if (error) { |
Orit Wasserman | 3a697f6 | 2012-06-19 18:43:15 +0300 | [diff] [blame] | 605 | ret = error; |
| 606 | goto done; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 607 | } |
| 608 | } while (!(flags & RAM_SAVE_FLAG_EOS)); |
| 609 | |
Orit Wasserman | 3a697f6 | 2012-06-19 18:43:15 +0300 | [diff] [blame] | 610 | done: |
| 611 | DPRINTF("Completed load of VM with exit code %d seq iteration " PRIu64 "\n", |
| 612 | ret, seq_iter); |
| 613 | return ret; |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 614 | } |
| 615 | |
Juan Quintela | 7908c78 | 2012-06-26 18:46:10 +0200 | [diff] [blame] | 616 | SaveVMHandlers savevm_ram_handlers = { |
Juan Quintela | d1315aa | 2012-06-28 15:11:57 +0200 | [diff] [blame] | 617 | .save_live_setup = ram_save_setup, |
Juan Quintela | 16310a3 | 2012-06-28 15:31:37 +0200 | [diff] [blame^] | 618 | .save_live_iterate = ram_save_iterate, |
| 619 | .save_live_complete = ram_save_complete, |
Juan Quintela | 7908c78 | 2012-06-26 18:46:10 +0200 | [diff] [blame] | 620 | .load_state = ram_load, |
Juan Quintela | 9b5bfab | 2012-06-26 19:26:41 +0200 | [diff] [blame] | 621 | .cancel = ram_migration_cancel, |
Juan Quintela | 7908c78 | 2012-06-26 18:46:10 +0200 | [diff] [blame] | 622 | }; |
| 623 | |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 624 | #ifdef HAS_AUDIO |
Isaku Yamahata | 0dfa5ef | 2011-01-21 19:53:45 +0900 | [diff] [blame] | 625 | struct soundhw { |
| 626 | const char *name; |
| 627 | const char *descr; |
| 628 | int enabled; |
| 629 | int isa; |
| 630 | union { |
Hervé Poussineau | 4a0f031 | 2011-12-15 22:10:01 +0100 | [diff] [blame] | 631 | int (*init_isa) (ISABus *bus); |
Isaku Yamahata | 0dfa5ef | 2011-01-21 19:53:45 +0900 | [diff] [blame] | 632 | int (*init_pci) (PCIBus *bus); |
| 633 | } init; |
| 634 | }; |
| 635 | |
| 636 | static struct soundhw soundhw[] = { |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 637 | #ifdef HAS_AUDIO_CHOICE |
Hervé Poussineau | da12872 | 2012-04-14 22:51:33 +0200 | [diff] [blame] | 638 | #ifdef CONFIG_PCSPK |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 639 | { |
| 640 | "pcspk", |
| 641 | "PC speaker", |
| 642 | 0, |
| 643 | 1, |
| 644 | { .init_isa = pcspk_audio_init } |
| 645 | }, |
| 646 | #endif |
| 647 | |
| 648 | #ifdef CONFIG_SB16 |
| 649 | { |
| 650 | "sb16", |
| 651 | "Creative Sound Blaster 16", |
| 652 | 0, |
| 653 | 1, |
| 654 | { .init_isa = SB16_init } |
| 655 | }, |
| 656 | #endif |
| 657 | |
| 658 | #ifdef CONFIG_CS4231A |
| 659 | { |
| 660 | "cs4231a", |
| 661 | "CS4231A", |
| 662 | 0, |
| 663 | 1, |
| 664 | { .init_isa = cs4231a_init } |
| 665 | }, |
| 666 | #endif |
| 667 | |
| 668 | #ifdef CONFIG_ADLIB |
| 669 | { |
| 670 | "adlib", |
| 671 | #ifdef HAS_YMF262 |
| 672 | "Yamaha YMF262 (OPL3)", |
| 673 | #else |
| 674 | "Yamaha YM3812 (OPL2)", |
| 675 | #endif |
| 676 | 0, |
| 677 | 1, |
| 678 | { .init_isa = Adlib_init } |
| 679 | }, |
| 680 | #endif |
| 681 | |
| 682 | #ifdef CONFIG_GUS |
| 683 | { |
| 684 | "gus", |
| 685 | "Gravis Ultrasound GF1", |
| 686 | 0, |
| 687 | 1, |
| 688 | { .init_isa = GUS_init } |
| 689 | }, |
| 690 | #endif |
| 691 | |
| 692 | #ifdef CONFIG_AC97 |
| 693 | { |
| 694 | "ac97", |
| 695 | "Intel 82801AA AC97 Audio", |
| 696 | 0, |
| 697 | 0, |
| 698 | { .init_pci = ac97_init } |
| 699 | }, |
| 700 | #endif |
| 701 | |
| 702 | #ifdef CONFIG_ES1370 |
| 703 | { |
| 704 | "es1370", |
| 705 | "ENSONIQ AudioPCI ES1370", |
| 706 | 0, |
| 707 | 0, |
| 708 | { .init_pci = es1370_init } |
| 709 | }, |
| 710 | #endif |
| 711 | |
Gerd Hoffmann | d61a4ce | 2010-11-01 13:05:32 +0100 | [diff] [blame] | 712 | #ifdef CONFIG_HDA |
| 713 | { |
| 714 | "hda", |
| 715 | "Intel HD Audio", |
| 716 | 0, |
| 717 | 0, |
| 718 | { .init_pci = intel_hda_and_codec_init } |
| 719 | }, |
| 720 | #endif |
| 721 | |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 722 | #endif /* HAS_AUDIO_CHOICE */ |
| 723 | |
| 724 | { NULL, NULL, 0, 0, { NULL } } |
| 725 | }; |
| 726 | |
| 727 | void select_soundhw(const char *optarg) |
| 728 | { |
| 729 | struct soundhw *c; |
| 730 | |
| 731 | if (*optarg == '?') { |
| 732 | show_valid_cards: |
| 733 | |
| 734 | printf("Valid sound card names (comma separated):\n"); |
| 735 | for (c = soundhw; c->name; ++c) { |
| 736 | printf ("%-11s %s\n", c->name, c->descr); |
| 737 | } |
| 738 | printf("\n-soundhw all will enable all of the above\n"); |
| 739 | exit(*optarg != '?'); |
| 740 | } |
| 741 | else { |
| 742 | size_t l; |
| 743 | const char *p; |
| 744 | char *e; |
| 745 | int bad_card = 0; |
| 746 | |
| 747 | if (!strcmp(optarg, "all")) { |
| 748 | for (c = soundhw; c->name; ++c) { |
| 749 | c->enabled = 1; |
| 750 | } |
| 751 | return; |
| 752 | } |
| 753 | |
| 754 | p = optarg; |
| 755 | while (*p) { |
| 756 | e = strchr(p, ','); |
| 757 | l = !e ? strlen(p) : (size_t) (e - p); |
| 758 | |
| 759 | for (c = soundhw; c->name; ++c) { |
| 760 | if (!strncmp(c->name, p, l) && !c->name[l]) { |
| 761 | c->enabled = 1; |
| 762 | break; |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | if (!c->name) { |
| 767 | if (l > 80) { |
| 768 | fprintf(stderr, |
| 769 | "Unknown sound card name (too big to show)\n"); |
| 770 | } |
| 771 | else { |
| 772 | fprintf(stderr, "Unknown sound card name `%.*s'\n", |
| 773 | (int) l, p); |
| 774 | } |
| 775 | bad_card = 1; |
| 776 | } |
| 777 | p += l + (e != NULL); |
| 778 | } |
| 779 | |
| 780 | if (bad_card) { |
| 781 | goto show_valid_cards; |
| 782 | } |
| 783 | } |
| 784 | } |
Isaku Yamahata | 0dfa5ef | 2011-01-21 19:53:45 +0900 | [diff] [blame] | 785 | |
Hervé Poussineau | 4a0f031 | 2011-12-15 22:10:01 +0100 | [diff] [blame] | 786 | void audio_init(ISABus *isa_bus, PCIBus *pci_bus) |
Isaku Yamahata | 0dfa5ef | 2011-01-21 19:53:45 +0900 | [diff] [blame] | 787 | { |
| 788 | struct soundhw *c; |
| 789 | |
| 790 | for (c = soundhw; c->name; ++c) { |
| 791 | if (c->enabled) { |
| 792 | if (c->isa) { |
Hervé Poussineau | 4a0f031 | 2011-12-15 22:10:01 +0100 | [diff] [blame] | 793 | if (isa_bus) { |
| 794 | c->init.init_isa(isa_bus); |
Isaku Yamahata | 0dfa5ef | 2011-01-21 19:53:45 +0900 | [diff] [blame] | 795 | } |
| 796 | } else { |
| 797 | if (pci_bus) { |
| 798 | c->init.init_pci(pci_bus); |
| 799 | } |
| 800 | } |
| 801 | } |
| 802 | } |
| 803 | } |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 804 | #else |
| 805 | void select_soundhw(const char *optarg) |
| 806 | { |
| 807 | } |
Hervé Poussineau | 4a0f031 | 2011-12-15 22:10:01 +0100 | [diff] [blame] | 808 | void audio_init(ISABus *isa_bus, PCIBus *pci_bus) |
Isaku Yamahata | 0dfa5ef | 2011-01-21 19:53:45 +0900 | [diff] [blame] | 809 | { |
| 810 | } |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 811 | #endif |
| 812 | |
| 813 | int qemu_uuid_parse(const char *str, uint8_t *uuid) |
| 814 | { |
| 815 | int ret; |
| 816 | |
| 817 | if (strlen(str) != 36) { |
| 818 | return -1; |
| 819 | } |
| 820 | |
| 821 | ret = sscanf(str, UUID_FMT, &uuid[0], &uuid[1], &uuid[2], &uuid[3], |
| 822 | &uuid[4], &uuid[5], &uuid[6], &uuid[7], &uuid[8], &uuid[9], |
| 823 | &uuid[10], &uuid[11], &uuid[12], &uuid[13], &uuid[14], |
| 824 | &uuid[15]); |
| 825 | |
| 826 | if (ret != 16) { |
| 827 | return -1; |
| 828 | } |
| 829 | #ifdef TARGET_I386 |
| 830 | smbios_add_field(1, offsetof(struct smbios_type_1, uuid), 16, uuid); |
| 831 | #endif |
| 832 | return 0; |
| 833 | } |
| 834 | |
| 835 | void do_acpitable_option(const char *optarg) |
| 836 | { |
| 837 | #ifdef TARGET_I386 |
| 838 | if (acpi_table_add(optarg) < 0) { |
| 839 | fprintf(stderr, "Wrong acpi table provided\n"); |
| 840 | exit(1); |
| 841 | } |
| 842 | #endif |
| 843 | } |
| 844 | |
| 845 | void do_smbios_option(const char *optarg) |
| 846 | { |
| 847 | #ifdef TARGET_I386 |
| 848 | if (smbios_entry_add(optarg) < 0) { |
| 849 | fprintf(stderr, "Wrong smbios provided\n"); |
| 850 | exit(1); |
| 851 | } |
| 852 | #endif |
| 853 | } |
| 854 | |
| 855 | void cpudef_init(void) |
| 856 | { |
| 857 | #if defined(cpudef_setup) |
| 858 | cpudef_setup(); /* parse cpu definitions in target config file */ |
| 859 | #endif |
| 860 | } |
| 861 | |
| 862 | int audio_available(void) |
| 863 | { |
| 864 | #ifdef HAS_AUDIO |
| 865 | return 1; |
| 866 | #else |
| 867 | return 0; |
| 868 | #endif |
| 869 | } |
| 870 | |
Anthony PERARD | 303d4e8 | 2010-09-21 20:05:31 +0100 | [diff] [blame] | 871 | int tcg_available(void) |
| 872 | { |
| 873 | return 1; |
| 874 | } |
| 875 | |
Blue Swirl | ad96090 | 2010-03-29 19:23:52 +0000 | [diff] [blame] | 876 | int kvm_available(void) |
| 877 | { |
| 878 | #ifdef CONFIG_KVM |
| 879 | return 1; |
| 880 | #else |
| 881 | return 0; |
| 882 | #endif |
| 883 | } |
| 884 | |
| 885 | int xen_available(void) |
| 886 | { |
| 887 | #ifdef CONFIG_XEN |
| 888 | return 1; |
| 889 | #else |
| 890 | return 0; |
| 891 | #endif |
| 892 | } |