2 * QEMU System Emulator, accelerator interfaces
4 * Copyright (c) 2003-2008 Fabrice Bellard
5 * Copyright (c) 2014 Red Hat Inc.
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 #include "sysemu/accel.h"
27 #include "qemu-common.h"
28 #include "sysemu/arch_init.h"
29 #include "sysemu/sysemu.h"
30 #include "sysemu/kvm.h"
31 #include "sysemu/qtest.h"
32 #include "hw/xen/xen.h"
35 static bool tcg_allowed
= true;
37 static int tcg_init(MachineClass
*mc
)
39 tcg_exec_init(tcg_tb_size
* 1024 * 1024);
46 int (*available
)(void);
47 int (*init
)(MachineClass
*mc
);
50 { "tcg", "tcg", tcg_available
, tcg_init
, &tcg_allowed
},
51 { "xen", "Xen", xen_available
, xen_init
, &xen_allowed
},
52 { "kvm", "KVM", kvm_available
, kvm_init
, &kvm_allowed
},
53 { "qtest", "QTest", qtest_available
, qtest_init_accel
, &qtest_allowed
},
56 int configure_accelerator(MachineClass
*mc
)
61 bool accel_initialised
= false;
62 bool init_failed
= false;
64 p
= qemu_opt_get(qemu_get_machine_opts(), "accel");
66 /* Use the default "accelerator", tcg */
70 while (!accel_initialised
&& *p
!= '\0') {
74 p
= get_opt_name(buf
, sizeof(buf
), p
, ':');
75 for (i
= 0; i
< ARRAY_SIZE(accel_list
); i
++) {
76 if (strcmp(accel_list
[i
].opt_name
, buf
) == 0) {
77 if (!accel_list
[i
].available()) {
78 printf("%s not supported for this target\n",
82 *(accel_list
[i
].allowed
) = true;
83 ret
= accel_list
[i
].init(mc
);
86 fprintf(stderr
, "failed to initialize %s: %s\n",
89 *(accel_list
[i
].allowed
) = false;
91 accel_initialised
= true;
96 if (i
== ARRAY_SIZE(accel_list
)) {
97 fprintf(stderr
, "\"%s\" accelerator does not exist.\n", buf
);
101 if (!accel_initialised
) {
103 fprintf(stderr
, "No accelerator found!\n");
109 fprintf(stderr
, "Back to %s accelerator.\n", accel_list
[i
].name
);
112 return !accel_initialised
;