This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / include / asm-i386 / mach-xen / asm / hypervisor.h
1 /******************************************************************************
2  * hypervisor.h
3  * 
4  * Linux-specific hypervisor handling.
5  * 
6  * Copyright (c) 2002-2004, K A Fraser
7  * 
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License version 2
10  * as published by the Free Software Foundation; or, when distributed
11  * separately from the Linux kernel or incorporated into other
12  * software packages, subject to the following license:
13  * 
14  * Permission is hereby granted, free of charge, to any person obtaining a copy
15  * of this source file (the "Software"), to deal in the Software without
16  * restriction, including without limitation the rights to use, copy, modify,
17  * merge, publish, distribute, sublicense, and/or sell copies of the Software,
18  * and to permit persons to whom the Software is furnished to do so, subject to
19  * the following conditions:
20  * 
21  * The above copyright notice and this permission notice shall be included in
22  * all copies or substantial portions of the Software.
23  * 
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30  * IN THE SOFTWARE.
31  */
32
33 #ifndef __HYPERVISOR_H__
34 #define __HYPERVISOR_H__
35
36 #include <linux/config.h>
37 #include <linux/types.h>
38 #include <linux/kernel.h>
39 #include <linux/version.h>
40 #include <linux/errno.h>
41 #include <xen/interface/xen.h>
42 #include <xen/interface/dom0_ops.h>
43 #include <xen/interface/event_channel.h>
44 #include <xen/interface/physdev.h>
45 #include <xen/interface/sched.h>
46 #include <xen/interface/nmi.h>
47 #include <asm/ptrace.h>
48 #include <asm/page.h>
49 #if defined(__i386__)
50 #  ifdef CONFIG_X86_PAE
51 #   include <asm-generic/pgtable-nopud.h>
52 #  else
53 #   include <asm-generic/pgtable-nopmd.h>
54 #  endif
55 #endif
56
57 extern shared_info_t *HYPERVISOR_shared_info;
58
59 /* arch/xen/i386/kernel/setup.c */
60 extern start_info_t *xen_start_info;
61
62 /* arch/xen/kernel/evtchn.c */
63 /* Force a proper event-channel callback from Xen. */
64 void force_evtchn_callback(void);
65
66 /* arch/xen/kernel/process.c */
67 void xen_cpu_idle (void);
68
69 /* arch/xen/i386/kernel/hypervisor.c */
70 void do_hypervisor_callback(struct pt_regs *regs);
71
72 /* arch/xen/i386/mm/hypervisor.c */
73 /*
74  * NB. ptr values should be PHYSICAL, not MACHINE. 'vals' should be already
75  * be MACHINE addresses.
76  */
77
78 void xen_pt_switch(unsigned long ptr);
79 void xen_new_user_pt(unsigned long ptr); /* x86_64 only */
80 void xen_load_gs(unsigned int selector); /* x86_64 only */
81 void xen_tlb_flush(void);
82 void xen_invlpg(unsigned long ptr);
83
84 void xen_l1_entry_update(pte_t *ptr, pte_t val);
85 void xen_l2_entry_update(pmd_t *ptr, pmd_t val);
86 void xen_l3_entry_update(pud_t *ptr, pud_t val); /* x86_64/PAE */
87 void xen_l4_entry_update(pgd_t *ptr, pgd_t val); /* x86_64 only */
88 void xen_pgd_pin(unsigned long ptr);
89 void xen_pgd_unpin(unsigned long ptr);
90
91 void xen_set_ldt(unsigned long ptr, unsigned long bytes);
92 void xen_machphys_update(unsigned long mfn, unsigned long pfn);
93
94 #ifdef CONFIG_SMP
95 #include <linux/cpumask.h>
96 void xen_tlb_flush_all(void);
97 void xen_invlpg_all(unsigned long ptr);
98 void xen_tlb_flush_mask(cpumask_t *mask);
99 void xen_invlpg_mask(cpumask_t *mask, unsigned long ptr);
100 #endif
101
102 /* Returns zero on success else negative errno. */
103 int xen_create_contiguous_region(
104     unsigned long vstart, unsigned int order, unsigned int address_bits);
105 void xen_destroy_contiguous_region(
106     unsigned long vstart, unsigned int order);
107
108 /* Turn jiffies into Xen system time. */
109 u64 jiffies_to_st(unsigned long jiffies);
110
111 #include <asm/hypercall.h>
112
113 #if defined(CONFIG_X86_64)
114 #define MULTI_UVMFLAGS_INDEX 2
115 #define MULTI_UVMDOMID_INDEX 3
116 #else
117 #define MULTI_UVMFLAGS_INDEX 3
118 #define MULTI_UVMDOMID_INDEX 4
119 #endif
120
121 #define is_running_on_xen() 1
122
123 static inline int
124 HYPERVISOR_yield(
125         void)
126 {
127         int rc = HYPERVISOR_sched_op(SCHEDOP_yield, NULL);
128
129         if (rc == -ENOSYS)
130                 rc = HYPERVISOR_sched_op_compat(SCHEDOP_yield, 0);
131
132         return rc;
133 }
134
135 static inline int
136 HYPERVISOR_block(
137         void)
138 {
139         int rc = HYPERVISOR_sched_op(SCHEDOP_block, NULL);
140
141         if (rc == -ENOSYS)
142                 rc = HYPERVISOR_sched_op_compat(SCHEDOP_block, 0);
143
144         return rc;
145 }
146
147 static inline int
148 HYPERVISOR_shutdown(
149         unsigned int reason)
150 {
151         struct sched_shutdown sched_shutdown = {
152                 .reason = reason
153         };
154
155         int rc = HYPERVISOR_sched_op(SCHEDOP_shutdown, &sched_shutdown);
156
157         if (rc == -ENOSYS)
158                 rc = HYPERVISOR_sched_op_compat(SCHEDOP_shutdown, reason);
159
160         return rc;
161 }
162
163 static inline int
164 HYPERVISOR_poll(
165         evtchn_port_t *ports, unsigned int nr_ports, u64 timeout)
166 {
167         int rc;
168         struct sched_poll sched_poll = {
169                 .nr_ports = nr_ports,
170                 .timeout = jiffies_to_st(timeout)
171         };
172         set_xen_guest_handle(sched_poll.ports, ports);
173
174         rc = HYPERVISOR_sched_op(SCHEDOP_poll, &sched_poll);
175         if (rc == -ENOSYS)
176                 rc = HYPERVISOR_sched_op_compat(SCHEDOP_yield, 0);
177
178         return rc;
179 }
180
181 static inline void
182 MULTI_update_va_mapping(
183     multicall_entry_t *mcl, unsigned long va,
184     pte_t new_val, unsigned long flags)
185 {
186     mcl->op = __HYPERVISOR_update_va_mapping;
187     mcl->args[0] = va;
188 #if defined(CONFIG_X86_64)
189     mcl->args[1] = new_val.pte;
190 #elif defined(CONFIG_X86_PAE)
191     mcl->args[1] = new_val.pte_low;
192     mcl->args[2] = new_val.pte_high;
193 #else
194     mcl->args[1] = new_val.pte_low;
195     mcl->args[2] = 0;
196 #endif
197     mcl->args[MULTI_UVMFLAGS_INDEX] = flags;
198 }
199
200 static inline void
201 MULTI_update_va_mapping_otherdomain(
202     multicall_entry_t *mcl, unsigned long va,
203     pte_t new_val, unsigned long flags, domid_t domid)
204 {
205     mcl->op = __HYPERVISOR_update_va_mapping_otherdomain;
206     mcl->args[0] = va;
207 #if defined(CONFIG_X86_64)
208     mcl->args[1] = new_val.pte;
209 #elif defined(CONFIG_X86_PAE)
210     mcl->args[1] = new_val.pte_low;
211     mcl->args[2] = new_val.pte_high;
212 #else
213     mcl->args[1] = new_val.pte_low;
214     mcl->args[2] = 0;
215 #endif
216     mcl->args[MULTI_UVMFLAGS_INDEX] = flags;
217     mcl->args[MULTI_UVMDOMID_INDEX] = domid;
218 }
219
220 #endif /* __HYPERVISOR_H__ */