]>
Commit | Line | Data |
---|---|---|
dd83b06a AF |
1 | /* |
2 | * QEMU CPU model | |
3 | * | |
4 | * Copyright (c) 2012 SUSE LINUX Products GmbH | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU General Public License | |
8 | * as published by the Free Software Foundation; either version 2 | |
9 | * of the License, or (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, see | |
18 | * <http://www.gnu.org/licenses/gpl-2.0.html> | |
19 | */ | |
20 | ||
dd83b06a | 21 | #include "qemu-common.h" |
878096ee | 22 | #include "qom/cpu.h" |
13eed94e | 23 | #include "sysemu/kvm.h" |
066e9b27 IM |
24 | #include "qemu/notify.h" |
25 | #include "sysemu/sysemu.h" | |
26 | ||
69e5ff06 IM |
27 | typedef struct CPUExistsArgs { |
28 | int64_t id; | |
29 | bool found; | |
30 | } CPUExistsArgs; | |
31 | ||
32 | static void cpu_exist_cb(CPUState *cpu, void *data) | |
33 | { | |
34 | CPUClass *klass = CPU_GET_CLASS(cpu); | |
35 | CPUExistsArgs *arg = data; | |
36 | ||
37 | if (klass->get_arch_id(cpu) == arg->id) { | |
38 | arg->found = true; | |
39 | } | |
40 | } | |
41 | ||
42 | bool cpu_exists(int64_t id) | |
43 | { | |
44 | CPUExistsArgs data = { | |
45 | .id = id, | |
46 | .found = false, | |
47 | }; | |
48 | ||
49 | qemu_for_each_cpu(cpu_exist_cb, &data); | |
50 | return data.found; | |
51 | } | |
52 | ||
444d5590 AF |
53 | bool cpu_paging_enabled(const CPUState *cpu) |
54 | { | |
55 | CPUClass *cc = CPU_GET_CLASS(cpu); | |
56 | ||
57 | return cc->get_paging_enabled(cpu); | |
58 | } | |
59 | ||
60 | static bool cpu_common_get_paging_enabled(const CPUState *cpu) | |
61 | { | |
6db297ea | 62 | return false; |
444d5590 AF |
63 | } |
64 | ||
a23bbfda AF |
65 | void cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list, |
66 | Error **errp) | |
67 | { | |
68 | CPUClass *cc = CPU_GET_CLASS(cpu); | |
69 | ||
70 | return cc->get_memory_mapping(cpu, list, errp); | |
71 | } | |
72 | ||
73 | static void cpu_common_get_memory_mapping(CPUState *cpu, | |
74 | MemoryMappingList *list, | |
75 | Error **errp) | |
76 | { | |
77 | error_setg(errp, "Obtaining memory mappings is unsupported on this CPU."); | |
78 | } | |
79 | ||
066e9b27 IM |
80 | /* CPU hot-plug notifiers */ |
81 | static NotifierList cpu_added_notifiers = | |
82 | NOTIFIER_LIST_INITIALIZER(cpu_add_notifiers); | |
83 | ||
84 | void qemu_register_cpu_added_notifier(Notifier *notifier) | |
85 | { | |
86 | notifier_list_add(&cpu_added_notifiers, notifier); | |
87 | } | |
dd83b06a | 88 | |
d8ed887b AF |
89 | void cpu_reset_interrupt(CPUState *cpu, int mask) |
90 | { | |
91 | cpu->interrupt_request &= ~mask; | |
92 | } | |
93 | ||
60a3e17a AF |
94 | void cpu_exit(CPUState *cpu) |
95 | { | |
96 | cpu->exit_request = 1; | |
97 | cpu->tcg_exit_req = 1; | |
98 | } | |
99 | ||
c72bf468 JF |
100 | int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu, |
101 | void *opaque) | |
102 | { | |
103 | CPUClass *cc = CPU_GET_CLASS(cpu); | |
104 | ||
105 | return (*cc->write_elf32_qemunote)(f, cpu, opaque); | |
106 | } | |
107 | ||
108 | static int cpu_common_write_elf32_qemunote(WriteCoreDumpFunction f, | |
109 | CPUState *cpu, void *opaque) | |
110 | { | |
111 | return -1; | |
112 | } | |
113 | ||
114 | int cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu, | |
115 | int cpuid, void *opaque) | |
116 | { | |
117 | CPUClass *cc = CPU_GET_CLASS(cpu); | |
118 | ||
119 | return (*cc->write_elf32_note)(f, cpu, cpuid, opaque); | |
120 | } | |
121 | ||
122 | static int cpu_common_write_elf32_note(WriteCoreDumpFunction f, | |
123 | CPUState *cpu, int cpuid, | |
124 | void *opaque) | |
125 | { | |
126 | return -1; | |
127 | } | |
128 | ||
129 | int cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu, | |
130 | void *opaque) | |
131 | { | |
132 | CPUClass *cc = CPU_GET_CLASS(cpu); | |
133 | ||
134 | return (*cc->write_elf64_qemunote)(f, cpu, opaque); | |
135 | } | |
136 | ||
137 | static int cpu_common_write_elf64_qemunote(WriteCoreDumpFunction f, | |
138 | CPUState *cpu, void *opaque) | |
139 | { | |
140 | return -1; | |
141 | } | |
142 | ||
143 | int cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu, | |
144 | int cpuid, void *opaque) | |
145 | { | |
146 | CPUClass *cc = CPU_GET_CLASS(cpu); | |
147 | ||
148 | return (*cc->write_elf64_note)(f, cpu, cpuid, opaque); | |
149 | } | |
150 | ||
151 | static int cpu_common_write_elf64_note(WriteCoreDumpFunction f, | |
152 | CPUState *cpu, int cpuid, | |
153 | void *opaque) | |
154 | { | |
155 | return -1; | |
156 | } | |
157 | ||
158 | ||
878096ee AF |
159 | void cpu_dump_state(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf, |
160 | int flags) | |
161 | { | |
162 | CPUClass *cc = CPU_GET_CLASS(cpu); | |
163 | ||
164 | if (cc->dump_state) { | |
165 | cc->dump_state(cpu, f, cpu_fprintf, flags); | |
166 | } | |
167 | } | |
168 | ||
169 | void cpu_dump_statistics(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf, | |
170 | int flags) | |
171 | { | |
172 | CPUClass *cc = CPU_GET_CLASS(cpu); | |
173 | ||
174 | if (cc->dump_statistics) { | |
175 | cc->dump_statistics(cpu, f, cpu_fprintf, flags); | |
176 | } | |
177 | } | |
178 | ||
dd83b06a AF |
179 | void cpu_reset(CPUState *cpu) |
180 | { | |
181 | CPUClass *klass = CPU_GET_CLASS(cpu); | |
182 | ||
183 | if (klass->reset != NULL) { | |
184 | (*klass->reset)(cpu); | |
185 | } | |
186 | } | |
187 | ||
188 | static void cpu_common_reset(CPUState *cpu) | |
189 | { | |
fcd7d003 | 190 | cpu->exit_request = 0; |
259186a7 | 191 | cpu->interrupt_request = 0; |
d77953b9 | 192 | cpu->current_tb = NULL; |
259186a7 | 193 | cpu->halted = 0; |
dd83b06a AF |
194 | } |
195 | ||
2b8c2754 AF |
196 | ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model) |
197 | { | |
198 | CPUClass *cc = CPU_CLASS(object_class_by_name(typename)); | |
199 | ||
200 | return cc->class_by_name(cpu_model); | |
201 | } | |
202 | ||
203 | static ObjectClass *cpu_common_class_by_name(const char *cpu_model) | |
204 | { | |
205 | return NULL; | |
206 | } | |
207 | ||
4f658099 AF |
208 | static void cpu_common_realizefn(DeviceState *dev, Error **errp) |
209 | { | |
13eed94e IM |
210 | CPUState *cpu = CPU(dev); |
211 | ||
212 | if (dev->hotplugged) { | |
213 | cpu_synchronize_post_init(cpu); | |
066e9b27 | 214 | notifier_list_notify(&cpu_added_notifiers, dev); |
6afb4721 | 215 | cpu_resume(cpu); |
13eed94e | 216 | } |
4f658099 AF |
217 | } |
218 | ||
997395d3 IM |
219 | static int64_t cpu_common_get_arch_id(CPUState *cpu) |
220 | { | |
221 | return cpu->cpu_index; | |
222 | } | |
223 | ||
dd83b06a AF |
224 | static void cpu_class_init(ObjectClass *klass, void *data) |
225 | { | |
961f8395 | 226 | DeviceClass *dc = DEVICE_CLASS(klass); |
dd83b06a AF |
227 | CPUClass *k = CPU_CLASS(klass); |
228 | ||
2b8c2754 | 229 | k->class_by_name = cpu_common_class_by_name; |
dd83b06a | 230 | k->reset = cpu_common_reset; |
997395d3 | 231 | k->get_arch_id = cpu_common_get_arch_id; |
444d5590 | 232 | k->get_paging_enabled = cpu_common_get_paging_enabled; |
a23bbfda | 233 | k->get_memory_mapping = cpu_common_get_memory_mapping; |
c72bf468 JF |
234 | k->write_elf32_qemunote = cpu_common_write_elf32_qemunote; |
235 | k->write_elf32_note = cpu_common_write_elf32_note; | |
236 | k->write_elf64_qemunote = cpu_common_write_elf64_qemunote; | |
237 | k->write_elf64_note = cpu_common_write_elf64_note; | |
4f658099 | 238 | dc->realize = cpu_common_realizefn; |
961f8395 | 239 | dc->no_user = 1; |
dd83b06a AF |
240 | } |
241 | ||
961f8395 | 242 | static const TypeInfo cpu_type_info = { |
dd83b06a | 243 | .name = TYPE_CPU, |
961f8395 | 244 | .parent = TYPE_DEVICE, |
dd83b06a AF |
245 | .instance_size = sizeof(CPUState), |
246 | .abstract = true, | |
247 | .class_size = sizeof(CPUClass), | |
248 | .class_init = cpu_class_init, | |
249 | }; | |
250 | ||
251 | static void cpu_register_types(void) | |
252 | { | |
253 | type_register_static(&cpu_type_info); | |
254 | } | |
255 | ||
256 | type_init(cpu_register_types) |