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_memseg_fbsd12 { 60 int segid; 61 size_t len; 62 char name[64]; 63 }; 64 _Static_assert(sizeof(struct vm_memseg_fbsd12) == 80, "COMPAT_FREEBSD12 ABI"); 65 66 struct vm_register { 67 int cpuid; 68 int regnum; /* enum vm_reg_name */ 69 uint64_t regval; 70 }; 71 72 struct vm_seg_desc { /* data or code segment */ 73 int cpuid; 74 int regnum; /* enum vm_reg_name */ 75 struct seg_desc desc; 76 }; 77 78 struct vm_register_set { 79 int cpuid; 80 unsigned int count; 81 const int *regnums; /* enum vm_reg_name */ 82 uint64_t *regvals; 83 }; 84 85 struct vm_run { 86 int cpuid; 87 struct vm_exit vm_exit; 88 }; 89 90 struct vm_exception { 91 int cpuid; 92 int vector; 93 uint32_t error_code; 94 int error_code_valid; 95 int restart_instruction; 96 }; 97 98 struct vm_lapic_msi { 99 uint64_t msg; 100 uint64_t addr; 101 }; 102 103 struct vm_lapic_irq { 104 int cpuid; 105 int vector; 106 }; 107 108 struct vm_ioapic_irq { 109 int irq; 110 }; 111 112 struct vm_isa_irq { 113 int atpic_irq; 114 int ioapic_irq; 115 }; 116 117 struct vm_isa_irq_trigger { 118 int atpic_irq; 119 enum vm_intr_trigger trigger; 120 }; 121 122 struct vm_capability { 123 int cpuid; 124 enum vm_cap_type captype; 125 int capval; 126 int allcpus; 127 }; 128 129 struct vm_pptdev { 130 int bus; 131 int slot; 132 int func; 133 }; 134 135 struct vm_pptdev_mmio { 136 int bus; 137 int slot; 138 int func; 139 vm_paddr_t gpa; 140 vm_paddr_t hpa; 141 size_t len; 142 }; 143 144 struct vm_pptdev_msi { 145 int vcpu; 146 int bus; 147 int slot; 148 int func; 149 int numvec; /* 0 means disabled */ 150 uint64_t msg; 151 uint64_t addr; 152 }; 153 154 struct vm_pptdev_msix { 155 int vcpu; 156 int bus; 157 int slot; 158 int func; 159 int idx; 160 uint64_t msg; 161 uint32_t vector_control; 162 uint64_t addr; 163 }; 164 165 struct vm_nmi { 166 int cpuid; 167 }; 168 169 #define MAX_VM_STATS 64 170 struct vm_stats { 171 int cpuid; /* in */ 172 int num_entries; /* out */ 173 struct timeval tv; 174 uint64_t statbuf[MAX_VM_STATS]; 175 }; 176 177 struct vm_stat_desc { 178 int index; /* in */ 179 char desc[128]; /* out */ 180 }; 181 182 struct vm_x2apic { 183 int cpuid; 184 enum x2apic_state state; 185 }; 186 187 struct vm_gpa_pte { 188 uint64_t gpa; /* in */ 189 uint64_t pte[4]; /* out */ 190 int ptenum; 191 }; 192 193 struct vm_hpet_cap { 194 uint32_t capabilities; /* lower 32 bits of HPET capabilities */ 195 }; 196 197 struct vm_suspend { 198 enum vm_suspend_how how; 199 }; 200 201 struct vm_gla2gpa { 202 int vcpuid; /* inputs */ 203 int prot; /* PROT_READ or PROT_WRITE */ 204 uint64_t gla; 205 struct vm_guest_paging paging; 206 int fault; /* outputs */ 207 uint64_t gpa; 208 }; 209 210 struct vm_activate_cpu { 211 int vcpuid; 212 }; 213 214 struct vm_cpuset { 215 int which; 216 int cpusetsize; 217 cpuset_t *cpus; 218 }; 219 #define VM_ACTIVE_CPUS 0 220 #define VM_SUSPENDED_CPUS 1 221 #define VM_DEBUG_CPUS 2 222 223 struct vm_intinfo { 224 int vcpuid; 225 uint64_t info1; 226 uint64_t info2; 227 }; 228 229 struct vm_rtc_time { 230 time_t secs; 231 }; 232 233 struct vm_rtc_data { 234 int offset; 235 uint8_t value; 236 }; 237 238 struct vm_cpu_topology { 239 uint16_t sockets; 240 uint16_t cores; 241 uint16_t threads; 242 uint16_t maxcpus; 243 }; 244 245 struct vm_readwrite_kernemu_device { 246 int vcpuid; 247 unsigned access_width : 3; 248 unsigned _unused : 29; 249 uint64_t gpa; 250 uint64_t value; 251 }; 252 _Static_assert(sizeof(struct vm_readwrite_kernemu_device) == 24, "ABI"); 253 254 enum { 255 /* general routines */ 256 IOCNUM_ABIVERS = 0, 257 IOCNUM_RUN = 1, 258 IOCNUM_SET_CAPABILITY = 2, 259 IOCNUM_GET_CAPABILITY = 3, 260 IOCNUM_SUSPEND = 4, 261 IOCNUM_REINIT = 5, 262 263 /* memory apis */ 264 IOCNUM_MAP_MEMORY = 10, /* deprecated */ 265 IOCNUM_GET_MEMORY_SEG = 11, /* deprecated */ 266 IOCNUM_GET_GPA_PMAP = 12, 267 IOCNUM_GLA2GPA = 13, 268 IOCNUM_ALLOC_MEMSEG = 14, 269 IOCNUM_GET_MEMSEG = 15, 270 IOCNUM_MMAP_MEMSEG = 16, 271 IOCNUM_MMAP_GETNEXT = 17, 272 IOCNUM_GLA2GPA_NOFAULT = 18, 273 274 /* register/state accessors */ 275 IOCNUM_SET_REGISTER = 20, 276 IOCNUM_GET_REGISTER = 21, 277 IOCNUM_SET_SEGMENT_DESCRIPTOR = 22, 278 IOCNUM_GET_SEGMENT_DESCRIPTOR = 23, 279 IOCNUM_SET_REGISTER_SET = 24, 280 IOCNUM_GET_REGISTER_SET = 25, 281 IOCNUM_GET_KERNEMU_DEV = 26, 282 IOCNUM_SET_KERNEMU_DEV = 27, 283 284 /* interrupt injection */ 285 IOCNUM_GET_INTINFO = 28, 286 IOCNUM_SET_INTINFO = 29, 287 IOCNUM_INJECT_EXCEPTION = 30, 288 IOCNUM_LAPIC_IRQ = 31, 289 IOCNUM_INJECT_NMI = 32, 290 IOCNUM_IOAPIC_ASSERT_IRQ = 33, 291 IOCNUM_IOAPIC_DEASSERT_IRQ = 34, 292 IOCNUM_IOAPIC_PULSE_IRQ = 35, 293 IOCNUM_LAPIC_MSI = 36, 294 IOCNUM_LAPIC_LOCAL_IRQ = 37, 295 IOCNUM_IOAPIC_PINCOUNT = 38, 296 IOCNUM_RESTART_INSTRUCTION = 39, 297 298 /* PCI pass-thru */ 299 IOCNUM_BIND_PPTDEV = 40, 300 IOCNUM_UNBIND_PPTDEV = 41, 301 IOCNUM_MAP_PPTDEV_MMIO = 42, 302 IOCNUM_PPTDEV_MSI = 43, 303 IOCNUM_PPTDEV_MSIX = 44, 304 IOCNUM_PPTDEV_DISABLE_MSIX = 45, 305 306 /* statistics */ 307 IOCNUM_VM_STATS = 50, 308 IOCNUM_VM_STAT_DESC = 51, 309 310 /* kernel device state */ 311 IOCNUM_SET_X2APIC_STATE = 60, 312 IOCNUM_GET_X2APIC_STATE = 61, 313 IOCNUM_GET_HPET_CAPABILITIES = 62, 314 315 /* CPU Topology */ 316 IOCNUM_SET_TOPOLOGY = 63, 317 IOCNUM_GET_TOPOLOGY = 64, 318 319 /* legacy interrupt injection */ 320 IOCNUM_ISA_ASSERT_IRQ = 80, 321 IOCNUM_ISA_DEASSERT_IRQ = 81, 322 IOCNUM_ISA_PULSE_IRQ = 82, 323 IOCNUM_ISA_SET_IRQ_TRIGGER = 83, 324 325 /* vm_cpuset */ 326 IOCNUM_ACTIVATE_CPU = 90, 327 IOCNUM_GET_CPUSET = 91, 328 IOCNUM_SUSPEND_CPU = 92, 329 IOCNUM_RESUME_CPU = 93, 330 331 /* RTC */ 332 IOCNUM_RTC_READ = 100, 333 IOCNUM_RTC_WRITE = 101, 334 IOCNUM_RTC_SETTIME = 102, 335 IOCNUM_RTC_GETTIME = 103, 336 337 /* checkpoint */ 338 IOCNUM_SNAPSHOT_REQ = 113, 339 340 IOCNUM_RESTORE_TIME = 115 341 }; 342 343 #define VM_RUN \ 344 _IOWR('v', IOCNUM_RUN, struct vm_run) 345 #define VM_SUSPEND \ 346 _IOW('v', IOCNUM_SUSPEND, struct vm_suspend) 347 #define VM_REINIT \ 348 _IO('v', IOCNUM_REINIT) 349 #define VM_ALLOC_MEMSEG_FBSD12 \ 350 _IOW('v', IOCNUM_ALLOC_MEMSEG, struct vm_memseg_fbsd12) 351 #define VM_ALLOC_MEMSEG \ 352 _IOW('v', IOCNUM_ALLOC_MEMSEG, struct vm_memseg) 353 #define VM_GET_MEMSEG_FBSD12 \ 354 _IOWR('v', IOCNUM_GET_MEMSEG, struct vm_memseg_fbsd12) 355 #define VM_GET_MEMSEG \ 356 _IOWR('v', IOCNUM_GET_MEMSEG, struct vm_memseg) 357 #define VM_MMAP_MEMSEG \ 358 _IOW('v', IOCNUM_MMAP_MEMSEG, struct vm_memmap) 359 #define VM_MMAP_GETNEXT \ 360 _IOWR('v', IOCNUM_MMAP_GETNEXT, struct vm_memmap) 361 #define VM_SET_REGISTER \ 362 _IOW('v', IOCNUM_SET_REGISTER, struct vm_register) 363 #define VM_GET_REGISTER \ 364 _IOWR('v', IOCNUM_GET_REGISTER, struct vm_register) 365 #define VM_SET_SEGMENT_DESCRIPTOR \ 366 _IOW('v', IOCNUM_SET_SEGMENT_DESCRIPTOR, struct vm_seg_desc) 367 #define VM_GET_SEGMENT_DESCRIPTOR \ 368 _IOWR('v', IOCNUM_GET_SEGMENT_DESCRIPTOR, struct vm_seg_desc) 369 #define VM_SET_REGISTER_SET \ 370 _IOW('v', IOCNUM_SET_REGISTER_SET, struct vm_register_set) 371 #define VM_GET_REGISTER_SET \ 372 _IOWR('v', IOCNUM_GET_REGISTER_SET, struct vm_register_set) 373 #define VM_SET_KERNEMU_DEV \ 374 _IOW('v', IOCNUM_SET_KERNEMU_DEV, \ 375 struct vm_readwrite_kernemu_device) 376 #define VM_GET_KERNEMU_DEV \ 377 _IOWR('v', IOCNUM_GET_KERNEMU_DEV, \ 378 struct vm_readwrite_kernemu_device) 379 #define VM_INJECT_EXCEPTION \ 380 _IOW('v', IOCNUM_INJECT_EXCEPTION, struct vm_exception) 381 #define VM_LAPIC_IRQ \ 382 _IOW('v', IOCNUM_LAPIC_IRQ, struct vm_lapic_irq) 383 #define VM_LAPIC_LOCAL_IRQ \ 384 _IOW('v', IOCNUM_LAPIC_LOCAL_IRQ, struct vm_lapic_irq) 385 #define VM_LAPIC_MSI \ 386 _IOW('v', IOCNUM_LAPIC_MSI, struct vm_lapic_msi) 387 #define VM_IOAPIC_ASSERT_IRQ \ 388 _IOW('v', IOCNUM_IOAPIC_ASSERT_IRQ, struct vm_ioapic_irq) 389 #define VM_IOAPIC_DEASSERT_IRQ \ 390 _IOW('v', IOCNUM_IOAPIC_DEASSERT_IRQ, struct vm_ioapic_irq) 391 #define VM_IOAPIC_PULSE_IRQ \ 392 _IOW('v', IOCNUM_IOAPIC_PULSE_IRQ, struct vm_ioapic_irq) 393 #define VM_IOAPIC_PINCOUNT \ 394 _IOR('v', IOCNUM_IOAPIC_PINCOUNT, int) 395 #define VM_ISA_ASSERT_IRQ \ 396 _IOW('v', IOCNUM_ISA_ASSERT_IRQ, struct vm_isa_irq) 397 #define VM_ISA_DEASSERT_IRQ \ 398 _IOW('v', IOCNUM_ISA_DEASSERT_IRQ, struct vm_isa_irq) 399 #define VM_ISA_PULSE_IRQ \ 400 _IOW('v', IOCNUM_ISA_PULSE_IRQ, struct vm_isa_irq) 401 #define VM_ISA_SET_IRQ_TRIGGER \ 402 _IOW('v', IOCNUM_ISA_SET_IRQ_TRIGGER, struct vm_isa_irq_trigger) 403 #define VM_SET_CAPABILITY \ 404 _IOW('v', IOCNUM_SET_CAPABILITY, struct vm_capability) 405 #define VM_GET_CAPABILITY \ 406 _IOWR('v', IOCNUM_GET_CAPABILITY, struct vm_capability) 407 #define VM_BIND_PPTDEV \ 408 _IOW('v', IOCNUM_BIND_PPTDEV, struct vm_pptdev) 409 #define VM_UNBIND_PPTDEV \ 410 _IOW('v', IOCNUM_UNBIND_PPTDEV, struct vm_pptdev) 411 #define VM_MAP_PPTDEV_MMIO \ 412 _IOW('v', IOCNUM_MAP_PPTDEV_MMIO, struct vm_pptdev_mmio) 413 #define VM_PPTDEV_MSI \ 414 _IOW('v', IOCNUM_PPTDEV_MSI, struct vm_pptdev_msi) 415 #define VM_PPTDEV_MSIX \ 416 _IOW('v', IOCNUM_PPTDEV_MSIX, struct vm_pptdev_msix) 417 #define VM_PPTDEV_DISABLE_MSIX \ 418 _IOW('v', IOCNUM_PPTDEV_DISABLE_MSIX, struct vm_pptdev) 419 #define VM_INJECT_NMI \ 420 _IOW('v', IOCNUM_INJECT_NMI, struct vm_nmi) 421 #define VM_STATS \ 422 _IOWR('v', IOCNUM_VM_STATS, struct vm_stats) 423 #define VM_STAT_DESC \ 424 _IOWR('v', IOCNUM_VM_STAT_DESC, struct vm_stat_desc) 425 #define VM_SET_X2APIC_STATE \ 426 _IOW('v', IOCNUM_SET_X2APIC_STATE, struct vm_x2apic) 427 #define VM_GET_X2APIC_STATE \ 428 _IOWR('v', IOCNUM_GET_X2APIC_STATE, struct vm_x2apic) 429 #define VM_GET_HPET_CAPABILITIES \ 430 _IOR('v', IOCNUM_GET_HPET_CAPABILITIES, struct vm_hpet_cap) 431 #define VM_SET_TOPOLOGY \ 432 _IOW('v', IOCNUM_SET_TOPOLOGY, struct vm_cpu_topology) 433 #define VM_GET_TOPOLOGY \ 434 _IOR('v', IOCNUM_GET_TOPOLOGY, struct vm_cpu_topology) 435 #define VM_GET_GPA_PMAP \ 436 _IOWR('v', IOCNUM_GET_GPA_PMAP, struct vm_gpa_pte) 437 #define VM_GLA2GPA \ 438 _IOWR('v', IOCNUM_GLA2GPA, struct vm_gla2gpa) 439 #define VM_GLA2GPA_NOFAULT \ 440 _IOWR('v', IOCNUM_GLA2GPA_NOFAULT, struct vm_gla2gpa) 441 #define VM_ACTIVATE_CPU \ 442 _IOW('v', IOCNUM_ACTIVATE_CPU, struct vm_activate_cpu) 443 #define VM_GET_CPUS \ 444 _IOW('v', IOCNUM_GET_CPUSET, struct vm_cpuset) 445 #define VM_SUSPEND_CPU \ 446 _IOW('v', IOCNUM_SUSPEND_CPU, struct vm_activate_cpu) 447 #define VM_RESUME_CPU \ 448 _IOW('v', IOCNUM_RESUME_CPU, struct vm_activate_cpu) 449 #define VM_SET_INTINFO \ 450 _IOW('v', IOCNUM_SET_INTINFO, struct vm_intinfo) 451 #define VM_GET_INTINFO \ 452 _IOWR('v', IOCNUM_GET_INTINFO, struct vm_intinfo) 453 #define VM_RTC_WRITE \ 454 _IOW('v', IOCNUM_RTC_WRITE, struct vm_rtc_data) 455 #define VM_RTC_READ \ 456 _IOWR('v', IOCNUM_RTC_READ, struct vm_rtc_data) 457 #define VM_RTC_SETTIME \ 458 _IOW('v', IOCNUM_RTC_SETTIME, struct vm_rtc_time) 459 #define VM_RTC_GETTIME \ 460 _IOR('v', IOCNUM_RTC_GETTIME, struct vm_rtc_time) 461 #define VM_RESTART_INSTRUCTION \ 462 _IOW('v', IOCNUM_RESTART_INSTRUCTION, int) 463 #define VM_SNAPSHOT_REQ \ 464 _IOWR('v', IOCNUM_SNAPSHOT_REQ, struct vm_snapshot_meta) 465 #define VM_RESTORE_TIME \ 466 _IOWR('v', IOCNUM_RESTORE_TIME, int) 467 #endif 468