2010-03-29 21:23:52 +02:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
#include <stdint.h>
|
2012-12-17 18:20:04 +01:00
|
|
|
#include "sysemu/sysemu.h"
|
|
|
|
#include "sysemu/arch_init.h"
|
2012-12-12 13:24:50 +01:00
|
|
|
#include "hw/pci/pci.h"
|
2013-02-05 17:06:20 +01:00
|
|
|
#include "hw/audio/audio.h"
|
2015-08-12 04:08:20 +02:00
|
|
|
#include "hw/smbios/smbios.h"
|
2012-12-17 18:20:00 +01:00
|
|
|
#include "qemu/config-file.h"
|
2014-03-19 19:32:31 +01:00
|
|
|
#include "qemu/error-report.h"
|
2012-08-20 16:31:38 +02:00
|
|
|
#include "qmp-commands.h"
|
2013-04-15 08:19:22 +02:00
|
|
|
#include "hw/acpi/acpi.h"
|
2010-03-29 21:23:52 +02:00
|
|
|
|
|
|
|
#ifdef TARGET_SPARC
|
|
|
|
int graphic_width = 1024;
|
|
|
|
int graphic_height = 768;
|
|
|
|
int graphic_depth = 8;
|
|
|
|
#else
|
|
|
|
int graphic_width = 800;
|
|
|
|
int graphic_height = 600;
|
2013-06-20 14:06:27 +02:00
|
|
|
int graphic_depth = 32;
|
2010-03-29 21:23:52 +02:00
|
|
|
#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
|
2011-02-17 23:45:02 +01:00
|
|
|
#elif defined(TARGET_LM32)
|
|
|
|
#define QEMU_ARCH QEMU_ARCH_LM32
|
2010-03-29 21:23:52 +02:00
|
|
|
#elif defined(TARGET_MICROBLAZE)
|
|
|
|
#define QEMU_ARCH QEMU_ARCH_MICROBLAZE
|
|
|
|
#elif defined(TARGET_MIPS)
|
|
|
|
#define QEMU_ARCH QEMU_ARCH_MIPS
|
2013-03-18 20:49:25 +01:00
|
|
|
#elif defined(TARGET_MOXIE)
|
|
|
|
#define QEMU_ARCH QEMU_ARCH_MOXIE
|
2012-07-20 09:50:39 +02:00
|
|
|
#elif defined(TARGET_OPENRISC)
|
|
|
|
#define QEMU_ARCH QEMU_ARCH_OPENRISC
|
2010-03-29 21:23:52 +02:00
|
|
|
#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
|
2011-09-06 01:55:25 +02:00
|
|
|
#elif defined(TARGET_XTENSA)
|
|
|
|
#define QEMU_ARCH QEMU_ARCH_XTENSA
|
2012-08-10 08:42:21 +02:00
|
|
|
#elif defined(TARGET_UNICORE32)
|
|
|
|
#define QEMU_ARCH QEMU_ARCH_UNICORE32
|
2014-09-01 13:59:46 +02:00
|
|
|
#elif defined(TARGET_TRICORE)
|
|
|
|
#define QEMU_ARCH QEMU_ARCH_TRICORE
|
2010-03-29 21:23:52 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
const uint32_t arch_type = QEMU_ARCH;
|
|
|
|
|
2012-05-02 18:07:27 +02:00
|
|
|
static struct defconfig_file {
|
|
|
|
const char *filename;
|
2012-05-02 18:07:29 +02:00
|
|
|
/* Indicates it is an user config file (disabled by -no-user-config) */
|
|
|
|
bool userconfig;
|
2012-05-02 18:07:27 +02:00
|
|
|
} default_config_files[] = {
|
2012-05-02 18:07:29 +02:00
|
|
|
{ CONFIG_QEMU_CONFDIR "/qemu.conf", true },
|
2012-05-02 18:07:27 +02:00
|
|
|
{ NULL }, /* end of list */
|
|
|
|
};
|
|
|
|
|
2012-05-02 18:07:29 +02:00
|
|
|
int qemu_read_default_config_files(bool userconfig)
|
2012-05-02 18:07:25 +02:00
|
|
|
{
|
|
|
|
int ret;
|
2012-05-02 18:07:27 +02:00
|
|
|
struct defconfig_file *f;
|
2012-05-02 18:07:25 +02:00
|
|
|
|
2012-05-02 18:07:27 +02:00
|
|
|
for (f = default_config_files; f->filename; f++) {
|
2012-05-02 18:07:29 +02:00
|
|
|
if (!userconfig && f->userconfig) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-05-02 18:07:27 +02:00
|
|
|
ret = qemu_read_config_file(f->filename);
|
|
|
|
if (ret < 0 && ret != -ENOENT) {
|
|
|
|
return ret;
|
|
|
|
}
|
2012-05-02 18:07:25 +02:00
|
|
|
}
|
2013-03-21 00:23:13 +01:00
|
|
|
|
2012-05-02 18:07:25 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-21 11:53:45 +01:00
|
|
|
struct soundhw {
|
|
|
|
const char *name;
|
|
|
|
const char *descr;
|
|
|
|
int enabled;
|
|
|
|
int isa;
|
|
|
|
union {
|
2011-12-15 22:10:01 +01:00
|
|
|
int (*init_isa) (ISABus *bus);
|
2011-01-21 11:53:45 +01:00
|
|
|
int (*init_pci) (PCIBus *bus);
|
|
|
|
} init;
|
|
|
|
};
|
|
|
|
|
2013-04-18 18:43:58 +02:00
|
|
|
static struct soundhw soundhw[9];
|
|
|
|
static int soundhw_count;
|
2010-03-29 21:23:52 +02:00
|
|
|
|
2013-04-18 18:43:58 +02:00
|
|
|
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++;
|
|
|
|
}
|
2010-03-29 21:23:52 +02:00
|
|
|
|
2013-04-18 18:43:58 +02:00
|
|
|
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++;
|
|
|
|
}
|
2010-03-29 21:23:52 +02:00
|
|
|
|
|
|
|
void select_soundhw(const char *optarg)
|
|
|
|
{
|
|
|
|
struct soundhw *c;
|
|
|
|
|
2012-08-02 14:45:54 +02:00
|
|
|
if (is_help_option(optarg)) {
|
2010-03-29 21:23:52 +02:00
|
|
|
show_valid_cards:
|
|
|
|
|
2013-04-18 18:43:58 +02:00
|
|
|
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");
|
2010-03-29 21:23:52 +02:00
|
|
|
}
|
2012-08-02 14:45:54 +02:00
|
|
|
exit(!is_help_option(optarg));
|
2010-03-29 21:23:52 +02:00
|
|
|
}
|
|
|
|
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) {
|
2014-05-21 02:10:38 +02:00
|
|
|
error_report("Unknown sound card name (too big to show)");
|
2010-03-29 21:23:52 +02:00
|
|
|
}
|
|
|
|
else {
|
2014-05-21 02:10:38 +02:00
|
|
|
error_report("Unknown sound card name `%.*s'",
|
|
|
|
(int) l, p);
|
2010-03-29 21:23:52 +02:00
|
|
|
}
|
|
|
|
bad_card = 1;
|
|
|
|
}
|
|
|
|
p += l + (e != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bad_card) {
|
|
|
|
goto show_valid_cards;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-21 11:53:45 +01:00
|
|
|
|
2013-04-18 18:44:03 +02:00
|
|
|
void audio_init(void)
|
2011-01-21 11:53:45 +01:00
|
|
|
{
|
|
|
|
struct soundhw *c;
|
2013-04-18 18:44:03 +02:00
|
|
|
ISABus *isa_bus = (ISABus *) object_resolve_path_type("", TYPE_ISA_BUS, NULL);
|
|
|
|
PCIBus *pci_bus = (PCIBus *) object_resolve_path_type("", TYPE_PCI_BUS, NULL);
|
2011-01-21 11:53:45 +01:00
|
|
|
|
|
|
|
for (c = soundhw; c->name; ++c) {
|
|
|
|
if (c->enabled) {
|
|
|
|
if (c->isa) {
|
2013-04-18 18:44:03 +02:00
|
|
|
if (!isa_bus) {
|
2014-05-21 02:10:38 +02:00
|
|
|
error_report("ISA bus not available for %s", c->name);
|
2013-04-18 18:44:03 +02:00
|
|
|
exit(1);
|
2011-01-21 11:53:45 +01:00
|
|
|
}
|
2013-04-18 18:44:03 +02:00
|
|
|
c->init.init_isa(isa_bus);
|
2011-01-21 11:53:45 +01:00
|
|
|
} else {
|
2013-04-18 18:44:03 +02:00
|
|
|
if (!pci_bus) {
|
2014-05-21 02:10:38 +02:00
|
|
|
error_report("PCI bus not available for %s", c->name);
|
2013-04-18 18:44:03 +02:00
|
|
|
exit(1);
|
2011-01-21 11:53:45 +01:00
|
|
|
}
|
2013-04-18 18:44:03 +02:00
|
|
|
c->init.init_pci(pci_bus);
|
2011-01-21 11:53:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-03-29 21:23:52 +02:00
|
|
|
|
|
|
|
int qemu_uuid_parse(const char *str, uint8_t *uuid)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (strlen(str) != 36) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = sscanf(str, UUID_FMT, &uuid[0], &uuid[1], &uuid[2], &uuid[3],
|
|
|
|
&uuid[4], &uuid[5], &uuid[6], &uuid[7], &uuid[8], &uuid[9],
|
|
|
|
&uuid[10], &uuid[11], &uuid[12], &uuid[13], &uuid[14],
|
|
|
|
&uuid[15]);
|
|
|
|
|
|
|
|
if (ret != 16) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-21 00:23:17 +01:00
|
|
|
void do_acpitable_option(const QemuOpts *opts)
|
2010-03-29 21:23:52 +02:00
|
|
|
{
|
|
|
|
#ifdef TARGET_I386
|
2013-03-21 00:23:19 +01:00
|
|
|
Error *err = NULL;
|
|
|
|
|
|
|
|
acpi_table_add(opts, &err);
|
|
|
|
if (err) {
|
2015-12-18 16:35:14 +01:00
|
|
|
error_reportf_err(err, "Wrong acpi table provided: ");
|
2010-03-29 21:23:52 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-08-16 15:18:29 +02:00
|
|
|
void do_smbios_option(QemuOpts *opts)
|
2010-03-29 21:23:52 +02:00
|
|
|
{
|
|
|
|
#ifdef TARGET_I386
|
2013-08-16 15:18:29 +02:00
|
|
|
smbios_entry_add(opts);
|
2010-03-29 21:23:52 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void cpudef_init(void)
|
|
|
|
{
|
|
|
|
#if defined(cpudef_setup)
|
|
|
|
cpudef_setup(); /* parse cpu definitions in target config file */
|
|
|
|
#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
|
|
|
|
}
|
2012-08-20 16:31:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
TargetInfo *qmp_query_target(Error **errp)
|
|
|
|
{
|
|
|
|
TargetInfo *info = g_malloc0(sizeof(*info));
|
|
|
|
|
2013-06-04 14:45:28 +02:00
|
|
|
info->arch = g_strdup(TARGET_NAME);
|
2012-08-20 16:31:38 +02:00
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|