xref: /netbsd-src/sys/arch/xen/include/hypervisor.h (revision 404fbe5fb94ca1e054339640cabb2801ce52dd30)
1 /*	$NetBSD: hypervisor.h,v 1.29 2008/11/13 18:44:51 cegger Exp $	*/
2 
3 /*
4  * Copyright (c) 2006 Manuel Bouyer.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. All advertising materials mentioning features or use of this software
15  *    must display the following acknowledgement:
16  *	This product includes software developed by Manuel Bouyer.
17  * 4. The name of the author may not be used to endorse or promote products
18  *    derived from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  *
31  */
32 
33 /*
34  *
35  * Communication to/from hypervisor.
36  *
37  * Copyright (c) 2002-2004, K A Fraser
38  *
39  * Permission is hereby granted, free of charge, to any person obtaining a copy
40  * of this source file (the "Software"), to deal in the Software without
41  * restriction, including without limitation the rights to use, copy, modify,
42  * merge, publish, distribute, sublicense, and/or sell copies of the Software,
43  * and to permit persons to whom the Software is furnished to do so, subject to
44  * the following conditions:
45  *
46  * The above copyright notice and this permission notice shall be included in
47  * all copies or substantial portions of the Software.
48  *
49  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
50  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
51  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
52  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
53  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
54  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
55  * IN THE SOFTWARE.
56  */
57 
58 
59 #ifndef _XEN_HYPERVISOR_H_
60 #define _XEN_HYPERVISOR_H_
61 
62 #include "opt_xen.h"
63 
64 
65 struct hypervisor_attach_args {
66 	const char 		*haa_busname;
67 };
68 
69 struct xencons_attach_args {
70 	const char 		*xa_device;
71 };
72 
73 struct xen_npx_attach_args {
74 	const char 		*xa_device;
75 };
76 
77 
78 #define	u8 uint8_t
79 #define	u16 uint16_t
80 #define	u32 uint32_t
81 #define	u64 uint64_t
82 #define	s8 int8_t
83 #define	s16 int16_t
84 #define	s32 int32_t
85 #define	s64 int64_t
86 
87 #ifdef XEN3
88 #include <xen/xen3-public/xen.h>
89 #include <xen/xen3-public/sched.h>
90 #include <xen/xen3-public/platform.h>
91 #if __XEN_INTERFACE_VERSION__ < 0x00030204
92 #include <xen/xen3-public/dom0_ops.h>
93 #endif
94 #include <xen/xen3-public/event_channel.h>
95 #include <xen/xen3-public/physdev.h>
96 #include <xen/xen3-public/memory.h>
97 #include <xen/xen3-public/io/netif.h>
98 #include <xen/xen3-public/io/blkif.h>
99 #else
100 #include <xen/xen-public/xen.h>
101 #include <xen/xen-public/dom0_ops.h>
102 #include <xen/xen-public/event_channel.h>
103 #include <xen/xen-public/physdev.h>
104 #include <xen/xen-public/io/domain_controller.h>
105 #include <xen/xen-public/io/netif.h>
106 #include <xen/xen-public/io/blkif.h>
107 #endif
108 
109 #include <machine/hypercalls.h>
110 
111 #undef u8
112 #undef u16
113 #undef u32
114 #undef u64
115 #undef s8
116 #undef s16
117 #undef s32
118 #undef s64
119 
120 
121 
122 /*
123  * a placeholder for the start of day information passed up from the hypervisor
124  */
125 union start_info_union
126 {
127     start_info_t start_info;
128     char padding[512];
129 };
130 extern union start_info_union start_info_union;
131 #define xen_start_info (start_info_union.start_info)
132 
133 /* For use in guest OSes. */
134 extern volatile shared_info_t *HYPERVISOR_shared_info;
135 
136 
137 /* Structural guest handles introduced in 0x00030201. */
138 #if __XEN_INTERFACE_VERSION__ >= 0x00030201
139 #define xenguest_handle(hnd)	(hnd).p
140 #else
141 #define xenguest_handle(hnd)	hnd
142 #endif
143 
144 /* hypervisor.c */
145 struct intrframe;
146 void do_hypervisor_callback(struct intrframe *regs);
147 void hypervisor_enable_event(unsigned int);
148 
149 /* hypervisor_machdep.c */
150 void hypervisor_unmask_event(unsigned int);
151 void hypervisor_mask_event(unsigned int);
152 void hypervisor_clear_event(unsigned int);
153 void hypervisor_enable_ipl(unsigned int);
154 void hypervisor_set_ipending(uint32_t, int, int);
155 void hypervisor_machdep_attach(void);
156 
157 /*
158  * Force a proper event-channel callback from Xen after clearing the
159  * callback mask. We do this in a very simple manner, by making a call
160  * down into Xen. The pending flag will be checked by Xen on return.
161  */
162 static __inline void hypervisor_force_callback(void)
163 {
164 #ifdef XEN3
165 	(void)HYPERVISOR_xen_version(0, (void*)0);
166 #else
167 	(void)HYPERVISOR_xen_version(0);
168 #endif
169 } __attribute__((no_instrument_function)) /* used by mcount */
170 
171 static __inline void
172 hypervisor_notify_via_evtchn(unsigned int port)
173 {
174 	evtchn_op_t op;
175 
176 	op.cmd = EVTCHNOP_send;
177 #ifdef XEN3
178 	op.u.send.port = port;
179 #else
180 	op.u.send.local_port = port;
181 #endif
182 	(void)HYPERVISOR_event_channel_op(&op);
183 }
184 
185 #endif /* _XEN_HYPERVISOR_H_ */
186