1 /*- 2 * Copyright (c) 2011 NetApp, Inc. 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 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 24 * SUCH DAMAGE. 25 * 26 * $FreeBSD$ 27 */ 28 29 #ifndef _VMM_DEV_H_ 30 #define _VMM_DEV_H_ 31 32 #ifdef _KERNEL 33 void vmmdev_init(void); 34 int vmmdev_cleanup(void); 35 #endif 36 37 struct vm_memory_segment { 38 vm_paddr_t gpa; /* in */ 39 size_t len; /* in */ 40 }; 41 42 struct vm_register { 43 int cpuid; 44 int regnum; /* enum vm_reg_name */ 45 uint64_t regval; 46 }; 47 48 struct vm_seg_desc { /* data or code segment */ 49 int cpuid; 50 int regnum; /* enum vm_reg_name */ 51 struct seg_desc desc; 52 }; 53 54 struct vm_run { 55 int cpuid; 56 uint64_t rip; /* start running here */ 57 struct vm_exit vm_exit; 58 }; 59 60 struct vm_event { 61 int cpuid; 62 enum vm_event_type type; 63 int vector; 64 uint32_t error_code; 65 int error_code_valid; 66 }; 67 68 struct vm_lapic_irq { 69 int cpuid; 70 int vector; 71 }; 72 73 struct vm_capability { 74 int cpuid; 75 enum vm_cap_type captype; 76 int capval; 77 int allcpus; 78 }; 79 80 struct vm_pptdev { 81 int bus; 82 int slot; 83 int func; 84 }; 85 86 struct vm_pptdev_mmio { 87 int bus; 88 int slot; 89 int func; 90 vm_paddr_t gpa; 91 vm_paddr_t hpa; 92 size_t len; 93 }; 94 95 struct vm_pptdev_msi { 96 int vcpu; 97 int bus; 98 int slot; 99 int func; 100 int numvec; /* 0 means disabled */ 101 int vector; 102 int destcpu; 103 }; 104 105 struct vm_pptdev_msix { 106 int vcpu; 107 int bus; 108 int slot; 109 int func; 110 int idx; 111 uint32_t msg; 112 uint32_t vector_control; 113 uint64_t addr; 114 }; 115 116 struct vm_nmi { 117 int cpuid; 118 }; 119 120 #define MAX_VM_STATS 64 121 struct vm_stats { 122 int cpuid; /* in */ 123 int num_entries; /* out */ 124 struct timeval tv; 125 uint64_t statbuf[MAX_VM_STATS]; 126 }; 127 128 struct vm_stat_desc { 129 int index; /* in */ 130 char desc[128]; /* out */ 131 }; 132 133 struct vm_x2apic { 134 int cpuid; 135 enum x2apic_state state; 136 }; 137 138 enum { 139 /* general routines */ 140 IOCNUM_ABIVERS = 0, 141 IOCNUM_RUN = 1, 142 IOCNUM_SET_CAPABILITY = 2, 143 IOCNUM_GET_CAPABILITY = 3, 144 145 /* memory apis */ 146 IOCNUM_MAP_MEMORY = 10, 147 IOCNUM_GET_MEMORY_SEG = 11, 148 149 /* register/state accessors */ 150 IOCNUM_SET_REGISTER = 20, 151 IOCNUM_GET_REGISTER = 21, 152 IOCNUM_SET_SEGMENT_DESCRIPTOR = 22, 153 IOCNUM_GET_SEGMENT_DESCRIPTOR = 23, 154 155 /* interrupt injection */ 156 IOCNUM_INJECT_EVENT = 30, 157 IOCNUM_LAPIC_IRQ = 31, 158 IOCNUM_INJECT_NMI = 32, 159 160 /* PCI pass-thru */ 161 IOCNUM_BIND_PPTDEV = 40, 162 IOCNUM_UNBIND_PPTDEV = 41, 163 IOCNUM_MAP_PPTDEV_MMIO = 42, 164 IOCNUM_PPTDEV_MSI = 43, 165 IOCNUM_PPTDEV_MSIX = 44, 166 167 /* statistics */ 168 IOCNUM_VM_STATS = 50, 169 IOCNUM_VM_STAT_DESC = 51, 170 171 /* kernel device state */ 172 IOCNUM_SET_X2APIC_STATE = 60, 173 IOCNUM_GET_X2APIC_STATE = 61, 174 }; 175 176 #define VM_RUN \ 177 _IOWR('v', IOCNUM_RUN, struct vm_run) 178 #define VM_MAP_MEMORY \ 179 _IOWR('v', IOCNUM_MAP_MEMORY, struct vm_memory_segment) 180 #define VM_GET_MEMORY_SEG \ 181 _IOWR('v', IOCNUM_GET_MEMORY_SEG, struct vm_memory_segment) 182 #define VM_SET_REGISTER \ 183 _IOW('v', IOCNUM_SET_REGISTER, struct vm_register) 184 #define VM_GET_REGISTER \ 185 _IOWR('v', IOCNUM_GET_REGISTER, struct vm_register) 186 #define VM_SET_SEGMENT_DESCRIPTOR \ 187 _IOW('v', IOCNUM_SET_SEGMENT_DESCRIPTOR, struct vm_seg_desc) 188 #define VM_GET_SEGMENT_DESCRIPTOR \ 189 _IOWR('v', IOCNUM_GET_SEGMENT_DESCRIPTOR, struct vm_seg_desc) 190 #define VM_INJECT_EVENT \ 191 _IOW('v', IOCNUM_INJECT_EVENT, struct vm_event) 192 #define VM_LAPIC_IRQ \ 193 _IOW('v', IOCNUM_LAPIC_IRQ, struct vm_lapic_irq) 194 #define VM_SET_CAPABILITY \ 195 _IOW('v', IOCNUM_SET_CAPABILITY, struct vm_capability) 196 #define VM_GET_CAPABILITY \ 197 _IOWR('v', IOCNUM_GET_CAPABILITY, struct vm_capability) 198 #define VM_BIND_PPTDEV \ 199 _IOW('v', IOCNUM_BIND_PPTDEV, struct vm_pptdev) 200 #define VM_UNBIND_PPTDEV \ 201 _IOW('v', IOCNUM_UNBIND_PPTDEV, struct vm_pptdev) 202 #define VM_MAP_PPTDEV_MMIO \ 203 _IOW('v', IOCNUM_MAP_PPTDEV_MMIO, struct vm_pptdev_mmio) 204 #define VM_PPTDEV_MSI \ 205 _IOW('v', IOCNUM_PPTDEV_MSI, struct vm_pptdev_msi) 206 #define VM_PPTDEV_MSIX \ 207 _IOW('v', IOCNUM_PPTDEV_MSIX, struct vm_pptdev_msix) 208 #define VM_INJECT_NMI \ 209 _IOW('v', IOCNUM_INJECT_NMI, struct vm_nmi) 210 #define VM_STATS \ 211 _IOWR('v', IOCNUM_VM_STATS, struct vm_stats) 212 #define VM_STAT_DESC \ 213 _IOWR('v', IOCNUM_VM_STAT_DESC, struct vm_stat_desc) 214 #define VM_SET_X2APIC_STATE \ 215 _IOW('v', IOCNUM_SET_X2APIC_STATE, struct vm_x2apic) 216 #define VM_GET_X2APIC_STATE \ 217 _IOWR('v', IOCNUM_GET_X2APIC_STATE, struct vm_x2apic) 218 #endif 219