Statistics
| Branch: | Revision:

root / arch_init.c @ 4508bd9e

History | View | Annotate | Download (19.7 kB)

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>
26
#include <stdlib.h>
27
#ifndef _WIN32
28
#include <sys/types.h>
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"
44
#include "exec-memory.h"
45
#include "hw/pcspk.h"
46

    
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

    
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

    
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
76
#elif defined(TARGET_LM32)
77
#define QEMU_ARCH QEMU_ARCH_LM32
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
90
#elif defined(TARGET_XTENSA)
91
#define QEMU_ARCH QEMU_ARCH_XTENSA
92
#endif
93

    
94
const uint32_t arch_type = QEMU_ARCH;
95

    
96
/***********************************************************/
97
/* ram save/restore */
98

    
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
105

    
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)
111
/* altivec.h may redefine the bool macro as vector type.
112
 * Reset it to POSIX semantics. */
113
#undef bool
114
#define bool _Bool
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

    
126

    
127
static struct defconfig_file {
128
    const char *filename;
129
    /* Indicates it is an user config file (disabled by -no-user-config) */
130
    bool userconfig;
131
} default_config_files[] = {
132
    { CONFIG_QEMU_DATADIR "/cpus-" TARGET_ARCH ".conf",  false },
133
    { CONFIG_QEMU_CONFDIR "/qemu.conf",                   true },
134
    { CONFIG_QEMU_CONFDIR "/target-" TARGET_ARCH ".conf", true },
135
    { NULL }, /* end of list */
136
};
137

    
138

    
139
int qemu_read_default_config_files(bool userconfig)
140
{
141
    int ret;
142
    struct defconfig_file *f;
143

    
144
    for (f = default_config_files; f->filename; f++) {
145
        if (!userconfig && f->userconfig) {
146
            continue;
147
        }
148
        ret = qemu_read_config_file(f->filename);
149
        if (ret < 0 && ret != -ENOENT) {
150
            return ret;
151
        }
152
    }
153
    
154
    return 0;
155
}
156

    
157
static int is_dup_page(uint8_t *page)
158
{
159
    VECTYPE *p = (VECTYPE *)page;
160
    VECTYPE val = SPLAT(page);
161
    int i;
162

    
163
    for (i = 0; i < TARGET_PAGE_SIZE / sizeof(VECTYPE); i++) {
164
        if (!ALL_EQ(val, p[i])) {
165
            return 0;
166
        }
167
    }
168

    
169
    return 1;
170
}
171

    
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

    
184
static RAMBlock *last_block;
185
static ram_addr_t last_offset;
186

    
187
static int ram_save_block(QEMUFile *f)
188
{
189
    RAMBlock *block = last_block;
190
    ram_addr_t offset = last_offset;
191
    int bytes_sent = 0;
192
    MemoryRegion *mr;
193

    
194
    if (!block)
195
        block = QLIST_FIRST(&ram_list.blocks);
196

    
197
    do {
198
        mr = block->mr;
199
        if (memory_region_get_dirty(mr, offset, TARGET_PAGE_SIZE,
200
                                    DIRTY_MEMORY_MIGRATION)) {
201
            uint8_t *p;
202
            int cont = (block == last_block) ? RAM_SAVE_FLAG_CONTINUE : 0;
203

    
204
            memory_region_reset_dirty(mr, offset, TARGET_PAGE_SIZE,
205
                                      DIRTY_MEMORY_MIGRATION);
206

    
207
            p = memory_region_get_ram_ptr(mr) + offset;
208

    
209
            if (is_dup_page(p)) {
210
                save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_COMPRESS);
211
                qemu_put_byte(f, *p);
212
                bytes_sent = 1;
213
            } else {
214
                save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_PAGE);
215
                qemu_put_buffer(f, p, TARGET_PAGE_SIZE);
216
                bytes_sent = TARGET_PAGE_SIZE;
217
            }
218

    
219
            break;
220
        }
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
        }
229
    } while (block != last_block || offset != last_offset);
230

    
231
    last_block = block;
232
    last_offset = offset;
233

    
234
    return bytes_sent;
