2 * Copyright (c) 2011 NetApp, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #define VM_MAX_NAMELEN 32
37 struct vm_memory_segment;
49 typedef int (*vmm_init_func_t)(void);
50 typedef int (*vmm_cleanup_func_t)(void);
51 typedef void * (*vmi_init_func_t)(struct vm *vm, struct pmap *pmap);
52 typedef int (*vmi_run_func_t)(void *vmi, int vcpu, register_t rip,
54 typedef void (*vmi_cleanup_func_t)(void *vmi);
55 typedef int (*vmi_get_register_t)(void *vmi, int vcpu, int num,
57 typedef int (*vmi_set_register_t)(void *vmi, int vcpu, int num,
59 typedef int (*vmi_get_desc_t)(void *vmi, int vcpu, int num,
60 struct seg_desc *desc);
61 typedef int (*vmi_set_desc_t)(void *vmi, int vcpu, int num,
62 struct seg_desc *desc);
63 typedef int (*vmi_inject_event_t)(void *vmi, int vcpu,
65 uint32_t code, int code_valid);
66 typedef int (*vmi_get_cap_t)(void *vmi, int vcpu, int num, int *retval);
67 typedef int (*vmi_set_cap_t)(void *vmi, int vcpu, int num, int val);
68 typedef struct vmspace * (*vmi_vmspace_alloc)(vm_offset_t min, vm_offset_t max);
69 typedef void (*vmi_vmspace_free)(struct vmspace *vmspace);
72 vmm_init_func_t init; /* module wide initialization */
73 vmm_cleanup_func_t cleanup;
75 vmi_init_func_t vminit; /* vm-specific initialization */
77 vmi_cleanup_func_t vmcleanup;
78 vmi_get_register_t vmgetreg;
79 vmi_set_register_t vmsetreg;
80 vmi_get_desc_t vmgetdesc;
81 vmi_set_desc_t vmsetdesc;
82 vmi_inject_event_t vminject;
83 vmi_get_cap_t vmgetcap;
84 vmi_set_cap_t vmsetcap;
85 vmi_vmspace_alloc vmspace_alloc;
86 vmi_vmspace_free vmspace_free;
89 extern struct vmm_ops vmm_ops_intel;
90 extern struct vmm_ops vmm_ops_amd;
92 int vm_create(const char *name, struct vm **retvm);
93 void vm_destroy(struct vm *vm);
94 const char *vm_name(struct vm *vm);
95 int vm_malloc(struct vm *vm, vm_paddr_t gpa, size_t len);
96 int vm_map_mmio(struct vm *vm, vm_paddr_t gpa, size_t len, vm_paddr_t hpa);
97 int vm_unmap_mmio(struct vm *vm, vm_paddr_t gpa, size_t len);
98 void *vm_gpa_hold(struct vm *, vm_paddr_t gpa, size_t len, int prot,
100 void vm_gpa_release(void *cookie);
101 int vm_gpabase2memseg(struct vm *vm, vm_paddr_t gpabase,
102 struct vm_memory_segment *seg);
103 int vm_get_memobj(struct vm *vm, vm_paddr_t gpa, size_t len,
104 vm_offset_t *offset, struct vm_object **object);
105 boolean_t vm_mem_allocated(struct vm *vm, vm_paddr_t gpa);
106 int vm_get_register(struct vm *vm, int vcpu, int reg, uint64_t *retval);
107 int vm_set_register(struct vm *vm, int vcpu, int reg, uint64_t val);
108 int vm_get_seg_desc(struct vm *vm, int vcpu, int reg,
109 struct seg_desc *ret_desc);
110 int vm_set_seg_desc(struct vm *vm, int vcpu, int reg,
111 struct seg_desc *desc);
112 int vm_run(struct vm *vm, struct vm_run *vmrun);
113 int vm_inject_event(struct vm *vm, int vcpu, int type,
114 int vector, uint32_t error_code, int error_code_valid);
115 int vm_inject_nmi(struct vm *vm, int vcpu);
116 int vm_nmi_pending(struct vm *vm, int vcpuid);
117 void vm_nmi_clear(struct vm *vm, int vcpuid);
118 uint64_t *vm_guest_msrs(struct vm *vm, int cpu);
119 struct vlapic *vm_lapic(struct vm *vm, int cpu);
120 struct vioapic *vm_ioapic(struct vm *vm);
121 int vm_get_capability(struct vm *vm, int vcpu, int type, int *val);
122 int vm_set_capability(struct vm *vm, int vcpu, int type, int val);
123 int vm_get_x2apic_state(struct vm *vm, int vcpu, enum x2apic_state *state);
124 int vm_set_x2apic_state(struct vm *vm, int vcpu, enum x2apic_state state);
125 int vm_apicid2vcpuid(struct vm *vm, int apicid);
126 void vm_activate_cpu(struct vm *vm, int vcpu);
127 cpuset_t vm_active_cpus(struct vm *vm);
128 struct vm_exit *vm_exitinfo(struct vm *vm, int vcpuid);
131 * Return 1 if device indicated by bus/slot/func is supposed to be a
132 * pci passthrough device.
134 * Return 0 otherwise.
136 int vmm_is_pptdev(int bus, int slot, int func);
138 void *vm_iommu_domain(struct vm *vm);
147 int vcpu_set_state(struct vm *vm, int vcpu, enum vcpu_state state);
148 enum vcpu_state vcpu_get_state(struct vm *vm, int vcpu, int *hostcpu);
151 vcpu_is_running(struct vm *vm, int vcpu, int *hostcpu)
153 return (vcpu_get_state(vm, vcpu, hostcpu) == VCPU_RUNNING);
156 void *vcpu_stats(struct vm *vm, int vcpu);
157 void vm_interrupt_hostcpu(struct vm *vm, int vcpu);
158 struct vmspace *vm_get_vmspace(struct vm *vm);
159 int vm_assign_pptdev(struct vm *vm, int bus, int slot, int func);
160 int vm_unassign_pptdev(struct vm *vm, int bus, int slot, int func);
163 #include <machine/vmm_instruction_emul.h>
165 #define VM_MAXCPU 16 /* maximum virtual cpus */
168 * Identifiers for events that can be injected into the VM
176 VM_PRIV_SW_EXCEPTION,
182 * Identifiers for architecturally defined registers.
222 * Identifiers for optional vmm capabilities
228 VM_CAP_UNRESTRICTED_GUEST,
229 VM_CAP_ENABLE_INVPCID,
241 * The 'access' field has the format specified in Table 21-2 of the Intel
242 * Architecture Manual vol 3b.
244 * XXX The contents of the 'access' field are architecturally defined except
245 * bit 16 - Segment Unusable.
263 VM_EXITCODE_INST_EMUL,
264 VM_EXITCODE_SPINUP_AP,
269 enum vm_exitcode exitcode;
270 int inst_length; /* 0 means unknown */
274 uint16_t bytes:3; /* 1 or 2 or 4 */
275 uint16_t in:1; /* out is 0, in is 1 */
279 uint32_t eax; /* valid for out */
293 * VMX specific payload. Used when there is no "better"
294 * exitcode to represent the VM-exit.
297 int error; /* vmx inst error */
298 uint32_t exit_reason;
299 uint64_t exit_qualification;
302 uint32_t code; /* ecx value */