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