1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 2011 NetApp, Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * $FreeBSD$ 29 */ 30 31 #ifndef _VMM_DEV_H_ 32 #define _VMM_DEV_H_ 33 34 struct vm_snapshot_meta; 35 36 #ifdef _KERNEL 37 void vmmdev_init(void); 38 int vmmdev_cleanup(void); 39 #endif 40 41 struct vm_memmap { 42 vm_paddr_t gpa; 43 int segid; /* memory segment */ 44 vm_ooffset_t segoff; /* offset into memory segment */ 45 size_t len; /* mmap length */ 46 int prot; /* RWX */ 47 int flags; 48 }; 49 #define VM_MEMMAP_F_WIRED 0x01 50 #define VM_MEMMAP_F_IOMMU 0x02 51 52 #define VM_MEMSEG_NAME(m) ((m)->name[0] != '\0' ? (m)->name : NULL) 53 struct vm_memseg { 54 int segid; 55 size_t len; 56 char name[VM_MAX_SUFFIXLEN + 1]; 57 }; 58 59 struct vm_register { 60 int cpuid; 61 int regnum; /* enum vm_reg_name */ 62 uint64_t regval; 63 }; 64 65 struct vm_seg_desc { /* data or code segment */ 66 int cpuid; 67 int regnum; /* enum vm_reg_name */ 68 struct seg_desc desc; 69 }; 70 71 struct vm_register_set { 72 int cpuid; 73 unsigned int count; 74 const int *regnums; /* enum vm_reg_name */ 75 uint64_t *regvals; 76 }; 77 78 struct vm_run { 79 int cpuid; 80 struct vm_exit vm_exit; 81 }; 82 83 struct vm_exception { 84 int cpuid; 85 int vector; 86 uint32_t error_code; 87 int error_code_valid; 88 int restart_instruction; 89 }; 90 91 struct vm_lapic_msi { 92 uint64_t msg; 93 uint64_t addr; 94 }; 95 96 struct vm_lapic_irq { 97 int cpuid; 98 int vector; 99 }; 100 101 struct vm_ioapic_irq { 102 int irq; 103 }; 104 105 struct vm_isa_irq { 106 int atpic_irq; 107 int ioapic_irq; 108 }; 109 110 struct vm_isa_irq_trigger { 111 int atpic_irq; 112 enum vm_intr_trigger trigger; 113 }; 114 115 struct vm_capability { 116 int cpuid; 117 enum vm_cap_type captype; 118 int capval; 119 int allcpus; 120 }; 121 122 struct vm_pptdev { 123 int bus; 124 int slot; 125 int func; 126 }; 127 128 struct vm_pptdev_mmio { 129 int bus; 130 int slot; 131 int func; 132 vm_paddr_t gpa; 133 vm_paddr_t hpa; 134 size_t len; 135 }; 136 137 struct vm_pptdev_msi { 138 int vcpu; 139 int bus; 140 int slot; 141 int func; 142 int numvec; /* 0 means disabled */ 143 uint64_t msg; 144 uint64_t addr; 145 }; 146 147 struct vm_pptdev_msix { 148 int vcpu; 149 int bus; 150 int slot; 151 int func; 152 int idx; 153 uint64_t msg; 154 uint32_t vector_control; 155 uint64_t addr; 156 }; 157 158 struct vm_nmi { 159 int cpuid; 160 }; 161 162 #define MAX_VM_STATS 64 163 struct vm_stats { 164 int cpuid; /* in */ 165 int num_entries; /* out */ 166 struct timeval tv; 167 uint64_t statbuf[MAX_VM_STATS]; 168 }; 169 170 struct vm_stat_desc { 171 int index; /* in */ 172 char desc[128]; /* out */ 173 }; 174 175 struct vm_x2apic { 176 int cpuid; 177 enum x2apic_state state; 178 }; 179 180 struct vm_gpa_pte { 181 uint64_t gpa; /* in */ 182 uint64_t pte[4]; /* out */ 183 int ptenum; 184 }; 185 186 struct vm_hpet_cap { 187 uint32_t capabilities; /* lower 32 bits of HPET capabilities */ 188 }; 189 190 struct vm_suspend { 191 enum vm_suspend_how how; 192 }; 193 194 struct vm_gla2gpa { 195 int vcpuid; /* inputs */ 196 int prot; /* PROT_READ or PROT_WRITE */ 197 uint64_t gla; 198 struct vm_guest_paging paging; 199 int fault; /* outputs */ 200 uint64_t gpa; 201 }; 202 203 struct vm_activate_cpu { 204 int vcpuid; 205 }; 206 207 struct vm_cpuset { 208 int which; 209 int cpusetsize; 210 cpuset_t *cpus; 211 }; 212 #define VM_ACTIVE_CPUS 0 213 #define VM_SUSPENDED_CPUS 1 214 #define VM_DEBUG_CPUS 2 215 216 struct vm_intinfo { 217 int vcpuid; 218 uint64_t info1; 219 uint64_t info2; 220 }; 221 222 struct vm_rtc_time { 223 time_t secs; 224 }; 225 226 struct vm_rtc_data { 227 int offset; 228 uint8_t value; 229 }; 230 231 struct vm_cpu_topology { 232 uint16_t sockets; 233 uint16_t cores; 234 uint16_t threads; 235 uint16_t maxcpus; 236 }; 237 238 struct vm_readwrite_kernemu_device { 239 int vcpuid; 240 unsigned access_width : 3; 241 unsigned _unused : 29; 242 uint64_t gpa; 243 uint64_t value; 244 }; 245 _Static_assert(sizeof(struct vm_readwrite_kernemu_device) == 24, "ABI"); 246 247 enum { 248 /* general routines */ 249 IOCNUM_ABIVERS = 0, 250 IOCNUM_RUN = 1, 251 IOCNUM_SET_CAPABILITY = 2, 252 IOCNUM_GET_CAPABILITY = 3, 253 IOCNUM_SUSPEND = 4, 254 IOCNUM_REINIT = 5, 255 256 /* memory apis */ 257 IOCNUM_MAP_MEMORY = 10, /* deprecated */ 258 IOCNUM_GET_MEMORY_SEG = 11, /* deprecated */ 259 IOCNUM_GET_GPA_PMAP = 12, 260 IOCNUM_GLA2GPA = 13, 261 IOCNUM_ALLOC_MEMSEG = 14, 262 IOCNUM_GET_MEMSEG = 15, 263 IOCNUM_MMAP_MEMSEG = 16, 264 IOCNUM_MMAP_GETNEXT = 17, 265 IOCNUM_GLA2GPA_NOFAULT = 18, 266 267 /* register/state accessors */ 268 IOCNUM_SET_REGISTER = 20, 269 IOCNUM_GET_REGISTER = 21, 270 IOCNUM_SET_SEGMENT_DESCRIPTOR = 22, 271 IOCNUM_GET_SEGMENT_DESCRIPTOR = 23, 272 IOCNUM_SET_REGISTER_SET = 24, 273 IOCNUM_GET_REGISTER_SET = 25, 274 IOCNUM_GET_KERNEMU_DEV = 26, 275 IOCNUM_SET_KERNEMU_DEV = 27, 276 277 /* interrupt injection */ 278 IOCNUM_GET_INTINFO = 28, 279 IOCNUM_SET_INTINFO = 29, 280 IOCNUM_INJECT_EXCEPTION = 30, 281 IOCNUM_LAPIC_IRQ = 31, 282 IOCNUM_INJECT_NMI = 32, 283 IOCNUM_IOAPIC_ASSERT_IRQ = 33, 284 IOCNUM_IOAPIC_DEASSERT_IRQ = 34, 285 IOCNUM_IOAPIC_PULSE_IRQ = 35, 286 IOCNUM_LAPIC_MSI = 36, 287 IOCNUM_LAPIC_LOCAL_IRQ = 37, 288 IOCNUM_IOAPIC_PINCOUNT = 38, 289 IOCNUM_RESTART_INSTRUCTION = 39, 290 291 /* PCI pass-thru */ 292 IOCNUM_BIND_PPTDEV = 40, 293 IOCNUM_UNBIND_PPTDEV = 41, 294 IOCNUM_MAP_PPTDEV_MMIO = 42, 295 IOCNUM_PPTDEV_MSI = 43, 296 IOCNUM_PPTDEV_MSIX = 44, 297 298 /* statistics */ 299 IOCNUM_VM_STATS = 50, 300 IOCNUM_VM_STAT_DESC = 51, 301 302 /* kernel device state */ 303 IOCNUM_SET_X2APIC_STATE = 60, 304 IOCNUM_GET_X2APIC_STATE = 61, 305 IOCNUM_GET_HPET_CAPABILITIES = 62, 306 307 /* CPU Topology */ 308 IOCNUM_SET_TOPOLOGY = 63, 309 IOCNUM_GET_TOPOLOGY = 64, 310 311 /* legacy interrupt injection */ 312 IOCNUM_ISA_ASSERT_IRQ = 80, 313 IOCNUM_ISA_DEASSERT_IRQ = 81, 314 IOCNUM_ISA_PULSE_IRQ = 82, 315 IOCNUM_ISA_SET_IRQ_TRIGGER = 83, 316 317 /* vm_cpuset */ 318 IOCNUM_ACTIVATE_CPU = 90, 319 IOCNUM_GET_CPUSET = 91, 320 IOCNUM_SUSPEND_CPU = 92, 321 IOCNUM_RESUME_CPU = 93, 322 323 /* RTC */ 324 IOCNUM_RTC_READ = 100, 325 IOCNUM_RTC_WRITE = 101, 326 IOCNUM_RTC_SETTIME = 102, 327 IOCNUM_RTC_GETTIME = 103, 328 329 /* checkpoint */ 330 IOCNUM_SNAPSHOT_REQ = 113, 331 332 IOCNUM_RESTORE_TIME = 115 333 }; 334 335 #define VM_RUN \ 336 _IOWR('v', IOCNUM_RUN, struct vm_run) 337 #define VM_SUSPEND \ 338 _IOW('v', IOCNUM_SUSPEND, struct vm_suspend) 339 #define VM_REINIT \ 340 _IO('v', IOCNUM_REINIT) 341 #define VM_ALLOC_MEMSEG \ 342 _IOW('v', IOCNUM_ALLOC_MEMSEG, struct vm_memseg) 343 #define VM_GET_MEMSEG \ 344 _IOWR('v', IOCNUM_GET_MEMSEG, struct vm_memseg) 345 #define VM_MMAP_MEMSEG \ 346 _IOW('v', IOCNUM_MMAP_MEMSEG, struct vm_memmap) 347 #define VM_MMAP_GETNEXT \ 348 _IOWR('v', IOCNUM_MMAP_GETNEXT, struct vm_memmap) 349 #define VM_SET_REGISTER \ 350 _IOW('v', IOCNUM_SET_REGISTER, struct vm_register) 351 #define VM_GET_REGISTER \ 352 _IOWR('v', IOCNUM_GET_REGISTER, struct vm_register) 353 #define VM_SET_SEGMENT_DESCRIPTOR \ 354 _IOW('v', IOCNUM_SET_SEGMENT_DESCRIPTOR, struct vm_seg_desc) 355 #define VM_GET_SEGMENT_DESCRIPTOR \ 356 _IOWR('v', IOCNUM_GET_SEGMENT_DESCRIPTOR, struct vm_seg_desc) 357 #define VM_SET_REGISTER_SET \ 358 _IOW('v', IOCNUM_SET_REGISTER_SET, struct vm_register_set) 359 #define VM_GET_REGISTER_SET \ 360 _IOWR('v', IOCNUM_GET_REGISTER_SET, struct vm_register_set) 361 #define VM_SET_KERNEMU_DEV \ 362 _IOW('v', IOCNUM_SET_KERNEMU_DEV, \ 363 struct vm_readwrite_kernemu_device) 364 #define VM_GET_KERNEMU_DEV \ 365 _IOWR('v', IOCNUM_GET_KERNEMU_DEV, \ 366 struct vm_readwrite_kernemu_device) 367 #define VM_INJECT_EXCEPTION \ 368 _IOW('v', IOCNUM_INJECT_EXCEPTION, struct vm_exception) 369 #define VM_LAPIC_IRQ \ 370 _IOW('v', IOCNUM_LAPIC_IRQ, struct vm_lapic_irq) 371 #define VM_LAPIC_LOCAL_IRQ \ 372 _IOW('v', IOCNUM_LAPIC_LOCAL_IRQ, struct vm_lapic_irq) 373 #define VM_LAPIC_MSI \ 374 _IOW('v', IOCNUM_LAPIC_MSI, struct vm_lapic_msi) 375 #define VM_IOAPIC_ASSERT_IRQ \ 376 _IOW('v', IOCNUM_IOAPIC_ASSERT_IRQ, struct vm_ioapic_irq) 377 #define VM_IOAPIC_DEASSERT_IRQ \ 378 _IOW('v', IOCNUM_IOAPIC_DEASSERT_IRQ, struct vm_ioapic_irq) 379 #define VM_IOAPIC_PULSE_IRQ \ 380 _IOW('v', IOCNUM_IOAPIC_PULSE_IRQ, struct vm_ioapic_irq) 381 #define VM_IOAPIC_PINCOUNT \ 382 _IOR('v', IOCNUM_IOAPIC_PINCOUNT, int) 383 #define VM_ISA_ASSERT_IRQ \ 384 _IOW('v', IOCNUM_ISA_ASSERT_IRQ, struct vm_isa_irq) 385 #define VM_ISA_DEASSERT_IRQ \ 386 _IOW('v', IOCNUM_ISA_DEASSERT_IRQ, struct vm_isa_irq) 387 #define VM_ISA_PULSE_IRQ \ 388 _IOW('v', IOCNUM_ISA_PULSE_IRQ, struct vm_isa_irq) 389 #define VM_ISA_SET_IRQ_TRIGGER \ 390 _IOW('v', IOCNUM_ISA_SET_IRQ_TRIGGER, struct vm_isa_irq_trigger) 391 #define VM_SET_CAPABILITY \ 392 _IOW('v', IOCNUM_SET_CAPABILITY, struct vm_capability) 393 #define VM_GET_CAPABILITY \ 394 _IOWR('v', IOCNUM_GET_CAPABILITY, struct vm_capability) 395 #define VM_BIND_PPTDEV \ 396 _IOW('v', IOCNUM_BIND_PPTDEV, struct vm_pptdev) 397 #define VM_UNBIND_PPTDEV \ 398 _IOW('v', IOCNUM_UNBIND_PPTDEV, struct vm_pptdev) 399 #define VM_MAP_PPTDEV_MMIO \ 400 _IOW('v', IOCNUM_MAP_PPTDEV_MMIO, struct vm_pptdev_mmio) 401 #define VM_PPTDEV_MSI \ 402 _IOW('v', IOCNUM_PPTDEV_MSI, struct vm_pptdev_msi) 403 #define VM_PPTDEV_MSIX \ 404 _IOW('v', IOCNUM_PPTDEV_MSIX, struct vm_pptdev_msix) 405 #define VM_INJECT_NMI \ 406 _IOW('v', IOCNUM_INJECT_NMI, struct vm_nmi) 407 #define VM_STATS \ 408 _IOWR('v', IOCNUM_VM_STATS, struct vm_stats) 409 #define VM_STAT_DESC \ 410 _IOWR('v', IOCNUM_VM_STAT_DESC, struct vm_stat_desc) 411 #define VM_SET_X2APIC_STATE \ 412 _IOW('v', IOCNUM_SET_X2APIC_STATE, struct vm_x2apic) 413 #define VM_GET_X2APIC_STATE \ 414 _IOWR('v', IOCNUM_GET_X2APIC_STATE, struct vm_x2apic) 415 #define VM_GET_HPET_CAPABILITIES \ 416 _IOR('v', IOCNUM_GET_HPET_CAPABILITIES, struct vm_hpet_cap) 417 #define VM_SET_TOPOLOGY \ 418 _IOW('v', IOCNUM_SET_TOPOLOGY, struct vm_cpu_topology) 419 #define VM_GET_TOPOLOGY \ 420 _IOR('v', IOCNUM_GET_TOPOLOGY, struct vm_cpu_topology) 421 #define VM_GET_GPA_PMAP \ 422 _IOWR('v', IOCNUM_GET_GPA_PMAP, struct vm_gpa_pte) 423 #define VM_GLA2GPA \ 424 _IOWR('v', IOCNUM_GLA2GPA, struct vm_gla2gpa) 425 #define VM_GLA2GPA_NOFAULT \ 426 _IOWR('v', IOCNUM_GLA2GPA_NOFAULT, struct vm_gla2gpa) 427 #define VM_ACTIVATE_CPU \ 428 _IOW('v', IOCNUM_ACTIVATE_CPU, struct vm_activate_cpu) 429 #define VM_GET_CPUS \ 430 _IOW('v', IOCNUM_GET_CPUSET, struct vm_cpuset) 431 #define VM_SUSPEND_CPU \ 432 _IOW('v', IOCNUM_SUSPEND_CPU, struct vm_activate_cpu) 433 #define VM_RESUME_CPU \ 434 _IOW('v', IOCNUM_RESUME_CPU, struct vm_activate_cpu) 435 #define VM_SET_INTINFO \ 436 _IOW('v', IOCNUM_SET_INTINFO, struct vm_intinfo) 437 #define VM_GET_INTINFO \ 438 _IOWR('v', IOCNUM_GET_INTINFO, struct vm_intinfo) 439 #define VM_RTC_WRITE \ 440 _IOW('v', IOCNUM_RTC_WRITE, struct vm_rtc_data) 441 #define VM_RTC_READ \ 442 _IOWR('v', IOCNUM_RTC_READ, struct vm_rtc_data) 443 #define VM_RTC_SETTIME \ 444 _IOW('v', IOCNUM_RTC_SETTIME, struct vm_rtc_time) 445 #define VM_RTC_GETTIME \ 446 _IOR('v', IOCNUM_RTC_GETTIME, struct vm_rtc_time) 447 #define VM_RESTART_INSTRUCTION \ 448 _IOW('v', IOCNUM_RESTART_INSTRUCTION, int) 449 #define VM_SNAPSHOT_REQ \ 450 _IOWR('v', IOCNUM_SNAPSHOT_REQ, struct vm_snapshot_meta) 451 #define VM_RESTORE_TIME \ 452 _IOWR('v', IOCNUM_RESTORE_TIME, int) 453 #endif 454