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