]>
Commit | Line | Data |
---|---|---|
a1a9cb0c EH |
1 | /* |
2 | * QEMU System Emulator, accelerator interfaces | |
3 | * | |
4 | * Copyright (c) 2003-2008 Fabrice Bellard | |
5 | * Copyright (c) 2014 Red Hat Inc. | |
6 | * | |
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: | |
13 | * | |
14 | * The above copyright notice and this permission notice shall be included in | |
15 | * all copies or substantial portions of the Software. | |
16 | * | |
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 | |
23 | * THE SOFTWARE. | |
24 | */ | |
25 | ||
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" | |
33 | ||
34 | int tcg_tb_size; | |
35 | static bool tcg_allowed = true; | |
36 | ||
37 | static int tcg_init(MachineClass *mc) | |
38 | { | |
39 | tcg_exec_init(tcg_tb_size * 1024 * 1024); | |
40 | return 0; | |
41 | } | |
42 | ||
e54adde6 | 43 | typedef struct AccelType { |
a1a9cb0c EH |
44 | const char *opt_name; |
45 | const char *name; | |
46 | int (*available)(void); | |
47 | int (*init)(MachineClass *mc); | |
48 | bool *allowed; | |
e54adde6 EH |
49 | } AccelType; |
50 | ||
51 | static AccelType accel_list[] = { | |
a1a9cb0c EH |
52 | { "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed }, |
53 | { "xen", "Xen", xen_available, xen_init, &xen_allowed }, | |
54 | { "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed }, | |
55 | { "qtest", "QTest", qtest_available, qtest_init_accel, &qtest_allowed }, | |
56 | }; | |
57 | ||
58 | int configure_accelerator(MachineClass *mc) | |
59 | { | |
60 | const char *p; | |
61 | char buf[10]; | |
62 | int i, ret; | |
63 | bool accel_initialised = false; | |
64 | bool init_failed = false; | |
65 | ||
66 | p = qemu_opt_get(qemu_get_machine_opts(), "accel"); | |
67 | if (p == NULL) { | |
68 | /* Use the default "accelerator", tcg */ | |
69 | p = "tcg"; | |
70 | } | |
71 | ||
72 | while (!accel_initialised && *p != '\0') { | |
73 | if (*p == ':') { | |
74 | p++; | |
75 | } | |
76 | p = get_opt_name(buf, sizeof(buf), p, ':'); | |
77 | for (i = 0; i < ARRAY_SIZE(accel_list); i++) { | |
78 | if (strcmp(accel_list[i].opt_name, buf) == 0) { | |
79 | if (!accel_list[i].available()) { | |
80 | printf("%s not supported for this target\n", | |
81 | accel_list[i].name); | |
82 | break; | |
83 | } | |
84 | *(accel_list[i].allowed) = true; | |
85 | ret = accel_list[i].init(mc); | |
86 | if (ret < 0) { | |
87 | init_failed = true; | |
88 | fprintf(stderr, "failed to initialize %s: %s\n", | |
89 | accel_list[i].name, | |
90 | strerror(-ret)); | |
91 | *(accel_list[i].allowed) = false; | |
92 | } else { | |
93 | accel_initialised = true; | |
94 | } | |
95 | break; | |
96 | } | |
97 | } | |
98 | if (i == ARRAY_SIZE(accel_list)) { | |
99 | fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf); | |
100 | } | |
101 | } | |
102 | ||
103 | if (!accel_initialised) { | |
104 | if (!init_failed) { | |
105 | fprintf(stderr, "No accelerator found!\n"); | |
106 | } | |
107 | exit(1); | |
108 | } | |
109 | ||
110 | if (init_failed) { | |
111 | fprintf(stderr, "Back to %s accelerator.\n", accel_list[i].name); | |
112 | } | |
113 | ||
114 | return !accel_initialised; | |
115 | } |