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