]>
Commit | Line | Data |
---|---|---|
ad96090a BS |
1 | /* |
2 | * QEMU System Emulator | |
3 | * | |
4 | * Copyright (c) 2003-2008 Fabrice Bellard | |
5 | * | |
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
7 | * of this software and associated documentation files (the "Software"), to deal | |
8 | * in the Software without restriction, including without limitation the rights | |
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
10 | * copies of the Software, and to permit persons to whom the Software is | |
11 | * furnished to do so, subject to the following conditions: | |
12 | * | |
13 | * The above copyright notice and this permission notice shall be included in | |
14 | * all copies or substantial portions of the Software. | |
15 | * | |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
22 | * THE SOFTWARE. | |
23 | */ | |
24 | #include <stdint.h> | |
25 | #include <stdarg.h> | |
b2e0a138 | 26 | #include <stdlib.h> |
ad96090a | 27 | #ifndef _WIN32 |
1c47cb16 | 28 | #include <sys/types.h> |
ad96090a BS |
29 | #include <sys/mman.h> |
30 | #endif | |
31 | #include "config.h" | |
32 | #include "monitor.h" | |
33 | #include "sysemu.h" | |
34 | #include "arch_init.h" | |
35 | #include "audio/audio.h" | |
36 | #include "hw/pc.h" | |
37 | #include "hw/pci.h" | |
38 | #include "hw/audiodev.h" | |
39 | #include "kvm.h" | |
40 | #include "migration.h" | |
41 | #include "net.h" | |
42 | #include "gdbstub.h" | |
43 | #include "hw/smbios.h" | |
86e775c6 | 44 | #include "exec-memory.h" |
302fe51b | 45 | #include "hw/pcspk.h" |
ad96090a BS |
46 | |
47 | #ifdef TARGET_SPARC | |
48 | int graphic_width = 1024; | |
49 | int graphic_height = 768; | |
50 | int graphic_depth = 8; | |
51 | #else | |
52 | int graphic_width = 800; | |
53 | int graphic_height = 600; | |
54 | int graphic_depth = 15; | |
55 | #endif | |
56 | ||
57 | const char arch_config_name[] = CONFIG_QEMU_CONFDIR "/target-" TARGET_ARCH ".conf"; | |
58 | ||
59 | #if defined(TARGET_ALPHA) | |
60 | #define QEMU_ARCH QEMU_ARCH_ALPHA | |
61 | #elif defined(TARGET_ARM) | |
62 | #define QEMU_ARCH QEMU_ARCH_ARM | |
63 | #elif defined(TARGET_CRIS) | |
64 | #define QEMU_ARCH QEMU_ARCH_CRIS | |
65 | #elif defined(TARGET_I386) | |
66 | #define QEMU_ARCH QEMU_ARCH_I386 | |
67 | #elif defined(TARGET_M68K) | |
68 | #define QEMU_ARCH QEMU_ARCH_M68K | |
81ea0e13 MW |
69 | #elif defined(TARGET_LM32) |
70 | #define QEMU_ARCH QEMU_ARCH_LM32 | |
ad96090a BS |
71 | #elif defined(TARGET_MICROBLAZE) |
72 | #define QEMU_ARCH QEMU_ARCH_MICROBLAZE | |
73 | #elif defined(TARGET_MIPS) | |
74 | #define QEMU_ARCH QEMU_ARCH_MIPS | |
75 | #elif defined(TARGET_PPC) | |
76 | #define QEMU_ARCH QEMU_ARCH_PPC | |
77 | #elif defined(TARGET_S390X) | |
78 | #define QEMU_ARCH QEMU_ARCH_S390X | |
79 | #elif defined(TARGET_SH4) | |
80 | #define QEMU_ARCH QEMU_ARCH_SH4 | |
81 | #elif defined(TARGET_SPARC) | |
82 | #define QEMU_ARCH QEMU_ARCH_SPARC | |
2328826b MF |
83 | #elif defined(TARGET_XTENSA) |
84 | #define QEMU_ARCH QEMU_ARCH_XTENSA | |
ad96090a BS |
85 | #endif |
86 | ||
87 | const uint32_t arch_type = QEMU_ARCH; | |
88 | ||
89 | /***********************************************************/ | |
90 | /* ram save/restore */ | |
91 | ||
d20878d2 YT |
92 | #define RAM_SAVE_FLAG_FULL 0x01 /* Obsolete, not used anymore */ |
93 | #define RAM_SAVE_FLAG_COMPRESS 0x02 | |
94 | #define RAM_SAVE_FLAG_MEM_SIZE 0x04 | |
95 | #define RAM_SAVE_FLAG_PAGE 0x08 | |
96 | #define RAM_SAVE_FLAG_EOS 0x10 | |
97 | #define RAM_SAVE_FLAG_CONTINUE 0x20 | |
ad96090a | 98 | |
86003615 PB |
99 | #ifdef __ALTIVEC__ |
100 | #include <altivec.h> | |
101 | #define VECTYPE vector unsigned char | |
102 | #define SPLAT(p) vec_splat(vec_ld(0, p), 0) | |
103 | #define ALL_EQ(v1, v2) vec_all_eq(v1, v2) | |
104 | #elif defined __SSE2__ | |
105 | #include <emmintrin.h> | |
106 | #define VECTYPE __m128i | |
107 | #define SPLAT(p) _mm_set1_epi8(*(p)) | |
108 | #define ALL_EQ(v1, v2) (_mm_movemask_epi8(_mm_cmpeq_epi8(v1, v2)) == 0xFFFF) | |
109 | #else | |
110 | #define VECTYPE unsigned long | |
111 | #define SPLAT(p) (*(p) * (~0UL / 255)) | |
112 | #define ALL_EQ(v1, v2) ((v1) == (v2)) | |
113 | #endif | |
114 | ||
b5a8fe5e EH |
115 | |
116 | int qemu_read_default_config_files(void) | |
117 | { | |
118 | int ret; | |
119 | ||
120 | ret = qemu_read_config_file(CONFIG_QEMU_CONFDIR "/qemu.conf"); | |
121 | if (ret < 0 && ret != -ENOENT) { | |
122 | return ret; | |
123 | } | |
124 | ||
125 | ret = qemu_read_config_file(arch_config_name); | |
126 | if (ret < 0 && ret != -ENOENT) { | |
127 | return ret; | |
128 | } | |
129 | ||
130 | return 0; | |
131 | } | |
132 | ||
86003615 | 133 | static int is_dup_page(uint8_t *page) |
ad96090a | 134 | { |
86003615 PB |
135 | VECTYPE *p = (VECTYPE *)page; |
136 | VECTYPE val = SPLAT(page); | |
ad96090a BS |
137 | int i; |
138 | ||
86003615 PB |
139 | for (i = 0; i < TARGET_PAGE_SIZE / sizeof(VECTYPE); i++) { |
140 | if (!ALL_EQ(val, p[i])) { | |
ad96090a BS |
141 | return 0; |
142 | } | |
143 | } | |
144 | ||
145 | return 1; | |
146 | } | |
147 | ||
760e77ea AW |
148 | static RAMBlock *last_block; |
149 | static ram_addr_t last_offset; | |
150 | ||
ad96090a BS |
151 | static int ram_save_block(QEMUFile *f) |
152 | { | |
e44359c3 AW |
153 | RAMBlock *block = last_block; |
154 | ram_addr_t offset = last_offset; | |
3fc250b4 | 155 | int bytes_sent = 0; |
71c510e2 | 156 | MemoryRegion *mr; |
ad96090a | 157 | |
e44359c3 AW |
158 | if (!block) |
159 | block = QLIST_FIRST(&ram_list.blocks); | |
160 | ||
e44359c3 | 161 | do { |
71c510e2 | 162 | mr = block->mr; |
cd7a45c9 BS |
163 | if (memory_region_get_dirty(mr, offset, TARGET_PAGE_SIZE, |
164 | DIRTY_MEMORY_MIGRATION)) { | |
ad96090a | 165 | uint8_t *p; |
a55bbe31 | 166 | int cont = (block == last_block) ? RAM_SAVE_FLAG_CONTINUE : 0; |
ad96090a | 167 | |
71c510e2 AK |
168 | memory_region_reset_dirty(mr, offset, TARGET_PAGE_SIZE, |
169 | DIRTY_MEMORY_MIGRATION); | |
ad96090a | 170 | |
71c510e2 | 171 | p = memory_region_get_ram_ptr(mr) + offset; |
ad96090a | 172 | |
86003615 | 173 | if (is_dup_page(p)) { |
a55bbe31 AW |
174 | qemu_put_be64(f, offset | cont | RAM_SAVE_FLAG_COMPRESS); |
175 | if (!cont) { | |
176 | qemu_put_byte(f, strlen(block->idstr)); | |
177 | qemu_put_buffer(f, (uint8_t *)block->idstr, | |
178 | strlen(block->idstr)); | |
179 | } | |
ad96090a | 180 | qemu_put_byte(f, *p); |
3fc250b4 | 181 | bytes_sent = 1; |
ad96090a | 182 | } else { |
a55bbe31 AW |
183 | qemu_put_be64(f, offset | cont | RAM_SAVE_FLAG_PAGE); |
184 | if (!cont) { | |
185 | qemu_put_byte(f, strlen(block->idstr)); | |
186 | qemu_put_buffer(f, (uint8_t *)block->idstr, | |
187 | strlen(block->idstr)); | |
188 | } | |
ad96090a | 189 | qemu_put_buffer(f, p, TARGET_PAGE_SIZE); |
3fc250b4 | 190 | bytes_sent = TARGET_PAGE_SIZE; |
ad96090a BS |
191 | } |
192 | ||
ad96090a BS |
193 | break; |
194 | } | |
e44359c3 AW |
195 | |
196 | offset += TARGET_PAGE_SIZE; | |
197 | if (offset >= block->length) { | |
198 | offset = 0; | |
199 | block = QLIST_NEXT(block, next); | |
200 | if (!block) | |
201 | block = QLIST_FIRST(&ram_list.blocks); | |
202 | } | |
71c510e2 | 203 | } while (block != last_block || offset != last_offset); |
e44359c3 AW |
204 | |
205 | last_block = block; | |
206 | last_offset = offset; | |
ad96090a | 207 | |
3fc250b4 | 208 | return bytes_sent; |
ad96090a BS |
209 | } |
210 | ||
211 | static uint64_t bytes_transferred; | |
212 | ||
213 | static ram_addr_t ram_save_remaining(void) | |
214 | { | |
e44359c3 | 215 | RAMBlock *block; |
ad96090a BS |
216 | ram_addr_t count = 0; |
217 | ||
e44359c3 AW |
218 | QLIST_FOREACH(block, &ram_list.blocks, next) { |
219 | ram_addr_t addr; | |
71c510e2 | 220 | for (addr = 0; addr < block->length; addr += TARGET_PAGE_SIZE) { |
cd7a45c9 | 221 | if (memory_region_get_dirty(block->mr, addr, TARGET_PAGE_SIZE, |
71c510e2 | 222 | DIRTY_MEMORY_MIGRATION)) { |
e44359c3 AW |
223 | count++; |
224 | } | |
ad96090a BS |
225 | } |
226 | } | |
227 | ||
228 | return count; | |
229 | } | |
230 | ||
231 | uint64_t ram_bytes_remaining(void) | |
232 | { | |
233 | return ram_save_remaining() * TARGET_PAGE_SIZE; | |
234 | } | |
235 | ||
236 | uint64_t ram_bytes_transferred(void) | |
237 | { | |
238 | return bytes_transferred; | |
239 | } | |
240 | ||
241 | uint64_t ram_bytes_total(void) | |
242 | { | |
d17b5288 AW |
243 | RAMBlock *block; |
244 | uint64_t total = 0; | |
245 | ||
246 | QLIST_FOREACH(block, &ram_list.blocks, next) | |
247 | total += block->length; | |
248 | ||
249 | return total; | |
ad96090a BS |
250 | } |
251 | ||
b2e0a138 MT |
252 | static int block_compar(const void *a, const void *b) |
253 | { | |
254 | RAMBlock * const *ablock = a; | |
255 | RAMBlock * const *bblock = b; | |
8fec98b4 AK |
256 | |
257 | return strcmp((*ablock)->idstr, (*bblock)->idstr); | |
b2e0a138 MT |
258 | } |
259 | ||
260 | static void sort_ram_list(void) | |
261 | { | |
262 | RAMBlock *block, *nblock, **blocks; | |
263 | int n; | |
264 | n = 0; | |
265 | QLIST_FOREACH(block, &ram_list.blocks, next) { | |
266 | ++n; | |
267 | } | |
7267c094 | 268 | blocks = g_malloc(n * sizeof *blocks); |
b2e0a138 MT |
269 | n = 0; |
270 | QLIST_FOREACH_SAFE(block, &ram_list.blocks, next, nblock) { | |
271 | blocks[n++] = block; | |
272 | QLIST_REMOVE(block, next); | |
273 | } | |
274 | qsort(blocks, n, sizeof *blocks, block_compar); | |
275 | while (--n >= 0) { | |
276 | QLIST_INSERT_HEAD(&ram_list.blocks, blocks[n], next); | |
277 | } | |
7267c094 | 278 | g_free(blocks); |
b2e0a138 MT |
279 | } |
280 | ||
539de124 | 281 | int ram_save_live(QEMUFile *f, int stage, void *opaque) |
ad96090a BS |
282 | { |
283 | ram_addr_t addr; | |
284 | uint64_t bytes_transferred_last; | |
285 | double bwidth = 0; | |
286 | uint64_t expected_time = 0; | |
2975725f | 287 | int ret; |
ad96090a BS |
288 | |
289 | if (stage < 0) { | |
8f77558f | 290 | memory_global_dirty_log_stop(); |
ad96090a BS |
291 | return 0; |
292 | } | |
293 | ||
86e775c6 | 294 | memory_global_sync_dirty_bitmap(get_system_memory()); |
ad96090a BS |
295 | |
296 | if (stage == 1) { | |
97ab12d4 | 297 | RAMBlock *block; |
ad96090a | 298 | bytes_transferred = 0; |
760e77ea AW |
299 | last_block = NULL; |
300 | last_offset = 0; | |
b2e0a138 | 301 | sort_ram_list(); |
ad96090a BS |
302 | |
303 | /* Make sure all dirty bits are set */ | |
e44359c3 | 304 | QLIST_FOREACH(block, &ram_list.blocks, next) { |
71c510e2 | 305 | for (addr = 0; addr < block->length; addr += TARGET_PAGE_SIZE) { |
cd7a45c9 | 306 | if (!memory_region_get_dirty(block->mr, addr, TARGET_PAGE_SIZE, |
71c510e2 | 307 | DIRTY_MEMORY_MIGRATION)) { |
fd4aa979 | 308 | memory_region_set_dirty(block->mr, addr, TARGET_PAGE_SIZE); |
e44359c3 | 309 | } |
ad96090a BS |
310 | } |
311 | } | |
312 | ||
8f77558f | 313 | memory_global_dirty_log_start(); |
ad96090a | 314 | |
e44359c3 | 315 | qemu_put_be64(f, ram_bytes_total() | RAM_SAVE_FLAG_MEM_SIZE); |
97ab12d4 AW |
316 | |
317 | QLIST_FOREACH(block, &ram_list.blocks, next) { | |
318 | qemu_put_byte(f, strlen(block->idstr)); | |
319 | qemu_put_buffer(f, (uint8_t *)block->idstr, strlen(block->idstr)); | |
320 | qemu_put_be64(f, block->length); | |
321 | } | |
ad96090a BS |
322 | } |
323 | ||
324 | bytes_transferred_last = bytes_transferred; | |
325 | bwidth = qemu_get_clock_ns(rt_clock); | |
326 | ||
2975725f | 327 | while ((ret = qemu_file_rate_limit(f)) == 0) { |
3fc250b4 | 328 | int bytes_sent; |
ad96090a | 329 | |
3fc250b4 PR |
330 | bytes_sent = ram_save_block(f); |
331 | bytes_transferred += bytes_sent; | |
332 | if (bytes_sent == 0) { /* no more blocks */ | |
ad96090a BS |
333 | break; |
334 | } | |
335 | } | |
336 | ||
2975725f JQ |
337 | if (ret < 0) { |
338 | return ret; | |
339 | } | |
340 | ||
ad96090a BS |
341 | bwidth = qemu_get_clock_ns(rt_clock) - bwidth; |
342 | bwidth = (bytes_transferred - bytes_transferred_last) / bwidth; | |
343 | ||
344 | /* if we haven't transferred anything this round, force expected_time to a | |
345 | * a very high value, but without crashing */ | |
346 | if (bwidth == 0) { | |
347 | bwidth = 0.000001; | |
348 | } | |
349 | ||
350 | /* try transferring iterative blocks of memory */ | |
351 | if (stage == 3) { | |
3fc250b4 PR |
352 | int bytes_sent; |
353 | ||
ad96090a | 354 | /* flush all remaining blocks regardless of rate limiting */ |
3fc250b4 PR |
355 | while ((bytes_sent = ram_save_block(f)) != 0) { |
356 | bytes_transferred += bytes_sent; | |
ad96090a | 357 | } |
8f77558f | 358 | memory_global_dirty_log_stop(); |
ad96090a BS |
359 | } |
360 | ||
361 | qemu_put_be64(f, RAM_SAVE_FLAG_EOS); | |
362 | ||
363 | expected_time = ram_save_remaining() * TARGET_PAGE_SIZE / bwidth; | |
364 | ||
365 | return (stage == 2) && (expected_time <= migrate_max_downtime()); | |
366 | } | |
367 | ||
a55bbe31 AW |
368 | static inline void *host_from_stream_offset(QEMUFile *f, |
369 | ram_addr_t offset, | |
370 | int flags) | |
371 | { | |
372 | static RAMBlock *block = NULL; | |
373 | char id[256]; | |
374 | uint8_t len; | |
375 | ||
376 | if (flags & RAM_SAVE_FLAG_CONTINUE) { | |
377 | if (!block) { | |
378 | fprintf(stderr, "Ack, bad migration stream!\n"); | |
379 | return NULL; | |
380 | } | |
381 | ||
dc94a7ed | 382 | return memory_region_get_ram_ptr(block->mr) + offset; |
a55bbe31 AW |
383 | } |
384 | ||
385 | len = qemu_get_byte(f); | |
386 | qemu_get_buffer(f, (uint8_t *)id, len); | |
387 | id[len] = 0; | |
388 | ||
389 | QLIST_FOREACH(block, &ram_list.blocks, next) { | |
390 | if (!strncmp(id, block->idstr, sizeof(id))) | |
dc94a7ed | 391 | return memory_region_get_ram_ptr(block->mr) + offset; |
a55bbe31 AW |
392 | } |
393 | ||
394 | fprintf(stderr, "Can't find block %s!\n", id); | |
395 | return NULL; | |
396 | } | |
397 | ||
ad96090a BS |
398 | int ram_load(QEMUFile *f, void *opaque, int version_id) |
399 | { | |
400 | ram_addr_t addr; | |
401 | int flags; | |
42802d47 | 402 | int error; |
ad96090a | 403 | |
f09f2189 | 404 | if (version_id < 4 || version_id > 4) { |
ad96090a BS |
405 | return -EINVAL; |
406 | } | |
407 | ||
408 | do { | |
409 | addr = qemu_get_be64(f); | |
410 | ||
411 | flags = addr & ~TARGET_PAGE_MASK; | |
412 | addr &= TARGET_PAGE_MASK; | |
413 | ||
414 | if (flags & RAM_SAVE_FLAG_MEM_SIZE) { | |
f09f2189 | 415 | if (version_id == 4) { |
97ab12d4 AW |
416 | /* Synchronize RAM block list */ |
417 | char id[256]; | |
418 | ram_addr_t length; | |
419 | ram_addr_t total_ram_bytes = addr; | |
420 | ||
421 | while (total_ram_bytes) { | |
422 | RAMBlock *block; | |
423 | uint8_t len; | |
424 | ||
425 | len = qemu_get_byte(f); | |
426 | qemu_get_buffer(f, (uint8_t *)id, len); | |
427 | id[len] = 0; | |
428 | length = qemu_get_be64(f); | |
429 | ||
430 | QLIST_FOREACH(block, &ram_list.blocks, next) { | |
431 | if (!strncmp(id, block->idstr, sizeof(id))) { | |
432 | if (block->length != length) | |
433 | return -EINVAL; | |
434 | break; | |
435 | } | |
436 | } | |
437 | ||
438 | if (!block) { | |
fb787f81 AW |
439 | fprintf(stderr, "Unknown ramblock \"%s\", cannot " |
440 | "accept migration\n", id); | |
441 | return -EINVAL; | |
97ab12d4 AW |
442 | } |
443 | ||
444 | total_ram_bytes -= length; | |
445 | } | |
ad96090a BS |
446 | } |
447 | } | |
448 | ||
449 | if (flags & RAM_SAVE_FLAG_COMPRESS) { | |
97ab12d4 AW |
450 | void *host; |
451 | uint8_t ch; | |
452 | ||
f09f2189 | 453 | host = host_from_stream_offset(f, addr, flags); |
492fb99c MT |
454 | if (!host) { |
455 | return -EINVAL; | |
456 | } | |
97ab12d4 | 457 | |
97ab12d4 AW |
458 | ch = qemu_get_byte(f); |
459 | memset(host, ch, TARGET_PAGE_SIZE); | |
ad96090a BS |
460 | #ifndef _WIN32 |
461 | if (ch == 0 && | |
462 | (!kvm_enabled() || kvm_has_sync_mmu())) { | |
e78815a5 | 463 | qemu_madvise(host, TARGET_PAGE_SIZE, QEMU_MADV_DONTNEED); |
ad96090a BS |
464 | } |
465 | #endif | |
466 | } else if (flags & RAM_SAVE_FLAG_PAGE) { | |
97ab12d4 AW |
467 | void *host; |
468 | ||
f09f2189 | 469 | host = host_from_stream_offset(f, addr, flags); |
97ab12d4 | 470 | |
97ab12d4 | 471 | qemu_get_buffer(f, host, TARGET_PAGE_SIZE); |
ad96090a | 472 | } |
42802d47 JQ |
473 | error = qemu_file_get_error(f); |
474 | if (error) { | |
475 | return error; | |
ad96090a BS |
476 | } |
477 | } while (!(flags & RAM_SAVE_FLAG_EOS)); | |
478 | ||
479 | return 0; | |
480 | } | |
481 | ||
ad96090a | 482 | #ifdef HAS_AUDIO |
0dfa5ef9 IY |
483 | struct soundhw { |
484 | const char *name; | |
485 | const char *descr; | |
486 | int enabled; | |
487 | int isa; | |
488 | union { | |
4a0f031d | 489 | int (*init_isa) (ISABus *bus); |
0dfa5ef9 IY |
490 | int (*init_pci) (PCIBus *bus); |
491 | } init; | |
492 | }; | |
493 | ||
494 | static struct soundhw soundhw[] = { | |
ad96090a | 495 | #ifdef HAS_AUDIO_CHOICE |
da12872a | 496 | #ifdef CONFIG_PCSPK |
ad96090a BS |
497 | { |
498 | "pcspk", | |
499 | "PC speaker", | |
500 | 0, | |
501 | 1, | |
502 | { .init_isa = pcspk_audio_init } | |
503 | }, | |
504 | #endif | |
505 | ||
506 | #ifdef CONFIG_SB16 | |
507 | { | |
508 | "sb16", | |
509 | "Creative Sound Blaster 16", | |
510 | 0, | |
511 | 1, | |
512 | { .init_isa = SB16_init } | |
513 | }, | |
514 | #endif | |
515 | ||
516 | #ifdef CONFIG_CS4231A | |
517 | { | |
518 | "cs4231a", | |
519 | "CS4231A", | |
520 | 0, | |
521 | 1, | |
522 | { .init_isa = cs4231a_init } | |
523 | }, | |
524 | #endif | |
525 | ||
526 | #ifdef CONFIG_ADLIB | |
527 | { | |
528 | "adlib", | |
529 | #ifdef HAS_YMF262 | |
530 | "Yamaha YMF262 (OPL3)", | |
531 | #else | |
532 | "Yamaha YM3812 (OPL2)", | |
533 | #endif | |
534 | 0, | |
535 | 1, | |
536 | { .init_isa = Adlib_init } | |
537 | }, | |
538 | #endif | |
539 | ||
540 | #ifdef CONFIG_GUS | |
541 | { | |
542 | "gus", | |
543 | "Gravis Ultrasound GF1", | |
544 | 0, | |
545 | 1, | |
546 | { .init_isa = GUS_init } | |
547 | }, | |
548 | #endif | |
549 | ||
550 | #ifdef CONFIG_AC97 | |
551 | { | |
552 | "ac97", | |
553 | "Intel 82801AA AC97 Audio", | |
554 | 0, | |
555 | 0, | |
556 | { .init_pci = ac97_init } | |
557 | }, | |
558 | #endif | |
559 | ||
560 | #ifdef CONFIG_ES1370 | |
561 | { | |
562 | "es1370", | |
563 | "ENSONIQ AudioPCI ES1370", | |
564 | 0, | |
565 | 0, | |
566 | { .init_pci = es1370_init } | |
567 | }, | |
568 | #endif | |
569 | ||
d61a4ce8 GH |
570 | #ifdef CONFIG_HDA |
571 | { | |
572 | "hda", | |
573 | "Intel HD Audio", | |
574 | 0, | |
575 | 0, | |
576 | { .init_pci = intel_hda_and_codec_init } | |
577 | }, | |
578 | #endif | |
579 | ||
ad96090a BS |
580 | #endif /* HAS_AUDIO_CHOICE */ |
581 | ||
582 | { NULL, NULL, 0, 0, { NULL } } | |
583 | }; | |
584 | ||
585 | void select_soundhw(const char *optarg) | |
586 | { | |
587 | struct soundhw *c; | |
588 | ||
589 | if (*optarg == '?') { | |
590 | show_valid_cards: | |
591 | ||
592 | printf("Valid sound card names (comma separated):\n"); | |
593 | for (c = soundhw; c->name; ++c) { | |
594 | printf ("%-11s %s\n", c->name, c->descr); | |
595 | } | |
596 | printf("\n-soundhw all will enable all of the above\n"); | |
597 | exit(*optarg != '?'); | |
598 | } | |
599 | else { | |
600 | size_t l; | |
601 | const char *p; | |
602 | char *e; | |
603 | int bad_card = 0; | |
604 | ||
605 | if (!strcmp(optarg, "all")) { | |
606 | for (c = soundhw; c->name; ++c) { | |
607 | c->enabled = 1; | |
608 | } | |
609 | return; | |
610 | } | |
611 | ||
612 | p = optarg; | |
613 | while (*p) { | |
614 | e = strchr(p, ','); | |
615 | l = !e ? strlen(p) : (size_t) (e - p); | |
616 | ||
617 | for (c = soundhw; c->name; ++c) { | |
618 | if (!strncmp(c->name, p, l) && !c->name[l]) { | |
619 | c->enabled = 1; | |
620 | break; | |
621 | } | |
622 | } | |
623 | ||
624 | if (!c->name) { | |
625 | if (l > 80) { | |
626 | fprintf(stderr, | |
627 | "Unknown sound card name (too big to show)\n"); | |
628 | } | |
629 | else { | |
630 | fprintf(stderr, "Unknown sound card name `%.*s'\n", | |
631 | (int) l, p); | |
632 | } | |
633 | bad_card = 1; | |
634 | } | |
635 | p += l + (e != NULL); | |
636 | } | |
637 | ||
638 | if (bad_card) { | |
639 | goto show_valid_cards; | |
640 | } | |
641 | } | |
642 | } | |
0dfa5ef9 | 643 | |
4a0f031d | 644 | void audio_init(ISABus *isa_bus, PCIBus *pci_bus) |
0dfa5ef9 IY |
645 | { |
646 | struct soundhw *c; | |
647 | ||
648 | for (c = soundhw; c->name; ++c) { | |
649 | if (c->enabled) { | |
650 | if (c->isa) { | |
4a0f031d HP |
651 | if (isa_bus) { |
652 | c->init.init_isa(isa_bus); | |
0dfa5ef9 IY |
653 | } |
654 | } else { | |
655 | if (pci_bus) { | |
656 | c->init.init_pci(pci_bus); | |
657 | } | |
658 | } | |
659 | } | |
660 | } | |
661 | } | |
ad96090a BS |
662 | #else |
663 | void select_soundhw(const char *optarg) | |
664 | { | |
665 | } | |
4a0f031d | 666 | void audio_init(ISABus *isa_bus, PCIBus *pci_bus) |
0dfa5ef9 IY |
667 | { |
668 | } | |
ad96090a BS |
669 | #endif |
670 | ||
671 | int qemu_uuid_parse(const char *str, uint8_t *uuid) | |
672 | { | |
673 | int ret; | |
674 | ||
675 | if (strlen(str) != 36) { | |
676 | return -1; | |
677 | } | |
678 | ||
679 | ret = sscanf(str, UUID_FMT, &uuid[0], &uuid[1], &uuid[2], &uuid[3], | |
680 | &uuid[4], &uuid[5], &uuid[6], &uuid[7], &uuid[8], &uuid[9], | |
681 | &uuid[10], &uuid[11], &uuid[12], &uuid[13], &uuid[14], | |
682 | &uuid[15]); | |
683 | ||
684 | if (ret != 16) { | |
685 | return -1; | |
686 | } | |
687 | #ifdef TARGET_I386 | |
688 | smbios_add_field(1, offsetof(struct smbios_type_1, uuid), 16, uuid); | |
689 | #endif | |
690 | return 0; | |
691 | } | |
692 | ||
693 | void do_acpitable_option(const char *optarg) | |
694 | { | |
695 | #ifdef TARGET_I386 | |
696 | if (acpi_table_add(optarg) < 0) { | |
697 | fprintf(stderr, "Wrong acpi table provided\n"); | |
698 | exit(1); | |
699 | } | |
700 | #endif | |
701 | } | |
702 | ||
703 | void do_smbios_option(const char *optarg) | |
704 | { | |
705 | #ifdef TARGET_I386 | |
706 | if (smbios_entry_add(optarg) < 0) { | |
707 | fprintf(stderr, "Wrong smbios provided\n"); | |
708 | exit(1); | |
709 | } | |
710 | #endif | |
711 | } | |
712 | ||
713 | void cpudef_init(void) | |
714 | { | |
715 | #if defined(cpudef_setup) | |
716 | cpudef_setup(); /* parse cpu definitions in target config file */ | |
717 | #endif | |
718 | } | |
719 | ||
720 | int audio_available(void) | |
721 | { | |
722 | #ifdef HAS_AUDIO | |
723 | return 1; | |
724 | #else | |
725 | return 0; | |
726 | #endif | |
727 | } | |
728 | ||
303d4e86 AP |
729 | int tcg_available(void) |
730 | { | |
731 | return 1; | |
732 | } | |
733 | ||
ad96090a BS |
734 | int kvm_available(void) |
735 | { | |
736 | #ifdef CONFIG_KVM | |
737 | return 1; | |
738 | #else | |
739 | return 0; | |
740 | #endif | |
741 | } | |
742 | ||
743 | int xen_available(void) | |
744 | { | |
745 | #ifdef CONFIG_XEN | |
746 | return 1; | |
747 | #else | |
748 | return 0; | |
749 | #endif | |
750 | } |