| 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 | #include "gdbstub/enums.h" |
| 17 | |
| 18 | #define ACCEL_OPS_SUFFIX "-ops" |
| 19 | #define TYPE_ACCEL_OPS "accel" ACCEL_OPS_SUFFIX |
| 20 | #define ACCEL_OPS_NAME(name) (name "-" TYPE_ACCEL_OPS) |
| 21 | |
| 22 | DECLARE_CLASS_CHECKERS(AccelOpsClass, ACCEL_OPS, TYPE_ACCEL_OPS) |
| 23 | |
| 24 | /** |
| 25 | * struct AccelOpsClass - accelerator interfaces |
| 26 | * |
| 27 | * This structure is used to abstract accelerator differences from the |
| 28 | * core CPU code. Not all have to be implemented. |
| 29 | */ |
| 30 | struct AccelOpsClass { |
| 31 | /*< private >*/ |
| 32 | ObjectClass parent_class; |
| 33 | /*< public >*/ |
| 34 | |
| 35 | /* initialization function called when accel is chosen */ |
| 36 | void (*ops_init)(AccelClass *ac); |
| 37 | |
| 38 | bool (*cpu_target_realize)(CPUState *cpu, Error **errp); |
| 39 | bool (*cpus_are_resettable)(void); |
| 40 | void (*cpu_reset_hold)(CPUState *cpu); |
| 41 | |
| 42 | void (*create_vcpu_thread)(CPUState *cpu); /* MANDATORY NON-NULL */ |
| 43 | void (*kick_vcpu_thread)(CPUState *cpu); |
| 44 | bool (*cpu_thread_is_idle)(CPUState *cpu); |
| 45 | |
| 46 | /** |
| 47 | * synchronize_post_reset: |
| 48 | * synchronize_post_init: |
| 49 | * @cpu: The vCPU to synchronize. |
| 50 | * |
| 51 | * Request to synchronize QEMU vCPU registers to the hardware accelerator |
| 52 | * (QEMU is the reference). |
| 53 | */ |
| 54 | void (*synchronize_post_reset)(CPUState *cpu); |
| 55 | void (*synchronize_post_init)(CPUState *cpu); |
| 56 | /** |
| 57 | * synchronize_state: |
| 58 | * synchronize_pre_loadvm: |
| 59 | * @cpu: The vCPU to synchronize. |
| 60 | * |
| 61 | * Request to synchronize QEMU vCPU registers from the hardware accelerator |
| 62 | * (the hardware accelerator is the reference). |
| 63 | */ |
| 64 | void (*synchronize_state)(CPUState *cpu); |
| 65 | void (*synchronize_pre_loadvm)(CPUState *cpu); |
| 66 | |
| 67 | /* handle_interrupt is mandatory. */ |
| 68 | void (*handle_interrupt)(CPUState *cpu, int mask); |
| 69 | |
| 70 | /* get_vcpu_stats: Append statistics of this @cpu to @buf */ |
| 71 | void (*get_vcpu_stats)(CPUState *cpu, GString *buf); |
| 72 | |
| 73 | /** |
| 74 | * @get_virtual_clock: fetch virtual clock |
| 75 | * @set_virtual_clock: set virtual clock |
| 76 | * |
| 77 | * These allow the timer subsystem to defer to the accelerator to |
| 78 | * fetch time. The set function is needed if the accelerator wants |
| 79 | * to track the changes to time as the timer is warped through |
| 80 | * various timer events. |
| 81 | */ |
| 82 | int64_t (*get_virtual_clock)(void); |
| 83 | void (*set_virtual_clock)(int64_t time); |
| 84 | |
| 85 | int64_t (*get_elapsed_ticks)(void); |
| 86 | |
| 87 | /* gdbstub hooks */ |
| 88 | int (*update_guest_debug)(CPUState *cpu); |
| 89 | int (*insert_gdbstub_breakpoint)(CPUState *cpu, GdbBreakpointType type, |
| 90 | vaddr addr, vaddr len); |
| 91 | int (*remove_gdbstub_breakpoint)(CPUState *cpu, GdbBreakpointType type, |
| 92 | vaddr addr, vaddr len); |
| 93 | void (*remove_all_gdbstub_breakpoints)(CPUState *cpu); |
| 94 | }; |
| 95 | |
| 96 | void generic_handle_interrupt(CPUState *cpu, int mask); |
| 97 | |
| 98 | #endif /* QEMU_ACCEL_CPU_OPS_H */ |