spapr: add node-id property to sPAPR core
[qemu/ar7.git] / include / qom / cpu.h
blob55214ce131ae5fb19ba9628a92982bbdaa56a605
1 /*
2 * QEMU CPU model
4 * Copyright (c) 2012 SUSE LINUX Products GmbH
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.
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.
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>
20 #ifndef QEMU_CPU_H
21 #define QEMU_CPU_H
23 #include "hw/qdev-core.h"
24 #include "disas/bfd.h"
25 #include "exec/hwaddr.h"
26 #include "exec/memattrs.h"
27 #include "qemu/bitmap.h"
28 #include "qemu/queue.h"
29 #include "qemu/thread.h"
31 typedef int (*WriteCoreDumpFunction)(const void *buf, size_t size,
32 void *opaque);
34 /**
35 * vaddr:
36 * Type wide enough to contain any #target_ulong virtual address.
38 typedef uint64_t vaddr;
39 #define VADDR_PRId PRId64
40 #define VADDR_PRIu PRIu64
41 #define VADDR_PRIo PRIo64
42 #define VADDR_PRIx PRIx64
43 #define VADDR_PRIX PRIX64
44 #define VADDR_MAX UINT64_MAX
46 /**
47 * SECTION:cpu
48 * @section_id: QEMU-cpu
49 * @title: CPU Class
50 * @short_description: Base class for all CPUs
53 #define TYPE_CPU "cpu"
55 /* Since this macro is used a lot in hot code paths and in conjunction with
56 * FooCPU *foo_env_get_cpu(), we deviate from usual QOM practice by using
57 * an unchecked cast.
59 #define CPU(obj) ((CPUState *)(obj))
61 #define CPU_CLASS(class) OBJECT_CLASS_CHECK(CPUClass, (class), TYPE_CPU)
62 #define CPU_GET_CLASS(obj) OBJECT_GET_CLASS(CPUClass, (obj), TYPE_CPU)
64 typedef enum MMUAccessType {
65 MMU_DATA_LOAD = 0,
66 MMU_DATA_STORE = 1,
67 MMU_INST_FETCH = 2
68 } MMUAccessType;
70 typedef struct CPUWatchpoint CPUWatchpoint;
72 typedef void (*CPUUnassignedAccess)(CPUState *cpu, hwaddr addr,
73 bool is_write, bool is_exec, int opaque,
74 unsigned size);
76 struct TranslationBlock;
78 /**
79 * CPUClass:
80 * @class_by_name: Callback to map -cpu command line model name to an
81 * instantiatable CPU type.
82 * @parse_features: Callback to parse command line arguments.
83 * @reset: Callback to reset the #CPUState to its initial state.
84 * @reset_dump_flags: #CPUDumpFlags to use for reset logging.
85 * @has_work: Callback for checking if there is work to do.
86 * @do_interrupt: Callback for interrupt handling.
87 * @do_unassigned_access: Callback for unassigned access handling.
88 * @do_unaligned_access: Callback for unaligned access handling, if
89 * the target defines #ALIGNED_ONLY.
90 * @virtio_is_big_endian: Callback to return %true if a CPU which supports
91 * runtime configurable endianness is currently big-endian. Non-configurable
92 * CPUs can use the default implementation of this method. This method should
93 * not be used by any callers other than the pre-1.0 virtio devices.
94 * @memory_rw_debug: Callback for GDB memory access.
95 * @dump_state: Callback for dumping state.
96 * @dump_statistics: Callback for dumping statistics.
97 * @get_arch_id: Callback for getting architecture-dependent CPU ID.
98 * @get_paging_enabled: Callback for inquiring whether paging is enabled.
99 * @get_memory_mapping: Callback for obtaining the memory mappings.
100 * @set_pc: Callback for setting the Program Counter register.
101 * @synchronize_from_tb: Callback for synchronizing state from a TCG
102 * #TranslationBlock.
103 * @handle_mmu_fault: Callback for handling an MMU fault.
104 * @get_phys_page_debug: Callback for obtaining a physical address.
105 * @get_phys_page_attrs_debug: Callback for obtaining a physical address and the
106 * associated memory transaction attributes to use for the access.
107 * CPUs which use memory transaction attributes should implement this
108 * instead of get_phys_page_debug.
109 * @asidx_from_attrs: Callback to return the CPU AddressSpace to use for
110 * a memory access with the specified memory transaction attributes.
111 * @gdb_read_register: Callback for letting GDB read a register.
112 * @gdb_write_register: Callback for letting GDB write a register.
113 * @debug_check_watchpoint: Callback: return true if the architectural
114 * watchpoint whose address has matched should really fire.
115 * @debug_excp_handler: Callback for handling debug exceptions.
116 * @write_elf64_note: Callback for writing a CPU-specific ELF note to a
117 * 64-bit VM coredump.
118 * @write_elf32_qemunote: Callback for writing a CPU- and QEMU-specific ELF
119 * note to a 32-bit VM coredump.
120 * @write_elf32_note: Callback for writing a CPU-specific ELF note to a
121 * 32-bit VM coredump.
122 * @write_elf32_qemunote: Callback for writing a CPU- and QEMU-specific ELF
123 * note to a 32-bit VM coredump.
124 * @vmsd: State description for migration.
125 * @gdb_num_core_regs: Number of core registers accessible to GDB.
126 * @gdb_core_xml_file: File name for core registers GDB XML description.
127 * @gdb_stop_before_watchpoint: Indicates whether GDB expects the CPU to stop
128 * before the insn which triggers a watchpoint rather than after it.
129 * @gdb_arch_name: Optional callback that returns the architecture name known
130 * to GDB. The caller must free the returned string with g_free.
131 * @cpu_exec_enter: Callback for cpu_exec preparation.
132 * @cpu_exec_exit: Callback for cpu_exec cleanup.
133 * @cpu_exec_interrupt: Callback for processing interrupts in cpu_exec.
134 * @disas_set_info: Setup architecture specific components of disassembly info
135 * @adjust_watchpoint_address: Perform a target-specific adjustment to an
136 * address before attempting to match it against watchpoints.
138 * Represents a CPU family or model.
140 typedef struct CPUClass {
141 /*< private >*/
142 DeviceClass parent_class;
143 /*< public >*/
145 ObjectClass *(*class_by_name)(const char *cpu_model);
146 void (*parse_features)(const char *typename, char *str, Error **errp);
148 void (*reset)(CPUState *cpu);
149 int reset_dump_flags;
150 bool (*has_work)(CPUState *cpu);
151 void (*do_interrupt)(CPUState *cpu);
152 CPUUnassignedAccess do_unassigned_access;
153 void (*do_unaligned_access)(CPUState *cpu, vaddr addr,
154 MMUAccessType access_type,
155 int mmu_idx, uintptr_t retaddr);
156 bool (*virtio_is_big_endian)(CPUState *cpu);
157 int (*memory_rw_debug)(CPUState *cpu, vaddr addr,
158 uint8_t *buf, int len, bool is_write);
159 void (*dump_state)(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,
160 int flags);
161 GuestPanicInformation* (*get_crash_info)(CPUState *cpu);
162 void (*dump_statistics)(CPUState *cpu, FILE *f,
163 fprintf_function cpu_fprintf, int flags);
164 int64_t (*get_arch_id)(CPUState *cpu);
165 bool (*get_paging_enabled)(const CPUState *cpu);
166 void (*get_memory_mapping)(CPUState *cpu, MemoryMappingList *list,
167 Error **errp);
168 void (*set_pc)(CPUState *cpu, vaddr value);
169 void (*synchronize_from_tb)(CPUState *cpu, struct TranslationBlock *tb);
170 int (*handle_mmu_fault)(CPUState *cpu, vaddr address, int rw,
171 int mmu_index);
172 hwaddr (*get_phys_page_debug)(CPUState *cpu, vaddr addr);
173 hwaddr (*get_phys_page_attrs_debug)(CPUState *cpu, vaddr addr,
174 MemTxAttrs *attrs);
175 int (*asidx_from_attrs)(CPUState *cpu, MemTxAttrs attrs);
176 int (*gdb_read_register)(CPUState *cpu, uint8_t *buf, int reg);
177 int (*gdb_write_register)(CPUState *cpu, uint8_t *buf, int reg);
178 bool (*debug_check_watchpoint)(CPUState *cpu, CPUWatchpoint *wp);
179 void (*debug_excp_handler)(CPUState *cpu);
181 int (*write_elf64_note)(WriteCoreDumpFunction f, CPUState *cpu,
182 int cpuid, void *opaque);
183 int (*write_elf64_qemunote)(WriteCoreDumpFunction f, CPUState *cpu,
184 void *opaque);
185 int (*write_elf32_note)(WriteCoreDumpFunction f, CPUState *cpu,
186 int cpuid, void *opaque);
187 int (*write_elf32_qemunote)(WriteCoreDumpFunction f, CPUState *cpu,
188 void *opaque);
190 const struct VMStateDescription *vmsd;
191 int gdb_num_core_regs;
192 const char *gdb_core_xml_file;
193 gchar * (*gdb_arch_name)(CPUState *cpu);
194 bool gdb_stop_before_watchpoint;
196 void (*cpu_exec_enter)(CPUState *cpu);
197 void (*cpu_exec_exit)(CPUState *cpu);
198 bool (*cpu_exec_interrupt)(CPUState *cpu, int interrupt_request);
200 void (*disas_set_info)(CPUState *cpu, disassemble_info *info);
201 vaddr (*adjust_watchpoint_address)(CPUState *cpu, vaddr addr, int len);
202 } CPUClass;
204 #ifdef HOST_WORDS_BIGENDIAN
205 typedef struct icount_decr_u16 {
206 uint16_t high;
207 uint16_t low;
208 } icount_decr_u16;
209 #else
210 typedef struct icount_decr_u16 {
211 uint16_t low;
212 uint16_t high;
213 } icount_decr_u16;
214 #endif
216 typedef struct CPUBreakpoint {
217 vaddr pc;
218 int flags; /* BP_* */
219 QTAILQ_ENTRY(CPUBreakpoint) entry;
220 } CPUBreakpoint;
222 struct CPUWatchpoint {
223 vaddr vaddr;
224 vaddr len;
225 vaddr hitaddr;
226 MemTxAttrs hitattrs;
227 int flags; /* BP_* */
228 QTAILQ_ENTRY(CPUWatchpoint) entry;
231 struct KVMState;
232 struct kvm_run;
234 struct hax_vcpu_state;
236 #define TB_JMP_CACHE_BITS 12
237 #define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS)
239 /* work queue */
241 /* The union type allows passing of 64 bit target pointers on 32 bit
242 * hosts in a single parameter
244 typedef union {
245 int host_int;
246 unsigned long host_ulong;
247 void *host_ptr;
248 vaddr target_ptr;
249 } run_on_cpu_data;
251 #define RUN_ON_CPU_HOST_PTR(p) ((run_on_cpu_data){.host_ptr = (p)})
252 #define RUN_ON_CPU_HOST_INT(i) ((run_on_cpu_data){.host_int = (i)})
253 #define RUN_ON_CPU_HOST_ULONG(ul) ((run_on_cpu_data){.host_ulong = (ul)})
254 #define RUN_ON_CPU_TARGET_PTR(v) ((run_on_cpu_data){.target_ptr = (v)})
255 #define RUN_ON_CPU_NULL RUN_ON_CPU_HOST_PTR(NULL)
257 typedef void (*run_on_cpu_func)(CPUState *cpu, run_on_cpu_data data);
259 struct qemu_work_item;
261 #define CPU_UNSET_NUMA_NODE_ID -1
264 * CPUState:
265 * @cpu_index: CPU index (informative).
266 * @nr_cores: Number of cores within this CPU package.
267 * @nr_threads: Number of threads within this CPU.
268 * @numa_node: NUMA node this CPU is belonging to.
269 * @host_tid: Host thread ID.
270 * @running: #true if CPU is currently running (lockless).
271 * @has_waiter: #true if a CPU is currently waiting for the cpu_exec_end;
272 * valid under cpu_list_lock.
273 * @created: Indicates whether the CPU thread has been successfully created.
274 * @interrupt_request: Indicates a pending interrupt request.
275 * @halted: Nonzero if the CPU is in suspended state.
276 * @stop: Indicates a pending stop request.
277 * @stopped: Indicates the CPU has been artificially stopped.
278 * @unplug: Indicates a pending CPU unplug request.
279 * @crash_occurred: Indicates the OS reported a crash (panic) for this CPU
280 * @singlestep_enabled: Flags for single-stepping.
281 * @icount_extra: Instructions until next timer event.
282 * @icount_decr: Low 16 bits: number of cycles left, only used in icount mode.
283 * High 16 bits: Set to -1 to force TCG to stop executing linked TBs for this
284 * CPU and return to its top level loop (even in non-icount mode).
285 * This allows a single read-compare-cbranch-write sequence to test
286 * for both decrementer underflow and exceptions.
287 * @can_do_io: Nonzero if memory-mapped IO is safe. Deterministic execution
288 * requires that IO only be performed on the last instruction of a TB
289 * so that interrupts take effect immediately.
290 * @cpu_ases: Pointer to array of CPUAddressSpaces (which define the
291 * AddressSpaces this CPU has)
292 * @num_ases: number of CPUAddressSpaces in @cpu_ases
293 * @as: Pointer to the first AddressSpace, for the convenience of targets which
294 * only have a single AddressSpace
295 * @env_ptr: Pointer to subclass-specific CPUArchState field.
296 * @gdb_regs: Additional GDB registers.
297 * @gdb_num_regs: Number of total registers accessible to GDB.
298 * @gdb_num_g_regs: Number of registers in GDB 'g' packets.
299 * @next_cpu: Next CPU sharing TB cache.
300 * @opaque: User data.
301 * @mem_io_pc: Host Program Counter at which the memory was accessed.
302 * @mem_io_vaddr: Target virtual address at which the memory was accessed.
303 * @kvm_fd: vCPU file descriptor for KVM.
304 * @work_mutex: Lock to prevent multiple access to queued_work_*.
305 * @queued_work_first: First asynchronous work pending.
306 * @trace_dstate: Dynamic tracing state of events for this vCPU (bitmask).
308 * State of one CPU core or thread.
310 struct CPUState {
311 /*< private >*/
312 DeviceState parent_obj;
313 /*< public >*/
315 int nr_cores;
316 int nr_threads;
317 int numa_node;
319 struct QemuThread *thread;
320 #ifdef _WIN32
321 HANDLE hThread;
322 #endif
323 int thread_id;
324 uint32_t host_tid;
325 bool running, has_waiter;
326 struct QemuCond *halt_cond;
327 bool thread_kicked;
328 bool created;
329 bool stop;
330 bool stopped;
331 bool unplug;
332 bool crash_occurred;
333 bool exit_request;
334 /* updates protected by BQL */
335 uint32_t interrupt_request;
336 int singlestep_enabled;
337 int64_t icount_budget;
338 int64_t icount_extra;
339 sigjmp_buf jmp_env;
341 QemuMutex work_mutex;
342 struct qemu_work_item *queued_work_first, *queued_work_last;
344 CPUAddressSpace *cpu_ases;
345 int num_ases;
346 AddressSpace *as;
347 MemoryRegion *memory;
349 void *env_ptr; /* CPUArchState */
351 /* Writes protected by tb_lock, reads not thread-safe */
352 struct TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE];
354 struct GDBRegisterState *gdb_regs;
355 int gdb_num_regs;
356 int gdb_num_g_regs;
357 QTAILQ_ENTRY(CPUState) node;
359 /* ice debug support */
360 QTAILQ_HEAD(breakpoints_head, CPUBreakpoint) breakpoints;
362 QTAILQ_HEAD(watchpoints_head, CPUWatchpoint) watchpoints;
363 CPUWatchpoint *watchpoint_hit;
365 void *opaque;
367 /* In order to avoid passing too many arguments to the MMIO helpers,
368 * we store some rarely used information in the CPU context.
370 uintptr_t mem_io_pc;
371 vaddr mem_io_vaddr;
373 int kvm_fd;
374 bool kvm_vcpu_dirty;
375 struct KVMState *kvm_state;
376 struct kvm_run *kvm_run;
379 * Used for events with 'vcpu' and *without* the 'disabled' properties.
380 * Dynamically allocated based on bitmap requried to hold up to
381 * trace_get_vcpu_event_count() entries.
383 unsigned long *trace_dstate;
385 /* TODO Move common fields from CPUArchState here. */
386 int cpu_index; /* used by alpha TCG */
387 uint32_t halted; /* used by alpha, cris, ppc TCG */
388 uint32_t can_do_io;
389 int32_t exception_index; /* used by m68k TCG */
391 /* Used to keep track of an outstanding cpu throttle thread for migration
392 * autoconverge
394 bool throttle_thread_scheduled;
396 /* Note that this is accessed at the start of every TB via a negative
397 offset from AREG0. Leave this field at the end so as to make the
398 (absolute value) offset as small as possible. This reduces code
399 size, especially for hosts without large memory offsets. */
400 union {
401 uint32_t u32;
402 icount_decr_u16 u16;
403 } icount_decr;
405 bool hax_vcpu_dirty;
406 struct hax_vcpu_state *hax_vcpu;
408 /* The pending_tlb_flush flag is set and cleared atomically to
409 * avoid potential races. The aim of the flag is to avoid
410 * unnecessary flushes.
412 uint16_t pending_tlb_flush;
415 QTAILQ_HEAD(CPUTailQ, CPUState);
416 extern struct CPUTailQ cpus;
417 #define CPU_NEXT(cpu) QTAILQ_NEXT(cpu, node)
418 #define CPU_FOREACH(cpu) QTAILQ_FOREACH(cpu, &cpus, node)
419 #define CPU_FOREACH_SAFE(cpu, next_cpu) \
420 QTAILQ_FOREACH_SAFE(cpu, &cpus, node, next_cpu)
421 #define CPU_FOREACH_REVERSE(cpu) \
422 QTAILQ_FOREACH_REVERSE(cpu, &cpus, CPUTailQ, node)
423 #define first_cpu QTAILQ_FIRST(&cpus)
425 extern __thread CPUState *current_cpu;
428 * qemu_tcg_mttcg_enabled:
429 * Check whether we are running MultiThread TCG or not.
431 * Returns: %true if we are in MTTCG mode %false otherwise.
433 extern bool mttcg_enabled;
434 #define qemu_tcg_mttcg_enabled() (mttcg_enabled)
437 * cpu_paging_enabled:
438 * @cpu: The CPU whose state is to be inspected.
440 * Returns: %true if paging is enabled, %false otherwise.
442 bool cpu_paging_enabled(const CPUState *cpu);
445 * cpu_get_memory_mapping:
446 * @cpu: The CPU whose memory mappings are to be obtained.
447 * @list: Where to write the memory mappings to.
448 * @errp: Pointer for reporting an #Error.
450 void cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list,
451 Error **errp);
454 * cpu_write_elf64_note:
455 * @f: pointer to a function that writes memory to a file
456 * @cpu: The CPU whose memory is to be dumped
457 * @cpuid: ID number of the CPU
458 * @opaque: pointer to the CPUState struct
460 int cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu,
461 int cpuid, void *opaque);
464 * cpu_write_elf64_qemunote:
465 * @f: pointer to a function that writes memory to a file
466 * @cpu: The CPU whose memory is to be dumped
467 * @cpuid: ID number of the CPU
468 * @opaque: pointer to the CPUState struct
470 int cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
471 void *opaque);
474 * cpu_write_elf32_note:
475 * @f: pointer to a function that writes memory to a file
476 * @cpu: The CPU whose memory is to be dumped
477 * @cpuid: ID number of the CPU
478 * @opaque: pointer to the CPUState struct
480 int cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu,
481 int cpuid, void *opaque);
484 * cpu_write_elf32_qemunote:
485 * @f: pointer to a function that writes memory to a file
486 * @cpu: The CPU whose memory is to be dumped
487 * @cpuid: ID number of the CPU
488 * @opaque: pointer to the CPUState struct
490 int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
491 void *opaque);
494 * cpu_get_crash_info:
495 * @cpu: The CPU to get crash information for
497 * Gets the previously saved crash information.
498 * Caller is responsible for freeing the data.
500 GuestPanicInformation *cpu_get_crash_info(CPUState *cpu);
503 * CPUDumpFlags:
504 * @CPU_DUMP_CODE:
505 * @CPU_DUMP_FPU: dump FPU register state, not just integer
506 * @CPU_DUMP_CCOP: dump info about TCG QEMU's condition code optimization state
508 enum CPUDumpFlags {
509 CPU_DUMP_CODE = 0x00010000,
510 CPU_DUMP_FPU = 0x00020000,
511 CPU_DUMP_CCOP = 0x00040000,
515 * cpu_dump_state:
516 * @cpu: The CPU whose state is to be dumped.
517 * @f: File to dump to.
518 * @cpu_fprintf: Function to dump with.
519 * @flags: Flags what to dump.
521 * Dumps CPU state.
523 void cpu_dump_state(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,
524 int flags);
527 * cpu_dump_statistics:
528 * @cpu: The CPU whose state is to be dumped.
529 * @f: File to dump to.
530 * @cpu_fprintf: Function to dump with.
531 * @flags: Flags what to dump.
533 * Dumps CPU statistics.
535 void cpu_dump_statistics(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,
536 int flags);
538 #ifndef CONFIG_USER_ONLY
540 * cpu_get_phys_page_attrs_debug:
541 * @cpu: The CPU to obtain the physical page address for.
542 * @addr: The virtual address.
543 * @attrs: Updated on return with the memory transaction attributes to use
544 * for this access.
546 * Obtains the physical page corresponding to a virtual one, together
547 * with the corresponding memory transaction attributes to use for the access.
548 * Use it only for debugging because no protection checks are done.
550 * Returns: Corresponding physical page address or -1 if no page found.
552 static inline hwaddr cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr,
553 MemTxAttrs *attrs)
555 CPUClass *cc = CPU_GET_CLASS(cpu);
557 if (cc->get_phys_page_attrs_debug) {
558 return cc->get_phys_page_attrs_debug(cpu, addr, attrs);
560 /* Fallback for CPUs which don't implement the _attrs_ hook */
561 *attrs = MEMTXATTRS_UNSPECIFIED;
562 return cc->get_phys_page_debug(cpu, addr);
566 * cpu_get_phys_page_debug:
567 * @cpu: The CPU to obtain the physical page address for.
568 * @addr: The virtual address.
570 * Obtains the physical page corresponding to a virtual one.
571 * Use it only for debugging because no protection checks are done.
573 * Returns: Corresponding physical page address or -1 if no page found.
575 static inline hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr)
577 MemTxAttrs attrs = {};
579 return cpu_get_phys_page_attrs_debug(cpu, addr, &attrs);
582 /** cpu_asidx_from_attrs:
583 * @cpu: CPU
584 * @attrs: memory transaction attributes
586 * Returns the address space index specifying the CPU AddressSpace
587 * to use for a memory access with the given transaction attributes.
589 static inline int cpu_asidx_from_attrs(CPUState *cpu, MemTxAttrs attrs)
591 CPUClass *cc = CPU_GET_CLASS(cpu);
593 if (cc->asidx_from_attrs) {
594 return cc->asidx_from_attrs(cpu, attrs);
596 return 0;
598 #endif
601 * cpu_list_add:
602 * @cpu: The CPU to be added to the list of CPUs.
604 void cpu_list_add(CPUState *cpu);
607 * cpu_list_remove:
608 * @cpu: The CPU to be removed from the list of CPUs.
610 void cpu_list_remove(CPUState *cpu);
613 * cpu_reset:
614 * @cpu: The CPU whose state is to be reset.
616 void cpu_reset(CPUState *cpu);
619 * cpu_class_by_name:
620 * @typename: The CPU base type.
621 * @cpu_model: The model string without any parameters.
623 * Looks up a CPU #ObjectClass matching name @cpu_model.
625 * Returns: A #CPUClass or %NULL if not matching class is found.
627 ObjectClass *cpu_class_by_name(const char *typename, const char *cpu_model);
630 * cpu_generic_init:
631 * @typename: The CPU base type.
632 * @cpu_model: The model string including optional parameters.
634 * Instantiates a CPU, processes optional parameters and realizes the CPU.
636 * Returns: A #CPUState or %NULL if an error occurred.
638 CPUState *cpu_generic_init(const char *typename, const char *cpu_model);
641 * cpu_has_work:
642 * @cpu: The vCPU to check.
644 * Checks whether the CPU has work to do.
646 * Returns: %true if the CPU has work, %false otherwise.
648 static inline bool cpu_has_work(CPUState *cpu)
650 CPUClass *cc = CPU_GET_CLASS(cpu);
652 g_assert(cc->has_work);
653 return cc->has_work(cpu);
657 * qemu_cpu_is_self:
658 * @cpu: The vCPU to check against.
660 * Checks whether the caller is executing on the vCPU thread.
662 * Returns: %true if called from @cpu's thread, %false otherwise.
664 bool qemu_cpu_is_self(CPUState *cpu);
667 * qemu_cpu_kick:
668 * @cpu: The vCPU to kick.
670 * Kicks @cpu's thread.
672 void qemu_cpu_kick(CPUState *cpu);
675 * cpu_is_stopped:
676 * @cpu: The CPU to check.
678 * Checks whether the CPU is stopped.
680 * Returns: %true if run state is not running or if artificially stopped;
681 * %false otherwise.
683 bool cpu_is_stopped(CPUState *cpu);
686 * do_run_on_cpu:
687 * @cpu: The vCPU to run on.
688 * @func: The function to be executed.
689 * @data: Data to pass to the function.
690 * @mutex: Mutex to release while waiting for @func to run.
692 * Used internally in the implementation of run_on_cpu.
694 void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data,
695 QemuMutex *mutex);
698 * run_on_cpu:
699 * @cpu: The vCPU to run on.
700 * @func: The function to be executed.
701 * @data: Data to pass to the function.
703 * Schedules the function @func for execution on the vCPU @cpu.
705 void run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data);
708 * async_run_on_cpu:
709 * @cpu: The vCPU to run on.
710 * @func: The function to be executed.
711 * @data: Data to pass to the function.
713 * Schedules the function @func for execution on the vCPU @cpu asynchronously.
715 void async_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data);
718 * async_safe_run_on_cpu:
719 * @cpu: The vCPU to run on.
720 * @func: The function to be executed.
721 * @data: Data to pass to the function.
723 * Schedules the function @func for execution on the vCPU @cpu asynchronously,
724 * while all other vCPUs are sleeping.
726 * Unlike run_on_cpu and async_run_on_cpu, the function is run outside the
727 * BQL.
729 void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data);
732 * qemu_get_cpu:
733 * @index: The CPUState@cpu_index value of the CPU to obtain.
735 * Gets a CPU matching @index.
737 * Returns: The CPU or %NULL if there is no matching CPU.
739 CPUState *qemu_get_cpu(int index);
742 * cpu_exists:
743 * @id: Guest-exposed CPU ID to lookup.
745 * Search for CPU with specified ID.
747 * Returns: %true - CPU is found, %false - CPU isn't found.
749 bool cpu_exists(int64_t id);
752 * cpu_throttle_set:
753 * @new_throttle_pct: Percent of sleep time. Valid range is 1 to 99.
755 * Throttles all vcpus by forcing them to sleep for the given percentage of
756 * time. A throttle_percentage of 25 corresponds to a 75% duty cycle roughly.
757 * (example: 10ms sleep for every 30ms awake).
759 * cpu_throttle_set can be called as needed to adjust new_throttle_pct.
760 * Once the throttling starts, it will remain in effect until cpu_throttle_stop
761 * is called.
763 void cpu_throttle_set(int new_throttle_pct);
766 * cpu_throttle_stop:
768 * Stops the vcpu throttling started by cpu_throttle_set.
770 void cpu_throttle_stop(void);
773 * cpu_throttle_active:
775 * Returns: %true if the vcpus are currently being throttled, %false otherwise.
777 bool cpu_throttle_active(void);
780 * cpu_throttle_get_percentage:
782 * Returns the vcpu throttle percentage. See cpu_throttle_set for details.
784 * Returns: The throttle percentage in range 1 to 99.
786 int cpu_throttle_get_percentage(void);
788 #ifndef CONFIG_USER_ONLY
790 typedef void (*CPUInterruptHandler)(CPUState *, int);
792 extern CPUInterruptHandler cpu_interrupt_handler;
795 * cpu_interrupt:
796 * @cpu: The CPU to set an interrupt on.
797 * @mask: The interupts to set.
799 * Invokes the interrupt handler.
801 static inline void cpu_interrupt(CPUState *cpu, int mask)
803 cpu_interrupt_handler(cpu, mask);
806 #else /* USER_ONLY */
808 void cpu_interrupt(CPUState *cpu, int mask);
810 #endif /* USER_ONLY */
812 #ifdef CONFIG_SOFTMMU
813 static inline void cpu_unassigned_access(CPUState *cpu, hwaddr addr,
814 bool is_write, bool is_exec,
815 int opaque, unsigned size)
817 CPUClass *cc = CPU_GET_CLASS(cpu);
819 if (cc->do_unassigned_access) {
820 cc->do_unassigned_access(cpu, addr, is_write, is_exec, opaque, size);
824 static inline void cpu_unaligned_access(CPUState *cpu, vaddr addr,
825 MMUAccessType access_type,
826 int mmu_idx, uintptr_t retaddr)
828 CPUClass *cc = CPU_GET_CLASS(cpu);
830 cc->do_unaligned_access(cpu, addr, access_type, mmu_idx, retaddr);
832 #endif
835 * cpu_set_pc:
836 * @cpu: The CPU to set the program counter for.
837 * @addr: Program counter value.
839 * Sets the program counter for a CPU.
841 static inline void cpu_set_pc(CPUState *cpu, vaddr addr)
843 CPUClass *cc = CPU_GET_CLASS(cpu);
845 cc->set_pc(cpu, addr);
849 * cpu_reset_interrupt:
850 * @cpu: The CPU to clear the interrupt on.
851 * @mask: The interrupt mask to clear.
853 * Resets interrupts on the vCPU @cpu.
855 void cpu_reset_interrupt(CPUState *cpu, int mask);
858 * cpu_exit:
859 * @cpu: The CPU to exit.
861 * Requests the CPU @cpu to exit execution.
863 void cpu_exit(CPUState *cpu);
866 * cpu_resume:
867 * @cpu: The CPU to resume.
869 * Resumes CPU, i.e. puts CPU into runnable state.
871 void cpu_resume(CPUState *cpu);
874 * cpu_remove:
875 * @cpu: The CPU to remove.
877 * Requests the CPU to be removed.
879 void cpu_remove(CPUState *cpu);
882 * cpu_remove_sync:
883 * @cpu: The CPU to remove.
885 * Requests the CPU to be removed and waits till it is removed.
887 void cpu_remove_sync(CPUState *cpu);
890 * process_queued_cpu_work() - process all items on CPU work queue
891 * @cpu: The CPU which work queue to process.
893 void process_queued_cpu_work(CPUState *cpu);
896 * cpu_exec_start:
897 * @cpu: The CPU for the current thread.
899 * Record that a CPU has started execution and can be interrupted with
900 * cpu_exit.
902 void cpu_exec_start(CPUState *cpu);
905 * cpu_exec_end:
906 * @cpu: The CPU for the current thread.
908 * Record that a CPU has stopped execution and exclusive sections
909 * can be executed without interrupting it.
911 void cpu_exec_end(CPUState *cpu);
914 * start_exclusive:
916 * Wait for a concurrent exclusive section to end, and then start
917 * a section of work that is run while other CPUs are not running
918 * between cpu_exec_start and cpu_exec_end. CPUs that are running
919 * cpu_exec are exited immediately. CPUs that call cpu_exec_start
920 * during the exclusive section go to sleep until this CPU calls
921 * end_exclusive.
923 void start_exclusive(void);
926 * end_exclusive:
928 * Concludes an exclusive execution section started by start_exclusive.
930 void end_exclusive(void);
933 * qemu_init_vcpu:
934 * @cpu: The vCPU to initialize.
936 * Initializes a vCPU.
938 void qemu_init_vcpu(CPUState *cpu);
940 #define SSTEP_ENABLE 0x1 /* Enable simulated HW single stepping */
941 #define SSTEP_NOIRQ 0x2 /* Do not use IRQ while single stepping */
942 #define SSTEP_NOTIMER 0x4 /* Do not Timers while single stepping */
945 * cpu_single_step:
946 * @cpu: CPU to the flags for.
947 * @enabled: Flags to enable.
949 * Enables or disables single-stepping for @cpu.
951 void cpu_single_step(CPUState *cpu, int enabled);
953 /* Breakpoint/watchpoint flags */
954 #define BP_MEM_READ 0x01
955 #define BP_MEM_WRITE 0x02
956 #define BP_MEM_ACCESS (BP_MEM_READ | BP_MEM_WRITE)
957 #define BP_STOP_BEFORE_ACCESS 0x04
958 /* 0x08 currently unused */
959 #define BP_GDB 0x10
960 #define BP_CPU 0x20
961 #define BP_ANY (BP_GDB | BP_CPU)
962 #define BP_WATCHPOINT_HIT_READ 0x40
963 #define BP_WATCHPOINT_HIT_WRITE 0x80
964 #define BP_WATCHPOINT_HIT (BP_WATCHPOINT_HIT_READ | BP_WATCHPOINT_HIT_WRITE)
966 int cpu_breakpoint_insert(CPUState *cpu, vaddr pc, int flags,
967 CPUBreakpoint **breakpoint);
968 int cpu_breakpoint_remove(CPUState *cpu, vaddr pc, int flags);
969 void cpu_breakpoint_remove_by_ref(CPUState *cpu, CPUBreakpoint *breakpoint);
970 void cpu_breakpoint_remove_all(CPUState *cpu, int mask);
972 /* Return true if PC matches an installed breakpoint. */
973 static inline bool cpu_breakpoint_test(CPUState *cpu, vaddr pc, int mask)
975 CPUBreakpoint *bp;
977 if (unlikely(!QTAILQ_EMPTY(&cpu->breakpoints))) {
978 QTAILQ_FOREACH(bp, &cpu->breakpoints, entry) {
979 if (bp->pc == pc && (bp->flags & mask)) {
980 return true;
984 return false;
987 int cpu_watchpoint_insert(CPUState *cpu, vaddr addr, vaddr len,
988 int flags, CPUWatchpoint **watchpoint);
989 int cpu_watchpoint_remove(CPUState *cpu, vaddr addr,
990 vaddr len, int flags);
991 void cpu_watchpoint_remove_by_ref(CPUState *cpu, CPUWatchpoint *watchpoint);
992 void cpu_watchpoint_remove_all(CPUState *cpu, int mask);
995 * cpu_get_address_space:
996 * @cpu: CPU to get address space from
997 * @asidx: index identifying which address space to get
999 * Return the requested address space of this CPU. @asidx
1000 * specifies which address space to read.
1002 AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx);
1004 void QEMU_NORETURN cpu_abort(CPUState *cpu, const char *fmt, ...)
1005 GCC_FMT_ATTR(2, 3);
1006 void cpu_exec_initfn(CPUState *cpu);
1007 void cpu_exec_realizefn(CPUState *cpu, Error **errp);
1008 void cpu_exec_unrealizefn(CPUState *cpu);
1010 #ifdef CONFIG_SOFTMMU
1011 extern const struct VMStateDescription vmstate_cpu_common;
1012 #else
1013 #define vmstate_cpu_common vmstate_dummy
1014 #endif
1016 #define VMSTATE_CPU() { \
1017 .name = "parent_obj", \
1018 .size = sizeof(CPUState), \
1019 .vmsd = &vmstate_cpu_common, \
1020 .flags = VMS_STRUCT, \
1021 .offset = 0, \
1024 #define UNASSIGNED_CPU_INDEX -1
1026 #endif