xref: /illumos-gate/usr/src/uts/intel/sys/hypervisor.h (revision 56f33205c9ed776c3c909e07d52e94610a675740)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  *
29  * Communication to/from hypervisor.
30  *
31  * Copyright (c) 2002-2004, K A Fraser
32  *
33  * Permission is hereby granted, free of charge, to any person obtaining a copy
34  * of this source file (the "Software"), to deal in the Software without
35  * restriction, including without limitation the rights to use, copy, modify,
36  * merge, publish, distribute, sublicense, and/or sell copies of the Software,
37  * and to permit persons to whom the Software is furnished to do so, subject to
38  * the following conditions:
39  *
40  * The above copyright notice and this permission notice shall be included in
41  * all copies or substantial portions of the Software.
42  *
43  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
44  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
45  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
46  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
47  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
48  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
49  * IN THE SOFTWARE.
50  */
51 
52 #ifndef _SYS_HYPERVISOR_H
53 #define	_SYS_HYPERVISOR_H
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
59 #define	xen_mb	membar_enter
60 #define	xen_wmb	membar_producer
61 
62 #ifndef __xpv
63 #include <sys/xpv_support.h>
64 #else
65 #include <sys/xpv_impl.h>
66 #endif
67 #include <sys/xen_errno.h>
68 
69 #if !defined(_ASM)
70 
71 #include <sys/processor.h>
72 #include <sys/cpuvar.h>
73 #ifdef __xpv
74 #include <sys/xen_mmu.h>
75 #endif
76 #include <sys/systm.h>
77 #include <xen/public/callback.h>
78 #include <xen/public/event_channel.h>
79 #include <xen/public/grant_table.h>
80 #include <xen/public/io/blkif.h>
81 #include <xen/public/io/xenbus.h>
82 #include <xen/public/memory.h>
83 #include <xen/public/nmi.h>
84 #include <xen/public/physdev.h>
85 #include <xen/public/sched.h>
86 #include <xen/public/platform.h>
87 #include <xen/public/vcpu.h>
88 #include <xen/public/version.h>
89 #include <xen/public/hvm/params.h>
90 #include <xen/public/arch-x86/xen-mca.h>
91 
92 extern shared_info_t *HYPERVISOR_shared_info;
93 extern void *HYPERVISOR_console_page;
94 
95 /* -- move these definitions elsewhere -- */
96 
97 extern int xen_debug_handler(void *);
98 extern void xen_printf(const char *, ...) __KPRINTFLIKE(1);
99 #pragma rarely_called(xen_printf)
100 
101 extern void xen_callback(void);
102 extern void xen_failsafe_callback(void);
103 
104 extern hrtime_t xpv_gethrtime(void);
105 extern hrtime_t xpv_getsystime(void);
106 
107 extern void xpv_time_suspend(void);
108 extern void xpv_time_resume(void);
109 
110 extern void startup_xen_version(void);
111 extern void startup_xen_mca(void);
112 
113 extern void mach_cpucontext_reset(cpu_t *);
114 extern void mach_cpucontext_restore(cpu_t *);
115 
116 extern void mp_enter_barrier(void);
117 extern void mp_leave_barrier(void);
118 
119 extern cpuset_t cpu_suspend_lost_set;
120 
121 extern int xen_gdt_setprot(cpu_t *, uint_t);
122 extern int xen_ldt_setprot(user_desc_t *, size_t, uint_t);
123 
124 /* -- while you're down there, move these too -- */
125 
126 typedef struct xen_mc_lcpu_cookie *xen_mc_lcpu_cookie_t;
127 
128 extern xen_mc_lcpu_cookie_t xen_physcpu_next(xen_mc_lcpu_cookie_t);
129 extern const char *xen_physcpu_vendorstr(xen_mc_lcpu_cookie_t);
130 extern int xen_physcpu_family(xen_mc_lcpu_cookie_t);
131 extern int xen_physcpu_model(xen_mc_lcpu_cookie_t);
132 extern int xen_physcpu_stepping(xen_mc_lcpu_cookie_t);
133 extern id_t xen_physcpu_chipid(xen_mc_lcpu_cookie_t);
134 extern id_t xen_physcpu_coreid(xen_mc_lcpu_cookie_t);
135 extern id_t xen_physcpu_strandid(xen_mc_lcpu_cookie_t);
136 extern id_t xen_physcpu_initial_apicid(xen_mc_lcpu_cookie_t);
137 extern boolean_t xen_physcpu_is_cmt(xen_mc_lcpu_cookie_t);
138 extern id_t xen_physcpu_logical_id(xen_mc_lcpu_cookie_t);
139 extern uint64_t xen_physcpu_mcg_cap(xen_mc_lcpu_cookie_t);
140 
141 extern int xen_map_gref(uint_t cmd, gnttab_map_grant_ref_t *mapop,
142     uint_t count, boolean_t uvaddr);
143 
144 /*
145  * Wrappered versions of the hypercalls that diagnose/panic on failure
146  */
147 extern void xen_set_gdt(ulong_t *, int);
148 extern void xen_set_ldt(user_desc_t *, uint_t);
149 extern void xen_stack_switch(ulong_t, ulong_t);
150 extern long xen_set_trap_table(trap_info_t *);
151 
152 #if defined(__amd64)
153 extern void xen_set_segment_base(int, ulong_t);
154 #endif	/* __amd64 */
155 extern long xen_vcpu_up(processorid_t);
156 extern long xen_vcpu_down(processorid_t);
157 extern void xen_enable_user_iopl(void);
158 extern void xen_disable_user_iopl(void);
159 
160 extern int xen_get_mc_physcpuinfo(xen_mc_logical_cpu_t *, uint_t *);
161 extern uint_t xen_phys_ncpus;
162 extern xen_mc_logical_cpu_t *xen_phys_cpus;
163 
164 extern uint_t xpv_nr_phys_cpus(void);
165 extern pgcnt_t xpv_nr_phys_pages(void);
166 extern uint64_t xpv_cpu_khz(void);
167 
168 
169 /*
170  * A quick way to ask if we're DOM0 or not ..
171  */
172 #ifndef __xpv
173 
174 #define	DOMAIN_IS_INITDOMAIN(info)	(__lintzero)
175 #define	DOMAIN_IS_PRIVILEGED(info)	(__lintzero)
176 
177 #else
178 
179 #define	DOMAIN_IS_INITDOMAIN(info)	\
180 	(((info)->flags & SIF_INITDOMAIN) == SIF_INITDOMAIN)
181 
182 #define	DOMAIN_IS_PRIVILEGED(info)	\
183 	(((info)->flags & SIF_PRIVILEGED) == SIF_PRIVILEGED)
184 
185 #endif
186 
187 /*
188  * start of day information passed up from the hypervisor
189  */
190 extern start_info_t *xen_info;
191 
192 extern long __hypercall0(int);
193 extern long __hypercall1(int, ulong_t);
194 extern long __hypercall2(int, ulong_t, ulong_t);
195 extern long __hypercall3(int, ulong_t, ulong_t, ulong_t);
196 extern long __hypercall4(int, ulong_t, ulong_t, ulong_t, ulong_t);
197 extern long __hypercall5(int, ulong_t, ulong_t, ulong_t, ulong_t, ulong_t);
198 
199 extern int __hypercall0_int(int);
200 extern int __hypercall1_int(int, ulong_t);
201 extern int __hypercall2_int(int, ulong_t, ulong_t);
202 extern int __hypercall3_int(int, ulong_t, ulong_t, ulong_t);
203 extern int __hypercall4_int(int, ulong_t, ulong_t, ulong_t, ulong_t);
204 extern int __hypercall5_int(int, ulong_t, ulong_t, ulong_t, ulong_t, ulong_t);
205 
206 extern long HYPERVISOR_set_trap_table(trap_info_t *);
207 extern int HYPERVISOR_mmu_update(mmu_update_t *, int, int *, domid_t);
208 extern long HYPERVISOR_set_gdt(ulong_t *, int);
209 extern long HYPERVISOR_stack_switch(ulong_t, ulong_t);
210 #if defined(__amd64)
211 extern long HYPERVISOR_set_callbacks(ulong_t, ulong_t, ulong_t);
212 #else
213 extern long HYPERVISOR_set_callbacks(ulong_t, ulong_t, ulong_t, ulong_t);
214 #endif
215 extern long HYPERVISOR_fpu_taskswitch(int);
216 /* *** __HYPERVISOR_sched_op_compat *** OBSOLETED */
217 extern long HYPERVISOR_platform_op(xen_platform_op_t *);
218 /* *** __HYPERVISOR_set_debugreg *** NOT IMPLEMENTED */
219 /* *** __HYPERVISOR_get_debugreg *** NOT IMPLEMENTED */
220 extern long HYPERVISOR_update_descriptor(maddr_t, uint64_t);
221 extern long HYPERVISOR_memory_op(int, void *);
222 extern long HYPERVISOR_multicall(void *, uint_t);
223 extern int HYPERVISOR_update_va_mapping(ulong_t, uint64_t, ulong_t);
224 extern long HYPERVISOR_set_timer_op(uint64_t);
225 /* *** __HYPERVISOR_event_channel_op_compat *** OBSOLETED */
226 extern long HYPERVISOR_xen_version(int, void *);
227 extern long HYPERVISOR_console_io(int, int, char *);
228 /* *** __HYPERVISOR_physdev_op_compat *** OBSOLETED */
229 extern long HYPERVISOR_grant_table_op(unsigned int, void *, unsigned int);
230 extern long HYPERVISOR_vm_assist(unsigned int, unsigned int);
231 extern int HYPERVISOR_update_va_mapping_otherdomain(ulong_t,
232     uint64_t, ulong_t, domid_t);
233 /* *** __HYPERVISOR_iret *** IN i86xpv/sys/machprivregs.h */
234 extern long HYPERVISOR_vcpu_op(int, int, void *);
235 #if defined(__amd64)
236 extern long HYPERVISOR_set_segment_base(int, ulong_t);
237 #endif	/* __amd64 */
238 extern int HYPERVISOR_mmuext_op(struct mmuext_op *, int, uint_t *, domid_t);
239 extern long HYPERVISOR_nmi_op(int cmd, void *);
240 extern long HYPERVISOR_sched_op(int, void *);
241 extern long HYPERVISOR_callback_op(int, void *);
242 /* *** __HYPERVISOR_xenoprof_op *** NOT IMPLEMENTED */
243 extern long HYPERVISOR_event_channel_op(int, void *); /* does return long */
244 extern long HYPERVISOR_physdev_op(int, void *);
245 extern long HYPERVISOR_hvm_op(int cmd, void *);
246 /* *** __HYPERVISOR_kexec_op *** NOT IMPLEMENTED */
247 #if defined(__xpv)
248 extern long HYPERVISOR_mca(uint32_t, xen_mc_t *);
249 #endif
250 
251 /*
252  * HYPERCALL HELPER ROUTINES
253  *    These don't have their own unique hypercalls.
254  */
255 extern long HYPERVISOR_yield(void);
256 extern long HYPERVISOR_block(void);
257 extern long HYPERVISOR_shutdown(uint_t);
258 extern long HYPERVISOR_poll(evtchn_port_t *, uint_t, uint64_t);
259 extern long HYPERVISOR_suspend(ulong_t);
260 
261 #endif /* !_ASM */
262 
263 #ifdef __cplusplus
264 }
265 #endif
266 
267 #endif /* _SYS_HYPERVISOR_H */
268