]>
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 | #ifndef QEMU_CPU_H | |
21 | #define QEMU_CPU_H | |
22 | ||
fcd7d003 | 23 | #include <signal.h> |
961f8395 | 24 | #include "hw/qdev-core.h" |
1de7afc9 | 25 | #include "qemu/thread.h" |
dd83b06a AF |
26 | |
27 | /** | |
28 | * SECTION:cpu | |
29 | * @section_id: QEMU-cpu | |
30 | * @title: CPU Class | |
31 | * @short_description: Base class for all CPUs | |
32 | */ | |
33 | ||
34 | #define TYPE_CPU "cpu" | |
35 | ||
36 | #define CPU(obj) OBJECT_CHECK(CPUState, (obj), TYPE_CPU) | |
37 | #define CPU_CLASS(class) OBJECT_CLASS_CHECK(CPUClass, (class), TYPE_CPU) | |
38 | #define CPU_GET_CLASS(obj) OBJECT_GET_CLASS(CPUClass, (obj), TYPE_CPU) | |
39 | ||
40 | typedef struct CPUState CPUState; | |
41 | ||
42 | /** | |
43 | * CPUClass: | |
2b8c2754 AF |
44 | * @class_by_name: Callback to map -cpu command line model name to an |
45 | * instantiatable CPU type. | |
f5df5baf | 46 | * @reset: Callback to reset the #CPUState to its initial state. |
97a8ea5a | 47 | * @do_interrupt: Callback for interrupt handling. |
997395d3 | 48 | * @get_arch_id: Callback for getting architecture-dependent CPU ID. |
b170fce3 | 49 | * @vmsd: State description for migration. |
dd83b06a AF |
50 | * |
51 | * Represents a CPU family or model. | |
52 | */ | |
53 | typedef struct CPUClass { | |
54 | /*< private >*/ | |
961f8395 | 55 | DeviceClass parent_class; |
dd83b06a AF |
56 | /*< public >*/ |
57 | ||
2b8c2754 AF |
58 | ObjectClass *(*class_by_name)(const char *cpu_model); |
59 | ||
dd83b06a | 60 | void (*reset)(CPUState *cpu); |
97a8ea5a | 61 | void (*do_interrupt)(CPUState *cpu); |
997395d3 | 62 | int64_t (*get_arch_id)(CPUState *cpu); |
b170fce3 AF |
63 | |
64 | const struct VMStateDescription *vmsd; | |
dd83b06a AF |
65 | } CPUClass; |
66 | ||
a60f24b5 | 67 | struct KVMState; |
f7575c96 | 68 | struct kvm_run; |
a60f24b5 | 69 | |
dd83b06a AF |
70 | /** |
71 | * CPUState: | |
55e5c285 | 72 | * @cpu_index: CPU index (informative). |
ce3960eb AF |
73 | * @nr_cores: Number of cores within this CPU package. |
74 | * @nr_threads: Number of threads within this CPU. | |
1b1ed8dc | 75 | * @numa_node: NUMA node this CPU is belonging to. |
0d34282f | 76 | * @host_tid: Host thread ID. |
0315c31c | 77 | * @running: #true if CPU is currently running (usermode). |
61a46217 | 78 | * @created: Indicates whether the CPU thread has been successfully created. |
259186a7 AF |
79 | * @interrupt_request: Indicates a pending interrupt request. |
80 | * @halted: Nonzero if the CPU is in suspended state. | |
4fdeee7c | 81 | * @stop: Indicates a pending stop request. |
f324e766 | 82 | * @stopped: Indicates the CPU has been artificially stopped. |
378df4b2 PM |
83 | * @tcg_exit_req: Set to force TCG to stop executing linked TBs for this |
84 | * CPU and return to its top level loop. | |
c05efcb1 | 85 | * @env_ptr: Pointer to subclass-specific CPUArchState field. |
d77953b9 | 86 | * @current_tb: Currently executing TB. |
8737c51c | 87 | * @kvm_fd: vCPU file descriptor for KVM. |
dd83b06a AF |
88 | * |
89 | * State of one CPU core or thread. | |
90 | */ | |
91 | struct CPUState { | |
92 | /*< private >*/ | |
961f8395 | 93 | DeviceState parent_obj; |
dd83b06a AF |
94 | /*< public >*/ |
95 | ||
ce3960eb AF |
96 | int nr_cores; |
97 | int nr_threads; | |
1b1ed8dc | 98 | int numa_node; |
ce3960eb | 99 | |
814e612e | 100 | struct QemuThread *thread; |
bcba2a72 AF |
101 | #ifdef _WIN32 |
102 | HANDLE hThread; | |
103 | #endif | |
9f09e18a | 104 | int thread_id; |
0d34282f | 105 | uint32_t host_tid; |
0315c31c | 106 | bool running; |
f5c121b8 | 107 | struct QemuCond *halt_cond; |
c64ca814 | 108 | struct qemu_work_item *queued_work_first, *queued_work_last; |
216fc9a4 | 109 | bool thread_kicked; |
61a46217 | 110 | bool created; |
4fdeee7c | 111 | bool stop; |
f324e766 | 112 | bool stopped; |
fcd7d003 | 113 | volatile sig_atomic_t exit_request; |
378df4b2 | 114 | volatile sig_atomic_t tcg_exit_req; |
259186a7 | 115 | uint32_t interrupt_request; |
bcba2a72 | 116 | |
c05efcb1 | 117 | void *env_ptr; /* CPUArchState */ |
d77953b9 AF |
118 | struct TranslationBlock *current_tb; |
119 | ||
8737c51c | 120 | int kvm_fd; |
20d695a9 | 121 | bool kvm_vcpu_dirty; |
a60f24b5 | 122 | struct KVMState *kvm_state; |
f7575c96 | 123 | struct kvm_run *kvm_run; |
8737c51c | 124 | |
f5df5baf | 125 | /* TODO Move common fields from CPUArchState here. */ |
55e5c285 | 126 | int cpu_index; /* used by alpha TCG */ |
259186a7 | 127 | uint32_t halted; /* used by alpha, cris, ppc TCG */ |
dd83b06a AF |
128 | }; |
129 | ||
130 | ||
131 | /** | |
132 | * cpu_reset: | |
133 | * @cpu: The CPU whose state is to be reset. | |
134 | */ | |
135 | void cpu_reset(CPUState *cpu); | |
136 | ||
2b8c2754 AF |
137 | /** |
138 | * cpu_class_by_name: | |
139 | * @typename: The CPU base type. | |
140 | * @cpu_model: The model string without any parameters. | |
141 | * | |
142 | * Looks up a CPU #ObjectClass matching name @cpu_model. | |
143 | * | |
144 | * Returns: A #CPUClass or %NULL if not matching class is found. | |
145 | */ | |
146 | ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model); | |
147 | ||
ca91b15f AF |
148 | /** |
149 | * cpu_class_set_vmsd: | |
150 | * @cc: CPU class | |
151 | * @value: Value to set. Unused for %CONFIG_USER_ONLY. | |
152 | * | |
153 | * Sets #VMStateDescription for @cc. | |
154 | * | |
155 | * The @value argument is intentionally discarded for the non-softmmu targets | |
156 | * to avoid linker errors or excessive preprocessor usage. If this behavior | |
157 | * is undesired, you should assign #CPUState.vmsd directly instead. | |
158 | */ | |
159 | #ifndef CONFIG_USER_ONLY | |
160 | static inline void cpu_class_set_vmsd(CPUClass *cc, | |
161 | const struct VMStateDescription *value) | |
162 | { | |
163 | cc->vmsd = value; | |
164 | } | |
165 | #else | |
166 | #define cpu_class_set_vmsd(cc, value) ((cc)->vmsd = NULL) | |
167 | #endif | |
168 | ||
3993c6bd AF |
169 | /** |
170 | * qemu_cpu_has_work: | |
171 | * @cpu: The vCPU to check. | |
172 | * | |
173 | * Checks whether the CPU has work to do. | |
174 | * | |
175 | * Returns: %true if the CPU has work, %false otherwise. | |
176 | */ | |
177 | bool qemu_cpu_has_work(CPUState *cpu); | |
178 | ||
60e82579 AF |
179 | /** |
180 | * qemu_cpu_is_self: | |
181 | * @cpu: The vCPU to check against. | |
182 | * | |
183 | * Checks whether the caller is executing on the vCPU thread. | |
184 | * | |
185 | * Returns: %true if called from @cpu's thread, %false otherwise. | |
186 | */ | |
187 | bool qemu_cpu_is_self(CPUState *cpu); | |
188 | ||
c08d7424 AF |
189 | /** |
190 | * qemu_cpu_kick: | |
191 | * @cpu: The vCPU to kick. | |
192 | * | |
193 | * Kicks @cpu's thread. | |
194 | */ | |
195 | void qemu_cpu_kick(CPUState *cpu); | |
196 | ||
2fa45344 AF |
197 | /** |
198 | * cpu_is_stopped: | |
199 | * @cpu: The CPU to check. | |
200 | * | |
201 | * Checks whether the CPU is stopped. | |
202 | * | |
203 | * Returns: %true if run state is not running or if artificially stopped; | |
204 | * %false otherwise. | |
205 | */ | |
206 | bool cpu_is_stopped(CPUState *cpu); | |
207 | ||
f100f0b3 AF |
208 | /** |
209 | * run_on_cpu: | |
210 | * @cpu: The vCPU to run on. | |
211 | * @func: The function to be executed. | |
212 | * @data: Data to pass to the function. | |
213 | * | |
214 | * Schedules the function @func for execution on the vCPU @cpu. | |
215 | */ | |
216 | void run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data); | |
217 | ||
38d8f5c8 AF |
218 | /** |
219 | * qemu_get_cpu: | |
220 | * @index: The CPUState@cpu_index value of the CPU to obtain. | |
221 | * | |
222 | * Gets a CPU matching @index. | |
223 | * | |
224 | * Returns: The CPU or %NULL if there is no matching CPU. | |
225 | */ | |
226 | CPUState *qemu_get_cpu(int index); | |
227 | ||
c3affe56 AF |
228 | #ifndef CONFIG_USER_ONLY |
229 | ||
230 | typedef void (*CPUInterruptHandler)(CPUState *, int); | |
231 | ||
232 | extern CPUInterruptHandler cpu_interrupt_handler; | |
233 | ||
234 | /** | |
235 | * cpu_interrupt: | |
236 | * @cpu: The CPU to set an interrupt on. | |
237 | * @mask: The interupts to set. | |
238 | * | |
239 | * Invokes the interrupt handler. | |
240 | */ | |
241 | static inline void cpu_interrupt(CPUState *cpu, int mask) | |
242 | { | |
243 | cpu_interrupt_handler(cpu, mask); | |
244 | } | |
245 | ||
246 | #else /* USER_ONLY */ | |
247 | ||
248 | void cpu_interrupt(CPUState *cpu, int mask); | |
249 | ||
250 | #endif /* USER_ONLY */ | |
251 | ||
d8ed887b AF |
252 | /** |
253 | * cpu_reset_interrupt: | |
254 | * @cpu: The CPU to clear the interrupt on. | |
255 | * @mask: The interrupt mask to clear. | |
256 | * | |
257 | * Resets interrupts on the vCPU @cpu. | |
258 | */ | |
259 | void cpu_reset_interrupt(CPUState *cpu, int mask); | |
260 | ||
2993683b IM |
261 | /** |
262 | * cpu_resume: | |
263 | * @cpu: The CPU to resume. | |
264 | * | |
265 | * Resumes CPU, i.e. puts CPU into runnable state. | |
266 | */ | |
267 | void cpu_resume(CPUState *cpu); | |
dd83b06a AF |
268 | |
269 | #endif |