You need to sign in or sign up before continuing.
arch_init.c 7.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * QEMU System Emulator
 *
 * Copyright (c) 2003-2008 Fabrice Bellard
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
P
Peter Maydell 已提交
24
#include "qemu/osdep.h"
25 26
#include "qemu-common.h"
#include "cpu.h"
27 28
#include "sysemu/sysemu.h"
#include "sysemu/arch_init.h"
29
#include "hw/pci/pci.h"
P
Paolo Bonzini 已提交
30
#include "hw/audio/audio.h"
31
#include "hw/smbios/smbios.h"
32
#include "qemu/config-file.h"
33
#include "qemu/error-report.h"
34
#include "qmp-commands.h"
35
#include "hw/acpi/acpi.h"
36
#include "qemu/help_option.h"
37 38 39 40 41 42 43 44

#ifdef TARGET_SPARC
int graphic_width = 1024;
int graphic_height = 768;
int graphic_depth = 8;
#else
int graphic_width = 800;
int graphic_height = 600;
45
int graphic_depth = 32;
46 47 48 49 50 51 52 53 54 55 56 57 58
#endif


#if defined(TARGET_ALPHA)
#define QEMU_ARCH QEMU_ARCH_ALPHA
#elif defined(TARGET_ARM)
#define QEMU_ARCH QEMU_ARCH_ARM
#elif defined(TARGET_CRIS)
#define QEMU_ARCH QEMU_ARCH_CRIS
#elif defined(TARGET_I386)
#define QEMU_ARCH QEMU_ARCH_I386
#elif defined(TARGET_M68K)
#define QEMU_ARCH QEMU_ARCH_M68K
M
Michael Walle 已提交
59 60
#elif defined(TARGET_LM32)
#define QEMU_ARCH QEMU_ARCH_LM32
61 62 63 64
#elif defined(TARGET_MICROBLAZE)
#define QEMU_ARCH QEMU_ARCH_MICROBLAZE
#elif defined(TARGET_MIPS)
#define QEMU_ARCH QEMU_ARCH_MIPS
A
Anthony Green 已提交
65 66
#elif defined(TARGET_MOXIE)
#define QEMU_ARCH QEMU_ARCH_MOXIE
67 68
#elif defined(TARGET_OPENRISC)
#define QEMU_ARCH QEMU_ARCH_OPENRISC
69 70 71 72 73 74 75 76
#elif defined(TARGET_PPC)
#define QEMU_ARCH QEMU_ARCH_PPC
#elif defined(TARGET_S390X)
#define QEMU_ARCH QEMU_ARCH_S390X
#elif defined(TARGET_SH4)
#define QEMU_ARCH QEMU_ARCH_SH4
#elif defined(TARGET_SPARC)
#define QEMU_ARCH QEMU_ARCH_SPARC
M
Max Filippov 已提交
77 78
#elif defined(TARGET_XTENSA)
#define QEMU_ARCH QEMU_ARCH_XTENSA
79 80
#elif defined(TARGET_UNICORE32)
#define QEMU_ARCH QEMU_ARCH_UNICORE32
81 82
#elif defined(TARGET_TRICORE)
#define QEMU_ARCH QEMU_ARCH_TRICORE
83 84 85 86
#endif

const uint32_t arch_type = QEMU_ARCH;

87 88
static struct defconfig_file {
    const char *filename;
89 90
    /* Indicates it is an user config file (disabled by -no-user-config) */
    bool userconfig;
91
} default_config_files[] = {
92
    { CONFIG_QEMU_CONFDIR "/qemu.conf",                   true },
93 94 95
    { NULL }, /* end of list */
};

96
int qemu_read_default_config_files(bool userconfig)
97 98
{
    int ret;
99
    struct defconfig_file *f;
100

101
    for (f = default_config_files; f->filename; f++) {
102 103 104
        if (!userconfig && f->userconfig) {
            continue;
        }
105 106 107 108
        ret = qemu_read_config_file(f->filename);
        if (ret < 0 && ret != -ENOENT) {
            return ret;
        }
109
    }
L
Laszlo Ersek 已提交
110

111 112 113
    return 0;
}

I
Isaku Yamahata 已提交
114 115 116 117 118 119
struct soundhw {
    const char *name;
    const char *descr;
    int enabled;
    int isa;
    union {
120
        int (*init_isa) (ISABus *bus);
I
Isaku Yamahata 已提交
121 122 123 124
        int (*init_pci) (PCIBus *bus);
    } init;
};

125 126
static struct soundhw soundhw[9];
static int soundhw_count;
127

