This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / include / asm-ia64 / 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 #ifdef CONFIG_XEN
37 extern int running_on_xen;
38 #define is_running_on_xen()                     (running_on_xen)
39 #else /* CONFIG_XEN */
40 # ifdef CONFIG_VMX_GUEST
41 #  define is_running_on_xen()                   (1)
42 # else /* CONFIG_VMX_GUEST */
43 #  define is_running_on_xen()                   (0)
44 #  define HYPERVISOR_ioremap(offset, size)      (offset)
45 # endif /* CONFIG_VMX_GUEST */
46 #endif /* CONFIG_XEN */
47
48 #if defined(CONFIG_XEN) || defined(CONFIG_VMX_GUEST)
49 #include <linux/types.h>
50 #include <linux/kernel.h>
51 #include <linux/version.h>
52 #include <linux/errno.h>
53 #include <xen/interface/xen.h>
54 #include <xen/interface/dom0_ops.h>
55 #include <xen/interface/event_channel.h>
56 #include <xen/interface/physdev.h>
57 #include <xen/interface/sched.h>
58 #include <asm/hypercall.h>
59 #include <asm/ptrace.h>
60 #include <asm/page.h>
61
62 extern shared_info_t *HYPERVISOR_shared_info;
63 extern start_info_t *xen_start_info;
64
65 void force_evtchn_callback(void);
66
67 #ifndef CONFIG_VMX_GUEST
68 /* Turn jiffies into Xen system time. XXX Implement me. */
69 #define jiffies_to_st(j)        0
70
71 static inline int
72 HYPERVISOR_yield(
73         void)
74 {
75         int rc = HYPERVISOR_sched_op(SCHEDOP_yield, NULL);
76
77         if (rc == -ENOSYS)
78                 rc = HYPERVISOR_sched_op_compat(SCHEDOP_yield, 0);
79
80         return rc;
81 }
82
83 static inline int
84 HYPERVISOR_block(
85         void)
86 {
87         int rc = HYPERVISOR_sched_op(SCHEDOP_block, NULL);
88
89         if (rc == -ENOSYS)
90                 rc = HYPERVISOR_sched_op_compat(SCHEDOP_block, 0);
91
92         return rc;
93 }
94
95 static inline int
96 HYPERVISOR_shutdown(
97         unsigned int reason)
98 {
99         struct sched_shutdown sched_shutdown = {
100                 .reason = reason
101         };
102
103         int rc = HYPERVISOR_sched_op(SCHEDOP_shutdown, &sched_shutdown);
104
105         if (rc == -ENOSYS)
106                 rc = HYPERVISOR_sched_op_compat(SCHEDOP_shutdown, reason);
107
108         return rc;
109 }
110
111 static inline int
112 HYPERVISOR_poll(
113         evtchn_port_t *ports, unsigned int nr_ports, u64 timeout)
114 {
115         struct sched_poll sched_poll = {
116                 .nr_ports = nr_ports,
117                 .timeout = jiffies_to_st(timeout)
118         };
119
120         int rc;
121
122         set_xen_guest_handle(sched_poll.ports, ports);
123         rc = HYPERVISOR_sched_op(SCHEDOP_poll, &sched_poll);
124         if (rc == -ENOSYS)
125                 rc = HYPERVISOR_sched_op_compat(SCHEDOP_yield, 0);
126
127         return rc;
128 }
129
130 #include <asm/hypercall.h>
131
132 // for drivers/xen/privcmd/privcmd.c
133 #define machine_to_phys_mapping 0
134 struct vm_area_struct;
135 int direct_remap_pfn_range(struct vm_area_struct *vma,
136                            unsigned long address,
137                            unsigned long mfn,
138                            unsigned long size,
139                            pgprot_t prot,
140                            domid_t  domid);
141 struct file;
142 int privcmd_mmap(struct file * file, struct vm_area_struct * vma);
143 #define HAVE_ARCH_PRIVCMD_MMAP
144
145 // for drivers/xen/balloon/balloon.c
146 #ifdef CONFIG_XEN_SCRUB_PAGES
147 #define scrub_pages(_p,_n) memset((void *)(_p), 0, (_n) << PAGE_SHIFT)
148 #else
149 #define scrub_pages(_p,_n) ((void)0)
150 #endif
151 #define pte_mfn(_x)     pte_pfn(_x)
152 #define phys_to_machine_mapping_valid(_x)       (1)
153
154 #endif /* !CONFIG_VMX_GUEST */
155
156 #define __pte_ma(_x)    ((pte_t) {(_x)})        /* unmodified use */
157 #define pfn_pte_ma(_x,_y)       __pte_ma(0)     /* unmodified use */
158
159 #ifndef CONFIG_VMX_GUEST
160 int __xen_create_contiguous_region(unsigned long vstart, unsigned int order, unsigned int address_bits);
161 static inline int
162 xen_create_contiguous_region(unsigned long vstart,
163                              unsigned int order, unsigned int address_bits)
164 {
165         int ret = 0;
166         if (is_running_on_xen()) {
167                 ret = __xen_create_contiguous_region(vstart, order,
168                                                      address_bits);
169         }
170         return ret;
171 }
172
173 void __xen_destroy_contiguous_region(unsigned long vstart, unsigned int order);
174 static inline void
175 xen_destroy_contiguous_region(unsigned long vstart, unsigned int order)
176 {
177         if (is_running_on_xen())
178                 __xen_destroy_contiguous_region(vstart, order);
179 }
180
181 #endif /* !CONFIG_VMX_GUEST */
182
183 // for netfront.c, netback.c
184 #define MULTI_UVMFLAGS_INDEX 0 //XXX any value
185
186 static inline void
187 MULTI_update_va_mapping(
188         multicall_entry_t *mcl, unsigned long va,
189         pte_t new_val, unsigned long flags)
190 {
191         mcl->op = __HYPERVISOR_update_va_mapping;
192         mcl->result = 0;
193 }
194
195 static inline void
196 MULTI_grant_table_op(multicall_entry_t *mcl, unsigned int cmd,
197         void *uop, unsigned int count)
198 {
199         mcl->op = __HYPERVISOR_grant_table_op;
200         mcl->args[0] = cmd;
201         mcl->args[1] = (unsigned long)uop;
202         mcl->args[2] = count;
203 }
204
205 // for debug
206 asmlinkage int xprintk(const char *fmt, ...);
207 #define xprintd(fmt, ...)       xprintk("%s:%d " fmt, __func__, __LINE__, \
208                                         ##__VA_ARGS__)
209
210 #endif /* CONFIG_XEN || CONFIG_VMX_GUEST */
211
212 #ifdef CONFIG_XEN_PRIVILEGED_GUEST
213 #define is_initial_xendomain() (xen_start_info->flags & SIF_INITDOMAIN)
214 #else
215 #define is_initial_xendomain() 0
216 #endif
217
218 #endif /* __HYPERVISOR_H__ */