1 /* 2 * Accelerator per-vCPU handlers 3 * 4 * Copyright 2021 SUSE LLC 5 * 6 * This work is licensed under the terms of the GNU GPL, version 2 or later. 7 * See the COPYING file in the top-level directory. 8 */ 9 10 #ifndef QEMU_ACCEL_CPU_OPS_H 11 #define QEMU_ACCEL_CPU_OPS_H 12 13 #include "qemu/accel.h" 14 #include "exec/vaddr.h" 15 #include "qom/object.h" 16 17 #define ACCEL_OPS_SUFFIX "-ops" 18 #define TYPE_ACCEL_OPS "accel" ACCEL_OPS_SUFFIX 19 #define ACCEL_OPS_NAME(name) (name "-" TYPE_ACCEL_OPS) 20 21 DECLARE_CLASS_CHECKERS(AccelOpsClass, ACCEL_OPS, TYPE_ACCEL_OPS) 22 23 /** 24 * struct AccelOpsClass - accelerator interfaces 25 * 26 * This structure is used to abstract accelerator differences from the 27 * core CPU code. Not all have to be implemented. 28 */ 29 struct AccelOpsClass { 30 /*< private >*/ 31 ObjectClass parent_class; 32 /*< public >*/ 33 34 /* initialization function called when accel is chosen */ 35 void (*ops_init)(AccelClass *ac); 36 37 bool (*cpus_are_resettable)(void); 38 void (*cpu_reset_hold)(CPUState *cpu); 39 40 void (*create_vcpu_thread)(CPUState *cpu); /* MANDATORY NON-NULL */ 41 void (*kick_vcpu_thread)(CPUState *cpu); 42 bool (*cpu_thread_is_idle)(CPUState *cpu); 43 44 /** 45 * synchronize_post_reset: 46 * synchronize_post_init: 47 * @cpu: The vCPU to synchronize. 48 * 49 * Request to synchronize QEMU vCPU registers to the hardware accelerator 50 * (QEMU is the reference). 51 */ 52 void (*synchronize_post_reset)(CPUState *cpu); 53 void (*synchronize_post_init)(CPUState *cpu); 54 /** 55 * synchronize_state: 56 * synchronize_pre_loadvm: 57 * @cpu: The vCPU to synchronize. 58 * 59 * Request to synchronize QEMU vCPU registers from the hardware accelerator 60 * (the hardware accelerator is the reference). 61 */ 62 void (*synchronize_state)(CPUState *cpu); 63 void (*synchronize_pre_loadvm)(CPUState *cpu); 64 65 /* handle_interrupt is mandatory. */ 66 void (*handle_interrupt)(CPUState *cpu, int mask); 67 68 /* get_vcpu_stats: Append statistics of this @cpu to @buf */ 69 void (*get_vcpu_stats)(CPUState *cpu, GString *buf); 70 71 /** 72 * @get_virtual_clock: fetch virtual clock 73 * @set_virtual_clock: set virtual clock 74 * 75 * These allow the timer subsystem to defer to the accelerator to 76 * fetch time. The set function is needed if the accelerator wants 77 * to track the changes to time as the timer is warped through 78 * various timer events. 79 */ 80 int64_t (*get_virtual_clock)(void); 81 void (*set_virtual_clock)(int64_t time); 82 83 int64_t (*get_elapsed_ticks)(void); 84 85 /* gdbstub hooks */ 86 bool (*supports_guest_debug)(void); 87 int (*update_guest_debug)(CPUState *cpu); 88 int (*insert_breakpoint)(CPUState *cpu, int type, vaddr addr, vaddr len); 89 int (*remove_breakpoint)(CPUState *cpu, int type, vaddr addr, vaddr len); 90 void (*remove_all_breakpoints)(CPUState *cpu); 91 }; 92 93 void generic_handle_interrupt(CPUState *cpu, int mask); 94 95 #endif /* QEMU_ACCEL_CPU_OPS_H */ 96