xref: /freebsd/sys/amd64/include/vmm_dev.h (revision 3fc9e2c36555140de248a0b4def91bbfa44d7c2c)
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 	IOCNUM_RUN,
140 	IOCNUM_MAP_MEMORY,
141 	IOCNUM_GET_MEMORY_SEG,
142 	IOCNUM_SET_REGISTER,
143 	IOCNUM_GET_REGISTER,
144 	IOCNUM_SET_SEGMENT_DESCRIPTOR,
145 	IOCNUM_GET_SEGMENT_DESCRIPTOR,
146 	IOCNUM_INJECT_EVENT,
147 	IOCNUM_LAPIC_IRQ,
148 	IOCNUM_SET_CAPABILITY,
149 	IOCNUM_GET_CAPABILITY,
150 	IOCNUM_BIND_PPTDEV,
151 	IOCNUM_UNBIND_PPTDEV,
152 	IOCNUM_MAP_PPTDEV_MMIO,
153 	IOCNUM_PPTDEV_MSI,
154 	IOCNUM_PPTDEV_MSIX,
155 	IOCNUM_INJECT_NMI,
156 	IOCNUM_VM_STATS,
157 	IOCNUM_VM_STAT_DESC,
158 	IOCNUM_SET_X2APIC_STATE,
159 	IOCNUM_GET_X2APIC_STATE,
160 };
161 
162 #define	VM_RUN		\
163 	_IOWR('v', IOCNUM_RUN, struct vm_run)
164 #define	VM_MAP_MEMORY	\
165 	_IOWR('v', IOCNUM_MAP_MEMORY, struct vm_memory_segment)
166 #define	VM_GET_MEMORY_SEG \
167 	_IOWR('v', IOCNUM_GET_MEMORY_SEG, struct vm_memory_segment)
168 #define	VM_SET_REGISTER \
169 	_IOW('v', IOCNUM_SET_REGISTER, struct vm_register)
170 #define	VM_GET_REGISTER \
171 	_IOWR('v', IOCNUM_GET_REGISTER, struct vm_register)
172 #define	VM_SET_SEGMENT_DESCRIPTOR \
173 	_IOW('v', IOCNUM_SET_SEGMENT_DESCRIPTOR, struct vm_seg_desc)
174 #define	VM_GET_SEGMENT_DESCRIPTOR \
175 	_IOWR('v', IOCNUM_GET_SEGMENT_DESCRIPTOR, struct vm_seg_desc)
176 #define	VM_INJECT_EVENT	\
177 	_IOW('v', IOCNUM_INJECT_EVENT, struct vm_event)
178 #define	VM_LAPIC_IRQ 		\
179 	_IOW('v', IOCNUM_LAPIC_IRQ, struct vm_lapic_irq)
180 #define	VM_SET_CAPABILITY \
181 	_IOW('v', IOCNUM_SET_CAPABILITY, struct vm_capability)
182 #define	VM_GET_CAPABILITY \
183 	_IOWR('v', IOCNUM_GET_CAPABILITY, struct vm_capability)
184 #define	VM_BIND_PPTDEV \
185 	_IOW('v', IOCNUM_BIND_PPTDEV, struct vm_pptdev)
186 #define	VM_UNBIND_PPTDEV \
187 	_IOW('v', IOCNUM_UNBIND_PPTDEV, struct vm_pptdev)
188 #define	VM_MAP_PPTDEV_MMIO \
189 	_IOW('v', IOCNUM_MAP_PPTDEV_MMIO, struct vm_pptdev_mmio)
190 #define	VM_PPTDEV_MSI \
191 	_IOW('v', IOCNUM_PPTDEV_MSI, struct vm_pptdev_msi)
192 #define	VM_PPTDEV_MSIX \
193 	_IOW('v', IOCNUM_PPTDEV_MSIX, struct vm_pptdev_msix)
194 #define VM_INJECT_NMI \
195 	_IOW('v', IOCNUM_INJECT_NMI, struct vm_nmi)
196 #define	VM_STATS \
197 	_IOWR('v', IOCNUM_VM_STATS, struct vm_stats)
198 #define	VM_STAT_DESC \
199 	_IOWR('v', IOCNUM_VM_STAT_DESC, struct vm_stat_desc)
200 #define	VM_SET_X2APIC_STATE \
201 	_IOW('v', IOCNUM_SET_X2APIC_STATE, struct vm_x2apic)
202 #define	VM_GET_X2APIC_STATE \
203 	_IOWR('v', IOCNUM_GET_X2APIC_STATE, struct vm_x2apic)
204 #endif
205