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