128 129 130 131 132 133 134 135 136 137
void isa_register_soundhw(const char *name, const char *descr,
                          int (*init_isa)(ISABus *bus))
{
    assert(soundhw_count < ARRAY_SIZE(soundhw) - 1);
    soundhw[soundhw_count].name = name;
    soundhw[soundhw_count].descr = descr;
    soundhw[soundhw_count].isa = 1;
    soundhw[soundhw_count].init.init_isa = init_isa;
    soundhw_count++;
}
138

139 140 141 142 143 144 145 146 147 148
void pci_register_soundhw(const char *name, const char *descr,
                          int (*init_pci)(PCIBus *bus))
{
    assert(soundhw_count < ARRAY_SIZE(soundhw) - 1);
    soundhw[soundhw_count].name = name;
    soundhw[soundhw_count].descr = descr;
    soundhw[soundhw_count].isa = 0;
    soundhw[soundhw_count].init.init_pci = init_pci;
    soundhw_count++;
}
149 150 151 152 153

void select_soundhw(const char *optarg)
{
    struct soundhw *c;

154
    if (is_help_option(optarg)) {
155 156
    show_valid_cards:

157 158 159 160 161 162 163 164 165
        if (soundhw_count) {
             printf("Valid sound card names (comma separated):\n");
             for (c = soundhw; c->name; ++c) {
                 printf ("%-11s %s\n", c->name, c->descr);
             }
             printf("\n-soundhw all will enable all of the above\n");
        } else {
             printf("Machine has no user-selectable audio hardware "
                    "(it may or may not have always-present audio hardware).\n");
166
        }
167
        exit(!is_help_option(optarg));
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
    }
    else {
        size_t l;
        const char *p;
        char *e;
        int bad_card = 0;

        if (!strcmp(optarg, "all")) {
            for (c = soundhw; c->name; ++c) {
                c->enabled = 1;
            }
            return;
        }

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

            for (c = soundhw; c->name; ++c) {
                if (!strncmp(c->name, p, l) && !c->name[l]) {
                    c->enabled = 1;
                    break;
                }
            }

            if (!c->name) {
                if (l > 80) {
196
                    error_report("Unknown sound card name (too big to show)");
197 198
                }
                else {
199 200
                    error_report("Unknown sound card name `%.*s'",
                                 (int) l, p);
201 202 203 204 205 206 207 208 209 210 211
                }
                bad_card = 1;
            }
            p += l + (e != NULL);
        }

        if (bad_card) {
            goto show_valid_cards;
        }
    }
}
I
Isaku Yamahata 已提交
212

213
void audio_init(void)
I
Isaku Yamahata 已提交
214 215
{
    struct soundhw *c;
216 217
    ISABus *isa_bus = (ISABus *) object_resolve_path_type("", TYPE_ISA_BUS, NULL);
    PCIBus *pci_bus = (PCIBus *) object_resolve_path_type("", TYPE_PCI_BUS, NULL);
I
Isaku Yamahata 已提交
218 219 220 221

    for (c = soundhw; c->name; ++c) {
        if (c->enabled) {
            if (c->isa) {
222
                if (!isa_bus) {
223
                    error_report("ISA bus not available for %s", c->name);
224
                    exit(1);
I
Isaku Yamahata 已提交
225
                }
226
                c->init.init_isa(isa_bus);
I
Isaku Yamahata 已提交
227
            } else {
228
                if (!pci_bus) {
229
                    error_report("PCI bus not available for %s", c->name);
230
                    exit(1);
I
Isaku Yamahata 已提交
231
                }
232
                c->init.init_pci(pci_bus);
I
Isaku Yamahata 已提交
233 234 235 236
            }
        }
    }
}
237

238
void do_acpitable_option(const QemuOpts *opts)
239 240
{
#ifdef TARGET_I386
241 242 243 244
    Error *err = NULL;

    acpi_table_add(opts, &err);
    if (err) {
245
        error_reportf_err(err, "Wrong acpi table provided: ");
246 247 248 249 250
        exit(1);
    }
#endif
}

M
Markus Armbruster 已提交
251
void do_smbios_option(QemuOpts *opts)
252 253
{
#ifdef TARGET_I386
M
Markus Armbruster 已提交
254
    smbios_entry_add(opts);
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
#endif
}

int kvm_available(void)
{
#ifdef CONFIG_KVM
    return 1;
#else
    return 0;
#endif
}

int xen_available(void)
{
#ifdef CONFIG_XEN
    return 1;
#else
    return 0;
#endif
}
275 276 277 278 279 280


TargetInfo *qmp_query_target(Error **errp)
{
    TargetInfo *info = g_malloc0(sizeof(*info));

P
Paolo Bonzini 已提交
281
    info->arch = g_strdup(TARGET_NAME);
282 283 284

    return info;
}