235
}
236

    
237
static uint64_t bytes_transferred;
238

    
239
static ram_addr_t ram_save_remaining(void)
240
{
241
    RAMBlock *block;
242
    ram_addr_t count = 0;
243

    
244
    QLIST_FOREACH(block, &ram_list.blocks, next) {
245
        ram_addr_t addr;
246
        for (addr = 0; addr < block->length; addr += TARGET_PAGE_SIZE) {
247
            if (memory_region_get_dirty(block->mr, addr, TARGET_PAGE_SIZE,
248
                                        DIRTY_MEMORY_MIGRATION)) {
249
                count++;
250
            }
251
        }
252
    }
253

    
254
    return count;
255
}
256

    
257
uint64_t ram_bytes_remaining(void)
258
{
259
    return ram_save_remaining() * TARGET_PAGE_SIZE;
260
}
261

    
262
uint64_t ram_bytes_transferred(void)
263
{
264
    return bytes_transferred;
265
}
266

    
267
uint64_t ram_bytes_total(void)
268
{
269
    RAMBlock *block;
270
    uint64_t total = 0;
271

    
272
    QLIST_FOREACH(block, &ram_list.blocks, next)
273
        total += block->length;
274

    
275
    return total;
276
}
277

    
278
static int block_compar(const void *a, const void *b)
279
{
280
    RAMBlock * const *ablock = a;
281
    RAMBlock * const *bblock = b;
282

    
283
    return strcmp((*ablock)->idstr, (*bblock)->idstr);
284
}
285

    
286
static void sort_ram_list(void)
287
{
288
    RAMBlock *block, *nblock, **blocks;
289
    int n;
290
    n = 0;
291
    QLIST_FOREACH(block, &ram_list.blocks, next) {
292
        ++n;
293
    }
294
    blocks = g_malloc(n * sizeof *blocks);
295
    n = 0;
296
    QLIST_FOREACH_SAFE(block, &ram_list.blocks, next, nblock) {
297
        blocks[n++] = block;
298
        QLIST_REMOVE(block, next);
299
    }
300
    qsort(blocks, n, sizeof *blocks, block_compar);
301
    while (--n >= 0) {
302
        QLIST_INSERT_HEAD(&ram_list.blocks, blocks[n], next);
303
    }
304
    g_free(blocks);
305
}
306

    
307
static void migration_end(void)
308
{
309
    memory_global_dirty_log_stop();
310
}
311

    
312
#define MAX_WAIT 50 /* ms, half buffered_file limit */
313

    
314
int ram_save_live(QEMUFile *f, int stage, void *opaque)
315
{
316
    ram_addr_t addr;
317
    uint64_t bytes_transferred_last;
318
    double bwidth = 0;
319
    int ret;
320
    int i;
321

    
322
    if (stage < 0) {
323
        migration_end();
324
        return 0;
325
    }
326

    
327
    memory_global_sync_dirty_bitmap(get_system_memory());
328

    
329
    if (stage == 1) {
330
        RAMBlock *block;
331
        bytes_transferred = 0;
332
        last_block = NULL;
333
        last_offset = 0;
334
        sort_ram_list();
335

    
336
        /* Make sure all dirty bits are set */
337
        QLIST_FOREACH(block, &ram_list.blocks, next) {
338
            for (addr = 0; addr < block->length; addr += TARGET_PAGE_SIZE) {
339
                if (!memory_region_get_dirty(block->mr, addr, TARGET_PAGE_SIZE,
340
                                             DIRTY_MEMORY_MIGRATION)) {
341
                    memory_region_set_dirty(block->mr, addr, TARGET_PAGE_SIZE);
342
                }
343
            }
344
        }
345

    
346
        memory_global_dirty_log_start();
347

    
348
        qemu_put_be64(f, ram_bytes_total() | RAM_SAVE_FLAG_MEM_SIZE);
349

    
350
        QLIST_FOREACH(block, &ram_list.blocks, next) {
351
            qemu_put_byte(f, strlen(block->idstr));
352
            qemu_put_buffer(f, (uint8_t *)block->idstr, strlen(block->idstr));
353
            qemu_put_be64(f, block->length);
354
        }
355
    }
356

    
357
    bytes_transferred_last = bytes_transferred;
358
    bwidth = qemu_get_clock_ns(rt_clock);
359

    
360
    i = 0;
361
    while ((ret = qemu_file_rate_limit(f)) == 0) {
362
        int bytes_sent;
363

    
364
        bytes_sent = ram_save_block(f);
365
        bytes_transferred += bytes_sent;
366
        if (bytes_sent == 0) { /* no more blocks */
367
            break;
368
        }
369
        /* we want to check in the 1st loop, just in case it was the 1st time
370
           and we had to sync the dirty bitmap.
371
           qemu_get_clock_ns() is a bit expensive, so we only check each some
372
           iterations
373
        */
374
        if ((i & 63) == 0) {
375
            uint64_t t1 = (qemu_get_clock_ns(rt_clock) - bwidth) / 1000000;
376
            if (t1 > MAX_WAIT) {
377
                DPRINTF("big wait: " PRIu64 " milliseconds, %d iterations\n",
378
                        t1, i);
379
                break;
380
            }
381
        }
382
        i++;
383
    }
384

    
385
    if (ret < 0) {
386
        return ret;
387
    }
388

    
389
    bwidth = qemu_get_clock_ns(rt_clock) - bwidth;
390
    bwidth = (bytes_transferred - bytes_transferred_last) / bwidth;
391

    
392
    /* if we haven't transferred anything this round, force expected_time to a
393
     * a very high value, but without crashing */
394
    if (bwidth == 0) {
395
        bwidth = 0.000001;
396
    }
397

    
398
    /* try transferring iterative blocks of memory */
399
    if (stage == 3) {
400
        int bytes_sent;
401

    
402
        /* flush all remaining blocks regardless of rate limiting */
403
        while ((bytes_sent = ram_save_block(f)) != 0) {
404
            bytes_transferred += bytes_sent;
405
        }
406
        memory_global_dirty_log_stop();
407
    }
408

    
409
    qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
410

    
411
    if (stage == 2) {
412
        uint64_t expected_time;
413
        expected_time = ram_save_remaining() * TARGET_PAGE_SIZE / bwidth;
414

    
415
        DPRINTF("ram_save_live: expected(" PRIu64 ") <= max(" PRIu64 ")?\n",
416
                expected_time, migrate_max_downtime());
417

    
418
        return expected_time <= migrate_max_downtime();
419
    }
420
    return 0;
421
}
422

    
423
static inline void *host_from_stream_offset(QEMUFile *f,
424
                                            ram_addr_t offset,
425
                                            int flags)
