xref: /openbmc/qemu/include/accel/accel-cpu-ops.h (revision f7a7e7dd2179e7189064e0b7b637e6906617221f)
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     /**
69      * @get_virtual_clock: fetch virtual clock
70      * @set_virtual_clock: set virtual clock
71      *
72      * These allow the timer subsystem to defer to the accelerator to
73      * fetch time. The set function is needed if the accelerator wants
74      * to track the changes to time as the timer is warped through
75      * various timer events.
76      */
77     int64_t (*get_virtual_clock)(void);
78     void (*set_virtual_clock)(int64_t time);
79 
80     int64_t (*get_elapsed_ticks)(void);
81 
82     /* gdbstub hooks */
83     bool (*supports_guest_debug)(void);
84     int (*update_guest_debug)(CPUState *cpu);
85     int (*insert_breakpoint)(CPUState *cpu, int type, vaddr addr, vaddr len);
86     int (*remove_breakpoint)(CPUState *cpu, int type, vaddr addr, vaddr len);
87     void (*remove_all_breakpoints)(CPUState *cpu);
88 };
89 
90 void generic_handle_interrupt(CPUState *cpu, int mask);
91 
92 #endif /* QEMU_ACCEL_CPU_OPS_H */
93