xenfunc.c revision 1.2.4.2 1 1.2.4.2 ad /* $NetBSD: xenfunc.c,v 1.2.4.2 2007/12/03 19:04:46 ad Exp $ */
2 1.2.4.2 ad
3 1.2.4.2 ad /*
4 1.2.4.2 ad *
5 1.2.4.2 ad * Copyright (c) 2004 Christian Limpach.
6 1.2.4.2 ad * All rights reserved.
7 1.2.4.2 ad *
8 1.2.4.2 ad * Redistribution and use in source and binary forms, with or without
9 1.2.4.2 ad * modification, are permitted provided that the following conditions
10 1.2.4.2 ad * are met:
11 1.2.4.2 ad * 1. Redistributions of source code must retain the above copyright
12 1.2.4.2 ad * notice, this list of conditions and the following disclaimer.
13 1.2.4.2 ad * 2. Redistributions in binary form must reproduce the above copyright
14 1.2.4.2 ad * notice, this list of conditions and the following disclaimer in the
15 1.2.4.2 ad * documentation and/or other materials provided with the distribution.
16 1.2.4.2 ad * 3. All advertising materials mentioning features or use of this software
17 1.2.4.2 ad * must display the following acknowledgement:
18 1.2.4.2 ad * This product includes software developed by Christian Limpach.
19 1.2.4.2 ad * 4. The name of the author may not be used to endorse or promote products
20 1.2.4.2 ad * derived from this software without specific prior written permission.
21 1.2.4.2 ad *
22 1.2.4.2 ad * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 1.2.4.2 ad * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.2.4.2 ad * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.2.4.2 ad * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 1.2.4.2 ad * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 1.2.4.2 ad * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 1.2.4.2 ad * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 1.2.4.2 ad * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 1.2.4.2 ad * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 1.2.4.2 ad * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.2.4.2 ad */
33 1.2.4.2 ad
34 1.2.4.2 ad #include <sys/param.h>
35 1.2.4.2 ad
36 1.2.4.2 ad #include <uvm/uvm_extern.h>
37 1.2.4.2 ad
38 1.2.4.2 ad #include <machine/intr.h>
39 1.2.4.2 ad #include <machine/vmparam.h>
40 1.2.4.2 ad #include <machine/pmap.h>
41 1.2.4.2 ad #include <xen/xen.h>
42 1.2.4.2 ad #include <xen/hypervisor.h>
43 1.2.4.2 ad //#include <xen/evtchn.h>
44 1.2.4.2 ad #include <xen/xenpmap.h>
45 1.2.4.2 ad #include <machine/pte.h>
46 1.2.4.2 ad
47 1.2.4.2 ad #ifdef XENDEBUG_LOW
48 1.2.4.2 ad #define __PRINTK(x) printk x
49 1.2.4.2 ad #else
50 1.2.4.2 ad #define __PRINTK(x)
51 1.2.4.2 ad #endif
52 1.2.4.2 ad
53 1.2.4.2 ad void xen_set_ldt(vaddr_t, uint32_t);
54 1.2.4.2 ad void xen_update_descriptor(union descriptor *, union descriptor *);
55 1.2.4.2 ad
56 1.2.4.2 ad void
57 1.2.4.2 ad invlpg(vaddr_t addr)
58 1.2.4.2 ad {
59 1.2.4.2 ad int s = splvm();
60 1.2.4.2 ad xpq_queue_invlpg(addr);
61 1.2.4.2 ad xpq_flush_queue();
62 1.2.4.2 ad splx(s);
63 1.2.4.2 ad }
64 1.2.4.2 ad
65 1.2.4.2 ad #ifndef __x86_64__
66 1.2.4.2 ad void
67 1.2.4.2 ad lldt(u_short sel)
68 1.2.4.2 ad {
69 1.2.4.2 ad
70 1.2.4.2 ad /* __PRINTK(("ldt %x\n", IDXSELN(sel))); */
71 1.2.4.2 ad if (sel == GSEL(GLDT_SEL, SEL_KPL))
72 1.2.4.2 ad xen_set_ldt((vaddr_t)ldt, NLDT);
73 1.2.4.2 ad else
74 1.2.4.2 ad xen_set_ldt(cpu_info_primary.ci_gdt[IDXSELN(sel)].ld.ld_base,
75 1.2.4.2 ad cpu_info_primary.ci_gdt[IDXSELN(sel)].ld.ld_entries);
76 1.2.4.2 ad }
77 1.2.4.2 ad #endif
78 1.2.4.2 ad
79 1.2.4.2 ad void
80 1.2.4.2 ad ltr(u_short sel)
81 1.2.4.2 ad {
82 1.2.4.2 ad __PRINTK(("XXX ltr not supported\n"));
83 1.2.4.2 ad }
84 1.2.4.2 ad
85 1.2.4.2 ad void
86 1.2.4.2 ad lcr0(u_int val)
87 1.2.4.2 ad {
88 1.2.4.2 ad __PRINTK(("XXX lcr0 not supported\n"));
89 1.2.4.2 ad }
90 1.2.4.2 ad
91 1.2.4.2 ad u_int
92 1.2.4.2 ad rcr0(void)
93 1.2.4.2 ad {
94 1.2.4.2 ad __PRINTK(("XXX rcr0 not supported\n"));
95 1.2.4.2 ad return 0;
96 1.2.4.2 ad }
97 1.2.4.2 ad
98 1.2.4.2 ad #ifndef __x86_64__
99 1.2.4.2 ad void
100 1.2.4.2 ad lcr3(vaddr_t val)
101 1.2.4.2 ad {
102 1.2.4.2 ad int s = splvm();
103 1.2.4.2 ad xpq_queue_pt_switch(xpmap_ptom_masked(val));
104 1.2.4.2 ad xpq_flush_queue();
105 1.2.4.2 ad splx(s);
106 1.2.4.2 ad }
107 1.2.4.2 ad #endif
108 1.2.4.2 ad
109 1.2.4.2 ad void
110 1.2.4.2 ad tlbflush(void)
111 1.2.4.2 ad {
112 1.2.4.2 ad int s = splvm();
113 1.2.4.2 ad xpq_queue_tlb_flush();
114 1.2.4.2 ad xpq_flush_queue();
115 1.2.4.2 ad splx(s);
116 1.2.4.2 ad }
117 1.2.4.2 ad
118 1.2.4.2 ad void
119 1.2.4.2 ad tlbflushg(void)
120 1.2.4.2 ad {
121 1.2.4.2 ad tlbflush();
122 1.2.4.2 ad }
123 1.2.4.2 ad
124 1.2.4.2 ad vaddr_t
125 1.2.4.2 ad rdr6(void)
126 1.2.4.2 ad {
127 1.2.4.2 ad u_int val;
128 1.2.4.2 ad
129 1.2.4.2 ad val = HYPERVISOR_get_debugreg(6);
130 1.2.4.2 ad return val;
131 1.2.4.2 ad }
132 1.2.4.2 ad
133 1.2.4.2 ad void
134 1.2.4.2 ad ldr6(vaddr_t val)
135 1.2.4.2 ad {
136 1.2.4.2 ad
137 1.2.4.2 ad HYPERVISOR_set_debugreg(6, val);
138 1.2.4.2 ad }
139 1.2.4.2 ad
140 1.2.4.2 ad void
141 1.2.4.2 ad wbinvd(void)
142 1.2.4.2 ad {
143 1.2.4.2 ad
144 1.2.4.2 ad xpq_flush_cache();
145 1.2.4.2 ad }
146 1.2.4.2 ad
147 1.2.4.2 ad vaddr_t
148 1.2.4.2 ad rcr2(void)
149 1.2.4.2 ad {
150 1.2.4.2 ad #ifdef XEN3
151 1.2.4.2 ad return HYPERVISOR_shared_info->vcpu_info[0].arch.cr2; /* XXX curcpu */
152 1.2.4.2 ad #else
153 1.2.4.2 ad return 0;
154 1.2.4.2 ad #endif
155 1.2.4.2 ad }
156 1.2.4.2 ad /* $NetBSD: xenfunc.c,v 1.2.4.2 2007/12/03 19:04:46 ad Exp $ */
157 1.2.4.2 ad
158 1.2.4.2 ad /*
159 1.2.4.2 ad *
160 1.2.4.2 ad * Copyright (c) 2004 Christian Limpach.
161 1.2.4.2 ad * All rights reserved.
162 1.2.4.2 ad *
163 1.2.4.2 ad * Redistribution and use in source and binary forms, with or without
164 1.2.4.2 ad * modification, are permitted provided that the following conditions
165 1.2.4.2 ad * are met:
166 1.2.4.2 ad * 1. Redistributions of source code must retain the above copyright
167 1.2.4.2 ad * notice, this list of conditions and the following disclaimer.
168 1.2.4.2 ad * 2. Redistributions in binary form must reproduce the above copyright
169 1.2.4.2 ad * notice, this list of conditions and the following disclaimer in the
170 1.2.4.2 ad * documentation and/or other materials provided with the distribution.
171 1.2.4.2 ad * 3. All advertising materials mentioning features or use of this software
172 1.2.4.2 ad * must display the following acknowledgement:
173 1.2.4.2 ad * This product includes software developed by Christian Limpach.
174 1.2.4.2 ad * 4. The name of the author may not be used to endorse or promote products
175 1.2.4.2 ad * derived from this software without specific prior written permission.
176 1.2.4.2 ad *
177 1.2.4.2 ad * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
178 1.2.4.2 ad * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
179 1.2.4.2 ad * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
180 1.2.4.2 ad * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
181 1.2.4.2 ad * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
182 1.2.4.2 ad * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
183 1.2.4.2 ad * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
184 1.2.4.2 ad * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
185 1.2.4.2 ad * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
186 1.2.4.2 ad * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
187 1.2.4.2 ad */
188 1.2.4.2 ad
189 1.2.4.2 ad #include <sys/param.h>
190 1.2.4.2 ad
191 1.2.4.2 ad #include <uvm/uvm_extern.h>
192 1.2.4.2 ad
193 1.2.4.2 ad #include <machine/intr.h>
194 1.2.4.2 ad #include <machine/vmparam.h>
195 1.2.4.2 ad #include <machine/pmap.h>
196 1.2.4.2 ad #include <xen/xen.h>
197 1.2.4.2 ad #include <xen/hypervisor.h>
198 1.2.4.2 ad //#include <xen/evtchn.h>
199 1.2.4.2 ad #include <xen/xenpmap.h>
200 1.2.4.2 ad #include <machine/pte.h>
201 1.2.4.2 ad
202 1.2.4.2 ad #ifdef XENDEBUG_LOW
203 1.2.4.2 ad #define __PRINTK(x) printk x
204 1.2.4.2 ad #else
205 1.2.4.2 ad #define __PRINTK(x)
206 1.2.4.2 ad #endif
207 1.2.4.2 ad
208 1.2.4.2 ad void xen_set_ldt(vaddr_t, uint32_t);
209 1.2.4.2 ad void xen_update_descriptor(union descriptor *, union descriptor *);
210 1.2.4.2 ad
211 1.2.4.2 ad void
212 1.2.4.2 ad invlpg(vaddr_t addr)
213 1.2.4.2 ad {
214 1.2.4.2 ad int s = splvm();
215 1.2.4.2 ad xpq_queue_invlpg(addr);
216 1.2.4.2 ad xpq_flush_queue();
217 1.2.4.2 ad splx(s);
218 1.2.4.2 ad }
219 1.2.4.2 ad
220 1.2.4.2 ad #ifndef __x86_64__
221 1.2.4.2 ad void
222 1.2.4.2 ad lldt(u_short sel)
223 1.2.4.2 ad {
224 1.2.4.2 ad
225 1.2.4.2 ad /* __PRINTK(("ldt %x\n", IDXSELN(sel))); */
226 1.2.4.2 ad if (sel == GSEL(GLDT_SEL, SEL_KPL))
227 1.2.4.2 ad xen_set_ldt((vaddr_t)ldt, NLDT);
228 1.2.4.2 ad else
229 1.2.4.2 ad xen_set_ldt(cpu_info_primary.ci_gdt[IDXSELN(sel)].ld.ld_base,
230 1.2.4.2 ad cpu_info_primary.ci_gdt[IDXSELN(sel)].ld.ld_entries);
231 1.2.4.2 ad }
232 1.2.4.2 ad #endif
233 1.2.4.2 ad
234 1.2.4.2 ad void
235 1.2.4.2 ad ltr(u_short sel)
236 1.2.4.2 ad {
237 1.2.4.2 ad __PRINTK(("XXX ltr not supported\n"));
238 1.2.4.2 ad }
239 1.2.4.2 ad
240 1.2.4.2 ad void
241 1.2.4.2 ad lcr0(u_int val)
242 1.2.4.2 ad {
243 1.2.4.2 ad __PRINTK(("XXX lcr0 not supported\n"));
244 1.2.4.2 ad }
245 1.2.4.2 ad
246 1.2.4.2 ad u_int
247 1.2.4.2 ad rcr0(void)
248 1.2.4.2 ad {
249 1.2.4.2 ad __PRINTK(("XXX rcr0 not supported\n"));
250 1.2.4.2 ad return 0;
251 1.2.4.2 ad }
252 1.2.4.2 ad
253 1.2.4.2 ad #ifndef __x86_64__
254 1.2.4.2 ad void
255 1.2.4.2 ad lcr3(vaddr_t val)
256 1.2.4.2 ad {
257 1.2.4.2 ad int s = splvm();
258 1.2.4.2 ad xpq_queue_pt_switch(xpmap_ptom_masked(val));
259 1.2.4.2 ad xpq_flush_queue();
260 1.2.4.2 ad splx(s);
261 1.2.4.2 ad }
262 1.2.4.2 ad #endif
263 1.2.4.2 ad
264 1.2.4.2 ad void
265 1.2.4.2 ad tlbflush(void)
266 1.2.4.2 ad {
267 1.2.4.2 ad int s = splvm();
268 1.2.4.2 ad xpq_queue_tlb_flush();
269 1.2.4.2 ad xpq_flush_queue();
270 1.2.4.2 ad splx(s);
271 1.2.4.2 ad }
272 1.2.4.2 ad
273 1.2.4.2 ad void
274 1.2.4.2 ad tlbflushg(void)
275 1.2.4.2 ad {
276 1.2.4.2 ad tlbflush();
277 1.2.4.2 ad }
278 1.2.4.2 ad
279 1.2.4.2 ad vaddr_t
280 1.2.4.2 ad rdr6(void)
281 1.2.4.2 ad {
282 1.2.4.2 ad u_int val;
283 1.2.4.2 ad
284 1.2.4.2 ad val = HYPERVISOR_get_debugreg(6);
285 1.2.4.2 ad return val;
286 1.2.4.2 ad }
287 1.2.4.2 ad
288 1.2.4.2 ad void
289 1.2.4.2 ad ldr6(vaddr_t val)
290 1.2.4.2 ad {
291 1.2.4.2 ad
292 1.2.4.2 ad HYPERVISOR_set_debugreg(6, val);
293 1.2.4.2 ad }
294 1.2.4.2 ad
295 1.2.4.2 ad void
296 1.2.4.2 ad wbinvd(void)
297 1.2.4.2 ad {
298 1.2.4.2 ad
299 1.2.4.2 ad xpq_flush_cache();
300 1.2.4.2 ad }
301 1.2.4.2 ad
302 1.2.4.2 ad vaddr_t
303 1.2.4.2 ad rcr2(void)
304 1.2.4.2 ad {
305 1.2.4.2 ad #ifdef XEN3
306 1.2.4.2 ad return HYPERVISOR_shared_info->vcpu_info[0].arch.cr2; /* XXX curcpu */
307 1.2.4.2 ad #else
308 1.2.4.2 ad return 0;
309 1.2.4.2 ad #endif
310 1.2.4.2 ad }
311