xref: /openbmc/qemu/include/sysemu/hvf.h (revision c97d6d2c)
1 /*
2  * QEMU Hypervisor.framework (HVF) support
3  *
4  * Copyright Google Inc., 2017
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 
11 /* header to be included in non-HVF-specific code */
12 #ifndef _HVF_H
13 #define _HVF_H
14 
15 #include "config-host.h"
16 #include "qemu/osdep.h"
17 #include "qemu-common.h"
18 #include "qemu/bitops.h"
19 #include "exec/memory.h"
20 #include "sysemu/accel.h"
21 
22 extern int hvf_disabled;
23 #ifdef CONFIG_HVF
24 #include <Hypervisor/hv.h>
25 #include <Hypervisor/hv_vmx.h>
26 #include <Hypervisor/hv_error.h>
27 #include "target/i386/cpu.h"
28 #include "hw/hw.h"
29 uint32_t hvf_get_supported_cpuid(uint32_t func, uint32_t idx,
30                                  int reg);
31 #define hvf_enabled() !hvf_disabled
32 #else
33 #define hvf_enabled() 0
34 #define hvf_get_supported_cpuid(func, idx, reg) 0
35 #endif
36 
37 typedef struct hvf_slot {
38     uint64_t start;
39     uint64_t size;
40     uint8_t *mem;
41     int slot_id;
42 } hvf_slot;
43 
44 typedef struct hvf_vcpu_caps {
45     uint64_t vmx_cap_pinbased;
46     uint64_t vmx_cap_procbased;
47     uint64_t vmx_cap_procbased2;
48     uint64_t vmx_cap_entry;
49     uint64_t vmx_cap_exit;
50     uint64_t vmx_cap_preemption_timer;
51 } hvf_vcpu_caps;
52 
53 typedef struct HVFState {
54     AccelState parent;
55     hvf_slot slots[32];
56     int num_slots;
57 
58     hvf_vcpu_caps *hvf_caps;
59 } HVFState;
60 extern HVFState *hvf_state;
61 
62 void hvf_set_phys_mem(MemoryRegionSection *, bool);
63 void hvf_handle_io(CPUArchState *, uint16_t, void *,
64                   int, int, int);
65 hvf_slot *hvf_find_overlap_slot(uint64_t, uint64_t);
66 
67 /* Disable HVF if |disable| is 1, otherwise, enable it iff it is supported by
68  * the host CPU. Use hvf_enabled() after this to get the result. */
69 void hvf_disable(int disable);
70 
71 /* Returns non-0 if the host CPU supports the VMX "unrestricted guest" feature
72  * which allows the virtual CPU to directly run in "real mode". If true, this
73  * allows QEMU to run several vCPU threads in parallel (see cpus.c). Otherwise,
74  * only a a single TCG thread can run, and it will call HVF to run the current
75  * instructions, except in case of "real mode" (paging disabled, typically at
76  * boot time), or MMIO operations. */
77 
78 int hvf_sync_vcpus(void);
79 
80 int hvf_init_vcpu(CPUState *);
81 int hvf_vcpu_exec(CPUState *);
82 int hvf_smp_cpu_exec(CPUState *);
83 void hvf_cpu_synchronize_state(CPUState *);
84 void hvf_cpu_synchronize_post_reset(CPUState *);
85 void hvf_cpu_synchronize_post_init(CPUState *);
86 void _hvf_cpu_synchronize_post_init(CPUState *, run_on_cpu_data);
87 
88 void hvf_vcpu_destroy(CPUState *);
89 void hvf_raise_event(CPUState *);
90 /* void hvf_reset_vcpu_state(void *opaque); */
91 void hvf_reset_vcpu(CPUState *);
92 void vmx_update_tpr(CPUState *);
93 void update_apic_tpr(CPUState *);
94 int hvf_put_registers(CPUState *);
95 void vmx_clear_int_window_exiting(CPUState *cpu);
96 
97 #define TYPE_HVF_ACCEL ACCEL_CLASS_NAME("hvf")
98 
99 #define HVF_STATE(obj) \
100     OBJECT_CHECK(HVFState, (obj), TYPE_HVF_ACCEL)
101 
102 #endif
103