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