426
{
427
    static RAMBlock *block = NULL;
428
    char id[256];
429
    uint8_t len;
430

    
431
    if (flags & RAM_SAVE_FLAG_CONTINUE) {
432
        if (!block) {
433
            fprintf(stderr, "Ack, bad migration stream!\n");
434
            return NULL;
435
        }
436

    
437
        return memory_region_get_ram_ptr(block->mr) + offset;
438
    }
439

    
440
    len = qemu_get_byte(f);
441
    qemu_get_buffer(f, (uint8_t *)id, len);
442
    id[len] = 0;
443

    
444
    QLIST_FOREACH(block, &ram_list.blocks, next) {
445
        if (!strncmp(id, block->idstr, sizeof(id)))
446
            return memory_region_get_ram_ptr(block->mr) + offset;
447
    }
448

    
449
    fprintf(stderr, "Can't find block %s!\n", id);
450
    return NULL;
451
}
452

    
453
int ram_load(QEMUFile *f, void *opaque, int version_id)
454
{
455
    ram_addr_t addr;
456
    int flags, ret = 0;
457
    int error;
458
    static uint64_t seq_iter;
459

    
460
    seq_iter++;
461

    
462
    if (version_id < 4 || version_id > 4) {
463
        return -EINVAL;
464
    }
465

    
466
    do {
467
        addr = qemu_get_be64(f);
468

    
469
        flags = addr & ~TARGET_PAGE_MASK;
470
        addr &= TARGET_PAGE_MASK;
471

    
472
        if (flags & RAM_SAVE_FLAG_MEM_SIZE) {
473
            if (version_id == 4) {
474
                /* Synchronize RAM block list */
475
                char id[256];
476
                ram_addr_t length;
477
                ram_addr_t total_ram_bytes = addr;
478

    
479
                while (total_ram_bytes) {
480
                    RAMBlock *block;
481
                    uint8_t len;
482

    
483
                    len = qemu_get_byte(f);
484
                    qemu_get_buffer(f, (uint8_t *)id, len);
485
                    id[len] = 0;
486
                    length = qemu_get_be64(f);
487

    
488
                    QLIST_FOREACH(block, &ram_list.blocks, next) {
489
                        if (!strncmp(id, block->idstr, sizeof(id))) {
490
                            if (block->length != length) {
491
                                ret =  -EINVAL;
492
                                goto done;
493
                            }
494
                            break;
495
                        }
496
                    }
497

    
498
                    if (!block) {
499
                        fprintf(stderr, "Unknown ramblock \"%s\", cannot "
500
                                "accept migration\n", id);
501
                        ret = -EINVAL;
502
                        goto done;
503
                    }
504

    
505
                    total_ram_bytes -= length;
506
                }
507
            }
508
        }
509

    
510
        if (flags & RAM_SAVE_FLAG_COMPRESS) {
511
            void *host;
512
            uint8_t ch;
513

    
514
            host = host_from_stream_offset(f, addr, flags);
515
            if (!host) {
516
                return -EINVAL;
517
            }
518

    
519
            ch = qemu_get_byte(f);
520
            memset(host, ch, TARGET_PAGE_SIZE);
521
#ifndef _WIN32
522
            if (ch == 0 &&
523
                (!kvm_enabled() || kvm_has_sync_mmu())) {
524
                qemu_madvise(host, TARGET_PAGE_SIZE, QEMU_MADV_DONTNEED);
525
            }
526
#endif
527
        } else if (flags & RAM_SAVE_FLAG_PAGE) {
528
            void *host;
529

    
530
            host = host_from_stream_offset(f, addr, flags);
531
            if (!host) {
532
                return -EINVAL;
533
            }
534

    
535
            qemu_get_buffer(f, host, TARGET_PAGE_SIZE);
536
        }
537
        error = qemu_file_get_error(f);
538
        if (error) {
539
            ret = error;
540
            goto done;
541
        }
542
    } while (!(flags & RAM_SAVE_FLAG_EOS));
543

    
544
done:
545
    DPRINTF("Completed load of VM with exit code %d seq iteration " PRIu64 "\n",
546
            ret, seq_iter);
547
    return ret;
548
}
549

    
550
#ifdef HAS_AUDIO
551
struct soundhw {
552
    const char *name;
553
    const char *descr;
554
    int enabled;
555
    int isa;
556
    union {
557
        int (*init_isa) (ISABus *bus);
558
        int (*init_pci) (PCIBus *bus);
559
    } init;
560
};
561

    
562
static struct soundhw soundhw[] = {
563
#ifdef HAS_AUDIO_CHOICE
564
#ifdef CONFIG_PCSPK
565
    {
566
        "pcspk",
567
        "PC speaker",
568
        0,
569
        1,
570
        { .init_isa = pcspk_audio_init }
571
    },
572
#endif
573

    
574
#ifdef CONFIG_SB16
575
    {
576
        "sb16",
577
        "Creative Sound Blaster 16",
578
        0,
579
        1,
580
        { .init_isa = SB16_init }
581
    },
582
#endif
583

    
584
#ifdef CONFIG_CS4231A
585
    {
586
        "cs4231a",
587
        "CS4231A",
588
        0,
589
        1,
590
        { .init_isa = cs4231a_init }
591
    },
592
#endif
593

    
594
#ifdef CONFIG_ADLIB
595
    {
596
        "adlib",
597
#ifdef HAS_YMF262
598
        "Yamaha YMF262 (OPL3)",
599
#else
600
        "Yamaha YM3812 (OPL2)",
601
#endif
602
        0,
603
        1,
604
        { .init_isa = Adlib_init }
605
    },
606
#endif
607

    
608
#ifdef CONFIG_GUS
609
    {
610
        "gus",
611
        "Gravis Ultrasound GF1",
612
        0,
613
        1,
614
        { .init_isa = GUS_init }
615
    },
616
#endif
617

    
618
#ifdef CONFIG_AC97
619
    {
620
        "ac97",
621
        "Intel 82801AA AC97 Audio",
622
        0,
623
        0,
624
        { .init_pci = ac97_init }
625
    },
626
#endif
627

    
628
#ifdef CONFIG_ES1370
629
    {
630
        "es1370",
631
        "ENSONIQ AudioPCI ES1370",
632
        0,
633
        0,
634
        { .init_pci = es1370_init }
635
    },
636
#endif
637

    
638
#ifdef CONFIG_HDA
639
    {
640
        "hda",
641
        "Intel HD Audio",
642
        0,
643
        0,
644
        { .init_pci = intel_hda_and_codec_init }
645
    },
646
#endif
647

    
648
#endif /* HAS_AUDIO_CHOICE */
649

    
650
    { NULL, NULL, 0, 0, { NULL } }
651
};
652

    
653
void select_soundhw(const char *optarg)
654
{
655
    struct soundhw *c;
656

    
657
    if (*optarg == '?') {
658
    show_valid_cards:
659

    
660
        printf("Valid sound card names (comma separated):\n");
661
        for (c = soundhw; c->name; ++c) {
662
            printf ("%-11s %s\n", c->name, c->descr);
663
        }
664
        printf("\n-soundhw all will enable all of the above\n");
665
        exit(*optarg != '?');
666
    }
667
    else {
668
        size_t l;
669
        const char *p;
670
        char *e;
671
        int bad_card = 0;
672

    
673
        if (!strcmp(optarg, "all")) {
674
            for (c = soundhw; c->name; ++c) {
675
                c->enabled = 1;
676
            }
677
            return;
678
        }
679

    
680
        p = optarg;
681
        while (*p) {
682
            e = strchr(p, ',');
683
            l = !e ? strlen(p) : (size_t) (e - p);
684

    
685
            for (c = soundhw; c->name; ++c) {
686
                if (!strncmp(c->name, p, l) && !c->name[l]) {
687
                    c->enabled = 1;
688
                    break;
689
                }
690
            }
691

    
692
            if (!c->name) {
693
                if (l > 80) {
694
                    fprintf(stderr,
695
                            "Unknown sound card name (too big to show)\n");
696
                }
697
                else {
698
                    fprintf(stderr, "Unknown sound card name `%.*s'\n",
699
                            (int) l, p);
700
                }
701
                bad_card = 1;
702
            }
703
            p += l + (e != NULL);
704
        }
705

    
706
        if (bad_card) {
707
            goto show_valid_cards;
708
        }
709
    }
710
}
711

    
712
void audio_init(ISABus *isa_bus, PCIBus *pci_bus)
713
{
714
    struct soundhw *c;
715

    
716
    for (c = soundhw; c->name; ++c) {
717
        if (c->enabled) {
718
            if (c->isa) {
719
                if (isa_bus) {
720
                    c->init.init_isa(isa_bus);
721
                }
722
            } else {
723
                if (pci_bus) {
724
                    c->init.init_pci(pci_bus);
725
                }
726
            }
727
        }
728
    }
729
}
730
#else
731
void select_soundhw(const char *optarg)
732
{
733
}
734
void audio_init(ISABus *isa_bus, PCIBus *pci_bus)
735
{
736
}
737
#endif
738

    
739
int qemu_uuid_parse(const char *str, uint8_t *uuid)
740
{
741
    int ret;
742

    
743
    if (strlen(str) != 36) {
744
        return -1;
745
    }
746

    
747
    ret = sscanf(str, UUID_FMT, &uuid[0], &uuid[1], &uuid[2], &uuid[3],
748
                 &uuid[4], &uuid[5], &uuid[6], &uuid[7], &uuid[8], &uuid[9],
749
                 &uuid[10], &uuid[11], &uuid[12], &uuid[13], &uuid[14],
750
                 &uuid[15]);
751

    
752
    if (ret != 16) {
753
        return -1;
754
    }
755
#ifdef TARGET_I386
756
    smbios_add_field(1, offsetof(struct smbios_type_1, uuid), 16, uuid);
757
#endif
758
    return 0;
759
}
760

    
761
void do_acpitable_option(const char *optarg)
762
{
763
#ifdef TARGET_I386
764
    if (acpi_table_add(optarg) < 0) {
765
        fprintf(stderr, "Wrong acpi table provided\n");
766
        exit(1);
767
    }
768
#endif
769
}
770

    
771
void do_smbios_option(const char *optarg)
772
{
773
#ifdef TARGET_I386
774
    if (smbios_entry_add(optarg) < 0) {
775
        fprintf(stderr, "Wrong smbios provided\n");
776
        exit(1);
777
    }
778
#endif
779
}
780

    
781
void cpudef_init(void)
782
{
783
#if defined(cpudef_setup)
784
    cpudef_setup(); /* parse cpu definitions in target config file */
785
#endif
786
}
787

    
788
int audio_available(void)
789
{
790
#ifdef HAS_AUDIO
791
    return 1;
792
#else
793
    return 0;
794
#endif
795
}
796

    
797
int tcg_available(void)
798
{
799
    return 1;
800
}
801

    
802
int kvm_available(void)
803
{
804
#ifdef CONFIG_KVM
805
    return 1;
806
#else
807
    return 0;
808
#endif
809
}
810

    
811
int xen_available(void)
812
{
813
#ifdef CONFIG_XEN
814
    return 1;
815
#else
816
    return 0;
817
#endif
818
}