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