1 /* 2 * Copyright (C) 2015 Mihai Carabas <mihai.carabas@gmail.com> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 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. 13 * 14 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``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 AUTHOR 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 24 * SUCH DAMAGE. 25 */ 26 27 #ifndef _VMM_DEV_H_ 28 #define _VMM_DEV_H_ 29 30 #include <sys/domainset.h> 31 32 #include <machine/vmm.h> 33 34 #include <dev/vmm/vmm_param.h> 35 36 struct vm_memmap { 37 vm_paddr_t gpa; 38 int segid; /* memory segment */ 39 vm_ooffset_t segoff; /* offset into memory segment */ 40 size_t len; /* mmap length */ 41 int prot; /* RWX */ 42 int flags; 43 }; 44 #define VM_MEMMAP_F_WIRED 0x01 45 46 struct vm_munmap { 47 vm_paddr_t gpa; 48 size_t len; 49 }; 50 51 #define VM_MEMSEG_NAME(m) ((m)->name[0] != '\0' ? (m)->name : NULL) 52 struct vm_memseg { 53 int segid; 54 size_t len; 55 char name[VM_MAX_SUFFIXLEN + 1]; 56 domainset_t *ds_mask; 57 size_t ds_mask_size; 58 int ds_policy; 59 }; 60 61 struct vm_register { 62 int cpuid; 63 int regnum; /* enum vm_reg_name */ 64 uint64_t regval; 65 }; 66 67 struct vm_register_set { 68 int cpuid; 69 unsigned int count; 70 const int *regnums; /* enum vm_reg_name */ 71 uint64_t *regvals; 72 }; 73 74 struct vm_run { 75 int cpuid; 76 cpuset_t *cpuset; /* CPU set storage */ 77 size_t cpusetsize; 78 struct vm_exit *vm_exit; 79 }; 80 81 struct vm_exception { 82 int cpuid; 83 uint64_t esr; 84 uint64_t far; 85 }; 86 87 struct vm_msi { 88 uint64_t msg; 89 uint64_t addr; 90 int bus; 91 int slot; 92 int func; 93 }; 94 95 struct vm_capability { 96 int cpuid; 97 enum vm_cap_type captype; 98 int capval; 99 int allcpus; 100 }; 101 102 #define MAX_VM_STATS 64 103 struct vm_stats { 104 int cpuid; /* in */ 105 int index; /* in */ 106 int num_entries; /* out */ 107 struct timeval tv; 108 uint64_t statbuf[MAX_VM_STATS]; 109 }; 110 struct vm_stat_desc { 111 int index; /* in */ 112 char desc[128]; /* out */ 113 }; 114 115 struct vm_suspend { 116 enum vm_suspend_how how; 117 }; 118 119 struct vm_gla2gpa { 120 int vcpuid; /* inputs */ 121 int prot; /* PROT_READ or PROT_WRITE */ 122 uint64_t gla; 123 struct vm_guest_paging paging; 124 int fault; /* outputs */ 125 uint64_t gpa; 126 }; 127 128 struct vm_activate_cpu { 129 int vcpuid; 130 }; 131 132 struct vm_cpuset { 133 int which; 134 int cpusetsize; 135 cpuset_t *cpus; 136 }; 137 #define VM_ACTIVE_CPUS 0 138 #define VM_SUSPENDED_CPUS 1 139 #define VM_DEBUG_CPUS 2 140 141 struct vm_vgic_version { 142 u_int version; 143 u_int flags; 144 }; 145 146 struct vm_vgic_descr { 147 struct vm_vgic_version ver; 148 union { 149 struct { 150 uint64_t dist_start; 151 uint64_t dist_size; 152 uint64_t redist_start; 153 uint64_t redist_size; 154 } v3_regs; 155 }; 156 }; 157 158 struct vm_irq { 159 uint32_t irq; 160 }; 161 162 struct vm_cpu_topology { 163 uint16_t sockets; 164 uint16_t cores; 165 uint16_t threads; 166 uint16_t maxcpus; 167 }; 168 169 enum { 170 /* general routines */ 171 IOCNUM_ABIVERS = 0, 172 IOCNUM_RUN = 1, 173 IOCNUM_SET_CAPABILITY = 2, 174 IOCNUM_GET_CAPABILITY = 3, 175 IOCNUM_SUSPEND = 4, 176 IOCNUM_REINIT = 5, 177 178 /* memory apis */ 179 IOCNUM_GET_GPA_PMAP = 12, 180 IOCNUM_GLA2GPA_NOFAULT = 13, 181 IOCNUM_ALLOC_MEMSEG = 14, 182 IOCNUM_GET_MEMSEG = 15, 183 IOCNUM_MMAP_MEMSEG = 16, 184 IOCNUM_MMAP_GETNEXT = 17, 185 IOCNUM_MUNMAP_MEMSEG = 18, 186 187 /* register/state accessors */ 188 IOCNUM_SET_REGISTER = 20, 189 IOCNUM_GET_REGISTER = 21, 190 IOCNUM_SET_REGISTER_SET = 24, 191 IOCNUM_GET_REGISTER_SET = 25, 192 193 /* statistics */ 194 IOCNUM_VM_STATS = 50, 195 IOCNUM_VM_STAT_DESC = 51, 196 197 /* CPU Topology */ 198 IOCNUM_SET_TOPOLOGY = 63, 199 IOCNUM_GET_TOPOLOGY = 64, 200 201 /* interrupt injection */ 202 IOCNUM_ASSERT_IRQ = 80, 203 IOCNUM_DEASSERT_IRQ = 81, 204 IOCNUM_RAISE_MSI = 82, 205 IOCNUM_INJECT_EXCEPTION = 83, 206 207 /* vm_cpuset */ 208 IOCNUM_ACTIVATE_CPU = 90, 209 IOCNUM_GET_CPUSET = 91, 210 IOCNUM_SUSPEND_CPU = 92, 211 IOCNUM_RESUME_CPU = 93, 212 213 /* vm_attach_vgic */ 214 IOCNUM_GET_VGIC_VERSION = 110, 215 IOCNUM_ATTACH_VGIC = 111, 216 }; 217 218 #define VM_RUN \ 219 _IOWR('v', IOCNUM_RUN, struct vm_run) 220 #define VM_SUSPEND \ 221 _IOW('v', IOCNUM_SUSPEND, struct vm_suspend) 222 #define VM_REINIT \ 223 _IO('v', IOCNUM_REINIT) 224 #define VM_ALLOC_MEMSEG \ 225 _IOW('v', IOCNUM_ALLOC_MEMSEG, struct vm_memseg) 226 #define VM_GET_MEMSEG \ 227 _IOWR('v', IOCNUM_GET_MEMSEG, struct vm_memseg) 228 #define VM_MMAP_MEMSEG \ 229 _IOW('v', IOCNUM_MMAP_MEMSEG, struct vm_memmap) 230 #define VM_MMAP_GETNEXT \ 231 _IOWR('v', IOCNUM_MMAP_GETNEXT, struct vm_memmap) 232 #define VM_MUNMAP_MEMSEG \ 233 _IOW('v', IOCNUM_MUNMAP_MEMSEG, struct vm_munmap) 234 #define VM_SET_REGISTER \ 235 _IOW('v', IOCNUM_SET_REGISTER, struct vm_register) 236 #define VM_GET_REGISTER \ 237 _IOWR('v', IOCNUM_GET_REGISTER, struct vm_register) 238 #define VM_SET_REGISTER_SET \ 239 _IOW('v', IOCNUM_SET_REGISTER_SET, struct vm_register_set) 240 #define VM_GET_REGISTER_SET \ 241 _IOWR('v', IOCNUM_GET_REGISTER_SET, struct vm_register_set) 242 #define VM_SET_CAPABILITY \ 243 _IOW('v', IOCNUM_SET_CAPABILITY, struct vm_capability) 244 #define VM_GET_CAPABILITY \ 245 _IOWR('v', IOCNUM_GET_CAPABILITY, struct vm_capability) 246 #define VM_STATS \ 247 _IOWR('v', IOCNUM_VM_STATS, struct vm_stats) 248 #define VM_STAT_DESC \ 249 _IOWR('v', IOCNUM_VM_STAT_DESC, struct vm_stat_desc) 250 #define VM_ASSERT_IRQ \ 251 _IOW('v', IOCNUM_ASSERT_IRQ, struct vm_irq) 252 #define VM_DEASSERT_IRQ \ 253 _IOW('v', IOCNUM_DEASSERT_IRQ, struct vm_irq) 254 #define VM_RAISE_MSI \ 255 _IOW('v', IOCNUM_RAISE_MSI, struct vm_msi) 256 #define VM_INJECT_EXCEPTION \ 257 _IOW('v', IOCNUM_INJECT_EXCEPTION, struct vm_exception) 258 #define VM_SET_TOPOLOGY \ 259 _IOW('v', IOCNUM_SET_TOPOLOGY, struct vm_cpu_topology) 260 #define VM_GET_TOPOLOGY \ 261 _IOR('v', IOCNUM_GET_TOPOLOGY, struct vm_cpu_topology) 262 #define VM_GLA2GPA_NOFAULT \ 263 _IOWR('v', IOCNUM_GLA2GPA_NOFAULT, struct vm_gla2gpa) 264 #define VM_ACTIVATE_CPU \ 265 _IOW('v', IOCNUM_ACTIVATE_CPU, struct vm_activate_cpu) 266 #define VM_GET_CPUS \ 267 _IOW('v', IOCNUM_GET_CPUSET, struct vm_cpuset) 268 #define VM_SUSPEND_CPU \ 269 _IOW('v', IOCNUM_SUSPEND_CPU, struct vm_activate_cpu) 270 #define VM_RESUME_CPU \ 271 _IOW('v', IOCNUM_RESUME_CPU, struct vm_activate_cpu) 272 #define VM_GET_VGIC_VERSION \ 273 _IOR('v', IOCNUM_GET_VGIC_VERSION, struct vm_vgic_version) 274 #define VM_ATTACH_VGIC \ 275 _IOW('v', IOCNUM_ATTACH_VGIC, struct vm_vgic_descr) 276 #endif 277