xref: /netbsd-src/sys/arch/xen/x86/xenfunc.c (revision b5677b36047b601b9addaaa494a58ceae82c2a6c)
1 /*	$NetBSD: xenfunc.c,v 1.7 2008/05/11 16:23:05 ad Exp $	*/
2 
3 /*
4  *
5  * Copyright (c) 2004 Christian Limpach.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *      This product includes software developed by Christian Limpach.
19  * 4. The name of the author may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #include <sys/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: xenfunc.c,v 1.7 2008/05/11 16:23:05 ad Exp $");
36 
37 #include <sys/param.h>
38 
39 #include <uvm/uvm_extern.h>
40 
41 #include <machine/intr.h>
42 #include <machine/vmparam.h>
43 #include <machine/pmap.h>
44 #include <xen/xen.h>
45 #include <xen/hypervisor.h>
46 //#include <xen/evtchn.h>
47 #include <xen/xenpmap.h>
48 #include <machine/pte.h>
49 
50 #ifdef XENDEBUG_LOW
51 #define	__PRINTK(x) printk x
52 #else
53 #define	__PRINTK(x)
54 #endif
55 
56 void xen_set_ldt(vaddr_t, uint32_t);
57 
58 void
59 invlpg(vaddr_t addr)
60 {
61 	int s = splvm();
62 	xpq_queue_invlpg(addr);
63 	xpq_flush_queue();
64 	splx(s);
65 }
66 
67 #ifndef __x86_64__
68 void
69 lldt(u_short sel)
70 {
71 	struct cpu_info *ci;
72 
73 	ci = curcpu();
74 
75 	if (ci->ci_curldt == sel)
76 		return;
77 	/* __PRINTK(("ldt %x\n", IDXSELN(sel))); */
78 	if (sel == GSEL(GLDT_SEL, SEL_KPL))
79 		xen_set_ldt((vaddr_t)ldt, NLDT);
80 	else
81 		xen_set_ldt(ci->ci_gdt[IDXSELN(sel)].ld.ld_base,
82 		    ci->ci_gdt[IDXSELN(sel)].ld.ld_entries);
83 	ci->ci_curldt = sel;
84 }
85 #endif
86 
87 void
88 ltr(u_short sel)
89 {
90 	__PRINTK(("XXX ltr not supported\n"));
91 }
92 
93 void
94 lcr0(u_long val)
95 {
96 	__PRINTK(("XXX lcr0 not supported\n"));
97 }
98 
99 u_long
100 rcr0(void)
101 {
102 	__PRINTK(("XXX rcr0 not supported\n"));
103 	return 0;
104 }
105 
106 #ifndef __x86_64__
107 void
108 lcr3(vaddr_t val)
109 {
110 	int s = splvm();
111 	xpq_queue_pt_switch(xpmap_ptom_masked(val));
112 	xpq_flush_queue();
113 	splx(s);
114 }
115 #endif
116 
117 void
118 tlbflush(void)
119 {
120 	int s = splvm();
121 	xpq_queue_tlb_flush();
122 	xpq_flush_queue();
123 	splx(s);
124 }
125 
126 void
127 tlbflushg(void)
128 {
129 	tlbflush();
130 }
131 
132 vaddr_t
133 rdr6(void)
134 {
135 	u_int val;
136 
137 	val = HYPERVISOR_get_debugreg(6);
138 	return val;
139 }
140 
141 void
142 ldr6(vaddr_t val)
143 {
144 
145 	HYPERVISOR_set_debugreg(6, val);
146 }
147 
148 void
149 wbinvd(void)
150 {
151 
152 	xpq_flush_cache();
153 }
154 
155 vaddr_t
156 rcr2(void)
157 {
158 #ifdef XEN3
159 	return curcpu()->ci_vcpu->arch.cr2;
160 #else
161 	return 0;
162 #endif
163 }
164