4 * Copyright (c) 2003-2008 Fabrice Bellard
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
28 #include <sys/types.h>
34 #include "arch_init.h"
35 #include "audio/audio.h"
38 #include "hw/audiodev.h"
40 #include "migration.h"
43 #include "hw/smbios.h"
44 #include "exec-memory.h"
46 #include "qemu/page_cache.h"
47 #include "qmp-commands.h"
50 #ifdef DEBUG_ARCH_INIT
51 #define DPRINTF(fmt, ...) \
52 do { fprintf(stdout, "arch_init: " fmt, ## __VA_ARGS__); } while (0)
54 #define DPRINTF(fmt, ...) \
59 int graphic_width
= 1024;
60 int graphic_height
= 768;
61 int graphic_depth
= 8;
63 int graphic_width
= 800;
64 int graphic_height
= 600;
65 int graphic_depth
= 15;
69 #if defined(TARGET_ALPHA)
70 #define QEMU_ARCH QEMU_ARCH_ALPHA
71 #elif defined(TARGET_ARM)
72 #define QEMU_ARCH QEMU_ARCH_ARM
73 #elif defined(TARGET_CRIS)
74 #define QEMU_ARCH QEMU_ARCH_CRIS
75 #elif defined(TARGET_I386)
76 #define QEMU_ARCH QEMU_ARCH_I386
77 #elif defined(TARGET_M68K)
78 #define QEMU_ARCH QEMU_ARCH_M68K
79 #elif defined(TARGET_LM32)
80 #define QEMU_ARCH QEMU_ARCH_LM32
81 #elif defined(TARGET_MICROBLAZE)
82 #define QEMU_ARCH QEMU_ARCH_MICROBLAZE
83 #elif defined(TARGET_MIPS)
84 #define QEMU_ARCH QEMU_ARCH_MIPS
85 #elif defined(TARGET_OPENRISC)
86 #define QEMU_ARCH QEMU_ARCH_OPENRISC
87 #elif defined(TARGET_PPC)
88 #define QEMU_ARCH QEMU_ARCH_PPC
89 #elif defined(TARGET_S390X)
90 #define QEMU_ARCH QEMU_ARCH_S390X
91 #elif defined(TARGET_SH4)
92 #define QEMU_ARCH QEMU_ARCH_SH4
93 #elif defined(TARGET_SPARC)
94 #define QEMU_ARCH QEMU_ARCH_SPARC
95 #elif defined(TARGET_XTENSA)
96 #define QEMU_ARCH QEMU_ARCH_XTENSA
97 #elif defined(TARGET_UNICORE32)
98 #define QEMU_ARCH QEMU_ARCH_UNICORE32
101 const uint32_t arch_type
= QEMU_ARCH
;
103 /***********************************************************/
104 /* ram save/restore */
106 #define RAM_SAVE_FLAG_FULL 0x01 /* Obsolete, not used anymore */
107 #define RAM_SAVE_FLAG_COMPRESS 0x02
108 #define RAM_SAVE_FLAG_MEM_SIZE 0x04
109 #define RAM_SAVE_FLAG_PAGE 0x08
110 #define RAM_SAVE_FLAG_EOS 0x10
111 #define RAM_SAVE_FLAG_CONTINUE 0x20
112 #define RAM_SAVE_FLAG_XBZRLE 0x40
116 #define VECTYPE vector unsigned char
117 #define SPLAT(p) vec_splat(vec_ld(0, p), 0)
118 #define ALL_EQ(v1, v2) vec_all_eq(v1, v2)
119 /* altivec.h may redefine the bool macro as vector type.
120 * Reset it to POSIX semantics. */
123 #elif defined __SSE2__
124 #include <emmintrin.h>
125 #define VECTYPE __m128i
126 #define SPLAT(p) _mm_set1_epi8(*(p))
127 #define ALL_EQ(v1, v2) (_mm_movemask_epi8(_mm_cmpeq_epi8(v1, v2)) == 0xFFFF)
129 #define VECTYPE unsigned long
130 #define SPLAT(p) (*(p) * (~0UL / 255))
131 #define ALL_EQ(v1, v2) ((v1) == (v2))
135 static struct defconfig_file
{
136 const char *filename
;
137 /* Indicates it is an user config file (disabled by -no-user-config) */
139 } default_config_files
[] = {
140 { CONFIG_QEMU_CONFDIR
"/qemu.conf", true },
141 { CONFIG_QEMU_CONFDIR
"/target-" TARGET_ARCH
".conf", true },
142 { NULL
}, /* end of list */
146 int qemu_read_default_config_files(bool userconfig
)
149 struct defconfig_file
*f
;
151 for (f
= default_config_files
; f
->filename
; f
++) {
152 if (!userconfig
&& f
->userconfig
) {
155 ret
= qemu_read_config_file(f
->filename
);
156 if (ret
< 0 && ret
!= -ENOENT
) {
164 static int is_dup_page(uint8_t *page
)
166 VECTYPE
*p
= (VECTYPE
*)page
;
167 VECTYPE val
= SPLAT(page
);
170 for (i
= 0; i
< TARGET_PAGE_SIZE
/ sizeof(VECTYPE
); i
++) {
171 if (!ALL_EQ(val
, p
[i
])) {
179 /* struct contains XBZRLE cache and a static page
180 used by the compression */
182 /* buffer used for XBZRLE encoding */
183 uint8_t *encoded_buf
;
184 /* buffer for storing page content */
185 uint8_t *current_buf
;
186 /* buffer used for XBZRLE decoding */
187 uint8_t *decoded_buf
;
188 /* Cache for XBZRLE */
198 int64_t xbzrle_cache_resize(int64_t new_size
)
200 if (XBZRLE
.cache
!= NULL
) {
201 return cache_resize(XBZRLE
.cache
, new_size
/ TARGET_PAGE_SIZE
) *
204 return pow2floor(new_size
);
207 /* accounting for migration statistics */
208 typedef struct AccountingInfo
{
212 uint64_t xbzrle_bytes
;
213 uint64_t xbzrle_pages
;
214 uint64_t xbzrle_cache_miss
;
215 uint64_t xbzrle_overflows
;
218 static AccountingInfo acct_info
;
220 static void acct_clear(void)
222 memset(&acct_info
, 0, sizeof(acct_info
));
225 uint64_t dup_mig_bytes_transferred(void)
227 return acct_info
.dup_pages
* TARGET_PAGE_SIZE
;
230 uint64_t dup_mig_pages_transferred(void)
232 return acct_info
.dup_pages
;
235 uint64_t norm_mig_bytes_transferred(void)
237 return acct_info
.norm_pages
* TARGET_PAGE_SIZE
;
240 uint64_t norm_mig_pages_transferred(void)
242 return acct_info
.norm_pages
;
245 uint64_t xbzrle_mig_bytes_transferred(void)
247 return acct_info
.xbzrle_bytes
;
250 uint64_t xbzrle_mig_pages_transferred(void)
252 return acct_info
.xbzrle_pages
;
255 uint64_t xbzrle_mig_pages_cache_miss(void)
257 return acct_info
.xbzrle_cache_miss
;
260 uint64_t xbzrle_mig_pages_overflow(void)
262 return acct_info
.xbzrle_overflows
;
265 static void save_block_hdr(QEMUFile
*f
, RAMBlock
*block
, ram_addr_t offset
,
268 qemu_put_be64(f
, offset
| cont
| flag
);
270 qemu_put_byte(f
, strlen(block
->idstr
));
271 qemu_put_buffer(f
, (uint8_t *)block
->idstr
,
272 strlen(block
->idstr
));
277 #define ENCODING_FLAG_XBZRLE 0x1
279 static int save_xbzrle_page(QEMUFile
*f
, uint8_t *current_data
,
280 ram_addr_t current_addr
, RAMBlock
*block
,
281 ram_addr_t offset
, int cont
, bool last_stage
)
283 int encoded_len
= 0, bytes_sent
= -1;
284 uint8_t *prev_cached_page
;
286 if (!cache_is_cached(XBZRLE
.cache
, current_addr
)) {
288 cache_insert(XBZRLE
.cache
, current_addr
,
289 g_memdup(current_data
, TARGET_PAGE_SIZE
));
291 acct_info
.xbzrle_cache_miss
++;
295 prev_cached_page
= get_cached_data(XBZRLE
.cache
, current_addr
);
297 /* save current buffer into memory */
298 memcpy(XBZRLE
.current_buf
, current_data
, TARGET_PAGE_SIZE
);
300 /* XBZRLE encoding (if there is no overflow) */
301 encoded_len
= xbzrle_encode_buffer(prev_cached_page
, XBZRLE
.current_buf
,
302 TARGET_PAGE_SIZE
, XBZRLE
.encoded_buf
,
304 if (encoded_len
== 0) {
305 DPRINTF("Skipping unmodified page\n");
307 } else if (encoded_len
== -1) {
308 DPRINTF("Overflow\n");
309 acct_info
.xbzrle_overflows
++;
310 /* update data in the cache */
311 memcpy(prev_cached_page
, current_data
, TARGET_PAGE_SIZE
);
315 /* we need to update the data in the cache, in order to get the same data */
317 memcpy(prev_cached_page
, XBZRLE
.current_buf
, TARGET_PAGE_SIZE
);
320 /* Send XBZRLE based compressed page */
321 save_block_hdr(f
, block
, offset
, cont
, RAM_SAVE_FLAG_XBZRLE
);
322 qemu_put_byte(f
, ENCODING_FLAG_XBZRLE
);
323 qemu_put_be16(f
, encoded_len
);
324 qemu_put_buffer(f
, XBZRLE
.encoded_buf
, encoded_len
);
325 bytes_sent
= encoded_len
+ 1 + 2;
326 acct_info
.xbzrle_pages
++;
327 acct_info
.xbzrle_bytes
+= bytes_sent
;
332 static RAMBlock
*last_block
;
333 static ram_addr_t last_offset
;
335 static inline bool migration_bitmap_test_and_reset_dirty(MemoryRegion
*mr
,
338 bool ret
= memory_region_get_dirty(mr
, offset
, TARGET_PAGE_SIZE
,
339 DIRTY_MEMORY_MIGRATION
);
342 memory_region_reset_dirty(mr
, offset
, TARGET_PAGE_SIZE
,
343 DIRTY_MEMORY_MIGRATION
);
348 static inline void migration_bitmap_set_dirty(MemoryRegion
*mr
, int length
)
352 for (addr
= 0; addr
< length
; addr
+= TARGET_PAGE_SIZE
) {
353 if (!memory_region_get_dirty(mr
, addr
, TARGET_PAGE_SIZE
,
354 DIRTY_MEMORY_MIGRATION
)) {
355 memory_region_set_dirty(mr
, addr
, TARGET_PAGE_SIZE
);
360 static void migration_bitmap_sync(void)
362 uint64_t num_dirty_pages_init
= ram_list
.dirty_pages
;
364 trace_migration_bitmap_sync_start();
365 memory_global_sync_dirty_bitmap(get_system_memory());
366 trace_migration_bitmap_sync_end(ram_list
.dirty_pages
367 - num_dirty_pages_init
);
372 * ram_save_block: Writes a page of memory to the stream f
374 * Returns: 0: if the page hasn't changed
375 * -1: if there are no more dirty pages
376 * n: the amount of bytes written in other case
379 static int ram_save_block(QEMUFile
*f
, bool last_stage
)
381 RAMBlock
*block
= last_block
;
382 ram_addr_t offset
= last_offset
;
385 ram_addr_t current_addr
;
388 block
= QLIST_FIRST(&ram_list
.blocks
);
392 if (migration_bitmap_test_and_reset_dirty(mr
, offset
)) {
394 int cont
= (block
== last_block
) ? RAM_SAVE_FLAG_CONTINUE
: 0;
396 p
= memory_region_get_ram_ptr(mr
) + offset
;
398 if (is_dup_page(p
)) {
399 acct_info
.dup_pages
++;
400 save_block_hdr(f
, block
, offset
, cont
, RAM_SAVE_FLAG_COMPRESS
);
401 qemu_put_byte(f
, *p
);
403 } else if (migrate_use_xbzrle()) {
404 current_addr
= block
->offset
+ offset
;
405 bytes_sent
= save_xbzrle_page(f
, p
, current_addr
, block
,
406 offset
, cont
, last_stage
);
408 p
= get_cached_data(XBZRLE
.cache
, current_addr
);
412 /* either we didn't send yet (we may have had XBZRLE overflow) */
413 if (bytes_sent
== -1) {
414 save_block_hdr(f
, block
, offset
, cont
, RAM_SAVE_FLAG_PAGE
);
415 qemu_put_buffer(f
, p
, TARGET_PAGE_SIZE
);
416 bytes_sent
= TARGET_PAGE_SIZE
;
417 acct_info
.norm_pages
++;
420 /* if page is unmodified, continue to the next */
421 if (bytes_sent
!= 0) {
426 offset
+= TARGET_PAGE_SIZE
;
427 if (offset
>= block
->length
) {
429 block
= QLIST_NEXT(block
, next
);
431 block
= QLIST_FIRST(&ram_list
.blocks
);
433 } while (block
!= last_block
|| offset
!= last_offset
);
436 last_offset
= offset
;
441 static uint64_t bytes_transferred
;
443 static ram_addr_t
ram_save_remaining(void)
445 return ram_list
.dirty_pages
;
448 uint64_t ram_bytes_remaining(void)
450 return ram_save_remaining() * TARGET_PAGE_SIZE
;
453 uint64_t ram_bytes_transferred(void)
455 return bytes_transferred
;
458 uint64_t ram_bytes_total(void)
463 QLIST_FOREACH(block
, &ram_list
.blocks
, next
)
464 total
+= block
->length
;
469 static int block_compar(const void *a
, const void *b
)
471 RAMBlock
* const *ablock
= a
;
472 RAMBlock
* const *bblock
= b
;
474 return strcmp((*ablock
)->idstr
, (*bblock
)->idstr
);
477 static void sort_ram_list(void)
479 RAMBlock
*block
, *nblock
, **blocks
;
482 QLIST_FOREACH(block
, &ram_list
.blocks
, next
) {
485 blocks
= g_malloc(n
* sizeof *blocks
);
487 QLIST_FOREACH_SAFE(block
, &ram_list
.blocks
, next
, nblock
) {
489 QLIST_REMOVE(block
, next
);
491 qsort(blocks
, n
, sizeof *blocks
, block_compar
);
493 QLIST_INSERT_HEAD(&ram_list
.blocks
, blocks
[n
], next
);
498 static void migration_end(void)
500 memory_global_dirty_log_stop();
502 if (migrate_use_xbzrle()) {
503 cache_fini(XBZRLE
.cache
);
504 g_free(XBZRLE
.cache
);
505 g_free(XBZRLE
.encoded_buf
);
506 g_free(XBZRLE
.current_buf
);
507 g_free(XBZRLE
.decoded_buf
);
512 static void ram_migration_cancel(void *opaque
)
518 static void reset_ram_globals(void)
525 #define MAX_WAIT 50 /* ms, half buffered_file limit */
527 static int ram_save_setup(QEMUFile
*f
, void *opaque
)
531 bytes_transferred
= 0;
534 if (migrate_use_xbzrle()) {
535 XBZRLE
.cache
= cache_init(migrate_xbzrle_cache_size() /
539 DPRINTF("Error creating cache\n");
542 XBZRLE
.encoded_buf
= g_malloc0(TARGET_PAGE_SIZE
);
543 XBZRLE
.current_buf
= g_malloc(TARGET_PAGE_SIZE
);
547 /* Make sure all dirty bits are set */
548 QLIST_FOREACH(block
, &ram_list
.blocks
, next
) {
549 migration_bitmap_set_dirty(block
->mr
, block
->length
);
552 memory_global_dirty_log_start();
553 memory_global_sync_dirty_bitmap(get_system_memory());
555 qemu_put_be64(f
, ram_bytes_total() | RAM_SAVE_FLAG_MEM_SIZE
);
557 QLIST_FOREACH(block
, &ram_list
.blocks
, next
) {
558 qemu_put_byte(f
, strlen(block
->idstr
));
559 qemu_put_buffer(f
, (uint8_t *)block
->idstr
, strlen(block
->idstr
));
560 qemu_put_be64(f
, block
->length
);
563 qemu_put_be64(f
, RAM_SAVE_FLAG_EOS
);
568 static int ram_save_iterate(QEMUFile
*f
, void *opaque
)
570 uint64_t bytes_transferred_last
;
574 uint64_t expected_downtime
;
575 MigrationState
*s
= migrate_get_current();
577 bytes_transferred_last
= bytes_transferred
;
578 bwidth
= qemu_get_clock_ns(rt_clock
);
581 while ((ret
= qemu_file_rate_limit(f
)) == 0) {
584 bytes_sent
= ram_save_block(f
, false);
585 /* no more blocks to sent */
586 if (bytes_sent
< 0) {
589 bytes_transferred
+= bytes_sent
;
590 acct_info
.iterations
++;
591 /* we want to check in the 1st loop, just in case it was the 1st time
592 and we had to sync the dirty bitmap.
593 qemu_get_clock_ns() is a bit expensive, so we only check each some
597 uint64_t t1
= (qemu_get_clock_ns(rt_clock
) - bwidth
) / 1000000;
599 DPRINTF("big wait: %" PRIu64
" milliseconds, %d iterations\n",
611 bwidth
= qemu_get_clock_ns(rt_clock
) - bwidth
;
612 bwidth
= (bytes_transferred
- bytes_transferred_last
) / bwidth
;
614 /* if we haven't transferred anything this round, force
615 * expected_downtime to a very high value, but without
621 qemu_put_be64(f
, RAM_SAVE_FLAG_EOS
);
623 expected_downtime
= ram_save_remaining() * TARGET_PAGE_SIZE
/ bwidth
;
624 DPRINTF("ram_save_live: expected(%" PRIu64
") <= max(" PRIu64
")?\n",
625 expected_downtime
, migrate_max_downtime());
627 if (expected_downtime
<= migrate_max_downtime()) {
628 migration_bitmap_sync();
629 expected_downtime
= ram_save_remaining() * TARGET_PAGE_SIZE
/ bwidth
;
630 s
->expected_downtime
= expected_downtime
/ 1000000; /* ns -> ms */
632 return expected_downtime
<= migrate_max_downtime();
637 static int ram_save_complete(QEMUFile
*f
, void *opaque
)
639 migration_bitmap_sync();
641 /* try transferring iterative blocks of memory */
643 /* flush all remaining blocks regardless of rate limiting */
647 bytes_sent
= ram_save_block(f
, true);
648 /* no more blocks to sent */
649 if (bytes_sent
< 0) {
652 bytes_transferred
+= bytes_sent
;
654 memory_global_dirty_log_stop();
656 qemu_put_be64(f
, RAM_SAVE_FLAG_EOS
);
661 static int load_xbzrle(QEMUFile
*f
, ram_addr_t addr
, void *host
)
667 if (!XBZRLE
.decoded_buf
) {
668 XBZRLE
.decoded_buf
= g_malloc(TARGET_PAGE_SIZE
);
671 /* extract RLE header */
672 xh_flags
= qemu_get_byte(f
);
673 xh_len
= qemu_get_be16(f
);
675 if (xh_flags
!= ENCODING_FLAG_XBZRLE
) {
676 fprintf(stderr
, "Failed to load XBZRLE page - wrong compression!\n");
680 if (xh_len
> TARGET_PAGE_SIZE
) {
681 fprintf(stderr
, "Failed to load XBZRLE page - len overflow!\n");
684 /* load data and decode */
685 qemu_get_buffer(f
, XBZRLE
.decoded_buf
, xh_len
);
688 ret
= xbzrle_decode_buffer(XBZRLE
.decoded_buf
, xh_len
, host
,
691 fprintf(stderr
, "Failed to load XBZRLE page - decode error!\n");
693 } else if (ret
> TARGET_PAGE_SIZE
) {
694 fprintf(stderr
, "Failed to load XBZRLE page - size %d exceeds %d!\n",
695 ret
, TARGET_PAGE_SIZE
);
702 static inline void *host_from_stream_offset(QEMUFile
*f
,
706 static RAMBlock
*block
= NULL
;
710 if (flags
& RAM_SAVE_FLAG_CONTINUE
) {
712 fprintf(stderr
, "Ack, bad migration stream!\n");
716 return memory_region_get_ram_ptr(block
->mr
) + offset
;
719 len
= qemu_get_byte(f
);
720 qemu_get_buffer(f
, (uint8_t *)id
, len
);
723 QLIST_FOREACH(block
, &ram_list
.blocks
, next
) {
724 if (!strncmp(id
, block
->idstr
, sizeof(id
)))
725 return memory_region_get_ram_ptr(block
->mr
) + offset
;
728 fprintf(stderr
, "Can't find block %s!\n", id
);
732 static int ram_load(QEMUFile
*f
, void *opaque
, int version_id
)
737 static uint64_t seq_iter
;
741 if (version_id
< 4 || version_id
> 4) {
746 addr
= qemu_get_be64(f
);
748 flags
= addr
& ~TARGET_PAGE_MASK
;
749 addr
&= TARGET_PAGE_MASK
;
751 if (flags
& RAM_SAVE_FLAG_MEM_SIZE
) {
752 if (version_id
== 4) {
753 /* Synchronize RAM block list */
756 ram_addr_t total_ram_bytes
= addr
;
758 while (total_ram_bytes
) {
762 len
= qemu_get_byte(f
);
763 qemu_get_buffer(f
, (uint8_t *)id
, len
);
765 length
= qemu_get_be64(f
);
767 QLIST_FOREACH(block
, &ram_list
.blocks
, next
) {
768 if (!strncmp(id
, block
->idstr
, sizeof(id
))) {
769 if (block
->length
!= length
) {
778 fprintf(stderr
, "Unknown ramblock \"%s\", cannot "
779 "accept migration\n", id
);
784 total_ram_bytes
-= length
;
789 if (flags
& RAM_SAVE_FLAG_COMPRESS
) {
793 host
= host_from_stream_offset(f
, addr
, flags
);
798 ch
= qemu_get_byte(f
);
799 memset(host
, ch
, TARGET_PAGE_SIZE
);
802 (!kvm_enabled() || kvm_has_sync_mmu())) {
803 qemu_madvise(host
, TARGET_PAGE_SIZE
, QEMU_MADV_DONTNEED
);
806 } else if (flags
& RAM_SAVE_FLAG_PAGE
) {
809 host
= host_from_stream_offset(f
, addr
, flags
);
814 qemu_get_buffer(f
, host
, TARGET_PAGE_SIZE
);
815 } else if (flags
& RAM_SAVE_FLAG_XBZRLE
) {
816 if (!migrate_use_xbzrle()) {
819 void *host
= host_from_stream_offset(f
, addr
, flags
);
824 if (load_xbzrle(f
, addr
, host
) < 0) {
829 error
= qemu_file_get_error(f
);
834 } while (!(flags
& RAM_SAVE_FLAG_EOS
));
837 DPRINTF("Completed load of VM with exit code %d seq iteration "
838 "%" PRIu64
"\n", ret
, seq_iter
);
842 SaveVMHandlers savevm_ram_handlers
= {
843 .save_live_setup
= ram_save_setup
,
844 .save_live_iterate
= ram_save_iterate
,
845 .save_live_complete
= ram_save_complete
,
846 .load_state
= ram_load
,
847 .cancel
= ram_migration_cancel
,
857 int (*init_isa
) (ISABus
*bus
);
858 int (*init_pci
) (PCIBus
*bus
);
862 static struct soundhw soundhw
[] = {
863 #ifdef HAS_AUDIO_CHOICE
870 { .init_isa
= pcspk_audio_init
}
877 "Creative Sound Blaster 16",
880 { .init_isa
= SB16_init
}
884 #ifdef CONFIG_CS4231A
890 { .init_isa
= cs4231a_init
}
898 "Yamaha YMF262 (OPL3)",
900 "Yamaha YM3812 (OPL2)",
904 { .init_isa
= Adlib_init
}
911 "Gravis Ultrasound GF1",
914 { .init_isa
= GUS_init
}
921 "Intel 82801AA AC97 Audio",
924 { .init_pci
= ac97_init
}
931 "ENSONIQ AudioPCI ES1370",
934 { .init_pci
= es1370_init
}
944 { .init_pci
= intel_hda_and_codec_init
}
948 #endif /* HAS_AUDIO_CHOICE */
950 { NULL
, NULL
, 0, 0, { NULL
} }
953 void select_soundhw(const char *optarg
)
957 if (is_help_option(optarg
)) {
960 #ifdef HAS_AUDIO_CHOICE
961 printf("Valid sound card names (comma separated):\n");
962 for (c
= soundhw
; c
->name
; ++c
) {
963 printf ("%-11s %s\n", c
->name
, c
->descr
);
965 printf("\n-soundhw all will enable all of the above\n");
967 printf("Machine has no user-selectable audio hardware "
968 "(it may or may not have always-present audio hardware).\n");
970 exit(!is_help_option(optarg
));
978 if (!strcmp(optarg
, "all")) {
979 for (c
= soundhw
; c
->name
; ++c
) {
988 l
= !e
? strlen(p
) : (size_t) (e
- p
);
990 for (c
= soundhw
; c
->name
; ++c
) {
991 if (!strncmp(c
->name
, p
, l
) && !c
->name
[l
]) {
1000 "Unknown sound card name (too big to show)\n");
1003 fprintf(stderr
, "Unknown sound card name `%.*s'\n",
1008 p
+= l
+ (e
!= NULL
);
1012 goto show_valid_cards
;
1017 void audio_init(ISABus
*isa_bus
, PCIBus
*pci_bus
)
1021 for (c
= soundhw
; c
->name
; ++c
) {
1025 c
->init
.init_isa(isa_bus
);
1029 c
->init
.init_pci(pci_bus
);
1036 void select_soundhw(const char *optarg
)
1039 void audio_init(ISABus
*isa_bus
, PCIBus
*pci_bus
)
1044 int qemu_uuid_parse(const char *str
, uint8_t *uuid
)
1048 if (strlen(str
) != 36) {
1052 ret
= sscanf(str
, UUID_FMT
, &uuid
[0], &uuid
[1], &uuid
[2], &uuid
[3],
1053 &uuid
[4], &uuid
[5], &uuid
[6], &uuid
[7], &uuid
[8], &uuid
[9],
1054 &uuid
[10], &uuid
[11], &uuid
[12], &uuid
[13], &uuid
[14],
1061 smbios_add_field(1, offsetof(struct smbios_type_1
, uuid
), 16, uuid
);
1066 void do_acpitable_option(const char *optarg
)
1069 if (acpi_table_add(optarg
) < 0) {
1070 fprintf(stderr
, "Wrong acpi table provided\n");
1076 void do_smbios_option(const char *optarg
)
1079 if (smbios_entry_add(optarg
) < 0) {
1080 fprintf(stderr
, "Wrong smbios provided\n");
1086 void cpudef_init(void)
1088 #if defined(cpudef_setup)
1089 cpudef_setup(); /* parse cpu definitions in target config file */
1093 int audio_available(void)
1102 int tcg_available(void)
1107 int kvm_available(void)
1116 int xen_available(void)
1126 TargetInfo
*qmp_query_target(Error
**errp
)
1128 TargetInfo
*info
= g_malloc0(sizeof(*info
));
1130 info
->arch
= TARGET_TYPE
;