blob: 0810116144a76c680dd6905bb34b46841ba5e204 [file] [log] [blame]
Blue Swirlad960902010-03-29 19:23:52 +00001/*
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 */
Peter Maydelld38ea872016-01-29 17:50:05 +000024#include "qemu/osdep.h"
Paolo Bonzini33c11872016-03-15 16:58:45 +010025#include "qemu-common.h"
26#include "cpu.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +010027#include "sysemu/sysemu.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +010028#include "sysemu/arch_init.h"
Michael S. Tsirkina2cb15b2012-12-12 14:24:50 +020029#include "hw/pci/pci.h"
Paolo Bonzini0d09e412013-02-05 17:06:20 +010030#include "hw/audio/audio.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010031#include "qemu/config-file.h"
Dr. David Alan Gilbertd97326e2014-03-19 18:32:31 +000032#include "qemu/error-report.h"
Daniel P. Berrange99afc912012-08-20 15:31:38 +010033#include "qmp-commands.h"
Michael S. Tsirkin04452592013-04-15 09:19:22 +030034#include "hw/acpi/acpi.h"
Veronia Bahaaf348b6d2016-03-20 19:16:19 +020035#include "qemu/help_option.h"
Blue Swirlad960902010-03-29 19:23:52 +000036
37#ifdef TARGET_SPARC
38int graphic_width = 1024;
39int graphic_height = 768;
40int graphic_depth = 8;
41#else
42int graphic_width = 800;
43int graphic_height = 600;
Alexander Graff1ff0e82013-06-20 14:06:27 +020044int graphic_depth = 32;
Blue Swirlad960902010-03-29 19:23:52 +000045#endif
46
Blue Swirlad960902010-03-29 19:23:52 +000047
48#if defined(TARGET_ALPHA)
49#define QEMU_ARCH QEMU_ARCH_ALPHA
50#elif defined(TARGET_ARM)
51#define QEMU_ARCH QEMU_ARCH_ARM
52#elif defined(TARGET_CRIS)
53#define QEMU_ARCH QEMU_ARCH_CRIS
54#elif defined(TARGET_I386)
55#define QEMU_ARCH QEMU_ARCH_I386
56#elif defined(TARGET_M68K)
57#define QEMU_ARCH QEMU_ARCH_M68K
Michael Walle81ea0e12011-02-17 23:45:02 +010058#elif defined(TARGET_LM32)
59#define QEMU_ARCH QEMU_ARCH_LM32
Blue Swirlad960902010-03-29 19:23:52 +000060#elif defined(TARGET_MICROBLAZE)
61#define QEMU_ARCH QEMU_ARCH_MICROBLAZE
62#elif defined(TARGET_MIPS)
63#define QEMU_ARCH QEMU_ARCH_MIPS
Anthony Greend15a9c22013-03-18 15:49:25 -040064#elif defined(TARGET_MOXIE)
65#define QEMU_ARCH QEMU_ARCH_MOXIE
Marek Vasute6717112017-01-18 23:01:46 +010066#elif defined(TARGET_NIOS2)
67#define QEMU_ARCH QEMU_ARCH_NIOS2
Jia Liue67db062012-07-20 15:50:39 +080068#elif defined(TARGET_OPENRISC)
69#define QEMU_ARCH QEMU_ARCH_OPENRISC
Blue Swirlad960902010-03-29 19:23:52 +000070#elif defined(TARGET_PPC)
71#define QEMU_ARCH QEMU_ARCH_PPC
72#elif defined(TARGET_S390X)
73#define QEMU_ARCH QEMU_ARCH_S390X
74#elif defined(TARGET_SH4)
75#define QEMU_ARCH QEMU_ARCH_SH4
76#elif defined(TARGET_SPARC)
77#define QEMU_ARCH QEMU_ARCH_SPARC
Max Filippov23288262011-09-06 03:55:25 +040078#elif defined(TARGET_XTENSA)
79#define QEMU_ARCH QEMU_ARCH_XTENSA
Guan Xuetao4f23a1e2012-08-10 14:42:21 +080080#elif defined(TARGET_UNICORE32)
81#define QEMU_ARCH QEMU_ARCH_UNICORE32
Bastian Koppelmann48e06fe2014-09-01 12:59:46 +010082#elif defined(TARGET_TRICORE)
83#define QEMU_ARCH QEMU_ARCH_TRICORE
Blue Swirlad960902010-03-29 19:23:52 +000084#endif
85
86const uint32_t arch_type = QEMU_ARCH;
Blue Swirlad960902010-03-29 19:23:52 +000087
Isaku Yamahata0dfa5ef2011-01-21 19:53:45 +090088struct soundhw {
89 const char *name;
90 const char *descr;
91 int enabled;
92 int isa;
93 union {
Hervé Poussineau4a0f0312011-12-15 22:10:01 +010094 int (*init_isa) (ISABus *bus);
Isaku Yamahata0dfa5ef2011-01-21 19:53:45 +090095 int (*init_pci) (PCIBus *bus);
96 } init;
97};
98
Paolo Bonzini36cd6f62013-04-18 18:43:58 +020099static struct soundhw soundhw[9];
100static int soundhw_count;
Blue Swirlad960902010-03-29 19:23:52 +0000101
Paolo Bonzini36cd6f62013-04-18 18:43:58 +0200102void isa_register_soundhw(const char *name, const char *descr,
103 int (*init_isa)(ISABus *bus))
104{
105 assert(soundhw_count < ARRAY_SIZE(soundhw) - 1);
106 soundhw[soundhw_count].name = name;
107 soundhw[soundhw_count].descr = descr;
108 soundhw[soundhw_count].isa = 1;
109 soundhw[soundhw_count].init.init_isa = init_isa;
110 soundhw_count++;
111}
Blue Swirlad960902010-03-29 19:23:52 +0000112
Paolo Bonzini36cd6f62013-04-18 18:43:58 +0200113void pci_register_soundhw(const char *name, const char *descr,
114 int (*init_pci)(PCIBus *bus))
115{
116 assert(soundhw_count < ARRAY_SIZE(soundhw) - 1);
117 soundhw[soundhw_count].name = name;
118 soundhw[soundhw_count].descr = descr;
119 soundhw[soundhw_count].isa = 0;
120 soundhw[soundhw_count].init.init_pci = init_pci;
121 soundhw_count++;
122}
Blue Swirlad960902010-03-29 19:23:52 +0000123
124void select_soundhw(const char *optarg)
125{
126 struct soundhw *c;
127
Peter Maydellc8057f92012-08-02 13:45:54 +0100128 if (is_help_option(optarg)) {
Blue Swirlad960902010-03-29 19:23:52 +0000129 show_valid_cards:
130
Paolo Bonzini36cd6f62013-04-18 18:43:58 +0200131 if (soundhw_count) {
132 printf("Valid sound card names (comma separated):\n");
133 for (c = soundhw; c->name; ++c) {
134 printf ("%-11s %s\n", c->name, c->descr);
135 }
136 printf("\n-soundhw all will enable all of the above\n");
137 } else {
138 printf("Machine has no user-selectable audio hardware "
139 "(it may or may not have always-present audio hardware).\n");
Blue Swirlad960902010-03-29 19:23:52 +0000140 }
Peter Maydellc8057f92012-08-02 13:45:54 +0100141 exit(!is_help_option(optarg));
Blue Swirlad960902010-03-29 19:23:52 +0000142 }
143 else {
144 size_t l;
145 const char *p;
146 char *e;
147 int bad_card = 0;
148
149 if (!strcmp(optarg, "all")) {
150 for (c = soundhw; c->name; ++c) {
151 c->enabled = 1;
152 }
153 return;
154 }
155
156 p = optarg;
157 while (*p) {
158 e = strchr(p, ',');
159 l = !e ? strlen(p) : (size_t) (e - p);
160
161 for (c = soundhw; c->name; ++c) {
162 if (!strncmp(c->name, p, l) && !c->name[l]) {
163 c->enabled = 1;
164 break;
165 }
166 }
167
168 if (!c->name) {
169 if (l > 80) {
Le Tan0971f1b2014-05-21 08:10:38 +0800170 error_report("Unknown sound card name (too big to show)");
Blue Swirlad960902010-03-29 19:23:52 +0000171 }
172 else {
Le Tan0971f1b2014-05-21 08:10:38 +0800173 error_report("Unknown sound card name `%.*s'",
174 (int) l, p);
Blue Swirlad960902010-03-29 19:23:52 +0000175 }
176 bad_card = 1;
177 }
178 p += l + (e != NULL);
179 }
180
181 if (bad_card) {
182 goto show_valid_cards;
183 }
184 }
185}
Isaku Yamahata0dfa5ef2011-01-21 19:53:45 +0900186
Paolo Bonzinif81222b2013-04-18 18:44:03 +0200187void audio_init(void)
Isaku Yamahata0dfa5ef2011-01-21 19:53:45 +0900188{
189 struct soundhw *c;
Paolo Bonzinif81222b2013-04-18 18:44:03 +0200190 ISABus *isa_bus = (ISABus *) object_resolve_path_type("", TYPE_ISA_BUS, NULL);
191 PCIBus *pci_bus = (PCIBus *) object_resolve_path_type("", TYPE_PCI_BUS, NULL);
Isaku Yamahata0dfa5ef2011-01-21 19:53:45 +0900192
193 for (c = soundhw; c->name; ++c) {
194 if (c->enabled) {
195 if (c->isa) {
Paolo Bonzinif81222b2013-04-18 18:44:03 +0200196 if (!isa_bus) {
Le Tan0971f1b2014-05-21 08:10:38 +0800197 error_report("ISA bus not available for %s", c->name);
Paolo Bonzinif81222b2013-04-18 18:44:03 +0200198 exit(1);
Isaku Yamahata0dfa5ef2011-01-21 19:53:45 +0900199 }
Paolo Bonzinif81222b2013-04-18 18:44:03 +0200200 c->init.init_isa(isa_bus);
Isaku Yamahata0dfa5ef2011-01-21 19:53:45 +0900201 } else {
Paolo Bonzinif81222b2013-04-18 18:44:03 +0200202 if (!pci_bus) {
Le Tan0971f1b2014-05-21 08:10:38 +0800203 error_report("PCI bus not available for %s", c->name);
Paolo Bonzinif81222b2013-04-18 18:44:03 +0200204 exit(1);
Isaku Yamahata0dfa5ef2011-01-21 19:53:45 +0900205 }
Paolo Bonzinif81222b2013-04-18 18:44:03 +0200206 c->init.init_pci(pci_bus);
Isaku Yamahata0dfa5ef2011-01-21 19:53:45 +0900207 }
208 }
209 }
210}
Blue Swirlad960902010-03-29 19:23:52 +0000211
Blue Swirlad960902010-03-29 19:23:52 +0000212int kvm_available(void)
213{
214#ifdef CONFIG_KVM
215 return 1;
216#else
217 return 0;
218#endif
219}
220
221int xen_available(void)
222{
223#ifdef CONFIG_XEN
224 return 1;
225#else
226 return 0;
227#endif
228}
Daniel P. Berrange99afc912012-08-20 15:31:38 +0100229
230
231TargetInfo *qmp_query_target(Error **errp)
232{
233 TargetInfo *info = g_malloc0(sizeof(*info));
234
Paolo Bonzinic02a9552013-06-04 14:45:28 +0200235 info->arch = g_strdup(TARGET_NAME);
Daniel P. Berrange99afc912012-08-20 15:31:38 +0100236
237 return info;
238}