xen.h revision 1.11 1 /* $NetBSD: xen.h,v 1.11 2005/03/26 20:00:49 bouyer Exp $ */
2
3 /*
4 *
5 * Copyright (c) 2003, 2004 Keir Fraser (on behalf of the Xen team)
6 * All rights reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to
10 * deal in the Software without restriction, including without limitation the
11 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 * sell copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
25 */
26
27
28 #ifndef _XEN_H
29 #define _XEN_H
30
31 #ifndef _LOCORE
32
33 struct xen_netinfo {
34 uint32_t xi_ifno;
35 char *xi_root;
36 uint32_t xi_ip[5];
37 };
38
39 union xen_cmdline_parseinfo {
40 char xcp_bootdev[16]; /* sizeof(dv_xname) */
41 struct xen_netinfo xcp_netinfo;
42 char xcp_console[16];
43 };
44
45 #define XEN_PARSE_BOOTDEV 0
46 #define XEN_PARSE_NETINFO 1
47 #define XEN_PARSE_CONSOLE 2
48
49 void xen_parse_cmdline(int, union xen_cmdline_parseinfo *);
50
51 void xenconscn_attach(void);
52
53 void xenprivcmd_init(void);
54
55 void xbdback_init(void);
56 void xennetback_init(void);
57 void xen_shm_init(void);
58
59 void xenevt_event(int);
60
61 void idle_block(void);
62
63 #ifdef XENDEBUG
64 void printk(const char *, ...);
65 void vprintk(const char *, _BSD_VA_LIST_);
66 #endif
67
68 #endif
69
70 #endif /* _XEN_H */
71
72 /******************************************************************************
73 * os.h
74 *
75 * random collection of macros and definition
76 */
77
78 #ifndef _OS_H_
79 #define _OS_H_
80
81 /*
82 * These are the segment descriptors provided for us by the hypervisor.
83 * For now, these are hardwired -- guest OSes cannot update the GDT
84 * or LDT.
85 *
86 * It shouldn't be hard to support descriptor-table frobbing -- let me
87 * know if the BSD or XP ports require flexibility here.
88 */
89
90
91 /*
92 * these are also defined in xen-public/xen.h but can't be pulled in as
93 * they are used in start of day assembly. Need to clean up the .h files
94 * a bit more...
95 */
96
97 #ifndef FLAT_RING1_CS
98 #define FLAT_RING1_CS 0x0819
99 #define FLAT_RING1_DS 0x0821
100 #define FLAT_RING3_CS 0x082b
101 #define FLAT_RING3_DS 0x0833
102 #endif
103
104 #define __KERNEL_CS FLAT_RING1_CS
105 #define __KERNEL_DS FLAT_RING1_DS
106
107 /* Everything below this point is not included by assembler (.S) files. */
108 #ifndef _LOCORE
109
110 /* some function prototypes */
111 void trap_init(void);
112 void xpq_flush_cache(void);
113
114
115 /*
116 * STI/CLI equivalents. These basically set and clear the virtual
117 * event_enable flag in the shared_info structure. Note that when
118 * the enable bit is set, there may be pending events to be handled.
119 * We may therefore call into do_hypervisor_callback() directly.
120 */
121
122 #define __save_flags(x) \
123 do { \
124 (x) = HYPERVISOR_shared_info->vcpu_data[0].evtchn_upcall_mask; \
125 } while (0)
126
127 #define __restore_flags(x) \
128 do { \
129 volatile shared_info_t *_shared = HYPERVISOR_shared_info; \
130 __insn_barrier(); \
131 if ((_shared->vcpu_data[0].evtchn_upcall_mask = (x)) == 0) { \
132 x86_lfence(); \
133 if (__predict_false(_shared->vcpu_data[0].evtchn_upcall_pending)) \
134 hypervisor_force_callback(); \
135 } \
136 } while (0)
137
138 #define __cli() \
139 do { \
140 HYPERVISOR_shared_info->vcpu_data[0].evtchn_upcall_mask = 1; \
141 x86_lfence(); \
142 } while (0)
143
144 #define __sti() \
145 do { \
146 volatile shared_info_t *_shared = HYPERVISOR_shared_info; \
147 __insn_barrier(); \
148 _shared->vcpu_data[0].evtchn_upcall_mask = 0; \
149 x86_lfence(); /* unmask then check (avoid races) */ \
150 if (__predict_false(_shared->vcpu_data[0].evtchn_upcall_pending)) \
151 hypervisor_force_callback(); \
152 } while (0)
153
154 #define cli() __cli()
155 #define sti() __sti()
156 #define save_flags(x) __save_flags(x)
157 #define restore_flags(x) __restore_flags(x)
158 #define save_and_cli(x) do { \
159 __save_flags(x); \
160 __cli(); \
161 } while (/* CONSTCOND */ 0)
162 #define save_and_sti(x) __save_and_sti(x)
163
164 /*
165 * always assume we're on multiprocessor. We don't know how many CPU the
166 * underlying hardware has.
167 */
168 #define __LOCK_PREFIX "lock; "
169
170 static __inline__ uint32_t
171 x86_atomic_xchg(volatile uint32_t *ptr, unsigned long val)
172 {
173 unsigned long result;
174
175 __asm __volatile(__LOCK_PREFIX
176 "xchgl %0,%1"
177 :"=r" (result)
178 :"m" (*ptr), "0" (val)
179 :"memory");
180
181 return result;
182 }
183
184 static __inline__ int
185 x86_atomic_test_and_clear_bit(volatile void *ptr, int bitno)
186 {
187 int result;
188
189 __asm __volatile(__LOCK_PREFIX
190 "btrl %2,%1 ;"
191 "sbbl %0,%0"
192 :"=r" (result), "=m" (*(volatile uint32_t *)(ptr))
193 :"Ir" (bitno) : "memory");
194 return result;
195 }
196
197 static __inline__ int
198 x86_atomic_test_and_set_bit(volatile void *ptr, int bitno)
199 {
200 int result;
201
202 __asm __volatile(__LOCK_PREFIX
203 "btsl %2,%1 ;"
204 "sbbl %0,%0"
205 :"=r" (result), "=m" (*(volatile uint32_t *)(ptr))
206 :"Ir" (bitno) : "memory");
207 return result;
208 }
209
210 static __inline int
211 x86_constant_test_bit(const volatile void *ptr, int bitno)
212 {
213 return ((1UL << (bitno & 31)) &
214 (((const volatile uint32_t *) ptr)[bitno >> 5])) != 0;
215 }
216
217 static __inline int
218 x86_variable_test_bit(const volatile void *ptr, int bitno)
219 {
220 int result;
221
222 __asm __volatile(
223 "btl %2,%1 ;"
224 "sbbl %0,%0"
225 :"=r" (result)
226 :"m" (*(volatile uint32_t *)(ptr)), "Ir" (bitno));
227 return result;
228 }
229
230 #define x86_atomic_test_bit(ptr, bitno) \
231 (__builtin_constant_p(bitno) ? \
232 x86_constant_test_bit((ptr),(bitno)) : \
233 x86_variable_test_bit((ptr),(bitno)))
234
235 static __inline void
236 x86_atomic_set_bit(volatile void *ptr, int bitno)
237 {
238 __asm __volatile(__LOCK_PREFIX
239 "btsl %1,%0"
240 :"=m" (*(volatile uint32_t *)(ptr))
241 :"Ir" (bitno));
242 }
243
244 static __inline void
245 x86_atomic_clear_bit(volatile void *ptr, int bitno)
246 {
247 __asm __volatile(__LOCK_PREFIX
248 "btrl %1,%0"
249 :"=m" (*(volatile uint32_t *)(ptr))
250 :"Ir" (bitno));
251 }
252
253 static __inline void
254 wbinvd(void)
255 {
256 xpq_flush_cache();
257 }
258
259 #endif /* !__ASSEMBLY__ */
260
261 #endif /* _OS_H_ */
262