]>
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 | ||
a2246552 EH |
58 | /* Lookup AccelType from opt_name. Returns NULL if not found */ |
59 | static AccelType *accel_find(const char *opt_name) | |
60 | { | |
61 | int i; | |
62 | for (i = 0; i < ARRAY_SIZE(accel_list); i++) { | |
63 | AccelType *acc = &accel_list[i]; | |
64 | if (acc->opt_name && strcmp(acc->opt_name, opt_name) == 0) { | |
65 | return acc; | |
66 | } | |
67 | } | |
68 | return NULL; | |
69 | } | |
70 | ||
a1a9cb0c EH |
71 | int configure_accelerator(MachineClass *mc) |
72 | { | |
73 | const char *p; | |
74 | char buf[10]; | |
a2246552 | 75 | int ret; |
a1a9cb0c EH |
76 | bool accel_initialised = false; |
77 | bool init_failed = false; | |
e8b466ef | 78 | AccelType *acc = NULL; |
a1a9cb0c EH |
79 | |
80 | p = qemu_opt_get(qemu_get_machine_opts(), "accel"); | |
81 | if (p == NULL) { | |
82 | /* Use the default "accelerator", tcg */ | |
83 | p = "tcg"; | |
84 | } | |
85 | ||
86 | while (!accel_initialised && *p != '\0') { | |
87 | if (*p == ':') { | |
88 | p++; | |
89 | } | |
90 | p = get_opt_name(buf, sizeof(buf), p, ':'); | |
a2246552 EH |
91 | acc = accel_find(buf); |
92 | if (!acc) { | |
a1a9cb0c | 93 | fprintf(stderr, "\"%s\" accelerator does not exist.\n", buf); |
a2246552 EH |
94 | continue; |
95 | } | |
96 | if (!acc->available()) { | |
97 | printf("%s not supported for this target\n", | |
98 | acc->name); | |
99 | continue; | |
100 | } | |
101 | *(acc->allowed) = true; | |
102 | ret = acc->init(mc); | |
103 | if (ret < 0) { | |
104 | init_failed = true; | |
105 | fprintf(stderr, "failed to initialize %s: %s\n", | |
106 | acc->name, | |
107 | strerror(-ret)); | |
108 | *(acc->allowed) = false; | |
109 | } else { | |
110 | accel_initialised = true; | |
a1a9cb0c EH |
111 | } |
112 | } | |
113 | ||
114 | if (!accel_initialised) { | |
115 | if (!init_failed) { | |
116 | fprintf(stderr, "No accelerator found!\n"); | |
117 | } | |
118 | exit(1); | |
119 | } | |
120 | ||
121 | if (init_failed) { | |
e8b466ef | 122 | fprintf(stderr, "Back to %s accelerator.\n", acc->name); |
a1a9cb0c EH |
123 | } |
124 | ||
125 | return !accel_initialised; | |
126 | } |