]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/amd64/include/vmm_dev.h
IFC @ r245178
[FreeBSD/FreeBSD.git] / sys / amd64 / include / vmm_dev.h
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: vmm_dev.h 482 2011-05-09 21:22:43Z grehan $
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_pin {
55         int             vm_cpuid;
56         int             host_cpuid;     /* -1 to unpin */
57 };
58
59 struct vm_run {
60         int             cpuid;
61         uint64_t        rip;            /* start running here */
62         struct vm_exit  vm_exit;
63 };
64
65 struct vm_event {
66         int             cpuid;
67         enum vm_event_type type;
68         int             vector;
69         uint32_t        error_code;
70         int             error_code_valid;
71 };
72
73 struct vm_lapic_irq {
74         int             cpuid;
75         int             vector;
76 };
77
78 struct vm_capability {
79         int             cpuid;
80         enum vm_cap_type captype;
81         int             capval;
82         int             allcpus;
83 };
84
85 struct vm_pptdev {
86         int             bus;
87         int             slot;
88         int             func;
89 };
90
91 struct vm_pptdev_mmio {
92         int             bus;
93         int             slot;
94         int             func;
95         vm_paddr_t      gpa;
96         vm_paddr_t      hpa;
97         size_t          len;
98 };
99
100 struct vm_pptdev_msi {
101         int             vcpu;
102         int             bus;
103         int             slot;
104         int             func;
105         int             numvec;         /* 0 means disabled */
106         int             vector;
107         int             destcpu;
108 };
109
110 struct vm_pptdev_msix {
111         int             vcpu;
112         int             bus;
113         int             slot;
114         int             func;
115         int             idx;
116         uint32_t        msg;
117         uint32_t        vector_control;
118         uint64_t        addr;
119 };
120
121 struct vm_nmi {
122         int             cpuid;
123 };
124
125 #define MAX_VM_STATS    64
126 struct vm_stats {
127         int             cpuid;                          /* in */
128         int             num_entries;                    /* out */
129         struct timeval  tv;
130         uint64_t        statbuf[MAX_VM_STATS];
131 };
132
133 struct vm_stat_desc {
134         int             index;                          /* in */
135         char            desc[128];                      /* out */
136 };
137
138 struct vm_x2apic {
139         int                     cpuid;
140         enum x2apic_state       state;
141 };
142
143 enum {
144         IOCNUM_RUN,
145         IOCNUM_SET_PINNING,
146         IOCNUM_GET_PINNING,
147         IOCNUM_MAP_MEMORY,
148         IOCNUM_GET_MEMORY_SEG,
149         IOCNUM_SET_REGISTER,
150         IOCNUM_GET_REGISTER,
151         IOCNUM_SET_SEGMENT_DESCRIPTOR,
152         IOCNUM_GET_SEGMENT_DESCRIPTOR,
153         IOCNUM_INJECT_EVENT,
154         IOCNUM_LAPIC_IRQ,
155         IOCNUM_SET_CAPABILITY,
156         IOCNUM_GET_CAPABILITY,
157         IOCNUM_BIND_PPTDEV,
158         IOCNUM_UNBIND_PPTDEV,
159         IOCNUM_MAP_PPTDEV_MMIO,
160         IOCNUM_PPTDEV_MSI,
161         IOCNUM_PPTDEV_MSIX,
162         IOCNUM_INJECT_NMI,
163         IOCNUM_VM_STATS,
164         IOCNUM_VM_STAT_DESC,
165         IOCNUM_SET_X2APIC_STATE,
166         IOCNUM_GET_X2APIC_STATE,
167 };
168
169 #define VM_RUN          \
170         _IOWR('v', IOCNUM_RUN, struct vm_run)
171 #define VM_SET_PINNING  \
172         _IOW('v', IOCNUM_SET_PINNING, struct vm_pin)
173 #define VM_GET_PINNING  \
174         _IOWR('v', IOCNUM_GET_PINNING, struct vm_pin)
175 #define VM_MAP_MEMORY   \
176         _IOWR('v', IOCNUM_MAP_MEMORY, struct vm_memory_segment)
177 #define VM_GET_MEMORY_SEG \
178         _IOWR('v', IOCNUM_GET_MEMORY_SEG, struct vm_memory_segment)
179 #define VM_SET_REGISTER \
180         _IOW('v', IOCNUM_SET_REGISTER, struct vm_register)
181 #define VM_GET_REGISTER \
182         _IOWR('v', IOCNUM_GET_REGISTER, struct vm_register)
183 #define VM_SET_SEGMENT_DESCRIPTOR \
184         _IOW('v', IOCNUM_SET_SEGMENT_DESCRIPTOR, struct vm_seg_desc)
185 #define VM_GET_SEGMENT_DESCRIPTOR \
186         _IOWR('v', IOCNUM_GET_SEGMENT_DESCRIPTOR, struct vm_seg_desc)
187 #define VM_INJECT_EVENT \
188         _IOW('v', IOCNUM_INJECT_EVENT, struct vm_event)
189 #define VM_LAPIC_IRQ            \
190         _IOW('v', IOCNUM_LAPIC_IRQ, struct vm_lapic_irq)
191 #define VM_SET_CAPABILITY \
192         _IOW('v', IOCNUM_SET_CAPABILITY, struct vm_capability)
193 #define VM_GET_CAPABILITY \
194         _IOWR('v', IOCNUM_GET_CAPABILITY, struct vm_capability)
195 #define VM_BIND_PPTDEV \
196         _IOW('v', IOCNUM_BIND_PPTDEV, struct vm_pptdev)
197 #define VM_UNBIND_PPTDEV \
198         _IOW('v', IOCNUM_UNBIND_PPTDEV, struct vm_pptdev)
199 #define VM_MAP_PPTDEV_MMIO \
200         _IOW('v', IOCNUM_MAP_PPTDEV_MMIO, struct vm_pptdev_mmio)
201 #define VM_PPTDEV_MSI \
202         _IOW('v', IOCNUM_PPTDEV_MSI, struct vm_pptdev_msi)
203 #define VM_PPTDEV_MSIX \
204         _IOW('v', IOCNUM_PPTDEV_MSIX, struct vm_pptdev_msix)
205 #define VM_INJECT_NMI \
206         _IOW('v', IOCNUM_INJECT_NMI, struct vm_nmi)
207 #define VM_STATS \
208         _IOWR('v', IOCNUM_VM_STATS, struct vm_stats)
209 #define VM_STAT_DESC \
210         _IOWR('v', IOCNUM_VM_STAT_DESC, struct vm_stat_desc)
211 #define VM_SET_X2APIC_STATE \
212         _IOW('v', IOCNUM_SET_X2APIC_STATE, struct vm_x2apic)
213 #define VM_GET_X2APIC_STATE \
214         _IOWR('v', IOCNUM_GET_X2APIC_STATE, struct vm_x2apic)
215 #endif