xref: /netbsd-src/sys/arch/xen/include/hypervisor.h (revision 8b0f9554ff8762542c4defc4f70e1eb76fb508fa)
1 /*	$NetBSD: hypervisor.h,v 1.24 2007/11/22 16:16:57 bouyer 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/dom0_ops.h>
91 #include <xen/xen3-public/event_channel.h>
92 #include <xen/xen3-public/physdev.h>
93 #include <xen/xen3-public/memory.h>
94 #include <xen/xen3-public/io/netif.h>
95 #include <xen/xen3-public/io/blkif.h>
96 #else
97 #include <xen/xen-public/xen.h>
98 #include <xen/xen-public/dom0_ops.h>
99 #include <xen/xen-public/event_channel.h>
100 #include <xen/xen-public/physdev.h>
101 #include <xen/xen-public/io/domain_controller.h>
102 #include <xen/xen-public/io/netif.h>
103 #include <xen/xen-public/io/blkif.h>
104 #endif
105 
106 #include <machine/hypercalls.h>
107 
108 #undef u8
109 #undef u16
110 #undef u32
111 #undef u64
112 #undef s8
113 #undef s16
114 #undef s32
115 #undef s64
116 
117 
118 
119 /*
120  * a placeholder for the start of day information passed up from the hypervisor
121  */
122 union start_info_union
123 {
124     start_info_t start_info;
125     char padding[512];
126 };
127 extern union start_info_union start_info_union;
128 #define xen_start_info (start_info_union.start_info)
129 
130 /* For use in guest OSes. */
131 volatile extern shared_info_t *HYPERVISOR_shared_info;
132 
133 /* hypervisor.c */
134 struct intrframe;
135 void do_hypervisor_callback(struct intrframe *regs);
136 void hypervisor_enable_event(unsigned int);
137 
138 /* hypervisor_machdep.c */
139 void hypervisor_unmask_event(unsigned int);
140 void hypervisor_mask_event(unsigned int);
141 void hypervisor_clear_event(unsigned int);
142 void hypervisor_enable_ipl(unsigned int);
143 void hypervisor_set_ipending(u_int32_t, int, int);
144 
145 
146 /*
147  * Force a proper event-channel callback from Xen after clearing the
148  * callback mask. We do this in a very simple manner, by making a call
149  * down into Xen. The pending flag will be checked by Xen on return.
150  */
151 static __inline void hypervisor_force_callback(void)
152 {
153 #ifdef XEN3
154 	(void)HYPERVISOR_xen_version(0, (void*)0);
155 #else
156 	(void)HYPERVISOR_xen_version(0);
157 #endif
158 } __attribute__((no_instrument_function)) /* used by mcount */
159 
160 static __inline void
161 hypervisor_notify_via_evtchn(unsigned int port)
162 {
163 	evtchn_op_t op;
164 
165 	op.cmd = EVTCHNOP_send;
166 #ifdef XEN3
167 	op.u.send.port = port;
168 #else
169 	op.u.send.local_port = port;
170 #endif
171 	(void)HYPERVISOR_event_channel_op(&op);
172 }
173 
174 #endif /* _XEN_HYPERVISOR_H_ */
175