hypervisor.h revision 1.60 1 1.60 riastrad /* $NetBSD: hypervisor.h,v 1.60 2024/07/16 22:44:38 riastradh Exp $ */
2 1.18 bouyer
3 1.18 bouyer /*
4 1.18 bouyer * Copyright (c) 2006 Manuel Bouyer.
5 1.18 bouyer *
6 1.18 bouyer * Redistribution and use in source and binary forms, with or without
7 1.18 bouyer * modification, are permitted provided that the following conditions
8 1.18 bouyer * are met:
9 1.18 bouyer * 1. Redistributions of source code must retain the above copyright
10 1.18 bouyer * notice, this list of conditions and the following disclaimer.
11 1.18 bouyer * 2. Redistributions in binary form must reproduce the above copyright
12 1.18 bouyer * notice, this list of conditions and the following disclaimer in the
13 1.18 bouyer * documentation and/or other materials provided with the distribution.
14 1.18 bouyer *
15 1.18 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 1.18 bouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 1.18 bouyer * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 1.18 bouyer * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 1.18 bouyer * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 1.18 bouyer * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 1.18 bouyer * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 1.18 bouyer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 1.18 bouyer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 1.18 bouyer * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 1.18 bouyer *
26 1.18 bouyer */
27 1.1 cl
28 1.1 cl /*
29 1.57 riastrad *
30 1.1 cl * Communication to/from hypervisor.
31 1.57 riastrad *
32 1.10 bouyer * Copyright (c) 2002-2004, K A Fraser
33 1.57 riastrad *
34 1.1 cl * Permission is hereby granted, free of charge, to any person obtaining a copy
35 1.10 bouyer * of this source file (the "Software"), to deal in the Software without
36 1.10 bouyer * restriction, including without limitation the rights to use, copy, modify,
37 1.10 bouyer * merge, publish, distribute, sublicense, and/or sell copies of the Software,
38 1.10 bouyer * and to permit persons to whom the Software is furnished to do so, subject to
39 1.10 bouyer * the following conditions:
40 1.57 riastrad *
41 1.1 cl * The above copyright notice and this permission notice shall be included in
42 1.1 cl * all copies or substantial portions of the Software.
43 1.57 riastrad *
44 1.10 bouyer * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
45 1.10 bouyer * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
46 1.10 bouyer * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
47 1.10 bouyer * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
48 1.10 bouyer * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
49 1.10 bouyer * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
50 1.10 bouyer * IN THE SOFTWARE.
51 1.1 cl */
52 1.1 cl
53 1.1 cl
54 1.1 cl #ifndef _XEN_HYPERVISOR_H_
55 1.1 cl #define _XEN_HYPERVISOR_H_
56 1.1 cl
57 1.18 bouyer #include "opt_xen.h"
58 1.46 cherry #include "isa.h"
59 1.46 cherry #include "pci.h"
60 1.1 cl
61 1.58 bouyer #include <machine/vmparam.h>
62 1.58 bouyer
63 1.51 bouyer struct cpu_info;
64 1.51 bouyer
65 1.51 bouyer int xen_hvm_init(void);
66 1.51 bouyer int xen_hvm_init_cpu(struct cpu_info *);
67 1.51 bouyer void xen_mainbus_attach(device_t, device_t, void *);
68 1.51 bouyer
69 1.4 cl struct hypervisor_attach_args {
70 1.4 cl const char *haa_busname;
71 1.4 cl };
72 1.4 cl
73 1.5 cl struct xencons_attach_args {
74 1.4 cl const char *xa_device;
75 1.1 cl };
76 1.1 cl
77 1.1 cl struct xen_npx_attach_args {
78 1.4 cl const char *xa_device;
79 1.1 cl };
80 1.1 cl
81 1.1 cl
82 1.10 bouyer #define u8 uint8_t
83 1.8 cl #define u16 uint16_t
84 1.8 cl #define u32 uint32_t
85 1.8 cl #define u64 uint64_t
86 1.10 bouyer #define s8 int8_t
87 1.10 bouyer #define s16 int16_t
88 1.10 bouyer #define s32 int32_t
89 1.10 bouyer #define s64 int64_t
90 1.10 bouyer
91 1.48 cherry #include <sys/atomic.h>
92 1.47 cherry
93 1.47 cherry #include <xen/include/public/xen.h>
94 1.47 cherry #include <xen/include/public/sched.h>
95 1.47 cherry #include <xen/include/public/platform.h>
96 1.28 cegger #if __XEN_INTERFACE_VERSION__ < 0x00030204
97 1.47 cherry #include <xen/include/public/dom0_ops.h>
98 1.28 cegger #endif
99 1.47 cherry #include <xen/include/public/event_channel.h>
100 1.47 cherry #include <xen/include/public/physdev.h>
101 1.47 cherry #include <xen/include/public/memory.h>
102 1.47 cherry #include <xen/include/public/io/netif.h>
103 1.47 cherry #include <xen/include/public/io/blkif.h>
104 1.52 bouyer #include <xen/include/public/arch-x86/hvm/start_info.h>
105 1.8 cl
106 1.49 cherry #if __XEN_INTERFACE_VERSION < 0x00030208
107 1.48 cherry /* Undo namespace damage from xen/include/public/io/ring.h
108 1.48 cherry * The proper fix is to get upstream to stop assuming that all OSs use
109 1.48 cherry * mb(), rmb(), wmb().
110 1.48 cherry */
111 1.48 cherry #undef xen_mb
112 1.48 cherry #undef xen_rmb
113 1.48 cherry #undef xen_wmb
114 1.48 cherry
115 1.60 riastrad void xen_mb(void);
116 1.56 riastrad #define xen_rmb() membar_acquire()
117 1.56 riastrad #define xen_wmb() membar_release()
118 1.49 cherry #endif /* __XEN_INTERFACE_VERSION */
119 1.48 cherry
120 1.51 bouyer #include <machine/xen/hypercalls.h>
121 1.24 bouyer
122 1.10 bouyer #undef u8
123 1.8 cl #undef u16
124 1.8 cl #undef u32
125 1.8 cl #undef u64
126 1.10 bouyer #undef s8
127 1.10 bouyer #undef s16
128 1.10 bouyer #undef s32
129 1.10 bouyer #undef s64
130 1.1 cl
131 1.1 cl
132 1.24 bouyer
133 1.1 cl /*
134 1.1 cl * a placeholder for the start of day information passed up from the hypervisor
135 1.1 cl */
136 1.1 cl union start_info_union
137 1.1 cl {
138 1.1 cl start_info_t start_info;
139 1.58 bouyer char padding[PAGE_SIZE];
140 1.1 cl };
141 1.1 cl extern union start_info_union start_info_union;
142 1.1 cl #define xen_start_info (start_info_union.start_info)
143 1.1 cl
144 1.58 bouyer CTASSERT(sizeof(start_info_t) <= PAGE_SIZE);
145 1.58 bouyer
146 1.52 bouyer extern struct hvm_start_info *hvm_start_info;
147 1.52 bouyer
148 1.18 bouyer /* For use in guest OSes. */
149 1.26 tron extern volatile shared_info_t *HYPERVISOR_shared_info;
150 1.1 cl
151 1.52 bouyer /* console */
152 1.52 bouyer extern volatile struct xencons_interface *xencons_interface;
153 1.52 bouyer
154 1.29 cegger
155 1.29 cegger /* Structural guest handles introduced in 0x00030201. */
156 1.29 cegger #if __XEN_INTERFACE_VERSION__ >= 0x00030201
157 1.29 cegger #define xenguest_handle(hnd) (hnd).p
158 1.29 cegger #else
159 1.29 cegger #define xenguest_handle(hnd) hnd
160 1.29 cegger #endif
161 1.29 cegger
162 1.1 cl /* hypervisor.c */
163 1.10 bouyer struct intrframe;
164 1.34 cherry struct cpu_info;
165 1.10 bouyer void do_hypervisor_callback(struct intrframe *regs);
166 1.53 bouyer #if defined(XENPV) && (NPCI > 0 || NISA > 0)
167 1.53 bouyer void hypervisor_prime_pirq_event(int, unsigned int);
168 1.53 bouyer void hypervisor_ack_pirq_event(unsigned int);
169 1.53 bouyer #endif /* XENPV && ( NPCI > 0 || NISA > 0 ) */
170 1.10 bouyer
171 1.38 bouyer extern int xen_version;
172 1.38 bouyer #define XEN_MAJOR(x) (((x) & 0xffff0000) >> 16)
173 1.38 bouyer #define XEN_MINOR(x) ((x) & 0x0000ffff)
174 1.38 bouyer
175 1.44 pgoyette /*
176 1.44 pgoyette * Does the hypervisor we're running on support an api
177 1.44 pgoyette * call at the requested version number ?
178 1.44 pgoyette */
179 1.44 pgoyette #define XEN_VERSION_SUPPORTED(major, minor) \
180 1.44 pgoyette (XEN_MAJOR(xen_version) > (major) || \
181 1.44 pgoyette (XEN_MAJOR(xen_version) == (major) && \
182 1.44 pgoyette XEN_MINOR(xen_version) >= (minor)))
183 1.44 pgoyette
184 1.10 bouyer /* hypervisor_machdep.c */
185 1.35 cherry void hypervisor_send_event(struct cpu_info *, unsigned int);
186 1.10 bouyer void hypervisor_unmask_event(unsigned int);
187 1.10 bouyer void hypervisor_mask_event(unsigned int);
188 1.10 bouyer void hypervisor_clear_event(unsigned int);
189 1.51 bouyer void hypervisor_enable_sir(unsigned int);
190 1.55 knakahar void hypervisor_set_ipending(uint64_t, int, int);
191 1.27 bouyer void hypervisor_machdep_attach(void);
192 1.33 jym void hypervisor_machdep_resume(void);
193 1.1 cl
194 1.57 riastrad /*
195 1.15 bouyer * Force a proper event-channel callback from Xen after clearing the
196 1.15 bouyer * callback mask. We do this in a very simple manner, by making a call
197 1.57 riastrad * down into Xen. The pending flag will be checked by Xen on return.
198 1.15 bouyer */
199 1.19 perry static __inline void hypervisor_force_callback(void)
200 1.15 bouyer {
201 1.18 bouyer (void)HYPERVISOR_xen_version(0, (void*)0);
202 1.15 bouyer } __attribute__((no_instrument_function)) /* used by mcount */
203 1.15 bouyer
204 1.19 perry static __inline void
205 1.15 bouyer hypervisor_notify_via_evtchn(unsigned int port)
206 1.15 bouyer {
207 1.15 bouyer evtchn_op_t op;
208 1.15 bouyer
209 1.15 bouyer op.cmd = EVTCHNOP_send;
210 1.18 bouyer op.u.send.port = port;
211 1.15 bouyer (void)HYPERVISOR_event_channel_op(&op);
212 1.15 bouyer }
213 1.15 bouyer
214 1.52 bouyer void xen_init_ksyms(void);
215 1.54 bouyer void xen_map_vcpu(struct cpu_info *);
216 1.52 bouyer
217 1.59 bouyer void xen_early_console(void);
218 1.59 bouyer
219 1.1 cl #endif /* _XEN_HYPERVISOR_H_ */
220